@kontent-ai/core-sdk 12.0.0-preview.2 → 12.0.0-preview.21
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/.npmignore +1 -5
- package/LICENSE.md +1 -1
- package/README.md +177 -12
- package/dist/core-sdk-info.d.ts +2 -0
- package/dist/core-sdk-info.js +6 -0
- package/dist/core-sdk-info.js.map +1 -0
- package/dist/devkit/console.utils.d.ts +2 -0
- package/dist/devkit/console.utils.js +5 -0
- package/dist/devkit/console.utils.js.map +1 -0
- package/dist/devkit/environment.utils.d.ts +2 -0
- package/dist/devkit/environment.utils.js +12 -0
- package/dist/devkit/environment.utils.js.map +1 -0
- package/dist/devkit/script.utils.js +3 -3
- package/dist/devkit/script.utils.js.map +1 -1
- package/dist/devkit_api.d.ts +3 -0
- package/dist/devkit_api.js +3 -1
- package/dist/devkit_api.js.map +1 -1
- package/dist/http/http.adapter.d.ts +1 -1
- package/dist/http/http.adapter.js +78 -24
- package/dist/http/http.adapter.js.map +1 -1
- package/dist/http/http.models.d.ts +42 -32
- package/dist/http/http.service.js +294 -220
- package/dist/http/http.service.js.map +1 -1
- package/dist/models/core.models.d.ts +34 -29
- package/dist/models/error.models.d.ts +48 -27
- package/dist/models/error.models.js +40 -1
- package/dist/models/error.models.js.map +1 -1
- package/dist/models/json.models.d.ts +13 -4
- package/dist/models/json.models.js +10 -1
- package/dist/models/json.models.js.map +1 -1
- package/dist/models/utility.types.d.ts +16 -0
- package/dist/models/utility.types.js +2 -0
- package/dist/models/utility.types.js.map +1 -0
- package/dist/public_api.d.ts +19 -11
- package/dist/public_api.js +15 -6
- package/dist/public_api.js.map +1 -1
- package/dist/sdk/queries/fetch-sdk-query.d.ts +7 -0
- package/dist/sdk/queries/fetch-sdk-query.js +24 -0
- package/dist/sdk/queries/fetch-sdk-query.js.map +1 -0
- package/dist/sdk/queries/mutation-sdk-query.d.ts +4 -0
- package/dist/sdk/queries/mutation-sdk-query.js +17 -0
- package/dist/sdk/queries/mutation-sdk-query.js.map +1 -0
- package/dist/sdk/queries/paged-fetch-sdk-query.d.ts +6 -0
- package/dist/sdk/queries/paged-fetch-sdk-query.js +145 -0
- package/dist/sdk/queries/paged-fetch-sdk-query.js.map +1 -0
- package/dist/sdk/resolve-query.d.ts +8 -0
- package/dist/sdk/resolve-query.js +108 -0
- package/dist/sdk/resolve-query.js.map +1 -0
- package/dist/sdk/sdk-config.d.ts +3 -0
- package/dist/sdk/sdk-config.js +4 -0
- package/dist/sdk/sdk-config.js.map +1 -0
- package/dist/sdk/sdk-models.d.ts +101 -36
- package/dist/sdk/sdk-utils.d.ts +2 -0
- package/dist/sdk/sdk-utils.js +9 -0
- package/dist/sdk/sdk-utils.js.map +1 -0
- package/dist/testkit/poll.utils.d.ts +5 -0
- package/dist/testkit/poll.utils.js +24 -0
- package/dist/testkit/poll.utils.js.map +1 -0
- package/dist/testkit/testkit.utils.d.ts +20 -0
- package/dist/testkit/testkit.utils.js +100 -0
- package/dist/testkit/testkit.utils.js.map +1 -0
- package/dist/testkit_api.d.ts +3 -1
- package/dist/testkit_api.js +3 -2
- package/dist/testkit_api.js.map +1 -1
- package/dist/utils/abort.utils.d.ts +12 -0
- package/dist/utils/abort.utils.js +29 -0
- package/dist/utils/abort.utils.js.map +1 -0
- package/dist/utils/core.utils.d.ts +3 -1
- package/dist/utils/core.utils.js +22 -2
- package/dist/utils/core.utils.js.map +1 -1
- package/dist/utils/error.utils.d.ts +18 -7
- package/dist/utils/error.utils.js +35 -7
- package/dist/utils/error.utils.js.map +1 -1
- package/dist/utils/header.utils.d.ts +6 -1
- package/dist/utils/header.utils.js +37 -6
- package/dist/utils/header.utils.js.map +1 -1
- package/dist/utils/retry.utils.d.ts +16 -11
- package/dist/utils/retry.utils.js +131 -63
- package/dist/utils/retry.utils.js.map +1 -1
- package/dist/utils/sdk-version.utils.js +2 -2
- package/dist/utils/sdk-version.utils.js.map +1 -1
- package/dist/utils/try-catch.utils.d.ts +15 -0
- package/dist/utils/{try.utils.js → try-catch.utils.js} +1 -1
- package/dist/utils/try-catch.utils.js.map +1 -0
- package/dist/utils/type.utils.d.ts +2 -0
- package/dist/utils/type.utils.js +5 -0
- package/dist/utils/type.utils.js.map +1 -0
- package/dist/utils/url.utils.d.ts +5 -0
- package/dist/utils/url.utils.js +10 -0
- package/dist/utils/url.utils.js.map +1 -0
- package/package.json +61 -64
- package/dist/models/utility.models.d.ts +0 -20
- package/dist/models/utility.models.js +0 -2
- package/dist/models/utility.models.js.map +0 -1
- package/dist/sdk/sdk-queries.d.ts +0 -30
- package/dist/sdk/sdk-queries.js +0 -152
- package/dist/sdk/sdk-queries.js.map +0 -1
- package/dist/sdk-info.d.ts +0 -5
- package/dist/sdk-info.js +0 -6
- package/dist/sdk-info.js.map +0 -1
- package/dist/testkit/test.utils.d.ts +0 -15
- package/dist/testkit/test.utils.js +0 -42
- package/dist/testkit/test.utils.js.map +0 -1
- package/dist/utils/try.utils.d.ts +0 -14
- package/dist/utils/try.utils.js.map +0 -1
- package/lib/devkit/script.utils.ts +0 -12
- package/lib/devkit_api.ts +0 -3
- package/lib/http/http.adapter.ts +0 -38
- package/lib/http/http.models.ts +0 -122
- package/lib/http/http.service.ts +0 -320
- package/lib/models/core.models.ts +0 -89
- package/lib/models/error.models.ts +0 -83
- package/lib/models/json.models.ts +0 -9
- package/lib/models/utility.models.ts +0 -21
- package/lib/public_api.ts +0 -45
- package/lib/sdk/sdk-models.ts +0 -85
- package/lib/sdk/sdk-queries.ts +0 -232
- package/lib/sdk-info.ts +0 -5
- package/lib/testkit/test.utils.ts +0 -79
- package/lib/testkit/testkit.models.ts +0 -7
- package/lib/testkit_api.ts +0 -3
- package/lib/utils/core.utils.ts +0 -3
- package/lib/utils/error.utils.ts +0 -48
- package/lib/utils/header.utils.ts +0 -40
- package/lib/utils/retry.utils.ts +0 -156
- package/lib/utils/sdk-version.utils.ts +0 -16
- package/lib/utils/try.utils.ts +0 -30
|
@@ -0,0 +1,108 @@
|
|
|
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 { getDefaultHttpService } from "../http/http.service.js";
|
|
6
|
+
import { createSdkError } from "../utils/error.utils.js";
|
|
7
|
+
import { createAuthorizationHeader, createContinuationHeader, extractContinuationToken, getSdkIdHeader } from "../utils/header.utils.js";
|
|
8
|
+
import { tryCatch } from "../utils/try-catch.utils.js";
|
|
9
|
+
export async function resolveQuery({ config, request, mapMetadata, zodSchema, sdkInfo, method, abortSignal, mapError, }) {
|
|
10
|
+
const urlToUse = config.baseUrl ? setBaseUrl(request.url, config.baseUrl) : request.url;
|
|
11
|
+
const { success, response, error } = await getHttpService(config).request({
|
|
12
|
+
body: request.body,
|
|
13
|
+
url: urlToUse,
|
|
14
|
+
method,
|
|
15
|
+
abortSignal,
|
|
16
|
+
requestHeaders: getCombinedRequestHeaders({
|
|
17
|
+
requestHeaders: request.requestHeaders ?? [],
|
|
18
|
+
continuationToken: request.continuationToken,
|
|
19
|
+
authorizationApiKey: request.authorizationApiKey,
|
|
20
|
+
sdkInfo,
|
|
21
|
+
}),
|
|
22
|
+
});
|
|
23
|
+
if (!success) {
|
|
24
|
+
return {
|
|
25
|
+
success: false,
|
|
26
|
+
error: mapError(error),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
if (config.responseValidation?.enable) {
|
|
30
|
+
const validationError = await validateResponse({ url: response.adapterResponse.url, response, zodSchema });
|
|
31
|
+
if (validationError) {
|
|
32
|
+
return {
|
|
33
|
+
success: false,
|
|
34
|
+
error: mapError(validationError.error),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const continuationTokenFromResponse = extractContinuationToken(response.adapterResponse.responseHeaders);
|
|
39
|
+
const result = {
|
|
40
|
+
success: true,
|
|
41
|
+
response: {
|
|
42
|
+
payload: response.payload,
|
|
43
|
+
meta: {
|
|
44
|
+
...mapMetadata(response, { continuationToken: continuationTokenFromResponse }),
|
|
45
|
+
url: response.adapterResponse.url,
|
|
46
|
+
responseHeaders: response.adapterResponse.responseHeaders,
|
|
47
|
+
status: response.adapterResponse.status,
|
|
48
|
+
continuationToken: continuationTokenFromResponse,
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* We are intentionally not throwing errors here as parsing errors are handled by the HttpService.
|
|
56
|
+
*/
|
|
57
|
+
function setBaseUrl(url, baseUrl) {
|
|
58
|
+
const { success, data: parsedUrl } = tryCatch(() => new URL(url));
|
|
59
|
+
if (!success) {
|
|
60
|
+
return url;
|
|
61
|
+
}
|
|
62
|
+
if (baseUrl.startsWith("http")) {
|
|
63
|
+
const { success, data: parsedBaseUrl } = tryCatch(() => new URL(baseUrl));
|
|
64
|
+
if (!success) {
|
|
65
|
+
return url;
|
|
66
|
+
}
|
|
67
|
+
parsedUrl.host = parsedBaseUrl.host;
|
|
68
|
+
parsedUrl.protocol = parsedBaseUrl.protocol;
|
|
69
|
+
return parsedUrl.toString();
|
|
70
|
+
}
|
|
71
|
+
parsedUrl.host = baseUrl;
|
|
72
|
+
return parsedUrl.toString();
|
|
73
|
+
}
|
|
74
|
+
async function validateResponse({ url, response, zodSchema, }) {
|
|
75
|
+
const { success, error } = await zodSchema.safeParseAsync(response.payload);
|
|
76
|
+
if (!success) {
|
|
77
|
+
return {
|
|
78
|
+
success: false,
|
|
79
|
+
error: createSdkError({
|
|
80
|
+
baseErrorData: {
|
|
81
|
+
message: `Failed to validate response schema for url '${url}'`,
|
|
82
|
+
url,
|
|
83
|
+
retryStrategyOptions: undefined,
|
|
84
|
+
retryAttempt: undefined,
|
|
85
|
+
},
|
|
86
|
+
details: {
|
|
87
|
+
reason: "validationFailed",
|
|
88
|
+
zodError: error,
|
|
89
|
+
response,
|
|
90
|
+
url,
|
|
91
|
+
},
|
|
92
|
+
}),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
function getHttpService(config) {
|
|
98
|
+
return config.httpService ?? getDefaultHttpService();
|
|
99
|
+
}
|
|
100
|
+
function getCombinedRequestHeaders({ requestHeaders, continuationToken, authorizationApiKey, sdkInfo, }) {
|
|
101
|
+
return [
|
|
102
|
+
getSdkIdHeader(sdkInfo),
|
|
103
|
+
...requestHeaders.filter((header) => header.name !== "X-KC-SDKID"),
|
|
104
|
+
...(continuationToken ? [createContinuationHeader(continuationToken)] : []),
|
|
105
|
+
...(authorizationApiKey ? [createAuthorizationHeader(authorizationApiKey)] : []),
|
|
106
|
+
];
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=resolve-query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-query.js","sourceRoot":"","sources":["../../lib/sdk/resolve-query.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAIhE,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AACzI,OAAO,EAAgB,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAGrE,MAAM,CAAC,KAAK,UAAU,YAAY,CAA0F,EAC3H,MAAM,EACN,OAAO,EACP,WAAW,EACX,SAAS,EACT,OAAO,EACP,MAAM,EACN,WAAW,EACX,QAAQ,GACyD;IACjE,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC;IACxF,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,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|
package/dist/sdk/sdk-models.d.ts
CHANGED
|
@@ -2,18 +2,22 @@
|
|
|
2
2
|
* Shared query models/types intended to be reused across SDKs (e.g. Sync, Delivery, Management)
|
|
3
3
|
* to keep common code and behavior consistent.
|
|
4
4
|
*/
|
|
5
|
-
import type
|
|
6
|
-
import type {
|
|
5
|
+
import type z from "zod";
|
|
6
|
+
import type { ZodType } from "zod";
|
|
7
|
+
import type { AdapterPayload, AdapterResponse, HttpPayload, HttpRequestBody, HttpResponse, HttpService, PaginationConfig } from "../http/http.models.js";
|
|
8
|
+
import type { Header, HttpMethod, SDKInfo } from "../models/core.models.js";
|
|
9
|
+
import type { KontentSdkError } from "../models/error.models.js";
|
|
7
10
|
import type { JsonValue } from "../models/json.models.js";
|
|
8
|
-
import type {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
readonly
|
|
11
|
+
import type { PickStringLiteral } from "../models/utility.types.js";
|
|
12
|
+
import type { Failure, Success } from "../utils/try-catch.utils.js";
|
|
13
|
+
export type QueryResponseMeta<TMeta> = Pick<AdapterResponse<AdapterPayload>, "status" | "responseHeaders" | "url"> & {
|
|
14
|
+
readonly continuationToken: string | undefined;
|
|
15
|
+
} & TMeta;
|
|
16
|
+
export type QueryResponse<TResponsePayload, TMeta> = {
|
|
17
|
+
readonly payload: TResponsePayload;
|
|
18
|
+
readonly meta: QueryResponseMeta<TMeta>;
|
|
15
19
|
};
|
|
16
|
-
export type
|
|
20
|
+
export type SdkConfig = {
|
|
17
21
|
/**
|
|
18
22
|
* The HTTP service to use for the request. If not provided, the default HTTP service will be used.
|
|
19
23
|
*
|
|
@@ -33,7 +37,7 @@ export type CoreSdkConfig = {
|
|
|
33
37
|
*/
|
|
34
38
|
readonly responseValidation?: {
|
|
35
39
|
/**
|
|
36
|
-
* When enabled, the response
|
|
40
|
+
* When enabled, the response data will be validated against the expected Zod schema from which the types
|
|
37
41
|
* this library are based on. This ensures that you are working with the correct data types.
|
|
38
42
|
*
|
|
39
43
|
* @default false
|
|
@@ -41,42 +45,103 @@ export type CoreSdkConfig = {
|
|
|
41
45
|
readonly enable: boolean;
|
|
42
46
|
};
|
|
43
47
|
};
|
|
44
|
-
export type Query<
|
|
45
|
-
|
|
46
|
-
|
|
48
|
+
export type Query<TResponsePayload> = {
|
|
49
|
+
readonly schema: z.ZodType<TResponsePayload>;
|
|
50
|
+
readonly url: string;
|
|
47
51
|
};
|
|
48
|
-
export type
|
|
49
|
-
|
|
52
|
+
export type FetchQuery<TResponsePayload, TMeta, TError> = Query<TResponsePayload> & {
|
|
53
|
+
fetchSafe(): Promise<QueryResult<QueryResponse<TResponsePayload, TMeta>, TError>>;
|
|
54
|
+
fetch(): Promise<QueryResponse<TResponsePayload, TMeta>>;
|
|
50
55
|
};
|
|
51
|
-
export type
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
56
|
+
export type PagedFetchQuery<TResponsePayload, TMeta, TError> = Query<TResponsePayload> & {
|
|
57
|
+
fetchPageSafe(): Promise<QueryResult<QueryResponse<TResponsePayload, TMeta>, TError>>;
|
|
58
|
+
fetchPage(): Promise<QueryResponse<TResponsePayload, TMeta>>;
|
|
59
|
+
fetchAllPagesSafe(config?: PaginationConfig): Promise<SafePagingQueryResult<QueryResponse<TResponsePayload, TMeta>, TError>>;
|
|
60
|
+
fetchAllPages(config?: PaginationConfig): Promise<PagingQueryResult<QueryResponse<TResponsePayload, TMeta>>>;
|
|
61
|
+
pagesSafe(config?: PaginationConfig): AsyncGenerator<QueryResult<QueryResponse<TResponsePayload, TMeta>, TError>>;
|
|
62
|
+
pages(config?: PaginationConfig): AsyncGenerator<QueryResponse<TResponsePayload, TMeta>>;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Not yet implemented.
|
|
66
|
+
*
|
|
67
|
+
* @todo Implement mutation query.
|
|
68
|
+
*/
|
|
69
|
+
export type MutationQuery<TResponsePayload, TMeta, TError> = Query<TResponsePayload> & {
|
|
70
|
+
executeSafe(): Promise<QueryResult<QueryResponse<TResponsePayload, TMeta>, TError>>;
|
|
71
|
+
execute(): Promise<QueryResponse<TResponsePayload, TMeta>>;
|
|
72
|
+
};
|
|
73
|
+
export type NextPageStateWithRequest = {
|
|
74
|
+
readonly pageSource: "continuationToken";
|
|
75
|
+
readonly hasNextPage: true;
|
|
76
|
+
readonly continuationToken: string;
|
|
77
|
+
readonly nextPageUrl?: never;
|
|
78
|
+
} | {
|
|
79
|
+
readonly pageSource: "nextPageUrl";
|
|
80
|
+
readonly hasNextPage: true;
|
|
81
|
+
readonly continuationToken?: never;
|
|
82
|
+
readonly nextPageUrl: string;
|
|
83
|
+
} | {
|
|
84
|
+
readonly pageSource: "firstRequest";
|
|
85
|
+
readonly hasNextPage: true;
|
|
86
|
+
readonly continuationToken?: never;
|
|
87
|
+
readonly nextPageUrl?: never;
|
|
88
|
+
};
|
|
89
|
+
export type SuccessfulHttpResponse<TResponsePayload extends HttpPayload, TRequestBody extends HttpRequestBody> = Extract<HttpResponse<TResponsePayload, TRequestBody>, {
|
|
55
90
|
readonly success: true;
|
|
56
91
|
}>["response"];
|
|
57
92
|
/**
|
|
58
|
-
*
|
|
93
|
+
* Result type that represents a success or failure of an operation.
|
|
59
94
|
*
|
|
60
95
|
* Ensures that consumers of this library handle both success and failure cases.
|
|
61
96
|
*/
|
|
62
|
-
export type QueryResult<
|
|
63
|
-
readonly response:
|
|
64
|
-
}
|
|
97
|
+
export type QueryResult<TResponsePayload, TError> = Success<{
|
|
98
|
+
readonly response: TResponsePayload;
|
|
99
|
+
}> | Failure<{
|
|
65
100
|
readonly response?: never;
|
|
66
|
-
}
|
|
67
|
-
export type
|
|
68
|
-
readonly responses:
|
|
69
|
-
readonly
|
|
70
|
-
|
|
101
|
+
}, TError>;
|
|
102
|
+
export type SafePagingQueryResult<TResponsePayload, TError> = Success<{
|
|
103
|
+
readonly responses: readonly TResponsePayload[];
|
|
104
|
+
readonly partialResponses?: never;
|
|
105
|
+
readonly lastContinuationToken: string | undefined;
|
|
106
|
+
}> | Failure<{
|
|
71
107
|
readonly responses?: never;
|
|
72
108
|
readonly lastContinuationToken?: never;
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
readonly
|
|
109
|
+
readonly partialResponses: readonly TResponsePayload[];
|
|
110
|
+
}, TError>;
|
|
111
|
+
export type PagingQueryResult<TResponsePayload> = {
|
|
112
|
+
readonly responses: readonly TResponsePayload[];
|
|
113
|
+
readonly lastContinuationToken: string | undefined;
|
|
114
|
+
};
|
|
115
|
+
export type QueryPromiseResult<TResponsePayload extends JsonValue, TMeta, TError> = ReturnType<Pick<FetchQuery<TResponsePayload, TMeta, TError>, "fetchSafe">["fetchSafe"]>;
|
|
116
|
+
export type FetchQueryRequest<TResponsePayload extends JsonValue, TMeta, TError> = Pick<ResolveQueryData<TResponsePayload, null, TMeta, TError>, "config" | "zodSchema" | "sdkInfo" | "mapMetadata" | "abortSignal" | "mapError"> & {
|
|
117
|
+
readonly request: RequestDataWithoutBody;
|
|
118
|
+
};
|
|
119
|
+
export type MutationQueryRequest<TResponsePayload extends JsonValue, TRequestBody extends HttpRequestBody, TMeta, TError> = Pick<ResolveQueryData<TResponsePayload, TRequestBody, TMeta, TError>, "config" | "zodSchema" | "sdkInfo" | "mapMetadata" | "abortSignal" | "request" | "mapError"> & {
|
|
120
|
+
readonly method: MutationHttpMethod;
|
|
121
|
+
};
|
|
122
|
+
export type ResolveQueryData<TResponsePayload extends JsonValue, TRequestBody extends HttpRequestBody, TMeta, TError> = {
|
|
123
|
+
readonly method: HttpMethod;
|
|
124
|
+
readonly request: RequestData<TRequestBody>;
|
|
125
|
+
readonly config: SdkConfig;
|
|
126
|
+
readonly zodSchema: ZodType<TResponsePayload>;
|
|
127
|
+
readonly sdkInfo: SDKInfo;
|
|
128
|
+
readonly abortSignal?: AbortSignal | undefined;
|
|
129
|
+
readonly mapError: (error: KontentSdkError) => TError;
|
|
130
|
+
} & MetadataMapperConfig<TResponsePayload, TRequestBody, TMeta>;
|
|
131
|
+
type MetadataMapperConfig<TResponsePayload extends JsonValue, TRequestBody extends HttpRequestBody, TMeta> = {
|
|
132
|
+
readonly mapMetadata: MetadataMapper<TResponsePayload, TRequestBody, TMeta>;
|
|
133
|
+
};
|
|
134
|
+
type MetadataMapper<TResponsePayload extends JsonValue, TRequestBody extends HttpRequestBody, TMeta> = (response: SuccessfulHttpResponse<TResponsePayload, TRequestBody>, data: MetadataContextData) => TMeta;
|
|
135
|
+
type MetadataContextData = {
|
|
136
|
+
readonly continuationToken: string | undefined;
|
|
77
137
|
};
|
|
78
|
-
type
|
|
79
|
-
readonly
|
|
80
|
-
readonly
|
|
138
|
+
type RequestData<TRequestBody extends HttpRequestBody> = {
|
|
139
|
+
readonly url: string;
|
|
140
|
+
readonly body: TRequestBody;
|
|
141
|
+
readonly requestHeaders?: readonly Header[];
|
|
142
|
+
readonly continuationToken?: string | undefined;
|
|
143
|
+
readonly authorizationApiKey?: string | undefined;
|
|
81
144
|
};
|
|
145
|
+
type MutationHttpMethod = PickStringLiteral<HttpMethod, "POST" | "PUT" | "PATCH" | "DELETE">;
|
|
146
|
+
type RequestDataWithoutBody = Omit<RequestData<never>, "body">;
|
|
82
147
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk-utils.js","sourceRoot":"","sources":["../../lib/sdk/sdk-utils.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,aAAa,CAC5B,KAAmD;IAEnD,OAAO,CACN,WAAW,IAAI,KAAK;QACpB,eAAe,IAAI,KAAK;QACxB,eAAe,IAAI,KAAK;QACxB,mBAAmB,IAAI,KAAK;QAC5B,OAAO,IAAI,KAAK;QAChB,WAAW,IAAI,KAAK,CACpB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Failure, Success } from "../utils/try-catch.utils.js";
|
|
2
|
+
export declare function poll<TResult, TError = unknown>(func: () => Promise<Success<TResult> | Failure<TResult, TError>>, config?: {
|
|
3
|
+
readonly intervalMs?: number;
|
|
4
|
+
readonly timeoutMs?: number;
|
|
5
|
+
}): Promise<Success<TResult> | Failure<TResult, TError>>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { sleep } from "../utils/core.utils.js";
|
|
2
|
+
const defaultIntervalMs = 1000;
|
|
3
|
+
const defaultTimeoutMs = 30000;
|
|
4
|
+
export async function poll(func, config) {
|
|
5
|
+
const intervalMs = config?.intervalMs ?? defaultIntervalMs;
|
|
6
|
+
const timeoutMs = config?.timeoutMs ?? defaultTimeoutMs;
|
|
7
|
+
const startTime = Date.now();
|
|
8
|
+
let elapsedMs = 0;
|
|
9
|
+
let latestAttempt;
|
|
10
|
+
while (elapsedMs <= timeoutMs) {
|
|
11
|
+
const result = await func();
|
|
12
|
+
latestAttempt = result;
|
|
13
|
+
if (result.success) {
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
elapsedMs = Date.now() - startTime;
|
|
17
|
+
await sleep(intervalMs);
|
|
18
|
+
}
|
|
19
|
+
if (!latestAttempt) {
|
|
20
|
+
throw new Error("Invalid latest attempt in poll result");
|
|
21
|
+
}
|
|
22
|
+
return latestAttempt;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=poll.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"poll.utils.js","sourceRoot":"","sources":["../../lib/testkit/poll.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAG/C,MAAM,iBAAiB,GAAG,IAAI,CAAC;AAC/B,MAAM,gBAAgB,GAAG,KAAK,CAAC;AAE/B,MAAM,CAAC,KAAK,UAAU,IAAI,CACzB,IAAgE,EAChE,MAGC;IAED,MAAM,UAAU,GAAG,MAAM,EAAE,UAAU,IAAI,iBAAiB,CAAC;IAC3D,MAAM,SAAS,GAAG,MAAM,EAAE,SAAS,IAAI,gBAAgB,CAAC;IACxD,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAE7B,IAAI,SAAS,GAAG,CAAC,CAAC;IAClB,IAAI,aAAsE,CAAC;IAE3E,OAAO,SAAS,IAAI,SAAS,EAAE,CAAC;QAC/B,MAAM,MAAM,GAAG,MAAM,IAAI,EAAE,CAAC;QAC5B,aAAa,GAAG,MAAM,CAAC;QAEvB,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YACpB,OAAO,MAAM,CAAC;QACf,CAAC;QAED,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;QACnC,MAAM,KAAK,CAAC,UAAU,CAAC,CAAC;IACzB,CAAC;IAED,IAAI,CAAC,aAAa,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;IAC1D,CAAC;IAED,OAAO,aAAa,CAAC;AACtB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { HttpService, HttpServiceStatus } from "../http/http.models.js";
|
|
2
|
+
import type { RetryStrategyOptions, SDKInfo } from "../models/core.models.js";
|
|
3
|
+
import type { JsonValue } from "../models/json.models.js";
|
|
4
|
+
export declare function mockGlobalFetchJsonResponse({ jsonResponse, statusCode, continuationToken, }: {
|
|
5
|
+
readonly jsonResponse: JsonValue;
|
|
6
|
+
readonly statusCode: HttpServiceStatus;
|
|
7
|
+
readonly continuationToken?: string;
|
|
8
|
+
}): void;
|
|
9
|
+
export declare function mockGlobalFetchBlobResponse({ blobResponse, statusCode, }: {
|
|
10
|
+
readonly blobResponse: Blob;
|
|
11
|
+
readonly statusCode: HttpServiceStatus;
|
|
12
|
+
}): void;
|
|
13
|
+
export declare function getFakeBlob(): Blob;
|
|
14
|
+
export declare function getTestSdkInfo(): SDKInfo;
|
|
15
|
+
export declare function getTestHttpServiceWithJsonResponse({ jsonResponse, statusCode, continuationToken, retryStrategy, }: {
|
|
16
|
+
readonly jsonResponse: JsonValue | (() => Promise<JsonValue>);
|
|
17
|
+
readonly statusCode: HttpServiceStatus;
|
|
18
|
+
readonly continuationToken?: string;
|
|
19
|
+
readonly retryStrategy?: RetryStrategyOptions;
|
|
20
|
+
}): HttpService;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { vi } from "vitest";
|
|
2
|
+
import { getDefaultHttpService } from "../http/http.service.js";
|
|
3
|
+
import { isDefined } from "../utils/core.utils.js";
|
|
4
|
+
import { createContinuationHeader, findHeaderByName, toFetchHeaders } from "../utils/header.utils.js";
|
|
5
|
+
export function mockGlobalFetchJsonResponse({ jsonResponse, statusCode, continuationToken, }) {
|
|
6
|
+
global.fetch = getFetchJsonMock({
|
|
7
|
+
json: jsonResponse,
|
|
8
|
+
status: statusCode,
|
|
9
|
+
responseHeaders: continuationToken ? [createContinuationHeader(continuationToken)] : [],
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
export function mockGlobalFetchBlobResponse({ blobResponse, statusCode, }) {
|
|
13
|
+
global.fetch = getFetchBlobMock({
|
|
14
|
+
blob: blobResponse,
|
|
15
|
+
status: statusCode,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
export function getFakeBlob() {
|
|
19
|
+
return new Blob(["x"], { type: "text/plain" });
|
|
20
|
+
}
|
|
21
|
+
export function getTestSdkInfo() {
|
|
22
|
+
return {
|
|
23
|
+
name: "test",
|
|
24
|
+
version: "0.0.0",
|
|
25
|
+
host: "sdk",
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export function getTestHttpServiceWithJsonResponse({ jsonResponse, statusCode, continuationToken, retryStrategy, }) {
|
|
29
|
+
return getDefaultHttpService({
|
|
30
|
+
retryStrategy: retryStrategy ?? {},
|
|
31
|
+
adapter: {
|
|
32
|
+
executeRequest: async ({ url }) => {
|
|
33
|
+
return {
|
|
34
|
+
responseHeaders: [...(continuationToken ? [createContinuationHeader(continuationToken)] : [])],
|
|
35
|
+
status: statusCode,
|
|
36
|
+
statusText: "",
|
|
37
|
+
url,
|
|
38
|
+
payload: typeof jsonResponse === "function" ? await jsonResponse() : jsonResponse,
|
|
39
|
+
};
|
|
40
|
+
},
|
|
41
|
+
downloadFile: async ({ url }) => {
|
|
42
|
+
return {
|
|
43
|
+
responseHeaders: [],
|
|
44
|
+
status: 200,
|
|
45
|
+
statusText: "",
|
|
46
|
+
url,
|
|
47
|
+
payload: await Promise.resolve(getFakeBlob()),
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function getFetchBlobMock({ blob, status, responseHeaders, }) {
|
|
54
|
+
return getFetchMock({
|
|
55
|
+
blob,
|
|
56
|
+
status,
|
|
57
|
+
responseHeaders: responseHeaders ?? [],
|
|
58
|
+
json: undefined,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
function getFetchJsonMock({ json, status, responseHeaders, }) {
|
|
62
|
+
return getFetchMock({
|
|
63
|
+
status,
|
|
64
|
+
responseHeaders: responseHeaders ?? [],
|
|
65
|
+
blob: undefined,
|
|
66
|
+
json,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function getFetchMock({ json, blob, status, responseHeaders, }) {
|
|
70
|
+
return vi.fn(async () => {
|
|
71
|
+
const baseResponse = {
|
|
72
|
+
ok: status >= 200 && status < 300,
|
|
73
|
+
headers: buildHeadersWithDefaultContentType(responseHeaders),
|
|
74
|
+
status,
|
|
75
|
+
json: async () => await Promise.resolve(json),
|
|
76
|
+
...(blob ? { blob: async () => await Promise.resolve(blob) } : {}),
|
|
77
|
+
};
|
|
78
|
+
return await Promise.resolve({
|
|
79
|
+
// only implement the methods we need, ignore the rest
|
|
80
|
+
...{},
|
|
81
|
+
...baseResponse,
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
function buildHeadersWithDefaultContentType(headers) {
|
|
86
|
+
const defaultContentTypeHeader = getDefaultContentTypeHeaderIfMissing(headers);
|
|
87
|
+
const headersWithDefaults = [...headers, defaultContentTypeHeader].filter(isDefined);
|
|
88
|
+
return toFetchHeaders(headersWithDefaults);
|
|
89
|
+
}
|
|
90
|
+
function getDefaultContentTypeHeaderIfMissing(headers) {
|
|
91
|
+
const hasContentTypeHeader = findHeaderByName(headers, "Content-Type");
|
|
92
|
+
if (hasContentTypeHeader) {
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
name: "Content-Type",
|
|
97
|
+
value: "application/json",
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=testkit.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testkit.utils.js","sourceRoot":"","sources":["../../lib/testkit/testkit.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,EAAE,EAAE,MAAM,QAAQ,CAAC;AAEvC,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAIhE,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,wBAAwB,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAEtG,MAAM,UAAU,2BAA2B,CAAC,EAC3C,YAAY,EACZ,UAAU,EACV,iBAAiB,GAKjB;IACA,MAAM,CAAC,KAAK,GAAG,gBAAgB,CAAC;QAC/B,IAAI,EAAE,YAAY;QAClB,MAAM,EAAE,UAAU;QAClB,eAAe,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC,wBAAwB,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE;KACvF,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,2BAA2B,CAAC,EAC3C,YAAY,EACZ,UAAU,GAIV;IACA,MAAM,CAAC,KAAK,GAAG,gBAAgB,CAAC;QAC/B,IAAI,EAAE,YAAY;QAClB,MAAM,EAAE,UAAU;KAClB,CAAC,CAAC;AACJ,CAAC;AAED,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CAAC,OAA0B;IACvE,MAAM,oBAAoB,GAAG,gBAAgB,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;IAEvE,IAAI,oBAAoB,EAAE,CAAC;QAC1B,OAAO,SAAS,CAAC;IAClB,CAAC;IAED,OAAO;QACN,IAAI,EAAE,cAA0C;QAChD,KAAK,EAAE,kBAAkB;KACzB,CAAC;AACH,CAAC"}
|
package/dist/testkit_api.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
/** biome-ignore-all lint/performance/noBarrelFile: One barrel for exported API is fine */
|
|
2
|
+
export { poll } from "./testkit/poll.utils.js";
|
|
2
3
|
export type { FetchResponse } from "./testkit/testkit.models.js";
|
|
4
|
+
export { getFakeBlob, getTestHttpServiceWithJsonResponse, getTestSdkInfo, mockGlobalFetchBlobResponse, mockGlobalFetchJsonResponse, } from "./testkit/testkit.utils.js";
|
package/dist/testkit_api.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
1
|
+
/** biome-ignore-all lint/performance/noBarrelFile: One barrel for exported API is fine */
|
|
2
|
+
export { poll } from "./testkit/poll.utils.js";
|
|
3
|
+
export { getFakeBlob, getTestHttpServiceWithJsonResponse, getTestSdkInfo, mockGlobalFetchBlobResponse, mockGlobalFetchJsonResponse, } from "./testkit/testkit.utils.js";
|
|
3
4
|
//# sourceMappingURL=testkit_api.js.map
|
package/dist/testkit_api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testkit_api.js","sourceRoot":"","sources":["../lib/testkit_api.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"testkit_api.js","sourceRoot":"","sources":["../lib/testkit_api.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAE1F,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAE/C,OAAO,EACN,WAAW,EACX,kCAAkC,EAClC,cAAc,EACd,2BAA2B,EAC3B,2BAA2B,GAC3B,MAAM,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
type AbortResult<TData> = {
|
|
2
|
+
readonly isAborted: false;
|
|
3
|
+
readonly data: TData;
|
|
4
|
+
} | {
|
|
5
|
+
readonly isAborted: true;
|
|
6
|
+
readonly data?: never;
|
|
7
|
+
};
|
|
8
|
+
export declare function runWithAbortSignal<T>({ func, abortSignal, }: {
|
|
9
|
+
readonly func: () => Promise<T>;
|
|
10
|
+
readonly abortSignal: AbortSignal;
|
|
11
|
+
}): Promise<AbortResult<T>>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export async function runWithAbortSignal({ func, abortSignal, }) {
|
|
2
|
+
if (abortSignal.aborted) {
|
|
3
|
+
return {
|
|
4
|
+
isAborted: true,
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
const listenerName = "abort";
|
|
8
|
+
return await new Promise((resolve) => {
|
|
9
|
+
const onAbort = () => {
|
|
10
|
+
cleanup();
|
|
11
|
+
resolve({ isAborted: true });
|
|
12
|
+
};
|
|
13
|
+
const cleanup = () => {
|
|
14
|
+
abortSignal.removeEventListener(listenerName, onAbort);
|
|
15
|
+
};
|
|
16
|
+
abortSignal.addEventListener(listenerName, onAbort);
|
|
17
|
+
func()
|
|
18
|
+
.then((result) => {
|
|
19
|
+
resolve({ isAborted: false, data: result });
|
|
20
|
+
})
|
|
21
|
+
.catch(() => {
|
|
22
|
+
resolve({ isAborted: true });
|
|
23
|
+
})
|
|
24
|
+
.finally(() => {
|
|
25
|
+
cleanup();
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=abort.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abort.utils.js","sourceRoot":"","sources":["../../lib/utils/abort.utils.ts"],"names":[],"mappings":"AAUA,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAI,EAC3C,IAAI,EACJ,WAAW,GAIX;IACA,IAAI,WAAW,CAAC,OAAO,EAAE,CAAC;QACzB,OAAO;YACN,SAAS,EAAE,IAAI;SACf,CAAC;IACH,CAAC;IAED,MAAM,YAAY,GAAG,OAAO,CAAC;IAE7B,OAAO,MAAM,IAAI,OAAO,CAAiB,CAAC,OAAO,EAAE,EAAE;QACpD,MAAM,OAAO,GAAG,GAAG,EAAE;YACpB,OAAO,EAAE,CAAC;YACV,OAAO,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC9B,CAAC,CAAC;QACF,MAAM,OAAO,GAAG,GAAG,EAAE;YACpB,WAAW,CAAC,mBAAmB,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;QACxD,CAAC,CAAC;QACF,WAAW,CAAC,gBAAgB,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;QAEpD,IAAI,EAAE;aACJ,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;YAChB,OAAO,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;QAC7C,CAAC,CAAC;aACD,KAAK,CAAC,GAAG,EAAE;YACX,OAAO,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC9B,CAAC,CAAC;aACD,OAAO,CAAC,GAAG,EAAE;YACb,OAAO,EAAE,CAAC;QACX,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1,3 @@
|
|
|
1
|
-
export declare function
|
|
1
|
+
export declare function isDefined<T>(value: T): value is NonNullable<T>;
|
|
2
|
+
export declare function sleep(ms: number): Promise<void>;
|
|
3
|
+
export declare function isBlob(value: unknown): value is Blob;
|
package/dist/utils/core.utils.js
CHANGED
|
@@ -1,4 +1,24 @@
|
|
|
1
|
-
export function
|
|
2
|
-
return value !== undefined;
|
|
1
|
+
export function isDefined(value) {
|
|
2
|
+
return value !== undefined && value !== null;
|
|
3
|
+
}
|
|
4
|
+
export async function sleep(ms) {
|
|
5
|
+
return await new Promise((resolve) => {
|
|
6
|
+
setTimeout(resolve, ms);
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
export function isBlob(value) {
|
|
10
|
+
if (!value) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
if (value instanceof Blob) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
const record = value;
|
|
17
|
+
return (Object.prototype.toString.call(value) === "[object Blob]" ||
|
|
18
|
+
(typeof record.arrayBuffer === "function" &&
|
|
19
|
+
typeof record.text === "function" &&
|
|
20
|
+
typeof record.stream === "function" &&
|
|
21
|
+
typeof record.size === "number" &&
|
|
22
|
+
typeof record.type === "string"));
|
|
3
23
|
}
|
|
4
24
|
//# sourceMappingURL=core.utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.utils.js","sourceRoot":"","sources":["../../lib/utils/core.utils.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"core.utils.js","sourceRoot":"","sources":["../../lib/utils/core.utils.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,SAAS,CAAI,KAAQ;IACpC,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,CAAC;AAC9C,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,KAAK,CAAC,EAAU;IACrC,OAAO,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;QAC1C,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IACzB,CAAC,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,KAAc;IACpC,IAAI,CAAC,KAAK,EAAE,CAAC;QACZ,OAAO,KAAK,CAAC;IACd,CAAC;IAED,IAAI,KAAK,YAAY,IAAI,EAAE,CAAC;QAC3B,OAAO,IAAI,CAAC;IACb,CAAC;IAED,MAAM,MAAM,GAAG,KAAgC,CAAC;IAEhD,OAAO,CACN,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,eAAe;QACzD,CAAC,OAAO,MAAM,CAAC,WAAW,KAAK,UAAU;YACxC,OAAO,MAAM,CAAC,IAAI,KAAK,UAAU;YACjC,OAAO,MAAM,CAAC,MAAM,KAAK,UAAU;YACnC,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ;YAC/B,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,CAAC,CACjC,CAAC;AACH,CAAC"}
|
|
@@ -1,10 +1,21 @@
|
|
|
1
|
-
import type { AdapterResponse } from "../http/http.models.js";
|
|
2
|
-
import type {
|
|
3
|
-
import type
|
|
4
|
-
export declare function
|
|
5
|
-
|
|
1
|
+
import type { AdapterPayload, AdapterResponse } from "../http/http.models.js";
|
|
2
|
+
import type { ErrorResponseData, HttpMethod } from "../models/core.models.js";
|
|
3
|
+
import { AdapterAbortError, AdapterParseError, type BaseErrorData, type ErrorDetails, KontentSdkError } from "../models/error.models.js";
|
|
4
|
+
export declare function createSdkError<TDetails extends ErrorDetails>({ baseErrorData, details, }: {
|
|
5
|
+
readonly baseErrorData: BaseErrorData;
|
|
6
|
+
readonly details: TDetails;
|
|
7
|
+
}): KontentSdkError<TDetails>;
|
|
8
|
+
export declare function isKontent404Error(error: unknown): boolean;
|
|
9
|
+
export declare function isKontentSdkError(error: unknown): error is KontentSdkError;
|
|
10
|
+
export declare function isAdapterParseError(error: unknown): error is AdapterParseError;
|
|
11
|
+
export declare function isAdapterAbortError(error: unknown): error is AdapterAbortError;
|
|
12
|
+
export declare function toInvalidResponseMessage({ method, url, adapterResponse, kontentErrorResponse, }: {
|
|
6
13
|
readonly url: string;
|
|
7
14
|
readonly method: HttpMethod;
|
|
8
|
-
readonly adapterResponse: AdapterResponse
|
|
9
|
-
readonly kontentErrorResponse?:
|
|
15
|
+
readonly adapterResponse: AdapterResponse<AdapterPayload>;
|
|
16
|
+
readonly kontentErrorResponse?: ErrorResponseData;
|
|
10
17
|
}): string;
|
|
18
|
+
/**
|
|
19
|
+
* Checks if the given JSON value is a Kontent API error response data.
|
|
20
|
+
*/
|
|
21
|
+
export declare function isKontentErrorResponseData(json: unknown): json is ErrorResponseData;
|