@questwork/q-store-model 0.1.44 → 0.2.1
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/dist/q-store-model.cjs +2 -2
- package/dist/q-store-model.esm.js +1588 -1162
- package/dist/q-store-model.iife.js +2 -2
- package/dist/q-store-model.umd.js +2 -2
- package/dist/v2/evaluation/acquisition.d.ts +48 -0
- package/dist/v2/evaluation/effectiveRules.d.ts +7 -0
- package/dist/v2/evaluation/index.d.ts +4 -0
- package/dist/v2/evaluation/ruleEvaluators.d.ts +48 -0
- package/dist/v2/evaluation/shared.d.ts +28 -0
- package/dist/v2/index.d.ts +11 -0
- package/dist/v2/internal/StoreContract.d.ts +10 -0
- package/dist/v2/internal/StoreContractValidationError.d.ts +9 -0
- package/dist/v2/internal/StoreEntity.d.ts +12 -0
- package/dist/v2/internal/validation.d.ts +12 -0
- package/dist/v2/models/AcquisitionSnapshot.d.ts +5 -0
- package/dist/v2/models/Category.d.ts +5 -0
- package/dist/v2/models/Currency.d.ts +5 -0
- package/dist/v2/models/EligibilityFact.d.ts +4 -0
- package/dist/v2/models/Merchandise.d.ts +5 -0
- package/dist/v2/models/MerchandiseComponent.d.ts +4 -0
- package/dist/v2/models/PriceEvaluationContext.d.ts +4 -0
- package/dist/v2/models/PriceMatchCriteria.d.ts +4 -0
- package/dist/v2/models/PriceRow.d.ts +4 -0
- package/dist/v2/models/PriceSchedule.d.ts +5 -0
- package/dist/v2/models/PriceScheduleRef.d.ts +4 -0
- package/dist/v2/models/Product.d.ts +5 -0
- package/dist/v2/models/PublishedRule.d.ts +5 -0
- package/dist/v2/models/PublishedRuleRef.d.ts +4 -0
- package/dist/v2/models/RefundPolicy.d.ts +5 -0
- package/dist/v2/models/RefundPolicyRef.d.ts +4 -0
- package/dist/v2/models/RequirementPlan.d.ts +4 -0
- package/dist/v2/models/SalesPeriod.d.ts +5 -0
- package/dist/v2/models/SalesPeriodRef.d.ts +4 -0
- package/dist/v2/models/Variant.d.ts +5 -0
- package/dist/v2/models/VariantRef.d.ts +4 -0
- package/dist/v2/models/WalletItem.d.ts +5 -0
- package/dist/v2/models/index.d.ts +24 -0
- package/dist/v2/models/ruleDetails/EligibilityRuleDetails.d.ts +4 -0
- package/dist/v2/models/ruleDetails/InventoryRuleDetails.d.ts +4 -0
- package/dist/v2/models/ruleDetails/PrerequisiteRuleDetails.d.ts +4 -0
- package/dist/v2/models/ruleDetails/QuantityRuleDetails.d.ts +4 -0
- package/dist/v2/models/ruleDetails/RefundRuleDetails.d.ts +4 -0
- package/dist/v2/models/ruleDetails/RequirementDefinition.d.ts +4 -0
- package/dist/v2/models/ruleDetails/RequirementFieldDefinition.d.ts +4 -0
- package/dist/v2/models/ruleDetails/RequirementRuleDetails.d.ts +4 -0
- package/dist/v2/models/ruleDetails/index.d.ts +1 -0
- package/dist/v2/models/ruleDetails/shared.d.ts +8 -0
- package/dist/v2/q-store-model-v2.cjs +2 -0
- package/dist/v2/q-store-model-v2.esm.js +1855 -0
- package/dist/v2/ruleVocabulary.d.ts +75 -0
- package/package.json +14 -6
|
@@ -0,0 +1,1855 @@
|
|
|
1
|
+
import { TenantAwareEntity as Ke } from "@questwork/q-utilities";
|
|
2
|
+
class G extends Error {
|
|
3
|
+
constructor({ contractName: o, issues: e }) {
|
|
4
|
+
super(`${o} is invalid: ${e.join("; ")}`), this.name = "StoreContractValidationError", this.code = "STORE_CONTRACT_INVALID", this.contractName = o, this.issues = [...e];
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
const We = ["boolean", "number", "string"];
|
|
8
|
+
function D(n, o = "value") {
|
|
9
|
+
if (n === null)
|
|
10
|
+
return null;
|
|
11
|
+
if (Array.isArray(n))
|
|
12
|
+
return n.map((e, t) => D(e, `${o}[${t}]`));
|
|
13
|
+
if (We.includes(typeof n)) {
|
|
14
|
+
if (typeof n == "number" && !Number.isFinite(n))
|
|
15
|
+
throw new TypeError(`${o} must be a finite number`);
|
|
16
|
+
return n;
|
|
17
|
+
}
|
|
18
|
+
if (typeof n == "object" && Object.getPrototypeOf(n) === Object.prototype)
|
|
19
|
+
return Object.fromEntries(Object.entries(n).map(([e, t]) => {
|
|
20
|
+
if (typeof t > "u")
|
|
21
|
+
throw new TypeError(`${o}.${e} must not be undefined`);
|
|
22
|
+
return [e, D(t, `${o}.${e}`)];
|
|
23
|
+
}));
|
|
24
|
+
throw new TypeError(`${o} must contain JSON-safe values only`);
|
|
25
|
+
}
|
|
26
|
+
function q(n) {
|
|
27
|
+
return n && typeof n == "object" && !Object.isFrozen(n) && (Object.values(n).forEach(q), Object.freeze(n)), n;
|
|
28
|
+
}
|
|
29
|
+
function xe({ contractName: n, object: o, fields: e }) {
|
|
30
|
+
const t = Object.keys(o).filter((i) => !e.includes(i));
|
|
31
|
+
if (t.length > 0)
|
|
32
|
+
throw new G({
|
|
33
|
+
contractName: n,
|
|
34
|
+
issues: t.map((i) => `unknown field "${i}"`)
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
function u(n, o, e) {
|
|
38
|
+
return typeof n != "string" || n.trim().length === 0 ? (e.push(`${o} must be a non-empty string`), "") : n;
|
|
39
|
+
}
|
|
40
|
+
function M(n, o, e) {
|
|
41
|
+
if (!(typeof n > "u" || n === null))
|
|
42
|
+
return u(n, o, e);
|
|
43
|
+
}
|
|
44
|
+
function I(n, o, e, t = 1) {
|
|
45
|
+
return !Number.isInteger(n) || n < 1 ? (e.push(`${o} must be a positive integer`), t) : n;
|
|
46
|
+
}
|
|
47
|
+
function He(n, o, e, t = 0) {
|
|
48
|
+
return typeof n != "number" || !Number.isFinite(n) || n < 0 ? (e.push(`${o} must be a non-negative finite number`), t) : n;
|
|
49
|
+
}
|
|
50
|
+
function z(n, o, e) {
|
|
51
|
+
return Array.isArray(n) ? n.map((t, i) => u(t, `${o}[${i}]`, e)) : (e.push(`${o} must be an array`), []);
|
|
52
|
+
}
|
|
53
|
+
class T {
|
|
54
|
+
constructor({ contractName: o, object: e, fields: t, normalize: i }) {
|
|
55
|
+
if (!e || typeof e != "object" || Array.isArray(e))
|
|
56
|
+
throw new G({ contractName: o, issues: ["input must be an object"] });
|
|
57
|
+
xe({ contractName: o, object: e, fields: t });
|
|
58
|
+
const r = [], s = i(D(e), r);
|
|
59
|
+
if (r.length > 0)
|
|
60
|
+
throw new G({ contractName: o, issues: r });
|
|
61
|
+
Object.assign(this, q(s)), Object.freeze(this);
|
|
62
|
+
}
|
|
63
|
+
toObject() {
|
|
64
|
+
return D(Object.fromEntries(Object.entries(this)));
|
|
65
|
+
}
|
|
66
|
+
toJSON() {
|
|
67
|
+
return this.toObject();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
class Te extends T {
|
|
71
|
+
constructor(o = {}) {
|
|
72
|
+
super({
|
|
73
|
+
contractName: "PriceEvaluationContext",
|
|
74
|
+
object: o,
|
|
75
|
+
fields: ["acquisitionSource", "countryCode", "countryRank", "currency", "instant"],
|
|
76
|
+
normalize(e, t) {
|
|
77
|
+
const i = u(e.instant, "instant", t);
|
|
78
|
+
return i && !Number.isFinite(Date.parse(i)) && t.push("instant must be an ISO-compatible timestamp"), {
|
|
79
|
+
acquisitionSource: u(e.acquisitionSource, "acquisitionSource", t),
|
|
80
|
+
countryCode: u(e.countryCode, "countryCode", t),
|
|
81
|
+
countryRank: I(e.countryRank, "countryRank", t),
|
|
82
|
+
currency: u(e.currency, "currency", t),
|
|
83
|
+
instant: i
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
class ge extends T {
|
|
90
|
+
constructor(o = {}) {
|
|
91
|
+
super({
|
|
92
|
+
contractName: "PriceScheduleRef",
|
|
93
|
+
object: o,
|
|
94
|
+
fields: ["priceScheduleCode", "priceScheduleVersion"],
|
|
95
|
+
normalize(e, t) {
|
|
96
|
+
return {
|
|
97
|
+
priceScheduleCode: u(e.priceScheduleCode, "priceScheduleCode", t),
|
|
98
|
+
priceScheduleVersion: I(e.priceScheduleVersion, "priceScheduleVersion", t)
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const S = Object.freeze({
|
|
105
|
+
ELIGIBILITY: "ELIGIBILITY",
|
|
106
|
+
INVENTORY: "INVENTORY",
|
|
107
|
+
PREREQUISITE: "PREREQUISITE",
|
|
108
|
+
QUANTITY: "QUANTITY",
|
|
109
|
+
REFUND: "REFUND",
|
|
110
|
+
REQUIREMENT: "REQUIREMENT"
|
|
111
|
+
}), V = Object.freeze({
|
|
112
|
+
ACQUISITION_SOURCE: "ACQUISITION_SOURCE",
|
|
113
|
+
CATEGORY: "CATEGORY",
|
|
114
|
+
MERCHANDISE: "MERCHANDISE",
|
|
115
|
+
PRODUCT: "PRODUCT"
|
|
116
|
+
}), _ = Object.freeze({
|
|
117
|
+
CATEGORY: "CATEGORY",
|
|
118
|
+
MERCHANDISE: "MERCHANDISE",
|
|
119
|
+
PRODUCT: "PRODUCT"
|
|
120
|
+
}), K = Object.freeze({ ACTIVE: "ACTIVE", HOLDING: "HOLDING", ORDER: "ORDER" }), x = Object.freeze({
|
|
121
|
+
NOT_SUBMITTED: "NOT_SUBMITTED",
|
|
122
|
+
REJECTED: "REJECTED",
|
|
123
|
+
REVOKED: "REVOKED",
|
|
124
|
+
UNDER_REVIEW: "UNDER_REVIEW",
|
|
125
|
+
VALID: "VALID"
|
|
126
|
+
}), se = Object.freeze({
|
|
127
|
+
CAPACITY_ADMISSION: "CAPACITY_ADMISSION",
|
|
128
|
+
PRODUCTION_DEMAND: "PRODUCTION_DEMAND",
|
|
129
|
+
STOCKED_VARIANT: "STOCKED_VARIANT"
|
|
130
|
+
}), ce = Object.freeze({ ALL: "ALL", ANY: "ANY" }), k = Object.freeze({ EXISTING: "EXISTING", SAME_ORDER: "SAME_ORDER" }), de = Object.freeze({ BEFORE_ITEM_VALID: "BEFORE_ITEM_VALID" }), Q = Object.freeze({
|
|
131
|
+
ALWAYS: "ALWAYS",
|
|
132
|
+
LOCK_AFTER_COMPLETE: "LOCK_AFTER_COMPLETE",
|
|
133
|
+
UNTIL_DEADLINE: "UNTIL_DEADLINE"
|
|
134
|
+
}), ie = Object.freeze({
|
|
135
|
+
COMPLETE: "COMPLETE",
|
|
136
|
+
INCOMPLETE: "INCOMPLETE",
|
|
137
|
+
OVERDUE: "OVERDUE"
|
|
138
|
+
}), H = Object.freeze({
|
|
139
|
+
EDITABLE: "EDITABLE",
|
|
140
|
+
LOCKED: "LOCKED"
|
|
141
|
+
}), re = Object.freeze({
|
|
142
|
+
EMAIL: "email",
|
|
143
|
+
TEXT: "text",
|
|
144
|
+
VARIANT: "VARIANT"
|
|
145
|
+
}), P = Object.freeze({
|
|
146
|
+
CANCELLED: "CANCELLED",
|
|
147
|
+
EXPIRED: "EXPIRED",
|
|
148
|
+
PENDING_REQUIREMENT: "PENDING_REQUIREMENT",
|
|
149
|
+
REFUNDED: "REFUNDED",
|
|
150
|
+
RESERVED: "RESERVED",
|
|
151
|
+
REVOKED: "REVOKED",
|
|
152
|
+
VALID: "VALID"
|
|
153
|
+
});
|
|
154
|
+
class be extends T {
|
|
155
|
+
constructor(o = {}) {
|
|
156
|
+
super({
|
|
157
|
+
contractName: "RequirementFieldDefinition",
|
|
158
|
+
object: o,
|
|
159
|
+
fields: [
|
|
160
|
+
"autocomplete",
|
|
161
|
+
"deferredLabel",
|
|
162
|
+
"fieldCode",
|
|
163
|
+
"inputType",
|
|
164
|
+
"label",
|
|
165
|
+
"optionValueKey"
|
|
166
|
+
],
|
|
167
|
+
normalize(e, t) {
|
|
168
|
+
const i = u(e.inputType, "inputType", t);
|
|
169
|
+
Object.values(re).includes(i) || t.push(`inputType "${i}" is not supported`);
|
|
170
|
+
const r = M(e.autocomplete, "autocomplete", t), s = M(e.deferredLabel, "deferredLabel", t), c = M(e.optionValueKey, "optionValueKey", t);
|
|
171
|
+
return i === re.VARIANT && !c && t.push("optionValueKey is required when inputType is VARIANT"), i !== re.VARIANT && c && t.push("optionValueKey is only supported when inputType is VARIANT"), {
|
|
172
|
+
fieldCode: u(e.fieldCode, "fieldCode", t),
|
|
173
|
+
label: u(e.label, "label", t),
|
|
174
|
+
inputType: i,
|
|
175
|
+
...r ? { autocomplete: r } : {},
|
|
176
|
+
...s ? { deferredLabel: s } : {},
|
|
177
|
+
...c ? { optionValueKey: c } : {}
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
class X extends T {
|
|
184
|
+
constructor(o = {}) {
|
|
185
|
+
super({
|
|
186
|
+
contractName: "RequirementDefinition",
|
|
187
|
+
object: o,
|
|
188
|
+
fields: ["requirementCode", "label", "fields"],
|
|
189
|
+
normalize(e, t) {
|
|
190
|
+
const i = (Array.isArray(e.fields) ? e.fields : []).flatMap((s, c) => {
|
|
191
|
+
try {
|
|
192
|
+
return [(s instanceof be ? s : new be(s)).toObject()];
|
|
193
|
+
} catch (d) {
|
|
194
|
+
return t.push(`fields[${c}]: ${d.message}`), [];
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
Array.isArray(e.fields) || t.push("fields must be an array"), i.length === 0 && t.push("fields must contain at least one field");
|
|
198
|
+
const r = /* @__PURE__ */ new Set();
|
|
199
|
+
return i.forEach((s, c) => {
|
|
200
|
+
r.has(s.fieldCode) && t.push(`fields[${c}].fieldCode duplicates "${s.fieldCode}"`), r.add(s.fieldCode);
|
|
201
|
+
}), {
|
|
202
|
+
requirementCode: u(e.requirementCode, "requirementCode", t),
|
|
203
|
+
label: u(e.label, "label", t),
|
|
204
|
+
fields: i
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
function ze({ values: n, allowedValues: o, path: e, issues: t }) {
|
|
211
|
+
n.forEach((i) => {
|
|
212
|
+
o.includes(i) || t.push(`${e} contains unsupported value "${i}"`);
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
function Je(n, o, e, t) {
|
|
216
|
+
return !n || typeof n != "object" || Array.isArray(n) ? (e.push(`${o} must be an object`), {}) : new T({
|
|
217
|
+
contractName: o,
|
|
218
|
+
object: n,
|
|
219
|
+
fields: ["code", "type"],
|
|
220
|
+
normalize(r, s) {
|
|
221
|
+
const c = typeof r.type == "string" ? r.type : "", d = typeof r.code == "string" ? r.code : "";
|
|
222
|
+
return c.trim() || s.push("type must be a non-empty string"), d.trim() || s.push("code must be a non-empty string"), c && !t.includes(c) && s.push(`type "${c}" is not supported`), { type: c, code: d };
|
|
223
|
+
}
|
|
224
|
+
}).toObject();
|
|
225
|
+
}
|
|
226
|
+
function Z(n, o, e) {
|
|
227
|
+
if (!(typeof n > "u" || n === null || n === "")) {
|
|
228
|
+
if (typeof n != "string" || !Number.isFinite(Date.parse(n))) {
|
|
229
|
+
e.push(`${o} must be an ISO-8601 timestamp`);
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
return n;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
class ee extends T {
|
|
236
|
+
constructor(o = {}) {
|
|
237
|
+
super({
|
|
238
|
+
contractName: "RequirementPlan",
|
|
239
|
+
object: o,
|
|
240
|
+
fields: [
|
|
241
|
+
"complete",
|
|
242
|
+
"completionDeadline",
|
|
243
|
+
"completionTiming",
|
|
244
|
+
"componentIndex",
|
|
245
|
+
"missingFields",
|
|
246
|
+
"modificationDeadline",
|
|
247
|
+
"modificationMode",
|
|
248
|
+
"productCode",
|
|
249
|
+
"requirement",
|
|
250
|
+
"ruleCode",
|
|
251
|
+
"unitIndex",
|
|
252
|
+
"values"
|
|
253
|
+
],
|
|
254
|
+
normalize(e, t) {
|
|
255
|
+
let i = {};
|
|
256
|
+
try {
|
|
257
|
+
i = (e.requirement instanceof X ? e.requirement : new X(e.requirement)).toObject();
|
|
258
|
+
} catch (d) {
|
|
259
|
+
t.push(`requirement: ${d.message}`);
|
|
260
|
+
}
|
|
261
|
+
Object.values(de).includes(e.completionTiming) || t.push(`completionTiming "${e.completionTiming}" is not supported`), Object.values(Q).includes(e.modificationMode) || t.push(`modificationMode "${e.modificationMode}" is not supported`);
|
|
262
|
+
const r = Z(e.completionDeadline, "completionDeadline", t), s = Z(e.modificationDeadline, "modificationDeadline", t);
|
|
263
|
+
(!Number.isInteger(e.componentIndex) || e.componentIndex < 0) && t.push("componentIndex must be a non-negative integer"), (!Number.isInteger(e.unitIndex) || e.unitIndex < 0) && t.push("unitIndex must be a non-negative integer"), typeof e.complete != "boolean" && t.push("complete must be a boolean");
|
|
264
|
+
let c = {};
|
|
265
|
+
try {
|
|
266
|
+
!e.values || typeof e.values != "object" || Array.isArray(e.values) ? t.push("values must be an object") : c = D(e.values);
|
|
267
|
+
} catch (d) {
|
|
268
|
+
t.push(`values: ${d.message}`);
|
|
269
|
+
}
|
|
270
|
+
return {
|
|
271
|
+
ruleCode: u(e.ruleCode, "ruleCode", t),
|
|
272
|
+
requirement: i,
|
|
273
|
+
productCode: u(e.productCode, "productCode", t),
|
|
274
|
+
componentIndex: Number.isInteger(e.componentIndex) && e.componentIndex >= 0 ? e.componentIndex : 0,
|
|
275
|
+
unitIndex: Number.isInteger(e.unitIndex) && e.unitIndex >= 0 ? e.unitIndex : 0,
|
|
276
|
+
completionTiming: e.completionTiming,
|
|
277
|
+
modificationMode: e.modificationMode,
|
|
278
|
+
...r ? { completionDeadline: r } : {},
|
|
279
|
+
...s ? { modificationDeadline: s } : {},
|
|
280
|
+
values: c,
|
|
281
|
+
missingFields: z(e.missingFields || [], "missingFields", t),
|
|
282
|
+
complete: e.complete === !0
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
class Xe extends T {
|
|
289
|
+
constructor(o = {}) {
|
|
290
|
+
super({
|
|
291
|
+
contractName: "AcquisitionSnapshot",
|
|
292
|
+
object: o,
|
|
293
|
+
fields: [
|
|
294
|
+
"id",
|
|
295
|
+
"contractVersion",
|
|
296
|
+
"eventRegistrationCode",
|
|
297
|
+
"purchaserEventRegistrationCode",
|
|
298
|
+
"payerEventRegistrationCode",
|
|
299
|
+
"acquisitionSource",
|
|
300
|
+
"merchandise",
|
|
301
|
+
"quantity",
|
|
302
|
+
"products",
|
|
303
|
+
"priceScheduleRef",
|
|
304
|
+
"matchedPriceRow",
|
|
305
|
+
"priceEvaluationContext",
|
|
306
|
+
"effectiveRules",
|
|
307
|
+
"eligibilityDecisions",
|
|
308
|
+
"requirementPlans",
|
|
309
|
+
"inventoryDecisions",
|
|
310
|
+
"variantSelections",
|
|
311
|
+
"evaluated"
|
|
312
|
+
],
|
|
313
|
+
normalize(e, t) {
|
|
314
|
+
let i = {};
|
|
315
|
+
try {
|
|
316
|
+
i = (e.priceEvaluationContext instanceof Te ? e.priceEvaluationContext : new Te(e.priceEvaluationContext)).toObject();
|
|
317
|
+
} catch (c) {
|
|
318
|
+
t.push(`priceEvaluationContext: ${c.message}`);
|
|
319
|
+
}
|
|
320
|
+
let r = {};
|
|
321
|
+
try {
|
|
322
|
+
r = (e.priceScheduleRef instanceof ge ? e.priceScheduleRef : new ge(e.priceScheduleRef)).toObject();
|
|
323
|
+
} catch (c) {
|
|
324
|
+
t.push(`priceScheduleRef: ${c.message}`);
|
|
325
|
+
}
|
|
326
|
+
const s = (Array.isArray(e.requirementPlans) ? e.requirementPlans : []).flatMap((c, d) => {
|
|
327
|
+
try {
|
|
328
|
+
return [(c instanceof ee ? c : new ee(c)).toObject()];
|
|
329
|
+
} catch (a) {
|
|
330
|
+
return t.push(`requirementPlans[${d}]: ${a.message}`), [];
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
return Array.isArray(e.requirementPlans) || t.push("requirementPlans must be an array"), {
|
|
334
|
+
id: u(e.id, "id", t),
|
|
335
|
+
contractVersion: I(e.contractVersion, "contractVersion", t, 2),
|
|
336
|
+
eventRegistrationCode: u(e.eventRegistrationCode, "eventRegistrationCode", t),
|
|
337
|
+
purchaserEventRegistrationCode: u(
|
|
338
|
+
e.purchaserEventRegistrationCode,
|
|
339
|
+
"purchaserEventRegistrationCode",
|
|
340
|
+
t
|
|
341
|
+
),
|
|
342
|
+
payerEventRegistrationCode: u(
|
|
343
|
+
e.payerEventRegistrationCode,
|
|
344
|
+
"payerEventRegistrationCode",
|
|
345
|
+
t
|
|
346
|
+
),
|
|
347
|
+
acquisitionSource: u(e.acquisitionSource, "acquisitionSource", t),
|
|
348
|
+
merchandise: e.merchandise || {},
|
|
349
|
+
quantity: I(e.quantity, "quantity", t),
|
|
350
|
+
products: e.products || [],
|
|
351
|
+
priceScheduleRef: r,
|
|
352
|
+
matchedPriceRow: e.matchedPriceRow || {},
|
|
353
|
+
priceEvaluationContext: i,
|
|
354
|
+
effectiveRules: e.effectiveRules || {},
|
|
355
|
+
eligibilityDecisions: e.eligibilityDecisions || [],
|
|
356
|
+
requirementPlans: s,
|
|
357
|
+
inventoryDecisions: e.inventoryDecisions || [],
|
|
358
|
+
variantSelections: e.variantSelections || [],
|
|
359
|
+
evaluated: u(e.evaluated, "evaluated", t)
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
getId() {
|
|
365
|
+
return this.id;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
const Ze = [
|
|
369
|
+
"_id",
|
|
370
|
+
"_tenant",
|
|
371
|
+
"_type",
|
|
372
|
+
"id",
|
|
373
|
+
"meta",
|
|
374
|
+
"metadata",
|
|
375
|
+
"remarks",
|
|
376
|
+
"tenantCode"
|
|
377
|
+
], Ye = [
|
|
378
|
+
"active",
|
|
379
|
+
"created",
|
|
380
|
+
"creator",
|
|
381
|
+
"deleted",
|
|
382
|
+
"modified",
|
|
383
|
+
"owner",
|
|
384
|
+
"revision"
|
|
385
|
+
];
|
|
386
|
+
class L extends Ke {
|
|
387
|
+
constructor({ contractName: o, object: e, fields: t, normalize: i }) {
|
|
388
|
+
var l;
|
|
389
|
+
if (!e || typeof e != "object" || Array.isArray(e))
|
|
390
|
+
throw new G({ contractName: o, issues: ["input must be an object"] });
|
|
391
|
+
xe({ contractName: o, object: e, fields: [...Ze, ...t] });
|
|
392
|
+
const r = [], s = u(e.tenantCode, "tenantCode", r);
|
|
393
|
+
et(e.meta, r), Ne(e.metadata, "metadata", r), Ne(e.remarks, "remarks", r);
|
|
394
|
+
const c = D(Object.fromEntries(t.flatMap((f) => Object.hasOwn(e, f) ? [[f, e[f]]] : []))), d = i(c, r);
|
|
395
|
+
if (r.length > 0)
|
|
396
|
+
throw new G({ contractName: o, issues: r });
|
|
397
|
+
super({ ...e, tenantCode: s });
|
|
398
|
+
const a = (l = e.meta) == null ? void 0 : l.revision;
|
|
399
|
+
Number.isInteger(a) && a >= 0 && (this.meta.revision = a), this._type = e._type || o, Object.assign(this, d), Object.defineProperty(this, "_storeContractFields", {
|
|
400
|
+
configurable: !1,
|
|
401
|
+
enumerable: !1,
|
|
402
|
+
value: Object.freeze([...t]),
|
|
403
|
+
writable: !1
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
getId() {
|
|
407
|
+
return this.id === null || typeof this.id > "u" ? "" : this.id.toString();
|
|
408
|
+
}
|
|
409
|
+
toJSON() {
|
|
410
|
+
return this.toObject();
|
|
411
|
+
}
|
|
412
|
+
toObject() {
|
|
413
|
+
const o = {
|
|
414
|
+
_type: this._type,
|
|
415
|
+
meta: De(this.meta, Ye),
|
|
416
|
+
metadata: Oe(this.metadata),
|
|
417
|
+
remarks: Oe(this.remarks),
|
|
418
|
+
tenantCode: this.tenantCode,
|
|
419
|
+
...De(this, this._storeContractFields)
|
|
420
|
+
}, e = this.getId();
|
|
421
|
+
return e && (o.id = e), D(o);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
function et(n, o) {
|
|
425
|
+
if (!(typeof n > "u")) {
|
|
426
|
+
if (!n || typeof n != "object" || Array.isArray(n)) {
|
|
427
|
+
o.push("meta must be an object");
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
Object.keys(n).forEach((e) => {
|
|
431
|
+
Ye.includes(e) || o.push(`meta contains unknown field "${e}"`);
|
|
432
|
+
}), ["active", "deleted"].forEach((e) => {
|
|
433
|
+
typeof n[e] < "u" && typeof n[e] != "boolean" && o.push(`meta.${e} must be a boolean`);
|
|
434
|
+
}), ["created", "modified"].forEach((e) => {
|
|
435
|
+
typeof n[e] < "u" && (!Number.isFinite(n[e]) || n[e] < 0) && o.push(`meta.${e} must be a non-negative finite number`);
|
|
436
|
+
}), ["creator", "owner"].forEach((e) => {
|
|
437
|
+
typeof n[e] < "u" && typeof n[e] != "string" && o.push(`meta.${e} must be a string`);
|
|
438
|
+
}), typeof n.revision < "u" && (!Number.isInteger(n.revision) || n.revision < 0) && o.push("meta.revision must be a non-negative integer");
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
function Oe(n) {
|
|
442
|
+
return Array.isArray(n) ? n.map((o) => ({ key: o.key, value: D(o.value) })) : [];
|
|
443
|
+
}
|
|
444
|
+
function De(n, o) {
|
|
445
|
+
return Object.fromEntries(o.flatMap((e) => typeof n[e] > "u" ? [] : [[e, D(n[e])]]));
|
|
446
|
+
}
|
|
447
|
+
function Ne(n, o, e) {
|
|
448
|
+
if (!(typeof n > "u")) {
|
|
449
|
+
if (!Array.isArray(n)) {
|
|
450
|
+
e.push(`${o} must be an array`);
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
n.forEach((t, i) => {
|
|
454
|
+
if (!t || typeof t != "object" || Array.isArray(t)) {
|
|
455
|
+
e.push(`${o}[${i}] must be an object`);
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
Object.keys(t).forEach((r) => {
|
|
459
|
+
["key", "value"].includes(r) || e.push(`${o}[${i}] contains unknown field "${r}"`);
|
|
460
|
+
}), u(t.key, `${o}[${i}].key`, e), Object.hasOwn(t, "value") ? D(t.value, `${o}[${i}].value`) : e.push(`${o}[${i}].value is required`);
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
class Lt extends L {
|
|
465
|
+
constructor(o = {}) {
|
|
466
|
+
super({
|
|
467
|
+
contractName: "Category",
|
|
468
|
+
object: o,
|
|
469
|
+
fields: ["categoryCode", "version", "name", "description"],
|
|
470
|
+
normalize(e, t) {
|
|
471
|
+
return {
|
|
472
|
+
categoryCode: u(e.categoryCode, "categoryCode", t),
|
|
473
|
+
version: I(e.version, "version", t),
|
|
474
|
+
name: u(e.name, "name", t),
|
|
475
|
+
...M(e.description, "description", t) ? { description: e.description } : {}
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
getCode() {
|
|
481
|
+
return this.categoryCode;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
class Ut extends L {
|
|
485
|
+
constructor(o = {}) {
|
|
486
|
+
super({
|
|
487
|
+
contractName: "Currency",
|
|
488
|
+
object: o,
|
|
489
|
+
fields: ["currencyCode", "name", "symbol", "factor", "unit"],
|
|
490
|
+
normalize(e, t) {
|
|
491
|
+
const i = M(e.symbol, "symbol", t);
|
|
492
|
+
return {
|
|
493
|
+
currencyCode: u(e.currencyCode, "currencyCode", t),
|
|
494
|
+
name: u(e.name, "name", t),
|
|
495
|
+
...i ? { symbol: i } : {},
|
|
496
|
+
factor: I(e.factor, "factor", t),
|
|
497
|
+
unit: u(e.unit, "unit", t)
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
getCode() {
|
|
503
|
+
return this.currencyCode;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
class vt extends T {
|
|
507
|
+
constructor(o = {}) {
|
|
508
|
+
super({
|
|
509
|
+
contractName: "EligibilityFact",
|
|
510
|
+
object: o,
|
|
511
|
+
fields: [
|
|
512
|
+
"eligibilityType",
|
|
513
|
+
"state",
|
|
514
|
+
"revision",
|
|
515
|
+
"decisionReference",
|
|
516
|
+
"reasonCode"
|
|
517
|
+
],
|
|
518
|
+
normalize(e, t) {
|
|
519
|
+
const i = u(e.state, "state", t);
|
|
520
|
+
return Object.values(x).includes(i) || t.push(`state "${i}" is not supported`), (!Number.isInteger(e.revision) || e.revision < 0) && t.push("revision must be a non-negative integer"), {
|
|
521
|
+
eligibilityType: u(e.eligibilityType, "eligibilityType", t),
|
|
522
|
+
state: i,
|
|
523
|
+
revision: Number.isInteger(e.revision) && e.revision >= 0 ? e.revision : 0,
|
|
524
|
+
...M(e.decisionReference, "decisionReference", t) ? { decisionReference: e.decisionReference } : {},
|
|
525
|
+
...M(e.reasonCode, "reasonCode", t) ? { reasonCode: e.reasonCode } : {}
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
class Ae extends T {
|
|
532
|
+
constructor(o = {}) {
|
|
533
|
+
super({
|
|
534
|
+
contractName: "MerchandiseComponent",
|
|
535
|
+
object: o,
|
|
536
|
+
fields: ["productCode", "productVersion", "quantityPerUnit"],
|
|
537
|
+
normalize(e, t) {
|
|
538
|
+
return {
|
|
539
|
+
productCode: u(e.productCode, "productCode", t),
|
|
540
|
+
productVersion: I(e.productVersion, "productVersion", t),
|
|
541
|
+
quantityPerUnit: I(e.quantityPerUnit, "quantityPerUnit", t)
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
class wt extends L {
|
|
548
|
+
constructor(o = {}) {
|
|
549
|
+
super({
|
|
550
|
+
contractName: "Merchandise",
|
|
551
|
+
object: o,
|
|
552
|
+
fields: ["merchandiseCode", "version", "name", "description", "components", "priceScheduleCode"],
|
|
553
|
+
normalize(e, t) {
|
|
554
|
+
let i = [];
|
|
555
|
+
try {
|
|
556
|
+
i = (e.components || []).map((r) => (r instanceof Ae ? r : new Ae(r)).toObject());
|
|
557
|
+
} catch (r) {
|
|
558
|
+
t.push(`components: ${r.message}`);
|
|
559
|
+
}
|
|
560
|
+
return i.length === 0 && t.push("components must contain at least one component"), {
|
|
561
|
+
merchandiseCode: u(e.merchandiseCode, "merchandiseCode", t),
|
|
562
|
+
version: I(e.version, "version", t),
|
|
563
|
+
name: u(e.name, "name", t),
|
|
564
|
+
...M(e.description, "description", t) ? { description: e.description } : {},
|
|
565
|
+
components: i,
|
|
566
|
+
priceScheduleCode: u(e.priceScheduleCode, "priceScheduleCode", t)
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
getCode() {
|
|
572
|
+
return this.merchandiseCode;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
function Se(n, o, e) {
|
|
576
|
+
if (!(typeof n > "u" || n === null))
|
|
577
|
+
return I(n, o, e);
|
|
578
|
+
}
|
|
579
|
+
class Pe extends T {
|
|
580
|
+
constructor(o = {}) {
|
|
581
|
+
super({
|
|
582
|
+
contractName: "PriceMatchCriteria",
|
|
583
|
+
object: o,
|
|
584
|
+
fields: ["countryCodes", "excludedCountryCodes", "countryRank"],
|
|
585
|
+
normalize(e, t) {
|
|
586
|
+
const i = z(e.countryCodes || [], "countryCodes", t), r = z(
|
|
587
|
+
e.excludedCountryCodes || [],
|
|
588
|
+
"excludedCountryCodes",
|
|
589
|
+
t
|
|
590
|
+
), s = i.filter((d) => r.includes(d));
|
|
591
|
+
s.length > 0 && t.push(
|
|
592
|
+
`countryCodes and excludedCountryCodes overlap: ${[...new Set(s)].join(", ")}`
|
|
593
|
+
);
|
|
594
|
+
let c;
|
|
595
|
+
if (typeof e.countryRank < "u" && e.countryRank !== null)
|
|
596
|
+
if (typeof e.countryRank != "object" || Array.isArray(e.countryRank))
|
|
597
|
+
t.push("countryRank must be an object");
|
|
598
|
+
else {
|
|
599
|
+
Object.keys(e.countryRank).filter((f) => !["min", "max"].includes(f)).forEach((f) => t.push(`countryRank contains unknown field "${f}"`));
|
|
600
|
+
const a = Se(e.countryRank.min, "countryRank.min", t), l = Se(e.countryRank.max, "countryRank.max", t);
|
|
601
|
+
typeof a > "u" && typeof l > "u" && t.push("countryRank must contain min or max"), a && l && a > l && t.push("countryRank.max must be greater than or equal to countryRank.min"), c = {
|
|
602
|
+
...a ? { min: a } : {},
|
|
603
|
+
...l ? { max: l } : {}
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
return {
|
|
607
|
+
countryCodes: i,
|
|
608
|
+
excludedCountryCodes: r,
|
|
609
|
+
...c ? { countryRank: c } : {}
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
class _e extends T {
|
|
616
|
+
constructor(o = {}) {
|
|
617
|
+
super({
|
|
618
|
+
contractName: "SalesPeriodRef",
|
|
619
|
+
object: o,
|
|
620
|
+
fields: ["salesPeriodCode", "salesPeriodVersion"],
|
|
621
|
+
normalize(e, t) {
|
|
622
|
+
return {
|
|
623
|
+
salesPeriodCode: u(e.salesPeriodCode, "salesPeriodCode", t),
|
|
624
|
+
salesPeriodVersion: I(e.salesPeriodVersion, "salesPeriodVersion", t)
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
function Ve(n, o, e) {
|
|
631
|
+
if (typeof n > "u" || n === null)
|
|
632
|
+
return;
|
|
633
|
+
const t = M(n, o, e);
|
|
634
|
+
return t && !Number.isFinite(Date.parse(t)) && e.push(`${o} must be an ISO-compatible timestamp`), t;
|
|
635
|
+
}
|
|
636
|
+
class Me extends T {
|
|
637
|
+
constructor(o = {}) {
|
|
638
|
+
super({
|
|
639
|
+
contractName: "PriceRow",
|
|
640
|
+
object: o,
|
|
641
|
+
fields: [
|
|
642
|
+
"priceRowCode",
|
|
643
|
+
"currency",
|
|
644
|
+
"amount",
|
|
645
|
+
"match",
|
|
646
|
+
"salesPeriodRef",
|
|
647
|
+
"validFrom",
|
|
648
|
+
"validUntil",
|
|
649
|
+
"acquisitionSources"
|
|
650
|
+
],
|
|
651
|
+
normalize(e, t) {
|
|
652
|
+
const i = Ve(e.validFrom, "validFrom", t), r = Ve(e.validUntil, "validUntil", t);
|
|
653
|
+
i && r && Date.parse(i) >= Date.parse(r) && t.push("validUntil must be later than validFrom");
|
|
654
|
+
let s;
|
|
655
|
+
if (e.salesPeriodRef !== null && typeof e.salesPeriodRef < "u") {
|
|
656
|
+
try {
|
|
657
|
+
s = (e.salesPeriodRef instanceof _e ? e.salesPeriodRef : new _e(e.salesPeriodRef)).toObject();
|
|
658
|
+
} catch (d) {
|
|
659
|
+
t.push(`salesPeriodRef: ${d.message}`);
|
|
660
|
+
}
|
|
661
|
+
(!i || !r) && t.push("salesPeriodRef requires validFrom and validUntil snapshots");
|
|
662
|
+
}
|
|
663
|
+
let c = {};
|
|
664
|
+
try {
|
|
665
|
+
c = (e.match instanceof Pe ? e.match : new Pe(e.match || {})).toObject();
|
|
666
|
+
} catch (d) {
|
|
667
|
+
t.push(`match: ${d.message}`);
|
|
668
|
+
}
|
|
669
|
+
return {
|
|
670
|
+
priceRowCode: u(e.priceRowCode, "priceRowCode", t),
|
|
671
|
+
currency: u(e.currency, "currency", t),
|
|
672
|
+
amount: He(e.amount, "amount", t),
|
|
673
|
+
match: c,
|
|
674
|
+
...s ? { salesPeriodRef: s } : {},
|
|
675
|
+
...i ? { validFrom: i } : {},
|
|
676
|
+
...r ? { validUntil: r } : {},
|
|
677
|
+
acquisitionSources: z(e.acquisitionSources || [], "acquisitionSources", t)
|
|
678
|
+
};
|
|
679
|
+
}
|
|
680
|
+
});
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
class jt extends L {
|
|
684
|
+
constructor(o = {}) {
|
|
685
|
+
super({
|
|
686
|
+
contractName: "PriceSchedule",
|
|
687
|
+
object: o,
|
|
688
|
+
fields: ["priceScheduleCode", "version", "rows"],
|
|
689
|
+
normalize(e, t) {
|
|
690
|
+
let i = [];
|
|
691
|
+
try {
|
|
692
|
+
i = (e.rows || []).map((r) => (r instanceof Me ? r : new Me(r)).toObject());
|
|
693
|
+
} catch (r) {
|
|
694
|
+
t.push(`rows: ${r.message}`);
|
|
695
|
+
}
|
|
696
|
+
return i.length === 0 && t.push("rows must contain at least one row"), {
|
|
697
|
+
priceScheduleCode: u(e.priceScheduleCode, "priceScheduleCode", t),
|
|
698
|
+
version: I(e.version, "version", t),
|
|
699
|
+
rows: i
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
getCode() {
|
|
705
|
+
return this.priceScheduleCode;
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
class xt extends L {
|
|
709
|
+
constructor(o = {}) {
|
|
710
|
+
super({
|
|
711
|
+
contractName: "Product",
|
|
712
|
+
object: o,
|
|
713
|
+
fields: ["productCode", "version", "name", "description", "categoryCodes"],
|
|
714
|
+
normalize(e, t) {
|
|
715
|
+
return {
|
|
716
|
+
productCode: u(e.productCode, "productCode", t),
|
|
717
|
+
version: I(e.version, "version", t),
|
|
718
|
+
name: u(e.name, "name", t),
|
|
719
|
+
...M(e.description, "description", t) ? { description: e.description } : {},
|
|
720
|
+
categoryCodes: z(e.categoryCodes || [], "categoryCodes", t)
|
|
721
|
+
};
|
|
722
|
+
}
|
|
723
|
+
});
|
|
724
|
+
}
|
|
725
|
+
getCode() {
|
|
726
|
+
return this.productCode;
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
class tt extends T {
|
|
730
|
+
constructor(o = {}) {
|
|
731
|
+
super({
|
|
732
|
+
contractName: "EligibilityRuleDetails",
|
|
733
|
+
object: o,
|
|
734
|
+
fields: ["acceptedStates", "eligibilityType"],
|
|
735
|
+
normalize(e, t) {
|
|
736
|
+
const i = z(e.acceptedStates || [], "acceptedStates", t);
|
|
737
|
+
return i.length === 0 && t.push("acceptedStates must contain at least one state"), ze({
|
|
738
|
+
values: i,
|
|
739
|
+
allowedValues: Object.values(x),
|
|
740
|
+
path: "acceptedStates",
|
|
741
|
+
issues: t
|
|
742
|
+
}), {
|
|
743
|
+
eligibilityType: u(e.eligibilityType, "eligibilityType", t),
|
|
744
|
+
acceptedStates: i
|
|
745
|
+
};
|
|
746
|
+
}
|
|
747
|
+
});
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
class nt extends T {
|
|
751
|
+
constructor(o = {}) {
|
|
752
|
+
super({
|
|
753
|
+
contractName: "InventoryRuleDetails",
|
|
754
|
+
object: o,
|
|
755
|
+
fields: ["inventoryMode", "inventoryPoolCode"],
|
|
756
|
+
normalize(e, t) {
|
|
757
|
+
return Object.values(se).includes(e.inventoryMode) || t.push(`inventoryMode "${e.inventoryMode}" is not supported`), {
|
|
758
|
+
inventoryMode: e.inventoryMode,
|
|
759
|
+
inventoryPoolCode: u(e.inventoryPoolCode, "inventoryPoolCode", t)
|
|
760
|
+
};
|
|
761
|
+
}
|
|
762
|
+
});
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
class ot extends T {
|
|
766
|
+
constructor(o = {}) {
|
|
767
|
+
super({
|
|
768
|
+
contractName: "PrerequisiteRuleDetails",
|
|
769
|
+
object: o,
|
|
770
|
+
fields: ["continuous", "evidenceSources", "matchMode", "requires"],
|
|
771
|
+
normalize(e, t) {
|
|
772
|
+
(!Array.isArray(e.requires) || e.requires.length === 0) && t.push("requires must contain at least one target");
|
|
773
|
+
const i = (e.requires || []).map((s, c) => {
|
|
774
|
+
try {
|
|
775
|
+
return Je(s, `requires[${c}]`, t, Object.values(_));
|
|
776
|
+
} catch (d) {
|
|
777
|
+
return t.push(`requires[${c}]: ${d.message}`), {};
|
|
778
|
+
}
|
|
779
|
+
});
|
|
780
|
+
Object.values(ce).includes(e.matchMode) || t.push(`matchMode "${e.matchMode}" is not supported`);
|
|
781
|
+
const r = z(e.evidenceSources || [], "evidenceSources", t);
|
|
782
|
+
return ze({
|
|
783
|
+
values: r,
|
|
784
|
+
allowedValues: Object.values(k),
|
|
785
|
+
path: "evidenceSources",
|
|
786
|
+
issues: t
|
|
787
|
+
}), {
|
|
788
|
+
requires: i,
|
|
789
|
+
matchMode: e.matchMode,
|
|
790
|
+
evidenceSources: r,
|
|
791
|
+
continuous: e.continuous === !0
|
|
792
|
+
};
|
|
793
|
+
}
|
|
794
|
+
});
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
class it extends T {
|
|
798
|
+
constructor(o = {}) {
|
|
799
|
+
super({
|
|
800
|
+
contractName: "QuantityRuleDetails",
|
|
801
|
+
object: o,
|
|
802
|
+
fields: ["limit", "limitType"],
|
|
803
|
+
normalize(e, t) {
|
|
804
|
+
return Object.values(K).includes(e.limitType) || t.push(`limitType "${e.limitType}" is not supported`), {
|
|
805
|
+
limitType: e.limitType,
|
|
806
|
+
limit: I(e.limit, "limit", t)
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
});
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
class qe extends T {
|
|
813
|
+
constructor(o = {}) {
|
|
814
|
+
super({
|
|
815
|
+
contractName: "RefundPolicyRef",
|
|
816
|
+
object: o,
|
|
817
|
+
fields: ["refundPolicyCode", "refundPolicyVersion"],
|
|
818
|
+
normalize(e, t) {
|
|
819
|
+
return {
|
|
820
|
+
refundPolicyCode: u(e.refundPolicyCode, "refundPolicyCode", t),
|
|
821
|
+
refundPolicyVersion: I(e.refundPolicyVersion, "refundPolicyVersion", t)
|
|
822
|
+
};
|
|
823
|
+
}
|
|
824
|
+
});
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
class rt extends T {
|
|
828
|
+
constructor(o = {}) {
|
|
829
|
+
super({
|
|
830
|
+
contractName: "RefundRuleDetails",
|
|
831
|
+
object: o,
|
|
832
|
+
fields: ["refundPolicyRef"],
|
|
833
|
+
normalize(e, t) {
|
|
834
|
+
try {
|
|
835
|
+
return { refundPolicyRef: (e.refundPolicyRef instanceof qe ? e.refundPolicyRef : new qe(e.refundPolicyRef)).toObject() };
|
|
836
|
+
} catch (i) {
|
|
837
|
+
return t.push(`refundPolicyRef: ${i.message}`), { refundPolicyRef: {} };
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
});
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
class st extends T {
|
|
844
|
+
constructor(o = {}) {
|
|
845
|
+
super({
|
|
846
|
+
contractName: "RequirementRuleDetails",
|
|
847
|
+
object: o,
|
|
848
|
+
fields: [
|
|
849
|
+
"completionDeadline",
|
|
850
|
+
"completionTiming",
|
|
851
|
+
"modificationDeadline",
|
|
852
|
+
"modificationMode",
|
|
853
|
+
"requirement"
|
|
854
|
+
],
|
|
855
|
+
normalize(e, t) {
|
|
856
|
+
let i = {};
|
|
857
|
+
try {
|
|
858
|
+
i = (e.requirement instanceof X ? e.requirement : new X(e.requirement)).toObject();
|
|
859
|
+
} catch (c) {
|
|
860
|
+
t.push(`requirement: ${c.message}`);
|
|
861
|
+
}
|
|
862
|
+
Object.values(de).includes(e.completionTiming) || t.push(`completionTiming "${e.completionTiming}" is not supported`), Object.values(Q).includes(e.modificationMode) || t.push(`modificationMode "${e.modificationMode}" is not supported`);
|
|
863
|
+
const r = Z(e.completionDeadline, "completionDeadline", t), s = Z(e.modificationDeadline, "modificationDeadline", t);
|
|
864
|
+
return e.modificationMode === Q.UNTIL_DEADLINE && !s && t.push("modificationDeadline is required when modificationMode is UNTIL_DEADLINE"), e.modificationMode !== Q.UNTIL_DEADLINE && s && t.push("modificationDeadline is only supported when modificationMode is UNTIL_DEADLINE"), {
|
|
865
|
+
requirement: i,
|
|
866
|
+
completionTiming: e.completionTiming,
|
|
867
|
+
modificationMode: e.modificationMode,
|
|
868
|
+
...r ? { completionDeadline: r } : {},
|
|
869
|
+
...s ? { modificationDeadline: s } : {}
|
|
870
|
+
};
|
|
871
|
+
}
|
|
872
|
+
});
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
const ct = Object.freeze({
|
|
876
|
+
[S.ELIGIBILITY]: tt,
|
|
877
|
+
[S.INVENTORY]: nt,
|
|
878
|
+
[S.PREREQUISITE]: ot,
|
|
879
|
+
[S.QUANTITY]: it,
|
|
880
|
+
[S.REFUND]: rt,
|
|
881
|
+
[S.REQUIREMENT]: st
|
|
882
|
+
});
|
|
883
|
+
function dt(n, o) {
|
|
884
|
+
const e = ct[n];
|
|
885
|
+
if (!e)
|
|
886
|
+
throw new TypeError(`Rule type "${n}" does not have a details contract`);
|
|
887
|
+
return new e(o);
|
|
888
|
+
}
|
|
889
|
+
function at(n, o, e) {
|
|
890
|
+
if (!n || typeof n != "object" || Array.isArray(n))
|
|
891
|
+
return e.push(`${o} must be an object`), {};
|
|
892
|
+
const t = u(n.type, `${o}.type`, e), i = u(n.code, `${o}.code`, e);
|
|
893
|
+
return Object.keys(n).forEach((r) => {
|
|
894
|
+
["code", "type"].includes(r) || e.push(`${o} contains unknown field "${r}"`);
|
|
895
|
+
}), Object.values(_).includes(t) || e.push(`${o}.type "${t}" is not supported`), { type: t, code: i };
|
|
896
|
+
}
|
|
897
|
+
class zt extends L {
|
|
898
|
+
constructor(o = {}) {
|
|
899
|
+
super({
|
|
900
|
+
contractName: "PublishedRule",
|
|
901
|
+
object: o,
|
|
902
|
+
fields: [
|
|
903
|
+
"publishedRuleCode",
|
|
904
|
+
"version",
|
|
905
|
+
"ruleType",
|
|
906
|
+
"sourceType",
|
|
907
|
+
"sourceCode",
|
|
908
|
+
"appliesTo",
|
|
909
|
+
"details",
|
|
910
|
+
"reason"
|
|
911
|
+
],
|
|
912
|
+
normalize(e, t) {
|
|
913
|
+
const i = u(e.ruleType, "ruleType", t);
|
|
914
|
+
Object.values(S).includes(i) || t.push(`ruleType "${i}" is not supported`);
|
|
915
|
+
const r = u(e.sourceType, "sourceType", t);
|
|
916
|
+
Object.values(V).includes(r) || t.push(`sourceType "${r}" is not supported`);
|
|
917
|
+
const s = at(e.appliesTo, "appliesTo", t);
|
|
918
|
+
let c = {};
|
|
919
|
+
try {
|
|
920
|
+
c = dt(i, e.details).toObject();
|
|
921
|
+
} catch (d) {
|
|
922
|
+
t.push(`details: ${d.message}`);
|
|
923
|
+
}
|
|
924
|
+
return {
|
|
925
|
+
publishedRuleCode: u(e.publishedRuleCode, "publishedRuleCode", t),
|
|
926
|
+
version: I(e.version, "version", t),
|
|
927
|
+
ruleType: i,
|
|
928
|
+
sourceType: r,
|
|
929
|
+
sourceCode: u(e.sourceCode, "sourceCode", t),
|
|
930
|
+
appliesTo: s,
|
|
931
|
+
details: c,
|
|
932
|
+
...e.reason ? { reason: e.reason } : {}
|
|
933
|
+
};
|
|
934
|
+
}
|
|
935
|
+
});
|
|
936
|
+
}
|
|
937
|
+
getCode() {
|
|
938
|
+
return this.publishedRuleCode;
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
class Yt extends T {
|
|
942
|
+
constructor(o = {}) {
|
|
943
|
+
super({
|
|
944
|
+
contractName: "PublishedRuleRef",
|
|
945
|
+
object: o,
|
|
946
|
+
fields: ["publishedRuleCode", "publishedRuleVersion"],
|
|
947
|
+
normalize(e, t) {
|
|
948
|
+
return {
|
|
949
|
+
publishedRuleCode: u(e.publishedRuleCode, "publishedRuleCode", t),
|
|
950
|
+
publishedRuleVersion: I(e.publishedRuleVersion, "publishedRuleVersion", t)
|
|
951
|
+
};
|
|
952
|
+
}
|
|
953
|
+
});
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
class Qt extends L {
|
|
957
|
+
constructor(o = {}) {
|
|
958
|
+
super({
|
|
959
|
+
contractName: "RefundPolicy",
|
|
960
|
+
object: o,
|
|
961
|
+
fields: ["refundPolicyCode", "version", "name"],
|
|
962
|
+
normalize(e, t) {
|
|
963
|
+
return {
|
|
964
|
+
refundPolicyCode: u(e.refundPolicyCode, "refundPolicyCode", t),
|
|
965
|
+
version: I(e.version, "version", t),
|
|
966
|
+
name: u(e.name, "name", t)
|
|
967
|
+
};
|
|
968
|
+
}
|
|
969
|
+
});
|
|
970
|
+
}
|
|
971
|
+
getCode() {
|
|
972
|
+
return this.refundPolicyCode;
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
function $e(n, o, e) {
|
|
976
|
+
const t = u(n, o, e);
|
|
977
|
+
return t && !Number.isFinite(Date.parse(t)) && e.push(`${o} must be an ISO-compatible timestamp`), t;
|
|
978
|
+
}
|
|
979
|
+
class Bt extends L {
|
|
980
|
+
constructor(o = {}) {
|
|
981
|
+
super({
|
|
982
|
+
contractName: "SalesPeriod",
|
|
983
|
+
object: o,
|
|
984
|
+
fields: ["salesPeriodCode", "version", "name", "validFrom", "validUntil"],
|
|
985
|
+
normalize(e, t) {
|
|
986
|
+
const i = $e(e.validFrom, "validFrom", t), r = $e(e.validUntil, "validUntil", t);
|
|
987
|
+
return i && r && Date.parse(i) >= Date.parse(r) && t.push("validUntil must be later than validFrom"), {
|
|
988
|
+
salesPeriodCode: u(e.salesPeriodCode, "salesPeriodCode", t),
|
|
989
|
+
version: I(e.version, "version", t),
|
|
990
|
+
name: u(e.name, "name", t),
|
|
991
|
+
validFrom: i,
|
|
992
|
+
validUntil: r
|
|
993
|
+
};
|
|
994
|
+
}
|
|
995
|
+
});
|
|
996
|
+
}
|
|
997
|
+
getCode() {
|
|
998
|
+
return this.salesPeriodCode;
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
class Ft extends L {
|
|
1002
|
+
constructor(o = {}) {
|
|
1003
|
+
super({
|
|
1004
|
+
contractName: "Variant",
|
|
1005
|
+
object: o,
|
|
1006
|
+
fields: ["variantCode", "version", "productCode", "productVersion", "name", "optionValues"],
|
|
1007
|
+
normalize(e, t) {
|
|
1008
|
+
return (!e.optionValues || typeof e.optionValues != "object" || Array.isArray(e.optionValues)) && t.push("optionValues must be an object"), {
|
|
1009
|
+
variantCode: u(e.variantCode, "variantCode", t),
|
|
1010
|
+
version: I(e.version, "version", t),
|
|
1011
|
+
productCode: u(e.productCode, "productCode", t),
|
|
1012
|
+
productVersion: I(e.productVersion, "productVersion", t),
|
|
1013
|
+
name: u(e.name, "name", t),
|
|
1014
|
+
optionValues: e.optionValues || {}
|
|
1015
|
+
};
|
|
1016
|
+
}
|
|
1017
|
+
});
|
|
1018
|
+
}
|
|
1019
|
+
getCode() {
|
|
1020
|
+
return this.variantCode;
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
class Le extends T {
|
|
1024
|
+
constructor(o = {}) {
|
|
1025
|
+
super({
|
|
1026
|
+
contractName: "VariantRef",
|
|
1027
|
+
object: o,
|
|
1028
|
+
fields: ["variantCode", "variantVersion"],
|
|
1029
|
+
normalize(e, t) {
|
|
1030
|
+
return {
|
|
1031
|
+
variantCode: u(e.variantCode, "variantCode", t),
|
|
1032
|
+
variantVersion: I(e.variantVersion, "variantVersion", t)
|
|
1033
|
+
};
|
|
1034
|
+
}
|
|
1035
|
+
});
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
class kt extends L {
|
|
1039
|
+
constructor(o = {}) {
|
|
1040
|
+
super({
|
|
1041
|
+
contractName: "WalletItem",
|
|
1042
|
+
object: o,
|
|
1043
|
+
fields: [
|
|
1044
|
+
"walletItemCode",
|
|
1045
|
+
"productCode",
|
|
1046
|
+
"productVersion",
|
|
1047
|
+
"state",
|
|
1048
|
+
"quantity",
|
|
1049
|
+
"acquisitionCode",
|
|
1050
|
+
"eventRegistrationCode",
|
|
1051
|
+
"variantCode",
|
|
1052
|
+
"variantVersion",
|
|
1053
|
+
"requirementPlans"
|
|
1054
|
+
],
|
|
1055
|
+
normalize(e, t) {
|
|
1056
|
+
const i = M(e.variantCode, "variantCode", t), r = typeof e.variantVersion > "u" || e.variantVersion === null ? void 0 : I(e.variantVersion, "variantVersion", t);
|
|
1057
|
+
(i && typeof r > "u" || !i && typeof r < "u") && t.push("variantCode and variantVersion must be provided together"), Array.isArray(e.requirementPlans || []) || t.push("requirementPlans must be an array");
|
|
1058
|
+
const s = u(e.state, "state", t);
|
|
1059
|
+
Object.values(P).includes(s) || t.push(`state "${s}" is not supported`);
|
|
1060
|
+
const c = (Array.isArray(e.requirementPlans) ? e.requirementPlans : []).flatMap((d, a) => {
|
|
1061
|
+
try {
|
|
1062
|
+
return [(d instanceof ee ? d : new ee(d)).toObject()];
|
|
1063
|
+
} catch (l) {
|
|
1064
|
+
return t.push(`requirementPlans[${a}]: ${l.message}`), [];
|
|
1065
|
+
}
|
|
1066
|
+
});
|
|
1067
|
+
return {
|
|
1068
|
+
walletItemCode: u(e.walletItemCode, "walletItemCode", t),
|
|
1069
|
+
productCode: u(e.productCode, "productCode", t),
|
|
1070
|
+
productVersion: I(e.productVersion, "productVersion", t),
|
|
1071
|
+
state: s,
|
|
1072
|
+
quantity: I(e.quantity, "quantity", t),
|
|
1073
|
+
acquisitionCode: u(e.acquisitionCode, "acquisitionCode", t),
|
|
1074
|
+
...M(e.eventRegistrationCode, "eventRegistrationCode", t) ? { eventRegistrationCode: e.eventRegistrationCode } : {},
|
|
1075
|
+
...i ? { variantCode: i, variantVersion: r } : {},
|
|
1076
|
+
requirementPlans: c
|
|
1077
|
+
};
|
|
1078
|
+
}
|
|
1079
|
+
});
|
|
1080
|
+
}
|
|
1081
|
+
getCode() {
|
|
1082
|
+
return this.walletItemCode;
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
const Ue = [
|
|
1086
|
+
V.CATEGORY,
|
|
1087
|
+
V.PRODUCT,
|
|
1088
|
+
V.MERCHANDISE,
|
|
1089
|
+
V.ACQUISITION_SOURCE
|
|
1090
|
+
];
|
|
1091
|
+
function ve(n, o) {
|
|
1092
|
+
return `${n}:${o}`;
|
|
1093
|
+
}
|
|
1094
|
+
function ut({ rule: n, relevantCategoryCodes: o, relevantProductCodes: e, merchandise: t }) {
|
|
1095
|
+
if (n.sourceType === V.CATEGORY)
|
|
1096
|
+
return n.appliesTo.type === _.CATEGORY && n.appliesTo.code === n.sourceCode;
|
|
1097
|
+
if (n.sourceType === V.PRODUCT)
|
|
1098
|
+
return n.appliesTo.type === _.PRODUCT && n.appliesTo.code === n.sourceCode;
|
|
1099
|
+
if (n.sourceType === V.MERCHANDISE)
|
|
1100
|
+
return n.appliesTo.type === _.MERCHANDISE ? n.appliesTo.code === t.merchandiseCode : n.appliesTo.type === _.PRODUCT ? e.has(n.appliesTo.code) : n.appliesTo.type === _.CATEGORY ? o.has(n.appliesTo.code) : !1;
|
|
1101
|
+
if (n.sourceType === V.ACQUISITION_SOURCE) {
|
|
1102
|
+
if (n.appliesTo.type === _.MERCHANDISE)
|
|
1103
|
+
return n.appliesTo.code === t.merchandiseCode;
|
|
1104
|
+
if (n.appliesTo.type === _.PRODUCT)
|
|
1105
|
+
return e.has(n.appliesTo.code);
|
|
1106
|
+
if (n.appliesTo.type === _.CATEGORY)
|
|
1107
|
+
return o.has(n.appliesTo.code);
|
|
1108
|
+
}
|
|
1109
|
+
return !1;
|
|
1110
|
+
}
|
|
1111
|
+
function lt({ categories: n = [], products: o = [], merchandise: e, acquisitionSource: t, publishedRules: i = [] }) {
|
|
1112
|
+
const r = new Set(e.components.map((p) => `${p.productCode}@${p.productVersion}`)), s = o.filter((p) => r.has(`${p.productCode}@${p.version}`)), c = new Set(s.map((p) => p.productCode)), d = new Set(s.flatMap((p) => p.categoryCodes || [])), l = [
|
|
1113
|
+
...n.filter((p) => d.has(p.categoryCode)).map((p) => ({
|
|
1114
|
+
sourceType: V.CATEGORY,
|
|
1115
|
+
sourceCode: p.categoryCode
|
|
1116
|
+
})),
|
|
1117
|
+
...s.map((p) => ({
|
|
1118
|
+
sourceType: V.PRODUCT,
|
|
1119
|
+
sourceCode: p.productCode
|
|
1120
|
+
})),
|
|
1121
|
+
{
|
|
1122
|
+
sourceType: V.MERCHANDISE,
|
|
1123
|
+
sourceCode: e.merchandiseCode
|
|
1124
|
+
},
|
|
1125
|
+
{
|
|
1126
|
+
sourceType: V.ACQUISITION_SOURCE,
|
|
1127
|
+
sourceCode: t
|
|
1128
|
+
}
|
|
1129
|
+
], f = new Set(l.map((p) => ve(p.sourceType, p.sourceCode))), N = i.filter((p) => f.has(ve(p.sourceType, p.sourceCode))).reduce((p, y) => {
|
|
1130
|
+
const h = p.get(y.publishedRuleCode) || [];
|
|
1131
|
+
return h.push(y), p.set(y.publishedRuleCode, h), p;
|
|
1132
|
+
}, /* @__PURE__ */ new Map()), g = [], m = [], E = [], R = /* @__PURE__ */ new Set();
|
|
1133
|
+
N.forEach((p, y) => {
|
|
1134
|
+
if (p.length > 1) {
|
|
1135
|
+
g.push({
|
|
1136
|
+
code: "RULE_PUBLICATION_AMBIGUOUS",
|
|
1137
|
+
ruleCode: y,
|
|
1138
|
+
sources: p.map((U) => ({
|
|
1139
|
+
sourceType: U.sourceType,
|
|
1140
|
+
sourceCode: U.sourceCode
|
|
1141
|
+
})),
|
|
1142
|
+
versions: p.map((U) => U.version)
|
|
1143
|
+
});
|
|
1144
|
+
return;
|
|
1145
|
+
}
|
|
1146
|
+
const [h] = p;
|
|
1147
|
+
if (h.tenantCode !== e.tenantCode) {
|
|
1148
|
+
g.push({
|
|
1149
|
+
code: "RULE_TENANT_MISMATCH",
|
|
1150
|
+
ruleCode: h.publishedRuleCode,
|
|
1151
|
+
ruleTenantCode: h.tenantCode,
|
|
1152
|
+
expectedTenantCode: e.tenantCode
|
|
1153
|
+
});
|
|
1154
|
+
return;
|
|
1155
|
+
}
|
|
1156
|
+
if (!ut({ rule: h, relevantCategoryCodes: d, relevantProductCodes: c, merchandise: e })) {
|
|
1157
|
+
g.push({
|
|
1158
|
+
code: "RULE_TARGET_MISMATCH",
|
|
1159
|
+
ruleCode: h.publishedRuleCode,
|
|
1160
|
+
sourceType: h.sourceType,
|
|
1161
|
+
sourceCode: h.sourceCode,
|
|
1162
|
+
appliesTo: D(h.appliesTo)
|
|
1163
|
+
});
|
|
1164
|
+
return;
|
|
1165
|
+
}
|
|
1166
|
+
const W = `${h.publishedRuleCode}@${h.version}`;
|
|
1167
|
+
R.has(W) || (R.add(W), E.push(h)), m.push({
|
|
1168
|
+
ruleCode: h.publishedRuleCode,
|
|
1169
|
+
ruleVersion: h.version,
|
|
1170
|
+
ruleType: h.ruleType,
|
|
1171
|
+
sourceType: h.sourceType,
|
|
1172
|
+
sourceCode: h.sourceCode
|
|
1173
|
+
});
|
|
1174
|
+
}), E.sort((p, y) => Ue.indexOf(p.sourceType) - Ue.indexOf(y.sourceType) || p.publishedRuleCode.localeCompare(y.publishedRuleCode));
|
|
1175
|
+
const b = E.map((p) => typeof p.toObject == "function" ? p.toObject() : D(p)), C = Object.fromEntries(Object.values(S).map((p) => [
|
|
1176
|
+
p,
|
|
1177
|
+
b.filter((y) => y.ruleType === p)
|
|
1178
|
+
]));
|
|
1179
|
+
return q({
|
|
1180
|
+
passed: g.length === 0,
|
|
1181
|
+
rules: b,
|
|
1182
|
+
byType: C,
|
|
1183
|
+
trace: m,
|
|
1184
|
+
errors: g
|
|
1185
|
+
});
|
|
1186
|
+
}
|
|
1187
|
+
const pt = Object.freeze([
|
|
1188
|
+
P.CANCELLED,
|
|
1189
|
+
P.EXPIRED,
|
|
1190
|
+
P.REFUNDED,
|
|
1191
|
+
P.REVOKED
|
|
1192
|
+
]), mt = Object.freeze([
|
|
1193
|
+
P.PENDING_REQUIREMENT,
|
|
1194
|
+
P.RESERVED,
|
|
1195
|
+
P.VALID
|
|
1196
|
+
]), A = Object.freeze({
|
|
1197
|
+
DEFINITION_INVALID: "DEFINITION_INVALID",
|
|
1198
|
+
ELIGIBILITY_REJECTED: "ELIGIBILITY_REJECTED",
|
|
1199
|
+
ELIGIBILITY_REQUIRED: "ELIGIBILITY_REQUIRED",
|
|
1200
|
+
ELIGIBILITY_REVOKED: "ELIGIBILITY_REVOKED",
|
|
1201
|
+
ELIGIBILITY_UNDER_REVIEW: "ELIGIBILITY_UNDER_REVIEW",
|
|
1202
|
+
INVENTORY_UNAVAILABLE: "INVENTORY_UNAVAILABLE",
|
|
1203
|
+
PREREQUISITE_NOT_MET: "PREREQUISITE_NOT_MET",
|
|
1204
|
+
PRICE_COUNTRY_UNRESOLVED: "PRICE_COUNTRY_UNRESOLVED",
|
|
1205
|
+
PRICE_MATCH_CRITERIA_NOT_MET: "PRICE_MATCH_CRITERIA_NOT_MET",
|
|
1206
|
+
PRICE_ROW_AMBIGUOUS: "PRICE_ROW_AMBIGUOUS",
|
|
1207
|
+
PRICE_ROW_NOT_FOUND: "PRICE_ROW_NOT_FOUND",
|
|
1208
|
+
QUANTITY_LIMIT_EXCEEDED: "QUANTITY_LIMIT_EXCEEDED",
|
|
1209
|
+
REQUIREMENT_INCOMPLETE: "REQUIREMENT_INCOMPLETE",
|
|
1210
|
+
REVISION_CONFLICT: "REVISION_CONFLICT",
|
|
1211
|
+
VARIANT_SELECTION_REQUIRED: "VARIANT_SELECTION_REQUIRED"
|
|
1212
|
+
});
|
|
1213
|
+
function $({ passed: n, code: o = null, message: e, details: t = {} }) {
|
|
1214
|
+
return q({ passed: n, code: o, message: e, details: D(t) });
|
|
1215
|
+
}
|
|
1216
|
+
function w(n, o) {
|
|
1217
|
+
return n.type === _.PRODUCT ? o.productCode === n.code : n.type === _.CATEGORY ? (o.categoryCodes || []).includes(n.code) : n.type === _.MERCHANDISE ? o.merchandiseCode === n.code : !1;
|
|
1218
|
+
}
|
|
1219
|
+
function J(n, o, e) {
|
|
1220
|
+
return n.reduce((t, i) => !w(o, i) || e && !e.includes(i.state) ? t : t + (i.quantity || 1), 0);
|
|
1221
|
+
}
|
|
1222
|
+
function ft(n) {
|
|
1223
|
+
return (n == null ? void 0 : n.state) === P.VALID;
|
|
1224
|
+
}
|
|
1225
|
+
function Ct({ rules: n = [], existingItems: o = [], candidateItems: e = [], activeItemStates: t = mt }) {
|
|
1226
|
+
const i = n.filter((r) => r.ruleType === S.QUANTITY).filter((r) => e.some((s) => w(r.appliesTo, s))).map((r) => {
|
|
1227
|
+
const s = J(e, r.appliesTo);
|
|
1228
|
+
let c = 0;
|
|
1229
|
+
r.details.limitType === K.HOLDING ? c = J(
|
|
1230
|
+
o.filter((l) => !pt.includes(l.state)),
|
|
1231
|
+
r.appliesTo
|
|
1232
|
+
) : r.details.limitType === K.ACTIVE && (c = J(o, r.appliesTo, t));
|
|
1233
|
+
const d = c + s, a = d <= r.details.limit;
|
|
1234
|
+
return $({
|
|
1235
|
+
passed: a,
|
|
1236
|
+
...a ? {} : { code: A.QUANTITY_LIMIT_EXCEEDED },
|
|
1237
|
+
message: a ? "Quantity rule passed" : "Quantity limit would be exceeded",
|
|
1238
|
+
details: {
|
|
1239
|
+
ruleCode: r.publishedRuleCode,
|
|
1240
|
+
ruleVersion: r.version,
|
|
1241
|
+
limitType: r.details.limitType,
|
|
1242
|
+
target: r.appliesTo,
|
|
1243
|
+
current: c,
|
|
1244
|
+
addition: s,
|
|
1245
|
+
resulting: d,
|
|
1246
|
+
limit: r.details.limit,
|
|
1247
|
+
remaining: Math.max(0, r.details.limit - c)
|
|
1248
|
+
}
|
|
1249
|
+
});
|
|
1250
|
+
});
|
|
1251
|
+
return q({ passed: i.every((r) => r.passed), decisions: i });
|
|
1252
|
+
}
|
|
1253
|
+
function Et(n) {
|
|
1254
|
+
return n === x.UNDER_REVIEW ? A.ELIGIBILITY_UNDER_REVIEW : n === x.REJECTED ? A.ELIGIBILITY_REJECTED : n === x.REVOKED ? A.ELIGIBILITY_REVOKED : A.ELIGIBILITY_REQUIRED;
|
|
1255
|
+
}
|
|
1256
|
+
function yt({ rules: n = [], eligibilityFacts: o = [], eventRegistrationCode: e, candidateItems: t = [] }) {
|
|
1257
|
+
const i = n.filter((r) => r.ruleType === S.ELIGIBILITY).filter((r) => t.some((s) => w(r.appliesTo, s))).map((r) => {
|
|
1258
|
+
const s = o.find((a) => a.eligibilityType === r.details.eligibilityType && (!e || !a.eventRegistrationCode || a.eventRegistrationCode === e)), c = (s == null ? void 0 : s.state) || x.NOT_SUBMITTED, d = (r.details.acceptedStates || [x.VALID]).includes(c);
|
|
1259
|
+
return $({
|
|
1260
|
+
passed: d,
|
|
1261
|
+
...d ? {} : { code: Et(c) },
|
|
1262
|
+
message: d ? "Eligibility rule passed" : "Required eligibility is not valid",
|
|
1263
|
+
details: {
|
|
1264
|
+
ruleCode: r.publishedRuleCode,
|
|
1265
|
+
eligibilityType: r.details.eligibilityType,
|
|
1266
|
+
eventRegistrationCode: e || null,
|
|
1267
|
+
state: c,
|
|
1268
|
+
factRevision: (s == null ? void 0 : s.revision) || null
|
|
1269
|
+
}
|
|
1270
|
+
});
|
|
1271
|
+
});
|
|
1272
|
+
return q({ passed: i.every((r) => r.passed), decisions: i });
|
|
1273
|
+
}
|
|
1274
|
+
function It(n, o) {
|
|
1275
|
+
return ft(n) && w(o, n);
|
|
1276
|
+
}
|
|
1277
|
+
function Rt(n) {
|
|
1278
|
+
return Object.fromEntries([
|
|
1279
|
+
"walletItemCode",
|
|
1280
|
+
"acquisitionCode",
|
|
1281
|
+
"merchandiseCode",
|
|
1282
|
+
"productCode",
|
|
1283
|
+
"productVersion",
|
|
1284
|
+
"categoryCodes",
|
|
1285
|
+
"state",
|
|
1286
|
+
"quantity",
|
|
1287
|
+
"componentIndex"
|
|
1288
|
+
].flatMap((e) => typeof n[e] > "u" ? [] : [[e, D(n[e])]]));
|
|
1289
|
+
}
|
|
1290
|
+
function ht({ rules: n = [], existingItems: o = [], candidateItems: e = [] }) {
|
|
1291
|
+
const t = n.filter((i) => i.ruleType === S.PREREQUISITE).filter((i) => e.some((r) => w(i.appliesTo, r))).map((i) => {
|
|
1292
|
+
const r = i.details.evidenceSources || [
|
|
1293
|
+
k.EXISTING,
|
|
1294
|
+
k.SAME_ORDER
|
|
1295
|
+
], s = [
|
|
1296
|
+
...r.includes(k.EXISTING) ? o : [],
|
|
1297
|
+
...r.includes(k.SAME_ORDER) ? e : []
|
|
1298
|
+
], c = (i.details.requires || []).map((a) => ({
|
|
1299
|
+
requirement: a,
|
|
1300
|
+
matched: s.filter((l) => It(l, a)).map(Rt)
|
|
1301
|
+
})), d = i.details.matchMode === ce.ALL ? c.every((a) => a.matched.length > 0) : c.some((a) => a.matched.length > 0);
|
|
1302
|
+
return $({
|
|
1303
|
+
passed: d,
|
|
1304
|
+
...d ? {} : { code: A.PREREQUISITE_NOT_MET },
|
|
1305
|
+
message: d ? "Prerequisite rule passed" : "Prerequisite item was not found",
|
|
1306
|
+
details: {
|
|
1307
|
+
ruleCode: i.publishedRuleCode,
|
|
1308
|
+
matchMode: i.details.matchMode || ce.ANY,
|
|
1309
|
+
continuous: i.details.continuous || !1,
|
|
1310
|
+
requirementResults: c
|
|
1311
|
+
}
|
|
1312
|
+
});
|
|
1313
|
+
});
|
|
1314
|
+
return q({ passed: t.every((i) => i.passed), decisions: t });
|
|
1315
|
+
}
|
|
1316
|
+
function Tt({
|
|
1317
|
+
rules: n = [],
|
|
1318
|
+
candidateItems: o = [],
|
|
1319
|
+
requirementInputs: e = [],
|
|
1320
|
+
requirementValues: t = {},
|
|
1321
|
+
variantSelections: i = []
|
|
1322
|
+
}) {
|
|
1323
|
+
const r = n.filter((s) => s.ruleType === S.REQUIREMENT).filter((s) => o.some((c) => w(s.appliesTo, c))).flatMap((s) => o.filter((c) => w(s.appliesTo, c)).flatMap((c) => Array.from({ length: c.quantity }, (d, a) => {
|
|
1324
|
+
var p;
|
|
1325
|
+
const l = s.details.requirement, f = l.requirementCode, O = e.find((y) => y.productCode === c.productCode && y.requirementCode === f), N = t[f], g = Array.isArray(N) ? N : [N || {}], E = O && a < O.inputs.length ? O.inputs[a] || {} : g[a] || {}, R = (p = i.find((y) => y.productCode === c.productCode)) == null ? void 0 : p.selections[a], b = Object.fromEntries(l.fields.map((y) => y.inputType === "VARIANT" ? [y.fieldCode, (R == null ? void 0 : R.variantCode) || ""] : [y.fieldCode, E[y.fieldCode] || ""])), C = l.fields.map((y) => y.fieldCode).filter((y) => typeof b[y] != "string" || b[y].trim().length === 0);
|
|
1326
|
+
return {
|
|
1327
|
+
ruleCode: s.publishedRuleCode,
|
|
1328
|
+
requirement: l,
|
|
1329
|
+
productCode: c.productCode,
|
|
1330
|
+
componentIndex: c.componentIndex,
|
|
1331
|
+
unitIndex: a,
|
|
1332
|
+
completionTiming: s.details.completionTiming || de.BEFORE_ITEM_VALID,
|
|
1333
|
+
modificationMode: s.details.modificationMode,
|
|
1334
|
+
...s.details.completionDeadline ? { completionDeadline: s.details.completionDeadline } : {},
|
|
1335
|
+
...s.details.modificationDeadline ? { modificationDeadline: s.details.modificationDeadline } : {},
|
|
1336
|
+
values: D(b),
|
|
1337
|
+
missingFields: C,
|
|
1338
|
+
complete: C.length === 0
|
|
1339
|
+
};
|
|
1340
|
+
})));
|
|
1341
|
+
return q({
|
|
1342
|
+
passed: !0,
|
|
1343
|
+
itemValid: r.every((s) => s.complete),
|
|
1344
|
+
code: r.every((s) => s.complete) ? null : A.REQUIREMENT_INCOMPLETE,
|
|
1345
|
+
plans: r
|
|
1346
|
+
});
|
|
1347
|
+
}
|
|
1348
|
+
function Gt({ requirementPlan: n = {}, rule: o, instant: e }) {
|
|
1349
|
+
if (!o || o.ruleType !== S.REQUIREMENT)
|
|
1350
|
+
throw new TypeError("rule must be a REQUIREMENT PublishedRule");
|
|
1351
|
+
const t = Date.parse(e);
|
|
1352
|
+
if (!Number.isFinite(t))
|
|
1353
|
+
throw new TypeError("instant must be an ISO-8601 timestamp");
|
|
1354
|
+
const i = o.details, r = !!(i.completionDeadline && t >= Date.parse(i.completionDeadline)), s = n.complete ? ie.COMPLETE : r ? ie.OVERDUE : ie.INCOMPLETE;
|
|
1355
|
+
let c = H.EDITABLE, d = null;
|
|
1356
|
+
return i.modificationMode === Q.LOCK_AFTER_COMPLETE && n.complete ? (c = H.LOCKED, d = "REQUIREMENT_COMPLETE") : i.modificationMode === Q.UNTIL_DEADLINE && t >= Date.parse(i.modificationDeadline) && (c = H.LOCKED, d = "MODIFICATION_DEADLINE_PASSED"), q({
|
|
1357
|
+
requirementCode: i.requirement.requirementCode,
|
|
1358
|
+
completionState: s,
|
|
1359
|
+
modificationState: c,
|
|
1360
|
+
canModify: c === H.EDITABLE,
|
|
1361
|
+
modificationReason: d,
|
|
1362
|
+
completionDeadline: i.completionDeadline || null,
|
|
1363
|
+
modificationDeadline: i.modificationDeadline || null,
|
|
1364
|
+
evaluated: e
|
|
1365
|
+
});
|
|
1366
|
+
}
|
|
1367
|
+
function gt(n, o) {
|
|
1368
|
+
const e = Date.parse(o);
|
|
1369
|
+
return !(!Number.isFinite(e) || n.validFrom && e < Date.parse(n.validFrom) || n.validUntil && e >= Date.parse(n.validUntil));
|
|
1370
|
+
}
|
|
1371
|
+
function bt(n, o, e) {
|
|
1372
|
+
const t = n.countryCodes || [], i = n.excludedCountryCodes || [];
|
|
1373
|
+
return t.length > 0 && !t.includes(o) || i.includes(o) ? !1 : n.countryRank ? !(!Number.isInteger(e) || e < 1 || n.countryRank.min && e < n.countryRank.min || n.countryRank.max && e > n.countryRank.max) : !0;
|
|
1374
|
+
}
|
|
1375
|
+
function we({ match: n, countryCode: o, countryRank: e }) {
|
|
1376
|
+
if (typeof o != "string" || o.trim().length === 0 || !Number.isInteger(e) || e < 1)
|
|
1377
|
+
return $({
|
|
1378
|
+
passed: !1,
|
|
1379
|
+
code: A.PRICE_COUNTRY_UNRESOLVED,
|
|
1380
|
+
message: "Country code and rank are required to evaluate price match criteria",
|
|
1381
|
+
details: { countryCode: o || null, countryRank: e ?? null }
|
|
1382
|
+
});
|
|
1383
|
+
const t = bt(n, o, e);
|
|
1384
|
+
return $({
|
|
1385
|
+
passed: t,
|
|
1386
|
+
...t ? {} : { code: A.PRICE_MATCH_CRITERIA_NOT_MET },
|
|
1387
|
+
message: t ? "Price match criteria passed" : "Price match criteria were not met",
|
|
1388
|
+
details: { countryCode: o, countryRank: e }
|
|
1389
|
+
});
|
|
1390
|
+
}
|
|
1391
|
+
function Ot({ priceSchedule: n, currency: o, countryCode: e, countryRank: t, acquisitionSource: i, instant: r }) {
|
|
1392
|
+
const s = we({ match: {}, countryCode: e, countryRank: t });
|
|
1393
|
+
if (!s.passed)
|
|
1394
|
+
return s;
|
|
1395
|
+
const c = n.rows.filter((d) => d.currency === o && we({ match: d.match, countryCode: e, countryRank: t }).passed && (d.acquisitionSources.length === 0 || d.acquisitionSources.includes(i)) && gt(d, r));
|
|
1396
|
+
return c.length === 0 ? $({
|
|
1397
|
+
passed: !1,
|
|
1398
|
+
code: A.PRICE_ROW_NOT_FOUND,
|
|
1399
|
+
message: "No price row matches the acquisition context",
|
|
1400
|
+
details: { currency: o, countryCode: e, countryRank: t, acquisitionSource: i, instant: r }
|
|
1401
|
+
}) : c.length > 1 ? $({
|
|
1402
|
+
passed: !1,
|
|
1403
|
+
code: A.PRICE_ROW_AMBIGUOUS,
|
|
1404
|
+
message: "More than one price row matches the acquisition context",
|
|
1405
|
+
details: { matchingPriceRowCodes: c.map((d) => d.priceRowCode) }
|
|
1406
|
+
}) : $({
|
|
1407
|
+
passed: !0,
|
|
1408
|
+
message: "Price row resolved",
|
|
1409
|
+
details: { countryCode: e, countryRank: t, matchedPriceRow: c[0] }
|
|
1410
|
+
});
|
|
1411
|
+
}
|
|
1412
|
+
function Dt({ rules: n = [], candidateItems: o = [], inventoryFacts: e = [], variantSelections: t = [] }) {
|
|
1413
|
+
const i = n.filter((r) => r.ruleType === S.INVENTORY).filter((r) => o.some((s) => w(r.appliesTo, s))).map((r) => {
|
|
1414
|
+
const s = J(o, r.appliesTo), c = t.find((m) => m.productCode === r.appliesTo.code), d = Array.from({ length: s }, (m, E) => (c == null ? void 0 : c.selections[E]) || null), a = d.length === s && d.every(Boolean), f = [...d.reduce((m, E) => {
|
|
1415
|
+
const b = (E == null ? void 0 : E.variantCode) || "UNSELECTED";
|
|
1416
|
+
return m.set(b, (m.get(b) || 0) + 1), m;
|
|
1417
|
+
}, /* @__PURE__ */ new Map())].map(([m, E]) => {
|
|
1418
|
+
const R = e.find((b) => b.inventoryPoolCode === r.details.inventoryPoolCode && (m === "UNSELECTED" || b.variantCode === m));
|
|
1419
|
+
return {
|
|
1420
|
+
variantCode: m === "UNSELECTED" ? null : m,
|
|
1421
|
+
requested: E,
|
|
1422
|
+
available: (R == null ? void 0 : R.available) ?? 0,
|
|
1423
|
+
revision: (R == null ? void 0 : R.revision) ?? null
|
|
1424
|
+
};
|
|
1425
|
+
}), O = r.details.inventoryMode === se.STOCKED_VARIANT && !a, N = f.every((m) => m.available >= m.requested), g = r.details.inventoryMode === se.PRODUCTION_DEMAND || !O && N;
|
|
1426
|
+
return $({
|
|
1427
|
+
passed: g,
|
|
1428
|
+
...g ? {} : { code: O ? A.VARIANT_SELECTION_REQUIRED : A.INVENTORY_UNAVAILABLE },
|
|
1429
|
+
message: g ? "Inventory rule passed" : O ? "A Variant must be selected for every unit" : "Inventory is unavailable",
|
|
1430
|
+
details: {
|
|
1431
|
+
ruleCode: r.publishedRuleCode,
|
|
1432
|
+
inventoryMode: r.details.inventoryMode,
|
|
1433
|
+
inventoryPoolCode: r.details.inventoryPoolCode,
|
|
1434
|
+
requested: s,
|
|
1435
|
+
requests: f,
|
|
1436
|
+
intent: g ? { type: "RESERVE_OR_RECORD_DEMAND", requests: f } : null
|
|
1437
|
+
}
|
|
1438
|
+
});
|
|
1439
|
+
});
|
|
1440
|
+
return q({ passed: i.every((r) => r.passed), decisions: i });
|
|
1441
|
+
}
|
|
1442
|
+
function Nt({ merchandise: n, products: o, quantity: e }) {
|
|
1443
|
+
const t = new Map(o.map((i) => [i.productCode, i]));
|
|
1444
|
+
return n.components.map((i, r) => {
|
|
1445
|
+
const s = t.get(i.productCode);
|
|
1446
|
+
if (!s)
|
|
1447
|
+
throw new Error(`Product ${i.productCode} is not available for Merchandise ${n.merchandiseCode}`);
|
|
1448
|
+
return {
|
|
1449
|
+
productCode: s.productCode,
|
|
1450
|
+
productVersion: s.version,
|
|
1451
|
+
categoryCodes: s.categoryCodes,
|
|
1452
|
+
merchandiseCode: n.merchandiseCode,
|
|
1453
|
+
componentIndex: r,
|
|
1454
|
+
quantity: e * i.quantityPerUnit,
|
|
1455
|
+
state: P.VALID
|
|
1456
|
+
};
|
|
1457
|
+
});
|
|
1458
|
+
}
|
|
1459
|
+
function At(n, o) {
|
|
1460
|
+
return n.flatMap((e) => Array.from({ length: e.quantity }, (t, i) => {
|
|
1461
|
+
const r = o.filter((s) => s.componentIndex === e.componentIndex && s.unitIndex === i);
|
|
1462
|
+
return {
|
|
1463
|
+
...e,
|
|
1464
|
+
quantity: 1,
|
|
1465
|
+
state: r.every((s) => s.complete) ? P.VALID : P.PENDING_REQUIREMENT
|
|
1466
|
+
};
|
|
1467
|
+
}));
|
|
1468
|
+
}
|
|
1469
|
+
function je({ items: n, path: o, productDefinitions: e }, t) {
|
|
1470
|
+
return n.map((i, r) => {
|
|
1471
|
+
const s = e.filter((d) => d.productCode === i.productCode && d.version === i.productVersion);
|
|
1472
|
+
return s.length !== 1 && t.push({
|
|
1473
|
+
path: `${o}[${r}].productCode`,
|
|
1474
|
+
message: s.length === 0 ? `Product ${i.productCode}@${i.productVersion} is missing from recipient Product definitions` : `Product ${i.productCode}@${i.productVersion} is ambiguous in recipient Product definitions`
|
|
1475
|
+
}), {
|
|
1476
|
+
...typeof i.toObject == "function" ? i.toObject() : i,
|
|
1477
|
+
categoryCodes: s.length === 1 ? [...s[0].categoryCodes] : []
|
|
1478
|
+
};
|
|
1479
|
+
});
|
|
1480
|
+
}
|
|
1481
|
+
function St({ acquisitionSnapshots: n, items: o, path: e }, t) {
|
|
1482
|
+
return o.map((i, r) => {
|
|
1483
|
+
var d, a;
|
|
1484
|
+
const s = n.filter((l) => l.id === i.acquisitionCode), c = (a = (d = s[0]) == null ? void 0 : d.merchandise) == null ? void 0 : a.merchandiseCode;
|
|
1485
|
+
return (s.length !== 1 || !c) && t.push({
|
|
1486
|
+
path: `${e}[${r}].acquisitionCode`,
|
|
1487
|
+
message: s.length === 0 ? `Acquisition ${i.acquisitionCode} is missing from recipient Acquisition snapshots` : s.length > 1 ? `Acquisition ${i.acquisitionCode} is ambiguous in recipient Acquisition snapshots` : `Acquisition ${i.acquisitionCode} does not contain a Merchandise code`
|
|
1488
|
+
}), {
|
|
1489
|
+
...i,
|
|
1490
|
+
...c ? { merchandiseCode: c } : {}
|
|
1491
|
+
};
|
|
1492
|
+
});
|
|
1493
|
+
}
|
|
1494
|
+
function Pt(n, o) {
|
|
1495
|
+
if (!Array.isArray(n))
|
|
1496
|
+
return o.push({ path: "variantSelections", message: "variantSelections must be an array" }), [];
|
|
1497
|
+
const e = /* @__PURE__ */ new Set();
|
|
1498
|
+
return n.flatMap((t, i) => {
|
|
1499
|
+
const r = `variantSelections[${i}]`;
|
|
1500
|
+
if (!t || typeof t != "object" || Array.isArray(t))
|
|
1501
|
+
return o.push({ path: r, message: "variant selection group must be an object" }), [];
|
|
1502
|
+
const s = typeof t.productCode == "string" ? t.productCode.trim() : "";
|
|
1503
|
+
if (s ? e.has(s) ? o.push({ path: `${r}.productCode`, message: `duplicate Product ${s}` }) : e.add(s) : o.push({ path: `${r}.productCode`, message: "productCode must be a non-empty string" }), !Array.isArray(t.selections))
|
|
1504
|
+
return o.push({ path: `${r}.selections`, message: "selections must be an array" }), [{ productCode: s, selections: [] }];
|
|
1505
|
+
const c = t.selections.flatMap((d, a) => {
|
|
1506
|
+
if (d === null)
|
|
1507
|
+
return [null];
|
|
1508
|
+
try {
|
|
1509
|
+
return [(d instanceof Le ? d : new Le(d)).toObject()];
|
|
1510
|
+
} catch (l) {
|
|
1511
|
+
return o.push({ path: `${r}.selections[${a}]`, message: l.message }), [];
|
|
1512
|
+
}
|
|
1513
|
+
});
|
|
1514
|
+
return [{ productCode: s, selections: c }];
|
|
1515
|
+
});
|
|
1516
|
+
}
|
|
1517
|
+
function _t(n, o) {
|
|
1518
|
+
if (!Array.isArray(n))
|
|
1519
|
+
return o.push({ path: "requirementInputs", message: "requirementInputs must be an array" }), [];
|
|
1520
|
+
const e = /* @__PURE__ */ new Set();
|
|
1521
|
+
return n.flatMap((t, i) => {
|
|
1522
|
+
const r = `requirementInputs[${i}]`;
|
|
1523
|
+
if (!t || typeof t != "object" || Array.isArray(t))
|
|
1524
|
+
return o.push({ path: r, message: "requirement input group must be an object" }), [];
|
|
1525
|
+
const s = typeof t.productCode == "string" ? t.productCode.trim() : "", c = typeof t.requirementCode == "string" ? t.requirementCode.trim() : "";
|
|
1526
|
+
s || o.push({ path: `${r}.productCode`, message: "productCode must be a non-empty string" }), c || o.push({ path: `${r}.requirementCode`, message: "requirementCode must be a non-empty string" });
|
|
1527
|
+
const d = `${s}:${c}`;
|
|
1528
|
+
if (s && c && e.has(d) && o.push({ path: r, message: `duplicate Requirement ${c} for Product ${s}` }), e.add(d), !Array.isArray(t.inputs))
|
|
1529
|
+
return o.push({ path: `${r}.inputs`, message: "inputs must be an array" }), [{ productCode: s, requirementCode: c, inputs: [] }];
|
|
1530
|
+
const a = t.inputs.map((l, f) => l === null ? null : !l || typeof l != "object" || Array.isArray(l) ? (o.push({ path: `${r}.inputs[${f}]`, message: "input must be an object or null" }), null) : D(l));
|
|
1531
|
+
return [{ productCode: s, requirementCode: c, inputs: a }];
|
|
1532
|
+
});
|
|
1533
|
+
}
|
|
1534
|
+
function Vt({ categories: n, merchandise: o, priceSchedule: e, products: t, variants: i }, r) {
|
|
1535
|
+
const s = o.tenantCode;
|
|
1536
|
+
[e, ...n, ...t, ...i].forEach((d) => {
|
|
1537
|
+
var a;
|
|
1538
|
+
d.tenantCode !== s && r.push({
|
|
1539
|
+
path: `${d._type || ((a = d.constructor) == null ? void 0 : a.name) || "definition"}.tenantCode`,
|
|
1540
|
+
message: `expected ${s} but received ${d.tenantCode}`
|
|
1541
|
+
});
|
|
1542
|
+
});
|
|
1543
|
+
}
|
|
1544
|
+
function Mt({ merchandise: n, variants: o, variantSelections: e }, t) {
|
|
1545
|
+
const i = new Map(n.components.map((r) => [r.productCode, r]));
|
|
1546
|
+
e.forEach((r, s) => {
|
|
1547
|
+
const { productCode: c, selections: d } = r, a = `variantSelections[${s}]`, l = i.get(c);
|
|
1548
|
+
if (!l) {
|
|
1549
|
+
t.push({
|
|
1550
|
+
path: `${a}.productCode`,
|
|
1551
|
+
message: `Product ${c} is not a Merchandise component`
|
|
1552
|
+
});
|
|
1553
|
+
return;
|
|
1554
|
+
}
|
|
1555
|
+
d.filter(Boolean).forEach((f, O) => {
|
|
1556
|
+
const N = o.filter((m) => m.variantCode === f.variantCode && m.version === f.variantVersion);
|
|
1557
|
+
if (N.length !== 1) {
|
|
1558
|
+
t.push({
|
|
1559
|
+
path: `${a}.selections[${O}]`,
|
|
1560
|
+
message: N.length === 0 ? `Variant ${f.variantCode}@${f.variantVersion} is missing` : `Variant ${f.variantCode}@${f.variantVersion} is ambiguous`
|
|
1561
|
+
});
|
|
1562
|
+
return;
|
|
1563
|
+
}
|
|
1564
|
+
const [g] = N;
|
|
1565
|
+
(g.productCode !== c || g.productVersion !== l.productVersion) && t.push({
|
|
1566
|
+
path: `${a}.selections[${O}]`,
|
|
1567
|
+
message: `Variant ${f.variantCode}@${f.variantVersion} does not belong to Product ${c}@${l.productVersion}`
|
|
1568
|
+
});
|
|
1569
|
+
});
|
|
1570
|
+
});
|
|
1571
|
+
}
|
|
1572
|
+
function qt({
|
|
1573
|
+
categories: n = [],
|
|
1574
|
+
merchandise: o,
|
|
1575
|
+
priceSchedule: e,
|
|
1576
|
+
products: t = [],
|
|
1577
|
+
quantity: i,
|
|
1578
|
+
requirementInputs: r = [],
|
|
1579
|
+
variants: s = [],
|
|
1580
|
+
variantSelections: c = []
|
|
1581
|
+
}) {
|
|
1582
|
+
const d = [], a = Pt(c, d), l = _t(r, d);
|
|
1583
|
+
(!Number.isInteger(i) || i < 1) && d.push({ path: "quantity", message: "quantity must be a positive integer" }), Vt({ categories: n, merchandise: o, priceSchedule: e, products: t, variants: s }, d), e.priceScheduleCode !== o.priceScheduleCode && d.push({
|
|
1584
|
+
path: "priceSchedule.priceScheduleCode",
|
|
1585
|
+
message: `expected ${o.priceScheduleCode} but received ${e.priceScheduleCode}`
|
|
1586
|
+
});
|
|
1587
|
+
const f = t.reduce((m, E) => {
|
|
1588
|
+
const R = m.get(E.productCode) || [];
|
|
1589
|
+
return R.push(E), m.set(E.productCode, R), m;
|
|
1590
|
+
}, /* @__PURE__ */ new Map()), O = n.reduce((m, E) => (m.set(E.categoryCode, (m.get(E.categoryCode) || 0) + 1), m), /* @__PURE__ */ new Map()), N = /* @__PURE__ */ new Set();
|
|
1591
|
+
o.components.forEach((m, E) => {
|
|
1592
|
+
const R = `${m.productCode}@${m.productVersion}`;
|
|
1593
|
+
N.has(R) && d.push({
|
|
1594
|
+
path: `merchandise.components[${E}]`,
|
|
1595
|
+
message: `duplicate component ${R}; use quantityPerUnit instead`
|
|
1596
|
+
}), N.add(R);
|
|
1597
|
+
const b = f.get(m.productCode) || [];
|
|
1598
|
+
b.length === 0 ? d.push({
|
|
1599
|
+
path: `merchandise.components[${E}].productCode`,
|
|
1600
|
+
message: `Product ${m.productCode} is missing`
|
|
1601
|
+
}) : b.length > 1 ? d.push({
|
|
1602
|
+
path: `merchandise.components[${E}].productCode`,
|
|
1603
|
+
message: `Product ${m.productCode} is ambiguous`
|
|
1604
|
+
}) : b[0].version !== m.productVersion ? d.push({
|
|
1605
|
+
path: `merchandise.components[${E}].productVersion`,
|
|
1606
|
+
message: `expected Product version ${m.productVersion} but received ${b[0].version}`
|
|
1607
|
+
}) : b[0].categoryCodes.forEach((C) => {
|
|
1608
|
+
const p = O.get(C) || 0;
|
|
1609
|
+
p !== 1 && d.push({
|
|
1610
|
+
path: `products.${m.productCode}.categoryCodes`,
|
|
1611
|
+
message: p === 0 ? `Category ${C} is missing` : `Category ${C} is ambiguous`
|
|
1612
|
+
});
|
|
1613
|
+
});
|
|
1614
|
+
}), Mt({
|
|
1615
|
+
merchandise: o,
|
|
1616
|
+
variants: s,
|
|
1617
|
+
variantSelections: a
|
|
1618
|
+
}, d);
|
|
1619
|
+
const g = new Set(o.components.map((m) => m.productCode));
|
|
1620
|
+
return l.forEach((m, E) => {
|
|
1621
|
+
g.has(m.productCode) || d.push({
|
|
1622
|
+
path: `requirementInputs[${E}].productCode`,
|
|
1623
|
+
message: `Product ${m.productCode} is not a Merchandise component`
|
|
1624
|
+
});
|
|
1625
|
+
}), $({
|
|
1626
|
+
passed: d.length === 0,
|
|
1627
|
+
...d.length === 0 ? {} : { code: A.DEFINITION_INVALID },
|
|
1628
|
+
message: d.length === 0 ? "Acquisition definitions are consistent" : "Acquisition definitions are inconsistent",
|
|
1629
|
+
details: {
|
|
1630
|
+
issues: d,
|
|
1631
|
+
requirementInputs: l,
|
|
1632
|
+
variantSelections: a
|
|
1633
|
+
}
|
|
1634
|
+
});
|
|
1635
|
+
}
|
|
1636
|
+
function Kt({
|
|
1637
|
+
acquisitionSource: n,
|
|
1638
|
+
categories: o,
|
|
1639
|
+
countryCode: e,
|
|
1640
|
+
countryRank: t,
|
|
1641
|
+
currency: i,
|
|
1642
|
+
eligibilityFacts: r = [],
|
|
1643
|
+
eventRegistrationCode: s,
|
|
1644
|
+
existingItems: c = [],
|
|
1645
|
+
instant: d,
|
|
1646
|
+
inventoryFacts: a = [],
|
|
1647
|
+
merchandise: l,
|
|
1648
|
+
priceSchedule: f,
|
|
1649
|
+
products: O,
|
|
1650
|
+
publishedRules: N,
|
|
1651
|
+
quantity: g = 1,
|
|
1652
|
+
requirementInputs: m = [],
|
|
1653
|
+
requirementValues: E = {},
|
|
1654
|
+
variants: R = [],
|
|
1655
|
+
variantSelections: b = [],
|
|
1656
|
+
recipientFacts: C
|
|
1657
|
+
}) {
|
|
1658
|
+
const p = (C == null ? void 0 : C.eligibilityFacts) || r, y = (C == null ? void 0 : C.existingWalletItems) || (C == null ? void 0 : C.existingItems) || c, h = (C == null ? void 0 : C.projectedItems) || [], W = (C == null ? void 0 : C.eventRegistrationCode) || s, U = qt({
|
|
1659
|
+
categories: o,
|
|
1660
|
+
merchandise: l,
|
|
1661
|
+
priceSchedule: f,
|
|
1662
|
+
products: O,
|
|
1663
|
+
quantity: g,
|
|
1664
|
+
requirementInputs: m,
|
|
1665
|
+
variants: R,
|
|
1666
|
+
variantSelections: b
|
|
1667
|
+
}), B = [], ae = (C == null ? void 0 : C.productDefinitions) || O, Qe = je({
|
|
1668
|
+
items: y,
|
|
1669
|
+
path: "recipientFacts.existingWalletItems",
|
|
1670
|
+
productDefinitions: ae
|
|
1671
|
+
}, B), ue = St({
|
|
1672
|
+
acquisitionSnapshots: (C == null ? void 0 : C.acquisitionSnapshots) || [],
|
|
1673
|
+
items: Qe,
|
|
1674
|
+
path: "recipientFacts.existingWalletItems"
|
|
1675
|
+
}, B), Be = je({
|
|
1676
|
+
items: h,
|
|
1677
|
+
path: "recipientFacts.projectedItems",
|
|
1678
|
+
productDefinitions: ae
|
|
1679
|
+
}, B), Fe = [
|
|
1680
|
+
...U.details.issues,
|
|
1681
|
+
...B
|
|
1682
|
+
], Y = B.length === 0 ? U : $({
|
|
1683
|
+
passed: !1,
|
|
1684
|
+
code: A.DEFINITION_INVALID,
|
|
1685
|
+
message: "Acquisition definitions are inconsistent",
|
|
1686
|
+
details: {
|
|
1687
|
+
...U.details,
|
|
1688
|
+
issues: Fe
|
|
1689
|
+
}
|
|
1690
|
+
}), v = lt({ categories: o, products: O, merchandise: l, acquisitionSource: n, publishedRules: N }), F = Y.passed ? Nt({ merchandise: l, products: O, quantity: g }) : [], te = Y.details.variantSelections, le = Y.details.requirementInputs, pe = yt({
|
|
1691
|
+
rules: v.rules,
|
|
1692
|
+
eligibilityFacts: p,
|
|
1693
|
+
eventRegistrationCode: W,
|
|
1694
|
+
candidateItems: F
|
|
1695
|
+
}), ne = Tt({
|
|
1696
|
+
rules: v.rules,
|
|
1697
|
+
candidateItems: F,
|
|
1698
|
+
requirementInputs: le,
|
|
1699
|
+
requirementValues: E,
|
|
1700
|
+
variantSelections: te
|
|
1701
|
+
}), me = [
|
|
1702
|
+
...Be,
|
|
1703
|
+
...At(F, ne.plans)
|
|
1704
|
+
], oe = Ct({
|
|
1705
|
+
rules: v.rules,
|
|
1706
|
+
existingItems: ue,
|
|
1707
|
+
candidateItems: me
|
|
1708
|
+
}), fe = ht({
|
|
1709
|
+
rules: v.rules,
|
|
1710
|
+
existingItems: ue,
|
|
1711
|
+
candidateItems: me
|
|
1712
|
+
}), Ce = Ot({ priceSchedule: f, currency: i, countryCode: e, countryRank: t, acquisitionSource: n, instant: d }), Ee = Dt({
|
|
1713
|
+
rules: v.rules,
|
|
1714
|
+
candidateItems: F,
|
|
1715
|
+
inventoryFacts: a,
|
|
1716
|
+
variantSelections: te
|
|
1717
|
+
}), ke = oe.decisions.filter((j) => j.details.limitType === K.ORDER).every((j) => j.passed), Ge = oe.decisions.filter((j) => j.details.limitType !== K.ORDER).every((j) => j.passed), ye = Y.passed && v.passed && ke && Ce.passed && Ee.passed, Ie = Ge, Re = Y.passed && v.passed && pe.passed && Ie && fe.passed, he = ye && Re;
|
|
1718
|
+
return q({
|
|
1719
|
+
passed: he,
|
|
1720
|
+
canPurchase: ye,
|
|
1721
|
+
canAcquire: Re,
|
|
1722
|
+
canHold: Ie,
|
|
1723
|
+
itemValid: he && ne.itemValid,
|
|
1724
|
+
candidateItems: F,
|
|
1725
|
+
requirementInputs: le,
|
|
1726
|
+
variantSelections: te,
|
|
1727
|
+
effectiveRules: v,
|
|
1728
|
+
evaluations: {
|
|
1729
|
+
definitions: Y,
|
|
1730
|
+
eligibility: pe,
|
|
1731
|
+
quantity: oe,
|
|
1732
|
+
prerequisites: fe,
|
|
1733
|
+
requirements: ne,
|
|
1734
|
+
price: Ce,
|
|
1735
|
+
inventory: Ee
|
|
1736
|
+
}
|
|
1737
|
+
});
|
|
1738
|
+
}
|
|
1739
|
+
function Wt({ id: n, evaluated: o, preview: e, context: t }) {
|
|
1740
|
+
if (!e.passed)
|
|
1741
|
+
throw new Error("Cannot snapshot a failed acquisition preview");
|
|
1742
|
+
const i = typeof t.merchandise.toObject == "function" ? t.merchandise.toObject() : D(t.merchandise), r = t.products.map((s) => typeof s.toObject == "function" ? s.toObject() : D(s));
|
|
1743
|
+
return new Xe({
|
|
1744
|
+
id: n,
|
|
1745
|
+
contractVersion: 2,
|
|
1746
|
+
eventRegistrationCode: t.eventRegistrationCode,
|
|
1747
|
+
purchaserEventRegistrationCode: t.purchaserEventRegistrationCode || t.eventRegistrationCode,
|
|
1748
|
+
payerEventRegistrationCode: t.payerEventRegistrationCode || t.eventRegistrationCode,
|
|
1749
|
+
acquisitionSource: t.acquisitionSource,
|
|
1750
|
+
merchandise: i,
|
|
1751
|
+
quantity: t.quantity,
|
|
1752
|
+
products: r,
|
|
1753
|
+
priceScheduleRef: {
|
|
1754
|
+
priceScheduleCode: t.priceSchedule.priceScheduleCode,
|
|
1755
|
+
priceScheduleVersion: t.priceSchedule.version
|
|
1756
|
+
},
|
|
1757
|
+
matchedPriceRow: e.evaluations.price.details.matchedPriceRow,
|
|
1758
|
+
priceEvaluationContext: {
|
|
1759
|
+
acquisitionSource: t.acquisitionSource,
|
|
1760
|
+
countryCode: e.evaluations.price.details.countryCode,
|
|
1761
|
+
countryRank: e.evaluations.price.details.countryRank,
|
|
1762
|
+
currency: e.evaluations.price.details.matchedPriceRow.currency,
|
|
1763
|
+
instant: t.instant
|
|
1764
|
+
},
|
|
1765
|
+
effectiveRules: e.effectiveRules,
|
|
1766
|
+
eligibilityDecisions: e.evaluations.eligibility.decisions,
|
|
1767
|
+
requirementPlans: e.evaluations.requirements.plans,
|
|
1768
|
+
inventoryDecisions: e.evaluations.inventory.decisions,
|
|
1769
|
+
variantSelections: e.variantSelections,
|
|
1770
|
+
evaluated: o
|
|
1771
|
+
});
|
|
1772
|
+
}
|
|
1773
|
+
function Ht({ acquisitionSnapshot: n, walletItemIdFactory: o }) {
|
|
1774
|
+
const e = [];
|
|
1775
|
+
return n.merchandise.components.forEach((t, i) => {
|
|
1776
|
+
const r = n.quantity * t.quantityPerUnit;
|
|
1777
|
+
for (let s = 0; s < r; s += 1) {
|
|
1778
|
+
const c = n.requirementPlans.filter((l) => l.componentIndex === i && l.unitIndex === s), d = n.variantSelections.find((l) => l.productCode === t.productCode), a = d == null ? void 0 : d.selections[s];
|
|
1779
|
+
e.push({
|
|
1780
|
+
walletItemCode: o({ component: t, index: s, acquisitionSnapshot: n }),
|
|
1781
|
+
eventRegistrationCode: n.eventRegistrationCode,
|
|
1782
|
+
productCode: t.productCode,
|
|
1783
|
+
productVersion: t.productVersion,
|
|
1784
|
+
acquisitionCode: n.id,
|
|
1785
|
+
quantity: 1,
|
|
1786
|
+
variantCode: (a == null ? void 0 : a.variantCode) || null,
|
|
1787
|
+
variantVersion: (a == null ? void 0 : a.variantVersion) || null,
|
|
1788
|
+
state: c.every((l) => l.complete) ? P.VALID : P.PENDING_REQUIREMENT,
|
|
1789
|
+
requirementPlans: c.map((l) => ({ ...l, unitIndex: 0 }))
|
|
1790
|
+
});
|
|
1791
|
+
}
|
|
1792
|
+
}), q(e);
|
|
1793
|
+
}
|
|
1794
|
+
const Jt = 2;
|
|
1795
|
+
export {
|
|
1796
|
+
Xe as AcquisitionSnapshot,
|
|
1797
|
+
Lt as Category,
|
|
1798
|
+
Ut as Currency,
|
|
1799
|
+
A as DECISION_CODES,
|
|
1800
|
+
mt as DEFAULT_ACTIVE_ITEM_STATES,
|
|
1801
|
+
x as ELIGIBILITY_STATES,
|
|
1802
|
+
vt as EligibilityFact,
|
|
1803
|
+
se as INVENTORY_MODES,
|
|
1804
|
+
ce as MATCH_MODES,
|
|
1805
|
+
wt as Merchandise,
|
|
1806
|
+
Ae as MerchandiseComponent,
|
|
1807
|
+
k as PREREQUISITE_EVIDENCE_SOURCES,
|
|
1808
|
+
Te as PriceEvaluationContext,
|
|
1809
|
+
Pe as PriceMatchCriteria,
|
|
1810
|
+
Me as PriceRow,
|
|
1811
|
+
jt as PriceSchedule,
|
|
1812
|
+
ge as PriceScheduleRef,
|
|
1813
|
+
xt as Product,
|
|
1814
|
+
zt as PublishedRule,
|
|
1815
|
+
Yt as PublishedRuleRef,
|
|
1816
|
+
K as QUANTITY_LIMIT_TYPES,
|
|
1817
|
+
ie as REQUIREMENT_COMPLETION_STATES,
|
|
1818
|
+
de as REQUIREMENT_COMPLETION_TIMINGS,
|
|
1819
|
+
re as REQUIREMENT_INPUT_TYPES,
|
|
1820
|
+
Q as REQUIREMENT_MODIFICATION_MODES,
|
|
1821
|
+
H as REQUIREMENT_MODIFICATION_STATES,
|
|
1822
|
+
V as RULE_SOURCES,
|
|
1823
|
+
S as RULE_TYPES,
|
|
1824
|
+
Qt as RefundPolicy,
|
|
1825
|
+
qe as RefundPolicyRef,
|
|
1826
|
+
X as RequirementDefinition,
|
|
1827
|
+
be as RequirementFieldDefinition,
|
|
1828
|
+
ee as RequirementPlan,
|
|
1829
|
+
Jt as STORE_MODEL_V2_CONTRACT_VERSION,
|
|
1830
|
+
Bt as SalesPeriod,
|
|
1831
|
+
_e as SalesPeriodRef,
|
|
1832
|
+
G as StoreContractValidationError,
|
|
1833
|
+
L as StoreEntity,
|
|
1834
|
+
_ as TARGET_TYPES,
|
|
1835
|
+
pt as TERMINAL_ITEM_STATES,
|
|
1836
|
+
Ft as Variant,
|
|
1837
|
+
Le as VariantRef,
|
|
1838
|
+
P as WALLET_ITEM_STATES,
|
|
1839
|
+
kt as WalletItem,
|
|
1840
|
+
lt as collectEffectiveRules,
|
|
1841
|
+
Wt as createAcquisitionSnapshot,
|
|
1842
|
+
Kt as evaluateAcquisitionPreview,
|
|
1843
|
+
yt as evaluateEligibilityRules,
|
|
1844
|
+
Dt as evaluateInventoryRules,
|
|
1845
|
+
ht as evaluatePrerequisiteRules,
|
|
1846
|
+
we as evaluatePriceMatchCriteria,
|
|
1847
|
+
Ct as evaluateQuantityRules,
|
|
1848
|
+
Gt as evaluateRequirementConfigurationState,
|
|
1849
|
+
Nt as expandCandidateItems,
|
|
1850
|
+
Tt as planItemRequirements,
|
|
1851
|
+
Ht as projectWalletItems,
|
|
1852
|
+
Ot as resolvePrice,
|
|
1853
|
+
qt as validateAcquisitionDefinitions
|
|
1854
|
+
};
|
|
1855
|
+
//# sourceMappingURL=q-store-model-v2.esm.js.map
|