cloudcommerce 0.0.4 → 0.0.7

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 (39) hide show
  1. package/.eslintrc.cjs +2 -1
  2. package/CHANGELOG.md +35 -0
  3. package/package.json +10 -9
  4. package/packages/api/lib/index.d.ts +183 -0
  5. package/packages/api/lib/index.js +115 -0
  6. package/packages/api/lib/index.js.map +1 -0
  7. package/packages/api/{dist → lib}/types/applications.d.ts +0 -0
  8. package/packages/api/{dist → lib}/types/authentications.d.ts +0 -0
  9. package/packages/api/{dist → lib}/types/brands.d.ts +0 -0
  10. package/packages/api/{dist → lib}/types/carts.d.ts +0 -0
  11. package/packages/api/{dist → lib}/types/categories.d.ts +0 -0
  12. package/packages/api/{dist → lib}/types/collections.d.ts +0 -0
  13. package/packages/api/{dist → lib}/types/customers.d.ts +0 -0
  14. package/packages/api/{dist → lib}/types/grids.d.ts +0 -0
  15. package/packages/api/{dist → lib}/types/orders.d.ts +0 -0
  16. package/packages/api/{dist → lib}/types/products.d.ts +0 -0
  17. package/packages/api/{dist → lib}/types/stores.d.ts +0 -0
  18. package/packages/api/lib/types.d.ts +77 -0
  19. package/packages/api/lib/types.js +2 -0
  20. package/packages/api/{dist → lib}/types.js.map +0 -0
  21. package/packages/api/package.json +5 -5
  22. package/packages/api/scripts/build.sh +6 -0
  23. package/packages/api/src/index.ts +74 -34
  24. package/packages/api/src/types.ts +96 -16
  25. package/packages/api/tests/index.test.ts +50 -10
  26. package/packages/api/tsconfig.json +6 -0
  27. package/packages/apps/discounts/package.json +1 -1
  28. package/packages/storefront/package.json +3 -2
  29. package/tsconfig.json +2 -1
  30. package/tsconfig.test.json +5 -100
  31. package/turbo.json +6 -1
  32. package/vite.config.ts +12 -0
  33. package/packages/api/dist/index.d.ts +0 -65
  34. package/packages/api/dist/index.js +0 -89
  35. package/packages/api/dist/index.js.map +0 -1
  36. package/packages/api/dist/types.d.ts +0 -65
  37. package/packages/api/dist/types.js +0 -2
  38. package/packages/api/scripts/build.mjs +0 -5
  39. package/packages/api/scripts/test.mjs +0 -4
