@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
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
@@ -1,7 +1,11 @@
1
+ # Optimizely CMS - Integration API Client <!-- omit in toc -->
2
+
3
+ > [!WARNING]
4
+ > There'll be an update of Optimizely SaaS CMS that is incompatible with all SDK versions prior to 5.1.6. If you don't upgrade, you will see empty pages (main website) and "Component not found" messages (preview).
5
+
1
6
  [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](./LICENSE)
2
7
  ![Static Badge](https://img.shields.io/badge/Optimizely-Content_Management_System-blue?cacheSeconds=7200)
3
8
 
4
- # Optimizely CMS - Integration API Client <!-- omit in toc -->
5
9
  A Javascript client for the Integration API provided by the Optimizely CMS. It wraps the [Optimizely CMS SaaS Core REST API](https://docs.developers.optimizely.com/content-management-system/v1.0.0-SaaS-Core/reference/introduction-to-the-cms-content-api).
6
10
 
7
11
  ## Installation
@@ -17,13 +21,12 @@ import createClient, { ContentRoots } from '@remkoj/optimizely-cms-integration-a
17
21
 
18
22
  // Create an instance of the client
19
23
  const client = createClient({
20
- base: "https://example.com",
21
24
  clientId: "apiClientID",
22
25
  clientSecret: "apiClientSecret"
23
26
  });
24
27
 
25
28
  // Start using client
26
- client.content.contentListItems(ContentRoots.SystemRoot).then(response => {
29
+ client.preview2ContentList(ContentRoots.SystemRoot).then(response => {
27
30
  const items = response.items
28
31
  items?.map(item => {
29
32
  // Do something with the item
@@ -38,8 +41,7 @@ The configuration object for the `createClient()` method is optional, if it is o
38
41
  The following configuration options are available for
39
42
  | Environment variable | Configuration key | Required | Usage |
40
43
  | --- | --- | --- | --- |
41
- | OPTIMIZELY_CMS_URL | base | yes | The URL where the CMS is available |
44
+ | OPTIMIZELY_CMS_URL | base | no | Sets the URL of the Optimizely CMS instance |
42
45
  | OPTIMIZELY_CMS_CLIENT_ID | clientId | yes | The API Client ID, as configured within the CMS |
43
46
  | OPTIMIZELY_CMS_CLIENT_SECRET | clientSecret | yes | The API Client Secret as generated by the CMS when creating the client |
44
47
  | 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 |
@@ -1,8 +1,7 @@
1
1
  import * as Operations from './client/sdk.gen';
2
+ import { createClient, type RequestResult, type ResponseStyle } from './client/client';
2
3
  import { type CmsIntegrationApiOptions } from "./config";
3
4
  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
5
  type OperationsType = {
7
6
  -readonly [KT in keyof typeof Operations]: (typeof Operations)[KT];
8
7
  };
@@ -24,24 +23,28 @@ export type ClassWithMixin<TBase extends BaseClass, Mixin> = OmitConstructor<TBa
24
23
  declare class BaseApiClient {
25
24
  protected _config: CmsIntegrationApiOptions;
26
25
  protected _client: ReturnType<typeof createClient>;
27
- private _token;
28
- protected getAccessToken(): Promise<string>;
29
26
  constructor(config?: CmsIntegrationApiOptions);
30
27
  /**
31
28
  * Get the runtime configuration of the target CMS version.
32
29
  *
33
30
  * If this differs from the cmsVersion the client may not work fully or not
34
31
  * at all.
32
+ *
33
+ * @deprecated This is based on the OPTIMIZELY_CMS_SCHEMA environment that is ignored by API client
35
34
  */
36
35
  get runtimeCmsVersion(): OptiCmsVersion;
37
36
  /**
38
37
  * The URL of the CMS instance
39
38
  */
40
- get cmsUrl(): URL;
39
+ get cmsUrl(): URL | undefined;
41
40
  /**
42
41
  * Marker to indicate if the client has debugging enabled
43
42
  */
44
43
  get debug(): boolean;
44
+ /**
45
+ * Detect the API Version from the URL, returning the runtime version. When
46
+ * this version differs from the `apiVersion` property errors can be expected.
47
+ */
45
48
  get version(): string;
46
49
  /**
47
50
  * The API version for which this client was build
@@ -58,7 +61,7 @@ declare class BaseApiClient {
58
61
  */
59
62
  getInstanceInfo(): Promise<InstanceApiVersionInfo>;
60
63
  getOpenApiSpec(): Promise<any>;
61
- protected createClientConfig: CreateClientConfig;
64
+ getSchemaItemBase(): URL | undefined;
62
65
  }
63
66
  export declare class ApiError extends Error {
64
67
  protected _ctx: {
@@ -38,11 +38,11 @@ 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");
41
42
  const config_1 = require("./config");
42
43
  const types_1 = require("./types");
43
- const client_1 = require("./client/client");
44
+ const client_config_1 = require("./client-config");
44
45
  const version_json_1 = __importDefault(require("./version.json"));
45
- const getaccesstoken_1 = require("./getaccesstoken");
46
46
  function applyOperations(Base) {
47
47
  // Create the new class
48
48
  class NewClass extends Base {
@@ -51,7 +51,7 @@ function applyOperations(Base) {
51
51
  }
52
52
  }
53
53
  // Bind the operations
54
- Object.getOwnPropertyNames(Operations).filter(isApiClientFunction).forEach((propName) => {
54
+ Object.getOwnPropertyNames(Operations).filter(isApiClientFunction).forEach(propName => {
55
55
  async function wrapper(args) {
56
56
  const operationArgs = {
57
57
  throwOnError: false,
@@ -71,56 +71,52 @@ function applyOperations(Base) {
71
71
  // Return the new class
72
72
  return NewClass;
73
73
  }
74
- function isApiClientFunction(propName) {
75
- return typeof (Operations[propName]) == 'function';
74
+ function createIsFunctionValidator(baseType) {
75
+ return (propName) => {
76
+ return typeof (baseType[propName]) == 'function';
77
+ };
76
78
  }
79
+ const isApiClientFunction = createIsFunctionValidator(Operations);
77
80
  class BaseApiClient {
78
81
  _config;
79
82
  _client;
80
- _token;
81
- getAccessToken() {
82
- if (!this._token)
83
- this._token = (0, getaccesstoken_1.getAccessToken)(this._config);
84
- return this._token;
85
- }
86
83
  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
84
  // Store instance variables
93
- this._config = options;
94
- this._client = (0, client_1.createClient)(this.createClientConfig());
85
+ this._config = config ?? (0, config_1.readEnvConfig)();
86
+ this._client = (0, client_1.createClient)((0, client_config_1.createClientConfig)((0, client_1.createConfig)({
87
+ baseUrl: 'https://api.cms.optimizely.com/preview3',
88
+ }), this._config));
95
89
  // 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)
90
+ if (this._config.debug) {
91
+ this._client.interceptors.request.use(async (request) => {
92
+ console.log(`🔍 [CMS API] Sending ${request.method} request to ${request.url}`);
93
+ return request;
94
+ });
105
95
  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}`);
96
+ console.log(`✨ [CMS API] Received response ${response.status} ${response.statusText} of type ${response.headers.get('Content-Type') ?? 'unknown'} for ${request.url}`);
107
97
  return response;
108
98
  });
99
+ }
109
100
  }
110
101
  /**
111
102
  * Get the runtime configuration of the target CMS version.
112
103
  *
113
104
  * If this differs from the cmsVersion the client may not work fully or not
114
105
  * at all.
106
+ *
107
+ * @deprecated This is based on the OPTIMIZELY_CMS_SCHEMA environment that is ignored by API client
115
108
  */
116
109
  get runtimeCmsVersion() {
117
- return this._config.cmsVersion ?? types_1.OptiCmsVersion.CMS13;
110
+ return this._config.cmsVersion ?? types_1.OptiCmsVersion.CMSSAAS;
118
111
  }
119
112
  /**
120
113
  * The URL of the CMS instance
121
114
  */
122
115
  get cmsUrl() {
123
- return this._config.base;
116
+ if (this._config.base)
117
+ return this._config.base;
118
+ const baseUrl = this._client.getConfig().baseUrl;
119
+ return baseUrl ? new URL(baseUrl) : undefined;
124
120
  }
125
121
  /**
126
122
  * Marker to indicate if the client has debugging enabled
@@ -128,8 +124,14 @@ class BaseApiClient {
128
124
  get debug() {
129
125
  return this._config.debug ?? false;
130
126
  }
127
+ /**
128
+ * Detect the API Version from the URL, returning the runtime version. When
129
+ * this version differs from the `apiVersion` property errors can be expected.
130
+ */
131
131
  get version() {
132
- return this._config.cmsVersion == types_1.OptiCmsVersion.CMS12 ? 'preview1' : 'preview2';
132
+ const baseUrl = this._client.getConfig().baseUrl;
133
+ const detectedVersion = baseUrl?.match(/^https{0,1}:\/\/.+?\/(_cms\/){0,1}([a-z0-9\.]+)(\/|$)/)?.at(2);
134
+ return detectedVersion || "";
133
135
  }
134
136
  /**
135
137
  * The API version for which this client was build
@@ -152,24 +154,27 @@ class BaseApiClient {
152
154
  const result = await this._client.get({
153
155
  url: '/info'
154
156
  });
155
- if (result.data)
156
- return result.data;
157
+ if (result.data) {
158
+ const data = result.data;
159
+ data.baseUrl = this._client.getConfig().baseUrl;
160
+ return data;
161
+ }
157
162
  throw new ApiError(result);
158
163
  }
159
164
  async getOpenApiSpec() {
160
165
  const result = await this._client.get({
161
- url: '/docs/content-openapi.json'
166
+ url: '/docs/content-openapi.json',
162
167
  });
163
168
  if (result.data)
164
169
  return result.data;
165
170
  throw new ApiError(result);
166
171
  }
167
- createClientConfig = (override) => {
168
- return {
169
- ...override,
170
- baseUrl: this._config.base.href
171
- };
172
- };
172
+ getSchemaItemBase() {
173
+ let baseUrl = this._client.getConfig().baseUrl;
174
+ if (typeof (baseUrl) === 'string' && !baseUrl.endsWith('/'))
175
+ baseUrl = baseUrl + '/';
176
+ return baseUrl ? new URL(baseUrl) : undefined;
177
+ }
173
178
  }
174
179
  class ApiError extends Error {
175
180
  _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;
@@ -0,0 +1,239 @@
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;
61
+ try {
62
+ response = await _fetch(request);
63
+ }
64
+ catch (error) {
65
+ // Handle fetch exceptions (AbortError, network errors, etc.)
66
+ let finalError = error;
67
+ for (const fn of interceptors.error.fns) {
68
+ if (fn) {
69
+ finalError = (await fn(error, undefined, request, opts));
70
+ }
71
+ }
72
+ finalError = finalError || {};
73
+ if (opts.throwOnError) {
74
+ throw finalError;
75
+ }
76
+ // Return error response
77
+ return opts.responseStyle === 'data'
78
+ ? undefined
79
+ : {
80
+ error: finalError,
81
+ request,
82
+ response: undefined,
83
+ };
84
+ }
85
+ for (const fn of interceptors.response.fns) {
86
+ if (fn) {
87
+ response = await fn(response, request, opts);
88
+ }
89
+ }
90
+ const result = {
91
+ request,
92
+ response,
93
+ };
94
+ if (response.ok) {
95
+ const parseAs = (opts.parseAs === 'auto'
96
+ ? (0, utils_gen_2.getParseAs)(response.headers.get('Content-Type'))
97
+ : opts.parseAs) ?? 'json';
98
+ if (response.status === 204 || response.headers.get('Content-Length') === '0') {
99
+ let emptyData;
100
+ switch (parseAs) {
101
+ case 'arrayBuffer':
102
+ case 'blob':
103
+ case 'text':
104
+ emptyData = await response[parseAs]();
105
+ break;
106
+ case 'formData':
107
+ emptyData = new FormData();
108
+ break;
109
+ case 'stream':
110
+ emptyData = response.body;
111
+ break;
112
+ case 'json':
113
+ default:
114
+ emptyData = {};
115
+ break;
116
+ }
117
+ return opts.responseStyle === 'data'
118
+ ? emptyData
119
+ : {
120
+ data: emptyData,
121
+ ...result,
122
+ };
123
+ }
124
+ let data;
125
+ switch (parseAs) {
126
+ case 'arrayBuffer':
127
+ case 'blob':
128
+ case 'formData':
129
+ case 'text':
130
+ data = await response[parseAs]();
131
+ break;
132
+ case 'json': {
133
+ // Some servers return 200 with no Content-Length and empty body.
134
+ // response.json() would throw; read as text and parse if non-empty.
135
+ const text = await response.text();
136
+ data = text ? JSON.parse(text) : {};
137
+ break;
138
+ }
139
+ case 'stream':
140
+ return opts.responseStyle === 'data'
141
+ ? response.body
142
+ : {
143
+ data: response.body,
144
+ ...result,
145
+ };
146
+ }
147
+ if (parseAs === 'json') {
148
+ if (opts.responseValidator) {
149
+ await opts.responseValidator(data);
150
+ }
151
+ if (opts.responseTransformer) {
152
+ data = await opts.responseTransformer(data);
153
+ }
154
+ }
155
+ return opts.responseStyle === 'data'
156
+ ? data
157
+ : {
158
+ data,
159
+ ...result,
160
+ };
161
+ }
162
+ const textError = await response.text();
163
+ let jsonError;
164
+ try {
165
+ jsonError = JSON.parse(textError);
166
+ }
167
+ catch {
168
+ // noop
169
+ }
170
+ const error = jsonError ?? textError;
171
+ let finalError = error;
172
+ for (const fn of interceptors.error.fns) {
173
+ if (fn) {
174
+ finalError = (await fn(error, response, request, opts));
175
+ }
176
+ }
177
+ finalError = finalError || {};
178
+ if (opts.throwOnError) {
179
+ throw finalError;
180
+ }
181
+ // TODO: we probably want to return error and improve types
182
+ return opts.responseStyle === 'data'
183
+ ? undefined
184
+ : {
185
+ error: finalError,
186
+ ...result,
187
+ };
188
+ };
189
+ const makeMethodFn = (method) => (options) => request({ ...options, method });
190
+ const makeSseFn = (method) => async (options) => {
191
+ const { opts, url } = await beforeRequest(options);
192
+ return (0, serverSentEvents_gen_1.createSseClient)({
193
+ ...opts,
194
+ body: opts.body,
195
+ headers: opts.headers,
196
+ method,
197
+ onRequest: async (url, init) => {
198
+ let request = new Request(url, init);
199
+ for (const fn of interceptors.request.fns) {
200
+ if (fn) {
201
+ request = await fn(request, opts);
202
+ }
203
+ }
204
+ return request;
205
+ },
206
+ serializedBody: (0, utils_gen_1.getValidRequestBody)(opts),
207
+ url,
208
+ });
209
+ };
210
+ const _buildUrl = (options) => (0, utils_gen_2.buildUrl)({ ..._config, ...options });
211
+ return {
212
+ buildUrl: _buildUrl,
213
+ connect: makeMethodFn('CONNECT'),
214
+ delete: makeMethodFn('DELETE'),
215
+ get: makeMethodFn('GET'),
216
+ getConfig,
217
+ head: makeMethodFn('HEAD'),
218
+ interceptors,
219
+ options: makeMethodFn('OPTIONS'),
220
+ patch: makeMethodFn('PATCH'),
221
+ post: makeMethodFn('POST'),
222
+ put: makeMethodFn('PUT'),
223
+ request,
224
+ setConfig,
225
+ sse: {
226
+ connect: makeSseFn('CONNECT'),
227
+ delete: makeSseFn('DELETE'),
228
+ get: makeSseFn('GET'),
229
+ head: makeSseFn('HEAD'),
230
+ options: makeSseFn('OPTIONS'),
231
+ patch: makeSseFn('PATCH'),
232
+ post: makeSseFn('POST'),
233
+ put: makeSseFn('PUT'),
234
+ trace: makeSseFn('TRACE'),
235
+ },
236
+ trace: makeMethodFn('TRACE'),
237
+ };
238
+ };
239
+ 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, 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; } });
@@ -1,6 +1,7 @@
1
- import type { Auth } from '../core/auth';
2
- import type { Client as CoreClient, Config as CoreConfig } from '../core/types';
3
- import type { Middleware } from './utils';
1
+ import type { Auth } from '../core/auth.gen';
2
+ import type { ServerSentEventsOptions, ServerSentEventsResult } from '../core/serverSentEvents.gen';
3
+ import type { Client as CoreClient, Config as CoreConfig } from '../core/types.gen';
4
+ import type { Middleware } from './utils.gen';
4
5
  export type ResponseStyle = 'data' | 'fields';
5
6
  export interface Config<T extends ClientOptions = ClientOptions> extends Omit<RequestInit, 'body' | 'headers' | 'method'>, CoreConfig {
6
7
  /**
@@ -13,7 +14,7 @@ export interface Config<T extends ClientOptions = ClientOptions> extends Omit<Re
13
14
  *
14
15
  * @default globalThis.fetch
15
16
  */
16
- fetch?: (request: Request) => ReturnType<typeof fetch>;
17
+ fetch?: typeof fetch;
17
18
  /**
18
19
  * Please don't use the Fetch client for Next.js applications. The `next`
19
20
  * options won't have any effect.
@@ -43,10 +44,10 @@ export interface Config<T extends ClientOptions = ClientOptions> extends Omit<Re
43
44
  */
44
45
  throwOnError?: T['throwOnError'];
45
46
  }
46
- export interface RequestOptions<TResponseStyle extends ResponseStyle = 'fields', ThrowOnError extends boolean = boolean, Url extends string = string> extends Config<{
47
+ export interface RequestOptions<TData = unknown, TResponseStyle extends ResponseStyle = 'fields', ThrowOnError extends boolean = boolean, Url extends string = string> extends Config<{
47
48
  responseStyle: TResponseStyle;
48
49
  throwOnError: ThrowOnError;
49
- }> {
50
+ }>, Pick<ServerSentEventsOptions<TData>, 'onRequest' | 'onSseError' | 'onSseEvent' | 'sseDefaultRetryDelay' | 'sseMaxRetryAttempts' | 'sseMaxRetryDelay'> {
50
51
  /**
51
52
  * Any body that you want to add to your request.
52
53
  *
@@ -61,6 +62,9 @@ export interface RequestOptions<TResponseStyle extends ResponseStyle = 'fields',
61
62
  security?: ReadonlyArray<Auth>;
62
63
  url: Url;
63
64
  }
65
+ export interface ResolvedRequestOptions<TResponseStyle extends ResponseStyle = 'fields', ThrowOnError extends boolean = boolean, Url extends string = string> extends RequestOptions<unknown, TResponseStyle, ThrowOnError, Url> {
66
+ serializedBody?: string;
67
+ }
64
68
  export type RequestResult<TData = unknown, TError = unknown, ThrowOnError extends boolean = boolean, TResponseStyle extends ResponseStyle = 'fields'> = ThrowOnError extends true ? Promise<TResponseStyle extends 'data' ? TData extends Record<string, unknown> ? TData[keyof TData] : TData : {
65
69
  data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
66
70
  request: Request;
@@ -80,16 +84,17 @@ export interface ClientOptions {
80
84
  responseStyle?: ResponseStyle;
81
85
  throwOnError?: boolean;
82
86
  }
83
- type MethodFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = 'fields'>(options: Omit<RequestOptions<TResponseStyle, ThrowOnError>, 'method'>) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
84
- type RequestFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = 'fields'>(options: Omit<RequestOptions<TResponseStyle, ThrowOnError>, 'method'> & Pick<Required<RequestOptions<TResponseStyle, ThrowOnError>>, 'method'>) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
87
+ type MethodFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = 'fields'>(options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'>) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
88
+ type SseFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = 'fields'>(options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'>) => Promise<ServerSentEventsResult<TData, TError>>;
89
+ type RequestFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = 'fields'>(options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'> & Pick<Required<RequestOptions<TData, TResponseStyle, ThrowOnError>>, 'method'>) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
85
90
  type BuildUrlFn = <TData extends {
86
91
  body?: unknown;
87
92
  path?: Record<string, unknown>;
88
93
  query?: Record<string, unknown>;
89
94
  url: string;
90
- }>(options: Pick<TData, 'url'> & Options<TData>) => string;
91
- export type Client = CoreClient<RequestFn, Config, MethodFn, BuildUrlFn> & {
92
- interceptors: Middleware<Request, Response, unknown, RequestOptions>;
95
+ }>(options: TData & Options<TData>) => string;
96
+ export type Client = CoreClient<RequestFn, Config, MethodFn, BuildUrlFn, SseFn> & {
97
+ interceptors: Middleware<Request, Response, unknown, ResolvedRequestOptions>;
93
98
  };
94
99
  /**
95
100
  * The `createClientConfig()` function will be called on client initialization
@@ -108,12 +113,5 @@ export interface TDataShape {
108
113
  url: string;
109
114
  }
110
115
  type OmitKeys<T, K> = Pick<T, Exclude<keyof T, K>>;
111
- export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean, TResponseStyle extends ResponseStyle = 'fields'> = OmitKeys<RequestOptions<TResponseStyle, ThrowOnError>, 'body' | 'path' | 'query' | 'url'> & Omit<TData, 'url'>;
112
- export type OptionsLegacyParser<TData = unknown, ThrowOnError extends boolean = boolean, TResponseStyle extends ResponseStyle = 'fields'> = TData extends {
113
- body?: any;
114
- } ? TData extends {
115
- headers?: any;
116
- } ? OmitKeys<RequestOptions<TResponseStyle, ThrowOnError>, 'body' | 'headers' | 'url'> & TData : OmitKeys<RequestOptions<TResponseStyle, ThrowOnError>, 'body' | 'url'> & TData & Pick<RequestOptions<TResponseStyle, ThrowOnError>, 'headers'> : TData extends {
117
- headers?: any;
118
- } ? OmitKeys<RequestOptions<TResponseStyle, ThrowOnError>, 'headers' | 'url'> & TData & Pick<RequestOptions<TResponseStyle, ThrowOnError>, 'body'> : OmitKeys<RequestOptions<TResponseStyle, ThrowOnError>, 'url'> & TData;
116
+ export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean, TResponse = unknown, TResponseStyle extends ResponseStyle = 'fields'> = OmitKeys<RequestOptions<TResponse, TResponseStyle, ThrowOnError>, 'body' | 'path' | 'query' | 'url'> & ([TData] extends [never] ? unknown : Omit<TData, 'url'>);
119
117
  export {};
@@ -1,2 +1,3 @@
1
1
  "use strict";
2
+ // This file is auto-generated by @hey-api/openapi-ts
2
3
  Object.defineProperty(exports, "__esModule", { value: true });