@vistagenic/vista 0.3.2 → 0.3.4

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.
Files changed (118) hide show
  1. package/bin/vista.js +79 -109
  2. package/dist/ai/embeddings.d.ts +11 -11
  3. package/dist/ai/embeddings.js +71 -71
  4. package/dist/ai/index.d.ts +10 -10
  5. package/dist/ai/index.js +26 -26
  6. package/dist/ai/providers/base.js +85 -85
  7. package/dist/ai/react/react-server.d.ts +1 -1
  8. package/dist/ai/react/react-server.js +17 -17
  9. package/dist/ai/react/use-agent.js +138 -138
  10. package/dist/auth/core.d.ts +140 -140
  11. package/dist/auth/core.js +165 -165
  12. package/dist/auth/index.d.ts +20 -20
  13. package/dist/auth/index.js +369 -369
  14. package/dist/auth/react-server.d.ts +1 -1
  15. package/dist/auth/react-server.js +10 -10
  16. package/dist/auth/react.d.ts +18 -18
  17. package/dist/auth/react.js +71 -71
  18. package/dist/bin/build-rsc-flashpack.js +6 -0
  19. package/dist/bin/build-rsc.js +555 -492
  20. package/dist/bin/build.js +365 -353
  21. package/dist/bin/generate.js +513 -510
  22. package/dist/bin/webpack.config.d.ts +3 -1
  23. package/dist/bin/webpack.config.js +7 -4
  24. package/dist/build/manifest.d.ts +169 -169
  25. package/dist/build/manifest.js +423 -423
  26. package/dist/build/rsc/client-manifest.d.ts +62 -62
  27. package/dist/build/rsc/client-manifest.js +295 -295
  28. package/dist/build/rsc/compiler.d.ts +3 -1
  29. package/dist/build/rsc/compiler.js +12 -7
  30. package/dist/build/rsc/native-scanner.d.ts +135 -135
  31. package/dist/build/rsc/native-scanner.js +203 -203
  32. package/dist/build/rsc/react-client-reference-manifest.d.ts +35 -28
  33. package/dist/build/rsc/react-client-reference-manifest.js +366 -240
  34. package/dist/build/standalone.js +260 -254
  35. package/dist/client/dynamic.react-server.d.ts +2 -2
  36. package/dist/client/dynamic.react-server.js +23 -23
  37. package/dist/client/link.js +1 -1
  38. package/dist/client/link.react-server.d.ts +2 -2
  39. package/dist/client/link.react-server.js +11 -11
  40. package/dist/client/navigation.js +2 -2
  41. package/dist/client/navigation.react-server.d.ts +1 -1
  42. package/dist/client/navigation.react-server.js +17 -17
  43. package/dist/client/router.react-server.d.ts +1 -1
  44. package/dist/client/router.react-server.js +17 -17
  45. package/dist/client/rsc-router.d.ts +1 -3
  46. package/dist/client/rsc-router.js +98 -45
  47. package/dist/client/rsc-router.react-server.d.ts +1 -1
  48. package/dist/client/rsc-router.react-server.js +17 -17
  49. package/dist/client/script.react-server.d.ts +2 -2
  50. package/dist/client/script.react-server.js +23 -23
  51. package/dist/config.d.ts +1 -1
  52. package/dist/config.js +1 -7
  53. package/dist/deploy/adapters/cloudflare.js +42 -41
  54. package/dist/deploy/adapters/docker.d.ts +1 -0
  55. package/dist/deploy/adapters/docker.js +5 -4
  56. package/dist/deploy/adapters/netlify.js +60 -27
  57. package/dist/deploy/adapters/vercel.js +80 -50
  58. package/dist/deploy/preflight.js +4 -3
  59. package/dist/deploy/runtime-pack.d.ts +11 -0
  60. package/dist/deploy/runtime-pack.js +300 -0
  61. package/dist/deploy/utils.d.ts +7 -1
  62. package/dist/deploy/utils.js +95 -3
  63. package/dist/flashpack/command.js +1 -0
  64. package/dist/flashpack/runtime.js +2 -1
  65. package/dist/image/get-img-props.js +21 -11
  66. package/dist/image/image-config.d.ts +2 -0
  67. package/dist/image/image-config.js +17 -0
  68. package/dist/image/index.d.ts +18 -3
  69. package/dist/image/index.js +1 -1
  70. package/dist/image/react-server.d.ts +1 -2
  71. package/dist/image/react-server.js +1 -1
  72. package/dist/index.d.ts +23 -23
  73. package/dist/index.js +61 -61
  74. package/dist/server/app-dir.d.ts +22 -0
  75. package/dist/server/app-dir.js +77 -0
  76. package/dist/server/app-router-runtime.d.ts +1 -0
  77. package/dist/server/app-router-runtime.js +34 -9
  78. package/dist/server/cookie-parse.d.ts +4 -4
  79. package/dist/server/cookie-parse.js +14 -14
  80. package/dist/server/engine.js +5 -5
  81. package/dist/server/hydration-chunks.d.ts +7 -0
  82. package/dist/server/hydration-chunks.js +49 -0
  83. package/dist/server/image-optimizer.js +2 -1
  84. package/dist/server/index.d.ts +109 -109
  85. package/dist/server/index.js +315 -315
  86. package/dist/server/middleware-runner.d.ts +125 -125
  87. package/dist/server/middleware-runner.js +607 -615
  88. package/dist/server/middleware-security.d.ts +36 -36
  89. package/dist/server/middleware-security.js +183 -183
  90. package/dist/server/module-compile-hook.js +706 -695
  91. package/dist/server/root-resolver.js +6 -5
  92. package/dist/server/rsc-engine-flashpack.d.ts +3 -1
  93. package/dist/server/rsc-engine-flashpack.js +12 -1
  94. package/dist/server/rsc-engine.d.ts +6 -1
  95. package/dist/server/rsc-engine.js +217 -280
  96. package/dist/server/rsc-upstream.js +900 -892
  97. package/dist/server/ssr-webpack-shim.d.ts +6 -0
  98. package/dist/server/ssr-webpack-shim.js +29 -0
  99. package/dist/server/static-generator.d.ts +2 -0
  100. package/dist/server/static-generator.js +33 -32
  101. package/dist/server/structure-validator.js +2 -1
  102. package/dist/server/structure-watch.js +2 -0
  103. package/dist/server/typed-api-runtime.js +639 -635
  104. package/dist/server/vista-import-map.js +134 -134
  105. package/dist/stack/index.d.ts +34 -34
  106. package/dist/stack/index.js +49 -49
  107. package/dist/stack/server/caller.d.ts +13 -13
  108. package/dist/stack/server/caller.js +42 -42
  109. package/dist/stack/server/executor.d.ts +40 -40
  110. package/dist/stack/server/executor.js +222 -222
  111. package/dist/stack/server/index.d.ts +11 -11
  112. package/dist/stack/server/index.js +24 -24
  113. package/dist/stack/server/procedure.d.ts +20 -20
  114. package/dist/stack/server/procedure.js +66 -66
  115. package/dist/stack/server/types.d.ts +113 -113
  116. package/dist/theme/react-server.d.ts +10 -10
  117. package/dist/theme/react-server.js +16 -16
  118. package/package.json +1 -1