package/.eslintrc.cjs CHANGED
@@ -26,6 +26,8 @@ module.exports = {
26
26
  'no-param-reassign': 'warn',
27
27
  'no-underscore-dangle': 'off',
28
28
  'no-continue': 'off',
29
+ 'lines-between-class-members': 'off',
30
+ 'arrow-body-style': 'off',
29
31
  'import/extensions': [
30
32
  'error',
31
33
  'ignorePackages',
@@ -42,7 +44,6 @@ module.exports = {
42
44
  { blankLine: 'never', prev: 'directive', next: 'directive' },
43
45
  { blankLine: 'never', prev: 'import', next: 'import' },
44
46
  ],
45
- 'arrow-body-style': 'off',
46
47
  'import/order': [
47
48
  'error',
48
49
  { groups: ['type', 'builtin', 'external', 'parent', 'sibling', 'index'] },
package/CHANGELOG.md CHANGED
@@ -2,6 +2,41 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [0.0.7](https://github.com/ecomplus/cloud-commerce/compare/v0.0.6...v0.0.7) (2022-06-21)
6
+
7
+
8
+ ### Features
9
+
10
+ * **api:** Add `fetch` option to config ([9ca0f68](https://github.com/ecomplus/cloud-commerce/commit/9ca0f681b003132574a6f147d406c8dddab93261))
11
+ * **api:** Add events, slug, search and auth endpoints to type ([9d4f712](https://github.com/ecomplus/cloud-commerce/commit/9d4f71217e73e22b941cfea855416a86e7bbc9a2))
12
+ * **api:** New (exported) `ApiError` class ([8e88494](https://github.com/ecomplus/cloud-commerce/commit/8e884944505caf3861aef4bce440f7fd0ed937a4))
13
+ * **api:** Type definiftion for list requests (`/${resource}`) ([21d71ff](https://github.com/ecomplus/cloud-commerce/commit/21d71ff56ac1220d16324f1018a9804b7f5cf3c3))
14
+
15
+
16
+ ### Bug Fixes
17
+
18
+ * **api:** Event `timestamp` retrieved as date iso string (not object) ([aa18cc7](https://github.com/ecomplus/cloud-commerce/commit/aa18cc7e8cf0d8fb3345da7e48ddc15f4bb2209e))
19
+
20
+ ### [0.0.6](https://github.com/ecomplus/cloud-commerce/compare/v0.0.5...v0.0.6) (2022-06-16)
21
+
22
+
23
+ ### Features
24
+
25
+ * **api:** New config option `maxRetries` (default 3) to retry on 429 and 5xx errors ([35c5287](https://github.com/ecomplus/cloud-commerce/commit/35c5287545a79bd15596f96e88bdb7d98c056183))
26
+
27
+ ### [0.0.5](https://github.com/ecomplus/cloud-commerce/compare/v0.0.4...v0.0.5) (2022-06-16)
28
+
29
+
30
+ ### Features
31
+
32
+ * **api:** Error object (not 2xx) includes `statusCode` property (as Fastify errors) ([a9681f2](https://github.com/ecomplus/cloud-commerce/commit/a9681f23ceb9b007f90e95351ca133fdac865f1b))
33
+
34
+
35
+ ### Bug Fixes
36
+
37
+ * **api:** Config object is optional on abstracted method functions ([2eebbe7](https://github.com/ecomplus/cloud-commerce/commit/2eebbe771971b5ac87b85f6068a36d7e1f647aba))
38
+ * **api:** Resolve with resource type on read without method (get is default) ([52b1a9b](https://github.com/ecomplus/cloud-commerce/commit/52b1a9b7cb48210b155ac620eaa6b3c8d95d681e))
39
+
5
40
  ### [0.0.4](https://github.com/ecomplus/cloud-commerce/compare/v0.0.3...v0.0.4) (2022-06-15)
6
41
 
7
42
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cloudcommerce",
3
- "version": "0.0.4",
3
+ "version": "0.0.7",
4
4
  "description": "Open fair-code headless commerce platform: API-first, microservices based, event driven and cloud native",
5
5
  "main": "src/index.js",
6
6
  "author": "E-Com Club Softwares para E-commerce <ti@e-com.club>",
@@ -13,7 +13,7 @@
13
13
  "postinstall": "husky install",
14
14
  "build": "turbo run build",
15
15
  "test": "turbo run test",
16
- "release": "pnpm build && standard-version --commit-all",
16
+ "release": "pnpm build && pnpm test && standard-version --commit-all",
17
17
  "postpublish": "zx scripts/release.mjs --publish"
18
18
  },
19
19
  "standard-version": {
@@ -25,20 +25,21 @@
25
25
  "@commitlint/cli": "^17.0.2",
26
26
  "@commitlint/config-conventional": "^17.0.2",
27
27
  "@commitlint/rules": "^17.0.0",
28
- "@types/node": "^17.0.42",
29
- "@typescript-eslint/eslint-plugin": "^5.28.0",
30
- "@typescript-eslint/parser": "^5.28.0",
31
- "esbuild": "^0.14.43",
32
- "eslint": "^8.17.0",
28
+ "@types/node": "^17.0.45",
29
+ "@typescript-eslint/eslint-plugin": "^5.29.0",
30
+ "@typescript-eslint/parser": "^5.29.0",
31
+ "esbuild": "^0.14.47",
32
+ "eslint": "^8.18.0",
33
33
  "eslint-config-airbnb-base": "^15.0.0",
34
34
  "eslint-plugin-import": "^2.26.0",
35
35
  "eslint-plugin-vue": "^9.1.1",
36
36
  "husky": "^8.0.1",
37
37
  "node-fetch": "^3.2.6",
38
38
  "standard-version": "^9.5.0",
39
- "tsx": "^3.4.2",
40
39
  "turbo": "^1.2.16",
41
- "typescript": "^4.7.3",
40
+ "typescript": "^4.7.4",
41
+ "vite": "^2.9.12",
42
+ "vitest": "^0.15.2",
42
43
  "zx": "^6.2.5"
43
44
  }
44
45
  }
@@ -0,0 +1,183 @@
1
+ import type { Endpoint, Config, ResponseBody } from './types';
2
+ declare class ApiError extends Error {
3
+ config: Config;
4
+ response?: Response;
5
+ statusCode?: number;
6
+ isTimeout: boolean;
7
+ constructor(config: Config, response?: Response, msg?: string, isTimeout?: boolean);
8
+ }
9
+ declare const def: {
10
+ middleware(config: Config): string;
11
+ };
12
+ declare const setMiddleware: (middleware: (config: Config) => string) => void;
13
+ declare const api: {
14
+ <T extends Config>(config: T, retries?: number): Promise<Response & {
15
+ config: Config;
16
+ data: ResponseBody<T>;
17
+ }>;
18
+ get: <E extends Endpoint, C extends AbstractedConfig>(endpoint: E, config?: C | undefined) => Promise<Response & {
19
+ config: Config;
20
+ data: E extends `products/${string}` ? import("./types").Products : E extends `categories/${string}` ? import("./types").Categories : E extends `brands/${string}` ? import("./types").Brands : E extends `collections/${string}` ? import("./types").Collections : E extends `grids/${string}` ? import("./types").Grids : E extends `carts/${string}` ? import("./types").Carts : E extends `orders/${string}` ? import("./types").Orders : E extends `customers/${string}` ? import("./types").Customers : E extends `stores/${string}` ? import("./types").Stores : E extends `applications/${string}` ? import("./types").Applications : E extends import("./types").Resource ? {
21
+ result: E extends infer T_1 ? T_1 extends E ? T_1 extends "products" ? import("./types").Products[] : T_1 extends "categories" ? import("./types").Categories[] : T_1 extends "brands" ? import("./types").Brands[] : T_1 extends "collections" ? import("./types").Collections[] : T_1 extends "grids" ? import("./types").Grids[] : T_1 extends "carts" ? import("./types").Carts[] : T_1 extends "orders" ? import("./types").Orders[] : T_1 extends "customers" ? import("./types").Customers[] : T_1 extends "stores" ? import("./types").Stores[] : T_1 extends "applications" ? import("./types").Applications[] : never : never : never;
22
+ meta: {
23
+ offset: number;
24
+ limit: number;
25
+ fields: string[];
26
+ } & {
27
+ count?: number | undefined;
28
+ sort: {
29
+ field: string;
30
+ order: 1 | -1;
31
+ }[];
32
+ query: {
33
+ [key: string]: any;
34
+ };
35
+ };
36
+ } : E extends "events/products" | "events/categories" | "events/brands" | "events/collections" | "events/grids" | "events/carts" | "events/orders" | "events/customers" | "events/stores" | "events/applications" | `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/me" ? {
37
+ result: ({
38
+ timestamp: string;
39
+ store_id?: number | undefined;
40
+ resource?: string | undefined;
41
+ authentication_id?: (string & {
42
+ length: 24;
43
+ }) | null | undefined;
44
+ resource_id?: (string & {
45
+ length: 24;
46
+ }) | undefined;
47
+ action: string;
48
+ modified_fields: string[];
49
+ method?: number | undefined;
50
+ endpoint?: string | undefined;
51
+ body?: any;
52
+ ip?: string | undefined;
53
+ } & (E extends infer T_2 ? T_2 extends E ? T_2 extends "events/products" | "events/categories" | "events/brands" | "events/collections" | "events/grids" | "events/carts" | "events/orders" | "events/customers" | "events/stores" | "events/applications" ? {
54
+ resource_id: string & {
55
+ length: 24;
56
+ };
57
+ authentication_id: (string & {
58
+ length: 24;
59
+ }) | null;
60
+ } : T_2 extends `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}` ? {
61
+ authentication_id: (string & {
62
+ length: 24;
63
+ }) | null;
64
+ } : T_2 extends "events/me" ? {
65
+ resource: import("./types").Resource;
66
+ resource_id: string & {
67
+ length: 24;
68
+ };
69
+ } : never : never : never))[];
70
+ meta: {
71
+ offset: number;
72
+ limit: number;
73
+ fields: string[];
74
+ };
75
+ } : any;
76
+ }>;
77
+ post: (endpoint: Endpoint, config?: AbstractedConfig) => Promise<Response & {
78
+ config: Config;
79
+ data: {
80
+ _id: string & {
81
+ length: 24;
82
+ };
83
+ };
84
+ }>;
85
+ put: (endpoint: Endpoint, config?: AbstractedConfig) => Promise<Response & {
86
+ config: Config;
87
+ data: null;
88
+ }>;
89
+ patch: (endpoint: Endpoint, config?: AbstractedConfig) => Promise<Response & {
90
+ config: Config;
91
+ data: null;
92
+ }>;
93
+ del: (endpoint: Endpoint, config?: AbstractedConfig) => Promise<Response & {
94
+ config: Config;
95
+ data: null;
96
+ }>;
97
+ delete: (endpoint: Endpoint, config?: AbstractedConfig) => Promise<Response & {
98
+ config: Config;
99
+ data: null;
100
+ }>;
101
+ };
102
+ declare type AbstractedConfig = Omit<Config, 'endpoint' | 'method'>;
103
+ declare const get: <E extends Endpoint, C extends AbstractedConfig>(endpoint: E, config?: C | undefined) => Promise<Response & {
104
+ config: Config;
105
+ data: E extends `products/${string}` ? import("./types").Products : E extends `categories/${string}` ? import("./types").Categories : E extends `brands/${string}` ? import("./types").Brands : E extends `collections/${string}` ? import("./types").Collections : E extends `grids/${string}` ? import("./types").Grids : E extends `carts/${string}` ? import("./types").Carts : E extends `orders/${string}` ? import("./types").Orders : E extends `customers/${string}` ? import("./types").Customers : E extends `stores/${string}` ? import("./types").Stores : E extends `applications/${string}` ? import("./types").Applications : E extends import("./types").Resource ? {
106
+ result: E extends infer T_1 ? T_1 extends E ? T_1 extends "products" ? import("./types").Products[] : T_1 extends "categories" ? import("./types").Categories[] : T_1 extends "brands" ? import("./types").Brands[] : T_1 extends "collections" ? import("./types").Collections[] : T_1 extends "grids" ? import("./types").Grids[] : T_1 extends "carts" ? import("./types").Carts[] : T_1 extends "orders" ? import("./types").Orders[] : T_1 extends "customers" ? import("./types").Customers[] : T_1 extends "stores" ? import("./types").Stores[] : T_1 extends "applications" ? import("./types").Applications[] : never : never : never;
107
+ meta: {
108
+ offset: number;
109
+ limit: number;
110
+ fields: string[];
111
+ } & {
112
+ count?: number | undefined;
113
+ sort: {
114
+ field: string;
115
+ order: 1 | -1;
116
+ }[];
117
+ query: {
118
+ [key: string]: any;
119
+ };
120
+ };
121
+ } : E extends "events/products" | "events/categories" | "events/brands" | "events/collections" | "events/grids" | "events/carts" | "events/orders" | "events/customers" | "events/stores" | "events/applications" | `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/me" ? {
122
+ result: ({
123
+ timestamp: string;
124
+ store_id?: number | undefined;
125
+ resource?: string | undefined;
126
+ authentication_id?: (string & {
127
+ length: 24;
128
+ }) | null | undefined;
129
+ resource_id?: (string & {
130
+ length: 24;
131
+ }) | undefined;
132
+ action: string;
133
+ modified_fields: string[];
134
+ method?: number | undefined;
135
+ endpoint?: string | undefined;
136
+ body?: any;
137
+ ip?: string | undefined;
138
+ } & (E extends infer T_2 ? T_2 extends E ? T_2 extends "events/products" | "events/categories" | "events/brands" | "events/collections" | "events/grids" | "events/carts" | "events/orders" | "events/customers" | "events/stores" | "events/applications" ? {
139
+ resource_id: string & {
140
+ length: 24;
141
+ };
142
+ authentication_id: (string & {
143
+ length: 24;
144
+ }) | null;
145
+ } : T_2 extends `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}` ? {
146
+ authentication_id: (string & {
147
+ length: 24;
148
+ }) | null;
149
+ } : T_2 extends "events/me" ? {
150
+ resource: import("./types").Resource;
151
+ resource_id: string & {
152
+ length: 24;
153
+ };
154
+ } : never : never : never))[];
155
+ meta: {
156
+ offset: number;
157
+ limit: number;
158
+ fields: string[];
159
+ };
160
+ } : any;
161
+ }>;
162
+ declare const post: (endpoint: Endpoint, config?: AbstractedConfig) => Promise<Response & {
163
+ config: Config;
164
+ data: {
165
+ _id: string & {
166
+ length: 24;
167
+ };
168
+ };
169
+ }>;
170
+ declare const put: (endpoint: Endpoint, config?: AbstractedConfig) => Promise<Response & {
171
+ config: Config;
172
+ data: null;
173
+ }>;
174
+ declare const patch: (endpoint: Endpoint, config?: AbstractedConfig) => Promise<Response & {
175
+ config: Config;
176
+ data: null;
177
+ }>;
178
+ declare const del: (endpoint: Endpoint, config?: AbstractedConfig) => Promise<Response & {
179
+ config: Config;
180
+ data: null;
181
+ }>;
182
+ export default api;
183
+ export { setMiddleware, get, post, put, patch, del, ApiError, };
@@ -0,0 +1,115 @@
1
+ // @ts-ignore
2
+ const env = (typeof window === 'object' && window)
3
+ || (typeof process === 'object' && process && process.env)
4
+ || {};
5
+ class ApiError extends Error {
6
+ constructor(config, response, msg, isTimeout = false) {
7
+ super(response?.statusText || msg || 'Request error');
8
+ this.config = config;
9
+ this.response = response;
10
+ this.statusCode = response?.status;
11
+ this.isTimeout = isTimeout;
12
+ }
13
+ }
14
+ const def = {
15
+ middleware(config) {
16
+ let url = config.baseUrl || env.API_BASE_URL || 'https://ecomplus.io/v2';
17
+ const storeId = config.storeId || env.ECOM_STORE_ID;
18
+ if (!storeId) {
19
+ throw new Error('`storeId` must be set in config or `ECOM_STORE_ID` env var');
20
+ }
21
+ url += `/:${storeId}`;
22
+ const lang = config.lang || env.ECOM_LANG;
23
+ if (lang) {
24
+ url += `,lang:${lang}`;
25
+ }
26
+ if (config.params) {
27
+ if (typeof config.params === 'string') {
28
+ url += `?${config.params}`;
29
+ } else {
30
+ // https://github.com/microsoft/TypeScript/issues/32951
31
+ url += `?${new URLSearchParams(config.params)}`;
32
+ }
33
+ }
34
+ return `${url}/${config.endpoint}`;
35
+ },
36
+ };
37
+ const setMiddleware = (middleware) => {
38
+ def.middleware = middleware;
39
+ };
40
+ const api = async (config, retries = 0) => {
41
+ const url = def.middleware(config);
42
+ const {
43
+ method, headers, timeout = 20000, maxRetries = 3,
44
+ } = config;
45
+ const abortController = new AbortController();
46
+ let isTimeout = false;
47
+ const timer = setTimeout(() => {
48
+ abortController.abort();
49
+ isTimeout = true;
50
+ }, timeout);
51
+ let response;
52
+ try {
53
+ response = await (config.fetch || fetch)(url, {
54
+ method,
55
+ headers,
56
+ signal: abortController.signal,
57
+ });
58
+ } catch (err) {
59
+ throw new ApiError(config, response, err.message, isTimeout);
60
+ }
61
+ clearTimeout(timer);
62
+ if (response) {
63
+ if (response.ok) {
64
+ return {
65
+ ...response,
66
+ config,
67
+ data: await response.json(),
68
+ };
69
+ }
70
+ const { status } = response;
71
+ if (maxRetries < retries && (status === 429 || status >= 500)) {
72
+ const retryAfter = response.headers.get('retry-after');
73
+ return new Promise((resolve, reject) => {
74
+ setTimeout(() => {
75
+ api(config, retries + 1).then(resolve).catch(reject);
76
+ }, (retryAfter && parseInt(retryAfter, 10)) || 5000);
77
+ });
78
+ }
79
+ }
80
+ throw new ApiError(config, response);
81
+ };
82
+ const get = (endpoint, config) => api({ ...config, endpoint });
83
+ const post = (endpoint, config) => api({
84
+ ...config,
85
+ method: 'post',
86
+ endpoint,
87
+ });
88
+ const put = (endpoint, config) => api({
89
+ ...config,
90
+ method: 'put',
91
+ endpoint,
92
+ });
93
+ const patch = (endpoint, config) => api({
94
+ ...config,
95
+ method: 'patch',
96
+ endpoint,
97
+ });
98
+ const del = (endpoint, config) => api({
99
+ ...config,
100
+ method: 'delete',
101
+ endpoint,
102
+ });
103
+ api.get = get;
104
+ api.post = post;
105
+ api.put = put;
106
+ api.patch = patch;
107
+ api.del = del;
108
+ api.delete = del;
109
+
110
+ export default api;
111
+
112
+ export {
113
+ setMiddleware, get, post, put, patch, del, ApiError,
114
+ };
115
+ // # sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,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;IAK1B,YAAY,MAAc,EAAE,QAAmB,EAAE,GAAY,EAAE,YAAqB,KAAK;QACvF,KAAK,CAAC,QAAQ,EAAE,UAAU,IAAI,GAAG,IAAI,eAAe,CAAC,CAAC;QACtD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,UAAU,GAAG,QAAQ,EAAE,MAAM,CAAC;QACnC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;CACF;AAED,MAAM,GAAG,GAAG;IACV,UAAU,CAAC,MAAc;QACvB,IAAI,GAAG,GAAG,MAAM,CAAC,OAAO,IAAI,GAAG,CAAC,YAAY,IAAI,wBAAwB,CAAC;QACzE,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,GAAG,CAAC,aAAa,CAAC;QACpD,IAAI,CAAC,OAAO,EAAE;YACZ,MAAM,IAAI,KAAK,CAAC,4DAA4D,CAAC,CAAC;SAC/E;QACD,GAAG,IAAI,KAA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AAG,CAAC,QAAkB,EAAE,MAAyB,EAAE,EAAE,CAAC,GAAG,CAAC;IAClE,GAAG,MAAM;IACT,MAAM,EAAE,MAAM;IACd,QAAQ;CACT,CAAC,CAAC;AAEH,MAAM,GAAG,GAAG,CAAC,QAAkB,EAAE,MAAyB,EAAE,EAAE,CAAC,GAAG,CAAC;IACjE,GAAG,MAAM;IACT,MAAM,EAAE,KAAK;IACb,QAAQ;CACT,CAAC,CAAC;AAEH,MAAM,KAAK,GAAG,CAAC,QAAkB,EAAE,MAAyB,EAAE,EAAE,CAAC,GAAG,CAAC;IACnE,GAAG,MAAM;IACT,MAAM,EAAE,OAAO;IACf,QAAQ;CACT,CAAC,CAAC;AAEH,MAAM,GAAG,GAAG,CAAC,QAAkB,EAAE,MAAyB,EAAE,EAAE,CAAC,GAAG,CAAC;IACjE,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"}
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,77 @@
1
+ import type { Products } from './types/products';
2
+ import type { Categories } from './types/categories';
3
+ import type { Brands } from './types/brands';
4
+ import type { Collections } from './types/collections';
5
+ import type { Grids } from './types/grids';
6
+ import type { Carts } from './types/carts';
7
+ import type { Orders } from './types/orders';
8
+ import type { Customers } from './types/customers';
9
+ import type { Stores } from './types/stores';
10
+ import type { Applications } from './types/applications';
11
+ declare type Resource = 'products' | 'categories' | 'brands' | 'collections' | 'grids' | 'carts' | 'orders' | 'customers' | 'stores' | 'applications';
12
+ declare type ResourceId = string & {
13
+ length: 24;
14
+ };
15
+ declare type ResourceAndId = `${Resource}/${ResourceId}`;
16
+ declare type EventsEndpoint = `events/${Resource}` | `events/${ResourceAndId}` | 'events/me';
17
+ declare type Endpoint = Resource | ResourceAndId | `${ResourceAndId}/${string}` | `slugs/${string}` | 'search/v1' | EventsEndpoint | 'login' | 'authenticate' | 'ask-auth-callback' | 'check-username' | `$aggregate/${Exclude<Resource, 'stores' | 'applications'>}` | `schemas/${Resource}`;
18
+ declare type Method = 'get' | 'post' | 'put' | 'patch' | 'delete';
19
+ declare type Config = {
20
+ baseUrl?: string;
21
+ storeId?: number;
22
+ lang?: string;
23
+ method?: Method;
24
+ endpoint: Endpoint;
25
+ params?: Record<string, string | number>;
26
+ headers?: Record<string, string>;
27
+ timeout?: number;
28
+ maxRetries?: number;
29
+ fetch?: typeof fetch;
30
+ };
31
+ declare type BaseListResultMeta = {
32
+ offset: number;
33
+ limit: number;
34
+ fields: Array<string>;
35
+ };
36
+ declare type ResourceListResult<TResource extends Resource> = {
37
+ result: TResource extends 'products' ? Products[] : TResource extends 'categories' ? Categories[] : TResource extends 'brands' ? Brands[] : TResource extends 'collections' ? Collections[] : TResource extends 'grids' ? Grids[] : TResource extends 'carts' ? Carts[] : TResource extends 'orders' ? Orders[] : TResource extends 'customers' ? Customers[] : TResource extends 'stores' ? Stores[] : TResource extends 'applications' ? Applications[] : never;
38
+ meta: BaseListResultMeta & {
39
+ count?: number;
40
+ sort: Array<{
41
+ field: string;
42
+ order: 1 | -1;
43
+ }>;
44
+ query: {
45
+ [key: string]: any;
46
+ };
47
+ };
48
+ };
49
+ declare type EventFieldsByEndpoint<TEndpoint extends EventsEndpoint> = TEndpoint extends `events/${Resource}` ? {
50
+ resource_id: ResourceId;
51
+ authentication_id: ResourceId | null;
52
+ } : TEndpoint extends `events/${ResourceAndId}` ? {
53
+ authentication_id: ResourceId | null;
54
+ } : TEndpoint extends 'events/me' ? {
55
+ resource: Resource;
56
+ resource_id: ResourceId;
57
+ } : never;
58
+ declare type EventsResult<TEndpoint extends EventsEndpoint> = {
59
+ result: Array<{
60
+ timestamp: string;
61
+ store_id?: number;
62
+ resource?: string;
63
+ authentication_id?: ResourceId | null;
64
+ resource_id?: ResourceId;
65
+ action: string;
66
+ modified_fields: string[];
67
+ method?: number | undefined;
68
+ endpoint?: string;
69
+ body?: any;
70
+ ip?: string;
71
+ } & EventFieldsByEndpoint<TEndpoint>>;
72
+ meta: BaseListResultMeta;
73
+ };
74
+ declare type ResponseBody<TConfig extends Config> = TConfig['method'] extends 'post' ? {
75
+ _id: ResourceId;
76
+ } : TConfig['method'] extends 'put' | 'patch' | 'delete' ? null : TConfig['endpoint'] extends `products/${ResourceId}` ? Products : TConfig['endpoint'] extends `categories/${ResourceId}` ? Categories : TConfig['endpoint'] extends `brands/${ResourceId}` ? Brands : TConfig['endpoint'] extends `collections/${ResourceId}` ? Collections : TConfig['endpoint'] extends `grids/${ResourceId}` ? Grids : TConfig['endpoint'] extends `carts/${ResourceId}` ? Carts : TConfig['endpoint'] extends `orders/${ResourceId}` ? Orders : TConfig['endpoint'] extends `customers/${ResourceId}` ? Customers : TConfig['endpoint'] extends `stores/${ResourceId}` ? Stores : TConfig['endpoint'] extends `applications/${ResourceId}` ? Applications : TConfig['endpoint'] extends Resource ? ResourceListResult<TConfig['endpoint']> : TConfig['endpoint'] extends EventsEndpoint ? EventsResult<TConfig['endpoint']> : any;
77
+ export type { Products, Categories, Brands, Collections, Grids, Carts, Orders, Customers, Stores, Applications, Resource, ResourceAndId, Endpoint, Method, Config, ResponseBody, };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ // # sourceMappingURL=types.js.map
File without changes
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@cloudcommerce/api",
3
- "version": "0.0.4",
3
+ "version": "0.0.7",
4
4
  "description": "E-Com Plus Cloud Commerce APIs client/adapter",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
7
  "repository": {
8
8
  "type": "git",
9
9
  "url": "git+https://github.com/ecomplus/cloud-commerce.git",
@@ -16,7 +16,7 @@
16
16
  },
17
17
  "homepage": "https://github.com/ecomplus/cloud-commerce/tree/main/packages/api#readme",
18
18
  "scripts": {
19
- "build": "zx scripts/build.mjs",
20
- "test": "zx scripts/test.mjs"
19
+ "build": "sh scripts/build.sh",
20
+ "test": "tsc -p ../../tsconfig.test.json && vitest run"
21
21
  }
22
22
  }
@@ -0,0 +1,6 @@
1
+ #!/bin/bash
2
+
3
+ rm -rf lib
4
+ tsc --outDir lib
5
+ cp -r src/types lib/
6
+ npx eslint --rule 'max-len: off' --ext .js lib --fix