cloudcommerce 0.0.97 → 0.0.98

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 (114) hide show
  1. package/CHANGELOG.md +7 -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/lib/event-to-tiny.js +94 -94
  9. package/packages/apps/tiny-erp/lib/index.js +1 -1
  10. package/packages/apps/tiny-erp/lib/integration/after-tiny-queue.js +74 -71
  11. package/packages/apps/tiny-erp/lib/integration/export-order-to-tiny.js +73 -70
  12. package/packages/apps/tiny-erp/lib/integration/export-product-to-tiny.js +53 -49
  13. package/packages/apps/tiny-erp/lib/integration/helpers/format-tiny-date.js +3 -3
  14. package/packages/apps/tiny-erp/lib/integration/import-order-from-tiny.js +75 -76
  15. package/packages/apps/tiny-erp/lib/integration/import-product-from-tiny.js +140 -137
  16. package/packages/apps/tiny-erp/lib/integration/parsers/order-from-tiny.js +39 -40
  17. package/packages/apps/tiny-erp/lib/integration/parsers/order-to-tiny.js +178 -173
  18. package/packages/apps/tiny-erp/lib/integration/parsers/product-from-tiny.js +171 -173
  19. package/packages/apps/tiny-erp/lib/integration/parsers/product-to-tiny.js +127 -123
  20. package/packages/apps/tiny-erp/lib/integration/parsers/status-from-tiny.js +32 -32
  21. package/packages/apps/tiny-erp/lib/integration/parsers/status-to-tiny.js +37 -37
  22. package/packages/apps/tiny-erp/lib/integration/post-tiny-erp.js +43 -42
  23. package/packages/apps/tiny-erp/lib/tiny-erp.js +6 -8
  24. package/packages/apps/tiny-erp/lib/tiny-webhook.js +73 -76
  25. package/packages/apps/tiny-erp/package.json +1 -1
  26. package/packages/cli/package.json +1 -1
  27. package/packages/config/package.json +1 -1
  28. package/packages/events/package.json +1 -1
  29. package/packages/firebase/lib/config.js +27 -25
  30. package/packages/firebase/lib/const.js +3 -2
  31. package/packages/firebase/lib/env.js +2 -1
  32. package/packages/firebase/lib/handlers/check-store-events.js +146 -145
  33. package/packages/firebase/lib/helpers/pubsub.js +20 -18
  34. package/packages/firebase/lib/helpers/update-app-data.js +38 -38
  35. package/packages/firebase/lib/index.js +9 -7
  36. package/packages/firebase/lib/init.js +2 -1
  37. package/packages/firebase/package.json +1 -1
  38. package/packages/modules/lib/firebase/ajv.js +19 -24
  39. package/packages/modules/lib/firebase/call-app-module.js +116 -110
  40. package/packages/modules/lib/firebase/checkout.js +151 -152
  41. package/packages/modules/lib/firebase/functions-checkout/fix-items.js +194 -187
  42. package/packages/modules/lib/firebase/functions-checkout/get-custumerId.js +25 -26
  43. package/packages/modules/lib/firebase/functions-checkout/handle-order-transaction.js +110 -109
  44. package/packages/modules/lib/firebase/functions-checkout/new-order.js +177 -177
  45. package/packages/modules/lib/firebase/functions-checkout/request-to-module.js +59 -59
  46. package/packages/modules/lib/firebase/functions-checkout/utils.js +195 -197
  47. package/packages/modules/lib/firebase/handle-module.js +144 -146
  48. package/packages/modules/lib/firebase/proxy-apps.js +2 -1
  49. package/packages/modules/lib/firebase/serve-modules-api.js +52 -53
  50. package/packages/modules/lib/firebase.js +4 -6
  51. package/packages/modules/lib/index.js +12 -15
  52. package/packages/modules/package.json +1 -1
  53. package/packages/passport/package.json +1 -1
  54. package/packages/ssr/package.json +1 -1
  55. package/packages/storefront/dist/client/LoginOffcanvas.daf3f717.js +1 -0
  56. package/packages/storefront/dist/client/admin/config.json +1 -0
  57. package/packages/storefront/dist/client/assets/_...522e6bf2.css +4 -0
  58. package/packages/storefront/dist/client/assets/_...a48b75c7.css +1 -0
  59. package/packages/storefront/dist/client/assets/cms-preview.css +274 -0
  60. package/packages/storefront/dist/client/assets/cms.css +114 -0
  61. package/packages/storefront/dist/client/assets/cvv.png +0 -0
  62. package/packages/storefront/dist/client/assets/icons/bootstrap-icons/font/storefront-icons.woff2 +0 -0
  63. package/packages/storefront/dist/client/assets/icons/feather-icons/font/storefront-icons.woff2 +0 -0
  64. package/packages/storefront/dist/client/assets/icons/font-awesome/font/storefront-icons.woff2 +0 -0
  65. package/packages/storefront/dist/client/assets/icons/line-awesome/font/storefront-icons.woff2 +0 -0
  66. package/packages/storefront/dist/client/assets/icons/tabler-icons/font/storefront-icons.woff2 +0 -0
  67. package/packages/storefront/dist/client/assets/img-placeholder.png +0 -0
  68. package/packages/storefront/dist/client/assets/payments.png +0 -0
  69. package/packages/storefront/dist/client/assets/ssl-safe.png +0 -0
  70. package/packages/storefront/dist/client/chunks/LoginForm.d9251274.js +1066 -0
  71. package/packages/storefront/dist/client/chunks/LoginOffcanvas.07fe6492.js +1 -0
  72. package/packages/storefront/dist/client/chunks/index.esm.84a649c7.js +331 -0
  73. package/packages/storefront/dist/client/chunks/preload-helper.f15ab524.js +1 -0
  74. package/packages/storefront/dist/client/chunks/runtime-dom.esm-bundler.738639ee.js +1 -0
  75. package/packages/storefront/dist/client/chunks/workbox-window.prod.es5.4b654ae6.js +2 -0
  76. package/packages/storefront/dist/client/client.b552d86a.js +1 -0
  77. package/packages/storefront/dist/client/hoisted.054c36ac.js +1 -0
  78. package/packages/storefront/dist/client/img/icon.png +0 -0
  79. package/packages/storefront/dist/client/img/large-icon.png +0 -0
  80. package/packages/storefront/dist/client/img/uploads/banner1.png +0 -0
  81. package/packages/storefront/dist/client/img/uploads/banner2.png +0 -0
  82. package/packages/storefront/dist/client/img/uploads/banner2.webp +0 -0
  83. package/packages/storefront/dist/client/img/uploads/favicon.png +0 -0
  84. package/packages/storefront/dist/client/img/uploads/headless.png +0 -0
  85. package/packages/storefront/dist/client/img/uploads/headphone.png +0 -0
  86. package/packages/storefront/dist/client/img/uploads/headphone.webp +0 -0
  87. package/packages/storefront/dist/client/img/uploads/icon.png +0 -0
  88. package/packages/storefront/dist/client/img/uploads/large-icon.png +0 -0
  89. package/packages/storefront/dist/client/img/uploads/logo.png +0 -0
  90. package/packages/storefront/dist/client/img/uploads/logo.webp +0 -0
  91. package/packages/storefront/dist/client/img/uploads/og-image.png +0 -0
  92. package/packages/storefront/dist/client/img/uploads/passion.png +0 -0
  93. package/packages/storefront/dist/client/img/uploads/passion.webp +0 -0
  94. package/packages/storefront/dist/client/img/uploads/pwa-reliable.png +0 -0
  95. package/packages/storefront/dist/client/img/uploads/rect8589.png +0 -0
  96. package/packages/storefront/dist/client/img/uploads/rect859.png +0 -0
  97. package/packages/storefront/dist/client/img/uploads/rect89.png +0 -0
  98. package/packages/storefront/dist/client/img/uploads/rect89.webp +0 -0
  99. package/packages/storefront/dist/client/img/uploads/ssl-safe.png +0 -0
  100. package/packages/storefront/dist/client/manifest.webmanifest +1 -0
  101. package/packages/storefront/dist/client/page.3aa82516.js +1 -0
  102. package/packages/storefront/dist/client/robots.txt +8 -0
  103. package/packages/storefront/dist/client/sw.js +1 -0
  104. package/packages/storefront/dist/client/workbox-6f0d1f78.js +1 -0
  105. package/packages/storefront/dist/client/~partytown/partytown-atomics.js +2 -0
  106. package/packages/storefront/dist/client/~partytown/partytown-media.js +2 -0
  107. package/packages/storefront/dist/client/~partytown/partytown-sw.js +2 -0
  108. package/packages/storefront/dist/client/~partytown/partytown.js +2 -0
  109. package/packages/storefront/dist/server/entry.mjs +2852 -0
  110. package/packages/storefront/dist/server/manifest.webmanifest +1 -0
  111. package/packages/storefront/dist/server/registerSW.js +1 -0
  112. package/packages/storefront/package.json +1 -1
  113. package/packages/storefront/src/lib/layouts/PagesHeader.astro +2 -1
  114. package/packages/types/package.json +1 -1
