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
@@ -1,89 +0,0 @@
1
- // @ts-ignore
2
- const env = (typeof window === 'object' && window)
3
- || (typeof process === 'object' && process && process.env)
4
- || {};
5
- const def = {
6
- middleware(config) {
7
- let url = config.baseUrl || env.API_BASE_URL || 'https://ecomplus.io/v2';
8
- const storeId = config.storeId || env.ECOM_STORE_ID;
9
- if (!storeId) {
10
- throw new Error('`storeId` must be set in config or `ECOM_STORE_ID` env var');
11
- }
12
- url += `/:${storeId}`;
13
- const lang = config.lang || env.ECOM_LANG;
14
- if (lang) {
15
- url += `,lang:${lang}`;
16
- }
17
- if (config.params) {
18
- if (typeof config.params === 'string') {
19
- url += `?${config.params}`;
20
- }
21
- else {
22
- // https://github.com/microsoft/TypeScript/issues/32951
23
- url += `?${new URLSearchParams(config.params)}`;
24
- }
25
- }
26
- return `${url}/${config.endpoint}`;
27
- },
28
- };
29
- // eslint-disable-next-line no-unused-vars
30
- const setMiddleware = (middleware) => {
31
- def.middleware = middleware;
32
- };
33
- const callApi = async (config) => {
34
- const url = def.middleware(config);
35
- const { method, headers, timeout = 20000 } = config;
36
- const abortController = new AbortController();
37
- const timer = setTimeout(() => abortController.abort(), timeout);
38
- const response = await fetch(url, {
39
- method,
40
- headers,
41
- signal: abortController.signal,
42
- });
43
- clearTimeout(timer);
44
- if (response.ok) {
45
- return {
46
- ...response,
47
- config,
48
- data: await response.json(),
49
- };
50
- }
51
- const error = new Error(response.statusText);
52
- error.config = config;
53
- error.response = response;
54
- throw error;
55
- };
56
- const get = (endpoint, config) => callApi({
57
- ...config,
58
- method: 'get',
59
- endpoint,
60
- });
61
- const post = (endpoint, config) => callApi({
62
- ...config,
63
- method: 'post',
64
- endpoint,
65
- });
66
- const put = (endpoint, config) => callApi({
67
- ...config,
68
- method: 'put',
69
- endpoint,
70
- });
71
- const patch = (endpoint, config) => callApi({
72
- ...config,
73
- method: 'patch',
74
- endpoint,
75
- });
76
- const del = (endpoint, config) => callApi({
77
- ...config,
78
- method: 'delete',
79
- endpoint,
80
- });
81
- callApi.get = get;
82
- callApi.post = post;
83
- callApi.put = put;
84
- callApi.patch = patch;
85
- callApi.del = del;
86
- callApi.delete = del;
87
- export default callApi;
88
- export { setMiddleware, get, post, put, patch, del, };
89
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
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,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,KAAK,OAAO,EAAE,CAAC;QACtB,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,GAAG,CAAC,SAAS,CAAC;QAC1C,IAAI,IAAI,EAAE;YACR,GAAG,IAAI,SAAS,IAAI,EAAE,CAAC;SACxB;QACD,IAAI,MAAM,CAAC,MAAM,EAAE;YACjB,IAAI,OAAO,MAAM,CAAC,MAAM,KAAK,QAAQ,EAAE;gBACrC,GAAG,IAAI,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;aAC5B;iBAAM;gBACL,uDAAuD;gBACvD,GAAG,IAAI,IAAI,IAAI,eAAe,CAAC,MAAM,CAAC,MAAgC,CAAC,EAAE,CAAC;aAC3E;S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AC;AAEH,MAAM,IAAI,GAAG,CAAC,QAAkB,EAAE,MAAiC,EAAE,EAAE,CAAC,OAAO,CAAC;IAC9E,GAAG,MAAM;IACT,MAAM,EAAE,MAAM;IACd,QAAQ;CACT,CAAC,CAAC;AAEH,MAAM,GAAG,GAAG,CAAC,QAAkB,EAAE,MAAiC,EAAE,EAAE,CAAC,OAAO,CAAC;IAC7E,GAAG,MAAM;IACT,MAAM,EAAE,KAAK;IACb,QAAQ;CACT,CAAC,CAAC;AAEH,MAAM,KAAK,GAAG,CAAC,QAAkB,EAAE,MAAiC,EAAE,EAAE,CAAC,OAAO,CAAC;IAC/E,GAAG,MAAM;IACT,MAAM,EAAE,OAAO;IACf,QAAQ;CACT,CAAC,CAAC;AAEH,MAAM,GAAG,GAAG,CAAC,QAAkB,EAAE,MAAiC,EAAE,EAAE,CAAC,OAAO,CAAC;IAC7E,GAAG,MAAM;IACT,MAAM,EAAE,QAAQ;IAChB,QAAQ;CACT,CAAC,CAAC;AAEH,OAAO,CAAC,GAAG,GAAG,GAAG,CAAC;AAClB,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;AACpB,OAAO,CAAC,GAAG,GAAG,GAAG,CAAC;AAClB,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC;AACtB,OAAO,CAAC,GAAG,GAAG,GAAG,CAAC;AAClB,OAAO,CAAC,MAAM,GAAG,GAAG,CAAC;AAErB,eAAe,OAAO,CAAC;AAEvB,OAAO,EACL,aAAa,EACb,GAAG,EACH,IAAI,EACJ,GAAG,EACH,KAAK,EACL,GAAG,GACJ,CAAC"}
@@ -1,65 +0,0 @@
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 Endpoint = Resource | ResourceAndId | `${ResourceAndId}/${string}`;
17
- declare type Method = 'get' | 'post' | 'put' | 'patch' | 'delete';
18
- declare type Config = {
19
- baseUrl?: string;
20
- storeId?: number;
21
- lang?: string;
22
- method: Method;
23
- endpoint: Endpoint;
24
- params?: Record<string, string | number>;
25
- headers?: Record<string, string>;
26
- timeout?: number;
27
- };
28
- declare type ResponseBody<T> = T extends Config & {
29
- method: 'post';
30
- } ? {
31
- _id: ResourceId;
32
- } : T extends Config & {
33
- method: 'put' | 'patch' | 'delete';
34
- } ? null : T extends Config & {
35
- method: 'get';
36
- endpoint: `products/${ResourceId}`;
37
- } ? Products : T extends Config & {
38
- method: 'get';
39
- endpoint: `categories/${ResourceId}`;
40
- } ? Categories : T extends Config & {
41
- method: 'get';
42
- endpoint: `brands/${ResourceId}`;
43
- } ? Brands : T extends Config & {
44
- method: 'get';
45
- endpoint: `collections/${ResourceId}`;
46
- } ? Collections : T extends Config & {
47
- method: 'get';
48
- endpoint: `grids/${ResourceId}`;
49
- } ? Grids : T extends Config & {
50
- method: 'get';
51
- endpoint: `carts/${ResourceId}`;
52
- } ? Carts : T extends Config & {
53
- method: 'get';
54
- endpoint: `orders/${ResourceId}`;
55
- } ? Orders : T extends Config & {
56
- method: 'get';
57
- endpoint: `customers/${ResourceId}`;
58
- } ? Customers : T extends Config & {
59
- method: 'get';
60
- endpoint: `stores/${ResourceId}`;
61
- } ? Stores : T extends Config & {
62
- method: 'get';
63
- endpoint: `applications/${ResourceId}`;
64
- } ? Applications : any;
65
- export type { Products, Categories, Brands, Collections, Grids, Carts, Orders, Customers, Stores, Applications, Resource, ResourceAndId, Endpoint, Method, Config, ResponseBody, };
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
@@ -1,5 +0,0 @@
1
- /* global $ */
2
-
3
- await $`rm -rf dist`;
4
- await $`tsc -p ../../tsconfig.json --outDir dist --declaration`;
5
- await $`cp -r src/types dist/`;
@@ -1,4 +0,0 @@
1
- /* global $ */
2
-
3
- await $`tsc -p ../../tsconfig.test.json`;
4
- await $`tsx tests/index.test.ts`;