celestya 0.0.2 → 0.0.4
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/README.md +5 -3
- package/package.json +1 -1
- package/dist/client/index.d.mts +0 -66
- package/dist/client/index.d.ts +0 -66
- package/dist/client/index.js +0 -238
- package/dist/client/index.js.map +0 -1
- package/dist/client/index.mjs +0 -210
- package/dist/client/index.mjs.map +0 -1
- package/dist/index.d.mts +0 -49
- package/dist/index.d.ts +0 -49
- package/dist/index.js +0 -270
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -240
- package/dist/index.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -31,6 +31,7 @@ const config: IConfig = {
|
|
|
31
31
|
|
|
32
32
|
export const POST = (req: any, opt: IRequestOptions) => Proxy("POST", req, opt, config);
|
|
33
33
|
export const GET = (req: any, opt: IRequestOptions) => Proxy("GET", req, opt, config);
|
|
34
|
+
export const DELETE = (req: any, opt: IRequestOptions) => Proxy("DELETE", req, opt, config);
|
|
34
35
|
```
|
|
35
36
|
|
|
36
37
|
Configure the provider
|
|
@@ -93,7 +94,7 @@ interface User {
|
|
|
93
94
|
}
|
|
94
95
|
|
|
95
96
|
const Navbar = async () => {
|
|
96
|
-
const user = await apiFetch("user", {}, config)
|
|
97
|
+
const user = await apiFetch("/user", {}, config)
|
|
97
98
|
|
|
98
99
|
return <div>Welcome: {session.user?.name}</div>;
|
|
99
100
|
};
|
|
@@ -137,10 +138,11 @@ export default Navbar;
|
|
|
137
138
|
|
|
138
139
|
## Todo
|
|
139
140
|
|
|
140
|
-
- [ ]: Upload request with worker as helper (?)
|
|
141
|
-
- [ ]: Refresh logic
|
|
142
141
|
- [x]: Change returns at error
|
|
143
142
|
- [x]: GET request with auth
|
|
144
143
|
- [x]: POST request with auth
|
|
145
144
|
- [x]: Fix issue with getSession serverside and config set at layout (If used at api/\_/route.tsx)
|
|
146
145
|
- [x]: Fix issue with api endpoints if no layout has been loaded (if accessing api directly)
|
|
146
|
+
- [ ]: Upload request with worker as helper (?)
|
|
147
|
+
- [ ]: Refresh logic
|
|
148
|
+
- [ ]: Fix Response types
|
package/package.json
CHANGED
package/dist/client/index.d.mts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
|
|
3
|
-
declare module "iron-session" {
|
|
4
|
-
interface IronSessionData<U, T> {
|
|
5
|
-
user?: U;
|
|
6
|
-
token?: {
|
|
7
|
-
jwt: string;
|
|
8
|
-
refresh: string;
|
|
9
|
-
decoded: T;
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
interface ILoginData {
|
|
15
|
-
data: object;
|
|
16
|
-
redirect?: string;
|
|
17
|
-
onErrorUrl?: string;
|
|
18
|
-
}
|
|
19
|
-
interface IRegisterData {
|
|
20
|
-
data: object;
|
|
21
|
-
redirect?: string;
|
|
22
|
-
onErrorUrl?: string;
|
|
23
|
-
}
|
|
24
|
-
interface IOAuthData {
|
|
25
|
-
state: string;
|
|
26
|
-
oAuthUrl: string;
|
|
27
|
-
onErrorUrl?: string;
|
|
28
|
-
}
|
|
29
|
-
interface IResponseError {
|
|
30
|
-
error: string;
|
|
31
|
-
message: string;
|
|
32
|
-
}
|
|
33
|
-
interface IResponseSuccess<T, U> {
|
|
34
|
-
error: null;
|
|
35
|
-
data: T;
|
|
36
|
-
details: U;
|
|
37
|
-
}
|
|
38
|
-
interface IAuthContext<U> {
|
|
39
|
-
isLoggedIn: boolean;
|
|
40
|
-
ready: boolean;
|
|
41
|
-
user: U;
|
|
42
|
-
login: (data: ILoginData) => Promise<string>;
|
|
43
|
-
register: (data: IRegisterData) => Promise<string>;
|
|
44
|
-
oAuth: (data: IOAuthData) => Promise<string>;
|
|
45
|
-
logout: () => Promise<string>;
|
|
46
|
-
refreshUser: (force?: boolean) => Promise<void>;
|
|
47
|
-
get: <T, U = any>(url: string) => Promise<ResponseType<T, U>>;
|
|
48
|
-
post: <T, U = any>(url: string, body: any) => Promise<ResponseType<T, U>>;
|
|
49
|
-
del: <T, U = any>(url: string) => Promise<ResponseType<T, U>>;
|
|
50
|
-
}
|
|
51
|
-
interface IAuthContextOptions {
|
|
52
|
-
children: React.ReactNode;
|
|
53
|
-
routePrefix?: string;
|
|
54
|
-
}
|
|
55
|
-
interface IChildProps {
|
|
56
|
-
children?: React.ReactNode;
|
|
57
|
-
}
|
|
58
|
-
type ResponseType<T, U = any> = IResponseError | IResponseSuccess<T, U>;
|
|
59
|
-
|
|
60
|
-
type LogoutProps = React.FC<React.ComponentProps<'div'> & IChildProps>;
|
|
61
|
-
|
|
62
|
-
declare const AuthProvider: <IU>({ children, routePrefix, }: IAuthContextOptions) => react_jsx_runtime.JSX.Element;
|
|
63
|
-
declare const Logout: LogoutProps;
|
|
64
|
-
declare const useAuth: () => IAuthContext<any>;
|
|
65
|
-
|
|
66
|
-
export { AuthProvider, Logout, useAuth };
|
package/dist/client/index.d.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
|
|
3
|
-
declare module "iron-session" {
|
|
4
|
-
interface IronSessionData<U, T> {
|
|
5
|
-
user?: U;
|
|
6
|
-
token?: {
|
|
7
|
-
jwt: string;
|
|
8
|
-
refresh: string;
|
|
9
|
-
decoded: T;
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
interface ILoginData {
|
|
15
|
-
data: object;
|
|
16
|
-
redirect?: string;
|
|
17
|
-
onErrorUrl?: string;
|
|
18
|
-
}
|
|
19
|
-
interface IRegisterData {
|
|
20
|
-
data: object;
|
|
21
|
-
redirect?: string;
|
|
22
|
-
onErrorUrl?: string;
|
|
23
|
-
}
|
|
24
|
-
interface IOAuthData {
|
|
25
|
-
state: string;
|
|
26
|
-
oAuthUrl: string;
|
|
27
|
-
onErrorUrl?: string;
|
|
28
|
-
}
|
|
29
|
-
interface IResponseError {
|
|
30
|
-
error: string;
|
|
31
|
-
message: string;
|
|
32
|
-
}
|
|
33
|
-
interface IResponseSuccess<T, U> {
|
|
34
|
-
error: null;
|
|
35
|
-
data: T;
|
|
36
|
-
details: U;
|
|
37
|
-
}
|
|
38
|
-
interface IAuthContext<U> {
|
|
39
|
-
isLoggedIn: boolean;
|
|
40
|
-
ready: boolean;
|
|
41
|
-
user: U;
|
|
42
|
-
login: (data: ILoginData) => Promise<string>;
|
|
43
|
-
register: (data: IRegisterData) => Promise<string>;
|
|
44
|
-
oAuth: (data: IOAuthData) => Promise<string>;
|
|
45
|
-
logout: () => Promise<string>;
|
|
46
|
-
refreshUser: (force?: boolean) => Promise<void>;
|
|
47
|
-
get: <T, U = any>(url: string) => Promise<ResponseType<T, U>>;
|
|
48
|
-
post: <T, U = any>(url: string, body: any) => Promise<ResponseType<T, U>>;
|
|
49
|
-
del: <T, U = any>(url: string) => Promise<ResponseType<T, U>>;
|
|
50
|
-
}
|
|
51
|
-
interface IAuthContextOptions {
|
|
52
|
-
children: React.ReactNode;
|
|
53
|
-
routePrefix?: string;
|
|
54
|
-
}
|
|
55
|
-
interface IChildProps {
|
|
56
|
-
children?: React.ReactNode;
|
|
57
|
-
}
|
|
58
|
-
type ResponseType<T, U = any> = IResponseError | IResponseSuccess<T, U>;
|
|
59
|
-
|
|
60
|
-
type LogoutProps = React.FC<React.ComponentProps<'div'> & IChildProps>;
|
|
61
|
-
|
|
62
|
-
declare const AuthProvider: <IU>({ children, routePrefix, }: IAuthContextOptions) => react_jsx_runtime.JSX.Element;
|
|
63
|
-
declare const Logout: LogoutProps;
|
|
64
|
-
declare const useAuth: () => IAuthContext<any>;
|
|
65
|
-
|
|
66
|
-
export { AuthProvider, Logout, useAuth };
|
package/dist/client/index.js
DELETED
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
"use strict";
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
|
|
21
|
-
// src/client/index.ts
|
|
22
|
-
var client_exports = {};
|
|
23
|
-
__export(client_exports, {
|
|
24
|
-
AuthProvider: () => AuthProvider,
|
|
25
|
-
Logout: () => Logout,
|
|
26
|
-
useAuth: () => useAuth
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(client_exports);
|
|
29
|
-
|
|
30
|
-
// src/client/contextProvider.tsx
|
|
31
|
-
var import_react = require("react");
|
|
32
|
-
|
|
33
|
-
// src/client/request.ts
|
|
34
|
-
async function gFetch({
|
|
35
|
-
url,
|
|
36
|
-
options
|
|
37
|
-
}) {
|
|
38
|
-
const response = await fetch(url, {
|
|
39
|
-
method: "GET",
|
|
40
|
-
...options
|
|
41
|
-
});
|
|
42
|
-
return await response.json();
|
|
43
|
-
}
|
|
44
|
-
async function pFetch({
|
|
45
|
-
url,
|
|
46
|
-
body
|
|
47
|
-
}) {
|
|
48
|
-
const response = await fetch(url, {
|
|
49
|
-
method: "POST",
|
|
50
|
-
headers: { "Content-Type": "application/json" },
|
|
51
|
-
body: JSON.stringify(body)
|
|
52
|
-
});
|
|
53
|
-
return await response.json();
|
|
54
|
-
}
|
|
55
|
-
async function dFetch({
|
|
56
|
-
url,
|
|
57
|
-
options
|
|
58
|
-
}) {
|
|
59
|
-
const response = await fetch(url, {
|
|
60
|
-
method: "DELETE",
|
|
61
|
-
...options
|
|
62
|
-
});
|
|
63
|
-
return await response.json();
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// src/client/contextProvider.tsx
|
|
67
|
-
var import_navigation = require("next/navigation");
|
|
68
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
69
|
-
var AuthContext = (0, import_react.createContext)(null);
|
|
70
|
-
var AuthContextProvider = ({
|
|
71
|
-
children,
|
|
72
|
-
routePrefix = "/api"
|
|
73
|
-
}) => {
|
|
74
|
-
const [isLoggedIn, setIsLoggedIn] = (0, import_react.useState)(false);
|
|
75
|
-
const [ready, setReady] = (0, import_react.useState)(false);
|
|
76
|
-
const [user, setUser] = (0, import_react.useState)({});
|
|
77
|
-
const router = (0, import_navigation.useRouter)();
|
|
78
|
-
const loginRoute = routePrefix + "/login";
|
|
79
|
-
const registerRoute = routePrefix + "/register";
|
|
80
|
-
const logoutRoute = routePrefix + "/logout";
|
|
81
|
-
const userRoute = routePrefix + "/user";
|
|
82
|
-
const oAuthRoute = routePrefix + "/oauth";
|
|
83
|
-
const proxyRoute = routePrefix + "/proxy";
|
|
84
|
-
const login = async (loginData) => {
|
|
85
|
-
try {
|
|
86
|
-
const res = await pFetch({
|
|
87
|
-
url: loginRoute,
|
|
88
|
-
body: loginData.data
|
|
89
|
-
});
|
|
90
|
-
setIsLoggedIn(true);
|
|
91
|
-
if (res.error)
|
|
92
|
-
throw new Error(res.message);
|
|
93
|
-
return loginData.redirect || "/";
|
|
94
|
-
} catch (e) {
|
|
95
|
-
return `${loginData.onErrorUrl || "/"}?error=${e.message}`;
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
const register = async (registerData) => {
|
|
99
|
-
try {
|
|
100
|
-
const res = await pFetch({
|
|
101
|
-
url: registerRoute,
|
|
102
|
-
body: registerData.data
|
|
103
|
-
});
|
|
104
|
-
if (res.error)
|
|
105
|
-
throw new Error(res.message);
|
|
106
|
-
return `${registerData.redirect || "/"}?success=true`;
|
|
107
|
-
} catch (e) {
|
|
108
|
-
return `${registerData.onErrorUrl || "/"}?error=${e.message}`;
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
const oAuth = async ({
|
|
112
|
-
state,
|
|
113
|
-
oAuthUrl,
|
|
114
|
-
onErrorUrl
|
|
115
|
-
}) => {
|
|
116
|
-
try {
|
|
117
|
-
const url = new URL(oAuthRoute, "http://localhost/");
|
|
118
|
-
url.searchParams.set("authUrl", oAuthUrl);
|
|
119
|
-
if (state && state !== "/")
|
|
120
|
-
url.searchParams.set("state", state);
|
|
121
|
-
const response = await gFetch({ url: url.pathname + url.search });
|
|
122
|
-
return response.data;
|
|
123
|
-
} catch (e) {
|
|
124
|
-
return `${onErrorUrl || "/"}?error=${e.message}`;
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
const logout = async () => {
|
|
128
|
-
try {
|
|
129
|
-
const data = await gFetch({
|
|
130
|
-
url: logoutRoute,
|
|
131
|
-
options: { cache: "no-store" }
|
|
132
|
-
});
|
|
133
|
-
setIsLoggedIn(false);
|
|
134
|
-
setUser({});
|
|
135
|
-
return data.data;
|
|
136
|
-
} catch (e) {
|
|
137
|
-
console.log(e);
|
|
138
|
-
return "/";
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
const refreshUser = async (force) => {
|
|
142
|
-
try {
|
|
143
|
-
const data = await gFetch({
|
|
144
|
-
url: `${userRoute}${force ? "?force=true" : ""}`,
|
|
145
|
-
options: { cache: "no-store" }
|
|
146
|
-
});
|
|
147
|
-
if (!data.error) {
|
|
148
|
-
setUser(data.data);
|
|
149
|
-
setIsLoggedIn(true);
|
|
150
|
-
} else {
|
|
151
|
-
setUser({});
|
|
152
|
-
setIsLoggedIn(false);
|
|
153
|
-
}
|
|
154
|
-
setReady(true);
|
|
155
|
-
router.refresh();
|
|
156
|
-
} catch (e) {
|
|
157
|
-
console.log("refreshUser error: ", e);
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
const get = async (url) => {
|
|
161
|
-
try {
|
|
162
|
-
const r = await gFetch({ url: `${proxyRoute}${url}` });
|
|
163
|
-
return r;
|
|
164
|
-
} catch (e) {
|
|
165
|
-
return { error: "getRequestError", message: e.message };
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
const post = async (url, body) => {
|
|
169
|
-
try {
|
|
170
|
-
const r = await pFetch({
|
|
171
|
-
url: `${proxyRoute}${url}`,
|
|
172
|
-
body
|
|
173
|
-
});
|
|
174
|
-
return r;
|
|
175
|
-
} catch (e) {
|
|
176
|
-
return { error: "getRequestError", message: e.message };
|
|
177
|
-
}
|
|
178
|
-
};
|
|
179
|
-
const del = async (url) => {
|
|
180
|
-
try {
|
|
181
|
-
const r = await dFetch({ url: `${proxyRoute}${url}` });
|
|
182
|
-
return r;
|
|
183
|
-
} catch (e) {
|
|
184
|
-
return { error: "getRequestError", message: e.message };
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
(0, import_react.useEffect)(() => {
|
|
188
|
-
if (!ready)
|
|
189
|
-
refreshUser();
|
|
190
|
-
}, []);
|
|
191
|
-
const provider = {
|
|
192
|
-
ready,
|
|
193
|
-
login,
|
|
194
|
-
register,
|
|
195
|
-
logout,
|
|
196
|
-
isLoggedIn,
|
|
197
|
-
refreshUser,
|
|
198
|
-
user,
|
|
199
|
-
oAuth,
|
|
200
|
-
get,
|
|
201
|
-
post,
|
|
202
|
-
del
|
|
203
|
-
/* upload, */
|
|
204
|
-
};
|
|
205
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AuthContext.Provider, { value: provider, children });
|
|
206
|
-
};
|
|
207
|
-
var contextProvider_default = AuthContextProvider;
|
|
208
|
-
|
|
209
|
-
// src/client/useAuth.ts
|
|
210
|
-
var import_react2 = require("react");
|
|
211
|
-
var useAuthContext = () => {
|
|
212
|
-
return (0, import_react2.useContext)(AuthContext);
|
|
213
|
-
};
|
|
214
|
-
var useAuth_default = useAuthContext;
|
|
215
|
-
|
|
216
|
-
// src/client/Logout.tsx
|
|
217
|
-
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
218
|
-
var LogoutComponent = ({ children, ...props }) => {
|
|
219
|
-
const { logout } = useAuth_default();
|
|
220
|
-
const handleLogout = async (e) => {
|
|
221
|
-
e.preventDefault();
|
|
222
|
-
await logout();
|
|
223
|
-
};
|
|
224
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { onClick: handleLogout, ...props, children });
|
|
225
|
-
};
|
|
226
|
-
var Logout_default = LogoutComponent;
|
|
227
|
-
|
|
228
|
-
// src/client/index.ts
|
|
229
|
-
var AuthProvider = contextProvider_default;
|
|
230
|
-
var Logout = Logout_default;
|
|
231
|
-
var useAuth = useAuth_default;
|
|
232
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
233
|
-
0 && (module.exports = {
|
|
234
|
-
AuthProvider,
|
|
235
|
-
Logout,
|
|
236
|
-
useAuth
|
|
237
|
-
});
|
|
238
|
-
//# sourceMappingURL=index.js.map
|
package/dist/client/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/client/index.ts","../../src/client/contextProvider.tsx","../../src/client/request.ts","../../src/client/useAuth.ts","../../src/client/Logout.tsx"],"sourcesContent":["import AuthContextProvider from \"./contextProvider\";\nimport LogoutComponent from \"./Logout\";\nimport useAuthContext from \"./useAuth\";\n\nexport const AuthProvider = AuthContextProvider;\nexport const Logout = LogoutComponent;\nexport const useAuth = useAuthContext;\n","\"use client\";\n\nimport { createContext, useEffect, useState } from \"react\";\nimport {\n IAuthContext,\n IAuthContextOptions,\n ILoginData,\n IOAuthData,\n IRegisterData,\n ResponseType,\n} from \"../types/internal\";\n\nimport { dFetch, gFetch, pFetch } from \"./request\";\n\nimport { useRouter } from \"next/navigation\";\n/* +\n Frontend context for providing login, logout, register and refresh\n 'use client' needed for using -> client components only\n server components need to use useSession()\n*/\n\nexport const AuthContext = createContext<IAuthContext<any>>(null as any);\n\nconst AuthContextProvider = <IU,>({\n children,\n routePrefix = \"/api\",\n}: IAuthContextOptions) => {\n const [isLoggedIn, setIsLoggedIn] = useState(false);\n const [ready, setReady] = useState(false);\n const [user, setUser] = useState<IU | {}>({});\n\n const router = useRouter();\n\n // POST /session/login\n const loginRoute = routePrefix + \"/login\";\n\n // POST /session/refresh\n const registerRoute = routePrefix + \"/register\";\n\n // GET /session/logout\n const logoutRoute = routePrefix + \"/logout\";\n\n // GET /session\n const userRoute = routePrefix + \"/user\";\n\n // GET /session/oauth/API_OAUTH_URL\n const oAuthRoute = routePrefix + \"/oauth\";\n\n // GET/POST/DELETE /proxy/URL\n const proxyRoute = routePrefix + \"/proxy\";\n\n const login = async (loginData: ILoginData): Promise<string> => {\n try {\n const res = await pFetch({\n url: loginRoute,\n body: loginData.data,\n });\n\n setIsLoggedIn(true);\n\n if (res.error) throw new Error(res.message);\n\n return loginData.redirect || \"/\";\n } catch (e: any) {\n return `${loginData.onErrorUrl || \"/\"}?error=${e.message}`;\n }\n };\n\n const register = async (registerData: IRegisterData): Promise<string> => {\n try {\n const res = await pFetch({\n url: registerRoute,\n body: registerData.data,\n });\n\n if (res.error) throw new Error(res.message);\n\n return `${registerData.redirect || \"/\"}?success=true`;\n } catch (e: any) {\n return `${registerData.onErrorUrl || \"/\"}?error=${e.message}`;\n }\n };\n\n const oAuth = async ({\n state,\n oAuthUrl,\n onErrorUrl,\n }: IOAuthData): Promise<string> => {\n try {\n const url = new URL(oAuthRoute, \"http://localhost/\");\n\n url.searchParams.set(\"authUrl\", oAuthUrl);\n\n if (state && state !== \"/\") url.searchParams.set(\"state\", state);\n\n const response = await gFetch({ url: url.pathname + url.search });\n\n return response.data;\n } catch (e: any) {\n return `${onErrorUrl || \"/\"}?error=${e.message}`;\n }\n };\n\n const logout = async (): Promise<string> => {\n try {\n const data = await gFetch({\n url: logoutRoute,\n options: { cache: \"no-store\" },\n });\n\n setIsLoggedIn(false);\n setUser({});\n\n return data.data;\n } catch (e: any) {\n console.log(e);\n return \"/\";\n }\n };\n\n const refreshUser = async (force?: boolean): Promise<void> => {\n try {\n const data = await gFetch({\n url: `${userRoute}${force ? \"?force=true\" : \"\"}`,\n options: { cache: \"no-store\" },\n });\n\n if (!data.error) {\n setUser(data.data);\n setIsLoggedIn(true);\n } else {\n setUser({});\n setIsLoggedIn(false);\n }\n\n setReady(true);\n\n router.refresh();\n } catch (e) {\n console.log(\"refreshUser error: \", e);\n }\n };\n\n const get = async <T, U>(url: string): Promise<ResponseType<T, U>> => {\n try {\n const r = await gFetch({ url: `${proxyRoute}${url}` });\n\n return r;\n } catch (e: any) {\n return { error: \"getRequestError\", message: e.message };\n }\n };\n\n const post = async <T, U = any>(\n url: string,\n body: any\n ): Promise<ResponseType<T, U>> => {\n try {\n const r = await pFetch({\n url: `${proxyRoute}${url}`,\n body,\n });\n\n return r;\n } catch (e: any) {\n return { error: \"getRequestError\", message: e.message };\n }\n };\n\n const del = async <T, U>(url: string): Promise<ResponseType<T, U>> => {\n try {\n const r = await dFetch({ url: `${proxyRoute}${url}` });\n\n return r;\n } catch (e: any) {\n return { error: \"getRequestError\", message: e.message };\n }\n };\n\n /**\n * Can only be used if user is logged in! and already initialised\n * @param url url for upload\n * @param formData form data\n * @param setProgress progress dispatch\n * @returns object with data or error\n */\n /* const upload = async <T, U = any>(\n url: string,\n formName: string,\n files: File[],\n setProgress: (p: number) => void,\n ): Promise<TRequest<T, U>> => {\n try {\n if (!user.token) throw new Error('user not logged in')\n \n const res: Error | XMLHttpRequest = await new Promise(\n (resolve, reject) => {\n try {\n const xhr = new XMLHttpRequest()\n const formData = new FormData()\n \n for (let i = 0; i < files.length; i++)\n formData.append(formName, files[i])\n \n xhr.open('POST', `${API_URL}${url}`, true)\n xhr.setRequestHeader('Authorization', `Bearer ${user.token}`)\n xhr.upload.onprogress = (ev: ProgressEvent<EventTarget>) => {\n if (ev.lengthComputable) {\n const percentComplete = (ev.loaded / ev.total) * 100\n setProgress(percentComplete)\n }\n }\n \n xhr.onload = function () {\n console.log('break3?', this)\n return this.status === 200\n ? resolve(this)\n : reject(new Error('Error while uploading: ' + this.status))\n }\n \n xhr.onerror = (ev: ProgressEvent<EventTarget>) => {\n console.log('break2', ev.target)\n reject(ev)\n }\n \n xhr.send(formData)\n } catch (e) {\n console.log('break1', e)\n reject(e)\n }\n },\n )\n \n if (res instanceof Error) throw res\n \n const data: any = JSON.parse(res.responseText)\n \n if (data.error) throw new Error(data.data)\n \n return { data: data.data }\n } catch (e) {\n console.log('break4', e)\n return { error: e.message || 'upload error' }\n }\n }\n \n const getContext = () => {\n let context = user.id\n \n if (!user.id) {\n // if not logged in\n const cookie = document.cookie\n .split(';')\n .find((c) => c.includes('cycle_cid'))\n \n if (cookie) {\n // use cookie value\n context = cookie.split('=')[1]\n } else {\n // set new cookie\n context =\n Math.random().toString(36).substring(2, 15) +\n Math.random().toString(36).substring(2, 15)\n \n document.cookie = `cycle_cid=${context};path=/;max-age=31536000`\n }\n }\n \n return context\n }\n \n const event = async (name: string, value?: any): Promise<boolean> => {\n try {\n const contextId = getContext()\n \n const r = await fetch(NOFY_API_URL + '/event', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: 'Basic ' + ANALYTICS_KEY,\n },\n body: JSON.stringify({\n source: IS_PROD ? 'cycle-frontend' : 'cycle-frontend-dev',\n contextId,\n name,\n value,\n }),\n })\n \n const res = await r.json()\n if (res.error) throw new Error(res.error)\n \n return true\n } catch (e) {\n console.log('#> event error: ', e)\n return false\n }\n }\n \n const pageView = async (url: string, referer?: string): Promise<boolean> => {\n try {\n const contextId = getContext()\n \n const r = await fetch(NOFY_API_URL + '/log/count', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: 'Basic ' + ANALYTICS_KEY,\n },\n body: JSON.stringify({\n meta: {\n contextId,\n type: 'pageview',\n },\n referer,\n identifier: url,\n }),\n })\n \n const res = await r.json()\n if (res.error) throw new Error(res.error)\n \n return true\n } catch (e) {\n console.log('#> event error: ', e)\n return false\n }\n } */\n\n useEffect(() => {\n if (!ready) refreshUser();\n }, []);\n\n const provider = {\n ready,\n login,\n register,\n logout,\n isLoggedIn,\n refreshUser,\n user,\n oAuth,\n get,\n post,\n del,\n /* upload, */\n };\n\n return (\n <AuthContext.Provider value={provider}>{children}</AuthContext.Provider>\n );\n};\n\nexport default AuthContextProvider;\n","export async function gFetch({\n url,\n options,\n}: {\n url: string | URL;\n options?: object;\n}) {\n const response: Response = await fetch(url, {\n method: \"GET\",\n ...options,\n });\n\n return await response.json();\n}\n\nexport async function pFetch({\n url,\n body,\n}: {\n url: string | URL;\n body: object;\n}) {\n const response: Response = await fetch(url, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify(body),\n });\n\n return await response.json();\n}\n\nexport async function dFetch({\n url,\n options,\n}: {\n url: string | URL;\n options?: object;\n}) {\n const response: Response = await fetch(url, {\n method: \"DELETE\",\n ...options,\n });\n\n return await response.json();\n}\n","import { useContext } from \"react\";\nimport { AuthContext } from \"./contextProvider\";\n\nconst useAuthContext = () => {\n return useContext(AuthContext);\n};\n\nexport default useAuthContext;\n","'use client'\n\nimport { IChildProps } from \"../types/internal\";\nimport useAuthContext from \"./useAuth\";\n\nexport type LogoutProps = React.FC<React.ComponentProps<'div'> & IChildProps>\n\nconst LogoutComponent: LogoutProps = ({ children, ...props }) => {\n const { logout } = useAuthContext()\n\n const handleLogout = async (e: any) => {\n e.preventDefault()\n await logout()\n }\n\n return (\n <div onClick={handleLogout} {...props}>\n {children}\n </div>\n )\n}\n\nexport default LogoutComponent"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;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GAAG,CAAC,CAAC;AAEL,QAAM,WAAW;AAAA,IACb;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA;AAAA,EAEJ;AAEA,SACI,4CAAC,YAAY,UAAZ,EAAqB,OAAO,UAAW,UAAS;AAEzD;AAEA,IAAO,0BAAQ;;;AEjWf,IAAAA,gBAA2B;AAG3B,IAAM,iBAAiB,MAAM;AACzB,aAAO,0BAAW,WAAW;AACjC;AAEA,IAAO,kBAAQ;;;ACSP,IAAAC,sBAAA;AATR,IAAM,kBAA+B,CAAC,EAAE,UAAU,GAAG,MAAM,MAAM;AAC7D,QAAM,EAAE,OAAO,IAAI,gBAAe;AAElC,QAAM,eAAe,OAAO,MAAW;AACnC,MAAE,eAAe;AACjB,UAAM,OAAO;AAAA,EACjB;AAEA,SACI,6CAAC,SAAI,SAAS,cAAe,GAAG,OAC3B,UACL;AAER;AAEA,IAAO,iBAAQ;;;AJlBR,IAAM,eAAe;AACrB,IAAM,SAAS;AACf,IAAM,UAAU;","names":["import_react","import_jsx_runtime"]}
|
package/dist/client/index.mjs
DELETED
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
// src/client/contextProvider.tsx
|
|
4
|
-
import { createContext, useEffect, useState } from "react";
|
|
5
|
-
|
|
6
|
-
// src/client/request.ts
|
|
7
|
-
async function gFetch({
|
|
8
|
-
url,
|
|
9
|
-
options
|
|
10
|
-
}) {
|
|
11
|
-
const response = await fetch(url, {
|
|
12
|
-
method: "GET",
|
|
13
|
-
...options
|
|
14
|
-
});
|
|
15
|
-
return await response.json();
|
|
16
|
-
}
|
|
17
|
-
async function pFetch({
|
|
18
|
-
url,
|
|
19
|
-
body
|
|
20
|
-
}) {
|
|
21
|
-
const response = await fetch(url, {
|
|
22
|
-
method: "POST",
|
|
23
|
-
headers: { "Content-Type": "application/json" },
|
|
24
|
-
body: JSON.stringify(body)
|
|
25
|
-
});
|
|
26
|
-
return await response.json();
|
|
27
|
-
}
|
|
28
|
-
async function dFetch({
|
|
29
|
-
url,
|
|
30
|
-
options
|
|
31
|
-
}) {
|
|
32
|
-
const response = await fetch(url, {
|
|
33
|
-
method: "DELETE",
|
|
34
|
-
...options
|
|
35
|
-
});
|
|
36
|
-
return await response.json();
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// src/client/contextProvider.tsx
|
|
40
|
-
import { useRouter } from "next/navigation";
|
|
41
|
-
import { jsx } from "react/jsx-runtime";
|
|
42
|
-
var AuthContext = createContext(null);
|
|
43
|
-
var AuthContextProvider = ({
|
|
44
|
-
children,
|
|
45
|
-
routePrefix = "/api"
|
|
46
|
-
}) => {
|
|
47
|
-
const [isLoggedIn, setIsLoggedIn] = useState(false);
|
|
48
|
-
const [ready, setReady] = useState(false);
|
|
49
|
-
const [user, setUser] = useState({});
|
|
50
|
-
const router = useRouter();
|
|
51
|
-
const loginRoute = routePrefix + "/login";
|
|
52
|
-
const registerRoute = routePrefix + "/register";
|
|
53
|
-
const logoutRoute = routePrefix + "/logout";
|
|
54
|
-
const userRoute = routePrefix + "/user";
|
|
55
|
-
const oAuthRoute = routePrefix + "/oauth";
|
|
56
|
-
const proxyRoute = routePrefix + "/proxy";
|
|
57
|
-
const login = async (loginData) => {
|
|
58
|
-
try {
|
|
59
|
-
const res = await pFetch({
|
|
60
|
-
url: loginRoute,
|
|
61
|
-
body: loginData.data
|
|
62
|
-
});
|
|
63
|
-
setIsLoggedIn(true);
|
|
64
|
-
if (res.error)
|
|
65
|
-
throw new Error(res.message);
|
|
66
|
-
return loginData.redirect || "/";
|
|
67
|
-
} catch (e) {
|
|
68
|
-
return `${loginData.onErrorUrl || "/"}?error=${e.message}`;
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
const register = async (registerData) => {
|
|
72
|
-
try {
|
|
73
|
-
const res = await pFetch({
|
|
74
|
-
url: registerRoute,
|
|
75
|
-
body: registerData.data
|
|
76
|
-
});
|
|
77
|
-
if (res.error)
|
|
78
|
-
throw new Error(res.message);
|
|
79
|
-
return `${registerData.redirect || "/"}?success=true`;
|
|
80
|
-
} catch (e) {
|
|
81
|
-
return `${registerData.onErrorUrl || "/"}?error=${e.message}`;
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
const oAuth = async ({
|
|
85
|
-
state,
|
|
86
|
-
oAuthUrl,
|
|
87
|
-
onErrorUrl
|
|
88
|
-
}) => {
|
|
89
|
-
try {
|
|
90
|
-
const url = new URL(oAuthRoute, "http://localhost/");
|
|
91
|
-
url.searchParams.set("authUrl", oAuthUrl);
|
|
92
|
-
if (state && state !== "/")
|
|
93
|
-
url.searchParams.set("state", state);
|
|
94
|
-
const response = await gFetch({ url: url.pathname + url.search });
|
|
95
|
-
return response.data;
|
|
96
|
-
} catch (e) {
|
|
97
|
-
return `${onErrorUrl || "/"}?error=${e.message}`;
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
const logout = async () => {
|
|
101
|
-
try {
|
|
102
|
-
const data = await gFetch({
|
|
103
|
-
url: logoutRoute,
|
|
104
|
-
options: { cache: "no-store" }
|
|
105
|
-
});
|
|
106
|
-
setIsLoggedIn(false);
|
|
107
|
-
setUser({});
|
|
108
|
-
return data.data;
|
|
109
|
-
} catch (e) {
|
|
110
|
-
console.log(e);
|
|
111
|
-
return "/";
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
const refreshUser = async (force) => {
|
|
115
|
-
try {
|
|
116
|
-
const data = await gFetch({
|
|
117
|
-
url: `${userRoute}${force ? "?force=true" : ""}`,
|
|
118
|
-
options: { cache: "no-store" }
|
|
119
|
-
});
|
|
120
|
-
if (!data.error) {
|
|
121
|
-
setUser(data.data);
|
|
122
|
-
setIsLoggedIn(true);
|
|
123
|
-
} else {
|
|
124
|
-
setUser({});
|
|
125
|
-
setIsLoggedIn(false);
|
|
126
|
-
}
|
|
127
|
-
setReady(true);
|
|
128
|
-
router.refresh();
|
|
129
|
-
} catch (e) {
|
|
130
|
-
console.log("refreshUser error: ", e);
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
const get = async (url) => {
|
|
134
|
-
try {
|
|
135
|
-
const r = await gFetch({ url: `${proxyRoute}${url}` });
|
|
136
|
-
return r;
|
|
137
|
-
} catch (e) {
|
|
138
|
-
return { error: "getRequestError", message: e.message };
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
const post = async (url, body) => {
|
|
142
|
-
try {
|
|
143
|
-
const r = await pFetch({
|
|
144
|
-
url: `${proxyRoute}${url}`,
|
|
145
|
-
body
|
|
146
|
-
});
|
|
147
|
-
return r;
|
|
148
|
-
} catch (e) {
|
|
149
|
-
return { error: "getRequestError", message: e.message };
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
const del = async (url) => {
|
|
153
|
-
try {
|
|
154
|
-
const r = await dFetch({ url: `${proxyRoute}${url}` });
|
|
155
|
-
return r;
|
|
156
|
-
} catch (e) {
|
|
157
|
-
return { error: "getRequestError", message: e.message };
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
useEffect(() => {
|
|
161
|
-
if (!ready)
|
|
162
|
-
refreshUser();
|
|
163
|
-
}, []);
|
|
164
|
-
const provider = {
|
|
165
|
-
ready,
|
|
166
|
-
login,
|
|
167
|
-
register,
|
|
168
|
-
logout,
|
|
169
|
-
isLoggedIn,
|
|
170
|
-
refreshUser,
|
|
171
|
-
user,
|
|
172
|
-
oAuth,
|
|
173
|
-
get,
|
|
174
|
-
post,
|
|
175
|
-
del
|
|
176
|
-
/* upload, */
|
|
177
|
-
};
|
|
178
|
-
return /* @__PURE__ */ jsx(AuthContext.Provider, { value: provider, children });
|
|
179
|
-
};
|
|
180
|
-
var contextProvider_default = AuthContextProvider;
|
|
181
|
-
|
|
182
|
-
// src/client/useAuth.ts
|
|
183
|
-
import { useContext } from "react";
|
|
184
|
-
var useAuthContext = () => {
|
|
185
|
-
return useContext(AuthContext);
|
|
186
|
-
};
|
|
187
|
-
var useAuth_default = useAuthContext;
|
|
188
|
-
|
|
189
|
-
// src/client/Logout.tsx
|
|
190
|
-
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
191
|
-
var LogoutComponent = ({ children, ...props }) => {
|
|
192
|
-
const { logout } = useAuth_default();
|
|
193
|
-
const handleLogout = async (e) => {
|
|
194
|
-
e.preventDefault();
|
|
195
|
-
await logout();
|
|
196
|
-
};
|
|
197
|
-
return /* @__PURE__ */ jsx2("div", { onClick: handleLogout, ...props, children });
|
|
198
|
-
};
|
|
199
|
-
var Logout_default = LogoutComponent;
|
|
200
|
-
|
|
201
|
-
// src/client/index.ts
|
|
202
|
-
var AuthProvider = contextProvider_default;
|
|
203
|
-
var Logout = Logout_default;
|
|
204
|
-
var useAuth = useAuth_default;
|
|
205
|
-
export {
|
|
206
|
-
AuthProvider,
|
|
207
|
-
Logout,
|
|
208
|
-
useAuth
|
|
209
|
-
};
|
|
210
|
-
//# sourceMappingURL=index.mjs.map
|