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

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 (52) hide show
  1. package/LICENSE +12 -12
  2. package/README.md +7 -5
  3. package/dist/api-client.d.ts +9 -6
  4. package/dist/api-client.js +45 -40
  5. package/dist/client/client/{client.d.ts → client.gen.d.ts} +1 -1
  6. package/dist/client/client/client.gen.js +239 -0
  7. package/dist/client/client/index.d.ts +8 -7
  8. package/dist/client/client/index.js +15 -12
  9. package/dist/client/client/{types.d.ts → types.gen.d.ts} +17 -19
  10. package/dist/client/{core/types.js → client/types.gen.js} +1 -0
  11. package/dist/client/client/{utils.d.ts → utils.gen.d.ts} +9 -21
  12. package/dist/client/client/{utils.js → utils.gen.js} +67 -124
  13. package/dist/client/client.gen.d.ts +3 -3
  14. package/dist/client/client.gen.js +2 -4
  15. package/dist/client/core/{auth.js → auth.gen.js} +1 -0
  16. package/dist/client/core/bodySerializer.gen.d.ts +25 -0
  17. package/dist/client/core/{bodySerializer.js → bodySerializer.gen.js} +5 -1
  18. package/dist/client/core/{params.d.ts → params.gen.d.ts} +20 -0
  19. package/dist/client/core/{params.js → params.gen.js} +19 -6
  20. package/dist/client/core/{pathSerializer.js → pathSerializer.gen.js} +4 -11
  21. package/dist/client/core/queryKeySerializer.gen.d.ts +18 -0
  22. package/dist/client/core/queryKeySerializer.gen.js +98 -0
  23. package/dist/client/core/serverSentEvents.gen.d.ts +71 -0
  24. package/dist/client/core/serverSentEvents.gen.js +137 -0
  25. package/dist/client/core/{types.d.ts → types.gen.d.ts} +19 -14
  26. package/dist/client/{client/types.js → core/types.gen.js} +1 -0
  27. package/dist/client/core/utils.gen.d.ts +19 -0
  28. package/dist/client/core/utils.gen.js +93 -0
  29. package/dist/client/index.d.ts +4 -4
  30. package/dist/client/index.js +99 -19
  31. package/dist/client/sdk.gen.d.ts +124 -70
  32. package/dist/client/sdk.gen.js +448 -490
  33. package/dist/client/transformers.gen.d.ts +14 -4
  34. package/dist/client/transformers.gen.js +143 -59
  35. package/dist/client/types.gen.d.ts +1231 -856
  36. package/dist/client/types.gen.js +0 -84
  37. package/dist/client-config.d.ts +5 -2
  38. package/dist/client-config.js +42 -14
  39. package/dist/config.d.ts +2 -3
  40. package/dist/config.js +13 -42
  41. package/dist/getaccesstoken.d.ts +1 -1
  42. package/dist/getaccesstoken.js +9 -7
  43. package/dist/index.d.ts +3 -1
  44. package/dist/index.js +7 -1
  45. package/dist/types.d.ts +3 -1
  46. package/dist/types.js +1 -0
  47. package/dist/version.json +3 -3
  48. package/package.json +11 -15
  49. package/dist/client/client/client.js +0 -149
  50. package/dist/client/core/bodySerializer.d.ts +0 -17
  51. /package/dist/client/core/{auth.d.ts → auth.gen.d.ts} +0 -0
  52. /package/dist/client/core/{pathSerializer.d.ts → pathSerializer.gen.d.ts} +0 -0
@@ -1,87 +1,3 @@
1
1
  "use strict";
