@deliverart/sdk-js-core 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @deliverart/sdk-js-core
2
2
 
3
+ ## 0.1.2
4
+
5
+ ### Patch Changes
6
+
7
+ - b204aab: Add parseResponse method
8
+
9
+ ## 0.1.1
10
+
11
+ ### Patch Changes
12
+
13
+ - 20b57df: Expose errors
14
+
3
15
  ## 0.1.0
4
16
 
5
17
  ### Minor Changes
package/dist/index.cjs CHANGED
@@ -31,6 +31,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
33
  AbstractApiRequest: () => AbstractApiRequest,
34
+ InputValidationError: () => InputValidationError,
35
+ OutputValidationError: () => OutputValidationError,
34
36
  createApiClient: () => createApiClient
35
37
  });
36
38
  module.exports = __toCommonJS(index_exports);
@@ -92,6 +94,9 @@ var AbstractApiRequest = class {
92
94
  }
93
95
  return result.data;
94
96
  }
97
+ parseResponse(data) {
98
+ return this.validateOutput(data);
99
+ }
95
100
  };
96
101
  function createApiClient(config) {
97
102
  const http = import_axios.default.create({ baseURL: config.baseUrl });
@@ -112,7 +117,7 @@ function createApiClient(config) {
112
117
  params: query,
113
118
  data: request.method !== "GET" ? input : void 0
114
119
  });
115
- return request.validateOutput(res.data);
120
+ return request.parseResponse(res.data);
116
121
  },
117
122
  addPlugin(plugin) {
118
123
  const extension = plugin.setup(this);
@@ -124,5 +129,7 @@ function createApiClient(config) {
124
129
  // Annotate the CommonJS export names for ESM import in node:
125
130
  0 && (module.exports = {
126
131
  AbstractApiRequest,
132
+ InputValidationError,
133
+ OutputValidationError,
127
134
  createApiClient
128
135
  });
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { AxiosInstance } from 'axios';
2
- import { ZodSchema } from 'zod';
2
+ import { ZodSchema, ZodIssue } from 'zod';
3
3
 
4
4
  type ApiExtension = Record<string, unknown>;
5
5
  interface ApiClientPlugin<T extends ApiExtension = Record<string, unknown>> {
@@ -28,6 +28,7 @@ declare abstract class AbstractApiRequest<Input, Output, Query = unknown, Header
28
28
  validateQuery(): Query | undefined;
29
29
  validateHeaders(): Headers | undefined;
30
30
  validateOutput(data: unknown): Output;
31
+ parseResponse(data: unknown): Output;
31
32
  }
32
33
  interface ApiClientBase {
33
34
  http: AxiosInstance;
@@ -39,4 +40,13 @@ declare function createApiClient<Extensions extends ApiExtension = NonNullable<u
39
40
  }): ApiClient<Extensions>;
40
41
  type ApiClient<Extensions extends ApiExtension = NonNullable<unknown>> = ApiClientBase & Extensions;
41
42
 
42
- export { AbstractApiRequest, type ApiClient, type ApiClientPlugin, type ApiExtension, createApiClient };
43
+ declare class InputValidationError extends Error {
44
+ readonly issues: ZodIssue[];
45
+ constructor(issues: ZodIssue[]);
46
+ }
47
+ declare class OutputValidationError extends Error {
48
+ readonly issues: ZodIssue[];
49
+ constructor(issues: ZodIssue[]);
50
+ }
51
+
52
+ export { AbstractApiRequest, type ApiClient, type ApiClientPlugin, type ApiExtension, InputValidationError, OutputValidationError, createApiClient };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { AxiosInstance } from 'axios';
2
- import { ZodSchema } from 'zod';
2
+ import { ZodSchema, ZodIssue } from 'zod';
3
3
 
4
4
  type ApiExtension = Record<string, unknown>;
5
5
  interface ApiClientPlugin<T extends ApiExtension = Record<string, unknown>> {
@@ -28,6 +28,7 @@ declare abstract class AbstractApiRequest<Input, Output, Query = unknown, Header
28
28
  validateQuery(): Query | undefined;
29
29
  validateHeaders(): Headers | undefined;
30
30
  validateOutput(data: unknown): Output;
31
+ parseResponse(data: unknown): Output;
31
32
  }
32
33
  interface ApiClientBase {
33
34
  http: AxiosInstance;
@@ -39,4 +40,13 @@ declare function createApiClient<Extensions extends ApiExtension = NonNullable<u
39
40
  }): ApiClient<Extensions>;
40
41
  type ApiClient<Extensions extends ApiExtension = NonNullable<unknown>> = ApiClientBase & Extensions;
41
42
 
42
- export { AbstractApiRequest, type ApiClient, type ApiClientPlugin, type ApiExtension, createApiClient };
43
+ declare class InputValidationError extends Error {
44
+ readonly issues: ZodIssue[];
45
+ constructor(issues: ZodIssue[]);
46
+ }
47
+ declare class OutputValidationError extends Error {
48
+ readonly issues: ZodIssue[];
49
+ constructor(issues: ZodIssue[]);
50
+ }
51
+
52
+ export { AbstractApiRequest, type ApiClient, type ApiClientPlugin, type ApiExtension, InputValidationError, OutputValidationError, createApiClient };
package/dist/index.js CHANGED
@@ -55,6 +55,9 @@ var AbstractApiRequest = class {
55
55
  }
56
56
  return result.data;
57
57
  }
58
+ parseResponse(data) {
59
+ return this.validateOutput(data);
60
+ }
58
61
  };
59
62
  function createApiClient(config) {
60
63
  const http = axios.create({ baseURL: config.baseUrl });
@@ -75,7 +78,7 @@ function createApiClient(config) {
75
78
  params: query,
76
79
  data: request.method !== "GET" ? input : void 0
77
80
  });
78
- return request.validateOutput(res.data);
81
+ return request.parseResponse(res.data);
79
82
  },
80
83
  addPlugin(plugin) {
81
84
  const extension = plugin.setup(this);
@@ -86,5 +89,7 @@ function createApiClient(config) {
86
89
  }
87
90
  export {
88
91
  AbstractApiRequest,
92
+ InputValidationError,
93
+ OutputValidationError,
89
94
  createApiClient
90
95
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@deliverart/sdk-js-core",
3
3
  "description": "Core SDK for DeliverArt, providing essential functionalities and utilities.",
4
- "version": "0.1.0",
4
+ "version": "0.1.2",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
package/src/ApiClient.ts CHANGED
@@ -63,6 +63,10 @@ export abstract class AbstractApiRequest<Input, Output, Query = unknown, Headers
63
63
  }
64
64
  return result.data
65
65
  }
66
+
67
+ parseResponse(data: unknown): Output {
68
+ return this.validateOutput(data)
69
+ }
66
70
  }
67
71
 
68
72
  interface ApiClientBase {
@@ -98,7 +102,7 @@ export function createApiClient<Extensions extends ApiExtension = NonNullable<un
98
102
  data: request.method !== 'GET' ? input : undefined,
99
103
  })
100
104
 
101
- return request.validateOutput(res.data)
105
+ return request.parseResponse(res.data)
102
106
  },
103
107
 
104
108
  addPlugin<T extends ApiExtension>(plugin: ApiClientPlugin<T>) {
package/src/index.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './ApiClient'
2
+ export * from './errors'
2
3
  export * from './types'