@simpleapps-com/augur-utils 2026.11.4 → 2026.11.6

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 = {
@@ -760,6 +826,22 @@ function generateProductJsonLd(doc, options) {
760
826
  return JSON.stringify(omitEmpty(merged));
761
827
  }
762
828
 
829
+ // src/log-line.ts
830
+ function logLineOf(context, errorName) {
831
+ if (errorName === "") return context;
832
+ return context + ": " + errorName;
833
+ }
834
+ function errorNameOf(hasType, typeName, name) {
835
+ if (hasType && typeName !== "") return typeName;
836
+ return name;
837
+ }
838
+ function errorLogLine(context, error) {
839
+ if (!(error instanceof Error)) return logLineOf(context, "");
840
+ const type = error.type;
841
+ const hasType = typeof type === "string";
842
+ return logLineOf(context, errorNameOf(hasType, hasType ? type : "", error.name));
843
+ }
844
+
763
845
  // src/result.ts
764
846
  function unwrap(result) {
765
847
  if (!result.ok) throw new Error(unwrapMessage(result.error));
@@ -796,7 +878,8 @@ function serializedTransforms(fields, present, texts) {
796
878
  return joinFrom(transformPartsFrom(fields, present, texts, 0), ",", 0);
797
879
  }
798
880
  function isExternal(path) {
799
- return startsWithAt(path, "http", 0);
881
+ if (startsWithCaseless(path, "https://", 0)) return true;
882
+ return startsWithAt(path, "//", 0);
800
883
  }
801
884
  function stripFirstPrefixFrom(path, prefixes, i) {
802
885
  if (i >= prefixes.length) return path;
@@ -808,27 +891,85 @@ function stripLeadingSlashes(s) {
808
891
  if (codeAt(s, 0) !== 47) return s;
809
892
  return stripLeadingSlashes(s.slice(1));
810
893
  }
811
- function normalizedPath(raw, prefixes, defaultPath) {
812
- if (isExternal(raw)) return raw;
894
+ function localPath(raw, prefixes, defaultPath) {
813
895
  const cleaned = stripLeadingSlashes(stripFirstPrefixFrom(raw, prefixes, 0));
814
896
  if (defaultPath !== "" && indexOfCode(cleaned, 47, 0) < 0) return defaultPath + "/" + cleaned;
815
897
  return cleaned;
816
898
  }
899
+ function isInsecure(s) {
900
+ return startsWithCaseless(s, "http://", 0);
901
+ }
902
+ function schemeEnd(raw) {
903
+ if (startsWithCaseless(raw, "https://", 0)) return 8;
904
+ return startsWithAt(raw, "//", 0) ? 2 : 0;
905
+ }
906
+ function slashAt(o) {
907
+ const k = indexOfCode(o, 47, 0);
908
+ return k < 0 ? o.length : k;
909
+ }
910
+ function ownOriginAt(raw, o, at) {
911
+ const cut = slashAt(o);
912
+ if (cut === 0) return false;
913
+ if (!startsWithCaseless(raw, lowerAscii(o.slice(0, cut)), at)) return false;
914
+ if (!startsWithAt(raw, o.slice(cut), at + cut)) return false;
915
+ return codeAt(raw, at + o.length) === 47;
916
+ }
917
+ function ownOriginRestFrom(raw, origins, i) {
918
+ const at = schemeEnd(raw);
919
+ if (at === 0 || i >= origins.length) return null;
920
+ const o = origins[i];
921
+ if (ownOriginAt(raw, o, at)) {
922
+ const path = stripLeadingSlashes(raw.slice(at + o.length));
923
+ return path === "" ? null : path;
924
+ }
925
+ return ownOriginRestFrom(raw, origins, i + 1);
926
+ }
927
+ function defaultOwnOrigins(clientDomain) {
928
+ return ["images." + clientDomain, "www." + clientDomain + "/images", clientDomain + "/images"];
929
+ }
930
+ function normalizedPath(raw, prefixes, origins, defaultPath) {
931
+ if (isInsecure(raw)) return "";
932
+ const own = ownOriginRestFrom(raw, origins, 0);
933
+ if (own !== null) return own;
934
+ if (isExternal(raw)) return raw;
935
+ const local = localPath(raw, prefixes, defaultPath);
936
+ return isInsecure(local) ? "" : local;
937
+ }
817
938
  function cdnUrlOf(clientDomain, serialized, normalized) {
818
939
  const segment = serialized !== "" ? "/" + serialized : "";
819
940
  return "https://agr.media/" + clientDomain + "/images" + segment + "/" + normalized;
820
941
  }
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);
942
+ function srcSetPartsFrom(urls, widths, i) {
943
+ if (i >= urls.length) return [];
944
+ const url = urls[i];
945
+ const rest = srcSetPartsFrom(urls, widths, i + 1);
946
+ return url === "" ? rest : [url + " " + widths[i] + "w", ...rest];
947
+ }
948
+ function srcSetOf(urls, widths) {
949
+ return joinFrom(srcSetPartsFrom(urls, widths, 0), ", ", 0);
950
+ }
951
+ function defaultImageUrlOf(clientDomain, fallback, prefixes, origins, defaultPath) {
952
+ if (fallback === "" || isInsecure(fallback)) return "";
953
+ const own = ownOriginRestFrom(fallback, origins, 0);
954
+ if (own !== null) return "https://agr.media/" + clientDomain + "/images/" + own;
955
+ if (isExternal(fallback)) return fallback;
956
+ const local = localPath(fallback, prefixes, defaultPath);
957
+ if (isInsecure(local)) return "";
958
+ if (isExternal(local)) return local;
959
+ return "https://agr.media/" + clientDomain + "/images/" + local;
960
+ }
961
+ function imageUrlOf(clientDomain, path, serialized, fallback, prefixes, origins, defaultPath) {
962
+ if (path === "" || isInsecure(path)) {
963
+ return defaultImageUrlOf(clientDomain, fallback, prefixes, origins, defaultPath);
964
+ }
965
+ const own = ownOriginRestFrom(path, origins, 0);
966
+ if (own !== null) return cdnUrlOf(clientDomain, serialized, own);
967
+ if (isExternal(path)) return path;
968
+ const local = localPath(path, prefixes, defaultPath);
969
+ if (isInsecure(local))
970
+ return defaultImageUrlOf(clientDomain, fallback, prefixes, origins, defaultPath);
971
+ if (isExternal(local)) return local;
972
+ return cdnUrlOf(clientDomain, serialized, local);
832
973
  }
833
974
 
834
975
  // src/image.ts
@@ -840,7 +981,8 @@ function createImageConfig(clientDomain, opts) {
840
981
  defaultImage: _optionalChain([opts, 'optionalAccess', _29 => _29.defaultImage]),
841
982
  defaultTransforms: _optionalChain([opts, 'optionalAccess', _30 => _30.defaultTransforms]),
842
983
  stripPrefixes: _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _31 => _31.stripPrefixes]), () => ( DEFAULT_STRIP_PREFIXES)),
843
- defaultPath: _optionalChain([opts, 'optionalAccess', _32 => _32.defaultPath])
984
+ defaultPath: _optionalChain([opts, 'optionalAccess', _32 => _32.defaultPath]),
985
+ ownOrigins: _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _33 => _33.ownOrigins]), () => ( defaultOwnOrigins(clientDomain)))
844
986
  });
