@happyvertical/smrt-messages 0.62.5 → 0.62.7
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/AGENTS.md +72 -0
- package/dist/access-enforcement.d.ts +20 -0
- package/dist/access-enforcement.d.ts.map +1 -0
- package/dist/access.d.ts +203 -0
- package/dist/access.d.ts.map +1 -0
- package/dist/chunks/AttachmentCollection-nTqD75n8.js +308 -0
- package/dist/chunks/AttachmentCollection-nTqD75n8.js.map +1 -0
- package/dist/chunks/{Email-rizVmZC9.js → Email-DKcIiMxB.js} +6 -6
- package/dist/chunks/{Email-rizVmZC9.js.map → Email-DKcIiMxB.js.map} +1 -1
- package/dist/chunks/EmailAccountCollection-DtCuHcB4.js +1224 -0
- package/dist/chunks/EmailAccountCollection-DtCuHcB4.js.map +1 -0
- package/dist/chunks/EmailCollection-BYeuWWsP.js +181 -0
- package/dist/chunks/EmailCollection-BYeuWWsP.js.map +1 -0
- package/dist/chunks/{EmailFolder-Dk9hx1HT.js → EmailFolder-UMGpXTQ7.js} +25 -6
- package/dist/chunks/EmailFolder-UMGpXTQ7.js.map +1 -0
- package/dist/chunks/EmailFolderCollection-DHZKwe1H.js +177 -0
- package/dist/chunks/EmailFolderCollection-DHZKwe1H.js.map +1 -0
- package/dist/chunks/EmailSender-B-Rtq9du.js +147 -0
- package/dist/chunks/EmailSender-B-Rtq9du.js.map +1 -0
- package/dist/chunks/{Message-QoL9DoTt.js → Message-M8INXZs5.js} +30 -6
- package/dist/chunks/Message-M8INXZs5.js.map +1 -0
- package/dist/chunks/{MessageCollection-B3YHj1hX.js → MessageCollection-CT0O_7wG.js} +2 -2
- package/dist/chunks/{MessageCollection-B3YHj1hX.js.map → MessageCollection-CT0O_7wG.js.map} +1 -1
- package/dist/chunks/MessagingEndpointCollection-DrNvP8GM.js +97 -0
- package/dist/chunks/MessagingEndpointCollection-DrNvP8GM.js.map +1 -0
- package/dist/collections/AttachmentCollection.d.ts +6 -0
- package/dist/collections/AttachmentCollection.d.ts.map +1 -1
- package/dist/connect.d.ts +82 -0
- package/dist/connect.d.ts.map +1 -0
- package/dist/connect.js +126 -0
- package/dist/connect.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +458 -1399
- package/dist/index.js.map +1 -1
- package/dist/manifest.json +892 -32
- package/dist/models/Account.d.ts +23 -0
- package/dist/models/Account.d.ts.map +1 -1
- package/dist/models/Attachment.d.ts +14 -0
- package/dist/models/Attachment.d.ts.map +1 -1
- package/dist/models/EmailAccount.d.ts +3 -0
- package/dist/models/EmailAccount.d.ts.map +1 -1
- package/dist/models/EmailFolder.d.ts +7 -0
- package/dist/models/EmailFolder.d.ts.map +1 -1
- package/dist/models/Message.d.ts +7 -0
- package/dist/models/Message.d.ts.map +1 -1
- package/dist/permissions.d.ts +11 -0
- package/dist/permissions.d.ts.map +1 -1
- package/dist/services/MessagingSettingsService.d.ts +86 -0
- package/dist/services/MessagingSettingsService.d.ts.map +1 -1
- package/dist/services/NotificationOutboxService.d.ts +3 -0
- package/dist/services/NotificationOutboxService.d.ts.map +1 -1
- package/dist/smrt-knowledge.json +762 -21
- package/dist/smrt-knowledge.okf.md +3 -2
- package/dist/types.d.ts +5 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +20 -16
- package/dist/chunks/AccountCollection-C4vlT1ZY.js +0 -257
- package/dist/chunks/AccountCollection-C4vlT1ZY.js.map +0 -1
- package/dist/chunks/EmailFolder-Dk9hx1HT.js.map +0 -1
- package/dist/chunks/Message-QoL9DoTt.js.map +0 -1
- package/dist/chunks/__smrt-register__-B48BcESB.js +0 -6
- package/dist/chunks/__smrt-register__-B48BcESB.js.map +0 -1
package/AGENTS.md
CHANGED
|
@@ -34,6 +34,78 @@ Multi-channel messaging with STI hierarchies for both messages and accounts. Cre
|
|
|
34
34
|
generated mutations around the settings service or make secret fields writable.
|
|
35
35
|
- **Recipe `messages.slack`** (`src/recipes.ts`, help in `src/help/slack.md`): lists Slack messages and workspaces beside the Mailbox and Notifications recipes; workspaces stay read-only and sending goes through the senders, not generated routes. Fields it shows carry `@field({ description })` in plain words; keep them when editing the models.
|
|
36
36
|
|
|
37
|
+
## Per-account mail access (owner + grants)
|
|
38
|
+
|
|
39
|
+
Optional by default: `Account.ownerUserId` is nullable, and an account without
|
|
40
|
+
an owner stays tenant-wide. Apps that want private or shared mailboxes set
|
|
41
|
+
owners and call `configureMailAccess({ options, resolvePrincipal })` at startup
|
|
42
|
+
(`access.ts`); smrt never knows the host's credential model, the host returns a
|
|
43
|
+
`MailPrincipal` (`userId` + tenant, optional `scopes` / `accountIds` ceilings).
|
|
44
|
+
|
|
45
|
+
- Scopes `read`, `triage`, `draft`, `send` are `ResourceGrant` rows (resource
|
|
46
|
+
type `messages:account`, permission `messages.<scope>`) checked by
|
|
47
|
+
`checkResourceOperationPermission`, so the grantee also needs the tenant
|
|
48
|
+
`messages.<scope>` permission (the ceiling). The owner holds every scope
|
|
49
|
+
implicitly. Agents are `User` rows the host maps its credential to; the
|
|
50
|
+
principal ceilings are intersected with the grant, never added to it.
|
|
51
|
+
- `access-enforcement.ts` is a `GlobalInterceptors` entry registered at package
|
|
52
|
+
load. Emails, folders and attachments (matched by STI ancestry) are filtered
|
|
53
|
+
in `beforeList`/`afterList`/`afterGet`; raw `query()` on them is refused while
|
|
54
|
+
any account is closed to the principal. Fail closed: no principal, no
|
|
55
|
+
resolver or a foreign tenant means owned accounts are invisible. No tenant
|
|
56
|
+
admin or super-admin bypass; trusted work (sync, outbox) uses
|
|
57
|
+
`runWithMailSystemAccess()`. `EmailAccount.syncFrom()` does so itself.
|
|
58
|
+
- Attachments carry a denormalized `accountId` (always derived from the message in a
|
|
59
|
+
`beforeSave` interceptor, never caller-supplied) so lists, projections and counts filter in SQL; run
|
|
60
|
+
`AttachmentCollection.backfillAccountIds()` once after upgrading (legacy rows
|
|
61
|
+
without it are hidden from every read until then).
|
|
62
|
+
- `connectMailbox` refuses by default: give the service `allowedMailHosts`
|
|
63
|
+
(and optionally `allowedMailPorts`) or your own `validateMailbox`. The
|
|
64
|
+
built-in validator never connects to private, loopback or link-local
|
|
65
|
+
addresses and returns only a generic error. Policy lookups use the
|
|
66
|
+
configured db handle, not a caller's transaction.
|
|
67
|
+
- `Message.send()` needs the `send` scope on an owned account. Account rows are
|
|
68
|
+
not filtered (senders, routes and the outbox read them without a principal).
|
|
69
|
+
- `MailAccessService` (`grant`, `revoke`, `list`, `setOwner`) needs tenant
|
|
70
|
+
`messages.manage-access` AND ownership (or delegation); an administrator
|
|
71
|
+
cannot read, self-grant or take over an owned mailbox. Unowned accounts can be
|
|
72
|
+
claimed once with `messages.manage-credentials`.
|
|
73
|
+
- Before `configureMailAccess` is called the policy still fails closed on
|
|
74
|
+
owned accounts: every collection operation on a mail class (the core `onCollectionReady`
|
|
75
|
+
interceptor hook, so STI subclasses on a default collection are covered) registers its
|
|
76
|
+
database, per database, and the policy hides every owned account's mail
|
|
77
|
+
through list, count, projections, facets and raw queries; it learns the database from the first mail or account row it
|
|
78
|
+
sees and, with no principal resolver, hides every owned account's mail.
|
|
79
|
+
Direct hydration (`new Email({ id }).initialize()`, `loadRelated()`) is gated
|
|
80
|
+
in the models' `loadFromId`/`loadFromSlug`.
|
|
81
|
+
- `connectionStatus` (`connected` / `needs_reconnect`) and `statusMessage` mark
|
|
82
|
+
an account whose sign-in the server refused; `syncFrom()` sets it.
|
|
83
|
+
|
|
84
|
+
## Mailbox connect (provider-neutral)
|
|
85
|
+
|
|
86
|
+
Credentials reach smrt-secrets in two ways; neither writes the plaintext `settings` fallback.
|
|
87
|
+
|
|
88
|
+
- **Write-only app password**: `MessagingSettingsService.connectMailbox()`
|
|
89
|
+
(permission `messages.manage-credentials`). The candidate credential is
|
|
90
|
+
validated by opening a session first (`validateMailbox` option, default the
|
|
91
|
+
provider's email client); a refusal leaves no account and no secret, and the
|
|
92
|
+
error text has the secret redacted. The connecting user becomes the owner;
|
|
93
|
+
`label` and the per-account endpoint (`configuration`) are stored; reconnect
|
|
94
|
+
replaces the secret and is owner-only. `setAccountActive()` pauses/resumes
|
|
95
|
+
(`isActive`), `removeAccount()` deletes the secret, the synced mail and the
|
|
96
|
+
account. IMAP/POP3 are admitted here (receive-only), not by `saveAccount`.
|
|
97
|
+
- **Generic OAuth 2.0 / OIDC**: `@happyvertical/smrt-messages/connect`
|
|
98
|
+
(`startMailOAuthConnect`, `completeMailOAuthConnect`, `MailOAuthProvider`)
|
|
99
|
+
on the shared kernel `@happyvertical/smrt-secrets/connect` (single-use
|
|
100
|
+
tenant- and user-bound `ConnectState`, PKCE, safe return path, OIDC
|
|
101
|
+
discovery with issuer check). The signed-in user becomes the owner; an
|
|
102
|
+
account owned by someone else or by no one is never taken over. No role
|
|
103
|
+
checks in the flow: authorize before calling.
|
|
104
|
+
- **Reconnect**: `syncFrom()` marks an auth failure `connectionStatus =
|
|
105
|
+
'needs_reconnect'` (`Account.markNeedsReconnect/markConnected`) instead of
|
|
106
|
+
failing silently.
|
|
107
|
+
- The Google provider is a later step (sdk#1405), not part of this flow.
|
|
108
|
+
|
|
37
109
|
## In-app notifications (`UserNotification`)
|
|
38
110
|
|
|
39
111
|
The in-app channel: one stored row per person, with read state.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Collection-layer enforcement of per-account mail access (see `access.ts`).
|
|
3
|
+
*
|
|
4
|
+
* Registered once at package load as a `GlobalInterceptors` entry, so every
|
|
5
|
+
* list/get/count/raw read of an owned account's emails, folders and
|
|
6
|
+
* attachments is filtered in the collection, not in a component. Matching is
|
|
7
|
+
* by STI ancestry, so an app subclass of `Email` is governed too.
|
|
8
|
+
*
|
|
9
|
+
* Account rows themselves are not filtered here: senders, routes and the
|
|
10
|
+
* outbox read them without a principal, and the content (emails, folders,
|
|
11
|
+
* attachments) is what an account grant protects.
|
|
12
|
+
*
|
|
13
|
+
* @packageDocumentation
|
|
14
|
+
*/
|
|
15
|
+
import { type CollectionInterceptor } from '@happyvertical/smrt-core';
|
|
16
|
+
export declare const MAIL_ACCESS_INTERCEPTOR_NAME = "smrt-messages-account-access";
|
|
17
|
+
export declare function createMailAccessInterceptor(): CollectionInterceptor;
|
|
18
|
+
/** Idempotent; called at package load. */
|
|
19
|
+
export declare function ensureMailAccessEnforcementRegistered(): void;
|
|
20
|
+
//# sourceMappingURL=access-enforcement.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"access-enforcement.d.ts","sourceRoot":"","sources":["../src/access-enforcement.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EACL,KAAK,qBAAqB,EAQ3B,MAAM,0BAA0B,CAAC;AA8FlC,eAAO,MAAM,4BAA4B,iCAAiC,CAAC;AAE3E,wBAAgB,2BAA2B,IAAI,qBAAqB,CAyHnE;AAID,0CAA0C;AAC1C,wBAAgB,qCAAqC,IAAI,IAAI,CAI5D"}
|
package/dist/access.d.ts
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-account mail access: an optional owner plus grants (read, triage, draft,
|
|
3
|
+
* send) for people and host-mapped agent accounts, on smrt-users
|
|
4
|
+
* `ResourceGrant`.
|
|
5
|
+
*
|
|
6
|
+
* Optional by default: a mail account with no `ownerUserId` keeps today's
|
|
7
|
+
* tenant-wide behavior. An app that wants private or shared mailboxes sets an
|
|
8
|
+
* owner and calls {@link configureMailAccess} once at startup; from then on
|
|
9
|
+
* reads of an owned account's emails, folders and attachments are limited to
|
|
10
|
+
* the owner and read grantees (enforced in the collection layer by
|
|
11
|
+
* `access-enforcement.ts`, never by UI), and sending through an owned account
|
|
12
|
+
* needs the `send` scope.
|
|
13
|
+
*
|
|
14
|
+
* The acting principal comes from the host through `resolvePrincipal`, so
|
|
15
|
+
* smrt never knows the host's credential model (a session cookie, an agent
|
|
16
|
+
* bearer token). Fail closed: an owned account is invisible to a missing,
|
|
17
|
+
* foreign-tenant or ceiling-excluded principal. There is no tenant-admin or
|
|
18
|
+
* super-admin bypass on content; trusted server work (sync, outbox) opts in
|
|
19
|
+
* explicitly with {@link runWithMailSystemAccess}.
|
|
20
|
+
*
|
|
21
|
+
* Grants live in `ResourceGrant` (resource type {@link MAIL_ACCOUNT_RESOURCE_TYPE},
|
|
22
|
+
* permission `messages.<scope>`). smrt-users composes them after tenant RBAC:
|
|
23
|
+
* the grantee must also hold the tenant-level `messages.<scope>` permission,
|
|
24
|
+
* which acts as the tenant's ceiling; the exact grant then narrows it per
|
|
25
|
+
* account. The owner implicitly holds every scope on their own accounts and
|
|
26
|
+
* needs no grant.
|
|
27
|
+
*
|
|
28
|
+
* @packageDocumentation
|
|
29
|
+
*/
|
|
30
|
+
import type { SmrtClassOptions } from '@happyvertical/smrt-core';
|
|
31
|
+
import { MANAGE_MAIL_ACCESS_PERMISSION } from './permissions.js';
|
|
32
|
+
export declare const MAIL_SCOPES: readonly ["read", "triage", "draft", "send"];
|
|
33
|
+
export type MailScope = (typeof MAIL_SCOPES)[number];
|
|
34
|
+
/** `ResourceGrant.resourceType` for a mail account. */
|
|
35
|
+
export declare const MAIL_ACCOUNT_RESOURCE_TYPE = "messages:account";
|
|
36
|
+
/** The tenant permission slug that is the ceiling for a mail scope. */
|
|
37
|
+
export declare function mailScopePermission(scope: MailScope): string;
|
|
38
|
+
export declare function isMailScope(value: unknown): value is MailScope;
|
|
39
|
+
/** The acting principal, as the host knows it. */
|
|
40
|
+
export interface MailPrincipal {
|
|
41
|
+
/** Host identity recorded for audit (a user id, an agent credential id). */
|
|
42
|
+
id: string;
|
|
43
|
+
/** Tenant the principal authenticated into. Must equal the account's. */
|
|
44
|
+
tenantId: string;
|
|
45
|
+
/**
|
|
46
|
+
* The smrt-users `User` id that owns accounts and holds `ResourceGrant`
|
|
47
|
+
* rows. People are their own user; an agent account is a `User` row the host
|
|
48
|
+
* maps its credential to.
|
|
49
|
+
*/
|
|
50
|
+
userId: string;
|
|
51
|
+
/** `'person'`, `'agent'`, or any host label; informational. */
|
|
52
|
+
kind?: string;
|
|
53
|
+
/**
|
|
54
|
+
* Host ceiling on scopes (for example an agent credential's mail scopes).
|
|
55
|
+
* Intersected with the owner/grant decision; omit for no ceiling. An empty
|
|
56
|
+
* list grants nothing.
|
|
57
|
+
*/
|
|
58
|
+
scopes?: readonly MailScope[];
|
|
59
|
+
/**
|
|
60
|
+
* Host ceiling on account ids (for example `allowedMailAccountIds`).
|
|
61
|
+
* Intersected with the owner/grant decision; omit for no ceiling. An empty
|
|
62
|
+
* list grants nothing.
|
|
63
|
+
*/
|
|
64
|
+
accountIds?: readonly string[];
|
|
65
|
+
}
|
|
66
|
+
export interface MailAccessResolverContext {
|
|
67
|
+
tenantId: string | null;
|
|
68
|
+
}
|
|
69
|
+
/** Returns the acting principal for the current request or job, or null. */
|
|
70
|
+
export type MailAccessResolver = (context: MailAccessResolverContext) => MailPrincipal | null | undefined | Promise<MailPrincipal | null | undefined>;
|
|
71
|
+
export interface MailAccessConfig {
|
|
72
|
+
/** Database options used to read accounts and grants. Required. */
|
|
73
|
+
options: SmrtClassOptions;
|
|
74
|
+
/** The host's access-check hook. Without it every owned account is closed. */
|
|
75
|
+
resolvePrincipal?: MailAccessResolver;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Turn on mail access enforcement for this process. Call once at startup,
|
|
79
|
+
* after the database is available. Calling again replaces the configuration.
|
|
80
|
+
*/
|
|
81
|
+
export declare function configureMailAccess(config: MailAccessConfig): void;
|
|
82
|
+
/** Remove the configuration (tests). Owned accounts then fail closed. */
|
|
83
|
+
export declare function resetMailAccess(): void;
|
|
84
|
+
/**
|
|
85
|
+
* Remember the database a mail row was read with. Until the host calls
|
|
86
|
+
* {@link configureMailAccess}, this lets the policy still find owned accounts
|
|
87
|
+
* and hide their mail (no principal resolver means no one is a principal).
|
|
88
|
+
*/
|
|
89
|
+
/**
|
|
90
|
+
* The options with their list bounds removed. `create()` forwards
|
|
91
|
+
* `defaultListLimit`/`maxListLimit` from any options bag, and an access
|
|
92
|
+
* decision needs every account: a truncated read would leave owned accounts
|
|
93
|
+
* out of the denied set and leak their mail.
|
|
94
|
+
*/
|
|
95
|
+
export declare function withoutListBounds<T extends object>(options: T): T;
|
|
96
|
+
export declare function learnMailAccessOptions(options: SmrtClassOptions | undefined): void;
|
|
97
|
+
/** Every policy in force: the configured one, else one per learned database. */
|
|
98
|
+
export declare function getEffectiveMailAccessConfigs(): MailAccessConfig[];
|
|
99
|
+
/** The configured policy, else a closed one over the learned database. */
|
|
100
|
+
export declare function getEffectiveMailAccessConfig(): MailAccessConfig | null;
|
|
101
|
+
export declare function getMailAccessConfig(): MailAccessConfig | null;
|
|
102
|
+
/**
|
|
103
|
+
* Run trusted server work (mailbox sync, the notification outbox) with the
|
|
104
|
+
* per-account policy lifted. This is the only bypass; tenant-admin and
|
|
105
|
+
* super-admin contexts do not lift it.
|
|
106
|
+
*/
|
|
107
|
+
export declare function runWithMailSystemAccess<T>(fn: () => T): T;
|
|
108
|
+
export declare function inMailSystemAccess(): boolean;
|
|
109
|
+
/** The minimal account shape the policy reads. */
|
|
110
|
+
export interface MailAccessSubject {
|
|
111
|
+
id?: string | null;
|
|
112
|
+
tenantId?: string | null;
|
|
113
|
+
ownerUserId?: string | null;
|
|
114
|
+
}
|
|
115
|
+
export type MailAccessReason = 'unowned' | 'system' | 'owner' | 'grant' | 'not_configured' | 'no_principal' | 'tenant_mismatch' | 'ceiling' | 'denied';
|
|
116
|
+
export interface MailAccessDecision {
|
|
117
|
+
allowed: boolean;
|
|
118
|
+
reason: MailAccessReason;
|
|
119
|
+
}
|
|
120
|
+
/** Thrown by {@link assertMailAccess}; carries a 403-class status. */
|
|
121
|
+
export declare class MailAccessError extends Error {
|
|
122
|
+
readonly scope: MailScope;
|
|
123
|
+
readonly reason: MailAccessReason;
|
|
124
|
+
readonly status = 403;
|
|
125
|
+
constructor(scope: MailScope, reason: MailAccessReason);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Decide whether the current principal holds `scope` on `account`. Never
|
|
129
|
+
* throws for a denial; a lookup failure denies.
|
|
130
|
+
*/
|
|
131
|
+
export declare function decideMailAccess(account: MailAccessSubject, scope: MailScope, principalOverride?: MailPrincipal | null): Promise<MailAccessDecision>;
|
|
132
|
+
export declare function canAccessMailAccount(account: MailAccessSubject, scope: MailScope): Promise<boolean>;
|
|
133
|
+
export declare function assertMailAccess(account: MailAccessSubject, scope: MailScope): Promise<void>;
|
|
134
|
+
/**
|
|
135
|
+
* Ids of accounts in the current tenant context on which the current
|
|
136
|
+
* principal lacks `scope`. Empty when nothing is configured or the call runs
|
|
137
|
+
* in {@link runWithMailSystemAccess}.
|
|
138
|
+
*/
|
|
139
|
+
export declare function deniedMailAccountIds(scope: MailScope): Promise<string[]>;
|
|
140
|
+
/** Whether the current principal may read mail of `accountId` (empty: yes). */
|
|
141
|
+
export declare function accountReadable(accountId: string | null | undefined, options: SmrtClassOptions | undefined): Promise<boolean>;
|
|
142
|
+
/**
|
|
143
|
+
* Gate for direct hydration (`new Email({ id }).initialize()`,
|
|
144
|
+
* `loadRelated('messageId')`), which bypasses collection read hooks: throws
|
|
145
|
+
* when the loaded row belongs to an account closed to the principal.
|
|
146
|
+
*/
|
|
147
|
+
export declare function assertHydratedMailAccess(row: {
|
|
148
|
+
accountId?: string | null;
|
|
149
|
+
messageId?: string | null;
|
|
150
|
+
options?: unknown;
|
|
151
|
+
}): Promise<void>;
|
|
152
|
+
export interface MailAccessAdmin {
|
|
153
|
+
/** The acting user (`MailPrincipal.userId`). */
|
|
154
|
+
userId: string;
|
|
155
|
+
tenantId: string;
|
|
156
|
+
}
|
|
157
|
+
export interface GrantMailAccessInput {
|
|
158
|
+
accountId: string;
|
|
159
|
+
/** The grantee's smrt-users `User` id (a person, or a host-mapped agent). */
|
|
160
|
+
userId: string;
|
|
161
|
+
scope: MailScope;
|
|
162
|
+
effect?: 'grant' | 'deny';
|
|
163
|
+
canDelegate?: boolean;
|
|
164
|
+
/** For a delegated grant: the actor's own delegable grant. */
|
|
165
|
+
parentGrantId?: string | null;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Owner-controlled grant administration. Tenant RBAC (`messages.manage-access`)
|
|
169
|
+
* is necessary but never sufficient: the actor must also own the account, or
|
|
170
|
+
* delegate from their own delegable grant. A tenant administrator therefore
|
|
171
|
+
* cannot read, grant themselves, or take over someone else's mailbox.
|
|
172
|
+
*/
|
|
173
|
+
export declare class MailAccessService {
|
|
174
|
+
private readonly options;
|
|
175
|
+
private readonly actor;
|
|
176
|
+
constructor(options: SmrtClassOptions, actor: MailAccessAdmin);
|
|
177
|
+
private account;
|
|
178
|
+
/** Tenant RBAC ceiling for administering mail access (grants, owner). */
|
|
179
|
+
private assertManageAccess;
|
|
180
|
+
/** The new owner must be a real, active member of this tenant. */
|
|
181
|
+
private assertTenantMember;
|
|
182
|
+
private inTenant;
|
|
183
|
+
private resourceFor;
|
|
184
|
+
private grantsApi;
|
|
185
|
+
grant(input: GrantMailAccessInput): Promise<import("@happyvertical/smrt-users").ResourceGrant>;
|
|
186
|
+
revoke(grantId: string): Promise<void>;
|
|
187
|
+
list(accountId: string): Promise<import("@happyvertical/smrt-users").ResourceGrant[]>;
|
|
188
|
+
setOwner(accountId: string, ownerUserId: string): Promise<void>;
|
|
189
|
+
private grantImpl;
|
|
190
|
+
/** Revoke a grant. Delegated children stop working with their ancestor. */
|
|
191
|
+
private revokeImpl;
|
|
192
|
+
/** Owner-only listing of who holds what on one account. */
|
|
193
|
+
private listImpl;
|
|
194
|
+
/**
|
|
195
|
+
* Set or change the owner. An owned account changes hands only by its
|
|
196
|
+
* owner. An unowned account can be claimed by a tenant administrator
|
|
197
|
+
* holding `messages.manage-credentials` (the migration path from
|
|
198
|
+
* tenant-wide to owned).
|
|
199
|
+
*/
|
|
200
|
+
private setOwnerImpl;
|
|
201
|
+
}
|
|
202
|
+
export { MANAGE_MAIL_ACCESS_PERMISSION };
|
|
203
|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AAM,CAAC;IAClB,6EAA6E;IAC7E,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,SAAS,CAAC;IACjB,MAAM,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAC1B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,8DAA8D;IAC9D,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B;AAED;;;;;GAKG;AACH,qBAAa,iBAAiB;IAE1B,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,KAAK;gBADL,OAAO,EAAE,gBAAgB,EACzB,KAAK,EAAE,eAAe;YAG3B,OAAO;IAiBrB,yEAAyE;YAC3D,kBAAkB;IAgBhC,kEAAkE;YACpD,kBAAkB;YAYlB,QAAQ;IAKtB,OAAO,CAAC,WAAW;YAQL,SAAS;IAYvB,KAAK,CAAC,KAAK,EAAE,oBAAoB;IAIjC,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAItC,IAAI,CAAC,SAAS,EAAE,MAAM;IAItB,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;YAIjD,SAAS;IAwDvB,2EAA2E;YAC7D,UAAU;IA8BxB,2DAA2D;YAC7C,QAAQ;IAoBtB;;;;;OAKG;YACW,YAAY;CA8B3B;AAED,OAAO,EAAE,6BAA6B,EAAE,CAAC"}
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
|
|
2
|
+
import { C as runWithMailSystemAccess, d as assertHydratedMailAccess } from "./EmailAccountCollection-DtCuHcB4.js";
|
|
3
|
+
import { queryGlobal, queryWithGlobals } from "../host.js";
|
|
4
|
+
import { SmrtCollection, SmrtObject, foreignKey, importOptionalDependency, smrt } from "@happyvertical/smrt-core";
|
|
5
|
+
import { TenantScoped, tenantId } from "@happyvertical/smrt-tenancy/decorators";
|
|
6
|
+
//#region src/models/Attachment.ts
|
|
7
|
+
var __defProp = Object.defineProperty;
|
|
8
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
configurable: true,
|
|
12
|
+
writable: true,
|
|
13
|
+
value
|
|
14
|
+
}) : obj[key] = value;
|
|
15
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
16
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
17
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--) if (decorator = decorators[i]) result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
18
|
+
if (kind && result) __defProp(target, key, result);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
22
|
+
function splitAbsolutePath(filePath) {
|
|
23
|
+
const windows = /^[A-Za-z]:[\\/]/.test(filePath);
|
|
24
|
+
if (!windows && !filePath.startsWith("/")) return null;
|
|
25
|
+
const cut = windows ? Math.max(filePath.lastIndexOf("/"), filePath.lastIndexOf("\\")) : filePath.lastIndexOf("/");
|
|
26
|
+
return {
|
|
27
|
+
dir: filePath.slice(0, cut) || filePath.slice(0, cut + 1),
|
|
28
|
+
base: filePath.slice(cut + 1)
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
var Attachment = class extends SmrtObject {
|
|
32
|
+
tenantId = null;
|
|
33
|
+
messageId = "";
|
|
34
|
+
accountId = null;
|
|
35
|
+
filename = "";
|
|
36
|
+
contentType = "";
|
|
37
|
+
size = 0;
|
|
38
|
+
contentId = "";
|
|
39
|
+
contentDisposition = "attachment";
|
|
40
|
+
filePath = "";
|
|
41
|
+
sourceUrl = "";
|
|
42
|
+
createdAt = /* @__PURE__ */ new Date();
|
|
43
|
+
constructor(options = {}) {
|
|
44
|
+
super(options);
|
|
45
|
+
if (options.tenantId !== void 0) this.tenantId = options.tenantId;
|
|
46
|
+
if (options.messageId !== void 0) this.messageId = options.messageId;
|
|
47
|
+
if (options.accountId !== void 0) this.accountId = options.accountId || null;
|
|
48
|
+
if (options.filename !== void 0) this.filename = options.filename;
|
|
49
|
+
if (options.contentType !== void 0) this.contentType = options.contentType;
|
|
50
|
+
if (options.size !== void 0) this.size = options.size;
|
|
51
|
+
if (options.contentId !== void 0) this.contentId = options.contentId;
|
|
52
|
+
if (options.contentDisposition !== void 0) this.contentDisposition = options.contentDisposition;
|
|
53
|
+
if (options.filePath !== void 0) this.filePath = options.filePath;
|
|
54
|
+
if (options.sourceUrl !== void 0) this.sourceUrl = options.sourceUrl;
|
|
55
|
+
if (options.createdAt) this.createdAt = options.createdAt;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Direct hydration (`new X({ id }).initialize()`, `loadRelated()`) bypasses
|
|
59
|
+
* the collection read hooks, so the per-account mail policy is applied here
|
|
60
|
+
* too: a row of an account closed to the principal never hydrates.
|
|
61
|
+
*/
|
|
62
|
+
async loadFromId() {
|
|
63
|
+
await super.loadFromId();
|
|
64
|
+
await assertHydratedMailAccess(this);
|
|
65
|
+
}
|
|
66
|
+
async loadFromSlug() {
|
|
67
|
+
await super.loadFromSlug();
|
|
68
|
+
await assertHydratedMailAccess(this);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Get the message this attachment belongs to
|
|
72
|
+
*/
|
|
73
|
+
async getMessage() {
|
|
74
|
+
if (!this.messageId) return null;
|
|
75
|
+
const { MessageCollection } = await import("./MessageCollection-CT0O_7wG.js").then((n) => n.n);
|
|
76
|
+
return await (await MessageCollection.create(this.options)).get({ id: this.messageId });
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Check if attachment is an image
|
|
80
|
+
*/
|
|
81
|
+
isImage() {
|
|
82
|
+
return this.contentType.startsWith("image/");
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Check if attachment is a PDF
|
|
86
|
+
*/
|
|
87
|
+
isPdf() {
|
|
88
|
+
return this.contentType === "application/pdf";
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Check if attachment is inline (embedded in message body)
|
|
92
|
+
*/
|
|
93
|
+
isInline() {
|
|
94
|
+
return this.contentDisposition === "inline";
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Get file extension from filename
|
|
98
|
+
*/
|
|
99
|
+
getExtension() {
|
|
100
|
+
if (!this.filename) return "";
|
|
101
|
+
const parts = this.filename.split(".");
|
|
102
|
+
return parts.length > 1 ? parts[parts.length - 1].toLowerCase() : "";
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Get human-readable file size
|
|
106
|
+
*/
|
|
107
|
+
getFormattedSize() {
|
|
108
|
+
const units = [
|
|
109
|
+
"B",
|
|
110
|
+
"KB",
|
|
111
|
+
"MB",
|
|
112
|
+
"GB"
|
|
113
|
+
];
|
|
114
|
+
let size = this.size;
|
|
115
|
+
let unitIndex = 0;
|
|
116
|
+
while (size >= 1024 && unitIndex < units.length - 1) {
|
|
117
|
+
size /= 1024;
|
|
118
|
+
unitIndex++;
|
|
119
|
+
}
|
|
120
|
+
return `${size.toFixed(1)} ${units[unitIndex]}`;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Check if file is stored externally
|
|
124
|
+
*/
|
|
125
|
+
hasExternalFile() {
|
|
126
|
+
return !!this.filePath;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Read file content (if stored externally)
|
|
130
|
+
*
|
|
131
|
+
* The files SDK is loaded through core's bundler-invisible optional-import
|
|
132
|
+
* boundary so it never enters provider-neutral consumer bundles (#1979).
|
|
133
|
+
* Absence of the SDK at runtime degrades to the existing null contract.
|
|
134
|
+
*
|
|
135
|
+
* The local provider joins every path onto its base path (the process cwd
|
|
136
|
+
* by default), so an absolute `filePath` is rooted at its own directory, and
|
|
137
|
+
* the bytes are read raw: decoding a PDF as UTF-8 corrupts it (#3808).
|
|
138
|
+
*/
|
|
139
|
+
async readContent() {
|
|
140
|
+
if (!this.filePath) return null;
|
|
141
|
+
try {
|
|
142
|
+
const { getFilesystem, initializeProviders } = await importOptionalDependency("@happyvertical/files", "Import '@happyvertical/smrt-core/filesystem' (or '@happyvertical/smrt-assets/filesystem') during server startup to read externally-stored attachments in bundled builds.");
|
|
143
|
+
await initializeProviders?.();
|
|
144
|
+
const split = splitAbsolutePath(this.filePath);
|
|
145
|
+
const data = await (await getFilesystem(split ? {
|
|
146
|
+
type: "local",
|
|
147
|
+
basePath: split.dir
|
|
148
|
+
} : { type: "local" })).read(split ? split.base : this.filePath, { raw: true });
|
|
149
|
+
return data instanceof Buffer ? data : Buffer.from(data);
|
|
150
|
+
} catch {
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
__publicField(Attachment, "__smrtPackage__", "@happyvertical/smrt-messages");
|
|
156
|
+
__decorateClass([tenantId({ nullable: true })], Attachment.prototype, "tenantId", 2);
|
|
157
|
+
__decorateClass([foreignKey("Message")], Attachment.prototype, "messageId", 2);
|
|
158
|
+
__decorateClass([foreignKey("Account")], Attachment.prototype, "accountId", 2);
|
|
159
|
+
Attachment = __decorateClass([TenantScoped({ mode: "optional" }), smrt({
|
|
160
|
+
api: { include: [
|
|
161
|
+
"list",
|
|
162
|
+
"get",
|
|
163
|
+
"create",
|
|
164
|
+
"delete"
|
|
165
|
+
] },
|
|
166
|
+
mcp: { include: ["list", "get"] },
|
|
167
|
+
cli: { skipApiCheck: true }
|
|
168
|
+
})], Attachment);
|
|
169
|
+
//#endregion
|
|
170
|
+
//#region src/collections/AttachmentCollection.ts
|
|
171
|
+
var AttachmentCollection_exports = /* @__PURE__ */ __exportAll({ AttachmentCollection: () => AttachmentCollection });
|
|
172
|
+
var AttachmentCollection = class extends SmrtCollection {
|
|
173
|
+
static _itemClass = Attachment;
|
|
174
|
+
/**
|
|
175
|
+
* Fill `accountId` on attachments saved before the column existed, from
|
|
176
|
+
* their message. Run once per tenant after upgrading; safe to repeat.
|
|
177
|
+
* Returns the number of rows updated.
|
|
178
|
+
*/
|
|
179
|
+
async backfillAccountIds() {
|
|
180
|
+
return runWithMailSystemAccess(async () => {
|
|
181
|
+
const { MessageCollection } = await import("./MessageCollection-CT0O_7wG.js").then((n) => n.n);
|
|
182
|
+
const messages = await MessageCollection.create(this.options);
|
|
183
|
+
let updated = 0;
|
|
184
|
+
for (const attachment of await this.list({ where: { accountId: null } })) {
|
|
185
|
+
if (!attachment.messageId) continue;
|
|
186
|
+
const message = await messages.get({ id: attachment.messageId });
|
|
187
|
+
if (!message?.accountId) continue;
|
|
188
|
+
attachment.accountId = message.accountId;
|
|
189
|
+
await attachment.save();
|
|
190
|
+
updated++;
|
|
191
|
+
}
|
|
192
|
+
return updated;
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Get attachments for a message
|
|
197
|
+
*/
|
|
198
|
+
async getByMessage(messageId) {
|
|
199
|
+
return await this.list({ where: { messageId } });
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Get attachments by content type
|
|
203
|
+
*/
|
|
204
|
+
async getByContentType(contentType) {
|
|
205
|
+
return await this.list({ where: { contentType } });
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Get image attachments
|
|
209
|
+
*/
|
|
210
|
+
async getImages(messageId) {
|
|
211
|
+
return (messageId ? await this.getByMessage(messageId) : await this.list({})).filter((a) => a.isImage());
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Get PDF attachments
|
|
215
|
+
*/
|
|
216
|
+
async getPdfs(messageId) {
|
|
217
|
+
return (messageId ? await this.getByMessage(messageId) : await this.list({})).filter((a) => a.isPdf());
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Get inline attachments (embedded in message body)
|
|
221
|
+
*/
|
|
222
|
+
async getInline(messageId) {
|
|
223
|
+
return (await this.getByMessage(messageId)).filter((a) => a.isInline());
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Get regular attachments (not inline)
|
|
227
|
+
*/
|
|
228
|
+
async getRegular(messageId) {
|
|
229
|
+
return (await this.getByMessage(messageId)).filter((a) => !a.isInline());
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Get attachments with external files
|
|
233
|
+
*/
|
|
234
|
+
async getWithExternalFiles() {
|
|
235
|
+
return (await this.list({})).filter((a) => a.hasExternalFile());
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Get total size of attachments for a message
|
|
239
|
+
*/
|
|
240
|
+
async getTotalSize(messageId) {
|
|
241
|
+
return (await this.getByMessage(messageId)).reduce((sum, a) => sum + a.size, 0);
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Get largest attachments
|
|
245
|
+
*/
|
|
246
|
+
async getLargest(limit = 10) {
|
|
247
|
+
return (await this.list({})).sort((a, b) => b.size - a.size).slice(0, limit);
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Search attachments by filename
|
|
251
|
+
*/
|
|
252
|
+
async searchByFilename(query) {
|
|
253
|
+
const attachments = await this.list({});
|
|
254
|
+
const lowerQuery = query.toLowerCase();
|
|
255
|
+
return attachments.filter((a) => a.filename?.toLowerCase().includes(lowerQuery));
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Get attachments by extension
|
|
259
|
+
*/
|
|
260
|
+
async getByExtension(extension) {
|
|
261
|
+
const attachments = await this.list({});
|
|
262
|
+
const lowerExt = extension.toLowerCase().replace(/^\./, "");
|
|
263
|
+
return attachments.filter((a) => a.getExtension() === lowerExt);
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Get attachment statistics
|
|
267
|
+
*/
|
|
268
|
+
async getStats() {
|
|
269
|
+
const attachments = await this.list({});
|
|
270
|
+
const byType = {};
|
|
271
|
+
for (const attachment of attachments) {
|
|
272
|
+
const type = attachment.contentType.split("/")[0] || "other";
|
|
273
|
+
byType[type] = (byType[type] || 0) + 1;
|
|
274
|
+
}
|
|
275
|
+
return {
|
|
276
|
+
total: attachments.length,
|
|
277
|
+
totalSize: attachments.reduce((sum, a) => sum + a.size, 0),
|
|
278
|
+
byType,
|
|
279
|
+
inline: attachments.filter((a) => a.isInline()).length,
|
|
280
|
+
regular: attachments.filter((a) => !a.isInline()).length
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Delete all attachments for a message
|
|
285
|
+
*/
|
|
286
|
+
async deleteByMessage(messageId) {
|
|
287
|
+
const attachments = await this.getByMessage(messageId);
|
|
288
|
+
let count = 0;
|
|
289
|
+
for (const attachment of attachments) {
|
|
290
|
+
await attachment.delete();
|
|
291
|
+
count++;
|
|
292
|
+
}
|
|
293
|
+
return count;
|
|
294
|
+
}
|
|
295
|
+
async findByTenant(tenantId) {
|
|
296
|
+
return this.list({ where: { tenantId } });
|
|
297
|
+
}
|
|
298
|
+
async findGlobal() {
|
|
299
|
+
return queryGlobal(this);
|
|
300
|
+
}
|
|
301
|
+
async findWithGlobals(tenantId) {
|
|
302
|
+
return queryWithGlobals(this, tenantId, "Attachment.findWithGlobals");
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
//#endregion
|
|
306
|
+
export { AttachmentCollection_exports as n, Attachment as r, AttachmentCollection as t };
|
|
307
|
+
|
|
308
|
+
//# sourceMappingURL=AttachmentCollection-nTqD75n8.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AttachmentCollection-nTqD75n8.js","names":[],"sources":["../../src/models/Attachment.ts","../../src/collections/AttachmentCollection.ts"],"sourcesContent":["/**\n * Attachment model - Generalized attachment for any message type\n *\n * Uses messageId instead of emailId for cross-type support.\n */\n\n// Register the package manifest before this module's @smrt() decorator\n// runs, whichever chunk the library build places it in (#3098).\nimport '../__smrt-register__.js';\nimport {\n foreignKey,\n importOptionalDependency,\n SmrtObject,\n smrt,\n} from '@happyvertical/smrt-core';\nimport { TenantScoped, tenantId } from '@happyvertical/smrt-tenancy/decorators';\nimport { assertHydratedMailAccess } from '../access.js';\nimport type { AttachmentOptions } from '../types';\n\n/**\n * Split an absolute path into its directory and file name, or return null for\n * a relative path. Plain string handling rather than `node:path`: the package\n * root must stay browser-reachable (the bundle-gate forbids `node:*` there).\n */\nfunction splitAbsolutePath(\n filePath: string,\n): { dir: string; base: string } | null {\n // A backslash separates segments only in a Windows path; in a POSIX path it\n // is an ordinary filename character.\n const windows = /^[A-Za-z]:[\\\\/]/.test(filePath);\n if (!windows && !filePath.startsWith('/')) return null;\n const cut = windows\n ? Math.max(filePath.lastIndexOf('/'), filePath.lastIndexOf('\\\\'))\n : filePath.lastIndexOf('/');\n const dir = filePath.slice(0, cut) || filePath.slice(0, cut + 1);\n return { dir, base: filePath.slice(cut + 1) };\n}\n\n@TenantScoped({ mode: 'optional' })\n@smrt({\n api: { include: ['list', 'get', 'create', 'delete'] },\n mcp: { include: ['list', 'get'] },\n cli: { skipApiCheck: true },\n})\nexport class Attachment extends SmrtObject { static __smrtPackage__ = \"@happyvertical/smrt-messages\";\n @tenantId({ nullable: true })\n tenantId: string | null = null;\n\n @foreignKey('Message')\n messageId = '';\n /**\n * The mail account this file belongs to. Copied from its message when the\n * attachment is saved, so per-account mail access can filter attachment\n * reads (lists, projections, counts) without a join. Null for rows saved\n * before the column existed: run `AttachmentCollection.backfillAccountIds()`.\n */\n @foreignKey('Account')\n accountId: string | null = null;\n filename = '';\n contentType = '';\n size = 0;\n contentId = ''; // For inline images (<img src=\"cid:...\">)\n contentDisposition: 'attachment' | 'inline' = 'attachment';\n filePath = ''; // External file storage path\n sourceUrl = ''; // For non-email attachments (media URLs, etc.)\n\n // Timestamps\n createdAt = new Date();\n\n constructor(options: AttachmentOptions = {}) {\n super(options);\n\n if (options.tenantId !== undefined) this.tenantId = options.tenantId;\n if (options.messageId !== undefined) this.messageId = options.messageId;\n if (options.accountId !== undefined)\n this.accountId = options.accountId || null;\n if (options.filename !== undefined) this.filename = options.filename;\n if (options.contentType !== undefined)\n this.contentType = options.contentType;\n if (options.size !== undefined) this.size = options.size;\n if (options.contentId !== undefined) this.contentId = options.contentId;\n if (options.contentDisposition !== undefined)\n this.contentDisposition = options.contentDisposition;\n if (options.filePath !== undefined) this.filePath = options.filePath;\n if (options.sourceUrl !== undefined) this.sourceUrl = options.sourceUrl;\n if (options.createdAt) this.createdAt = options.createdAt;\n }\n\n /**\n * Direct hydration (`new X({ id }).initialize()`, `loadRelated()`) bypasses\n * the collection read hooks, so the per-account mail policy is applied here\n * too: a row of an account closed to the principal never hydrates.\n */\n override async loadFromId() {\n await super.loadFromId();\n await assertHydratedMailAccess(this);\n }\n\n override async loadFromSlug() {\n await super.loadFromSlug();\n await assertHydratedMailAccess(this);\n }\n\n /**\n * Get the message this attachment belongs to\n */\n async getMessage() {\n if (!this.messageId) return null;\n\n const { MessageCollection } = await import(\n '../collections/MessageCollection'\n );\n const collection = await MessageCollection.create(this.options);\n\n return await collection.get({ id: this.messageId });\n }\n\n /**\n * Check if attachment is an image\n */\n isImage(): boolean {\n return this.contentType.startsWith('image/');\n }\n\n /**\n * Check if attachment is a PDF\n */\n isPdf(): boolean {\n return this.contentType === 'application/pdf';\n }\n\n /**\n * Check if attachment is inline (embedded in message body)\n */\n isInline(): boolean {\n return this.contentDisposition === 'inline';\n }\n\n /**\n * Get file extension from filename\n */\n getExtension(): string {\n if (!this.filename) return '';\n const parts = this.filename.split('.');\n return parts.length > 1 ? parts[parts.length - 1].toLowerCase() : '';\n }\n\n /**\n * Get human-readable file size\n */\n getFormattedSize(): string {\n const units = ['B', 'KB', 'MB', 'GB'];\n let size = this.size;\n let unitIndex = 0;\n\n while (size >= 1024 && unitIndex < units.length - 1) {\n size /= 1024;\n unitIndex++;\n }\n\n return `${size.toFixed(1)} ${units[unitIndex]}`;\n }\n\n /**\n * Check if file is stored externally\n */\n hasExternalFile(): boolean {\n return !!this.filePath;\n }\n\n /**\n * Read file content (if stored externally)\n *\n * The files SDK is loaded through core's bundler-invisible optional-import\n * boundary so it never enters provider-neutral consumer bundles (#1979).\n * Absence of the SDK at runtime degrades to the existing null contract.\n *\n * The local provider joins every path onto its base path (the process cwd\n * by default), so an absolute `filePath` is rooted at its own directory, and\n * the bytes are read raw: decoding a PDF as UTF-8 corrupts it (#3808).\n */\n async readContent(): Promise<Buffer | null> {\n if (!this.filePath) return null;\n\n try {\n const { getFilesystem, initializeProviders } =\n (await importOptionalDependency(\n '@happyvertical/files',\n \"Import '@happyvertical/smrt-core/filesystem' (or '@happyvertical/smrt-assets/filesystem') during server startup to read externally-stored attachments in bundled builds.\",\n )) as typeof import('@happyvertical/files');\n // The SDK registers its providers asynchronously on import; make the\n // local one available before asking for it.\n await initializeProviders?.();\n const split = splitAbsolutePath(this.filePath);\n const files = await getFilesystem(\n split ? { type: 'local', basePath: split.dir } : { type: 'local' },\n );\n const data = await files.read(split ? split.base : this.filePath, {\n raw: true,\n });\n return data instanceof Buffer ? data : Buffer.from(data);\n } catch {\n return null;\n }\n }\n}\n","/**\n * AttachmentCollection - Generalized attachment collection using messageId\n */\n\nimport { SmrtCollection } from '@happyvertical/smrt-core';\nimport { runWithMailSystemAccess } from '../access.js';\nimport { queryGlobal, queryWithGlobals } from '../host.js';\nimport { Attachment } from '../models/Attachment';\n\nexport class AttachmentCollection extends SmrtCollection<Attachment> {\n static readonly _itemClass = Attachment;\n\n /**\n * Fill `accountId` on attachments saved before the column existed, from\n * their message. Run once per tenant after upgrading; safe to repeat.\n * Returns the number of rows updated.\n */\n async backfillAccountIds(): Promise<number> {\n return runWithMailSystemAccess(async () => {\n const { MessageCollection } = await import('./MessageCollection');\n const messages = await MessageCollection.create(this.options);\n let updated = 0;\n for (const attachment of await this.list({\n where: { accountId: null },\n })) {\n if (!attachment.messageId) continue;\n const message = await messages.get({ id: attachment.messageId });\n if (!message?.accountId) continue;\n attachment.accountId = message.accountId;\n await attachment.save();\n updated++;\n }\n return updated;\n });\n }\n\n /**\n * Get attachments for a message\n */\n async getByMessage(messageId: string): Promise<Attachment[]> {\n return await this.list({ where: { messageId } });\n }\n\n /**\n * Get attachments by content type\n */\n async getByContentType(contentType: string): Promise<Attachment[]> {\n return await this.list({ where: { contentType } });\n }\n\n /**\n * Get image attachments\n */\n async getImages(messageId?: string): Promise<Attachment[]> {\n const attachments = messageId\n ? await this.getByMessage(messageId)\n : await this.list({});\n\n return attachments.filter((a) => a.isImage());\n }\n\n /**\n * Get PDF attachments\n */\n async getPdfs(messageId?: string): Promise<Attachment[]> {\n const attachments = messageId\n ? await this.getByMessage(messageId)\n : await this.list({});\n\n return attachments.filter((a) => a.isPdf());\n }\n\n /**\n * Get inline attachments (embedded in message body)\n */\n async getInline(messageId: string): Promise<Attachment[]> {\n const attachments = await this.getByMessage(messageId);\n return attachments.filter((a) => a.isInline());\n }\n\n /**\n * Get regular attachments (not inline)\n */\n async getRegular(messageId: string): Promise<Attachment[]> {\n const attachments = await this.getByMessage(messageId);\n return attachments.filter((a) => !a.isInline());\n }\n\n /**\n * Get attachments with external files\n */\n async getWithExternalFiles(): Promise<Attachment[]> {\n const attachments = await this.list({});\n return attachments.filter((a) => a.hasExternalFile());\n }\n\n /**\n * Get total size of attachments for a message\n */\n async getTotalSize(messageId: string): Promise<number> {\n const attachments = await this.getByMessage(messageId);\n return attachments.reduce((sum, a) => sum + a.size, 0);\n }\n\n /**\n * Get largest attachments\n */\n async getLargest(limit = 10): Promise<Attachment[]> {\n const attachments = await this.list({});\n return attachments.sort((a, b) => b.size - a.size).slice(0, limit);\n }\n\n /**\n * Search attachments by filename\n */\n async searchByFilename(query: string): Promise<Attachment[]> {\n const attachments = await this.list({});\n const lowerQuery = query.toLowerCase();\n\n return attachments.filter((a) =>\n a.filename?.toLowerCase().includes(lowerQuery),\n );\n }\n\n /**\n * Get attachments by extension\n */\n async getByExtension(extension: string): Promise<Attachment[]> {\n const attachments = await this.list({});\n const lowerExt = extension.toLowerCase().replace(/^\\./, '');\n\n return attachments.filter((a) => a.getExtension() === lowerExt);\n }\n\n /**\n * Get attachment statistics\n */\n async getStats(): Promise<{\n total: number;\n totalSize: number;\n byType: Record<string, number>;\n inline: number;\n regular: number;\n }> {\n const attachments = await this.list({});\n\n const byType: Record<string, number> = {};\n for (const attachment of attachments) {\n const type = attachment.contentType.split('/')[0] || 'other';\n byType[type] = (byType[type] || 0) + 1;\n }\n\n return {\n total: attachments.length,\n totalSize: attachments.reduce((sum, a) => sum + a.size, 0),\n byType,\n inline: attachments.filter((a) => a.isInline()).length,\n regular: attachments.filter((a) => !a.isInline()).length,\n };\n }\n\n /**\n * Delete all attachments for a message\n */\n async deleteByMessage(messageId: string): Promise<number> {\n const attachments = await this.getByMessage(messageId);\n let count = 0;\n\n for (const attachment of attachments) {\n await attachment.delete();\n count++;\n }\n\n return count;\n }\n\n // ─────────────────────────────────────────────────────────────────────────\n // Tenant Helper Methods\n // ─────────────────────────────────────────────────────────────────────────\n\n async findByTenant(tenantId: string): Promise<Attachment[]> {\n return this.list({ where: { tenantId } });\n }\n\n // Attachment is @TenantScoped (CTI, own `attachments` table). Under an active\n // tenant context list({ tenantId: null }) throws and unflagged raw SQL is\n // blocked (#1596); route through the raw helpers.\n async findGlobal(): Promise<Attachment[]> {\n return queryGlobal<Attachment>(this);\n }\n\n async findWithGlobals(tenantId: string): Promise<Attachment[]> {\n return queryWithGlobals<Attachment>(\n this,\n tenantId,\n 'Attachment.findWithGlobals',\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAwBA,SAAS,kBACP,UACsC;CAGtC,MAAM,UAAU,kBAAkB,KAAK,QAAQ;CAC/C,IAAI,CAAC,WAAW,CAAC,SAAS,WAAW,GAAG,GAAG,OAAO;CAClD,MAAM,MAAM,UACR,KAAK,IAAI,SAAS,YAAY,GAAG,GAAG,SAAS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