@simpleapps-com/augur-utils 2026.11.1 → 2026.11.3

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/EXPORTS.md CHANGED
@@ -9,9 +9,11 @@
9
9
 
10
10
  | Export | Kind | Description |
11
11
  |--------|------|-------------|
12
+ | `addMillis` | const | A clock reading plus a duration, both milliseconds: when something expires. |
12
13
  | `BillingAddressInvoiceSchema` | const | Valibot schema for billing address with required PO number (invoice payments). |
13
14
  | `BillingAddressSchema` | const | Valibot schema for billing address validation. Less strict than shipping: allows PO Box, no email/phone required. |
14
15
  | `BLUR_DATA_URL` | const | 1x1 transparent PNG for Next.js `<Image blurDataURL={...}>` placeholders. |
16
+ | `breadcrumbLd` | const | A breadcrumb trail's BreadcrumbList as text. |
15
17
  | `buildCheckoutPayload` | function | Builds the oe_hdr + oe_line payload required by the commerce checkout API from cart data. |
16
18
  | `buildImageLoader` | function | Returns a loader function compatible with Next.js `<Image loader={...}>`. |
17
19
  | `buildTrackingData` | function | Build a GA4 begin_checkout ecommerce payload from cart lines, item details, and prices. |
@@ -21,7 +23,10 @@
21
23
  | `cn` | function | Merge Tailwind classes without conflicts. Web only (tailwind-merge is meaningless in RN). |
22
24
  | `CONTIGUOUS_STATES` | const | Lower 48 contiguous states. |
23
25
  | `createImageConfig` | function | Creates a frozen ImageConfig object. |
26
+ | `days` | const | `n` days, in seconds. |
24
27
  | `derivePrice` | function | Pure price derivation — usable in hooks AND server components. |
28
+ | `faqLd` | const | A FAQ page's FAQPage markup as text: one Question per entry. |
29
+ | `floorSeconds` | const | Milliseconds as whole seconds, rounded down. |
25
30
  | `formatPrice` | function | Locale-aware currency formatting. Defaults to USD -- consumers can override locale and currency. |
26
31
  | `generateBreadcrumbJsonLd` | function | Generates a Schema.org BreadcrumbList JSON-LD object from an array of breadcrumb items. |
27
32
  | `generateProductJsonLd` | function | Generates a Schema.org Product JSON-LD string from an inventory document. Returns null if the item is suppressed, unnamed, or has no price. |
@@ -33,17 +38,31 @@
33
38
  | `getSchemaAvailability` | function | Maps resolved stock to a Schema.org availability URL. |
34
39
  | `getShippingLeadDate` | function | Get shipping lead date estimate based on days string (the table is `shippingLeadOf`). |
35
40
  | `hasPriceBreaks` | function | Type guard: true when `libraryPriceData` is the price-page shape with quantity `breaks`. |
41
+ | `hours` | const | `n` hours, in seconds. |
42
+ | `idRef` | const | A reference to another node by its @id, as JSON text. |
36
43
  | `isAddressDifferent` | function | Compares a user-entered address with a SmartyStreets-validated address. Returns true if any field differs (case-insensitive for address/city, exact match for state abbreviation and zip code). |
44
+ | `isServerRuntime` | function | Returns true when running outside a browser (Node SSR, edge, Deno). Mirrors `isServer` in `@tanstack/query-core` (`build/modern/utils.js`). Evaluated per call, not at module scope, so `"use client"` modules that also run during SSR resolve correctly on each pass. |
45
+ | `millis` | const | `n` milliseconds, for a duration under a second. |
46
+ | `millisOf` | const | `n` as `Millis`, or null unless it is a safe integer at least 0. |
47
+ | `minusMillis` | const | A reading less a duration, never below 0. |
48
+ | `minutes` | const | `n` minutes, in seconds. |
49
+ | `nodeHead` | const | The schema.org context and a node's type: its first two members, as JSON text. |
37
50
  | `normalizePath` | function | Normalizes an image path by: 1. Returning it as-is if it starts with `http` (external URL). 2. Stripping configured prefixes (defaults: `/images`, `images`). 3. Prepending `defaultPath` for bare filenames (no `/`). 4. Stripping leading slashes. |
38
51
  | `paginateOffset` | function | Returns a copy of filters with offset adjusted for the given page. |
