@akanjs/next 0.0.54 → 0.0.55

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/useFetch.mjs ADDED
@@ -0,0 +1,23 @@
1
+ "use client";
2
+ import { useEffect, useState } from "react";
3
+ const useFetch = (fnOrPromise, { onError } = {}) => {
4
+ const [fetchState, setFetchState] = useState(
5
+ fnOrPromise instanceof Promise ? { fulfilled: false, value: null } : { fulfilled: true, value: fnOrPromise }
6
+ );
7
+ useEffect(() => {
8
+ void (async () => {
9
+ try {
10
+ const ret = fnOrPromise instanceof Promise ? await fnOrPromise : fnOrPromise;
11
+ setFetchState({ fulfilled: true, value: ret });
12
+ } catch (err) {
13
+ const content = `Error: ${typeof err === "string" ? err : err.message}`;
14
+ onError?.(content);
15
+ throw new Error(content);
16
+ }
17
+ })();
18
+ }, []);
19
+ return fetchState;
20
+ };
21
+ export {
22
+ useFetch
23
+ };
package/useGeoLocation.js CHANGED
@@ -1,8 +1,30 @@
1
1
  "use client";
2
- import { Geolocation } from "@capacitor/geolocation";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var useGeoLocation_exports = {};
20
+ __export(useGeoLocation_exports, {
21
+ useGeoLocation: () => useGeoLocation
22
+ });
23
+ module.exports = __toCommonJS(useGeoLocation_exports);
24
+ var import_geolocation = require("@capacitor/geolocation");
3
25
  const useGeoLocation = () => {
4
26
  const checkPermission = async () => {
5
- const { location: geolocation, coarseLocation } = await Geolocation.requestPermissions();
27
+ const { location: geolocation, coarseLocation } = await import_geolocation.Geolocation.requestPermissions();
6
28
  return { geolocation, coarseLocation };
7
29
  };
8
30
  const getPosition = async () => {
@@ -11,11 +33,8 @@ const useGeoLocation = () => {
11
33
  location.assign("app-settings:");
12
34
  return;
13
35
  }
14
- const coordinates = await Geolocation.getCurrentPosition();
36
+ const coordinates = await import_geolocation.Geolocation.getCurrentPosition();
15
37
  return coordinates;
16
38
  };
17
39
  return { checkPermission, getPosition };
18
40
  };
19
- export {
20
- useGeoLocation
21
- };
@@ -0,0 +1,21 @@
1
+ "use client";
2
+ import { Geolocation } from "@capacitor/geolocation";
3
+ const useGeoLocation = () => {
4
+ const checkPermission = async () => {
5
+ const { location: geolocation, coarseLocation } = await Geolocation.requestPermissions();
6
+ return { geolocation, coarseLocation };
7
+ };
8
+ const getPosition = async () => {
9
+ const { geolocation, coarseLocation } = await checkPermission();
10
+ if (geolocation === "denied" || coarseLocation === "denied") {
11
+ location.assign("app-settings:");
12
+ return;
13
+ }
14
+ const coordinates = await Geolocation.getCurrentPosition();
15
+ return coordinates;
16
+ };
17
+ return { checkPermission, getPosition };
18
+ };
19
+ export {
20
+ useGeoLocation
21
+ };
package/useHistory.js CHANGED
@@ -1,7 +1,29 @@
1
1
  "use client";
