authula 0.2.0
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/LICENSE +201 -0
- package/README.md +627 -0
- package/dist/fetch-B4O1awi2.js +124 -0
- package/dist/fetch-B4O1awi2.js.map +1 -0
- package/dist/fetch-q98rEoAp.cjs +159 -0
- package/dist/fetch-q98rEoAp.cjs.map +1 -0
- package/dist/index.cjs +60 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +53 -0
- package/dist/index.js.map +1 -0
- package/dist/plugins/index.cjs +388 -0
- package/dist/plugins/index.cjs.map +1 -0
- package/dist/plugins/index.d.cts +417 -0
- package/dist/plugins/index.d.ts +417 -0
- package/dist/plugins/index.js +377 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/sdk-BWoai6MP.d.ts +163 -0
- package/dist/sdk-DV73pbRH.d.cts +163 -0
- package/package.json +52 -0
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
import { r as sessionSchema, t as wrappedFetch } from "../fetch-B4O1awi2.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { parse } from "cookie";
|
|
4
|
+
|
|
5
|
+
//#region src/plugins/admin/plugin.ts
|
|
6
|
+
var AdminPlugin = class {
|
|
7
|
+
id = "admin";
|
|
8
|
+
constructor() {}
|
|
9
|
+
init(client) {
|
|
10
|
+
return {
|
|
11
|
+
createUser: async (data) => {
|
|
12
|
+
return wrappedFetch(client, "/admin/users", {
|
|
13
|
+
method: "POST",
|
|
14
|
+
body: data
|
|
15
|
+
});
|
|
16
|
+
},
|
|
17
|
+
getAllUsers: async (limit) => {
|
|
18
|
+
const urlSearchParams = new URLSearchParams();
|
|
19
|
+
if (limit) urlSearchParams.append("limit", limit.toString());
|
|
20
|
+
return wrappedFetch(client, `/admin/users${urlSearchParams.toString() ? `?${urlSearchParams.toString()}` : ""}`, { method: "GET" });
|
|
21
|
+
},
|
|
22
|
+
getUserById: async (userId) => {
|
|
23
|
+
return wrappedFetch(client, `/admin/users/${userId}`, { method: "GET" });
|
|
24
|
+
},
|
|
25
|
+
updateUser: async (userId, data) => {
|
|
26
|
+
return wrappedFetch(client, `/admin/users/${userId}`, {
|
|
27
|
+
method: "PATCH",
|
|
28
|
+
body: data
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
deleteUser: async (userId) => {
|
|
32
|
+
return wrappedFetch(client, `/admin/users/${userId}`, { method: "DELETE" });
|
|
33
|
+
},
|
|
34
|
+
createAccount: async (userId, data) => {
|
|
35
|
+
return wrappedFetch(client, `/admin/users/${userId}/accounts`, {
|
|
36
|
+
method: "POST",
|
|
37
|
+
body: data
|
|
38
|
+
});
|
|
39
|
+
},
|
|
40
|
+
getUserAccounts: async (userId) => {
|
|
41
|
+
return wrappedFetch(client, `/admin/users/${userId}/accounts`, { method: "GET" });
|
|
42
|
+
},
|
|
43
|
+
getAccountById: async (id) => {
|
|
44
|
+
return wrappedFetch(client, `/admin/accounts/${id}`, { method: "GET" });
|
|
45
|
+
},
|
|
46
|
+
updateAccount: async (id, data) => {
|
|
47
|
+
return wrappedFetch(client, `/admin/accounts/${id}`, {
|
|
48
|
+
method: "PATCH",
|
|
49
|
+
body: data
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
deleteAccount: async (id) => {
|
|
53
|
+
return wrappedFetch(client, `/admin/accounts/${id}`, { method: "DELETE" });
|
|
54
|
+
},
|
|
55
|
+
getUserState: async (userId) => {
|
|
56
|
+
return wrappedFetch(client, `/admin/users/${userId}/state`, { method: "GET" });
|
|
57
|
+
},
|
|
58
|
+
createUserState: async (userId, data) => {
|
|
59
|
+
return wrappedFetch(client, `/admin/users/${userId}/state`, {
|
|
60
|
+
method: "POST",
|
|
61
|
+
body: data
|
|
62
|
+
});
|
|
63
|
+
},
|
|
64
|
+
updateUserState: async (userId, data) => {
|
|
65
|
+
return wrappedFetch(client, `/admin/users/${userId}/state`, {
|
|
66
|
+
method: "PATCH",
|
|
67
|
+
body: data
|
|
68
|
+
});
|
|
69
|
+
},
|
|
70
|
+
deleteUserState: async (userId) => {
|
|
71
|
+
return wrappedFetch(client, `/admin/users/${userId}/state`, { method: "DELETE" });
|
|
72
|
+
},
|
|
73
|
+
getBannedUserStates: async () => {
|
|
74
|
+
return wrappedFetch(client, `/admin/users/states/banned`, { method: "GET" });
|
|
75
|
+
},
|
|
76
|
+
banUser: async (userId, data) => {
|
|
77
|
+
return wrappedFetch(client, `/admin/users/${userId}/ban`, {
|
|
78
|
+
method: "POST",
|
|
79
|
+
body: data
|
|
80
|
+
});
|
|
81
|
+
},
|
|
82
|
+
unbanUser: async (userId) => {
|
|
83
|
+
return wrappedFetch(client, `/admin/users/${userId}/unban`, { method: "POST" });
|
|
84
|
+
},
|
|
85
|
+
getUserAdminSessions: async (userId) => {
|
|
86
|
+
return wrappedFetch(client, `/admin/users/${userId}/sessions`, { method: "GET" });
|
|
87
|
+
},
|
|
88
|
+
getSessionState: async (sessionId) => {
|
|
89
|
+
return wrappedFetch(client, `/admin/sessions/${sessionId}/state`, { method: "GET" });
|
|
90
|
+
},
|
|
91
|
+
createSessionState: async (sessionId, data) => {
|
|
92
|
+
return wrappedFetch(client, `/admin/sessions/${sessionId}/state`, {
|
|
93
|
+
method: "POST",
|
|
94
|
+
body: data
|
|
95
|
+
});
|
|
96
|
+
},
|
|
97
|
+
updateSessionState: async (sessionId, data) => {
|
|
98
|
+
return wrappedFetch(client, `/admin/sessions/${sessionId}/state`, {
|
|
99
|
+
method: "PATCH",
|
|
100
|
+
body: data
|
|
101
|
+
});
|
|
102
|
+
},
|
|
103
|
+
deleteSessionState: async (sessionId) => {
|
|
104
|
+
return wrappedFetch(client, `/admin/sessions/${sessionId}/state`, { method: "DELETE" });
|
|
105
|
+
},
|
|
106
|
+
getRevokedSessionStates: async () => {
|
|
107
|
+
return wrappedFetch(client, `/admin/sessions/states/revoked`, { method: "GET" });
|
|
108
|
+
},
|
|
109
|
+
revokeSession: async (sessionId, data) => {
|
|
110
|
+
return wrappedFetch(client, `/admin/sessions/${sessionId}/revoke`, {
|
|
111
|
+
method: "POST",
|
|
112
|
+
body: data
|
|
113
|
+
});
|
|
114
|
+
},
|
|
115
|
+
getAllImpersonations: async () => {
|
|
116
|
+
return wrappedFetch(client, "/admin/impersonations", { method: "GET" });
|
|
117
|
+
},
|
|
118
|
+
getImpersonationById: async (impersonationId) => {
|
|
119
|
+
return wrappedFetch(client, `/admin/impersonations/${impersonationId}`, { method: "GET" });
|
|
120
|
+
},
|
|
121
|
+
startImpersonation: async (data) => {
|
|
122
|
+
return wrappedFetch(client, "/admin/impersonations", {
|
|
123
|
+
method: "POST",
|
|
124
|
+
body: data
|
|
125
|
+
});
|
|
126
|
+
},
|
|
127
|
+
stopImpersonation: async (impersonationId) => {
|
|
128
|
+
return wrappedFetch(client, `/admin/impersonations/${impersonationId}/stop`, { method: "POST" });
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
//#endregion
|
|
135
|
+
//#region src/plugins/admin/types.ts
|
|
136
|
+
const adminUserStateSchema = z.object({
|
|
137
|
+
userId: z.string().nonempty(),
|
|
138
|
+
isBanned: z.boolean(),
|
|
139
|
+
bannedAt: z.iso.datetime().nullable(),
|
|
140
|
+
bannedUntil: z.iso.datetime().nullable(),
|
|
141
|
+
bannedReason: z.string().nullable(),
|
|
142
|
+
bannedByUserId: z.string().nullable(),
|
|
143
|
+
createdAt: z.iso.datetime(),
|
|
144
|
+
updatedAt: z.iso.datetime()
|
|
145
|
+
});
|
|
146
|
+
const adminSessionStateSchema = z.object({
|
|
147
|
+
sessionId: z.string().nonempty(),
|
|
148
|
+
revokedAt: z.iso.datetime().nullable(),
|
|
149
|
+
revokedReason: z.string().nullable(),
|
|
150
|
+
revokedByUserId: z.string().nullable(),
|
|
151
|
+
impersonatorUserId: z.string().nullable(),
|
|
152
|
+
impersonationReason: z.string().nullable(),
|
|
153
|
+
impersonationExpiresAt: z.iso.datetime().nullable(),
|
|
154
|
+
createdAt: z.iso.datetime(),
|
|
155
|
+
updatedAt: z.iso.datetime()
|
|
156
|
+
});
|
|
157
|
+
const adminUserSessionSchema = z.object({
|
|
158
|
+
session: sessionSchema,
|
|
159
|
+
state: adminSessionStateSchema.nullable()
|
|
160
|
+
});
|
|
161
|
+
const impersonationSchema = z.object({
|
|
162
|
+
id: z.string().nonempty(),
|
|
163
|
+
actorUserId: z.string().nonempty(),
|
|
164
|
+
targetUserId: z.string().nonempty(),
|
|
165
|
+
actorSessionId: z.string().nullable(),
|
|
166
|
+
impersonationSessionId: z.string().nullable(),
|
|
167
|
+
reason: z.string().nonempty(),
|
|
168
|
+
startedAt: z.iso.datetime(),
|
|
169
|
+
expiresAt: z.iso.datetime(),
|
|
170
|
+
endedAt: z.iso.datetime().nullable(),
|
|
171
|
+
endedByUserId: z.string().nullable(),
|
|
172
|
+
createdAt: z.iso.datetime(),
|
|
173
|
+
updatedAt: z.iso.datetime()
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
//#endregion
|
|
177
|
+
//#region src/plugins/bearer/plugin.ts
|
|
178
|
+
var BearerPlugin = class {
|
|
179
|
+
id = "bearer";
|
|
180
|
+
refreshPromise = null;
|
|
181
|
+
constructor(options) {
|
|
182
|
+
this.options = options;
|
|
183
|
+
}
|
|
184
|
+
init(client) {
|
|
185
|
+
client.registerBeforeFetch(async (ctx) => {
|
|
186
|
+
if (typeof document === "undefined") return;
|
|
187
|
+
const headerName = this.options?.headerName ?? "Authorization";
|
|
188
|
+
const token = localStorage.getItem("accessToken");
|
|
189
|
+
if (token) ctx.init.headers = {
|
|
190
|
+
...ctx.init.headers,
|
|
191
|
+
[headerName]: `Bearer ${token}`
|
|
192
|
+
};
|
|
193
|
+
});
|
|
194
|
+
client.registerAfterFetch(async (ctx, res) => {
|
|
195
|
+
if (typeof document === "undefined") return;
|
|
196
|
+
if (res.status !== 401) return;
|
|
197
|
+
if (ctx.meta.retry) return;
|
|
198
|
+
const refreshToken = localStorage.getItem("refreshToken");
|
|
199
|
+
if (!refreshToken) return;
|
|
200
|
+
if (!client.jwt) {
|
|
201
|
+
console.warn("JWT Plugin is required for Bearer token refresh.");
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
if (!this.refreshPromise) this.refreshPromise = (async () => {
|
|
205
|
+
try {
|
|
206
|
+
const response = await client.jwt.refreshToken({ refreshToken });
|
|
207
|
+
if (!response) return null;
|
|
208
|
+
localStorage.setItem("accessToken", response.accessToken);
|
|
209
|
+
localStorage.setItem("refreshToken", response.refreshToken);
|
|
210
|
+
return response;
|
|
211
|
+
} finally {
|
|
212
|
+
this.refreshPromise = null;
|
|
213
|
+
}
|
|
214
|
+
})();
|
|
215
|
+
const refreshed = await this.refreshPromise;
|
|
216
|
+
if (!refreshed) return;
|
|
217
|
+
const headerName = this.options?.headerName ?? "Authorization";
|
|
218
|
+
ctx.init.headers = {
|
|
219
|
+
...ctx.init.headers,
|
|
220
|
+
[headerName]: `Bearer ${refreshed.accessToken}`
|
|
221
|
+
};
|
|
222
|
+
return "retry";
|
|
223
|
+
});
|
|
224
|
+
return {};
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
//#endregion
|
|
229
|
+
//#region src/plugins/csrf/plugin.ts
|
|
230
|
+
var CSRFPlugin = class {
|
|
231
|
+
id = "csrf";
|
|
232
|
+
constructor(options) {
|
|
233
|
+
this.options = options;
|
|
234
|
+
}
|
|
235
|
+
init(client) {
|
|
236
|
+
client.registerBeforeFetch(async (ctx) => {
|
|
237
|
+
if (typeof document !== "undefined") {
|
|
238
|
+
if ([
|
|
239
|
+
"OPTIONS",
|
|
240
|
+
"HEAD",
|
|
241
|
+
"GET"
|
|
242
|
+
].includes(ctx.init.method || "GET")) return;
|
|
243
|
+
const value = parse(document.cookie)[this.options.cookieName];
|
|
244
|
+
if (!value) return;
|
|
245
|
+
ctx.init.headers = new Headers(ctx.init.headers);
|
|
246
|
+
ctx.init.headers.set(this.options.headerName, value);
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
if (this.cookies) {
|
|
250
|
+
if ([
|
|
251
|
+
"OPTIONS",
|
|
252
|
+
"HEAD",
|
|
253
|
+
"GET"
|
|
254
|
+
].includes(ctx.init.method || "GET")) return;
|
|
255
|
+
const cookie = (await this.cookies()).get(this.options.cookieName);
|
|
256
|
+
if (!cookie) return;
|
|
257
|
+
ctx.init.headers = new Headers(ctx.init.headers);
|
|
258
|
+
ctx.init.headers.set(this.options.headerName, cookie.value);
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
return {};
|
|
262
|
+
}
|
|
263
|
+
cookies;
|
|
264
|
+
attachCookies(fn) {
|
|
265
|
+
this.cookies = fn;
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
//#endregion
|
|
270
|
+
//#region src/plugins/email-password/plugin.ts
|
|
271
|
+
var EmailPasswordPlugin = class {
|
|
272
|
+
id = "emailPassword";
|
|
273
|
+
init(client) {
|
|
274
|
+
return {
|
|
275
|
+
signUp: async (data) => {
|
|
276
|
+
return wrappedFetch(client, "/sign-up", {
|
|
277
|
+
method: "POST",
|
|
278
|
+
body: data
|
|
279
|
+
});
|
|
280
|
+
},
|
|
281
|
+
signIn: async (data) => {
|
|
282
|
+
return wrappedFetch(client, "/sign-in", {
|
|
283
|
+
method: "POST",
|
|
284
|
+
body: data
|
|
285
|
+
});
|
|
286
|
+
},
|
|
287
|
+
sendEmailVerification: async (data) => {
|
|
288
|
+
return wrappedFetch(client, `/send-email-verification`, {
|
|
289
|
+
method: "POST",
|
|
290
|
+
body: data
|
|
291
|
+
});
|
|
292
|
+
},
|
|
293
|
+
requestPasswordReset: async (data) => {
|
|
294
|
+
return wrappedFetch(client, `/request-password-reset`, {
|
|
295
|
+
method: "POST",
|
|
296
|
+
body: data
|
|
297
|
+
});
|
|
298
|
+
},
|
|
299
|
+
changePassword: async (data) => {
|
|
300
|
+
return wrappedFetch(client, `/change-password`, {
|
|
301
|
+
method: "POST",
|
|
302
|
+
body: data
|
|
303
|
+
});
|
|
304
|
+
},
|
|
305
|
+
requestEmailChange: async (data) => {
|
|
306
|
+
return wrappedFetch(client, `/request-email-change`, {
|
|
307
|
+
method: "POST",
|
|
308
|
+
body: data
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
//#endregion
|
|
316
|
+
//#region src/plugins/jwt/plugin.ts
|
|
317
|
+
var JWTPlugin = class {
|
|
318
|
+
id = "jwt";
|
|
319
|
+
constructor() {}
|
|
320
|
+
init(client) {
|
|
321
|
+
return {
|
|
322
|
+
refreshToken: async (data) => {
|
|
323
|
+
return wrappedFetch(client, "/token/refresh", {
|
|
324
|
+
method: "POST",
|
|
325
|
+
body: data
|
|
326
|
+
});
|
|
327
|
+
},
|
|
328
|
+
getJWKSKeys: async () => {
|
|
329
|
+
return wrappedFetch(client, "/.well-known/jwks.json", { method: "GET" });
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
//#endregion
|
|
336
|
+
//#region src/plugins/magic-link/plugin.ts
|
|
337
|
+
var MagicLinkPlugin = class {
|
|
338
|
+
id = "magicLink";
|
|
339
|
+
constructor() {}
|
|
340
|
+
init(client) {
|
|
341
|
+
return {
|
|
342
|
+
signIn: async (data) => {
|
|
343
|
+
return wrappedFetch(client, "/magic-link/sign-in", {
|
|
344
|
+
method: "POST",
|
|
345
|
+
body: data
|
|
346
|
+
});
|
|
347
|
+
},
|
|
348
|
+
verify: async (data) => {
|
|
349
|
+
const searchParams = new URLSearchParams();
|
|
350
|
+
searchParams.append("token", data.token);
|
|
351
|
+
if (data.callbackUrl) searchParams.append("callback_url", data.callbackUrl);
|
|
352
|
+
return wrappedFetch(client, `/magic-link/verify?${searchParams.toString()}`, { method: "GET" });
|
|
353
|
+
},
|
|
354
|
+
exchange: async (data) => {
|
|
355
|
+
return wrappedFetch(client, "/magic-link/exchange", {
|
|
356
|
+
method: "POST",
|
|
357
|
+
body: data
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
//#endregion
|
|
365
|
+
//#region src/plugins/oauth2/plugin.ts
|
|
366
|
+
var OAuth2Plugin = class {
|
|
367
|
+
id = "oauth2";
|
|
368
|
+
init(client) {
|
|
369
|
+
return { signIn: async (data) => {
|
|
370
|
+
return wrappedFetch(client, `/oauth2/authorize/${data.provider}?redirect_to=${data.redirectTo}`, { method: "GET" });
|
|
371
|
+
} };
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
//#endregion
|
|
376
|
+
export { AdminPlugin, BearerPlugin, CSRFPlugin, EmailPasswordPlugin, JWTPlugin, MagicLinkPlugin, OAuth2Plugin, adminSessionStateSchema, adminUserSessionSchema, adminUserStateSchema, impersonationSchema };
|
|
377
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/plugins/admin/plugin.ts","../../src/plugins/admin/types.ts","../../src/plugins/bearer/plugin.ts","../../src/plugins/csrf/plugin.ts","../../src/plugins/email-password/plugin.ts","../../src/plugins/jwt/plugin.ts","../../src/plugins/magic-link/plugin.ts","../../src/plugins/oauth2/plugin.ts"],"sourcesContent":["import type { AuthulaClient } from \"@/client\";\nimport { wrappedFetch } from \"@/fetch\";\nimport type { Plugin } from \"@/types\";\nimport type {\n BanUserRequest,\n BanUserResponse,\n CreateUserRequest,\n CreateUserResponse,\n DeleteSessionStateResponse,\n DeleteUserStateResponse,\n StopImpersonationResponse,\n GetAllImpersonationsResponse,\n GetAllUsersResponse,\n GetBannedUserStatesResponse,\n GetImpersonationByIdResponse,\n GetRevokedSessionStatesResponse,\n GetSessionStateResponse,\n GetUserAdminSessionsResponse,\n GetUserByIdResponse,\n GetUserStateResponse,\n RevokeSessionRequest,\n RevokeSessionResponse,\n StartImpersonationRequest,\n StartImpersonationResponse,\n UnbanUserResponse,\n UpdateUserRequest,\n UpdateUserResponse,\n DeleteUserResponse,\n CreateAccountRequest,\n CreateAccountResponse,\n GetUserAccountsResponse,\n GetAccountByIdResponse,\n UpdateAccountRequest,\n UpdateAccountResponse,\n DeleteAccountResponse,\n CreateUserStateRequest,\n CreateUserStateResponse,\n UpdateUserStateRequest,\n UpdateUserStateResponse,\n CreateSessionStateRequest,\n CreateSessionStateResponse,\n UpdateSessionStateRequest,\n UpdateSessionStateResponse,\n} from \"./types\";\n\nexport class AdminPlugin implements Plugin {\n public readonly id = \"admin\";\n\n constructor() {}\n\n public init(client: AuthulaClient) {\n return {\n // User management\n\n createUser: async (\n data: CreateUserRequest,\n ): Promise<CreateUserResponse> => {\n return wrappedFetch(client, \"/admin/users\", {\n method: \"POST\",\n body: data,\n });\n },\n getAllUsers: async (limit?: number): Promise<GetAllUsersResponse> => {\n const urlSearchParams = new URLSearchParams();\n if (limit) {\n urlSearchParams.append(\"limit\", limit.toString());\n }\n const params = urlSearchParams.toString()\n ? `?${urlSearchParams.toString()}`\n : \"\";\n return wrappedFetch(client, `/admin/users${params}`, {\n method: \"GET\",\n });\n },\n getUserById: async (userId: string): Promise<GetUserByIdResponse> => {\n return wrappedFetch(client, `/admin/users/${userId}`, {\n method: \"GET\",\n });\n },\n updateUser: async (\n userId: string,\n data: UpdateUserRequest,\n ): Promise<UpdateUserResponse> => {\n return wrappedFetch(client, `/admin/users/${userId}`, {\n method: \"PATCH\",\n body: data,\n });\n },\n deleteUser: async (userId: string): Promise<DeleteUserResponse> => {\n return wrappedFetch(client, `/admin/users/${userId}`, {\n method: \"DELETE\",\n });\n },\n\n // Account management\n\n createAccount: async (\n userId: string,\n data: CreateAccountRequest,\n ): Promise<CreateAccountResponse> => {\n return wrappedFetch(client, `/admin/users/${userId}/accounts`, {\n method: \"POST\",\n body: data,\n });\n },\n getUserAccounts: async (\n userId: string,\n ): Promise<GetUserAccountsResponse> => {\n return wrappedFetch(client, `/admin/users/${userId}/accounts`, {\n method: \"GET\",\n });\n },\n getAccountById: async (id: string): Promise<GetAccountByIdResponse> => {\n return wrappedFetch(client, `/admin/accounts/${id}`, {\n method: \"GET\",\n });\n },\n updateAccount: async (\n id: string,\n data: UpdateAccountRequest,\n ): Promise<UpdateAccountResponse> => {\n return wrappedFetch(client, `/admin/accounts/${id}`, {\n method: \"PATCH\",\n body: data,\n });\n },\n deleteAccount: async (id: string): Promise<DeleteAccountResponse> => {\n return wrappedFetch(client, `/admin/accounts/${id}`, {\n method: \"DELETE\",\n });\n },\n\n // User state management\n\n getUserState: async (userId: string): Promise<GetUserStateResponse> => {\n return wrappedFetch(client, `/admin/users/${userId}/state`, {\n method: \"GET\",\n });\n },\n createUserState: async (\n userId: string,\n data: CreateUserStateRequest,\n ): Promise<CreateUserStateResponse> => {\n return wrappedFetch(client, `/admin/users/${userId}/state`, {\n method: \"POST\",\n body: data,\n });\n },\n updateUserState: async (\n userId: string,\n data: UpdateUserStateRequest,\n ): Promise<UpdateUserStateResponse> => {\n return wrappedFetch(client, `/admin/users/${userId}/state`, {\n method: \"PATCH\",\n body: data,\n });\n },\n deleteUserState: async (\n userId: string,\n ): Promise<DeleteUserStateResponse> => {\n return wrappedFetch(client, `/admin/users/${userId}/state`, {\n method: \"DELETE\",\n });\n },\n getBannedUserStates: async (): Promise<GetBannedUserStatesResponse> => {\n return wrappedFetch(client, `/admin/users/states/banned`, {\n method: \"GET\",\n });\n },\n banUser: async (\n userId: string,\n data: BanUserRequest,\n ): Promise<BanUserResponse> => {\n return wrappedFetch(client, `/admin/users/${userId}/ban`, {\n method: \"POST\",\n body: data,\n });\n },\n unbanUser: async (userId: string): Promise<UnbanUserResponse> => {\n return wrappedFetch(client, `/admin/users/${userId}/unban`, {\n method: \"POST\",\n });\n },\n getUserAdminSessions: async (\n userId: string,\n ): Promise<GetUserAdminSessionsResponse> => {\n return wrappedFetch(client, `/admin/users/${userId}/sessions`, {\n method: \"GET\",\n });\n },\n\n // Session state management\n\n getSessionState: async (\n sessionId: string,\n ): Promise<GetSessionStateResponse> => {\n return wrappedFetch(client, `/admin/sessions/${sessionId}/state`, {\n method: \"GET\",\n });\n },\n createSessionState: async (\n sessionId: string,\n data: CreateSessionStateRequest,\n ): Promise<CreateSessionStateResponse> => {\n return wrappedFetch(client, `/admin/sessions/${sessionId}/state`, {\n method: \"POST\",\n body: data,\n });\n },\n updateSessionState: async (\n sessionId: string,\n data: UpdateSessionStateRequest,\n ): Promise<UpdateSessionStateResponse> => {\n return wrappedFetch(client, `/admin/sessions/${sessionId}/state`, {\n method: \"PATCH\",\n body: data,\n });\n },\n deleteSessionState: async (\n sessionId: string,\n ): Promise<DeleteSessionStateResponse> => {\n return wrappedFetch(client, `/admin/sessions/${sessionId}/state`, {\n method: \"DELETE\",\n });\n },\n getRevokedSessionStates:\n async (): Promise<GetRevokedSessionStatesResponse> => {\n return wrappedFetch(client, `/admin/sessions/states/revoked`, {\n method: \"GET\",\n });\n },\n revokeSession: async (\n sessionId: string,\n data: RevokeSessionRequest,\n ): Promise<RevokeSessionResponse> => {\n return wrappedFetch(client, `/admin/sessions/${sessionId}/revoke`, {\n method: \"POST\",\n body: data,\n });\n },\n\n // Impersonations\n\n getAllImpersonations: async (): Promise<GetAllImpersonationsResponse> => {\n return wrappedFetch(client, \"/admin/impersonations\", {\n method: \"GET\",\n });\n },\n getImpersonationById: async (\n impersonationId: string,\n ): Promise<GetImpersonationByIdResponse> => {\n return wrappedFetch(\n client,\n `/admin/impersonations/${impersonationId}`,\n {\n method: \"GET\",\n },\n );\n },\n startImpersonation: async (\n data: StartImpersonationRequest,\n ): Promise<StartImpersonationResponse> => {\n return wrappedFetch(client, \"/admin/impersonations\", {\n method: \"POST\",\n body: data,\n });\n },\n stopImpersonation: async (\n impersonationId: string,\n ): Promise<StopImpersonationResponse> => {\n return wrappedFetch(\n client,\n `/admin/impersonations/${impersonationId}/stop`,\n {\n method: \"POST\",\n },\n );\n },\n };\n }\n}\n","import { z } from \"zod\";\n\nimport { sessionSchema, type Account, type User } from \"@/types\";\n\n// ------------------------------\n// SCHEMAS\n// ------------------------------\n\nexport const adminUserStateSchema = z.object({\n userId: z.string().nonempty(),\n isBanned: z.boolean(),\n bannedAt: z.iso.datetime().nullable(),\n bannedUntil: z.iso.datetime().nullable(),\n bannedReason: z.string().nullable(),\n bannedByUserId: z.string().nullable(),\n createdAt: z.iso.datetime(),\n updatedAt: z.iso.datetime(),\n});\nexport type AdminUserState = z.infer<typeof adminUserStateSchema>;\n\nexport const adminSessionStateSchema = z.object({\n sessionId: z.string().nonempty(),\n revokedAt: z.iso.datetime().nullable(),\n revokedReason: z.string().nullable(),\n revokedByUserId: z.string().nullable(),\n impersonatorUserId: z.string().nullable(),\n impersonationReason: z.string().nullable(),\n impersonationExpiresAt: z.iso.datetime().nullable(),\n createdAt: z.iso.datetime(),\n updatedAt: z.iso.datetime(),\n});\nexport type AdminSessionState = z.infer<typeof adminSessionStateSchema>;\n\nexport const adminUserSessionSchema = z.object({\n session: sessionSchema,\n state: adminSessionStateSchema.nullable(),\n});\nexport type AdminUserSession = z.infer<typeof adminUserSessionSchema>;\n\nexport const impersonationSchema = z.object({\n id: z.string().nonempty(),\n actorUserId: z.string().nonempty(),\n targetUserId: z.string().nonempty(),\n actorSessionId: z.string().nullable(),\n impersonationSessionId: z.string().nullable(),\n reason: z.string().nonempty(),\n startedAt: z.iso.datetime(),\n expiresAt: z.iso.datetime(),\n endedAt: z.iso.datetime().nullable(),\n endedByUserId: z.string().nullable(),\n createdAt: z.iso.datetime(),\n updatedAt: z.iso.datetime(),\n});\nexport type Impersonation = z.infer<typeof impersonationSchema>;\n\n// ------------------------------\n// API response types\n// ------------------------------\n\n// User management\n\nexport type CreateUserRequest = {\n name: string;\n email: string;\n emailVerified?: boolean;\n image?: string;\n metadata?: Record<string, unknown>;\n};\n\nexport type CreateUserResponse = {\n user: User;\n};\n\nexport type GetAllUsersResponse = {\n users: Array<User>;\n nextCursor?: string | null;\n};\n\nexport type GetUserByIdResponse = {\n user: User;\n};\n\nexport type UpdateUserRequest = {\n name?: string;\n email?: string;\n emailVerified?: boolean;\n image?: string;\n metadata?: Record<string, unknown>;\n};\n\nexport type UpdateUserResponse = {\n user: User;\n};\n\nexport type DeleteUserResponse = {\n message: string;\n};\n\n// Account management\n\nexport type CreateAccountRequest = {\n providerId: string;\n accountId: string;\n accessToken?: string;\n refreshToken?: string;\n idToken?: string;\n accessTokenExpiresAt?: string;\n refreshTokenExpiresAt?: string;\n scope?: string;\n password?: string;\n};\n\nexport type CreateAccountResponse = {\n account: Account;\n};\n\nexport type GetUserAccountsResponse = {\n accounts: Array<Account>;\n};\n\nexport type GetAccountByIdResponse = {\n account: Account;\n};\n\nexport type UpdateAccountRequest = {\n providerId?: string;\n accountId?: string;\n accessToken?: string;\n refreshToken?: string;\n idToken?: string;\n accessTokenExpiresAt?: string;\n refreshTokenExpiresAt?: string;\n scope?: string;\n password?: string;\n};\n\nexport type UpdateAccountResponse = {\n account: Account;\n};\n\nexport type DeleteAccountResponse = {\n message: string;\n};\n\n// User state management\n\nexport type GetUserStateResponse = {\n state: AdminUserState;\n};\n\nexport type CreateUserStateRequest = {\n banned: boolean;\n bannedUntil?: string;\n bannedReason?: string;\n};\n\nexport type UpdateUserStateRequest = {\n banned: boolean;\n bannedUntil?: string;\n bannedReason?: string;\n};\n\nexport type CreateUserStateResponse = {\n userState: AdminUserState;\n};\n\nexport type UpdateUserStateResponse = {\n userState: AdminUserState;\n};\n\nexport type DeleteUserStateResponse = {\n message: string;\n};\n\nexport type GetBannedUserStatesResponse = Array<AdminUserState>;\n\nexport type BanUserRequest = {\n bannedUntil?: string;\n reason?: string;\n};\n\nexport type BanUserResponse = {\n state: AdminUserState;\n};\n\nexport type UnbanUserResponse = {\n state: AdminUserState;\n};\n\nexport type GetUserAdminSessionsResponse = Array<AdminUserSession>;\n\n// Session state management\n\nexport type GetSessionStateResponse = {\n state: AdminSessionState;\n};\n\nexport type CreateSessionStateRequest = {\n revoke: boolean;\n revokedReason?: string;\n impersonatorUserId?: string;\n impersonationReason?: string;\n impersonationExpiresAt?: string;\n};\n\nexport type UpdateSessionStateRequest = {\n revoke: boolean;\n revokedReason?: string;\n impersonatorUserId?: string;\n impersonationReason?: string;\n impersonationExpiresAt?: string;\n};\n\nexport type CreateSessionStateResponse = {\n state: AdminSessionState;\n};\n\nexport type UpdateSessionStateResponse = {\n state: AdminSessionState;\n};\n\nexport type DeleteSessionStateResponse = {\n message: string;\n};\n\nexport type GetRevokedSessionStatesResponse = Array<AdminSessionState>;\n\nexport type RevokeSessionRequest = {\n reason?: string;\n};\n\nexport type RevokeSessionResponse = {\n sessionState: AdminSessionState;\n};\n\n// Impersonation\n\nexport type GetAllImpersonationsResponse = Array<Impersonation>;\n\nexport type GetImpersonationByIdResponse = {\n impersonation: Impersonation;\n};\n\nexport type StartImpersonationRequest = {\n targetUserId: string;\n reason: string;\n expiresInSeconds?: number;\n};\n\nexport type StartImpersonationResponse = {\n impersonation: Impersonation;\n};\n\nexport type StopImpersonationResponse = {\n message: string;\n};\n","import type { FetchContext, Plugin } from \"@/types\";\nimport type { BearerPluginOptions } from \"./types\";\nimport type { JWTPlugin } from \"../jwt/plugin\";\nimport type { ClientWithPlugins } from \"@/sdk\";\n\nexport class BearerPlugin implements Plugin {\n public readonly id = \"bearer\";\n private refreshPromise: Promise<any> | null = null;\n\n constructor(private readonly options?: BearerPluginOptions) {}\n\n public init(client: ClientWithPlugins<[JWTPlugin]>) {\n client.registerBeforeFetch(async (ctx: FetchContext) => {\n if (typeof document === \"undefined\") {\n return;\n }\n\n const headerName = this.options?.headerName ?? \"Authorization\";\n const token = localStorage.getItem(\"accessToken\");\n if (token) {\n ctx.init.headers = {\n ...ctx.init.headers,\n [headerName]: `Bearer ${token}`,\n };\n }\n });\n\n client.registerAfterFetch(async (ctx: FetchContext, res: Response) => {\n if (typeof document === \"undefined\") {\n return;\n }\n if (res.status !== 401) {\n return;\n }\n if (ctx.meta.retry) {\n return;\n }\n\n const refreshToken = localStorage.getItem(\"refreshToken\");\n if (!refreshToken) {\n return;\n }\n\n if (!client.jwt) {\n console.warn(\"JWT Plugin is required for Bearer token refresh.\");\n return;\n }\n\n // 🔒 SINGLE FLIGHT REFRESH\n if (!this.refreshPromise) {\n this.refreshPromise = (async () => {\n try {\n const response = await client.jwt.refreshToken({\n refreshToken: refreshToken,\n });\n if (!response) {\n return null;\n }\n\n localStorage.setItem(\"accessToken\", response.accessToken);\n localStorage.setItem(\"refreshToken\", response.refreshToken);\n\n return response;\n } finally {\n this.refreshPromise = null;\n }\n })();\n }\n\n const refreshed = await this.refreshPromise;\n if (!refreshed) {\n return;\n }\n\n const headerName = this.options?.headerName ?? \"Authorization\";\n ctx.init.headers = {\n ...ctx.init.headers,\n [headerName]: `Bearer ${refreshed.accessToken}`,\n };\n\n return \"retry\";\n });\n\n return {};\n }\n}\n","import { parse } from \"cookie\";\n\nimport type { FetchContext, Plugin } from \"@/types\";\nimport type { CSRFPluginOptions } from \"./types\";\nimport type { AuthulaClient } from \"@/client\";\n\nexport class CSRFPlugin implements Plugin {\n public readonly id = \"csrf\";\n\n constructor(private readonly options: CSRFPluginOptions) {}\n\n public init(client: AuthulaClient) {\n client.registerBeforeFetch(async (ctx: FetchContext) => {\n // Client-side\n if (typeof document !== \"undefined\") {\n if ([\"OPTIONS\", \"HEAD\", \"GET\"].includes(ctx.init.method || \"GET\")) {\n return;\n }\n\n const cookies = parse(document.cookie);\n const value = cookies[this.options.cookieName];\n\n if (!value) return;\n\n ctx.init.headers = new Headers(ctx.init.headers);\n ctx.init.headers.set(this.options.headerName, value);\n return;\n }\n\n // SSR\n if (this.cookies) {\n if ([\"OPTIONS\", \"HEAD\", \"GET\"].includes(ctx.init.method || \"GET\")) {\n return;\n }\n\n const store = await this.cookies();\n const cookie = store.get(this.options.cookieName);\n\n if (!cookie) return;\n\n ctx.init.headers = new Headers(ctx.init.headers);\n ctx.init.headers.set(this.options.headerName, cookie.value);\n }\n });\n\n return {};\n }\n\n // Injected by client\n private cookies?: () => Promise<any>;\n attachCookies(fn: () => Promise<any>) {\n this.cookies = fn;\n }\n}\n","import type { AuthulaClient } from \"@/client\";\nimport { wrappedFetch } from \"@/fetch\";\nimport type { Plugin } from \"@/types\";\nimport type {\n ChangePasswordRequest,\n RequestEmailChangeRequest,\n RequestPasswordResetRequest,\n SendEmailVerificationRequest,\n SignInRequest,\n SignUpRequest,\n} from \"./types\";\n\nexport class EmailPasswordPlugin implements Plugin {\n public readonly id = \"emailPassword\";\n\n public init(client: AuthulaClient) {\n return {\n signUp: async <T>(data: SignUpRequest): Promise<T> => {\n return wrappedFetch<T>(client, \"/sign-up\", {\n method: \"POST\",\n body: data,\n });\n },\n signIn: async <T>(data: SignInRequest): Promise<T> => {\n return wrappedFetch<T>(client, \"/sign-in\", {\n method: \"POST\",\n body: data,\n });\n },\n sendEmailVerification: async (\n data: SendEmailVerificationRequest,\n ): Promise<void> => {\n return wrappedFetch(client, `/send-email-verification`, {\n method: \"POST\",\n body: data,\n });\n },\n requestPasswordReset: async (\n data: RequestPasswordResetRequest,\n ): Promise<void> => {\n return wrappedFetch(client, `/request-password-reset`, {\n method: \"POST\",\n body: data,\n });\n },\n changePassword: async (data: ChangePasswordRequest): Promise<void> => {\n return wrappedFetch(client, `/change-password`, {\n method: \"POST\",\n body: data,\n });\n },\n requestEmailChange: async (\n data: RequestEmailChangeRequest,\n ): Promise<void> => {\n return wrappedFetch(client, `/request-email-change`, {\n method: \"POST\",\n body: data,\n });\n },\n };\n }\n}\n","import type { AuthulaClient } from \"@/client\";\nimport { wrappedFetch } from \"@/fetch\";\nimport type { Plugin } from \"@/types\";\nimport type {\n JWKSKey,\n TokenRefreshRequest,\n TokenRefreshResponse,\n} from \"./types\";\n\nexport class JWTPlugin implements Plugin {\n public readonly id = \"jwt\";\n\n constructor() {}\n\n public init(client: AuthulaClient) {\n return {\n refreshToken: async (\n data: TokenRefreshRequest,\n ): Promise<TokenRefreshResponse> => {\n return wrappedFetch(client, \"/token/refresh\", {\n method: \"POST\",\n body: data,\n });\n },\n getJWKSKeys: async (): Promise<Array<JWKSKey>> => {\n return wrappedFetch(client, \"/.well-known/jwks.json\", {\n method: \"GET\",\n });\n },\n };\n }\n}\n","import type { AuthulaClient } from \"@/client\";\nimport { wrappedFetch } from \"@/fetch\";\nimport type { Plugin } from \"@/types\";\nimport type {\n MagicLinkSignInRequest,\n MagicLinkSignInResponse,\n MagicLinkExchangeRequest,\n MagicLinkVerifyRequest,\n MagicLinkVerifyResponse,\n} from \"./types\";\n\nexport class MagicLinkPlugin implements Plugin {\n public readonly id = \"magicLink\";\n\n constructor() {}\n\n public init(client: AuthulaClient) {\n return {\n signIn: async (\n data: MagicLinkSignInRequest,\n ): Promise<MagicLinkSignInResponse> => {\n return wrappedFetch(client, \"/magic-link/sign-in\", {\n method: \"POST\",\n body: data,\n });\n },\n verify: async (\n data: MagicLinkVerifyRequest,\n ): Promise<MagicLinkVerifyResponse> => {\n const searchParams = new URLSearchParams();\n searchParams.append(\"token\", data.token);\n if (data.callbackUrl) {\n searchParams.append(\"callback_url\", data.callbackUrl);\n }\n return wrappedFetch(\n client,\n `/magic-link/verify?${searchParams.toString()}`,\n {\n method: \"GET\",\n },\n );\n },\n exchange: async <T>(data: MagicLinkExchangeRequest): Promise<T> => {\n return wrappedFetch(client, \"/magic-link/exchange\", {\n method: \"POST\",\n body: data,\n });\n },\n };\n }\n}\n","import type { AuthulaClient } from \"@/client\";\nimport { wrappedFetch } from \"@/fetch\";\nimport type { Plugin } from \"@/types/plugins\";\nimport type {\n SignInWithOAuth2Request,\n SignInWithOAuth2Response,\n} from \"./types\";\n\nexport class OAuth2Plugin implements Plugin {\n public readonly id = \"oauth2\";\n\n public init(client: AuthulaClient) {\n return {\n signIn: async (\n data: SignInWithOAuth2Request,\n ): Promise<SignInWithOAuth2Response> => {\n return wrappedFetch(\n client,\n `/oauth2/authorize/${data.provider}?redirect_to=${data.redirectTo}`,\n {\n method: \"GET\",\n },\n );\n },\n };\n }\n}\n"],"mappings":";;;;;AA6CA,IAAa,cAAb,MAA2C;CACzC,AAAgB,KAAK;CAErB,cAAc;CAEd,AAAO,KAAK,QAAuB;AACjC,SAAO;GAGL,YAAY,OACV,SACgC;AAChC,WAAO,aAAa,QAAQ,gBAAgB;KAC1C,QAAQ;KACR,MAAM;KACP,CAAC;;GAEJ,aAAa,OAAO,UAAiD;IACnE,MAAM,kBAAkB,IAAI,iBAAiB;AAC7C,QAAI,MACF,iBAAgB,OAAO,SAAS,MAAM,UAAU,CAAC;AAKnD,WAAO,aAAa,QAAQ,eAHb,gBAAgB,UAAU,GACrC,IAAI,gBAAgB,UAAU,KAC9B,MACiD,EACnD,QAAQ,OACT,CAAC;;GAEJ,aAAa,OAAO,WAAiD;AACnE,WAAO,aAAa,QAAQ,gBAAgB,UAAU,EACpD,QAAQ,OACT,CAAC;;GAEJ,YAAY,OACV,QACA,SACgC;AAChC,WAAO,aAAa,QAAQ,gBAAgB,UAAU;KACpD,QAAQ;KACR,MAAM;KACP,CAAC;;GAEJ,YAAY,OAAO,WAAgD;AACjE,WAAO,aAAa,QAAQ,gBAAgB,UAAU,EACpD,QAAQ,UACT,CAAC;;GAKJ,eAAe,OACb,QACA,SACmC;AACnC,WAAO,aAAa,QAAQ,gBAAgB,OAAO,YAAY;KAC7D,QAAQ;KACR,MAAM;KACP,CAAC;;GAEJ,iBAAiB,OACf,WACqC;AACrC,WAAO,aAAa,QAAQ,gBAAgB,OAAO,YAAY,EAC7D,QAAQ,OACT,CAAC;;GAEJ,gBAAgB,OAAO,OAAgD;AACrE,WAAO,aAAa,QAAQ,mBAAmB,MAAM,EACnD,QAAQ,OACT,CAAC;;GAEJ,eAAe,OACb,IACA,SACmC;AACnC,WAAO,aAAa,QAAQ,mBAAmB,MA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,kBAAb,MAA+C;CAC7C,AAAgB,KAAK;CAErB,cAAc;CAEd,AAAO,KAAK,QAAuB;AACjC,SAAO;GACL,QAAQ,OACN,SACqC;AACrC,WAAO,aAAa,QAAQ,uBAAuB;KACjD,QAAQ;KACR,MAAM;KACP,CAAC;;GAEJ,QAAQ,OACN,SACqC;IACrC,MAAM,eAAe,IAAI,iBAAiB;AAC1C,iBAAa,OAAO,SAAS,KAAK,MAAM;AACxC,QAAI,KAAK,YACP,cAAa,OAAO,gBAAgB,KAAK,YAAY;AAEvD,WAAO,aACL,QACA,sBAAsB,aAAa,UAAU,IAC7C,EACE,QAAQ,OACT,CACF;;GAEH,UAAU,OAAU,SAA+C;AACjE,WAAO,aAAa,QAAQ,wBAAwB;KAClD,QAAQ;KACR,MAAM;KACP,CAAC;;GAEL;;;;;;ACxCL,IAAa,eAAb,MAA4C;CAC1C,AAAgB,KAAK;CAErB,AAAO,KAAK,QAAuB;AACjC,SAAO,EACL,QAAQ,OACN,SACsC;AACtC,UAAO,aACL,QACA,qBAAqB,KAAK,SAAS,eAAe,KAAK,cACvD,EACE,QAAQ,OACT,CACF;KAEJ"}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
//#region src/types/http.d.ts
|
|
4
|
+
type FetchContext = {
|
|
5
|
+
url: string;
|
|
6
|
+
init: RequestInit; /** internal metadata for plugins */
|
|
7
|
+
meta: {
|
|
8
|
+
retry?: boolean;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
type BeforeFetchHook = (ctx: FetchContext) => Promise<void> | void;
|
|
12
|
+
type AfterFetchHook = (ctx: FetchContext, res: Response) => Promise<"retry" | void> | "retry" | void;
|
|
13
|
+
/**
|
|
14
|
+
* Fetch options for internal API calls
|
|
15
|
+
*/
|
|
16
|
+
type FetchRequestOptions = {
|
|
17
|
+
method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
18
|
+
headers?: Record<string, string>;
|
|
19
|
+
body?: Record<string, unknown>;
|
|
20
|
+
callbackUrl?: string;
|
|
21
|
+
};
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/types/schemas.d.ts
|
|
24
|
+
declare const userSchema: z.ZodObject<{
|
|
25
|
+
id: z.ZodUUID;
|
|
26
|
+
name: z.ZodString;
|
|
27
|
+
email: z.ZodEmail;
|
|
28
|
+
emailVerified: z.ZodBoolean;
|
|
29
|
+
image: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
30
|
+
metadata: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
31
|
+
createdAt: z.ZodISODateTime;
|
|
32
|
+
updatedAt: z.ZodISODateTime;
|
|
33
|
+
}, z.core.$strip>;
|
|
34
|
+
type User = z.infer<typeof userSchema>;
|
|
35
|
+
declare const accountSchema: z.ZodObject<{
|
|
36
|
+
id: z.ZodUUID;
|
|
37
|
+
userId: z.ZodString;
|
|
38
|
+
accountId: z.ZodString;
|
|
39
|
+
providerId: z.ZodString;
|
|
40
|
+
accessToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
41
|
+
refreshToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
42
|
+
idToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
43
|
+
accessTokenExpiresAt: z.ZodOptional<z.ZodNullable<z.ZodISODateTime>>;
|
|
44
|
+
refreshTokenExpiresAt: z.ZodOptional<z.ZodNullable<z.ZodISODateTime>>;
|
|
45
|
+
scope: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
46
|
+
password: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
47
|
+
createdAt: z.ZodISODateTime;
|
|
48
|
+
updatedAt: z.ZodISODateTime;
|
|
49
|
+
}, z.core.$strip>;
|
|
50
|
+
type Account = z.infer<typeof accountSchema>;
|
|
51
|
+
declare const sessionSchema: z.ZodObject<{
|
|
52
|
+
id: z.ZodUUID;
|
|
53
|
+
userId: z.ZodString;
|
|
54
|
+
token: z.ZodString;
|
|
55
|
+
expiresAt: z.ZodISODateTime;
|
|
56
|
+
ipAddress: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
57
|
+
userAgent: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
58
|
+
createdAt: z.ZodISODateTime;
|
|
59
|
+
updatedAt: z.ZodISODateTime;
|
|
60
|
+
}, z.core.$strip>;
|
|
61
|
+
type Session = z.infer<typeof sessionSchema>;
|
|
62
|
+
declare const verificationTypeSchema: z.ZodEnum<{
|
|
63
|
+
email_verification: "email_verification";
|
|
64
|
+
password_reset_request: "password_reset_request";
|
|
65
|
+
email_reset_request: "email_reset_request";
|
|
66
|
+
}>;
|
|
67
|
+
type VerificationType = z.infer<typeof verificationTypeSchema>;
|
|
68
|
+
declare const verificationSchema: z.ZodObject<{
|
|
69
|
+
id: z.ZodUUID;
|
|
70
|
+
userId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
71
|
+
identifier: z.ZodString;
|
|
72
|
+
token: z.ZodString;
|
|
73
|
+
type: z.ZodEnum<{
|
|
74
|
+
email_verification: "email_verification";
|
|
75
|
+
password_reset_request: "password_reset_request";
|
|
76
|
+
email_reset_request: "email_reset_request";
|
|
77
|
+
}>;
|
|
78
|
+
expiresAt: z.ZodISODateTime;
|
|
79
|
+
createdAt: z.ZodISODateTime;
|
|
80
|
+
updatedAt: z.ZodISODateTime;
|
|
81
|
+
}, z.core.$strip>;
|
|
82
|
+
type Verification = z.infer<typeof verificationSchema>;
|
|
83
|
+
//#endregion
|
|
84
|
+
//#region src/types/cookies.d.ts
|
|
85
|
+
type CookieStore = {
|
|
86
|
+
getAll(): {
|
|
87
|
+
name: string;
|
|
88
|
+
value: string;
|
|
89
|
+
}[];
|
|
90
|
+
set(name: string, value: string, options?: Record<string, any>): void;
|
|
91
|
+
delete?(name: string): void;
|
|
92
|
+
};
|
|
93
|
+
type CookieProvider = (() => Promise<CookieStore>) | (() => CookieStore);
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/client.d.ts
|
|
96
|
+
declare class AuthulaClient {
|
|
97
|
+
readonly config: AuthulaClientConfig;
|
|
98
|
+
private readonly plugins;
|
|
99
|
+
private readonly beforeFetchHooks;
|
|
100
|
+
private readonly afterFetchHooks;
|
|
101
|
+
constructor(options: AuthulaClientOptions);
|
|
102
|
+
registerBeforeFetch(hook: BeforeFetchHook): void;
|
|
103
|
+
registerAfterFetch(hook: AfterFetchHook): void;
|
|
104
|
+
runBeforeFetch(ctx: FetchContext): Promise<void>;
|
|
105
|
+
runAfterFetch(ctx: FetchContext, res: Response): Promise<"retry" | undefined>;
|
|
106
|
+
getMe<T = unknown>(): Promise<T>;
|
|
107
|
+
signOut(data: SignOutRequest): Promise<SignOutResponse>;
|
|
108
|
+
getPlugin<T extends Plugin>(id: string): T | undefined;
|
|
109
|
+
}
|
|
110
|
+
//#endregion
|
|
111
|
+
//#region src/types/plugins.d.ts
|
|
112
|
+
interface Plugin {
|
|
113
|
+
readonly id: string;
|
|
114
|
+
init(client: AuthulaClient): any;
|
|
115
|
+
}
|
|
116
|
+
//#endregion
|
|
117
|
+
//#region src/types/config.d.ts
|
|
118
|
+
type FetchOptions = {
|
|
119
|
+
/**
|
|
120
|
+
* The abort timeout in seconds
|
|
121
|
+
*/
|
|
122
|
+
abortTimeout?: number;
|
|
123
|
+
};
|
|
124
|
+
type AuthulaClientConfig = {
|
|
125
|
+
/**
|
|
126
|
+
* The URL of your Authula server
|
|
127
|
+
* @example 'http://localhost:8080/auth'
|
|
128
|
+
*/
|
|
129
|
+
url: string;
|
|
130
|
+
fetchOptions?: FetchOptions;
|
|
131
|
+
cookies?: CookieProvider;
|
|
132
|
+
};
|
|
133
|
+
type AuthulaClientOptions = AuthulaClientConfig & {
|
|
134
|
+
/**
|
|
135
|
+
* The list of plugins to use
|
|
136
|
+
*/
|
|
137
|
+
plugins: Array<Plugin>;
|
|
138
|
+
};
|
|
139
|
+
//#endregion
|
|
140
|
+
//#region src/types/methods.d.ts
|
|
141
|
+
type GetMeResponse = {
|
|
142
|
+
user: User;
|
|
143
|
+
session: Session;
|
|
144
|
+
};
|
|
145
|
+
type SignOutRequest = {
|
|
146
|
+
sessionId?: string;
|
|
147
|
+
signOutAll?: boolean;
|
|
148
|
+
};
|
|
149
|
+
type SignOutResponse = {
|
|
150
|
+
message: string;
|
|
151
|
+
};
|
|
152
|
+
//#endregion
|
|
153
|
+
//#region src/sdk.d.ts
|
|
154
|
+
type InferPluginMethods<P> = P extends {
|
|
155
|
+
init: (client: any) => infer M;
|
|
156
|
+
} ? M : never;
|
|
157
|
+
type ClientWithPlugins<T extends readonly Plugin[]> = AuthulaClient & { [P in T[number] as P["id"]]: InferPluginMethods<P> };
|
|
158
|
+
declare function createClient<const T extends readonly Plugin[]>(options: Omit<AuthulaClientOptions, "plugins"> & {
|
|
159
|
+
plugins: T;
|
|
160
|
+
}): ClientWithPlugins<T>;
|
|
161
|
+
//#endregion
|
|
162
|
+
export { AfterFetchHook as C, FetchRequestOptions as E, verificationTypeSchema as S, FetchContext as T, VerificationType as _, SignOutResponse as a, userSchema as b, FetchOptions as c, CookieProvider as d, CookieStore as f, Verification as g, User as h, SignOutRequest as i, Plugin as l, Session as m, createClient as n, AuthulaClientConfig as o, Account as p, GetMeResponse as r, AuthulaClientOptions as s, ClientWithPlugins as t, AuthulaClient as u, accountSchema as v, BeforeFetchHook as w, verificationSchema as x, sessionSchema as y };
|
|
163
|
+
//# sourceMappingURL=sdk-BWoai6MP.d.ts.map
|