cloudcommerce 0.0.42 → 0.0.45

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 (72) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/action.yml +8 -6
  3. package/package.json +1 -1
  4. package/packages/api/lib/index.d.ts +9 -3
  5. package/packages/api/lib/index.js +12 -2
  6. package/packages/api/lib/index.js.map +1 -1
  7. package/packages/api/lib/types.d.ts +12 -2
  8. package/packages/api/package.json +1 -1
  9. package/packages/api/src/index.ts +28 -5
  10. package/packages/api/src/types.ts +13 -1
  11. package/packages/apps/discounts/lib/index.d.ts +3 -0
  12. package/packages/apps/discounts/lib/index.js +3 -1
  13. package/packages/apps/discounts/lib/index.js.map +1 -1
  14. package/packages/apps/discounts/package.json +3 -3
  15. package/packages/apps/discounts/src/index.ts +1 -1
  16. package/packages/apps/discounts/tsconfig.json +4 -1
  17. package/packages/cli/lib/build.js +5 -2
  18. package/packages/cli/package.json +1 -1
  19. package/packages/cli/src/build.ts +8 -5
  20. package/packages/events/CHANGELOG.md +1 -0
  21. package/packages/events/README.md +1 -0
  22. package/packages/events/package.json +36 -0
  23. package/packages/events/src/firebase.ts +31 -0
  24. package/packages/events/src/index.ts +1 -0
  25. package/packages/events/tsconfig.json +3 -0
  26. package/packages/firebase/lib/config.d.ts +5 -0
  27. package/packages/firebase/lib/config.js +27 -18
  28. package/packages/firebase/lib/config.js.map +1 -1
  29. package/packages/firebase/lib/defaults.js +4 -1
  30. package/packages/firebase/lib/env.js +17 -17
  31. package/packages/firebase/lib/handlers/check-store-events.js +24 -23
  32. package/packages/firebase/lib/index.d.ts +1 -1
  33. package/packages/firebase/lib/index.js +6 -3
  34. package/packages/firebase/lib/index.js.map +1 -1
  35. package/packages/firebase/lib/types.js +1 -1
  36. package/packages/firebase/package.json +3 -2
  37. package/packages/firebase/src/config.ts +5 -0
  38. package/packages/firebase/src/index.ts +2 -1
  39. package/packages/modules/lib/firebase/ajv.js +33 -0
  40. package/packages/modules/lib/firebase/ajv.js.map +1 -0
  41. package/packages/modules/lib/firebase/call-app-module.js +76 -0
  42. package/packages/modules/lib/firebase/call-app-module.js.map +1 -0
  43. package/packages/modules/lib/firebase/checkout.js +1 -0
  44. package/packages/modules/lib/firebase/checkout.js.map +1 -0
  45. package/packages/modules/lib/firebase/handle-module.js +161 -0
  46. package/packages/modules/lib/firebase/handle-module.js.map +1 -0
  47. package/packages/modules/lib/firebase/proxy-apps.js +1 -0
  48. package/packages/modules/lib/firebase/proxy-apps.js.map +1 -0
  49. package/packages/modules/lib/firebase/serve-modules-api.js +57 -0
  50. package/packages/modules/lib/firebase/serve-modules-api.js.map +1 -0
  51. package/packages/modules/lib/firebase.js +11 -3
  52. package/packages/modules/lib/firebase.js.map +1 -1
  53. package/packages/modules/lib/index.js +11 -7
  54. package/packages/modules/lib/index.js.map +1 -1
  55. package/packages/modules/package.json +5 -1
  56. package/packages/modules/src/firebase/ajv.ts +38 -0
  57. package/packages/modules/src/firebase/call-app-module.ts +86 -0
  58. package/packages/modules/src/firebase/{.gitkeep → checkout.ts} +0 -0
  59. package/packages/modules/src/firebase/handle-module.ts +197 -0
  60. package/packages/modules/src/firebase/proxy-apps.ts +0 -0
  61. package/packages/modules/src/firebase/serve-modules-api.ts +66 -0
  62. package/packages/modules/src/firebase.ts +11 -3
  63. package/packages/modules/src/index.ts +11 -8
  64. package/packages/passport/lib/firebase.js +2 -1
  65. package/packages/passport/lib/firebase.js.map +1 -1
  66. package/packages/passport/package.json +1 -1
  67. package/packages/passport/src/firebase.ts +2 -1
  68. package/packages/ssr/package.json +1 -1
  69. package/packages/storefront/package.json +1 -1
  70. package/packages/types/index.ts +10 -4
  71. package/packages/types/package.json +1 -1
  72. package/pnpm-lock.yaml +79 -13
