@happyvertical/smrt-messages 0.61.2 → 0.61.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/dist/chunks/{AccountCollection-C715bDaZ.js → AccountCollection-CwJs7h6H.js} +2 -2
  2. package/dist/chunks/{AccountCollection-C715bDaZ.js.map → AccountCollection-CwJs7h6H.js.map} +1 -1
  3. package/dist/chunks/{Email-BlbBidi-.js → Email-J4TCNxb4.js} +6 -6
  4. package/dist/chunks/Email-J4TCNxb4.js.map +1 -0
  5. package/dist/chunks/{EmailFolder-CgxdkIF7.js → EmailFolder-ayDSeXKL.js} +2 -2
  6. package/dist/chunks/{EmailFolder-CgxdkIF7.js.map → EmailFolder-ayDSeXKL.js.map} +1 -1
  7. package/dist/chunks/{Message-DXXy2R-t.js → Message-DT0amGGC.js} +4 -4
  8. package/dist/chunks/{Message-DXXy2R-t.js.map → Message-DT0amGGC.js.map} +1 -1
  9. package/dist/chunks/{MessageCollection-HjzJvFYY.js → MessageCollection-CGaUjwK1.js} +2 -2
  10. package/dist/chunks/{MessageCollection-HjzJvFYY.js.map → MessageCollection-CGaUjwK1.js.map} +1 -1
  11. package/dist/chunks/__smrt-register__-D4OOWdmP.js +6 -0
  12. package/dist/chunks/__smrt-register__-D4OOWdmP.js.map +1 -0
  13. package/dist/index.js +79 -39
  14. package/dist/index.js.map +1 -1
  15. package/dist/manifest.json +2500 -848
  16. package/dist/migrations/profileRecipients.d.ts.map +1 -1
  17. package/dist/models/EmailAccount.d.ts.map +1 -1
  18. package/dist/models/NotificationDelivery.d.ts +6 -1
  19. package/dist/models/NotificationDelivery.d.ts.map +1 -1
  20. package/dist/models/NotificationOptOut.d.ts.map +1 -1
  21. package/dist/models/PersonaMessageRoute.d.ts.map +1 -1
  22. package/dist/models/UserNotification.d.ts.map +1 -1
  23. package/dist/services/MessagingSettingsService.d.ts +1 -1
  24. package/dist/services/MessagingSettingsService.d.ts.map +1 -1
  25. package/dist/services/NotificationOptOutService.d.ts.map +1 -1
  26. package/dist/services/PersonaMessagingService.d.ts +1 -1
  27. package/dist/services/PersonaMessagingService.d.ts.map +1 -1
  28. package/dist/smrt-knowledge.json +8 -8
  29. package/package.json +16 -16
  30. package/dist/chunks/Email-BlbBidi-.js.map +0 -1
  31. package/dist/chunks/__smrt-register__-yE42KJtc.js +0 -6
  32. package/dist/chunks/__smrt-register__-yE42KJtc.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,16 +1,16 @@
1
1
  import { t as __exportAll } from "./chunks/rolldown-runtime-D7D4PA-g.js";
2
- import "./chunks/__smrt-register__-yE42KJtc.js";
2
+ import "./chunks/__smrt-register__-D4OOWdmP.js";
3
3
  import { a as registerMessagingProvider, n as getMessagingProvider, o as ZulipSender, r as listMessagingProviders, s as TelegramSender, t as ensureBuiltinMessagingProvidersRegistered } from "./chunks/providers-4iLula-V.js";
4
4
  import { buildSqliteRebuildStatements, isDeepStrictEqual, normalizeIdentityEmail, queryGlobal, queryWithGlobals, readNotificationProfile, withSystemContext, withTenant } from "./host.js";
5
- import { r as Account, t as AccountCollection } from "./chunks/AccountCollection-C715bDaZ.js";
5
+ import { r as Account, t as AccountCollection } from "./chunks/AccountCollection-CwJs7h6H.js";
6
6
  import { d as withProtectedNotificationHandoff, f as PROFILE_NOTIFICATION_POLICY_PREFIX, l as protectedNotificationMetadata, m as profileNotificationPolicy, n as assertProtectedEmailAdmission, p as assertNotificationRecipientIdentity, r as assertProtectedEmailHandoff, t as ProtectedNotificationHandoffError } from "./chunks/protected-notification-handoff-mvaEZVp7.js";
