@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.
Files changed (127) hide show
  1. package/.npmignore +1 -5
  2. package/LICENSE.md +1 -1
  3. package/README.md +177 -12
  4. package/dist/core-sdk-info.d.ts +2 -0
  5. package/dist/core-sdk-info.js +6 -0
  6. package/dist/core-sdk-info.js.map +1 -0
  7. package/dist/devkit/console.utils.d.ts +2 -0
  8. package/dist/devkit/console.utils.js +5 -0
  9. package/dist/devkit/console.utils.js.map +1 -0
  10. package/dist/devkit/environment.utils.d.ts +2 -0
  11. package/dist/devkit/environment.utils.js +12 -0
  12. package/dist/devkit/environment.utils.js.map +1 -0
  13. package/dist/devkit/script.utils.js +3 -3
  14. package/dist/devkit/script.utils.js.map +1 -1
  15. package/dist/devkit_api.d.ts +3 -0
  16. package/dist/devkit_api.js +3 -1
  17. package/dist/devkit_api.js.map +1 -1
  18. package/dist/http/http.adapter.d.ts +1 -1
  19. package/dist/http/http.adapter.js +78 -24
  20. package/dist/http/http.adapter.js.map +1 -1
  21. package/dist/http/http.models.d.ts +42 -32
  22. package/dist/http/http.service.js +294 -220
  23. package/dist/http/http.service.js.map +1 -1
  24. package/dist/models/core.models.d.ts +34 -29
  25. package/dist/models/error.models.d.ts +48 -27
  26. package/dist/models/error.models.js +40 -1
  27. package/dist/models/error.models.js.map +1 -1
  28. package/dist/models/json.models.d.ts +13 -4
  29. package/dist/models/json.models.js +10 -1
  30. package/dist/models/json.models.js.map +1 -1
  31. package/dist/models/utility.types.d.ts +16 -0
  32. package/dist/models/utility.types.js +2 -0
  33. package/dist/models/utility.types.js.map +1 -0
  34. package/dist/public_api.d.ts +19 -11
  35. package/dist/public_api.js +15 -6
  36. package/dist/public_api.js.map +1 -1
  37. package/dist/sdk/queries/fetch-sdk-query.d.ts +7 -0
  38. package/dist/sdk/queries/fetch-sdk-query.js +24 -0
  39. package/dist/sdk/queries/fetch-sdk-query.js.map +1 -0
  40. package/dist/sdk/queries/mutation-sdk-query.d.ts +4 -0
  41. package/dist/sdk/queries/mutation-sdk-query.js +17 -0
  42. package/dist/sdk/queries/mutation-sdk-query.js.map +1 -0
  43. package/dist/sdk/queries/paged-fetch-sdk-query.d.ts +6 -0
  44. package/dist/sdk/queries/paged-fetch-sdk-query.js +145 -0
  45. package/dist/sdk/queries/paged-fetch-sdk-query.js.map +1 -0
  46. package/dist/sdk/resolve-query.d.ts +8 -0
  47. package/dist/sdk/resolve-query.js +108 -0
  48. package/dist/sdk/resolve-query.js.map +1 -0
  49. package/dist/sdk/sdk-config.d.ts +3 -0
  50. package/dist/sdk/sdk-config.js +4 -0
  51. package/dist/sdk/sdk-config.js.map +1 -0
  52. package/dist/sdk/sdk-models.d.ts +101 -36
  53. package/dist/sdk/sdk-utils.d.ts +2 -0
  54. package/dist/sdk/sdk-utils.js +9 -0
  55. package/dist/sdk/sdk-utils.js.map +1 -0
  56. package/dist/testkit/poll.utils.d.ts +5 -0
  57. package/dist/testkit/poll.utils.js +24 -0
  58. package/dist/testkit/poll.utils.js.map +1 -0
  59. package/dist/testkit/testkit.utils.d.ts +20 -0
  60. package/dist/testkit/testkit.utils.js +100 -0
  61. package/dist/testkit/testkit.utils.js.map +1 -0
  62. package/dist/testkit_api.d.ts +3 -1
  63. package/dist/testkit_api.js +3 -2
  64. package/dist/testkit_api.js.map +1 -1
  65. package/dist/utils/abort.utils.d.ts +12 -0
  66. package/dist/utils/abort.utils.js +29 -0
  67. package/dist/utils/abort.utils.js.map +1 -0
  68. package/dist/utils/core.utils.d.ts +3 -1
  69. package/dist/utils/core.utils.js +22 -2
  70. package/dist/utils/core.utils.js.map +1 -1
  71. package/dist/utils/error.utils.d.ts +18 -7
  72. package/dist/utils/error.utils.js +35 -7
  73. package/dist/utils/error.utils.js.map +1 -1
  74. package/dist/utils/header.utils.d.ts +6 -1
  75. package/dist/utils/header.utils.js +37 -6
  76. package/dist/utils/header.utils.js.map +1 -1
  77. package/dist/utils/retry.utils.d.ts +16 -11
  78. package/dist/utils/retry.utils.js +131 -63
  79. package/dist/utils/retry.utils.js.map +1 -1
  80. package/dist/utils/sdk-version.utils.js +2 -2
  81. package/dist/utils/sdk-version.utils.js.map +1 -1
  82. package/dist/utils/try-catch.utils.d.ts +15 -0
  83. package/dist/utils/{try.utils.js → try-catch.utils.js} +1 -1
  84. package/dist/utils/try-catch.utils.js.map +1 -0
  85. package/dist/utils/type.utils.d.ts +2 -0
  86. package/dist/utils/type.utils.js +5 -0
  87. package/dist/utils/type.utils.js.map +1 -0
  88. package/dist/utils/url.utils.d.ts +5 -0
  89. package/dist/utils/url.utils.js +10 -0
  90. package/dist/utils/url.utils.js.map +1 -0
  91. package/package.json +61 -64
  92. package/dist/models/utility.models.d.ts +0 -20
  93. package/dist/models/utility.models.js +0 -2
  94. package/dist/models/utility.models.js.map +0 -1
  95. package/dist/sdk/sdk-queries.d.ts +0 -30
  96. package/dist/sdk/sdk-queries.js +0 -152
  97. package/dist/sdk/sdk-queries.js.map +0 -1
  98. package/dist/sdk-info.d.ts +0 -5
  99. package/dist/sdk-info.js +0 -6
  100. package/dist/sdk-info.js.map +0 -1
  101. package/dist/testkit/test.utils.d.ts +0 -15
  102. package/dist/testkit/test.utils.js +0 -42
  103. package/dist/testkit/test.utils.js.map +0 -1
  104. package/dist/utils/try.utils.d.ts +0 -14
  105. package/dist/utils/try.utils.js.map +0 -1
  106. package/lib/devkit/script.utils.ts +0 -12
  107. package/lib/devkit_api.ts +0 -3
  108. package/lib/http/http.adapter.ts +0 -38
  109. package/lib/http/http.models.ts +0 -122
  110. package/lib/http/http.service.ts +0 -320
  111. package/lib/models/core.models.ts +0 -89
  112. package/lib/models/error.models.ts +0 -83
  113. package/lib/models/json.models.ts +0 -9
  114. package/lib/models/utility.models.ts +0 -21
  115. package/lib/public_api.ts +0 -45
  116. package/lib/sdk/sdk-models.ts +0 -85
  117. package/lib/sdk/sdk-queries.ts +0 -232
  118. package/lib/sdk-info.ts +0 -5
  119. package/lib/testkit/test.utils.ts +0 -79
  120. package/lib/testkit/testkit.models.ts +0 -7
  121. package/lib/testkit_api.ts +0 -3
  122. package/lib/utils/core.utils.ts +0 -3
  123. package/lib/utils/error.utils.ts +0 -48
  124. package/lib/utils/header.utils.ts +0 -40
  125. package/lib/utils/retry.utils.ts +0 -156
  126. package/lib/utils/sdk-version.utils.ts +0 -16
  127. package/lib/utils/try.utils.ts +0 -30
