dn-react-router-toolkit 0.1.1 → 0.1.3
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/auth-kit/apple_auth.d.mts +24 -0
- package/dist/{esm/auth-kit → auth-kit}/apple_auth.d.ts +11 -2
- package/dist/auth-kit/apple_auth.js +75 -0
- package/dist/auth-kit/apple_auth.mjs +50 -0
- package/dist/auth-kit/auth_service.d.mts +73 -0
- package/dist/{esm/auth-kit → auth-kit}/auth_service.d.ts +17 -11
- package/dist/auth-kit/auth_service.js +257 -0
- package/dist/auth-kit/auth_service.mjs +218 -0
- package/dist/auth-kit/client/google_login_button.d.mts +9 -0
- package/dist/auth-kit/client/google_login_button.d.ts +9 -0
- package/dist/auth-kit/client/google_login_button.js +67 -0
- package/dist/auth-kit/client/google_login_button.mjs +32 -0
- package/dist/auth-kit/client/redirect_page.d.mts +5 -0
- package/dist/auth-kit/client/redirect_page.d.ts +5 -0
- package/dist/auth-kit/client/redirect_page.js +53 -0
- package/dist/auth-kit/client/redirect_page.mjs +18 -0
- package/dist/auth-kit/google_auth.d.mts +27 -0
- package/dist/{esm/auth-kit → auth-kit}/google_auth.d.ts +11 -2
- package/dist/auth-kit/google_auth.js +144 -0
- package/dist/auth-kit/google_auth.mjs +117 -0
- package/dist/auth-kit/jwt.d.mts +18 -0
- package/dist/{esm/auth-kit → auth-kit}/jwt.d.ts +5 -2
- package/dist/auth-kit/jwt.js +76 -0
- package/dist/auth-kit/jwt.mjs +51 -0
- package/dist/auth-kit/kakao_auth.d.mts +24 -0
- package/dist/{esm/auth-kit → auth-kit}/kakao_auth.d.ts +11 -2
- package/dist/auth-kit/kakao_auth.js +115 -0
- package/dist/auth-kit/kakao_auth.mjs +88 -0
- package/dist/auth-kit/repository.d.mts +42 -0
- package/dist/{esm/auth-kit → auth-kit}/repository.d.ts +3 -1
- package/dist/auth-kit/repository.js +18 -0
- package/dist/auth-kit/repository.mjs +0 -0
- package/dist/auth-kit/with_auth.d.mts +17 -0
- package/dist/auth-kit/with_auth.d.ts +17 -0
- package/dist/auth-kit/with_auth.js +106 -0
- package/dist/auth-kit/with_auth.mjs +69 -0
- package/dist/cn.d.mts +3 -0
- package/dist/cn.d.ts +3 -0
- package/dist/cn.js +32 -0
- package/dist/cn.mjs +7 -0
- package/dist/components/index.d.mts +5 -0
- package/dist/components/index.d.ts +5 -0
- package/dist/components/index.js +261 -0
- package/dist/components/index.mjs +219 -0
- package/dist/components/modal/fullscreen_container.d.mts +7 -0
- package/dist/components/modal/fullscreen_container.d.ts +7 -0
- package/dist/components/modal/fullscreen_container.js +102 -0
- package/dist/components/modal/fullscreen_container.mjs +68 -0
- package/dist/components/modal/hooks.d.mts +18 -0
- package/dist/components/modal/hooks.d.ts +18 -0
- package/dist/components/modal/hooks.js +236 -0
- package/dist/components/modal/hooks.mjs +204 -0
- package/dist/components/modal/index.d.mts +4 -0
- package/dist/components/modal/index.d.ts +4 -0
- package/dist/components/modal/index.js +238 -0
- package/dist/components/modal/index.mjs +203 -0
- package/dist/components/modal/modal.d.mts +13 -0
- package/dist/components/modal/modal.d.ts +13 -0
- package/dist/components/modal/modal.js +155 -0
- package/dist/components/modal/modal.mjs +130 -0
- package/dist/components/styles.d.mts +9 -0
- package/dist/components/styles.d.ts +9 -0
- package/dist/components/styles.js +48 -0
- package/dist/components/styles.mjs +17 -0
- package/dist/date.d.mts +3 -0
- package/dist/date.d.ts +3 -0
- package/dist/date.js +63 -0
- package/dist/date.mjs +28 -0
- package/dist/file-kit/cdn.d.mts +5 -0
- package/dist/file-kit/cdn.d.ts +5 -0
- package/dist/file-kit/cdn.js +34 -0
- package/dist/file-kit/cdn.mjs +9 -0
- package/dist/file-kit/client/drop_file_input.d.mts +33 -0
- package/dist/{esm/file-kit → file-kit}/client/drop_file_input.d.ts +10 -8
- package/dist/file-kit/client/drop_file_input.js +235 -0
- package/dist/file-kit/client/drop_file_input.mjs +205 -0
- package/dist/file-kit/client/file_uploader.d.mts +13 -0
- package/dist/{esm/file-kit → file-kit}/client/file_uploader.d.ts +4 -2
- package/dist/file-kit/client/file_uploader.js +115 -0
- package/dist/file-kit/client/file_uploader.mjs +90 -0
- package/dist/file-kit/file_service.d.mts +26 -0
- package/dist/{esm/file-kit → file-kit}/file_service.d.ts +7 -4
- package/dist/file-kit/file_service.js +60 -0
- package/dist/file-kit/file_service.mjs +35 -0
- package/dist/file-kit/object_storage.d.mts +17 -0
- package/dist/{esm/file-kit → file-kit}/object_storage.d.ts +6 -2
- package/dist/file-kit/object_storage.js +78 -0
- package/dist/file-kit/object_storage.mjs +57 -0
- package/dist/file-kit/repository.d.mts +16 -0
- package/dist/{esm/file-kit → file-kit}/repository.d.ts +3 -1
- package/dist/file-kit/repository.js +18 -0
- package/dist/file-kit/repository.mjs +0 -0
- package/dist/file-kit/responsive_image.d.mts +20 -0
- package/dist/file-kit/responsive_image.d.ts +20 -0
- package/dist/file-kit/responsive_image.js +123 -0
- package/dist/file-kit/responsive_image.mjs +87 -0
- package/dist/http-kit/index.d.mts +1 -0
- package/dist/http-kit/index.d.ts +1 -0
- package/dist/http-kit/index.js +111 -0
- package/dist/http-kit/index.mjs +68 -0
- package/dist/http-kit/response.d.mts +19 -0
- package/dist/http-kit/response.d.ts +19 -0
- package/dist/http-kit/response.js +109 -0
- package/dist/http-kit/response.mjs +68 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +91 -0
- package/dist/index.mjs +51 -0
- package/dist/route/api/auth/login/[provider]/route.js +113 -0
- package/dist/route/api/auth/login/[provider]/route.mjs +86 -0
- package/dist/route/api/auth/login/_provider_/route.d.mts +20 -0
- package/dist/route/api/auth/login/_provider_/route.d.ts +20 -0
- package/dist/route/api/auth/login/route.d.mts +14 -0
- package/dist/route/api/auth/login/route.d.ts +14 -0
- package/dist/route/api/auth/login/route.js +107 -0
- package/dist/route/api/auth/login/route.mjs +80 -0
- package/dist/route/api/auth/logout/route.d.mts +14 -0
- package/dist/route/api/auth/logout/route.d.ts +14 -0
- package/dist/route/api/auth/logout/route.js +98 -0
- package/dist/route/api/auth/logout/route.mjs +71 -0
- package/dist/route/api/auth/refresh/route.d.mts +13 -0
- package/dist/route/api/auth/refresh/route.d.ts +13 -0
- package/dist/route/api/auth/refresh/route.js +92 -0
- package/dist/route/api/auth/refresh/route.mjs +65 -0
- package/dist/route/api/auth/route.d.mts +13 -0
- package/dist/route/api/auth/route.d.ts +13 -0
- package/dist/route/api/auth/route.js +82 -0
- package/dist/route/api/auth/route.mjs +55 -0
- package/dist/route/api/files/[fileId]/route.js +99 -0
- package/dist/route/api/files/[fileId]/route.mjs +72 -0
- package/dist/route/api/files/_fileId_/route.d.mts +17 -0
- package/dist/route/api/files/_fileId_/route.d.ts +17 -0
- package/dist/route/api/files/route.d.mts +16 -0
- package/dist/route/api/files/route.d.ts +16 -0
- package/dist/route/api/files/route.js +106 -0
- package/dist/route/api/files/route.mjs +79 -0
- package/dist/route/api.d.mts +29 -0
- package/dist/route/api.d.ts +29 -0
- package/dist/route/api.js +395 -0
- package/dist/route/api.mjs +368 -0
- package/dist/route/auth/callback/[provider]/route.js +120 -0
- package/dist/route/auth/callback/[provider]/route.mjs +93 -0
- package/dist/route/auth/callback/_provider_/route.d.mts +20 -0
- package/dist/route/auth/callback/_provider_/route.d.ts +20 -0
- package/dist/seo-kit/index.d.mts +6 -0
- package/dist/seo-kit/index.d.ts +6 -0
- package/dist/seo-kit/index.js +321 -0
- package/dist/seo-kit/index.mjs +282 -0
- package/dist/seo-kit/loader.d.mts +7 -0
- package/dist/seo-kit/loader.d.ts +7 -0
- package/dist/seo-kit/loader.js +43 -0
- package/dist/seo-kit/loader.mjs +18 -0
- package/dist/seo-kit/seo.d.mts +103 -0
- package/dist/{esm/seo-kit → seo-kit}/seo.d.ts +10 -6
- package/dist/seo-kit/seo.js +286 -0
- package/dist/seo-kit/seo.mjs +251 -0
- package/dist/seo-kit/seo_loader.d.mts +16 -0
- package/dist/seo-kit/seo_loader.d.ts +16 -0
- package/dist/seo-kit/seo_loader.js +68 -0
- package/dist/seo-kit/seo_loader.mjs +31 -0
- package/dist/singleton.d.mts +3 -0
- package/dist/singleton.d.ts +3 -0
- package/dist/singleton.js +37 -0
- package/dist/singleton.mjs +12 -0
- package/dist/slug.d.mts +3 -0
- package/dist/slug.d.ts +3 -0
- package/dist/slug.js +32 -0
- package/dist/slug.mjs +7 -0
- package/package.json +36 -34
- package/tsup.config.ts +9 -0
- package/dist/cjs/auth-kit/apple_auth.js +0 -61
- package/dist/cjs/auth-kit/auth_service.js +0 -204
- package/dist/cjs/auth-kit/client/google_login_button.js +0 -19
- package/dist/cjs/auth-kit/client/redirect_page.js +0 -18
- package/dist/cjs/auth-kit/google_auth.js +0 -69
- package/dist/cjs/auth-kit/jwt.js +0 -54
- package/dist/cjs/auth-kit/kakao_auth.js +0 -43
- package/dist/cjs/auth-kit/repository.js +0 -2
- package/dist/cjs/auth-kit/with_auth.js +0 -46
- package/dist/cjs/cn.js +0 -6
- package/dist/cjs/components/index.js +0 -18
- package/dist/cjs/components/modal/fullscreen_container.js +0 -49
- package/dist/cjs/components/modal/hooks.js +0 -76
- package/dist/cjs/components/modal/index.js +0 -19
- package/dist/cjs/components/modal/modal.js +0 -79
- package/dist/cjs/components/styles.js +0 -10
- package/dist/cjs/date.js +0 -31
- package/dist/cjs/file-kit/cdn.js +0 -9
- package/dist/cjs/file-kit/client/drop_file_input.js +0 -148
- package/dist/cjs/file-kit/client/file_uploader.js +0 -88
- package/dist/cjs/file-kit/file_service.js +0 -32
- package/dist/cjs/file-kit/object_storage.js +0 -51
- package/dist/cjs/file-kit/repository.js +0 -2
- package/dist/cjs/file-kit/responsive_image.js +0 -63
- package/dist/cjs/http-kit/index.js +0 -17
- package/dist/cjs/http-kit/response.js +0 -37
- package/dist/cjs/index.js +0 -20
- package/dist/cjs/route/api/auth/login/[provider]/route.js +0 -36
- package/dist/cjs/route/api/auth/login/route.js +0 -35
- package/dist/cjs/route/api/auth/logout/route.js +0 -22
- package/dist/cjs/route/api/auth/refresh/route.js +0 -22
- package/dist/cjs/route/api/auth/route.js +0 -12
- package/dist/cjs/route/api/files/[fileId]/route.js +0 -20
- package/dist/cjs/route/api/files/route.js +0 -34
- package/dist/cjs/route/auth/callback/[provider]/route.js +0 -38
- package/dist/cjs/route/index.js +0 -80
- package/dist/cjs/seo-kit/index.js +0 -19
- package/dist/cjs/seo-kit/loader.js +0 -17
- package/dist/cjs/seo-kit/seo.js +0 -278
- package/dist/cjs/seo-kit/seo_loader.js +0 -15
- package/dist/cjs/singleton.js +0 -12
- package/dist/cjs/slug.js +0 -10
- package/dist/esm/auth-kit/apple_auth.js +0 -57
- package/dist/esm/auth-kit/auth_service.js +0 -197
- package/dist/esm/auth-kit/client/google_login_button.d.ts +0 -5
- package/dist/esm/auth-kit/client/google_login_button.js +0 -16
- package/dist/esm/auth-kit/client/redirect_page.d.ts +0 -1
- package/dist/esm/auth-kit/client/redirect_page.js +0 -15
- package/dist/esm/auth-kit/google_auth.js +0 -65
- package/dist/esm/auth-kit/jwt.js +0 -50
- package/dist/esm/auth-kit/kakao_auth.js +0 -39
- package/dist/esm/auth-kit/repository.js +0 -1
- package/dist/esm/auth-kit/with_auth.d.ts +0 -12
- package/dist/esm/auth-kit/with_auth.js +0 -43
- package/dist/esm/cn.d.ts +0 -1
- package/dist/esm/cn.js +0 -3
- package/dist/esm/components/index.d.ts +0 -2
- package/dist/esm/components/index.js +0 -2
- package/dist/esm/components/modal/fullscreen_container.d.ts +0 -5
- package/dist/esm/components/modal/fullscreen_container.js +0 -45
- package/dist/esm/components/modal/hooks.d.ts +0 -15
- package/dist/esm/components/modal/hooks.js +0 -67
- package/dist/esm/components/modal/index.d.ts +0 -3
- package/dist/esm/components/modal/index.js +0 -3
- package/dist/esm/components/modal/modal.d.ts +0 -10
- package/dist/esm/components/modal/modal.js +0 -43
- package/dist/esm/components/styles.d.ts +0 -7
- package/dist/esm/components/styles.js +0 -7
- package/dist/esm/date.d.ts +0 -1
- package/dist/esm/date.js +0 -24
- package/dist/esm/file-kit/cdn.d.ts +0 -3
- package/dist/esm/file-kit/cdn.js +0 -5
- package/dist/esm/file-kit/client/drop_file_input.js +0 -144
- package/dist/esm/file-kit/client/file_uploader.js +0 -84
- package/dist/esm/file-kit/file_service.js +0 -28
- package/dist/esm/file-kit/object_storage.js +0 -47
- package/dist/esm/file-kit/repository.js +0 -1
- package/dist/esm/file-kit/responsive_image.d.ts +0 -17
- package/dist/esm/file-kit/responsive_image.js +0 -58
- package/dist/esm/http-kit/index.d.ts +0 -1
- package/dist/esm/http-kit/index.js +0 -1
- package/dist/esm/http-kit/response.d.ts +0 -17
- package/dist/esm/http-kit/response.js +0 -31
- package/dist/esm/index.d.ts +0 -4
- package/dist/esm/index.js +0 -4
- package/dist/esm/route/api/auth/login/[provider]/route.d.ts +0 -10
- package/dist/esm/route/api/auth/login/[provider]/route.js +0 -32
- package/dist/esm/route/api/auth/login/route.d.ts +0 -6
- package/dist/esm/route/api/auth/login/route.js +0 -31
- package/dist/esm/route/api/auth/logout/route.d.ts +0 -6
- package/dist/esm/route/api/auth/logout/route.js +0 -18
- package/dist/esm/route/api/auth/refresh/route.d.ts +0 -4
- package/dist/esm/route/api/auth/refresh/route.js +0 -18
- package/dist/esm/route/api/auth/route.d.ts +0 -4
- package/dist/esm/route/api/auth/route.js +0 -8
- package/dist/esm/route/api/files/[fileId]/route.d.ts +0 -8
- package/dist/esm/route/api/files/[fileId]/route.js +0 -16
- package/dist/esm/route/api/files/route.d.ts +0 -6
- package/dist/esm/route/api/files/route.js +0 -30
- package/dist/esm/route/auth/callback/[provider]/route.d.ts +0 -11
- package/dist/esm/route/auth/callback/[provider]/route.js +0 -34
- package/dist/esm/route/index.d.ts +0 -22
- package/dist/esm/route/index.js +0 -76
- package/dist/esm/seo-kit/index.d.ts +0 -3
- package/dist/esm/seo-kit/index.js +0 -3
- package/dist/esm/seo-kit/loader.d.ts +0 -5
- package/dist/esm/seo-kit/loader.js +0 -14
- package/dist/esm/seo-kit/seo.js +0 -275
- package/dist/esm/seo-kit/seo_loader.d.ts +0 -12
- package/dist/esm/seo-kit/seo_loader.js +0 -12
- package/dist/esm/singleton.d.ts +0 -1
- package/dist/esm/singleton.js +0 -9
- package/dist/esm/slug.d.ts +0 -1
- package/dist/esm/slug.js +0 -6
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import React, { useEffect, useRef, } from "react";
|
|
3
|
-
import { useFullscreen } from "./fullscreen_container";
|
|
4
|
-
import { cn } from "../../cn";
|
|
5
|
-
export default function Modal({ open, className, background = "bg-gray-500/25", onBackgroundClick, children, ...props }) {
|
|
6
|
-
const containerRef = useRef(null);
|
|
7
|
-
const fullscreen = useFullscreen(containerRef);
|
|
8
|
-
const [mounted, setMounted] = React.useState(false);
|
|
9
|
-
useEffect(() => {
|
|
10
|
-
if (open) {
|
|
11
|
-
// document.body.style.overflow = "hidden";
|
|
12
|
-
setMounted(true);
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
// document.body.style.overflow = "";
|
|
16
|
-
setTimeout(() => {
|
|
17
|
-
setMounted(false);
|
|
18
|
-
}, 200);
|
|
19
|
-
}
|
|
20
|
-
return () => {
|
|
21
|
-
// document.body.style.overflow = "";
|
|
22
|
-
};
|
|
23
|
-
}, [open]);
|
|
24
|
-
const onBackgroundMouseDown = (event) => {
|
|
25
|
-
event.preventDefault();
|
|
26
|
-
onBackgroundClick?.();
|
|
27
|
-
};
|
|
28
|
-
const onModalMouseDown = (event) => {
|
|
29
|
-
event.stopPropagation();
|
|
30
|
-
};
|
|
31
|
-
const onBackgroundTouchStart = (event) => {
|
|
32
|
-
event.preventDefault();
|
|
33
|
-
onBackgroundClick?.();
|
|
34
|
-
};
|
|
35
|
-
const onModalTouchStart = (event) => {
|
|
36
|
-
event.stopPropagation();
|
|
37
|
-
};
|
|
38
|
-
return (_jsx("div", { ref: containerRef, className: cn(fullscreen, "z-[999] flex flex-col justify-center transition-bg duration-200 md:px-6 overflow-hidden print:px-0 print:block print:overflow-auto", open && mounted
|
|
39
|
-
? cn(background, "ease-out")
|
|
40
|
-
: "bg-transparent ease-in pointer-events-none"), onMouseDown: onBackgroundMouseDown, onTouchStart: onBackgroundTouchStart, children: _jsx("div", { className: cn("relative flex-1 flex flex-col justify-end md:justify-center items-center transition-[opacity transform] duration-200 print:block", open && mounted
|
|
41
|
-
? "translate-y-[0px] opacity-100 ease-out"
|
|
42
|
-
: "translate-y-[100%] md:translate-y-[50px] opacity-0 ease-in"), children: (open || mounted) && (_jsx("div", { ...props, className: cn(className, "w-full max-h-[92vh] print:w-[unset] print:max-h-[unset] rounded-tl-lg rounded-tr-lg md:rounded-lg overflow-auto print:rounded-none"), onMouseDown: onModalMouseDown, onTouchStart: onModalTouchStart, children: children })) }) }));
|
|
43
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export declare const inputBackgroundStyle = "text-[16px] border border-neutral-200 outline-none appearance-none disabled:opacity-50 disabled:cursor-not-allowed placeholder:text-neutral-400";
|
|
2
|
-
export declare const formInputStyle = "w-full px-3 text-[16px] border border-neutral-200 outline-none appearance-none disabled:opacity-50 disabled:cursor-not-allowed placeholder:text-neutral-400 h-[40px]";
|
|
3
|
-
export declare const baseButtonStyle = "transition-colors text-sm font-semibold cursor-pointer flex items-center justify-center rounded-lg whitespace-nowrap text-ellipsis overflow-hidden";
|
|
4
|
-
export declare const primaryButtonStyle = "transition-colors text-sm font-semibold cursor-pointer flex items-center justify-center rounded-lg whitespace-nowrap text-ellipsis overflow-hidden px-4 h-[40px] bg-gradient-to-br from-primary-400 to-primary-500 text-white transition-colors";
|
|
5
|
-
export declare const disabledButtonStyle = "transition-colors text-sm font-semibold cursor-pointer flex items-center justify-center rounded-lg whitespace-nowrap text-ellipsis overflow-hidden h-[40px] px-4 bg-neutral-200 text-neutral-400";
|
|
6
|
-
export declare const outlineButtonStyle = "transition-colors text-sm font-semibold cursor-pointer flex items-center justify-center rounded-lg whitespace-nowrap text-ellipsis overflow-hidden h-[40px] px-4 bg-white border border-neutral-300 hover:bg-neutral-50";
|
|
7
|
-
export declare const dangerousButtonStyle = "transition-colors text-sm font-semibold cursor-pointer flex items-center justify-center rounded-lg whitespace-nowrap text-ellipsis overflow-hidden h-[40px] px-4 bg-white border hover:bg-red-50 text-red-600";
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export const inputBackgroundStyle = "text-[16px] border border-neutral-200 outline-none appearance-none disabled:opacity-50 disabled:cursor-not-allowed placeholder:text-neutral-400";
|
|
2
|
-
export const formInputStyle = `w-full px-3 ${inputBackgroundStyle} h-[40px]`;
|
|
3
|
-
export const baseButtonStyle = "transition-colors text-sm font-semibold cursor-pointer flex items-center justify-center rounded-lg whitespace-nowrap text-ellipsis overflow-hidden";
|
|
4
|
-
export const primaryButtonStyle = `${baseButtonStyle} px-4 h-[40px] bg-gradient-to-br from-primary-400 to-primary-500 text-white transition-colors`;
|
|
5
|
-
export const disabledButtonStyle = `${baseButtonStyle} h-[40px] px-4 bg-neutral-200 text-neutral-400`;
|
|
6
|
-
export const outlineButtonStyle = `${baseButtonStyle} h-[40px] px-4 bg-white border border-neutral-300 hover:bg-neutral-50`;
|
|
7
|
-
export const dangerousButtonStyle = `${baseButtonStyle} h-[40px] px-4 bg-white border hover:bg-red-50 text-red-600`;
|
package/dist/esm/date.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const formatHumanDateTime: (value: string | Date) => string;
|
package/dist/esm/date.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import moment from "moment-timezone";
|
|
2
|
-
export const formatHumanDateTime = (value) => {
|
|
3
|
-
const date = moment(value).tz("Asia/Seoul");
|
|
4
|
-
const now = moment().tz("Asia/Seoul");
|
|
5
|
-
if (date.isAfter(now.clone().subtract(1, "minute"))) {
|
|
6
|
-
return "방금 전";
|
|
7
|
-
}
|
|
8
|
-
if (date.isAfter(now.clone().subtract(1, "hour"))) {
|
|
9
|
-
const diff = now.diff(date, "minute");
|
|
10
|
-
return `${diff}분 전`;
|
|
11
|
-
}
|
|
12
|
-
if (date.isAfter(now.clone().subtract(6, "hours"))) {
|
|
13
|
-
const diff = now.diff(date, "hour");
|
|
14
|
-
return `${diff}시간 전`;
|
|
15
|
-
}
|
|
16
|
-
if (date.isAfter(now.clone().subtract(1, "week"))) {
|
|
17
|
-
const diff = now.diff(date, "day");
|
|
18
|
-
return `${diff}일 전`;
|
|
19
|
-
}
|
|
20
|
-
if (date.isSame(now, "year")) {
|
|
21
|
-
return date.format("M월 D일");
|
|
22
|
-
}
|
|
23
|
-
return date.format("YYYY년 M월 D일");
|
|
24
|
-
};
|
package/dist/esm/file-kit/cdn.js
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useState, useCallback, useRef, useEffect, useMemo, } from "react";
|
|
3
|
-
import { v4 } from "uuid";
|
|
4
|
-
import { cn } from "../../cn";
|
|
5
|
-
export function useDropFileInput({ defaultValue, options, uploadFile, onFileInput, onFileUploaded, limit, } = {}) {
|
|
6
|
-
const [files, setFiles] = useState(defaultValue
|
|
7
|
-
? (Array.isArray(defaultValue) ? defaultValue : [defaultValue])
|
|
8
|
-
.map((v) => {
|
|
9
|
-
return {
|
|
10
|
-
key: v4(),
|
|
11
|
-
item: v,
|
|
12
|
-
};
|
|
13
|
-
})
|
|
14
|
-
.slice(0, limit ? limit : Infinity)
|
|
15
|
-
: []);
|
|
16
|
-
const fileRef = useRef([]);
|
|
17
|
-
useEffect(() => {
|
|
18
|
-
fileRef.current = files;
|
|
19
|
-
}, [files]);
|
|
20
|
-
const Component = useCallback(function Component({ className, container = "border border-dashed border-neutral-300 rounded flex items-center justify-center", draggingClassName, name, hideMessage = false, children, ...props }) {
|
|
21
|
-
const [isDragging, setIsDragging] = useState(false);
|
|
22
|
-
const handleDragEnter = useCallback((e) => {
|
|
23
|
-
e.preventDefault();
|
|
24
|
-
e.stopPropagation();
|
|
25
|
-
setIsDragging(true);
|
|
26
|
-
}, []);
|
|
27
|
-
const handleDragLeave = useCallback((e) => {
|
|
28
|
-
e.preventDefault();
|
|
29
|
-
e.stopPropagation();
|
|
30
|
-
setIsDragging(false);
|
|
31
|
-
}, []);
|
|
32
|
-
const handleDragOver = useCallback((e) => {
|
|
33
|
-
e.preventDefault();
|
|
34
|
-
e.stopPropagation();
|
|
35
|
-
}, []);
|
|
36
|
-
const handleFiles = useCallback(async (files) => {
|
|
37
|
-
if (limit && fileRef.current.length >= limit) {
|
|
38
|
-
alert(`파일은 최대 ${limit}개 업로드할 수 있습니다.`);
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
const filteredFiles = files.filter((file) => {
|
|
42
|
-
// if (!props.accept) {
|
|
43
|
-
// return true;
|
|
44
|
-
// }
|
|
45
|
-
// const accepts = props.accept.split(",");
|
|
46
|
-
// for (const accept of accepts) {
|
|
47
|
-
// if (file.type.startsWith(accept)) {
|
|
48
|
-
// return true;
|
|
49
|
-
// }
|
|
50
|
-
// if (file.name.endsWith(accept)) {
|
|
51
|
-
// return true;
|
|
52
|
-
// }
|
|
53
|
-
// }
|
|
54
|
-
// return false;
|
|
55
|
-
return true;
|
|
56
|
-
});
|
|
57
|
-
if (files.length !== filteredFiles.length) {
|
|
58
|
-
alert(`${props.accept} 형식의 파일만 업로드할 수 있습니다.`);
|
|
59
|
-
}
|
|
60
|
-
const limitedFiles = filteredFiles.slice(0, limit ? limit - fileRef.current.length : Infinity);
|
|
61
|
-
if (limitedFiles.length === 0) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
if (onFileInput) {
|
|
65
|
-
onFileInput(limitedFiles);
|
|
66
|
-
}
|
|
67
|
-
for (const file of limitedFiles) {
|
|
68
|
-
const fileItem = {
|
|
69
|
-
key: v4(),
|
|
70
|
-
};
|
|
71
|
-
setFiles((prevFiles) => [...prevFiles, fileItem]);
|
|
72
|
-
uploadFile?.(file, options).then(async (item) => {
|
|
73
|
-
await onFileUploaded?.(item);
|
|
74
|
-
setFiles((prevFiles) => prevFiles.map((f) => {
|
|
75
|
-
if (f.key === fileItem.key) {
|
|
76
|
-
return {
|
|
77
|
-
...f,
|
|
78
|
-
item,
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
return f;
|
|
82
|
-
}));
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
}, [props.accept]);
|
|
86
|
-
const handleDrop = useCallback((e) => {
|
|
87
|
-
e.preventDefault();
|
|
88
|
-
e.stopPropagation();
|
|
89
|
-
setIsDragging(false);
|
|
90
|
-
if (e.dataTransfer.files && e.dataTransfer.files.length > 0) {
|
|
91
|
-
handleFiles(Array.from(e.dataTransfer.files));
|
|
92
|
-
e.dataTransfer.clearData();
|
|
93
|
-
}
|
|
94
|
-
}, [handleFiles]);
|
|
95
|
-
const inputRef = useRef(null);
|
|
96
|
-
const handleClick = useCallback(() => {
|
|
97
|
-
inputRef.current?.click();
|
|
98
|
-
}, []);
|
|
99
|
-
const handleKeyDown = useCallback((e) => {
|
|
100
|
-
if (e.key === "Enter" || e.key === " ") {
|
|
101
|
-
handleClick();
|
|
102
|
-
}
|
|
103
|
-
}, [handleClick]);
|
|
104
|
-
const handleChange = useCallback((e) => {
|
|
105
|
-
if (e.target.files && e.target.files.length > 0) {
|
|
106
|
-
handleFiles(Array.from(e.target.files));
|
|
107
|
-
e.target.value = "";
|
|
108
|
-
}
|
|
109
|
-
}, [handleFiles]);
|
|
110
|
-
return (_jsxs("div", { className: cn(className, container, draggingClassName?.(isDragging) ||
|
|
111
|
-
(isDragging ? "bg-neutral-300/25" : "hover:bg-neutral-300/25"), "transition-colors cursor-pointer"), onDragEnter: handleDragEnter, onDragLeave: handleDragLeave, onDragOver: handleDragOver, onDrop: handleDrop, onClick: handleClick, onChange: handleChange, onKeyDown: handleKeyDown, tabIndex: 0, role: "button", children: [_jsx("input", { ...props, defaultValue: "", type: "file", hidden: true, ref: inputRef }), _jsx("input", { name: name, hidden: true, readOnly: true, value: files
|
|
112
|
-
.map((file) => {
|
|
113
|
-
if (file.item &&
|
|
114
|
-
typeof file.item === "object" &&
|
|
115
|
-
"id" in file.item) {
|
|
116
|
-
return file.item.id;
|
|
117
|
-
}
|
|
118
|
-
return null;
|
|
119
|
-
})
|
|
120
|
-
.filter(Boolean)
|
|
121
|
-
.join(",") }), children ||
|
|
122
|
-
(!(hideMessage && !isDragging) && _jsx(DropFileMessageBox, {}))] }));
|
|
123
|
-
}, [limit, fileRef, files, options, uploadFile, onFileInput, onFileUploaded]);
|
|
124
|
-
const loadedFileIds = files
|
|
125
|
-
.map((file) => {
|
|
126
|
-
if (file.item && typeof file.item === "object" && "id" in file.item) {
|
|
127
|
-
return file.item.id;
|
|
128
|
-
}
|
|
129
|
-
return null;
|
|
130
|
-
})
|
|
131
|
-
.filter(Boolean);
|
|
132
|
-
const loadedFileIdsString = loadedFileIds.join(",");
|
|
133
|
-
const fileIds = useMemo(() => loadedFileIdsString.split(",").filter(Boolean), [loadedFileIdsString]);
|
|
134
|
-
return {
|
|
135
|
-
fileIds,
|
|
136
|
-
files,
|
|
137
|
-
setFiles,
|
|
138
|
-
Component,
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
export function DropFileMessageBox() {
|
|
142
|
-
return (_jsx("div", { className: "text-sm pointer-events-none flex justify-center items-center", children: _jsx("div", { className: "flex flex-col items-center", children: _jsx("span", { children: "\uD30C\uC77C\uC744 \uC5EC\uAE30\uB85C \uB04C\uC5B4\uB2E4 \uB193\uAC70\uB098 \uD074\uB9AD\uD574\uC11C \uC120\uD0DD\uD574 \uC8FC\uC138\uC694" }) }) }));
|
|
143
|
-
}
|
|
144
|
-
export default useDropFileInput;
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
export class FileUploader {
|
|
2
|
-
endpoint;
|
|
3
|
-
constructor(endpoint = "/api/files") {
|
|
4
|
-
this.endpoint = endpoint;
|
|
5
|
-
}
|
|
6
|
-
formatSize = (size) => {
|
|
7
|
-
if (size < 1024) {
|
|
8
|
-
return `${size} B`;
|
|
9
|
-
}
|
|
10
|
-
if (size < 1024 * 1024) {
|
|
11
|
-
return `${(size / 1024).toFixed(2)} KB`;
|
|
12
|
-
}
|
|
13
|
-
return `${(size / (1024 * 1024)).toFixed(2)} MB`;
|
|
14
|
-
};
|
|
15
|
-
uploadFile(file, options = {}) {
|
|
16
|
-
return this.uploadBlob(file, file.name, options);
|
|
17
|
-
}
|
|
18
|
-
async uploadBlob(blob, name = "blob", options = {}) {
|
|
19
|
-
const { type, size } = blob;
|
|
20
|
-
const metadataForMedia = await new Promise((resolve, reject) => {
|
|
21
|
-
if (blob.type.startsWith("image/")) {
|
|
22
|
-
const img = new Image();
|
|
23
|
-
img.src = URL.createObjectURL(blob);
|
|
24
|
-
img.onload = () => {
|
|
25
|
-
resolve({
|
|
26
|
-
...options.metadata,
|
|
27
|
-
width: img.width,
|
|
28
|
-
height: img.height,
|
|
29
|
-
});
|
|
30
|
-
};
|
|
31
|
-
img.onerror = reject;
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
if (blob.type.startsWith("video/")) {
|
|
35
|
-
const video = document.createElement("video");
|
|
36
|
-
video.src = URL.createObjectURL(blob);
|
|
37
|
-
video.onloadedmetadata = () => {
|
|
38
|
-
resolve({
|
|
39
|
-
...options.metadata,
|
|
40
|
-
width: video.videoWidth,
|
|
41
|
-
height: video.videoHeight,
|
|
42
|
-
duration: video.duration,
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
video.onerror = reject;
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
resolve(options.metadata || {});
|
|
49
|
-
});
|
|
50
|
-
const res1 = await fetch(this.endpoint, {
|
|
51
|
-
method: "POST",
|
|
52
|
-
body: JSON.stringify({
|
|
53
|
-
name: name.replace(/ /g, "_"),
|
|
54
|
-
type,
|
|
55
|
-
size,
|
|
56
|
-
metadata: metadataForMedia,
|
|
57
|
-
}),
|
|
58
|
-
});
|
|
59
|
-
if (!res1.ok) {
|
|
60
|
-
const message = await res1.json();
|
|
61
|
-
throw new Error(message);
|
|
62
|
-
}
|
|
63
|
-
const result = await res1.json();
|
|
64
|
-
const { signedUrl, file } = result;
|
|
65
|
-
const res2 = await fetch(signedUrl, {
|
|
66
|
-
method: "PUT",
|
|
67
|
-
body: blob,
|
|
68
|
-
});
|
|
69
|
-
if (!res2.ok) {
|
|
70
|
-
throw new Error(await res2.text());
|
|
71
|
-
}
|
|
72
|
-
return file;
|
|
73
|
-
}
|
|
74
|
-
async deleteFile(fileId) {
|
|
75
|
-
const res = await fetch(`${this.endpoint}/${fileId}`, {
|
|
76
|
-
method: "DELETE",
|
|
77
|
-
});
|
|
78
|
-
if (!res.ok) {
|
|
79
|
-
const { message } = await res.json();
|
|
80
|
-
throw new Error(message);
|
|
81
|
-
}
|
|
82
|
-
return true;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { v4 } from "uuid";
|
|
2
|
-
export class FileService {
|
|
3
|
-
prefix;
|
|
4
|
-
repository;
|
|
5
|
-
OBJECT_STORAGE;
|
|
6
|
-
constructor(prefix = "user", { repository, OBJECT_STORAGE, }) {
|
|
7
|
-
this.prefix = prefix;
|
|
8
|
-
this.repository = repository;
|
|
9
|
-
this.OBJECT_STORAGE = OBJECT_STORAGE;
|
|
10
|
-
}
|
|
11
|
-
async generateSignedUrl({ userId, name, type, size, metadata = {} }) {
|
|
12
|
-
const id = v4();
|
|
13
|
-
const key = `${this.prefix}/${id}/${name}`;
|
|
14
|
-
const file = await this.repository.createFile({
|
|
15
|
-
id,
|
|
16
|
-
userId,
|
|
17
|
-
name,
|
|
18
|
-
type,
|
|
19
|
-
size,
|
|
20
|
-
metadata,
|
|
21
|
-
key,
|
|
22
|
-
});
|
|
23
|
-
const signedUrl = await this.OBJECT_STORAGE.generateSignedUrl(key, {
|
|
24
|
-
contentType: type,
|
|
25
|
-
});
|
|
26
|
-
return { file, signedUrl };
|
|
27
|
-
}
|
|
28
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { GetObjectCommand, PutObjectCommand, S3Client, } from "@aws-sdk/client-s3";
|
|
2
|
-
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
|
|
3
|
-
export class ObjectStorage {
|
|
4
|
-
client = new S3Client({
|
|
5
|
-
region: "ap-northeast-2",
|
|
6
|
-
});
|
|
7
|
-
bucketName;
|
|
8
|
-
constructor(bucketName) {
|
|
9
|
-
this.bucketName = bucketName;
|
|
10
|
-
}
|
|
11
|
-
async generateSignedUrl(key, { contentType, expiresIn = 3600, } = {}) {
|
|
12
|
-
const command = new PutObjectCommand({
|
|
13
|
-
Bucket: this.bucketName,
|
|
14
|
-
Key: key,
|
|
15
|
-
ContentType: contentType,
|
|
16
|
-
});
|
|
17
|
-
const signedUrl = await getSignedUrl(this.client, command, {
|
|
18
|
-
expiresIn,
|
|
19
|
-
});
|
|
20
|
-
return signedUrl;
|
|
21
|
-
}
|
|
22
|
-
async find(key) {
|
|
23
|
-
try {
|
|
24
|
-
const command = new GetObjectCommand({
|
|
25
|
-
Bucket: this.bucketName,
|
|
26
|
-
Key: key,
|
|
27
|
-
});
|
|
28
|
-
const { Body } = await this.client.send(command);
|
|
29
|
-
if (!Body) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
return Body.transformToByteArray();
|
|
33
|
-
}
|
|
34
|
-
catch (error) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
async put(key, buffer, { contentType } = {}) {
|
|
39
|
-
const command = new PutObjectCommand({
|
|
40
|
-
Bucket: this.bucketName,
|
|
41
|
-
Key: key,
|
|
42
|
-
ContentType: contentType,
|
|
43
|
-
Body: buffer,
|
|
44
|
-
});
|
|
45
|
-
return await this.client.send(command);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
export type ResponsiveImageProps = Omit<React.DetailedHTMLProps<React.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, "src" | "srcSet" | "alt"> & {
|
|
3
|
-
alt: string;
|
|
4
|
-
src?: string;
|
|
5
|
-
file?: {
|
|
6
|
-
key: string;
|
|
7
|
-
};
|
|
8
|
-
ratio?: number;
|
|
9
|
-
};
|
|
10
|
-
export declare const createResponsiveImage: (cdn: (key: string | undefined, options?: {
|
|
11
|
-
width?: number;
|
|
12
|
-
}) => string | undefined) => React.FC<ResponsiveImageProps>;
|
|
13
|
-
export default createResponsiveImage;
|
|
14
|
-
export declare function generateSrcSet(image: HTMLImageElement | string, ratio?: number, props?: {
|
|
15
|
-
width?: string | number;
|
|
16
|
-
height?: string | number;
|
|
17
|
-
}): string | undefined;
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
const sizes = [
|
|
3
|
-
64, 128, 256, 320, 480, 640, 768, 1080, 1200, 1536, 1920, 2560, 3840,
|
|
4
|
-
];
|
|
5
|
-
export const createResponsiveImage = (cdn) => {
|
|
6
|
-
const Component = ({ alt, file, ratio, ...props }) => {
|
|
7
|
-
const src = cdn(file?.key) || props.src || "#";
|
|
8
|
-
return (_jsx("img", { ...props, src: src, alt: alt, srcSet: generateSrcSet(src, ratio, props) }));
|
|
9
|
-
};
|
|
10
|
-
return Component;
|
|
11
|
-
};
|
|
12
|
-
export default createResponsiveImage;
|
|
13
|
-
const generateSrc = (src, width, height, ratio, image = {}) => {
|
|
14
|
-
const searchParams = new URLSearchParams();
|
|
15
|
-
if (image.width) {
|
|
16
|
-
searchParams.set("w", image.width.toString());
|
|
17
|
-
}
|
|
18
|
-
if (width) {
|
|
19
|
-
searchParams.set("w", width.toString());
|
|
20
|
-
if (ratio) {
|
|
21
|
-
searchParams.set("h", Math.round(width / ratio).toString());
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
if (image.height) {
|
|
25
|
-
searchParams.set("h", image.height.toString());
|
|
26
|
-
}
|
|
27
|
-
if (height) {
|
|
28
|
-
searchParams.set("h", height.toString());
|
|
29
|
-
}
|
|
30
|
-
const search = searchParams.toString() ? `?${searchParams.toString()}` : "";
|
|
31
|
-
const origin = process.env.NEXT_PUBLIC_CDN_ORIGIN || "";
|
|
32
|
-
if (!src.includes(origin)) {
|
|
33
|
-
return src;
|
|
34
|
-
}
|
|
35
|
-
return `${encodeURI(decodeURI(src))}${search}`;
|
|
36
|
-
};
|
|
37
|
-
export function generateSrcSet(image, ratio, props = {}) {
|
|
38
|
-
const src = typeof image === "string" ? image : image.src;
|
|
39
|
-
const isGif = src.endsWith(".gif");
|
|
40
|
-
if (isGif) {
|
|
41
|
-
return undefined;
|
|
42
|
-
}
|
|
43
|
-
if (props.width) {
|
|
44
|
-
return [1, 2, 3]
|
|
45
|
-
.map((scale) => {
|
|
46
|
-
const genWidth = Number(props.width) * scale;
|
|
47
|
-
return `${generateSrc(src, genWidth, props.height
|
|
48
|
-
? Number(props.height) * scale
|
|
49
|
-
: ratio
|
|
50
|
-
? Math.round(genWidth / ratio)
|
|
51
|
-
: undefined)} ${scale}x`;
|
|
52
|
-
})
|
|
53
|
-
.join(", ");
|
|
54
|
-
}
|
|
55
|
-
return sizes
|
|
56
|
-
.map((size) => `${generateSrc(src, size, undefined, ratio, props)} ${size}w`)
|
|
57
|
-
.join(", ");
|
|
58
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./response";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./response";
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export declare const createJsonResponse: (status: number) => (data?: unknown, init?: ResponseInit) => Response;
|
|
2
|
-
export declare const OK: (data?: unknown, init?: ResponseInit) => Response;
|
|
3
|
-
export declare const CREATED: (data?: unknown, init?: ResponseInit) => Response;
|
|
4
|
-
export declare const ACCEPTED: (data?: unknown, init?: ResponseInit) => Response;
|
|
5
|
-
export declare const NO_CONTENT: (init?: ResponseInit) => Response;
|
|
6
|
-
export declare const createException: (status: number, defaultMessage?: unknown) => (message?: unknown, init?: ResponseInit) => Response;
|
|
7
|
-
export declare const BAD_REQUEST: (message?: unknown, init?: ResponseInit) => Response;
|
|
8
|
-
export declare const UNAUTHORIZED: (message?: unknown, init?: ResponseInit) => Response;
|
|
9
|
-
export declare const FORBIDDEN: (message?: unknown, init?: ResponseInit) => Response;
|
|
10
|
-
export declare const NOT_FOUND: (message?: unknown, init?: ResponseInit) => Response;
|
|
11
|
-
export declare const METHOD_NOT_ALLOWED: (message?: unknown, init?: ResponseInit) => Response;
|
|
12
|
-
export declare const NOT_ACCEPTABLE: (message?: unknown, init?: ResponseInit) => Response;
|
|
13
|
-
export declare const REQUEST_TIMEOUT: (message?: unknown, init?: ResponseInit) => Response;
|
|
14
|
-
export declare const CONFLICT: (message?: unknown, init?: ResponseInit) => Response;
|
|
15
|
-
export declare const UNPROCESSABLE_ENTITY: (message?: unknown, init?: ResponseInit) => Response;
|
|
16
|
-
export declare const TOO_MANY_REQUESTS: (message?: unknown, init?: ResponseInit) => Response;
|
|
17
|
-
export declare const INTERNAL_SERVER_ERROR: (message?: unknown, init?: ResponseInit) => Response;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
export const createJsonResponse = (status) => {
|
|
2
|
-
return (data = {}, init) => {
|
|
3
|
-
return Response.json(data, { status, ...init });
|
|
4
|
-
};
|
|
5
|
-
};
|
|
6
|
-
Response;
|
|
7
|
-
export const OK = createJsonResponse(200);
|
|
8
|
-
export const CREATED = createJsonResponse(201);
|
|
9
|
-
export const ACCEPTED = createJsonResponse(202);
|
|
10
|
-
export const NO_CONTENT = (init) => {
|
|
11
|
-
return new Response(null, {
|
|
12
|
-
...init,
|
|
13
|
-
status: 204,
|
|
14
|
-
});
|
|
15
|
-
};
|
|
16
|
-
export const createException = (status, defaultMessage = "오류가 발생했습니다.") => {
|
|
17
|
-
return (message = defaultMessage, init) => {
|
|
18
|
-
return createJsonResponse(status)({ message }, init);
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
export const BAD_REQUEST = createException(400, "요청이 올바르지 않습니다.");
|
|
22
|
-
export const UNAUTHORIZED = createException(401, "인증이 필요합니다.");
|
|
23
|
-
export const FORBIDDEN = createException(403, "권한이 없습니다.");
|
|
24
|
-
export const NOT_FOUND = createException(404, "요청한 리소스를 찾을 수 없습니다.");
|
|
25
|
-
export const METHOD_NOT_ALLOWED = createException(405, "메서드를 사용할 수 없습니다.");
|
|
26
|
-
export const NOT_ACCEPTABLE = createException(406, "요청한 형식을 사용할 수 없습니다.");
|
|
27
|
-
export const REQUEST_TIMEOUT = createException(408, "요청 시간이 초과되었습니다.");
|
|
28
|
-
export const CONFLICT = createException(409, "요청이 충돌했습니다.");
|
|
29
|
-
export const UNPROCESSABLE_ENTITY = createException(422, "처리할 수 없는 엔티티입니다.");
|
|
30
|
-
export const TOO_MANY_REQUESTS = createException(429, "요청이 너무 많습니다.");
|
|
31
|
-
export const INTERNAL_SERVER_ERROR = createException(500, "예기치 못한 오류가 발생했습니다.");
|
package/dist/esm/index.d.ts
DELETED
package/dist/esm/index.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { GoogleAuth } from "../../../../../auth-kit/google_auth";
|
|
2
|
-
import { AppleAuth } from "../../../../../auth-kit/apple_auth";
|
|
3
|
-
import { KakaoAuth } from "../../../../../auth-kit/kakao_auth";
|
|
4
|
-
export declare const loginThirdPartyHandler: (request: Request, { provider, }: {
|
|
5
|
-
provider: string;
|
|
6
|
-
}, { GOOGLE_AUTH, APPLE_AUTH, KAKAO_AUTH, }: {
|
|
7
|
-
GOOGLE_AUTH: GoogleAuth;
|
|
8
|
-
APPLE_AUTH: AppleAuth;
|
|
9
|
-
KAKAO_AUTH: KakaoAuth;
|
|
10
|
-
}) => Promise<Response>;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { BAD_REQUEST, CREATED, INTERNAL_SERVER_ERROR, } from "../../../../../http-kit";
|
|
2
|
-
export const loginThirdPartyHandler = async (request, { provider, }, { GOOGLE_AUTH, APPLE_AUTH, KAKAO_AUTH, }) => {
|
|
3
|
-
const { code } = await request.json();
|
|
4
|
-
if (!code) {
|
|
5
|
-
return BAD_REQUEST("코드가 없습니다.");
|
|
6
|
-
}
|
|
7
|
-
const getThirdPartyAuth = (provider) => {
|
|
8
|
-
switch (provider) {
|
|
9
|
-
case "google":
|
|
10
|
-
return GOOGLE_AUTH;
|
|
11
|
-
case "apple":
|
|
12
|
-
return APPLE_AUTH;
|
|
13
|
-
case "kakao":
|
|
14
|
-
return KAKAO_AUTH;
|
|
15
|
-
default:
|
|
16
|
-
throw BAD_REQUEST("지원하지 않는 인증 제공자입니다.");
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
try {
|
|
20
|
-
const { accessToken, refreshToken } = await getThirdPartyAuth(provider).signIn(code);
|
|
21
|
-
return CREATED({
|
|
22
|
-
accessToken,
|
|
23
|
-
refreshToken,
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
catch (error) {
|
|
27
|
-
if (error instanceof Response) {
|
|
28
|
-
return error;
|
|
29
|
-
}
|
|
30
|
-
throw INTERNAL_SERVER_ERROR();
|
|
31
|
-
}
|
|
32
|
-
};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { AuthService } from "../../../../auth-kit/auth_service";
|
|
2
|
-
import { JWTManager } from "../../../../auth-kit/jwt";
|
|
3
|
-
export declare const loginCredentialHandler: (request: Request, { AUTH, JWT_MANAGER, }: {
|
|
4
|
-
AUTH: AuthService;
|
|
5
|
-
JWT_MANAGER: JWTManager;
|
|
6
|
-
}) => Promise<Response>;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { CREATED, UNAUTHORIZED } from "../../../../http-kit";
|
|
2
|
-
export const loginCredentialHandler = async (request, { AUTH, JWT_MANAGER, }) => {
|
|
3
|
-
const searchParams = new URL(request.url).searchParams;
|
|
4
|
-
const { id, password } = await request.json();
|
|
5
|
-
try {
|
|
6
|
-
const { accessToken, refreshToken } = await AUTH.signIn({
|
|
7
|
-
id,
|
|
8
|
-
password,
|
|
9
|
-
});
|
|
10
|
-
if (searchParams.get("type") === "json") {
|
|
11
|
-
return CREATED({ accessToken, refreshToken });
|
|
12
|
-
}
|
|
13
|
-
const [accessTokenSetCookie, refreshTokenSetCookie] = await Promise.all([
|
|
14
|
-
AUTH.getAccessTokenSetCookie(accessToken),
|
|
15
|
-
AUTH.getRefreshTokenSetCookie(refreshToken),
|
|
16
|
-
]);
|
|
17
|
-
const payload = JWT_MANAGER.decode(accessToken);
|
|
18
|
-
const headers = new Headers();
|
|
19
|
-
headers.append("Set-Cookie", accessTokenSetCookie);
|
|
20
|
-
headers.append("Set-Cookie", refreshTokenSetCookie);
|
|
21
|
-
return CREATED(payload, {
|
|
22
|
-
headers,
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
catch (e) {
|
|
26
|
-
if (e instanceof Error) {
|
|
27
|
-
return UNAUTHORIZED(e.message);
|
|
28
|
-
}
|
|
29
|
-
throw e;
|
|
30
|
-
}
|
|
31
|
-
};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { AuthService } from "../../../../auth-kit/auth_service";
|
|
2
|
-
import { type AuthRepository } from "../../../../auth-kit/repository";
|
|
3
|
-
export declare const logoutHandler: (request: Request, { AUTH, repository }: {
|
|
4
|
-
AUTH: AuthService;
|
|
5
|
-
repository: AuthRepository;
|
|
6
|
-
}) => Promise<Response>;
|