rerobe-js-orm 4.9.5 → 4.9.7

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.
@@ -693,11 +693,12 @@ class OrderHelpers {
693
693
  }
694
694
  let info = additionalInfo;
695
695
  // Derive the return-policy line from the structured policy for the order's
696
- // sales channel (legacy free-text policies pass through unchanged). Never
697
- // shown on refund receipts.
696
+ // sales channel, localized to the receipt's presentment locale (legacy
697
+ // free-text policies pass through unchanged). Never shown on refund receipts.
698
+ const returnPolicyTemplate = translations_1.returnPolicyReceiptTranslations[presentmentLocale] || translations_1.returnPolicyReceiptTranslations['en-US'];
698
699
  const returnPolicyText = isRefund
699
700
  ? ''
700
- : ReturnPolicyHelpers_1.default.returnPolicyReceiptText(returnPolicy, (_d = order.salesChannel) !== null && _d !== void 0 ? _d : undefined);
701
+ : ReturnPolicyHelpers_1.default.returnPolicyReceiptText(returnPolicy, (_d = order.salesChannel) !== null && _d !== void 0 ? _d : undefined, returnPolicyTemplate);
701
702
  if (returnPolicyText) {
702
703
  info = returnPolicyText;
703
704
  if (additionalInfo) {
@@ -17,20 +17,23 @@ export default class ReturnPolicyHelpers {
17
17
  withinWindow: string;
18
18
  };
19
19
  private static normChannel;
20
+ private static effectiveWindowDays;
20
21
  static parse(raw: any): ReturnPolicy | null;
21
22
  static isConfigured(raw: any): boolean;
22
23
  static defaultPolicy(): ReturnPolicy;
23
24
  static channelKeyForSalesChannel(salesChannel: string): string | null;
24
25
  static getChannelPolicy(raw: any, salesChannel: string): ReturnPolicyChannel | null;
25
26
  static resolveSoldState(raw: any, salesChannel: string): string;
27
+ static getEffectiveWindowDays(raw: any, salesChannel: string): number;
26
28
  static getReturnWindowEndMillis(raw: any, salesChannel: string, soldAtMillis: number): number | null;
29
+ static getPayoutClearanceMillis(raw: any, salesChannel: string, soldAtMillis: number): number | null;
27
30
  static evaluateReturn({ raw, salesChannel, soldAtMillis, nowMillis, }: {
28
31
  raw: any;
29
32
  salesChannel: string;
30
33
  soldAtMillis?: number;
31
34
  nowMillis?: number;
32
35
  }): ReturnEvaluation;
33
- static returnPolicyReceiptText(raw: any, salesChannel?: string): string;
36
+ static returnPolicyReceiptText(raw: any, salesChannel?: string, template?: string): string;
34
37
  static resolveEffectiveReturnPolicy({ ownPolicyRaw, marketplaceDefaultRaw, isManaged, }: {
35
38
  ownPolicyRaw?: any;
36
39
  marketplaceDefaultRaw?: any;
@@ -36,10 +36,20 @@ class ReturnPolicyHelpers {
36
36
  return { allowed: false, returnPeriodDays: 0 };
37
37
  }
38
38
  const days = Number(ch.returnPeriodDays);
39
- return {
39
+ const buffer = Number(ch.bufferDays);
40
+ const out = {
40
41
  allowed: ch.allowed !== false,
41
42
  returnPeriodDays: days > 0 ? Math.floor(days) : 0,
42
43
  };
44
+ // Only persist a buffer when set, so existing no-buffer policies serialize
45
+ // (and compare) unchanged.
46
+ if (buffer > 0)
47
+ out.bufferDays = Math.floor(buffer);
48
+ return out;
49
+ }
50
+ // Total payout-hold days for a channel = nominal return period + buffer.
51
+ static effectiveWindowDays(channel) {
52
+ return (channel.returnPeriodDays || 0) + (channel.bufferDays || 0);
43
53
  }
44
54
  // Parse a raw stored value into a structured ReturnPolicy, or null when the
45
55
  // merchant has not configured a (structured) policy. Returns null for:
@@ -102,6 +112,14 @@ class ReturnPolicyHelpers {
102
112
  }
103
113
  // The instant (ms) a return window closes for a sale, or null when there's no
104
114
  // applicable window (no policy / not allowed / 0-day / no sale time).
115
+ // Effective window length (days) for a sale's channel, including the buffer.
116
+ // 0 when the channel has no allowed window.
117
+ static getEffectiveWindowDays(raw, salesChannel) {
118
+ const channel = this.getChannelPolicy(raw, salesChannel);
119
+ if (!channel || !channel.allowed || channel.returnPeriodDays <= 0)
120
+ return 0;
121
+ return this.effectiveWindowDays(channel);
122
+ }
105
123
  static getReturnWindowEndMillis(raw, salesChannel, soldAtMillis) {
106
124
  const channel = this.getChannelPolicy(raw, salesChannel);
107
125
  if (!channel || !channel.allowed || channel.returnPeriodDays <= 0)
@@ -109,7 +127,13 @@ class ReturnPolicyHelpers {
109
127
  const soldAt = Number(soldAtMillis);
110
128
  if (!(soldAt > 0))
111
129
  return null;
112
- return soldAt + channel.returnPeriodDays * MS_PER_DAY;
130
+ return soldAt + this.effectiveWindowDays(channel) * MS_PER_DAY;
131
+ }
132
+ // The instant (ms) the seller payout becomes safe to release for a windowed
133
+ // SOLD item — return period + buffer from the sale. Same value as the window
134
+ // end; named for the payout-clearance caller. Null when there's no window.
135
+ static getPayoutClearanceMillis(raw, salesChannel, soldAtMillis) {
136
+ return this.getReturnWindowEndMillis(raw, salesChannel, soldAtMillis);
113
137
  }
114
138
  // Evaluate whether a return/refund should be permitted under the policy.
115
139
  // Conservative by design: when nothing is configured (no policy, unmapped
@@ -133,7 +157,7 @@ class ReturnPolicyHelpers {
133
157
  const soldAt = Number(soldAtMillis);
134
158
  if (!(soldAt > 0))
135
159
  return { allowed: true, reason: REASONS.noSoldTimestamp };
136
- const windowEndMillis = soldAt + channel.returnPeriodDays * MS_PER_DAY;
160
+ const windowEndMillis = soldAt + this.effectiveWindowDays(channel) * MS_PER_DAY;
137
161
  const now = Number(nowMillis) > 0 ? Number(nowMillis) : Date.now();
138
162
  if (now <= windowEndMillis)
139
163
  return { allowed: true, reason: REASONS.withinWindow, windowEndMillis };
@@ -143,7 +167,12 @@ class ReturnPolicyHelpers {
143
167
  // unchanged. For a structured policy, prefer the sale's channel; without a
144
168
  // channel, summarize whichever channel(s) accept returns. Returns '' when
145
169
  // there's nothing meaningful to print (no policy, or returns not accepted).
146
- static returnPolicyReceiptText(raw, salesChannel) {
170
+ // `template` is a per-locale format string with a `{days}` placeholder, e.g.
171
+ // "{days} day return policy" / "{days} dagars öppet köp". Defaults to English
172
+ // so non-receipt callers (admin preview) need not pass one; the receipt
173
+ // builder passes the localized template. Legacy free-text policies pass
174
+ // through unchanged (can't be localized).
175
+ static returnPolicyReceiptText(raw, salesChannel, template = '{days} day return policy') {
147
176
  if (typeof raw === 'string')
148
177
  return raw.trim();
149
178
  const policy = this.parse(raw);
@@ -152,7 +181,7 @@ class ReturnPolicyHelpers {
152
181
  const lineFor = (ch) => {
153
182
  if (!ch || !ch.allowed || ch.returnPeriodDays <= 0)
154
183
  return '';
155
- return `${ch.returnPeriodDays} day return policy`;
184
+ return template.replace('{days}', String(ch.returnPeriodDays));
156
185
  };
157
186
  if (salesChannel) {
158
187
  const key = this.channelKeyForSalesChannel(salesChannel);
@@ -1,6 +1,9 @@
1
1
  export declare const receiptTranslations: {
2
2
  [key: string]: string;
3
3
  };
4
+ export declare const returnPolicyReceiptTranslations: {
5
+ [key: string]: string;
6
+ };
4
7
  export declare const totalTranslations: {
5
8
  [key: string]: string;
6
9
  };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.originalReceiptTranslations = exports.refundPurchaseTranslations = exports.refundReceiptTranslations = exports.referenceTranslations = exports.contactlessTranslations = exports.authorizationCodeTranslations = exports.mobilePaymentTranslations = exports.cardPaymentTranslations = exports.cashTranslations = exports.purchaseTranslations = exports.taxTranslations = exports.totalTranslations = exports.receiptTranslations = void 0;
3
+ exports.originalReceiptTranslations = exports.refundPurchaseTranslations = exports.refundReceiptTranslations = exports.referenceTranslations = exports.contactlessTranslations = exports.authorizationCodeTranslations = exports.mobilePaymentTranslations = exports.cardPaymentTranslations = exports.cashTranslations = exports.purchaseTranslations = exports.taxTranslations = exports.totalTranslations = exports.returnPolicyReceiptTranslations = exports.receiptTranslations = void 0;
4
4
  exports.receiptTranslations = {
5
5
  'sv-SE': 'Kvitto',
6
6
  'nb-NO': 'Kvittering',
@@ -8,6 +8,16 @@ exports.receiptTranslations = {
8
8
  'en-UK': 'Receipt',
9
9
  'en-DE': 'Quittung',
10
10
  };
11
+ // Return-policy line on the receipt. `{days}` is replaced with the channel's
12
+ // returnPeriodDays. Localized per presentment locale (en-DE renders German,
13
+ // matching the other dicts).
14
+ exports.returnPolicyReceiptTranslations = {
15
+ 'sv-SE': '{days} dagars öppet köp',
16
+ 'nb-NO': '{days} dagers åpent kjøp',
17
+ 'en-US': '{days} day return policy',
18
+ 'en-UK': '{days} day return policy',
19
+ 'en-DE': '{days} Tage Rückgaberecht',
20
+ };
11
21
  exports.totalTranslations = {
12
22
  'sv-SE': 'Totalt',
13
23
  'nb-NO': 'Total',
@@ -9,6 +9,7 @@ type SocialLinksType = {
9
9
  type ReturnPolicyChannel = {
10
10
  allowed: boolean;
11
11
  returnPeriodDays: number;
12
+ bufferDays?: number;
12
13
  };
13
14
  type ReturnPolicy = {
14
15
  IN_STORE: ReturnPolicyChannel;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rerobe-js-orm",
3
- "version": "4.9.5",
3
+ "version": "4.9.7",
4
4
  "description": "ReRobe's Javascript ORM Framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",