celitech-sdk 1.1.71 → 1.1.72
Sign up to get free protection for your applications and to get access to all the features.
- package/.manifest.json +12 -12
- package/README.md +2 -2
- package/documentation/services/PurchasesService.md +6 -6
- package/examples/package.json +1 -1
- package/package.json +1 -1
- package/src/http/handlers/hook-handler.ts +6 -4
- package/src/http/handlers/response-validation-handler.ts +1 -1
- package/src/http/handlers/retry-handler.ts +8 -5
- package/src/http/hooks/hook.ts +3 -2
- package/src/http/serializer.ts +7 -4
- package/src/http/transport/request-builder.ts +145 -0
- package/src/http/transport/request.ts +45 -36
- package/src/services/destinations/destinations.ts +14 -11
- package/src/services/destinations/models/destinations.ts +3 -3
- package/src/services/destinations/models/list-destinations-ok-response.ts +3 -3
- package/src/services/e-sim/e-sim.ts +57 -45
- package/src/services/e-sim/models/device.ts +3 -3
- package/src/services/e-sim/models/get-esim-device-ok-response.ts +3 -3
- package/src/services/e-sim/models/get-esim-history-ok-response-esim.ts +3 -3
- package/src/services/e-sim/models/get-esim-history-ok-response.ts +3 -3
- package/src/services/e-sim/models/get-esim-mac-ok-response-esim.ts +3 -3
- package/src/services/e-sim/models/get-esim-mac-ok-response.ts +3 -3
- package/src/services/e-sim/models/get-esim-ok-response-esim.ts +3 -3
- package/src/services/e-sim/models/get-esim-ok-response.ts +3 -3
- package/src/services/e-sim/models/history.ts +3 -3
- package/src/services/packages/models/list-packages-ok-response.ts +3 -3
- package/src/services/packages/models/packages.ts +3 -3
- package/src/services/packages/packages.ts +22 -19
- package/src/services/purchases/models/create-purchase-ok-response-profile.ts +3 -3
- package/src/services/purchases/models/create-purchase-ok-response-purchase.ts +3 -3
- package/src/services/purchases/models/create-purchase-ok-response.ts +3 -3
- package/src/services/purchases/models/create-purchase-request.ts +3 -3
- package/src/services/purchases/models/edit-purchase-ok-response.ts +3 -3
- package/src/services/purchases/models/edit-purchase-request.ts +3 -3
- package/src/services/purchases/models/get-purchase-consumption-ok-response.ts +3 -3
- package/src/services/purchases/models/list-purchases-ok-response.ts +3 -3
- package/src/services/purchases/models/package_.ts +3 -3
- package/src/services/purchases/models/purchases-esim.ts +3 -3
- package/src/services/purchases/models/purchases.ts +3 -3
- package/src/services/purchases/models/top-up-esim-ok-response-profile.ts +3 -3
- package/src/services/purchases/models/top-up-esim-ok-response-purchase.ts +3 -3
- package/src/services/purchases/models/top-up-esim-ok-response.ts +3 -3
- package/src/services/purchases/models/top-up-esim-request.ts +3 -3
- package/src/services/purchases/purchases.ts +81 -66
- package/.github/PROTECTED_BRANCHES.txt +0 -1
package/.manifest.json
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
{
|
2
|
-
"liblabVersion": "2.1.
|
3
|
-
"date": "2024-07-
|
2
|
+
"liblabVersion": "2.1.23",
|
3
|
+
"date": "2024-07-24T16:11:13.332Z",
|
4
4
|
"config": {
|
5
|
-
"apiId":
|
5
|
+
"apiId": 936,
|
6
6
|
"sdkName": "Celitech",
|
7
|
-
"sdkVersion": "1.1.
|
7
|
+
"sdkVersion": "1.1.72",
|
8
8
|
"liblabVersion": "2",
|
9
9
|
"deliveryMethods": ["zip"],
|
10
10
|
"languages": ["typescript"],
|
11
|
-
"apiVersion": "1.1.
|
11
|
+
"apiVersion": "1.1.72",
|
12
12
|
"specFilePath": "swagger.yaml",
|
13
13
|
"languageOptions": {
|
14
14
|
"python": {
|
@@ -26,7 +26,7 @@
|
|
26
26
|
"pypiPackageName": "celitech-sdk",
|
27
27
|
"githubRepoName": "CelitechSDKPython",
|
28
28
|
"liblabVersion": "2",
|
29
|
-
"sdkVersion": "1.1.
|
29
|
+
"sdkVersion": "1.1.72"
|
30
30
|
},
|
31
31
|
"php": {
|
32
32
|
"packageName": "celitech-sdk/sdk",
|
@@ -41,7 +41,8 @@
|
|
41
41
|
}
|
42
42
|
],
|
43
43
|
"githubRepoName": "CelitechSDKPHP",
|
44
|
-
"
|
44
|
+
"liblabVersion": "2",
|
45
|
+
"sdkVersion": "1.1.72"
|
45
46
|
},
|
46
47
|
"typescript": {
|
47
48
|
"bundle": false,
|
@@ -59,9 +60,8 @@
|
|
59
60
|
}
|
60
61
|
],
|
61
62
|
"githubRepoName": "CelitechSDKTypeScript",
|
62
|
-
"ignoreFiles": [],
|
63
63
|
"liblabVersion": "2",
|
64
|
-
"sdkVersion": "1.1.
|
64
|
+
"sdkVersion": "1.1.72"
|
65
65
|
}
|
66
66
|
},
|
67
67
|
"publishing": {
|
@@ -101,10 +101,10 @@
|
|
101
101
|
},
|
102
102
|
"multiTenant": true,
|
103
103
|
"hooksLocation": {
|
104
|
-
"bucketKey": "
|
104
|
+
"bucketKey": "6361/hooks.zip",
|
105
105
|
"bucketName": "prod-liblab-api-stack-hooks"
|
106
106
|
},
|
107
|
-
"specUrl": "https://prod-liblab-api-stack-specs.s3.us-east-1.amazonaws.com/
|
107
|
+
"specUrl": "https://prod-liblab-api-stack-specs.s3.us-east-1.amazonaws.com/936/open-api-spec.yaml?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIA5P3QKKDKGVNIJ2H7%2F20240724%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20240724T161111Z&X-Amz-Expires=43200&X-Amz-Signature=0236628a6da6e1de7697560d1f6376f1176442f3899d75d7185d05b689f6b608&X-Amz-SignedHeaders=host&x-id=GetObject",
|
108
108
|
"includeWatermark": false,
|
109
109
|
"language": "typescript",
|
110
110
|
"deliveryMethod": "zip",
|
@@ -127,7 +127,6 @@
|
|
127
127
|
}
|
128
128
|
],
|
129
129
|
"githubRepoName": "CelitechSDKTypeScript",
|
130
|
-
"ignoreFiles": [],
|
131
130
|
"typescriptVersion": "5.3.3",
|
132
131
|
"zodVersion": "3.22.0",
|
133
132
|
"compilerOptions": {
|
@@ -227,6 +226,7 @@
|
|
227
226
|
"src/http/handlers/request-validation-handler.ts",
|
228
227
|
".devcontainer/devcontainer.json",
|
229
228
|
"src/http/transport/request.ts",
|
229
|
+
"src/http/transport/request-builder.ts",
|
230
230
|
"documentation/models/ListDestinationsOkResponse.md",
|
231
231
|
"documentation/models/ListPackagesOkResponse.md",
|
232
232
|
"documentation/models/GetEsimOkResponse.md",
|
package/README.md
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
# Celitech TypeScript SDK 1.1.
|
1
|
+
# Celitech TypeScript SDK 1.1.72
|
2
2
|
|
3
3
|
Welcome to the Celitech SDK documentation. This guide will help you get started with integrating and using the Celitech SDK in your project.
|
4
4
|
|
5
5
|
## Versions
|
6
6
|
|
7
7
|
- API version: `1.1.0`
|
8
|
-
- SDK version: `1.1.
|
8
|
+
- SDK version: `1.1.72`
|
9
9
|
|
10
10
|
## About the API
|
11
11
|
|
@@ -87,8 +87,8 @@ import { Celitech, CreatePurchaseRequest } from 'celitech-sdk';
|
|
87
87
|
email: 'example@domain.com',
|
88
88
|
referenceId: 'abc111222333444',
|
89
89
|
networkBrand: 'CELITECH',
|
90
|
-
startTime:
|
91
|
-
endTime:
|
90
|
+
startTime: 8.94,
|
91
|
+
endTime: 5.28,
|
92
92
|
};
|
93
93
|
|
94
94
|
const { data } = await celitech.purchases.createPurchase(input);
|
@@ -132,8 +132,8 @@ import { Celitech, TopUpEsimRequest } from 'celitech-sdk';
|
|
132
132
|
endDate: '2023-11-20',
|
133
133
|
email: 'example@domain.com',
|
134
134
|
referenceId: 'abc111222333444',
|
135
|
-
startTime:
|
136
|
-
endTime:
|
135
|
+
startTime: 5.74,
|
136
|
+
endTime: 9.23,
|
137
137
|
};
|
138
138
|
|
139
139
|
const { data } = await celitech.purchases.topUpEsim(input);
|
@@ -174,8 +174,8 @@ import { Celitech, EditPurchaseRequest } from 'celitech-sdk';
|
|
174
174
|
purchaseId: 'ae471106-c8b4-42cf-b83a-b061291f2922',
|
175
175
|
startDate: '2023-11-01',
|
176
176
|
endDate: '2023-11-20',
|
177
|
-
startTime:
|
178
|
-
endTime:
|
177
|
+
startTime: 1.27,
|
178
|
+
endTime: 5.18,
|
179
179
|
};
|
180
180
|
|
181
181
|
const { data } = await celitech.purchases.editPurchase(input);
|
package/examples/package.json
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "celitech-sdk",
|
3
|
-
"version": "1.1.
|
3
|
+
"version": "1.1.72",
|
4
4
|
"description": "Welcome to the CELITECH API documentation! Useful links: [Homepage](https://www.celitech.com) | [Support email](mailto:support@celitech.com) | [Blog](https://www.celitech.com/blog/) ",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"types": "dist/index.d.ts",
|
@@ -20,18 +20,20 @@ export class HookHandler implements RequestHandler {
|
|
20
20
|
const response = await this.next.handle(nextRequest);
|
21
21
|
|
22
22
|
if (response.metadata.status < 400) {
|
23
|
-
return await this.hook.afterResponse(request, response, hookParams);
|
23
|
+
return await this.hook.afterResponse(request.toHookRequest(), response, hookParams);
|
24
24
|
}
|
25
25
|
|
26
|
-
const error = await this.hook.onError(request, response, hookParams);
|
26
|
+
const error = await this.hook.onError(request.toHookRequest(), response, hookParams);
|
27
27
|
|
28
28
|
throw new HttpError(error.metadata, error.error);
|
29
29
|
}
|
30
30
|
|
31
31
|
private async beforeRequest<T>(request: Request<T>, hookParams: Map<string, string>): Promise<Request<T>> {
|
32
|
-
const hookRequest =
|
32
|
+
const hookRequest = request.toHookRequest();
|
33
33
|
|
34
|
-
|
34
|
+
const newRequest = await this.hook.beforeRequest(hookRequest, hookParams);
|
35
|
+
|
36
|
+
request.updateFromHookRequest(newRequest);
|
35
37
|
|
36
38
|
return request;
|
37
39
|
}
|
@@ -57,7 +57,7 @@ export class ResponseValidationHandler implements RequestHandler {
|
|
57
57
|
}
|
58
58
|
|
59
59
|
private validate<T>(request: Request<T>, data: any): T {
|
60
|
-
if (request.
|
60
|
+
if (request.validation?.responseValidation) {
|
61
61
|
return request.responseSchema.parse(data);
|
62
62
|
}
|
63
63
|
return data;
|
@@ -10,15 +10,14 @@ export class RetryHandler implements RequestHandler {
|
|
10
10
|
throw new Error('No next handler set in retry handler.');
|
11
11
|
}
|
12
12
|
|
13
|
-
|
14
|
-
for (let attempt = 1; attempt <= retry.attempts; attempt++) {
|
13
|
+
for (let attempt = 1; attempt <= request.retry.attempts; attempt++) {
|
15
14
|
try {
|
16
15
|
return await this.next.handle(request);
|
17
16
|
} catch (error: any) {
|
18
|
-
if (!this.shouldRetry(error) || attempt === retry.attempts) {
|
17
|
+
if (!this.shouldRetry(error) || attempt === request.retry.attempts) {
|
19
18
|
throw error;
|
20
19
|
}
|
21
|
-
await this.delay(retry.delayMs);
|
20
|
+
await this.delay(request.retry.delayMs);
|
22
21
|
}
|
23
22
|
}
|
24
23
|
|
@@ -29,7 +28,11 @@ export class RetryHandler implements RequestHandler {
|
|
29
28
|
return error instanceof HttpError && (error.metadata.status >= 500 || error.metadata.status === 408);
|
30
29
|
}
|
31
30
|
|
32
|
-
private delay(delayMs: number): Promise<void> {
|
31
|
+
private delay(delayMs: number | undefined): Promise<void> {
|
32
|
+
if (!delayMs) {
|
33
|
+
return Promise.resolve();
|
34
|
+
}
|
35
|
+
|
33
36
|
return new Promise((resolve, reject) => {
|
34
37
|
setTimeout(() => resolve(), delayMs);
|
35
38
|
});
|
package/src/http/hooks/hook.ts
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
2
2
|
|
3
3
|
export interface HttpRequest {
|
4
|
+
baseUrl: string;
|
4
5
|
method: HttpMethod;
|
5
6
|
path: string;
|
6
|
-
headers
|
7
|
+
headers: Map<string, unknown>;
|
7
8
|
body?: BodyInit;
|
8
9
|
abortSignal?: AbortSignal;
|
9
|
-
queryParams
|
10
|
+
queryParams: Map<string, unknown>;
|
10
11
|
}
|
11
12
|
|
12
13
|
interface HttpMetadata {
|
package/src/http/serializer.ts
CHANGED
@@ -25,7 +25,7 @@ export function serializeQuery(
|
|
25
25
|
_style = SerializationStyle.FORM,
|
26
26
|
explode = true,
|
27
27
|
): string {
|
28
|
-
if (!queryParams || !Object.entries(queryParams)) {
|
28
|
+
if (!queryParams || !Object.entries(queryParams).length) {
|
29
29
|
return '';
|
30
30
|
}
|
31
31
|
|
@@ -58,9 +58,12 @@ export function serializeQuery(
|
|
58
58
|
return `?${query}`;
|
59
59
|
}
|
60
60
|
|
61
|
-
export function serializeHeader(
|
62
|
-
|
63
|
-
|
61
|
+
export function serializeHeader(
|
62
|
+
headers?: Record<string, unknown>,
|
63
|
+
explode = false,
|
64
|
+
): Record<string, string> | undefined {
|
65
|
+
if (!headers || !Object.entries(headers).length) {
|
66
|
+
return undefined;
|
64
67
|
}
|
65
68
|
|
66
69
|
return Object.entries(headers).reduce((acc, [key, value]) => {
|
@@ -0,0 +1,145 @@
|
|
1
|
+
import z, { ZodType } from 'zod';
|
2
|
+
import { Request, CreateRequestParameters } from './request';
|
3
|
+
import { ContentType, HttpMethod, SdkConfig, RequestConfig, RetryOptions, ValidationOptions } from '../types';
|
4
|
+
import { Environment } from '../environment';
|
5
|
+
|
6
|
+
export class RequestBuilder<T> {
|
7
|
+
private params: CreateRequestParameters<T>;
|
8
|
+
|
9
|
+
constructor() {
|
10
|
+
this.params = {
|
11
|
+
baseUrl: Environment.DEFAULT,
|
12
|
+
method: 'GET',
|
13
|
+
path: '',
|
14
|
+
config: {},
|
15
|
+
responseSchema: z.any(),
|
16
|
+
requestSchema: z.any(),
|
17
|
+
requestContentType: ContentType.Json,
|
18
|
+
responseContentType: ContentType.Json,
|
19
|
+
retry: {
|
20
|
+
attempts: 3,
|
21
|
+
delayMs: 150,
|
22
|
+
},
|
23
|
+
validation: {
|
24
|
+
responseValidation: true,
|
25
|
+
},
|
26
|
+
pathParams: new Map(),
|
27
|
+
queryParams: new Map(),
|
28
|
+
headers: new Map(),
|
29
|
+
};
|
30
|
+
}
|
31
|
+
|
32
|
+
setRetryAttempts(sdkConfig?: SdkConfig, requestConfig?: RequestConfig): RequestBuilder<T> {
|
33
|
+
if (requestConfig?.retry?.attempts !== undefined) {
|
34
|
+
this.params.retry.attempts = requestConfig.retry.attempts;
|
35
|
+
} else if (sdkConfig?.retry?.attempts !== undefined) {
|
36
|
+
this.params.retry.attempts = sdkConfig.retry.attempts;
|
37
|
+
}
|
38
|
+
|
39
|
+
return this;
|
40
|
+
}
|
41
|
+
|
42
|
+
setRetryDelayMs(sdkConfig?: SdkConfig, requestConfig?: RequestConfig): RequestBuilder<T> {
|
43
|
+
if (requestConfig?.retry?.delayMs !== undefined) {
|
44
|
+
this.params.retry.delayMs = requestConfig.retry.delayMs;
|
45
|
+
} else if (sdkConfig?.retry?.delayMs !== undefined) {
|
46
|
+
this.params.retry.delayMs = sdkConfig.retry.delayMs;
|
47
|
+
}
|
48
|
+
|
49
|
+
return this;
|
50
|
+
}
|
51
|
+
|
52
|
+
setResponseValidation(sdkConfig: SdkConfig, requestConfig?: RequestConfig): RequestBuilder<T> {
|
53
|
+
if (requestConfig?.validation?.responseValidation !== undefined) {
|
54
|
+
this.params.validation.responseValidation = requestConfig.validation.responseValidation;
|
55
|
+
} else if (sdkConfig?.validation?.responseValidation !== undefined) {
|
56
|
+
this.params.validation.responseValidation = sdkConfig.validation.responseValidation;
|
57
|
+
}
|
58
|
+
|
59
|
+
return this;
|
60
|
+
}
|
61
|
+
|
62
|
+
setBaseUrl(sdkConfig: SdkConfig): RequestBuilder<T> {
|
63
|
+
if (sdkConfig?.baseUrl !== undefined) {
|
64
|
+
this.params.baseUrl = sdkConfig.baseUrl;
|
65
|
+
}
|
66
|
+
|
67
|
+
return this;
|
68
|
+
}
|
69
|
+
|
70
|
+
setMethod(method: HttpMethod): RequestBuilder<T> {
|
71
|
+
this.params.method = method;
|
72
|
+
return this;
|
73
|
+
}
|
74
|
+
|
75
|
+
setPath(path: string): RequestBuilder<T> {
|
76
|
+
this.params.path = path;
|
77
|
+
return this;
|
78
|
+
}
|
79
|
+
|
80
|
+
setConfig(config: SdkConfig): RequestBuilder<T> {
|
81
|
+
this.params.config = config;
|
82
|
+
return this;
|
83
|
+
}
|
84
|
+
|
85
|
+
setRequestContentType(contentType: ContentType): RequestBuilder<T> {
|
86
|
+
this.params.requestContentType = contentType;
|
87
|
+
return this;
|
88
|
+
}
|
89
|
+
|
90
|
+
setResponseContentType(contentType: ContentType): RequestBuilder<T> {
|
91
|
+
this.params.responseContentType = contentType;
|
92
|
+
return this;
|
93
|
+
}
|
94
|
+
|
95
|
+
setRequestSchema(requestSchema: ZodType): RequestBuilder<T> {
|
96
|
+
this.params.requestSchema = requestSchema;
|
97
|
+
return this;
|
98
|
+
}
|
99
|
+
|
100
|
+
setResponseSchema(responseSchema: ZodType): RequestBuilder<T> {
|
101
|
+
this.params.responseSchema = responseSchema;
|
102
|
+
return this;
|
103
|
+
}
|
104
|
+
|
105
|
+
addBody(body?: any): RequestBuilder<T> {
|
106
|
+
if (body !== undefined) {
|
107
|
+
this.params.body = body;
|
108
|
+
}
|
109
|
+
return this;
|
110
|
+
}
|
111
|
+
|
112
|
+
addPathParam(key: string, value: unknown): RequestBuilder<T> {
|
113
|
+
if (value === undefined) {
|
114
|
+
return this;
|
115
|
+
}
|
116
|
+
|
117
|
+
this.params.pathParams.set(key, value);
|
118
|
+
|
119
|
+
return this;
|
120
|
+
}
|
121
|
+
|
122
|
+
addQueryParam(key: string, value: unknown): RequestBuilder<T> {
|
123
|
+
if (value === undefined) {
|
124
|
+
return this;
|
125
|
+
}
|
126
|
+
|
127
|
+
this.params.queryParams.set(key, value);
|
128
|
+
|
129
|
+
return this;
|
130
|
+
}
|
131
|
+
|
132
|
+
addHeaderParam(key: string, value: unknown): RequestBuilder<T> {
|
133
|
+
if (value === undefined) {
|
134
|
+
return this;
|
135
|
+
}
|
136
|
+
|
137
|
+
this.params.headers.set(key, value);
|
138
|
+
|
139
|
+
return this;
|
140
|
+
}
|
141
|
+
|
142
|
+
public build(): Request<T> {
|
143
|
+
return new Request<T>(this.params);
|
144
|
+
}
|
145
|
+
}
|
@@ -1,21 +1,28 @@
|
|
1
1
|
import { ZodType } from 'zod';
|
2
|
-
import { ContentType, HttpMethod, SdkConfig, RetryOptions, RequestConfig } from '../types';
|
2
|
+
import { ContentType, HttpMethod, SdkConfig, RetryOptions, RequestConfig, ValidationOptions } from '../types';
|
3
3
|
import { serializeHeader, serializePath, serializeQuery } from '../serializer';
|
4
4
|
import { HttpRequest } from '../hooks/hook';
|
5
5
|
|
6
|
-
interface CreateRequestParameters<T> {
|
6
|
+
export interface CreateRequestParameters<T> {
|
7
|
+
baseUrl: string;
|
7
8
|
method: HttpMethod;
|
8
9
|
body?: any;
|
10
|
+
headers: Map<string, unknown>;
|
11
|
+
queryParams: Map<string, unknown>;
|
12
|
+
pathParams: Map<string, unknown>;
|
9
13
|
path: string;
|
10
14
|
config: SdkConfig;
|
11
15
|
responseSchema: ZodType<T, any, any>;
|
12
16
|
requestSchema: ZodType;
|
13
17
|
requestContentType: ContentType;
|
14
18
|
responseContentType: ContentType;
|
15
|
-
|
19
|
+
validation: ValidationOptions;
|
20
|
+
retry: RetryOptions;
|
16
21
|
}
|
17
22
|
|
18
23
|
export class Request<T> {
|
24
|
+
public baseUrl: string = '';
|
25
|
+
|
19
26
|
public headers: Map<string, unknown> = new Map();
|
20
27
|
|
21
28
|
public queryParams: Map<string, unknown> = new Map();
|
@@ -40,23 +47,33 @@ export class Request<T> {
|
|
40
47
|
|
41
48
|
private readonly pathPattern: string;
|
42
49
|
|
50
|
+
public validation: ValidationOptions = {} as any;
|
51
|
+
|
52
|
+
public retry: RetryOptions = {} as any;
|
53
|
+
|
43
54
|
constructor(params: CreateRequestParameters<T>) {
|
55
|
+
this.baseUrl = params.baseUrl;
|
44
56
|
this.method = params.method;
|
45
57
|
this.pathPattern = params.path;
|
46
58
|
this.body = params.body;
|
47
59
|
this.path = this.constructPath();
|
48
60
|
this.config = params.config;
|
61
|
+
this.pathParams = params.pathParams;
|
62
|
+
this.headers = params.headers;
|
63
|
+
this.queryParams = params.queryParams;
|
49
64
|
this.responseSchema = params.responseSchema;
|
50
65
|
this.requestSchema = params.requestSchema;
|
51
66
|
this.requestContentType = params.requestContentType;
|
52
67
|
this.responseContentType = params.responseContentType;
|
53
|
-
this.
|
68
|
+
this.retry = params.retry;
|
69
|
+
this.validation = params.validation;
|
54
70
|
}
|
55
71
|
|
56
72
|
addHeaderParam(key: string, value: unknown): void {
|
57
73
|
if (value === undefined) {
|
58
74
|
return;
|
59
75
|
}
|
76
|
+
|
60
77
|
this.headers.set(key, value);
|
61
78
|
}
|
62
79
|
|
@@ -64,6 +81,7 @@ export class Request<T> {
|
|
64
81
|
if (value === undefined) {
|
65
82
|
return;
|
66
83
|
}
|
84
|
+
|
67
85
|
this.queryParams.set(key, value);
|
68
86
|
}
|
69
87
|
|
@@ -71,6 +89,7 @@ export class Request<T> {
|
|
71
89
|
if (value === undefined) {
|
72
90
|
return;
|
73
91
|
}
|
92
|
+
|
74
93
|
this.pathParams.set(key, value);
|
75
94
|
}
|
76
95
|
|
@@ -78,14 +97,8 @@ export class Request<T> {
|
|
78
97
|
if (body === undefined) {
|
79
98
|
return;
|
80
99
|
}
|
81
|
-
this.body = body;
|
82
|
-
}
|
83
100
|
|
84
|
-
|
85
|
-
return {
|
86
|
-
attempts: this.config.retry?.attempts ?? 3,
|
87
|
-
delayMs: this.config.retry?.delayMs ?? 150,
|
88
|
-
};
|
101
|
+
this.body = body;
|
89
102
|
}
|
90
103
|
|
91
104
|
getFetchArgs(): { url: string; requestInit: RequestInit } {
|
@@ -94,10 +107,14 @@ export class Request<T> {
|
|
94
107
|
requestInit: {
|
95
108
|
method: this.method,
|
96
109
|
body: this.body,
|
97
|
-
headers: this.constructHeadersInit(),
|
98
110
|
},
|
99
111
|
};
|
100
112
|
|
113
|
+
const headersInit = this.constructHeadersInit();
|
114
|
+
if (!!headersInit) {
|
115
|
+
fetchArgs.requestInit['headers'] = headersInit;
|
116
|
+
}
|
117
|
+
|
101
118
|
if (this.config.timeout !== undefined) {
|
102
119
|
fetchArgs.requestInit = {
|
103
120
|
...fetchArgs.requestInit,
|
@@ -109,39 +126,28 @@ export class Request<T> {
|
|
109
126
|
}
|
110
127
|
|
111
128
|
public updateFromHookRequest(hookRequest: HttpRequest) {
|
129
|
+
this.baseUrl = hookRequest.baseUrl;
|
112
130
|
this.method = hookRequest.method;
|
113
131
|
this.path = hookRequest.path;
|
114
132
|
this.body = hookRequest.body;
|
115
|
-
this.headers = hookRequest.headers
|
116
|
-
this.queryParams = hookRequest.queryParams
|
133
|
+
this.headers = hookRequest.headers;
|
134
|
+
this.queryParams = hookRequest.queryParams;
|
117
135
|
}
|
118
136
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
responseValidation: this.applyResponseValidation(requestConfig),
|
128
|
-
},
|
137
|
+
public toHookRequest(): HttpRequest {
|
138
|
+
return {
|
139
|
+
baseUrl: this.baseUrl,
|
140
|
+
method: this.method,
|
141
|
+
path: this.path,
|
142
|
+
headers: this.headers,
|
143
|
+
body: this.body,
|
144
|
+
queryParams: this.queryParams,
|
129
145
|
};
|
130
146
|
}
|
131
147
|
|
132
|
-
private applyResponseValidation(requestConfig: RequestConfig | undefined): boolean {
|
133
|
-
if (requestConfig?.validation?.responseValidation !== undefined) {
|
134
|
-
return requestConfig?.validation.responseValidation;
|
135
|
-
}
|
136
|
-
if (this.config?.validation?.responseValidation !== undefined) {
|
137
|
-
return this.config?.validation?.responseValidation;
|
138
|
-
}
|
139
|
-
return true;
|
140
|
-
}
|
141
|
-
|
142
148
|
private constructFullUrl(): string {
|
143
149
|
const queryString = this.constructQueryString();
|
144
|
-
return `${this.
|
150
|
+
return `${this.baseUrl}${this.constructPath()}${queryString}`;
|
145
151
|
}
|
146
152
|
|
147
153
|
private constructPath(): string {
|
@@ -149,8 +155,11 @@ export class Request<T> {
|
|
149
155
|
return serializePath(this.pathPattern, pathParamsRecord);
|
150
156
|
}
|
151
157
|
|
152
|
-
private constructHeadersInit(): HeadersInit {
|
158
|
+
private constructHeadersInit(): HeadersInit | undefined {
|
153
159
|
const headerParamsRecord: Record<string, unknown> = this.constructParamsRecord(this.headers);
|
160
|
+
if (Object.entries(headerParamsRecord).length === 0) {
|
161
|
+
return undefined;
|
162
|
+
}
|
154
163
|
return serializeHeader(headerParamsRecord);
|
155
164
|
}
|
156
165
|
|
@@ -2,7 +2,7 @@ import { z } from 'zod';
|
|
2
2
|
import { BaseService } from '../base-service';
|
3
3
|
import { ContentType, HttpResponse } from '../../http';
|
4
4
|
import { RequestConfig } from '../../http/types';
|
5
|
-
import {
|
5
|
+
import { RequestBuilder } from '../../http/transport/request-builder';
|
6
6
|
import { ListDestinationsOkResponse, listDestinationsOkResponseResponse } from './models/list-destinations-ok-response';
|
7
7
|
|
8
8
|
export class DestinationsService extends BaseService {
|
@@ -11,16 +11,19 @@ export class DestinationsService extends BaseService {
|
|
11
11
|
* @returns {Promise<HttpResponse<ListDestinationsOkResponse>>} Successful Response
|
12
12
|
*/
|
13
13
|
async listDestinations(requestConfig?: RequestConfig): Promise<HttpResponse<ListDestinationsOkResponse>> {
|
14
|
-
const request = new
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
14
|
+
const request = new RequestBuilder<ListDestinationsOkResponse>()
|
15
|
+
.setConfig(this.config)
|
16
|
+
.setBaseUrl(this.config)
|
17
|
+
.setMethod('GET')
|
18
|
+
.setPath('/destinations')
|
19
|
+
.setRequestSchema(z.any())
|
20
|
+
.setResponseSchema(listDestinationsOkResponseResponse)
|
21
|
+
.setRequestContentType(ContentType.Json)
|
22
|
+
.setResponseContentType(ContentType.Json)
|
23
|
+
.setRetryAttempts(this.config, requestConfig)
|
24
|
+
.setRetryDelayMs(this.config, requestConfig)
|
25
|
+
.setResponseValidation(this.config, requestConfig)
|
26
|
+
.build();
|
24
27
|
return this.client.call<ListDestinationsOkResponse>(request);
|
25
28
|
}
|
26
29
|
}
|
@@ -3,7 +3,7 @@ import { z } from 'zod';
|
|
3
3
|
/**
|
4
4
|
* The shape of the model inside the application code - what the users use
|
5
5
|
*/
|
6
|
-
export const destinations
|
6
|
+
export const destinations = z.lazy(() => {
|
7
7
|
return z.object({
|
8
8
|
name: z.string().optional(),
|
9
9
|
destination: z.string().optional(),
|
@@ -24,7 +24,7 @@ export type Destinations = z.infer<typeof destinations>;
|
|
24
24
|
* The shape of the model mapping from the api schema into the application shape.
|
25
25
|
* Is equal to application shape if all property names match the api schema
|
26
26
|
*/
|
27
|
-
export const destinationsResponse
|
27
|
+
export const destinationsResponse = z.lazy(() => {
|
28
28
|
return z
|
29
29
|
.object({
|
30
30
|
name: z.string().optional(),
|
@@ -42,7 +42,7 @@ export const destinationsResponse: any = z.lazy(() => {
|
|
42
42
|
* The shape of the model mapping from the application shape into the api schema.
|
43
43
|
* Is equal to application shape if all property names match the api schema
|
44
44
|
*/
|
45
|
-
export const destinationsRequest
|
45
|
+
export const destinationsRequest = z.lazy(() => {
|
46
46
|
return z
|
47
47
|
.object({
|
48
48
|
name: z.string().nullish(),
|
@@ -4,7 +4,7 @@ import { destinations, destinationsRequest, destinationsResponse } from './desti
|
|
4
4
|
/**
|
5
5
|
* The shape of the model inside the application code - what the users use
|
6
6
|
*/
|
7
|
-
export const listDestinationsOkResponse
|
7
|
+
export const listDestinationsOkResponse = z.lazy(() => {
|
8
8
|
return z.object({
|
9
9
|
destinations: z.array(destinations).optional(),
|
10
10
|
});
|
@@ -21,7 +21,7 @@ export type ListDestinationsOkResponse = z.infer<typeof listDestinationsOkRespon
|
|
21
21
|
* The shape of the model mapping from the api schema into the application shape.
|
22
22
|
* Is equal to application shape if all property names match the api schema
|
23
23
|
*/
|
24
|
-
export const listDestinationsOkResponseResponse
|
24
|
+
export const listDestinationsOkResponseResponse = z.lazy(() => {
|
25
25
|
return z
|
26
26
|
.object({
|
27
27
|
destinations: z.array(destinationsResponse).optional(),
|
@@ -35,7 +35,7 @@ export const listDestinationsOkResponseResponse: any = z.lazy(() => {
|
|
35
35
|
* The shape of the model mapping from the application shape into the api schema.
|
36
36
|
* Is equal to application shape if all property names match the api schema
|
37
37
|
*/
|
38
|
-
export const listDestinationsOkResponseRequest
|
38
|
+
export const listDestinationsOkResponseRequest = z.lazy(() => {
|
39
39
|
return z.object({ destinations: z.array(destinationsRequest).nullish() }).transform((data) => ({
|
40
40
|
destinations: data['destinations'],
|
41
41
|
}));
|