@cloudcommerce/api 0.0.40 → 0.0.43
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/.turbo/turbo-build.log +2 -2
- package/.turbo/turbo-test.log +20 -18
- package/lib/index.d.ts +9 -3
- package/lib/index.js +12 -2
- package/lib/index.js.map +1 -1
- package/lib/types.d.ts +12 -2
- package/package.json +1 -1
- package/src/index.ts +28 -5
- package/src/types.ts +13 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
[35m@cloudcommerce/api:build[0m: cache hit, replaying output [
|
|
1
|
+
[35m@cloudcommerce/api:build[0m: cache hit, replaying output [2m06315149adc38209[0m
|
|
2
2
|
[35m@cloudcommerce/api:build: [0m
|
|
3
|
-
[35m@cloudcommerce/api:build: [0m> @cloudcommerce/api@0.0.
|
|
3
|
+
[35m@cloudcommerce/api:build: [0m> @cloudcommerce/api@0.0.42 build /home/leo/code/ecomplus/cloud-commerce/packages/api
|
|
4
4
|
[35m@cloudcommerce/api:build: [0m> sh ../../scripts/build-lib.sh && cp -r src/types lib/
|
|
5
5
|
[35m@cloudcommerce/api:build: [0m
|
package/.turbo/turbo-test.log
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
[
|
|
2
|
-
[
|
|
3
|
-
[
|
|
4
|
-
[
|
|
5
|
-
[
|
|
6
|
-
[
|
|
7
|
-
[
|
|
8
|
-
[
|
|
9
|
-
[
|
|
10
|
-
[
|
|
11
|
-
[
|
|
12
|
-
[
|
|
13
|
-
[
|
|
14
|
-
[
|
|
15
|
-
[
|
|
16
|
-
[
|
|
17
|
-
[
|
|
18
|
-
[
|
|
1
|
+
[35m@cloudcommerce/api:test[0m: cache hit, replaying output [2m8e4df92d0547e596[0m
|
|
2
|
+
[35m@cloudcommerce/api:test: [0m
|
|
3
|
+
[35m@cloudcommerce/api:test: [0m> @cloudcommerce/api@0.0.42 test /home/leo/code/ecomplus/cloud-commerce/packages/api
|
|
4
|
+
[35m@cloudcommerce/api:test: [0m> tsc -p ../../tsconfig.test.json && vitest run
|
|
5
|
+
[35m@cloudcommerce/api:test: [0m
|
|
6
|
+
[35m@cloudcommerce/api:test: [0m
|
|
7
|
+
[35m@cloudcommerce/api:test: [0m RUN v0.20.2 /home/leo/code/ecomplus/cloud-commerce/packages/api
|
|
8
|
+
[35m@cloudcommerce/api:test: [0m
|
|
9
|
+
[35m@cloudcommerce/api:test: [0m ✓ tests/index.test.ts > Read product and typecheck SKU
|
|
10
|
+
[35m@cloudcommerce/api:test: [0m(node:41553) [https://github.com/node-fetch/node-fetch/issues/1000 (response)] DeprecationWarning: data doesn't exist, use json(), text(), arrayBuffer(), or body instead
|
|
11
|
+
[35m@cloudcommerce/api:test: [0m(Use `node --trace-deprecation ...` to show where the warning was created)
|
|
12
|
+
[35m@cloudcommerce/api:test: [0m ✓ tests/index.test.ts > 404 with different Store ID from env
|
|
13
|
+
[35m@cloudcommerce/api:test: [0m ✓ tests/index.test.ts > List categories and typecheck result
|
|
14
|
+
[35m@cloudcommerce/api:test: [0m ✓ tests/index.test.ts > 401 trying to list API events
|
|
15
|
+
[35m@cloudcommerce/api:test: [0m ✓ tests/index.test.ts > 401 to create category and body typecheck
|
|
16
|
+
[35m@cloudcommerce/api:test: [0m
|
|
17
|
+
[35m@cloudcommerce/api:test: [0mTest Files 1 passed (1)
|
|
18
|
+
[35m@cloudcommerce/api:test: [0m Tests 5 passed (5)
|
|
19
|
+
[35m@cloudcommerce/api:test: [0m Time 3.14s (setup 0ms, collect 117ms, tests 1.53s)
|
|
20
|
+
[35m@cloudcommerce/api:test: [0m
|
package/lib/index.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import type { ResourceOpQuery, Endpoint, Config, ResponseBody, RequestBody } from './types';
|
|
1
|
+
import type { ResourceOpQuery, Endpoint, Config, ResponseBody, RequestBody, ErrorBody } from './types';
|
|
2
2
|
declare class ApiError extends Error {
|
|
3
3
|
config: Config;
|
|
4
|
-
response?: Response
|
|
4
|
+
response?: Response & {
|
|
5
|
+
data?: ErrorBody;
|
|
6
|
+
};
|
|
5
7
|
statusCode?: number;
|
|
8
|
+
data?: ErrorBody;
|
|
6
9
|
isTimeout: boolean;
|
|
7
|
-
constructor(config: Config, response?:
|
|
10
|
+
constructor(config: Config, response?: ApiError['response'], msg?: string, isTimeout?: boolean);
|
|
8
11
|
}
|
|
9
12
|
declare const def: {
|
|
10
13
|
middleware(config: Config): {
|
|
@@ -10030,3 +10033,6 @@ declare const del: (endpoint: Endpoint, config: AbstractedAuthConfig) => Promise
|
|
|
10030
10033
|
}>;
|
|
10031
10034
|
export default api;
|
|
10032
10035
|
export { setMiddleware, get, post, put, patch, del, ApiError, };
|
|
10036
|
+
export declare type ApiEndpoint = Endpoint;
|
|
10037
|
+
export declare type ApiConfig = Config;
|
|
10038
|
+
export declare type ApiErrorBody = ErrorBody;
|
package/lib/index.js
CHANGED
|
@@ -4,10 +4,15 @@ const env = (typeof window === 'object' && window)
|
|
|
4
4
|
|| {};
|
|
5
5
|
class ApiError extends Error {
|
|
6
6
|
constructor(config, response, msg, isTimeout = false) {
|
|
7
|
-
|
|
7
|
+
if (response) {
|
|
8
|
+
super(response.statusText);
|
|
9
|
+
this.data = response.data;
|
|
10
|
+
this.statusCode = response.status;
|
|
11
|
+
} else {
|
|
12
|
+
super(msg || 'Request error');
|
|
13
|
+
}
|
|
8
14
|
this.config = config;
|
|
9
15
|
this.response = response;
|
|
10
|
-
this.statusCode = response?.status;
|
|
11
16
|
this.isTimeout = isTimeout;
|
|
12
17
|
}
|
|
13
18
|
}
|
|
@@ -101,6 +106,11 @@ const api = async (config, retries = 0) => {
|
|
|
101
106
|
});
|
|
102
107
|
}
|
|
103
108
|
}
|
|
109
|
+
try {
|
|
110
|
+
response.data = await response?.json();
|
|
111
|
+
} catch (e) {
|
|
112
|
+
//
|
|
113
|
+
}
|
|
104
114
|
throw new ApiError(config, response);
|
|
105
115
|
};
|
|
106
116
|
const get = (endpoint, config) => api({ ...config, endpoint });
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,aAAa;AACb,MAAM,GAAG,GAA8B,CAAC,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC;OACxE,CAAC,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC;OACvD,EAAE,CAAC;AAER,MAAM,QAAS,SAAQ,KAAK;IAM1B,YACE,MAAc,EACd,QAA+B,EAC/B,GAAY,EACZ,YAAqB,KAAK;QAE1B,IAAI,QAAQ,EAAE;YACZ,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;YAC3B,IAAI,CAAC,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC;YAC1B,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAC;SACnC;aAAM;YACL,KAAK,CAAC,GAAG,IAAI,eAAe,CAAC,CAAC;SAC/B;QACD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;CACF;AAED,MAAM,GAAG,GAAG;IACV,UAAU,CAAC,MAAc;QACvB,MAAM,OAAO,GAAqC,EAAE,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC;QACxE,IAAI,MAAM,CAAC,WAAW,EAAE;YACtB,wCAAwC;YACxC,OAAO,CAAC,eAAe,CAAC,GAAG,UAAU,MAAM,CAAC,WAAW,EAAE,CAAC;SAC3D;aAAM,IAAI,MAAM,CAAC,gBAAgB,IAAI,MAAM,CAAC,MAAM,EAAE;YACnD,MAAM,OAAO,G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IAAI,GAAG,CACX,QAAW,EACX,IAAkD,EAClD,MAAiE,EACjE,EAAE,CAAC,GAAG,CAAC;IACL,GAAG,MAAM;IACT,MAAM,EAAE,MAAM;IACd,QAAQ;IACR,IAAI;CACL,CAAC,CAAC;AAEL,MAAM,GAAG,GAAG,CACV,QAAW,EACX,IAAiD,EACjD,MAAS,EACT,EAAE,CAAC,GAAG,CAAC;IACL,GAAG,MAAM;IACT,MAAM,EAAE,KAAK;IACb,QAAQ;IACR,IAAI;CACL,CAAC,CAAC;AAEL,MAAM,KAAK,GAAG,CAAC,QAAkB,EAAE,IAAS,EAAE,MAA4B,EAAE,EAAE,CAAC,GAAG,CAAC;IACjF,GAAG,MAAM;IACT,MAAM,EAAE,OAAO;IACf,QAAQ;IACR,IAAI;CACL,CAAC,CAAC;AAEH,MAAM,GAAG,GAAG,CAAC,QAAkB,EAAE,MAA4B,EAAE,EAAE,CAAC,GAAG,CAAC;IACpE,GAAG,MAAM;IACT,MAAM,EAAE,QAAQ;IAChB,QAAQ;CACT,CAAC,CAAC;AAEH,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC;AACd,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;AAChB,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC;AACd,GAAG,CAAC,KAAK,GAAG,KAAK,CAAC;AAClB,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC;AACd,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC;AAEjB,eAAe,GAAG,CAAC;AAEnB,OAAO,EACL,aAAa,EACb,GAAG,EACH,IAAI,EACJ,GAAG,EACH,KAAK,EACL,GAAG,EACH,QAAQ,GACT,CAAC"}
|
package/lib/types.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ declare type Config = {
|
|
|
27
27
|
lang?: string;
|
|
28
28
|
method?: Method;
|
|
29
29
|
endpoint: Endpoint;
|
|
30
|
-
params?: Record<string, string | number>;
|
|
30
|
+
params?: Record<string, string | number | boolean>;
|
|
31
31
|
headers?: Headers | Record<string, string>;
|
|
32
32
|
timeout?: number;
|
|
33
33
|
maxRetries?: number;
|
|
@@ -91,4 +91,14 @@ declare type ResponseBody<TConfig extends Config> = TConfig['method'] extends 'p
|
|
|
91
91
|
declare type DocSchema<Document extends any> = Omit<Document, '_id' | 'store_id' | 'store_ids' | 'created_at' | 'updated_at'>;
|
|
92
92
|
declare type SetDocEndpoint<TResource extends Resource> = TResource | `${TResource}/${ResourceId}`;
|
|
93
93
|
declare type RequestBody<TConfig extends Config> = TConfig['method'] extends undefined | 'get' | 'delete' ? undefined : TConfig['method'] extends 'patch' ? any : TConfig['endpoint'] extends SetDocEndpoint<'products'> ? DocSchema<Products> : TConfig['endpoint'] extends SetDocEndpoint<'categories'> ? DocSchema<Categories> : TConfig['endpoint'] extends SetDocEndpoint<'brands'> ? DocSchema<Brands> : TConfig['endpoint'] extends SetDocEndpoint<'collections'> ? DocSchema<Collections> : TConfig['endpoint'] extends SetDocEndpoint<'grids'> ? DocSchema<Grids> : TConfig['endpoint'] extends SetDocEndpoint<'carts'> ? DocSchema<Carts> : TConfig['endpoint'] extends SetDocEndpoint<'orders'> ? DocSchema<Orders> : TConfig['endpoint'] extends SetDocEndpoint<'customers'> ? DocSchema<Customers> : TConfig['endpoint'] extends SetDocEndpoint<'stores'> ? DocSchema<Stores> : TConfig['endpoint'] extends SetDocEndpoint<'applications'> ? DocSchema<Applications> : TConfig['endpoint'] extends SetDocEndpoint<'authentications'> ? DocSchema<Authentications> : any;
|
|
94
|
-
|
|
94
|
+
declare type ErrorBody = {
|
|
95
|
+
status: number;
|
|
96
|
+
error_code: number;
|
|
97
|
+
message: string;
|
|
98
|
+
user_message?: {
|
|
99
|
+
en_us: string;
|
|
100
|
+
pt_br: string;
|
|
101
|
+
};
|
|
102
|
+
more_info?: string;
|
|
103
|
+
};
|
|
104
|
+
export type { Products, Categories, Brands, Collections, Grids, Carts, Orders, Customers, Stores, Applications, Authentications, Resource, ResourceId, ResourceAndId, ResourceOpQuery, Endpoint, Method, Config, ResourceListResult, EventsResult, ResponseBody, RequestBody, ErrorBody, };
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
Config,
|
|
5
5
|
ResponseBody,
|
|
6
6
|
RequestBody,
|
|
7
|
+
ErrorBody,
|
|
7
8
|
} from './types';
|
|
8
9
|
|
|
9
10
|
// @ts-ignore
|
|
@@ -13,14 +14,25 @@ const env: { [key: string]: string } = (typeof window === 'object' && window)
|
|
|
13
14
|
|
|
14
15
|
class ApiError extends Error {
|
|
15
16
|
config: Config;
|
|
16
|
-
response?: Response;
|
|
17
|
+
response?: Response & { data?: ErrorBody };
|
|
17
18
|
statusCode?: number;
|
|
19
|
+
data?: ErrorBody;
|
|
18
20
|
isTimeout: boolean;
|
|
19
|
-
constructor(
|
|
20
|
-
|
|
21
|
+
constructor(
|
|
22
|
+
config: Config,
|
|
23
|
+
response?: ApiError['response'],
|
|
24
|
+
msg?: string,
|
|
25
|
+
isTimeout: boolean = false,
|
|
26
|
+
) {
|
|
27
|
+
if (response) {
|
|
28
|
+
super(response.statusText);
|
|
29
|
+
this.data = response.data;
|
|
30
|
+
this.statusCode = response.status;
|
|
31
|
+
} else {
|
|
32
|
+
super(msg || 'Request error');
|
|
33
|
+
}
|
|
21
34
|
this.config = config;
|
|
22
35
|
this.response = response;
|
|
23
|
-
this.statusCode = response?.status;
|
|
24
36
|
this.isTimeout = isTimeout;
|
|
25
37
|
}
|
|
26
38
|
}
|
|
@@ -98,7 +110,7 @@ Promise<Response & {
|
|
|
98
110
|
abortController.abort();
|
|
99
111
|
isTimeout = true;
|
|
100
112
|
}, timeout);
|
|
101
|
-
let response: Response | undefined;
|
|
113
|
+
let response: Response & { data?: any } | undefined;
|
|
102
114
|
try {
|
|
103
115
|
response = await (config.fetch || fetch)(url, {
|
|
104
116
|
method,
|
|
@@ -129,6 +141,11 @@ Promise<Response & {
|
|
|
129
141
|
});
|
|
130
142
|
}
|
|
131
143
|
}
|
|
144
|
+
try {
|
|
145
|
+
response.data = await response?.json() as ErrorBody;
|
|
146
|
+
} catch (e) {
|
|
147
|
+
//
|
|
148
|
+
}
|
|
132
149
|
throw new ApiError(config, response);
|
|
133
150
|
};
|
|
134
151
|
|
|
@@ -197,3 +214,9 @@ export {
|
|
|
197
214
|
del,
|
|
198
215
|
ApiError,
|
|
199
216
|
};
|
|
217
|
+
|
|
218
|
+
export type ApiEndpoint = Endpoint;
|
|
219
|
+
|
|
220
|
+
export type ApiConfig = Config;
|
|
221
|
+
|
|
222
|
+
export type ApiErrorBody = ErrorBody;
|
package/src/types.ts
CHANGED
|
@@ -56,7 +56,7 @@ type Config = {
|
|
|
56
56
|
lang?: string,
|
|
57
57
|
method?: Method,
|
|
58
58
|
endpoint: Endpoint,
|
|
59
|
-
params?: Record<string, string | number>,
|
|
59
|
+
params?: Record<string, string | number | boolean>,
|
|
60
60
|
headers?: Headers | Record<string, string>,
|
|
61
61
|
timeout?: number,
|
|
62
62
|
maxRetries?: number,
|
|
@@ -171,6 +171,17 @@ type RequestBody<TConfig extends Config> =
|
|
|
171
171
|
TConfig['endpoint'] extends SetDocEndpoint<'authentications'> ? DocSchema<Authentications> :
|
|
172
172
|
any;
|
|
173
173
|
|
|
174
|
+
type ErrorBody = {
|
|
175
|
+
status: number,
|
|
176
|
+
error_code: number,
|
|
177
|
+
message: string,
|
|
178
|
+
user_message?: {
|
|
179
|
+
en_us: string,
|
|
180
|
+
pt_br: string,
|
|
181
|
+
},
|
|
182
|
+
more_info?: string,
|
|
183
|
+
};
|
|
184
|
+
|
|
174
185
|
export type {
|
|
175
186
|
Products,
|
|
176
187
|
Categories,
|
|
@@ -194,4 +205,5 @@ export type {
|
|
|
194
205
|
EventsResult,
|
|
195
206
|
ResponseBody,
|
|
196
207
|
RequestBody,
|
|
208
|
+
ErrorBody,
|
|
197
209
|
};
|