Skip to content
Merged
153 changes: 153 additions & 0 deletions .changeset/experimental-xmc-enhancements.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
---
'@sitecore-marketplace-sdk/xmc': patch
---

# Experimental XMC - Server-to-Server API Access

## 🚀 What's New

### Server-to-Server Support

EXPERIMENTAL_XMC enables API access to Sitecore APIs without requiring the Host SDK or Client SDK mode. Perfect for server-side applications that need to communicate with Sitecore APIs.

### Setup

```typescript
import { EXPERIMENTAL_XMC } from '@sitecore-marketplace-sdk/xmc';

// No Host SDK required
const xmc = new EXPERIMENTAL_XMC({
getAccessToken: () => auth0.getAccessTokenSilently(),
});
```

### Enhanced Type Safety

```typescript
import { EXPERIMENTAL_Sites } from '@sitecore-marketplace-sdk/xmc';

// Optional: Full IntelliSense support with types
const response = await xmc.sites.listLanguages();
let data: EXPERIMENTAL_Sites.ListLanguagesResponse = response.data!;
```

## 🎯 Quick Start - Server-to-Server

### 1. Install and Import

```typescript
import { EXPERIMENTAL_XMC } from '@sitecore-marketplace-sdk/xmc';
// Optional: import types for enhanced IntelliSense
import { EXPERIMENTAL_Sites } from '@sitecore-marketplace-sdk/xmc';
```

### 2. Initialize with Auth

```typescript
const xmc = new EXPERIMENTAL_XMC({
getAccessToken: () => auth0.getAccessTokenSilently(),
});
```

### 3. Use APIs

```typescript
// Sites API
const languages = await xmc.sites.listLanguages({
query: { sitecoreContextId: 'your-context-id' },
});

// Pages API
const pages = await xmc.pages.search({
query: { sitecoreContextId: 'your-context-id' },
});

// Authoring API
const result = await xmc.authoring.graphql({
body: {
query: `query {
sites {
name
}
}`,
},
query: { sitecoreContextId: 'your-context-id' },
});

// Content Transfer API
const transfer = await xmc.contentTransfer.createContentTransfer({
body: {
configuration: {
dataTrees: [
{
itemPath: '/sitecore/content/Home',
scope: 'SingleItem',
mergeStrategy: 'OverrideExistingItem',
},
],
},
transferId: crypto.randomUUID(),
},
query: { sitecoreContextId: 'your-context-id' },
});

// Preview API
const previewContent = await xmc.preview.graphql({
body: {
query: `query {
item(path: "/sitecore/content/Home", language: "en") {
id
name
path
fields {
name
value
}
}
}`,
},
query: { sitecoreContextId: 'your-context-id' },
});

// Live API
const liveContent = await xmc.live.graphql({
body: {
query: `query {
item(path: "/sitecore/content/Home", language: "en") {
id
name
path
fields {
name
value
}
}
}`,
},
query: { sitecoreContextId: 'your-context-id' },
});
```

## 🔧 Use Cases

### Server-Side Applications

```typescript
// Node.js server, Azure Functions, AWS Lambda, etc.
const xmc = new EXPERIMENTAL_XMC({
getAccessToken: () => getServerSideToken(),
});

// Direct API calls without browser context
const languages = await xmc.sites.listLanguages();
```

## 🎨 Optional Type Support

For enhanced IntelliSense, you can optionally import type namespaces:

- `EXPERIMENTAL_Sites.*` - Sites API types
- `EXPERIMENTAL_Pages.*` - Pages API types
- `EXPERIMENTAL_Authoring.*` - Authoring API types
- `EXPERIMENTAL_ContentTransfer.*` - Content Transfer API types
- `EXPERIMENTAL_Content.*` - Content API types
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"test:all": "turbo run test",
"coverage": "turbo run coverage",
"generate:module": "turbo run generate:module",
"generate:module:experimental": "turbo run generate:module:experimental",
"pack:client": "cd packages/client && pnpm pack",
"pack:core": "cd packages/core && pnpm pack",
"pack:xmc": "cd packages/xmc && pnpm pack",
Expand Down Expand Up @@ -44,4 +45,4 @@
}
},
"packageManager": "pnpm@10.6.3"
}
}
115 changes: 115 additions & 0 deletions packages/xmc/generate-xmc-experimental.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import { createClient } from '@hey-api/openapi-ts';
import { defineAugmentationConfig } from './plugins/augmentation';
import { defineClientTransformerConfig } from './plugins/client-transformer/config';
import { defineSchemaPatcherConfig } from './plugins/schema-patcher';
import { defineNamespaceTransformerConfig } from './plugins/namespace-transformer';

