@protobase/server 0.7.0 → 0.8.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.
Files changed (99) hide show
  1. package/dist/assistant/conversations.d.ts +1 -1
  2. package/dist/assistant/tools.d.ts +1 -1
  3. package/dist/assistant/turn.d.ts +2 -2
  4. package/dist/audit/origin.js +12 -0
  5. package/dist/auth/jwt.d.ts +2 -0
  6. package/dist/auth/jwt.js +5 -3
  7. package/dist/batch/reorder.js +1 -1
  8. package/dist/better-auth/authenticator.d.ts +7 -3
  9. package/dist/better-auth/authenticator.js +24 -3
  10. package/dist/better-auth/create-auth.d.ts +619 -81
  11. package/dist/better-auth/create-auth.js +64 -27
  12. package/dist/better-auth/organizations/accept-invitation.js +80 -0
  13. package/dist/better-auth/organizations/active-organization.js +12 -0
  14. package/dist/better-auth/organizations/admin-routes.js +83 -0
  15. package/dist/better-auth/organizations/app-roles.js +43 -0
  16. package/dist/better-auth/organizations/host.d.ts +53 -0
  17. package/dist/better-auth/organizations/host.js +251 -0
  18. package/dist/better-auth/organizations/invitation-endpoints.js +133 -0
  19. package/dist/better-auth/organizations/invitation-mail.js +17 -0
  20. package/dist/better-auth/organizations/invitation-token.js +27 -0
  21. package/dist/better-auth/organizations/member-endpoints.js +182 -0
  22. package/dist/better-auth/organizations/options.d.ts +48 -0
  23. package/dist/better-auth/organizations/options.js +23 -0
  24. package/dist/better-auth/organizations/organization-plugin.js +128 -0
  25. package/dist/better-auth/organizations/protobase-plugin.js +21 -0
  26. package/dist/better-auth/organizations/role-definitions.d.ts +15 -0
  27. package/dist/better-auth/organizations/role-definitions.js +56 -0
  28. package/dist/better-auth/organizations/session-organization.js +68 -0
  29. package/dist/better-auth/organizations/store.d.ts +19 -0
  30. package/dist/better-auth/organizations/store.js +73 -0
  31. package/dist/better-auth/staff-checks.js +5 -1
  32. package/dist/better-auth/staff-sign-in-endpoints.js +1 -1
  33. package/dist/better-auth/status-route.js +14 -3
  34. package/dist/better-auth/users.d.ts +2 -1
  35. package/dist/better-auth/users.js +4 -1
  36. package/dist/create-admin.d.ts +8 -2
  37. package/dist/create-admin.js +31 -2
  38. package/dist/deps.d.ts +1 -0
  39. package/dist/files/attach.js +80 -0
  40. package/dist/files/cleanup-runner.d.ts +8 -0
  41. package/dist/files/cleanup-runner.js +58 -0
  42. package/dist/files/cleanup-schedule.d.ts +28 -0
  43. package/dist/files/cleanup-schedule.js +48 -0
  44. package/dist/files/detect.js +51 -0
  45. package/dist/files/download-url.js +43 -0
  46. package/dist/files/download.js +90 -0
  47. package/dist/files/duration.js +35 -0
  48. package/dist/files/file-cleanup.d.ts +18 -0
  49. package/dist/files/file-cleanup.js +17 -0
  50. package/dist/files/local-files.d.ts +17 -0
  51. package/dist/files/local-files.js +101 -0
  52. package/dist/files/media-types.js +99 -0
  53. package/dist/files/options.d.ts +15 -0
  54. package/dist/files/present.d.ts +15 -0
  55. package/dist/files/present.js +59 -0
  56. package/dist/files/processors.d.ts +15 -0
  57. package/dist/files/processors.js +39 -0
  58. package/dist/files/providers.js +70 -0
  59. package/dist/files/routes.js +26 -0
  60. package/dist/files/runtime.d.ts +3 -0
  61. package/dist/files/runtime.js +37 -0
  62. package/dist/files/signer.js +32 -0
  63. package/dist/files/store.d.ts +37 -0
  64. package/dist/files/ticket.js +87 -0
  65. package/dist/files/upload-body.js +85 -0
  66. package/dist/files/upload.js +124 -0
  67. package/dist/files/uri.js +47 -0
  68. package/dist/functions/define-function.d.ts +71 -0
  69. package/dist/functions/define-function.js +36 -0
  70. package/dist/functions/function-app.d.ts +17 -0
  71. package/dist/functions/function-app.js +19 -0
  72. package/dist/functions/read-json.d.ts +35 -0
  73. package/dist/functions/read-json.js +24 -0
  74. package/dist/functions/records.d.ts +43 -0
  75. package/dist/functions/records.js +31 -0
  76. package/dist/functions/require-env.d.ts +7 -0
  77. package/dist/functions/require-env.js +12 -0
  78. package/dist/functions/routes.js +60 -0
  79. package/dist/functions/verify-signature.d.ts +32 -0
  80. package/dist/functions/verify-signature.js +49 -0
  81. package/dist/index.d.ts +21 -3
  82. package/dist/index.js +13 -3
  83. package/dist/list-service.js +4 -2
  84. package/dist/openapi/resource-paths.js +78 -1
  85. package/dist/openapi/schemas.js +28 -3
  86. package/dist/project-config.d.ts +7 -1
  87. package/dist/project-config.js +37 -1
  88. package/dist/read-service.js +5 -1
  89. package/dist/request-access.d.ts +5 -0
  90. package/dist/request-access.js +9 -4
  91. package/dist/resource-source.d.ts +4 -1
  92. package/dist/routes/batch.js +1 -1
  93. package/dist/routes/collection.js +3 -1
  94. package/dist/routes/record.js +2 -5
  95. package/dist/types.d.ts +25 -5
  96. package/dist/write-pipeline.js +2 -1
  97. package/dist/write-shared.js +6 -3
  98. package/dist/write-update.js +2 -1
  99. package/package.json +6 -4
