@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.
- package/README.md +39 -2
- package/dist/module.d.mts +452 -0
- package/dist/module.json +9 -0
- package/dist/module.mjs +242 -0
- package/dist/runtime/access.d.ts +1 -0
- package/dist/runtime/access.js +62 -0
- package/dist/runtime/app/components/InboxChannelSlideover.d.vue.ts +12 -0
- package/dist/runtime/app/components/InboxChannelSlideover.vue +171 -0
- package/dist/runtime/app/components/InboxChannelSlideover.vue.d.ts +12 -0
- package/dist/runtime/app/components/InboxComposer.d.vue.ts +12 -0
- package/dist/runtime/app/components/InboxComposer.vue +71 -0
- package/dist/runtime/app/components/InboxComposer.vue.d.ts +12 -0
- package/dist/runtime/app/components/InboxConversation.d.vue.ts +8 -0
- package/dist/runtime/app/components/InboxConversation.vue +82 -0
- package/dist/runtime/app/components/InboxConversation.vue.d.ts +8 -0
- package/dist/runtime/app/components/InboxHideSlideover.d.vue.ts +12 -0
- package/dist/runtime/app/components/InboxHideSlideover.vue +54 -0
- package/dist/runtime/app/components/InboxHideSlideover.vue.d.ts +12 -0
- package/dist/runtime/app/components/InboxMailboxSlideover.d.vue.ts +11 -0
- package/dist/runtime/app/components/InboxMailboxSlideover.vue +125 -0
- package/dist/runtime/app/components/InboxMailboxSlideover.vue.d.ts +11 -0
- package/dist/runtime/app/composables/index.d.ts +6 -0
- package/dist/runtime/app/composables/index.js +5 -0
- package/dist/runtime/app/composables/useInboxChannelActions.d.ts +15 -0
- package/dist/runtime/app/composables/useInboxChannelActions.js +45 -0
- package/dist/runtime/app/composables/useInboxLinks.d.ts +11 -0
- package/dist/runtime/app/composables/useInboxLinks.js +17 -0
- package/dist/runtime/app/composables/useInboxMailboxActions.d.ts +14 -0
- package/dist/runtime/app/composables/useInboxMailboxActions.js +47 -0
- package/dist/runtime/app/composables/useInboxThreadActions.d.ts +29 -0
- package/dist/runtime/app/composables/useInboxThreadActions.js +76 -0
- package/dist/runtime/app/composables/useInboxTranslate.d.ts +3 -0
- package/dist/runtime/app/composables/useInboxTranslate.js +7 -0
- package/dist/runtime/app/dashboard/InboxMine.d.vue.ts +3 -0
- package/dist/runtime/app/dashboard/InboxMine.vue +25 -0
- package/dist/runtime/app/dashboard/InboxMine.vue.d.ts +3 -0
- package/dist/runtime/app/dashboard/InboxUnassigned.d.vue.ts +3 -0
- package/dist/runtime/app/dashboard/InboxUnassigned.vue +25 -0
- package/dist/runtime/app/dashboard/InboxUnassigned.vue.d.ts +3 -0
- package/dist/runtime/app/pages/admin-settings.d.vue.ts +3 -0
- package/dist/runtime/app/pages/admin-settings.vue +161 -0
- package/dist/runtime/app/pages/admin-settings.vue.d.ts +3 -0
- package/dist/runtime/app/pages/admin-thread.d.vue.ts +3 -0
- package/dist/runtime/app/pages/admin-thread.vue +234 -0
- package/dist/runtime/app/pages/admin-thread.vue.d.ts +3 -0
- package/dist/runtime/app/pages/admin.d.vue.ts +3 -0
- package/dist/runtime/app/pages/admin.vue +211 -0
- package/dist/runtime/app/pages/admin.vue.d.ts +3 -0
- package/dist/runtime/channels/email.d.ts +2 -0
- package/dist/runtime/channels/email.js +8 -0
- package/dist/runtime/channels/form.d.ts +2 -0
- package/dist/runtime/channels/form.js +9 -0
- package/dist/runtime/channels/instagram.d.ts +2 -0
- package/dist/runtime/channels/instagram.js +5 -0
- package/dist/runtime/channels/messenger.d.ts +2 -0
- package/dist/runtime/channels/messenger.js +5 -0
- package/dist/runtime/channels/whatsapp.d.ts +2 -0
- package/dist/runtime/channels/whatsapp.js +5 -0
- package/dist/runtime/i18n/lang/da.json +247 -0
- package/dist/runtime/i18n/lang/en.json +247 -0
- package/dist/runtime/menus.d.ts +2 -0
- package/dist/runtime/menus.js +19 -0
- package/dist/runtime/server/db/schema.postgresql.d.ts +1216 -0
- package/dist/runtime/server/db/schema.postgresql.js +154 -0
- package/dist/runtime/server/db/schema.sqlite.d.ts +1294 -0
- package/dist/runtime/server/db/schema.sqlite.js +154 -0
- package/dist/runtime/server/plugins/forms.d.ts +2 -0
- package/dist/runtime/server/plugins/forms.js +55 -0
- package/dist/runtime/server/plugins/links.d.ts +2 -0
- package/dist/runtime/server/plugins/links.js +18 -0
- package/dist/runtime/server/plugins/notify.d.ts +2 -0
- package/dist/runtime/server/plugins/notify.js +24 -0
- package/dist/runtime/server/plugins/seed.d.ts +2 -0
- package/dist/runtime/server/plugins/seed.js +7 -0
- package/dist/runtime/server/plugins/teams.d.ts +2 -0
- package/dist/runtime/server/plugins/teams.js +3 -0
- package/dist/runtime/server/policies.d.ts +2 -0
- package/dist/runtime/server/policies.js +15 -0
- package/dist/runtime/server/routes/admin/audit.get.d.ts +2 -0
- package/dist/runtime/server/routes/admin/audit.get.js +43 -0
- package/dist/runtime/server/routes/admin/channel.delete.d.ts +2 -0
- package/dist/runtime/server/routes/admin/channel.delete.js +13 -0
- package/dist/runtime/server/routes/admin/channel.patch.d.ts +2 -0
- package/dist/runtime/server/routes/admin/channel.patch.js +24 -0
- package/dist/runtime/server/routes/admin/channels.get.d.ts +2 -0
- package/dist/runtime/server/routes/admin/channels.get.js +10 -0
- package/dist/runtime/server/routes/admin/channels.post.d.ts +2 -0
- package/dist/runtime/server/routes/admin/channels.post.js +21 -0
- package/dist/runtime/server/routes/admin/contact-erase.post.d.ts +2 -0
- package/dist/runtime/server/routes/admin/contact-erase.post.js +20 -0
- package/dist/runtime/server/routes/admin/contact-export.get.d.ts +2 -0
- package/dist/runtime/server/routes/admin/contact-export.get.js +41 -0
- package/dist/runtime/server/routes/admin/mailbox.delete.d.ts +2 -0
- package/dist/runtime/server/routes/admin/mailbox.delete.js +14 -0
- package/dist/runtime/server/routes/admin/mailbox.get.d.ts +2 -0
- package/dist/runtime/server/routes/admin/mailbox.get.js +9 -0
- package/dist/runtime/server/routes/admin/mailbox.patch.d.ts +2 -0
- package/dist/runtime/server/routes/admin/mailbox.patch.js +17 -0
- package/dist/runtime/server/routes/admin/mailboxes.get.d.ts +2 -0
- package/dist/runtime/server/routes/admin/mailboxes.get.js +5 -0
- package/dist/runtime/server/routes/admin/mailboxes.post.d.ts +2 -0
- package/dist/runtime/server/routes/admin/mailboxes.post.js +22 -0
- package/dist/runtime/server/routes/admin/summary.get.d.ts +2 -0
- package/dist/runtime/server/routes/admin/summary.get.js +19 -0
- package/dist/runtime/server/routes/admin/thread-assignees.get.d.ts +2 -0
- package/dist/runtime/server/routes/admin/thread-assignees.get.js +11 -0
- package/dist/runtime/server/routes/admin/thread-hide.post.d.ts +2 -0
- package/dist/runtime/server/routes/admin/thread-hide.post.js +23 -0
- package/dist/runtime/server/routes/admin/thread-messages.post.d.ts +2 -0
- package/dist/runtime/server/routes/admin/thread-messages.post.js +10 -0
- package/dist/runtime/server/routes/admin/thread-notes.post.d.ts +2 -0
- package/dist/runtime/server/routes/admin/thread-notes.post.js +10 -0
- package/dist/runtime/server/routes/admin/thread.get.d.ts +2 -0
- package/dist/runtime/server/routes/admin/thread.get.js +27 -0
- package/dist/runtime/server/routes/admin/thread.patch.d.ts +2 -0
- package/dist/runtime/server/routes/admin/thread.patch.js +23 -0
- package/dist/runtime/server/routes/admin/threads.get.d.ts +2 -0
- package/dist/runtime/server/routes/admin/threads.get.js +49 -0
- package/dist/runtime/server/routes/webhooks/channel.post.d.ts +2 -0
- package/dist/runtime/server/routes/webhooks/channel.post.js +11 -0
- package/dist/runtime/server/routes/webhooks/email.post.d.ts +2 -0
- package/dist/runtime/server/routes/webhooks/email.post.js +38 -0
- package/dist/runtime/server/routes/webhooks/meta.get.d.ts +2 -0
- package/dist/runtime/server/routes/webhooks/meta.get.js +19 -0
- package/dist/runtime/server/routes/webhooks/meta.post.d.ts +2 -0
- package/dist/runtime/server/routes/webhooks/meta.post.js +29 -0
- package/dist/runtime/server/search-index.d.ts +2 -0
- package/dist/runtime/server/search-index.js +7 -0
- package/dist/runtime/server/tasks/retention.d.ts +2 -0
- package/dist/runtime/server/tasks/retention.js +12 -0
- package/dist/runtime/server/utils/inbox-audit.d.ts +17 -0
- package/dist/runtime/server/utils/inbox-audit.js +35 -0
- package/dist/runtime/server/utils/inbox-channels.d.ts +42 -0
- package/dist/runtime/server/utils/inbox-channels.js +73 -0
- package/dist/runtime/server/utils/inbox-config.d.ts +12 -0
- package/dist/runtime/server/utils/inbox-config.js +8 -0
- package/dist/runtime/server/utils/inbox-dto.d.ts +19 -0
- package/dist/runtime/server/utils/inbox-dto.js +92 -0
- package/dist/runtime/server/utils/inbox-ingest.d.ts +43 -0
- package/dist/runtime/server/utils/inbox-ingest.js +136 -0
- package/dist/runtime/server/utils/inbox-integrations.d.ts +7 -0
- package/dist/runtime/server/utils/inbox-integrations.js +13 -0
- package/dist/runtime/server/utils/inbox-mailboxes.d.ts +14 -0
- package/dist/runtime/server/utils/inbox-mailboxes.js +27 -0
- package/dist/runtime/server/utils/inbox-registry.d.ts +7 -0
- package/dist/runtime/server/utils/inbox-registry.js +10 -0
- package/dist/runtime/server/utils/inbox-retention.d.ts +57 -0
- package/dist/runtime/server/utils/inbox-retention.js +167 -0
- package/dist/runtime/server/utils/inbox-schemas.d.ts +123 -0
- package/dist/runtime/server/utils/inbox-schemas.js +78 -0
- package/dist/runtime/server/utils/inbox-search.d.ts +8 -0
- package/dist/runtime/server/utils/inbox-search.js +2 -0
- package/dist/runtime/server/utils/inbox-seed.d.ts +9 -0
- package/dist/runtime/server/utils/inbox-seed.js +35 -0
- package/dist/runtime/server/utils/inbox-send.d.ts +25 -0
- package/dist/runtime/server/utils/inbox-send.js +84 -0
- package/dist/runtime/server/utils/inbox-tombstones.d.ts +25 -0
- package/dist/runtime/server/utils/inbox-tombstones.js +47 -0
- package/dist/runtime/server/utils/inbox-webhooks.d.ts +8 -0
- package/dist/runtime/server/utils/inbox-webhooks.js +10 -0
- package/dist/runtime/server/utils/inbox.d.ts +79 -0
- package/dist/runtime/server/utils/inbox.js +134 -0
- package/dist/runtime/utils/api.d.ts +40 -0
- package/dist/runtime/utils/api.js +43 -0
- package/dist/runtime/utils/index.d.ts +44 -0
- package/dist/runtime/utils/index.js +27 -0
- package/dist/runtime/utils/payloads.d.ts +99 -0
- package/dist/runtime/utils/payloads.js +173 -0
- package/dist/runtime/utils/registry.d.ts +17 -0
- package/dist/runtime/utils/registry.js +29 -0
- package/dist/runtime/utils/signature.d.ts +14 -0
- package/dist/runtime/utils/signature.js +16 -0
- package/dist/types.d.mts +7 -0
- package/package.json +118 -3
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { db, schema } from "@nuxthub/db";
|
|
2
|
+
import { and, count, eq, inArray, isNull, or } from "drizzle-orm";
|
|
3
|
+
import { inboxAccess } from "../../../access.js";
|
|
4
|
+
export default defineEventHandler(async (event) => {
|
|
5
|
+
const principal = await authorize(event, inboxAccess.permissions.read);
|
|
6
|
+
const mailboxes = await inboxReadableMailboxes(event);
|
|
7
|
+
if (!mailboxes.length) return { unassigned: 0, mine: 0, mailboxes: 0 };
|
|
8
|
+
const roles = await inboxCallerRoles(event);
|
|
9
|
+
const base = and(
|
|
10
|
+
inArray(schema.inboxThreads.mailboxId, mailboxes.map((mailbox) => mailbox.id)),
|
|
11
|
+
inArray(schema.inboxThreads.status, ["open", "pending"]),
|
|
12
|
+
roles.length ? or(isNull(schema.inboxThreads.hiddenBelow), inArray(schema.inboxThreads.hiddenBelow, roles)) : isNull(schema.inboxThreads.hiddenBelow)
|
|
13
|
+
);
|
|
14
|
+
const [[unassigned], [mine]] = await Promise.all([
|
|
15
|
+
db.select({ total: count() }).from(schema.inboxThreads).where(and(base, isNull(schema.inboxThreads.assigneeId))),
|
|
16
|
+
db.select({ total: count() }).from(schema.inboxThreads).where(and(base, eq(schema.inboxThreads.assigneeId, Number(principal.user.id))))
|
|
17
|
+
]);
|
|
18
|
+
return { unassigned: Number(unassigned?.total ?? 0), mine: Number(mine?.total ?? 0), mailboxes: mailboxes.length };
|
|
19
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { idParams } 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
|
+
await authorize(event, inboxAccess.permissions.assign);
|
|
6
|
+
const { id } = await getValidatedRouterParams(event, idParams().parse);
|
|
7
|
+
const { q } = await getValidatedQuery(event, inboxAssigneesQuery.parse);
|
|
8
|
+
const thread = await getReadableInboxThreadOr404(event, id);
|
|
9
|
+
await authorize(event, inboxAccess.permissions.assign, thread);
|
|
10
|
+
return inboxAssigneeCandidates(event, thread, { q });
|
|
11
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { db, schema } from "@nuxthub/db";
|
|
2
|
+
import { eq } from "drizzle-orm";
|
|
3
|
+
import { idParams, validationError } from "@frigear-nu/module-kit/server";
|
|
4
|
+
import { inboxAccess } from "../../../access.js";
|
|
5
|
+
export default defineEventHandler(async (event) => {
|
|
6
|
+
await authorize(event, inboxAccess.permissions.hide);
|
|
7
|
+
const { id } = await getValidatedRouterParams(event, idParams().parse);
|
|
8
|
+
const input = await readValidatedBody(event, inboxHideInput.parse);
|
|
9
|
+
const thread = await getReadableInboxThreadOr404(event, id);
|
|
10
|
+
await authorize(event, inboxAccess.permissions.hide, thread);
|
|
11
|
+
if (input.role && !(await inboxCallerRoles(event)).includes(input.role)) {
|
|
12
|
+
throw validationError([{ path: ["role"], message: "Choose one of your own roles." }], "Invalid role");
|
|
13
|
+
}
|
|
14
|
+
if ((thread.hiddenBelow ?? null) === input.role) return toInboxThreadDto(thread);
|
|
15
|
+
let assigneeId = thread.assigneeId;
|
|
16
|
+
if (input.role && assigneeId && !await inboxUserCanAccessThread(event, assigneeId, { mailboxId: thread.mailboxId, hiddenBelow: input.role })) assigneeId = null;
|
|
17
|
+
const [updated] = await db.update(schema.inboxThreads).set({ hiddenBelow: input.role, assigneeId }).where(eq(schema.inboxThreads.id, thread.id)).returning();
|
|
18
|
+
await inboxAudit(event, { action: "hidden", threadId: thread.id, data: { from: thread.hiddenBelow ?? null, to: input.role } });
|
|
19
|
+
if (assigneeId !== thread.assigneeId) {
|
|
20
|
+
await useNitroApp().hooks.callHook("inbox:thread:assigned", { event, thread: toInboxThreadDto(updated), assigneeId, previous: thread.assigneeId ?? null });
|
|
21
|
+
}
|
|
22
|
+
return toInboxThreadDto(updated);
|
|
23
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { created, idParams } from "@frigear-nu/module-kit/server";
|
|
2
|
+
import { inboxAccess } from "../../../access.js";
|
|
3
|
+
export default defineEventHandler(async (event) => {
|
|
4
|
+
const principal = await authorize(event, inboxAccess.permissions.reply);
|
|
5
|
+
const { id } = await getValidatedRouterParams(event, idParams().parse);
|
|
6
|
+
const input = await readValidatedBody(event, inboxMessageInput.parse);
|
|
7
|
+
const thread = await getReadableInboxThreadOr404(event, id);
|
|
8
|
+
await authorize(event, inboxAccess.permissions.reply, thread);
|
|
9
|
+
return created(event, await inboxReply(event, thread, { body: input.body, authorId: Number(principal.user.id), status: input.status }));
|
|
10
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { created, idParams } from "@frigear-nu/module-kit/server";
|
|
2
|
+
import { inboxAccess } from "../../../access.js";
|
|
3
|
+
export default defineEventHandler(async (event) => {
|
|
4
|
+
const principal = await authorize(event, inboxAccess.permissions.reply);
|
|
5
|
+
const { id } = await getValidatedRouterParams(event, idParams().parse);
|
|
6
|
+
const input = await readValidatedBody(event, inboxNoteInput.parse);
|
|
7
|
+
const thread = await getReadableInboxThreadOr404(event, id);
|
|
8
|
+
await authorize(event, inboxAccess.permissions.reply, thread);
|
|
9
|
+
return created(event, await inboxAddNote(event, thread, { body: input.body, authorId: Number(principal.user.id) }));
|
|
10
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { db, schema } from "@nuxthub/db";
|
|
2
|
+
import { asc, 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.read);
|
|
7
|
+
const { id } = await getValidatedRouterParams(event, idParams().parse);
|
|
8
|
+
const thread = await getReadableInboxThreadOr404(event, id);
|
|
9
|
+
const [mailbox, contact, messages, can, roles] = await Promise.all([
|
|
10
|
+
findInboxMailbox(thread.mailboxId),
|
|
11
|
+
findInboxContact(thread.contactId),
|
|
12
|
+
db.select().from(schema.inboxMessages).where(eq(schema.inboxMessages.threadId, thread.id)).orderBy(asc(schema.inboxMessages.createdAtMs), asc(schema.inboxMessages.id)),
|
|
13
|
+
inboxAbilities(event, thread),
|
|
14
|
+
inboxCallerRoles(event)
|
|
15
|
+
]);
|
|
16
|
+
const users = await inboxUserRefs([thread.assigneeId, ...messages.map((message) => message.authorId)]);
|
|
17
|
+
await inboxAudit(event, { action: "viewed", threadId: thread.id });
|
|
18
|
+
return {
|
|
19
|
+
thread: toInboxThreadDto(thread),
|
|
20
|
+
mailbox: toInboxMailboxDto(mailbox),
|
|
21
|
+
contact: contact ? toInboxContactDto(contact, can.pii) : null,
|
|
22
|
+
assignee: thread.assigneeId ? users.get(thread.assigneeId) ?? { id: thread.assigneeId, name: null } : null,
|
|
23
|
+
messages: messages.map((message) => toInboxMessageDto(message, message.authorId ? users.get(message.authorId) ?? null : null, can.pii)),
|
|
24
|
+
can,
|
|
25
|
+
hideRoles: can.hide ? roles : []
|
|
26
|
+
};
|
|
27
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
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.read);
|
|
7
|
+
const { id } = await getValidatedRouterParams(event, idParams().parse);
|
|
8
|
+
const input = await readValidatedBody(event, inboxThreadPatchInput.parse);
|
|
9
|
+
if (input.status !== void 0) await authorize(event, inboxAccess.permissions.reply);
|
|
10
|
+
if (input.assigneeId !== void 0) await authorize(event, inboxAccess.permissions.assign);
|
|
11
|
+
let thread = await getReadableInboxThreadOr404(event, id);
|
|
12
|
+
if (input.status !== void 0) await authorize(event, inboxAccess.permissions.reply, thread);
|
|
13
|
+
if (input.assigneeId !== void 0) await authorize(event, inboxAccess.permissions.assign, thread);
|
|
14
|
+
if (input.assigneeId !== void 0 && input.assigneeId !== thread.assigneeId) {
|
|
15
|
+
if (input.assigneeId !== null) await inboxAssertAssignee(event, input.assigneeId, thread);
|
|
16
|
+
const previous = thread.assigneeId ?? null;
|
|
17
|
+
thread = (await db.update(schema.inboxThreads).set({ assigneeId: input.assigneeId }).where(eq(schema.inboxThreads.id, thread.id)).returning())[0];
|
|
18
|
+
await useNitroApp().hooks.callHook("inbox:thread:assigned", { event, thread: toInboxThreadDto(thread), assigneeId: input.assigneeId, previous });
|
|
19
|
+
await inboxAudit(event, { action: "assigned", threadId: thread.id, data: { from: previous, to: input.assigneeId } });
|
|
20
|
+
}
|
|
21
|
+
if (input.status !== void 0) thread = await inboxSetStatus(event, thread, input.status);
|
|
22
|
+
return toInboxThreadDto(thread);
|
|
23
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { db, schema } from "@nuxthub/db";
|
|
2
|
+
import { and, count, eq, inArray, isNull, or } from "drizzle-orm";
|
|
3
|
+
import { orderByQuery, pageRange, paginate, searchContains } from "@frigear-nu/module-kit/server";
|
|
4
|
+
import { inboxAccess } from "../../../access.js";
|
|
5
|
+
export default defineEventHandler(async (event) => {
|
|
6
|
+
const principal = await authorize(event, inboxAccess.permissions.read);
|
|
7
|
+
const query = await getValidatedQuery(event, inboxThreadsQuery.parse);
|
|
8
|
+
const mailboxes = (await inboxReadableMailboxes(event)).map((mailbox) => mailbox.id);
|
|
9
|
+
const ids = query.mailbox ? mailboxes.filter((id) => id === query.mailbox) : mailboxes;
|
|
10
|
+
if (!ids.length) return paginate({ items: [], total: 0, query });
|
|
11
|
+
const roles = await inboxCallerRoles(event);
|
|
12
|
+
const conditions = [
|
|
13
|
+
inArray(schema.inboxThreads.mailboxId, ids),
|
|
14
|
+
roles.length ? or(isNull(schema.inboxThreads.hiddenBelow), inArray(schema.inboxThreads.hiddenBelow, roles)) : isNull(schema.inboxThreads.hiddenBelow)
|
|
15
|
+
];
|
|
16
|
+
if (query.status === "active") conditions.push(inArray(schema.inboxThreads.status, ["open", "pending"]));
|
|
17
|
+
else if (query.status !== "all") conditions.push(eq(schema.inboxThreads.status, query.status));
|
|
18
|
+
if (query.assignee === "me") conditions.push(eq(schema.inboxThreads.assigneeId, Number(principal.user.id)));
|
|
19
|
+
else if (query.assignee === "none") conditions.push(isNull(schema.inboxThreads.assigneeId));
|
|
20
|
+
else if (typeof query.assignee === "number") conditions.push(eq(schema.inboxThreads.assigneeId, query.assignee));
|
|
21
|
+
if (query.channel) conditions.push(eq(schema.inboxThreads.channel, query.channel));
|
|
22
|
+
if (query.q) conditions.push(searchContains(schema.inboxThreads.searchText, query.q));
|
|
23
|
+
const where = and(...conditions);
|
|
24
|
+
const orderBy = orderByQuery({
|
|
25
|
+
lastMessageAt: schema.inboxThreads.lastMessageAt,
|
|
26
|
+
createdAt: schema.inboxThreads.createdAt,
|
|
27
|
+
status: schema.inboxThreads.status
|
|
28
|
+
}, query, { tiebreaker: schema.inboxThreads.id });
|
|
29
|
+
const { limit, offset } = pageRange(query);
|
|
30
|
+
const [rows, [totals]] = await Promise.all([
|
|
31
|
+
db.select().from(schema.inboxThreads).where(where).orderBy(...orderBy).limit(limit).offset(offset),
|
|
32
|
+
db.select({ total: count() }).from(schema.inboxThreads).where(where)
|
|
33
|
+
]);
|
|
34
|
+
const pii = await allows(event, inboxAccess.permissions.pii);
|
|
35
|
+
const contactIds = [...new Set(rows.map((row) => row.contactId))];
|
|
36
|
+
const contacts = contactIds.length ? await db.select().from(schema.inboxContacts).where(inArray(schema.inboxContacts.id, contactIds)) : [];
|
|
37
|
+
const contactById = new Map(contacts.map((contact) => [contact.id, contact]));
|
|
38
|
+
const users = await inboxUserRefs(rows.map((row) => row.assigneeId));
|
|
39
|
+
const items = rows.map((row) => {
|
|
40
|
+
const contact = contactById.get(row.contactId);
|
|
41
|
+
return {
|
|
42
|
+
...toInboxThreadDto(row),
|
|
43
|
+
contact: contact ? toInboxContactDto(contact, pii) : null,
|
|
44
|
+
assignee: row.assigneeId ? users.get(row.assigneeId) ?? { id: row.assigneeId, name: null } : null,
|
|
45
|
+
preview: row.preview ?? null
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
return paginate({ total: Number(totals?.total ?? 0), query, items });
|
|
49
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { notConfigured, notFound } from "@frigear-nu/module-kit/server";
|
|
2
|
+
export default defineEventHandler(async (event) => {
|
|
3
|
+
const { channel } = await getValidatedRouterParams(event, inboxChannelParams.parse);
|
|
4
|
+
const adapter = inboxChannelAdapter(channel);
|
|
5
|
+
if (!adapter?.inbound) throw notFound("This channel has no webhook.");
|
|
6
|
+
const secret = inboxSecret(adapter.inboundSecret, event);
|
|
7
|
+
if (!secret) throw notConfigured(`The ${channel} webhook has no secret (inboundSecret${adapter.inboundSecret ? ` ${adapter.inboundSecret} in inbox.secrets` : ""}).`);
|
|
8
|
+
const rawBody = await inboxReadRawBody(event);
|
|
9
|
+
const messages = await adapter.inbound(event, { secret, rawBody });
|
|
10
|
+
return inboxReceiveAll(event, channel, messages);
|
|
11
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { apiError, notConfigured, validationError } from "@frigear-nu/module-kit/server";
|
|
2
|
+
import { emailRecipients, emailToInbound, inboxEmailPayload } from "../../../utils/payloads.js";
|
|
3
|
+
import { verifySha256Signature } from "../../../utils/signature.js";
|
|
4
|
+
const withoutMailbox = (delivery) => {
|
|
5
|
+
const { mailboxId: _mailboxId, ...rest } = delivery;
|
|
6
|
+
return rest;
|
|
7
|
+
};
|
|
8
|
+
export default defineEventHandler(async (event) => {
|
|
9
|
+
const secret = inboxConfig(event).email.webhookSecret;
|
|
10
|
+
if (!secret) throw notConfigured("The email webhook has no secret (inbox.email.webhookSecret).");
|
|
11
|
+
const raw = await inboxReadRawBody(event);
|
|
12
|
+
if (!await verifySha256Signature(secret, raw, getRequestHeader(event, "x-inbox-signature"))) {
|
|
13
|
+
throw apiError(401, "invalid_signature", "The signature does not match.");
|
|
14
|
+
}
|
|
15
|
+
let json;
|
|
16
|
+
try {
|
|
17
|
+
json = JSON.parse(raw);
|
|
18
|
+
} catch {
|
|
19
|
+
throw validationError([{ path: [], message: "The body is not JSON." }], "Invalid email");
|
|
20
|
+
}
|
|
21
|
+
const parsed = inboxEmailPayload.safeParse(json);
|
|
22
|
+
if (!parsed.success) throw validationError(parsed.error.issues, "Invalid email");
|
|
23
|
+
const accounts = /* @__PURE__ */ new Map();
|
|
24
|
+
for (const recipient of emailRecipients(parsed.data)) {
|
|
25
|
+
const account = await inboxFindAccount("email", { address: recipient });
|
|
26
|
+
if (account && !accounts.has(account.id)) accounts.set(account.id, account);
|
|
27
|
+
}
|
|
28
|
+
if (!accounts.size) return { status: "ignored", reason: "no_account" };
|
|
29
|
+
const deliveries = [];
|
|
30
|
+
for (const account of accounts.values()) {
|
|
31
|
+
const result = await inboxReceive(event, "email", emailToInbound(parsed.data, account.address), account);
|
|
32
|
+
if (result.status === "received") deliveries.push({ status: "received", mailboxId: account.mailboxId, threadId: result.thread.id, messageId: result.message.id });
|
|
33
|
+
else if (result.status === "duplicate") deliveries.push({ status: "duplicate", mailboxId: account.mailboxId, messageId: result.messageId });
|
|
34
|
+
else deliveries.push({ status: "ignored", mailboxId: account.mailboxId, reason: result.reason });
|
|
35
|
+
}
|
|
36
|
+
const first = withoutMailbox(deliveries[0]);
|
|
37
|
+
return deliveries.length > 1 ? { ...first, deliveries } : first;
|
|
38
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { apiError, notConfigured } from "@frigear-nu/module-kit/server";
|
|
3
|
+
import { secretsEqual } from "../../../utils/signature.js";
|
|
4
|
+
const verifyQuery = z.object({
|
|
5
|
+
"hub.mode": z.string().max(32).default(""),
|
|
6
|
+
"hub.verify_token": z.string().max(512).default(""),
|
|
7
|
+
"hub.challenge": z.string().max(200).default("")
|
|
8
|
+
});
|
|
9
|
+
export default defineEventHandler(async (event) => {
|
|
10
|
+
const verifyToken = inboxConfig(event).meta.verifyToken;
|
|
11
|
+
if (!verifyToken) throw notConfigured("The Meta webhook has no verify token (inbox.meta.verifyToken).");
|
|
12
|
+
const query = await getValidatedQuery(event, verifyQuery.parse);
|
|
13
|
+
const challenge = query["hub.challenge"];
|
|
14
|
+
if (query["hub.mode"] !== "subscribe" || !challenge || !await secretsEqual(query["hub.verify_token"], verifyToken)) {
|
|
15
|
+
throw apiError(403, "invalid_verify_token", "The verify token does not match.");
|
|
16
|
+
}
|
|
17
|
+
setResponseHeader(event, "content-type", "text/plain; charset=utf-8");
|
|
18
|
+
return challenge;
|
|
19
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { apiError, notConfigured } from "@frigear-nu/module-kit/server";
|
|
2
|
+
import { parseMetaWebhook } from "../../../utils/payloads.js";
|
|
3
|
+
import { verifySha256Signature } from "../../../utils/signature.js";
|
|
4
|
+
export default defineEventHandler(async (event) => {
|
|
5
|
+
const appSecret = inboxConfig(event).meta.appSecret;
|
|
6
|
+
if (!appSecret) throw notConfigured("The Meta webhook has no app secret (inbox.meta.appSecret).");
|
|
7
|
+
const raw = await inboxReadRawBody(event);
|
|
8
|
+
if (!await verifySha256Signature(appSecret, raw, getRequestHeader(event, "x-hub-signature-256"))) {
|
|
9
|
+
throw apiError(401, "invalid_signature", "The signature does not match.");
|
|
10
|
+
}
|
|
11
|
+
let json;
|
|
12
|
+
try {
|
|
13
|
+
json = JSON.parse(raw);
|
|
14
|
+
} catch {
|
|
15
|
+
throw apiError(400, "invalid_body", "The body is not JSON.");
|
|
16
|
+
}
|
|
17
|
+
const counts = { received: 0, duplicates: 0, ignored: 0, failed: 0 };
|
|
18
|
+
const messages = parseMetaWebhook(json);
|
|
19
|
+
for (const channel of ["whatsapp", "messenger", "instagram"]) {
|
|
20
|
+
const batch = messages.filter((message) => message.channel === channel).map(({ channel: _channel, ...message }) => message);
|
|
21
|
+
if (!batch.length) continue;
|
|
22
|
+
const result = await inboxReceiveAll(event, channel, batch);
|
|
23
|
+
counts.received += result.received;
|
|
24
|
+
counts.duplicates += result.duplicates;
|
|
25
|
+
counts.ignored += result.ignored;
|
|
26
|
+
counts.failed += result.failed;
|
|
27
|
+
}
|
|
28
|
+
return counts;
|
|
29
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { schema } from "@nuxthub/db";
|
|
2
|
+
import { defineSearchIndex } from "@frigear-nu/module-kit/server";
|
|
3
|
+
import { inboxThreadSearchText } from "./utils/inbox-search.js";
|
|
4
|
+
export default defineSearchIndex({
|
|
5
|
+
table: schema.inboxThreads,
|
|
6
|
+
columns: (thread) => ({ searchText: inboxThreadSearchText(thread) })
|
|
7
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export default defineTask({
|
|
2
|
+
meta: {
|
|
3
|
+
name: "inbox:retention",
|
|
4
|
+
description: "Delete or anonymise closed inbox threads older than their mailbox keeps them."
|
|
5
|
+
},
|
|
6
|
+
async run({ payload }) {
|
|
7
|
+
const now = typeof payload?.now === "string" && !Number.isNaN(Date.parse(payload.now)) ? new Date(payload.now) : void 0;
|
|
8
|
+
const mode = payload?.mode === "delete" || payload?.mode === "anonymise" ? payload.mode : void 0;
|
|
9
|
+
const batch = typeof payload?.batch === "number" && Number.isSafeInteger(payload.batch) && payload.batch > 0 ? payload.batch : void 0;
|
|
10
|
+
return { result: await inboxRunRetention({ now, mode, batch }) };
|
|
11
|
+
}
|
|
12
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { H3Event } from 'h3';
|
|
2
|
+
import type { InboxAuditAction } from '../../../types.js';
|
|
3
|
+
/** The signed-in caller's user id, or `null`. */
|
|
4
|
+
export declare function inboxActorId(event: H3Event | undefined): Promise<number | null>;
|
|
5
|
+
/**
|
|
6
|
+
* Writes one audit entry. A failure is logged and never fails the request: the action it records has happened.
|
|
7
|
+
* `viewed` is written once per person and thread in a 15 minute window. An entry of a thread records the thread's
|
|
8
|
+
* mailbox (unless given), so the log can be filtered by mailbox access after the thread is gone.
|
|
9
|
+
*/
|
|
10
|
+
export declare function inboxAudit(event: H3Event | undefined, entry: {
|
|
11
|
+
action: InboxAuditAction;
|
|
12
|
+
threadId?: string | null;
|
|
13
|
+
mailboxId?: string | null;
|
|
14
|
+
contactId?: string | null;
|
|
15
|
+
data?: Record<string, unknown> | null;
|
|
16
|
+
actorId?: number | null;
|
|
17
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { db, schema } from "@nuxthub/db";
|
|
2
|
+
import { and, desc, eq, gt } from "drizzle-orm";
|
|
3
|
+
import { newId } from "@frigear-nu/module-kit/id";
|
|
4
|
+
const VIEW_WINDOW_MS = 15 * 60 * 1e3;
|
|
5
|
+
export async function inboxActorId(event) {
|
|
6
|
+
if (!event) return null;
|
|
7
|
+
const principal = await getAuth(event);
|
|
8
|
+
return principal?.user ? Number(principal.user.id) : null;
|
|
9
|
+
}
|
|
10
|
+
export async function inboxAudit(event, entry) {
|
|
11
|
+
try {
|
|
12
|
+
const actorId = entry.actorId !== void 0 ? entry.actorId : await inboxActorId(event);
|
|
13
|
+
if (entry.action === "viewed" && entry.threadId && actorId !== null) {
|
|
14
|
+
const since = new Date(Date.now() - VIEW_WINDOW_MS);
|
|
15
|
+
const [recent] = await db.select({ id: schema.inboxAudit.id }).from(schema.inboxAudit).where(and(eq(schema.inboxAudit.threadId, entry.threadId), eq(schema.inboxAudit.actorId, actorId), eq(schema.inboxAudit.action, "viewed"), gt(schema.inboxAudit.createdAt, since))).orderBy(desc(schema.inboxAudit.createdAt)).limit(1);
|
|
16
|
+
if (recent) return;
|
|
17
|
+
}
|
|
18
|
+
let mailboxId = entry.mailboxId ?? null;
|
|
19
|
+
if (mailboxId === null && entry.threadId) {
|
|
20
|
+
const [thread] = await db.select({ mailboxId: schema.inboxThreads.mailboxId }).from(schema.inboxThreads).where(eq(schema.inboxThreads.id, entry.threadId)).limit(1);
|
|
21
|
+
mailboxId = thread?.mailboxId ?? null;
|
|
22
|
+
}
|
|
23
|
+
await db.insert(schema.inboxAudit).values({
|
|
24
|
+
id: newId("iba"),
|
|
25
|
+
threadId: entry.threadId ?? null,
|
|
26
|
+
mailboxId,
|
|
27
|
+
contactId: entry.contactId ?? null,
|
|
28
|
+
actorId,
|
|
29
|
+
action: entry.action,
|
|
30
|
+
data: entry.data ?? null
|
|
31
|
+
});
|
|
32
|
+
} catch (error) {
|
|
33
|
+
console.error(`[inbox] could not write the audit entry "${entry.action}"`, error);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { InboxMetaChannel } from '../../utils/payloads.js';
|
|
2
|
+
import type { InboxChannelAccountDto, InboxContactDetails, InboxSendContext, InboxThreadDto } from '../../../types.js';
|
|
3
|
+
/** The `Reply-To` of an email account: `config.replyTo`, else its own address. */
|
|
4
|
+
export declare function inboxReplyToAddress(account: InboxChannelAccountDto | null): string | undefined;
|
|
5
|
+
/** The address a mailbox is answered at: its first enabled email account, for threads that did not come in by email. */
|
|
6
|
+
export declare function inboxMailboxEmailAddress(mailboxId: string): Promise<string | undefined>;
|
|
7
|
+
/** The subject of a reply: `Re: <subject> [ibt_...]`, so an answer threads back by its subject. */
|
|
8
|
+
export declare function inboxReplySubject(thread: Pick<InboxThreadDto, 'id' | 'subject'>): string;
|
|
9
|
+
/**
|
|
10
|
+
* The address a reply to the contact goes to: their email (or the email they wrote from) when it is one plain valid
|
|
11
|
+
* address, checked like cc recipients (`isEmailAddress`): a list (`a@x.org, b@y.org`) or a value with a line break is
|
|
12
|
+
* not one. `null` otherwise.
|
|
13
|
+
*/
|
|
14
|
+
export declare function inboxReplyAddress(contact: Pick<InboxContactDetails, 'email' | 'channel' | 'externalId'>): string | null;
|
|
15
|
+
/**
|
|
16
|
+
* Sends a reply by email to the contact (`409 no_reply_address` when they left no valid address, see
|
|
17
|
+
* `inboxReplyAddress`), copying the people their last authenticated email copied (`inboxReplyCc`), as a reply-all
|
|
18
|
+
* would.
|
|
19
|
+
*/
|
|
20
|
+
export declare function inboxSendEmailReply(input: {
|
|
21
|
+
thread: InboxThreadDto;
|
|
22
|
+
contact: InboxContactDetails;
|
|
23
|
+
body: string;
|
|
24
|
+
replyTo?: string;
|
|
25
|
+
}): Promise<{
|
|
26
|
+
cc: string[];
|
|
27
|
+
}>;
|
|
28
|
+
/**
|
|
29
|
+
* The `Cc` of an email reply in a thread: the cc recipients stored with the thread's latest authenticated inbound
|
|
30
|
+
* message (what the person's last verified email copied: the cc of an email with a forged sender is never sent to),
|
|
31
|
+
* without our own addresses: every email account's address and `config.replyTo`, the
|
|
32
|
+
* notify sender, and `exclude` (the recipient and the reply's `Reply-To`). Empty when the person copied nobody.
|
|
33
|
+
*/
|
|
34
|
+
export declare function inboxReplyCc(threadId: string, exclude: ReadonlyArray<string | null | undefined>): Promise<string[]>;
|
|
35
|
+
/**
|
|
36
|
+
* Sends a reply through the Graph API (WhatsApp Cloud API, Messenger, Instagram) with the account's access token,
|
|
37
|
+
* within `inbox.meta.timeoutMs`. WhatsApp only delivers free text within 24 hours of the person's last message;
|
|
38
|
+
* outside that window the API refuses it and the reply fails with `delivery_failed`.
|
|
39
|
+
*/
|
|
40
|
+
export declare function inboxMetaSend(channel: InboxMetaChannel, ctx: InboxSendContext): Promise<{
|
|
41
|
+
externalId: string | null;
|
|
42
|
+
}>;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { db, schema } from "@nuxthub/db";
|
|
2
|
+
import { and, asc, desc, eq } from "drizzle-orm";
|
|
3
|
+
import { apiError } from "@frigear-nu/module-kit/server";
|
|
4
|
+
import { isEmailAddress, metaSendRequest, metaSentId, normaliseEmail, replyCc } from "../../utils/payloads.js";
|
|
5
|
+
export function inboxReplyToAddress(account) {
|
|
6
|
+
if (!account) return void 0;
|
|
7
|
+
const replyTo = typeof account.config.replyTo === "string" ? account.config.replyTo : void 0;
|
|
8
|
+
return replyTo || (account.channel === "email" ? account.address : void 0);
|
|
9
|
+
}
|
|
10
|
+
export async function inboxMailboxEmailAddress(mailboxId) {
|
|
11
|
+
const [row] = await db.select({ address: schema.inboxChannelAccounts.address, config: schema.inboxChannelAccounts.config }).from(schema.inboxChannelAccounts).where(and(eq(schema.inboxChannelAccounts.mailboxId, mailboxId), eq(schema.inboxChannelAccounts.channel, "email"), eq(schema.inboxChannelAccounts.enabled, true))).orderBy(asc(schema.inboxChannelAccounts.createdAt)).limit(1);
|
|
12
|
+
if (!row) return void 0;
|
|
13
|
+
return typeof row.config?.replyTo === "string" && row.config.replyTo || row.address;
|
|
14
|
+
}
|
|
15
|
+
export function inboxReplySubject(thread) {
|
|
16
|
+
return `Re: ${inboxCleanSubject(thread.subject) || "Your message"} [${thread.id}]`;
|
|
17
|
+
}
|
|
18
|
+
export function inboxReplyAddress(contact) {
|
|
19
|
+
const raw = contact.email ?? (contact.channel === "email" ? contact.externalId : null);
|
|
20
|
+
if (!raw) return null;
|
|
21
|
+
const address = normaliseEmail(raw);
|
|
22
|
+
return isEmailAddress(address) ? address : null;
|
|
23
|
+
}
|
|
24
|
+
export async function inboxSendEmailReply(input) {
|
|
25
|
+
const to = inboxReplyAddress(input.contact);
|
|
26
|
+
if (!to) throw apiError(409, "no_reply_address", "The contact left no valid email address to reply to.");
|
|
27
|
+
const cc = await inboxReplyCc(input.thread.id, [to, input.replyTo]);
|
|
28
|
+
await dispatchEmailNotification({
|
|
29
|
+
to,
|
|
30
|
+
...cc.length ? { cc } : {},
|
|
31
|
+
subject: inboxReplySubject(input.thread),
|
|
32
|
+
body: inboxTextToHtml(input.body),
|
|
33
|
+
text: input.body,
|
|
34
|
+
...input.replyTo ? { replyTo: input.replyTo } : {},
|
|
35
|
+
meta: { inboxThreadId: input.thread.id }
|
|
36
|
+
});
|
|
37
|
+
return { cc };
|
|
38
|
+
}
|
|
39
|
+
export async function inboxReplyCc(threadId, exclude) {
|
|
40
|
+
const [latest] = await db.select({ cc: schema.inboxMessages.cc }).from(schema.inboxMessages).where(and(eq(schema.inboxMessages.threadId, threadId), eq(schema.inboxMessages.direction, "in"), eq(schema.inboxMessages.authenticated, true))).orderBy(desc(schema.inboxMessages.createdAtMs)).limit(1);
|
|
41
|
+
if (!latest?.cc?.length) return [];
|
|
42
|
+
const accounts = await db.select({ address: schema.inboxChannelAccounts.address, config: schema.inboxChannelAccounts.config }).from(schema.inboxChannelAccounts).where(eq(schema.inboxChannelAccounts.channel, "email"));
|
|
43
|
+
const from = useRuntimeConfig().notify?.email?.from;
|
|
44
|
+
return replyCc(latest.cc, [
|
|
45
|
+
...exclude,
|
|
46
|
+
from,
|
|
47
|
+
...accounts.flatMap((account) => [account.address, typeof account.config?.replyTo === "string" ? account.config.replyTo : null])
|
|
48
|
+
]);
|
|
49
|
+
}
|
|
50
|
+
export async function inboxMetaSend(channel, ctx) {
|
|
51
|
+
if (!ctx.account) throw apiError(409, "channel_unavailable", "The channel account of this thread was deleted.");
|
|
52
|
+
if (!ctx.secret) throw apiError(409, "channel_not_configured", `The access token of this ${channel} account is not configured (secretRef).`);
|
|
53
|
+
const meta = inboxConfig(ctx.event).meta;
|
|
54
|
+
const { url, body } = metaSendRequest(channel, {
|
|
55
|
+
apiBase: meta.apiBase,
|
|
56
|
+
apiVersion: meta.apiVersion,
|
|
57
|
+
accountId: ctx.account.address,
|
|
58
|
+
recipient: ctx.contact.externalId,
|
|
59
|
+
text: ctx.message.body
|
|
60
|
+
});
|
|
61
|
+
const response = await fetch(url, {
|
|
62
|
+
method: "POST",
|
|
63
|
+
headers: { "content-type": "application/json", "authorization": `Bearer ${ctx.secret}` },
|
|
64
|
+
body: JSON.stringify(body),
|
|
65
|
+
signal: AbortSignal.timeout(meta.timeoutMs)
|
|
66
|
+
});
|
|
67
|
+
const json = await response.json().catch(() => null);
|
|
68
|
+
if (!response.ok) {
|
|
69
|
+
const error = json?.error?.message;
|
|
70
|
+
throw new Error(`Graph API ${response.status}${error ? `: ${error}` : ""}`);
|
|
71
|
+
}
|
|
72
|
+
return { externalId: metaSentId(json) };
|
|
73
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { H3Event } from 'h3';
|
|
2
|
+
import type { InboxRuntimeConfig } from '../../../types.js';
|
|
3
|
+
/** The server-only inbox settings (`runtimeConfig.inbox`). */
|
|
4
|
+
export declare function inboxConfig(event?: H3Event): InboxRuntimeConfig;
|
|
5
|
+
/** Valid secret names: upper case letters, digits and `_`, so a ref can only name an inbox secret. */
|
|
6
|
+
export declare const INBOX_SECRET_REF: RegExp;
|
|
7
|
+
/**
|
|
8
|
+
* The value of a channel account's `secretRef`: `inbox.secrets[ref]` of the runtime config, read per request so the
|
|
9
|
+
* `NUXT_INBOX_SECRETS_<REF>` (or JSON `NUXT_INBOX_SECRETS`) environment override applies, on Cloudflare Workers too.
|
|
10
|
+
* Never read from `process.env` directly; secrets never go into the database, and a ref can name nothing else.
|
|
11
|
+
*/
|
|
12
|
+
export declare function inboxSecret(ref: string | null | undefined, event?: H3Event): string | undefined;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export function inboxConfig(event) {
|
|
2
|
+
return useRuntimeConfig(event).inbox;
|
|
3
|
+
}
|
|
4
|
+
export const INBOX_SECRET_REF = /^[A-Z][A-Z0-9_]{0,63}$/;
|
|
5
|
+
export function inboxSecret(ref, event) {
|
|
6
|
+
if (!ref || !INBOX_SECRET_REF.test(ref)) return void 0;
|
|
7
|
+
return inboxConfig(event).secrets?.[ref] || void 0;
|
|
8
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { schema } from '@nuxthub/db';
|
|
2
|
+
import type { InboxAuditDto, InboxChannelAccountDto, InboxContactDetails, InboxContactDto, InboxMailboxDto, InboxMessageDto, InboxThreadDto, InboxUserRef } from '../../../types.js';
|
|
3
|
+
export type InboxMailboxRow = typeof schema.inboxMailboxes.$inferSelect;
|
|
4
|
+
export type InboxChannelAccountRow = typeof schema.inboxChannelAccounts.$inferSelect;
|
|
5
|
+
export type InboxContactRow = typeof schema.inboxContacts.$inferSelect;
|
|
6
|
+
export type InboxThreadRow = typeof schema.inboxThreads.$inferSelect;
|
|
7
|
+
export type InboxMessageRow = typeof schema.inboxMessages.$inferSelect;
|
|
8
|
+
export type InboxAuditRow = typeof schema.inboxAudit.$inferSelect;
|
|
9
|
+
export declare function toInboxMailboxDto(row: InboxMailboxRow): InboxMailboxDto;
|
|
10
|
+
/** `secretConfigured` says whether the ref resolves on this server; the secret itself never leaves it. */
|
|
11
|
+
export declare function toInboxChannelAccountDto(row: InboxChannelAccountRow, secretConfigured: boolean): InboxChannelAccountDto;
|
|
12
|
+
/** A contact; the details only with `inbox:pii`. */
|
|
13
|
+
export declare function toInboxContactDto(row: InboxContactRow, pii: boolean): InboxContactDto;
|
|
14
|
+
/** Every detail of a contact, for channels (to reach the person) and exports. */
|
|
15
|
+
export declare function toInboxContactDetails(row: InboxContactRow): InboxContactDetails;
|
|
16
|
+
export declare function toInboxThreadDto(row: InboxThreadRow): InboxThreadDto;
|
|
17
|
+
/** A message; its cc recipients (other people's addresses) only with `pii`. */
|
|
18
|
+
export declare function toInboxMessageDto(row: InboxMessageRow, author?: InboxUserRef | null, pii?: boolean): InboxMessageDto;
|
|
19
|
+
export declare function toInboxAuditDto(row: InboxAuditRow, actor?: InboxUserRef | null): InboxAuditDto;
|