39
52
  | `pushTrackingData` | function | Push ecommerce tracking data to window.dataLayer using the GA4 clear-then-push pattern. |
53
+ | `resolveGcTime` | function | Returns the React Query `gcTime` to use for a query built in this runtime. On the server returns `Infinity`, which query-core treats as "schedule no GC timer", so a per-request QueryClient is freed when the request ends. A finite value would start a timer that pins the whole request cache. In the browser returns `clientGcTime` unchanged. The result is a `number`, not `Millis`: `Infinity` is no whole number of milliseconds. |
40
54
  | `resolveStock` | function | Pure stock resolution -- usable in hooks AND server components. |
41
55
  | `roundHalfAway` | function | Round half away from zero to `decimals` places. |
42
56
  | `sanitizeHtmlImages` | function | Rewrites `<img src="...">` attributes in an HTML string to use agr.media URLs. Useful for CMS/Joomla content that contains raw image references. |
57
+ | `seconds` | const | `n` seconds. |
58
+ | `secondsOf` | const | `n` as `Seconds`, or null unless it is a safe integer at least 0. |
43
59
  | `serializeCategoryFilters` | function | Converts TItemsFilters to the SDK params shape for category item endpoints. |
44
60
  | `serializeSearchParams` | function | Converts TItemsFilters to the SDK params shape for search endpoints. |
45
61
  | `serializeTransforms` | function | Serializes transform options into the CDN path segment. Example: `{ width: 400, format: "webp" }` → `"w_400,f_webp"` |
46
62
  | `ShippingAddressSchema` | const | Valibot schema for shipping address validation. Enforces no PO Box, requires street number, formats phone number. |
63
+ | `tierBrowserGcTime` | function | A tier's gcTime in the browser: STATIC 24 h, SEMI_STATIC 4 h, DYNAMIC and CART 30 min, REALTIME 5 min; never shorter than its staleTime. On the server the tier's gcTime is `gcTimeFor(true, …)`: none. |
64
+ | `tierStaleTime` | function | A tier's staleTime: STATIC 1 h, SEMI_STATIC 10 min, DYNAMIC 5 min, CART 2 min, REALTIME 0. |
65
+ | `toMillis` | const | Seconds as milliseconds, exactly. |
47
66
  | `trackAddToCart` | function | Track add_to_cart event to Google Analytics dataLayer. |
48
67
  | `trackViewItem` | function | Track view_item event to Google Analytics dataLayer. |
49
68
  | `transformShipToAddress` | function | Normalizes a raw ship-to address object (camelCase or snake_case, physical or mailing) into a consistent ShipToAddress shape. |
@@ -53,10 +72,11 @@
53
72
  | `US_STATES_FULL` | const | All US states and territories — full data from states-us. |
54
73
  | `US_TERRITORIES` | const | US territories (PR, GU, VI, AS, MP). |
55
74
  | `VALIDATION_PATTERNS` | const | Common regex patterns used for form validation across augur-hosted sites. |
75
+ | `wholeSeconds` | const | An outside count of seconds, rounded down; 0 when it is then no safe integer at least 0. |
56
76
 
57
77
  ### Types
58
78
 
