@akanjs/client 0.0.40 → 0.0.41

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akanjs/client",
3
- "version": "0.0.40",
3
+ "version": "0.0.41",
4
4
  "type": "commonjs",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -14,5 +14,24 @@
14
14
  "engines": {
15
15
  "node": ">=22"
16
16
  },
17
- "dependencies": {}
17
+ "dependencies": {
18
+ "@capacitor/core": "^7.2.0",
19
+ "@capacitor/device": "^7.0.1",
20
+ "@capacitor/haptics": "^7.0.1",
21
+ "@capacitor/keyboard": "^7.0.1",
22
+ "@capacitor/preferences": "^7.0.1",
23
+ "@urql/core": "^5.1.0",
24
+ "capacitor-plugin-safe-area": "^3.0.4",
25
+ "clsx": "^2.1.1",
26
+ "dayjs": "^1.11.13",
27
+ "immer": "^10.1.1",
28
+ "js-cookie": "^3.0.5",
29
+ "jwt-decode": "^4.0.0",
30
+ "next": "^15.3.2",
31
+ "pluralize": "^8.0.0",
32
+ "react": "^18.3.1",
33
+ "react-device-detect": "^2.2.3",
34
+ "reflect-metadata": "^0.2.2",
35
+ "socket.io-client": "^4.8.1"
36
+ }
18
37
  }
