authula 0.3.4 → 0.5.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/README.md CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  <p align="center">
3
2
  <img src="./project-logo.png" width="200" />
4
3
  </p>
@@ -7,7 +6,6 @@
7
6
  This Node.js SDK provides seamless integration with an Authula server for both client-side and server-side applications and is framework agnostic.
8
7
  </p>
9
8
 
10
-
11
9
  <div align="center">
12
10
  <a href="https://www.npmjs.com/package/authula" target="_parent">
13
11
  <img src="https://img.shields.io/npm/dm/authula.svg" alt="Node.js SDK downloads" />
@@ -165,7 +163,8 @@ const updatedRole = await authulaClient.accessControl.updateRole("role-id", {
165
163
  });
166
164
 
167
165
  // Delete a role
168
- const deleteRoleResult = await authulaClient.accessControl.deleteRole("role-id");
166
+ const deleteRoleResult =
167
+ await authulaClient.accessControl.deleteRole("role-id");
169
168
  ```
170
169
 
171
170
  #### Permission Management
@@ -182,40 +181,49 @@ const createdPermission = await authulaClient.accessControl.createPermission({
182
181
  const allPermissions = await authulaClient.accessControl.getAllPermissions();
183
182
 
184
183
  // Get a specific permission
185
- const permission = await authulaClient.accessControl.getPermissionById("permission-id");
184
+ const permission =
185
+ await authulaClient.accessControl.getPermissionById("permission-id");
186
186
 
187
187
  // Update a permission
188
- const updatedPermission = await authulaClient.accessControl.updatePermission("permission-id", {
189
- description: "Updated permission description",
190
- });
188
+ const updatedPermission = await authulaClient.accessControl.updatePermission(
189
+ "permission-id",
190
+ {
191
+ description: "Updated permission description",
192
+ },
193
+ );
191
194
 
192
195
  // Delete a permission
193
- const deletePermissionResult = await authulaClient.accessControl.deletePermission("permission-id");
196
+ const deletePermissionResult =
197
+ await authulaClient.accessControl.deletePermission("permission-id");
194
198
  ```
195
199
 
196
200
  #### Role-Permission Management
197
201
 
198
202
  ```typescript
199
203
  // Add a permission to a role
200
- const addPermissionResult = await authulaClient.accessControl.addRolePermission("role-id", {
201
- permissionId: "permission-id",
202
- });
203
-
204
- // Get all permissions for a role
205
- const rolePermissions = await authulaClient.accessControl.getRolePermissions(
204
+ const addPermissionResult = await authulaClient.accessControl.addRolePermission(
206
205
  "role-id",
206
+ {
207
+ permissionId: "permission-id",
208
+ },
207
209
  );
208
210
 
211
+ // Get all permissions for a role
212
+ const rolePermissions =
213
+ await authulaClient.accessControl.getRolePermissions("role-id");
214
+
209
215
  // Replace all permissions for a role
210
- const replaceRolePermissionsResult = await authulaClient.accessControl.replaceRolePermissions("role-id", {
211
- permissionIds: ["permission-id-1", "permission-id-2", "permission-id-3"],
212
- });
216
+ const replaceRolePermissionsResult =
217
+ await authulaClient.accessControl.replaceRolePermissions("role-id", {
218
+ permissionIds: ["permission-id-1", "permission-id-2", "permission-id-3"],
219
+ });
213
220
 
214
221
  // Remove a permission from a role
215
- const removeRolePermissionResult = await authulaClient.accessControl.removeRolePermission(
216
- "role-id",
217
- "permission-id",
218
- );
222
+ const removeRolePermissionResult =
223
+ await authulaClient.accessControl.removeRolePermission(
224
+ "role-id",
225
+ "permission-id",
226
+ );
219
227
  ```
220
228
 
221
229
  #### User Role Management
@@ -225,30 +233,190 @@ const removeRolePermissionResult = await authulaClient.accessControl.removeRoleP
225
233
  const userRoles = await authulaClient.accessControl.getUserRoles("user-id");
226
234
 
227
235
  // Assign a role to a user
228
- const assignUserRoleResult = await authulaClient.accessControl.assignUserRole("user-id", {
229
- roleId: "role-id",
230
- expiresAt: new Date("2025-12-31"), // Optional: role expiration date
231
- });
236
+ const assignUserRoleResult = await authulaClient.accessControl.assignUserRole(
237
+ "user-id",
238
+ {
239
+ roleId: "role-id",
240
+ expiresAt: new Date("2025-12-31"), // Optional: role expiration date
241
+ },
242
+ );
232
243
 
