@imtbl/auth-next-server 2.12.5-alpha.13
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/.eslintrc.cjs +17 -0
- package/LICENSE.md +176 -0
- package/dist/node/config.d.ts +21 -0
- package/dist/node/constants.d.ts +42 -0
- package/dist/node/index.cjs +436 -0
- package/dist/node/index.d.ts +301 -0
- package/dist/node/index.js +390 -0
- package/dist/node/refresh.d.ts +9 -0
- package/dist/node/types.d.ts +111 -0
- package/dist/node/utils/pathMatch.d.ts +10 -0
- package/jest.config.ts +16 -0
- package/package.json +60 -0
- package/src/config.ts +243 -0
- package/src/constants.ts +51 -0
- package/src/index.ts +662 -0
- package/src/refresh.ts +21 -0
- package/src/types.ts +124 -0
- package/src/utils/pathMatch.ts +16 -0
- package/tsconfig.eslint.json +5 -0
- package/tsconfig.json +16 -0
- package/tsconfig.types.json +8 -0
- package/tsup.config.ts +29 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-side types for @imtbl/auth-next-server
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { DefaultSession } from 'next-auth';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* zkEVM wallet information for module augmentation
|
|
9
|
+
*/
|
|
10
|
+
interface ZkEvmInfo {
|
|
11
|
+
ethAddress: string;
|
|
12
|
+
userAdminAddress: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Auth.js v5 module augmentation to add Immutable-specific fields
|
|
17
|
+
* This extends the Session type to include our custom fields
|
|
18
|
+
*/
|
|
19
|
+
declare module 'next-auth' {
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
21
|
+
interface Session extends DefaultSession {
|
|
22
|
+
user: {
|
|
23
|
+
sub: string;
|
|
24
|
+
email?: string;
|
|
25
|
+
nickname?: string;
|
|
26
|
+
} & DefaultSession['user'];
|
|
27
|
+
accessToken: string;
|
|
28
|
+
refreshToken?: string;
|
|
29
|
+
idToken?: string;
|
|
30
|
+
accessTokenExpires: number;
|
|
31
|
+
zkEvm?: ZkEvmInfo;
|
|
32
|
+
error?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
interface User {
|
|
36
|
+
id: string;
|
|
37
|
+
sub: string;
|
|
38
|
+
email?: string | null;
|
|
39
|
+
nickname?: string;
|
|
40
|
+
accessToken: string;
|
|
41
|
+
refreshToken?: string;
|
|
42
|
+
idToken?: string;
|
|
43
|
+
accessTokenExpires: number;
|
|
44
|
+
zkEvm?: ZkEvmInfo;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Configuration options for Immutable authentication
|
|
50
|
+
*/
|
|
51
|
+
export interface ImmutableAuthConfig {
|
|
52
|
+
/**
|
|
53
|
+
* Your Immutable application client ID
|
|
54
|
+
*/
|
|
55
|
+
clientId: string;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The OAuth redirect URI configured in your Immutable Hub project
|
|
59
|
+
*/
|
|
60
|
+
redirectUri: string;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* OAuth audience (default: "platform_api")
|
|
64
|
+
*/
|
|
65
|
+
audience?: string;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* OAuth scopes (default: "openid profile email offline_access transact")
|
|
69
|
+
*/
|
|
70
|
+
scope?: string;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The Immutable authentication domain (default: "https://auth.immutable.com")
|
|
74
|
+
*/
|
|
75
|
+
authenticationDomain?: string;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Token data passed from client to server during authentication
|
|
80
|
+
*/
|
|
81
|
+
export interface ImmutableTokenData {
|
|
82
|
+
accessToken: string;
|
|
83
|
+
refreshToken?: string;
|
|
84
|
+
idToken?: string;
|
|
85
|
+
accessTokenExpires: number;
|
|
86
|
+
profile: {
|
|
87
|
+
sub: string;
|
|
88
|
+
email?: string;
|
|
89
|
+
nickname?: string;
|
|
90
|
+
};
|
|
91
|
+
zkEvm?: {
|
|
92
|
+
ethAddress: string;
|
|
93
|
+
userAdminAddress: string;
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Response from the userinfo endpoint
|
|
99
|
+
*/
|
|
100
|
+
export interface UserInfoResponse {
|
|
101
|
+
sub: string;
|
|
102
|
+
email?: string;
|
|
103
|
+
email_verified?: boolean;
|
|
104
|
+
nickname?: string;
|
|
105
|
+
[key: string]: unknown;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* zkEVM user data stored in session
|
|
110
|
+
*/
|
|
111
|
+
export interface ZkEvmUser {
|
|
112
|
+
ethAddress: string;
|
|
113
|
+
userAdminAddress: string;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Immutable user data structure
|
|
118
|
+
*/
|
|
119
|
+
export interface ImmutableUser {
|
|
120
|
+
sub: string;
|
|
121
|
+
email?: string;
|
|
122
|
+
nickname?: string;
|
|
123
|
+
zkEvm?: ZkEvmUser;
|
|
124
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if pathname matches a string pattern as a path prefix.
|
|
3
|
+
* Ensures proper path boundary checking: '/api' matches '/api' and '/api/users'
|
|
4
|
+
* but NOT '/apiversion' or '/api-docs'.
|
|
5
|
+
*
|
|
6
|
+
* @param pathname - The URL pathname to check
|
|
7
|
+
* @param pattern - The string pattern to match against
|
|
8
|
+
* @returns true if pathname matches the pattern with proper path boundaries
|
|
9
|
+
*/
|
|
10
|
+
export function matchPathPrefix(pathname: string, pattern: string): boolean {
|
|
11
|
+
if (pathname === pattern) return true;
|
|
12
|
+
// Ensure pattern acts as a complete path segment prefix
|
|
13
|
+
// Add trailing slash if pattern doesn't end with one to enforce boundary
|
|
14
|
+
const prefix = pattern.endsWith('/') ? pattern : `${pattern}/`;
|
|
15
|
+
return pathname.startsWith(prefix);
|
|
16
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "./dist",
|
|
5
|
+
"rootDirs": ["src"],
|
|
6
|
+
"customConditions": ["development"],
|
|
7
|
+
"types": ["node"]
|
|
8
|
+
},
|
|
9
|
+
"include": ["src"],
|
|
10
|
+
"exclude": [
|
|
11
|
+
"node_modules",
|
|
12
|
+
"dist",
|
|
13
|
+
"src/**/*.test.ts",
|
|
14
|
+
"src/**/*.spec.ts"
|
|
15
|
+
]
|
|
16
|
+
}
|
package/tsup.config.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { defineConfig, type Options } from "tsup";
|
|
2
|
+
|
|
3
|
+
// Peer dependencies that should never be bundled
|
|
4
|
+
const peerExternal = [
|
|
5
|
+
"next",
|
|
6
|
+
"next-auth",
|
|
7
|
+
"next/navigation",
|
|
8
|
+
"next/headers",
|
|
9
|
+
"next/server",
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
const baseConfig: Options = {
|
|
13
|
+
outDir: "dist/node",
|
|
14
|
+
format: ["esm", "cjs"],
|
|
15
|
+
target: "es2022",
|
|
16
|
+
platform: "node",
|
|
17
|
+
dts: false,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export default defineConfig([
|
|
21
|
+
{
|
|
22
|
+
...baseConfig,
|
|
23
|
+
entry: {
|
|
24
|
+
index: "src/index.ts",
|
|
25
|
+
},
|
|
26
|
+
external: peerExternal,
|
|
27
|
+
clean: true,
|
|
28
|
+
},
|
|
29
|
+
]);
|