package/package.json CHANGED
@@ -1,65 +1,62 @@
1
1
  {
2
- "name": "@kontent-ai/core-sdk",
3
- "version": "12.0.0-preview.2",
4
- "repository": {
5
- "type": "git",
6
- "url": "https://github.com/kontent-ai/kontent-core-js"
7
- },
8
- "private": false,
9
- "author": "richard sustek",
10
- "license": "MIT",
11
- "description": "Core package with shared / common functionality for Kontent.ai SDKs",
12
- "keywords": [
13
- "Kontent.ai",
14
- "Kontent AI",
15
- "Kontent SDK Core"
16
- ],
17
- "engines": {
18
- "node": ">= 22"
19
- },
20
- "exports": {
21
- ".": {
22
- "types": "./dist/public_api.d.ts",
23
- "default": "./dist/public_api.js"
24
- },
25
- "./devkit": {
26
- "types": "./dist/devkit_api.d.ts",
27
- "default": "./dist/devkit_api.js"
28
- },
29
- "./testkit": {
30
- "types": "./dist/testkit_api.d.ts",
31
- "default": "./dist/testkit_api.js"
32
- }
33
- },
34
- "type": "module",
35
- "scripts": {
36
- "prepublishOnly": "npm run build",
37
- "build": "npm run lint && npm run clean && tsc --p tsconfig.build.json && npm run update:version",
38
- "test": "npm run test:unit && npm run test:integration",
39
- "test:unit": "vitest run --config=vitest-unit.config.ts",
40
- "test:integration": "vitest run --config=vitest-integration.config.ts",
41
- "lint": "npm run biome:check && npm run eslint",
42
- "eslint": "eslint ",
43
- "biome:check": "biome check",
44
- "biome:fix": "biome check --write",
45
- "biome:fix:unsafe": "biome check --write --unsafe",
46
- "clean": "tsx scripts/clean.ts",
47
- "update:version": "tsx ./scripts/update-version.ts"
48
- },
49
- "dependencies": {
50
- "zod": "4.3.5"
51
- },
52
- "devDependencies": {
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"
64
- }
65
- }
2
+ "name": "@kontent-ai/core-sdk",
3
+ "version": "12.0.0-preview.21",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "https://github.com/kontent-ai/core-sdk-js"
7
+ },
8
+ "private": false,
9
+ "author": "richard sustek",
10
+ "license": "MIT",
11
+ "description": "Core package with shared / common functionality for Kontent.ai SDKs",
12
+ "keywords": [
13
+ "Kontent.ai",
14
+ "Kontent AI",
15
+ "Kontent SDK Core"
16
+ ],
17
+ "engines": {
18
+ "node": ">=22"
19
+ },
20
+ "exports": {
21
+ ".": {
22
+ "types": "./dist/public_api.d.ts",
23
+ "default": "./dist/public_api.js"
24
+ },
25
+ "./devkit": {
26
+ "types": "./dist/devkit_api.d.ts",
27
+ "default": "./dist/devkit_api.js"
28
+ },
29
+ "./testkit": {
30
+ "types": "./dist/testkit_api.d.ts",
31
+ "default": "./dist/testkit_api.js"
32
+ }
33
+ },
34
+ "type": "module",
35
+ "peerDependencies": {
36
+ "ts-pattern": "^5",
37
+ "zod": "^4"
38
+ },
39
+ "devDependencies": {
40
+ "@kontent-ai/biome-config": "0.7.0",
41
+ "@kontent-ai/eslint-config": "2.4.1",
42
+ "eslint": "10.1.0",
43
+ "@biomejs/biome": "2.4.9",
44
+ "@types/node": "25.5.0",
45
+ "typescript": "6.0.2",
46
+ "vitest": "4.1.2",
47
+ "tsx": "4.21.0"
48
+ },
49
+ "scripts": {
50
+ "build": "pnpm run lint && pnpm run clean && tsc --p tsconfig.json && tsc --p tsconfig.build.json && pnpm run update:version",
51
+ "test": "pnpm run test:unit && pnpm run test:integration",
52
+ "test:unit": "vitest run --config=vitest-unit.config.ts",
53
+ "test:integration": "vitest run --config=vitest-integration.config.ts",
54
+ "lint": "pnpm run biome:check && pnpm run eslint",
55
+ "eslint": "eslint lib tests scripts",
56
+ "biome:check": "biome check",
57
+ "biome:fix": "biome check --write",
58
+ "biome:fix:unsafe": "biome check --write --unsafe",
59
+ "clean": "tsx ./scripts/clean.ts",
60
+ "update:version": "tsx ./scripts/update-version.ts"
61
+ }
62
+ }
@@ -1,20 +0,0 @@
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>;
17
- /**
18
- * Picks a string literal type from a union type.
19
- */
20
- export type PickStringLiteral<T extends string, U extends T> = U;
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=utility.models.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utility.models.js","sourceRoot":"","sources":["../../lib/models/utility.models.ts"],"names":[],"mappings":""}
@@ -1,30 +0,0 @@
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 {};
@@ -1,152 +0,0 @@
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
@@ -1 +0,0 @@
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,CAC7B,IAGC;IAED,OAAO;QACN,GAAG,QAAQ,CAAsC,IAAI,CAAC;QACtD,YAAY,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EAAE,KAAK;QACd,KAAK,EAAE,cAAc,CAAC,KAAK;KAC3B,CAAC;AACH,CAAC"}
@@ -1,5 +0,0 @@
1
- export declare const sdkInfo: {
2
- host: string;
3
- version: string;
4
- name: string;
5
- };
package/dist/sdk-info.js DELETED
@@ -1,6 +0,0 @@
1
- export const sdkInfo = {
2
- host: "npmjs.com",
3
- version: "12.0.0-preview.2",
4
- name: "@kontent-ai/core-sdk",
5
- };
6
- //# sourceMappingURL=sdk-info.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sdk-info.js","sourceRoot":"","sources":["../lib/sdk-info.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG;IACtB,IAAI,EAAE,WAAW;IACjB,OAAO,EAAE,aAAa;IACtB,IAAI,EAAE,sBAAsB;CAC5B,CAAC"}
@@ -1,15 +0,0 @@
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
- export declare function getFetchJsonMock<TResponseData extends JsonValue>({ json, status, responseHeaders, }: {
6
- readonly json: TResponseData;
7
- readonly status: HttpServiceStatus;
8
- readonly responseHeaders?: readonly Header[];
9
- }): Mock<() => Promise<Response>>;
10
- export declare function getFetchBlobMock({ blob, status, responseHeaders, }: {
11
- readonly blob: Blob;
12
- readonly status: HttpServiceStatus;
13
- readonly responseHeaders?: readonly Header[];
14
- }): Mock<() => Promise<Response>>;
15
- export declare function getFakeBlob(): Blob;
@@ -1,42 +0,0 @@
1
- import { vi } from "vitest";
2
- import { isNotUndefined } from "../utils/core.utils.js";
3
- import { toFetchHeaders } from "../utils/header.utils.js";
4
- export function getFetchJsonMock({ json, status, responseHeaders, }) {
5
- return getFetchMock({
6
- status,
7
- responseHeaders: responseHeaders ?? [],
8
- blob: undefined,
9
- json,
10
- });
11
- }
12
- export function getFetchBlobMock({ blob, status, responseHeaders, }) {
13
- return getFetchMock({
14
- blob,
15
- status,
16
- responseHeaders: responseHeaders ?? [],
17
- json: undefined,
18
- });
19
- }
20
- export function getFakeBlob() {
21
- return new Blob(["x"], { type: "text/plain" });
22
- }
23
- function getFetchMock({ json, blob, status, responseHeaders, }) {
24
- return vi.fn(() => {
25
- const contentTypeHeader = responseHeaders.find((m) => m.name.toLowerCase() === "Content-Type".toLowerCase())
26
- ? undefined
27
- : {
28
- name: "Content-Type",
29
- value: "application/json",
30
- };
31
- return Promise.resolve({
32
- // only implement the methods we need, ignore the rest
33
- ...{},
34
- ok: status === 200,
35
- headers: toFetchHeaders([...responseHeaders, contentTypeHeader].filter(isNotUndefined)),
36
- status,
37
- json: async () => await Promise.resolve(json),
38
- ...(blob ? { blob: async () => await Promise.resolve(blob) } : {}),
39
- });
40
- });
41
- }
42
- //# sourceMappingURL=test.utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"test.utils.js","sourceRoot":"","sources":["../../lib/testkit/test.utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAK5B,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE1D,MAAM,UAAU,gBAAgB,CAAkC,EACjE,IAAI,EACJ,MAAM,EACN,eAAe,GAKf;IACA,OAAO,YAAY,CAAY;QAC9B,MAAM;QACN,eAAe,EAAE,eAAe,IAAI,EAAE;QACtC,IAAI,EAAE,SAAS;QACf,IAAI;KACJ,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,EAChC,IAAI,EACJ,MAAM,EACN,eAAe,GAKf;IACA,OAAO,YAAY,CAAO;QACzB,IAAI;QACJ,MAAM;QACN,eAAe,EAAE,eAAe,IAAI,EAAE;QACtC,IAAI,EAAE,SAAS;KACf,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,WAAW;IAC1B,OAAO,IAAI,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC;AAChD,CAAC;AAED,SAAS,YAAY,CAAyC,EAC7D,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,eAAe,GAMf;IACA,OAAO,EAAE,CAAC,EAAE,CAAC,GAAG,EAAE;QACjB,MAAM,iBAAiB,GAAuB,eAAe,CAAC,IAAI,CACjE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,KAAM,cAA2C,CAAC,WAAW,EAAE,CAC1F;YACA,CAAC,CAAC,SAAS;YACX,CAAC,CAAC;gBACA,IAAI,EAAE,cAA0C;gBAChD,KAAK,EAAE,kBAAkB;aACzB,CAAC;QAEJ,OAAO,OAAO,CAAC,OAAO,CAAW;YAChC,sDAAsD;YACtD,GAAI,EAAe;YACnB,EAAE,EAAE,MAAM,KAAK,GAAG;YAClB,OAAO,EAAE,cAAc,CAAC,CAAC,GAAG,eAAe,EAAE,iBAAiB,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;YACvF,MAAM;YACN,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC,MAAM,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC;YAC7C,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC,MAAM,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAClE,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;AACJ,CAAC"}
@@ -1,14 +0,0 @@
1
- type Success<TData> = {
2
- readonly success: true;
3
- readonly data: TData;
4
- readonly error?: never;
5
- };
6
- type Failure<TError = unknown> = {
7
- readonly success: false;
8
- readonly data?: never;
9
- readonly error: TError;
10
- };
11
- export type Result<TData, TError = unknown> = Success<TData> | Failure<TError>;
12
- export declare function tryCatchAsync<T>(fn: () => Promise<T>): Promise<Result<T>>;
13
- export declare function tryCatch<T>(fn: () => T): Result<T>;
14
- export {};
@@ -1 +0,0 @@
1
- {"version":3,"file":"try.utils.js","sourceRoot":"","sources":["../../lib/utils/try.utils.ts"],"names":[],"mappings":"AAcA,MAAM,CAAC,KAAK,UAAU,aAAa,CAAI,EAAoB;IAC1D,IAAI,CAAC;QACJ,MAAM,IAAI,GAAG,MAAM,EAAE,EAAE,CAAC;QACxB,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IAChC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;IAClC,CAAC;AACF,CAAC;AAED,MAAM,UAAU,QAAQ,CAAI,EAAW;IACtC,IAAI,CAAC;QACJ,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC;IACtC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;IAClC,CAAC;AACF,CAAC"}
@@ -1,12 +0,0 @@
1
- import { rmSync } from "node:fs";
2
- import chalk from "chalk";
3
-
4
- export function deleteFolderRecursive(path: string): void {
5
- console.log(`Deleting existing folder '${chalk.yellow(path)}'`);
6
- rmSync(path, {
7
- recursive: true,
8
- force: true,
9
- });
10
-
11
- console.log(`Folder '${chalk.yellow(path)}' deleted successfully`);
12
- }
package/lib/devkit_api.ts DELETED
@@ -1,3 +0,0 @@
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";
@@ -1,38 +0,0 @@
1
- import type { CommonHeaderNames } from "../models/core.models.js";
2
- import type { JsonValue } from "../models/json.models.js";
3
- import { toFetchHeaders, toSdkHeaders } from "../utils/header.utils.js";
4
- import type { HttpAdapter } from "./http.models.js";
5
-
6
- export function getDefaultHttpAdapter(): HttpAdapter {
7
- return {
8
- requestAsync: async (options) => {
9
- const response = await fetch(options.url, {
10
- method: options.method,
11
- headers: toFetchHeaders(options.requestHeaders ?? []),
12
- body: options.body,
13
- });
14
-
15
- const sdkResponseHeaders = toSdkHeaders(response.headers);
16
-
17
- return {
18
- isValidResponse: response.ok,
19
- responseHeaders: sdkResponseHeaders,
20
- status: response.status,
21
- statusText: response.statusText,
22
- toBlobAsync: async () => await response.blob(),
23
- toJsonAsync: async () => {
24
- const contentTypeResponseHeader = sdkResponseHeaders
25
- .find((m) => m.name.toLowerCase() === ("Content-Type" satisfies CommonHeaderNames).toLowerCase())
26
- ?.value.toLowerCase();
27
-
28
- if (contentTypeResponseHeader?.includes("application/json")) {
29
- // Includes instead of equal due to the fact that the header value can be 'application/json; charset=utf-8' or similar
30
- return (await response.json()) as JsonValue;
31
- }
32
-
33
- return null;
34
- },
35
- };
36
- },
37
- };
38
- }
@@ -1,122 +0,0 @@
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
-
5
- type Success<TData> = {
6
- readonly success: true;
7
- readonly response: TData;
8
- readonly error?: never;
9
- };
10
-
11
- type Failure = {
12
- readonly success: false;
13
- readonly response?: never;
14
- readonly error: CoreSdkError;
15
- };
16
-
17
- export type HttpResult<TData> = Success<TData> | Failure;
18
-
19
- /**
20
- * Helper status codes for the HTTP service.
21
- * It can be any valid number status code as this type only serves as a helper.
22
- */
23
- export type HttpServiceStatus = LiteralUnionNumber<200 | 201 | 204 | 500 | 429 | 404 | 403 | 401 | 400>;
24
-
25
- export type DefaultHttpServiceConfig = {
26
- /**
27
- * The retry strategy to be used. If not provided, the default retry strategy will be used.
28
- */
29
- readonly retryStrategy?: RetryStrategyOptions;
30
-
31
- /**
32
- * The headers appended to all requests.
33
- */
34
- readonly requestHeaders?: readonly Header[];
35
-
36
- /**
37
- * The adapter to be used. If not provided, the default adapter will be used.
38
- */
39
- readonly adapter?: HttpAdapter;
40
- };
41
-
42
- export type HttpResponse<TResponseData extends JsonValue | Blob, TBodyData extends JsonValue | Blob> = HttpResult<{
43
- readonly data: TResponseData;
44
- readonly body: TBodyData;
45
- readonly method: HttpMethod;
46
- readonly requestHeaders: readonly Header[];
47
- readonly adapterResponse: Omit<AdapterResponse, "toJsonAsync" | "toBlobAsync">;
48
- }>;
49
-
50
- export type ExecuteRequestOptions<TBodyData extends JsonValue | Blob> = {
51
- readonly url: string;
52
- readonly method: HttpMethod;
53
- readonly body: TBodyData;
54
- readonly requestHeaders?: readonly Header[];
55
- };
56
-
57
- export type UploadFileRequestOptions = Omit<ExecuteRequestOptions<Blob>, "method"> & {
58
- readonly method: Extract<HttpMethod, "POST" | "PUT" | "PATCH">;
59
- };
60
-
61
- export type DownloadFileRequestOptions = Pick<ExecuteRequestOptions<Blob>, "url" | "requestHeaders">;
62
-
63
- /**
64
- * Represents the HTTP service used for making requests to the Kontent.ai API.
65
- *
66
- * This service includes built-in retry logic, request validation, and automatic header processing.
67
- *
68
- * By default, it uses the `fetch` API for executing requests. However, you can supply a custom `HttpAdapter`
69
- * to integrate your preferred HTTP client.
70
- *
71
- * For full customization—including retry behavior and other request-handling logic—you may implement the `HttpService` directly.
72
- */
73
- export type HttpService = {
74
- /**
75
- * Executes request with the given method and body.
76
- */
77
- requestAsync<TResponseData extends JsonValue, TBodyData extends JsonValue>(
78
- opts: ExecuteRequestOptions<TBodyData>,
79
- ): Promise<HttpResponse<TResponseData, TBodyData>>;
80
-
81
- /**
82
- * Downloads a file from the given URL as a blob.
83
- */
84
- downloadFileAsync(opts: DownloadFileRequestOptions): Promise<HttpResponse<Blob, null>>;
85
-
86
- /**
87
- * This method is used to upload a kontent.ai binary file.
88
- */
89
- uploadFileAsync<TResponseData extends JsonValue>(opts: UploadFileRequestOptions): Promise<HttpResponse<TResponseData, Blob>>;
90
- };
91
-
92
- export type AdapterResponse<TStatusCode extends HttpServiceStatus = HttpServiceStatus> = {
93
- readonly toJsonAsync: () => Promise<JsonValue>;
94
- readonly toBlobAsync: () => Promise<Blob>;
95
-
96
- readonly isValidResponse: boolean;
97
- readonly responseHeaders: readonly Header[];
98
- readonly status: TStatusCode;
99
- readonly statusText: string;
100
- };
101
-
102
- export type AdapterRequestOptions = {
103
- readonly url: string;
104
- readonly method: HttpMethod;
105
- readonly body: string | Blob | undefined | null;
106
- readonly requestHeaders?: readonly Header[];
107
- };
108
-
109
- /**
110
- * Defines the adapter responsible solely for executing HTTP requests.
111
- *
112
- * This implementation should focus exclusively on performing the request itself.
113
- * It should not handle concerns such as retry policies, header manipulation, response parsing, or request body transformation.
114
- *
115
- * To extend functionality, you can implement a custom adapter and pass it to the `getDefaultHttpService` function,
116
- * which handles additional concerns like retries and parsing.
117
- *
118
- * Alternatively, you may implement the entire `HttpService` interface to create a fully customized HTTP service.
119
- */
120
- export type HttpAdapter = {
121
- readonly requestAsync: (options: AdapterRequestOptions) => Promise<AdapterResponse>;
122
- };