845
987
  }
846
988
  function serializeTransforms(transforms) {
@@ -852,11 +994,14 @@ function serializeTransforms(transforms) {
852
994
  );
853
995
  }
854
996
  function normalizePath(config, raw) {
855
- return normalizedPath(raw, prefixesOf(config), _nullishCoalesce(config.defaultPath, () => ( "")));
997
+ return normalizedPath(raw, prefixesOf(config), originsOf(config), _nullishCoalesce(config.defaultPath, () => ( "")));
856
998
  }
857
999
  function prefixesOf(config) {
858
1000
  return _nullishCoalesce(config.stripPrefixes, () => ( DEFAULT_STRIP_PREFIXES));
859
1001
  }
1002
+ function originsOf(config) {
1003
+ return _nullishCoalesce(config.ownOrigins, () => ( defaultOwnOrigins(config.clientDomain)));
1004
+ }
860
1005
  function getImageUrl(config, imagePath, transforms, options) {
861
1006
  const merged = {
862
1007
  ...config.defaultTransforms,
@@ -864,10 +1009,11 @@ function getImageUrl(config, imagePath, transforms, options) {
864
1009
  };
865
1010
  return imageUrlOf(
866
1011
  config.clientDomain,
867
- _nullishCoalesce(_optionalChain([imagePath, 'optionalAccess', _33 => _33.trim, 'call', _34 => _34()]), () => ( "")),
1012
+ _nullishCoalesce(_optionalChain([imagePath, 'optionalAccess', _34 => _34.trim, 'call', _35 => _35()]), () => ( "")),
868
1013
  serializeTransforms(merged),
869
1014
  fallbackOf(config, options),
870
1015
  prefixesOf(config),
1016
+ originsOf(config),
871
1017
  _nullishCoalesce(config.defaultPath, () => ( ""))
872
1018
  );
873
1019
  }
@@ -876,17 +1022,18 @@ function getDefaultImageUrl(config, options) {
876
1022
  config.clientDomain,
877
1023
  fallbackOf(config, options),
878
1024
  prefixesOf(config),
1025
+ originsOf(config),
879
1026
  _nullishCoalesce(config.defaultPath, () => ( ""))
880
1027
  );
881
1028
  }
