cloudcommerce 0.0.97 → 0.0.99

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 (85) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/package.json +1 -1
  3. package/packages/api/package.json +1 -1
  4. package/packages/apps/correios/package.json +1 -1
  5. package/packages/apps/custom-shipping/package.json +1 -1
  6. package/packages/apps/discounts/package.json +1 -1
  7. package/packages/apps/frenet/package.json +1 -1
  8. package/packages/apps/tiny-erp/package.json +1 -1
  9. package/packages/cli/package.json +1 -1
  10. package/packages/config/package.json +1 -1
  11. package/packages/events/package.json +1 -1
  12. package/packages/firebase/lib/config.js +27 -25
  13. package/packages/firebase/lib/const.js +3 -2
  14. package/packages/firebase/lib/env.js +2 -1
  15. package/packages/firebase/lib/handlers/check-store-events.js +146 -145
  16. package/packages/firebase/lib/helpers/pubsub.js +20 -18
  17. package/packages/firebase/lib/helpers/update-app-data.js +38 -38
  18. package/packages/firebase/lib/index.js +9 -7
  19. package/packages/firebase/lib/init.js +2 -1
  20. package/packages/firebase/package.json +1 -1
  21. package/packages/modules/package.json +1 -1
  22. package/packages/passport/package.json +1 -1
  23. package/packages/ssr/package.json +1 -1
  24. package/packages/storefront/astro.config.mjs +1 -1
  25. package/packages/storefront/dist/client/LoginOffcanvas.c2faa1dc.js +1 -0
  26. package/packages/storefront/dist/client/admin/config.json +1 -0
  27. package/packages/storefront/dist/client/assets/_...522e6bf2.css +4 -0
  28. package/packages/storefront/dist/client/assets/_...a48b75c7.css +1 -0
  29. package/packages/storefront/dist/client/assets/cms-preview.css +274 -0
  30. package/packages/storefront/dist/client/assets/cms.css +114 -0
  31. package/packages/storefront/dist/client/assets/cvv.png +0 -0
  32. package/packages/storefront/dist/client/assets/icons/bootstrap-icons/font/storefront-icons.woff2 +0 -0
  33. package/packages/storefront/dist/client/assets/icons/feather-icons/font/storefront-icons.woff2 +0 -0
  34. package/packages/storefront/dist/client/assets/icons/font-awesome/font/storefront-icons.woff2 +0 -0
  35. package/packages/storefront/dist/client/assets/icons/line-awesome/font/storefront-icons.woff2 +0 -0
  36. package/packages/storefront/dist/client/assets/icons/tabler-icons/font/storefront-icons.woff2 +0 -0
  37. package/packages/storefront/dist/client/assets/img-placeholder.png +0 -0
  38. package/packages/storefront/dist/client/assets/payments.png +0 -0
  39. package/packages/storefront/dist/client/assets/ssl-safe.png +0 -0
  40. package/packages/storefront/dist/client/chunks/LoginForm.3bcb85fb.js +1066 -0
  41. package/packages/storefront/dist/client/chunks/LoginOffcanvas.e48f274b.js +1 -0
  42. package/packages/storefront/dist/client/chunks/index.esm.84a649c7.js +331 -0
  43. package/packages/storefront/dist/client/chunks/preload-helper.f15ab524.js +1 -0
  44. package/packages/storefront/dist/client/chunks/runtime-dom.esm-bundler.738639ee.js +1 -0
  45. package/packages/storefront/dist/client/chunks/workbox-window.prod.es5.4b654ae6.js +2 -0
  46. package/packages/storefront/dist/client/client.b552d86a.js +1 -0
  47. package/packages/storefront/dist/client/hoisted.054c36ac.js +1 -0
  48. package/packages/storefront/dist/client/img/icon.png +0 -0
  49. package/packages/storefront/dist/client/img/large-icon.png +0 -0
  50. package/packages/storefront/dist/client/img/uploads/banner1.png +0 -0
  51. package/packages/storefront/dist/client/img/uploads/banner2.png +0 -0
  52. package/packages/storefront/dist/client/img/uploads/banner2.webp +0 -0
  53. package/packages/storefront/dist/client/img/uploads/favicon.png +0 -0
  54. package/packages/storefront/dist/client/img/uploads/headless.png +0 -0
  55. package/packages/storefront/dist/client/img/uploads/headphone.png +0 -0
  56. package/packages/storefront/dist/client/img/uploads/headphone.webp +0 -0
  57. package/packages/storefront/dist/client/img/uploads/icon.png +0 -0
  58. package/packages/storefront/dist/client/img/uploads/large-icon.png +0 -0
  59. package/packages/storefront/dist/client/img/uploads/logo.png +0 -0
  60. package/packages/storefront/dist/client/img/uploads/logo.webp +0 -0
  61. package/packages/storefront/dist/client/img/uploads/og-image.png +0 -0
  62. package/packages/storefront/dist/client/img/uploads/passion.png +0 -0
  63. package/packages/storefront/dist/client/img/uploads/passion.webp +0 -0
  64. package/packages/storefront/dist/client/img/uploads/pwa-reliable.png +0 -0
  65. package/packages/storefront/dist/client/img/uploads/rect8589.png +0 -0
  66. package/packages/storefront/dist/client/img/uploads/rect859.png +0 -0
  67. package/packages/storefront/dist/client/img/uploads/rect89.png +0 -0
  68. package/packages/storefront/dist/client/img/uploads/rect89.webp +0 -0
  69. package/packages/storefront/dist/client/img/uploads/ssl-safe.png +0 -0
  70. package/packages/storefront/dist/client/manifest.webmanifest +1 -0
  71. package/packages/storefront/dist/client/page.3aa82516.js +1 -0
  72. package/packages/storefront/dist/client/robots.txt +8 -0
  73. package/packages/storefront/dist/client/sw.js +1 -0
  74. package/packages/storefront/dist/client/workbox-6f0d1f78.js +1 -0
  75. package/packages/storefront/dist/client/~partytown/partytown-atomics.js +2 -0
  76. package/packages/storefront/dist/client/~partytown/partytown-media.js +2 -0
  77. package/packages/storefront/dist/client/~partytown/partytown-sw.js +2 -0
  78. package/packages/storefront/dist/client/~partytown/partytown.js +2 -0
  79. package/packages/storefront/dist/server/entry.mjs +2852 -0
  80. package/packages/storefront/dist/server/manifest.webmanifest +1 -0
  81. package/packages/storefront/dist/server/registerSW.js +1 -0
  82. package/packages/storefront/package.json +2 -2
  83. package/packages/storefront/src/lib/layouts/PagesHeader.astro +2 -1
  84. package/packages/storefront/tsconfig.json +1 -1
  85. package/packages/types/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
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.99](https://github.com/ecomplus/cloud-commerce/compare/v0.0.98...v0.0.99) (2022-09-27)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * **storefront:** Bump `@ecomplus/i18n` and fix alias to .mjs ([fa33b44](https://github.com/ecomplus/cloud-commerce/commit/fa33b44ffa63d48f3de075d44cf09d9e4066f9fe))
11
+
12
+ ### [0.0.98](https://github.com/ecomplus/cloud-commerce/compare/v0.0.97...v0.0.98) (2022-09-27)
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * **storefront:** Fix handling `loginOffcanvasProps` from Astro component ([1897907](https://github.com/ecomplus/cloud-commerce/commit/1897907ecb948b476ffbd8d3916e8a452f541421))
18
+
5
19
  ### [0.0.97](https://github.com/ecomplus/cloud-commerce/compare/v0.0.96...v0.0.97) (2022-09-27)
6
20
 
7
21
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "cloudcommerce",
3
3
  "type": "module",
4
- "version": "0.0.97",
4
+ "version": "0.0.99",
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,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/api",
3
3
  "type": "module",
4
- "version": "0.0.97",
4
+ "version": "0.0.99",
5
5
  "description": "E-Com Plus Cloud Commerce APIs client/adapter",
6
6
  "main": "lib/api.js",
7
7
  "types": "lib/api.d.ts",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-correios",
3
3
  "type": "module",
4
- "version": "0.0.97",
4
+ "version": "0.0.99",
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.97",
4
+ "version": "0.0.99",
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.97",
4
+ "version": "0.0.99",
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.97",
4
+ "version": "0.0.99",
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.97",
4
+ "version": "0.0.99",
5
5
  "description": "E-Com Plus Cloud Commerce app for Tiny ERP",
6
6
  "main": "lib/tiny-erp.js",
7
7
  "repository": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/cli",
3
3
  "type": "module",
4
- "version": "0.0.97",
4
+ "version": "0.0.99",
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.97",
4
+ "version": "0.0.99",
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.97",
4
+ "version": "0.0.99",
5
5
  "description": "E-Com Plus Cloud Commerce app events",
6
6
  "main": "lib/index.js",
7
7
  "exports": {
@@ -1,34 +1,36 @@
1
1
  import config from '@cloudcommerce/config';
2
+
2
3
  const tinyErpEvents = [
3
- 'orders-anyStatusSet',
4
- 'products-new',
5
- 'products-priceSet',
6
- 'applications-dataSet',
4
+ 'orders-anyStatusSet',
5
+ 'products-new',
6
+ 'products-priceSet',
7
+ 'applications-dataSet',
7
8
  ];
8
9
  const mergeConfig = {
9
- hello: 'from @cloudcommerce/firebase',
10
- httpsFunctionOptions: {
11
- region: process.env.DEPLOY_REGION || 'southamerica-east1',
10
+ hello: 'from @cloudcommerce/firebase',
11
+ httpsFunctionOptions: {
12
+ region: process.env.DEPLOY_REGION || 'southamerica-east1',
13
+ },
14
+ apps: {
15
+ discounts: {
16
+ appId: 1252,
12
17
  },
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
- },
18
+ correios: {
19
+ appId: 1248,
30
20
  },
21
+ customShipping: {
22
+ appId: 1253,
23
+ },
24
+ frenet: {
25
+ appId: 1244,
26
+ },
27
+ tinyErp: {
28
+ appId: 105922,
29
+ events: tinyErpEvents,
30
+ },
31
+ },
31
32
  };
32
33
  config.set(mergeConfig);
34
+
33
35
  export default config;
34
- //# sourceMappingURL=config.js.map
36
+ // # sourceMappingURL=config.js.map
@@ -1,5 +1,6 @@
1
1
  export const EVENT_SKIP_FLAG = '_skip';
2
+
2
3
  export const GET_PUBSUB_TOPIC = (appId) => {
3
- return `app${appId}_api_events`;
4
+ return `app${appId}_api_events`;
4
5
  };
5
- //# sourceMappingURL=const.js.map
6
+ // # sourceMappingURL=const.js.map
@@ -1,3 +1,4 @@
1
1
  import getEnv from '@cloudcommerce/config/lib/env';
2
+
2
3
  export default getEnv;
3
- //# sourceMappingURL=env.js.map
4
+ // # sourceMappingURL=env.js.map
@@ -5,125 +5,126 @@ 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
+
8
9
  const parseEventName = (evName, baseApiEventsFilter) => {
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:
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
+ ];
52
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:
53
52
  }
54
- Object.keys(bodySet).forEach((field) => {
55
- params[`body.${field}`] = bodySet[field];
56
- });
57
- return { resource, params };
53
+ }
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
+
73
74
  export default async () => {
74
- const timestamp = Date.now();
75
- const documentRef = getFirestore().doc('storeEvents/last');
76
- const documentSnapshot = await documentRef.get();
77
- const lastRunTimestamp = documentSnapshot.get('timestamp')
75
+ const timestamp = Date.now();
76
+ const documentRef = getFirestore().doc('storeEvents/last');
77
+ const documentSnapshot = await documentRef.get();
78
+ const lastRunTimestamp = documentSnapshot.get('timestamp')
78
79
  || Date.now() - 1000 * 60 * 5;
79
- const lastNonOrdersTimestamp = documentSnapshot.get('nonOrdersTimestamp')
80
+ const lastNonOrdersTimestamp = documentSnapshot.get('nonOrdersTimestamp')
80
81
  || 0;
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);
92
- }
93
- });
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
- });
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);
109
108
  }
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,
110
126
  });
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
- /*
127
+ /*
127
128
  global.api_events_middleware = async (
128
129
  resource: string,
129
130
  result: EventsResult,
@@ -134,45 +135,45 @@ export default async () => {
134
135
  return result;
135
136
  };
136
137
  */