@@ -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
@@ -3,16 +3,18 @@ import './init.js';
3
3
  import functions from 'firebase-functions';
4
4
  import config from './config.js';
5
5
  import checkStoreEvents from './handlers/check-store-events.js';
6
+
6
7
  const { httpsFunctionOptions: { region } } = config.get();
7
8
  const functionBuilder = functions
8
- .region(region)
9
- .runWith({
9
+ .region(region)
10
+ .runWith({
10
11
  timeoutSeconds: 300,
11
12
  memory: '128MB',
12
- });
13
+ });
14
+
13
15
  export const cronStoreEvents = functionBuilder.pubsub
14
- .schedule('* * * * *')
15
- .onRun(() => {
16
+ .schedule('* * * * *')
17
+ .onRun(() => {
16
18
  return checkStoreEvents();
17
- });
18
- //# sourceMappingURL=index.js.map
19
+ });
20
+ // # sourceMappingURL=index.js.map
@@ -4,5 +4,6 @@ import '@cloudcommerce/api/fetch-polyfill';
4
4
  // https://github.com/import-js/eslint-plugin-import/issues/1810
5
5
  // eslint-disable-next-line import/no-unresolved
6
6
  import { initializeApp } from 'firebase-admin/app';
7
+
7
8
  initializeApp();
