@protobase/server 0.6.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 (105) 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/auth-schema.d.ts +4 -2
  9. package/dist/better-auth/auth-schema.js +18 -8
  10. package/dist/better-auth/authenticator.d.ts +7 -3
  11. package/dist/better-auth/authenticator.js +24 -3
  12. package/dist/better-auth/create-auth.d.ts +683 -10
  13. package/dist/better-auth/create-auth.js +72 -27
  14. package/dist/better-auth/organizations/accept-invitation.js +80 -0
  15. package/dist/better-auth/organizations/active-organization.js +12 -0
  16. package/dist/better-auth/organizations/admin-routes.js +83 -0
  17. package/dist/better-auth/organizations/app-roles.js +43 -0
  18. package/dist/better-auth/organizations/host.d.ts +53 -0
  19. package/dist/better-auth/organizations/host.js +251 -0
  20. package/dist/better-auth/organizations/invitation-endpoints.js +133 -0
  21. package/dist/better-auth/organizations/invitation-mail.js +17 -0
  22. package/dist/better-auth/organizations/invitation-token.js +27 -0
  23. package/dist/better-auth/organizations/member-endpoints.js +182 -0
  24. package/dist/better-auth/organizations/options.d.ts +48 -0
  25. package/dist/better-auth/organizations/options.js +23 -0
  26. package/dist/better-auth/organizations/organization-plugin.js +128 -0
  27. package/dist/better-auth/organizations/protobase-plugin.js +21 -0
  28. package/dist/better-auth/organizations/role-definitions.d.ts +15 -0
  29. package/dist/better-auth/organizations/role-definitions.js +56 -0
  30. package/dist/better-auth/organizations/session-organization.js +68 -0
  31. package/dist/better-auth/organizations/store.d.ts +19 -0
  32. package/dist/better-auth/organizations/store.js +73 -0
  33. package/dist/better-auth/policy-store.js +44 -35
  34. package/dist/better-auth/snake-case-migration.js +122 -0
  35. package/dist/better-auth/snake-case-names.js +72 -0
  36. package/dist/better-auth/staff-checks.js +5 -1
  37. package/dist/better-auth/staff-log.js +56 -45
  38. package/dist/better-auth/staff-sign-in-endpoints.js +1 -1
  39. package/dist/better-auth/status-route.js +14 -3
  40. package/dist/better-auth/users.d.ts +2 -1
  41. package/dist/better-auth/users.js +4 -1
  42. package/dist/create-admin.d.ts +8 -2
  43. package/dist/create-admin.js +31 -2
  44. package/dist/deps.d.ts +1 -0
  45. package/dist/files/attach.js +80 -0
  46. package/dist/files/cleanup-runner.d.ts +8 -0
  47. package/dist/files/cleanup-runner.js +58 -0
  48. package/dist/files/cleanup-schedule.d.ts +28 -0
  49. package/dist/files/cleanup-schedule.js +48 -0
  50. package/dist/files/detect.js +51 -0
  51. package/dist/files/download-url.js +43 -0
  52. package/dist/files/download.js +90 -0
  53. package/dist/files/duration.js +35 -0
  54. package/dist/files/file-cleanup.d.ts +18 -0
  55. package/dist/files/file-cleanup.js +17 -0
  56. package/dist/files/local-files.d.ts +17 -0
  57. package/dist/files/local-files.js +101 -0
  58. package/dist/files/media-types.js +99 -0
  59. package/dist/files/options.d.ts +15 -0
  60. package/dist/files/present.d.ts +15 -0
  61. package/dist/files/present.js +59 -0
  62. package/dist/files/processors.d.ts +15 -0
  63. package/dist/files/processors.js +39 -0
  64. package/dist/files/providers.js +70 -0
  65. package/dist/files/routes.js +26 -0
  66. package/dist/files/runtime.d.ts +3 -0
  67. package/dist/files/runtime.js +37 -0
  68. package/dist/files/signer.js +32 -0
  69. package/dist/files/store.d.ts +37 -0
  70. package/dist/files/ticket.js +87 -0
  71. package/dist/files/upload-body.js +85 -0
  72. package/dist/files/upload.js +124 -0
  73. package/dist/files/uri.js +47 -0
  74. package/dist/functions/define-function.d.ts +71 -0
  75. package/dist/functions/define-function.js +36 -0
  76. package/dist/functions/function-app.d.ts +17 -0
  77. package/dist/functions/function-app.js +19 -0
  78. package/dist/functions/read-json.d.ts +35 -0
  79. package/dist/functions/read-json.js +24 -0
  80. package/dist/functions/records.d.ts +43 -0
  81. package/dist/functions/records.js +31 -0
  82. package/dist/functions/require-env.d.ts +7 -0
  83. package/dist/functions/require-env.js +12 -0
  84. package/dist/functions/routes.js +60 -0
  85. package/dist/functions/verify-signature.d.ts +32 -0
  86. package/dist/functions/verify-signature.js +49 -0
  87. package/dist/index.d.ts +21 -3
  88. package/dist/index.js +13 -3
  89. package/dist/list-service.js +4 -2
  90. package/dist/openapi/resource-paths.js +78 -1
  91. package/dist/openapi/schemas.js +28 -3
  92. package/dist/project-config.d.ts +7 -1
  93. package/dist/project-config.js +37 -1
  94. package/dist/read-service.js +5 -1
  95. package/dist/request-access.d.ts +5 -0
  96. package/dist/request-access.js +9 -4
  97. package/dist/resource-source.d.ts +4 -1
  98. package/dist/routes/batch.js +1 -1
  99. package/dist/routes/collection.js +3 -1
  100. package/dist/routes/record.js +2 -5
  101. package/dist/types.d.ts +25 -5
  102. package/dist/write-pipeline.js +2 -1
  103. package/dist/write-shared.js +6 -3
  104. package/dist/write-update.js +2 -1
  105. 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,18 +63,79 @@ 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<{
84
+ user: {
85
+ fields: {
86
+ emailVerified: string;
87
+ createdAt: string;
88
+ updatedAt: string;
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
+ };
104
+ };
105
+ session: {
106
+ fields: {
107
+ expiresAt: string;
108
+ createdAt: string;
109
+ updatedAt: string;
110
+ ipAddress: string;
111
+ userAgent: string;
112
+ userId: string;
113
+ };
114
+ };
115
+ verification: {
116
+ fields: {
117
+ expiresAt: string;
118
+ createdAt: string;
119
+ updatedAt: string;
120
+ };
121
+ };
65
122
  account: {
66
123
  encryptOAuthTokens?: true | undefined;
67
124
  accountLinking: {
68
125
  allowDifferentEmails: true;
69
126
  };
127
+ fields: {
128
+ accountId: string;
129
+ providerId: string;
130
+ userId: string;
131
+ accessToken: string;
132
+ refreshToken: string;
133
+ idToken: string;
134
+ accessTokenExpiresAt: string;
135
+ refreshTokenExpiresAt: string;
136
+ createdAt: string;
137
+ updatedAt: string;
138
+ };
70
139
  };
71
140
  plugins: [{
72
141
  id: "admin";
@@ -954,6 +1023,19 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
954
1023
  };
955
1024
  };
956
1025
  options: NoInfer<{
1026
+ schema: {
1027
+ user: {
1028
+ fields: {
1029
+ banReason: string;
1030
+ banExpires: string;
1031
+ };
1032
+ };
1033
+ session: {
1034
+ fields: {
1035
+ impersonatedBy: string;
1036
+ };
1037
+ };
1038
+ };
957
1039
  defaultRole: string;
958
1040
  roles: {
959
1041
  [k: string]: import("better-auth/plugins").Role<import("better-auth/plugins").ExactRoleStatements<{
@@ -975,17 +1057,45 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
975
1057
  id: "jwt";
976
1058
  version: string;
977
1059
  options: NoInfer<{
1060
+ schema: {
1061
+ jwks: {
1062
+ fields: {
1063
+ publicKey: string;
1064
+ privateKey: string;
1065
+ createdAt: string;
1066
+ expiresAt: string;
1067
+ };
1068
+ };
1069
+ };
978
1070
  jwt: {
979
1071
  expirationTime: string;
980
1072
  issuer: string;
981
1073
  audience: string;
982
- definePayload: ({ user }: {
1074
+ definePayload: ({ user, session }: {
983
1075
  user: import("better-auth").User & Record<string, any>;
984
1076
  session: import("better-auth").Session & Record<string, any>;
985
- }) => {
1077
+ }) => Promise<{
986
1078
  email: string;
987
1079
  role: any;
988
- };
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
+ }>;
989
1099
  };
990
1100
  disableSettingJwtHeader: true;
991
1101
  }>;
@@ -3017,10 +3127,11 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
3017
3127
  INVALID_OAUTH_CONFIGURATION: import("better-auth").RawError<"INVALID_OAUTH_CONFIGURATION">;
3018
3128
  TOKEN_URL_NOT_FOUND: import("better-auth").RawError<"TOKEN_URL_NOT_FOUND">;
3019
3129
  };
3020
- })[], {
3130
+ } | {
3021
3131
  id: "protobase-sign-in-policy";
3022
3132
  schema: {
3023
3133
  readonly signInPolicy: {
3134
+ readonly modelName: "sign_in_policy";
3024
3135
  readonly fields: {
3025
3136
  readonly password: {
3026
3137
  readonly type: "string";
@@ -3029,6 +3140,7 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
3029
3140
  readonly emailCode: {
3030
3141
  readonly type: "string";
3031
3142
  readonly required: true;
3143
+ readonly fieldName: "email_code";
3032
3144
  };
3033
3145
  readonly passkey: {
3034
3146
  readonly type: "string";
@@ -3037,24 +3149,29 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
3037
3149
  readonly twoFactor: {
3038
3150
  readonly type: "string";
3039
3151
  readonly required: true;
3152
+ readonly fieldName: "two_factor";
3040
3153
  };
3041
3154
  readonly staffAccess: {
3042
3155
  readonly type: "string";
3043
3156
  readonly required: true;
3044
3157
  readonly defaultValue: "allowed";
3158
+ readonly fieldName: "staff_access";
3045
3159
  };
3046
3160
  readonly platformSignIn: {
3047
3161
  readonly type: "string";
3048
3162
  readonly required: true;
3049
3163
  readonly defaultValue: "allowed";
3164
+ readonly fieldName: "platform_sign_in";
3050
3165
  };
3051
3166
  readonly createdAt: {
3052
3167
  readonly type: "date";
3053
3168
  readonly required: true;
3169
+ readonly fieldName: "created_at";
3054
3170
  };
3055
3171
  readonly createdBy: {
3056
3172
  readonly type: "string";
3057
3173
  readonly required: false;
3174
+ readonly fieldName: "created_by";
3058
3175
  };
3059
3176
  };
3060
3177
  };
@@ -3299,7 +3416,7 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
3299
3416
  twoFactor: boolean;
3300
3417
  authenticatorApp: boolean;
3301
3418
  };
3302
- missing: ("passkey" | "twoFactor")[];
3419
+ missing: ("twoFactor" | "passkey")[];
3303
3420
  }>;
3304
3421
  };
3305
3422
  hooks: {
@@ -3308,18 +3425,21 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
3308
3425
  handler: import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<void>>;
3309
3426
  }[];
3310
3427
  };
3311
- }, {
3428
+ } | {
3312
3429
  id: "protobase-staff-sign-in";
3313
3430
  schema: {
3314
3431
  readonly staffSignIn: {
3432
+ readonly modelName: "staff_sign_in";
3315
3433
  readonly fields: {
3316
3434
  readonly userId: {
3317
3435
  readonly type: "string";
3318
3436
  readonly required: true;
3437
+ readonly fieldName: "user_id";
3319
3438
  };
3320
3439
  readonly userEmail: {
3321
3440
  readonly type: "string";
3322
3441
  readonly required: true;
3442
+ readonly fieldName: "user_email";
3323
3443
  };
3324
3444
  readonly staff: {
3325
3445
  readonly type: "string";
@@ -3328,10 +3448,12 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
3328
3448
  readonly staffName: {
3329
3449
  readonly type: "string";
3330
3450
  readonly required: false;
3451
+ readonly fieldName: "staff_name";
3331
3452
  };
3332
3453
  readonly staffSubject: {
3333
3454
  readonly type: "string";
3334
3455
  readonly required: true;
3456
+ readonly fieldName: "staff_subject";
3335
3457
  };
3336
3458
  readonly issuer: {
3337
3459
  readonly type: "string";
@@ -3344,18 +3466,22 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
3344
3466
  readonly sessionId: {
3345
3467
  readonly type: "string";
3346
3468
  readonly required: true;
3469
+ readonly fieldName: "session_id";
3347
3470
  };
3348
3471
  readonly startedAt: {
3349
3472
  readonly type: "date";
3350
3473
  readonly required: true;
3474
+ readonly fieldName: "started_at";
3351
3475
  };
3352
3476
  readonly expiresAt: {
3353
3477
  readonly type: "date";
3354
3478
  readonly required: true;
3479
+ readonly fieldName: "expires_at";
3355
3480
  };
3356
3481
  readonly endedAt: {
3357
3482
  readonly type: "date";
3358
3483
  readonly required: false;
3484
+ readonly fieldName: "ended_at";
3359
3485
  };
3360
3486
  };
3361
3487
  };
@@ -3537,9 +3663,550 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
3537
3663
  handler: import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<void>>;
3538
3664
  }[];
3539
3665
  };
3540
- }];
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
+ })[]];
3541
4189
  disabledPaths: string[];
3542
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;
3543
4210
  user: {
3544
4211
  create: {
3545
4212
  after?: ((user: import("better-auth").User & Record<string, unknown>, context: import("better-auth").GenericEndpointContext | null) => Promise<void>) | undefined;
@@ -3578,6 +4245,10 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
3578
4245
  window: number;
3579
4246
  max: number;
3580
4247
  };
4248
+ '/invitation/sign-up': {
4249
+ window: number;
4250
+ max: number;
4251
+ };
3581
4252
  };
3582
4253
  };
3583
4254
  advanced: {
@@ -3611,6 +4282,8 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
3611
4282
  };
3612
4283
  }> & {
3613
4284
  roles: string[];
4285
+ roleDefinitions: RoleDefinitions;
4286
+ organizations: ResolvedOrganizations | undefined;
3614
4287
  defaultRole: string | undefined;
3615
4288
  mail: boolean;
3616
4289
  passwordReset: boolean;