@akanjs/next 0.0.97 → 0.0.99

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 (58) hide show
  1. package/{bootCsr.mjs → bootCsr.cjs} +52 -28
  2. package/bootCsr.js +28 -52
  3. package/createNextMiddleware.cjs +78 -0
  4. package/createNextMiddleware.js +13 -42
  5. package/createRobotPage.cjs +34 -0
  6. package/createRobotPage.js +3 -22
  7. package/createSitemapPage.cjs +26 -0
  8. package/createSitemapPage.js +3 -22
  9. package/index.cjs +60 -0
  10. package/index.js +40 -59
  11. package/lazy.cjs +35 -0
  12. package/lazy.js +5 -34
  13. package/{makePageProto.mjs → makePageProto.cjs} +32 -13
  14. package/makePageProto.js +13 -32
  15. package/package.json +4 -4
  16. package/types.cjs +15 -0
  17. package/types.js +0 -15
  18. package/useCamera.cjs +96 -0
  19. package/useCamera.js +17 -36
  20. package/useCodepush.cjs +103 -0
  21. package/useCodepush.js +25 -54
  22. package/useContact.cjs +55 -0
  23. package/useContact.js +12 -31
  24. package/{useCsrValues.mjs → useCsrValues.cjs} +74 -59
  25. package/useCsrValues.js +59 -74
  26. package/useDebounce.cjs +37 -0
  27. package/useDebounce.js +5 -24
  28. package/useFetch.cjs +42 -0
  29. package/useFetch.js +6 -25
  30. package/useGeoLocation.cjs +40 -0
  31. package/useGeoLocation.js +6 -25
  32. package/{useHistory.mjs → useHistory.cjs} +29 -10
  33. package/useHistory.js +10 -29
  34. package/useInterval.cjs +40 -0
  35. package/useInterval.js +7 -26
  36. package/{useLocation.mjs → useLocation.cjs} +24 -5
  37. package/useLocation.js +5 -24
  38. package/{usePurchase.mjs → usePurchase.cjs} +29 -10
  39. package/usePurchase.js +10 -29
  40. package/usePushNoti.cjs +61 -0
  41. package/usePushNoti.js +16 -35
  42. package/useThrottle.cjs +39 -0
  43. package/useThrottle.js +6 -25
  44. package/createNextMiddleware.mjs +0 -49
  45. package/createRobotPage.mjs +0 -15
  46. package/createSitemapPage.mjs +0 -7
  47. package/index.mjs +0 -41
  48. package/lazy.mjs +0 -6
  49. package/types.mjs +0 -0
  50. package/useCamera.mjs +0 -77
  51. package/useCodepush.mjs +0 -74
  52. package/useContact.mjs +0 -36
  53. package/useDebounce.mjs +0 -18
  54. package/useFetch.mjs +0 -23
  55. package/useGeoLocation.mjs +0 -21
  56. package/useInterval.mjs +0 -21
  57. package/usePushNoti.mjs +0 -42
  58. package/useThrottle.mjs +0 -20
