@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,242 @@
1
+ import { defineNuxtModule, createResolver, hasNuxtModule, addTypeTemplate, addServerImportsDir, addServerPlugin, addImports, addComponentsDir } from '@nuxt/kit';
2
+ import { registerModule, registerTailwindSource, registerLocales, resolvePagePath, defineVirtualRegistry, registerDatabaseTable, registerSearchIndex, addModuleRoutes, inlineModuleRuntime, addModulePages, addOptionalMenuSource } from '@frigear-nu/module-kit/utils';
3
+ import { registerAccess, addPolicies } from '@frigear-nu/auth/utils';
4
+ import { extendNotificationTopics } from '@frigear-nu/notify/utils';
5
+ import { inboxAccess } from '../dist/runtime/access.js';
6
+ import { buildInboxRegistry } from '../dist/runtime/utils/registry.js';
7
+
8
+ const MODULE_NAME = "@frigear-nu/inbox";
9
+ function builtInExtension(resolve) {
10
+ return {
11
+ channels: [
12
+ { id: "form", label: { da: "Kontaktformular", en: "Contact form" }, icon: "i-lucide-file-text", adapter: resolve("./runtime/channels/form") },
13
+ { id: "email", label: { da: "E-mail", en: "Email" }, icon: "i-lucide-mail", adapter: resolve("./runtime/channels/email") },
14
+ { id: "whatsapp", label: "WhatsApp", icon: "i-lucide-message-circle", adapter: resolve("./runtime/channels/whatsapp") },
15
+ { id: "messenger", label: "Messenger", icon: "i-lucide-messages-square", adapter: resolve("./runtime/channels/messenger") },
16
+ { id: "instagram", label: "Instagram", icon: "i-lucide-instagram", adapter: resolve("./runtime/channels/instagram") }
17
+ ]
18
+ };
19
+ }
20
+ function serverRegistryTemplate(registry) {
21
+ const ids = Object.keys(registry.adapters);
22
+ const lines = ids.map((id, index) => `import adapter${index} from ${JSON.stringify(registry.adapters[id])}`);
23
+ lines.push(`export const channels = ${JSON.stringify(registry.channels)}`);
24
+ lines.push(`export const adapters = {${ids.map((id, index) => `${JSON.stringify(id)}: adapter${index}`).join(", ")}}`);
25
+ return `${lines.join("\n")}
26
+ `;
27
+ }
28
+ const module$1 = defineNuxtModule({
29
+ meta: { name: MODULE_NAME, configKey: "inbox" },
30
+ defaults: {
31
+ settings: { pages: {} }
32
+ },
33
+ moduleDependencies: {
34
+ "@nuxthub/core": { version: ">=0.10" },
35
+ "@frigear-nu/module-kit": { version: ">=0.0.1" },
36
+ "@frigear-nu/auth": { version: ">=0.0.1" },
37
+ // Assignees, authors and actors are users: their names come from the `users` table.
38
+ "@frigear-nu/users": { version: ">=0.0.1" },
39
+ "@frigear-nu/notify": { version: ">=0.0.1" },
40
+ "@frigear-nu/ui": { version: ">=0.0.1" },
41
+ "@frigear-nu/menu": { version: ">=0.0.1", optional: true },
42
+ // Renders the `inbox.thread.actions` slot of the thread page, which other modules fill (`extendWidgets`).
43
+ "@frigear-nu/widget": { version: ">=0.0.0" },
44
+ // Provides the admin route and shell the staff pages live in; the page components come from `@frigear-nu/ui`.
45
+ "@frigear-nu/admin": { version: ">=0.0.0", optional: true }
46
+ },
47
+ async setup(options, nuxt) {
48
+ registerModule(MODULE_NAME, nuxt);
49
+ const resolver = createResolver(import.meta.url);
50
+ registerAccess(nuxt, inboxAccess, { from: MODULE_NAME });
51
+ addPolicies(nuxt, { path: resolver.resolve("./runtime/server/policies") });
52
+ registerTailwindSource(nuxt, resolver.resolve("./runtime/app"));
53
+ registerLocales(nuxt, resolver.resolve("./runtime/i18n/lang"));
54
+ const settings = options.settings ?? {};
55
+ let adminPath;
56
+ let adminThreadPath;
57
+ let adminSettingsPath;
58
+ if (hasNuxtModule("@frigear-nu/admin")) {
59
+ const { adminRoute } = await import('@frigear-nu/admin/utils');
60
+ adminPath = resolvePagePath(settings.pages?.admin, adminRoute(nuxt, "inbox"));
61
+ adminThreadPath = resolvePagePath(settings.pages?.adminThread, adminRoute(nuxt, "inbox", "threads", ":id"));
62
+ adminSettingsPath = resolvePagePath(settings.pages?.adminSettings, adminRoute(nuxt, "inbox", "settings"));
63
+ }
64
+ nuxt.options.runtimeConfig.public.inbox = {
65
+ pages: { admin: adminPath, adminThread: adminThreadPath, adminSettings: adminSettingsPath }
66
+ };
67
+ const existing = nuxt.options.runtimeConfig.inbox ?? {};
68
+ const runtime = {
69
+ retention: {
70
+ days: options.retention?.days ?? existing.retention?.days ?? 365,
71
+ mode: options.retention?.mode ?? existing.retention?.mode ?? "delete",
72
+ batch: options.retention?.batch ?? existing.retention?.batch ?? 500,
73
+ tombstoneDays: options.retention?.tombstoneDays ?? existing.retention?.tombstoneDays ?? 365
74
+ },
75
+ email: { webhookSecret: options.email?.webhookSecret ?? existing.email?.webhookSecret ?? "" },
76
+ meta: {
77
+ appSecret: options.meta?.appSecret ?? existing.meta?.appSecret ?? "",
78
+ verifyToken: options.meta?.verifyToken ?? existing.meta?.verifyToken ?? "",
79
+ apiBase: options.meta?.apiBase ?? existing.meta?.apiBase ?? "https://graph.facebook.com",
80
+ apiVersion: options.meta?.apiVersion ?? existing.meta?.apiVersion ?? "v21.0",
81
+ timeoutMs: options.meta?.timeoutMs ?? existing.meta?.timeoutMs ?? 1e4
82
+ },
83
+ secrets: { ...existing.secrets, ...options.secrets },
84
+ mailboxes: [...existing.mailboxes ?? [], ...options.mailboxes ?? []]
85
+ };
86
+ nuxt.options.runtimeConfig.inbox = runtime;
87
+ let built;
88
+ const registryOf = () => {
89
+ if (built) return built;
90
+ const stash = nuxt.options.inbox?._extensions ?? [];
91
+ const { registry, issues } = buildInboxRegistry([
92
+ builtInExtension((path) => resolver.resolve(path)),
93
+ ...stash,
94
+ { channels: options.channels }
95
+ ]);
96
+ if (issues.length) throw new Error(`[${MODULE_NAME}] Invalid inbox channels:
97
+ - ${issues.join("\n- ")}`);
98
+ built = registry;
99
+ return registry;
100
+ };
101
+ nuxt.hook("modules:done", () => {
102
+ registryOf();
103
+ });
104
+ defineVirtualRegistry(nuxt, {
105
+ filename: "inbox/registry.mjs",
106
+ alias: "#inbox/registry",
107
+ collect: registryOf,
108
+ contents: (registry) => `export const channels = ${JSON.stringify(registry.channels)}
109
+ `
110
+ });
111
+ defineVirtualRegistry(nuxt, {
112
+ filename: "#inbox/server-registry",
113
+ target: "server",
114
+ collect: registryOf,
115
+ contents: serverRegistryTemplate
116
+ });
117
+ const types = JSON.stringify(resolver.resolve("./types"));
118
+ addTypeTemplate({
119
+ filename: "types/inbox-registry.d.ts",
120
+ getContents: () => `declare module '#inbox/registry' {
121
+ import type { InboxChannelInfo } from ${types}
122
+ export const channels: Record<string, InboxChannelInfo>
123
+ }
124
+ declare module '#inbox/server-registry' {
125
+ import type { InboxChannelAdapter, InboxChannelInfo } from ${types}
126
+ export const channels: Record<string, InboxChannelInfo>
127
+ export const adapters: Record<string, InboxChannelAdapter>
128
+ }
129
+ `
130
+ }, { nitro: true, nuxt: true });
131
+ registerDatabaseTable(nuxt, {
132
+ resolver,
133
+ schema: (dialect) => `./runtime/server/db/schema.${dialect}`
134
+ });
135
+ registerSearchIndex(nuxt, { name: "inbox_threads", handler: resolver.resolve("./runtime/server/search-index") });
136
+ addModuleRoutes(resolver, [
137
+ { method: "get", path: "summary", file: "admin/summary.get" },
138
+ { method: "get", path: "mailboxes", file: "admin/mailboxes.get" },
139
+ { method: "post", path: "mailboxes", file: "admin/mailboxes.post" },
140
+ { method: "get", path: "mailboxes/:id", file: "admin/mailbox.get" },
141
+ { method: "patch", path: "mailboxes/:id", file: "admin/mailbox.patch" },
142
+ { method: "delete", path: "mailboxes/:id", file: "admin/mailbox.delete" },
143
+ { method: "get", path: "threads", file: "admin/threads.get" },
144
+ { method: "get", path: "threads/:id", file: "admin/thread.get" },
145
+ { method: "patch", path: "threads/:id", file: "admin/thread.patch" },
146
+ { method: "get", path: "threads/:id/assignees", file: "admin/thread-assignees.get" },
147
+ { method: "post", path: "threads/:id/messages", file: "admin/thread-messages.post" },
148
+ { method: "post", path: "threads/:id/notes", file: "admin/thread-notes.post" },
149
+ { method: "post", path: "threads/:id/hide", file: "admin/thread-hide.post" },
150
+ { method: "get", path: "channels", file: "admin/channels.get" },
151
+ { method: "post", path: "channels", file: "admin/channels.post" },
152
+ { method: "patch", path: "channels/:id", file: "admin/channel.patch" },
153
+ { method: "delete", path: "channels/:id", file: "admin/channel.delete" },
154
+ { method: "get", path: "audit", file: "admin/audit.get" },
155
+ { method: "get", path: "contacts/:id/export", file: "admin/contact-export.get" },
156
+ { method: "post", path: "contacts/:id/erase", file: "admin/contact-erase.post" }
157
+ ], { base: "/api/admin/inbox" });
158
+ addModuleRoutes(resolver, [
159
+ { method: "post", path: "email", file: "webhooks/email.post" },
160
+ { method: "get", path: "meta", file: "webhooks/meta.get" },
161
+ { method: "post", path: "meta", file: "webhooks/meta.post" },
162
+ { method: "post", path: ":channel", file: "webhooks/channel.post" }
163
+ ], { base: "/api/inbox/webhooks" });
164
+ addServerImportsDir(resolver.resolve("./runtime/server/utils"));
165
+ inlineModuleRuntime(nuxt, resolver);
166
+ addServerPlugin(resolver.resolve("./runtime/server/plugins/seed"));
167
+ if (hasNuxtModule("@frigear-nu/forms")) addServerPlugin(resolver.resolve("./runtime/server/plugins/forms"));
168
+ if (hasNuxtModule("@frigear-nu/teams")) addServerPlugin(resolver.resolve("./runtime/server/plugins/teams"));
169
+ extendNotificationTopics(nuxt, [{
170
+ id: "inbox.message",
171
+ label: { da: "Nye beskeder i indbakken", en: "New inbox messages" },
172
+ description: { da: "N\xE5r nogen skriver i en tr\xE5d, du er tildelt.", en: "When someone writes in a thread assigned to you." },
173
+ defaults: { email: false, sms: false, push: true },
174
+ channels: ["email", "push"]
175
+ }]);
176
+ addServerPlugin(resolver.resolve("./runtime/server/plugins/notify"));
177
+ addServerPlugin(resolver.resolve("./runtime/server/plugins/links"));
178
+ const cron = options.retention?.cron === void 0 ? "30 3 * * *" : options.retention.cron;
179
+ nuxt.hook("nitro:config", (nitroConfig) => {
180
+ nitroConfig.experimental ||= {};
181
+ nitroConfig.experimental.tasks = true;
182
+ nitroConfig.tasks ||= {};
183
+ nitroConfig.tasks["inbox:retention"] = {
184
+ handler: resolver.resolve("./runtime/server/tasks/retention"),
185
+ description: "Delete or anonymise closed inbox threads older than their mailbox keeps them."
186
+ };
187
+ if (cron) {
188
+ nitroConfig.scheduledTasks ||= {};
189
+ const scheduled = nitroConfig.scheduledTasks[cron];
190
+ nitroConfig.scheduledTasks[cron] = [...Array.isArray(scheduled) ? scheduled : scheduled ? [scheduled] : [], "inbox:retention"];
191
+ }
192
+ });
193
+ if (cron) {
194
+ nuxt.hook("nitro:init", (nitro) => {
195
+ if (!nitro.options.preset.startsWith("cloudflare")) return;
196
+ const wrangler = (nitro.options.cloudflare ||= {}).wrangler ||= {};
197
+ wrangler.triggers = { ...wrangler.triggers, crons: [.../* @__PURE__ */ new Set([...wrangler.triggers?.crons ?? [], cron])] };
198
+ });
199
+ }
200
+ addImports([
201
+ { name: "useInboxTranslate", from: resolver.resolve("./runtime/app/composables/useInboxTranslate") },
202
+ { name: "useInboxLinks", from: resolver.resolve("./runtime/app/composables/useInboxLinks") },
203
+ { name: "useInboxMailboxActions", from: resolver.resolve("./runtime/app/composables/useInboxMailboxActions") },
204
+ { name: "useInboxChannelActions", from: resolver.resolve("./runtime/app/composables/useInboxChannelActions") },
205
+ { name: "useInboxThreadActions", from: resolver.resolve("./runtime/app/composables/useInboxThreadActions") }
206
+ ]);
207
+ addComponentsDir({ path: resolver.resolve("./runtime/app/components") });
208
+ addModulePages(MODULE_NAME, resolver, [
209
+ { name: "inbox-admin", path: adminPath, file: "./runtime/app/pages/admin.vue" },
210
+ { name: "inbox-admin-thread", path: adminThreadPath, file: "./runtime/app/pages/admin-thread.vue" },
211
+ { name: "inbox-admin-settings", path: adminSettingsPath, file: "./runtime/app/pages/admin-settings.vue" }
212
+ ]);
213
+ const dashboard = settings.dashboard === void 0 ? "crew.home" : settings.dashboard;
214
+ if (dashboard && adminThreadPath && hasNuxtModule("@frigear-nu/dashboard")) await addDashboardItems(nuxt, dashboard, resolver.resolve);
215
+ addOptionalMenuSource(nuxt, { file: resolver.resolve("./runtime/menus"), menu: "admin.nav" });
216
+ }
217
+ });
218
+ async function addDashboardItems(nuxt, name, resolve) {
219
+ const { extendDashboard } = await import('@frigear-nu/dashboard/utils');
220
+ extendDashboard(nuxt, name, [
221
+ {
222
+ id: "inbox.unassigned",
223
+ component: resolve("./runtime/app/dashboard/InboxUnassigned.vue"),
224
+ title: "Unassigned messages",
225
+ titleKey: "inbox.dashboard.unassigned",
226
+ order: 70,
227
+ platforms: ["web"],
228
+ permission: inboxAccess.permissions.read
229
+ },
230
+ {
231
+ id: "inbox.mine",
232
+ component: resolve("./runtime/app/dashboard/InboxMine.vue"),
233
+ title: "Assigned to me",
234
+ titleKey: "inbox.dashboard.mine",
235
+ order: 71,
236
+ platforms: ["web"],
237
+ permission: inboxAccess.permissions.read
238
+ }
239
+ ]);
240
+ }
241
+
242
+ export { module$1 as default };
@@ -0,0 +1 @@
1
+ export declare const inboxAccess: import("@frigear-nu/auth/access").Access<"inbox", "read" | "reply" | "assign" | "hide" | "manage" | "pii" | "channels" | "inbox-audit:pii", never, never>;
@@ -0,0 +1,62 @@
1
+ import { defineAccess } from "@frigear-nu/auth/access";
2
+ export const inboxAccess = defineAccess("inbox", {
3
+ permissions: {
4
+ // Held by every signed-in user and narrowed by the policy: staff with `inbox:manage` read every mailbox, a team's
5
+ // leads read the team's mailbox, anyone else whom the mailbox's `grants` admit. A mailbox with an empty
6
+ // list is staff only (and its team's leads), never "every signed-in user". A hidden thread needs its `hiddenBelow` role on top.
7
+ "read": {
8
+ sessionOnly: true,
9
+ label: "Read inboxes",
10
+ description: "Read the threads of the mailboxes you have access to.",
11
+ implicit: true
12
+ },
13
+ // The same narrowing as `inbox:read`: whoever reads a mailbox answers in it.
14
+ "reply": {
15
+ sessionOnly: true,
16
+ label: "Answer in inboxes",
17
+ description: "Reply to the threads of the mailboxes you have access to, write internal notes and change their status.",
18
+ implicit: true
19
+ },
20
+ "assign": {
21
+ sessionOnly: true,
22
+ label: "Assign inbox threads",
23
+ description: "Assign threads to the people who answer them.",
24
+ grantTo: ["admin"]
25
+ },
26
+ "hide": {
27
+ sessionOnly: true,
28
+ label: "Hide inbox threads",
29
+ description: "Hide a thread from everybody below one of your own roles.",
30
+ grantTo: ["admin"]
31
+ },
32
+ "manage": {
33
+ sessionOnly: true,
34
+ label: "Manage inboxes",
35
+ description: "Create, edit and delete mailboxes, read every mailbox and erase contacts.",
36
+ grantTo: ["admin"]
37
+ },
38
+ // Outsiders' email addresses and phone numbers. Never covered by a wildcard.
39
+ "pii": {
40
+ sessionOnly: true,
41
+ label: "See inbox contact details",
42
+ description: "See the email address, phone number and channel id of the people who write in, and export their data.",
43
+ sensitive: true,
44
+ grantTo: ["admin"]
45
+ },
46
+ // Channel credentials: a token can never change them.
47
+ "channels": {
48
+ label: "Manage inbox channels",
49
+ description: "Connect the contact form, email addresses, WhatsApp numbers and Meta pages to mailboxes.",
50
+ sessionOnly: true,
51
+ grantTo: ["admin"]
52
+ },
53
+ // Who read and answered what. Never covered by a wildcard.
54
+ "inbox-audit:pii": {
55
+ sessionOnly: true,
56
+ label: "Read the inbox audit log",
57
+ description: "See who viewed, answered, assigned, hid, exported and erased what.",
58
+ sensitive: true,
59
+ grantTo: ["admin"]
60
+ }
61
+ }
62
+ });
@@ -0,0 +1,12 @@
1
+ import type { InboxChannelAccountDto, InboxMailboxDto } from '../../../types.js';
2
+ type __VLS_Props = {
3
+ account?: InboxChannelAccountDto;
4
+ mailboxes: InboxMailboxDto[];
5
+ };
6
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
7
+ close: (saved: false | InboxChannelAccountDto) => any;
8
+ }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
9
+ onClose?: ((saved: false | InboxChannelAccountDto) => any) | undefined;
10
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
11
+ declare const _default: typeof __VLS_export;
12
+ export default _default;
@@ -0,0 +1,171 @@
1
+ <script setup>
2
+ import { z } from "zod";
3
+ import { channels } from "#inbox/registry";
4
+ import { inboxApi } from "../../utils/api";
5
+ import { $fetch, computed, reactive, useAction, useInboxTranslate, useModuleT } from "#imports";
6
+ defineOptions({ name: "InboxChannelSlideover" });
7
+ const props = defineProps({
8
+ account: { type: Object, required: false },
9
+ mailboxes: { type: Array, required: true }
10
+ });
11
+ const emit = defineEmits(["close"]);
12
+ const t = useModuleT("inbox");
13
+ const tr = useInboxTranslate();
14
+ const { busy, run } = useAction();
15
+ const config = props.account?.config ?? {};
16
+ const fields = config.fields ?? {};
17
+ const state = reactive({
18
+ mailboxId: props.account?.mailboxId ?? props.mailboxes[0]?.id ?? "",
19
+ channel: props.account?.channel ?? "email",
20
+ address: props.account?.address ?? "",
21
+ secretRef: props.account?.secretRef ?? "",
22
+ enabled: props.account?.enabled ?? true,
23
+ replyTo: typeof config.replyTo === "string" ? config.replyTo : "",
24
+ nameField: fields.name ?? "",
25
+ emailField: fields.email ?? "",
26
+ messageField: fields.message ?? ""
27
+ });
28
+ const channelOptions = computed(() => Object.values(channels).map((channel) => ({ label: tr(channel.label) || channel.id, value: channel.id, icon: channel.icon })));
29
+ const mailboxOptions = computed(() => props.mailboxes.map((mailbox) => ({ label: tr(mailbox.name) || mailbox.key, value: mailbox.id })));
30
+ const needsSecret = computed(() => ["whatsapp", "messenger", "instagram"].includes(state.channel));
31
+ const addressHelp = computed(() => ({
32
+ email: t("channels.addressEmail", "The address people write to, such as support@example.com."),
33
+ form: t("channels.addressForm", "The slug of the form, such as contact."),
34
+ whatsapp: t("channels.addressWhatsapp", "The phone number id of the WhatsApp Business number (not the phone number)."),
35
+ messenger: t("channels.addressMessenger", "The id of the Facebook page."),
36
+ instagram: t("channels.addressInstagram", "The id of the Instagram professional account.")
37
+ })[state.channel] ?? t("channels.addressOther", "The identity of the mailbox on this channel."));
38
+ const schema = z.object({
39
+ mailboxId: z.string().min(1, t("channels.mailboxRequired", "Choose a mailbox.")),
40
+ channel: z.string().min(1),
41
+ address: z.string().trim().min(1, t("channels.addressRequired", "Fill in the address.")),
42
+ secretRef: z.string().trim().regex(/^$|^[A-Z][A-Z0-9_]{0,63}$/, t("channels.secretRefHelp", 'Upper case letters, digits and "_", such as WHATSAPP_TOKEN.'))
43
+ });
44
+ function buildConfig() {
45
+ const next = { ...config };
46
+ delete next.replyTo;
47
+ delete next.fields;
48
+ if (state.replyTo.trim()) next.replyTo = state.replyTo.trim();
49
+ if (state.channel === "form") {
50
+ const mapped = Object.fromEntries(Object.entries({ name: state.nameField, email: state.emailField, message: state.messageField }).filter(([, value]) => value.trim()).map(([key, value]) => [key, value.trim()]));
51
+ if (Object.keys(mapped).length) next.fields = mapped;
52
+ }
53
+ return next;
54
+ }
55
+ async function save() {
56
+ const body = { address: state.address.trim(), secretRef: state.secretRef.trim() || null, enabled: state.enabled, config: buildConfig() };
57
+ const saved = await run(
58
+ () => props.account ? $fetch(inboxApi.admin.channel(props.account.id), { method: "PATCH", body }) : $fetch(inboxApi.admin.channels, { method: "POST", body: { ...body, mailboxId: state.mailboxId, channel: state.channel } }),
59
+ { success: props.account ? t("channels.saved", "Saved {address}", { address: body.address }) : t("channels.connected", "Connected {address}", { address: body.address }) }
60
+ );
61
+ if (saved) emit("close", saved);
62
+ }
63
+ </script>
64
+
65
+ <template>
66
+ <FormSlideover
67
+ form-id="inbox-channel-form"
68
+ :title="account ? t('settings.editChannel', 'Edit channel') : t('settings.addChannel', 'Connect channel')"
69
+ :description="account ? void 0 : t('channels.description', 'Messages to this address land in the mailbox, and replies go out the same way.')"
70
+ :submit-label="account ? t('channels.save', 'Save channel') : t('channels.connect', 'Connect channel')"
71
+ :loading="busy"
72
+ @close="emit('close', false)"
73
+ >
74
+ <UForm
75
+ id="inbox-channel-form"
76
+ :schema="schema"
77
+ :state="state"
78
+ class="flex flex-col gap-4"
79
+ @submit="save"
80
+ >
81
+ <UFormField
82
+ v-if="!account"
83
+ name="mailboxId"
84
+ :label="t('channels.mailbox', 'Mailbox')"
85
+ required
86
+ >
87
+ <USelect
88
+ v-model="state.mailboxId"
89
+ :items="mailboxOptions"
90
+ class="w-full"
91
+ />
92
+ </UFormField>
93
+ <UFormField
94
+ v-if="!account"
95
+ name="channel"
96
+ :label="t('channels.channel', 'Channel')"
97
+ required
98
+ >
99
+ <USelect
100
+ v-model="state.channel"
101
+ :items="channelOptions"
102
+ class="w-full"
103
+ />
104
+ </UFormField>
105
+ <UFormField
106
+ name="address"
107
+ :label="t('channels.address', 'Address')"
108
+ :description="addressHelp"
109
+ required
110
+ >
111
+ <UInput
112
+ v-model="state.address"
113
+ class="w-full"
114
+ />
115
+ </UFormField>
116
+ <UFormField
117
+ name="secretRef"
118
+ :label="t('channels.secretRef', 'Secret name')"
119
+ :description="needsSecret ? t('channels.secretRefMeta', 'The name of the access token in the server config: inbox.secrets.NAME, set with NUXT_INBOX_SECRETS_NAME.') : t('channels.secretRefOptional', 'Only for channels that need a token of their own.')"
120
+ :required="needsSecret"
121
+ >
122
+ <UInput
123
+ v-model="state.secretRef"
124
+ placeholder="WHATSAPP_TOKEN"
125
+ class="w-full font-mono"
126
+ />
127
+ </UFormField>
128
+ <UFormField
129
+ v-if="state.channel === 'email' || state.channel === 'form'"
130
+ name="replyTo"
131
+ :label="t('channels.replyTo', 'Reply-To address')"
132
+ :description="t('channels.replyToHelp', 'Where answers to replies go. Defaults to the address above, or the mailbox\'s email address.')"
133
+ >
134
+ <UInput
135
+ v-model="state.replyTo"
136
+ type="email"
137
+ class="w-full"
138
+ />
139
+ </UFormField>
140
+ <template v-if="state.channel === 'form'">
141
+ <UFormField
142
+ name="fields"
143
+ :label="t('channels.fields', 'Form fields')"
144
+ :description="t('channels.fieldsHelp', 'The field keys of the name, email and message. Defaults: name, email, message.')"
145
+ >
146
+ <div class="grid grid-cols-3 gap-2">
147
+ <UInput
148
+ v-model="state.nameField"
149
+ placeholder="name"
150
+ />
151
+ <UInput
152
+ v-model="state.emailField"
153
+ placeholder="email"
154
+ />
155
+ <UInput
156
+ v-model="state.messageField"
157
+ placeholder="message"
158
+ />
159
+ </div>
160
+ </UFormField>
161
+ </template>
162
+ <UFormField
163
+ name="enabled"
164
+ :label="t('channels.enabled', 'On')"
165
+ :description="t('channels.enabledHelp', 'A channel that is off drops new messages and sends no replies.')"
166
+ >
167
+ <USwitch v-model="state.enabled" />
168
+ </UFormField>
169
+ </UForm>
170
+ </FormSlideover>
171
+ </template>
@@ -0,0 +1,12 @@
1
+ import type { InboxChannelAccountDto, InboxMailboxDto } from '../../../types.js';
2
+ type __VLS_Props = {
3
+ account?: InboxChannelAccountDto;
4
+ mailboxes: InboxMailboxDto[];
5
+ };
6
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
7
+ close: (saved: false | InboxChannelAccountDto) => any;
8
+ }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
9
+ onClose?: ((saved: false | InboxChannelAccountDto) => any) | undefined;
10
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
11
+ declare const _default: typeof __VLS_export;
12
+ export default _default;
@@ -0,0 +1,12 @@
1
+ import type { InboxThreadDto } from '../../../types.js';
2
+ type __VLS_Props = {
3
+ thread: InboxThreadDto;
4
+ disabled?: boolean;
5
+ };
6
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
7
+ sent: () => any;
8
+ }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
9
+ onSent?: (() => any) | undefined;
10
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
11
+ declare const _default: typeof __VLS_export;
12
+ export default _default;
@@ -0,0 +1,71 @@
1
+ <script setup>
2
+ import { channels } from "#inbox/registry";
3
+ import { inboxApi } from "../../utils/api";
4
+ import { $fetch, computed, ref, useAction, useInboxTranslate, useModuleT } from "#imports";
5
+ defineOptions({ name: "InboxComposer" });
6
+ const props = defineProps({
7
+ thread: { type: Object, required: true },
8
+ disabled: { type: Boolean, required: false }
9
+ });
10
+ const emit = defineEmits(["sent"]);
11
+ const t = useModuleT("inbox");
12
+ const tr = useInboxTranslate();
13
+ const { busy, run } = useAction();
14
+ const mode = ref("reply");
15
+ const body = ref("");
16
+ const channelLabel = computed(() => tr(channels[props.thread.channel]?.label) || props.thread.channel);
17
+ const modes = computed(() => [
18
+ { label: t("composer.reply", "Reply"), value: "reply", icon: "i-lucide-reply" },
19
+ { label: t("composer.note", "Internal note"), value: "note", icon: "i-lucide-sticky-note" }
20
+ ]);
21
+ async function send(status) {
22
+ const text = body.value.trim();
23
+ if (!text) return;
24
+ const done = await run(
25
+ () => mode.value === "reply" ? $fetch(inboxApi.admin.messages(props.thread.id), { method: "POST", body: { body: text, ...status ? { status } : {} } }) : $fetch(inboxApi.admin.notes(props.thread.id), { method: "POST", body: { body: text } }),
26
+ { success: mode.value === "reply" ? t("composer.sent", "Reply sent by {channel}", { channel: channelLabel.value }) : t("composer.noted", "Note added") }
27
+ );
28
+ if (!done) return;
29
+ body.value = "";
30
+ emit("sent");
31
+ }
32
+ </script>
33
+
34
+ <template>
35
+ <div class="flex flex-col gap-3">
36
+ <UTabs
37
+ v-model="mode"
38
+ :items="modes"
39
+ :content="false"
40
+ size="sm"
41
+ class="w-fit"
42
+ />
43
+ <UTextarea
44
+ v-model="body"
45
+ :rows="4"
46
+ autoresize
47
+ :disabled="disabled"
48
+ :placeholder="mode === 'reply' ? t('composer.replyPlaceholder', 'Write a reply. It goes out by {channel}.', { channel: channelLabel }) : t('composer.notePlaceholder', 'Write a note for the team. It is never sent.')"
49
+ :aria-label="mode === 'reply' ? t('composer.reply', 'Reply') : t('composer.note', 'Internal note')"
50
+ class="w-full"
51
+ />
52
+ <div class="flex flex-wrap justify-end gap-2">
53
+ <UButton
54
+ v-if="mode === 'reply'"
55
+ color="neutral"
56
+ variant="outline"
57
+ :disabled="disabled || !body.trim()"
58
+ :loading="busy"
59
+ :label="t('composer.sendAndClose', 'Send and close')"
60
+ @click="send('closed')"
61
+ />
62
+ <UButton
63
+ :icon="mode === 'reply' ? 'i-lucide-send' : 'i-lucide-sticky-note'"
64
+ :disabled="disabled || !body.trim()"
65
+ :loading="busy"
66
+ :label="mode === 'reply' ? t('composer.send', 'Send reply') : t('composer.addNote', 'Add note')"
67
+ @click="send()"
68
+ />
69
+ </div>
70
+ </div>
71
+ </template>
@@ -0,0 +1,12 @@
1
+ import type { InboxThreadDto } from '../../../types.js';
2
+ type __VLS_Props = {
3
+ thread: InboxThreadDto;
4
+ disabled?: boolean;
5
+ };
6
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
7
+ sent: () => any;
8
+ }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
9
+ onSent?: (() => any) | undefined;
10
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
11
+ declare const _default: typeof __VLS_export;
12
+ export default _default;
@@ -0,0 +1,8 @@
1
+ import type { InboxMessageDto } from '../../../types.js';
2
+ type __VLS_Props = {
3
+ messages: InboxMessageDto[];
4
+ contactName?: string | null;
5
+ };
6
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
7
+ declare const _default: typeof __VLS_export;
8
+ export default _default;