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.
- package/CHANGELOG.md +7 -0
- package/package.json +1 -1
- package/packages/api/package.json +1 -1
- package/packages/apps/correios/package.json +1 -1
- package/packages/apps/custom-shipping/package.json +1 -1
- package/packages/apps/discounts/package.json +1 -1
- package/packages/apps/frenet/package.json +1 -1
- package/packages/apps/tiny-erp/lib/event-to-tiny.js +94 -94
- package/packages/apps/tiny-erp/lib/index.js +1 -1
- package/packages/apps/tiny-erp/lib/integration/after-tiny-queue.js +71 -74
- package/packages/apps/tiny-erp/lib/integration/export-order-to-tiny.js +70 -73
- package/packages/apps/tiny-erp/lib/integration/export-product-to-tiny.js +49 -53
- package/packages/apps/tiny-erp/lib/integration/helpers/format-tiny-date.js +3 -3
- package/packages/apps/tiny-erp/lib/integration/import-order-from-tiny.js +76 -75
- package/packages/apps/tiny-erp/lib/integration/import-product-from-tiny.js +137 -140
- package/packages/apps/tiny-erp/lib/integration/parsers/order-from-tiny.js +40 -39
- package/packages/apps/tiny-erp/lib/integration/parsers/order-to-tiny.js +173 -178
- package/packages/apps/tiny-erp/lib/integration/parsers/product-from-tiny.js +173 -171
- package/packages/apps/tiny-erp/lib/integration/parsers/product-to-tiny.js +123 -127
- package/packages/apps/tiny-erp/lib/integration/parsers/status-from-tiny.js +32 -32
- package/packages/apps/tiny-erp/lib/integration/parsers/status-to-tiny.js +37 -37
- package/packages/apps/tiny-erp/lib/integration/post-tiny-erp.js +42 -43
- package/packages/apps/tiny-erp/lib/tiny-erp.js +8 -6
- package/packages/apps/tiny-erp/lib/tiny-webhook.js +76 -73
- package/packages/apps/tiny-erp/package.json +1 -1
- package/packages/cli/package.json +1 -1
- package/packages/config/package.json +1 -1
- package/packages/events/package.json +1 -1
- package/packages/firebase/package.json +1 -1
- package/packages/modules/lib/firebase/ajv.js +24 -19
- package/packages/modules/lib/firebase/call-app-module.js +110 -116
- package/packages/modules/lib/firebase/checkout.js +152 -151
- package/packages/modules/lib/firebase/functions-checkout/fix-items.js +187 -194
- package/packages/modules/lib/firebase/functions-checkout/get-custumerId.js +26 -25
- package/packages/modules/lib/firebase/functions-checkout/handle-order-transaction.js +109 -110
- package/packages/modules/lib/firebase/functions-checkout/new-order.js +177 -177
- package/packages/modules/lib/firebase/functions-checkout/request-to-module.js +59 -59
- package/packages/modules/lib/firebase/functions-checkout/utils.js +197 -195
- package/packages/modules/lib/firebase/handle-module.js +146 -144
- package/packages/modules/lib/firebase/proxy-apps.js +1 -2
- package/packages/modules/lib/firebase/serve-modules-api.js +53 -52
- package/packages/modules/lib/firebase.js +6 -4
- package/packages/modules/lib/index.js +15 -12
- package/packages/modules/package.json +1 -1
- package/packages/passport/package.json +1 -1
- package/packages/ssr/package.json +1 -1
- package/packages/storefront/astro.config.mjs +1 -1
- package/packages/storefront/dist/client/{LoginOffcanvas.daf3f717.js → LoginOffcanvas.c2faa1dc.js} +1 -1
- package/packages/storefront/dist/client/chunks/{LoginForm.d9251274.js → LoginForm.3bcb85fb.js} +10 -10
- package/packages/storefront/dist/client/chunks/{LoginOffcanvas.07fe6492.js → LoginOffcanvas.e48f274b.js} +1 -1
- package/packages/storefront/dist/client/sw.js +1 -1
- package/packages/storefront/dist/server/entry.mjs +2 -2
- package/packages/storefront/package.json +2 -2
- package/packages/storefront/tsconfig.json +1 -1
- package/packages/types/package.json +1 -1
|
@@ -1,207 +1,200 @@
|
|
|
1
1
|
import api from '@cloudcommerce/api';
|
|
2
|
+
|
|
2
3
|
export default async (checkoutItems) => {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
4
|
+
const items = [...checkoutItems];
|
|
5
|
+
// get each cart item
|
|
6
|
+
// count done processes
|
|
7
|
+
let itemsDone = 0;
|
|
8
|
+
const itemsTodo = items.length;
|
|
9
|
+
// eslint-disable-next-line consistent-return
|
|
10
|
+
const doFinally = () => {
|
|
11
|
+
// after each item
|
|
12
|
+
itemsDone += 1;
|
|
13
|
+
if (itemsDone === itemsTodo) {
|
|
14
|
+
return items;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
16
17
|
// run item by item
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
18
|
+
for (let i = 0; i < items.length; i++) {
|
|
19
|
+
// i, item scoped
|
|
20
|
+
const item = items[i];
|
|
21
|
+
const removeItem = () => {
|
|
22
|
+
// remove invalid item from list
|
|
23
|
+
items.splice(i, 1);
|
|
24
|
+
doFinally();
|
|
25
|
+
};
|
|
26
|
+
if (!item.quantity) {
|
|
27
|
+
// ignore items without quantity or zero
|
|
28
|
+
removeItem();
|
|
29
|
+
i -= 1;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
const proceedItem = () => {
|
|
33
|
+
// additions to final price
|
|
34
|
+
if (Array.isArray(item.customizations)) {
|
|
35
|
+
item.customizations.forEach((customization) => {
|
|
36
|
+
if (item.final_price) {
|
|
37
|
+
if (customization.add_to_price) {
|
|
38
|
+
const { type, addition } = customization.add_to_price;
|
|
39
|
+
item.final_price += type === 'fixed'
|
|
40
|
+
? addition
|
|
41
|
+
: ((item.price * addition) / 100);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
// done
|
|
47
|
+
doFinally();
|
|
48
|
+
};
|
|
49
|
+
const checkItem = (product) => {
|
|
50
|
+
if (!product.available) {
|
|
51
|
+
removeItem();
|
|
52
|
+
} else {
|
|
53
|
+
let body;
|
|
54
|
+
// check variation if any
|
|
55
|
+
if (!item.variation_id) {
|
|
56
|
+
body = product;
|
|
57
|
+
} else {
|
|
58
|
+
// find respective variation
|
|
59
|
+
let variation;
|
|
60
|
+
if (product.variations) {
|
|
61
|
+
variation = product.variations.find((variationFind) => variationFind._id === item.variation_id);
|
|
62
|
+
}
|
|
63
|
+
if (variation) {
|
|
64
|
+
// merge product body with variation object
|
|
65
|
+
body = Object.assign(product, variation);
|
|
66
|
+
}
|
|
30
67
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
68
|
+
// logger.log(body._id)
|
|
69
|
+
if (!body || (body.min_quantity && body.min_quantity > item.quantity)) {
|
|
70
|
+
// cannot handle current item
|
|
71
|
+
// invalid variation or quantity lower then minimum
|
|
72
|
+
removeItem();
|
|
73
|
+
} else {
|
|
74
|
+
// check quantity
|
|
75
|
+
if (body.quantity && body.quantity < item.quantity) {
|
|
76
|
+
// reduce to max available quantity
|
|
77
|
+
item.quantity = body.quantity;
|
|
78
|
+
}
|
|
79
|
+
// extend item properties with body
|
|
80
|
+
[
|
|
81
|
+
'sku',
|
|
82
|
+
'name',
|
|
83
|
+
'currency_id',
|
|
84
|
+
'currency_symbol',
|
|
85
|
+
'price',
|
|
86
|
+
'dimensions',
|
|
87
|
+
'weight',
|
|
88
|
+
'production_time',
|
|
89
|
+
].forEach((prop) => {
|
|
90
|
+
if (body && body[prop] !== undefined) {
|
|
91
|
+
item[prop] = body[prop];
|
|
44
92
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
93
|
+
});
|
|
94
|
+
// price is required
|
|
95
|
+
if (!item.price) {
|
|
96
|
+
item.price = 0;
|
|
97
|
+
}
|
|
98
|
+
if (Array.isArray(item.flags)) {
|
|
99
|
+
// prevent error with repeated flags
|
|
100
|
+
const flags = [];
|
|
101
|
+
item.flags.forEach((flag) => {
|
|
102
|
+
if (!flags.includes(flag)) {
|
|
103
|
+
flags.push(flag);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
item.flags = flags;
|
|
107
|
+
}
|
|
108
|
+
//
|
|
109
|
+
// item.final_price = getPrice(body);
|
|
110
|
+
proceedItem();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
const checkKitProduct = (kitProduct, kitProductId) => {
|
|
115
|
+
if (item.kit_product) {
|
|
116
|
+
if (kitProduct.available && kitProduct.kit_composition) {
|
|
117
|
+
// check kit composition and quantities
|
|
118
|
+
let packQuantity = 0;
|
|
119
|
+
let isFixedQuantity = true;
|
|
120
|
+
let kitItem;
|
|
121
|
+
kitProduct.kit_composition.forEach((currentKitItem) => {
|
|
122
|
+
if (currentKitItem.quantity) {
|
|
123
|
+
packQuantity += currentKitItem.quantity;
|
|
124
|
+
} else if (isFixedQuantity) {
|
|
125
|
+
isFixedQuantity = false;
|
|
51
126
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
// check variation if any
|
|
55
|
-
if (!item.variation_id) {
|
|
56
|
-
body = product;
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
// find respective variation
|
|
60
|
-
let variation;
|
|
61
|
-
if (product.variations) {
|
|
62
|
-
variation = product.variations.find((variationFind) => variationFind._id === item.variation_id);
|
|
63
|
-
}
|
|
64
|
-
if (variation) {
|
|
65
|
-
// merge product body with variation object
|
|
66
|
-
body = Object.assign(product, variation);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
// logger.log(body._id)
|
|
70
|
-
if (!body || (body.min_quantity && body.min_quantity > item.quantity)) {
|
|
71
|
-
// cannot handle current item
|
|
72
|
-
// invalid variation or quantity lower then minimum
|
|
73
|
-
removeItem();
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
// check quantity
|
|
77
|
-
if (body.quantity && body.quantity < item.quantity) {
|
|
78
|
-
// reduce to max available quantity
|
|
79
|
-
item.quantity = body.quantity;
|
|
80
|
-
}
|
|
81
|
-
// extend item properties with body
|
|
82
|
-
[
|
|
83
|
-
'sku',
|
|
84
|
-
'name',
|
|
85
|
-
'currency_id',
|
|
86
|
-
'currency_symbol',
|
|
87
|
-
'price',
|
|
88
|
-
'dimensions',
|
|
89
|
-
'weight',
|
|
90
|
-
'production_time',
|
|
91
|
-
].forEach((prop) => {
|
|
92
|
-
if (body && body[prop] !== undefined) {
|
|
93
|
-
item[prop] = body[prop];
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
// price is required
|
|
97
|
-
if (!item.price) {
|
|
98
|
-
item.price = 0;
|
|
99
|
-
}
|
|
100
|
-
if (Array.isArray(item.flags)) {
|
|
101
|
-
// prevent error with repeated flags
|
|
102
|
-
const flags = [];
|
|
103
|
-
item.flags.forEach((flag) => {
|
|
104
|
-
if (!flags.includes(flag)) {
|
|
105
|
-
flags.push(flag);
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
item.flags = flags;
|
|
109
|
-
}
|
|
110
|
-
//
|
|
111
|
-
// item.final_price = getPrice(body);
|
|
112
|
-
proceedItem();
|
|
113
|
-
}
|
|
127
|
+
if (currentKitItem._id === item.product_id) {
|
|
128
|
+
kitItem = currentKitItem;
|
|
114
129
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
let isFixedQuantity = true;
|
|
122
|
-
let kitItem;
|
|
123
|
-
kitProduct.kit_composition.forEach((currentKitItem) => {
|
|
124
|
-
if (currentKitItem.quantity) {
|
|
125
|
-
packQuantity += currentKitItem.quantity;
|
|
126
|
-
}
|
|
127
|
-
else if (isFixedQuantity) {
|
|
128
|
-
isFixedQuantity = false;
|
|
129
|
-
}
|
|
130
|
-
if (currentKitItem._id === item.product_id) {
|
|
131
|
-
kitItem = currentKitItem;
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
if (!isFixedQuantity) {
|
|
135
|
-
// use parent product min quantity
|
|
136
|
-
packQuantity = kitProduct.min_quantity || 0;
|
|
137
|
-
}
|
|
138
|
-
if (kitItem && (kitItem.quantity === undefined
|
|
130
|
+
});
|
|
131
|
+
if (!isFixedQuantity) {
|
|
132
|
+
// use parent product min quantity
|
|
133
|
+
packQuantity = kitProduct.min_quantity || 0;
|
|
134
|
+
}
|
|
135
|
+
if (kitItem && (kitItem.quantity === undefined
|
|
139
136
|
|| item.quantity % kitItem.quantity === 0)) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
// remove items with invalid kit
|
|
163
|
-
let index = 0;
|
|
164
|
-
while (index < items.length) {
|
|
165
|
-
const itemKit = items[index].kit_product;
|
|
166
|
-
if (itemKit && itemKit._id === kitProductId) {
|
|
167
|
-
items.splice(index, 1);
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
index += 1;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
doFinally();
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
if (item.kit_product) {
|
|
177
|
-
// GET public kit product object
|
|
178
|
-
const kitProductId = item.kit_product._id;
|
|
179
|
-
// eslint-disable-next-line no-await-in-loop
|
|
180
|
-
const kitProduct = (await api.get(`products/${kitProductId}`, {
|
|
181
|
-
isNoAuth: true,
|
|
182
|
-
})).data;
|
|
183
|
-
if (kitProduct) {
|
|
184
|
-
checkKitProduct(kitProduct, kitProductId);
|
|
185
|
-
}
|
|
186
|
-
else {
|
|
187
|
-
removeItem();
|
|
137
|
+
// valid kit item and quantity
|
|
138
|
+
let kitTotalQuantity = 0;
|
|
139
|
+
items.forEach((itemFind) => {
|
|
140
|
+
if (itemFind.kit_product && itemFind.kit_product._id === kitProductId) {
|
|
141
|
+
kitTotalQuantity += itemFind.quantity;
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
const minPacks = kitItem.quantity
|
|
145
|
+
? item.quantity / kitItem.quantity
|
|
146
|
+
: 1;
|
|
147
|
+
if (kitTotalQuantity && kitTotalQuantity % (minPacks * packQuantity) === 0) {
|
|
148
|
+
// matched pack quantity
|
|
149
|
+
// item.kit_product.price = getPrice(kitProduct);
|
|
150
|
+
item.kit_product.pack_quantity = packQuantity;
|
|
151
|
+
if (item.kit_product.price) {
|
|
152
|
+
// set final price from kit
|
|
153
|
+
item.final_price = item.kit_product.price / packQuantity;
|
|
154
|
+
}
|
|
155
|
+
proceedItem();
|
|
188
156
|
}
|
|
157
|
+
}
|
|
189
158
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
else {
|
|
200
|
-
// remove cart item
|
|
201
|
-
removeItem();
|
|
202
|
-
}
|
|
159
|
+
// remove items with invalid kit
|
|
160
|
+
let index = 0;
|
|
161
|
+
while (index < items.length) {
|
|
162
|
+
const itemKit = items[index].kit_product;
|
|
163
|
+
if (itemKit && itemKit._id === kitProductId) {
|
|
164
|
+
items.splice(index, 1);
|
|
165
|
+
} else {
|
|
166
|
+
index += 1;
|
|
167
|
+
}
|
|
203
168
|
}
|
|
169
|
+
doFinally();
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
if (item.kit_product) {
|
|
173
|
+
// GET public kit product object
|
|
174
|
+
const kitProductId = item.kit_product._id;
|
|
175
|
+
// eslint-disable-next-line no-await-in-loop
|
|
176
|
+
const kitProduct = (await api.get(`products/${kitProductId}`, {
|
|
177
|
+
isNoAuth: true,
|
|
178
|
+
})).data;
|
|
179
|
+
if (kitProduct) {
|
|
180
|
+
checkKitProduct(kitProduct, kitProductId);
|
|
181
|
+
} else {
|
|
182
|
+
removeItem();
|
|
183
|
+
}
|
|
184
|
+
} else {
|
|
185
|
+
// GET public product object
|
|
186
|
+
// eslint-disable-next-line no-await-in-loop
|
|
187
|
+
const product = (await api.get(`products/${item.product_id}`, {
|
|
188
|
+
isNoAuth: true,
|
|
189
|
+
})).data;
|
|
190
|
+
if (product) {
|
|
191
|
+
checkItem(product);
|
|
192
|
+
} else {
|
|
193
|
+
// remove cart item
|
|
194
|
+
removeItem();
|
|
195
|
+
}
|
|
204
196
|
}
|
|
205
|
-
|
|
197
|
+
}
|
|
198
|
+
return items;
|
|
206
199
|
};
|
|
207
|
-
|
|
200
|
+
// # sourceMappingURL=fix-items.js.map
|
|
@@ -1,33 +1,34 @@
|
|
|
1
1
|
import api from '@cloudcommerce/api';
|
|
2
2
|
import { logger } from 'firebase-functions';
|
|
3
|
+
|
|
3
4
|
const findCustomerByEmail = async (email, accessToken) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
return null;
|
|
12
|
-
}
|
|
13
|
-
catch (e) {
|
|
14
|
-
logger.error(e);
|
|
15
|
-
return null;
|
|
5
|
+
try {
|
|
6
|
+
const { data } = await api.get(`customers?main_email=${email}`, {
|
|
7
|
+
accessToken,
|
|
8
|
+
});
|
|
9
|
+
if (data.result.length) {
|
|
10
|
+
return data.result[0]._id;
|
|
16
11
|
}
|
|
12
|
+
return null;
|
|
13
|
+
} catch (e) {
|
|
14
|
+
logger.error(e);
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
17
|
};
|
|
18
|
+
|
|
18
19
|
export default (accessToken, customer) => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
if (customer._id && (typeof customer._id === 'string') && customer._id.length === 24) {
|
|
27
|
-
// customer ID already defined
|
|
28
|
-
return customer._id;
|
|
29
|
-
}
|
|
20
|
+
if (customer) {
|
|
21
|
+
if (!customer._id) {
|
|
22
|
+
// try to find customer by e-mail
|
|
23
|
+
// GET customer object
|
|
24
|
+
return customer.main_email ? findCustomerByEmail(customer.main_email, accessToken) : null;
|
|
25
|
+
// use first resulted customer ID
|
|
30
26
|
}
|
|
31
|
-
|
|
27
|
+
if (customer._id && (typeof customer._id === 'string') && customer._id.length === 24) {
|
|
28
|
+
// customer ID already defined
|
|
29
|
+
return customer._id;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
32
33
|
};
|
|
33
|
-
|
|
34
|
+
// # sourceMappingURL=get-custumerId.js.map
|