@final-commerce/common 1.1.4-beta.4
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/README.md +224 -0
- package/bin/gate-done.mjs +161 -0
- package/bin/gate-i18n-sync.mjs +351 -0
- package/bin/gate-save.mjs +146 -0
- package/bin/gate-setup.mjs +227 -0
- package/bin/gate-start.mjs +101 -0
- package/bin/prepare-commit-msg.sh +16 -0
- package/commitlint/index.mjs +14 -0
- package/dist/index.d.mts +468 -0
- package/dist/index.d.ts +468 -0
- package/dist/index.js +2702 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2565 -0
- package/dist/index.mjs.map +1 -0
- package/dist/interfaces-6GnQyqYd.d.mts +598 -0
- package/dist/interfaces-6GnQyqYd.d.ts +598 -0
- package/dist/pos-types/index.d.mts +1782 -0
- package/dist/pos-types/index.d.ts +1782 -0
- package/dist/pos-types/index.js +144 -0
- package/dist/pos-types/index.js.map +1 -0
- package/dist/pos-types/index.mjs +114 -0
- package/dist/pos-types/index.mjs.map +1 -0
- package/eslint/backend-nestjs.mjs +30 -0
- package/eslint/frontend-react.mjs +27 -0
- package/eslint/library.mjs +19 -0
- package/lint-staged/index.mjs +4 -0
- package/package.json +160 -0
- package/prettier/index.json +10 -0
- package/typescript/backend-nestjs.json +13 -0
- package/typescript/base.json +13 -0
- package/typescript/frontend-react.json +15 -0
- package/typescript/library.json +12 -0
- package/vitest/backend.ts +20 -0
- package/vitest/frontend.ts +22 -0
- package/vitest/library.ts +20 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,2565 @@
|
|
|
1
|
+
// enums/currency.enum.ts
|
|
2
|
+
var CurrencyCode = /* @__PURE__ */ ((CurrencyCode2) => {
|
|
3
|
+
CurrencyCode2["USD"] = "USD";
|
|
4
|
+
CurrencyCode2["EUR"] = "EUR";
|
|
5
|
+
CurrencyCode2["GBP"] = "GBP";
|
|
6
|
+
CurrencyCode2["CAD"] = "CAD";
|
|
7
|
+
CurrencyCode2["AUD"] = "AUD";
|
|
8
|
+
CurrencyCode2["NZD"] = "NZD";
|
|
9
|
+
CurrencyCode2["CHF"] = "CHF";
|
|
10
|
+
CurrencyCode2["CNY"] = "CNY";
|
|
11
|
+
CurrencyCode2["INR"] = "INR";
|
|
12
|
+
CurrencyCode2["MXN"] = "MXN";
|
|
13
|
+
CurrencyCode2["BRL"] = "BRL";
|
|
14
|
+
CurrencyCode2["ZAR"] = "ZAR";
|
|
15
|
+
CurrencyCode2["SGD"] = "SGD";
|
|
16
|
+
CurrencyCode2["HKD"] = "HKD";
|
|
17
|
+
CurrencyCode2["SEK"] = "SEK";
|
|
18
|
+
CurrencyCode2["NOK"] = "NOK";
|
|
19
|
+
CurrencyCode2["DKK"] = "DKK";
|
|
20
|
+
CurrencyCode2["PLN"] = "PLN";
|
|
21
|
+
CurrencyCode2["THB"] = "THB";
|
|
22
|
+
CurrencyCode2["MYR"] = "MYR";
|
|
23
|
+
CurrencyCode2["PHP"] = "PHP";
|
|
24
|
+
CurrencyCode2["IDR"] = "IDR";
|
|
25
|
+
CurrencyCode2["AED"] = "AED";
|
|
26
|
+
CurrencyCode2["SAR"] = "SAR";
|
|
27
|
+
CurrencyCode2["ILS"] = "ILS";
|
|
28
|
+
CurrencyCode2["TRY"] = "TRY";
|
|
29
|
+
CurrencyCode2["RUB"] = "RUB";
|
|
30
|
+
CurrencyCode2["HTG"] = "HTG";
|
|
31
|
+
CurrencyCode2["BND"] = "BND";
|
|
32
|
+
CurrencyCode2["CRC"] = "CRC";
|
|
33
|
+
CurrencyCode2["BDT"] = "BDT";
|
|
34
|
+
CurrencyCode2["UAH"] = "UAH";
|
|
35
|
+
CurrencyCode2["NGN"] = "NGN";
|
|
36
|
+
CurrencyCode2["AFN"] = "AFN";
|
|
37
|
+
CurrencyCode2["ALL"] = "ALL";
|
|
38
|
+
CurrencyCode2["AMD"] = "AMD";
|
|
39
|
+
CurrencyCode2["ANG"] = "ANG";
|
|
40
|
+
CurrencyCode2["AOA"] = "AOA";
|
|
41
|
+
CurrencyCode2["ARS"] = "ARS";
|
|
42
|
+
CurrencyCode2["AWG"] = "AWG";
|
|
43
|
+
CurrencyCode2["AZN"] = "AZN";
|
|
44
|
+
CurrencyCode2["BAM"] = "BAM";
|
|
45
|
+
CurrencyCode2["BBD"] = "BBD";
|
|
46
|
+
CurrencyCode2["BGN"] = "BGN";
|
|
47
|
+
CurrencyCode2["BMD"] = "BMD";
|
|
48
|
+
CurrencyCode2["BOB"] = "BOB";
|
|
49
|
+
CurrencyCode2["BSD"] = "BSD";
|
|
50
|
+
CurrencyCode2["BTN"] = "BTN";
|
|
51
|
+
CurrencyCode2["BWP"] = "BWP";
|
|
52
|
+
CurrencyCode2["BYN"] = "BYN";
|
|
53
|
+
CurrencyCode2["BZD"] = "BZD";
|
|
54
|
+
CurrencyCode2["COP"] = "COP";
|
|
55
|
+
CurrencyCode2["CZK"] = "CZK";
|
|
56
|
+
CurrencyCode2["DOP"] = "DOP";
|
|
57
|
+
CurrencyCode2["DZD"] = "DZD";
|
|
58
|
+
CurrencyCode2["EGP"] = "EGP";
|
|
59
|
+
CurrencyCode2["ETB"] = "ETB";
|
|
60
|
+
CurrencyCode2["FJD"] = "FJD";
|
|
61
|
+
CurrencyCode2["GEL"] = "GEL";
|
|
62
|
+
CurrencyCode2["GHS"] = "GHS";
|
|
63
|
+
CurrencyCode2["GTQ"] = "GTQ";
|
|
64
|
+
CurrencyCode2["GYD"] = "GYD";
|
|
65
|
+
CurrencyCode2["HNL"] = "HNL";
|
|
66
|
+
CurrencyCode2["IRR"] = "IRR";
|
|
67
|
+
CurrencyCode2["JMD"] = "JMD";
|
|
68
|
+
CurrencyCode2["KES"] = "KES";
|
|
69
|
+
CurrencyCode2["KGS"] = "KGS";
|
|
70
|
+
CurrencyCode2["KHR"] = "KHR";
|
|
71
|
+
CurrencyCode2["KYD"] = "KYD";
|
|
72
|
+
CurrencyCode2["KZT"] = "KZT";
|
|
73
|
+
CurrencyCode2["LAK"] = "LAK";
|
|
74
|
+
CurrencyCode2["LBP"] = "LBP";
|
|
75
|
+
CurrencyCode2["LKR"] = "LKR";
|
|
76
|
+
CurrencyCode2["MAD"] = "MAD";
|
|
77
|
+
CurrencyCode2["MDL"] = "MDL";
|
|
78
|
+
CurrencyCode2["MKD"] = "MKD";
|
|
79
|
+
CurrencyCode2["MMK"] = "MMK";
|
|
80
|
+
CurrencyCode2["MNT"] = "MNT";
|
|
81
|
+
CurrencyCode2["MOP"] = "MOP";
|
|
82
|
+
CurrencyCode2["MUR"] = "MUR";
|
|
83
|
+
CurrencyCode2["MVR"] = "MVR";
|
|
84
|
+
CurrencyCode2["MZN"] = "MZN";
|
|
85
|
+
CurrencyCode2["NAD"] = "NAD";
|
|
86
|
+
CurrencyCode2["NIO"] = "NIO";
|
|
87
|
+
CurrencyCode2["NPR"] = "NPR";
|
|
88
|
+
CurrencyCode2["PAB"] = "PAB";
|
|
89
|
+
CurrencyCode2["PEN"] = "PEN";
|
|
90
|
+
CurrencyCode2["PGK"] = "PGK";
|
|
91
|
+
CurrencyCode2["PKR"] = "PKR";
|
|
92
|
+
CurrencyCode2["QAR"] = "QAR";
|
|
93
|
+
CurrencyCode2["RON"] = "RON";
|
|
94
|
+
CurrencyCode2["RSD"] = "RSD";
|
|
95
|
+
CurrencyCode2["SBD"] = "SBD";
|
|
96
|
+
CurrencyCode2["SRD"] = "SRD";
|
|
97
|
+
CurrencyCode2["SYP"] = "SYP";
|
|
98
|
+
CurrencyCode2["TJS"] = "TJS";
|
|
99
|
+
CurrencyCode2["TMT"] = "TMT";
|
|
100
|
+
CurrencyCode2["TOP"] = "TOP";
|
|
101
|
+
CurrencyCode2["TTD"] = "TTD";
|
|
102
|
+
CurrencyCode2["TZS"] = "TZS";
|
|
103
|
+
CurrencyCode2["UYU"] = "UYU";
|
|
104
|
+
CurrencyCode2["UZS"] = "UZS";
|
|
105
|
+
CurrencyCode2["VES"] = "VES";
|
|
106
|
+
CurrencyCode2["WST"] = "WST";
|
|
107
|
+
CurrencyCode2["XCD"] = "XCD";
|
|
108
|
+
CurrencyCode2["YER"] = "YER";
|
|
109
|
+
CurrencyCode2["ZMW"] = "ZMW";
|
|
110
|
+
CurrencyCode2["CDF"] = "CDF";
|
|
111
|
+
CurrencyCode2["CUP"] = "CUP";
|
|
112
|
+
CurrencyCode2["ERN"] = "ERN";
|
|
113
|
+
CurrencyCode2["FKP"] = "FKP";
|
|
114
|
+
CurrencyCode2["GIP"] = "GIP";
|
|
115
|
+
CurrencyCode2["GMD"] = "GMD";
|
|
116
|
+
CurrencyCode2["KPW"] = "KPW";
|
|
117
|
+
CurrencyCode2["LRD"] = "LRD";
|
|
118
|
+
CurrencyCode2["LSL"] = "LSL";
|
|
119
|
+
CurrencyCode2["MGA"] = "MGA";
|
|
120
|
+
CurrencyCode2["MWK"] = "MWK";
|
|
121
|
+
CurrencyCode2["SCR"] = "SCR";
|
|
122
|
+
CurrencyCode2["SDG"] = "SDG";
|
|
123
|
+
CurrencyCode2["SHP"] = "SHP";
|
|
124
|
+
CurrencyCode2["SLE"] = "SLE";
|
|
125
|
+
CurrencyCode2["SOS"] = "SOS";
|
|
126
|
+
CurrencyCode2["SSP"] = "SSP";
|
|
127
|
+
CurrencyCode2["STN"] = "STN";
|
|
128
|
+
CurrencyCode2["SZL"] = "SZL";
|
|
129
|
+
CurrencyCode2["VED"] = "VED";
|
|
130
|
+
CurrencyCode2["XCG"] = "XCG";
|
|
131
|
+
CurrencyCode2["JPY"] = "JPY";
|
|
132
|
+
CurrencyCode2["KRW"] = "KRW";
|
|
133
|
+
CurrencyCode2["VND"] = "VND";
|
|
134
|
+
CurrencyCode2["CLP"] = "CLP";
|
|
135
|
+
CurrencyCode2["ISK"] = "ISK";
|
|
136
|
+
CurrencyCode2["HUF"] = "HUF";
|
|
137
|
+
CurrencyCode2["TWD"] = "TWD";
|
|
138
|
+
CurrencyCode2["GNF"] = "GNF";
|
|
139
|
+
CurrencyCode2["BIF"] = "BIF";
|
|
140
|
+
CurrencyCode2["DJF"] = "DJF";
|
|
141
|
+
CurrencyCode2["KMF"] = "KMF";
|
|
142
|
+
CurrencyCode2["PYG"] = "PYG";
|
|
143
|
+
CurrencyCode2["RWF"] = "RWF";
|
|
144
|
+
CurrencyCode2["UGX"] = "UGX";
|
|
145
|
+
CurrencyCode2["VUV"] = "VUV";
|
|
146
|
+
CurrencyCode2["XAF"] = "XAF";
|
|
147
|
+
CurrencyCode2["XOF"] = "XOF";
|
|
148
|
+
CurrencyCode2["XPF"] = "XPF";
|
|
149
|
+
CurrencyCode2["KWD"] = "KWD";
|
|
150
|
+
CurrencyCode2["BHD"] = "BHD";
|
|
151
|
+
CurrencyCode2["OMR"] = "OMR";
|
|
152
|
+
CurrencyCode2["JOD"] = "JOD";
|
|
153
|
+
CurrencyCode2["TND"] = "TND";
|
|
154
|
+
CurrencyCode2["LYD"] = "LYD";
|
|
155
|
+
CurrencyCode2["IQD"] = "IQD";
|
|
156
|
+
return CurrencyCode2;
|
|
157
|
+
})(CurrencyCode || {});
|
|
158
|
+
|
|
159
|
+
// enums/core.enum.ts
|
|
160
|
+
var TimePeriod = /* @__PURE__ */ ((TimePeriod2) => {
|
|
161
|
+
TimePeriod2["TODAY"] = "today";
|
|
162
|
+
TimePeriod2["THIS_WEEK"] = "this week";
|
|
163
|
+
TimePeriod2["THIS_MONTH"] = "this month";
|
|
164
|
+
TimePeriod2["THIS_YEAR"] = "this year";
|
|
165
|
+
TimePeriod2["All_TIME"] = "all_time";
|
|
166
|
+
return TimePeriod2;
|
|
167
|
+
})(TimePeriod || {});
|
|
168
|
+
var TopMetericsSort = /* @__PURE__ */ ((TopMetericsSort2) => {
|
|
169
|
+
TopMetericsSort2["TOTAL_PAYMENT_VOLUME"] = "totalPaymentVolume";
|
|
170
|
+
TopMetericsSort2["TOTAL_TRANSACTION"] = "totalTransaction";
|
|
171
|
+
return TopMetericsSort2;
|
|
172
|
+
})(TopMetericsSort || {});
|
|
173
|
+
var CompanyType = /* @__PURE__ */ ((CompanyType2) => {
|
|
174
|
+
CompanyType2["COMPANY"] = "company";
|
|
175
|
+
CompanyType2["ROOT"] = "root";
|
|
176
|
+
CompanyType2["ORGANIZATION"] = "organization";
|
|
177
|
+
return CompanyType2;
|
|
178
|
+
})(CompanyType || {});
|
|
179
|
+
var CustomTableAvailability = /* @__PURE__ */ ((CustomTableAvailability2) => {
|
|
180
|
+
CustomTableAvailability2["PUBLIC"] = "public";
|
|
181
|
+
CustomTableAvailability2["ORGANIZATION"] = "organization";
|
|
182
|
+
return CustomTableAvailability2;
|
|
183
|
+
})(CustomTableAvailability || {});
|
|
184
|
+
var AttributeType = /* @__PURE__ */ ((AttributeType2) => {
|
|
185
|
+
AttributeType2["STRING"] = "string";
|
|
186
|
+
AttributeType2["NUMBER"] = "number";
|
|
187
|
+
AttributeType2["BOOLEAN"] = "boolean";
|
|
188
|
+
AttributeType2["DATE"] = "date";
|
|
189
|
+
AttributeType2["JSON_STRING"] = "json-string";
|
|
190
|
+
return AttributeType2;
|
|
191
|
+
})(AttributeType || {});
|
|
192
|
+
var Platform = /* @__PURE__ */ ((Platform2) => {
|
|
193
|
+
Platform2["WOO_COMMERCE"] = "woo-commerce";
|
|
194
|
+
Platform2["SHOPIFY"] = "shopify";
|
|
195
|
+
Platform2["OLIVER"] = "oliver";
|
|
196
|
+
Platform2["STANDALONE"] = "standalone";
|
|
197
|
+
return Platform2;
|
|
198
|
+
})(Platform || {});
|
|
199
|
+
var OrderPlatform = /* @__PURE__ */ ((OrderPlatform2) => {
|
|
200
|
+
OrderPlatform2["POS"] = "in-store";
|
|
201
|
+
OrderPlatform2["WOO_COMMERCE"] = "woo-commerce";
|
|
202
|
+
return OrderPlatform2;
|
|
203
|
+
})(OrderPlatform || {});
|
|
204
|
+
var CustomerPlatform = /* @__PURE__ */ ((CustomerPlatform2) => {
|
|
205
|
+
CustomerPlatform2["POS"] = "in-store";
|
|
206
|
+
CustomerPlatform2["WOO_COMMERCE"] = "woo-commerce";
|
|
207
|
+
return CustomerPlatform2;
|
|
208
|
+
})(CustomerPlatform || {});
|
|
209
|
+
var StationStatus = /* @__PURE__ */ ((StationStatus2) => {
|
|
210
|
+
StationStatus2["IN_USE"] = "IN_USE";
|
|
211
|
+
StationStatus2["AVAILABLE"] = "AVAILABLE";
|
|
212
|
+
return StationStatus2;
|
|
213
|
+
})(StationStatus || {});
|
|
214
|
+
var InventoryBaseActionEnum = /* @__PURE__ */ ((InventoryBaseActionEnum2) => {
|
|
215
|
+
InventoryBaseActionEnum2["ADD"] = "ADD";
|
|
216
|
+
InventoryBaseActionEnum2["REMOVE"] = "REMOVE";
|
|
217
|
+
InventoryBaseActionEnum2["RECOUNT"] = "RECOUNT";
|
|
218
|
+
InventoryBaseActionEnum2["SKIP"] = "SKIP";
|
|
219
|
+
return InventoryBaseActionEnum2;
|
|
220
|
+
})(InventoryBaseActionEnum || {});
|
|
221
|
+
var InventorySpecificActionType = /* @__PURE__ */ ((InventorySpecificActionType2) => {
|
|
222
|
+
InventorySpecificActionType2["STOCK_RECEIVED"] = "STOCK_RECEIVED";
|
|
223
|
+
InventorySpecificActionType2["INVENTORY_RECOUNT"] = "INVENTORY_RECOUNT";
|
|
224
|
+
InventorySpecificActionType2["DAMAGE"] = "DAMAGE";
|
|
225
|
+
InventorySpecificActionType2["THEFT"] = "THEFT";
|
|
226
|
+
InventorySpecificActionType2["LOSS"] = "LOSS";
|
|
227
|
+
InventorySpecificActionType2["RESTOCK_RETURN"] = "RESTOCK_RETURN";
|
|
228
|
+
InventorySpecificActionType2["REFUND_RESTOCK_RETURN"] = "REFUND_RESTOCK_RETURN";
|
|
229
|
+
InventorySpecificActionType2["REFUND_DAMAGE"] = "REFUND_DAMAGE";
|
|
230
|
+
InventorySpecificActionType2["SALE"] = "SALE";
|
|
231
|
+
InventorySpecificActionType2["TRANSFER"] = "TRANSFER";
|
|
232
|
+
InventorySpecificActionType2["BULK_RECOUNT"] = "BULK_RECOUNT";
|
|
233
|
+
InventorySpecificActionType2["APPLIED_FROM_WOO"] = "APPLIED_FROM_WOO";
|
|
234
|
+
return InventorySpecificActionType2;
|
|
235
|
+
})(InventorySpecificActionType || {});
|
|
236
|
+
var ExtensionCategory = /* @__PURE__ */ ((ExtensionCategory2) => {
|
|
237
|
+
ExtensionCategory2["SYNC"] = "sync";
|
|
238
|
+
ExtensionCategory2["PAYMENT"] = "payment";
|
|
239
|
+
ExtensionCategory2["HUB"] = "hub";
|
|
240
|
+
ExtensionCategory2["BUILDER"] = "builder";
|
|
241
|
+
return ExtensionCategory2;
|
|
242
|
+
})(ExtensionCategory || {});
|
|
243
|
+
var FeesCustomBillingStatus = /* @__PURE__ */ ((FeesCustomBillingStatus2) => {
|
|
244
|
+
FeesCustomBillingStatus2["UNPAID"] = "unpaid";
|
|
245
|
+
FeesCustomBillingStatus2["PAID"] = "paid";
|
|
246
|
+
FeesCustomBillingStatus2["OPEN"] = "open";
|
|
247
|
+
return FeesCustomBillingStatus2;
|
|
248
|
+
})(FeesCustomBillingStatus || {});
|
|
249
|
+
var PricingPlanEnum = /* @__PURE__ */ ((PricingPlanEnum2) => {
|
|
250
|
+
PricingPlanEnum2["DEFAULT"] = "default";
|
|
251
|
+
PricingPlanEnum2["MINIMUM"] = "minimum";
|
|
252
|
+
PricingPlanEnum2["ORGANIZATION"] = "organization";
|
|
253
|
+
PricingPlanEnum2["PLAN"] = "plan";
|
|
254
|
+
PricingPlanEnum2["COMPANY"] = "company";
|
|
255
|
+
return PricingPlanEnum2;
|
|
256
|
+
})(PricingPlanEnum || {});
|
|
257
|
+
var PricingLevel = /* @__PURE__ */ ((PricingLevel2) => {
|
|
258
|
+
PricingLevel2["ORG"] = "org";
|
|
259
|
+
PricingLevel2["PLAN"] = "plan";
|
|
260
|
+
PricingLevel2["DEFAULT"] = "default";
|
|
261
|
+
PricingLevel2["MINIMUM"] = "minimum";
|
|
262
|
+
return PricingLevel2;
|
|
263
|
+
})(PricingLevel || {});
|
|
264
|
+
var PricingRegionEnum = /* @__PURE__ */ ((PricingRegionEnum2) => {
|
|
265
|
+
PricingRegionEnum2["EUROPE"] = "europe";
|
|
266
|
+
PricingRegionEnum2["OTHER"] = "others";
|
|
267
|
+
PricingRegionEnum2["NORTH_AMERICA"] = "northAmerica";
|
|
268
|
+
return PricingRegionEnum2;
|
|
269
|
+
})(PricingRegionEnum || {});
|
|
270
|
+
var MenuProject = /* @__PURE__ */ ((MenuProject2) => {
|
|
271
|
+
MenuProject2["MANAGE"] = "Manage";
|
|
272
|
+
MenuProject2["SCALE"] = "Scale";
|
|
273
|
+
MenuProject2["BUILD"] = "Build";
|
|
274
|
+
MenuProject2["PAY"] = "Pay";
|
|
275
|
+
MenuProject2["RUN"] = "Run";
|
|
276
|
+
return MenuProject2;
|
|
277
|
+
})(MenuProject || {});
|
|
278
|
+
var UserTypes = /* @__PURE__ */ ((UserTypes2) => {
|
|
279
|
+
UserTypes2["COMPANY_OWNER"] = "owner";
|
|
280
|
+
UserTypes2["ORG_USER"] = "organization_user";
|
|
281
|
+
UserTypes2["ORG_OWNER"] = "organization_owner";
|
|
282
|
+
UserTypes2["FINAL_USER"] = "final_user";
|
|
283
|
+
UserTypes2["FINAL_OWNER"] = "final_owner";
|
|
284
|
+
UserTypes2["EMPLOYEE"] = "employee";
|
|
285
|
+
UserTypes2["SUPER_ADMIN"] = "super_admin";
|
|
286
|
+
UserTypes2["MANAGER"] = "manager";
|
|
287
|
+
UserTypes2["ADMIN"] = "admin";
|
|
288
|
+
UserTypes2["ASSISTANT_MANAGER"] = "assistant";
|
|
289
|
+
UserTypes2["CASHIER"] = "cashier";
|
|
290
|
+
UserTypes2["RESELLER"] = "reseller";
|
|
291
|
+
return UserTypes2;
|
|
292
|
+
})(UserTypes || {});
|
|
293
|
+
var OwnerType = /* @__PURE__ */ ((OwnerType2) => {
|
|
294
|
+
OwnerType2["API_KEY"] = "api-key";
|
|
295
|
+
OwnerType2["ORGANIZATION"] = "organization";
|
|
296
|
+
OwnerType2["COMPANY"] = "company";
|
|
297
|
+
return OwnerType2;
|
|
298
|
+
})(OwnerType || {});
|
|
299
|
+
var PublicationAvailability = /* @__PURE__ */ ((PublicationAvailability2) => {
|
|
300
|
+
PublicationAvailability2["GLOBAL"] = "global";
|
|
301
|
+
PublicationAvailability2["PRIVATE"] = "private";
|
|
302
|
+
return PublicationAvailability2;
|
|
303
|
+
})(PublicationAvailability || {});
|
|
304
|
+
var PublicationStatus = /* @__PURE__ */ ((PublicationStatus2) => {
|
|
305
|
+
PublicationStatus2["APPROVED"] = "approved";
|
|
306
|
+
PublicationStatus2["REJECTED"] = "rejected";
|
|
307
|
+
PublicationStatus2["PENDING"] = "pending";
|
|
308
|
+
PublicationStatus2["NOT_APPLICABLE"] = "not_applicable";
|
|
309
|
+
return PublicationStatus2;
|
|
310
|
+
})(PublicationStatus || {});
|
|
311
|
+
var ResidualStatus = /* @__PURE__ */ ((ResidualStatus2) => {
|
|
312
|
+
ResidualStatus2["PAID"] = "paid";
|
|
313
|
+
ResidualStatus2["DUE"] = "due";
|
|
314
|
+
ResidualStatus2["ACCRUING"] = "accruing";
|
|
315
|
+
return ResidualStatus2;
|
|
316
|
+
})(ResidualStatus || {});
|
|
317
|
+
var PreviewImageMode = /* @__PURE__ */ ((PreviewImageMode2) => {
|
|
318
|
+
PreviewImageMode2["STATIC"] = "static";
|
|
319
|
+
PreviewImageMode2["DYNAMIC"] = "dynamic";
|
|
320
|
+
return PreviewImageMode2;
|
|
321
|
+
})(PreviewImageMode || {});
|
|
322
|
+
var LibraryItemType = /* @__PURE__ */ ((LibraryItemType2) => {
|
|
323
|
+
LibraryItemType2["FLOW"] = "flow";
|
|
324
|
+
LibraryItemType2["PAGE"] = "page";
|
|
325
|
+
LibraryItemType2["COMPOSITION"] = "composition";
|
|
326
|
+
LibraryItemType2["LAYOUT"] = "layout";
|
|
327
|
+
return LibraryItemType2;
|
|
328
|
+
})(LibraryItemType || {});
|
|
329
|
+
var ResidualPaymentMethod = /* @__PURE__ */ ((ResidualPaymentMethod2) => {
|
|
330
|
+
ResidualPaymentMethod2["CHEQUE"] = "cheque";
|
|
331
|
+
return ResidualPaymentMethod2;
|
|
332
|
+
})(ResidualPaymentMethod || {});
|
|
333
|
+
var PaymentMethod = /* @__PURE__ */ ((PaymentMethod2) => {
|
|
334
|
+
PaymentMethod2["CUSTOM"] = "Custom";
|
|
335
|
+
PaymentMethod2["CASH"] = "Cash";
|
|
336
|
+
PaymentMethod2["TERMINAL"] = "Terminal";
|
|
337
|
+
PaymentMethod2["CLOUD"] = "Cloud";
|
|
338
|
+
PaymentMethod2["BLUETOOTH"] = "Bluetooth";
|
|
339
|
+
return PaymentMethod2;
|
|
340
|
+
})(PaymentMethod || {});
|
|
341
|
+
var NonRevenueItemType = /* @__PURE__ */ ((NonRevenueItemType2) => {
|
|
342
|
+
NonRevenueItemType2["GIFT_CARD"] = "gift-card";
|
|
343
|
+
return NonRevenueItemType2;
|
|
344
|
+
})(NonRevenueItemType || {});
|
|
345
|
+
var ReceiptSendChannel = /* @__PURE__ */ ((ReceiptSendChannel2) => {
|
|
346
|
+
ReceiptSendChannel2["EMAIL"] = "email";
|
|
347
|
+
ReceiptSendChannel2["TEXT"] = "text";
|
|
348
|
+
return ReceiptSendChannel2;
|
|
349
|
+
})(ReceiptSendChannel || {});
|
|
350
|
+
var ReceiptType = /* @__PURE__ */ ((ReceiptType2) => {
|
|
351
|
+
ReceiptType2["ORDER"] = "order";
|
|
352
|
+
ReceiptType2["REFUND"] = "refund";
|
|
353
|
+
return ReceiptType2;
|
|
354
|
+
})(ReceiptType || {});
|
|
355
|
+
var StripeStatus = /* @__PURE__ */ ((StripeStatus2) => {
|
|
356
|
+
StripeStatus2["ACTIVE"] = "active";
|
|
357
|
+
StripeStatus2["INACTIVE"] = "inactive";
|
|
358
|
+
StripeStatus2["PAYMENT_METHOD_REQUIRED"] = "payment_method_required";
|
|
359
|
+
StripeStatus2["PAYMENT_METHOD_ADDED"] = "payment_method_added";
|
|
360
|
+
return StripeStatus2;
|
|
361
|
+
})(StripeStatus || {});
|
|
362
|
+
var InvoiceStatus = /* @__PURE__ */ ((InvoiceStatus2) => {
|
|
363
|
+
InvoiceStatus2["PAID"] = "paid";
|
|
364
|
+
InvoiceStatus2["PENDING"] = "pending";
|
|
365
|
+
InvoiceStatus2["EXPIRED"] = "expired";
|
|
366
|
+
return InvoiceStatus2;
|
|
367
|
+
})(InvoiceStatus || {});
|
|
368
|
+
|
|
369
|
+
// enums/stripe-currencies.enum.ts
|
|
370
|
+
var StripeCurrencyCode = /* @__PURE__ */ ((StripeCurrencyCode2) => {
|
|
371
|
+
StripeCurrencyCode2["USD"] = "USD";
|
|
372
|
+
StripeCurrencyCode2["EUR"] = "EUR";
|
|
373
|
+
StripeCurrencyCode2["GBP"] = "GBP";
|
|
374
|
+
StripeCurrencyCode2["CAD"] = "CAD";
|
|
375
|
+
StripeCurrencyCode2["AUD"] = "AUD";
|
|
376
|
+
StripeCurrencyCode2["NZD"] = "NZD";
|
|
377
|
+
StripeCurrencyCode2["CHF"] = "CHF";
|
|
378
|
+
StripeCurrencyCode2["CNY"] = "CNY";
|
|
379
|
+
StripeCurrencyCode2["INR"] = "INR";
|
|
380
|
+
StripeCurrencyCode2["MXN"] = "MXN";
|
|
381
|
+
StripeCurrencyCode2["BRL"] = "BRL";
|
|
382
|
+
StripeCurrencyCode2["ZAR"] = "ZAR";
|
|
383
|
+
StripeCurrencyCode2["SGD"] = "SGD";
|
|
384
|
+
StripeCurrencyCode2["HKD"] = "HKD";
|
|
385
|
+
StripeCurrencyCode2["SEK"] = "SEK";
|
|
386
|
+
StripeCurrencyCode2["NOK"] = "NOK";
|
|
387
|
+
StripeCurrencyCode2["DKK"] = "DKK";
|
|
388
|
+
StripeCurrencyCode2["PLN"] = "PLN";
|
|
389
|
+
StripeCurrencyCode2["THB"] = "THB";
|
|
390
|
+
StripeCurrencyCode2["MYR"] = "MYR";
|
|
391
|
+
StripeCurrencyCode2["PHP"] = "PHP";
|
|
392
|
+
StripeCurrencyCode2["IDR"] = "IDR";
|
|
393
|
+
StripeCurrencyCode2["AED"] = "AED";
|
|
394
|
+
StripeCurrencyCode2["SAR"] = "SAR";
|
|
395
|
+
StripeCurrencyCode2["ILS"] = "ILS";
|
|
396
|
+
StripeCurrencyCode2["TRY"] = "TRY";
|
|
397
|
+
StripeCurrencyCode2["RUB"] = "RUB";
|
|
398
|
+
StripeCurrencyCode2["JPY"] = "JPY";
|
|
399
|
+
StripeCurrencyCode2["KRW"] = "KRW";
|
|
400
|
+
StripeCurrencyCode2["VND"] = "VND";
|
|
401
|
+
StripeCurrencyCode2["CLP"] = "CLP";
|
|
402
|
+
StripeCurrencyCode2["ISK"] = "ISK";
|
|
403
|
+
StripeCurrencyCode2["HUF"] = "HUF";
|
|
404
|
+
StripeCurrencyCode2["TWD"] = "TWD";
|
|
405
|
+
StripeCurrencyCode2["KWD"] = "KWD";
|
|
406
|
+
StripeCurrencyCode2["BHD"] = "BHD";
|
|
407
|
+
StripeCurrencyCode2["OMR"] = "OMR";
|
|
408
|
+
StripeCurrencyCode2["JOD"] = "JOD";
|
|
409
|
+
StripeCurrencyCode2["TND"] = "TND";
|
|
410
|
+
StripeCurrencyCode2["LYD"] = "LYD";
|
|
411
|
+
StripeCurrencyCode2["IQD"] = "IQD";
|
|
412
|
+
return StripeCurrencyCode2;
|
|
413
|
+
})(StripeCurrencyCode || {});
|
|
414
|
+
|
|
415
|
+
// enums/product.enum.ts
|
|
416
|
+
var ProductType = /* @__PURE__ */ ((ProductType2) => {
|
|
417
|
+
ProductType2["SIMPLE"] = "simple";
|
|
418
|
+
ProductType2["VARIABLE"] = "variable";
|
|
419
|
+
return ProductType2;
|
|
420
|
+
})(ProductType || {});
|
|
421
|
+
var ProductStatus = /* @__PURE__ */ ((ProductStatus2) => {
|
|
422
|
+
ProductStatus2["ACTIVE"] = "active";
|
|
423
|
+
ProductStatus2["INACTIVE"] = "inactive";
|
|
424
|
+
ProductStatus2["DRAFT"] = "draft";
|
|
425
|
+
return ProductStatus2;
|
|
426
|
+
})(ProductStatus || {});
|
|
427
|
+
|
|
428
|
+
// utils/currency.util.ts
|
|
429
|
+
var CURRENCY_CONFIG = {
|
|
430
|
+
// Major currencies with 2 decimal places
|
|
431
|
+
["USD" /* USD */]: { minorUnits: 2, symbol: "$", symbolPosition: "prefix" },
|
|
432
|
+
["EUR" /* EUR */]: { minorUnits: 2, symbol: "\u20AC", symbolPosition: "prefix" },
|
|
433
|
+
["GBP" /* GBP */]: { minorUnits: 2, symbol: "\xA3", symbolPosition: "prefix" },
|
|
434
|
+
["CAD" /* CAD */]: { minorUnits: 2, symbol: "CA$", symbolPosition: "prefix" },
|
|
435
|
+
["AUD" /* AUD */]: { minorUnits: 2, symbol: "A$", symbolPosition: "prefix" },
|
|
436
|
+
["NZD" /* NZD */]: { minorUnits: 2, symbol: "NZ$", symbolPosition: "prefix" },
|
|
437
|
+
["CHF" /* CHF */]: { minorUnits: 2, symbol: "CHF", symbolPosition: "prefix" },
|
|
438
|
+
["CNY" /* CNY */]: { minorUnits: 2, symbol: "\xA5", symbolPosition: "prefix" },
|
|
439
|
+
["INR" /* INR */]: { minorUnits: 2, symbol: "\u20B9", symbolPosition: "prefix" },
|
|
440
|
+
["MXN" /* MXN */]: { minorUnits: 2, symbol: "MX$", symbolPosition: "prefix" },
|
|
441
|
+
["BRL" /* BRL */]: { minorUnits: 2, symbol: "R$", symbolPosition: "prefix" },
|
|
442
|
+
["ZAR" /* ZAR */]: { minorUnits: 2, symbol: "R", symbolPosition: "prefix" },
|
|
443
|
+
["SGD" /* SGD */]: { minorUnits: 2, symbol: "S$", symbolPosition: "prefix" },
|
|
444
|
+
["HKD" /* HKD */]: { minorUnits: 2, symbol: "HK$", symbolPosition: "prefix" },
|
|
445
|
+
["SEK" /* SEK */]: { minorUnits: 2, symbol: "kr", symbolPosition: "suffix" },
|
|
446
|
+
["NOK" /* NOK */]: { minorUnits: 2, symbol: "kr", symbolPosition: "suffix" },
|
|
447
|
+
["DKK" /* DKK */]: { minorUnits: 2, symbol: "kr", symbolPosition: "suffix" },
|
|
448
|
+
["PLN" /* PLN */]: { minorUnits: 2, symbol: "z\u0142", symbolPosition: "suffix" },
|
|
449
|
+
["THB" /* THB */]: { minorUnits: 2, symbol: "\u0E3F", symbolPosition: "prefix" },
|
|
450
|
+
["MYR" /* MYR */]: { minorUnits: 2, symbol: "RM", symbolPosition: "prefix" },
|
|
451
|
+
["PHP" /* PHP */]: { minorUnits: 2, symbol: "\u20B1", symbolPosition: "prefix" },
|
|
452
|
+
["IDR" /* IDR */]: { minorUnits: 2, symbol: "Rp", symbolPosition: "prefix" },
|
|
453
|
+
["AED" /* AED */]: { minorUnits: 2, symbol: "\u062F.\u0625", symbolPosition: "prefix" },
|
|
454
|
+
["SAR" /* SAR */]: { minorUnits: 2, symbol: "\uFDFC", symbolPosition: "prefix" },
|
|
455
|
+
["ILS" /* ILS */]: { minorUnits: 2, symbol: "\u20AA", symbolPosition: "prefix" },
|
|
456
|
+
["TRY" /* TRY */]: { minorUnits: 2, symbol: "\u20BA", symbolPosition: "prefix" },
|
|
457
|
+
["RUB" /* RUB */]: { minorUnits: 2, symbol: "\u20BD", symbolPosition: "suffix" },
|
|
458
|
+
["HTG" /* HTG */]: { minorUnits: 2, symbol: "HTG", symbolPosition: "prefix" },
|
|
459
|
+
// New Currencies with 2 decimal places
|
|
460
|
+
["BND" /* BND */]: { minorUnits: 2, symbol: "BND", symbolPosition: "prefix" },
|
|
461
|
+
["CRC" /* CRC */]: { minorUnits: 2, symbol: "CRC", symbolPosition: "prefix" },
|
|
462
|
+
["BDT" /* BDT */]: { minorUnits: 2, symbol: "BDT", symbolPosition: "prefix" },
|
|
463
|
+
["UAH" /* UAH */]: { minorUnits: 2, symbol: "UAH", symbolPosition: "prefix" },
|
|
464
|
+
["NGN" /* NGN */]: { minorUnits: 2, symbol: "\u20A6", symbolPosition: "prefix" },
|
|
465
|
+
["AFN" /* AFN */]: { minorUnits: 2, symbol: "\u060B", symbolPosition: "prefix" },
|
|
466
|
+
["ALL" /* ALL */]: { minorUnits: 2, symbol: "L", symbolPosition: "suffix" },
|
|
467
|
+
["AMD" /* AMD */]: { minorUnits: 2, symbol: "\u058F", symbolPosition: "suffix" },
|
|
468
|
+
["ANG" /* ANG */]: { minorUnits: 2, symbol: "\u0192", symbolPosition: "prefix" },
|
|
469
|
+
["AOA" /* AOA */]: { minorUnits: 2, symbol: "Kz", symbolPosition: "prefix" },
|
|
470
|
+
["ARS" /* ARS */]: { minorUnits: 2, symbol: "AR$", symbolPosition: "prefix" },
|
|
471
|
+
["AWG" /* AWG */]: { minorUnits: 2, symbol: "Afl.", symbolPosition: "prefix" },
|
|
472
|
+
["AZN" /* AZN */]: { minorUnits: 2, symbol: "\u20BC", symbolPosition: "prefix" },
|
|
473
|
+
["BAM" /* BAM */]: { minorUnits: 2, symbol: "KM", symbolPosition: "suffix" },
|
|
474
|
+
["BBD" /* BBD */]: { minorUnits: 2, symbol: "Bds$", symbolPosition: "prefix" },
|
|
475
|
+
["BGN" /* BGN */]: { minorUnits: 2, symbol: "\u043B\u0432", symbolPosition: "suffix" },
|
|
476
|
+
["BMD" /* BMD */]: { minorUnits: 2, symbol: "BD$", symbolPosition: "prefix" },
|
|
477
|
+
["BOB" /* BOB */]: { minorUnits: 2, symbol: "Bs.", symbolPosition: "prefix" },
|
|
478
|
+
["BSD" /* BSD */]: { minorUnits: 2, symbol: "B$", symbolPosition: "prefix" },
|
|
479
|
+
["BTN" /* BTN */]: { minorUnits: 2, symbol: "Nu.", symbolPosition: "prefix" },
|
|
480
|
+
["BWP" /* BWP */]: { minorUnits: 2, symbol: "P", symbolPosition: "prefix" },
|
|
481
|
+
["BYN" /* BYN */]: { minorUnits: 2, symbol: "Br", symbolPosition: "suffix" },
|
|
482
|
+
["BZD" /* BZD */]: { minorUnits: 2, symbol: "BZ$", symbolPosition: "prefix" },
|
|
483
|
+
["COP" /* COP */]: { minorUnits: 2, symbol: "COL$", symbolPosition: "prefix" },
|
|
484
|
+
["CZK" /* CZK */]: { minorUnits: 2, symbol: "K\u010D", symbolPosition: "suffix" },
|
|
485
|
+
["DOP" /* DOP */]: { minorUnits: 2, symbol: "RD$", symbolPosition: "prefix" },
|
|
486
|
+
["DZD" /* DZD */]: { minorUnits: 2, symbol: "DA", symbolPosition: "prefix" },
|
|
487
|
+
["EGP" /* EGP */]: { minorUnits: 2, symbol: "E\xA3", symbolPosition: "prefix" },
|
|
488
|
+
["ETB" /* ETB */]: { minorUnits: 2, symbol: "Br", symbolPosition: "prefix" },
|
|
489
|
+
["FJD" /* FJD */]: { minorUnits: 2, symbol: "FJ$", symbolPosition: "prefix" },
|
|
490
|
+
["GEL" /* GEL */]: { minorUnits: 2, symbol: "\u20BE", symbolPosition: "prefix" },
|
|
491
|
+
["GHS" /* GHS */]: { minorUnits: 2, symbol: "\u20B5", symbolPosition: "prefix" },
|
|
492
|
+
["GTQ" /* GTQ */]: { minorUnits: 2, symbol: "Q", symbolPosition: "prefix" },
|
|
493
|
+
["GYD" /* GYD */]: { minorUnits: 2, symbol: "G$", symbolPosition: "prefix" },
|
|
494
|
+
["HNL" /* HNL */]: { minorUnits: 2, symbol: "L", symbolPosition: "prefix" },
|
|
495
|
+
["IRR" /* IRR */]: { minorUnits: 2, symbol: "\uFDFC", symbolPosition: "prefix" },
|
|
496
|
+
["JMD" /* JMD */]: { minorUnits: 2, symbol: "J$", symbolPosition: "prefix" },
|
|
497
|
+
["KES" /* KES */]: { minorUnits: 2, symbol: "KSh", symbolPosition: "prefix" },
|
|
498
|
+
["KGS" /* KGS */]: { minorUnits: 2, symbol: "\u0441", symbolPosition: "suffix" },
|
|
499
|
+
["KHR" /* KHR */]: { minorUnits: 2, symbol: "\u17DB", symbolPosition: "prefix" },
|
|
500
|
+
["KYD" /* KYD */]: { minorUnits: 2, symbol: "CI$", symbolPosition: "prefix" },
|
|
501
|
+
["KZT" /* KZT */]: { minorUnits: 2, symbol: "\u20B8", symbolPosition: "prefix" },
|
|
502
|
+
["LAK" /* LAK */]: { minorUnits: 2, symbol: "\u20AD", symbolPosition: "prefix" },
|
|
503
|
+
["LBP" /* LBP */]: { minorUnits: 2, symbol: "L\xA3", symbolPosition: "prefix" },
|
|
504
|
+
["LKR" /* LKR */]: { minorUnits: 2, symbol: "Rs", symbolPosition: "prefix" },
|
|
505
|
+
["MAD" /* MAD */]: { minorUnits: 2, symbol: "DH", symbolPosition: "prefix" },
|
|
506
|
+
["MDL" /* MDL */]: { minorUnits: 2, symbol: "L", symbolPosition: "suffix" },
|
|
507
|
+
["MKD" /* MKD */]: { minorUnits: 2, symbol: "\u0434\u0435\u043D", symbolPosition: "suffix" },
|
|
508
|
+
["MMK" /* MMK */]: { minorUnits: 2, symbol: "K", symbolPosition: "prefix" },
|
|
509
|
+
["MNT" /* MNT */]: { minorUnits: 2, symbol: "\u20AE", symbolPosition: "prefix" },
|
|
510
|
+
["MOP" /* MOP */]: { minorUnits: 2, symbol: "MOP$", symbolPosition: "prefix" },
|
|
511
|
+
["MUR" /* MUR */]: { minorUnits: 2, symbol: "Rs", symbolPosition: "prefix" },
|
|
512
|
+
["MVR" /* MVR */]: { minorUnits: 2, symbol: "Rf", symbolPosition: "prefix" },
|
|
513
|
+
["MZN" /* MZN */]: { minorUnits: 2, symbol: "MT", symbolPosition: "prefix" },
|
|
514
|
+
["NAD" /* NAD */]: { minorUnits: 2, symbol: "N$", symbolPosition: "prefix" },
|
|
515
|
+
["NIO" /* NIO */]: { minorUnits: 2, symbol: "C$", symbolPosition: "prefix" },
|
|
516
|
+
["NPR" /* NPR */]: { minorUnits: 2, symbol: "Rs", symbolPosition: "prefix" },
|
|
517
|
+
["PAB" /* PAB */]: { minorUnits: 2, symbol: "B/.", symbolPosition: "prefix" },
|
|
518
|
+
["PEN" /* PEN */]: { minorUnits: 2, symbol: "S/", symbolPosition: "prefix" },
|
|
519
|
+
["PGK" /* PGK */]: { minorUnits: 2, symbol: "K", symbolPosition: "prefix" },
|
|
520
|
+
["PKR" /* PKR */]: { minorUnits: 2, symbol: "\u20A8", symbolPosition: "prefix" },
|
|
521
|
+
["QAR" /* QAR */]: { minorUnits: 2, symbol: "QR", symbolPosition: "prefix" },
|
|
522
|
+
["RON" /* RON */]: { minorUnits: 2, symbol: "lei", symbolPosition: "suffix" },
|
|
523
|
+
["RSD" /* RSD */]: { minorUnits: 2, symbol: "\u0434\u0438\u043D.", symbolPosition: "suffix" },
|
|
524
|
+
["SBD" /* SBD */]: { minorUnits: 2, symbol: "SI$", symbolPosition: "prefix" },
|
|
525
|
+
["SRD" /* SRD */]: { minorUnits: 2, symbol: "Sr$", symbolPosition: "prefix" },
|
|
526
|
+
["SYP" /* SYP */]: { minorUnits: 2, symbol: "\xA3S", symbolPosition: "prefix" },
|
|
527
|
+
["TJS" /* TJS */]: { minorUnits: 2, symbol: "SM", symbolPosition: "prefix" },
|
|
528
|
+
["TMT" /* TMT */]: { minorUnits: 2, symbol: "m.", symbolPosition: "prefix" },
|
|
529
|
+
["TOP" /* TOP */]: { minorUnits: 2, symbol: "T$", symbolPosition: "prefix" },
|
|
530
|
+
["TTD" /* TTD */]: { minorUnits: 2, symbol: "TT$", symbolPosition: "prefix" },
|
|
531
|
+
["TZS" /* TZS */]: { minorUnits: 2, symbol: "TSh", symbolPosition: "prefix" },
|
|
532
|
+
["UYU" /* UYU */]: { minorUnits: 2, symbol: "$U", symbolPosition: "prefix" },
|
|
533
|
+
["UZS" /* UZS */]: { minorUnits: 2, symbol: "\u0441\u045E\u043C", symbolPosition: "suffix" },
|
|
534
|
+
["VES" /* VES */]: { minorUnits: 2, symbol: "Bs.", symbolPosition: "prefix" },
|
|
535
|
+
["WST" /* WST */]: { minorUnits: 2, symbol: "WS$", symbolPosition: "prefix" },
|
|
536
|
+
["XCD" /* XCD */]: { minorUnits: 2, symbol: "EC$", symbolPosition: "prefix" },
|
|
537
|
+
["YER" /* YER */]: { minorUnits: 2, symbol: "\uFDFC", symbolPosition: "prefix" },
|
|
538
|
+
["ZMW" /* ZMW */]: { minorUnits: 2, symbol: "ZK", symbolPosition: "prefix" },
|
|
539
|
+
["CDF" /* CDF */]: { minorUnits: 2, symbol: "FC", symbolPosition: "prefix" },
|
|
540
|
+
["CUP" /* CUP */]: { minorUnits: 2, symbol: "$MN", symbolPosition: "prefix" },
|
|
541
|
+
["ERN" /* ERN */]: { minorUnits: 2, symbol: "Nfk", symbolPosition: "prefix" },
|
|
542
|
+
["FKP" /* FKP */]: { minorUnits: 2, symbol: "FK\xA3", symbolPosition: "prefix" },
|
|
543
|
+
["GIP" /* GIP */]: { minorUnits: 2, symbol: "GI\xA3", symbolPosition: "prefix" },
|
|
544
|
+
["GMD" /* GMD */]: { minorUnits: 2, symbol: "D", symbolPosition: "prefix" },
|
|
545
|
+
["KPW" /* KPW */]: { minorUnits: 2, symbol: "KPW", symbolPosition: "prefix" },
|
|
546
|
+
["LRD" /* LRD */]: { minorUnits: 2, symbol: "L$", symbolPosition: "prefix" },
|
|
547
|
+
["LSL" /* LSL */]: { minorUnits: 2, symbol: "M", symbolPosition: "prefix" },
|
|
548
|
+
["MGA" /* MGA */]: { minorUnits: 2, symbol: "Ar", symbolPosition: "prefix" },
|
|
549
|
+
["MWK" /* MWK */]: { minorUnits: 2, symbol: "MK", symbolPosition: "prefix" },
|
|
550
|
+
["SCR" /* SCR */]: { minorUnits: 2, symbol: "SR", symbolPosition: "prefix" },
|
|
551
|
+
["SDG" /* SDG */]: { minorUnits: 2, symbol: "SDG", symbolPosition: "prefix" },
|
|
552
|
+
["SHP" /* SHP */]: { minorUnits: 2, symbol: "SH\xA3", symbolPosition: "prefix" },
|
|
553
|
+
["SLE" /* SLE */]: { minorUnits: 2, symbol: "Le", symbolPosition: "prefix" },
|
|
554
|
+
["SOS" /* SOS */]: { minorUnits: 2, symbol: "SSh", symbolPosition: "prefix" },
|
|
555
|
+
["SSP" /* SSP */]: { minorUnits: 2, symbol: "SSP", symbolPosition: "prefix" },
|
|
556
|
+
["STN" /* STN */]: { minorUnits: 2, symbol: "Db", symbolPosition: "prefix" },
|
|
557
|
+
["SZL" /* SZL */]: { minorUnits: 2, symbol: "E", symbolPosition: "prefix" },
|
|
558
|
+
["VED" /* VED */]: { minorUnits: 2, symbol: "Bs.D", symbolPosition: "prefix" },
|
|
559
|
+
["XCG" /* XCG */]: { minorUnits: 2, symbol: "Cg", symbolPosition: "prefix" },
|
|
560
|
+
// Zero decimal currencies
|
|
561
|
+
["JPY" /* JPY */]: { minorUnits: 0, symbol: "\xA5", symbolPosition: "prefix" },
|
|
562
|
+
["KRW" /* KRW */]: { minorUnits: 0, symbol: "\u20A9", symbolPosition: "prefix" },
|
|
563
|
+
["VND" /* VND */]: { minorUnits: 0, symbol: "\u20AB", symbolPosition: "suffix" },
|
|
564
|
+
["CLP" /* CLP */]: { minorUnits: 0, symbol: "CLP$", symbolPosition: "prefix" },
|
|
565
|
+
["ISK" /* ISK */]: { minorUnits: 0, symbol: "kr", symbolPosition: "suffix" },
|
|
566
|
+
["HUF" /* HUF */]: { minorUnits: 0, symbol: "Ft", symbolPosition: "suffix" },
|
|
567
|
+
["TWD" /* TWD */]: { minorUnits: 0, symbol: "NT$", symbolPosition: "prefix" },
|
|
568
|
+
// New Currencies with 0 decimal places
|
|
569
|
+
["GNF" /* GNF */]: { minorUnits: 0, symbol: "GNF", symbolPosition: "prefix" },
|
|
570
|
+
["BIF" /* BIF */]: { minorUnits: 0, symbol: "FBu", symbolPosition: "prefix" },
|
|
571
|
+
["DJF" /* DJF */]: { minorUnits: 0, symbol: "Fdj", symbolPosition: "prefix" },
|
|
572
|
+
["KMF" /* KMF */]: { minorUnits: 0, symbol: "CF", symbolPosition: "prefix" },
|
|
573
|
+
["PYG" /* PYG */]: { minorUnits: 0, symbol: "\u20B2", symbolPosition: "prefix" },
|
|
574
|
+
["RWF" /* RWF */]: { minorUnits: 0, symbol: "FRw", symbolPosition: "prefix" },
|
|
575
|
+
["UGX" /* UGX */]: { minorUnits: 0, symbol: "USh", symbolPosition: "prefix" },
|
|
576
|
+
["VUV" /* VUV */]: { minorUnits: 0, symbol: "VT", symbolPosition: "prefix" },
|
|
577
|
+
["XAF" /* XAF */]: { minorUnits: 0, symbol: "FCFA", symbolPosition: "suffix" },
|
|
578
|
+
["XOF" /* XOF */]: { minorUnits: 0, symbol: "CFA", symbolPosition: "suffix" },
|
|
579
|
+
["XPF" /* XPF */]: { minorUnits: 0, symbol: "\u20A3", symbolPosition: "suffix" },
|
|
580
|
+
// Three decimal currencies
|
|
581
|
+
["KWD" /* KWD */]: { minorUnits: 3, symbol: "KD", symbolPosition: "prefix" },
|
|
582
|
+
["BHD" /* BHD */]: { minorUnits: 3, symbol: "BD", symbolPosition: "prefix" },
|
|
583
|
+
["OMR" /* OMR */]: { minorUnits: 3, symbol: "OMR", symbolPosition: "prefix" },
|
|
584
|
+
["JOD" /* JOD */]: { minorUnits: 3, symbol: "JD", symbolPosition: "prefix" },
|
|
585
|
+
["TND" /* TND */]: { minorUnits: 3, symbol: "DT", symbolPosition: "prefix" },
|
|
586
|
+
["LYD" /* LYD */]: { minorUnits: 3, symbol: "LD", symbolPosition: "prefix" },
|
|
587
|
+
["IQD" /* IQD */]: { minorUnits: 3, symbol: "IQD", symbolPosition: "prefix" }
|
|
588
|
+
};
|
|
589
|
+
var DEFAULT_CURRENCY_CONFIG = {
|
|
590
|
+
minorUnits: 2,
|
|
591
|
+
symbol: "",
|
|
592
|
+
symbolPosition: "prefix"
|
|
593
|
+
};
|
|
594
|
+
function getCurrencyConfig(currency) {
|
|
595
|
+
const upperCurrency = currency.toUpperCase();
|
|
596
|
+
return CURRENCY_CONFIG[upperCurrency] || DEFAULT_CURRENCY_CONFIG;
|
|
597
|
+
}
|
|
598
|
+
function getMinorUnitMultiplier(currency) {
|
|
599
|
+
const config = getCurrencyConfig(currency);
|
|
600
|
+
return Math.pow(10, config.minorUnits);
|
|
601
|
+
}
|
|
602
|
+
function toMinorUnits(amount, currency) {
|
|
603
|
+
const multiplier = getMinorUnitMultiplier(currency);
|
|
604
|
+
return Math.round(amount * multiplier);
|
|
605
|
+
}
|
|
606
|
+
function fromMinorUnits(minorAmount, currency) {
|
|
607
|
+
const multiplier = getMinorUnitMultiplier(currency);
|
|
608
|
+
return minorAmount / multiplier;
|
|
609
|
+
}
|
|
610
|
+
function formatCurrency(minorAmount, currency, options = {}) {
|
|
611
|
+
const { includeSymbol = true, useGrouping = true } = options;
|
|
612
|
+
const config = getCurrencyConfig(currency);
|
|
613
|
+
const majorAmount = fromMinorUnits(minorAmount, currency);
|
|
614
|
+
const formattedNumber = majorAmount.toLocaleString("en-US", {
|
|
615
|
+
minimumFractionDigits: config.minorUnits,
|
|
616
|
+
maximumFractionDigits: config.minorUnits,
|
|
617
|
+
useGrouping
|
|
618
|
+
});
|
|
619
|
+
if (!includeSymbol || !config.symbol) {
|
|
620
|
+
return formattedNumber;
|
|
621
|
+
}
|
|
622
|
+
if (config.symbolPosition === "suffix") {
|
|
623
|
+
return `${formattedNumber}${config.symbol}`;
|
|
624
|
+
}
|
|
625
|
+
return `${config.symbol}${formattedNumber}`;
|
|
626
|
+
}
|
|
627
|
+
function addAmounts(a, b) {
|
|
628
|
+
return Math.round(a + b);
|
|
629
|
+
}
|
|
630
|
+
function subtractAmounts(a, b) {
|
|
631
|
+
return Math.round(a - b);
|
|
632
|
+
}
|
|
633
|
+
function multiplyAmount(amount, multiplier) {
|
|
634
|
+
return Math.round(amount * multiplier);
|
|
635
|
+
}
|
|
636
|
+
function divideAmount(amount, divisor) {
|
|
637
|
+
if (divisor === 0) {
|
|
638
|
+
throw new Error("Cannot divide by zero");
|
|
639
|
+
}
|
|
640
|
+
return Math.round(amount / divisor);
|
|
641
|
+
}
|
|
642
|
+
function calculatePercentage(amount, percentage) {
|
|
643
|
+
return Math.round(amount * percentage / 100);
|
|
644
|
+
}
|
|
645
|
+
function parseAmountToMinorUnits(amountString, currency) {
|
|
646
|
+
const parsed = parseFloat(amountString);
|
|
647
|
+
if (isNaN(parsed)) {
|
|
648
|
+
return null;
|
|
649
|
+
}
|
|
650
|
+
return toMinorUnits(parsed, currency);
|
|
651
|
+
}
|
|
652
|
+
function isSupportedCurrency(currency) {
|
|
653
|
+
return currency.toUpperCase() in CURRENCY_CONFIG;
|
|
654
|
+
}
|
|
655
|
+
function parseCurrencyCode(value) {
|
|
656
|
+
if (!value || typeof value !== "string") {
|
|
657
|
+
throw new Error(`Currency value is missing or invalid`);
|
|
658
|
+
}
|
|
659
|
+
const validCodes = Object.values(CurrencyCode);
|
|
660
|
+
if (!validCodes.includes(value)) {
|
|
661
|
+
throw new Error(`"${value}" is not a supported CurrencyCode. Supported codes: ${validCodes.join(", ")}`);
|
|
662
|
+
}
|
|
663
|
+
return value;
|
|
664
|
+
}
|
|
665
|
+
function parseStripeCurrencyCode(value) {
|
|
666
|
+
if (!value || typeof value !== "string") {
|
|
667
|
+
throw new Error(`Currency value is missing or invalid`);
|
|
668
|
+
}
|
|
669
|
+
const validCodes = Object.values(StripeCurrencyCode);
|
|
670
|
+
if (!validCodes.includes(value)) {
|
|
671
|
+
throw new Error(`"${value}" is not a supported Stripe CurrencyCode. Supported codes: ${validCodes.join(", ")}`);
|
|
672
|
+
}
|
|
673
|
+
return value;
|
|
674
|
+
}
|
|
675
|
+
function stringifyMinorUnits(minorAmount, minorUnits) {
|
|
676
|
+
const multiplier = Math.pow(10, minorUnits);
|
|
677
|
+
return minorAmount / multiplier;
|
|
678
|
+
}
|
|
679
|
+
function formatMinorUnitsToString(minorAmount, minorUnits) {
|
|
680
|
+
const majorAmount = stringifyMinorUnits(minorAmount, minorUnits);
|
|
681
|
+
return majorAmount.toString();
|
|
682
|
+
}
|
|
683
|
+
function getMinorUnits(currency) {
|
|
684
|
+
return getCurrencyConfig(currency).minorUnits;
|
|
685
|
+
}
|
|
686
|
+
function createAmount(value, currency) {
|
|
687
|
+
if (value === null || value === void 0 || value === "") {
|
|
688
|
+
return void 0;
|
|
689
|
+
}
|
|
690
|
+
const numericValue = typeof value === "string" ? parseFloat(value) : value;
|
|
691
|
+
if (isNaN(numericValue)) {
|
|
692
|
+
return void 0;
|
|
693
|
+
}
|
|
694
|
+
const minorUnits = getMinorUnits(currency);
|
|
695
|
+
const multiplier = Math.pow(10, minorUnits);
|
|
696
|
+
return {
|
|
697
|
+
amount: Math.round(numericValue * multiplier),
|
|
698
|
+
currency,
|
|
699
|
+
minorUnits
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
function amountToString(amount) {
|
|
703
|
+
if (!amount) {
|
|
704
|
+
return "";
|
|
705
|
+
}
|
|
706
|
+
const divisor = Math.pow(10, amount.minorUnits);
|
|
707
|
+
const majorValue = amount.amount / divisor;
|
|
708
|
+
return majorValue.toFixed(amount.minorUnits);
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
// constants/pricing.constants.ts
|
|
712
|
+
var REGION_MAPPING = {
|
|
713
|
+
// North America
|
|
714
|
+
US: "northAmerica" /* NORTH_AMERICA */,
|
|
715
|
+
CA: "northAmerica" /* NORTH_AMERICA */,
|
|
716
|
+
MX: "northAmerica" /* NORTH_AMERICA */,
|
|
717
|
+
// Europe
|
|
718
|
+
AT: "europe" /* EUROPE */,
|
|
719
|
+
BE: "europe" /* EUROPE */,
|
|
720
|
+
BG: "europe" /* EUROPE */,
|
|
721
|
+
CH: "europe" /* EUROPE */,
|
|
722
|
+
CY: "europe" /* EUROPE */,
|
|
723
|
+
CZ: "europe" /* EUROPE */,
|
|
724
|
+
DE: "europe" /* EUROPE */,
|
|
725
|
+
DK: "europe" /* EUROPE */,
|
|
726
|
+
EE: "europe" /* EUROPE */,
|
|
727
|
+
ES: "europe" /* EUROPE */,
|
|
728
|
+
FI: "europe" /* EUROPE */,
|
|
729
|
+
FR: "europe" /* EUROPE */,
|
|
730
|
+
GB: "europe" /* EUROPE */,
|
|
731
|
+
// Stripe uses 'GB' (not 'UK')
|
|
732
|
+
GR: "europe" /* EUROPE */,
|
|
733
|
+
HR: "europe" /* EUROPE */,
|
|
734
|
+
HU: "europe" /* EUROPE */,
|
|
735
|
+
IE: "europe" /* EUROPE */,
|
|
736
|
+
IT: "europe" /* EUROPE */,
|
|
737
|
+
LI: "europe" /* EUROPE */,
|
|
738
|
+
LT: "europe" /* EUROPE */,
|
|
739
|
+
LU: "europe" /* EUROPE */,
|
|
740
|
+
LV: "europe" /* EUROPE */,
|
|
741
|
+
MT: "europe" /* EUROPE */,
|
|
742
|
+
NL: "europe" /* EUROPE */,
|
|
743
|
+
NO: "europe" /* EUROPE */,
|
|
744
|
+
PL: "europe" /* EUROPE */,
|
|
745
|
+
PT: "europe" /* EUROPE */,
|
|
746
|
+
RO: "europe" /* EUROPE */,
|
|
747
|
+
SE: "europe" /* EUROPE */,
|
|
748
|
+
SI: "europe" /* EUROPE */,
|
|
749
|
+
SK: "europe" /* EUROPE */,
|
|
750
|
+
GI: "europe" /* EUROPE */,
|
|
751
|
+
// Gibraltar (NEW)
|
|
752
|
+
// Others (Asia-Pacific, Middle East, South America, etc.)
|
|
753
|
+
AE: "others" /* OTHER */,
|
|
754
|
+
// United Arab Emirates
|
|
755
|
+
AU: "others" /* OTHER */,
|
|
756
|
+
// Australia
|
|
757
|
+
BR: "others" /* OTHER */,
|
|
758
|
+
// Brazil (NEW)
|
|
759
|
+
HK: "others" /* OTHER */,
|
|
760
|
+
// Hong Kong
|
|
761
|
+
IN: "others" /* OTHER */,
|
|
762
|
+
// India (NEW)
|
|
763
|
+
JP: "others" /* OTHER */,
|
|
764
|
+
// Japan
|
|
765
|
+
MY: "others" /* OTHER */,
|
|
766
|
+
// Malaysia
|
|
767
|
+
NZ: "others" /* OTHER */,
|
|
768
|
+
// New Zealand
|
|
769
|
+
SG: "others" /* OTHER */,
|
|
770
|
+
// Singapore
|
|
771
|
+
TH: "others" /* OTHER */
|
|
772
|
+
// Thailand
|
|
773
|
+
};
|
|
774
|
+
var STRIPE_SUPPORTED_COUNTRIES = /* @__PURE__ */ new Set([
|
|
775
|
+
// North America
|
|
776
|
+
"US",
|
|
777
|
+
"CA",
|
|
778
|
+
"MX",
|
|
779
|
+
// Europe
|
|
780
|
+
"AT",
|
|
781
|
+
"BE",
|
|
782
|
+
"BG",
|
|
783
|
+
"CH",
|
|
784
|
+
"CY",
|
|
785
|
+
"CZ",
|
|
786
|
+
"DE",
|
|
787
|
+
"DK",
|
|
788
|
+
"EE",
|
|
789
|
+
"ES",
|
|
790
|
+
"FI",
|
|
791
|
+
"FR",
|
|
792
|
+
"GB",
|
|
793
|
+
"GR",
|
|
794
|
+
"HR",
|
|
795
|
+
"HU",
|
|
796
|
+
"IE",
|
|
797
|
+
"IT",
|
|
798
|
+
"LI",
|
|
799
|
+
"LT",
|
|
800
|
+
"LU",
|
|
801
|
+
"LV",
|
|
802
|
+
"MT",
|
|
803
|
+
"NL",
|
|
804
|
+
"NO",
|
|
805
|
+
"PL",
|
|
806
|
+
"PT",
|
|
807
|
+
"RO",
|
|
808
|
+
"SE",
|
|
809
|
+
"SI",
|
|
810
|
+
"SK",
|
|
811
|
+
// Others
|
|
812
|
+
"AE",
|
|
813
|
+
// United Arab Emirates
|
|
814
|
+
"AU",
|
|
815
|
+
// Australia
|
|
816
|
+
"BR",
|
|
817
|
+
// Brazil (NEW)
|
|
818
|
+
"GI",
|
|
819
|
+
// Gibraltar (NEW)
|
|
820
|
+
"HK",
|
|
821
|
+
// Hong Kong
|
|
822
|
+
"IN",
|
|
823
|
+
// India (NEW)
|
|
824
|
+
"JP",
|
|
825
|
+
// Japan
|
|
826
|
+
"MY",
|
|
827
|
+
// Malaysia
|
|
828
|
+
"NZ",
|
|
829
|
+
// New Zealand
|
|
830
|
+
"SG",
|
|
831
|
+
// Singapore
|
|
832
|
+
"TH"
|
|
833
|
+
// Thailand
|
|
834
|
+
]);
|
|
835
|
+
var NAFixedRates = {
|
|
836
|
+
USD: { rate: 30, country: "United States" },
|
|
837
|
+
CAD: { rate: 20, country: "Canada" },
|
|
838
|
+
MXN: { rate: 300, country: "Mexico" }
|
|
839
|
+
};
|
|
840
|
+
var EUFixedRates = {
|
|
841
|
+
EUR: { rate: 30, country: "European Union" },
|
|
842
|
+
GBP: { rate: 20, country: "Great Britain" },
|
|
843
|
+
CHF: { rate: 30, country: "Switzerland" },
|
|
844
|
+
DKK: { rate: 180, country: "Denmark" },
|
|
845
|
+
NOK: { rate: 200, country: "Norway" },
|
|
846
|
+
SEK: { rate: 180, country: "Sweden" },
|
|
847
|
+
PLN: { rate: 100, country: "Poland" }
|
|
848
|
+
};
|
|
849
|
+
var OtherFixedRates = {
|
|
850
|
+
AUD: { rate: 30, country: "Australia" },
|
|
851
|
+
NZD: { rate: 30, country: "New Zealand" },
|
|
852
|
+
SGD: { rate: 50, country: "Singapore" },
|
|
853
|
+
MYR: { rate: 100, country: "Malaysia" },
|
|
854
|
+
JPY: { rate: 30, country: "Japan" }
|
|
855
|
+
};
|
|
856
|
+
var COUNTRY_CURRENCIES = {
|
|
857
|
+
US: "USD",
|
|
858
|
+
CA: "CAD",
|
|
859
|
+
MX: "MXN",
|
|
860
|
+
AT: "EUR",
|
|
861
|
+
BE: "EUR",
|
|
862
|
+
BG: "BGN",
|
|
863
|
+
CH: "CHF",
|
|
864
|
+
CY: "EUR",
|
|
865
|
+
CZ: "CZK",
|
|
866
|
+
DE: "EUR",
|
|
867
|
+
DK: "DKK",
|
|
868
|
+
EE: "EUR",
|
|
869
|
+
ES: "EUR",
|
|
870
|
+
FI: "EUR",
|
|
871
|
+
FR: "EUR",
|
|
872
|
+
GB: "GBP",
|
|
873
|
+
GI: "GIP",
|
|
874
|
+
GR: "EUR",
|
|
875
|
+
HR: "EUR",
|
|
876
|
+
HU: "HUF",
|
|
877
|
+
IE: "EUR",
|
|
878
|
+
IT: "EUR",
|
|
879
|
+
LI: "CHF",
|
|
880
|
+
LT: "EUR",
|
|
881
|
+
LU: "EUR",
|
|
882
|
+
LV: "EUR",
|
|
883
|
+
MT: "EUR",
|
|
884
|
+
NL: "EUR",
|
|
885
|
+
NO: "NOK",
|
|
886
|
+
PL: "PLN",
|
|
887
|
+
PT: "EUR",
|
|
888
|
+
RO: "RON",
|
|
889
|
+
SE: "SEK",
|
|
890
|
+
SI: "EUR",
|
|
891
|
+
SK: "EUR",
|
|
892
|
+
AE: "AED",
|
|
893
|
+
AU: "AUD",
|
|
894
|
+
BR: "BRL",
|
|
895
|
+
HK: "HKD",
|
|
896
|
+
IN: "INR",
|
|
897
|
+
JP: "JPY",
|
|
898
|
+
MY: "MYR",
|
|
899
|
+
NZ: "NZD",
|
|
900
|
+
SG: "SGD",
|
|
901
|
+
TH: "THB"
|
|
902
|
+
};
|
|
903
|
+
|
|
904
|
+
// utils/pricing.util.ts
|
|
905
|
+
function getPricingRegionFromCountry(countryCode) {
|
|
906
|
+
const code = (countryCode || "").toUpperCase();
|
|
907
|
+
if (NORTH_AMERICA.has(code)) return "northAmerica" /* NORTH_AMERICA */;
|
|
908
|
+
if (EUROPE.has(code)) return "europe" /* EUROPE */;
|
|
909
|
+
return "others" /* OTHER */;
|
|
910
|
+
}
|
|
911
|
+
var NORTH_AMERICA = getCountriesByRegion("northAmerica" /* NORTH_AMERICA */);
|
|
912
|
+
var EUROPE = getCountriesByRegion("europe" /* EUROPE */);
|
|
913
|
+
function convertFixedFeeToLocalCurrency(currency, region) {
|
|
914
|
+
const currencyCode = currency.toUpperCase();
|
|
915
|
+
let fixedRate;
|
|
916
|
+
switch (region) {
|
|
917
|
+
case "northAmerica" /* NORTH_AMERICA */: {
|
|
918
|
+
fixedRate = NAFixedRates[currencyCode];
|
|
919
|
+
break;
|
|
920
|
+
}
|
|
921
|
+
case "europe" /* EUROPE */: {
|
|
922
|
+
fixedRate = EUFixedRates[currencyCode];
|
|
923
|
+
break;
|
|
924
|
+
}
|
|
925
|
+
case "others" /* OTHER */: {
|
|
926
|
+
fixedRate = OtherFixedRates[currencyCode];
|
|
927
|
+
break;
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
return fixedRate?.rate ?? null;
|
|
931
|
+
}
|
|
932
|
+
function getCountriesByRegion(region) {
|
|
933
|
+
const countries = /* @__PURE__ */ new Set();
|
|
934
|
+
for (const [country, mappedRegion] of Object.entries(REGION_MAPPING)) {
|
|
935
|
+
if (mappedRegion === region) {
|
|
936
|
+
countries.add(country);
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
return countries;
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
// utils/report-sign.util.ts
|
|
943
|
+
var REPORT_NEGATE_PATHS = /* @__PURE__ */ new Set([
|
|
944
|
+
// Sales summary — reductions to revenue
|
|
945
|
+
"salesSummary.discounts.netDiscounts",
|
|
946
|
+
"salesSummary.refundsItems",
|
|
947
|
+
// Settlement — money going out of the merchant
|
|
948
|
+
"settlementBreakdown.cards.refunded",
|
|
949
|
+
"settlementBreakdown.cards.processingFees",
|
|
950
|
+
"settlementBreakdown.cash.refunded",
|
|
951
|
+
"settlementBreakdown.custom[].refunded",
|
|
952
|
+
"settlementBreakdown.custom[].processingFees",
|
|
953
|
+
// Tax breakdown — refunds sub-table renders signed-negative
|
|
954
|
+
"taxBreakdown.refunds.entries[].taxableSales",
|
|
955
|
+
"taxBreakdown.refunds.entries[].tax",
|
|
956
|
+
"taxBreakdown.refunds.total.taxableSales",
|
|
957
|
+
"taxBreakdown.refunds.total.tax",
|
|
958
|
+
// Refunds breakdown — reductions and naturally-signed entries
|
|
959
|
+
"refundsBreakdown.discountsReversed",
|
|
960
|
+
"refundsBreakdown.cashRoundingRefund",
|
|
961
|
+
// Fees breakdown — refunded magnitudes are money flowing back out
|
|
962
|
+
"feesBreakdown.productFee.refundedProductFees",
|
|
963
|
+
"feesBreakdown.cartFee.refundedCartFees",
|
|
964
|
+
// Discounts breakdown — refunded magnitudes reverse discount reductions
|
|
965
|
+
"discountsBreakdown.productDiscounts.refundedProductDiscounts",
|
|
966
|
+
"discountsBreakdown.cartDiscounts.refundedCartDiscounts",
|
|
967
|
+
// Staff sales — refunds are money flowing back out
|
|
968
|
+
"staffSales.staffSales[].refundSales",
|
|
969
|
+
"staffSales.refundTotal",
|
|
970
|
+
// Tips — refunds are money flowing back out
|
|
971
|
+
"tipsBreakdown.tips[].refundAmount"
|
|
972
|
+
]);
|
|
973
|
+
function signReportForDisplay(report) {
|
|
974
|
+
return negateAtPaths(report, "", REPORT_NEGATE_PATHS);
|
|
975
|
+
}
|
|
976
|
+
function negateAtPaths(value, path, paths) {
|
|
977
|
+
if (Array.isArray(value)) {
|
|
978
|
+
const next = `${path}[]`;
|
|
979
|
+
return value.map((item) => negateAtPaths(item, next, paths));
|
|
980
|
+
}
|
|
981
|
+
if (value !== null && typeof value === "object") {
|
|
982
|
+
const out = {};
|
|
983
|
+
for (const [key, child] of Object.entries(value)) {
|
|
984
|
+
const next = path ? `${path}.${key}` : key;
|
|
985
|
+
out[key] = negateAtPaths(child, next, paths);
|
|
986
|
+
}
|
|
987
|
+
return out;
|
|
988
|
+
}
|
|
989
|
+
if (typeof value === "number" && paths.has(path)) {
|
|
990
|
+
return value === 0 ? 0 : -value;
|
|
991
|
+
}
|
|
992
|
+
return value;
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
// utils/mongo.util.ts
|
|
996
|
+
function padHex(value, length) {
|
|
997
|
+
return value.toString(16).padStart(length, "0");
|
|
998
|
+
}
|
|
999
|
+
var PROCESS_RANDOM = Array.from(
|
|
1000
|
+
{ length: 5 },
|
|
1001
|
+
() => padHex(Math.floor(Math.random() * 256), 2)
|
|
1002
|
+
).join("");
|
|
1003
|
+
var objectIdCounter = Math.floor(Math.random() * 16777215);
|
|
1004
|
+
function generateMongoID() {
|
|
1005
|
+
const timestamp = padHex(Math.floor(Date.now() / 1e3), 8);
|
|
1006
|
+
objectIdCounter = (objectIdCounter + 1) % 16777216;
|
|
1007
|
+
return timestamp + PROCESS_RANDOM + padHex(objectIdCounter, 6);
|
|
1008
|
+
}
|
|
1009
|
+
function getCurrentISODate() {
|
|
1010
|
+
const now = new Date(Date.now());
|
|
1011
|
+
return now.toISOString();
|
|
1012
|
+
}
|
|
1013
|
+
function normalizeMongoIdString(value) {
|
|
1014
|
+
if (value == null || value === "") {
|
|
1015
|
+
return null;
|
|
1016
|
+
}
|
|
1017
|
+
if (typeof value === "string") {
|
|
1018
|
+
const t = value.trim();
|
|
1019
|
+
return t.length > 0 ? t : null;
|
|
1020
|
+
}
|
|
1021
|
+
if (typeof value === "object" && value !== null && "$oid" in value) {
|
|
1022
|
+
const oid = value.$oid;
|
|
1023
|
+
return typeof oid === "string" && oid.length > 0 ? oid : null;
|
|
1024
|
+
}
|
|
1025
|
+
return null;
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
// order-state-machine/types.ts
|
|
1029
|
+
var PAYMENT_STATES = [
|
|
1030
|
+
"unpaid",
|
|
1031
|
+
"payment_pending",
|
|
1032
|
+
"partially_paid",
|
|
1033
|
+
"paid",
|
|
1034
|
+
"partially_refunded",
|
|
1035
|
+
"refunded",
|
|
1036
|
+
"voided"
|
|
1037
|
+
];
|
|
1038
|
+
var FULFILLMENT_STATES = [
|
|
1039
|
+
"draft",
|
|
1040
|
+
"pending",
|
|
1041
|
+
"on_hold",
|
|
1042
|
+
"in_progress",
|
|
1043
|
+
"fulfilled",
|
|
1044
|
+
"partially_fulfilled",
|
|
1045
|
+
"returned",
|
|
1046
|
+
"partially_returned",
|
|
1047
|
+
"cancelled"
|
|
1048
|
+
];
|
|
1049
|
+
function isPaymentState(value) {
|
|
1050
|
+
return PAYMENT_STATES.includes(value);
|
|
1051
|
+
}
|
|
1052
|
+
function isFulfillmentState(value) {
|
|
1053
|
+
return FULFILLMENT_STATES.includes(value);
|
|
1054
|
+
}
|
|
1055
|
+
var CONDITION_OPERATORS = [
|
|
1056
|
+
"eq",
|
|
1057
|
+
"neq",
|
|
1058
|
+
"gt",
|
|
1059
|
+
"gte",
|
|
1060
|
+
"lt",
|
|
1061
|
+
"lte",
|
|
1062
|
+
"in",
|
|
1063
|
+
"notIn",
|
|
1064
|
+
"isEmpty",
|
|
1065
|
+
"isNotEmpty"
|
|
1066
|
+
];
|
|
1067
|
+
function isConditionOperator(value) {
|
|
1068
|
+
return CONDITION_OPERATORS.includes(value);
|
|
1069
|
+
}
|
|
1070
|
+
var PATH_MODES = [
|
|
1071
|
+
"strict",
|
|
1072
|
+
"permissive"
|
|
1073
|
+
];
|
|
1074
|
+
|
|
1075
|
+
// order-state-machine/state-schema.ts
|
|
1076
|
+
var PAYMENT_DEFS = [
|
|
1077
|
+
{ id: "unpaid", label: "Unpaid", terminal: false },
|
|
1078
|
+
{ id: "payment_pending", label: "Payment Pending", terminal: false },
|
|
1079
|
+
{ id: "partially_paid", label: "Partially Paid", terminal: false },
|
|
1080
|
+
{ id: "paid", label: "Paid", terminal: false },
|
|
1081
|
+
{ id: "partially_refunded", label: "Partially Refunded", terminal: false },
|
|
1082
|
+
{ id: "refunded", label: "Refunded", terminal: true },
|
|
1083
|
+
{ id: "voided", label: "Voided", terminal: true }
|
|
1084
|
+
];
|
|
1085
|
+
var FULFILLMENT_DEFS = [
|
|
1086
|
+
{ id: "draft", label: "Draft", terminal: false },
|
|
1087
|
+
{ id: "pending", label: "Pending", terminal: false },
|
|
1088
|
+
{ id: "on_hold", label: "On Hold", terminal: false },
|
|
1089
|
+
{ id: "in_progress", label: "In Progress", terminal: false },
|
|
1090
|
+
{ id: "fulfilled", label: "Fulfilled", terminal: true },
|
|
1091
|
+
{ id: "partially_fulfilled", label: "Partially Fulfilled", terminal: false },
|
|
1092
|
+
{ id: "returned", label: "Returned", terminal: true },
|
|
1093
|
+
{ id: "partially_returned", label: "Partially Returned", terminal: false },
|
|
1094
|
+
{ id: "cancelled", label: "Cancelled", terminal: true }
|
|
1095
|
+
];
|
|
1096
|
+
function basePaymentDefinitions() {
|
|
1097
|
+
return PAYMENT_DEFS.map((d) => ({
|
|
1098
|
+
id: d.id,
|
|
1099
|
+
label: d.label,
|
|
1100
|
+
isBase: true,
|
|
1101
|
+
isTerminal: d.terminal
|
|
1102
|
+
}));
|
|
1103
|
+
}
|
|
1104
|
+
function baseFulfillmentDefinitions() {
|
|
1105
|
+
return FULFILLMENT_DEFS.map((d) => ({
|
|
1106
|
+
id: d.id,
|
|
1107
|
+
label: d.label,
|
|
1108
|
+
isBase: true,
|
|
1109
|
+
isTerminal: d.terminal
|
|
1110
|
+
}));
|
|
1111
|
+
}
|
|
1112
|
+
var STATE_SCHEMA = Object.freeze({
|
|
1113
|
+
paymentStates: Object.freeze(basePaymentDefinitions()),
|
|
1114
|
+
fulfillmentStates: Object.freeze(baseFulfillmentDefinitions())
|
|
1115
|
+
});
|
|
1116
|
+
|
|
1117
|
+
// order-state-machine/financial-invariants.ts
|
|
1118
|
+
var REFUND_ALLOWED_FULFILLMENT = /* @__PURE__ */ new Set(["fulfilled", "returned", "partially_returned", "cancelled"]);
|
|
1119
|
+
var PAYMENT_COLLECTION_ORDER = ["unpaid", "partially_paid", "paid"];
|
|
1120
|
+
var FINANCIAL_INVARIANTS = [
|
|
1121
|
+
{
|
|
1122
|
+
id: "no-leave-refunded",
|
|
1123
|
+
description: "Cannot change payment state after a full refund (no un-refund / reactivation of funds)",
|
|
1124
|
+
check: (from, to) => from?.payment === "refunded" && to.payment !== "refunded"
|
|
1125
|
+
},
|
|
1126
|
+
{
|
|
1127
|
+
id: "no-leave-voided",
|
|
1128
|
+
description: "Cannot un-void payment (voided orders stay voided on the payment axis)",
|
|
1129
|
+
check: (from, to) => from?.payment === "voided" && to.payment !== "voided"
|
|
1130
|
+
},
|
|
1131
|
+
{
|
|
1132
|
+
id: "no-refund-without-fulfillment",
|
|
1133
|
+
description: "Cannot mark payment as fully refunded unless fulfillment is delivered, returned, or cancelled",
|
|
1134
|
+
check: (_from, to) => to.payment === "refunded" && !REFUND_ALLOWED_FULFILLMENT.has(to.fulfillment)
|
|
1135
|
+
},
|
|
1136
|
+
{
|
|
1137
|
+
id: "no-partial-refund-in-draft",
|
|
1138
|
+
description: "Cannot partially refund while order is still in draft fulfillment",
|
|
1139
|
+
check: (_from, to) => to.payment === "partially_refunded" && to.fulfillment === "draft"
|
|
1140
|
+
},
|
|
1141
|
+
{
|
|
1142
|
+
id: "no-payment-regression",
|
|
1143
|
+
description: "Payment cannot regress to a lower collection state without a refund \u2014 collected funds must be returned through the refund flow, not by reverting payment state",
|
|
1144
|
+
check: (from, to) => {
|
|
1145
|
+
if (!from) return false;
|
|
1146
|
+
const fromIdx = PAYMENT_COLLECTION_ORDER.indexOf(from.payment);
|
|
1147
|
+
const toIdx = PAYMENT_COLLECTION_ORDER.indexOf(to.payment);
|
|
1148
|
+
return fromIdx !== -1 && toIdx !== -1 && fromIdx > toIdx;
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
];
|
|
1152
|
+
function getFinancialInvariantViolations(from, to) {
|
|
1153
|
+
const ids = [];
|
|
1154
|
+
for (const inv of FINANCIAL_INVARIANTS) {
|
|
1155
|
+
if (inv.check(from, to)) {
|
|
1156
|
+
ids.push(inv.id);
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
return ids;
|
|
1160
|
+
}
|
|
1161
|
+
function violatesFinancialInvariant(from, to) {
|
|
1162
|
+
return getFinancialInvariantViolations(from, to).length > 0;
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
// order-state-machine/default-cross-axis-rules.ts
|
|
1166
|
+
var DEFAULT_CROSS_AXIS_RULES = [
|
|
1167
|
+
{
|
|
1168
|
+
id: "require-payment-before-prep",
|
|
1169
|
+
label: "Require payment before prep",
|
|
1170
|
+
description: "When moving fulfillment to in progress, payment must be paid or partially paid",
|
|
1171
|
+
enabled: true,
|
|
1172
|
+
trigger: { axis: "fulfillment", to: "in_progress" },
|
|
1173
|
+
requires: { axis: "payment", states: ["paid", "partially_paid"] }
|
|
1174
|
+
},
|
|
1175
|
+
{
|
|
1176
|
+
id: "require-fulfillment-or-return-before-full-refund",
|
|
1177
|
+
label: "Require fulfillment or return before full refund",
|
|
1178
|
+
description: "When moving payment to refunded, fulfillment must be fulfilled, returned, partially returned, or cancelled",
|
|
1179
|
+
enabled: true,
|
|
1180
|
+
trigger: { axis: "payment", to: "refunded" },
|
|
1181
|
+
requires: {
|
|
1182
|
+
axis: "fulfillment",
|
|
1183
|
+
states: ["fulfilled", "returned", "partially_returned", "cancelled"]
|
|
1184
|
+
}
|
|
1185
|
+
},
|
|
1186
|
+
{
|
|
1187
|
+
id: "require-return-context-before-partial-refund",
|
|
1188
|
+
label: "Require return path before partial refund",
|
|
1189
|
+
description: "When moving payment to partially refunded, fulfillment must reflect a completed or return path",
|
|
1190
|
+
enabled: true,
|
|
1191
|
+
trigger: { axis: "payment", to: "partially_refunded" },
|
|
1192
|
+
requires: {
|
|
1193
|
+
axis: "fulfillment",
|
|
1194
|
+
states: ["fulfilled", "partially_returned", "returned"]
|
|
1195
|
+
}
|
|
1196
|
+
},
|
|
1197
|
+
{
|
|
1198
|
+
id: "block-fulfillment-when-payment-voided",
|
|
1199
|
+
label: "Block fulfillment completion when payment is voided",
|
|
1200
|
+
description: "When moving fulfillment to fulfilled, payment must not be voided",
|
|
1201
|
+
enabled: true,
|
|
1202
|
+
trigger: { axis: "fulfillment", to: "fulfilled" },
|
|
1203
|
+
requires: {
|
|
1204
|
+
axis: "payment",
|
|
1205
|
+
states: ["unpaid", "partially_paid", "paid", "partially_refunded", "refunded"]
|
|
1206
|
+
}
|
|
1207
|
+
},
|
|
1208
|
+
{
|
|
1209
|
+
id: "require-payment-before-fulfillment-complete",
|
|
1210
|
+
label: "Require payment before fulfillment complete",
|
|
1211
|
+
description: "When moving fulfillment to fulfilled, payment must be paid or partially paid",
|
|
1212
|
+
enabled: true,
|
|
1213
|
+
trigger: { axis: "fulfillment", to: "fulfilled" },
|
|
1214
|
+
requires: { axis: "payment", states: ["paid", "partially_paid"] }
|
|
1215
|
+
}
|
|
1216
|
+
];
|
|
1217
|
+
|
|
1218
|
+
// order-state-machine/default-config.ts
|
|
1219
|
+
var DEFAULT_EPOCH = /* @__PURE__ */ new Date(0);
|
|
1220
|
+
var PAYMENT_LABELS = new Map(
|
|
1221
|
+
basePaymentDefinitions().map((d) => [d.id, d.label])
|
|
1222
|
+
);
|
|
1223
|
+
var FULFILLMENT_LABELS = new Map(
|
|
1224
|
+
baseFulfillmentDefinitions().map((d) => [d.id, d.label])
|
|
1225
|
+
);
|
|
1226
|
+
var TERMINAL_PAYMENT_STATES = new Set(
|
|
1227
|
+
basePaymentDefinitions().filter((d) => d.isTerminal).map((d) => d.id)
|
|
1228
|
+
);
|
|
1229
|
+
var DISPLAY_LABEL_OVERRIDES = {
|
|
1230
|
+
"unpaid|draft": "In Cart",
|
|
1231
|
+
"unpaid|pending": "Pending Payment",
|
|
1232
|
+
"unpaid|on_hold": "On Hold",
|
|
1233
|
+
"unpaid|cancelled": "Cancelled",
|
|
1234
|
+
"partially_paid|pending": "Deposit Received",
|
|
1235
|
+
"partially_paid|on_hold": "On Hold - Deposit Received",
|
|
1236
|
+
"paid|pending": "Paid - Awaiting Fulfillment",
|
|
1237
|
+
"paid|on_hold": "Paid - On Hold",
|
|
1238
|
+
"paid|fulfilled": "Completed",
|
|
1239
|
+
"partially_refunded|fulfilled": "Partially Refunded",
|
|
1240
|
+
"partially_refunded|partially_returned": "Partially Returned",
|
|
1241
|
+
"refunded|fulfilled": "Refunded",
|
|
1242
|
+
"refunded|returned": "Returned and Refunded",
|
|
1243
|
+
"voided|cancelled": "Cancelled"
|
|
1244
|
+
};
|
|
1245
|
+
function buildDefaultDisplayStateMap() {
|
|
1246
|
+
const rules = [];
|
|
1247
|
+
for (const p of PAYMENT_STATES) {
|
|
1248
|
+
for (const f of FULFILLMENT_STATES) {
|
|
1249
|
+
const key = `${p}|${f}`;
|
|
1250
|
+
const override = DISPLAY_LABEL_OVERRIDES[key];
|
|
1251
|
+
if (TERMINAL_PAYMENT_STATES.has(p) && !override) continue;
|
|
1252
|
+
const label = override ?? `${PAYMENT_LABELS.get(p)} / ${FULFILLMENT_LABELS.get(f)}`;
|
|
1253
|
+
rules.push({ paymentState: p, fulfillmentState: f, label });
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
return rules;
|
|
1257
|
+
}
|
|
1258
|
+
var DEFAULT_DISPLAY_STATE_MAP = buildDefaultDisplayStateMap();
|
|
1259
|
+
var DEFAULT_CONFIG = {
|
|
1260
|
+
_id: "default",
|
|
1261
|
+
companyId: "system",
|
|
1262
|
+
version: 1,
|
|
1263
|
+
name: "Default",
|
|
1264
|
+
isDefault: true,
|
|
1265
|
+
paymentPaths: [],
|
|
1266
|
+
fulfillmentPaths: [],
|
|
1267
|
+
paymentPathMode: "permissive",
|
|
1268
|
+
fulfillmentPathMode: "permissive",
|
|
1269
|
+
crossAxisRules: [...DEFAULT_CROSS_AXIS_RULES],
|
|
1270
|
+
transitionConditions: [],
|
|
1271
|
+
validInitialStates: [{ payment: "unpaid", fulfillment: "draft" }],
|
|
1272
|
+
displayStateMap: [...DEFAULT_DISPLAY_STATE_MAP],
|
|
1273
|
+
createdAt: DEFAULT_EPOCH,
|
|
1274
|
+
updatedAt: DEFAULT_EPOCH
|
|
1275
|
+
};
|
|
1276
|
+
function buildResolvedConfig(config) {
|
|
1277
|
+
return {
|
|
1278
|
+
...config,
|
|
1279
|
+
paymentStates: STATE_SCHEMA.paymentStates,
|
|
1280
|
+
fulfillmentStates: STATE_SCHEMA.fulfillmentStates
|
|
1281
|
+
};
|
|
1282
|
+
}
|
|
1283
|
+
var DEFAULT_RESOLVED_CONFIG = buildResolvedConfig(DEFAULT_CONFIG);
|
|
1284
|
+
|
|
1285
|
+
// order-state-machine/pos-preset.ts
|
|
1286
|
+
var POS_CROSS_AXIS_RULES = [
|
|
1287
|
+
{
|
|
1288
|
+
id: "pos-pay-requires-open-fulfillment",
|
|
1289
|
+
label: "Payments only on open fulfillment states",
|
|
1290
|
+
description: "POS payments are only valid on orders whose fulfillment is open (draft / pending / on_hold) or auto-fulfilled in lock-step (fulfilled). Returned / cancelled / in-progress fulfillment must use refund flows instead.",
|
|
1291
|
+
enabled: true,
|
|
1292
|
+
trigger: { axis: "payment", to: ["payment_pending", "paid", "partially_paid"] },
|
|
1293
|
+
requires: {
|
|
1294
|
+
axis: "fulfillment",
|
|
1295
|
+
states: ["draft", "pending", "on_hold", "fulfilled"]
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
];
|
|
1299
|
+
var POS_VALID_INITIAL_STATES = [
|
|
1300
|
+
{ payment: "unpaid", fulfillment: "draft" },
|
|
1301
|
+
{ payment: "unpaid", fulfillment: "on_hold" },
|
|
1302
|
+
{ payment: "unpaid", fulfillment: "pending" },
|
|
1303
|
+
{ payment: "paid", fulfillment: "fulfilled" },
|
|
1304
|
+
{ payment: "partially_paid", fulfillment: "draft" },
|
|
1305
|
+
{ payment: "partially_paid", fulfillment: "pending" }
|
|
1306
|
+
];
|
|
1307
|
+
function buildPosPresetConfig(companyId) {
|
|
1308
|
+
return {
|
|
1309
|
+
...DEFAULT_CONFIG,
|
|
1310
|
+
_id: "pos-preset",
|
|
1311
|
+
companyId: companyId ?? DEFAULT_CONFIG.companyId,
|
|
1312
|
+
name: "POS Preset",
|
|
1313
|
+
crossAxisRules: [...DEFAULT_CROSS_AXIS_RULES, ...POS_CROSS_AXIS_RULES],
|
|
1314
|
+
validInitialStates: [...POS_VALID_INITIAL_STATES],
|
|
1315
|
+
displayStateMap: [...DEFAULT_DISPLAY_STATE_MAP]
|
|
1316
|
+
};
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1319
|
+
// order-state-machine/build-order-context.ts
|
|
1320
|
+
function sumNumbers(items) {
|
|
1321
|
+
if (!items?.length) return 0;
|
|
1322
|
+
let t = 0;
|
|
1323
|
+
for (const x of items) {
|
|
1324
|
+
const n = x.amount;
|
|
1325
|
+
if (typeof n === "number" && Number.isFinite(n)) t += n;
|
|
1326
|
+
}
|
|
1327
|
+
return t;
|
|
1328
|
+
}
|
|
1329
|
+
function sumRefundQuantities(refunds) {
|
|
1330
|
+
if (!refunds?.length) return 0;
|
|
1331
|
+
let t = 0;
|
|
1332
|
+
for (const r of refunds) {
|
|
1333
|
+
const q = r.quantity;
|
|
1334
|
+
if (typeof q === "number" && Number.isFinite(q) && q > 0) t += q;
|
|
1335
|
+
}
|
|
1336
|
+
return t;
|
|
1337
|
+
}
|
|
1338
|
+
function buildOrderContext(order, extras) {
|
|
1339
|
+
const o = order ?? {};
|
|
1340
|
+
const total = typeof o.total === "number" && Number.isFinite(o.total) ? o.total : 0;
|
|
1341
|
+
const balance = typeof o.balance === "number" && Number.isFinite(o.balance) ? o.balance : 0;
|
|
1342
|
+
const paymentMethods = o.paymentMethods ?? [];
|
|
1343
|
+
const refunds = o.refunds ?? o.refund ?? [];
|
|
1344
|
+
const lineItems = o.lineItems ?? [];
|
|
1345
|
+
const totalPaid = sumNumbers(paymentMethods);
|
|
1346
|
+
const totalRefunded = sumRefundQuantities(refunds);
|
|
1347
|
+
const isFullyPaid = total > 0 ? balance <= 0 : totalPaid > 0 && balance <= 0;
|
|
1348
|
+
const hasPartialPayments = totalPaid > 0 && balance > 0;
|
|
1349
|
+
let itemCount = 0;
|
|
1350
|
+
let fulfilledItemCount = 0;
|
|
1351
|
+
let returnedItemCount = 0;
|
|
1352
|
+
for (const li of lineItems) {
|
|
1353
|
+
const q = typeof li.quantity === "number" && Number.isFinite(li.quantity) ? Math.max(0, li.quantity) : 0;
|
|
1354
|
+
itemCount += q;
|
|
1355
|
+
const fq = typeof li.fulfilledQuantity === "number" && Number.isFinite(li.fulfilledQuantity) ? Math.max(0, li.fulfilledQuantity) : 0;
|
|
1356
|
+
fulfilledItemCount += Math.min(fq, q);
|
|
1357
|
+
const rq = typeof li.returnedQuantity === "number" && Number.isFinite(li.returnedQuantity) ? Math.max(0, li.returnedQuantity) : 0;
|
|
1358
|
+
returnedItemCount += Math.min(rq, q);
|
|
1359
|
+
}
|
|
1360
|
+
const isFullyReturned = itemCount > 0 ? returnedItemCount >= itemCount : returnedItemCount > 0;
|
|
1361
|
+
const hasPartialReturns = returnedItemCount > 0 && !isFullyReturned;
|
|
1362
|
+
return {
|
|
1363
|
+
order: {
|
|
1364
|
+
total,
|
|
1365
|
+
balance,
|
|
1366
|
+
paymentMethods,
|
|
1367
|
+
refunds,
|
|
1368
|
+
lineItems
|
|
1369
|
+
},
|
|
1370
|
+
computed: {
|
|
1371
|
+
balance,
|
|
1372
|
+
isFullyPaid,
|
|
1373
|
+
hasPartialPayments,
|
|
1374
|
+
totalPaid,
|
|
1375
|
+
totalRefunded,
|
|
1376
|
+
itemCount,
|
|
1377
|
+
fulfilledItemCount,
|
|
1378
|
+
returnedItemCount,
|
|
1379
|
+
isFullyReturned,
|
|
1380
|
+
hasPartialReturns
|
|
1381
|
+
},
|
|
1382
|
+
splitPayment: extras?.splitPayment
|
|
1383
|
+
};
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1386
|
+
// order-state-machine/display-state.ts
|
|
1387
|
+
function matchesOptional(actual, rule) {
|
|
1388
|
+
if (rule === void 0) return true;
|
|
1389
|
+
return Array.isArray(rule) ? rule.includes(actual) : rule === actual;
|
|
1390
|
+
}
|
|
1391
|
+
function deriveDisplayState(payment, fulfillment, config) {
|
|
1392
|
+
for (const rule of config.displayStateMap) {
|
|
1393
|
+
if (matchesOptional(payment, rule.paymentState) && matchesOptional(fulfillment, rule.fulfillmentState)) {
|
|
1394
|
+
return { label: rule.label, color: rule.color, icon: rule.icon };
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
return { label: `${payment} / ${fulfillment}` };
|
|
1398
|
+
}
|
|
1399
|
+
function displayRuleMatchesPair(rule, payment, fulfillment) {
|
|
1400
|
+
return matchesOptional(payment, rule.paymentState) && matchesOptional(fulfillment, rule.fulfillmentState);
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1403
|
+
// order-state-machine/condition-eval.ts
|
|
1404
|
+
function getByPath(root, path) {
|
|
1405
|
+
const parts = path.split(".").filter(Boolean);
|
|
1406
|
+
let cur = root;
|
|
1407
|
+
for (const p of parts) {
|
|
1408
|
+
if (cur === null || cur === void 0) return void 0;
|
|
1409
|
+
if (typeof cur !== "object") return void 0;
|
|
1410
|
+
cur = cur[p];
|
|
1411
|
+
}
|
|
1412
|
+
return cur;
|
|
1413
|
+
}
|
|
1414
|
+
function isEmptyValue(v) {
|
|
1415
|
+
if (v === null || v === void 0) return true;
|
|
1416
|
+
if (typeof v === "string") return v.length === 0;
|
|
1417
|
+
if (Array.isArray(v)) return v.length === 0;
|
|
1418
|
+
return false;
|
|
1419
|
+
}
|
|
1420
|
+
function evaluateCondition(condition, context) {
|
|
1421
|
+
const left = getByPath(context, condition.field);
|
|
1422
|
+
const op = condition.operator;
|
|
1423
|
+
const right = condition.value;
|
|
1424
|
+
let ok = false;
|
|
1425
|
+
switch (op) {
|
|
1426
|
+
case "eq":
|
|
1427
|
+
ok = left === right;
|
|
1428
|
+
break;
|
|
1429
|
+
case "neq":
|
|
1430
|
+
ok = left !== right;
|
|
1431
|
+
break;
|
|
1432
|
+
case "gt":
|
|
1433
|
+
ok = typeof left === "number" && typeof right === "number" && left > right;
|
|
1434
|
+
break;
|
|
1435
|
+
case "gte":
|
|
1436
|
+
ok = typeof left === "number" && typeof right === "number" && left >= right;
|
|
1437
|
+
break;
|
|
1438
|
+
case "lt":
|
|
1439
|
+
ok = typeof left === "number" && typeof right === "number" && left < right;
|
|
1440
|
+
break;
|
|
1441
|
+
case "lte":
|
|
1442
|
+
ok = typeof left === "number" && typeof right === "number" && left <= right;
|
|
1443
|
+
break;
|
|
1444
|
+
case "in":
|
|
1445
|
+
ok = Array.isArray(right) && right.some((r) => r === left);
|
|
1446
|
+
break;
|
|
1447
|
+
case "notIn":
|
|
1448
|
+
ok = Array.isArray(right) && !right.some((r) => r === left);
|
|
1449
|
+
break;
|
|
1450
|
+
case "isEmpty":
|
|
1451
|
+
ok = isEmptyValue(left);
|
|
1452
|
+
break;
|
|
1453
|
+
case "isNotEmpty":
|
|
1454
|
+
ok = !isEmptyValue(left);
|
|
1455
|
+
break;
|
|
1456
|
+
default: {
|
|
1457
|
+
const _exhaustive = op;
|
|
1458
|
+
return {
|
|
1459
|
+
ok: false,
|
|
1460
|
+
failed: {
|
|
1461
|
+
field: condition.field,
|
|
1462
|
+
operator: condition.operator,
|
|
1463
|
+
value: condition.value,
|
|
1464
|
+
reason: `Unknown operator: ${_exhaustive}`
|
|
1465
|
+
}
|
|
1466
|
+
};
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
if (!ok) {
|
|
1470
|
+
return {
|
|
1471
|
+
ok: false,
|
|
1472
|
+
failed: {
|
|
1473
|
+
field: condition.field,
|
|
1474
|
+
operator: condition.operator,
|
|
1475
|
+
value: condition.value
|
|
1476
|
+
}
|
|
1477
|
+
};
|
|
1478
|
+
}
|
|
1479
|
+
return { ok: true };
|
|
1480
|
+
}
|
|
1481
|
+
function groupPasses(group, context) {
|
|
1482
|
+
const failed = [];
|
|
1483
|
+
for (const c of group.conditions) {
|
|
1484
|
+
const r = evaluateCondition(c, context);
|
|
1485
|
+
if (!r.ok && r.failed) failed.push(r.failed);
|
|
1486
|
+
}
|
|
1487
|
+
return { ok: failed.length === 0, failed };
|
|
1488
|
+
}
|
|
1489
|
+
function evaluateConditionSet(set, context) {
|
|
1490
|
+
if (!set || set.groups.length === 0) {
|
|
1491
|
+
return { ok: true, failedConditions: [] };
|
|
1492
|
+
}
|
|
1493
|
+
const allFailed = [];
|
|
1494
|
+
for (const g of set.groups) {
|
|
1495
|
+
const { ok, failed } = groupPasses(g, context);
|
|
1496
|
+
if (ok) return { ok: true, failedConditions: [] };
|
|
1497
|
+
allFailed.push(...failed);
|
|
1498
|
+
}
|
|
1499
|
+
return { ok: false, failedConditions: allFailed };
|
|
1500
|
+
}
|
|
1501
|
+
function conditionSummary(c) {
|
|
1502
|
+
return `${c.field} ${c.operator} ${JSON.stringify(c.value)}`;
|
|
1503
|
+
}
|
|
1504
|
+
|
|
1505
|
+
// order-state-machine/engine.ts
|
|
1506
|
+
function pairInInitialList(to, config) {
|
|
1507
|
+
return config.validInitialStates.some(
|
|
1508
|
+
(p) => p.payment === to.payment && p.fulfillment === to.fulfillment
|
|
1509
|
+
);
|
|
1510
|
+
}
|
|
1511
|
+
function triggerTargets(rule) {
|
|
1512
|
+
const t = rule.trigger.to;
|
|
1513
|
+
return Array.isArray(t) ? [...t] : [t];
|
|
1514
|
+
}
|
|
1515
|
+
function crossAxisRuleApplies(rule, from, to) {
|
|
1516
|
+
if (!rule.enabled) return false;
|
|
1517
|
+
const targets = triggerTargets(rule);
|
|
1518
|
+
if (rule.trigger.axis === "fulfillment") {
|
|
1519
|
+
if (!targets.includes(to.fulfillment)) return false;
|
|
1520
|
+
if (from !== null && from.fulfillment === to.fulfillment) return false;
|
|
1521
|
+
return true;
|
|
1522
|
+
}
|
|
1523
|
+
if (!targets.includes(to.payment)) return false;
|
|
1524
|
+
if (from !== null && from.payment === to.payment) return false;
|
|
1525
|
+
return true;
|
|
1526
|
+
}
|
|
1527
|
+
function crossAxisSatisfied(rule, to) {
|
|
1528
|
+
const req = rule.requires;
|
|
1529
|
+
if (req.axis === "payment") {
|
|
1530
|
+
return req.states.includes(to.payment);
|
|
1531
|
+
}
|
|
1532
|
+
return req.states.includes(to.fulfillment);
|
|
1533
|
+
}
|
|
1534
|
+
function firstBlockingCrossAxisRule(from, to, config) {
|
|
1535
|
+
for (const rule of config.crossAxisRules) {
|
|
1536
|
+
if (!crossAxisRuleApplies(rule, from, to)) continue;
|
|
1537
|
+
if (!crossAxisSatisfied(rule, to)) return rule;
|
|
1538
|
+
}
|
|
1539
|
+
return void 0;
|
|
1540
|
+
}
|
|
1541
|
+
function findConditionSet(config, id) {
|
|
1542
|
+
if (!id) return void 0;
|
|
1543
|
+
return config.transitionConditions.find((s) => s.id === id);
|
|
1544
|
+
}
|
|
1545
|
+
function pathExists(paths, fromId, toId) {
|
|
1546
|
+
return paths.some((p) => p.from === fromId && p.to === toId);
|
|
1547
|
+
}
|
|
1548
|
+
function axisTransitionAllowed(mode, paths, fromId, toId) {
|
|
1549
|
+
if (fromId === toId) return true;
|
|
1550
|
+
if (mode === "permissive") return true;
|
|
1551
|
+
return pathExists(paths, fromId, toId);
|
|
1552
|
+
}
|
|
1553
|
+
function collectPathConditionFailures(config, from, to, context) {
|
|
1554
|
+
const failed = [];
|
|
1555
|
+
if (from === null) return { failed };
|
|
1556
|
+
if (from.payment !== to.payment) {
|
|
1557
|
+
const p = config.paymentPaths.find(
|
|
1558
|
+
(x) => x.from === from.payment && x.to === to.payment
|
|
1559
|
+
);
|
|
1560
|
+
const set = findConditionSet(config, p?.conditionSetId);
|
|
1561
|
+
const ev = evaluateConditionSet(set, context);
|
|
1562
|
+
if (!ev.ok) failed.push(...ev.failedConditions);
|
|
1563
|
+
}
|
|
1564
|
+
if (from.fulfillment !== to.fulfillment) {
|
|
1565
|
+
const p = config.fulfillmentPaths.find(
|
|
1566
|
+
(x) => x.from === from.fulfillment && x.to === to.fulfillment
|
|
1567
|
+
);
|
|
1568
|
+
const set = findConditionSet(config, p?.conditionSetId);
|
|
1569
|
+
const ev = evaluateConditionSet(set, context);
|
|
1570
|
+
if (!ev.ok) failed.push(...ev.failedConditions);
|
|
1571
|
+
}
|
|
1572
|
+
return { failed };
|
|
1573
|
+
}
|
|
1574
|
+
function pathBlocked(config, from, to) {
|
|
1575
|
+
if (from === null) return false;
|
|
1576
|
+
if (from.payment !== to.payment && !axisTransitionAllowed(
|
|
1577
|
+
config.paymentPathMode,
|
|
1578
|
+
config.paymentPaths,
|
|
1579
|
+
from.payment,
|
|
1580
|
+
to.payment
|
|
1581
|
+
)) {
|
|
1582
|
+
return true;
|
|
1583
|
+
}
|
|
1584
|
+
if (from.fulfillment !== to.fulfillment && !axisTransitionAllowed(
|
|
1585
|
+
config.fulfillmentPathMode,
|
|
1586
|
+
config.fulfillmentPaths,
|
|
1587
|
+
from.fulfillment,
|
|
1588
|
+
to.fulfillment
|
|
1589
|
+
)) {
|
|
1590
|
+
return true;
|
|
1591
|
+
}
|
|
1592
|
+
return false;
|
|
1593
|
+
}
|
|
1594
|
+
function canTransition(request) {
|
|
1595
|
+
const { from, to, config, context } = request;
|
|
1596
|
+
const fin = getFinancialInvariantViolations(from, to);
|
|
1597
|
+
if (fin.length > 0) {
|
|
1598
|
+
return {
|
|
1599
|
+
allowed: false,
|
|
1600
|
+
blockedBy: "financial_invariant",
|
|
1601
|
+
guard: fin[0],
|
|
1602
|
+
reason: `Blocked by financial invariant: ${fin[0]}`
|
|
1603
|
+
};
|
|
1604
|
+
}
|
|
1605
|
+
const cross = firstBlockingCrossAxisRule(from, to, config);
|
|
1606
|
+
if (cross) {
|
|
1607
|
+
return {
|
|
1608
|
+
allowed: false,
|
|
1609
|
+
blockedBy: "cross_axis_rule",
|
|
1610
|
+
guard: cross.id,
|
|
1611
|
+
reason: `Blocked by cross-axis rule: ${cross.label}`
|
|
1612
|
+
};
|
|
1613
|
+
}
|
|
1614
|
+
if (from === null) {
|
|
1615
|
+
if (!pairInInitialList(to, config)) {
|
|
1616
|
+
return {
|
|
1617
|
+
allowed: false,
|
|
1618
|
+
blockedBy: "path",
|
|
1619
|
+
reason: "Target state is not a valid initial state for new orders"
|
|
1620
|
+
};
|
|
1621
|
+
}
|
|
1622
|
+
} else if (pathBlocked(config, from, to)) {
|
|
1623
|
+
return {
|
|
1624
|
+
allowed: false,
|
|
1625
|
+
blockedBy: "path",
|
|
1626
|
+
reason: "Transition is not allowed by configured path rules"
|
|
1627
|
+
};
|
|
1628
|
+
}
|
|
1629
|
+
if (!request.skipConditionEvaluation) {
|
|
1630
|
+
const cond = collectPathConditionFailures(config, from, to, context);
|
|
1631
|
+
if (cond.failed.length > 0) {
|
|
1632
|
+
return {
|
|
1633
|
+
allowed: false,
|
|
1634
|
+
blockedBy: "condition",
|
|
1635
|
+
reason: "Transition conditions not satisfied",
|
|
1636
|
+
failedConditions: cond.failed
|
|
1637
|
+
};
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
return { allowed: true };
|
|
1641
|
+
}
|
|
1642
|
+
function labelForPayment(id, config) {
|
|
1643
|
+
return config.paymentStates.find((s) => s.id === id)?.label ?? id;
|
|
1644
|
+
}
|
|
1645
|
+
function labelForFulfillment(id, config) {
|
|
1646
|
+
return config.fulfillmentStates.find((s) => s.id === id)?.label ?? id;
|
|
1647
|
+
}
|
|
1648
|
+
function transitionDisplayLabel(to, config) {
|
|
1649
|
+
const pay = labelForPayment(to.payment, config);
|
|
1650
|
+
const ful = labelForFulfillment(to.fulfillment, config);
|
|
1651
|
+
const derived = deriveDisplayState(to.payment, to.fulfillment, config).label;
|
|
1652
|
+
if (derived && derived !== `${to.payment} / ${to.fulfillment}`) {
|
|
1653
|
+
return derived;
|
|
1654
|
+
}
|
|
1655
|
+
return `${pay} \xB7 ${ful}`;
|
|
1656
|
+
}
|
|
1657
|
+
function conditionMetLines(config, from, to, context) {
|
|
1658
|
+
const lines = [];
|
|
1659
|
+
const appendForPath = (p) => {
|
|
1660
|
+
const set = findConditionSet(config, p?.conditionSetId);
|
|
1661
|
+
if (!set) return;
|
|
1662
|
+
for (const g of set.groups) {
|
|
1663
|
+
for (const c of g.conditions) {
|
|
1664
|
+
const r = evaluateCondition(c, context);
|
|
1665
|
+
lines.push({
|
|
1666
|
+
met: r.ok,
|
|
1667
|
+
description: conditionSummary(c)
|
|
1668
|
+
});
|
|
1669
|
+
}
|
|
1670
|
+
}
|
|
1671
|
+
};
|
|
1672
|
+
if (from.payment !== to.payment) {
|
|
1673
|
+
const p = config.paymentPaths.find(
|
|
1674
|
+
(x) => x.from === from.payment && x.to === to.payment
|
|
1675
|
+
);
|
|
1676
|
+
appendForPath(p);
|
|
1677
|
+
}
|
|
1678
|
+
if (from.fulfillment !== to.fulfillment) {
|
|
1679
|
+
const p = config.fulfillmentPaths.find(
|
|
1680
|
+
(x) => x.from === from.fulfillment && x.to === to.fulfillment
|
|
1681
|
+
);
|
|
1682
|
+
appendForPath(p);
|
|
1683
|
+
}
|
|
1684
|
+
return lines;
|
|
1685
|
+
}
|
|
1686
|
+
function getAvailableTransitions(current, config, context) {
|
|
1687
|
+
const candidates = [];
|
|
1688
|
+
for (const s of config.paymentStates) {
|
|
1689
|
+
if (s.id === current.payment) continue;
|
|
1690
|
+
candidates.push({ payment: s.id, fulfillment: current.fulfillment });
|
|
1691
|
+
}
|
|
1692
|
+
for (const s of config.fulfillmentStates) {
|
|
1693
|
+
if (s.id === current.fulfillment) continue;
|
|
1694
|
+
candidates.push({ payment: current.payment, fulfillment: s.id });
|
|
1695
|
+
}
|
|
1696
|
+
const out = [];
|
|
1697
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1698
|
+
for (const to of candidates) {
|
|
1699
|
+
const key = `${to.payment}:${to.fulfillment}`;
|
|
1700
|
+
if (seen.has(key)) continue;
|
|
1701
|
+
seen.add(key);
|
|
1702
|
+
const result = canTransition({
|
|
1703
|
+
from: current,
|
|
1704
|
+
to,
|
|
1705
|
+
config,
|
|
1706
|
+
context
|
|
1707
|
+
});
|
|
1708
|
+
if (!result.allowed) continue;
|
|
1709
|
+
out.push({
|
|
1710
|
+
to,
|
|
1711
|
+
displayLabel: transitionDisplayLabel(to, config),
|
|
1712
|
+
conditions: conditionMetLines(config, current, to, context)
|
|
1713
|
+
});
|
|
1714
|
+
}
|
|
1715
|
+
return out;
|
|
1716
|
+
}
|
|
1717
|
+
|
|
1718
|
+
// order-state-machine/validate-config.ts
|
|
1719
|
+
function paymentStateIds(config) {
|
|
1720
|
+
return new Set(config.paymentStates.map((s) => s.id));
|
|
1721
|
+
}
|
|
1722
|
+
function fulfillmentStateIds(config) {
|
|
1723
|
+
return new Set(config.fulfillmentStates.map((s) => s.id));
|
|
1724
|
+
}
|
|
1725
|
+
var VALID_OPERATORS = new Set(CONDITION_OPERATORS);
|
|
1726
|
+
function validateConditionShape(c, path, errors) {
|
|
1727
|
+
if (!VALID_OPERATORS.has(c.operator)) {
|
|
1728
|
+
errors.push({
|
|
1729
|
+
code: "invalid_condition_operator",
|
|
1730
|
+
message: `Unknown operator "${c.operator}"`,
|
|
1731
|
+
path
|
|
1732
|
+
});
|
|
1733
|
+
return;
|
|
1734
|
+
}
|
|
1735
|
+
const needsNumberCompare = ["gt", "gte", "lt", "lte"].includes(c.operator);
|
|
1736
|
+
if (needsNumberCompare && typeof c.value !== "number") {
|
|
1737
|
+
errors.push({
|
|
1738
|
+
code: "invalid_condition_value_type",
|
|
1739
|
+
message: `Operator "${c.operator}" requires a numeric value`,
|
|
1740
|
+
path: `${path}.value`
|
|
1741
|
+
});
|
|
1742
|
+
}
|
|
1743
|
+
if ((c.operator === "in" || c.operator === "notIn") && !Array.isArray(c.value)) {
|
|
1744
|
+
errors.push({
|
|
1745
|
+
code: "invalid_condition_value_type",
|
|
1746
|
+
message: `Operator "${c.operator}" requires an array value`,
|
|
1747
|
+
path: `${path}.value`
|
|
1748
|
+
});
|
|
1749
|
+
}
|
|
1750
|
+
}
|
|
1751
|
+
function validationContext() {
|
|
1752
|
+
return buildOrderContext({
|
|
1753
|
+
total: 100,
|
|
1754
|
+
balance: 0,
|
|
1755
|
+
paymentMethods: [{ amount: 100 }],
|
|
1756
|
+
lineItems: [{ quantity: 1, fulfilledQuantity: 1, returnedQuantity: 0 }]
|
|
1757
|
+
});
|
|
1758
|
+
}
|
|
1759
|
+
function pairKey(p) {
|
|
1760
|
+
return `${p.payment}\0${p.fulfillment}`;
|
|
1761
|
+
}
|
|
1762
|
+
function validateConfig(config) {
|
|
1763
|
+
const errors = [];
|
|
1764
|
+
const warnings = [];
|
|
1765
|
+
if (!Number.isFinite(config.version) || config.version < 1) {
|
|
1766
|
+
errors.push({
|
|
1767
|
+
code: "invalid_version",
|
|
1768
|
+
message: "version must be a finite number >= 1",
|
|
1769
|
+
path: "version"
|
|
1770
|
+
});
|
|
1771
|
+
}
|
|
1772
|
+
if (!config.validInitialStates?.length) {
|
|
1773
|
+
errors.push({
|
|
1774
|
+
code: "missing_initial_states",
|
|
1775
|
+
message: "validInitialStates must contain at least one pair",
|
|
1776
|
+
path: "validInitialStates"
|
|
1777
|
+
});
|
|
1778
|
+
}
|
|
1779
|
+
const payIds = paymentStateIds(config);
|
|
1780
|
+
const fulIds = fulfillmentStateIds(config);
|
|
1781
|
+
config.validInitialStates?.forEach((pair, i) => {
|
|
1782
|
+
if (!payIds.has(pair.payment)) {
|
|
1783
|
+
errors.push({
|
|
1784
|
+
code: "initial_unknown_payment",
|
|
1785
|
+
message: `validInitialStates[${i}].payment "${pair.payment}" is not defined`,
|
|
1786
|
+
path: `validInitialStates[${i}].payment`
|
|
1787
|
+
});
|
|
1788
|
+
}
|
|
1789
|
+
if (!fulIds.has(pair.fulfillment)) {
|
|
1790
|
+
errors.push({
|
|
1791
|
+
code: "initial_unknown_fulfillment",
|
|
1792
|
+
message: `validInitialStates[${i}].fulfillment "${pair.fulfillment}" is not defined`,
|
|
1793
|
+
path: `validInitialStates[${i}].fulfillment`
|
|
1794
|
+
});
|
|
1795
|
+
}
|
|
1796
|
+
});
|
|
1797
|
+
const conditionSetIds = new Set(config.transitionConditions.map((s) => s.id));
|
|
1798
|
+
config.transitionConditions.forEach((set, si) => {
|
|
1799
|
+
set.groups.forEach((g, gi) => {
|
|
1800
|
+
g.conditions.forEach((c, ci) => {
|
|
1801
|
+
validateConditionShape(
|
|
1802
|
+
c,
|
|
1803
|
+
`transitionConditions[${si}].groups[${gi}].conditions[${ci}]`,
|
|
1804
|
+
errors
|
|
1805
|
+
);
|
|
1806
|
+
});
|
|
1807
|
+
});
|
|
1808
|
+
});
|
|
1809
|
+
const pathConditionRef = (paths, axis) => {
|
|
1810
|
+
paths.forEach((p, i) => {
|
|
1811
|
+
if (p.conditionSetId && !conditionSetIds.has(p.conditionSetId)) {
|
|
1812
|
+
errors.push({
|
|
1813
|
+
code: "unknown_condition_set",
|
|
1814
|
+
message: `${axis}Paths[${i}] references unknown conditionSetId "${p.conditionSetId}"`,
|
|
1815
|
+
path: `${axis}Paths[${i}].conditionSetId`
|
|
1816
|
+
});
|
|
1817
|
+
}
|
|
1818
|
+
});
|
|
1819
|
+
};
|
|
1820
|
+
pathConditionRef(config.paymentPaths, "payment");
|
|
1821
|
+
pathConditionRef(config.fulfillmentPaths, "fulfillment");
|
|
1822
|
+
config.paymentPaths.forEach((path, i) => {
|
|
1823
|
+
if (!payIds.has(path.from) || !payIds.has(path.to)) {
|
|
1824
|
+
errors.push({
|
|
1825
|
+
code: "payment_path_unknown_state",
|
|
1826
|
+
message: `paymentPaths[${i}] references unknown payment state`,
|
|
1827
|
+
path: `paymentPaths[${i}]`
|
|
1828
|
+
});
|
|
1829
|
+
return;
|
|
1830
|
+
}
|
|
1831
|
+
for (const f of config.fulfillmentStates) {
|
|
1832
|
+
const from = { payment: path.from, fulfillment: f.id };
|
|
1833
|
+
const to = { payment: path.to, fulfillment: f.id };
|
|
1834
|
+
if (getFinancialInvariantViolations(null, from).length > 0) continue;
|
|
1835
|
+
const v = getFinancialInvariantViolations(from, to);
|
|
1836
|
+
if (v.length > 0) {
|
|
1837
|
+
errors.push({
|
|
1838
|
+
code: "payment_path_violates_financial_invariant",
|
|
1839
|
+
message: `paymentPaths[${i}] (${path.from}\u2192${path.to}) with fulfillment "${f.id}" violates invariant(s): ${v.join(", ")}`,
|
|
1840
|
+
path: `paymentPaths[${i}]`
|
|
1841
|
+
});
|
|
1842
|
+
}
|
|
1843
|
+
}
|
|
1844
|
+
});
|
|
1845
|
+
config.fulfillmentPaths.forEach((path, i) => {
|
|
1846
|
+
if (!fulIds.has(path.from) || !fulIds.has(path.to)) {
|
|
1847
|
+
errors.push({
|
|
1848
|
+
code: "fulfillment_path_unknown_state",
|
|
1849
|
+
message: `fulfillmentPaths[${i}] references unknown fulfillment state`,
|
|
1850
|
+
path: `fulfillmentPaths[${i}]`
|
|
1851
|
+
});
|
|
1852
|
+
return;
|
|
1853
|
+
}
|
|
1854
|
+
for (const p of config.paymentStates) {
|
|
1855
|
+
const from = { payment: p.id, fulfillment: path.from };
|
|
1856
|
+
const to = { payment: p.id, fulfillment: path.to };
|
|
1857
|
+
if (getFinancialInvariantViolations(null, from).length > 0) continue;
|
|
1858
|
+
const v = getFinancialInvariantViolations(from, to);
|
|
1859
|
+
if (v.length > 0) {
|
|
1860
|
+
errors.push({
|
|
1861
|
+
code: "fulfillment_path_violates_financial_invariant",
|
|
1862
|
+
message: `fulfillmentPaths[${i}] (${path.from}\u2192${path.to}) with payment "${p.id}" violates invariant(s): ${v.join(", ")}`,
|
|
1863
|
+
path: `fulfillmentPaths[${i}]`
|
|
1864
|
+
});
|
|
1865
|
+
}
|
|
1866
|
+
}
|
|
1867
|
+
});
|
|
1868
|
+
config.crossAxisRules.forEach((rule, i) => {
|
|
1869
|
+
const req = rule.requires;
|
|
1870
|
+
if (req.axis === "payment") {
|
|
1871
|
+
for (const id of req.states) {
|
|
1872
|
+
if (!payIds.has(id)) {
|
|
1873
|
+
errors.push({
|
|
1874
|
+
code: "cross_axis_unknown_payment",
|
|
1875
|
+
message: `crossAxisRules[${i}] requires unknown payment state "${id}"`,
|
|
1876
|
+
path: `crossAxisRules[${i}].requires.states`
|
|
1877
|
+
});
|
|
1878
|
+
}
|
|
1879
|
+
}
|
|
1880
|
+
} else {
|
|
1881
|
+
for (const id of req.states) {
|
|
1882
|
+
if (!fulIds.has(id)) {
|
|
1883
|
+
errors.push({
|
|
1884
|
+
code: "cross_axis_unknown_fulfillment",
|
|
1885
|
+
message: `crossAxisRules[${i}] requires unknown fulfillment state "${id}"`,
|
|
1886
|
+
path: `crossAxisRules[${i}].requires.states`
|
|
1887
|
+
});
|
|
1888
|
+
}
|
|
1889
|
+
}
|
|
1890
|
+
}
|
|
1891
|
+
const trig = rule.trigger;
|
|
1892
|
+
const targets = Array.isArray(trig.to) ? trig.to : [trig.to];
|
|
1893
|
+
if (trig.axis === "payment") {
|
|
1894
|
+
for (const id of targets) {
|
|
1895
|
+
if (!payIds.has(id)) {
|
|
1896
|
+
errors.push({
|
|
1897
|
+
code: "cross_axis_trigger_unknown_payment",
|
|
1898
|
+
message: `crossAxisRules[${i}] triggers on unknown payment state "${id}"`,
|
|
1899
|
+
path: `crossAxisRules[${i}].trigger.to`
|
|
1900
|
+
});
|
|
1901
|
+
}
|
|
1902
|
+
}
|
|
1903
|
+
} else {
|
|
1904
|
+
for (const id of targets) {
|
|
1905
|
+
if (!fulIds.has(id)) {
|
|
1906
|
+
errors.push({
|
|
1907
|
+
code: "cross_axis_trigger_unknown_fulfillment",
|
|
1908
|
+
message: `crossAxisRules[${i}] triggers on unknown fulfillment state "${id}"`,
|
|
1909
|
+
path: `crossAxisRules[${i}].trigger.to`
|
|
1910
|
+
});
|
|
1911
|
+
}
|
|
1912
|
+
}
|
|
1913
|
+
}
|
|
1914
|
+
});
|
|
1915
|
+
strictAxisReachability(config, "payment", payIds, warnings);
|
|
1916
|
+
strictAxisReachability(config, "fulfillment", fulIds, warnings);
|
|
1917
|
+
combinedReachability(config, warnings);
|
|
1918
|
+
if (!config.displayStateMap.length) {
|
|
1919
|
+
warnings.push({
|
|
1920
|
+
code: "empty_display_map",
|
|
1921
|
+
message: "displayStateMap is empty; UI will fall back to raw state pair labels",
|
|
1922
|
+
path: "displayStateMap"
|
|
1923
|
+
});
|
|
1924
|
+
} else {
|
|
1925
|
+
const missingDisplay = [];
|
|
1926
|
+
for (const p of PAYMENT_STATES) {
|
|
1927
|
+
for (const f of FULFILLMENT_STATES) {
|
|
1928
|
+
if (!payIds.has(p) || !fulIds.has(f)) continue;
|
|
1929
|
+
const matched = config.displayStateMap.some(
|
|
1930
|
+
(rule) => displayRuleMatchesPair(rule, p, f)
|
|
1931
|
+
);
|
|
1932
|
+
if (!matched) missingDisplay.push(`${p}/${f}`);
|
|
1933
|
+
}
|
|
1934
|
+
}
|
|
1935
|
+
if (missingDisplay.length > 0) {
|
|
1936
|
+
const sample = missingDisplay.slice(0, 8).join(", ");
|
|
1937
|
+
const more = missingDisplay.length > 8 ? ` (+${missingDisplay.length - 8} more)` : "";
|
|
1938
|
+
warnings.push({
|
|
1939
|
+
code: "display_map_missing_combos",
|
|
1940
|
+
message: `No displayStateMap rule matches ${missingDisplay.length} base pair(s): ${sample}${more}`,
|
|
1941
|
+
path: "displayStateMap"
|
|
1942
|
+
});
|
|
1943
|
+
}
|
|
1944
|
+
}
|
|
1945
|
+
refundReturnPathWarnings(config, payIds, fulIds, warnings);
|
|
1946
|
+
if (config.paymentPathMode === "strict" && config.paymentPaths.length === 0) {
|
|
1947
|
+
errors.push({
|
|
1948
|
+
code: "strict_payment_paths_empty",
|
|
1949
|
+
message: "paymentPathMode is strict but paymentPaths is empty",
|
|
1950
|
+
path: "paymentPaths"
|
|
1951
|
+
});
|
|
1952
|
+
}
|
|
1953
|
+
if (config.fulfillmentPathMode === "strict" && config.fulfillmentPaths.length === 0) {
|
|
1954
|
+
errors.push({
|
|
1955
|
+
code: "strict_fulfillment_paths_empty",
|
|
1956
|
+
message: "fulfillmentPathMode is strict but fulfillmentPaths is empty",
|
|
1957
|
+
path: "fulfillmentPaths"
|
|
1958
|
+
});
|
|
1959
|
+
}
|
|
1960
|
+
return {
|
|
1961
|
+
valid: errors.length === 0,
|
|
1962
|
+
errors,
|
|
1963
|
+
warnings
|
|
1964
|
+
};
|
|
1965
|
+
}
|
|
1966
|
+
function strictAxisReachability(config, axis, ids, warnings) {
|
|
1967
|
+
const mode = axis === "payment" ? config.paymentPathMode : config.fulfillmentPathMode;
|
|
1968
|
+
const paths = axis === "payment" ? config.paymentPaths : config.fulfillmentPaths;
|
|
1969
|
+
if (mode !== "strict" || paths.length === 0) return;
|
|
1970
|
+
const reachable = /* @__PURE__ */ new Set();
|
|
1971
|
+
const initials = new Set(
|
|
1972
|
+
config.validInitialStates.map((p) => axis === "payment" ? p.payment : p.fulfillment)
|
|
1973
|
+
);
|
|
1974
|
+
for (const id of initials) {
|
|
1975
|
+
if (ids.has(id)) bfsAxis(id, paths, reachable);
|
|
1976
|
+
}
|
|
1977
|
+
const stateRows = axis === "payment" ? config.paymentStates : config.fulfillmentStates;
|
|
1978
|
+
for (const id of stateRows) {
|
|
1979
|
+
if (!reachable.has(id.id)) {
|
|
1980
|
+
warnings.push({
|
|
1981
|
+
code: `${axis}_state_unreachable_strict`,
|
|
1982
|
+
message: `State "${id.id}" may be unreachable from valid initial ${axis} states under strict paths`,
|
|
1983
|
+
path: axis === "payment" ? "paymentPaths" : "fulfillmentPaths"
|
|
1984
|
+
});
|
|
1985
|
+
}
|
|
1986
|
+
if (!id.isTerminal) {
|
|
1987
|
+
const hasOut = paths.some((p) => p.from === id.id && p.to !== id.id);
|
|
1988
|
+
if (!hasOut) {
|
|
1989
|
+
warnings.push({
|
|
1990
|
+
code: `${axis}_nonterminal_no_outbound`,
|
|
1991
|
+
message: `Non-terminal ${axis} state "${id.id}" has no strict outbound path`,
|
|
1992
|
+
path: axis === "payment" ? "paymentPaths" : "fulfillmentPaths"
|
|
1993
|
+
});
|
|
1994
|
+
}
|
|
1995
|
+
}
|
|
1996
|
+
}
|
|
1997
|
+
}
|
|
1998
|
+
function bfsAxis(start, paths, reachable) {
|
|
1999
|
+
const q = [start];
|
|
2000
|
+
reachable.add(start);
|
|
2001
|
+
while (q.length) {
|
|
2002
|
+
const cur = q.pop();
|
|
2003
|
+
for (const p of paths) {
|
|
2004
|
+
if (p.from !== cur) continue;
|
|
2005
|
+
if (!reachable.has(p.to)) {
|
|
2006
|
+
reachable.add(p.to);
|
|
2007
|
+
q.push(p.to);
|
|
2008
|
+
}
|
|
2009
|
+
}
|
|
2010
|
+
}
|
|
2011
|
+
}
|
|
2012
|
+
function combinedReachability(config, warnings) {
|
|
2013
|
+
const ctx = validationContext();
|
|
2014
|
+
const payIds = config.paymentStates.map((s) => s.id);
|
|
2015
|
+
const fulIds = config.fulfillmentStates.map((s) => s.id);
|
|
2016
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2017
|
+
const queue = [...config.validInitialStates];
|
|
2018
|
+
for (const p of queue) {
|
|
2019
|
+
seen.add(pairKey(p));
|
|
2020
|
+
}
|
|
2021
|
+
while (queue.length) {
|
|
2022
|
+
const cur = queue.pop();
|
|
2023
|
+
for (const np of payIds) {
|
|
2024
|
+
if (np === cur.payment) continue;
|
|
2025
|
+
const to = { payment: np, fulfillment: cur.fulfillment };
|
|
2026
|
+
const r = canTransition({
|
|
2027
|
+
from: cur,
|
|
2028
|
+
to,
|
|
2029
|
+
config,
|
|
2030
|
+
context: ctx,
|
|
2031
|
+
skipConditionEvaluation: true
|
|
2032
|
+
});
|
|
2033
|
+
const k = pairKey(to);
|
|
2034
|
+
if (r.allowed && !seen.has(k)) {
|
|
2035
|
+
seen.add(k);
|
|
2036
|
+
queue.push(to);
|
|
2037
|
+
}
|
|
2038
|
+
}
|
|
2039
|
+
for (const nf of fulIds) {
|
|
2040
|
+
if (nf === cur.fulfillment) continue;
|
|
2041
|
+
const to = { payment: cur.payment, fulfillment: nf };
|
|
2042
|
+
const r = canTransition({
|
|
2043
|
+
from: cur,
|
|
2044
|
+
to,
|
|
2045
|
+
config,
|
|
2046
|
+
context: ctx,
|
|
2047
|
+
skipConditionEvaluation: true
|
|
2048
|
+
});
|
|
2049
|
+
const k = pairKey(to);
|
|
2050
|
+
if (r.allowed && !seen.has(k)) {
|
|
2051
|
+
seen.add(k);
|
|
2052
|
+
queue.push(to);
|
|
2053
|
+
}
|
|
2054
|
+
}
|
|
2055
|
+
}
|
|
2056
|
+
const total = payIds.length * fulIds.length;
|
|
2057
|
+
if (seen.size < total && (config.paymentPathMode === "strict" || config.fulfillmentPathMode === "strict")) {
|
|
2058
|
+
warnings.push({
|
|
2059
|
+
code: "combined_pairs_not_all_reachable",
|
|
2060
|
+
message: "Some payment\xD7fulfillment pairs appear unreachable under current paths, cross-axis rules, and financial invariants (structural check with generic context)",
|
|
2061
|
+
path: "validInitialStates"
|
|
2062
|
+
});
|
|
2063
|
+
}
|
|
2064
|
+
}
|
|
2065
|
+
function refundReturnPathWarnings(config, payIds, fulIds, warnings) {
|
|
2066
|
+
const hasReturned = config.fulfillmentPaths.some(
|
|
2067
|
+
(p) => p.to === "returned" || p.from === "returned"
|
|
2068
|
+
);
|
|
2069
|
+
const hasRefunded = config.paymentPaths.some(
|
|
2070
|
+
(p) => p.to === "refunded" || p.from === "refunded"
|
|
2071
|
+
);
|
|
2072
|
+
if (fulIds.has("returned") && hasReturned && payIds.has("refunded") && !hasRefunded && config.paymentPathMode === "strict") {
|
|
2073
|
+
warnings.push({
|
|
2074
|
+
code: "refund_path_missing_for_return",
|
|
2075
|
+
message: 'Fulfillment paths mention "returned" but no strict payment path touches "refunded"; verify refund workflow',
|
|
2076
|
+
path: "paymentPaths"
|
|
2077
|
+
});
|
|
2078
|
+
}
|
|
2079
|
+
}
|
|
2080
|
+
|
|
2081
|
+
// order-state-machine/set-order-state.ts
|
|
2082
|
+
function mapToLegacyStatus(pair) {
|
|
2083
|
+
const { payment, fulfillment } = pair;
|
|
2084
|
+
if (payment === "voided") return "park-deleted";
|
|
2085
|
+
if (payment === "refunded") return "refunded";
|
|
2086
|
+
if (payment === "partially_refunded") return "partial-refund";
|
|
2087
|
+
if (payment === "paid") return "completed";
|
|
2088
|
+
if (fulfillment === "draft") return "in-cart";
|
|
2089
|
+
if (fulfillment === "on_hold") return "parked";
|
|
2090
|
+
if (fulfillment === "pending") return "parked";
|
|
2091
|
+
if (fulfillment === "cancelled") return "park-deleted";
|
|
2092
|
+
return "parked";
|
|
2093
|
+
}
|
|
2094
|
+
function setOrderState(order, paymentState, fulfillmentState, config, options) {
|
|
2095
|
+
order.paymentState = paymentState;
|
|
2096
|
+
order.fulfillmentState = fulfillmentState;
|
|
2097
|
+
const display = deriveDisplayState(paymentState, fulfillmentState, config);
|
|
2098
|
+
order.displayState = display.label;
|
|
2099
|
+
if (options?.includeLegacyStatus !== false) {
|
|
2100
|
+
order.status = mapToLegacyStatus({ payment: paymentState, fulfillment: fulfillmentState });
|
|
2101
|
+
}
|
|
2102
|
+
}
|
|
2103
|
+
|
|
2104
|
+
// order-state-machine/legacy-infer.ts
|
|
2105
|
+
function normalizeStatus(raw) {
|
|
2106
|
+
return (raw ?? "").trim().toLowerCase();
|
|
2107
|
+
}
|
|
2108
|
+
function hasRefundActivity(order) {
|
|
2109
|
+
const refunds = order.refunds ?? order.refund ?? [];
|
|
2110
|
+
return refunds.some((r) => {
|
|
2111
|
+
const q = r.quantity;
|
|
2112
|
+
return typeof q === "number" && q > 0;
|
|
2113
|
+
});
|
|
2114
|
+
}
|
|
2115
|
+
function inferStatesFromLegacyStatus(order) {
|
|
2116
|
+
const status = normalizeStatus(order.status);
|
|
2117
|
+
if (status === "completed") {
|
|
2118
|
+
return { payment: "paid", fulfillment: "fulfilled" };
|
|
2119
|
+
}
|
|
2120
|
+
if (status === "in-cart") {
|
|
2121
|
+
return { payment: "unpaid", fulfillment: "draft" };
|
|
2122
|
+
}
|
|
2123
|
+
if (status === "park-deleted") {
|
|
2124
|
+
return { payment: "voided", fulfillment: "cancelled" };
|
|
2125
|
+
}
|
|
2126
|
+
if (status === "refunded") {
|
|
2127
|
+
return { payment: "refunded", fulfillment: "returned" };
|
|
2128
|
+
}
|
|
2129
|
+
if (status === "partial-refund" || status === "partial_refund") {
|
|
2130
|
+
return { payment: "partially_refunded", fulfillment: "partially_returned" };
|
|
2131
|
+
}
|
|
2132
|
+
if (status === "parked") {
|
|
2133
|
+
const ctx = order.paymentMethods ?? [];
|
|
2134
|
+
const paid = ctx.reduce((s, m) => {
|
|
2135
|
+
const a = m.amount;
|
|
2136
|
+
return s + (typeof a === "number" && Number.isFinite(a) ? a : 0);
|
|
2137
|
+
}, 0);
|
|
2138
|
+
const partial = paid > 0 || typeof order.balance === "number" && typeof order.total === "number" && order.total > 0 && order.balance > 0 && order.balance < order.total;
|
|
2139
|
+
return {
|
|
2140
|
+
payment: partial ? "partially_paid" : "unpaid",
|
|
2141
|
+
fulfillment: "on_hold"
|
|
2142
|
+
};
|
|
2143
|
+
}
|
|
2144
|
+
if (status === "" && hasRefundActivity(order)) {
|
|
2145
|
+
return { payment: "partially_refunded", fulfillment: "partially_returned" };
|
|
2146
|
+
}
|
|
2147
|
+
return { payment: "unpaid", fulfillment: "pending" };
|
|
2148
|
+
}
|
|
2149
|
+
|
|
2150
|
+
// order-state-machine/resolve-template.ts
|
|
2151
|
+
function resolveTemplate(templateJson, params, values = {}) {
|
|
2152
|
+
const resolvedValues = {};
|
|
2153
|
+
for (const param of params) {
|
|
2154
|
+
const raw = values[param.key] ?? param.default;
|
|
2155
|
+
if (raw === void 0 || raw === null) {
|
|
2156
|
+
throw new Error(`Missing required parameter: "${param.key}" (${param.label})`);
|
|
2157
|
+
}
|
|
2158
|
+
validateParamValue(param, raw);
|
|
2159
|
+
resolvedValues[param.key] = raw;
|
|
2160
|
+
}
|
|
2161
|
+
let resolved = templateJson;
|
|
2162
|
+
for (const [key, value] of Object.entries(resolvedValues)) {
|
|
2163
|
+
const placeholder = `{{${key}}}`;
|
|
2164
|
+
const replacement = typeof value === "string" ? escapeJsonString(value) : String(value);
|
|
2165
|
+
resolved = replaceAll(resolved, placeholder, replacement);
|
|
2166
|
+
}
|
|
2167
|
+
let fragment;
|
|
2168
|
+
try {
|
|
2169
|
+
fragment = JSON.parse(resolved);
|
|
2170
|
+
} catch (err) {
|
|
2171
|
+
throw new Error(
|
|
2172
|
+
`Fragment template produced invalid JSON after substitution: ${err.message}`
|
|
2173
|
+
);
|
|
2174
|
+
}
|
|
2175
|
+
return { fragment, resolvedValues };
|
|
2176
|
+
}
|
|
2177
|
+
function validateParamValue(param, value) {
|
|
2178
|
+
const { key, label, type } = param;
|
|
2179
|
+
if (type === "string" && typeof value !== "string") {
|
|
2180
|
+
throw new Error(`Parameter "${key}" (${label}) must be a string, got ${typeof value}`);
|
|
2181
|
+
}
|
|
2182
|
+
if (type === "number") {
|
|
2183
|
+
if (typeof value !== "number" || Number.isNaN(value)) {
|
|
2184
|
+
throw new Error(`Parameter "${key}" (${label}) must be a number`);
|
|
2185
|
+
}
|
|
2186
|
+
if (param.min !== void 0 && value < param.min) {
|
|
2187
|
+
throw new Error(`Parameter "${key}" (${label}) must be >= ${param.min}`);
|
|
2188
|
+
}
|
|
2189
|
+
if (param.max !== void 0 && value > param.max) {
|
|
2190
|
+
throw new Error(`Parameter "${key}" (${label}) must be <= ${param.max}`);
|
|
2191
|
+
}
|
|
2192
|
+
}
|
|
2193
|
+
if (type === "boolean" && typeof value !== "boolean") {
|
|
2194
|
+
throw new Error(`Parameter "${key}" (${label}) must be a boolean`);
|
|
2195
|
+
}
|
|
2196
|
+
if (param.options && param.options.length > 0 && !param.options.includes(String(value))) {
|
|
2197
|
+
throw new Error(
|
|
2198
|
+
`Parameter "${key}" (${label}) must be one of: ${param.options.join(", ")}`
|
|
2199
|
+
);
|
|
2200
|
+
}
|
|
2201
|
+
}
|
|
2202
|
+
function escapeJsonString(value) {
|
|
2203
|
+
return value.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t");
|
|
2204
|
+
}
|
|
2205
|
+
function replaceAll(str, search, replacement) {
|
|
2206
|
+
let result = str;
|
|
2207
|
+
let idx = result.indexOf(search);
|
|
2208
|
+
while (idx !== -1) {
|
|
2209
|
+
result = result.slice(0, idx) + replacement + result.slice(idx + search.length);
|
|
2210
|
+
idx = result.indexOf(search, idx + replacement.length);
|
|
2211
|
+
}
|
|
2212
|
+
return result;
|
|
2213
|
+
}
|
|
2214
|
+
|
|
2215
|
+
// order-state-machine/validate-fragment.ts
|
|
2216
|
+
function validateFragmentCompatibility(config, fragment) {
|
|
2217
|
+
const errors = [];
|
|
2218
|
+
validateStateReferences(fragment, errors);
|
|
2219
|
+
validatePathUniqueness(config, fragment, errors);
|
|
2220
|
+
validateConditionSetUniqueness(config, fragment, errors);
|
|
2221
|
+
validateCrossAxisRuleUniqueness(config, fragment, errors);
|
|
2222
|
+
return { valid: errors.length === 0, errors };
|
|
2223
|
+
}
|
|
2224
|
+
function validateStateReferences(fragment, errors) {
|
|
2225
|
+
for (const path of fragment.paymentPaths ?? []) {
|
|
2226
|
+
if (!isPaymentState(path.from)) {
|
|
2227
|
+
errors.push({
|
|
2228
|
+
code: "invalid_payment_state",
|
|
2229
|
+
message: `Unknown payment state "${path.from}" in paymentPaths`,
|
|
2230
|
+
path: `paymentPaths[from=${path.from}]`
|
|
2231
|
+
});
|
|
2232
|
+
}
|
|
2233
|
+
if (!isPaymentState(path.to)) {
|
|
2234
|
+
errors.push({
|
|
2235
|
+
code: "invalid_payment_state",
|
|
2236
|
+
message: `Unknown payment state "${path.to}" in paymentPaths`,
|
|
2237
|
+
path: `paymentPaths[to=${path.to}]`
|
|
2238
|
+
});
|
|
2239
|
+
}
|
|
2240
|
+
}
|
|
2241
|
+
for (const path of fragment.fulfillmentPaths ?? []) {
|
|
2242
|
+
if (!isFulfillmentState(path.from)) {
|
|
2243
|
+
errors.push({
|
|
2244
|
+
code: "invalid_fulfillment_state",
|
|
2245
|
+
message: `Unknown fulfillment state "${path.from}" in fulfillmentPaths`,
|
|
2246
|
+
path: `fulfillmentPaths[from=${path.from}]`
|
|
2247
|
+
});
|
|
2248
|
+
}
|
|
2249
|
+
if (!isFulfillmentState(path.to)) {
|
|
2250
|
+
errors.push({
|
|
2251
|
+
code: "invalid_fulfillment_state",
|
|
2252
|
+
message: `Unknown fulfillment state "${path.to}" in fulfillmentPaths`,
|
|
2253
|
+
path: `fulfillmentPaths[to=${path.to}]`
|
|
2254
|
+
});
|
|
2255
|
+
}
|
|
2256
|
+
}
|
|
2257
|
+
for (const rule of fragment.crossAxisRules ?? []) {
|
|
2258
|
+
const triggerStates = Array.isArray(rule.trigger.to) ? rule.trigger.to : [rule.trigger.to];
|
|
2259
|
+
const check = rule.trigger.axis === "payment" ? isPaymentState : isFulfillmentState;
|
|
2260
|
+
for (const s of triggerStates) {
|
|
2261
|
+
if (!check(s)) {
|
|
2262
|
+
errors.push({
|
|
2263
|
+
code: `invalid_${rule.trigger.axis}_state`,
|
|
2264
|
+
message: `Unknown ${rule.trigger.axis} state "${s}" in crossAxisRule "${rule.id}" trigger`,
|
|
2265
|
+
path: `crossAxisRules[${rule.id}].trigger.to`
|
|
2266
|
+
});
|
|
2267
|
+
}
|
|
2268
|
+
}
|
|
2269
|
+
const reqCheck = rule.requires.axis === "payment" ? isPaymentState : isFulfillmentState;
|
|
2270
|
+
for (const s of rule.requires.states) {
|
|
2271
|
+
if (!reqCheck(s)) {
|
|
2272
|
+
errors.push({
|
|
2273
|
+
code: `invalid_${rule.requires.axis}_state`,
|
|
2274
|
+
message: `Unknown ${rule.requires.axis} state "${s}" in crossAxisRule "${rule.id}" requires`,
|
|
2275
|
+
path: `crossAxisRules[${rule.id}].requires.states`
|
|
2276
|
+
});
|
|
2277
|
+
}
|
|
2278
|
+
}
|
|
2279
|
+
}
|
|
2280
|
+
for (const pair of fragment.validInitialStates ?? []) {
|
|
2281
|
+
if (!isPaymentState(pair.payment)) {
|
|
2282
|
+
errors.push({
|
|
2283
|
+
code: "invalid_payment_state",
|
|
2284
|
+
message: `Unknown payment state "${pair.payment}" in validInitialStates`,
|
|
2285
|
+
path: "validInitialStates"
|
|
2286
|
+
});
|
|
2287
|
+
}
|
|
2288
|
+
if (!isFulfillmentState(pair.fulfillment)) {
|
|
2289
|
+
errors.push({
|
|
2290
|
+
code: "invalid_fulfillment_state",
|
|
2291
|
+
message: `Unknown fulfillment state "${pair.fulfillment}" in validInitialStates`,
|
|
2292
|
+
path: "validInitialStates"
|
|
2293
|
+
});
|
|
2294
|
+
}
|
|
2295
|
+
}
|
|
2296
|
+
for (const rule of fragment.displayStateMap ?? []) {
|
|
2297
|
+
const pStates = rule.paymentState ? Array.isArray(rule.paymentState) ? rule.paymentState : [rule.paymentState] : [];
|
|
2298
|
+
for (const s of pStates) {
|
|
2299
|
+
if (!isPaymentState(s)) {
|
|
2300
|
+
errors.push({
|
|
2301
|
+
code: "invalid_payment_state",
|
|
2302
|
+
message: `Unknown payment state "${s}" in displayStateMap rule "${rule.label}"`,
|
|
2303
|
+
path: "displayStateMap"
|
|
2304
|
+
});
|
|
2305
|
+
}
|
|
2306
|
+
}
|
|
2307
|
+
const fStates = rule.fulfillmentState ? Array.isArray(rule.fulfillmentState) ? rule.fulfillmentState : [rule.fulfillmentState] : [];
|
|
2308
|
+
for (const s of fStates) {
|
|
2309
|
+
if (!isFulfillmentState(s)) {
|
|
2310
|
+
errors.push({
|
|
2311
|
+
code: "invalid_fulfillment_state",
|
|
2312
|
+
message: `Unknown fulfillment state "${s}" in displayStateMap rule "${rule.label}"`,
|
|
2313
|
+
path: "displayStateMap"
|
|
2314
|
+
});
|
|
2315
|
+
}
|
|
2316
|
+
}
|
|
2317
|
+
}
|
|
2318
|
+
}
|
|
2319
|
+
function validatePathUniqueness(config, fragment, errors) {
|
|
2320
|
+
const existingPaymentEdges = new Set(
|
|
2321
|
+
config.paymentPaths.map((p) => `${p.from}->${p.to}`)
|
|
2322
|
+
);
|
|
2323
|
+
for (const path of fragment.paymentPaths ?? []) {
|
|
2324
|
+
const edge = `${path.from}->${path.to}`;
|
|
2325
|
+
if (existingPaymentEdges.has(edge)) {
|
|
2326
|
+
errors.push({
|
|
2327
|
+
code: "duplicate_payment_path",
|
|
2328
|
+
message: `Payment path ${path.from} \u2192 ${path.to} already exists in the config`,
|
|
2329
|
+
path: `paymentPaths[${edge}]`
|
|
2330
|
+
});
|
|
2331
|
+
}
|
|
2332
|
+
}
|
|
2333
|
+
const existingFulfillmentEdges = new Set(
|
|
2334
|
+
config.fulfillmentPaths.map((p) => `${p.from}->${p.to}`)
|
|
2335
|
+
);
|
|
2336
|
+
for (const path of fragment.fulfillmentPaths ?? []) {
|
|
2337
|
+
const edge = `${path.from}->${path.to}`;
|
|
2338
|
+
if (existingFulfillmentEdges.has(edge)) {
|
|
2339
|
+
errors.push({
|
|
2340
|
+
code: "duplicate_fulfillment_path",
|
|
2341
|
+
message: `Fulfillment path ${path.from} \u2192 ${path.to} already exists in the config`,
|
|
2342
|
+
path: `fulfillmentPaths[${edge}]`
|
|
2343
|
+
});
|
|
2344
|
+
}
|
|
2345
|
+
}
|
|
2346
|
+
}
|
|
2347
|
+
function validateConditionSetUniqueness(config, fragment, errors) {
|
|
2348
|
+
const existingIds = new Set(config.transitionConditions.map((c) => c.id));
|
|
2349
|
+
for (const cond of fragment.transitionConditions ?? []) {
|
|
2350
|
+
if (existingIds.has(cond.id)) {
|
|
2351
|
+
errors.push({
|
|
2352
|
+
code: "duplicate_condition_set_id",
|
|
2353
|
+
message: `Condition set ID "${cond.id}" already exists in the config`,
|
|
2354
|
+
path: `transitionConditions[${cond.id}]`
|
|
2355
|
+
});
|
|
2356
|
+
}
|
|
2357
|
+
}
|
|
2358
|
+
}
|
|
2359
|
+
function validateCrossAxisRuleUniqueness(config, fragment, errors) {
|
|
2360
|
+
const existingIds = new Set(config.crossAxisRules.map((r) => r.id));
|
|
2361
|
+
for (const rule of fragment.crossAxisRules ?? []) {
|
|
2362
|
+
if (existingIds.has(rule.id)) {
|
|
2363
|
+
errors.push({
|
|
2364
|
+
code: "duplicate_cross_axis_rule_id",
|
|
2365
|
+
message: `Cross-axis rule ID "${rule.id}" already exists in the config`,
|
|
2366
|
+
path: `crossAxisRules[${rule.id}]`
|
|
2367
|
+
});
|
|
2368
|
+
}
|
|
2369
|
+
}
|
|
2370
|
+
}
|
|
2371
|
+
|
|
2372
|
+
// order-state-machine/merge-fragment.ts
|
|
2373
|
+
function displayRuleKey(rule) {
|
|
2374
|
+
const p = rule.paymentState;
|
|
2375
|
+
const f = rule.fulfillmentState;
|
|
2376
|
+
const pKey = p === void 0 ? "*" : Array.isArray(p) ? p.slice().sort().join(",") : p;
|
|
2377
|
+
const fKey = f === void 0 ? "*" : Array.isArray(f) ? f.slice().sort().join(",") : f;
|
|
2378
|
+
return `${pKey}|${fKey}`;
|
|
2379
|
+
}
|
|
2380
|
+
function mergeFragment(config, fragment, extensionId) {
|
|
2381
|
+
const merged = JSON.parse(JSON.stringify(config));
|
|
2382
|
+
for (const path of fragment.paymentPaths ?? []) {
|
|
2383
|
+
merged.paymentPaths.push({ ...path, _sourceExtensionId: extensionId });
|
|
2384
|
+
}
|
|
2385
|
+
for (const path of fragment.fulfillmentPaths ?? []) {
|
|
2386
|
+
merged.fulfillmentPaths.push({ ...path, _sourceExtensionId: extensionId });
|
|
2387
|
+
}
|
|
2388
|
+
for (const rule of fragment.crossAxisRules ?? []) {
|
|
2389
|
+
merged.crossAxisRules.push({ ...rule, _sourceExtensionId: extensionId });
|
|
2390
|
+
}
|
|
2391
|
+
for (const cond of fragment.transitionConditions ?? []) {
|
|
2392
|
+
merged.transitionConditions.push({ ...cond, _sourceExtensionId: extensionId });
|
|
2393
|
+
}
|
|
2394
|
+
for (const pair of fragment.validInitialStates ?? []) {
|
|
2395
|
+
merged.validInitialStates.push(pair);
|
|
2396
|
+
}
|
|
2397
|
+
for (const rule of fragment.displayStateMap ?? []) {
|
|
2398
|
+
const tagged = { ...rule, _sourceExtensionId: extensionId };
|
|
2399
|
+
const key = displayRuleKey(tagged);
|
|
2400
|
+
const existingIdx = merged.displayStateMap.findIndex(
|
|
2401
|
+
(r) => displayRuleKey(r) === key
|
|
2402
|
+
);
|
|
2403
|
+
if (existingIdx !== -1) {
|
|
2404
|
+
merged.displayStateMap[existingIdx] = tagged;
|
|
2405
|
+
} else {
|
|
2406
|
+
merged.displayStateMap.push(tagged);
|
|
2407
|
+
}
|
|
2408
|
+
}
|
|
2409
|
+
return merged;
|
|
2410
|
+
}
|
|
2411
|
+
|
|
2412
|
+
// order-state-machine/remove-fragment.ts
|
|
2413
|
+
function removeFragment(config, extensionId) {
|
|
2414
|
+
const cleaned = JSON.parse(JSON.stringify(config));
|
|
2415
|
+
cleaned.paymentPaths = cleaned.paymentPaths.filter(
|
|
2416
|
+
(p) => p._sourceExtensionId !== extensionId
|
|
2417
|
+
);
|
|
2418
|
+
cleaned.fulfillmentPaths = cleaned.fulfillmentPaths.filter(
|
|
2419
|
+
(p) => p._sourceExtensionId !== extensionId
|
|
2420
|
+
);
|
|
2421
|
+
cleaned.crossAxisRules = cleaned.crossAxisRules.filter(
|
|
2422
|
+
(r) => r._sourceExtensionId !== extensionId
|
|
2423
|
+
);
|
|
2424
|
+
cleaned.transitionConditions = cleaned.transitionConditions.filter(
|
|
2425
|
+
(c) => c._sourceExtensionId !== extensionId
|
|
2426
|
+
);
|
|
2427
|
+
cleaned.displayStateMap = cleaned.displayStateMap.filter(
|
|
2428
|
+
(d) => d._sourceExtensionId !== extensionId
|
|
2429
|
+
);
|
|
2430
|
+
return cleaned;
|
|
2431
|
+
}
|
|
2432
|
+
|
|
2433
|
+
// order-state-machine/actions.ts
|
|
2434
|
+
var ORDER_STATE_ACTIONS = {
|
|
2435
|
+
getOrderStateConfig: "getOrderStateConfig",
|
|
2436
|
+
getAvailableTransitions: "getAvailableTransitions",
|
|
2437
|
+
getOrderDisplayState: "getOrderDisplayState",
|
|
2438
|
+
transitionOrderState: "transitionOrderState",
|
|
2439
|
+
getStateConfigFragment: "getStateConfigFragment",
|
|
2440
|
+
saveStateConfigFragment: "saveStateConfigFragment",
|
|
2441
|
+
deleteStateConfigFragment: "deleteStateConfigFragment"
|
|
2442
|
+
};
|
|
2443
|
+
|
|
2444
|
+
// order-state-machine/pubsub.ts
|
|
2445
|
+
var ORDER_STATE_TOPIC = "order-state";
|
|
2446
|
+
var ORDER_STATE_EVENTS = {
|
|
2447
|
+
stateTransitionCompleted: "state-transition-completed",
|
|
2448
|
+
stateTransitionBlocked: "state-transition-blocked",
|
|
2449
|
+
configUpdated: "config-updated"
|
|
2450
|
+
};
|
|
2451
|
+
export {
|
|
2452
|
+
AttributeType,
|
|
2453
|
+
CONDITION_OPERATORS,
|
|
2454
|
+
COUNTRY_CURRENCIES,
|
|
2455
|
+
CURRENCY_CONFIG,
|
|
2456
|
+
CompanyType,
|
|
2457
|
+
CurrencyCode,
|
|
2458
|
+
CustomTableAvailability,
|
|
2459
|
+
CustomerPlatform,
|
|
2460
|
+
DEFAULT_CONFIG,
|
|
2461
|
+
DEFAULT_CROSS_AXIS_RULES,
|
|
2462
|
+
DEFAULT_DISPLAY_STATE_MAP,
|
|
2463
|
+
DEFAULT_RESOLVED_CONFIG,
|
|
2464
|
+
EUFixedRates,
|
|
2465
|
+
EUROPE,
|
|
2466
|
+
ExtensionCategory,
|
|
2467
|
+
FINANCIAL_INVARIANTS,
|
|
2468
|
+
FULFILLMENT_STATES,
|
|
2469
|
+
FeesCustomBillingStatus,
|
|
2470
|
+
InventoryBaseActionEnum,
|
|
2471
|
+
InventorySpecificActionType,
|
|
2472
|
+
InvoiceStatus,
|
|
2473
|
+
LibraryItemType,
|
|
2474
|
+
MenuProject,
|
|
2475
|
+
NAFixedRates,
|
|
2476
|
+
NORTH_AMERICA,
|
|
2477
|
+
NonRevenueItemType,
|
|
2478
|
+
ORDER_STATE_ACTIONS,
|
|
2479
|
+
ORDER_STATE_EVENTS,
|
|
2480
|
+
ORDER_STATE_TOPIC,
|
|
2481
|
+
OrderPlatform,
|
|
2482
|
+
OtherFixedRates,
|
|
2483
|
+
OwnerType,
|
|
2484
|
+
PATH_MODES,
|
|
2485
|
+
PAYMENT_STATES,
|
|
2486
|
+
POS_CROSS_AXIS_RULES,
|
|
2487
|
+
POS_VALID_INITIAL_STATES,
|
|
2488
|
+
PaymentMethod,
|
|
2489
|
+
Platform,
|
|
2490
|
+
PreviewImageMode,
|
|
2491
|
+
PricingLevel,
|
|
2492
|
+
PricingPlanEnum,
|
|
2493
|
+
PricingRegionEnum,
|
|
2494
|
+
ProductStatus,
|
|
2495
|
+
ProductType,
|
|
2496
|
+
PublicationAvailability,
|
|
2497
|
+
PublicationStatus,
|
|
2498
|
+
REGION_MAPPING,
|
|
2499
|
+
REPORT_NEGATE_PATHS,
|
|
2500
|
+
ReceiptSendChannel,
|
|
2501
|
+
ReceiptType,
|
|
2502
|
+
ResidualPaymentMethod,
|
|
2503
|
+
ResidualStatus,
|
|
2504
|
+
STATE_SCHEMA,
|
|
2505
|
+
STRIPE_SUPPORTED_COUNTRIES,
|
|
2506
|
+
StationStatus,
|
|
2507
|
+
StripeCurrencyCode,
|
|
2508
|
+
StripeStatus,
|
|
2509
|
+
TimePeriod,
|
|
2510
|
+
TopMetericsSort,
|
|
2511
|
+
UserTypes,
|
|
2512
|
+
addAmounts,
|
|
2513
|
+
amountToString,
|
|
2514
|
+
baseFulfillmentDefinitions,
|
|
2515
|
+
basePaymentDefinitions,
|
|
2516
|
+
buildOrderContext,
|
|
2517
|
+
buildPosPresetConfig,
|
|
2518
|
+
buildResolvedConfig,
|
|
2519
|
+
calculatePercentage,
|
|
2520
|
+
canTransition,
|
|
2521
|
+
conditionSummary,
|
|
2522
|
+
convertFixedFeeToLocalCurrency,
|
|
2523
|
+
createAmount,
|
|
2524
|
+
crossAxisRuleApplies,
|
|
2525
|
+
deriveDisplayState,
|
|
2526
|
+
displayRuleMatchesPair,
|
|
2527
|
+
divideAmount,
|
|
2528
|
+
evaluateCondition,
|
|
2529
|
+
evaluateConditionSet,
|
|
2530
|
+
formatCurrency,
|
|
2531
|
+
formatMinorUnitsToString,
|
|
2532
|
+
fromMinorUnits,
|
|
2533
|
+
generateMongoID,
|
|
2534
|
+
getAvailableTransitions,
|
|
2535
|
+
getCountriesByRegion,
|
|
2536
|
+
getCurrencyConfig,
|
|
2537
|
+
getCurrentISODate,
|
|
2538
|
+
getFinancialInvariantViolations,
|
|
2539
|
+
getMinorUnitMultiplier,
|
|
2540
|
+
getMinorUnits,
|
|
2541
|
+
getPricingRegionFromCountry,
|
|
2542
|
+
inferStatesFromLegacyStatus,
|
|
2543
|
+
isConditionOperator,
|
|
2544
|
+
isFulfillmentState,
|
|
2545
|
+
isPaymentState,
|
|
2546
|
+
isSupportedCurrency,
|
|
2547
|
+
mapToLegacyStatus,
|
|
2548
|
+
mergeFragment,
|
|
2549
|
+
multiplyAmount,
|
|
2550
|
+
normalizeMongoIdString,
|
|
2551
|
+
parseAmountToMinorUnits,
|
|
2552
|
+
parseCurrencyCode,
|
|
2553
|
+
parseStripeCurrencyCode,
|
|
2554
|
+
removeFragment,
|
|
2555
|
+
resolveTemplate,
|
|
2556
|
+
setOrderState,
|
|
2557
|
+
signReportForDisplay,
|
|
2558
|
+
stringifyMinorUnits,
|
|
2559
|
+
subtractAmounts,
|
|
2560
|
+
toMinorUnits,
|
|
2561
|
+
validateConfig,
|
|
2562
|
+
validateFragmentCompatibility,
|
|
2563
|
+
violatesFinancialInvariant
|
|
2564
|
+
};
|
|
2565
|
+
//# sourceMappingURL=index.mjs.map
|