@kontent-ai/core-sdk 12.0.0-preview.2 → 12.0.0-preview.20

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 +28 -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 +10 -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 +105 -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 +100 -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 +18 -19
  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
@@ -1,320 +0,0 @@
1
- import type { CommonHeaderNames, Header, KontentErrorResponseData, 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 { sdkInfo } from "../sdk-info.js";
5
- import { isNotUndefined } from "../utils/core.utils.js";
6
- import { getErrorMessage } from "../utils/error.utils.js";
7
- import { getSdkIdHeader } from "../utils/header.utils.js";
8
- import { runWithRetryAsync, toRequiredRetryStrategyOptions } from "../utils/retry.utils.js";
9
- import { type Result, tryCatch, tryCatchAsync } from "../utils/try.utils.js";
10
- import { getDefaultHttpAdapter } from "./http.adapter.js";
11
- import type {
12
- AdapterResponse,
13
- DefaultHttpServiceConfig,
14
- DownloadFileRequestOptions,
15
- ExecuteRequestOptions,
16
- HttpResponse,
17
- HttpService,
18
- UploadFileRequestOptions,
19
- } from "./http.models.js";
20
-
21
- export function getDefaultHttpService(config?: DefaultHttpServiceConfig): HttpService {
22
- const withUnknownErrorHandlingAsync = async <TResponseData extends JsonValue | Blob, TBodyData extends JsonValue | Blob>({
23
- url,
24
- funcAsync,
25
- }: {
26
- readonly url: string;
27
- readonly funcAsync: () => Promise<HttpResponse<TResponseData, TBodyData>>;
28
- }): Promise<HttpResponse<TResponseData, TBodyData>> => {
29
- const { success, data, error } = await tryCatchAsync(funcAsync);
30
-
31
- if (success) {
32
- return data;
33
- }
34
-
35
- return {
36
- success: false,
37
- error: {
38
- reason: "unknown",
39
- message: "Unknown error. See the error object for more details.",
40
- url: url,
41
- originalError: error,
42
- },
43
- };
44
- };
45
-
46
- const resolveRequestAsync = async <TResponseData extends JsonValue | Blob, TBodyData extends JsonValue | Blob>({
47
- options,
48
- resolveDataAsync,
49
- }: {
50
- readonly options: ExecuteRequestOptions<TBodyData>;
51
- readonly resolveDataAsync: (response: AdapterResponse) => Promise<TResponseData>;
52
- }): Promise<HttpResponse<TResponseData, TBodyData>> => {
53
- return await withUnknownErrorHandlingAsync({
54
- url: options.url,
55
- funcAsync: async () => {
56
- const adapter = config?.adapter ?? getDefaultHttpAdapter();
57
-
58
- const getCombinedRequestHeaders = (): readonly Header[] => {
59
- return getRequestHeaders([...(config?.requestHeaders ?? []), ...(options.requestHeaders ?? [])], options.body);
60
- };
61
-
62
- const getRequestBody = (): Result<string | Blob | null, CoreSdkError> => {
63
- if (options.body === null) {
64
- return {
65
- success: true,
66
- data: null,
67
- };
68
- }
69
-
70
- if (options.body instanceof Blob) {
71
- return {
72
- success: true,
73
- data: options.body,
74
- };
75
- }
76
-
77
- const { success, data: parsedBody, error } = tryCatch(() => JSON.stringify(options.body));
78
-
79
- if (!success) {
80
- return {
81
- success: false,
82
- error: {
83
- message: "Failed to stringify body of request.",
84
- url: options.url,
85
- reason: "invalidBody",
86
- originalError: error,
87
- },
88
- };
89
- }
90
-
91
- return {
92
- success: true,
93
- data: parsedBody,
94
- };
95
- };
96
-
97
- const getUrl = (): Result<URL, CoreSdkError> => {
98
- const { success, data: parsedUrl, error } = tryCatch(() => new URL(options.url));
99
-
100
- if (!success) {
101
- return {
102
- success: false,
103
- error: {
104
- message: `Failed to parse url '${options.url}'.`,
105
- url: options.url,
106
- reason: "invalidUrl",
107
- originalError: error,
108
- },
109
- };
110
- }
111
-
112
- return {
113
- success: true,
114
- data: parsedUrl,
115
- };
116
- };
117
-
118
- const requestHeaders = getCombinedRequestHeaders();
119
- const retryStrategyOptions: Required<RetryStrategyOptions> = toRequiredRetryStrategyOptions(config?.retryStrategy);
120
-
121
- const withRetryAsync = async (
122
- funcAsync: () => Promise<HttpResponse<TResponseData, TBodyData>>,
123
- ): Promise<HttpResponse<TResponseData, TBodyData>> => {
124
- return await runWithRetryAsync({
125
- url: options.url,
126
- retryStrategyOptions,
127
- retryAttempt: 0,
128
- requestHeaders,
129
- method: options.method,
130
- funcAsync: async () => {
131
- return await funcAsync();
132
- },
133
- });
134
- };
135
-
136
- const { success: urlParsedSuccess, data: parsedUrl, error: urlError } = getUrl();
137
-
138
- if (!urlParsedSuccess) {
139
- return {
140
- success: false,
141
- error: urlError,
142
- };
143
- }
144
-
145
- const { success: requestBodyParsedSuccess, data: requestBody, error: requestBodyError } = getRequestBody();
146
-
147
- if (!requestBodyParsedSuccess) {
148
- return {
149
- success: false,
150
- error: requestBodyError,
151
- };
152
- }
153
-
154
- const getResponseAsync = async (): Promise<AdapterResponse> => {
155
- return await adapter.requestAsync({
156
- url: parsedUrl.toString(),
157
- method: options.method,
158
- requestHeaders,
159
- body: requestBody,
160
- });
161
- };
162
-
163
- const getErrorForInvalidResponseAsync = async (response: AdapterResponse): Promise<CoreSdkError> => {
164
- const sharedErrorData: Pick<CoreSdkError, "message" | "url"> = {
165
- message: getErrorMessage({
166
- url: options.url,
167
- adapterResponse: response,
168
- method: options.method,
169
- }),
170
- url: options.url,
171
- };
172
-
173
- if (response.status === 404) {
174
- const error: CoreSdkError<"notFound"> = {
175
- ...sharedErrorData,
176
- reason: "notFound",
177
- isValidResponse: response.isValidResponse,
178
- responseHeaders: response.responseHeaders,
179
- status: 404,
180
- statusText: response.statusText,
181
- kontentErrorResponse: await getKontentErrorDataAsync(response),
182
- };
183
-
184
- return error;
185
- }
186
-
187
- const error: CoreSdkError<"invalidResponse"> = {
188
- ...sharedErrorData,
189
- reason: "invalidResponse",
190
- isValidResponse: response.isValidResponse,
191
- responseHeaders: response.responseHeaders,
192
- status: response.status,
193
- statusText: response.statusText,
194
- kontentErrorResponse: await getKontentErrorDataAsync(response),
195
- };
196
-
197
- return error;
198
- };
199
-
200
- const resolveResponseAsync = async (response: AdapterResponse): Promise<HttpResponse<TResponseData, TBodyData>> => {
201
- if (!response.isValidResponse) {
202
- return {
203
- success: false,
204
- error: await getErrorForInvalidResponseAsync(response),
205
- };
206
- }
207
-
208
- return {
209
- success: true,
210
- response: {
211
- data: await resolveDataAsync(response),
212
- body: options.body,
213
- method: options.method,
214
- adapterResponse: {
215
- isValidResponse: response.isValidResponse,
216
- responseHeaders: response.responseHeaders,
217
- status: response.status,
218
- statusText: response.statusText,
219
- },
220
- requestHeaders: requestHeaders,
221
- },
222
- };
223
- };
224
-
225
- return await withRetryAsync(async () => await resolveResponseAsync(await getResponseAsync()));
226
- },
227
- });
228
- };
229
-
230
- return {
231
- requestAsync: async <TResponseData extends JsonValue, TBodyData extends JsonValue>(options: ExecuteRequestOptions<TBodyData>) => {
232
- return await resolveRequestAsync<TResponseData, TBodyData>({
233
- options,
234
- resolveDataAsync: async (response) => {
235
- return (await response.toJsonAsync()) as TResponseData;
236
- },
237
- });
238
- },
239
-
240
- downloadFileAsync: async (options: DownloadFileRequestOptions): Promise<HttpResponse<Blob, null>> => {
241
- return await resolveRequestAsync<Blob, null>({
242
- options: {
243
- ...options,
244
- method: "GET",
245
- body: null,
246
- },
247
- resolveDataAsync: async (response) => {
248
- return await response.toBlobAsync();
249
- },
250
- });
251
- },
252
-
253
- uploadFileAsync: async <TResponseData extends JsonValue>(
254
- options: UploadFileRequestOptions,
255
- ): Promise<HttpResponse<TResponseData, Blob>> => {
256
- return await resolveRequestAsync<TResponseData, Blob>({
257
- options,
258
- resolveDataAsync: async (response) => {
259
- return (await response.toJsonAsync()) as TResponseData;
260
- },
261
- });
262
- },
263
- };
264
- }
265
-
266
- async function getKontentErrorDataAsync(response: AdapterResponse): Promise<KontentErrorResponseData | undefined> {
267
- if (
268
- response.responseHeaders
269
- .find((header) => header.name.toLowerCase() === ("Content-Type" satisfies CommonHeaderNames).toLowerCase())
270
- ?.value.toLowerCase()
271
- .includes("application/json")
272
- ) {
273
- const json = (await response.toJsonAsync()) as Partial<KontentErrorResponseData>;
274
-
275
- // We check the existence of 'message' property which should always be set when the error is a Kontent API error
276
- if (!json.message) {
277
- return undefined;
278
- }
279
-
280
- return {
281
- ...json,
282
- message: json.message,
283
- };
284
- }
285
- return undefined;
286
- }
287
-
288
- function getRequestHeaders(headers: readonly Header[] | undefined, body: Blob | JsonValue): readonly Header[] {
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
- );
295
-
296
- const contentTypeHeader: Header | undefined = existingContentTypeHeader
297
- ? undefined
298
- : {
299
- name: "Content-Type" satisfies CommonHeaderNames,
300
- value: body instanceof Blob ? body.type : "application/json",
301
- };
302
-
303
- const sdkVersionHeader: Header | undefined = existingSdkVersionHeader
304
- ? undefined
305
- : getSdkIdHeader({
306
- host: sdkInfo.host,
307
- name: sdkInfo.name,
308
- version: sdkInfo.version,
309
- });
310
-
311
- const contentLengthHeader: Header | undefined =
312
- body instanceof Blob
313
- ? {
314
- name: "Content-Length" satisfies CommonHeaderNames,
315
- value: body.size.toString(),
316
- }
317
- : undefined;
318
-
319
- return [...(headers ?? []), contentTypeHeader, contentLengthHeader, sdkVersionHeader].filter(isNotUndefined);
320
- }
@@ -1,89 +0,0 @@
1
- import type { CoreSdkError } from "./error.models.js";
2
- import type { PickStringLiteral } from "./utility.models.js";
3
-
4
- /**
5
- * SDK info for identification of the SDK
6
- */
7
- export type SDKInfo = {
8
- /**
9
- * The name of the SDK.
10
- */
11
- readonly name: string;
12
-
13
- /**
14
- * The version of the SDK.
15
- */
16
- readonly version: string;
17
-
18
- /**
19
- * The host of the SDK.
20
- */
21
- readonly host: LiteralUnion<"npmjs.com">;
22
- };
23
-
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">;
27
-
28
- export type Header = {
29
- readonly name: string;
30
- readonly value: string;
31
- };
32
-
33
- export type HttpMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
34
-
35
- export type KontentValidationError = {
36
- readonly message: string;
37
- readonly path?: string;
38
- readonly line?: number;
39
- readonly position?: number;
40
- };
41
-
42
- export type KontentErrorResponseData = {
43
- readonly message: string;
44
- readonly requestId?: string;
45
- readonly error_code?: number;
46
- readonly validation_errors?: readonly KontentValidationError[];
47
- };
48
-
49
- export type RetryStrategyOptions = {
50
- /**
51
- * Maximum number of retry attempts.
52
- *
53
- * If not provided, the default implementation will be used.
54
- */
55
- readonly maxRetries?: number;
56
-
57
- /**
58
- * Function to determine if the error should be retried.
59
- *
60
- * If not provided, the default implementation will be used.
61
- */
62
- readonly canRetryError?: (error: CoreSdkError) => boolean;
63
-
64
- /**
65
- * Function to determine the delay between requests in milliseconds.
66
- *
67
- * If not provided, the default implementation will be used.
68
- */
69
- readonly getDelayBetweenRetriesMs?: (error: CoreSdkError) => number;
70
-
71
- /**
72
- * Whether to log the retry attempt.
73
- *
74
- * If false, the retry attempt will not be logged.
75
- * If undefined, the default implementation will be used.
76
- * Otherwise, the function will be called with the retry attempt and url.
77
- */
78
- readonly logRetryAttempt?: false | ((retryAttempt: number, url: string) => void);
79
- };
80
-
81
- /**
82
- * Adds intellisense for string union type, but also allows any string
83
- */
84
- export type LiteralUnion<T extends string | undefined> = T | (string & NonNullable<unknown>);
85
-
86
- /**
87
- * Adds intellisense for number union type, but also allows any number
88
- */
89
- export type LiteralUnionNumber<T extends number | undefined> = T | (number & NonNullable<unknown>);
@@ -1,83 +0,0 @@
1
- import type { ZodError } from "zod";
2
- import type { AdapterResponse, HttpServiceStatus } from "../http/http.models.js";
3
- import type { SuccessfulHttpResponse } from "../sdk/sdk-models.js";
4
- import type { KontentErrorResponseData, RetryStrategyOptions } from "./core.models.js";
5
- import type { JsonValue } from "./json.models.js";
6
-
7
- export type ErrorReason = "invalidResponse" | "invalidUrl" | "unknown" | "invalidBody" | "notFound" | "validationFailed" | "noResponses";
8
-
9
- export type CoreSdkErrorDetails<TReason extends ErrorReason = ErrorReason> = (
10
- | Details<
11
- "invalidResponse",
12
- {
13
- readonly kontentErrorResponse: KontentErrorResponseData | undefined;
14
- } & Pick<AdapterResponse<HttpServiceStatus>, "isValidResponse" | "responseHeaders" | "status" | "statusText">
15
- >
16
- | Details<
17
- "notFound",
18
- {
19
- readonly kontentErrorResponse: KontentErrorResponseData | undefined;
20
- } & Pick<AdapterResponse<404>, "isValidResponse" | "responseHeaders" | "status" | "statusText">
21
- >
22
- | Details<
23
- "invalidBody",
24
- {
25
- readonly originalError: unknown;
26
- }
27
- >
28
- | Details<
29
- "invalidUrl",
30
- {
31
- readonly originalError: unknown;
32
- }
33
- >
34
- | Details<
35
- "unknown",
36
- {
37
- readonly originalError: unknown;
38
- }
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
- >
55
- ) & {
56
- readonly reason: TReason;
57
- };
58
-
59
- export type CoreSdkError<TReason extends ErrorReason = ErrorReason> = {
60
- /**
61
- * The message of the error
62
- */
63
- readonly message: string;
64
-
65
- /**
66
- * The URL of the request.
67
- */
68
- readonly url: string;
69
-
70
- /**
71
- * Used retry strategy.
72
- */
73
- readonly retryStrategyOptions?: Required<RetryStrategyOptions>;
74
-
75
- /**
76
- * The number of times the request has been retried.
77
- */
78
- readonly retryAttempt?: number;
79
- } & CoreSdkErrorDetails<TReason>;
80
-
81
- type Details<TReason extends ErrorReason, TDetails> = {
82
- readonly reason: TReason;
83
- } & TDetails;
@@ -1,9 +0,0 @@
1
- import type { EmptyObject } from "./utility.models.js";
2
-
3
- export type JsonValue = string | number | null | boolean | JsonObject | JsonArray | EmptyObject;
4
-
5
- export interface JsonObject {
6
- readonly [property: string]: JsonValue;
7
- }
8
-
9
- export type JsonArray = readonly JsonValue[];
@@ -1,21 +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
- /**
9
- * Override selected properties of a type. Uses Omit to remove the properties and then adds the new properties.
10
- */
11
- export type Override<Type, NewType extends { [key in keyof Type]?: NewType[key] }> = Omit<Type, keyof NewType> & NewType;
12
-
13
- /**
14
- * Represents an empty object type.
15
- */
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 DELETED
@@ -1,45 +0,0 @@
1
- // biome-ignore lint/performance/noBarrelFile: One barrel for the public API is fine
2
- export { getDefaultHttpAdapter } from "./http/http.adapter.js";
3
- export type {
4
- AdapterRequestOptions,
5
- AdapterResponse,
6
- DefaultHttpServiceConfig,
7
- DownloadFileRequestOptions,
8
- ExecuteRequestOptions,
9
- HttpAdapter,
10
- HttpResponse,
11
- HttpService,
12
- HttpServiceStatus,
13
- UploadFileRequestOptions,
14
- } from "./http/http.models.js";
15
- export { getDefaultHttpService } from "./http/http.service.js";
16
- export type {
17
- CommonHeaderNames,
18
- Header,
19
- HttpMethod,
20
- RetryStrategyOptions,
21
- SDKInfo,
22
- } from "./models/core.models.js";
23
- export type {
24
- CoreSdkError,
25
- CoreSdkErrorDetails,
26
- ErrorReason,
27
- } from "./models/error.models.js";
28
- export type { JsonArray, JsonObject, JsonValue } from "./models/json.models.js";
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";
@@ -1,85 +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
-
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
- };