@soroi/auth 0.0.0-stage → 0.1.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 (52) hide show
  1. package/AGENTS.md +154 -0
  2. package/LICENSE +21 -0
  3. package/README.md +26 -2
  4. package/dist/account.d.ts +52 -0
  5. package/dist/account.js +177 -0
  6. package/dist/adapters/next.d.ts +6 -0
  7. package/dist/adapters/next.js +35 -0
  8. package/dist/adapters/tanstack.d.ts +12 -0
  9. package/dist/adapters/tanstack.js +40 -0
  10. package/dist/cli.d.ts +2 -0
  11. package/dist/cli.js +76 -0
  12. package/dist/core.d.ts +122 -0
  13. package/dist/core.js +351 -0
  14. package/dist/crypto.d.ts +12 -0
  15. package/dist/crypto.js +69 -0
  16. package/dist/db.d.ts +29 -0
  17. package/dist/db.js +55 -0
  18. package/dist/email.d.ts +9 -0
  19. package/dist/email.js +64 -0
  20. package/dist/errors.d.ts +24 -0
  21. package/dist/errors.js +88 -0
  22. package/dist/index.d.ts +202 -0
  23. package/dist/index.js +255 -0
  24. package/dist/methods.d.ts +16 -0
  25. package/dist/methods.js +21 -0
  26. package/dist/migrations.d.ts +5 -0
  27. package/dist/migrations.js +147 -0
  28. package/dist/modules/oauth-server.d.ts +110 -0
  29. package/dist/modules/oauth-server.js +568 -0
  30. package/dist/modules/tokens.d.ts +31 -0
  31. package/dist/modules/tokens.js +107 -0
  32. package/dist/modules/two-factor.d.ts +41 -0
  33. package/dist/modules/two-factor.js +169 -0
  34. package/dist/modules/workspaces.d.ts +138 -0
  35. package/dist/modules/workspaces.js +295 -0
  36. package/dist/oauth/flow.d.ts +5 -0
  37. package/dist/oauth/flow.js +161 -0
  38. package/dist/oauth/providers.d.ts +29 -0
  39. package/dist/oauth/providers.js +124 -0
  40. package/dist/password-hash.d.ts +8 -0
  41. package/dist/password-hash.js +68 -0
  42. package/dist/password.d.ts +49 -0
  43. package/dist/password.js +181 -0
  44. package/dist/routes.d.ts +5 -0
  45. package/dist/routes.js +77 -0
  46. package/dist/sessions.d.ts +51 -0
  47. package/dist/sessions.js +184 -0
  48. package/dist/testing.d.ts +15 -0
  49. package/dist/testing.js +32 -0
  50. package/dist/types.d.ts +184 -0
  51. package/dist/types.js +1 -0
  52. package/package.json +75 -4
