@simpleapps-com/augur-utils 2026.11.2 → 2026.11.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.cjs CHANGED
@@ -7,46 +7,43 @@ function hasPriceBreaks(libraryPriceData) {
7
7
  return libraryPriceData !== null && Array.isArray(libraryPriceData.breaks);
8
8
  }
9
9
 
10
- // src/cache-config.ts
11
- var CACHE_CONFIG = {
12
- STATIC: {
13
- staleTime: 1e3 * 60 * 60,
14
- // 1 hour
15
- gcTime: 1e3 * 60 * 60 * 24
16
- // 24 hours
17
- },
18
- SEMI_STATIC: {
19
- staleTime: 1e3 * 60 * 10,
20
- // 10 minutes
21
- gcTime: 1e3 * 60 * 60 * 4
22
- // 4 hours
23
- },
24
- DYNAMIC: {
25
- staleTime: 1e3 * 60 * 5,
26
- // 5 minutes
27
- gcTime: 1e3 * 60 * 30
28
- // 30 minutes
29
- },
30
- CART: {
31
- staleTime: 1e3 * 60 * 2,
32
- // 2 minutes
33
- gcTime: 1e3 * 60 * 30
34
- // 30 minutes
35
- },
36
- REALTIME: {
37
- staleTime: 0,
38
- gcTime: 1e3 * 60 * 5
39
- // 5 minutes
40
- }
41
- };
42
-
43
- // src/format-price.ts
44
- function formatPrice(price, locale = "en-US", currency = "USD") {
45
- return new Intl.NumberFormat(locale, {
46
- style: "currency",
47
- currency,
48
- minimumFractionDigits: 2
49
- }).format(price);
10
+ // ../foundation/src/duration.ts
11
+ function seconds(n) {
12
+ return n;
13
+ }
14
+ function minutes(n) {
15
+ return n * 60;
16
+ }
17
+ function hours(n) {
18
+ return n * 3600;
19
+ }
20
+ function days(n) {
21
+ return n * 86400;
22
+ }
23
+ function millis(n) {
24
+ return n;
25
+ }
26
+ function toMillis(d) {
27
+ return d * 1e3;
28
+ }
29
+ function floorSeconds(m) {
30
+ return Math.floor(m / 1e3);
31
+ }
32
+ function addMillis(a, b) {
33
+ return a + b;
34
+ }
35
+ function minusMillis(a, b) {
36
+ return a >= b ? a - b : millis(0);
37
+ }
38
+ function secondsOf(n) {
39
+ return Math.floor(n) === n && n >= 0 && n <= 9007199254740991 ? n : null;
40
+ }
41
+ function wholeSeconds(n) {
42
+ const whole = secondsOf(Math.floor(n));
43
+ return whole === null ? seconds(0) : whole;
44
+ }
45
+ function millisOf(n) {
46
+ return Math.floor(n) === n && n >= 0 && n <= 9007199254740991 ? n : null;
50
47
  }
51
48
 
52
49
  // src/rules.ts
@@ -77,14 +74,14 @@ function pageOffset(page, limit) {
77
74
  function unwrapMessage(error) {
78
75
  return error !== "" ? error : "Action failed";
79
76
  }
80
- function shippingLeadOf(days) {
81
- if (days === "1-2") return { from: 1, to: 4 };
82
- if (days === "2") return { from: 4, to: 0 };
83
- if (days === "2-3") return { from: 2, to: 5 };
84
- if (days === "3") return { from: 5, to: 0 };
85
- if (days === "3-4") return { from: 3, to: 6 };
86
- if (days === "4") return { from: 6, to: 0 };
87
- if (days === "5") return { from: 7, to: 0 };
77
+ function shippingLeadOf(days3) {
78
+ if (days3 === "1-2") return { from: 1, to: 4 };
79
+ if (days3 === "2") return { from: 4, to: 0 };
80
+ if (days3 === "2-3") return { from: 2, to: 5 };
81
+ if (days3 === "3") return { from: 5, to: 0 };
82
+ if (days3 === "3-4") return { from: 3, to: 6 };
83
+ if (days3 === "4") return { from: 6, to: 0 };
84
+ if (days3 === "5") return { from: 7, to: 0 };
88
85
  return null;
89
86
  }
90
87
  function isBusinessDayName(dayName) {
@@ -95,12 +92,89 @@ function availabilityOf(isInStock, isDiscontinued) {
95
92
  if (isDiscontinued) return "OutOfStock";
96
93
  return "BackOrder";
97
94
  }
95
+ function presentIndexFrom(present, i) {
96
+ if (i === present.length) return -1;
97
+ if (present[i] === true) return i;
98
+ return presentIndexFrom(present, i + 1);
99
+ }
100
+ function leadDateText(from, hasTo, to) {
101
+ return hasTo ? from + " - " + to : from;
102
+ }
98
103
  function takerOf(taker) {
99
104
  return _nullishCoalesce(taker, () => ( "ESTORE"));
100
105
  }
101
106
  function addressDifferentOf(line1Same, citySame, stateSame, zipSame) {
102
107
  return !line1Same || !citySame || !stateSame || !zipSame;
103
108
  }
109
+ function gcTimeFor(isServer, clientGcTime) {
110
+ return isServer ? null : clientGcTime;
111
+ }
112
+ function tierStaleTime(t) {
113
+ if (t === "STATIC") return toMillis(hours(1));
114
+ if (t === "SEMI_STATIC") return toMillis(minutes(10));
115
+ if (t === "DYNAMIC") return toMillis(minutes(5));
116
+ if (t === "CART") return toMillis(minutes(2));
117
+ return millis(0);
118
+ }
119
+ function tierBrowserGcTime(t) {
120
+ if (t === "STATIC") return toMillis(hours(24));
121
+ if (t === "SEMI_STATIC") return toMillis(hours(4));
122
+ if (t === "DYNAMIC") return toMillis(minutes(30));
123
+ if (t === "CART") return toMillis(minutes(30));
124
+ return toMillis(minutes(5));
125
+ }
126
+ function serverRuntimeOf(hasWindow, hasDeno) {
127
+ return !hasWindow || hasDeno;
128
+ }
129
+
130
+ // src/runtime.ts
131
+ function isServerRuntime() {
132
+ const hasWindow = typeof globalThis.window !== "undefined";
133
+ return serverRuntimeOf(hasWindow, "Deno" in globalThis);
134
+ }
135
+ function resolveGcTime(clientGcTime) {
136
+ return _nullishCoalesce(gcTimeFor(isServerRuntime(), clientGcTime), () => ( Infinity));
137
+ }
138
+
139
+ // src/cache-config.ts
140
+ function tier(name) {
141
+ return {
142
+ staleTime: tierStaleTime(name),
143
+ get gcTime() {
144
+ return resolveGcTime(tierBrowserGcTime(name));
145
+ }
146
+ };
147
+ }
148
+ var CACHE_CONFIG = {
149
+ STATIC: tier("STATIC"),
150
+ SEMI_STATIC: tier("SEMI_STATIC"),
151
+ DYNAMIC: tier("DYNAMIC"),
152
+ CART: tier("CART"),
153
+ REALTIME: tier("REALTIME")
154
+ };
155
+
156
+ // src/duration.ts
157
+ var seconds2 = seconds;
158
+ var minutes2 = minutes;
159
+ var hours2 = hours;
160
+ var days2 = days;
161
+ var millis2 = millis;
162
+ var toMillis2 = toMillis;
163
+ var addMillis2 = addMillis;
164
+ var minusMillis2 = minusMillis;
165
+ var floorSeconds2 = floorSeconds;
166
+ var secondsOf2 = secondsOf;
167
+ var wholeSeconds2 = wholeSeconds;
168
+ var millisOf2 = millisOf;
169
+
170
+ // src/format-price.ts
171
+ function formatPrice(price, locale = "en-US", currency = "USD") {
172
+ return new Intl.NumberFormat(locale, {
173
+ style: "currency",
174
+ currency,
175
+ minimumFractionDigits: 2
176
+ }).format(price);
177
+ }
104
178
 
105
179
  // src/address-comparison.ts
106
180
  function isAddressDifferent(userAddress, smartyAddress) {
@@ -125,11 +199,12 @@ function getPaymentStatus(invoice) {
125
199
  function str(value) {
126
200
  return String(value).trim();
127
201
  }
202
+ function presence(raw, keys) {
203
+ return keys.map((k) => raw[k] != null);
204
+ }
128
205
  function firstPresent(raw, keys) {
129
- for (const k of keys) {
130
- if (raw[k] != null) return raw[k];
131
- }
132
- return "";
206
+ const index = presentIndexFrom(presence(raw, keys), 0);
207
+ return index < 0 ? "" : raw[keys[index]];
133
208
  }
134
209
  function pick(raw, keys) {
135
210
  return str(firstPresent(raw, keys));
@@ -159,7 +234,7 @@ var MAIL_FIELDS = {
159
234
  country: ["mailCountry", "mail_country", "country"]
160
235
  };
161
236
  function transformShipToAddress(raw) {
162
- const isPhys = PHYS_MARKERS.some((k) => raw[k] != null);
237
+ const isPhys = presentIndexFrom(presence(raw, PHYS_MARKERS), 0) >= 0;
163
238
  const f = isPhys ? PHYS_FIELDS : MAIL_FIELDS;
164
239
  const address = {
165
240
  shipToId: firstPresent(raw, ["shipToId", "ship_to_id", "id"]),
@@ -176,6 +251,48 @@ function transformShipToAddress(raw) {
176
251
  return address;
177
252
  }
178
253
 
254
+ // ../utils/src/strings.ts
255
+ function codeAt(s, i) {
256
+ return i >= 0 && i < s.length ? s.charCodeAt(i) : -1;
257
+ }
258
+ function indexOfCode(s, code, from) {
259
+ const c = codeAt(s, from);
260
+ if (c === code) return from;
261
+ if (c === -1) return -1;
262
+ return indexOfCode(s, code, from + 1);
263
+ }
264
+ function startsWithAt(s, x, pos) {
265
+ const at = Math.min(pos, s.length);
266
+ return s.slice(at, Math.min(at + x.length, s.length)) === x;
267
+ }
268
+ function isBlank(s) {
269
+ return s.trim() === "";
270
+ }
271
+
272
+ // src/cart-line-rules.ts
273
+ function lineHasQuantity(quantity) {
274
+ return quantity !== null;
275
+ }
276
+ function priceQueryRuns(hasCustomer, hasItemId, quantity) {
277
+ return hasCustomer && hasItemId && lineHasQuantity(quantity);
278
+ }
279
+ function priceQueryUnit(unitOfMeasure) {
280
+ return unitOfMeasure !== null && !isBlank(unitOfMeasure) ? unitOfMeasure : null;
281
+ }
282
+ function pricingSettledFrom(succeeded, runs, i) {
283
+ if (i === succeeded.length) return true;
284
+ if (runs[i] === true && succeeded[i] !== true) return false;
285
+ return pricingSettledFrom(succeeded, runs, i + 1);
286
+ }
287
+ function pricingLoadingFrom(loading, runs, i) {
288
+ if (i === loading.length) return false;
289
+ if (runs[i] === true && loading[i] === true) return true;
290
+ return pricingLoadingFrom(loading, runs, i + 1);
291
+ }
292
+ function linePriceAt(unitPrices, i) {
293
+ return i < unitPrices.length ? unitPrices[i] : 0;
294
+ }
295
+
179
296
  // src/build-checkout-payload.ts
180
297
  function buildCheckoutPayload(input) {
181
298
  const oe_hdr = {
@@ -310,21 +427,6 @@ var SCHEMA_URLS = {
310
427
  BackOrder: "https://schema.org/BackOrder"
311
428
  };
312
429
 
313
- // ../utils/src/strings.ts
314
- function codeAt(s, i) {
315
- return i >= 0 && i < s.length ? s.charCodeAt(i) : -1;
316
- }
317
- function indexOfCode(s, code, from) {
318
- const c = codeAt(s, from);
319
- if (c === code) return from;
320
- if (c === -1) return -1;
321
- return indexOfCode(s, code, from + 1);
322
- }
323
- function startsWithAt(s, x, pos) {
324
- const at = Math.min(pos, s.length);
325
- return s.slice(at, Math.min(at + x.length, s.length)) === x;
326
- }
327
-
328
430
  // ../utils/src/lists.ts
329
431
  function joinFrom(xs, sep, i) {
330
432
  if (i >= xs.length) return "";
@@ -443,7 +545,7 @@ function jsonArray(items) {
443
545
  return "[" + joinFrom(items, ",", 0) + "]";
444
546
  }
445
547
 
446
- // ../utils/src/decimal.ts
548
+ // ../foundation/src/decimal.ts
447
549
  function decimal(n) {
448
550
  const last = "0123456789".slice(n % 10, n % 10 + 1);
449
551
  return n < 10 ? last : decimal(Math.floor(n / 10)) + last;
@@ -946,15 +1048,11 @@ function getBusinessDay(businessDaysFromNow) {
946
1048
  }
947
1049
  return businessDays[businessDays.length - 1] || "";
948
1050
  }
949
- function getShippingLeadDate(days) {
950
- const config = shippingLeadOf(days);
1051
+ function getShippingLeadDate(days3) {
1052
+ const config = shippingLeadOf(days3);
951
1053
  if (!config) return "";
952
- const fromDate = getBusinessDay(config.from);
953
- if (config.to) {
954
- const toDate = getBusinessDay(config.to);
955
- return `${fromDate} - ${toDate}`;
956
- }
957
- return fromDate;
1054
+ const hasTo = config.to !== 0;
1055
+ return leadDateText(getBusinessDay(config.from), hasTo, hasTo ? getBusinessDay(config.to) : "");
958
1056
  }
959
1057
 
960
1058
  // src/transforms.ts
@@ -1048,13 +1146,13 @@ function trackViewItem({
1048
1146
  function buildTrackingData({
1049
1147
  cartLines,
1050
1148
  itemDetails,
1051
- getUnitPrice,
1149
+ getLineUnitPrice,
1052
1150
  currency = "USD"
1053
1151
  }) {
1054
1152
  let total = 0;
1055
1153
  const items = cartLines.map((line, index) => {
1056
1154
  const details = itemDetails[line.itemId];
1057
- const price = getUnitPrice(line.itemId);
1155
+ const price = getLineUnitPrice(index);
1058
1156
  total = cleanMoney(total + cleanMoney(price * line.quantity));
1059
1157
  return {
1060
1158
  item_id: line.itemId,
@@ -1135,5 +1233,27 @@ function pushTrackingData(data) {
1135
1233
 
1136
1234
 
1137
1235
 
1138
- exports.BLUR_DATA_URL = BLUR_DATA_URL; exports.BillingAddressInvoiceSchema = BillingAddressInvoiceSchema; exports.BillingAddressSchema = BillingAddressSchema; exports.CACHE_CONFIG = CACHE_CONFIG; exports.CONTIGUOUS_STATES = CONTIGUOUS_STATES; exports.ShippingAddressSchema = ShippingAddressSchema; exports.US_STATES = US_STATES; exports.US_STATES_FULL = US_STATES_FULL; exports.US_TERRITORIES = US_TERRITORIES; exports.VALIDATION_PATTERNS = VALIDATION_PATTERNS; exports.breadcrumbLd = breadcrumbLd2; exports.buildCheckoutPayload = buildCheckoutPayload; exports.buildImageLoader = buildImageLoader; exports.buildTrackingData = buildTrackingData; exports.categorySortBy = categorySortBy; exports.cleanMoney = cleanMoney; exports.cn = _chunk5UMFBGVAcjs.cn; exports.createImageConfig = createImageConfig; exports.derivePrice = derivePrice; exports.faqLd = faqLd2; exports.formatPrice = formatPrice; exports.generateBreadcrumbJsonLd = generateBreadcrumbJsonLd; exports.generateProductJsonLd = generateProductJsonLd; exports.getBusinessDay = getBusinessDay; exports.getDefaultImageUrl = getDefaultImageUrl; exports.getImageSrcSet = getImageSrcSet; exports.getImageUrl = getImageUrl; exports.getPaymentStatus = getPaymentStatus; exports.getSchemaAvailability = getSchemaAvailability; exports.getShippingLeadDate = getShippingLeadDate; exports.hasPriceBreaks = hasPriceBreaks; exports.idRef = idRef2; exports.isAddressDifferent = isAddressDifferent; exports.nodeHead = nodeHead2; exports.normalizePath = normalizePath; exports.paginateOffset = paginateOffset; exports.pushTrackingData = pushTrackingData; exports.resolveStock = resolveStock; exports.roundHalfAway = roundHalfAway; exports.sanitizeHtmlImages = sanitizeHtmlImages; exports.serializeCategoryFilters = serializeCategoryFilters; exports.serializeSearchParams = serializeSearchParams; exports.serializeTransforms = serializeTransforms; exports.trackAddToCart = trackAddToCart; exports.trackViewItem = trackViewItem; exports.transformShipToAddress = transformShipToAddress; exports.unwrap = unwrap; exports.unwrapOr = unwrapOr;
1236
+
1237
+
1238
+
1239
+
1240
+
1241
+
1242
+
1243
+
1244
+
1245
+
1246
+
1247
+
1248
+
1249
+
1250
+
1251
+
1252
+
1253
+
1254
+
1255
+
1256
+
1257
+
1258
+ exports.BLUR_DATA_URL = BLUR_DATA_URL; exports.BillingAddressInvoiceSchema = BillingAddressInvoiceSchema; exports.BillingAddressSchema = BillingAddressSchema; exports.CACHE_CONFIG = CACHE_CONFIG; exports.CONTIGUOUS_STATES = CONTIGUOUS_STATES; exports.ShippingAddressSchema = ShippingAddressSchema; exports.US_STATES = US_STATES; exports.US_STATES_FULL = US_STATES_FULL; exports.US_TERRITORIES = US_TERRITORIES; exports.VALIDATION_PATTERNS = VALIDATION_PATTERNS; exports.addMillis = addMillis2; exports.breadcrumbLd = breadcrumbLd2; exports.buildCheckoutPayload = buildCheckoutPayload; exports.buildImageLoader = buildImageLoader; exports.buildTrackingData = buildTrackingData; exports.categorySortBy = categorySortBy; exports.cleanMoney = cleanMoney; exports.cn = _chunk5UMFBGVAcjs.cn; exports.createImageConfig = createImageConfig; exports.days = days2; exports.derivePrice = derivePrice; exports.faqLd = faqLd2; exports.floorSeconds = floorSeconds2; exports.formatPrice = formatPrice; exports.generateBreadcrumbJsonLd = generateBreadcrumbJsonLd; exports.generateProductJsonLd = generateProductJsonLd; exports.getBusinessDay = getBusinessDay; exports.getDefaultImageUrl = getDefaultImageUrl; exports.getImageSrcSet = getImageSrcSet; exports.getImageUrl = getImageUrl; exports.getPaymentStatus = getPaymentStatus; exports.getSchemaAvailability = getSchemaAvailability; exports.getShippingLeadDate = getShippingLeadDate; exports.hasPriceBreaks = hasPriceBreaks; exports.hours = hours2; exports.idRef = idRef2; exports.isAddressDifferent = isAddressDifferent; exports.isServerRuntime = isServerRuntime; exports.lineHasQuantity = lineHasQuantity; exports.linePriceAt = linePriceAt; exports.millis = millis2; exports.millisOf = millisOf2; exports.minusMillis = minusMillis2; exports.minutes = minutes2; exports.nodeHead = nodeHead2; exports.normalizePath = normalizePath; exports.paginateOffset = paginateOffset; exports.priceQueryRuns = priceQueryRuns; exports.priceQueryUnit = priceQueryUnit; exports.pricingLoadingFrom = pricingLoadingFrom; exports.pricingSettledFrom = pricingSettledFrom; exports.pushTrackingData = pushTrackingData; exports.resolveGcTime = resolveGcTime; exports.resolveStock = resolveStock; exports.roundHalfAway = roundHalfAway; exports.sanitizeHtmlImages = sanitizeHtmlImages; exports.seconds = seconds2; exports.secondsOf = secondsOf2; exports.serializeCategoryFilters = serializeCategoryFilters; exports.serializeSearchParams = serializeSearchParams; exports.serializeTransforms = serializeTransforms; exports.tierBrowserGcTime = tierBrowserGcTime; exports.tierStaleTime = tierStaleTime; exports.toMillis = toMillis2; exports.trackAddToCart = trackAddToCart; exports.trackViewItem = trackViewItem; exports.transformShipToAddress = transformShipToAddress; exports.unwrap = unwrap; exports.unwrapOr = unwrapOr; exports.wholeSeconds = wholeSeconds2;
1139
1259
  //# sourceMappingURL=index.cjs.map