@amboras-dev/storefront-core 2026.11.0 → 2026.11.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/CHANGELOG.md +80 -0
  2. package/README.md +67 -23
  3. package/core-manifest.json +11 -1
  4. package/dist/entries/server.d.ts +1 -0
  5. package/dist/entries/server.d.ts.map +1 -1
  6. package/dist/entries/server.js +1 -0
  7. package/dist/entries/server.js.map +1 -1
  8. package/dist/hooks/use-checkout-settings.d.ts +9 -2
  9. package/dist/hooks/use-checkout-settings.d.ts.map +1 -1
  10. package/dist/hooks/use-checkout-settings.js +25 -3
  11. package/dist/hooks/use-checkout-settings.js.map +1 -1
  12. package/dist/hooks/use-store-config.d.ts +43 -0
  13. package/dist/hooks/use-store-config.d.ts.map +1 -0
  14. package/dist/hooks/use-store-config.js +53 -0
  15. package/dist/hooks/use-store-config.js.map +1 -0
  16. package/dist/hooks/use-store-credit.d.ts +5 -1
  17. package/dist/hooks/use-store-credit.d.ts.map +1 -1
  18. package/dist/hooks/use-store-credit.js +5 -0
  19. package/dist/hooks/use-store-credit.js.map +1 -1
  20. package/dist/hooks/use-subscription-offers.d.ts +5 -2
  21. package/dist/hooks/use-subscription-offers.d.ts.map +1 -1
  22. package/dist/hooks/use-subscription-offers.js +17 -6
  23. package/dist/hooks/use-subscription-offers.js.map +1 -1
  24. package/dist/lib/brand.d.ts +6 -0
  25. package/dist/lib/brand.d.ts.map +1 -1
  26. package/dist/lib/brand.js +7 -1
  27. package/dist/lib/brand.js.map +1 -1
  28. package/dist/lib/store-config.d.ts +69 -0
  29. package/dist/lib/store-config.d.ts.map +1 -0
  30. package/dist/lib/store-config.js +70 -0
  31. package/dist/lib/store-config.js.map +1 -0
  32. package/dist/next-config/index.d.ts +24 -5
  33. package/dist/next-config/index.d.ts.map +1 -1
  34. package/dist/next-config/index.js +258 -35
  35. package/dist/next-config/index.js.map +1 -1
  36. package/dist/shell/client-plugin-slot.d.ts +1 -1
  37. package/dist/shell/client-plugin-slot.d.ts.map +1 -1
  38. package/dist/shell/client-plugin-slot.js +9 -1
  39. package/dist/shell/client-plugin-slot.js.map +1 -1
  40. package/dist/shell/plugin-slot.d.ts +1 -1
  41. package/dist/shell/plugin-slot.d.ts.map +1 -1
  42. package/dist/shell/plugin-slot.js +9 -1
  43. package/dist/shell/plugin-slot.js.map +1 -1
  44. package/package.json +4 -4