2
- import { useCallback, useRef } from "react";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var useHistory_exports = {};
20
+ __export(useHistory_exports, {
21
+ useHistory: () => useHistory
22
+ });
23
+ module.exports = __toCommonJS(useHistory_exports);
24
+ var import_react = require("react");
3
25
  const useHistory = (locations = []) => {
4
- const history = useRef({
26
+ const history = (0, import_react.useRef)({
5
27
  type: "initial",
6
28
  locations,
7
29
  scrollMap: /* @__PURE__ */ new Map([[window.location.pathname, 0]]),
@@ -9,7 +31,7 @@ const useHistory = (locations = []) => {
9
31
  cachedLocationMap: /* @__PURE__ */ new Map(),
10
32
  idx: 0
11
33
  });
12
- const setHistoryForward = useCallback(({ type, location, scrollTop = 0 }) => {
34
+ const setHistoryForward = (0, import_react.useCallback)(({ type, location, scrollTop = 0 }) => {
13
35
  history.current.type = "forward";
14
36
  history.current.scrollMap.set(location.pathname, scrollTop);
15
37
  history.current.idxMap.set(location.pathname, history.current.idx);
@@ -22,7 +44,7 @@ const useHistory = (locations = []) => {
22
44
  if (type === "push" || type === "popForward")
23
45
  history.current.idx++;
24
46
  }, []);
25
- const setHistoryBack = useCallback(({ location, scrollTop = 0 }) => {
47
+ const setHistoryBack = (0, import_react.useCallback)(({ location, scrollTop = 0 }) => {
26
48
  history.current.type = "back";
27
49
  history.current.scrollMap.set(location.pathname, scrollTop);
28
50
  history.current.idxMap.set(location.pathname, history.current.idx);
@@ -30,17 +52,14 @@ const useHistory = (locations = []) => {
30
52
  history.current.cachedLocationMap.set(location.pathRoute.path, location);
31
53
  history.current.idx--;
32
54
  }, []);
33
- const getCurrentLocation = useCallback(() => {
55
+ const getCurrentLocation = (0, import_react.useCallback)(() => {
34
56
  return history.current.locations[history.current.idx];
35
57
  }, []);
36
- const getPrevLocation = useCallback(() => {
58
+ const getPrevLocation = (0, import_react.useCallback)(() => {
37
59
  return history.current.locations[history.current.idx - 1] ?? null;
38
60
  }, []);
39
- const getScrollTop = useCallback((pathname = history.current.locations[history.current.idx]?.pathname ?? "/") => {
61
+ const getScrollTop = (0, import_react.useCallback)((pathname = history.current.locations[history.current.idx]?.pathname ?? "/") => {
40
62
  return history.current.scrollMap.get(pathname) ?? 0;
41
63
  }, []);
42
64
  return { history, setHistoryForward, setHistoryBack, getCurrentLocation, getPrevLocation, getScrollTop };
43
65
  };
44
- export {
45
- useHistory
46
- };
package/useHistory.mjs ADDED
@@ -0,0 +1,46 @@
1
+ "use client";
2
+ import { useCallback, useRef } from "react";
3
+ const useHistory = (locations = []) => {
4
+ const history = useRef({
5
+ type: "initial",
6
+ locations,
7
+ scrollMap: /* @__PURE__ */ new Map([[window.location.pathname, 0]]),
8
+ idxMap: /* @__PURE__ */ new Map([[window.location.pathname, 0]]),
9
+ cachedLocationMap: /* @__PURE__ */ new Map(),
10
+ idx: 0
11
+ });
12
+ const setHistoryForward = useCallback(({ type, location, scrollTop = 0 }) => {
13
+ history.current.type = "forward";
14
+ history.current.scrollMap.set(location.pathname, scrollTop);
15
+ history.current.idxMap.set(location.pathname, history.current.idx);
16
+ if (type === "push")
17
+ history.current.locations = [...history.current.locations.slice(0, history.current.idx + 1), location];
18
+ else if (type === "replace")
19
+ history.current.locations = [...history.current.locations.slice(0, history.current.idx), location];
20
+ if (location.pathRoute.pageState.cache)
21
+ history.current.cachedLocationMap.set(location.pathRoute.path, location);
22
+ if (type === "push" || type === "popForward")
23
+ history.current.idx++;
24
+ }, []);
25
+ const setHistoryBack = useCallback(({ location, scrollTop = 0 }) => {
26
+ history.current.type = "back";
27
+ history.current.scrollMap.set(location.pathname, scrollTop);
28
+ history.current.idxMap.set(location.pathname, history.current.idx);
29
+ if (location.pathRoute.pageState.cache)
30
+ history.current.cachedLocationMap.set(location.pathRoute.path, location);
31
+ history.current.idx--;
32
+ }, []);
33
+ const getCurrentLocation = useCallback(() => {
34
+ return history.current.locations[history.current.idx];
35
+ }, []);
36
+ const getPrevLocation = useCallback(() => {
37
+ return history.current.locations[history.current.idx - 1] ?? null;
38
+ }, []);
39
+ const getScrollTop = useCallback((pathname = history.current.locations[history.current.idx]?.pathname ?? "/") => {
40
+ return history.current.scrollMap.get(pathname) ?? 0;
41
+ }, []);
42
+ return { history, setHistoryForward, setHistoryBack, getCurrentLocation, getPrevLocation, getScrollTop };
43
+ };
44
+ export {
45
+ useHistory
46
+ };
package/useInterval.js CHANGED
@@ -1,11 +1,33 @@
1
1
  "use client";
2
- import { useEffect, useRef } from "react";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var useInterval_exports = {};
20
+ __export(useInterval_exports, {
21
+ useInterval: () => useInterval
22
+ });
23
+ module.exports = __toCommonJS(useInterval_exports);
24
+ var import_react = require("react");
3
25
  const useInterval = (callback, delay) => {
4
- const savedCallback = useRef(null);
5
- useEffect(() => {
26
+ const savedCallback = (0, import_react.useRef)(null);
27
+ (0, import_react.useEffect)(() => {
6
28
  savedCallback.current = callback;
7
29
  }, [callback]);
8
- useEffect(() => {
30
+ (0, import_react.useEffect)(() => {
9
31
  const tick = () => {
10
32
  void savedCallback.current?.();
11
33
  };
@@ -16,6 +38,3 @@ const useInterval = (callback, delay) => {
16
38
  }, [delay]);
17
39
  return savedCallback;
18
40
  };
19
- export {
20
- useInterval
21
- };
@@ -0,0 +1,21 @@
1
+ "use client";
2
+ import { useEffect, useRef } from "react";
3
+ const useInterval = (callback, delay) => {
4
+ const savedCallback = useRef(null);
5
+ useEffect(() => {
6
+ savedCallback.current = callback;
7
+ }, [callback]);
8
+ useEffect(() => {
9
+ const tick = () => {
10
+ void savedCallback.current?.();
11
+ };
12
+ const id = setInterval(tick, delay);
13
+ return () => {
14
+ clearInterval(id);
15
+ };
16
+ }, [delay]);
17
+ return savedCallback;
18
+ };
19
+ export {
20
+ useInterval
21
+ };
package/useLocation.js CHANGED
@@ -1,7 +1,29 @@
1
1
  "use client";
2
- import { useCallback } from "react";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var useLocation_exports = {};
20
+ __export(useLocation_exports, {
21
+ useLocation: () => useLocation
22
+ });
23
+ module.exports = __toCommonJS(useLocation_exports);
24
+ var import_react = require("react");
3
25
  const useLocation = ({ rootRouteGuide }) => {
4
- const getLocation = useCallback((href) => {
26
+ const getLocation = (0, import_react.useCallback)((href) => {
5
27
  const getPathSegments = (pathname2) => {
6
28
  return [
7
29
  ...pathname2.split("/").filter((pathSegment) => !!pathSegment).map((pathSegment) => `/${pathSegment}`)
@@ -54,6 +76,3 @@ const useLocation = ({ rootRouteGuide }) => {
54
76
  }, []);
55
77
  return { getLocation };
56
78
  };
57
- export {
58
- useLocation
59
- };
@@ -0,0 +1,59 @@
1
+ "use client";
2
+ import { useCallback } from "react";
3
+ const useLocation = ({ rootRouteGuide }) => {
4
+ const getLocation = useCallback((href) => {
5
+ const getPathSegments = (pathname2) => {
6
+ return [
7
+ ...pathname2.split("/").filter((pathSegment) => !!pathSegment).map((pathSegment) => `/${pathSegment}`)
8
+ ];
9
+ };
10
+ const getPathRoute = (pathname2) => {
11
+ const pathSegments = getPathSegments(pathname2);
12
+ const getTargetRouteGuide = (pathSegments2, routeGuide) => {
13
+ const pathSegment = pathSegments2.shift();
14
+ if (!pathSegment)
15
+ return routeGuide;
16
+ const childrenSegments = Object.keys(routeGuide.children);
17
+ const matchingPathSegment = childrenSegments.find((segment) => segment === pathSegment);
18
+ const paramSegment = childrenSegments.find((segment) => segment.startsWith("/:"));
19
+ const childRouteGuide = matchingPathSegment ? routeGuide.children[pathSegment] : paramSegment ? routeGuide.children[paramSegment] : null;
20
+ if (!childRouteGuide)
21
+ throw new Error("404");
22
+ return getTargetRouteGuide(pathSegments2, childRouteGuide);
23
+ };
24
+ const targetRouteGuide = getTargetRouteGuide(pathSegments, rootRouteGuide);
25
+ const pathRoute2 = targetRouteGuide.pathRoute;
26
+ if (!pathRoute2) {
27
+ window.location.assign("/404");
28
+ throw new Error("404");
29
+ }
30
+ return pathRoute2;
31
+ };
32
+ const getParams = (pathname2, pathRoute2) => {
33
+ const pathSegments = getPathSegments(pathname2);
34
+ return pathRoute2.pathSegments.reduce((params2, pathSegment, idx) => {
35
+ if (pathSegment.startsWith("/:"))
36
+ params2[pathSegment.slice(2)] = pathSegments[idx - 1].slice(1);
37
+ return params2;
38
+ }, {});
39
+ };
40
+ const getSearchParams = (search2) => {
41
+ return [...new URLSearchParams(search2).entries()].reduce(
42
+ (params2, [key, value]) => {
43
+ params2[key] = params2[key] ? [...Array.isArray(params2[key]) ? params2[key] : [params2[key]], value] : value;
44
+ return params2;
45
+ },
46
+ {}
47
+ );
48
+ };
49
+ const [pathname, search] = href.split("?");
50
+ const pathRoute = getPathRoute(pathname);
51
+ const params = getParams(pathname, pathRoute);
52
+ const searchParams = getSearchParams(search);
53
+ return { pathname, search, params, searchParams, pathRoute };
54
+ }, []);
55
+ return { getLocation };
56
+ };
57
+ export {
58
+ useLocation
59
+ };
package/usePurchase.js CHANGED
@@ -1,7 +1,29 @@
1
1
  "use client";
2
- import "cordova-plugin-purchase/www/store";
3
- import { App } from "@capacitor/app";
4
- import { useEffect, useRef, useState } from "react";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var usePurchase_exports = {};
20
+ __export(usePurchase_exports, {
21
+ usePurchase: () => usePurchase
22
+ });
23
+ module.exports = __toCommonJS(usePurchase_exports);
24
+ var import_store = require("cordova-plugin-purchase/www/store");
25
+ var import_app = require("@capacitor/app");
26
+ var import_react = require("react");
5
27
  const usePurchase = ({
6
28
  platform,
7
29
  productInfo,
@@ -9,15 +31,15 @@ const usePurchase = ({
9
31
  onPay,
10
32
  onSubscribe
11
33
  }) => {
12
- const [isLoading, setIsLoading] = useState(true);
13
- const billingRef = useRef();
14
- useEffect(() => {
34
+ const [isLoading, setIsLoading] = (0, import_react.useState)(true);
35
+ const billingRef = (0, import_react.useRef)();
36
+ (0, import_react.useEffect)(() => {
15
37
  const init = async () => {
16
38
  if (CdvPurchase.store.isReady) {
17
39
  setIsLoading(false);
18
40
  return;
19
41
  }
20
- const app = await App.getInfo();
42
+ const app = await import_app.App.getInfo();
21
43
  if (platform === "all")
22
44
  CdvPurchase.store.register([
23
45
  ...productInfo.map((prouct) => ({
@@ -115,6 +137,3 @@ const usePurchase = ({
115
137
  restorePurchases
116
138
  };
117
139
  };
118
- export {
119
- usePurchase
120
- };
@@ -0,0 +1,120 @@
1
+ "use client";
2
+ import "cordova-plugin-purchase/www/store";
3
+ import { App } from "@capacitor/app";
4
+ import { useEffect, useRef, useState } from "react";
5
+ const usePurchase = ({
6
+ platform,
7
+ productInfo,
8
+ url,
9
+ onPay,
10
+ onSubscribe
11
+ }) => {
12
+ const [isLoading, setIsLoading] = useState(true);
13
+ const billingRef = useRef();
14
+ useEffect(() => {
15
+ const init = async () => {
16
+ if (CdvPurchase.store.isReady) {
17
+ setIsLoading(false);
18
+ return;
19
+ }
20
+ const app = await App.getInfo();
21
+ if (platform === "all")
22
+ CdvPurchase.store.register([
23
+ ...productInfo.map((prouct) => ({
24
+ id: prouct.id,
25
+ platform: CdvPurchase.Platform.GOOGLE_PLAY,
26
+ type: CdvPurchase.ProductType[prouct.type]
27
+ })),
28
+ ...productInfo.map((prouct) => ({
29
+ id: prouct.id,
30
+ platform: CdvPurchase.Platform.APPLE_APPSTORE,
31
+ type: CdvPurchase.ProductType[prouct.type]
32
+ }))
33
+ ]);
34
+ else
35
+ CdvPurchase.store.register(
36
+ productInfo.map((product) => ({
37
+ id: product.id,
38
+ platform: platform === "android" ? CdvPurchase.Platform.GOOGLE_PLAY : CdvPurchase.Platform.APPLE_APPSTORE,
39
+ type: CdvPurchase.ProductType[product.type]
40
+ }))
41
+ );
42
+ await CdvPurchase.store.initialize([
43
+ { platform: CdvPurchase.Platform.APPLE_APPSTORE, options: { needAppReceipt: false } },
44
+ { platform: CdvPurchase.Platform.GOOGLE_PLAY }
45
+ ]);
46
+ await CdvPurchase.store.update();
47
+ await CdvPurchase.store.restorePurchases();
48
+ CdvPurchase.store.validator = async (request, callback) => {
49
+ const transactionId = request.transaction.id;
50
+ const transactions = CdvPurchase.store.localTransactions;
51
+ const verifingTransaction = transactions.find((transaction) => transaction.transactionId === transactionId);
52
+ if (verifingTransaction?.state !== "approved")
53
+ return;
54
+ const billing = await fetch(`${url}/billing/verifyBilling`, {
55
+ method: "POST",
56
+ headers: {
57
+ "Content-Type": "application/json"
58
+ },
59
+ body: JSON.stringify({
60
+ data: {
61
+ platform: verifingTransaction.platform === CdvPurchase.Platform.GOOGLE_PLAY ? "google" : "apple",
62
+ packageName: app.id,
63
+ productId: verifingTransaction.products[0].id,
64
+ receipt: verifingTransaction.platform === CdvPurchase.Platform.GOOGLE_PLAY ? request.transaction.purchaseToken : request.transaction.appStoreReceipt,
65
+ transactionId: verifingTransaction.transactionId
66
+ }
67
+ })
68
+ });
69
+ billingRef.current = billing.json();
70
+ callback({
71
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
72
+ ok: billing ? true : false,
73
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
74
+ data: { id: request.id, latest_receipt: true, transaction: request.transaction }
75
+ });
76
+ };
77
+ if (CdvPurchase.store.localReceipts.length > 0) {
78
+ CdvPurchase.store.localReceipts.forEach((receipt) => {
79
+ if (receipt.platform === CdvPurchase.Platform.GOOGLE_PLAY)
80
+ if (receipt.transactions[0].state === CdvPurchase.TransactionState.APPROVED)
81
+ void receipt.transactions[0].verify();
82
+ else
83
+ void receipt.transactions[0].finish();
84
+ });
85
+ }
86
+ CdvPurchase.store.when().approved((transaction) => {
87
+ void transaction.verify();
88
+ }).verified((receipt) => {
89
+ void receipt.finish();
90
+ }).finished((transaction) => {
91
+ void inAppPurchase(transaction);
92
+ });
93
+ setIsLoading(false);
94
+ };
95
+ void init();
96
+ }, []);
97
+ const purchaseProduct = async (product) => {
98
+ await product.getOffer()?.order();
99
+ };
100
+ const restorePurchases = async () => {
101
+ await CdvPurchase.store.restorePurchases();
102
+ };
103
+ const inAppPurchase = async (transaction) => {
104
+ const product = CdvPurchase.store.get(transaction.products[0].id);
105
+ if (product?.type === "consumable")
106
+ await onPay?.(transaction);
107
+ else
108
+ await onSubscribe?.(transaction);
109
+ await transaction.finish();
110
+ };
111
+ return {
112
+ isLoading,
113
+ products: CdvPurchase.store.products,
114
+ purchaseProduct,
115
+ restorePurchases
116
+ };
117
+ };
118
+ export {
119
+ usePurchase
120
+ };
package/usePushNoti.js CHANGED
@@ -1,42 +1,61 @@
1
1
  "use client";
2
- import { Device } from "@capacitor/device";
3
- import { PushNotifications } from "@capacitor/push-notifications";
4
- import { FCM } from "@capacitor-community/fcm";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var usePushNoti_exports = {};
20
+ __export(usePushNoti_exports, {
21
+ usePushNoti: () => usePushNoti
22
+ });
23
+ module.exports = __toCommonJS(usePushNoti_exports);
24
+ var import_device = require("@capacitor/device");
25
+ var import_push_notifications = require("@capacitor/push-notifications");
26
+ var import_fcm = require("@capacitor-community/fcm");
5
27
  const usePushNoti = () => {
6
28
  const init = async () => {
7
- const device = await Device.getInfo();
29
+ const device = await import_device.Device.getInfo();
8
30
  if (device.platform === "web")
9
31
  return;
10
- void FCM.setAutoInit({ enabled: true });
11
- void PushNotifications.requestPermissions().then(async (result) => {
32
+ void import_fcm.FCM.setAutoInit({ enabled: true });
33
+ void import_push_notifications.PushNotifications.requestPermissions().then(async (result) => {
12
34
  if (result.receive === "granted") {
13
- await PushNotifications.register();
35
+ await import_push_notifications.PushNotifications.register();
14
36
  }
15
37
  });
16
38
  };
17
39
  const checkPermission = async () => {
18
- const { receive } = await PushNotifications.checkPermissions();
40
+ const { receive } = await import_push_notifications.PushNotifications.checkPermissions();
19
41
  return receive === "granted";
20
42
  };
21
43
  const register = async () => {
22
- const device = await Device.getInfo();
44
+ const device = await import_device.Device.getInfo();
23
45
  if (device.platform === "web")
24
46
  return;
25
- const { receive } = await PushNotifications.checkPermissions();
47
+ const { receive } = await import_push_notifications.PushNotifications.checkPermissions();
26
48
  if (receive === "denied")
27
49
  location.assign("app-settings:");
28
50
  else
29
- await PushNotifications.register();
51
+ await import_push_notifications.PushNotifications.register();
30
52
  };
31
53
  const getToken = async () => {
32
- const device = await Device.getInfo();
54
+ const device = await import_device.Device.getInfo();
33
55
  if (device.platform === "web")
34
56
  return;
35
- const { token } = await FCM.getToken();
57
+ const { token } = await import_fcm.FCM.getToken();
36
58
  return token;
37
59
  };
38
60
  return { init, checkPermission, register, getToken };
39
61
  };
40
- export {
41
- usePushNoti
42
- };
@@ -0,0 +1,42 @@
1
+ "use client";
2
+ import { Device } from "@capacitor/device";
3
+ import { PushNotifications } from "@capacitor/push-notifications";
4
+ import { FCM } from "@capacitor-community/fcm";
5
+ const usePushNoti = () => {
6
+ const init = async () => {
7
+ const device = await Device.getInfo();
8
+ if (device.platform === "web")
9
+ return;
10
+ void FCM.setAutoInit({ enabled: true });
11
+ void PushNotifications.requestPermissions().then(async (result) => {
12
+ if (result.receive === "granted") {
13
+ await PushNotifications.register();
14
+ }
15
+ });
16
+ };
17
+ const checkPermission = async () => {
18
+ const { receive } = await PushNotifications.checkPermissions();
19
+ return receive === "granted";
20
+ };
21
+ const register = async () => {
22
+ const device = await Device.getInfo();
23
+ if (device.platform === "web")
24
+ return;
25
+ const { receive } = await PushNotifications.checkPermissions();
26
+ if (receive === "denied")
27
+ location.assign("app-settings:");
28
+ else
29
+ await PushNotifications.register();
30
+ };
31
+ const getToken = async () => {
32
+ const device = await Device.getInfo();
33
+ if (device.platform === "web")
34
+ return;
35
+ const { token } = await FCM.getToken();
36
+ return token;
37
+ };
38
+ return { init, checkPermission, register, getToken };
39
+ };
40
+ export {
41
+ usePushNoti
42
+ };