@happyvertical/smrt-messages 0.62.10 → 0.62.12
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 +18 -1
- package/dist/chunks/{AttachmentCollection-DqZ-ReHp.js → AttachmentCollection-gv5YpGPo.js} +4 -4
- package/dist/chunks/{AttachmentCollection-DqZ-ReHp.js.map → AttachmentCollection-gv5YpGPo.js.map} +1 -1
- package/dist/chunks/{Email-PGHFnLSi.js → Email---ifczUW.js} +6 -6
- package/dist/chunks/{Email-PGHFnLSi.js.map → Email---ifczUW.js.map} +1 -1
- package/dist/chunks/EmailAccountCollection-DkvT4tdP.js +1992 -0
- package/dist/chunks/EmailAccountCollection-DkvT4tdP.js.map +1 -0
- package/dist/chunks/{EmailCollection-C7MOWGLe.js → EmailCollection-CHINTmyA.js} +3 -3
- package/dist/chunks/{EmailCollection-C7MOWGLe.js.map → EmailCollection-CHINTmyA.js.map} +1 -1
- package/dist/chunks/{EmailFolder-BE9Xx2pw.js → EmailFolder-C_H8u6bS.js} +6 -6
- package/dist/chunks/{EmailFolder-BE9Xx2pw.js.map → EmailFolder-C_H8u6bS.js.map} +1 -1
- package/dist/chunks/{EmailFolderCollection-CHAKFybY.js → EmailFolderCollection-B83qLC-c.js} +2 -2
- package/dist/chunks/{EmailFolderCollection-CHAKFybY.js.map → EmailFolderCollection-B83qLC-c.js.map} +1 -1
- package/dist/chunks/{Message-8L3St6NF.js → Message-Ccqg6BLO.js} +6 -6
- package/dist/chunks/{Message-8L3St6NF.js.map → Message-Ccqg6BLO.js.map} +1 -1
- package/dist/chunks/{MessageCollection-CNkx4JVp.js → MessageCollection-BnHCLi1Q.js} +2 -2
- package/dist/chunks/{MessageCollection-CNkx4JVp.js.map → MessageCollection-BnHCLi1Q.js.map} +1 -1
- package/dist/chunks/{MessagingEndpointCollection-BA-Zzk8o.js → MessagingEndpointCollection-CHzGhkeL.js} +2 -2
- package/dist/chunks/{MessagingEndpointCollection-BA-Zzk8o.js.map → MessagingEndpointCollection-CHzGhkeL.js.map} +1 -1
- package/dist/connect.js +1 -1
- package/dist/index.js +12 -11
- package/dist/index.js.map +1 -1
- package/dist/mail-sync-jobs.d.ts.map +1 -1
- package/dist/mail-sync.d.ts +16 -1
- package/dist/mail-sync.d.ts.map +1 -1
- package/dist/manifest.json +264 -18
- package/dist/models/EmailAccount.d.ts +24 -0
- package/dist/models/EmailAccount.d.ts.map +1 -1
- package/dist/smrt-knowledge.json +35 -5
- package/dist/smrt-knowledge.okf.md +2 -2
- package/dist/types.d.ts +8 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +11 -11
- package/dist/chunks/EmailAccountCollection-qe0Umrjz.js +0 -1944
- package/dist/chunks/EmailAccountCollection-qe0Umrjz.js.map +0 -1
|
@@ -0,0 +1,1992 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
|
|
2
|
+
import { createAccountSecretService, createHandoffContext, getCurrentTenant, queryGlobal, queryWithGlobals, withTenant } from "../host.js";
|
|
3
|
+
import { ObjectRegistry, SmrtCollection, SmrtObject, crossPackageRef, field, smrt } from "@happyvertical/smrt-core";
|
|
4
|
+
import { registerPermissionDefinitions } from "@happyvertical/smrt-users/permission-registry";
|
|
5
|
+
import { TenantScoped, tenantId } from "@happyvertical/smrt-tenancy/decorators";
|
|
6
|
+
//#region src/__smrt-register__.ts
|
|
7
|
+
ObjectRegistry.registerPackageManifest(JSON.parse(`{"version":"1.0.0","timestamp":0,"packageName":"@happyvertical/smrt-messages","packageVersion":"0.62.12","objects":{"@happyvertical/smrt-messages:AccountCollection":{"name":"accountcollection","className":"AccountCollection","qualifiedName":"@happyvertical/smrt-messages:AccountCollection","collection":"accounts","filePath":"src/collections/AccountCollection.ts","packageName":"@happyvertical/smrt-messages","fields":{},"methods":{"getActive":{"name":"getActive","async":true,"parameters":[],"returnType":"Promise<Account[]>","isStatic":false,"isPublic":true},"getInactive":{"name":"getInactive","async":true,"parameters":[],"returnType":"Promise<Account[]>","isStatic":false,"isPublic":true},"getByProviderType":{"name":"getByProviderType","async":true,"parameters":[{"name":"providerType","type":"string","optional":false}],"returnType":"Promise<Account[]>","isStatic":false,"isPublic":true},"getByType":{"name":"getByType","async":true,"parameters":[{"name":"accountType","type":"string","optional":false}],"returnType":"Promise<Account[]>","isStatic":false,"isPublic":true},"search":{"name":"search","async":true,"parameters":[{"name":"query","type":"string","optional":false},{"name":"filters","type":"AccountSearchFilters","optional":true}],"returnType":"Promise<Account[]>","isStatic":false,"isPublic":true},"getStats":{"name":"getStats","async":true,"parameters":[],"returnType":"Promise<object>","isStatic":false,"isPublic":true},"findByTenant":{"name":"findByTenant","async":true,"parameters":[{"name":"tenantId","type":"string","optional":false}],"returnType":"Promise<Account[]>","isStatic":false,"isPublic":true},"findGlobal":{"name":"findGlobal","async":true,"parameters":[],"returnType":"Promise<Account[]>","isStatic":false,"isPublic":true},"findWithGlobals":{"name":"findWithGlobals","async":true,"parameters":[{"name":"tenantId","type":"string","optional":false}],"returnType":"Promise<Account[]>","isStatic":false,"isPublic":true}},"decoratorConfig":{"api":{"include":["list","get"]},"mcp":{"include":["list","get"]},"cli":{"include":["list","get"]}},"extends":"SmrtCollection","extendsTypeArg":"Account","exportName":"AccountCollection","collectionExportName":"AccountCollectionCollection","collectionOf":"@happyvertical/smrt-messages:Account","inheritedExposure":["api","mcp","cli"],"schema":{"tableName":"accounts","ddl":"CREATE TABLE IF NOT EXISTS \\"accounts\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"_meta_type\\" TEXT NOT NULL,\\n \\"_meta_data\\" JSON,\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"name\\" TEXT,\\n \\"provider_type\\" TEXT,\\n \\"channel_type\\" TEXT,\\n \\"credential_secret_id\\" TEXT,\\n \\"is_active\\" BOOLEAN DEFAULT TRUE,\\n \\"owner_user_id\\" UUID,\\n \\"label\\" TEXT,\\n \\"connection_status\\" TEXT,\\n \\"status_message\\" TEXT,\\n \\"last_sync_at\\" TIMESTAMP,\\n \\"settings\\" TEXT,\\n \\"configuration\\" TEXT,\\n \\"email\\" TEXT,\\n \\"sync_interval_minutes\\" INTEGER DEFAULT 60,\\n \\"sync_cursor\\" TEXT,\\n \\"backfill_since\\" TIMESTAMP,\\n \\"cursor_horizon\\" TIMESTAMP,\\n \\"last_sync_error\\" TEXT,\\n \\"backlog\\" BOOLEAN DEFAULT FALSE,\\n \\"workspace_id\\" TEXT,\\n \\"workspace_name\\" TEXT,\\n \\"bot_user_id\\" TEXT,\\n \\"handle\\" TEXT,\\n \\"twitter_user_id\\" TEXT\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"_meta_type":{"type":"TEXT","notNull":true},"_meta_data":{"type":"JSON","notNull":false},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false},"name":{"type":"TEXT","notNull":false},"provider_type":{"type":"TEXT","notNull":false},"channel_type":{"type":"TEXT","notNull":false},"credential_secret_id":{"type":"TEXT","notNull":false},"is_active":{"type":"BOOLEAN","notNull":false,"default":true},"owner_user_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false},"label":{"type":"TEXT","notNull":false},"connection_status":{"type":"TEXT","notNull":false},"status_message":{"type":"TEXT","notNull":false},"last_sync_at":{"type":"TIMESTAMP","notNull":false},"settings":{"type":"TEXT","notNull":false},"configuration":{"type":"TEXT","notNull":false},"email":{"type":"TEXT","notNull":false},"sync_interval_minutes":{"type":"INTEGER","notNull":false,"default":60},"sync_cursor":{"type":"TEXT","notNull":false},"backfill_since":{"type":"TIMESTAMP","notNull":false},"cursor_horizon":{"type":"TIMESTAMP","notNull":false},"last_sync_error":{"type":"TEXT","notNull":false},"backlog":{"type":"BOOLEAN","notNull":false,"default":false},"workspace_id":{"type":"TEXT","notNull":false},"workspace_name":{"type":"TEXT","notNull":false},"bot_user_id":{"type":"TEXT","notNull":false},"handle":{"type":"TEXT","notNull":false},"twitter_user_id":{"type":"TEXT","notNull":false}},"indexes":[{"name":"accounts_slug_context_meta_type_idx","columns":["tenant_id","slug","context","_meta_type"],"unique":true,"nullsNotDistinct":true},{"name":"accounts_meta_type_idx","columns":["_meta_type"]},{"name":"accounts_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"accounts_owner_user_id_idx","columns":["owner_user_id"]}],"checks":[{"name":"smrt_ck_81229bbfe8e3","columns":["backlog"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:EmailAccount') OR \\"backlog\\" IS NOT NULL"},{"name":"smrt_ck_1f9c5f0ee488","columns":["sync_interval_minutes"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:EmailAccount') OR \\"sync_interval_minutes\\" IS NOT NULL"}],"version":"f48d7a23"},"importPath":"@happyvertical/smrt-messages"},"@happyvertical/smrt-messages:AttachmentCollection":{"name":"attachmentcollection","className":"AttachmentCollection","qualifiedName":"@happyvertical/smrt-messages:AttachmentCollection","collection":"attachments","filePath":"src/collections/AttachmentCollection.ts","packageName":"@happyvertical/smrt-messages","fields":{},"methods":{"backfillAccountIds":{"name":"backfillAccountIds","async":true,"parameters":[],"returnType":"Promise<number>","isStatic":false,"isPublic":true},"getByMessage":{"name":"getByMessage","async":true,"parameters":[{"name":"messageId","type":"string","optional":false}],"returnType":"Promise<Attachment[]>","isStatic":false,"isPublic":true},"getByContentType":{"name":"getByContentType","async":true,"parameters":[{"name":"contentType","type":"string","optional":false}],"returnType":"Promise<Attachment[]>","isStatic":false,"isPublic":true},"getImages":{"name":"getImages","async":true,"parameters":[{"name":"messageId","type":"string","optional":true}],"returnType":"Promise<Attachment[]>","isStatic":false,"isPublic":true},"getPdfs":{"name":"getPdfs","async":true,"parameters":[{"name":"messageId","type":"string","optional":true}],"returnType":"Promise<Attachment[]>","isStatic":false,"isPublic":true},"getInline":{"name":"getInline","async":true,"parameters":[{"name":"messageId","type":"string","optional":false}],"returnType":"Promise<Attachment[]>","isStatic":false,"isPublic":true},"getRegular":{"name":"getRegular","async":true,"parameters":[{"name":"messageId","type":"string","optional":false}],"returnType":"Promise<Attachment[]>","isStatic":false,"isPublic":true},"getWithExternalFiles":{"name":"getWithExternalFiles","async":true,"parameters":[],"returnType":"Promise<Attachment[]>","isStatic":false,"isPublic":true},"getTotalSize":{"name":"getTotalSize","async":true,"parameters":[{"name":"messageId","type":"string","optional":false}],"returnType":"Promise<number>","isStatic":false,"isPublic":true},"getLargest":{"name":"getLargest","async":true,"parameters":[{"name":"limit","type":"any","optional":true}],"returnType":"Promise<Attachment[]>","isStatic":false,"isPublic":true},"searchByFilename":{"name":"searchByFilename","async":true,"parameters":[{"name":"query","type":"string","optional":false}],"returnType":"Promise<Attachment[]>","isStatic":false,"isPublic":true},"getByExtension":{"name":"getByExtension","async":true,"parameters":[{"name":"extension","type":"string","optional":false}],"returnType":"Promise<Attachment[]>","isStatic":false,"isPublic":true},"getStats":{"name":"getStats","async":true,"parameters":[],"returnType":"Promise<object>","isStatic":false,"isPublic":true},"deleteByMessage":{"name":"deleteByMessage","async":true,"parameters":[{"name":"messageId","type":"string","optional":false}],"returnType":"Promise<number>","isStatic":false,"isPublic":true},"findByTenant":{"name":"findByTenant","async":true,"parameters":[{"name":"tenantId","type":"string","optional":false}],"returnType":"Promise<Attachment[]>","isStatic":false,"isPublic":true},"findGlobal":{"name":"findGlobal","async":true,"parameters":[],"returnType":"Promise<Attachment[]>","isStatic":false,"isPublic":true},"findWithGlobals":{"name":"findWithGlobals","async":true,"parameters":[{"name":"tenantId","type":"string","optional":false}],"returnType":"Promise<Attachment[]>","isStatic":false,"isPublic":true}},"decoratorConfig":{"api":{"include":["list","get","create","delete"]},"mcp":{"include":["list","get"]}},"extends":"SmrtCollection","extendsTypeArg":"Attachment","exportName":"AttachmentCollection","collectionExportName":"AttachmentCollectionCollection","collectionOf":"@happyvertical/smrt-messages:Attachment","inheritedExposure":["api","mcp"],"schema":{"tableName":"attachments","ddl":"CREATE TABLE IF NOT EXISTS \\"attachments\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"message_id\\" UUID,\\n \\"account_id\\" UUID,\\n \\"filename\\" TEXT,\\n \\"content_type\\" TEXT,\\n \\"size\\" INTEGER NOT NULL DEFAULT 0,\\n \\"content_id\\" TEXT,\\n \\"content_disposition\\" TEXT DEFAULT 'attachment',\\n \\"file_path\\" TEXT,\\n \\"source_url\\" TEXT\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false,"unique":false},"message_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"messages","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"account_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"accounts","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"filename":{"type":"TEXT","notNull":false,"unique":false},"content_type":{"type":"TEXT","notNull":false,"unique":false},"size":{"type":"INTEGER","notNull":true,"unique":false,"default":0},"content_id":{"type":"TEXT","notNull":false,"unique":false},"content_disposition":{"type":"TEXT","notNull":false,"unique":false,"default":"attachment"},"file_path":{"type":"TEXT","notNull":false,"unique":false},"source_url":{"type":"TEXT","notNull":false,"unique":false}},"indexes":[{"name":"attachments_slug_context_idx","columns":["tenant_id","slug","context"],"unique":true,"nullsNotDistinct":true},{"name":"attachments_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"attachments_message_id_idx","columns":["message_id"]},{"name":"attachments_account_id_idx","columns":["account_id"]}],"version":"3f32531c"},"importPath":"@happyvertical/smrt-messages"},"@happyvertical/smrt-messages:BlacklistCollection":{"name":"blacklistcollection","className":"BlacklistCollection","qualifiedName":"@happyvertical/smrt-messages:BlacklistCollection","collection":"blacklists","filePath":"src/collections/BlacklistCollection.ts","packageName":"@happyvertical/smrt-messages","fields":{},"methods":{"isBlacklisted":{"name":"isBlacklisted","async":true,"parameters":[{"name":"email","type":"string","optional":false}],"returnType":"Promise<boolean>","isStatic":false,"isPublic":true},"getMatchingEntry":{"name":"getMatchingEntry","async":true,"parameters":[{"name":"email","type":"string","optional":false}],"returnType":"Promise<Blacklist | null>","isStatic":false,"isPublic":true}},"decoratorConfig":{"api":{"include":["list","get","create","update","delete"]}},"extends":"SmrtCollection","extendsTypeArg":"Blacklist","exportName":"BlacklistCollection","collectionExportName":"BlacklistCollectionCollection","collectionOf":"@happyvertical/smrt-messages:Blacklist","inheritedExposure":["api"],"schema":{"tableName":"blacklists","ddl":"CREATE TABLE IF NOT EXISTS \\"blacklists\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"pattern\\" TEXT DEFAULT '',\\n \\"type\\" TEXT DEFAULT 'email',\\n \\"reason\\" TEXT DEFAULT '',\\n \\"auto_archive\\" BOOLEAN DEFAULT TRUE,\\n \\"tenant_id\\" UUID NOT NULL\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"pattern":{"type":"TEXT","notNull":false,"unique":false,"default":""},"type":{"type":"TEXT","notNull":false,"unique":false,"default":"email"},"reason":{"type":"TEXT","notNull":false,"unique":false,"default":""},"auto_archive":{"type":"BOOLEAN","notNull":false,"unique":false,"default":true},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false}},"indexes":[{"name":"blacklists_slug_context_idx","columns":["tenant_id","slug","context"],"unique":true},{"name":"blacklists_tenant_id_created_at_idx","columns":["tenant_id","created_at"]}],"version":"478c8724"},"importPath":"@happyvertical/smrt-messages"},"@happyvertical/smrt-messages:EmailAccountCollection":{"name":"emailaccountcollection","className":"EmailAccountCollection","qualifiedName":"@happyvertical/smrt-messages:EmailAccountCollection","collection":"accounts","filePath":"src/collections/EmailAccountCollection.ts","packageName":"@happyvertical/smrt-messages","fields":{},"methods":{"getActive":{"name":"getActive","async":true,"parameters":[],"returnType":"Promise<EmailAccount[]>","isStatic":false,"isPublic":true},"getInactive":{"name":"getInactive","async":true,"parameters":[],"returnType":"Promise<EmailAccount[]>","isStatic":false,"isPublic":true},"getByProviderType":{"name":"getByProviderType","async":true,"parameters":[{"name":"providerType","type":"string","optional":false}],"returnType":"Promise<EmailAccount[]>","isStatic":false,"isPublic":true},"getByType":{"name":"getByType","async":true,"parameters":[{"name":"accountType","type":"string","optional":false}],"returnType":"Promise<Account[]>","isStatic":false,"isPublic":true},"search":{"name":"search","async":true,"parameters":[{"name":"query","type":"string","optional":false},{"name":"filters","type":"EmailAccountSearchFilters","optional":true}],"returnType":"Promise<EmailAccount[]>","isStatic":false,"isPublic":true},"getStats":{"name":"getStats","async":true,"parameters":[],"returnType":"Promise<object>","isStatic":false,"isPublic":true},"findByTenant":{"name":"findByTenant","async":true,"parameters":[{"name":"tenantId","type":"string","optional":false}],"returnType":"Promise<EmailAccount[]>","isStatic":false,"isPublic":true},"findGlobal":{"name":"findGlobal","async":true,"parameters":[],"returnType":"Promise<EmailAccount[]>","isStatic":false,"isPublic":true},"findWithGlobals":{"name":"findWithGlobals","async":true,"parameters":[{"name":"tenantId","type":"string","optional":false}],"returnType":"Promise<EmailAccount[]>","isStatic":false,"isPublic":true},"getByEmail":{"name":"getByEmail","async":true,"parameters":[{"name":"email","type":"string","optional":false}],"returnType":"Promise<EmailAccount | null>","isStatic":false,"isPublic":true},"getByEmailProviderType":{"name":"getByEmailProviderType","async":true,"parameters":[{"name":"providerType","type":"ProviderType","optional":false}],"returnType":"Promise<EmailAccount[]>","isStatic":false,"isPublic":true},"getNeedingSync":{"name":"getNeedingSync","async":true,"parameters":[{"name":"maxAgeMinutes","type":"any","optional":true}],"returnType":"Promise<EmailAccount[]>","isStatic":false,"isPublic":true},"searchEmailAccounts":{"name":"searchEmailAccounts","async":true,"parameters":[{"name":"query","type":"string","optional":false},{"name":"filters","type":"EmailAccountSearchFilters","optional":true}],"returnType":"Promise<EmailAccount[]>","isStatic":false,"isPublic":true},"syncAll":{"name":"syncAll","async":true,"parameters":[{"name":"options","type":"SyncOptions","optional":true}],"returnType":"Promise<Map<string, object>>","isStatic":false,"isPublic":true},"getTotalUnreadCount":{"name":"getTotalUnreadCount","async":true,"parameters":[],"returnType":"Promise<number>","isStatic":false,"isPublic":true},"getEmailStats":{"name":"getEmailStats","async":true,"parameters":[],"returnType":"Promise<object>","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableName":"accounts","api":{"include":["list","get"]},"mcp":{"include":["list","get"]},"cli":{"include":["list","get"]}},"extends":"AccountCollection","exportName":"EmailAccountCollection","collectionExportName":"EmailAccountCollectionCollection","collectionOf":"@happyvertical/smrt-messages:EmailAccount","inheritedExposure":["api","mcp","cli"],"schema":{"tableName":"accounts","ddl":"CREATE TABLE IF NOT EXISTS \\"accounts\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"_meta_type\\" TEXT NOT NULL,\\n \\"_meta_data\\" JSON,\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"name\\" TEXT,\\n \\"provider_type\\" TEXT,\\n \\"channel_type\\" TEXT,\\n \\"credential_secret_id\\" TEXT,\\n \\"is_active\\" BOOLEAN DEFAULT TRUE,\\n \\"owner_user_id\\" UUID,\\n \\"label\\" TEXT,\\n \\"connection_status\\" TEXT,\\n \\"status_message\\" TEXT,\\n \\"last_sync_at\\" TIMESTAMP,\\n \\"settings\\" TEXT,\\n \\"configuration\\" TEXT,\\n \\"email\\" TEXT,\\n \\"sync_interval_minutes\\" INTEGER DEFAULT 60,\\n \\"sync_cursor\\" TEXT,\\n \\"backfill_since\\" TIMESTAMP,\\n \\"cursor_horizon\\" TIMESTAMP,\\n \\"last_sync_error\\" TEXT,\\n \\"backlog\\" BOOLEAN DEFAULT FALSE,\\n \\"workspace_id\\" TEXT,\\n \\"workspace_name\\" TEXT,\\n \\"bot_user_id\\" TEXT,\\n \\"handle\\" TEXT,\\n \\"twitter_user_id\\" TEXT\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"_meta_type":{"type":"TEXT","notNull":true},"_meta_data":{"type":"JSON","notNull":false},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false},"name":{"type":"TEXT","notNull":false},"provider_type":{"type":"TEXT","notNull":false},"channel_type":{"type":"TEXT","notNull":false},"credential_secret_id":{"type":"TEXT","notNull":false},"is_active":{"type":"BOOLEAN","notNull":false,"default":true},"owner_user_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false},"label":{"type":"TEXT","notNull":false},"connection_status":{"type":"TEXT","notNull":false},"status_message":{"type":"TEXT","notNull":false},"last_sync_at":{"type":"TIMESTAMP","notNull":false},"settings":{"type":"TEXT","notNull":false},"configuration":{"type":"TEXT","notNull":false},"email":{"type":"TEXT","notNull":false},"sync_interval_minutes":{"type":"INTEGER","notNull":false,"default":60},"sync_cursor":{"type":"TEXT","notNull":false},"backfill_since":{"type":"TIMESTAMP","notNull":false},"cursor_horizon":{"type":"TIMESTAMP","notNull":false},"last_sync_error":{"type":"TEXT","notNull":false},"backlog":{"type":"BOOLEAN","notNull":false,"default":false},"workspace_id":{"type":"TEXT","notNull":false},"workspace_name":{"type":"TEXT","notNull":false},"bot_user_id":{"type":"TEXT","notNull":false},"handle":{"type":"TEXT","notNull":false},"twitter_user_id":{"type":"TEXT","notNull":false}},"indexes":[{"name":"accounts_slug_context_meta_type_idx","columns":["tenant_id","slug","context","_meta_type"],"unique":true,"nullsNotDistinct":true},{"name":"accounts_meta_type_idx","columns":["_meta_type"]},{"name":"accounts_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"accounts_owner_user_id_idx","columns":["owner_user_id"]}],"checks":[{"name":"smrt_ck_81229bbfe8e3","columns":["backlog"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:EmailAccount') OR \\"backlog\\" IS NOT NULL"},{"name":"smrt_ck_1f9c5f0ee488","columns":["sync_interval_minutes"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:EmailAccount') OR \\"sync_interval_minutes\\" IS NOT NULL"}],"version":"f48d7a23"},"importPath":"@happyvertical/smrt-messages"},"@happyvertical/smrt-messages:EmailAttachmentCollection":{"name":"emailattachmentcollection","className":"EmailAttachmentCollection","qualifiedName":"@happyvertical/smrt-messages:EmailAttachmentCollection","collection":"emailattachments","filePath":"src/collections/EmailAttachmentCollection.ts","packageName":"@happyvertical/smrt-messages","fields":{},"methods":{"backfillAccountIds":{"name":"backfillAccountIds","async":true,"parameters":[],"returnType":"Promise<number>","isStatic":false,"isPublic":true},"getByMessage":{"name":"getByMessage","async":true,"parameters":[{"name":"messageId","type":"string","optional":false}],"returnType":"Promise<Attachment[]>","isStatic":false,"isPublic":true},"getByContentType":{"name":"getByContentType","async":true,"parameters":[{"name":"contentType","type":"string","optional":false}],"returnType":"Promise<Attachment[]>","isStatic":false,"isPublic":true},"getImages":{"name":"getImages","async":true,"parameters":[{"name":"emailId","type":"string","optional":true}],"returnType":"Promise<EmailAttachment[]>","isStatic":false,"isPublic":true},"getPdfs":{"name":"getPdfs","async":true,"parameters":[{"name":"emailId","type":"string","optional":true}],"returnType":"Promise<EmailAttachment[]>","isStatic":false,"isPublic":true},"getInline":{"name":"getInline","async":true,"parameters":[{"name":"emailId","type":"string","optional":false}],"returnType":"Promise<EmailAttachment[]>","isStatic":false,"isPublic":true},"getRegular":{"name":"getRegular","async":true,"parameters":[{"name":"emailId","type":"string","optional":false}],"returnType":"Promise<EmailAttachment[]>","isStatic":false,"isPublic":true},"getWithExternalFiles":{"name":"getWithExternalFiles","async":true,"parameters":[],"returnType":"Promise<Attachment[]>","isStatic":false,"isPublic":true},"getTotalSize":{"name":"getTotalSize","async":true,"parameters":[{"name":"messageId","type":"string","optional":false}],"returnType":"Promise<number>","isStatic":false,"isPublic":true},"getLargest":{"name":"getLargest","async":true,"parameters":[{"name":"limit","type":"any","optional":true}],"returnType":"Promise<Attachment[]>","isStatic":false,"isPublic":true},"searchByFilename":{"name":"searchByFilename","async":true,"parameters":[{"name":"query","type":"string","optional":false}],"returnType":"Promise<Attachment[]>","isStatic":false,"isPublic":true},"getByExtension":{"name":"getByExtension","async":true,"parameters":[{"name":"extension","type":"string","optional":false}],"returnType":"Promise<Attachment[]>","isStatic":false,"isPublic":true},"getStats":{"name":"getStats","async":true,"parameters":[],"returnType":"Promise<object>","isStatic":false,"isPublic":true},"deleteByMessage":{"name":"deleteByMessage","async":true,"parameters":[{"name":"messageId","type":"string","optional":false}],"returnType":"Promise<number>","isStatic":false,"isPublic":true},"findByTenant":{"name":"findByTenant","async":true,"parameters":[{"name":"tenantId","type":"string","optional":false}],"returnType":"Promise<EmailAttachment[]>","isStatic":false,"isPublic":true},"findGlobal":{"name":"findGlobal","async":true,"parameters":[],"returnType":"Promise<EmailAttachment[]>","isStatic":false,"isPublic":true},"findWithGlobals":{"name":"findWithGlobals","async":true,"parameters":[{"name":"tenantId","type":"string","optional":false}],"returnType":"Promise<EmailAttachment[]>","isStatic":false,"isPublic":true},"getByEmail":{"name":"getByEmail","async":true,"parameters":[{"name":"emailId","type":"string","optional":false}],"returnType":"Promise<EmailAttachment[]>","isStatic":false,"isPublic":true},"deleteByEmail":{"name":"deleteByEmail","async":true,"parameters":[{"name":"emailId","type":"string","optional":false}],"returnType":"Promise<number>","isStatic":false,"isPublic":true}},"decoratorConfig":{"api":{"include":["list","get","create","delete"]},"mcp":{"include":["list","get"]}},"extends":"AttachmentCollection","exportName":"EmailAttachmentCollection","collectionExportName":"EmailAttachmentCollectionCollection","collectionOf":"@happyvertical/smrt-messages:EmailAttachment","inheritedExposure":["api","mcp"],"schema":{"tableName":"email_attachments","ddl":"CREATE TABLE IF NOT EXISTS \\"email_attachments\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"message_id\\" UUID,\\n \\"account_id\\" UUID,\\n \\"filename\\" TEXT,\\n \\"content_type\\" TEXT,\\n \\"size\\" INTEGER NOT NULL DEFAULT 0,\\n \\"content_id\\" TEXT,\\n \\"content_disposition\\" TEXT DEFAULT 'attachment',\\n \\"file_path\\" TEXT,\\n \\"source_url\\" TEXT\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false,"unique":false},"message_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"messages","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"account_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"accounts","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"filename":{"type":"TEXT","notNull":false,"unique":false},"content_type":{"type":"TEXT","notNull":false,"unique":false},"size":{"type":"INTEGER","notNull":true,"unique":false,"default":0},"content_id":{"type":"TEXT","notNull":false,"unique":false},"content_disposition":{"type":"TEXT","notNull":false,"unique":false,"default":"attachment"},"file_path":{"type":"TEXT","notNull":false,"unique":false},"source_url":{"type":"TEXT","notNull":false,"unique":false}},"indexes":[{"name":"email_attachments_slug_context_idx","columns":["tenant_id","slug","context"],"unique":true,"nullsNotDistinct":true},{"name":"email_attachments_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"email_attachments_message_id_idx","columns":["message_id"]},{"name":"email_attachments_account_id_idx","columns":["account_id"]}],"version":"ebed0053"},"importPath":"@happyvertical/smrt-messages"},"@happyvertical/smrt-messages:EmailCollection":{"name":"emailcollection","className":"EmailCollection","qualifiedName":"@happyvertical/smrt-messages:EmailCollection","collection":"messages","filePath":"src/collections/EmailCollection.ts","packageName":"@happyvertical/smrt-messages","fields":{},"methods":{"search":{"name":"search","async":true,"parameters":[{"name":"query","type":"string","optional":false},{"name":"filters","type":"EmailSearchFilters","optional":true}],"returnType":"Promise<Email[]>","isStatic":false,"isPublic":true},"getByAccounts":{"name":"getByAccounts","async":true,"parameters":[{"name":"accountIds","type":"string[]","optional":false}],"returnType":"Promise<Message[]>","isStatic":false,"isPublic":true},"getByType":{"name":"getByType","async":true,"parameters":[{"name":"messageType","type":"string","optional":false}],"returnType":"Promise<Message[]>","isStatic":false,"isPublic":true},"getUnread":{"name":"getUnread","async":true,"parameters":[{"name":"accountId","type":"string","optional":true}],"returnType":"Promise<Email[]>","isStatic":false,"isPublic":true},"getFlagged":{"name":"getFlagged","async":true,"parameters":[{"name":"accountId","type":"string","optional":true}],"returnType":"Promise<Email[]>","isStatic":false,"isPublic":true},"getRecent":{"name":"getRecent","async":true,"parameters":[{"name":"limit","type":"any","optional":true},{"name":"accountId","type":"string","optional":true}],"returnType":"Promise<Email[]>","isStatic":false,"isPublic":true},"getByThread":{"name":"getByThread","async":true,"parameters":[{"name":"threadId","type":"string","optional":false}],"returnType":"Promise<Email[]>","isStatic":false,"isPublic":true},"markAllRead":{"name":"markAllRead","async":true,"parameters":[{"name":"messageIds","type":"string[]","optional":false}],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"getAccountStats":{"name":"getAccountStats","async":true,"parameters":[{"name":"accountId","type":"string","optional":false}],"returnType":"Promise<object>","isStatic":false,"isPublic":true},"getDrafts":{"name":"getDrafts","async":true,"parameters":[{"name":"accountId","type":"string","optional":true}],"returnType":"Promise<Message[]>","isStatic":false,"isPublic":true},"getSent":{"name":"getSent","async":true,"parameters":[{"name":"accountId","type":"string","optional":true}],"returnType":"Promise<Message[]>","isStatic":false,"isPublic":true},"getScheduled":{"name":"getScheduled","async":true,"parameters":[{"name":"accountId","type":"string","optional":true}],"returnType":"Promise<Message[]>","isStatic":false,"isPublic":true},"getFailedSends":{"name":"getFailedSends","async":true,"parameters":[{"name":"accountId","type":"string","optional":true}],"returnType":"Promise<Message[]>","isStatic":false,"isPublic":true},"getOutbox":{"name":"getOutbox","async":true,"parameters":[{"name":"accountId","type":"string","optional":true}],"returnType":"Promise<Message[]>","isStatic":false,"isPublic":true},"findByTenant":{"name":"findByTenant","async":true,"parameters":[{"name":"tenantId","type":"string","optional":false}],"returnType":"Promise<Email[]>","isStatic":false,"isPublic":true},"findGlobal":{"name":"findGlobal","async":true,"parameters":[],"returnType":"Promise<Email[]>","isStatic":false,"isPublic":true},"findWithGlobals":{"name":"findWithGlobals","async":true,"parameters":[{"name":"tenantId","type":"string","optional":false}],"returnType":"Promise<Email[]>","isStatic":false,"isPublic":true},"getByMessageId":{"name":"getByMessageId","async":true,"parameters":[{"name":"accountId","type":"string","optional":false},{"name":"messageId","type":"string","optional":false}],"returnType":"Promise<Email | null>","isStatic":false,"isPublic":true},"getByAccount":{"name":"getByAccount","async":true,"parameters":[{"name":"accountId","type":"string","optional":false}],"returnType":"Promise<Email[]>","isStatic":false,"isPublic":true},"getByFolder":{"name":"getByFolder","async":true,"parameters":[{"name":"folderId","type":"string","optional":false}],"returnType":"Promise<Email[]>","isStatic":false,"isPublic":true},"getWithAttachments":{"name":"getWithAttachments","async":true,"parameters":[{"name":"accountId","type":"string","optional":true}],"returnType":"Promise<Email[]>","isStatic":false,"isPublic":true},"countByFolder":{"name":"countByFolder","async":true,"parameters":[{"name":"folderId","type":"string","optional":false}],"returnType":"Promise<number>","isStatic":false,"isPublic":true},"countUnreadByFolder":{"name":"countUnreadByFolder","async":true,"parameters":[{"name":"folderId","type":"string","optional":false}],"returnType":"Promise<number>","isStatic":false,"isPublic":true},"countUnreadByAccount":{"name":"countUnreadByAccount","async":true,"parameters":[{"name":"accountId","type":"string","optional":false}],"returnType":"Promise<number>","isStatic":false,"isPublic":true},"searchEmails":{"name":"searchEmails","async":true,"parameters":[{"name":"query","type":"string","optional":false},{"name":"filters","type":"EmailSearchFilters","optional":true}],"returnType":"Promise<Email[]>","isStatic":false,"isPublic":true},"markFolderRead":{"name":"markFolderRead","async":true,"parameters":[{"name":"folderId","type":"string","optional":false}],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"deleteByFolder":{"name":"deleteByFolder","async":true,"parameters":[{"name":"folderId","type":"string","optional":false}],"returnType":"Promise<number>","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableName":"messages","api":{"include":["list","get","create","update","delete"]},"mcp":{"include":["list","get"]}},"extends":"MessageCollection","exportName":"EmailCollection","collectionExportName":"EmailCollectionCollection","collectionOf":"@happyvertical/smrt-messages:Email","inheritedExposure":["api","mcp"],"schema":{"tableName":"messages","ddl":"CREATE TABLE IF NOT EXISTS \\"messages\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"_meta_type\\" TEXT NOT NULL,\\n \\"_meta_data\\" JSON,\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"account_id\\" UUID,\\n \\"persona_id\\" UUID,\\n \\"endpoint_id\\" UUID,\\n \\"correlation_id\\" TEXT,\\n \\"thread_id\\" TEXT,\\n \\"subject\\" TEXT,\\n \\"body\\" TEXT,\\n \\"from_address\\" TEXT,\\n \\"from_name\\" TEXT,\\n \\"to_addresses\\" TEXT,\\n \\"date\\" TIMESTAMP,\\n \\"is_read\\" BOOLEAN DEFAULT FALSE,\\n \\"is_flagged\\" BOOLEAN DEFAULT FALSE,\\n \\"has_attachments\\" BOOLEAN DEFAULT FALSE,\\n \\"size\\" INTEGER DEFAULT 0,\\n \\"metadata\\" TEXT,\\n \\"send_status\\" TEXT DEFAULT 'draft',\\n \\"sent_at\\" TIMESTAMP,\\n \\"send_error\\" TEXT,\\n \\"retry_count\\" INTEGER DEFAULT 0,\\n \\"max_retries\\" INTEGER DEFAULT 3,\\n \\"scheduled_send_at\\" TIMESTAMP,\\n \\"in_reply_to_message_id\\" UUID,\\n \\"message_id\\" TEXT,\\n \\"in_reply_to\\" TEXT,\\n \\"provider_message_id\\" TEXT,\\n \\"cc_addresses\\" TEXT,\\n \\"bcc_addresses\\" TEXT,\\n \\"reply_to_address\\" TEXT,\\n \\"reply_to_name\\" TEXT,\\n \\"text_body\\" TEXT,\\n \\"html_body\\" TEXT,\\n \\"folder_id\\" TEXT,\\n \\"folder_path\\" TEXT,\\n \\"labels\\" TEXT,\\n \\"flags\\" TEXT,\\n \\"is_answered\\" BOOLEAN DEFAULT FALSE,\\n \\"is_draft\\" BOOLEAN DEFAULT FALSE,\\n \\"raw_message\\" TEXT,\\n \\"headers\\" TEXT,\\n \\"channel_id\\" TEXT,\\n \\"channel_name\\" TEXT,\\n \\"slack_ts\\" TEXT,\\n \\"slack_thread_ts\\" TEXT,\\n \\"reactions\\" TEXT,\\n \\"is_edited\\" BOOLEAN DEFAULT FALSE,\\n \\"message_type\\" TEXT,\\n \\"blocks\\" TEXT,\\n \\"tweet_id\\" TEXT,\\n \\"retweet_count\\" INTEGER DEFAULT 0,\\n \\"like_count\\" INTEGER DEFAULT 0,\\n \\"reply_count\\" INTEGER DEFAULT 0,\\n \\"is_retweet\\" BOOLEAN DEFAULT FALSE,\\n \\"is_reply\\" BOOLEAN DEFAULT FALSE,\\n \\"media_urls\\" TEXT,\\n \\"hashtags\\" TEXT,\\n \\"mentions\\" TEXT\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"_meta_type":{"type":"TEXT","notNull":true},"_meta_data":{"type":"JSON","notNull":false},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false},"account_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"foreignKey":{"table":"accounts","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"persona_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false},"endpoint_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"foreignKey":{"table":"messaging_endpoints","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"correlation_id":{"type":"TEXT","notNull":false},"thread_id":{"type":"TEXT","notNull":false},"subject":{"type":"TEXT","notNull":false},"body":{"type":"TEXT","notNull":false},"from_address":{"type":"TEXT","notNull":false},"from_name":{"type":"TEXT","notNull":false},"to_addresses":{"type":"TEXT","notNull":false},"date":{"type":"TIMESTAMP","notNull":false},"is_read":{"type":"BOOLEAN","notNull":false,"default":false},"is_flagged":{"type":"BOOLEAN","notNull":false,"default":false},"has_attachments":{"type":"BOOLEAN","notNull":false,"default":false},"size":{"type":"INTEGER","notNull":false,"default":0},"metadata":{"type":"TEXT","notNull":false},"send_status":{"type":"TEXT","notNull":false,"default":"draft"},"sent_at":{"type":"TIMESTAMP","notNull":false},"send_error":{"type":"TEXT","notNull":false},"retry_count":{"type":"INTEGER","notNull":false,"default":0},"max_retries":{"type":"INTEGER","notNull":false,"default":3},"scheduled_send_at":{"type":"TIMESTAMP","notNull":false},"in_reply_to_message_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"foreignKey":{"table":"messages","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"message_id":{"type":"TEXT","notNull":false},"in_reply_to":{"type":"TEXT","notNull":false},"provider_message_id":{"type":"TEXT","notNull":false},"cc_addresses":{"type":"TEXT","notNull":false},"bcc_addresses":{"type":"TEXT","notNull":false},"reply_to_address":{"type":"TEXT","notNull":false},"reply_to_name":{"type":"TEXT","notNull":false},"text_body":{"type":"TEXT","notNull":false},"html_body":{"type":"TEXT","notNull":false},"folder_id":{"type":"TEXT","notNull":false},"folder_path":{"type":"TEXT","notNull":false},"labels":{"type":"TEXT","notNull":false},"flags":{"type":"TEXT","notNull":false},"is_answered":{"type":"BOOLEAN","notNull":false,"default":false},"is_draft":{"type":"BOOLEAN","notNull":false,"default":false},"raw_message":{"type":"TEXT","notNull":false},"headers":{"type":"TEXT","notNull":false},"channel_id":{"type":"TEXT","notNull":false},"channel_name":{"type":"TEXT","notNull":false},"slack_ts":{"type":"TEXT","notNull":false},"slack_thread_ts":{"type":"TEXT","notNull":false},"reactions":{"type":"TEXT","notNull":false},"is_edited":{"type":"BOOLEAN","notNull":false,"default":false},"message_type":{"type":"TEXT","notNull":false},"blocks":{"type":"TEXT","notNull":false},"tweet_id":{"type":"TEXT","notNull":false},"retweet_count":{"type":"INTEGER","notNull":false,"default":0},"like_count":{"type":"INTEGER","notNull":false,"default":0},"reply_count":{"type":"INTEGER","notNull":false,"default":0},"is_retweet":{"type":"BOOLEAN","notNull":false,"default":false},"is_reply":{"type":"BOOLEAN","notNull":false,"default":false},"media_urls":{"type":"TEXT","notNull":false},"hashtags":{"type":"TEXT","notNull":false},"mentions":{"type":"TEXT","notNull":false}},"indexes":[{"name":"messages_slug_context_meta_type_idx","columns":["tenant_id","slug","context","_meta_type"],"unique":true,"nullsNotDistinct":true},{"name":"messages_meta_type_idx","columns":["_meta_type"]},{"name":"messages_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"messages_account_id_idx","columns":["account_id"]},{"name":"messages_persona_id_idx","columns":["persona_id"]},{"name":"messages_endpoint_id_idx","columns":["endpoint_id"]},{"name":"messages_in_reply_to_message_id_idx","columns":["in_reply_to_message_id"]}],"checks":[{"name":"smrt_ck_d0024f738cf4","columns":["is_answered"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:Email') OR \\"is_answered\\" IS NOT NULL"},{"name":"smrt_ck_0adcd2453c81","columns":["is_draft"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:Email') OR \\"is_draft\\" IS NOT NULL"},{"name":"smrt_ck_428e155c9609","columns":["is_edited"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:SlackMessage') OR \\"is_edited\\" IS NOT NULL"},{"name":"smrt_ck_a17af99e85e3","columns":["is_reply"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:Tweet') OR \\"is_reply\\" IS NOT NULL"},{"name":"smrt_ck_3e30563cba58","columns":["is_retweet"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:Tweet') OR \\"is_retweet\\" IS NOT NULL"},{"name":"smrt_ck_bab2c772ebe6","columns":["like_count"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:Tweet') OR \\"like_count\\" IS NOT NULL"},{"name":"smrt_ck_c6ad8d47bbc8","columns":["reply_count"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:Tweet') OR \\"reply_count\\" IS NOT NULL"},{"name":"smrt_ck_43a00e1c098d","columns":["retweet_count"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:Tweet') OR \\"retweet_count\\" IS NOT NULL"}],"version":"f48614e6"},"importPath":"@happyvertical/smrt-messages"},"@happyvertical/smrt-messages:EmailFolderCollection":{"name":"emailfoldercollection","className":"EmailFolderCollection","qualifiedName":"@happyvertical/smrt-messages:EmailFolderCollection","collection":"emailfolders","filePath":"src/collections/EmailFolderCollection.ts","packageName":"@happyvertical/smrt-messages","fields":{},"methods":{"getByPath":{"name":"getByPath","async":true,"parameters":[{"name":"accountId","type":"string","optional":false},{"name":"path","type":"string","optional":false}],"returnType":"Promise<EmailFolder | null>","isStatic":false,"isPublic":true},"getByAccount":{"name":"getByAccount","async":true,"parameters":[{"name":"accountId","type":"string","optional":false}],"returnType":"Promise<EmailFolder[]>","isStatic":false,"isPublic":true},"getInbox":{"name":"getInbox","async":true,"parameters":[{"name":"accountId","type":"string","optional":false}],"returnType":"Promise<EmailFolder | null>","isStatic":false,"isPublic":true},"getSent":{"name":"getSent","async":true,"parameters":[{"name":"accountId","type":"string","optional":false}],"returnType":"Promise<EmailFolder | null>","isStatic":false,"isPublic":true},"getDrafts":{"name":"getDrafts","async":true,"parameters":[{"name":"accountId","type":"string","optional":false}],"returnType":"Promise<EmailFolder | null>","isStatic":false,"isPublic":true},"getTrash":{"name":"getTrash","async":true,"parameters":[{"name":"accountId","type":"string","optional":false}],"returnType":"Promise<EmailFolder | null>","isStatic":false,"isPublic":true},"getSpam":{"name":"getSpam","async":true,"parameters":[{"name":"accountId","type":"string","optional":false}],"returnType":"Promise<EmailFolder | null>","isStatic":false,"isPublic":true},"getSystemFolders":{"name":"getSystemFolders","async":true,"parameters":[{"name":"accountId","type":"string","optional":false}],"returnType":"Promise<EmailFolder[]>","isStatic":false,"isPublic":true},"getUserFolders":{"name":"getUserFolders","async":true,"parameters":[{"name":"accountId","type":"string","optional":false}],"returnType":"Promise<EmailFolder[]>","isStatic":false,"isPublic":true},"getSubscribed":{"name":"getSubscribed","async":true,"parameters":[{"name":"accountId","type":"string","optional":true}],"returnType":"Promise<EmailFolder[]>","isStatic":false,"isPublic":true},"getWithUnread":{"name":"getWithUnread","async":true,"parameters":[{"name":"accountId","type":"string","optional":true}],"returnType":"Promise<EmailFolder[]>","isStatic":false,"isPublic":true},"search":{"name":"search","async":true,"parameters":[{"name":"query","type":"string","optional":false},{"name":"filters","type":"EmailFolderSearchFilters","optional":true}],"returnType":"Promise<EmailFolder[]>","isStatic":false,"isPublic":true},"refreshAllCounts":{"name":"refreshAllCounts","async":true,"parameters":[{"name":"accountId","type":"string","optional":false}],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"getAccountStats":{"name":"getAccountStats","async":true,"parameters":[{"name":"accountId","type":"string","optional":false}],"returnType":"Promise<object>","isStatic":false,"isPublic":true},"createSystemFolders":{"name":"createSystemFolders","async":true,"parameters":[{"name":"accountId","type":"string","optional":false}],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"findByTenant":{"name":"findByTenant","async":true,"parameters":[{"name":"tenantId","type":"string","optional":false}],"returnType":"Promise<EmailFolder[]>","isStatic":false,"isPublic":true},"findGlobal":{"name":"findGlobal","async":true,"parameters":[],"returnType":"Promise<EmailFolder[]>","isStatic":false,"isPublic":true},"findWithGlobals":{"name":"findWithGlobals","async":true,"parameters":[{"name":"tenantId","type":"string","optional":false}],"returnType":"Promise<EmailFolder[]>","isStatic":false,"isPublic":true}},"decoratorConfig":{"api":{"include":["list","get","create","update","delete"]},"mcp":{"include":["list","get"]}},"extends":"SmrtCollection","extendsTypeArg":"EmailFolder","exportName":"EmailFolderCollection","collectionExportName":"EmailFolderCollectionCollection","collectionOf":"@happyvertical/smrt-messages:EmailFolder","inheritedExposure":["api","mcp"],"schema":{"tableName":"email_folders","ddl":"CREATE TABLE IF NOT EXISTS \\"email_folders\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"account_id\\" UUID,\\n \\"name\\" TEXT,\\n \\"path\\" TEXT,\\n \\"delimiter\\" TEXT,\\n \\"special_use\\" TEXT,\\n \\"message_count\\" INTEGER NOT NULL DEFAULT 0,\\n \\"unread_count\\" INTEGER NOT NULL DEFAULT 0,\\n \\"subscribed\\" BOOLEAN NOT NULL DEFAULT TRUE\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false,"unique":false},"account_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"accounts","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"name":{"type":"TEXT","notNull":false,"unique":false},"path":{"type":"TEXT","notNull":false,"unique":false},"delimiter":{"type":"TEXT","notNull":false,"unique":false},"special_use":{"type":"TEXT","notNull":false,"unique":false},"message_count":{"type":"INTEGER","notNull":true,"unique":false,"default":0},"unread_count":{"type":"INTEGER","notNull":true,"unique":false,"default":0},"subscribed":{"type":"BOOLEAN","notNull":true,"unique":false,"default":true}},"indexes":[{"name":"email_folders_slug_context_idx","columns":["tenant_id","slug","context"],"unique":true,"nullsNotDistinct":true},{"name":"email_folders_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"email_folders_account_id_idx","columns":["account_id"]}],"version":"cfea127c"},"importPath":"@happyvertical/smrt-messages"},"@happyvertical/smrt-messages:MessageCollection":{"name":"messagecollection","className":"MessageCollection","qualifiedName":"@happyvertical/smrt-messages:MessageCollection","collection":"messages","filePath":"src/collections/MessageCollection.ts","packageName":"@happyvertical/smrt-messages","fields":{},"methods":{"search":{"name":"search","async":true,"parameters":[{"name":"query","type":"string","optional":false},{"name":"filters","type":"MessageSearchFilters","optional":true}],"returnType":"Promise<Message[]>","isStatic":false,"isPublic":true},"getByAccounts":{"name":"getByAccounts","async":true,"parameters":[{"name":"accountIds","type":"string[]","optional":false}],"returnType":"Promise<Message[]>","isStatic":false,"isPublic":true},"getByType":{"name":"getByType","async":true,"parameters":[{"name":"messageType","type":"string","optional":false}],"returnType":"Promise<Message[]>","isStatic":false,"isPublic":true},"getUnread":{"name":"getUnread","async":true,"parameters":[{"name":"accountId","type":"string","optional":true}],"returnType":"Promise<Message[]>","isStatic":false,"isPublic":true},"getFlagged":{"name":"getFlagged","async":true,"parameters":[{"name":"accountId","type":"string","optional":true}],"returnType":"Promise<Message[]>","isStatic":false,"isPublic":true},"getRecent":{"name":"getRecent","async":true,"parameters":[{"name":"limit","type":"any","optional":true},{"name":"accountId","type":"string","optional":true}],"returnType":"Promise<Message[]>","isStatic":false,"isPublic":true},"getByThread":{"name":"getByThread","async":true,"parameters":[{"name":"threadId","type":"string","optional":false}],"returnType":"Promise<Message[]>","isStatic":false,"isPublic":true},"markAllRead":{"name":"markAllRead","async":true,"parameters":[{"name":"messageIds","type":"string[]","optional":false}],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"getAccountStats":{"name":"getAccountStats","async":true,"parameters":[{"name":"accountId","type":"string","optional":false}],"returnType":"Promise<object>","isStatic":false,"isPublic":true},"getDrafts":{"name":"getDrafts","async":true,"parameters":[{"name":"accountId","type":"string","optional":true}],"returnType":"Promise<Message[]>","isStatic":false,"isPublic":true},"getSent":{"name":"getSent","async":true,"parameters":[{"name":"accountId","type":"string","optional":true}],"returnType":"Promise<Message[]>","isStatic":false,"isPublic":true},"getScheduled":{"name":"getScheduled","async":true,"parameters":[{"name":"accountId","type":"string","optional":true}],"returnType":"Promise<Message[]>","isStatic":false,"isPublic":true},"getFailedSends":{"name":"getFailedSends","async":true,"parameters":[{"name":"accountId","type":"string","optional":true}],"returnType":"Promise<Message[]>","isStatic":false,"isPublic":true},"getOutbox":{"name":"getOutbox","async":true,"parameters":[{"name":"accountId","type":"string","optional":true}],"returnType":"Promise<Message[]>","isStatic":false,"isPublic":true},"findByTenant":{"name":"findByTenant","async":true,"parameters":[{"name":"tenantId","type":"string","optional":false}],"returnType":"Promise<Message[]>","isStatic":false,"isPublic":true},"findGlobal":{"name":"findGlobal","async":true,"parameters":[],"returnType":"Promise<Message[]>","isStatic":false,"isPublic":true},"findWithGlobals":{"name":"findWithGlobals","async":true,"parameters":[{"name":"tenantId","type":"string","optional":false}],"returnType":"Promise<Message[]>","isStatic":false,"isPublic":true}},"decoratorConfig":{"api":{"include":["list","get"]},"mcp":{"include":["list","get"]}},"extends":"SmrtCollection","extendsTypeArg":"Message","exportName":"MessageCollection","collectionExportName":"MessageCollectionCollection","collectionOf":"@happyvertical/smrt-messages:Message","inheritedExposure":["api","mcp"],"schema":{"tableName":"messages","ddl":"CREATE TABLE IF NOT EXISTS \\"messages\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"_meta_type\\" TEXT NOT NULL,\\n \\"_meta_data\\" JSON,\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"account_id\\" UUID,\\n \\"persona_id\\" UUID,\\n \\"endpoint_id\\" UUID,\\n \\"correlation_id\\" TEXT,\\n \\"thread_id\\" TEXT,\\n \\"subject\\" TEXT,\\n \\"body\\" TEXT,\\n \\"from_address\\" TEXT,\\n \\"from_name\\" TEXT,\\n \\"to_addresses\\" TEXT,\\n \\"date\\" TIMESTAMP,\\n \\"is_read\\" BOOLEAN DEFAULT FALSE,\\n \\"is_flagged\\" BOOLEAN DEFAULT FALSE,\\n \\"has_attachments\\" BOOLEAN DEFAULT FALSE,\\n \\"size\\" INTEGER DEFAULT 0,\\n \\"metadata\\" TEXT,\\n \\"send_status\\" TEXT DEFAULT 'draft',\\n \\"sent_at\\" TIMESTAMP,\\n \\"send_error\\" TEXT,\\n \\"retry_count\\" INTEGER DEFAULT 0,\\n \\"max_retries\\" INTEGER DEFAULT 3,\\n \\"scheduled_send_at\\" TIMESTAMP,\\n \\"in_reply_to_message_id\\" UUID,\\n \\"message_id\\" TEXT,\\n \\"in_reply_to\\" TEXT,\\n \\"provider_message_id\\" TEXT,\\n \\"cc_addresses\\" TEXT,\\n \\"bcc_addresses\\" TEXT,\\n \\"reply_to_address\\" TEXT,\\n \\"reply_to_name\\" TEXT,\\n \\"text_body\\" TEXT,\\n \\"html_body\\" TEXT,\\n \\"folder_id\\" TEXT,\\n \\"folder_path\\" TEXT,\\n \\"labels\\" TEXT,\\n \\"flags\\" TEXT,\\n \\"is_answered\\" BOOLEAN DEFAULT FALSE,\\n \\"is_draft\\" BOOLEAN DEFAULT FALSE,\\n \\"raw_message\\" TEXT,\\n \\"headers\\" TEXT,\\n \\"channel_id\\" TEXT,\\n \\"channel_name\\" TEXT,\\n \\"slack_ts\\" TEXT,\\n \\"slack_thread_ts\\" TEXT,\\n \\"reactions\\" TEXT,\\n \\"is_edited\\" BOOLEAN DEFAULT FALSE,\\n \\"message_type\\" TEXT,\\n \\"blocks\\" TEXT,\\n \\"tweet_id\\" TEXT,\\n \\"retweet_count\\" INTEGER DEFAULT 0,\\n \\"like_count\\" INTEGER DEFAULT 0,\\n \\"reply_count\\" INTEGER DEFAULT 0,\\n \\"is_retweet\\" BOOLEAN DEFAULT FALSE,\\n \\"is_reply\\" BOOLEAN DEFAULT FALSE,\\n \\"media_urls\\" TEXT,\\n \\"hashtags\\" TEXT,\\n \\"mentions\\" TEXT\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"_meta_type":{"type":"TEXT","notNull":true},"_meta_data":{"type":"JSON","notNull":false},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false},"account_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"foreignKey":{"table":"accounts","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"persona_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false},"endpoint_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"foreignKey":{"table":"messaging_endpoints","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"correlation_id":{"type":"TEXT","notNull":false},"thread_id":{"type":"TEXT","notNull":false},"subject":{"type":"TEXT","notNull":false},"body":{"type":"TEXT","notNull":false},"from_address":{"type":"TEXT","notNull":false},"from_name":{"type":"TEXT","notNull":false},"to_addresses":{"type":"TEXT","notNull":false},"date":{"type":"TIMESTAMP","notNull":false},"is_read":{"type":"BOOLEAN","notNull":false,"default":false},"is_flagged":{"type":"BOOLEAN","notNull":false,"default":false},"has_attachments":{"type":"BOOLEAN","notNull":false,"default":false},"size":{"type":"INTEGER","notNull":false,"default":0},"metadata":{"type":"TEXT","notNull":false},"send_status":{"type":"TEXT","notNull":false,"default":"draft"},"sent_at":{"type":"TIMESTAMP","notNull":false},"send_error":{"type":"TEXT","notNull":false},"retry_count":{"type":"INTEGER","notNull":false,"default":0},"max_retries":{"type":"INTEGER","notNull":false,"default":3},"scheduled_send_at":{"type":"TIMESTAMP","notNull":false},"in_reply_to_message_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"foreignKey":{"table":"messages","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"message_id":{"type":"TEXT","notNull":false},"in_reply_to":{"type":"TEXT","notNull":false},"provider_message_id":{"type":"TEXT","notNull":false},"cc_addresses":{"type":"TEXT","notNull":false},"bcc_addresses":{"type":"TEXT","notNull":false},"reply_to_address":{"type":"TEXT","notNull":false},"reply_to_name":{"type":"TEXT","notNull":false},"text_body":{"type":"TEXT","notNull":false},"html_body":{"type":"TEXT","notNull":false},"folder_id":{"type":"TEXT","notNull":false},"folder_path":{"type":"TEXT","notNull":false},"labels":{"type":"TEXT","notNull":false},"flags":{"type":"TEXT","notNull":false},"is_answered":{"type":"BOOLEAN","notNull":false,"default":false},"is_draft":{"type":"BOOLEAN","notNull":false,"default":false},"raw_message":{"type":"TEXT","notNull":false},"headers":{"type":"TEXT","notNull":false},"channel_id":{"type":"TEXT","notNull":false},"channel_name":{"type":"TEXT","notNull":false},"slack_ts":{"type":"TEXT","notNull":false},"slack_thread_ts":{"type":"TEXT","notNull":false},"reactions":{"type":"TEXT","notNull":false},"is_edited":{"type":"BOOLEAN","notNull":false,"default":false},"message_type":{"type":"TEXT","notNull":false},"blocks":{"type":"TEXT","notNull":false},"tweet_id":{"type":"TEXT","notNull":false},"retweet_count":{"type":"INTEGER","notNull":false,"default":0},"like_count":{"type":"INTEGER","notNull":false,"default":0},"reply_count":{"type":"INTEGER","notNull":false,"default":0},"is_retweet":{"type":"BOOLEAN","notNull":false,"default":false},"is_reply":{"type":"BOOLEAN","notNull":false,"default":false},"media_urls":{"type":"TEXT","notNull":false},"hashtags":{"type":"TEXT","notNull":false},"mentions":{"type":"TEXT","notNull":false}},"indexes":[{"name":"messages_slug_context_meta_type_idx","columns":["tenant_id","slug","context","_meta_type"],"unique":true,"nullsNotDistinct":true},{"name":"messages_meta_type_idx","columns":["_meta_type"]},{"name":"messages_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"messages_account_id_idx","columns":["account_id"]},{"name":"messages_persona_id_idx","columns":["persona_id"]},{"name":"messages_endpoint_id_idx","columns":["endpoint_id"]},{"name":"messages_in_reply_to_message_id_idx","columns":["in_reply_to_message_id"]}],"checks":[{"name":"smrt_ck_d0024f738cf4","columns":["is_answered"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:Email') OR \\"is_answered\\" IS NOT NULL"},{"name":"smrt_ck_0adcd2453c81","columns":["is_draft"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:Email') OR \\"is_draft\\" IS NOT NULL"},{"name":"smrt_ck_428e155c9609","columns":["is_edited"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:SlackMessage') OR \\"is_edited\\" IS NOT NULL"},{"name":"smrt_ck_a17af99e85e3","columns":["is_reply"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:Tweet') OR \\"is_reply\\" IS NOT NULL"},{"name":"smrt_ck_3e30563cba58","columns":["is_retweet"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:Tweet') OR \\"is_retweet\\" IS NOT NULL"},{"name":"smrt_ck_bab2c772ebe6","columns":["like_count"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:Tweet') OR \\"like_count\\" IS NOT NULL"},{"name":"smrt_ck_c6ad8d47bbc8","columns":["reply_count"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:Tweet') OR \\"reply_count\\" IS NOT NULL"},{"name":"smrt_ck_43a00e1c098d","columns":["retweet_count"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:Tweet') OR \\"retweet_count\\" IS NOT NULL"}],"version":"d8da74ce"},"importPath":"@happyvertical/smrt-messages"},"@happyvertical/smrt-messages:MessagingEndpointCollection":{"name":"messagingendpointcollection","className":"MessagingEndpointCollection","qualifiedName":"@happyvertical/smrt-messages:MessagingEndpointCollection","collection":"messagingendpoints","filePath":"src/collections/MessagingEndpointCollection.ts","packageName":"@happyvertical/smrt-messages","fields":{},"methods":{},"decoratorConfig":{"tableName":"messaging_endpoints","api":{"include":["list","get"]},"mcp":{"include":["list","get"]},"cli":{"include":["list","get"]}},"extends":"SmrtCollection","extendsTypeArg":"MessagingEndpoint","exportName":"MessagingEndpointCollection","collectionExportName":"MessagingEndpointCollectionCollection","collectionOf":"@happyvertical/smrt-messages:MessagingEndpoint","inheritedExposure":["api","mcp","cli"],"schema":{"tableName":"messaging_endpoints","ddl":"CREATE TABLE IF NOT EXISTS \\"messaging_endpoints\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"profile_id\\" UUID,\\n \\"label\\" TEXT NOT NULL,\\n \\"channel\\" TEXT NOT NULL DEFAULT 'email',\\n \\"address\\" TEXT NOT NULL,\\n \\"is_active\\" BOOLEAN NOT NULL DEFAULT TRUE,\\n \\"verified_at\\" TIMESTAMP\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"profile_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false,"unique":false},"label":{"type":"TEXT","notNull":true,"unique":false},"channel":{"type":"TEXT","notNull":true,"unique":false,"default":"email"},"address":{"type":"TEXT","notNull":true,"unique":false},"is_active":{"type":"BOOLEAN","notNull":true,"unique":false,"default":true},"verified_at":{"type":"TIMESTAMP","notNull":false,"unique":false}},"indexes":[{"name":"messaging_endpoints_tenant_id_channel_idx","columns":["tenant_id","channel","label"],"unique":true},{"name":"messaging_endpoints_slug_context_idx","columns":["slug","context"]},{"name":"messaging_endpoints_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"messaging_endpoints_profile_id_idx","columns":["profile_id"]}],"version":"b4466849"},"importPath":"@happyvertical/smrt-messages"},"@happyvertical/smrt-messages:NotificationDeliveryCollection":{"name":"notificationdeliverycollection","className":"NotificationDeliveryCollection","qualifiedName":"@happyvertical/smrt-messages:NotificationDeliveryCollection","collection":"notificationdeliveries","filePath":"src/collections/NotificationDeliveryCollection.ts","packageName":"@happyvertical/smrt-messages","fields":{},"methods":{},"decoratorConfig":{"tableName":"notification_deliveries","api":false,"mcp":false,"cli":false},"extends":"SmrtCollection","extendsTypeArg":"NotificationDelivery","exportName":"NotificationDeliveryCollection","collectionExportName":"NotificationDeliveryCollectionCollection","collectionOf":"@happyvertical/smrt-messages:NotificationDelivery","inheritedExposure":["api","mcp","cli"],"schema":{"tableName":"notification_deliveries","ddl":"CREATE TABLE IF NOT EXISTS \\"notification_deliveries\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"recipient_user_id\\" UUID,\\n \\"recipient_profile_id\\" UUID,\\n \\"recipient_kind\\" TEXT NOT NULL DEFAULT 'user',\\n \\"channel\\" TEXT NOT NULL DEFAULT 'email',\\n \\"source_ref\\" TEXT NOT NULL,\\n \\"kind\\" TEXT NOT NULL,\\n \\"required_dispatch_policy\\" TEXT,\\n \\"dispatch_policy_binding\\" JSON,\\n \\"subject\\" TEXT,\\n \\"text_body\\" TEXT,\\n \\"href\\" TEXT,\\n \\"recipient_address\\" TEXT NOT NULL,\\n \\"recipient_name\\" TEXT,\\n \\"account_id\\" UUID,\\n \\"message_id\\" UUID,\\n \\"status\\" TEXT DEFAULT 'pending',\\n \\"state_version\\" INTEGER NOT NULL DEFAULT 0,\\n \\"transition_id\\" TEXT,\\n \\"attempts\\" INTEGER NOT NULL DEFAULT 0,\\n \\"max_attempts\\" INTEGER NOT NULL DEFAULT 5,\\n \\"next_attempt_at\\" TEXT,\\n \\"lease_token\\" TEXT,\\n \\"lease_expires_at\\" TIMESTAMP,\\n \\"handed_off_at\\" TIMESTAMP,\\n \\"delivered_at\\" TIMESTAMP,\\n \\"provider_message_id\\" TEXT,\\n \\"last_error\\" TEXT\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"recipient_user_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false,"unique":false},"recipient_profile_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false,"unique":false},"recipient_kind":{"type":"TEXT","notNull":true,"unique":false,"default":"user"},"channel":{"type":"TEXT","notNull":true,"unique":false,"default":"email"},"source_ref":{"type":"TEXT","notNull":true,"unique":false},"kind":{"type":"TEXT","notNull":true,"unique":false},"required_dispatch_policy":{"type":"TEXT","notNull":false,"unique":false},"dispatch_policy_binding":{"type":"JSON","notNull":false,"unique":false},"subject":{"type":"TEXT","notNull":false,"unique":false},"text_body":{"type":"TEXT","notNull":false,"unique":false},"href":{"type":"TEXT","notNull":false,"unique":false},"recipient_address":{"type":"TEXT","notNull":true,"unique":false},"recipient_name":{"type":"TEXT","notNull":false,"unique":false},"account_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"accounts","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"message_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"messages","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"status":{"type":"TEXT","notNull":false,"unique":false,"default":"pending"},"state_version":{"type":"INTEGER","notNull":true,"unique":false,"default":0},"transition_id":{"type":"TEXT","notNull":false,"unique":false},"attempts":{"type":"INTEGER","notNull":true,"unique":false,"default":0},"max_attempts":{"type":"INTEGER","notNull":true,"unique":false,"default":5},"next_attempt_at":{"type":"TEXT","notNull":false,"unique":false},"lease_token":{"type":"TEXT","notNull":false,"unique":false},"lease_expires_at":{"type":"TIMESTAMP","notNull":false,"unique":false},"handed_off_at":{"type":"TIMESTAMP","notNull":false,"unique":false},"delivered_at":{"type":"TIMESTAMP","notNull":false,"unique":false},"provider_message_id":{"type":"TEXT","notNull":false,"unique":false},"last_error":{"type":"TEXT","notNull":false,"unique":false}},"indexes":[{"name":"notification_deliveries_tenant_id_recipient_kind_idx","columns":["tenant_id","recipient_kind","recipient_user_id","recipient_profile_id","channel","source_ref"],"unique":true,"nullsNotDistinct":true},{"name":"notification_deliveries_slug_context_idx","columns":["slug","context"]},{"name":"notification_deliveries_user_identity","columns":["tenant_id","recipient_user_id","channel","source_ref"],"unique":true},{"name":"notification_deliveries_profile_identity","columns":["tenant_id","recipient_profile_id","channel","source_ref"],"unique":true},{"name":"notification_deliveries_due_idx","columns":["status","next_attempt_at"]},{"name":"notification_deliveries_lease_idx","columns":["status","lease_expires_at"]},{"name":"notification_deliveries_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"notification_deliveries_recipient_user_id_idx","columns":["recipient_user_id"]},{"name":"notification_deliveries_recipient_profile_id_idx","columns":["recipient_profile_id"]},{"name":"notification_deliveries_account_id_idx","columns":["account_id"]},{"name":"notification_deliveries_message_id_idx","columns":["message_id"]}],"version":"547f434f"},"importPath":"@happyvertical/smrt-messages"},"@happyvertical/smrt-messages:NotificationOptOutCollection":{"name":"notificationoptoutcollection","className":"NotificationOptOutCollection","qualifiedName":"@happyvertical/smrt-messages:NotificationOptOutCollection","collection":"notificationoptouts","filePath":"src/collections/NotificationOptOutCollection.ts","packageName":"@happyvertical/smrt-messages","fields":{},"methods":{},"decoratorConfig":{"tableName":"notification_opt_outs","api":false,"mcp":false,"cli":false},"extends":"SmrtCollection","extendsTypeArg":"NotificationOptOut","exportName":"NotificationOptOutCollection","collectionExportName":"NotificationOptOutCollectionCollection","collectionOf":"@happyvertical/smrt-messages:NotificationOptOut","inheritedExposure":["api","mcp","cli"],"schema":{"tableName":"notification_opt_outs","ddl":"CREATE TABLE IF NOT EXISTS \\"notification_opt_outs\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"recipient_user_id\\" UUID NOT NULL,\\n \\"channel\\" TEXT NOT NULL DEFAULT 'email',\\n \\"scope\\" TEXT NOT NULL,\\n \\"opted_out_at\\" TIMESTAMP,\\n \\"updated_by\\" TEXT\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"recipient_user_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":true,"unique":false},"channel":{"type":"TEXT","notNull":true,"unique":false,"default":"email"},"scope":{"type":"TEXT","notNull":true,"unique":false},"opted_out_at":{"type":"TIMESTAMP","notNull":false,"unique":false},"updated_by":{"type":"TEXT","notNull":false,"unique":false}},"indexes":[{"name":"notification_opt_outs_tenant_id_recipient_user_id_idx","columns":["tenant_id","recipient_user_id","channel","scope"],"unique":true},{"name":"notification_opt_outs_slug_context_idx","columns":["slug","context"]},{"name":"notification_opt_outs_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"notification_opt_outs_recipient_user_id_idx","columns":["recipient_user_id"]}],"version":"a13e93c1"},"importPath":"@happyvertical/smrt-messages"},"@happyvertical/smrt-messages:PersonaMessageRouteCollection":{"name":"personamessageroutecollection","className":"PersonaMessageRouteCollection","qualifiedName":"@happyvertical/smrt-messages:PersonaMessageRouteCollection","collection":"personamessageroutes","filePath":"src/collections/PersonaMessageRouteCollection.ts","packageName":"@happyvertical/smrt-messages","fields":{},"methods":{"forPersona":{"name":"forPersona","async":true,"parameters":[{"name":"personaId","type":"string","optional":false}],"returnType":"Promise<PersonaMessageRoute[]>","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableName":"persona_message_routes","api":{"include":["list","get"]},"mcp":{"include":["list","get"]},"cli":{"include":["list","get"]}},"extends":"SmrtCollection","extendsTypeArg":"PersonaMessageRoute","exportName":"PersonaMessageRouteCollection","collectionExportName":"PersonaMessageRouteCollectionCollection","collectionOf":"@happyvertical/smrt-messages:PersonaMessageRoute","inheritedExposure":["api","mcp","cli"],"schema":{"tableName":"persona_message_routes","ddl":"CREATE TABLE IF NOT EXISTS \\"persona_message_routes\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"persona_id\\" UUID NOT NULL,\\n \\"account_id\\" UUID NOT NULL,\\n \\"endpoint_id\\" UUID NOT NULL,\\n \\"purpose\\" TEXT NOT NULL,\\n \\"priority\\" INTEGER NOT NULL DEFAULT 0,\\n \\"enabled\\" BOOLEAN NOT NULL DEFAULT TRUE\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"persona_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":true,"unique":false},"account_id":{"type":"UUID","referenceKind":"foreignKey","notNull":true,"unique":false,"foreignKey":{"table":"accounts","column":"id","onDelete":"CASCADE","onUpdate":"CASCADE"}},"endpoint_id":{"type":"UUID","referenceKind":"foreignKey","notNull":true,"unique":false,"foreignKey":{"table":"messaging_endpoints","column":"id","onDelete":"CASCADE","onUpdate":"CASCADE"}},"purpose":{"type":"TEXT","notNull":true,"unique":false},"priority":{"type":"INTEGER","notNull":true,"unique":false,"default":0},"enabled":{"type":"BOOLEAN","notNull":true,"unique":false,"default":true}},"indexes":[{"name":"persona_message_routes_tenant_id_persona_id_idx","columns":["tenant_id","persona_id","account_id","endpoint_id","purpose"],"unique":true},{"name":"persona_message_routes_slug_context_idx","columns":["slug","context"]},{"name":"persona_message_routes_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"persona_message_routes_persona_id_idx","columns":["persona_id"]},{"name":"persona_message_routes_account_id_idx","columns":["account_id"]},{"name":"persona_message_routes_endpoint_id_idx","columns":["endpoint_id"]}],"version":"3caf446e"},"importPath":"@happyvertical/smrt-messages"},"@happyvertical/smrt-messages:UserNotificationCollection":{"name":"usernotificationcollection","className":"UserNotificationCollection","qualifiedName":"@happyvertical/smrt-messages:UserNotificationCollection","collection":"usernotifications","filePath":"src/collections/UserNotificationCollection.ts","packageName":"@happyvertical/smrt-messages","fields":{},"methods":{},"decoratorConfig":{"tableName":"user_notifications","api":false,"mcp":false,"cli":false},"extends":"SmrtCollection","extendsTypeArg":"UserNotification","exportName":"UserNotificationCollection","collectionExportName":"UserNotificationCollectionCollection","collectionOf":"@happyvertical/smrt-messages:UserNotification","inheritedExposure":["api","mcp","cli"],"schema":{"tableName":"user_notifications","ddl":"CREATE TABLE IF NOT EXISTS \\"user_notifications\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"recipient_user_id\\" UUID NOT NULL,\\n \\"kind\\" TEXT,\\n \\"title\\" TEXT,\\n \\"body\\" TEXT,\\n \\"href\\" TEXT,\\n \\"severity\\" TEXT DEFAULT 'info',\\n \\"source_ref\\" TEXT NOT NULL,\\n \\"occurred_at\\" TEXT,\\n \\"read_at\\" TIMESTAMP,\\n \\"dismissed_at\\" TIMESTAMP\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"recipient_user_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":true,"unique":false},"kind":{"type":"TEXT","notNull":false,"unique":false},"title":{"type":"TEXT","notNull":false,"unique":false},"body":{"type":"TEXT","notNull":false,"unique":false},"href":{"type":"TEXT","notNull":false,"unique":false},"severity":{"type":"TEXT","notNull":false,"unique":false,"default":"info"},"source_ref":{"type":"TEXT","notNull":true,"unique":false},"occurred_at":{"type":"TEXT","notNull":false,"unique":false},"read_at":{"type":"TIMESTAMP","notNull":false,"unique":false},"dismissed_at":{"type":"TIMESTAMP","notNull":false,"unique":false}},"indexes":[{"name":"user_notifications_tenant_id_recipient_user_id_idx","columns":["tenant_id","recipient_user_id","source_ref"],"unique":true},{"name":"user_notifications_slug_context_idx","columns":["slug","context"]},{"name":"user_notifications_recipient_occurred_idx","columns":["tenant_id","recipient_user_id","occurred_at"]},{"name":"user_notifications_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"user_notifications_recipient_user_id_idx","columns":["recipient_user_id"]}],"version":"812ca772"},"importPath":"@happyvertical/smrt-messages"},"@happyvertical/smrt-messages:WhitelistCollection":{"name":"whitelistcollection","className":"WhitelistCollection","qualifiedName":"@happyvertical/smrt-messages:WhitelistCollection","collection":"whitelists","filePath":"src/collections/WhitelistCollection.ts","packageName":"@happyvertical/smrt-messages","fields":{},"methods":{"isWhitelisted":{"name":"isWhitelisted","async":true,"parameters":[{"name":"email","type":"string","optional":false},{"name":"category","type":"string","optional":true}],"returnType":"Promise<boolean>","isStatic":false,"isPublic":true},"getMatchingEntry":{"name":"getMatchingEntry","async":true,"parameters":[{"name":"email","type":"string","optional":false}],"returnType":"Promise<Whitelist | null>","isStatic":false,"isPublic":true},"getByCategory":{"name":"getByCategory","async":true,"parameters":[{"name":"category","type":"string","optional":false}],"returnType":"Promise<Whitelist[]>","isStatic":false,"isPublic":true}},"decoratorConfig":{"api":{"include":["list","get","create","update","delete"]}},"extends":"SmrtCollection","extendsTypeArg":"Whitelist","exportName":"WhitelistCollection","collectionExportName":"WhitelistCollectionCollection","collectionOf":"@happyvertical/smrt-messages:Whitelist","inheritedExposure":["api"],"schema":{"tableName":"whitelists","ddl":"CREATE TABLE IF NOT EXISTS \\"whitelists\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"pattern\\" TEXT DEFAULT '',\\n \\"type\\" TEXT DEFAULT 'email',\\n \\"category\\" TEXT,\\n \\"description\\" TEXT DEFAULT '',\\n \\"tenant_id\\" UUID NOT NULL\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"pattern":{"type":"TEXT","notNull":false,"unique":false,"default":""},"type":{"type":"TEXT","notNull":false,"unique":false,"default":"email"},"category":{"type":"TEXT","notNull":false,"unique":false},"description":{"type":"TEXT","notNull":false,"unique":false,"default":""},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false}},"indexes":[{"name":"whitelists_slug_context_idx","columns":["tenant_id","slug","context"],"unique":true},{"name":"whitelists_tenant_id_created_at_idx","columns":["tenant_id","created_at"]}],"version":"eb5b558d"},"importPath":"@happyvertical/smrt-messages"},"@happyvertical/smrt-messages:Account":{"name":"account","className":"Account","qualifiedName":"@happyvertical/smrt-messages:Account","collection":"accounts","filePath":"src/models/Account.ts","packageName":"@happyvertical/smrt-messages","fields":{"created_at":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"updated_at":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"tenantId":{"type":"text","_meta":{"__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":false,"autoPopulate":true,"nullable":true,"mode":"optional","field":"tenantId","allowSuperAdminBypass":false},"__statedOptions":["sqlType","nullable","__tenancy","required"],"sqlType":"UUID","nullable":true,"required":false},"required":false},"name":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The display name for this connected messaging account."},"required":false,"description":"The display name for this connected messaging account."},"providerType":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The service that connects this account to your application."},"required":false,"description":"The service that connects this account to your application."},"channelType":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The kind of messaging this account supports, such as email or chat."},"required":false,"description":"The kind of messaging this account supports, such as email or chat."},"credentialSecretId":{"type":"text","_meta":{"__statedOptions":["sensitive","readonly"],"sensitive":true,"readonly":true},"required":false,"sensitive":true,"readonly":true},"isActive":{"type":"boolean","_meta":{"__statedOptions":["description","default"],"description":"Whether this account is enabled for messaging."},"required":true,"default":true,"description":"Whether this account is enabled for messaging."},"ownerUserId":{"type":"crossPackageRef","_meta":{"__statedOptions":["description","related"],"description":"The person who owns this account and decides who else may use it."},"required":false,"related":"@happyvertical/smrt-users:User","description":"The person who owns this account and decides who else may use it."},"label":{"type":"text","_meta":{"__statedOptions":["description"],"description":"A short name shown beside this account, such as Support or Personal."},"required":false,"description":"A short name shown beside this account, such as Support or Personal."},"connectionStatus":{"type":"text","_meta":{"__statedOptions":["description"],"description":"Whether the saved sign-in still works: connected, or needs_reconnect after the server refused it."},"required":false,"description":"Whether the saved sign-in still works: connected, or needs_reconnect after the server refused it."},"statusMessage":{"type":"text","_meta":{"__statedOptions":["description"],"description":"Why the account needs attention, in plain words."},"required":false,"description":"Why the account needs attention, in plain words."},"lastSyncAt":{"type":"datetime","_meta":{"__statedOptions":["description"],"description":"When this account last checked for new messages."},"required":false,"description":"When this account last checked for new messages."},"settings":{"type":"text","_meta":{"__statedOptions":["sensitive","readonly"],"sensitive":true,"readonly":true},"required":false,"sensitive":true,"readonly":true},"configuration":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The public connection settings for this account; credentials are stored separately."},"required":false,"description":"The public connection settings for this account; credentials are stored separately."},"createdAt":{"type":"text","_meta":{"__statedOptions":["description"],"description":"When this account was added."},"required":false,"description":"When this account was added."},"updatedAt":{"type":"text","_meta":{"__statedOptions":["description"],"description":"When this account was last changed."},"required":false,"description":"When this account was last changed."}},"methods":{"getSettings":{"name":"getSettings","async":false,"parameters":[],"returnType":"Record<string, unknown>","isStatic":false,"isPublic":true},"setSettings":{"name":"setSettings","async":false,"parameters":[{"name":"settings","type":"Record<string, unknown>","optional":false}],"returnType":"void","isStatic":false,"isPublic":true},"getConfiguration":{"name":"getConfiguration","async":false,"parameters":[],"returnType":"Record<string, unknown>","isStatic":false,"isPublic":true},"setConfiguration":{"name":"setConfiguration","async":false,"parameters":[{"name":"configuration","type":"Record<string, unknown>","optional":false}],"returnType":"void","isStatic":false,"isPublic":true},"markNeedsReconnect":{"name":"markNeedsReconnect","async":true,"parameters":[{"name":"reason","type":"string","optional":false}],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"markConnected":{"name":"markConnected","async":true,"parameters":[],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"activate":{"name":"activate","async":true,"parameters":[],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"deactivate":{"name":"deactivate","async":true,"parameters":[],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"setCredentials":{"name":"setCredentials","async":true,"parameters":[{"name":"credentials","type":"Record<string, unknown>","optional":false},{"name":"options","type":"object","optional":true,"memberTypes":["string"]}],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"removeCredentials":{"name":"removeCredentials","async":true,"parameters":[],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"createSender":{"name":"createSender","async":true,"parameters":[],"returnType":"Promise<MessageSenderInterface>","isStatic":false,"isPublic":true},"getCredentials":{"name":"getCredentials","async":true,"parameters":[],"returnType":"Promise<Record<string, unknown> | null>","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableStrategy":"sti","api":{"include":["list","get"]},"mcp":{"include":["list","get"]},"cli":{"include":["list","get"]},"tenantScoped":{"mode":"optional"},"conflictColumns":["tenant_id","slug","context","_meta_type"]},"extends":"SmrtObject","exportName":"Account","collectionExportName":"AccountCollection","displayLabelField":"name","validationRules":[{"field":"isActive","rule":"required","fieldType":"boolean"}],"schema":{"tableName":"accounts","ddl":"CREATE TABLE IF NOT EXISTS \\"accounts\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"_meta_type\\" TEXT NOT NULL,\\n \\"_meta_data\\" JSON,\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"name\\" TEXT,\\n \\"provider_type\\" TEXT,\\n \\"channel_type\\" TEXT,\\n \\"credential_secret_id\\" TEXT,\\n \\"is_active\\" BOOLEAN DEFAULT TRUE,\\n \\"owner_user_id\\" UUID,\\n \\"label\\" TEXT,\\n \\"connection_status\\" TEXT,\\n \\"status_message\\" TEXT,\\n \\"last_sync_at\\" TIMESTAMP,\\n \\"settings\\" TEXT,\\n \\"configuration\\" TEXT,\\n \\"email\\" TEXT,\\n \\"sync_interval_minutes\\" INTEGER DEFAULT 60,\\n \\"sync_cursor\\" TEXT,\\n \\"backfill_since\\" TIMESTAMP,\\n \\"cursor_horizon\\" TIMESTAMP,\\n \\"last_sync_error\\" TEXT,\\n \\"backlog\\" BOOLEAN DEFAULT FALSE,\\n \\"workspace_id\\" TEXT,\\n \\"workspace_name\\" TEXT,\\n \\"bot_user_id\\" TEXT,\\n \\"handle\\" TEXT,\\n \\"twitter_user_id\\" TEXT\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"_meta_type":{"type":"TEXT","notNull":true},"_meta_data":{"type":"JSON","notNull":false},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false},"name":{"type":"TEXT","notNull":false},"provider_type":{"type":"TEXT","notNull":false},"channel_type":{"type":"TEXT","notNull":false},"credential_secret_id":{"type":"TEXT","notNull":false},"is_active":{"type":"BOOLEAN","notNull":false,"default":true},"owner_user_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false},"label":{"type":"TEXT","notNull":false},"connection_status":{"type":"TEXT","notNull":false},"status_message":{"type":"TEXT","notNull":false},"last_sync_at":{"type":"TIMESTAMP","notNull":false},"settings":{"type":"TEXT","notNull":false},"configuration":{"type":"TEXT","notNull":false},"email":{"type":"TEXT","notNull":false},"sync_interval_minutes":{"type":"INTEGER","notNull":false,"default":60},"sync_cursor":{"type":"TEXT","notNull":false},"backfill_since":{"type":"TIMESTAMP","notNull":false},"cursor_horizon":{"type":"TIMESTAMP","notNull":false},"last_sync_error":{"type":"TEXT","notNull":false},"backlog":{"type":"BOOLEAN","notNull":false,"default":false},"workspace_id":{"type":"TEXT","notNull":false},"workspace_name":{"type":"TEXT","notNull":false},"bot_user_id":{"type":"TEXT","notNull":false},"handle":{"type":"TEXT","notNull":false},"twitter_user_id":{"type":"TEXT","notNull":false}},"indexes":[{"name":"accounts_slug_context_meta_type_idx","columns":["tenant_id","slug","context","_meta_type"],"unique":true,"nullsNotDistinct":true},{"name":"accounts_meta_type_idx","columns":["_meta_type"]},{"name":"accounts_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"accounts_owner_user_id_idx","columns":["owner_user_id"]}],"checks":[{"name":"smrt_ck_81229bbfe8e3","columns":["backlog"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:EmailAccount') OR \\"backlog\\" IS NOT NULL"},{"name":"smrt_ck_1f9c5f0ee488","columns":["sync_interval_minutes"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:EmailAccount') OR \\"sync_interval_minutes\\" IS NOT NULL"}],"version":"f48d7a23"},"importPath":"@happyvertical/smrt-messages"},"@happyvertical/smrt-messages:Attachment":{"name":"attachment","className":"Attachment","qualifiedName":"@happyvertical/smrt-messages:Attachment","collection":"attachments","filePath":"src/models/Attachment.ts","packageName":"@happyvertical/smrt-messages","fields":{"tenantId":{"type":"text","_meta":{"__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":false,"autoPopulate":true,"nullable":true,"mode":"optional","field":"tenantId","allowSuperAdminBypass":false},"__statedOptions":["sqlType","nullable","__tenancy","required"],"sqlType":"UUID","nullable":true,"required":false},"required":false},"messageId":{"type":"foreignKey","_meta":{"__statedOptions":["related"]},"required":false,"related":"Message"},"accountId":{"type":"foreignKey","_meta":{"__statedOptions":["related"]},"required":false,"related":"Account"},"filename":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"contentType":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"size":{"type":"integer","_meta":{"__statedOptions":["default"]},"required":true,"default":0},"contentId":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"contentDisposition":{"type":"text","_meta":{"__statedOptions":["default","enum"]},"required":false,"default":"attachment","enum":["attachment","inline"]},"filePath":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"sourceUrl":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"createdAt":{"type":"text","_meta":{"__statedOptions":[]},"required":false}},"methods":{"loadFromId":{"name":"loadFromId","async":true,"parameters":[],"returnType":"any","isStatic":false,"isPublic":true},"loadFromSlug":{"name":"loadFromSlug","async":true,"parameters":[],"returnType":"any","isStatic":false,"isPublic":true},"getMessage":{"name":"getMessage","async":true,"parameters":[],"returnType":"any","isStatic":false,"isPublic":true},"isImage":{"name":"isImage","async":false,"parameters":[],"returnType":"boolean","isStatic":false,"isPublic":true},"isPdf":{"name":"isPdf","async":false,"parameters":[],"returnType":"boolean","isStatic":false,"isPublic":true},"isInline":{"name":"isInline","async":false,"parameters":[],"returnType":"boolean","isStatic":false,"isPublic":true},"getExtension":{"name":"getExtension","async":false,"parameters":[],"returnType":"string","isStatic":false,"isPublic":true},"getFormattedSize":{"name":"getFormattedSize","async":false,"parameters":[],"returnType":"string","isStatic":false,"isPublic":true},"hasExternalFile":{"name":"hasExternalFile","async":false,"parameters":[],"returnType":"boolean","isStatic":false,"isPublic":true},"readContent":{"name":"readContent","async":true,"parameters":[],"returnType":"Promise<Buffer | null>","isStatic":false,"isPublic":true}},"decoratorConfig":{"api":{"include":["list","get","create","delete"]},"mcp":{"include":["list","get"]},"cli":{"skipApiCheck":true},"tenantScoped":{"mode":"optional"},"conflictColumns":["tenant_id","slug","context"]},"extends":"SmrtObject","exportName":"Attachment","collectionExportName":"AttachmentCollection","validationRules":[{"field":"size","rule":"required","fieldType":"integer"}],"schema":{"tableName":"attachments","ddl":"CREATE TABLE IF NOT EXISTS \\"attachments\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"message_id\\" UUID,\\n \\"account_id\\" UUID,\\n \\"filename\\" TEXT,\\n \\"content_type\\" TEXT,\\n \\"size\\" INTEGER NOT NULL DEFAULT 0,\\n \\"content_id\\" TEXT,\\n \\"content_disposition\\" TEXT DEFAULT 'attachment',\\n \\"file_path\\" TEXT,\\n \\"source_url\\" TEXT\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false,"unique":false},"message_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"messages","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"account_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"accounts","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"filename":{"type":"TEXT","notNull":false,"unique":false},"content_type":{"type":"TEXT","notNull":false,"unique":false},"size":{"type":"INTEGER","notNull":true,"unique":false,"default":0},"content_id":{"type":"TEXT","notNull":false,"unique":false},"content_disposition":{"type":"TEXT","notNull":false,"unique":false,"default":"attachment"},"file_path":{"type":"TEXT","notNull":false,"unique":false},"source_url":{"type":"TEXT","notNull":false,"unique":false}},"indexes":[{"name":"attachments_slug_context_idx","columns":["tenant_id","slug","context"],"unique":true,"nullsNotDistinct":true},{"name":"attachments_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"attachments_message_id_idx","columns":["message_id"]},{"name":"attachments_account_id_idx","columns":["account_id"]}],"version":"3f32531c"},"importPath":"@happyvertical/smrt-messages"},"@happyvertical/smrt-messages:Blacklist":{"name":"blacklist","className":"Blacklist","qualifiedName":"@happyvertical/smrt-messages:Blacklist","collection":"blacklists","description":"Block entries for email filtering","filePath":"src/models/Blacklist.ts","packageName":"@happyvertical/smrt-messages","fields":{"pattern":{"type":"text","_meta":{"__statedOptions":["default"]},"required":false,"default":""},"type":{"type":"text","_meta":{"__statedOptions":["default","enum"]},"required":false,"default":"email","enum":["email","domain","regex"]},"reason":{"type":"text","_meta":{"__statedOptions":["default"]},"required":false,"default":""},"autoArchive":{"type":"boolean","_meta":{"__statedOptions":["default"]},"required":false,"default":true},"tenantId":{"type":"text","_meta":{"__tenancy":{"isTenantIdField":true,"mode":"required","field":"tenantId","autoFilter":true,"autoPopulate":true,"allowSuperAdminBypass":false},"generated":true,"source":"tenantScoped_decorator","sqlType":"UUID"},"required":true}},"methods":{"matches":{"name":"matches","async":false,"parameters":[{"name":"email","type":"string","optional":false}],"returnType":"boolean","isStatic":false,"isPublic":true}},"decoratorConfig":{"api":{"include":["list","get","create","update","delete"]},"cli":{"skipApiCheck":true},"tenantScoped":true,"conflictColumns":["tenant_id","slug","context"]},"extends":"SmrtObject","exportName":"Blacklist","collectionExportName":"BlacklistCollection","validationRules":[],"schema":{"tableName":"blacklists","ddl":"CREATE TABLE IF NOT EXISTS \\"blacklists\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"pattern\\" TEXT DEFAULT '',\\n \\"type\\" TEXT DEFAULT 'email',\\n \\"reason\\" TEXT DEFAULT '',\\n \\"auto_archive\\" BOOLEAN DEFAULT TRUE,\\n \\"tenant_id\\" UUID NOT NULL\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"pattern":{"type":"TEXT","notNull":false,"unique":false,"default":""},"type":{"type":"TEXT","notNull":false,"unique":false,"default":"email"},"reason":{"type":"TEXT","notNull":false,"unique":false,"default":""},"auto_archive":{"type":"BOOLEAN","notNull":false,"unique":false,"default":true},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false}},"indexes":[{"name":"blacklists_slug_context_idx","columns":["tenant_id","slug","context"],"unique":true},{"name":"blacklists_tenant_id_created_at_idx","columns":["tenant_id","created_at"]}],"version":"478c8724"},"importPath":"@happyvertical/smrt-messages"},"@happyvertical/smrt-messages:Email":{"name":"email","className":"Email","qualifiedName":"@happyvertical/smrt-messages:Email","collection":"messages","filePath":"src/models/Email.ts","packageName":"@happyvertical/smrt-messages","fields":{"created_at":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"updated_at":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"tenantId":{"type":"text","_meta":{"__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":false,"autoPopulate":true,"nullable":true},"__statedOptions":["sqlType","nullable","__tenancy","required"],"required":false,"sqlType":"UUID","nullable":true},"required":false},"accountId":{"type":"foreignKey","_meta":{"__statedOptions":["description","related"],"description":"The connected account used to receive or send this message."},"required":false,"related":"Account","description":"The connected account used to receive or send this message."},"personaId":{"type":"crossPackageRef","_meta":{"__statedOptions":["nullable","description","related","required"],"required":false,"description":"The assistant identity associated with this message, when one was used.","nullable":true},"required":false,"related":"@happyvertical/smrt-personas:AgentPersona","description":"The assistant identity associated with this message, when one was used."},"endpointId":{"type":"foreignKey","_meta":{"__statedOptions":["description","related"],"description":"The saved destination used to deliver this message."},"required":false,"related":"MessagingEndpoint","description":"The saved destination used to deliver this message."},"correlationId":{"type":"text","_meta":{"__statedOptions":["description"],"description":"A tracking reference that connects this message to related activity."},"required":false,"description":"A tracking reference that connects this message to related activity."},"threadId":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The conversation this message belongs to."},"required":false,"description":"The conversation this message belongs to."},"subject":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The subject shown in the message list."},"required":false,"description":"The subject shown in the message list."},"body":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The message content in plain text."},"required":false,"description":"The message content in plain text."},"fromAddress":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The address the message was sent from."},"required":false,"description":"The address the message was sent from."},"fromName":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The sender name shown beside their address."},"required":false,"description":"The sender name shown beside their address."},"toAddresses":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The people or addresses receiving this message."},"required":false,"description":"The people or addresses receiving this message."},"date":{"type":"datetime","_meta":{"__statedOptions":["description"],"description":"When the message was sent or received."},"required":false,"description":"When the message was sent or received."},"isRead":{"type":"boolean","_meta":{"__statedOptions":["description","default"],"description":"Whether this message has been marked as read."},"required":true,"default":false,"description":"Whether this message has been marked as read."},"isFlagged":{"type":"boolean","_meta":{"__statedOptions":["description","default"],"description":"Whether this message is flagged for follow-up."},"required":true,"default":false,"description":"Whether this message is flagged for follow-up."},"hasAttachments":{"type":"boolean","_meta":{"__statedOptions":["description","default"],"description":"Whether files are attached to this message."},"required":true,"default":false,"description":"Whether files are attached to this message."},"size":{"type":"integer","_meta":{"__statedOptions":["description","default"],"description":"The size of the message in bytes."},"required":true,"default":0,"description":"The size of the message in bytes."},"metadata":{"type":"text","_meta":{"__statedOptions":["description"],"description":"Additional details supplied by the messaging connection."},"required":false,"description":"Additional details supplied by the messaging connection."},"sendStatus":{"type":"text","_meta":{"__statedOptions":["description","default","enum"],"description":"The latest sending state: draft, sending, sent, or failed. Received mail may also show draft here."},"required":false,"default":"draft","description":"The latest sending state: draft, sending, sent, or failed. Received mail may also show draft here.","enum":["draft","pending","sending","sent","failed","scheduled"]},"sentAt":{"type":"datetime","_meta":{"__statedOptions":["description"],"description":"When the message was successfully sent."},"required":false,"description":"When the message was successfully sent."},"sendError":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The reason the latest send attempt failed."},"required":false,"description":"The reason the latest send attempt failed."},"retryCount":{"type":"integer","_meta":{"__statedOptions":["description","default"],"description":"How many times delivery has been retried."},"required":true,"default":0,"description":"How many times delivery has been retried."},"maxRetries":{"type":"integer","_meta":{"__statedOptions":["description","default"],"description":"The maximum number of delivery retries allowed."},"required":true,"default":3,"description":"The maximum number of delivery retries allowed."},"scheduledSendAt":{"type":"datetime","_meta":{"__statedOptions":["description"],"description":"When this message is scheduled to be sent."},"required":false,"description":"When this message is scheduled to be sent."},"inReplyToMessageId":{"type":"foreignKey","_meta":{"__statedOptions":["description","related"],"description":"The earlier message this one replies to."},"required":false,"related":"Message","description":"The earlier message this one replies to."},"createdAt":{"type":"text","_meta":{"__statedOptions":["description"],"description":"When this message was recorded."},"required":false,"description":"When this message was recorded."},"updatedAt":{"type":"text","_meta":{"__statedOptions":["description"],"description":"When this message was last changed."},"required":false,"description":"When this message was last changed."},"messageId":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The email reference assigned by the sender for tracking replies."},"required":false,"description":"The email reference assigned by the sender for tracking replies."},"inReplyTo":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The sender-assigned reference of the email being replied to."},"required":false,"description":"The sender-assigned reference of the email being replied to."},"providerMessageId":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The mail server's own id for this email, used to keep mailbox sync from storing it twice."},"required":false,"description":"The mail server's own id for this email, used to keep mailbox sync from storing it twice."},"ccAddresses":{"type":"text","_meta":{"__statedOptions":["description"],"description":"Recipients receiving a visible copy of this email."},"required":false,"description":"Recipients receiving a visible copy of this email."},"bccAddresses":{"type":"text","_meta":{"__statedOptions":["description"],"description":"Recipients receiving a copy without appearing in the visible recipient list."},"required":false,"description":"Recipients receiving a copy without appearing in the visible recipient list."},"replyToAddress":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The address replies should be sent to."},"required":false,"description":"The address replies should be sent to."},"replyToName":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The name associated with the reply address."},"required":false,"description":"The name associated with the reply address."},"textBody":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The plain-text version of the email."},"required":false,"description":"The plain-text version of the email."},"htmlBody":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The formatted version of the email."},"required":false,"description":"The formatted version of the email."},"folderId":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The mailbox folder reference supplied by the email connection."},"required":false,"description":"The mailbox folder reference supplied by the email connection."},"folderPath":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The location of this email within the mailbox folders."},"required":false,"description":"The location of this email within the mailbox folders."},"labels":{"type":"text","_meta":{"__statedOptions":["description"],"description":"Labels applied to this email by the mailbox provider."},"required":false,"description":"Labels applied to this email by the mailbox provider."},"flags":{"type":"text","_meta":{"__statedOptions":["description"],"description":"Mailbox markers such as read, answered, or flagged."},"required":false,"description":"Mailbox markers such as read, answered, or flagged."},"isAnswered":{"type":"boolean","_meta":{"__statedOptions":["description","default"],"description":"Whether this email has been replied to."},"required":true,"default":false,"description":"Whether this email has been replied to."},"isDraft":{"type":"boolean","_meta":{"__statedOptions":["description","default"],"description":"Whether this email is saved as an unfinished draft."},"required":true,"default":false,"description":"Whether this email is saved as an unfinished draft."},"rawMessage":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The original email content as received from the mail server."},"required":false,"description":"The original email content as received from the mail server."},"headers":{"type":"text","_meta":{"__statedOptions":["description"],"description":"Delivery and routing details included with the email."},"required":false,"description":"Delivery and routing details included with the email."}},"methods":{"save":{"name":"save","async":true,"parameters":[{"name":"options","type":"SmrtSaveOptions","optional":true}],"returnType":"Promise<this>","isStatic":false,"isPublic":true},"delete":{"name":"delete","async":true,"parameters":[{"name":"options","type":"object","optional":true,"memberTypes":["Date | string"]}],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"getToAddresses":{"name":"getToAddresses","async":false,"parameters":[],"returnType":"Array<object>","isStatic":false,"isPublic":true},"setToAddresses":{"name":"setToAddresses","async":false,"parameters":[{"name":"addresses","type":"Array<object>","optional":false,"memberTypes":["string"]}],"returnType":"void","isStatic":false,"isPublic":true},"getMetadata":{"name":"getMetadata","async":false,"parameters":[],"returnType":"Record<string, unknown>","isStatic":false,"isPublic":true},"setMetadata":{"name":"setMetadata","async":false,"parameters":[{"name":"data","type":"Record<string, unknown>","optional":false}],"returnType":"void","isStatic":false,"isPublic":true},"markRead":{"name":"markRead","async":true,"parameters":[],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"markUnread":{"name":"markUnread","async":true,"parameters":[],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"toggleFlagged":{"name":"toggleFlagged","async":true,"parameters":[],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"isUnread":{"name":"isUnread","async":false,"parameters":[],"returnType":"boolean","isStatic":false,"isPublic":true},"getPreview":{"name":"getPreview","async":false,"parameters":[{"name":"maxLength","type":"any","optional":true}],"returnType":"string","isStatic":false,"isPublic":true},"loadFromId":{"name":"loadFromId","async":true,"parameters":[],"returnType":"any","isStatic":false,"isPublic":true},"loadFromSlug":{"name":"loadFromSlug","async":true,"parameters":[],"returnType":"any","isStatic":false,"isPublic":true},"getAccount":{"name":"getAccount","async":true,"parameters":[],"returnType":"any","isStatic":false,"isPublic":true},"getEndpoint":{"name":"getEndpoint","async":true,"parameters":[],"returnType":"any","isStatic":false,"isPublic":true},"getThreadMessages":{"name":"getThreadMessages","async":true,"parameters":[],"returnType":"Promise<Message[]>","isStatic":false,"isPublic":true},"getAttachments":{"name":"getAttachments","async":true,"parameters":[],"returnType":"any","isStatic":false,"isPublic":true},"send":{"name":"send","async":true,"parameters":[{"name":"options","type":"SendEmailOptions","optional":true}],"returnType":"Promise<MessageSendResult>","isStatic":false,"isPublic":true},"isSendOutcomeUnknown":{"name":"isSendOutcomeUnknown","async":false,"parameters":[],"returnType":"boolean","isStatic":false,"isPublic":true},"abandonSendAttempt":{"name":"abandonSendAttempt","async":true,"parameters":[{"name":"reason","type":"string","optional":false}],"returnType":"Promise<boolean>","isStatic":false,"isPublic":true},"retrySend":{"name":"retrySend","async":true,"parameters":[{"name":"options","type":"SendEmailOptions","optional":true}],"returnType":"Promise<MessageSendResult>","isStatic":false,"isPublic":true},"createReply":{"name":"createReply","async":false,"parameters":[{"name":"options","type":"object","optional":true,"memberTypes":["boolean"]}],"returnType":"Email","isStatic":false,"isPublic":true},"createForward":{"name":"createForward","async":false,"parameters":[],"returnType":"Email","isStatic":false,"isPublic":true},"triage":{"name":"triage","async":true,"parameters":[{"name":"action","type":"MailTriageAction","optional":false}],"returnType":"Promise<MailTriageResult>","isStatic":false,"isPublic":true},"getCcAddresses":{"name":"getCcAddresses","async":false,"parameters":[],"returnType":"Array<object>","isStatic":false,"isPublic":true},"getBccAddresses":{"name":"getBccAddresses","async":false,"parameters":[],"returnType":"Array<object>","isStatic":false,"isPublic":true},"getLabels":{"name":"getLabels","async":false,"parameters":[],"returnType":"string[]","isStatic":false,"isPublic":true},"setLabels":{"name":"setLabels","async":false,"parameters":[{"name":"labels","type":"string[]","optional":false}],"returnType":"void","isStatic":false,"isPublic":true},"getFlags":{"name":"getFlags","async":false,"parameters":[],"returnType":"string[]","isStatic":false,"isPublic":true},"setFlags":{"name":"setFlags","async":false,"parameters":[{"name":"flags","type":"string[]","optional":false}],"returnType":"void","isStatic":false,"isPublic":true},"getHeaders":{"name":"getHeaders","async":false,"parameters":[],"returnType":"Record<string, string | string[]>","isStatic":false,"isPublic":true},"setHeaders":{"name":"setHeaders","async":false,"parameters":[{"name":"headers","type":"Record<string, string | string[]>","optional":false}],"returnType":"void","isStatic":false,"isPublic":true},"getFolder":{"name":"getFolder","async":true,"parameters":[],"returnType":"any","isStatic":false,"isPublic":true},"getThreadEmails":{"name":"getThreadEmails","async":true,"parameters":[],"returnType":"Promise<Email[]>","isStatic":false,"isPublic":true},"getReferences":{"name":"getReferences","async":false,"parameters":[],"returnType":"string[]","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableStrategy":"sti","api":{"include":["list","get","create","update","delete"]},"mcp":{"include":["list","get"]},"cli":{"skipApiCheck":true},"widenParentExposure":{"api":["create","update","delete"]},"tableName":"messages"},"extends":"Message","exportName":"Email","collectionExportName":"EmailCollection","validationRules":[{"field":"isRead","rule":"required","fieldType":"boolean"},{"field":"isFlagged","rule":"required","fieldType":"boolean"},{"field":"hasAttachments","rule":"required","fieldType":"boolean"},{"field":"size","rule":"required","fieldType":"integer"},{"field":"retryCount","rule":"required","fieldType":"integer"},{"field":"maxRetries","rule":"required","fieldType":"integer"},{"field":"isAnswered","rule":"required","fieldType":"boolean"},{"field":"isDraft","rule":"required","fieldType":"boolean"}],"schema":{"tableName":"messages","ddl":"CREATE TABLE IF NOT EXISTS \\"messages\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"_meta_type\\" TEXT NOT NULL,\\n \\"_meta_data\\" JSON,\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"account_id\\" UUID,\\n \\"persona_id\\" UUID,\\n \\"endpoint_id\\" UUID,\\n \\"correlation_id\\" TEXT,\\n \\"thread_id\\" TEXT,\\n \\"subject\\" TEXT,\\n \\"body\\" TEXT,\\n \\"from_address\\" TEXT,\\n \\"from_name\\" TEXT,\\n \\"to_addresses\\" TEXT,\\n \\"date\\" TIMESTAMP,\\n \\"is_read\\" BOOLEAN DEFAULT FALSE,\\n \\"is_flagged\\" BOOLEAN DEFAULT FALSE,\\n \\"has_attachments\\" BOOLEAN DEFAULT FALSE,\\n \\"size\\" INTEGER DEFAULT 0,\\n \\"metadata\\" TEXT,\\n \\"send_status\\" TEXT DEFAULT 'draft',\\n \\"sent_at\\" TIMESTAMP,\\n \\"send_error\\" TEXT,\\n \\"retry_count\\" INTEGER DEFAULT 0,\\n \\"max_retries\\" INTEGER DEFAULT 3,\\n \\"scheduled_send_at\\" TIMESTAMP,\\n \\"in_reply_to_message_id\\" UUID,\\n \\"message_id\\" TEXT,\\n \\"in_reply_to\\" TEXT,\\n \\"provider_message_id\\" TEXT,\\n \\"cc_addresses\\" TEXT,\\n \\"bcc_addresses\\" TEXT,\\n \\"reply_to_address\\" TEXT,\\n \\"reply_to_name\\" TEXT,\\n \\"text_body\\" TEXT,\\n \\"html_body\\" TEXT,\\n \\"folder_id\\" TEXT,\\n \\"folder_path\\" TEXT,\\n \\"labels\\" TEXT,\\n \\"flags\\" TEXT,\\n \\"is_answered\\" BOOLEAN DEFAULT FALSE,\\n \\"is_draft\\" BOOLEAN DEFAULT FALSE,\\n \\"raw_message\\" TEXT,\\n \\"headers\\" TEXT,\\n \\"channel_id\\" TEXT,\\n \\"channel_name\\" TEXT,\\n \\"slack_ts\\" TEXT,\\n \\"slack_thread_ts\\" TEXT,\\n \\"reactions\\" TEXT,\\n \\"is_edited\\" BOOLEAN DEFAULT FALSE,\\n \\"message_type\\" TEXT,\\n \\"blocks\\" TEXT,\\n \\"tweet_id\\" TEXT,\\n \\"retweet_count\\" INTEGER DEFAULT 0,\\n \\"like_count\\" INTEGER DEFAULT 0,\\n \\"reply_count\\" INTEGER DEFAULT 0,\\n \\"is_retweet\\" BOOLEAN DEFAULT FALSE,\\n \\"is_reply\\" BOOLEAN DEFAULT FALSE,\\n \\"media_urls\\" TEXT,\\n \\"hashtags\\" TEXT,\\n \\"mentions\\" TEXT\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"_meta_type":{"type":"TEXT","notNull":true},"_meta_data":{"type":"JSON","notNull":false},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false},"account_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"foreignKey":{"table":"accounts","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"persona_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false},"endpoint_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"foreignKey":{"table":"messaging_endpoints","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"correlation_id":{"type":"TEXT","notNull":false},"thread_id":{"type":"TEXT","notNull":false},"subject":{"type":"TEXT","notNull":false},"body":{"type":"TEXT","notNull":false},"from_address":{"type":"TEXT","notNull":false},"from_name":{"type":"TEXT","notNull":false},"to_addresses":{"type":"TEXT","notNull":false},"date":{"type":"TIMESTAMP","notNull":false},"is_read":{"type":"BOOLEAN","notNull":false,"default":false},"is_flagged":{"type":"BOOLEAN","notNull":false,"default":false},"has_attachments":{"type":"BOOLEAN","notNull":false,"default":false},"size":{"type":"INTEGER","notNull":false,"default":0},"metadata":{"type":"TEXT","notNull":false},"send_status":{"type":"TEXT","notNull":false,"default":"draft"},"sent_at":{"type":"TIMESTAMP","notNull":false},"send_error":{"type":"TEXT","notNull":false},"retry_count":{"type":"INTEGER","notNull":false,"default":0},"max_retries":{"type":"INTEGER","notNull":false,"default":3},"scheduled_send_at":{"type":"TIMESTAMP","notNull":false},"in_reply_to_message_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"foreignKey":{"table":"messages","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"message_id":{"type":"TEXT","notNull":false},"in_reply_to":{"type":"TEXT","notNull":false},"provider_message_id":{"type":"TEXT","notNull":false},"cc_addresses":{"type":"TEXT","notNull":false},"bcc_addresses":{"type":"TEXT","notNull":false},"reply_to_address":{"type":"TEXT","notNull":false},"reply_to_name":{"type":"TEXT","notNull":false},"text_body":{"type":"TEXT","notNull":false},"html_body":{"type":"TEXT","notNull":false},"folder_id":{"type":"TEXT","notNull":false},"folder_path":{"type":"TEXT","notNull":false},"labels":{"type":"TEXT","notNull":false},"flags":{"type":"TEXT","notNull":false},"is_answered":{"type":"BOOLEAN","notNull":false,"default":false},"is_draft":{"type":"BOOLEAN","notNull":false,"default":false},"raw_message":{"type":"TEXT","notNull":false},"headers":{"type":"TEXT","notNull":false},"channel_id":{"type":"TEXT","notNull":false},"channel_name":{"type":"TEXT","notNull":false},"slack_ts":{"type":"TEXT","notNull":false},"slack_thread_ts":{"type":"TEXT","notNull":false},"reactions":{"type":"TEXT","notNull":false},"is_edited":{"type":"BOOLEAN","notNull":false,"default":false},"message_type":{"type":"TEXT","notNull":false},"blocks":{"type":"TEXT","notNull":false},"tweet_id":{"type":"TEXT","notNull":false},"retweet_count":{"type":"INTEGER","notNull":false,"default":0},"like_count":{"type":"INTEGER","notNull":false,"default":0},"reply_count":{"type":"INTEGER","notNull":false,"default":0},"is_retweet":{"type":"BOOLEAN","notNull":false,"default":false},"is_reply":{"type":"BOOLEAN","notNull":false,"default":false},"media_urls":{"type":"TEXT","notNull":false},"hashtags":{"type":"TEXT","notNull":false},"mentions":{"type":"TEXT","notNull":false}},"indexes":[{"name":"messages_slug_context_meta_type_idx","columns":["tenant_id","slug","context","_meta_type"],"unique":true,"nullsNotDistinct":true},{"name":"messages_meta_type_idx","columns":["_meta_type"]},{"name":"messages_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"messages_account_id_idx","columns":["account_id"]},{"name":"messages_persona_id_idx","columns":["persona_id"]},{"name":"messages_endpoint_id_idx","columns":["endpoint_id"]},{"name":"messages_in_reply_to_message_id_idx","columns":["in_reply_to_message_id"]}],"checks":[{"name":"smrt_ck_d0024f738cf4","columns":["is_answered"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:Email') OR \\"is_answered\\" IS NOT NULL"},{"name":"smrt_ck_0adcd2453c81","columns":["is_draft"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:Email') OR \\"is_draft\\" IS NOT NULL"},{"name":"smrt_ck_428e155c9609","columns":["is_edited"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:SlackMessage') OR \\"is_edited\\" IS NOT NULL"},{"name":"smrt_ck_a17af99e85e3","columns":["is_reply"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:Tweet') OR \\"is_reply\\" IS NOT NULL"},{"name":"smrt_ck_3e30563cba58","columns":["is_retweet"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:Tweet') OR \\"is_retweet\\" IS NOT NULL"},{"name":"smrt_ck_bab2c772ebe6","columns":["like_count"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:Tweet') OR \\"like_count\\" IS NOT NULL"},{"name":"smrt_ck_c6ad8d47bbc8","columns":["reply_count"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:Tweet') OR \\"reply_count\\" IS NOT NULL"},{"name":"smrt_ck_43a00e1c098d","columns":["retweet_count"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:Tweet') OR \\"retweet_count\\" IS NOT NULL"}],"version":"f48614e6"},"importPath":"@happyvertical/smrt-messages"},"@happyvertical/smrt-messages:EmailAccount":{"name":"emailaccount","className":"EmailAccount","qualifiedName":"@happyvertical/smrt-messages:EmailAccount","collection":"accounts","filePath":"src/models/EmailAccount.ts","packageName":"@happyvertical/smrt-messages","fields":{"created_at":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"updated_at":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"tenantId":{"type":"text","_meta":{"__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":false,"autoPopulate":true,"nullable":true},"__statedOptions":["sqlType","nullable","__tenancy","required"],"required":false,"sqlType":"UUID","nullable":true},"required":false},"name":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The display name for this connected messaging account."},"required":false,"description":"The display name for this connected messaging account."},"providerType":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The service that connects this account to your application."},"required":false,"description":"The service that connects this account to your application."},"channelType":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The kind of messaging this account supports, such as email or chat."},"required":false,"description":"The kind of messaging this account supports, such as email or chat."},"credentialSecretId":{"type":"text","_meta":{"__statedOptions":["sensitive","readonly"],"sensitive":true,"readonly":true},"required":false,"sensitive":true,"readonly":true},"isActive":{"type":"boolean","_meta":{"__statedOptions":["description","default"],"description":"Whether this account is enabled for messaging."},"required":true,"default":true,"description":"Whether this account is enabled for messaging."},"ownerUserId":{"type":"crossPackageRef","_meta":{"__statedOptions":["description","related"],"description":"The person who owns this account and decides who else may use it."},"required":false,"related":"@happyvertical/smrt-users:User","description":"The person who owns this account and decides who else may use it."},"label":{"type":"text","_meta":{"__statedOptions":["description"],"description":"A short name shown beside this account, such as Support or Personal."},"required":false,"description":"A short name shown beside this account, such as Support or Personal."},"connectionStatus":{"type":"text","_meta":{"__statedOptions":["description"],"description":"Whether the saved sign-in still works: connected, or needs_reconnect after the server refused it."},"required":false,"description":"Whether the saved sign-in still works: connected, or needs_reconnect after the server refused it."},"statusMessage":{"type":"text","_meta":{"__statedOptions":["description"],"description":"Why the account needs attention, in plain words."},"required":false,"description":"Why the account needs attention, in plain words."},"lastSyncAt":{"type":"datetime","_meta":{"__statedOptions":["description"],"description":"When this account last checked for new messages."},"required":false,"description":"When this account last checked for new messages."},"settings":{"type":"text","_meta":{"__statedOptions":["sensitive","readonly"],"sensitive":true,"readonly":true},"required":false,"sensitive":true,"readonly":true},"configuration":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The public connection settings for this account; credentials are stored separately."},"required":false,"description":"The public connection settings for this account; credentials are stored separately."},"createdAt":{"type":"text","_meta":{"__statedOptions":["description"],"description":"When this account was added."},"required":false,"description":"When this account was added."},"updatedAt":{"type":"text","_meta":{"__statedOptions":["description"],"description":"When this account was last changed."},"required":false,"description":"When this account was last changed."},"email":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The email address associated with this mailbox."},"required":false,"description":"The email address associated with this mailbox."},"syncIntervalMinutes":{"type":"integer","_meta":{"__statedOptions":["description","default"],"description":"The time in minutes between scheduled mailbox checks."},"required":true,"default":60,"description":"The time in minutes between scheduled mailbox checks."},"syncCursor":{"type":"text","_meta":{"__statedOptions":["sensitive","readonly","description"],"description":"Where the next mailbox check resumes.","sensitive":true,"readonly":true},"required":false,"description":"Where the next mailbox check resumes.","sensitive":true,"readonly":true},"backfillSince":{"type":"datetime","_meta":{"__statedOptions":["description"],"description":"Mail older than this date is not stored. Empty means the whole mailbox."},"required":false,"description":"Mail older than this date is not stored. Empty means the whole mailbox."},"cursorHorizon":{"type":"datetime","_meta":{"__statedOptions":["readonly","description"],"description":"The backfill date the saved mailbox position was built under.","readonly":true},"required":false,"description":"The backfill date the saved mailbox position was built under.","readonly":true},"lastSyncError":{"type":"text","_meta":{"__statedOptions":["description"],"description":"Why the last mailbox check failed, if it did."},"required":false,"description":"Why the last mailbox check failed, if it did."},"backlog":{"type":"boolean","_meta":{"__statedOptions":["description","default"],"description":"Whether more mail was still waiting after the last check."},"required":true,"default":false,"description":"Whether more mail was still waiting after the last check."}},"methods":{"getSettings":{"name":"getSettings","async":false,"parameters":[],"returnType":"Record<string, unknown>","isStatic":false,"isPublic":true},"setSettings":{"name":"setSettings","async":false,"parameters":[{"name":"settings","type":"Record<string, unknown>","optional":false}],"returnType":"void","isStatic":false,"isPublic":true},"getConfiguration":{"name":"getConfiguration","async":false,"parameters":[],"returnType":"Record<string, unknown>","isStatic":false,"isPublic":true},"setConfiguration":{"name":"setConfiguration","async":false,"parameters":[{"name":"configuration","type":"Record<string, unknown>","optional":false}],"returnType":"void","isStatic":false,"isPublic":true},"markNeedsReconnect":{"name":"markNeedsReconnect","async":true,"parameters":[{"name":"reason","type":"string","optional":false}],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"markConnected":{"name":"markConnected","async":true,"parameters":[],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"activate":{"name":"activate","async":true,"parameters":[],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"deactivate":{"name":"deactivate","async":true,"parameters":[],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"setCredentials":{"name":"setCredentials","async":true,"parameters":[{"name":"credentials","type":"Record<string, unknown>","optional":false},{"name":"options","type":"object","optional":true,"memberTypes":["string"]}],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"removeCredentials":{"name":"removeCredentials","async":true,"parameters":[],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"createSender":{"name":"createSender","async":true,"parameters":[],"returnType":"Promise<MessageSenderInterface>","isStatic":false,"isPublic":true},"getCredentials":{"name":"getCredentials","async":true,"parameters":[],"returnType":"Promise<Record<string, unknown> | null>","isStatic":false,"isPublic":true},"childOptions":{"name":"childOptions","async":false,"parameters":[],"returnType":"Record<string, unknown>","isStatic":false,"isPublic":true},"createClient":{"name":"createClient","async":true,"parameters":[],"returnType":"any","isStatic":false,"isPublic":true},"readIntakeMessage":{"name":"readIntakeMessage","async":true,"parameters":[{"name":"locator","type":"string","optional":false},{"name":"maxBytes","type":"number","optional":false},{"name":"imapIdentity","type":"object","optional":true,"memberTypes":["string","number"]}],"returnType":"any","isStatic":false,"isPublic":true},"syncFrom":{"name":"syncFrom","async":true,"parameters":[{"name":"options","type":"SyncOptions","optional":true}],"returnType":"Promise<SyncResult>","isStatic":false,"isPublic":true},"syncChanges":{"name":"syncChanges","async":true,"parameters":[{"name":"options","type":"MailSyncOptions","optional":true}],"returnType":"Promise<MailSyncResult>","isStatic":false,"isPublic":true},"triage":{"name":"triage","async":true,"parameters":[{"name":"action","type":"MailTriageAction","optional":false},{"name":"emailIds","type":"any","optional":false,"typeUnresolved":true}],"returnType":"Promise<MailTriageResult>","isStatic":false,"isPublic":true},"fetchThread":{"name":"fetchThread","async":true,"parameters":[{"name":"threadId","type":"string","optional":false}],"returnType":"any","isStatic":false,"isPublic":true},"getFolders":{"name":"getFolders","async":true,"parameters":[],"returnType":"any","isStatic":false,"isPublic":true},"getEmails":{"name":"getEmails","async":true,"parameters":[{"name":"limit","type":"number","optional":true}],"returnType":"any","isStatic":false,"isPublic":true},"getUnreadCount":{"name":"getUnreadCount","async":true,"parameters":[],"returnType":"Promise<number>","isStatic":false,"isPublic":true},"syncAll":{"name":"syncAll","async":true,"parameters":[{"name":"args","type":"Record<string, unknown>","optional":true}],"returnType":"Promise<Map<string, object>>","isStatic":false,"isPublic":true},"migrateToSecrets":{"name":"migrateToSecrets","async":true,"parameters":[],"returnType":"Promise<void>","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableStrategy":"sti","api":{"include":["list","get"]},"mcp":{"include":["list","get"]},"cli":{"include":["list","get"]},"tableName":"accounts"},"extends":"Account","exportName":"EmailAccount","collectionExportName":"EmailAccountCollection","displayLabelField":"name","validationRules":[{"field":"isActive","rule":"required","fieldType":"boolean"},{"field":"syncIntervalMinutes","rule":"required","fieldType":"integer"},{"field":"backlog","rule":"required","fieldType":"boolean"}],"schema":{"tableName":"accounts","ddl":"CREATE TABLE IF NOT EXISTS \\"accounts\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"_meta_type\\" TEXT NOT NULL,\\n \\"_meta_data\\" JSON,\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"name\\" TEXT,\\n \\"provider_type\\" TEXT,\\n \\"channel_type\\" TEXT,\\n \\"credential_secret_id\\" TEXT,\\n \\"is_active\\" BOOLEAN DEFAULT TRUE,\\n \\"owner_user_id\\" UUID,\\n \\"label\\" TEXT,\\n \\"connection_status\\" TEXT,\\n \\"status_message\\" TEXT,\\n \\"last_sync_at\\" TIMESTAMP,\\n \\"settings\\" TEXT,\\n \\"configuration\\" TEXT,\\n \\"email\\" TEXT,\\n \\"sync_interval_minutes\\" INTEGER DEFAULT 60,\\n \\"sync_cursor\\" TEXT,\\n \\"backfill_since\\" TIMESTAMP,\\n \\"cursor_horizon\\" TIMESTAMP,\\n \\"last_sync_error\\" TEXT,\\n \\"backlog\\" BOOLEAN DEFAULT FALSE,\\n \\"workspace_id\\" TEXT,\\n \\"workspace_name\\" TEXT,\\n \\"bot_user_id\\" TEXT,\\n \\"handle\\" TEXT,\\n \\"twitter_user_id\\" TEXT\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"_meta_type":{"type":"TEXT","notNull":true},"_meta_data":{"type":"JSON","notNull":false},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false},"name":{"type":"TEXT","notNull":false},"provider_type":{"type":"TEXT","notNull":false},"channel_type":{"type":"TEXT","notNull":false},"credential_secret_id":{"type":"TEXT","notNull":false},"is_active":{"type":"BOOLEAN","notNull":false,"default":true},"owner_user_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false},"label":{"type":"TEXT","notNull":false},"connection_status":{"type":"TEXT","notNull":false},"status_message":{"type":"TEXT","notNull":false},"last_sync_at":{"type":"TIMESTAMP","notNull":false},"settings":{"type":"TEXT","notNull":false},"configuration":{"type":"TEXT","notNull":false},"email":{"type":"TEXT","notNull":false},"sync_interval_minutes":{"type":"INTEGER","notNull":false,"default":60},"sync_cursor":{"type":"TEXT","notNull":false},"backfill_since":{"type":"TIMESTAMP","notNull":false},"cursor_horizon":{"type":"TIMESTAMP","notNull":false},"last_sync_error":{"type":"TEXT","notNull":false},"backlog":{"type":"BOOLEAN","notNull":false,"default":false},"workspace_id":{"type":"TEXT","notNull":false},"workspace_name":{"type":"TEXT","notNull":false},"bot_user_id":{"type":"TEXT","notNull":false},"handle":{"type":"TEXT","notNull":false},"twitter_user_id":{"type":"TEXT","notNull":false}},"indexes":[{"name":"accounts_slug_context_meta_type_idx","columns":["tenant_id","slug","context","_meta_type"],"unique":true,"nullsNotDistinct":true},{"name":"accounts_meta_type_idx","columns":["_meta_type"]},{"name":"accounts_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"accounts_owner_user_id_idx","columns":["owner_user_id"]}],"checks":[{"name":"smrt_ck_81229bbfe8e3","columns":["backlog"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:EmailAccount') OR \\"backlog\\" IS NOT NULL"},{"name":"smrt_ck_1f9c5f0ee488","columns":["sync_interval_minutes"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:EmailAccount') OR \\"sync_interval_minutes\\" IS NOT NULL"}],"version":"f48d7a23"},"importPath":"@happyvertical/smrt-messages"},"@happyvertical/smrt-messages:EmailAttachment":{"name":"emailattachment","className":"EmailAttachment","qualifiedName":"@happyvertical/smrt-messages:EmailAttachment","collection":"emailattachments","filePath":"src/models/EmailAttachment.ts","packageName":"@happyvertical/smrt-messages","fields":{"tenantId":{"type":"text","_meta":{"__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":false,"autoPopulate":true,"nullable":true,"mode":"optional","field":"tenantId","allowSuperAdminBypass":false},"__statedOptions":["sqlType","nullable","__tenancy","required"],"required":false,"sqlType":"UUID","nullable":true},"required":false},"messageId":{"type":"foreignKey","_meta":{"__statedOptions":["related"]},"required":false,"related":"Message"},"accountId":{"type":"foreignKey","_meta":{"__statedOptions":["related"]},"required":false,"related":"Account"},"filename":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"contentType":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"size":{"type":"integer","_meta":{"__statedOptions":["default"]},"required":true,"default":0},"contentId":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"contentDisposition":{"type":"text","_meta":{"__statedOptions":["default","enum"]},"required":false,"default":"attachment","enum":["attachment","inline"]},"filePath":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"sourceUrl":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"createdAt":{"type":"text","_meta":{"__statedOptions":[]},"required":false}},"methods":{"loadFromId":{"name":"loadFromId","async":true,"parameters":[],"returnType":"any","isStatic":false,"isPublic":true},"loadFromSlug":{"name":"loadFromSlug","async":true,"parameters":[],"returnType":"any","isStatic":false,"isPublic":true},"getMessage":{"name":"getMessage","async":true,"parameters":[],"returnType":"any","isStatic":false,"isPublic":true},"isImage":{"name":"isImage","async":false,"parameters":[],"returnType":"boolean","isStatic":false,"isPublic":true},"isPdf":{"name":"isPdf","async":false,"parameters":[],"returnType":"boolean","isStatic":false,"isPublic":true},"isInline":{"name":"isInline","async":false,"parameters":[],"returnType":"boolean","isStatic":false,"isPublic":true},"getExtension":{"name":"getExtension","async":false,"parameters":[],"returnType":"string","isStatic":false,"isPublic":true},"getFormattedSize":{"name":"getFormattedSize","async":false,"parameters":[],"returnType":"string","isStatic":false,"isPublic":true},"hasExternalFile":{"name":"hasExternalFile","async":false,"parameters":[],"returnType":"boolean","isStatic":false,"isPublic":true},"readContent":{"name":"readContent","async":true,"parameters":[],"returnType":"Promise<Buffer | null>","isStatic":false,"isPublic":true},"getEmail":{"name":"getEmail","async":true,"parameters":[],"returnType":"any","isStatic":false,"isPublic":true}},"decoratorConfig":{"api":{"include":["list","get","create","delete"]},"mcp":{"include":["list","get"]},"cli":{"skipApiCheck":true},"conflictColumns":["tenant_id","slug","context"]},"extends":"Attachment","exportName":"EmailAttachment","collectionExportName":"EmailAttachmentCollection","validationRules":[{"field":"size","rule":"required","fieldType":"integer"}],"schema":{"tableName":"email_attachments","ddl":"CREATE TABLE IF NOT EXISTS \\"email_attachments\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"message_id\\" UUID,\\n \\"account_id\\" UUID,\\n \\"filename\\" TEXT,\\n \\"content_type\\" TEXT,\\n \\"size\\" INTEGER NOT NULL DEFAULT 0,\\n \\"content_id\\" TEXT,\\n \\"content_disposition\\" TEXT DEFAULT 'attachment',\\n \\"file_path\\" TEXT,\\n \\"source_url\\" TEXT\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false,"unique":false},"message_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"messages","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"account_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"accounts","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"filename":{"type":"TEXT","notNull":false,"unique":false},"content_type":{"type":"TEXT","notNull":false,"unique":false},"size":{"type":"INTEGER","notNull":true,"unique":false,"default":0},"content_id":{"type":"TEXT","notNull":false,"unique":false},"content_disposition":{"type":"TEXT","notNull":false,"unique":false,"default":"attachment"},"file_path":{"type":"TEXT","notNull":false,"unique":false},"source_url":{"type":"TEXT","notNull":false,"unique":false}},"indexes":[{"name":"email_attachments_slug_context_idx","columns":["tenant_id","slug","context"],"unique":true,"nullsNotDistinct":true},{"name":"email_attachments_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"email_attachments_message_id_idx","columns":["message_id"]},{"name":"email_attachments_account_id_idx","columns":["account_id"]}],"version":"ebed0053"},"importPath":"@happyvertical/smrt-messages"},"@happyvertical/smrt-messages:EmailFolder":{"name":"emailfolder","className":"EmailFolder","qualifiedName":"@happyvertical/smrt-messages:EmailFolder","collection":"emailfolders","filePath":"src/models/EmailFolder.ts","packageName":"@happyvertical/smrt-messages","fields":{"tenantId":{"type":"text","_meta":{"__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":false,"autoPopulate":true,"nullable":true,"mode":"optional","field":"tenantId","allowSuperAdminBypass":false},"__statedOptions":["sqlType","nullable","__tenancy","required"],"sqlType":"UUID","nullable":true,"required":false},"required":false},"accountId":{"type":"foreignKey","_meta":{"__statedOptions":["related"]},"required":false,"related":"Account"},"name":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"path":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"delimiter":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"specialUse":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"messageCount":{"type":"integer","_meta":{"__statedOptions":["default"]},"required":true,"default":0},"unreadCount":{"type":"integer","_meta":{"__statedOptions":["default"]},"required":true,"default":0},"subscribed":{"type":"boolean","_meta":{"__statedOptions":["default"]},"required":true,"default":true},"createdAt":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"updatedAt":{"type":"text","_meta":{"__statedOptions":[]},"required":false}},"methods":{"loadFromId":{"name":"loadFromId","async":true,"parameters":[],"returnType":"any","isStatic":false,"isPublic":true},"loadFromSlug":{"name":"loadFromSlug","async":true,"parameters":[],"returnType":"any","isStatic":false,"isPublic":true},"getAccount":{"name":"getAccount","async":true,"parameters":[],"returnType":"any","isStatic":false,"isPublic":true},"getEmails":{"name":"getEmails","async":true,"parameters":[{"name":"limit","type":"number","optional":true}],"returnType":"any","isStatic":false,"isPublic":true},"getUnreadEmails":{"name":"getUnreadEmails","async":true,"parameters":[{"name":"limit","type":"number","optional":true}],"returnType":"any","isStatic":false,"isPublic":true},"refreshCounts":{"name":"refreshCounts","async":true,"parameters":[],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"isInbox":{"name":"isInbox","async":false,"parameters":[],"returnType":"boolean","isStatic":false,"isPublic":true},"isSent":{"name":"isSent","async":false,"parameters":[],"returnType":"boolean","isStatic":false,"isPublic":true},"isDrafts":{"name":"isDrafts","async":false,"parameters":[],"returnType":"boolean","isStatic":false,"isPublic":true},"isTrash":{"name":"isTrash","async":false,"parameters":[],"returnType":"boolean","isStatic":false,"isPublic":true},"isSpam":{"name":"isSpam","async":false,"parameters":[],"returnType":"boolean","isStatic":false,"isPublic":true},"isSystemFolder":{"name":"isSystemFolder","async":false,"parameters":[],"returnType":"boolean","isStatic":false,"isPublic":true},"subscribe":{"name":"subscribe","async":true,"parameters":[],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"unsubscribe":{"name":"unsubscribe","async":true,"parameters":[],"returnType":"Promise<void>","isStatic":false,"isPublic":true}},"decoratorConfig":{"api":{"include":["list","get","create","update","delete"]},"mcp":{"include":["list","get"]},"cli":{"skipApiCheck":true},"tenantScoped":{"mode":"optional"},"conflictColumns":["tenant_id","slug","context"]},"extends":"SmrtObject","exportName":"EmailFolder","collectionExportName":"EmailFolderCollection","displayLabelField":"name","validationRules":[{"field":"messageCount","rule":"required","fieldType":"integer"},{"field":"unreadCount","rule":"required","fieldType":"integer"},{"field":"subscribed","rule":"required","fieldType":"boolean"}],"schema":{"tableName":"email_folders","ddl":"CREATE TABLE IF NOT EXISTS \\"email_folders\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"account_id\\" UUID,\\n \\"name\\" TEXT,\\n \\"path\\" TEXT,\\n \\"delimiter\\" TEXT,\\n \\"special_use\\" TEXT,\\n \\"message_count\\" INTEGER NOT NULL DEFAULT 0,\\n \\"unread_count\\" INTEGER NOT NULL DEFAULT 0,\\n \\"subscribed\\" BOOLEAN NOT NULL DEFAULT TRUE\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false,"unique":false},"account_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"accounts","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"name":{"type":"TEXT","notNull":false,"unique":false},"path":{"type":"TEXT","notNull":false,"unique":false},"delimiter":{"type":"TEXT","notNull":false,"unique":false},"special_use":{"type":"TEXT","notNull":false,"unique":false},"message_count":{"type":"INTEGER","notNull":true,"unique":false,"default":0},"unread_count":{"type":"INTEGER","notNull":true,"unique":false,"default":0},"subscribed":{"type":"BOOLEAN","notNull":true,"unique":false,"default":true}},"indexes":[{"name":"email_folders_slug_context_idx","columns":["tenant_id","slug","context"],"unique":true,"nullsNotDistinct":true},{"name":"email_folders_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"email_folders_account_id_idx","columns":["account_id"]}],"version":"cfea127c"},"importPath":"@happyvertical/smrt-messages"},"@happyvertical/smrt-messages:Message":{"name":"message","className":"Message","qualifiedName":"@happyvertical/smrt-messages:Message","collection":"messages","filePath":"src/models/Message.ts","packageName":"@happyvertical/smrt-messages","fields":{"created_at":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"updated_at":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"tenantId":{"type":"text","_meta":{"__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":false,"autoPopulate":true,"nullable":true,"mode":"optional","field":"tenantId","allowSuperAdminBypass":false},"__statedOptions":["sqlType","nullable","__tenancy","required"],"sqlType":"UUID","nullable":true,"required":false},"required":false},"accountId":{"type":"foreignKey","_meta":{"__statedOptions":["description","related"],"description":"The connected account used to receive or send this message."},"required":false,"related":"Account","description":"The connected account used to receive or send this message."},"personaId":{"type":"crossPackageRef","_meta":{"__statedOptions":["nullable","description","related","required"],"description":"The assistant identity associated with this message, when one was used.","nullable":true,"required":false},"required":false,"related":"@happyvertical/smrt-personas:AgentPersona","description":"The assistant identity associated with this message, when one was used."},"endpointId":{"type":"foreignKey","_meta":{"__statedOptions":["description","related"],"description":"The saved destination used to deliver this message."},"required":false,"related":"MessagingEndpoint","description":"The saved destination used to deliver this message."},"correlationId":{"type":"text","_meta":{"__statedOptions":["description"],"description":"A tracking reference that connects this message to related activity."},"required":false,"description":"A tracking reference that connects this message to related activity."},"threadId":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The conversation this message belongs to."},"required":false,"description":"The conversation this message belongs to."},"subject":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The subject shown in the message list."},"required":false,"description":"The subject shown in the message list."},"body":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The message content in plain text."},"required":false,"description":"The message content in plain text."},"fromAddress":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The address the message was sent from."},"required":false,"description":"The address the message was sent from."},"fromName":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The sender name shown beside their address."},"required":false,"description":"The sender name shown beside their address."},"toAddresses":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The people or addresses receiving this message."},"required":false,"description":"The people or addresses receiving this message."},"date":{"type":"datetime","_meta":{"__statedOptions":["description"],"description":"When the message was sent or received."},"required":false,"description":"When the message was sent or received."},"isRead":{"type":"boolean","_meta":{"__statedOptions":["description","default"],"description":"Whether this message has been marked as read."},"required":true,"default":false,"description":"Whether this message has been marked as read."},"isFlagged":{"type":"boolean","_meta":{"__statedOptions":["description","default"],"description":"Whether this message is flagged for follow-up."},"required":true,"default":false,"description":"Whether this message is flagged for follow-up."},"hasAttachments":{"type":"boolean","_meta":{"__statedOptions":["description","default"],"description":"Whether files are attached to this message."},"required":true,"default":false,"description":"Whether files are attached to this message."},"size":{"type":"integer","_meta":{"__statedOptions":["description","default"],"description":"The size of the message in bytes."},"required":true,"default":0,"description":"The size of the message in bytes."},"metadata":{"type":"text","_meta":{"__statedOptions":["description"],"description":"Additional details supplied by the messaging connection."},"required":false,"description":"Additional details supplied by the messaging connection."},"sendStatus":{"type":"text","_meta":{"__statedOptions":["description","default","enum"],"description":"The latest sending state: draft, sending, sent, or failed. Received mail may also show draft here."},"required":false,"default":"draft","description":"The latest sending state: draft, sending, sent, or failed. Received mail may also show draft here.","enum":["draft","pending","sending","sent","failed","scheduled"]},"sentAt":{"type":"datetime","_meta":{"__statedOptions":["description"],"description":"When the message was successfully sent."},"required":false,"description":"When the message was successfully sent."},"sendError":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The reason the latest send attempt failed."},"required":false,"description":"The reason the latest send attempt failed."},"retryCount":{"type":"integer","_meta":{"__statedOptions":["description","default"],"description":"How many times delivery has been retried."},"required":true,"default":0,"description":"How many times delivery has been retried."},"maxRetries":{"type":"integer","_meta":{"__statedOptions":["description","default"],"description":"The maximum number of delivery retries allowed."},"required":true,"default":3,"description":"The maximum number of delivery retries allowed."},"scheduledSendAt":{"type":"datetime","_meta":{"__statedOptions":["description"],"description":"When this message is scheduled to be sent."},"required":false,"description":"When this message is scheduled to be sent."},"inReplyToMessageId":{"type":"foreignKey","_meta":{"__statedOptions":["description","related"],"description":"The earlier message this one replies to."},"required":false,"related":"Message","description":"The earlier message this one replies to."},"createdAt":{"type":"text","_meta":{"__statedOptions":["description"],"description":"When this message was recorded."},"required":false,"description":"When this message was recorded."},"updatedAt":{"type":"text","_meta":{"__statedOptions":["description"],"description":"When this message was last changed."},"required":false,"description":"When this message was last changed."}},"methods":{"save":{"name":"save","async":true,"parameters":[{"name":"options","type":"SmrtSaveOptions","optional":true}],"returnType":"Promise<this>","isStatic":false,"isPublic":true},"delete":{"name":"delete","async":true,"parameters":[{"name":"options","type":"object","optional":true,"memberTypes":["Date | string"]}],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"getToAddresses":{"name":"getToAddresses","async":false,"parameters":[],"returnType":"Array<object>","isStatic":false,"isPublic":true},"setToAddresses":{"name":"setToAddresses","async":false,"parameters":[{"name":"addresses","type":"Array<object>","optional":false,"memberTypes":["string"]}],"returnType":"void","isStatic":false,"isPublic":true},"getMetadata":{"name":"getMetadata","async":false,"parameters":[],"returnType":"Record<string, unknown>","isStatic":false,"isPublic":true},"setMetadata":{"name":"setMetadata","async":false,"parameters":[{"name":"data","type":"Record<string, unknown>","optional":false}],"returnType":"void","isStatic":false,"isPublic":true},"markRead":{"name":"markRead","async":true,"parameters":[],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"markUnread":{"name":"markUnread","async":true,"parameters":[],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"toggleFlagged":{"name":"toggleFlagged","async":true,"parameters":[],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"isUnread":{"name":"isUnread","async":false,"parameters":[],"returnType":"boolean","isStatic":false,"isPublic":true},"getPreview":{"name":"getPreview","async":false,"parameters":[{"name":"maxLength","type":"any","optional":true}],"returnType":"string","isStatic":false,"isPublic":true},"loadFromId":{"name":"loadFromId","async":true,"parameters":[],"returnType":"any","isStatic":false,"isPublic":true},"loadFromSlug":{"name":"loadFromSlug","async":true,"parameters":[],"returnType":"any","isStatic":false,"isPublic":true},"getAccount":{"name":"getAccount","async":true,"parameters":[],"returnType":"any","isStatic":false,"isPublic":true},"getEndpoint":{"name":"getEndpoint","async":true,"parameters":[],"returnType":"any","isStatic":false,"isPublic":true},"getThreadMessages":{"name":"getThreadMessages","async":true,"parameters":[],"returnType":"Promise<Message[]>","isStatic":false,"isPublic":true},"getAttachments":{"name":"getAttachments","async":true,"parameters":[],"returnType":"any","isStatic":false,"isPublic":true},"send":{"name":"send","async":true,"parameters":[{"name":"options","type":"SendMessageOptions","optional":true}],"returnType":"Promise<MessageSendResult>","isStatic":false,"isPublic":true},"isSendOutcomeUnknown":{"name":"isSendOutcomeUnknown","async":false,"parameters":[],"returnType":"boolean","isStatic":false,"isPublic":true},"abandonSendAttempt":{"name":"abandonSendAttempt","async":true,"parameters":[{"name":"reason","type":"string","optional":false}],"returnType":"Promise<boolean>","isStatic":false,"isPublic":true},"retrySend":{"name":"retrySend","async":true,"parameters":[{"name":"options","type":"SendMessageOptions","optional":true}],"returnType":"Promise<MessageSendResult>","isStatic":false,"isPublic":true},"createReply":{"name":"createReply","async":false,"parameters":[{"name":"_options","type":"object","optional":true,"memberTypes":["boolean"]}],"returnType":"Message","isStatic":false,"isPublic":true},"createForward":{"name":"createForward","async":false,"parameters":[],"returnType":"Message","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableStrategy":"sti","api":{"include":["list","get"]},"mcp":{"include":["list","get"]},"cli":{"skipApiCheck":true},"tenantScoped":{"mode":"optional"},"conflictColumns":["tenant_id","slug","context","_meta_type"]},"extends":"SmrtObject","exportName":"Message","collectionExportName":"MessageCollection","validationRules":[{"field":"isRead","rule":"required","fieldType":"boolean"},{"field":"isFlagged","rule":"required","fieldType":"boolean"},{"field":"hasAttachments","rule":"required","fieldType":"boolean"},{"field":"size","rule":"required","fieldType":"integer"},{"field":"retryCount","rule":"required","fieldType":"integer"},{"field":"maxRetries","rule":"required","fieldType":"integer"}],"schema":{"tableName":"messages","ddl":"CREATE TABLE IF NOT EXISTS \\"messages\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"_meta_type\\" TEXT NOT NULL,\\n \\"_meta_data\\" JSON,\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"account_id\\" UUID,\\n \\"persona_id\\" UUID,\\n \\"endpoint_id\\" UUID,\\n \\"correlation_id\\" TEXT,\\n \\"thread_id\\" TEXT,\\n \\"subject\\" TEXT,\\n \\"body\\" TEXT,\\n \\"from_address\\" TEXT,\\n \\"from_name\\" TEXT,\\n \\"to_addresses\\" TEXT,\\n \\"date\\" TIMESTAMP,\\n \\"is_read\\" BOOLEAN DEFAULT FALSE,\\n \\"is_flagged\\" BOOLEAN DEFAULT FALSE,\\n \\"has_attachments\\" BOOLEAN DEFAULT FALSE,\\n \\"size\\" INTEGER DEFAULT 0,\\n \\"metadata\\" TEXT,\\n \\"send_status\\" TEXT DEFAULT 'draft',\\n \\"sent_at\\" TIMESTAMP,\\n \\"send_error\\" TEXT,\\n \\"retry_count\\" INTEGER DEFAULT 0,\\n \\"max_retries\\" INTEGER DEFAULT 3,\\n \\"scheduled_send_at\\" TIMESTAMP,\\n \\"in_reply_to_message_id\\" UUID,\\n \\"message_id\\" TEXT,\\n \\"in_reply_to\\" TEXT,\\n \\"provider_message_id\\" TEXT,\\n \\"cc_addresses\\" TEXT,\\n \\"bcc_addresses\\" TEXT,\\n \\"reply_to_address\\" TEXT,\\n \\"reply_to_name\\" TEXT,\\n \\"text_body\\" TEXT,\\n \\"html_body\\" TEXT,\\n \\"folder_id\\" TEXT,\\n \\"folder_path\\" TEXT,\\n \\"labels\\" TEXT,\\n \\"flags\\" TEXT,\\n \\"is_answered\\" BOOLEAN DEFAULT FALSE,\\n \\"is_draft\\" BOOLEAN DEFAULT FALSE,\\n \\"raw_message\\" TEXT,\\n \\"headers\\" TEXT,\\n \\"channel_id\\" TEXT,\\n \\"channel_name\\" TEXT,\\n \\"slack_ts\\" TEXT,\\n \\"slack_thread_ts\\" TEXT,\\n \\"reactions\\" TEXT,\\n \\"is_edited\\" BOOLEAN DEFAULT FALSE,\\n \\"message_type\\" TEXT,\\n \\"blocks\\" TEXT,\\n \\"tweet_id\\" TEXT,\\n \\"retweet_count\\" INTEGER DEFAULT 0,\\n \\"like_count\\" INTEGER DEFAULT 0,\\n \\"reply_count\\" INTEGER DEFAULT 0,\\n \\"is_retweet\\" BOOLEAN DEFAULT FALSE,\\n \\"is_reply\\" BOOLEAN DEFAULT FALSE,\\n \\"media_urls\\" TEXT,\\n \\"hashtags\\" TEXT,\\n \\"mentions\\" TEXT\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"_meta_type":{"type":"TEXT","notNull":true},"_meta_data":{"type":"JSON","notNull":false},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false},"account_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"foreignKey":{"table":"accounts","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"persona_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false},"endpoint_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"foreignKey":{"table":"messaging_endpoints","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"correlation_id":{"type":"TEXT","notNull":false},"thread_id":{"type":"TEXT","notNull":false},"subject":{"type":"TEXT","notNull":false},"body":{"type":"TEXT","notNull":false},"from_address":{"type":"TEXT","notNull":false},"from_name":{"type":"TEXT","notNull":false},"to_addresses":{"type":"TEXT","notNull":false},"date":{"type":"TIMESTAMP","notNull":false},"is_read":{"type":"BOOLEAN","notNull":false,"default":false},"is_flagged":{"type":"BOOLEAN","notNull":false,"default":false},"has_attachments":{"type":"BOOLEAN","notNull":false,"default":false},"size":{"type":"INTEGER","notNull":false,"default":0},"metadata":{"type":"TEXT","notNull":false},"send_status":{"type":"TEXT","notNull":false,"default":"draft"},"sent_at":{"type":"TIMESTAMP","notNull":false},"send_error":{"type":"TEXT","notNull":false},"retry_count":{"type":"INTEGER","notNull":false,"default":0},"max_retries":{"type":"INTEGER","notNull":false,"default":3},"scheduled_send_at":{"type":"TIMESTAMP","notNull":false},"in_reply_to_message_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"foreignKey":{"table":"messages","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"message_id":{"type":"TEXT","notNull":false},"in_reply_to":{"type":"TEXT","notNull":false},"provider_message_id":{"type":"TEXT","notNull":false},"cc_addresses":{"type":"TEXT","notNull":false},"bcc_addresses":{"type":"TEXT","notNull":false},"reply_to_address":{"type":"TEXT","notNull":false},"reply_to_name":{"type":"TEXT","notNull":false},"text_body":{"type":"TEXT","notNull":false},"html_body":{"type":"TEXT","notNull":false},"folder_id":{"type":"TEXT","notNull":false},"folder_path":{"type":"TEXT","notNull":false},"labels":{"type":"TEXT","notNull":false},"flags":{"type":"TEXT","notNull":false},"is_answered":{"type":"BOOLEAN","notNull":false,"default":false},"is_draft":{"type":"BOOLEAN","notNull":false,"default":false},"raw_message":{"type":"TEXT","notNull":false},"headers":{"type":"TEXT","notNull":false},"channel_id":{"type":"TEXT","notNull":false},"channel_name":{"type":"TEXT","notNull":false},"slack_ts":{"type":"TEXT","notNull":false},"slack_thread_ts":{"type":"TEXT","notNull":false},"reactions":{"type":"TEXT","notNull":false},"is_edited":{"type":"BOOLEAN","notNull":false,"default":false},"message_type":{"type":"TEXT","notNull":false},"blocks":{"type":"TEXT","notNull":false},"tweet_id":{"type":"TEXT","notNull":false},"retweet_count":{"type":"INTEGER","notNull":false,"default":0},"like_count":{"type":"INTEGER","notNull":false,"default":0},"reply_count":{"type":"INTEGER","notNull":false,"default":0},"is_retweet":{"type":"BOOLEAN","notNull":false,"default":false},"is_reply":{"type":"BOOLEAN","notNull":false,"default":false},"media_urls":{"type":"TEXT","notNull":false},"hashtags":{"type":"TEXT","notNull":false},"mentions":{"type":"TEXT","notNull":false}},"indexes":[{"name":"messages_slug_context_meta_type_idx","columns":["tenant_id","slug","context","_meta_type"],"unique":true,"nullsNotDistinct":true},{"name":"messages_meta_type_idx","columns":["_meta_type"]},{"name":"messages_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"messages_account_id_idx","columns":["account_id"]},{"name":"messages_persona_id_idx","columns":["persona_id"]},{"name":"messages_endpoint_id_idx","columns":["endpoint_id"]},{"name":"messages_in_reply_to_message_id_idx","columns":["in_reply_to_message_id"]}],"checks":[{"name":"smrt_ck_d0024f738cf4","columns":["is_answered"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:Email') OR \\"is_answered\\" IS NOT NULL"},{"name":"smrt_ck_0adcd2453c81","columns":["is_draft"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:Email') OR \\"is_draft\\" IS NOT NULL"},{"name":"smrt_ck_428e155c9609","columns":["is_edited"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:SlackMessage') OR \\"is_edited\\" IS NOT NULL"},{"name":"smrt_ck_a17af99e85e3","columns":["is_reply"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:Tweet') OR \\"is_reply\\" IS NOT NULL"},{"name":"smrt_ck_3e30563cba58","columns":["is_retweet"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:Tweet') OR \\"is_retweet\\" IS NOT NULL"},{"name":"smrt_ck_bab2c772ebe6","columns":["like_count"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:Tweet') OR \\"like_count\\" IS NOT NULL"},{"name":"smrt_ck_c6ad8d47bbc8","columns":["reply_count"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:Tweet') OR \\"reply_count\\" IS NOT NULL"},{"name":"smrt_ck_43a00e1c098d","columns":["retweet_count"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:Tweet') OR \\"retweet_count\\" IS NOT NULL"}],"version":"d8da74ce"},"importPath":"@happyvertical/smrt-messages"},"@happyvertical/smrt-messages:MessagingEndpoint":{"name":"messagingendpoint","className":"MessagingEndpoint","qualifiedName":"@happyvertical/smrt-messages:MessagingEndpoint","collection":"messagingendpoints","filePath":"src/models/MessagingEndpoint.ts","packageName":"@happyvertical/smrt-messages","fields":{"tenantId":{"type":"text","_meta":{"__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":true,"autoPopulate":true,"nullable":false,"mode":"required","field":"tenantId","allowSuperAdminBypass":false},"__statedOptions":["sqlType","requiredFor","__tenancy"],"sqlType":"UUID","requiredFor":"tenant-scope"},"required":true},"profileId":{"type":"crossPackageRef","_meta":{"__statedOptions":["nullable","related","required"],"nullable":true,"required":false},"required":false,"related":"@happyvertical/smrt-profiles:Profile"},"label":{"type":"text","_meta":{"__statedOptions":["required","requiredFor"],"required":true,"requiredFor":"identity"},"required":true},"channel":{"type":"text","_meta":{"__statedOptions":["required","default"],"required":true},"required":true,"default":"email"},"address":{"type":"text","_meta":{"__statedOptions":["required","sensitive"],"required":true,"sensitive":true},"required":true,"sensitive":true},"isActive":{"type":"boolean","_meta":{"__statedOptions":["default"]},"required":true,"default":true},"verifiedAt":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"createdAt":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"updatedAt":{"type":"text","_meta":{"__statedOptions":[]},"required":false}},"methods":{"getAddress":{"name":"getAddress","async":false,"parameters":[],"returnType":"T","isStatic":false,"isPublic":true},"setAddress":{"name":"setAddress","async":false,"parameters":[{"name":"address","type":"Record<string, unknown>","optional":false}],"returnType":"void","isStatic":false,"isPublic":true},"getMaskedAddress":{"name":"getMaskedAddress","async":false,"parameters":[],"returnType":"string","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableName":"messaging_endpoints","api":{"include":["list","get"]},"mcp":{"include":["list","get"]},"cli":{"include":["list","get"]},"conflictColumns":["tenant_id","channel","label"],"tenantScoped":{"mode":"required"}},"extends":"SmrtObject","exportName":"MessagingEndpoint","collectionExportName":"MessagingEndpointCollection","displayLabelField":"label","validationRules":[{"field":"label","rule":"required","fieldType":"text"},{"field":"channel","rule":"required","fieldType":"text"},{"field":"address","rule":"required","fieldType":"text"},{"field":"isActive","rule":"required","fieldType":"boolean"}],"schema":{"tableName":"messaging_endpoints","ddl":"CREATE TABLE IF NOT EXISTS \\"messaging_endpoints\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"profile_id\\" UUID,\\n \\"label\\" TEXT NOT NULL,\\n \\"channel\\" TEXT NOT NULL DEFAULT 'email',\\n \\"address\\" TEXT NOT NULL,\\n \\"is_active\\" BOOLEAN NOT NULL DEFAULT TRUE,\\n \\"verified_at\\" TIMESTAMP\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"profile_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false,"unique":false},"label":{"type":"TEXT","notNull":true,"unique":false},"channel":{"type":"TEXT","notNull":true,"unique":false,"default":"email"},"address":{"type":"TEXT","notNull":true,"unique":false},"is_active":{"type":"BOOLEAN","notNull":true,"unique":false,"default":true},"verified_at":{"type":"TIMESTAMP","notNull":false,"unique":false}},"indexes":[{"name":"messaging_endpoints_tenant_id_channel_idx","columns":["tenant_id","channel","label"],"unique":true},{"name":"messaging_endpoints_slug_context_idx","columns":["slug","context"]},{"name":"messaging_endpoints_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"messaging_endpoints_profile_id_idx","columns":["profile_id"]}],"version":"b4466849"},"importPath":"@happyvertical/smrt-messages"},"@happyvertical/smrt-messages:NotificationDelivery":{"name":"notificationdelivery","className":"NotificationDelivery","qualifiedName":"@happyvertical/smrt-messages:NotificationDelivery","collection":"notificationdeliveries","description":"One durable, source-keyed notification delivery to one person over one external channel (the outbox row behind NotificationOutboxService).","filePath":"src/models/NotificationDelivery.ts","packageName":"@happyvertical/smrt-messages","fields":{"tenantId":{"type":"text","_meta":{"__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":true,"autoPopulate":true,"nullable":false,"mode":"required","field":"tenantId","allowSuperAdminBypass":false},"__statedOptions":["sqlType","requiredFor","__tenancy"],"sqlType":"UUID","requiredFor":"tenant-scope"},"required":true},"recipientUserId":{"type":"crossPackageRef","_meta":{"__statedOptions":["nullable","related","required"],"nullable":true,"required":false},"required":false,"related":"@happyvertical/smrt-users:User"},"recipientProfileId":{"type":"crossPackageRef","_meta":{"__statedOptions":["nullable","related","required"],"nullable":true,"required":false},"required":false,"related":"@happyvertical/smrt-profiles:Profile"},"recipientKind":{"type":"text","_meta":{"__statedOptions":["required","requiredFor","default","enum"],"required":true,"requiredFor":"identity"},"required":true,"default":"user","enum":["user","profile"]},"channel":{"type":"text","_meta":{"__statedOptions":["required","requiredFor","default","enum"],"required":true,"requiredFor":"identity"},"required":true,"default":"email","enum":["email"]},"sourceRef":{"type":"text","_meta":{"__statedOptions":["required","requiredFor"],"required":true,"requiredFor":"idempotency"},"required":true},"kind":{"type":"text","_meta":{"__statedOptions":["required","requiredFor"],"required":true,"requiredFor":"identity"},"required":true},"requiredDispatchPolicy":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"dispatchPolicyBinding":{"type":"json","_meta":{"__statedOptions":[]},"required":false},"subject":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"textBody":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"href":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"recipientAddress":{"type":"text","_meta":{"__statedOptions":["required","requiredFor"],"required":true,"requiredFor":"identity"},"required":true},"recipientName":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"accountId":{"type":"foreignKey","_meta":{"__statedOptions":["related"]},"required":false,"related":"Account"},"messageId":{"type":"foreignKey","_meta":{"__statedOptions":["related"]},"required":false,"related":"Message"},"status":{"type":"text","_meta":{"__statedOptions":["default","enum"]},"required":false,"default":"pending","enum":["pending","sending","sent","failed","uncertain","cancelled"]},"stateVersion":{"type":"integer","_meta":{"__statedOptions":["default"]},"required":true,"default":0},"transitionId":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"attempts":{"type":"integer","_meta":{"__statedOptions":["default"]},"required":true,"default":0},"maxAttempts":{"type":"integer","_meta":{"__statedOptions":["default"]},"required":true,"default":5},"nextAttemptAt":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"leaseToken":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"leaseExpiresAt":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"handedOffAt":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"deliveredAt":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"providerMessageId":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"lastError":{"type":"text","_meta":{"__statedOptions":[]},"required":false}},"methods":{"save":{"name":"save","async":true,"parameters":[{"name":"options","type":"SmrtSaveOptions","optional":true}],"returnType":"Promise<this>","isStatic":false,"isPublic":true},"delete":{"name":"delete","async":true,"parameters":[],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"transition":{"name":"transition","async":true,"parameters":[{"name":"changes","type":"NotificationDeliveryTransition","optional":false,"resolvedType":"Partial<Pick<NotificationDelivery, 'messageId' | 'status' | 'attempts' | 'nextAttemptAt' | 'leaseToken' | 'leaseExpiresAt' | 'handedOffAt' | 'deliveredAt' | 'providerMessageId' | 'lastError'>>"},{"name":"expected","type":"object","optional":true,"memberTypes":["string"]}],"returnType":"Promise<boolean>","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableName":"notification_deliveries","api":false,"mcp":false,"cli":false,"conflictColumns":["tenant_id","recipient_kind","recipient_user_id","recipient_profile_id","channel","source_ref"],"indexes":[{"name":"notification_deliveries_user_identity","columns":["tenantId","recipientUserId","channel","sourceRef"],"unique":true},{"name":"notification_deliveries_profile_identity","columns":["tenantId","recipientProfileId","channel","sourceRef"],"unique":true},{"name":"notification_deliveries_due_idx","columns":["status","nextAttemptAt"]},{"name":"notification_deliveries_lease_idx","columns":["status","leaseExpiresAt"]}],"tenantScoped":{"mode":"required"}},"extends":"SmrtObject","exportName":"NotificationDelivery","collectionExportName":"NotificationDeliveryCollection","validationRules":[{"field":"recipientKind","rule":"required","fieldType":"text"},{"field":"channel","rule":"required","fieldType":"text"},{"field":"sourceRef","rule":"required","fieldType":"text"},{"field":"kind","rule":"required","fieldType":"text"},{"field":"recipientAddress","rule":"required","fieldType":"text"},{"field":"stateVersion","rule":"required","fieldType":"integer"},{"field":"attempts","rule":"required","fieldType":"integer"},{"field":"maxAttempts","rule":"required","fieldType":"integer"}],"schema":{"tableName":"notification_deliveries","ddl":"CREATE TABLE IF NOT EXISTS \\"notification_deliveries\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"recipient_user_id\\" UUID,\\n \\"recipient_profile_id\\" UUID,\\n \\"recipient_kind\\" TEXT NOT NULL DEFAULT 'user',\\n \\"channel\\" TEXT NOT NULL DEFAULT 'email',\\n \\"source_ref\\" TEXT NOT NULL,\\n \\"kind\\" TEXT NOT NULL,\\n \\"required_dispatch_policy\\" TEXT,\\n \\"dispatch_policy_binding\\" JSON,\\n \\"subject\\" TEXT,\\n \\"text_body\\" TEXT,\\n \\"href\\" TEXT,\\n \\"recipient_address\\" TEXT NOT NULL,\\n \\"recipient_name\\" TEXT,\\n \\"account_id\\" UUID,\\n \\"message_id\\" UUID,\\n \\"status\\" TEXT DEFAULT 'pending',\\n \\"state_version\\" INTEGER NOT NULL DEFAULT 0,\\n \\"transition_id\\" TEXT,\\n \\"attempts\\" INTEGER NOT NULL DEFAULT 0,\\n \\"max_attempts\\" INTEGER NOT NULL DEFAULT 5,\\n \\"next_attempt_at\\" TEXT,\\n \\"lease_token\\" TEXT,\\n \\"lease_expires_at\\" TIMESTAMP,\\n \\"handed_off_at\\" TIMESTAMP,\\n \\"delivered_at\\" TIMESTAMP,\\n \\"provider_message_id\\" TEXT,\\n \\"last_error\\" TEXT\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"recipient_user_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false,"unique":false},"recipient_profile_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false,"unique":false},"recipient_kind":{"type":"TEXT","notNull":true,"unique":false,"default":"user"},"channel":{"type":"TEXT","notNull":true,"unique":false,"default":"email"},"source_ref":{"type":"TEXT","notNull":true,"unique":false},"kind":{"type":"TEXT","notNull":true,"unique":false},"required_dispatch_policy":{"type":"TEXT","notNull":false,"unique":false},"dispatch_policy_binding":{"type":"JSON","notNull":false,"unique":false},"subject":{"type":"TEXT","notNull":false,"unique":false},"text_body":{"type":"TEXT","notNull":false,"unique":false},"href":{"type":"TEXT","notNull":false,"unique":false},"recipient_address":{"type":"TEXT","notNull":true,"unique":false},"recipient_name":{"type":"TEXT","notNull":false,"unique":false},"account_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"accounts","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"message_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"messages","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"status":{"type":"TEXT","notNull":false,"unique":false,"default":"pending"},"state_version":{"type":"INTEGER","notNull":true,"unique":false,"default":0},"transition_id":{"type":"TEXT","notNull":false,"unique":false},"attempts":{"type":"INTEGER","notNull":true,"unique":false,"default":0},"max_attempts":{"type":"INTEGER","notNull":true,"unique":false,"default":5},"next_attempt_at":{"type":"TEXT","notNull":false,"unique":false},"lease_token":{"type":"TEXT","notNull":false,"unique":false},"lease_expires_at":{"type":"TIMESTAMP","notNull":false,"unique":false},"handed_off_at":{"type":"TIMESTAMP","notNull":false,"unique":false},"delivered_at":{"type":"TIMESTAMP","notNull":false,"unique":false},"provider_message_id":{"type":"TEXT","notNull":false,"unique":false},"last_error":{"type":"TEXT","notNull":false,"unique":false}},"indexes":[{"name":"notification_deliveries_tenant_id_recipient_kind_idx","columns":["tenant_id","recipient_kind","recipient_user_id","recipient_profile_id","channel","source_ref"],"unique":true,"nullsNotDistinct":true},{"name":"notification_deliveries_slug_context_idx","columns":["slug","context"]},{"name":"notification_deliveries_user_identity","columns":["tenant_id","recipient_user_id","channel","source_ref"],"unique":true},{"name":"notification_deliveries_profile_identity","columns":["tenant_id","recipient_profile_id","channel","source_ref"],"unique":true},{"name":"notification_deliveries_due_idx","columns":["status","next_attempt_at"]},{"name":"notification_deliveries_lease_idx","columns":["status","lease_expires_at"]},{"name":"notification_deliveries_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"notification_deliveries_recipient_user_id_idx","columns":["recipient_user_id"]},{"name":"notification_deliveries_recipient_profile_id_idx","columns":["recipient_profile_id"]},{"name":"notification_deliveries_account_id_idx","columns":["account_id"]},{"name":"notification_deliveries_message_id_idx","columns":["message_id"]}],"version":"547f434f"},"importPath":"@happyvertical/smrt-messages"},"@happyvertical/smrt-messages:NotificationOptOut":{"name":"notificationoptout","className":"NotificationOptOut","qualifiedName":"@happyvertical/smrt-messages:NotificationOptOut","collection":"notificationoptouts","description":"One person's opt-out of one notification channel for one scope, in one tenant: the preference store behind the outbox's isSuppressed hook.","filePath":"src/models/NotificationOptOut.ts","packageName":"@happyvertical/smrt-messages","fields":{"tenantId":{"type":"text","_meta":{"__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":true,"autoPopulate":true,"nullable":false,"mode":"required","field":"tenantId","allowSuperAdminBypass":false},"__statedOptions":["sqlType","requiredFor","__tenancy"],"sqlType":"UUID","requiredFor":"tenant-scope"},"required":true},"recipientUserId":{"type":"crossPackageRef","_meta":{"__statedOptions":["required","requiredFor","related"],"required":true,"requiredFor":"identity"},"required":true,"related":"@happyvertical/smrt-users:User"},"channel":{"type":"text","_meta":{"__statedOptions":["required","default","enum"],"required":true},"required":true,"default":"email","enum":["email"]},"scope":{"type":"text","_meta":{"__statedOptions":["required","requiredFor"],"required":true,"requiredFor":"identity"},"required":true},"optedOutAt":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"updatedBy":{"type":"text","_meta":{"__statedOptions":[]},"required":false}},"methods":{},"decoratorConfig":{"tableName":"notification_opt_outs","api":false,"mcp":false,"cli":false,"conflictColumns":["tenant_id","recipient_user_id","channel","scope"],"tenantScoped":{"mode":"required"}},"extends":"SmrtObject","exportName":"NotificationOptOut","collectionExportName":"NotificationOptOutCollection","validationRules":[{"field":"recipientUserId","rule":"required","fieldType":"crossPackageRef"},{"field":"channel","rule":"required","fieldType":"text"},{"field":"scope","rule":"required","fieldType":"text"}],"schema":{"tableName":"notification_opt_outs","ddl":"CREATE TABLE IF NOT EXISTS \\"notification_opt_outs\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"recipient_user_id\\" UUID NOT NULL,\\n \\"channel\\" TEXT NOT NULL DEFAULT 'email',\\n \\"scope\\" TEXT NOT NULL,\\n \\"opted_out_at\\" TIMESTAMP,\\n \\"updated_by\\" TEXT\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"recipient_user_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":true,"unique":false},"channel":{"type":"TEXT","notNull":true,"unique":false,"default":"email"},"scope":{"type":"TEXT","notNull":true,"unique":false},"opted_out_at":{"type":"TIMESTAMP","notNull":false,"unique":false},"updated_by":{"type":"TEXT","notNull":false,"unique":false}},"indexes":[{"name":"notification_opt_outs_tenant_id_recipient_user_id_idx","columns":["tenant_id","recipient_user_id","channel","scope"],"unique":true},{"name":"notification_opt_outs_slug_context_idx","columns":["slug","context"]},{"name":"notification_opt_outs_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"notification_opt_outs_recipient_user_id_idx","columns":["recipient_user_id"]}],"version":"a13e93c1"},"importPath":"@happyvertical/smrt-messages"},"@happyvertical/smrt-messages:PersonaMessageRoute":{"name":"personamessageroute","className":"PersonaMessageRoute","qualifiedName":"@happyvertical/smrt-messages:PersonaMessageRoute","collection":"personamessageroutes","filePath":"src/models/PersonaMessageRoute.ts","packageName":"@happyvertical/smrt-messages","fields":{"tenantId":{"type":"text","_meta":{"__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":true,"autoPopulate":true,"nullable":false,"mode":"required","field":"tenantId","allowSuperAdminBypass":false},"__statedOptions":["sqlType","requiredFor","__tenancy"],"sqlType":"UUID","requiredFor":"tenant-scope"},"required":true},"personaId":{"type":"crossPackageRef","_meta":{"__statedOptions":["required","requiredFor","related"],"required":true,"requiredFor":"identity"},"required":true,"related":"@happyvertical/smrt-personas:AgentPersona"},"accountId":{"type":"foreignKey","_meta":{"__statedOptions":["required","requiredFor","related"],"required":true,"requiredFor":"identity"},"required":true,"related":"Account"},"endpointId":{"type":"foreignKey","_meta":{"__statedOptions":["required","requiredFor","related"],"required":true,"requiredFor":"identity"},"required":true,"related":"MessagingEndpoint"},"purpose":{"type":"text","_meta":{"__statedOptions":["required"],"required":true},"required":true},"priority":{"type":"integer","_meta":{"__statedOptions":["default"]},"required":true,"default":0},"enabled":{"type":"boolean","_meta":{"__statedOptions":["default"]},"required":true,"default":true},"createdAt":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"updatedAt":{"type":"text","_meta":{"__statedOptions":[]},"required":false}},"methods":{},"decoratorConfig":{"tableName":"persona_message_routes","api":{"include":["list","get"]},"mcp":{"include":["list","get"]},"cli":{"include":["list","get"]},"conflictColumns":["tenant_id","persona_id","account_id","endpoint_id","purpose"],"tenantScoped":{"mode":"required"}},"extends":"SmrtObject","exportName":"PersonaMessageRoute","collectionExportName":"PersonaMessageRouteCollection","validationRules":[{"field":"personaId","rule":"required","fieldType":"crossPackageRef"},{"field":"accountId","rule":"required","fieldType":"foreignKey"},{"field":"endpointId","rule":"required","fieldType":"foreignKey"},{"field":"purpose","rule":"required","fieldType":"text"},{"field":"priority","rule":"required","fieldType":"integer"},{"field":"enabled","rule":"required","fieldType":"boolean"}],"schema":{"tableName":"persona_message_routes","ddl":"CREATE TABLE IF NOT EXISTS \\"persona_message_routes\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"persona_id\\" UUID NOT NULL,\\n \\"account_id\\" UUID NOT NULL,\\n \\"endpoint_id\\" UUID NOT NULL,\\n \\"purpose\\" TEXT NOT NULL,\\n \\"priority\\" INTEGER NOT NULL DEFAULT 0,\\n \\"enabled\\" BOOLEAN NOT NULL DEFAULT TRUE\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"persona_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":true,"unique":false},"account_id":{"type":"UUID","referenceKind":"foreignKey","notNull":true,"unique":false,"foreignKey":{"table":"accounts","column":"id","onDelete":"CASCADE","onUpdate":"CASCADE"}},"endpoint_id":{"type":"UUID","referenceKind":"foreignKey","notNull":true,"unique":false,"foreignKey":{"table":"messaging_endpoints","column":"id","onDelete":"CASCADE","onUpdate":"CASCADE"}},"purpose":{"type":"TEXT","notNull":true,"unique":false},"priority":{"type":"INTEGER","notNull":true,"unique":false,"default":0},"enabled":{"type":"BOOLEAN","notNull":true,"unique":false,"default":true}},"indexes":[{"name":"persona_message_routes_tenant_id_persona_id_idx","columns":["tenant_id","persona_id","account_id","endpoint_id","purpose"],"unique":true},{"name":"persona_message_routes_slug_context_idx","columns":["slug","context"]},{"name":"persona_message_routes_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"persona_message_routes_persona_id_idx","columns":["persona_id"]},{"name":"persona_message_routes_account_id_idx","columns":["account_id"]},{"name":"persona_message_routes_endpoint_id_idx","columns":["endpoint_id"]}],"version":"3caf446e"},"importPath":"@happyvertical/smrt-messages"},"@happyvertical/smrt-messages:SlackAccount":{"name":"slackaccount","className":"SlackAccount","qualifiedName":"@happyvertical/smrt-messages:SlackAccount","collection":"accounts","filePath":"src/models/SlackAccount.ts","packageName":"@happyvertical/smrt-messages","fields":{"created_at":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"updated_at":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"tenantId":{"type":"text","_meta":{"__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":false,"autoPopulate":true,"nullable":true},"__statedOptions":["sqlType","nullable","__tenancy","required"],"required":false,"sqlType":"UUID","nullable":true},"required":false},"name":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The display name for this connected messaging account."},"required":false,"description":"The display name for this connected messaging account."},"providerType":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The service that connects this account to your application."},"required":false,"description":"The service that connects this account to your application."},"channelType":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The kind of messaging this account supports, such as email or chat."},"required":false,"description":"The kind of messaging this account supports, such as email or chat."},"credentialSecretId":{"type":"text","_meta":{"__statedOptions":["sensitive","readonly"],"sensitive":true,"readonly":true},"required":false,"sensitive":true,"readonly":true},"isActive":{"type":"boolean","_meta":{"__statedOptions":["description","default"],"description":"Whether this account is enabled for messaging."},"required":true,"default":true,"description":"Whether this account is enabled for messaging."},"ownerUserId":{"type":"crossPackageRef","_meta":{"__statedOptions":["description","related"],"description":"The person who owns this account and decides who else may use it."},"required":false,"related":"@happyvertical/smrt-users:User","description":"The person who owns this account and decides who else may use it."},"label":{"type":"text","_meta":{"__statedOptions":["description"],"description":"A short name shown beside this account, such as Support or Personal."},"required":false,"description":"A short name shown beside this account, such as Support or Personal."},"connectionStatus":{"type":"text","_meta":{"__statedOptions":["description"],"description":"Whether the saved sign-in still works: connected, or needs_reconnect after the server refused it."},"required":false,"description":"Whether the saved sign-in still works: connected, or needs_reconnect after the server refused it."},"statusMessage":{"type":"text","_meta":{"__statedOptions":["description"],"description":"Why the account needs attention, in plain words."},"required":false,"description":"Why the account needs attention, in plain words."},"lastSyncAt":{"type":"datetime","_meta":{"__statedOptions":["description"],"description":"When this account last checked for new messages."},"required":false,"description":"When this account last checked for new messages."},"settings":{"type":"text","_meta":{"__statedOptions":["sensitive","readonly"],"sensitive":true,"readonly":true},"required":false,"sensitive":true,"readonly":true},"configuration":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The public connection settings for this account; credentials are stored separately."},"required":false,"description":"The public connection settings for this account; credentials are stored separately."},"createdAt":{"type":"text","_meta":{"__statedOptions":["description"],"description":"When this account was added."},"required":false,"description":"When this account was added."},"updatedAt":{"type":"text","_meta":{"__statedOptions":["description"],"description":"When this account was last changed."},"required":false,"description":"When this account was last changed."},"workspaceId":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The identifier of the connected workspace."},"required":false,"description":"The identifier of the connected workspace."},"workspaceName":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The name of the connected workspace."},"required":false,"description":"The name of the connected workspace."},"botUserId":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The bot user your application posts as in this workspace."},"required":false,"description":"The bot user your application posts as in this workspace."}},"methods":{"getSettings":{"name":"getSettings","async":false,"parameters":[],"returnType":"Record<string, unknown>","isStatic":false,"isPublic":true},"setSettings":{"name":"setSettings","async":false,"parameters":[{"name":"settings","type":"Record<string, unknown>","optional":false}],"returnType":"void","isStatic":false,"isPublic":true},"getConfiguration":{"name":"getConfiguration","async":false,"parameters":[],"returnType":"Record<string, unknown>","isStatic":false,"isPublic":true},"setConfiguration":{"name":"setConfiguration","async":false,"parameters":[{"name":"configuration","type":"Record<string, unknown>","optional":false}],"returnType":"void","isStatic":false,"isPublic":true},"markNeedsReconnect":{"name":"markNeedsReconnect","async":true,"parameters":[{"name":"reason","type":"string","optional":false}],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"markConnected":{"name":"markConnected","async":true,"parameters":[],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"activate":{"name":"activate","async":true,"parameters":[],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"deactivate":{"name":"deactivate","async":true,"parameters":[],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"setCredentials":{"name":"setCredentials","async":true,"parameters":[{"name":"credentials","type":"Record<string, unknown>","optional":false},{"name":"options","type":"object","optional":true,"memberTypes":["string"]}],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"removeCredentials":{"name":"removeCredentials","async":true,"parameters":[],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"createSender":{"name":"createSender","async":true,"parameters":[],"returnType":"Promise<MessageSenderInterface>","isStatic":false,"isPublic":true},"getCredentials":{"name":"getCredentials","async":true,"parameters":[],"returnType":"Promise<Record<string, unknown> | null>","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableStrategy":"sti","api":{"include":["list","get"]},"mcp":{"include":["list","get"]},"cli":{"include":["list","get"]},"tableName":"accounts"},"extends":"Account","exportName":"SlackAccount","collectionExportName":"SlackAccountCollection","displayLabelField":"name","validationRules":[{"field":"isActive","rule":"required","fieldType":"boolean"}],"schema":{"tableName":"accounts","ddl":"CREATE TABLE IF NOT EXISTS \\"accounts\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"_meta_type\\" TEXT NOT NULL,\\n \\"_meta_data\\" JSON,\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"name\\" TEXT,\\n \\"provider_type\\" TEXT,\\n \\"channel_type\\" TEXT,\\n \\"credential_secret_id\\" TEXT,\\n \\"is_active\\" BOOLEAN DEFAULT TRUE,\\n \\"owner_user_id\\" UUID,\\n \\"label\\" TEXT,\\n \\"connection_status\\" TEXT,\\n \\"status_message\\" TEXT,\\n \\"last_sync_at\\" TIMESTAMP,\\n \\"settings\\" TEXT,\\n \\"configuration\\" TEXT,\\n \\"email\\" TEXT,\\n \\"sync_interval_minutes\\" INTEGER DEFAULT 60,\\n \\"sync_cursor\\" TEXT,\\n \\"backfill_since\\" TIMESTAMP,\\n \\"cursor_horizon\\" TIMESTAMP,\\n \\"last_sync_error\\" TEXT,\\n \\"backlog\\" BOOLEAN DEFAULT FALSE,\\n \\"workspace_id\\" TEXT,\\n \\"workspace_name\\" TEXT,\\n \\"bot_user_id\\" TEXT,\\n \\"handle\\" TEXT,\\n \\"twitter_user_id\\" TEXT\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"_meta_type":{"type":"TEXT","notNull":true},"_meta_data":{"type":"JSON","notNull":false},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false},"name":{"type":"TEXT","notNull":false},"provider_type":{"type":"TEXT","notNull":false},"channel_type":{"type":"TEXT","notNull":false},"credential_secret_id":{"type":"TEXT","notNull":false},"is_active":{"type":"BOOLEAN","notNull":false,"default":true},"owner_user_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false},"label":{"type":"TEXT","notNull":false},"connection_status":{"type":"TEXT","notNull":false},"status_message":{"type":"TEXT","notNull":false},"last_sync_at":{"type":"TIMESTAMP","notNull":false},"settings":{"type":"TEXT","notNull":false},"configuration":{"type":"TEXT","notNull":false},"email":{"type":"TEXT","notNull":false},"sync_interval_minutes":{"type":"INTEGER","notNull":false,"default":60},"sync_cursor":{"type":"TEXT","notNull":false},"backfill_since":{"type":"TIMESTAMP","notNull":false},"cursor_horizon":{"type":"TIMESTAMP","notNull":false},"last_sync_error":{"type":"TEXT","notNull":false},"backlog":{"type":"BOOLEAN","notNull":false,"default":false},"workspace_id":{"type":"TEXT","notNull":false},"workspace_name":{"type":"TEXT","notNull":false},"bot_user_id":{"type":"TEXT","notNull":false},"handle":{"type":"TEXT","notNull":false},"twitter_user_id":{"type":"TEXT","notNull":false}},"indexes":[{"name":"accounts_slug_context_meta_type_idx","columns":["tenant_id","slug","context","_meta_type"],"unique":true,"nullsNotDistinct":true},{"name":"accounts_meta_type_idx","columns":["_meta_type"]},{"name":"accounts_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"accounts_owner_user_id_idx","columns":["owner_user_id"]}],"checks":[{"name":"smrt_ck_81229bbfe8e3","columns":["backlog"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:EmailAccount') OR \\"backlog\\" IS NOT NULL"},{"name":"smrt_ck_1f9c5f0ee488","columns":["sync_interval_minutes"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:EmailAccount') OR \\"sync_interval_minutes\\" IS NOT NULL"}],"version":"f48d7a23"},"importPath":"@happyvertical/smrt-messages"},"@happyvertical/smrt-messages:SlackMessage":{"name":"slackmessage","className":"SlackMessage","qualifiedName":"@happyvertical/smrt-messages:SlackMessage","collection":"messages","filePath":"src/models/SlackMessage.ts","packageName":"@happyvertical/smrt-messages","fields":{"created_at":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"updated_at":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"tenantId":{"type":"text","_meta":{"__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":false,"autoPopulate":true,"nullable":true},"__statedOptions":["sqlType","nullable","__tenancy","required"],"required":false,"sqlType":"UUID","nullable":true},"required":false},"accountId":{"type":"foreignKey","_meta":{"__statedOptions":["description","related"],"description":"The connected account used to receive or send this message."},"required":false,"related":"Account","description":"The connected account used to receive or send this message."},"personaId":{"type":"crossPackageRef","_meta":{"__statedOptions":["nullable","description","related","required"],"required":false,"description":"The assistant identity associated with this message, when one was used.","nullable":true},"required":false,"related":"@happyvertical/smrt-personas:AgentPersona","description":"The assistant identity associated with this message, when one was used."},"endpointId":{"type":"foreignKey","_meta":{"__statedOptions":["description","related"],"description":"The saved destination used to deliver this message."},"required":false,"related":"MessagingEndpoint","description":"The saved destination used to deliver this message."},"correlationId":{"type":"text","_meta":{"__statedOptions":["description"],"description":"A tracking reference that connects this message to related activity."},"required":false,"description":"A tracking reference that connects this message to related activity."},"threadId":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The conversation this message belongs to."},"required":false,"description":"The conversation this message belongs to."},"subject":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The subject shown in the message list."},"required":false,"description":"The subject shown in the message list."},"body":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The message content in plain text."},"required":false,"description":"The message content in plain text."},"fromAddress":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The address the message was sent from."},"required":false,"description":"The address the message was sent from."},"fromName":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The sender name shown beside their address."},"required":false,"description":"The sender name shown beside their address."},"toAddresses":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The people or addresses receiving this message."},"required":false,"description":"The people or addresses receiving this message."},"date":{"type":"datetime","_meta":{"__statedOptions":["description"],"description":"When the message was sent or received."},"required":false,"description":"When the message was sent or received."},"isRead":{"type":"boolean","_meta":{"__statedOptions":["description","default"],"description":"Whether this message has been marked as read."},"required":true,"default":false,"description":"Whether this message has been marked as read."},"isFlagged":{"type":"boolean","_meta":{"__statedOptions":["description","default"],"description":"Whether this message is flagged for follow-up."},"required":true,"default":false,"description":"Whether this message is flagged for follow-up."},"hasAttachments":{"type":"boolean","_meta":{"__statedOptions":["description","default"],"description":"Whether files are attached to this message."},"required":true,"default":false,"description":"Whether files are attached to this message."},"size":{"type":"integer","_meta":{"__statedOptions":["description","default"],"description":"The size of the message in bytes."},"required":true,"default":0,"description":"The size of the message in bytes."},"metadata":{"type":"text","_meta":{"__statedOptions":["description"],"description":"Additional details supplied by the messaging connection."},"required":false,"description":"Additional details supplied by the messaging connection."},"sendStatus":{"type":"text","_meta":{"__statedOptions":["description","default","enum"],"description":"The latest sending state: draft, sending, sent, or failed. Received mail may also show draft here."},"required":false,"default":"draft","description":"The latest sending state: draft, sending, sent, or failed. Received mail may also show draft here.","enum":["draft","pending","sending","sent","failed","scheduled"]},"sentAt":{"type":"datetime","_meta":{"__statedOptions":["description"],"description":"When the message was successfully sent."},"required":false,"description":"When the message was successfully sent."},"sendError":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The reason the latest send attempt failed."},"required":false,"description":"The reason the latest send attempt failed."},"retryCount":{"type":"integer","_meta":{"__statedOptions":["description","default"],"description":"How many times delivery has been retried."},"required":true,"default":0,"description":"How many times delivery has been retried."},"maxRetries":{"type":"integer","_meta":{"__statedOptions":["description","default"],"description":"The maximum number of delivery retries allowed."},"required":true,"default":3,"description":"The maximum number of delivery retries allowed."},"scheduledSendAt":{"type":"datetime","_meta":{"__statedOptions":["description"],"description":"When this message is scheduled to be sent."},"required":false,"description":"When this message is scheduled to be sent."},"inReplyToMessageId":{"type":"foreignKey","_meta":{"__statedOptions":["description","related"],"description":"The earlier message this one replies to."},"required":false,"related":"Message","description":"The earlier message this one replies to."},"createdAt":{"type":"text","_meta":{"__statedOptions":["description"],"description":"When this message was recorded."},"required":false,"description":"When this message was recorded."},"updatedAt":{"type":"text","_meta":{"__statedOptions":["description"],"description":"When this message was last changed."},"required":false,"description":"When this message was last changed."},"channelId":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The identifier of the channel this message is in."},"required":false,"description":"The identifier of the channel this message is in."},"channelName":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The name of the channel this message was posted in."},"required":false,"description":"The name of the channel this message was posted in."},"slackTs":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The workspace's own reference for this message."},"required":false,"description":"The workspace's own reference for this message."},"slackThreadTs":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The workspace's own reference for the thread this message belongs to."},"required":false,"description":"The workspace's own reference for the thread this message belongs to."},"reactions":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The reactions people added to this message."},"required":false,"description":"The reactions people added to this message."},"isEdited":{"type":"boolean","_meta":{"__statedOptions":["description","default"],"description":"Whether this message was edited after posting."},"required":true,"default":false,"description":"Whether this message was edited after posting."},"messageType":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The kind of message, such as one from a person or a bot."},"required":false,"description":"The kind of message, such as one from a person or a bot."},"blocks":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The rich layout of the message as the workspace stores it."},"required":false,"description":"The rich layout of the message as the workspace stores it."}},"methods":{"save":{"name":"save","async":true,"parameters":[{"name":"options","type":"SmrtSaveOptions","optional":true}],"returnType":"Promise<this>","isStatic":false,"isPublic":true},"delete":{"name":"delete","async":true,"parameters":[{"name":"options","type":"object","optional":true,"memberTypes":["Date | string"]}],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"getToAddresses":{"name":"getToAddresses","async":false,"parameters":[],"returnType":"Array<object>","isStatic":false,"isPublic":true},"setToAddresses":{"name":"setToAddresses","async":false,"parameters":[{"name":"addresses","type":"Array<object>","optional":false,"memberTypes":["string"]}],"returnType":"void","isStatic":false,"isPublic":true},"getMetadata":{"name":"getMetadata","async":false,"parameters":[],"returnType":"Record<string, unknown>","isStatic":false,"isPublic":true},"setMetadata":{"name":"setMetadata","async":false,"parameters":[{"name":"data","type":"Record<string, unknown>","optional":false}],"returnType":"void","isStatic":false,"isPublic":true},"markRead":{"name":"markRead","async":true,"parameters":[],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"markUnread":{"name":"markUnread","async":true,"parameters":[],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"toggleFlagged":{"name":"toggleFlagged","async":true,"parameters":[],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"isUnread":{"name":"isUnread","async":false,"parameters":[],"returnType":"boolean","isStatic":false,"isPublic":true},"getPreview":{"name":"getPreview","async":false,"parameters":[{"name":"maxLength","type":"any","optional":true}],"returnType":"string","isStatic":false,"isPublic":true},"loadFromId":{"name":"loadFromId","async":true,"parameters":[],"returnType":"any","isStatic":false,"isPublic":true},"loadFromSlug":{"name":"loadFromSlug","async":true,"parameters":[],"returnType":"any","isStatic":false,"isPublic":true},"getAccount":{"name":"getAccount","async":true,"parameters":[],"returnType":"any","isStatic":false,"isPublic":true},"getEndpoint":{"name":"getEndpoint","async":true,"parameters":[],"returnType":"any","isStatic":false,"isPublic":true},"getThreadMessages":{"name":"getThreadMessages","async":true,"parameters":[],"returnType":"Promise<Message[]>","isStatic":false,"isPublic":true},"getAttachments":{"name":"getAttachments","async":true,"parameters":[],"returnType":"any","isStatic":false,"isPublic":true},"send":{"name":"send","async":true,"parameters":[{"name":"options","type":"SendMessageOptions","optional":true}],"returnType":"Promise<MessageSendResult>","isStatic":false,"isPublic":true},"isSendOutcomeUnknown":{"name":"isSendOutcomeUnknown","async":false,"parameters":[],"returnType":"boolean","isStatic":false,"isPublic":true},"abandonSendAttempt":{"name":"abandonSendAttempt","async":true,"parameters":[{"name":"reason","type":"string","optional":false}],"returnType":"Promise<boolean>","isStatic":false,"isPublic":true},"retrySend":{"name":"retrySend","async":true,"parameters":[{"name":"options","type":"SendMessageOptions","optional":true}],"returnType":"Promise<MessageSendResult>","isStatic":false,"isPublic":true},"createReply":{"name":"createReply","async":false,"parameters":[{"name":"_options","type":"object","optional":true,"memberTypes":["boolean"]}],"returnType":"Message","isStatic":false,"isPublic":true},"createForward":{"name":"createForward","async":false,"parameters":[],"returnType":"Message","isStatic":false,"isPublic":true},"getReactions":{"name":"getReactions","async":false,"parameters":[],"returnType":"Array<object>","isStatic":false,"isPublic":true},"getBlocks":{"name":"getBlocks","async":false,"parameters":[],"returnType":"Record<string, unknown>[]","isStatic":false,"isPublic":true},"isInThread":{"name":"isInThread","async":false,"parameters":[],"returnType":"boolean","isStatic":false,"isPublic":true},"getTotalReactions":{"name":"getTotalReactions","async":false,"parameters":[],"returnType":"number","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableStrategy":"sti","api":{"include":["list","get","create"]},"mcp":{"include":["list","get"]},"cli":{"skipApiCheck":true},"widenParentExposure":{"api":["create"]},"tableName":"messages"},"extends":"Message","exportName":"SlackMessage","collectionExportName":"SlackMessageCollection","validationRules":[{"field":"isRead","rule":"required","fieldType":"boolean"},{"field":"isFlagged","rule":"required","fieldType":"boolean"},{"field":"hasAttachments","rule":"required","fieldType":"boolean"},{"field":"size","rule":"required","fieldType":"integer"},{"field":"retryCount","rule":"required","fieldType":"integer"},{"field":"maxRetries","rule":"required","fieldType":"integer"},{"field":"isEdited","rule":"required","fieldType":"boolean"}],"schema":{"tableName":"messages","ddl":"CREATE TABLE IF NOT EXISTS \\"messages\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"_meta_type\\" TEXT NOT NULL,\\n \\"_meta_data\\" JSON,\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"account_id\\" UUID,\\n \\"persona_id\\" UUID,\\n \\"endpoint_id\\" UUID,\\n \\"correlation_id\\" TEXT,\\n \\"thread_id\\" TEXT,\\n \\"subject\\" TEXT,\\n \\"body\\" TEXT,\\n \\"from_address\\" TEXT,\\n \\"from_name\\" TEXT,\\n \\"to_addresses\\" TEXT,\\n \\"date\\" TIMESTAMP,\\n \\"is_read\\" BOOLEAN DEFAULT FALSE,\\n \\"is_flagged\\" BOOLEAN DEFAULT FALSE,\\n \\"has_attachments\\" BOOLEAN DEFAULT FALSE,\\n \\"size\\" INTEGER DEFAULT 0,\\n \\"metadata\\" TEXT,\\n \\"send_status\\" TEXT DEFAULT 'draft',\\n \\"sent_at\\" TIMESTAMP,\\n \\"send_error\\" TEXT,\\n \\"retry_count\\" INTEGER DEFAULT 0,\\n \\"max_retries\\" INTEGER DEFAULT 3,\\n \\"scheduled_send_at\\" TIMESTAMP,\\n \\"in_reply_to_message_id\\" UUID,\\n \\"message_id\\" TEXT,\\n \\"in_reply_to\\" TEXT,\\n \\"provider_message_id\\" TEXT,\\n \\"cc_addresses\\" TEXT,\\n \\"bcc_addresses\\" TEXT,\\n \\"reply_to_address\\" TEXT,\\n \\"reply_to_name\\" TEXT,\\n \\"text_body\\" TEXT,\\n \\"html_body\\" TEXT,\\n \\"folder_id\\" TEXT,\\n \\"folder_path\\" TEXT,\\n \\"labels\\" TEXT,\\n \\"flags\\" TEXT,\\n \\"is_answered\\" BOOLEAN DEFAULT FALSE,\\n \\"is_draft\\" BOOLEAN DEFAULT FALSE,\\n \\"raw_message\\" TEXT,\\n \\"headers\\" TEXT,\\n \\"channel_id\\" TEXT,\\n \\"channel_name\\" TEXT,\\n \\"slack_ts\\" TEXT,\\n \\"slack_thread_ts\\" TEXT,\\n \\"reactions\\" TEXT,\\n \\"is_edited\\" BOOLEAN DEFAULT FALSE,\\n \\"message_type\\" TEXT,\\n \\"blocks\\" TEXT,\\n \\"tweet_id\\" TEXT,\\n \\"retweet_count\\" INTEGER DEFAULT 0,\\n \\"like_count\\" INTEGER DEFAULT 0,\\n \\"reply_count\\" INTEGER DEFAULT 0,\\n \\"is_retweet\\" BOOLEAN DEFAULT FALSE,\\n \\"is_reply\\" BOOLEAN DEFAULT FALSE,\\n \\"media_urls\\" TEXT,\\n \\"hashtags\\" TEXT,\\n \\"mentions\\" TEXT\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"_meta_type":{"type":"TEXT","notNull":true},"_meta_data":{"type":"JSON","notNull":false},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false},"account_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"foreignKey":{"table":"accounts","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"persona_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false},"endpoint_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"foreignKey":{"table":"messaging_endpoints","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"correlation_id":{"type":"TEXT","notNull":false},"thread_id":{"type":"TEXT","notNull":false},"subject":{"type":"TEXT","notNull":false},"body":{"type":"TEXT","notNull":false},"from_address":{"type":"TEXT","notNull":false},"from_name":{"type":"TEXT","notNull":false},"to_addresses":{"type":"TEXT","notNull":false},"date":{"type":"TIMESTAMP","notNull":false},"is_read":{"type":"BOOLEAN","notNull":false,"default":false},"is_flagged":{"type":"BOOLEAN","notNull":false,"default":false},"has_attachments":{"type":"BOOLEAN","notNull":false,"default":false},"size":{"type":"INTEGER","notNull":false,"default":0},"metadata":{"type":"TEXT","notNull":false},"send_status":{"type":"TEXT","notNull":false,"default":"draft"},"sent_at":{"type":"TIMESTAMP","notNull":false},"send_error":{"type":"TEXT","notNull":false},"retry_count":{"type":"INTEGER","notNull":false,"default":0},"max_retries":{"type":"INTEGER","notNull":false,"default":3},"scheduled_send_at":{"type":"TIMESTAMP","notNull":false},"in_reply_to_message_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"foreignKey":{"table":"messages","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"message_id":{"type":"TEXT","notNull":false},"in_reply_to":{"type":"TEXT","notNull":false},"provider_message_id":{"type":"TEXT","notNull":false},"cc_addresses":{"type":"TEXT","notNull":false},"bcc_addresses":{"type":"TEXT","notNull":false},"reply_to_address":{"type":"TEXT","notNull":false},"reply_to_name":{"type":"TEXT","notNull":false},"text_body":{"type":"TEXT","notNull":false},"html_body":{"type":"TEXT","notNull":false},"folder_id":{"type":"TEXT","notNull":false},"folder_path":{"type":"TEXT","notNull":false},"labels":{"type":"TEXT","notNull":false},"flags":{"type":"TEXT","notNull":false},"is_answered":{"type":"BOOLEAN","notNull":false,"default":false},"is_draft":{"type":"BOOLEAN","notNull":false,"default":false},"raw_message":{"type":"TEXT","notNull":false},"headers":{"type":"TEXT","notNull":false},"channel_id":{"type":"TEXT","notNull":false},"channel_name":{"type":"TEXT","notNull":false},"slack_ts":{"type":"TEXT","notNull":false},"slack_thread_ts":{"type":"TEXT","notNull":false},"reactions":{"type":"TEXT","notNull":false},"is_edited":{"type":"BOOLEAN","notNull":false,"default":false},"message_type":{"type":"TEXT","notNull":false},"blocks":{"type":"TEXT","notNull":false},"tweet_id":{"type":"TEXT","notNull":false},"retweet_count":{"type":"INTEGER","notNull":false,"default":0},"like_count":{"type":"INTEGER","notNull":false,"default":0},"reply_count":{"type":"INTEGER","notNull":false,"default":0},"is_retweet":{"type":"BOOLEAN","notNull":false,"default":false},"is_reply":{"type":"BOOLEAN","notNull":false,"default":false},"media_urls":{"type":"TEXT","notNull":false},"hashtags":{"type":"TEXT","notNull":false},"mentions":{"type":"TEXT","notNull":false}},"indexes":[{"name":"messages_slug_context_meta_type_idx","columns":["tenant_id","slug","context","_meta_type"],"unique":true,"nullsNotDistinct":true},{"name":"messages_meta_type_idx","columns":["_meta_type"]},{"name":"messages_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"messages_account_id_idx","columns":["account_id"]},{"name":"messages_persona_id_idx","columns":["persona_id"]},{"name":"messages_endpoint_id_idx","columns":["endpoint_id"]},{"name":"messages_in_reply_to_message_id_idx","columns":["in_reply_to_message_id"]}],"checks":[{"name":"smrt_ck_d0024f738cf4","columns":["is_answered"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:Email') OR \\"is_answered\\" IS NOT NULL"},{"name":"smrt_ck_0adcd2453c81","columns":["is_draft"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:Email') OR \\"is_draft\\" IS NOT NULL"},{"name":"smrt_ck_428e155c9609","columns":["is_edited"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:SlackMessage') OR \\"is_edited\\" IS NOT NULL"},{"name":"smrt_ck_a17af99e85e3","columns":["is_reply"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:Tweet') OR \\"is_reply\\" IS NOT NULL"},{"name":"smrt_ck_3e30563cba58","columns":["is_retweet"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:Tweet') OR \\"is_retweet\\" IS NOT NULL"},{"name":"smrt_ck_bab2c772ebe6","columns":["like_count"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:Tweet') OR \\"like_count\\" IS NOT NULL"},{"name":"smrt_ck_c6ad8d47bbc8","columns":["reply_count"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:Tweet') OR \\"reply_count\\" IS NOT NULL"},{"name":"smrt_ck_43a00e1c098d","columns":["retweet_count"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:Tweet') OR \\"retweet_count\\" IS NOT NULL"}],"version":"63b1a1ae"},"importPath":"@happyvertical/smrt-messages"},"@happyvertical/smrt-messages:TelegramAccount":{"name":"telegramaccount","className":"TelegramAccount","qualifiedName":"@happyvertical/smrt-messages:TelegramAccount","collection":"accounts","filePath":"src/models/TelegramAccount.ts","packageName":"@happyvertical/smrt-messages","fields":{"created_at":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"updated_at":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"tenantId":{"type":"text","_meta":{"__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":false,"autoPopulate":true,"nullable":true},"__statedOptions":["sqlType","nullable","__tenancy","required"],"required":false,"sqlType":"UUID","nullable":true},"required":false},"name":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The display name for this connected messaging account."},"required":false,"description":"The display name for this connected messaging account."},"providerType":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The service that connects this account to your application."},"required":false,"description":"The service that connects this account to your application."},"channelType":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The kind of messaging this account supports, such as email or chat."},"required":false,"description":"The kind of messaging this account supports, such as email or chat."},"credentialSecretId":{"type":"text","_meta":{"__statedOptions":["sensitive","readonly"],"sensitive":true,"readonly":true},"required":false,"sensitive":true,"readonly":true},"isActive":{"type":"boolean","_meta":{"__statedOptions":["description","default"],"description":"Whether this account is enabled for messaging."},"required":true,"default":true,"description":"Whether this account is enabled for messaging."},"ownerUserId":{"type":"crossPackageRef","_meta":{"__statedOptions":["description","related"],"description":"The person who owns this account and decides who else may use it."},"required":false,"related":"@happyvertical/smrt-users:User","description":"The person who owns this account and decides who else may use it."},"label":{"type":"text","_meta":{"__statedOptions":["description"],"description":"A short name shown beside this account, such as Support or Personal."},"required":false,"description":"A short name shown beside this account, such as Support or Personal."},"connectionStatus":{"type":"text","_meta":{"__statedOptions":["description"],"description":"Whether the saved sign-in still works: connected, or needs_reconnect after the server refused it."},"required":false,"description":"Whether the saved sign-in still works: connected, or needs_reconnect after the server refused it."},"statusMessage":{"type":"text","_meta":{"__statedOptions":["description"],"description":"Why the account needs attention, in plain words."},"required":false,"description":"Why the account needs attention, in plain words."},"lastSyncAt":{"type":"datetime","_meta":{"__statedOptions":["description"],"description":"When this account last checked for new messages."},"required":false,"description":"When this account last checked for new messages."},"settings":{"type":"text","_meta":{"__statedOptions":["sensitive","readonly"],"sensitive":true,"readonly":true},"required":false,"sensitive":true,"readonly":true},"configuration":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The public connection settings for this account; credentials are stored separately."},"required":false,"description":"The public connection settings for this account; credentials are stored separately."},"createdAt":{"type":"text","_meta":{"__statedOptions":["description"],"description":"When this account was added."},"required":false,"description":"When this account was added."},"updatedAt":{"type":"text","_meta":{"__statedOptions":["description"],"description":"When this account was last changed."},"required":false,"description":"When this account was last changed."}},"methods":{"getSettings":{"name":"getSettings","async":false,"parameters":[],"returnType":"Record<string, unknown>","isStatic":false,"isPublic":true},"setSettings":{"name":"setSettings","async":false,"parameters":[{"name":"settings","type":"Record<string, unknown>","optional":false}],"returnType":"void","isStatic":false,"isPublic":true},"getConfiguration":{"name":"getConfiguration","async":false,"parameters":[],"returnType":"Record<string, unknown>","isStatic":false,"isPublic":true},"setConfiguration":{"name":"setConfiguration","async":false,"parameters":[{"name":"configuration","type":"Record<string, unknown>","optional":false}],"returnType":"void","isStatic":false,"isPublic":true},"markNeedsReconnect":{"name":"markNeedsReconnect","async":true,"parameters":[{"name":"reason","type":"string","optional":false}],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"markConnected":{"name":"markConnected","async":true,"parameters":[],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"activate":{"name":"activate","async":true,"parameters":[],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"deactivate":{"name":"deactivate","async":true,"parameters":[],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"setCredentials":{"name":"setCredentials","async":true,"parameters":[{"name":"credentials","type":"Record<string, unknown>","optional":false},{"name":"options","type":"object","optional":true,"memberTypes":["string"]}],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"removeCredentials":{"name":"removeCredentials","async":true,"parameters":[],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"createSender":{"name":"createSender","async":true,"parameters":[],"returnType":"Promise<MessageSenderInterface>","isStatic":false,"isPublic":true},"getCredentials":{"name":"getCredentials","async":true,"parameters":[],"returnType":"Promise<Record<string, unknown> | null>","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableStrategy":"sti","api":{"include":["list","get"]},"mcp":{"include":["list","get"]},"cli":{"include":["list","get"]},"tableName":"accounts"},"extends":"Account","exportName":"TelegramAccount","collectionExportName":"TelegramAccountCollection","displayLabelField":"name","validationRules":[{"field":"isActive","rule":"required","fieldType":"boolean"}],"schema":{"tableName":"accounts","ddl":"CREATE TABLE IF NOT EXISTS \\"accounts\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"_meta_type\\" TEXT NOT NULL,\\n \\"_meta_data\\" JSON,\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"name\\" TEXT,\\n \\"provider_type\\" TEXT,\\n \\"channel_type\\" TEXT,\\n \\"credential_secret_id\\" TEXT,\\n \\"is_active\\" BOOLEAN DEFAULT TRUE,\\n \\"owner_user_id\\" UUID,\\n \\"label\\" TEXT,\\n \\"connection_status\\" TEXT,\\n \\"status_message\\" TEXT,\\n \\"last_sync_at\\" TIMESTAMP,\\n \\"settings\\" TEXT,\\n \\"configuration\\" TEXT,\\n \\"email\\" TEXT,\\n \\"sync_interval_minutes\\" INTEGER DEFAULT 60,\\n \\"sync_cursor\\" TEXT,\\n \\"backfill_since\\" TIMESTAMP,\\n \\"cursor_horizon\\" TIMESTAMP,\\n \\"last_sync_error\\" TEXT,\\n \\"backlog\\" BOOLEAN DEFAULT FALSE,\\n \\"workspace_id\\" TEXT,\\n \\"workspace_name\\" TEXT,\\n \\"bot_user_id\\" TEXT,\\n \\"handle\\" TEXT,\\n \\"twitter_user_id\\" TEXT\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"_meta_type":{"type":"TEXT","notNull":true},"_meta_data":{"type":"JSON","notNull":false},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false},"name":{"type":"TEXT","notNull":false},"provider_type":{"type":"TEXT","notNull":false},"channel_type":{"type":"TEXT","notNull":false},"credential_secret_id":{"type":"TEXT","notNull":false},"is_active":{"type":"BOOLEAN","notNull":false,"default":true},"owner_user_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false},"label":{"type":"TEXT","notNull":false},"connection_status":{"type":"TEXT","notNull":false},"status_message":{"type":"TEXT","notNull":false},"last_sync_at":{"type":"TIMESTAMP","notNull":false},"settings":{"type":"TEXT","notNull":false},"configuration":{"type":"TEXT","notNull":false},"email":{"type":"TEXT","notNull":false},"sync_interval_minutes":{"type":"INTEGER","notNull":false,"default":60},"sync_cursor":{"type":"TEXT","notNull":false},"backfill_since":{"type":"TIMESTAMP","notNull":false},"cursor_horizon":{"type":"TIMESTAMP","notNull":false},"last_sync_error":{"type":"TEXT","notNull":false},"backlog":{"type":"BOOLEAN","notNull":false,"default":false},"workspace_id":{"type":"TEXT","notNull":false},"workspace_name":{"type":"TEXT","notNull":false},"bot_user_id":{"type":"TEXT","notNull":false},"handle":{"type":"TEXT","notNull":false},"twitter_user_id":{"type":"TEXT","notNull":false}},"indexes":[{"name":"accounts_slug_context_meta_type_idx","columns":["tenant_id","slug","context","_meta_type"],"unique":true,"nullsNotDistinct":true},{"name":"accounts_meta_type_idx","columns":["_meta_type"]},{"name":"accounts_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"accounts_owner_user_id_idx","columns":["owner_user_id"]}],"checks":[{"name":"smrt_ck_81229bbfe8e3","columns":["backlog"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:EmailAccount') OR \\"backlog\\" IS NOT NULL"},{"name":"smrt_ck_1f9c5f0ee488","columns":["sync_interval_minutes"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:EmailAccount') OR \\"sync_interval_minutes\\" IS NOT NULL"}],"version":"f48d7a23"},"importPath":"@happyvertical/smrt-messages"},"@happyvertical/smrt-messages:Tweet":{"name":"tweet","className":"Tweet","qualifiedName":"@happyvertical/smrt-messages:Tweet","collection":"messages","filePath":"src/models/Tweet.ts","packageName":"@happyvertical/smrt-messages","fields":{"created_at":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"updated_at":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"tenantId":{"type":"text","_meta":{"__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":false,"autoPopulate":true,"nullable":true},"__statedOptions":["sqlType","nullable","__tenancy","required"],"required":false,"sqlType":"UUID","nullable":true},"required":false},"accountId":{"type":"foreignKey","_meta":{"__statedOptions":["description","related"],"description":"The connected account used to receive or send this message."},"required":false,"related":"Account","description":"The connected account used to receive or send this message."},"personaId":{"type":"crossPackageRef","_meta":{"__statedOptions":["nullable","description","related","required"],"required":false,"description":"The assistant identity associated with this message, when one was used.","nullable":true},"required":false,"related":"@happyvertical/smrt-personas:AgentPersona","description":"The assistant identity associated with this message, when one was used."},"endpointId":{"type":"foreignKey","_meta":{"__statedOptions":["description","related"],"description":"The saved destination used to deliver this message."},"required":false,"related":"MessagingEndpoint","description":"The saved destination used to deliver this message."},"correlationId":{"type":"text","_meta":{"__statedOptions":["description"],"description":"A tracking reference that connects this message to related activity."},"required":false,"description":"A tracking reference that connects this message to related activity."},"threadId":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The conversation this message belongs to."},"required":false,"description":"The conversation this message belongs to."},"subject":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The subject shown in the message list."},"required":false,"description":"The subject shown in the message list."},"body":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The message content in plain text."},"required":false,"description":"The message content in plain text."},"fromAddress":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The address the message was sent from."},"required":false,"description":"The address the message was sent from."},"fromName":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The sender name shown beside their address."},"required":false,"description":"The sender name shown beside their address."},"toAddresses":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The people or addresses receiving this message."},"required":false,"description":"The people or addresses receiving this message."},"date":{"type":"datetime","_meta":{"__statedOptions":["description"],"description":"When the message was sent or received."},"required":false,"description":"When the message was sent or received."},"isRead":{"type":"boolean","_meta":{"__statedOptions":["description","default"],"description":"Whether this message has been marked as read."},"required":true,"default":false,"description":"Whether this message has been marked as read."},"isFlagged":{"type":"boolean","_meta":{"__statedOptions":["description","default"],"description":"Whether this message is flagged for follow-up."},"required":true,"default":false,"description":"Whether this message is flagged for follow-up."},"hasAttachments":{"type":"boolean","_meta":{"__statedOptions":["description","default"],"description":"Whether files are attached to this message."},"required":true,"default":false,"description":"Whether files are attached to this message."},"size":{"type":"integer","_meta":{"__statedOptions":["description","default"],"description":"The size of the message in bytes."},"required":true,"default":0,"description":"The size of the message in bytes."},"metadata":{"type":"text","_meta":{"__statedOptions":["description"],"description":"Additional details supplied by the messaging connection."},"required":false,"description":"Additional details supplied by the messaging connection."},"sendStatus":{"type":"text","_meta":{"__statedOptions":["description","default","enum"],"description":"The latest sending state: draft, sending, sent, or failed. Received mail may also show draft here."},"required":false,"default":"draft","description":"The latest sending state: draft, sending, sent, or failed. Received mail may also show draft here.","enum":["draft","pending","sending","sent","failed","scheduled"]},"sentAt":{"type":"datetime","_meta":{"__statedOptions":["description"],"description":"When the message was successfully sent."},"required":false,"description":"When the message was successfully sent."},"sendError":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The reason the latest send attempt failed."},"required":false,"description":"The reason the latest send attempt failed."},"retryCount":{"type":"integer","_meta":{"__statedOptions":["description","default"],"description":"How many times delivery has been retried."},"required":true,"default":0,"description":"How many times delivery has been retried."},"maxRetries":{"type":"integer","_meta":{"__statedOptions":["description","default"],"description":"The maximum number of delivery retries allowed."},"required":true,"default":3,"description":"The maximum number of delivery retries allowed."},"scheduledSendAt":{"type":"datetime","_meta":{"__statedOptions":["description"],"description":"When this message is scheduled to be sent."},"required":false,"description":"When this message is scheduled to be sent."},"inReplyToMessageId":{"type":"foreignKey","_meta":{"__statedOptions":["description","related"],"description":"The earlier message this one replies to."},"required":false,"related":"Message","description":"The earlier message this one replies to."},"createdAt":{"type":"text","_meta":{"__statedOptions":["description"],"description":"When this message was recorded."},"required":false,"description":"When this message was recorded."},"updatedAt":{"type":"text","_meta":{"__statedOptions":["description"],"description":"When this message was last changed."},"required":false,"description":"When this message was last changed."},"tweetId":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"retweetCount":{"type":"integer","_meta":{"__statedOptions":["default"]},"required":true,"default":0},"likeCount":{"type":"integer","_meta":{"__statedOptions":["default"]},"required":true,"default":0},"replyCount":{"type":"integer","_meta":{"__statedOptions":["default"]},"required":true,"default":0},"isRetweet":{"type":"boolean","_meta":{"__statedOptions":["default"]},"required":true,"default":false},"isReply":{"type":"boolean","_meta":{"__statedOptions":["default"]},"required":true,"default":false},"mediaUrls":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"hashtags":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"mentions":{"type":"text","_meta":{"__statedOptions":[]},"required":false}},"methods":{"save":{"name":"save","async":true,"parameters":[{"name":"options","type":"SmrtSaveOptions","optional":true}],"returnType":"Promise<this>","isStatic":false,"isPublic":true},"delete":{"name":"delete","async":true,"parameters":[{"name":"options","type":"object","optional":true,"memberTypes":["Date | string"]}],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"getToAddresses":{"name":"getToAddresses","async":false,"parameters":[],"returnType":"Array<object>","isStatic":false,"isPublic":true},"setToAddresses":{"name":"setToAddresses","async":false,"parameters":[{"name":"addresses","type":"Array<object>","optional":false,"memberTypes":["string"]}],"returnType":"void","isStatic":false,"isPublic":true},"getMetadata":{"name":"getMetadata","async":false,"parameters":[],"returnType":"Record<string, unknown>","isStatic":false,"isPublic":true},"setMetadata":{"name":"setMetadata","async":false,"parameters":[{"name":"data","type":"Record<string, unknown>","optional":false}],"returnType":"void","isStatic":false,"isPublic":true},"markRead":{"name":"markRead","async":true,"parameters":[],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"markUnread":{"name":"markUnread","async":true,"parameters":[],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"toggleFlagged":{"name":"toggleFlagged","async":true,"parameters":[],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"isUnread":{"name":"isUnread","async":false,"parameters":[],"returnType":"boolean","isStatic":false,"isPublic":true},"getPreview":{"name":"getPreview","async":false,"parameters":[{"name":"maxLength","type":"any","optional":true}],"returnType":"string","isStatic":false,"isPublic":true},"loadFromId":{"name":"loadFromId","async":true,"parameters":[],"returnType":"any","isStatic":false,"isPublic":true},"loadFromSlug":{"name":"loadFromSlug","async":true,"parameters":[],"returnType":"any","isStatic":false,"isPublic":true},"getAccount":{"name":"getAccount","async":true,"parameters":[],"returnType":"any","isStatic":false,"isPublic":true},"getEndpoint":{"name":"getEndpoint","async":true,"parameters":[],"returnType":"any","isStatic":false,"isPublic":true},"getThreadMessages":{"name":"getThreadMessages","async":true,"parameters":[],"returnType":"Promise<Message[]>","isStatic":false,"isPublic":true},"getAttachments":{"name":"getAttachments","async":true,"parameters":[],"returnType":"any","isStatic":false,"isPublic":true},"send":{"name":"send","async":true,"parameters":[{"name":"options","type":"SendMessageOptions","optional":true}],"returnType":"Promise<MessageSendResult>","isStatic":false,"isPublic":true},"isSendOutcomeUnknown":{"name":"isSendOutcomeUnknown","async":false,"parameters":[],"returnType":"boolean","isStatic":false,"isPublic":true},"abandonSendAttempt":{"name":"abandonSendAttempt","async":true,"parameters":[{"name":"reason","type":"string","optional":false}],"returnType":"Promise<boolean>","isStatic":false,"isPublic":true},"retrySend":{"name":"retrySend","async":true,"parameters":[{"name":"options","type":"SendMessageOptions","optional":true}],"returnType":"Promise<MessageSendResult>","isStatic":false,"isPublic":true},"createReply":{"name":"createReply","async":false,"parameters":[{"name":"_options","type":"object","optional":true,"memberTypes":["boolean"]}],"returnType":"Message","isStatic":false,"isPublic":true},"createForward":{"name":"createForward","async":false,"parameters":[],"returnType":"Message","isStatic":false,"isPublic":true},"getMediaUrls":{"name":"getMediaUrls","async":false,"parameters":[],"returnType":"string[]","isStatic":false,"isPublic":true},"getHashtags":{"name":"getHashtags","async":false,"parameters":[],"returnType":"string[]","isStatic":false,"isPublic":true},"getMentions":{"name":"getMentions","async":false,"parameters":[],"returnType":"string[]","isStatic":false,"isPublic":true},"getEngagement":{"name":"getEngagement","async":false,"parameters":[],"returnType":"number","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableStrategy":"sti","api":{"include":["list","get","create"]},"mcp":{"include":["list","get"]},"cli":{"skipApiCheck":true},"widenParentExposure":{"api":["create"]},"tableName":"messages"},"extends":"Message","exportName":"Tweet","collectionExportName":"TweetCollection","validationRules":[{"field":"isRead","rule":"required","fieldType":"boolean"},{"field":"isFlagged","rule":"required","fieldType":"boolean"},{"field":"hasAttachments","rule":"required","fieldType":"boolean"},{"field":"size","rule":"required","fieldType":"integer"},{"field":"retryCount","rule":"required","fieldType":"integer"},{"field":"maxRetries","rule":"required","fieldType":"integer"},{"field":"retweetCount","rule":"required","fieldType":"integer"},{"field":"likeCount","rule":"required","fieldType":"integer"},{"field":"replyCount","rule":"required","fieldType":"integer"},{"field":"isRetweet","rule":"required","fieldType":"boolean"},{"field":"isReply","rule":"required","fieldType":"boolean"}],"schema":{"tableName":"messages","ddl":"CREATE TABLE IF NOT EXISTS \\"messages\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"_meta_type\\" TEXT NOT NULL,\\n \\"_meta_data\\" JSON,\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"account_id\\" UUID,\\n \\"persona_id\\" UUID,\\n \\"endpoint_id\\" UUID,\\n \\"correlation_id\\" TEXT,\\n \\"thread_id\\" TEXT,\\n \\"subject\\" TEXT,\\n \\"body\\" TEXT,\\n \\"from_address\\" TEXT,\\n \\"from_name\\" TEXT,\\n \\"to_addresses\\" TEXT,\\n \\"date\\" TIMESTAMP,\\n \\"is_read\\" BOOLEAN DEFAULT FALSE,\\n \\"is_flagged\\" BOOLEAN DEFAULT FALSE,\\n \\"has_attachments\\" BOOLEAN DEFAULT FALSE,\\n \\"size\\" INTEGER DEFAULT 0,\\n \\"metadata\\" TEXT,\\n \\"send_status\\" TEXT DEFAULT 'draft',\\n \\"sent_at\\" TIMESTAMP,\\n \\"send_error\\" TEXT,\\n \\"retry_count\\" INTEGER DEFAULT 0,\\n \\"max_retries\\" INTEGER DEFAULT 3,\\n \\"scheduled_send_at\\" TIMESTAMP,\\n \\"in_reply_to_message_id\\" UUID,\\n \\"message_id\\" TEXT,\\n \\"in_reply_to\\" TEXT,\\n \\"provider_message_id\\" TEXT,\\n \\"cc_addresses\\" TEXT,\\n \\"bcc_addresses\\" TEXT,\\n \\"reply_to_address\\" TEXT,\\n \\"reply_to_name\\" TEXT,\\n \\"text_body\\" TEXT,\\n \\"html_body\\" TEXT,\\n \\"folder_id\\" TEXT,\\n \\"folder_path\\" TEXT,\\n \\"labels\\" TEXT,\\n \\"flags\\" TEXT,\\n \\"is_answered\\" BOOLEAN DEFAULT FALSE,\\n \\"is_draft\\" BOOLEAN DEFAULT FALSE,\\n \\"raw_message\\" TEXT,\\n \\"headers\\" TEXT,\\n \\"channel_id\\" TEXT,\\n \\"channel_name\\" TEXT,\\n \\"slack_ts\\" TEXT,\\n \\"slack_thread_ts\\" TEXT,\\n \\"reactions\\" TEXT,\\n \\"is_edited\\" BOOLEAN DEFAULT FALSE,\\n \\"message_type\\" TEXT,\\n \\"blocks\\" TEXT,\\n \\"tweet_id\\" TEXT,\\n \\"retweet_count\\" INTEGER DEFAULT 0,\\n \\"like_count\\" INTEGER DEFAULT 0,\\n \\"reply_count\\" INTEGER DEFAULT 0,\\n \\"is_retweet\\" BOOLEAN DEFAULT FALSE,\\n \\"is_reply\\" BOOLEAN DEFAULT FALSE,\\n \\"media_urls\\" TEXT,\\n \\"hashtags\\" TEXT,\\n \\"mentions\\" TEXT\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"_meta_type":{"type":"TEXT","notNull":true},"_meta_data":{"type":"JSON","notNull":false},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false},"account_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"foreignKey":{"table":"accounts","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"persona_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false},"endpoint_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"foreignKey":{"table":"messaging_endpoints","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"correlation_id":{"type":"TEXT","notNull":false},"thread_id":{"type":"TEXT","notNull":false},"subject":{"type":"TEXT","notNull":false},"body":{"type":"TEXT","notNull":false},"from_address":{"type":"TEXT","notNull":false},"from_name":{"type":"TEXT","notNull":false},"to_addresses":{"type":"TEXT","notNull":false},"date":{"type":"TIMESTAMP","notNull":false},"is_read":{"type":"BOOLEAN","notNull":false,"default":false},"is_flagged":{"type":"BOOLEAN","notNull":false,"default":false},"has_attachments":{"type":"BOOLEAN","notNull":false,"default":false},"size":{"type":"INTEGER","notNull":false,"default":0},"metadata":{"type":"TEXT","notNull":false},"send_status":{"type":"TEXT","notNull":false,"default":"draft"},"sent_at":{"type":"TIMESTAMP","notNull":false},"send_error":{"type":"TEXT","notNull":false},"retry_count":{"type":"INTEGER","notNull":false,"default":0},"max_retries":{"type":"INTEGER","notNull":false,"default":3},"scheduled_send_at":{"type":"TIMESTAMP","notNull":false},"in_reply_to_message_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"foreignKey":{"table":"messages","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"message_id":{"type":"TEXT","notNull":false},"in_reply_to":{"type":"TEXT","notNull":false},"provider_message_id":{"type":"TEXT","notNull":false},"cc_addresses":{"type":"TEXT","notNull":false},"bcc_addresses":{"type":"TEXT","notNull":false},"reply_to_address":{"type":"TEXT","notNull":false},"reply_to_name":{"type":"TEXT","notNull":false},"text_body":{"type":"TEXT","notNull":false},"html_body":{"type":"TEXT","notNull":false},"folder_id":{"type":"TEXT","notNull":false},"folder_path":{"type":"TEXT","notNull":false},"labels":{"type":"TEXT","notNull":false},"flags":{"type":"TEXT","notNull":false},"is_answered":{"type":"BOOLEAN","notNull":false,"default":false},"is_draft":{"type":"BOOLEAN","notNull":false,"default":false},"raw_message":{"type":"TEXT","notNull":false},"headers":{"type":"TEXT","notNull":false},"channel_id":{"type":"TEXT","notNull":false},"channel_name":{"type":"TEXT","notNull":false},"slack_ts":{"type":"TEXT","notNull":false},"slack_thread_ts":{"type":"TEXT","notNull":false},"reactions":{"type":"TEXT","notNull":false},"is_edited":{"type":"BOOLEAN","notNull":false,"default":false},"message_type":{"type":"TEXT","notNull":false},"blocks":{"type":"TEXT","notNull":false},"tweet_id":{"type":"TEXT","notNull":false},"retweet_count":{"type":"INTEGER","notNull":false,"default":0},"like_count":{"type":"INTEGER","notNull":false,"default":0},"reply_count":{"type":"INTEGER","notNull":false,"default":0},"is_retweet":{"type":"BOOLEAN","notNull":false,"default":false},"is_reply":{"type":"BOOLEAN","notNull":false,"default":false},"media_urls":{"type":"TEXT","notNull":false},"hashtags":{"type":"TEXT","notNull":false},"mentions":{"type":"TEXT","notNull":false}},"indexes":[{"name":"messages_slug_context_meta_type_idx","columns":["tenant_id","slug","context","_meta_type"],"unique":true,"nullsNotDistinct":true},{"name":"messages_meta_type_idx","columns":["_meta_type"]},{"name":"messages_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"messages_account_id_idx","columns":["account_id"]},{"name":"messages_persona_id_idx","columns":["persona_id"]},{"name":"messages_endpoint_id_idx","columns":["endpoint_id"]},{"name":"messages_in_reply_to_message_id_idx","columns":["in_reply_to_message_id"]}],"checks":[{"name":"smrt_ck_d0024f738cf4","columns":["is_answered"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:Email') OR \\"is_answered\\" IS NOT NULL"},{"name":"smrt_ck_0adcd2453c81","columns":["is_draft"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:Email') OR \\"is_draft\\" IS NOT NULL"},{"name":"smrt_ck_428e155c9609","columns":["is_edited"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:SlackMessage') OR \\"is_edited\\" IS NOT NULL"},{"name":"smrt_ck_a17af99e85e3","columns":["is_reply"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:Tweet') OR \\"is_reply\\" IS NOT NULL"},{"name":"smrt_ck_3e30563cba58","columns":["is_retweet"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:Tweet') OR \\"is_retweet\\" IS NOT NULL"},{"name":"smrt_ck_bab2c772ebe6","columns":["like_count"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:Tweet') OR \\"like_count\\" IS NOT NULL"},{"name":"smrt_ck_c6ad8d47bbc8","columns":["reply_count"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:Tweet') OR \\"reply_count\\" IS NOT NULL"},{"name":"smrt_ck_43a00e1c098d","columns":["retweet_count"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:Tweet') OR \\"retweet_count\\" IS NOT NULL"}],"version":"28598df2"},"importPath":"@happyvertical/smrt-messages"},"@happyvertical/smrt-messages:TwitterAccount":{"name":"twitteraccount","className":"TwitterAccount","qualifiedName":"@happyvertical/smrt-messages:TwitterAccount","collection":"accounts","filePath":"src/models/TwitterAccount.ts","packageName":"@happyvertical/smrt-messages","fields":{"created_at":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"updated_at":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"tenantId":{"type":"text","_meta":{"__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":false,"autoPopulate":true,"nullable":true},"__statedOptions":["sqlType","nullable","__tenancy","required"],"required":false,"sqlType":"UUID","nullable":true},"required":false},"name":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The display name for this connected messaging account."},"required":false,"description":"The display name for this connected messaging account."},"providerType":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The service that connects this account to your application."},"required":false,"description":"The service that connects this account to your application."},"channelType":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The kind of messaging this account supports, such as email or chat."},"required":false,"description":"The kind of messaging this account supports, such as email or chat."},"credentialSecretId":{"type":"text","_meta":{"__statedOptions":["sensitive","readonly"],"sensitive":true,"readonly":true},"required":false,"sensitive":true,"readonly":true},"isActive":{"type":"boolean","_meta":{"__statedOptions":["description","default"],"description":"Whether this account is enabled for messaging."},"required":true,"default":true,"description":"Whether this account is enabled for messaging."},"ownerUserId":{"type":"crossPackageRef","_meta":{"__statedOptions":["description","related"],"description":"The person who owns this account and decides who else may use it."},"required":false,"related":"@happyvertical/smrt-users:User","description":"The person who owns this account and decides who else may use it."},"label":{"type":"text","_meta":{"__statedOptions":["description"],"description":"A short name shown beside this account, such as Support or Personal."},"required":false,"description":"A short name shown beside this account, such as Support or Personal."},"connectionStatus":{"type":"text","_meta":{"__statedOptions":["description"],"description":"Whether the saved sign-in still works: connected, or needs_reconnect after the server refused it."},"required":false,"description":"Whether the saved sign-in still works: connected, or needs_reconnect after the server refused it."},"statusMessage":{"type":"text","_meta":{"__statedOptions":["description"],"description":"Why the account needs attention, in plain words."},"required":false,"description":"Why the account needs attention, in plain words."},"lastSyncAt":{"type":"datetime","_meta":{"__statedOptions":["description"],"description":"When this account last checked for new messages."},"required":false,"description":"When this account last checked for new messages."},"settings":{"type":"text","_meta":{"__statedOptions":["sensitive","readonly"],"sensitive":true,"readonly":true},"required":false,"sensitive":true,"readonly":true},"configuration":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The public connection settings for this account; credentials are stored separately."},"required":false,"description":"The public connection settings for this account; credentials are stored separately."},"createdAt":{"type":"text","_meta":{"__statedOptions":["description"],"description":"When this account was added."},"required":false,"description":"When this account was added."},"updatedAt":{"type":"text","_meta":{"__statedOptions":["description"],"description":"When this account was last changed."},"required":false,"description":"When this account was last changed."},"handle":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"twitterUserId":{"type":"text","_meta":{"__statedOptions":[]},"required":false}},"methods":{"getSettings":{"name":"getSettings","async":false,"parameters":[],"returnType":"Record<string, unknown>","isStatic":false,"isPublic":true},"setSettings":{"name":"setSettings","async":false,"parameters":[{"name":"settings","type":"Record<string, unknown>","optional":false}],"returnType":"void","isStatic":false,"isPublic":true},"getConfiguration":{"name":"getConfiguration","async":false,"parameters":[],"returnType":"Record<string, unknown>","isStatic":false,"isPublic":true},"setConfiguration":{"name":"setConfiguration","async":false,"parameters":[{"name":"configuration","type":"Record<string, unknown>","optional":false}],"returnType":"void","isStatic":false,"isPublic":true},"markNeedsReconnect":{"name":"markNeedsReconnect","async":true,"parameters":[{"name":"reason","type":"string","optional":false}],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"markConnected":{"name":"markConnected","async":true,"parameters":[],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"activate":{"name":"activate","async":true,"parameters":[],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"deactivate":{"name":"deactivate","async":true,"parameters":[],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"setCredentials":{"name":"setCredentials","async":true,"parameters":[{"name":"credentials","type":"Record<string, unknown>","optional":false},{"name":"options","type":"object","optional":true,"memberTypes":["string"]}],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"removeCredentials":{"name":"removeCredentials","async":true,"parameters":[],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"createSender":{"name":"createSender","async":true,"parameters":[],"returnType":"Promise<MessageSenderInterface>","isStatic":false,"isPublic":true},"getCredentials":{"name":"getCredentials","async":true,"parameters":[],"returnType":"Promise<Record<string, unknown> | null>","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableStrategy":"sti","api":{"include":["list","get"]},"mcp":{"include":["list","get"]},"cli":{"include":["list","get"]},"tableName":"accounts"},"extends":"Account","exportName":"TwitterAccount","collectionExportName":"TwitterAccountCollection","displayLabelField":"name","validationRules":[{"field":"isActive","rule":"required","fieldType":"boolean"}],"schema":{"tableName":"accounts","ddl":"CREATE TABLE IF NOT EXISTS \\"accounts\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"_meta_type\\" TEXT NOT NULL,\\n \\"_meta_data\\" JSON,\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"name\\" TEXT,\\n \\"provider_type\\" TEXT,\\n \\"channel_type\\" TEXT,\\n \\"credential_secret_id\\" TEXT,\\n \\"is_active\\" BOOLEAN DEFAULT TRUE,\\n \\"owner_user_id\\" UUID,\\n \\"label\\" TEXT,\\n \\"connection_status\\" TEXT,\\n \\"status_message\\" TEXT,\\n \\"last_sync_at\\" TIMESTAMP,\\n \\"settings\\" TEXT,\\n \\"configuration\\" TEXT,\\n \\"email\\" TEXT,\\n \\"sync_interval_minutes\\" INTEGER DEFAULT 60,\\n \\"sync_cursor\\" TEXT,\\n \\"backfill_since\\" TIMESTAMP,\\n \\"cursor_horizon\\" TIMESTAMP,\\n \\"last_sync_error\\" TEXT,\\n \\"backlog\\" BOOLEAN DEFAULT FALSE,\\n \\"workspace_id\\" TEXT,\\n \\"workspace_name\\" TEXT,\\n \\"bot_user_id\\" TEXT,\\n \\"handle\\" TEXT,\\n \\"twitter_user_id\\" TEXT\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"_meta_type":{"type":"TEXT","notNull":true},"_meta_data":{"type":"JSON","notNull":false},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false},"name":{"type":"TEXT","notNull":false},"provider_type":{"type":"TEXT","notNull":false},"channel_type":{"type":"TEXT","notNull":false},"credential_secret_id":{"type":"TEXT","notNull":false},"is_active":{"type":"BOOLEAN","notNull":false,"default":true},"owner_user_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false},"label":{"type":"TEXT","notNull":false},"connection_status":{"type":"TEXT","notNull":false},"status_message":{"type":"TEXT","notNull":false},"last_sync_at":{"type":"TIMESTAMP","notNull":false},"settings":{"type":"TEXT","notNull":false},"configuration":{"type":"TEXT","notNull":false},"email":{"type":"TEXT","notNull":false},"sync_interval_minutes":{"type":"INTEGER","notNull":false,"default":60},"sync_cursor":{"type":"TEXT","notNull":false},"backfill_since":{"type":"TIMESTAMP","notNull":false},"cursor_horizon":{"type":"TIMESTAMP","notNull":false},"last_sync_error":{"type":"TEXT","notNull":false},"backlog":{"type":"BOOLEAN","notNull":false,"default":false},"workspace_id":{"type":"TEXT","notNull":false},"workspace_name":{"type":"TEXT","notNull":false},"bot_user_id":{"type":"TEXT","notNull":false},"handle":{"type":"TEXT","notNull":false},"twitter_user_id":{"type":"TEXT","notNull":false}},"indexes":[{"name":"accounts_slug_context_meta_type_idx","columns":["tenant_id","slug","context","_meta_type"],"unique":true,"nullsNotDistinct":true},{"name":"accounts_meta_type_idx","columns":["_meta_type"]},{"name":"accounts_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"accounts_owner_user_id_idx","columns":["owner_user_id"]}],"checks":[{"name":"smrt_ck_81229bbfe8e3","columns":["backlog"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:EmailAccount') OR \\"backlog\\" IS NOT NULL"},{"name":"smrt_ck_1f9c5f0ee488","columns":["sync_interval_minutes"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:EmailAccount') OR \\"sync_interval_minutes\\" IS NOT NULL"}],"version":"f48d7a23"},"importPath":"@happyvertical/smrt-messages"},"@happyvertical/smrt-messages:UserNotification":{"name":"usernotification","className":"UserNotification","qualifiedName":"@happyvertical/smrt-messages:UserNotification","collection":"usernotifications","description":"One in-app notification for one person, with its own read state.","filePath":"src/models/UserNotification.ts","packageName":"@happyvertical/smrt-messages","fields":{"tenantId":{"type":"text","_meta":{"__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":true,"autoPopulate":true,"nullable":false,"mode":"required","field":"tenantId","allowSuperAdminBypass":false},"__statedOptions":["sqlType","requiredFor","__tenancy"],"sqlType":"UUID","requiredFor":"tenant-scope"},"required":true},"recipientUserId":{"type":"crossPackageRef","_meta":{"__statedOptions":["required","requiredFor","related"],"required":true,"requiredFor":"identity"},"required":true,"related":"@happyvertical/smrt-users:User"},"kind":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"title":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"body":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"href":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"severity":{"type":"text","_meta":{"__statedOptions":["default","enum"]},"required":false,"default":"info","enum":["info","success","warning","error"]},"sourceRef":{"type":"text","_meta":{"__statedOptions":["required","requiredFor"],"required":true,"requiredFor":"idempotency"},"required":true},"occurredAt":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"readAt":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"dismissedAt":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false}},"methods":{},"decoratorConfig":{"tableName":"user_notifications","api":false,"mcp":false,"cli":false,"conflictColumns":["tenant_id","recipient_user_id","source_ref"],"indexes":[{"name":"user_notifications_recipient_occurred_idx","columns":["tenantId","recipientUserId","occurredAt"]}],"tenantScoped":{"mode":"required"}},"extends":"SmrtObject","exportName":"UserNotification","collectionExportName":"UserNotificationCollection","displayLabelField":"title","validationRules":[{"field":"recipientUserId","rule":"required","fieldType":"crossPackageRef"},{"field":"sourceRef","rule":"required","fieldType":"text"}],"schema":{"tableName":"user_notifications","ddl":"CREATE TABLE IF NOT EXISTS \\"user_notifications\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"recipient_user_id\\" UUID NOT NULL,\\n \\"kind\\" TEXT,\\n \\"title\\" TEXT,\\n \\"body\\" TEXT,\\n \\"href\\" TEXT,\\n \\"severity\\" TEXT DEFAULT 'info',\\n \\"source_ref\\" TEXT NOT NULL,\\n \\"occurred_at\\" TEXT,\\n \\"read_at\\" TIMESTAMP,\\n \\"dismissed_at\\" TIMESTAMP\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"recipient_user_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":true,"unique":false},"kind":{"type":"TEXT","notNull":false,"unique":false},"title":{"type":"TEXT","notNull":false,"unique":false},"body":{"type":"TEXT","notNull":false,"unique":false},"href":{"type":"TEXT","notNull":false,"unique":false},"severity":{"type":"TEXT","notNull":false,"unique":false,"default":"info"},"source_ref":{"type":"TEXT","notNull":true,"unique":false},"occurred_at":{"type":"TEXT","notNull":false,"unique":false},"read_at":{"type":"TIMESTAMP","notNull":false,"unique":false},"dismissed_at":{"type":"TIMESTAMP","notNull":false,"unique":false}},"indexes":[{"name":"user_notifications_tenant_id_recipient_user_id_idx","columns":["tenant_id","recipient_user_id","source_ref"],"unique":true},{"name":"user_notifications_slug_context_idx","columns":["slug","context"]},{"name":"user_notifications_recipient_occurred_idx","columns":["tenant_id","recipient_user_id","occurred_at"]},{"name":"user_notifications_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"user_notifications_recipient_user_id_idx","columns":["recipient_user_id"]}],"version":"812ca772"},"importPath":"@happyvertical/smrt-messages"},"@happyvertical/smrt-messages:Whitelist":{"name":"whitelist","className":"Whitelist","qualifiedName":"@happyvertical/smrt-messages:Whitelist","collection":"whitelists","description":"Allow-only entries for email filtering","filePath":"src/models/Whitelist.ts","packageName":"@happyvertical/smrt-messages","fields":{"pattern":{"type":"text","_meta":{"__statedOptions":["default"]},"required":false,"default":""},"type":{"type":"text","_meta":{"__statedOptions":["default","enum"]},"required":false,"default":"email","enum":["email","domain","regex"]},"category":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"description":{"type":"text","_meta":{"__statedOptions":["default"]},"required":false,"default":""},"tenantId":{"type":"text","_meta":{"__tenancy":{"isTenantIdField":true,"mode":"required","field":"tenantId","autoFilter":true,"autoPopulate":true,"allowSuperAdminBypass":false},"generated":true,"source":"tenantScoped_decorator","sqlType":"UUID"},"required":true}},"methods":{"matches":{"name":"matches","async":false,"parameters":[{"name":"email","type":"string","optional":false}],"returnType":"boolean","isStatic":false,"isPublic":true}},"decoratorConfig":{"api":{"include":["list","get","create","update","delete"]},"cli":{"skipApiCheck":true},"tenantScoped":true,"conflictColumns":["tenant_id","slug","context"]},"extends":"SmrtObject","exportName":"Whitelist","collectionExportName":"WhitelistCollection","validationRules":[],"schema":{"tableName":"whitelists","ddl":"CREATE TABLE IF NOT EXISTS \\"whitelists\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"pattern\\" TEXT DEFAULT '',\\n \\"type\\" TEXT DEFAULT 'email',\\n \\"category\\" TEXT,\\n \\"description\\" TEXT DEFAULT '',\\n \\"tenant_id\\" UUID NOT NULL\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"pattern":{"type":"TEXT","notNull":false,"unique":false,"default":""},"type":{"type":"TEXT","notNull":false,"unique":false,"default":"email"},"category":{"type":"TEXT","notNull":false,"unique":false},"description":{"type":"TEXT","notNull":false,"unique":false,"default":""},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false}},"indexes":[{"name":"whitelists_slug_context_idx","columns":["tenant_id","slug","context"],"unique":true},{"name":"whitelists_tenant_id_created_at_idx","columns":["tenant_id","created_at"]}],"version":"eb5b558d"},"importPath":"@happyvertical/smrt-messages"},"@happyvertical/smrt-messages:ZulipAccount":{"name":"zulipaccount","className":"ZulipAccount","qualifiedName":"@happyvertical/smrt-messages:ZulipAccount","collection":"accounts","filePath":"src/models/ZulipAccount.ts","packageName":"@happyvertical/smrt-messages","fields":{"created_at":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"updated_at":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"tenantId":{"type":"text","_meta":{"__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":false,"autoPopulate":true,"nullable":true},"__statedOptions":["sqlType","nullable","__tenancy","required"],"required":false,"sqlType":"UUID","nullable":true},"required":false},"name":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The display name for this connected messaging account."},"required":false,"description":"The display name for this connected messaging account."},"providerType":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The service that connects this account to your application."},"required":false,"description":"The service that connects this account to your application."},"channelType":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The kind of messaging this account supports, such as email or chat."},"required":false,"description":"The kind of messaging this account supports, such as email or chat."},"credentialSecretId":{"type":"text","_meta":{"__statedOptions":["sensitive","readonly"],"sensitive":true,"readonly":true},"required":false,"sensitive":true,"readonly":true},"isActive":{"type":"boolean","_meta":{"__statedOptions":["description","default"],"description":"Whether this account is enabled for messaging."},"required":true,"default":true,"description":"Whether this account is enabled for messaging."},"ownerUserId":{"type":"crossPackageRef","_meta":{"__statedOptions":["description","related"],"description":"The person who owns this account and decides who else may use it."},"required":false,"related":"@happyvertical/smrt-users:User","description":"The person who owns this account and decides who else may use it."},"label":{"type":"text","_meta":{"__statedOptions":["description"],"description":"A short name shown beside this account, such as Support or Personal."},"required":false,"description":"A short name shown beside this account, such as Support or Personal."},"connectionStatus":{"type":"text","_meta":{"__statedOptions":["description"],"description":"Whether the saved sign-in still works: connected, or needs_reconnect after the server refused it."},"required":false,"description":"Whether the saved sign-in still works: connected, or needs_reconnect after the server refused it."},"statusMessage":{"type":"text","_meta":{"__statedOptions":["description"],"description":"Why the account needs attention, in plain words."},"required":false,"description":"Why the account needs attention, in plain words."},"lastSyncAt":{"type":"datetime","_meta":{"__statedOptions":["description"],"description":"When this account last checked for new messages."},"required":false,"description":"When this account last checked for new messages."},"settings":{"type":"text","_meta":{"__statedOptions":["sensitive","readonly"],"sensitive":true,"readonly":true},"required":false,"sensitive":true,"readonly":true},"configuration":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The public connection settings for this account; credentials are stored separately."},"required":false,"description":"The public connection settings for this account; credentials are stored separately."},"createdAt":{"type":"text","_meta":{"__statedOptions":["description"],"description":"When this account was added."},"required":false,"description":"When this account was added."},"updatedAt":{"type":"text","_meta":{"__statedOptions":["description"],"description":"When this account was last changed."},"required":false,"description":"When this account was last changed."}},"methods":{"getSettings":{"name":"getSettings","async":false,"parameters":[],"returnType":"Record<string, unknown>","isStatic":false,"isPublic":true},"setSettings":{"name":"setSettings","async":false,"parameters":[{"name":"settings","type":"Record<string, unknown>","optional":false}],"returnType":"void","isStatic":false,"isPublic":true},"getConfiguration":{"name":"getConfiguration","async":false,"parameters":[],"returnType":"Record<string, unknown>","isStatic":false,"isPublic":true},"setConfiguration":{"name":"setConfiguration","async":false,"parameters":[{"name":"configuration","type":"Record<string, unknown>","optional":false}],"returnType":"void","isStatic":false,"isPublic":true},"markNeedsReconnect":{"name":"markNeedsReconnect","async":true,"parameters":[{"name":"reason","type":"string","optional":false}],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"markConnected":{"name":"markConnected","async":true,"parameters":[],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"activate":{"name":"activate","async":true,"parameters":[],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"deactivate":{"name":"deactivate","async":true,"parameters":[],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"setCredentials":{"name":"setCredentials","async":true,"parameters":[{"name":"credentials","type":"Record<string, unknown>","optional":false},{"name":"options","type":"object","optional":true,"memberTypes":["string"]}],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"removeCredentials":{"name":"removeCredentials","async":true,"parameters":[],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"createSender":{"name":"createSender","async":true,"parameters":[],"returnType":"Promise<MessageSenderInterface>","isStatic":false,"isPublic":true},"getCredentials":{"name":"getCredentials","async":true,"parameters":[],"returnType":"Promise<Record<string, unknown> | null>","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableStrategy":"sti","api":{"include":["list","get"]},"mcp":{"include":["list","get"]},"cli":{"include":["list","get"]},"tableName":"accounts"},"extends":"Account","exportName":"ZulipAccount","collectionExportName":"ZulipAccountCollection","displayLabelField":"name","validationRules":[{"field":"isActive","rule":"required","fieldType":"boolean"}],"schema":{"tableName":"accounts","ddl":"CREATE TABLE IF NOT EXISTS \\"accounts\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"_meta_type\\" TEXT NOT NULL,\\n \\"_meta_data\\" JSON,\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"name\\" TEXT,\\n \\"provider_type\\" TEXT,\\n \\"channel_type\\" TEXT,\\n \\"credential_secret_id\\" TEXT,\\n \\"is_active\\" BOOLEAN DEFAULT TRUE,\\n \\"owner_user_id\\" UUID,\\n \\"label\\" TEXT,\\n \\"connection_status\\" TEXT,\\n \\"status_message\\" TEXT,\\n \\"last_sync_at\\" TIMESTAMP,\\n \\"settings\\" TEXT,\\n \\"configuration\\" TEXT,\\n \\"email\\" TEXT,\\n \\"sync_interval_minutes\\" INTEGER DEFAULT 60,\\n \\"sync_cursor\\" TEXT,\\n \\"backfill_since\\" TIMESTAMP,\\n \\"cursor_horizon\\" TIMESTAMP,\\n \\"last_sync_error\\" TEXT,\\n \\"backlog\\" BOOLEAN DEFAULT FALSE,\\n \\"workspace_id\\" TEXT,\\n \\"workspace_name\\" TEXT,\\n \\"bot_user_id\\" TEXT,\\n \\"handle\\" TEXT,\\n \\"twitter_user_id\\" TEXT\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"_meta_type":{"type":"TEXT","notNull":true},"_meta_data":{"type":"JSON","notNull":false},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false},"name":{"type":"TEXT","notNull":false},"provider_type":{"type":"TEXT","notNull":false},"channel_type":{"type":"TEXT","notNull":false},"credential_secret_id":{"type":"TEXT","notNull":false},"is_active":{"type":"BOOLEAN","notNull":false,"default":true},"owner_user_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false},"label":{"type":"TEXT","notNull":false},"connection_status":{"type":"TEXT","notNull":false},"status_message":{"type":"TEXT","notNull":false},"last_sync_at":{"type":"TIMESTAMP","notNull":false},"settings":{"type":"TEXT","notNull":false},"configuration":{"type":"TEXT","notNull":false},"email":{"type":"TEXT","notNull":false},"sync_interval_minutes":{"type":"INTEGER","notNull":false,"default":60},"sync_cursor":{"type":"TEXT","notNull":false},"backfill_since":{"type":"TIMESTAMP","notNull":false},"cursor_horizon":{"type":"TIMESTAMP","notNull":false},"last_sync_error":{"type":"TEXT","notNull":false},"backlog":{"type":"BOOLEAN","notNull":false,"default":false},"workspace_id":{"type":"TEXT","notNull":false},"workspace_name":{"type":"TEXT","notNull":false},"bot_user_id":{"type":"TEXT","notNull":false},"handle":{"type":"TEXT","notNull":false},"twitter_user_id":{"type":"TEXT","notNull":false}},"indexes":[{"name":"accounts_slug_context_meta_type_idx","columns":["tenant_id","slug","context","_meta_type"],"unique":true,"nullsNotDistinct":true},{"name":"accounts_meta_type_idx","columns":["_meta_type"]},{"name":"accounts_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"accounts_owner_user_id_idx","columns":["owner_user_id"]}],"checks":[{"name":"smrt_ck_81229bbfe8e3","columns":["backlog"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:EmailAccount') OR \\"backlog\\" IS NOT NULL"},{"name":"smrt_ck_1f9c5f0ee488","columns":["sync_interval_minutes"],"expression":"_meta_type NOT IN ('@happyvertical/smrt-messages:EmailAccount') OR \\"sync_interval_minutes\\" IS NOT NULL"}],"version":"f48d7a23"},"importPath":"@happyvertical/smrt-messages"}},"moduleType":"smrt","recipes":[{"id":"messages.mailbox","className":"MailboxRecipe","label":"Mailbox","summary":"Read and compose email from your connected accounts.","synonyms":["email","inbox","mail"],"models":["@happyvertical/smrt-messages:Email","@happyvertical/smrt-messages:EmailAccount"],"nav":[{"label":"Mailbox","model":"@happyvertical/smrt-messages:Email","icon":"folder","description":"Read email from your connected accounts.","key":"mailbox","noun":"email"},{"label":"Failed sends","model":"@happyvertical/smrt-messages:Email","icon":"fileText","description":"Review email whose last send attempt failed.","key":"failed-sends","noun":"email","filter":{"field":"sendStatus","value":"failed"}}],"requires":[],"group":{"id":"messages","label":"Messaging","summary":"Choose email and personal updates independently."},"section":{"id":"messages","label":"Messaging","icon":"folder","description":"Read email and keep up with updates addressed to you."},"options":{"@happyvertical/smrt-messages:Email":{"fields":{"created_at":{"help":"When this email was first recorded."},"updated_at":{"help":"When this email record was last changed."}}},"@happyvertical/smrt-messages:EmailAccount":{"fields":{"created_at":{"help":"When this mailbox connection was first recorded."},"updated_at":{"help":"When this mailbox connection was last changed."}}}},"help":{"markdown":"## Your mailbox\\nRead messages, open a conversation, or compose an email using a connected account.\\nChoose the sender account, add recipients, and check the subject and message before sending.\\n\\n## Failed sends\\nUse Failed sends to review email whose last send attempt failed. Returning to the mailbox shows all email again.\\nCheck the failure and sender connection before retrying through your application. This view does not resend email automatically.\\n\\n## Preview\\nThe playground uses fictional messages. Sending and saving are mocked and never contact a mail server.\\n\\n## Connect an account\\nYour application administrator connects an authorized email provider on the server. Real sending and mailbox synchronization require that connection; a preview does not verify delivery.\\n","fieldRefs":[]},"surfaces":[{"kind":"route","path":"/messages/mailbox","export":"@happyvertical/smrt-messages/svelte#MessageList","label":"Mailbox"},{"kind":"playground","export":"@happyvertical/smrt-messages/svelte#MailboxDemo","label":"Mailbox with mocked sending"}],"providers":[{"id":"email-inbox","kind":"email","options":["imap","pop3","gmail","jmap"],"required":true},{"id":"email-send","kind":"email","options":["smtp","gmail"],"required":false}],"runtime":"both","demoSeed":{"data":{"accounts":[{"id":"demo-account","name":"Demo Inbox","providerType":"email","email":"you@example.com","isActive":true}],"messages":[{"id":"demo-welcome","type":"email","accountId":"demo-account","subject":"Welcome to your mailbox","body":"Fictional mail. Sending is mocked; nothing leaves this browser.","senderName":"Demo colleague","senderAddress":"colleague@example.com","recipientAddresses":[{"address":"you@example.com"}],"date":"2026-01-01T12:00:00Z","isRead":false,"isFlagged":false,"hasAttachments":false}]}},"demo":{"mode":"server","reasons":["Needs a server because its package depends on @happyvertical/smrt-jobs, @happyvertical/smrt-profiles, @happyvertical/smrt-secrets, @happyvertical/smrt-tenancy, @happyvertical/smrt-users, which do not build for a browser (#3615, #3617, #3624, #3626, #3627)."]}},{"id":"messages.notifications","className":"NotificationsRecipe","label":"Notifications","summary":"See updates addressed to you and mark them read.","synonyms":["alerts","notification bell"],"models":["@happyvertical/smrt-messages:UserNotification"],"nav":[],"requires":[],"group":{"id":"messages","label":"Messaging","summary":"Choose email and personal updates independently."},"section":{"id":"messages","label":"Messaging","icon":"folder","description":"Read email and keep up with updates addressed to you."},"help":{"markdown":"## Notifications\\nOpen the notification bell to see updates addressed to you. Unread updates have a visible marker.\\nChoose Mark read for one update or Mark all read for every unread update in your authorized accounts.\\nFollow a notification link to open its related record when one is available.\\n\\n## Availability\\nNotifications are scoped to the signed-in person. Your application connects the notification provider and may enable live updates. If loading fails, try again after the connection returns.\\n","fieldRefs":[]},"surfaces":[{"kind":"shell-widget","slot":"header.end","export":"@happyvertical/smrt-svelte/notifications#NotificationBell","label":"Notifications"}],"providers":[{"id":"notifications","kind":"notifications","options":["user-notification-service"],"required":true}],"runtime":"both","demoSeed":{"data":{"items":[{"id":"demo-notification","title":"You were mentioned","body":"A fictional update for the demo user.","occurredAt":"2026-01-01T12:00:00Z","severity":"info","readAt":null}]}},"demo":{"mode":"server","reasons":["Needs a server because its package depends on @happyvertical/smrt-jobs, @happyvertical/smrt-profiles, @happyvertical/smrt-secrets, @happyvertical/smrt-tenancy, @happyvertical/smrt-users, which do not build for a browser (#3615, #3617, #3624, #3626, #3627)."]}},{"id":"messages.slack","className":"SlackRecipe","label":"Slack","summary":"Read Slack messages from your connected workspaces.","synonyms":["slack","slack messages","slack channels","workspace chat","team chat"],"models":["@happyvertical/smrt-messages:SlackMessage","@happyvertical/smrt-messages:SlackAccount"],"nav":[{"label":"Slack messages","model":"@happyvertical/smrt-messages:SlackMessage","icon":"folder","description":"Read messages from your connected workspaces by channel.","key":"slack-messages","noun":"message"},{"label":"Slack workspaces","model":"@happyvertical/smrt-messages:SlackAccount","icon":"users","description":"The workspaces your application is connected to.","noun":"workspace"}],"requires":[],"group":{"id":"messages","label":"Messaging","summary":"Choose email and personal updates independently."},"section":{"id":"messages","label":"Messaging","icon":"folder","description":"Read email and keep up with updates addressed to you."},"options":{"@happyvertical/smrt-messages:SlackMessage":{"fields":{"channelName":{"label":"Channel","order":1},"body":{"label":"Message","order":2},"threadId":{"label":"Thread","order":3},"sendStatus":{"label":"Sent status","order":4},"accountId":{"label":"Workspace","order":5},"fromName":{"label":"From","visibility":"advanced"},"fromAddress":{"visibility":"advanced"},"toAddresses":{"visibility":"advanced"},"subject":{"visibility":"advanced"},"date":{"visibility":"advanced"},"isRead":{"visibility":"advanced"},"isFlagged":{"visibility":"advanced"},"isEdited":{"label":"Edited","visibility":"advanced"},"messageType":{"label":"Message kind","visibility":"advanced"},"reactions":{"visibility":"advanced"},"hasAttachments":{"visibility":"advanced"},"channelId":{"visibility":"advanced"},"sentAt":{"visibility":"advanced"},"sendError":{"visibility":"advanced"},"scheduledSendAt":{"visibility":"advanced"},"inReplyToMessageId":{"label":"Replying to","visibility":"advanced"},"personaId":{"visibility":"advanced"},"endpointId":{"visibility":"advanced"},"retryCount":{"visibility":"hidden"},"maxRetries":{"visibility":"hidden"},"size":{"visibility":"hidden"},"correlationId":{"visibility":"hidden"},"slackTs":{"visibility":"hidden"},"slackThreadTs":{"visibility":"hidden"},"blocks":{"visibility":"hidden"},"metadata":{"visibility":"hidden"},"tenantId":{"visibility":"hidden"},"created_at":{"help":"When this message was first recorded."},"updated_at":{"help":"When this message record was last changed."}}},"@happyvertical/smrt-messages:SlackAccount":{"fields":{"name":{"order":1},"workspaceName":{"label":"Workspace","order":2},"isActive":{"label":"Enabled","order":3},"lastSyncAt":{"label":"Last checked","order":4},"workspaceId":{"visibility":"advanced"},"credentialSecretId":{"visibility":"hidden"},"settings":{"visibility":"hidden"},"botUserId":{"label":"Bot user","visibility":"advanced"},"providerType":{"visibility":"advanced"},"channelType":{"visibility":"advanced"},"configuration":{"visibility":"advanced"},"tenantId":{"visibility":"hidden"},"created_at":{"help":"When this workspace connection was first recorded."},"updated_at":{"help":"When this workspace connection was last changed."}}}},"help":{"markdown":"## Overview\\n\\nSlack shows the messages from the workspaces your application is connected to,\\nin one place beside your email. Each message keeps the channel it was posted\\nin, the thread it belongs to, the reactions people added and whether it was\\nedited, so you can catch up on a conversation without opening Slack.\\n\\n## Tasks\\n\\nWorkspaces are connected by your application administrator on the server.\\nMessages arrive from those connected workspaces; here you read them and see\\nwhere each one stands.\\n\\n### Find a message in a channel\\n\\n1. Open Slack messages.\\n2. Look at the **{field:SlackMessage.channelName}** to find the channel you want.\\n3. Open a message to read the **{field:SlackMessage.body}** and see who it is from.\\n\\n### Follow a thread\\n\\n1. Open a message that is part of a conversation.\\n2. Use its **{field:SlackMessage.threadId}** to find the other messages in the same thread.\\n3. Read them oldest first; the **{field:SlackMessage.reactions}** show how people responded.\\n\\n### See whether a message was changed\\n\\n1. Open the message.\\n2. Check **{field:SlackMessage.isEdited}** to see whether it was edited after it was posted.\\n\\n### Draft a message\\n\\n1. Open Slack messages and choose **New**.\\n2. Type the **{field:SlackMessage.channelName}** it is for and the **{field:SlackMessage.body}**.\\n3. Save. This records the draft; your application sends it through the connected workspace, and the **{field:SlackMessage.sendStatus}** shows where it stands.\\n\\n### See which workspaces are connected\\n\\n1. Open Slack workspaces.\\n2. Look at the **{field:SlackAccount.workspaceName}** and whether it is **{field:SlackAccount.isActive}**.\\n3. Check **{field:SlackAccount.lastSyncAt}** to see when messages were last collected. Connecting or changing a workspace is done by your application administrator, not here.\\n","fieldRefs":["SlackAccount.isActive","SlackAccount.lastSyncAt","SlackAccount.workspaceName","SlackMessage.body","SlackMessage.channelName","SlackMessage.isEdited","SlackMessage.reactions","SlackMessage.sendStatus","SlackMessage.threadId"]},"demo":{"mode":"server","reasons":["Needs a server because its package depends on @happyvertical/smrt-jobs, @happyvertical/smrt-profiles, @happyvertical/smrt-secrets, @happyvertical/smrt-tenancy, @happyvertical/smrt-users, which do not build for a browser (#3615, #3617, #3624, #3626, #3627)."]}}],"smrtDependencies":["@happyvertical/smrt-core","@happyvertical/smrt-jobs","@happyvertical/smrt-ledgers","@happyvertical/smrt-profiles","@happyvertical/smrt-secrets","@happyvertical/smrt-tenancy","@happyvertical/smrt-users"],"browser":{"status":"server-only","issues":["#3615","#3617","#3624","#3626","#3627"],"via":["@happyvertical/smrt-jobs","@happyvertical/smrt-profiles","@happyvertical/smrt-secrets","@happyvertical/smrt-tenancy","@happyvertical/smrt-users"]},"stampsConstructors":true}`));
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/permissions.ts
|
|
10
|
+
var SEND_MESSAGES_PERMISSION = "messages.send";
|
|
11
|
+
var MANAGE_MESSAGE_ROUTES_PERMISSION = "messages.manage-routes";
|
|
12
|
+
var MANAGE_MESSAGE_CREDENTIALS_PERMISSION = "messages.manage-credentials";
|
|
13
|
+
var READ_MAIL_PERMISSION = "messages.read";
|
|
14
|
+
var TRIAGE_MAIL_PERMISSION = "messages.triage";
|
|
15
|
+
var DRAFT_MAIL_PERMISSION = "messages.draft";
|
|
16
|
+
var MANAGE_MAIL_ACCESS_PERMISSION = "messages.manage-access";
|
|
17
|
+
var MESSAGING_PERMISSION_DEFINITIONS = [
|
|
18
|
+
{
|
|
19
|
+
slug: SEND_MESSAGES_PERMISSION,
|
|
20
|
+
category: "messages",
|
|
21
|
+
name: "Send Messages",
|
|
22
|
+
description: "Allows send on messages"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
slug: MANAGE_MESSAGE_ROUTES_PERMISSION,
|
|
26
|
+
category: "messages",
|
|
27
|
+
name: "Manage Message Routes",
|
|
28
|
+
description: "Manage persona messaging endpoints and route bindings"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
slug: MANAGE_MESSAGE_CREDENTIALS_PERMISSION,
|
|
32
|
+
category: "messages",
|
|
33
|
+
name: "Manage Message Credentials",
|
|
34
|
+
description: "Create accounts and replace write-only provider credentials"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
slug: TRIAGE_MAIL_PERMISSION,
|
|
38
|
+
category: "messages",
|
|
39
|
+
name: "Triage Messages",
|
|
40
|
+
description: "Allows triage on messages"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
slug: DRAFT_MAIL_PERMISSION,
|
|
44
|
+
category: "messages",
|
|
45
|
+
name: "Draft Mail",
|
|
46
|
+
description: "Write mail drafts; a mail account grant narrows this per account"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
slug: MANAGE_MAIL_ACCESS_PERMISSION,
|
|
50
|
+
category: "messages",
|
|
51
|
+
name: "Manage Mail Access",
|
|
52
|
+
description: "Grant or revoke per-account mail access; only an account owner or a delegating grantee may use it on that account"
|
|
53
|
+
}
|
|
54
|
+
];
|
|
55
|
+
var MESSAGES_ROLE_PERMISSION_MATRIX = Object.freeze({
|
|
56
|
+
owner: Object.freeze([
|
|
57
|
+
READ_MAIL_PERMISSION,
|
|
58
|
+
TRIAGE_MAIL_PERMISSION,
|
|
59
|
+
DRAFT_MAIL_PERMISSION,
|
|
60
|
+
SEND_MESSAGES_PERMISSION,
|
|
61
|
+
MANAGE_MESSAGE_CREDENTIALS_PERMISSION,
|
|
62
|
+
MANAGE_MAIL_ACCESS_PERMISSION
|
|
63
|
+
]),
|
|
64
|
+
admin: Object.freeze([
|
|
65
|
+
READ_MAIL_PERMISSION,
|
|
66
|
+
TRIAGE_MAIL_PERMISSION,
|
|
67
|
+
DRAFT_MAIL_PERMISSION,
|
|
68
|
+
SEND_MESSAGES_PERMISSION,
|
|
69
|
+
MANAGE_MESSAGE_CREDENTIALS_PERMISSION,
|
|
70
|
+
MANAGE_MAIL_ACCESS_PERMISSION
|
|
71
|
+
]),
|
|
72
|
+
member: Object.freeze([
|
|
73
|
+
READ_MAIL_PERMISSION,
|
|
74
|
+
TRIAGE_MAIL_PERMISSION,
|
|
75
|
+
DRAFT_MAIL_PERMISSION,
|
|
76
|
+
SEND_MESSAGES_PERMISSION
|
|
77
|
+
]),
|
|
78
|
+
viewer: Object.freeze([READ_MAIL_PERMISSION])
|
|
79
|
+
});
|
|
80
|
+
async function seedMessagesRolePermissions(options) {
|
|
81
|
+
ensureMessagingPermissionsRegistered();
|
|
82
|
+
const { RolePermissionCollection } = await import("@happyvertical/smrt-users");
|
|
83
|
+
const result = await (await RolePermissionCollection.create(options)).seedRolePermissions(MESSAGES_ROLE_PERMISSION_MATRIX, {
|
|
84
|
+
prune: false,
|
|
85
|
+
systemRolesOnly: true
|
|
86
|
+
});
|
|
87
|
+
const missing = Object.entries(result.missingPermissions).filter(([, slugs]) => slugs.length > 0);
|
|
88
|
+
if (missing.length > 0) throw new Error(`Messaging permissions missing from the catalog after sync: ${missing.map(([role, slugs]) => `${role}: ${slugs.join(", ")}`).join("; ")}`);
|
|
89
|
+
return {
|
|
90
|
+
added: Object.fromEntries(Object.entries(result.added).filter(([, slugs]) => slugs.length > 0)),
|
|
91
|
+
missingRoles: result.missingRoles
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function messagingPrincipalFromPermissions(permissions, options = {}) {
|
|
95
|
+
const granted = new Set(permissions);
|
|
96
|
+
return {
|
|
97
|
+
...options,
|
|
98
|
+
can: (slug) => granted.has(slug)
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
function assertMessagingPermission(principal, tenantId, permission) {
|
|
102
|
+
if (principal.tenantId && principal.tenantId !== tenantId) throw new Error("Messaging principal does not belong to this tenant.");
|
|
103
|
+
if (!principal.can(permission)) throw new Error(`Missing required permission '${permission}'.`);
|
|
104
|
+
}
|
|
105
|
+
var registered = false;
|
|
106
|
+
function ensureMessagingPermissionsRegistered() {
|
|
107
|
+
if (registered) return;
|
|
108
|
+
registered = true;
|
|
109
|
+
registerPermissionDefinitions(MESSAGING_PERMISSION_DEFINITIONS);
|
|
110
|
+
}
|
|
111
|
+
//#endregion
|
|
112
|
+
//#region src/access.ts
|
|
113
|
+
var MAIL_SCOPES = [
|
|
114
|
+
"read",
|
|
115
|
+
"triage",
|
|
116
|
+
"draft",
|
|
117
|
+
"send"
|
|
118
|
+
];
|
|
119
|
+
var MAIL_ACCOUNT_RESOURCE_TYPE = "messages:account";
|
|
120
|
+
var SCOPE_PERMISSIONS = {
|
|
121
|
+
read: READ_MAIL_PERMISSION,
|
|
122
|
+
triage: TRIAGE_MAIL_PERMISSION,
|
|
123
|
+
draft: DRAFT_MAIL_PERMISSION,
|
|
124
|
+
send: "messages.send"
|
|
125
|
+
};
|
|
126
|
+
function mailScopePermission(scope) {
|
|
127
|
+
return SCOPE_PERMISSIONS[scope];
|
|
128
|
+
}
|
|
129
|
+
function isMailScope(value) {
|
|
130
|
+
return MAIL_SCOPES.includes(value);
|
|
131
|
+
}
|
|
132
|
+
var STATE_KEY = /* @__PURE__ */ Symbol.for("@happyvertical/smrt-messages:mail-access");
|
|
133
|
+
function state() {
|
|
134
|
+
const holder = globalThis;
|
|
135
|
+
let current = holder[STATE_KEY];
|
|
136
|
+
if (!current) {
|
|
137
|
+
current = {
|
|
138
|
+
config: null,
|
|
139
|
+
learned: /* @__PURE__ */ new Map(),
|
|
140
|
+
system: createHandoffContext()
|
|
141
|
+
};
|
|
142
|
+
holder[STATE_KEY] = current;
|
|
143
|
+
}
|
|
144
|
+
return current;
|
|
145
|
+
}
|
|
146
|
+
function configureMailAccess(config) {
|
|
147
|
+
state().config = {
|
|
148
|
+
...config,
|
|
149
|
+
options: withoutListBounds(config.options)
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
function resetMailAccess() {
|
|
153
|
+
state().config = null;
|
|
154
|
+
state().learned.clear();
|
|
155
|
+
}
|
|
156
|
+
function withoutListBounds(options) {
|
|
157
|
+
return {
|
|
158
|
+
...options,
|
|
159
|
+
defaultListLimit: void 0,
|
|
160
|
+
maxListLimit: void 0
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
function learnMailAccessOptions(options) {
|
|
164
|
+
const current = state();
|
|
165
|
+
if (current.config || !options) return;
|
|
166
|
+
const key = options.db ?? options;
|
|
167
|
+
current.learned.delete(key);
|
|
168
|
+
current.learned.set(key, withoutListBounds(options));
|
|
169
|
+
if (current.learned.size > 16) {
|
|
170
|
+
const oldest = current.learned.keys().next().value;
|
|
171
|
+
current.learned.delete(oldest);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
function getEffectiveMailAccessConfigs() {
|
|
175
|
+
const current = state();
|
|
176
|
+
if (current.config) return [current.config];
|
|
177
|
+
return [...current.learned.values()].map((options) => ({ options }));
|
|
178
|
+
}
|
|
179
|
+
function getEffectiveMailAccessConfig() {
|
|
180
|
+
const current = state();
|
|
181
|
+
if (current.config) return current.config;
|
|
182
|
+
const latest = [...current.learned.values()].pop();
|
|
183
|
+
return latest ? { options: latest } : null;
|
|
184
|
+
}
|
|
185
|
+
function getMailAccessConfig() {
|
|
186
|
+
return state().config;
|
|
187
|
+
}
|
|
188
|
+
function runWithMailSystemAccess(fn) {
|
|
189
|
+
return state().system.run(true, fn);
|
|
190
|
+
}
|
|
191
|
+
function inMailSystemAccess() {
|
|
192
|
+
return state().system.getStore() === true;
|
|
193
|
+
}
|
|
194
|
+
var MailAccessError = class extends Error {
|
|
195
|
+
constructor(scope, reason) {
|
|
196
|
+
super(`Mail access denied for scope '${scope}'.`);
|
|
197
|
+
this.scope = scope;
|
|
198
|
+
this.reason = reason;
|
|
199
|
+
this.name = "MailAccessError";
|
|
200
|
+
}
|
|
201
|
+
scope;
|
|
202
|
+
reason;
|
|
203
|
+
status = 403;
|
|
204
|
+
};
|
|
205
|
+
async function resolvePrincipal(config) {
|
|
206
|
+
if (!config.resolvePrincipal) return null;
|
|
207
|
+
const principal = await config.resolvePrincipal({ tenantId: getCurrentTenant()?.tenantId ?? null });
|
|
208
|
+
if (!principal || typeof principal.id !== "string" || !principal.id || typeof principal.userId !== "string" || !principal.userId || typeof principal.tenantId !== "string" || !principal.tenantId) return null;
|
|
209
|
+
return principal;
|
|
210
|
+
}
|
|
211
|
+
async function hasGrant(config, principal, account, scope) {
|
|
212
|
+
const { checkResourceOperationPermission } = await import("@happyvertical/smrt-users");
|
|
213
|
+
const accountId = account.id ?? "";
|
|
214
|
+
const tenantId = account.tenantId ?? "";
|
|
215
|
+
if (!accountId || !tenantId) return false;
|
|
216
|
+
return (await checkResourceOperationPermission({
|
|
217
|
+
...config.options,
|
|
218
|
+
collection: "messages",
|
|
219
|
+
action: scope,
|
|
220
|
+
tenantId,
|
|
221
|
+
userId: principal.userId,
|
|
222
|
+
allowSuperAdminBypass: false,
|
|
223
|
+
allowSystemContextBypass: false,
|
|
224
|
+
resource: {
|
|
225
|
+
tenantId,
|
|
226
|
+
resourceType: MAIL_ACCOUNT_RESOURCE_TYPE,
|
|
227
|
+
resourceId: accountId
|
|
228
|
+
},
|
|
229
|
+
verifyResource: (resource) => resource.tenantId === tenantId && resource.resourceType === "messages:account" && resource.resourceId === accountId
|
|
230
|
+
})).allowed;
|
|
231
|
+
}
|
|
232
|
+
async function decideMailAccess(account, scope, principalOverride) {
|
|
233
|
+
if (inMailSystemAccess()) return {
|
|
234
|
+
allowed: true,
|
|
235
|
+
reason: "system"
|
|
236
|
+
};
|
|
237
|
+
const config = getEffectiveMailAccessConfig();
|
|
238
|
+
const owned = Boolean(account.ownerUserId);
|
|
239
|
+
if (!config) return owned ? {
|
|
240
|
+
allowed: false,
|
|
241
|
+
reason: "not_configured"
|
|
242
|
+
} : {
|
|
243
|
+
allowed: true,
|
|
244
|
+
reason: "unowned"
|
|
245
|
+
};
|
|
246
|
+
const principal = principalOverride !== void 0 ? principalOverride : await resolvePrincipal(config);
|
|
247
|
+
if (!principal) return owned ? {
|
|
248
|
+
allowed: false,
|
|
249
|
+
reason: "no_principal"
|
|
250
|
+
} : {
|
|
251
|
+
allowed: true,
|
|
252
|
+
reason: "unowned"
|
|
253
|
+
};
|
|
254
|
+
if (account.tenantId && principal.tenantId !== account.tenantId) return {
|
|
255
|
+
allowed: false,
|
|
256
|
+
reason: "tenant_mismatch"
|
|
257
|
+
};
|
|
258
|
+
const currentTenant = getCurrentTenant()?.tenantId;
|
|
259
|
+
if (currentTenant && currentTenant !== principal.tenantId) return {
|
|
260
|
+
allowed: false,
|
|
261
|
+
reason: "tenant_mismatch"
|
|
262
|
+
};
|
|
263
|
+
if (principal.scopes && !principal.scopes.includes(scope)) return {
|
|
264
|
+
allowed: false,
|
|
265
|
+
reason: "ceiling"
|
|
266
|
+
};
|
|
267
|
+
if (principal.accountIds && (!account.id || !principal.accountIds.includes(account.id))) return {
|
|
268
|
+
allowed: false,
|
|
269
|
+
reason: "ceiling"
|
|
270
|
+
};
|
|
271
|
+
if (!owned) return {
|
|
272
|
+
allowed: true,
|
|
273
|
+
reason: "unowned"
|
|
274
|
+
};
|
|
275
|
+
if (account.ownerUserId === principal.userId) return {
|
|
276
|
+
allowed: true,
|
|
277
|
+
reason: "owner"
|
|
278
|
+
};
|
|
279
|
+
try {
|
|
280
|
+
return await hasGrant(config, principal, account, scope) ? {
|
|
281
|
+
allowed: true,
|
|
282
|
+
reason: "grant"
|
|
283
|
+
} : {
|
|
284
|
+
allowed: false,
|
|
285
|
+
reason: "denied"
|
|
286
|
+
};
|
|
287
|
+
} catch {
|
|
288
|
+
return {
|
|
289
|
+
allowed: false,
|
|
290
|
+
reason: "denied"
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
async function canAccessMailAccount(account, scope) {
|
|
295
|
+
return (await decideMailAccess(account, scope)).allowed;
|
|
296
|
+
}
|
|
297
|
+
async function assertMailAccess(account, scope) {
|
|
298
|
+
const decision = await decideMailAccess(account, scope);
|
|
299
|
+
if (!decision.allowed) throw new MailAccessError(scope, decision.reason);
|
|
300
|
+
}
|
|
301
|
+
async function deniedMailAccountIds(scope) {
|
|
302
|
+
if (inMailSystemAccess()) return [];
|
|
303
|
+
const { AccountCollection } = await Promise.resolve().then(() => AccountCollection_exports);
|
|
304
|
+
const denied = /* @__PURE__ */ new Set();
|
|
305
|
+
for (const config of getEffectiveMailAccessConfigs()) {
|
|
306
|
+
let accounts;
|
|
307
|
+
try {
|
|
308
|
+
accounts = await runWithMailSystemAccess(async () => (await AccountCollection.create(config.options)).list({}));
|
|
309
|
+
} catch (error) {
|
|
310
|
+
if (!state().config && /CLIENT_CLOSED/.test(String(error))) {
|
|
311
|
+
state().learned.delete(config.options.db ?? config.options);
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
throw error;
|
|
315
|
+
}
|
|
316
|
+
const principal = await resolvePrincipal(config);
|
|
317
|
+
for (const account of accounts) {
|
|
318
|
+
if (!account.id) continue;
|
|
319
|
+
if (!(await decideMailAccess({
|
|
320
|
+
id: account.id,
|
|
321
|
+
tenantId: account.tenantId,
|
|
322
|
+
ownerUserId: account.ownerUserId
|
|
323
|
+
}, scope, principal)).allowed) denied.add(account.id);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
return [...denied];
|
|
327
|
+
}
|
|
328
|
+
async function accountReadable(accountId, options) {
|
|
329
|
+
if (inMailSystemAccess()) return true;
|
|
330
|
+
learnMailAccessOptions(options);
|
|
331
|
+
if (!accountId) return true;
|
|
332
|
+
const config = getEffectiveMailAccessConfig();
|
|
333
|
+
if (!config) return true;
|
|
334
|
+
const { AccountCollection } = await Promise.resolve().then(() => AccountCollection_exports);
|
|
335
|
+
const account = await runWithMailSystemAccess(async () => (await AccountCollection.create(config.options)).get({ id: accountId }));
|
|
336
|
+
if (!account) return false;
|
|
337
|
+
return (await decideMailAccess({
|
|
338
|
+
id: account.id,
|
|
339
|
+
tenantId: account.tenantId,
|
|
340
|
+
ownerUserId: account.ownerUserId
|
|
341
|
+
}, "read")).allowed;
|
|
342
|
+
}
|
|
343
|
+
async function assertHydratedMailAccess(row) {
|
|
344
|
+
if (inMailSystemAccess()) return;
|
|
345
|
+
const options = row.options;
|
|
346
|
+
let accountId = row.accountId || null;
|
|
347
|
+
if (!accountId && row.messageId && options) {
|
|
348
|
+
const { MessageCollection } = await import("./MessageCollection-BnHCLi1Q.js").then((n) => n.n);
|
|
349
|
+
const message = await runWithMailSystemAccess(async () => (await MessageCollection.create(options)).get({ id: row.messageId }));
|
|
350
|
+
if (!message) throw new MailAccessError("read", "denied");
|
|
351
|
+
accountId = message.accountId || null;
|
|
352
|
+
}
|
|
353
|
+
if (!await accountReadable(accountId, options)) throw new MailAccessError("read", "denied");
|
|
354
|
+
}
|
|
355
|
+
var MailAccessService = class {
|
|
356
|
+
constructor(options, actor) {
|
|
357
|
+
this.options = options;
|
|
358
|
+
this.actor = actor;
|
|
359
|
+
}
|
|
360
|
+
options;
|
|
361
|
+
actor;
|
|
362
|
+
async account(accountId) {
|
|
363
|
+
const { AccountCollection } = await Promise.resolve().then(() => AccountCollection_exports);
|
|
364
|
+
const { withTenant } = await import("../host.js");
|
|
365
|
+
return withTenant({ tenantId: this.actor.tenantId }, async () => {
|
|
366
|
+
const account = await (await AccountCollection.create(withoutListBounds(this.options))).get({ id: accountId });
|
|
367
|
+
if (!account || account.tenantId !== this.actor.tenantId) throw new Error("Mail account was not found in this tenant.");
|
|
368
|
+
return account;
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
/** Tenant RBAC ceiling for administering mail access (grants, owner). */
|
|
372
|
+
async assertManageAccess() {
|
|
373
|
+
const { assertOperationPermission } = await import("@happyvertical/smrt-users");
|
|
374
|
+
await assertOperationPermission({
|
|
375
|
+
...this.options,
|
|
376
|
+
collection: "messages",
|
|
377
|
+
action: "manage-access",
|
|
378
|
+
tenantId: this.actor.tenantId,
|
|
379
|
+
userId: this.actor.userId,
|
|
380
|
+
allowSuperAdminBypass: false,
|
|
381
|
+
allowSystemContextBypass: false,
|
|
382
|
+
onDeny: "throw"
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
/** The new owner must be a real, active member of this tenant. */
|
|
386
|
+
async assertTenantMember(userId) {
|
|
387
|
+
if (!(await (await (await import("@happyvertical/smrt-users")).MembershipCollection.create(this.options)).list({
|
|
388
|
+
where: {
|
|
389
|
+
tenantId: this.actor.tenantId,
|
|
390
|
+
userId,
|
|
391
|
+
status: "active"
|
|
392
|
+
},
|
|
393
|
+
limit: 1
|
|
394
|
+
})).length) throw new Error("The new owner must be an active member of this tenant.");
|
|
395
|
+
}
|
|
396
|
+
async inTenant(fn) {
|
|
397
|
+
const { withTenant } = await import("../host.js");
|
|
398
|
+
return withTenant({ tenantId: this.actor.tenantId }, fn);
|
|
399
|
+
}
|
|
400
|
+
resourceFor(accountId) {
|
|
401
|
+
return {
|
|
402
|
+
tenantId: this.actor.tenantId,
|
|
403
|
+
resourceType: MAIL_ACCOUNT_RESOURCE_TYPE,
|
|
404
|
+
resourceId: accountId
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
async grantsApi() {
|
|
408
|
+
const users = await import("@happyvertical/smrt-users");
|
|
409
|
+
const verifyResource = (resource) => resource.tenantId === this.actor.tenantId && resource.resourceType === "messages:account";
|
|
410
|
+
return {
|
|
411
|
+
users,
|
|
412
|
+
verifyResource
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
grant(input) {
|
|
416
|
+
return this.inTenant(() => this.grantImpl(input));
|
|
417
|
+
}
|
|
418
|
+
revoke(grantId) {
|
|
419
|
+
return this.inTenant(() => this.revokeImpl(grantId));
|
|
420
|
+
}
|
|
421
|
+
list(accountId) {
|
|
422
|
+
return this.inTenant(() => this.listImpl(accountId));
|
|
423
|
+
}
|
|
424
|
+
setOwner(accountId, ownerUserId) {
|
|
425
|
+
return this.inTenant(() => this.setOwnerImpl(accountId, ownerUserId));
|
|
426
|
+
}
|
|
427
|
+
async grantImpl(input) {
|
|
428
|
+
if (!isMailScope(input.scope)) throw new Error("Unknown mail scope.");
|
|
429
|
+
const account = await this.account(input.accountId);
|
|
430
|
+
if (!account.ownerUserId) throw new Error("Set an owner on this mail account before sharing it.");
|
|
431
|
+
if (input.userId === this.actor.userId && !input.parentGrantId) throw new Error("A mail grant must name another user.");
|
|
432
|
+
const isOwner = account.ownerUserId === this.actor.userId;
|
|
433
|
+
if (!isOwner && !input.parentGrantId) throw new Error("Only the account owner can grant mail access.");
|
|
434
|
+
if (isOwner && input.parentGrantId) throw new Error("An owner grants directly, not by delegation.");
|
|
435
|
+
if (!isOwner && (input.effect === "deny" || input.canDelegate === true)) throw new Error("A delegate can only pass on a plain, non-delegable grant.");
|
|
436
|
+
const { users, verifyResource } = await this.grantsApi();
|
|
437
|
+
return new users.ResourceGrantService(this.options).create({
|
|
438
|
+
actor: {
|
|
439
|
+
collection: "messages",
|
|
440
|
+
action: "manage-access",
|
|
441
|
+
tenantId: this.actor.tenantId,
|
|
442
|
+
userId: this.actor.userId,
|
|
443
|
+
allowSuperAdminBypass: false,
|
|
444
|
+
allowSystemContextBypass: false
|
|
445
|
+
},
|
|
446
|
+
authorization: {
|
|
447
|
+
collection: "messages",
|
|
448
|
+
action: input.scope,
|
|
449
|
+
tenantId: this.actor.tenantId,
|
|
450
|
+
userId: this.actor.userId,
|
|
451
|
+
allowSuperAdminBypass: false,
|
|
452
|
+
allowSystemContextBypass: false,
|
|
453
|
+
resource: this.resourceFor(input.accountId),
|
|
454
|
+
verifyResource
|
|
455
|
+
},
|
|
456
|
+
grant: {
|
|
457
|
+
...this.resourceFor(input.accountId),
|
|
458
|
+
userId: input.userId,
|
|
459
|
+
permission: mailScopePermission(input.scope),
|
|
460
|
+
effect: input.effect ?? "grant",
|
|
461
|
+
canDelegate: input.canDelegate ?? false,
|
|
462
|
+
parentGrantId: input.parentGrantId ?? null
|
|
463
|
+
}
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
/** Revoke a grant. Delegated children stop working with their ancestor. */
|
|
467
|
+
async revokeImpl(grantId) {
|
|
468
|
+
const { users, verifyResource } = await this.grantsApi();
|
|
469
|
+
const grant = await (await users.ResourceGrantCollection.create(withoutListBounds(this.options))).get({ id: grantId });
|
|
470
|
+
if (!grant || grant.tenantId !== this.actor.tenantId || grant.resourceType !== "messages:account") throw new Error("Mail grant not found.");
|
|
471
|
+
if ((await this.account(grant.resourceId)).ownerUserId !== this.actor.userId) throw new Error("Only the account owner can revoke mail access.");
|
|
472
|
+
await new users.ResourceGrantService(this.options).revoke(grantId, {
|
|
473
|
+
actor: {
|
|
474
|
+
collection: "messages",
|
|
475
|
+
action: "manage-access",
|
|
476
|
+
tenantId: this.actor.tenantId,
|
|
477
|
+
userId: this.actor.userId,
|
|
478
|
+
allowSuperAdminBypass: false,
|
|
479
|
+
allowSystemContextBypass: false
|
|
480
|
+
},
|
|
481
|
+
verifyResource
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
/** Owner-only listing of who holds what on one account. */
|
|
485
|
+
async listImpl(accountId) {
|
|
486
|
+
if ((await this.account(accountId)).ownerUserId !== this.actor.userId) throw new Error("Only the account owner can list mail access.");
|
|
487
|
+
await this.assertManageAccess();
|
|
488
|
+
const { users } = await this.grantsApi();
|
|
489
|
+
return (await (await users.ResourceGrantCollection.create(withoutListBounds(this.options))).list({ where: {
|
|
490
|
+
tenantId: this.actor.tenantId,
|
|
491
|
+
resourceType: MAIL_ACCOUNT_RESOURCE_TYPE,
|
|
492
|
+
resourceId: accountId
|
|
493
|
+
} })).filter((grant) => grant.isActive());
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Set or change the owner. An owned account changes hands only by its
|
|
497
|
+
* owner. An unowned account can be claimed by a tenant administrator
|
|
498
|
+
* holding `messages.manage-credentials` (the migration path from
|
|
499
|
+
* tenant-wide to owned).
|
|
500
|
+
*/
|
|
501
|
+
async setOwnerImpl(accountId, ownerUserId) {
|
|
502
|
+
const account = await this.account(accountId);
|
|
503
|
+
if (account.ownerUserId) {
|
|
504
|
+
if (account.ownerUserId !== this.actor.userId) throw new Error("Only the account owner can transfer ownership.");
|
|
505
|
+
await this.assertManageAccess();
|
|
506
|
+
} else {
|
|
507
|
+
const { assertOperationPermission } = await import("@happyvertical/smrt-users");
|
|
508
|
+
await assertOperationPermission({
|
|
509
|
+
...this.options,
|
|
510
|
+
collection: "messages",
|
|
511
|
+
action: "manage-credentials",
|
|
512
|
+
tenantId: this.actor.tenantId,
|
|
513
|
+
userId: this.actor.userId,
|
|
514
|
+
allowSuperAdminBypass: false,
|
|
515
|
+
allowSystemContextBypass: false,
|
|
516
|
+
onDeny: "throw"
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
await this.assertTenantMember(ownerUserId);
|
|
520
|
+
account.ownerUserId = ownerUserId;
|
|
521
|
+
account.updatedAt = /* @__PURE__ */ new Date();
|
|
522
|
+
await account.save();
|
|
523
|
+
}
|
|
524
|
+
};
|
|
525
|
+
//#endregion
|
|
526
|
+
//#region src/models/Account.ts
|
|
527
|
+
var __defProp$1 = Object.defineProperty;
|
|
528
|
+
var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
|
|
529
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, {
|
|
530
|
+
enumerable: true,
|
|
531
|
+
configurable: true,
|
|
532
|
+
writable: true,
|
|
533
|
+
value
|
|
534
|
+
}) : obj[key] = value;
|
|
535
|
+
var __decorateClass$1 = (decorators, target, key, kind) => {
|
|
536
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target;
|
|
537
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--) if (decorator = decorators[i]) result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
538
|
+
if (kind && result) __defProp$1(target, key, result);
|
|
539
|
+
return result;
|
|
540
|
+
};
|
|
541
|
+
var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
542
|
+
var Account = class extends SmrtObject {
|
|
543
|
+
tenantId = null;
|
|
544
|
+
name = "";
|
|
545
|
+
providerType = "";
|
|
546
|
+
channelType = "";
|
|
547
|
+
credentialSecretId = null;
|
|
548
|
+
isActive = true;
|
|
549
|
+
ownerUserId = null;
|
|
550
|
+
label = null;
|
|
551
|
+
connectionStatus = null;
|
|
552
|
+
statusMessage = null;
|
|
553
|
+
lastSyncAt = null;
|
|
554
|
+
settings = "";
|
|
555
|
+
configuration = "{}";
|
|
556
|
+
createdAt = /* @__PURE__ */ new Date();
|
|
557
|
+
updatedAt = /* @__PURE__ */ new Date();
|
|
558
|
+
constructor(options = {}) {
|
|
559
|
+
super(options);
|
|
560
|
+
if (options.tenantId !== void 0) this.tenantId = options.tenantId;
|
|
561
|
+
if (options.name !== void 0) this.name = options.name;
|
|
562
|
+
if (options.providerType !== void 0) this.providerType = options.providerType;
|
|
563
|
+
if (options.channelType !== void 0) this.channelType = options.channelType;
|
|
564
|
+
if (options.credentialSecretId !== void 0) this.credentialSecretId = options.credentialSecretId || null;
|
|
565
|
+
if (options.isActive !== void 0) this.isActive = options.isActive;
|
|
566
|
+
if (options.ownerUserId !== void 0) this.ownerUserId = options.ownerUserId || null;
|
|
567
|
+
if (options.label !== void 0) this.label = options.label || null;
|
|
568
|
+
if (options.connectionStatus !== void 0) this.connectionStatus = options.connectionStatus || null;
|
|
569
|
+
if (options.statusMessage !== void 0) this.statusMessage = options.statusMessage || null;
|
|
570
|
+
if (options.lastSyncAt !== void 0) this.lastSyncAt = options.lastSyncAt || null;
|
|
571
|
+
if (options.settings !== void 0) this.settings = options.settings;
|
|
572
|
+
if (options.configuration !== void 0) this.configuration = options.configuration;
|
|
573
|
+
if (options.createdAt) this.createdAt = options.createdAt;
|
|
574
|
+
if (options.updatedAt) this.updatedAt = options.updatedAt;
|
|
575
|
+
}
|
|
576
|
+
/**
|
|
577
|
+
* Get settings as parsed object
|
|
578
|
+
*/
|
|
579
|
+
getSettings() {
|
|
580
|
+
if (!this.settings) return {};
|
|
581
|
+
try {
|
|
582
|
+
return JSON.parse(this.settings);
|
|
583
|
+
} catch {
|
|
584
|
+
return {};
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* Set settings from object
|
|
589
|
+
*/
|
|
590
|
+
setSettings(settings) {
|
|
591
|
+
this.settings = JSON.stringify(settings);
|
|
592
|
+
}
|
|
593
|
+
getConfiguration() {
|
|
594
|
+
try {
|
|
595
|
+
return JSON.parse(this.configuration || "{}");
|
|
596
|
+
} catch {
|
|
597
|
+
return {};
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
setConfiguration(configuration) {
|
|
601
|
+
this.configuration = JSON.stringify(configuration);
|
|
602
|
+
}
|
|
603
|
+
get hasCredentials() {
|
|
604
|
+
return Boolean(this.credentialSecretId || this.settings);
|
|
605
|
+
}
|
|
606
|
+
/** Whether this account needs its sign-in entered again. */
|
|
607
|
+
get needsReconnect() {
|
|
608
|
+
return this.connectionStatus === "needs_reconnect";
|
|
609
|
+
}
|
|
610
|
+
/**
|
|
611
|
+
* Record that the server refused this account's sign-in, so the host can ask
|
|
612
|
+
* the owner to reconnect instead of failing every sync silently.
|
|
613
|
+
*/
|
|
614
|
+
async markNeedsReconnect(reason) {
|
|
615
|
+
this.connectionStatus = "needs_reconnect";
|
|
616
|
+
this.statusMessage = reason.slice(0, 200);
|
|
617
|
+
this.updatedAt = /* @__PURE__ */ new Date();
|
|
618
|
+
await this.save();
|
|
619
|
+
}
|
|
620
|
+
/** Record a working sign-in (after connect, reconnect, or a good sync). */
|
|
621
|
+
async markConnected() {
|
|
622
|
+
if (this.connectionStatus === "connected" && !this.statusMessage) return;
|
|
623
|
+
this.connectionStatus = "connected";
|
|
624
|
+
this.statusMessage = null;
|
|
625
|
+
this.updatedAt = /* @__PURE__ */ new Date();
|
|
626
|
+
await this.save();
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* Activate account
|
|
630
|
+
*/
|
|
631
|
+
async activate() {
|
|
632
|
+
this.isActive = true;
|
|
633
|
+
this.updatedAt = /* @__PURE__ */ new Date();
|
|
634
|
+
await this.save();
|
|
635
|
+
}
|
|
636
|
+
/**
|
|
637
|
+
* Deactivate account
|
|
638
|
+
*/
|
|
639
|
+
async deactivate() {
|
|
640
|
+
this.isActive = false;
|
|
641
|
+
this.updatedAt = /* @__PURE__ */ new Date();
|
|
642
|
+
await this.save();
|
|
643
|
+
}
|
|
644
|
+
/**
|
|
645
|
+
* Store credentials securely using smrt-secrets
|
|
646
|
+
*/
|
|
647
|
+
async setCredentials(credentials, options = {}) {
|
|
648
|
+
if (!this.id) throw new Error("Account must be persisted before storing credentials.");
|
|
649
|
+
const secretService = await createAccountSecretService(this.db);
|
|
650
|
+
const secretName = `${this.channelType || "messaging"}-account-${this.id}`;
|
|
651
|
+
const secretValue = JSON.stringify(credentials);
|
|
652
|
+
const tenantId2 = this.requireCredentialTenantId("store credentials");
|
|
653
|
+
await secretService.storeForTenant(tenantId2, this.credentialSecretId || secretName, secretValue, {
|
|
654
|
+
description: options.description || `Credentials for ${this.name}`,
|
|
655
|
+
category: options.category || "messaging"
|
|
656
|
+
});
|
|
657
|
+
this.credentialSecretId ||= secretName;
|
|
658
|
+
this.updatedAt = /* @__PURE__ */ new Date();
|
|
659
|
+
await this.withCredentialTenantContext(() => this.save());
|
|
660
|
+
}
|
|
661
|
+
/**
|
|
662
|
+
* Delete the stored credential from smrt-secrets (used when the account is
|
|
663
|
+
* removed, so a removed mailbox never leaves a live secret behind).
|
|
664
|
+
*/
|
|
665
|
+
async removeCredentials() {
|
|
666
|
+
if (!this.credentialSecretId) return;
|
|
667
|
+
const tenantId2 = this.requireCredentialTenantId("remove credentials");
|
|
668
|
+
const secretService = await createAccountSecretService(this.db);
|
|
669
|
+
const name = this.credentialSecretId;
|
|
670
|
+
await withTenant({ tenantId: tenantId2 }, () => secretService.delete(name));
|
|
671
|
+
this.credentialSecretId = null;
|
|
672
|
+
}
|
|
673
|
+
/**
|
|
674
|
+
* Create a sender for this account.
|
|
675
|
+
* Subclasses must override to return a concrete sender.
|
|
676
|
+
*/
|
|
677
|
+
async createSender() {
|
|
678
|
+
const { getMessagingProvider } = await import("./providers-Bz_F_ywF.js").then((n) => n.i);
|
|
679
|
+
const provider = getMessagingProvider(this.providerType);
|
|
680
|
+
if (!provider?.createSender) throw new Error(`createSender() not implemented for account type '${this.providerType}'`);
|
|
681
|
+
return provider.createSender(this);
|
|
682
|
+
}
|
|
683
|
+
/**
|
|
684
|
+
* Retrieve stored credentials
|
|
685
|
+
*/
|
|
686
|
+
async getCredentials() {
|
|
687
|
+
if (!this.credentialSecretId) return this.getSettings();
|
|
688
|
+
const tenantId2 = this.requireCredentialTenantId("retrieve credentials");
|
|
689
|
+
const secretService = await createAccountSecretService(this.db);
|
|
690
|
+
try {
|
|
691
|
+
const secret = await secretService.retrieveForTenant(tenantId2, this.credentialSecretId);
|
|
692
|
+
return JSON.parse(secret.value);
|
|
693
|
+
} catch {
|
|
694
|
+
return null;
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
getCredentialTenantId() {
|
|
698
|
+
return this.tenantId || getCurrentTenant()?.tenantId || null;
|
|
699
|
+
}
|
|
700
|
+
requireCredentialTenantId(action) {
|
|
701
|
+
const tenantId2 = this.getCredentialTenantId();
|
|
702
|
+
if (!tenantId2) throw new Error(`Tenant context required to ${action}.`);
|
|
703
|
+
return tenantId2;
|
|
704
|
+
}
|
|
705
|
+
async withCredentialTenantContext(fn) {
|
|
706
|
+
const tenantId2 = this.getCredentialTenantId();
|
|
707
|
+
if (!tenantId2 || getCurrentTenant()?.tenantId === tenantId2) return fn();
|
|
708
|
+
return withTenant({ tenantId: tenantId2 }, fn);
|
|
709
|
+
}
|
|
710
|
+
};
|
|
711
|
+
__publicField$1(Account, "__smrtPackage__", "@happyvertical/smrt-messages");
|
|
712
|
+
__decorateClass$1([tenantId({ nullable: true })], Account.prototype, "tenantId", 2);
|
|
713
|
+
__decorateClass$1([field({ description: "The display name for this connected messaging account." })], Account.prototype, "name", 2);
|
|
714
|
+
__decorateClass$1([field({ description: "The service that connects this account to your application." })], Account.prototype, "providerType", 2);
|
|
715
|
+
__decorateClass$1([field({ description: "The kind of messaging this account supports, such as email or chat." })], Account.prototype, "channelType", 2);
|
|
716
|
+
__decorateClass$1([field({
|
|
717
|
+
sensitive: true,
|
|
718
|
+
readonly: true
|
|
719
|
+
})], Account.prototype, "credentialSecretId", 2);
|
|
720
|
+
__decorateClass$1([field({ description: "Whether this account is enabled for messaging." })], Account.prototype, "isActive", 2);
|
|
721
|
+
__decorateClass$1([crossPackageRef("@happyvertical/smrt-users:User"), field({ description: "The person who owns this account and decides who else may use it." })], Account.prototype, "ownerUserId", 2);
|
|
722
|
+
__decorateClass$1([field({ description: "A short name shown beside this account, such as Support or Personal." })], Account.prototype, "label", 2);
|
|
723
|
+
__decorateClass$1([field({ description: "Whether the saved sign-in still works: connected, or needs_reconnect after the server refused it." })], Account.prototype, "connectionStatus", 2);
|
|
724
|
+
__decorateClass$1([field({ description: "Why the account needs attention, in plain words." })], Account.prototype, "statusMessage", 2);
|
|
725
|
+
__decorateClass$1([field({ description: "When this account last checked for new messages." })], Account.prototype, "lastSyncAt", 2);
|
|
726
|
+
__decorateClass$1([field({
|
|
727
|
+
sensitive: true,
|
|
728
|
+
readonly: true
|
|
729
|
+
})], Account.prototype, "settings", 2);
|
|
730
|
+
__decorateClass$1([field({ description: "The public connection settings for this account; credentials are stored separately." })], Account.prototype, "configuration", 2);
|
|
731
|
+
__decorateClass$1([field({ description: "When this account was added." })], Account.prototype, "createdAt", 2);
|
|
732
|
+
__decorateClass$1([field({ description: "When this account was last changed." })], Account.prototype, "updatedAt", 2);
|
|
733
|
+
Account = __decorateClass$1([TenantScoped({ mode: "optional" }), smrt({
|
|
734
|
+
tableStrategy: "sti",
|
|
735
|
+
api: { include: ["list", "get"] },
|
|
736
|
+
mcp: { include: ["list", "get"] },
|
|
737
|
+
cli: { include: ["list", "get"] }
|
|
738
|
+
})], Account);
|
|
739
|
+
//#endregion
|
|
740
|
+
//#region src/mail-sync.ts
|
|
741
|
+
var mail_sync_exports = /* @__PURE__ */ __exportAll({
|
|
742
|
+
applyServerMessage: () => applyServerMessage,
|
|
743
|
+
ensureFolder: () => ensureFolder,
|
|
744
|
+
folderIdFor: () => folderIdFor,
|
|
745
|
+
inLane: () => inLane,
|
|
746
|
+
refreshCounts: () => refreshCounts,
|
|
747
|
+
rethrowAfterAuthCheck: () => rethrowAfterAuthCheck,
|
|
748
|
+
syncMailChanges: () => syncMailChanges,
|
|
749
|
+
withMailboxLabels: () => withMailboxLabels
|
|
750
|
+
});
|
|
751
|
+
var DEFAULT_LIMIT = 100;
|
|
752
|
+
var DEFAULT_MAX_BATCHES = 500;
|
|
753
|
+
var PRUNE_PAGE = 500;
|
|
754
|
+
var lanes = /* @__PURE__ */ new Map();
|
|
755
|
+
async function inLane(accountId, run) {
|
|
756
|
+
const next = (lanes.get(accountId) ?? Promise.resolve()).then(run, run);
|
|
757
|
+
const tail = next.catch(() => void 0);
|
|
758
|
+
lanes.set(accountId, tail);
|
|
759
|
+
try {
|
|
760
|
+
return await next;
|
|
761
|
+
} finally {
|
|
762
|
+
if (lanes.get(accountId) === tail) lanes.delete(accountId);
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
function applyServerMessage(email, msg, location, options = {}) {
|
|
766
|
+
email.messageId = msg.messageId || "";
|
|
767
|
+
email.threadId = msg.threadId || "";
|
|
768
|
+
email.inReplyTo = msg.inReplyTo || "";
|
|
769
|
+
email.fromAddress = msg.from?.address || "";
|
|
770
|
+
email.fromName = msg.from?.name || "";
|
|
771
|
+
email.toAddresses = JSON.stringify(msg.to || []);
|
|
772
|
+
email.ccAddresses = JSON.stringify(msg.cc || []);
|
|
773
|
+
email.bccAddresses = JSON.stringify(msg.bcc || []);
|
|
774
|
+
email.replyToAddress = msg.replyTo?.address || "";
|
|
775
|
+
email.replyToName = msg.replyTo?.name || "";
|
|
776
|
+
email.subject = msg.subject || "";
|
|
777
|
+
email.date = msg.date || null;
|
|
778
|
+
if (!(options.keepBodies && msg.text === void 0 && msg.html === void 0)) {
|
|
779
|
+
email.textBody = msg.text || "";
|
|
780
|
+
email.htmlBody = msg.html || "";
|
|
781
|
+
email.body = msg.text || "";
|
|
782
|
+
}
|
|
783
|
+
email.folderId = location.folderId;
|
|
784
|
+
email.folderPath = location.folderPath;
|
|
785
|
+
email.labels = JSON.stringify(msg.labels || []);
|
|
786
|
+
email.flags = JSON.stringify(msg.flags || []);
|
|
787
|
+
email.hasAttachments = msg.attachments && msg.attachments.length > 0 || false;
|
|
788
|
+
email.size = msg.size || 0;
|
|
789
|
+
email.headers = JSON.stringify(msg.headers || {});
|
|
790
|
+
email.updatedAt = /* @__PURE__ */ new Date();
|
|
791
|
+
if (options.deriveState) {
|
|
792
|
+
const flags = new Set((msg.flags || []).map((f) => f.toLowerCase()));
|
|
793
|
+
email.isRead = flags.has("\\seen");
|
|
794
|
+
email.isFlagged = flags.has("\\flagged");
|
|
795
|
+
email.isAnswered = flags.has("\\answered");
|
|
796
|
+
email.isDraft = flags.has("\\draft");
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
function withMailboxLabels(msg) {
|
|
800
|
+
return msg.labels?.length || !msg.folders?.length ? msg : {
|
|
801
|
+
...msg,
|
|
802
|
+
labels: msg.folders
|
|
803
|
+
};
|
|
804
|
+
}
|
|
805
|
+
async function ensureFolder(ctx, path, details = {}) {
|
|
806
|
+
let folder = await ctx.folders.getByPath(ctx.accountId, path);
|
|
807
|
+
if (!folder) {
|
|
808
|
+
const { EmailFolder: EmailFolderModel } = await import("./EmailFolder-C_H8u6bS.js").then((n) => n.n);
|
|
809
|
+
folder = new (ObjectRegistry.resolveEffectiveConstructor(EmailFolderModel))({
|
|
810
|
+
...ctx.childOptions,
|
|
811
|
+
accountId: ctx.accountId,
|
|
812
|
+
name: details.name || path,
|
|
813
|
+
path
|
|
814
|
+
});
|
|
815
|
+
await folder.initialize();
|
|
816
|
+
}
|
|
817
|
+
if (details.name !== void 0) folder.name = details.name;
|
|
818
|
+
if (details.delimiter !== void 0) folder.delimiter = details.delimiter;
|
|
819
|
+
folder.specialUse = details.specialUse ?? folder.specialUse ?? "";
|
|
820
|
+
if (details.subscribed !== void 0) folder.subscribed = details.subscribed;
|
|
821
|
+
folder.updatedAt = /* @__PURE__ */ new Date();
|
|
822
|
+
await folder.save();
|
|
823
|
+
const id = folder.id ?? "";
|
|
824
|
+
ctx.folderIds.set(path, id);
|
|
825
|
+
return id;
|
|
826
|
+
}
|
|
827
|
+
async function folderIdFor(ctx, path) {
|
|
828
|
+
if (!path) return "";
|
|
829
|
+
return ctx.folderIds.get(path) ?? await ensureFolder(ctx, path);
|
|
830
|
+
}
|
|
831
|
+
async function findByProviderId(ctx, providerMessageId) {
|
|
832
|
+
return await ctx.emails.list({ where: {
|
|
833
|
+
accountId: ctx.accountId,
|
|
834
|
+
providerMessageId
|
|
835
|
+
} });
|
|
836
|
+
}
|
|
837
|
+
async function upsertMessage(ctx, msg, touched, isChange) {
|
|
838
|
+
if (!msg.id) throw new Error("Mail change feed returned a message without an id");
|
|
839
|
+
const [existing] = await findByProviderId(ctx, msg.id);
|
|
840
|
+
if (!existing && ctx.horizon && msg.date && new Date(msg.date).getTime() < ctx.horizon.getTime()) {
|
|
841
|
+
ctx.beforeHorizon = (ctx.beforeHorizon ?? 0) + 1;
|
|
842
|
+
return;
|
|
843
|
+
}
|
|
844
|
+
const folderPath = msg.folder ?? msg.folders?.[0] ?? "";
|
|
845
|
+
const folderId = await folderIdFor(ctx, folderPath);
|
|
846
|
+
let email = existing;
|
|
847
|
+
if (!email) {
|
|
848
|
+
const { Email: EmailModel } = await import("./Email---ifczUW.js").then((n) => n.n);
|
|
849
|
+
email = new (ObjectRegistry.resolveEffectiveConstructor(EmailModel))({
|
|
850
|
+
...ctx.childOptions,
|
|
851
|
+
accountId: ctx.accountId
|
|
852
|
+
});
|
|
853
|
+
await email.initialize();
|
|
854
|
+
} else if (email.folderId) touched.add(email.folderId);
|
|
855
|
+
email.providerMessageId = msg.id;
|
|
856
|
+
applyServerMessage(email, withMailboxLabels(msg), {
|
|
857
|
+
folderId,
|
|
858
|
+
folderPath
|
|
859
|
+
}, {
|
|
860
|
+
keepBodies: isChange,
|
|
861
|
+
deriveState: true
|
|
862
|
+
});
|
|
863
|
+
await email.save();
|
|
864
|
+
if (folderId) touched.add(folderId);
|
|
865
|
+
}
|
|
866
|
+
async function removeMessages(ctx, ids, touched) {
|
|
867
|
+
let removed = 0;
|
|
868
|
+
for (const id of ids) for (const email of await findByProviderId(ctx, id)) {
|
|
869
|
+
if (email.folderId) touched.add(email.folderId);
|
|
870
|
+
await email.delete();
|
|
871
|
+
removed++;
|
|
872
|
+
}
|
|
873
|
+
return removed;
|
|
874
|
+
}
|
|
875
|
+
async function pruneUnseen(ctx, seen, touched) {
|
|
876
|
+
let removed = 0;
|
|
877
|
+
for (let offset = 0;; offset += PRUNE_PAGE) {
|
|
878
|
+
const page = await ctx.emails.list({
|
|
879
|
+
where: { accountId: ctx.accountId },
|
|
880
|
+
limit: PRUNE_PAGE,
|
|
881
|
+
offset
|
|
882
|
+
});
|
|
883
|
+
for (const email of page) {
|
|
884
|
+
if (!email.providerMessageId || seen.has(email.providerMessageId)) continue;
|
|
885
|
+
if (email.folderId) touched.add(email.folderId);
|
|
886
|
+
await email.delete();
|
|
887
|
+
removed++;
|
|
888
|
+
offset--;
|
|
889
|
+
}
|
|
890
|
+
if (page.length < PRUNE_PAGE) return removed;
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
async function refreshCounts(ctx, folderIds) {
|
|
894
|
+
for (const folderId of folderIds) {
|
|
895
|
+
const folder = await ctx.folders.get({ id: folderId });
|
|
896
|
+
if (!folder) continue;
|
|
897
|
+
folder.messageCount = await ctx.emails.countByFolder(folderId);
|
|
898
|
+
folder.unreadCount = await ctx.emails.countUnreadByFolder(folderId);
|
|
899
|
+
await folder.save();
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
async function reconcileAllCounts(ctx) {
|
|
903
|
+
const folders = await ctx.folders.list({ where: { accountId: ctx.accountId } });
|
|
904
|
+
await refreshCounts(ctx, new Set(folders.map((f) => f.id).filter((id) => !!id)));
|
|
905
|
+
}
|
|
906
|
+
async function applyBatch(ctx, batch, seen) {
|
|
907
|
+
const touched = /* @__PURE__ */ new Set();
|
|
908
|
+
for (const folder of batch.folders ?? []) await ensureFolder(ctx, folder.path, folder);
|
|
909
|
+
for (const msg of batch.added) {
|
|
910
|
+
await upsertMessage(ctx, msg, touched, false);
|
|
911
|
+
if (seen && msg.id) seen.add(msg.id);
|
|
912
|
+
}
|
|
913
|
+
for (const msg of batch.changed) {
|
|
914
|
+
await upsertMessage(ctx, msg, touched, true);
|
|
915
|
+
if (seen && msg.id) seen.add(msg.id);
|
|
916
|
+
}
|
|
917
|
+
const removed = await removeMessages(ctx, batch.removed, touched);
|
|
918
|
+
return {
|
|
919
|
+
added: batch.added.length,
|
|
920
|
+
changed: batch.changed.length,
|
|
921
|
+
removed,
|
|
922
|
+
touched
|
|
923
|
+
};
|
|
924
|
+
}
|
|
925
|
+
function widensHorizon(built, next) {
|
|
926
|
+
if (!built) return false;
|
|
927
|
+
if (!next) return true;
|
|
928
|
+
return next.getTime() < new Date(built).getTime();
|
|
929
|
+
}
|
|
930
|
+
function resolveHorizon(since, stored) {
|
|
931
|
+
const value = since === void 0 ? stored : since;
|
|
932
|
+
if (!value) return null;
|
|
933
|
+
const date = new Date(value);
|
|
934
|
+
if (Number.isNaN(date.getTime())) throw new Error(`Invalid mail backfill horizon: ${String(value)}`);
|
|
935
|
+
return date;
|
|
936
|
+
}
|
|
937
|
+
function mirrorAccountState(from, to) {
|
|
938
|
+
to.syncCursor = from.syncCursor;
|
|
939
|
+
to.cursorHorizon = from.cursorHorizon;
|
|
940
|
+
to.lastSyncAt = from.lastSyncAt;
|
|
941
|
+
to.connectionStatus = from.connectionStatus;
|
|
942
|
+
to.statusMessage = from.statusMessage;
|
|
943
|
+
to.lastSyncError = from.lastSyncError;
|
|
944
|
+
to.backlog = from.backlog;
|
|
945
|
+
to.isActive = from.isActive;
|
|
946
|
+
to.updatedAt = from.updatedAt;
|
|
947
|
+
to.updated_at = from.updated_at;
|
|
948
|
+
}
|
|
949
|
+
async function persistCursor(account, cursor, horizon = null) {
|
|
950
|
+
account.syncCursor = cursor;
|
|
951
|
+
account.cursorHorizon = horizon;
|
|
952
|
+
account.updatedAt = /* @__PURE__ */ new Date();
|
|
953
|
+
await account.save();
|
|
954
|
+
}
|
|
955
|
+
async function rethrowAfterAuthCheck(account, error, isAuthFailure, options = {}) {
|
|
956
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
957
|
+
if (options.recordError) {
|
|
958
|
+
account.lastSyncError = err.message.slice(0, 500);
|
|
959
|
+
account.updatedAt = /* @__PURE__ */ new Date();
|
|
960
|
+
await account.save().catch(() => void 0);
|
|
961
|
+
}
|
|
962
|
+
if (isAuthFailure(err)) {
|
|
963
|
+
await account.markNeedsReconnect(err.message).catch(() => void 0);
|
|
964
|
+
err.retryable = false;
|
|
965
|
+
}
|
|
966
|
+
throw err;
|
|
967
|
+
}
|
|
968
|
+
async function syncMailChanges(source, options = {}, deps) {
|
|
969
|
+
if (!source.id) throw new Error("EmailAccount.syncChanges requires a persisted account");
|
|
970
|
+
const accountId = source.id;
|
|
971
|
+
return inLane(accountId, async () => {
|
|
972
|
+
const startedAt = Date.now();
|
|
973
|
+
const result = {
|
|
974
|
+
status: "synced",
|
|
975
|
+
batches: 0,
|
|
976
|
+
added: 0,
|
|
977
|
+
changed: 0,
|
|
978
|
+
removed: 0,
|
|
979
|
+
resynced: false,
|
|
980
|
+
hasMore: false,
|
|
981
|
+
beforeHorizon: 0,
|
|
982
|
+
duration: 0
|
|
983
|
+
};
|
|
984
|
+
const skip = (reason) => ({
|
|
985
|
+
...result,
|
|
986
|
+
status: "skipped",
|
|
987
|
+
skipped: reason,
|
|
988
|
+
duration: Date.now() - startedAt
|
|
989
|
+
});
|
|
990
|
+
const { EmailAccountCollection } = await Promise.resolve().then(() => EmailAccountCollection_exports);
|
|
991
|
+
const account = await (await EmailAccountCollection.create(deps.childOptions)).get({ id: accountId }) ?? source;
|
|
992
|
+
try {
|
|
993
|
+
return await runLane(account);
|
|
994
|
+
} finally {
|
|
995
|
+
if (account !== source) mirrorAccountState(account, source);
|
|
996
|
+
}
|
|
997
|
+
async function runLane(account2) {
|
|
998
|
+
if (!account2.isActive) return skip("inactive");
|
|
999
|
+
if (account2.needsReconnect) return skip("needs-reconnect");
|
|
1000
|
+
const limit = options.limit ?? DEFAULT_LIMIT;
|
|
1001
|
+
const maxBatches = options.maxBatches ?? DEFAULT_MAX_BATCHES;
|
|
1002
|
+
let client;
|
|
1003
|
+
try {
|
|
1004
|
+
client = await deps.createClient(account2);
|
|
1005
|
+
await client.connect();
|
|
1006
|
+
if (typeof client.getChanges !== "function") return skip("unsupported");
|
|
1007
|
+
const { EmailCollection: EmailCollectionClass } = await import("./EmailCollection-CHINTmyA.js").then((n) => n.n);
|
|
1008
|
+
const { EmailFolderCollection: FolderCollectionClass } = await import("./EmailFolderCollection-B83qLC-c.js").then((n) => n.n);
|
|
1009
|
+
const ctx = {
|
|
1010
|
+
account: account2,
|
|
1011
|
+
accountId,
|
|
1012
|
+
emails: await EmailCollectionClass.create(deps.childOptions),
|
|
1013
|
+
folders: await FolderCollectionClass.create(deps.childOptions),
|
|
1014
|
+
childOptions: deps.childOptions,
|
|
1015
|
+
folderIds: /* @__PURE__ */ new Map(),
|
|
1016
|
+
horizon: resolveHorizon(options.since, account2.backfillSince),
|
|
1017
|
+
beforeHorizon: 0
|
|
1018
|
+
};
|
|
1019
|
+
await reconcileAllCounts(ctx);
|
|
1020
|
+
if (account2.syncCursor && widensHorizon(account2.cursorHorizon, ctx.horizon)) await persistCursor(account2, null, ctx.horizon);
|
|
1021
|
+
let cursor = account2.syncCursor || void 0;
|
|
1022
|
+
let seen = cursor === void 0 ? /* @__PURE__ */ new Set() : null;
|
|
1023
|
+
while (result.batches < maxBatches) {
|
|
1024
|
+
const next = await client.getChanges({
|
|
1025
|
+
cursor,
|
|
1026
|
+
limit,
|
|
1027
|
+
includeBodies: true
|
|
1028
|
+
});
|
|
1029
|
+
if (next.status === "resync-required") {
|
|
1030
|
+
if (result.resynced) throw new Error(`Mail server asked for a second resync in one run (${next.reason})`);
|
|
1031
|
+
result.resynced = true;
|
|
1032
|
+
cursor = void 0;
|
|
1033
|
+
seen = /* @__PURE__ */ new Set();
|
|
1034
|
+
await persistCursor(account2, null, ctx.horizon);
|
|
1035
|
+
continue;
|
|
1036
|
+
}
|
|
1037
|
+
const applied = await applyBatch(ctx, next, seen);
|
|
1038
|
+
result.batches++;
|
|
1039
|
+
result.added += applied.added;
|
|
1040
|
+
result.changed += applied.changed;
|
|
1041
|
+
result.removed += applied.removed;
|
|
1042
|
+
if (seen && next.initial && !next.hasMore) result.removed += await pruneUnseen(ctx, seen, applied.touched);
|
|
1043
|
+
await refreshCounts(ctx, applied.touched);
|
|
1044
|
+
await persistCursor(account2, next.cursor, ctx.horizon ?? null);
|
|
1045
|
+
cursor = next.cursor;
|
|
1046
|
+
if (!next.hasMore) break;
|
|
1047
|
+
if (result.batches >= maxBatches) result.hasMore = true;
|
|
1048
|
+
}
|
|
1049
|
+
result.beforeHorizon = ctx.beforeHorizon ?? 0;
|
|
1050
|
+
account2.lastSyncAt = /* @__PURE__ */ new Date();
|
|
1051
|
+
account2.connectionStatus = "connected";
|
|
1052
|
+
account2.statusMessage = null;
|
|
1053
|
+
account2.lastSyncError = null;
|
|
1054
|
+
account2.backlog = result.hasMore;
|
|
1055
|
+
account2.updatedAt = /* @__PURE__ */ new Date();
|
|
1056
|
+
await account2.save();
|
|
1057
|
+
result.duration = Date.now() - startedAt;
|
|
1058
|
+
return result;
|
|
1059
|
+
} catch (error) {
|
|
1060
|
+
return rethrowAfterAuthCheck(account2, error, deps.isAuthFailure, { recordError: true });
|
|
1061
|
+
} finally {
|
|
1062
|
+
await client?.disconnect().catch(() => void 0);
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
});
|
|
1066
|
+
}
|
|
1067
|
+
//#endregion
|
|
1068
|
+
//#region src/mail-triage.ts
|
|
1069
|
+
var ACTION_CAPABILITY = {
|
|
1070
|
+
markRead: "flags",
|
|
1071
|
+
markUnread: "flags",
|
|
1072
|
+
star: "flags",
|
|
1073
|
+
unstar: "flags",
|
|
1074
|
+
archive: "archive",
|
|
1075
|
+
markSpam: "spam",
|
|
1076
|
+
unmarkSpam: "spam",
|
|
1077
|
+
addLabels: "labels",
|
|
1078
|
+
removeLabels: "labels",
|
|
1079
|
+
move: "labels"
|
|
1080
|
+
};
|
|
1081
|
+
var CAPABILITY_METHOD = {
|
|
1082
|
+
flags: "updateFlags",
|
|
1083
|
+
labels: "updateLabels",
|
|
1084
|
+
archive: "archive",
|
|
1085
|
+
spam: "markSpam"
|
|
1086
|
+
};
|
|
1087
|
+
var MailWriteBackUnsupportedError = class extends Error {
|
|
1088
|
+
constructor(action, capability, providerType) {
|
|
1089
|
+
super(`Mail provider '${providerType}' cannot write '${action}' back to the server (no '${capability}' write-back).`);
|
|
1090
|
+
this.action = action;
|
|
1091
|
+
this.capability = capability;
|
|
1092
|
+
this.providerType = providerType;
|
|
1093
|
+
this.name = "MailWriteBackUnsupportedError";
|
|
1094
|
+
}
|
|
1095
|
+
action;
|
|
1096
|
+
capability;
|
|
1097
|
+
providerType;
|
|
1098
|
+
code = "WRITE_BACK_UNSUPPORTED";
|
|
1099
|
+
};
|
|
1100
|
+
function parseLabels(email) {
|
|
1101
|
+
const labels = email.getLabels();
|
|
1102
|
+
return labels.length > 0 ? labels : email.folderPath ? [email.folderPath] : [];
|
|
1103
|
+
}
|
|
1104
|
+
function assertValid(action) {
|
|
1105
|
+
if (!(action.kind in ACTION_CAPABILITY)) throw new TypeError(`Unknown triage action '${action.kind}'`);
|
|
1106
|
+
const names = action.kind === "addLabels" || action.kind === "removeLabels" ? action.labels : action.kind === "move" ? [action.folder] : null;
|
|
1107
|
+
if (names && (!Array.isArray(names) || names.length === 0 || names.some((n) => typeof n !== "string" || !n.trim()))) throw new TypeError(`Triage action '${action.kind}' needs at least one non-empty label or folder name`);
|
|
1108
|
+
}
|
|
1109
|
+
function requireCapability(action, client, capabilities, providerType) {
|
|
1110
|
+
const capability = ACTION_CAPABILITY[action];
|
|
1111
|
+
const method = CAPABILITY_METHOD[capability];
|
|
1112
|
+
if (!capabilities.writeBack?.[capability] || typeof client[method] !== "function") throw new MailWriteBackUnsupportedError(action, capability, providerType);
|
|
1113
|
+
}
|
|
1114
|
+
async function resolveMailbox(folders, accountId, requested) {
|
|
1115
|
+
const wanted = requested.trim();
|
|
1116
|
+
const known = await folders.getByAccount(accountId);
|
|
1117
|
+
const lower = wanted.toLowerCase();
|
|
1118
|
+
const exact = known.find((f) => f.path === wanted);
|
|
1119
|
+
if (exact?.path) return exact.path;
|
|
1120
|
+
const byPath = known.filter((f) => f.path?.toLowerCase() === lower);
|
|
1121
|
+
if (byPath.length === 1 && byPath[0].path) return byPath[0].path;
|
|
1122
|
+
const byName = known.filter((f) => f.name?.toLowerCase() === lower);
|
|
1123
|
+
if (byName.length === 1 && byName[0].path) return byName[0].path;
|
|
1124
|
+
return wanted;
|
|
1125
|
+
}
|
|
1126
|
+
function plan(action, client, rows, destination) {
|
|
1127
|
+
const ids = [...rows.keys()];
|
|
1128
|
+
switch (action.kind) {
|
|
1129
|
+
case "markRead": return [{
|
|
1130
|
+
ids,
|
|
1131
|
+
run: () => client.updateFlags(ids, { add: ["\\Seen"] })
|
|
1132
|
+
}];
|
|
1133
|
+
case "markUnread": return [{
|
|
1134
|
+
ids,
|
|
1135
|
+
run: () => client.updateFlags(ids, { remove: ["\\Seen"] })
|
|
1136
|
+
}];
|
|
1137
|
+
case "star": return [{
|
|
1138
|
+
ids,
|
|
1139
|
+
run: () => client.updateFlags(ids, { add: ["\\Flagged"] })
|
|
1140
|
+
}];
|
|
1141
|
+
case "unstar": return [{
|
|
1142
|
+
ids,
|
|
1143
|
+
run: () => client.updateFlags(ids, { remove: ["\\Flagged"] })
|
|
1144
|
+
}];
|
|
1145
|
+
case "archive": return [{
|
|
1146
|
+
ids,
|
|
1147
|
+
run: () => client.archive(ids)
|
|
1148
|
+
}];
|
|
1149
|
+
case "markSpam": return [{
|
|
1150
|
+
ids,
|
|
1151
|
+
run: () => client.markSpam(ids, true)
|
|
1152
|
+
}];
|
|
1153
|
+
case "unmarkSpam": return [{
|
|
1154
|
+
ids,
|
|
1155
|
+
run: () => client.markSpam(ids, false)
|
|
1156
|
+
}];
|
|
1157
|
+
case "addLabels": {
|
|
1158
|
+
const add = [...new Set(action.labels)];
|
|
1159
|
+
return [{
|
|
1160
|
+
ids,
|
|
1161
|
+
run: () => client.updateLabels(ids, { add })
|
|
1162
|
+
}];
|
|
1163
|
+
}
|
|
1164
|
+
case "removeLabels": {
|
|
1165
|
+
const remove = [...new Set(action.labels)];
|
|
1166
|
+
return [{
|
|
1167
|
+
ids,
|
|
1168
|
+
run: () => client.updateLabels(ids, { remove })
|
|
1169
|
+
}];
|
|
1170
|
+
}
|
|
1171
|
+
case "move": {
|
|
1172
|
+
const target = destination ?? action.folder;
|
|
1173
|
+
const groups = /* @__PURE__ */ new Map();
|
|
1174
|
+
const inPlace = [];
|
|
1175
|
+
for (const [id, row] of rows) {
|
|
1176
|
+
const labels = parseLabels(row);
|
|
1177
|
+
const remove = labels.filter((label) => label !== target).sort();
|
|
1178
|
+
if (remove.length === 0 && labels.includes(target)) {
|
|
1179
|
+
inPlace.push(id);
|
|
1180
|
+
continue;
|
|
1181
|
+
}
|
|
1182
|
+
const key = JSON.stringify(remove);
|
|
1183
|
+
const group = groups.get(key) ?? {
|
|
1184
|
+
remove,
|
|
1185
|
+
ids: []
|
|
1186
|
+
};
|
|
1187
|
+
group.ids.push(id);
|
|
1188
|
+
groups.set(key, group);
|
|
1189
|
+
}
|
|
1190
|
+
const calls = [...groups.values()].map((group) => ({
|
|
1191
|
+
ids: group.ids,
|
|
1192
|
+
run: () => client.updateLabels(group.ids, {
|
|
1193
|
+
add: [target],
|
|
1194
|
+
...group.remove.length > 0 ? { remove: group.remove } : {}
|
|
1195
|
+
})
|
|
1196
|
+
}));
|
|
1197
|
+
if (inPlace.length > 0) calls.unshift({
|
|
1198
|
+
ids: inPlace,
|
|
1199
|
+
local: true,
|
|
1200
|
+
run: async () => ({
|
|
1201
|
+
updated: inPlace,
|
|
1202
|
+
failed: []
|
|
1203
|
+
})
|
|
1204
|
+
});
|
|
1205
|
+
return calls;
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
async function triageMailMessages(suppliedAccount, action, emailIds, deps) {
|
|
1210
|
+
if (!suppliedAccount.id) throw new Error("EmailAccount.triage requires a persisted account");
|
|
1211
|
+
const accountId = suppliedAccount.id;
|
|
1212
|
+
let account = suppliedAccount;
|
|
1213
|
+
assertValid(action);
|
|
1214
|
+
await assertMailAccess(account, "read");
|
|
1215
|
+
await assertMailAccess(account, "triage");
|
|
1216
|
+
const result = {
|
|
1217
|
+
action: action.kind,
|
|
1218
|
+
accountId,
|
|
1219
|
+
updated: [],
|
|
1220
|
+
failed: [],
|
|
1221
|
+
stale: []
|
|
1222
|
+
};
|
|
1223
|
+
const requested = [...new Set(emailIds)];
|
|
1224
|
+
if (requested.length === 0) return result;
|
|
1225
|
+
return inLane(accountId, async () => {
|
|
1226
|
+
const { EmailAccountCollection: AccountCollectionClass } = await Promise.resolve().then(() => EmailAccountCollection_exports);
|
|
1227
|
+
const stored = await runWithMailSystemAccess(async () => (await AccountCollectionClass.create(deps.childOptions)).get({ id: accountId }));
|
|
1228
|
+
if (!stored?.id) throw new MailAccessError("read", "denied");
|
|
1229
|
+
await assertMailAccess(stored, "read");
|
|
1230
|
+
await assertMailAccess(stored, "triage");
|
|
1231
|
+
account = stored;
|
|
1232
|
+
if (!account.isActive || !suppliedAccount.isActive) throw new Error("Mail account is inactive");
|
|
1233
|
+
if (account.needsReconnect || suppliedAccount.needsReconnect) throw new Error("Mail account needs to be reconnected");
|
|
1234
|
+
return runWithMailSystemAccess(async () => {
|
|
1235
|
+
const { EmailCollection: EmailCollectionClass } = await import("./EmailCollection-CHINTmyA.js").then((n) => n.n);
|
|
1236
|
+
const { EmailFolderCollection: FolderCollectionClass } = await import("./EmailFolderCollection-B83qLC-c.js").then((n) => n.n);
|
|
1237
|
+
const emails = await EmailCollectionClass.create(deps.childOptions);
|
|
1238
|
+
const folders = await FolderCollectionClass.create(deps.childOptions);
|
|
1239
|
+
const rows = /* @__PURE__ */ new Map();
|
|
1240
|
+
const byLocalId = /* @__PURE__ */ new Map();
|
|
1241
|
+
for (const id of requested) {
|
|
1242
|
+
const row = await emails.get({ id });
|
|
1243
|
+
if (!row || row.accountId !== accountId) result.failed.push({
|
|
1244
|
+
id,
|
|
1245
|
+
code: "notFound"
|
|
1246
|
+
});
|
|
1247
|
+
else if (!row.providerMessageId) result.failed.push({
|
|
1248
|
+
id,
|
|
1249
|
+
code: "notSynced",
|
|
1250
|
+
message: "The message has not been synced from the server yet"
|
|
1251
|
+
});
|
|
1252
|
+
else if (rows.has(row.providerMessageId)) result.failed.push({
|
|
1253
|
+
id,
|
|
1254
|
+
code: "duplicate",
|
|
1255
|
+
message: "Another selected row has the same server id"
|
|
1256
|
+
});
|
|
1257
|
+
else {
|
|
1258
|
+
rows.set(row.providerMessageId, row);
|
|
1259
|
+
byLocalId.set(id, row);
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
const client = await deps.createClient(account);
|
|
1263
|
+
try {
|
|
1264
|
+
await client.connect();
|
|
1265
|
+
requireCapability(action.kind, client, await client.getCapabilities(), account.providerType);
|
|
1266
|
+
if (rows.size === 0) return result;
|
|
1267
|
+
const destination = action.kind === "move" ? await resolveMailbox(folders, accountId, action.folder) : null;
|
|
1268
|
+
const ctx = {
|
|
1269
|
+
account,
|
|
1270
|
+
accountId,
|
|
1271
|
+
emails,
|
|
1272
|
+
folders,
|
|
1273
|
+
childOptions: deps.childOptions,
|
|
1274
|
+
folderIds: /* @__PURE__ */ new Map()
|
|
1275
|
+
};
|
|
1276
|
+
const touched = /* @__PURE__ */ new Set();
|
|
1277
|
+
const accepted = /* @__PURE__ */ new Set();
|
|
1278
|
+
const calls = plan(action, client, rows, destination);
|
|
1279
|
+
let firstError;
|
|
1280
|
+
let authError;
|
|
1281
|
+
let completed = 0;
|
|
1282
|
+
for (const call of calls) {
|
|
1283
|
+
let outcome;
|
|
1284
|
+
if (authError) {
|
|
1285
|
+
outcome = {
|
|
1286
|
+
updated: [],
|
|
1287
|
+
failed: []
|
|
1288
|
+
};
|
|
1289
|
+
for (const id of call.ids) outcome.failed.push({
|
|
1290
|
+
id,
|
|
1291
|
+
code: "skipped",
|
|
1292
|
+
message: "Not attempted: the server refused the sign-in"
|
|
1293
|
+
});
|
|
1294
|
+
} else try {
|
|
1295
|
+
outcome = await call.run();
|
|
1296
|
+
if (!call.local) completed++;
|
|
1297
|
+
} catch (error) {
|
|
1298
|
+
firstError ??= error;
|
|
1299
|
+
if (deps.isAuthFailure(error)) authError = error;
|
|
1300
|
+
outcome = {
|
|
1301
|
+
updated: [],
|
|
1302
|
+
failed: []
|
|
1303
|
+
};
|
|
1304
|
+
for (const id of call.ids) outcome.failed.push({
|
|
1305
|
+
id,
|
|
1306
|
+
code: "serverError",
|
|
1307
|
+
message: "The server call failed before reporting an outcome"
|
|
1308
|
+
});
|
|
1309
|
+
}
|
|
1310
|
+
const wanted = new Set(call.ids);
|
|
1311
|
+
const settled = /* @__PURE__ */ new Set();
|
|
1312
|
+
for (const providerId of outcome.updated) {
|
|
1313
|
+
if (!wanted.has(providerId) || settled.has(providerId)) continue;
|
|
1314
|
+
settled.add(providerId);
|
|
1315
|
+
accepted.add(providerId);
|
|
1316
|
+
}
|
|
1317
|
+
for (const failure of outcome.failed) {
|
|
1318
|
+
const row = rows.get(failure.id);
|
|
1319
|
+
if (!row?.id || settled.has(failure.id) || !wanted.has(failure.id)) continue;
|
|
1320
|
+
settled.add(failure.id);
|
|
1321
|
+
result.failed.push({
|
|
1322
|
+
id: row.id,
|
|
1323
|
+
code: failure.code,
|
|
1324
|
+
...failure.message ? { message: failure.message } : {}
|
|
1325
|
+
});
|
|
1326
|
+
}
|
|
1327
|
+
for (const providerId of call.ids) {
|
|
1328
|
+
if (settled.has(providerId)) continue;
|
|
1329
|
+
const row = rows.get(providerId);
|
|
1330
|
+
if (!row?.id) continue;
|
|
1331
|
+
result.failed.push({
|
|
1332
|
+
id: row.id,
|
|
1333
|
+
code: "unknown",
|
|
1334
|
+
message: "Server did not report an outcome for this message"
|
|
1335
|
+
});
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
let readBackAuthError;
|
|
1339
|
+
for (const providerId of accepted) {
|
|
1340
|
+
const row = rows.get(providerId);
|
|
1341
|
+
if (!row?.id) continue;
|
|
1342
|
+
if (readBackAuthError) {
|
|
1343
|
+
result.stale.push(row.id);
|
|
1344
|
+
continue;
|
|
1345
|
+
}
|
|
1346
|
+
try {
|
|
1347
|
+
if (row.folderId) touched.add(row.folderId);
|
|
1348
|
+
const fresh = await client.getMessage(providerId);
|
|
1349
|
+
const folderPath = fresh.folder ?? fresh.folders?.[0] ?? "";
|
|
1350
|
+
const folderId = folderPath ? await folderIdFor(ctx, folderPath) : "";
|
|
1351
|
+
applyServerMessage(row, withMailboxLabels(fresh), {
|
|
1352
|
+
folderId,
|
|
1353
|
+
folderPath
|
|
1354
|
+
}, {
|
|
1355
|
+
keepBodies: true,
|
|
1356
|
+
deriveState: true
|
|
1357
|
+
});
|
|
1358
|
+
await row.save();
|
|
1359
|
+
if (folderId) touched.add(folderId);
|
|
1360
|
+
result.updated.push(row.id);
|
|
1361
|
+
} catch (error) {
|
|
1362
|
+
result.stale.push(row.id);
|
|
1363
|
+
if (deps.isAuthFailure(error)) readBackAuthError = error;
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
if (touched.size > 0) await refreshCounts(ctx, touched).catch(() => {});
|
|
1367
|
+
if (firstError && completed === 0) throw firstError;
|
|
1368
|
+
const lateAuthError = authError ?? readBackAuthError;
|
|
1369
|
+
if (lateAuthError) {
|
|
1370
|
+
const err = lateAuthError instanceof Error ? lateAuthError : new Error(String(lateAuthError));
|
|
1371
|
+
await account.markNeedsReconnect(err.message).catch(() => void 0);
|
|
1372
|
+
result.needsReconnect = true;
|
|
1373
|
+
}
|
|
1374
|
+
return result;
|
|
1375
|
+
} catch (error) {
|
|
1376
|
+
return rethrowAfterAuthCheck(account, error, deps.isAuthFailure);
|
|
1377
|
+
} finally {
|
|
1378
|
+
await client.disconnect().catch(() => void 0);
|
|
1379
|
+
}
|
|
1380
|
+
});
|
|
1381
|
+
});
|
|
1382
|
+
}
|
|
1383
|
+
//#endregion
|
|
1384
|
+
//#region src/collections/AccountCollection.ts
|
|
1385
|
+
var AccountCollection_exports = /* @__PURE__ */ __exportAll({ AccountCollection: () => AccountCollection });
|
|
1386
|
+
var AccountCollection = class extends SmrtCollection {
|
|
1387
|
+
static _itemClass = Account;
|
|
1388
|
+
/**
|
|
1389
|
+
* Get active accounts
|
|
1390
|
+
*/
|
|
1391
|
+
async getActive() {
|
|
1392
|
+
return await this.list({ where: { isActive: true } });
|
|
1393
|
+
}
|
|
1394
|
+
/**
|
|
1395
|
+
* Get inactive accounts
|
|
1396
|
+
*/
|
|
1397
|
+
async getInactive() {
|
|
1398
|
+
return await this.list({ where: { isActive: false } });
|
|
1399
|
+
}
|
|
1400
|
+
/**
|
|
1401
|
+
* Get accounts by provider type
|
|
1402
|
+
*/
|
|
1403
|
+
async getByProviderType(providerType) {
|
|
1404
|
+
return await this.list({ where: { providerType } });
|
|
1405
|
+
}
|
|
1406
|
+
/**
|
|
1407
|
+
* Get accounts by STI type.
|
|
1408
|
+
*
|
|
1409
|
+
* Accepts either the full discriminator (e.g. "@happyvertical/smrt-messages:EmailAccount")
|
|
1410
|
+
* or the short type name (e.g. "EmailAccount").
|
|
1411
|
+
*/
|
|
1412
|
+
async getByType(accountType) {
|
|
1413
|
+
if (accountType.includes(":") || accountType.startsWith("@")) return await this.list({ where: { _meta_type: accountType } });
|
|
1414
|
+
return (await this.list({})).filter((a) => {
|
|
1415
|
+
return (a._meta_type || "").endsWith(`:${accountType}`);
|
|
1416
|
+
});
|
|
1417
|
+
}
|
|
1418
|
+
/**
|
|
1419
|
+
* Search accounts with filters
|
|
1420
|
+
*/
|
|
1421
|
+
async search(query, filters) {
|
|
1422
|
+
let accounts = await this.list({});
|
|
1423
|
+
if (query) {
|
|
1424
|
+
const lowerQuery = query.toLowerCase();
|
|
1425
|
+
accounts = accounts.filter((a) => a.name?.toLowerCase().includes(lowerQuery));
|
|
1426
|
+
}
|
|
1427
|
+
if (filters) {
|
|
1428
|
+
if (filters.providerType) accounts = accounts.filter((a) => a.providerType === filters.providerType);
|
|
1429
|
+
if (filters.isActive !== void 0) accounts = accounts.filter((a) => a.isActive === filters.isActive);
|
|
1430
|
+
if (filters.accountType) accounts = accounts.filter((a) => {
|
|
1431
|
+
return (a._meta_type || "").includes(filters.accountType);
|
|
1432
|
+
});
|
|
1433
|
+
}
|
|
1434
|
+
return accounts;
|
|
1435
|
+
}
|
|
1436
|
+
/**
|
|
1437
|
+
* Get account statistics
|
|
1438
|
+
*/
|
|
1439
|
+
async getStats() {
|
|
1440
|
+
const accounts = await this.list({});
|
|
1441
|
+
const byType = {};
|
|
1442
|
+
for (const account of accounts) {
|
|
1443
|
+
const metaType = account._meta_type || "Unknown";
|
|
1444
|
+
const shortType = metaType.split(":").pop() || metaType;
|
|
1445
|
+
byType[shortType] = (byType[shortType] || 0) + 1;
|
|
1446
|
+
}
|
|
1447
|
+
return {
|
|
1448
|
+
total: accounts.length,
|
|
1449
|
+
active: accounts.filter((a) => a.isActive).length,
|
|
1450
|
+
inactive: accounts.filter((a) => !a.isActive).length,
|
|
1451
|
+
byType
|
|
1452
|
+
};
|
|
1453
|
+
}
|
|
1454
|
+
async findByTenant(tenantId) {
|
|
1455
|
+
return this.list({ where: { tenantId } });
|
|
1456
|
+
}
|
|
1457
|
+
async findGlobal() {
|
|
1458
|
+
return queryGlobal(this);
|
|
1459
|
+
}
|
|
1460
|
+
async findWithGlobals(tenantId) {
|
|
1461
|
+
return queryWithGlobals(this, tenantId, "Account.findWithGlobals");
|
|
1462
|
+
}
|
|
1463
|
+
};
|
|
1464
|
+
//#endregion
|
|
1465
|
+
//#region src/models/EmailAccount.ts
|
|
1466
|
+
var __defProp = Object.defineProperty;
|
|
1467
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
1468
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
1469
|
+
enumerable: true,
|
|
1470
|
+
configurable: true,
|
|
1471
|
+
writable: true,
|
|
1472
|
+
value
|
|
1473
|
+
}) : obj[key] = value;
|
|
1474
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
1475
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
1476
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--) if (decorator = decorators[i]) result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
1477
|
+
if (kind && result) __defProp(target, key, result);
|
|
1478
|
+
return result;
|
|
1479
|
+
};
|
|
1480
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1481
|
+
function isMailAuthFailure(error) {
|
|
1482
|
+
const code = error?.code;
|
|
1483
|
+
if (code === "EAUTH" || code === "AUTHENTICATIONFAILED") return true;
|
|
1484
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1485
|
+
return /\b(auth(entication|orization)?\s*(failed|failure|error)|invalid credentials|login failed|unauthori[sz]ed|401|invalid_grant)\b/i.test(message);
|
|
1486
|
+
}
|
|
1487
|
+
var EmailAccount = class extends Account {
|
|
1488
|
+
email = "";
|
|
1489
|
+
syncIntervalMinutes = 60;
|
|
1490
|
+
syncCursor = null;
|
|
1491
|
+
backfillSince = null;
|
|
1492
|
+
cursorHorizon = null;
|
|
1493
|
+
lastSyncError = null;
|
|
1494
|
+
backlog = false;
|
|
1495
|
+
constructor(options = {}) {
|
|
1496
|
+
super(options);
|
|
1497
|
+
if (options.email !== void 0) this.email = options.email;
|
|
1498
|
+
if (options.providerType !== void 0) this.providerType = options.providerType;
|
|
1499
|
+
if (options.syncIntervalMinutes !== void 0) this.syncIntervalMinutes = options.syncIntervalMinutes;
|
|
1500
|
+
if (options.syncCursor !== void 0) this.syncCursor = options.syncCursor || null;
|
|
1501
|
+
if (options.backfillSince !== void 0) this.backfillSince = options.backfillSince || null;
|
|
1502
|
+
if (options.cursorHorizon !== void 0) this.cursorHorizon = options.cursorHorizon || null;
|
|
1503
|
+
if (options.lastSyncError !== void 0) this.lastSyncError = options.lastSyncError || null;
|
|
1504
|
+
if (options.backlog !== void 0) this.backlog = options.backlog;
|
|
1505
|
+
this.channelType = "email";
|
|
1506
|
+
}
|
|
1507
|
+
/**
|
|
1508
|
+
* Options for child rows (folders/emails) created during sync: carries the DB
|
|
1509
|
+
* connection + tenant context from this account, but strips this account's own
|
|
1510
|
+
* identity fields. When this account was hydrated from the DB, `this.options`
|
|
1511
|
+
* holds the account row's `id`/`slug`/`_skipLoad`; spreading those into a new
|
|
1512
|
+
* child would make every synced row inherit the account's primary key and
|
|
1513
|
+
* upsert over each other. Internal: the mail sync engine reuses it.
|
|
1514
|
+
*/
|
|
1515
|
+
childOptions() {
|
|
1516
|
+
const rest = { ...this.options };
|
|
1517
|
+
delete rest.id;
|
|
1518
|
+
delete rest.slug;
|
|
1519
|
+
delete rest._skipLoad;
|
|
1520
|
+
return rest;
|
|
1521
|
+
}
|
|
1522
|
+
/**
|
|
1523
|
+
* Create a sender for this email account
|
|
1524
|
+
*/
|
|
1525
|
+
async createSender() {
|
|
1526
|
+
const client = await this.createClient();
|
|
1527
|
+
await client.connect();
|
|
1528
|
+
const { EmailSender } = await import("./EmailSender-B-Rtq9du.js").then((n) => n.n);
|
|
1529
|
+
return new EmailSender(client, this);
|
|
1530
|
+
}
|
|
1531
|
+
/**
|
|
1532
|
+
* Create an EmailClient from stored settings
|
|
1533
|
+
* Retrieves credentials from smrt-secrets if credentialSecretId is set
|
|
1534
|
+
*
|
|
1535
|
+
* The client factory comes from the messaging provider registry rather than
|
|
1536
|
+
* a direct `@happyvertical/email` import so the email SDK
|
|
1537
|
+
* (googleapis/nodemailer) never becomes reachable from provider-neutral
|
|
1538
|
+
* consumer bundles (#1979). Server code that uses email accounts must
|
|
1539
|
+
* import '@happyvertical/smrt-messages/providers/email' (or
|
|
1540
|
+
* '/providers/all') once during startup.
|
|
1541
|
+
*/
|
|
1542
|
+
async createClient() {
|
|
1543
|
+
const { getMessagingProvider } = await import("./providers-Bz_F_ywF.js").then((n) => n.i);
|
|
1544
|
+
const createEmailClient = getMessagingProvider(this.providerType)?.createEmailClient;
|
|
1545
|
+
if (!createEmailClient) throw new Error(`Email provider '${this.providerType}' has no client implementation registered. Import '@happyvertical/smrt-messages/providers/email' (or '/providers/all') during server startup to enable outbound email and mailbox sync.`);
|
|
1546
|
+
const settings = {
|
|
1547
|
+
...this.getConfiguration(),
|
|
1548
|
+
...await this.getCredentials() ?? {}
|
|
1549
|
+
};
|
|
1550
|
+
delete settings.email;
|
|
1551
|
+
if (this.providerType === "jmap") {
|
|
1552
|
+
const { token, username, password } = settings;
|
|
1553
|
+
for (const key of [
|
|
1554
|
+
"token",
|
|
1555
|
+
"username",
|
|
1556
|
+
"password"
|
|
1557
|
+
]) delete settings[key];
|
|
1558
|
+
if (settings.auth === void 0) {
|
|
1559
|
+
if (typeof token === "string" && token) settings.auth = {
|
|
1560
|
+
type: "bearer",
|
|
1561
|
+
token
|
|
1562
|
+
};
|
|
1563
|
+
else if (typeof username === "string" && typeof password === "string") settings.auth = {
|
|
1564
|
+
user: username,
|
|
1565
|
+
pass: password
|
|
1566
|
+
};
|
|
1567
|
+
}
|
|
1568
|
+
}
|
|
1569
|
+
return await createEmailClient({
|
|
1570
|
+
type: this.providerType,
|
|
1571
|
+
...settings
|
|
1572
|
+
});
|
|
1573
|
+
}
|
|
1574
|
+
/**
|
|
1575
|
+
* Read an immutable body/attachment-byte snapshot for an authorized intake host.
|
|
1576
|
+
* Does not sync, acknowledge, mark read or advance mailbox checkpoints.
|
|
1577
|
+
* Metadata-only providers fail explicitly; provider paths are never dereferenced.
|
|
1578
|
+
*/
|
|
1579
|
+
async readIntakeMessage(locator, maxBytes, imapIdentity) {
|
|
1580
|
+
if (!this.id || !this.isActive || !locator) throw new Error("Email intake account unavailable");
|
|
1581
|
+
const client = await this.createClient();
|
|
1582
|
+
try {
|
|
1583
|
+
await client.connect();
|
|
1584
|
+
if (this.providerType === "imap") {
|
|
1585
|
+
if (!imapIdentity?.folder || !imapIdentity.uid || !Number.isSafeInteger(imapIdentity.uidValidity)) throw new Error("IMAP intake requires folder and immutable UID identity");
|
|
1586
|
+
if ((await client.selectFolder(imapIdentity.folder)).uidValidity !== imapIdentity.uidValidity) throw new Error("IMAP intake identity changed");
|
|
1587
|
+
}
|
|
1588
|
+
const message = await client.getMessage(locator);
|
|
1589
|
+
if (this.providerType === "imap" && message.id !== imapIdentity?.uid) throw new Error("IMAP intake identity changed");
|
|
1590
|
+
const { snapshotEmailForIntake } = await import("./intake-snapshot-B03bDtSW.js");
|
|
1591
|
+
return snapshotEmailForIntake(this.id, message, maxBytes);
|
|
1592
|
+
} finally {
|
|
1593
|
+
await client.disconnect();
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
/**
|
|
1597
|
+
* Sync emails from the email server to the database
|
|
1598
|
+
*/
|
|
1599
|
+
async syncFrom(options = {}) {
|
|
1600
|
+
return runWithMailSystemAccess(() => this.syncFromScoped(options));
|
|
1601
|
+
}
|
|
1602
|
+
async syncFromScoped(options) {
|
|
1603
|
+
const startTime = Date.now();
|
|
1604
|
+
const result = {
|
|
1605
|
+
folders: [],
|
|
1606
|
+
messagesProcessed: 0,
|
|
1607
|
+
messagesDownloaded: 0,
|
|
1608
|
+
messagesSkipped: 0,
|
|
1609
|
+
errors: [],
|
|
1610
|
+
duration: 0
|
|
1611
|
+
};
|
|
1612
|
+
try {
|
|
1613
|
+
const client = await this.createClient();
|
|
1614
|
+
await client.connect();
|
|
1615
|
+
const foldersToSync = options.folders || ["INBOX"];
|
|
1616
|
+
result.folders = foldersToSync;
|
|
1617
|
+
const { EmailCollection } = await import("./EmailCollection-CHINTmyA.js").then((n) => n.n);
|
|
1618
|
+
const { EmailFolderCollection } = await import("./EmailFolderCollection-B83qLC-c.js").then((n) => n.n);
|
|
1619
|
+
const emailCollection = await EmailCollection.create(this.options);
|
|
1620
|
+
const folderCollection = await EmailFolderCollection.create(this.options);
|
|
1621
|
+
if (!this.id) throw new Error("EmailAccount.syncFrom requires a persisted account (missing id)");
|
|
1622
|
+
const accountId = this.id;
|
|
1623
|
+
for (const folderName of foldersToSync) try {
|
|
1624
|
+
let folder = await folderCollection.getByPath(accountId, folderName);
|
|
1625
|
+
if (!folder) {
|
|
1626
|
+
const { EmailFolder } = await import("./EmailFolder-C_H8u6bS.js").then((n) => n.n);
|
|
1627
|
+
folder = new (ObjectRegistry.resolveEffectiveConstructor(EmailFolder))({
|
|
1628
|
+
...this.childOptions(),
|
|
1629
|
+
accountId,
|
|
1630
|
+
name: folderName,
|
|
1631
|
+
path: folderName
|
|
1632
|
+
});
|
|
1633
|
+
await folder.initialize();
|
|
1634
|
+
await folder.save();
|
|
1635
|
+
}
|
|
1636
|
+
const fetchOptions = {
|
|
1637
|
+
folder: folderName,
|
|
1638
|
+
limit: options.batchSize || 100
|
|
1639
|
+
};
|
|
1640
|
+
if (options.since) fetchOptions.since = options.since;
|
|
1641
|
+
if (options.before) fetchOptions.before = options.before;
|
|
1642
|
+
const messages = await client.fetch(fetchOptions);
|
|
1643
|
+
for (const msg of messages) {
|
|
1644
|
+
result.messagesProcessed++;
|
|
1645
|
+
try {
|
|
1646
|
+
const existingEmail = await emailCollection.getByMessageId(accountId, msg.messageId || "");
|
|
1647
|
+
if (existingEmail && !options.fullSync) {
|
|
1648
|
+
result.messagesSkipped++;
|
|
1649
|
+
continue;
|
|
1650
|
+
}
|
|
1651
|
+
const { Email } = await import("./Email---ifczUW.js").then((n) => n.n);
|
|
1652
|
+
let email = existingEmail;
|
|
1653
|
+
if (!email) {
|
|
1654
|
+
email = new (ObjectRegistry.resolveEffectiveConstructor(Email))({
|
|
1655
|
+
...this.childOptions(),
|
|
1656
|
+
accountId
|
|
1657
|
+
});
|
|
1658
|
+
await email.initialize();
|
|
1659
|
+
}
|
|
1660
|
+
applyServerMessage(email, msg, {
|
|
1661
|
+
folderId: folder.id ?? "",
|
|
1662
|
+
folderPath: folderName
|
|
1663
|
+
});
|
|
1664
|
+
await email.save();
|
|
1665
|
+
result.messagesDownloaded++;
|
|
1666
|
+
if (options.onProgress) options.onProgress({
|
|
1667
|
+
folder: folderName,
|
|
1668
|
+
processed: result.messagesProcessed,
|
|
1669
|
+
total: messages.length,
|
|
1670
|
+
downloaded: result.messagesDownloaded,
|
|
1671
|
+
skipped: result.messagesSkipped,
|
|
1672
|
+
errors: result.errors.length
|
|
1673
|
+
});
|
|
1674
|
+
} catch (error) {
|
|
1675
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
1676
|
+
result.errors.push(err);
|
|
1677
|
+
if (options.onError) options.onError(err, msg);
|
|
1678
|
+
}
|
|
1679
|
+
}
|
|
1680
|
+
const folderId = folder.id ?? "";
|
|
1681
|
+
folder.messageCount = await emailCollection.countByFolder(folderId);
|
|
1682
|
+
folder.unreadCount = await emailCollection.countUnreadByFolder(folderId);
|
|
1683
|
+
await folder.save();
|
|
1684
|
+
} catch (error) {
|
|
1685
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
1686
|
+
result.errors.push(err);
|
|
1687
|
+
if (options.onError) options.onError(err);
|
|
1688
|
+
}
|
|
1689
|
+
this.lastSyncAt = /* @__PURE__ */ new Date();
|
|
1690
|
+
if (!result.errors.length) {
|
|
1691
|
+
this.connectionStatus = "connected";
|
|
1692
|
+
this.statusMessage = null;
|
|
1693
|
+
}
|
|
1694
|
+
this.updatedAt = /* @__PURE__ */ new Date();
|
|
1695
|
+
await this.save();
|
|
1696
|
+
await client.disconnect();
|
|
1697
|
+
} catch (error) {
|
|
1698
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
1699
|
+
result.errors.push(err);
|
|
1700
|
+
if (isMailAuthFailure(err)) try {
|
|
1701
|
+
await this.markNeedsReconnect(err.message);
|
|
1702
|
+
} catch {}
|
|
1703
|
+
if (options.onError) options.onError(err);
|
|
1704
|
+
}
|
|
1705
|
+
result.duration = Date.now() - startTime;
|
|
1706
|
+
return result;
|
|
1707
|
+
}
|
|
1708
|
+
/**
|
|
1709
|
+
* Sync new, changed and deleted mail since the last run, from the server's
|
|
1710
|
+
* change feed (JMAP). The feed cursor is saved on `syncCursor` only after
|
|
1711
|
+
* each batch has been applied; replaying a batch is harmless; a rejected
|
|
1712
|
+
* cursor restarts with a full pass. One run per account at a time.
|
|
1713
|
+
*
|
|
1714
|
+
* Closed accounts (inactive, or needing reconnection) are skipped. A server
|
|
1715
|
+
* that refuses the sign-in marks the account `needs_reconnect` and throws an
|
|
1716
|
+
* error flagged `retryable: false`. Every other failure throws and leaves the
|
|
1717
|
+
* cursor where it was, so the job can simply retry.
|
|
1718
|
+
*
|
|
1719
|
+
* This is the method the sync job runs (`enqueueMailSync`).
|
|
1720
|
+
*/
|
|
1721
|
+
async syncChanges(options = {}) {
|
|
1722
|
+
return runWithMailSystemAccess(async () => {
|
|
1723
|
+
const { syncMailChanges } = await Promise.resolve().then(() => mail_sync_exports);
|
|
1724
|
+
return syncMailChanges(this, options, {
|
|
1725
|
+
createClient: (account) => account.createClient(),
|
|
1726
|
+
childOptions: this.childOptions(),
|
|
1727
|
+
isAuthFailure: isMailAuthFailure
|
|
1728
|
+
});
|
|
1729
|
+
});
|
|
1730
|
+
}
|
|
1731
|
+
/**
|
|
1732
|
+
* Triage synced messages: mark read or unread, star, archive, spam, label or
|
|
1733
|
+
* move. `emailIds` are local `Email` row ids of this account.
|
|
1734
|
+
*
|
|
1735
|
+
* Needs the `read` and `triage` scopes on this account (`MailAccessError`
|
|
1736
|
+
* otherwise, nothing sent or changed). The change is written to the mail
|
|
1737
|
+
* server first; only messages the server accepted are updated locally, and
|
|
1738
|
+
* the rest come back in `failed` with the server's reason. A provider
|
|
1739
|
+
* without the matching write-back capability throws
|
|
1740
|
+
* `MailWriteBackUnsupportedError`. Repeating a call changes nothing.
|
|
1741
|
+
*
|
|
1742
|
+
* Local rows are stored as the server reports them after the change, so the
|
|
1743
|
+
* next sync agrees with them. See `mail-triage.ts`.
|
|
1744
|
+
*/
|
|
1745
|
+
async triage(action, emailIds) {
|
|
1746
|
+
return triageMailMessages(this, action, emailIds, {
|
|
1747
|
+
createClient: (account) => account.createClient(),
|
|
1748
|
+
childOptions: this.childOptions(),
|
|
1749
|
+
isAuthFailure: isMailAuthFailure
|
|
1750
|
+
});
|
|
1751
|
+
}
|
|
1752
|
+
/**
|
|
1753
|
+
* Every message in one server-side conversation, oldest first, read straight
|
|
1754
|
+
* from the mail server (providers with native threads, such as JMAP).
|
|
1755
|
+
* Returns null when the provider has no thread lookup.
|
|
1756
|
+
*/
|
|
1757
|
+
async fetchThread(threadId) {
|
|
1758
|
+
const client = await this.createClient();
|
|
1759
|
+
try {
|
|
1760
|
+
await client.connect();
|
|
1761
|
+
if (typeof client.getThread !== "function") return null;
|
|
1762
|
+
return await client.getThread(threadId);
|
|
1763
|
+
} finally {
|
|
1764
|
+
await client.disconnect().catch(() => void 0);
|
|
1765
|
+
}
|
|
1766
|
+
}
|
|
1767
|
+
/**
|
|
1768
|
+
* Get all folders for this account
|
|
1769
|
+
*/
|
|
1770
|
+
async getFolders() {
|
|
1771
|
+
const { EmailFolderCollection } = await import("./EmailFolderCollection-B83qLC-c.js").then((n) => n.n);
|
|
1772
|
+
return await (await EmailFolderCollection.create(this.options)).list({ where: { accountId: this.id } });
|
|
1773
|
+
}
|
|
1774
|
+
/**
|
|
1775
|
+
* Get all emails for this account
|
|
1776
|
+
*/
|
|
1777
|
+
async getEmails(limit) {
|
|
1778
|
+
const { EmailCollection } = await import("./EmailCollection-CHINTmyA.js").then((n) => n.n);
|
|
1779
|
+
const collection = await EmailCollection.create(this.options);
|
|
1780
|
+
const options = { where: { accountId: this.id } };
|
|
1781
|
+
if (limit) options.limit = limit;
|
|
1782
|
+
return await collection.list(options);
|
|
1783
|
+
}
|
|
1784
|
+
/**
|
|
1785
|
+
* Get unread email count
|
|
1786
|
+
*/
|
|
1787
|
+
async getUnreadCount() {
|
|
1788
|
+
const { EmailCollection } = await import("./EmailCollection-CHINTmyA.js").then((n) => n.n);
|
|
1789
|
+
return await (await EmailCollection.create(this.options)).countUnreadByAccount(this.id ?? "");
|
|
1790
|
+
}
|
|
1791
|
+
/**
|
|
1792
|
+
* Store credentials securely using smrt-secrets (email-specific)
|
|
1793
|
+
*/
|
|
1794
|
+
async setCredentials(credentials, options = {}) {
|
|
1795
|
+
await super.setCredentials(credentials, {
|
|
1796
|
+
description: options.description || `Email credentials for ${this.name}`,
|
|
1797
|
+
category: options.category || "email"
|
|
1798
|
+
});
|
|
1799
|
+
}
|
|
1800
|
+
/**
|
|
1801
|
+
* Sync all active email accounts (for job runner)
|
|
1802
|
+
*
|
|
1803
|
+
* NOTE: This is a class-wide operation, not per-instance. It syncs ALL active
|
|
1804
|
+
* accounts, ignoring `this` instance. It exists as an instance method because
|
|
1805
|
+
* the TaskRunner dispatches via `objectType: 'EmailAccount', method: 'syncAll'`
|
|
1806
|
+
* which requires an instance method signature.
|
|
1807
|
+
*/
|
|
1808
|
+
async syncAll(args) {
|
|
1809
|
+
const { EmailAccountCollection } = await Promise.resolve().then(() => EmailAccountCollection_exports);
|
|
1810
|
+
return (await EmailAccountCollection.create({ db: this.db })).syncAll(args);
|
|
1811
|
+
}
|
|
1812
|
+
/**
|
|
1813
|
+
* Migrate from plain-text settings to secrets
|
|
1814
|
+
*/
|
|
1815
|
+
async migrateToSecrets() {
|
|
1816
|
+
if (this.credentialSecretId) return;
|
|
1817
|
+
const settings = this.getSettings();
|
|
1818
|
+
if (Object.keys(settings).length === 0) return;
|
|
1819
|
+
await this.setCredentials(settings, { description: `Migrated IMAP credentials for ${this.name}` });
|
|
1820
|
+
}
|
|
1821
|
+
};
|
|
1822
|
+
__publicField(EmailAccount, "__smrtPackage__", "@happyvertical/smrt-messages");
|
|
1823
|
+
__decorateClass([field({ description: "The email address associated with this mailbox." })], EmailAccount.prototype, "email", 2);
|
|
1824
|
+
__decorateClass([field({ description: "The time in minutes between scheduled mailbox checks." })], EmailAccount.prototype, "syncIntervalMinutes", 2);
|
|
1825
|
+
__decorateClass([field({
|
|
1826
|
+
sensitive: true,
|
|
1827
|
+
readonly: true,
|
|
1828
|
+
description: "Where the next mailbox check resumes."
|
|
1829
|
+
})], EmailAccount.prototype, "syncCursor", 2);
|
|
1830
|
+
__decorateClass([field({ description: "Mail older than this date is not stored. Empty means the whole mailbox." })], EmailAccount.prototype, "backfillSince", 2);
|
|
1831
|
+
__decorateClass([field({
|
|
1832
|
+
readonly: true,
|
|
1833
|
+
description: "The backfill date the saved mailbox position was built under."
|
|
1834
|
+
})], EmailAccount.prototype, "cursorHorizon", 2);
|
|
1835
|
+
__decorateClass([field({ description: "Why the last mailbox check failed, if it did." })], EmailAccount.prototype, "lastSyncError", 2);
|
|
1836
|
+
__decorateClass([field({ description: "Whether more mail was still waiting after the last check." })], EmailAccount.prototype, "backlog", 2);
|
|
1837
|
+
EmailAccount = __decorateClass([smrt({
|
|
1838
|
+
tableStrategy: "sti",
|
|
1839
|
+
api: { include: ["list", "get"] },
|
|
1840
|
+
mcp: { include: ["list", "get"] },
|
|
1841
|
+
cli: { include: ["list", "get"] }
|
|
1842
|
+
})], EmailAccount);
|
|
1843
|
+
//#endregion
|
|
1844
|
+
//#region src/collections/EmailAccountCollection.ts
|
|
1845
|
+
var EmailAccountCollection_exports = /* @__PURE__ */ __exportAll({ EmailAccountCollection: () => EmailAccountCollection });
|
|
1846
|
+
var EmailAccountCollection = class extends AccountCollection {
|
|
1847
|
+
static _itemClass = EmailAccount;
|
|
1848
|
+
/**
|
|
1849
|
+
* Get account by email address
|
|
1850
|
+
*/
|
|
1851
|
+
async getByEmail(email) {
|
|
1852
|
+
return (await this.list({ where: { email } }))[0] || null;
|
|
1853
|
+
}
|
|
1854
|
+
/**
|
|
1855
|
+
* Get accounts by email provider type
|
|
1856
|
+
*/
|
|
1857
|
+
async getByEmailProviderType(providerType) {
|
|
1858
|
+
return await this.list({ where: { providerType } });
|
|
1859
|
+
}
|
|
1860
|
+
/**
|
|
1861
|
+
* Get active email accounts
|
|
1862
|
+
*/
|
|
1863
|
+
async getActive() {
|
|
1864
|
+
return await this.list({ where: { isActive: true } });
|
|
1865
|
+
}
|
|
1866
|
+
/**
|
|
1867
|
+
* Get inactive email accounts
|
|
1868
|
+
*/
|
|
1869
|
+
async getInactive() {
|
|
1870
|
+
return await this.list({ where: { isActive: false } });
|
|
1871
|
+
}
|
|
1872
|
+
/**
|
|
1873
|
+
* Get accounts that need syncing
|
|
1874
|
+
*/
|
|
1875
|
+
async getNeedingSync(maxAgeMinutes = 60) {
|
|
1876
|
+
const allAccounts = await this.getActive();
|
|
1877
|
+
const cutoffTime = /* @__PURE__ */ new Date(Date.now() - maxAgeMinutes * 60 * 1e3);
|
|
1878
|
+
return allAccounts.filter((account) => !account.lastSyncAt || account.lastSyncAt < cutoffTime);
|
|
1879
|
+
}
|
|
1880
|
+
/**
|
|
1881
|
+
* Search email accounts with filters.
|
|
1882
|
+
* Alias: `search()` for backward compatibility.
|
|
1883
|
+
*/
|
|
1884
|
+
async search(query, filters) {
|
|
1885
|
+
return this.searchEmailAccounts(query, filters);
|
|
1886
|
+
}
|
|
1887
|
+
/**
|
|
1888
|
+
* Get accounts by email provider type.
|
|
1889
|
+
* Alias: `getByProviderType()` for backward compatibility.
|
|
1890
|
+
*/
|
|
1891
|
+
async getByProviderType(providerType) {
|
|
1892
|
+
return this.getByEmailProviderType(providerType);
|
|
1893
|
+
}
|
|
1894
|
+
/**
|
|
1895
|
+
* Get email account statistics.
|
|
1896
|
+
* Alias: `getStats()` for backward compatibility.
|
|
1897
|
+
*/
|
|
1898
|
+
async getStats() {
|
|
1899
|
+
const stats = await this.getEmailStats();
|
|
1900
|
+
return {
|
|
1901
|
+
total: stats.total,
|
|
1902
|
+
active: stats.active,
|
|
1903
|
+
inactive: stats.inactive,
|
|
1904
|
+
byType: stats.byProvider
|
|
1905
|
+
};
|
|
1906
|
+
}
|
|
1907
|
+
/**
|
|
1908
|
+
* Search email accounts with filters
|
|
1909
|
+
*/
|
|
1910
|
+
async searchEmailAccounts(query, filters) {
|
|
1911
|
+
let accounts = await this.list({});
|
|
1912
|
+
if (query) {
|
|
1913
|
+
const lowerQuery = query.toLowerCase();
|
|
1914
|
+
accounts = accounts.filter((a) => a.name?.toLowerCase().includes(lowerQuery) || a.email?.toLowerCase().includes(lowerQuery));
|
|
1915
|
+
}
|
|
1916
|
+
if (filters) {
|
|
1917
|
+
if (filters.providerType) accounts = accounts.filter((a) => a.providerType === filters.providerType);
|
|
1918
|
+
if (filters.email) {
|
|
1919
|
+
const emailLower = filters.email.toLowerCase();
|
|
1920
|
+
accounts = accounts.filter((a) => a.email?.toLowerCase().includes(emailLower));
|
|
1921
|
+
}
|
|
1922
|
+
if (filters.isActive !== void 0) accounts = accounts.filter((a) => a.isActive === filters.isActive);
|
|
1923
|
+
}
|
|
1924
|
+
return accounts;
|
|
1925
|
+
}
|
|
1926
|
+
/**
|
|
1927
|
+
* Sync all active email accounts
|
|
1928
|
+
*/
|
|
1929
|
+
async syncAll(options) {
|
|
1930
|
+
const results = /* @__PURE__ */ new Map();
|
|
1931
|
+
const accounts = await this.getActive();
|
|
1932
|
+
for (const account of accounts) {
|
|
1933
|
+
const ea = account;
|
|
1934
|
+
const accountId = ea.id ?? ea.email ?? "unknown";
|
|
1935
|
+
try {
|
|
1936
|
+
await ea.syncFrom(options);
|
|
1937
|
+
results.set(accountId, { success: true });
|
|
1938
|
+
} catch (error) {
|
|
1939
|
+
results.set(accountId, {
|
|
1940
|
+
success: false,
|
|
1941
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
1942
|
+
});
|
|
1943
|
+
}
|
|
1944
|
+
}
|
|
1945
|
+
return results;
|
|
1946
|
+
}
|
|
1947
|
+
/**
|
|
1948
|
+
* Get total unread count across all email accounts
|
|
1949
|
+
*/
|
|
1950
|
+
async getTotalUnreadCount() {
|
|
1951
|
+
const accounts = await this.getActive();
|
|
1952
|
+
let total = 0;
|
|
1953
|
+
for (const account of accounts) total += await account.getUnreadCount();
|
|
1954
|
+
return total;
|
|
1955
|
+
}
|
|
1956
|
+
/**
|
|
1957
|
+
* Get email account statistics
|
|
1958
|
+
*/
|
|
1959
|
+
async getEmailStats() {
|
|
1960
|
+
const accounts = await this.list({});
|
|
1961
|
+
const byProvider = {
|
|
1962
|
+
smtp: 0,
|
|
1963
|
+
imap: 0,
|
|
1964
|
+
pop3: 0,
|
|
1965
|
+
gmail: 0,
|
|
1966
|
+
jmap: 0
|
|
1967
|
+
};
|
|
1968
|
+
for (const account of accounts) {
|
|
1969
|
+
const pt = account.providerType;
|
|
1970
|
+
if (pt in byProvider) byProvider[pt]++;
|
|
1971
|
+
}
|
|
1972
|
+
return {
|
|
1973
|
+
total: accounts.length,
|
|
1974
|
+
active: accounts.filter((a) => a.isActive).length,
|
|
1975
|
+
inactive: accounts.filter((a) => !a.isActive).length,
|
|
1976
|
+
byProvider
|
|
1977
|
+
};
|
|
1978
|
+
}
|
|
1979
|
+
async findByTenant(tenantId) {
|
|
1980
|
+
return this.list({ where: { tenantId } });
|
|
1981
|
+
}
|
|
1982
|
+
async findGlobal() {
|
|
1983
|
+
return queryGlobal(this);
|
|
1984
|
+
}
|
|
1985
|
+
async findWithGlobals(tenantId) {
|
|
1986
|
+
return queryWithGlobals(this, tenantId, "EmailAccount.findWithGlobals");
|
|
1987
|
+
}
|
|
1988
|
+
};
|
|
1989
|
+
//#endregion
|
|
1990
|
+
export { MESSAGING_PERMISSION_DEFINITIONS as A, mailScopePermission as C, MANAGE_MESSAGE_CREDENTIALS_PERMISSION as D, withoutListBounds as E, seedMessagesRolePermissions as F, assertMessagingPermission as M, ensureMessagingPermissionsRegistered as N, MANAGE_MESSAGE_ROUTES_PERMISSION as O, messagingPrincipalFromPermissions as P, learnMailAccessOptions as S, runWithMailSystemAccess as T, deniedMailAccountIds as _, AccountCollection_exports as a, inMailSystemAccess as b, MAIL_ACCOUNT_RESOURCE_TYPE as c, MailAccessService as d, assertHydratedMailAccess as f, decideMailAccess as g, configureMailAccess as h, AccountCollection as i, SEND_MESSAGES_PERMISSION as j, MESSAGES_ROLE_PERMISSION_MATRIX as k, MAIL_SCOPES as l, canAccessMailAccount as m, EmailAccountCollection_exports as n, MailWriteBackUnsupportedError as o, assertMailAccess as p, EmailAccount as r, Account as s, EmailAccountCollection as t, MailAccessError as u, getEffectiveMailAccessConfigs as v, resetMailAccess as w, isMailScope as x, getMailAccessConfig as y };
|
|
1991
|
+
|
|
1992
|
+
//# sourceMappingURL=EmailAccountCollection-DkvT4tdP.js.map
|