@remkoj/optimizely-cms-api 6.0.0-pre9 → 6.0.0-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +66 -0
- package/README.md +6 -2
- package/dist/api-client.d.ts +10 -77
- package/dist/api-client.js +18 -171
- package/dist/client/client/client.gen.js +114 -102
- package/dist/client/client/index.d.ts +3 -1
- package/dist/client/client/types.gen.d.ts +9 -13
- package/dist/client/client/utils.gen.d.ts +8 -4
- package/dist/client/client/utils.gen.js +15 -17
- package/dist/client/client.gen.d.ts +2 -2
- package/dist/client/client.gen.js +2 -4
- package/dist/client/core/auth.gen.d.ts +7 -0
- package/dist/client/core/bodySerializer.gen.d.ts +16 -8
- package/dist/client/core/bodySerializer.gen.js +1 -1
- package/dist/client/core/params.gen.d.ts +12 -2
- package/dist/client/core/params.gen.js +40 -20
- package/dist/client/core/pathSerializer.gen.js +3 -11
- package/dist/client/core/queryKeySerializer.gen.d.ts +1 -1
- package/dist/client/core/queryKeySerializer.gen.js +4 -11
- package/dist/client/core/serverSentEvents.gen.d.ts +1 -1
- package/dist/client/core/serverSentEvents.gen.js +7 -11
- package/dist/client/core/types.gen.d.ts +6 -1
- package/dist/client/core/utils.gen.js +1 -1
- package/dist/client/index.d.ts +4 -4
- package/dist/client/index.js +140 -17
- package/dist/client/sdk.gen.d.ts +336 -23
- package/dist/client/sdk.gen.js +761 -148
- package/dist/client/transformers.gen.d.ts +49 -1
- package/dist/client/transformers.gen.js +491 -49
- package/dist/client/types.gen.d.ts +5323 -466
- package/dist/client-config.d.ts +11 -0
- package/dist/client-config.js +21 -10
- package/dist/config.d.ts +39 -4
- package/dist/config.js +44 -18
- package/dist/getaccesstoken.js +22 -4
- package/dist/index.d.ts +20 -2
- package/dist/index.js +18 -5
- package/dist/types.d.ts +1 -14
- package/dist/types.js +0 -7
- package/dist/version.json +3 -3
- package/package.json +23 -12
- package/dist/instance.client/client/client.gen.d.ts +0 -2
- package/dist/instance.client/client/client.gen.js +0 -208
- package/dist/instance.client/client/index.d.ts +0 -8
- package/dist/instance.client/client/index.js +0 -17
- package/dist/instance.client/client/types.gen.d.ts +0 -124
- package/dist/instance.client/client/types.gen.js +0 -3
- package/dist/instance.client/client/utils.gen.d.ts +0 -33
- package/dist/instance.client/client/utils.gen.js +0 -241
- package/dist/instance.client/client.gen.d.ts +0 -12
- package/dist/instance.client/client.gen.js +0 -9
- package/dist/instance.client/core/auth.gen.d.ts +0 -18
- package/dist/instance.client/core/auth.gen.js +0 -18
- package/dist/instance.client/core/bodySerializer.gen.d.ts +0 -17
- package/dist/instance.client/core/bodySerializer.gen.js +0 -60
- package/dist/instance.client/core/params.gen.d.ts +0 -33
- package/dist/instance.client/core/params.gen.js +0 -92
- package/dist/instance.client/core/pathSerializer.gen.d.ts +0 -33
- package/dist/instance.client/core/pathSerializer.gen.js +0 -123
- package/dist/instance.client/core/queryKeySerializer.gen.d.ts +0 -18
- package/dist/instance.client/core/queryKeySerializer.gen.js +0 -105
- package/dist/instance.client/core/serverSentEvents.gen.d.ts +0 -71
- package/dist/instance.client/core/serverSentEvents.gen.js +0 -139
- package/dist/instance.client/core/types.gen.d.ts +0 -78
- package/dist/instance.client/core/types.gen.js +0 -3
- package/dist/instance.client/core/utils.gen.d.ts +0 -19
- package/dist/instance.client/core/utils.gen.js +0 -93
- package/dist/instance.client/index.d.ts +0 -4
- package/dist/instance.client/index.js +0 -21
- package/dist/instance.client/sdk.gen.d.ts +0 -256
- package/dist/instance.client/sdk.gen.js +0 -638
- package/dist/instance.client/transformers.gen.d.ts +0 -34
- package/dist/instance.client/transformers.gen.js +0 -273
- package/dist/instance.client/types.gen.d.ts +0 -2838
- package/dist/instance.client/types.gen.js +0 -3
|
@@ -22,10 +22,7 @@ const createClient = (config = {}) => {
|
|
|
22
22
|
serializedBody: undefined,
|
|
23
23
|
};
|
|
24
24
|
if (opts.security) {
|
|
25
|
-
await (0, utils_gen_2.setAuthParams)(
|
|
26
|
-
...opts,
|
|
27
|
-
security: opts.security,
|
|
28
|
-
});
|
|
25
|
+
await (0, utils_gen_2.setAuthParams)(opts);
|
|
29
26
|
}
|
|
30
27
|
if (opts.requestValidator) {
|
|
31
28
|
await opts.requestValidator(opts);
|
|
@@ -37,125 +34,139 @@ const createClient = (config = {}) => {
|
|
|
37
34
|
if (opts.body === undefined || opts.serializedBody === '') {
|
|
38
35
|
opts.headers.delete('Content-Type');
|
|
39
36
|
}
|
|
40
|
-
const
|
|
41
|
-
|
|
37
|
+
const resolvedOpts = opts;
|
|
38
|
+
const url = (0, utils_gen_2.buildUrl)(resolvedOpts);
|
|
39
|
+
return { opts: resolvedOpts, url };
|
|
42
40
|
};
|
|
43
41
|
const request = async (options) => {
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
42
|
+
const throwOnError = options.throwOnError ?? _config.throwOnError;
|
|
43
|
+
const responseStyle = options.responseStyle ?? _config.responseStyle;
|
|
44
|
+
let request;
|
|
45
|
+
let response;
|
|
46
|
+
try {
|
|
47
|
+
const { opts, url } = await beforeRequest(options);
|
|
48
|
+
const requestInit = {
|
|
49
|
+
redirect: 'follow',
|
|
50
|
+
...opts,
|
|
51
|
+
body: (0, utils_gen_1.getValidRequestBody)(opts),
|
|
52
|
+
};
|
|
53
|
+
request = new Request(url, requestInit);
|
|
54
|
+
for (const fn of interceptors.request.fns) {
|
|
55
|
+
if (fn) {
|
|
56
|
+
request = await fn(request, opts);
|
|
57
|
+
}
|
|
55
58
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
59
|
+
// fetch must be assigned here, otherwise it would throw the error:
|
|
60
|
+
// TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
|
|
61
|
+
const _fetch = opts.fetch;
|
|
62
|
+
response = await _fetch(request);
|
|
63
|
+
for (const fn of interceptors.response.fns) {
|
|
64
|
+
if (fn) {
|
|
65
|
+
response = await fn(response, request, opts);
|
|
66
|
+
}
|
|
64
67
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
68
|
+
const result = {
|
|
69
|
+
request,
|
|
70
|
+
response,
|
|
71
|
+
};
|
|
72
|
+
if (response.ok) {
|
|
73
|
+
const parseAs = (opts.parseAs === 'auto'
|
|
74
|
+
? (0, utils_gen_2.getParseAs)(response.headers.get('Content-Type'))
|
|
75
|
+
: opts.parseAs) ?? 'json';
|
|
76
|
+
if (response.status === 204 || response.headers.get('Content-Length') === '0') {
|
|
77
|
+
let emptyData;
|
|
78
|
+
switch (parseAs) {
|
|
79
|
+
case 'arrayBuffer':
|
|
80
|
+
case 'blob':
|
|
81
|
+
case 'text':
|
|
82
|
+
emptyData = await response[parseAs]();
|
|
83
|
+
break;
|
|
84
|
+
case 'formData':
|
|
85
|
+
emptyData = new FormData();
|
|
86
|
+
break;
|
|
87
|
+
case 'stream':
|
|
88
|
+
emptyData = response.body;
|
|
89
|
+
break;
|
|
90
|
+
case 'json':
|
|
91
|
+
default:
|
|
92
|
+
emptyData = {};
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
return opts.responseStyle === 'data'
|
|
96
|
+
? emptyData
|
|
97
|
+
: {
|
|
98
|
+
data: emptyData,
|
|
99
|
+
...result,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
let data;
|
|
77
103
|
switch (parseAs) {
|
|
78
104
|
case 'arrayBuffer':
|
|
79
105
|
case 'blob':
|
|
106
|
+
case 'formData':
|
|
80
107
|
case 'text':
|
|
81
|
-
|
|
108
|
+
data = await response[parseAs]();
|
|
82
109
|
break;
|
|
83
|
-
case '
|
|
84
|
-
|
|
110
|
+
case 'json': {
|
|
111
|
+
// Some servers return 200 with no Content-Length and empty body.
|
|
112
|
+
// response.json() would throw; read as text and parse if non-empty.
|
|
113
|
+
const text = await response.text();
|
|
114
|
+
data = text ? JSON.parse(text) : {};
|
|
85
115
|
break;
|
|
116
|
+
}
|
|
86
117
|
case 'stream':
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
118
|
+
return opts.responseStyle === 'data'
|
|
119
|
+
? response.body
|
|
120
|
+
: {
|
|
121
|
+
data: response.body,
|
|
122
|
+
...result,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
if (parseAs === 'json') {
|
|
126
|
+
if (opts.responseValidator) {
|
|
127
|
+
await opts.responseValidator(data);
|
|
128
|
+
}
|
|
129
|
+
if (opts.responseTransformer) {
|
|
130
|
+
data = await opts.responseTransformer(data);
|
|
131
|
+
}
|
|
93
132
|
}
|
|
94
133
|
return opts.responseStyle === 'data'
|
|
95
|
-
?
|
|
134
|
+
? data
|
|
96
135
|
: {
|
|
97
|
-
data
|
|
136
|
+
data,
|
|
98
137
|
...result,
|
|
99
138
|
};
|
|
100
139
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
case 'formData':
|
|
106
|
-
case 'json':
|
|
107
|
-
case 'text':
|
|
108
|
-
data = await response[parseAs]();
|
|
109
|
-
break;
|
|
110
|
-
case 'stream':
|
|
111
|
-
return opts.responseStyle === 'data'
|
|
112
|
-
? response.body
|
|
113
|
-
: {
|
|
114
|
-
data: response.body,
|
|
115
|
-
...result,
|
|
116
|
-
};
|
|
140
|
+
const textError = await response.text();
|
|
141
|
+
let jsonError;
|
|
142
|
+
try {
|
|
143
|
+
jsonError = JSON.parse(textError);
|
|
117
144
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
145
|
+
catch {
|
|
146
|
+
// noop
|
|
147
|
+
}
|
|
148
|
+
throw jsonError ?? textError;
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
let finalError = error;
|
|
152
|
+
for (const fn of interceptors.error.fns) {
|
|
153
|
+
if (fn) {
|
|
154
|
+
finalError = await fn(finalError, response, request, options);
|
|
124
155
|
}
|
|
125
156
|
}
|
|
126
|
-
|
|
127
|
-
|
|
157
|
+
finalError = finalError || {};
|
|
158
|
+
if (throwOnError) {
|
|
159
|
+
throw finalError;
|
|
160
|
+
}
|
|
161
|
+
// TODO: we probably want to return error and improve types
|
|
162
|
+
return responseStyle === 'data'
|
|
163
|
+
? undefined
|
|
128
164
|
: {
|
|
129
|
-
|
|
130
|
-
|
|
165
|
+
error: finalError,
|
|
166
|
+
request,
|
|
167
|
+
response,
|
|
131
168
|
};
|
|
132
169
|
}
|
|
133
|
-
const textError = await response.text();
|
|
134
|
-
let jsonError;
|
|
135
|
-
try {
|
|
136
|
-
jsonError = JSON.parse(textError);
|
|
137
|
-
}
|
|
138
|
-
catch {
|
|
139
|
-
// noop
|
|
140
|
-
}
|
|
141
|
-
const error = jsonError ?? textError;
|
|
142
|
-
let finalError = error;
|
|
143
|
-
for (const fn of interceptors.error.fns) {
|
|
144
|
-
if (fn) {
|
|
145
|
-
finalError = (await fn(error, response, request, opts));
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
finalError = finalError || {};
|
|
149
|
-
if (opts.throwOnError) {
|
|
150
|
-
throw finalError;
|
|
151
|
-
}
|
|
152
|
-
// TODO: we probably want to return error and improve types
|
|
153
|
-
return opts.responseStyle === 'data'
|
|
154
|
-
? undefined
|
|
155
|
-
: {
|
|
156
|
-
error: finalError,
|
|
157
|
-
...result,
|
|
158
|
-
};
|
|
159
170
|
};
|
|
160
171
|
const makeMethodFn = (method) => (options) => request({ ...options, method });
|
|
161
172
|
const makeSseFn = (method) => async (options) => {
|
|
@@ -163,7 +174,6 @@ const createClient = (config = {}) => {
|
|
|
163
174
|
return (0, serverSentEvents_gen_1.createSseClient)({
|
|
164
175
|
...opts,
|
|
165
176
|
body: opts.body,
|
|
166
|
-
headers: opts.headers,
|
|
167
177
|
method,
|
|
168
178
|
onRequest: async (url, init) => {
|
|
169
179
|
let request = new Request(url, init);
|
|
@@ -174,11 +184,13 @@ const createClient = (config = {}) => {
|
|
|
174
184
|
}
|
|
175
185
|
return request;
|
|
176
186
|
},
|
|
187
|
+
serializedBody: (0, utils_gen_1.getValidRequestBody)(opts),
|
|
177
188
|
url,
|
|
178
189
|
});
|
|
179
190
|
};
|
|
191
|
+
const _buildUrl = (options) => (0, utils_gen_2.buildUrl)({ ..._config, ...options });
|
|
180
192
|
return {
|
|
181
|
-
buildUrl:
|
|
193
|
+
buildUrl: _buildUrl,
|
|
182
194
|
connect: makeMethodFn('CONNECT'),
|
|
183
195
|
delete: makeMethodFn('DELETE'),
|
|
184
196
|
get: makeMethodFn('GET'),
|
|
@@ -3,6 +3,8 @@ export type { QuerySerializerOptions } from '../core/bodySerializer.gen';
|
|
|
3
3
|
export { formDataBodySerializer, jsonBodySerializer, urlSearchParamsBodySerializer, } from '../core/bodySerializer.gen';
|
|
4
4
|
export { buildClientParams } from '../core/params.gen';
|
|
5
5
|
export { serializeQueryKeyValue } from '../core/queryKeySerializer.gen';
|
|
6
|
+
export type { ServerSentEventsResult } from '../core/serverSentEvents.gen';
|
|
7
|
+
export type { ClientMeta } from '../core/types.gen';
|
|
6
8
|
export { createClient } from './client.gen';
|
|
7
|
-
export type { Client, ClientOptions, Config, CreateClientConfig, Options,
|
|
9
|
+
export type { Client, ClientOptions, Config, CreateClientConfig, Options, RequestOptions, RequestResult, ResolvedRequestOptions, ResponseStyle, TDataShape, } from './types.gen';
|
|
8
10
|
export { createConfig, mergeHeaders } from './utils.gen';
|
|
@@ -47,7 +47,7 @@ export interface Config<T extends ClientOptions = ClientOptions> extends Omit<Re
|
|
|
47
47
|
export interface RequestOptions<TData = unknown, TResponseStyle extends ResponseStyle = 'fields', ThrowOnError extends boolean = boolean, Url extends string = string> extends Config<{
|
|
48
48
|
responseStyle: TResponseStyle;
|
|
49
49
|
throwOnError: ThrowOnError;
|
|
50
|
-
}>, Pick<ServerSentEventsOptions<TData>, 'onSseError' | 'onSseEvent' | 'sseDefaultRetryDelay' | 'sseMaxRetryAttempts' | 'sseMaxRetryDelay'> {
|
|
50
|
+
}>, Pick<ServerSentEventsOptions<TData>, 'onRequest' | 'onSseError' | 'onSseEvent' | 'sseDefaultRetryDelay' | 'sseMaxRetryAttempts' | 'sseMaxRetryDelay'> {
|
|
51
51
|
/**
|
|
52
52
|
* Any body that you want to add to your request.
|
|
53
53
|
*
|
|
@@ -63,6 +63,7 @@ export interface RequestOptions<TData = unknown, TResponseStyle extends Response
|
|
|
63
63
|
url: Url;
|
|
64
64
|
}
|
|
65
65
|
export interface ResolvedRequestOptions<TResponseStyle extends ResponseStyle = 'fields', ThrowOnError extends boolean = boolean, Url extends string = string> extends RequestOptions<unknown, TResponseStyle, ThrowOnError, Url> {
|
|
66
|
+
headers: Headers;
|
|
66
67
|
serializedBody?: string;
|
|
67
68
|
}
|
|
68
69
|
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 : {
|
|
@@ -76,8 +77,10 @@ export type RequestResult<TData = unknown, TError = unknown, ThrowOnError extend
|
|
|
76
77
|
data: undefined;
|
|
77
78
|
error: TError extends Record<string, unknown> ? TError[keyof TError] : TError;
|
|
78
79
|
}) & {
|
|
79
|
-
request
|
|
80
|
-
|
|
80
|
+
/** request may be undefined, because error may be from building the request object itself */
|
|
81
|
+
request?: Request;
|
|
82
|
+
/** response may be undefined, because error may be from building the request object itself or from a network error */
|
|
83
|
+
response?: Response;
|
|
81
84
|
}>;
|
|
82
85
|
export interface ClientOptions {
|
|
83
86
|
baseUrl?: string;
|
|
@@ -85,14 +88,14 @@ export interface ClientOptions {
|
|
|
85
88
|
throwOnError?: boolean;
|
|
86
89
|
}
|
|
87
90
|
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,
|
|
91
|
+
type SseFn = <TData = unknown, _TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = 'fields'>(options: Omit<RequestOptions<never, TResponseStyle, ThrowOnError>, 'method'>) => Promise<ServerSentEventsResult<TData>>;
|
|
89
92
|
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>;
|
|
90
93
|
type BuildUrlFn = <TData extends {
|
|
91
94
|
body?: unknown;
|
|
92
95
|
path?: Record<string, unknown>;
|
|
93
96
|
query?: Record<string, unknown>;
|
|
94
97
|
url: string;
|
|
95
|
-
}>(options:
|
|
98
|
+
}>(options: TData & Options<TData>) => string;
|
|
96
99
|
export type Client = CoreClient<RequestFn, Config, MethodFn, BuildUrlFn, SseFn> & {
|
|
97
100
|
interceptors: Middleware<Request, Response, unknown, ResolvedRequestOptions>;
|
|
98
101
|
};
|
|
@@ -113,12 +116,5 @@ export interface TDataShape {
|
|
|
113
116
|
url: string;
|
|
114
117
|
}
|
|
115
118
|
type OmitKeys<T, K> = Pick<T, Exclude<keyof T, K>>;
|
|
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'> & Omit<TData, 'url'
|
|
117
|
-
export type OptionsLegacyParser<TData = unknown, ThrowOnError extends boolean = boolean, TResponseStyle extends ResponseStyle = 'fields'> = TData extends {
|
|
118
|
-
body?: any;
|
|
119
|
-
} ? TData extends {
|
|
120
|
-
headers?: any;
|
|
121
|
-
} ? OmitKeys<RequestOptions<unknown, TResponseStyle, ThrowOnError>, 'body' | 'headers' | 'url'> & TData : OmitKeys<RequestOptions<unknown, TResponseStyle, ThrowOnError>, 'body' | 'url'> & TData & Pick<RequestOptions<unknown, TResponseStyle, ThrowOnError>, 'headers'> : TData extends {
|
|
122
|
-
headers?: any;
|
|
123
|
-
} ? OmitKeys<RequestOptions<unknown, TResponseStyle, ThrowOnError>, 'headers' | 'url'> & TData & Pick<RequestOptions<unknown, TResponseStyle, ThrowOnError>, 'body'> : OmitKeys<RequestOptions<unknown, TResponseStyle, ThrowOnError>, 'url'> & TData;
|
|
119
|
+
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'>);
|
|
124
120
|
export {};
|
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import type { QuerySerializerOptions } from '../core/bodySerializer.gen';
|
|
2
2
|
import type { Client, ClientOptions, Config, RequestOptions } from './types.gen';
|
|
3
|
-
export declare const createQuerySerializer: <T = unknown>({
|
|
3
|
+
export declare const createQuerySerializer: <T = unknown>({ parameters, ...args }?: QuerySerializerOptions) => ((queryParams: T) => string);
|
|
4
4
|
/**
|
|
5
5
|
* Infers parseAs value from provided Content-Type header.
|
|
6
6
|
*/
|
|
7
7
|
export declare const getParseAs: (contentType: string | null) => Exclude<Config["parseAs"], "auto">;
|
|
8
|
-
export declare
|
|
8
|
+
export declare function setAuthParams(options: Pick<RequestOptions, 'auth' | 'query' | 'security'> & {
|
|
9
9
|
headers: Headers;
|
|
10
|
-
})
|
|
10
|
+
}): Promise<void>;
|
|
11
11
|
export declare const buildUrl: Client['buildUrl'];
|
|
12
12
|
export declare const mergeConfigs: (a: Config, b: Config) => Config;
|
|
13
13
|
export declare const mergeHeaders: (...headers: Array<Required<Config>["headers"] | undefined>) => Headers;
|
|
14
|
-
type ErrInterceptor<Err, Res, Req, Options> = (error: Err,
|
|
14
|
+
type ErrInterceptor<Err, Res, Req, Options> = (error: Err,
|
|
15
|
+
/** response may be undefined due to a network error where no response object is produced */
|
|
16
|
+
response: Res | undefined,
|
|
17
|
+
/** request may be undefined, because error may be from building the request object itself */
|
|
18
|
+
request: Req | undefined, options: Options) => Err | Promise<Err>;
|
|
15
19
|
type ReqInterceptor<Req, Options> = (request: Req, options: Options) => Req | Promise<Req>;
|
|
16
20
|
type ResInterceptor<Res, Req, Options> = (response: Res, request: Req, options: Options) => Res | Promise<Res>;
|
|
17
21
|
declare class Interceptors<Interceptor> {
|
|
@@ -1,12 +1,13 @@
|
|
|
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.createConfig = exports.createInterceptors = exports.mergeHeaders = exports.mergeConfigs = exports.buildUrl = exports.
|
|
4
|
+
exports.createConfig = exports.createInterceptors = exports.mergeHeaders = exports.mergeConfigs = exports.buildUrl = exports.getParseAs = exports.createQuerySerializer = void 0;
|
|
5
|
+
exports.setAuthParams = setAuthParams;
|
|
5
6
|
const auth_gen_1 = require("../core/auth.gen");
|
|
6
7
|
const bodySerializer_gen_1 = require("../core/bodySerializer.gen");
|
|
7
8
|
const pathSerializer_gen_1 = require("../core/pathSerializer.gen");
|
|
8
9
|
const utils_gen_1 = require("../core/utils.gen");
|
|
9
|
-
const createQuerySerializer = ({
|
|
10
|
+
const createQuerySerializer = ({ parameters = {}, ...args } = {}) => {
|
|
10
11
|
const querySerializer = (queryParams) => {
|
|
11
12
|
const search = [];
|
|
12
13
|
if (queryParams && typeof queryParams === 'object') {
|
|
@@ -15,33 +16,34 @@ const createQuerySerializer = ({ allowReserved, array, object, } = {}) => {
|
|
|
15
16
|
if (value === undefined || value === null) {
|
|
16
17
|
continue;
|
|
17
18
|
}
|
|
19
|
+
const options = parameters[name] || args;
|
|
18
20
|
if (Array.isArray(value)) {
|
|
19
21
|
const serializedArray = (0, pathSerializer_gen_1.serializeArrayParam)({
|
|
20
|
-
allowReserved,
|
|
22
|
+
allowReserved: options.allowReserved,
|
|
21
23
|
explode: true,
|
|
22
24
|
name,
|
|
23
25
|
style: 'form',
|
|
24
26
|
value,
|
|
25
|
-
...array,
|
|
27
|
+
...options.array,
|
|
26
28
|
});
|
|
27
29
|
if (serializedArray)
|
|
28
30
|
search.push(serializedArray);
|
|
29
31
|
}
|
|
30
32
|
else if (typeof value === 'object') {
|
|
31
33
|
const serializedObject = (0, pathSerializer_gen_1.serializeObjectParam)({
|
|
32
|
-
allowReserved,
|
|
34
|
+
allowReserved: options.allowReserved,
|
|
33
35
|
explode: true,
|
|
34
36
|
name,
|
|
35
37
|
style: 'deepObject',
|
|
36
38
|
value: value,
|
|
37
|
-
...object,
|
|
39
|
+
...options.object,
|
|
38
40
|
});
|
|
39
41
|
if (serializedObject)
|
|
40
42
|
search.push(serializedObject);
|
|
41
43
|
}
|
|
42
44
|
else {
|
|
43
45
|
const serializedPrimitive = (0, pathSerializer_gen_1.serializePrimitiveParam)({
|
|
44
|
-
allowReserved,
|
|
46
|
+
allowReserved: options.allowReserved,
|
|
45
47
|
name,
|
|
46
48
|
value: value,
|
|
47
49
|
});
|
|
@@ -68,8 +70,7 @@ const getParseAs = (contentType) => {
|
|
|
68
70
|
if (!cleanContent) {
|
|
69
71
|
return;
|
|
70
72
|
}
|
|
71
|
-
if (cleanContent.startsWith('application/json') ||
|
|
72
|
-
cleanContent.endsWith('+json')) {
|
|
73
|
+
if (cleanContent.startsWith('application/json') || cleanContent.endsWith('+json')) {
|
|
73
74
|
return 'json';
|
|
74
75
|
}
|
|
75
76
|
if (cleanContent === 'multipart/form-data') {
|
|
@@ -95,8 +96,8 @@ const checkForExistence = (options, name) => {
|
|
|
95
96
|
}
|
|
96
97
|
return false;
|
|
97
98
|
};
|
|
98
|
-
|
|
99
|
-
for (const auth of security) {
|
|
99
|
+
async function setAuthParams(options) {
|
|
100
|
+
for (const auth of options.security ?? []) {
|
|
100
101
|
if (checkForExistence(options, auth.name)) {
|
|
101
102
|
continue;
|
|
102
103
|
}
|
|
@@ -121,8 +122,7 @@ const setAuthParams = async ({ security, ...options }) => {
|
|
|
121
122
|
break;
|
|
122
123
|
}
|
|
123
124
|
}
|
|
124
|
-
}
|
|
125
|
-
exports.setAuthParams = setAuthParams;
|
|
125
|
+
}
|
|
126
126
|
const buildUrl = (options) => (0, utils_gen_1.getUrl)({
|
|
127
127
|
baseUrl: options.baseUrl,
|
|
128
128
|
path: options.path,
|
|
@@ -155,9 +155,7 @@ const mergeHeaders = (...headers) => {
|
|
|
155
155
|
if (!header) {
|
|
156
156
|
continue;
|
|
157
157
|
}
|
|
158
|
-
const iterator = header instanceof Headers
|
|
159
|
-
? headersEntries(header)
|
|
160
|
-
: Object.entries(header);
|
|
158
|
+
const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
|
|
161
159
|
for (const [key, value] of iterator) {
|
|
162
160
|
if (value === null) {
|
|
163
161
|
mergedHeaders.delete(key);
|
|
@@ -168,7 +166,7 @@ const mergeHeaders = (...headers) => {
|
|
|
168
166
|
}
|
|
169
167
|
}
|
|
170
168
|
else if (value !== undefined) {
|
|
171
|
-
// assume object headers are meant to be JSON stringified, i.e
|
|
169
|
+
// assume object headers are meant to be JSON stringified, i.e., their
|
|
172
170
|
// content value in OpenAPI specification is 'application/json'
|
|
173
171
|
mergedHeaders.set(key, typeof value === 'object' ? JSON.stringify(value) : value);
|
|
174
172
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ClientOptions, type Config } from './client';
|
|
1
|
+
import { type Client, type ClientOptions, type Config } from './client';
|
|
2
2
|
import type { ClientOptions as ClientOptions2 } from './types.gen';
|
|
3
3
|
/**
|
|
4
4
|
* The `createClientConfig()` function will be called on client initialization
|
|
@@ -9,4 +9,4 @@ import type { ClientOptions as ClientOptions2 } from './types.gen';
|
|
|
9
9
|
* to ensure your client always has the correct values.
|
|
10
10
|
*/
|
|
11
11
|
export type CreateClientConfig<T extends ClientOptions = ClientOptions2> = (override?: Config<ClientOptions & T>) => Config<Required<ClientOptions> & T>;
|
|
12
|
-
export declare const client:
|
|
12
|
+
export declare const client: Client;
|
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
// This file is auto-generated by @hey-api/openapi-ts
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.client = void 0;
|
|
5
|
-
const client_1 = require("./client");
|
|
6
5
|
const client_config_1 = require("../client-config");
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
})));
|
|
6
|
+
const client_1 = require("./client");
|
|
7
|
+
exports.client = (0, client_1.createClient)((0, client_config_1.createClientConfig)((0, client_1.createConfig)({ baseUrl: 'https://api.cms.optimizely.com/v1' })));
|
|
@@ -6,6 +6,13 @@ export interface Auth {
|
|
|
6
6
|
* @default 'header'
|
|
7
7
|
*/
|
|
8
8
|
in?: 'header' | 'query' | 'cookie';
|
|
9
|
+
/**
|
|
10
|
+
* A unique identifier for the security scheme.
|
|
11
|
+
*
|
|
12
|
+
* Defined only when there are multiple security schemes whose `Auth`
|
|
13
|
+
* shape would otherwise be identical.
|
|
14
|
+
*/
|
|
15
|
+
key?: string;
|
|
9
16
|
/**
|
|
10
17
|
* Header or query parameter name.
|
|
11
18
|
*
|
|
@@ -1,17 +1,25 @@
|
|
|
1
1
|
import type { ArrayStyle, ObjectStyle, SerializerOptions } from './pathSerializer.gen';
|
|
2
2
|
export type QuerySerializer = (query: Record<string, unknown>) => string;
|
|
3
|
-
export type BodySerializer = (body:
|
|
4
|
-
|
|
3
|
+
export type BodySerializer = (body: unknown) => unknown;
|
|
4
|
+
type QuerySerializerOptionsObject = {
|
|
5
5
|
allowReserved?: boolean;
|
|
6
|
-
array?: SerializerOptions<ArrayStyle
|
|
7
|
-
object?: SerializerOptions<ObjectStyle
|
|
8
|
-
}
|
|
6
|
+
array?: Partial<SerializerOptions<ArrayStyle>>;
|
|
7
|
+
object?: Partial<SerializerOptions<ObjectStyle>>;
|
|
8
|
+
};
|
|
9
|
+
export type QuerySerializerOptions = QuerySerializerOptionsObject & {
|
|
10
|
+
/**
|
|
11
|
+
* Per-parameter serialization overrides. When provided, these settings
|
|
12
|
+
* override the global array/object settings for specific parameter names.
|
|
13
|
+
*/
|
|
14
|
+
parameters?: Record<string, QuerySerializerOptionsObject>;
|
|
15
|
+
};
|
|
9
16
|
export declare const formDataBodySerializer: {
|
|
10
|
-
bodySerializer:
|
|
17
|
+
bodySerializer: (body: unknown) => FormData;
|
|
11
18
|
};
|
|
12
19
|
export declare const jsonBodySerializer: {
|
|
13
|
-
bodySerializer:
|
|
20
|
+
bodySerializer: (body: unknown) => string;
|
|
14
21
|
};
|
|
15
22
|
export declare const urlSearchParamsBodySerializer: {
|
|
16
|
-
bodySerializer:
|
|
23
|
+
bodySerializer: (body: unknown) => string;
|
|
17
24
|
};
|
|
25
|
+
export {};
|
|
@@ -39,7 +39,7 @@ exports.formDataBodySerializer = {
|
|
|
39
39
|
},
|
|
40
40
|
};
|
|
41
41
|
exports.jsonBodySerializer = {
|
|
42
|
-
bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === 'bigint' ? value.toString() : value),
|
|
42
|
+
bodySerializer: (body) => JSON.stringify(body, (_key, value) => (typeof value === 'bigint' ? value.toString() : value)),
|
|
43
43
|
};
|
|
44
44
|
exports.urlSearchParamsBodySerializer = {
|
|
45
45
|
bodySerializer: (body) => {
|
|
@@ -17,6 +17,16 @@ export type Field = {
|
|
|
17
17
|
*/
|
|
18
18
|
key?: string;
|
|
19
19
|
map?: string;
|
|
20
|
+
} | {
|
|
21
|
+
/**
|
|
22
|
+
* Field name. This is the name we want the user to see and use.
|
|
23
|
+
*/
|
|
24
|
+
key: string;
|
|
25
|
+
/**
|
|
26
|
+
* Field mapped name. This is the name we want to use in the request.
|
|
27
|
+
* If `in` is omitted, `map` aliases `key` to the transport layer.
|
|
28
|
+
*/
|
|
29
|
+
map: Slot;
|
|
20
30
|
};
|
|
21
31
|
export interface Fields {
|
|
22
32
|
allowExtra?: Partial<Record<Slot, boolean>>;
|
|
@@ -24,10 +34,10 @@ export interface Fields {
|
|
|
24
34
|
}
|
|
25
35
|
export type FieldsConfig = ReadonlyArray<Field | Fields>;
|
|
26
36
|
interface Params {
|
|
27
|
-
body
|
|
37
|
+
body?: unknown;
|
|
28
38
|
headers: Record<string, unknown>;
|
|
29
39
|
path: Record<string, unknown>;
|
|
30
40
|
query: Record<string, unknown>;
|
|
31
41
|
}
|
|
32
|
-
export declare
|
|
42
|
+
export declare function buildClientParams(args: ReadonlyArray<unknown>, fields: FieldsConfig): Params;
|
|
33
43
|
export {};
|