@simpleapps-com/augur-utils 2026.11.4 → 2026.11.5

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
@@ -251,6 +251,14 @@ function transformShipToAddress(raw) {
251
251
  return address;
252
252
  }
253
253
 
254
+ // ../foundation/src/chars.ts
255
+ function isDigit(c) {
256
+ return c >= 48 && c <= 57;
257
+ }
258
+ function lowerCode(c) {
259
+ return c >= 65 && c <= 90 ? c + 32 : c;
260
+ }
261
+
254
262
  // ../utils/src/strings.ts
255
263
  function codeAt(s, i) {
256
264
  return i >= 0 && i < s.length ? s.charCodeAt(i) : -1;
@@ -265,6 +273,23 @@ function startsWithAt(s, x, pos) {
265
273
  const at = Math.min(pos, s.length);
266
274
  return s.slice(at, Math.min(at + x.length, s.length)) === x;
267
275
  }
276
+ function lowerAscii(s) {
277
+ if (s.length === 0) return "";
278
+ const c = s.charCodeAt(0);
279
+ const head = c >= 65 && c <= 90 ? "abcdefghijklmnopqrstuvwxyz".slice(c - 65, c - 64) : s.slice(0, 1);
280
+ return head + lowerAscii(s.slice(1));
281
+ }
282
+ function caselessFrom(s, x, pos, k) {
283
+ if (k === x.length) return true;
284
+ return lowerCode(codeAt(s, pos + k)) === x.charCodeAt(k) && caselessFrom(s, x, pos, k + 1);
285
+ }
286
+ function startsWithCaseless(s, x, pos) {
287
+ return pos <= s.length && caselessFrom(s, x, pos, 0);
288
+ }
289
+ function digitsValue(s) {
290
+ if (s.length === 0) return 0;
291
+ return digitsValue(s.slice(0, s.length - 1)) * 10 + (s.charCodeAt(s.length - 1) - 48);
292
+ }
268
293
  function isBlank(s) {
269
294
  return s.trim() === "";
270
295
  }
@@ -293,6 +318,47 @@ function linePriceAt(unitPrices, i) {
293
318
  return i < unitPrices.length ? unitPrices[i] : 0;
294
319
  }
295
320
 
321
+ // ../foundation/src/pos-digits.ts
322
+ function posDigitsFrom(s, i, nonZero) {
323
+ if (i === s.length) return nonZero;
324
+ const c = s.charCodeAt(i);
325
+ if (!isDigit(c)) return false;
326
+ return posDigitsFrom(s, i + 1, nonZero || c !== 48);
327
+ }
328
+ function isPosDigits(s) {
329
+ return posDigitsFrom(s, 0, false);
330
+ }
331
+
332
+ // ../foundation/src/pos-int.ts
333
+ function posIntOf(n) {
334
+ return Math.floor(n) === n && n >= 1 && n <= 9007199254740991 ? n : null;
335
+ }
336
+
337
+ // src/address-id.ts
338
+ function addressIdOfText(s) {
339
+ const t = s.trim();
340
+ if (!isPosDigits(t)) return null;
341
+ const v2 = digitsValue(t);
342
+ return v2 >= 1 && v2 <= 9007199254740991 ? v2 : null;
343
+ }
344
+ function firstAddressIdFrom(ids, i) {
345
+ if (i === ids.length) return null;
346
+ const id = ids[i];
347
+ if (id !== null) return id;
348
+ return firstAddressIdFrom(ids, i + 1);
349
+ }
350
+ function addressIdOf(value) {
351
+ if (typeof value === "number") return posIntOf(value);
352
+ if (typeof value === "string") return addressIdOfText(value);
353
+ return null;
354
+ }
355
+ function isUsableAddressId(value) {
356
+ return addressIdOf(value) !== null;
357
+ }
358
+ function resolveAddressId(...candidates) {
359
+ return firstAddressIdFrom(candidates.map(addressIdOf), 0);
360
+ }
361
+
296
362
  // src/build-checkout-payload.ts
297
363
  function buildCheckoutPayload(input) {
298
364
  const oe_hdr = {
@@ -796,7 +862,8 @@ function serializedTransforms(fields, present, texts) {
796
862
  return joinFrom(transformPartsFrom(fields, present, texts, 0), ",", 0);
797
863
  }
798
864
  function isExternal(path) {
799
- return startsWithAt(path, "http", 0);
865
+ if (startsWithCaseless(path, "https://", 0)) return true;
866
+ return startsWithAt(path, "//", 0);
800
867
  }
801
868
  function stripFirstPrefixFrom(path, prefixes, i) {
802
869
  if (i >= prefixes.length) return path;
@@ -808,27 +875,85 @@ function stripLeadingSlashes(s) {
808
875
  if (codeAt(s, 0) !== 47) return s;
809
876
  return stripLeadingSlashes(s.slice(1));
810
877
  }
811
- function normalizedPath(raw, prefixes, defaultPath) {
812
- if (isExternal(raw)) return raw;
878
+ function localPath(raw, prefixes, defaultPath) {
813
879
  const cleaned = stripLeadingSlashes(stripFirstPrefixFrom(raw, prefixes, 0));
814
880
  if (defaultPath !== "" && indexOfCode(cleaned, 47, 0) < 0) return defaultPath + "/" + cleaned;
815
881
  return cleaned;
816
882
  }
883
+ function isInsecure(s) {
884
+ return startsWithCaseless(s, "http://", 0);
885
+ }
886
+ function schemeEnd(raw) {
887
+ if (startsWithCaseless(raw, "https://", 0)) return 8;
888
+ return startsWithAt(raw, "//", 0) ? 2 : 0;
889
+ }
890
+ function slashAt(o) {
891
+ const k = indexOfCode(o, 47, 0);
892
+ return k < 0 ? o.length : k;
893
+ }
894
+ function ownOriginAt(raw, o, at) {
895
+ const cut = slashAt(o);
896
+ if (cut === 0) return false;
897
+ if (!startsWithCaseless(raw, lowerAscii(o.slice(0, cut)), at)) return false;
898
+ if (!startsWithAt(raw, o.slice(cut), at + cut)) return false;
899
+ return codeAt(raw, at + o.length) === 47;
900
+ }
901
+ function ownOriginRestFrom(raw, origins, i) {
902
+ const at = schemeEnd(raw);
903
+ if (at === 0 || i >= origins.length) return null;
904
+ const o = origins[i];
905
+ if (ownOriginAt(raw, o, at)) {
906
+ const path = stripLeadingSlashes(raw.slice(at + o.length));
907
+ return path === "" ? null : path;
908
+ }
909
+ return ownOriginRestFrom(raw, origins, i + 1);
910
+ }
911
+ function defaultOwnOrigins(clientDomain) {
912
+ return ["images." + clientDomain, "www." + clientDomain + "/images", clientDomain + "/images"];
913
+ }
914
+ function normalizedPath(raw, prefixes, origins, defaultPath) {
915
+ if (isInsecure(raw)) return "";
916
+ const own = ownOriginRestFrom(raw, origins, 0);
917
+ if (own !== null) return own;
918
+ if (isExternal(raw)) return raw;
919
+ const local = localPath(raw, prefixes, defaultPath);
920
+ return isInsecure(local) ? "" : local;
921
+ }
817
922
  function cdnUrlOf(clientDomain, serialized, normalized) {
818
923
  const segment = serialized !== "" ? "/" + serialized : "";
819
924
  return "https://agr.media/" + clientDomain + "/images" + segment + "/" + normalized;
820
925
  }
821
- function defaultImageUrlOf(clientDomain, fallback, prefixes, defaultPath) {
822
- if (fallback === "") return "";
823
- const normalized = normalizedPath(fallback, prefixes, defaultPath);
824
- if (isExternal(normalized)) return normalized;
825
- return "https://agr.media/" + clientDomain + "/images/" + normalized;
826
- }
827
- function imageUrlOf(clientDomain, path, serialized, fallback, prefixes, defaultPath) {
828
- if (path === "") return defaultImageUrlOf(clientDomain, fallback, prefixes, defaultPath);
829
- const normalized = normalizedPath(path, prefixes, defaultPath);
830
- if (isExternal(normalized)) return normalized;
831
- return cdnUrlOf(clientDomain, serialized, normalized);
926
+ function srcSetPartsFrom(urls, widths, i) {
927
+ if (i >= urls.length) return [];
928
+ const url = urls[i];
929
+ const rest = srcSetPartsFrom(urls, widths, i + 1);
930
+ return url === "" ? rest : [url + " " + widths[i] + "w", ...rest];
931
+ }
932
+ function srcSetOf(urls, widths) {
933
+ return joinFrom(srcSetPartsFrom(urls, widths, 0), ", ", 0);
934
+ }
935
+ function defaultImageUrlOf(clientDomain, fallback, prefixes, origins, defaultPath) {
936
+ if (fallback === "" || isInsecure(fallback)) return "";
937
+ const own = ownOriginRestFrom(fallback, origins, 0);
938
+ if (own !== null) return "https://agr.media/" + clientDomain + "/images/" + own;
939
+ if (isExternal(fallback)) return fallback;
940
+ const local = localPath(fallback, prefixes, defaultPath);
941
+ if (isInsecure(local)) return "";
942
+ if (isExternal(local)) return local;
943
+ return "https://agr.media/" + clientDomain + "/images/" + local;
944
+ }
945
+ function imageUrlOf(clientDomain, path, serialized, fallback, prefixes, origins, defaultPath) {
946
+ if (path === "" || isInsecure(path)) {
947
+ return defaultImageUrlOf(clientDomain, fallback, prefixes, origins, defaultPath);
948
+ }
949
+ const own = ownOriginRestFrom(path, origins, 0);
950
+ if (own !== null) return cdnUrlOf(clientDomain, serialized, own);
951
+ if (isExternal(path)) return path;
952
+ const local = localPath(path, prefixes, defaultPath);
953
+ if (isInsecure(local))
954
+ return defaultImageUrlOf(clientDomain, fallback, prefixes, origins, defaultPath);
955
+ if (isExternal(local)) return local;
956
+ return cdnUrlOf(clientDomain, serialized, local);
832
957
  }
833
958
 
834
959
  // src/image.ts
@@ -840,7 +965,8 @@ function createImageConfig(clientDomain, opts) {
840
965
  defaultImage: _optionalChain([opts, 'optionalAccess', _29 => _29.defaultImage]),
841
966
  defaultTransforms: _optionalChain([opts, 'optionalAccess', _30 => _30.defaultTransforms]),
842
967
  stripPrefixes: _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _31 => _31.stripPrefixes]), () => ( DEFAULT_STRIP_PREFIXES)),
843
- defaultPath: _optionalChain([opts, 'optionalAccess', _32 => _32.defaultPath])
968
+ defaultPath: _optionalChain([opts, 'optionalAccess', _32 => _32.defaultPath]),
969
+ ownOrigins: _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _33 => _33.ownOrigins]), () => ( defaultOwnOrigins(clientDomain)))
844
970
  });