@@ -0,0 +1,107 @@
1
+ import { assertSameOrigin, limit } from "../core.js";
2
+ import { randomToken, sha256 } from "../crypto.js";
3
+ import { AuthException } from "../errors.js";
4
+ import { requireRecent, requireSession, toUser, userColumns } from "../sessions.js";
5
+ // The public id is a short hash prefix. The full hash stays internal, so it never reaches the browser.
6
+ const publicId = (hash) => hash.slice(0, 16);
7
+ const toToken = (row) => ({
8
+ id: publicId(row.id),
9
+ name: row.name,
10
+ prefix: row.prefix,
11
+ scopes: row.scopes ? row.scopes.split(" ") : [],
12
+ workspaceId: row.workspace_id,
13
+ createdAt: new Date(row.created_at),
14
+ lastUsedAt: row.last_used_at ? new Date(row.last_used_at) : null,
15
+ expiresAt: row.expires_at ? new Date(row.expires_at) : null,
16
+ });
17
+ function guard(core) {
18
+ if (!core.modules.tokens)
19
+ throw new AuthException("method_disabled");
20
+ }
21
+ /** Returns the token once. Only its hash is stored. */
22
+ export async function create(core, ctx, input) {
23
+ guard(core);
24
+ assertSameOrigin(core, ctx);
25
+ const current = await requireSession(core, ctx, { browser: true });
26
+ const { user } = current;
27
+ // A token outlives sessions, so making one needs a recent sign-in.
28
+ await requireRecent(core, current, input?.password);
29
+ if (typeof input?.name !== "string" || !input.name.trim() || input.name.length > 100)
30
+ throw new AuthException("invalid_input");
31
+ const scopes = input.scopes ?? [];
32
+ if (!Array.isArray(scopes) || scopes.some((scope) => typeof scope !== "string" || !/^[\w:.-]{1,64}$/.test(scope))) {
33
+ throw new AuthException("invalid_input");
34
+ }
35
+ const days = input.expiresInDays;
36
+ if (days !== undefined && (!Number.isInteger(days) || days < 1 || days > 3650))
37
+ throw new AuthException("invalid_input");
38
+ const workspaceId = input.workspaceId ?? null;
39
+ if (workspaceId) {
40
+ const [member] = await core.db.query(`select 1 from ${core.s}.members where workspace_id = $1::uuid and user_id = $2::uuid`, [workspaceId, user.id]);
41
+ if (!member)
42
+ throw new AuthException("not_found");
43
+ }
44
+ await limit(core, `token-create:${user.id}`, 20, 3600);
45
+ const token = `${core.tokenPrefix}_${randomToken(32)}`;
46
+ const [row] = await core.db.query(`insert into ${core.s}.api_tokens (id, user_id, workspace_id, name, prefix, scopes, expires_at)
47
+ values ($1, $2::uuid, $3::uuid, $4, $5, $6, case when $7::int is null then null else now() + make_interval(days => $7::int) end)
48
+ returning id, name, prefix, scopes, workspace_id::text, created_at, last_used_at, expires_at`, [sha256(token), user.id, workspaceId, input.name.trim(), token.slice(0, core.tokenPrefix.length + 7), scopes.join(" "), days ?? null]);
49
+ const tokenName = input.name.trim();
50
+ core.background(() => core.sendEmail("tokenCreated", user.email, { appName: core.appName, email: user.email, name: user.name, tokenName }));
51
+ return { ok: true, token, apiToken: toToken(row) };
52
+ }
53
+ export async function list(core, ctx) {
54
+ guard(core);
55
+ const { user } = await requireSession(core, ctx, { browser: true });
56
+ const rows = await core.db.query(`select id, name, prefix, scopes, workspace_id::text, created_at, last_used_at, expires_at
57
+ from ${core.s}.api_tokens where user_id = $1::uuid order by created_at desc`, [user.id]);
58
+ return rows.map(toToken);
59
+ }
60
+ export async function revoke(core, ctx, input) {
61
+ guard(core);
62
+ assertSameOrigin(core, ctx);
63
+ const { user } = await requireSession(core, ctx, { browser: true });
64
+ if (typeof input?.id !== "string" || !/^[0-9a-f]{16}$/.test(input.id))
65
+ throw new AuthException("not_found");
66
+ const rows = await core.db.query(`delete from ${core.s}.api_tokens where user_id = $1::uuid and left(id, 16) = $2 returning 1`, [user.id, input.id]);
67
+ if (!rows.length)
68
+ throw new AuthException("not_found");
69
+ return { ok: true };
70
+ }
71
+ /** Resolves `Authorization: Bearer <token>`. Registered on the core when the module is on. */
72
+ export async function bearer(core, ctx) {
73
+ const header = ctx.request.headers.get("authorization");
74
+ if (!header?.startsWith("Bearer "))
75
+ return null;
76
+ const token = header.slice(7).trim();
77
+ if (!token.startsWith(`${core.tokenPrefix}_`) || token.length > 200)
78
+ return null;
79
+ const id = sha256(token);
80
+ const [row] = await core.db.query(`select t.id as t_id, t.scopes as t_scopes, t.workspace_id::text as t_workspace_id, t.created_at as t_created_at,
81
+ t.last_used_at as t_last_used_at, t.expires_at as t_expires_at, ${userColumns("u")}
82
+ from ${core.s}.api_tokens t join ${core.s}.users u on u.id = t.user_id
83
+ where t.id = $1 and (t.expires_at is null or t.expires_at > now())`, [id]);
84
+ if (!row)
85
+ return null;
86
+ const lastUsed = row.t_last_used_at ? new Date(row.t_last_used_at).getTime() : 0;
87
+ if (Date.now() - lastUsed > 60_000) {
88
+ await core.db.query(`update ${core.s}.api_tokens set last_used_at = now() where id = $1`, [id]);
89
+ }
90
+ const user = toUser(row);
91
+ return {
92
+ user,
93
+ tokenScopes: row.t_scopes ? String(row.t_scopes).split(" ") : [],
94
+ session: {
95
+ id: publicId(id),
96
+ userId: user.id,
97
+ method: "token",
98
+ workspaceId: row.t_workspace_id ?? null,
99
+ ip: ctx.ip,
100
+ userAgent: ctx.userAgent,
101
+ createdAt: new Date(row.t_created_at),
102
+ lastSeenAt: new Date(),
103
+ expiresAt: row.t_expires_at ? new Date(row.t_expires_at) : new Date(8.64e15),
104
+ providerEmail: null,
105
+ },
106
+ };
107
+ }
@@ -0,0 +1,41 @@
1
+ import { type Core, type RequestContext } from "../core.js";
2
+ export declare function totpCode(secret: Buffer, counter: number, digits?: number, algorithm?: string): string;
3
+ /** Checks a code outside the settings, for a re-authentication. */
4
+ export declare function confirm(core: Core, userId: string, code: unknown): Promise<void>;
5
+ export declare function status(core: Core, ctx: RequestContext): Promise<{
6
+ enabled: boolean;
7
+ recoveryCodesLeft: number;
8
+ }>;
9
+ /** Starts the setup. Show `uri` as a QR code; 2FA turns on only after `enable` gets a valid code. */
10
+ export declare function setup(core: Core, ctx: RequestContext, input?: {
11
+ password?: string;
12
+ }): Promise<{
13
+ ok: true;
14
+ secret: string;
15
+ uri: string;
16
+ }>;
17
+ /** Returns the recovery codes once. Other sessions are signed out. */
18
+ export declare function enable(core: Core, ctx: RequestContext, input: {
19
+ code: string;
20
+ }): Promise<{
21
+ ok: true;
22
+ recoveryCodes: string[];
23
+ }>;
24
+ export declare function disable(core: Core, ctx: RequestContext, input: {
25
+ code: string;
26
+ }): Promise<{
27
+ ok: true;
28
+ }>;
29
+ export declare function regenerateRecoveryCodes(core: Core, ctx: RequestContext, input: {
30
+ code: string;
31
+ }): Promise<{
32
+ ok: true;
33
+ recoveryCodes: string[];
34
+ }>;
35
+ /** The second sign-in step. Reads the challenge cookie that the first step set. */
36
+ export declare function verify(core: Core, ctx: RequestContext, input: {
37
+ code: string;
38
+ }): Promise<{
39
+ ok: true;
40
+ redirectTo: string;
41
+ }>;
@@ -0,0 +1,169 @@
1
+ import { createHmac, randomBytes } from "node:crypto";
2
+ import { assertSameOrigin, limit } from "../core.js";
3
+ import { base32Decode, base32Encode, hmac, seal, sha256, unseal } from "../crypto.js";
4
+ import { AuthException } from "../errors.js";
5
+ import { createSession, deleteUserSessions, requireRecent, requireSession } from "../sessions.js";
6
+ const PERIOD = 30;
7
+ const DIGITS = 6;
8
+ const RECOVERY_CODES = 10;
9
+ const MAX_ATTEMPTS = 5;
10
+ export function totpCode(secret, counter, digits = DIGITS, algorithm = "sha1") {
11
+ const message = Buffer.alloc(8);
12
+ message.writeBigUInt64BE(BigInt(counter));
13
+ const digest = createHmac(algorithm, secret).update(message).digest();
14
+ const offset = digest[digest.length - 1] & 0x0f;
15
+ const binary = ((digest[offset] & 0x7f) << 24) | (digest[offset + 1] << 16) | (digest[offset + 2] << 8) | digest[offset + 3];
16
+ return String(binary % 10 ** digits).padStart(digits, "0");
17
+ }
18
+ const currentCounter = () => Math.floor(Date.now() / 1000 / PERIOD);
19
+ function enabledGuard(core) {
20
+ if (!core.modules.twoFactor)
21
+ throw new AuthException("method_disabled");
22
+ }
23
+ /** Codes from the step before and after count too, for clock drift. Each code works once. */
24
+ async function useTotp(core, db, userId, secret, code) {
25
+ if (!/^\d{6}$/.test(code))
26
+ return false;
27
+ const now = currentCounter();
28
+ for (const counter of [now - 1, now, now + 1]) {
29
+ if (totpCode(secret, counter) !== code)
30
+ continue;
31
+ const [row] = await db.query(`update ${core.s}.two_factor set last_counter = $2 where user_id = $1::uuid and last_counter < $2 returning 1`, [userId, counter]);
32
+ return !!row;
33
+ }
34
+ return false;
35
+ }
36
+ const normalizeRecovery = (code) => code.toUpperCase().replace(/[^A-Z2-7]/g, "");
37
+ // Keyed with the app secret: 50-bit codes are too short to resist brute force on a plain hash.
38
+ const recoveryId = (core, userId, code) => hmac(core.keys.recovery, `${userId}:${normalizeRecovery(code)}`);
39
+ async function useRecoveryCode(core, db, userId, code) {
40
+ if (normalizeRecovery(code).length !== 10)
41
+ return false;
42
+ const [row] = await db.query(`update ${core.s}.recovery_codes set used_at = now() where id = $1 and user_id = $2::uuid and used_at is null returning 1`, [recoveryId(core, userId, code), userId]);
43
+ return !!row;
44
+ }
45
+ async function loadSecret(core, userId, enabled) {
46
+ const [row] = await core.db.query(`select secret from ${core.s}.two_factor where user_id = $1::uuid and (enabled_at is not null) = $2`, [userId, enabled]);
47
+ const base32 = row ? unseal(core.keys.totp, row.secret) : null;
48
+ return base32 ? base32Decode(base32) : null;
49
+ }
50
+ async function checkCode(core, userId, code) {
51
+ if (typeof code !== "string")
52
+ return false;
53
+ const secret = await loadSecret(core, userId, true);
54
+ if (!secret)
55
+ throw new AuthException("two_factor_not_enabled");
56
+ return (await useTotp(core, core.db, userId, secret, code.trim())) || (await useRecoveryCode(core, core.db, userId, code));
57
+ }
58
+ /** Checks a code outside the settings, for a re-authentication. */
59
+ export async function confirm(core, userId, code) {
60
+ await limit(core, `2fa:${userId}`, 10, 900);
61
+ if (!(await checkCode(core, userId, code)))
62
+ throw new AuthException("invalid_code");
63
+ }
64
+ async function newRecoveryCodes(core, db, userId) {
65
+ const codes = Array.from({ length: RECOVERY_CODES }, () => {
66
+ const raw = base32Encode(randomBytes(7)).slice(0, 10);
67
+ return `${raw.slice(0, 5)}-${raw.slice(5)}`;
68
+ });
69
+ await db.query(`delete from ${core.s}.recovery_codes where user_id = $1::uuid`, [userId]);
70
+ for (const code of codes) {
71
+ await db.query(`insert into ${core.s}.recovery_codes (id, user_id) values ($1, $2::uuid)`, [recoveryId(core, userId, code), userId]);
72
+ }
73
+ return codes;
74
+ }
75
+ async function signedInUser(core, ctx) {
76
+ enabledGuard(core);
77
+ assertSameOrigin(core, ctx);
78
+ const current = await requireSession(core, ctx);
79
+ if (current.session.method === "token")
80
+ throw new AuthException("forbidden");
81
+ await limit(core, `2fa:${current.user.id}`, 10, 900);
82
+ return current;
83
+ }
84
+ export async function status(core, ctx) {
85
+ enabledGuard(core);
86
+ const { user } = await requireSession(core, ctx);
87
+ const [row] = await core.db.query(`select t.enabled_at is not null as enabled,
88
+ (select count(*)::int from ${core.s}.recovery_codes r where r.user_id = t.user_id and r.used_at is null) as left
89
+ from ${core.s}.two_factor t where t.user_id = $1::uuid`, [user.id]);
90
+ return { enabled: !!row?.enabled, recoveryCodesLeft: row?.enabled ? Number(row.left) : 0 };
91
+ }
92
+ /** Starts the setup. Show `uri` as a QR code; 2FA turns on only after `enable` gets a valid code. */
93
+ export async function setup(core, ctx, input = {}) {
94
+ const current = await signedInUser(core, ctx);
95
+ const { user } = current;
96
+ // An attacker with a stolen session could otherwise add their own authenticator and lock the owner out.
97
+ await requireRecent(core, current, input?.password);
98
+ if (await loadSecret(core, user.id, true))
99
+ throw new AuthException("two_factor_already_enabled");
100
+ const secret = base32Encode(randomBytes(20));
101
+ await core.db.query(`insert into ${core.s}.two_factor (user_id, secret) values ($1::uuid, $2)
102
+ on conflict (user_id) do update set secret = excluded.secret, last_counter = 0, enabled_at = null`, [user.id, seal(core.keys.totp, secret)]);
103
+ const label = encodeURIComponent(`${core.twoFactorIssuer}:${user.email}`);
104
+ const issuer = encodeURIComponent(core.twoFactorIssuer);
105
+ return {
106
+ ok: true,
107
+ secret,
108
+ uri: `otpauth://totp/${label}?secret=${secret}&issuer=${issuer}&algorithm=SHA1&digits=${DIGITS}&period=${PERIOD}`,
109
+ };
110
+ }
111
+ /** Returns the recovery codes once. Other sessions are signed out. */
112
+ export async function enable(core, ctx, input) {
113
+ const { user, session } = await signedInUser(core, ctx);
114
+ const secret = await loadSecret(core, user.id, false);
115
+ if (!secret)
116
+ throw new AuthException(await loadSecret(core, user.id, true) ? "two_factor_already_enabled" : "two_factor_not_enabled");
117
+ if (typeof input?.code !== "string" || !(await useTotp(core, core.db, user.id, secret, input.code.trim()))) {
118
+ throw new AuthException("invalid_code");
119
+ }
120
+ const recoveryCodes = await core.db.transaction(async (tx) => {
121
+ await tx.query(`update ${core.s}.two_factor set enabled_at = now() where user_id = $1::uuid`, [user.id]);
122
+ await deleteUserSessions(core, tx, user.id, session.id);
123
+ return newRecoveryCodes(core, tx, user.id);
124
+ });
125
+ return { ok: true, recoveryCodes };
126
+ }
127
+ export async function disable(core, ctx, input) {
128
+ const { user } = await signedInUser(core, ctx);
129
+ if (!(await checkCode(core, user.id, input?.code)))
130
+ throw new AuthException("invalid_code");
131
+ await core.db.transaction(async (tx) => {
132
+ await tx.query(`delete from ${core.s}.two_factor where user_id = $1::uuid`, [user.id]);
133
+ await tx.query(`delete from ${core.s}.recovery_codes where user_id = $1::uuid`, [user.id]);
134
+ });
135
+ return { ok: true };
136
+ }
137
+ export async function regenerateRecoveryCodes(core, ctx, input) {
138
+ const { user } = await signedInUser(core, ctx);
139
+ if (!(await checkCode(core, user.id, input?.code)))
140
+ throw new AuthException("invalid_code");
141
+ return { ok: true, recoveryCodes: await newRecoveryCodes(core, core.db, user.id) };
142
+ }
143
+ /** The second sign-in step. Reads the challenge cookie that the first step set. */
144
+ export async function verify(core, ctx, input) {
145
+ enabledGuard(core);
146
+ assertSameOrigin(core, ctx);
147
+ const token = ctx.cookie(core.cookies.challenge);
148
+ if (!token)
149
+ throw new AuthException("challenge_expired");
150
+ const id = sha256(token);
151
+ // Count the attempt before the check, so parallel guesses cannot skip the limit.
152
+ const [challenge] = await core.db.query(`update ${core.s}.challenges set attempts = attempts + 1 where id = $1
153
+ returning user_id::text, method, provider_email, next, attempts, expires_at < now() as expired`, [id]);
154
+ if (!challenge || challenge.expired || challenge.attempts > MAX_ATTEMPTS) {
155
+ if (challenge)
156
+ await core.db.query(`delete from ${core.s}.challenges where id = $1`, [id]);
157
+ ctx.clearCookie(core.cookies.challenge);
158
+ throw new AuthException("challenge_expired");
159
+ }
160
+ // Each new sign-in makes a new challenge, so the per-user limit is what bounds guessing.
161
+ await limit(core, `2fa-verify:${challenge.user_id}`, 10, 900);
162
+ await limit(core, `2fa-verify-day:${challenge.user_id}`, 30, 86_400);
163
+ if (!(await checkCode(core, challenge.user_id, input?.code)))
164
+ throw new AuthException("invalid_code");
165
+ await core.db.query(`delete from ${core.s}.challenges where id = $1`, [id]);
166
+ ctx.clearCookie(core.cookies.challenge);
167
+ await createSession(core, ctx, challenge.user_id, challenge.method, challenge.provider_email);
168
+ return { ok: true, redirectTo: challenge.next ?? core.pages.afterSignIn };
169
+ }
@@ -0,0 +1,138 @@
1
+ import { type Core, type RequestContext } from "../core.js";
2
+ import type { User } from "../types.js";
3
+ export type Workspace = {
4
+ id: string;
5
+ name: string;
6
+ createdAt: Date;
7
+ };
8
+ export type Membership = {
9
+ workspace: Workspace;
10
+ role: string;
11
+ };
12
+ export type Member = {
13
+ user: Pick<User, "id" | "email" | "name" | "image">;
14
+ role: string;
15
+ joinedAt: Date;
16
+ };
17
+ export type Invite = {
18
+ email: string;
19
+ role: string;
20
+ expiresAt: Date;
21
+ createdAt: Date;
22
+ };
23
+ /** True when `role` is `min` or higher. Roles are listed highest first. */
24
+ export declare const atLeast: (core: Core, role: string, min: string) => boolean;
25
+ export declare function current(core: Core, ctx: RequestContext): Promise<Membership | null>;
26
+ /** Use in loaders and server functions. Throws `not_signed_in` or `forbidden`. */
27
+ export declare function requireMember(core: Core, ctx: RequestContext, options?: {
28
+ role?: string;
29
+ workspaceId?: string;
30
+ }): Promise<{
31
+ user: User;
32
+ session: import("../types.js").Session;
33
+ workspace: Workspace;
34
+ role: string;
35
+ }>;
36
+ export declare function list(core: Core, ctx: RequestContext): Promise<Membership[]>;
37
+ /** Makes the creator the owner and switches the session to the new workspace. */
38
+ export declare function create(core: Core, ctx: RequestContext, input: {
39
+ name: string;
40
+ }): Promise<{
41
+ ok: true;
42
+ workspace: Workspace;
43
+ }>;
44
+ export declare function switchTo(core: Core, ctx: RequestContext, input: {
45
+ workspaceId: string;
46
+ }): Promise<{
47
+ workspace: Workspace;
48
+ role: string;
49
+ ok: true;
50
+ }>;
51
+ export declare function rename(core: Core, ctx: RequestContext, input: {
52
+ name: string;
53
+ workspaceId?: string;
54
+ }): Promise<{
55
+ ok: true;
56
+ workspace: {
57
+ name: string;
58
+ id: string;
59
+ createdAt: Date;
60
+ };
61
+ }>;
62
+ export declare function remove(core: Core, ctx: RequestContext, input?: {
63
+ workspaceId?: string;
64
+ }): Promise<{
65
+ ok: true;
66
+ }>;
67
+ export declare function members(core: Core, ctx: RequestContext, input?: {
68
+ workspaceId?: string;
69
+ }): Promise<Member[]>;
70
+ /** Admins and up can invite. Nobody can invite someone above their own role, or as owner. */
71
+ export declare function invite(core: Core, ctx: RequestContext, input: {
72
+ email: string;
73
+ role: string;
74
+ workspaceId?: string;
75
+ }): Promise<{
76
+ ok: true;
77
+ }>;
78
+ export declare function invites(core: Core, ctx: RequestContext, input?: {
79
+ workspaceId?: string;
80
+ }): Promise<Invite[]>;
81
+ export declare function revokeInvite(core: Core, ctx: RequestContext, input: {
82
+ email: string;
83
+ workspaceId?: string;
84
+ }): Promise<{
85
+ ok: true;
86
+ }>;
87
+ /** For the invite page before sign-in: what the invite is for. Does not use it up. */
88
+ export declare function inviteInfo(core: Core, input: {
89
+ token: string;
90
+ }): Promise<{
91
+ ok: false;
92
+ error: "link_expired";
93
+ email?: undefined;
94
+ role?: undefined;
95
+ workspace?: undefined;
96
+ invitedBy?: undefined;
97
+ } | {
98
+ ok: true;
99
+ email: string;
100
+ role: string;
101
+ workspace: string;
102
+ invitedBy: string | null;
103
+ error?: undefined;
104
+ }>;
105
+ /** The signed-in user's verified e-mail must match the invite. */
106
+ export declare function acceptInvite(core: Core, ctx: RequestContext, input: {
107
+ token: string;
108
+ }): Promise<{
109
+ ok: true;
110
+ workspace: Workspace;
111
+ role: string;
112
+ }>;
113
+ /** Owner role changes only through `transferOwnership`. Nobody can raise someone above themselves. */
114
+ export declare function setRole(core: Core, ctx: RequestContext, input: {
115
+ userId: string;
116
+ role: string;
117
+ workspaceId?: string;
118
+ }): Promise<{
119
+ ok: true;
120
+ }>;
121
+ export declare function removeMember(core: Core, ctx: RequestContext, input: {
122
+ userId: string;
123
+ workspaceId?: string;
124
+ }): Promise<{
125
+ ok: true;
126
+ }>;
127
+ export declare function leave(core: Core, ctx: RequestContext, input?: {
128
+ workspaceId?: string;
129
+ }): Promise<{
130
+ ok: true;
131
+ }>;
132
+ /** The new owner must be a member. The old owner gets the second role. */
133
+ export declare function transferOwnership(core: Core, ctx: RequestContext, input: {
134
+ userId: string;
135
+ workspaceId?: string;
136
+ }): Promise<{
137
+ ok: true;
138
+ }>;