dn-react-router-toolkit 0.2.6 → 0.3.1
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/dist/api/create_handler.d.mts +13 -0
- package/dist/api/create_handler.d.ts +13 -0
- package/dist/api/create_handler.js +276 -0
- package/dist/api/create_handler.mjs +282 -0
- package/dist/api/index.d.mts +4 -0
- package/dist/api/index.d.ts +4 -0
- package/dist/api/index.js +276 -0
- package/dist/api/index.mjs +282 -0
- package/dist/auth/client/index.d.mts +3 -0
- package/dist/auth/client/index.d.ts +3 -0
- package/dist/{date.js → auth/client/index.js} +25 -32
- package/dist/auth/client/index.mjs +21 -0
- package/dist/auth/client/redirect_page.d.mts +1 -0
- package/dist/auth/client/redirect_page.d.ts +1 -0
- package/dist/auth/index.d.mts +4 -0
- package/dist/auth/index.d.ts +4 -0
- package/dist/auth/index.js +116 -0
- package/dist/auth/index.mjs +89 -0
- package/dist/auth/server/index.d.mts +1 -0
- package/dist/auth/server/index.d.ts +1 -0
- package/dist/{slug.js → auth/server/index.js} +6 -14
- package/dist/auth/server/index.mjs +2 -0
- package/dist/auth/with_auth.d.mts +2 -6
- package/dist/auth/with_auth.d.ts +2 -6
- package/dist/auth/with_auth.js +3 -0
- package/dist/auth/with_auth.mjs +3 -0
- package/dist/{components → client}/client_env.d.mts +1 -1
- package/dist/{components → client}/client_env.d.ts +1 -1
- package/dist/{components → client}/client_env.js +6 -2
- package/dist/{components → client}/client_env.mjs +2 -2
- package/dist/client/index.d.mts +3 -0
- package/dist/client/index.d.ts +3 -0
- package/dist/{auth/client/google_login_button.js → client/index.js} +30 -33
- package/dist/client/index.mjs +31 -0
- package/dist/client/use_user_agent.d.mts +8 -0
- package/dist/client/use_user_agent.d.ts +8 -0
- package/dist/{file/client/format_size.js → client/use_user_agent.js} +14 -14
- package/dist/client/use_user_agent.mjs +13 -0
- package/dist/file/client/index.d.mts +1 -0
- package/dist/file/client/index.d.ts +1 -0
- package/dist/file/{cdn.js → client/index.js} +6 -16
- package/dist/file/client/index.mjs +2 -0
- package/dist/file/index.d.mts +1 -0
- package/dist/file/index.d.ts +1 -0
- package/dist/{cn.js → file/index.js} +6 -14
- package/dist/file/index.mjs +2 -0
- package/dist/file/server/index.d.mts +1 -0
- package/dist/file/server/index.d.ts +1 -0
- package/dist/file/server/index.js +24 -0
- package/dist/file/server/index.mjs +2 -0
- package/dist/http/index.d.mts +1 -1
- package/dist/http/index.d.ts +1 -1
- package/dist/http/index.js +3 -90
- package/dist/http/index.mjs +2 -68
- package/dist/index.d.mts +8 -6
- package/dist/index.d.ts +8 -6
- package/dist/index.js +3 -79
- package/dist/index.mjs +2 -58
- package/dist/modal/index.d.mts +1 -0
- package/dist/modal/index.d.ts +1 -0
- package/dist/{sleep.js → modal/index.js} +6 -14
- package/dist/modal/index.mjs +2 -0
- package/dist/seo/index.d.mts +4 -0
- package/dist/seo/index.d.ts +4 -0
- package/dist/seo/index.js +304 -0
- package/dist/seo/index.mjs +267 -0
- package/dist/seo/seo.js +9 -1
- package/dist/seo/seo.mjs +9 -1
- package/dist/text_editor/index.d.mts +1 -0
- package/dist/text_editor/index.d.ts +1 -0
- package/dist/text_editor/index.js +24 -0
- package/dist/text_editor/index.mjs +2 -0
- package/package.json +58 -32
- package/dist/auth/apple_auth.d.mts +0 -38
- package/dist/auth/apple_auth.d.ts +0 -38
- package/dist/auth/apple_auth.js +0 -88
- package/dist/auth/apple_auth.mjs +0 -63
- package/dist/auth/auth_repository.d.mts +0 -41
- package/dist/auth/auth_repository.d.ts +0 -41
- package/dist/auth/auth_repository.js +0 -18
- package/dist/auth/auth_repository.mjs +0 -0
- package/dist/auth/auth_service.d.mts +0 -63
- package/dist/auth/auth_service.d.ts +0 -63
- package/dist/auth/auth_service.js +0 -210
- package/dist/auth/auth_service.mjs +0 -171
- package/dist/auth/client/google_login_button.d.mts +0 -7
- package/dist/auth/client/google_login_button.d.ts +0 -7
- package/dist/auth/client/google_login_button.mjs +0 -37
- package/dist/auth/client/provider.d.mts +0 -24
- package/dist/auth/client/provider.d.ts +0 -24
- package/dist/auth/client/provider.js +0 -154
- package/dist/auth/client/provider.mjs +0 -118
- package/dist/auth/google_auth.d.mts +0 -33
- package/dist/auth/google_auth.d.ts +0 -33
- package/dist/auth/google_auth.js +0 -135
- package/dist/auth/google_auth.mjs +0 -108
- package/dist/auth/handlers/find_auth.d.mts +0 -13
- package/dist/auth/handlers/find_auth.d.ts +0 -13
- package/dist/auth/handlers/find_auth.js +0 -82
- package/dist/auth/handlers/find_auth.mjs +0 -55
- package/dist/auth/handlers/login.d.mts +0 -13
- package/dist/auth/handlers/login.d.ts +0 -13
- package/dist/auth/handlers/login.js +0 -107
- package/dist/auth/handlers/login.mjs +0 -80
- package/dist/auth/handlers/login_with_thirdparty.d.mts +0 -15
- package/dist/auth/handlers/login_with_thirdparty.d.ts +0 -15
- package/dist/auth/handlers/login_with_thirdparty.js +0 -98
- package/dist/auth/handlers/login_with_thirdparty.mjs +0 -71
- package/dist/auth/handlers/logout.d.mts +0 -13
- package/dist/auth/handlers/logout.d.ts +0 -13
- package/dist/auth/handlers/logout.js +0 -102
- package/dist/auth/handlers/logout.mjs +0 -75
- package/dist/auth/handlers/refresh.d.mts +0 -13
- package/dist/auth/handlers/refresh.d.ts +0 -13
- package/dist/auth/handlers/refresh.js +0 -92
- package/dist/auth/handlers/refresh.mjs +0 -65
- package/dist/auth/handlers/request_password_reset.d.mts +0 -10
- package/dist/auth/handlers/request_password_reset.d.ts +0 -10
- package/dist/auth/handlers/request_password_reset.js +0 -87
- package/dist/auth/handlers/request_password_reset.mjs +0 -60
- package/dist/auth/handlers/reset_password.d.mts +0 -10
- package/dist/auth/handlers/reset_password.d.ts +0 -10
- package/dist/auth/handlers/reset_password.js +0 -88
- package/dist/auth/handlers/reset_password.mjs +0 -61
- package/dist/auth/handlers/signup.d.mts +0 -15
- package/dist/auth/handlers/signup.d.ts +0 -15
- package/dist/auth/handlers/signup.js +0 -147
- package/dist/auth/handlers/signup.mjs +0 -112
- package/dist/auth/handlers/signup_with_thirdparty.d.mts +0 -17
- package/dist/auth/handlers/signup_with_thirdparty.d.ts +0 -17
- package/dist/auth/handlers/signup_with_thirdparty.js +0 -123
- package/dist/auth/handlers/signup_with_thirdparty.mjs +0 -98
- package/dist/auth/handlers/thirdparty_auth_callback.d.mts +0 -16
- package/dist/auth/handlers/thirdparty_auth_callback.d.ts +0 -16
- package/dist/auth/handlers/thirdparty_auth_callback.js +0 -129
- package/dist/auth/handlers/thirdparty_auth_callback.mjs +0 -102
- package/dist/auth/jwt_manager.d.mts +0 -38
- package/dist/auth/jwt_manager.d.ts +0 -38
- package/dist/auth/jwt_manager.js +0 -90
- package/dist/auth/jwt_manager.mjs +0 -65
- package/dist/auth/kakao_auth.d.mts +0 -27
- package/dist/auth/kakao_auth.d.ts +0 -27
- package/dist/auth/kakao_auth.js +0 -56
- package/dist/auth/kakao_auth.mjs +0 -31
- package/dist/auth/password_recovery.d.mts +0 -34
- package/dist/auth/password_recovery.d.ts +0 -34
- package/dist/auth/password_recovery.js +0 -169
- package/dist/auth/password_recovery.mjs +0 -134
- package/dist/auth/thirdparty_auth.d.mts +0 -41
- package/dist/auth/thirdparty_auth.d.ts +0 -41
- package/dist/auth/thirdparty_auth.js +0 -113
- package/dist/auth/thirdparty_auth.mjs +0 -86
- package/dist/cn.d.mts +0 -3
- package/dist/cn.d.ts +0 -3
- package/dist/cn.mjs +0 -7
- package/dist/components/index.d.mts +0 -5
- package/dist/components/index.d.ts +0 -5
- package/dist/components/index.js +0 -261
- package/dist/components/index.mjs +0 -219
- package/dist/components/modal/fullscreen_container.d.mts +0 -7
- package/dist/components/modal/fullscreen_container.d.ts +0 -7
- package/dist/components/modal/fullscreen_container.js +0 -102
- package/dist/components/modal/fullscreen_container.mjs +0 -68
- package/dist/components/modal/hooks.d.mts +0 -18
- package/dist/components/modal/hooks.d.ts +0 -18
- package/dist/components/modal/hooks.js +0 -236
- package/dist/components/modal/hooks.mjs +0 -204
- package/dist/components/modal/index.d.mts +0 -4
- package/dist/components/modal/index.d.ts +0 -4
- package/dist/components/modal/index.js +0 -238
- package/dist/components/modal/index.mjs +0 -203
- package/dist/components/modal/modal.d.mts +0 -13
- package/dist/components/modal/modal.d.ts +0 -13
- package/dist/components/modal/modal.js +0 -155
- package/dist/components/modal/modal.mjs +0 -130
- package/dist/components/styles.d.mts +0 -9
- package/dist/components/styles.d.ts +0 -9
- package/dist/components/styles.js +0 -48
- package/dist/components/styles.mjs +0 -17
- package/dist/date.d.mts +0 -5
- package/dist/date.d.ts +0 -5
- package/dist/date.mjs +0 -29
- package/dist/file/cdn.d.mts +0 -6
- package/dist/file/cdn.d.ts +0 -6
- package/dist/file/cdn.mjs +0 -9
- package/dist/file/client/drop_file_input.d.mts +0 -36
- package/dist/file/client/drop_file_input.d.ts +0 -36
- package/dist/file/client/drop_file_input.js +0 -323
- package/dist/file/client/drop_file_input.mjs +0 -294
- package/dist/file/client/file_upload_button.d.mts +0 -10
- package/dist/file/client/file_upload_button.d.ts +0 -10
- package/dist/file/client/file_upload_button.js +0 -89
- package/dist/file/client/file_upload_button.mjs +0 -58
- package/dist/file/client/file_uploader.d.mts +0 -13
- package/dist/file/client/file_uploader.d.ts +0 -13
- package/dist/file/client/file_uploader.js +0 -163
- package/dist/file/client/file_uploader.mjs +0 -136
- package/dist/file/client/format_size.d.mts +0 -3
- package/dist/file/client/format_size.d.ts +0 -3
- package/dist/file/client/format_size.mjs +0 -13
- package/dist/file/client/metadata.d.mts +0 -7
- package/dist/file/client/metadata.d.ts +0 -7
- package/dist/file/client/metadata.js +0 -85
- package/dist/file/client/metadata.mjs +0 -60
- package/dist/file/file_repository.d.mts +0 -16
- package/dist/file/file_repository.d.ts +0 -16
- package/dist/file/file_repository.js +0 -18
- package/dist/file/file_repository.mjs +0 -0
- package/dist/file/file_service.d.mts +0 -32
- package/dist/file/file_service.d.ts +0 -32
- package/dist/file/file_service.js +0 -66
- package/dist/file/file_service.mjs +0 -41
- package/dist/file/handlers/delete_file.d.mts +0 -17
- package/dist/file/handlers/delete_file.d.ts +0 -17
- package/dist/file/handlers/delete_file.js +0 -99
- package/dist/file/handlers/delete_file.mjs +0 -72
- package/dist/file/handlers/upload_file.d.mts +0 -16
- package/dist/file/handlers/upload_file.d.ts +0 -16
- package/dist/file/handlers/upload_file.js +0 -106
- package/dist/file/handlers/upload_file.mjs +0 -79
- package/dist/file/object_storage.d.mts +0 -19
- package/dist/file/object_storage.d.ts +0 -19
- package/dist/file/object_storage.js +0 -78
- package/dist/file/object_storage.mjs +0 -57
- package/dist/file/responsive_image.d.mts +0 -20
- package/dist/file/responsive_image.d.ts +0 -20
- package/dist/file/responsive_image.js +0 -132
- package/dist/file/responsive_image.mjs +0 -96
- package/dist/http/response.d.mts +0 -19
- package/dist/http/response.d.ts +0 -19
- package/dist/http/response.js +0 -109
- package/dist/http/response.mjs +0 -68
- package/dist/route/api.d.mts +0 -21
- package/dist/route/api.d.ts +0 -21
- package/dist/route/api.js +0 -584
- package/dist/route/api.mjs +0 -547
- package/dist/singleton.d.mts +0 -3
- package/dist/singleton.d.ts +0 -3
- package/dist/singleton.js +0 -37
- package/dist/singleton.mjs +0 -12
- package/dist/sleep.d.mts +0 -3
- package/dist/sleep.d.ts +0 -3
- package/dist/sleep.mjs +0 -7
- package/dist/slug.d.mts +0 -3
- package/dist/slug.d.ts +0 -3
- package/dist/slug.mjs +0 -7
- package/dist/text_editor/attach_media.d.mts +0 -16
- package/dist/text_editor/attach_media.d.ts +0 -16
- package/dist/text_editor/attach_media.js +0 -237
- package/dist/text_editor/attach_media.mjs +0 -210
- package/dist/text_editor/plugins/drag_and_drop.d.mts +0 -13
- package/dist/text_editor/plugins/drag_and_drop.d.ts +0 -13
- package/dist/text_editor/plugins/drag_and_drop.js +0 -59
- package/dist/text_editor/plugins/drag_and_drop.mjs +0 -34
- package/dist/text_editor/plugins/keymap.d.mts +0 -5
- package/dist/text_editor/plugins/keymap.d.ts +0 -5
- package/dist/text_editor/plugins/keymap.js +0 -40
- package/dist/text_editor/plugins/keymap.mjs +0 -15
- package/dist/text_editor/plugins/placehoder.d.mts +0 -5
- package/dist/text_editor/plugins/placehoder.d.ts +0 -5
- package/dist/text_editor/plugins/placehoder.js +0 -112
- package/dist/text_editor/plugins/placehoder.mjs +0 -87
- package/dist/text_editor/plugins/trailing_paragraph.d.mts +0 -5
- package/dist/text_editor/plugins/trailing_paragraph.d.ts +0 -5
- package/dist/text_editor/plugins/trailing_paragraph.js +0 -46
- package/dist/text_editor/plugins/trailing_paragraph.mjs +0 -21
- package/dist/text_editor/plugins/upload_placeholder.d.mts +0 -7
- package/dist/text_editor/plugins/upload_placeholder.d.ts +0 -7
- package/dist/text_editor/plugins/upload_placeholder.js +0 -94
- package/dist/text_editor/plugins/upload_placeholder.mjs +0 -68
- package/dist/text_editor/schema.d.mts +0 -9
- package/dist/text_editor/schema.d.ts +0 -9
- package/dist/text_editor/schema.js +0 -354
- package/dist/text_editor/schema.mjs +0 -319
- package/dist/text_editor/text_editor.d.mts +0 -44
- package/dist/text_editor/text_editor.d.ts +0 -44
- package/dist/text_editor/text_editor.js +0 -830
- package/dist/text_editor/text_editor.mjs +0 -802
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { LoaderFunctionArgs, ActionFunctionArgs } from 'react-router';
|
|
2
|
+
import { AuthService, PasswordRecoveryService, ThirdpartyAuth } from 'dn-react-toolkit/auth/server';
|
|
3
|
+
import { FileService } from 'dn-react-toolkit/file/server';
|
|
4
|
+
|
|
5
|
+
declare const createAPIHandler: <TFile>({ authService, fileService, passwordRecoveryService, getThirdPartyAuth, signupTokenSecret, }: {
|
|
6
|
+
authService: AuthService<TFile>;
|
|
7
|
+
fileService: FileService<TFile>;
|
|
8
|
+
passwordRecoveryService: PasswordRecoveryService;
|
|
9
|
+
getThirdPartyAuth: (provider: string) => ThirdpartyAuth;
|
|
10
|
+
signupTokenSecret: string;
|
|
11
|
+
}) => (args: LoaderFunctionArgs | ActionFunctionArgs) => Promise<Response | (({ request }: LoaderFunctionArgs<any> | ActionFunctionArgs<any>) => Promise<Response>)>;
|
|
12
|
+
|
|
13
|
+
export { createAPIHandler };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { LoaderFunctionArgs, ActionFunctionArgs } from 'react-router';
|
|
2
|
+
import { AuthService, PasswordRecoveryService, ThirdpartyAuth } from 'dn-react-toolkit/auth/server';
|
|
3
|
+
import { FileService } from 'dn-react-toolkit/file/server';
|
|
4
|
+
|
|
5
|
+
declare const createAPIHandler: <TFile>({ authService, fileService, passwordRecoveryService, getThirdPartyAuth, signupTokenSecret, }: {
|
|
6
|
+
authService: AuthService<TFile>;
|
|
7
|
+
fileService: FileService<TFile>;
|
|
8
|
+
passwordRecoveryService: PasswordRecoveryService;
|
|
9
|
+
getThirdPartyAuth: (provider: string) => ThirdpartyAuth;
|
|
10
|
+
signupTokenSecret: string;
|
|
11
|
+
}) => (args: LoaderFunctionArgs | ActionFunctionArgs) => Promise<Response | (({ request }: LoaderFunctionArgs<any> | ActionFunctionArgs<any>) => Promise<Response>)>;
|
|
12
|
+
|
|
13
|
+
export { createAPIHandler };
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
"use strict";
|
|
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/api/create_handler.ts
|
|
22
|
+
var create_handler_exports = {};
|
|
23
|
+
__export(create_handler_exports, {
|
|
24
|
+
createAPIHandler: () => createAPIHandler
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(create_handler_exports);
|
|
27
|
+
|
|
28
|
+
// src/http/index.ts
|
|
29
|
+
var http_exports = {};
|
|
30
|
+
__reExport(http_exports, require("dn-react-toolkit/http"));
|
|
31
|
+
|
|
32
|
+
// src/api/create_handler.ts
|
|
33
|
+
var import_server = require("dn-react-toolkit/auth/server");
|
|
34
|
+
|
|
35
|
+
// src/auth/index.ts
|
|
36
|
+
var auth_exports = {};
|
|
37
|
+
__export(auth_exports, {
|
|
38
|
+
createWithAuthHandler: () => createWithAuthHandler
|
|
39
|
+
});
|
|
40
|
+
__reExport(auth_exports, require("dn-react-toolkit/auth"));
|
|
41
|
+
|
|
42
|
+
// src/auth/with_auth.ts
|
|
43
|
+
function createWithAuthHandler({ authService }) {
|
|
44
|
+
return function(fn) {
|
|
45
|
+
const handler = async function(arg) {
|
|
46
|
+
const respond = async (auth) => {
|
|
47
|
+
const userAgent = arg.request.headers.get("User-Agent") || "";
|
|
48
|
+
const res = await fn(auth)(arg);
|
|
49
|
+
if (typeof res === "object" && res !== null && !Array.isArray(res)) {
|
|
50
|
+
if (res instanceof Response) {
|
|
51
|
+
if (res.status < 300 && res.headers.get("Content-Type")?.includes("application/json")) {
|
|
52
|
+
const data = await res.json();
|
|
53
|
+
return new Response(
|
|
54
|
+
JSON.stringify({
|
|
55
|
+
AUTH: auth,
|
|
56
|
+
userAgent,
|
|
57
|
+
...data
|
|
58
|
+
}),
|
|
59
|
+
{
|
|
60
|
+
status: res.status,
|
|
61
|
+
headers: res.headers
|
|
62
|
+
}
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
return res;
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
AUTH: auth,
|
|
69
|
+
userAgent,
|
|
70
|
+
...res
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
return res;
|
|
74
|
+
};
|
|
75
|
+
const accessToken = await authService.getAccessTokenFromRequest(
|
|
76
|
+
arg.request
|
|
77
|
+
);
|
|
78
|
+
if (accessToken) {
|
|
79
|
+
const payload = await authService.jwtManager.verifyAccessToken(
|
|
80
|
+
accessToken
|
|
81
|
+
);
|
|
82
|
+
if (payload) {
|
|
83
|
+
return respond(payload);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const refreshToken = await authService.getRefreshTokenFromCookies(
|
|
87
|
+
arg.request
|
|
88
|
+
);
|
|
89
|
+
if (refreshToken) {
|
|
90
|
+
try {
|
|
91
|
+
const newAccessToken = await authService.refreshAccessToken(
|
|
92
|
+
refreshToken
|
|
93
|
+
);
|
|
94
|
+
const setCookieHeader = await authService.getAccessTokenSetCookie(
|
|
95
|
+
newAccessToken
|
|
96
|
+
);
|
|
97
|
+
const headers = new Headers();
|
|
98
|
+
headers.append("Set-Cookie", setCookieHeader);
|
|
99
|
+
headers.append("Location", arg.request.url);
|
|
100
|
+
return new Response("Temporary Redirect", {
|
|
101
|
+
status: 307,
|
|
102
|
+
headers
|
|
103
|
+
});
|
|
104
|
+
} catch (e) {
|
|
105
|
+
if (e instanceof Error) {
|
|
106
|
+
console.log(e.message);
|
|
107
|
+
}
|
|
108
|
+
const setCookieHeader = await authService.getRefreshTokenSetCookie(
|
|
109
|
+
null
|
|
110
|
+
);
|
|
111
|
+
const headers = new Headers();
|
|
112
|
+
headers.append("Set-Cookie", setCookieHeader);
|
|
113
|
+
headers.append("Location", arg.request.url);
|
|
114
|
+
return new Response("Temporary Redirect", {
|
|
115
|
+
status: 307,
|
|
116
|
+
headers
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return respond(void 0);
|
|
121
|
+
};
|
|
122
|
+
return handler;
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// src/api/create_handler.ts
|
|
127
|
+
var import_server2 = require("dn-react-toolkit/file/server");
|
|
128
|
+
var createAPIHandler = ({
|
|
129
|
+
authService,
|
|
130
|
+
fileService,
|
|
131
|
+
passwordRecoveryService,
|
|
132
|
+
getThirdPartyAuth,
|
|
133
|
+
signupTokenSecret
|
|
134
|
+
}) => {
|
|
135
|
+
const handler = async (args) => {
|
|
136
|
+
const { request, params } = args;
|
|
137
|
+
const method = request.method.toUpperCase();
|
|
138
|
+
const slug = params["*"] ? params["*"].split("/") : [];
|
|
139
|
+
const withAuth = createWithAuthHandler({ authService });
|
|
140
|
+
switch (slug[0]) {
|
|
141
|
+
case "auth": {
|
|
142
|
+
switch (slug[1]) {
|
|
143
|
+
case void 0: {
|
|
144
|
+
switch (method) {
|
|
145
|
+
case "GET": {
|
|
146
|
+
return withAuth(
|
|
147
|
+
(auth) => ({ request: request2 }) => (0, import_server.findAuthHandler)(auth)(request2)
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
case "login": {
|
|
153
|
+
switch (slug[2]) {
|
|
154
|
+
case void 0: {
|
|
155
|
+
switch (method) {
|
|
156
|
+
case "POST": {
|
|
157
|
+
return (0, import_server.loginHandler)(request, {
|
|
158
|
+
authService
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
default: {
|
|
164
|
+
const provider = slug[2];
|
|
165
|
+
switch (method) {
|
|
166
|
+
case "POST": {
|
|
167
|
+
return (0, import_server.loginWithThirdPartyHandler)(request, {
|
|
168
|
+
provider,
|
|
169
|
+
getThirdPartyAuth
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
case "logout": {
|
|
177
|
+
switch (method) {
|
|
178
|
+
case "POST": {
|
|
179
|
+
return withAuth(
|
|
180
|
+
(auth) => async ({ request: request2 }) => (0, import_server.logoutHandler)({
|
|
181
|
+
authService
|
|
182
|
+
})(auth)(request2)
|
|
183
|
+
)(args);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
case "refresh": {
|
|
188
|
+
switch (method) {
|
|
189
|
+
case "GET": {
|
|
190
|
+
return (0, import_server.refreshHandler)(request, { authService });
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
case "signup": {
|
|
195
|
+
switch (slug[2]) {
|
|
196
|
+
case void 0: {
|
|
197
|
+
switch (method) {
|
|
198
|
+
case "POST": {
|
|
199
|
+
return (0, import_server.signupHandler)(request, {
|
|
200
|
+
authService,
|
|
201
|
+
fileRepository: fileService.fileRepository
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
default: {
|
|
207
|
+
switch (method) {
|
|
208
|
+
case "POST": {
|
|
209
|
+
return (0, import_server.signUpWithThirdpartyHandler)(request, {
|
|
210
|
+
authService,
|
|
211
|
+
fileService,
|
|
212
|
+
signupTokenSecret
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
case "callback": {
|
|
220
|
+
if (slug[2]) {
|
|
221
|
+
const provider = slug[2];
|
|
222
|
+
if (method === "GET") {
|
|
223
|
+
return (0, import_server.thirdpartyAuthCallbackHandler)(request, {
|
|
224
|
+
provider,
|
|
225
|
+
authService,
|
|
226
|
+
getThirdPartyAuth
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
case "request-password-reset": {
|
|
232
|
+
return (0, import_server.requestPasswordResetHandler)(request, {
|
|
233
|
+
passwordRecoveryService
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
case "reset-password": {
|
|
237
|
+
return (0, import_server.resetPasswordHandler)(request, { passwordRecoveryService });
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
case "files": {
|
|
242
|
+
switch (slug[1]) {
|
|
243
|
+
case void 0: {
|
|
244
|
+
switch (method) {
|
|
245
|
+
case "POST": {
|
|
246
|
+
return withAuth(
|
|
247
|
+
(auth) => ({ request: request2 }) => (0, import_server2.uploadFileHandler)({ fileService })(auth)(request2)
|
|
248
|
+
)(args);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
default: {
|
|
253
|
+
switch (method) {
|
|
254
|
+
case "DELETE": {
|
|
255
|
+
const fileId = slug[1];
|
|
256
|
+
return withAuth(
|
|
257
|
+
(auth) => () => (0, import_server2.deleteFileHandler)({
|
|
258
|
+
fileRepository: fileService.fileRepository
|
|
259
|
+
})({ fileId })(auth)()
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
default: {
|
|
267
|
+
return (0, http_exports.NOT_FOUND)();
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
return handler;
|
|
272
|
+
};
|
|
273
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
274
|
+
0 && (module.exports = {
|
|
275
|
+
createAPIHandler
|
|
276
|
+
});
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
|
+
|
|
19
|
+
// src/http/index.ts
|
|
20
|
+
var http_exports = {};
|
|
21
|
+
__reExport(http_exports, http_star);
|
|
22
|
+
import * as http_star from "dn-react-toolkit/http";
|
|
23
|
+
|
|
24
|
+
// src/api/create_handler.ts
|
|
25
|
+
import {
|
|
26
|
+
findAuthHandler,
|
|
27
|
+
loginHandler,
|
|
28
|
+
loginWithThirdPartyHandler,
|
|
29
|
+
logoutHandler,
|
|
30
|
+
refreshHandler,
|
|
31
|
+
requestPasswordResetHandler,
|
|
32
|
+
resetPasswordHandler,
|
|
33
|
+
signupHandler,
|
|
34
|
+
signUpWithThirdpartyHandler,
|
|
35
|
+
thirdpartyAuthCallbackHandler
|
|
36
|
+
} from "dn-react-toolkit/auth/server";
|
|
37
|
+
|
|
38
|
+
// src/auth/index.ts
|
|
39
|
+
var auth_exports = {};
|
|
40
|
+
__export(auth_exports, {
|
|
41
|
+
createWithAuthHandler: () => createWithAuthHandler
|
|
42
|
+
});
|
|
43
|
+
__reExport(auth_exports, auth_star);
|
|
44
|
+
import * as auth_star from "dn-react-toolkit/auth";
|
|
45
|
+
|
|
46
|
+
// src/auth/with_auth.ts
|
|
47
|
+
function createWithAuthHandler({ authService }) {
|
|
48
|
+
return function(fn) {
|
|
49
|
+
const handler = async function(arg) {
|
|
50
|
+
const respond = async (auth) => {
|
|
51
|
+
const userAgent = arg.request.headers.get("User-Agent") || "";
|
|
52
|
+
const res = await fn(auth)(arg);
|
|
53
|
+
if (typeof res === "object" && res !== null && !Array.isArray(res)) {
|
|
54
|
+
if (res instanceof Response) {
|
|
55
|
+
if (res.status < 300 && res.headers.get("Content-Type")?.includes("application/json")) {
|
|
56
|
+
const data = await res.json();
|
|
57
|
+
return new Response(
|
|
58
|
+
JSON.stringify({
|
|
59
|
+
AUTH: auth,
|
|
60
|
+
userAgent,
|
|
61
|
+
...data
|
|
62
|
+
}),
|
|
63
|
+
{
|
|
64
|
+
status: res.status,
|
|
65
|
+
headers: res.headers
|
|
66
|
+
}
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
return res;
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
AUTH: auth,
|
|
73
|
+
userAgent,
|
|
74
|
+
...res
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
return res;
|
|
78
|
+
};
|
|
79
|
+
const accessToken = await authService.getAccessTokenFromRequest(
|
|
80
|
+
arg.request
|
|
81
|
+
);
|
|
82
|
+
if (accessToken) {
|
|
83
|
+
const payload = await authService.jwtManager.verifyAccessToken(
|
|
84
|
+
accessToken
|
|
85
|
+
);
|
|
86
|
+
if (payload) {
|
|
87
|
+
return respond(payload);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const refreshToken = await authService.getRefreshTokenFromCookies(
|
|
91
|
+
arg.request
|
|
92
|
+
);
|
|
93
|
+
if (refreshToken) {
|
|
94
|
+
try {
|
|
95
|
+
const newAccessToken = await authService.refreshAccessToken(
|
|
96
|
+
refreshToken
|
|
97
|
+
);
|
|
98
|
+
const setCookieHeader = await authService.getAccessTokenSetCookie(
|
|
99
|
+
newAccessToken
|
|
100
|
+
);
|
|
101
|
+
const headers = new Headers();
|
|
102
|
+
headers.append("Set-Cookie", setCookieHeader);
|
|
103
|
+
headers.append("Location", arg.request.url);
|
|
104
|
+
return new Response("Temporary Redirect", {
|
|
105
|
+
status: 307,
|
|
106
|
+
headers
|
|
107
|
+
});
|
|
108
|
+
} catch (e) {
|
|
109
|
+
if (e instanceof Error) {
|
|
110
|
+
console.log(e.message);
|
|
111
|
+
}
|
|
112
|
+
const setCookieHeader = await authService.getRefreshTokenSetCookie(
|
|
113
|
+
null
|
|
114
|
+
);
|
|
115
|
+
const headers = new Headers();
|
|
116
|
+
headers.append("Set-Cookie", setCookieHeader);
|
|
117
|
+
headers.append("Location", arg.request.url);
|
|
118
|
+
return new Response("Temporary Redirect", {
|
|
119
|
+
status: 307,
|
|
120
|
+
headers
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return respond(void 0);
|
|
125
|
+
};
|
|
126
|
+
return handler;
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// src/api/create_handler.ts
|
|
131
|
+
import {
|
|
132
|
+
deleteFileHandler,
|
|
133
|
+
uploadFileHandler
|
|
134
|
+
} from "dn-react-toolkit/file/server";
|
|
135
|
+
var createAPIHandler = ({
|
|
136
|
+
authService,
|
|
137
|
+
fileService,
|
|
138
|
+
passwordRecoveryService,
|
|
139
|
+
getThirdPartyAuth,
|
|
140
|
+
signupTokenSecret
|
|
141
|
+
}) => {
|
|
142
|
+
const handler = async (args) => {
|
|
143
|
+
const { request, params } = args;
|
|
144
|
+
const method = request.method.toUpperCase();
|
|
145
|
+
const slug = params["*"] ? params["*"].split("/") : [];
|
|
146
|
+
const withAuth = createWithAuthHandler({ authService });
|
|
147
|
+
switch (slug[0]) {
|
|
148
|
+
case "auth": {
|
|
149
|
+
switch (slug[1]) {
|
|
150
|
+
case void 0: {
|
|
151
|
+
switch (method) {
|
|
152
|
+
case "GET": {
|
|
153
|
+
return withAuth(
|
|
154
|
+
(auth) => ({ request: request2 }) => findAuthHandler(auth)(request2)
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
case "login": {
|
|
160
|
+
switch (slug[2]) {
|
|
161
|
+
case void 0: {
|
|
162
|
+
switch (method) {
|
|
163
|
+
case "POST": {
|
|
164
|
+
return loginHandler(request, {
|
|
165
|
+
authService
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
default: {
|
|
171
|
+
const provider = slug[2];
|
|
172
|
+
switch (method) {
|
|
173
|
+
case "POST": {
|
|
174
|
+
return loginWithThirdPartyHandler(request, {
|
|
175
|
+
provider,
|
|
176
|
+
getThirdPartyAuth
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
case "logout": {
|
|
184
|
+
switch (method) {
|
|
185
|
+
case "POST": {
|
|
186
|
+
return withAuth(
|
|
187
|
+
(auth) => async ({ request: request2 }) => logoutHandler({
|
|
188
|
+
authService
|
|
189
|
+
})(auth)(request2)
|
|
190
|
+
)(args);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
case "refresh": {
|
|
195
|
+
switch (method) {
|
|
196
|
+
case "GET": {
|
|
197
|
+
return refreshHandler(request, { authService });
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
case "signup": {
|
|
202
|
+
switch (slug[2]) {
|
|
203
|
+
case void 0: {
|
|
204
|
+
switch (method) {
|
|
205
|
+
case "POST": {
|
|
206
|
+
return signupHandler(request, {
|
|
207
|
+
authService,
|
|
208
|
+
fileRepository: fileService.fileRepository
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
default: {
|
|
214
|
+
switch (method) {
|
|
215
|
+
case "POST": {
|
|
216
|
+
return signUpWithThirdpartyHandler(request, {
|
|
217
|
+
authService,
|
|
218
|
+
fileService,
|
|
219
|
+
signupTokenSecret
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
case "callback": {
|
|
227
|
+
if (slug[2]) {
|
|
228
|
+
const provider = slug[2];
|
|
229
|
+
if (method === "GET") {
|
|
230
|
+
return thirdpartyAuthCallbackHandler(request, {
|
|
231
|
+
provider,
|
|
232
|
+
authService,
|
|
233
|
+
getThirdPartyAuth
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
case "request-password-reset": {
|
|
239
|
+
return requestPasswordResetHandler(request, {
|
|
240
|
+
passwordRecoveryService
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
case "reset-password": {
|
|
244
|
+
return resetPasswordHandler(request, { passwordRecoveryService });
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
case "files": {
|
|
249
|
+
switch (slug[1]) {
|
|
250
|
+
case void 0: {
|
|
251
|
+
switch (method) {
|
|
252
|
+
case "POST": {
|
|
253
|
+
return withAuth(
|
|
254
|
+
(auth) => ({ request: request2 }) => uploadFileHandler({ fileService })(auth)(request2)
|
|
255
|
+
)(args);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
default: {
|
|
260
|
+
switch (method) {
|
|
261
|
+
case "DELETE": {
|
|
262
|
+
const fileId = slug[1];
|
|
263
|
+
return withAuth(
|
|
264
|
+
(auth) => () => deleteFileHandler({
|
|
265
|
+
fileRepository: fileService.fileRepository
|
|
266
|
+
})({ fileId })(auth)()
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
default: {
|
|
274
|
+
return (0, http_exports.NOT_FOUND)();
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
return handler;
|
|
279
|
+
};
|
|
280
|
+
export {
|
|
281
|
+
createAPIHandler
|
|
282
|
+
};
|