882
1029
  function fallbackOf(config, options) {
883
- return _nullishCoalesce(_nullishCoalesce(_optionalChain([options, 'optionalAccess', _35 => _35.defaultImage]), () => ( config.defaultImage)), () => ( ""));
1030
+ return _nullishCoalesce(_nullishCoalesce(_optionalChain([options, 'optionalAccess', _36 => _36.defaultImage]), () => ( config.defaultImage)), () => ( ""));
884
1031
  }
885
1032
  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(", ");
1033
+ return srcSetOf(
1034
+ widths.map((width) => getImageUrl(config, imagePath, { ...transforms, width })),
1035
+ widths.map(String)
1036
+ );
890
1037
  }
891
1038
  function buildImageLoader(config, transforms) {
892
1039
  return ({ src, width, quality }) => {
@@ -1080,7 +1227,7 @@ function serializeSearchParams(filters, options) {
1080
1227
  from: filters.offset,
1081
1228
  sortBy: searchSortBy(filters.sortBy),
1082
1229
  classId5List: categoryUid ? String(categoryUid) : void 0,
1083
- filters: _optionalChain([filters, 'access', _36 => _36.filters, 'optionalAccess', _37 => _37.length]) ? JSON.stringify(filters.filters) : void 0,
1230
+ filters: _optionalChain([filters, 'access', _37 => _37.filters, 'optionalAccess', _38 => _38.length]) ? JSON.stringify(filters.filters) : void 0,
1084
1231
  sourceFieldsList: sourceFields
1085
1232
  };
1086
1233
  }
@@ -1156,10 +1303,10 @@ function buildTrackingData({
1156
1303
  total = cleanMoney(total + cleanMoney(price * line.quantity));
1157
1304
  return {
1158
1305
  item_id: line.itemId,
1159
- item_name: _nullishCoalesce(_optionalChain([details, 'optionalAccess', _38 => _38.itemDesc]), () => ( "")),
1306
+ item_name: _nullishCoalesce(_optionalChain([details, 'optionalAccess', _39 => _39.itemDesc]), () => ( "")),
1160
1307
  currency,
1161
1308
  index,
1162
- item_category: _nullishCoalesce(_optionalChain([details, 'optionalAccess', _39 => _39.classId5]), () => ( "")),
1309
+ item_category: _nullishCoalesce(_optionalChain([details, 'optionalAccess', _40 => _40.classId5]), () => ( "")),
1163
1310
  price,
1164
1311
  quantity: line.quantity
1165
1312
  };
@@ -1255,5 +1402,12 @@ function pushTrackingData(data) {
1255
1402
 
1256
1403
 
1257
1404
 
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;
1405
+
1406
+
1407
+
1408
+
1409
+
1410
+
1411
+
1412
+ 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.errorLogLine = errorLogLine; 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.logLineOf = logLineOf; 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
1413
  //# sourceMappingURL=index.cjs.map