7
- import { t as Message } from "./chunks/Message-DXXy2R-t.js";
8
- import { t as MessageCollection } from "./chunks/MessageCollection-HjzJvFYY.js";
9
- import { t as Email } from "./chunks/Email-BlbBidi-.js";
10
- import { t as EmailFolder } from "./chunks/EmailFolder-CgxdkIF7.js";
7
+ import { t as Message } from "./chunks/Message-DT0amGGC.js";
8
+ import { t as MessageCollection } from "./chunks/MessageCollection-CGaUjwK1.js";
9
+ import { t as Email } from "./chunks/Email-J4TCNxb4.js";
10
+ import { t as EmailFolder } from "./chunks/EmailFolder-ayDSeXKL.js";
11
11
  import { t as SlackSender } from "./chunks/SlackSender-CjSvwY1K.js";
12
12
  import { t as TweetSender } from "./chunks/TweetSender-CcLPNNi1.js";
13
- import { GlobalInterceptors, SmrtCollection, SmrtObject, SmrtRecipe, crossPackageRef, detectEngine, field, foreignKey, importOptionalDependency, isUniqueViolationError, smrt, usesEmbeddedRevisionFallback, withEmbeddedWriteQueue } from "@happyvertical/smrt-core";
13
+ import { GlobalInterceptors, ObjectRegistry, SmrtCollection, SmrtObject, SmrtRecipe, crossPackageRef, detectEngine, field, foreignKey, importOptionalDependency, isUniqueViolationError, smrt, usesEmbeddedRevisionFallback, withEmbeddedWriteQueue } from "@happyvertical/smrt-core";
14
14
  import { registerPermissionDefinitions } from "@happyvertical/smrt-users/permission-registry";
15
15
  import { TenantScoped, tenantId } from "@happyvertical/smrt-tenancy/decorators";
16
16
  //#region src/permissions.ts