package/CHANGELOG.md CHANGED
@@ -2,6 +2,48 @@
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.45](https://github.com/ecomplus/cloud-commerce/compare/v0.0.44...v0.0.45) (2022-08-05)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * GH Action must install dependencies of each functions codebase ([0e1212a](https://github.com/ecomplus/cloud-commerce/commit/0e1212a61c455de0e1b698e9086c1df2a6c24fd7))
11
+ * GH Action must install dependencies of each functions codebase ([7379f0e](https://github.com/ecomplus/cloud-commerce/commit/7379f0e01e9ce94a666735e12dd38a29f090d238))
12
+ * GH Action must install optional dependencies for functions deploy ([59b281e](https://github.com/ecomplus/cloud-commerce/commit/59b281e74346dbe360c2810eb9749304214df17c))
13
+ * Set Firebase Functions names with snake case ([2ec6a31](https://github.com/ecomplus/cloud-commerce/commit/2ec6a31a42cd7692f5b004d65dff6d2e0b3bad30))
14
+
15
+ ### [0.0.44](https://github.com/ecomplus/cloud-commerce/compare/v0.0.43...v0.0.44) (2022-08-05)
16
+
17
+
18
+ ### Features
19
+
20
+ * **apps/discounts:** Start exporting apply discount function for module [[#29](https://github.com/ecomplus/cloud-commerce/issues/29)] ([a4ca745](https://github.com/ecomplus/cloud-commerce/commit/a4ca745ac69318e2c2ba1b4e94e68f37924b0682))
21
+ * **events:** Setup `@cloudcommerce/events` pkg with first listener start [[#29](https://github.com/ecomplus/cloud-commerce/issues/29)] ([3a4ae39](https://github.com/ecomplus/cloud-commerce/commit/3a4ae3996066ece4c502d55b39f79f9fab20fee3))
22
+ * **firebase:** Start defining apps on config with first (discount) app [[#29](https://github.com/ecomplus/cloud-commerce/issues/29)] ([8a810cf](https://github.com/ecomplus/cloud-commerce/commit/8a810cf45ad41c29adb14e111dccd63afd71b63c))
23
+ * **modules:** Start importing/calling internal apps dynamically [[#29](https://github.com/ecomplus/cloud-commerce/issues/29)] ([47db241](https://github.com/ecomplus/cloud-commerce/commit/47db24193c3423851246e691604a5e9f691c9077))
24
+ * **types:** Add `AppModuleName` enum definition ([642235c](https://github.com/ecomplus/cloud-commerce/commit/642235cf789d11b3208526a87bd7fc72e2dd38e4))
25
+
26
+
27
+ ### Bug Fixes
28
+
29
+ * **cli:** Prevent no such file error with optional `.env` on build ([201f30e](https://github.com/ecomplus/cloud-commerce/commit/201f30e6ce365ff01ae46dad83a8dfa899b6b91a))
30
+ * **types:** Edit some app events types (grammar) ([a552efa](https://github.com/ecomplus/cloud-commerce/commit/a552efa08b0eba6e25292f0a64a2a269bb812adb))
31
+
32
+ ### [0.0.43](https://github.com/ecomplus/cloud-commerce/compare/v0.0.42...v0.0.43) (2022-08-04)
33
+
34
+
35
+ ### Features
36
+
37
+ * **api:** Export types `ApiEndpoint` and `ApiConfig` ([056f6b4](https://github.com/ecomplus/cloud-commerce/commit/056f6b48d5add05aea7a437674b42a88061acd44))
38
+ * **api:** Parse error response and return `error.data` ([b37e561](https://github.com/ecomplus/cloud-commerce/commit/b37e56161ab5673028d4e14d5645bc64bbf9ccbd))
39
+ * **firebase:** Add `./lib/env` to pkg named exports ([31e9d0d](https://github.com/ecomplus/cloud-commerce/commit/31e9d0d0841f3e5a7e15f7e16babdeace4bf32b8))
40
+ * **modules:** Setup Modules API function ([2a58363](https://github.com/ecomplus/cloud-commerce/commit/2a58363b7e3bc0a3a4e19c1278a0d366deb6f393))
41
+
42
+
43
+ ### Bug Fixes
44
+
45
+ * **api:** Fix config params typedef to accept booleans ([d14ca33](https://github.com/ecomplus/cloud-commerce/commit/d14ca33cc9ad66f185856fed4fa0b11d32c192f7))
46
+
5
47
  ### [0.0.42](https://github.com/ecomplus/cloud-commerce/compare/v0.0.41...v0.0.42) (2022-08-02)
6
48
 
7
49
  ### [0.0.41](https://github.com/ecomplus/cloud-commerce/compare/v0.0.40...v0.0.41) (2022-08-02)
package/action.yml CHANGED
@@ -29,17 +29,19 @@ runs:
29
29
 
30
30
  - if: github.event_name == 'push'
31
31
  shell: bash
32
- run: npm i --location=global firebase-tools@^11.2.1
32
+ run: npm i --location=global firebase-tools@11
33
33
 
34
34
  - shell: bash
35
- run: npm ci --only=production
35
+ run: npm ci --omit=dev
36
36
 
37
37
  - shell: bash
38
38
  working-directory: functions
39
- run: npm ci --only=production --no-optional
40
-
41
- - shell: bash
42
- run: npm run build
39
+ run: |
40
+ for d in */ ; do
41
+ cd $d
42
+ npm ci --omit=dev
43
+ cd ..
44
+ done
43
45
 
44
46
  - if: github.event_name == 'push'
45
47
  name: Deploy to Firebase live
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "cloudcommerce",
3
3
  "type": "module",
4
- "version": "0.0.42",
4
+ "version": "0.0.45",
5
5
  "description": "Open fair-code headless commerce platform: API-first, microservices based, event driven and cloud native",
6
6
  "main": "packages/api/lib/index.js",
7
7
  "author": "E-Com Club Softwares para E-commerce <ti@e-com.club>",
@@ -1,10 +1,13 @@
1
- import type { ResourceOpQuery, Endpoint, Config, ResponseBody, RequestBody } from './types';
1
+ import type { ResourceOpQuery, Endpoint, Config, ResponseBody, RequestBody, ErrorBody } from './types';
2
2
  declare class ApiError extends Error {
3
3
  config: Config;
4
- response?: Response;
4
+ response?: Response & {
5
+ data?: ErrorBody;
6
+ };
5
7
  statusCode?: number;
8
+ data?: ErrorBody;
6
9
  isTimeout: boolean;
7
- constructor(config: Config, response?: Response, msg?: string, isTimeout?: boolean);
10
+ constructor(config: Config, response?: ApiError['response'], msg?: string, isTimeout?: boolean);
8
11
  }
9
12
  declare const def: {
10
13
  middleware(config: Config): {
@@ -10030,3 +10033,6 @@ declare const del: (endpoint: Endpoint, config: AbstractedAuthConfig) => Promise
10030
10033
  }>;
10031
10034
  export default api;
10032
10035
  export { setMiddleware, get, post, put, patch, del, ApiError, };
10036
+ export declare type ApiEndpoint = Endpoint;
10037
+ export declare type ApiConfig = Config;
10038
+ export declare type ApiErrorBody = ErrorBody;
@@ -4,10 +4,15 @@ const env = (typeof window === 'object' && window)
4
4
  || {};
5
5
  class ApiError extends Error {
6
6
  constructor(config, response, msg, isTimeout = false) {
7
- super(response?.statusText || msg || 'Request error');
7
+ if (response) {
8
+ super(response.statusText);
9
+ this.data = response.data;
10
+ this.statusCode = response.status;
11
+ } else {
12
+ super(msg || 'Request error');
13
+ }
8
14
  this.config = config;
9
15
  this.response = response;
10
- this.statusCode = response?.status;
11
16
  this.isTimeout = isTimeout;
12
17
  }
13
18
  }
@@ -101,6 +106,11 @@ const api = async (config, retries = 0) => {
101
106
  });
102
107
  }
103
108
  }
109
+ try {
110
+ response.data = await response?.json();
111
+ } catch (e) {
112
+ //
113
+ }
104
114
  throw new ApiError(config, response);
105
115
  };
106
116
  const get = (endpoint, config) => api({ ...config, endpoint });
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,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,MAAM,OAAO,GAAqC,EAAE,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC;QACxE,IAAI,MAAM,CAAC,WAAW,EAAE;YACtB,wCAAwC;YACxC,OAAO,CAAC,eAAe,CAAC,GAAG,UAAU,MAAM,CAAC,WAAW,EAAE,CAAC;SAC3D;aAAM,IAAI,M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,MAAM;IACT,MAAM,EAAE,OAAO;IACf,QAAQ;IACR,IAAI;CACL,CAAC,CAAC;AAEH,MAAM,GAAG,GAAG,CAAC,QAAkB,EAAE,MAA4B,EAAE,EAAE,CAAC,GAAG,CAAC;IACpE,GAAG,MAAM;IACT,MAAM,EAAE,QAAQ;IAChB,QAAQ;CACT,CAAC,CAAC;AAEH,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC;AACd,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;AAChB,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC;AACd,GAAG,CAAC,KAAK,GAAG,KAAK,CAAC;AAClB,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC;AACd,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC;AAEjB,eAAe,GAAG,CAAC;AAEnB,OAAO,EACL,aAAa,EACb,GAAG,EACH,IAAI,EACJ,GAAG,EACH,KAAK,EACL,GAAG,EACH,QAAQ,GACT,CAAC"}
@@ -27,7 +27,7 @@ declare type Config = {
27
27
  lang?: string;
28
28
  method?: Method;
29
29
  endpoint: Endpoint;
30
- params?: Record<string, string | number>;
30
+ params?: Record<string, string | number | boolean>;
31
31
  headers?: Headers | Record<string, string>;
32
32
  timeout?: number;
33
33
  maxRetries?: number;
@@ -91,4 +91,14 @@ declare type ResponseBody<TConfig extends Config> = TConfig['method'] extends 'p
91
91
  declare type DocSchema<Document extends any> = Omit<Document, '_id' | 'store_id' | 'store_ids' | 'created_at' | 'updated_at'>;
92
92
  declare type SetDocEndpoint<TResource extends Resource> = TResource | `${TResource}/${ResourceId}`;
93
93
  declare type RequestBody<TConfig extends Config> = TConfig['method'] extends undefined | 'get' | 'delete' ? undefined : TConfig['method'] extends 'patch' ? any : TConfig['endpoint'] extends SetDocEndpoint<'products'> ? DocSchema<Products> : TConfig['endpoint'] extends SetDocEndpoint<'categories'> ? DocSchema<Categories> : TConfig['endpoint'] extends SetDocEndpoint<'brands'> ? DocSchema<Brands> : TConfig['endpoint'] extends SetDocEndpoint<'collections'> ? DocSchema<Collections> : TConfig['endpoint'] extends SetDocEndpoint<'grids'> ? DocSchema<Grids> : TConfig['endpoint'] extends SetDocEndpoint<'carts'> ? DocSchema<Carts> : TConfig['endpoint'] extends SetDocEndpoint<'orders'> ? DocSchema<Orders> : TConfig['endpoint'] extends SetDocEndpoint<'customers'> ? DocSchema<Customers> : TConfig['endpoint'] extends SetDocEndpoint<'stores'> ? DocSchema<Stores> : TConfig['endpoint'] extends SetDocEndpoint<'applications'> ? DocSchema<Applications> : TConfig['endpoint'] extends SetDocEndpoint<'authentications'> ? DocSchema<Authentications> : any;
94
- export type { Products, Categories, Brands, Collections, Grids, Carts, Orders, Customers, Stores, Applications, Authentications, Resource, ResourceId, ResourceAndId, ResourceOpQuery, Endpoint, Method, Config, ResourceListResult, EventsResult, ResponseBody, RequestBody, };
94
+ declare type ErrorBody = {
95
+ status: number;
96
+ error_code: number;
97
+ message: string;
98
+ user_message?: {
99
+ en_us: string;
100
+ pt_br: string;
101
+ };
102
+ more_info?: string;
103
+ };
104
+ export type { Products, Categories, Brands, Collections, Grids, Carts, Orders, Customers, Stores, Applications, Authentications, Resource, ResourceId, ResourceAndId, ResourceOpQuery, Endpoint, Method, Config, ResourceListResult, EventsResult, ResponseBody, RequestBody, ErrorBody, };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/api",
3
3
  "type": "module",
4
- "version": "0.0.42",
4
+ "version": "0.0.45",
5
5
  "description": "E-Com Plus Cloud Commerce APIs client/adapter",
6
6
  "main": "lib/index.js",
7
7
  "types": "lib/index.d.ts",
@@ -4,6 +4,7 @@ import type {
4
4
  Config,
5
5
  ResponseBody,
6
6
  RequestBody,
7
+ ErrorBody,
7
8
  } from './types';
8
9
 
9
10
  // @ts-ignore
@@ -13,14 +14,25 @@ const env: { [key: string]: string } = (typeof window === 'object' && window)
13
14
 
14
15
  class ApiError extends Error {
15
16
  config: Config;
16
- response?: Response;
17
+ response?: Response & { data?: ErrorBody };
17
18
  statusCode?: number;
19
+ data?: ErrorBody;
18
20
  isTimeout: boolean;
19
- constructor(config: Config, response?: Response, msg?: string, isTimeout: boolean = false) {
20
- super(response?.statusText || msg || 'Request error');
21
+ constructor(
22
+ config: Config,
23
+ response?: ApiError['response'],
24
+ msg?: string,
25
+ isTimeout: boolean = false,
26
+ ) {
27
+ if (response) {
28
+ super(response.statusText);
29
+ this.data = response.data;
30
+ this.statusCode = response.status;
31
+ } else {
32
+ super(msg || 'Request error');
33
+ }
21
34
  this.config = config;
22
35
  this.response = response;
23
- this.statusCode = response?.status;
24
36
  this.isTimeout = isTimeout;
25
37
  }
26
38
  }
@@ -98,7 +110,7 @@ Promise<Response & {
98
110
  abortController.abort();
99
111
  isTimeout = true;
100
112
  }, timeout);
101
- let response: Response | undefined;
113
+ let response: Response & { data?: any } | undefined;
102
114
  try {
103
115
  response = await (config.fetch || fetch)(url, {
104
116
  method,
@@ -129,6 +141,11 @@ Promise<Response & {
129
141
  });
130
142
  }
131
143
  }
144
+ try {
145
+ response.data = await response?.json() as ErrorBody;
146
+ } catch (e) {
147
+ //
148
+ }
132
149
  throw new ApiError(config, response);
133
150
  };
134
151
 
@@ -197,3 +214,9 @@ export {
197
214
  del,
198
215
  ApiError,
199
216
  };
217
+
218
+ export type ApiEndpoint = Endpoint;
219
+
220
+ export type ApiConfig = Config;
221
+
222
+ export type ApiErrorBody = ErrorBody;
@@ -56,7 +56,7 @@ type Config = {
56
56
  lang?: string,
57
57
  method?: Method,
58
58
  endpoint: Endpoint,
59
- params?: Record<string, string | number>,
59
+ params?: Record<string, string | number | boolean>,
60
60
  headers?: Headers | Record<string, string>,
61
61
  timeout?: number,
62
62
  maxRetries?: number,
@@ -171,6 +171,17 @@ type RequestBody<TConfig extends Config> =
171
171
  TConfig['endpoint'] extends SetDocEndpoint<'authentications'> ? DocSchema<Authentications> :
172
172
  any;
173
173
 
174
+ type ErrorBody = {
175
+ status: number,
176
+ error_code: number,
177
+ message: string,
178
+ user_message?: {
179
+ en_us: string,
180
+ pt_br: string,
181
+ },
182
+ more_info?: string,
183
+ };
184
+
174
185
  export type {
175
186
  Products,
176
187
  Categories,
@@ -194,4 +205,5 @@ export type {
194
205
  EventsResult,
195
206
  ResponseBody,
196
207
  RequestBody,
208
+ ErrorBody,
197
209
  };
@@ -0,0 +1,3 @@
1
+ import type { AppEventsTopic } from '@cloudcommerce/types';
2
+ export declare const events: AppEventsTopic[];
3
+ export declare const applyDiscount: () => Promise<{}>;
@@ -1,4 +1,6 @@
1
1
  export const events = [];
2
2
 
3
- export const modules = {};
3
+ export const applyDiscount = async () => {
4
+ return {};
5
+ };
4
6
  // # sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,MAAM,GAAiB,EAAE,CAAC;AAEvC,MAAM,CAAC,MAAM,OAAO,GAAG,EAAE,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,MAAM,GAAqB,EAAE,CAAC;AAE3C,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,IAAI,EAAE;IACtC,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC"}
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-discounts",
3
3
  "type": "module",
4
- "version": "0.0.42",
4
+ "version": "0.0.45",
5
5
  "description": "E-Com Plus Cloud Commerce app for complex discount rules",
6
- "main": "functions/dist/index.js",
6
+ "main": "lib/index.js",
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/apps/discounts#readme",
18
18
  "scripts": {
19
- "build": "echo '@ecomplus/app-discounts'"
19
+ "build": "sh ../../../scripts/build-lib.sh"
20
20
  },
21
21
  "dependencies": {
22
22
  "@cloudcommerce/api": "workspace:*"
@@ -2,6 +2,6 @@ import type { AppEventsTopic } from '@cloudcommerce/types';
2
2
 
3
3
  export const events: AppEventsTopic[] = [];
4
4
 
5
- export const applyDiscount = () => {
5
+ export const applyDiscount = async () => {
6
6
  return {};
7
7
  };
@@ -1,3 +1,6 @@
1
1
  {
2
- "extends": "../../../tsconfig.json"
2
+ "extends": "../../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "declaration": true
5
+ }
3
6
  }
@@ -8,8 +8,11 @@ const copyFunctionsConfig = async () => {
8
8
  for (let i = 0; i < dirents.length; i++) {
9
9
  if (dirents[i].isDirectory() && dirents[i].name.charAt(0) !== '.') {
10
10
  for (let ii = 0; ii < filesToCopy.length; ii++) {
11
- // eslint-disable-next-line no-await-in-loop
12
- await fs.copy(path.join(functionsDir, filesToCopy[ii]), path.join(functionsDir, dirents[i].name, filesToCopy[ii]));
11
+ const srcPath = path.join(functionsDir, filesToCopy[ii]);
12
+ if (fs.existsSync(srcPath)) {
13
+ // eslint-disable-next-line no-await-in-loop
14
+ await fs.copy(srcPath, path.join(functionsDir, dirents[i].name, filesToCopy[ii]));
15
+ }
13
16
  }
14
17
  }
15
18
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/cli",
3
3
  "type": "module",
4
- "version": "0.0.42",
4
+ "version": "0.0.45",
5
5
  "description": "E-Com Plus Cloud Commerce CLI tools",
6
6
  "bin": {
7
7
  "cloudcommerce": "./bin/run.mjs"
@@ -8,11 +8,14 @@ const copyFunctionsConfig = async () => {
8
8
  for (let i = 0; i < dirents.length; i++) {
9
9
  if (dirents[i].isDirectory() && dirents[i].name.charAt(0) !== '.') {
10
10
  for (let ii = 0; ii < filesToCopy.length; ii++) {
11
- // eslint-disable-next-line no-await-in-loop
12
- await fs.copy(
13
- path.join(functionsDir, filesToCopy[ii]),
14
- path.join(functionsDir, dirents[i].name, filesToCopy[ii]),
15
- );
11
+ const srcPath = path.join(functionsDir, filesToCopy[ii]);
12
+ if (fs.existsSync(srcPath)) {
13
+ // eslint-disable-next-line no-await-in-loop
14
+ await fs.copy(
15
+ srcPath,
16
+ path.join(functionsDir, dirents[i].name, filesToCopy[ii]),
17
+ );
18
+ }
16
19
  }
17
20
  }
18
21
  }
@@ -0,0 +1 @@
1
+ Please refer to GitHub [repository releases](https://github.com/ecomplus/cloud-commerce/releases) or monorepo unified [CHANGELOG.md](https://github.com/ecomplus/cloud-commerce/blob/main/CHANGELOG.md).
@@ -0,0 +1 @@
1
+ # `@cloudcommerce/events`
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@cloudcommerce/events",
3
+ "type": "module",
4
+ "version": "0.0.45",
5
+ "description": "E-Com Plus Cloud Commerce app events",
6
+ "main": "lib/index.js",
7
+ "exports": {
8
+ ".": "./lib/index.js",
9
+ "./firebase": "./lib/firebase.js"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/ecomplus/cloud-commerce.git",
14
+ "directory": "packages/events"
15
+ },
16
+ "author": "E-Com Club Softwares para E-commerce <ti@e-com.club>",
17
+ "license": "Apache 2.0 with Commons Clause",
18
+ "bugs": {
19
+ "url": "https://github.com/ecomplus/cloud-commerce/issues"
20
+ },
21
+ "homepage": "https://github.com/ecomplus/cloud-commerce/tree/main/packages/events#readme",
22
+ "scripts": {
23
+ "build": "echo '@ecomplus/events'"
24
+ },
25
+ "dependencies": {
26
+ "@cloudcommerce/api": "workspace:*",
27
+ "@cloudcommerce/firebase": "workspace:*",
28
+ "firebase-admin": "^11.0.1",
29
+ "firebase-functions": "^3.22.0",
30
+ "source-map-support": "^0.5.21"
31
+ },
32
+ "devDependencies": {
33
+ "@cloudcommerce/types": "workspace:*",
34
+ "@firebase/app-types": "^0.7.0"
35
+ }
36
+ }
@@ -0,0 +1,31 @@
1
+ /* eslint-disable import/prefer-default-export */
2
+
3
+ import type { AppEventsTopic } from '@cloudcommerce/types';
4
+ import 'source-map-support/register.js';
5
+ // eslint-disable-next-line import/no-unresolved
6
+ import { initializeApp } from 'firebase-admin/app';
7
+ // eslint-disable-next-line import/no-unresolved
8
+ import { runWith, logger } from 'firebase-functions';
9
+
10
+ initializeApp();
11
+
12
+ const eventMaxAgeMs = 60000;
13
+ const newOrderTopic: AppEventsTopic = 'orders-new';
14
+
15
+ // eslint-disable-next-line camelcase
16
+ export const on_new_order = runWith({ failurePolicy: true })
17
+ .pubsub.topic(newOrderTopic).onPublish((message, context) => {
18
+ const eventAgeMs = Date.now() - Date.parse(context.timestamp);
19
+ if (eventAgeMs > eventMaxAgeMs) {
20
+ logger.warn(`Dropping event ${context.eventId} with age[ms]: ${eventAgeMs}`);
21
+ return;
22
+ }
23
+ // Hide API key for security
24
+ process.env.ECOM_API_KEY = '***';
25
+ const { json } = message;
26
+ logger.info({
27
+ topic: newOrderTopic,
28
+ eventId: context.eventId,
29
+ json,
30
+ });
31
+ });
@@ -0,0 +1 @@
1
+ export default {};
@@ -0,0 +1,3 @@
1
+ {
2
+ "extends": "../../tsconfig.json"
3
+ }
@@ -9,6 +9,11 @@ declare const _default: {
9
9
  httpsFunctionOptions: {
10
10
  region: string;
11
11
  };
12
+ apps: {
13
+ discounts: {
14
+ appId: number;
15
+ };
16
+ };
12
17
  };
13
18
  set(config: any): void;
14
19
  };
@@ -1,25 +1,34 @@
1
1
  import Deepmerge from '@fastify/deepmerge';
2
- import { DEFAULT_LANG, DEFAULT_CURRENCY, DEFAULT_CURRENCY_SYMBOL, DEFAULT_COUNTRY_CODE, } from './defaults.js';
2
+ import {
3
+ DEFAULT_LANG, DEFAULT_CURRENCY, DEFAULT_CURRENCY_SYMBOL, DEFAULT_COUNTRY_CODE,
4
+ } from './defaults.js';
5
+
3
6
  const deepmerge = Deepmerge();
4
7
  const self = {
5
- __config: {
6
- hello: 'from @cloudcommerce/firebase',
7
- lang: process.env.ECOM_LANG || DEFAULT_LANG,
8
- currency: process.env.ECOM_CURRENCY || DEFAULT_CURRENCY,
9
- currencySymbol: process.env.ECOM_CURRENCY_SYMBOL || DEFAULT_CURRENCY_SYMBOL,
10
- countryCode: process.env.ECOM_COUNTRY_CODE || DEFAULT_COUNTRY_CODE,
11
- storeId: Number(process.env.ECOM_STORE_ID),
12
- httpsFunctionOptions: {
13
- region: process.env.DEPLOY_REGION || 'us-east1',
14
- },
8
+ __config: {
9
+ hello: 'from @cloudcommerce/firebase',
10
+ lang: process.env.ECOM_LANG || DEFAULT_LANG,
11
+ currency: process.env.ECOM_CURRENCY || DEFAULT_CURRENCY,
12
+ currencySymbol: process.env.ECOM_CURRENCY_SYMBOL || DEFAULT_CURRENCY_SYMBOL,
13
+ countryCode: process.env.ECOM_COUNTRY_CODE || DEFAULT_COUNTRY_CODE,
14
+ storeId: Number(process.env.ECOM_STORE_ID),
15
+ httpsFunctionOptions: {
16
+ region: process.env.DEPLOY_REGION || 'us-east1',
15
17
  },
18
+ apps: {
19
+ discounts: {
20
+ appId: 912000,
21
+ },
22
+ },
23
+ },
16
24
  };
25
+
17
26
  export default {
18
- get() {
19
- return self.__config;
20
- },
21
- set(config) {
22
- self.__config = deepmerge(self.__config, config);
23
- },
27
+ get() {
28
+ return self.__config;
29
+ },
30
+ set(config) {
31
+ self.__config = deepmerge(self.__config, config);
32
+ },
24
33
  };
25
- //# sourceMappingURL=config.js.map
34
+ // # sourceMappingURL=config.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,YAAY,CAAC;AAEpB,MAAM,SAAS,GAAG,SAAS,EAAE,CAAC;AAE9B,MAAM,IAAI,GAAG;IACX,QAAQ,EAAE;QACR,KAAK,EAAE,8BAA8B;QACrC,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,Y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M,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa,IAAI,UAAU;SAChD;QACD,IAAI,EAAE;YACJ,SAAS,EAAE;gBACT,KAAK,EAAE,MAAM;aACd;SACF;KACF;CACF,CAAC;AAEF,eAAe;IACb,GAAG;QACD,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IACD,GAAG,CAAC,MAAM;QACR,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IACnD,CAAC;CACF,CAAC"}
@@ -1,5 +1,8 @@
1
1
  export const DEFAULT_LANG = 'pt_br';
2
+
2
3
  export const DEFAULT_CURRENCY = 'BRL';
4
+
3
5
  export const DEFAULT_CURRENCY_SYMBOL = 'R$';
6
+
4
7
  export const DEFAULT_COUNTRY_CODE = 'BR';
5
- //# sourceMappingURL=defaults.js.map
8
+ // # sourceMappingURL=defaults.js.map
@@ -1,19 +1,19 @@
1
1
  export default () => {
2
- const { ECOM_AUTHENTICATION_ID, ECOM_API_KEY, GITHUB_TOKEN, } = process.env;
3
- if (!ECOM_AUTHENTICATION_ID) {
4
- throw new Error('ECOM_AUTHENTICATION_ID is not set');
5
- }
6
- if (!ECOM_API_KEY) {
7
- throw new Error('ECOM_API_KEY is not set');
8
- }
9
- const authenticationId = ECOM_AUTHENTICATION_ID;
10
- const apiKey = ECOM_API_KEY;
11
- const githubToken = GITHUB_TOKEN;
12
- const env = {
13
- authenticationId,
14
- apiKey,
15
- githubToken,
16
- };
17
- return env;
2
+ const { ECOM_AUTHENTICATION_ID, ECOM_API_KEY, GITHUB_TOKEN } = process.env;
3
+ if (!ECOM_AUTHENTICATION_ID) {
4
+ throw new Error('ECOM_AUTHENTICATION_ID is not set');
5
+ }
6
+ if (!ECOM_API_KEY) {
7
+ throw new Error('ECOM_API_KEY is not set');
8
+ }
9
+ const authenticationId = ECOM_AUTHENTICATION_ID;
10
+ const apiKey = ECOM_API_KEY;
11
+ const githubToken = GITHUB_TOKEN;
12
+ const env = {
13
+ authenticationId,
14
+ apiKey,
15
+ githubToken,
16
+ };
17
+ return env;
18
18
  };
19
- //# sourceMappingURL=env.js.map
19
+ // # sourceMappingURL=env.js.map