@tangle-network/agent-app 0.58.21 → 0.59.1
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/dist/app-auth/index.d.ts +6 -3
- package/dist/app-auth/index.js +26 -23
- package/dist/app-auth/index.js.map +1 -1
- package/dist/assistant/index.js +1 -1
- package/dist/chunk-AB63T2LM.js +32 -0
- package/dist/chunk-AB63T2LM.js.map +1 -0
- package/dist/chunk-TLVRBD2M.js +424 -0
- package/dist/chunk-TLVRBD2M.js.map +1 -0
- package/dist/email/index.d.ts +28 -0
- package/dist/email/index.js +19 -0
- package/dist/email/index.js.map +1 -0
- package/dist/email/layout.d.ts +87 -0
- package/dist/email/lint.d.ts +12 -0
- package/dist/email/mark.generated.d.ts +2 -0
- package/dist/email/palette.d.ts +38 -0
- package/dist/email/templates.d.ts +69 -0
- package/dist/teams/index.js +2 -4
- package/dist/teams/invitations-api.d.ts +1 -1
- package/dist/teams/invitations-api.js +4 -4
- package/dist/teams/invitations-api.js.map +1 -1
- package/dist/teams/invitations.d.ts +4 -37
- package/dist/web-react/index.js +1 -1
- package/package.json +6 -1
- package/dist/chunk-2DRYTJHI.js +0 -58
- package/dist/chunk-2DRYTJHI.js.map +0 -1
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/** The app an email comes from. */
|
|
2
|
+
export interface EmailProduct {
|
|
3
|
+
/**
|
|
4
|
+
* The product name, e.g. `GTM Agent`. The header reads `Tangle GTM Agent`;
|
|
5
|
+
* subjects and the sender use the name alone. A name that already starts
|
|
6
|
+
* with `Tangle` (`Tangle Sandbox`) is not doubled.
|
|
7
|
+
*/
|
|
8
|
+
name: string;
|
|
9
|
+
/** The app's absolute origin; app-relative links resolve against it. */
|
|
10
|
+
url: string;
|
|
11
|
+
}
|
|
12
|
+
/** Why the recipient got the email and where they control it. */
|
|
13
|
+
export interface EmailFooter {
|
|
14
|
+
/** The workspace the email concerns. */
|
|
15
|
+
workspaceName?: string;
|
|
16
|
+
/** One sentence, e.g. `You own this workspace.` */
|
|
17
|
+
reason: string;
|
|
18
|
+
/** Where the recipient changes which emails they get; absolute or app-relative. */
|
|
19
|
+
manageUrl?: string;
|
|
20
|
+
/**
|
|
21
|
+
* The sender's postal address, for marketing mail such as a digest. Leave it
|
|
22
|
+
* unset on transactional mail (approvals, invites, sign-in), which does not
|
|
23
|
+
* need one.
|
|
24
|
+
*/
|
|
25
|
+
postalAddress?: string;
|
|
26
|
+
}
|
|
27
|
+
/** A button. `url` is absolute or app-relative. */
|
|
28
|
+
export interface EmailAction {
|
|
29
|
+
label: string;
|
|
30
|
+
url: string;
|
|
31
|
+
}
|
|
32
|
+
/** One row in the email's list box: an approval request or a digest entry. */
|
|
33
|
+
export interface EmailItem {
|
|
34
|
+
title: string;
|
|
35
|
+
detail?: string;
|
|
36
|
+
/** Makes the title a link; absolute or app-relative. */
|
|
37
|
+
url?: string;
|
|
38
|
+
}
|
|
39
|
+
/** An inline image the HTML references by `cid:`; the mail client must send it with the message. */
|
|
40
|
+
export interface EmailAttachment {
|
|
41
|
+
filename: string;
|
|
42
|
+
/** Base64 file content, the form Resend and SES accept. */
|
|
43
|
+
content: string;
|
|
44
|
+
contentType: string;
|
|
45
|
+
contentId: string;
|
|
46
|
+
}
|
|
47
|
+
/** A rendered email, ready for any transport. */
|
|
48
|
+
export interface EmailMessage {
|
|
49
|
+
subject: string;
|
|
50
|
+
/** The inbox preview line. */
|
|
51
|
+
preheader: string;
|
|
52
|
+
html: string;
|
|
53
|
+
text: string;
|
|
54
|
+
/** Pass these through to the mail client; the header mark is one of them. */
|
|
55
|
+
attachments: EmailAttachment[];
|
|
56
|
+
}
|
|
57
|
+
/** What a template places in the shared layout. */
|
|
58
|
+
interface EmailContent {
|
|
59
|
+
subject: string;
|
|
60
|
+
preheader: string;
|
|
61
|
+
title: string;
|
|
62
|
+
paragraphs: readonly string[];
|
|
63
|
+
items?: readonly EmailItem[];
|
|
64
|
+
primary?: EmailAction;
|
|
65
|
+
secondary?: EmailAction;
|
|
66
|
+
/** Print the primary link under the buttons for clients that strip them. */
|
|
67
|
+
showPrimaryLink?: boolean;
|
|
68
|
+
/** A short line under the buttons, e.g. an expiry. */
|
|
69
|
+
note?: string;
|
|
70
|
+
footer: EmailFooter;
|
|
71
|
+
}
|
|
72
|
+
/** `Title — Product`, the one subject shape every Tangle email uses. */
|
|
73
|
+
export declare function emailSubject(subject: string, product: EmailProduct): string;
|
|
74
|
+
/** Place a template's content in the shared Tangle layout. */
|
|
75
|
+
export declare function renderEmail(product: EmailProduct, content: EmailContent): EmailMessage;
|
|
76
|
+
/**
|
|
77
|
+
* The HTML with inline images embedded as data URIs, for browser previews and
|
|
78
|
+
* screenshots. Mail clients get `cid:` references and the attachments instead.
|
|
79
|
+
*/
|
|
80
|
+
export declare function emailPreviewHtml(message: Pick<EmailMessage, 'html' | 'attachments'>): string;
|
|
81
|
+
/**
|
|
82
|
+
* The From header for an app's mail: `GTM Agent · Tangle <noreply@tangle.tools>`.
|
|
83
|
+
* The product leads because inbox sender columns truncate; `· Tangle` ties
|
|
84
|
+
* every app to the company and the sending domain.
|
|
85
|
+
*/
|
|
86
|
+
export declare function emailSender(productName: string, address: string): string;
|
|
87
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** One way an email's HTML would break in Gmail or Outlook. */
|
|
2
|
+
export interface EmailLintIssue {
|
|
3
|
+
rule: 'document' | 'external-css' | 'style-block' | 'unsupported-element' | 'unsupported-css' | 'layout-table' | 'inline-style' | 'image' | 'link' | 'size';
|
|
4
|
+
message: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Check rendered email HTML against what Gmail and Outlook render: a complete
|
|
8
|
+
* document, layout in presentation tables, styles inline (a `<style>` block may
|
|
9
|
+
* only add dark-mode and narrow-screen overrides), images with alt text and
|
|
10
|
+
* fixed size, absolute links, and a body small enough that Gmail does not clip.
|
|
11
|
+
*/
|
|
12
|
+
export declare function lintEmailHtml(html: string): EmailLintIssue[];
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/** The Tangle knot as a 84px transparent PNG (base64), shown at 28px in email headers. */
|
|
2
|
+
export declare const TANGLE_MARK_PNG_BASE64 = "iVBORw0KGgoAAAANSUhEUgAAAFQAAABUCAYAAAAcaxDBAAAQAElEQVR4nOxcDZBV1X3//8+9971dVvkwEhR1GuvEatIY09hmOklTCU2bMQYnH3ZMTAmRZRdpqIAYgV3Iy35CgAUEBBGcBNskliSmTZqPjtox6dhJaGY61NFGpfEDSBRBgbjsvnfv+fd/P86959x73+5b9r26mdm/Luede+/5uP/zO//z/zjnCpikupKASaorTTK0zjTJ0DrTJEPrTJMMrTNNMrTOZMM4qWuxewsBXsVDcxEBzSQUBQAJ4VhxilHq/6sPHyY/SU+NIeYriFw6TMMnMC6Rfj5oFVVrOfWh+Wx0zUWiEyTwZeHRrzauL+yFcRDCOVDPYu8LHtICr4Dv8oAK/rsGr+q/PMkgDfPccWJ281sSpxCl4f2QScF1xSztepwnGV0PLxv1CAzrj8qF7afykG3PzMuofyE3+L5nS/FL8OChLb1OF4yRamZoaSlNtctyo2vTpz0LzlcvTVpNlKqZ4pRiJgPo+QhpGD0YvKQql0Ji1FPCpH7Qn9DqBwy5Q1p9RntR9ZTqJwCY7REO2S78gCrunVvXNz8PNVBNDO1tc1vLNm4nC5oyI28gJWFGMvIJ8vKQotejIy9TLrgPoABt1JNCqn59xPaNctFMoFBK6eUECldUaNfWLueOaLTOnaFd7fIx15FzgkeNkU8hSqux2ogbyPCvoyYT09MdakCQfl/dUUhF9STG7ZhMrb3fYV95PD16XkBh7tYS/i9UoRFX+e52+aRryzkYvbSfKmT5QxnmAVC1qkZY6w1FyFW8CkYeomkfCq3kOT0P0TRV9UepWZ8qpzFT5UljYlRvjHQw6437jar9ZPBV3k/Jwrd5WD64rJcursazqgjtaXMZmTgnI6NQz4d3GQBnhMRf8/w5AkIMklrlMfjf4euXCoLZ/PSMoDRCslbnIJe1gaelRYdVD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SFpladaOT/3VGa1hsZ6A05XmuQaCGWMUkiB0suUiBbFw/g/Aqcf0MEqMPuUANp030AF86rh+vEal9AFxelpvkAwNdThvgOL/OqMiPgjpI97PqNA+CyE5Sgz7CGdQayFSkIzV5OfNlR0ImpBCtkKlJ5QipCTKrRDejPiJkZ4Zv9HoFeXC4SAvvKRWfhBqoZoYq2tBKl/rKOGvc77MkzsogFvKRmS8j06tzFsEmwvJmxgjlRpCh2e+NJqdN2FX4mifov8qFyupt3VPGdIR8zAxNU1e7O5879vv88yLu5UzuVSGNIEVSX/2FoQWkngNDQ07LPMi7r2YCqG/hpWQ0pMph/HVGl03fE2DhbzygF8vkPLx9HKecx83QSTJpAp8C+d2kSYbWmSYZWmeaZGidaZKhdaZJhtaZJhlaZ/o/AAAA//8mfCa5AAAABklEQVQDAPyiOFzVbOpbAAAAAElFTkSuQmCC";
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Brand roles the email layout paints with, as literal hex. Email clients
|
|
3
|
+
* cannot read CSS variables, and importing `@tangle-network/brand` at runtime
|
|
4
|
+
* would load React into a server-only renderer, so the values live here and
|
|
5
|
+
* `tests/email/palette.test.ts` fails when they drift from Brand's `palettes`.
|
|
6
|
+
*/
|
|
7
|
+
export declare const EMAIL_PALETTE: {
|
|
8
|
+
readonly light: {
|
|
9
|
+
readonly canvas: '#eceef3';
|
|
10
|
+
readonly card: '#ffffff';
|
|
11
|
+
readonly well: '#f6f7fa';
|
|
12
|
+
readonly hairline: '#c7c6d6';
|
|
13
|
+
readonly ink: '#2d2d2d';
|
|
14
|
+
readonly inkSecondary: '#3f3f3f';
|
|
15
|
+
readonly inkMuted: '#4c4c4c';
|
|
16
|
+
readonly accent: '#4c3fc5';
|
|
17
|
+
readonly onAccent: '#ffffff';
|
|
18
|
+
readonly accentText: '#3c32e9';
|
|
19
|
+
};
|
|
20
|
+
readonly dark: {
|
|
21
|
+
readonly canvas: '#0a0a14';
|
|
22
|
+
readonly card: '#191826';
|
|
23
|
+
readonly well: '#12111f';
|
|
24
|
+
readonly hairline: '#2a293d';
|
|
25
|
+
readonly ink: '#e6e6e6';
|
|
26
|
+
readonly inkSecondary: '#c7c7c7';
|
|
27
|
+
readonly inkMuted: '#b5b5b5';
|
|
28
|
+
readonly accent: '#4c3fc5';
|
|
29
|
+
readonly onAccent: '#ffffff';
|
|
30
|
+
readonly accentText: '#a5b4fc';
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Brand's `--font-sans` stack with the system faces email clients actually
|
|
35
|
+
* have. No client used for this mail loads web fonts reliably, so Inter shows
|
|
36
|
+
* only where it is installed and the platform UI face carries the rest.
|
|
37
|
+
*/
|
|
38
|
+
export declare const EMAIL_FONT_STACK = "Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Helvetica, Arial, sans-serif";
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { type EmailAction, type EmailFooter, type EmailItem, type EmailMessage, type EmailProduct } from './layout';
|
|
2
|
+
/** One action an agent is waiting to run. */
|
|
3
|
+
export interface ApprovalEmailAction {
|
|
4
|
+
/** What runs, in plain language and sentence case: `Create agent “Quinn”`. */
|
|
5
|
+
summary: string;
|
|
6
|
+
/** Where it runs and until when, e.g. `ph0ny · open until Oct 9, 3:40 PM UTC`. */
|
|
7
|
+
detail?: string;
|
|
8
|
+
}
|
|
9
|
+
/** Input for {@link approvalEmail}. */
|
|
10
|
+
export interface ApprovalEmailInput {
|
|
11
|
+
/** At least one action, in the order the agent asked. */
|
|
12
|
+
actions: readonly ApprovalEmailAction[];
|
|
13
|
+
/** The conversation the agent paused in. */
|
|
14
|
+
conversation?: string;
|
|
15
|
+
/** Opens the decision, e.g. the chat with the approval card. */
|
|
16
|
+
approveUrl: string;
|
|
17
|
+
/** Opens the context, e.g. every request waiting in the workspace. */
|
|
18
|
+
reviewUrl: string;
|
|
19
|
+
footer: EmailFooter;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* An agent paused until someone approves what it wants to do. Neither button
|
|
23
|
+
* decides anything: link scanners open email links, so both lead to the app,
|
|
24
|
+
* where the signed-in owner approves.
|
|
25
|
+
*/
|
|
26
|
+
export declare function approvalEmail(product: EmailProduct, input: ApprovalEmailInput): EmailMessage;
|
|
27
|
+
/** Input for {@link inviteEmail}. */
|
|
28
|
+
export interface InviteEmailInput {
|
|
29
|
+
workspaceName: string;
|
|
30
|
+
/** Who sent the invitation: a name or an email address. */
|
|
31
|
+
inviter: string;
|
|
32
|
+
/** The role the invitation grants, e.g. `editor`. */
|
|
33
|
+
role: string;
|
|
34
|
+
acceptUrl: string;
|
|
35
|
+
expiresAt: Date;
|
|
36
|
+
}
|
|
37
|
+
/** Someone invited the recipient to a workspace. */
|
|
38
|
+
export declare function inviteEmail(product: EmailProduct, input: InviteEmailInput): EmailMessage;
|
|
39
|
+
/** Input for {@link digestEmail}. */
|
|
40
|
+
export interface DigestEmailInput {
|
|
41
|
+
workspaceName: string;
|
|
42
|
+
/** The day the digest covers. */
|
|
43
|
+
date: Date;
|
|
44
|
+
/** What happened, most important first. */
|
|
45
|
+
items: readonly EmailItem[];
|
|
46
|
+
/** Opens the workspace. */
|
|
47
|
+
openUrl: string;
|
|
48
|
+
footer: EmailFooter;
|
|
49
|
+
}
|
|
50
|
+
/** What happened in a workspace that day. */
|
|
51
|
+
export declare function digestEmail(product: EmailProduct, input: DigestEmailInput): EmailMessage;
|
|
52
|
+
/** Input for {@link noticeEmail}. */
|
|
53
|
+
export interface NoticeEmailInput {
|
|
54
|
+
/** Short; the product name is appended. */
|
|
55
|
+
subject: string;
|
|
56
|
+
title: string;
|
|
57
|
+
/** One or two short paragraphs. */
|
|
58
|
+
body: string | readonly string[];
|
|
59
|
+
action?: EmailAction;
|
|
60
|
+
secondaryAction?: EmailAction;
|
|
61
|
+
/** Print the action's link too, for one-time links such as sign-in. */
|
|
62
|
+
showLink?: boolean;
|
|
63
|
+
note?: string;
|
|
64
|
+
/** Inbox preview line. Defaults to the first paragraph. */
|
|
65
|
+
preheader?: string;
|
|
66
|
+
footer: EmailFooter;
|
|
67
|
+
}
|
|
68
|
+
/** Any other transactional message: one title, a short body and at most two buttons. */
|
|
69
|
+
export declare function noticeEmail(product: EmailProduct, input: NoticeEmailInput): EmailMessage;
|
package/dist/teams/index.js
CHANGED
|
@@ -4,9 +4,8 @@ import {
|
|
|
4
4
|
getInvitationExpiresAt,
|
|
5
5
|
inviteUrlForToken,
|
|
6
6
|
normalizeInvitationEmail,
|
|
7
|
-
parseInvitationPermission
|
|
8
|
-
|
|
9
|
-
} from "../chunk-2DRYTJHI.js";
|
|
7
|
+
parseInvitationPermission
|
|
8
|
+
} from "../chunk-AB63T2LM.js";
|
|
10
9
|
import {
|
|
11
10
|
generateInviteToken,
|
|
12
11
|
isInviteTokenShape,
|
|
@@ -46,7 +45,6 @@ export {
|
|
|
46
45
|
normalizeInvitationEmail,
|
|
47
46
|
organizationRoleGrantsWorkspaceOwner,
|
|
48
47
|
parseInvitationPermission,
|
|
49
|
-
renderInvitationEmail,
|
|
50
48
|
resolveWorkspaceRole,
|
|
51
49
|
validateInviteToken,
|
|
52
50
|
workspaceRoleToCollaborationAccess,
|
|
@@ -70,7 +70,7 @@ export interface InvitationsApiOptions {
|
|
|
70
70
|
userTable: TeamParentTable & InvitationUserTable;
|
|
71
71
|
workspaceTable: TeamParentTable & InvitationWorkspaceTable;
|
|
72
72
|
access: Pick<WorkspaceAccessApi, 'getWorkspaceAccess'>;
|
|
73
|
-
/** REQUIRED — the app's mail transport (e.g. Resend +
|
|
73
|
+
/** REQUIRED — the app's mail transport (e.g. Resend + `inviteEmail` from `./email`). */
|
|
74
74
|
sendInvitationEmail: SendInvitationEmailSeam;
|
|
75
75
|
/** OPTIONAL — seat-limit gate at create time; mirrors members-api. */
|
|
76
76
|
enforceSeat?: EnforceSeatSeam;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
SeatLimitError
|
|
3
|
-
} from "../chunk-MEUNTJL5.js";
|
|
4
1
|
import {
|
|
5
2
|
generateInvitationToken,
|
|
6
3
|
getInvitationExpiresAt,
|
|
7
4
|
inviteUrlForToken,
|
|
8
5
|
normalizeInvitationEmail,
|
|
9
6
|
parseInvitationPermission
|
|
10
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-AB63T2LM.js";
|
|
8
|
+
import {
|
|
9
|
+
SeatLimitError
|
|
10
|
+
} from "../chunk-MEUNTJL5.js";
|
|
11
11
|
import "../chunk-DJ4VJIH5.js";
|
|
12
12
|
import {
|
|
13
13
|
hasWorkspaceRole
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/teams/invitations-api.ts"],"sourcesContent":["/**\n * Framework-neutral email-invitation lifecycle for the teams module: create /\n * list / resend / revoke / preview / accept over the dedicated\n * `workspace_invitation` table (from `createWorkspaceInvitationTable`). Lifted out\n * of any one app's route file — each app binds this once to its own db/tables/\n * access and mounts the handlers in its own routes with its own auth.\n *\n * Unlike `members-api` (whose \"invite\" is a pending workspaceMember row, no\n * email), this models the rich lifecycle: a dedicated invitation row with status,\n * 7-day expiry, emailStatus, resend, and revoke. On accept it materializes the\n * `organizationMembers` + `workspaceMembers` rows, so `members-api.listMembers`\n * still surfaces accepted members; pending invites live only here.\n *\n * Handlers return a discriminated `InvitationOutcome` (not a `Response`) so the\n * route adapter maps `{ status }` to its own framework's response. Three seams:\n * - `sendInvitationEmail` (REQUIRED) — the app's mail transport. Returns a\n * typed outcome; a failed send never blocks invitation creation (emailStatus\n * is recorded as 'failed' and the invite link is still returned).\n * - `enforceSeat` (OPTIONAL) — billing/seat-limit gate, called at create time\n * only when the invite would consume a NEW seat. Reused from members-api.\n * - `memberSyncSeam.add` (OPTIONAL) — fire-and-forget propagation of the new\n * member to a sandbox/external system on accept. Fail-soft by contract.\n *\n * Imports `drizzle-orm`, so this is a subpath, never re-exported from root.\n */\n\nimport { and, eq, lte, sql } from 'drizzle-orm'\nimport {\n type InvitationEmailStatus,\n type InvitationPermission,\n type InvitationStatus,\n generateInvitationToken,\n getInvitationExpiresAt,\n inviteUrlForToken,\n normalizeInvitationEmail,\n parseInvitationPermission,\n} from './invitations'\nimport { type WorkspaceRole, hasWorkspaceRole } from './roles'\nimport { type EnforceSeatSeam, type MemberSyncSeam, SeatLimitError } from './members-api'\nimport type { TeamDatabase, WorkspaceAccessApi } from './drizzle/access'\nimport type { TeamParentTable, TeamTables } from './drizzle/schema'\nimport type { WorkspaceInvitationRow, WorkspaceInvitationTables } from './drizzle/invitations-schema'\n\n// Re-export the seams an adopter wires, so a consumer can import everything the\n// invitations API needs from this one subpath.\nexport { SeatLimitError } from './members-api'\nexport type { EnforceSeatSeam, MemberSyncSeam } from './members-api'\n\n/** The app's mail transport. Returns a typed outcome; never throws to the API. */\nexport interface SendInvitationEmailInput {\n to: string\n workspaceName: string\n inviterEmail: string\n permission: InvitationPermission\n inviteUrl: string\n expiresAt: Date\n}\n/** Represent the outcome of sending an invitation email with success status and optional error message */\nexport type SendInvitationEmailResult = { succeeded: true } | { succeeded: false; error: string }\n/** Resolve sending an invitation email and return the result asynchronously */\nexport interface SendInvitationEmailSeam {\n (input: SendInvitationEmailInput): Promise<SendInvitationEmailResult>\n}\n\n/** The product's user table, narrowed to the columns the queries read. */\nexport interface InvitationUserTable {\n id: any\n email: any\n emailVerified: any\n}\n\n/** The product's workspace table, narrowed to the columns the queries read. */\nexport interface InvitationWorkspaceTable {\n id: any\n name: any\n}\n\n/** Define configuration options required to manage workspace invitations and related data sources */\nexport interface InvitationsApiOptions {\n db: TeamDatabase\n tables: TeamTables\n /** The invitation table from `createWorkspaceInvitationTable`. */\n invitationsTable: WorkspaceInvitationTables\n userTable: TeamParentTable & InvitationUserTable\n workspaceTable: TeamParentTable & InvitationWorkspaceTable\n access: Pick<WorkspaceAccessApi, 'getWorkspaceAccess'>\n /** REQUIRED — the app's mail transport (e.g. Resend + renderInvitationEmail). */\n sendInvitationEmail: SendInvitationEmailSeam\n /** OPTIONAL — seat-limit gate at create time; mirrors members-api. */\n enforceSeat?: EnforceSeatSeam\n /** OPTIONAL — fire-and-forget member propagation on accept. */\n memberSyncSeam?: Pick<MemberSyncSeam, 'add'>\n /** Inviter display fallback when the inviter's email is unknown. */\n productDisplayName?: string\n}\n\n/** Represent a workspace invitation with details about inviter, permissions, status, and timestamps */\nexport interface WorkspaceInvitationView {\n id: string\n workspaceId: string\n organizationId: string\n email: string\n invitedByUserId: string\n inviterEmail: string | null\n permissions: InvitationPermission\n token: string\n status: InvitationStatus\n emailStatus: InvitationEmailStatus\n expiresAt: Date\n createdAt: Date\n acceptedAt: Date | null\n revokedAt: Date | null\n lastSentAt: Date | null\n}\n\n/** Describe the structure of an invitation preview with workspace, email, permissions, status, and expiration details */\nexport interface InvitationPreview {\n workspaceId: string\n workspaceName: string\n email: string\n inviterEmail: string | null\n permissions: InvitationPermission\n status: InvitationStatus\n expiresAt: Date\n}\n\n/** Resolve the result of an invitation as success with a value or failure with status and error details */\nexport type InvitationOutcome<T> =\n | { succeeded: true; value: T }\n | { succeeded: false; status: number; error: string }\n\n/**\n * Build the invitations API bound to one product's db/tables/access/seams.\n * Returns the six lifecycle handlers an app mounts in its routes.\n */\nexport function createInvitationsApi(opts: InvitationsApiOptions) {\n const { db, tables, access, sendInvitationEmail, enforceSeat, memberSyncSeam } = opts\n const { organizationMembers, workspaceMembers } = tables\n const { workspaceInvitations } = opts.invitationsTable\n const users = opts.userTable\n const workspaces = opts.workspaceTable\n const productDisplayName = opts.productDisplayName ?? 'A workspace admin'\n\n function fireSync(op: () => Promise<void> | void) {\n try {\n Promise.resolve(op()).catch(() => {})\n } catch {\n // seam threw synchronously — swallow; sync is best-effort by contract.\n }\n }\n\n async function createInvitation(input: {\n workspaceId: string\n email: string\n permissions: string | undefined\n invitedByUserId: string\n origin: string\n now?: Date\n }): Promise<InvitationOutcome<{ invitation: WorkspaceInvitationView; inviteUrl: string; emailError?: string }>> {\n const now = input.now ?? new Date()\n const accessRow = await access.getWorkspaceAccess(input.workspaceId, input.invitedByUserId, 'admin')\n if (!accessRow) return { succeeded: false, status: 404, error: 'Workspace not found' }\n\n const permissions = parseInvitationPermission(input.permissions ?? 'editor')\n if (!permissions) return { succeeded: false, status: 400, error: 'Invalid permissions' }\n if (!hasWorkspaceRole(accessRow.role, permissions)) {\n return { succeeded: false, status: 403, error: 'Cannot assign higher permissions than your own' }\n }\n\n const email = normalizeInvitationEmail(input.email)\n if (!email) return { succeeded: false, status: 400, error: 'Missing email' }\n\n const organizationId = accessRow.organization.id\n const workspaceName = (accessRow.workspace as { name: string }).name\n\n await expirePendingInvitations(input.workspaceId, email, now)\n\n const existingPending = await getPendingInvitation(input.workspaceId, email)\n if (existingPending) return { succeeded: false, status: 409, error: 'A pending invitation already exists for this email' }\n\n const accountCheck = await checkExistingAccountAccess(organizationId, input.workspaceId, email, input.invitedByUserId)\n if (!accountCheck.succeeded) return accountCheck\n\n // Seat gate: only a genuinely NEW seat. The checks above reject re-invites,\n // existing workspace members, and org admins; an existing plain org member is\n // already billable (no new seat), so skip the gate for them — mirrors\n // members-api. The pending row is not inserted yet, so the seam's count\n // reflects current usage and denies the invite that would push OVER the limit\n // (at invite time, not accept time).\n if (enforceSeat && !accountCheck.isExistingOrgMember) {\n try {\n await enforceSeat({ actorId: input.invitedByUserId, organizationId })\n } catch (err) {\n if (err instanceof SeatLimitError) return { succeeded: false, status: err.status, error: err.message }\n throw err\n }\n }\n\n const token = generateInvitationToken()\n const expiresAt = getInvitationExpiresAt(now)\n\n const [created] = await db.insert(workspaceInvitations).values({\n workspaceId: input.workspaceId,\n organizationId,\n email,\n invitedByUserId: input.invitedByUserId,\n permissions,\n token,\n status: 'pending',\n emailStatus: 'not_sent',\n expiresAt,\n createdAt: now,\n }).returning()\n\n const inviteUrl = inviteUrlForToken(input.origin, token)\n const emailResult = await sendInvitationEmail({\n to: email,\n workspaceName,\n inviterEmail: accountCheck.inviterEmail ?? productDisplayName,\n permission: permissions,\n inviteUrl,\n expiresAt,\n })\n\n const emailStatus: InvitationEmailStatus = emailResult.succeeded ? 'sent' : 'failed'\n const [updated] = await db.update(workspaceInvitations)\n .set({ emailStatus, lastSentAt: emailResult.succeeded ? now : null })\n .where(eq(workspaceInvitations.id, created!.id))\n .returning()\n\n return {\n succeeded: true,\n value: {\n invitation: toInvitationView(updated!, accountCheck.inviterEmail),\n inviteUrl,\n emailError: emailResult.succeeded ? undefined : emailResult.error,\n },\n }\n }\n\n async function listInvitations(input: {\n workspaceId: string\n userId: string\n origin: string\n now?: Date\n }): Promise<InvitationOutcome<{ invitations: Array<WorkspaceInvitationView & { inviteUrl: string }> }>> {\n const accessRow = await access.getWorkspaceAccess(input.workspaceId, input.userId, 'admin')\n if (!accessRow) return { succeeded: false, status: 404, error: 'Workspace not found' }\n\n await expirePendingInvitations(input.workspaceId, undefined, input.now ?? new Date())\n\n const rows = await db\n .select({ invitation: workspaceInvitations, inviterEmail: users.email })\n .from(workspaceInvitations)\n .leftJoin(users, eq(users.id, workspaceInvitations.invitedByUserId))\n .where(eq(workspaceInvitations.workspaceId, input.workspaceId))\n .orderBy(sql`${workspaceInvitations.createdAt} desc`)\n\n return {\n succeeded: true,\n value: {\n invitations: rows.map((row: { invitation: WorkspaceInvitationRow; inviterEmail: string | null }) => ({\n ...toInvitationView(row.invitation, row.inviterEmail),\n inviteUrl: inviteUrlForToken(input.origin, row.invitation.token),\n })),\n },\n }\n }\n\n async function resendInvitation(input: {\n invitationId: string\n userId: string\n origin: string\n now?: Date\n }): Promise<InvitationOutcome<{ invitation: WorkspaceInvitationView; inviteUrl: string; emailError?: string }>> {\n const row = await getInvitationById(input.invitationId)\n if (!row) return { succeeded: false, status: 404, error: 'Invitation not found' }\n\n const accessRow = await access.getWorkspaceAccess(row.invitation.workspaceId, input.userId, 'admin')\n if (!accessRow) return { succeeded: false, status: 404, error: 'Workspace not found' }\n\n const now = input.now ?? new Date()\n if (row.invitation.status !== 'pending') {\n return { succeeded: false, status: 409, error: 'Only pending invitations can be resent' }\n }\n if (row.invitation.expiresAt <= now) {\n await markInvitationExpired(row.invitation.id)\n return { succeeded: false, status: 409, error: 'Invitation has expired' }\n }\n\n const workspaceName = (accessRow.workspace as { name: string }).name\n const inviteUrl = inviteUrlForToken(input.origin, row.invitation.token)\n const emailResult = await sendInvitationEmail({\n to: row.invitation.email,\n workspaceName,\n inviterEmail: row.inviterEmail ?? productDisplayName,\n permission: row.invitation.permissions,\n inviteUrl,\n expiresAt: row.invitation.expiresAt,\n })\n\n const [updated] = await db.update(workspaceInvitations)\n .set({\n emailStatus: emailResult.succeeded ? 'sent' : 'failed',\n lastSentAt: emailResult.succeeded ? now : row.invitation.lastSentAt,\n })\n .where(eq(workspaceInvitations.id, row.invitation.id))\n .returning()\n\n return {\n succeeded: true,\n value: {\n invitation: toInvitationView(updated!, row.inviterEmail),\n inviteUrl,\n emailError: emailResult.succeeded ? undefined : emailResult.error,\n },\n }\n }\n\n async function revokeInvitation(input: {\n invitationId: string\n userId: string\n now?: Date\n }): Promise<InvitationOutcome<{ invitation: WorkspaceInvitationView }>> {\n const row = await getInvitationById(input.invitationId)\n if (!row) return { succeeded: false, status: 404, error: 'Invitation not found' }\n\n const accessRow = await access.getWorkspaceAccess(row.invitation.workspaceId, input.userId, 'admin')\n if (!accessRow) return { succeeded: false, status: 404, error: 'Workspace not found' }\n if (row.invitation.status !== 'pending') {\n return { succeeded: false, status: 409, error: 'Only pending invitations can be revoked' }\n }\n\n const [updated] = await db.update(workspaceInvitations)\n .set({ status: 'revoked', revokedAt: input.now ?? new Date() })\n .where(and(eq(workspaceInvitations.id, row.invitation.id), eq(workspaceInvitations.status, 'pending')))\n .returning()\n\n // The status read above is advisory. A concurrent accept may win between\n // that read and this update, so the write must be compare-and-set.\n if (!updated) return { succeeded: false, status: 409, error: 'The invitation changed. Reload it before continuing.' }\n\n return { succeeded: true, value: { invitation: toInvitationView(updated!, row.inviterEmail) } }\n }\n\n async function getPreview(token: string, now: Date = new Date()): Promise<InvitationOutcome<InvitationPreview>> {\n const row = await getInvitationByToken(token)\n if (!row) return { succeeded: false, status: 404, error: 'Invitation not found' }\n\n let invitation = row.invitation\n if (invitation.status === 'pending' && invitation.expiresAt <= now) {\n invitation = await markInvitationExpired(invitation.id)\n }\n\n return {\n succeeded: true,\n value: {\n workspaceId: invitation.workspaceId,\n workspaceName: row.workspaceName,\n email: invitation.email,\n inviterEmail: row.inviterEmail,\n permissions: invitation.permissions,\n status: invitation.status,\n expiresAt: invitation.expiresAt,\n },\n }\n }\n\n async function acceptInvitation(input: {\n token: string\n userId: string\n now?: Date\n }): Promise<InvitationOutcome<{ workspaceId: string }>> {\n const now = input.now ?? new Date()\n const row = await getInvitationByToken(input.token)\n if (!row) return { succeeded: false, status: 404, error: 'Invitation not found' }\n\n let invitation = row.invitation\n if (invitation.status === 'pending' && invitation.expiresAt <= now) {\n invitation = await markInvitationExpired(invitation.id)\n }\n\n const [currentUser] = await db\n .select({ id: users.id, email: users.email, emailVerified: users.emailVerified })\n .from(users)\n .where(eq(users.id, input.userId))\n .limit(1)\n if (!currentUser) return { succeeded: false, status: 401, error: 'Authentication required' }\n\n if (normalizeInvitationEmail(currentUser.email) !== invitation.email) {\n return { succeeded: false, status: 403, error: 'Sign in with the invited email address to accept this invitation' }\n }\n\n const collisionCheck = await findUsersByNormalizedEmail(invitation.email)\n if (collisionCheck.length > 1) {\n return {\n succeeded: false,\n status: 409,\n error: 'Multiple accounts use this email. Contact support to reconcile before accepting this invitation.',\n }\n }\n\n let orgMember = await getOrganizationMember(invitation.organizationId, currentUser.id)\n if (orgMember?.role === 'owner' || orgMember?.role === 'admin') {\n return { succeeded: false, status: 409, error: 'This user already has account-level access.' }\n }\n\n if (invitation.status === 'accepted') {\n const existing = orgMember ? await getWorkspaceMemberByOrganizationMember(invitation.workspaceId, orgMember.id) : null\n if (existing) return { succeeded: true, value: { workspaceId: invitation.workspaceId } }\n return { succeeded: false, status: 409, error: 'Invitation has already been accepted' }\n }\n if (invitation.status === 'expired') return { succeeded: false, status: 409, error: 'Invitation has expired' }\n if (invitation.status === 'revoked') return { succeeded: false, status: 409, error: 'Invitation has been revoked' }\n\n if (!orgMember) {\n const [inserted] = await db.insert(organizationMembers).values({\n organizationId: invitation.organizationId,\n userId: currentUser.id,\n role: 'member',\n createdAt: now,\n updatedAt: now,\n }).returning()\n if (!inserted) return { succeeded: false, status: 500, error: 'Failed to create organization membership' }\n orgMember = inserted\n }\n\n const existingMember = await getWorkspaceMemberByOrganizationMember(invitation.workspaceId, orgMember.id)\n if (!existingMember) {\n await db.insert(workspaceMembers).values({\n workspaceId: invitation.workspaceId,\n organizationMemberId: orgMember.id,\n userId: currentUser.id,\n role: invitation.permissions,\n inviteEmail: invitation.email,\n // members-api nulls the token on accept to release the unique slot; the\n // invitations flow keeps it (its `inv_` tokens never collide), so the\n // materialized row carries the originating token for audit.\n inviteToken: invitation.token,\n invitedAt: now,\n acceptedAt: now,\n })\n if (memberSyncSeam?.add) {\n const userId = currentUser.id\n const role = invitation.permissions as WorkspaceRole\n fireSync(() => memberSyncSeam.add!({ workspaceId: invitation.workspaceId, userId, role }))\n }\n }\n\n const [accepted] = await db.update(workspaceInvitations)\n .set({ status: 'accepted', acceptedAt: now })\n .where(and(eq(workspaceInvitations.id, invitation.id), eq(workspaceInvitations.status, 'pending')))\n .returning()\n\n if (!accepted) {\n // Membership was materialized before the final compare-and-set. Remove\n // only the row created by this attempt before reporting the conflict.\n await db.delete(workspaceMembers)\n .where(and(eq(workspaceMembers.workspaceId, invitation.workspaceId), eq(workspaceMembers.userId, currentUser.id)))\n return { succeeded: false, status: 409, error: 'The invitation changed. Reload it before continuing.' }\n }\n\n return { succeeded: true, value: { workspaceId: invitation.workspaceId } }\n }\n\n // ── internal query helpers ──\n\n async function expirePendingInvitations(workspaceId: string, email: string | undefined, now: Date) {\n const conditions = [\n eq(workspaceInvitations.workspaceId, workspaceId),\n eq(workspaceInvitations.status, 'pending' as const),\n lte(workspaceInvitations.expiresAt, now),\n ]\n if (email) conditions.push(eq(workspaceInvitations.email, email))\n await db.update(workspaceInvitations).set({ status: 'expired' }).where(and(...conditions))\n }\n\n async function getPendingInvitation(workspaceId: string, email: string) {\n const [invitation] = await db\n .select({ id: workspaceInvitations.id })\n .from(workspaceInvitations)\n .where(and(\n eq(workspaceInvitations.workspaceId, workspaceId),\n eq(workspaceInvitations.email, email),\n eq(workspaceInvitations.status, 'pending' as const),\n ))\n .limit(1)\n return invitation ?? null\n }\n\n async function checkExistingAccountAccess(\n organizationId: string,\n workspaceId: string,\n email: string,\n invitedByUserId: string,\n ): Promise<\n | { succeeded: false; status: number; error: string }\n | { succeeded: true; inviterEmail: string | null; isExistingOrgMember: boolean }\n > {\n const matchingUsers = await findUsersByNormalizedEmail(email)\n const [inviter] = await db\n .select({ email: users.email })\n .from(users)\n .where(eq(users.id, invitedByUserId))\n .limit(1)\n\n if (matchingUsers.length > 1) {\n return {\n succeeded: false,\n status: 409,\n error: 'Multiple accounts use this email. Contact support to reconcile before inviting this user.',\n }\n }\n const existingUser = matchingUsers[0]\n if (!existingUser) return { succeeded: true, inviterEmail: inviter?.email ?? null, isExistingOrgMember: false }\n\n const orgMember = await getOrganizationMember(organizationId, existingUser.id)\n if (orgMember?.role === 'owner' || orgMember?.role === 'admin') {\n return { succeeded: false, status: 409, error: 'This user already has account-level access.' }\n }\n if (orgMember) {\n const workspaceMember = await getWorkspaceMemberByOrganizationMember(workspaceId, orgMember.id)\n if (workspaceMember) return { succeeded: false, status: 409, error: 'User is already a workspace member' }\n }\n\n return { succeeded: true, inviterEmail: inviter?.email ?? null, isExistingOrgMember: Boolean(orgMember) }\n }\n\n async function findUsersByNormalizedEmail(email: string) {\n return db\n .select({ id: users.id, email: users.email, emailVerified: users.emailVerified })\n .from(users)\n .where(sql`lower(${users.email}) = ${email}`)\n }\n\n async function getOrganizationMember(organizationId: string, userId: string) {\n const [member] = await db\n .select()\n .from(organizationMembers)\n .where(and(eq(organizationMembers.organizationId, organizationId), eq(organizationMembers.userId, userId)))\n .limit(1)\n return member ?? null\n }\n\n async function getWorkspaceMemberByOrganizationMember(workspaceId: string, organizationMemberId: string) {\n const [member] = await db\n .select({ id: workspaceMembers.id })\n .from(workspaceMembers)\n .where(and(\n eq(workspaceMembers.workspaceId, workspaceId),\n eq(workspaceMembers.organizationMemberId, organizationMemberId),\n ))\n .limit(1)\n return member ?? null\n }\n\n async function getInvitationById(invitationId: string) {\n const [row] = await db\n .select({ invitation: workspaceInvitations, inviterEmail: users.email })\n .from(workspaceInvitations)\n .leftJoin(users, eq(users.id, workspaceInvitations.invitedByUserId))\n .where(eq(workspaceInvitations.id, invitationId))\n .limit(1)\n return row ?? null\n }\n\n async function getInvitationByToken(token: string) {\n const [row] = await db\n .select({\n invitation: workspaceInvitations,\n workspaceName: workspaces.name,\n inviterEmail: users.email,\n })\n .from(workspaceInvitations)\n .innerJoin(workspaces, eq(workspaces.id, workspaceInvitations.workspaceId))\n .leftJoin(users, eq(users.id, workspaceInvitations.invitedByUserId))\n .where(eq(workspaceInvitations.token, token))\n .limit(1)\n return row ?? null\n }\n\n async function markInvitationExpired(invitationId: string) {\n const [updated] = await db.update(workspaceInvitations)\n .set({ status: 'expired' })\n .where(eq(workspaceInvitations.id, invitationId))\n .returning()\n return updated!\n }\n\n function toInvitationView(invitation: WorkspaceInvitationRow, inviterEmail: string | null): WorkspaceInvitationView {\n return {\n id: invitation.id,\n workspaceId: invitation.workspaceId,\n organizationId: invitation.organizationId,\n email: invitation.email,\n invitedByUserId: invitation.invitedByUserId,\n inviterEmail,\n permissions: invitation.permissions,\n token: invitation.token,\n status: invitation.status,\n emailStatus: invitation.emailStatus,\n expiresAt: invitation.expiresAt,\n createdAt: invitation.createdAt,\n acceptedAt: invitation.acceptedAt,\n revokedAt: invitation.revokedAt,\n lastSentAt: invitation.lastSentAt,\n }\n }\n\n return { createInvitation, listInvitations, resendInvitation, revokeInvitation, getPreview, acceptInvitation }\n}\n"],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W;AAAA,MACxB,WAAW,WAAW;AAAA,MACtB,WAAW,WAAW;AAAA,MACtB,YAAY,WAAW;AAAA,MACvB,WAAW,WAAW;AAAA,MACtB,YAAY,WAAW;AAAA,IACzB;AAAA,EACF;AAEA,SAAO,EAAE,kBAAkB,iBAAiB,kBAAkB,kBAAkB,YAAY,iBAAiB;AAC/G;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/teams/invitations-api.ts"],"sourcesContent":["/**\n * Framework-neutral email-invitation lifecycle for the teams module: create /\n * list / resend / revoke / preview / accept over the dedicated\n * `workspace_invitation` table (from `createWorkspaceInvitationTable`). Lifted out\n * of any one app's route file — each app binds this once to its own db/tables/\n * access and mounts the handlers in its own routes with its own auth.\n *\n * Unlike `members-api` (whose \"invite\" is a pending workspaceMember row, no\n * email), this models the rich lifecycle: a dedicated invitation row with status,\n * 7-day expiry, emailStatus, resend, and revoke. On accept it materializes the\n * `organizationMembers` + `workspaceMembers` rows, so `members-api.listMembers`\n * still surfaces accepted members; pending invites live only here.\n *\n * Handlers return a discriminated `InvitationOutcome` (not a `Response`) so the\n * route adapter maps `{ status }` to its own framework's response. Three seams:\n * - `sendInvitationEmail` (REQUIRED) — the app's mail transport. Returns a\n * typed outcome; a failed send never blocks invitation creation (emailStatus\n * is recorded as 'failed' and the invite link is still returned).\n * - `enforceSeat` (OPTIONAL) — billing/seat-limit gate, called at create time\n * only when the invite would consume a NEW seat. Reused from members-api.\n * - `memberSyncSeam.add` (OPTIONAL) — fire-and-forget propagation of the new\n * member to a sandbox/external system on accept. Fail-soft by contract.\n *\n * Imports `drizzle-orm`, so this is a subpath, never re-exported from root.\n */\n\nimport { and, eq, lte, sql } from 'drizzle-orm'\nimport {\n type InvitationEmailStatus,\n type InvitationPermission,\n type InvitationStatus,\n generateInvitationToken,\n getInvitationExpiresAt,\n inviteUrlForToken,\n normalizeInvitationEmail,\n parseInvitationPermission,\n} from './invitations'\nimport { type WorkspaceRole, hasWorkspaceRole } from './roles'\nimport { type EnforceSeatSeam, type MemberSyncSeam, SeatLimitError } from './members-api'\nimport type { TeamDatabase, WorkspaceAccessApi } from './drizzle/access'\nimport type { TeamParentTable, TeamTables } from './drizzle/schema'\nimport type { WorkspaceInvitationRow, WorkspaceInvitationTables } from './drizzle/invitations-schema'\n\n// Re-export the seams an adopter wires, so a consumer can import everything the\n// invitations API needs from this one subpath.\nexport { SeatLimitError } from './members-api'\nexport type { EnforceSeatSeam, MemberSyncSeam } from './members-api'\n\n/** The app's mail transport. Returns a typed outcome; never throws to the API. */\nexport interface SendInvitationEmailInput {\n to: string\n workspaceName: string\n inviterEmail: string\n permission: InvitationPermission\n inviteUrl: string\n expiresAt: Date\n}\n/** Represent the outcome of sending an invitation email with success status and optional error message */\nexport type SendInvitationEmailResult = { succeeded: true } | { succeeded: false; error: string }\n/** Resolve sending an invitation email and return the result asynchronously */\nexport interface SendInvitationEmailSeam {\n (input: SendInvitationEmailInput): Promise<SendInvitationEmailResult>\n}\n\n/** The product's user table, narrowed to the columns the queries read. */\nexport interface InvitationUserTable {\n id: any\n email: any\n emailVerified: any\n}\n\n/** The product's workspace table, narrowed to the columns the queries read. */\nexport interface InvitationWorkspaceTable {\n id: any\n name: any\n}\n\n/** Define configuration options required to manage workspace invitations and related data sources */\nexport interface InvitationsApiOptions {\n db: TeamDatabase\n tables: TeamTables\n /** The invitation table from `createWorkspaceInvitationTable`. */\n invitationsTable: WorkspaceInvitationTables\n userTable: TeamParentTable & InvitationUserTable\n workspaceTable: TeamParentTable & InvitationWorkspaceTable\n access: Pick<WorkspaceAccessApi, 'getWorkspaceAccess'>\n /** REQUIRED — the app's mail transport (e.g. Resend + `inviteEmail` from `./email`). */\n sendInvitationEmail: SendInvitationEmailSeam\n /** OPTIONAL — seat-limit gate at create time; mirrors members-api. */\n enforceSeat?: EnforceSeatSeam\n /** OPTIONAL — fire-and-forget member propagation on accept. */\n memberSyncSeam?: Pick<MemberSyncSeam, 'add'>\n /** Inviter display fallback when the inviter's email is unknown. */\n productDisplayName?: string\n}\n\n/** Represent a workspace invitation with details about inviter, permissions, status, and timestamps */\nexport interface WorkspaceInvitationView {\n id: string\n workspaceId: string\n organizationId: string\n email: string\n invitedByUserId: string\n inviterEmail: string | null\n permissions: InvitationPermission\n token: string\n status: InvitationStatus\n emailStatus: InvitationEmailStatus\n expiresAt: Date\n createdAt: Date\n acceptedAt: Date | null\n revokedAt: Date | null\n lastSentAt: Date | null\n}\n\n/** Describe the structure of an invitation preview with workspace, email, permissions, status, and expiration details */\nexport interface InvitationPreview {\n workspaceId: string\n workspaceName: string\n email: string\n inviterEmail: string | null\n permissions: InvitationPermission\n status: InvitationStatus\n expiresAt: Date\n}\n\n/** Resolve the result of an invitation as success with a value or failure with status and error details */\nexport type InvitationOutcome<T> =\n | { succeeded: true; value: T }\n | { succeeded: false; status: number; error: string }\n\n/**\n * Build the invitations API bound to one product's db/tables/access/seams.\n * Returns the six lifecycle handlers an app mounts in its routes.\n */\nexport function createInvitationsApi(opts: InvitationsApiOptions) {\n const { db, tables, access, sendInvitationEmail, enforceSeat, memberSyncSeam } = opts\n const { organizationMembers, workspaceMembers } = tables\n const { workspaceInvitations } = opts.invitationsTable\n const users = opts.userTable\n const workspaces = opts.workspaceTable\n const productDisplayName = opts.productDisplayName ?? 'A workspace admin'\n\n function fireSync(op: () => Promise<void> | void) {\n try {\n Promise.resolve(op()).catch(() => {})\n } catch {\n // seam threw synchronously — swallow; sync is best-effort by contract.\n }\n }\n\n async function createInvitation(input: {\n workspaceId: string\n email: string\n permissions: string | undefined\n invitedByUserId: string\n origin: string\n now?: Date\n }): Promise<InvitationOutcome<{ invitation: WorkspaceInvitationView; inviteUrl: string; emailError?: string }>> {\n const now = input.now ?? new Date()\n const accessRow = await access.getWorkspaceAccess(input.workspaceId, input.invitedByUserId, 'admin')\n if (!accessRow) return { succeeded: false, status: 404, error: 'Workspace not found' }\n\n const permissions = parseInvitationPermission(input.permissions ?? 'editor')\n if (!permissions) return { succeeded: false, status: 400, error: 'Invalid permissions' }\n if (!hasWorkspaceRole(accessRow.role, permissions)) {\n return { succeeded: false, status: 403, error: 'Cannot assign higher permissions than your own' }\n }\n\n const email = normalizeInvitationEmail(input.email)\n if (!email) return { succeeded: false, status: 400, error: 'Missing email' }\n\n const organizationId = accessRow.organization.id\n const workspaceName = (accessRow.workspace as { name: string }).name\n\n await expirePendingInvitations(input.workspaceId, email, now)\n\n const existingPending = await getPendingInvitation(input.workspaceId, email)\n if (existingPending) return { succeeded: false, status: 409, error: 'A pending invitation already exists for this email' }\n\n const accountCheck = await checkExistingAccountAccess(organizationId, input.workspaceId, email, input.invitedByUserId)\n if (!accountCheck.succeeded) return accountCheck\n\n // Seat gate: only a genuinely NEW seat. The checks above reject re-invites,\n // existing workspace members, and org admins; an existing plain org member is\n // already billable (no new seat), so skip the gate for them — mirrors\n // members-api. The pending row is not inserted yet, so the seam's count\n // reflects current usage and denies the invite that would push OVER the limit\n // (at invite time, not accept time).\n if (enforceSeat && !accountCheck.isExistingOrgMember) {\n try {\n await enforceSeat({ actorId: input.invitedByUserId, organizationId })\n } catch (err) {\n if (err instanceof SeatLimitError) return { succeeded: false, status: err.status, error: err.message }\n throw err\n }\n }\n\n const token = generateInvitationToken()\n const expiresAt = getInvitationExpiresAt(now)\n\n const [created] = await db.insert(workspaceInvitations).values({\n workspaceId: input.workspaceId,\n organizationId,\n email,\n invitedByUserId: input.invitedByUserId,\n permissions,\n token,\n status: 'pending',\n emailStatus: 'not_sent',\n expiresAt,\n createdAt: now,\n }).returning()\n\n const inviteUrl = inviteUrlForToken(input.origin, token)\n const emailResult = await sendInvitationEmail({\n to: email,\n workspaceName,\n inviterEmail: accountCheck.inviterEmail ?? productDisplayName,\n permission: permissions,\n inviteUrl,\n expiresAt,\n })\n\n const emailStatus: InvitationEmailStatus = emailResult.succeeded ? 'sent' : 'failed'\n const [updated] = await db.update(workspaceInvitations)\n .set({ emailStatus, lastSentAt: emailResult.succeeded ? now : null })\n .where(eq(workspaceInvitations.id, created!.id))\n .returning()\n\n return {\n succeeded: true,\n value: {\n invitation: toInvitationView(updated!, accountCheck.inviterEmail),\n inviteUrl,\n emailError: emailResult.succeeded ? undefined : emailResult.error,\n },\n }\n }\n\n async function listInvitations(input: {\n workspaceId: string\n userId: string\n origin: string\n now?: Date\n }): Promise<InvitationOutcome<{ invitations: Array<WorkspaceInvitationView & { inviteUrl: string }> }>> {\n const accessRow = await access.getWorkspaceAccess(input.workspaceId, input.userId, 'admin')\n if (!accessRow) return { succeeded: false, status: 404, error: 'Workspace not found' }\n\n await expirePendingInvitations(input.workspaceId, undefined, input.now ?? new Date())\n\n const rows = await db\n .select({ invitation: workspaceInvitations, inviterEmail: users.email })\n .from(workspaceInvitations)\n .leftJoin(users, eq(users.id, workspaceInvitations.invitedByUserId))\n .where(eq(workspaceInvitations.workspaceId, input.workspaceId))\n .orderBy(sql`${workspaceInvitations.createdAt} desc`)\n\n return {\n succeeded: true,\n value: {\n invitations: rows.map((row: { invitation: WorkspaceInvitationRow; inviterEmail: string | null }) => ({\n ...toInvitationView(row.invitation, row.inviterEmail),\n inviteUrl: inviteUrlForToken(input.origin, row.invitation.token),\n })),\n },\n }\n }\n\n async function resendInvitation(input: {\n invitationId: string\n userId: string\n origin: string\n now?: Date\n }): Promise<InvitationOutcome<{ invitation: WorkspaceInvitationView; inviteUrl: string; emailError?: string }>> {\n const row = await getInvitationById(input.invitationId)\n if (!row) return { succeeded: false, status: 404, error: 'Invitation not found' }\n\n const accessRow = await access.getWorkspaceAccess(row.invitation.workspaceId, input.userId, 'admin')\n if (!accessRow) return { succeeded: false, status: 404, error: 'Workspace not found' }\n\n const now = input.now ?? new Date()\n if (row.invitation.status !== 'pending') {\n return { succeeded: false, status: 409, error: 'Only pending invitations can be resent' }\n }\n if (row.invitation.expiresAt <= now) {\n await markInvitationExpired(row.invitation.id)\n return { succeeded: false, status: 409, error: 'Invitation has expired' }\n }\n\n const workspaceName = (accessRow.workspace as { name: string }).name\n const inviteUrl = inviteUrlForToken(input.origin, row.invitation.token)\n const emailResult = await sendInvitationEmail({\n to: row.invitation.email,\n workspaceName,\n inviterEmail: row.inviterEmail ?? productDisplayName,\n permission: row.invitation.permissions,\n inviteUrl,\n expiresAt: row.invitation.expiresAt,\n })\n\n const [updated] = await db.update(workspaceInvitations)\n .set({\n emailStatus: emailResult.succeeded ? 'sent' : 'failed',\n lastSentAt: emailResult.succeeded ? now : row.invitation.lastSentAt,\n })\n .where(eq(workspaceInvitations.id, row.invitation.id))\n .returning()\n\n return {\n succeeded: true,\n value: {\n invitation: toInvitationView(updated!, row.inviterEmail),\n inviteUrl,\n emailError: emailResult.succeeded ? undefined : emailResult.error,\n },\n }\n }\n\n async function revokeInvitation(input: {\n invitationId: string\n userId: string\n now?: Date\n }): Promise<InvitationOutcome<{ invitation: WorkspaceInvitationView }>> {\n const row = await getInvitationById(input.invitationId)\n if (!row) return { succeeded: false, status: 404, error: 'Invitation not found' }\n\n const accessRow = await access.getWorkspaceAccess(row.invitation.workspaceId, input.userId, 'admin')\n if (!accessRow) return { succeeded: false, status: 404, error: 'Workspace not found' }\n if (row.invitation.status !== 'pending') {\n return { succeeded: false, status: 409, error: 'Only pending invitations can be revoked' }\n }\n\n const [updated] = await db.update(workspaceInvitations)\n .set({ status: 'revoked', revokedAt: input.now ?? new Date() })\n .where(and(eq(workspaceInvitations.id, row.invitation.id), eq(workspaceInvitations.status, 'pending')))\n .returning()\n\n // The status read above is advisory. A concurrent accept may win between\n // that read and this update, so the write must be compare-and-set.\n if (!updated) return { succeeded: false, status: 409, error: 'The invitation changed. Reload it before continuing.' }\n\n return { succeeded: true, value: { invitation: toInvitationView(updated!, row.inviterEmail) } }\n }\n\n async function getPreview(token: string, now: Date = new Date()): Promise<InvitationOutcome<InvitationPreview>> {\n const row = await getInvitationByToken(token)\n if (!row) return { succeeded: false, status: 404, error: 'Invitation not found' }\n\n let invitation = row.invitation\n if (invitation.status === 'pending' && invitation.expiresAt <= now) {\n invitation = await markInvitationExpired(invitation.id)\n }\n\n return {\n succeeded: true,\n value: {\n workspaceId: invitation.workspaceId,\n workspaceName: row.workspaceName,\n email: invitation.email,\n inviterEmail: row.inviterEmail,\n permissions: invitation.permissions,\n status: invitation.status,\n expiresAt: invitation.expiresAt,\n },\n }\n }\n\n async function acceptInvitation(input: {\n token: string\n userId: string\n now?: Date\n }): Promise<InvitationOutcome<{ workspaceId: string }>> {\n const now = input.now ?? new Date()\n const row = await getInvitationByToken(input.token)\n if (!row) return { succeeded: false, status: 404, error: 'Invitation not found' }\n\n let invitation = row.invitation\n if (invitation.status === 'pending' && invitation.expiresAt <= now) {\n invitation = await markInvitationExpired(invitation.id)\n }\n\n const [currentUser] = await db\n .select({ id: users.id, email: users.email, emailVerified: users.emailVerified })\n .from(users)\n .where(eq(users.id, input.userId))\n .limit(1)\n if (!currentUser) return { succeeded: false, status: 401, error: 'Authentication required' }\n\n if (normalizeInvitationEmail(currentUser.email) !== invitation.email) {\n return { succeeded: false, status: 403, error: 'Sign in with the invited email address to accept this invitation' }\n }\n\n const collisionCheck = await findUsersByNormalizedEmail(invitation.email)\n if (collisionCheck.length > 1) {\n return {\n succeeded: false,\n status: 409,\n error: 'Multiple accounts use this email. Contact support to reconcile before accepting this invitation.',\n }\n }\n\n let orgMember = await getOrganizationMember(invitation.organizationId, currentUser.id)\n if (orgMember?.role === 'owner' || orgMember?.role === 'admin') {\n return { succeeded: false, status: 409, error: 'This user already has account-level access.' }\n }\n\n if (invitation.status === 'accepted') {\n const existing = orgMember ? await getWorkspaceMemberByOrganizationMember(invitation.workspaceId, orgMember.id) : null\n if (existing) return { succeeded: true, value: { workspaceId: invitation.workspaceId } }\n return { succeeded: false, status: 409, error: 'Invitation has already been accepted' }\n }\n if (invitation.status === 'expired') return { succeeded: false, status: 409, error: 'Invitation has expired' }\n if (invitation.status === 'revoked') return { succeeded: false, status: 409, error: 'Invitation has been revoked' }\n\n if (!orgMember) {\n const [inserted] = await db.insert(organizationMembers).values({\n organizationId: invitation.organizationId,\n userId: currentUser.id,\n role: 'member',\n createdAt: now,\n updatedAt: now,\n }).returning()\n if (!inserted) return { succeeded: false, status: 500, error: 'Failed to create organization membership' }\n orgMember = inserted\n }\n\n const existingMember = await getWorkspaceMemberByOrganizationMember(invitation.workspaceId, orgMember.id)\n if (!existingMember) {\n await db.insert(workspaceMembers).values({\n workspaceId: invitation.workspaceId,\n organizationMemberId: orgMember.id,\n userId: currentUser.id,\n role: invitation.permissions,\n inviteEmail: invitation.email,\n // members-api nulls the token on accept to release the unique slot; the\n // invitations flow keeps it (its `inv_` tokens never collide), so the\n // materialized row carries the originating token for audit.\n inviteToken: invitation.token,\n invitedAt: now,\n acceptedAt: now,\n })\n if (memberSyncSeam?.add) {\n const userId = currentUser.id\n const role = invitation.permissions as WorkspaceRole\n fireSync(() => memberSyncSeam.add!({ workspaceId: invitation.workspaceId, userId, role }))\n }\n }\n\n const [accepted] = await db.update(workspaceInvitations)\n .set({ status: 'accepted', acceptedAt: now })\n .where(and(eq(workspaceInvitations.id, invitation.id), eq(workspaceInvitations.status, 'pending')))\n .returning()\n\n if (!accepted) {\n // Membership was materialized before the final compare-and-set. Remove\n // only the row created by this attempt before reporting the conflict.\n await db.delete(workspaceMembers)\n .where(and(eq(workspaceMembers.workspaceId, invitation.workspaceId), eq(workspaceMembers.userId, currentUser.id)))\n return { succeeded: false, status: 409, error: 'The invitation changed. Reload it before continuing.' }\n }\n\n return { succeeded: true, value: { workspaceId: invitation.workspaceId } }\n }\n\n // ── internal query helpers ──\n\n async function expirePendingInvitations(workspaceId: string, email: string | undefined, now: Date) {\n const conditions = [\n eq(workspaceInvitations.workspaceId, workspaceId),\n eq(workspaceInvitations.status, 'pending' as const),\n lte(workspaceInvitations.expiresAt, now),\n ]\n if (email) conditions.push(eq(workspaceInvitations.email, email))\n await db.update(workspaceInvitations).set({ status: 'expired' }).where(and(...conditions))\n }\n\n async function getPendingInvitation(workspaceId: string, email: string) {\n const [invitation] = await db\n .select({ id: workspaceInvitations.id })\n .from(workspaceInvitations)\n .where(and(\n eq(workspaceInvitations.workspaceId, workspaceId),\n eq(workspaceInvitations.email, email),\n eq(workspaceInvitations.status, 'pending' as const),\n ))\n .limit(1)\n return invitation ?? null\n }\n\n async function checkExistingAccountAccess(\n organizationId: string,\n workspaceId: string,\n email: string,\n invitedByUserId: string,\n ): Promise<\n | { succeeded: false; status: number; error: string }\n | { succeeded: true; inviterEmail: string | null; isExistingOrgMember: boolean }\n > {\n const matchingUsers = await findUsersByNormalizedEmail(email)\n const [inviter] = await db\n .select({ email: users.email })\n .from(users)\n .where(eq(users.id, invitedByUserId))\n .limit(1)\n\n if (matchingUsers.length > 1) {\n return {\n succeeded: false,\n status: 409,\n error: 'Multiple accounts use this email. Contact support to reconcile before inviting this user.',\n }\n }\n const existingUser = matchingUsers[0]\n if (!existingUser) return { succeeded: true, inviterEmail: inviter?.email ?? null, isExistingOrgMember: false }\n\n const orgMember = await getOrganizationMember(organizationId, existingUser.id)\n if (orgMember?.role === 'owner' || orgMember?.role === 'admin') {\n return { succeeded: false, status: 409, error: 'This user already has account-level access.' }\n }\n if (orgMember) {\n const workspaceMember = await getWorkspaceMemberByOrganizationMember(workspaceId, orgMember.id)\n if (workspaceMember) return { succeeded: false, status: 409, error: 'User is already a workspace member' }\n }\n\n return { succeeded: true, inviterEmail: inviter?.email ?? null, isExistingOrgMember: Boolean(orgMember) }\n }\n\n async function findUsersByNormalizedEmail(email: string) {\n return db\n .select({ id: users.id, email: users.email, emailVerified: users.emailVerified })\n .from(users)\n .where(sql`lower(${users.email}) = ${email}`)\n }\n\n async function getOrganizationMember(organizationId: string, userId: string) {\n const [member] = await db\n .select()\n .from(organizationMembers)\n .where(and(eq(organizationMembers.organizationId, organizationId), eq(organizationMembers.userId, userId)))\n .limit(1)\n return member ?? null\n }\n\n async function getWorkspaceMemberByOrganizationMember(workspaceId: string, organizationMemberId: string) {\n const [member] = await db\n .select({ id: workspaceMembers.id })\n .from(workspaceMembers)\n .where(and(\n eq(workspaceMembers.workspaceId, workspaceId),\n eq(workspaceMembers.organizationMemberId, organizationMemberId),\n ))\n .limit(1)\n return member ?? null\n }\n\n async function getInvitationById(invitationId: string) {\n const [row] = await db\n .select({ invitation: workspaceInvitations, inviterEmail: users.email })\n .from(workspaceInvitations)\n .leftJoin(users, eq(users.id, workspaceInvitations.invitedByUserId))\n .where(eq(workspaceInvitations.id, invitationId))\n .limit(1)\n return row ?? null\n }\n\n async function getInvitationByToken(token: string) {\n const [row] = await db\n .select({\n invitation: workspaceInvitations,\n workspaceName: workspaces.name,\n inviterEmail: users.email,\n })\n .from(workspaceInvitations)\n .innerJoin(workspaces, eq(workspaces.id, workspaceInvitations.workspaceId))\n .leftJoin(users, eq(users.id, workspaceInvitations.invitedByUserId))\n .where(eq(workspaceInvitations.token, token))\n .limit(1)\n return row ?? null\n }\n\n async function markInvitationExpired(invitationId: string) {\n const [updated] = await db.update(workspaceInvitations)\n .set({ status: 'expired' })\n .where(eq(workspaceInvitations.id, invitationId))\n .returning()\n return updated!\n }\n\n function toInvitationView(invitation: WorkspaceInvitationRow, inviterEmail: string | null): WorkspaceInvitationView {\n return {\n id: invitation.id,\n workspaceId: invitation.workspaceId,\n organizationId: invitation.organizationId,\n email: invitation.email,\n invitedByUserId: invitation.invitedByUserId,\n inviterEmail,\n permissions: invitation.permissions,\n token: invitation.token,\n status: invitation.status,\n emailStatus: invitation.emailStatus,\n expiresAt: invitation.expiresAt,\n createdAt: invitation.createdAt,\n acceptedAt: invitation.acceptedAt,\n revokedAt: invitation.revokedAt,\n lastSentAt: invitation.lastSentAt,\n }\n }\n\n return { createInvitation, listInvitations, resendInvitation, revokeInvitation, getPreview, acceptInvitation }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA0BA,SAAS,KAAK,IAAI,KAAK,WAAW;AA6G3B,SAAS,qBAAqB,MAA6B;AAChE,QAAM,EAAE,IAAI,QAAQ,QAAQ,qBAAqB,aAAa,eAAe,IAAI;AACjF,QAAM,EAAE,qBAAqB,iBAAi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BAAkB,YAAY,iBAAiB;AAC/G;","names":[]}
|
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Pure invitation helpers
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* template renderer without dragging in drizzle or a mail client.
|
|
7
|
-
*
|
|
8
|
-
* `renderInvitationEmail` is deliberately transport-free: it returns the
|
|
9
|
-
* `{ from, subject, html, text }` an app hands to its own Resend/SES/etc. The
|
|
10
|
-
* secret (API key) and the network call stay in the app's seam — agent-app ships
|
|
11
|
-
* only the deterministic template.
|
|
2
|
+
* Pure invitation helpers for the teams capability. Zero dependencies: no
|
|
3
|
+
* drizzle, no env, no react, no network. The lifecycle API (`./invitations-api`)
|
|
4
|
+
* and an app's own mail transport build on these; the invitation email itself
|
|
5
|
+
* is `inviteEmail` from `@tangle-network/agent-app/email`.
|
|
12
6
|
*/
|
|
13
7
|
import type { AssignableWorkspaceRole } from './roles';
|
|
14
8
|
/** The role an invitation grants — the assignable workspace ladder (never owner). */
|
|
@@ -33,30 +27,3 @@ export declare function getInvitationExpiresAt(now?: Date): Date;
|
|
|
33
27
|
export declare function generateInvitationToken(): string;
|
|
34
28
|
/** Generate an invite URL by combining the origin with an encoded token */
|
|
35
29
|
export declare function inviteUrlForToken(origin: string, token: string): string;
|
|
36
|
-
/** Define input data required to render an invitation email template */
|
|
37
|
-
export interface RenderInvitationEmailInput {
|
|
38
|
-
to: string;
|
|
39
|
-
workspaceName: string;
|
|
40
|
-
inviterEmail: string;
|
|
41
|
-
permission: string;
|
|
42
|
-
inviteUrl: string;
|
|
43
|
-
expiresAt: Date;
|
|
44
|
-
}
|
|
45
|
-
/** Define the structure for an invitation email brand including the RFC-5322 From header */
|
|
46
|
-
export interface InvitationEmailBrand {
|
|
47
|
-
/** RFC-5322 From header, e.g. `GTM Agent <noreply@gtm.tangle.tools>`. */
|
|
48
|
-
fromAddress: string;
|
|
49
|
-
}
|
|
50
|
-
/** Define the structure of a fully rendered invitation email with sender, subject, and content fields */
|
|
51
|
-
export interface RenderedInvitationEmail {
|
|
52
|
-
from: string;
|
|
53
|
-
subject: string;
|
|
54
|
-
html: string;
|
|
55
|
-
text: string;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Render the invitation email body — pure, deterministic, transport-free. The
|
|
59
|
-
* caller passes the result to its own mail client; this never reads a secret or
|
|
60
|
-
* touches the network.
|
|
61
|
-
*/
|
|
62
|
-
export declare function renderInvitationEmail(input: RenderInvitationEmailInput, brand: InvitationEmailBrand): RenderedInvitationEmail;
|
package/dist/web-react/index.js
CHANGED
|
@@ -206,11 +206,11 @@ import {
|
|
|
206
206
|
usePending,
|
|
207
207
|
usePopover
|
|
208
208
|
} from "../chunk-HG4OONJA.js";
|
|
209
|
+
import "../chunk-SJWIZT7B.js";
|
|
209
210
|
import {
|
|
210
211
|
tabTerminalConnectionId,
|
|
211
212
|
useSandboxTerminalConnection
|
|
212
213
|
} from "../chunk-E4AY62T2.js";
|
|
213
|
-
import "../chunk-SJWIZT7B.js";
|
|
214
214
|
import "../chunk-LSUELMHY.js";
|
|
215
215
|
import "../chunk-FQYAJYPW.js";
|
|
216
216
|
import {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tangle-network/agent-app",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.59.1",
|
|
4
4
|
"packageManager": "pnpm@11.24.0",
|
|
5
5
|
"description": "Build agent applications with typed chat, tools, sandboxes, integrations, billing, and evaluation.",
|
|
6
6
|
"keywords": [
|
|
@@ -70,6 +70,11 @@
|
|
|
70
70
|
"import": "./dist/app-auth/index.js",
|
|
71
71
|
"default": "./dist/app-auth/index.js"
|
|
72
72
|
},
|
|
73
|
+
"./email": {
|
|
74
|
+
"types": "./dist/email/index.d.ts",
|
|
75
|
+
"import": "./dist/email/index.js",
|
|
76
|
+
"default": "./dist/email/index.js"
|
|
77
|
+
},
|
|
73
78
|
"./app-oauth": {
|
|
74
79
|
"types": "./dist/app-oauth/index.d.ts",
|
|
75
80
|
"import": "./dist/app-oauth/index.js",
|
package/dist/chunk-2DRYTJHI.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
// src/teams/invitations.ts
|
|
2
|
-
var INVITATION_EXPIRY_DAYS = 7;
|
|
3
|
-
var INVITATION_PERMISSIONS = ["admin", "editor", "viewer"];
|
|
4
|
-
var TOKEN_BYTE_LENGTH = 32;
|
|
5
|
-
function normalizeInvitationEmail(email) {
|
|
6
|
-
return email.trim().toLowerCase();
|
|
7
|
-
}
|
|
8
|
-
function parseInvitationPermission(value) {
|
|
9
|
-
return INVITATION_PERMISSIONS.includes(value) ? value : null;
|
|
10
|
-
}
|
|
11
|
-
function getInvitationExpiresAt(now = /* @__PURE__ */ new Date()) {
|
|
12
|
-
return new Date(now.getTime() + INVITATION_EXPIRY_DAYS * 24 * 60 * 60 * 1e3);
|
|
13
|
-
}
|
|
14
|
-
function generateInvitationToken() {
|
|
15
|
-
const bytes = new Uint8Array(TOKEN_BYTE_LENGTH);
|
|
16
|
-
globalThis.crypto.getRandomValues(bytes);
|
|
17
|
-
const token = Array.from(bytes, (byte) => String.fromCharCode(byte)).join("");
|
|
18
|
-
return `inv_${btoa(token).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "")}`;
|
|
19
|
-
}
|
|
20
|
-
function inviteUrlForToken(origin, token) {
|
|
21
|
-
return `${origin.replace(/\/+$/, "")}/invite/${encodeURIComponent(token)}`;
|
|
22
|
-
}
|
|
23
|
-
function renderInvitationEmail(input, brand) {
|
|
24
|
-
const role = input.permission.toLowerCase();
|
|
25
|
-
const expiry = input.expiresAt.toLocaleDateString("en-US", {
|
|
26
|
-
month: "short",
|
|
27
|
-
day: "numeric",
|
|
28
|
-
year: "numeric"
|
|
29
|
-
});
|
|
30
|
-
return {
|
|
31
|
-
from: brand.fromAddress,
|
|
32
|
-
subject: `${input.inviterEmail} invited you to ${input.workspaceName}`,
|
|
33
|
-
html: [
|
|
34
|
-
`<p>${escapeHtml(input.inviterEmail)} invited you to join <strong>${escapeHtml(input.workspaceName)}</strong> as ${escapeHtml(role)}.</p>`,
|
|
35
|
-
`<p><a href="${input.inviteUrl}">Accept the invitation</a></p>`,
|
|
36
|
-
`<p>This invitation expires on ${expiry}.</p>`
|
|
37
|
-
].join(""),
|
|
38
|
-
text: [
|
|
39
|
-
`${input.inviterEmail} invited you to join ${input.workspaceName} as ${role}.`,
|
|
40
|
-
`Accept the invitation: ${input.inviteUrl}`,
|
|
41
|
-
`This invitation expires on ${expiry}.`
|
|
42
|
-
].join("\n\n")
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
function escapeHtml(value) {
|
|
46
|
-
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export {
|
|
50
|
-
INVITATION_EXPIRY_DAYS,
|
|
51
|
-
normalizeInvitationEmail,
|
|
52
|
-
parseInvitationPermission,
|
|
53
|
-
getInvitationExpiresAt,
|
|
54
|
-
generateInvitationToken,
|
|
55
|
-
inviteUrlForToken,
|
|
56
|
-
renderInvitationEmail
|
|
57
|
-
};
|
|
58
|
-
//# sourceMappingURL=chunk-2DRYTJHI.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/teams/invitations.ts"],"sourcesContent":["/**\n * Pure invitation helpers + email-template renderer for the teams capability.\n * Zero dependencies: no drizzle, no env, no react, no network. The lifecycle API\n * (`./invitations-api`) and an app's own mail transport build on these; this leaf\n * imports nothing back, so a consumer can pull just the token/expiry math or the\n * template renderer without dragging in drizzle or a mail client.\n *\n * `renderInvitationEmail` is deliberately transport-free: it returns the\n * `{ from, subject, html, text }` an app hands to its own Resend/SES/etc. The\n * secret (API key) and the network call stay in the app's seam — agent-app ships\n * only the deterministic template.\n */\n\nimport type { AssignableWorkspaceRole } from './roles'\n\n/** The role an invitation grants — the assignable workspace ladder (never owner). */\nexport type InvitationPermission = AssignableWorkspaceRole\n\n/** Define possible states for an invitation's lifecycle including pending, accepted, expired, and revoked */\nexport type InvitationStatus = 'pending' | 'accepted' | 'expired' | 'revoked'\n/** Define possible statuses for the sending state of an invitation email */\nexport type InvitationEmailStatus = 'not_sent' | 'sent' | 'failed'\n\n/** Define the number of days before an invitation expires */\nexport const INVITATION_EXPIRY_DAYS = 7\n\nconst INVITATION_PERMISSIONS = ['admin', 'editor', 'viewer'] as const\nconst TOKEN_BYTE_LENGTH = 32\n\n/** Normalize an invitation email by trimming whitespace and converting to lowercase */\nexport function normalizeInvitationEmail(email: string): string {\n return email.trim().toLowerCase()\n}\n\n/** Resolve invitation permission from a string or return null if invalid */\nexport function parseInvitationPermission(value: string | undefined): InvitationPermission | null {\n return INVITATION_PERMISSIONS.includes(value as InvitationPermission) ? (value as InvitationPermission) : null\n}\n\n/** Calculate the expiration date of an invitation based on the given or current date */\nexport function getInvitationExpiresAt(now: Date = new Date()): Date {\n return new Date(now.getTime() + INVITATION_EXPIRY_DAYS * 24 * 60 * 60 * 1000)\n}\n\n/**\n * A cryptographically-random, URL-safe invitation token. `inv_`-prefixed so a\n * token is self-identifying and never collides with the workspaceMember invite\n * tokens minted by `members-api` (`generateInviteToken`).\n */\nexport function generateInvitationToken(): string {\n const bytes = new Uint8Array(TOKEN_BYTE_LENGTH)\n globalThis.crypto.getRandomValues(bytes)\n const token = Array.from(bytes, (byte) => String.fromCharCode(byte)).join('')\n return `inv_${btoa(token).replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=+$/g, '')}`\n}\n\n/** Generate an invite URL by combining the origin with an encoded token */\nexport function inviteUrlForToken(origin: string, token: string): string {\n return `${origin.replace(/\\/+$/, '')}/invite/${encodeURIComponent(token)}`\n}\n\n// ── email template (pure; no transport) ──\n\n/** Define input data required to render an invitation email template */\nexport interface RenderInvitationEmailInput {\n to: string\n workspaceName: string\n inviterEmail: string\n permission: string\n inviteUrl: string\n expiresAt: Date\n}\n\n/** Define the structure for an invitation email brand including the RFC-5322 From header */\nexport interface InvitationEmailBrand {\n /** RFC-5322 From header, e.g. `GTM Agent <noreply@gtm.tangle.tools>`. */\n fromAddress: string\n}\n\n/** Define the structure of a fully rendered invitation email with sender, subject, and content fields */\nexport interface RenderedInvitationEmail {\n from: string\n subject: string\n html: string\n text: string\n}\n\n/**\n * Render the invitation email body — pure, deterministic, transport-free. The\n * caller passes the result to its own mail client; this never reads a secret or\n * touches the network.\n */\nexport function renderInvitationEmail(\n input: RenderInvitationEmailInput,\n brand: InvitationEmailBrand,\n): RenderedInvitationEmail {\n const role = input.permission.toLowerCase()\n const expiry = input.expiresAt.toLocaleDateString('en-US', {\n month: 'short',\n day: 'numeric',\n year: 'numeric',\n })\n return {\n from: brand.fromAddress,\n subject: `${input.inviterEmail} invited you to ${input.workspaceName}`,\n html: [\n `<p>${escapeHtml(input.inviterEmail)} invited you to join <strong>${escapeHtml(input.workspaceName)}</strong> as ${escapeHtml(role)}.</p>`,\n `<p><a href=\"${input.inviteUrl}\">Accept the invitation</a></p>`,\n `<p>This invitation expires on ${expiry}.</p>`,\n ].join(''),\n text: [\n `${input.inviterEmail} invited you to join ${input.workspaceName} as ${role}.`,\n `Accept the invitation: ${input.inviteUrl}`,\n `This invitation expires on ${expiry}.`,\n ].join('\\n\\n'),\n }\n}\n\nfunction escapeHtml(value: string): string {\n return value\n .replace(/&/g, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/\"/g, '"')\n .replace(/'/g, ''')\n}\n"],"mappings":";AAwBO,IAAM,yBAAyB;AAEtC,IAAM,yBAAyB,CAAC,SAAS,UAAU,QAAQ;AAC3D,IAAM,oBAAoB;AAGnB,SAAS,yBAAyB,OAAuB;AAC9D,SAAO,MAAM,KAAK,EAAE,YAAY;AAClC;AAGO,SAAS,0BAA0B,OAAwD;AAChG,SAAO,uBAAuB,SAAS,KAA6B,IAAK,QAAiC;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