rerobe-js-orm 4.9.5 → 4.9.6

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.
@@ -17,13 +17,16 @@ 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;
@@ -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 };
@@ -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.6",
4
4
  "description": "ReRobe's Javascript ORM Framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",