@nuxt-tmpl/core 0.0.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/.prepublish-backup.json +10 -0
- package/.turbo/turbo-build$colon$types.log +1 -0
- package/.turbo/turbo-build.log +9 -0
- package/dist/capitalize.d.ts +2 -0
- package/dist/capitalize.d.ts.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/route.d.ts +16 -0
- package/dist/route.d.ts.map +1 -0
- package/dist/types/auth.d.ts +41 -0
- package/dist/types/auth.d.ts.map +1 -0
- package/eslint.config.mjs +3 -0
- package/package.json +36 -0
- package/src/capitalize.ts +3 -0
- package/src/index.ts +3 -0
- package/src/route.ts +43 -0
- package/src/types/auth.ts +52 -0
- package/tsconfig.json +16 -0
- package/vite.config.ts +14 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
$ tsc --emitDeclarationOnly --outDir dist
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
$ vite build && pnpm build:types
|
|
2
|
+
[36mvite v6.4.3 [32mbuilding for production...[36m[39m
|
|
3
|
+
transforming...
|
|
4
|
+
[32m✓[39m 4 modules transformed.
|
|
5
|
+
rendering chunks...
|
|
6
|
+
computing gzip size...
|
|
7
|
+
[2mdist/[22m[36mindex.js [39m[1m[2m0.36 kB[22m[1m[22m[2m │ gzip: 0.26 kB[22m
|
|
8
|
+
[32m✓ built in 49ms[39m
|
|
9
|
+
$ tsc --emitDeclarationOnly --outDir dist
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capitalize.d.ts","sourceRoot":"","sources":["../src/capitalize.ts"],"names":[],"mappings":"AAAA,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,UAEvC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,SAAS,CAAA;AACvB,cAAc,cAAc,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
function i(e) {
|
|
2
|
+
return e[0] ? e[0].toUpperCase() + e.slice(1) : "";
|
|
3
|
+
}
|
|
4
|
+
const s = ["/sign-in", "/sign-up", "/"], t = ["/__nuxt_error"];
|
|
5
|
+
function o(e, r) {
|
|
6
|
+
return r.some(
|
|
7
|
+
(n) => e === n || (e == null ? void 0 : e.includes(`${n}/`))
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
function c(e, r = []) {
|
|
11
|
+
const n = [...s, ...r];
|
|
12
|
+
return o(e, n);
|
|
13
|
+
}
|
|
14
|
+
function _(e, r = [], n = []) {
|
|
15
|
+
if (e != null && e.startsWith("/__nuxt_error?"))
|
|
16
|
+
return !0;
|
|
17
|
+
const u = [
|
|
18
|
+
...s,
|
|
19
|
+
...r,
|
|
20
|
+
...t,
|
|
21
|
+
...n
|
|
22
|
+
];
|
|
23
|
+
return o(e, u);
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
i as capitalize,
|
|
27
|
+
c as isGuestRoute,
|
|
28
|
+
_ as isSafeRoute
|
|
29
|
+
};
|
package/dist/route.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 是否是访客路由(未登录用户可访问,登录后应跳走)
|
|
3
|
+
* @param path 路径
|
|
4
|
+
* @param extraRoutes 其他路由
|
|
5
|
+
* @returns 是否是访客路由
|
|
6
|
+
*/
|
|
7
|
+
export declare function isGuestRoute(path: string, extraRoutes?: string[]): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* 是否是安全路由(无需鉴权即可访问)
|
|
10
|
+
* @param path 路径
|
|
11
|
+
* @param guestRoutes 访客路由
|
|
12
|
+
* @param publicRoutes 公开路由
|
|
13
|
+
* @returns 是否是安全路由
|
|
14
|
+
*/
|
|
15
|
+
export declare function isSafeRoute(path: string, guestRoutes?: string[], publicRoutes?: string[]): boolean;
|
|
16
|
+
//# sourceMappingURL=route.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../src/route.ts"],"names":[],"mappings":"AASA;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,GAAE,MAAM,EAAO,WAGpE;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,MAAM,EACZ,WAAW,GAAE,MAAM,EAAO,EAC1B,YAAY,GAAE,MAAM,EAAO,WAY5B"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ApiResponse } from '@ipa-schema/api';
|
|
2
|
+
export type AuthProviderId = 'clerk' | 'better-auth' | 'supabase';
|
|
3
|
+
export interface AuthUser {
|
|
4
|
+
id: string;
|
|
5
|
+
email: string;
|
|
6
|
+
name: string;
|
|
7
|
+
avatarUrl: string | null;
|
|
8
|
+
createdAt: Date;
|
|
9
|
+
}
|
|
10
|
+
export interface AuthSession {
|
|
11
|
+
user: AuthUser;
|
|
12
|
+
sessionId: string;
|
|
13
|
+
expiresAt: Date;
|
|
14
|
+
}
|
|
15
|
+
export interface AuthSignInData {
|
|
16
|
+
email: string;
|
|
17
|
+
password: string;
|
|
18
|
+
}
|
|
19
|
+
export interface AuthSignUpData extends AuthSignInData {
|
|
20
|
+
name?: string;
|
|
21
|
+
}
|
|
22
|
+
export type AuthResult = ApiResponse;
|
|
23
|
+
export interface RefLike<T> {
|
|
24
|
+
value: T;
|
|
25
|
+
}
|
|
26
|
+
export interface AuthProvider {
|
|
27
|
+
readonly id: AuthProviderId | 'none';
|
|
28
|
+
user: RefLike<AuthUser | null>;
|
|
29
|
+
isLoaded: RefLike<boolean>;
|
|
30
|
+
isSignedIn: RefLike<boolean>;
|
|
31
|
+
signIn: (data: AuthSignInData) => Promise<AuthResult>;
|
|
32
|
+
signUp: (data: AuthSignUpData) => Promise<AuthResult>;
|
|
33
|
+
signOut: () => Promise<void>;
|
|
34
|
+
signInWithOAuth: (provider: string) => Promise<void>;
|
|
35
|
+
openSignIn?: () => Promise<void>;
|
|
36
|
+
openSignUp?: () => Promise<void>;
|
|
37
|
+
openUserProfile?: () => Promise<void>;
|
|
38
|
+
SignInForm?: Record<string, any>;
|
|
39
|
+
SignUpForm?: Record<string, any>;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/types/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAElD,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,aAAa,GAAG,UAAU,CAAA;AAEjE,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,SAAS,EAAE,IAAI,CAAA;CAChB;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,QAAQ,CAAA;IACd,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,IAAI,CAAA;CAChB;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,cAAe,SAAQ,cAAc;IACpD,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAED,MAAM,MAAM,UAAU,GAAG,WAAW,CAAA;AAEpC,MAAM,WAAW,OAAO,CAAC,CAAC;IACxB,KAAK,EAAE,CAAC,CAAA;CACT;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,EAAE,cAAc,GAAG,MAAM,CAAA;IAEpC,IAAI,EAAE,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAA;IAC9B,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;IAC1B,UAAU,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;IAE5B,MAAM,EAAE,CAAC,IAAI,EAAE,cAAc,KAAK,OAAO,CAAC,UAAU,CAAC,CAAA;IACrD,MAAM,EAAE,CAAC,IAAI,EAAE,cAAc,KAAK,OAAO,CAAC,UAAU,CAAC,CAAA;IACrD,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAC5B,eAAe,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAEpD,UAAU,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAChC,UAAU,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAChC,eAAe,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAErC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAChC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CACjC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nuxt-tmpl/core",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.3",
|
|
5
|
+
"private": false,
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"import": "./dist/index.js",
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.js",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build:types": "tsc --emitDeclarationOnly --outDir dist",
|
|
24
|
+
"build": "vite build && pnpm build:types",
|
|
25
|
+
"dev": "vite build --watch",
|
|
26
|
+
"prepublishOnly": "pnpm build && node ../../scripts/prepublish.mjs",
|
|
27
|
+
"postpublish": "node ../../scripts/prepublish.mjs --restore"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@ipa-schema/api": "^1.1.0",
|
|
32
|
+
"@nuxt-tmpl/eslint": "workspace:*",
|
|
33
|
+
"typescript": "^6.0.3",
|
|
34
|
+
"vite": "^6.0.0"
|
|
35
|
+
}
|
|
36
|
+
}
|
package/src/index.ts
ADDED
package/src/route.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const DEFAULT_GUEST_ROUTES = ['/sign-in', '/sign-up', '/']
|
|
2
|
+
const DEFAULT_PUBLIC_ROUTES = ['/__nuxt_error']
|
|
3
|
+
|
|
4
|
+
function matchRoutes(path: string, routes: string[]) {
|
|
5
|
+
return routes.some(
|
|
6
|
+
route => path === route || path?.includes(`${route}/`),
|
|
7
|
+
)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 是否是访客路由(未登录用户可访问,登录后应跳走)
|
|
12
|
+
* @param path 路径
|
|
13
|
+
* @param extraRoutes 其他路由
|
|
14
|
+
* @returns 是否是访客路由
|
|
15
|
+
*/
|
|
16
|
+
export function isGuestRoute(path: string, extraRoutes: string[] = []) {
|
|
17
|
+
const routes = [...DEFAULT_GUEST_ROUTES, ...extraRoutes]
|
|
18
|
+
return matchRoutes(path, routes)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 是否是安全路由(无需鉴权即可访问)
|
|
23
|
+
* @param path 路径
|
|
24
|
+
* @param guestRoutes 访客路由
|
|
25
|
+
* @param publicRoutes 公开路由
|
|
26
|
+
* @returns 是否是安全路由
|
|
27
|
+
*/
|
|
28
|
+
export function isSafeRoute(
|
|
29
|
+
path: string,
|
|
30
|
+
guestRoutes: string[] = [],
|
|
31
|
+
publicRoutes: string[] = [],
|
|
32
|
+
) {
|
|
33
|
+
if (path?.startsWith('/__nuxt_error?')) {
|
|
34
|
+
return true
|
|
35
|
+
}
|
|
36
|
+
const routes = [
|
|
37
|
+
...DEFAULT_GUEST_ROUTES,
|
|
38
|
+
...guestRoutes,
|
|
39
|
+
...DEFAULT_PUBLIC_ROUTES,
|
|
40
|
+
...publicRoutes,
|
|
41
|
+
]
|
|
42
|
+
return matchRoutes(path, routes)
|
|
43
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { ApiResponse } from '@ipa-schema/api'
|
|
2
|
+
|
|
3
|
+
export type AuthProviderId = 'clerk' | 'better-auth' | 'supabase'
|
|
4
|
+
|
|
5
|
+
export interface AuthUser {
|
|
6
|
+
id: string
|
|
7
|
+
email: string
|
|
8
|
+
name: string
|
|
9
|
+
avatarUrl: string | null
|
|
10
|
+
createdAt: Date
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface AuthSession {
|
|
14
|
+
user: AuthUser
|
|
15
|
+
sessionId: string
|
|
16
|
+
expiresAt: Date
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface AuthSignInData {
|
|
20
|
+
email: string
|
|
21
|
+
password: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface AuthSignUpData extends AuthSignInData {
|
|
25
|
+
name?: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type AuthResult = ApiResponse
|
|
29
|
+
|
|
30
|
+
export interface RefLike<T> {
|
|
31
|
+
value: T
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface AuthProvider {
|
|
35
|
+
readonly id: AuthProviderId | 'none'
|
|
36
|
+
|
|
37
|
+
user: RefLike<AuthUser | null>
|
|
38
|
+
isLoaded: RefLike<boolean>
|
|
39
|
+
isSignedIn: RefLike<boolean>
|
|
40
|
+
|
|
41
|
+
signIn: (data: AuthSignInData) => Promise<AuthResult>
|
|
42
|
+
signUp: (data: AuthSignUpData) => Promise<AuthResult>
|
|
43
|
+
signOut: () => Promise<void>
|
|
44
|
+
signInWithOAuth: (provider: string) => Promise<void>
|
|
45
|
+
|
|
46
|
+
openSignIn?: () => Promise<void>
|
|
47
|
+
openSignUp?: () => Promise<void>
|
|
48
|
+
openUserProfile?: () => Promise<void>
|
|
49
|
+
|
|
50
|
+
SignInForm?: Record<string, any>
|
|
51
|
+
SignUpForm?: Record<string, any>
|
|
52
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
"rootDir": "./src",
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"moduleResolution": "bundler",
|
|
7
|
+
"strict": true,
|
|
8
|
+
"declaration": true,
|
|
9
|
+
"declarationMap": true,
|
|
10
|
+
"outDir": "./dist",
|
|
11
|
+
"sourceMap": true,
|
|
12
|
+
"esModuleInterop": true,
|
|
13
|
+
"skipLibCheck": true
|
|
14
|
+
},
|
|
15
|
+
"include": ["src"]
|
|
16
|
+
}
|
package/vite.config.ts
ADDED