8
- //# sourceMappingURL=init.js.map
9
+ // # sourceMappingURL=init.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/firebase",
3
3
  "type": "module",
4
- "version": "0.0.97",
4
+ "version": "0.0.98",
5
5
  "description": "E-Com Plus Cloud Commerce on Firebase",
6
6
  "main": "lib/index.js",
7
7
  "types": "lib/index.d.ts",
@@ -1,34 +1,29 @@
1
1
  import Ajv from 'ajv';
2
2
  import addFormats from 'ajv-formats';
3
-
4
3
  const ajvOptions = {
5
- coerceTypes: false,
6
- useDefaults: true,
7
- removeAdditional: true,
8
- // Explicitly set `allErrors` to false, when set to true a DoS attack is possible
9
- allErrors: false,
10
- multipleOfPrecision: 5,
11
- allowMatchingProperties: true,
4
+ coerceTypes: false,
5
+ useDefaults: true,
6
+ removeAdditional: true,
7
+ // Explicitly set `allErrors` to false, when set to true a DoS attack is possible
8
+ allErrors: false,
9
+ multipleOfPrecision: 5,
10
+ allowMatchingProperties: true,
12
11
  };
13
12
  const ajv = addFormats(new Ajv(ajvOptions));
14
13
  const parseAjvErrors = (errors, ajvInstance = ajv) => {
15
- return ajvInstance.errorsText(errors, { separator: '\n' });
14
+ return ajvInstance.errorsText(errors, { separator: '\n' });
16
15
  };
17
16
  const sendRequestError = (res, modName, errors) => {
18
- res.status(400).send({
19
- status: 400,
20
- error_code: 'MOD901',
21
- message: 'Bad-formatted JSON body (POST) or URL params (GET), details in `user_message`',
22
- user_message: {
23
- en_us: ajv.errorsText(errors, { separator: '\n' }),
24
- },
25
- more_info: `/${modName}/schema`,
26
- });
17
+ res.status(400).send({
18
+ status: 400,
19
+ error_code: 'MOD901',
20
+ message: 'Bad-formatted JSON body (POST) or URL params (GET), details in `user_message`',
21
+ user_message: {
22
+ en_us: ajv.errorsText(errors, { separator: '\n' }),
23
+ },
24
+ more_info: `/${modName}/schema`,
25
+ });
27
26
  };
28
-
29
27
  export default ajv;
30
-
31
- export {
32
- ajv, ajvOptions, parseAjvErrors, sendRequestError,
33
- };
34
- // # sourceMappingURL=ajv.js.map
28
+ export { ajv, ajvOptions, parseAjvErrors, sendRequestError, };
29
+ //# sourceMappingURL=ajv.js.map