createClient({
input: 'https://api-docs.sitecore.com/_spec/xmc/sites-api/index.yaml',
output: {
format: 'prettier',
lint: 'eslint',
path: './src/experimental/client-sites',
},
plugins: [
defineSchemaPatcherConfig(),
'@hey-api/client-fetch',
'@hey-api/schemas',
'@hey-api/sdk',
{
enums: 'javascript',
name: '@hey-api/typescript',
},
defineNamespaceTransformerConfig({
namespace: 'EXPERIMENTAL_Sites',
}),
],
});

createClient({
input: 'https://api-docs.sitecore.com/_spec/xmc/pages-api/index.yaml',
output: {
format: 'prettier',
lint: 'eslint',
path: './src/experimental/client-pages',
},
plugins: [
defineSchemaPatcherConfig(),
'@hey-api/client-fetch',
'@hey-api/schemas',
'@hey-api/sdk',
{
enums: 'javascript',
name: '@hey-api/typescript',
},
defineNamespaceTransformerConfig({
namespace: 'EXPERIMENTAL_Pages',
}),
],
});

createClient({
input: './schema/experimental/authoring.yaml',
output: {
format: 'prettier',
lint: 'eslint',
path: './src/experimental/client-authoring',
},
plugins: [
defineSchemaPatcherConfig(),
'@hey-api/client-fetch',
'@hey-api/schemas',
'@hey-api/sdk',
{
enums: 'javascript',
name: '@hey-api/typescript',
},
defineNamespaceTransformerConfig({
namespace: 'EXPERIMENTAL_Authoring',
}),
],
});

createClient({
input: './schema/experimental/content-transfer.yaml',
output: {
format: 'prettier',
lint: 'eslint',
path: './src/experimental/client-content-transfer',
},
plugins: [
defineSchemaPatcherConfig(),
'@hey-api/client-fetch',
'@hey-api/schemas',
'@hey-api/sdk',
{
enums: 'javascript',
name: '@hey-api/typescript',
},
defineNamespaceTransformerConfig({
namespace: 'EXPERIMENTAL_ContentTransfer',
}),
],
});

createClient({
input: './schema/experimental/content.yaml',
output: {
format: 'prettier',
lint: 'eslint',
path: './src/experimental/client-content',
},
plugins: [
defineSchemaPatcherConfig(),
'@hey-api/client-fetch',
'@hey-api/schemas',
'@hey-api/sdk',
{
enums: 'javascript',
name: '@hey-api/typescript',
},
defineNamespaceTransformerConfig({
namespace: 'EXPERIMENTAL_Content',
}),
],
});
1 change: 1 addition & 0 deletions packages/xmc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"build": "pnpm run clean && rollup -c",
"clean": "rimraf dist tsconfig.tsbuildinfo",
"generate:module": "tsx generate-xmc.ts",
"generate:module:experimental": "tsx generate-xmc-experimental.ts",
"coverage": "vitest --coverage",
"generate:docs": "npx typedoc --options ../../typedoc.json --out ../../docs/modules/xmc src/index.ts"
},
Expand Down
21 changes: 21 additions & 0 deletions packages/xmc/plugins/namespace-transformer/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { Plugin } from '@hey-api/openapi-ts';

import { handler } from './plugin';
import type { Config } from './types';

export const defaultNamespaceTransformerConfig: Plugin.Config<Config> = {
_dependencies: ['@hey-api/client-fetch', '@hey-api/typescript'],
_handler: handler,
_handlerLegacy: () => {},
name: '@sitecore-marketplace/namespace-transformer',
output: 'client',
namespace: '',
};

/**
* Type helper for `my-plugin` plugin, returns {@link Plugin.Config} object
*/
export const defineNamespaceTransformerConfig: Plugin.DefineConfig<Config> = (config) => ({
...defaultNamespaceTransformerConfig,
...config,
});
2 changes: 2 additions & 0 deletions packages/xmc/plugins/namespace-transformer/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { defaultNamespaceTransformerConfig, defineNamespaceTransformerConfig } from './config';
export type { Config } from './types';
Loading
Loading