@fanfare-io/fanfare-sdk-shopify 0.4.0 → 0.5.0

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/config.d.ts CHANGED
@@ -40,18 +40,19 @@ export interface ShopifyAdapterConfig {
40
40
  * product/experience id never appears here. The adapter's job is to map this to a
41
41
  * Fanfare experience id.
42
42
  *
43
- * Experience resolution keys on `handle` only (the live app-proxy read and
44
- * the `map` / `metafieldValues` lookups all index by handle), so `handle` is the
45
- * one required field. `id` is OPTIONAL: it is carried for forward-compat (it flows
46
- * through to the claim/checkout path and may matter to future resolution
47
- * strategies) but no current path reads it, so you can pass `{ handle }` alone.
43
+ * Experience resolution prefers `handle` (the `map` / `metafieldValues` lookups
44
+ * index by handle), so `handle` is the primary field. `id` is OPTIONAL: the live
45
+ * app-proxy read falls back to it when `handle` is empty/absent, and it flows
46
+ * through to the claim/checkout path. The preloaded handle-keyed maps never read
47
+ * `id`, so an id-only ref resolves via the live read, not those maps.
48
48
  */
49
49
  export interface ShopifyProductRef {
50
50
  /** The product handle, e.g. "limited-drop-tee". The key experience resolution
51
51
  * uses. Required. */
52
52
  handle: string;
53
- /** The product GID, e.g. "gid://shopify/Product/123". Optional — carried for
54
- * forward-compat; no current resolution path reads it. */
53
+ /** The product GID, e.g. "gid://shopify/Product/123". Optional — the live
54
+ * app-proxy read falls back to it when `handle` is empty/absent; the preloaded
55
+ * handle-keyed maps do not use it. */
55
56
  id?: string;
56
57
  }
57
58
  /**
@@ -1,3 +1,3 @@
1
1
  "use client";
2
- import{jsx as r}from"react/jsx-runtime";import{useState as e,useRef as n,useCallback as t,useMemo as o,createContext as i,useContext as u}from"react";import{getParticipation as s,getDistribution as a}from"@fanfare-io/fanfare-sdk-core/internals";import{snapshotToAccessStatus as c}from"@fanfare-io/fanfare-sdk-core/storefront";import{assertShopifyConfig as l}from"../config.js";import{shopifyCheckoutVerifier as f}from"../verifier.js";const d={source:"metafield"},p="storefront_adapter_grant",m=i(null);function h(){if("undefined"==typeof window)return null;try{return function(r){if(null===r)return null;try{return JSON.parse(r)}catch{return null}}(window.sessionStorage.getItem(p))}catch{return null}}function y({organizationId:i,publishableKey:u,mode:y="production",shopify:g,experiences:w=d,children:v}){l({mode:y,shopify:g});const[I,S]=e(null),[b,x]=e(()=>h()),k=n(null),j=n(null);j.current=I;const C=n(null);C.current=b;const z=t(r=>{S(r)},[]),A=t(r=>{x(r);try{window.sessionStorage.setItem(p,JSON.stringify(r))}catch{}},[]),G=t(()=>{x(null);try{window.sessionStorage.removeItem(p)}catch{}},[]),J=t(r=>{k.current=r},[]),K=t(()=>{const r=C.current?.token,e=function(r){if(null!==r)return s(r)?.id??a(r)?.id}(j.current),n=k.current;return void 0===r||void 0===e||null===n?null:{credential:r,distributionId:e,cartId:n}},[]),N=o(()=>f,[]),O=o(()=>({organizationId:i,publishableKey:u,mode:y,shopify:g,experiences:w}),[i,u,y,g,w]),P=o(()=>({config:O,snapshot:I,status:c(I),grant:b,reportSnapshot:z,recordGrant:A,clearGrant:G,verifier:N,setActiveCartId:J,getCheckoutContext:K}),[O,I,b,z,A,G,N,J,K]);/* @__PURE__ */
3
- return r(m.Provider,{value:P,children:v})}function g(){const r=u(m);if(null===r)throw new Error("useShopifyAdapter must be used within FanfareShopifyProvider");return r}export{y as FanfareShopifyProvider,g as useShopifyAdapter};
2
+ import{jsx as r}from"react/jsx-runtime";import{useState as e,useRef as n,useCallback as t,useMemo as o,useContext as i,createContext as u}from"react";import{getParticipation as s,getDistribution as a}from"@fanfare-io/fanfare-sdk-core/internals";import{snapshotToAccessStatus as c}from"@fanfare-io/fanfare-sdk-core/storefront";import{assertShopifyConfig as l}from"../config.js";import{shopifyCheckoutVerifier as f}from"../verifier.js";const d={source:"metafield"},p="storefront_adapter_grant",m=u(null);function h(){if("undefined"==typeof window)return null;try{return function(r){if(null===r)return null;try{return JSON.parse(r)}catch{return null}}(window.sessionStorage.getItem(p))}catch{return null}}function y({organizationId:i,publishableKey:u,mode:y="production",shopify:g,experiences:w=d,children:v}){l({mode:y,shopify:g});const[I,S]=e(null),[b,x]=e(()=>h()),k=n(null),j=n(null);j.current=I;const C=n(null);C.current=b;const z=t(r=>{S(r)},[]),A=t(r=>{x(r);try{window.sessionStorage.setItem(p,JSON.stringify(r))}catch{}},[]),G=t(()=>{x(null);try{window.sessionStorage.removeItem(p)}catch{}},[]),J=t(r=>{k.current=r},[]),K=t(()=>{const r=C.current?.token,e=function(r){if(null!==r)return s(r)?.id??a(r)?.id}(j.current),n=k.current;return void 0===r||void 0===e||null===n?null:{credential:r,distributionId:e,cartId:n}},[]),N=o(()=>f,[]),O=o(()=>({organizationId:i,publishableKey:u,mode:y,shopify:g,experiences:w}),[i,u,y,g,w]),P=o(()=>({config:O,snapshot:I,status:c(I),grant:b,reportSnapshot:z,recordGrant:A,clearGrant:G,verifier:N,setActiveCartId:J,getCheckoutContext:K}),[O,I,b,z,A,G,N,J,K]);/* @__PURE__ */
3
+ return r(m.Provider,{value:P,children:v})}function g(){const r=i(m);if(null===r)throw new Error("useShopifyAdapter must be used within FanfareShopifyProvider");return r}export{y as FanfareShopifyProvider,g as useShopifyAdapter};
package/dist/resolver.js CHANGED
@@ -1 +1 @@
1
- import{parseFirstExperienceId as e}from"./metafield.js";async function n(e,n){const r=n.fetchImpl??globalThis.fetch,t=`${n.proxyBaseUrl.replace(/\/+$/,"")}/experiences/ids-by-handle/${encodeURIComponent(e.handle)}`;try{const e=await r(t,{method:"GET"});if(!e.ok)return null;return function(e){if("object"!=typeof e||null===e)return null;const n=e.experienceIds;if(!Array.isArray(n))return null;const r=n[0];return"string"==typeof r?r:null}(await e.json())}catch{return null}}async function r(r,t){if(void 0!==t.resolveExperience)try{return await t.resolveExperience(r)??null}catch{return null}const l=t.metafieldValues?.[r.handle];return void 0!==l?e(l):n(r,t)}export{r as resolveShopifyExperienceId};
1
+ import{parseFirstExperienceId as e}from"./metafield.js";async function n(e,n){const r=n.fetchImpl??globalThis.fetch,t=n.proxyBaseUrl.replace(/\/+$/,""),l=e.handle?.trim()?e.handle:e.id??"",o=`${t}/experiences/ids-by-handle/${encodeURIComponent(l)}`;try{const e=await r(o,{method:"GET"});if(!e.ok)return null;return function(e){if("object"!=typeof e||null===e)return null;const n=e.experienceIds;if(!Array.isArray(n))return null;const r=n[0];return"string"==typeof r?r:null}(await e.json())}catch{return null}}async function r(r,t){if(void 0!==t.resolveExperience)try{return await t.resolveExperience(r)??null}catch{return null}const l=t.metafieldValues?.[r.handle];return void 0!==l?e(l):n(r,t)}export{r as resolveShopifyExperienceId};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fanfare-io/fanfare-sdk-shopify",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Shopify storefront adapter for Fanfare SDK: product→experience resolver, checkout verifier, and experienceIds metafield primitives",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org",
@@ -39,7 +39,7 @@
39
39
  "peerDependencies": {
40
40
  "react": "^18.0.0 || ^19.1.1",
41
41
  "react-dom": "^18.0.0 || ^19.1.1",
42
- "@fanfare-io/fanfare-sdk-core": "0.4.0"
42
+ "@fanfare-io/fanfare-sdk-core": "0.5.0"
43
43
  },
44
44
  "peerDependenciesMeta": {
45
45
  "react": {
@@ -60,11 +60,11 @@
60
60
  "react-dom": "^19.1.1",
61
61
  "rimraf": "^6.0.1",
62
62
  "typescript": "^5.9.2",
63
- "vite": "^7.3.1",
63
+ "vite": "^7.3.5",
64
64
  "vite-plugin-dts": "^4.5.4",
65
65
  "vite-tsconfig-paths": "^5.1.4",
66
66
  "vitest": "^3.2.4",
67
- "@fanfare-io/fanfare-sdk-core": "0.4.0"
67
+ "@fanfare-io/fanfare-sdk-core": "0.5.0"
68
68
  },
69
69
  "sideEffects": false,
70
70
  "keywords": [