59
- `AddToCartEventParams`, `BillingAddress`, `BreadcrumbJsonLdItem`, `BuildTrackingDataInput`, `CacheTier`, `CategoryFilterOptions`, `CheckoutInput`, `CheckoutPayment`, `CustomerDocument`, `DerivedPrice`, `DerivePriceInput`, `ImageConfig`, `ImageTransforms`, `ImageUrlOptions`, `MenuItem`, `OeHdr`, `OeLine`, `OrderHeader`, `OrderLine`, `OrderNote`, `OrderPayment`, `PaymentStatus`, `PaymentStatusInvoice`, `ProductJsonLdAggregateRating`, `ProductJsonLdOptions`, `ProductJsonLdSeller`, `ResolvedStock`, `ResolveStockInput`, `SafeActionResult`, `SchemaAvailability`, `SearchParamOptions`, `ShippingAddress`, `ShipToAddress`, `TAccountQuery`, `TApiResponse`, `TAttribute`, `TAttributeValue`, `TBillingUpdate`, `TCardInfo`, `TCartHdrUid`, `TCartLine`, `TCartLookUp`, `TCategory`, `TCategoryChild`, `TCategoryItemsResult`, `TCheckoutResult`, `TInventorySupplier`, `TInvMast`, `TInvMastDoc`, `TItemAccessory`, `TItemAttribute`, `TItemAttributes`, `TItemCategory`, `TItemDetails`, `TItemRelatedProduct`, `TItemsFilters`, `TItemUom`, `TJoomlaContent`, `TJoomlaContentFilters`, `TLibraryMultiplierData`, `TLibraryPriceBreak`, `TLibraryPriceData`, `TLtlRatesResponse`, `TLtlShipmentData`, `TMenu`, `TMenuFilters`, `TMetaTags`, `TOrderCartLine`, `TPasswordVerification`, `TPaymentValidation`, `TPriceData`, `TProductCategory`, `TProductItem`, `TProductStockData`, `TProfileValues`, `TrackingData`, `TrackingItem`, `TRelatedProduct`, `TSearchSuggestion`, `TSearchSuggestionsResponse`, `TShippingMethod`, `TSmartyStreets`, `TStock`, `TStockData`, `TSurcharge`, `TTax`, `TTaxItem`, `TTransactionSetup`, `TUserProfile`, `TWebDesc`, `UserAddress`, `USState`, `USStateCode`, `ViewItemEventParams`
79
+ `AddToCartEventParams`, `BillingAddress`, `BreadcrumbJsonLdItem`, `BuildTrackingDataInput`, `CacheTier`, `CategoryFilterOptions`, `CheckoutInput`, `CheckoutPayment`, `CustomerDocument`, `DerivedPrice`, `DerivePriceInput`, `Faq`, `ImageConfig`, `ImageTransforms`, `ImageUrlOptions`, `MenuItem`, `Millis`, `OeHdr`, `OeLine`, `OrderHeader`, `OrderLine`, `OrderNote`, `OrderPayment`, `PaymentStatus`, `PaymentStatusInvoice`, `ProductJsonLdAggregateRating`, `ProductJsonLdOptions`, `ProductJsonLdSeller`, `ResolvedStock`, `ResolveStockInput`, `SafeActionResult`, `SchemaAvailability`, `SearchParamOptions`, `Seconds`, `ShippingAddress`, `ShipToAddress`, `TAccountQuery`, `TApiResponse`, `TAttribute`, `TAttributeValue`, `TBillingUpdate`, `TCardInfo`, `TCartHdrUid`, `TCartLine`, `TCartLookUp`, `TCategory`, `TCategoryChild`, `TCategoryItemsResult`, `TCheckoutResult`, `TierName`, `TInventorySupplier`, `TInvMast`, `TInvMastDoc`, `TItemAccessory`, `TItemAttribute`, `TItemAttributes`, `TItemCategory`, `TItemDetails`, `TItemRelatedProduct`, `TItemsFilters`, `TItemUom`, `TJoomlaContent`, `TJoomlaContentFilters`, `TLibraryMultiplierData`, `TLibraryPriceBreak`, `TLibraryPriceData`, `TLtlRatesResponse`, `TLtlShipmentData`, `TMenu`, `TMenuFilters`, `TMetaTags`, `TOrderCartLine`, `TPasswordVerification`, `TPaymentValidation`, `TPriceData`, `TProductCategory`, `TProductItem`, `TProductStockData`, `TProfileValues`, `TrackingData`, `TrackingItem`, `TRelatedProduct`, `TSearchSuggestion`, `TSearchSuggestionsResponse`, `TShippingMethod`, `TSmartyStreets`, `TStock`, `TStockData`, `TSurcharge`, `TTax`, `TTaxItem`, `TTransactionSetup`, `TUserProfile`, `TWebDesc`, `UserAddress`, `USState`, `USStateCode`, `ViewItemEventParams`
60
80
 
61
81
  ## `@simpleapps-com/augur-utils/web`
62
82
 
package/README.md CHANGED
@@ -26,6 +26,12 @@ TypeScript in `src/`, built to `dist/` (ESM and CJS) by tsup. The decisions are
26
26
  (`src/rules.ts`, `src/price-outcome.ts`, `src/image-rules.ts`, `src/json-ld-rules.ts`; model
27
27
  `models/AugurUtils.dfy`, links `models/links/augur-utils-*.dfy`); the rest is tested at 100%.
28
28
 
