@frigear-nu/inbox 0.0.0-stage → 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. package/README.md +39 -2
  2. package/dist/module.d.mts +452 -0
  3. package/dist/module.json +9 -0
  4. package/dist/module.mjs +242 -0
  5. package/dist/runtime/access.d.ts +1 -0
  6. package/dist/runtime/access.js +62 -0
  7. package/dist/runtime/app/components/InboxChannelSlideover.d.vue.ts +12 -0
  8. package/dist/runtime/app/components/InboxChannelSlideover.vue +171 -0
  9. package/dist/runtime/app/components/InboxChannelSlideover.vue.d.ts +12 -0
  10. package/dist/runtime/app/components/InboxComposer.d.vue.ts +12 -0
  11. package/dist/runtime/app/components/InboxComposer.vue +71 -0
  12. package/dist/runtime/app/components/InboxComposer.vue.d.ts +12 -0
  13. package/dist/runtime/app/components/InboxConversation.d.vue.ts +8 -0
  14. package/dist/runtime/app/components/InboxConversation.vue +82 -0
  15. package/dist/runtime/app/components/InboxConversation.vue.d.ts +8 -0
  16. package/dist/runtime/app/components/InboxHideSlideover.d.vue.ts +12 -0
  17. package/dist/runtime/app/components/InboxHideSlideover.vue +54 -0
  18. package/dist/runtime/app/components/InboxHideSlideover.vue.d.ts +12 -0
  19. package/dist/runtime/app/components/InboxMailboxSlideover.d.vue.ts +11 -0
  20. package/dist/runtime/app/components/InboxMailboxSlideover.vue +125 -0
  21. package/dist/runtime/app/components/InboxMailboxSlideover.vue.d.ts +11 -0
  22. package/dist/runtime/app/composables/index.d.ts +6 -0
  23. package/dist/runtime/app/composables/index.js +5 -0
  24. package/dist/runtime/app/composables/useInboxChannelActions.d.ts +15 -0
  25. package/dist/runtime/app/composables/useInboxChannelActions.js +45 -0
  26. package/dist/runtime/app/composables/useInboxLinks.d.ts +11 -0
  27. package/dist/runtime/app/composables/useInboxLinks.js +17 -0
  28. package/dist/runtime/app/composables/useInboxMailboxActions.d.ts +14 -0
  29. package/dist/runtime/app/composables/useInboxMailboxActions.js +47 -0
  30. package/dist/runtime/app/composables/useInboxThreadActions.d.ts +29 -0
  31. package/dist/runtime/app/composables/useInboxThreadActions.js +76 -0
  32. package/dist/runtime/app/composables/useInboxTranslate.d.ts +3 -0
  33. package/dist/runtime/app/composables/useInboxTranslate.js +7 -0
  34. package/dist/runtime/app/dashboard/InboxMine.d.vue.ts +3 -0
  35. package/dist/runtime/app/dashboard/InboxMine.vue +25 -0
  36. package/dist/runtime/app/dashboard/InboxMine.vue.d.ts +3 -0
  37. package/dist/runtime/app/dashboard/InboxUnassigned.d.vue.ts +3 -0
  38. package/dist/runtime/app/dashboard/InboxUnassigned.vue +25 -0
  39. package/dist/runtime/app/dashboard/InboxUnassigned.vue.d.ts +3 -0
  40. package/dist/runtime/app/pages/admin-settings.d.vue.ts +3 -0
  41. package/dist/runtime/app/pages/admin-settings.vue +161 -0
  42. package/dist/runtime/app/pages/admin-settings.vue.d.ts +3 -0
  43. package/dist/runtime/app/pages/admin-thread.d.vue.ts +3 -0
  44. package/dist/runtime/app/pages/admin-thread.vue +234 -0
  45. package/dist/runtime/app/pages/admin-thread.vue.d.ts +3 -0
  46. package/dist/runtime/app/pages/admin.d.vue.ts +3 -0
  47. package/dist/runtime/app/pages/admin.vue +211 -0
  48. package/dist/runtime/app/pages/admin.vue.d.ts +3 -0
  49. package/dist/runtime/channels/email.d.ts +2 -0
  50. package/dist/runtime/channels/email.js +8 -0
  51. package/dist/runtime/channels/form.d.ts +2 -0
  52. package/dist/runtime/channels/form.js +9 -0
  53. package/dist/runtime/channels/instagram.d.ts +2 -0
  54. package/dist/runtime/channels/instagram.js +5 -0
  55. package/dist/runtime/channels/messenger.d.ts +2 -0
  56. package/dist/runtime/channels/messenger.js +5 -0
  57. package/dist/runtime/channels/whatsapp.d.ts +2 -0
  58. package/dist/runtime/channels/whatsapp.js +5 -0
  59. package/dist/runtime/i18n/lang/da.json +247 -0
  60. package/dist/runtime/i18n/lang/en.json +247 -0
  61. package/dist/runtime/menus.d.ts +2 -0
  62. package/dist/runtime/menus.js +19 -0
  63. package/dist/runtime/server/db/schema.postgresql.d.ts +1216 -0
  64. package/dist/runtime/server/db/schema.postgresql.js +154 -0
  65. package/dist/runtime/server/db/schema.sqlite.d.ts +1294 -0
  66. package/dist/runtime/server/db/schema.sqlite.js +154 -0
  67. package/dist/runtime/server/plugins/forms.d.ts +2 -0
  68. package/dist/runtime/server/plugins/forms.js +55 -0
  69. package/dist/runtime/server/plugins/links.d.ts +2 -0
  70. package/dist/runtime/server/plugins/links.js +18 -0
  71. package/dist/runtime/server/plugins/notify.d.ts +2 -0
  72. package/dist/runtime/server/plugins/notify.js +24 -0
  73. package/dist/runtime/server/plugins/seed.d.ts +2 -0
  74. package/dist/runtime/server/plugins/seed.js +7 -0
  75. package/dist/runtime/server/plugins/teams.d.ts +2 -0
  76. package/dist/runtime/server/plugins/teams.js +3 -0
  77. package/dist/runtime/server/policies.d.ts +2 -0
  78. package/dist/runtime/server/policies.js +15 -0
  79. package/dist/runtime/server/routes/admin/audit.get.d.ts +2 -0
  80. package/dist/runtime/server/routes/admin/audit.get.js +43 -0
  81. package/dist/runtime/server/routes/admin/channel.delete.d.ts +2 -0
  82. package/dist/runtime/server/routes/admin/channel.delete.js +13 -0
  83. package/dist/runtime/server/routes/admin/channel.patch.d.ts +2 -0
  84. package/dist/runtime/server/routes/admin/channel.patch.js +24 -0
  85. package/dist/runtime/server/routes/admin/channels.get.d.ts +2 -0
  86. package/dist/runtime/server/routes/admin/channels.get.js +10 -0
  87. package/dist/runtime/server/routes/admin/channels.post.d.ts +2 -0
  88. package/dist/runtime/server/routes/admin/channels.post.js +21 -0
  89. package/dist/runtime/server/routes/admin/contact-erase.post.d.ts +2 -0
  90. package/dist/runtime/server/routes/admin/contact-erase.post.js +20 -0
  91. package/dist/runtime/server/routes/admin/contact-export.get.d.ts +2 -0
  92. package/dist/runtime/server/routes/admin/contact-export.get.js +41 -0
  93. package/dist/runtime/server/routes/admin/mailbox.delete.d.ts +2 -0
  94. package/dist/runtime/server/routes/admin/mailbox.delete.js +14 -0
  95. package/dist/runtime/server/routes/admin/mailbox.get.d.ts +2 -0
  96. package/dist/runtime/server/routes/admin/mailbox.get.js +9 -0
  97. package/dist/runtime/server/routes/admin/mailbox.patch.d.ts +2 -0
  98. package/dist/runtime/server/routes/admin/mailbox.patch.js +17 -0
  99. package/dist/runtime/server/routes/admin/mailboxes.get.d.ts +2 -0
  100. package/dist/runtime/server/routes/admin/mailboxes.get.js +5 -0
  101. package/dist/runtime/server/routes/admin/mailboxes.post.d.ts +2 -0
  102. package/dist/runtime/server/routes/admin/mailboxes.post.js +22 -0
  103. package/dist/runtime/server/routes/admin/summary.get.d.ts +2 -0
  104. package/dist/runtime/server/routes/admin/summary.get.js +19 -0
  105. package/dist/runtime/server/routes/admin/thread-assignees.get.d.ts +2 -0
  106. package/dist/runtime/server/routes/admin/thread-assignees.get.js +11 -0
  107. package/dist/runtime/server/routes/admin/thread-hide.post.d.ts +2 -0
  108. package/dist/runtime/server/routes/admin/thread-hide.post.js +23 -0
  109. package/dist/runtime/server/routes/admin/thread-messages.post.d.ts +2 -0
  110. package/dist/runtime/server/routes/admin/thread-messages.post.js +10 -0
  111. package/dist/runtime/server/routes/admin/thread-notes.post.d.ts +2 -0
  112. package/dist/runtime/server/routes/admin/thread-notes.post.js +10 -0
  113. package/dist/runtime/server/routes/admin/thread.get.d.ts +2 -0
  114. package/dist/runtime/server/routes/admin/thread.get.js +27 -0
  115. package/dist/runtime/server/routes/admin/thread.patch.d.ts +2 -0
  116. package/dist/runtime/server/routes/admin/thread.patch.js +23 -0
  117. package/dist/runtime/server/routes/admin/threads.get.d.ts +2 -0
  118. package/dist/runtime/server/routes/admin/threads.get.js +49 -0
  119. package/dist/runtime/server/routes/webhooks/channel.post.d.ts +2 -0
  120. package/dist/runtime/server/routes/webhooks/channel.post.js +11 -0
  121. package/dist/runtime/server/routes/webhooks/email.post.d.ts +2 -0
  122. package/dist/runtime/server/routes/webhooks/email.post.js +38 -0
  123. package/dist/runtime/server/routes/webhooks/meta.get.d.ts +2 -0
  124. package/dist/runtime/server/routes/webhooks/meta.get.js +19 -0
  125. package/dist/runtime/server/routes/webhooks/meta.post.d.ts +2 -0
  126. package/dist/runtime/server/routes/webhooks/meta.post.js +29 -0
  127. package/dist/runtime/server/search-index.d.ts +2 -0
  128. package/dist/runtime/server/search-index.js +7 -0
  129. package/dist/runtime/server/tasks/retention.d.ts +2 -0
  130. package/dist/runtime/server/tasks/retention.js +12 -0
  131. package/dist/runtime/server/utils/inbox-audit.d.ts +17 -0
  132. package/dist/runtime/server/utils/inbox-audit.js +35 -0
  133. package/dist/runtime/server/utils/inbox-channels.d.ts +42 -0
  134. package/dist/runtime/server/utils/inbox-channels.js +73 -0
  135. package/dist/runtime/server/utils/inbox-config.d.ts +12 -0
  136. package/dist/runtime/server/utils/inbox-config.js +8 -0
  137. package/dist/runtime/server/utils/inbox-dto.d.ts +19 -0
  138. package/dist/runtime/server/utils/inbox-dto.js +92 -0
  139. package/dist/runtime/server/utils/inbox-ingest.d.ts +43 -0
  140. package/dist/runtime/server/utils/inbox-ingest.js +136 -0
  141. package/dist/runtime/server/utils/inbox-integrations.d.ts +7 -0
  142. package/dist/runtime/server/utils/inbox-integrations.js +13 -0
  143. package/dist/runtime/server/utils/inbox-mailboxes.d.ts +14 -0
  144. package/dist/runtime/server/utils/inbox-mailboxes.js +27 -0
  145. package/dist/runtime/server/utils/inbox-registry.d.ts +7 -0
  146. package/dist/runtime/server/utils/inbox-registry.js +10 -0
  147. package/dist/runtime/server/utils/inbox-retention.d.ts +57 -0
  148. package/dist/runtime/server/utils/inbox-retention.js +167 -0
  149. package/dist/runtime/server/utils/inbox-schemas.d.ts +123 -0
  150. package/dist/runtime/server/utils/inbox-schemas.js +78 -0
  151. package/dist/runtime/server/utils/inbox-search.d.ts +8 -0
  152. package/dist/runtime/server/utils/inbox-search.js +2 -0
  153. package/dist/runtime/server/utils/inbox-seed.d.ts +9 -0
  154. package/dist/runtime/server/utils/inbox-seed.js +35 -0
  155. package/dist/runtime/server/utils/inbox-send.d.ts +25 -0
  156. package/dist/runtime/server/utils/inbox-send.js +84 -0
  157. package/dist/runtime/server/utils/inbox-tombstones.d.ts +25 -0
  158. package/dist/runtime/server/utils/inbox-tombstones.js +47 -0
  159. package/dist/runtime/server/utils/inbox-webhooks.d.ts +8 -0
  160. package/dist/runtime/server/utils/inbox-webhooks.js +10 -0
  161. package/dist/runtime/server/utils/inbox.d.ts +79 -0
  162. package/dist/runtime/server/utils/inbox.js +134 -0
  163. package/dist/runtime/utils/api.d.ts +40 -0
  164. package/dist/runtime/utils/api.js +43 -0
  165. package/dist/runtime/utils/index.d.ts +44 -0
  166. package/dist/runtime/utils/index.js +27 -0
  167. package/dist/runtime/utils/payloads.d.ts +99 -0
  168. package/dist/runtime/utils/payloads.js +173 -0
  169. package/dist/runtime/utils/registry.d.ts +17 -0
  170. package/dist/runtime/utils/registry.js +29 -0
  171. package/dist/runtime/utils/signature.d.ts +14 -0
  172. package/dist/runtime/utils/signature.js +16 -0
  173. package/dist/types.d.mts +7 -0
  174. package/package.json +118 -3