@@ -1,8 +1,12 @@
1
1
  import { SignInPolicy } from "./sign-in-policy.js";
2
2
  import { StaffSignIn } from "./staff-log.js";
3
+ import { RoleDefinitions, RolesInput } from "./organizations/role-definitions.js";
3
4
  import { Mailer } from "../mail/smtp-mailer.js";
4
5
  import { OperatorProvider } from "./operator-provider.js";
6
+ import { OrganizationRole } from "./organizations/store.js";
7
+ import { OrganizationsOptions, ResolvedOrganizations } from "./organizations/options.js";
5
8
  import { PlatformSignIn } from "./platform-sign-in.js";
9
+ import "../index.js";
6
10
  import { BetterAuthOptions } from "better-auth";
7
11
  //#region src/better-auth/create-auth.d.ts
8
12
  export type CreateAuthOptions = {
@@ -16,8 +20,12 @@ export type CreateAuthOptions = {
16
20
  secret: string;
17
21
  /** Extra origins that may call the auth endpoints. `baseURL` and `https://*.trycloudflare.com` are always trusted. */
18
22
  trustedOrigins?: string[];
19
- /** The roles users can have, for example `['admin', 'accountant', 'warehouse']`. `admin` is always included; default `['admin', 'user']`. */
20
- roles?: string[];
23
+ /**
24
+ * The roles users can have, for example `['admin', 'accountant', 'warehouse']`. `admin` is always included; default
25
+ * `['admin', 'user']`. With `organizations`, give each a label, and optionally the other roles its holders may also
26
+ * give members: `{ manager: { label: 'Manager', grants: ['sales'] }, sales: 'Sales' }`.
27
+ */
28
+ roles?: RolesInput;
21
29
  /**
22
30
  * The role of a user created without one. Optional: when unset, and more than one role besides `admin` exists,
23
31
  * creating a user without a role is an error that asks for one. With exactly one other role, that role is the default.
@@ -55,12 +63,23 @@ export type CreateAuthOptions = {
55
63
  * environment says. Left out when `socialProviders` has a provider with the same id.
56
64
  */
57
65
  signInProvider?: PlatformSignIn | false;
66
+ /**
67
+ * Turns on organizations: people work in one at a time, records of `.tenant` resources are scoped to it, and roles
68
+ * are held globally (on the user) or per membership. Off by default: the app works as one organization.
69
+ */
70
+ organizations?: OrganizationsOptions;
58
71
  };
59
72
  type UserCreateHooks = NonNullable<NonNullable<NonNullable<BetterAuthOptions['databaseHooks']>['user']>['create']>;
60
73
  /** Better Auth's `databaseHooks.user.create.after`: the created user (with its `role`) and the request context, `null` outside a request. */
61
74
  export type UserCreatedHook = NonNullable<UserCreateHooks['after']>;
75
+ /**
76
+ * Better Auth for a single-tenant admin: sign-in with a password, an emailed code or a passkey, two-factor
77
+ * authentication, and the sign-in policy admins set; no public sign-up (every account is created on the host with
78
+ * `createUser`, or by an admin through the admin plugin), roles from the admin plugin's `role` column, 15 minute JWTs
79
+ * at `/api/auth/token` with the keys at `/api/auth/jwks`.
80
+ */
62
81
  /** The configured roles with `admin` first; `admin` is added when missing. */
63
- export declare const normalizeRoles: (roles?: string[]) => string[];
82
+ export declare const normalizeRoles: (roles?: RolesInput) => string[];
64
83
  export declare const createAuth: (options: CreateAuthOptions) => import("better-auth").Auth<{
65
84
  user: {
66
85
  fields: {
@@ -68,6 +87,20 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
68
87
  createdAt: string;
69
88
  updatedAt: string;
70
89
  };
90
+ } | {
91
+ additionalFields: {
92
+ readonly lastOrganizationId: {
93
+ readonly type: "string";
94
+ readonly required: false;
95
+ readonly input: false;
96
+ readonly fieldName: "last_organization_id";
97
+ };
98
+ };
99
+ fields: {
100
+ emailVerified: string;
101
+ createdAt: string;
102
+ updatedAt: string;
103
+ };
71
104
  };
72
105
  session: {
73
106
  fields: {
@@ -1038,13 +1071,31 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
1038
1071
  expirationTime: string;
1039
1072
  issuer: string;
1040
1073
  audience: string;
1041
- definePayload: ({ user }: {
1074
+ definePayload: ({ user, session }: {
1042
1075
  user: import("better-auth").User & Record<string, any>;
1043
1076
  session: import("better-auth").Session & Record<string, any>;
1044
- }) => {
1077
+ }) => Promise<{
1045
1078
  email: string;
1046
1079
  role: any;
1047
- };
1080
+ } | {
1081
+ org?: undefined;
1082
+ org_role?: undefined;
1083
+ app_roles?: undefined;
1084
+ email: string;
1085
+ role: any;
1086
+ } | {
1087
+ org: string;
1088
+ org_role: OrganizationRole;
1089
+ app_roles: string[];
1090
+ email: string;
1091
+ role: any;
1092
+ } | {
1093
+ org: string;
1094
+ org_role?: undefined;
1095
+ app_roles?: undefined;
1096
+ email: string;
1097
+ role: any;
1098
+ }>;
1048
1099
  };
1049
1100
  disableSettingJwtHeader: true;
1050
1101
  }>;
@@ -3076,7 +3127,7 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
3076
3127
  INVALID_OAUTH_CONFIGURATION: import("better-auth").RawError<"INVALID_OAUTH_CONFIGURATION">;
3077
3128
  TOKEN_URL_NOT_FOUND: import("better-auth").RawError<"TOKEN_URL_NOT_FOUND">;
3078
3129
  };
3079
- })[], {
3130
+ } | {
3080
3131
  id: "protobase-sign-in-policy";
3081
3132
  schema: {
3082
3133
  readonly signInPolicy: {
@@ -3139,12 +3190,7 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
3139
3190
  expiresAt: Date;
3140
3191
  token: string;
3141
3192
  ipAddress?: string | null | undefined;
3142
- userAgent? /**
3143
- * A sign-in provider the platform adds for people who already have an account: an OpenID Connect provider that never
3144
- * signs anyone up. Defaults to the one the platform passes in `PROTOBASE_SIGN_IN_ISSUER`, `PROTOBASE_SIGN_IN_CLIENT_ID`
3145
- * and `PROTOBASE_SIGN_IN_CLIENT_SECRET` (see `readPlatformSignIn`), when set; `false` turns it off whatever the
3146
- * environment says. Left out when `socialProviders` has a provider with the same id.
3147
- */ : string | null | undefined;
3193
+ userAgent?: string | null | undefined;
3148
3194
  };
3149
3195
  user: Record<string, any> & {
3150
3196
  id: string;
@@ -3168,12 +3214,7 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
3168
3214
  expiresAt: Date;
3169
3215
  token: string;
3170
3216
  ipAddress?: string | null | undefined;
3171
- userAgent? /**
3172
- * A sign-in provider the platform adds for people who already have an account: an OpenID Connect provider that never
3173
- * signs anyone up. Defaults to the one the platform passes in `PROTOBASE_SIGN_IN_ISSUER`, `PROTOBASE_SIGN_IN_CLIENT_ID`
3174
- * and `PROTOBASE_SIGN_IN_CLIENT_SECRET` (see `readPlatformSignIn`), when set; `false` turns it off whatever the
3175
- * environment says. Left out when `socialProviders` has a provider with the same id.
3176
- */ : string | null | undefined;
3217
+ userAgent?: string | null | undefined;
3177
3218
  };
3178
3219
  user: Record<string, any> & {
3179
3220
  id: string;
@@ -3196,12 +3237,7 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
3196
3237
  expiresAt: Date;
3197
3238
  token: string;
3198
3239
  ipAddress?: string | null | undefined;
3199
- userAgent? /**
3200
- * A sign-in provider the platform adds for people who already have an account: an OpenID Connect provider that never
3201
- * signs anyone up. Defaults to the one the platform passes in `PROTOBASE_SIGN_IN_ISSUER`, `PROTOBASE_SIGN_IN_CLIENT_ID`
3202
- * and `PROTOBASE_SIGN_IN_CLIENT_SECRET` (see `readPlatformSignIn`), when set; `false` turns it off whatever the
3203
- * environment says. Left out when `socialProviders` has a provider with the same id.
3204
- */ : string | null | undefined;
3240
+ userAgent?: string | null | undefined;
3205
3241
  };
3206
3242
  user: Record<string, any> & {
3207
3243
  id: string;
@@ -3256,12 +3292,7 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
3256
3292
  expiresAt: Date;
3257
3293
  token: string;
3258
3294
  ipAddress?: string | null | undefined;
3259
- userAgent? /**
3260
- * A sign-in provider the platform adds for people who already have an account: an OpenID Connect provider that never
3261
- * signs anyone up. Defaults to the one the platform passes in `PROTOBASE_SIGN_IN_ISSUER`, `PROTOBASE_SIGN_IN_CLIENT_ID`
3262
- * and `PROTOBASE_SIGN_IN_CLIENT_SECRET` (see `readPlatformSignIn`), when set; `false` turns it off whatever the
3263
- * environment says. Left out when `socialProviders` has a provider with the same id.
3264
- */ : string | null | undefined;
3295
+ userAgent?: string | null | undefined;
3265
3296
  };
3266
3297
  user: Record<string, any> & {
3267
3298
  id: string;
@@ -3285,12 +3316,7 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
3285
3316
  expiresAt: Date;
3286
3317
  token: string;
3287
3318
  ipAddress?: string | null | undefined;
3288
- userAgent? /**
3289
- * A sign-in provider the platform adds for people who already have an account: an OpenID Connect provider that never
3290
- * signs anyone up. Defaults to the one the platform passes in `PROTOBASE_SIGN_IN_ISSUER`, `PROTOBASE_SIGN_IN_CLIENT_ID`
3291
- * and `PROTOBASE_SIGN_IN_CLIENT_SECRET` (see `readPlatformSignIn`), when set; `false` turns it off whatever the
3292
- * environment says. Left out when `socialProviders` has a provider with the same id.
3293
- */ : string | null | undefined;
3319
+ userAgent?: string | null | undefined;
3294
3320
  };
3295
3321
  user: Record<string, any> & {
3296
3322
  id: string;
@@ -3313,12 +3339,7 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
3313
3339
  expiresAt: Date;
3314
3340
  token: string;
3315
3341
  ipAddress?: string | null | undefined;
3316
- userAgent? /**
3317
- * A sign-in provider the platform adds for people who already have an account: an OpenID Connect provider that never
3318
- * signs anyone up. Defaults to the one the platform passes in `PROTOBASE_SIGN_IN_ISSUER`, `PROTOBASE_SIGN_IN_CLIENT_ID`
3319
- * and `PROTOBASE_SIGN_IN_CLIENT_SECRET` (see `readPlatformSignIn`), when set; `false` turns it off whatever the
3320
- * environment says. Left out when `socialProviders` has a provider with the same id.
3321
- */ : string | null | undefined;
3342
+ userAgent?: string | null | undefined;
3322
3343
  };
3323
3344
  user: Record<string, any> & {
3324
3345
  id: string;
@@ -3373,12 +3394,7 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
3373
3394
  expiresAt: Date;
3374
3395
  token: string;
3375
3396
  ipAddress?: string | null | undefined;
3376
- userAgent? /**
3377
- * A sign-in provider the platform adds for people who already have an account: an OpenID Connect provider that never
3378
- * signs anyone up. Defaults to the one the platform passes in `PROTOBASE_SIGN_IN_ISSUER`, `PROTOBASE_SIGN_IN_CLIENT_ID`
3379
- * and `PROTOBASE_SIGN_IN_CLIENT_SECRET` (see `readPlatformSignIn`), when set; `false` turns it off whatever the
3380
- * environment says. Left out when `socialProviders` has a provider with the same id.
3381
- */ : string | null | undefined;
3397
+ userAgent?: string | null | undefined;
3382
3398
  };
3383
3399
  user: Record<string, any> & {
3384
3400
  id: string;
@@ -3409,7 +3425,7 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
3409
3425
  handler: import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<void>>;
3410
3426
  }[];
3411
3427
  };
3412
- }, {
3428
+ } | {
3413
3429
  id: "protobase-staff-sign-in";
3414
3430
  schema: {
3415
3431
  readonly staffSignIn: {
@@ -3483,12 +3499,7 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
3483
3499
  expiresAt: Date;
3484
3500
  token: string;
3485
3501
  ipAddress?: string | null | undefined;
3486
- userAgent? /**
3487
- * A sign-in provider the platform adds for people who already have an account: an OpenID Connect provider that never
3488
- * signs anyone up. Defaults to the one the platform passes in `PROTOBASE_SIGN_IN_ISSUER`, `PROTOBASE_SIGN_IN_CLIENT_ID`
3489
- * and `PROTOBASE_SIGN_IN_CLIENT_SECRET` (see `readPlatformSignIn`), when set; `false` turns it off whatever the
3490
- * environment says. Left out when `socialProviders` has a provider with the same id.
3491
- */ : string | null | undefined;
3502
+ userAgent?: string | null | undefined;
3492
3503
  };
3493
3504
  user: Record<string, any> & {
3494
3505
  id: string;
@@ -3516,12 +3527,7 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
3516
3527
  expiresAt: Date;
3517
3528
  token: string;
3518
3529
  ipAddress?: string | null | undefined;
3519
- userAgent? /**
3520
- * A sign-in provider the platform adds for people who already have an account: an OpenID Connect provider that never
3521
- * signs anyone up. Defaults to the one the platform passes in `PROTOBASE_SIGN_IN_ISSUER`, `PROTOBASE_SIGN_IN_CLIENT_ID`
3522
- * and `PROTOBASE_SIGN_IN_CLIENT_SECRET` (see `readPlatformSignIn`), when set; `false` turns it off whatever the
3523
- * environment says. Left out when `socialProviders` has a provider with the same id.
3524
- */ : string | null | undefined;
3530
+ userAgent?: string | null | undefined;
3525
3531
  };
3526
3532
  user: Record<string, any> & {
3527
3533
  id: string;
@@ -3550,12 +3556,7 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
3550
3556
  expiresAt: Date;
3551
3557
  token: string;
3552
3558
  ipAddress?: string | null | undefined;
3553
- userAgent? /**
3554
- * A sign-in provider the platform adds for people who already have an account: an OpenID Connect provider that never
3555
- * signs anyone up. Defaults to the one the platform passes in `PROTOBASE_SIGN_IN_ISSUER`, `PROTOBASE_SIGN_IN_CLIENT_ID`
3556
- * and `PROTOBASE_SIGN_IN_CLIENT_SECRET` (see `readPlatformSignIn`), when set; `false` turns it off whatever the
3557
- * environment says. Left out when `socialProviders` has a provider with the same id.
3558
- */ : string | null | undefined;
3559
+ userAgent?: string | null | undefined;
3559
3560
  };
3560
3561
  user: Record<string, any> & {
3561
3562
  id: string;
@@ -3579,12 +3580,7 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
3579
3580
  expiresAt: Date;
3580
3581
  token: string;
3581
3582
  ipAddress?: string | null | undefined;
3582
- userAgent? /**
3583
- * A sign-in provider the platform adds for people who already have an account: an OpenID Connect provider that never
3584
- * signs anyone up. Defaults to the one the platform passes in `PROTOBASE_SIGN_IN_ISSUER`, `PROTOBASE_SIGN_IN_CLIENT_ID`
3585
- * and `PROTOBASE_SIGN_IN_CLIENT_SECRET` (see `readPlatformSignIn`), when set; `false` turns it off whatever the
3586
- * environment says. Left out when `socialProviders` has a provider with the same id.
3587
- */ : string | null | undefined;
3583
+ userAgent?: string | null | undefined;
3588
3584
  };
3589
3585
  user: Record<string, any> & {
3590
3586
  id: string;
@@ -3607,12 +3603,7 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
3607
3603
  expiresAt: Date;
3608
3604
  token: string;
3609
3605
  ipAddress?: string | null | undefined;
3610
- userAgent? /**
3611
- * A sign-in provider the platform adds for people who already have an account: an OpenID Connect provider that never
3612
- * signs anyone up. Defaults to the one the platform passes in `PROTOBASE_SIGN_IN_ISSUER`, `PROTOBASE_SIGN_IN_CLIENT_ID`
3613
- * and `PROTOBASE_SIGN_IN_CLIENT_SECRET` (see `readPlatformSignIn`), when set; `false` turns it off whatever the
3614
- * environment says. Left out when `socialProviders` has a provider with the same id.
3615
- */ : string | null | undefined;
3606
+ userAgent?: string | null | undefined;
3616
3607
  };
3617
3608
  user: Record<string, any> & {
3618
3609
  id: string;
@@ -3672,9 +3663,550 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
3672
3663
  handler: import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<void>>;
3673
3664
  }[];
3674
3665
  };
3675
- }];
3666
+ } | import("better-auth/plugins").DefaultOrganizationPlugin<{
3667
+ organizationHooks: {
3668
+ beforeCreateOrganization?: (data: {
3669
+ organization: {
3670
+ name?: string;
3671
+ slug?: string;
3672
+ logo?: string | null;
3673
+ metadata?: Record<string, any>;
3674
+ [key: string]: any;
3675
+ };
3676
+ user: import("better-auth").User & Record<string, any>;
3677
+ }) => Promise<void | {
3678
+ data: Record<string, any>;
3679
+ }>;
3680
+ afterCreateOrganization?: (data: {
3681
+ organization: import("better-auth/plugins").Organization & Record<string, any>;
3682
+ member: import("better-auth/plugins").Member & Record<string, any>;
3683
+ user: import("better-auth").User & Record<string, any>;
3684
+ }) => Promise<void>;
3685
+ beforeUpdateOrganization?: (data: {
3686
+ organization: {
3687
+ name?: string;
3688
+ slug?: string;
3689
+ logo?: string | null;
3690
+ metadata?: Record<string, any>;
3691
+ [key: string]: any;
3692
+ };
3693
+ user: import("better-auth").User & Record<string, any>;
3694
+ member: import("better-auth/plugins").Member & Record<string, any>;
3695
+ }) => Promise<void | {
3696
+ data: {
3697
+ name?: string;
3698
+ slug?: string;
3699
+ logo?: string | null;
3700
+ metadata?: Record<string, any>;
3701
+ [key: string]: any;
3702
+ };
3703
+ }>;
3704
+ afterUpdateOrganization?: (data: {
3705
+ organization: (import("better-auth/plugins").Organization & Record<string, any>) | null;
3706
+ user: import("better-auth").User & Record<string, any>;
3707
+ member: import("better-auth/plugins").Member & Record<string, any>;
3708
+ }) => Promise<void>;
3709
+ beforeDeleteOrganization?: (data: {
3710
+ organization: import("better-auth/plugins").Organization & Record<string, any>;
3711
+ user: import("better-auth").User & Record<string, any>;
3712
+ }, ctx?: import("better-auth").GenericEndpointContext) => Promise<void>;
3713
+ afterDeleteOrganization?: (data: {
3714
+ organization: import("better-auth/plugins").Organization & Record<string, any>;
3715
+ user: import("better-auth").User & Record<string, any>;
3716
+ }, ctx?: import("better-auth").GenericEndpointContext) => Promise<void>;
3717
+ beforeAddMember?: (data: {
3718
+ member: {
3719
+ userId: string;
3720
+ organizationId: string;
3721
+ role: string;
3722
+ [key: string]: any;
3723
+ };
3724
+ user: import("better-auth").User & Record<string, any>;
3725
+ organization: import("better-auth/plugins").Organization & Record<string, any>;
3726
+ }) => Promise<void | {
3727
+ data: Record<string, any>;
3728
+ }>;
3729
+ afterAddMember?: (data: {
3730
+ member: import("better-auth/plugins").Member & Record<string, any>;
3731
+ user: import("better-auth").User & Record<string, any>;
3732
+ organization: import("better-auth/plugins").Organization & Record<string, any>;
3733
+ }) => Promise<void>;
3734
+ beforeRemoveMember?: (data: {
3735
+ member: import("better-auth/plugins").Member & Record<string, any>;
3736
+ user: import("better-auth").User & Record<string, any>;
3737
+ organization: import("better-auth/plugins").Organization & Record<string, any>;
3738
+ }) => Promise<void>;
3739
+ afterRemoveMember?: (data: {
3740
+ member: import("better-auth/plugins").Member & Record<string, any>;
3741
+ user: import("better-auth").User & Record<string, any>;
3742
+ organization: import("better-auth/plugins").Organization & Record<string, any>;
3743
+ }) => Promise<void>;
3744
+ beforeUpdateMemberRole?: (data: {
3745
+ member: import("better-auth/plugins").Member & Record<string, any>;
3746
+ newRole: string;
3747
+ user: import("better-auth").User & Record<string, any>;
3748
+ organization: import("better-auth/plugins").Organization & Record<string, any>;
3749
+ }) => Promise<void | {
3750
+ data: {
3751
+ role: string;
3752
+ [key: string]: any;
3753
+ };
3754
+ }>;
3755
+ afterUpdateMemberRole?: (data: {
3756
+ member: import("better-auth/plugins").Member & Record<string, any>;
3757
+ previousRole: string;
3758
+ user: import("better-auth").User & Record<string, any>;
3759
+ organization: import("better-auth/plugins").Organization & Record<string, any>;
3760
+ }) => Promise<void>;
3761
+ beforeCreateInvitation?: (data: {
3762
+ invitation: {
3763
+ email: string;
3764
+ role: string;
3765
+ organizationId: string;
3766
+ inviterId: string;
3767
+ teamId?: string;
3768
+ [key: string]: any;
3769
+ };
3770
+ inviter: import("better-auth").User & Record<string, any>;
3771
+ organization: import("better-auth/plugins").Organization & Record<string, any>;
3772
+ }) => Promise<void | {
3773
+ data: Record<string, any>;
3774
+ }>;
3775
+ afterCreateInvitation?: (data: {
3776
+ invitation: import("better-auth/plugins").Invitation & Record<string, any>;
3777
+ inviter: import("better-auth").User & Record<string, any>;
3778
+ organization: import("better-auth/plugins").Organization & Record<string, any>;
3779
+ }) => Promise<void>;
3780
+ beforeAcceptInvitation?: (data: {
3781
+ invitation: import("better-auth/plugins").Invitation & Record<string, any>;
3782
+ user: import("better-auth").User & Record<string, any>;
3783
+ organization: import("better-auth/plugins").Organization & Record<string, any>;
3784
+ }) => Promise<void>;
3785
+ afterAcceptInvitation?: (data: {
3786
+ invitation: import("better-auth/plugins").Invitation & Record<string, any>;
3787
+ member: import("better-auth/plugins").Member & Record<string, any>;
3788
+ user: import("better-auth").User & Record<string, any>;
3789
+ organization: import("better-auth/plugins").Organization & Record<string, any>;
3790
+ }) => Promise<void>;
3791
+ beforeRejectInvitation?: (data: {
3792
+ invitation: import("better-auth/plugins").Invitation & Record<string, any>;
3793
+ user: import("better-auth").User & Record<string, any>;
3794
+ organization: import("better-auth/plugins").Organization & Record<string, any>;
3795
+ }) => Promise<void>;
3796
+ afterRejectInvitation?: (data: {
3797
+ invitation: import("better-auth/plugins").Invitation & Record<string, any>;
3798
+ user: import("better-auth").User & Record<string, any>;
3799
+ organization: import("better-auth/plugins").Organization & Record<string, any>;
3800
+ }) => Promise<void>;
3801
+ beforeCancelInvitation?: (data: {
3802
+ invitation: import("better-auth/plugins").Invitation & Record<string, any>;
3803
+ cancelledBy: import("better-auth").User & Record<string, any>;
3804
+ organization: import("better-auth/plugins").Organization & Record<string, any>;
3805
+ }) => Promise<void>;
3806
+ afterCancelInvitation?: (data: {
3807
+ invitation: import("better-auth/plugins").Invitation & Record<string, any>;
3808
+ cancelledBy: import("better-auth").User & Record<string, any>;
3809
+ organization: import("better-auth/plugins").Organization & Record<string, any>;
3810
+ }) => Promise<void>;
3811
+ beforeCreateTeam?: (data: {
3812
+ team: {
3813
+ name: string;
3814
+ organizationId: string;
3815
+ [key: string]: any;
3816
+ };
3817
+ user?: import("better-auth").User & Record<string, any>;
3818
+ organization: import("better-auth/plugins").Organization & Record<string, any>;
3819
+ }) => Promise<void | {
3820
+ data: Record<string, any>;
3821
+ }>;
3822
+ afterCreateTeam?: (data: {
3823
+ team: import("better-auth/plugins").Team & Record<string, any>;
3824
+ user?: import("better-auth").User & Record<string, any>;
3825
+ organization: import("better-auth/plugins").Organization & Record<string, any>;
3826
+ }) => Promise<void>;
3827
+ beforeUpdateTeam?: (data: {
3828
+ team: import("better-auth/plugins").Team & Record<string, any>;
3829
+ updates: {
3830
+ name?: string;
3831
+ [key: string]: any;
3832
+ };
3833
+ user: import("better-auth").User & Record<string, any>;
3834
+ organization: import("better-auth/plugins").Organization & Record<string, any>;
3835
+ }) => Promise<void | {
3836
+ data: Record<string, any>;
3837
+ }>;
3838
+ afterUpdateTeam?: (data: {
3839
+ team: (import("better-auth/plugins").Team & Record<string, any>) | null;
3840
+ user: import("better-auth").User & Record<string, any>;
3841
+ organization: import("better-auth/plugins").Organization & Record<string, any>;
3842
+ }) => Promise<void>;
3843
+ beforeDeleteTeam?: (data: {
3844
+ team: import("better-auth/plugins").Team & Record<string, any>;
3845
+ user?: import("better-auth").User & Record<string, any>;
3846
+ organization: import("better-auth/plugins").Organization & Record<string, any>;
3847
+ }) => Promise<void>;
3848
+ afterDeleteTeam?: (data: {
3849
+ team: import("better-auth/plugins").Team & Record<string, any>;
3850
+ user?: import("better-auth").User & Record<string, any>;
3851
+ organization: import("better-auth/plugins").Organization & Record<string, any>;
3852
+ }) => Promise<void>;
3853
+ beforeAddTeamMember?: (data: {
3854
+ teamMember: {
3855
+ teamId: string;
3856
+ userId: string;
3857
+ [key: string]: any;
3858
+ };
3859
+ team: import("better-auth/plugins").Team & Record<string, any>;
3860
+ user: import("better-auth").User & Record<string, any>;
3861
+ organization: import("better-auth/plugins").Organization & Record<string, any>;
3862
+ }) => Promise<void | {
3863
+ data: Record<string, any>;
3864
+ }>;
3865
+ afterAddTeamMember?: (data: {
3866
+ teamMember: import("better-auth/plugins").TeamMember & Record<string, any>;
3867
+ team: import("better-auth/plugins").Team & Record<string, any>;
3868
+ user: import("better-auth").User & Record<string, any>;
3869
+ organization: import("better-auth/plugins").Organization & Record<string, any>;
3870
+ }) => Promise<void>;
3871
+ beforeRemoveTeamMember?: (data: {
3872
+ teamMember: import("better-auth/plugins").TeamMember & Record<string, any>;
3873
+ team: import("better-auth/plugins").Team & Record<string, any>;
3874
+ user: import("better-auth").User & Record<string, any>;
3875
+ organization: import("better-auth/plugins").Organization & Record<string, any>;
3876
+ }) => Promise<void>;
3877
+ afterRemoveTeamMember?: (data: {
3878
+ teamMember: import("better-auth/plugins").TeamMember & Record<string, any>;
3879
+ team: import("better-auth/plugins").Team & Record<string, any>;
3880
+ user: import("better-auth").User & Record<string, any>;
3881
+ organization: import("better-auth/plugins").Organization & Record<string, any>;
3882
+ }) => Promise<void>;
3883
+ };
3884
+ sendInvitationEmail?: (({ invitation, organization, inviter }: {
3885
+ id: string;
3886
+ role: string;
3887
+ email: string;
3888
+ organization: import("better-auth/plugins").Organization;
3889
+ invitation: import("better-auth/plugins").Invitation;
3890
+ inviter: import("better-auth/plugins").Member & {
3891
+ user: import("better-auth").User;
3892
+ };
3893
+ }) => Promise<void>) | undefined;
3894
+ creatorRole: string;
3895
+ allowUserToCreateOrganization: (user: {
3896
+ id: string;
3897
+ createdAt: Date;
3898
+ updatedAt: Date;
3899
+ email: string;
3900
+ emailVerified: boolean;
3901
+ name: string;
3902
+ image?: string | null | undefined;
3903
+ } & Record<string, any>) => boolean;
3904
+ invitationExpiresIn: number;
3905
+ membershipLimit: number;
3906
+ requireEmailVerificationOnInvitation: true;
3907
+ cancelPendingInvitationsOnReInvite: true;
3908
+ schema: {
3909
+ organization: {
3910
+ fields: {
3911
+ createdAt: string;
3912
+ };
3913
+ };
3914
+ member: {
3915
+ fields: {
3916
+ organizationId: string;
3917
+ userId: string;
3918
+ createdAt: string;
3919
+ };
3920
+ additionalFields: {
3921
+ appRoles: {
3922
+ type: "string[]";
3923
+ required: false;
3924
+ defaultValue: never[];
3925
+ input: false;
3926
+ fieldName: string;
3927
+ };
3928
+ };
3929
+ };
3930
+ invitation: {
3931
+ fields: {
3932
+ organizationId: string;
3933
+ inviterId: string;
3934
+ expiresAt: string;
3935
+ createdAt: string;
3936
+ };
3937
+ additionalFields: {
3938
+ appRoles: {
3939
+ type: "string[]";
3940
+ required: false;
3941
+ defaultValue: never[];
3942
+ input: true;
3943
+ fieldName: string;
3944
+ };
3945
+ };
3946
+ };
3947
+ session: {
3948
+ fields: {
3949
+ activeOrganizationId: string;
3950
+ };
3951
+ };
3952
+ };
3953
+ }> | {
3954
+ id: "protobase-organizations";
3955
+ endpoints: {
3956
+ setAppRoles: import("better-auth").StrictEndpoint<"/organization/set-app-roles", {
3957
+ method: "POST";
3958
+ use: import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<{
3959
+ session: {
3960
+ session: Record<string, any> & {
3961
+ id: string;
3962
+ createdAt: Date;
3963
+ updatedAt: Date;
3964
+ userId: string;
3965
+ expiresAt: Date;
3966
+ token: string;
3967
+ ipAddress?: string | null | undefined;
3968
+ userAgent?: string | null | undefined;
3969
+ };
3970
+ user: Record<string, any> & {
3971
+ id: string;
3972
+ createdAt: Date;
3973
+ updatedAt: Date;
3974
+ email: string;
3975
+ emailVerified: boolean;
3976
+ name: string;
3977
+ image?: string | null | undefined;
3978
+ };
3979
+ };
3980
+ }>>[];
3981
+ body: import("zod").ZodObject<{
3982
+ memberId: import("zod").ZodString;
3983
+ appRoles: import("zod").ZodArray<import("zod").ZodString>;
3984
+ }, import("zod/v4/core").$strip>;
3985
+ }, {
3986
+ member: {
3987
+ appRoles: string[];
3988
+ id: string;
3989
+ organizationId: string;
3990
+ userId: string;
3991
+ role: string;
3992
+ createdAt: Date;
3993
+ };
3994
+ }>;
3995
+ transferOwnership: import("better-auth").StrictEndpoint<"/organization/transfer-ownership", {
3996
+ method: "POST";
3997
+ use: import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<{
3998
+ session: {
3999
+ session: Record<string, any> & {
4000
+ id: string;
4001
+ createdAt: Date;
4002
+ updatedAt: Date;
4003
+ userId: string;
4004
+ expiresAt: Date;
4005
+ token: string;
4006
+ ipAddress?: string | null | undefined;
4007
+ userAgent?: string | null | undefined;
4008
+ };
4009
+ user: Record<string, any> & {
4010
+ id: string;
4011
+ createdAt: Date;
4012
+ updatedAt: Date;
4013
+ email: string;
4014
+ emailVerified: boolean;
4015
+ name: string;
4016
+ image?: string | null | undefined;
4017
+ };
4018
+ };
4019
+ }>>[];
4020
+ body: import("zod").ZodObject<{
4021
+ memberId: import("zod").ZodString;
4022
+ keepAs: import("zod").ZodOptional<import("zod").ZodEnum<{
4023
+ admin: "admin";
4024
+ member: "member";
4025
+ }>>;
4026
+ }, import("zod/v4/core").$strip>;
4027
+ }, {
4028
+ owner: string;
4029
+ }>;
4030
+ currentOrganization: import("better-auth").StrictEndpoint<"/organization/current", {
4031
+ method: "GET";
4032
+ use: import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<{
4033
+ session: {
4034
+ session: Record<string, any> & {
4035
+ id: string;
4036
+ createdAt: Date;
4037
+ updatedAt: Date;
4038
+ userId: string;
4039
+ expiresAt: Date;
4040
+ token: string;
4041
+ ipAddress?: string | null | undefined;
4042
+ userAgent?: string | null | undefined;
4043
+ };
4044
+ user: Record<string, any> & {
4045
+ id: string;
4046
+ createdAt: Date;
4047
+ updatedAt: Date;
4048
+ email: string;
4049
+ emailVerified: boolean;
4050
+ name: string;
4051
+ image?: string | null | undefined;
4052
+ };
4053
+ };
4054
+ }>>[];
4055
+ }, {
4056
+ organization: null;
4057
+ globalRoles: string[];
4058
+ } | {
4059
+ globalRoles: string[];
4060
+ role?: OrganizationRole | undefined;
4061
+ appRoles?: string[] | undefined;
4062
+ memberId?: string | undefined;
4063
+ organization: {
4064
+ id: string;
4065
+ name: string;
4066
+ slug: string;
4067
+ logo: string | null;
4068
+ };
4069
+ }>;
4070
+ searchOrganizations: import("better-auth").StrictEndpoint<"/organization/search", {
4071
+ method: "GET";
4072
+ use: import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<{
4073
+ session: {
4074
+ session: Record<string, any> & {
4075
+ id: string;
4076
+ createdAt: Date;
4077
+ updatedAt: Date;
4078
+ userId: string;
4079
+ expiresAt: Date;
4080
+ token: string;
4081
+ ipAddress?: string | null | undefined;
4082
+ userAgent?: string | null | undefined;
4083
+ };
4084
+ user: Record<string, any> & {
4085
+ id: string;
4086
+ createdAt: Date;
4087
+ updatedAt: Date;
4088
+ email: string;
4089
+ emailVerified: boolean;
4090
+ name: string;
4091
+ image?: string | null | undefined;
4092
+ };
4093
+ };
4094
+ }>>[];
4095
+ query: import("zod").ZodObject<{
4096
+ query: import("zod").ZodDefault<import("zod").ZodString>;
4097
+ }, import("zod/v4/core").$strip>;
4098
+ }, {
4099
+ organizations: {
4100
+ id: string;
4101
+ name: string;
4102
+ slug: string;
4103
+ }[];
4104
+ }>;
4105
+ getInvitation: import("better-auth").StrictEndpoint<"/invitation", {
4106
+ method: "GET";
4107
+ query: import("zod").ZodObject<{
4108
+ token: import("zod").ZodString;
4109
+ }, import("zod/v4/core").$strip>;
4110
+ }, {
4111
+ organization: {
4112
+ id: string;
4113
+ name: string;
4114
+ };
4115
+ inviter: {
4116
+ name: string;
4117
+ };
4118
+ email: string;
4119
+ role: string;
4120
+ appRoles: string[];
4121
+ expiresAt: string;
4122
+ hasAccount: boolean;
4123
+ }>;
4124
+ acceptInvitation: import("better-auth").StrictEndpoint<"/invitation/accept", {
4125
+ method: "POST";
4126
+ body: import("zod").ZodObject<{
4127
+ token: import("zod").ZodString;
4128
+ }, import("zod/v4/core").$strip>;
4129
+ use: import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<{
4130
+ session: {
4131
+ session: Record<string, any> & {
4132
+ id: string;
4133
+ createdAt: Date;
4134
+ updatedAt: Date;
4135
+ userId: string;
4136
+ expiresAt: Date;
4137
+ token: string;
4138
+ ipAddress?: string | null | undefined;
4139
+ userAgent?: string | null | undefined;
4140
+ };
4141
+ user: Record<string, any> & {
4142
+ id: string;
4143
+ createdAt: Date;
4144
+ updatedAt: Date;
4145
+ email: string;
4146
+ emailVerified: boolean;
4147
+ name: string;
4148
+ image?: string | null | undefined;
4149
+ };
4150
+ };
4151
+ }>>[];
4152
+ }, {
4153
+ member: {
4154
+ appRoles: string[];
4155
+ id: string;
4156
+ createdAt: Date;
4157
+ userId: string;
4158
+ role: string;
4159
+ organizationId: string;
4160
+ };
4161
+ }>;
4162
+ signUpFromInvitation: import("better-auth").StrictEndpoint<"/invitation/sign-up", {
4163
+ method: "POST";
4164
+ body: import("zod").ZodObject<{
4165
+ token: import("zod").ZodString;
4166
+ name: import("zod").ZodString;
4167
+ password: import("zod").ZodOptional<import("zod").ZodString>;
4168
+ }, import("zod/v4/core").$strip>;
4169
+ }, {
4170
+ member: {
4171
+ appRoles: string[];
4172
+ id: string;
4173
+ createdAt: Date;
4174
+ userId: string;
4175
+ role: string;
4176
+ organizationId: string;
4177
+ };
4178
+ }>;
4179
+ };
4180
+ hooks: {
4181
+ after: {
4182
+ matcher: (context: {
4183
+ path?: string;
4184
+ }) => boolean;
4185
+ handler: import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<void>>;
4186
+ }[];
4187
+ };
4188
+ })[]];
3676
4189
  disabledPaths: string[];