package/src/cookie.d.ts CHANGED
@@ -1,71 +1,29 @@
1
- import { Dayjs } from 'dayjs';
2
- import Cookies from 'js-cookie';
3
-
4
- type Environment = "testing" | "debug" | "develop" | "main";
5
-
6
- declare const Account: (option?: {
7
- nullable?: boolean;
8
- }) => (prototype: object, key: string, idx: number) => void;
9
- type Account<AddData = unknown> = {
10
- __InternalArg__: "Account";
11
- self?: Self;
12
- me?: Me;
13
- appName: string;
14
- environment: Environment;
15
- } & AddData;
16
- declare const Self: (option?: {
17
- nullable?: boolean;
18
- }) => (prototype: object, key: string, idx: number) => void;
19
- interface Self {
20
- __InternalArg__: "Self";
21
- id: string;
22
- nickname: string;
23
- roles: string[];
24
- image: {
25
- url: string;
26
- imageSize: [number, number];
27
- } | null;
28
- profileStatus: "active" | "prepare" | "applied" | "approved" | "reapplied" | "featured" | "reserved" | "rejected";
29
- status: "prepare" | "active" | "restricted" | "dormant";
30
- removedAt: Dayjs | null;
31
- }
32
- declare const Me: (option?: {
33
- nullable?: boolean;
34
- }) => (prototype: object, key: string, idx: number) => void;
35
- interface Me {
36
- __InternalArg__: "Me";
37
- id: string;
38
- accountId: string;
39
- roles: string[];
40
- status: "active";
41
- removedAt: Dayjs | null;
42
- }
43
-
44
- declare const cookies: () => Map<string, {
1
+ import { type Account, type Me, type Self } from "@akanjs/signal";
2
+ import Cookies from "js-cookie";
3
+ export declare const cookies: () => Map<string, {
45
4
  name: string;
46
5
  value: string;
47
6
  }>;
48
- declare const setCookie: (key: string, value: string, options?: Cookies.CookieAttributes) => void;
49
- declare const getCookie: (key: string) => string | undefined;
50
- declare const removeCookie: (key: string, options?: {
7
+ export declare const setCookie: (key: string, value: string, options?: Cookies.CookieAttributes) => void;
8
+ export declare const getCookie: (key: string) => string | undefined;
9
+ export declare const removeCookie: (key: string, options?: {
51
10
  path: string;
52
11
  }) => boolean | undefined;
53
- declare const headers: () => Map<string, string>;
54
- declare const getHeader: (key: string) => string | undefined;
55
- declare const getAccount: () => Account;
56
- interface GetOption {
12
+ export declare const headers: () => Map<string, string>;
13
+ export declare const getHeader: (key: string) => string | undefined;
14
+ export declare const getAccount: () => Account;
15
+ export interface GetOption {
57
16
  unauthorize: string;
58
17
  }
59
- declare function getMe<O extends GetOption | undefined>(option?: O): O extends GetOption ? Me : Me | undefined;
60
- declare function getSelf<O extends GetOption | undefined>(option?: O): O extends GetOption ? Self : Self | undefined;
18
+ export declare function getMe<O extends GetOption | undefined>(option?: O): O extends GetOption ? Me : Me | undefined;
19
+ export declare function getSelf<O extends GetOption | undefined>(option?: O): O extends GetOption ? Self : Self | undefined;
61
20
  interface SetAuthOption {
62
21
  jwt: string;
63
22
  }
64
- declare const setAuth: ({ jwt }: SetAuthOption) => void;
23
+ export declare const setAuth: ({ jwt }: SetAuthOption) => void;
65
24
  interface InitAuthOption {
66
25
  jwt?: string;
67
26
  }
68
- declare const initAuth: ({ jwt }?: InitAuthOption) => void;
69
- declare const resetAuth: () => void;
70
-
71
- export { type GetOption, cookies, getAccount, getCookie, getHeader, getMe, getSelf, headers, initAuth, removeCookie, resetAuth, setAuth, setCookie };
27
+ export declare const initAuth: ({ jwt }?: InitAuthOption) => void;
28
+ export declare const resetAuth: () => void;
29
+ export {};
@@ -1,6 +1,4 @@
1
- declare const createFont: (data: any) => null;
2
-
3
- declare const Nanum_Gothic_Coding: (data: any) => null;
4
- declare const Noto_Sans_KR: (data: any) => null;
5
-
6
- export { Nanum_Gothic_Coding, Noto_Sans_KR, createFont, createFont as default };
1
+ export declare const createFont: (data: any) => null;
2
+ export default createFont;
3
+ export declare const Nanum_Gothic_Coding: (data: any) => null;
4
+ export declare const Noto_Sans_KR: (data: any) => null;
package/src/csrTypes.d.ts CHANGED
@@ -1,11 +1,10 @@
1
- import * as react from 'react';
2
- import { ReactNode, ExoticComponent, MutableRefObject } from 'react';
3
- import { ReactDOMAttributes } from '@use-gesture/react/dist/declarations/src/types';
4
- import { AnimatedComponent, SpringValue, Interpolation } from 'react-spring';
5
- import { RouterInstance } from './router.js';
6
-
7
- type TransitionType = "none" | "fade" | "bottomUp" | "stack" | "scaleOut";
8
- interface CsrConfig {
1
+ import type { ReactDOMAttributes } from "@use-gesture/react/dist/declarations/src/types";
2
+ import { type ExoticComponent, type MutableRefObject } from "react";
3
+ import { ReactNode } from "react";
4
+ import type { AnimatedComponent, Interpolation, SpringValue } from "react-spring";
5
+ import type { RouterInstance } from "./router";
6
+ export type TransitionType = "none" | "fade" | "bottomUp" | "stack" | "scaleOut";
7
+ export interface CsrConfig {
9
8
  transition?: TransitionType;
10
9
  safeArea?: boolean;
11
10
  topInset?: boolean | number;
@@ -13,7 +12,7 @@ interface CsrConfig {
13
12
  gesture?: boolean;
14
13
  cache?: boolean;
15
14
  }
16
- interface CsrState {
15
+ export interface CsrState {
17
16
  transition: TransitionType;
18
17
  topSafeArea: number;
19
18
  bottomSafeArea: number;
@@ -22,9 +21,9 @@ interface CsrState {
22
21
  gesture: boolean;
23
22
  cache: boolean;
24
23
  }
25
- declare const DEFAULT_TOP_INSET = 48;
26
- declare const DEFAULT_BOTTOM_INSET = 60;
27
- interface Route {
24
+ export declare const DEFAULT_TOP_INSET = 48;
25
+ export declare const DEFAULT_BOTTOM_INSET = 60;
26
+ export interface Route {
28
27
  csrConfig?: CsrConfig;
29
28
  path: string;
30
29
  Page?: (({ params, searchParams }: {
@@ -47,20 +46,20 @@ interface Route {
47
46
  pageState?: PageState;
48
47
  children: Map<string, Route>;
49
48
  }
50
- type TransitionStyle = NonNullable<AnimatedComponent<ExoticComponent>["defaultProps"]>["style"];
51
- interface SafeAreaTransition {
49
+ export type TransitionStyle = NonNullable<AnimatedComponent<ExoticComponent>["defaultProps"]>["style"];
50
+ export interface SafeAreaTransition {
52
51
  containerStyle: TransitionStyle;
53
52
  }
54
- interface ContainerTransition {
53
+ export interface ContainerTransition {
55
54
  containerStyle: TransitionStyle;
56
55
  contentStyle: TransitionStyle;
57
56
  prevContentStyle: TransitionStyle;
58
57
  }
59
- interface PageTransition {
58
+ export interface PageTransition {
60
59
  containerStyle: TransitionStyle;
61
60
  contentStyle: TransitionStyle;
62
61
  }
63
- interface CsrTransitionStyles {
62
+ export interface CsrTransitionStyles {
64
63
  topSafeArea: SafeAreaTransition | null;
65
64
  page: PageTransition | null;
66
65
  prevPage: PageTransition | null;
@@ -69,12 +68,12 @@ interface CsrTransitionStyles {
69
68
  topLeftAction: ContainerTransition | null;
70
69
  bottomSafeArea: SafeAreaTransition | null;
71
70
  }
72
- type PageState = CsrState & {
71
+ export type PageState = CsrState & {
73
72
  topInset: number;
74
73
  bottomInset: number;
75
74
  };
76
- declare const defaultPageState: PageState;
77
- interface Location {
75
+ export declare const defaultPageState: PageState;
76
+ export interface Location {
78
77
  pathname: string;
79
78
  search: string;
80
79
  params: {
@@ -85,11 +84,11 @@ interface Location {
85
84
  };
86
85
  pathRoute: PathRoute;
87
86
  }
88
- interface LocationState {
87
+ export interface LocationState {
89
88
  location: Location;
90
89
  prevLocation: Location | null;
91
90
  }
92
- interface History {
91
+ export interface History {
93
92
  type: "initial" | "forward" | "back";
94
93
  locations: Location[];
95
94
  scrollMap: Map<string, number>;
@@ -97,13 +96,13 @@ interface History {
97
96
  cachedLocationMap: Map<string, Location>;
98
97
  idx: number;
99
98
  }
100
- interface RouterProps {
99
+ export interface RouterProps {
101
100
  push: (path: string) => void;
102
101
  replace: (path: string) => void;
103
102
  refresh: () => void;
104
103
  back: () => void | Promise<void>;
105
104
  }
106
- interface RouteState {
105
+ export interface RouteState {
107
106
  clientWidth: number;
108
107
  clientHeight: number;
109
108
  location: Location;
@@ -120,7 +119,7 @@ interface RouteState {
120
119
  router: RouterInstance;
121
120
  pathRoutes: PathRoute[];
122
121
  }
123
- type UseCsrTransition = CsrTransitionStyles & {
122
+ export type UseCsrTransition = CsrTransitionStyles & {
124
123
  pageBind: (...args: any[]) => ReactDOMAttributes;
125
124
  pageClassName: string;
126
125
  transDirection: "vertical" | "horizontal" | "none";
@@ -129,18 +128,18 @@ type UseCsrTransition = CsrTransitionStyles & {
129
128
  transPercent: Interpolation<number>;
130
129
  transProgress: Interpolation<number>;
131
130
  };
132
- type CsrContextType = RouteState & UseCsrTransition;
133
- declare const csrContext: react.Context<CsrContextType>;
134
- declare const useCsr: () => CsrContextType;
135
- interface PathContextType {
131
+ export type CsrContextType = RouteState & UseCsrTransition;
132
+ export declare const csrContext: import("react").Context<CsrContextType>;
133
+ export declare const useCsr: () => CsrContextType;
134
+ export interface PathContextType {
136
135
  pageType: "current" | "prev" | "cached";
137
136
  location: Location;
138
137
  gestureEnabled: boolean;
139
138
  setGestureEnabled: (enabled: boolean) => void;
140
139
  }
141
- declare const pathContext: react.Context<PathContextType>;
142
- declare const usePathCtx: () => PathContextType;
143
- interface PathRoute {
140
+ export declare const pathContext: import("react").Context<PathContextType>;
141
+ export declare const usePathCtx: () => PathContextType;
142
+ export interface PathRoute {
144
143
  path: string;
145
144
  pathSegments: string[];
146
145
  Page: (({ params, searchParams }: {
@@ -170,12 +169,10 @@ interface PathRoute {
170
169
  searchParams: any;
171
170
  }) => Promise<ReactNode>))[];
172
171
  }
173
- interface RouteGuide {
172
+ export interface RouteGuide {
174
173
  pathSegment: string;
175
174
  pathRoute?: PathRoute;
176
175
  children: {
177
176
  [key: string]: RouteGuide;
178
177
  };
179
178
  }
180
-
181
- export { type ContainerTransition, type CsrConfig, type CsrContextType, type CsrState, type CsrTransitionStyles, DEFAULT_BOTTOM_INSET, DEFAULT_TOP_INSET, type History, type Location, type LocationState, type PageState, type PageTransition, type PathContextType, type PathRoute, type Route, type RouteGuide, type RouteState, type RouterProps, type SafeAreaTransition, type TransitionStyle, type TransitionType, type UseCsrTransition, csrContext, defaultPageState, pathContext, useCsr, usePathCtx };
package/src/device.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- import { DeviceInfo } from '@capacitor/device';
2
- import { MutableRefObject } from 'react';
3
-
1
+ import { type DeviceInfo } from "@capacitor/device";
2
+ import type { MutableRefObject } from "react";
4
3
  interface DeviceInitOption {
5
4
  lang?: string;
6
5
  supportLanguages?: string[] | readonly string[];
@@ -22,6 +21,5 @@ declare class Device {
22
21
  getScrollTop(): number;
23
22
  setScrollTop(scrollTop: number): void;
24
23
  }
25
- declare const device: Device;
26
-
27
- export { device };
24
+ export declare const device: Device;
25
+ export {};
package/src/index.d.ts CHANGED
@@ -1,14 +1,7 @@
1
- export { DataAction, DataColumn, DataMenu, DataMenuItem, DataTool, MenuItem, ModelDashboardProps, ModelEditProps, ModelInsightProps, ModelProps, ModelViewProps, ModelsProps, ReactFont, RootLayoutProps, UserMenuItem, clsx, loadFonts } from './types.js';
2
- export { ContainerTransition, CsrConfig, CsrContextType, CsrState, CsrTransitionStyles, DEFAULT_BOTTOM_INSET, DEFAULT_TOP_INSET, History, Location, LocationState, PageState, PageTransition, PathContextType, PathRoute, Route, RouteGuide, RouteState, RouterProps, SafeAreaTransition, TransitionStyle, TransitionType, UseCsrTransition, csrContext, defaultPageState, pathContext, useCsr, usePathCtx } from './csrTypes.js';
3
- export { RouterInstance, getPathInfo, router } from './router.js';
4
- export { GetOption, cookies, getAccount, getCookie, getHeader, getMe, getSelf, headers, initAuth, removeCookie, resetAuth, setAuth, setCookie } from './cookie.js';
5
- export { storage } from './storage.js';
6
- export { device } from './device.js';
7
- export { Nanum_Gothic_Coding, Noto_Sans_KR, default as createFont } from './createFont.js';
8
- import 'dayjs';
9
- import 'clsx';
10
- import 'react';
11
- import '@use-gesture/react/dist/declarations/src/types';
12
- import 'react-spring';
13
- import 'js-cookie';
14
- import '@capacitor/device';
1
+ export * from "./types";
2
+ export * from "./csrTypes";
3
+ export * from "./router";
4
+ export * from "./cookie";
5
+ export * from "./storage";
6
+ export * from "./device";
7
+ export * from "./createFont";
package/src/router.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- interface RouterInstance {
1
+ export interface RouterInstance {
2
2
  push: (href: string) => void;
3
3
  replace: (href: string) => void;
4
4
  back: () => void;
@@ -21,7 +21,7 @@ interface CSRClientRouterOption extends RouterOptions {
21
21
  type: "csr";
22
22
  router: RouterInstance;
23
23
  }
24
- declare const getPathInfo: (href: string, lang: string, prefix: string) => {
24
+ export declare const getPathInfo: (href: string, lang: string, prefix: string) => {
25
25
  path: string;
26
26
  pathname: string;
27
27
  };
@@ -41,6 +41,5 @@ declare class Router {
41
41
  getPrefix(): string;
42
42
  getPrefixedPath(path: string): string;
43
43
  }
44
- declare const router: Router;
45
-
46
- export { type RouterInstance, getPathInfo, router };
44
+ export declare const router: Router;
45
+ export {};
package/src/storage.d.ts CHANGED
@@ -1,7 +1,5 @@
1
- declare const storage: {
1
+ export declare const storage: {
2
2
  getItem: (key: string) => Promise<string | null | undefined>;
3
3
  setItem: (key: string, value: string) => Promise<void>;
4
4
  removeItem: (key: string) => Promise<void> | undefined;
5
5
  };
6
-
7
- export { storage };
package/src/types.d.ts CHANGED
@@ -1,30 +1,8 @@
1
- import { Dayjs } from 'dayjs';
2
- import { ClassValue } from 'clsx';
3
- import { ReactNode } from 'react';
4
-
5
- type SortOf<Filter> = keyof GetStateObject<Filter>;
6
- type FilterType = Record<string, any>;
7
- type GetStateObject<T> = Omit<{
8
- [K in keyof T as T[K] extends (...args: any) => any ? never : K]: T[K];
9
- }, "prototype">;
10
-
11
- type FieldState<T> = T extends string ? T : T extends number ? T : T extends boolean ? T : T extends Dayjs ? T : T extends any[] ? T : T extends {
12
- id: string;
13
- } ? T | null : T;
14
- type DefaultOf<S> = S extends infer T ? {
15
- [K in keyof T]: FieldState<T[K]>;
16
- } : never;
17
- interface FetchInitForm<Input, Full, Filter extends FilterType> {
18
- page?: number;
19
- limit?: number;
20
- sort?: SortOf<Filter> | symbol;
21
- default?: Partial<DefaultOf<Input>>;
22
- invalidate?: boolean;
23
- insight?: boolean;
24
- }
25
-
26
- declare const clsx: (...args: ClassValue[]) => string;
27
- declare const loadFonts: (fonts: {
1
+ import type { FetchInitForm } from "@akanjs/signal";
2
+ import { type ClassValue } from "clsx";
3
+ import type { ReactNode } from "react";
4
+ export declare const clsx: (...args: ClassValue[]) => string;
5
+ export declare const loadFonts: (fonts: {
28
6
  name: string;
29
7
  nextFont: any;
30
8
  paths: {
@@ -32,7 +10,7 @@ declare const loadFonts: (fonts: {
32
10
  weight: number;
33
11
  }[];
34
12
  }[]) => ReactFont[];
35
- interface ModelsProps<M extends {
13
+ export interface ModelsProps<M extends {
36
14
  id: string;
37
15
  }> {
38
16
  className?: string;
@@ -43,7 +21,7 @@ interface ModelsProps<M extends {
43
21
  init?: FetchInitForm<any, M, any>;
44
22
  onClickItem?: (model: M) => any;
45
23
  }
46
- type ModelProps<T extends string, L extends {
24
+ export type ModelProps<T extends string, L extends {
47
25
  id: string;
48
26
  }> = {
49
27
  [key in T]: L;
@@ -55,7 +33,7 @@ type ModelProps<T extends string, L extends {
55
33
  columns?: DataColumn<L>[];
56
34
  href?: string;
57
35
  };
58
- interface ModelDashboardProps<Summary> {
36
+ export interface ModelDashboardProps<Summary> {
59
37
  className?: string;
60
38
  summary: Summary;
61
39
  queryMap?: {
@@ -65,26 +43,26 @@ interface ModelDashboardProps<Summary> {
65
43
  hidePresents?: boolean;
66
44
  sliceName?: string;
67
45
  }
68
- interface ModelInsightProps<Insight> {
46
+ export interface ModelInsightProps<Insight> {
69
47
  className?: string;
70
48
  insight: Insight;
71
49
  sliceName?: string;
72
50
  }
73
- interface ModelEditProps {
51
+ export interface ModelEditProps {
74
52
  sliceName?: string;
75
53
  }
76
- interface ModelViewProps {
54
+ export interface ModelViewProps {
77
55
  id?: string;
78
56
  sliceName?: string;
79
57
  }
80
- type DataAction<L> = "edit" | "view" | "remove" | {
58
+ export type DataAction<L> = "edit" | "view" | "remove" | {
81
59
  type: string;
82
60
  render: () => ReactNode;
83
61
  };
84
- interface DataTool {
62
+ export interface DataTool {
85
63
  render: () => ReactNode;
86
64
  }
87
- type DataColumn<L> = string | {
65
+ export type DataColumn<L> = string | {
88
66
  key: keyof L;
89
67
  title?: string;
90
68
  value?: (value: any, model: L) => string | number | boolean | undefined | null | object;
@@ -92,16 +70,16 @@ type DataColumn<L> = string | {
92
70
  render?: (value: any, model: L) => ReactNode;
93
71
  only?: "user" | "admin";
94
72
  };
95
- interface DataMenuItem {
73
+ export interface DataMenuItem {
96
74
  key: string;
97
75
  icon: ReactNode;
98
76
  label?: string;
99
77
  render: () => ReactNode;
100
78
  }
101
- interface DataMenu {
79
+ export interface DataMenu {
102
80
  [key: string]: DataMenuItem;
103
81
  }
104
- interface UserMenuItem {
82
+ export interface UserMenuItem {
105
83
  title: string | ReactNode;
106
84
  icon?: ReactNode;
107
85
  path: string;
@@ -109,7 +87,7 @@ interface UserMenuItem {
109
87
  children?: UserMenuItem[];
110
88
  onClick?: () => void;
111
89
  }
112
- interface MenuItem {
90
+ export interface MenuItem {
113
91
  icon?: ReactNode;
114
92
  title: string | ReactNode;
115
93
  href: string;
@@ -117,18 +95,16 @@ interface MenuItem {
117
95
  children?: MenuItem[];
118
96
  onClick?: () => void;
119
97
  }
120
- interface ReactFont {
98
+ export interface ReactFont {
121
99
  name: string;
122
100
  paths: {
123
101
  src: string;
124
102
  weight: number;
125
103
  }[];
126
104
  }
127
- interface RootLayoutProps {
105
+ export interface RootLayoutProps {
128
106
  children: ReactNode;
129
107
  params: Promise<{
130
108
  lang: "en" | "ko";
131
109
  }>;
132
110
  }
133
-
134
- export { type DataAction, type DataColumn, type DataMenu, type DataMenuItem, type DataTool, type MenuItem, type ModelDashboardProps, type ModelEditProps, type ModelInsightProps, type ModelProps, type ModelViewProps, type ModelsProps, type ReactFont, type RootLayoutProps, type UserMenuItem, clsx, loadFonts };
package/src/cookie.js DELETED
@@ -1,155 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var cookie_exports = {};
30
- __export(cookie_exports, {
31
- cookies: () => cookies,
32
- getAccount: () => getAccount,
33
- getCookie: () => getCookie,
34
- getHeader: () => getHeader,
35
- getMe: () => getMe,
36
- getSelf: () => getSelf,
37
- headers: () => headers,
38
- initAuth: () => initAuth,
39
- removeCookie: () => removeCookie,
40
- resetAuth: () => resetAuth,
41
- setAuth: () => setAuth,
42
- setCookie: () => setCookie
43
- });
44
- module.exports = __toCommonJS(cookie_exports);
45
- var import_base = require("@akanjs/base");
46
- var import_common = require("@akanjs/common");
47
- var import_signal = require("@akanjs/signal");
48
- var import_signal2 = require("@akanjs/signal");
49
- var import_core = require("@capacitor/core");
50
- var import_js_cookie = __toESM(require("js-cookie"));
51
- var import_jwt_decode = require("jwt-decode");
52
- var import_react = __toESM(require("react"));
53
- var import_router = require("./router");
54
- var import_storage = require("./storage");
55
- const cookies = import_base.baseClientEnv.side === "server" ? () => {
56
- const nextHeaders = require("next/headers");
57
- const cookies2 = nextHeaders.cookies();
58
- return import_react.default.use(cookies2);
59
- } : () => {
60
- const cookie = import_js_cookie.default.get();
61
- return new Map(Object.entries(cookie).map(([key, value]) => [
62
- key,
63
- {
64
- name: key,
65
- value: typeof value === "string" && value.startsWith("j:") ? JSON.parse(value.slice(2)) : value
66
- }
67
- ]));
68
- };
69
- const setCookie = /* @__PURE__ */ __name((key, value, options = {
70
- path: "/",
71
- sameSite: "none",
72
- secure: true
73
- }) => {
74
- if (import_base.baseClientEnv.side === "server") return;
75
- else void import_core.CapacitorCookies.setCookie({
76
- key,
77
- value
78
- });
79
- }, "setCookie");
80
- const getCookie = /* @__PURE__ */ __name((key) => {
81
- if (import_base.baseClientEnv.side === "server") return cookies().get(key)?.value;
82
- else return document.cookie.split(";").find((c) => c.trim().startsWith(`${key}=`))?.split("=")[1];
83
- }, "getCookie");
84
- const removeCookie = /* @__PURE__ */ __name((key, options = {
85
- path: "/"
86
- }) => {
87
- if (import_base.baseClientEnv.side === "server") return cookies().delete(key);
88
- else {
89
- document.cookie = `${key}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`;
90
- }
91
- }, "removeCookie");
92
- const headers = import_base.baseClientEnv.side === "server" ? () => import_react.default.use(require("next/headers").headers()) : () => /* @__PURE__ */ new Map();
93
- const getHeader = /* @__PURE__ */ __name((key) => {
94
- return headers().get(key);
95
- }, "getHeader");
96
- const getAccount = /* @__PURE__ */ __name(() => {
97
- const jwt = getCookie("jwt") ?? getHeader("jwt");
98
- if (!jwt) return import_signal2.defaultAccount;
99
- const account = (0, import_jwt_decode.jwtDecode)(jwt);
100
- if (account.appName !== import_base.baseEnv.appName || account.environment !== import_base.baseEnv.environment) return import_signal2.defaultAccount;
101
- return account;
102
- }, "getAccount");
103
- function getMe(option) {
104
- const me = getAccount().me;
105
- if (!me && option) {
106
- if (option.unauthorize === "notFound") import_router.router.notFound();
107
- else if (import_base.baseClientEnv.side === "client") import_router.router.replace(option.unauthorize);
108
- else import_react.default.use(import_router.router.redirect(option.unauthorize));
109
- }
110
- return me;
111
- }
112
- __name(getMe, "getMe");
113
- function getSelf(option) {
114
- const self = getAccount().self;
115
- if (!self && option) {
116
- if (option.unauthorize === "notFound") import_router.router.notFound();
117
- else if (import_base.baseClientEnv.side === "client") import_router.router.replace(option.unauthorize);
118
- else import_react.default.use(import_router.router.redirect(option.unauthorize));
119
- }
120
- return self;
121
- }
122
- __name(getSelf, "getSelf");
123
- const setAuth = /* @__PURE__ */ __name(({ jwt }) => {
124
- import_signal.client.setJwt(jwt);
125
- setCookie("jwt", jwt);
126
- void import_storage.storage.setItem("jwt", jwt);
127
- }, "setAuth");
128
- const initAuth = /* @__PURE__ */ __name(({ jwt } = {}) => {
129
- const token = jwt ?? cookies().get("jwt")?.value;
130
- if (token) setAuth({
131
- jwt: token
132
- });
133
- import_signal.client.init();
134
- import_common.Logger.verbose(`JWT set from cookie: ${token}`);
135
- }, "initAuth");
136
- const resetAuth = /* @__PURE__ */ __name(() => {
137
- import_signal.client.reset();
138
- removeCookie("jwt");
139
- void import_storage.storage.removeItem("jwt");
140
- }, "resetAuth");
141
- // Annotate the CommonJS export names for ESM import in node:
142
- 0 && (module.exports = {
143
- cookies,
144
- getAccount,
145
- getCookie,
146
- getHeader,
147
- getMe,
148
- getSelf,
149
- headers,
150
- initAuth,
151
- removeCookie,
152
- resetAuth,
153
- setAuth,
154
- setCookie
155
- });