@happyvertical/smrt-messages 0.70.3 → 0.71.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/AGENTS.md +9 -3
  2. package/README.md +4 -2
  3. package/agents/attachment-storage.md +41 -0
  4. package/dist/attachment-storage.d.ts +50 -0
  5. package/dist/attachment-storage.d.ts.map +1 -0
  6. package/dist/chunks/{AttachmentCollection-Di2aRb2k.js → AttachmentCollection-C14dERNK.js} +31 -37
  7. package/dist/chunks/AttachmentCollection-C14dERNK.js.map +1 -0
  8. package/dist/chunks/{Email-tEYH6ZRw.js → Email-Bd1lCLiC.js} +6 -6
  9. package/dist/chunks/{Email-tEYH6ZRw.js.map → Email-Bd1lCLiC.js.map} +1 -1
  10. package/dist/chunks/{EmailAccountCollection-DWo_a-X5.js → EmailAccountCollection-Clv4kruh.js} +108 -37
  11. package/dist/chunks/EmailAccountCollection-Clv4kruh.js.map +1 -0
  12. package/dist/chunks/{EmailCollection-_Z2JY26I.js → EmailCollection-CiZJ5I2l.js} +3 -3
  13. package/dist/chunks/{EmailCollection-_Z2JY26I.js.map → EmailCollection-CiZJ5I2l.js.map} +1 -1
  14. package/dist/chunks/{EmailFolder-TyoFZVcC.js → EmailFolder-Dvb6M-d_.js} +6 -6
  15. package/dist/chunks/{EmailFolder-TyoFZVcC.js.map → EmailFolder-Dvb6M-d_.js.map} +1 -1
  16. package/dist/chunks/{EmailFolderCollection-CFtttkx6.js → EmailFolderCollection-BR3yh7sp.js} +2 -2
  17. package/dist/chunks/{EmailFolderCollection-CFtttkx6.js.map → EmailFolderCollection-BR3yh7sp.js.map} +1 -1
  18. package/dist/chunks/{EmailSender-bHwAYzBO.js → EmailSender-B-c7mxbY.js} +10 -4
  19. package/dist/chunks/EmailSender-B-c7mxbY.js.map +1 -0
  20. package/dist/chunks/{Message-DC877Gl7.js → Message-CGyhd0kh.js} +6 -6
  21. package/dist/chunks/{Message-DC877Gl7.js.map → Message-CGyhd0kh.js.map} +1 -1
  22. package/dist/chunks/{MessageCollection-yZ6RyAtB.js → MessageCollection-DRCtm5z2.js} +2 -2
  23. package/dist/chunks/{MessageCollection-yZ6RyAtB.js.map → MessageCollection-DRCtm5z2.js.map} +1 -1
  24. package/dist/chunks/{MessagingEndpointCollection-CNwpv_ZW.js → MessagingEndpointCollection-Cju_NnJZ.js} +2 -2
  25. package/dist/chunks/{MessagingEndpointCollection-CNwpv_ZW.js.map → MessagingEndpointCollection-Cju_NnJZ.js.map} +1 -1
  26. package/dist/collections/AttachmentCollection.d.ts.map +1 -1
  27. package/dist/connect.js +1 -1
  28. package/dist/host.browser.d.ts +2 -0
  29. package/dist/host.browser.d.ts.map +1 -1
  30. package/dist/host.browser.js +3 -1
  31. package/dist/host.browser.js.map +1 -1
  32. package/dist/host.d.ts +20 -0
  33. package/dist/host.d.ts.map +1 -1
  34. package/dist/host.js +39 -1
  35. package/dist/host.js.map +1 -1
  36. package/dist/index.d.ts +1 -0
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +17 -17
  39. package/dist/index.js.map +1 -1
  40. package/dist/manifest.json +1 -1
  41. package/dist/models/Attachment.d.ts +13 -8
  42. package/dist/models/Attachment.d.ts.map +1 -1
  43. package/dist/send-approval.d.ts.map +1 -1
  44. package/dist/senders/EmailSender.d.ts.map +1 -1
  45. package/dist/smrt-knowledge.json +11 -5
  46. package/dist/smrt-knowledge.okf.md +9 -5
  47. package/package.json +12 -12
  48. package/dist/chunks/AttachmentCollection-Di2aRb2k.js.map +0 -1
  49. package/dist/chunks/EmailAccountCollection-DWo_a-X5.js.map +0 -1
  50. package/dist/chunks/EmailSender-bHwAYzBO.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"EmailSender-bHwAYzBO.js","names":[],"sources":["../../src/senders/EmailSender.ts"],"sourcesContent":["import {\n assertProtectedEmailAdmission,\n assertProtectedEmailHandoff,\n ProtectedNotificationHandoffError,\n} from '../protected-notification-handoff.js';\n/**\n * EmailSender — sends email messages via the SDK EmailClient\n */\n\nimport type { Attachment, EmailClient } from '@happyvertical/email';\nimport type { Email } from '../models/Email';\nimport type { EmailAccount } from '../models/EmailAccount';\nimport { assertApprovedAttachments } from '../send-approval.js';\nimport type {\n MessageSenderInterface,\n MessageSendResult,\n SendEmailOptions,\n} from '../types';\n\nexport class EmailSender implements MessageSenderInterface {\n readonly providerType = 'email';\n private client: EmailClient;\n private account: EmailAccount;\n\n constructor(client: EmailClient, account: EmailAccount) {\n this.client = client;\n this.account = account;\n }\n\n isReady(): boolean {\n return this.client.isConnected();\n }\n\n async send(\n message: Email,\n options?: SendEmailOptions,\n ): Promise<MessageSendResult> {\n const toAddresses = message.getToAddresses();\n const ccAddresses = message.getCcAddresses();\n const bccAddresses = message.getBccAddresses();\n\n // Resolve every attachment before anything reaches the transport: a file\n // that cannot be read fails the send instead of leaving silently (#3808).\n let attachments: Attachment[];\n try {\n await assertProtectedEmailAdmission(message, options);\n attachments = await this.collectAttachments(message, options);\n } catch (error) {\n return {\n success: false,\n error: error instanceof Error ? error.message : String(error),\n sentAt: new Date(),\n };\n }\n\n const emailMessage = {\n from: {\n name: message.fromName || this.account.name,\n address: message.fromAddress || this.account.email,\n },\n to: toAddresses.map((r) => ({\n name: r.name,\n address: r.address,\n })),\n cc:\n ccAddresses.length > 0\n ? ccAddresses.map((r) => ({ name: r.name, address: r.address }))\n : undefined,\n bcc:\n bccAddresses.length > 0\n ? bccAddresses.map((r) => ({ name: r.name, address: r.address }))\n : undefined,\n subject: message.subject,\n text: message.textBody || message.body,\n html: message.htmlBody || undefined,\n inReplyTo: message.inReplyTo || undefined,\n attachments: attachments.length > 0 ? attachments : undefined,\n };\n\n try {\n await assertProtectedEmailHandoff(\n message,\n attachments as unknown as NonNullable<SendEmailOptions['attachments']>,\n options,\n emailMessage,\n );\n const result = await this.client.send(emailMessage);\n\n return {\n success: true,\n providerMessageId: result.messageId,\n accepted: result.accepted,\n rejected: result.rejected,\n providerResponse: { response: result.response },\n sentAt: new Date(),\n };\n } catch (error) {\n return {\n success: false,\n error: error instanceof Error ? error.message : String(error),\n ...(error instanceof ProtectedNotificationHandoffError ||\n isDefiniteSendRejection(error)\n ? {}\n : { outcomeUnknown: true }),\n sentAt: new Date(),\n };\n }\n }\n\n /**\n * The message's stored `Attachment` rows followed by the send-time bytes.\n *\n * Stored rows are listed through the message's own options, so the lookup\n * runs under the same tenant context as the message. A row's file is read\n * through `Attachment.readContent()`, the package's one attachment-reading\n * seam, so the bytes are handed to the transport rather than a path it\n * would have to resolve itself.\n */\n private async collectAttachments(\n message: Email,\n options?: SendEmailOptions,\n ): Promise<Attachment[]> {\n const resolved: Attachment[] = [];\n const handed: Parameters<typeof assertApprovedAttachments>[1] = [];\n\n // Only a message backed by a row can own attachment rows; an unsaved\n // draft sent directly through the sender has none to look up.\n const stored = message.isPersisted ? await message.getAttachments() : [];\n for (const attachment of stored) {\n if (\n message.tenantId &&\n attachment.tenantId &&\n attachment.tenantId !== message.tenantId\n ) {\n throw new Error(\n `Attachment \"${attachment.filename}\" belongs to another tenant than its message.`,\n );\n }\n if (!attachment.filePath) {\n throw new Error(\n `Attachment \"${attachment.filename}\" has no stored file to send` +\n (attachment.sourceUrl\n ? ' (a sourceUrl is not fetched at send time).'\n : '.'),\n );\n }\n const content = await attachment.readContent();\n if (!content) {\n throw new Error(\n `Attachment \"${attachment.filename}\" could not be read from \"${attachment.filePath}\": ` +\n 'the file is missing or unreadable, or the files SDK is not loaded ' +\n '(see Attachment.readContent()).',\n );\n }\n handed.push({ row: attachment, content });\n resolved.push({\n filename: attachment.filename,\n contentType: attachment.contentType || 'application/octet-stream',\n size: content.length,\n content: Buffer.from(content),\n contentId: attachment.contentId || undefined,\n contentDisposition: attachment.contentDisposition,\n });\n }\n\n // A send an approval released carries exactly the approved files.\n assertApprovedAttachments(message, handed);\n\n for (const attachment of options?.attachments ?? []) {\n if (!attachment.filename) {\n throw new Error('A send-time attachment needs a filename.');\n }\n if (!attachment.content) {\n throw new Error(\n `Send-time attachment \"${attachment.filename}\" has no content.`,\n );\n }\n // Own the bytes handed to the SDK so callers cannot mutate the approved\n // document while an asynchronous provider send is in flight.\n const content = Buffer.from(attachment.content);\n resolved.push({\n filename: attachment.filename,\n contentType: attachment.contentType || 'application/octet-stream',\n size: content.length,\n content,\n contentId: attachment.contentId,\n contentDisposition: attachment.contentDisposition ?? 'attachment',\n });\n }\n\n return resolved;\n }\n}\n\n/** Error codes the SDK email clients use for a send that was refused. */\nconst DEFINITE_EMAIL_ERROR_CODES = new Set([\n 'AUTHENTICATION_ERROR',\n 'AUTHORIZATION_ERROR',\n 'INVALID_MESSAGE',\n 'ATTACHMENT_ERROR',\n]);\n\n/** Socket errors raised before any connection to the server existed. */\nconst NEVER_CONNECTED_CODES = new Set([\n 'ECONNREFUSED',\n 'ENOTFOUND',\n 'EHOSTUNREACH',\n 'EAI_AGAIN',\n]);\n\n/**\n * Whether a provider send error proves the message was not accepted: the\n * server answered with an SMTP reply code, the SDK classified it as an\n * authentication/validation failure, a send error accepted no recipient, or\n * the connection was never made. Anything else (a timeout, a reset\n * connection, an unclassified error) may have happened after the server took\n * the message, so its outcome is unknown.\n */\nexport function isDefiniteSendRejection(error: unknown): boolean {\n if (!error || typeof error !== 'object') return false;\n const candidates = [error, (error as { cause?: unknown }).cause].filter(\n (value): value is Record<string, unknown> =>\n !!value && typeof value === 'object',\n );\n for (const candidate of candidates) {\n if (typeof candidate.responseCode === 'number') return true;\n if (typeof candidate.code === 'string') {\n if (DEFINITE_EMAIL_ERROR_CODES.has(candidate.code)) return true;\n if (NEVER_CONNECTED_CODES.has(candidate.code)) return true;\n }\n }\n const sendError = error as { code?: unknown; accepted?: unknown };\n return (\n sendError.code === 'SEND_ERROR' &&\n Array.isArray(sendError.accepted) &&\n sendError.accepted.length === 0\n );\n}\n"],"mappings":";;;;;;;;AAmBO,IAAM,cAAN,MAAoD;CAChD,eAAe;CAChB;CACA;CAER,YAAY,QAAqB,S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