@cloudcommerce/api 0.14.0 → 0.15.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.
@@ -1,4 +1,4 @@
1
1
 
2
- > @cloudcommerce/api@0.12.1 build /home/leo/code/ecomplus/cloud-commerce/packages/api
3
- > bash ../../scripts/build-lib.sh && cp -r src/types lib/
2
+ > @cloudcommerce/api@0.14.1 build /home/leo/code/ecomplus/cloud-commerce/packages/api
3
+ > bash ../../scripts/build-lib.sh
4
4
 
@@ -1,9 +1,9 @@
1
1
 
2
- > @cloudcommerce/api@0.12.1 test /home/leo/code/ecomplus/cloud-commerce/packages/api
2
+ > @cloudcommerce/api@0.14.1 test /home/leo/code/ecomplus/cloud-commerce/packages/api
3
3
  > tsc -p ../../tsconfig.test.json && vitest run
4
4
 
5
5
 
6
- RUN v0.31.0 /home/leo/code/ecomplus/cloud-commerce/packages/api
6
+ RUN v0.32.4 /home/leo/code/ecomplus/cloud-commerce/packages/api
7
7
 
8
8
  ✓ tests/index.test.ts > Read product and typecheck SKU
9
9
  ✓ tests/index.test.ts > 404 with different Store ID from env
@@ -13,6 +13,6 @@
13
13
 
14
14
  Test Files 1 passed (1)
15
15
  Tests 5 passed (5)
16
- Start at 19:59:03
17
- Duration 1.39s (transform 180ms, setup 0ms, collect 139ms, tests 495ms, environment 0ms, prepare 150ms)
16
+ Start at 14:08:13
17
+ Duration 1.17s (transform 162ms, setup 0ms, collect 140ms, tests 456ms, environment 0ms, prepare 222ms)
18
18
 
