@remkoj/optimizely-cms-api 6.0.0-pre9 → 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 (75) hide show
  1. package/AGENTS.md +66 -0
  2. package/README.md +6 -2
  3. package/dist/api-client.d.ts +10 -77
  4. package/dist/api-client.js +18 -171
  5. package/dist/client/client/client.gen.js +114 -102
  6. package/dist/client/client/index.d.ts +3 -1
  7. package/dist/client/client/types.gen.d.ts +9 -13
  8. package/dist/client/client/utils.gen.d.ts +8 -4
  9. package/dist/client/client/utils.gen.js +15 -17
  10. package/dist/client/client.gen.d.ts +2 -2
  11. package/dist/client/client.gen.js +2 -4
  12. package/dist/client/core/auth.gen.d.ts +7 -0
  13. package/dist/client/core/bodySerializer.gen.d.ts +16 -8
  14. package/dist/client/core/bodySerializer.gen.js +1 -1
  15. package/dist/client/core/params.gen.d.ts +12 -2
  16. package/dist/client/core/params.gen.js +40 -20
  17. package/dist/client/core/pathSerializer.gen.js +3 -11
  18. package/dist/client/core/queryKeySerializer.gen.d.ts +1 -1
  19. package/dist/client/core/queryKeySerializer.gen.js +4 -11
  20. package/dist/client/core/serverSentEvents.gen.d.ts +1 -1
  21. package/dist/client/core/serverSentEvents.gen.js +7 -11
  22. package/dist/client/core/types.gen.d.ts +6 -1
  23. package/dist/client/core/utils.gen.js +1 -1
  24. package/dist/client/index.d.ts +4 -4
  25. package/dist/client/index.js +140 -17
  26. package/dist/client/sdk.gen.d.ts +336 -23
  27. package/dist/client/sdk.gen.js +761 -148
  28. package/dist/client/transformers.gen.d.ts +49 -1
  29. package/dist/client/transformers.gen.js +491 -49
  30. package/dist/client/types.gen.d.ts +5323 -466
  31. package/dist/client-config.d.ts +11 -0
  32. package/dist/client-config.js +21 -10
  33. package/dist/config.d.ts +39 -4
  34. package/dist/config.js +44 -18
  35. package/dist/getaccesstoken.js +22 -4
  36. package/dist/index.d.ts +20 -2
  37. package/dist/index.js +18 -5
  38. package/dist/types.d.ts +1 -14
  39. package/dist/types.js +0 -7
  40. package/dist/version.json +3 -3
  41. package/package.json +23 -12
  42. package/dist/instance.client/client/client.gen.d.ts +0 -2
  43. package/dist/instance.client/client/client.gen.js +0 -208
  44. package/dist/instance.client/client/index.d.ts +0 -8
  45. package/dist/instance.client/client/index.js +0 -17
  46. package/dist/instance.client/client/types.gen.d.ts +0 -124
  47. package/dist/instance.client/client/types.gen.js +0 -3
  48. package/dist/instance.client/client/utils.gen.d.ts +0 -33
  49. package/dist/instance.client/client/utils.gen.js +0 -241
  50. package/dist/instance.client/client.gen.d.ts +0 -12
  51. package/dist/instance.client/client.gen.js +0 -9
  52. package/dist/instance.client/core/auth.gen.d.ts +0 -18
  53. package/dist/instance.client/core/auth.gen.js +0 -18
  54. package/dist/instance.client/core/bodySerializer.gen.d.ts +0 -17
  55. package/dist/instance.client/core/bodySerializer.gen.js +0 -60
  56. package/dist/instance.client/core/params.gen.d.ts +0 -33
  57. package/dist/instance.client/core/params.gen.js +0 -92
  58. package/dist/instance.client/core/pathSerializer.gen.d.ts +0 -33
  59. package/dist/instance.client/core/pathSerializer.gen.js +0 -123
  60. package/dist/instance.client/core/queryKeySerializer.gen.d.ts +0 -18
  61. package/dist/instance.client/core/queryKeySerializer.gen.js +0 -105
  62. package/dist/instance.client/core/serverSentEvents.gen.d.ts +0 -71
  63. package/dist/instance.client/core/serverSentEvents.gen.js +0 -139
  64. package/dist/instance.client/core/types.gen.d.ts +0 -78
  65. package/dist/instance.client/core/types.gen.js +0 -3
  66. package/dist/instance.client/core/utils.gen.d.ts +0 -19
  67. package/dist/instance.client/core/utils.gen.js +0 -93
  68. package/dist/instance.client/index.d.ts +0 -4
  69. package/dist/instance.client/index.js +0 -21
  70. package/dist/instance.client/sdk.gen.d.ts +0 -256
  71. package/dist/instance.client/sdk.gen.js +0 -638
  72. package/dist/instance.client/transformers.gen.d.ts +0 -34
  73. package/dist/instance.client/transformers.gen.js +0 -273
  74. package/dist/instance.client/types.gen.d.ts +0 -2838
  75. package/dist/instance.client/types.gen.js +0 -3
