@kontent-ai/core-sdk 11.0.2 → 12.0.0-preview.2
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.map +1 -1
- package/dist/models/core.models.d.ts +3 -1
- package/dist/models/error.models.d.ts +11 -1
- package/dist/models/utility.models.d.ts +4 -0
- package/dist/public_api.d.ts +8 -6
- package/dist/public_api.js +2 -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 +13 -6
- package/lib/models/core.models.ts +4 -1
- package/lib/models/error.models.ts +19 -1
- package/lib/models/utility.models.ts +5 -0
- package/lib/public_api.ts +19 -9
- package/lib/sdk/sdk-models.ts +85 -0
- package/lib/sdk/sdk-queries.ts +232 -0
- package/lib/utils/header.utils.ts +3 -1
- package/package.json +23 -15
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.service.js","sourceRoot":"","sources":["../../lib/http/http.service.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,8BAA8B,EAAE,MAAM,yBAAyB,CAAC;AAC5F,OAAO,EAAe,QAAQ,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC7E,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CA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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,6 +1,9 @@
|
|
|
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", {
|
|
@@ -11,6 +14,13 @@ export type CoreSdkErrorDetails<TReason extends ErrorReason = ErrorReason> = (De
|
|
|
11
14
|
readonly originalError: unknown;
|
|
12
15
|
}> | Details<"unknown", {
|
|
13
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,13 @@
|
|
|
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 type { CoreResponse, CoreResponseMeta, CoreSdkConfig, PagingQuery, PagingQueryResult, Query, QueryResult, ResultOfSuccessfulQuery, SuccessfulHttpResponse, } from "./sdk/sdk-models.js";
|
|
9
|
+
export { extractContinuationToken, getPagingQuery, getQuery } from "./sdk/sdk-queries.js";
|
|
10
|
+
export { isKontent404Error } from "./utils/error.utils.js";
|
|
3
11
|
export { getSdkIdHeader } from "./utils/header.utils.js";
|
|
4
12
|
export { toRequiredRetryStrategyOptions } from "./utils/retry.utils.js";
|
|
5
13
|
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, CommonHeaderNames, } 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,9 @@
|
|
|
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 { extractContinuationToken, getPagingQuery, getQuery } from "./sdk/sdk-queries.js";
|
|
5
|
+
export { isKontent404Error } from "./utils/error.utils.js";
|
|
4
6
|
export { getSdkIdHeader } from "./utils/header.utils.js";
|
|
5
7
|
export { toRequiredRetryStrategyOptions } from "./utils/retry.utils.js";
|
|
6
8
|
export { tryCatch, tryCatchAsync } from "./utils/try.utils.js";
|
|
7
|
-
export { isKontent404Error } from "./utils/error.utils.js";
|
|
8
9
|
//# 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;AAa/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AA0B/D,OAAO,EAAE,wBAAwB,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAC1F,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 {};
|
|
@@ -0,0 +1,152 @@
|
|
|
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 { getSdkIdHeader } from "../utils/header.utils.js";
|
|
7
|
+
export function getQuery(data) {
|
|
8
|
+
return {
|
|
9
|
+
toPromise: async () => {
|
|
10
|
+
return await resolveQueryAsync(data);
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export function getPagingQuery(data) {
|
|
15
|
+
return {
|
|
16
|
+
...getQuery(data),
|
|
17
|
+
toAllPromise: async () => {
|
|
18
|
+
return await resolvePagingQueryAsync(data);
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export function extractContinuationToken(responseHeaders) {
|
|
23
|
+
return responseHeaders.find((header) => header.name.toLowerCase() === "X-Continuation".toLowerCase())
|
|
24
|
+
?.value;
|
|
25
|
+
}
|
|
26
|
+
function getHttpService(config) {
|
|
27
|
+
return config.httpService ?? getDefaultHttpService();
|
|
28
|
+
}
|
|
29
|
+
function getCombinedRequestHeaders({ requestHeaders, continuationToken, authorizationApiKey, sdkInfo, }) {
|
|
30
|
+
return [
|
|
31
|
+
getSdkIdHeader({
|
|
32
|
+
host: "npmjs.com",
|
|
33
|
+
name: sdkInfo.name,
|
|
34
|
+
version: sdkInfo.version,
|
|
35
|
+
}),
|
|
36
|
+
...requestHeaders,
|
|
37
|
+
...(continuationToken
|
|
38
|
+
? [
|
|
39
|
+
{
|
|
40
|
+
name: "X-Continuation",
|
|
41
|
+
value: continuationToken,
|
|
42
|
+
},
|
|
43
|
+
]
|
|
44
|
+
: []),
|
|
45
|
+
...(authorizationApiKey
|
|
46
|
+
? [
|
|
47
|
+
{
|
|
48
|
+
name: "Authorization",
|
|
49
|
+
value: `Bearer ${authorizationApiKey}`,
|
|
50
|
+
},
|
|
51
|
+
]
|
|
52
|
+
: []),
|
|
53
|
+
];
|
|
54
|
+
}
|
|
55
|
+
async function resolvePagingQueryAsync(data) {
|
|
56
|
+
const responses = [];
|
|
57
|
+
let nextContinuationToken = data.continuationToken;
|
|
58
|
+
while (nextContinuationToken) {
|
|
59
|
+
const { success, response, error } = await getQuery({
|
|
60
|
+
...data,
|
|
61
|
+
continuationToken: nextContinuationToken,
|
|
62
|
+
}).toPromise();
|
|
63
|
+
if (success) {
|
|
64
|
+
responses.push(response);
|
|
65
|
+
if (data.canFetchNextResponse(response)) {
|
|
66
|
+
nextContinuationToken = response.meta.continuationToken;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
nextContinuationToken = undefined;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
return {
|
|
74
|
+
success: false,
|
|
75
|
+
error: error,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (responses.length === 0) {
|
|
80
|
+
return {
|
|
81
|
+
success: false,
|
|
82
|
+
error: {
|
|
83
|
+
reason: "noResponses",
|
|
84
|
+
url: data.url,
|
|
85
|
+
message: "No responses were processed. Expected at least one response to be fetched when using paging queries.",
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
success: true,
|
|
91
|
+
responses: responses,
|
|
92
|
+
lastContinuationToken: responses.at(-1)?.meta.continuationToken ?? "",
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
async function resolveQueryAsync({ config, request, url, extraMetadata, zodSchema, continuationToken, sdkInfo, authorizationApiKey, }) {
|
|
96
|
+
const { success, response, error } = await getHttpService(config).requestAsync({
|
|
97
|
+
...request,
|
|
98
|
+
requestHeaders: getCombinedRequestHeaders({
|
|
99
|
+
requestHeaders: request.requestHeaders ?? [],
|
|
100
|
+
continuationToken,
|
|
101
|
+
authorizationApiKey: authorizationApiKey,
|
|
102
|
+
sdkInfo,
|
|
103
|
+
}),
|
|
104
|
+
});
|
|
105
|
+
if (!success) {
|
|
106
|
+
return {
|
|
107
|
+
success: false,
|
|
108
|
+
error,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
if (config.responseValidation?.enable) {
|
|
112
|
+
const { isValid, error: validationError } = await validateResponseAsync(response.data, zodSchema);
|
|
113
|
+
if (!isValid) {
|
|
114
|
+
return {
|
|
115
|
+
success: false,
|
|
116
|
+
error: {
|
|
117
|
+
message: `Failed to validate response schema for url '${url}'`,
|
|
118
|
+
reason: "validationFailed",
|
|
119
|
+
zodError: validationError,
|
|
120
|
+
response,
|
|
121
|
+
url,
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
const result = {
|
|
127
|
+
success: true,
|
|
128
|
+
response: {
|
|
129
|
+
payload: response.data,
|
|
130
|
+
meta: {
|
|
131
|
+
responseHeaders: response.adapterResponse.responseHeaders,
|
|
132
|
+
status: response.adapterResponse.status,
|
|
133
|
+
continuationToken: extractContinuationToken(response.adapterResponse.responseHeaders),
|
|
134
|
+
...extraMetadata(response),
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
return result;
|
|
139
|
+
}
|
|
140
|
+
async function validateResponseAsync(data, zodSchema) {
|
|
141
|
+
const validateResult = await zodSchema.safeParseAsync(data);
|
|
142
|
+
if (validateResult.success) {
|
|
143
|
+
return {
|
|
144
|
+
isValid: true,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
isValid: false,
|
|
149
|
+
error: validateResult.error,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=sdk-queries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk-queries.js","sourceRoot":"","sources":["../../lib/sdk/sdk-queries.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAIhE,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAW1D,MAAM,UAAU,QAAQ,CACvB,IAAkF;IAElF,OAAO;QACN,SAAS,EAAE,KAAK,IAAI,EAAE;YACrB,OAAO,MAAM,iBAAiB,CAAsC,IAAI,CAAC,CAAC;QAC3E,CAAC;KACD,CAAC;AACH,CAAC;AAED,MAAM,UAAU,cAAc,CAC7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O;YACN,OAAO,EAAE,IAAI;SACb,CAAC;IACH,CAAC;IAED,OAAO;QACN,OAAO,EAAE,KAAK;QACd,KAAK,EAAE,cAAc,CAAC,KAAK;KAC3B,CAAC;AACH,CAAC"}
|
package/dist/sdk-info.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"header.utils.js","sourceRoot":"","sources":["../../lib/utils/header.utils.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,cAAc,CAAC,IAAa;IAC3C,OAAO;QACN,IAAI,EAAE,YAAwC;QAC9C,KAAK,EAAE,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,OAAO,EAAE;KAClD,CAAC;AACH,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,OAA0B;IAClE,MAAM,gBAAgB,GAAG,OAAO,CAAC,IAAI,
|
|
1
|
+
{"version":3,"file":"header.utils.js","sourceRoot":"","sources":["../../lib/utils/header.utils.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,cAAc,CAAC,IAAa;IAC3C,OAAO;QACN,IAAI,EAAE,YAAwC;QAC9C,KAAK,EAAE,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,OAAO,EAAE;KAClD,CAAC;AACH,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,OAA0B;IAClE,MAAM,gBAAgB,GAAG,OAAO,CAAC,IAAI,CACpC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,KAAM,aAA0C,CAAC,WAAW,EAAE,CACnG,CAAC;IAEF,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACvB,OAAO,SAAS,CAAC;IAClB,CAAC;IAED,MAAM,WAAW,GAAG,CAAC,gBAAgB,CAAC,KAAK,CAAC;IAE5C,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,WAAW,CAAC,EAAE,CAAC;QACxC,OAAO,SAAS,CAAC;IAClB,CAAC;IAED,OAAO,WAAW,CAAC;AACpB,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,OAAgB;IAC5C,OAAO,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;QAC3D,IAAI,EAAE,GAAG;QACT,KAAK,EAAE,KAAK;KACZ,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,OAA0B;IACxD,OAAO,OAAO,CAAC,MAAM,CAAU,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAClD,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;QAC1C,OAAO,OAAO,CAAC;IAChB,CAAC,EAAE,IAAI,OAAO,EAAE,CAAC,CAAC;AACnB,CAAC"}
|
package/lib/http/http.service.ts
CHANGED
|
@@ -22,9 +22,10 @@ export function getDefaultHttpService(config?: DefaultHttpServiceConfig): HttpSe
|
|
|
22
22
|
const withUnknownErrorHandlingAsync = async <TResponseData extends JsonValue | Blob, TBodyData extends JsonValue | Blob>({
|
|
23
23
|
url,
|
|
24
24
|
funcAsync,
|
|
25
|
-
}: {
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
}: {
|
|
26
|
+
readonly url: string;
|
|
27
|
+
readonly funcAsync: () => Promise<HttpResponse<TResponseData, TBodyData>>;
|
|
28
|
+
}): Promise<HttpResponse<TResponseData, TBodyData>> => {
|
|
28
29
|
const { success, data, error } = await tryCatchAsync(funcAsync);
|
|
29
30
|
|
|
30
31
|
if (success) {
|
|
@@ -249,7 +250,9 @@ export function getDefaultHttpService(config?: DefaultHttpServiceConfig): HttpSe
|
|
|
249
250
|
});
|
|
250
251
|
},
|
|
251
252
|
|
|
252
|
-
uploadFileAsync: async <TResponseData extends JsonValue>(
|
|
253
|
+
uploadFileAsync: async <TResponseData extends JsonValue>(
|
|
254
|
+
options: UploadFileRequestOptions,
|
|
255
|
+
): Promise<HttpResponse<TResponseData, Blob>> => {
|
|
253
256
|
return await resolveRequestAsync<TResponseData, Blob>({
|
|
254
257
|
options,
|
|
255
258
|
resolveDataAsync: async (response) => {
|
|
@@ -283,8 +286,12 @@ async function getKontentErrorDataAsync(response: AdapterResponse): Promise<Kont
|
|
|
283
286
|
}
|
|
284
287
|
|
|
285
288
|
function getRequestHeaders(headers: readonly Header[] | undefined, body: Blob | JsonValue): readonly Header[] {
|
|
286
|
-
const existingContentTypeHeader = headers?.find(
|
|
287
|
-
|
|
289
|
+
const existingContentTypeHeader = headers?.find(
|
|
290
|
+
(header) => header.name.toLowerCase() === ("Content-Type" satisfies CommonHeaderNames).toLowerCase(),
|
|
291
|
+
);
|
|
292
|
+
const existingSdkVersionHeader = headers?.find(
|
|
293
|
+
(header) => header.name.toLowerCase() === ("X-KC-SDKID" satisfies CommonHeaderNames).toLowerCase(),
|
|
294
|
+
);
|
|
288
295
|
|
|
289
296
|
const contentTypeHeader: Header | undefined = existingContentTypeHeader
|
|
290
297
|
? undefined
|
|
@@ -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
|
/**
|
|
4
5
|
* SDK info for identification of the SDK
|
|
@@ -20,7 +21,9 @@ export type SDKInfo = {
|
|
|
20
21
|
readonly host: LiteralUnion<"npmjs.com">;
|
|
21
22
|
};
|
|
22
23
|
|
|
23
|
-
export type CommonHeaderNames = "Retry-After" | "X-KC-SDKID" | "Authorization" | "Content-Type" | "Content-Length";
|
|
24
|
+
export type CommonHeaderNames = "Retry-After" | "X-KC-SDKID" | "Authorization" | "Content-Type" | "Content-Length" | "X-Continuation";
|
|
25
|
+
|
|
26
|
+
export type ContinuationHeaderName = PickStringLiteral<CommonHeaderNames, "X-Continuation">;
|
|
24
27
|
|
|
25
28
|
export type Header = {
|
|
26
29
|
readonly name: string;
|
|
@@ -1,7 +1,10 @@
|
|
|
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";
|
|
5
|
+
import type { JsonValue } from "./json.models.js";
|
|
3
6
|
|
|
4
|
-
export type ErrorReason = "invalidResponse" | "invalidUrl" | "unknown" | "invalidBody" | "notFound";
|
|
7
|
+
export type ErrorReason = "invalidResponse" | "invalidUrl" | "unknown" | "invalidBody" | "notFound" | "validationFailed" | "noResponses";
|
|
5
8
|
|
|
6
9
|
export type CoreSdkErrorDetails<TReason extends ErrorReason = ErrorReason> = (
|
|
7
10
|
| Details<
|
|
@@ -34,6 +37,21 @@ export type CoreSdkErrorDetails<TReason extends ErrorReason = ErrorReason> = (
|
|
|
34
37
|
readonly originalError: unknown;
|
|
35
38
|
}
|
|
36
39
|
>
|
|
40
|
+
| Details<
|
|
41
|
+
"validationFailed",
|
|
42
|
+
{
|
|
43
|
+
readonly reason: "validationFailed";
|
|
44
|
+
readonly zodError: ZodError;
|
|
45
|
+
readonly response: SuccessfulHttpResponse<JsonValue, JsonValue>;
|
|
46
|
+
readonly url: string;
|
|
47
|
+
}
|
|
48
|
+
>
|
|
49
|
+
| Details<
|
|
50
|
+
"noResponses",
|
|
51
|
+
{
|
|
52
|
+
readonly url: string;
|
|
53
|
+
}
|
|
54
|
+
>
|
|
37
55
|
) & {
|
|
38
56
|
readonly reason: TReason;
|
|
39
57
|
};
|
|
@@ -14,3 +14,8 @@ export type Override<Type, NewType extends { [key in keyof Type]?: NewType[key]
|
|
|
14
14
|
* Represents an empty object type.
|
|
15
15
|
*/
|
|
16
16
|
export type EmptyObject = Record<string, never>;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Picks a string literal type from a union type.
|
|
20
|
+
*/
|
|
21
|
+
export type PickStringLiteral<T extends string, U extends T> = U;
|
package/lib/public_api.ts
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
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
|
-
export { getDefaultHttpService } from "./http/http.service.js";
|
|
4
|
-
export { getSdkIdHeader } from "./utils/header.utils.js";
|
|
5
|
-
export { toRequiredRetryStrategyOptions } from "./utils/retry.utils.js";
|
|
6
|
-
export { tryCatch, tryCatchAsync } from "./utils/try.utils.js";
|
|
7
|
-
export { isKontent404Error } from "./utils/error.utils.js";
|
|
8
|
-
|
|
9
|
-
// Types
|
|
10
3
|
export type {
|
|
11
4
|
AdapterRequestOptions,
|
|
12
5
|
AdapterResponse,
|
|
@@ -19,17 +12,34 @@ export type {
|
|
|
19
12
|
HttpServiceStatus,
|
|
20
13
|
UploadFileRequestOptions,
|
|
21
14
|
} from "./http/http.models.js";
|
|
15
|
+
export { getDefaultHttpService } from "./http/http.service.js";
|
|
22
16
|
export type {
|
|
17
|
+
CommonHeaderNames,
|
|
23
18
|
Header,
|
|
24
19
|
HttpMethod,
|
|
25
20
|
RetryStrategyOptions,
|
|
26
21
|
SDKInfo,
|
|
27
|
-
CommonHeaderNames,
|
|
28
22
|
} from "./models/core.models.js";
|
|
29
23
|
export type {
|
|
30
24
|
CoreSdkError,
|
|
31
|
-
ErrorReason,
|
|
32
25
|
CoreSdkErrorDetails,
|
|
26
|
+
ErrorReason,
|
|
33
27
|
} from "./models/error.models.js";
|
|
34
28
|
export type { JsonArray, JsonObject, JsonValue } from "./models/json.models.js";
|
|
35
29
|
export type { EmptyObject, Override, Prettify } from "./models/utility.models.js";
|
|
30
|
+
export type {
|
|
31
|
+
CoreResponse,
|
|
32
|
+
CoreResponseMeta,
|
|
33
|
+
CoreSdkConfig,
|
|
34
|
+
PagingQuery,
|
|
35
|
+
PagingQueryResult,
|
|
36
|
+
Query,
|
|
37
|
+
QueryResult,
|
|
38
|
+
ResultOfSuccessfulQuery,
|
|
39
|
+
SuccessfulHttpResponse,
|
|
40
|
+
} from "./sdk/sdk-models.js";
|
|
41
|
+
export { extractContinuationToken, getPagingQuery, getQuery } from "./sdk/sdk-queries.js";
|
|
42
|
+
export { isKontent404Error } from "./utils/error.utils.js";
|
|
43
|
+
export { getSdkIdHeader } from "./utils/header.utils.js";
|
|
44
|
+
export { toRequiredRetryStrategyOptions } from "./utils/retry.utils.js";
|
|
45
|
+
export { tryCatch, tryCatchAsync } from "./utils/try.utils.js";
|
|
@@ -0,0 +1,85 @@
|
|
|
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
|
+
|
|
6
|
+
import type { AdapterResponse, HttpResponse, HttpService } from "../http/http.models.js";
|
|
7
|
+
import type { CoreSdkError } from "../models/error.models.js";
|
|
8
|
+
import type { JsonValue } from "../models/json.models.js";
|
|
9
|
+
import type { Prettify } from "../models/utility.models.js";
|
|
10
|
+
|
|
11
|
+
export type CoreResponseMeta<TExtraMetadata = unknown> = Pick<AdapterResponse, "status" | "responseHeaders"> & {
|
|
12
|
+
readonly continuationToken?: string;
|
|
13
|
+
} & TExtraMetadata;
|
|
14
|
+
|
|
15
|
+
export type CoreResponse<TPayload, TExtraMetadata = unknown> = {
|
|
16
|
+
readonly payload: TPayload;
|
|
17
|
+
readonly meta: CoreResponseMeta<TExtraMetadata>;
|
|
18
|
+
};
|
|
19
|
+
export type CoreSdkConfig = {
|
|
20
|
+
/**
|
|
21
|
+
* The HTTP service to use for the request. If not provided, the default HTTP service will be used.
|
|
22
|
+
*
|
|
23
|
+
* You may provide your own HTTP service implementation to customize the request behavior.
|
|
24
|
+
*
|
|
25
|
+
* See https://github.com/kontent-ai/core-sdk-js for more information regarding the HTTP service customization.
|
|
26
|
+
*/
|
|
27
|
+
readonly httpService?: HttpService;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The base URL to use for the request. If not provided, the default base URL will be used.
|
|
31
|
+
*
|
|
32
|
+
* If provided, it will override the default base URL based on selected API mode.
|
|
33
|
+
*/
|
|
34
|
+
readonly baseUrl?: string;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Configuration for response validation.
|
|
38
|
+
*/
|
|
39
|
+
readonly responseValidation?: {
|
|
40
|
+
/**
|
|
41
|
+
* When enabled, the response payload will be validated against the expected Zod schema from which the types
|
|
42
|
+
* this library are based on. This ensures that you are working with the correct data types.
|
|
43
|
+
*
|
|
44
|
+
* @default false
|
|
45
|
+
*/
|
|
46
|
+
readonly enable: boolean;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export type Query<TPayload, TExtraData = unknown> = {
|
|
51
|
+
toUrl(): string;
|
|
52
|
+
toPromise(): Promise<QueryResult<CoreResponse<TPayload, TExtraData>>>;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export type PagingQuery<TPayload, TExtraData = unknown> = Query<TPayload, TExtraData> & {
|
|
56
|
+
toAllPromise(): Promise<PagingQueryResult<CoreResponse<TPayload, TExtraData>>>;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export type SuccessfulHttpResponse<TPayload extends JsonValue, TBodyData extends JsonValue> = Prettify<
|
|
60
|
+
Extract<HttpResponse<TPayload, TBodyData>, { readonly success: true }>["response"]
|
|
61
|
+
>;
|
|
62
|
+
|
|
63
|
+
export type ResultOfSuccessfulQuery<TQuery extends Query<unknown>> = Extract<
|
|
64
|
+
Awaited<ReturnType<TQuery["toPromise"]>>,
|
|
65
|
+
{ readonly success: true }
|
|
66
|
+
>["response"];
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* A nomadic result type that represents a success or failure of an operation.
|
|
70
|
+
*
|
|
71
|
+
* Ensures that consumers of this library handle both success and failure cases.
|
|
72
|
+
*/
|
|
73
|
+
export type QueryResult<TResponse> = (Success & { readonly response: TResponse }) | (Failure & { readonly response?: never });
|
|
74
|
+
export type PagingQueryResult<TResponse> =
|
|
75
|
+
| (Success & { readonly responses: TResponse[]; readonly lastContinuationToken: string })
|
|
76
|
+
| (Failure & { readonly responses?: never; readonly lastContinuationToken?: never });
|
|
77
|
+
|
|
78
|
+
type Success = {
|
|
79
|
+
readonly success: true;
|
|
80
|
+
readonly error?: never;
|
|
81
|
+
};
|
|
82
|
+
type Failure = {
|
|
83
|
+
readonly success: false;
|
|
84
|
+
readonly error: CoreSdkError;
|
|
85
|
+
};
|
|
@@ -0,0 +1,232 @@
|
|
|
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
|
+
|
|
6
|
+
import type { ZodError, ZodType } from "zod";
|
|
7
|
+
import type { HttpService } from "../http/http.models.js";
|
|
8
|
+
import { getDefaultHttpService } from "../http/http.service.js";
|
|
9
|
+
import type { CommonHeaderNames, ContinuationHeaderName, Header, SDKInfo } from "../models/core.models.js";
|
|
10
|
+
import type { JsonValue } from "../models/json.models.js";
|
|
11
|
+
import type { EmptyObject } from "../models/utility.models.js";
|
|
12
|
+
import { getSdkIdHeader } from "../utils/header.utils.js";
|
|
13
|
+
import type { CoreResponse, CoreSdkConfig, PagingQuery, Query, SuccessfulHttpResponse } from "./sdk-models.js";
|
|
14
|
+
|
|
15
|
+
type ResolveToPromiseQuery<TPayload extends JsonValue, TExtraMetadata = EmptyObject> = ReturnType<
|
|
16
|
+
Pick<Query<TPayload, TExtraMetadata>, "toPromise">["toPromise"]
|
|
17
|
+
>;
|
|
18
|
+
|
|
19
|
+
type ResolveToAllPromiseQuery<TPayload extends JsonValue, TExtraMetadata = EmptyObject> = ReturnType<
|
|
20
|
+
Pick<PagingQuery<TPayload, TExtraMetadata>, "toAllPromise">["toAllPromise"]
|
|
21
|
+
>;
|
|
22
|
+
|
|
23
|
+
export function getQuery<TPayload extends JsonValue, TBodyData extends JsonValue, TExtraMetadata>(
|
|
24
|
+
data: Parameters<typeof resolveQueryAsync<TPayload, TBodyData, TExtraMetadata>>[0],
|
|
25
|
+
): Pick<Query<TPayload, TExtraMetadata>, "toPromise"> {
|
|
26
|
+
return {
|
|
27
|
+
toPromise: async () => {
|
|
28
|
+
return await resolveQueryAsync<TPayload, TBodyData, TExtraMetadata>(data);
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function getPagingQuery<TPayload extends JsonValue, TBodyData extends JsonValue, TExtraMetadata = EmptyObject>(
|
|
34
|
+
data: Parameters<typeof resolveQueryAsync<TPayload, TBodyData, TExtraMetadata>>[0] & {
|
|
35
|
+
readonly canFetchNextResponse: (response: CoreResponse<TPayload, TExtraMetadata>) => boolean;
|
|
36
|
+
readonly continuationToken: string;
|
|
37
|
+
},
|
|
38
|
+
): Pick<PagingQuery<TPayload, TExtraMetadata>, "toPromise" | "toAllPromise"> {
|
|
39
|
+
return {
|
|
40
|
+
...getQuery<TPayload, TBodyData, TExtraMetadata>(data),
|
|
41
|
+
toAllPromise: async () => {
|
|
42
|
+
return await resolvePagingQueryAsync<TPayload, TBodyData, TExtraMetadata>(data);
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function extractContinuationToken(responseHeaders: readonly Header[]): string | undefined {
|
|
48
|
+
return responseHeaders.find((header) => header.name.toLowerCase() === ("X-Continuation" satisfies ContinuationHeaderName).toLowerCase())
|
|
49
|
+
?.value;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function getHttpService(config: CoreSdkConfig) {
|
|
53
|
+
return config.httpService ?? getDefaultHttpService();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function getCombinedRequestHeaders({
|
|
57
|
+
requestHeaders,
|
|
58
|
+
continuationToken,
|
|
59
|
+
authorizationApiKey,
|
|
60
|
+
sdkInfo,
|
|
61
|
+
}: {
|
|
62
|
+
readonly requestHeaders: readonly Header[];
|
|
63
|
+
readonly continuationToken: string | undefined;
|
|
64
|
+
readonly authorizationApiKey: string | undefined;
|
|
65
|
+
readonly sdkInfo: SDKInfo;
|
|
66
|
+
}): readonly Header[] {
|
|
67
|
+
return [
|
|
68
|
+
getSdkIdHeader({
|
|
69
|
+
host: "npmjs.com",
|
|
70
|
+
name: sdkInfo.name,
|
|
71
|
+
version: sdkInfo.version,
|
|
72
|
+
}),
|
|
73
|
+
...requestHeaders,
|
|
74
|
+
...(continuationToken
|
|
75
|
+
? [
|
|
76
|
+
{
|
|
77
|
+
name: "X-Continuation" satisfies CommonHeaderNames,
|
|
78
|
+
value: continuationToken,
|
|
79
|
+
},
|
|
80
|
+
]
|
|
81
|
+
: []),
|
|
82
|
+
...(authorizationApiKey
|
|
83
|
+
? [
|
|
84
|
+
{
|
|
85
|
+
name: "Authorization" satisfies CommonHeaderNames,
|
|
86
|
+
value: `Bearer ${authorizationApiKey}`,
|
|
87
|
+
},
|
|
88
|
+
]
|
|
89
|
+
: []),
|
|
90
|
+
];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async function resolvePagingQueryAsync<TPayload extends JsonValue, TBodyData extends JsonValue, TExtraMetadata = EmptyObject>(
|
|
94
|
+
data: Parameters<typeof getPagingQuery<TPayload, TBodyData, TExtraMetadata>>[0],
|
|
95
|
+
): Promise<ResolveToAllPromiseQuery<TPayload, TExtraMetadata>> {
|
|
96
|
+
const responses: CoreResponse<TPayload, TExtraMetadata>[] = [];
|
|
97
|
+
let nextContinuationToken: string | undefined = data.continuationToken;
|
|
98
|
+
|
|
99
|
+
while (nextContinuationToken) {
|
|
100
|
+
const { success, response, error } = await getQuery<TPayload, TBodyData, TExtraMetadata>({
|
|
101
|
+
...data,
|
|
102
|
+
continuationToken: nextContinuationToken,
|
|
103
|
+
}).toPromise();
|
|
104
|
+
|
|
105
|
+
if (success) {
|
|
106
|
+
responses.push(response);
|
|
107
|
+
|
|
108
|
+
if (data.canFetchNextResponse(response)) {
|
|
109
|
+
nextContinuationToken = response.meta.continuationToken;
|
|
110
|
+
} else {
|
|
111
|
+
nextContinuationToken = undefined;
|
|
112
|
+
}
|
|
113
|
+
} else {
|
|
114
|
+
return {
|
|
115
|
+
success: false,
|
|
116
|
+
error: error,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (responses.length === 0) {
|
|
122
|
+
return {
|
|
123
|
+
success: false,
|
|
124
|
+
error: {
|
|
125
|
+
reason: "noResponses",
|
|
126
|
+
url: data.url,
|
|
127
|
+
message: "No responses were processed. Expected at least one response to be fetched when using paging queries.",
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return {
|
|
133
|
+
success: true,
|
|
134
|
+
responses: responses,
|
|
135
|
+
lastContinuationToken: responses.at(-1)?.meta.continuationToken ?? "",
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
async function resolveQueryAsync<TPayload extends JsonValue, TBodyData extends JsonValue, TExtraMetadata>({
|
|
140
|
+
config,
|
|
141
|
+
request,
|
|
142
|
+
url,
|
|
143
|
+
extraMetadata,
|
|
144
|
+
zodSchema,
|
|
145
|
+
continuationToken,
|
|
146
|
+
sdkInfo,
|
|
147
|
+
authorizationApiKey,
|
|
148
|
+
}: {
|
|
149
|
+
readonly continuationToken: string | undefined;
|
|
150
|
+
readonly request: Parameters<HttpService["requestAsync"]>[number] & { readonly body: TBodyData };
|
|
151
|
+
readonly extraMetadata: (response: SuccessfulHttpResponse<TPayload, TBodyData>) => TExtraMetadata;
|
|
152
|
+
readonly config: CoreSdkConfig;
|
|
153
|
+
readonly url: string;
|
|
154
|
+
readonly zodSchema: ZodType<TPayload>;
|
|
155
|
+
readonly sdkInfo: SDKInfo;
|
|
156
|
+
readonly authorizationApiKey: string | undefined;
|
|
157
|
+
}): ResolveToPromiseQuery<TPayload, TExtraMetadata> {
|
|
158
|
+
const { success, response, error } = await getHttpService(config).requestAsync<TPayload, TBodyData>({
|
|
159
|
+
...request,
|
|
160
|
+
requestHeaders: getCombinedRequestHeaders({
|
|
161
|
+
requestHeaders: request.requestHeaders ?? [],
|
|
162
|
+
continuationToken,
|
|
163
|
+
authorizationApiKey: authorizationApiKey,
|
|
164
|
+
sdkInfo,
|
|
165
|
+
}),
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
if (!success) {
|
|
169
|
+
return {
|
|
170
|
+
success: false,
|
|
171
|
+
error,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (config.responseValidation?.enable) {
|
|
176
|
+
const { isValid, error: validationError } = await validateResponseAsync(response.data, zodSchema);
|
|
177
|
+
if (!isValid) {
|
|
178
|
+
return {
|
|
179
|
+
success: false,
|
|
180
|
+
error: {
|
|
181
|
+
message: `Failed to validate response schema for url '${url}'`,
|
|
182
|
+
reason: "validationFailed",
|
|
183
|
+
zodError: validationError,
|
|
184
|
+
response,
|
|
185
|
+
url,
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const result: Awaited<ResolveToPromiseQuery<TPayload, TExtraMetadata>> = {
|
|
192
|
+
success: true,
|
|
193
|
+
response: {
|
|
194
|
+
payload: response.data,
|
|
195
|
+
meta: {
|
|
196
|
+
responseHeaders: response.adapterResponse.responseHeaders,
|
|
197
|
+
status: response.adapterResponse.status,
|
|
198
|
+
continuationToken: extractContinuationToken(response.adapterResponse.responseHeaders),
|
|
199
|
+
...extraMetadata(response),
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
return result;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
async function validateResponseAsync<TPayload extends JsonValue>(
|
|
208
|
+
data: TPayload,
|
|
209
|
+
zodSchema: ZodType<TPayload>,
|
|
210
|
+
): Promise<
|
|
211
|
+
| {
|
|
212
|
+
readonly isValid: true;
|
|
213
|
+
readonly error?: never;
|
|
214
|
+
}
|
|
215
|
+
| {
|
|
216
|
+
readonly isValid: false;
|
|
217
|
+
readonly error: ZodError;
|
|
218
|
+
}
|
|
219
|
+
> {
|
|
220
|
+
const validateResult = await zodSchema.safeParseAsync(data);
|
|
221
|
+
|
|
222
|
+
if (validateResult.success) {
|
|
223
|
+
return {
|
|
224
|
+
isValid: true,
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return {
|
|
229
|
+
isValid: false,
|
|
230
|
+
error: validateResult.error,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
@@ -8,7 +8,9 @@ export function getSdkIdHeader(info: SDKInfo): Header {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export function getRetryAfterHeaderValue(headers: readonly Header[]): number | undefined {
|
|
11
|
-
const retryAfterHeader = headers.find(
|
|
11
|
+
const retryAfterHeader = headers.find(
|
|
12
|
+
(header) => header.name.toLowerCase() === ("Retry-After" satisfies CommonHeaderNames).toLowerCase(),
|
|
13
|
+
);
|
|
12
14
|
|
|
13
15
|
if (!retryAfterHeader) {
|
|
14
16
|
return undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kontent-ai/core-sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "12.0.0-preview.2",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/kontent-ai/kontent-core-js"
|
|
@@ -9,7 +9,11 @@
|
|
|
9
9
|
"author": "richard sustek",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"description": "Core package with shared / common functionality for Kontent.ai SDKs",
|
|
12
|
-
"keywords": [
|
|
12
|
+
"keywords": [
|
|
13
|
+
"Kontent.ai",
|
|
14
|
+
"Kontent AI",
|
|
15
|
+
"Kontent SDK Core"
|
|
16
|
+
],
|
|
13
17
|
"engines": {
|
|
14
18
|
"node": ">= 22"
|
|
15
19
|
},
|
|
@@ -30,28 +34,32 @@
|
|
|
30
34
|
"type": "module",
|
|
31
35
|
"scripts": {
|
|
32
36
|
"prepublishOnly": "npm run build",
|
|
33
|
-
"build": "npm run
|
|
37
|
+
"build": "npm run lint && npm run clean && tsc --p tsconfig.build.json && npm run update:version",
|
|
34
38
|
"test": "npm run test:unit && npm run test:integration",
|
|
35
39
|
"test:unit": "vitest run --config=vitest-unit.config.ts",
|
|
36
40
|
"test:integration": "vitest run --config=vitest-integration.config.ts",
|
|
37
|
-
"
|
|
41
|
+
"lint": "npm run biome:check && npm run eslint",
|
|
42
|
+
"eslint": "eslint ",
|
|
38
43
|
"biome:check": "biome check",
|
|
39
44
|
"biome:fix": "biome check --write",
|
|
40
45
|
"biome:fix:unsafe": "biome check --write --unsafe",
|
|
41
46
|
"clean": "tsx scripts/clean.ts",
|
|
42
47
|
"update:version": "tsx ./scripts/update-version.ts"
|
|
43
48
|
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"zod": "4.3.5"
|
|
51
|
+
},
|
|
44
52
|
"devDependencies": {
|
|
45
|
-
"@kontent-ai/biome-config": "0.
|
|
46
|
-
"@kontent-ai/eslint-config": "2.
|
|
47
|
-
"@typescript-eslint/eslint-plugin": "8.
|
|
48
|
-
"eslint": "9.
|
|
49
|
-
"@biomejs/biome": "
|
|
50
|
-
"@types/node": "
|
|
51
|
-
"chalk": "5.
|
|
52
|
-
"typescript": "5.
|
|
53
|
-
"vitest": "
|
|
54
|
-
"dotenv-cli": "
|
|
55
|
-
"tsx": "4.
|
|
53
|
+
"@kontent-ai/biome-config": "0.5.1",
|
|
54
|
+
"@kontent-ai/eslint-config": "2.2.1",
|
|
55
|
+
"@typescript-eslint/eslint-plugin": "8.51.0",
|
|
56
|
+
"eslint": "9.39.2",
|
|
57
|
+
"@biomejs/biome": "2.3.11",
|
|
58
|
+
"@types/node": "25.0.3",
|
|
59
|
+
"chalk": "5.6.2",
|
|
60
|
+
"typescript": "5.9.3",
|
|
61
|
+
"vitest": "4.0.16",
|
|
62
|
+
"dotenv-cli": "11.0.0",
|
|
63
|
+
"tsx": "4.21.0"
|
|
56
64
|
}
|
|
57
65
|
}
|