package/lib/api.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import type { Endpoint, Config, ResponseBody, RequestBody, ErrorBody } from './types';
1
+ import type { Endpoint, Config, ResponseBody, RequestBody, ErrorBody } from '../types.d';
2
2
  declare global {
3
+ var $apiMergeConfig: Partial<Config> | undefined;
3
4
  var __apiCache: Record<string, {
4
5
  timestamp: number;
5
6
  res: Response & {
@@ -19,25 +20,25 @@ declare class ApiError extends Error {
19
20
  }
20
21
  declare const def: {
21
22
  middleware(config: Config): {
22
- url: string;
23
+ url: any;
23
24
  headers: Headers | Record<string, string>;
24
25
  };
25
26
  };
26
27
  declare const setMiddleware: (middleware: (config: Config) => {
27
- url: string;
28
+ url: any;
28
29
  headers: Headers | Record<string, string>;
29
30
  }) => void;
30
31
  declare const api: {
31
32
  <T extends Config & {
32
33
  body?: any;
33
34
  data?: any;
34
- }>(config: T, retries?: number): Promise<Response & {
35
+ }>(requestConfig: T, _retries?: number): Promise<Response & {
35
36
  config: Config;
36
37
  data: ResponseBody<T>;
37
38
  }>;
38
39
  get: <E extends Endpoint, C extends AbstractedConfig>(endpoint: E, config?: C | undefined) => Promise<Response & {
39
40
  config: Config;
40
- data: ResponseBody<{
41
+ data: ResponseBody<C & {
41
42
  endpoint: E;
42
43
  }>;
43
44
  }>;
@@ -47,7 +48,7 @@ declare const api: {
47
48
  }>, config?: (E extends "login" | "authenticate" ? AbstractedConfig : C) | undefined) => Promise<Response & {
48
49
  config: Config;
49
50
  data: E extends "login" ? {
50
- _id: import("./types").ResourceId;
51
+ _id: import("../types.d").ResourceId;
51
52
  store_ids: number[];
52
53
  api_key: string;
53
54
  } : E extends "authenticate" ? {
@@ -55,10 +56,10 @@ declare const api: {
55
56
  access_token: string;
56
57
  expires: string;
57
58
  } : {
58
- _id: import("./types").ResourceId;
59
+ _id: import("../types.d").ResourceId;
59
60
  };
60
61
  }>;
61
- put: <E_1 extends `products/${string}` | `categories/${string}` | `brands/${string}` | `collections/${string}` | `grids/${string}` | `carts/${string}` | `orders/${string}` | `customers/${string}` | `stores/${string}` | `applications/${string}` | `authentications/${string}` | ("events/products" | "events/categories" | "events/brands" | "events/collections" | "events/grids" | "events/carts" | "events/orders" | "events/customers" | "events/stores" | "events/applications" | "events/authentications" | `events/products/${string}` | `events/categories/${string}` | `events/brands/${string}` | `events/collections/${string}` | `events/grids/${string}` | `events/carts/${string}` | `events/orders/${string}` | `events/customers/${string}` | `events/stores/${string}` | `events/applications/${string}` | `events/authentications/${string}` | "events/me") | `products/${string}/${string}` | `categories/${string}/${string}` | `brands/${string}/${string}` | `collections/${string}/${string}` | `grids/${string}/${string}` | `carts/${string}/${string}` | `orders/${string}/${string}` | `customers/${string}/${string}` | `stores/${string}/${string}` | `applications/${string}/${string}` | `authentications/${string}/${string}` | `slugs/${string}` | "$aggregate/products" | "$aggregate/categories" | "$aggregate/brands" | "$aggregate/collections" | "$aggregate/grids" | "$aggregate/carts" | "$aggregate/orders" | "$aggregate/customers" | "schemas/products" | "schemas/categories" | "schemas/brands" | "schemas/collections" | "schemas/grids" | "schemas/carts" | "schemas/orders" | "schemas/customers" | "schemas/stores" | "schemas/applications" | "schemas/authentications" | "search/v1" | "login" | "authenticate" | "ask-auth-callback" | "check-username", C_1 extends AbstractedConfig>(endpoint: E_1, body: RequestBody<{
62
+ put: <E_1 extends import("../types.d").ResourceAndFind | `products/${string}/${string}` | `categories/${string}/${string}` | `brands/${string}/${string}` | `collections/${string}/${string}` | `grids/${string}/${string}` | `carts/${string}/${string}` | `orders/${string}/${string}` | `customers/${string}/${string}` | `stores/${string}/${string}` | `applications/${string}/${string}` | `authentications/${string}/${string}` | `products/${string}:${string}/${string}` | `categories/${string}:${string}/${string}` | `brands/${string}:${string}/${string}` | `collections/${string}:${string}/${string}` | `grids/${string}:${string}/${string}` | `carts/${string}:${string}/${string}` | `orders/${string}:${string}/${string}` | `customers/${string}:${string}/${string}` | `stores/${string}:${string}/${string}` | `applications/${string}:${string}/${string}` | `authentications/${string}:${string}/${string}` | `slugs/${string}` | ("search/v1" | `search/v1?${string}` | "search/_els" | `search/_els?${string}`) | ("events/products" | "events/categories" | "events/brands" | "events/collections" | "events/grids" | "events/carts" | "events/orders" | "events/customers" | "events/stores" | "events/applications" | "events/authentications" | `events/products/${string}` | `events/categories/${string}` | `events/brands/${string}` | `events/collections/${string}` | `events/grids/${string}` | `events/carts/${string}` | `events/orders/${string}` | `events/customers/${string}` | `events/stores/${string}` | `events/applications/${string}` | `events/authentications/${string}` | "events/me") | "login" | "authenticate" | "ask-auth-callback" | "check-username" | "$aggregate/products" | "$aggregate/categories" | "$aggregate/brands" | "$aggregate/collections" | "$aggregate/grids" | "$aggregate/carts" | "$aggregate/orders" | "$aggregate/customers" | "schemas/products" | "schemas/categories" | "schemas/brands" | "schemas/collections" | "schemas/grids" | "schemas/carts" | "schemas/orders" | "schemas/customers" | "schemas/stores" | "schemas/applications" | "schemas/authentications", C_1 extends AbstractedConfig>(endpoint: E_1, body: RequestBody<{
62
63
  endpoint: E_1;
63
64
  method: 'put';
64
65
  }>, config?: C_1 | undefined) => Promise<Response & {
@@ -81,7 +82,7 @@ declare const api: {
81
82
  type AbstractedConfig = Omit<Config, 'endpoint' | 'method'>;
82
83
  declare const get: <E extends Endpoint, C extends AbstractedConfig>(endpoint: E, config?: C | undefined) => Promise<Response & {
83
84
  config: Config;
84
- data: ResponseBody<{
85
+ data: ResponseBody<C & {
85
86
  endpoint: E;
86
87
  }>;
87
88
  }>;
@@ -91,7 +92,7 @@ declare const post: <E extends Endpoint, C extends AbstractedConfig>(endpoint: E
91
92
  }>, config?: (E extends "login" | "authenticate" ? AbstractedConfig : C) | undefined) => Promise<Response & {
92
93
  config: Config;
93
94
  data: E extends "login" ? {
94
- _id: import("./types").ResourceId;
95
+ _id: import("../types.d").ResourceId;
95
96
  store_ids: number[];
96
97
  api_key: string;
97
98
  } : E extends "authenticate" ? {
@@ -99,10 +100,10 @@ declare const post: <E extends Endpoint, C extends AbstractedConfig>(endpoint: E
99
100
  access_token: string;
100
101
  expires: string;
101
102
  } : {
102
- _id: import("./types").ResourceId;
103
+ _id: import("../types.d").ResourceId;
103
104
  };
104
105
  }>;
105
- declare const put: <E extends `products/${string}` | `categories/${string}` | `brands/${string}` | `collections/${string}` | `grids/${string}` | `carts/${string}` | `orders/${string}` | `customers/${string}` | `stores/${string}` | `applications/${string}` | `authentications/${string}` | ("events/products" | "events/categories" | "events/brands" | "events/collections" | "events/grids" | "events/carts" | "events/orders" | "events/customers" | "events/stores" | "events/applications" | "events/authentications" | `events/products/${string}` | `events/categories/${string}` | `events/brands/${string}` | `events/collections/${string}` | `events/grids/${string}` | `events/carts/${string}` | `events/orders/${string}` | `events/customers/${string}` | `events/stores/${string}` | `events/applications/${string}` | `events/authentications/${string}` | "events/me") | `products/${string}/${string}` | `categories/${string}/${string}` | `brands/${string}/${string}` | `collections/${string}/${string}` | `grids/${string}/${string}` | `carts/${string}/${string}` | `orders/${string}/${string}` | `customers/${string}/${string}` | `stores/${string}/${string}` | `applications/${string}/${string}` | `authentications/${string}/${string}` | `slugs/${string}` | "$aggregate/products" | "$aggregate/categories" | "$aggregate/brands" | "$aggregate/collections" | "$aggregate/grids" | "$aggregate/carts" | "$aggregate/orders" | "$aggregate/customers" | "schemas/products" | "schemas/categories" | "schemas/brands" | "schemas/collections" | "schemas/grids" | "schemas/carts" | "schemas/orders" | "schemas/customers" | "schemas/stores" | "schemas/applications" | "schemas/authentications" | "search/v1" | "login" | "authenticate" | "ask-auth-callback" | "check-username", C extends AbstractedConfig>(endpoint: E, body: RequestBody<{
106
+ declare const put: <E extends import("../types.d").ResourceAndFind | `products/${string}/${string}` | `categories/${string}/${string}` | `brands/${string}/${string}` | `collections/${string}/${string}` | `grids/${string}/${string}` | `carts/${string}/${string}` | `orders/${string}/${string}` | `customers/${string}/${string}` | `stores/${string}/${string}` | `applications/${string}/${string}` | `authentications/${string}/${string}` | `products/${string}:${string}/${string}` | `categories/${string}:${string}/${string}` | `brands/${string}:${string}/${string}` | `collections/${string}:${string}/${string}` | `grids/${string}:${string}/${string}` | `carts/${string}:${string}/${string}` | `orders/${string}:${string}/${string}` | `customers/${string}:${string}/${string}` | `stores/${string}:${string}/${string}` | `applications/${string}:${string}/${string}` | `authentications/${string}:${string}/${string}` | `slugs/${string}` | ("search/v1" | `search/v1?${string}` | "search/_els" | `search/_els?${string}`) | ("events/products" | "events/categories" | "events/brands" | "events/collections" | "events/grids" | "events/carts" | "events/orders" | "events/customers" | "events/stores" | "events/applications" | "events/authentications" | `events/products/${string}` | `events/categories/${string}` | `events/brands/${string}` | `events/collections/${string}` | `events/grids/${string}` | `events/carts/${string}` | `events/orders/${string}` | `events/customers/${string}` | `events/stores/${string}` | `events/applications/${string}` | `events/authentications/${string}` | "events/me") | "login" | "authenticate" | "ask-auth-callback" | "check-username" | "$aggregate/products" | "$aggregate/categories" | "$aggregate/brands" | "$aggregate/collections" | "$aggregate/grids" | "$aggregate/carts" | "$aggregate/orders" | "$aggregate/customers" | "schemas/products" | "schemas/categories" | "schemas/brands" | "schemas/collections" | "schemas/grids" | "schemas/carts" | "schemas/orders" | "schemas/customers" | "schemas/stores" | "schemas/applications" | "schemas/authentications", C extends AbstractedConfig>(endpoint: E, body: RequestBody<{
106
107
  endpoint: E;
107
108
  method: 'put';
108
109
  }>, config?: C | undefined) => Promise<Response & {
package/lib/api.js CHANGED
@@ -1,10 +1,8 @@
1
1
  if (!globalThis.__apiCache) {
2
2
  globalThis.__apiCache = {};
3
3
  }
4
- // @ts-ignore
5
- const _env = import.meta.env
6
- || (typeof process === 'object' && process?.env)
7
- || globalThis;
4
+ const _env = ((typeof process === 'object' && process?.env)
5
+ || globalThis);
8
6
  class ApiError extends Error {
9
7
  constructor(config, response, msg, isTimeout = false) {
10
8
  if (response) {
@@ -55,19 +53,34 @@ const def = {
55
53
  }
56
54
  }
57
55
  url += `/${endpoint}`;
58
- if (params) {
59
- if (typeof params === 'string') {
60
- url += `?${params}`;
61
- } else if (typeof params === 'object') {
56
+ if (typeof params === 'string') {
57
+ url += `?${params}`;
58
+ } else {
59
+ const paramsObj = params || {};
60
+ ['fields', 'sort']
61
+ .forEach((param) => {
62
+ const value = config[param];
63
+ if (value && !paramsObj[param]) {
64
+ paramsObj[param] = value.join(',');
65
+ }
66
+ });
67
+ ['limit', 'offset', 'count', 'buckets', 'concise', 'verbose']
68
+ .forEach((param) => {
69
+ const value = config[param];
70
+ if (value && !paramsObj[param]) {
71
+ paramsObj[param] = value;
72
+ }
73
+ });
74
+ if (Object.keys(paramsObj).length) {
62
75
  const searchParams = new URLSearchParams();
63
- Object.keys(params).forEach((key) => {
64
- const values = params[key];
76
+ Object.keys(paramsObj).forEach((key) => {
77
+ const values = paramsObj[key];
65
78
  if (Array.isArray(values)) {
66
79
  values.forEach((value) => {
67
80
  // https://github.com/microsoft/TypeScript/issues/32951
68
81
  searchParams.append(key, value);
69
82
  });
70
- } else {
83
+ } else if (values !== undefined) {
71
84
  searchParams.append(key, values);
72
85
  }
73
86
  });
@@ -80,13 +93,15 @@ const def = {
80
93
  const setMiddleware = (middleware) => {
81
94
  def.middleware = middleware;
82
95
  };
83
- const api = async (config, retries = 0) => {
96
+ const api = async (requestConfig, _retries = 0) => {
97
+ const config = globalThis.$apiMergeConfig
98
+ ? { ...globalThis.$apiMergeConfig, ...requestConfig }
99
+ : requestConfig;
84
100
  const { url, headers } = def.middleware(config);
85
101
  const {
86
102
  method = 'get', timeout = 20000, maxRetries = 3, cacheMaxAge = 600000, // 10 minutes
87
103
  } = config;
88
- const canCache = method === 'get'
89
- && (config.canCache || (config.canCache === undefined && _env.SSR));
104
+ const canCache = method === 'get' && config.canCache;
90
105
  let cacheKey;
91
106
  if (canCache) {
92
107
  cacheKey = `${url}${JSON.stringify(headers)}`;
@@ -135,11 +150,11 @@ const api = async (config, retries = 0) => {
135
150
  return { ...res, config };
136
151
  }
137
152
  const { status } = response;
138
- if (maxRetries < retries && (status === 429 || status >= 500)) {
153
+ if (maxRetries < _retries && (status === 429 || status >= 500)) {
139
154
  const retryAfter = response.headers.get('retry-after');
140
155
  return new Promise((resolve, reject) => {
141
156
  setTimeout(() => {
142
- api(config, retries + 1).then(resolve).catch(reject);
157
+ api(requestConfig, _retries + 1).then(resolve).catch(reject);
143
158
  }, (retryAfter && parseInt(retryAfter, 10)) || 5000);
144
159
  });
145
160
  }
@@ -151,19 +166,26 @@ const api = async (config, retries = 0) => {
151
166
  }
152
167
  throw new ApiError(config, response);
153
168
  };
154
- const get = (endpoint, config) => api({ ...config, endpoint });
155
- const post = (endpoint, body, config) => api({
156
- ...config,
157
- method: 'post',
158
- endpoint,
159
- body,
160
- });
161
- const put = (endpoint, body, config) => api({
162
- ...config,
163
- method: 'put',
164
- endpoint,
165
- body,
166
- });
169
+ const get = (endpoint, config) => {
170
+ // @ts-ignore
171
+ return api({ ...config, endpoint });
172
+ };
173
+ const post = (endpoint, body, config) => {
174
+ return api({
175
+ ...config,
176
+ method: 'post',
177
+ endpoint,
178
+ body,
179
+ });
180
+ };
181
+ const put = (endpoint, body, config) => {
182
+ return api({
183
+ ...config,
184
+ method: 'put',
185
+ endpoint,
186
+ body,
187
+ });
188
+ };
167
189
  const patch = (endpoint, body, config) => api({
168
190
  ...config,
169
191
  method: 'patch',
package/lib/api.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAgBA,IAAI,CAAC,UAAU,CAAC,UAAU,EAAE;IAC1B,UAAU,CAAC,UAAU,GAAG,EAAE,CAAC;CAC5B;AAED,aAAa;AACb,MAAM,IAAI,GAA2B,MAAM,CAAC,IAAI,CAAC,GAAG;OAC/C,CAAC,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,EAAE,GAAG,CAAC;OAC7C,UAAU,CAAC;AAEhB,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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K,EACL,GAAG,EACH,QAAQ,GACT,CAAC"}
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@cloudcommerce/api",
3
3
  "type": "module",
4
- "version": "0.14.0",
4
+ "version": "0.15.0",
5
5
  "description": "E-Com Plus Cloud Commerce APIs client/adapter",
6
6
  "main": "lib/api.js",
7
7
  "types": "lib/api.d.ts",
8
8
  "exports": {
9
9
  ".": "./lib/api.js",
10
- "./types": "./lib/types.d.ts"
10
+ "./types": "./types.d.ts"
11
11
  },
12
12
  "repository": {
13
13
  "type": "git",
@@ -21,7 +21,7 @@
21
21
  },
22
22
  "homepage": "https://github.com/ecomplus/cloud-commerce/tree/main/packages/api#readme",
23
23
  "scripts": {
24
- "build": "bash ../../scripts/build-lib.sh && cp -r src/types lib/",
24
+ "build": "bash ../../scripts/build-lib.sh",
25
25
  "test": "tsc -p ../../tsconfig.test.json && vitest run"
26
26
  }
27
27
  }
package/src/api.ts CHANGED
@@ -5,23 +5,27 @@ import type {
5
5
  ResponseBody,
6
6
  RequestBody,
7
7
  ErrorBody,
8
- } from './types';
8
+ } from '../types.d';
9
9
 
10
10
  declare global {
11
+ /* eslint-disable no-var, vars-on-top */
12
+ // @ts-ignore
13
+ var $apiMergeConfig: Partial<Config> | undefined;
11
14
  // eslint-disable-next-line
12
15
  var __apiCache: Record<string, {
13
16
  timestamp: number,
14
17
  res: Response & { data: any },
15
18
  }>;
19
+ /* eslint-enable no-var */
16
20
  }
17
21
  if (!globalThis.__apiCache) {
18
22
  globalThis.__apiCache = {};
19
23
  }
20
24
 
21
- // @ts-ignore
22
- const _env: Record<string, string> = import.meta.env
23
- || (typeof process === 'object' && process?.env)
24
- || globalThis;
25
+ const _env = (
26
+ (typeof process === 'object' && process?.env)
27
+ || globalThis
28
+ ) as Record<string, any>;
25
29
 
26
30
  class ApiError extends Error {
27
31
  config: Config;
@@ -86,19 +90,34 @@ const def = {
86
90
  }
87
91
  }
88
92
  url += `/${endpoint}`;
89
- if (params) {
90
- if (typeof params === 'string') {
91
- url += `?${params}`;
92
- } else if (typeof params === 'object') {
93
+ if (typeof params === 'string') {
94
+ url += `?${params}`;
95
+ } else {
96
+ const paramsObj: Exclude<typeof params, string> = params || {};
97
+ (['fields', 'sort'] as const)
98
+ .forEach((param) => {
99
+ const value = config[param];
100
+ if (value && !paramsObj[param]) {
101
+ paramsObj[param] = value.join(',');
102
+ }
103
+ });
104
+ (['limit', 'offset', 'count', 'buckets', 'concise', 'verbose'] as const)
105
+ .forEach((param) => {
106
+ const value = config[param];
107
+ if (value && !paramsObj[param]) {
108
+ paramsObj[param] = value;
109
+ }
110
+ });
111
+ if (Object.keys(paramsObj).length) {
93
112
  const searchParams = new URLSearchParams();
94
- Object.keys(params).forEach((key) => {
95
- const values = params[key];
113
+ Object.keys(paramsObj).forEach((key) => {
114
+ const values = paramsObj[key];
96
115
  if (Array.isArray(values)) {
97
116
  values.forEach((value: string | number) => {
98
117
  // https://github.com/microsoft/TypeScript/issues/32951
99
118
  searchParams.append(key, value as string);
100
119
  });
101
- } else {
120
+ } else if (values !== undefined) {
102
121
  searchParams.append(key, values as string);
103
122
  }
104
123
  });
@@ -113,11 +132,16 @@ const setMiddleware = (middleware: typeof def.middleware) => {
113
132
  def.middleware = middleware;
114
133
  };
115
134
 
116
- const api = async <T extends Config & { body?: any, data?: any }>(config: T, retries = 0):
117
- Promise<Response & {
135
+ const api = async <T extends Config & { body?: any, data?: any }>(
136
+ requestConfig: T,
137
+ _retries = 0,
138
+ ): Promise<Response & {
118
139
  config: Config,
119
140
  data: ResponseBody<T>,
120
141
  }> => {
142
+ const config = globalThis.$apiMergeConfig
143
+ ? { ...globalThis.$apiMergeConfig, ...requestConfig }
144
+ : requestConfig;
121
145
  const { url, headers } = def.middleware(config);
122
146
  const {
123
147
  method = 'get',
@@ -125,8 +149,7 @@ Promise<Response & {
125
149
  maxRetries = 3,
126
150
  cacheMaxAge = 600000, // 10 minutes
127
151
  } = config;
128
- const canCache = method === 'get'
129
- && (config.canCache || (config.canCache === undefined && _env.SSR));
152
+ const canCache = method === 'get' && config.canCache;
130
153
  let cacheKey: string | undefined;
131
154
  if (canCache) {
132
155
  cacheKey = `${url}${JSON.stringify(headers)}`;
@@ -177,11 +200,11 @@ Promise<Response & {
177
200
  return { ...res, config };
178
201
  }
179
202
  const { status } = response;
180
- if (maxRetries < retries && (status === 429 || status >= 500)) {
203
+ if (maxRetries < _retries && (status === 429 || status >= 500)) {
181
204
  const retryAfter = response.headers.get('retry-after');
182
205
  return new Promise((resolve, reject) => {
183
206
  setTimeout(() => {
184
- api(config, retries + 1).then(resolve).catch(reject);
207
+ api(requestConfig, _retries + 1).then(resolve).catch(reject);
185
208
  }, (retryAfter && parseInt(retryAfter, 10)) || 5000);
186
209
  });
187
210
  }
@@ -201,30 +224,37 @@ const get = <E extends Endpoint, C extends AbstractedConfig>(
201
224
  config?: C,
202
225
  ): Promise<Response & {
203
226
  config: Config,
204
- data: ResponseBody<{ endpoint: E }>,
205
- }> => api({ ...config, endpoint });
227
+ data: ResponseBody<C & { endpoint: E }>,
228
+ }> => {
229
+ // @ts-ignore
230
+ return api({ ...config, endpoint });
231
+ };
206
232
 
207
233
  const post = <E extends Endpoint, C extends AbstractedConfig>(
208
234
  endpoint: E,
209
235
  body: RequestBody<{ endpoint: E, method: 'post' }>,
210
236
  config?: E extends 'login' | 'authenticate' ? AbstractedConfig : C,
211
- ) => api({
237
+ ) => {
238
+ return api({
212
239
  ...config,
213
240
  method: 'post',
214
241
  endpoint,
215
242
  body,
216
243
  });
244
+ };
217
245
 
218
246
  const put = <E extends Exclude<Endpoint, ResourceOpQuery>, C extends AbstractedConfig>(
219
247
  endpoint: E,
220
248
  body: RequestBody<{ endpoint: E, method: 'put' }>,
221
249
  config?: C,
222
- ) => api({
250
+ ) => {
251
+ return api({
223
252
  ...config,
224
253
  method: 'put',
225
254
  endpoint,
226
255
  body,
227
256
  });
257
+ };
228
258
 
229
259
  const patch = (endpoint: Endpoint, body: any, config?: AbstractedConfig) => api({
230
260
  ...config,
@@ -1,9 +1,9 @@
1
1
  /* eslint-disable no-console, import/no-extraneous-dependencies */
2
2
 
3
3
  import { test, expect } from 'vitest';
4
- import api, { ApiError } from '../src/api';
4
+ import api, { type ApiError } from '../src/api';
5
5
 
6
- const productId = '618041aa239b7206d3fc06de';
6
+ const productId = '618041aa239b7206d3fc06de' as string & { length: 24 };
7
7
  test('Read product and typecheck SKU', async () => {
8
8
  const { data } = await api({
9
9
  storeId: 1056,
@@ -30,13 +30,28 @@ test('404 with different Store ID from env', async () => {
30
30
  });
31
31
 
32
32
  test('List categories and typecheck result', async () => {
33
- const { data } = await api.get('categories');
33
+ const { data } = await api.get('categories', {
34
+ fields: ['name'] as const,
35
+ });
34
36
  if (!data.result.length) {
35
37
  console.log('Any category found');
36
38
  }
37
39
  expect(Array.isArray(data.result)).toBe(true);
40
+ expect(data.result[0].name).toBeTypeOf('string');
41
+ // @ts-ignore
42
+ expect(data.result[0].slug).toBeTypeOf('undefined');
38
43
  expect(data.meta).toBeTypeOf('object');
39
44
  expect(data.meta.offset).toBeTypeOf('number');
45
+ const { data: data2 } = await api.get('categories', {
46
+ limit: 1,
47
+ });
48
+ expect(data2.result.length).toBe(1);
49
+ const { data: data3 } = await api.get('categories', {
50
+ params: {
51
+ slug: 'this-slug-doesnt-exists-123',
52
+ },
53
+ });
54
+ expect(data3.result.length).toBe(0);
40
55
  });
41
56
 
42
57
  test('401 trying to list API events', async () => {
@@ -105,7 +105,7 @@ export interface Brands {
105
105
  /**
106
106
  * Picture ID (ObjectID) [auto]
107
107
  */
108
- _id?: string;
108
+ _id?: string & { length: 24 };
109
109
  /**
110
110
  * Tag to identify object, use only lowercase letters, digits and underscore
111
111
  */
@@ -85,15 +85,15 @@ export interface Carts {
85
85
  /**
86
86
  * Cart item ID (ObjectID) [auto]
87
87
  */
88
- _id?: string;
88
+ _id?: string & { length: 24 };
89
89
  /**
90
90
  * Product ID
91
91
  */
92
- product_id: string;
92
+ product_id: string & { length: 24 };
93
93
  /**
94
94
  * ID to specify the variation added to cart, if product has variations
95
95
  */
96
- variation_id?: string;
96
+ variation_id?: string & { length: 24 };
97
97
  /**
98
98
  * Product or variation SKU (reference code)
99
99
  */
@@ -128,7 +128,7 @@ export interface Carts {
128
128
  /**
129
129
  * Option ID (ObjectID) if it was predefined (not custom value created by customer)
130
130
  */
131
- _id?: string;
131
+ _id?: string & { length: 24 };
132
132
  /**
133
133
  * Option text value displayed for the client
134
134
  */
@@ -185,7 +185,7 @@ export interface Carts {
185
185
  /**
186
186
  * Selected variation ID (ObjectID) if any
187
187
  */
188
- variation_id?: string;
188
+ variation_id?: string & { length: 24 };
189
189
  /**
190
190
  * Kit item quantity
191
191
  */
@@ -86,7 +86,7 @@ export interface Categories {
86
86
  /**
87
87
  * Parent category ID (ObjectID)
88
88
  */
89
- _id?: string;
89
+ _id?: string & { length: 24 };
90
90
  /**
91
91
  * Parent category name
92
92
  */
@@ -139,7 +139,7 @@ export interface Categories {
139
139
  /**
140
140
  * Picture ID (ObjectID) [auto]
141
141
  */
142
- _id?: string;
142
+ _id?: string & { length: 24 };
143
143
  /**
144
144
  * Tag to identify object, use only lowercase letters, digits and underscore
145
145
  */
@@ -80,7 +80,7 @@ export interface Collections {
80
80
  *
81
81
  * @maxItems 3000
82
82
  */
83
- products?: string[];
83
+ products?: Array<string & { length: 24 }>;
84
84
  /**
85
85
  * Collection icon image
86
86
  */
@@ -107,7 +107,7 @@ export interface Collections {
107
107
  /**
108
108
  * Picture ID (ObjectID) [auto]
109
109
  */
110
- _id?: string;
110
+ _id?: string & { length: 24 };
111
111
  /**
112
112
  * Tag to identify object, use only lowercase letters, digits and underscore
113
113
  */
@@ -346,7 +346,7 @@ export interface Customers {
346
346
  /**
347
347
  * Points origin order ID (ObjectID)
348
348
  */
349
- order_id?: string;
349
+ order_id?: string & { length: 24 };
350
350
  }[];
351
351
  /**
352
352
  * The total amount of money that this customer has spent at the store
@@ -44,7 +44,7 @@ export interface Grids {
44
44
  /**
45
45
  * Option ID (ObjectID) [auto]
46
46
  */
47
- _id?: string;
47
+ _id?: string & { length: 24 };
48
48
  /**
49
49
  * Option text value displayed for the client
50
50
  */