rerobe-js-orm 4.6.1 → 4.6.3

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.
@@ -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, current_subtotal_price_set, current_total_price_set, current_total_tax_set, current_total_discounts_set, current_shipping_price_set, } = 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,
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
- title: item.title,
426
- quantity: item.quantity,
427
- variant: {
428
- id: '',
429
- shopifyId: item.variant_id ? `gid://shopify/ProductVariant/${item.variant_id}` : '',
430
- title: item.variant_title || '',
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
- shopifyProductId: item.product_id ? `gid://shopify/Product/${item.product_id}` : null,
434
- originalTotalPrice: moneyFromSet(item.price_set),
435
- discountedTotalPrice: moneyFromSet(item.total_discount_set),
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() : '',
@@ -135,4 +135,5 @@ export default class Order extends Base {
135
135
  name: string;
136
136
  };
137
137
  toObjForTypesense(): TypesenseOrderObj;
138
+ toOrderInputObj(): any;
138
139
  }
@@ -430,6 +430,66 @@ 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: item.shopifyVariantId ||
446
+ ((_a = item.variant) === null || _a === void 0 ? void 0 : _a.shopifyId) ||
447
+ item.shopifyProductId ||
448
+ ((_b = item.variant) === null || _b === void 0 ? void 0 : _b.id) ||
449
+ '',
450
+ });
451
+ });
452
+ const tagsArray = Array.isArray(this.tags)
453
+ ? this.tags
454
+ : typeof this.tags === 'string' && this.tags
455
+ ? String(this.tags)
456
+ .split(',')
457
+ .map((t) => t.trim())
458
+ .filter(Boolean)
459
+ : [];
460
+ const ribbnTag = 'source:ribbn';
461
+ if (!tagsArray.includes(ribbnTag)) {
462
+ tagsArray.push(ribbnTag);
463
+ }
464
+ const shippingAddress = this.shippingAddress
465
+ ? {
466
+ address1: this.shippingAddress.address1 || '',
467
+ address2: this.shippingAddress.address2 || '',
468
+ city: this.shippingAddress.city || '',
469
+ country: this.shippingAddress.country || this.shippingAddress.countryCode || '',
470
+ province: this.shippingAddress.province || '',
471
+ zip: this.shippingAddress.zip || '',
472
+ }
473
+ : undefined;
474
+ const shippingLine = this.shippingLine
475
+ ? {
476
+ title: this.shippingLine.title || 'Shipping fee',
477
+ 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),
478
+ }
479
+ : undefined;
480
+ const orderInput = {
481
+ email: this.email || undefined,
482
+ phone: this.phone || undefined,
483
+ note: this.notes || undefined,
484
+ tags: tagsArray,
485
+ lineItems,
486
+ shippingAddress,
487
+ shippingLine,
488
+ };
489
+ // Remove undefined props to match GraphQL input expectations
490
+ Object.keys(orderInput).forEach((k) => orderInput[k] === undefined && delete orderInput[k]);
491
+ return orderInput;
492
+ }
433
493
  }
434
494
  Order.SHIPPING_TYPES = order_constants_1.SHIPPING_TYPES;
435
495
  Order.PAYMENT_TYPES = order_constants_1.PAYMENT_TYPES;
@@ -383,7 +383,7 @@ class Product extends Base_1.default {
383
383
  values: Array.from(axisValuesMap[axis] || new Set()).map((name) => ({ name })),
384
384
  }));
385
385
  const variants = variantsFromInventory.map((v) => {
386
- var _a, _b, _c, _d, _e, _f, _g;
386
+ var _a, _b, _c, _d, _e;
387
387
  const optionValues = limitedAxes.map((axis) => ({
388
388
  optionName: axis,
389
389
  name: String(v.options[axis] || ''),
@@ -431,9 +431,9 @@ class Product extends Base_1.default {
431
431
  variant.compareAtPrice = ((_c = v.compareAtPrice) !== null && _c !== void 0 ? _c : basePrice);
432
432
  const onSale = ((_d = v.isOnSale) !== null && _d !== void 0 ? _d : this.consignmentAttributes.isOnSale);
433
433
  const salePrice = ((_e = v.salePrice) !== null && _e !== void 0 ? _e : this.consignmentAttributes.salePrice);
434
- if (salePrice && Boolean(this.timestampAttributes.clearanceTimestamp) && onSale === 'yes') {
434
+ if (salePrice && onSale === 'yes') {
435
435
  variant.price = salePrice;
436
- variant.compareAtPrice = ((_g = (_f = v.compareAtPrice) !== null && _f !== void 0 ? _f : this.attributes.price) !== null && _g !== void 0 ? _g : basePrice);
436
+ variant.compareAtPrice = basePrice;
437
437
  }
438
438
  return variant;
439
439
  });
@@ -1740,18 +1740,29 @@ type ShopifyOrdersCreateRefund = {
1740
1740
  refund_line_items: ShopifyOrdersCreateRefundLineItem[];
1741
1741
  };
1742
1742
  type GadgetRefundLineItem = {
1743
- line_item?: {
1744
- price?: string | number;
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
- status?: string;
1779
- tracking_company?: string;
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
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rerobe-js-orm",
3
- "version": "4.6.1",
3
+ "version": "4.6.3",
4
4
  "description": "ReRobe's Javascript ORM Framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",