@nok-integration/storefront-react 0.29.5 → 0.29.7

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.d.ts CHANGED
@@ -6054,6 +6054,7 @@ declare interface ShopContextValue {
6054
6054
  subscribe: (listener: OnEvent) => () => void;
6055
6055
  navigate: (to: ShopRoute) => void;
6056
6056
  prefetch: ((to: ShopRoute) => void) | null;
6057
+ hasSession: () => Promise<boolean>;
6057
6058
  }
6058
6059
 
6059
6060
  export declare type ShopEvent = {
package/dist/index.mjs CHANGED
@@ -5749,6 +5749,14 @@ function DaznShopProvider({ children, ...config }) {
5749
5749
  const getTokenRef = useRef(getToken);
5750
5750
  getTokenRef.current = getToken;
5751
5751
  const stableGetToken = useCallback(() => getTokenRef.current(), []);
5752
+ const hasSession = useCallback(async () => {
5753
+ if (sessionTransport === "cookie") return true;
5754
+ try {
5755
+ return Boolean(await getTokenRef.current());
5756
+ } catch {
5757
+ return false;
5758
+ }
5759
+ }, [sessionTransport]);
5752
5760
  const productsRef = useRef(null);
5753
5761
  productsRef.current ??= new ProductCache();
5754
5762
  const products2 = productsRef.current;
@@ -5837,8 +5845,9 @@ function DaznShopProvider({ children, ...config }) {
5837
5845
  emit,
5838
5846
  subscribe,
5839
5847
  navigate,
5840
- prefetch: hostPrefetch ?? null
5841
- }), [api, market, products2, theme, resolvedFeatures, notifications, locale, assetBaseUrl, emit, subscribe, navigate, hostPrefetch]);
5848
+ prefetch: hostPrefetch ?? null,
5849
+ hasSession
5850
+ }), [api, market, products2, theme, resolvedFeatures, notifications, locale, assetBaseUrl, emit, subscribe, navigate, hostPrefetch, hasSession]);
5842
5851
  return jsx(ShopContext.Provider, {
5843
5852
  value: value2,
5844
5853
  children: jsx(CartCacheContext.Provider, {
@@ -9748,6 +9757,7 @@ function OrderListContent({ onOpenOrder, onOpenReturn, onStartShopping, locale:
9748
9757
  if (state === "loading") {
9749
9758
  return jsxs("div", {
9750
9759
  className: styles$A.page,
9760
+ "data-shop-layout": "wide",
9751
9761
  children: [jsx(Skeleton, {
9752
9762
  height: 148,
9753
9763
  radius: 12
@@ -14999,7 +15009,7 @@ function heroFromProduct(product, ctaLabel) {
14999
15009
  function ActiveLanding({ token, invite, screen: screen2 }) {
15000
15010
  const t = useT();
15001
15011
  const toast2 = useToast();
15002
- const { api, emit } = useShop();
15012
+ const { api, emit, hasSession } = useShop();
15003
15013
  const navigate = useNavigate();
15004
15014
  const sku = invite.items[0]?.product_sku ?? "";
15005
15015
  const loaded = useProduct(sku, {
@@ -15012,7 +15022,21 @@ function ActiveLanding({ token, invite, screen: screen2 }) {
15012
15022
  else window.location.assign(to);
15013
15023
  }, [navigate]);
15014
15024
  const fallback = useMemo(() => loaded.product ? heroFromProduct(loaded.product, t("See more")) : null, [loaded.product, t]);
15025
+ const shop2 = useCallback(async () => {
15026
+ if (await hasSession()) go(productPath);
15027
+ else emit({
15028
+ type: "session_required",
15029
+ action: "vip_claim"
15030
+ });
15031
+ }, [emit, go, hasSession, productPath]);
15015
15032
  const claim = useCallback(async (variantSku) => {
15033
+ if (!await hasSession()) {
15034
+ emit({
15035
+ type: "session_required",
15036
+ action: "vip_claim"
15037
+ });
15038
+ return;
15039
+ }
15016
15040
  try {
15017
15041
  const current2 = await api.cart.get().catch(() => null);
15018
15042
  if (current2?.vip?.invite_ref === invite.invite_ref) {
@@ -15053,12 +15077,12 @@ function ActiveLanding({ token, invite, screen: screen2 }) {
15053
15077
  });
15054
15078
  toast2.show(t(treatmentFor(code).body), "critical");
15055
15079
  }
15056
- }, [api, emit, invite.invite_ref, t, toast2, token]);
15080
+ }, [api, emit, hasSession, invite.invite_ref, t, toast2, token]);
15057
15081
  if (screen2 === "hero") {
15058
15082
  const hero2 = invite.hero ?? fallback;
15059
15083
  if (hero2) return jsx(VipHero, {
15060
15084
  hero: hero2,
15061
- onContinue: () => go(productPath)
15085
+ onContinue: () => void shop2()
15062
15086
  });
15063
15087
  } else if (loaded.product) {
15064
15088
  return jsx(ProductDetail, {
@@ -5749,6 +5749,14 @@ function DaznShopProvider({ children, ...config }) {
5749
5749
  const getTokenRef = useRef(getToken);
5750
5750
  getTokenRef.current = getToken;
5751
5751
  const stableGetToken = useCallback(() => getTokenRef.current(), []);
5752
+ const hasSession = useCallback(async () => {
5753
+ if (sessionTransport === "cookie") return true;
5754
+ try {
5755
+ return Boolean(await getTokenRef.current());
5756
+ } catch {
5757
+ return false;
5758
+ }
5759
+ }, [sessionTransport]);
5752
5760
  const productsRef = useRef(null);
5753
5761
  productsRef.current ??= new ProductCache();
5754
5762
  const products2 = productsRef.current;
@@ -5837,8 +5845,9 @@ function DaznShopProvider({ children, ...config }) {
5837
5845
  emit,
5838
5846
  subscribe,
5839
5847
  navigate,
5840
- prefetch: hostPrefetch ?? null
5841
- }), [api, market, products2, theme, resolvedFeatures, notifications, locale, assetBaseUrl, emit, subscribe, navigate, hostPrefetch]);
5848
+ prefetch: hostPrefetch ?? null,
5849
+ hasSession
5850
+ }), [api, market, products2, theme, resolvedFeatures, notifications, locale, assetBaseUrl, emit, subscribe, navigate, hostPrefetch, hasSession]);
5842
5851
  return jsx(ShopContext.Provider, {
5843
5852
  value: value2,
5844
5853
  children: jsx(CartCacheContext.Provider, {
@@ -9748,6 +9757,7 @@ function OrderListContent({ onOpenOrder, onOpenReturn, onStartShopping, locale:
9748
9757
  if (state === "loading") {
9749
9758
  return jsxs("div", {
9750
9759
  className: styles$A.page,
9760
+ "data-shop-layout": "wide",
9751
9761
  children: [jsx(Skeleton, {
9752
9762
  height: 148,
9753
9763
  radius: 12
@@ -14999,7 +15009,7 @@ function heroFromProduct(product, ctaLabel) {
14999
15009
  function ActiveLanding({ token, invite, screen: screen2 }) {
15000
15010
  const t = useT();
15001
15011
  const toast2 = useToast();
15002
- const { api, emit } = useShop();
15012
+ const { api, emit, hasSession } = useShop();
15003
15013
  const navigate = useNavigate();
15004
15014
  const sku = invite.items[0]?.product_sku ?? "";
15005
15015
  const loaded = useProduct(sku, {
@@ -15012,7 +15022,21 @@ function ActiveLanding({ token, invite, screen: screen2 }) {
15012
15022
  else window.location.assign(to);
15013
15023
  }, [navigate]);
15014
15024
  const fallback = useMemo(() => loaded.product ? heroFromProduct(loaded.product, t("See more")) : null, [loaded.product, t]);
15025
+ const shop2 = useCallback(async () => {
15026
+ if (await hasSession()) go(productPath);
15027
+ else emit({
15028
+ type: "session_required",
15029
+ action: "vip_claim"
15030
+ });
15031
+ }, [emit, go, hasSession, productPath]);
15015
15032
  const claim = useCallback(async (variantSku) => {
15033
+ if (!await hasSession()) {
15034
+ emit({
15035
+ type: "session_required",
15036
+ action: "vip_claim"
15037
+ });
15038
+ return;
15039
+ }
15016
15040
  try {
15017
15041
  const current2 = await api.cart.get().catch(() => null);
15018
15042
  if (current2?.vip?.invite_ref === invite.invite_ref) {
@@ -15053,12 +15077,12 @@ function ActiveLanding({ token, invite, screen: screen2 }) {
15053
15077
  });
15054
15078
  toast2.show(t(treatmentFor(code).body), "critical");
15055
15079
  }
15056
- }, [api, emit, invite.invite_ref, t, toast2, token]);
15080
+ }, [api, emit, hasSession, invite.invite_ref, t, toast2, token]);
15057
15081
  if (screen2 === "hero") {
15058
15082
  const hero2 = invite.hero ?? fallback;
15059
15083
  if (hero2) return jsx(VipHero, {
15060
15084
  hero: hero2,
15061
- onContinue: () => go(productPath)
15085
+ onContinue: () => void shop2()
15062
15086
  });
15063
15087
  } else if (loaded.product) {
15064
15088
  return jsx(ProductDetail, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nok-integration/storefront-react",
3
- "version": "0.29.5",
3
+ "version": "0.29.7",
4
4
  "description": "Mountable React storefront components: catalogue, product detail and cart, mounted directly into a host DOM tree. No iframe.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",