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

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.js CHANGED
@@ -77,6 +77,7 @@ __export(index_exports, {
77
77
  ORDER_STATE_TOPIC: () => ORDER_STATE_TOPIC,
78
78
  OrderPlatform: () => OrderPlatform,
79
79
  OtherFixedRates: () => OtherFixedRates,
80
+ OutOfProvinceTaxes: () => OutOfProvinceTaxes,
80
81
  OwnerType: () => OwnerType,
81
82
  PATH_MODES: () => PATH_MODES,
82
83
  PAYMENT_CHANNELS: () => PAYMENT_CHANNELS,
@@ -105,6 +106,10 @@ __export(index_exports, {
105
106
  ResidualStatus: () => ResidualStatus,
106
107
  ResourceAvailabilityState: () => ResourceAvailabilityState,
107
108
  SHIPPING_COUNTRIES: () => SHIPPING_COUNTRIES,
109
+ SHOPPER_CONSENT_SOURCES: () => SHOPPER_CONSENT_SOURCES,
110
+ SHOPPER_ERROR_CODES: () => SHOPPER_ERROR_CODES,
111
+ SHOPPER_RETURN_METHODS: () => SHOPPER_RETURN_METHODS,
112
+ STANDARD_TAX_TYPE: () => STANDARD_TAX_TYPE,
108
113
  STATE_SCHEMA: () => STATE_SCHEMA,
109
114
  STRIPE_SUPPORTED_COUNTRIES: () => STRIPE_SUPPORTED_COUNTRIES,
110
115
  SYSTEM_FAMILIES: () => SYSTEM_FAMILIES,
@@ -122,6 +127,9 @@ __export(index_exports, {
122
127
  StationStatus: () => StationStatus,
123
128
  StripeCurrencyCode: () => StripeCurrencyCode,
124
129
  StripeStatus: () => StripeStatus,
130
+ TaxRegistrationKind: () => TaxRegistrationKind,
131
+ TaxSource: () => TaxSource,
132
+ TaxWarningCode: () => TaxWarningCode,
125
133
  TimePeriod: () => TimePeriod,
126
134
  TopMetericsSort: () => TopMetericsSort,
127
135
  UserTypes: () => UserTypes,
@@ -136,11 +144,13 @@ __export(index_exports, {
136
144
  ancestorChain: () => ancestorChain,
137
145
  applyAssignment: () => applyAssignment,
138
146
  assertUnitSane: () => assertUnitSane,
147
+ automaticTaxTableVersion: () => automaticTaxTableVersion,
139
148
  availableIn: () => availableIn,
140
149
  baseFor: () => baseFor,
141
150
  baseFulfillmentDefinitions: () => baseFulfillmentDefinitions,
142
151
  baseOf: () => baseOf,
143
152
  basePaymentDefinitions: () => basePaymentDefinitions,
153
+ buildAutomaticTaxTable: () => buildAutomaticTaxTable,
144
154
  buildAvailability: () => buildAvailability,
145
155
  buildGrid: () => buildGrid,
146
156
  buildOrderContext: () => buildOrderContext,
@@ -148,6 +158,7 @@ __export(index_exports, {
148
158
  buildResolvedConfig: () => buildResolvedConfig,
149
159
  calculatePercentage: () => calculatePercentage,
150
160
  canTransition: () => canTransition,
161
+ cardFromProcessorData: () => cardFromProcessorData,
151
162
  cheapestCompositeItem: () => cheapestCompositeItem,
152
163
  cheapestCompositePrice: () => cheapestCompositePrice,
153
164
  compositeItemCost: () => compositeItemCost,
@@ -222,6 +233,7 @@ __export(index_exports, {
222
233
  normalizeMongoIdString: () => normalizeMongoIdString,
223
234
  normalizePostCode: () => normalizePostCode,
224
235
  normalizeProvince: () => normalizeProvince,
236
+ normalizeShopperEmail: () => normalizeShopperEmail,
225
237
  occupancyIn: () => occupancyIn,
226
238
  orderAssignments: () => orderAssignments,
227
239
  parseAmountToMinorUnits: () => parseAmountToMinorUnits,
@@ -237,6 +249,7 @@ __export(index_exports, {
237
249
  presentAt: () => presentAt,
238
250
  priceForTotal: () => priceForTotal,
239
251
  provincesForPostCode: () => provincesForPostCode,
252
+ registrationPlacesByKind: () => registrationPlacesByKind,
240
253
  removeFragment: () => removeFragment,
241
254
  resolveFamily: () => resolveFamily,
242
255
  resolveModifiersForProduct: () => resolveModifiersForProduct,
@@ -246,6 +259,7 @@ __export(index_exports, {
246
259
  roundToPrecision: () => roundToPrecision,
247
260
  sameFamily: () => sameFamily,
248
261
  setOrderState: () => setOrderState,
262
+ sha1Hex: () => sha1Hex,
249
263
  shipsToCountry: () => shipsToCountry,
250
264
  shopDayKey: () => shopDayKey,
251
265
  shopDayRange: () => shopDayRange,
@@ -808,6 +822,30 @@ var ShippingZoneError = /* @__PURE__ */ ((ShippingZoneError2) => {
808
822
  return ShippingZoneError2;
809
823
  })(ShippingZoneError || {});
810
824
 
825
+ // enums/tax.enum.ts
826
+ var TaxRegistrationKind = /* @__PURE__ */ ((TaxRegistrationKind2) => {
827
+ TaxRegistrationKind2["GST_HST"] = "GST_HST";
828
+ TaxRegistrationKind2["PST"] = "PST";
829
+ TaxRegistrationKind2["QST"] = "QST";
830
+ return TaxRegistrationKind2;
831
+ })(TaxRegistrationKind || {});
832
+ var TaxSource = /* @__PURE__ */ ((TaxSource2) => {
833
+ TaxSource2["MERCHANT"] = "merchant";
834
+ TaxSource2["AUTOMATIC"] = "automatic";
835
+ return TaxSource2;
836
+ })(TaxSource || {});
837
+ var OutOfProvinceTaxes = /* @__PURE__ */ ((OutOfProvinceTaxes2) => {
838
+ OutOfProvinceTaxes2["AUTOMATIC"] = "automatic";
839
+ OutOfProvinceTaxes2["HOME"] = "home";
840
+ return OutOfProvinceTaxes2;
841
+ })(OutOfProvinceTaxes || {});
842
+ var TaxWarningCode = /* @__PURE__ */ ((TaxWarningCode2) => {
843
+ TaxWarningCode2["NOT_REGISTERED"] = "NOT_REGISTERED";
844
+ TaxWarningCode2["NO_RULES_FOR_PLACE"] = "NO_RULES_FOR_PLACE";
845
+ TaxWarningCode2["NO_TABLE"] = "NO_TABLE";
846
+ return TaxWarningCode2;
847
+ })(TaxWarningCode || {});
848
+
811
849
  // enums/sales-line.enum.ts
812
850
  var SalesLineAction = /* @__PURE__ */ ((SalesLineAction2) => {
813
851
  SalesLineAction2["SALE"] = "sale";
@@ -4312,6 +4350,187 @@ function tiersAreValid(option) {
4312
4350
  return tiers.every((tier) => Number.isInteger(tier.from) && tier.from > 0 && isAmount(tier.price)) && new Set(froms).size === froms.length;
4313
4351
  }
4314
4352
 
4353
+ // tax/sha1.ts
4354
+ function utf8Bytes(text) {
4355
+ const bytes = [];
4356
+ for (const char of text) {
4357
+ const cp = char.codePointAt(0);
4358
+ if (cp < 128) bytes.push(cp);
4359
+ else if (cp < 2048) bytes.push(192 | cp >> 6, 128 | cp & 63);
4360
+ else if (cp < 65536) bytes.push(224 | cp >> 12, 128 | cp >> 6 & 63, 128 | cp & 63);
4361
+ else bytes.push(240 | cp >> 18, 128 | cp >> 12 & 63, 128 | cp >> 6 & 63, 128 | cp & 63);
4362
+ }
4363
+ return bytes;
4364
+ }
4365
+ var rotl = (x, n) => x << n | x >>> 32 - n;
4366
+ function sha1Hex(text) {
4367
+ const bytes = utf8Bytes(text);
4368
+ const bitLength = bytes.length * 8;
4369
+ bytes.push(128);
4370
+ while (bytes.length % 64 !== 56) bytes.push(0);
4371
+ const high = Math.floor(bitLength / 4294967296);
4372
+ for (const word of [high, bitLength >>> 0])
4373
+ bytes.push(word >>> 24 & 255, word >>> 16 & 255, word >>> 8 & 255, word & 255);
4374
+ const h = [1732584193, 4023233417, 2562383102, 271733878, 3285377520];
4375
+ const w = new Array(80);
4376
+ for (let offset = 0; offset < bytes.length; offset += 64) {
4377
+ for (let i = 0; i < 16; i++) {
4378
+ const j = offset + i * 4;
4379
+ w[i] = bytes[j] << 24 | bytes[j + 1] << 16 | bytes[j + 2] << 8 | bytes[j + 3];
4380
+ }
4381
+ for (let i = 16; i < 80; i++) w[i] = rotl(w[i - 3] ^ w[i - 8] ^ w[i - 14] ^ w[i - 16], 1);
4382
+ let [a, b, c, d, e] = h;
4383
+ for (let i = 0; i < 80; i++) {
4384
+ 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];
4385
+ const t = rotl(a, 5) + f + e + k + w[i] | 0;
4386
+ e = d;
4387
+ d = c;
4388
+ c = rotl(b, 30);
4389
+ b = a;
4390
+ a = t;
4391
+ }
4392
+ h[0] = h[0] + a | 0;
4393
+ h[1] = h[1] + b | 0;
4394
+ h[2] = h[2] + c | 0;
4395
+ h[3] = h[3] + d | 0;
4396
+ h[4] = h[4] + e | 0;
4397
+ }
4398
+ return h.map((x) => (x >>> 0).toString(16).padStart(8, "0")).join("");
4399
+ }
4400
+
4401
+ // tax/table.ts
4402
+ var STANDARD_TAX_TYPE = "standard";
4403
+ var TYPE_FIELDS = ["key", "name", "description", "sortOrder", "active"];
4404
+ var RATE_FIELDS = [
4405
+ "code",
4406
+ "name",
4407
+ "kind",
4408
+ "places",
4409
+ "rate",
4410
+ "from",
4411
+ "to",
4412
+ "order",
4413
+ "compound",
4414
+ "registrationPlace",
4415
+ "harmonized",
4416
+ "parts",
4417
+ "sourceUrl",
4418
+ "status"
4419
+ ];
4420
+ var RULE_FIELDS = ["taxType", "codes", "rate", "from", "to", "sourceUrl", "status", "note"];
4421
+ function canonical(row, fields) {
4422
+ return JSON.stringify(fields.map((field) => row[field] ?? null));
4423
+ }
4424
+ var sortedCanonical = (rows, fields) => rows.map((row) => canonical(row, fields)).sort();
4425
+ function automaticTaxTableVersion(table) {
4426
+ return sha1Hex(
4427
+ JSON.stringify([
4428
+ sortedCanonical(table.types, TYPE_FIELDS),
4429
+ sortedCanonical(table.rates, RATE_FIELDS),
4430
+ sortedCanonical(table.rules, RULE_FIELDS)
4431
+ ])
4432
+ );
4433
+ }
4434
+ var toTypeRow = ({ key, name, description, sortOrder, active }) => ({
4435
+ key,
4436
+ name,
4437
+ description,
4438
+ sortOrder,
4439
+ active
4440
+ });
4441
+ var toRateRow = (rate) => ({
4442
+ code: rate.code,
4443
+ name: rate.name,
4444
+ kind: rate.kind,
4445
+ places: rate.places,
4446
+ rate: rate.rate,
4447
+ from: rate.from,
4448
+ to: rate.to,
4449
+ order: rate.order,
4450
+ compound: rate.compound,
4451
+ registrationPlace: rate.registrationPlace,
4452
+ harmonized: rate.harmonized,
4453
+ parts: rate.parts?.map(({ code, name, rate: partRate, level }) => ({ code, name, rate: partRate, level })),
4454
+ sourceUrl: rate.sourceUrl,
4455
+ status: rate.status
4456
+ });
4457
+ var toRuleRow = ({
4458
+ taxType,
4459
+ codes: codes2,
4460
+ rate,
4461
+ from,
4462
+ to,
4463
+ sourceUrl,
4464
+ status,
4465
+ note
4466
+ }) => ({
4467
+ taxType,
4468
+ codes: codes2,
4469
+ rate,
4470
+ from,
4471
+ to,
4472
+ sourceUrl,
4473
+ status,
4474
+ note
4475
+ });
4476
+ function buildAutomaticTaxTable(rows) {
4477
+ const table = {
4478
+ types: [...rows.types].sort((a, b) => a.sortOrder - b.sortOrder).map(toTypeRow),
4479
+ rates: rows.rates.map(toRateRow),
4480
+ rules: rows.rules.map(toRuleRow)
4481
+ };
4482
+ return { version: automaticTaxTableVersion(table), ...table };
4483
+ }
4484
+ function registrationPlacesByKind(rates) {
4485
+ const places = /* @__PURE__ */ new Map();
4486
+ for (const rate of rates) {
4487
+ const list = places.get(rate.kind) ?? [];
4488
+ if (!list.includes(rate.registrationPlace)) list.push(rate.registrationPlace);
4489
+ places.set(rate.kind, list);
4490
+ }
4491
+ return places;
4492
+ }
4493
+
4494
+ // shopper/types.ts
4495
+ var SHOPPER_CONSENT_SOURCES = ["checkout", "my-account", "store-account"];
4496
+ var SHOPPER_RETURN_METHODS = ["mail", "in-store"];
4497
+ var SHOPPER_ERROR_CODES = {
4498
+ ORDER_NOT_FOUND: "ORDER_NOT_FOUND",
4499
+ RETURN_ALREADY_REQUESTED: "RETURN_ALREADY_REQUESTED",
4500
+ RETURN_NOT_ALLOWED: "RETURN_NOT_ALLOWED",
4501
+ STORE_HAS_NO_SUPPORT_EMAIL: "STORE_HAS_NO_SUPPORT_EMAIL",
4502
+ TOO_MANY_ADDRESSES: "TOO_MANY_ADDRESSES",
4503
+ STORE_NOT_LINKED: "STORE_NOT_LINKED",
4504
+ STORED_METHOD_NOT_FOUND: "STORED_METHOD_NOT_FOUND"
4505
+ };
4506
+
4507
+ // shopper/email.ts
4508
+ function normalizeShopperEmail(email) {
4509
+ if (typeof email !== "string") return null;
4510
+ const value = email.trim().toLowerCase();
4511
+ return /^[^\s@]+@[^\s@]+$/.test(value) ? value : null;
4512
+ }
4513
+
4514
+ // shopper/card.ts
4515
+ function cardFromProcessorData(processorData) {
4516
+ if (typeof processorData !== "string" || !processorData) return {};
4517
+ let data;
4518
+ try {
4519
+ data = JSON.parse(processorData);
4520
+ } catch {
4521
+ return {};
4522
+ }
4523
+ if (!data || typeof data !== "object") return {};
4524
+ const fields = new Map(Object.entries(data));
4525
+ const text = (...keys) => keys.map((key) => fields.get(key)).find((value) => typeof value === "string" && !!value.trim());
4526
+ const brand = text("Brand", "brand")?.trim();
4527
+ const digits = text("Card Number", "card", "card_number")?.replace(/\D/g, "");
4528
+ return {
4529
+ ...brand ? { cardBrand: brand.charAt(0).toUpperCase() + brand.slice(1) } : {},
4530
+ ...digits && digits.length >= 4 ? { cardLastFour: digits.slice(-4) } : {}
4531
+ };
4532
+ }
4533
+
4315
4534
  // constants/adyen.constants.ts
4316
4535
  var ADYEN_ROLLOUT_COUNTRY_CODES = /* @__PURE__ */ new Set(["CA"]);
4317
4536
  function isAdyenRolloutCountry(alpha2) {
@@ -4465,6 +4684,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
4465
4684
  ORDER_STATE_TOPIC,
4466
4685
  OrderPlatform,
4467
4686
  OtherFixedRates,
4687
+ OutOfProvinceTaxes,
4468
4688
  OwnerType,
4469
4689
  PATH_MODES,
4470
4690
  PAYMENT_CHANNELS,
@@ -4493,6 +4713,10 @@ var EXPENSE_DEFAULT_CATEGORIES = [
4493
4713
  ResidualStatus,
4494
4714
  ResourceAvailabilityState,
4495
4715
  SHIPPING_COUNTRIES,
4716
+ SHOPPER_CONSENT_SOURCES,
4717
+ SHOPPER_ERROR_CODES,
4718
+ SHOPPER_RETURN_METHODS,
4719
+ STANDARD_TAX_TYPE,
4496
4720
  STATE_SCHEMA,
4497
4721
  STRIPE_SUPPORTED_COUNTRIES,
4498
4722
  SYSTEM_FAMILIES,
@@ -4510,6 +4734,9 @@ var EXPENSE_DEFAULT_CATEGORIES = [
4510
4734
  StationStatus,
4511
4735
  StripeCurrencyCode,
4512
4736
  StripeStatus,
4737
+ TaxRegistrationKind,
4738
+ TaxSource,
4739
+ TaxWarningCode,
4513
4740
  TimePeriod,
4514
4741
  TopMetericsSort,
4515
4742
  UserTypes,
@@ -4524,11 +4751,13 @@ var EXPENSE_DEFAULT_CATEGORIES = [
4524
4751
  ancestorChain,
4525
4752
  applyAssignment,
4526
4753
  assertUnitSane,
4754
+ automaticTaxTableVersion,
4527
4755
  availableIn,
4528
4756
  baseFor,
4529
4757
  baseFulfillmentDefinitions,
4530
4758
  baseOf,
4531
4759
  basePaymentDefinitions,
4760
+ buildAutomaticTaxTable,
4532
4761
  buildAvailability,
4533
4762
  buildGrid,
4534
4763
  buildOrderContext,
@@ -4536,6 +4765,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
4536
4765
  buildResolvedConfig,
4537
4766
  calculatePercentage,
4538
4767
  canTransition,
4768
+ cardFromProcessorData,
4539
4769
  cheapestCompositeItem,
4540
4770
  cheapestCompositePrice,
4541
4771
  compositeItemCost,
@@ -4610,6 +4840,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
4610
4840
  normalizeMongoIdString,
4611
4841
  normalizePostCode,
4612
4842
  normalizeProvince,
4843
+ normalizeShopperEmail,
4613
4844
  occupancyIn,
4614
4845
  orderAssignments,
4615
4846
  parseAmountToMinorUnits,
@@ -4625,6 +4856,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
4625
4856
  presentAt,
4626
4857
  priceForTotal,
4627
4858
  provincesForPostCode,
4859
+ registrationPlacesByKind,
4628
4860
  removeFragment,
4629
4861
  resolveFamily,
4630
4862
  resolveModifiersForProduct,
@@ -4634,6 +4866,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
4634
4866
  roundToPrecision,
4635
4867
  sameFamily,
4636
4868
  setOrderState,
4869
+ sha1Hex,
4637
4870
  shipsToCountry,
4638
4871
  shopDayKey,
4639
4872
  shopDayRange,