@remkoj/optimizely-cms-api 6.0.0-pre8 → 6.0.0-pre9

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 (84) hide show
  1. package/LICENSE +12 -12
  2. package/README.md +3 -5
  3. package/dist/api-client.d.ts +22 -7
  4. package/dist/api-client.js +92 -40
  5. package/dist/client/client/{client.d.ts → client.gen.d.ts} +1 -1
  6. package/dist/client/client/{client.js → client.gen.js} +88 -29
  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} +18 -13
  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} +8 -20
  12. package/dist/client/client/{utils.js → utils.gen.js} +61 -116
  13. package/dist/client/client.gen.d.ts +3 -3
  14. package/dist/client/client.gen.js +1 -1
  15. package/dist/client/core/{auth.js → auth.gen.js} +1 -0
  16. package/dist/client/core/{bodySerializer.d.ts → bodySerializer.gen.d.ts} +1 -1
  17. package/dist/client/core/{bodySerializer.js → bodySerializer.gen.js} +4 -0
  18. package/dist/client/core/{params.d.ts → params.gen.d.ts} +10 -0
  19. package/dist/client/core/{params.js → params.gen.js} +1 -0
  20. package/dist/client/core/{pathSerializer.js → pathSerializer.gen.js} +1 -0
  21. package/dist/client/core/queryKeySerializer.gen.d.ts +18 -0
  22. package/dist/client/core/queryKeySerializer.gen.js +105 -0
  23. package/dist/client/core/serverSentEvents.gen.d.ts +71 -0
  24. package/dist/client/core/serverSentEvents.gen.js +139 -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 +1 -1
  30. package/dist/client/index.js +1 -2
  31. package/dist/client/sdk.gen.d.ts +11 -167
  32. package/dist/client/sdk.gen.js +17 -421
  33. package/dist/client/transformers.gen.d.ts +8 -24
  34. package/dist/client/transformers.gen.js +77 -193
  35. package/dist/client/types.gen.d.ts +520 -1919
  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 +4 -1
  44. package/dist/index.js +9 -2
  45. package/dist/instance.client/client/client.gen.d.ts +2 -0
  46. package/dist/instance.client/client/client.gen.js +208 -0
  47. package/dist/instance.client/client/index.d.ts +8 -0
  48. package/dist/instance.client/client/index.js +17 -0
  49. package/dist/instance.client/client/types.gen.d.ts +124 -0
  50. package/dist/instance.client/client/types.gen.js +3 -0
  51. package/dist/instance.client/client/utils.gen.d.ts +33 -0
  52. package/dist/instance.client/client/utils.gen.js +241 -0
  53. package/dist/instance.client/client.gen.d.ts +12 -0
  54. package/dist/instance.client/client.gen.js +9 -0
  55. package/dist/instance.client/core/auth.gen.d.ts +18 -0
  56. package/dist/instance.client/core/auth.gen.js +18 -0
  57. package/dist/instance.client/core/bodySerializer.gen.d.ts +17 -0
  58. package/dist/instance.client/core/bodySerializer.gen.js +60 -0
  59. package/dist/instance.client/core/params.gen.d.ts +33 -0
  60. package/dist/instance.client/core/params.gen.js +92 -0
  61. package/dist/instance.client/core/pathSerializer.gen.d.ts +33 -0
  62. package/dist/instance.client/core/pathSerializer.gen.js +123 -0
  63. package/dist/instance.client/core/queryKeySerializer.gen.d.ts +18 -0
  64. package/dist/instance.client/core/queryKeySerializer.gen.js +105 -0
  65. package/dist/instance.client/core/serverSentEvents.gen.d.ts +71 -0
  66. package/dist/instance.client/core/serverSentEvents.gen.js +139 -0
  67. package/dist/instance.client/core/types.gen.d.ts +78 -0
  68. package/dist/instance.client/core/types.gen.js +3 -0
  69. package/dist/instance.client/core/utils.gen.d.ts +19 -0
  70. package/dist/instance.client/core/utils.gen.js +93 -0
  71. package/dist/instance.client/index.d.ts +4 -0
  72. package/dist/instance.client/index.js +21 -0
  73. package/dist/instance.client/sdk.gen.d.ts +256 -0
  74. package/dist/instance.client/sdk.gen.js +638 -0
  75. package/dist/instance.client/transformers.gen.d.ts +34 -0
  76. package/dist/instance.client/transformers.gen.js +273 -0
  77. package/dist/instance.client/types.gen.d.ts +2838 -0
  78. package/dist/instance.client/types.gen.js +3 -0
  79. package/dist/types.d.ts +3 -1
  80. package/dist/types.js +1 -0
  81. package/dist/version.json +3 -3
  82. package/package.json +8 -12
  83. /package/dist/client/core/{auth.d.ts → auth.gen.d.ts} +0 -0
  84. /package/dist/client/core/{pathSerializer.d.ts → pathSerializer.gen.d.ts} +0 -0
