cloudcommerce 0.0.95 → 0.0.97

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 (101) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/package.json +3 -3
  3. package/packages/api/package.json +1 -1
  4. package/packages/apps/correios/lib-mjs/correios-ws.mjs +2 -1
  5. package/packages/apps/correios/package.json +1 -1
  6. package/packages/apps/custom-shipping/package.json +1 -1
  7. package/packages/apps/discounts/package.json +1 -1
  8. package/packages/apps/frenet/package.json +1 -1
  9. package/packages/apps/tiny-erp/package.json +2 -2
  10. package/packages/cli/package.json +1 -1
  11. package/packages/config/package.json +1 -1
  12. package/packages/events/package.json +2 -2
  13. package/packages/firebase/lib/config.js +25 -27
  14. package/packages/firebase/lib/const.js +2 -3
  15. package/packages/firebase/lib/env.js +1 -2
  16. package/packages/firebase/lib/handlers/check-store-events.js +145 -146
  17. package/packages/firebase/lib/helpers/pubsub.js +18 -20
  18. package/packages/firebase/lib/helpers/update-app-data.js +38 -38
  19. package/packages/firebase/lib/index.js +7 -9
  20. package/packages/firebase/lib/init.js +1 -2
  21. package/packages/firebase/package.json +3 -3
  22. package/packages/modules/package.json +2 -2
  23. package/packages/passport/package.json +2 -2
  24. package/packages/ssr/lib/firebase.js +1 -1
  25. package/packages/ssr/lib/firebase.js.map +1 -1
  26. package/packages/ssr/package.json +2 -2
  27. package/packages/ssr/src/firebase.ts +1 -1
  28. package/packages/storefront/.eslintrc.cjs +1 -0
  29. package/packages/storefront/astro.config.mjs +11 -1
  30. package/packages/storefront/example.env +1 -1
  31. package/packages/storefront/package.json +6 -5
  32. package/packages/storefront/src/assets/pico.css +0 -1
  33. package/packages/storefront/src/env.d.ts +1 -1
  34. package/packages/storefront/src/lib/components/AOffcanvas.vue +98 -0
  35. package/packages/storefront/src/lib/components/LoginForm.vue +54 -0
  36. package/packages/storefront/src/lib/components/LoginOffcanvas.vue +41 -0
  37. package/packages/storefront/src/lib/components/TheHeader.vue +37 -3
  38. package/packages/storefront/src/lib/components/TopBar.vue +13 -21
  39. package/packages/storefront/src/lib/layouts/BaseBody.astro +41 -38
  40. package/packages/storefront/src/lib/layouts/BaseHead.astro +0 -5
  41. package/packages/storefront/src/lib/layouts/BaseStateJson.astro +12 -11
  42. package/packages/storefront/src/lib/layouts/PagesHeader.astro +28 -20
  43. package/packages/storefront/src/lib/scripts/firebase-app.ts +16 -0
  44. package/packages/storefront/src/lib/{helpers → ssr}/image.ts +4 -2
  45. package/packages/storefront/src/pages/app/account.astro +0 -0
  46. package/packages/storefront/storefront.config.mjs +6 -7
  47. package/packages/storefront/tsconfig.json +4 -1
  48. package/packages/types/package.json +1 -1
  49. package/store.renovate.json +55 -0
  50. package/packages/storefront/dist/client/admin/config.json +0 -1
  51. package/packages/storefront/dist/client/assets/_...73e01db2.css +0 -4
  52. package/packages/storefront/dist/client/assets/_...ee104f19.css +0 -1
  53. package/packages/storefront/dist/client/assets/cms-preview.css +0 -274
  54. package/packages/storefront/dist/client/assets/cms.css +0 -114
  55. package/packages/storefront/dist/client/assets/cvv.png +0 -0
  56. package/packages/storefront/dist/client/assets/icons/bootstrap-icons/font/storefront-icons.woff2 +0 -0
  57. package/packages/storefront/dist/client/assets/icons/feather-icons/font/storefront-icons.woff2 +0 -0
  58. package/packages/storefront/dist/client/assets/icons/font-awesome/font/storefront-icons.woff2 +0 -0
  59. package/packages/storefront/dist/client/assets/icons/line-awesome/font/storefront-icons.woff2 +0 -0
  60. package/packages/storefront/dist/client/assets/icons/tabler-icons/font/storefront-icons.woff2 +0 -0
  61. package/packages/storefront/dist/client/assets/img-placeholder.png +0 -0
  62. package/packages/storefront/dist/client/assets/payments.png +0 -0
  63. package/packages/storefront/dist/client/assets/ssl-safe.png +0 -0
  64. package/packages/storefront/dist/client/chunks/workbox-window.prod.es5.4b654ae6.js +0 -2
  65. package/packages/storefront/dist/client/client.80baece3.js +0 -1
  66. package/packages/storefront/dist/client/hoisted.46e058d2.js +0 -271
  67. package/packages/storefront/dist/client/img/icon.png +0 -0
  68. package/packages/storefront/dist/client/img/large-icon.png +0 -0
  69. package/packages/storefront/dist/client/img/uploads/banner1.png +0 -0
  70. package/packages/storefront/dist/client/img/uploads/banner2.png +0 -0
  71. package/packages/storefront/dist/client/img/uploads/banner2.webp +0 -0
  72. package/packages/storefront/dist/client/img/uploads/favicon.png +0 -0
  73. package/packages/storefront/dist/client/img/uploads/headless.png +0 -0
  74. package/packages/storefront/dist/client/img/uploads/headphone.png +0 -0
  75. package/packages/storefront/dist/client/img/uploads/headphone.webp +0 -0
  76. package/packages/storefront/dist/client/img/uploads/icon.png +0 -0
  77. package/packages/storefront/dist/client/img/uploads/large-icon.png +0 -0
  78. package/packages/storefront/dist/client/img/uploads/logo.png +0 -0
  79. package/packages/storefront/dist/client/img/uploads/logo.webp +0 -0
  80. package/packages/storefront/dist/client/img/uploads/og-image.png +0 -0
  81. package/packages/storefront/dist/client/img/uploads/passion.png +0 -0
  82. package/packages/storefront/dist/client/img/uploads/passion.webp +0 -0
  83. package/packages/storefront/dist/client/img/uploads/pwa-reliable.png +0 -0
  84. package/packages/storefront/dist/client/img/uploads/rect8589.png +0 -0
  85. package/packages/storefront/dist/client/img/uploads/rect859.png +0 -0
  86. package/packages/storefront/dist/client/img/uploads/rect89.png +0 -0
  87. package/packages/storefront/dist/client/img/uploads/rect89.webp +0 -0
  88. package/packages/storefront/dist/client/img/uploads/ssl-safe.png +0 -0
  89. package/packages/storefront/dist/client/manifest.webmanifest +0 -1
  90. package/packages/storefront/dist/client/page.3aa82516.js +0 -1
  91. package/packages/storefront/dist/client/robots.txt +0 -8
  92. package/packages/storefront/dist/client/sw.js +0 -1
  93. package/packages/storefront/dist/client/workbox-6f0d1f78.js +0 -1
  94. package/packages/storefront/dist/client/~partytown/partytown-atomics.js +0 -2
  95. package/packages/storefront/dist/client/~partytown/partytown-media.js +0 -2
  96. package/packages/storefront/dist/client/~partytown/partytown-sw.js +0 -2
  97. package/packages/storefront/dist/client/~partytown/partytown.js +0 -2
  98. package/packages/storefront/dist/server/entry.mjs +0 -2662
  99. package/packages/storefront/dist/server/manifest.webmanifest +0 -1
  100. package/packages/storefront/dist/server/registerSW.js +0 -1
  101. package/packages/storefront/src/lib/components/LoginModal.vue +0 -82
