@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.
@@ -0,0 +1,10 @@
1
+ {
2
+ "exports": {
3
+ ".": {
4
+ "development": "./src/index.ts",
5
+ "types": "./dist/index.d.ts",
6
+ "import": "./dist/index.js",
7
+ "default": "./dist/index.js"
8
+ }
9
+ }
10
+ }
@@ -0,0 +1 @@
1
+ $ tsc --emitDeclarationOnly --outDir dist
@@ -0,0 +1,9 @@
1
+ $ vite build && pnpm build:types
2
+ vite v6.4.3 building for production...
3
+ transforming...
4
+ ✓ 4 modules transformed.
5
+ rendering chunks...
6
+ computing gzip size...
7
+ dist/index.js 0.36 kB │ gzip: 0.26 kB
8
+ ✓ built in 49ms
9
+ $ tsc --emitDeclarationOnly --outDir dist
@@ -0,0 +1,2 @@
1
+ export declare function capitalize(input: string): string;
2
+ //# sourceMappingURL=capitalize.d.ts.map
@@ -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"}
@@ -0,0 +1,4 @@
1
+ export * from './capitalize';
2
+ export * from './route';
3
+ export * from './types/auth';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -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
+ };
@@ -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"}
@@ -0,0 +1,3 @@
1
+ import base from '@nuxt-tmpl/eslint'
2
+
3
+ export default [...base]
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
+ }
@@ -0,0 +1,3 @@
1
+ export function capitalize(input: string) {
2
+ return input[0] ? input[0].toUpperCase() + input.slice(1) : ''
3
+ }
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './capitalize'
2
+ export * from './route'
3
+ export * from './types/auth'
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
@@ -0,0 +1,14 @@
1
+ import { defineConfig } from 'vite'
2
+
3
+ export default defineConfig({
4
+ build: {
5
+ lib: {
6
+ entry: './src/index.ts',
7
+ fileName: 'index',
8
+ formats: ['es'],
9
+ },
10
+ rollupOptions: {
11
+ external: ['@ipa-schema/api'],
12
+ },
13
+ },
14
+ })