@final-commerce/common 2.11.0 → 2.11.1-online.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -541,6 +541,30 @@ var ShippingZoneError = /* @__PURE__ */ ((ShippingZoneError2) => {
541
541
  return ShippingZoneError2;
542
542
  })(ShippingZoneError || {});
543
543
 
544
+ // enums/tax.enum.ts
545
+ var TaxRegistrationKind = /* @__PURE__ */ ((TaxRegistrationKind2) => {
546
+ TaxRegistrationKind2["GST_HST"] = "GST_HST";
547
+ TaxRegistrationKind2["PST"] = "PST";
548
+ TaxRegistrationKind2["QST"] = "QST";
549
+ return TaxRegistrationKind2;
550
+ })(TaxRegistrationKind || {});
551
+ var TaxSource = /* @__PURE__ */ ((TaxSource2) => {
552
+ TaxSource2["MERCHANT"] = "merchant";
553
+ TaxSource2["AUTOMATIC"] = "automatic";
554
+ return TaxSource2;
555
+ })(TaxSource || {});
556
+ var OutOfProvinceTaxes = /* @__PURE__ */ ((OutOfProvinceTaxes2) => {
557
+ OutOfProvinceTaxes2["AUTOMATIC"] = "automatic";
558
+ OutOfProvinceTaxes2["HOME"] = "home";
559
+ return OutOfProvinceTaxes2;
560
+ })(OutOfProvinceTaxes || {});
561
+ var TaxWarningCode = /* @__PURE__ */ ((TaxWarningCode2) => {
562
+ TaxWarningCode2["NOT_REGISTERED"] = "NOT_REGISTERED";
563
+ TaxWarningCode2["NO_RULES_FOR_PLACE"] = "NO_RULES_FOR_PLACE";
564
+ TaxWarningCode2["NO_TABLE"] = "NO_TABLE";
565
+ return TaxWarningCode2;
566
+ })(TaxWarningCode || {});
567
+
544
568
  // enums/sales-line.enum.ts