package/LICENSE CHANGED
@@ -1,13 +1,13 @@
1
- Copyright 2023 Remko Jantzen
2
-
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
6
-
7
- http://www.apache.org/licenses/LICENSE-2.0
8
-
9
- Unless required by applicable law or agreed to in writing, software
10
- distributed under the License is distributed on an "AS IS" BASIS,
11
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- See the License for the specific language governing permissions and
1
+ Copyright 2023 Remko Jantzen
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
13
  limitations under the License.
package/README.md CHANGED
@@ -17,13 +17,12 @@ import createClient, { ContentRoots } from '@remkoj/optimizely-cms-integration-a
17
17
 
18
18
  // Create an instance of the client
19
19
  const client = createClient({
20
- base: "https://example.com",
21
20
  clientId: "apiClientID",
22
21
  clientSecret: "apiClientSecret"
23
22
  });
24
23
 
25
24
  // Start using client
26
- client.content.contentListItems(ContentRoots.SystemRoot).then(response => {
25
+ client.preview2ContentList(ContentRoots.SystemRoot).then(response => {
27
26
  const items = response.items
28
27
  items?.map(item => {
29
28
  // Do something with the item
@@ -38,8 +37,7 @@ The configuration object for the `createClient()` method is optional, if it is o
38
37
  The following configuration options are available for
39
38
  | Environment variable | Configuration key | Required | Usage |
40
39
  | --- | --- | --- | --- |
41
- | OPTIMIZELY_CMS_URL | base | yes | The URL where the CMS is available |
40
+ | OPTIMIZELY_CMS_URL | base | no | Sets the URL of the Optimizely CMS instance |
42
41
  | OPTIMIZELY_CMS_CLIENT_ID | clientId | yes | The API Client ID, as configured within the CMS |
43
42
  | OPTIMIZELY_CMS_CLIENT_SECRET | clientSecret | yes | The API Client Secret as generated by the CMS when creating the client |
44
- | OPTIMIZELY_CMS_USER_ID | actAs | no | The username of the CMS user to impersonate |
45
- | OPTIMIZELY_CMS_SCHEMA | cmsVersion | no | Override the target Optimizely CMS Version:<br/><br/>`OPTI-CMS-12`: Optimizely CMS 12, With [CMS Service Preview 1](https://nuget.optimizely.com/package/?id=Optimizely.Cms.Preview1.Service) installed and working.<br/><br/>`OPTI-CMS-13`: Optimizely SaaS CMS / CMS 13<br/><br/>**Default:** SaaS CMS / CMS 13 |
43
+ | OPTIMIZELY_CMS_USER_ID | actAs | no | The username of the CMS user to impersonate |
@@ -1,16 +1,26 @@
1
1
  import * as Operations from './client/sdk.gen';
2
+ import { createClient, type RequestResult, type ResponseStyle } from './client/client';
3
+ import * as InstanceOperations from './instance.client/sdk.gen';
4
+ import { createClient as createInstanceClient, type RequestResult as InstanceRequestResult, type ResponseStyle as InstanceResponseStyle } from './instance.client/client';
2
5
  import { type CmsIntegrationApiOptions } from "./config";
3
6
  import { type InstanceApiVersionInfo, OptiCmsVersion } from "./types";
4
- import { createClient, type RequestResult, type ResponseStyle } from './client/client';
5
- import type { CreateClientConfig } from './client/client.gen';
6
7
  type OperationsType = {
7
8
  -readonly [KT in keyof typeof Operations]: (typeof Operations)[KT];
8
9
  };
9
10
  type OperationsNames = keyof OperationsType;
10
11
  type OperationReturnType<RT extends (...args: any) => any> = ReturnType<RT> extends RequestResult<any, any, boolean, ResponseStyle> ? Promise<NonNullable<Awaited<ReturnType<RT>>['data']>> : never;
11
- type ApiClientFunctions = {
12
+ type InstanceOperationsType = {
13
+ -readonly [KT in keyof typeof InstanceOperations]: (typeof InstanceOperations)[KT];
14
+ };
15
+ type InstanceOperationsNames = keyof InstanceOperationsType;
16
+ type InstanceOperationReturnType<RT extends (...args: any) => any> = ReturnType<RT> extends InstanceRequestResult<any, any, boolean, InstanceResponseStyle> ? Promise<NonNullable<Awaited<ReturnType<RT>>['data']>> : never;
17
+ type BaseApiClientFunctions = {
12
18
  readonly [KT in OperationsNames]: OperationsType[KT] extends Function ? (options?: Parameters<OperationsType[KT]>[0]) => OperationReturnType<OperationsType[KT]> : never;
13
19
  };
20
+ type InstanceClientFunctions = {
21
+ readonly [KT in InstanceOperationsNames as InstanceOperationsType[KT] extends Function ? `preview2${Capitalize<KT>}` : never]: InstanceOperationsType[KT] extends Function ? (options?: Parameters<InstanceOperationsType[KT]>[0]) => InstanceOperationReturnType<InstanceOperationsType[KT]> : never;
22
+ };
23
+ type ApiClientFunctions = BaseApiClientFunctions & InstanceClientFunctions;
14
24
  type BaseClass = {
15
25
  new (...args: any[]): BaseApiClient;
16
26
  };
@@ -24,24 +34,29 @@ export type ClassWithMixin<TBase extends BaseClass, Mixin> = OmitConstructor<TBa
24
34
  declare class BaseApiClient {
25
35
  protected _config: CmsIntegrationApiOptions;
26
36
  protected _client: ReturnType<typeof createClient>;
27
- private _token;
28
- protected getAccessToken(): Promise<string>;
37
+ protected _instanceClient: ReturnType<typeof createInstanceClient>;
29
38
  constructor(config?: CmsIntegrationApiOptions);
30
39
  /**
31
40
  * Get the runtime configuration of the target CMS version.
32
41
  *
33
42
  * If this differs from the cmsVersion the client may not work fully or not
34
43
  * at all.
44
+ *
45
+ * @deprecated This is based on the OPTIMIZELY_CMS_SCHEMA environment that is ignored by API client
35
46
  */
36
47
  get runtimeCmsVersion(): OptiCmsVersion;
37
48
  /**
38
49
  * The URL of the CMS instance
39
50
  */
40
- get cmsUrl(): URL;
51
+ get cmsUrl(): URL | undefined;
41
52
  /**
42
53
  * Marker to indicate if the client has debugging enabled
43
54
  */
44
55
  get debug(): boolean;
56
+ /**
57
+ * Detect the API Version from the URL, returning the runtime version. When
58
+ * this version differs from the `apiVersion` property errors can be expected.
59
+ */
45
60
  get version(): string;
46
61
  /**
47
62
  * The API version for which this client was build
@@ -58,7 +73,7 @@ declare class BaseApiClient {
58
73
  */
59
74
  getInstanceInfo(): Promise<InstanceApiVersionInfo>;
60
75
  getOpenApiSpec(): Promise<any>;
61
- protected createClientConfig: CreateClientConfig;
76
+ getSchemaItemBase(): URL | undefined;
62
77
  }
63
78
  export declare class ApiError extends Error {
64
79
  protected _ctx: {
@@ -38,11 +38,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.ApiClient = exports.ApiError = void 0;
40
40
  const Operations = __importStar(require("./client/sdk.gen"));
41
+ const client_1 = require("./client/client");
42
+ const InstanceOperations = __importStar(require("./instance.client/sdk.gen"));
43
+ const client_2 = require("./instance.client/client");
41
44
  const config_1 = require("./config");
42
45
  const types_1 = require("./types");
43
- const client_1 = require("./client/client");
46
+ const client_config_1 = require("./client-config");
44
47
  const version_json_1 = __importDefault(require("./version.json"));
45
- const getaccesstoken_1 = require("./getaccesstoken");
46
48
  function applyOperations(Base) {
47
49
  // Create the new class
48
50
  class NewClass extends Base {
@@ -51,7 +53,7 @@ function applyOperations(Base) {
51
53
  }
52
54
  }
53
55
  // Bind the operations
54
- Object.getOwnPropertyNames(Operations).filter(isApiClientFunction).forEach((propName) => {
56
+ Object.getOwnPropertyNames(Operations).filter(isApiClientFunction).forEach(propName => {
55
57
  async function wrapper(args) {
56
58
  const operationArgs = {
57
59
  throwOnError: false,
@@ -68,59 +70,90 @@ function applyOperations(Base) {
68
70
  //@ts-expect-error
69
71
  NewClass.prototype[propName] = wrapper;
70
72
  });
73
+ // Bind the older Preview2 operations
74
+ Object.getOwnPropertyNames(InstanceOperations).filter(isInstanceClientFunction).forEach(propName => {
75
+ async function wrapper(args) {
76
+ const operationArgs = {
77
+ throwOnError: false,
78
+ ...args,
79
+ //@ts-expect-error
80
+ client: this._instanceClient
81
+ };
82
+ //@ts-expect-error
83
+ const result = await InstanceOperations[propName](operationArgs);
84
+ if (result.data)
85
+ return result.data;
86
+ throw new ApiError(result);
87
+ }
88
+ const fnName = `preview2${toCapitalized(propName)}`;
89
+ //@ts-expect-error
90
+ NewClass.prototype[fnName] = wrapper;
91
+ });
71
92
  // Return the new class
72
93
  return NewClass;
73
94
  }
74
- function isApiClientFunction(propName) {
75
- return typeof (Operations[propName]) == 'function';
95
+ function toCapitalized(toCapitalize) {
96
+ return (toCapitalize.substring(0, 1).toUpperCase() + toCapitalize.substring(1));
97
+ }
98
+ function createIsFunctionValidator(baseType) {
99
+ return (propName) => {
100
+ return typeof (baseType[propName]) == 'function';
101
+ };
76
102
  }
103
+ const isApiClientFunction = createIsFunctionValidator(Operations);
104
+ const isInstanceClientFunction = createIsFunctionValidator(InstanceOperations);
77
105
  class BaseApiClient {
78
106
  _config;
79
107
  _client;
80
- _token;
81
- getAccessToken() {
82
- if (!this._token)
83
- this._token = (0, getaccesstoken_1.getAccessToken)(this._config);
84
- return this._token;
85
- }
108
+ _instanceClient;
86
109
  constructor(config) {
87
- // Prepare config
88
- const options = config ?? (0, config_1.getCmsIntegrationApiConfigFromEnvironment)();
89
- options.base = new URL("/_cms/preview2", options.base);
90
- if (options.cmsVersion == types_1.OptiCmsVersion.CMS12)
91
- options.base.pathname = options.base.pathname.replace('preview2', 'preview1');
92
110
  // Store instance variables
93
- this._config = options;
94
- this._client = (0, client_1.createClient)(this.createClientConfig());
111
+ this._config = config ?? (0, config_1.readEnvConfig)();
112
+ this._client = (0, client_1.createClient)((0, client_config_1.createClientConfig)((0, client_1.createConfig)({
113
+ baseUrl: 'https://api.cms.optimizely.com/preview3'
114
+ }), this._config));
115
+ this._instanceClient = (0, client_2.createClient)((0, client_config_1.createClientConfig)((0, client_2.createConfig)({
116
+ baseUrl: new URL('/_cms/preview2', this._config.base).href
117
+ })));
95
118
  // Configure Client
96
- this._client.interceptors.request.use(async (request) => {
97
- const token = await this.getAccessToken();
98
- request.headers.set('Authorization', 'Bearer ' + token);
99
- if (this._config.debug) {
100
- console.log(`🔍 Sending ${request.method} request to ${request.url}`);
101
- }
102
- return request;
103
- });
104
- if (this._config.debug)
119
+ if (this._config.debug) {
120
+ this._client.interceptors.request.use(async (request) => {
121
+ console.log(`🔍 [CMS API] Sending ${request.method} request to ${request.url}`);
122
+ return request;
123
+ });
105
124
  this._client.interceptors.response.use((response, request) => {
106
- console.log(`✨ Received response ${response.status} ${response.statusText} of type ${response.headers.get('Content-Type') ?? 'unknown'} for ${request.url}`);
125
+ console.log(`✨ [CMS API] Received response ${response.status} ${response.statusText} of type ${response.headers.get('Content-Type') ?? 'unknown'} for ${request.url}`);
126
+ return response;
127
+ });
128
+ this._instanceClient.interceptors.request.use(async (request) => {
129
+ console.log(`🔍 [CMS API] Sending ${request.method} request to ${request.url}`);
130
+ return request;
131
+ });
132
+ this._instanceClient.interceptors.response.use((response, request) => {
133
+ console.log(`✨ [CMS API] Received response ${response.status} ${response.statusText} of type ${response.headers.get('Content-Type') ?? 'unknown'} for ${request.url}`);
107
134
  return response;
108
135
  });
136
+ }
109
137
  }
110
138
  /**
111
139
  * Get the runtime configuration of the target CMS version.
112
140
  *
113
141
  * If this differs from the cmsVersion the client may not work fully or not
114
142
  * at all.
143
+ *
144
+ * @deprecated This is based on the OPTIMIZELY_CMS_SCHEMA environment that is ignored by API client
115
145
  */
116
146
  get runtimeCmsVersion() {
117
- return this._config.cmsVersion ?? types_1.OptiCmsVersion.CMS13;
147
+ return this._config.cmsVersion ?? types_1.OptiCmsVersion.CMSSAAS;
118
148
  }
119
149
  /**
120
150
  * The URL of the CMS instance
121
151
  */
122
152
  get cmsUrl() {
123
- return this._config.base;
153
+ if (this._config.base)
154
+ return this._config.base;
155
+ const baseUrl = this._client.getConfig().baseUrl;
156
+ return baseUrl ? new URL(baseUrl) : undefined;
124
157
  }
125
158
  /**
126
159
  * Marker to indicate if the client has debugging enabled
@@ -128,8 +161,14 @@ class BaseApiClient {
128
161
  get debug() {
129
162
  return this._config.debug ?? false;
130
163
  }
164
+ /**
165
+ * Detect the API Version from the URL, returning the runtime version. When
166
+ * this version differs from the `apiVersion` property errors can be expected.
167
+ */
131
168
  get version() {
132
- return this._config.cmsVersion == types_1.OptiCmsVersion.CMS12 ? 'preview1' : 'preview2';
169
+ const baseUrl = this._client.getConfig().baseUrl;
170
+ const detectedVersion = baseUrl?.match(/^https{0,1}:\/\/.+?\/(_cms\/){0,1}([a-z0-9\.]+)(\/|$)/)?.at(2);
171
+ return detectedVersion || "";
133
172
  }
134
173
  /**
135
174
  * The API version for which this client was build
@@ -152,24 +191,37 @@ class BaseApiClient {
152
191
  const result = await this._client.get({
153
192
  url: '/info'
154
193
  });
155
- if (result.data)
156
- return result.data;
194
+ const instanceResult = await this._instanceClient.get({
195
+ url: '/info'
196
+ });
197
+ if (result.data) {
198
+ const data = result.data;
199
+ data.baseUrl = this._client.getConfig().baseUrl;
200
+ data.results = {
201
+ preview2Data: {
202
+ baseUrl: this._instanceClient.getConfig().baseUrl,
203
+ ...instanceResult?.data ?? {}
204
+ },
205
+ ...data.results,
206
+ };
207
+ return data;
208
+ }
157
209
  throw new ApiError(result);
158
210
  }
159
211
  async getOpenApiSpec() {
160
212
  const result = await this._client.get({
161
- url: '/docs/content-openapi.json'
213
+ url: '/docs/content-openapi.json',
162
214
  });
163
215
  if (result.data)
164
216
  return result.data;
165
217
  throw new ApiError(result);
166
218
  }
167
- createClientConfig = (override) => {
168
- return {
169
- ...override,
170
- baseUrl: this._config.base.href
171
- };
172
- };
219
+ getSchemaItemBase() {
220
+ let baseUrl = this._client.getConfig().baseUrl;
221
+ if (typeof (baseUrl) === 'string' && !baseUrl.endsWith('/'))
222
+ baseUrl = baseUrl + '/';
223
+ return baseUrl ? new URL(baseUrl) : undefined;
224
+ }
173
225
  }
174
226
  class ApiError extends Error {
175
227
  _ctx;
@@ -1,2 +1,2 @@
1
- import type { Client, Config } from './types';
1
+ import type { Client, Config } from './types.gen';
2
2
  export declare const createClient: (config?: Config) => Client;
@@ -1,24 +1,28 @@
1
1
  "use strict";
2
+ // This file is auto-generated by @hey-api/openapi-ts
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.createClient = void 0;
4
- const utils_1 = require("./utils");
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");
5
8
  const createClient = (config = {}) => {
6
- let _config = (0, utils_1.mergeConfigs)((0, utils_1.createConfig)(), config);
9
+ let _config = (0, utils_gen_2.mergeConfigs)((0, utils_gen_2.createConfig)(), config);
7
10
  const getConfig = () => ({ ..._config });
8
11
  const setConfig = (config) => {
9
- _config = (0, utils_1.mergeConfigs)(_config, config);
12
+ _config = (0, utils_gen_2.mergeConfigs)(_config, config);
10
13
  return getConfig();
11
14
  };
12
- const interceptors = (0, utils_1.createInterceptors)();
13
- const request = async (options) => {
15
+ const interceptors = (0, utils_gen_2.createInterceptors)();
16
+ const beforeRequest = async (options) => {
14
17
  const opts = {
15
18
  ..._config,
16
19
  ...options,
17
20
  fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
18
- headers: (0, utils_1.mergeHeaders)(_config.headers, options.headers),
21
+ headers: (0, utils_gen_2.mergeHeaders)(_config.headers, options.headers),
22
+ serializedBody: undefined,
19
23
  };
20
24
  if (opts.security) {
21
- await (0, utils_1.setAuthParams)({
25
+ await (0, utils_gen_2.setAuthParams)({
22
26
  ...opts,
23
27
  security: opts.security,
24
28
  });
@@ -26,20 +30,26 @@ const createClient = (config = {}) => {
26
30
  if (opts.requestValidator) {
27
31
  await opts.requestValidator(opts);
28
32
  }
29
- if (opts.body && opts.bodySerializer) {
30
- opts.body = opts.bodySerializer(opts.body);
33
+ if (opts.body !== undefined && opts.bodySerializer) {
34
+ opts.serializedBody = opts.bodySerializer(opts.body);
31
35
  }
32
36
  // remove Content-Type header if body is empty to avoid sending invalid requests
33
- if (opts.body === undefined || opts.body === '') {
37
+ if (opts.body === undefined || opts.serializedBody === '') {
34
38
  opts.headers.delete('Content-Type');
35
39
  }
36
- const url = (0, utils_1.buildUrl)(opts);
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);
37
46
  const requestInit = {
38
47
  redirect: 'follow',
39
48
  ...opts,
49
+ body: (0, utils_gen_1.getValidRequestBody)(opts),
40
50
  };
41
51
  let request = new Request(url, requestInit);
42
- for (const fn of interceptors.request._fns) {
52
+ for (const fn of interceptors.request.fns) {
43
53
  if (fn) {
44
54
  request = await fn(request, opts);
45
55
  }
@@ -48,7 +58,7 @@ const createClient = (config = {}) => {
48
58
  // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
49
59
  const _fetch = opts.fetch;
50
60
  let response = await _fetch(request);
51
- for (const fn of interceptors.response._fns) {
61
+ for (const fn of interceptors.response.fns) {
52
62
  if (fn) {
53
63
  response = await fn(response, request, opts);
54
64
  }
@@ -58,18 +68,36 @@ const createClient = (config = {}) => {
58
68
  response,
59
69
  };
60
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';
61
74
  if (response.status === 204 ||
62
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
+ }
63
94
  return opts.responseStyle === 'data'
64
- ? {}
95
+ ? emptyData
65
96
  : {
66
- data: {},
97
+ data: emptyData,
67
98
  ...result,
68
99
  };
69
100
  }
70
- const parseAs = (opts.parseAs === 'auto'
71
- ? (0, utils_1.getParseAs)(response.headers.get('Content-Type'))
72
- : opts.parseAs) ?? 'json';
73
101
  let data;
74
102
  switch (parseAs) {
75
103
  case 'arrayBuffer':
@@ -112,7 +140,7 @@ const createClient = (config = {}) => {
112
140
  }
113
141
  const error = jsonError ?? textError;
114
142
  let finalError = error;
115
- for (const fn of interceptors.error._fns) {
143
+ for (const fn of interceptors.error.fns) {
116
144
  if (fn) {
117
145
  finalError = (await fn(error, response, request, opts));
118
146
  }
@@ -129,21 +157,52 @@ const createClient = (config = {}) => {
129
157
  ...result,
130
158
  };
131
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
+ };
132
180
  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' }),
181
+ buildUrl: utils_gen_2.buildUrl,
182
+ connect: makeMethodFn('CONNECT'),
183
+ delete: makeMethodFn('DELETE'),
184
+ get: makeMethodFn('GET'),
137
185
  getConfig,
138
- head: (options) => request({ ...options, method: 'HEAD' }),
186
+ head: makeMethodFn('HEAD'),
139
187
  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' }),
188
+ options: makeMethodFn('OPTIONS'),
189
+ patch: makeMethodFn('PATCH'),
190
+ post: makeMethodFn('POST'),
191
+ put: makeMethodFn('PUT'),
144
192
  request,
145
193
  setConfig,
146
- trace: (options) => request({ ...options, method: 'TRACE' }),
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'),
147
206
  };
148
207
  };
149
208
  exports.createClient = createClient;
@@ -1,7 +1,8 @@
1
- export type { Auth } from '../core/auth';
2
- export type { QuerySerializerOptions } from '../core/bodySerializer';
3
- export { formDataBodySerializer, jsonBodySerializer, urlSearchParamsBodySerializer, } from '../core/bodySerializer';
4
- export { buildClientParams } from '../core/params';
5
- export { createClient } from './client';
6
- export type { Client, ClientOptions, Config, CreateClientConfig, Options, OptionsLegacyParser, RequestOptions, RequestResult, ResponseStyle, TDataShape, } from './types';
7
- export { createConfig, mergeHeaders } from './utils';
1
+ export type { Auth } from '../core/auth.gen';
2
+ export type { QuerySerializerOptions } from '../core/bodySerializer.gen';
3
+ export { formDataBodySerializer, jsonBodySerializer, urlSearchParamsBodySerializer, } from '../core/bodySerializer.gen';
4
+ export { buildClientParams } from '../core/params.gen';
5
+ export { serializeQueryKeyValue } from '../core/queryKeySerializer.gen';
6
+ export { createClient } from './client.gen';
7
+ export type { Client, ClientOptions, Config, CreateClientConfig, Options, OptionsLegacyParser, RequestOptions, RequestResult, ResolvedRequestOptions, ResponseStyle, TDataShape, } from './types.gen';
8
+ export { createConfig, mergeHeaders } from './utils.gen';
@@ -1,14 +1,17 @@
1
1
  "use strict";
2
+ // This file is auto-generated by @hey-api/openapi-ts
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mergeHeaders = exports.createConfig = exports.createClient = exports.buildClientParams = exports.urlSearchParamsBodySerializer = exports.jsonBodySerializer = exports.formDataBodySerializer = void 0;
4
- var bodySerializer_1 = require("../core/bodySerializer");
5
- Object.defineProperty(exports, "formDataBodySerializer", { enumerable: true, get: function () { return bodySerializer_1.formDataBodySerializer; } });
6
- Object.defineProperty(exports, "jsonBodySerializer", { enumerable: true, get: function () { return bodySerializer_1.jsonBodySerializer; } });
7
- Object.defineProperty(exports, "urlSearchParamsBodySerializer", { enumerable: true, get: function () { return bodySerializer_1.urlSearchParamsBodySerializer; } });
8
- var params_1 = require("../core/params");
9
- Object.defineProperty(exports, "buildClientParams", { enumerable: true, get: function () { return params_1.buildClientParams; } });
10
- var client_1 = require("./client");
11
- Object.defineProperty(exports, "createClient", { enumerable: true, get: function () { return client_1.createClient; } });
12
- var utils_1 = require("./utils");
13
- Object.defineProperty(exports, "createConfig", { enumerable: true, get: function () { return utils_1.createConfig; } });
14
- Object.defineProperty(exports, "mergeHeaders", { enumerable: true, get: function () { return utils_1.mergeHeaders; } });
4
+ exports.mergeHeaders = exports.createConfig = exports.createClient = exports.serializeQueryKeyValue = exports.buildClientParams = exports.urlSearchParamsBodySerializer = exports.jsonBodySerializer = exports.formDataBodySerializer = void 0;
5
+ var bodySerializer_gen_1 = require("../core/bodySerializer.gen");
6
+ Object.defineProperty(exports, "formDataBodySerializer", { enumerable: true, get: function () { return bodySerializer_gen_1.formDataBodySerializer; } });
7
+ Object.defineProperty(exports, "jsonBodySerializer", { enumerable: true, get: function () { return bodySerializer_gen_1.jsonBodySerializer; } });
8
+ Object.defineProperty(exports, "urlSearchParamsBodySerializer", { enumerable: true, get: function () { return bodySerializer_gen_1.urlSearchParamsBodySerializer; } });
9
+ var params_gen_1 = require("../core/params.gen");
10
+ Object.defineProperty(exports, "buildClientParams", { enumerable: true, get: function () { return params_gen_1.buildClientParams; } });
11
+ var queryKeySerializer_gen_1 = require("../core/queryKeySerializer.gen");
12
+ Object.defineProperty(exports, "serializeQueryKeyValue", { enumerable: true, get: function () { return queryKeySerializer_gen_1.serializeQueryKeyValue; } });
13
+ var client_gen_1 = require("./client.gen");
14
+ Object.defineProperty(exports, "createClient", { enumerable: true, get: function () { return client_gen_1.createClient; } });
15
+ var utils_gen_1 = require("./utils.gen");
16
+ Object.defineProperty(exports, "createConfig", { enumerable: true, get: function () { return utils_gen_1.createConfig; } });
17
+ Object.defineProperty(exports, "mergeHeaders", { enumerable: true, get: function () { return utils_gen_1.mergeHeaders; } });