@final-commerce/common 2.8.1-online.2 → 2.8.1-online.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/dist/index.d.mts +84 -1
- package/dist/index.d.ts +84 -1
- package/dist/index.js +183 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +174 -0
- package/dist/index.mjs.map +1 -1
- package/dist/pos-types/index.d.mts +36 -12
- package/dist/pos-types/index.d.ts +36 -12
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -531,6 +531,30 @@ var ShippingZoneError = /* @__PURE__ */ ((ShippingZoneError2) => {
|
|
|
531
531
|
return ShippingZoneError2;
|
|
532
532
|
})(ShippingZoneError || {});
|
|
533
533
|
|
|
534
|
+
// enums/tax.enum.ts
|
|
535
|
+
var TaxRegistrationKind = /* @__PURE__ */ ((TaxRegistrationKind2) => {
|
|
536
|
+
TaxRegistrationKind2["GST_HST"] = "GST_HST";
|
|
537
|
+
TaxRegistrationKind2["PST"] = "PST";
|
|
538
|
+
TaxRegistrationKind2["QST"] = "QST";
|
|
539
|
+
return TaxRegistrationKind2;
|
|
540
|
+
})(TaxRegistrationKind || {});
|
|
541
|
+
var TaxSource = /* @__PURE__ */ ((TaxSource2) => {
|
|
542
|
+
TaxSource2["MERCHANT"] = "merchant";
|
|
543
|
+
TaxSource2["AUTOMATIC"] = "automatic";
|
|
544
|
+
return TaxSource2;
|
|
545
|
+
})(TaxSource || {});
|
|
546
|
+
var OutOfProvinceTaxes = /* @__PURE__ */ ((OutOfProvinceTaxes2) => {
|
|
547
|
+
OutOfProvinceTaxes2["AUTOMATIC"] = "automatic";
|
|
548
|
+
OutOfProvinceTaxes2["HOME"] = "home";
|
|
549
|
+
return OutOfProvinceTaxes2;
|
|
550
|
+
})(OutOfProvinceTaxes || {});
|
|
551
|
+
var TaxWarningCode = /* @__PURE__ */ ((TaxWarningCode2) => {
|
|
552
|
+
TaxWarningCode2["NOT_REGISTERED"] = "NOT_REGISTERED";
|
|
553
|
+
TaxWarningCode2["NO_RULES_FOR_PLACE"] = "NO_RULES_FOR_PLACE";
|
|
554
|
+
TaxWarningCode2["NO_TABLE"] = "NO_TABLE";
|
|
555
|
+
return TaxWarningCode2;
|
|
556
|
+
})(TaxWarningCode || {});
|
|
557
|
+
|
|
534
558
|
// utils/currency.util.ts
|
|
535
559
|
var CURRENCY_CONFIG = {
|
|
536
560
|
// Major currencies with 2 decimal places
|
|
@@ -3966,6 +3990,147 @@ function tiersAreValid(option) {
|
|
|
3966
3990
|
return tiers.every((tier) => Number.isInteger(tier.from) && tier.from > 0 && isAmount(tier.price)) && new Set(froms).size === froms.length;
|
|
3967
3991
|
}
|
|
3968
3992
|
|
|
3993
|
+
// tax/sha1.ts
|
|
3994
|
+
function utf8Bytes(text) {
|
|
3995
|
+
const bytes = [];
|
|
3996
|
+
for (const char of text) {
|
|
3997
|
+
const cp = char.codePointAt(0);
|
|
3998
|
+
if (cp < 128) bytes.push(cp);
|
|
3999
|
+
else if (cp < 2048) bytes.push(192 | cp >> 6, 128 | cp & 63);
|
|
4000
|
+
else if (cp < 65536) bytes.push(224 | cp >> 12, 128 | cp >> 6 & 63, 128 | cp & 63);
|
|
4001
|
+
else bytes.push(240 | cp >> 18, 128 | cp >> 12 & 63, 128 | cp >> 6 & 63, 128 | cp & 63);
|
|
4002
|
+
}
|
|
4003
|
+
return bytes;
|
|
4004
|
+
}
|
|
4005
|
+
var rotl = (x, n) => x << n | x >>> 32 - n;
|
|
4006
|
+
function sha1Hex(text) {
|
|
4007
|
+
const bytes = utf8Bytes(text);
|
|
4008
|
+
const bitLength = bytes.length * 8;
|
|
4009
|
+
bytes.push(128);
|
|
4010
|
+
while (bytes.length % 64 !== 56) bytes.push(0);
|
|
4011
|
+
const high = Math.floor(bitLength / 4294967296);
|
|
4012
|
+
for (const word of [high, bitLength >>> 0])
|
|
4013
|
+
bytes.push(word >>> 24 & 255, word >>> 16 & 255, word >>> 8 & 255, word & 255);
|
|
4014
|
+
const h = [1732584193, 4023233417, 2562383102, 271733878, 3285377520];
|
|
4015
|
+
const w = new Array(80);
|
|
4016
|
+
for (let offset = 0; offset < bytes.length; offset += 64) {
|
|
4017
|
+
for (let i = 0; i < 16; i++) {
|
|
4018
|
+
const j = offset + i * 4;
|
|
4019
|
+
w[i] = bytes[j] << 24 | bytes[j + 1] << 16 | bytes[j + 2] << 8 | bytes[j + 3];
|
|
4020
|
+
}
|
|
4021
|
+
for (let i = 16; i < 80; i++) w[i] = rotl(w[i - 3] ^ w[i - 8] ^ w[i - 14] ^ w[i - 16], 1);
|
|
4022
|
+
let [a, b, c, d, e] = h;
|
|
4023
|
+
for (let i = 0; i < 80; i++) {
|
|
4024
|
+
const [f, k] = i < 20 ? [b & c | ~b & d, 1518500249] : i < 40 ? [b ^ c ^ d, 1859775393] : i < 60 ? [b & c | b & d | c & d, 2400959708] : [b ^ c ^ d, 3395469782];
|
|
4025
|
+
const t = rotl(a, 5) + f + e + k + w[i] | 0;
|
|
4026
|
+
e = d;
|
|
4027
|
+
d = c;
|
|
4028
|
+
c = rotl(b, 30);
|
|
4029
|
+
b = a;
|
|
4030
|
+
a = t;
|
|
4031
|
+
}
|
|
4032
|
+
h[0] = h[0] + a | 0;
|
|
4033
|
+
h[1] = h[1] + b | 0;
|
|
4034
|
+
h[2] = h[2] + c | 0;
|
|
4035
|
+
h[3] = h[3] + d | 0;
|
|
4036
|
+
h[4] = h[4] + e | 0;
|
|
4037
|
+
}
|
|
4038
|
+
return h.map((x) => (x >>> 0).toString(16).padStart(8, "0")).join("");
|
|
4039
|
+
}
|
|
4040
|
+
|
|
4041
|
+
// tax/table.ts
|
|
4042
|
+
var STANDARD_TAX_TYPE = "standard";
|
|
4043
|
+
var TYPE_FIELDS = ["key", "name", "description", "sortOrder", "active"];
|
|
4044
|
+
var RATE_FIELDS = [
|
|
4045
|
+
"code",
|
|
4046
|
+
"name",
|
|
4047
|
+
"kind",
|
|
4048
|
+
"places",
|
|
4049
|
+
"rate",
|
|
4050
|
+
"from",
|
|
4051
|
+
"to",
|
|
4052
|
+
"order",
|
|
4053
|
+
"compound",
|
|
4054
|
+
"registrationPlace",
|
|
4055
|
+
"harmonized",
|
|
4056
|
+
"parts",
|
|
4057
|
+
"sourceUrl",
|
|
4058
|
+
"status"
|
|
4059
|
+
];
|
|
4060
|
+
var RULE_FIELDS = ["taxType", "codes", "rate", "from", "to", "sourceUrl", "status", "note"];
|
|
4061
|
+
function canonical(row, fields) {
|
|
4062
|
+
return JSON.stringify(fields.map((field) => row[field] ?? null));
|
|
4063
|
+
}
|
|
4064
|
+
var sortedCanonical = (rows, fields) => rows.map((row) => canonical(row, fields)).sort();
|
|
4065
|
+
function automaticTaxTableVersion(table) {
|
|
4066
|
+
return sha1Hex(
|
|
4067
|
+
JSON.stringify([
|
|
4068
|
+
sortedCanonical(table.types, TYPE_FIELDS),
|
|
4069
|
+
sortedCanonical(table.rates, RATE_FIELDS),
|
|
4070
|
+
sortedCanonical(table.rules, RULE_FIELDS)
|
|
4071
|
+
])
|
|
4072
|
+
);
|
|
4073
|
+
}
|
|
4074
|
+
var toTypeRow = ({ key, name, description, sortOrder, active }) => ({
|
|
4075
|
+
key,
|
|
4076
|
+
name,
|
|
4077
|
+
description,
|
|
4078
|
+
sortOrder,
|
|
4079
|
+
active
|
|
4080
|
+
});
|
|
4081
|
+
var toRateRow = (rate) => ({
|
|
4082
|
+
code: rate.code,
|
|
4083
|
+
name: rate.name,
|
|
4084
|
+
kind: rate.kind,
|
|
4085
|
+
places: rate.places,
|
|
4086
|
+
rate: rate.rate,
|
|
4087
|
+
from: rate.from,
|
|
4088
|
+
to: rate.to,
|
|
4089
|
+
order: rate.order,
|
|
4090
|
+
compound: rate.compound,
|
|
4091
|
+
registrationPlace: rate.registrationPlace,
|
|
4092
|
+
harmonized: rate.harmonized,
|
|
4093
|
+
parts: rate.parts?.map(({ code, name, rate: partRate, level }) => ({ code, name, rate: partRate, level })),
|
|
4094
|
+
sourceUrl: rate.sourceUrl,
|
|
4095
|
+
status: rate.status
|
|
4096
|
+
});
|
|
4097
|
+
var toRuleRow = ({
|
|
4098
|
+
taxType,
|
|
4099
|
+
codes: codes2,
|
|
4100
|
+
rate,
|
|
4101
|
+
from,
|
|
4102
|
+
to,
|
|
4103
|
+
sourceUrl,
|
|
4104
|
+
status,
|
|
4105
|
+
note
|
|
4106
|
+
}) => ({
|
|
4107
|
+
taxType,
|
|
4108
|
+
codes: codes2,
|
|
4109
|
+
rate,
|
|
4110
|
+
from,
|
|
4111
|
+
to,
|
|
4112
|
+
sourceUrl,
|
|
4113
|
+
status,
|
|
4114
|
+
note
|
|
4115
|
+
});
|
|
4116
|
+
function buildAutomaticTaxTable(rows) {
|
|
4117
|
+
const table = {
|
|
4118
|
+
types: [...rows.types].sort((a, b) => a.sortOrder - b.sortOrder).map(toTypeRow),
|
|
4119
|
+
rates: rows.rates.map(toRateRow),
|
|
4120
|
+
rules: rows.rules.map(toRuleRow)
|
|
4121
|
+
};
|
|
4122
|
+
return { version: automaticTaxTableVersion(table), ...table };
|
|
4123
|
+
}
|
|
4124
|
+
function registrationPlacesByKind(rates) {
|
|
4125
|
+
const places = /* @__PURE__ */ new Map();
|
|
4126
|
+
for (const rate of rates) {
|
|
4127
|
+
const list = places.get(rate.kind) ?? [];
|
|
4128
|
+
if (!list.includes(rate.registrationPlace)) list.push(rate.registrationPlace);
|
|
4129
|
+
places.set(rate.kind, list);
|
|
4130
|
+
}
|
|
4131
|
+
return places;
|
|
4132
|
+
}
|
|
4133
|
+
|
|
3969
4134
|
// constants/adyen.constants.ts
|
|
3970
4135
|
var ADYEN_ROLLOUT_COUNTRY_CODES = /* @__PURE__ */ new Set(["CA"]);
|
|
3971
4136
|
function isAdyenRolloutCountry(alpha2) {
|
|
@@ -4117,6 +4282,7 @@ export {
|
|
|
4117
4282
|
ORDER_STATE_TOPIC,
|
|
4118
4283
|
OrderPlatform,
|
|
4119
4284
|
OtherFixedRates,
|
|
4285
|
+
OutOfProvinceTaxes,
|
|
4120
4286
|
OwnerType,
|
|
4121
4287
|
PATH_MODES,
|
|
4122
4288
|
PAYMENT_CHANNELS,
|
|
@@ -4142,6 +4308,7 @@ export {
|
|
|
4142
4308
|
ResidualPaymentMethod,
|
|
4143
4309
|
ResidualStatus,
|
|
4144
4310
|
ResourceAvailabilityState,
|
|
4311
|
+
STANDARD_TAX_TYPE,
|
|
4145
4312
|
STATE_SCHEMA,
|
|
4146
4313
|
STRIPE_SUPPORTED_COUNTRIES,
|
|
4147
4314
|
SYSTEM_FAMILIES,
|
|
@@ -4157,6 +4324,9 @@ export {
|
|
|
4157
4324
|
StationStatus,
|
|
4158
4325
|
StripeCurrencyCode,
|
|
4159
4326
|
StripeStatus,
|
|
4327
|
+
TaxRegistrationKind,
|
|
4328
|
+
TaxSource,
|
|
4329
|
+
TaxWarningCode,
|
|
4160
4330
|
TimePeriod,
|
|
4161
4331
|
TopMetericsSort,
|
|
4162
4332
|
UserTypes,
|
|
@@ -4170,11 +4340,13 @@ export {
|
|
|
4170
4340
|
amountToString,
|
|
4171
4341
|
ancestorChain,
|
|
4172
4342
|
assertUnitSane,
|
|
4343
|
+
automaticTaxTableVersion,
|
|
4173
4344
|
availableIn,
|
|
4174
4345
|
baseFor,
|
|
4175
4346
|
baseFulfillmentDefinitions,
|
|
4176
4347
|
baseOf,
|
|
4177
4348
|
basePaymentDefinitions,
|
|
4349
|
+
buildAutomaticTaxTable,
|
|
4178
4350
|
buildAvailability,
|
|
4179
4351
|
buildGrid,
|
|
4180
4352
|
buildOrderContext,
|
|
@@ -4268,6 +4440,7 @@ export {
|
|
|
4268
4440
|
presentAt,
|
|
4269
4441
|
priceForTotal,
|
|
4270
4442
|
provincesForPostCode,
|
|
4443
|
+
registrationPlacesByKind,
|
|
4271
4444
|
removeFragment,
|
|
4272
4445
|
resolveFamily,
|
|
4273
4446
|
resolveModifiersForProduct,
|
|
@@ -4277,6 +4450,7 @@ export {
|
|
|
4277
4450
|
roundToPrecision,
|
|
4278
4451
|
sameFamily,
|
|
4279
4452
|
setOrderState,
|
|
4453
|
+
sha1Hex,
|
|
4280
4454
|
shopDayKey,
|
|
4281
4455
|
shopDayRange,
|
|
4282
4456
|
signReportForDisplay,
|