expo-superwall 0.0.17 → 0.1.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/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - b39e98e: feat: Remove the export of the internal SuperwallExpoModule Class,
8
+ this class should have not been used since it's an internal class and could break the state of the internal SuperwallStore.
9
+ If you have used in prior for a usecase that the current SDK doesn't support, please open an issue.
10
+
11
+ ### Patch Changes
12
+
13
+ - 32112a6: feat: handle deeplink automatically, no need for manual handling
14
+
15
+ ## 0.0.18
16
+
17
+ ### Patch Changes
18
+
19
+ - 3a93b2b: feat: fix inital loading state
20
+
3
21
  ## 0.0.17
4
22
 
5
23
  ### Patch Changes
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-superwall",
3
- "version": "0.0.17",
3
+ "version": "0.1.0",
4
4
  "description": "Offical Expo Integration for Superwall",
5
5
  "main": "build/src/index.js",
6
6
  "types": "build/src/index.d.ts",
@@ -1 +1 @@
1
- {"version":3,"file":"SuperwallProvider.d.ts","sourceRoot":"","sources":["../../src/SuperwallProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAa,MAAM,OAAO,CAAA;AAMjD,UAAU,sBAAsB;IAC9B,6BAA6B;IAC7B,OAAO,EAAE;QACP,OAAO,CAAC,EAAE,MAAM,CAAA;QAChB,GAAG,CAAC,EAAE,MAAM,CAAA;KACb,CAAA;IACD,8DAA8D;IAC9D,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC7B,4CAA4C;IAC5C,QAAQ,EAAE,SAAS,CAAA;CACpB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,OAAO,EACP,OAAO,EAEP,QAAQ,GACT,EAAE,sBAAsB,+BAiCxB"}
1
+ {"version":3,"file":"SuperwallProvider.d.ts","sourceRoot":"","sources":["../../src/SuperwallProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAqB,MAAM,OAAO,CAAA;AAOzD,UAAU,sBAAsB;IAC9B,6BAA6B;IAC7B,OAAO,EAAE;QACP,OAAO,CAAC,EAAE,MAAM,CAAA;QAChB,GAAG,CAAC,EAAE,MAAM,CAAA;KACb,CAAA;IACD,8DAA8D;IAC9D,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC7B,4CAA4C;IAC5C,QAAQ,EAAE,SAAS,CAAA;CACpB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,OAAO,EACP,OAAO,EAEP,QAAQ,GACT,EAAE,sBAAsB,+BAyDxB"}
@@ -1,7 +1,8 @@
1
- import { useEffect } from "react";
2
- import { Platform } from "react-native";
1
+ import { useEffect, useRef } from "react";
2
+ import { Linking, Platform } from "react-native";
3
3
  import { useShallow } from "zustand/shallow";
4
4
  import { useCustomPurchaseController } from "./CustomPurchaseControllerProvider";
5
+ import SuperwallExpoModule from "./SuperwallExpoModule";
5
6
  import { SuperwallContext, useSuperwallStore } from "./useSuperwall";
6
7
  /**
7
8
  * @category Providers
@@ -25,6 +26,7 @@ import { SuperwallContext, useSuperwallStore } from "./useSuperwall";
25
26
  * ```
26
27
  */
27
28
  export function SuperwallProvider({ apiKeys, options, children, }) {
29
+ const deepLinkEventHandlerRef = useRef(null);
28
30
  const isUsingCustomPurchaseController = !!useCustomPurchaseController();
29
31
  const { isConfigured, isLoading, configure } = useSuperwallStore(useShallow((state) => ({
30
32
  isConfigured: state.isConfigured,
@@ -49,6 +51,24 @@ export function SuperwallProvider({ apiKeys, options, children, }) {
49
51
  const cleanup = useSuperwallStore.getState()._initListeners();
50
52
  return cleanup;
51
53
  }, []);
54
+ useEffect(() => {
55
+ const handleDeepLink = async () => {
56
+ await Linking.getInitialURL().then((url) => {
57
+ if (url) {
58
+ SuperwallExpoModule.handleDeepLink(url);
59
+ }
60
+ });
61
+ deepLinkEventHandlerRef.current = Linking.addEventListener("url", (event) => {
62
+ SuperwallExpoModule.handleDeepLink(event.url);
63
+ });
64
+ };
65
+ handleDeepLink();
66
+ return () => {
67
+ if (deepLinkEventHandlerRef.current) {
68
+ deepLinkEventHandlerRef.current.remove();
69
+ }
70
+ };
71
+ }, []);
52
72
  return <SuperwallContext.Provider value={true}>{children}</SuperwallContext.Provider>;
53
73
  }
54
74
  //# sourceMappingURL=SuperwallProvider.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SuperwallProvider.js","sourceRoot":"","sources":["../../src/SuperwallProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAkB,SAAS,EAAE,MAAM,OAAO,CAAA;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,2BAA2B,EAAE,MAAM,oCAAoC,CAAA;AAChF,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAcpE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,iBAAiB,CAAC,EAChC,OAAO,EACP,OAAO,EAEP,QAAQ,GACe;IACvB,MAAM,+BAA+B,GAAG,CAAC,CAAC,2BAA2B,EAAE,CAAA;IACvE,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,iBAAiB,CAC9D,UAAU,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACrB,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,SAAS,EAAE,KAAK,CAAC,SAAS;KAC3B,CAAC,CAAC,CACJ,CAAA;IAED,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,YAAY,IAAI,CAAC,SAAS,EAAE,CAAC;YAChC,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,EAA0B,CAAC,CAAA;YAC3D,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,MAAM,IAAI,KAAK,CAAC,oCAAoC,QAAQ,CAAC,EAAE,EAAE,CAAC,CAAA;YACpE,CAAC;YAED,SAAS,CAAC,MAAM,EAAE;gBAChB,GAAG,OAAO;gBACV,uBAAuB,EAAE,+BAA+B;aACzD,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;gBACf,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,GAAG,CAAC,CAAA;YAClD,CAAC,CAAC,CAAA;QACJ,CAAC;IACH,CAAC,EAAE,CAAC,YAAY,EAAE,+BAA+B,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC,CAAA;IAE3F,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,OAAO,GAAG,iBAAiB,CAAC,QAAQ,EAAE,CAAC,cAAc,EAAE,CAAA;QAE7D,OAAO,OAAO,CAAA;IAChB,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,OAAO,CAAC,gBAAgB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,gBAAgB,CAAC,QAAQ,CAAC,CAAA;AACvF,CAAC","sourcesContent":["import { type ReactNode, useEffect } from \"react\"\nimport { Platform } from \"react-native\"\nimport { useShallow } from \"zustand/shallow\"\nimport { useCustomPurchaseController } from \"./CustomPurchaseControllerProvider\"\nimport { SuperwallContext, useSuperwallStore } from \"./useSuperwall\"\n\ninterface SuperwallProviderProps {\n /** Your Superwall API key */\n apiKeys: {\n android?: string\n ios?: string\n }\n /** Optional configuration options passed to the native SDK */\n options?: Record<string, any>\n /** App content to render once configured */\n children: ReactNode\n}\n\n/**\n * @category Providers\n * @since 0.0.15\n * Main provider component for the Superwall SDK.\n *\n * This component initializes the Superwall SDK with your API key and configuration options.\n * It should wrap the root of your application or the part of your app that requires Superwall functionality.\n * It also sets up necessary event listeners for the SDK.\n *\n * @param props - The properties for the SuperwallProvider.\n * @param props.apiKeys - An object containing your Superwall API keys for Android and iOS.\n * @param props.options - Optional configuration options to pass to the native Superwall SDK.\n * @param props.children - The child components of your application that will have access to Superwall features.\n *\n * Example:\n * ```tsx\n * <SuperwallProvider apiKeys={{ ios: \"YOUR_IOS_API_KEY\", android: \"YOUR_ANDROID_API_KEY\" }}>\n * <App />\n * </SuperwallProvider>\n * ```\n */\nexport function SuperwallProvider({\n apiKeys,\n options,\n\n children,\n}: SuperwallProviderProps) {\n const isUsingCustomPurchaseController = !!useCustomPurchaseController()\n const { isConfigured, isLoading, configure } = useSuperwallStore(\n useShallow((state) => ({\n isConfigured: state.isConfigured,\n isLoading: state.isLoading,\n configure: state.configure,\n })),\n )\n\n useEffect(() => {\n if (!isConfigured && !isLoading) {\n const apiKey = apiKeys[Platform.OS as keyof typeof apiKeys]\n if (!apiKey) {\n throw new Error(`No API key provided for platform ${Platform.OS}`)\n }\n\n configure(apiKey, {\n ...options,\n manualPurchaseManagment: isUsingCustomPurchaseController,\n }).catch((err) => {\n console.error(\"Superwall configure failed\", err)\n })\n }\n }, [isConfigured, isUsingCustomPurchaseController, isLoading, apiKeys, options, configure])\n\n useEffect(() => {\n const cleanup = useSuperwallStore.getState()._initListeners()\n\n return cleanup\n }, [])\n\n return <SuperwallContext.Provider value={true}>{children}</SuperwallContext.Provider>\n}\n"]}
1
+ {"version":3,"file":"SuperwallProvider.js","sourceRoot":"","sources":["../../src/SuperwallProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAkB,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AACzD,OAAO,EAA4B,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAC1E,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,O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EAAE,SAAS,CAAC,CAAC,CAAA;IAE3F,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,OAAO,GAAG,iBAAiB,CAAC,QAAQ,EAAE,CAAC,cAAc,EAAE,CAAA;QAE7D,OAAO,OAAO,CAAA;IAChB,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,cAAc,GAAG,KAAK,IAAI,EAAE;YAChC,MAAM,OAAO,CAAC,aAAa,EAAE,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE;gBACzC,IAAI,GAAG,EAAE,CAAC;oBACR,mBAAmB,CAAC,cAAc,CAAC,GAAG,CAAC,CAAA;gBACzC,CAAC;YACH,CAAC,CAAC,CAAA;YAEF,uBAAuB,CAAC,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE;gBAC1E,mBAAmB,CAAC,cAAc,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;YAC/C,CAAC,CAAC,CAAA;QACJ,CAAC,CAAA;QAED,cAAc,EAAE,CAAA;QAEhB,OAAO,GAAG,EAAE;YACV,IAAI,uBAAuB,CAAC,OAAO,EAAE,CAAC;gBACpC,uBAAuB,CAAC,OAAO,CAAC,MAAM,EAAE,CAAA;YAC1C,CAAC;QACH,CAAC,CAAA;IACH,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,OAAO,CAAC,gBAAgB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,gBAAgB,CAAC,QAAQ,CAAC,CAAA;AACvF,CAAC","sourcesContent":["import { type ReactNode, useEffect, useRef } from \"react\"\nimport { type EmitterSubscription, Linking, Platform } from \"react-native\"\nimport { useShallow } from \"zustand/shallow\"\nimport { useCustomPurchaseController } from \"./CustomPurchaseControllerProvider\"\nimport SuperwallExpoModule from \"./SuperwallExpoModule\"\nimport { SuperwallContext, useSuperwallStore } from \"./useSuperwall\"\n\ninterface SuperwallProviderProps {\n /** Your Superwall API key */\n apiKeys: {\n android?: string\n ios?: string\n }\n /** Optional configuration options passed to the native SDK */\n options?: Record<string, any>\n /** App content to render once configured */\n children: ReactNode\n}\n\n/**\n * @category Providers\n * @since 0.0.15\n * Main provider component for the Superwall SDK.\n *\n * This component initializes the Superwall SDK with your API key and configuration options.\n * It should wrap the root of your application or the part of your app that requires Superwall functionality.\n * It also sets up necessary event listeners for the SDK.\n *\n * @param props - The properties for the SuperwallProvider.\n * @param props.apiKeys - An object containing your Superwall API keys for Android and iOS.\n * @param props.options - Optional configuration options to pass to the native Superwall SDK.\n * @param props.children - The child components of your application that will have access to Superwall features.\n *\n * Example:\n * ```tsx\n * <SuperwallProvider apiKeys={{ ios: \"YOUR_IOS_API_KEY\", android: \"YOUR_ANDROID_API_KEY\" }}>\n * <App />\n * </SuperwallProvider>\n * ```\n */\nexport function SuperwallProvider({\n apiKeys,\n options,\n\n children,\n}: SuperwallProviderProps) {\n const deepLinkEventHandlerRef = useRef<EmitterSubscription>(null)\n const isUsingCustomPurchaseController = !!useCustomPurchaseController()\n\n const { isConfigured, isLoading, configure } = useSuperwallStore(\n useShallow((state) => ({\n isConfigured: state.isConfigured,\n isLoading: state.isLoading,\n configure: state.configure,\n })),\n )\n\n useEffect(() => {\n if (!isConfigured && !isLoading) {\n const apiKey = apiKeys[Platform.OS as keyof typeof apiKeys]\n if (!apiKey) {\n throw new Error(`No API key provided for platform ${Platform.OS}`)\n }\n\n configure(apiKey, {\n ...options,\n manualPurchaseManagment: isUsingCustomPurchaseController,\n }).catch((err) => {\n console.error(\"Superwall configure failed\", err)\n })\n }\n }, [isConfigured, isUsingCustomPurchaseController, isLoading, apiKeys, options, configure])\n\n useEffect(() => {\n const cleanup = useSuperwallStore.getState()._initListeners()\n\n return cleanup\n }, [])\n\n useEffect(() => {\n const handleDeepLink = async () => {\n await Linking.getInitialURL().then((url) => {\n if (url) {\n SuperwallExpoModule.handleDeepLink(url)\n }\n })\n\n deepLinkEventHandlerRef.current = Linking.addEventListener(\"url\", (event) => {\n SuperwallExpoModule.handleDeepLink(event.url)\n })\n }\n\n handleDeepLink()\n\n return () => {\n if (deepLinkEventHandlerRef.current) {\n deepLinkEventHandlerRef.current.remove()\n }\n }\n }, [])\n\n return <SuperwallContext.Provider value={true}>{children}</SuperwallContext.Provider>\n}\n"]}
@@ -1,6 +1,5 @@
1
1
  export * from "./CustomPurchaseControllerProvider";
2
2
  export * from "./components";
3
- export { default as SuperwallExpoModule } from "./SuperwallExpoModule";
4
3
  export * from "./SuperwallProvider";
5
4
  export * from "./usePlacement";
6
5
  export * from "./useSuperwall";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oCAAoC,CAAA;AAClD,cAAc,cAAc,CAAA;AAC5B,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AACtE,cAAc,qBAAqB,CAAA;AACnC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,sBAAsB,CAAA;AACpC,cAAc,WAAW,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oCAAoC,CAAA;AAClD,cAAc,cAAc,CAAA;AAC5B,cAAc,qBAAqB,CAAA;AACnC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,sBAAsB,CAAA;AACpC,cAAc,WAAW,CAAA"}
@@ -1,6 +1,5 @@
1
1
  export * from "./CustomPurchaseControllerProvider";
2
2
  export * from "./components";
3
- export { default as SuperwallExpoModule } from "./SuperwallExpoModule";
4
3
  export * from "./SuperwallProvider";
5
4
  export * from "./usePlacement";
6
5
  export * from "./useSuperwall";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oCAAoC,CAAA;AAClD,cAAc,cAAc,CAAA;AAC5B,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AACtE,cAAc,qBAAqB,CAAA;AACnC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,sBAAsB,CAAA;AACpC,cAAc,WAAW,CAAA","sourcesContent":["export * from \"./CustomPurchaseControllerProvider\"\nexport * from \"./components\"\nexport { default as SuperwallExpoModule } from \"./SuperwallExpoModule\"\nexport * from \"./SuperwallProvider\"\nexport * from \"./usePlacement\"\nexport * from \"./useSuperwall\"\nexport * from \"./useSuperwallEvents\"\nexport * from \"./useUser\"\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oCAAoC,CAAA;AAClD,cAAc,cAAc,CAAA;AAC5B,cAAc,qBAAqB,CAAA;AACnC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,sBAAsB,CAAA;AACpC,cAAc,WAAW,CAAA","sourcesContent":["export * from \"./CustomPurchaseControllerProvider\"\nexport * from \"./components\"\nexport * from \"./SuperwallProvider\"\nexport * from \"./usePlacement\"\nexport * from \"./useSuperwall\"\nexport * from \"./useSuperwallEvents\"\nexport * from \"./useUser\"\n"]}
@@ -22,25 +22,30 @@ export const useSuperwallStore = create((set, get) => ({
22
22
  configure: async (apiKey, options) => {
23
23
  set({ isLoading: true });
24
24
  const { manualPurchaseManagment, ...restOptions } = options || {};
25
- await SuperwallExpoModule.configure(apiKey, restOptions, !!options?.manualPurchaseManagment, pkg.version);
26
- set({ isConfigured: true, isLoading: false });
27
- const currentUser = (await SuperwallExpoModule.getUserAttributes());
25
+ await SuperwallExpoModule.configure(apiKey, restOptions, !!manualPurchaseManagment, pkg.version);
26
+ const currentUser = await SuperwallExpoModule.getUserAttributes();
28
27
  const subscriptionStatus = await SuperwallExpoModule.getSubscriptionStatus();
29
- set({ user: currentUser, subscriptionStatus });
28
+ set({
29
+ isConfigured: true,
30
+ isLoading: false,
31
+ user: currentUser,
32
+ subscriptionStatus,
33
+ });
30
34
  },
31
35
  identify: async (userId, options) => {
32
36
  SuperwallExpoModule.identify(userId, options);
33
37
  // TODO: Instead of setting users after identify, we should set this based on an event
34
38
  setTimeout(async () => {
35
- const currentUser = (await SuperwallExpoModule.getUserAttributes());
39
+ const currentUser = await SuperwallExpoModule.getUserAttributes();
36
40
  const subscriptionStatus = await SuperwallExpoModule.getSubscriptionStatus();
37
41
  set({ user: currentUser, subscriptionStatus });
38
42
  }, 0);
39
43
  },
40
44
  reset: async () => {
41
45
  SuperwallExpoModule.reset();
42
- const currentUser = (await SuperwallExpoModule.getUserAttributes());
43
- set({ user: currentUser });
46
+ const currentUser = await SuperwallExpoModule.getUserAttributes();
47
+ const subscriptionStatus = await SuperwallExpoModule.getSubscriptionStatus();
48
+ set({ user: currentUser, subscriptionStatus });
44
49
  },
45
50
  registerPlacement: async (placement, params, handlerId = "default") => {
46
51
  await SuperwallExpoModule.registerPlacement(placement, params, handlerId);
@@ -59,7 +64,7 @@ export const useSuperwallStore = create((set, get) => ({
59
64
  },
60
65
  setUserAttributes: async (attrs) => {
61
66
  SuperwallExpoModule.setUserAttributes(attrs);
62
- const currentUser = (await SuperwallExpoModule.getUserAttributes());
67
+ const currentUser = await SuperwallExpoModule.getUserAttributes();
63
68
  set({ user: currentUser });
64
69
  },
65
70
  getUserAttributes: async () => {
@@ -138,7 +143,7 @@ export function useSuperwall(selector) {
138
143
  throw new Error("useSuperwall must be used within a SuperwallProvider");
139
144
  }
140
145
  const identity = (state) => state;
141
- // biome-ignore lint/correctness/useHookAtTopLevel: <explanation>
146
+ // biome-ignore lint/correctness/useHookAtTopLevel: good here
142
147
  return useSuperwallStore(selector ? useShallow(selector) : identity);
143
148
  }
144
149
  //# sourceMappingURL=useSuperwall.js.map
@@ -1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7B,6BAA6B,EAC7B,CAAC,EAAE,EAAE,EAA8B,EAAE,EAAE;YACrC,GAAG,CAAC,EAAE,kBAAkB,EAAE,EAAE,EAAE,CAAC,CAAA;QACjC,CAAC,CACF,CACF,CAAA;QAED,GAAG,CAAC,EAAE,oBAAoB,EAAE,IAAI,EAAE,CAAC,CAAA;QACnC,OAAO,CAAC,GAAG,CAAC,uBAAuB,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;QAE1D,OAAO,GAAS,EAAE;YAChB,OAAO,CAAC,GAAG,CAAC,uBAAuB,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;YAC1D,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAA;YACxC,6BAA6B;YAC7B,GAAG,CAAC,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAAC,CAAA;QACtC,CAAC,CAAA;IACH,CAAC;CACF,CAAC,CAAC,CAAA;AASH,MAAM,CAAC,MAAM,gBAAgB,GAAG,aAAa,CAAU,KAAK,CAAC,CAAA;AAE7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,UAAU,YAAY,CAA2B,QAAuC;IAC5F,MAAM,UAAU,GAAG,UAAU,CAAC,gBAAgB,CAAC,CAAA;IAC/C,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAA;IACzE,CAAC;IAED,MAAM,QAAQ,GAAG,CAAC,KAAqB,EAAE,EAAE,CAAC,KAAqB,CAAA;IACjE,iEAAiE;IACjE,OAAO,iBAAiB,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAA;AACtE,CAAC","sourcesContent":["import { createContext, useContext } from \"react\"\nimport { create } from \"zustand\"\nimport { useShallow } from \"zustand/shallow\"\nimport pkg from \"../package.json\"\nimport SuperwallExpoModule from \"./SuperwallExpoModule\"\nimport type { SubscriptionStatus } from \"./SuperwallExpoModule.types\"\n\n/**\n * @category Models\n * @since 0.0.15\n * Interface representing the attributes of a user.\n */\nexport interface UserAttributes {\n /** The user's alias ID, if set. */\n aliasId: string\n /** The user's application-specific user ID. */\n appUserId: string\n /** The ISO 8601 date string representation of when the application was installed on the user's device. */\n applicationInstalledAt: string\n /** A seed value associated with the user, used for consistent variant assignments in experiments. */\n seed: number\n /** Allows for custom attributes to be set for the user. These can be of any type. */\n [key: string]: any\n}\n\n/**\n * @category Models\n * @since 0.0.15\n * Options for the `identify` method.\n */\nexport interface IdentifyOptions {\n /**\n * Determines whether to restore paywall assignments from a previous session for the identified user.\n * If `true`, the SDK attempts to restore the assignments. Defaults to `false`.\n */\n restorePaywallAssignments?: boolean\n}\n\n/**\n * @category Store\n * @since 0.0.15\n * Defines the structure of the Superwall store, including its state and actions.\n * This store is managed by Zustand.\n */\nexport interface SuperwallStore {\n /* -------------------- State -------------------- */\n /** Indicates whether the Superwall SDK has been successfully configured. */\n isConfigured: boolean\n /** Indicates whether the SDK is currently performing a loading operation (e.g., configuring, fetching data). */\n isLoading: boolean\n /** Indicates whether the native event listeners have been initialized. */\n listenersInitialized: boolean\n\n /**\n * The current user's attributes.\n * `null` if no user is identified or after `reset` is called.\n * `undefined` initially before any user data is fetched or set.\n */\n user?: UserAttributes | null\n\n /** The current subscription status of the user. */\n subscriptionStatus: SubscriptionStatus\n\n /* -------------------- Internal -------------------- */\n // Internal listener references for cleanup handled inside Provider effect.\n // Not reactive, so we store outside Zustand state to avoid unnecessary rerenders.\n\n /* -------------------- Actions -------------------- */\n /**\n * Configures the Superwall SDK with the provided API key and options.\n * This must be called before most other SDK functions can be used.\n * @param apiKey - Your Superwall API key.\n * @param options - Optional configuration settings for the SDK.\n * @returns A promise that resolves when configuration is complete.\n * @internal\n */\n configure: (\n apiKey: string,\n options?: {\n manualPurchaseManagment?: boolean\n enableExperimentalDeviceVariables?: boolean\n } & Record<string, any>,\n ) => Promise<void>\n /**\n * Identifies the current user with a unique ID.\n * @param userId - The unique identifier for the user.\n * @param options - Optional parameters for identification.\n * @returns A promise that resolves when identification is complete.\n */\n identify: (userId: string, options?: IdentifyOptions) => Promise<void>\n /**\n * Resets the user's identity and clears all user-specific data, effectively logging them out.\n * @internal\n */\n reset: () => Promise<void>\n\n /**\n * Registers a placement to potentially show a paywall.\n * The decision to show a paywall is determined by campaign rules and user assignments on the Superwall dashboard.\n * @param placement - The ID of the placement to register.\n * @param params - Optional parameters to pass with the placement.\n * @param handlerId - An optional identifier used to associate specific event handlers (e.g., from `usePlacement`). Defaults to \"default\".\n * @returns A promise that resolves when the placement registration is complete.\n */\n registerPlacement: (\n placement: string,\n params?: Record<string, any>,\n handlerId?: string | null,\n ) => Promise<void>\n /**\n * Retrieves the presentation result for a given placement.\n * This can be used to understand what would happen if a placement were to be registered, without actually registering it.\n * @param placement - The ID of the placement.\n * @param params - Optional parameters for the placement.\n * @returns A promise that resolves with the presentation result.\n */\n getPresentationResult: (placement: string, params?: Record<string, any>) => Promise<any>\n /**\n * Dismisses any currently presented Superwall paywall.\n * @returns A promise that resolves when the dismissal is complete.\n */\n dismiss: () => Promise<void>\n\n /**\n * Preloads all paywalls configured in your Superwall dashboard.\n * @returns A promise that resolves when preloading is complete.\n */\n preloadAllPaywalls: () => Promise<void>\n /**\n * Preloads specific paywalls.\n * @param placements - An array of placement IDs for which to preload paywalls.\n * @returns A promise that resolves when preloading is complete.\n */\n preloadPaywalls: (placements: string[]) => Promise<void>\n\n /**\n * Sets custom attributes for the current user.\n * @param attrs - An object containing the attributes to set.\n * @returns A promise that resolves when attributes are set.\n */\n setUserAttributes: (attrs: Record<string, any>) => Promise<void>\n /**\n * Retrieves the current user's attributes.\n * @returns A promise that resolves with the user's attributes.\n */\n getUserAttributes: () => Promise<Record<string, any>>\n\n /**\n * Sets the logging level for the Superwall SDK.\n * @param level - The desired log level (e.g., \"debug\", \"info\", \"warn\", \"error\", \"none\").\n * @returns A promise that resolves when the log level is set.\n */\n setLogLevel: (level: string) => Promise<void>\n\n /* -------------------- Listener helpers -------------------- */\n /**\n * Initializes native event listeners for the SDK.\n * This is typically called internally by the `SuperwallProvider`.\n * @returns A cleanup function to remove the listeners.\n * @internal\n */\n _initListeners: () => () => void\n\n setSubscriptionStatus: (status: SubscriptionStatus) => Promise<void>\n\n getDeviceAttributes: () => Promise<Record<string, any>>\n}\n\n/**\n * @category Store\n * @since 0.0.15\n * Zustand store for Superwall SDK state and actions.\n * @internal\n */\nexport const useSuperwallStore = create<SuperwallStore>((set, get) => ({\n /* -------------------- State -------------------- */\n isConfigured: false,\n isLoading: false,\n listenersInitialized: false,\n\n user: null,\n subscriptionStatus: {\n status: \"UNKNOWN\",\n },\n\n /* -------------------- Actions -------------------- */\n configure: async (apiKey, options) => {\n set({ isLoading: true })\n const { manualPurchaseManagment, ...restOptions } = options || {}\n\n await SuperwallExpoModule.configure(\n apiKey,\n restOptions,\n !!options?.manualPurchaseManagment,\n pkg.version,\n )\n set({ isConfigured: true, isLoading: false })\n\n const currentUser = (await SuperwallExpoModule.getUserAttributes()) as UserAttributes\n const subscriptionStatus = await SuperwallExpoModule.getSubscriptionStatus()\n\n set({ user: currentUser, subscriptionStatus })\n },\n identify: async (userId, options) => {\n SuperwallExpoModule.identify(userId, options)\n\n // TODO: Instead of setting users after identify, we should set this based on an event\n setTimeout(async () => {\n const currentUser = (await SuperwallExpoModule.getUserAttributes()) as UserAttributes\n const subscriptionStatus = await SuperwallExpoModule.getSubscriptionStatus()\n set({ user: currentUser, subscriptionStatus })\n }, 0)\n },\n reset: async () => {\n SuperwallExpoModule.reset()\n\n const currentUser = (await SuperwallExpoModule.getUserAttributes()) as UserAttributes\n\n set({ user: currentUser })\n },\n registerPlacement: async (placement, params, handlerId = \"default\") => {\n await SuperwallExpoModule.registerPlacement(placement, params, handlerId)\n },\n getPresentationResult: async (placement, params) => {\n return SuperwallExpoModule.getPresentationResult(placement, params)\n },\n dismiss: async () => {\n await SuperwallExpoModule.dismiss()\n },\n preloadAllPaywalls: async () => {\n SuperwallExpoModule.preloadAllPaywalls()\n },\n preloadPaywalls: async (placements) => {\n SuperwallExpoModule.preloadPaywalls(placements)\n },\n setUserAttributes: async (attrs) => {\n SuperwallExpoModule.setUserAttributes(attrs)\n\n const currentUser = (await SuperwallExpoModule.getUserAttributes()) as UserAttributes\n set({ user: currentUser })\n },\n getUserAttributes: async () => {\n const attributes = await SuperwallExpoModule.getUserAttributes()\n set({ user: attributes as UserAttributes })\n return attributes\n },\n setLogLevel: async (level) => {\n SuperwallExpoModule.setLogLevel(level)\n },\n\n setSubscriptionStatus: async (status) => {\n SuperwallExpoModule.setSubscriptionStatus(status)\n },\n getDeviceAttributes: async () => {\n const attributes = await SuperwallExpoModule.getDeviceAttributes()\n return attributes\n },\n\n /* -------------------- Listener helpers -------------------- */\n _initListeners: (): (() => void) => {\n // Use get() to read the state from within the store\n if (get().listenersInitialized) {\n console.warn(\"Listeners already initialized. Skipping.\")\n return () => {} // Return no-op cleanup\n }\n\n const subscriptions: { remove: () => void }[] = []\n\n subscriptions.push(\n SuperwallExpoModule.addListener(\n \"subscriptionStatusDidChange\",\n ({ to }: { to: SubscriptionStatus }) => {\n set({ subscriptionStatus: to })\n },\n ),\n )\n\n set({ listenersInitialized: true })\n console.log(\"Initialized listeners\", subscriptions.length)\n\n return (): void => {\n console.log(\"Cleaning up listeners\", subscriptions.length)\n subscriptions.forEach((s) => s.remove())\n // Reset the state on cleanup\n set({ listenersInitialized: false })\n }\n },\n}))\n\n/**\n * @category Store\n * @since 0.0.15\n * Public interface for the Superwall store, excluding internal methods.\n */\nexport type PublicSuperwallStore = Omit<SuperwallStore, \"configure\" | \"reset\" | \"_initListeners\">\n\nexport const SuperwallContext = createContext<boolean>(false)\n\n/**\n * @category Hooks\n * @since 0.0.15\n * Core React hook for interacting with the Superwall SDK.\n *\n * This hook provides access to the Superwall store, which includes SDK state\n * (like configuration status, user information, subscription status) and actions\n * (like `identify`, `reset`, `registerPlacement`).\n *\n * It must be used within a component that is a descendant of `<SuperwallProvider />`.\n *\n * @template T - Optional type parameter for the selected state. Defaults to the entire `PublicSuperwallStore`.\n * @param selector - An optional function to select a specific slice of the store's state.\n * This is useful for performance optimization, as components will only re-render\n * if the selected part of the state changes. Uses shallow equality checking\n * via `zustand/shallow`. If omitted, the entire store is returned.\n * @returns The selected slice of the Superwall store state, or the entire store if no selector is provided.\n * @throws Error if used outside of a `SuperwallProvider`.\n *\n * @example\n * // Get the entire store\n * const superwall = useSuperwall();\n * console.log(superwall.isConfigured);\n * superwall.identify(\"user_123\");\n *\n * @example\n * // Select specific state properties\n * const { user, subscriptionStatus } = useSuperwall(state => ({\n * user: state.user,\n * subscriptionStatus: state.subscriptionStatus,\n * }));\n * console.log(user?.appUserId, subscriptionStatus?.status);\n */\nexport function useSuperwall<T = PublicSuperwallStore>(selector?: (state: SuperwallStore) => T): T {\n const inProvider = useContext(SuperwallContext)\n if (!inProvider) {\n throw new Error(\"useSuperwall must be used within a SuperwallProvider\")\n }\n\n const identity = (state: SuperwallStore) => state as unknown as T\n // biome-ignore lint/correctness/useHookAtTopLevel: <explanation>\n return useSuperwallStore(selector ? useShallow(selector) : identity)\n}\n"]}
1
+ {"version":3,"file":"useSuperwall.js","sourceRoot":"","sources":["../../src/useSuperwall.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,GAAG,MAAM,iBAAiB,CAAA;AACjC,OAAO,mBAAmB,MAAM,uBAAuB,CAAA;AAoKvD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAiB,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;IACrE,qDAAqD;IACr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AAC,CAAA;YACxC,6BAA6B;YAC7B,GAAG,CAAC,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAAC,CAAA;QACtC,CAAC,CAAA;IACH,CAAC;CACF,CAAC,CAAC,CAAA;AASH,MAAM,CAAC,MAAM,gBAAgB,GAAG,aAAa,CAAU,KAAK,CAAC,CAAA;AAE7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,UAAU,YAAY,CAA2B,QAAuC;IAC5F,MAAM,UAAU,GAAG,UAAU,CAAC,gBAAgB,CAAC,CAAA;IAC/C,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAA;IACzE,CAAC;IAED,MAAM,QAAQ,GAAG,CAAC,KAAqB,EAAE,EAAE,CAAC,KAAqB,CAAA;IACjE,6DAA6D;IAC7D,OAAO,iBAAiB,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAA;AACtE,CAAC","sourcesContent":["import { createContext, useContext } from \"react\"\nimport { create } from \"zustand\"\nimport { useShallow } from \"zustand/shallow\"\nimport pkg from \"../package.json\"\nimport SuperwallExpoModule from \"./SuperwallExpoModule\"\nimport type { SubscriptionStatus } from \"./SuperwallExpoModule.types\"\n\n/**\n * @category Models\n * @since 0.0.15\n * Interface representing the attributes of a user.\n */\nexport interface UserAttributes {\n /** The user's alias ID, if set. */\n aliasId: string\n /** The user's application-specific user ID. */\n appUserId: string\n /** The ISO 8601 date string representation of when the application was installed on the user's device. */\n applicationInstalledAt: string\n /** A seed value associated with the user, used for consistent variant assignments in experiments. */\n seed: number\n /** Allows for custom attributes to be set for the user. These can be of any type. */\n [key: string]: any\n}\n\n/**\n * @category Models\n * @since 0.0.15\n * Options for the `identify` method.\n */\nexport interface IdentifyOptions {\n /**\n * Determines whether to restore paywall assignments from a previous session for the identified user.\n * If `true`, the SDK attempts to restore the assignments. Defaults to `false`.\n */\n restorePaywallAssignments?: boolean\n}\n\n/**\n * @category Store\n * @since 0.0.15\n * Defines the structure of the Superwall store, including its state and actions.\n * This store is managed by Zustand.\n */\nexport interface SuperwallStore {\n /* -------------------- State -------------------- */\n /** Indicates whether the Superwall SDK has been successfully configured. */\n isConfigured: boolean\n /** Indicates whether the SDK is currently performing a loading operation (e.g., configuring, fetching data). */\n isLoading: boolean\n /** Indicates whether the native event listeners have been initialized. */\n listenersInitialized: boolean\n\n /**\n * The current user's attributes.\n * `null` if no user is identified or after `reset` is called.\n * `undefined` initially before any user data is fetched or set.\n */\n user?: UserAttributes | null\n\n /** The current subscription status of the user. */\n subscriptionStatus: SubscriptionStatus\n\n /* -------------------- Internal -------------------- */\n // Internal listener references for cleanup handled inside Provider effect.\n // Not reactive, so we store outside Zustand state to avoid unnecessary rerenders.\n\n /* -------------------- Actions -------------------- */\n /**\n * Configures the Superwall SDK with the provided API key and options.\n * This must be called before most other SDK functions can be used.\n * @param apiKey - Your Superwall API key.\n * @param options - Optional configuration settings for the SDK.\n * @returns A promise that resolves when configuration is complete.\n * @internal\n */\n configure: (\n apiKey: string,\n options?: {\n manualPurchaseManagment?: boolean\n enableExperimentalDeviceVariables?: boolean\n } & Record<string, any>,\n ) => Promise<void>\n /**\n * Identifies the current user with a unique ID.\n * @param userId - The unique identifier for the user.\n * @param options - Optional parameters for identification.\n * @returns A promise that resolves when identification is complete.\n */\n identify: (userId: string, options?: IdentifyOptions) => Promise<void>\n /**\n * Resets the user's identity and clears all user-specific data, effectively logging them out.\n * @internal\n */\n reset: () => Promise<void>\n\n /**\n * Registers a placement to potentially show a paywall.\n * The decision to show a paywall is determined by campaign rules and user assignments on the Superwall dashboard.\n * @param placement - The ID of the placement to register.\n * @param params - Optional parameters to pass with the placement.\n * @param handlerId - An optional identifier used to associate specific event handlers (e.g., from `usePlacement`). Defaults to \"default\".\n * @returns A promise that resolves when the placement registration is complete.\n */\n registerPlacement: (\n placement: string,\n params?: Record<string, any>,\n handlerId?: string | null,\n ) => Promise<void>\n /**\n * Retrieves the presentation result for a given placement.\n * This can be used to understand what would happen if a placement were to be registered, without actually registering it.\n * @param placement - The ID of the placement.\n * @param params - Optional parameters for the placement.\n * @returns A promise that resolves with the presentation result.\n */\n getPresentationResult: (placement: string, params?: Record<string, any>) => Promise<any>\n /**\n * Dismisses any currently presented Superwall paywall.\n * @returns A promise that resolves when the dismissal is complete.\n */\n dismiss: () => Promise<void>\n\n /**\n * Preloads all paywalls configured in your Superwall dashboard.\n * @returns A promise that resolves when preloading is complete.\n */\n preloadAllPaywalls: () => Promise<void>\n /**\n * Preloads specific paywalls.\n * @param placements - An array of placement IDs for which to preload paywalls.\n * @returns A promise that resolves when preloading is complete.\n */\n preloadPaywalls: (placements: string[]) => Promise<void>\n\n /**\n * Sets custom attributes for the current user.\n * @param attrs - An object containing the attributes to set.\n * @returns A promise that resolves when attributes are set.\n */\n setUserAttributes: (attrs: Record<string, any>) => Promise<void>\n /**\n * Retrieves the current user's attributes.\n * @returns A promise that resolves with the user's attributes.\n */\n getUserAttributes: () => Promise<Record<string, any>>\n\n /**\n * Sets the logging level for the Superwall SDK.\n * @param level - The desired log level (e.g., \"debug\", \"info\", \"warn\", \"error\", \"none\").\n * @returns A promise that resolves when the log level is set.\n */\n setLogLevel: (level: string) => Promise<void>\n\n /* -------------------- Listener helpers -------------------- */\n /**\n * Initializes native event listeners for the SDK.\n * This is typically called internally by the `SuperwallProvider`.\n * @returns A cleanup function to remove the listeners.\n * @internal\n */\n _initListeners: () => () => void\n\n setSubscriptionStatus: (status: SubscriptionStatus) => Promise<void>\n\n getDeviceAttributes: () => Promise<Record<string, any>>\n}\n\n/**\n * @category Store\n * @since 0.0.15\n * Zustand store for Superwall SDK state and actions.\n * @internal\n */\nexport const useSuperwallStore = create<SuperwallStore>((set, get) => ({\n /* -------------------- State -------------------- */\n isConfigured: false,\n isLoading: false,\n listenersInitialized: false,\n\n user: null,\n subscriptionStatus: {\n status: \"UNKNOWN\",\n },\n\n /* -------------------- Actions -------------------- */\n configure: async (apiKey, options) => {\n set({ isLoading: true })\n const { manualPurchaseManagment, ...restOptions } = options || {}\n\n await SuperwallExpoModule.configure(apiKey, restOptions, !!manualPurchaseManagment, pkg.version)\n\n const currentUser = await SuperwallExpoModule.getUserAttributes()\n const subscriptionStatus = await SuperwallExpoModule.getSubscriptionStatus()\n\n set({\n isConfigured: true,\n isLoading: false,\n user: currentUser as UserAttributes,\n subscriptionStatus,\n })\n },\n identify: async (userId, options) => {\n SuperwallExpoModule.identify(userId, options)\n\n // TODO: Instead of setting users after identify, we should set this based on an event\n setTimeout(async () => {\n const currentUser = await SuperwallExpoModule.getUserAttributes()\n const subscriptionStatus = await SuperwallExpoModule.getSubscriptionStatus()\n set({ user: currentUser as UserAttributes, subscriptionStatus })\n }, 0)\n },\n reset: async () => {\n SuperwallExpoModule.reset()\n\n const currentUser = await SuperwallExpoModule.getUserAttributes()\n const subscriptionStatus = await SuperwallExpoModule.getSubscriptionStatus()\n\n set({ user: currentUser as UserAttributes, subscriptionStatus })\n },\n registerPlacement: async (placement, params, handlerId = \"default\") => {\n await SuperwallExpoModule.registerPlacement(placement, params, handlerId)\n },\n getPresentationResult: async (placement, params) => {\n return SuperwallExpoModule.getPresentationResult(placement, params)\n },\n dismiss: async () => {\n await SuperwallExpoModule.dismiss()\n },\n preloadAllPaywalls: async () => {\n SuperwallExpoModule.preloadAllPaywalls()\n },\n preloadPaywalls: async (placements) => {\n SuperwallExpoModule.preloadPaywalls(placements)\n },\n setUserAttributes: async (attrs) => {\n SuperwallExpoModule.setUserAttributes(attrs)\n\n const currentUser = await SuperwallExpoModule.getUserAttributes()\n set({ user: currentUser as UserAttributes })\n },\n getUserAttributes: async () => {\n const attributes = await SuperwallExpoModule.getUserAttributes()\n set({ user: attributes as UserAttributes })\n return attributes\n },\n setLogLevel: async (level) => {\n SuperwallExpoModule.setLogLevel(level)\n },\n\n setSubscriptionStatus: async (status) => {\n SuperwallExpoModule.setSubscriptionStatus(status)\n },\n getDeviceAttributes: async () => {\n const attributes = await SuperwallExpoModule.getDeviceAttributes()\n return attributes\n },\n\n /* -------------------- Listener helpers -------------------- */\n _initListeners: (): (() => void) => {\n // Use get() to read the state from within the store\n if (get().listenersInitialized) {\n console.warn(\"Listeners already initialized. Skipping.\")\n return () => {} // Return no-op cleanup\n }\n\n const subscriptions: { remove: () => void }[] = []\n\n subscriptions.push(\n SuperwallExpoModule.addListener(\n \"subscriptionStatusDidChange\",\n ({ to }: { to: SubscriptionStatus }) => {\n set({ subscriptionStatus: to })\n },\n ),\n )\n\n set({ listenersInitialized: true })\n console.log(\"Initialized listeners\", subscriptions.length)\n\n return (): void => {\n console.log(\"Cleaning up listeners\", subscriptions.length)\n subscriptions.forEach((s) => s.remove())\n // Reset the state on cleanup\n set({ listenersInitialized: false })\n }\n },\n}))\n\n/**\n * @category Store\n * @since 0.0.15\n * Public interface for the Superwall store, excluding internal methods.\n */\nexport type PublicSuperwallStore = Omit<SuperwallStore, \"configure\" | \"reset\" | \"_initListeners\">\n\nexport const SuperwallContext = createContext<boolean>(false)\n\n/**\n * @category Hooks\n * @since 0.0.15\n * Core React hook for interacting with the Superwall SDK.\n *\n * This hook provides access to the Superwall store, which includes SDK state\n * (like configuration status, user information, subscription status) and actions\n * (like `identify`, `reset`, `registerPlacement`).\n *\n * It must be used within a component that is a descendant of `<SuperwallProvider />`.\n *\n * @template T - Optional type parameter for the selected state. Defaults to the entire `PublicSuperwallStore`.\n * @param selector - An optional function to select a specific slice of the store's state.\n * This is useful for performance optimization, as components will only re-render\n * if the selected part of the state changes. Uses shallow equality checking\n * via `zustand/shallow`. If omitted, the entire store is returned.\n * @returns The selected slice of the Superwall store state, or the entire store if no selector is provided.\n * @throws Error if used outside of a `SuperwallProvider`.\n *\n * @example\n * // Get the entire store\n * const superwall = useSuperwall();\n * console.log(superwall.isConfigured);\n * superwall.identify(\"user_123\");\n *\n * @example\n * // Select specific state properties\n * const { user, subscriptionStatus } = useSuperwall(state => ({\n * user: state.user,\n * subscriptionStatus: state.subscriptionStatus,\n * }));\n * console.log(user?.appUserId, subscriptionStatus?.status);\n */\nexport function useSuperwall<T = PublicSuperwallStore>(selector?: (state: SuperwallStore) => T): T {\n const inProvider = useContext(SuperwallContext)\n if (!inProvider) {\n throw new Error(\"useSuperwall must be used within a SuperwallProvider\")\n }\n\n const identity = (state: SuperwallStore) => state as unknown as T\n // biome-ignore lint/correctness/useHookAtTopLevel: good here\n return useSuperwallStore(selector ? useShallow(selector) : identity)\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-superwall",
3
- "version": "0.0.17",
3
+ "version": "0.1.0",
4
4
  "description": "Offical Expo Integration for Superwall",
5
5
  "main": "build/src/index.js",
6
6
  "types": "build/src/index.d.ts",