@voyant-travel/auth 0.113.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +225 -0
- package/dist/api-token-rotation.d.ts +54 -0
- package/dist/api-token-rotation.d.ts.map +1 -0
- package/dist/api-token-rotation.js +134 -0
- package/dist/api-token-rotation.js.map +1 -0
- package/dist/auth-facades.d.ts +62 -0
- package/dist/auth-facades.d.ts.map +1 -0
- package/dist/auth-facades.js +252 -0
- package/dist/auth-facades.js.map +1 -0
- package/dist/backend.d.ts +10 -0
- package/dist/backend.d.ts.map +1 -0
- package/dist/backend.js +15 -0
- package/dist/backend.js.map +1 -0
- package/dist/cloud-admin-session-public.d.ts +67 -0
- package/dist/cloud-admin-session-public.d.ts.map +1 -0
- package/dist/cloud-admin-session-public.js +2 -0
- package/dist/cloud-admin-session-public.js.map +1 -0
- package/dist/cloud-admin-session-revalidation-store.d.ts +17 -0
- package/dist/cloud-admin-session-revalidation-store.d.ts.map +1 -0
- package/dist/cloud-admin-session-revalidation-store.js +64 -0
- package/dist/cloud-admin-session-revalidation-store.js.map +1 -0
- package/dist/cloud-admin-session.d.ts +70 -0
- package/dist/cloud-admin-session.d.ts.map +1 -0
- package/dist/cloud-admin-session.js +319 -0
- package/dist/cloud-admin-session.js.map +1 -0
- package/dist/cloud-broker/assertion.d.ts +69 -0
- package/dist/cloud-broker/assertion.d.ts.map +1 -0
- package/dist/cloud-broker/assertion.js +226 -0
- package/dist/cloud-broker/assertion.js.map +1 -0
- package/dist/cloud-broker/state.d.ts +55 -0
- package/dist/cloud-broker/state.d.ts.map +1 -0
- package/dist/cloud-broker/state.js +191 -0
- package/dist/cloud-broker/state.js.map +1 -0
- package/dist/cloud-broker/utils.d.ts +7 -0
- package/dist/cloud-broker/utils.d.ts.map +1 -0
- package/dist/cloud-broker/utils.js +50 -0
- package/dist/cloud-broker/utils.js.map +1 -0
- package/dist/cloud-broker.d.ts +5 -0
- package/dist/cloud-broker.d.ts.map +1 -0
- package/dist/cloud-broker.js +3 -0
- package/dist/cloud-broker.js.map +1 -0
- package/dist/edge.d.ts +28 -0
- package/dist/edge.d.ts.map +1 -0
- package/dist/edge.js +106 -0
- package/dist/edge.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +42 -0
- package/dist/index.js.map +1 -0
- package/dist/permissions.d.ts +141 -0
- package/dist/permissions.d.ts.map +1 -0
- package/dist/permissions.js +46 -0
- package/dist/permissions.js.map +1 -0
- package/dist/server.d.ts +106 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +193 -0
- package/dist/server.js.map +1 -0
- package/dist/trusted-origins.d.ts +9 -0
- package/dist/trusted-origins.d.ts.map +1 -0
- package/dist/trusted-origins.js +41 -0
- package/dist/trusted-origins.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/workspace.d.ts +43 -0
- package/dist/workspace.d.ts.map +1 -0
- package/dist/workspace.js +146 -0
- package/dist/workspace.js.map +1 -0
- package/package.json +81 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
export declare const voyantStatements: {
|
|
2
|
+
readonly operator: readonly ["create", "read", "update", "delete"];
|
|
3
|
+
readonly connection: readonly ["create", "read", "update", "delete"];
|
|
4
|
+
readonly oauthClient: readonly ["create", "read", "revoke"];
|
|
5
|
+
readonly apiKey: readonly ["create", "read", "update", "delete"];
|
|
6
|
+
readonly operatorGrant: readonly ["create", "read", "update", "delete"];
|
|
7
|
+
readonly auditLog: readonly ["read"];
|
|
8
|
+
readonly settings: readonly ["read", "update"];
|
|
9
|
+
readonly organization: readonly ["update", "delete"];
|
|
10
|
+
readonly member: readonly ["create", "update", "delete"];
|
|
11
|
+
readonly invitation: readonly ["create", "cancel"];
|
|
12
|
+
readonly team: readonly ["create", "update", "delete"];
|
|
13
|
+
readonly ac: readonly ["create", "read", "update", "delete"];
|
|
14
|
+
};
|
|
15
|
+
export declare const ac: {
|
|
16
|
+
newRole<const TRoleStatements extends import("better-auth/plugins").Statements>(statements: import("better-auth/plugins").RoleInput<{
|
|
17
|
+
readonly operator: readonly ["create", "read", "update", "delete"];
|
|
18
|
+
readonly connection: readonly ["create", "read", "update", "delete"];
|
|
19
|
+
readonly oauthClient: readonly ["create", "read", "revoke"];
|
|
20
|
+
readonly apiKey: readonly ["create", "read", "update", "delete"];
|
|
21
|
+
readonly operatorGrant: readonly ["create", "read", "update", "delete"];
|
|
22
|
+
readonly auditLog: readonly ["read"];
|
|
23
|
+
readonly settings: readonly ["read", "update"];
|
|
24
|
+
readonly organization: readonly ["update", "delete"];
|
|
25
|
+
readonly member: readonly ["create", "update", "delete"];
|
|
26
|
+
readonly invitation: readonly ["create", "cancel"];
|
|
27
|
+
readonly team: readonly ["create", "update", "delete"];
|
|
28
|
+
readonly ac: readonly ["create", "read", "update", "delete"];
|
|
29
|
+
}, TRoleStatements>): import("better-auth/plugins").Role<import("better-auth/plugins").ExactRoleStatements<TRoleStatements>, {
|
|
30
|
+
readonly operator: readonly ["create", "read", "update", "delete"];
|
|
31
|
+
readonly connection: readonly ["create", "read", "update", "delete"];
|
|
32
|
+
readonly oauthClient: readonly ["create", "read", "revoke"];
|
|
33
|
+
readonly apiKey: readonly ["create", "read", "update", "delete"];
|
|
34
|
+
readonly operatorGrant: readonly ["create", "read", "update", "delete"];
|
|
35
|
+
readonly auditLog: readonly ["read"];
|
|
36
|
+
readonly settings: readonly ["read", "update"];
|
|
37
|
+
readonly organization: readonly ["update", "delete"];
|
|
38
|
+
readonly member: readonly ["create", "update", "delete"];
|
|
39
|
+
readonly invitation: readonly ["create", "cancel"];
|
|
40
|
+
readonly team: readonly ["create", "update", "delete"];
|
|
41
|
+
readonly ac: readonly ["create", "read", "update", "delete"];
|
|
42
|
+
}>;
|
|
43
|
+
statements: {
|
|
44
|
+
readonly operator: readonly ["create", "read", "update", "delete"];
|
|
45
|
+
readonly connection: readonly ["create", "read", "update", "delete"];
|
|
46
|
+
readonly oauthClient: readonly ["create", "read", "revoke"];
|
|
47
|
+
readonly apiKey: readonly ["create", "read", "update", "delete"];
|
|
48
|
+
readonly operatorGrant: readonly ["create", "read", "update", "delete"];
|
|
49
|
+
readonly auditLog: readonly ["read"];
|
|
50
|
+
readonly settings: readonly ["read", "update"];
|
|
51
|
+
readonly organization: readonly ["update", "delete"];
|
|
52
|
+
readonly member: readonly ["create", "update", "delete"];
|
|
53
|
+
readonly invitation: readonly ["create", "cancel"];
|
|
54
|
+
readonly team: readonly ["create", "update", "delete"];
|
|
55
|
+
readonly ac: readonly ["create", "read", "update", "delete"];
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
export declare const roles: {
|
|
59
|
+
owner: import("better-auth/plugins").Role<import("better-auth/plugins").ExactRoleStatements<{
|
|
60
|
+
readonly organization: readonly ["update", "delete"];
|
|
61
|
+
readonly member: readonly ["create", "update", "delete"];
|
|
62
|
+
readonly invitation: readonly ["create", "cancel"];
|
|
63
|
+
readonly team: readonly ["create", "update", "delete"];
|
|
64
|
+
readonly ac: readonly ["create", "read", "update", "delete"];
|
|
65
|
+
readonly operator: ["create", "read", "update", "delete"];
|
|
66
|
+
readonly connection: ["create", "read", "update", "delete"];
|
|
67
|
+
readonly oauthClient: ["create", "read", "revoke"];
|
|
68
|
+
readonly apiKey: ["create", "read", "update", "delete"];
|
|
69
|
+
readonly operatorGrant: ["create", "read", "update", "delete"];
|
|
70
|
+
readonly auditLog: ["read"];
|
|
71
|
+
readonly settings: ["read", "update"];
|
|
72
|
+
}>, {
|
|
73
|
+
readonly operator: readonly ["create", "read", "update", "delete"];
|
|
74
|
+
readonly connection: readonly ["create", "read", "update", "delete"];
|
|
75
|
+
readonly oauthClient: readonly ["create", "read", "revoke"];
|
|
76
|
+
readonly apiKey: readonly ["create", "read", "update", "delete"];
|
|
77
|
+
readonly operatorGrant: readonly ["create", "read", "update", "delete"];
|
|
78
|
+
readonly auditLog: readonly ["read"];
|
|
79
|
+
readonly settings: readonly ["read", "update"];
|
|
80
|
+
readonly organization: readonly ["update", "delete"];
|
|
81
|
+
readonly member: readonly ["create", "update", "delete"];
|
|
82
|
+
readonly invitation: readonly ["create", "cancel"];
|
|
83
|
+
readonly team: readonly ["create", "update", "delete"];
|
|
84
|
+
readonly ac: readonly ["create", "read", "update", "delete"];
|
|
85
|
+
}>;
|
|
86
|
+
admin: import("better-auth/plugins").Role<import("better-auth/plugins").ExactRoleStatements<{
|
|
87
|
+
readonly organization: readonly ["update"];
|
|
88
|
+
readonly invitation: readonly ["create", "cancel"];
|
|
89
|
+
readonly member: readonly ["create", "update", "delete"];
|
|
90
|
+
readonly team: readonly ["create", "update", "delete"];
|
|
91
|
+
readonly ac: readonly ["create", "read", "update", "delete"];
|
|
92
|
+
readonly operator: ["create", "read", "update"];
|
|
93
|
+
readonly connection: ["create", "read", "update", "delete"];
|
|
94
|
+
readonly oauthClient: ["create", "read", "revoke"];
|
|
95
|
+
readonly apiKey: ["create", "read", "update", "delete"];
|
|
96
|
+
readonly operatorGrant: ["create", "read", "update"];
|
|
97
|
+
readonly auditLog: ["read"];
|
|
98
|
+
readonly settings: ["read"];
|
|
99
|
+
}>, {
|
|
100
|
+
readonly operator: readonly ["create", "read", "update", "delete"];
|
|
101
|
+
readonly connection: readonly ["create", "read", "update", "delete"];
|
|
102
|
+
readonly oauthClient: readonly ["create", "read", "revoke"];
|
|
103
|
+
readonly apiKey: readonly ["create", "read", "update", "delete"];
|
|
104
|
+
readonly operatorGrant: readonly ["create", "read", "update", "delete"];
|
|
105
|
+
readonly auditLog: readonly ["read"];
|
|
106
|
+
readonly settings: readonly ["read", "update"];
|
|
107
|
+
readonly organization: readonly ["update", "delete"];
|
|
108
|
+
readonly member: readonly ["create", "update", "delete"];
|
|
109
|
+
readonly invitation: readonly ["create", "cancel"];
|
|
110
|
+
readonly team: readonly ["create", "update", "delete"];
|
|
111
|
+
readonly ac: readonly ["create", "read", "update", "delete"];
|
|
112
|
+
}>;
|
|
113
|
+
member: import("better-auth/plugins").Role<import("better-auth/plugins").ExactRoleStatements<{
|
|
114
|
+
readonly organization: readonly [];
|
|
115
|
+
readonly member: readonly [];
|
|
116
|
+
readonly invitation: readonly [];
|
|
117
|
+
readonly team: readonly [];
|
|
118
|
+
readonly ac: readonly ["read"];
|
|
119
|
+
readonly operator: ["read"];
|
|
120
|
+
readonly connection: ["read"];
|
|
121
|
+
readonly oauthClient: ["read"];
|
|
122
|
+
readonly apiKey: ["read"];
|
|
123
|
+
readonly operatorGrant: ["read"];
|
|
124
|
+
readonly auditLog: ["read"];
|
|
125
|
+
readonly settings: ["read"];
|
|
126
|
+
}>, {
|
|
127
|
+
readonly operator: readonly ["create", "read", "update", "delete"];
|
|
128
|
+
readonly connection: readonly ["create", "read", "update", "delete"];
|
|
129
|
+
readonly oauthClient: readonly ["create", "read", "revoke"];
|
|
130
|
+
readonly apiKey: readonly ["create", "read", "update", "delete"];
|
|
131
|
+
readonly operatorGrant: readonly ["create", "read", "update", "delete"];
|
|
132
|
+
readonly auditLog: readonly ["read"];
|
|
133
|
+
readonly settings: readonly ["read", "update"];
|
|
134
|
+
readonly organization: readonly ["update", "delete"];
|
|
135
|
+
readonly member: readonly ["create", "update", "delete"];
|
|
136
|
+
readonly invitation: readonly ["create", "cancel"];
|
|
137
|
+
readonly team: readonly ["create", "update", "delete"];
|
|
138
|
+
readonly ac: readonly ["create", "read", "update", "delete"];
|
|
139
|
+
}>;
|
|
140
|
+
};
|
|
141
|
+
//# sourceMappingURL=permissions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permissions.d.ts","sourceRoot":"","sources":["../src/permissions.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;CASnB,CAAA;AAEV,eAAO,MAAM,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAAwC,CAAA;AAEvD,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+BjB,CAAA"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { createAccessControl } from "better-auth/plugins/access";
|
|
2
|
+
import { adminAc, defaultStatements, memberAc, ownerAc, } from "better-auth/plugins/organization/access";
|
|
3
|
+
export const voyantStatements = {
|
|
4
|
+
...defaultStatements,
|
|
5
|
+
operator: ["create", "read", "update", "delete"],
|
|
6
|
+
connection: ["create", "read", "update", "delete"],
|
|
7
|
+
oauthClient: ["create", "read", "revoke"],
|
|
8
|
+
apiKey: ["create", "read", "update", "delete"],
|
|
9
|
+
operatorGrant: ["create", "read", "update", "delete"],
|
|
10
|
+
auditLog: ["read"],
|
|
11
|
+
settings: ["read", "update"],
|
|
12
|
+
};
|
|
13
|
+
export const ac = createAccessControl(voyantStatements);
|
|
14
|
+
export const roles = {
|
|
15
|
+
owner: ac.newRole({
|
|
16
|
+
operator: ["create", "read", "update", "delete"],
|
|
17
|
+
connection: ["create", "read", "update", "delete"],
|
|
18
|
+
oauthClient: ["create", "read", "revoke"],
|
|
19
|
+
apiKey: ["create", "read", "update", "delete"],
|
|
20
|
+
operatorGrant: ["create", "read", "update", "delete"],
|
|
21
|
+
auditLog: ["read"],
|
|
22
|
+
settings: ["read", "update"],
|
|
23
|
+
...ownerAc.statements,
|
|
24
|
+
}),
|
|
25
|
+
admin: ac.newRole({
|
|
26
|
+
operator: ["create", "read", "update"],
|
|
27
|
+
connection: ["create", "read", "update", "delete"],
|
|
28
|
+
oauthClient: ["create", "read", "revoke"],
|
|
29
|
+
apiKey: ["create", "read", "update", "delete"],
|
|
30
|
+
operatorGrant: ["create", "read", "update"],
|
|
31
|
+
auditLog: ["read"],
|
|
32
|
+
settings: ["read"],
|
|
33
|
+
...adminAc.statements,
|
|
34
|
+
}),
|
|
35
|
+
member: ac.newRole({
|
|
36
|
+
operator: ["read"],
|
|
37
|
+
connection: ["read"],
|
|
38
|
+
oauthClient: ["read"],
|
|
39
|
+
apiKey: ["read"],
|
|
40
|
+
operatorGrant: ["read"],
|
|
41
|
+
auditLog: ["read"],
|
|
42
|
+
settings: ["read"],
|
|
43
|
+
...memberAc.statements,
|
|
44
|
+
}),
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=permissions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permissions.js","sourceRoot":"","sources":["../src/permissions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAA;AAChE,OAAO,EACL,OAAO,EACP,iBAAiB,EACjB,QAAQ,EACR,OAAO,GACR,MAAM,yCAAyC,CAAA;AAEhD,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,GAAG,iBAAiB;IACpB,QAAQ,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC;IAChD,UAAU,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC;IAClD,WAAW,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC;IACzC,MAAM,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC;IAC9C,aAAa,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC;IACrD,QAAQ,EAAE,CAAC,MAAM,CAAC;IAClB,QAAQ,EAAE,CAAC,MAAM,EAAE,QAAQ,CAAC;CACpB,CAAA;AAEV,MAAM,CAAC,MAAM,EAAE,GAAG,mBAAmB,CAAC,gBAAgB,CAAC,CAAA;AAEvD,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC;QAChB,QAAQ,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC;QAChD,UAAU,EA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AAU;KACvB,CAAC;CACH,CAAA"}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { apiKey } from "@better-auth/api-key";
|
|
2
|
+
import { getDb } from "@voyant-travel/db";
|
|
3
|
+
import { type BetterAuthOptions } from "better-auth";
|
|
4
|
+
import { emailOTP } from "better-auth/plugins";
|
|
5
|
+
import type { BetterAuthPlugin } from "better-auth/types";
|
|
6
|
+
import type { AnyPgTable } from "drizzle-orm/pg-core";
|
|
7
|
+
export declare function getAuthSecret(): string;
|
|
8
|
+
export type { AccountProfileUpdateHandler, ApiTokenRotationStore, BetterAuthApiTokenManagement, HandleAccountProfileRequestOptions, HandleApiTokenManagementRequestOptions, } from "./auth-facades.js";
|
|
9
|
+
export { handleAccountProfileRequest, handleApiTokenManagementRequest } from "./auth-facades.js";
|
|
10
|
+
type DefinedBetterAuthUserOptions<UserOptions extends BetterAuthOptions["user"]> = UserOptions extends undefined ? Record<PropertyKey, never> : NonNullable<UserOptions>;
|
|
11
|
+
type ResolvedBetterAuthChangeEmail<UserOptions extends BetterAuthOptions["user"]> = DefinedBetterAuthUserOptions<UserOptions> extends {
|
|
12
|
+
changeEmail?: infer ChangeEmail;
|
|
13
|
+
} ? ChangeEmail extends {
|
|
14
|
+
enabled: infer Enabled;
|
|
15
|
+
} ? Omit<ChangeEmail, "enabled"> & {
|
|
16
|
+
enabled: Enabled;
|
|
17
|
+
} : NonNullable<ChangeEmail> & {
|
|
18
|
+
enabled: true;
|
|
19
|
+
} : {
|
|
20
|
+
enabled: true;
|
|
21
|
+
};
|
|
22
|
+
type ResolvedBetterAuthUserOptions<UserOptions extends BetterAuthOptions["user"]> = Omit<DefinedBetterAuthUserOptions<UserOptions>, "changeEmail"> & {
|
|
23
|
+
changeEmail: ResolvedBetterAuthChangeEmail<UserOptions>;
|
|
24
|
+
};
|
|
25
|
+
type VoyantBetterAuthPlugins = [ReturnType<typeof apiKey>, ReturnType<typeof emailOTP>];
|
|
26
|
+
type ResolvedBetterAuthPlugins<Plugins extends BetterAuthPlugin[] | undefined> = Plugins extends BetterAuthPlugin[] ? [...VoyantBetterAuthPlugins, ...Plugins] : VoyantBetterAuthPlugins;
|
|
27
|
+
export interface DisableSignupWhenUsersExistOptions {
|
|
28
|
+
/**
|
|
29
|
+
* Set to false when the consuming app owns all signup admission checks.
|
|
30
|
+
*
|
|
31
|
+
* Defaults to true.
|
|
32
|
+
*/
|
|
33
|
+
enabled?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* User surfaces that should keep the single-tenant signup guard. New users
|
|
36
|
+
* with only other explicit surfaces can still be created by customer-facing
|
|
37
|
+
* auth plugins such as phone OTP.
|
|
38
|
+
*
|
|
39
|
+
* Defaults to ["admin"]. Users without an explicit surfaces array are
|
|
40
|
+
* treated as admin users for backward compatibility.
|
|
41
|
+
*/
|
|
42
|
+
surfaces?: readonly string[];
|
|
43
|
+
}
|
|
44
|
+
type ResolvedCreateBetterAuthOptions<UserOptions extends BetterAuthOptions["user"], Plugins extends BetterAuthPlugin[] | undefined> = Omit<BetterAuthOptions, "plugins" | "user"> & {
|
|
45
|
+
plugins: ResolvedBetterAuthPlugins<Plugins>;
|
|
46
|
+
user: ResolvedBetterAuthUserOptions<UserOptions>;
|
|
47
|
+
};
|
|
48
|
+
export type BetterAuthDrizzleSchema = Record<string, AnyPgTable>;
|
|
49
|
+
export interface CreateBetterAuthOptions<UserOptions extends BetterAuthOptions["user"] = BetterAuthOptions["user"], Plugins extends BetterAuthPlugin[] | undefined = BetterAuthPlugin[] | undefined> {
|
|
50
|
+
db?: ReturnType<typeof getDb>;
|
|
51
|
+
secret?: string;
|
|
52
|
+
baseURL?: string;
|
|
53
|
+
basePath?: string;
|
|
54
|
+
trustedOrigins?: string[];
|
|
55
|
+
/**
|
|
56
|
+
* Additional Drizzle tables for Better Auth plugins. The consuming app owns
|
|
57
|
+
* matching migrations for every table passed here.
|
|
58
|
+
*/
|
|
59
|
+
extraSchema?: BetterAuthDrizzleSchema;
|
|
60
|
+
plugins?: Plugins;
|
|
61
|
+
user?: UserOptions;
|
|
62
|
+
disableSignupWhenUsersExist?: DisableSignupWhenUsersExistOptions;
|
|
63
|
+
/** Called when a user requests a password reset. If not provided, logs to console. */
|
|
64
|
+
sendResetPassword?: (data: {
|
|
65
|
+
user: {
|
|
66
|
+
email: string;
|
|
67
|
+
name: string;
|
|
68
|
+
};
|
|
69
|
+
url: string;
|
|
70
|
+
token: string;
|
|
71
|
+
}) => Promise<void>;
|
|
72
|
+
/** Called to send a verification OTP. If not provided, logs to console. */
|
|
73
|
+
sendVerificationOTP?: (data: {
|
|
74
|
+
email: string;
|
|
75
|
+
otp: string;
|
|
76
|
+
type: string;
|
|
77
|
+
}) => Promise<void>;
|
|
78
|
+
/**
|
|
79
|
+
* Better Auth session cookie cache: session data rides in a short-lived
|
|
80
|
+
* signed cookie so `getSession` skips the Postgres lookup on most
|
|
81
|
+
* requests. Enabled by default with a 5-minute TTL — the trade-off is
|
|
82
|
+
* that a revoked/expired session can stay usable for up to `maxAge`
|
|
83
|
+
* seconds. Pass `false` for revocation-sensitive deployments, or tune
|
|
84
|
+
* `maxAge` (seconds).
|
|
85
|
+
*/
|
|
86
|
+
sessionCookieCache?: false | {
|
|
87
|
+
maxAge?: number;
|
|
88
|
+
};
|
|
89
|
+
/** Better Auth secondary storage, typically Redis/KV, used for distributed rate limits. */
|
|
90
|
+
secondaryStorage?: BetterAuthOptions["secondaryStorage"];
|
|
91
|
+
/** Better Auth rate-limit config. Defaults to secondary storage when present. */
|
|
92
|
+
rateLimit?: BetterAuthOptions["rateLimit"];
|
|
93
|
+
/**
|
|
94
|
+
* Controls Better Auth's Secure cookie flag. Defaults to secure except in
|
|
95
|
+
* explicit local development (`NODE_ENV=development`).
|
|
96
|
+
*/
|
|
97
|
+
useSecureCookies?: boolean;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Framework-agnostic Better Auth factory.
|
|
101
|
+
*
|
|
102
|
+
* Accepts optional overrides for db, secret, baseURL, trustedOrigins.
|
|
103
|
+
* Does NOT depend on Next.js — safe to use in Hono workers, TanStack Start, etc.
|
|
104
|
+
*/
|
|
105
|
+
export declare function createBetterAuth<const UserOptions extends BetterAuthOptions["user"] = undefined, const Plugins extends BetterAuthPlugin[] | undefined = undefined>(options?: CreateBetterAuthOptions<UserOptions, Plugins>): import("better-auth").Auth<ResolvedCreateBetterAuthOptions<UserOptions, Plugins>>;
|
|
106
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAC7C,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAQzC,OAAO,EAAE,KAAK,iBAAiB,EAAc,MAAM,aAAa,CAAA;AAEhE,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAC9C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAEzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAKrD,wBAAgB,aAAa,IAAI,MAAM,CAQtC;AAED,YAAY,EACV,2BAA2B,EAC3B,qBAAqB,EACrB,4BAA4B,EAC5B,kCAAkC,EAClC,sCAAsC,GACvC,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,2BAA2B,EAAE,+BAA+B,EAAE,MAAM,mBAAmB,CAAA;AAEhG,KAAK,4BAA4B,CAAC,WAAW,SAAS,iBAAiB,CAAC,MAAM,CAAC,IAC7E,WAAW,SAAS,SAAS,GAAG,MAAM,CAAC,WAAW,EAAE,KAAK,CAAC,GAAG,WAAW,CAAC,WAAW,CAAC,CAAA;AAEvF,KAAK,6BAA6B,CAAC,WAAW,SAAS,iBAAiB,CAAC,MAAM,CAAC,IAC9E,4BAA4B,CAAC,WAAW,CAAC,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iBAAiB,CAAC,kBAAkB,CAAC,CAAA;IACxD,iFAAiF;IACjF,SAAS,CAAC,EAAE,iBAAiB,CAAC,WAAW,CAAC,CAAA;IAC1C;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,CAAC,WAAW,SAAS,iBAAiB,CAAC,MAAM,CAAC,GAAG,SAAS,EAC/D,KAAK,CAAC,OAAO,SAAS,gBAAgB,EAAE,GAAG,SAAS,GAAG,SAAS,EAChE,OAAO,GAAE,uBAAuB,CAAC,WAAW,EAAE,OAAO,CAAM,qFAgK5D"}
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { apiKey } from "@better-auth/api-key";
|
|
2
|
+
import { getDb } from "@voyant-travel/db";
|
|
3
|
+
import { apikeyTable, authAccount, authSession, authUser, authVerification, } from "@voyant-travel/db/schema/iam";
|
|
4
|
+
import { betterAuth } from "better-auth";
|
|
5
|
+
import { drizzleAdapter } from "better-auth/adapters/drizzle";
|
|
6
|
+
import { emailOTP } from "better-auth/plugins";
|
|
7
|
+
import { sql } from "drizzle-orm";
|
|
8
|
+
import { expandTrustedOrigins, getTrustedOrigins } from "./trusted-origins.js";
|
|
9
|
+
import { isFirstAuthUser, provisionCurrentUserProfile } from "./workspace.js";
|
|
10
|
+
export function getAuthSecret() {
|
|
11
|
+
const secret = process.env.BETTER_AUTH_SECRET || "";
|
|
12
|
+
if (!secret || secret.length < 32) {
|
|
13
|
+
throw new Error("Missing BETTER_AUTH_SECRET with at least 32 characters");
|
|
14
|
+
}
|
|
15
|
+
return secret;
|
|
16
|
+
}
|
|
17
|
+
export { handleAccountProfileRequest, handleApiTokenManagementRequest } from "./auth-facades.js";
|
|
18
|
+
const DEFAULT_SIGNUP_BLOCK_SURFACES = ["admin"];
|
|
19
|
+
function normalizeSignupBlockSurfaces(options) {
|
|
20
|
+
return options?.surfaces ?? DEFAULT_SIGNUP_BLOCK_SURFACES;
|
|
21
|
+
}
|
|
22
|
+
function isSignupBlockEnabled(options) {
|
|
23
|
+
return options?.enabled !== false;
|
|
24
|
+
}
|
|
25
|
+
function signupBlockAppliesToUser(user, blockedSurfaces) {
|
|
26
|
+
if (blockedSurfaces.length === 0)
|
|
27
|
+
return false;
|
|
28
|
+
const surfaces = user?.surfaces;
|
|
29
|
+
if (Array.isArray(surfaces)) {
|
|
30
|
+
const explicitSurfaces = surfaces.filter((surface) => typeof surface === "string" && surface.trim().length > 0);
|
|
31
|
+
if (explicitSurfaces.length > 0) {
|
|
32
|
+
return explicitSurfaces.some((surface) => blockedSurfaces.includes(surface.trim()));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (typeof surfaces === "string" && surfaces.trim().length > 0) {
|
|
36
|
+
return blockedSurfaces.includes(surfaces.trim());
|
|
37
|
+
}
|
|
38
|
+
return blockedSurfaces.includes("admin");
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Framework-agnostic Better Auth factory.
|
|
42
|
+
*
|
|
43
|
+
* Accepts optional overrides for db, secret, baseURL, trustedOrigins.
|
|
44
|
+
* Does NOT depend on Next.js — safe to use in Hono workers, TanStack Start, etc.
|
|
45
|
+
*/
|
|
46
|
+
export function createBetterAuth(options = {}) {
|
|
47
|
+
const db = options.db ?? getDb("edge");
|
|
48
|
+
const secret = options.secret ?? getAuthSecret();
|
|
49
|
+
const baseURL = options.baseURL ??
|
|
50
|
+
process.env.BETTER_AUTH_URL ??
|
|
51
|
+
process.env.APP_URL ??
|
|
52
|
+
process.env.NEXT_PUBLIC_APP_URL ??
|
|
53
|
+
"http://localhost:3000";
|
|
54
|
+
const trustedOrigins = expandTrustedOrigins(options.trustedOrigins ?? getTrustedOrigins(), baseURL);
|
|
55
|
+
const extraPlugins = options.plugins ?? [];
|
|
56
|
+
const signupBlockSurfaces = normalizeSignupBlockSurfaces(options.disableSignupWhenUsersExist);
|
|
57
|
+
const signupBlockEnabled = isSignupBlockEnabled(options.disableSignupWhenUsersExist);
|
|
58
|
+
const schema = {
|
|
59
|
+
user: authUser,
|
|
60
|
+
session: authSession,
|
|
61
|
+
account: authAccount,
|
|
62
|
+
verification: authVerification,
|
|
63
|
+
apikey: apikeyTable,
|
|
64
|
+
...(options.extraSchema ?? {}),
|
|
65
|
+
};
|
|
66
|
+
const rateLimit = options.rateLimit ??
|
|
67
|
+
(options.secondaryStorage
|
|
68
|
+
? {
|
|
69
|
+
enabled: true,
|
|
70
|
+
window: 60,
|
|
71
|
+
max: 100,
|
|
72
|
+
storage: "secondary-storage",
|
|
73
|
+
}
|
|
74
|
+
: undefined);
|
|
75
|
+
const authOptions = {
|
|
76
|
+
appName: "Voyant",
|
|
77
|
+
baseURL,
|
|
78
|
+
...(options.basePath ? { basePath: options.basePath } : {}),
|
|
79
|
+
secret,
|
|
80
|
+
database: drizzleAdapter(db, {
|
|
81
|
+
provider: "pg",
|
|
82
|
+
schema,
|
|
83
|
+
}),
|
|
84
|
+
...(options.secondaryStorage ? { secondaryStorage: options.secondaryStorage } : {}),
|
|
85
|
+
...(rateLimit ? { rateLimit } : {}),
|
|
86
|
+
...(options.sessionCookieCache === false
|
|
87
|
+
? {}
|
|
88
|
+
: {
|
|
89
|
+
session: {
|
|
90
|
+
cookieCache: {
|
|
91
|
+
enabled: true,
|
|
92
|
+
// Caps how long a revoked session stays usable from the
|
|
93
|
+
// cookie alone; within the window getSession answers from
|
|
94
|
+
// the signed cookie with zero DB roundtrips.
|
|
95
|
+
maxAge: options.sessionCookieCache?.maxAge ?? 300,
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
}),
|
|
99
|
+
emailAndPassword: {
|
|
100
|
+
enabled: true,
|
|
101
|
+
minPasswordLength: 8,
|
|
102
|
+
maxPasswordLength: 128,
|
|
103
|
+
requireEmailVerification: true,
|
|
104
|
+
revokeSessionsOnPasswordReset: true,
|
|
105
|
+
// eslint-disable-next-line @typescript-eslint/require-await -- owner: auth; existing suppression is intentional pending typed cleanup.
|
|
106
|
+
sendResetPassword: options.sendResetPassword ??
|
|
107
|
+
(async ({ user, url }) => {
|
|
108
|
+
console.warn(`[Auth] No email provider configured — password reset for ${user.email}: ${url}`);
|
|
109
|
+
}),
|
|
110
|
+
},
|
|
111
|
+
emailVerification: {
|
|
112
|
+
sendOnSignUp: false, // OTP plugin handles this
|
|
113
|
+
autoSignInAfterVerification: true,
|
|
114
|
+
},
|
|
115
|
+
user: {
|
|
116
|
+
...options.user,
|
|
117
|
+
changeEmail: {
|
|
118
|
+
enabled: true,
|
|
119
|
+
...options.user?.changeEmail,
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
socialProviders: {
|
|
123
|
+
google: {
|
|
124
|
+
clientId: process.env.GOOGLE_CLIENT_ID || "",
|
|
125
|
+
clientSecret: process.env.GOOGLE_CLIENT_SECRET || "",
|
|
126
|
+
enabled: Boolean(process.env.GOOGLE_CLIENT_ID && process.env.GOOGLE_CLIENT_SECRET),
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
trustedOrigins,
|
|
130
|
+
plugins: [
|
|
131
|
+
apiKey({
|
|
132
|
+
defaultPrefix: "voy_",
|
|
133
|
+
apiKeyHeaders: ["authorization"],
|
|
134
|
+
requireName: true,
|
|
135
|
+
keyExpiration: {
|
|
136
|
+
defaultExpiresIn: null,
|
|
137
|
+
},
|
|
138
|
+
}),
|
|
139
|
+
emailOTP({
|
|
140
|
+
// eslint-disable-next-line @typescript-eslint/require-await -- owner: auth; existing suppression is intentional pending typed cleanup.
|
|
141
|
+
sendVerificationOTP: options.sendVerificationOTP ??
|
|
142
|
+
(async ({ email, otp, type }) => {
|
|
143
|
+
console.warn(`[Auth] OTP for ${email}: ${otp} (${type})`);
|
|
144
|
+
}),
|
|
145
|
+
otpLength: 6,
|
|
146
|
+
expiresIn: 600,
|
|
147
|
+
sendVerificationOnSignUp: true,
|
|
148
|
+
changeEmail: {
|
|
149
|
+
enabled: true,
|
|
150
|
+
},
|
|
151
|
+
}),
|
|
152
|
+
...extraPlugins,
|
|
153
|
+
],
|
|
154
|
+
databaseHooks: {
|
|
155
|
+
user: {
|
|
156
|
+
create: {
|
|
157
|
+
// Single-tenant: once a user exists, reject any new-user creation.
|
|
158
|
+
// Covers email sign-up AND social-provider sign-up (Google would
|
|
159
|
+
// otherwise auto-create a user on first OAuth callback). Existing
|
|
160
|
+
// social sign-ins still work because this hook only fires on CREATE.
|
|
161
|
+
// Seed scripts do raw drizzle inserts, so they bypass this hook —
|
|
162
|
+
// which is intentional.
|
|
163
|
+
before: async (user) => {
|
|
164
|
+
if (!signupBlockEnabled ||
|
|
165
|
+
!signupBlockAppliesToUser(user, signupBlockSurfaces)) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
const [row] = await db.select({ count: sql `count(*)::int` }).from(authUser);
|
|
169
|
+
if ((row?.count ?? 0) > 0) {
|
|
170
|
+
throw new Error("Sign-up is disabled. Ask an admin to invite you.");
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
after: async (user) => {
|
|
174
|
+
// Single-tenant bootstrap: the very first user to register becomes
|
|
175
|
+
// the super-admin. Runs atomically after the `user` row is
|
|
176
|
+
// inserted, so a simple COUNT(*) = 1 check identifies them.
|
|
177
|
+
await provisionCurrentUserProfile(db, {
|
|
178
|
+
userId: user.id,
|
|
179
|
+
name: user.name,
|
|
180
|
+
image: user.image,
|
|
181
|
+
isSuperAdmin: await isFirstAuthUser(db),
|
|
182
|
+
});
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
advanced: {
|
|
188
|
+
useSecureCookies: options.useSecureCookies ?? process.env.NODE_ENV !== "development",
|
|
189
|
+
},
|
|
190
|
+
};
|
|
191
|
+
return betterAuth(authOptions);
|
|
192
|
+
}
|
|
193
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":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AAE;wBACpB,mEAAmE;wBACnE,2DAA2D;wBAC3D,4DAA4D;wBAC5D,MAAM,2BAA2B,CAAC,EAAE,EAAE;4BACpC,MAAM,EAAE,IAAI,CAAC,EAAE;4BACf,IAAI,EAAE,IAAI,CAAC,IAAI;4BACf,KAAK,EAAE,IAAI,CAAC,KAAK;4BACjB,YAAY,EAAE,MAAM,eAAe,CAAC,EAAE,CAAC;yBACxC,CAAC,CAAA;oBACJ,CAAC;iBACF;aACF;SACF;QACD,QAAQ,EAAE;YACR,gBAAgB,EAAE,OAAO,CAAC,gBAAgB,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa;SACrF;KACuD,CAAA;IAE1D,OAAO,UAAU,CAAwD,WAAW,CAAC,CAAA;AACvF,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare function getTrustedOrigins(): string[];
|
|
2
|
+
/**
|
|
3
|
+
* If the app is running against a localhost baseURL (dev), allow any localhost
|
|
4
|
+
* origin/port so second dev servers (e.g. Vite on :3301 hitting API on :3200)
|
|
5
|
+
* aren't rejected by Better Auth's origin check. Production origins are
|
|
6
|
+
* unaffected - the wildcards are only added when we already see localhost.
|
|
7
|
+
*/
|
|
8
|
+
export declare function expandTrustedOrigins(origins: string[], baseURL: string): string[];
|
|
9
|
+
//# sourceMappingURL=trusted-origins.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trusted-origins.d.ts","sourceRoot":"","sources":["../src/trusted-origins.ts"],"names":[],"mappings":"AAAA,wBAAgB,iBAAiB,IAAI,MAAM,EAAE,CAW5C;AAqBD;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAGjF"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export function getTrustedOrigins() {
|
|
2
|
+
const values = [
|
|
3
|
+
process.env.BETTER_AUTH_URL,
|
|
4
|
+
process.env.APP_URL,
|
|
5
|
+
process.env.NEXT_PUBLIC_APP_URL,
|
|
6
|
+
process.env.VOYANT_DASHBOARD_URL,
|
|
7
|
+
process.env.NEXT_PUBLIC_SITE_URL,
|
|
8
|
+
process.env.ADMIN_URL,
|
|
9
|
+
].filter((value) => typeof value === "string" && value.trim().length > 0);
|
|
10
|
+
return Array.from(new Set(values.map((value) => value.trim().replace(/\/$/, ""))));
|
|
11
|
+
}
|
|
12
|
+
const LOCAL_WILDCARDS = [
|
|
13
|
+
"http://localhost:*",
|
|
14
|
+
"http://127.0.0.1:*",
|
|
15
|
+
"https://localhost:*",
|
|
16
|
+
"https://127.0.0.1:*",
|
|
17
|
+
];
|
|
18
|
+
function hasLocalOrigin(origins, baseURL) {
|
|
19
|
+
const all = [...origins, baseURL];
|
|
20
|
+
return all.some((value) => {
|
|
21
|
+
try {
|
|
22
|
+
const { hostname } = new URL(value);
|
|
23
|
+
return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]";
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* If the app is running against a localhost baseURL (dev), allow any localhost
|
|
32
|
+
* origin/port so second dev servers (e.g. Vite on :3301 hitting API on :3200)
|
|
33
|
+
* aren't rejected by Better Auth's origin check. Production origins are
|
|
34
|
+
* unaffected - the wildcards are only added when we already see localhost.
|
|
35
|
+
*/
|
|
36
|
+
export function expandTrustedOrigins(origins, baseURL) {
|
|
37
|
+
if (!hasLocalOrigin(origins, baseURL))
|
|
38
|
+
return origins;
|
|
39
|
+
return Array.from(new Set([...origins, ...LOCAL_WILDCARDS]));
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=trusted-origins.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trusted-origins.js","sourceRoot":"","sources":["../src/trusted-origins.ts"],"names":[],"mappings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