cloudcommerce 0.0.6 → 0.0.9
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/.eslintrc.cjs +2 -1
- package/.github/workflows/firebase-hosting-merge.yml +20 -0
- package/.github/workflows/firebase-hosting-pull-request.yml +17 -0
- package/.gitmodules +3 -0
- package/.vscode/extensions.json +2 -1
- package/CHANGELOG.md +24 -0
- package/CONTRIBUTING.md +42 -0
- package/README.md +1 -0
- package/package.json +11 -10
- package/packages/api/lib/index.d.ts +120 -71
- package/packages/api/lib/index.js +43 -28
- package/packages/api/lib/index.js.map +1 -1
- package/packages/api/lib/types.d.ts +47 -10
- package/packages/api/package.json +2 -1
- package/packages/api/src/index.ts +48 -27
- package/packages/api/src/types.ts +93 -16
- package/packages/api/tests/index.test.ts +26 -2
- package/packages/apps/discounts/package.json +2 -1
- package/packages/firebase/CHANGELOG.md +1 -0
- package/packages/firebase/README.md +1 -0
- package/packages/firebase/package.json +24 -0
- package/packages/firebase/src/index.js +0 -0
- package/packages/storefront/package.json +2 -1
- package/pnpm-workspace.yaml +1 -0
- package/store/.firebaserc +5 -0
- package/store/LICENSE.md +230 -0
- package/store/README.md +2 -0
- package/store/firebase.json +47 -0
- package/store/firestore.indexes.json +4 -0
- package/store/firestore.rules +8 -0
- package/store/functions/index.js +12 -0
- package/store/functions/package.json +25 -0
- package/store/public/404.html +33 -0
- package/store/public/index.html +89 -0
- package/store/remoteconfig.template.json +1 -0
- package/store/storage.rules +15 -0
- package/src/index.js +0 -3
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'] },
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# This file was auto-generated by the Firebase CLI
|
|
2
|
+
# https://github.com/firebase/firebase-tools
|
|
3
|
+
|
|
4
|
+
name: Deploy to Firebase Hosting on merge
|
|
5
|
+
'on':
|
|
6
|
+
push:
|
|
7
|
+
branches:
|
|
8
|
+
- main
|
|
9
|
+
jobs:
|
|
10
|
+
build_and_deploy:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v2
|
|
14
|
+
- run: 'y'
|
|
15
|
+
- uses: FirebaseExtended/action-hosting-deploy@v0
|
|
16
|
+
with:
|
|
17
|
+
repoToken: '${{ secrets.GITHUB_TOKEN }}'
|
|
18
|
+
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_ECOM2_HELLO }}'
|
|
19
|
+
channelId: live
|
|
20
|
+
projectId: ecom2-hello
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# This file was auto-generated by the Firebase CLI
|
|
2
|
+
# https://github.com/firebase/firebase-tools
|
|
3
|
+
|
|
4
|
+
name: Deploy to Firebase Hosting on PR
|
|
5
|
+
'on': pull_request
|
|
6
|
+
jobs:
|
|
7
|
+
build_and_preview:
|
|
8
|
+
if: '${{ github.event.pull_request.head.repo.full_name == github.repository }}'
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
steps:
|
|
11
|
+
- uses: actions/checkout@v2
|
|
12
|
+
- run: 'y'
|
|
13
|
+
- uses: FirebaseExtended/action-hosting-deploy@v0
|
|
14
|
+
with:
|
|
15
|
+
repoToken: '${{ secrets.GITHUB_TOKEN }}'
|
|
16
|
+
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_ECOM2_HELLO }}'
|
|
17
|
+
projectId: ecom2-hello
|
package/.gitmodules
ADDED
package/.vscode/extensions.json
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,30 @@
|
|
|
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.9](https://github.com/ecomplus/cloud-commerce/compare/v0.0.8...v0.0.9) (2022-06-24)
|
|
6
|
+
|
|
7
|
+
### [0.0.8](https://github.com/ecomplus/cloud-commerce/compare/v0.0.7...v0.0.8) (2022-06-21)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Bug Fixes
|
|
11
|
+
|
|
12
|
+
* Explictly set packages `"type": "module"` ([dcaffce](https://github.com/ecomplus/cloud-commerce/commit/dcaffcecf78d30cd480f1cf2794eb61afaeba5bf))
|
|
13
|
+
|
|
14
|
+
### [0.0.7](https://github.com/ecomplus/cloud-commerce/compare/v0.0.6...v0.0.7) (2022-06-21)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
* **api:** Add `fetch` option to config ([9ca0f68](https://github.com/ecomplus/cloud-commerce/commit/9ca0f681b003132574a6f147d406c8dddab93261))
|
|
20
|
+
* **api:** Add events, slug, search and auth endpoints to type ([9d4f712](https://github.com/ecomplus/cloud-commerce/commit/9d4f71217e73e22b941cfea855416a86e7bbc9a2))
|
|
21
|
+
* **api:** New (exported) `ApiError` class ([8e88494](https://github.com/ecomplus/cloud-commerce/commit/8e884944505caf3861aef4bce440f7fd0ed937a4))
|
|
22
|
+
* **api:** Type definiftion for list requests (`/${resource}`) ([21d71ff](https://github.com/ecomplus/cloud-commerce/commit/21d71ff56ac1220d16324f1018a9804b7f5cf3c3))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Bug Fixes
|
|
26
|
+
|
|
27
|
+
* **api:** Event `timestamp` retrieved as date iso string (not object) ([aa18cc7](https://github.com/ecomplus/cloud-commerce/commit/aa18cc7e8cf0d8fb3345da7e48ddc15f4bb2209e))
|
|
28
|
+
|
|
5
29
|
### [0.0.6](https://github.com/ecomplus/cloud-commerce/compare/v0.0.5...v0.0.6) (2022-06-16)
|
|
6
30
|
|
|
7
31
|
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Contribution guidelines
|
|
2
|
+
|
|
3
|
+
:blush:
|
|
4
|
+
|
|
5
|
+
## Prepare your environment
|
|
6
|
+
|
|
7
|
+
```console
|
|
8
|
+
npm i -g pnpm firebase-tools
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Clone this repo to your local machine and install the dependencies:
|
|
12
|
+
|
|
13
|
+
```console
|
|
14
|
+
pnpm install
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### Setup Firebase
|
|
18
|
+
|
|
19
|
+
You may create a Firebase project to test or just setup emulators to test locally:
|
|
20
|
+
|
|
21
|
+
```console
|
|
22
|
+
firebase init emulators
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Select emulators for _Authentication_, _Hosting_, _Functions_, _Firestore_, _Pub/Sub_ and _Storage_.
|
|
26
|
+
You can skip the last three if you're willing to work with Storefront only, and the first two if willing to work if app(s) only.
|
|
27
|
+
|
|
28
|
+
#### Creating a Firebase project
|
|
29
|
+
|
|
30
|
+
If you want to deploy to a new Firebase project:
|
|
31
|
+
|
|
32
|
+
1. Start creating new project on [Firebase console](https://console.firebase.google.com/):
|
|
33
|
+
- Set a nice project name (ID) and remember it;
|
|
34
|
+
- You may enable Firebase Analytics for enhanced remote config options and A/B testing;
|
|
35
|
+
|
|
36
|
+
2. Go to _Firestore Database_ page (on sidebar) and _create database_:
|
|
37
|
+
- Just bypass with default production mode and rules;
|
|
38
|
+
- Select region `us-east1` (recommended);
|
|
39
|
+
|
|
40
|
+
3. Firebase free plan doesn't support sending external HTTP requests, so you'll need to upgrade to _Blaze_ (on demand) plan;
|
|
41
|
+
|
|
42
|
+
4. Then run `firebase login && firebase init` and select the created project;
|
package/README.md
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Open fair-code eCommerce platform to use on top of headless commerce APIs, it includes:
|
|
4
4
|
- High performant [Astro](https://astro.build/) + [Vue](https://vuejs.org/) PWA & Jamstack storefront;
|
|
5
5
|
- Storefront CMS and page builder;
|
|
6
|
+
- Analytics and A/B testing;
|
|
6
7
|
- Integrations for payments, shipping, ERPs, CRMs and others.
|
|
7
8
|
|
|
8
9
|
Easy deployment on [Firebase](https://firebase.google.com/), plug & play with **[E-Com Plus APIs](https://developers.e-com.plus/)**.
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cloudcommerce",
|
|
3
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.9",
|
|
4
5
|
"description": "Open fair-code headless commerce platform: API-first, microservices based, event driven and cloud native",
|
|
5
|
-
"main": "
|
|
6
|
+
"main": "store/functions/index.js",
|
|
6
7
|
"author": "E-Com Club Softwares para E-commerce <ti@e-com.club>",
|
|
7
8
|
"license": "Apache 2.0 with Commons Clause",
|
|
8
9
|
"engines": {
|
|
@@ -25,11 +26,11 @@
|
|
|
25
26
|
"@commitlint/cli": "^17.0.2",
|
|
26
27
|
"@commitlint/config-conventional": "^17.0.2",
|
|
27
28
|
"@commitlint/rules": "^17.0.0",
|
|
28
|
-
"@types/node": "^17.0.
|
|
29
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
30
|
-
"@typescript-eslint/parser": "^5.
|
|
31
|
-
"esbuild": "^0.14.
|
|
32
|
-
"eslint": "^8.
|
|
29
|
+
"@types/node": "^17.0.45",
|
|
30
|
+
"@typescript-eslint/eslint-plugin": "^5.29.0",
|
|
31
|
+
"@typescript-eslint/parser": "^5.29.0",
|
|
32
|
+
"esbuild": "^0.14.47",
|
|
33
|
+
"eslint": "^8.18.0",
|
|
33
34
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
34
35
|
"eslint-plugin-import": "^2.26.0",
|
|
35
36
|
"eslint-plugin-vue": "^9.1.1",
|
|
@@ -37,9 +38,9 @@
|
|
|
37
38
|
"node-fetch": "^3.2.6",
|
|
38
39
|
"standard-version": "^9.5.0",
|
|
39
40
|
"turbo": "^1.2.16",
|
|
40
|
-
"typescript": "^4.7.
|
|
41
|
+
"typescript": "^4.7.4",
|
|
41
42
|
"vite": "^2.9.12",
|
|
42
|
-
"vitest": "^0.15.
|
|
43
|
-
"zx": "
|
|
43
|
+
"vitest": "^0.15.2",
|
|
44
|
+
"zx": "7"
|
|
44
45
|
}
|
|
45
46
|
}
|
|
@@ -1,4 +1,11 @@
|
|
|
1
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
|
+
}
|
|
2
9
|
declare const def: {
|
|
3
10
|
middleware(config: Config): string;
|
|
4
11
|
};
|
|
@@ -10,41 +17,62 @@ declare const api: {
|
|
|
10
17
|
}>;
|
|
11
18
|
get: <E extends Endpoint, C extends AbstractedConfig>(endpoint: E, config?: C | undefined) => Promise<Response & {
|
|
12
19
|
config: Config;
|
|
13
|
-
data: {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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;
|
|
48
76
|
}>;
|
|
49
77
|
post: (endpoint: Endpoint, config?: AbstractedConfig) => Promise<Response & {
|
|
50
78
|
config: Config;
|
|
@@ -74,41 +102,62 @@ declare const api: {
|
|
|
74
102
|
declare type AbstractedConfig = Omit<Config, 'endpoint' | 'method'>;
|
|
75
103
|
declare const get: <E extends Endpoint, C extends AbstractedConfig>(endpoint: E, config?: C | undefined) => Promise<Response & {
|
|
76
104
|
config: Config;
|
|
77
|
-
data: {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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;
|
|
112
161
|
}>;
|
|
113
162
|
declare const post: (endpoint: Endpoint, config?: AbstractedConfig) => Promise<Response & {
|
|
114
163
|
config: Config;
|
|
@@ -131,4 +180,4 @@ declare const del: (endpoint: Endpoint, config?: AbstractedConfig) => Promise<Re
|
|
|
131
180
|
data: null;
|
|
132
181
|
}>;
|
|
133
182
|
export default api;
|
|
134
|
-
export { setMiddleware, get, post, put, patch, del, };
|
|
183
|
+
export { setMiddleware, get, post, put, patch, del, ApiError, };
|
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
const env = (typeof window === 'object' && window)
|
|
3
3
|
|| (typeof process === 'object' && process && process.env)
|
|
4
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
|
+
}
|
|
5
14
|
const def = {
|
|
6
15
|
middleware(config) {
|
|
7
16
|
let url = config.baseUrl || env.API_BASE_URL || 'https://ecomplus.io/v2';
|
|
@@ -25,7 +34,6 @@ const def = {
|
|
|
25
34
|
return `${url}/${config.endpoint}`;
|
|
26
35
|
},
|
|
27
36
|
};
|
|
28
|
-
// eslint-disable-next-line no-unused-vars
|
|
29
37
|
const setMiddleware = (middleware) => {
|
|
30
38
|
def.middleware = middleware;
|
|
31
39
|
};
|
|
@@ -35,34 +43,41 @@ const api = async (config, retries = 0) => {
|
|
|
35
43
|
method, headers, timeout = 20000, maxRetries = 3,
|
|
36
44
|
} = config;
|
|
37
45
|
const abortController = new AbortController();
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
data: await response.json(),
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
const { status } = response;
|
|
53
|
-
if (maxRetries < retries && (status === 429 || status >= 500)) {
|
|
54
|
-
const retryAfter = response.headers.get('retry-after');
|
|
55
|
-
return new Promise((resolve, reject) => {
|
|
56
|
-
setTimeout(() => {
|
|
57
|
-
api(config, retries + 1).then(resolve).catch(reject);
|
|
58
|
-
}, (retryAfter && parseInt(retryAfter, 10)) || 5000);
|
|
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,
|
|
59
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
|
+
}
|
|
60
79
|
}
|
|
61
|
-
|
|
62
|
-
error.config = config;
|
|
63
|
-
error.response = response;
|
|
64
|
-
error.statusCode = status;
|
|
65
|
-
throw error;
|
|
80
|
+
throw new ApiError(config, response);
|
|
66
81
|
};
|
|
67
82
|
const get = (endpoint, config) => api({ ...config, endpoint });
|
|
68
83
|
const post = (endpoint, config) => api({
|
|
@@ -95,6 +110,6 @@ api.delete = del;
|
|
|
95
110
|
export default api;
|
|
96
111
|
|
|
97
112
|
export {
|
|
98
|
-
setMiddleware, get, post, put, patch, del,
|
|
113
|
+
setMiddleware, get, post, put, patch, del, ApiError,
|
|
99
114
|
};
|
|
100
115
|
// # sourceMappingURL=index.js.map
|
|
@@ -1 +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,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,C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
|
|
14
14
|
};
|
|
15
15
|
declare type ResourceAndId = `${Resource}/${ResourceId}`;
|
|
16
|
-
declare type
|
|
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}`;
|
|
17
18
|
declare type Method = 'get' | 'post' | 'put' | 'patch' | 'delete';
|
|
18
19
|
declare type Config = {
|
|
19
20
|
baseUrl?: string;
|
|
@@ -25,16 +26,52 @@ declare type Config = {
|
|
|
25
26
|
headers?: Record<string, string>;
|
|
26
27
|
timeout?: number;
|
|
27
28
|
maxRetries?: number;
|
|
29
|
+
fetch?: typeof fetch;
|
|
28
30
|
};
|
|
29
|
-
declare type
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
declare type BaseListResultMeta = {
|
|
32
|
+
offset: number;
|
|
33
|
+
limit: number;
|
|
34
|
+
fields: Array<string>;
|
|
32
35
|
};
|
|
33
|
-
declare type
|
|
34
|
-
|
|
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' ? {
|
|
36
75
|
_id: ResourceId;
|
|
37
|
-
} :
|
|
38
|
-
method: 'put' | 'patch' | 'delete';
|
|
39
|
-
} ? null : T extends ReadConfig<`products/${ResourceId}`> ? Products : T extends ReadConfig<`categories/${ResourceId}`> ? Categories : T extends ReadConfig<`brands/${ResourceId}`> ? Brands : T extends ReadConfig<`collections/${ResourceId}`> ? Collections : T extends ReadConfig<`grids/${ResourceId}`> ? Grids : T extends ReadConfig<`carts/${ResourceId}`> ? Carts : T extends ReadConfig<`orders/${ResourceId}`> ? Orders : T extends ReadConfig<`customers/${ResourceId}`> ? Customers : T extends ReadConfig<`stores/${ResourceId}`> ? Stores : T extends ReadConfig<`applications/${ResourceId}`> ? Applications : any;
|
|
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;
|
|
40
77
|
export type { Products, Categories, Brands, Collections, Grids, Carts, Orders, Customers, Stores, Applications, Resource, ResourceAndId, Endpoint, Method, Config, ResponseBody, };
|