cloudcommerce 0.0.98 → 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 (55) 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 +71 -74
  11. package/packages/apps/tiny-erp/lib/integration/export-order-to-tiny.js +70 -73
  12. package/packages/apps/tiny-erp/lib/integration/export-product-to-tiny.js +49 -53
  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 +76 -75
  15. package/packages/apps/tiny-erp/lib/integration/import-product-from-tiny.js +137 -140
  16. package/packages/apps/tiny-erp/lib/integration/parsers/order-from-tiny.js +40 -39
  17. package/packages/apps/tiny-erp/lib/integration/parsers/order-to-tiny.js +173 -178
  18. package/packages/apps/tiny-erp/lib/integration/parsers/product-from-tiny.js +173 -171
  19. package/packages/apps/tiny-erp/lib/integration/parsers/product-to-tiny.js +123 -127
  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 +42 -43
  23. package/packages/apps/tiny-erp/lib/tiny-erp.js +8 -6
  24. package/packages/apps/tiny-erp/lib/tiny-webhook.js +76 -73
  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/package.json +1 -1
  30. package/packages/modules/lib/firebase/ajv.js +24 -19
  31. package/packages/modules/lib/firebase/call-app-module.js +110 -116
  32. package/packages/modules/lib/firebase/checkout.js +152 -151
  33. package/packages/modules/lib/firebase/functions-checkout/fix-items.js +187 -194
  34. package/packages/modules/lib/firebase/functions-checkout/get-custumerId.js +26 -25
  35. package/packages/modules/lib/firebase/functions-checkout/handle-order-transaction.js +109 -110
  36. package/packages/modules/lib/firebase/functions-checkout/new-order.js +177 -177
  37. package/packages/modules/lib/firebase/functions-checkout/request-to-module.js +59 -59
  38. package/packages/modules/lib/firebase/functions-checkout/utils.js +197 -195
  39. package/packages/modules/lib/firebase/handle-module.js +146 -144
  40. package/packages/modules/lib/firebase/proxy-apps.js +1 -2
  41. package/packages/modules/lib/firebase/serve-modules-api.js +53 -52
  42. package/packages/modules/lib/firebase.js +6 -4
  43. package/packages/modules/lib/index.js +15 -12
  44. package/packages/modules/package.json +1 -1
  45. package/packages/passport/package.json +1 -1
  46. package/packages/ssr/package.json +1 -1
  47. package/packages/storefront/astro.config.mjs +1 -1
  48. package/packages/storefront/dist/client/{LoginOffcanvas.daf3f717.js → LoginOffcanvas.c2faa1dc.js} +1 -1
  49. package/packages/storefront/dist/client/chunks/{LoginForm.d9251274.js → LoginForm.3bcb85fb.js} +10 -10
  50. package/packages/storefront/dist/client/chunks/{LoginOffcanvas.07fe6492.js → LoginOffcanvas.e48f274b.js} +1 -1
  51. package/packages/storefront/dist/client/sw.js +1 -1
  52. package/packages/storefront/dist/server/entry.mjs +2 -2
  53. package/packages/storefront/package.json +2 -2
  54. package/packages/storefront/tsconfig.json +1 -1
  55. package/packages/types/package.json +1 -1
@@ -3,165 +3,167 @@ import Ajv from 'ajv';
3
3
  import addFormats from 'ajv-formats';
4
4
  import api from '@cloudcommerce/api';
5
5
  import config from '@cloudcommerce/firebase/lib/config';
6
- import { ajv, ajvOptions, parseAjvErrors, sendRequestError, } from './ajv.js';
6
+ import {
7
+ ajv, ajvOptions, parseAjvErrors, sendRequestError,
8
+ } from './ajv.js';
7
9
  import callAppModule from './call-app-module.js';
10
+
8
11
  const ajvAppsResponse = addFormats(new Ajv({ ...ajvOptions, allErrors: true }));