@@ -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
- process.stdout.write(`⚪ [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,14 +1,32 @@
1
1
  export * from './config';
2
+ export type * from './types';
2
3
  export * as IntegrationApi from './client/types.gen';
3
- export * as Preview2IntegrationApi from './instance.client/types.gen';
4
4
  export { ApiClient, ApiError, ApiClient as CoreClient, type ApiClientStatic, type CmsIntegrationApiClient } from './api-client';
5
- export { OptiCmsVersion } from "./types";
6
5
  import { type CmsIntegrationApiOptions } from './config';
7
6
  import { type CmsIntegrationApiClient } from './api-client';
8
7
  export { readEnvConfig } from './config';
8
+ /**
9
+ * Type alias describing a CMS Integration API client instance.
10
+ */
9
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
+ */
10
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
+ */
11
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
+ */
12
30
  export declare enum ContentRoots {
13
31
  /**
14
32
  * The Global root node of the Content Tree
package/dist/index.js CHANGED
@@ -36,29 +36,42 @@ 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.Preview2IntegrationApi = 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);
43
43
  exports.IntegrationApi = __importStar(require("./client/types.gen"));
44
- exports.Preview2IntegrationApi = __importStar(require("./instance.client/types.gen"));
45
44
  var api_client_1 = require("./api-client");
46
45
  Object.defineProperty(exports, "ApiClient", { enumerable: true, get: function () { return api_client_1.ApiClient; } });
47
46
  Object.defineProperty(exports, "ApiError", { enumerable: true, get: function () { return api_client_1.ApiError; } });
48
47
  Object.defineProperty(exports, "CoreClient", { enumerable: true, get: function () { return api_client_1.ApiClient; } });
49
- var types_1 = require("./types");
50
- Object.defineProperty(exports, "OptiCmsVersion", { enumerable: true, get: function () { return types_1.OptiCmsVersion; } });
51
48
  const api_client_2 = require("./api-client");
52
49
  var config_1 = require("./config");
53
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
+ */
54
57
  function createClient(config) {
55
58
  return new api_client_2.ApiClient(config);
56
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
+ */
57
66
  function isClientInstance(value) {
58
67
  if (typeof value !== 'object' || value === null)
59
68
  return false;
60
- return typeof value['getInstanceInfo'] === 'function';
69
+ return typeof value['getSchemaItemBase'] === 'function';
61
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
+ */
62
75
  var ContentRoots;
63
76
  (function (ContentRoots) {
64
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": "2025.09.15.0810",
4
- "cms": "2025.09.15.0810"
2
+ "api": "v1",
3
+ "service": "unknown",
4
+ "cms": "unknown"
5
5
  }
package/package.json CHANGED
@@ -2,34 +2,45 @@
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-pre9",
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.85.1",
16
- "rimraf": "^6.0.1"
23
+ "@hey-api/openapi-ts": "^0.99.0",
24
+ "@remkoj/hey-api-wrapper": "6.0.0-rc.3",
25
+ "rimraf": "^6.1.3"
17
26
  },
18
27
  "dependencies": {
19
- "@types/node": "^22.18.10",
20
- "dotenv": "^17.2.3",
21
- "dotenv-expand": "^12.0.3",
22
- "glob": "^11.0.3",
23
- "openapi-typescript-codegen": "^0.29.0",
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",
32
+ "glob": "^13.0.6",
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
  },
27
38
  "scripts": {
28
- "clean": "rimraf -g ./dist ./*.tsbuildinfo ./openapi-ts*log",
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
- "stableVersion": "5.1.0"
45
+ "stableVersion": "5.2.0"
35
46
  }
@@ -1,2 +0,0 @@
1
- import type { Client, Config } from './types.gen';
2
- export declare const createClient: (config?: Config) => Client;
@@ -1,208 +0,0 @@
1
- "use strict";
2
- // This file is auto-generated by @hey-api/openapi-ts
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.createClient = void 0;
5
- const serverSentEvents_gen_1 = require("../core/serverSentEvents.gen");
6
- const utils_gen_1 = require("../core/utils.gen");
7
- const utils_gen_2 = require("./utils.gen");
8
- const createClient = (config = {}) => {
9
- let _config = (0, utils_gen_2.mergeConfigs)((0, utils_gen_2.createConfig)(), config);
10
- const getConfig = () => ({ ..._config });
11
- const setConfig = (config) => {
12
- _config = (0, utils_gen_2.mergeConfigs)(_config, config);
13
- return getConfig();
14
- };
15
- const interceptors = (0, utils_gen_2.createInterceptors)();
16
- const beforeRequest = async (options) => {
17
- const opts = {
18
- ..._config,
19
- ...options,
20
- fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
21
- headers: (0, utils_gen_2.mergeHeaders)(_config.headers, options.headers),
22
- serializedBody: undefined,
23
- };
24
- if (opts.security) {
25
- await (0, utils_gen_2.setAuthParams)({
26
- ...opts,
27
- security: opts.security,
28
- });
29
- }
30
- if (opts.requestValidator) {
31
- await opts.requestValidator(opts);
32
- }
33
- if (opts.body !== undefined && opts.bodySerializer) {
34
- opts.serializedBody = opts.bodySerializer(opts.body);
35
- }
36
- // remove Content-Type header if body is empty to avoid sending invalid requests
37
- if (opts.body === undefined || opts.serializedBody === '') {
38
- opts.headers.delete('Content-Type');
39
- }
40
- const url = (0, utils_gen_2.buildUrl)(opts);
41
- return { opts, url };
42
- };
43
- const request = async (options) => {
44
- // @ts-expect-error
45
- const { opts, url } = await beforeRequest(options);
46
- const requestInit = {
47
- redirect: 'follow',
48
- ...opts,
49
- body: (0, utils_gen_1.getValidRequestBody)(opts),
50
- };
51
- let request = new Request(url, requestInit);
52
- for (const fn of interceptors.request.fns) {
53
- if (fn) {
54
- request = await fn(request, opts);
55
- }
56
- }
57
- // fetch must be assigned here, otherwise it would throw the error:
58
- // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
59
- const _fetch = opts.fetch;
60
- let response = await _fetch(request);
61
- for (const fn of interceptors.response.fns) {
62
- if (fn) {
63
- response = await fn(response, request, opts);
64
- }
65
- }
66
- const result = {
67
- request,
68
- response,
69
- };
70
- if (response.ok) {
71
- const parseAs = (opts.parseAs === 'auto'
72
- ? (0, utils_gen_2.getParseAs)(response.headers.get('Content-Type'))
73
- : opts.parseAs) ?? 'json';
74
- if (response.status === 204 ||
75
- response.headers.get('Content-Length') === '0') {
76
- let emptyData;
77
- switch (parseAs) {
78
- case 'arrayBuffer':
79
- case 'blob':
80
- case 'text':
81
- emptyData = await response[parseAs]();
82
- break;
83
- case 'formData':
84
- emptyData = new FormData();
85
- break;
86
- case 'stream':
87
- emptyData = response.body;
88
- break;
89
- case 'json':
90
- default:
91
- emptyData = {};
92
- break;
93
- }
94
- return opts.responseStyle === 'data'
95
- ? emptyData
96
- : {
97
- data: emptyData,
98
- ...result,
99
- };
100
- }
101
- let data;
102
- switch (parseAs) {
103
- case 'arrayBuffer':
104
- case 'blob':
105
- case 'formData':
106
- case 'json':
107
- case 'text':
108
- data = await response[parseAs]();
109
- break;
110
- case 'stream':
111
- return opts.responseStyle === 'data'
112
- ? response.body
113
- : {
114
- data: response.body,
115
- ...result,
116
- };
117
- }
118
- if (parseAs === 'json') {
119
- if (opts.responseValidator) {
120
- await opts.responseValidator(data);
121
- }
122
- if (opts.responseTransformer) {
123
- data = await opts.responseTransformer(data);
124
- }
125
- }
126
- return opts.responseStyle === 'data'
127
- ? data
128
- : {
129
- data,
130
- ...result,
131
- };
132
- }
133
- const textError = await response.text();
134
- let jsonError;
135
- try {
136
- jsonError = JSON.parse(textError);
137
- }
138
- catch {
139
- // noop
140
- }
141
- const error = jsonError ?? textError;
142
- let finalError = error;
143
- for (const fn of interceptors.error.fns) {
144
- if (fn) {
145
- finalError = (await fn(error, response, request, opts));
146
- }
147
- }
148
- finalError = finalError || {};
149
- if (opts.throwOnError) {
150
- throw finalError;
151
- }
152
- // TODO: we probably want to return error and improve types
153
- return opts.responseStyle === 'data'
154
- ? undefined
155
- : {
156
- error: finalError,
157
- ...result,
158
- };
159
- };
160
- const makeMethodFn = (method) => (options) => request({ ...options, method });
161
- const makeSseFn = (method) => async (options) => {
162
- const { opts, url } = await beforeRequest(options);
163
- return (0, serverSentEvents_gen_1.createSseClient)({
164
- ...opts,
165
- body: opts.body,
166
- headers: opts.headers,
167
- method,
168
- onRequest: async (url, init) => {
169
- let request = new Request(url, init);
170
- for (const fn of interceptors.request.fns) {
171
- if (fn) {
172
- request = await fn(request, opts);
173
- }
174
- }
175
- return request;
176
- },
177
- url,
178
- });
179
- };
180
- return {
181
- buildUrl: utils_gen_2.buildUrl,
182
- connect: makeMethodFn('CONNECT'),
183
- delete: makeMethodFn('DELETE'),
184
- get: makeMethodFn('GET'),
185
- getConfig,
186
- head: makeMethodFn('HEAD'),
187
- interceptors,
188
- options: makeMethodFn('OPTIONS'),
189
- patch: makeMethodFn('PATCH'),
190
- post: makeMethodFn('POST'),
191
- put: makeMethodFn('PUT'),
192
- request,
193
- setConfig,
194
- sse: {
195
- connect: makeSseFn('CONNECT'),
196
- delete: makeSseFn('DELETE'),
197
- get: makeSseFn('GET'),
198
- head: makeSseFn('HEAD'),
199
- options: makeSseFn('OPTIONS'),
200
- patch: makeSseFn('PATCH'),
201
- post: makeSseFn('POST'),
202
- put: makeSseFn('PUT'),
203
- trace: makeSseFn('TRACE'),
204
- },
205
- trace: makeMethodFn('TRACE'),
206
- };
207
- };
208
- exports.createClient = createClient;