rerobe-js-orm 4.6.0 → 4.6.2
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/product-constants.d.ts +7 -0
- package/lib/constants/product-constants.js +8 -1
- package/lib/factories/Order/OrderFromShopifyWebhook.js +60 -19
- package/lib/models/Order.d.ts +1 -0
- package/lib/models/Order.js +56 -0
- package/lib/models/Product.js +10 -4
- package/lib/types/rerobe-order-types.d.ts +45 -7
- package/package.json +1 -1
|
@@ -327,3 +327,10 @@ export namespace PAYOUT_SYSTEM {
|
|
|
327
327
|
export { RIBBN_CREDITS_1 as RIBBN_CREDITS };
|
|
328
328
|
}
|
|
329
329
|
export const ADMIN_STATES: {};
|
|
330
|
+
export namespace PRODUCT_CLASS_VALUES {
|
|
331
|
+
let UNIQUE: string;
|
|
332
|
+
let MULTIVARIANT: string;
|
|
333
|
+
let TEMPLATE: string;
|
|
334
|
+
let SUPPLY: string;
|
|
335
|
+
let DIGITAL: string;
|
|
336
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ADMIN_STATES = exports.PAYOUT_SYSTEM = exports.PAYOUT_METHOD = exports.PUBLISH_TYPE = exports.MEASUREMENT_FIELDS_DICT = exports.MEASUREMENT_CATEGORY = exports.PRODUCT_STATE_LABELS_ADMIN_VIEW = exports.PRODUCT_STATE_LABELS = exports.ADMIN_SIMPLIFIED_STATES = exports.PRODUCT_STATES = exports.SYSTEM_DRIVEN_STATES = exports.ADMIN_ACTION_DRIVEN_STATES = exports.ADMIN_DRIVEN_STATES = exports.SELLER_DRIVEN_STATES = void 0;
|
|
3
|
+
exports.PRODUCT_CLASS_VALUES = exports.ADMIN_STATES = exports.PAYOUT_SYSTEM = exports.PAYOUT_METHOD = exports.PUBLISH_TYPE = exports.MEASUREMENT_FIELDS_DICT = exports.MEASUREMENT_CATEGORY = exports.PRODUCT_STATE_LABELS_ADMIN_VIEW = exports.PRODUCT_STATE_LABELS = exports.ADMIN_SIMPLIFIED_STATES = exports.PRODUCT_STATES = exports.SYSTEM_DRIVEN_STATES = exports.ADMIN_ACTION_DRIVEN_STATES = exports.ADMIN_DRIVEN_STATES = exports.SELLER_DRIVEN_STATES = void 0;
|
|
4
4
|
exports.SELLER_DRIVEN_STATES = {
|
|
5
5
|
sellerDonated: 'SELLER_DONATED',
|
|
6
6
|
sellRequestReview: 'SELL_REQUEST_REVIEW',
|
|
@@ -234,3 +234,10 @@ exports.ADMIN_STATES = Object.entries(exports.PRODUCT_STATES)
|
|
|
234
234
|
acc[key] = value;
|
|
235
235
|
return acc;
|
|
236
236
|
}, {});
|
|
237
|
+
exports.PRODUCT_CLASS_VALUES = {
|
|
238
|
+
UNIQUE: 'UNIQUE',
|
|
239
|
+
MULTIVARIANT: 'MULTIVARIANT',
|
|
240
|
+
TEMPLATE: 'TEMPLATE',
|
|
241
|
+
SUPPLY: 'SUPPLY',
|
|
242
|
+
DIGITAL: 'DIGITAL',
|
|
243
|
+
};
|
|
@@ -396,19 +396,21 @@ class OrderFromShopifyWebhook extends OrderFactory_1.default {
|
|
|
396
396
|
}
|
|
397
397
|
// Aligned with Shopify REST order payload that includes current_* fields and statusUrl
|
|
398
398
|
createOrderV3(order) {
|
|
399
|
-
const { id, name, financial_status, fulfillment_status, cancel_reason, created_at, processed_at, updated_at, currency, contact_email, email, order_status_url, shipping_address, line_items = [], discount_applications = [], shipping_lines = [], tax_lines = [], tags = '', cancelled_at, closed_at, order_number,
|
|
399
|
+
const { id, name, financial_status, fulfillment_status, cancel_reason, created_at, processed_at, updated_at, currency, contact_email, email, order_status_url, shipping_address, line_items = [], discount_applications = [], shipping_lines = [], tax_lines = [], tags = '', cancelled_at, closed_at, order_number,
|
|
400
|
+
// Prefer non-current fields; fall back to current_* when needed
|
|
401
|
+
subtotal_price_set, total_price_set, total_tax_set, total_discounts_set, shipping_price_set, current_subtotal_price_set, current_total_price_set, current_total_tax_set, current_total_discounts_set, current_shipping_price_set, } = order || {};
|
|
400
402
|
const moneyFromSet = (setObj) => {
|
|
401
403
|
const shop = setObj === null || setObj === void 0 ? void 0 : setObj.shop_money;
|
|
402
404
|
return shop
|
|
403
405
|
? { amount: shop.amount, currencyCode: shop.currency_code }
|
|
404
406
|
: { amount: 0, currencyCode: currency || '' };
|
|
405
407
|
};
|
|
406
|
-
const subtotalPrice = moneyFromSet(current_subtotal_price_set);
|
|
407
|
-
const totalPrice = moneyFromSet(current_total_price_set);
|
|
408
|
-
const totalTax = moneyFromSet(current_total_tax_set);
|
|
409
|
-
const totalShippingPrice = moneyFromSet(current_shipping_price_set);
|
|
410
|
-
const totalDiscount = current_total_discounts_set
|
|
411
|
-
? moneyFromSet(current_total_discounts_set)
|
|
408
|
+
const subtotalPrice = moneyFromSet(subtotal_price_set || current_subtotal_price_set);
|
|
409
|
+
const totalPrice = moneyFromSet(total_price_set || current_total_price_set);
|
|
410
|
+
const totalTax = moneyFromSet(total_tax_set || current_total_tax_set);
|
|
411
|
+
const totalShippingPrice = moneyFromSet(shipping_price_set || current_shipping_price_set);
|
|
412
|
+
const totalDiscount = total_discounts_set || current_total_discounts_set
|
|
413
|
+
? moneyFromSet(total_discounts_set || current_total_discounts_set)
|
|
412
414
|
: { amount: 0, currencyCode: currency || '' };
|
|
413
415
|
const shippingAddress = shipping_address
|
|
414
416
|
? {
|
|
@@ -421,19 +423,58 @@ class OrderFromShopifyWebhook extends OrderFactory_1.default {
|
|
|
421
423
|
zip: shipping_address.zip,
|
|
422
424
|
}
|
|
423
425
|
: null;
|
|
424
|
-
const lineItems = (line_items || []).map((item) =>
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
426
|
+
const lineItems = (line_items || []).map((item) => {
|
|
427
|
+
var _a, _b, _c, _d;
|
|
428
|
+
const quantityNum = Number(item.quantity || 1);
|
|
429
|
+
const unitShop = (_a = item.price_set) === null || _a === void 0 ? void 0 : _a.shop_money;
|
|
430
|
+
const unitPresent = (_b = item.price_set) === null || _b === void 0 ? void 0 : _b.presentment_money;
|
|
431
|
+
const discountShopTotal = (_c = item.total_discount_set) === null || _c === void 0 ? void 0 : _c.shop_money;
|
|
432
|
+
const discountPresentTotal = (_d = item.total_discount_set) === null || _d === void 0 ? void 0 : _d.presentment_money;
|
|
433
|
+
const taxLine = (item.tax_lines && item.tax_lines[0]) || undefined;
|
|
434
|
+
const toNum = (v) => Number(v || 0);
|
|
435
|
+
const perUnitDiscountShop = quantityNum > 0 ? toNum(discountShopTotal === null || discountShopTotal === void 0 ? void 0 : discountShopTotal.amount) / quantityNum : 0;
|
|
436
|
+
const perUnitDiscountPresent = quantityNum > 0 ? toNum(discountPresentTotal === null || discountPresentTotal === void 0 ? void 0 : discountPresentTotal.amount) / quantityNum : 0;
|
|
437
|
+
const originalUnitPrice = unitShop
|
|
438
|
+
? { amount: unitShop.amount, currencyCode: unitShop.currency_code || currency || '' }
|
|
439
|
+
: { amount: 0, currencyCode: currency || '' };
|
|
440
|
+
const presentmentUnitPrice = unitPresent
|
|
441
|
+
? { amount: unitPresent.amount, currencyCode: unitPresent.currency_code || currency || '' }
|
|
442
|
+
: { amount: 0, currencyCode: currency || '' };
|
|
443
|
+
const saleUnitAmount = (toNum(originalUnitPrice.amount) - perUnitDiscountShop).toFixed(2);
|
|
444
|
+
const presentmentSaleUnitAmount = (toNum(presentmentUnitPrice.amount) - perUnitDiscountPresent).toFixed(2);
|
|
445
|
+
const isOnSale = toNum(discountShopTotal === null || discountShopTotal === void 0 ? void 0 : discountShopTotal.amount) > 0 ? 'yes' : '';
|
|
446
|
+
const taxRate = taxLine ? Number(taxLine.rate || 0) : 0;
|
|
447
|
+
const presentmentTaxPrice = taxLine
|
|
448
|
+
? { amount: String(taxLine.price || 0), currencyCode: presentmentUnitPrice.currencyCode }
|
|
449
|
+
: { amount: 0, currencyCode: presentmentUnitPrice.currencyCode };
|
|
450
|
+
return {
|
|
451
|
+
title: item.title,
|
|
452
|
+
quantity: quantityNum,
|
|
453
|
+
variant: {
|
|
454
|
+
id: '',
|
|
455
|
+
shopifyId: item.variant_id ? `gid://shopify/ProductVariant/${item.variant_id}` : '',
|
|
456
|
+
title: item.variant_title || '',
|
|
457
|
+
image: { id: '', originalSrc: '' },
|
|
458
|
+
},
|
|
431
459
|
image: { id: '', originalSrc: '' },
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
460
|
+
brand: item.vendor || '',
|
|
461
|
+
shopifyProductId: item.product_id ? `gid://shopify/Product/${item.product_id}` : null,
|
|
462
|
+
originalTotalPrice: moneyFromSet(item.price_set),
|
|
463
|
+
discountedTotalPrice: moneyFromSet(item.total_discount_set),
|
|
464
|
+
// Fields used by web client
|
|
465
|
+
originalUnitPrice,
|
|
466
|
+
presentmentUnitPrice,
|
|
467
|
+
salePrice: saleUnitAmount,
|
|
468
|
+
presentmentSalePrice: {
|
|
469
|
+
amount: presentmentSaleUnitAmount,
|
|
470
|
+
currencyCode: presentmentUnitPrice.currencyCode,
|
|
471
|
+
},
|
|
472
|
+
isOnSale,
|
|
473
|
+
isTaxable: Boolean(item.taxable),
|
|
474
|
+
taxRate,
|
|
475
|
+
presentmentTaxPrice,
|
|
476
|
+
};
|
|
477
|
+
});
|
|
437
478
|
const discountApplications = discount_applications.map((item) => ({
|
|
438
479
|
allocationMethod: item.allocation_method ? String(item.allocation_method).toUpperCase() : '',
|
|
439
480
|
targetSelection: item.target_selection ? String(item.target_selection).toUpperCase() : '',
|
package/lib/models/Order.d.ts
CHANGED
package/lib/models/Order.js
CHANGED
|
@@ -430,6 +430,62 @@ class Order extends Base_1.default {
|
|
|
430
430
|
};
|
|
431
431
|
return stagedObj;
|
|
432
432
|
}
|
|
433
|
+
toOrderInputObj() {
|
|
434
|
+
var _a, _b, _c, _d;
|
|
435
|
+
const toFixedPriceString = (val) => {
|
|
436
|
+
const num = Number(val || 0);
|
|
437
|
+
if (!Number.isFinite(num))
|
|
438
|
+
return '0.00';
|
|
439
|
+
return num.toFixed(2);
|
|
440
|
+
};
|
|
441
|
+
const lineItems = (this.lineItems || []).map((item) => {
|
|
442
|
+
var _a, _b;
|
|
443
|
+
return ({
|
|
444
|
+
quantity: Number(item.quantity || 1),
|
|
445
|
+
variantId: ((_a = item.variant) === null || _a === void 0 ? void 0 : _a.shopifyId) || item.shopifyProductId || ((_b = item.variant) === null || _b === void 0 ? void 0 : _b.id) || '',
|
|
446
|
+
});
|
|
447
|
+
});
|
|
448
|
+
const tagsArray = Array.isArray(this.tags)
|
|
449
|
+
? this.tags
|
|
450
|
+
: typeof this.tags === 'string' && this.tags
|
|
451
|
+
? String(this.tags)
|
|
452
|
+
.split(',')
|
|
453
|
+
.map((t) => t.trim())
|
|
454
|
+
.filter(Boolean)
|
|
455
|
+
: [];
|
|
456
|
+
const ribbnTag = 'source:ribbn';
|
|
457
|
+
if (!tagsArray.includes(ribbnTag)) {
|
|
458
|
+
tagsArray.push(ribbnTag);
|
|
459
|
+
}
|
|
460
|
+
const shippingAddress = this.shippingAddress
|
|
461
|
+
? {
|
|
462
|
+
address1: this.shippingAddress.address1 || '',
|
|
463
|
+
address2: this.shippingAddress.address2 || '',
|
|
464
|
+
city: this.shippingAddress.city || '',
|
|
465
|
+
country: this.shippingAddress.country || this.shippingAddress.countryCode || '',
|
|
466
|
+
province: this.shippingAddress.province || '',
|
|
467
|
+
zip: this.shippingAddress.zip || '',
|
|
468
|
+
}
|
|
469
|
+
: undefined;
|
|
470
|
+
const shippingLine = this.shippingLine
|
|
471
|
+
? {
|
|
472
|
+
title: this.shippingLine.title || 'Shipping fee',
|
|
473
|
+
price: toFixedPriceString((_d = (_b = (_a = this.shippingLine.originalPrice) === null || _a === void 0 ? void 0 : _a.amount) !== null && _b !== void 0 ? _b : (_c = this.totalShippingPrice) === null || _c === void 0 ? void 0 : _c.amount) !== null && _d !== void 0 ? _d : 0),
|
|
474
|
+
}
|
|
475
|
+
: undefined;
|
|
476
|
+
const orderInput = {
|
|
477
|
+
email: this.email || undefined,
|
|
478
|
+
phone: this.phone || undefined,
|
|
479
|
+
note: this.notes || undefined,
|
|
480
|
+
tags: tagsArray,
|
|
481
|
+
lineItems,
|
|
482
|
+
shippingAddress,
|
|
483
|
+
shippingLine,
|
|
484
|
+
};
|
|
485
|
+
// Remove undefined props to match GraphQL input expectations
|
|
486
|
+
Object.keys(orderInput).forEach((k) => orderInput[k] === undefined && delete orderInput[k]);
|
|
487
|
+
return orderInput;
|
|
488
|
+
}
|
|
433
489
|
}
|
|
434
490
|
Order.SHIPPING_TYPES = order_constants_1.SHIPPING_TYPES;
|
|
435
491
|
Order.PAYMENT_TYPES = order_constants_1.PAYMENT_TYPES;
|
package/lib/models/Product.js
CHANGED
|
@@ -335,7 +335,13 @@ class Product extends Base_1.default {
|
|
|
335
335
|
: [];
|
|
336
336
|
const hasShopifyId = !!this.attributes.shopifyId;
|
|
337
337
|
const currentStatus = String(this.consignmentAttributes.status || '').toUpperCase();
|
|
338
|
-
const
|
|
338
|
+
const isUnique = ![
|
|
339
|
+
product_constants_1.PRODUCT_CLASS_VALUES.MULTIVARIANT,
|
|
340
|
+
product_constants_1.PRODUCT_CLASS_VALUES.TEMPLATE,
|
|
341
|
+
product_constants_1.PRODUCT_CLASS_VALUES.SUPPLY,
|
|
342
|
+
product_constants_1.PRODUCT_CLASS_VALUES.DIGITAL,
|
|
343
|
+
].includes(String(this.attributes.productClass));
|
|
344
|
+
const statusToInclude = !hasShopifyId || (currentStatus.includes('SOLD') && isUnique) ? 'DRAFT' : undefined;
|
|
339
345
|
if (variantsFromInventory.length === 0) {
|
|
340
346
|
// Fallback: single-variant product (legacy behavior)
|
|
341
347
|
const variant = Object.assign(Object.assign({ id: '' }, baseVariantFields()), { inventoryQuantities: [
|
|
@@ -377,7 +383,7 @@ class Product extends Base_1.default {
|
|
|
377
383
|
values: Array.from(axisValuesMap[axis] || new Set()).map((name) => ({ name })),
|
|
378
384
|
}));
|
|
379
385
|
const variants = variantsFromInventory.map((v) => {
|
|
380
|
-
var _a, _b, _c, _d, _e
|
|
386
|
+
var _a, _b, _c, _d, _e;
|
|
381
387
|
const optionValues = limitedAxes.map((axis) => ({
|
|
382
388
|
optionName: axis,
|
|
383
389
|
name: String(v.options[axis] || ''),
|
|
@@ -425,9 +431,9 @@ class Product extends Base_1.default {
|
|
|
425
431
|
variant.compareAtPrice = ((_c = v.compareAtPrice) !== null && _c !== void 0 ? _c : basePrice);
|
|
426
432
|
const onSale = ((_d = v.isOnSale) !== null && _d !== void 0 ? _d : this.consignmentAttributes.isOnSale);
|
|
427
433
|
const salePrice = ((_e = v.salePrice) !== null && _e !== void 0 ? _e : this.consignmentAttributes.salePrice);
|
|
428
|
-
if (salePrice &&
|
|
434
|
+
if (salePrice && onSale === 'yes') {
|
|
429
435
|
variant.price = salePrice;
|
|
430
|
-
variant.compareAtPrice =
|
|
436
|
+
variant.compareAtPrice = basePrice;
|
|
431
437
|
}
|
|
432
438
|
return variant;
|
|
433
439
|
});
|
|
@@ -1740,18 +1740,29 @@ type ShopifyOrdersCreateRefund = {
|
|
|
1740
1740
|
refund_line_items: ShopifyOrdersCreateRefundLineItem[];
|
|
1741
1741
|
};
|
|
1742
1742
|
type GadgetRefundLineItem = {
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
product_id?: string | number;
|
|
1746
|
-
};
|
|
1743
|
+
id?: string | number;
|
|
1744
|
+
line_item_id?: string | number;
|
|
1747
1745
|
quantity: number;
|
|
1748
1746
|
location_id?: string | number | null;
|
|
1747
|
+
restock_type?: string;
|
|
1749
1748
|
subtotal?: string | number;
|
|
1749
|
+
subtotal_set?: MoneyBagRest;
|
|
1750
|
+
total_tax?: string | number;
|
|
1751
|
+
total_tax_set?: MoneyBagRest;
|
|
1752
|
+
line_item?: GadgetLineItem & {
|
|
1753
|
+
id?: string | number;
|
|
1754
|
+
admin_graphql_api_id?: string;
|
|
1755
|
+
};
|
|
1750
1756
|
};
|
|
1751
1757
|
type GadgetRefund = {
|
|
1752
1758
|
id: string | number;
|
|
1753
1759
|
created_at?: string;
|
|
1760
|
+
processed_at?: string;
|
|
1754
1761
|
note?: string;
|
|
1762
|
+
order_id?: string | number;
|
|
1763
|
+
user_id?: string | number;
|
|
1764
|
+
restock?: boolean;
|
|
1765
|
+
total_duties_set?: MoneyBagRest;
|
|
1755
1766
|
order_adjustments: any[];
|
|
1756
1767
|
transactions: any[];
|
|
1757
1768
|
refund_line_items: GadgetRefundLineItem[];
|
|
@@ -1760,10 +1771,30 @@ type GadgetLineItem = {
|
|
|
1760
1771
|
title: string;
|
|
1761
1772
|
quantity: number;
|
|
1762
1773
|
variant_id?: string | number | null;
|
|
1763
|
-
variant_title?: string;
|
|
1774
|
+
variant_title?: string | null;
|
|
1764
1775
|
product_id?: string | number | null;
|
|
1765
1776
|
price_set?: MoneyBagRest;
|
|
1766
1777
|
total_discount_set?: MoneyBagRest;
|
|
1778
|
+
id?: string | number;
|
|
1779
|
+
admin_graphql_api_id?: string;
|
|
1780
|
+
current_quantity?: number;
|
|
1781
|
+
fulfillable_quantity?: number;
|
|
1782
|
+
fulfillment_service?: string | null;
|
|
1783
|
+
fulfillment_status?: string | null;
|
|
1784
|
+
gift_card?: boolean;
|
|
1785
|
+
grams?: number;
|
|
1786
|
+
name?: string;
|
|
1787
|
+
price?: number | string;
|
|
1788
|
+
product_exists?: boolean;
|
|
1789
|
+
requires_shipping?: boolean;
|
|
1790
|
+
sales_line_item_group_id?: number | string | null;
|
|
1791
|
+
sku?: string | null;
|
|
1792
|
+
taxable?: boolean;
|
|
1793
|
+
total_discount?: number | string;
|
|
1794
|
+
variant_inventory_management?: string | null;
|
|
1795
|
+
vendor?: string;
|
|
1796
|
+
discount_allocations?: DiscountAllocationRest[];
|
|
1797
|
+
tax_lines?: TaxLineRest[];
|
|
1767
1798
|
};
|
|
1768
1799
|
type GadgetTaxLine = {
|
|
1769
1800
|
price: string | number;
|
|
@@ -1772,12 +1803,19 @@ type GadgetTaxLine = {
|
|
|
1772
1803
|
};
|
|
1773
1804
|
type GadgetFulfillment = {
|
|
1774
1805
|
id: string | number;
|
|
1806
|
+
admin_graphql_api_id?: string;
|
|
1775
1807
|
created_at: string;
|
|
1776
1808
|
updated_at?: string;
|
|
1777
1809
|
name: string;
|
|
1778
|
-
|
|
1779
|
-
|
|
1810
|
+
location_id?: string | number;
|
|
1811
|
+
order_id?: string | number;
|
|
1812
|
+
service?: string | null;
|
|
1813
|
+
shipment_status?: string | null;
|
|
1814
|
+
status?: string | null;
|
|
1815
|
+
tracking_company?: string | null;
|
|
1816
|
+
tracking_number?: string | number | null;
|
|
1780
1817
|
tracking_numbers?: (string | number)[];
|
|
1818
|
+
tracking_url?: string | null;
|
|
1781
1819
|
tracking_urls?: string[];
|
|
1782
1820
|
line_items?: GadgetLineItem[];
|
|
1783
1821
|
};
|