@happyvertical/smrt-messages 0.62.13 → 0.62.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/AGENTS.md +7 -1
  2. package/agents/send-approval.md +101 -0
  3. package/dist/access.d.ts +33 -1
  4. package/dist/access.d.ts.map +1 -1
  5. package/dist/chunks/{AttachmentCollection-Dzz2iKjx.js → AttachmentCollection-C0K7lITr.js} +4 -4
  6. package/dist/chunks/{AttachmentCollection-Dzz2iKjx.js.map → AttachmentCollection-C0K7lITr.js.map} +1 -1
  7. package/dist/chunks/{Email-DDMgkm_l.js → Email-DWF2VG_4.js} +6 -6
  8. package/dist/chunks/{Email-DDMgkm_l.js.map → Email-DWF2VG_4.js.map} +1 -1
  9. package/dist/chunks/EmailAccountCollection-OLTzu2T0.js +2472 -0
  10. package/dist/chunks/EmailAccountCollection-OLTzu2T0.js.map +1 -0
  11. package/dist/chunks/{EmailCollection-lo8WePl-.js → EmailCollection-8HeBXd0F.js} +3 -3
  12. package/dist/chunks/{EmailCollection-lo8WePl-.js.map → EmailCollection-8HeBXd0F.js.map} +1 -1
  13. package/dist/chunks/{EmailFolder-Bu7y8-VX.js → EmailFolder-Cl4sKRMB.js} +6 -6
  14. package/dist/chunks/{EmailFolder-Bu7y8-VX.js.map → EmailFolder-Cl4sKRMB.js.map} +1 -1
  15. package/dist/chunks/{EmailFolderCollection-BpzzKBhM.js → EmailFolderCollection-L0na2e1L.js} +2 -2
  16. package/dist/chunks/{EmailFolderCollection-BpzzKBhM.js.map → EmailFolderCollection-L0na2e1L.js.map} +1 -1
  17. package/dist/chunks/{EmailSender-B-Rtq9du.js → EmailSender-BiAI0LWU.js} +8 -1
  18. package/dist/chunks/EmailSender-BiAI0LWU.js.map +1 -0
  19. package/dist/chunks/{Message-BwW51pgG.js → Message-CuvACyOv.js} +76 -9
  20. package/dist/chunks/Message-CuvACyOv.js.map +1 -0
  21. package/dist/chunks/{MessageCollection-JjZybSMu.js → MessageCollection-DOErodD3.js} +2 -2
  22. package/dist/chunks/{MessageCollection-JjZybSMu.js.map → MessageCollection-DOErodD3.js.map} +1 -1
  23. package/dist/chunks/{MessagingEndpointCollection-FmbtiFJy.js → MessagingEndpointCollection-CE3kQKQU.js} +2 -2
  24. package/dist/chunks/{MessagingEndpointCollection-FmbtiFJy.js.map → MessagingEndpointCollection-CE3kQKQU.js.map} +1 -1
  25. package/dist/connect.js +1 -1
  26. package/dist/index.d.ts +4 -2
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +110 -14
  29. package/dist/index.js.map +1 -1
  30. package/dist/mail-drafts.d.ts +63 -0
  31. package/dist/mail-drafts.d.ts.map +1 -0
  32. package/dist/mail-triage.d.ts.map +1 -1
  33. package/dist/manifest.json +354 -30
  34. package/dist/models/EmailAccount.d.ts +8 -1
  35. package/dist/models/EmailAccount.d.ts.map +1 -1
  36. package/dist/models/Message.d.ts +9 -0
  37. package/dist/models/Message.d.ts.map +1 -1
  38. package/dist/send-approval.d.ts +275 -0
  39. package/dist/send-approval.d.ts.map +1 -0
  40. package/dist/senders/EmailSender.d.ts.map +1 -1
  41. package/dist/smrt-knowledge.json +213 -5
  42. package/dist/smrt-knowledge.okf.md +7 -2
  43. package/dist/types.d.ts +20 -0
  44. package/dist/types.d.ts.map +1 -1
  45. package/package.json +12 -11
  46. package/dist/chunks/EmailAccountCollection-CgZE9YAM.js +0 -1992
  47. package/dist/chunks/EmailAccountCollection-CgZE9YAM.js.map +0 -1
  48. package/dist/chunks/EmailSender-B-Rtq9du.js.map +0 -1
  49. package/dist/chunks/Message-BwW51pgG.js.map +0 -1
@@ -1,6 +1,6 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
2
2
  import { queryGlobal, queryWithGlobals } from "../host.js";
3
- import { t as Message } from "./Message-BwW51pgG.js";
3
+ import { t as Message } from "./Message-CuvACyOv.js";
4
4
  import { SmrtCollection } from "@happyvertical/smrt-core";
5
5
  //#region src/collections/MessageCollection.ts
6
6
  var MessageCollection_exports = /* @__PURE__ */ __exportAll({ MessageCollection: () => MessageCollection });