package/CHANGELOG.md CHANGED
@@ -2,6 +2,28 @@
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.97](https://github.com/ecomplus/cloud-commerce/compare/v0.0.96...v0.0.97) (2022-09-27)
6
+
7
+
8
+ ### Features
9
+
10
+ * **storefront:** Login offcanvas with first Firebase Auth interaction ([01519b0](https://github.com/ecomplus/cloud-commerce/commit/01519b0af00fda5db95eab69dddd6e96869f1e44))
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * **app-correios:** XML parsing fix to json ([#52](https://github.com/ecomplus/cloud-commerce/issues/52)) ([58a922f](https://github.com/ecomplus/cloud-commerce/commit/58a922f125640b24ee5a132d74f13a8400da4fee))
16
+ * **deps:** Update all non-major dependencies ([#51](https://github.com/ecomplus/cloud-commerce/issues/51)) ([8d447a2](https://github.com/ecomplus/cloud-commerce/commit/8d447a23868ec5e07211ba3058e535c3ddf3681a))
17
+ * **storefront:** Edit `pico.css` styles to remove link background on focus ([fd14624](https://github.com/ecomplus/cloud-commerce/commit/fd14624e56c6989ac1c98acc34370a7634b3af53))
18
+
19
+ ### [0.0.96](https://github.com/ecomplus/cloud-commerce/compare/v0.0.95...v0.0.96) (2022-09-24)
20
+
21
+
22
+ ### Bug Fixes
23
+
24
+ * **storefront:** Image size input with full image path using `STOREFRONT_BASE_DIR` ([59bb3f6](https://github.com/ecomplus/cloud-commerce/commit/59bb3f67fb074536fa280326ae8c268187b065f7))
25
+ * **storefront:** Must always set `process.env.STOREFRONT_BASE_DIR` instead of `import.meta.env` ([d4b0812](https://github.com/ecomplus/cloud-commerce/commit/d4b0812e4119119c4ac6489bbee7116b4927ac74))
26
+
5
27
  ### [0.0.95](https://github.com/ecomplus/cloud-commerce/compare/v0.0.94...v0.0.95) (2022-09-24)
6
28
 
7
29
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "cloudcommerce",
3
3
  "type": "module",
4
- "version": "0.0.95",
4
+ "version": "0.0.97",
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>",
@@ -23,7 +23,7 @@
23
23
  "@typescript-eslint/eslint-plugin": "^5.38.0",
24
24
  "@typescript-eslint/parser": "^5.38.0",
25
25
  "esbuild": "^0.15.9",
26
- "eslint": "^8.23.1",
26
+ "eslint": "^8.24.0",
27
27
  "eslint-config-airbnb-base": "^15.0.0",
28
28
  "eslint-plugin-import": "^2.26.0",
29
29
  "eslint-plugin-vue": "^9.5.1",
@@ -31,7 +31,7 @@
31
31
  "node-fetch": "^3.2.10",
32
32
  "standard-version": "^9.5.0",
33
33
  "ts-node": "^10.9.1",
34
- "turbo": "^1.5.1",
34
+ "turbo": "^1.5.3",
35
35
  "typescript": "^4.8.3",
36
36
  "vite": "^3.1.3",
37
37
  "vitest": "^0.23.4",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/api",
3
3
  "type": "module",
4
- "version": "0.0.95",
4
+ "version": "0.0.97",
5
5
  "description": "E-Com Plus Cloud Commerce APIs client/adapter",
6
6
  "main": "lib/api.js",
7
7
  "types": "lib/api.d.ts",
@@ -27,7 +27,8 @@ const sendCalculateRequest = (params, timeout, isDebug = false) => {
27
27
  })
28
28
  .then(async (response) => {
29
29
  // parse XML to object
30
- const result = await xml2js.parseStringPromise(response.data);
30
+ // https://www.npmjs.com/package/xml2js#options/
31
+ const result = await xml2js.parseStringPromise(response.data, { explicitArray: false });
31
32
  let services;
32
33
  if (Array.isArray(result.Servicos)) {
33
34
  services = result.Servicos;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-correios",
3
3
  "type": "module",
4
- "version": "0.0.95",
4
+ "version": "0.0.97",
5
5
  "description": "E-Com Plus Cloud Commerce app for Correios shipping calculation",
6
6
  "main": "lib/correios.js",
7
7
  "repository": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-custom-shipping",
3
3
  "type": "module",
4
- "version": "0.0.95",
4
+ "version": "0.0.97",
5
5
  "description": "E-Com Plus Cloud Commerce app for custom shipping methods",
6
6
  "main": "lib/custom-shipping.js",
7
7
  "repository": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-discounts",
3
3
  "type": "module",
4
- "version": "0.0.95",
4
+ "version": "0.0.97",
5
5
  "description": "E-Com Plus Cloud Commerce app for complex discount rules",
6
6
  "main": "lib/discounts.js",
7
7
  "repository": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-frenet",
3
3
  "type": "module",
4
- "version": "0.0.95",
4
+ "version": "0.0.97",
5
5
  "description": "E-Com Plus Cloud Commerce app for Frenet shipping calculation",
6
6
  "main": "lib/frenet.js",
7
7
  "repository": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-tiny-erp",
3
3
  "type": "module",
4
- "version": "0.0.95",
4
+ "version": "0.0.97",
5
5
  "description": "E-Com Plus Cloud Commerce app for Tiny ERP",
6
6
  "main": "lib/tiny-erp.js",
7
7
  "repository": {
@@ -24,7 +24,7 @@
24
24
  "@ecomplus/utils": "^1.4.1",
25
25
  "axios": "^0.27.2",
26
26
  "firebase-admin": "^11.0.1",
27
- "firebase-functions": "^3.23.0",
27
+ "firebase-functions": "^3.24.0",
28
28
  "form-data": "^4.0.0"
29
29
  },
30
30
  "devDependencies": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/cli",
3
3
  "type": "module",
4
- "version": "0.0.95",
4
+ "version": "0.0.97",
5
5
  "description": "E-Com Plus Cloud Commerce CLI tools",
6
6
  "bin": {
7
7
  "cloudcommerce": "./bin/run.mjs"
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/config",
3
3
  "type": "module",
4
- "version": "0.0.95",
4
+ "version": "0.0.97",
5
5
  "description": "E-Com Plus Cloud Commerce base config",
6
6
  "main": "lib/config.js",
7
7
  "exports": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/events",
3
3
  "type": "module",
4
- "version": "0.0.95",
4
+ "version": "0.0.97",
5
5
  "description": "E-Com Plus Cloud Commerce app events",
6
6
  "main": "lib/index.js",
7
7
  "exports": {
@@ -27,7 +27,7 @@
27
27
  "@cloudcommerce/app-tiny-erp": "workspace:*",
28
28
  "@cloudcommerce/firebase": "workspace:*",
29
29
  "firebase-admin": "^11.0.1",
30
- "firebase-functions": "^3.23.0",
30
+ "firebase-functions": "^3.24.0",
31
31
  "source-map-support": "^0.5.21"
32
32
  },
33
33
  "devDependencies": {
@@ -1,36 +1,34 @@
1
1
  import config from '@cloudcommerce/config';
2
-
3
2
  const tinyErpEvents = [
4
- 'orders-anyStatusSet',
5
- 'products-new',
6
- 'products-priceSet',
7
- 'applications-dataSet',
3
+ 'orders-anyStatusSet',
4
+ 'products-new',
5
+ 'products-priceSet',
6
+ 'applications-dataSet',
8
7
  ];
9
8
  const mergeConfig = {
10
- hello: 'from @cloudcommerce/firebase',
11
- httpsFunctionOptions: {
12
- region: process.env.DEPLOY_REGION || 'southamerica-east1',
13
- },
14
- apps: {
15
- discounts: {
16
- appId: 1252,
9
+ hello: 'from @cloudcommerce/firebase',
10
+ httpsFunctionOptions: {
11
+ region: process.env.DEPLOY_REGION || 'southamerica-east1',
17
12
  },
18
- correios: {
19
- appId: 1248,
13
+ apps: {
14
+ discounts: {
15
+ appId: 1252,
16
+ },
17
+ correios: {
18
+ appId: 1248,
19
+ },
20
+ customShipping: {
21
+ appId: 1253,
22
+ },
23
+ frenet: {
24
+ appId: 1244,
25
+ },
26
+ tinyErp: {
27
+ appId: 105922,
28
+ events: tinyErpEvents,
29
+ },
20
30
  },
21
- customShipping: {
22
- appId: 1253,
23
- },
24
- frenet: {
25
- appId: 1244,
26
- },
27
- tinyErp: {
28
- appId: 105922,
29
- events: tinyErpEvents,
30
- },
31
- },
32
31
  };
33
32
  config.set(mergeConfig);
34
-
35
33
  export default config;
36
- // # sourceMappingURL=config.js.map
34
+ //# sourceMappingURL=config.js.map
@@ -1,6 +1,5 @@
1
1
  export const EVENT_SKIP_FLAG = '_skip';
2
-
3
2
  export const GET_PUBSUB_TOPIC = (appId) => {
4
- return `app${appId}_api_events`;
3
+ return `app${appId}_api_events`;
5
4
  };
6
- // # sourceMappingURL=const.js.map
5
+ //# sourceMappingURL=const.js.map
@@ -1,4 +1,3 @@
1
1
  import getEnv from '@cloudcommerce/config/lib/env';
2
-
3
2
  export default getEnv;
4
- // # sourceMappingURL=env.js.map
3
+ //# sourceMappingURL=env.js.map
@@ -5,126 +5,125 @@ import { PubSub } from '@google-cloud/pubsub';
5
5
  import api from '@cloudcommerce/api';
6
6
  import config from '../config.js';
7
7
  import { EVENT_SKIP_FLAG, GET_PUBSUB_TOPIC } from '../const.js';
8
-
9
8
  const parseEventName = (evName, baseApiEventsFilter) => {
10
- const [resource, actionName] = evName.split('-');
11
- const params = { ...baseApiEventsFilter };
12
- const bodySet = {};
13
- if (actionName === 'new') {
14
- params.action = 'create';
15
- } else {
16
- switch (resource) {
17
- case 'orders':
18
- switch (actionName) {
19
- case 'paid':
20
- bodySet['financial_status.current'] = 'paid';
21
- break;
22
- case 'readyForShipping':
23
- bodySet['fulfillment_status.current'] = 'ready_for_shipping';
24
- break;
25
- case 'shipped':
26
- case 'delivered':
27
- bodySet['fulfillment_status.current'] = actionName;
28
- break;
29
- case 'cancelled':
30
- bodySet.status = 'cancelled';
31
- break;
32
- default: // anyStatusSet
33
- params.modified_fields = [
34
- 'financial_status',
35
- 'fulfillment_status',
36
- 'status',
37
- ];
9
+ const [resource, actionName] = evName.split('-');
10
+ const params = { ...baseApiEventsFilter };
11
+ const bodySet = {};
12
+ if (actionName === 'new') {
13
+ params.action = 'create';
14
+ }
15
+ else {
16
+ switch (resource) {
17
+ case 'orders':
18
+ switch (actionName) {
19
+ case 'paid':
20
+ bodySet['financial_status.current'] = 'paid';
21
+ break;
22
+ case 'readyForShipping':
23
+ bodySet['fulfillment_status.current'] = 'ready_for_shipping';
24
+ break;
25
+ case 'shipped':
26
+ case 'delivered':
27
+ bodySet['fulfillment_status.current'] = actionName;
28
+ break;
29
+ case 'cancelled':
30
+ bodySet.status = 'cancelled';
31
+ break;
32
+ default: // anyStatusSet
33
+ params.modified_fields = [
34
+ 'financial_status',
35
+ 'fulfillment_status',
36
+ 'status',
37
+ ];
38
+ }
39
+ break;
40
+ case 'products':
41
+ params.modified_fields = actionName === 'priceSet'
42
+ ? ['price', 'variations.price']
43
+ : ['quantity']; // quantitySet
44
+ break;
45
+ case 'carts':
46
+ params.modified_fields = ['customers']; // customerSet
47
+ break;
48
+ case 'applications':
49
+ params.modified_fields = ['data', 'hidden_data']; // dataSet
50
+ break;
51
+ default:
38
52
  }
39
- break;
40
- case 'products':
41
- params.modified_fields = actionName === 'priceSet'
42
- ? ['price', 'variations.price']
43
- : ['quantity']; // quantitySet
44
- break;
45
- case 'carts':
46
- params.modified_fields = ['customers']; // customerSet
47
- break;
48
- case 'applications':
49
- params.modified_fields = ['data', 'hidden_data']; // dataSet
50
- break;
51
- default:
52
53
  }
53
- }
54
- Object.keys(bodySet).forEach((field) => {
55
- params[`body.${field}`] = bodySet[field];
56
- });
57
- return { resource, params };
54
+ Object.keys(bodySet).forEach((field) => {
55
+ params[`body.${field}`] = bodySet[field];
56
+ });
57
+ return { resource, params };
58
58
  };
59
59
  const pubSubClient = new PubSub();
60
60
  const tryPubSubPublish = (topicName, messageObj, retries = 0) => {
61
- pubSubClient.topic(topicName).publishMessage(messageObj)
62
- .catch((err) => {
63
- // eslint-disable-next-line no-param-reassign
64
- err.retries = retries;
65
- logger.error(err);
66
- if (retries <= 3) {
67
- setTimeout(() => {
68
- tryPubSubPublish(topicName, messageObj, retries + 1);
69
- }, 1000 * (2 ** retries));
70
- }
61
+ pubSubClient.topic(topicName).publishMessage(messageObj)
62
+ .catch((err) => {
63
+ // eslint-disable-next-line no-param-reassign
64
+ err.retries = retries;
65
+ logger.error(err);
66
+ if (retries <= 3) {
67
+ setTimeout(() => {
68
+ tryPubSubPublish(topicName, messageObj, retries + 1);
69
+ }, 1000 * (2 ** retries));
70
+ }
71
71
  });
72
72
  };
73
-
74
73
  export default async () => {
75
- const timestamp = Date.now();
76
- const documentRef = getFirestore().doc('storeEvents/last');
77
- const documentSnapshot = await documentRef.get();
78
- const lastRunTimestamp = documentSnapshot.get('timestamp')
74
+ const timestamp = Date.now();
75
+ const documentRef = getFirestore().doc('storeEvents/last');
76
+ const documentSnapshot = await documentRef.get();
77
+ const lastRunTimestamp = documentSnapshot.get('timestamp')
79
78
  || Date.now() - 1000 * 60 * 5;
80
- const lastNonOrdersTimestamp = documentSnapshot.get('nonOrdersTimestamp')
79
+ const lastNonOrdersTimestamp = documentSnapshot.get('nonOrdersTimestamp')
81
80
  || 0;
82
- const baseApiEventsFilter = {
83
- 'flag!': EVENT_SKIP_FLAG,
84
- 'timestamp>': new Date(lastRunTimestamp - 1).toISOString(),
85
- 'timestamp<': new Date(timestamp).toISOString(),
86
- };
87
- const { apps } = config.get();
88
- const subscribersApps = [];
89
- Object.keys(apps).forEach((appName) => {
90
- const appObj = apps[appName];
91
- if (appObj.events && appObj.events.length) {
92
- subscribersApps.push(appObj);
93
- }
94
- });
95
- const activeApps = (await api.get('applications', {
96
- params: {
97
- state: 'active',
98
- app_id: subscribersApps.map(({ appId }) => appId),
99
- fields: '_id,app_id,data,hidden_data',
100
- },
101
- })).data.result;
102
- const listenedEvents = [];
103
- subscribersApps.forEach(({ appId, events }) => {
104
- if (activeApps.find((app) => app.app_id === appId)) {
105
- events.forEach((evName) => {
106
- if (!listenedEvents.includes(evName)) {
107
- listenedEvents.push(evName);
81
+ const baseApiEventsFilter = {
82
+ 'flag!': EVENT_SKIP_FLAG,
83
+ 'timestamp>': new Date(lastRunTimestamp - 1).toISOString(),
84
+ 'timestamp<': new Date(timestamp).toISOString(),
85
+ };
86
+ const { apps } = config.get();
87
+ const subscribersApps = [];
88
+ Object.keys(apps).forEach((appName) => {
89
+ const appObj = apps[appName];
90
+ if (appObj.events && appObj.events.length) {
91
+ subscribersApps.push(appObj);
108
92
  }
109
- });
110
- }
111
- });
112
- // Some resource events are not listened to every minute
113
- const isOrdersOnly = Boolean(new Date().getMinutes() % 5);
114
- listenedEvents.forEach(async (listenedEventName) => {
115
- const { resource, params } = parseEventName(listenedEventName, baseApiEventsFilter);
116
- if (resource !== 'orders') {
117
- if (isOrdersOnly) {
118
- return;
119
- }
120
- if (lastNonOrdersTimestamp) {
121
- params['timestamp>'] = new Date(lastNonOrdersTimestamp).toISOString();
122
- }
123
- }
124
- let { data: { result } } = await api.get(`events/${resource}`, {
125
- params,
126
93
  });
127
- /*
94
+ const activeApps = (await api.get('applications', {
95
+ params: {
96
+ state: 'active',
97
+ app_id: subscribersApps.map(({ appId }) => appId),
98
+ fields: '_id,app_id,data,hidden_data',
99
+ },
100
+ })).data.result;
101
+ const listenedEvents = [];
102
+ subscribersApps.forEach(({ appId, events }) => {
103
+ if (activeApps.find((app) => app.app_id === appId)) {
104
+ events.forEach((evName) => {
105
+ if (!listenedEvents.includes(evName)) {
106
+ listenedEvents.push(evName);
107
+ }
108
+ });
109
+ }
110
+ });
111
+ // Some resource events are not listened to every minute
112
+ const isOrdersOnly = Boolean(new Date().getMinutes() % 5);
113
+ listenedEvents.forEach(async (listenedEventName) => {
114
+ const { resource, params } = parseEventName(listenedEventName, baseApiEventsFilter);
115
+ if (resource !== 'orders') {
116
+ if (isOrdersOnly) {
117
+ return;
118
+ }
119
+ if (lastNonOrdersTimestamp) {
120
+ params['timestamp>'] = new Date(lastNonOrdersTimestamp).toISOString();
121
+ }
122
+ }
123
+ let { data: { result } } = await api.get(`events/${resource}`, {
124
+ params,
125
+ });
126
+ /*
128
127
  global.api_events_middleware = async (
129
128
  resource: string,
130
129
  result: EventsResult,
@@ -135,45 +134,45 @@ export default async () => {
135
134
  return result;
136
135
  };
137
136
  */
138
- const middleware = global.api_events_middleware;
139
- if (typeof middleware === 'function') {
140
- result = await middleware(resource, result);
141
- }
142
- const resourceIdsRead = [];
143
- result.forEach(async (apiEvent) => {
144
- const resourceId = apiEvent.resource_id;
145
- if (resourceIdsRead.includes(resourceId)) {
146
- return;
147
- }
148
- resourceIdsRead.push(resourceId);
149
- const apiDoc = resource !== 'applications'
150
- ? (await api.get(`${resource}/${resourceId}`)).data
151
- : null;
152
- activeApps.forEach((app) => {
153
- const appConfig = subscribersApps.find(({ appId }) => appId === app.app_id);
154
- if (appConfig?.events.includes(listenedEventName)) {
155
- const topicName = GET_PUBSUB_TOPIC(app.app_id);
156
- const json = {
157
- evName: listenedEventName,
158
- apiEvent,
159
- apiDoc: apiDoc || app,
160
- app,
161
- };
162
- const messageObj = {
163
- messageId: `${resourceId}_${apiEvent.timestamp}`,
164
- json,
165
- };
166
- tryPubSubPublish(topicName, messageObj);
137
+ const middleware = global.api_events_middleware;
138
+ if (typeof middleware === 'function') {
139
+ result = await middleware(resource, result);
167
140
  }
168
- });
141
+ const resourceIdsRead = [];
142
+ result.forEach(async (apiEvent) => {
143
+ const resourceId = apiEvent.resource_id;
144
+ if (resourceIdsRead.includes(resourceId)) {
145
+ return;
146
+ }
147
+ resourceIdsRead.push(resourceId);
148
+ const apiDoc = resource !== 'applications'
149
+ ? (await api.get(`${resource}/${resourceId}`)).data
150
+ : null;
151
+ activeApps.forEach((app) => {
152
+ const appConfig = subscribersApps.find(({ appId }) => appId === app.app_id);
153
+ if (appConfig?.events.includes(listenedEventName)) {
154
+ const topicName = GET_PUBSUB_TOPIC(app.app_id);
155
+ const json = {
156
+ evName: listenedEventName,
157
+ apiEvent,
158
+ apiDoc: apiDoc || app,
159
+ app,
160
+ };
161
+ const messageObj = {
162
+ messageId: `${resourceId}_${apiEvent.timestamp}`,
163
+ json,
164
+ };
165
+ tryPubSubPublish(topicName, messageObj);
166
+ }
167
+ });
168
+ });
169
+ logger.info(`> '${listenedEventName}' events: `, result);
170
+ });
171
+ return documentRef.set({
172
+ timestamp,
173
+ nonOrdersTimestamp: isOrdersOnly ? lastNonOrdersTimestamp : timestamp,
174
+ activeApps,
175
+ listenedEvents,
169
176
  });
170
- logger.info(`> '${listenedEventName}' events: `, result);
171
- });
172
- return documentRef.set({
173
- timestamp,
174
- nonOrdersTimestamp: isOrdersOnly ? lastNonOrdersTimestamp : timestamp,
175
- activeApps,
176
- listenedEvents,
177
- });
178
177
  };
179
- // # sourceMappingURL=check-store-events.js.map
178
+ //# sourceMappingURL=check-store-events.js.map
@@ -1,32 +1,30 @@
1
1
  import functions from 'firebase-functions';
2
2
  import config from '../config.js';
3
3
  import { GET_PUBSUB_TOPIC } from '../const.js';
4
-
5
4
  const { logger } = functions;
6
5
  /* eslint-enable no-unused-vars */
7
6
  const createPubSubFunction = (pubSubTopic, fn, eventMaxAgeMs = 60000) => {
8
- const { httpsFunctionOptions: { region } } = config.get();
9
- return functions.region(region)
10
- .runWith({ failurePolicy: true })
11
- .pubsub.topic(pubSubTopic).onPublish((message, context) => {
12
- const eventAgeMs = Date.now() - Date.parse(context.timestamp);
13
- if (eventAgeMs > eventMaxAgeMs) {
14
- logger.warn(`Dropping event ${context.eventId} with age[ms]: ${eventAgeMs}`);
15
- }
16
- fn(message.json, context, message);
7
+ const { httpsFunctionOptions: { region } } = config.get();
8
+ return functions.region(region)
9
+ .runWith({ failurePolicy: true })
10
+ .pubsub.topic(pubSubTopic).onPublish((message, context) => {
11
+ const eventAgeMs = Date.now() - Date.parse(context.timestamp);
12
+ if (eventAgeMs > eventMaxAgeMs) {
13
+ logger.warn(`Dropping event ${context.eventId} with age[ms]: ${eventAgeMs}`);
14
+ }
15
+ fn(message.json, context, message);
17
16
  });
18
17
  };
19
18
  const createAppEventsFunction = (appNameOrId, fn, eventMaxAgeMs = 60000) => {
20
- let appId;
21
- if (typeof appNameOrId === 'string') {
22
- appId = config.get().apps[appNameOrId].appId;
23
- } else {
24
- appId = appNameOrId;
25
- }
26
- return createPubSubFunction(GET_PUBSUB_TOPIC(appId), fn, eventMaxAgeMs);
19
+ let appId;
20
+ if (typeof appNameOrId === 'string') {
21
+ appId = config.get().apps[appNameOrId].appId;
22
+ }
23
+ else {
24
+ appId = appNameOrId;
25
+ }
26
+ return createPubSubFunction(GET_PUBSUB_TOPIC(appId), fn, eventMaxAgeMs);
27
27
  };
28
-
29
28
  export default createPubSubFunction;
30
-
31
29
  export { createPubSubFunction, createAppEventsFunction };
32
- // # sourceMappingURL=pubsub.js.map
30
+ //# sourceMappingURL=pubsub.js.map