29
+ `CACHE_CONFIG`'s tiers are server-safe (#94): each `gcTime` is a getter through
30
+ `resolveGcTime` (`src/runtime.ts`, the proved `gcTimeFor` in `src/rules.ts`), so it is
31
+ `Infinity` on the server and the tier's value in the browser, decided each time a tier is read.
32
+ `isServerRuntime` and `resolveGcTime` live here, the lowest package that needs them; augur-core
33
+ re-exports `resolveGcTime`.
34
+
29
35
  ```bash
30
36
  pnpm -C repo/packages/augur-utils test
31
37
  pnpm -C repo/packages/augur-utils proofs
@@ -8,33 +8,39 @@
8
8
  *
9
9
  * gcTime (garbage collection time) -- How long UNUSED cached data stays in
10
10
  * memory after all components using it unmount. Once gcTime expires the
11
- * cache entry is deleted entirely.
11
+ * cache entry is deleted entirely. Server-safe (#94): each tier's gcTime is
12
+ * read through `resolveGcTime`, so on the server it is `Infinity` (no GC
13
+ * timer, the per-request cache is freed with the request) and in the browser
14
+ * the value below, never shorter than the tier's staleTime (proved). It is
15
+ * decided each time the tier is read, so spreading a tier after the proxy's
16
+ * options (`{ ...q.items.get(id), ...CACHE_CONFIG.STATIC }`) is safe in a
17
+ * `"use client"` module rendered on the server too.
12
18
  *
13
- * STATIC (1h): categories, menus, item details
14
- * SEMI_STATIC (10m): pricing, stock, search results
15
- * DYNAMIC (5m): infinite scroll data
16
- * CART (2m): cart lines, cart header
17
- * REALTIME (0): active orders, checkout state
19
+ * STATIC (1h, gc 24h): categories, menus, item details
20
+ * SEMI_STATIC (10m, gc 4h): pricing, stock, search results
21
+ * DYNAMIC (5m, gc 30m): infinite scroll data
22
+ * CART (2m, gc 30m): cart lines, cart header
23
+ * REALTIME (0, gc 5m): active orders, checkout state
18
24
  */
19
25
  export declare const CACHE_CONFIG: {
20
26
  readonly STATIC: {
21
- readonly staleTime: number;
27
+ readonly staleTime: import("./duration").Millis;
22
28
  readonly gcTime: number;
23
29
  };
24
30
  readonly SEMI_STATIC: {
25
- readonly staleTime: number;
31
+ readonly staleTime: import("./duration").Millis;
26
32
  readonly gcTime: number;
27
33
  };
28
34
  readonly DYNAMIC: {
29
- readonly staleTime: number;
35
+ readonly staleTime: import("./duration").Millis;
30
36
  readonly gcTime: number;
31
37
  };
32
38
  readonly CART: {
33
- readonly staleTime: number;
39
+ readonly staleTime: import("./duration").Millis;
34
40
  readonly gcTime: number;
35
41
  };
36
42
  readonly REALTIME: {
37
- readonly staleTime: 0;
43
+ readonly staleTime: import("./duration").Millis;
38
44
  readonly gcTime: number;
39
45
  };
40
46
  };
@@ -1 +1 @@
1
- {"version":3,"file":"cache-config.d.ts","sourceRoot":"","sources":["../src/cache-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;CAqBf,CAAC;AAEX,MAAM,MAAM,SAAS,GAAG,MAAM,OAAO,YAAY,CAAC"}
1
+ {"version":3,"file":"cache-config.d.ts","sourceRoot":"","sources":["../src/cache-config.ts"],"names":[],"mappings":"AAiBA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,YAAY;;;yBA9BP,MAAM;;;;yBAAN,MAAM;;;;yBAAN,MAAM;;;;yBAAN,MAAM;;;;yBAAN,MAAM;;CAoCd,CAAC;AAEX,MAAM,MAAM,SAAS,GAAG,MAAM,OAAO,YAAY,CAAC"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Seconds and milliseconds for the published augur-* packages (2026-11-08): the same two types
3
+ * as `@atlas/utils/duration`, which is private (its code is bundled in, its types can't be
4
+ * named in a published `.d.ts`). The brands are the same, so a `Seconds` from either package is
5
+ * the other's (as the SDK's `SiteId` is auth-core's); the builders are the proved ones, passed
6
+ * through (model `Utils` "durations", link `models/links/utils-duration.dfy`).
7
+ *
8
+ * A TTL in seconds can't go where milliseconds are meant: React Query's `staleTime` / `gcTime`
9
+ * are `Millis`, a Redis TTL is `Seconds`. Write `toMillis(minutes(5))`, not `300000`.
10
+ */
11
+ /** A whole number of seconds (a Redis TTL, a JWT `exp`). */
12
+ export type Seconds = number & {
13
+ readonly __seconds: true;
14
+ };
15
+ /** A whole number of milliseconds (React Query's `staleTime` / `gcTime`, `Date.now()`). */
16
+ export type Millis = number & {
17
+ readonly __millis: true;
18
+ };
19
+ /** `n` seconds. */
20
+ export declare const seconds: (n: number) => Seconds;
21
+ /** `n` minutes, in seconds. */
22
+ export declare const minutes: (n: number) => Seconds;
23
+ /** `n` hours, in seconds. */
24
+ export declare const hours: (n: number) => Seconds;
25
+ /** `n` days, in seconds. */
26
+ export declare const days: (n: number) => Seconds;
27
+ /** `n` milliseconds, for a duration under a second. */
28
+ export declare const millis: (n: number) => Millis;
29
+ /** Seconds as milliseconds, exactly. */
30
+ export declare const toMillis: (d: Seconds) => Millis;
31
+ /** A clock reading plus a duration, both milliseconds: when something expires. */
32
+ export declare const addMillis: (a: Millis, b: Millis) => Millis;
33
+ /** A reading less a duration, never below 0. */
34
+ export declare const minusMillis: (a: Millis, b: Millis) => Millis;
35
+ /** Milliseconds as whole seconds, rounded down. */
36
+ export declare const floorSeconds: (m: Millis) => Seconds;
37
+ /** `n` as `Seconds`, or null unless it is a safe integer at least 0. */
38
+ export declare const secondsOf: (n: number) => Seconds | null;
39
+ /** An outside count of seconds, rounded down; 0 when it is then no safe integer at least 0. */
40
+ export declare const wholeSeconds: (n: number) => Seconds;
41
+ /** `n` as `Millis`, or null unless it is a safe integer at least 0. */
42
+ export declare const millisOf: (n: number) => Millis | null;
43
+ //# sourceMappingURL=duration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"duration.d.ts","sourceRoot":"","sources":["../src/duration.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AAEH,4DAA4D;AAE5D,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAA;CAAE,CAAC;AAE5D,2FAA2F;AAE3F,MAAM,MAAM,MAAM,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAA;CAAE,CAAC;AAE1D,mBAAmB;AACnB,eAAO,MAAM,OAAO,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,OAA0B,CAAC;AAChE,+BAA+B;AAC/B,eAAO,MAAM,OAAO,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,OAA0B,CAAC;AAChE,6BAA6B;AAC7B,eAAO,MAAM,KAAK,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,OAAwB,CAAC;AAC5D,4BAA4B;AAC5B,eAAO,MAAM,IAAI,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,OAAuB,CAAC;AAC1D,uDAAuD;AACvD,eAAO,MAAM,MAAM,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAwB,CAAC;AAC7D,wCAAwC;AACxC,eAAO,MAAM,QAAQ,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,MAA0B,CAAC;AAClE,kFAAkF;AAClF,eAAO,MAAM,SAAS,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,MAA2B,CAAC;AAC9E,gDAAgD;AAChD,eAAO,MAAM,WAAW,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,MAA6B,CAAC;AAClF,mDAAmD;AACnD,eAAO,MAAM,YAAY,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,OAA+B,CAAC;AAC1E,wEAAwE;AACxE,eAAO,MAAM,SAAS,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,OAAO,GAAG,IAAyB,CAAC;AAC3E,+FAA+F;AAC/F,eAAO,MAAM,YAAY,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,OAA+B,CAAC;AAC1E,uEAAuE;AACvE,eAAO,MAAM,QAAQ,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,GAAG,IAAwB,CAAC"}
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) {
@@ -101,6 +98,75 @@ function takerOf(taker) {
101
98
  function addressDifferentOf(line1Same, citySame, stateSame, zipSame) {
102
99
  return !line1Same || !citySame || !stateSame || !zipSame;
103
100
  }
101
+ function gcTimeFor(isServer, clientGcTime) {
102
+ return isServer ? null : clientGcTime;
103
+ }
104
+ function tierStaleTime(t) {
105
+ if (t === "STATIC") return toMillis(hours(1));
106
+ if (t === "SEMI_STATIC") return toMillis(minutes(10));
107
+ if (t === "DYNAMIC") return toMillis(minutes(5));
108
+ if (t === "CART") return toMillis(minutes(2));
109
+ return millis(0);
110
+ }
111
+ function tierBrowserGcTime(t) {
112
+ if (t === "STATIC") return toMillis(hours(24));
113
+ if (t === "SEMI_STATIC") return toMillis(hours(4));
114
+ if (t === "DYNAMIC") return toMillis(minutes(30));
115
+ if (t === "CART") return toMillis(minutes(30));
116
+ return toMillis(minutes(5));
117
+ }
118
+ function serverRuntimeOf(hasWindow, hasDeno) {
119
+ return !hasWindow || hasDeno;
120
+ }
121
+
122
+ // src/runtime.ts
123
+ function isServerRuntime() {
124
+ const hasWindow = typeof globalThis.window !== "undefined";
125
+ return serverRuntimeOf(hasWindow, "Deno" in globalThis);
126
+ }
127
+ function resolveGcTime(clientGcTime) {
128
+ return _nullishCoalesce(gcTimeFor(isServerRuntime(), clientGcTime), () => ( Infinity));
129
+ }
130
+
131
+ // src/cache-config.ts
132
+ function tier(name) {
133
+ return {
134
+ staleTime: tierStaleTime(name),
135
+ get gcTime() {
136
+ return resolveGcTime(tierBrowserGcTime(name));
137
+ }
138
+ };
139
+ }
140
+ var CACHE_CONFIG = {
141
+ STATIC: tier("STATIC"),
142
+ SEMI_STATIC: tier("SEMI_STATIC"),
143
+ DYNAMIC: tier("DYNAMIC"),
144
+ CART: tier("CART"),
145
+ REALTIME: tier("REALTIME")
146
+ };
147
+
148
+ // src/duration.ts
149
+ var seconds2 = seconds;
150
+ var minutes2 = minutes;
151
+ var hours2 = hours;
152
+ var days2 = days;
153
+ var millis2 = millis;
154
+ var toMillis2 = toMillis;
155
+ var addMillis2 = addMillis;
156
+ var minusMillis2 = minusMillis;
157
+ var floorSeconds2 = floorSeconds;
158
+ var secondsOf2 = secondsOf;
159
+ var wholeSeconds2 = wholeSeconds;
160
+ var millisOf2 = millisOf;
161
+
162
+ // src/format-price.ts
163
+ function formatPrice(price, locale = "en-US", currency = "USD") {
164
+ return new Intl.NumberFormat(locale, {
165
+ style: "currency",
166
+ currency,
167
+ minimumFractionDigits: 2
168
+ }).format(price);
169
+ }
104
170
 
105
171
  // src/address-comparison.ts
106
172
  function isAddressDifferent(userAddress, smartyAddress) {
@@ -310,6 +376,195 @@ var SCHEMA_URLS = {
310
376
  BackOrder: "https://schema.org/BackOrder"
311
377
  };
312
378
 
379
+ // ../utils/src/strings.ts
380
+ function codeAt(s, i) {
381
+ return i >= 0 && i < s.length ? s.charCodeAt(i) : -1;
382
+ }
383
+ function indexOfCode(s, code, from) {
384
+ const c = codeAt(s, from);
385
+ if (c === code) return from;
386
+ if (c === -1) return -1;
387
+ return indexOfCode(s, code, from + 1);
388
+ }
389
+ function startsWithAt(s, x, pos) {
390
+ const at = Math.min(pos, s.length);
391
+ return s.slice(at, Math.min(at + x.length, s.length)) === x;
392
+ }
393
+
394
+ // ../utils/src/lists.ts
395
+ function joinFrom(xs, sep, i) {
396
+ if (i >= xs.length) return "";
397
+ return joinRange(xs, sep, i, xs.length);
398
+ }
399
+ function joinRange(xs, sep, lo, hi) {
400
+ if (hi - lo === 1) return xs[lo];
401
+ const mid = lo + Math.floor((hi - lo) / 2);
402
+ return joinRange(xs, sep, lo, mid) + sep + joinRange(xs, sep, mid, hi);
403
+ }
404
+
405
+ // ../utils/src/replace.ts
406
+ function codeIndex(codes, c, i) {
407
+ if (i === codes.length) return -1;
408
+ return codes[i] === c ? i : codeIndex(codes, c, i + 1);
409
+ }
410
+ function substitute(s, codes, texts) {
411
+ let out = "";
412
+ for (let i = 0; i !== s.length; i++) {
413
+ const k = codeIndex(codes, s.charCodeAt(i), 0);
414
+ out = k >= 0 && k < texts.length ? out + texts[k] : out + s.slice(i, i + 1);
415
+ }
416
+ return out;
417
+ }
418
+ function jsonCodes() {
419
+ return [
420
+ 34,
421
+ 92,
422
+ 8,
423
+ 9,
424
+ 10,
425
+ 12,
426
+ 13,
427
+ 0,
428
+ 1,
429
+ 2,
430
+ 3,
431
+ 4,
432
+ 5,
433
+ 6,
434
+ 7,
435
+ 11,
436
+ 14,
437
+ 15,
438
+ 16,
439
+ 17,
440
+ 18,
441
+ 19,
442
+ 20,
443
+ 21,
444
+ 22,
445
+ 23,
446
+ 24,
447
+ 25,
448
+ 26,
449
+ 27,
450
+ 28,
451
+ 29,
452
+ 30,
453
+ 31
454
+ ];
455
+ }
456
+ function jsonTexts() {
457
+ return [
458
+ '\\"',
459
+ "\\\\",
460
+ "\\b",
461
+ "\\t",
462
+ "\\n",
463
+ "\\f",
464
+ "\\r",
465
+ "\\u0000",
466
+ "\\u0001",
467
+ "\\u0002",
468
+ "\\u0003",
469
+ "\\u0004",
470
+ "\\u0005",
471
+ "\\u0006",
472
+ "\\u0007",
473
+ "\\u000b",
474
+ "\\u000e",
475
+ "\\u000f",
476
+ "\\u0010",
477
+ "\\u0011",
478
+ "\\u0012",
479
+ "\\u0013",
480
+ "\\u0014",
481
+ "\\u0015",
482
+ "\\u0016",
483
+ "\\u0017",
484
+ "\\u0018",
485
+ "\\u0019",
486
+ "\\u001a",
487
+ "\\u001b",
488
+ "\\u001c",
489
+ "\\u001d",
490
+ "\\u001e",
491
+ "\\u001f"
492
+ ];
493
+ }
494
+ function jsonString(s) {
495
+ return '"' + substitute(s, jsonCodes(), jsonTexts()) + '"';
496
+ }
497
+
498
+ // ../utils/src/json.ts
499
+ function jsonPair(key, value) {
500
+ return jsonString(key) + ":" + value;
501
+ }
502
+ function jsonTextPair(key, value) {
503
+ return jsonString(key) + ":" + jsonString(value);
504
+ }
505
+ function jsonObject(pairs) {
506
+ return "{" + joinFrom(pairs, ",", 0) + "}";
507
+ }
508
+ function jsonArray(items) {
509
+ return "[" + joinFrom(items, ",", 0) + "]";
510
+ }
511
+
512
+ // ../foundation/src/decimal.ts
513
+ function decimal(n) {
514
+ const last = "0123456789".slice(n % 10, n % 10 + 1);
515
+ return n < 10 ? last : decimal(Math.floor(n / 10)) + last;
516
+ }
517
+
518
+ // ../utils/src/json-ld-items.ts
519
+ function nodeHead(type) {
520
+ return [jsonTextPair("@context", "https://schema.org"), jsonTextPair("@type", type)];
521
+ }
522
+ function crumbItemsFrom(crumbs, i) {
523
+ if (i >= crumbs.length) return [];
524
+ const crumb = crumbs[i];
525
+ return [
526
+ jsonObject([
527
+ jsonTextPair("@type", "ListItem"),
528
+ jsonPair("position", decimal(i + 1)),
529
+ jsonTextPair("name", crumb.name),
530
+ jsonTextPair("item", crumb.url)
531
+ ]),
532
+ ...crumbItemsFrom(crumbs, i + 1)
533
+ ];
534
+ }
535
+ function faqItemsFrom(faqs, i) {
536
+ if (i >= faqs.length) return [];
537
+ const faq = faqs[i];
538
+ return [
539
+ jsonObject([
540
+ jsonTextPair("@type", "Question"),
541
+ jsonTextPair("name", faq.question),
542
+ jsonPair(
543
+ "acceptedAnswer",
544
+ jsonObject([jsonTextPair("@type", "Answer"), jsonTextPair("text", faq.answer)])
545
+ )
546
+ ]),
547
+ ...faqItemsFrom(faqs, i + 1)
548
+ ];
549
+ }
550
+
551
+ // ../utils/src/json-ld.ts
552
+ function idRef(id) {
553
+ return jsonObject([jsonTextPair("@id", id)]);
554
+ }
555
+ function breadcrumbLd(crumbs) {
556
+ return jsonObject([
557
+ ...nodeHead("BreadcrumbList"),
558
+ jsonPair("itemListElement", jsonArray(crumbItemsFrom(crumbs, 0)))
559
+ ]);
560
+ }
561
+ function faqLd(faqs) {
562
+ return jsonObject([
563
+ ...nodeHead("FAQPage"),
564
+ jsonPair("mainEntity", jsonArray(faqItemsFrom(faqs, 0)))
565
+ ]);
566
+ }
567
+
313
568
  // src/json-ld-rules.ts
314
569
  function breadcrumbPosition(i) {
315
570
  return i + 1;
@@ -360,6 +615,10 @@ function generateBreadcrumbJsonLd(items) {
360
615
  }))
361
616
  };
362
617
  }
618
+ var breadcrumbLd2 = breadcrumbLd;
619
+ var faqLd2 = faqLd;
620
+ var nodeHead2 = nodeHead;
621
+ var idRef2 = idRef;
363
622
  function getGtinField(upcOrEan) {
364
623
  return gtinFieldOf(_nullishCoalesce(_optionalChain([upcOrEan, 'optionalAccess', _6 => _6.toUpperCase, 'call', _7 => _7()]), () => ( "")));
365
624
  }
@@ -474,28 +733,6 @@ function unwrapOr(result) {
474
733
  return result.ok ? _nullishCoalesce(result.data, () => ( null)) : null;
475
734
  }
476
735
 
477
- // ../utils/src/strings.ts
478
- function codeAt(s, i) {
479
- return i >= 0 && i < s.length ? s.charCodeAt(i) : -1;
480
- }
481
- function indexOfCode(s, code, from) {
482
- const c = codeAt(s, from);
483
- if (c === code) return from;
484
- if (c === -1) return -1;
485
- return indexOfCode(s, code, from + 1);
486
- }
487
- function startsWithAt(s, x, pos) {
488
- const at = Math.min(pos, s.length);
489
- return s.slice(at, Math.min(at + x.length, s.length)) === x;
490
- }
491
-
492
- // ../utils/src/lists.ts
493
- function joinFrom(xs, sep, i) {
494
- if (i >= xs.length) return "";
495
- if (i === xs.length - 1) return xs[i];
496
- return xs[i] + sep + joinFrom(xs, sep, i + 1);
497
- }
498
-
499
736
  // src/image-rules.ts
500
737
  function transformKeyOf(field) {
501
738
  if (field === "width") return "w";
@@ -775,8 +1012,8 @@ function getBusinessDay(businessDaysFromNow) {
775
1012
  }
776
1013
  return businessDays[businessDays.length - 1] || "";
777
1014
  }
778
- function getShippingLeadDate(days) {
779
- const config = shippingLeadOf(days);
1015
+ function getShippingLeadDate(days3) {
1016
+ const config = shippingLeadOf(days3);
780
1017
  if (!config) return "";
781
1018
  const fromDate = getBusinessDay(config.from);
782
1019
  if (config.to) {
@@ -960,5 +1197,25 @@ function pushTrackingData(data) {
960
1197
 
961
1198
 
962
1199
 
963
- 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.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.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.isAddressDifferent = isAddressDifferent; 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;
1200
+
1201
+
1202
+
1203
+
1204
+
1205
+
1206
+
1207
+
1208
+
1209
+
1210
+
1211
+
1212
+
1213
+
1214
+
1215
+
1216
+
1217
+
1218
+
1219
+
1220
+ 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.millis = millis2; exports.millisOf = millisOf2; exports.minusMillis = minusMillis2; exports.minutes = minutes2; exports.nodeHead = nodeHead2; exports.normalizePath = normalizePath; exports.paginateOffset = paginateOffset; 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;
964
1221
  //# sourceMappingURL=index.cjs.map