@@ -166,4 +166,4 @@ var MessageCollection = class extends SmrtCollection {
166
166
  //#endregion
167
167
  export { MessageCollection_exports as n, MessageCollection as t };
168
168
 
169
- //# sourceMappingURL=MessageCollection-JjZybSMu.js.map
169
+ //# sourceMappingURL=MessageCollection-DOErodD3.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"MessageCollection-JjZybSMu.js","names":[],"sources":["../../src/collections/MessageCollection.ts"],"sourcesContent":["/**\n * MessageCollection - Unified collection for polymorphic message queries\n *\n * Queries the messages table with STI, returning correct subclass instances.\n */\n\nimport { SmrtCollection } from '@happyvertical/smrt-core';\nimport { queryGlobal, queryWithGlobals } from '../host.js';\nimport { Message } from '../models/Message';\nimport type { MessageSearchFilters } from '../types';\n\nexport class MessageCollection extends SmrtCollection<Message> {\n static readonly _itemClass = Message;\n\n /**\n * Search messages with filters\n */\n async search(\n query: string,\n filters?: MessageSearchFilters,\n ): Promise<Message[]> {\n let messages = await this.list({});\n\n // Filter by query\n if (query) {\n const lowerQuery = query.toLowerCase();\n messages = messages.filter(\n (m) =>\n m.subject?.toLowerCase().includes(lowerQuery) ||\n m.body?.toLowerCase().includes(lowerQuery) ||\n m.fromAddress?.toLowerCase().includes(lowerQuery) ||\n m.fromName?.toLowerCase().includes(lowerQuery),\n );\n }\n\n // Apply filters\n if (filters) {\n if (filters.accountIds && filters.accountIds.length > 0) {\n messages = messages.filter((m) =>\n filters.accountIds?.includes(m.accountId),\n );\n }\n if (filters.messageType) {\n messages = messages.filter((m) => {\n const metaType = (m as { _meta_type?: string })._meta_type || '';\n return metaType.includes(filters.messageType as string);\n });\n }\n if (filters.from) {\n const fromLower = filters.from.toLowerCase();\n messages = messages.filter(\n (m) =>\n m.fromAddress?.toLowerCase().includes(fromLower) ||\n m.fromName?.toLowerCase().includes(fromLower),\n );\n }\n if (filters.to) {\n const toLower = filters.to.toLowerCase();\n messages = messages.filter((m) =>\n m.toAddresses?.toLowerCase().includes(toLower),\n );\n }\n if (filters.isRead !== undefined) {\n messages = messages.filter((m) => m.isRead === filters.isRead);\n }\n if (filters.isFlagged !== undefined) {\n messages = messages.filter((m) => m.isFlagged === filters.isFlagged);\n }\n if (filters.sinceDate) {\n messages = messages.filter(\n (m) => m.date && m.date >= (filters.sinceDate as Date),\n );\n }\n if (filters.beforeDate) {\n messages = messages.filter(\n (m) => m.date && m.date < (filters.beforeDate as Date),\n );\n }\n if (filters.query) {\n const q = filters.query.toLowerCase();\n messages = messages.filter(\n (m) =>\n m.subject?.toLowerCase().includes(q) ||\n m.body?.toLowerCase().includes(q),\n );\n }\n }\n\n return messages;\n }\n\n /**\n * Get messages by multiple accounts\n */\n async getByAccounts(accountIds: string[]): Promise<Message[]> {\n const allMessages = await this.list({});\n return allMessages.filter((m) => accountIds.includes(m.accountId));\n }\n\n /**\n * Get messages by STI type.\n *\n * Accepts either the full discriminator (e.g. \"@happyvertical/smrt-messages:Email\")\n * or the short type name (e.g. \"Email\").\n */\n async getByType(messageType: string): Promise<Message[]> {\n if (messageType.includes(':') || messageType.startsWith('@')) {\n return await this.list({ where: { _meta_type: messageType } });\n }\n const allMessages = await this.list({});\n return allMessages.filter((m) => {\n const metaType = (m as { _meta_type?: string })._meta_type || '';\n return metaType.endsWith(`:${messageType}`);\n });\n }\n\n /**\n * Get unread messages\n */\n async getUnread(accountId?: string): Promise<Message[]> {\n const where: Record<string, unknown> = { isRead: false };\n if (accountId) {\n where.accountId = accountId;\n }\n return await this.list({ where });\n }\n\n /**\n * Get flagged messages\n */\n async getFlagged(accountId?: string): Promise<Message[]> {\n const where: Record<string, unknown> = { isFlagged: true };\n if (accountId) {\n where.accountId = accountId;\n }\n return await this.list({ where });\n }\n\n /**\n * Get recent messages\n */\n async getRecent(limit = 20, accountId?: string): Promise<Message[]> {\n const allMessages = await this.list({\n where: accountId ? { accountId } : undefined,\n });\n\n return allMessages\n .sort((a, b) => {\n const dateA = a.date?.getTime() || 0;\n const dateB = b.date?.getTime() || 0;\n return dateB - dateA;\n })\n .slice(0, limit);\n }\n\n /**\n * Get messages by thread\n */\n async getByThread(threadId: string): Promise<Message[]> {\n return await this.list({ where: { threadId } });\n }\n\n /**\n * Mark multiple messages as read\n */\n async markAllRead(messageIds: string[]): Promise<void> {\n for (const id of messageIds) {\n const message = await this.get({ id });\n if (message) {\n await message.markRead();\n }\n }\n }\n\n /**\n * Get message statistics for an account\n */\n async getAccountStats(accountId: string): Promise<{\n total: number;\n unread: number;\n flagged: number;\n byType: Record<string, number>;\n }> {\n const messages = await this.list({ where: { accountId } });\n const byType: Record<string, number> = {};\n\n for (const msg of messages) {\n const metaType = (msg as { _meta_type?: string })._meta_type || 'Unknown';\n const shortType = metaType.split(':').pop() || metaType;\n byType[shortType] = (byType[shortType] || 0) + 1;\n }\n\n return {\n total: messages.length,\n unread: messages.filter((m) => !m.isRead).length,\n flagged: messages.filter((m) => m.isFlagged).length,\n byType,\n };\n }\n\n // ─────────────────────────────────────────────────────────────────────────\n // Send / Draft Queries\n // ─────────────────────────────────────────────────────────────────────────\n\n /**\n * Get draft messages\n */\n async getDrafts(accountId?: string): Promise<Message[]> {\n const where: Record<string, unknown> = { sendStatus: 'draft' };\n if (accountId) where.accountId = accountId;\n return await this.list({ where });\n }\n\n /**\n * Get sent messages\n */\n async getSent(accountId?: string): Promise<Message[]> {\n const where: Record<string, unknown> = { sendStatus: 'sent' };\n if (accountId) where.accountId = accountId;\n return await this.list({ where });\n }\n\n /**\n * Get scheduled messages\n */\n async getScheduled(accountId?: string): Promise<Message[]> {\n const where: Record<string, unknown> = { sendStatus: 'scheduled' };\n if (accountId) where.accountId = accountId;\n return await this.list({ where });\n }\n\n /**\n * Get messages that failed to send\n */\n async getFailedSends(accountId?: string): Promise<Message[]> {\n const where: Record<string, unknown> = { sendStatus: 'failed' };\n if (accountId) where.accountId = accountId;\n return await this.list({ where });\n }\n\n /**\n * Get outbox (pending + sending + scheduled)\n */\n async getOutbox(accountId?: string): Promise<Message[]> {\n const allMessages = await this.list({\n where: accountId ? { accountId } : undefined,\n });\n return allMessages.filter(\n (m) =>\n m.sendStatus === 'pending' ||\n m.sendStatus === 'sending' ||\n m.sendStatus === 'scheduled',\n );\n }\n\n // ─────────────────────────────────────────────────────────────────────────\n // Tenant Helper Methods\n // ─────────────────────────────────────────────────────────────────────────\n\n async findByTenant(tenantId: string): Promise<Message[]> {\n return this.list({ where: { tenantId } });\n }\n\n // Message is the @TenantScoped STI base, so an explicit `tenant_id IS NULL`\n // filter via list() throws and unflagged raw SQL is blocked under an active\n // tenant context (#1596). Route through the raw helpers — no `_meta_type`\n // scope so the base collection still returns ALL message subtypes.\n async findGlobal(): Promise<Message[]> {\n return queryGlobal<Message>(this);\n }\n\n async findWithGlobals(tenantId: string): Promise<Message[]> {\n return queryWithGlobals<Message>(this, tenantId, 'Message.findWithGlobals');\n }\n}\n"],"mappings":";;;;;;AAWO,IAAM,oBAAN,cAAgC,eAAwB;CAC7D,OAAgB,aAAa;;;;CAK7B,MAAM,OACJ,OACA,SACoB;EACpB,IAAI,WAAW,MAAM,KAAK,KAAK,CAAC,CAAC;EAGjC,IAAI,OAAO;GACT,MAAM,aAAa,MAAM,YAAY;GACrC,WAAW,SAAS,QACjB,MACC,EAAE,SAAS,YAAY,CAAA,CAAE,SAAS,UAAU,KAC5C,EAAE,MAAM,YAAY,CAAA,CAAE,SAAS,UAAU,KACzC,EAAE,aAAa,YAAY,CAAA,CAAE,SAAS,UAAU,KAChD,EAAE,UAAU,YAAY,CAAA,CAAE,SAAS,UAAU,CACjD;EACF;EAGA,IAAI,SAAS;GACX,IAAI,QAAQ,cAAc,QAAQ,WAAW,SAAS,GACpD,WAAW,SAAS,QAAQ,MAC1B,QAAQ,YAAY,SAAS,EAAE,SAAS,CAC1C;GAEF,IAAI,QAAQ,aACV,WAAW,SAAS,QAAQ,MAAM;IAEhC,QADkB,EAA8B,cAAc,GAAA,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AAM,UAAU,yBAAyB;CAC5E;AACF"}
1
+ {"version":3,"file":"MessageCollection-DOErodD3.js","names":[],"sources":["../../src/collections/MessageCollection.ts"],"sourcesContent":["/**\n * MessageCollection - Unified collection for polymorphic message queries\n *\n * Queries the messages table with STI, returning correct subclass instances.\n */\n\nimport { SmrtCollection } from '@happyvertical/smrt-core';\nimport { queryGlobal, queryWithGlobals } from '../host.js';\nimport { Message } from '../models/Message';\nimport type { MessageSearchFilters } from '../types';\n\nexport class MessageCollection extends SmrtCollection<Message> {\n static readonly _itemClass = Message;\n\n /**\n * Search messages with filters\n */\n async search(\n query: string,\n filters?: MessageSearchFilters,\n ): Promise<Message[]> {\n let messages = await this.list({});\n\n // Filter by query\n if (query) {\n const lowerQuery = query.toLowerCase();\n messages = messages.filter(\n (m) =>\n m.subject?.toLowerCase().includes(lowerQuery) ||\n m.body?.toLowerCase().includes(lowerQuery) ||\n m.fromAddress?.toLowerCase().includes(lowerQuery) ||\n m.fromName?.toLowerCase().includes(lowerQuery),\n );\n }\n\n // Apply filters\n if (filters) {\n if (filters.accountIds && filters.accountIds.length > 0) {\n messages = messages.filter((m) =>\n filters.accountIds?.includes(m.accountId),\n );\n }\n if (filters.messageType) {\n messages = messages.filter((m) => {\n const metaType = (m as { _meta_type?: string })._meta_type || '';\n return metaType.includes(filters.messageType as string);\n });\n }\n if (filters.from) {\n const fromLower = filters.from.toLowerCase();\n messages = messages.filter(\n (m) =>\n m.fromAddress?.toLowerCase().includes(fromLower) ||\n m.fromName?.toLowerCase().includes(fromLower),\n );\n }\n if (filters.to) {\n const toLower = filters.to.toLowerCase();\n messages = messages.filter((m) =>\n m.toAddresses?.toLowerCase().includes(toLower),\n );\n }\n if (filters.isRead !== undefined) {\n messages = messages.filter((m) => m.isRead === filters.isRead);\n }\n if (filters.isFlagged !== undefined) {\n messages = messages.filter((m) => m.isFlagged === filters.isFlagged);\n }\n if (filters.sinceDate) {\n messages = messages.filter(\n (m) => m.date && m.date >= (filters.sinceDate as Date),\n );\n }\n if (filters.beforeDate) {\n messages = messages.filter(\n (m) => m.date && m.date < (filters.beforeDate as Date),\n );\n }\n if (filters.query) {\n const q = filters.query.toLowerCase();\n messages = messages.filter(\n (m) =>\n m.subject?.toLowerCase().includes(q) ||\n m.body?.toLowerCase().includes(q),\n );\n }\n }\n\n return messages;\n }\n\n /**\n * Get messages by multiple accounts\n */\n async getByAccounts(accountIds: string[]): Promise<Message[]> {\n const allMessages = await this.list({});\n return allMessages.filter((m) => accountIds.includes(m.accountId));\n }\n\n /**\n * Get messages by STI type.\n *\n * Accepts either the full discriminator (e.g. \"@happyvertical/smrt-messages:Email\")\n * or the short type name (e.g. \"Email\").\n */\n async getByType(messageType: string): Promise<Message[]> {\n if (messageType.includes(':') || messageType.startsWith('@')) {\n return await this.list({ where: { _meta_type: messageType } });\n }\n const allMessages = await this.list({});\n return allMessages.filter((m) => {\n const metaType = (m as { _meta_type?: string })._meta_type || '';\n return metaType.endsWith(`:${messageType}`);\n });\n }\n\n /**\n * Get unread messages\n */\n async getUnread(accountId?: string): Promise<Message[]> {\n const where: Record<string, unknown> = { isRead: false };\n if (accountId) {\n where.accountId = accountId;\n }\n return await this.list({ where });\n }\n\n /**\n * Get flagged messages\n */\n async getFlagged(accountId?: string): Promise<Message[]> {\n const where: Record<string, unknown> = { isFlagged: true };\n if (accountId) {\n where.accountId = accountId;\n }\n return await this.list({ where });\n }\n\n /**\n * Get recent messages\n */\n async getRecent(limit = 20, accountId?: string): Promise<Message[]> {\n const allMessages = await this.list({\n where: accountId ? { accountId } : undefined,\n });\n\n return allMessages\n .sort((a, b) => {\n const dateA = a.date?.getTime() || 0;\n const dateB = b.date?.getTime() || 0;\n return dateB - dateA;\n })\n .slice(0, limit);\n }\n\n /**\n * Get messages by thread\n */\n async getByThread(threadId: string): Promise<Message[]> {\n return await this.list({ where: { threadId } });\n }\n\n /**\n * Mark multiple messages as read\n */\n async markAllRead(messageIds: string[]): Promise<void> {\n for (const id of messageIds) {\n const message = await this.get({ id });\n if (message) {\n await message.markRead();\n }\n }\n }\n\n /**\n * Get message statistics for an account\n */\n async getAccountStats(accountId: string): Promise<{\n total: number;\n unread: number;\n flagged: number;\n byType: Record<string, number>;\n }> {\n const messages = await this.list({ where: { accountId } });\n const byType: Record<string, number> = {};\n\n for (const msg of messages) {\n const metaType = (msg as { _meta_type?: string })._meta_type || 'Unknown';\n const shortType = metaType.split(':').pop() || metaType;\n byType[shortType] = (byType[shortType] || 0) + 1;\n }\n\n return {\n total: messages.length,\n unread: messages.filter((m) => !m.isRead).length,\n flagged: messages.filter((m) => m.isFlagged).length,\n byType,\n };\n }\n\n // ─────────────────────────────────────────────────────────────────────────\n // Send / Draft Queries\n // ─────────────────────────────────────────────────────────────────────────\n\n /**\n * Get draft messages\n */\n async getDrafts(accountId?: string): Promise<Message[]> {\n const where: Record<string, unknown> = { sendStatus: 'draft' };\n if (accountId) where.accountId = accountId;\n return await this.list({ where });\n }\n\n /**\n * Get sent messages\n */\n async getSent(accountId?: string): Promise<Message[]> {\n const where: Record<string, unknown> = { sendStatus: 'sent' };\n if (accountId) where.accountId = accountId;\n return await this.list({ where });\n }\n\n /**\n * Get scheduled messages\n */\n async getScheduled(accountId?: string): Promise<Message[]> {\n const where: Record<string, unknown> = { sendStatus: 'scheduled' };\n if (accountId) where.accountId = accountId;\n return await this.list({ where });\n }\n\n /**\n * Get messages that failed to send\n */\n async getFailedSends(accountId?: string): Promise<Message[]> {\n const where: Record<string, unknown> = { sendStatus: 'failed' };\n if (accountId) where.accountId = accountId;\n return await this.list({ where });\n }\n\n /**\n * Get outbox (pending + sending + scheduled)\n */\n async getOutbox(accountId?: string): Promise<Message[]> {\n const allMessages = await this.list({\n where: accountId ? { accountId } : undefined,\n });\n return allMessages.filter(\n (m) =>\n m.sendStatus === 'pending' ||\n m.sendStatus === 'sending' ||\n m.sendStatus === 'scheduled',\n );\n }\n\n // ─────────────────────────────────────────────────────────────────────────\n // Tenant Helper Methods\n // ─────────────────────────────────────────────────────────────────────────\n\n async findByTenant(tenantId: string): Promise<Message[]> {\n return this.list({ where: { tenantId } });\n }\n\n // Message is the @TenantScoped STI base, so an explicit `tenant_id IS NULL`\n // filter via list() throws and unflagged raw SQL is blocked under an active\n // tenant context (#1596). Route through the raw helpers — no `_meta_type`\n // scope so the base collection still returns ALL message subtypes.\n async findGlobal(): Promise<Message[]> {\n return queryGlobal<Message>(this);\n }\n\n async findWithGlobals(tenantId: string): Promise<Message[]> {\n return queryWithGlobals<Message>(this, tenantId, 'Message.findWithGlobals');\n }\n}\n"],"mappings":";;;;;;AAWO,IAAM,oBAAN,cAAgC,eAAwB;CAC7D,OAAgB,aAAa;;;;CAK7B,MAAM,OACJ,OACA,SACoB;EACpB,IAAI,WAAW,MAAM,KAAK,KAAK,CAAC,CAAC;EAGjC,IAAI,OAAO;GACT,MAAM,aAAa,MAAM,YAAY;GACrC,WAAW,SAAS,QACjB,MACC,EAAE,SAAS,YAAY,CAAA,CAAE,SAAS,UAAU,KAC5C,EAAE,MAAM,YAAY,CAAA,CAAE,SAAS,UAAU,KACzC,EAAE,aAAa,YAAY,CAAA,CAAE,SAAS,UAAU,KAChD,EAAE,UAAU,YAAY,CAAA,CAAE,SAAS,UAAU,CACjD;EACF;EAGA,IAAI,SAAS;GACX,IAAI,QAAQ,cAAc,QAAQ,WAAW,SAAS,GACpD,WAAW,SAAS,QAAQ,MAC1B,QAAQ,YAAY,SAAS,EAAE,SAAS,CAC1C;GAEF,IAAI,QAAQ,aACV,WAAW,SAAS,QAAQ,MAAM;IAEhC,QADkB,EAA8B,cAAc,GAAA,CAC9C,SAAS,QAAQ,WAAqB;GACxD,CAAC;GAEH,IAAI,QAAQ,MAAM;IAChB,MAAM,YAAY,QAAQ,KAAK,YAAY;IAC3C,WAAW,SAAS,QACjB,MACC,EAAE,aAAa,YAAY,CAAA,CAAE,SAAS,SAAS,KAC/C,EAAE,UAAU,YAAY,CAAA,CAAE,SAAS,SAAS,CAChD;GACF;GACA,IAAI,QAA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UAAU,WAAwC;EACtD,MAAM,QAAiC,EAAE,YAAY,QAAQ;EAC7D,IAAI,WAAW,MAAM,YAAY;EACjC,OAAO,MAAM,KAAK,KAAK,EAAE,MAAM,CAAC;CAClC;;;;CAKA,MAAM,QAAQ,WAAwC;EACpD,MAAM,QAAiC,EAAE,YAAY,OAAO;EAC5D,IAAI,WAAW,MAAM,YAAY;EACjC,OAAO,MAAM,KAAK,KAAK,EAAE,MAAM,CAAC;CAClC;;;;CAKA,MAAM,aAAa,WAAwC;EACzD,MAAM,QAAiC,EAAE,YAAY,YAAY;EACjE,IAAI,WAAW,MAAM,YAAY;EACjC,OAAO,MAAM,KAAK,KAAK,EAAE,MAAM,CAAC;CAClC;;;;CAKA,MAAM,eAAe,WAAwC;EAC3D,MAAM,QAAiC,EAAE,YAAY,SAAS;EAC9D,IAAI,WAAW,MAAM,YAAY;EACjC,OAAO,MAAM,KAAK,KAAK,EAAE,MAAM,CAAC;CAClC;;;;CAKA,MAAM,UAAU,WAAwC;EAItD,QAAO,MAHmB,KAAK,KAAK,EAClC,OAAO,YAAY,EAAE,UAAU,IAAI,KAAA,EACrC,CAAC,EAAA,CACkB,QAChB,MACC,EAAE,eAAe,aACjB,EAAE,eAAe,aACjB,EAAE,eAAe,WACrB;CACF;CAMA,MAAM,aAAa,UAAsC;EACvD,OAAO,KAAK,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;CAC1C;CAMA,MAAM,aAAiC;EACrC,OAAO,YAAqB,IAAI;CAClC;CAEA,MAAM,gBAAgB,UAAsC;EAC1D,OAAO,iBAA0B,MAAM,UAAU,yBAAyB;CAC5E;AACF"}
@@ -1,5 +1,5 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
2
- import "./EmailAccountCollection-CgZE9YAM.js";
2
+ import "./EmailAccountCollection-OLTzu2T0.js";
3
3
  import { SmrtCollection, SmrtObject, crossPackageRef, field, smrt } from "@happyvertical/smrt-core";
4
4
  import { TenantScoped, tenantId } from "@happyvertical/smrt-tenancy/decorators";
5
5
  //#region src/models/MessagingEndpoint.ts
@@ -94,4 +94,4 @@ var MessagingEndpointCollection = class extends SmrtCollection {
94
94
  //#endregion
95
95
  export { MessagingEndpointCollection_exports as n, MessagingEndpoint as r, MessagingEndpointCollection as t };
96
96
 
97
- //# sourceMappingURL=MessagingEndpointCollection-FmbtiFJy.js.map
97
+ //# sourceMappingURL=MessagingEndpointCollection-CE3kQKQU.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"MessagingEndpointCollection-FmbtiFJy.js","names":[],"sources":["../../src/models/MessagingEndpoint.ts","../../src/collections/MessagingEndpointCollection.ts"],"sourcesContent":["import type { SmrtObjectOptions } from '@happyvertical/smrt-core';\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 crossPackageRef,\n field,\n SmrtObject,\n smrt,\n} from '@happyvertical/smrt-core';\nimport { TenantScoped, tenantId } from '@happyvertical/smrt-tenancy/decorators';\nimport type { MessagingChannel, MessagingEndpointOptions } from '../types.js';\n\n@TenantScoped({ mode: 'required' })\n@smrt({\n tableName: 'messaging_endpoints',\n api: { include: ['list', 'get'] },\n mcp: { include: ['list', 'get'] },\n cli: { include: ['list', 'get'] },\n conflictColumns: ['tenant_id', 'channel', 'label'],\n})\nexport class MessagingEndpoint extends SmrtObject { static __smrtPackage__ = \"@happyvertical/smrt-messages\";\n @tenantId()\n tenantId = '';\n\n @crossPackageRef('@happyvertical/smrt-profiles:Profile', { nullable: true })\n profileId: string | null = null;\n\n @field({ required: true, requiredFor: 'identity' })\n label = '';\n\n @field({ required: true })\n channel: MessagingChannel = 'email';\n\n /** Provider-specific destination JSON. Hidden from generated read surfaces. */\n @field({ required: true, sensitive: true })\n address = '{}';\n\n isActive = true;\n verifiedAt: Date | null = null;\n createdAt = new Date();\n updatedAt = new Date();\n\n constructor(options: MessagingEndpointOptions = {}) {\n super(options as SmrtObjectOptions);\n if (options.tenantId !== undefined) this.tenantId = options.tenantId;\n if (options.profileId !== undefined) this.profileId = options.profileId;\n if (options.label !== undefined) this.label = options.label;\n if (options.channel !== undefined) this.channel = options.channel;\n if (options.address !== undefined) this.address = options.address;\n if (options.isActive !== undefined) this.isActive = options.isActive;\n if (options.verifiedAt !== undefined) this.verifiedAt = options.verifiedAt;\n if (options.createdAt !== undefined) this.createdAt = options.createdAt;\n if (options.updatedAt !== undefined) this.updatedAt = options.updatedAt;\n }\n\n getAddress<T extends Record<string, unknown> = Record<string, unknown>>(): T {\n try {\n return JSON.parse(this.address) as T;\n } catch {\n return {} as T;\n }\n }\n\n setAddress(address: Record<string, unknown>): void {\n this.address = JSON.stringify(address);\n }\n\n getMaskedAddress(): string {\n const address = this.getAddress();\n const visible =\n address.email ??\n address.chatId ??\n address.to ??\n address.stream ??\n address.phoneNumber;\n if (typeof visible !== 'string' && typeof visible !== 'number')\n return '••••';\n const value = String(visible);\n if (value.includes('@')) {\n const [name, domain] = value.split('@');\n return `${name.slice(0, 2)}•••@${domain}`;\n }\n return value.length <= 4 ? '••••' : `••••${value.slice(-4)}`;\n }\n}\n","import { SmrtCollection } from '@happyvertical/smrt-core';\nimport { MessagingEndpoint } from '../models/MessagingEndpoint.js';\n\nexport class MessagingEndpointCollection extends SmrtCollection<MessagingEndpoint> {\n static readonly _itemClass = MessagingEndpoint;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAqBO,IAAM,oBAAN,cAAgC,WAAW;CAEhD,WAAW;CAGX,YAA2B;CAG3B,QAAQ;CAGR,UAA4B;CAI5B,UAAU;CAEV,WAAW;CACX,aAA0B;CAC1B,4BAAY,IAAI,KAAK;CACrB,4BAAY,IAAI,KAAK;CAErB,YAAY,UAAoC,CAAC,GAAG;EAClD,MAAM,OAA4B;EAClC,IAAI,QAAQ,aAAa,KAAA,GAAW,KAAK,WAAW,QAAQ;EAC5D,IAAI,QAAQ,cAAc,KAAA,GAAW,KAAK,YAAY,QAAQ;EAC9D,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AAW,CAAC,CAAA,GAPvC,kBAQX,WAAA,SAAA,CAAA;AAGA,gBAAA,CADC,MAAM,EAAE,UAAU,KAAK,CAAC,CAAA,GAVd,kBAWX,WAAA,WAAA,CAAA;AAIA,gBAAA,CADC,MAAM;CAAE,UAAU;CAAM,WAAW;AAAK,CAAC,CAAA,GAd/B,kBAeX,WAAA,WAAA,CAAA;AAfW,oBAAN,gBAAA,CARN,aAAa,EAAE,MAAM,WAAW,CAAC,GACjC,KAAK;CACJ,WAAW;CACX,KAAK,EAAE,SAAS,CAAC,QAAQ,KAAK,EAAE;CAChC,KAAK,EAAE,SAAS,CAAC,QAAQ,KAAK,EAAE;CAChC,KAAK,EAAE,SAAS,CAAC,QAAQ,KAAK,EAAE;CAChC,iBAAiB;EAAC;EAAa;EAAW;CAAO;AACnD,CAAC,CAAA,GACY,iBAAA;;;;AClBN,IAAM,8BAAN,cAA0C,eAAkC;CACjF,OAAgB,aAAa;AAC/B"}
1
+ {"version":3,"file":"MessagingEndpointCollection-CE3kQKQU.js","names":[],"sources":["../../src/models/MessagingEndpoint.ts","../../src/collections/MessagingEndpointCollection.ts"],"sourcesContent":["import type { SmrtObjectOptions } from '@happyvertical/smrt-core';\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 crossPackageRef,\n field,\n SmrtObject,\n smrt,\n} from '@happyvertical/smrt-core';\nimport { TenantScoped, tenantId } from '@happyvertical/smrt-tenancy/decorators';\nimport type { MessagingChannel, MessagingEndpointOptions } from '../types.js';\n\n@TenantScoped({ mode: 'required' })\n@smrt({\n tableName: 'messaging_endpoints',\n api: { include: ['list', 'get'] },\n mcp: { include: ['list', 'get'] },\n cli: { include: ['list', 'get'] },\n conflictColumns: ['tenant_id', 'channel', 'label'],\n})\nexport class MessagingEndpoint extends SmrtObject { static __smrtPackage__ = \"@happyvertical/smrt-messages\";\n @tenantId()\n tenantId = '';\n\n @crossPackageRef('@happyvertical/smrt-profiles:Profile', { nullable: true })\n profileId: string | null = null;\n\n @field({ required: true, requiredFor: 'identity' })\n label = '';\n\n @field({ required: true })\n channel: MessagingChannel = 'email';\n\n /** Provider-specific destination JSON. Hidden from generated read surfaces. */\n @field({ required: true, sensitive: true })\n address = '{}';\n\n isActive = true;\n verifiedAt: Date | null = null;\n createdAt = new Date();\n updatedAt = new Date();\n\n constructor(options: MessagingEndpointOptions = {}) {\n super(options as SmrtObjectOptions);\n if (options.tenantId !== undefined) this.tenantId = options.tenantId;\n if (options.profileId !== undefined) this.profileId = options.profileId;\n if (options.label !== undefined) this.label = options.label;\n if (options.channel !== undefined) this.channel = options.channel;\n if (options.address !== undefined) this.address = options.address;\n if (options.isActive !== undefined) this.isActive = options.isActive;\n if (options.verifiedAt !== undefined) this.verifiedAt = options.verifiedAt;\n if (options.createdAt !== undefined) this.createdAt = options.createdAt;\n if (options.updatedAt !== undefined) this.updatedAt = options.updatedAt;\n }\n\n getAddress<T extends Record<string, unknown> = Record<string, unknown>>(): T {\n try {\n return JSON.parse(this.address) as T;\n } catch {\n return {} as T;\n }\n }\n\n setAddress(address: Record<string, unknown>): void {\n this.address = JSON.stringify(address);\n }\n\n getMaskedAddress(): string {\n const address = this.getAddress();\n const visible =\n address.email ??\n address.chatId ??\n address.to ??\n address.stream ??\n address.phoneNumber;\n if (typeof visible !== 'string' && typeof visible !== 'number')\n return '••••';\n const value = String(visible);\n if (value.includes('@')) {\n const [name, domain] = value.split('@');\n return `${name.slice(0, 2)}•••@${domain}`;\n }\n return value.length <= 4 ? '••••' : `••••${value.slice(-4)}`;\n }\n}\n","import { SmrtCollection } from '@happyvertical/smrt-core';\nimport { MessagingEndpoint } from '../models/MessagingEndpoint.js';\n\nexport class MessagingEndpointCollection extends SmrtCollection<MessagingEndpoint> {\n static readonly _itemClass = MessagingEndpoint;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAqBO,IAAM,oBAAN,cAAgC,WAAW;CAEhD,WAAW;CAGX,YAA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,SAAS,2BAAO,MAAM,MAAM,EAAE;CAC3D;AACF;AAhEoD,cAAvC,mBAA8C,mBAAkB,8BAAA;AAE3E,gBAAA,CADC,SAAS,CAAA,GADC,kBAEX,WAAA,YAAA,CAAA;AAGA,gBAAA,CADC,gBAAgB,wCAAwC,EAAE,UAAU,KAAK,CAAC,CAAA,GAJhE,kBAKX,WAAA,aAAA,CAAA;AAGA,gBAAA,CADC,MAAM;CAAE,UAAU;CAAM,aAAa;AAAW,CAAC,CAAA,GAPvC,kBAQX,WAAA,SAAA,CAAA;AAGA,gBAAA,CADC,MAAM,EAAE,UAAU,KAAK,CAAC,CAAA,GAVd,kBAWX,WAAA,WAAA,CAAA;AAIA,gBAAA,CADC,MAAM;CAAE,UAAU;CAAM,WAAW;AAAK,CAAC,CAAA,GAd/B,kBAeX,WAAA,WAAA,CAAA;AAfW,oBAAN,gBAAA,CARN,aAAa,EAAE,MAAM,WAAW,CAAC,GACjC,KAAK;CACJ,WAAW;CACX,KAAK,EAAE,SAAS,CAAC,QAAQ,KAAK,EAAE;CAChC,KAAK,EAAE,SAAS,CAAC,QAAQ,KAAK,EAAE;CAChC,KAAK,EAAE,SAAS,CAAC,QAAQ,KAAK,EAAE;CAChC,iBAAiB;EAAC;EAAa;EAAW;CAAO;AACnD,CAAC,CAAA,GACY,iBAAA;;;;AClBN,IAAM,8BAAN,cAA0C,eAAkC;CACjF,OAAgB,aAAa;AAC/B"}
package/dist/connect.js CHANGED
@@ -1,4 +1,4 @@
1
- import { r as EmailAccount, t as EmailAccountCollection } from "./chunks/EmailAccountCollection-CgZE9YAM.js";
1
+ import { r as EmailAccount, t as EmailAccountCollection } from "./chunks/EmailAccountCollection-OLTzu2T0.js";
2
2
  import { withTenant } from "./host.js";
3
3
  import { ObjectRegistry } from "@happyvertical/smrt-core";
4
4
  import { ConnectError, ConnectStateCollection, beginConnect, buildOAuth2AuthorizeUrl, consumeConnect, discoverOidcEndpoints, exchangeOAuth2Code, fetchOidcUserInfo } from "@happyvertical/smrt-secrets/connect";
package/dist/index.d.ts CHANGED
@@ -6,10 +6,12 @@
6
6
  * @packageDocumentation
7
7
  */
8
8
  import './__smrt-register__.js';
9
- export { assertMailAccess, canAccessMailAccount, configureMailAccess, decideMailAccess, deniedMailAccountIds, type GrantMailAccessInput, isMailScope, MAIL_ACCOUNT_RESOURCE_TYPE, MAIL_SCOPES, type MailAccessAdmin, type MailAccessConfig, type MailAccessDecision, MailAccessError, type MailAccessReason, type MailAccessResolver, type MailAccessResolverContext, MailAccessService, type MailAccessSubject, type MailPrincipal, type MailScope, mailScopePermission, resetMailAccess, runWithMailSystemAccess, } from './access.js';
9
+ export { assertMailAccess, canAccessMailAccount, configureMailAccess, decideMailAccess, deniedMailAccountIds, type GrantMailAccessInput, isMailScope, isPersonMailPrincipal, MAIL_ACCOUNT_RESOURCE_TYPE, MAIL_SCOPES, type MailAccessAdmin, type MailAccessConfig, type MailAccessDecision, MailAccessError, type MailAccessReason, type MailAccessResolver, type MailAccessResolverContext, MailAccessService, type MailAccessSubject, type MailPrincipal, type MailScope, mailScopePermission, resetMailAccess, resolveMailPrincipal, runWithMailSystemAccess, } from './access.js';
10
+ export { MailDraftError, type MailDraftInput, MailDraftService, } from './mail-drafts.js';
10
11
  export type { MailSyncOptions, MailSyncResult, MailSyncSkipReason, } from './mail-sync.js';
11
12
  export { CHANGE_FEED_PROVIDERS, type EnqueueMailSyncOptions, enqueueDueMailSyncs, enqueueMailSync, MAIL_SYNC_QUEUE, mailSyncDedupeKey, } from './mail-sync-jobs.js';
12
13
  export { type MailTriageAction, type MailTriageActionKind, type MailTriageFailure, type MailTriageResult, type MailWriteBackCapability, MailWriteBackUnsupportedError, } from './mail-triage.js';
14
+ export { type AgentSendPolicyContext, APPROVE_HELD_SEND_PERMISSION, auditMailAction, configureMailSendApprovals, effectiveAgentSendPolicy, type HeldSendDecisionResult, type HeldSendEdits, HeldSendError, type MailSendApprovalActor, type MailSendApprovalCheckResult, type MailSendApprovalConfig, type MailSendApprovalGate, type MailSendApprovalOutcome, MailSendApprovalService, type MailSendApprovalView, mailSendBindingHash, resetMailSendApprovals, stampHandledBy, threadHandledBy, } from './send-approval.js';
13
15
  export { AccountCollection } from "./collections/AccountCollection.js";
14
16
  export { AttachmentCollection } from "./collections/AttachmentCollection.js";
15
17
  export { CorrespondentCollection } from './collections/CorrespondentCollection.js';
@@ -60,7 +62,7 @@ export { type NotificationOptOutChange, type NotificationOptOutDenialReason, Not
60
62
  export { buildNotificationLink, messageSendTransport, type NotificationDispatchOptions, type NotificationDispatchOutcome, type NotificationDispatchReport, type NotificationEmailInput, type NotificationEnqueueResult, type NotificationOutboxDenialReason, NotificationOutboxDeniedError, type NotificationOutboxOptions, NotificationOutboxService, type NotificationProfileRecipientRequest, type NotificationProfileSuppressionRequest, type NotificationRecipient, type NotificationRecipientRequest, type NotificationReconcileOutcome, type NotificationSuppressionRequest, type NotificationTransport, type NotificationTransportOutcome, type NotificationTransportReconciliation, type NotificationTransportRequest, notificationDeliveryCorrelationId, notificationDeliveryMessageId, } from './services/NotificationOutboxService.js';
61
63
  export { type PersonaMessageSendResult, PersonaMessagingService, } from './services/PersonaMessagingService.js';
62
64
  export { type UserNotificationInput, type UserNotificationListOptions, type UserNotificationNotifyResult, type UserNotificationScope, UserNotificationService, } from './services/UserNotificationService.js';
63
- export type { AccountOptions, AccountSearchFilters, AccountType, AttachmentOptions, EmailAccountOptions, EmailAccountSearchFilters, EmailAttachmentOptions, EmailFolderOptions, EmailFolderSearchFilters, EmailOptions, EmailSearchFilters, KnownMessagingChannel, MessageOptions, MessageSearchFilters, MessageSenderInterface, MessageSendResult, MessageType, MessagingChannel, MessagingEndpointOptions, PersonaMessageRouteOptions, ProviderType, SendEmailAttachment, SendEmailOptions, SendMessageOptions, SendPersonaMessageOptions, SendSlackOptions, SendStatus, SendTweetOptions, SlackAccountOptions, SlackMessageOptions, SyncOptions, SyncProgress, SyncResult, TweetOptions, TwitterAccountOptions, } from "./types.js";
65
+ export type { AccountOptions, AccountSearchFilters, AccountType, AgentSendPolicy, AttachmentOptions, EmailAccountOptions, EmailAccountSearchFilters, EmailAttachmentOptions, EmailFolderOptions, EmailFolderSearchFilters, EmailOptions, EmailSearchFilters, KnownMessagingChannel, MessageOptions, MessageSearchFilters, MessageSenderInterface, MessageSendResult, MessageType, MessagingChannel, MessagingEndpointOptions, PersonaMessageRouteOptions, ProviderType, SendEmailAttachment, SendEmailOptions, SendMessageOptions, SendPersonaMessageOptions, SendSlackOptions, SendStatus, SendTweetOptions, SlackAccountOptions, SlackMessageOptions, SyncOptions, SyncProgress, SyncResult, TweetOptions, TwitterAccountOptions, } from "./types.js";
64
66
  export { assertNotificationProfileRecipientSchema, migrateNotificationProfileRecipients, type NotificationProfileRecipientEngine, type NotificationProfileRecipientPlan, planNotificationProfileRecipients, } from './migrations/profileRecipients.js';
65
67
  export { type NotificationRecipientIdentity, PROFILE_NOTIFICATION_POLICY_PREFIX, profileNotificationPolicy, } from './notification-recipient-identity.js';
66
68
  export { MailboxRecipe, NotificationsRecipe, SlackRecipe } from './recipes.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,wBAAwB,CAAC;AAQhC,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,mBAAmB,EACnB,gBAAgB,EAChB,oBAAoB,EACpB,KAAK,oBAAoB,EACzB,WAAW,EACX,0BAA0B,EAC1B,WAAW,EACX,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,eAAe,EACf,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,yBAAyB,EAC9B,iBAAiB,EACjB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,mBAAmB,EACnB,eAAe,EACf,uBAAuB,GACxB,MAAM,aAAa,CAAC;AACrB,YAAY,EACV,eAAe,EACf,cAAc,E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,WAAW,EACX,YAAY,EACZ,UAAU,EAEV,YAAY,EACZ,qBAAqB,GACtB,MAAM,YAAS,CAAC;AAMjB,OAAO,EACL,wCAAwC,EACxC,oCAAoC,EACpC,KAAK,kCAAkC,EACvC,KAAK,gCAAgC,EACrC,iCAAiC,GAClC,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,KAAK,6BAA6B,EAClC,kCAAkC,EAClC,yBAAyB,GAC1B,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,wBAAwB,CAAC;AAQhC,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,mBAAmB,EACnB,gBAAgB,EAChB,oBAAoB,EACpB,KAAK,oBAAoB,EACzB,WAAW,EACX,qBAAqB,EACrB,0BAA0B,EAC1B,WAAW,EACX,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,eAAe,EACf,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,yBAAyB,EAC9B,iBAAiB,EACjB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,mBAAmB,EACnB,eAAe,EACf,oBAAoB,EACpB,uBAAuB,GACxB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,cAAc,EACd,KAAK,cAAc,EACnB,gBAAgB,GACjB,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EACV,eAAe,EACf,cAAc,EACd,kBAAkB,GACnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,qBAAqB,EACrB,KAAK,sBAAsB,EAC3B,mBAAmB,EACnB,eAAe,EACf,eAAe,EACf,iBAAiB,GAClB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,KAAK,gBAAgB,EACr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ChB,wBAAwB,EACxB,0BAA0B,EAC1B,YAAY,EACZ,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,yBAAyB,EACzB,gBAAgB,EAChB,UAAU,EACV,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EAEnB,WAAW,EACX,YAAY,EACZ,UAAU,EAEV,YAAY,EACZ,qBAAqB,GACtB,MAAM,YAAS,CAAC;AAMjB,OAAO,EACL,wCAAwC,EACxC,oCAAoC,EACpC,KAAK,kCAAkC,EACvC,KAAK,gCAAgC,EACrC,iCAAiC,GAClC,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,KAAK,6BAA6B,EAClC,kCAAkC,EAClC,yBAAyB,GAC1B,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC"}
package/dist/index.js CHANGED
@@ -1,16 +1,16 @@
1
- import { A as MESSAGING_PERMISSION_DEFINITIONS, C as mailScopePermission, D as MANAGE_MESSAGE_CREDENTIALS_PERMISSION, E as withoutListBounds, F as seedMessagesRolePermissions, M as assertMessagingPermission, N as ensureMessagingPermissionsRegistered, O as MANAGE_MESSAGE_ROUTES_PERMISSION, P as messagingPrincipalFromPermissions, S as learnMailAccessOptions, T as runWithMailSystemAccess, _ as deniedMailAccountIds, b as inMailSystemAccess, c as MAIL_ACCOUNT_RESOURCE_TYPE, d as MailAccessService, f as assertHydratedMailAccess, g as decideMailAccess, h as configureMailAccess, i as AccountCollection, j as SEND_MESSAGES_PERMISSION, k as MESSAGES_ROLE_PERMISSION_MATRIX, l as MAIL_SCOPES, m as canAccessMailAccount, o as MailWriteBackUnsupportedError, p as assertMailAccess, r as EmailAccount, s as Account, t as EmailAccountCollection, u as MailAccessError, v as getEffectiveMailAccessConfigs, w as resetMailAccess, x as isMailScope, y as getMailAccessConfig } from "./chunks/EmailAccountCollection-CgZE9YAM.js";
1
+ import { A as deniedMailAccountIds, B as runWithMailSystemAccess, C as MailAccessError, D as canAccessMailAccount, E as assertMailAccess, F as isPersonMailPrincipal, G as MESSAGING_PERMISSION_DEFINITIONS, H as MANAGE_MESSAGE_CREDENTIALS_PERMISSION, I as learnMailAccessOptions, J as ensureMessagingPermissionsRegistered, K as SEND_MESSAGES_PERMISSION, L as mailScopePermission, M as getMailAccessConfig, N as inMailSystemAccess, O as configureMailAccess, P as isMailScope, R as resetMailAccess, S as MAIL_SCOPES, T as assertHydratedMailAccess, U as MANAGE_MESSAGE_ROUTES_PERMISSION, V as withoutListBounds, W as MESSAGES_ROLE_PERMISSION_MATRIX, X as seedMessagesRolePermissions, Y as messagingPrincipalFromPermissions, _ as resetMailSendApprovals, b as Account, c as HeldSendError, f as auditMailAction, g as mailSendBindingHash, i as AccountCollection, j as getEffectiveMailAccessConfigs, k as decideMailAccess, l as MailSendApprovalService, m as effectiveAgentSendPolicy, o as MailWriteBackUnsupportedError, p as configureMailSendApprovals, q as assertMessagingPermission, r as EmailAccount, s as APPROVE_HELD_SEND_PERMISSION, t as EmailAccountCollection, v as stampHandledBy, w as MailAccessService, x as MAIL_ACCOUNT_RESOURCE_TYPE, y as threadHandledBy, z as resolveMailPrincipal } from "./chunks/EmailAccountCollection-OLTzu2T0.js";
2
2
  import { buildSqliteRebuildStatements, isDeepStrictEqual, normalizeIdentityEmail, queryGlobal, queryWithGlobals, readNotificationProfile, withSystemContext, withTenant } from "./host.js";
3
- import { r as Attachment, t as AttachmentCollection } from "./chunks/AttachmentCollection-Dzz2iKjx.js";
4
- import { t as EmailFolder } from "./chunks/EmailFolder-Bu7y8-VX.js";
3
+ import { r as Attachment, t as AttachmentCollection } from "./chunks/AttachmentCollection-C0K7lITr.js";
4
+ import { t as EmailFolder } from "./chunks/EmailFolder-Cl4sKRMB.js";
5
5
  import { d as withProtectedNotificationHandoff, f as PROFILE_NOTIFICATION_POLICY_PREFIX, l as protectedNotificationMetadata, m as profileNotificationPolicy, p as assertNotificationRecipientIdentity, t as ProtectedNotificationHandoffError } from "./chunks/protected-notification-handoff-mvaEZVp7.js";
6
- import { t as Message } from "./chunks/Message-BwW51pgG.js";
6
+ import { t as Message } from "./chunks/Message-CuvACyOv.js";
7
7
  import { a as registerMessagingProvider, n as getMessagingProvider, o as ZulipSender, r as listMessagingProviders, s as TelegramSender, t as ensureBuiltinMessagingProvidersRegistered } from "./chunks/providers-Bz_F_ywF.js";
8
- import { t as MessageCollection } from "./chunks/MessageCollection-JjZybSMu.js";
9
- import { r as MessagingEndpoint, t as MessagingEndpointCollection } from "./chunks/MessagingEndpointCollection-FmbtiFJy.js";
10
- import { t as Email } from "./chunks/Email-DDMgkm_l.js";
11
- import { t as EmailCollection } from "./chunks/EmailCollection-lo8WePl-.js";
12
- import { t as EmailFolderCollection } from "./chunks/EmailFolderCollection-BpzzKBhM.js";
13
- import { t as EmailSender } from "./chunks/EmailSender-B-Rtq9du.js";
8
+ import { t as MessageCollection } from "./chunks/MessageCollection-DOErodD3.js";
9
+ import { r as MessagingEndpoint, t as MessagingEndpointCollection } from "./chunks/MessagingEndpointCollection-CE3kQKQU.js";
10
+ import { t as Email } from "./chunks/Email-DWF2VG_4.js";
11
+ import { t as EmailCollection } from "./chunks/EmailCollection-8HeBXd0F.js";
12
+ import { t as EmailFolderCollection } from "./chunks/EmailFolderCollection-L0na2e1L.js";
13
+ import { t as EmailSender } from "./chunks/EmailSender-BiAI0LWU.js";
14
14
  import { t as SlackSender } from "./chunks/SlackSender-CetlSe6D.js";
15
15
  import { t as TweetSender } from "./chunks/TweetSender-Dw-TDxIB.js";
16
16
  import { GlobalInterceptors, ObjectRegistry, SmrtCollection, SmrtObject, SmrtRecipe, crossPackageRef, detectEngine, field, foreignKey, isUniqueViolationError, smrt, usesEmbeddedRevisionFallback, withEmbeddedWriteQueue } from "@happyvertical/smrt-core";
@@ -98,7 +98,7 @@ function createMailAccessInterceptor() {
98
98
  const row = instance;
99
99
  row.accountId = null;
100
100
  if (!row.messageId || !row.options) return;
101
- const { MessageCollection } = await import("./chunks/MessageCollection-JjZybSMu.js").then((n) => n.n);
101
+ const { MessageCollection } = await import("./chunks/MessageCollection-DOErodD3.js").then((n) => n.n);
102
102
  row.accountId = (await runWithMailSystemAccess(async () => (await MessageCollection.create(row.options)).get({ id: row.messageId })))?.accountId || null;
103
103
  },
104
104
  async afterList(className, results, context) {
@@ -153,6 +153,102 @@ function ensureMailAccessEnforcementRegistered() {
153
153
  GlobalInterceptors.register(createMailAccessInterceptor());
154
154
  }
155
155
  //#endregion
156
+ //#region src/mail-drafts.ts
157
+ var MailDraftError = class extends Error {
158
+ status;
159
+ constructor(message, status = 400) {
160
+ super(message);
161
+ this.name = "MailDraftError";
162
+ this.status = status;
163
+ }
164
+ };
165
+ function assertRecipients(value, label) {
166
+ if (value === void 0) return;
167
+ if (!Array.isArray(value) || value.some((entry) => !entry || typeof entry.address !== "string" || !entry.address.includes("@") || entry.name !== void 0 && typeof entry.name !== "string")) throw new MailDraftError(`${label} must be a list of { address, name? }.`);
168
+ }
169
+ var MailDraftService = class {
170
+ constructor(options) {
171
+ this.options = options;
172
+ }
173
+ options;
174
+ async account(accountId) {
175
+ const { EmailAccountCollection } = await import("./chunks/EmailAccountCollection-OLTzu2T0.js").then((n) => n.n);
176
+ const account = await runWithMailSystemAccess(async () => (await EmailAccountCollection.create(withoutListBounds(this.options))).get({ id: accountId }));
177
+ if (!account?.id) throw new MailDraftError("Mail account not found.", 404);
178
+ return account;
179
+ }
180
+ async stored(id) {
181
+ const { EmailCollection } = await import("./chunks/EmailCollection-8HeBXd0F.js").then((n) => n.n);
182
+ return await runWithMailSystemAccess(async () => (await EmailCollection.create(this.options)).get({ id }));
183
+ }
184
+ /** Create or update a draft. Returns the saved draft. */
185
+ async save(input) {
186
+ assertRecipients(input.toAddresses, "toAddresses");
187
+ assertRecipients(input.ccAddresses, "ccAddresses");
188
+ assertRecipients(input.bccAddresses, "bccAddresses");
189
+ const account = await this.account(input.accountId);
190
+ const principal = await resolveMailPrincipal();
191
+ if (principal && account.tenantId && principal.tenantId !== account.tenantId) throw new MailAccessError("draft", "tenant_mismatch");
192
+ await assertMailAccess(account, "draft");
193
+ let draft;
194
+ if (input.draftId) {
195
+ const existing = await this.stored(input.draftId);
196
+ if (!existing || existing.accountId !== account.id) throw new MailDraftError("Draft not found.", 404);
197
+ if (!existing.isDraft || existing.sendStatus !== "draft") throw new MailDraftError("Only an unsent draft can be changed.", 409);
198
+ draft = existing;
199
+ } else if (input.inReplyToMessageId) {
200
+ await assertMailAccess(account, "read");
201
+ const original = await this.stored(input.inReplyToMessageId);
202
+ if (!original || original.accountId !== account.id) throw new MailDraftError("Message not found.", 404);
203
+ draft = original.createReply({ replyAll: input.replyAll === true });
204
+ await draft.initialize();
205
+ } else {
206
+ const { Email: EmailClass } = await import("./chunks/Email-DWF2VG_4.js").then((n) => n.n);
207
+ draft = new (ObjectRegistry.resolveEffectiveConstructor(EmailClass))({
208
+ ...this.options,
209
+ tenantId: account.tenantId,
210
+ accountId: account.id,
211
+ isDraft: true,
212
+ sendStatus: "draft",
213
+ isRead: true,
214
+ toAddresses: "[]",
215
+ ccAddresses: "[]",
216
+ bccAddresses: "[]"
217
+ });
218
+ await draft.initialize();
219
+ }
220
+ if (input.subject !== void 0) draft.subject = input.subject;
221
+ if (input.textBody !== void 0) {
222
+ draft.textBody = input.textBody;
223
+ draft.body = input.textBody;
224
+ }
225
+ if (input.htmlBody !== void 0) draft.htmlBody = input.htmlBody;
226
+ if (input.toAddresses !== void 0) draft.toAddresses = JSON.stringify(input.toAddresses);
227
+ if (input.ccAddresses !== void 0) draft.ccAddresses = JSON.stringify(input.ccAddresses);
228
+ if (input.bccAddresses !== void 0) draft.bccAddresses = JSON.stringify(input.bccAddresses);
229
+ draft.fromAddress = account.email;
230
+ draft.tenantId = account.tenantId;
231
+ draft.accountId = account.id;
232
+ draft.isDraft = true;
233
+ draft.sendStatus = "draft";
234
+ draft.updatedAt = /* @__PURE__ */ new Date();
235
+ stampHandledBy(draft, principal);
236
+ await draft.save();
237
+ await auditMailAction("messages.draft.save", draft);
238
+ return draft;
239
+ }
240
+ /**
241
+ * Send a draft. The account's agent send policy applies: an agent's draft
242
+ * normally comes back with `pendingApproval` and waits for a person.
243
+ */
244
+ async submit(draftId, options) {
245
+ const draft = await this.stored(draftId);
246
+ if (!draft?.accountId || !draft.isDraft) throw new MailDraftError("Draft not found.", 404);
247
+ await assertMailAccess(await this.account(draft.accountId), "draft");
248
+ return await draft.send(options);
249
+ }
250
+ };
251
+ //#endregion
156
252
  //#region src/mail-sync-jobs.ts
157
253
  var MAIL_SYNC_QUEUE = "mail-sync";
158
254
  var CHANGE_FEED_PROVIDERS = ["jmap"];
@@ -887,7 +983,7 @@ var EmailAttachment = class extends Attachment {
887
983
  */
888
984
  async getEmail() {
889
985
  if (!this.messageId) return null;
890
- const { EmailCollection } = await import("./chunks/EmailCollection-lo8WePl-.js").then((n) => n.n);
986
+ const { EmailCollection } = await import("./chunks/EmailCollection-8HeBXd0F.js").then((n) => n.n);
891
987
  return await (await EmailCollection.create(this.options)).get({ id: this.messageId });
892
988
  }
893
989
  };
@@ -2574,7 +2670,7 @@ var CorrespondentService = class {
2574
2670
  return result;
2575
2671
  }
2576
2672
  async ownAddresses(accountIds) {
2577
- const { EmailAccountCollection } = await import("./chunks/EmailAccountCollection-CgZE9YAM.js").then((n) => n.n);
2673
+ const { EmailAccountCollection } = await import("./chunks/EmailAccountCollection-OLTzu2T0.js").then((n) => n.n);
2578
2674
  const accounts = await EmailAccountCollection.create({ db: this.options.db });
2579
2675
  const out = [];
2580
2676
  for (const id of accountIds) {
@@ -4349,6 +4445,6 @@ ensureBuiltinMessagingProvidersRegistered();
4349
4445
  ensureMessagingPermissionsRegistered();
4350
4446
  ensureMailAccessEnforcementRegistered();
4351
4447
  //#endregion
4352
- export { Account, AccountCollection, Attachment, AttachmentCollection, Blacklist, BlacklistCollection, CHANGE_FEED_PROVIDERS, Correspondent, CorrespondentCollection, CorrespondentService, Email, EmailAccount, EmailAccountCollection, EmailAttachment, EmailAttachmentCollection, EmailCollection, EmailFolder, EmailFolderCollection, EmailSender, MAIL_ACCOUNT_RESOURCE_TYPE, MAIL_SCOPES, MAIL_SYNC_QUEUE, MANAGE_MESSAGE_CREDENTIALS_PERMISSION, MANAGE_MESSAGE_ROUTES_PERMISSION, MESSAGES_ROLE_PERMISSION_MATRIX, MESSAGING_PERMISSION_DEFINITIONS, MailAccessError, MailAccessService, MailSearchService, MailWriteBackUnsupportedError, MailboxRecipe, Message, MessageCollection, MessagingEndpoint, MessagingEndpointCollection, MessagingSettingsService, NOTIFICATION_DELIVERY_CHANNELS, NOTIFICATION_OPT_OUT_ALL_SCOPE, NOTIFICATION_OPT_OUT_SCOPE_PATTERN, NotificationDelivery, NotificationDeliveryCollection, NotificationOptOut, NotificationOptOutCollection, NotificationOptOutDeniedError, NotificationOptOutService, NotificationOutboxDeniedError, NotificationOutboxService, NotificationsRecipe, PROFILE_NOTIFICATION_POLICY_PREFIX, PersonaMessageRoute, PersonaMessageRouteCollection, PersonaMessagingService, SEND_MESSAGES_PERMISSION, SlackAccount, SlackMessage, SlackRecipe, SlackSender, TelegramAccount, TelegramSender, Tweet, TweetSender, TwitterAccount, USER_NOTIFICATION_SEVERITIES, UserNotification, UserNotificationCollection, UserNotificationService, Whitelist, WhitelistCollection, ZulipAccount, ZulipSender, assertMailAccess, assertMessagingPermission, assertNotificationProfileRecipientSchema, buildNotificationLink, canAccessMailAccount, configureMailAccess, decideMailAccess, deniedMailAccountIds, enqueueDueMailSyncs, enqueueMailSync, ensureBuiltinMessagingProvidersRegistered, ensureMessagingPermissionsRegistered, getMessagingProvider, isMailScope, isValidNotificationOptOutScope, listMessagingProviders, mailScopePermission, mailSyncDedupeKey, messageSendTransport, messagingPrincipalFromPermissions, migrateNotificationProfileRecipients, normalizeCorrespondentAddress, notificationDeliveryCorrelationId, notificationDeliveryMessageId, optOutSuppression, planNotificationProfileRecipients, profileNotificationPolicy, readableMailAccounts, registerMessagingProvider, resetMailAccess, runWithMailSystemAccess, seedMessagesRolePermissions };
4448
+ export { APPROVE_HELD_SEND_PERMISSION, Account, AccountCollection, Attachment, AttachmentCollection, Blacklist, BlacklistCollection, CHANGE_FEED_PROVIDERS, Correspondent, CorrespondentCollection, CorrespondentService, Email, EmailAccount, EmailAccountCollection, EmailAttachment, EmailAttachmentCollection, EmailCollection, EmailFolder, EmailFolderCollection, EmailSender, HeldSendError, MAIL_ACCOUNT_RESOURCE_TYPE, MAIL_SCOPES, MAIL_SYNC_QUEUE, MANAGE_MESSAGE_CREDENTIALS_PERMISSION, MANAGE_MESSAGE_ROUTES_PERMISSION, MESSAGES_ROLE_PERMISSION_MATRIX, MESSAGING_PERMISSION_DEFINITIONS, MailAccessError, MailAccessService, MailDraftError, MailDraftService, MailSearchService, MailSendApprovalService, MailWriteBackUnsupportedError, MailboxRecipe, Message, MessageCollection, MessagingEndpoint, MessagingEndpointCollection, MessagingSettingsService, NOTIFICATION_DELIVERY_CHANNELS, NOTIFICATION_OPT_OUT_ALL_SCOPE, NOTIFICATION_OPT_OUT_SCOPE_PATTERN, NotificationDelivery, NotificationDeliveryCollection, NotificationOptOut, NotificationOptOutCollection, NotificationOptOutDeniedError, NotificationOptOutService, NotificationOutboxDeniedError, NotificationOutboxService, NotificationsRecipe, PROFILE_NOTIFICATION_POLICY_PREFIX, PersonaMessageRoute, PersonaMessageRouteCollection, PersonaMessagingService, SEND_MESSAGES_PERMISSION, SlackAccount, SlackMessage, SlackRecipe, SlackSender, TelegramAccount, TelegramSender, Tweet, TweetSender, TwitterAccount, USER_NOTIFICATION_SEVERITIES, UserNotification, UserNotificationCollection, UserNotificationService, Whitelist, WhitelistCollection, ZulipAccount, ZulipSender, assertMailAccess, assertMessagingPermission, assertNotificationProfileRecipientSchema, auditMailAction, buildNotificationLink, canAccessMailAccount, configureMailAccess, configureMailSendApprovals, decideMailAccess, deniedMailAccountIds, effectiveAgentSendPolicy, enqueueDueMailSyncs, enqueueMailSync, ensureBuiltinMessagingProvidersRegistered, ensureMessagingPermissionsRegistered, getMessagingProvider, isMailScope, isPersonMailPrincipal, isValidNotificationOptOutScope, listMessagingProviders, mailScopePermission, mailSendBindingHash, mailSyncDedupeKey, messageSendTransport, messagingPrincipalFromPermissions, migrateNotificationProfileRecipients, normalizeCorrespondentAddress, notificationDeliveryCorrelationId, notificationDeliveryMessageId, optOutSuppression, planNotificationProfileRecipients, profileNotificationPolicy, readableMailAccounts, registerMessagingProvider, resetMailAccess, resetMailSendApprovals, resolveMailPrincipal, runWithMailSystemAccess, seedMessagesRolePermissions, stampHandledBy, threadHandledBy };
4353
4449
 
4354
4450
  //# sourceMappingURL=index.js.map