@deliverart/sdk-js-core 2.5.34 → 2.6.0
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/index.cjs +22406 -18
- package/dist/index.d.cts +43 -3
- package/dist/index.d.ts +43 -3
- package/dist/index.js +22412 -18
- package/package.json +3 -2
package/dist/index.d.cts
CHANGED
|
@@ -5,11 +5,21 @@ interface ApiClientPlugin<T extends ApiExtension = Record<string, unknown>> {
|
|
|
5
5
|
setup: (client: ApiClient<Record<string, unknown>>) => T;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
+
type UnpaginatedResponse<T> = T extends {
|
|
9
|
+
data: infer U;
|
|
10
|
+
} ? U : T;
|
|
8
11
|
declare abstract class AbstractApiRequest<TInputSchema extends ZodType<any, any, any>, TOutputSchema extends ZodType<any, any, any>, Query = unknown, Headers = unknown> {
|
|
9
12
|
readonly input: input<TInputSchema>;
|
|
10
13
|
readonly options?: {
|
|
11
14
|
query?: Query;
|
|
12
15
|
headers?: Headers;
|
|
16
|
+
/**
|
|
17
|
+
* Toggle pagination at call-time if the request supports it.
|
|
18
|
+
* - true: attach pagination (if `getPagination` returns a value)
|
|
19
|
+
* - false: return a plain array of items
|
|
20
|
+
* - undefined: fall back to `paginationDefaultEnabled` (true if not set)
|
|
21
|
+
*/
|
|
22
|
+
pagination?: boolean;
|
|
13
23
|
} | undefined;
|
|
14
24
|
abstract readonly method: 'GET' | 'POST' | 'PATCH' | 'DELETE';
|
|
15
25
|
abstract readonly contentType: 'application/json' | 'multipart/form-data' | 'application/merge-patch+json';
|
|
@@ -18,16 +28,39 @@ declare abstract class AbstractApiRequest<TInputSchema extends ZodType<any, any,
|
|
|
18
28
|
abstract readonly outputSchema: TOutputSchema;
|
|
19
29
|
abstract readonly querySchema?: ZodType<Query>;
|
|
20
30
|
abstract readonly headersSchema?: ZodType<Headers>;
|
|
31
|
+
/**
|
|
32
|
+
* Optional hints to enable automatic list parsing.
|
|
33
|
+
* - If `listItemSchema` is provided, `parseResponse` will automatically
|
|
34
|
+
* parse arrays and optionally attach pagination when enabled.
|
|
35
|
+
* - Pagination attachment requires overriding `getPagination` in concrete requests
|
|
36
|
+
* to compute pagination metadata from the raw response (e.g. headers).
|
|
37
|
+
*/
|
|
38
|
+
readonly listItemSchema?: ZodType<any, any, any>;
|
|
39
|
+
/** Whether pagination is enabled by default for this request (if available). */
|
|
40
|
+
readonly paginationDefaultEnabled?: boolean;
|
|
21
41
|
protected constructor(input: input<TInputSchema>, options?: {
|
|
22
42
|
query?: Query;
|
|
23
43
|
headers?: Headers;
|
|
44
|
+
/**
|
|
45
|
+
* Toggle pagination at call-time if the request supports it.
|
|
46
|
+
* - true: attach pagination (if `getPagination` returns a value)
|
|
47
|
+
* - false: return a plain array of items
|
|
48
|
+
* - undefined: fall back to `paginationDefaultEnabled` (true if not set)
|
|
49
|
+
*/
|
|
50
|
+
pagination?: boolean;
|
|
24
51
|
} | undefined);
|
|
25
52
|
abstract getPath(): string;
|
|
53
|
+
/**
|
|
54
|
+
* Override this in list requests to provide pagination metadata from the raw HTTP response.
|
|
55
|
+
* Default implementation uses `responseToPagination`.
|
|
56
|
+
* Return `undefined` if pagination cannot be resolved.
|
|
57
|
+
*/
|
|
58
|
+
protected getPagination(rawResponse: Response): unknown | undefined;
|
|
26
59
|
validateInput(): output<TInputSchema>;
|
|
27
60
|
validateQuery(): Query | undefined;
|
|
28
61
|
validateHeaders(): Headers | undefined;
|
|
29
62
|
validateOutput(data: unknown): output<TOutputSchema>;
|
|
30
|
-
parseResponse(data: unknown, rawResponse?: Response): output<TOutputSchema>;
|
|
63
|
+
parseResponse(data: unknown, rawResponse?: Response, paginationOption?: boolean): output<TOutputSchema>;
|
|
31
64
|
}
|
|
32
65
|
type RequestContext = {
|
|
33
66
|
url: URL;
|
|
@@ -41,7 +74,14 @@ type ParsedResponse = {
|
|
|
41
74
|
type ResponseMiddleware = (parsed: ParsedResponse, requestCtx: RequestContext) => Promise<ParsedResponse> | ParsedResponse;
|
|
42
75
|
interface ApiClientBase {
|
|
43
76
|
fetch: typeof fetch;
|
|
44
|
-
call<TInputSchema extends ZodType<any, any, any>, TOutputSchema extends ZodType<any, any, any>, Q = unknown, H = unknown>(request: AbstractApiRequest<TInputSchema, TOutputSchema, Q, H
|
|
77
|
+
call<TInputSchema extends ZodType<any, any, any>, TOutputSchema extends ZodType<any, any, any>, Q = unknown, H = unknown>(request: AbstractApiRequest<TInputSchema, TOutputSchema, Q, H>, options: {
|
|
78
|
+
pagination: false;
|
|
79
|
+
itemsPerPage?: number;
|
|
80
|
+
}): Promise<UnpaginatedResponse<output<TOutputSchema>>>;
|
|
81
|
+
call<TInputSchema extends ZodType<any, any, any>, TOutputSchema extends ZodType<any, any, any>, Q = unknown, H = unknown>(request: AbstractApiRequest<TInputSchema, TOutputSchema, Q, H>, options?: {
|
|
82
|
+
pagination?: true;
|
|
83
|
+
itemsPerPage?: number;
|
|
84
|
+
}): Promise<output<TOutputSchema>>;
|
|
45
85
|
addPlugin: <T extends ApiExtension>(plugin: ApiClientPlugin<T>) => ApiClient<T>;
|
|
46
86
|
addRequestMiddleware: (middleware: RequestMiddleware) => void;
|
|
47
87
|
addResponseMiddleware: (middleware: ResponseMiddleware) => void;
|
|
@@ -61,4 +101,4 @@ declare class OutputValidationError extends Error {
|
|
|
61
101
|
constructor(issues: ZodIssue[]);
|
|
62
102
|
}
|
|
63
103
|
|
|
64
|
-
export { AbstractApiRequest, type ApiClient, type ApiClientPlugin, type ApiExtension, InputValidationError, OutputValidationError, createApiClient };
|
|
104
|
+
export { AbstractApiRequest, type ApiClient, type ApiClientPlugin, type ApiExtension, InputValidationError, OutputValidationError, type UnpaginatedResponse, createApiClient };
|
package/dist/index.d.ts
CHANGED
|
@@ -5,11 +5,21 @@ interface ApiClientPlugin<T extends ApiExtension = Record<string, unknown>> {
|
|
|
5
5
|
setup: (client: ApiClient<Record<string, unknown>>) => T;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
+
type UnpaginatedResponse<T> = T extends {
|
|
9
|
+
data: infer U;
|
|
10
|
+
} ? U : T;
|
|
8
11
|
declare abstract class AbstractApiRequest<TInputSchema extends ZodType<any, any, any>, TOutputSchema extends ZodType<any, any, any>, Query = unknown, Headers = unknown> {
|
|
9
12
|
readonly input: input<TInputSchema>;
|
|
10
13
|
readonly options?: {
|
|
11
14
|
query?: Query;
|
|
12
15
|
headers?: Headers;
|
|
16
|
+
/**
|
|
17
|
+
* Toggle pagination at call-time if the request supports it.
|
|
18
|
+
* - true: attach pagination (if `getPagination` returns a value)
|
|
19
|
+
* - false: return a plain array of items
|
|
20
|
+
* - undefined: fall back to `paginationDefaultEnabled` (true if not set)
|
|
21
|
+
*/
|
|
22
|
+
pagination?: boolean;
|
|
13
23
|
} | undefined;
|
|
14
24
|
abstract readonly method: 'GET' | 'POST' | 'PATCH' | 'DELETE';
|
|
15
25
|
abstract readonly contentType: 'application/json' | 'multipart/form-data' | 'application/merge-patch+json';
|
|
@@ -18,16 +28,39 @@ declare abstract class AbstractApiRequest<TInputSchema extends ZodType<any, any,
|
|
|
18
28
|
abstract readonly outputSchema: TOutputSchema;
|
|
19
29
|
abstract readonly querySchema?: ZodType<Query>;
|
|
20
30
|
abstract readonly headersSchema?: ZodType<Headers>;
|
|
31
|
+
/**
|
|
32
|
+
* Optional hints to enable automatic list parsing.
|
|
33
|
+
* - If `listItemSchema` is provided, `parseResponse` will automatically
|
|
34
|
+
* parse arrays and optionally attach pagination when enabled.
|
|
35
|
+
* - Pagination attachment requires overriding `getPagination` in concrete requests
|
|
36
|
+
* to compute pagination metadata from the raw response (e.g. headers).
|
|
37
|
+
*/
|
|
38
|
+
readonly listItemSchema?: ZodType<any, any, any>;
|
|
39
|
+
/** Whether pagination is enabled by default for this request (if available). */
|
|
40
|
+
readonly paginationDefaultEnabled?: boolean;
|
|
21
41
|
protected constructor(input: input<TInputSchema>, options?: {
|
|
22
42
|
query?: Query;
|
|
23
43
|
headers?: Headers;
|
|
44
|
+
/**
|
|
45
|
+
* Toggle pagination at call-time if the request supports it.
|
|
46
|
+
* - true: attach pagination (if `getPagination` returns a value)
|
|
47
|
+
* - false: return a plain array of items
|
|
48
|
+
* - undefined: fall back to `paginationDefaultEnabled` (true if not set)
|
|
49
|
+
*/
|
|
50
|
+
pagination?: boolean;
|
|
24
51
|
} | undefined);
|
|
25
52
|
abstract getPath(): string;
|
|
53
|
+
/**
|
|
54
|
+
* Override this in list requests to provide pagination metadata from the raw HTTP response.
|
|
55
|
+
* Default implementation uses `responseToPagination`.
|
|
56
|
+
* Return `undefined` if pagination cannot be resolved.
|
|
57
|
+
*/
|
|
58
|
+
protected getPagination(rawResponse: Response): unknown | undefined;
|
|
26
59
|
validateInput(): output<TInputSchema>;
|
|
27
60
|
validateQuery(): Query | undefined;
|
|
28
61
|
validateHeaders(): Headers | undefined;
|
|
29
62
|
validateOutput(data: unknown): output<TOutputSchema>;
|
|
30
|
-
parseResponse(data: unknown, rawResponse?: Response): output<TOutputSchema>;
|
|
63
|
+
parseResponse(data: unknown, rawResponse?: Response, paginationOption?: boolean): output<TOutputSchema>;
|
|
31
64
|
}
|
|
32
65
|
type RequestContext = {
|
|
33
66
|
url: URL;
|
|
@@ -41,7 +74,14 @@ type ParsedResponse = {
|
|
|
41
74
|
type ResponseMiddleware = (parsed: ParsedResponse, requestCtx: RequestContext) => Promise<ParsedResponse> | ParsedResponse;
|
|
42
75
|
interface ApiClientBase {
|
|
43
76
|
fetch: typeof fetch;
|
|
44
|
-
call<TInputSchema extends ZodType<any, any, any>, TOutputSchema extends ZodType<any, any, any>, Q = unknown, H = unknown>(request: AbstractApiRequest<TInputSchema, TOutputSchema, Q, H
|
|
77
|
+
call<TInputSchema extends ZodType<any, any, any>, TOutputSchema extends ZodType<any, any, any>, Q = unknown, H = unknown>(request: AbstractApiRequest<TInputSchema, TOutputSchema, Q, H>, options: {
|
|
78
|
+
pagination: false;
|
|
79
|
+
itemsPerPage?: number;
|
|
80
|
+
}): Promise<UnpaginatedResponse<output<TOutputSchema>>>;
|
|
81
|
+
call<TInputSchema extends ZodType<any, any, any>, TOutputSchema extends ZodType<any, any, any>, Q = unknown, H = unknown>(request: AbstractApiRequest<TInputSchema, TOutputSchema, Q, H>, options?: {
|
|
82
|
+
pagination?: true;
|
|
83
|
+
itemsPerPage?: number;
|
|
84
|
+
}): Promise<output<TOutputSchema>>;
|
|
45
85
|
addPlugin: <T extends ApiExtension>(plugin: ApiClientPlugin<T>) => ApiClient<T>;
|
|
46
86
|
addRequestMiddleware: (middleware: RequestMiddleware) => void;
|
|
47
87
|
addResponseMiddleware: (middleware: ResponseMiddleware) => void;
|
|
@@ -61,4 +101,4 @@ declare class OutputValidationError extends Error {
|
|
|
61
101
|
constructor(issues: ZodIssue[]);
|
|
62
102
|
}
|
|
63
103
|
|
|
64
|
-
export { AbstractApiRequest, type ApiClient, type ApiClientPlugin, type ApiExtension, InputValidationError, OutputValidationError, createApiClient };
|
|
104
|
+
export { AbstractApiRequest, type ApiClient, type ApiClientPlugin, type ApiExtension, InputValidationError, OutputValidationError, type UnpaginatedResponse, createApiClient };
|