137
- const middleware = global.api_events_middleware;
138
- if (typeof middleware === 'function') {
139
- result = await middleware(resource, result);
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);
140
167
  }
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,
168
+ });
176
169
  });
170
+ logger.info(`> '${listenedEventName}' events: `, result);
171
+ });
172
+ return documentRef.set({
173
+ timestamp,
174
+ nonOrdersTimestamp: isOrdersOnly ? lastNonOrdersTimestamp : timestamp,
175
+ activeApps,
176
+ listenedEvents,
177
+ });
177
178
  };
178
- //# sourceMappingURL=check-store-events.js.map
179
+ // # sourceMappingURL=check-store-events.js.map
@@ -1,30 +1,32 @@
1
1
  import functions from 'firebase-functions';
2
2
  import config from '../config.js';
3
3
  import { GET_PUBSUB_TOPIC } from '../const.js';
4
+
4
5
  const { logger } = functions;
5
6
  /* eslint-enable no-unused-vars */
6
7
  const createPubSubFunction = (pubSubTopic, fn, eventMaxAgeMs = 60000) => {
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);
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);
16
17
  });
17
18
  };
18
19
  const createAppEventsFunction = (appNameOrId, fn, eventMaxAgeMs = 60000) => {
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);
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);
27
27
  };
28
+
28
29
  export default createPubSubFunction;