package/CHANGELOG.md CHANGED
@@ -2,6 +2,86 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 2026.11.2
6
+
7
+ ### Release order
8
+
9
+ **The orchestrator's image-hosts endpoint (`GET /api/v1/public/storefront/image-hosts`) must be live
10
+ in production before any production store adopts 2026.11.2.** Until then a production build cannot
11
+ reach it and uses the baked fallback list. In a 1% production sample of product `image` rows on the
12
+ 12 most common hosts, about 4% (850 of 20,217) were on merchant hosts that the fallback list does
13
+ not include. Those images would fail in `/_next/image`.
14
+
15
+ ### Breaking
16
+
17
+ - **`withAmborasCore`'s `imageHosts` option now replaces the host list.** In 2026.11.1 it was added
18
+ to the platform's wildcard hosts. Now it is the whole list (plus the Medusa host, the local-dev
19
+ hosts off Vercel, and the store's own `images.remotePatterns`). Pass
20
+ `await resolveAmborasImageHosts()`, not only your extra hosts. The `./next-config` entry now has
21
+ an API report (`api/next-config.api.md`) checked by `api:check`.
22
+ - **`medusaImageHost()` is removed** from `./next-config`. Core no longer used it, and no store or
23
+ template imports it. The reader adds the Medusa host itself.
24
+ - **The documented `next.config.mjs` shape changed.** Keep the literal
25
+ `const nextConfig = { … }` and apply core on the export line:
26
+ `export default withAmborasCore(nextConfig, { root: __dirname, imageHosts })`. The shape this
27
+ release first documented, `const nextConfig = withAmborasCore({...})`, matches none of the
28
+ orchestrator's or the Shopify cloner's patterns, so previews lost `allowedDevOrigins` and
29
+ `check_build` lost `NEXT_DIST_DIR`. A test now runs those real patterns, vendored verbatim
30
+ with their source lines, against the README snippet.
31
+
32
+ ### Changes
33
+
34
+ - **`withAmborasCore()` allows no wildcard image hosts.** Version 2026.11.1 allowed
35
+ `*.amazonaws.com`, `*.s3.amazonaws.com`, `*.cloudfront.net`, `*.supabase.co` and
36
+ `*.amboras.com`, which reopened the image proxy the platform had just closed. The hosts are now
37
+ data. The new `resolveAmborasImageHosts()` reads them from the platform endpoint
38
+ (`/api/v1/public/storefront/image-hosts?store=…`, 2s timeout). If that fails, it reads
39
+ `AMBORAS_IMAGE_HOSTS`, and then the baked fallback list (`AMBORAS_FALLBACK_IMAGE_HOSTS`,
40
+ the template's 13 hosts). It always adds the store's Medusa host. This is the template's
41
+ `amboras:image-hosts-reader` algorithm. A drift test runs core's copy next to a vendored copy
42
+ of the template's block (source commit in the fixture) and fails on any difference. Any
43
+ hostname containing `*` now throws. `PLATFORM_IMAGE_HOSTS` is a deprecated alias of the
44
+ exact-host fallback list.
45
+ - **Features come from Medusa's `GET /store/config`.** There is a new `useStoreConfig()` hook
46
+ (`client/use-store-config`, query key `['store-config']`) and a new server read,
47
+ `getStoreConfig()` (`/server`, `lib/store-config`, revalidates every 60s). Both return
48
+ `features` (`store_credit`, `gift_card_tender`, `subscriptions`, `cod`), `checkout_settings` and
49
+ `brand`. **Unknown is not off.** Each flag is `true`, `false`, or `null` (unknown), and
50
+ `checkout_settings` and `brand` are `null` when unknown. Everything is unknown while loading, on
51
+ an older Medusa (404), when Medusa cannot read the store (503), and on a network error. In those
52
+ cases `available` is false. A part whose reader failed in Medusa is `null` while the rest is
53
+ known. `isFeatureOff()` is true only for an explicit `false`, and it is the safe gate. Do not
54
+ read `features.x` as a boolean. `isFeatureOn()` is its counterpart. `useStoreConfig()` also
55
+ returns `checkoutSettingsAvailable` and `brandAvailable`, which are true when the route answered
56
+ and that part is known. Several hooks now use this data, and their APIs are unchanged:
57
+ - `useStoreCreditBalance` skips the balance call only when `store_credit` is `false`. When the
58
+ flag is unknown it asks as before.
59
+ - `useSubscriptionOffers` returns an empty page only when `subscriptions` is `false`. When the
60
+ flag is unknown it asks as before.
61
+ - `useCheckoutSettings` reads `checkout_settings` through the same `['store-config']` query
62
+ (`select`), so there is one cache and one 5-minute bound, not two stacked. It falls back to
63
+ `/store/checkout-settings` when that part is unknown.
64
+
65
+ `useBrand` and `getBrand` keep using `/store/brand`, because they need the store name.
66
+ `/store/payment-providers` still decides COD for each region.
67
+
68
+ - **`getBrand()` revalidates every 60s instead of using `no-store`.** The store's root
69
+ `generateMetadata` calls it, so the `no-store` fetch made every route dynamic and cancelled the
70
+ template's `force-dynamic` scoping. With this change, routes without A/B tests can be static.
71
+ For example, a test build rendered the `/checkout` shell as `○` static. It still returns `null`
72
+ on any failure. A logo or colour change can take up to about 2 minutes to reach metadata (Next's
73
+ 60s plus Medusa's 60s route cache).
74
+
75
+ ## 2026.11.1
76
+
77
+ - **A broken plugin no longer takes the page down.** Each plugin in `PluginSlot` and
78
+ `ClientPluginSlot` now sits in `<Suspense>` inside its error boundary with an invisible
79
+ fallback. A plugin that throws while rendering on the server used to fail the whole page with
80
+ HTTP 500, and after recovery it painted the "Something went wrong" panel. Now it renders
81
+ nothing, and the other plugins render as normal.
82
+ - **`amboras-check` survives CI publishing.** The `bin` path no longer starts with `./`. npm 11
83
+ dropped the old path during the tag-driven release.
84
+
5
85
  ## 2026.11.0
6
86
 
7
87
  First release: the template's Locked logic moves into core with unchanged export names.
package/README.md CHANGED
@@ -90,18 +90,52 @@ Payment plugins add an adapter with `registerPaymentProvider(config)` from
90
90
 
91
91
  ```js
92
92
  // next.config.mjs
93
- import { withAmborasCore } from '@amboras-dev/storefront-core/next-config'
94
- export default withAmborasCore(
95
- {
96
- /* store options */
97
- },
98
- { root: __dirname },
99
- )
93
+ import { fileURLToPath } from 'node:url'
94
+ import { dirname } from 'node:path'
95
+ import { resolveAmborasImageHosts, withAmborasCore } from '@amboras-dev/storefront-core/next-config'
96
+
97
+ const __dirname = dirname(fileURLToPath(import.meta.url))
98
+ const imageHosts = await resolveAmborasImageHosts()
99
+
100
+ /** @type {import('next').NextConfig} */
101
+ const nextConfig = {
102
+ /* store options */
103
+ }
104
+
105
+ export default withAmborasCore(nextConfig, { root: __dirname, imageHosts })
100
106
  ```
101
107
 
102
- `withAmborasCore` adds core to `transpilePackages`, pins `turbopack.root`, and limits
103
- `images.remotePatterns` to our storage/CDN hosts and the store's Medusa. A `hostname: '**'` pattern
104
- throws: it made `/_next/image` an open proxy. Pass real extra hosts with `imageHosts`.
108
+ **Keep that shape.** The orchestrator (e2b previews, `check_build`) and the Shopify cloner patch
109
+ `next.config.mjs` by regex, and all of them anchor on the literal `const nextConfig = {`. That is
110
+ where `allowedDevOrigins` (previews) and `distDir: process.env.NEXT_DIST_DIR` (`check_build`'s
111
+ isolated build) are injected. Keep the store's options in that literal object and apply core only
112
+ on the export line. `const nextConfig = withAmborasCore({...})` matches none of the patterns, so
113
+ previews and `check_build` silently lose their patches. `withAmborasCore` spreads the object, so
114
+ the injected keys survive. `test/core/next-config-patchers.test.ts` runs the orchestrator's and
115
+ the cloner's real patterns against this snippet. Resolve the hosts with a top-level `await`; never
116
+ export an async function.
117
+
118
+ `withAmborasCore` adds core to `transpilePackages`, pins `turbopack.root`, and builds
119
+ `images.remotePatterns` from exact hosts only. The hosts are platform data, not code.
120
+ `resolveAmborasImageHosts()` reads them once, at config load, from the first source that answers:
121
+
122
+ 1. the platform: `GET <platform>/api/v1/public/storefront/image-hosts?store=<NEXT_PUBLIC_STORE_ID>`,
123
+ with a 2s timeout. `<platform>` is `AMBORAS_PLATFORM_API_URL`, else derived from the Medusa host
124
+ (`api[-env].amboras.com` becomes `core[-env].amboras.com`), else `https://core.amboras.com`;
125
+ 2. `AMBORAS_IMAGE_HOSTS`: a JSON array or a comma list of exact host names;
126
+ 3. the baked fallback `AMBORAS_FALLBACK_IMAGE_HOSTS` (the template's 13 hosts).
127
+
128
+ The exact host of `NEXT_PUBLIC_MEDUSA_BACKEND_URL` is always added, and the local-dev hosts are
129
+ added when not on Vercel. It is the same algorithm as the template's
130
+ `amboras:image-hosts-reader` block. Without `imageHosts`, `withAmborasCore` uses
131
+ `AMBORAS_IMAGE_HOSTS` or the fallback list (it does not call the network). Any hostname containing `*`
132
+ throws, whether it is `**` or `*.cloudfront.net`, because a wildcard makes `/_next/image` an open
133
+ proxy.
134
+
135
+ **Release order:** the orchestrator's image-hosts endpoint must be live in production before any
136
+ production store adopts 2026.11.2. Without it a production build uses the fallback list. In a 1%
137
+ production sample of product images, about 4% were on merchant hosts that the list does not
138
+ include, so they would fail in `/_next/image`.
105
139
 
106
140
  Add `@source "../node_modules/@amboras-dev/storefront-core";` to `app/globals.css` (see
107
141
  `presets/tailwind.md`).
@@ -120,7 +154,17 @@ export const config = {
120
154
  }
121
155
  ```
122
156
 
123
- ### 6. Build gates
157
+ ### 6. Feature switches: unknown is not off
158
+
159
+ `useStoreConfig()` (client) and `getStoreConfig()` (server) read Medusa's `GET /store/config`. Each
160
+ feature flag is `true`, `false` or `null`, and `null` means unknown. Everything is unknown while
161
+ loading, on an older Medusa, on a 503 and on a network error, and a flag whose reader failed in
162
+ Medusa is `null` too. Gate UI with `isFeatureOff(feature)`, which is true only when Medusa said
163
+ `false`. Never read `features.x` as a boolean, because `null` is falsy and would hide a feature
164
+ nobody turned off. `checkout_settings` and `brand` are `null` when unknown. `useCheckoutSettings`
165
+ then falls back to `/store/checkout-settings`.
166
+
167
+ ### 7. Build gates
124
168
 
125
169
  ```bash
126
170
  npx amboras-check # plugin slots, store quirks, redirect boundaries, consent scroll
@@ -129,16 +173,16 @@ npx amboras-check slots # one gate
129
173
 
130
174
  ## Entry points
131
175
 
132
- | Entry | What | `"use client"` |
133
- | -------------------------- | --------------------------------------------------------------------------- | -------------- |
134
- | `/client` | `CoreProvider`, `ClientPluginSlot`, payment UI injection, config | yes |
135
- | `/client/<hook>` | one hook file, same exports as the template's | per file |
136
- | `/server` | `createPluginSlot`, `PluginSlot`, `getPluginConfigs`, `medusaFetch`, config | no |
137
- | `/lib/<path>` | logic modules (checkout, cart, payment providers, analytics, consent…) | per file |
138
- | `/edge` | `proxy`, `proxyConfig` | no |
139
- | `/next-config` | `withAmborasCore` | no |
140
- | `/config` | `configureCore`, `getCoreConfig` | no |
141
- | `/types`, `/types/plugins` | shared types, slot types | no |
176
+ | Entry | What | `"use client"` |
177
+ | -------------------------- | --------------------------------------------------------------------------------------------- | -------------- |
178
+ | `/client` | `CoreProvider`, `ClientPluginSlot`, payment UI injection, config | yes |
179
+ | `/client/<hook>` | one hook file, same exports as the template's | per file |
180
+ | `/server` | `createPluginSlot`, `PluginSlot`, `getPluginConfigs`, `medusaFetch`, `getStoreConfig`, config | no |
181
+ | `/lib/<path>` | logic modules (checkout, cart, payment providers, analytics, consent…) | per file |
182
+ | `/edge` | `proxy`, `proxyConfig` | no |
183
+ | `/next-config` | `withAmborasCore`, `resolveAmborasImageHosts` | no |
184
+ | `/config` | `configureCore`, `getCoreConfig` | no |
185
+ | `/types`, `/types/plugins` | shared types, slot types | no |
142
186
 
143
187
  `dist/` is `tsc` output, file for file: every `"use client"` stays on the file that had it.
144
188
 
@@ -146,7 +190,7 @@ npx amboras-check slots # one gate
146
190
 
147
191
  CalVer `YYYY.M.N` (`npm run version:next`). Plugins declare
148
192
  `peerDependencies['@amboras-dev/storefront-core']: '>=2026.11.0'`. Deprecated names stay exported
149
- for at least two minors. `api/*.api.md` is the public surface of `/client` and `/server`; CI fails
150
- when it changes without the report being updated.
193
+ for at least two minors. `api/*.api.md` is the public surface of `/client`, `/server` and
194
+ `/next-config`; CI fails when it changes without the report being updated.
151
195
 
152
196
  See [CONTRIBUTING.md](./CONTRIBUTING.md) for development and release.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$comment": "Generated by scripts/build-manifest.mjs. Paths are relative to the storefront app root.",
3
3
  "package": "@amboras-dev/storefront-core",
4
- "version": "2026.11.0",
4
+ "version": "2026.11.2",
5
5
  "shims": [
6
6
  {
7
7
  "path": "hooks/use-auth.ts",
@@ -173,6 +173,11 @@
173
173
  "import": "@amboras-dev/storefront-core/client/use-shipping-countries",
174
174
  "kind": "reexport"
175
175
  },
176
+ {
177
+ "path": "hooks/use-store-config.ts",
178
+ "import": "@amboras-dev/storefront-core/client/use-store-config",
179
+ "kind": "reexport"
180
+ },
176
181
  {
177
182
  "path": "hooks/use-store-credit.ts",
178
183
  "import": "@amboras-dev/storefront-core/client/use-store-credit",
@@ -443,6 +448,11 @@
443
448
  "import": "@amboras-dev/storefront-core/lib/store-api",
444
449
  "kind": "reexport"
445
450
  },
451
+ {
452
+ "path": "lib/store-config.ts",
453
+ "import": "@amboras-dev/storefront-core/lib/store-config",
454
+ "kind": "reexport"
455
+ },
446
456
  {
447
457
  "path": "lib/stripe/appearance.ts",
448
458
  "import": "@amboras-dev/storefront-core/lib/stripe/appearance",
@@ -2,4 +2,5 @@ export { createPluginSlot, PluginSlot, type PluginSlotProps } from '../shell/plu
2
2
  export { getPluginConfigs } from '../lib/plugin-config.js';
3
3
  export { configureCore, getCoreConfig, type CoreConfig, type CoreConfigInput } from '../config/index.js';
4
4
  export { medusaFetch, medusaBackendUrl, storeHeaders, storeGetJson, storePostJson } from '../lib/store-api.js';
5
+ export { getStoreConfig, isFeatureOff, isFeatureOn, DEFAULT_STORE_CONFIG, type StoreConfig, type StoreConfigFeatures, type StoreFeature, } from '../lib/store-config.js';
5
6
  //# sourceMappingURL=server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/entries/server.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,KAAK,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAC5F,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,KAAK,UAAU,EAAE,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACxG,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA"}
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/entries/server.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,KAAK,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAC5F,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,KAAK,UAAU,EAAE,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACxG,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAC9G,OAAO,EACL,cAAc,EACd,YAAY,EACZ,WAAW,EACX,oBAAoB,EACpB,KAAK,WAAW,EAChB,KAAK,mBAAmB,EACxB,KAAK,YAAY,GAClB,MAAM,wBAAwB,CAAA"}
@@ -4,4 +4,5 @@ export { createPluginSlot, PluginSlot } from '../shell/plugin-slot.js';
4
4
  export { getPluginConfigs } from '../lib/plugin-config.js';
5
5
  export { configureCore, getCoreConfig } from '../config/index.js';
6
6
  export { medusaFetch, medusaBackendUrl, storeHeaders, storeGetJson, storePostJson } from '../lib/store-api.js';
7
+ export { getStoreConfig, isFeatureOff, isFeatureOn, DEFAULT_STORE_CONFIG, } from '../lib/store-config.js';
7
8
  //# sourceMappingURL=server.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/entries/server.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,0EAA0E;AAC1E,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAwB,MAAM,yBAAyB,CAAA;AAC5F,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EAAE,aAAa,EAAE,aAAa,EAAyC,MAAM,oBAAoB,CAAA;AACxG,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA"}
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/entries/server.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,0EAA0E;AAC1E,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAwB,MAAM,yBAAyB,CAAA;AAC5F,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EAAE,aAAa,EAAE,aAAa,EAAyC,MAAM,oBAAoB,CAAA;AACxG,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAC9G,OAAO,EACL,cAAc,EACd,YAAY,EACZ,WAAW,EACX,oBAAoB,GAIrB,MAAM,wBAAwB,CAAA"}
@@ -1,3 +1,4 @@
1
+ import { type UseQueryResult } from '@tanstack/react-query';
1
2
  import { type CheckoutSettings } from '../lib/checkout-config.js';
2
3
  /**
3
4
  * Hook to fetch and cache checkout field configuration
@@ -8,7 +9,13 @@ import { type CheckoutSettings } from '../lib/checkout-config.js';
8
9
  * - Contact method (email only vs email or phone)
9
10
  * - Marketing opt-in behavior
10
11
  *
11
- * Settings are cached for 5 minutes and shared across checkout steps.
12
+ * Source: GET /store/config's `checkout_settings`, read through the SAME
13
+ * ['store-config'] query (`select`), so there is one cache, one staleTime
14
+ * (5 minutes), never a cache stacked on another. When that part is unknown
15
+ * (an older Medusa without the route, a 503 or network error, or Medusa
16
+ * answered `checkout_settings: null` because its reader failed) it falls
17
+ * back to GET /store/checkout-settings exactly as before. `data` is the
18
+ * defaults while loading (placeholder), never undefined.
12
19
  */
13
- export declare function useCheckoutSettings(): import("@tanstack/react-query").UseQueryResult<CheckoutSettings, Error>;
20
+ export declare function useCheckoutSettings(): UseQueryResult<CheckoutSettings>;
14
21
  //# sourceMappingURL=use-checkout-settings.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-checkout-settings.d.ts","sourceRoot":"","sources":["../../src/hooks/use-checkout-settings.ts"],"names":[],"mappings":"AACA,OAAO,EAAoD,KAAK,gBAAgB,EAAE,MAAM,2BAA2B,CAAA;AAEnH;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,4EAYlC"}
1
+ {"version":3,"file":"use-checkout-settings.d.ts","sourceRoot":"","sources":["../../src/hooks/use-checkout-settings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACrE,OAAO,EAAoD,KAAK,gBAAgB,EAAE,MAAM,2BAA2B,CAAA;AAWnH;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,mBAAmB,IAAI,cAAc,CAAC,gBAAgB,CAAC,CAsBtE"}
@@ -1,5 +1,11 @@
1
1
  import { useQuery } from '@tanstack/react-query';
2
2
  import { fetchCheckoutSettings, DEFAULT_CHECKOUT_SETTINGS } from '../lib/checkout-config.js';
3
+ import { DEFAULT_STORE_CONFIG } from '../lib/store-config.js';
4
+ import { storeConfigQuery } from './use-store-config.js';
5
+ const selectCheckoutSettings = (config) => config.available ? config.checkout_settings : null;
6
+ // Shown while /store/config loads (never written to the cache): selects to the
7
+ // default checkout settings, as the hook's placeholder always did.
8
+ const LOADING_PLACEHOLDER = { ...DEFAULT_STORE_CONFIG, available: true, checkout_settings: DEFAULT_CHECKOUT_SETTINGS };
3
9
  /**
4
10
  * Hook to fetch and cache checkout field configuration
5
11
  *
@@ -9,19 +15,35 @@ import { fetchCheckoutSettings, DEFAULT_CHECKOUT_SETTINGS } from '../lib/checkou
9
15
  * - Contact method (email only vs email or phone)
10
16
  * - Marketing opt-in behavior
11
17
  *
12
- * Settings are cached for 5 minutes and shared across checkout steps.
18
+ * Source: GET /store/config's `checkout_settings`, read through the SAME
19
+ * ['store-config'] query (`select`), so there is one cache, one staleTime
20
+ * (5 minutes), never a cache stacked on another. When that part is unknown
21
+ * (an older Medusa without the route, a 503 or network error, or Medusa
22
+ * answered `checkout_settings: null` because its reader failed) it falls
23
+ * back to GET /store/checkout-settings exactly as before. `data` is the
24
+ * defaults while loading (placeholder), never undefined.
13
25
  */
14
26
  export function useCheckoutSettings() {
15
- return useQuery({
27
+ const fromConfig = useQuery({
28
+ ...storeConfigQuery,
29
+ select: selectCheckoutSettings,
30
+ placeholderData: LOADING_PLACEHOLDER,
31
+ refetchOnWindowFocus: false,
32
+ retry: false, // fetchStoreConfig never throws
33
+ });
34
+ const unknown = fromConfig.isSuccess && !fromConfig.isPlaceholderData && fromConfig.data === null;
35
+ const legacy = useQuery({
16
36
  queryKey: ['checkout-settings'],
17
37
  queryFn: fetchCheckoutSettings,
38
+ enabled: unknown,
18
39
  staleTime: 5 * 60 * 1000, // 5 minutes
19
40
  gcTime: 10 * 60 * 1000, // 10 minutes
20
41
  refetchOnWindowFocus: false,
21
42
  refetchOnMount: false,
22
43
  // Always return defaults on error (never show error to user)
23
44
  placeholderData: DEFAULT_CHECKOUT_SETTINGS,
24
- retry: 1
45
+ retry: 1,
25
46
  });
47
+ return unknown ? legacy : fromConfig;
26
48
  }
27
49
  //# sourceMappingURL=use-checkout-settings.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-checkout-settings.js","sourceRoot":"","sources":["../../src/hooks/use-checkout-settings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAChD,OAAO,EAAE,qBAAqB,EAAE,yBAAyB,EAAyB,MAAM,2BAA2B,CAAA;AAEnH;;;;;;;;;;GAUG;AACH,MAAM,UAAU,mBAAmB;IACjC,OAAO,QAAQ,CAAmB;QAChC,QAAQ,EAAE,CAAC,mBAAmB,CAAC;QAC/B,OAAO,EAAE,qBAAqB;QAC9B,SAAS,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE,YAAY;QACtC,MAAM,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,aAAa;QACrC,oBAAoB,EAAE,KAAK;QAC3B,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AAS,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE,YAAY;QACtC,MAAM,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,aAAa;QACrC,oBAAoB,EAAE,KAAK;QAC3B,cAAc,EAAE,KAAK;QACrB,6DAA6D;QAC7D,eAAe,EAAE,yBAAyB;QAC1C,KAAK,EAAE,CAAC;KACT,CAAC,CAAA;IACF,OAAO,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAE,UAA+C,CAAA;AAC5E,CAAC"}
@@ -0,0 +1,43 @@
1
+ import { DEFAULT_STORE_CONFIG, fetchStoreConfig, isFeatureOff, isFeatureOn, type StoreConfig, type StoreConfigFeatures, type StoreFeature } from '../lib/store-config.js';
2
+ export { DEFAULT_STORE_CONFIG, isFeatureOff, isFeatureOn, type StoreConfig, type StoreConfigFeatures, type StoreFeature, };
3
+ /**
4
+ * The shared query for GET /store/config. Other hooks read it through
5
+ * `queryClient.fetchQuery(storeConfigQuery)`, or `useQuery({ ...storeConfigQuery, select })`,
6
+ * so the whole page makes one call and holds one cache entry. The queryFn
7
+ * never throws: a route that does not answer (older Medusa 404, a 503, a
8
+ * network error) yields DEFAULT_STORE_CONFIG, every part unknown.
9
+ */
10
+ export declare const storeConfigQuery: {
11
+ queryKey: readonly ["store-config"];
12
+ queryFn: typeof fetchStoreConfig;
13
+ staleTime: number;
14
+ gcTime: number;
15
+ };
16
+ /**
17
+ * The store's feature switches, checkout settings and brand from Medusa's
18
+ * GET /store/config.
19
+ *
20
+ * UNKNOWN IS NOT OFF. While loading, on an older Medusa, on a 503 or a
21
+ * network error every part is unknown: each `features` flag is `null`, and
22
+ * `checkout_settings` / `brand` are `null`. A flag whose reader failed in
23
+ * Medusa is `null` too. Gate UI with `isFeatureOff('store_credit')` (true only
24
+ * when Medusa said `false`) or `isFeatureOn(...)`; never treat `features.x`
25
+ * as a boolean, `null` is falsy.
26
+ */
27
+ export declare function useStoreConfig(): {
28
+ config: StoreConfig;
29
+ /** Raw flags: `true` / `false` as Medusa answered, `null` = unknown (loading, older Medusa, failed read). Prefer `isFeatureOff`. */
30
+ features: StoreConfigFeatures;
31
+ /** The route answered (false while loading, on older backends, on a 503 or network error). */
32
+ available: boolean;
33
+ /** The route answered AND its checkout_settings part is known (else fall back to /store/checkout-settings). */
34
+ checkoutSettingsAvailable: boolean;
35
+ /** The route answered AND its brand part is known. */
36
+ brandAvailable: boolean;
37
+ /** True only when Medusa said `feature` is off. The safe gate. */
38
+ isFeatureOff: (feature: StoreFeature) => boolean;
39
+ /** True only when Medusa said `feature` is on. */
40
+ isFeatureOn: (feature: StoreFeature) => boolean;
41
+ isLoading: boolean;
42
+ };
43
+ //# sourceMappingURL=use-store-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-store-config.d.ts","sourceRoot":"","sources":["../../src/hooks/use-store-config.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACX,KAAK,WAAW,EAChB,KAAK,mBAAmB,EACxB,KAAK,YAAY,EAClB,MAAM,wBAAwB,CAAA;AAE/B,OAAO,EACL,oBAAoB,EACpB,YAAY,EACZ,WAAW,EACX,KAAK,WAAW,EAChB,KAAK,mBAAmB,EACxB,KAAK,YAAY,GAClB,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB;;;;;CAK5B,CAAA;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc;;IAS1B,oIAAoI;;IAEpI,8FAA8F;;IAE9F,+GAA+G;;IAE/G,sDAAsD;;IAEtD,kEAAkE;4BAC1C,YAAY;IACpC,kDAAkD;2BAC3B,YAAY;;EAGtC"}
@@ -0,0 +1,53 @@
1
+ 'use client';
2
+ import { useQuery } from '@tanstack/react-query';
3
+ import { DEFAULT_STORE_CONFIG, fetchStoreConfig, isFeatureOff, isFeatureOn, } from '../lib/store-config.js';
4
+ export { DEFAULT_STORE_CONFIG, isFeatureOff, isFeatureOn, };
5
+ /**
6
+ * The shared query for GET /store/config. Other hooks read it through
7
+ * `queryClient.fetchQuery(storeConfigQuery)`, or `useQuery({ ...storeConfigQuery, select })`,
8
+ * so the whole page makes one call and holds one cache entry. The queryFn
9
+ * never throws: a route that does not answer (older Medusa 404, a 503, a
10
+ * network error) yields DEFAULT_STORE_CONFIG, every part unknown.
11
+ */
12
+ export const storeConfigQuery = {
13
+ queryKey: ['store-config'],
14
+ queryFn: fetchStoreConfig,
15
+ staleTime: 5 * 60 * 1000,
16
+ gcTime: 10 * 60 * 1000,
17
+ };
18
+ /**
19
+ * The store's feature switches, checkout settings and brand from Medusa's
20
+ * GET /store/config.
21
+ *
22
+ * UNKNOWN IS NOT OFF. While loading, on an older Medusa, on a 503 or a
23
+ * network error every part is unknown: each `features` flag is `null`, and
24
+ * `checkout_settings` / `brand` are `null`. A flag whose reader failed in
25
+ * Medusa is `null` too. Gate UI with `isFeatureOff('store_credit')` (true only
26
+ * when Medusa said `false`) or `isFeatureOn(...)`; never treat `features.x`
27
+ * as a boolean, `null` is falsy.
28
+ */
29
+ export function useStoreConfig() {
30
+ const query = useQuery({
31
+ ...storeConfigQuery,
32
+ refetchOnWindowFocus: false,
33
+ retry: false,
34
+ });
35
+ const config = query.data ?? DEFAULT_STORE_CONFIG;
36
+ return {
37
+ config,
38
+ /** Raw flags: `true` / `false` as Medusa answered, `null` = unknown (loading, older Medusa, failed read). Prefer `isFeatureOff`. */
39
+ features: config.features,
40
+ /** The route answered (false while loading, on older backends, on a 503 or network error). */
41
+ available: config.available,
42
+ /** The route answered AND its checkout_settings part is known (else fall back to /store/checkout-settings). */
43
+ checkoutSettingsAvailable: config.available && config.checkout_settings !== null,
44
+ /** The route answered AND its brand part is known. */
45
+ brandAvailable: config.available && config.brand !== null,
46
+ /** True only when Medusa said `feature` is off. The safe gate. */
47
+ isFeatureOff: (feature) => isFeatureOff(config, feature),
48
+ /** True only when Medusa said `feature` is on. */
49
+ isFeatureOn: (feature) => isFeatureOn(config, feature),
50
+ isLoading: query.isLoading,
51
+ };
52
+ }
53
+ //# sourceMappingURL=use-store-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-store-config.js","sourceRoot":"","sources":["../../src/hooks/use-store-config.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAChD,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,YAAY,EACZ,WAAW,GAIZ,MAAM,wBAAwB,CAAA;AAE/B,OAAO,EACL,oBAAoB,EACpB,YAAY,EACZ,WAAW,GAIZ,CAAA;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,QAAQ,EAAE,CAAC,cAAc,CAAU;IACnC,OAAO,EAAE,gBAAgB;IACzB,SAAS,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI;IACxB,MAAM,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI;CACvB,CAAA;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,cAAc;IAC5B,MAAM,KAAK,GAAG,QAAQ,CAAc;QAClC,GAAG,gBAAgB;QACnB,oBAAoB,EAAE,KAAK;QAC3B,KAAK,EAAE,KAAK;KACb,CAAC,CAAA;IACF,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,IAAI,oBAAoB,CAAA;IACjD,OAAO;QACL,MAAM;QACN,oIAAoI;QACpI,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,8FAA8F;QAC9F,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,+GAA+G;QAC/G,yBAAyB,EAAE,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,iBAAiB,KAAK,IAAI;QAChF,sDAAsD;QACtD,cAAc,EAAE,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,KAAK,KAAK,IAAI;QACzD,kEAAkE;QAClE,YAAY,EAAE,CAAC,OAAqB,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC;QACtE,kDAAkD;QAClD,WAAW,EAAE,CAAC,OAAqB,EAAE,EAAE,CAAC,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC;QACpE,SAAS,EAAE,KAAK,CAAC,SAAS;KAC3B,CAAA;AACH,CAAC"}
@@ -10,7 +10,11 @@ import type { Cart } from '../types/index.js';
10
10
  * Every amount comes from Medusa: the storefront sends apply / remove and
11
11
  * reads `cart.credit_lines` (reference 'store_credit') and `cart.store_credit`
12
12
  * back. A backend without the routes (older Medusa, feature off) answers
13
- * 404 → treated as "no store credit".
13
+ * 404 → treated as "no store credit". When GET /store/config says
14
+ * `features.store_credit: false` the balance is not requested at all. When
15
+ * the flag is unknown (a Medusa without /store/config, a 503 or network
16
+ * error, or `null` because Medusa's reader failed) it keeps the old
17
+ * behaviour (ask, 404 → none): unknown never hides store credit.
14
18
  */
15
19
  export interface StoreCreditAccountView {
16
20
  currency_code: string;
@@ -1 +1 @@
1
- {"version":3,"file":"use-store-credit.d.ts","sourceRoot":"","sources":["../../src/hooks/use-store-credit.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AAE7C;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,sBAAsB;IACrC,aAAa,EAAE,MAAM,CAAA;IACrB,qEAAqE;IACrE,OAAO,EAAE,MAAM,CAAA;IACf,WAAW,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAA;CAC/E;AAED,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,OAAO,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,sBAAsB,EAAE,CAAA;CACnC;AAcD,4FAA4F;AAC5F,wBAAgB,qBAAqB,CAAC,OAAO,UAAO,6EAcnD;AAED,4DAA4D;A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AAa,gBAAiB,SAAQ,KAAK;aAGvB,IAAI,EAAE,MAAM,GAAG,IAAI;aACnB,MAAM,EAAE,MAAM;gBAF9B,OAAO,EAAE,MAAM,EACC,IAAI,EAAE,MAAM,GAAG,IAAI,EACnB,MAAM,EAAE,MAAM;CAKjC;AAmBD;;;;GAIG;AACH,wBAAgB,mBAAmB;YAGiB,MAAM;WAAS,OAAO;YAazE;AAED,gFAAgF;AAChF,wBAAsB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAOtE"}
@@ -4,6 +4,8 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
4
4
  import { getMedusaClient } from '../lib/medusa-client.js';
5
5
  import { logger } from '../lib/logger.js';
6
6
  import { medusaBackendUrl, storeHeaders } from '../lib/store-api.js';
7
+ import { isFeatureOff } from '../lib/store-config.js';
8
+ import { storeConfigQuery } from './use-store-config.js';
7
9
  const AUTH_TOKEN_KEY = 'medusa_auth_token';
8
10
  /** Store headers (tenant from the publishable key alone) plus the customer's bearer token. */
9
11
  function storeCreditHeaders() {
@@ -17,12 +19,15 @@ const NONE = { enabled: false, timezone: 'UTC', accounts: [] };
17
19
  /** The signed-in customer's store credit; `NONE` for guests and when the feature is off. */
18
20
  export function useStoreCreditBalance(enabled = true) {
19
21
  const storeId = getCoreConfig().storeId;
22
+ const queryClient = useQueryClient();
20
23
  return useQuery({
21
24
  queryKey: ['store-credit', storeId],
22
25
  enabled,
23
26
  staleTime: 15 * 1000,
24
27
  retry: false,
25
28
  queryFn: async () => {
29
+ if (isFeatureOff(await queryClient.fetchQuery(storeConfigQuery), 'store_credit'))
30
+ return NONE;
26
31
  const res = await fetch(`${medusaBackendUrl()}/store/customers/me/store-credit`, { headers: storeCreditHeaders(), cache: 'no-store' });
27
32
  if (res.status === 401 || res.status === 404)
28
33
  return NONE;
@@ -1 +1 @@
1
- {"version":3,"file":"use-store-credit.js","sourceRoot":"","sources":["../../src/hoo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,KAAK,EAAE,EAAE,MAAM,EAAE,KAAK,EAAsC,EAAE,EAAE,CAC1E,sBAAsB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC;QAC3D,SAAS,EAAE,CAAC,IAAI,EAAE,EAAE;YAClB,WAAW,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,CAAA;QAC1C,CAAC;QACD,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;YACjB,MAAM,CAAC,IAAI,CAAC,kCAAkC,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;QAC5D,CAAC;QACD,SAAS,EAAE,GAAG,EAAE;YACd,WAAW,CAAC,iBAAiB,CAAC,EAAE,QAAQ,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;YACrD,WAAW,CAAC,iBAAiB,CAAC,EAAE,QAAQ,EAAE,CAAC,cAAc,CAAC,EAAE,CAAC,CAAA;QAC/D,CAAC;KACF,CAAC,CAAA;AACJ,CAAC;AAED,gFAAgF;AAChF,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,MAAc;IAC9C,IAAI,CAAC;QACH,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,eAAe,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;QACpE,OAAO,IAAuB,CAAA;IAChC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC"}
@@ -146,8 +146,11 @@ export interface UseSubscriptionOffersOptions {
146
146
  }
147
147
  /**
148
148
  * Fetch a page of the store's active subscription offers, newest first.
149
- * Empty when Subscribe & Save is off store-wide. Cached 5 minutes client-side
150
- * (the backend caches it too) — offers are rare merchant edits.
149
+ * Empty when Subscribe & Save is off store-wide (GET /store/config's
150
+ * `features.subscriptions: false` answers empty without the offers call; an
151
+ * unknown flag (older Medusa, a 503 or network error, or `null`) asks as
152
+ * before: unknown never hides offers). Cached 5 minutes client-side (the backend
153
+ * caches it too) — offers are rare merchant edits.
151
154
  */
152
155
  export declare function useSubscriptionOffers(opts?: UseSubscriptionOffersOptions): import("@tanstack/react-query").UseQueryResult<SubscriptionOffersPage, Error>;
153
156
  /** Narrow an offer's open-union type before switching on it. */
@@ -1 +1 @@
1
- {"version":3,"file":"use-subscription-offers.d.ts","sourceRoot":"","sources":["../../src/hooks/use-subscription-offers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAOH,4DAA4D;AAC5D,MAAM,WAAW,qBAAqB;IACpC,yFAAyF;IACzF,KAAK,EAAE,MAAM,CAAA;IACb,oEAAoE;IACpE,KAAK,EAAE,MAAM,CAAA;IACb,uBAAuB;IACvB,IAAI,EAAE,MAAM,CAAA;IACZ,8DAA8D;IAC9D,QAAQ,EAAE,OAAO,CAAA;CAClB;AAED,+EAA+E;AAC/E,MAAM,WAAW,mBAAmB;IAClC,8EAA8E;IAC9E,QAAQ,EAAE,OAAO,CAAA;IACjB;;;OAGG;IACH,iBAAiB,EAAE,OAAO,CAAA;IAC1B,iEAAiE;IACjE,WAAW,EAAE,qBAAqB,EAAE,CAAA;IACpC,6EAA6E;IAC7E,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAA;CACjC;AAED,6DAA6D;AAC7D,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI,CAAC,GAAG;IAAE,YAAY,CAAC,EAAE,mBAAmB,CAAA;CAAE,CAAA;AAI5E,wFAAwF;AACxF,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,YAAY,GAAG,cAAc,CAAA;IACnC,KAAK,EAAE,MAAM,CAAA;CACd;AAED,2DAA2D;AAC3D,eAAO,MAAM,iBAAiB,0HAMpB,CAAA;AAEV,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAA;AAE/D;;;;;GAKG;AACH,MAAM,MAAM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row with `isKnownOfferType()`); the cart still prices them
24
24
  * correctly, the UI just doesn't advertise them until it learns the type.
25
25
  */
26
- import { useQuery } from '@tanstack/react-query';
26
+ import { useQuery, useQueryClient } from '@tanstack/react-query';
27
27
  import { getMedusaClient } from '../lib/medusa-client.js';
28
+ import { isFeatureOff } from '../lib/store-config.js';
29
+ import { storeConfigQuery } from './use-store-config.js';
28
30
  /** The 5 offer types this storefront build knows about. */
29
31
  export const KNOWN_OFFER_TYPES = [
30
32
  'product_discount',
@@ -35,17 +37,26 @@ export const KNOWN_OFFER_TYPES = [
35
37
  ];
36
38
  /**
37
39
  * Fetch a page of the store's active subscription offers, newest first.
38
- * Empty when Subscribe & Save is off store-wide. Cached 5 minutes client-side
39
- * (the backend caches it too) — offers are rare merchant edits.
40
+ * Empty when Subscribe & Save is off store-wide (GET /store/config's
41
+ * `features.subscriptions: false` answers empty without the offers call; an
42
+ * unknown flag (older Medusa, a 503 or network error, or `null`) asks as
43
+ * before: unknown never hides offers). Cached 5 minutes client-side (the backend
44
+ * caches it too) — offers are rare merchant edits.
40
45
  */
41
46
  export function useSubscriptionOffers(opts) {
42
47
  const limit = opts?.limit ?? 20;
43
48
  const offset = opts?.offset ?? 0;
49
+ const queryClient = useQueryClient();
44
50
  return useQuery({
45
51
  queryKey: ['subscription-offers', limit, offset],
46
- queryFn: async () => getMedusaClient().client.fetch('/store/subscription-offers', {
47
- query: { limit, offset },
48
- }),
52
+ queryFn: async () => {
53
+ if (isFeatureOff(await queryClient.fetchQuery(storeConfigQuery), 'subscriptions')) {
54
+ return { offers: [], count: 0, limit, offset };
55
+ }
56
+ return getMedusaClient().client.fetch('/store/subscription-offers', {
57
+ query: { limit, offset },
58
+ });
59
+ },
49
60
  staleTime: 5 * 60 * 1000,
50
61
  });
51
62
  }
@@ -1 +1 @@
1
- {"version":3,"file":"use-subscription-offers.js","sourceRoot":"","sources":["../../src/hooks/use-subscription-offers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;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