3677
4190
  databaseHooks: {
4191
+ session?: {
4192
+ create: {
4193
+ before: (session: {
4194
+ userId: string;
4195
+ activeOrganizationId?: string | null;
4196
+ } & Record<string, unknown>) => Promise<{
4197
+ data: {
4198
+ activeOrganizationId: string;
4199
+ userId: string;
4200
+ };
4201
+ } | undefined>;
4202
+ };
4203
+ update: {
4204
+ after: (session: {
4205
+ userId: string;
4206
+ activeOrganizationId?: string | null;
4207
+ }) => Promise<void>;
4208
+ };
4209
+ } | undefined;
3678
4210
  user: {
3679
4211
  create: {
3680
4212
  after?: ((user: import("better-auth").User & Record<string, unknown>, context: import("better-auth").GenericEndpointContext | null) => Promise<void>) | undefined;
@@ -3713,6 +4245,10 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
3713
4245
  window: number;
3714
4246
  max: number;
3715
4247
  };
4248
+ '/invitation/sign-up': {
4249
+ window: number;
4250
+ max: number;
4251
+ };
3716
4252
  };
3717
4253
  };
3718
4254
  advanced: {
@@ -3746,6 +4282,8 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
3746
4282
  };
3747
4283
  }> & {
3748
4284
  roles: string[];
4285
+ roleDefinitions: RoleDefinitions;
4286
+ organizations: ResolvedOrganizations | undefined;
3749
4287
  defaultRole: string | undefined;
3750
4288
  mail: boolean;
3751
4289
  passwordReset: boolean;