845
971
  }
846
972
  function serializeTransforms(transforms) {
@@ -852,11 +978,14 @@ function serializeTransforms(transforms) {
852
978
  );
853
979
  }
854
980
  function normalizePath(config, raw) {
855
- return normalizedPath(raw, prefixesOf(config), _nullishCoalesce(config.defaultPath, () => ( "")));
981
+ return normalizedPath(raw, prefixesOf(config), originsOf(config), _nullishCoalesce(config.defaultPath, () => ( "")));
856
982
  }
857
983
  function prefixesOf(config) {
858
984
  return _nullishCoalesce(config.stripPrefixes, () => ( DEFAULT_STRIP_PREFIXES));
859
985
  }
986
+ function originsOf(config) {
987
+ return _nullishCoalesce(config.ownOrigins, () => ( defaultOwnOrigins(config.clientDomain)));
988
+ }
860
989
  function getImageUrl(config, imagePath, transforms, options) {
861
990
  const merged = {
862
991
  ...config.defaultTransforms,
@@ -864,10 +993,11 @@ function getImageUrl(config, imagePath, transforms, options) {
864
993
  };
865
994
  return imageUrlOf(
866
995
  config.clientDomain,
867
- _nullishCoalesce(_optionalChain([imagePath, 'optionalAccess', _33 => _33.trim, 'call', _34 => _34()]), () => ( "")),
996
+ _nullishCoalesce(_optionalChain([imagePath, 'optionalAccess', _34 => _34.trim, 'call', _35 => _35()]), () => ( "")),
868
997
  serializeTransforms(merged),
869
998
  fallbackOf(config, options),
870
999
  prefixesOf(config),
1000
+ originsOf(config),
871
1001
  _nullishCoalesce(config.defaultPath, () => ( ""))
872
1002
  );
873
1003
  }
@@ -876,17 +1006,18 @@ function getDefaultImageUrl(config, options) {
876
1006
  config.clientDomain,
877
1007
  fallbackOf(config, options),
878
1008
  prefixesOf(config),
1009
+ originsOf(config),
879
1010
  _nullishCoalesce(config.defaultPath, () => ( ""))
880
1011
  );
881
1012
  }