9
12
  // Cache apps list and no params modules results
10
13
  const appsCache = {};
11
14
  const resultsCache = {};
12
15
  async function runModule(params, res, modName, validate, responseValidate, appId) {
13
- const respond = (result) => res.send({
14
- result,
15
- meta: params,
16
- });
17
- const { storeId } = config.get();
18
- const isEmptyParams = (!params || !Object.keys(params).length);
19
- if (!validate(params)) {
20
- return sendRequestError(res, modName, validate.errors);
21
- }
22
- let canCache = true;
23
- const cacheKey = `${storeId}:${modName}`;
24
- const listAppsParams = {
25
- state: 'active',
26
- [`modules.${modName}.enabled`]: true,
27
- fields: `_id,app_id,version,data,hidden_data,modules.${modName}`,
28
- };
29
- if (appId
16
+ const respond = (result) => res.send({
17
+ result,
18
+ meta: params,
19
+ });
20
+ const { storeId } = config.get();
21
+ const isEmptyParams = (!params || !Object.keys(params).length);
22
+ if (!validate(params)) {
23
+ return sendRequestError(res, modName, validate.errors);
24
+ }
25
+ let canCache = true;
26
+ const cacheKey = `${storeId}:${modName}`;
27
+ const listAppsParams = {
28
+ state: 'active',
29
+ [`modules.${modName}.enabled`]: true,
30
+ fields: `_id,app_id,version,data,hidden_data,modules.${modName}`,
31
+ };
32
+ if (appId
30
33
  && (typeof appId === 'number' || (typeof appId === 'string' && /^\d+$/.test(appId)))) {
31
- if (typeof appId === 'string') {
32
- appId = parseInt(appId, 10);
33
- }
34
- canCache = false;
35
- listAppsParams.app_id = appId;
36
- listAppsParams.limit = 1;
34
+ if (typeof appId === 'string') {
35
+ appId = parseInt(appId, 10);
37
36
  }
38
- let canCacheResults = false;
39
- if (canCache && isEmptyParams) {
40
- if (resultsCache[cacheKey]) {
41
- return respond(resultsCache[cacheKey]);
42
- }
43
- canCacheResults = true;
37
+ canCache = false;
38
+ listAppsParams.app_id = appId;
39
+ listAppsParams.limit = 1;
40
+ }
41
+ let canCacheResults = false;
42
+ if (canCache && isEmptyParams) {
43
+ if (resultsCache[cacheKey]) {
44
+ return respond(resultsCache[cacheKey]);
44
45
  }
45
- let appsList;
46
- if (canCache && appsCache[cacheKey]) {
47
- appsList = appsCache[cacheKey];
46
+ canCacheResults = true;
47
+ }
48
+ let appsList;
49
+ if (canCache && appsCache[cacheKey]) {
50
+ appsList = appsCache[cacheKey];
51
+ } else {
52
+ try {
53
+ const { data } = await api.get('applications', {
54
+ params: listAppsParams,
55
+ });
56
+ appsList = data.result;
57
+ } catch (err) {
58
+ logger.error(err);
59
+ const error = err;
60
+ return res.status(500).send({
61
+ status: 500,
62
+ error_code: 'MOD801',
63
+ message: `Store API returned status ${error.statusCode} trying to list apps`,
64
+ more_info: error.data?.user_message?.en_us,
65
+ });
48
66
  }
49
- else {
50
- try {
51
- const { data } = await api.get('applications', {
52
- params: listAppsParams,
53
- });
54
- appsList = data.result;
55
- }
56
- catch (err) {
57
- logger.error(err);
58
- const error = err;
59
- return res.status(500).send({
60
- status: 500,
61
- error_code: 'MOD801',
62
- message: `Store API returned status ${error.statusCode} trying to list apps`,
63
- more_info: error.data?.user_message?.en_us,
64
- });
65
- }
67
+ }
68
+ if (Array.isArray(appsList)) {
69
+ if (!appsList.length) {
70
+ return respond([]);
66
71
  }
67
- if (Array.isArray(appsList)) {
68
- if (!appsList.length) {
69
- return respond([]);
70
- }
71
- if (canCache && !appsCache[cacheKey]) {
72
- appsCache[cacheKey] = appsList;
73
- setTimeout(() => {
74
- appsCache[cacheKey] = null;
75
- delete appsCache[cacheKey];
76
- }, appsList.length ? 60000 : 3000);
77
- }
78
- const moduleReqs = [];
79
- for (let i = 0; i < appsList.length; i++) {
80
- const application = appsList[i];
81
- if (!application.hidden_data) {
82
- application.hidden_data = {};
83
- }
84
- if (!application.data) {
85
- application.data = {};
72
+ if (canCache && !appsCache[cacheKey]) {
73
+ appsCache[cacheKey] = appsList;
74
+ setTimeout(() => {
75
+ appsCache[cacheKey] = null;
76
+ delete appsCache[cacheKey];
77
+ }, appsList.length ? 60000 : 3000);
78
+ }
79
+ const moduleReqs = [];
80
+ for (let i = 0; i < appsList.length; i++) {
81
+ const application = appsList[i];
82
+ if (!application.hidden_data) {
83
+ application.hidden_data = {};
84
+ }
85
+ if (!application.data) {
86
+ application.data = {};
87
+ }
88
+ const appModuleUrl = application.modules[modName].endpoint;
89
+ // Handle request with big timeout if proxying one app (by ID) only
90
+ const isBigTimeout = !!(appId);
91
+ const appModuleBody = {
92
+ storeId,
93
+ module: modName,
94
+ params,
95
+ application,
96
+ };
97
+ const reqStartTime = Date.now();
98
+ moduleReqs.push(new Promise((resolve) => {
99
+ let response;
100
+ let isError = false;
101
+ let errorMessage = null;
102
+ callAppModule(appId, modName, appModuleUrl, appModuleBody, isBigTimeout)
103
+ .then((appResponse) => {
104
+ response = appResponse;
105
+ if (appResponse?.error) {
106
+ isError = true;
107
+ errorMessage = appResponse.message || String(appResponse.error);
86
108
  }
87
- const appModuleUrl = application.modules[modName].endpoint;
88
- // Handle request with big timeout if proxying one app (by ID) only
89
- const isBigTimeout = !!(appId);
90
- const appModuleBody = {
91
- storeId,
92
- module: modName,
93
- params,
94
- application,
109
+ })
110
+ .catch((err) => {
111
+ response = null;
112
+ isError = true;
113
+ errorMessage = err.message;
114
+ })
115
+ .finally(() => {
116
+ const result = {
117
+ _id: application._id,
118
+ app_id: application.app_id,
119
+ took: Date.now() - reqStartTime,
120
+ version: application.version,
121
+ validated: false,
122
+ response_errors: null,
123
+ error: isError,
124
+ error_message: errorMessage,
125
+ response,
95
126
  };
96
- const reqStartTime = Date.now();
97
- moduleReqs.push(new Promise((resolve) => {
98
- let response;
99
- let isError = false;
100
- let errorMessage = null;
101
- callAppModule(appId, modName, appModuleUrl, appModuleBody, isBigTimeout)
102
- .then((appResponse) => {
103
- response = appResponse;
104
- if (appResponse?.error) {
105
- isError = true;
106
- errorMessage = appResponse.message || String(appResponse.error);
107
- }
108
- })
109
- .catch((err) => {
110
- response = null;
111
- isError = true;
112
- errorMessage = err.message;
113
- })
114
- .finally(() => {
115
- const result = {
116
- _id: application._id,
117
- app_id: application.app_id,
118
- took: Date.now() - reqStartTime,
119
- version: application.version,
120
- validated: false,
121
- response_errors: null,
122
- error: isError,
123
- error_message: errorMessage,
124
- response,
125
- };
126
- if (!isError && typeof response === 'object' && response !== null) {
127
- result.validated = responseValidate(response);
128
- if (!result.validated) {
129
- // @ts-ignore
130
- result.response_errors = parseAjvErrors(responseValidate.errors, ajvAppsResponse);
131
- }
132
- }
133
- resolve(result);
134
- });
135
- }));
136
- }
137
- return Promise.all(moduleReqs).then((results) => {
138
- if (!results.find(({ response }) => response)) {
139
- res.status(409);
140
- canCacheResults = false;
141
- }
142
- if (canCacheResults && !resultsCache[cacheKey]) {
143
- resultsCache[cacheKey] = results;
144
- setTimeout(() => {
145
- resultsCache[cacheKey] = null;
146
- delete resultsCache[cacheKey];
147
- }, 60000);
127
+ if (!isError && typeof response === 'object' && response !== null) {
128
+ result.validated = responseValidate(response);
129
+ if (!result.validated) {
130
+ // @ts-ignore
131
+ result.response_errors = parseAjvErrors(responseValidate.errors, ajvAppsResponse);
132
+ }
148
133
  }
149
- return respond(results);
150
- });
134
+ resolve(result);
135
+ });
136
+ }));
151
137
  }
152
- // Shoud never happen
153
- return res.sendStatus(501);
138
+ return Promise.all(moduleReqs).then((results) => {
139
+ if (!results.find(({ response }) => response)) {
140
+ res.status(409);
141
+ canCacheResults = false;
142
+ }
143
+ if (canCacheResults && !resultsCache[cacheKey]) {
144
+ resultsCache[cacheKey] = results;
145
+ setTimeout(() => {
146
+ resultsCache[cacheKey] = null;
147
+ delete resultsCache[cacheKey];
148
+ }, 60000);
149
+ }
150
+ return respond(results);
151
+ });
152
+ }
153
+ // Shoud never happen
154
+ return res.sendStatus(501);
154
155
  }
156
+
155
157
  export default (modName, schema, responseSchema, req, res) => {
156
- const validate = ajv.compile(schema);
157
- const responseValidate = ajvAppsResponse.compile(responseSchema);
158
- return {
159
- GET() {
160
- runModule(req.query, res, modName, validate, responseValidate);
161
- },
162
- POST() {
163
- runModule(req.body, res, modName, validate, responseValidate, req.query.app_id);
164
- },
165
- };
158
+ const validate = ajv.compile(schema);
159
+ const responseValidate = ajvAppsResponse.compile(responseSchema);
160
+ return {
161
+ GET() {
162
+ runModule(req.query, res, modName, validate, responseValidate);
163
+ },
164
+ POST() {
165
+ runModule(req.body, res, modName, validate, responseValidate, req.query.app_id);
166
+ },
167
+ };
166
168
  };
167
- //# sourceMappingURL=handle-module.js.map
169
+ // # sourceMappingURL=handle-module.js.map
@@ -1,2 +1 @@
1
- "use strict";
2
- //# sourceMappingURL=proxy-apps.js.map
1
+ // # sourceMappingURL=proxy-apps.js.map
@@ -1,62 +1,63 @@
1
1
  import { schemas } from '../index.js';
2
2
  import handleModule from './handle-module.js';
3
3
  import checkout from './checkout.js';
4
+
4
5
  export default (req, res) => {
5
- const { method } = req;
6
- if (method !== 'POST' && method !== 'GET') {
7
- return res.sendStatus(405);
8
- }
9
- if (method === 'POST'
6
+ const { method } = req;
7
+ if (method !== 'POST' && method !== 'GET') {
8
+ return res.sendStatus(405);
9
+ }
10
+ if (method === 'POST'
10
11
  && (!req.body || typeof req.body !== 'object' || Array.isArray(req.body))) {
11
- return res.sendStatus(400);
12
+ return res.sendStatus(400);
13
+ }
14
+ let { url } = req;
15
+ if (url.endsWith('.json')) {
16
+ url = url.slice(0, -5);
17
+ }
18
+ [url] = url.split('?');
19
+ const modName = url.split('/')[1];
20
+ const sendSchema = (isResponseSchema = false) => {
21
+ return res.status(200)
22
+ .setHeader('Cache-Control', 'public, max-age=3600')
23
+ .send(schemas[modName][isResponseSchema ? 'response' : 'params']);
24
+ };
25
+ if (modName === '@checkout') {
26
+ if (url === '/@checkout') {
27
+ if (method === 'GET') {
28
+ return res.status(405)
29
+ .send({
30
+ error_code: 'CKT101',
31
+ message: 'GET is acceptable only to JSON schema, at /@checkout/schema',
32
+ });
33
+ }
34
+ return checkout(schemas[modName].params, req, res, req.hostname);
12
35
  }
13
- let { url } = req;
14
- if (url.endsWith('.json')) {
15
- url = url.slice(0, -5);
36
+ if (url === '/@checkout/schema') {
37
+ return sendSchema();
16
38
  }
17
- [url] = url.split('?');
18
- const modName = url.split('/')[1];
19
- const sendSchema = (isResponseSchema = false) => {
20
- return res.status(200)
21
- .setHeader('Cache-Control', 'public, max-age=3600')
22
- .send(schemas[modName][isResponseSchema ? 'response' : 'params']);
23
- };
24
- if (modName === '@checkout') {
25
- if (url === '/@checkout') {
26
- if (method === 'GET') {
27
- return res.status(405)
28
- .send({
29
- error_code: 'CKT101',
30
- message: 'GET is acceptable only to JSON schema, at /@checkout/schema',
31
- });
32
- }
33
- return checkout(schemas[modName].params, req, res, req.hostname);
34
- }
35
- if (url === '/@checkout/schema') {
36
- return sendSchema();
37
- }
38
- return res.sendStatus(404);
39
+ return res.sendStatus(404);
40
+ }
41
+ if (schemas[modName]) {
42
+ const { params: schema, response: responseSchema } = schemas[modName];
43
+ if (!schema.$schema) {
44
+ schema.$schema = 'http://json-schema.org/draft-07/schema#';
45
+ schema.title = `Module \`${modName}\`: Params model`;
39
46
  }
40
- if (schemas[modName]) {
41
- const { params: schema, response: responseSchema } = schemas[modName];
42
- if (!schema.$schema) {
43
- schema.$schema = 'http://json-schema.org/draft-07/schema#';
44
- schema.title = `Module \`${modName}\`: Params model`;
45
- }
46
- if (!responseSchema.$schema) {
47
- responseSchema.$schema = 'http://json-schema.org/draft-07/schema#';
48
- responseSchema.title = `Module \`${modName}\`: App response model`;
49
- }
50
- if (url === `/${modName}/schema`) {
51
- return sendSchema();
52
- }
53
- if (url === `/${modName}/response_schema`) {
54
- return sendSchema(true);
55
- }
56
- if (url === `/${modName}`) {
57
- return handleModule(modName, schema, responseSchema, req, res)[method]();
58
- }
47
+ if (!responseSchema.$schema) {
48
+ responseSchema.$schema = 'http://json-schema.org/draft-07/schema#';
49
+ responseSchema.title = `Module \`${modName}\`: App response model`;
59
50
  }
60
- return res.sendStatus(404);
51
+ if (url === `/${modName}/schema`) {
52
+ return sendSchema();
53
+ }
54
+ if (url === `/${modName}/response_schema`) {
55
+ return sendSchema(true);
56
+ }
57
+ if (url === `/${modName}`) {
58
+ return handleModule(modName, schema, responseSchema, req, res)[method]();
59
+ }
60
+ }
61
+ return res.sendStatus(404);
61
62
  };
62
- //# sourceMappingURL=serve-modules-api.js.map
63
+ // # sourceMappingURL=serve-modules-api.js.map
@@ -4,11 +4,13 @@ import '@cloudcommerce/firebase/lib/init';
4
4
  import { onRequest } from 'firebase-functions/v2/https';
5
5
  import config from '@cloudcommerce/firebase/lib/config';
6
6
  import serveModulesApi from './firebase/serve-modules-api.js';
7
+
7
8
  const { httpsFunctionOptions } = config.get();
9
+
8
10
  export const modules = onRequest({
9
- concurrency: 6,
10
- ...httpsFunctionOptions,
11
+ concurrency: 6,
12
+ ...httpsFunctionOptions,
11
13
  }, (req, res) => {
12
- serveModulesApi(req, res);
14
+ serveModulesApi(req, res);
13
15
  });
14
- //# sourceMappingURL=firebase.js.map
16
+ // # sourceMappingURL=firebase.js.map
@@ -3,20 +3,23 @@ import * as applyDiscount from '../schemas/apply_discount.cjs';
3
3
  import * as listPayments from '../schemas/list_payments.cjs';
4
4
  import * as createTransaction from '../schemas/create_transaction.cjs';
5
5
  import * as checkout from '../schemas/@checkout.cjs';
6
+
6
7
  const schemas = {
7
- calculate_shipping: calculateShipping,
8
- apply_discount: applyDiscount,
9
- list_payments: listPayments,
10
- create_transaction: createTransaction,
11
- '@checkout': checkout,
8
+ calculate_shipping: calculateShipping,
9
+ apply_discount: applyDiscount,
10
+ list_payments: listPayments,
11
+ create_transaction: createTransaction,
12
+ '@checkout': checkout,
12
13
  };
14
+
13
15
  export default {
14
- calculateShipping,
15
- applyDiscount,
16
- listPayments,
17
- createTransaction,
18
- checkout,
19
- schemas,
16
+ calculateShipping,
17
+ applyDiscount,
18
+ listPayments,
19
+ createTransaction,
20
+ checkout,
21
+ schemas,
20
22
  };
23
+
21
24
  export { schemas };
22
- //# sourceMappingURL=index.js.map
25
+ // # sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/modules",
3
3
  "type": "module",
4
- "version": "0.0.98",
4
+ "version": "0.0.99",
5
5
  "description": "E-Com Plus Cloud Commerce modules API",
6
6
  "main": "lib/index.cjs",
7
7
  "exports": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/passport",
3
3
  "type": "module",
4
- "version": "0.0.98",
4
+ "version": "0.0.99",
5
5
  "description": "E-Com Plus Cloud Commerce customers authentication (passport) API",
6
6
  "main": "lib/index.js",
7
7
  "exports": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/ssr",
3
3
  "type": "module",
4
- "version": "0.0.98",
4
+ "version": "0.0.99",
5
5
  "description": "E-Com Plus Cloud Commerce storefront SSR",
6
6
  "main": "lib/index.js",
7
7
  "exports": {
@@ -143,7 +143,7 @@ const genAstroConfig = ({
143
143
  ],
144
144
  resolve: {
145
145
  alias: {
146
- '@i18n': `@ecomplus/i18n/src/${lang}/index.js`,
146
+ '@i18n': `@ecomplus/i18n/lib/${lang}.mjs`,
147
147
  },
148
148
  },
149
149
  },
@@ -1 +1 @@
1
- import{_ as i}from"./chunks/LoginOffcanvas.07fe6492.js";import"./chunks/preload-helper.f15ab524.js";import"./chunks/runtime-dom.esm-bundler.738639ee.js";/* empty css */export{i as default};
1
+ import{_ as i}from"./chunks/LoginOffcanvas.e48f274b.js";import"./chunks/preload-helper.f15ab524.js";import"./chunks/runtime-dom.esm-bundler.738639ee.js";/* empty css */export{i as default};