2
2
  // This file is auto-generated by @hey-api/openapi-ts
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.VersionStatus = exports.PropertyDataType = exports.LocaleStatus = exports.IndexingType = exports.ContentTypeUsage = exports.ContentTypeFeature = exports.ContentBaseType = exports.CompositionBehavior = void 0;
5
- /**
6
- * Represent a Composition behavior for a ContentType.
7
- */
8
- exports.CompositionBehavior = {
9
- SECTION_ENABLED: 'sectionEnabled',
10
- ELEMENT_ENABLED: 'elementEnabled'
11
- };
12
- /**
13
- * Represent the base type of a ContentType.
14
- */
15
- exports.ContentBaseType = {
16
- PAGE: 'page',
17
- COMPONENT: 'component',
18
- MEDIA: 'media',
19
- IMAGE: 'image',
20
- VIDEO: 'video',
21
- FOLDER: 'folder',
22
- EXPERIENCE: 'experience',
23
- SECTION: 'section',
24
- ELEMENT: 'element'
25
- };
26
- /**
27
- * Represent different features that a content type can have.
28
- */
29
- exports.ContentTypeFeature = {
30
- LOCALIZATION: 'localization',
31
- VERSIONING: 'versioning',
32
- PUBLISH_PERIOD: 'publishPeriod',
33
- ROUTING: 'routing',
34
- BINARY: 'binary'
35
- };
36
- /**
37
- * Represent the usage types for a ContentType.
38
- */
39
- exports.ContentTypeUsage = {
40
- PROPERTY: 'property',
41
- INSTANCE: 'instance'
42
- };
43
- /**
44
- * Represents the indexing type of a content type property.
45
- */
46
- exports.IndexingType = {
47
- DISABLED: 'disabled',
48
- QUERYABLE: 'queryable',
49
- SEARCHABLE: 'searchable'
50
- };
51
- /**
52
- * Represent the different status values of a content locale.
53
- */
54
- exports.LocaleStatus = {
55
- DRAFT: 'draft',
56
- PUBLISHED: 'published'
57
- };
58
- /**
59
- * Represent the basic type that a PropertyFormat
60
- * is using for data storage and data transport.
61
- */
62
- exports.PropertyDataType = {
63
- STRING: 'string',
64
- URL: 'url',
65
- BOOLEAN: 'boolean',
66
- INTEGER: 'integer',
67
- FLOAT: 'float',
68
- DATE_TIME: 'dateTime',
69
- CONTENT_REFERENCE: 'contentReference',
70
- CONTENT: 'content',
71
- BINARY: 'binary',
72
- JSON: 'json',
73
- ARRAY: 'array',
74
- COMPONENT: 'component'
75
- };
76
- /**
77
- * Represent the different status values of a content version.
78
- */
79
- exports.VersionStatus = {
80
- DRAFT: 'draft',
81
- READY: 'ready',
82
- PUBLISHED: 'published',
83
- PREVIOUS: 'previous',
84
- SCHEDULED: 'scheduled',
85
- REJECTED: 'rejected',
86
- IN_REVIEW: 'inReview'
87
- };
@@ -1,2 +1,5 @@
1
- import type { CreateClientConfig } from './client/client.gen';
2
- export declare const createClientConfig: CreateClientConfig;
1
+ import type { ClientOptions, Config } from './client/client';
2
+ import { type CmsIntegrationApiOptions } from "./config";
3
+ type CreateConfig<T extends ClientOptions = ClientOptions> = (config?: Config<ClientOptions & T>, apiConfig?: CmsIntegrationApiOptions) => Config<Required<ClientOptions> & T>;
4
+ export declare const createClientConfig: CreateConfig;
5
+ export {};
@@ -3,25 +3,53 @@ 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
- const createClientConfig = (config) => {
7
- const envConfig = (0, config_1.readPartialEnvConfig)();
8
- const baseUrl = envConfig.base.href;
6
+ const createClientConfig = (config, apiConfig) => {
7
+ 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;
9
+ // If we don't have a valid base URL just return the config as given
10
+ if (!baseUrl)
11
+ return { ...config };
12
+ if (!baseUrl.pathname.endsWith('/'))
13
+ baseUrl.pathname = baseUrl.pathname + '/';
14
+ 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;
19
+ let clientToken = undefined;
9
20
  const newClientConfig = {
10
- baseUrl,
11
- auth: (auth) => {
12
- auth.scheme = "bearer";
13
- auth.type = "apiKey";
14
- return (0, getaccesstoken_1.getAccessToken)(envConfig).catch((error) => {
15
- if (envConfig?.debug)
16
- console.error(`❌ Error while resolving the Access Token`, error);
21
+ security: [{
22
+ in: 'header',
23
+ name: 'Authorization',
24
+ scheme: 'bearer',
25
+ type: 'apiKey'
26
+ }],
27
+ auth: async (auth) => {
28
+ if (auth.type !== 'apiKey' || auth.scheme !== 'bearer') {
29
+ if (envConfig.debug)
30
+ console.error(`❌ [CMS API] Unsupported auth model`, auth);
17
31
  return undefined;
18
- });
32
+ }
33
+ if (typeof (clientToken) !== 'string' || clientToken.length == 0) {
34
+ try {
35
+ const token = await (0, getaccesstoken_1.getAccessToken)(envConfig, authBaseUrl.href);
36
+ clientToken = token;
37
+ if (envConfig.debug)
38
+ console.log(`🔑 [CMS API] Using new token`);
39
+ }
40
+ catch (error) {
41
+ if (envConfig.debug)
42
+ console.error(`❌ [CMS API] Error while resolving the Access Token`, error);
43
+ clientToken = undefined;
44
+ }
45
+ }
46
+ else if (envConfig.debug)
47
+ console.log(`🔑 [CMS API] Using previously generated token`);
48
+ return clientToken;
19
49
  },
20
50
  ...config,
51
+ baseUrl: baseUrl.href,
21
52
  };
22
- // Ensure the baseUrl is set
23
- if (!newClientConfig.baseUrl)
24
- newClientConfig.baseUrl = baseUrl;
25
53
  return newClientConfig;
26
54
  };
27
55
  exports.createClientConfig = createClientConfig;
package/dist/config.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { OptiCmsVersion } from './types';
2
2
  export type CmsIntegrationApiOptions = {
3
- base: URL;
3
+ base?: URL;
4
4
  clientId?: string;
5
5
  clientSecret?: string;
6
6
  actAs?: string;
@@ -10,8 +10,7 @@ export type CmsIntegrationApiOptions = {
10
10
  */
11
11
  cmsVersion?: OptiCmsVersion;
12
12
  };
13
- type ClientCredentials = 'clientId' | 'clientSecret';
13
+ type ClientCredentials = 'clientId' | 'clientSecret' | 'cmsVersion';
14
14
  export declare function readPartialEnvConfig(): CmsIntegrationApiOptions;
15
15
  export declare function readEnvConfig(): Omit<CmsIntegrationApiOptions, ClientCredentials> & Pick<Required<CmsIntegrationApiOptions>, ClientCredentials>;
16
- export declare function getCmsIntegrationApiConfigFromEnvironment(): CmsIntegrationApiOptions;
17
16
  export {};
package/dist/config.js CHANGED
@@ -2,29 +2,28 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.readPartialEnvConfig = readPartialEnvConfig;
4
4
  exports.readEnvConfig = readEnvConfig;
5
- exports.getCmsIntegrationApiConfigFromEnvironment = getCmsIntegrationApiConfigFromEnvironment;
6
5
  const types_1 = require("./types");
7
6
  function readPartialEnvConfig() {
8
- const cmsUrl = getOptional('OPTIMIZELY_CMS_URL', 'https://api.cms.optimizely.com');
7
+ const cmsUrl = getOptional('OPTIMIZELY_CMS_URL');
9
8
  const clientId = getOptional('OPTIMIZELY_CMS_CLIENT_ID');
10
9
  const clientSecret = getOptional('OPTIMIZELY_CMS_CLIENT_SECRET');
11
10
  const actAs = getOptional('OPTIMIZELY_CMS_USER_ID');
12
11
  const debug = getOptional('OPTIMIZELY_DEBUG', "0") == "1";
13
- const cmsVersion = getSelection('OPTIMIZELY_CMS_SCHEMA', [types_1.OptiCmsVersion.CMS12, types_1.OptiCmsVersion.CMS13], types_1.OptiCmsVersion.CMS13);
14
- let baseUrl;
15
- try {
16
- const cmsUrlAdjusted = cmsUrl.includes("://") ? cmsUrl : 'https://' + cmsUrl;
17
- baseUrl = new URL('/_cms/preview2', cmsUrlAdjusted);
18
- if (cmsVersion == types_1.OptiCmsVersion.CMS12)
19
- baseUrl.pathname = baseUrl.pathname.replace('preview2', 'preview1');
20
- }
21
- catch (e) {
22
- throw new Error("Invalid Optimizely CMS URL provided");
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
14
+ let base;
15
+ if (cmsUrl) {
16
+ try {
17
+ base = new URL(cmsUrl.includes("://") ? cmsUrl : 'https://' + cmsUrl);
18
+ }
19
+ catch (e) {
20
+ throw new Error("Invalid Optimizely CMS URL provided");
21
+ }
23
22
  }
24
23
  if (debug)
25
- console.log(`[Optimizely CMS API] Connecting to ${baseUrl} as ${clientId ?? 'Anonymous'}`);
24
+ console.log(`[Optimizely CMS API] Connecting to ${base || 'CMS API HOST'} as ${clientId ?? 'Anonymous'}`);
26
25
  return {
27
- base: baseUrl,
26
+ base,
28
27
  clientId,
29
28
  clientSecret,
30
29
  actAs,
@@ -40,34 +39,6 @@ function readEnvConfig() {
40
39
  throw new Error("The Client Secret (OPTIMIZELY_CMS_CLIENT_SECRET) is a required environment variable");
41
40
  return partialConfig;
42
41
  }
43
- function getCmsIntegrationApiConfigFromEnvironment() {
44
- const cmsUrl = getOptional('OPTIMIZELY_CMS_URL', 'https://api.cms.optimizely.com');
45
- const clientId = getMandatory('OPTIMIZELY_CMS_CLIENT_ID');
46
- const clientSecret = getMandatory('OPTIMIZELY_CMS_CLIENT_SECRET');
47
- const actAs = getOptional('OPTIMIZELY_CMS_USER_ID');
48
- const debug = getOptional('OPTIMIZELY_DEBUG', "0") == "1";
49
- const cmsVersion = getSelection('OPTIMIZELY_CMS_SCHEMA', [types_1.OptiCmsVersion.CMS12, types_1.OptiCmsVersion.CMS13], types_1.OptiCmsVersion.CMS13);
50
- let baseUrl;
51
- try {
52
- const cmsUrlAdjusted = cmsUrl.includes("://") ? cmsUrl : 'https://' + cmsUrl;
53
- baseUrl = new URL('/_cms/preview2', cmsUrlAdjusted);
54
- if (cmsVersion == types_1.OptiCmsVersion.CMS12)
55
- baseUrl.pathname = baseUrl.pathname.replace('preview2', 'preview1');
56
- }
57
- catch (e) {
58
- throw new Error("Invalid Optimizely CMS URL provided");
59
- }
60
- if (debug)
61
- console.log(`[Optimizely CMS API] Connecting to ${baseUrl} as ${clientId}`);
62
- return {
63
- base: baseUrl,
64
- clientId,
65
- clientSecret,
66
- actAs,
67
- debug,
68
- cmsVersion
69
- };
70
- }
71
42
  function getOptional(variable, defaultValue) {
72
43
  const envValue = process.env[variable];
73
44
  if (!envValue || envValue == "")
@@ -1,3 +1,3 @@
1
1
  import { type CmsIntegrationApiOptions } from "./config";
2
- export declare function getAccessToken(config?: CmsIntegrationApiOptions): Promise<string>;
2
+ export declare function getAccessToken(config?: CmsIntegrationApiOptions, baseUrl?: string): Promise<string>;
3
3
  export default getAccessToken;
@@ -2,22 +2,24 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getAccessToken = getAccessToken;
4
4
  const config_1 = require("./config");
5
- const types_1 = require("./types");
6
5
  function isErrorResponse(response) {
7
6
  return typeof (response.error) == 'string';
8
7
  }
9
- async function getAccessToken(config) {
10
- const options = config ?? (0, config_1.getCmsIntegrationApiConfigFromEnvironment)();
11
- let authUrl = new URL(`/_cms/preview2/oauth/token`, options.base).href;
8
+ async function getAccessToken(config, baseUrl) {
9
+ const options = config ?? (0, config_1.readEnvConfig)();
10
+ const authUrl = new URL(`oauth/token`, baseUrl ?? options.base ?? 'https://api.cms.optimizely.com/').href;
12
11
  const headers = new Headers();
13
- if (options.cmsVersion == types_1.OptiCmsVersion.CMS12)
14
- authUrl = authUrl.replace('preview2', 'preview1');
12
+ if (!options.clientId || !options.clientSecret) {
13
+ if (options.debug)
14
+ console.log(`❌ [CMS API] Skipping authentication due to missing clientId or clientSecret`);
15
+ return '';
16
+ }
15
17
  headers.append('Authorization', `Basic ${base64Encode(`${options.clientId ?? ''}:${options.clientSecret ?? ''}`)}`);
16
18
  headers.append('Content-Type', 'application/x-www-form-urlencoded');
17
19
  headers.append('Connection', 'close');
18
20
  if (options.debug) {
19
21
  console.log(`⚪ [CMS API] Using authentication endpoint: ${authUrl}`);
20
- console.log(`⚪ [CMS API] Retrieving new credentials for ${options.clientId}, acting as ${options.actAs ?? options.clientId ?? '-'}`);
22
+ console.log(`⚪ [CMS API] Retrieving new credentials for ${options.clientId ?? '-'}${options.actAs ? ", acting as " + options.actAs : ""}`);
21
23
  }
22
24
  const body = new URLSearchParams();
23
25
  body.append("grant_type", "client_credentials");
package/dist/index.d.ts CHANGED
@@ -4,8 +4,10 @@ export { ApiClient, ApiError, ApiClient as CoreClient, type ApiClientStatic, typ
4
4
  export { OptiCmsVersion } from "./types";
5
5
  import { type CmsIntegrationApiOptions } from './config';
6
6
  import { type CmsIntegrationApiClient } from './api-client';
7
- export { getCmsIntegrationApiConfigFromEnvironment as readEnvConfig } from './config';
7
+ export { readEnvConfig } from './config';
8
+ export type ApiClientInstance = CmsIntegrationApiClient;
8
9
  export declare function createClient(config?: CmsIntegrationApiOptions): CmsIntegrationApiClient;
10
+ export declare function isClientInstance(value?: object): value is CmsIntegrationApiClient;
9
11
  export declare enum ContentRoots {
10
12
  /**
11
13
  * The Global root node of the Content Tree
package/dist/index.js CHANGED
@@ -38,6 +38,7 @@ var __importStar = (this && this.__importStar) || (function () {
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.ContentTypeKeys = exports.ContentRoots = exports.readEnvConfig = exports.OptiCmsVersion = exports.CoreClient = exports.ApiError = exports.ApiClient = exports.IntegrationApi = void 0;
40
40
  exports.createClient = createClient;
41
+ exports.isClientInstance = isClientInstance;
41
42
  __exportStar(require("./config"), exports);
42
43
  exports.IntegrationApi = __importStar(require("./client/types.gen"));
43
44
  var api_client_1 = require("./api-client");
@@ -48,10 +49,15 @@ var types_1 = require("./types");
48
49
  Object.defineProperty(exports, "OptiCmsVersion", { enumerable: true, get: function () { return types_1.OptiCmsVersion; } });
49
50
  const api_client_2 = require("./api-client");
50
51
  var config_1 = require("./config");
51
- Object.defineProperty(exports, "readEnvConfig", { enumerable: true, get: function () { return config_1.getCmsIntegrationApiConfigFromEnvironment; } });
52
+ Object.defineProperty(exports, "readEnvConfig", { enumerable: true, get: function () { return config_1.readEnvConfig; } });
52
53
  function createClient(config) {
53
54
  return new api_client_2.ApiClient(config);
54
55
  }
56
+ function isClientInstance(value) {
57
+ if (typeof value !== 'object' || value === null)
58
+ return false;
59
+ return typeof value['getInstanceInfo'] === 'function';
60
+ }
55
61
  var ContentRoots;
56
62
  (function (ContentRoots) {
57
63
  /**
package/dist/types.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export type InstanceApiVersionInfo = {
2
2
  status: "Healthy";
3
+ baseUrl?: string;
3
4
  statusDuration: number;
4
5
  apiVersion: string;
5
6
  serviceVersion: string;
@@ -8,5 +9,6 @@ export type InstanceApiVersionInfo = {
8
9
  };
9
10
  export declare enum OptiCmsVersion {
10
11
  CMS12 = "OPTI-CMS-12",
11
- CMS13 = "OPTI-CMS-13"
12
+ CMS13 = "OPTI-CMS-13",
13
+ CMSSAAS = "OPTI-CMS-SAAS"
12
14
  }
package/dist/types.js CHANGED
@@ -5,4 +5,5 @@ var OptiCmsVersion;
5
5
  (function (OptiCmsVersion) {
6
6
  OptiCmsVersion["CMS12"] = "OPTI-CMS-12";
7
7
  OptiCmsVersion["CMS13"] = "OPTI-CMS-13";
8
+ OptiCmsVersion["CMSSAAS"] = "OPTI-CMS-SAAS";
8
9
  })(OptiCmsVersion || (exports.OptiCmsVersion = OptiCmsVersion = {}));
package/dist/version.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "api": "preview2-1.0.0",
3
- "service": "2025.06.18.1736",
4
- "cms": "2025.06.18.1736"
2
+ "api": "preview3-1.0.0",
3
+ "service": "2026.01.06.0826-preview2",
4
+ "cms": "2026.01.06.0826-preview2"
5
5
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
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-pre8",
5
+ "version": "6.0.0-rc.1",
6
6
  "type": "commonjs",
7
7
  "license": "Apache-2.0",
8
8
  "main": "./dist/index.js",
@@ -12,28 +12,24 @@
12
12
  ],
13
13
  "devDependencies": {
14
14
  "@hey-api/client-fetch": "^0.13.1",
15
- "@hey-api/openapi-ts": "^0.78.3",
16
- "@types/node": "^22.16.4",
17
- "dotenv": "^17.2.0",
18
- "dotenv-expand": "^12.0.2",
19
- "glob": "^11.0.3",
20
- "rimraf": "^6.0.1",
21
- "typescript": "^5.8.3"
15
+ "@hey-api/openapi-ts": "^0.94.4",
16
+ "rimraf": "^6.1.3"
22
17
  },
23
18
  "dependencies": {
24
- "@types/node": "^22.16.4",
25
- "dotenv": "^17.2.0",
26
- "glob": "^11.0.3",
27
- "openapi-typescript-codegen": "^0.29.0",
19
+ "@types/node": "^22.19.15",
20
+ "dotenv": "^17.3.1",
21
+ "dotenv-expand": "^12.0.3",
22
+ "glob": "^13.0.6",
23
+ "openapi-typescript-codegen": "^0.30.0",
28
24
  "tslib": "^2.8.1",
29
- "typescript": "^5.8.3"
25
+ "typescript": "^5.9.3"
30
26
  },
31
27
  "scripts": {
32
- "clean": "rimraf -g ./dist ./*.tsbuildinfo && rimraf -g ./openapi-ts*log",
28
+ "clean": "rimraf -g ./dist ./src/client ./*.tsbuildinfo",
33
29
  "prepare": "tsc --build && yarn node scripts/copy-client.mjs",
34
30
  "watch": "tsc --watch",
35
31
  "rebuild": "yarn clean && yarn generate && tsc --build --force",
36
32
  "generate": "yarn node scripts/create-client.mjs"
37
33
  },
38
- "stableVersion": "5.1.0"
34
+ "stableVersion": "5.2.0"
39
35
  }
@@ -1,149 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createClient = void 0;
4
- const utils_1 = require("./utils");
5
- const createClient = (config = {}) => {
6
- let _config = (0, utils_1.mergeConfigs)((0, utils_1.createConfig)(), config);
7
- const getConfig = () => ({ ..._config });
8
- const setConfig = (config) => {
9
- _config = (0, utils_1.mergeConfigs)(_config, config);
10
- return getConfig();
11
- };
12
- const interceptors = (0, utils_1.createInterceptors)();
13
- const request = async (options) => {
14
- const opts = {
15
- ..._config,
16
- ...options,
17
- fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
18
- headers: (0, utils_1.mergeHeaders)(_config.headers, options.headers),
19
- };
20
- if (opts.security) {
21
- await (0, utils_1.setAuthParams)({
22
- ...opts,
23
- security: opts.security,
24
- });
25
- }
26
- if (opts.requestValidator) {
27
- await opts.requestValidator(opts);
28
- }
29
- if (opts.body && opts.bodySerializer) {
30
- opts.body = opts.bodySerializer(opts.body);
31
- }
32
- // remove Content-Type header if body is empty to avoid sending invalid requests
33
- if (opts.body === undefined || opts.body === '') {
34
- opts.headers.delete('Content-Type');
35
- }
36
- const url = (0, utils_1.buildUrl)(opts);
37
- const requestInit = {
38
- redirect: 'follow',
39
- ...opts,
40
- };
41
- let request = new Request(url, requestInit);
42
- for (const fn of interceptors.request._fns) {
43
- if (fn) {
44
- request = await fn(request, opts);
45
- }
46
- }
47
- // fetch must be assigned here, otherwise it would throw the error:
48
- // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
49
- const _fetch = opts.fetch;
50
- let response = await _fetch(request);
51
- for (const fn of interceptors.response._fns) {
52
- if (fn) {
53
- response = await fn(response, request, opts);
54
- }
55
- }
56
- const result = {
57
- request,
58
- response,
59
- };
60
- if (response.ok) {
61
- if (response.status === 204 ||
62
- response.headers.get('Content-Length') === '0') {
63
- return opts.responseStyle === 'data'
64
- ? {}
65
- : {
66
- data: {},
67
- ...result,
68
- };
69
- }
70
- const parseAs = (opts.parseAs === 'auto'
71
- ? (0, utils_1.getParseAs)(response.headers.get('Content-Type'))
72
- : opts.parseAs) ?? 'json';
73
- let data;
74
- switch (parseAs) {
75
- case 'arrayBuffer':
76
- case 'blob':
77
- case 'formData':
78
- case 'json':
79
- case 'text':
80
- data = await response[parseAs]();
81
- break;
82
- case 'stream':
83
- return opts.responseStyle === 'data'
84
- ? response.body
85
- : {
86
- data: response.body,
87
- ...result,
88
- };
89
- }
90
- if (parseAs === 'json') {
91
- if (opts.responseValidator) {
92
- await opts.responseValidator(data);
93
- }
94
- if (opts.responseTransformer) {
95
- data = await opts.responseTransformer(data);
96
- }
97
- }
98
- return opts.responseStyle === 'data'
99
- ? data
100
- : {
101
- data,
102
- ...result,
103
- };
104
- }
105
- const textError = await response.text();
106
- let jsonError;
107
- try {
108
- jsonError = JSON.parse(textError);
109
- }
110
- catch {
111
- // noop
112
- }
113
- const error = jsonError ?? textError;
114
- let finalError = error;
115
- for (const fn of interceptors.error._fns) {
116
- if (fn) {
117
- finalError = (await fn(error, response, request, opts));
118
- }
119
- }
120
- finalError = finalError || {};
121
- if (opts.throwOnError) {
122
- throw finalError;
123
- }
124
- // TODO: we probably want to return error and improve types
125
- return opts.responseStyle === 'data'
126
- ? undefined
127
- : {
128
- error: finalError,
129
- ...result,
130
- };
131
- };
132
- return {
133
- buildUrl: utils_1.buildUrl,
134
- connect: (options) => request({ ...options, method: 'CONNECT' }),
135
- delete: (options) => request({ ...options, method: 'DELETE' }),
136
- get: (options) => request({ ...options, method: 'GET' }),
137
- getConfig,
138
- head: (options) => request({ ...options, method: 'HEAD' }),
139
- interceptors,
140
- options: (options) => request({ ...options, method: 'OPTIONS' }),
141
- patch: (options) => request({ ...options, method: 'PATCH' }),
142
- post: (options) => request({ ...options, method: 'POST' }),
143
- put: (options) => request({ ...options, method: 'PUT' }),
144
- request,
145
- setConfig,
146
- trace: (options) => request({ ...options, method: 'TRACE' }),
147
- };
148
- };
149
- exports.createClient = createClient;
@@ -1,17 +0,0 @@
1
- import type { ArrayStyle, ObjectStyle, SerializerOptions } from './pathSerializer';
2
- export type QuerySerializer = (query: Record<string, unknown>) => string;
3
- export type BodySerializer = (body: any) => any;
4
- export interface QuerySerializerOptions {
5
- allowReserved?: boolean;
6
- array?: SerializerOptions<ArrayStyle>;
7
- object?: SerializerOptions<ObjectStyle>;
8
- }
9
- export declare const formDataBodySerializer: {
10
- bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(body: T) => FormData;
11
- };
12
- export declare const jsonBodySerializer: {
13
- bodySerializer: <T>(body: T) => string;
14
- };
15
- export declare const urlSearchParamsBodySerializer: {
16
- bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(body: T) => string;
17
- };
File without changes