@remkoj/optimizely-cms-api 6.0.0-rc.1 → 6.0.0-rc.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/AGENTS.md +66 -0
  2. package/dist/api-client.d.ts +10 -65
  3. package/dist/api-client.js +18 -124
  4. package/dist/client/client/client.gen.js +107 -126
  5. package/dist/client/client/index.d.ts +2 -0
  6. package/dist/client/client/types.gen.d.ts +6 -3
  7. package/dist/client/client/utils.gen.d.ts +8 -4
  8. package/dist/client/client/utils.gen.js +6 -6
  9. package/dist/client/client.gen.d.ts +2 -2
  10. package/dist/client/client.gen.js +1 -1
  11. package/dist/client/core/auth.gen.d.ts +7 -0
  12. package/dist/client/core/params.gen.d.ts +2 -2
  13. package/dist/client/core/params.gen.js +24 -16
  14. package/dist/client/core/queryKeySerializer.gen.d.ts +1 -1
  15. package/dist/client/core/serverSentEvents.gen.d.ts +1 -1
  16. package/dist/client/core/serverSentEvents.gen.js +4 -6
  17. package/dist/client/core/types.gen.d.ts +6 -1
  18. package/dist/client/core/utils.gen.js +1 -1
  19. package/dist/client/index.d.ts +3 -3
  20. package/dist/client/index.js +63 -21
  21. package/dist/client/sdk.gen.d.ts +221 -118
  22. package/dist/client/sdk.gen.js +431 -180
  23. package/dist/client/transformers.gen.d.ts +35 -13
  24. package/dist/client/transformers.gen.js +341 -99
  25. package/dist/client/types.gen.d.ts +4383 -1300
  26. package/dist/client-config.d.ts +11 -0
  27. package/dist/client-config.js +21 -10
  28. package/dist/config.d.ts +39 -4
  29. package/dist/config.js +44 -18
  30. package/dist/getaccesstoken.js +22 -4
  31. package/dist/index.d.ts +20 -1
  32. package/dist/index.js +18 -4
  33. package/dist/types.d.ts +1 -14
  34. package/dist/types.js +0 -7
  35. package/dist/version.json +3 -3
  36. package/package.json +19 -8
@@ -1,5 +1,16 @@
1
1
  import type { ClientOptions, Config } from './client/client';
2
2
  import { type CmsIntegrationApiOptions } from "./config";
3
3
  type CreateConfig<T extends ClientOptions = ClientOptions> = (config?: Config<ClientOptions & T>, apiConfig?: CmsIntegrationApiOptions) => Config<Required<ClientOptions> & T>;
4
+ /**
5
+ * Creates a fully resolved API client configuration.
6
+ *
7
+ * The function combines explicit client configuration with environment-based
8
+ * defaults and sets up bearer token authentication for requests.
9
+ *
10
+ * @param config - Optional core client configuration.
11
+ * @param apiConfig - Optional API integration configuration. When omitted,
12
+ * values are resolved from environment variables.
13
+ * @returns A normalized client configuration with authentication support.
14
+ */
4
15
  export declare const createClientConfig: CreateConfig;
5
16
  export {};
@@ -3,21 +3,33 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createClientConfig = void 0;
4
4
  const config_1 = require("./config");
5
5
  const getaccesstoken_1 = require("./getaccesstoken");