233
244
  // Replace all roles for a user
234
- const replaceUserRolesResult = await authulaClient.accessControl.replaceUserRoles("user-id", {
235
- roleIds: ["role-id-1", "role-id-2"],
236
- });
245
+ const replaceUserRolesResult =
246
+ await authulaClient.accessControl.replaceUserRoles("user-id", {
247
+ roleIds: ["role-id-1", "role-id-2"],
248
+ });
237
249
 
238
250
  // Remove a role from a user
239
- const removeUserRoleResult = await authulaClient.accessControl.removeUserRole("user-id", "role-id");
251
+ const removeUserRoleResult = await authulaClient.accessControl.removeUserRole(
252
+ "user-id",
253
+ "role-id",
254
+ );
240
255
  ```
241
256
 
242
257
  #### User Permission Management
243
258
 
244
259
  ```typescript
245
260
  // Get all effective permissions for a user (from all assigned roles)
246
- const effectivePermissions = await authulaClient.accessControl.getUserPermissions("user-id");
261
+ const effectivePermissions =
262
+ await authulaClient.accessControl.getUserPermissions("user-id");
247
263
 
248
264
  // Check whether the user has all requested permissions
249
- const permissionCheck = await authulaClient.accessControl.checkUserPermissions("user-id", {
250
- permissionKeys: ["users.create", "users.update"],
265
+ const permissionCheck = await authulaClient.accessControl.checkUserPermissions(
266
+ "user-id",
267
+ {
268
+ permissionKeys: ["users.create", "users.update"],
269
+ },
270
+ );
271
+ ```
272
+
273
+ ---
274
+
275
+ ### Organizations Plugin
276
+
277
+ Provides the ability to manage organizations, members, teams and invitations.
278
+
279
+ ```typescript
280
+ import { OrganizationsPlugin } from "authula/plugins";
281
+
282
+ const authulaClient = createClient({
283
+ url: "http://localhost:8080/auth",
284
+ plugins: [new OrganizationsPlugin()],
251
285
  });
286
+
287
+ // Organizations
288
+
289
+ await authulaClient.organizations.createOrganization({
290
+ name: "Acme Inc.",
291
+ slug: "acme-inc",
292
+ logo: "https://example.com/logo.svg",
293
+ metadata: { key: "value" },
294
+ });
295
+
296
+ await authulaClient.organizations.getAllOrganizations();
297
+
298
+ await authulaClient.organizations.getOrganizationById("organization-id");
299
+
300
+ await authulaClient.organizations.updateOrganization("organization-id", {
301
+ name: "Updated name",
302
+ });
303
+
304
+ await authulaClient.organizations.deleteOrganization("organization-id");
305
+
306
+ // Invitations
307
+
308
+ await authulaClient.organizations.createOrganizationInvitation(
309
+ "organization-id",
310
+ {
311
+ email: "user@example.com",
312
+ role: "member",
313
+ redirectUrl: "https://example.com/invite",
314
+ },
315
+ );
316
+
317
+ await authulaClient.organizations.getAllOrganizationInvitations(
318
+ "organization-id",
319
+ );
320
+
321
+ await authulaClient.organizations.getOrganizationInvitation(
322
+ "organization-id",
323
+ "invitation-id",
324
+ );
325
+
326
+ await authulaClient.organizations.revokeOrganizationInvitation(
327
+ "organization-id",
328
+ "invitation-id",
329
+ );
330
+
331
+ await authulaClient.organizations.acceptOrganizationInvitation(
332
+ "organization-id",
333
+ "invitation-id",
334
+ {
335
+ redirectUrl: "https://example.com/accepted",
336
+ },
337
+ );
338
+
339
+ await authulaClient.organizations.rejectOrganizationInvitation(
340
+ "organization-id",
341
+ "invitation-id",
342
+ );
343
+
344
+ // Members
345
+
346
+ await authulaClient.organizations.addOrganizationMember("organization-id", {
347
+ userId: "user-id",
348
+ role: "owner",
349
+ });
350
+
351
+ await authulaClient.organizations.getAllOrganizationMembers("organization-id");
352
+
353
+ await authulaClient.organizations.getOrganizationMember(
354
+ "organization-id",
355
+ "member-id",
356
+ );
357
+
358
+ await authulaClient.organizations.updateOrganizationMember(
359
+ "organization-id",
360
+ "member-id",
361
+ {
362
+ role: "owner",
363
+ },
364
+ );
365
+
366
+ await authulaClient.organizations.deleteOrganizationMember(
367
+ "organization-id",
368
+ "member-id",
369
+ );
370
+
371
+ // Teams
372
+
373
+ await authulaClient.organizations.createOrganizationTeam("organization-id", {
374
+ name: "Platform",
375
+ slug: "platform",
376
+ description: "Platform team",
377
+ metadata: { key: "value" },
378
+ });
379
+
380
+ await authulaClient.organizations.getAllOrganizationTeams("organization-id");
381
+
382
+ await authulaClient.organizations.updateOrganizationTeam(
383
+ "organization-id",
384
+ "team-id",
385
+ {
386
+ name: "Platform",
387
+ slug: "platform",
388
+ description: "Updated team description",
389
+ metadata: { key: "value" },
390
+ },
391
+ );
392
+ await authulaClient.organizations.deleteOrganizationTeam(
393
+ "organization-id",
394
+ "team-id",
395
+ );
396
+
397
+ // Team Members
398
+
399
+ await authulaClient.organizations.addOrganizationTeamMember(
400
+ "organization-id",
401
+ "team-id",
402
+ {
403
+ memberId: "member-id",
404
+ },
405
+ );
406
+ await authulaClient.organizations.getAllOrganizationTeamMembers(
407
+ "organization-id",
408
+ "team-id",
409
+ );
410
+ await authulaClient.organizations.getOrganizationTeamMember(
411
+ "organization-id",
412
+ "team-id",
413
+ "member-id",
414
+ );
415
+ await authulaClient.organizations.deleteOrganizationTeamMember(
416
+ "organization-id",
417
+ "team-id",
418
+ "member-id",
419
+ );
252
420
  ```
253
421
 
254
422
  ---
@@ -292,7 +460,9 @@ await authulaClient.admin.deleteUser("user-id");
292
460
 
293
461
  ```typescript
294
462
  // Create a new account for a user
295
- await authulaClient.admin.createAccount("user-id", { /* account data */ });
463
+ await authulaClient.admin.createAccount("user-id", {
464
+ /* account data */
465
+ });
296
466
 
297
467
  // Get all accounts for a user
298
468
  await authulaClient.admin.getUserAccounts("user-id");
@@ -301,7 +471,9 @@ await authulaClient.admin.getUserAccounts("user-id");
301
471
  await authulaClient.admin.getAccountById("account-id");
302
472
 
303
473
  // Update account information
304
- await authulaClient.admin.updateAccount("account-id", { /* data */ });
474
+ await authulaClient.admin.updateAccount("account-id", {
475
+ /* data */
476
+ });
305
477
 
306
478
  // Delete an account
307
479
  await authulaClient.admin.deleteAccount("account-id");
@@ -314,10 +486,14 @@ await authulaClient.admin.deleteAccount("account-id");
314
486
  await authulaClient.admin.getUserState("user-id");
315
487
 
316
488
  // Create or update user state
317
- await authulaClient.admin.createUserState("user-id", { /* state data */ });
489
+ await authulaClient.admin.createUserState("user-id", {
490
+ /* state data */
491
+ });
318
492
 
319
493
  // Update user state
320
- await authulaClient.admin.updateUserState("user-id", { /* state data */ });
494
+ await authulaClient.admin.updateUserState("user-id", {
495
+ /* state data */
496
+ });
321
497
 
322
498
  // Delete user state
323
499
  await authulaClient.admin.deleteUserState("user-id");
@@ -342,10 +518,14 @@ await authulaClient.admin.getUserAdminSessions("user-id");
342
518
  await authulaClient.admin.getSessionState("session-id");
343
519
 
344
520
  // Create or update session state
345
- await authulaClient.admin.createSessionState("session-id", { /* data */ });
521
+ await authulaClient.admin.createSessionState("session-id", {
522
+ /* data */
523
+ });
346
524
 
347
525
  // Update session state
348
- await authulaClient.admin.updateSessionState("session-id", { /* data */ });
526
+ await authulaClient.admin.updateSessionState("session-id", {
527
+ /* data */
528
+ });
349
529
 
350
530
  // Delete session state
351
531
  await authulaClient.admin.deleteSessionState("session-id");
@@ -367,7 +547,7 @@ await authulaClient.admin.getAllImpersonations();
367
547
  await authulaClient.admin.getImpersonationById("impersonation-id");
368
548
 
369
549
  // Start impersonating a user
370
- await authulaClient.admin.startImpersonation({ user_id: "user-id", /* data */ });
550
+ await authulaClient.admin.startImpersonation({ user_id: "user-id" /* data */ });
371
551
 
372
552
  // Stop impersonation
373
553
  await authulaClient.admin.stopImpersonation("impersonation-id");
@@ -56,7 +56,11 @@ const verificationSchema = z.object({
56
56
  //#endregion
57
57
  //#region src/fetch.ts
58
58
  async function wrappedFetch(client, endpoint, options = {}) {
59
- const headers = new Headers(options.headers || {});
59
+ const headersCombined = {
60
+ ...options.headers,
61
+ ...client.config.fetchOptions?.headers ?? {}
62
+ };
63
+ const headers = new Headers(headersCombined || {});
60
64
  let cookieStore = null;
61
65
  if (client.config.cookies) {
62
66
  cookieStore = await client.config.cookies();
@@ -121,4 +125,4 @@ async function wrappedFetch(client, endpoint, options = {}) {
121
125
 
122
126
  //#endregion
123
127
  export { verificationSchema as a, userSchema as i, accountSchema as n, verificationTypeSchema as o, sessionSchema as r, wrappedFetch as t };
124
- //# sourceMappingURL=fetch-B4O1awi2.js.map
128
+ //# sourceMappingURL=fetch-CDNq42ed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch-CDNq42ed.js","names":[],"sources":["../src/types/schemas.ts","../src/fetch.ts"],"sourcesContent":["import { z } from \"zod\";\n\nexport const userSchema = z.object({\n id: z.uuid(),\n name: z.string().nonempty(),\n email: z.email(),\n emailVerified: z.boolean(),\n image: z.string().nullish(),\n metadata: z.record(z.string(), z.unknown()).nullish(),\n createdAt: z.iso.datetime(),\n updatedAt: z.iso.datetime(),\n});\nexport type User = z.infer<typeof userSchema>;\n\nexport const accountSchema = z.object({\n id: z.uuid(),\n userId: z.string().nonempty(),\n accountId: z.string().nonempty(),\n providerId: z.string().nonempty(),\n accessToken: z.string().nullish(),\n refreshToken: z.string().nullish(),\n idToken: z.string().nullish(),\n accessTokenExpiresAt: z.iso.datetime().nullish(),\n refreshTokenExpiresAt: z.iso.datetime().nullish(),\n scope: z.string().nullish(),\n password: z.string().nullish(),\n createdAt: z.iso.datetime(),\n updatedAt: z.iso.datetime(),\n});\nexport type Account = z.infer<typeof accountSchema>;\n\nexport const sessionSchema = z.object({\n id: z.uuid(),\n userId: z.string().nonempty(),\n token: z.string().nonempty(),\n expiresAt: z.iso.datetime(),\n ipAddress: z.string().nullish(),\n userAgent: z.string().nullish(),\n createdAt: z.iso.datetime(),\n updatedAt: z.iso.datetime(),\n});\nexport type Session = z.infer<typeof sessionSchema>;\n\nexport const verificationTypeSchema = z.enum([\n \"email_verification\",\n \"password_reset_request\",\n \"email_reset_request\",\n]);\nexport type VerificationType = z.infer<typeof verificationTypeSchema>;\n\nexport const verificationSchema = z.object({\n id: z.uuid(),\n userId: z.string().nullish(),\n identifier: z.string().nonempty(),\n token: z.string().nonempty(),\n type: verificationTypeSchema,\n expiresAt: z.iso.datetime(),\n createdAt: z.iso.datetime(),\n updatedAt: z.iso.datetime(),\n});\nexport type Verification = z.infer<typeof verificationSchema>;\n","import { toCamelCaseKeys, toSnakeCaseKeys } from \"es-toolkit\";\n\nimport type { AuthulaClient } from \"./client\";\nimport type { CookieStore, FetchContext, FetchRequestOptions } from \"./types\";\n\nexport async function wrappedFetch<T>(\n client: AuthulaClient,\n endpoint: string,\n options: FetchRequestOptions = {},\n): Promise<T> {\n const headersCombined = {\n ...options.headers,\n ...(client.config.fetchOptions?.headers ?? {}),\n };\n const headers = new Headers(headersCombined || {});\n\n let cookieStore: CookieStore | null = null;\n\n if (client.config.cookies) {\n cookieStore = await client.config.cookies();\n\n const cookieHeader = cookieStore\n .getAll()\n .map((c) => `${c.name}=${c.value}`)\n .join(\"; \");\n\n if (cookieHeader) {\n headers.set(\"cookie\", cookieHeader);\n }\n }\n\n const controller = new AbortController();\n const abortTimeout = client.config.fetchOptions?.abortTimeout;\n\n if (abortTimeout) {\n setTimeout(() => controller.abort(), abortTimeout * 1000);\n }\n\n const ctx: FetchContext = {\n url: `${client.config.url}${endpoint}`,\n init: {\n method: options.method ?? \"GET\",\n headers,\n body: options.body\n ? JSON.stringify(toSnakeCaseKeys(options.body))\n : undefined,\n credentials: \"include\",\n signal: controller.signal,\n },\n meta: {},\n };\n\n await client.runBeforeFetch(ctx);\n\n let res = await fetch(ctx.url, ctx.init);\n\n const action = await client.runAfterFetch(ctx, res);\n if (action === \"retry\" && !ctx.meta.retry) {\n ctx.meta.retry = true;\n res = await fetch(ctx.url, ctx.init);\n }\n\n const setCookieHeaders =\n res.headers.getSetCookie?.() ??\n res.headers.get(\"set-cookie\")?.split(\", \") ??\n null;\n\n if (!res.ok) {\n throw new Error(await res.text());\n }\n\n const resData = await res.json();\n\n // Apply Set-Cookie back into Next.js store (SSR only)\n if (cookieStore && setCookieHeaders) {\n for (const raw of setCookieHeaders) {\n const [pair, ...attrs] = raw.split(\";\");\n const [name, value] = pair.split(\"=\");\n\n if (!name || !value) continue;\n\n const options: Record<string, any> = {};\n\n for (const attr of attrs) {\n const [k, v] = attr.trim().split(\"=\");\n\n switch (k.toLowerCase()) {\n case \"path\":\n options.path = v;\n break;\n case \"expires\":\n options.expires = new Date(v);\n break;\n case \"max-age\":\n options.maxAge = Number(v);\n break;\n case \"httponly\":\n options.httpOnly = true;\n break;\n case \"secure\":\n options.secure = true;\n break;\n case \"samesite\":\n options.sameSite = v?.toLowerCase();\n break;\n }\n }\n\n cookieStore.set(name.trim(), decodeURIComponent(value.trim()), options);\n }\n }\n\n return toCamelCaseKeys(resData)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,CAAC,IAAI,KAAK,OAAO;AACzC,MAAI,KAAK,QAAQ;AACjB,QAAM,MAAM,MAAM,IAAI,KAAK,IAAI,KAAK;;CAGtC,MAAM,mBACJ,IAAI,QAAQ,gBAAgB,IAC5B,IAAI,QAAQ,IAAI,aAAa,EAAE,MAAM,KAAK,IAC1C;AAEF,KAAI,CAAC,IAAI,GACP,OAAM,IAAI,MAAM,MAAM,IAAI,MAAM,CAAC;CAGnC,MAAM,UAAU,MAAM,IAAI,MAAM;AAGhC,KAAI,eAAe,iBACjB,MAAK,MAAM,OAAO,kBAAkB;EAClC,MAAM,CAAC,MAAM,GAAG,SAAS,IAAI,MAAM,IAAI;EACvC,MAAM,CAAC,MAAM,SAAS,KAAK,MAAM,IAAI;AAErC,MAAI,CAAC,QAAQ,CAAC,MAAO;EAErB,MAAM,UAA+B,EAAE;AAEvC,OAAK,MAAM,QAAQ,OAAO;GACxB,MAAM,CAAC,GAAG,KAAK,KAAK,MAAM,CAAC,MAAM,IAAI;AAErC,WAAQ,EAAE,aAAa,EAAvB;IACE,KAAK;AACH,aAAQ,OAAO;AACf;IACF,KAAK;AACH,aAAQ,UAAU,IAAI,KAAK,EAAE;AAC7B;IACF,KAAK;AACH,aAAQ,SAAS,OAAO,EAAE;AAC1B;IACF,KAAK;AACH,aAAQ,WAAW;AACnB;IACF,KAAK;AACH,aAAQ,SAAS;AACjB;IACF,KAAK;AACH,aAAQ,WAAW,GAAG,aAAa;AACnC;;;AAIN,cAAY,IAAI,KAAK,MAAM,EAAE,mBAAmB,MAAM,MAAM,CAAC,EAAE,QAAQ;;AAI3E,QAAO,gBAAgB,QAAQ"}
@@ -56,7 +56,11 @@ const verificationSchema = zod.z.object({
56
56
  //#endregion
57
57
  //#region src/fetch.ts
58
58
  async function wrappedFetch(client, endpoint, options = {}) {
59
- const headers = new Headers(options.headers || {});
59
+ const headersCombined = {
60
+ ...options.headers,
61
+ ...client.config.fetchOptions?.headers ?? {}
62
+ };
63
+ const headers = new Headers(headersCombined || {});
60
64
  let cookieStore = null;
61
65
  if (client.config.cookies) {
62
66
  cookieStore = await client.config.cookies();
@@ -156,4 +160,4 @@ Object.defineProperty(exports, 'wrappedFetch', {
156
160
  return wrappedFetch;
157
161
  }
158
162
  });
159
- //# sourceMappingURL=fetch-q98rEoAp.cjs.map
163
+ //# sourceMappingURL=fetch-DBol2Fc9.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch-DBol2Fc9.cjs","names":["z"],"sources":["../src/types/schemas.ts","../src/fetch.ts"],"sourcesContent":["import { z } from \"zod\";\n\nexport const userSchema = z.object({\n id: z.uuid(),\n name: z.string().nonempty(),\n email: z.email(),\n emailVerified: z.boolean(),\n image: z.string().nullish(),\n metadata: z.record(z.string(), z.unknown()).nullish(),\n createdAt: z.iso.datetime(),\n updatedAt: z.iso.datetime(),\n});\nexport type User = z.infer<typeof userSchema>;\n\nexport const accountSchema = z.object({\n id: z.uuid(),\n userId: z.string().nonempty(),\n accountId: z.string().nonempty(),\n providerId: z.string().nonempty(),\n accessToken: z.string().nullish(),\n refreshToken: z.string().nullish(),\n idToken: z.string().nullish(),\n accessTokenExpiresAt: z.iso.datetime().nullish(),\n refreshTokenExpiresAt: z.iso.datetime().nullish(),\n scope: z.string().nullish(),\n password: z.string().nullish(),\n createdAt: z.iso.datetime(),\n updatedAt: z.iso.datetime(),\n});\nexport type Account = z.infer<typeof accountSchema>;\n\nexport const sessionSchema = z.object({\n id: z.uuid(),\n userId: z.string().nonempty(),\n token: z.string().nonempty(),\n expiresAt: z.iso.datetime(),\n ipAddress: z.string().nullish(),\n userAgent: z.string().nullish(),\n createdAt: z.iso.datetime(),\n updatedAt: z.iso.datetime(),\n});\nexport type Session = z.infer<typeof sessionSchema>;\n\nexport const verificationTypeSchema = z.enum([\n \"email_verification\",\n \"password_reset_request\",\n \"email_reset_request\",\n]);\nexport type VerificationType = z.infer<typeof verificationTypeSchema>;\n\nexport const verificationSchema = z.object({\n id: z.uuid(),\n userId: z.string().nullish(),\n identifier: z.string().nonempty(),\n token: z.string().nonempty(),\n type: verificationTypeSchema,\n expiresAt: z.iso.datetime(),\n createdAt: z.iso.datetime(),\n updatedAt: z.iso.datetime(),\n});\nexport type Verification = z.infer<typeof verificationSchema>;\n","import { toCamelCaseKeys, toSnakeCaseKeys } from \"es-toolkit\";\n\nimport type { AuthulaClient } from \"./client\";\nimport type { CookieStore, FetchContext, FetchRequestOptions } from \"./types\";\n\nexport async function wrappedFetch<T>(\n client: AuthulaClient,\n endpoint: string,\n options: FetchRequestOptions = {},\n): Promise<T> {\n const headersCombined = {\n ...options.headers,\n ...(client.config.fetchOptions?.headers ?? {}),\n };\n const headers = new Headers(headersCombined || {});\n\n let cookieStore: CookieStore | null = null;\n\n if (client.config.cookies) {\n cookieStore = await client.config.cookies();\n\n const cookieHeader = cookieStore\n .getAll()\n .map((c) => `${c.name}=${c.value}`)\n .join(\"; \");\n\n if (cookieHeader) {\n headers.set(\"cookie\", cookieHeader);\n }\n }\n\n const controller = new AbortController();\n const abortTimeout = client.config.fetchOptions?.abortTimeout;\n\n if (abortTimeout) {\n setTimeout(() => controller.abort(), abortTimeout * 1000);\n }\n\n const ctx: FetchContext = {\n url: `${client.config.url}${endpoint}`,\n init: {\n method: options.method ?? \"GET\",\n headers,\n body: options.body\n ? JSON.stringify(toSnakeCaseKeys(options.body))\n : undefined,\n credentials: \"include\",\n signal: controller.signal,\n },\n meta: {},\n };\n\n await client.runBeforeFetch(ctx);\n\n let res = await fetch(ctx.url, ctx.init);\n\n const action = await client.runAfterFetch(ctx, res);\n if (action === \"retry\" && !ctx.meta.retry) {\n ctx.meta.retry = true;\n res = await fetch(ctx.url, ctx.init);\n }\n\n const setCookieHeaders =\n res.headers.getSetCookie?.() ??\n res.headers.get(\"set-cookie\")?.split(\", \") ??\n null;\n\n if (!res.ok) {\n throw new Error(await res.text());\n }\n\n const resData = await res.json();\n\n // Apply Set-Cookie back into Next.js store (SSR only)\n if (cookieStore && setCookieHeaders) {\n for (const raw of setCookieHeaders) {\n const [pair, ...attrs] = raw.split(\";\");\n const [name, value] = pair.split(\"=\");\n\n if (!name || !value) continue;\n\n const options: Record<string, any> = {};\n\n for (const attr of attrs) {\n const [k, v] = attr.trim().split(\"=\");\n\n switch (k.toLowerCase()) {\n case \"path\":\n options.path = v;\n break;\n case \"expires\":\n options.expires = new Date(v);\n break;\n case \"max-age\":\n options.maxAge = Number(v);\n break;\n case \"httponly\":\n options.httpOnly = true;\n break;\n case \"secure\":\n options.secure = true;\n break;\n case \"samesite\":\n options.sameSite = v?.toLowerCase();\n break;\n }\n }\n\n cookieStore.set(name.trim(), decodeURIComponent(value.trim()), options);\n }\n }\n\n return toCamelCaseKeys(resData) as T;\n}\n"],"mappings":";;;;AAEA,MAAa,aAAaA,MAAE,OAAO;CACjC,IAAIA,MAAE,MAAM;CACZ,MAAMA,MAAE,QAAQ,CAAC,UAAU;CAC3B,OAAOA,MAAE,OAAO;CAChB,eAAeA,MAAE,SAAS;CAC1B,OAAOA,MAAE,QAAQ,CAAC,SAAS;CAC3B,UAAUA,MAAE,OAAOA,MAAE,QAAQ,EAAEA,MAAE,SAAS,CAAC,CAAC,SAAS;CACrD,WAAWA,MAAE,IAAI,UAAU;CAC3B,WAAWA,MAAE,IAAI,UAAU;CAC5B,CAAC;AAGF,MAAa,gBAAgBA,MAAE,OAAO;CACpC,IAAIA,MAAE,MAAM;CACZ,QAAQA,MAAE,QAAQ,CAAC,UAAU;CAC7B,WAAWA,MAAE,QAAQ,CAAC,UAAU;CAChC,YAAYA,MAAE,QAAQ,CAAC,UAAU;CACjC,aAAaA,MAAE,QAAQ,CAAC,SAAS;CACjC,cAAcA,MAAE,QAAQ,CAAC,SAAS;CAClC,SAASA,MAAE,QAAQ,CAAC,SAAS;CAC7B,sBAAsBA,MAAE,IAAI,UAAU,CAAC,SAAS;CAChD,uBAAuBA,MAAE,IAAI,UAAU,CAAC,SAAS;CACjD,OAAOA,MAAE,QAAQ,CAAC,SAAS;CAC3B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ACH,aAAQ,SAAS,OAAO,EAAE;AAC1B;IACF,KAAK;AACH,aAAQ,WAAW;AACnB;IACF,KAAK;AACH,aAAQ,SAAS;AACjB;IACF,KAAK;AACH,aAAQ,WAAW,GAAG,aAAa;AACnC;;;AAIN,cAAY,IAAI,KAAK,MAAM,EAAE,mBAAmB,MAAM,MAAM,CAAC,EAAE,QAAQ;;AAI3E,wCAAuB,QAAQ"}
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_fetch = require('./fetch-q98rEoAp.cjs');
2
+ const require_fetch = require('./fetch-DBol2Fc9.cjs');
3
3
  let es_toolkit = require("es-toolkit");
4
4
 
5
5
  //#region src/client.ts
package/dist/index.d.cts CHANGED
@@ -1,2 +1,2 @@
1
- import { C as AfterFetchHook, E as FetchRequestOptions, S as verificationTypeSchema, T as FetchContext, _ as VerificationType, a as SignOutResponse, b as userSchema, c as FetchOptions, d as CookieProvider, f as CookieStore, g as Verification, h as User, i as SignOutRequest, l as Plugin, m as Session, n as createClient, o as AuthulaClientConfig, p as Account, r as GetMeResponse, s as AuthulaClientOptions, u as AuthulaClient, v as accountSchema, w as BeforeFetchHook, x as verificationSchema, y as sessionSchema } from "./sdk-DV73pbRH.cjs";
1
+ import { C as AfterFetchHook, E as FetchRequestOptions, S as verificationTypeSchema, T as FetchContext, _ as VerificationType, a as SignOutResponse, b as userSchema, c as FetchOptions, d as CookieProvider, f as CookieStore, g as Verification, h as User, i as SignOutRequest, l as Plugin, m as Session, n as createClient, o as AuthulaClientConfig, p as Account, r as GetMeResponse, s as AuthulaClientOptions, u as AuthulaClient, v as accountSchema, w as BeforeFetchHook, x as verificationSchema, y as sessionSchema } from "./sdk-CONwA-47.cjs";
2
2
  export { Account, AfterFetchHook, AuthulaClient, AuthulaClientConfig, AuthulaClientOptions, BeforeFetchHook, CookieProvider, CookieStore, FetchContext, FetchOptions, FetchRequestOptions, GetMeResponse, Plugin, Session, SignOutRequest, SignOutResponse, User, Verification, VerificationType, accountSchema, createClient, sessionSchema, userSchema, verificationSchema, verificationTypeSchema };
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { C as AfterFetchHook, E as FetchRequestOptions, S as verificationTypeSchema, T as FetchContext, _ as VerificationType, a as SignOutResponse, b as userSchema, c as FetchOptions, d as CookieProvider, f as CookieStore, g as Verification, h as User, i as SignOutRequest, l as Plugin, m as Session, n as createClient, o as AuthulaClientConfig, p as Account, r as GetMeResponse, s as AuthulaClientOptions, u as AuthulaClient, v as accountSchema, w as BeforeFetchHook, x as verificationSchema, y as sessionSchema } from "./sdk-BWoai6MP.js";
1
+ import { C as AfterFetchHook, E as FetchRequestOptions, S as verificationTypeSchema, T as FetchContext, _ as VerificationType, a as SignOutResponse, b as userSchema, c as FetchOptions, d as CookieProvider, f as CookieStore, g as Verification, h as User, i as SignOutRequest, l as Plugin, m as Session, n as createClient, o as AuthulaClientConfig, p as Account, r as GetMeResponse, s as AuthulaClientOptions, u as AuthulaClient, v as accountSchema, w as BeforeFetchHook, x as verificationSchema, y as sessionSchema } from "./sdk-C0cWDM6F.js";
2
2
  export { Account, AfterFetchHook, AuthulaClient, AuthulaClientConfig, AuthulaClientOptions, BeforeFetchHook, CookieProvider, CookieStore, FetchContext, FetchOptions, FetchRequestOptions, GetMeResponse, Plugin, Session, SignOutRequest, SignOutResponse, User, Verification, VerificationType, accountSchema, createClient, sessionSchema, userSchema, verificationSchema, verificationTypeSchema };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as verificationSchema, i as userSchema, n as accountSchema, o as verificationTypeSchema, r as sessionSchema, t as wrappedFetch } from "./fetch-B4O1awi2.js";
1
+ import { a as verificationSchema, i as userSchema, n as accountSchema, o as verificationTypeSchema, r as sessionSchema, t as wrappedFetch } from "./fetch-CDNq42ed.js";
2
2
  import { toSnakeCaseKeys } from "es-toolkit";
3
3
 
4
4
  //#region src/client.ts