@@ -1,17 +1,17 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./index"), exports);
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./index"), exports);
@@ -1,138 +1,138 @@
1
- 'use client';
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.useAgent = useAgent;
5
- const react_1 = require("react");
6
- function useAgent(options = {}) {
7
- const { api = '/api/chat', initialMessages = [], sessionId, onResponse, onFinish, onError, } = options;
8
- const [messages, setMessages] = (0, react_1.useState)(initialMessages);
9
- const [input, setInput] = (0, react_1.useState)('');
10
- const [isLoading, setIsLoading] = (0, react_1.useState)(false);
11
- const [error, setError] = (0, react_1.useState)(null);
12
- const abortControllerRef = (0, react_1.useRef)(null);
13
- const handleInputChange = (0, react_1.useCallback)((e) => {
14
- setInput(e?.target?.value ?? e);
15
- }, []);
16
- const stop = (0, react_1.useCallback)(() => {
17
- if (abortControllerRef.current) {
18
- abortControllerRef.current.abort();
19
- abortControllerRef.current = null;
20
- setIsLoading(false);
21
- }
22
- }, []);
23
- const sendPrompt = (0, react_1.useCallback)(async (promptToSend) => {
24
- if (!promptToSend.trim())
25
- return;
26
- const userMessage = { role: 'user', content: promptToSend };
27
- const newMessages = [...messages, userMessage];
28
- setMessages(newMessages);
29
- setInput('');
30
- setIsLoading(true);
31
- setError(null);
32
- const abortController = new AbortController();
33
- abortControllerRef.current = abortController;
34
- try {
35
- const response = await fetch(api, {
36
- method: 'POST',
37
- headers: { 'Content-Type': 'application/json' },
38
- body: JSON.stringify({
39
- prompt: promptToSend,
40
- messages: newMessages,
41
- sessionId,
42
- }),
43
- signal: abortController.signal,
44
- });
45
- onResponse?.(response);
46
- if (!response.ok) {
47
- const errText = await response.text().catch(() => '');
48
- throw new Error(errText || `Request failed with status ${response.status}`);
49
- }
50
- if (!response.body) {
51
- throw new Error('Response body is empty or not streamable');
52
- }
53
- const reader = response.body.getReader();
54
- const decoder = new TextDecoder();
55
- let buffer = '';
56
- let assistantText = '';
57
- // Add empty assistant message that will stream
58
- setMessages((prev) => [...prev, { role: 'assistant', content: '' }]);
59
- while (true) {
60
- const { done, value } = await reader.read();
61
- if (done)
62
- break;
63
- buffer += decoder.decode(value, { stream: true });
64
- const lines = buffer.split('\n');
65
- buffer = lines.pop() || '';
66
- for (const line of lines) {
67
- const trimmed = line.trim();
68
- if (!trimmed.startsWith('data: '))
69
- continue;
70
- const payload = trimmed.slice(6);
71
- if (payload === '[DONE]')
72
- break;
73
- try {
74
- const chunk = JSON.parse(payload);
75
- if (chunk.type === 'text-delta' && chunk.textDelta) {
76
- assistantText += chunk.textDelta;
77
- setMessages((prev) => {
78
- const updated = [...prev];
79
- const lastIdx = updated.length - 1;
80
- if (lastIdx >= 0 && updated[lastIdx].role === 'assistant') {
81
- updated[lastIdx] = {
82
- ...updated[lastIdx],
83
- content: assistantText,
84
- };
85
- }
86
- return updated;
87
- });
88
- }
89
- else if (chunk.type === 'error' && chunk.error) {
90
- throw new Error(chunk.error);
91
- }
92
- }
93
- catch {
94
- // Ignore partial JSON chunks
95
- }
96
- }
97
- }
98
- const finalAssistantMessage = {
99
- role: 'assistant',
100
- content: assistantText,
101
- };
102
- onFinish?.(finalAssistantMessage);
103
- }
104
- catch (err) {
105
- if (err?.name === 'AbortError')
106
- return;
107
- const e = err instanceof Error ? err : new Error(String(err));
108
- setError(e);
109
- onError?.(e);
110
- }
111
- finally {
112
- setIsLoading(false);
113
- abortControllerRef.current = null;
114
- }
115
- }, [api, messages, sessionId, onResponse, onFinish, onError]);
116
- const handleSubmit = (0, react_1.useCallback)(async (e, submitOptions) => {
117
- e?.preventDefault?.();
118
- const promptToSend = submitOptions?.prompt ?? input;
119
- await sendPrompt(promptToSend);
120
- }, [input, sendPrompt]);
121
- const reload = (0, react_1.useCallback)(async () => {
122
- const lastUserMessage = [...messages].reverse().find((m) => m.role === 'user');
123
- if (lastUserMessage) {
124
- await sendPrompt(lastUserMessage.content);
125
- }
126
- }, [messages, sendPrompt]);
127
- return {
128
- messages,
129
- input,
130
- setInput,
131
- handleInputChange,
132
- handleSubmit,
133
- isLoading,
134
- error,
135
- stop,
136
- reload,
137
- };
138
- }
1
+ 'use client';
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.useAgent = useAgent;
5
+ const react_1 = require("react");
6
+ function useAgent(options = {}) {
7
+ const { api = '/api/chat', initialMessages = [], sessionId, onResponse, onFinish, onError, } = options;
8
+ const [messages, setMessages] = (0, react_1.useState)(initialMessages);
9
+ const [input, setInput] = (0, react_1.useState)('');
10
+ const [isLoading, setIsLoading] = (0, react_1.useState)(false);
11
+ const [error, setError] = (0, react_1.useState)(null);
12
+ const abortControllerRef = (0, react_1.useRef)(null);
13
+ const handleInputChange = (0, react_1.useCallback)((e) => {
14
+ setInput(e?.target?.value ?? e);
15
+ }, []);
16
+ const stop = (0, react_1.useCallback)(() => {
17
+ if (abortControllerRef.current) {
18
+ abortControllerRef.current.abort();
19
+ abortControllerRef.current = null;
20
+ setIsLoading(false);
21
+ }
22
+ }, []);
23
+ const sendPrompt = (0, react_1.useCallback)(async (promptToSend) => {
24
+ if (!promptToSend.trim())
25
+ return;
26
+ const userMessage = { role: 'user', content: promptToSend };
27
+ const newMessages = [...messages, userMessage];
28
+ setMessages(newMessages);
29
+ setInput('');
30
+ setIsLoading(true);
31
+ setError(null);
32
+ const abortController = new AbortController();
33
+ abortControllerRef.current = abortController;
34
+ try {
35
+ const response = await fetch(api, {
36
+ method: 'POST',
37
+ headers: { 'Content-Type': 'application/json' },
38
+ body: JSON.stringify({
39
+ prompt: promptToSend,
40
+ messages: newMessages,
41
+ sessionId,
42
+ }),
43
+ signal: abortController.signal,
44
+ });
45
+ onResponse?.(response);
46
+ if (!response.ok) {
47
+ const errText = await response.text().catch(() => '');
48
+ throw new Error(errText || `Request failed with status ${response.status}`);
49
+ }
50
+ if (!response.body) {
51
+ throw new Error('Response body is empty or not streamable');
52
+ }
53
+ const reader = response.body.getReader();
54
+ const decoder = new TextDecoder();
55
+ let buffer = '';
56
+ let assistantText = '';
57
+ // Add empty assistant message that will stream
58
+ setMessages((prev) => [...prev, { role: 'assistant', content: '' }]);
59
+ while (true) {
60
+ const { done, value } = await reader.read();
61
+ if (done)
62
+ break;
63
+ buffer += decoder.decode(value, { stream: true });
64
+ const lines = buffer.split('\n');
65
+ buffer = lines.pop() || '';
66
+ for (const line of lines) {
67
+ const trimmed = line.trim();
68
+ if (!trimmed.startsWith('data: '))
69
+ continue;
70
+ const payload = trimmed.slice(6);
71
+ if (payload === '[DONE]')
72
+ break;
73
+ try {
74
+ const chunk = JSON.parse(payload);
75
+ if (chunk.type === 'text-delta' && chunk.textDelta) {
76
+ assistantText += chunk.textDelta;
77
+ setMessages((prev) => {
78
+ const updated = [...prev];
79
+ const lastIdx = updated.length - 1;
80
+ if (lastIdx >= 0 && updated[lastIdx].role === 'assistant') {
81
+ updated[lastIdx] = {
82
+ ...updated[lastIdx],
83
+ content: assistantText,
84
+ };
85
+ }
86
+ return updated;
87
+ });
88
+ }
89
+ else if (chunk.type === 'error' && chunk.error) {
90
+ throw new Error(chunk.error);
91
+ }
92
+ }
93
+ catch {
94
+ // Ignore partial JSON chunks
95
+ }
96
+ }
97
+ }
98
+ const finalAssistantMessage = {
99
+ role: 'assistant',
100
+ content: assistantText,
101
+ };
102
+ onFinish?.(finalAssistantMessage);
103
+ }
104
+ catch (err) {
105
+ if (err?.name === 'AbortError')
106
+ return;
107
+ const e = err instanceof Error ? err : new Error(String(err));
108
+ setError(e);
109
+ onError?.(e);
110
+ }
111
+ finally {
112
+ setIsLoading(false);
113
+ abortControllerRef.current = null;
114
+ }
115
+ }, [api, messages, sessionId, onResponse, onFinish, onError]);
116
+ const handleSubmit = (0, react_1.useCallback)(async (e, submitOptions) => {
117
+ e?.preventDefault?.();
118
+ const promptToSend = submitOptions?.prompt ?? input;
119
+ await sendPrompt(promptToSend);
120
+ }, [input, sendPrompt]);
121
+ const reload = (0, react_1.useCallback)(async () => {
122
+ const lastUserMessage = [...messages].reverse().find((m) => m.role === 'user');
123
+ if (lastUserMessage) {
124
+ await sendPrompt(lastUserMessage.content);
125
+ }
126
+ }, [messages, sendPrompt]);
127
+ return {
128
+ messages,
129
+ input,
130
+ setInput,
131
+ handleInputChange,
132
+ handleSubmit,
133
+ isLoading,
134
+ error,
135
+ stop,
136
+ reload,
137
+ };
138
+ }
@@ -1,140 +1,140 @@
1
- export interface AuthUser {
2
- id: string;
3
- name?: string | null;
4
- email?: string | null;
5
- image?: string | null;
6
- }
7
- export interface AuthSession {
8
- user: AuthUser;
9
- expires: string;
10
- }
11
- export interface JWTPayload extends AuthSession {
12
- iat: number;
13
- exp: number;
14
- }
15
- export interface Account {
16
- provider: string;
17
- type: 'oauth' | 'oidc' | 'credentials';
18
- providerAccountId: string;
19
- access_token?: string;
20
- refresh_token?: string;
21
- token_type?: string;
22
- scope?: string;
23
- id_token?: string;
24
- }
25
- export interface Adapter {
26
- createUser?(user: AuthUser): Promise<AuthUser> | AuthUser;
27
- getUser?(id: string): Promise<AuthUser | null> | AuthUser | null;
28
- getUserByEmail?(email: string): Promise<AuthUser | null> | AuthUser | null;
29
- getUserByAccount?(provider: string, providerAccountId: string): Promise<AuthUser | null> | AuthUser | null;
30
- linkAccount?(userId: string, account: Account): Promise<void> | void;
31
- }
32
- export interface OAuthProvider {
33
- id: string;
34
- name: string;
35
- type: 'oauth';
36
- clientId: string;
37
- clientSecret: string;
38
- authorization: {
39
- url: string;
40
- params?: Record<string, string>;
41
- };
42
- token: string;
43
- userinfo: string;
44
- profile(profile: any): AuthUser | Promise<AuthUser>;
45
- }
46
- export interface CredentialsProvider {
47
- id: string;
48
- name: string;
49
- type: 'credentials';
50
- credentials: Record<string, {
51
- label?: string;
52
- type?: string;
53
- }>;
54
- authorize(credentials: Record<string, string>): Promise<AuthUser | null> | AuthUser | null;
55
- }
56
- export type AuthProvider = OAuthProvider | CredentialsProvider;
57
- export interface AuthCallbacks {
58
- signIn?: (params: {
59
- user: AuthUser;
60
- account?: Account | null;
61
- }) => boolean | Promise<boolean>;
62
- jwt?: (params: {
63
- token: JWTPayload;
64
- user?: AuthUser;
65
- }) => JWTPayload | Promise<JWTPayload>;
66
- session?: (params: {
67
- session: AuthSession;
68
- token: JWTPayload;
69
- }) => AuthSession | Promise<AuthSession>;
70
- redirect?: (params: {
71
- url: string;
72
- baseUrl: string;
73
- }) => string | Promise<string>;
74
- authorized?: (params: {
75
- auth: AuthSession | null;
76
- request: Request;
77
- }) => boolean | Response | Promise<boolean | Response>;
78
- }
79
- export interface AuthConfig {
80
- providers: AuthProvider[];
81
- adapter?: Adapter;
82
- secret?: string;
83
- session?: {
84
- strategy?: 'jwt' | 'database';
85
- maxAge?: number;
86
- cookieName?: string;
87
- };
88
- pages?: {
89
- signIn?: string;
90
- error?: string;
91
- };
92
- callbacks?: AuthCallbacks;
93
- trustHost?: boolean;
94
- basePath?: string;
95
- }
96
- export interface ResolvedAuthConfig extends AuthConfig {
97
- secret: string;
98
- session: {
99
- strategy: 'jwt' | 'database';
100
- maxAge: number;
101
- cookieName: string;
102
- };
103
- basePath: string;
104
- }
105
- export declare function hashPassword(password: string, salt?: string): string;
106
- export declare function verifyPassword(password: string, stored: string): boolean;
107
- export declare function randomToken(bytes?: number): string;
108
- export declare function encryptJwt(payload: JWTPayload, secret: string): string;
109
- export declare function decryptJwt(token: string, secret: string): JWTPayload | null;
110
- export declare function pkcePair(): {
111
- verifier: string;
112
- challenge: string;
113
- };
114
- export declare class MemoryAdapter implements Adapter {
115
- users: Map<string, AuthUser>;
116
- accounts: Map<string, string>;
117
- createUser(user: AuthUser): AuthUser;
118
- getUser(id: string): AuthUser | null;
119
- getUserByEmail(email: string): AuthUser | null;
120
- getUserByAccount(provider: string, providerAccountId: string): AuthUser | null;
121
- linkAccount(userId: string, account: Account): void;
122
- }
123
- export declare function GitHub(options: {
124
- clientId?: string;
125
- clientSecret?: string;
126
- }): OAuthProvider;
127
- export declare function Google(options?: {
128
- clientId?: string;
129
- clientSecret?: string;
130
- }): OAuthProvider;
131
- export declare function Credentials(options: {
132
- id?: string;
133
- name?: string;
134
- credentials?: Record<string, {
135
- label?: string;
136
- type?: string;
137
- }>;
138
- authorize: CredentialsProvider['authorize'];
139
- }): CredentialsProvider;
140
- export declare function resolveAuthConfig(config: AuthConfig): ResolvedAuthConfig;
1
+ export interface AuthUser {
2
+ id: string;
3
+ name?: string | null;
4
+ email?: string | null;
5
+ image?: string | null;
6
+ }
7
+ export interface AuthSession {
8
+ user: AuthUser;
9
+ expires: string;
10
+ }
11
+ export interface JWTPayload extends AuthSession {
12
+ iat: number;
13
+ exp: number;
14
+ }
15
+ export interface Account {
16
+ provider: string;
17
+ type: 'oauth' | 'oidc' | 'credentials';
18
+ providerAccountId: string;
19
+ access_token?: string;
20
+ refresh_token?: string;
21
+ token_type?: string;
22
+ scope?: string;
23
+ id_token?: string;
24
+ }
25
+ export interface Adapter {
26
+ createUser?(user: AuthUser): Promise<AuthUser> | AuthUser;
27
+ getUser?(id: string): Promise<AuthUser | null> | AuthUser | null;
28
+ getUserByEmail?(email: string): Promise<AuthUser | null> | AuthUser | null;
29
+ getUserByAccount?(provider: string, providerAccountId: string): Promise<AuthUser | null> | AuthUser | null;
30
+ linkAccount?(userId: string, account: Account): Promise<void> | void;
31
+ }
32
+ export interface OAuthProvider {
33
+ id: string;
34
+ name: string;
35
+ type: 'oauth';
36
+ clientId: string;
37
+ clientSecret: string;
38
+ authorization: {
39
+ url: string;
40
+ params?: Record<string, string>;
41
+ };
42
+ token: string;
43
+ userinfo: string;
44
+ profile(profile: any): AuthUser | Promise<AuthUser>;
45
+ }
46
+ export interface CredentialsProvider {
47
+ id: string;
48
+ name: string;
49
+ type: 'credentials';
50
+ credentials: Record<string, {
51
+ label?: string;
52
+ type?: string;
53
+ }>;
54
+ authorize(credentials: Record<string, string>): Promise<AuthUser | null> | AuthUser | null;
55
+ }
56
+ export type AuthProvider = OAuthProvider | CredentialsProvider;
57
+ export interface AuthCallbacks {
58
+ signIn?: (params: {
59
+ user: AuthUser;
60
+ account?: Account | null;
61
+ }) => boolean | Promise<boolean>;
62
+ jwt?: (params: {
63
+ token: JWTPayload;
64
+ user?: AuthUser;
65
+ }) => JWTPayload | Promise<JWTPayload>;
66
+ session?: (params: {
67
+ session: AuthSession;
68
+ token: JWTPayload;
69
+ }) => AuthSession | Promise<AuthSession>;
70
+ redirect?: (params: {
71
+ url: string;
72
+ baseUrl: string;
73
+ }) => string | Promise<string>;
74
+ authorized?: (params: {
75
+ auth: AuthSession | null;
76
+ request: Request;
77
+ }) => boolean | Response | Promise<boolean | Response>;
78
+ }
79
+ export interface AuthConfig {
80
+ providers: AuthProvider[];
81
+ adapter?: Adapter;
82
+ secret?: string;
83
+ session?: {
84
+ strategy?: 'jwt' | 'database';
85
+ maxAge?: number;
86
+ cookieName?: string;
87
+ };
88
+ pages?: {
89
+ signIn?: string;
90
+ error?: string;
91
+ };
92
+ callbacks?: AuthCallbacks;
93
+ trustHost?: boolean;
94
+ basePath?: string;
95
+ }
96
+ export interface ResolvedAuthConfig extends AuthConfig {
97
+ secret: string;
98
+ session: {
99
+ strategy: 'jwt' | 'database';
100
+ maxAge: number;
101
+ cookieName: string;
102
+ };
103
+ basePath: string;
104
+ }
105
+ export declare function hashPassword(password: string, salt?: string): string;
106
+ export declare function verifyPassword(password: string, stored: string): boolean;
107
+ export declare function randomToken(bytes?: number): string;
108
+ export declare function encryptJwt(payload: JWTPayload, secret: string): string;
109
+ export declare function decryptJwt(token: string, secret: string): JWTPayload | null;
110
+ export declare function pkcePair(): {
111
+ verifier: string;
112
+ challenge: string;
113
+ };
114
+ export declare class MemoryAdapter implements Adapter {
115
+ users: Map<string, AuthUser>;
116
+ accounts: Map<string, string>;
117
+ createUser(user: AuthUser): AuthUser;
118
+ getUser(id: string): AuthUser | null;
119
+ getUserByEmail(email: string): AuthUser | null;
120
+ getUserByAccount(provider: string, providerAccountId: string): AuthUser | null;
121
+ linkAccount(userId: string, account: Account): void;
122
+ }
123
+ export declare function GitHub(options: {
124
+ clientId?: string;
125
+ clientSecret?: string;
126
+ }): OAuthProvider;
127
+ export declare function Google(options?: {
128
+ clientId?: string;
129
+ clientSecret?: string;
130
+ }): OAuthProvider;
131
+ export declare function Credentials(options: {
132
+ id?: string;
133
+ name?: string;
134
+ credentials?: Record<string, {
135
+ label?: string;
136
+ type?: string;
137
+ }>;
138
+ authorize: CredentialsProvider['authorize'];
139
+ }): CredentialsProvider;
140
+ export declare function resolveAuthConfig(config: AuthConfig): ResolvedAuthConfig;