6
+ /**
7
+ * Creates a fully resolved API client configuration.
8
+ *
9
+ * The function combines explicit client configuration with environment-based
10
+ * defaults and sets up bearer token authentication for requests.
11
+ *
12
+ * @param config - Optional core client configuration.
13
+ * @param apiConfig - Optional API integration configuration. When omitted,
14
+ * values are resolved from environment variables.
15
+ * @returns A normalized client configuration with authentication support.
16
+ */
6
17
  const createClientConfig = (config, apiConfig) => {
7
18
  const envConfig = apiConfig || (0, config_1.readPartialEnvConfig)();
8
- const baseUrl = config?.baseUrl && !config.baseUrl.startsWith('/') ? new URL(config.baseUrl) : envConfig?.base ? new URL(config?.baseUrl ?? '/', envConfig.base) : undefined;
19
+ const baseUrl = envConfig.apiBaseUrl?.href ?? config?.baseUrl;
9
20
  // If we don't have a valid base URL just return the config as given
10
21
  if (!baseUrl)
11
22
  return { ...config };
12
- if (!baseUrl.pathname.endsWith('/'))
13
- baseUrl.pathname = baseUrl.pathname + '/';
14
23
  if (envConfig.debug)
15
- console.log(`⚪ [CMS API] Creating API-Client for ${baseUrl.href} as ${envConfig.actAs ?? envConfig.clientId}\n`);
16
- const authBaseUrl = baseUrl.hostname === 'api.cms.optimizely.com' ?
17
- new URL("/", baseUrl) :
18
- baseUrl;
24
+ console.log(`⚪ [CMS API] Creating API-Client for ${baseUrl} as ${envConfig.actAs ?? envConfig.clientId}\n`);
25
+ const authBaseUrl = ((new URL(baseUrl)).hostname.includes('cms.optimizely.com') ?
26
+ new URL('/', baseUrl) :
27
+ new URL('/_cms/v1/', baseUrl)).href;
28
+ if (envConfig.debug)
29
+ console.log(`⚪ [CMS API] Creating API-Client for ${baseUrl}\n`);
19
30
  let clientToken = undefined;
20
31
  const newClientConfig = {
32
+ ...config,
21
33
  security: [{
22
34
  in: 'header',
23
35
  name: 'Authorization',
@@ -32,7 +44,7 @@ const createClientConfig = (config, apiConfig) => {
32
44
  }
33
45
  if (typeof (clientToken) !== 'string' || clientToken.length == 0) {
34
46
  try {
35
- const token = await (0, getaccesstoken_1.getAccessToken)(envConfig, authBaseUrl.href);
47
+ const token = await (0, getaccesstoken_1.getAccessToken)(envConfig, authBaseUrl);
36
48
  clientToken = token;
37
49
  if (envConfig.debug)
38
50
  console.log(`🔑 [CMS API] Using new token`);
@@ -47,8 +59,7 @@ const createClientConfig = (config, apiConfig) => {
47
59
  console.log(`🔑 [CMS API] Using previously generated token`);
48
60
  return clientToken;
49
61
  },
50
- ...config,
51
- baseUrl: baseUrl.href,
62
+ baseUrl: baseUrl,
52
63
  };
53
64
  return newClientConfig;
54
65
  };
package/dist/config.d.ts CHANGED
@@ -1,16 +1,51 @@
1
- import { OptiCmsVersion } from './types';
1
+ /**
2
+ * Configuration options for creating and authenticating a CMS Integration API client.
3
+ */
2
4
  export type CmsIntegrationApiOptions = {
5
+ /**
6
+ * The domain where the CMS instance is running
7
+ */
3
8
  base?: URL;
9
+ /**
10
+ * The OAuth Client ID for the client credentials login
11
+ */
4
12
  clientId?: string;
13
+ /**
14
+ * The OAuth client secret for the client credentials login
15
+ */
5
16
  clientSecret?: string;
17
+ /**
18
+ * The username to impersonate, using the special "actAs"
19
+ * field supported by Optimizely CMS
20
+ */
6
21
  actAs?: string;
22
+ /**
23
+ * Flag to enable debugging output
24
+ */
7
25
  debug?: boolean;
8
26
  /**
9
- * The CMS Schema version that is used
27
+ * The BaseURL where the services are running
10
28
  */
11
- cmsVersion?: OptiCmsVersion;
29
+ apiBaseUrl?: URL;
12
30
  };
13
- type ClientCredentials = 'clientId' | 'clientSecret' | 'cmsVersion';
31
+ type ClientCredentials = 'clientId' | 'clientSecret';
32
+ /**
33
+ * Reads CMS Integration API configuration from environment variables.
34
+ *
35
+ * Client credentials are optional in this variant, which allows callers to
36
+ * bootstrap configuration and decide credential handling separately.
37
+ *
38
+ * @returns A partially populated configuration object.
39
+ */
14
40
  export declare function readPartialEnvConfig(): CmsIntegrationApiOptions;
41
+ /**
42
+ * Reads and validates CMS Integration API configuration from environment variables.
43
+ *
44
+ * This function requires both client credentials to be present and throws when
45
+ * either value is missing.
46
+ *
47
+ * @returns Configuration object with required `clientId` and `clientSecret`.
48
+ * @throws {Error} When a required client credential is missing.
49
+ */
15
50
  export declare function readEnvConfig(): Omit<CmsIntegrationApiOptions, ClientCredentials> & Pick<Required<CmsIntegrationApiOptions>, ClientCredentials>;
16
51
  export {};
package/dist/config.js CHANGED
@@ -2,22 +2,39 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.readPartialEnvConfig = readPartialEnvConfig;
4
4
  exports.readEnvConfig = readEnvConfig;
5
- const types_1 = require("./types");
5
+ /**
6
+ * Reads CMS Integration API configuration from environment variables.
7
+ *
8
+ * Client credentials are optional in this variant, which allows callers to
9
+ * bootstrap configuration and decide credential handling separately.
10
+ *
11
+ * @returns A partially populated configuration object.
12
+ */
6
13
  function readPartialEnvConfig() {
14
+ const apiBaseUrl = getOptional('OPTIMIZELY_CMS_API_BASEURL');
7
15
  const cmsUrl = getOptional('OPTIMIZELY_CMS_URL');
8
16
  const clientId = getOptional('OPTIMIZELY_CMS_CLIENT_ID');
9
17
  const clientSecret = getOptional('OPTIMIZELY_CMS_CLIENT_SECRET');
10
18
  const actAs = getOptional('OPTIMIZELY_CMS_USER_ID');
11
19
  const debug = getOptional('OPTIMIZELY_DEBUG', "0") == "1";
12
- const cmsVersion = getSelection('OPTIMIZELY_CMS_SCHEMA', [types_1.OptiCmsVersion.CMS12, types_1.OptiCmsVersion.CMS13, types_1.OptiCmsVersion.CMSSAAS], types_1.OptiCmsVersion.CMSSAAS);
13
- // Determine the base, if set by the config
20
+ // Determine the CMS URL, if set by the config
14
21
  let base;
15
22
  if (cmsUrl) {
16
23
  try {
17
24
  base = new URL(cmsUrl.includes("://") ? cmsUrl : 'https://' + cmsUrl);
18
25
  }
19
26
  catch (e) {
20
- throw new Error("Invalid Optimizely CMS URL provided");
27
+ throw new Error("Invalid Optimizely CMS URL provided", { cause: e });
28
+ }
29
+ }
30
+ // Determine the API Base path, if set by the config
31
+ let apiBase;
32
+ if (apiBaseUrl) {
33
+ try {
34
+ apiBase = new URL(apiBaseUrl);
35
+ }
36
+ catch (e) {
37
+ throw new Error("Invalid Optimizely CMS API Base URL Provided", { cause: e });
21
38
  }
22
39
  }
23
40
  if (debug)
@@ -28,9 +45,18 @@ function readPartialEnvConfig() {
28
45
  clientSecret,
29
46
  actAs,
30
47
  debug,
31
- cmsVersion
48
+ apiBaseUrl: apiBase
32
49
  };
33
50
  }
51
+ /**
52
+ * Reads and validates CMS Integration API configuration from environment variables.
53
+ *
54
+ * This function requires both client credentials to be present and throws when
55
+ * either value is missing.
56
+ *
57
+ * @returns Configuration object with required `clientId` and `clientSecret`.
58
+ * @throws {Error} When a required client credential is missing.
59
+ */
34
60
  function readEnvConfig() {
35
61
  const partialConfig = readPartialEnvConfig();
36
62
  if (!partialConfig.clientId)
@@ -45,17 +71,17 @@ function getOptional(variable, defaultValue) {
45
71
  return defaultValue;
46
72
  return envValue;
47
73
  }
48
- function getMandatory(variable) {
49
- const envValue = process.env[variable];
50
- if (!envValue)
51
- throw new Error(`The environment variable ${variable} is missing or empty`);
52
- return envValue;
53
- }
54
- function getSelection(envVarName, allowedValues, defaultValue) {
55
- const rawValue = getOptional(envVarName, defaultValue);
56
- if (!rawValue)
57
- return defaultValue;
58
- if (allowedValues.some(av => av == rawValue))
59
- return rawValue;
60
- return defaultValue;
74
+ /*function getMandatory(variable: string): string {
75
+ const envValue = process.env[variable]
76
+ if (!envValue)
77
+ throw new Error(`The environment variable ${variable} is missing or empty`)
78
+ return envValue
61
79
  }
80
+ function getSelection<T>(envVarName: string, allowedValues: T[], defaultValue: T): T {
81
+ const rawValue = getOptional(envVarName, defaultValue as string)
82
+ if (!rawValue)
83
+ return defaultValue
84
+ if (allowedValues.some(av => av == rawValue))
85
+ return rawValue as T
86
+ return defaultValue
87
+ }*/
@@ -19,18 +19,36 @@ async function getAccessToken(config, baseUrl) {
19
19
  headers.append('Connection', 'close');
20
20
  if (options.debug) {
21
21
  console.log(`⚪ [CMS API] Using authentication endpoint: ${authUrl}`);
22
- console.log(`⚪ [CMS API] Retrieving new credentials for ${options.clientId ?? '-'}${options.actAs ? ", acting as " + options.actAs : ""}`);
22
+ console.log(`⚪ [CMS API] Retrieving new credentials for ${options.clientId ?? '-'}`);
23
23
  }
24
24
  const body = new URLSearchParams();
25
25
  body.append("grant_type", "client_credentials");
26
- if (options.actAs)
27
- body.append("act_as", options.actAs);
28
26
  const httpResponse = await fetch(authUrl, {
29
27
  method: "POST",
30
28
  headers: headers,
31
29
  body: body.toString(),
32
30
  cache: "no-store"
33
31
  });
32
+ if (!httpResponse.ok) {
33
+ console.error(`❌ [CMS API] Network error while authenticating: ${httpResponse.status} ${httpResponse.statusText}`);
34
+ if (config?.debug) {
35
+ console.group("Network request");
36
+ console.log(`URL: ${authUrl}`);
37
+ console.log(`Method: POST`);
38
+ headers.entries().forEach(([headerKey, headerValue]) => {
39
+ console.log(`Header ${headerKey}: ${headerValue}`);
40
+ });
41
+ console.log(body.toString());
42
+ console.groupEnd();
43
+ console.group("Network response");
44
+ httpResponse.headers.entries().forEach(([headerKey, headerValue]) => {
45
+ console.log(`Header ${headerKey}: ${headerValue}`);
46
+ });
47
+ console.log(await httpResponse.text());
48
+ console.groupEnd();
49
+ }
50
+ throw new Error(`Network error ${httpResponse.status} ${httpResponse.statusText}`);
51
+ }
34
52
  const response = await httpResponse.json();
35
53
  if (isErrorResponse(response))
36
54
  throw new Error("Authentication error: " + response.error_description);
@@ -40,7 +58,7 @@ function base64Encode(input) {
40
58
  if (btoa && typeof (btoa) == 'function')
41
59
  return btoa(input);
42
60
  if (Buffer && typeof (Buffer) == 'object')
43
- //@ts-expect-error
61
+ //@ts-expect-error We're running in server context, so no need for errors here
44
62
  return Buffer.from(input).toString('base64');
45
63
  throw new Error("Unable to base64Encode");
46
64
  }
package/dist/index.d.ts CHANGED
@@ -1,13 +1,32 @@
1
1
  export * from './config';
2
+ export type * from './types';
2
3
  export * as IntegrationApi from './client/types.gen';
3
4
  export { ApiClient, ApiError, ApiClient as CoreClient, type ApiClientStatic, type CmsIntegrationApiClient } from './api-client';
4
- export { OptiCmsVersion } from "./types";
5
5
  import { type CmsIntegrationApiOptions } from './config';
6
6
  import { type CmsIntegrationApiClient } from './api-client';
7
7
  export { readEnvConfig } from './config';
8
+ /**
9
+ * Type alias describing a CMS Integration API client instance.
10
+ */
8
11
  export type ApiClientInstance = CmsIntegrationApiClient;
12
+ /**
13
+ * Creates a new CMS Integration API client instance.
14
+ *
15
+ * @param config - Optional client configuration.
16
+ * @returns The configured API client.
17
+ */
9
18
  export declare function createClient(config?: CmsIntegrationApiOptions): CmsIntegrationApiClient;
19
+ /**
20
+ * Determines whether a value is a CMS Integration API client instance.
21
+ *
22
+ * @param value - Value to inspect.
23
+ * @returns `true` when the value matches the client instance shape.
24
+ */
10
25
  export declare function isClientInstance(value?: object): value is CmsIntegrationApiClient;
26
+ /**
27
+ * A list of all hard-coded content roots within Optimizely CMS (Both 12+ & SaaS),
28
+ * you need these to be able to start reading content from a given location.
29
+ */
11
30
  export declare enum ContentRoots {
12
31
  /**
13
32
  * The Global root node of the Content Tree
package/dist/index.js CHANGED
@@ -36,7 +36,7 @@ var __importStar = (this && this.__importStar) || (function () {
36
36
  };
37
37
  })();
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.ContentTypeKeys = exports.ContentRoots = exports.readEnvConfig = exports.OptiCmsVersion = exports.CoreClient = exports.ApiError = exports.ApiClient = exports.IntegrationApi = void 0;
39
+ exports.ContentTypeKeys = exports.ContentRoots = exports.readEnvConfig = exports.CoreClient = exports.ApiError = exports.ApiClient = exports.IntegrationApi = void 0;
40
40
  exports.createClient = createClient;
41
41
  exports.isClientInstance = isClientInstance;
42
42
  __exportStar(require("./config"), exports);
@@ -45,19 +45,33 @@ var api_client_1 = require("./api-client");
45
45
  Object.defineProperty(exports, "ApiClient", { enumerable: true, get: function () { return api_client_1.ApiClient; } });
46
46
  Object.defineProperty(exports, "ApiError", { enumerable: true, get: function () { return api_client_1.ApiError; } });
47
47
  Object.defineProperty(exports, "CoreClient", { enumerable: true, get: function () { return api_client_1.ApiClient; } });
48
- var types_1 = require("./types");
49
- Object.defineProperty(exports, "OptiCmsVersion", { enumerable: true, get: function () { return types_1.OptiCmsVersion; } });
50
48
  const api_client_2 = require("./api-client");
51
49
  var config_1 = require("./config");
52
50
  Object.defineProperty(exports, "readEnvConfig", { enumerable: true, get: function () { return config_1.readEnvConfig; } });
51
+ /**
52
+ * Creates a new CMS Integration API client instance.
53
+ *
54
+ * @param config - Optional client configuration.
55
+ * @returns The configured API client.
56
+ */
53
57
  function createClient(config) {
54
58
  return new api_client_2.ApiClient(config);
55
59
  }
60
+ /**
61
+ * Determines whether a value is a CMS Integration API client instance.
62
+ *
63
+ * @param value - Value to inspect.
64
+ * @returns `true` when the value matches the client instance shape.
65
+ */
56
66
  function isClientInstance(value) {
57
67
  if (typeof value !== 'object' || value === null)
58
68
  return false;
59
- return typeof value['getInstanceInfo'] === 'function';
69
+ return typeof value['getSchemaItemBase'] === 'function';
60
70
  }
71
+ /**
72
+ * A list of all hard-coded content roots within Optimizely CMS (Both 12+ & SaaS),
73
+ * you need these to be able to start reading content from a given location.
74
+ */
61
75
  var ContentRoots;
62
76
  (function (ContentRoots) {
63
77
  /**
package/dist/types.d.ts CHANGED
@@ -1,14 +1 @@
1
- export type InstanceApiVersionInfo = {
2
- status: "Healthy";
3
- baseUrl?: string;
4
- statusDuration: number;
5
- apiVersion: string;
6
- serviceVersion: string;
7
- cmsVersion: string;
8
- results: Record<string, any>;
9
- };
10
- export declare enum OptiCmsVersion {
11
- CMS12 = "OPTI-CMS-12",
12
- CMS13 = "OPTI-CMS-13",
13
- CMSSAAS = "OPTI-CMS-SAAS"
14
- }
1
+ export type { OpenAPIV3_1 as OpenAPI } from "openapi-types";
package/dist/types.js CHANGED
@@ -1,9 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OptiCmsVersion = void 0;
4
- var OptiCmsVersion;
5
- (function (OptiCmsVersion) {
6
- OptiCmsVersion["CMS12"] = "OPTI-CMS-12";
7
- OptiCmsVersion["CMS13"] = "OPTI-CMS-13";
8
- OptiCmsVersion["CMSSAAS"] = "OPTI-CMS-SAAS";
9
- })(OptiCmsVersion || (exports.OptiCmsVersion = OptiCmsVersion = {}));
package/dist/version.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "api": "preview3-1.0.0",
3
- "service": "2026.01.06.0826-preview2",
4
- "cms": "2026.01.06.0826-preview2"
2
+ "api": "v1",
3
+ "service": "unknown",
4
+ "cms": "unknown"
5
5
  }
package/package.json CHANGED
@@ -2,25 +2,36 @@
2
2
  "name": "@remkoj/optimizely-cms-api",
3
3
  "displayName": "Optimizely CMS - Integration API Client",
4
4
  "description": "A Javascript client for the Integration API provided by the Optimizely CMS.",
5
- "version": "6.0.0-rc.1",
5
+ "version": "6.0.0-rc.3",
6
6
  "type": "commonjs",
7
7
  "license": "Apache-2.0",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/remkoj/optimizely-dxp-clients.git",
11
+ "directory": "packages/optimizely-cms-api"
12
+ },
13
+ "bugs": "https://github.com/remkoj/optimizely-dxp-clients/issues",
14
+ "homepage": "https://github.com/remkoj/optimizely-dxp-clients/blob/main/packages/optimizely-cms-api/README.md",
8
15
  "main": "./dist/index.js",
9
16
  "types": "./dist/index.d.ts",
10
17
  "files": [
11
- "./dist"
18
+ "./dist",
19
+ "./AGENTS.md"
12
20
  ],
13
21
  "devDependencies": {
14
22
  "@hey-api/client-fetch": "^0.13.1",
15
- "@hey-api/openapi-ts": "^0.94.4",
23
+ "@hey-api/openapi-ts": "^0.99.0",
24
+ "@remkoj/hey-api-wrapper": "6.0.0-rc.3",
16
25
  "rimraf": "^6.1.3"
17
26
  },
18
27
  "dependencies": {
19
- "@types/node": "^22.19.15",
20
- "dotenv": "^17.3.1",
21
- "dotenv-expand": "^12.0.3",
28
+ "@remkoj/hey-api-wrapper": "6.0.0-rc.3",
29
+ "@types/node": "^24.13.3",
30
+ "dotenv": "^17.4.2",
31
+ "dotenv-expand": "^13.0.0",
22
32
  "glob": "^13.0.6",
23
- "openapi-typescript-codegen": "^0.30.0",
33
+ "openapi-types": "^12.1.3",
34
+ "openapi-typescript-codegen": "^0.31.0",
24
35
  "tslib": "^2.8.1",
25
36
  "typescript": "^5.9.3"
26
37
  },
@@ -28,7 +39,7 @@
28
39
  "clean": "rimraf -g ./dist ./src/client ./*.tsbuildinfo",
29
40
  "prepare": "tsc --build && yarn node scripts/copy-client.mjs",
30
41
  "watch": "tsc --watch",
31
- "rebuild": "yarn clean && yarn generate && tsc --build --force",
42
+ "recompile": "yarn clean && yarn generate && tsc --build --force",
32
43
  "generate": "yarn node scripts/create-client.mjs"
33
44
  },
34
45
  "stableVersion": "5.2.0"