rerobe-js-orm 4.8.3 → 4.8.5

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.
@@ -44,6 +44,10 @@ export namespace INDUSTRY_TYPES {
44
44
  let toys: string;
45
45
  let other: string;
46
46
  }
47
+ export const INDUSTRY_TYPE_OPTIONS: {
48
+ label: string;
49
+ value: string;
50
+ }[];
47
51
  export namespace UNIT_SYSTEM_TYPES {
48
52
  let metric: string;
49
53
  let imperial: string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AUTOMATED_PAYOUT_MONTH_DAYS = exports.AUTOMATED_PAYOUT_BUSINESS_DAYS = exports.AUTOMATED_PAYOUT_SCHEDULE = exports.SUBSCRIPTION_STATUSES = exports.RIBBN_WEBHOOK_EVENT_DICT = exports.IMPERIAL_WEIGHT_TYPES = exports.METRIC_WEIGHT_TYPES = exports.UNIT_SYSTEM_TYPES = exports.INDUSTRY_TYPES = exports.PAYMENT_TIERS = exports.MERCHANT_TYPES = void 0;
3
+ exports.AUTOMATED_PAYOUT_MONTH_DAYS = exports.AUTOMATED_PAYOUT_BUSINESS_DAYS = exports.AUTOMATED_PAYOUT_SCHEDULE = exports.SUBSCRIPTION_STATUSES = exports.RIBBN_WEBHOOK_EVENT_DICT = exports.IMPERIAL_WEIGHT_TYPES = exports.METRIC_WEIGHT_TYPES = exports.UNIT_SYSTEM_TYPES = exports.INDUSTRY_TYPE_OPTIONS = exports.INDUSTRY_TYPES = exports.PAYMENT_TIERS = exports.MERCHANT_TYPES = void 0;
4
4
  exports.MERCHANT_TYPES = {
5
5
  individual: 'INDIVIDUAL',
6
6
  business: 'BUSINESS',
@@ -37,6 +37,17 @@ exports.INDUSTRY_TYPES = {
37
37
  toys: 'TOYS',
38
38
  other: 'OTHER',
39
39
  };
40
+ exports.INDUSTRY_TYPE_OPTIONS = [
41
+ { label: 'Beauty & Cosmetics', value: exports.INDUSTRY_TYPES.beauty },
42
+ { label: 'Clothing & Apparel', value: exports.INDUSTRY_TYPES.clothing },
43
+ { label: 'Electronics', value: exports.INDUSTRY_TYPES.electronics },
44
+ { label: 'Furniture & Home', value: exports.INDUSTRY_TYPES.furniture },
45
+ { label: 'Handcrafts & Artisan', value: exports.INDUSTRY_TYPES.handcrafts },
46
+ { label: 'Jewelry & Watches', value: exports.INDUSTRY_TYPES.jewelry },
47
+ { label: 'Sports & Outdoors', value: exports.INDUSTRY_TYPES.sports },
48
+ { label: 'Toys & Games', value: exports.INDUSTRY_TYPES.toys },
49
+ { label: 'Other', value: exports.INDUSTRY_TYPES.other },
50
+ ];
40
51
  exports.UNIT_SYSTEM_TYPES = {
41
52
  metric: 'METRIC',
42
53
  imperial: 'IMPERIAL',
@@ -580,7 +580,7 @@ class OrderHelpers {
580
580
  };
581
581
  }
582
582
  buildReceiptObjFromOrder({ order, merchant, merchantLogoUrl = '', receiptNumber = '', additionalInfo = '', isRefund = false, refundId = null, originalReceiptNumber = null, }) {
583
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
583
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
584
584
  const { address: merchantAddress, legalName, name, contactEmail, phone = '', organizationNumber = '', primaryDomain, currency: storeCurrencyCode, returnPolicy, } = merchant;
585
585
  const currencyCode = ((_a = order.totalPricePresentment) === null || _a === void 0 ? void 0 : _a.currencyCode) || storeCurrencyCode;
586
586
  const presentmentLocale = (0, Utilities_1.getPresentmentLocaleByCurrencyCode)(currencyCode);
@@ -689,7 +689,7 @@ class OrderHelpers {
689
689
  const num = Number(amount);
690
690
  return isNaN(num) ? amount : -Math.abs(num);
691
691
  };
692
- return Object.assign(Object.assign({ merchantLogoUrl, merchantName: name, legalName, storeAddress: buildStoreAddress(), phone,
692
+ return Object.assign(Object.assign(Object.assign({ merchantLogoUrl, merchantName: name, legalName, storeAddress: buildStoreAddress(), phone,
693
693
  contactEmail,
694
694
  organizationNumber,
695
695
  primaryDomain, storeUrl: `https://${primaryDomain}`, orderDate: (0, Utilities_1.getFormattedTimestamp)(presentmentLocale, order === null || order === void 0 ? void 0 : order.createdAtTimestamp), receiptNumber, additionalInfo: info, isRefund, originalReceiptNumber: originalReceiptNumber || null, originalReceiptLabel: translations_1.originalReceiptTranslations[presentmentLocale] || translations_1.originalReceiptTranslations['en-US'], lineItems: buildLineItems(), subTotal: (0, Utilities_1.formatPrice)({
@@ -708,7 +708,30 @@ class OrderHelpers {
708
708
  currencyCode,
709
709
  amount: (_q = negateForRefund((_p = (_o = order.totalTaxPresentment) === null || _o === void 0 ? void 0 : _o.amount) !== null && _p !== void 0 ? _p : '')) !== null && _q !== void 0 ? _q : '',
710
710
  fractionDigits: 2,
711
- }), taxRates: formattedTaxRates }, paymentTerminalInfo), receiptLabels);
711
+ }), taxRates: formattedTaxRates }, paymentTerminalInfo), receiptLabels), (Number(((_r = order.totalRefundedPresentment) === null || _r === void 0 ? void 0 : _r.amount) || 0) > 0 && {
712
+ totalRefunded: (0, Utilities_1.formatPrice)({
713
+ currencyCode,
714
+ amount: (_t = (_s = order.totalRefundedPresentment) === null || _s === void 0 ? void 0 : _s.amount) !== null && _t !== void 0 ? _t : '',
715
+ fractionDigits: 2,
716
+ }),
717
+ netPayment: (0, Utilities_1.formatPrice)({
718
+ currencyCode,
719
+ amount: Number((_v = (_u = order.totalPricePresentment) === null || _u === void 0 ? void 0 : _u.amount) !== null && _v !== void 0 ? _v : 0) - Number((_x = (_w = order.totalRefundedPresentment) === null || _w === void 0 ? void 0 : _w.amount) !== null && _x !== void 0 ? _x : 0),
720
+ fractionDigits: 2,
721
+ }),
722
+ refundLineItems: (order.refunds || []).flatMap((refund) => (refund.refundLineItems || []).map((item) => {
723
+ var _a, _b;
724
+ return ({
725
+ title: item.title || '',
726
+ quantity: item.quantity || 1,
727
+ price: (0, Utilities_1.formatPrice)({
728
+ currencyCode,
729
+ amount: -Number(((_a = item.presentmentTotalPrice) === null || _a === void 0 ? void 0 : _a.amount) || ((_b = item.totalPrice) === null || _b === void 0 ? void 0 : _b.amount) || 0),
730
+ fractionDigits: 2,
731
+ }),
732
+ });
733
+ })),
734
+ }));
712
735
  }
713
736
  /**
714
737
  * Generates an idempotency key from a ReRobeOrderObj to prevent duplicate order creation
@@ -11,7 +11,14 @@ export default class Product extends Base {
11
11
  toObj(): CompleteProduct;
12
12
  toProductInputObjForShopify(location?: string): any;
13
13
  toProductInputObjForShopifyV2(locationId: string, weightUnit?: string): any[];
14
- toProductInputObjForShopifyV3(locationId: string, weightUnit?: string, taxRate?: number): {
14
+ /**
15
+ * Builds a Shopify product input object for a product with variant inventory.
16
+ * @param locationsMap { RibbnLocationID => ShopifyLocation GUID } - Map of locationId to location Shopify ID
17
+ * @param weightUnit
18
+ * @param taxRate
19
+ * @returns
20
+ */
21
+ toProductInputObjForShopifyV3(locationsInput: Map<string, string> | string, weightUnit?: string, taxRate?: number): {
15
22
  productOptions: {
16
23
  name: string;
17
24
  values: {
@@ -296,8 +296,18 @@ class Product extends Base_1.default {
296
296
  }
297
297
  return [productInputObj];
298
298
  }
299
- toProductInputObjForShopifyV3(locationId, weightUnit, taxRate) {
299
+ /**
300
+ * Builds a Shopify product input object for a product with variant inventory.
301
+ * @param locationsMap { RibbnLocationID => ShopifyLocation GUID } - Map of locationId to location Shopify ID
302
+ * @param weightUnit
303
+ * @param taxRate
304
+ * @returns
305
+ */
306
+ toProductInputObjForShopifyV3(locationsInput, weightUnit, taxRate) {
300
307
  var _a;
308
+ const isLegacy = typeof locationsInput === 'string';
309
+ const legacyGid = isLegacy ? `gid://shopify/Location/${locationsInput}` : undefined;
310
+ const locationsMap = isLegacy ? undefined : locationsInput;
301
311
  const title = this.attributes.title || `Ribbn Product ${this.attributes.handle || this.filterAttributes.documentId}`;
302
312
  const inInventoryStatuses = [
303
313
  product_constants_1.PRODUCT_STATES.draft,
@@ -369,7 +379,7 @@ class Product extends Base_1.default {
369
379
  // Fallback: single-variant product (legacy behavior)
370
380
  const variant = Object.assign(Object.assign({ id: '' }, baseVariantFields()), { inventoryQuantities: [
371
381
  {
372
- locationId: `gid://shopify/Location/${locationId}`,
382
+ locationId: isLegacy ? legacyGid : locationsMap.get(this.consignmentAttributes.inventoryLocations[0].id),
373
383
  name: 'available',
374
384
  quantity: 0,
375
385
  },
@@ -415,16 +425,24 @@ class Product extends Base_1.default {
415
425
  name: String(v.options[axis] || ''),
416
426
  }));
417
427
  const inventoryQuantities = Array.isArray(v.locations) && v.locations.length > 0
418
- ? [
419
- {
420
- locationId: `gid://shopify/Location/${locationId}`,
428
+ ? isLegacy
429
+ ? [
430
+ {
431
+ locationId: legacyGid,
432
+ name: 'available',
433
+ quantity: (v.locations || []).reduce((acc, l) => acc + (Number(l === null || l === void 0 ? void 0 : l.availableAmount) || 0), 0),
434
+ },
435
+ ]
436
+ : v.locations.map((location) => ({
437
+ locationId: locationsMap.get(location.id),
421
438
  name: 'available',
422
- quantity: (v.locations || []).reduce((acc, l) => acc + (Number(l === null || l === void 0 ? void 0 : l.availableAmount) || 0), 0),
423
- },
424
- ]
439
+ quantity: location.availableAmount,
440
+ }))
425
441
  : [
426
442
  {
427
- locationId: `gid://shopify/Location/${locationId}`,
443
+ locationId: isLegacy
444
+ ? legacyGid
445
+ : locationsMap.get(this.consignmentAttributes.inventoryLocations[0].id),
428
446
  name: 'available',
429
447
  quantity: inInventoryStatuses.indexOf(this.consignmentAttributes.status) !== -1 ? 1 : 0,
430
448
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rerobe-js-orm",
3
- "version": "4.8.3",
3
+ "version": "4.8.5",
4
4
  "description": "ReRobe's Javascript ORM Framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",