545
569
  var SalesLineAction = /* @__PURE__ */ ((SalesLineAction2) => {
546
570
  SalesLineAction2["SALE"] = "sale";
@@ -4045,6 +4069,147 @@ function tiersAreValid(option) {
4045
4069
  return tiers.every((tier) => Number.isInteger(tier.from) && tier.from > 0 && isAmount(tier.price)) && new Set(froms).size === froms.length;
4046
4070
  }
4047
4071
 
4072
+ // tax/sha1.ts
4073
+ function utf8Bytes(text) {
4074
+ const bytes = [];
4075
+ for (const char of text) {
4076
+ const cp = char.codePointAt(0);
4077
+ if (cp < 128) bytes.push(cp);
4078
+ else if (cp < 2048) bytes.push(192 | cp >> 6, 128 | cp & 63);
4079
+ else if (cp < 65536) bytes.push(224 | cp >> 12, 128 | cp >> 6 & 63, 128 | cp & 63);
4080
+ else bytes.push(240 | cp >> 18, 128 | cp >> 12 & 63, 128 | cp >> 6 & 63, 128 | cp & 63);
4081
+ }
4082
+ return bytes;
4083
+ }
4084
+ var rotl = (x, n) => x << n | x >>> 32 - n;
4085
+ function sha1Hex(text) {
4086
+ const bytes = utf8Bytes(text);
4087
+ const bitLength = bytes.length * 8;
4088
+ bytes.push(128);
4089
+ while (bytes.length % 64 !== 56) bytes.push(0);
4090
+ const high = Math.floor(bitLength / 4294967296);
4091
+ for (const word of [high, bitLength >>> 0])
4092
+ bytes.push(word >>> 24 & 255, word >>> 16 & 255, word >>> 8 & 255, word & 255);
4093
+ const h = [1732584193, 4023233417, 2562383102, 271733878, 3285377520];
4094
+ const w = new Array(80);
4095
+ for (let offset = 0; offset < bytes.length; offset += 64) {
4096
+ for (let i = 0; i < 16; i++) {
4097
+ const j = offset + i * 4;
4098
+ w[i] = bytes[j] << 24 | bytes[j + 1] << 16 | bytes[j + 2] << 8 | bytes[j + 3];
4099
+ }
4100
+ for (let i = 16; i < 80; i++) w[i] = rotl(w[i - 3] ^ w[i - 8] ^ w[i - 14] ^ w[i - 16], 1);
4101
+ let [a, b, c, d, e] = h;
4102
+ for (let i = 0; i < 80; i++) {
4103
+ 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];
4104
+ const t = rotl(a, 5) + f + e + k + w[i] | 0;
4105
+ e = d;
4106
+ d = c;
4107
+ c = rotl(b, 30);
4108
+ b = a;
4109
+ a = t;
4110
+ }
4111
+ h[0] = h[0] + a | 0;
4112
+ h[1] = h[1] + b | 0;
4113
+ h[2] = h[2] + c | 0;
4114
+ h[3] = h[3] + d | 0;
4115
+ h[4] = h[4] + e | 0;
4116
+ }
4117
+ return h.map((x) => (x >>> 0).toString(16).padStart(8, "0")).join("");
4118
+ }
4119
+
4120
+ // tax/table.ts
4121
+ var STANDARD_TAX_TYPE = "standard";
4122
+ var TYPE_FIELDS = ["key", "name", "description", "sortOrder", "active"];
4123
+ var RATE_FIELDS = [
4124
+ "code",
4125
+ "name",
4126
+ "kind",
4127
+ "places",
4128
+ "rate",
4129
+ "from",
4130
+ "to",
4131
+ "order",
4132
+ "compound",
4133
+ "registrationPlace",
4134
+ "harmonized",
4135
+ "parts",
4136
+ "sourceUrl",
4137
+ "status"
4138
+ ];
4139
+ var RULE_FIELDS = ["taxType", "codes", "rate", "from", "to", "sourceUrl", "status", "note"];
4140
+ function canonical(row, fields) {
4141
+ return JSON.stringify(fields.map((field) => row[field] ?? null));
4142
+ }
4143
+ var sortedCanonical = (rows, fields) => rows.map((row) => canonical(row, fields)).sort();
4144
+ function automaticTaxTableVersion(table) {
4145
+ return sha1Hex(
4146
+ JSON.stringify([
4147
+ sortedCanonical(table.types, TYPE_FIELDS),
4148
+ sortedCanonical(table.rates, RATE_FIELDS),
4149
+ sortedCanonical(table.rules, RULE_FIELDS)
4150
+ ])
4151
+ );
4152
+ }
4153
+ var toTypeRow = ({ key, name, description, sortOrder, active }) => ({
4154
+ key,
4155
+ name,
4156
+ description,
4157
+ sortOrder,
4158
+ active
4159
+ });
4160
+ var toRateRow = (rate) => ({
4161
+ code: rate.code,
4162
+ name: rate.name,
4163
+ kind: rate.kind,
4164
+ places: rate.places,
4165
+ rate: rate.rate,
4166
+ from: rate.from,
4167
+ to: rate.to,
4168
+ order: rate.order,
4169
+ compound: rate.compound,
4170
+ registrationPlace: rate.registrationPlace,
4171
+ harmonized: rate.harmonized,
4172
+ parts: rate.parts?.map(({ code, name, rate: partRate, level }) => ({ code, name, rate: partRate, level })),
4173
+ sourceUrl: rate.sourceUrl,
4174
+ status: rate.status
4175
+ });
4176
+ var toRuleRow = ({
4177
+ taxType,
4178
+ codes: codes2,
4179
+ rate,
4180
+ from,
4181
+ to,
4182
+ sourceUrl,
4183
+ status,
4184
+ note
4185
+ }) => ({
4186
+ taxType,
4187
+ codes: codes2,
4188
+ rate,
4189
+ from,
4190
+ to,
4191
+ sourceUrl,
4192
+ status,
4193
+ note
4194
+ });
4195
+ function buildAutomaticTaxTable(rows) {
4196
+ const table = {
4197
+ types: [...rows.types].sort((a, b) => a.sortOrder - b.sortOrder).map(toTypeRow),
4198
+ rates: rows.rates.map(toRateRow),
4199
+ rules: rows.rules.map(toRuleRow)
4200
+ };
4201
+ return { version: automaticTaxTableVersion(table), ...table };
4202
+ }
4203
+ function registrationPlacesByKind(rates) {
4204
+ const places = /* @__PURE__ */ new Map();
4205
+ for (const rate of rates) {
4206
+ const list = places.get(rate.kind) ?? [];
4207
+ if (!list.includes(rate.registrationPlace)) list.push(rate.registrationPlace);
4208
+ places.set(rate.kind, list);
4209
+ }
4210
+ return places;
4211
+ }
4212
+
4048
4213
  // constants/adyen.constants.ts
4049
4214
  var ADYEN_ROLLOUT_COUNTRY_CODES = /* @__PURE__ */ new Set(["CA"]);
4050
4215
  function isAdyenRolloutCountry(alpha2) {
@@ -4197,6 +4362,7 @@ export {
4197
4362
  ORDER_STATE_TOPIC,
4198
4363
  OrderPlatform,
4199
4364
  OtherFixedRates,
4365
+ OutOfProvinceTaxes,
4200
4366
  OwnerType,
4201
4367
  PATH_MODES,
4202
4368
  PAYMENT_CHANNELS,
@@ -4225,6 +4391,7 @@ export {
4225
4391
  ResidualStatus,
4226
4392
  ResourceAvailabilityState,
4227
4393
  SHIPPING_COUNTRIES,
4394
+ STANDARD_TAX_TYPE,
4228
4395
  STATE_SCHEMA,
4229
4396
  STRIPE_SUPPORTED_COUNTRIES,
4230
4397
  SYSTEM_FAMILIES,
@@ -4242,6 +4409,9 @@ export {
4242
4409
  StationStatus,
4243
4410
  StripeCurrencyCode,
4244
4411
  StripeStatus,
4412
+ TaxRegistrationKind,
4413
+ TaxSource,
4414
+ TaxWarningCode,
4245
4415
  TimePeriod,
4246
4416
  TopMetericsSort,
4247
4417
  UserTypes,
@@ -4256,11 +4426,13 @@ export {
4256
4426
  ancestorChain,
4257
4427
  applyAssignment,
4258
4428
  assertUnitSane,
4429
+ automaticTaxTableVersion,
4259
4430
  availableIn,
4260
4431
  baseFor,
4261
4432
  baseFulfillmentDefinitions,
4262
4433
  baseOf,
4263
4434
  basePaymentDefinitions,
4435
+ buildAutomaticTaxTable,
4264
4436
  buildAvailability,
4265
4437
  buildGrid,
4266
4438
  buildOrderContext,
@@ -4357,6 +4529,7 @@ export {
4357
4529
  presentAt,
4358
4530
  priceForTotal,
4359
4531
  provincesForPostCode,
4532
+ registrationPlacesByKind,
4360
4533
  removeFragment,
4361
4534
  resolveFamily,
4362
4535
  resolveModifiersForProduct,
@@ -4366,6 +4539,7 @@ export {
4366
4539
  roundToPrecision,
4367
4540
  sameFamily,
4368
4541
  setOrderState,
4542
+ sha1Hex,
4369
4543
  shipsToCountry,
4370
4544
  shopDayKey,
4371
4545
  shopDayRange,