package/useCamera.mjs DELETED
@@ -1,77 +0,0 @@
1
- "use client";
2
- import { device } from "@akanjs/client";
3
- import { Camera, CameraResultType, CameraSource } from "@capacitor/camera";
4
- import { useEffect, useState } from "react";
5
- const useCamera = () => {
6
- const [permissions, setPermissions] = useState({ camera: "prompt", photos: "prompt" });
7
- const checkPermission = async (type) => {
8
- try {
9
- if (type === "photos") {
10
- if (permissions.photos === "prompt") {
11
- const { photos } = await Camera.requestPermissions();
12
- setPermissions((prev) => ({ ...prev, photos }));
13
- } else if (permissions.photos === "denied") {
14
- location.assign("app-settings:");
15
- return;
16
- }
17
- } else if (type === "camera") {
18
- if (permissions.camera === "prompt") {
19
- const { camera } = await Camera.requestPermissions();
20
- setPermissions((prev) => ({ ...prev, camera }));
21
- } else if (permissions.camera === "denied") {
22
- location.assign("app-settings:");
23
- return;
24
- }
25
- } else {
26
- if (permissions.camera === "prompt" || permissions.photos === "prompt") {
27
- const permissions2 = await Camera.requestPermissions();
28
- setPermissions(permissions2);
29
- } else if (permissions.camera === "denied" || permissions.photos === "denied") {
30
- location.assign("app-settings:");
31
- return;
32
- }
33
- }
34
- } catch (e) {
35
- }
36
- };
37
- const getPhoto = async (src = "prompt") => {
38
- const source = device.info.platform !== "web" ? src === "prompt" ? CameraSource.Prompt : src === "camera" ? CameraSource.Camera : CameraSource.Photos : CameraSource.Photos;
39
- const permission = src === "prompt" ? "all" : src === "camera" ? "camera" : "photos";
40
- void checkPermission(permission);
41
- try {
42
- const photo = await Camera.getPhoto({
43
- quality: 100,
44
- source,
45
- allowEditing: false,
46
- resultType: CameraResultType.DataUrl,
47
- promptLabelHeader: "\uD504\uB85C\uD544 \uC0AC\uC9C4\uC744 \uC62C\uB824\uC8FC\uC138\uC694",
48
- promptLabelPhoto: "\uC568\uBC94\uC5D0\uC11C \uC120\uD0DD\uD558\uAE30",
49
- promptLabelPicture: "\uC0AC\uC9C4 \uCC0D\uAE30",
50
- promptLabelCancel: "\uCDE8\uC18C"
51
- });
52
- return photo;
53
- } catch (e) {
54
- if (e === "User cancelled photos app")
55
- return;
56
- }
57
- };
58
- const pickImage = async () => {
59
- void checkPermission("photos");
60
- const photo = await Camera.pickImages({
61
- quality: 90
62
- });
63
- return photo;
64
- };
65
- useEffect(() => {
66
- void (async () => {
67
- if (device.info.platform !== "web") {
68
- const permissions2 = await Camera.checkPermissions();
69
- setPermissions(permissions2);
70
- }
71
- })();
72
- }, []);
73
- return { permissions, getPhoto, pickImage, checkPermission };
74
- };
75
- export {
76
- useCamera
77
- };
package/useCodepush.mjs DELETED
@@ -1,74 +0,0 @@
1
- "use client";
2
- import { mergeVersion, splitVersion } from "@akanjs/common";
3
- import { App } from "@capacitor/app";
4
- import { Device } from "@capacitor/device";
5
- import { CapacitorUpdater } from "@capgo/capacitor-updater";
6
- import axios from "axios";
7
- import { useState } from "react";
8
- const useCodepush = ({ serverUrl, branch }) => {
9
- const [update, setUpdate] = useState(false);
10
- const [version, setVersion] = useState("");
11
- const initialize = async () => {
12
- await CapacitorUpdater.notifyAppReady();
13
- };
14
- const checkNewRelease = async () => {
15
- const info = await Device.getInfo();
16
- const app = await App.getInfo();
17
- const pluginVersion = await CapacitorUpdater.getPluginVersion();
18
- const { deviceId } = await CapacitorUpdater.getDeviceId();
19
- const { bundle: version2, native } = await CapacitorUpdater.current();
20
- const builtInversion = await CapacitorUpdater.getBuiltinVersion();
21
- const appId = app.id;
22
- const platform = info.platform;
23
- window.alert(
24
- `getBuildinVersion:${builtInversion.version}
25
- current.bundle:${version2.version}
26
- currennt.native:${native}`
27
- );
28
- const { major, minor, patch } = splitVersion(version2.version === "builtin" ? app.version : version2.version);
29
- const appName = process.env.NEXT_PUBLIC_APP_NAME ?? "";
30
- const appInfo = {
31
- appId,
32
- appName,
33
- deviceId,
34
- platform,
35
- branch,
36
- isEmulator: info.isVirtual,
37
- major: parseInt(major),
38
- minor: parseInt(minor),
39
- patch: parseInt(patch),
40
- buildNum: app.build,
41
- //앱내 빌드시 버전 횟수 모르면 고한테 물어보기
42
- versionOs: info.osVersion
43
- };
44
- const url = serverUrl.replace("lu", "akasys");
45
- const release = (await axios.post(`${url}/release/codepush`, {
46
- data: { ...appInfo }
47
- })).data;
48
- if (!release)
49
- return;
50
- const file = (await axios.get(`${url}/file/file/${release.appBuild}`)).data;
51
- return { release, bundleFile: file };
52
- };
53
- const codepush = async () => {
54
- const isNewRelease = await checkNewRelease();
55
- if (!isNewRelease)
56
- return;
57
- const { release, bundleFile } = isNewRelease;
58
- setUpdate(true);
59
- const bundle = await CapacitorUpdater.download({
60
- url: bundleFile.url,
61
- version: mergeVersion(release.major, release.minor, release.patch)
62
- });
63
- await CapacitorUpdater.set(bundle);
64
- };
65
- const getVersion = async () => {
66
- return await CapacitorUpdater.getBuiltinVersion();
67
- };
68
- const statManager = async () => {
69
- };
70
- return { update, version, initialize, checkNewRelease, codepush, statManager };
71
- };
72
- export {
73
- useCodepush
74
- };
package/useContact.mjs DELETED
@@ -1,36 +0,0 @@
1
- "use client";
2
- import { device } from "@akanjs/client";
3
- import { Contacts } from "@capacitor-community/contacts";
4
- import { useEffect, useState } from "react";
5
- const useContact = () => {
6
- const [permissions, setPermissions] = useState({ contacts: "prompt" });
7
- const checkPermission = async () => {
8
- try {
9
- if (permissions.contacts === "prompt") {
10
- const { contacts } = await Contacts.requestPermissions();
11
- setPermissions((prev) => ({ ...prev, contacts }));
12
- } else if (permissions.contacts === "denied") {
13
- location.assign("app-settings:");
14
- return;
15
- }
16
- } catch (e) {
17
- }
18
- };
19
- const getContacts = async () => {
20
- await checkPermission();
21
- const { contacts } = await Contacts.getContacts({ projection: { name: true, phones: true } });
22
- return contacts;
23
- };
24
- useEffect(() => {
25
- void (async () => {
26
- if (device.info.platform === "web")
27
- return;
28
- const permissions2 = await Contacts.checkPermissions();
29
- setPermissions(permissions2);
30
- })();
31
- }, []);
32
- return { permissions, getContacts, checkPermission };
33
- };
34
- export {
35
- useContact
36
- };
package/useDebounce.mjs DELETED
@@ -1,18 +0,0 @@
1
- "use client";
2
- import { useCallback } from "react";
3
- const debounce = (callback, wait = 500) => {
4
- let timer;
5
- return (...args) => {
6
- clearTimeout(timer);
7
- timer = setTimeout(() => {
8
- callback(...args);
9
- }, wait);
10
- };
11
- };
12
- const useDebounce = (callback, states = [], wait = 100) => {
13
- const fn = useCallback(debounce(callback, wait), states);
14
- return fn;
15
- };
16
- export {
17
- useDebounce
18
- };
package/useFetch.mjs DELETED
@@ -1,23 +0,0 @@
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
- };
@@ -1,21 +0,0 @@
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/useInterval.mjs DELETED
@@ -1,21 +0,0 @@
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/usePushNoti.mjs DELETED
@@ -1,42 +0,0 @@
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
- };
package/useThrottle.mjs DELETED
@@ -1,20 +0,0 @@
1
- "use client";
2
- import { useCallback, useRef } from "react";
3
- const useThrottle = (func, delay = 200, deps = []) => {
4
- const throttleSeed = useRef(null);
5
- const throttleFunction = useCallback(
6
- (...args) => {
7
- if (throttleSeed.current)
8
- return;
9
- func(...args);
10
- throttleSeed.current = setTimeout(() => {
11
- throttleSeed.current = null;
12
- }, delay);
13
- },
14
- [func, delay, ...deps]
15
- );
16
- return throttleFunction;
17
- };
18
- export {
19
- useThrottle
20
- };