@kontent-ai/core-sdk 11.0.1 → 12.0.0-preview.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.
- package/dist/http/http.service.js +155 -135
- package/dist/http/http.service.js.map +1 -1
- package/dist/models/core.models.d.ts +3 -1
- package/dist/models/error.models.d.ts +14 -4
- package/dist/models/utility.models.d.ts +4 -0
- package/dist/public_api.d.ts +6 -6
- package/dist/public_api.js +1 -1
- package/dist/public_api.js.map +1 -1
- package/dist/sdk/sdk-models.d.ts +82 -0
- package/dist/sdk/sdk-models.js +6 -0
- package/dist/sdk/sdk-models.js.map +1 -0
- package/dist/sdk/sdk-queries.d.ts +30 -0
- package/dist/sdk/sdk-queries.js +152 -0
- package/dist/sdk/sdk-queries.js.map +1 -0
- package/dist/sdk-info.js +1 -1
- package/dist/utils/header.utils.js.map +1 -1
- package/lib/http/http.service.ts +187 -150
- package/lib/models/core.models.ts +4 -1
- package/lib/models/error.models.ts +22 -4
- package/lib/models/utility.models.ts +5 -0
- package/lib/public_api.ts +7 -7
- package/lib/sdk/sdk-models.ts +85 -0
- package/lib/sdk/sdk-queries.ts +232 -0
- package/lib/utils/header.utils.ts +5 -3
- package/package.json +23 -15
|
@@ -3,154 +3,174 @@ import { isNotUndefined } from "../utils/core.utils.js";
|
|
|
3
3
|
import { getErrorMessage } from "../utils/error.utils.js";
|
|
4
4
|
import { getSdkIdHeader } from "../utils/header.utils.js";
|
|
5
5
|
import { runWithRetryAsync, toRequiredRetryStrategyOptions } from "../utils/retry.utils.js";
|
|
6
|
-
import { tryCatch } from "../utils/try.utils.js";
|
|
6
|
+
import { tryCatch, tryCatchAsync } from "../utils/try.utils.js";
|
|
7
7
|
import { getDefaultHttpAdapter } from "./http.adapter.js";
|
|
8
8
|
export function getDefaultHttpService(config) {
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
return
|
|
9
|
+
const withUnknownErrorHandlingAsync = async ({ url, funcAsync, }) => {
|
|
10
|
+
const { success, data, error } = await tryCatchAsync(funcAsync);
|
|
11
|
+
if (success) {
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
success: false,
|
|
16
|
+
error: {
|
|
17
|
+
reason: "unknown",
|
|
18
|
+
message: "Unknown error. See the error object for more details.",
|
|
19
|
+
url: url,
|
|
20
|
+
originalError: error,
|
|
21
|
+
},
|
|
13
22
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
23
|
+
};
|
|
24
|
+
const resolveRequestAsync = async ({ options, resolveDataAsync, }) => {
|
|
25
|
+
return await withUnknownErrorHandlingAsync({
|
|
26
|
+
url: options.url,
|
|
27
|
+
funcAsync: async () => {
|
|
28
|
+
const adapter = config?.adapter ?? getDefaultHttpAdapter();
|
|
29
|
+
const getCombinedRequestHeaders = () => {
|
|
30
|
+
return getRequestHeaders([...(config?.requestHeaders ?? []), ...(options.requestHeaders ?? [])], options.body);
|
|
19
31
|
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
32
|
+
const getRequestBody = () => {
|
|
33
|
+
if (options.body === null) {
|
|
34
|
+
return {
|
|
35
|
+
success: true,
|
|
36
|
+
data: null,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
if (options.body instanceof Blob) {
|
|
40
|
+
return {
|
|
41
|
+
success: true,
|
|
42
|
+
data: options.body,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
const { success, data: parsedBody, error } = tryCatch(() => JSON.stringify(options.body));
|
|
46
|
+
if (!success) {
|
|
47
|
+
return {
|
|
48
|
+
success: false,
|
|
49
|
+
error: {
|
|
50
|
+
message: "Failed to stringify body of request.",
|
|
51
|
+
url: options.url,
|
|
52
|
+
reason: "invalidBody",
|
|
53
|
+
originalError: error,
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
success: true,
|
|
59
|
+
data: parsedBody,
|
|
60
|
+
};
|
|
25
61
|
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
62
|
+
const getUrl = () => {
|
|
63
|
+
const { success, data: parsedUrl, error } = tryCatch(() => new URL(options.url));
|
|
64
|
+
if (!success) {
|
|
65
|
+
return {
|
|
66
|
+
success: false,
|
|
67
|
+
error: {
|
|
68
|
+
message: `Failed to parse url '${options.url}'.`,
|
|
69
|
+
url: options.url,
|
|
70
|
+
reason: "invalidUrl",
|
|
71
|
+
originalError: error,
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
success: true,
|
|
77
|
+
data: parsedUrl,
|
|
78
|
+
};
|
|
37
79
|
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
const getUrl = () => {
|
|
45
|
-
const { success, data: parsedUrl, error } = tryCatch(() => new URL(options.url));
|
|
46
|
-
if (!success) {
|
|
47
|
-
return {
|
|
48
|
-
success: false,
|
|
49
|
-
error: {
|
|
50
|
-
message: `Failed to parse url '${options.url}'.`,
|
|
80
|
+
const requestHeaders = getCombinedRequestHeaders();
|
|
81
|
+
const retryStrategyOptions = toRequiredRetryStrategyOptions(config?.retryStrategy);
|
|
82
|
+
const withRetryAsync = async (funcAsync) => {
|
|
83
|
+
return await runWithRetryAsync({
|
|
51
84
|
url: options.url,
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
85
|
+
retryStrategyOptions,
|
|
86
|
+
retryAttempt: 0,
|
|
87
|
+
requestHeaders,
|
|
88
|
+
method: options.method,
|
|
89
|
+
funcAsync: async () => {
|
|
90
|
+
return await funcAsync();
|
|
91
|
+
},
|
|
92
|
+
});
|
|
55
93
|
};
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
if (!urlParsedSuccess) {
|
|
78
|
-
return {
|
|
79
|
-
success: false,
|
|
80
|
-
error: urlError,
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
const { success: requestBodyParsedSuccess, data: requestBody, error: requestBodyError } = getRequestBody();
|
|
84
|
-
if (!requestBodyParsedSuccess) {
|
|
85
|
-
return {
|
|
86
|
-
success: false,
|
|
87
|
-
error: requestBodyError,
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
const getResponseAsync = async () => {
|
|
91
|
-
return await adapter.requestAsync({
|
|
92
|
-
url: parsedUrl.toString(),
|
|
93
|
-
method: options.method,
|
|
94
|
-
requestHeaders,
|
|
95
|
-
body: requestBody,
|
|
96
|
-
});
|
|
97
|
-
};
|
|
98
|
-
const getErrorForInvalidResponseAsync = async (response) => {
|
|
99
|
-
const sharedErrorData = {
|
|
100
|
-
message: getErrorMessage({
|
|
101
|
-
url: options.url,
|
|
102
|
-
adapterResponse: response,
|
|
103
|
-
method: options.method,
|
|
104
|
-
}),
|
|
105
|
-
url: options.url,
|
|
106
|
-
};
|
|
107
|
-
if (response.status === 404) {
|
|
108
|
-
const error = {
|
|
109
|
-
...sharedErrorData,
|
|
110
|
-
reason: "notFound",
|
|
111
|
-
isValidResponse: response.isValidResponse,
|
|
112
|
-
responseHeaders: response.responseHeaders,
|
|
113
|
-
status: 404,
|
|
114
|
-
statusText: response.statusText,
|
|
115
|
-
kontentErrorResponse: await getKontentErrorDataAsync(response),
|
|
94
|
+
const { success: urlParsedSuccess, data: parsedUrl, error: urlError } = getUrl();
|
|
95
|
+
if (!urlParsedSuccess) {
|
|
96
|
+
return {
|
|
97
|
+
success: false,
|
|
98
|
+
error: urlError,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
const { success: requestBodyParsedSuccess, data: requestBody, error: requestBodyError } = getRequestBody();
|
|
102
|
+
if (!requestBodyParsedSuccess) {
|
|
103
|
+
return {
|
|
104
|
+
success: false,
|
|
105
|
+
error: requestBodyError,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
const getResponseAsync = async () => {
|
|
109
|
+
return await adapter.requestAsync({
|
|
110
|
+
url: parsedUrl.toString(),
|
|
111
|
+
method: options.method,
|
|
112
|
+
requestHeaders,
|
|
113
|
+
body: requestBody,
|
|
114
|
+
});
|
|
116
115
|
};
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
body: options.body,
|
|
142
|
-
method: options.method,
|
|
143
|
-
adapterResponse: {
|
|
116
|
+
const getErrorForInvalidResponseAsync = async (response) => {
|
|
117
|
+
const sharedErrorData = {
|
|
118
|
+
message: getErrorMessage({
|
|
119
|
+
url: options.url,
|
|
120
|
+
adapterResponse: response,
|
|
121
|
+
method: options.method,
|
|
122
|
+
}),
|
|
123
|
+
url: options.url,
|
|
124
|
+
};
|
|
125
|
+
if (response.status === 404) {
|
|
126
|
+
const error = {
|
|
127
|
+
...sharedErrorData,
|
|
128
|
+
reason: "notFound",
|
|
129
|
+
isValidResponse: response.isValidResponse,
|
|
130
|
+
responseHeaders: response.responseHeaders,
|
|
131
|
+
status: 404,
|
|
132
|
+
statusText: response.statusText,
|
|
133
|
+
kontentErrorResponse: await getKontentErrorDataAsync(response),
|
|
134
|
+
};
|
|
135
|
+
return error;
|
|
136
|
+
}
|
|
137
|
+
const error = {
|
|
138
|
+
...sharedErrorData,
|
|
139
|
+
reason: "invalidResponse",
|
|
144
140
|
isValidResponse: response.isValidResponse,
|
|
145
141
|
responseHeaders: response.responseHeaders,
|
|
146
142
|
status: response.status,
|
|
147
143
|
statusText: response.statusText,
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
144
|
+
kontentErrorResponse: await getKontentErrorDataAsync(response),
|
|
145
|
+
};
|
|
146
|
+
return error;
|
|
147
|
+
};
|
|
148
|
+
const resolveResponseAsync = async (response) => {
|
|
149
|
+
if (!response.isValidResponse) {
|
|
150
|
+
return {
|
|
151
|
+
success: false,
|
|
152
|
+
error: await getErrorForInvalidResponseAsync(response),
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
success: true,
|
|
157
|
+
response: {
|
|
158
|
+
data: await resolveDataAsync(response),
|
|
159
|
+
body: options.body,
|
|
160
|
+
method: options.method,
|
|
161
|
+
adapterResponse: {
|
|
162
|
+
isValidResponse: response.isValidResponse,
|
|
163
|
+
responseHeaders: response.responseHeaders,
|
|
164
|
+
status: response.status,
|
|
165
|
+
statusText: response.statusText,
|
|
166
|
+
},
|
|
167
|
+
requestHeaders: requestHeaders,
|
|
168
|
+
},
|
|
169
|
+
};
|
|
170
|
+
};
|
|
171
|
+
return await withRetryAsync(async () => await resolveResponseAsync(await getResponseAsync()));
|
|
172
|
+
},
|
|
173
|
+
});
|
|
154
174
|
};
|
|
155
175
|
return {
|
|
156
176
|
requestAsync: async (options) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.service.js","sourceRoot":"","sources":["../../lib/http/http.service.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAA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,EAAE,gBAAgB,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;AAC9G,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { CoreSdkError } from "./error.models.js";
|
|
2
|
+
import type { PickStringLiteral } from "./utility.models.js";
|
|
2
3
|
/**
|
|
3
4
|
* SDK info for identification of the SDK
|
|
4
5
|
*/
|
|
@@ -16,7 +17,8 @@ export type SDKInfo = {
|
|
|
16
17
|
*/
|
|
17
18
|
readonly host: LiteralUnion<"npmjs.com">;
|
|
18
19
|
};
|
|
19
|
-
export type CommonHeaderNames = "Retry-After" | "X-KC-SDKID" | "Authorization" | "Content-Type" | "Content-Length";
|
|
20
|
+
export type CommonHeaderNames = "Retry-After" | "X-KC-SDKID" | "Authorization" | "Content-Type" | "Content-Length" | "X-Continuation";
|
|
21
|
+
export type ContinuationHeaderName = PickStringLiteral<CommonHeaderNames, "X-Continuation">;
|
|
20
22
|
export type Header = {
|
|
21
23
|
readonly name: string;
|
|
22
24
|
readonly value: string;
|
|
@@ -1,16 +1,26 @@
|
|
|
1
|
+
import type { ZodError } from "zod";
|
|
1
2
|
import type { AdapterResponse, HttpServiceStatus } from "../http/http.models.js";
|
|
3
|
+
import type { SuccessfulHttpResponse } from "../sdk/sdk-models.js";
|
|
2
4
|
import type { KontentErrorResponseData, RetryStrategyOptions } from "./core.models.js";
|
|
3
|
-
|
|
5
|
+
import type { JsonValue } from "./json.models.js";
|
|
6
|
+
export type ErrorReason = "invalidResponse" | "invalidUrl" | "unknown" | "invalidBody" | "notFound" | "validationFailed" | "noResponses";
|
|
4
7
|
export type CoreSdkErrorDetails<TReason extends ErrorReason = ErrorReason> = (Details<"invalidResponse", {
|
|
5
8
|
readonly kontentErrorResponse: KontentErrorResponseData | undefined;
|
|
6
9
|
} & Pick<AdapterResponse<HttpServiceStatus>, "isValidResponse" | "responseHeaders" | "status" | "statusText">> | Details<"notFound", {
|
|
7
10
|
readonly kontentErrorResponse: KontentErrorResponseData | undefined;
|
|
8
11
|
} & Pick<AdapterResponse<404>, "isValidResponse" | "responseHeaders" | "status" | "statusText">> | Details<"invalidBody", {
|
|
9
|
-
readonly
|
|
12
|
+
readonly originalError: unknown;
|
|
10
13
|
}> | Details<"invalidUrl", {
|
|
11
|
-
readonly
|
|
14
|
+
readonly originalError: unknown;
|
|
12
15
|
}> | Details<"unknown", {
|
|
13
|
-
readonly
|
|
16
|
+
readonly originalError: unknown;
|
|
17
|
+
}> | Details<"validationFailed", {
|
|
18
|
+
readonly reason: "validationFailed";
|
|
19
|
+
readonly zodError: ZodError;
|
|
20
|
+
readonly response: SuccessfulHttpResponse<JsonValue, JsonValue>;
|
|
21
|
+
readonly url: string;
|
|
22
|
+
}> | Details<"noResponses", {
|
|
23
|
+
readonly url: string;
|
|
14
24
|
}>) & {
|
|
15
25
|
readonly reason: TReason;
|
|
16
26
|
};
|
|
@@ -14,3 +14,7 @@ export type Override<Type, NewType extends {
|
|
|
14
14
|
* Represents an empty object type.
|
|
15
15
|
*/
|
|
16
16
|
export type EmptyObject = Record<string, never>;
|
|
17
|
+
/**
|
|
18
|
+
* Picks a string literal type from a union type.
|
|
19
|
+
*/
|
|
20
|
+
export type PickStringLiteral<T extends string, U extends T> = U;
|
package/dist/public_api.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export { getDefaultHttpAdapter } from "./http/http.adapter.js";
|
|
2
|
+
export type { AdapterRequestOptions, AdapterResponse, DefaultHttpServiceConfig, DownloadFileRequestOptions, ExecuteRequestOptions, HttpAdapter, HttpResponse, HttpService, HttpServiceStatus, UploadFileRequestOptions, } from "./http/http.models.js";
|
|
2
3
|
export { getDefaultHttpService } from "./http/http.service.js";
|
|
4
|
+
export type { CommonHeaderNames, Header, HttpMethod, RetryStrategyOptions, SDKInfo, } from "./models/core.models.js";
|
|
5
|
+
export type { CoreSdkError, CoreSdkErrorDetails, ErrorReason, } from "./models/error.models.js";
|
|
6
|
+
export type { JsonArray, JsonObject, JsonValue } from "./models/json.models.js";
|
|
7
|
+
export type { EmptyObject, Override, Prettify } from "./models/utility.models.js";
|
|
8
|
+
export { isKontent404Error } from "./utils/error.utils.js";
|
|
3
9
|
export { getSdkIdHeader } from "./utils/header.utils.js";
|
|
4
10
|
export { toRequiredRetryStrategyOptions } from "./utils/retry.utils.js";
|
|
5
11
|
export { tryCatch, tryCatchAsync } from "./utils/try.utils.js";
|
|
6
|
-
export { isKontent404Error } from "./utils/error.utils.js";
|
|
7
|
-
export type { AdapterRequestOptions, AdapterResponse, DefaultHttpServiceConfig, DownloadFileRequestOptions, ExecuteRequestOptions, HttpAdapter, HttpResponse, HttpService, HttpServiceStatus, UploadFileRequestOptions, } from "./http/http.models.js";
|
|
8
|
-
export type { Header, HttpMethod, RetryStrategyOptions, SDKInfo, } from "./models/core.models.js";
|
|
9
|
-
export type { CoreSdkError, ErrorReason, CoreSdkErrorDetails, } from "./models/error.models.js";
|
|
10
|
-
export type { JsonArray, JsonObject, JsonValue } from "./models/json.models.js";
|
|
11
|
-
export type { EmptyObject, Override, Prettify } from "./models/utility.models.js";
|
package/dist/public_api.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// biome-ignore lint/performance/noBarrelFile: One barrel for the public API is fine
|
|
2
2
|
export { getDefaultHttpAdapter } from "./http/http.adapter.js";
|
|
3
3
|
export { getDefaultHttpService } from "./http/http.service.js";
|
|
4
|
+
export { isKontent404Error } from "./utils/error.utils.js";
|
|
4
5
|
export { getSdkIdHeader } from "./utils/header.utils.js";
|
|
5
6
|
export { toRequiredRetryStrategyOptions } from "./utils/retry.utils.js";
|
|
6
7
|
export { tryCatch, tryCatchAsync } from "./utils/try.utils.js";
|
|
7
|
-
export { isKontent404Error } from "./utils/error.utils.js";
|
|
8
8
|
//# sourceMappingURL=public_api.js.map
|
package/dist/public_api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"public_api.js","sourceRoot":"","sources":["../lib/public_api.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"public_api.js","sourceRoot":"","sources":["../lib/public_api.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAc/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAe/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,8BAA8B,EAAE,MAAM,wBAAwB,CAAC;AACxE,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared query models/types intended to be reused across SDKs (e.g. Sync, Delivery, Management)
|
|
3
|
+
* to keep common code and behavior consistent.
|
|
4
|
+
*/
|
|
5
|
+
import type { AdapterResponse, HttpResponse, HttpService } from "../http/http.models.js";
|
|
6
|
+
import type { CoreSdkError } from "../models/error.models.js";
|
|
7
|
+
import type { JsonValue } from "../models/json.models.js";
|
|
8
|
+
import type { Prettify } from "../models/utility.models.js";
|
|
9
|
+
export type CoreResponseMeta<TExtraMetadata = unknown> = Pick<AdapterResponse, "status" | "responseHeaders"> & {
|
|
10
|
+
readonly continuationToken?: string;
|
|
11
|
+
} & TExtraMetadata;
|
|
12
|
+
export type CoreResponse<TPayload, TExtraMetadata = unknown> = {
|
|
13
|
+
readonly payload: TPayload;
|
|
14
|
+
readonly meta: CoreResponseMeta<TExtraMetadata>;
|
|
15
|
+
};
|
|
16
|
+
export type CoreSdkConfig = {
|
|
17
|
+
/**
|
|
18
|
+
* The HTTP service to use for the request. If not provided, the default HTTP service will be used.
|
|
19
|
+
*
|
|
20
|
+
* You may provide your own HTTP service implementation to customize the request behavior.
|
|
21
|
+
*
|
|
22
|
+
* See https://github.com/kontent-ai/core-sdk-js for more information regarding the HTTP service customization.
|
|
23
|
+
*/
|
|
24
|
+
readonly httpService?: HttpService;
|
|
25
|
+
/**
|
|
26
|
+
* The base URL to use for the request. If not provided, the default base URL will be used.
|
|
27
|
+
*
|
|
28
|
+
* If provided, it will override the default base URL based on selected API mode.
|
|
29
|
+
*/
|
|
30
|
+
readonly baseUrl?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Configuration for response validation.
|
|
33
|
+
*/
|
|
34
|
+
readonly responseValidation?: {
|
|
35
|
+
/**
|
|
36
|
+
* When enabled, the response payload will be validated against the expected Zod schema from which the types
|
|
37
|
+
* this library are based on. This ensures that you are working with the correct data types.
|
|
38
|
+
*
|
|
39
|
+
* @default false
|
|
40
|
+
*/
|
|
41
|
+
readonly enable: boolean;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
export type Query<TPayload, TExtraData = unknown> = {
|
|
45
|
+
toUrl(): string;
|
|
46
|
+
toPromise(): Promise<QueryResult<CoreResponse<TPayload, TExtraData>>>;
|
|
47
|
+
};
|
|
48
|
+
export type PagingQuery<TPayload, TExtraData = unknown> = Query<TPayload, TExtraData> & {
|
|
49
|
+
toAllPromise(): Promise<PagingQueryResult<CoreResponse<TPayload, TExtraData>>>;
|
|
50
|
+
};
|
|
51
|
+
export type SuccessfulHttpResponse<TPayload extends JsonValue, TBodyData extends JsonValue> = Prettify<Extract<HttpResponse<TPayload, TBodyData>, {
|
|
52
|
+
readonly success: true;
|
|
53
|
+
}>["response"]>;
|
|
54
|
+
export type ResultOfSuccessfulQuery<TQuery extends Query<unknown>> = Extract<Awaited<ReturnType<TQuery["toPromise"]>>, {
|
|
55
|
+
readonly success: true;
|
|
56
|
+
}>["response"];
|
|
57
|
+
/**
|
|
58
|
+
* A nomadic result type that represents a success or failure of an operation.
|
|
59
|
+
*
|
|
60
|
+
* Ensures that consumers of this library handle both success and failure cases.
|
|
61
|
+
*/
|
|
62
|
+
export type QueryResult<TResponse> = (Success & {
|
|
63
|
+
readonly response: TResponse;
|
|
64
|
+
}) | (Failure & {
|
|
65
|
+
readonly response?: never;
|
|
66
|
+
});
|
|
67
|
+
export type PagingQueryResult<TResponse> = (Success & {
|
|
68
|
+
readonly responses: TResponse[];
|
|
69
|
+
readonly lastContinuationToken: string;
|
|
70
|
+
}) | (Failure & {
|
|
71
|
+
readonly responses?: never;
|
|
72
|
+
readonly lastContinuationToken?: never;
|
|
73
|
+
});
|
|
74
|
+
type Success = {
|
|
75
|
+
readonly success: true;
|
|
76
|
+
readonly error?: never;
|
|
77
|
+
};
|
|
78
|
+
type Failure = {
|
|
79
|
+
readonly success: false;
|
|
80
|
+
readonly error: CoreSdkError;
|
|
81
|
+
};
|
|
82
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk-models.js","sourceRoot":"","sources":["../../lib/sdk/sdk-models.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared query models/types intended to be reused across SDKs (e.g. Sync, Delivery, Management)
|
|
3
|
+
* to keep common code and behavior consistent.
|
|
4
|
+
*/
|
|
5
|
+
import type { ZodType } from "zod";
|
|
6
|
+
import type { HttpService } from "../http/http.models.js";
|
|
7
|
+
import type { Header, SDKInfo } from "../models/core.models.js";
|
|
8
|
+
import type { JsonValue } from "../models/json.models.js";
|
|
9
|
+
import type { EmptyObject } from "../models/utility.models.js";
|
|
10
|
+
import type { CoreResponse, CoreSdkConfig, PagingQuery, Query, SuccessfulHttpResponse } from "./sdk-models.js";
|
|
11
|
+
type ResolveToPromiseQuery<TPayload extends JsonValue, TExtraMetadata = EmptyObject> = ReturnType<Pick<Query<TPayload, TExtraMetadata>, "toPromise">["toPromise"]>;
|
|
12
|
+
export declare function getQuery<TPayload extends JsonValue, TBodyData extends JsonValue, TExtraMetadata>(data: Parameters<typeof resolveQueryAsync<TPayload, TBodyData, TExtraMetadata>>[0]): Pick<Query<TPayload, TExtraMetadata>, "toPromise">;
|
|
13
|
+
export declare function getPagingQuery<TPayload extends JsonValue, TBodyData extends JsonValue, TExtraMetadata = EmptyObject>(data: Parameters<typeof resolveQueryAsync<TPayload, TBodyData, TExtraMetadata>>[0] & {
|
|
14
|
+
readonly canFetchNextResponse: (response: CoreResponse<TPayload, TExtraMetadata>) => boolean;
|
|
15
|
+
readonly continuationToken: string;
|
|
16
|
+
}): Pick<PagingQuery<TPayload, TExtraMetadata>, "toPromise" | "toAllPromise">;
|
|
17
|
+
export declare function extractContinuationToken(responseHeaders: readonly Header[]): string | undefined;
|
|
18
|
+
declare function resolveQueryAsync<TPayload extends JsonValue, TBodyData extends JsonValue, TExtraMetadata>({ config, request, url, extraMetadata, zodSchema, continuationToken, sdkInfo, authorizationApiKey, }: {
|
|
19
|
+
readonly continuationToken: string | undefined;
|
|
20
|
+
readonly request: Parameters<HttpService["requestAsync"]>[number] & {
|
|
21
|
+
readonly body: TBodyData;
|
|
22
|
+
};
|
|
23
|
+
readonly extraMetadata: (response: SuccessfulHttpResponse<TPayload, TBodyData>) => TExtraMetadata;
|
|
24
|
+
readonly config: CoreSdkConfig;
|
|
25
|
+
readonly url: string;
|
|
26
|
+
readonly zodSchema: ZodType<TPayload>;
|
|
27
|
+
readonly sdkInfo: SDKInfo;
|
|
28
|
+
readonly authorizationApiKey: string | undefined;
|
|
29
|
+
}): ResolveToPromiseQuery<TPayload, TExtraMetadata>;
|
|
30
|
+
export {};
|