@@ -0,0 +1,154 @@
1
+ import { sqliteTable, text, integer, index, uniqueIndex } from "drizzle-orm/sqlite-core";
2
+ export const inboxMailboxes = sqliteTable("inbox_mailboxes", {
3
+ /** `ibx_` + random id. */
4
+ id: text().primaryKey(),
5
+ /** Stable name for code and seeds (`support`), unique. */
6
+ key: text().notNull().unique(),
7
+ /** `platform | team | user` (only `platform` and `team` are used for now). */
8
+ ownerType: text().notNull(),
9
+ /** The owner's id as text; `null` for `platform`. */
10
+ ownerId: text(),
11
+ name: text({ mode: "json" }).$type().notNull(),
12
+ /** Who may read it (`@frigear-nu/auth`): any one grant admits, an empty list admits nobody. */
13
+ grants: text({ mode: "json" }).$type().notNull().default([]),
14
+ /** Days a closed thread is kept; `null` takes the module's `retention.days`. */
15
+ retentionDays: integer(),
16
+ createdAt: integer({ mode: "timestamp" }).notNull().$defaultFn(() => /* @__PURE__ */ new Date()),
17
+ updatedAt: integer({ mode: "timestamp" }).notNull().$defaultFn(() => /* @__PURE__ */ new Date()).$onUpdateFn(() => /* @__PURE__ */ new Date())
18
+ }, (t) => [
19
+ index("inbox_mailbox_owner_idx").on(t.ownerType, t.ownerId)
20
+ ]);
21
+ export const inboxChannelAccounts = sqliteTable("inbox_channel_accounts", {
22
+ /** `ica_` + random id. */
23
+ id: text().primaryKey(),
24
+ mailboxId: text().notNull().references(() => inboxMailboxes.id, { onDelete: "cascade" }),
25
+ /** A registered channel id (`email`, `whatsapp`, ...). */
26
+ channel: text().notNull(),
27
+ /** The identity on the channel (email address, phone number id, page id, form slug), unique per channel. */
28
+ address: text().notNull(),
29
+ /** Settings that are not secret. */
30
+ config: text({ mode: "json" }).$type().notNull(),
31
+ /** The name of a secret in the runtime config or environment; never the secret itself. */
32
+ secretRef: text(),
33
+ enabled: integer({ mode: "boolean" }).notNull().default(true),
34
+ createdAt: integer({ mode: "timestamp" }).notNull().$defaultFn(() => /* @__PURE__ */ new Date()),
35
+ updatedAt: integer({ mode: "timestamp" }).notNull().$defaultFn(() => /* @__PURE__ */ new Date()).$onUpdateFn(() => /* @__PURE__ */ new Date())
36
+ }, (t) => [
37
+ uniqueIndex("inbox_channel_address_idx").on(t.channel, t.address),
38
+ index("inbox_channel_mailbox_idx").on(t.mailboxId)
39
+ ]);
40
+ export const inboxContacts = sqliteTable("inbox_contacts", {
41
+ /** `icn_` + random id. */
42
+ id: text().primaryKey(),
43
+ channel: text().notNull(),
44
+ /** Who the person is on the channel (email address, WhatsApp id, page-scoped id); `erased:<id>` once erased. */
45
+ externalId: text().notNull(),
46
+ name: text(),
47
+ email: text(),
48
+ phone: text(),
49
+ /** The signed-in user who wrote, when known. */
50
+ userId: integer(),
51
+ erasedAt: integer({ mode: "timestamp" }),
52
+ createdAt: integer({ mode: "timestamp" }).notNull().$defaultFn(() => /* @__PURE__ */ new Date())
53
+ }, (t) => [
54
+ uniqueIndex("inbox_contact_external_idx").on(t.channel, t.externalId),
55
+ index("inbox_contact_user_idx").on(t.userId)
56
+ ]);
57
+ export const inboxThreads = sqliteTable("inbox_threads", {
58
+ /** `ibt_` + random id. */
59
+ id: text().primaryKey(),
60
+ mailboxId: text().notNull().references(() => inboxMailboxes.id, { onDelete: "cascade" }),
61
+ contactId: text().notNull().references(() => inboxContacts.id),
62
+ /** The account replies go out through; `null` once the account is deleted. */
63
+ channelAccountId: text().references(() => inboxChannelAccounts.id, { onDelete: "set null" }),
64
+ channel: text().notNull(),
65
+ subject: text(),
66
+ /** `subject` folded for search (`searchText` of `@frigear-nu/module-kit/server`); cleared with it. */
67
+ searchText: text().notNull().default(""),
68
+ /** `open | pending | closed`. */
69
+ status: text().notNull().default("open"),
70
+ assigneeId: integer(),
71
+ /** `null`, or the lowest global role that sees the thread. */
72
+ hiddenBelow: text(),
73
+ /** The start of the last message that is not a note, for the thread list. */
74
+ preview: text(),
75
+ lastMessageAt: integer({ mode: "timestamp" }).notNull().$defaultFn(() => /* @__PURE__ */ new Date()),
76
+ /** When retention or an erase blanked its messages. */
77
+ anonymisedAt: integer({ mode: "timestamp" }),
78
+ createdAt: integer({ mode: "timestamp" }).notNull().$defaultFn(() => /* @__PURE__ */ new Date()),
79
+ updatedAt: integer({ mode: "timestamp" }).notNull().$defaultFn(() => /* @__PURE__ */ new Date()).$onUpdateFn(() => /* @__PURE__ */ new Date())
80
+ }, (t) => [
81
+ index("inbox_thread_mailbox_idx").on(t.mailboxId, t.status),
82
+ index("inbox_thread_assignee_idx").on(t.assigneeId),
83
+ index("inbox_thread_contact_idx").on(t.contactId),
84
+ index("inbox_thread_last_idx").on(t.lastMessageAt)
85
+ ]);
86
+ export const inboxMessages = sqliteTable("inbox_messages", {
87
+ /** `ibm_` + random id. */
88
+ id: text().primaryKey(),
89
+ threadId: text().notNull().references(() => inboxThreads.id, { onDelete: "cascade" }),
90
+ /** `in | out | note`. */
91
+ direction: text().notNull(),
92
+ /** The staff member who replied or wrote the note. */
93
+ authorId: integer(),
94
+ body: text().notNull(),
95
+ attachments: text({ mode: "json" }).$type().notNull(),
96
+ /**
97
+ * Email `Cc` recipients (lower case, valid addresses only): who an inbound message copied (the mailbox's own address
98
+ * left out), or who a reply copied. `null` otherwise.
99
+ */
100
+ cc: text({ mode: "json" }).$type(),
101
+ /**
102
+ * The channel account the message came in on or went out through. No foreign key: it stays when the account is
103
+ * deleted, so the account's provider ids keep their meaning.
104
+ */
105
+ channelAccountId: text(),
106
+ /** `<channel>:<provider id>`, unique per channel account: a webhook delivered twice stores one message. */
107
+ externalId: text(),
108
+ /**
109
+ * The contact who sent an inbound message (`null` for replies and notes). Usually the thread's contact; a reply by
110
+ * email to a contact form thread is filed under the form's contact but sent by the email contact, and exports and
111
+ * erases find it by this column.
112
+ */
113
+ contactId: text(),
114
+ /** Whether the channel verified the sender of an inbound message (see `InboxInboundMessage.authenticated`). */
115
+ authenticated: integer({ mode: "boolean" }).notNull().default(false),
116
+ /** Epoch milliseconds: orders a thread's messages (`createdAt` has whole seconds on sqlite). */
117
+ createdAtMs: integer().notNull().$defaultFn(() => Date.now()),
118
+ createdAt: integer({ mode: "timestamp" }).notNull().$defaultFn(() => /* @__PURE__ */ new Date())
119
+ }, (t) => [
120
+ index("inbox_message_thread_idx").on(t.threadId, t.createdAtMs),
121
+ uniqueIndex("inbox_message_external_idx").on(t.channelAccountId, t.externalId),
122
+ index("inbox_message_contact_idx").on(t.contactId)
123
+ ]);
124
+ export const inboxAudit = sqliteTable("inbox_audit", {
125
+ /** `iba_` + random id. */
126
+ id: text().primaryKey(),
127
+ /** No foreign key: the log outlives deleted threads. */
128
+ threadId: text(),
129
+ /** The thread's mailbox (or the mailbox of a retention run): the log is filtered by mailbox access. */
130
+ mailboxId: text(),
131
+ contactId: text(),
132
+ actorId: integer(),
133
+ /** `viewed | replied | noted | assigned | status | hidden | exported | erased | retention`. */
134
+ action: text().notNull(),
135
+ data: text({ mode: "json" }).$type(),
136
+ createdAt: integer({ mode: "timestamp" }).notNull().$defaultFn(() => /* @__PURE__ */ new Date())
137
+ }, (t) => [
138
+ index("inbox_audit_thread_idx").on(t.threadId),
139
+ index("inbox_audit_contact_idx").on(t.contactId),
140
+ index("inbox_audit_mailbox_idx").on(t.mailboxId),
141
+ index("inbox_audit_created_idx").on(t.createdAt)
142
+ ]);
143
+ export const inboxTombstones = sqliteTable("inbox_tombstones", {
144
+ /** Hex SHA-256 of `<channel account id>:<external id>`: no provider id or address is kept in the clear. */
145
+ key: text().primaryKey(),
146
+ /** The contact who sent the message (no foreign key: the tombstone outlives the contact). */
147
+ contactId: text(),
148
+ /** Written by an erase (GDPR): never pruned, so a replay can never bring the message back. */
149
+ permanent: integer({ mode: "boolean" }).notNull().default(false),
150
+ createdAt: integer({ mode: "timestamp" }).notNull().$defaultFn(() => /* @__PURE__ */ new Date())
151
+ }, (t) => [
152
+ index("inbox_tombstone_created_idx").on(t.createdAt),
153
+ index("inbox_tombstone_contact_idx").on(t.contactId)
154
+ ]);
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1,55 @@
1
+ import { db, schema } from "@nuxthub/db";
2
+ import { and, eq } from "drizzle-orm";
3
+ import { isEmailAddress, normaliseEmail } from "../../utils/payloads.js";
4
+ const DEFAULT_FIELDS = { name: "name", email: "email", phone: "phone", subject: "subject", message: "message" };
5
+ const text = (value) => {
6
+ if (typeof value === "string") return value.trim() || null;
7
+ if (typeof value === "number" || typeof value === "boolean") return String(value);
8
+ if (Array.isArray(value)) return value.map(String).join(", ") || null;
9
+ return null;
10
+ };
11
+ const typedEmail = (value) => {
12
+ const raw = text(value);
13
+ if (!raw) return null;
14
+ const email = normaliseEmail(raw);
15
+ return isEmailAddress(email) ? email : null;
16
+ };
17
+ export default defineNitroPlugin((nitro) => {
18
+ nitro.hooks.hook("forms:submitted", async (ctx) => {
19
+ const accounts = await db.select().from(schema.inboxChannelAccounts).where(and(eq(schema.inboxChannelAccounts.channel, "form"), eq(schema.inboxChannelAccounts.enabled, true)));
20
+ const slug = ctx.form.slug.toLowerCase();
21
+ const matching = accounts.filter((account) => account.address === slug || account.address === ctx.form.id.toLowerCase());
22
+ if (!matching.length) return;
23
+ const own = ctx.userId !== null ? (await loadUserRefs([ctx.userId])).get(Number(ctx.userId))?.email?.toLowerCase() ?? null : null;
24
+ for (const account of matching) {
25
+ const fields = { ...DEFAULT_FIELDS, ...account.config?.fields };
26
+ const answers = ctx.answers;
27
+ const email = typedEmail(answers[fields.email]);
28
+ const message = text(answers[fields.message]);
29
+ const body = message ?? Object.entries(answers).map(([key, value]) => `${key}: ${text(value) ?? ""}`).join("\n");
30
+ const signedIn = ctx.userId !== null;
31
+ const verified = signedIn && (email ? email === own : true);
32
+ const externalContact = email ?? (signedIn ? `user:${ctx.userId}` : `submission:${ctx.submissionId ?? crypto.randomUUID()}`);
33
+ try {
34
+ const result = await inboxReceive(ctx.event, "form", {
35
+ contact: {
36
+ externalId: externalContact,
37
+ name: text(answers[fields.name]),
38
+ email,
39
+ phone: text(answers[fields.phone]),
40
+ // Never from an unverified submission: the typed address may be someone else's.
41
+ userId: verified ? ctx.userId : null
42
+ },
43
+ externalId: ctx.submissionId ?? crypto.randomUUID(),
44
+ subject: inboxCleanSubject(text(answers[fields.subject]) ?? ctx.form.name),
45
+ authenticated: verified,
46
+ body,
47
+ attachments: ctx.files.map((file) => ({ filename: file.filename, contentType: file.contentType, size: file.size, ...file.pathname ? { pathname: file.pathname } : {} }))
48
+ }, account);
49
+ if (result.status !== "ignored") ctx.delivered = true;
50
+ } catch (error) {
51
+ console.error(`[inbox] the submission of "${ctx.form.slug}" could not be stored in the inbox`, error);
52
+ }
53
+ }
54
+ });
55
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1,18 @@
1
+ export default defineNitroPlugin((nitro) => {
2
+ nitro.hooks.hook("inbox:thread:linked", async (ctx) => {
3
+ try {
4
+ const thread = await findInboxThread(ctx.threadId);
5
+ if (!thread || ctx.actorId === null) return;
6
+ if (!await inboxUserCanAccessThread(ctx.event, ctx.actorId, thread)) return;
7
+ await inboxAudit(ctx.event, {
8
+ action: "linked",
9
+ threadId: thread.id,
10
+ contactId: thread.contactId,
11
+ actorId: ctx.actorId,
12
+ data: { module: ctx.module, kind: ctx.kind, label: ctx.label ?? null, userId: ctx.userId ?? null, url: ctx.url ?? null }
13
+ });
14
+ } catch (error) {
15
+ console.error("[inbox] could not record a linked action", error);
16
+ }
17
+ });
18
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1,24 @@
1
+ import { readTranslated } from "@frigear-nu/notify/utils";
2
+ export default defineNitroPlugin((nitro) => {
3
+ nitro.hooks.hook("inbox:message:received", async (ctx) => {
4
+ const assigneeId = ctx.thread.assigneeId;
5
+ if (!assigneeId) return;
6
+ try {
7
+ if (!await inboxUserCanAccessThread(ctx.event, assigneeId, ctx.thread)) return;
8
+ const pages = useRuntimeConfig(ctx.event).public.inbox?.pages;
9
+ const url = pages?.adminThread?.replace(":id", encodeURIComponent(ctx.thread.id));
10
+ const title = { da: "Ny besked i indbakken", en: "New inbox message" };
11
+ const body = { da: "Der er en ny besked i en tr\xE5d, du er tildelt.", en: "There is a new message in a thread assigned to you." };
12
+ const locale = (await loadUserRefs([assigneeId])).get(assigneeId)?.locale || "en";
13
+ const subject = readTranslated(title, locale);
14
+ const text = readTranslated(body, locale);
15
+ await notifyUser(assigneeId, {
16
+ topic: "inbox.message",
17
+ push: { title, body, ...url ? { url } : {} },
18
+ email: { subject, body: `<p>${text}</p>`, text }
19
+ });
20
+ } catch (error) {
21
+ console.error("[inbox] could not notify the assignee", error);
22
+ }
23
+ });
24
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1,7 @@
1
+ export default defineNitroPlugin((nitroApp) => {
2
+ if (import.meta.prerender) return;
3
+ nitroApp.hooks.hook("request", async (event) => {
4
+ if (getRequestHeader(event, "x-nitro-prerender")) return;
5
+ await inboxEnsureMailboxesSeeded(event);
6
+ });
7
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1,3 @@
1
+ export default defineNitroPlugin(() => {
2
+ setInboxTeamLeadResolver((event, userId, teamId) => isTeamLead(event, userId, teamId));
3
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: any[];
2
+ export default _default;
@@ -0,0 +1,15 @@
1
+ const isThread = (record) => "mailboxId" in record;
2
+ function inboxRecordAllowed(event, user, record) {
3
+ const subject = inboxCallerSubject(event, user);
4
+ return isThread(record) ? inboxCanAccessThread(event, subject, record) : inboxCanAccessMailbox(event, subject, record);
5
+ }
6
+ export default [
7
+ definePolicy("inbox:read", async ({ event, user, record }) => {
8
+ if (!record) return void 0;
9
+ return inboxRecordAllowed(event, user, record);
10
+ }),
11
+ definePolicy("inbox:reply", async ({ event, user, record }) => {
12
+ if (!record) return void 0;
13
+ return inboxRecordAllowed(event, user, record);
14
+ })
15
+ ];
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1,43 @@
1
+ import { db, schema } from "@nuxthub/db";
2
+ import { and, count, eq, getTableColumns, inArray, isNotNull, isNull, or } from "drizzle-orm";
3
+ import { orderByQuery, pageRange, paginate } from "@frigear-nu/module-kit/server";
4
+ import { inboxAccess } from "../../../access.js";
5
+ export default defineEventHandler(async (event) => {
6
+ await authorize(event, inboxAccess.permissions["inbox-audit:pii"]);
7
+ const query = await getValidatedQuery(event, inboxAuditQuery.parse);
8
+ const audit = schema.inboxAudit;
9
+ const threads = schema.inboxThreads;
10
+ const readable = (await inboxReadableMailboxes(event)).map((mailbox) => mailbox.id);
11
+ const manage = await allows(event, inboxAccess.permissions.manage);
12
+ if (!readable.length && !manage) return paginate({ items: [], total: 0, query });
13
+ const roles = await inboxCallerRoles(event);
14
+ const notHidden = roles.length ? or(isNull(threads.hiddenBelow), inArray(threads.hiddenBelow, roles)) : isNull(threads.hiddenBelow);
15
+ const visible = [];
16
+ if (readable.length) {
17
+ visible.push(
18
+ and(isNotNull(threads.id), inArray(threads.mailboxId, readable), notHidden),
19
+ and(isNull(threads.id), isNotNull(audit.mailboxId), inArray(audit.mailboxId, readable)),
20
+ and(isNull(audit.threadId), isNull(audit.mailboxId), isNotNull(audit.contactId), inArray(
21
+ audit.contactId,
22
+ db.select({ contactId: threads.contactId }).from(threads).where(and(inArray(threads.mailboxId, readable), notHidden))
23
+ ))
24
+ );
25
+ }
26
+ if (manage) visible.push(and(isNull(threads.id), isNull(audit.mailboxId), isNull(audit.contactId)));
27
+ const conditions = [or(...visible)];
28
+ if (query.threadId) conditions.push(eq(audit.threadId, query.threadId));
29
+ if (query.contactId) conditions.push(eq(audit.contactId, query.contactId));
30
+ if (query.action) conditions.push(eq(audit.action, query.action));
31
+ const where = and(...conditions);
32
+ const { limit, offset } = pageRange(query);
33
+ const [rows, [totals]] = await Promise.all([
34
+ db.select(getTableColumns(audit)).from(audit).leftJoin(threads, eq(threads.id, audit.threadId)).where(where).orderBy(...orderByQuery({ createdAt: audit.createdAt }, query, { tiebreaker: audit.id })).limit(limit).offset(offset),
35
+ db.select({ total: count() }).from(audit).leftJoin(threads, eq(threads.id, audit.threadId)).where(where)
36
+ ]);
37
+ const users = await inboxUserRefs(rows.map((row) => row.actorId));
38
+ return paginate({
39
+ total: Number(totals?.total ?? 0),
40
+ query,
41
+ items: rows.map((row) => toInboxAuditDto(row, row.actorId ? users.get(row.actorId) ?? null : null))
42
+ });
43
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1,13 @@
1
+ import { db, schema } from "@nuxthub/db";
2
+ import { eq } from "drizzle-orm";
3
+ import { idParams, noContent, notFound } from "@frigear-nu/module-kit/server";
4
+ import { inboxAccess } from "../../../access.js";
5
+ export default defineEventHandler(async (event) => {
6
+ await authorize(event, inboxAccess.permissions.channels);
7
+ const { id } = await getValidatedRouterParams(event, idParams().parse);
8
+ const row = await findInboxChannelAccount(id);
9
+ if (!row) throw notFound("Channel account not found.");
10
+ await db.update(schema.inboxThreads).set({ channelAccountId: null }).where(eq(schema.inboxThreads.channelAccountId, row.id));
11
+ await db.delete(schema.inboxChannelAccounts).where(eq(schema.inboxChannelAccounts.id, row.id));
12
+ return noContent(event);
13
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1,24 @@
1
+ import { db, schema } from "@nuxthub/db";
2
+ import { and, eq, ne } from "drizzle-orm";
3
+ import { conflict, idParams, notFound } from "@frigear-nu/module-kit/server";
4
+ import { inboxAccess } from "../../../access.js";
5
+ export default defineEventHandler(async (event) => {
6
+ await authorize(event, inboxAccess.permissions.channels);
7
+ const { id } = await getValidatedRouterParams(event, idParams().parse);
8
+ const input = await readValidatedBody(event, inboxChannelPatchInput.parse);
9
+ const row = await findInboxChannelAccount(id);
10
+ if (!row) throw notFound("Channel account not found.");
11
+ const values = {};
12
+ if (input.address !== void 0) {
13
+ const address = inboxNormaliseAddress(row.channel, input.address);
14
+ const [taken] = await db.select({ id: schema.inboxChannelAccounts.id }).from(schema.inboxChannelAccounts).where(and(eq(schema.inboxChannelAccounts.channel, row.channel), eq(schema.inboxChannelAccounts.address, address), ne(schema.inboxChannelAccounts.id, row.id))).limit(1);
15
+ if (taken) throw conflict("This address is already connected to a mailbox.", { field: "address" });
16
+ values.address = address;
17
+ }
18
+ if (input.config !== void 0) values.config = input.config;
19
+ if (input.secretRef !== void 0) values.secretRef = input.secretRef;
20
+ if (input.enabled !== void 0) values.enabled = input.enabled;
21
+ if (!Object.keys(values).length) return toInboxChannelAccountDto(row, !!inboxSecret(row.secretRef, event));
22
+ const [updated] = await db.update(schema.inboxChannelAccounts).set(values).where(eq(schema.inboxChannelAccounts.id, row.id)).returning();
23
+ return toInboxChannelAccountDto(updated, !!inboxSecret(updated.secretRef, event));
24
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1,10 @@
1
+ import { db, schema } from "@nuxthub/db";
2
+ import { asc, eq } from "drizzle-orm";
3
+ import { z } from "zod";
4
+ import { inboxAccess } from "../../../access.js";
5
+ export default defineEventHandler(async (event) => {
6
+ await authorize(event, inboxAccess.permissions.channels);
7
+ const query = await getValidatedQuery(event, z.object({ mailboxId: z.string().trim().min(1).max(64).optional() }).parse);
8
+ const rows = await db.select().from(schema.inboxChannelAccounts).where(query.mailboxId ? eq(schema.inboxChannelAccounts.mailboxId, query.mailboxId) : void 0).orderBy(asc(schema.inboxChannelAccounts.channel), asc(schema.inboxChannelAccounts.address));
9
+ return rows.map((row) => toInboxChannelAccountDto(row, !!inboxSecret(row.secretRef, event)));
10
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1,21 @@
1
+ import { db, schema } from "@nuxthub/db";
2
+ import { conflict, created, validationError } from "@frigear-nu/module-kit/server";
3
+ import { newId } from "@frigear-nu/module-kit/id";
4
+ import { inboxAccess } from "../../../access.js";
5
+ export default defineEventHandler(async (event) => {
6
+ await authorize(event, inboxAccess.permissions.channels);
7
+ const input = await readValidatedBody(event, inboxChannelCreateInput.parse);
8
+ if (!inboxChannel(input.channel)) throw validationError([{ path: ["channel"], message: `The channel "${input.channel}" is not installed.` }], "Unknown channel");
9
+ const mailbox = await getInboxMailboxOr404(input.mailboxId);
10
+ const [row] = await db.insert(schema.inboxChannelAccounts).values({
11
+ id: newId("ica"),
12
+ mailboxId: mailbox.id,
13
+ channel: input.channel,
14
+ address: inboxNormaliseAddress(input.channel, input.address),
15
+ config: input.config,
16
+ secretRef: input.secretRef ?? null,
17
+ enabled: input.enabled
18
+ }).onConflictDoNothing().returning();
19
+ if (!row) throw conflict("This address is already connected to a mailbox.", { field: "address" });
20
+ return created(event, toInboxChannelAccountDto(row, !!inboxSecret(row.secretRef, event)));
21
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1,20 @@
1
+ import { apiError, idParams, notFound } from "@frigear-nu/module-kit/server";
2
+ import { inboxAccess } from "../../../access.js";
3
+ export default defineEventHandler(async (event) => {
4
+ await authorize(event, inboxAccess.permissions.manage);
5
+ await authorize(event, inboxAccess.permissions.pii);
6
+ const { id } = await getValidatedRouterParams(event, idParams().parse);
7
+ const contact = await findInboxContact(id);
8
+ if (!contact) throw notFound("Contact not found.");
9
+ const scope = await inboxContactScope(contact);
10
+ const all = [...scope.threads, ...scope.foreign];
11
+ const visible = await inboxVisibleThreads(event, all);
12
+ if (all.length && !visible.length) throw notFound("Contact not found.");
13
+ if (visible.length < all.length) {
14
+ throw apiError(409, "contact_threads_hidden", "Some of this contact's threads are hidden from you. Someone who sees all of them must erase the contact.");
15
+ }
16
+ const erased = await inboxEraseContact(contact.id, /* @__PURE__ */ new Date(), scope);
17
+ await inboxAudit(event, { action: "erased", contactId: contact.id, data: erased });
18
+ const row = await findInboxContact(contact.id);
19
+ return { ...toInboxContactDto(row, true), ...erased };
20
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1,41 @@
1
+ import { db, schema } from "@nuxthub/db";
2
+ import { asc, inArray, ne, and } from "drizzle-orm";
3
+ import { apiError, chunkParams, idParams, isoDate, notFound } from "@frigear-nu/module-kit/server";
4
+ import { inboxAccess } from "../../../access.js";
5
+ export default defineEventHandler(async (event) => {
6
+ await authorize(event, inboxAccess.permissions.pii);
7
+ const { id } = await getValidatedRouterParams(event, idParams().parse);
8
+ const contact = await findInboxContact(id);
9
+ if (!contact) throw notFound("Contact not found.");
10
+ const scope = await inboxContactScope(contact);
11
+ const all = [...scope.threads, ...scope.foreign];
12
+ const visible = await inboxVisibleThreads(event, all);
13
+ if (!visible.length && (all.length || !await allows(event, inboxAccess.permissions.manage))) throw notFound("Contact not found.");
14
+ if (visible.length < all.length) {
15
+ throw apiError(409, "contact_threads_hidden", "Some of this contact's threads are hidden from you. Someone who sees all of them must export the contact.");
16
+ }
17
+ const messages = [];
18
+ for (const chunk of chunkParams(all.map((thread) => thread.id))) {
19
+ messages.push(...await db.select().from(schema.inboxMessages).where(and(inArray(schema.inboxMessages.threadId, chunk), ne(schema.inboxMessages.direction, "note"))).orderBy(asc(schema.inboxMessages.createdAtMs)));
20
+ }
21
+ const foreignIds = new Set(scope.foreign.map((thread) => thread.id));
22
+ const sentHere = new Set(scope.foreignMessageIds);
23
+ const related = [];
24
+ for (const chunk of chunkParams(scope.contactIds.filter((contactId) => contactId !== contact.id))) {
25
+ related.push(...await db.select().from(schema.inboxContacts).where(inArray(schema.inboxContacts.id, chunk)).orderBy(asc(schema.inboxContacts.createdAt)));
26
+ }
27
+ await inboxAudit(event, { action: "exported", contactId: contact.id, data: { threads: all.length, contacts: scope.contactIds.length } });
28
+ const details = (row) => ({ ...toInboxContactDetails(row), createdAt: isoDate(row.createdAt), erasedAt: isoDate(row.erasedAt) });
29
+ return {
30
+ contact: details(contact),
31
+ related: related.map(details),
32
+ threads: all.map((thread) => ({
33
+ thread: toInboxThreadDto(thread),
34
+ messages: messages.filter((message) => message.threadId === thread.id && (!foreignIds.has(thread.id) || sentHere.has(message.id))).map((message) => {
35
+ const { author: _author, ...rest } = toInboxMessageDto(message, null, true);
36
+ return rest;
37
+ })
38
+ })),
39
+ exportedAt: (/* @__PURE__ */ new Date()).toISOString()
40
+ };
41
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1,14 @@
1
+ import { db, schema } from "@nuxthub/db";
2
+ import { eq } from "drizzle-orm";
3
+ import { apiError, idParams, noContent } from "@frigear-nu/module-kit/server";
4
+ import { inboxAccess } from "../../../access.js";
5
+ export default defineEventHandler(async (event) => {
6
+ await authorize(event, inboxAccess.permissions.manage);
7
+ const { id } = await getValidatedRouterParams(event, idParams().parse);
8
+ const row = await getInboxMailboxOr404(id);
9
+ const [thread] = await db.select({ id: schema.inboxThreads.id }).from(schema.inboxThreads).where(eq(schema.inboxThreads.mailboxId, row.id)).limit(1);
10
+ if (thread) throw apiError(409, "mailbox_not_empty", "This mailbox still has threads.");
11
+ await db.delete(schema.inboxChannelAccounts).where(eq(schema.inboxChannelAccounts.mailboxId, row.id));
12
+ await db.delete(schema.inboxMailboxes).where(eq(schema.inboxMailboxes.id, row.id));
13
+ return noContent(event);
14
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1,9 @@
1
+ import { idParams, notFound } from "@frigear-nu/module-kit/server";
2
+ import { inboxAccess } from "../../../access.js";
3
+ export default defineEventHandler(async (event) => {
4
+ await authorize(event, inboxAccess.permissions.read);
5
+ const { id } = await getValidatedRouterParams(event, idParams().parse);
6
+ const row = await findInboxMailbox(id);
7
+ if (!row || !await allows(event, inboxAccess.permissions.read, row)) throw notFound("Mailbox not found.");
8
+ return toInboxMailboxDto(row);
9
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1,17 @@
1
+ import { db, schema } from "@nuxthub/db";
2
+ import { eq } from "drizzle-orm";
3
+ import { idParams } from "@frigear-nu/module-kit/server";
4
+ import { inboxAccess } from "../../../access.js";
5
+ export default defineEventHandler(async (event) => {
6
+ await authorize(event, inboxAccess.permissions.manage);
7
+ const { id } = await getValidatedRouterParams(event, idParams().parse);
8
+ const input = await readValidatedBody(event, inboxMailboxPatchInput.parse);
9
+ const row = await getInboxMailboxOr404(id);
10
+ const values = {};
11
+ if (input.name !== void 0) values.name = input.name;
12
+ if (input.grants !== void 0) values.grants = await inboxCheckMailboxGrants(event, row.ownerType, input.grants, row.grants);
13
+ if (input.retentionDays !== void 0) values.retentionDays = input.retentionDays;
14
+ if (!Object.keys(values).length) return toInboxMailboxDto(row);
15
+ const [updated] = await db.update(schema.inboxMailboxes).set(values).where(eq(schema.inboxMailboxes.id, row.id)).returning();
16
+ return toInboxMailboxDto(updated);
17
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1,5 @@
1
+ import { inboxAccess } from "../../../access.js";
2
+ export default defineEventHandler(async (event) => {
3
+ await authorize(event, inboxAccess.permissions.read);
4
+ return (await inboxReadableMailboxes(event)).map(toInboxMailboxDto);
5
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1,22 @@
1
+ import { db, schema } from "@nuxthub/db";
2
+ import { conflict, created } from "@frigear-nu/module-kit/server";
3
+ import { newId } from "@frigear-nu/module-kit/id";
4
+ import { inboxAccess } from "../../../access.js";
5
+ export default defineEventHandler(async (event) => {
6
+ await authorize(event, inboxAccess.permissions.manage);
7
+ const input = await readValidatedBody(event, inboxMailboxCreateInput.parse);
8
+ const owner = await inboxCheckMailboxOwner(event, input.ownerType, input.ownerId ?? null);
9
+ const grants = await inboxCheckMailboxGrants(event, input.ownerType, input.grants ?? []);
10
+ if (await findInboxMailboxByKey(input.key)) throw conflict("A mailbox with this key already exists.", { field: "key" });
11
+ const [row] = await db.insert(schema.inboxMailboxes).values({
12
+ id: newId("ibx"),
13
+ key: input.key,
14
+ ownerType: input.ownerType,
15
+ ownerId: owner,
16
+ name: input.name,
17
+ grants,
18
+ retentionDays: input.retentionDays ?? null
19
+ }).onConflictDoNothing().returning();
20
+ if (!row) throw conflict("A mailbox with this key already exists.", { field: "key" });
21
+ return created(event, toInboxMailboxDto(row));
22
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;