@frigear-nu/inbox 0.0.0-stage → 0.0.1

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
package/README.md CHANGED
@@ -1,3 +1,40 @@
1
- # Temporary Holding Version
1
+ # @frigear-nu/inbox
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Shared support inboxes for Nuxt apps built on this ecosystem. Messages from the website contact form, email, WhatsApp, Messenger and
4
+ Instagram land in mailboxes that staff read together: they assign threads, write internal notes, hide threads from
5
+ lower roles and reply, and the reply goes out through the channel the message came in on. Every view and reply is in
6
+ an audit log, closed threads are deleted (or anonymised) after a retention period, and a contact's data can be
7
+ exported and erased.
8
+
9
+ ```bash
10
+ pnpm add @frigear-nu/inbox
11
+ ```
12
+
13
+ ```ts
14
+ // nuxt.config.ts
15
+ export default defineNuxtConfig({
16
+ // `@frigear-nu/authorization` brings the `role` grant kind.
17
+ modules: ['@nuxthub/core', '@frigear-nu/users', '@frigear-nu/authorization', '@frigear-nu/forms', '@frigear-nu/inbox'],
18
+ hub: { db: 'sqlite' },
19
+ inbox: {
20
+ mailboxes: [{ key: 'support', name: 'Support', grants: [{ kind: 'role', role: 'coordinator' }] }],
21
+ settings: { pages: { admin: true, adminThread: true, adminSettings: true } },
22
+ },
23
+ })
24
+ ```
25
+
26
+ Secrets come from the environment, never the database: `NUXT_INBOX_EMAIL_WEBHOOK_SECRET`,
27
+ `NUXT_INBOX_META_APP_SECRET`, `NUXT_INBOX_META_VERIFY_TOKEN` and one `NUXT_INBOX_SECRETS_<REF>` per channel token
28
+ (declare the ref in `inbox.secrets` with an empty value so the variable applies).
29
+
30
+ | Export | What it does |
31
+ | --- | --- |
32
+ | `extendInbox`, `defineInboxChannel` (`@frigear-nu/inbox/utils`) | Register a channel (an adapter with `send` and an optional webhook `inbound`) from a module's `setup()`. |
33
+ | `inboxReceive`, `inboxRunRetention`, `inboxEraseContact` (server utils) | Store an inbound message, run retention, erase a contact. |
34
+ | `inboxApi` (`@frigear-nu/inbox/api`) | Typed paths of the HTTP API and the webhooks. |
35
+ | `inbox:message:received`, `inbox:message:sent`, `inbox:thread:assigned`, `inbox:thread:status-changed` | Nitro hooks. |
36
+
37
+ WhatsApp, Messenger and Instagram need Meta business verification, a WhatsApp Business number and app review before
38
+ they work: start those early.
39
+
40
+ Full reference: [docs.frigear.dev/modules/communication/inbox](https://docs.frigear.dev/modules/communication/inbox).
@@ -0,0 +1,452 @@
1
+ import * as _nuxt_schema from '@nuxt/schema';
2
+ import { H3Event } from 'h3';
3
+ import { Grant } from '@frigear-nu/auth/grants';
4
+ export { Grant } from '@frigear-nu/auth/grants';
5
+ export { OwnerRef } from '@frigear-nu/teams';
6
+
7
+ /** A text in one language, or one per locale code (`{ da: '...', en: '...' }`), as in `@frigear-nu/ui`. */
8
+ type Translated = string | Record<string, string>;
9
+ /** The built-in channels. Other modules add their own with `extendInbox`. */
10
+ type InboxBuiltInChannel = 'form' | 'email' | 'whatsapp' | 'messenger' | 'instagram';
11
+ /** A channel id: a built-in one or one a module registered. */
12
+ type InboxChannelId = InboxBuiltInChannel | (string & {});
13
+ /** `platform` and `team` mailboxes exist now; `user` mailboxes come with the user side of the inbox. */
14
+ type InboxMailboxOwnerType = 'platform' | 'team' | 'user';
15
+ type InboxThreadStatus = 'open' | 'pending' | 'closed';
16
+ /** `in`: from the contact. `out`: a reply that went out through the channel. `note`: internal, never sent. */
17
+ type InboxMessageDirection = 'in' | 'out' | 'note';
18
+ /** A file on a message: a NuxtHub Blob pathname (form uploads) or a provider URL, never the bytes themselves. */
19
+ type InboxAttachment = {
20
+ filename: string;
21
+ contentType?: string;
22
+ size?: number;
23
+ /** NuxtHub Blob pathname, for files a form stored. */
24
+ pathname?: string;
25
+ /** A link at the provider, for files an email or Meta webhook announced. */
26
+ url?: string;
27
+ };
28
+ /** One inbound message, normalised by a channel: what `inboxReceive` stores. */
29
+ type InboxInboundMessage = {
30
+ /** The channel account it arrived on: its id, or its `address` on the channel (an email address, a page id). */
31
+ accountId?: string;
32
+ address?: string;
33
+ /** The sender, identified on the channel by `externalId` (an email address, a WhatsApp id, a page-scoped id). */
34
+ contact: {
35
+ externalId: string;
36
+ name?: string | null;
37
+ email?: string | null;
38
+ phone?: string | null;
39
+ userId?: number | null;
40
+ };
41
+ /** The provider's id of the message: the same id twice is stored once (webhook retries). */
42
+ externalId: string;
43
+ subject?: string | null;
44
+ body: string;
45
+ attachments?: InboxAttachment[];
46
+ /** Email `Cc` recipients (lower case), stored on the message and shown with `inbox:pii`. */
47
+ cc?: string[];
48
+ /** A thread id the message answers (`[ibt_...]` in an email subject); used when it belongs to the same mailbox and contact. */
49
+ threadId?: string | null;
50
+ /**
51
+ * Whether the channel verified the sender: a signed-in user, Meta's signed webhook, an email that passed SPF, DKIM or
52
+ * DMARC. Only an authenticated message joins an existing thread or renames its contact; anything else (the default)
53
+ * starts a new thread.
54
+ */
55
+ authenticated?: boolean;
56
+ };
57
+ /** What a channel's `send` gets to deliver a reply. */
58
+ type InboxSendContext = {
59
+ event: H3Event;
60
+ mailbox: InboxMailboxDto;
61
+ /** The channel account the thread came in on, `null` when it was deleted since. */
62
+ account: InboxChannelAccountDto | null;
63
+ /** The account's secret (an access token), resolved from `secretRef`; never stored in the database. */
64
+ secret: string | undefined;
65
+ thread: InboxThreadDto;
66
+ /** The contact with their details, as the channel needs them to reach the person. */
67
+ contact: InboxContactDetails;
68
+ message: {
69
+ id: string;
70
+ body: string;
71
+ attachments: InboxAttachment[];
72
+ };
73
+ };
74
+ /** What a channel's `inbound` gets besides the request. */
75
+ type InboxInboundContext = {
76
+ /** The value of the adapter's `inboundSecret`, never empty: verify the request with it. */
77
+ secret: string;
78
+ /**
79
+ * The request body as text, read by the inbox with its webhook size limit (1 MB; a larger body is a 413 before the
80
+ * adapter runs). Verify a signature over it and parse it.
81
+ */
82
+ rawBody: string;
83
+ };
84
+ /** What a channel's `send` may return: the provider's id of the sent message. */
85
+ type InboxSendResult = {
86
+ externalId?: string | null;
87
+ /** The email addresses the channel copied (`Cc`), stored on the reply. Invalid addresses are dropped. */
88
+ cc?: string[] | null;
89
+ } | undefined;
90
+ /** A channel adapter, the default export of the file `extendInbox` names. */
91
+ type InboxChannelAdapter = {
92
+ id: string;
93
+ label?: Translated;
94
+ /**
95
+ * Reads a webhook on `POST /api/inbox/webhooks/:channel` and returns the messages in it. Verify the request here with
96
+ * `ctx.secret` (throw a 401 when the signature or token does not match). The inbox only calls it once
97
+ * `inboundSecret` names a configured secret: otherwise the webhook answers 501 `not_configured`, so a channel is never
98
+ * open by default. Built-in channels have routes of their own instead.
99
+ */
100
+ inbound?: (event: H3Event, ctx: InboxInboundContext) => InboxInboundMessage[] | Promise<InboxInboundMessage[]>;
101
+ /**
102
+ * The name of the `inbox.secrets` entry `inbound` verifies requests with (a signing secret or a shared token, e.g.
103
+ * `ACME_SMS_WEBHOOK`, set by `NUXT_INBOX_SECRETS_ACME_SMS_WEBHOOK`). Required with `inbound`.
104
+ */
105
+ inboundSecret?: string;
106
+ /** Delivers a reply. Throw to fail the reply: nothing is stored then. */
107
+ send: (ctx: InboxSendContext) => InboxSendResult | void | Promise<InboxSendResult | void>;
108
+ };
109
+ /** A channel registration of `extendInbox`: the label for the app, and the server file with the adapter. */
110
+ type InboxChannelDefinition = {
111
+ id: string;
112
+ label: Translated;
113
+ icon?: string;
114
+ /** Absolute path of a server file default-exporting `defineInboxChannel({ ... })`. */
115
+ adapter: string;
116
+ };
117
+ /** What a channel looks like to the app (`#inbox/registry`). */
118
+ type InboxChannelInfo = {
119
+ id: string;
120
+ label: Translated;
121
+ icon?: string;
122
+ };
123
+ type InboxExtension = {
124
+ channels?: InboxChannelDefinition[];
125
+ };
126
+ type InboxMailboxDto = {
127
+ id: string;
128
+ key: string;
129
+ ownerType: InboxMailboxOwnerType;
130
+ ownerId: string | null;
131
+ name: Translated;
132
+ /** Who reads it besides staff (and a team mailbox's leads): any one grant admits, never `public`. */
133
+ grants: Grant[];
134
+ /** Days a closed thread is kept; `null` takes `inbox.retention.days`. */
135
+ retentionDays: number | null;
136
+ createdAt: string;
137
+ updatedAt: string;
138
+ };
139
+ type InboxChannelAccountDto = {
140
+ id: string;
141
+ mailboxId: string;
142
+ channel: InboxChannelId;
143
+ /** The identity on the channel: an email address, a WhatsApp phone number id, a page id, a form slug. */
144
+ address: string;
145
+ /** Settings that are not secret (`fields` of a form account, `replyTo` of an email account). */
146
+ config: Record<string, unknown>;
147
+ /** The name of the secret in `inbox.secrets` (`NUXT_INBOX_SECRETS_<REF>`); the value is never stored or shown. */
148
+ secretRef: string | null;
149
+ /** Whether `secretRef` resolves to a value on this server. */
150
+ secretConfigured: boolean;
151
+ enabled: boolean;
152
+ createdAt: string;
153
+ updatedAt: string;
154
+ };
155
+ /** A contact as everyone with access to the thread sees them: no contact details. */
156
+ type InboxContactDto = {
157
+ id: string;
158
+ channel: InboxChannelId;
159
+ name: string | null;
160
+ /** Contact details, only with `inbox:pii`. */
161
+ email?: string | null;
162
+ phone?: string | null;
163
+ externalId?: string | null;
164
+ userId?: number | null;
165
+ erasedAt: string | null;
166
+ };
167
+ /** A contact with every detail, for channels and exports. */
168
+ type InboxContactDetails = {
169
+ id: string;
170
+ channel: InboxChannelId;
171
+ externalId: string;
172
+ name: string | null;
173
+ email: string | null;
174
+ phone: string | null;
175
+ userId: number | null;
176
+ };
177
+ type InboxUserRef = {
178
+ id: number;
179
+ name: string | null;
180
+ };
181
+ type InboxThreadDto = {
182
+ id: string;
183
+ mailboxId: string;
184
+ contactId: string;
185
+ channelAccountId: string | null;
186
+ channel: InboxChannelId;
187
+ subject: string | null;
188
+ status: InboxThreadStatus;
189
+ assigneeId: number | null;
190
+ /** `null`: everyone with access to the mailbox; otherwise only people at or above this global role. */
191
+ hiddenBelow: string | null;
192
+ lastMessageAt: string;
193
+ anonymisedAt: string | null;
194
+ createdAt: string;
195
+ updatedAt: string;
196
+ };
197
+ /** A row of the staff thread list. */
198
+ type InboxThreadListItemDto = InboxThreadDto & {
199
+ contact: InboxContactDto | null;
200
+ assignee: InboxUserRef | null;
201
+ /** The start of the last message that is not a note. */
202
+ preview: string | null;
203
+ };
204
+ type InboxMessageDto = {
205
+ id: string;
206
+ threadId: string;
207
+ direction: InboxMessageDirection;
208
+ authorId: number | null;
209
+ author: InboxUserRef | null;
210
+ body: string;
211
+ attachments: InboxAttachment[];
212
+ /** Email `Cc` recipients of an inbound message, or the people a reply copied; only with `inbox:pii`. */
213
+ cc?: string[] | null;
214
+ /**
215
+ * The contact who sent an inbound message (`null` for replies and notes): usually the thread's contact, another one
216
+ * for a reply by email in a contact form thread.
217
+ */
218
+ contactId: string | null;
219
+ createdAt: string;
220
+ };
221
+ /** What the caller may do with a thread, for the thread page. */
222
+ type InboxThreadAbilities = {
223
+ reply: boolean;
224
+ assign: boolean;
225
+ hide: boolean;
226
+ pii: boolean;
227
+ audit: boolean;
228
+ erase: boolean;
229
+ };
230
+ type InboxThreadDetailDto = {
231
+ thread: InboxThreadDto;
232
+ mailbox: InboxMailboxDto;
233
+ contact: InboxContactDto | null;
234
+ assignee: InboxUserRef | null;
235
+ messages: InboxMessageDto[];
236
+ can: InboxThreadAbilities;
237
+ /** The global roles the caller can hide a thread below (the roles they hold). */
238
+ hideRoles: string[];
239
+ };
240
+ type InboxAuditAction = 'viewed' | 'replied' | 'noted' | 'assigned' | 'status' | 'hidden' | 'exported' | 'erased' | 'retention' | 'linked';
241
+ type InboxAuditDto = {
242
+ id: string;
243
+ threadId: string | null;
244
+ contactId: string | null;
245
+ actorId: number | null;
246
+ actor: InboxUserRef | null;
247
+ action: InboxAuditAction;
248
+ data: Record<string, unknown> | null;
249
+ createdAt: string;
250
+ };
251
+ type InboxSummaryDto = {
252
+ /** Open or pending threads nobody is assigned to, in the mailboxes the caller reads. */
253
+ unassigned: number;
254
+ /** Open or pending threads assigned to the caller. */
255
+ mine: number;
256
+ /** Mailboxes the caller reads. */
257
+ mailboxes: number;
258
+ };
259
+ type InboxContactExportDto = {
260
+ contact: InboxContactDetails & {
261
+ createdAt: string;
262
+ erasedAt: string | null;
263
+ };
264
+ /** The other contacts of the same person: every contact with the same email address (one per channel). */
265
+ related: Array<InboxContactDetails & {
266
+ createdAt: string;
267
+ erasedAt: string | null;
268
+ }>;
269
+ /**
270
+ * Their threads with every message but internal notes, and the threads of other contacts they wrote in with only the
271
+ * messages they sent there.
272
+ */
273
+ threads: Array<{
274
+ thread: InboxThreadDto;
275
+ messages: Array<Omit<InboxMessageDto, 'author'>>;
276
+ }>;
277
+ exportedAt: string;
278
+ };
279
+ type InboxRetentionResult = {
280
+ mailboxes: number;
281
+ threads: number;
282
+ contacts: number;
283
+ mode: InboxRetentionMode;
284
+ /** Whether a mailbox had more expired threads than this run's budget let it handle: the next run goes on. */
285
+ more: boolean;
286
+ };
287
+ type InboxMessageContext = {
288
+ event: H3Event;
289
+ thread: InboxThreadDto;
290
+ message: InboxMessageDto;
291
+ };
292
+ type InboxThreadAssignedContext = {
293
+ event: H3Event;
294
+ thread: InboxThreadDto;
295
+ assigneeId: number | null;
296
+ previous: number | null;
297
+ };
298
+ type InboxThreadStatusContext = {
299
+ event: H3Event;
300
+ thread: InboxThreadDto;
301
+ from: InboxThreadStatus;
302
+ to: InboxThreadStatus;
303
+ };
304
+ /**
305
+ * `inbox:thread:linked`: `module` did `kind` for the thread's person (`userId`) from the thread `threadId`; `label` and
306
+ * `url` describe it on the audit trail ("Added to the crew of Summer 2027"). `actorId` is who did it.
307
+ */
308
+ type InboxThreadLinkedContext = {
309
+ event: H3Event;
310
+ threadId: string;
311
+ actorId: number | null;
312
+ module: string;
313
+ kind: string;
314
+ label?: string;
315
+ url?: string;
316
+ userId?: number | null;
317
+ };
318
+ /**
319
+ * What an `inbox.thread.actions` widget receives (as props) on the staff thread page: the thread, its contact (details
320
+ * only with `inbox:pii`; `userId` is the account of a verified contact) and `onChanged`, to refresh the page.
321
+ */
322
+ type InboxThreadActionContext = {
323
+ threadId: string;
324
+ contact: InboxContactDto | null;
325
+ onChanged: () => unknown;
326
+ };
327
+ type InboxRetentionMode = 'delete' | 'anonymise';
328
+ type InboxMailboxSeed = {
329
+ key: string;
330
+ name: Translated;
331
+ ownerType?: 'platform' | 'team';
332
+ ownerId?: string | null;
333
+ /** Who reads it besides staff. A platform mailbox names someone; `public` is refused. */
334
+ grants?: Grant[];
335
+ retentionDays?: number | null;
336
+ };
337
+ type ModuleOptions = {
338
+ /** Channels of the host, next to the built-in ones and those of other modules (`extendInbox`). */
339
+ channels?: InboxChannelDefinition[];
340
+ /** Mailboxes created on the first request when their key does not exist yet; never changed afterwards. */
341
+ mailboxes?: InboxMailboxSeed[];
342
+ retention?: {
343
+ /** Days a closed thread is kept when its mailbox sets none. Defaults to `365`; `false` keeps them. */
344
+ days?: number | false;
345
+ /** `delete` (default) removes the thread and its messages; `anonymise` keeps the thread and blanks every message. */
346
+ mode?: InboxRetentionMode;
347
+ /** Cron of the `inbox:retention` task. Defaults to `'30 3 * * *'`; `false` registers the task without a schedule. */
348
+ cron?: string | false;
349
+ /** Threads one run handles at most (D1 friendly). Defaults to `500`. */
350
+ batch?: number;
351
+ /**
352
+ * Days the provider ids of removed messages are remembered, so a replayed webhook is not stored again. Counted from
353
+ * when retention or an erase removed them. Defaults to `365`.
354
+ */
355
+ tombstoneDays?: number;
356
+ };
357
+ email?: {
358
+ /** HMAC secret of `POST /api/inbox/webhooks/email` (`NUXT_INBOX_EMAIL_WEBHOOK_SECRET`). */
359
+ webhookSecret?: string;
360
+ };
361
+ meta?: {
362
+ /** The Meta app secret: checks `X-Hub-Signature-256` (`NUXT_INBOX_META_APP_SECRET`). */
363
+ appSecret?: string;
364
+ /** The verify token entered in the Meta app's webhook settings (`NUXT_INBOX_META_VERIFY_TOKEN`). */
365
+ verifyToken?: string;
366
+ /** Defaults to `https://graph.facebook.com`. */
367
+ apiBase?: string;
368
+ /** Defaults to `v21.0`. */
369
+ apiVersion?: string;
370
+ /** Milliseconds a Graph API call may take. Defaults to `10000`. */
371
+ timeoutMs?: number;
372
+ };
373
+ /**
374
+ * Channel account secrets by `secretRef` (access tokens). Declare each ref with an empty value and set it with the
375
+ * `NUXT_INBOX_SECRETS_<REF>` environment variable, or set them all at once as JSON in `NUXT_INBOX_SECRETS`.
376
+ */
377
+ secrets?: Record<string, string>;
378
+ settings?: {
379
+ pages?: {
380
+ /** Staff thread list. `true` = `/admin/inbox`. Needs `@frigear-nu/admin`. */
381
+ admin?: string | boolean;
382
+ /** Staff thread page; must contain `:id`. `true` = `/admin/inbox/threads/:id`. */
383
+ adminThread?: string | boolean;
384
+ /** Mailbox and channel settings. `true` = `/admin/inbox/settings`. */
385
+ adminSettings?: string | boolean;
386
+ };
387
+ /** Add the `inbox.unassigned` and `inbox.mine` items to this dashboard when `@frigear-nu/dashboard` is installed. Defaults to `crew.home`; `false` adds none. */
388
+ dashboard?: string | false;
389
+ };
390
+ };
391
+ type PublicModuleOptions = {
392
+ pages: {
393
+ admin?: string;
394
+ adminThread?: string;
395
+ adminSettings?: string;
396
+ };
397
+ };
398
+ /** The server-only runtime config (`runtimeConfig.inbox`). */
399
+ type InboxRuntimeConfig = {
400
+ retention: {
401
+ days: number | false;
402
+ mode: InboxRetentionMode;
403
+ batch: number;
404
+ tombstoneDays: number;
405
+ };
406
+ email: {
407
+ webhookSecret: string;
408
+ };
409
+ meta: {
410
+ appSecret: string;
411
+ verifyToken: string;
412
+ apiBase: string;
413
+ apiVersion: string;
414
+ timeoutMs: number;
415
+ };
416
+ secrets: Record<string, string>;
417
+ mailboxes: InboxMailboxSeed[];
418
+ };
419
+
420
+ declare module '@nuxt/schema' {
421
+ interface NuxtConfig {
422
+ inbox?: ModuleOptions;
423
+ }
424
+ interface PublicRuntimeConfig {
425
+ inbox: PublicModuleOptions;
426
+ }
427
+ interface RuntimeConfig {
428
+ inbox: InboxRuntimeConfig;
429
+ }
430
+ }
431
+ declare module 'nitropack' {
432
+ interface NitroRuntimeHooks {
433
+ /** A message came in on a channel (a webhook, the contact form) and was stored. Not for a duplicate delivery. */
434
+ 'inbox:message:received': (ctx: InboxMessageContext) => void | Promise<void>;
435
+ /** A reply went out through the thread's channel and was stored. Notes fire nothing. */
436
+ 'inbox:message:sent': (ctx: InboxMessageContext) => void | Promise<void>;
437
+ /** A thread got another assignee (`null`: unassigned); `previous` is the one before. */
438
+ 'inbox:thread:assigned': (ctx: InboxThreadAssignedContext) => void | Promise<void>;
439
+ /** A thread's status changed: by staff, or a closed thread reopened by a new message. */
440
+ 'inbox:thread:status-changed': (ctx: InboxThreadStatusContext) => void | Promise<void>;
441
+ /**
442
+ * Another module did something for the thread's person from the thread (an action on the `inbox.thread.actions`
443
+ * slot, such as crew's "Add to crew"). Inbox records it on the thread's audit trail (`linked`) when the actor can
444
+ * read and answer the thread. Modules call it without depending on inbox: nothing listens when inbox is absent.
445
+ */
446
+ 'inbox:thread:linked': (ctx: InboxThreadLinkedContext) => void | Promise<void>;
447
+ }
448
+ }
449
+ declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
450
+
451
+ export { _default as default };
452
+ export type { InboxAttachment, InboxAuditAction, InboxAuditDto, InboxBuiltInChannel, InboxChannelAccountDto, InboxChannelAdapter, InboxChannelDefinition, InboxChannelId, InboxChannelInfo, InboxContactDetails, InboxContactDto, InboxContactExportDto, InboxExtension, InboxInboundContext, InboxInboundMessage, InboxMailboxDto, InboxMailboxOwnerType, InboxMailboxSeed, InboxMessageContext, InboxMessageDirection, InboxMessageDto, InboxRetentionMode, InboxRetentionResult, InboxRuntimeConfig, InboxSendContext, InboxSendResult, InboxSummaryDto, InboxThreadAbilities, InboxThreadActionContext, InboxThreadAssignedContext, InboxThreadDetailDto, InboxThreadDto, InboxThreadLinkedContext, InboxThreadListItemDto, InboxThreadStatus, InboxThreadStatusContext, InboxUserRef, ModuleOptions, PublicModuleOptions, Translated };
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "@frigear-nu/inbox",
3
+ "configKey": "inbox",
4
+ "version": "0.0.1",
5
+ "builder": {
6
+ "@nuxt/module-builder": "1.0.4",
7
+ "unbuild": "unknown"
8
+ }
9
+ }