@@ -109,7 +109,7 @@ var Attachment = class extends SmrtObject {
109
109
  */
110
110
  async getMessage() {
111
111
  if (!this.messageId) return null;
112
- const { MessageCollection } = await import("./chunks/MessageCollection-HjzJvFYY.js").then((n) => n.n);
112
+ const { MessageCollection } = await import("./chunks/MessageCollection-CGaUjwK1.js").then((n) => n.n);
113
113
  return await (await MessageCollection.create(this.options)).get({ id: this.messageId });
114
114
  }
115
115
  /**
@@ -381,7 +381,10 @@ var MessagingEndpoint = class extends SmrtObject {
381
381
  __publicField$13(MessagingEndpoint, "__smrtPackage__", "@happyvertical/smrt-messages");
382
382
  __decorateClass$13([tenantId()], MessagingEndpoint.prototype, "tenantId", 2);
383
383
  __decorateClass$13([crossPackageRef("@happyvertical/smrt-profiles:Profile", { nullable: true })], MessagingEndpoint.prototype, "profileId", 2);
384
- __decorateClass$13([field({ required: true })], MessagingEndpoint.prototype, "label", 2);
384
+ __decorateClass$13([field({
385
+ required: true,
386
+ requiredFor: "identity"
387
+ })], MessagingEndpoint.prototype, "label", 2);
385
388
  __decorateClass$13([field({ required: true })], MessagingEndpoint.prototype, "channel", 2);
386
389
  __decorateClass$13([field({
387
390
  required: true,
@@ -644,15 +647,30 @@ __publicField$12(NotificationDelivery, "__smrtPackage__", "@happyvertical/smrt-m
644
647
  __decorateClass$12([tenantId()], NotificationDelivery.prototype, "tenantId", 2);
645
648
  __decorateClass$12([crossPackageRef("@happyvertical/smrt-users:User", { nullable: true })], NotificationDelivery.prototype, "recipientUserId", 2);
646
649
  __decorateClass$12([crossPackageRef("@happyvertical/smrt-profiles:Profile", { nullable: true })], NotificationDelivery.prototype, "recipientProfileId", 2);
647
- __decorateClass$12([field({ required: true })], NotificationDelivery.prototype, "recipientKind", 2);
648
- __decorateClass$12([field({ required: true })], NotificationDelivery.prototype, "channel", 2);
649
- __decorateClass$12([field({ required: true })], NotificationDelivery.prototype, "sourceRef", 2);
650
- __decorateClass$12([field({ required: true })], NotificationDelivery.prototype, "kind", 2);
650
+ __decorateClass$12([field({
651
+ required: true,
652
+ requiredFor: "identity"
653
+ })], NotificationDelivery.prototype, "recipientKind", 2);
654
+ __decorateClass$12([field({
655
+ required: true,
656
+ requiredFor: "identity"
657
+ })], NotificationDelivery.prototype, "channel", 2);
658
+ __decorateClass$12([field({
659
+ required: true,
660
+ requiredFor: "idempotency"
661
+ })], NotificationDelivery.prototype, "sourceRef", 2);
662
+ __decorateClass$12([field({
663
+ required: true,
664
+ requiredFor: "identity"
665
+ })], NotificationDelivery.prototype, "kind", 2);
651
666
  __decorateClass$12([field({ type: "json" })], NotificationDelivery.prototype, "dispatchPolicyBinding", 2);
652
- __decorateClass$12([field({ required: true })], NotificationDelivery.prototype, "subject", 2);
653
- __decorateClass$12([field({ required: true })], NotificationDelivery.prototype, "textBody", 2);
654
- __decorateClass$12([field({ required: true })], NotificationDelivery.prototype, "href", 2);
655
- __decorateClass$12([field({ required: true })], NotificationDelivery.prototype, "recipientAddress", 2);
667
+ __decorateClass$12([field()], NotificationDelivery.prototype, "subject", 2);
668
+ __decorateClass$12([field()], NotificationDelivery.prototype, "textBody", 2);
669
+ __decorateClass$12([field()], NotificationDelivery.prototype, "href", 2);
670
+ __decorateClass$12([field({
671
+ required: true,
672
+ requiredFor: "identity"
673
+ })], NotificationDelivery.prototype, "recipientAddress", 2);
656
674
  __decorateClass$12([foreignKey("Account")], NotificationDelivery.prototype, "accountId", 2);
657
675
  __decorateClass$12([foreignKey("Message")], NotificationDelivery.prototype, "messageId", 2);
658
676
  NotificationDelivery = __decorateClass$12([TenantScoped({ mode: "required" }), smrt({
@@ -750,9 +768,15 @@ var NotificationOptOut = class extends SmrtObject {
750
768
  };
751
769
  __publicField$11(NotificationOptOut, "__smrtPackage__", "@happyvertical/smrt-messages");
752
770
  __decorateClass$11([tenantId()], NotificationOptOut.prototype, "tenantId", 2);
753
- __decorateClass$11([crossPackageRef("@happyvertical/smrt-users:User", { required: true })], NotificationOptOut.prototype, "recipientUserId", 2);
771
+ __decorateClass$11([crossPackageRef("@happyvertical/smrt-users:User", {
772
+ required: true,
773
+ requiredFor: "identity"
774
+ })], NotificationOptOut.prototype, "recipientUserId", 2);
754
775
  __decorateClass$11([field({ required: true })], NotificationOptOut.prototype, "channel", 2);
755
- __decorateClass$11([field({ required: true })], NotificationOptOut.prototype, "scope", 2);
776
+ __decorateClass$11([field({
777
+ required: true,
778
+ requiredFor: "identity"
779
+ })], NotificationOptOut.prototype, "scope", 2);
756
780
  NotificationOptOut = __decorateClass$11([TenantScoped({ mode: "required" }), smrt({
757
781
  tableName: "notification_opt_outs",
758
782
  api: false,
@@ -812,9 +836,18 @@ var PersonaMessageRoute = class extends SmrtObject {
812
836
  };
813
837
  __publicField$10(PersonaMessageRoute, "__smrtPackage__", "@happyvertical/smrt-messages");
814
838
  __decorateClass$10([tenantId()], PersonaMessageRoute.prototype, "tenantId", 2);
815
- __decorateClass$10([crossPackageRef("@happyvertical/smrt-personas:AgentPersona", { required: true })], PersonaMessageRoute.prototype, "personaId", 2);
816
- __decorateClass$10([foreignKey("Account", { required: true })], PersonaMessageRoute.prototype, "accountId", 2);
817
- __decorateClass$10([foreignKey("MessagingEndpoint", { required: true })], PersonaMessageRoute.prototype, "endpointId", 2);
839
+ __decorateClass$10([crossPackageRef("@happyvertical/smrt-personas:AgentPersona", {
840
+ required: true,
841
+ requiredFor: "identity"
842
+ })], PersonaMessageRoute.prototype, "personaId", 2);
843
+ __decorateClass$10([foreignKey("Account", {
844
+ required: true,
845
+ requiredFor: "identity"
846
+ })], PersonaMessageRoute.prototype, "accountId", 2);
847
+ __decorateClass$10([foreignKey("MessagingEndpoint", {
848
+ required: true,
849
+ requiredFor: "identity"
850
+ })], PersonaMessageRoute.prototype, "endpointId", 2);
818
851
  __decorateClass$10([field({ required: true })], PersonaMessageRoute.prototype, "purpose", 2);
819
852
  PersonaMessageRoute = __decorateClass$10([TenantScoped({ mode: "required" }), smrt({
820
853
  tableName: "persona_message_routes",
@@ -903,10 +936,16 @@ var UserNotification = class extends SmrtObject {
903
936
  };
904
937
  __publicField$9(UserNotification, "__smrtPackage__", "@happyvertical/smrt-messages");
905
938
  __decorateClass$9([tenantId()], UserNotification.prototype, "tenantId", 2);
906
- __decorateClass$9([crossPackageRef("@happyvertical/smrt-users:User", { required: true })], UserNotification.prototype, "recipientUserId", 2);
907
- __decorateClass$9([field({ required: true })], UserNotification.prototype, "kind", 2);
908
- __decorateClass$9([field({ required: true })], UserNotification.prototype, "title", 2);
909
- __decorateClass$9([field({ required: true })], UserNotification.prototype, "sourceRef", 2);
939
+ __decorateClass$9([crossPackageRef("@happyvertical/smrt-users:User", {
940
+ required: true,
941
+ requiredFor: "identity"
942
+ })], UserNotification.prototype, "recipientUserId", 2);
943
+ __decorateClass$9([field()], UserNotification.prototype, "kind", 2);
944
+ __decorateClass$9([field()], UserNotification.prototype, "title", 2);
945
+ __decorateClass$9([field({
946
+ required: true,
947
+ requiredFor: "idempotency"
948
+ })], UserNotification.prototype, "sourceRef", 2);
910
949
  UserNotification = __decorateClass$9([TenantScoped({ mode: "required" }), smrt({
911
950
  tableName: "user_notifications",
912
951
  api: false,
@@ -1056,8 +1095,8 @@ var EmailAccount = class extends Account {
1056
1095
  for (const folderName of foldersToSync) try {
1057
1096
  let folder = await folderCollection.getByPath(accountId, folderName);
1058
1097
  if (!folder) {
1059
- const { EmailFolder } = await import("./chunks/EmailFolder-CgxdkIF7.js").then((n) => n.n);
1060
- folder = new EmailFolder({
1098
+ const { EmailFolder } = await import("./chunks/EmailFolder-ayDSeXKL.js").then((n) => n.n);
1099
+ folder = new (ObjectRegistry.resolveEffectiveConstructor(EmailFolder))({
1061
1100
  ...this.childOptions(),
1062
1101
  accountId,
1063
1102
  name: folderName,
@@ -1081,10 +1120,10 @@ var EmailAccount = class extends Account {
1081
1120
  result.messagesSkipped++;
1082
1121
  continue;
1083
1122
  }
1084
- const { Email } = await import("./chunks/Email-BlbBidi-.js").then((n) => n.n);
1123
+ const { Email } = await import("./chunks/Email-J4TCNxb4.js").then((n) => n.n);
1085
1124
  let email = existingEmail;
1086
1125
  if (!email) {
1087
- email = new Email({
1126
+ email = new (ObjectRegistry.resolveEffectiveConstructor(Email))({
1088
1127
  ...this.childOptions(),
1089
1128
  accountId
1090
1129
  });
@@ -2500,7 +2539,7 @@ var MessagingSettingsService = class {
2500
2539
  let endpoint = input.id ? await collection.get({ id: input.id }) : null;
2501
2540
  if (endpoint && endpoint.tenantId !== this.options.tenantId) throw new Error("Messaging endpoint belongs to another tenant.");
2502
2541
  if (!endpoint) {
2503
- endpoint = new MessagingEndpoint({
2542
+ endpoint = new (ObjectRegistry.resolveEffectiveConstructor(MessagingEndpoint))({
2504
2543
  db: this.options.db,
2505
2544
  tenantId: this.options.tenantId
2506
2545
  });
@@ -2532,7 +2571,7 @@ var MessagingSettingsService = class {
2532
2571
  let route = input.id ? await routes.get({ id: input.id }) : null;
2533
2572
  if (route && route.tenantId !== this.options.tenantId) throw new Error("Messaging route belongs to another tenant.");
2534
2573
  if (!route) {
2535
- route = new PersonaMessageRoute({
2574
+ route = new (ObjectRegistry.resolveEffectiveConstructor(PersonaMessageRoute))({
2536
2575
  db: this.options.db,
2537
2576
  tenantId: this.options.tenantId
2538
2577
  });
@@ -2579,13 +2618,13 @@ var MessagingSettingsService = class {
2579
2618
  providerType: provider.id,
2580
2619
  channelType: provider.channel
2581
2620
  };
2582
- if (provider.id === "zulip") return new ZulipAccount(options);
2583
- if (provider.id === "telegram") return new TelegramAccount(options);
2584
- if (provider.channel === "email") return new EmailAccount({
2621
+ if (provider.id === "zulip") return new (ObjectRegistry.resolveEffectiveConstructor(ZulipAccount))(options);
2622
+ if (provider.id === "telegram") return new (ObjectRegistry.resolveEffectiveConstructor(TelegramAccount))(options);
2623
+ if (provider.channel === "email") return new (ObjectRegistry.resolveEffectiveConstructor(EmailAccount))({
2585
2624
  ...options,
2586
2625
  providerType: provider.id
2587
2626
  });
2588
- return new Account(options);
2627
+ return new (ObjectRegistry.resolveEffectiveConstructor(Account))(options);
2589
2628
  }
2590
2629
  normalizeCredentials(provider, credentials) {
2591
2630
  if (provider.channel !== "email") return credentials;
@@ -2733,7 +2772,7 @@ var NotificationOptOutService = class {
2733
2772
  };
2734
2773
  const existing = await find();
2735
2774
  if (existing) return apply(existing);
2736
- if (!optedOut) return new NotificationOptOut({
2775
+ if (!optedOut) return new (ObjectRegistry.resolveEffectiveConstructor(NotificationOptOut))({
2737
2776
  tenantId,
2738
2777
  recipientUserId,
2739
2778
  channel,
@@ -2931,6 +2970,7 @@ async function planNotificationProfileRecipients(db, engine) {
2931
2970
  columns: state.columns.map((c) => c.name),
2932
2971
  objects: [...state.indexes, ...triggers],
2933
2972
  legacyAlterTable: Boolean((await db.query("PRAGMA legacy_alter_table")).rows[0]?.legacy_alter_table),
2973
+ inboundReferences: [],
2934
2974
  nullableColumns: new Set(Number(state.columns.find((c) => c.name === "recipient_user_id")?.notnull) ? ["recipient_user_id"] : []),
2935
2975
  appendColumns: [...!state.columns.some((c) => c.name === "recipient_kind") ? [{
2936
2976
  name: "recipient_kind",
@@ -3739,14 +3779,14 @@ var PersonaMessagingService = class {
3739
3779
  if (!(account instanceof EmailAccount)) throw new Error("Email routes require an EmailAccount.");
3740
3780
  const address = endpoint.getAddress();
3741
3781
  if (!address.email) throw new Error("Email endpoint has no address.");
3742
- const email = new Email({
3782
+ const email = new (ObjectRegistry.resolveEffectiveConstructor(Email))({
3743
3783
  ...base,
3744
3784
  textBody: base.body,
3745
3785
  hasAttachments: Boolean(input.attachments?.length)
3746
3786
  });
3747
3787
  email.setToAddresses([{ address: address.email }]);
3748
3788
  message = email;
3749
- } else message = new Message(base);
3789
+ } else message = new (ObjectRegistry.resolveEffectiveConstructor(Message))(base);
3750
3790
  await message.initialize();
3751
3791
  await message.save();
3752
3792
  const sendOptions = input.attachments?.length ? { attachments: input.attachments } : void 0;