@rage-against-the-pixel/app-store-connect-api 4.0.0 → 4.1.0
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/README.md +1 -1
- package/dist/app_store_connect_api/client/client.gen.d.ts +2 -0
- package/dist/app_store_connect_api/client/client.gen.js +208 -0
- package/dist/app_store_connect_api/client/index.d.ts +7 -4
- package/dist/app_store_connect_api/client/index.js +13 -119
- package/dist/app_store_connect_api/client/types.gen.d.ts +124 -0
- package/dist/app_store_connect_api/client/{types.js → types.gen.js} +1 -0
- package/dist/app_store_connect_api/client/utils.gen.d.ts +33 -0
- package/dist/app_store_connect_api/client/utils.gen.js +241 -0
- package/dist/app_store_connect_api/client.gen.d.ts +12 -0
- package/dist/app_store_connect_api/client.gen.js +8 -0
- package/dist/app_store_connect_api/core/auth.gen.d.ts +18 -0
- package/dist/app_store_connect_api/core/auth.gen.js +18 -0
- package/dist/app_store_connect_api/core/bodySerializer.gen.d.ts +17 -0
- package/dist/app_store_connect_api/core/bodySerializer.gen.js +60 -0
- package/dist/app_store_connect_api/core/params.gen.d.ts +33 -0
- package/dist/app_store_connect_api/core/params.gen.js +92 -0
- package/dist/app_store_connect_api/core/pathSerializer.gen.d.ts +33 -0
- package/dist/app_store_connect_api/core/pathSerializer.gen.js +123 -0
- package/dist/app_store_connect_api/core/serverSentEvents.gen.d.ts +71 -0
- package/dist/app_store_connect_api/core/serverSentEvents.gen.js +139 -0
- package/dist/app_store_connect_api/core/types.gen.d.ts +78 -0
- package/dist/app_store_connect_api/core/types.gen.js +3 -0
- package/dist/app_store_connect_api/core/utils.gen.d.ts +19 -0
- package/dist/app_store_connect_api/core/utils.gen.js +93 -0
- package/dist/app_store_connect_api/index.d.ts +2 -2
- package/dist/app_store_connect_api/index.js +3 -3
- package/dist/app_store_connect_api/schemas.gen.d.ts +3781 -483
- package/dist/app_store_connect_api/schemas.gen.js +4382 -1060
- package/dist/app_store_connect_api/sdk.gen.d.ts +1611 -0
- package/dist/app_store_connect_api/sdk.gen.js +17940 -0
- package/dist/app_store_connect_api/types.gen.d.ts +53384 -13438
- package/dist/app_store_connect_api/types.gen.js +806 -0
- package/dist/client.d.ts +3 -4
- package/dist/client.js +4 -3
- package/package.json +10 -11
- package/dist/app_store_connect_api/client/types.d.ts +0 -121
- package/dist/app_store_connect_api/client/utils.d.ts +0 -63
- package/dist/app_store_connect_api/client/utils.js +0 -398
- package/dist/app_store_connect_api/services.gen.d.ts +0 -1548
- package/dist/app_store_connect_api/services.gen.js +0 -7134
package/dist/client.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import * as services from './app_store_connect_api/
|
|
1
|
+
import * as services from './app_store_connect_api/sdk.gen';
|
|
2
2
|
/**
|
|
3
3
|
* Options for configuring the App Store Connect client.
|
|
4
4
|
* @see https://developer.apple.com/documentation/appstoreconnectapi/creating_api_keys_for_app_store_connect_api
|
|
5
5
|
*/
|
|
6
|
-
interface AppStoreConnectOptions {
|
|
6
|
+
export interface AppStoreConnectOptions {
|
|
7
7
|
/**
|
|
8
8
|
* The issuer ID associated with the private key.
|
|
9
9
|
*/
|
|
@@ -29,7 +29,7 @@ interface AppStoreConnectOptions {
|
|
|
29
29
|
*/
|
|
30
30
|
expirationTime?: number;
|
|
31
31
|
}
|
|
32
|
-
declare class AppStoreConnectClient {
|
|
32
|
+
export declare class AppStoreConnectClient {
|
|
33
33
|
private appStoreConnectOptions;
|
|
34
34
|
private bearerToken;
|
|
35
35
|
private bearerTokenGeneratedAt;
|
|
@@ -47,4 +47,3 @@ declare class AppStoreConnectClient {
|
|
|
47
47
|
*/
|
|
48
48
|
private generateUserAuthToken;
|
|
49
49
|
}
|
|
50
|
-
export { AppStoreConnectOptions, AppStoreConnectClient };
|
package/dist/client.js
CHANGED
|
@@ -37,7 +37,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.AppStoreConnectClient = void 0;
|
|
40
|
-
const services = __importStar(require("./app_store_connect_api/
|
|
40
|
+
const services = __importStar(require("./app_store_connect_api/sdk.gen"));
|
|
41
|
+
const client_gen_1 = require("./app_store_connect_api/client.gen");
|
|
41
42
|
const jose = __importStar(require("jose"));
|
|
42
43
|
const fs_1 = __importDefault(require("fs"));
|
|
43
44
|
class AppStoreConnectClient {
|
|
@@ -50,8 +51,8 @@ class AppStoreConnectClient {
|
|
|
50
51
|
throw new Error('AppStoreConnectOptions is required');
|
|
51
52
|
}
|
|
52
53
|
this.appStoreConnectOptions = appStoreConnectOptions;
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
client_gen_1.client.setConfig({ baseUrl: 'https://api.appstoreconnect.apple.com' });
|
|
55
|
+
client_gen_1.client.interceptors.request.use(async (request, _options) => {
|
|
55
56
|
request.headers.set('Authorization', `Bearer ${await this.getToken()}`);
|
|
56
57
|
return request;
|
|
57
58
|
});
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rage-against-the-pixel/app-store-connect-api",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "A TypeScript package for communicating with Apple App Store Connect API",
|
|
5
5
|
"author": "RageAgainstThePixel",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "https://github.com/RageAgainstThePixel/app-store-connect-api"
|
|
9
|
+
"url": "git+https://github.com/RageAgainstThePixel/app-store-connect-api.git"
|
|
10
10
|
},
|
|
11
11
|
"keywords": [
|
|
12
12
|
"apple",
|
|
@@ -34,16 +34,15 @@
|
|
|
34
34
|
"generate": "npx @hey-api/openapi-ts -f ./openapi-ts.config.ts && tsc"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@hey-api/openapi-ts": "
|
|
38
|
-
"@types/jest": "
|
|
39
|
-
"@types/node": "
|
|
40
|
-
"jest": "
|
|
41
|
-
"ts-jest": "
|
|
42
|
-
"ts-node": "
|
|
43
|
-
"typescript": "
|
|
37
|
+
"@hey-api/openapi-ts": "0.84.4",
|
|
38
|
+
"@types/jest": "29.5.14",
|
|
39
|
+
"@types/node": "22.18.8",
|
|
40
|
+
"jest": "29.7.0",
|
|
41
|
+
"ts-jest": "29.4.4",
|
|
42
|
+
"ts-node": "10.9.2",
|
|
43
|
+
"typescript": "5.9.3"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"
|
|
47
|
-
"jose": "^5.10.0"
|
|
46
|
+
"jose": "5.10.0"
|
|
48
47
|
}
|
|
49
48
|
}
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import type { BodySerializer, Middleware, QuerySerializer, QuerySerializerOptions } from './utils';
|
|
2
|
-
type OmitKeys<T, K> = Pick<T, Exclude<keyof T, K>>;
|
|
3
|
-
export interface Config<ThrowOnError extends boolean = boolean> extends Omit<RequestInit, 'body' | 'headers' | 'method'> {
|
|
4
|
-
/**
|
|
5
|
-
* Base URL for all requests made by this client.
|
|
6
|
-
* @default ''
|
|
7
|
-
*/
|
|
8
|
-
baseUrl?: string;
|
|
9
|
-
/**
|
|
10
|
-
* Any body that you want to add to your request.
|
|
11
|
-
*
|
|
12
|
-
* {@link https://developer.mozilla.org/docs/Web/API/fetch#body}
|
|
13
|
-
*/
|
|
14
|
-
body?: RequestInit['body'] | Record<string, unknown> | Array<Record<string, unknown>> | Array<unknown> | number;
|
|
15
|
-
/**
|
|
16
|
-
* A function for serializing request body parameter. By default,
|
|
17
|
-
* {@link JSON.stringify()} will be used.
|
|
18
|
-
*/
|
|
19
|
-
bodySerializer?: BodySerializer;
|
|
20
|
-
/**
|
|
21
|
-
* Fetch API implementation. You can use this option to provide a custom
|
|
22
|
-
* fetch instance.
|
|
23
|
-
* @default globalThis.fetch
|
|
24
|
-
*/
|
|
25
|
-
fetch?: (request: Request) => ReturnType<typeof fetch>;
|
|
26
|
-
/**
|
|
27
|
-
* An object containing any HTTP headers that you want to pre-populate your
|
|
28
|
-
* `Headers` object with.
|
|
29
|
-
*
|
|
30
|
-
* {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more}
|
|
31
|
-
*/
|
|
32
|
-
headers?: RequestInit['headers'] | Record<string, string | number | boolean | (string | number | boolean)[] | null | undefined | unknown>;
|
|
33
|
-
/**
|
|
34
|
-
* The request method.
|
|
35
|
-
*
|
|
36
|
-
* {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more}
|
|
37
|
-
*/
|
|
38
|
-
method?: 'CONNECT' | 'DELETE' | 'GET' | 'HEAD' | 'OPTIONS' | 'PATCH' | 'POST' | 'PUT' | 'TRACE';
|
|
39
|
-
/**
|
|
40
|
-
* Return the response data parsed in a specified format. By default, `auto`
|
|
41
|
-
* will infer the appropriate method from the `Content-Type` response header.
|
|
42
|
-
* You can override this behavior with any of the {@link Body} methods.
|
|
43
|
-
* Select `stream` if you don't want to parse response data at all.
|
|
44
|
-
* @default 'auto'
|
|
45
|
-
*/
|
|
46
|
-
parseAs?: Exclude<keyof Body, 'body' | 'bodyUsed'> | 'auto' | 'stream';
|
|
47
|
-
/**
|
|
48
|
-
* A function for serializing request query parameters. By default, arrays
|
|
49
|
-
* will be exploded in form style, objects will be exploded in deepObject
|
|
50
|
-
* style, and reserved characters are percent-encoded.
|
|
51
|
-
*
|
|
52
|
-
* {@link https://swagger.io/docs/specification/serialization/#query View examples}
|
|
53
|
-
*/
|
|
54
|
-
querySerializer?: QuerySerializer | QuerySerializerOptions;
|
|
55
|
-
/**
|
|
56
|
-
* A function for transforming response data before it's returned to the
|
|
57
|
-
* caller function. This is an ideal place to post-process server data,
|
|
58
|
-
* e.g. convert date ISO strings into native Date objects.
|
|
59
|
-
*/
|
|
60
|
-
responseTransformer?: (data: unknown) => Promise<unknown>;
|
|
61
|
-
/**
|
|
62
|
-
* Throw an error instead of returning it in the response?
|
|
63
|
-
* @default false
|
|
64
|
-
*/
|
|
65
|
-
throwOnError?: ThrowOnError;
|
|
66
|
-
}
|
|
67
|
-
export interface RequestOptionsBase<ThrowOnError extends boolean> extends Config<ThrowOnError> {
|
|
68
|
-
path?: Record<string, unknown>;
|
|
69
|
-
query?: Record<string, unknown>;
|
|
70
|
-
url: string;
|
|
71
|
-
}
|
|
72
|
-
export type RequestResult<Data = unknown, TError = unknown, ThrowOnError extends boolean = boolean> = ThrowOnError extends true ? Promise<{
|
|
73
|
-
data: Data;
|
|
74
|
-
request: Request;
|
|
75
|
-
response: Response;
|
|
76
|
-
}> : Promise<({
|
|
77
|
-
data: Data;
|
|
78
|
-
error: undefined;
|
|
79
|
-
} | {
|
|
80
|
-
data: undefined;
|
|
81
|
-
error: TError;
|
|
82
|
-
}) & {
|
|
83
|
-
request: Request;
|
|
84
|
-
response: Response;
|
|
85
|
-
}>;
|
|
86
|
-
type MethodFn = <Data = unknown, TError = unknown, ThrowOnError extends boolean = false>(options: Omit<RequestOptionsBase<ThrowOnError>, 'method'>) => RequestResult<Data, TError, ThrowOnError>;
|
|
87
|
-
type RequestFn = <Data = unknown, TError = unknown, ThrowOnError extends boolean = false>(options: Omit<RequestOptionsBase<ThrowOnError>, 'method'> & Pick<Required<RequestOptionsBase<ThrowOnError>>, 'method'>) => RequestResult<Data, TError, ThrowOnError>;
|
|
88
|
-
export interface Client<Req = Request, Res = Response, Err = unknown, Options = RequestOptions> {
|
|
89
|
-
connect: MethodFn;
|
|
90
|
-
delete: MethodFn;
|
|
91
|
-
get: MethodFn;
|
|
92
|
-
getConfig: () => Config;
|
|
93
|
-
head: MethodFn;
|
|
94
|
-
interceptors: Middleware<Req, Res, Err, Options>;
|
|
95
|
-
options: MethodFn;
|
|
96
|
-
patch: MethodFn;
|
|
97
|
-
post: MethodFn;
|
|
98
|
-
put: MethodFn;
|
|
99
|
-
request: RequestFn;
|
|
100
|
-
setConfig: (config: Config) => Config;
|
|
101
|
-
trace: MethodFn;
|
|
102
|
-
}
|
|
103
|
-
export type RequestOptions = RequestOptionsBase<false> & Config<false> & {
|
|
104
|
-
headers: Headers;
|
|
105
|
-
};
|
|
106
|
-
type OptionsBase<ThrowOnError extends boolean> = Omit<RequestOptionsBase<ThrowOnError>, 'url'> & {
|
|
107
|
-
/**
|
|
108
|
-
* You can provide a client instance returned by `createClient()` instead of
|
|
109
|
-
* individual options. This might be also useful if you want to implement a
|
|
110
|
-
* custom client.
|
|
111
|
-
*/
|
|
112
|
-
client?: Client;
|
|
113
|
-
};
|
|
114
|
-
export type Options<T = unknown, ThrowOnError extends boolean = boolean> = T extends {
|
|
115
|
-
body?: any;
|
|
116
|
-
} ? T extends {
|
|
117
|
-
headers?: any;
|
|
118
|
-
} ? OmitKeys<OptionsBase<ThrowOnError>, 'body' | 'headers'> & T : OmitKeys<OptionsBase<ThrowOnError>, 'body'> & T & Pick<OptionsBase<ThrowOnError>, 'headers'> : T extends {
|
|
119
|
-
headers?: any;
|
|
120
|
-
} ? OmitKeys<OptionsBase<ThrowOnError>, 'headers'> & T & Pick<OptionsBase<ThrowOnError>, 'body'> : OptionsBase<ThrowOnError> & T;
|
|
121
|
-
export {};
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import type { Config } from './types';
|
|
2
|
-
type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited';
|
|
3
|
-
type ObjectStyle = 'form' | 'deepObject';
|
|
4
|
-
export type QuerySerializer = (query: Record<string, unknown>) => string;
|
|
5
|
-
export type BodySerializer = (body: any) => any;
|
|
6
|
-
interface SerializerOptions<T> {
|
|
7
|
-
/**
|
|
8
|
-
* @default true
|
|
9
|
-
*/
|
|
10
|
-
explode: boolean;
|
|
11
|
-
style: T;
|
|
12
|
-
}
|
|
13
|
-
export interface QuerySerializerOptions {
|
|
14
|
-
allowReserved?: boolean;
|
|
15
|
-
array?: SerializerOptions<ArrayStyle>;
|
|
16
|
-
object?: SerializerOptions<ObjectStyle>;
|
|
17
|
-
}
|
|
18
|
-
export declare const createQuerySerializer: <T = unknown>({ allowReserved, array, object, }?: QuerySerializerOptions) => (queryParams: T) => string;
|
|
19
|
-
/**
|
|
20
|
-
* Infers parseAs value from provided Content-Type header.
|
|
21
|
-
*/
|
|
22
|
-
export declare const getParseAs: (contentType: string | null) => Exclude<Config["parseAs"], "auto" | "stream">;
|
|
23
|
-
export declare const getUrl: ({ baseUrl, path, query, querySerializer, url: _url, }: {
|
|
24
|
-
baseUrl: string;
|
|
25
|
-
path?: Record<string, unknown>;
|
|
26
|
-
query?: Record<string, unknown>;
|
|
27
|
-
querySerializer: QuerySerializer;
|
|
28
|
-
url: string;
|
|
29
|
-
}) => string;
|
|
30
|
-
export declare const mergeConfigs: (a: Config, b: Config) => Config;
|
|
31
|
-
export declare const mergeHeaders: (...headers: Array<Required<Config>["headers"] | undefined>) => Headers;
|
|
32
|
-
type ErrInterceptor<Err, Res, Req, Options> = (error: Err, response: Res, request: Req, options: Options) => Err | Promise<Err>;
|
|
33
|
-
type ReqInterceptor<Req, Options> = (request: Req, options: Options) => Req | Promise<Req>;
|
|
34
|
-
type ResInterceptor<Res, Req, Options> = (response: Res, request: Req, options: Options) => Res | Promise<Res>;
|
|
35
|
-
declare class Interceptors<Interceptor> {
|
|
36
|
-
_fns: Interceptor[];
|
|
37
|
-
constructor();
|
|
38
|
-
clear(): void;
|
|
39
|
-
exists(fn: Interceptor): boolean;
|
|
40
|
-
eject(fn: Interceptor): void;
|
|
41
|
-
use(fn: Interceptor): void;
|
|
42
|
-
}
|
|
43
|
-
export interface Middleware<Req, Res, Err, Options> {
|
|
44
|
-
error: Pick<Interceptors<ErrInterceptor<Err, Res, Req, Options>>, 'eject' | 'use'>;
|
|
45
|
-
request: Pick<Interceptors<ReqInterceptor<Req, Options>>, 'eject' | 'use'>;
|
|
46
|
-
response: Pick<Interceptors<ResInterceptor<Res, Req, Options>>, 'eject' | 'use'>;
|
|
47
|
-
}
|
|
48
|
-
export declare const createInterceptors: <Req, Res, Err, Options>() => {
|
|
49
|
-
error: Interceptors<ErrInterceptor<Err, Res, Req, Options>>;
|
|
50
|
-
request: Interceptors<ReqInterceptor<Req, Options>>;
|
|
51
|
-
response: Interceptors<ResInterceptor<Res, Req, Options>>;
|
|
52
|
-
};
|
|
53
|
-
export declare const formDataBodySerializer: {
|
|
54
|
-
bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(body: T) => FormData;
|
|
55
|
-
};
|
|
56
|
-
export declare const jsonBodySerializer: {
|
|
57
|
-
bodySerializer: <T>(body: T) => string;
|
|
58
|
-
};
|
|
59
|
-
export declare const urlSearchParamsBodySerializer: {
|
|
60
|
-
bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(body: T) => URLSearchParams;
|
|
61
|
-
};
|
|
62
|
-
export declare const createConfig: (override?: Config) => Config;
|
|
63
|
-
export {};
|
|
@@ -1,398 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createConfig = exports.urlSearchParamsBodySerializer = exports.jsonBodySerializer = exports.formDataBodySerializer = exports.createInterceptors = exports.mergeHeaders = exports.mergeConfigs = exports.getUrl = exports.getParseAs = exports.createQuerySerializer = void 0;
|
|
4
|
-
const PATH_PARAM_RE = /\{[^{}]+\}/g;
|
|
5
|
-
const serializePrimitiveParam = ({ allowReserved, name, value, }) => {
|
|
6
|
-
if (value === undefined || value === null) {
|
|
7
|
-
return '';
|
|
8
|
-
}
|
|
9
|
-
if (typeof value === 'object') {
|
|
10
|
-
throw new Error('Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.');
|
|
11
|
-
}
|
|
12
|
-
return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
|
|
13
|
-
};
|
|
14
|
-
const separatorArrayExplode = (style) => {
|
|
15
|
-
switch (style) {
|
|
16
|
-
case 'label':
|
|
17
|
-
return '.';
|
|
18
|
-
case 'matrix':
|
|
19
|
-
return ';';
|
|
20
|
-
case 'simple':
|
|
21
|
-
return ',';
|
|
22
|
-
default:
|
|
23
|
-
return '&';
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
const separatorArrayNoExplode = (style) => {
|
|
27
|
-
switch (style) {
|
|
28
|
-
case 'form':
|
|
29
|
-
return ',';
|
|
30
|
-
case 'pipeDelimited':
|
|
31
|
-
return '|';
|
|
32
|
-
case 'spaceDelimited':
|
|
33
|
-
return '%20';
|
|
34
|
-
default:
|
|
35
|
-
return ',';
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
const separatorObjectExplode = (style) => {
|
|
39
|
-
switch (style) {
|
|
40
|
-
case 'label':
|
|
41
|
-
return '.';
|
|
42
|
-
case 'matrix':
|
|
43
|
-
return ';';
|
|
44
|
-
case 'simple':
|
|
45
|
-
return ',';
|
|
46
|
-
default:
|
|
47
|
-
return '&';
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
const serializeArrayParam = ({ allowReserved, explode, name, style, value, }) => {
|
|
51
|
-
if (!explode) {
|
|
52
|
-
const joinedValues = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
|
|
53
|
-
switch (style) {
|
|
54
|
-
case 'label':
|
|
55
|
-
return `.${joinedValues}`;
|
|
56
|
-
case 'matrix':
|
|
57
|
-
return `;${name}=${joinedValues}`;
|
|
58
|
-
case 'simple':
|
|
59
|
-
return joinedValues;
|
|
60
|
-
default:
|
|
61
|
-
return `${name}=${joinedValues}`;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
const separator = separatorArrayExplode(style);
|
|
65
|
-
const joinedValues = value
|
|
66
|
-
.map((v) => {
|
|
67
|
-
if (style === 'label' || style === 'simple') {
|
|
68
|
-
return allowReserved ? v : encodeURIComponent(v);
|
|
69
|
-
}
|
|
70
|
-
return serializePrimitiveParam({
|
|
71
|
-
allowReserved,
|
|
72
|
-
name,
|
|
73
|
-
value: v,
|
|
74
|
-
});
|
|
75
|
-
})
|
|
76
|
-
.join(separator);
|
|
77
|
-
return style === 'label' || style === 'matrix'
|
|
78
|
-
? separator + joinedValues
|
|
79
|
-
: joinedValues;
|
|
80
|
-
};
|
|
81
|
-
const serializeObjectParam = ({ allowReserved, explode, name, style, value, }) => {
|
|
82
|
-
if (value instanceof Date) {
|
|
83
|
-
return `${name}=${value.toISOString()}`;
|
|
84
|
-
}
|
|
85
|
-
if (style !== 'deepObject' && !explode) {
|
|
86
|
-
let values = [];
|
|
87
|
-
Object.entries(value).forEach(([key, v]) => {
|
|
88
|
-
values = [
|
|
89
|
-
...values,
|
|
90
|
-
key,
|
|
91
|
-
allowReserved ? v : encodeURIComponent(v),
|
|
92
|
-
];
|
|
93
|
-
});
|
|
94
|
-
const joinedValues = values.join(',');
|
|
95
|
-
switch (style) {
|
|
96
|
-
case 'form':
|
|
97
|
-
return `${name}=${joinedValues}`;
|
|
98
|
-
case 'label':
|
|
99
|
-
return `.${joinedValues}`;
|
|
100
|
-
case 'matrix':
|
|
101
|
-
return `;${name}=${joinedValues}`;
|
|
102
|
-
default:
|
|
103
|
-
return joinedValues;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
const separator = separatorObjectExplode(style);
|
|
107
|
-
const joinedValues = Object.entries(value)
|
|
108
|
-
.map(([key, v]) => serializePrimitiveParam({
|
|
109
|
-
allowReserved,
|
|
110
|
-
name: style === 'deepObject' ? `${name}[${key}]` : key,
|
|
111
|
-
value: v,
|
|
112
|
-
}))
|
|
113
|
-
.join(separator);
|
|
114
|
-
return style === 'label' || style === 'matrix'
|
|
115
|
-
? separator + joinedValues
|
|
116
|
-
: joinedValues;
|
|
117
|
-
};
|
|
118
|
-
const defaultPathSerializer = ({ path, url: _url }) => {
|
|
119
|
-
let url = _url;
|
|
120
|
-
const matches = _url.match(PATH_PARAM_RE);
|
|
121
|
-
if (matches) {
|
|
122
|
-
for (const match of matches) {
|
|
123
|
-
let explode = false;
|
|
124
|
-
let name = match.substring(1, match.length - 1);
|
|
125
|
-
let style = 'simple';
|
|
126
|
-
if (name.endsWith('*')) {
|
|
127
|
-
explode = true;
|
|
128
|
-
name = name.substring(0, name.length - 1);
|
|
129
|
-
}
|
|
130
|
-
if (name.startsWith('.')) {
|
|
131
|
-
name = name.substring(1);
|
|
132
|
-
style = 'label';
|
|
133
|
-
}
|
|
134
|
-
else if (name.startsWith(';')) {
|
|
135
|
-
name = name.substring(1);
|
|
136
|
-
style = 'matrix';
|
|
137
|
-
}
|
|
138
|
-
const value = path[name];
|
|
139
|
-
if (value === undefined || value === null) {
|
|
140
|
-
continue;
|
|
141
|
-
}
|
|
142
|
-
if (Array.isArray(value)) {
|
|
143
|
-
url = url.replace(match, serializeArrayParam({ explode, name, style, value }));
|
|
144
|
-
continue;
|
|
145
|
-
}
|
|
146
|
-
if (typeof value === 'object') {
|
|
147
|
-
url = url.replace(match, serializeObjectParam({
|
|
148
|
-
explode,
|
|
149
|
-
name,
|
|
150
|
-
style,
|
|
151
|
-
value: value,
|
|
152
|
-
}));
|
|
153
|
-
continue;
|
|
154
|
-
}
|
|
155
|
-
if (style === 'matrix') {
|
|
156
|
-
url = url.replace(match, `;${serializePrimitiveParam({
|
|
157
|
-
name,
|
|
158
|
-
value: value,
|
|
159
|
-
})}`);
|
|
160
|
-
continue;
|
|
161
|
-
}
|
|
162
|
-
const replaceValue = encodeURIComponent(style === 'label' ? `.${value}` : value);
|
|
163
|
-
url = url.replace(match, replaceValue);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
return url;
|
|
167
|
-
};
|
|
168
|
-
const createQuerySerializer = ({ allowReserved, array, object, } = {}) => {
|
|
169
|
-
const querySerializer = (queryParams) => {
|
|
170
|
-
let search = [];
|
|
171
|
-
if (queryParams && typeof queryParams === 'object') {
|
|
172
|
-
for (const name in queryParams) {
|
|
173
|
-
const value = queryParams[name];
|
|
174
|
-
if (value === undefined || value === null) {
|
|
175
|
-
continue;
|
|
176
|
-
}
|
|
177
|
-
if (Array.isArray(value)) {
|
|
178
|
-
search = [
|
|
179
|
-
...search,
|
|
180
|
-
serializeArrayParam({
|
|
181
|
-
allowReserved,
|
|
182
|
-
explode: true,
|
|
183
|
-
name,
|
|
184
|
-
style: 'form',
|
|
185
|
-
value,
|
|
186
|
-
...array,
|
|
187
|
-
}),
|
|
188
|
-
];
|
|
189
|
-
continue;
|
|
190
|
-
}
|
|
191
|
-
if (typeof value === 'object') {
|
|
192
|
-
search = [
|
|
193
|
-
...search,
|
|
194
|
-
serializeObjectParam({
|
|
195
|
-
allowReserved,
|
|
196
|
-
explode: true,
|
|
197
|
-
name,
|
|
198
|
-
style: 'deepObject',
|
|
199
|
-
value: value,
|
|
200
|
-
...object,
|
|
201
|
-
}),
|
|
202
|
-
];
|
|
203
|
-
continue;
|
|
204
|
-
}
|
|
205
|
-
search = [
|
|
206
|
-
...search,
|
|
207
|
-
serializePrimitiveParam({
|
|
208
|
-
allowReserved,
|
|
209
|
-
name,
|
|
210
|
-
value: value,
|
|
211
|
-
}),
|
|
212
|
-
];
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
return search.join('&');
|
|
216
|
-
};
|
|
217
|
-
return querySerializer;
|
|
218
|
-
};
|
|
219
|
-
exports.createQuerySerializer = createQuerySerializer;
|
|
220
|
-
/**
|
|
221
|
-
* Infers parseAs value from provided Content-Type header.
|
|
222
|
-
*/
|
|
223
|
-
const getParseAs = (contentType) => {
|
|
224
|
-
if (!contentType) {
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
const cleanContent = contentType.split(';')[0].trim();
|
|
228
|
-
if (cleanContent.startsWith('application/json') ||
|
|
229
|
-
cleanContent.endsWith('+json')) {
|
|
230
|
-
return 'json';
|
|
231
|
-
}
|
|
232
|
-
if (cleanContent === 'multipart/form-data') {
|
|
233
|
-
return 'formData';
|
|
234
|
-
}
|
|
235
|
-
if (['application/', 'audio/', 'image/', 'video/'].some((type) => cleanContent.startsWith(type))) {
|
|
236
|
-
return 'blob';
|
|
237
|
-
}
|
|
238
|
-
if (cleanContent.startsWith('text/')) {
|
|
239
|
-
return 'text';
|
|
240
|
-
}
|
|
241
|
-
};
|
|
242
|
-
exports.getParseAs = getParseAs;
|
|
243
|
-
const getUrl = ({ baseUrl, path, query, querySerializer, url: _url, }) => {
|
|
244
|
-
const pathUrl = _url.startsWith('/') ? _url : `/${_url}`;
|
|
245
|
-
let url = baseUrl + pathUrl;
|
|
246
|
-
if (path) {
|
|
247
|
-
url = defaultPathSerializer({ path, url });
|
|
248
|
-
}
|
|
249
|
-
let search = query ? querySerializer(query) : '';
|
|
250
|
-
if (search.startsWith('?')) {
|
|
251
|
-
search = search.substring(1);
|
|
252
|
-
}
|
|
253
|
-
if (search) {
|
|
254
|
-
url += `?${search}`;
|
|
255
|
-
}
|
|
256
|
-
return url;
|
|
257
|
-
};
|
|
258
|
-
exports.getUrl = getUrl;
|
|
259
|
-
const mergeConfigs = (a, b) => {
|
|
260
|
-
const config = { ...a, ...b };
|
|
261
|
-
if (config.baseUrl?.endsWith('/')) {
|
|
262
|
-
config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
|
|
263
|
-
}
|
|
264
|
-
config.headers = (0, exports.mergeHeaders)(a.headers, b.headers);
|
|
265
|
-
return config;
|
|
266
|
-
};
|
|
267
|
-
exports.mergeConfigs = mergeConfigs;
|
|
268
|
-
const mergeHeaders = (...headers) => {
|
|
269
|
-
const mergedHeaders = new Headers();
|
|
270
|
-
for (const header of headers) {
|
|
271
|
-
if (!header || typeof header !== 'object') {
|
|
272
|
-
continue;
|
|
273
|
-
}
|
|
274
|
-
const iterator = header instanceof Headers ? header.entries() : Object.entries(header);
|
|
275
|
-
for (const [key, value] of iterator) {
|
|
276
|
-
if (value === null) {
|
|
277
|
-
mergedHeaders.delete(key);
|
|
278
|
-
}
|
|
279
|
-
else if (Array.isArray(value)) {
|
|
280
|
-
for (const v of value) {
|
|
281
|
-
mergedHeaders.append(key, v);
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
else if (value !== undefined) {
|
|
285
|
-
// assume object headers are meant to be JSON stringified, i.e. their
|
|
286
|
-
// content value in OpenAPI specification is 'application/json'
|
|
287
|
-
mergedHeaders.set(key, typeof value === 'object' ? JSON.stringify(value) : value);
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
return mergedHeaders;
|
|
292
|
-
};
|
|
293
|
-
exports.mergeHeaders = mergeHeaders;
|
|
294
|
-
class Interceptors {
|
|
295
|
-
_fns;
|
|
296
|
-
constructor() {
|
|
297
|
-
this._fns = [];
|
|
298
|
-
}
|
|
299
|
-
clear() {
|
|
300
|
-
this._fns = [];
|
|
301
|
-
}
|
|
302
|
-
exists(fn) {
|
|
303
|
-
return this._fns.indexOf(fn) !== -1;
|
|
304
|
-
}
|
|
305
|
-
eject(fn) {
|
|
306
|
-
const index = this._fns.indexOf(fn);
|
|
307
|
-
if (index !== -1) {
|
|
308
|
-
this._fns = [...this._fns.slice(0, index), ...this._fns.slice(index + 1)];
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
use(fn) {
|
|
312
|
-
this._fns = [...this._fns, fn];
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
// do not add `Middleware` as return type so we can use _fns internally
|
|
316
|
-
const createInterceptors = () => ({
|
|
317
|
-
error: new Interceptors(),
|
|
318
|
-
request: new Interceptors(),
|
|
319
|
-
response: new Interceptors(),
|
|
320
|
-
});
|
|
321
|
-
exports.createInterceptors = createInterceptors;
|
|
322
|
-
const serializeFormDataPair = (data, key, value) => {
|
|
323
|
-
if (typeof value === 'string' || value instanceof Blob) {
|
|
324
|
-
data.append(key, value);
|
|
325
|
-
}
|
|
326
|
-
else {
|
|
327
|
-
data.append(key, JSON.stringify(value));
|
|
328
|
-
}
|
|
329
|
-
};
|
|
330
|
-
exports.formDataBodySerializer = {
|
|
331
|
-
bodySerializer: (body) => {
|
|
332
|
-
const data = new FormData();
|
|
333
|
-
Object.entries(body).forEach(([key, value]) => {
|
|
334
|
-
if (value === undefined || value === null) {
|
|
335
|
-
return;
|
|
336
|
-
}
|
|
337
|
-
if (Array.isArray(value)) {
|
|
338
|
-
value.forEach((v) => serializeFormDataPair(data, key, v));
|
|
339
|
-
}
|
|
340
|
-
else {
|
|
341
|
-
serializeFormDataPair(data, key, value);
|
|
342
|
-
}
|
|
343
|
-
});
|
|
344
|
-
return data;
|
|
345
|
-
},
|
|
346
|
-
};
|
|
347
|
-
exports.jsonBodySerializer = {
|
|
348
|
-
bodySerializer: (body) => JSON.stringify(body),
|
|
349
|
-
};
|
|
350
|
-
const serializeUrlSearchParamsPair = (data, key, value) => {
|
|
351
|
-
if (typeof value === 'string') {
|
|
352
|
-
data.append(key, value);
|
|
353
|
-
}
|
|
354
|
-
else {
|
|
355
|
-
data.append(key, JSON.stringify(value));
|
|
356
|
-
}
|
|
357
|
-
};
|
|
358
|
-
exports.urlSearchParamsBodySerializer = {
|
|
359
|
-
bodySerializer: (body) => {
|
|
360
|
-
const data = new URLSearchParams();
|
|
361
|
-
Object.entries(body).forEach(([key, value]) => {
|
|
362
|
-
if (value === undefined || value === null) {
|
|
363
|
-
return;
|
|
364
|
-
}
|
|
365
|
-
if (Array.isArray(value)) {
|
|
366
|
-
value.forEach((v) => serializeUrlSearchParamsPair(data, key, v));
|
|
367
|
-
}
|
|
368
|
-
else {
|
|
369
|
-
serializeUrlSearchParamsPair(data, key, value);
|
|
370
|
-
}
|
|
371
|
-
});
|
|
372
|
-
return data;
|
|
373
|
-
},
|
|
374
|
-
};
|
|
375
|
-
const defaultQuerySerializer = (0, exports.createQuerySerializer)({
|
|
376
|
-
allowReserved: false,
|
|
377
|
-
array: {
|
|
378
|
-
explode: true,
|
|
379
|
-
style: 'form',
|
|
380
|
-
},
|
|
381
|
-
object: {
|
|
382
|
-
explode: true,
|
|
383
|
-
style: 'deepObject',
|
|
384
|
-
},
|
|
385
|
-
});
|
|
386
|
-
const defaultHeaders = {
|
|
387
|
-
'Content-Type': 'application/json',
|
|
388
|
-
};
|
|
389
|
-
const createConfig = (override = {}) => ({
|
|
390
|
-
...exports.jsonBodySerializer,
|
|
391
|
-
baseUrl: '',
|
|
392
|
-
fetch: globalThis.fetch,
|
|
393
|
-
headers: defaultHeaders,
|
|
394
|
-
parseAs: 'auto',
|
|
395
|
-
querySerializer: defaultQuerySerializer,
|
|
396
|
-
...override,
|
|
397
|
-
});
|
|
398
|
-
exports.createConfig = createConfig;
|