@kontent-ai/core-sdk 11.0.0-5 → 11.0.0-7
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/devkit/devkit.models.d.ts +1 -1
- package/dist/devkit/script.utils.js +2 -2
- package/dist/devkit/script.utils.js.map +1 -1
- package/dist/devkit/test.utils.d.ts +4 -4
- package/dist/devkit/test.utils.js +7 -7
- package/dist/devkit_api.d.ts +4 -7
- package/dist/devkit_api.js +3 -2
- package/dist/devkit_api.js.map +1 -1
- package/dist/http/http.adapter.d.ts +1 -1
- package/dist/http/http.adapter.js +5 -5
- package/dist/http/http.adapter.js.map +1 -1
- package/dist/http/http.models.d.ts +8 -8
- package/dist/http/http.service.d.ts +1 -1
- package/dist/http/http.service.js +22 -22
- package/dist/http/http.service.js.map +1 -1
- package/dist/models/core.models.d.ts +4 -4
- package/dist/models/error.models.d.ts +7 -7
- package/dist/models/json.models.d.ts +2 -1
- package/dist/models/utility.models.d.ts +16 -0
- package/dist/models/utility.models.js +2 -0
- package/dist/models/utility.models.js.map +1 -0
- package/dist/public_api.d.ts +10 -9
- package/dist/public_api.js +6 -8
- package/dist/public_api.js.map +1 -1
- package/dist/sdk-info.js +3 -3
- package/dist/utils/error.utils.d.ts +2 -2
- package/dist/utils/error.utils.js +6 -6
- package/dist/utils/error.utils.js.map +1 -1
- package/dist/utils/header.utils.d.ts +1 -1
- package/dist/utils/header.utils.js +2 -2
- package/dist/utils/header.utils.js.map +1 -1
- package/dist/utils/retry.utils.d.ts +3 -3
- package/dist/utils/retry.utils.js +3 -3
- package/dist/utils/sdk-version.utils.js +5 -5
- package/dist/utils/sdk-version.utils.js.map +1 -1
- package/lib/devkit/devkit.models.ts +6 -6
- package/lib/devkit/script.utils.ts +12 -12
- package/lib/devkit/test.utils.ts +12 -12
- package/lib/devkit_api.ts +5 -7
- package/lib/http/http.adapter.ts +38 -38
- package/lib/http/http.models.ts +8 -8
- package/lib/http/http.service.ts +26 -26
- package/lib/models/core.models.ts +4 -4
- package/lib/models/error.models.ts +59 -59
- package/lib/models/json.models.ts +3 -1
- package/lib/models/utility.models.ts +16 -0
- package/lib/public_api.ts +14 -13
- package/lib/sdk-info.ts +3 -3
- package/lib/utils/core.utils.ts +3 -3
- package/lib/utils/error.utils.ts +8 -8
- package/lib/utils/header.utils.ts +3 -3
- package/lib/utils/retry.utils.ts +11 -11
- package/lib/utils/sdk-version.utils.ts +16 -16
- package/lib/utils/try.utils.ts +30 -30
- package/package.json +14 -11
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"script.utils.js","sourceRoot":"","sources":["../../lib/devkit/script.utils.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"script.utils.js","sourceRoot":"","sources":["../../lib/devkit/script.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,UAAU,qBAAqB,CAAC,IAAY;IACjD,OAAO,CAAC,GAAG,CAAC,6BAA6B,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAChE,MAAM,CAAC,IAAI,EAAE;QACZ,SAAS,EAAE,IAAI;QACf,KAAK,EAAE,IAAI;KACX,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,CAAC,WAAW,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;AACpE,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { Mock } from
|
|
2
|
-
import type { HttpServiceStatus } from
|
|
3
|
-
import type { JsonValue } from
|
|
4
|
-
import type { Header } from
|
|
1
|
+
import type { Mock } from "vitest";
|
|
2
|
+
import type { HttpServiceStatus } from "../http/http.models.js";
|
|
3
|
+
import type { JsonValue } from "../models/json.models.js";
|
|
4
|
+
import type { Header } from "../public_api.js";
|
|
5
5
|
export declare function getFetchJsonMock<TResponseData extends JsonValue>({ json, status, responseHeaders, }: {
|
|
6
6
|
readonly json: TResponseData;
|
|
7
7
|
readonly status: HttpServiceStatus;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { vi } from
|
|
2
|
-
import { isNotUndefined } from
|
|
3
|
-
import { toFetchHeaders } from
|
|
1
|
+
import { vi } from "vitest";
|
|
2
|
+
import { isNotUndefined } from "../utils/core.utils.js";
|
|
3
|
+
import { toFetchHeaders } from "../utils/header.utils.js";
|
|
4
4
|
export function getFetchJsonMock({ json, status, responseHeaders, }) {
|
|
5
5
|
return getFetchMock({
|
|
6
6
|
status,
|
|
@@ -18,15 +18,15 @@ export function getFetchBlobMock({ blob, status, responseHeaders, }) {
|
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
export function getFakeBlob() {
|
|
21
|
-
return new Blob([
|
|
21
|
+
return new Blob(["x"], { type: "text/plain" });
|
|
22
22
|
}
|
|
23
23
|
function getFetchMock({ json, blob, status, responseHeaders, }) {
|
|
24
24
|
return vi.fn(() => {
|
|
25
|
-
const contentTypeHeader = responseHeaders.find((m) => m.name.toLowerCase() ===
|
|
25
|
+
const contentTypeHeader = responseHeaders.find((m) => m.name.toLowerCase() === "Content-Type".toLowerCase())
|
|
26
26
|
? undefined
|
|
27
27
|
: {
|
|
28
|
-
name:
|
|
29
|
-
value:
|
|
28
|
+
name: "Content-Type",
|
|
29
|
+
value: "application/json",
|
|
30
30
|
};
|
|
31
31
|
return Promise.resolve({
|
|
32
32
|
// only implement the methods we need, ignore the rest
|
package/dist/devkit_api.d.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export type {
|
|
5
|
-
export { deleteFolderRecursive } from './devkit/script.utils.js';
|
|
6
|
-
export type { getFakeBlob, getFetchBlobMock, getFetchJsonMock } from './devkit/test.utils.js';
|
|
7
|
-
export { replaceSdkVersionPlaceholder } from './utils/sdk-version.utils.js';
|
|
1
|
+
export { deleteFolderRecursive } from "./devkit/script.utils.js";
|
|
2
|
+
export { replaceSdkVersionPlaceholder } from "./utils/sdk-version.utils.js";
|
|
3
|
+
export type { FetchResponse } from "./devkit/devkit.models.js";
|
|
4
|
+
export type { getFakeBlob, getFetchBlobMock, getFetchJsonMock } from "./devkit/test.utils.js";
|
package/dist/devkit_api.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
1
|
+
// biome-ignore lint/performance/noBarrelFile: One barrel for the Devkit API is fine
|
|
2
|
+
export { deleteFolderRecursive } from "./devkit/script.utils.js";
|
|
3
|
+
export { replaceSdkVersionPlaceholder } from "./utils/sdk-version.utils.js";
|
|
3
4
|
//# sourceMappingURL=devkit_api.js.map
|
package/dist/devkit_api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devkit_api.js","sourceRoot":"","sources":["../lib/devkit_api.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"devkit_api.js","sourceRoot":"","sources":["../lib/devkit_api.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,4BAA4B,EAAE,MAAM,8BAA8B,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { HttpAdapter } from
|
|
1
|
+
import type { HttpAdapter } from "./http.models.js";
|
|
2
2
|
export declare function getDefaultHttpAdapter(): HttpAdapter;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { toFetchHeaders, toSdkHeaders } from
|
|
1
|
+
import { toFetchHeaders, toSdkHeaders } from "../utils/header.utils.js";
|
|
2
2
|
export function getDefaultHttpAdapter() {
|
|
3
3
|
return {
|
|
4
4
|
requestAsync: async (options) => {
|
|
5
5
|
const response = await fetch(options.url, {
|
|
6
6
|
method: options.method,
|
|
7
|
-
headers: toFetchHeaders(options
|
|
7
|
+
headers: toFetchHeaders(options.requestHeaders ?? []),
|
|
8
8
|
body: options.body,
|
|
9
9
|
});
|
|
10
10
|
const sdkResponseHeaders = toSdkHeaders(response.headers);
|
|
@@ -16,9 +16,9 @@ export function getDefaultHttpAdapter() {
|
|
|
16
16
|
toBlobAsync: async () => await response.blob(),
|
|
17
17
|
toJsonAsync: async () => {
|
|
18
18
|
const contentTypeResponseHeader = sdkResponseHeaders
|
|
19
|
-
.find((m) => m.name.toLowerCase() ===
|
|
20
|
-
?.value
|
|
21
|
-
if (contentTypeResponseHeader?.includes(
|
|
19
|
+
.find((m) => m.name.toLowerCase() === "Content-Type".toLowerCase())
|
|
20
|
+
?.value.toLowerCase();
|
|
21
|
+
if (contentTypeResponseHeader?.includes("application/json")) {
|
|
22
22
|
// Includes instead of equap due to the fact that the header value can be 'application/json; charset=utf-8' or similar
|
|
23
23
|
return (await response.json());
|
|
24
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.adapter.js","sourceRoot":"","sources":["../../lib/http/http.adapter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAGxE,MAAM,UAAU,qBAAqB;IACpC,OAAO;QACN,YAAY,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;YAC/B,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE;gBACzC,MAAM,EAAE,OAAO,CAAC,MAAM;gBACtB,OAAO,EAAE,cAAc,CAAC,OAAO,
|
|
1
|
+
{"version":3,"file":"http.adapter.js","sourceRoot":"","sources":["../../lib/http/http.adapter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAGxE,MAAM,UAAU,qBAAqB;IACpC,OAAO;QACN,YAAY,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;YAC/B,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE;gBACzC,MAAM,EAAE,OAAO,CAAC,MAAM;gBACtB,OAAO,EAAE,cAAc,CAAC,OAAO,CAAC,cAAc,IAAI,EAAE,CAAC;gBACrD,IAAI,EAAE,OAAO,CAAC,IAAI;aAClB,CAAC,CAAC;YAEH,MAAM,kBAAkB,GAAG,YAAY,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;YAE1D,OAAO;gBACN,eAAe,EAAE,QAAQ,CAAC,EAAE;gBAC5B,eAAe,EAAE,kBAAkB;gBACnC,MAAM,EAAE,QAAQ,CAAC,MAAM;gBACvB,UAAU,EAAE,QAAQ,CAAC,UAAU;gBAC/B,WAAW,EAAE,KAAK,IAAI,EAAE,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE;gBAC9C,WAAW,EAAE,KAAK,IAAI,EAAE;oBACvB,MAAM,yBAAyB,GAAG,kBAAkB;yBAClD,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,KAAM,cAA2C,CAAC,WAAW,EAAE,CAAC;wBACjG,EAAE,KAAK,CAAC,WAAW,EAAE,CAAC;oBAEvB,IAAI,yBAAyB,EAAE,QAAQ,CAAC,kBAAkB,CAAC,EAAE,CAAC;wBAC7D,sHAAsH;wBACtH,OAAO,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAc,CAAC;oBAC7C,CAAC;oBAED,OAAO,IAAI,CAAC;gBACb,CAAC;aACD,CAAC;QACH,CAAC;KACD,CAAC;AACH,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { Header, HttpMethod, LiteralUnionNumber, RetryStrategyOptions } from
|
|
2
|
-
import type { CoreSdkError } from
|
|
3
|
-
import type { JsonValue } from
|
|
4
|
-
import type { Result } from
|
|
1
|
+
import type { Header, HttpMethod, LiteralUnionNumber, RetryStrategyOptions } from "../models/core.models.js";
|
|
2
|
+
import type { CoreSdkError } from "../models/error.models.js";
|
|
3
|
+
import type { JsonValue } from "../models/json.models.js";
|
|
4
|
+
import type { Result } from "../utils/try.utils.js";
|
|
5
5
|
/**
|
|
6
6
|
* Helper status codes for the HTTP service.
|
|
7
7
|
* It can be any valid number status code as this type only serves as a helper.
|
|
@@ -26,7 +26,7 @@ export type HttpResponse<TResponseData extends JsonValue | Blob, TBodyData exten
|
|
|
26
26
|
readonly body: TBodyData;
|
|
27
27
|
readonly method: HttpMethod;
|
|
28
28
|
readonly requestHeaders: readonly Header[];
|
|
29
|
-
readonly adapterResponse: Omit<AdapterResponse,
|
|
29
|
+
readonly adapterResponse: Omit<AdapterResponse, "toJsonAsync" | "toBlobAsync">;
|
|
30
30
|
}, CoreSdkError>;
|
|
31
31
|
export type ExecuteRequestOptions<TBodyData extends JsonValue | Blob> = {
|
|
32
32
|
readonly url: string;
|
|
@@ -34,10 +34,10 @@ export type ExecuteRequestOptions<TBodyData extends JsonValue | Blob> = {
|
|
|
34
34
|
readonly body: TBodyData;
|
|
35
35
|
readonly requestHeaders?: readonly Header[];
|
|
36
36
|
};
|
|
37
|
-
export type UploadFileRequestOptions = Omit<ExecuteRequestOptions<Blob>,
|
|
38
|
-
readonly method: Extract<HttpMethod,
|
|
37
|
+
export type UploadFileRequestOptions = Omit<ExecuteRequestOptions<Blob>, "method"> & {
|
|
38
|
+
readonly method: Extract<HttpMethod, "POST" | "PUT" | "PATCH">;
|
|
39
39
|
};
|
|
40
|
-
export type DownloadFileRequestOptions = Pick<ExecuteRequestOptions<Blob>,
|
|
40
|
+
export type DownloadFileRequestOptions = Pick<ExecuteRequestOptions<Blob>, "url" | "requestHeaders">;
|
|
41
41
|
/**
|
|
42
42
|
* Represents the HTTP service used for making requests to the Kontent.ai API.
|
|
43
43
|
*
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { DefaultHttpServiceConfig, HttpService } from
|
|
1
|
+
import type { DefaultHttpServiceConfig, HttpService } from "./http.models.js";
|
|
2
2
|
export declare function getDefaultHttpService(config?: DefaultHttpServiceConfig): HttpService;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { sdkInfo } from
|
|
2
|
-
import { isNotUndefined } from
|
|
3
|
-
import { getDefaultErrorMessage } from
|
|
4
|
-
import { getSdkIdHeader } from
|
|
5
|
-
import { runWithRetryAsync, toRequiredRetryStrategyOptions } from
|
|
6
|
-
import { tryCatch } from
|
|
7
|
-
import { getDefaultHttpAdapter } from
|
|
1
|
+
import { sdkInfo } from "../sdk-info.js";
|
|
2
|
+
import { isNotUndefined } from "../utils/core.utils.js";
|
|
3
|
+
import { getDefaultErrorMessage } from "../utils/error.utils.js";
|
|
4
|
+
import { getSdkIdHeader } from "../utils/header.utils.js";
|
|
5
|
+
import { runWithRetryAsync, toRequiredRetryStrategyOptions } from "../utils/retry.utils.js";
|
|
6
|
+
import { tryCatch } from "../utils/try.utils.js";
|
|
7
|
+
import { getDefaultHttpAdapter } from "./http.adapter.js";
|
|
8
8
|
export function getDefaultHttpService(config) {
|
|
9
9
|
const resolveRequestAsync = async ({ options, resolveDataAsync, }) => {
|
|
10
10
|
const adapter = config?.adapter ?? getDefaultHttpAdapter();
|
|
11
11
|
const getCombinedRequestHeaders = () => {
|
|
12
|
-
return getRequestHeaders([...(config?.requestHeaders ?? []), ...(options
|
|
12
|
+
return getRequestHeaders([...(config?.requestHeaders ?? []), ...(options.requestHeaders ?? [])], options.body);
|
|
13
13
|
};
|
|
14
14
|
const getRequestBody = () => {
|
|
15
15
|
if (options.body === null) {
|
|
@@ -29,10 +29,10 @@ export function getDefaultHttpService(config) {
|
|
|
29
29
|
return {
|
|
30
30
|
success: false,
|
|
31
31
|
error: {
|
|
32
|
-
message:
|
|
32
|
+
message: "Failed to stringify body of request.",
|
|
33
33
|
url: options.url,
|
|
34
34
|
details: {
|
|
35
|
-
type:
|
|
35
|
+
type: "invalidBody",
|
|
36
36
|
error: error,
|
|
37
37
|
},
|
|
38
38
|
},
|
|
@@ -52,7 +52,7 @@ export function getDefaultHttpService(config) {
|
|
|
52
52
|
message: `Failed to parse url '${options.url}'.`,
|
|
53
53
|
url: options.url,
|
|
54
54
|
details: {
|
|
55
|
-
type:
|
|
55
|
+
type: "invalidUrl",
|
|
56
56
|
error,
|
|
57
57
|
},
|
|
58
58
|
},
|
|
@@ -106,7 +106,7 @@ export function getDefaultHttpService(config) {
|
|
|
106
106
|
success: false,
|
|
107
107
|
error: {
|
|
108
108
|
details: {
|
|
109
|
-
type:
|
|
109
|
+
type: "invalidResponse",
|
|
110
110
|
isValidResponse: response.isValidResponse,
|
|
111
111
|
responseHeaders: response.responseHeaders,
|
|
112
112
|
status: response.status,
|
|
@@ -154,7 +154,7 @@ export function getDefaultHttpService(config) {
|
|
|
154
154
|
return await resolveRequestAsync({
|
|
155
155
|
options: {
|
|
156
156
|
...options,
|
|
157
|
-
method:
|
|
157
|
+
method: "GET",
|
|
158
158
|
body: null,
|
|
159
159
|
},
|
|
160
160
|
resolveDataAsync: async (response) => {
|
|
@@ -174,12 +174,12 @@ export function getDefaultHttpService(config) {
|
|
|
174
174
|
}
|
|
175
175
|
async function getKontentErrorDataAsync(response) {
|
|
176
176
|
if (response.responseHeaders
|
|
177
|
-
.find((header) => header.name.toLowerCase() ===
|
|
178
|
-
?.value
|
|
179
|
-
|
|
177
|
+
.find((header) => header.name.toLowerCase() === "Content-Type".toLowerCase())
|
|
178
|
+
?.value.toLowerCase()
|
|
179
|
+
.includes("application/json")) {
|
|
180
180
|
const json = (await response.toJsonAsync());
|
|
181
181
|
// We check the existence of 'message' property which should always be set when the error is a Kontent API error
|
|
182
|
-
if (!json
|
|
182
|
+
if (!json.message) {
|
|
183
183
|
return undefined;
|
|
184
184
|
}
|
|
185
185
|
return {
|
|
@@ -190,13 +190,13 @@ async function getKontentErrorDataAsync(response) {
|
|
|
190
190
|
return undefined;
|
|
191
191
|
}
|
|
192
192
|
function getRequestHeaders(headers, body) {
|
|
193
|
-
const existingContentTypeHeader = headers?.find((header) => header.name.toLowerCase() ===
|
|
194
|
-
const existingSdkVersionHeader = headers?.find((header) => header.name.toLowerCase() ===
|
|
193
|
+
const existingContentTypeHeader = headers?.find((header) => header.name.toLowerCase() === "Content-Type".toLowerCase());
|
|
194
|
+
const existingSdkVersionHeader = headers?.find((header) => header.name.toLowerCase() === "X-KC-SDKID".toLowerCase());
|
|
195
195
|
const contentTypeHeader = existingContentTypeHeader
|
|
196
196
|
? undefined
|
|
197
197
|
: {
|
|
198
|
-
name:
|
|
199
|
-
value: body instanceof Blob ? body.type :
|
|
198
|
+
name: "Content-Type",
|
|
199
|
+
value: body instanceof Blob ? body.type : "application/json",
|
|
200
200
|
};
|
|
201
201
|
const sdkVersionHeader = existingSdkVersionHeader
|
|
202
202
|
? undefined
|
|
@@ -207,7 +207,7 @@ function getRequestHeaders(headers, body) {
|
|
|
207
207
|
});
|
|
208
208
|
const contentLengthHeader = body instanceof Blob
|
|
209
209
|
? {
|
|
210
|
-
name:
|
|
210
|
+
name: "Content-Length",
|
|
211
211
|
value: body.size.toString(),
|
|
212
212
|
}
|
|
213
213
|
: undefined;
|
|
@@ -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,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,8BAA8B,EAAE,MAAM,yBAAyB,CAAC;AAC5F,OAAO,EAAe,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAW1D,MAAM,UAAU,qBAAqB,CAAC,MAAiC;IACtE,MAAM,mBAAmB,GAAG,KAAK,EAA8E,EA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,CAAC,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,gBAAgB,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;AAC9G,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CoreSdkError } from
|
|
1
|
+
import type { CoreSdkError } from "./error.models.js";
|
|
2
2
|
/**
|
|
3
3
|
* SDK info for identification of the SDK
|
|
4
4
|
*/
|
|
@@ -14,14 +14,14 @@ export type SDKInfo = {
|
|
|
14
14
|
/**
|
|
15
15
|
* The host of the SDK.
|
|
16
16
|
*/
|
|
17
|
-
readonly host: LiteralUnion<
|
|
17
|
+
readonly host: LiteralUnion<"npmjs.com">;
|
|
18
18
|
};
|
|
19
|
-
export type CommonHeaderNames =
|
|
19
|
+
export type CommonHeaderNames = "Retry-After" | "X-KC-SDKID" | "Authorization" | "Content-Type" | "Content-Length";
|
|
20
20
|
export type Header = {
|
|
21
21
|
readonly name: string;
|
|
22
22
|
readonly value: string;
|
|
23
23
|
};
|
|
24
|
-
export type HttpMethod =
|
|
24
|
+
export type HttpMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
25
25
|
export type KontentValidationError = {
|
|
26
26
|
readonly message: string;
|
|
27
27
|
readonly path?: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { AdapterResponse, HttpServiceStatus } from
|
|
2
|
-
import type { KontentErrorResponseData, RetryStrategyOptions } from
|
|
3
|
-
export type ErrorType =
|
|
1
|
+
import type { AdapterResponse, HttpServiceStatus } from "../http/http.models.js";
|
|
2
|
+
import type { KontentErrorResponseData, RetryStrategyOptions } from "./core.models.js";
|
|
3
|
+
export type ErrorType = "invalidResponse" | "invalidUrl" | "unknown" | "invalidBody";
|
|
4
4
|
export type CoreSdkError = {
|
|
5
5
|
/**
|
|
6
6
|
* The message of the error
|
|
@@ -21,13 +21,13 @@ export type CoreSdkError = {
|
|
|
21
21
|
/**
|
|
22
22
|
* The original error that caused the request to fail
|
|
23
23
|
*/
|
|
24
|
-
readonly details: SdkErrorDetails<
|
|
24
|
+
readonly details: SdkErrorDetails<"invalidResponse", {
|
|
25
25
|
readonly kontentErrorResponse: KontentErrorResponseData | undefined;
|
|
26
|
-
} & Pick<AdapterResponse<HttpServiceStatus>,
|
|
26
|
+
} & Pick<AdapterResponse<HttpServiceStatus>, "isValidResponse" | "responseHeaders" | "status" | "statusText">> | SdkErrorDetails<"invalidBody", {
|
|
27
27
|
readonly error: unknown;
|
|
28
|
-
}> | SdkErrorDetails<
|
|
28
|
+
}> | SdkErrorDetails<"invalidUrl", {
|
|
29
29
|
readonly error: unknown;
|
|
30
|
-
}> | SdkErrorDetails<
|
|
30
|
+
}> | SdkErrorDetails<"unknown", {
|
|
31
31
|
readonly error: unknown;
|
|
32
32
|
}>;
|
|
33
33
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import type { EmptyObject } from "./utility.models.js";
|
|
2
|
+
export type JsonValue = string | number | null | boolean | JsonObject | JsonArray | EmptyObject;
|
|
2
3
|
export interface JsonObject {
|
|
3
4
|
readonly [property: string]: JsonValue;
|
|
4
5
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Improves the type readability by flattening the type.
|
|
3
|
+
*/
|
|
4
|
+
export type Prettify<T> = {
|
|
5
|
+
[K in keyof T]: T[K];
|
|
6
|
+
} & {};
|
|
7
|
+
/**
|
|
8
|
+
* Override selected properties of a type. Uses Omit to remove the properties and then adds the new properties.
|
|
9
|
+
*/
|
|
10
|
+
export type Override<Type, NewType extends {
|
|
11
|
+
[key in keyof Type]?: NewType[key];
|
|
12
|
+
}> = Omit<Type, keyof NewType> & NewType;
|
|
13
|
+
/**
|
|
14
|
+
* Represents an empty object type.
|
|
15
|
+
*/
|
|
16
|
+
export type EmptyObject = Record<string, never>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utility.models.js","sourceRoot":"","sources":["../../lib/models/utility.models.ts"],"names":[],"mappings":""}
|
package/dist/public_api.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
export { getDefaultHttpAdapter } from
|
|
2
|
-
export
|
|
3
|
-
export {
|
|
4
|
-
export
|
|
5
|
-
export {
|
|
6
|
-
export type {
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
1
|
+
export { getDefaultHttpAdapter } from "./http/http.adapter.js";
|
|
2
|
+
export { getDefaultHttpService } from "./http/http.service.js";
|
|
3
|
+
export { getSdkIdHeader } from "./utils/header.utils.js";
|
|
4
|
+
export { toRequiredRetryStrategyOptions } from "./utils/retry.utils.js";
|
|
5
|
+
export { tryCatch, tryCatchAsync } from "./utils/try.utils.js";
|
|
6
|
+
export type { AdapterRequestOptions, AdapterResponse, DefaultHttpServiceConfig, DownloadFileRequestOptions, ExecuteRequestOptions, HttpAdapter, HttpResponse, HttpService, HttpServiceStatus, UploadFileRequestOptions, } from "./http/http.models.js";
|
|
7
|
+
export type { Header, HttpMethod, RetryStrategyOptions, SDKInfo, } from "./models/core.models.js";
|
|
8
|
+
export type { CoreSdkError, ErrorType, } from "./models/error.models.js";
|
|
9
|
+
export type { JsonArray, JsonObject, JsonValue } from "./models/json.models.js";
|
|
10
|
+
export type { EmptyObject, Override, Prettify } from "./models/utility.models.js";
|
package/dist/public_api.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
export { toRequiredRetryStrategyOptions } from './utils/retry.utils.js';
|
|
8
|
-
export { tryCatch, tryCatchAsync } from './utils/try.utils.js';
|
|
1
|
+
// biome-ignore lint/performance/noBarrelFile: One barrel for the public API is fine
|
|
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";
|
|
9
7
|
//# 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
|
|
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;AAC/D,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"}
|
package/dist/sdk-info.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { AdapterResponse } from
|
|
2
|
-
import type { HttpMethod, KontentErrorResponseData } from
|
|
1
|
+
import type { AdapterResponse } from "../http/http.models.js";
|
|
2
|
+
import type { HttpMethod, KontentErrorResponseData } from "../models/core.models.js";
|
|
3
3
|
export declare function getDefaultErrorMessage({ method, url, adapterResponse, kontentErrorResponse, }: {
|
|
4
4
|
readonly url: string;
|
|
5
5
|
readonly method: HttpMethod;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { isNotUndefined } from
|
|
1
|
+
import { isNotUndefined } from "./core.utils.js";
|
|
2
2
|
export function getDefaultErrorMessage({ method, url, adapterResponse, kontentErrorResponse, }) {
|
|
3
3
|
const errorMessage = extractMessageFromError(adapterResponse, kontentErrorResponse);
|
|
4
|
-
return `Failed to execute '${method}' request '${url}'.${errorMessage ? ` ${errorMessage}` :
|
|
4
|
+
return `Failed to execute '${method}' request '${url}'.${errorMessage ? ` ${errorMessage}` : ""}`;
|
|
5
5
|
}
|
|
6
6
|
function getValidationErrorMessage(validationErrors) {
|
|
7
|
-
if (!validationErrors
|
|
7
|
+
if (!validationErrors?.length) {
|
|
8
8
|
return undefined;
|
|
9
9
|
}
|
|
10
10
|
return validationErrors
|
|
@@ -14,14 +14,14 @@ function getValidationErrorMessage(validationErrors) {
|
|
|
14
14
|
m.line ? `line: ${m.line}` : undefined,
|
|
15
15
|
m.position ? `position: ${m.position}` : undefined,
|
|
16
16
|
].filter(isNotUndefined);
|
|
17
|
-
return `${m.message}${details.length ? ` (${details.join(
|
|
17
|
+
return `${m.message}${details.length ? ` (${details.join(", ")})` : ""}`;
|
|
18
18
|
})
|
|
19
|
-
.join(
|
|
19
|
+
.join(", ");
|
|
20
20
|
}
|
|
21
21
|
function extractMessageFromError(adapterResponse, kontentErrorResponse) {
|
|
22
22
|
if (kontentErrorResponse) {
|
|
23
23
|
const validationErrorMessage = getValidationErrorMessage(kontentErrorResponse.validation_errors);
|
|
24
|
-
return `Response failed with status '${adapterResponse.status}' and status text '${adapterResponse.statusText}'.${kontentErrorResponse
|
|
24
|
+
return `Response failed with status '${adapterResponse.status}' and status text '${adapterResponse.statusText}'.${kontentErrorResponse.message}${validationErrorMessage ? ` ${validationErrorMessage}` : ""}`;
|
|
25
25
|
}
|
|
26
26
|
return undefined;
|
|
27
27
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.utils.js","sourceRoot":"","sources":["../../lib/utils/error.utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD,MAAM,UAAU,sBAAsB,CAAC,EACtC,MAAM,EACN,GAAG,EACH,eAAe,EACf,oBAAoB,GAMpB;IACA,MAAM,YAAY,GAAG,uBAAuB,CAAC,eAAe,EAAE,oBAAoB,CAAC,CAA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AC,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;IAC1E,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAC;AACd,CAAC;AAED,SAAS,uBAAuB,CAAC,eAAgC,EAAE,oBAA+C;IACjH,IAAI,oBAAoB,EAAE,CAAC;QAC1B,MAAM,sBAAsB,GAAG,yBAAyB,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,CAAC;QACjG,OAAO,gCAAgC,eAAe,CAAC,MAAM,sBAAsB,eAAe,CAAC,UAAU,KAAK,oBAAoB,CAAC,OAAO,GAAG,sBAAsB,CAAC,CAAC,CAAC,IAAI,sBAAsB,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;IAC/M,CAAC;IAED,OAAO,SAAS,CAAC;AAClB,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Header, SDKInfo } from
|
|
1
|
+
import type { Header, SDKInfo } from "../models/core.models.js";
|
|
2
2
|
export declare function getSdkIdHeader(info: SDKInfo): Header;
|
|
3
3
|
export declare function getRetryAfterHeaderValue(headers: readonly Header[]): number | undefined;
|
|
4
4
|
export declare function toSdkHeaders(headers: Headers): readonly Header[];
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export function getSdkIdHeader(info) {
|
|
2
2
|
return {
|
|
3
|
-
name:
|
|
3
|
+
name: "X-KC-SDKID",
|
|
4
4
|
value: `${info.host};${info.name};${info.version}`,
|
|
5
5
|
};
|
|
6
6
|
}
|
|
7
7
|
export function getRetryAfterHeaderValue(headers) {
|
|
8
|
-
const retryAfterHeader = headers.find((header) => header.name
|
|
8
|
+
const retryAfterHeader = headers.find((header) => header.name.toLowerCase() === "Retry-After".toLowerCase());
|
|
9
9
|
if (!retryAfterHeader) {
|
|
10
10
|
return undefined;
|
|
11
11
|
}
|
|
@@ -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,YAAY;QAClB,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,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,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,YAAY;QAClB,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,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,aAAa,CAAC,WAAW,EAAE,CAAC,CAAC;IAE7G,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACvB,OAAO,SAAS,CAAC;IAClB,CAAC;IAED,OAAO,CAAC,gBAAgB,CAAC,KAAK,CAAC;AAChC,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"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { HttpResponse } from
|
|
2
|
-
import type { Header, HttpMethod, RetryStrategyOptions } from
|
|
3
|
-
import type { JsonValue } from
|
|
1
|
+
import type { HttpResponse } from "../http/http.models.js";
|
|
2
|
+
import type { Header, HttpMethod, RetryStrategyOptions } from "../models/core.models.js";
|
|
3
|
+
import type { JsonValue } from "../models/json.models.js";
|
|
4
4
|
export declare function runWithRetryAsync<TResponse extends JsonValue | Blob, TBodyData extends JsonValue | Blob>(data: {
|
|
5
5
|
readonly funcAsync: () => Promise<HttpResponse<TResponse, TBodyData>>;
|
|
6
6
|
readonly retryStrategyOptions: Required<RetryStrategyOptions>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { getRetryAfterHeaderValue } from
|
|
1
|
+
import { getRetryAfterHeaderValue } from "./header.utils.js";
|
|
2
2
|
const defaultMaxAttempts = 3;
|
|
3
3
|
const defaultDelayBetweenAttemptsMs = 1000;
|
|
4
4
|
const defaultCanRetryError = (error) => {
|
|
5
|
-
if (error.details.type ===
|
|
5
|
+
if (error.details.type === "invalidResponse") {
|
|
6
6
|
if (error.details.kontentErrorResponse) {
|
|
7
7
|
// The request is clearly invalid as we got an error response from the API
|
|
8
8
|
return false;
|
|
@@ -89,7 +89,7 @@ function getRetryResult({ retryAttempt, error, options, }) {
|
|
|
89
89
|
return getRetryFromHeader({ options, error });
|
|
90
90
|
}
|
|
91
91
|
function getRetryFromHeader({ options, error }) {
|
|
92
|
-
if (error.details.type !==
|
|
92
|
+
if (error.details.type !== "invalidResponse") {
|
|
93
93
|
return {
|
|
94
94
|
canRetry: false,
|
|
95
95
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
const sdkVersionPlaceholderMacro =
|
|
1
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
const sdkVersionPlaceholderMacro = "{{version}}";
|
|
4
4
|
export function replaceSdkVersionPlaceholder(filePath, version) {
|
|
5
|
-
const fileContent = readFileSync(filePath,
|
|
5
|
+
const fileContent = readFileSync(filePath, "utf8");
|
|
6
6
|
if (!fileContent.includes(sdkVersionPlaceholderMacro)) {
|
|
7
|
-
throw Error(`File '${filePath}' does not contain macro '${sdkVersionPlaceholderMacro}'`);
|
|
7
|
+
throw new Error(`File '${filePath}' does not contain macro '${sdkVersionPlaceholderMacro}'`);
|
|
8
8
|
}
|
|
9
9
|
writeFileSync(filePath, fileContent.replace(sdkVersionPlaceholderMacro, version));
|
|
10
10
|
console.log(`Updated SDK version in '${chalk.yellow(filePath)}' to '${chalk.green(version)}'`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdk-version.utils.js","sourceRoot":"","sources":["../../lib/utils/sdk-version.utils.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"sdk-version.utils.js","sourceRoot":"","sources":["../../lib/utils/sdk-version.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,0BAA0B,GAAG,aAAa,CAAC;AAEjD,MAAM,UAAU,4BAA4B,CAAC,QAAgB,EAAE,OAAe;IAC7E,MAAM,WAAW,GAAG,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAEnD,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,0BAA0B,CAAC,EAAE,CAAC;QACvD,MAAM,IAAI,KAAK,CAAC,SAAS,QAAQ,6BAA6B,0BAA0B,GAAG,CAAC,CAAC;IAC9F,CAAC;IAED,aAAa,CAAC,QAAQ,EAAE,WAAW,CAAC,OAAO,CAAC,0BAA0B,EAAE,OAAO,CAAC,CAAC,CAAC;IAElF,OAAO,CAAC,GAAG,CAAC,2BAA2B,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;AAChG,CAAC"}
|