rerobe-js-orm 4.5.7 → 4.5.9
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/lib/constants/order-constants.d.ts +3 -0
- package/lib/constants/order-constants.js +3 -0
- package/lib/factories/Order/OrderFromShopifyWebhook.js +13 -9
- package/lib/models/Order.d.ts +2 -0
- package/lib/models/Order.js +39 -26
- package/lib/models/Product.d.ts +2 -4
- package/lib/models/Product.js +7 -21
- package/package.json +1 -1
|
@@ -10,6 +10,7 @@ export namespace PAYMENT_TYPES {
|
|
|
10
10
|
let shoppingCredit: string;
|
|
11
11
|
let cash: string;
|
|
12
12
|
let mobilePayment: string;
|
|
13
|
+
let shopifyPayment: string;
|
|
13
14
|
}
|
|
14
15
|
export namespace ORDER_STATES {
|
|
15
16
|
let draft: string;
|
|
@@ -21,6 +22,7 @@ export namespace SALES_CHANNELS {
|
|
|
21
22
|
let store: string;
|
|
22
23
|
let onlineStore: string;
|
|
23
24
|
let thirdParty: string;
|
|
25
|
+
let shopify: string;
|
|
24
26
|
let ahlens: string;
|
|
25
27
|
let ribbnMobilePOS: string;
|
|
26
28
|
let ribbnWebPOS: string;
|
|
@@ -51,6 +53,7 @@ export const SALES_CHANNEL_TO_RETURN_POLICY_MAPPING: {
|
|
|
51
53
|
[SALES_CHANNELS.webApp]: string;
|
|
52
54
|
[SALES_CHANNELS.store]: string;
|
|
53
55
|
[SALES_CHANNELS.onlineStore]: string;
|
|
56
|
+
[SALES_CHANNELS.shopify]: string;
|
|
54
57
|
[SALES_CHANNELS.thirdParty]: string;
|
|
55
58
|
[SALES_CHANNELS.ahlens]: string;
|
|
56
59
|
[SALES_CHANNELS.ribbnMobilePOS]: string;
|
|
@@ -13,6 +13,7 @@ exports.PAYMENT_TYPES = {
|
|
|
13
13
|
shoppingCredit: 'SHOPPING_CREDIT',
|
|
14
14
|
cash: 'CASH',
|
|
15
15
|
mobilePayment: 'MOBILE_PAYMENT',
|
|
16
|
+
shopifyPayment: 'SHOPIFY_PAYMENT',
|
|
16
17
|
};
|
|
17
18
|
exports.ORDER_STATES = {
|
|
18
19
|
draft: 'DRAFT',
|
|
@@ -24,6 +25,7 @@ exports.SALES_CHANNELS = {
|
|
|
24
25
|
store: 'STORE',
|
|
25
26
|
onlineStore: 'ONLINE_STORE',
|
|
26
27
|
thirdParty: 'THIRD_PARTY',
|
|
28
|
+
shopify: 'SHOPIFY',
|
|
27
29
|
ahlens: 'AHLENS',
|
|
28
30
|
ribbnMobilePOS: 'RIBBN_MOBILE_POS',
|
|
29
31
|
ribbnWebPOS: 'RIBBN_WEB_POS',
|
|
@@ -54,6 +56,7 @@ exports.SALES_CHANNEL_TO_RETURN_POLICY_MAPPING = {
|
|
|
54
56
|
[exports.SALES_CHANNELS.webApp]: exports.RETURN_POLICY_TYPES.inStore,
|
|
55
57
|
[exports.SALES_CHANNELS.store]: exports.RETURN_POLICY_TYPES.inStore,
|
|
56
58
|
[exports.SALES_CHANNELS.onlineStore]: exports.RETURN_POLICY_TYPES.online,
|
|
59
|
+
[exports.SALES_CHANNELS.shopify]: exports.RETURN_POLICY_TYPES.online,
|
|
57
60
|
[exports.SALES_CHANNELS.thirdParty]: exports.RETURN_POLICY_TYPES.inStore,
|
|
58
61
|
[exports.SALES_CHANNELS.ahlens]: exports.RETURN_POLICY_TYPES.inStore,
|
|
59
62
|
[exports.SALES_CHANNELS.ribbnMobilePOS]: exports.RETURN_POLICY_TYPES.inStore,
|
|
@@ -3,7 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const OrderFactory_1 = require("./OrderFactory");
|
|
4
4
|
const Order_1 = require("../../models/Order");
|
|
5
5
|
const OrderHelpers_1 = require("../../helpers/OrderHelpers");
|
|
6
|
+
const order_constants_1 = require("../../constants/order-constants");
|
|
6
7
|
const orderHelpers = new OrderHelpers_1.default();
|
|
8
|
+
// Helper: build MoneyBag with defaults; if presentment missing, copy from shop, and vice versa
|
|
9
|
+
const buildMoneyBagFromAmount = (amount, currency) => ({
|
|
10
|
+
shopMoney: { amount: amount !== undefined ? amount : 0, currencyCode: currency || '' },
|
|
11
|
+
presentmentMoney: { amount: amount !== undefined ? amount : 0, currencyCode: currency || '' },
|
|
12
|
+
});
|
|
7
13
|
const fulfillmentStatusRestMapping = {
|
|
8
14
|
fulfilled: 'FULFILLED',
|
|
9
15
|
null: '',
|
|
@@ -274,7 +280,7 @@ class OrderFromShopifyWebhook extends OrderFactory_1.default {
|
|
|
274
280
|
fulfillments,
|
|
275
281
|
refunds,
|
|
276
282
|
taxLines,
|
|
277
|
-
shippingLine, state: Order_1.default.ORDER_STATES.completed, shippingType: orderHelpers.getShippingTypeFromShopifyObj(shipping_lines), paymentType: orderHelpers.getPaymentTypeUsingTags(tags), salesChannel:
|
|
283
|
+
shippingLine, state: Order_1.default.ORDER_STATES.completed, shippingType: orderHelpers.getShippingTypeFromShopifyObj(shipping_lines), paymentType: orderHelpers.getPaymentTypeUsingTags(tags), salesChannel: order_constants_1.SALES_CHANNELS.shopify, tags: tags ? tags.split(', ') : [] }));
|
|
278
284
|
return rerobeOrder.toObj();
|
|
279
285
|
}
|
|
280
286
|
// Aligned with Shopify REST order payload that includes current_* fields
|
|
@@ -326,7 +332,7 @@ class OrderFromShopifyWebhook extends OrderFactory_1.default {
|
|
|
326
332
|
const taxLinesV2 = tax_lines.map((item) => ({
|
|
327
333
|
rate: item.rate,
|
|
328
334
|
title: item.title,
|
|
329
|
-
priceSet:
|
|
335
|
+
priceSet: buildMoneyBagFromAmount(item.price, currency || ''),
|
|
330
336
|
}));
|
|
331
337
|
const shippingLine = shipping_lines && shipping_lines.length
|
|
332
338
|
? {
|
|
@@ -437,10 +443,7 @@ class OrderFromShopifyWebhook extends OrderFactory_1.default {
|
|
|
437
443
|
const taxLinesV3 = (tax_lines || []).map((item) => ({
|
|
438
444
|
rate: item.rate,
|
|
439
445
|
title: item.title,
|
|
440
|
-
priceSet:
|
|
441
|
-
shopMoney: { amount: item.price, currencyCode: currency || '' },
|
|
442
|
-
presentmentMoney: { amount: item.price, currencyCode: currency || '' },
|
|
443
|
-
},
|
|
446
|
+
priceSet: buildMoneyBagFromAmount(item.price, currency || ''),
|
|
444
447
|
}));
|
|
445
448
|
const shippingLine = shipping_lines && shipping_lines.length
|
|
446
449
|
? {
|
|
@@ -580,7 +583,8 @@ class OrderFromShopifyWebhook extends OrderFactory_1.default {
|
|
|
580
583
|
// @ts-ignore
|
|
581
584
|
const fulfillmentStatus = !fulfillment_status ? '' : fulfillmentStatusRestMapping[fulfillment_status];
|
|
582
585
|
const rerobeOrder = new Order_1.default({
|
|
583
|
-
id:
|
|
586
|
+
id: this.utilities.makeRandId(28),
|
|
587
|
+
documentId: this.utilities.makeRandId(28),
|
|
584
588
|
shopifyId: `gid://shopify/Order/${id}`,
|
|
585
589
|
shopifyOrderNumber: name ? Number(String(name).replace('#', '')) : order_number || 0,
|
|
586
590
|
name: name || '',
|
|
@@ -612,8 +616,8 @@ class OrderFromShopifyWebhook extends OrderFactory_1.default {
|
|
|
612
616
|
tags: tags ? String(tags).split(', ').filter(Boolean) : [],
|
|
613
617
|
state: Order_1.default.ORDER_STATES.completed,
|
|
614
618
|
shippingType: orderHelpers.getShippingTypeFromShopifyObj((shipping_lines || [])),
|
|
615
|
-
paymentType:
|
|
616
|
-
salesChannel:
|
|
619
|
+
paymentType: order_constants_1.PAYMENT_TYPES.shopifyPayment,
|
|
620
|
+
salesChannel: order_constants_1.SALES_CHANNELS.shopify,
|
|
617
621
|
});
|
|
618
622
|
return rerobeOrder.toObj();
|
|
619
623
|
}
|
package/lib/models/Order.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export default class Order extends Base {
|
|
|
12
12
|
shoppingCredit: string;
|
|
13
13
|
cash: string;
|
|
14
14
|
mobilePayment: string;
|
|
15
|
+
shopifyPayment: string;
|
|
15
16
|
};
|
|
16
17
|
static ORDER_STATES: {
|
|
17
18
|
draft: string;
|
|
@@ -23,6 +24,7 @@ export default class Order extends Base {
|
|
|
23
24
|
store: string;
|
|
24
25
|
onlineStore: string;
|
|
25
26
|
thirdParty: string;
|
|
27
|
+
shopify: string;
|
|
26
28
|
ahlens: string;
|
|
27
29
|
ribbnMobilePOS: string;
|
|
28
30
|
ribbnWebPOS: string;
|
package/lib/models/Order.js
CHANGED
|
@@ -99,33 +99,46 @@ class Order extends Base_1.default {
|
|
|
99
99
|
this.customerName = (props === null || props === void 0 ? void 0 : props.customerName) || '';
|
|
100
100
|
this.merchantId = (props === null || props === void 0 ? void 0 : props.merchantId) || '';
|
|
101
101
|
this.refunds = (props === null || props === void 0 ? void 0 : props.refunds) || [];
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
amount
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
102
|
+
const defaultPresentmentFrom = (present, base) => {
|
|
103
|
+
const coerceAmount = (val) => {
|
|
104
|
+
const num = Number(val);
|
|
105
|
+
if (!Number.isFinite(num))
|
|
106
|
+
return NaN;
|
|
107
|
+
const rounded = Math.round((num + Number.EPSILON) * 100) / 100;
|
|
108
|
+
return Number(rounded.toFixed(2));
|
|
109
|
+
};
|
|
110
|
+
// Try presentment first
|
|
111
|
+
if (present && typeof present === 'object' && 'amount' in present) {
|
|
112
|
+
const amt = coerceAmount(present.amount);
|
|
113
|
+
if (!Number.isNaN(amt)) {
|
|
114
|
+
return {
|
|
115
|
+
amount: amt,
|
|
116
|
+
currencyCode: present.currencyCode || (base === null || base === void 0 ? void 0 : base.currencyCode) || this.currencyCode || '',
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
// Fallback to base
|
|
121
|
+
if (base && typeof base === 'object' && 'amount' in base) {
|
|
122
|
+
const amt = coerceAmount(base.amount);
|
|
123
|
+
if (!Number.isNaN(amt)) {
|
|
124
|
+
return {
|
|
125
|
+
amount: amt,
|
|
126
|
+
currencyCode: base.currencyCode || this.currencyCode || '',
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
// Final default
|
|
131
|
+
return { amount: 0, currencyCode: this.currencyCode || '' };
|
|
128
132
|
};
|
|
133
|
+
this.subtotalPricePresentment = defaultPresentmentFrom(props === null || props === void 0 ? void 0 : props.subtotalPricePresentment, this.subtotalPrice);
|
|
134
|
+
this.totalDiscountPresentment = defaultPresentmentFrom(props === null || props === void 0 ? void 0 : props.totalDiscountPresentment, this.totalDiscount);
|
|
135
|
+
this.totalPricePresentment = defaultPresentmentFrom(props === null || props === void 0 ? void 0 : props.totalPricePresentment, this.totalPrice);
|
|
136
|
+
this.totalRefundedPresentment = defaultPresentmentFrom(props === null || props === void 0 ? void 0 : props.totalRefundedPresentment, this.totalRefunded);
|
|
137
|
+
this.totalShippingPricePresentment = defaultPresentmentFrom(props === null || props === void 0 ? void 0 : props.totalShippingPricePresentment, this.totalShippingPrice);
|
|
138
|
+
this.totalTaxPresentment = defaultPresentmentFrom(props === null || props === void 0 ? void 0 : props.totalTaxPresentment, this.totalTax);
|
|
139
|
+
this.creditDiscountPresentment = defaultPresentmentFrom(props === null || props === void 0 ? void 0 : props.creditDiscountPresentment, this.creditDiscount);
|
|
140
|
+
this.saleDiscountPresentment = defaultPresentmentFrom(props === null || props === void 0 ? void 0 : props.saleDiscountPresentment, this.saleDiscount);
|
|
141
|
+
this.additionalDiscountPresentment = defaultPresentmentFrom(props === null || props === void 0 ? void 0 : props.additionalDiscountPresentment, this.additionalDiscount);
|
|
129
142
|
this.createdAtTimestamp = (props === null || props === void 0 ? void 0 : props.createdAtTimestamp) || 0;
|
|
130
143
|
this.updatedAtTimestamp = (props === null || props === void 0 ? void 0 : props.updatedAtTimestamp) || 0;
|
|
131
144
|
this.adjustments = (props === null || props === void 0 ? void 0 : props.adjustments) || [];
|
package/lib/models/Product.d.ts
CHANGED
|
@@ -12,8 +12,6 @@ export default class Product extends Base {
|
|
|
12
12
|
toProductInputObjForShopify(location?: string): any;
|
|
13
13
|
toProductInputObjForShopifyV2(locationId: string, weightUnit?: string): any[];
|
|
14
14
|
toProductInputObjForShopifyV3(locationId: string, weightUnit?: string): {
|
|
15
|
-
title: string;
|
|
16
|
-
status: string;
|
|
17
15
|
productOptions: {
|
|
18
16
|
name: string;
|
|
19
17
|
values: {
|
|
@@ -21,14 +19,14 @@ export default class Product extends Base {
|
|
|
21
19
|
}[];
|
|
22
20
|
}[];
|
|
23
21
|
descriptionHtml: string;
|
|
24
|
-
productType: string;
|
|
25
|
-
vendor: string;
|
|
26
22
|
tags: (string | null)[];
|
|
27
23
|
files: {
|
|
28
24
|
originalSource: string;
|
|
29
25
|
contentType: string;
|
|
30
26
|
}[];
|
|
31
27
|
variants: any[];
|
|
28
|
+
status?: string | undefined;
|
|
29
|
+
title: string;
|
|
32
30
|
};
|
|
33
31
|
toObjForTextTranslation(): TranslatableAttributes;
|
|
34
32
|
toObjForTypesense(isCanonicalMerchant?: boolean): TypesenseProductObj;
|
package/lib/models/Product.js
CHANGED
|
@@ -333,6 +333,9 @@ class Product extends Base_1.default {
|
|
|
333
333
|
const variantsFromInventory = Array.isArray(this.attributes.variantInventory)
|
|
334
334
|
? this.attributes.variantInventory
|
|
335
335
|
: [];
|
|
336
|
+
const hasShopifyId = !!this.attributes.shopifyId;
|
|
337
|
+
const currentStatus = String(this.consignmentAttributes.status || '').toUpperCase();
|
|
338
|
+
const statusToInclude = !hasShopifyId || currentStatus.includes('SOLD') ? 'DRAFT' : undefined;
|
|
336
339
|
if (variantsFromInventory.length === 0) {
|
|
337
340
|
// Fallback: single-variant product (legacy behavior)
|
|
338
341
|
const variant = Object.assign(Object.assign({ id: '' }, baseVariantFields()), { inventoryQuantities: [
|
|
@@ -351,17 +354,8 @@ class Product extends Base_1.default {
|
|
|
351
354
|
variant.price = this.consignmentAttributes.salePrice;
|
|
352
355
|
variant.compareAtPrice = this.attributes.price || variant.compareAtPrice;
|
|
353
356
|
}
|
|
354
|
-
return {
|
|
355
|
-
|
|
356
|
-
status: 'DRAFT',
|
|
357
|
-
productOptions: [{ name: 'Variant', values: [{ name: title }] }],
|
|
358
|
-
descriptionHtml: this.attributes.description,
|
|
359
|
-
productType: this.filterAttributes.productType,
|
|
360
|
-
vendor: this.attributes.vendorId,
|
|
361
|
-
tags,
|
|
362
|
-
files,
|
|
363
|
-
variants: [variant],
|
|
364
|
-
};
|
|
357
|
+
return Object.assign(Object.assign({ title }, (statusToInclude ? { status: statusToInclude } : {})), { productOptions: [{ name: 'Variant', values: [{ name: title }] }], descriptionHtml: this.attributes.description, tags,
|
|
358
|
+
files, variants: [variant] });
|
|
365
359
|
}
|
|
366
360
|
// Multi-variant: derive axes and values from variantInventory
|
|
367
361
|
const axisOrder = [];
|
|
@@ -437,17 +431,9 @@ class Product extends Base_1.default {
|
|
|
437
431
|
}
|
|
438
432
|
return variant;
|
|
439
433
|
});
|
|
440
|
-
return {
|
|
441
|
-
title,
|
|
442
|
-
status: 'DRAFT',
|
|
443
|
-
productOptions,
|
|
444
|
-
descriptionHtml: this.attributes.description,
|
|
445
|
-
productType: this.filterAttributes.productType,
|
|
446
|
-
vendor: this.attributes.vendorId,
|
|
447
|
-
tags,
|
|
434
|
+
return Object.assign(Object.assign({ title }, (statusToInclude ? { status: statusToInclude } : {})), { productOptions, descriptionHtml: this.attributes.description, tags,
|
|
448
435
|
files,
|
|
449
|
-
variants
|
|
450
|
-
};
|
|
436
|
+
variants });
|
|
451
437
|
}
|
|
452
438
|
toObjForTextTranslation() {
|
|
453
439
|
return {
|