882
1013
  function fallbackOf(config, options) {
883
- return _nullishCoalesce(_nullishCoalesce(_optionalChain([options, 'optionalAccess', _35 => _35.defaultImage]), () => ( config.defaultImage)), () => ( ""));
1014
+ return _nullishCoalesce(_nullishCoalesce(_optionalChain([options, 'optionalAccess', _36 => _36.defaultImage]), () => ( config.defaultImage)), () => ( ""));
884
1015
  }
885
1016
  function getImageSrcSet(config, imagePath, widths, transforms) {
886
- return widths.map((w) => {
887
- const url = getImageUrl(config, imagePath, { ...transforms, width: w });
888
- return `${url} ${w}w`;
889
- }).join(", ");
1017
+ return srcSetOf(
1018
+ widths.map((width) => getImageUrl(config, imagePath, { ...transforms, width })),
1019
+ widths.map(String)
1020
+ );
890
1021
  }
891
1022
  function buildImageLoader(config, transforms) {
892
1023
  return ({ src, width, quality }) => {
@@ -1080,7 +1211,7 @@ function serializeSearchParams(filters, options) {
1080
1211
  from: filters.offset,
1081
1212
  sortBy: searchSortBy(filters.sortBy),
1082
1213
  classId5List: categoryUid ? String(categoryUid) : void 0,
1083
- filters: _optionalChain([filters, 'access', _36 => _36.filters, 'optionalAccess', _37 => _37.length]) ? JSON.stringify(filters.filters) : void 0,
1214
+ filters: _optionalChain([filters, 'access', _37 => _37.filters, 'optionalAccess', _38 => _38.length]) ? JSON.stringify(filters.filters) : void 0,
1084
1215
  sourceFieldsList: sourceFields
1085
1216
  };
1086
1217
  }
@@ -1156,10 +1287,10 @@ function buildTrackingData({
1156
1287
  total = cleanMoney(total + cleanMoney(price * line.quantity));
1157
1288
  return {
1158
1289
  item_id: line.itemId,
1159
- item_name: _nullishCoalesce(_optionalChain([details, 'optionalAccess', _38 => _38.itemDesc]), () => ( "")),
1290
+ item_name: _nullishCoalesce(_optionalChain([details, 'optionalAccess', _39 => _39.itemDesc]), () => ( "")),
1160
1291
  currency,
1161
1292
  index,
1162
- item_category: _nullishCoalesce(_optionalChain([details, 'optionalAccess', _39 => _39.classId5]), () => ( "")),
1293
+ item_category: _nullishCoalesce(_optionalChain([details, 'optionalAccess', _40 => _40.classId5]), () => ( "")),
1163
1294
  price,
1164
1295
  quantity: line.quantity
1165
1296
  };
@@ -1255,5 +1386,10 @@ function pushTrackingData(data) {
1255
1386
 
1256
1387
 
1257
1388
 
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;
1389
+
1390
+
1391
+
1392
+
1393
+
1394
+ 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.addressIdOf = addressIdOf; exports.addressIdOfText = addressIdOfText; 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.firstAddressIdFrom = firstAddressIdFrom; 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.isUsableAddressId = isUsableAddressId; 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.resolveAddressId = resolveAddressId; 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;
1259
1395
  //# sourceMappingURL=index.cjs.map