30
+
29
31
  export { createPubSubFunction, createAppEventsFunction };
30
- //# sourceMappingURL=pubsub.js.map
32
+ // # sourceMappingURL=pubsub.js.map
@@ -2,44 +2,44 @@ import { PubSub } from '@google-cloud/pubsub';
2
2
  import logger from 'firebase-functions/lib/logger';
3
3
  import api from '@cloudcommerce/api';
4
4
  import { EVENT_SKIP_FLAG, GET_PUBSUB_TOPIC } from '../const.js';
5
+
5
6
  export default async (application, data, { isHiddenData = false, canSendPubSub = true } = {}) => {
6
- const applicationId = typeof application === 'string'
7
- ? application : application._id;
8
- const subresource = isHiddenData ? 'hidden_data' : 'data';
9
- if (application && typeof application === 'object' && canSendPubSub) {
10
- // eslint-disable-next-line no-param-reassign
11
- application[subresource] = data;
12
- const json = {
13
- evName: 'applications-dataSet',
14
- apiEvent: {
15
- timestamp: new Date().toISOString(),
16
- resource_id: applicationId,
17
- action: 'update',
18
- modified_fields: [subresource],
19
- authentication_id: null,
20
- },
21
- apiDoc: application,
22
- app: {
23
- _id: applicationId,
24
- app_id: application.app_id,
25
- data: application.data,
26
- hidden_data: application.hidden_data,
27
- },
28
- isInternal: true,
29
- };
30
- try {
31
- await new PubSub()
32
- .topic(GET_PUBSUB_TOPIC(application.app_id))
33
- .publishMessage({ json });
34
- }
35
- catch (err) {
36
- logger.error(err);
37
- }
7
+ const applicationId = typeof application === 'string'
8
+ ? application : application._id;
9
+ const subresource = isHiddenData ? 'hidden_data' : 'data';
10
+ if (application && typeof application === 'object' && canSendPubSub) {
11
+ // eslint-disable-next-line no-param-reassign
12
+ application[subresource] = data;
13
+ const json = {
14
+ evName: 'applications-dataSet',
15
+ apiEvent: {
16
+ timestamp: new Date().toISOString(),
17
+ resource_id: applicationId,
18
+ action: 'update',
19
+ modified_fields: [subresource],
20
+ authentication_id: null,
21
+ },
22
+ apiDoc: application,
23
+ app: {
24
+ _id: applicationId,
25
+ app_id: application.app_id,
26
+ data: application.data,
27
+ hidden_data: application.hidden_data,
28
+ },
29
+ isInternal: true,
30
+ };
31
+ try {
32
+ await new PubSub()
33
+ .topic(GET_PUBSUB_TOPIC(application.app_id))
34
+ .publishMessage({ json });
35
+ } catch (err) {
36
+ logger.error(err);
38
37
  }
39
- return api.patch(`applications/${applicationId}/${subresource}`, data, {
40
- headers: {
41
- 'X-Event-Flag': EVENT_SKIP_FLAG,
42
- },
43
- });
38
+ }
39
+ return api.patch(`applications/${applicationId}/${subresource}`, data, {
40
+ headers: {
41
+ 'X-Event-Flag': EVENT_SKIP_FLAG,
42
+ },
43
+ });
44
44
  };
45
- //# sourceMappingURL=update-app-data.js.map
45
+ // # sourceMappingURL=update-app-data.js.map