@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,123 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** A mailbox key: letters, digits, `.`, `_` and `-`, starting with a letter or digit. */
|
|
3
|
+
export declare const inboxKeySchema: z.ZodString;
|
|
4
|
+
/** A text in one language, or a locale -> text map with at least one text. */
|
|
5
|
+
export declare const inboxTranslatedInput: (max?: number) => z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>;
|
|
6
|
+
export declare const inboxStatusSchema: z.ZodEnum<{
|
|
7
|
+
open: "open";
|
|
8
|
+
pending: "pending";
|
|
9
|
+
closed: "closed";
|
|
10
|
+
}>;
|
|
11
|
+
export declare const inboxRoleSchema: z.ZodString;
|
|
12
|
+
/** `POST /api/admin/inbox/mailboxes`. A platform mailbox needs grants that name who reads it (checked in the handler). */
|
|
13
|
+
export declare const inboxMailboxCreateInput: z.ZodObject<{
|
|
14
|
+
key: z.ZodString;
|
|
15
|
+
name: z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>;
|
|
16
|
+
ownerType: z.ZodDefault<z.ZodEnum<{
|
|
17
|
+
platform: "platform";
|
|
18
|
+
team: "team";
|
|
19
|
+
}>>;
|
|
20
|
+
ownerId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
21
|
+
grants: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
22
|
+
kind: z.ZodString;
|
|
23
|
+
}, z.core.$loose>>>;
|
|
24
|
+
retentionDays: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
25
|
+
}, z.core.$strip>;
|
|
26
|
+
/** `PATCH /api/admin/inbox/mailboxes/:id`. The owner never changes; the key does not either (code finds mailboxes by it). */
|
|
27
|
+
export declare const inboxMailboxPatchInput: z.ZodObject<{
|
|
28
|
+
name: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
29
|
+
grants: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
30
|
+
kind: z.ZodString;
|
|
31
|
+
}, z.core.$loose>>>;
|
|
32
|
+
retentionDays: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
33
|
+
}, z.core.$strip>;
|
|
34
|
+
/** `GET /api/admin/inbox/threads`. `status` defaults to `active` (open or pending), `all` lists every status; `assignee`: `me`, `none` or a user id. */
|
|
35
|
+
export declare const inboxThreadsQuery: z.ZodObject<{
|
|
36
|
+
page: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
37
|
+
pageSize: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
38
|
+
q: z.ZodOptional<z.ZodString>;
|
|
39
|
+
sort: z.ZodDefault<z.ZodEnum<{
|
|
40
|
+
createdAt: "createdAt";
|
|
41
|
+
status: "status";
|
|
42
|
+
lastMessageAt: "lastMessageAt";
|
|
43
|
+
}>>;
|
|
44
|
+
order: z.ZodDefault<z.ZodEnum<{
|
|
45
|
+
asc: "asc";
|
|
46
|
+
desc: "desc";
|
|
47
|
+
}>>;
|
|
48
|
+
mailbox: z.ZodOptional<z.ZodString>;
|
|
49
|
+
status: z.ZodDefault<z.ZodEnum<{
|
|
50
|
+
open: "open";
|
|
51
|
+
active: "active";
|
|
52
|
+
all: "all";
|
|
53
|
+
pending: "pending";
|
|
54
|
+
closed: "closed";
|
|
55
|
+
}>>;
|
|
56
|
+
assignee: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"me">, z.ZodLiteral<"none">, z.ZodCoercedNumber<unknown>]>>;
|
|
57
|
+
channel: z.ZodOptional<z.ZodString>;
|
|
58
|
+
}, z.core.$strip>;
|
|
59
|
+
/** `PATCH /api/admin/inbox/threads/:id`: the status (`inbox:reply`) and the assignee (`inbox:assign`). */
|
|
60
|
+
export declare const inboxThreadPatchInput: z.ZodObject<{
|
|
61
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
62
|
+
open: "open";
|
|
63
|
+
pending: "pending";
|
|
64
|
+
closed: "closed";
|
|
65
|
+
}>>;
|
|
66
|
+
assigneeId: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
67
|
+
}, z.core.$strip>;
|
|
68
|
+
/** `POST .../messages` and `.../notes`. A reply may set the status in the same call (`pending`: waiting for them). */
|
|
69
|
+
export declare const inboxMessageInput: z.ZodObject<{
|
|
70
|
+
body: z.ZodString;
|
|
71
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
72
|
+
open: "open";
|
|
73
|
+
pending: "pending";
|
|
74
|
+
closed: "closed";
|
|
75
|
+
}>>;
|
|
76
|
+
}, z.core.$strip>;
|
|
77
|
+
export declare const inboxNoteInput: z.ZodObject<{
|
|
78
|
+
body: z.ZodString;
|
|
79
|
+
}, z.core.$strip>;
|
|
80
|
+
/** `POST .../hide`: the lowest global role that still sees the thread, or `null` to show it again. */
|
|
81
|
+
export declare const inboxHideInput: z.ZodObject<{
|
|
82
|
+
role: z.ZodNullable<z.ZodString>;
|
|
83
|
+
}, z.core.$strip>;
|
|
84
|
+
/** `POST /api/admin/inbox/channels`. */
|
|
85
|
+
export declare const inboxChannelCreateInput: z.ZodObject<{
|
|
86
|
+
mailboxId: z.ZodString;
|
|
87
|
+
channel: z.ZodString;
|
|
88
|
+
address: z.ZodString;
|
|
89
|
+
config: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
90
|
+
secretRef: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
91
|
+
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
92
|
+
}, z.core.$strip>;
|
|
93
|
+
/** `PATCH /api/admin/inbox/channels/:id`. The channel and the mailbox never change. */
|
|
94
|
+
export declare const inboxChannelPatchInput: z.ZodObject<{
|
|
95
|
+
address: z.ZodOptional<z.ZodString>;
|
|
96
|
+
config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
97
|
+
secretRef: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
98
|
+
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
99
|
+
}, z.core.$strip>;
|
|
100
|
+
/** `GET /api/admin/inbox/threads/:id/assignees`: `q` narrows by name. */
|
|
101
|
+
export declare const inboxAssigneesQuery: z.ZodObject<{
|
|
102
|
+
q: z.ZodPipe<z.ZodOptional<z.ZodString>, z.ZodTransform<string | undefined, string | undefined>>;
|
|
103
|
+
}, z.core.$strip>;
|
|
104
|
+
/** `GET /api/admin/inbox/audit`. */
|
|
105
|
+
export declare const inboxAuditQuery: z.ZodObject<{
|
|
106
|
+
page: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
107
|
+
pageSize: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
108
|
+
q: z.ZodOptional<z.ZodString>;
|
|
109
|
+
sort: z.ZodDefault<z.ZodEnum<{
|
|
110
|
+
createdAt: "createdAt";
|
|
111
|
+
}>>;
|
|
112
|
+
order: z.ZodDefault<z.ZodEnum<{
|
|
113
|
+
asc: "asc";
|
|
114
|
+
desc: "desc";
|
|
115
|
+
}>>;
|
|
116
|
+
threadId: z.ZodOptional<z.ZodString>;
|
|
117
|
+
contactId: z.ZodOptional<z.ZodString>;
|
|
118
|
+
action: z.ZodOptional<z.ZodString>;
|
|
119
|
+
}, z.core.$strip>;
|
|
120
|
+
/** `:channel` of the module webhooks. */
|
|
121
|
+
export declare const inboxChannelParams: z.ZodObject<{
|
|
122
|
+
channel: z.ZodString;
|
|
123
|
+
}, z.core.$strip>;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { grantListShape } from "@frigear-nu/auth/grants";
|
|
3
|
+
import { pageQuery } from "@frigear-nu/module-kit/server";
|
|
4
|
+
import { INBOX_CHANNEL_ID } from "../../utils/registry.js";
|
|
5
|
+
export const inboxKeySchema = z.string().trim().regex(/^[a-z0-9][\w.-]{0,63}$/i, 'Use letters, digits, ".", "_" and "-".');
|
|
6
|
+
export const inboxTranslatedInput = (max = 200) => z.union([
|
|
7
|
+
z.string().trim().min(1).max(max),
|
|
8
|
+
z.record(z.string().min(2).max(16), z.string().trim().max(max)).refine((value) => Object.values(value).some(Boolean), "Write the text in at least one language.")
|
|
9
|
+
]);
|
|
10
|
+
export const inboxStatusSchema = z.enum(["open", "pending", "closed"]);
|
|
11
|
+
export const inboxRoleSchema = z.string().trim().min(1).max(64);
|
|
12
|
+
export const inboxMailboxCreateInput = z.object({
|
|
13
|
+
key: inboxKeySchema,
|
|
14
|
+
name: inboxTranslatedInput(),
|
|
15
|
+
ownerType: z.enum(["platform", "team"]).default("platform"),
|
|
16
|
+
ownerId: z.string().trim().min(1).max(128).nullish(),
|
|
17
|
+
grants: grantListShape.optional(),
|
|
18
|
+
retentionDays: z.number().int().min(1).max(36500).nullish()
|
|
19
|
+
});
|
|
20
|
+
export const inboxMailboxPatchInput = z.object({
|
|
21
|
+
name: inboxTranslatedInput().optional(),
|
|
22
|
+
grants: grantListShape.optional(),
|
|
23
|
+
retentionDays: z.number().int().min(1).max(36500).nullable().optional()
|
|
24
|
+
});
|
|
25
|
+
export const inboxThreadsQuery = pageQuery({
|
|
26
|
+
sort: ["lastMessageAt", "createdAt", "status"],
|
|
27
|
+
defaultSort: "lastMessageAt",
|
|
28
|
+
// A page's ids go into one `IN (...)`: D1 binds at most 100 parameters.
|
|
29
|
+
maxPageSize: 90,
|
|
30
|
+
filters: {
|
|
31
|
+
mailbox: z.string().trim().min(1).max(64).optional(),
|
|
32
|
+
status: z.enum(["open", "pending", "closed", "active", "all"]).default("active"),
|
|
33
|
+
assignee: z.union([z.literal("me"), z.literal("none"), z.coerce.number().int().positive()]).optional(),
|
|
34
|
+
channel: z.string().trim().min(1).max(64).optional()
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
export const inboxThreadPatchInput = z.object({
|
|
38
|
+
status: inboxStatusSchema.optional(),
|
|
39
|
+
assigneeId: z.number().int().positive().nullable().optional()
|
|
40
|
+
}).refine((value) => value.status !== void 0 || value.assigneeId !== void 0, "Change the status or the assignee.");
|
|
41
|
+
export const inboxMessageInput = z.object({
|
|
42
|
+
body: z.string().trim().min(1).max(2e4),
|
|
43
|
+
status: inboxStatusSchema.optional()
|
|
44
|
+
});
|
|
45
|
+
export const inboxNoteInput = z.object({
|
|
46
|
+
body: z.string().trim().min(1).max(2e4)
|
|
47
|
+
});
|
|
48
|
+
export const inboxHideInput = z.object({
|
|
49
|
+
role: inboxRoleSchema.nullable()
|
|
50
|
+
});
|
|
51
|
+
const configSchema = z.record(z.string().min(1).max(64), z.unknown()).refine((value) => !Object.keys(value).some((key) => /secret|token|password|apikey|api_key/i.test(key)), "Put secrets in the runtime config and name them in secretRef.").refine((value) => JSON.stringify(value).length <= 4e3, "The settings are too long.");
|
|
52
|
+
export const inboxChannelCreateInput = z.object({
|
|
53
|
+
mailboxId: z.string().trim().min(1).max(64),
|
|
54
|
+
channel: z.string().trim().regex(INBOX_CHANNEL_ID, "Unknown channel.").max(64),
|
|
55
|
+
address: z.string().trim().min(1).max(320),
|
|
56
|
+
config: configSchema.default({}),
|
|
57
|
+
secretRef: z.string().trim().regex(/^[A-Z][A-Z0-9_]{0,63}$/, 'Upper case letters, digits and "_", such as WHATSAPP_TOKEN.').nullish(),
|
|
58
|
+
enabled: z.boolean().default(true)
|
|
59
|
+
});
|
|
60
|
+
export const inboxChannelPatchInput = z.object({
|
|
61
|
+
address: z.string().trim().min(1).max(320).optional(),
|
|
62
|
+
config: configSchema.optional(),
|
|
63
|
+
secretRef: z.string().trim().regex(/^[A-Z][A-Z0-9_]{0,63}$/, 'Upper case letters, digits and "_", such as WHATSAPP_TOKEN.').nullable().optional(),
|
|
64
|
+
enabled: z.boolean().optional()
|
|
65
|
+
});
|
|
66
|
+
export const inboxAssigneesQuery = z.object({
|
|
67
|
+
q: z.string().trim().max(100).optional().transform((value) => value || void 0)
|
|
68
|
+
});
|
|
69
|
+
export const inboxAuditQuery = pageQuery({
|
|
70
|
+
sort: ["createdAt"],
|
|
71
|
+
defaultPageSize: 50,
|
|
72
|
+
filters: {
|
|
73
|
+
threadId: z.string().trim().min(1).max(64).optional(),
|
|
74
|
+
contactId: z.string().trim().min(1).max(64).optional(),
|
|
75
|
+
action: z.string().trim().min(1).max(32).optional()
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
export const inboxChannelParams = z.object({ channel: z.string().trim().regex(INBOX_CHANNEL_ID).max(64) });
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `inbox_threads.searchText`: the (cleaned) subject, folded; always empty for an anonymised thread, whose subject is
|
|
3
|
+
* gone. Written on create, when a thread gets its first subject, cleared on anonymise, and by `search:reindex`.
|
|
4
|
+
*/
|
|
5
|
+
export declare const inboxThreadSearchText: (thread: {
|
|
6
|
+
subject: string | null;
|
|
7
|
+
anonymisedAt?: Date | null;
|
|
8
|
+
}) => string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { H3Event } from 'h3';
|
|
2
|
+
import type { InboxMailboxSeed } from '../../../types.js';
|
|
3
|
+
/** Creates a mailbox of `inbox.mailboxes` unless one with its key exists; an existing one is never changed. */
|
|
4
|
+
export declare function inboxEnsureMailbox(seed: InboxMailboxSeed): Promise<void>;
|
|
5
|
+
/**
|
|
6
|
+
* Creates the configured mailboxes once per server, on the first request (NuxtHub has applied the migrations by
|
|
7
|
+
* then). A failure is logged and retried on a request a minute later.
|
|
8
|
+
*/
|
|
9
|
+
export declare function inboxEnsureMailboxesSeeded(event: H3Event): Promise<void>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { db, schema } from "@nuxthub/db";
|
|
2
|
+
import { PUBLIC_GRANT_KIND, SIGNED_IN_GRANT_KIND, checkGrantList, readGrants } from "@frigear-nu/auth/grants";
|
|
3
|
+
import { newId } from "@frigear-nu/module-kit/id";
|
|
4
|
+
const RETRY_MS = 6e4;
|
|
5
|
+
let seeding;
|
|
6
|
+
let failedAt = 0;
|
|
7
|
+
export async function inboxEnsureMailbox(seed) {
|
|
8
|
+
const grants = readGrants(seed.grants ?? []);
|
|
9
|
+
if (checkGrantList(grantsRegistry(), grants).length || grants.some((grant) => grant.kind === PUBLIC_GRANT_KIND || grant.kind === SIGNED_IN_GRANT_KIND)) {
|
|
10
|
+
throw new Error(`[inbox] the mailbox "${seed.key}" has invalid grants (an unknown kind, an invalid grant, or a public or signed-in one)`);
|
|
11
|
+
}
|
|
12
|
+
await db.insert(schema.inboxMailboxes).values({
|
|
13
|
+
id: newId("ibx"),
|
|
14
|
+
key: seed.key,
|
|
15
|
+
ownerType: seed.ownerType ?? "platform",
|
|
16
|
+
ownerId: seed.ownerType === "team" ? seed.ownerId ?? null : null,
|
|
17
|
+
name: seed.name,
|
|
18
|
+
grants,
|
|
19
|
+
retentionDays: seed.retentionDays ?? null
|
|
20
|
+
}).onConflictDoNothing();
|
|
21
|
+
}
|
|
22
|
+
export function inboxEnsureMailboxesSeeded(event) {
|
|
23
|
+
const seeds = inboxConfig(event).mailboxes ?? [];
|
|
24
|
+
if (!seeds.length) return Promise.resolve();
|
|
25
|
+
if (!seeding && failedAt && Date.now() - failedAt < RETRY_MS) return Promise.resolve();
|
|
26
|
+
seeding ??= (async () => {
|
|
27
|
+
for (const seed of seeds) await inboxEnsureMailbox(seed);
|
|
28
|
+
failedAt = 0;
|
|
29
|
+
})().catch((error) => {
|
|
30
|
+
seeding = void 0;
|
|
31
|
+
failedAt = Date.now();
|
|
32
|
+
console.error("[inbox] the configured mailboxes could not be created; retried on a request in a minute", error);
|
|
33
|
+
});
|
|
34
|
+
return seeding;
|
|
35
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { H3Event } from 'h3';
|
|
2
|
+
import type { InboxMessageDto, InboxThreadDto, InboxThreadStatus } from '../../../types.js';
|
|
3
|
+
import type { InboxThreadRow } from './inbox-dto.js';
|
|
4
|
+
/** Changes a thread's status and fires `inbox:thread:status-changed`; the same status is a no-op. */
|
|
5
|
+
export declare function inboxSetStatus(event: H3Event, thread: InboxThreadRow, to: InboxThreadStatus): Promise<InboxThreadRow>;
|
|
6
|
+
/**
|
|
7
|
+
* Sends a reply through the thread's channel and stores it. The channel's adapter delivers it first: when it throws,
|
|
8
|
+
* nothing is stored and the caller gets a 502 `delivery_failed` (409 `channel_unavailable` when the channel or the
|
|
9
|
+
* account is gone, or the contact was erased). Fires `inbox:message:sent`.
|
|
10
|
+
*/
|
|
11
|
+
export declare function inboxReply(event: H3Event, thread: InboxThreadRow, input: {
|
|
12
|
+
body: string;
|
|
13
|
+
authorId: number;
|
|
14
|
+
status?: InboxThreadStatus;
|
|
15
|
+
}): Promise<{
|
|
16
|
+
thread: InboxThreadDto;
|
|
17
|
+
message: InboxMessageDto;
|
|
18
|
+
}>;
|
|
19
|
+
/** Stores an internal note: never sent, never in an export, no hook. */
|
|
20
|
+
export declare function inboxAddNote(event: H3Event, thread: InboxThreadRow, input: {
|
|
21
|
+
body: string;
|
|
22
|
+
authorId: number;
|
|
23
|
+
}): Promise<InboxMessageDto>;
|
|
24
|
+
/** Escapes text for an HTML email body, keeping line breaks. */
|
|
25
|
+
export declare function inboxTextToHtml(text: string): string;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { db, schema } from "@nuxthub/db";
|
|
2
|
+
import { eq } from "drizzle-orm";
|
|
3
|
+
import { apiError } from "@frigear-nu/module-kit/server";
|
|
4
|
+
import { newId } from "@frigear-nu/module-kit/id";
|
|
5
|
+
import { toInboxChannelAccountDto, toInboxContactDetails, toInboxMailboxDto, toInboxMessageDto, toInboxThreadDto } from "./inbox-dto.js";
|
|
6
|
+
import { inboxCcList } from "../../utils/payloads.js";
|
|
7
|
+
export async function inboxSetStatus(event, thread, to) {
|
|
8
|
+
const from = thread.status;
|
|
9
|
+
if (from === to) return thread;
|
|
10
|
+
const [updated] = await db.update(schema.inboxThreads).set({ status: to }).where(eq(schema.inboxThreads.id, thread.id)).returning();
|
|
11
|
+
await useNitroApp().hooks.callHook("inbox:thread:status-changed", { event, thread: toInboxThreadDto(updated), from, to });
|
|
12
|
+
await inboxAudit(event, { action: "status", threadId: thread.id, data: { from, to } });
|
|
13
|
+
return updated;
|
|
14
|
+
}
|
|
15
|
+
export async function inboxReply(event, thread, input) {
|
|
16
|
+
const adapter = inboxChannelAdapter(thread.channel);
|
|
17
|
+
if (!adapter) throw apiError(409, "channel_unavailable", `The channel "${thread.channel}" is no longer installed.`);
|
|
18
|
+
const contact = await findInboxContact(thread.contactId);
|
|
19
|
+
if (!contact || contact.erasedAt) throw apiError(409, "channel_unavailable", "The contact was erased: there is nobody to reply to.");
|
|
20
|
+
const mailbox = await findInboxMailbox(thread.mailboxId);
|
|
21
|
+
const account = thread.channelAccountId ? await findInboxChannelAccount(thread.channelAccountId) : void 0;
|
|
22
|
+
if (account && !account.enabled) throw apiError(409, "channel_unavailable", "The channel account of this thread is turned off.");
|
|
23
|
+
const secret = inboxSecret(account?.secretRef, event);
|
|
24
|
+
const id = newId("ibm");
|
|
25
|
+
let externalId;
|
|
26
|
+
let cc;
|
|
27
|
+
try {
|
|
28
|
+
const result = await adapter.send({
|
|
29
|
+
event,
|
|
30
|
+
mailbox: toInboxMailboxDto(mailbox),
|
|
31
|
+
account: account ? toInboxChannelAccountDto(account, !!secret) : null,
|
|
32
|
+
secret,
|
|
33
|
+
thread: toInboxThreadDto(thread),
|
|
34
|
+
contact: toInboxContactDetails(contact),
|
|
35
|
+
message: { id, body: input.body, attachments: [] }
|
|
36
|
+
});
|
|
37
|
+
externalId = result?.externalId ? `${thread.channel}:out:${result.externalId}` : null;
|
|
38
|
+
cc = inboxCcList(result?.cc);
|
|
39
|
+
} catch (error) {
|
|
40
|
+
const status = error.statusCode;
|
|
41
|
+
if (status && status >= 400 && status < 500) throw error;
|
|
42
|
+
console.error(`[inbox] the ${thread.channel} channel could not deliver a reply in ${thread.id}`, error);
|
|
43
|
+
throw apiError(502, "delivery_failed", "The reply could not be delivered. Nothing was sent.");
|
|
44
|
+
}
|
|
45
|
+
const now = /* @__PURE__ */ new Date();
|
|
46
|
+
const [message] = await db.insert(schema.inboxMessages).values({
|
|
47
|
+
id,
|
|
48
|
+
threadId: thread.id,
|
|
49
|
+
direction: "out",
|
|
50
|
+
authorId: input.authorId,
|
|
51
|
+
body: input.body,
|
|
52
|
+
attachments: [],
|
|
53
|
+
cc: cc.length ? cc : null,
|
|
54
|
+
channelAccountId: thread.channelAccountId,
|
|
55
|
+
externalId,
|
|
56
|
+
createdAt: now,
|
|
57
|
+
createdAtMs: now.getTime()
|
|
58
|
+
}).returning();
|
|
59
|
+
let updated = (await db.update(schema.inboxThreads).set({ lastMessageAt: now, preview: inboxPreview(input.body) }).where(eq(schema.inboxThreads.id, thread.id)).returning())[0];
|
|
60
|
+
if (input.status) updated = await inboxSetStatus(event, updated, input.status);
|
|
61
|
+
const threadDto = toInboxThreadDto(updated);
|
|
62
|
+
const author = (await inboxUserRefs([input.authorId])).get(input.authorId) ?? null;
|
|
63
|
+
const messageDto = toInboxMessageDto(message, author);
|
|
64
|
+
await useNitroApp().hooks.callHook("inbox:message:sent", { event, thread: threadDto, message: messageDto });
|
|
65
|
+
await inboxAudit(event, { action: "replied", threadId: thread.id, actorId: input.authorId, data: { messageId: id } });
|
|
66
|
+
return { thread: threadDto, message: messageDto };
|
|
67
|
+
}
|
|
68
|
+
export async function inboxAddNote(event, thread, input) {
|
|
69
|
+
const [message] = await db.insert(schema.inboxMessages).values({
|
|
70
|
+
id: newId("ibm"),
|
|
71
|
+
threadId: thread.id,
|
|
72
|
+
direction: "note",
|
|
73
|
+
authorId: input.authorId,
|
|
74
|
+
body: input.body,
|
|
75
|
+
attachments: []
|
|
76
|
+
}).returning();
|
|
77
|
+
await inboxAudit(event, { action: "noted", threadId: thread.id, actorId: input.authorId, data: { messageId: message.id } });
|
|
78
|
+
const author = (await inboxUserRefs([input.authorId])).get(input.authorId) ?? null;
|
|
79
|
+
return toInboxMessageDto(message, author);
|
|
80
|
+
}
|
|
81
|
+
export function inboxTextToHtml(text) {
|
|
82
|
+
const escaped = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
83
|
+
return escaped.split(/\n{2,}/).map((paragraph) => `<p>${paragraph.replace(/\n/g, "<br>")}</p>`).join("\n");
|
|
84
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** The tombstone key of a provider id on a channel account: a hex SHA-256, so no id or address is kept in the clear. */
|
|
2
|
+
export declare function inboxTombstoneKey(channelAccountId: string, externalId: string): Promise<string>;
|
|
3
|
+
/** Whether the message with this provider id on this account was removed by retention or an erase. */
|
|
4
|
+
export declare function inboxIsTombstoned(channelAccountId: string, externalId: string): Promise<boolean>;
|
|
5
|
+
export type InboxTombstoneOptions = {
|
|
6
|
+
/** An erase's tombstones: never pruned. */
|
|
7
|
+
permanent?: boolean;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Records a tombstone for every inbound message of these threads that still has its provider id, before retention or an
|
|
11
|
+
* erase deletes or blanks them (D1-sized chunks).
|
|
12
|
+
*/
|
|
13
|
+
export declare function inboxTombstoneThreads(threadIds: string[], now?: Date, options?: InboxTombstoneOptions): Promise<void>;
|
|
14
|
+
/** Records a tombstone for each of these inbound messages that still has its provider id (D1-sized chunks). */
|
|
15
|
+
export declare function inboxTombstoneMessages(messageIds: string[], now?: Date, options?: InboxTombstoneOptions): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Keeps the tombstones of the messages these contacts sent for good: an erase covers what retention removed of theirs
|
|
18
|
+
* earlier too.
|
|
19
|
+
*/
|
|
20
|
+
export declare function inboxKeepTombstonesOf(contactIds: string[]): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Forgets retention's tombstones written before `before`: a replay that late is stored as a new message. An erase's are
|
|
23
|
+
* kept for good.
|
|
24
|
+
*/
|
|
25
|
+
export declare function inboxPruneTombstones(before: Date): Promise<void>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { db, schema } from "@nuxthub/db";
|
|
2
|
+
import { and, eq, inArray, isNotNull, lt } from "drizzle-orm";
|
|
3
|
+
import { chunkParams } from "@frigear-nu/module-kit/server";
|
|
4
|
+
import { sha256Hex } from "@frigear-nu/module-kit/crypto";
|
|
5
|
+
const TOMBSTONE_INSERT_CHUNK = 22;
|
|
6
|
+
export function inboxTombstoneKey(channelAccountId, externalId) {
|
|
7
|
+
return sha256Hex(`${channelAccountId}:${externalId}`);
|
|
8
|
+
}
|
|
9
|
+
export async function inboxIsTombstoned(channelAccountId, externalId) {
|
|
10
|
+
const key = await inboxTombstoneKey(channelAccountId, externalId);
|
|
11
|
+
const [row] = await db.select({ key: schema.inboxTombstones.key }).from(schema.inboxTombstones).where(eq(schema.inboxTombstones.key, key)).limit(1);
|
|
12
|
+
return !!row;
|
|
13
|
+
}
|
|
14
|
+
async function tombstoneWhere(where, now, options) {
|
|
15
|
+
const messages = schema.inboxMessages;
|
|
16
|
+
const rows = await db.select({
|
|
17
|
+
channelAccountId: messages.channelAccountId,
|
|
18
|
+
externalId: messages.externalId,
|
|
19
|
+
contactId: messages.contactId,
|
|
20
|
+
threadContactId: schema.inboxThreads.contactId
|
|
21
|
+
}).from(messages).innerJoin(schema.inboxThreads, eq(schema.inboxThreads.id, messages.threadId)).where(and(where, eq(messages.direction, "in"), isNotNull(messages.channelAccountId), isNotNull(messages.externalId)));
|
|
22
|
+
const values = /* @__PURE__ */ new Map();
|
|
23
|
+
for (const row of rows) {
|
|
24
|
+
if (!row.channelAccountId || !row.externalId || row.externalId.startsWith("erased:")) continue;
|
|
25
|
+
const key = await inboxTombstoneKey(row.channelAccountId, row.externalId);
|
|
26
|
+
values.set(key, { key, createdAt: now, contactId: row.contactId ?? row.threadContactId ?? null, permanent: options.permanent === true });
|
|
27
|
+
}
|
|
28
|
+
for (const part of chunkParams([...values.values()], TOMBSTONE_INSERT_CHUNK)) {
|
|
29
|
+
const insert = db.insert(schema.inboxTombstones).values(part);
|
|
30
|
+
if (options.permanent) await insert.onConflictDoUpdate({ target: schema.inboxTombstones.key, set: { permanent: true } });
|
|
31
|
+
else await insert.onConflictDoNothing();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export async function inboxTombstoneThreads(threadIds, now = /* @__PURE__ */ new Date(), options = {}) {
|
|
35
|
+
for (const chunk of chunkParams(threadIds)) await tombstoneWhere(inArray(schema.inboxMessages.threadId, chunk), now, options);
|
|
36
|
+
}
|
|
37
|
+
export async function inboxTombstoneMessages(messageIds, now = /* @__PURE__ */ new Date(), options = {}) {
|
|
38
|
+
for (const chunk of chunkParams(messageIds)) await tombstoneWhere(inArray(schema.inboxMessages.id, chunk), now, options);
|
|
39
|
+
}
|
|
40
|
+
export async function inboxKeepTombstonesOf(contactIds) {
|
|
41
|
+
for (const chunk of chunkParams(contactIds)) {
|
|
42
|
+
await db.update(schema.inboxTombstones).set({ permanent: true }).where(inArray(schema.inboxTombstones.contactId, chunk));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export async function inboxPruneTombstones(before) {
|
|
46
|
+
await db.delete(schema.inboxTombstones).where(and(lt(schema.inboxTombstones.createdAt, before), eq(schema.inboxTombstones.permanent, false)));
|
|
47
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { H3Event } from 'h3';
|
|
2
|
+
/** The largest webhook body read: an inbound email or a Meta batch is far smaller. */
|
|
3
|
+
export declare const INBOX_MAX_WEBHOOK_BYTES: number;
|
|
4
|
+
/**
|
|
5
|
+
* The raw body of a webhook (signatures are over the exact bytes), at most `INBOX_MAX_WEBHOOK_BYTES`: a larger
|
|
6
|
+
* `content-length` is refused before reading, a larger body after. Both answer 413 `payload_too_large`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function inboxReadRawBody(event: H3Event): Promise<string>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { apiError } from "@frigear-nu/module-kit/server";
|
|
2
|
+
export const INBOX_MAX_WEBHOOK_BYTES = 1024 * 1024;
|
|
3
|
+
export async function inboxReadRawBody(event) {
|
|
4
|
+
const tooLarge = () => apiError(413, "payload_too_large", `The body is larger than ${INBOX_MAX_WEBHOOK_BYTES} bytes.`);
|
|
5
|
+
const declared = Number(getRequestHeader(event, "content-length") ?? 0);
|
|
6
|
+
if (declared > INBOX_MAX_WEBHOOK_BYTES) throw tooLarge();
|
|
7
|
+
const raw = await readRawBody(event, false) ?? new Uint8Array();
|
|
8
|
+
if (raw.byteLength > INBOX_MAX_WEBHOOK_BYTES) throw tooLarge();
|
|
9
|
+
return new TextDecoder().decode(raw);
|
|
10
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { H3Event } from 'h3';
|
|
2
|
+
import type { InboxThreadAbilities, InboxUserRef } from '../../../types.js';
|
|
3
|
+
import type { InboxChannelAccountRow, InboxContactRow, InboxMailboxRow, InboxThreadRow } from './inbox-dto.js';
|
|
4
|
+
/** Page size of the assignee scan. */
|
|
5
|
+
export declare const INBOX_CHUNK = 90;
|
|
6
|
+
export declare function findInboxMailbox(id: string): Promise<InboxMailboxRow | undefined>;
|
|
7
|
+
export declare function findInboxMailboxByKey(key: string): Promise<InboxMailboxRow | undefined>;
|
|
8
|
+
export declare function findInboxThread(id: string): Promise<InboxThreadRow | undefined>;
|
|
9
|
+
export declare function findInboxContact(id: string): Promise<InboxContactRow | undefined>;
|
|
10
|
+
export declare function findInboxChannelAccount(id: string): Promise<InboxChannelAccountRow | undefined>;
|
|
11
|
+
export declare function getInboxMailboxOr404(id: string): Promise<InboxMailboxRow>;
|
|
12
|
+
/** Every mailbox, by name order of their keys. A deployment has a handful, so they are read whole. */
|
|
13
|
+
export declare function listInboxMailboxes(): Promise<InboxMailboxRow[]>;
|
|
14
|
+
/** Names of users, for assignees, authors and actors (`loadUserRefs` of `@frigear-nu/users`). */
|
|
15
|
+
export declare function inboxUserRefs(ids: Array<number | null | undefined>): Promise<Map<number, InboxUserRef>>;
|
|
16
|
+
/** The caller's global roles (closed over `inherit`), once per request. */
|
|
17
|
+
export declare function inboxCallerRoles(event: H3Event): Promise<string[]>;
|
|
18
|
+
/**
|
|
19
|
+
* Whoever a mailbox or thread rule is evaluated for: the caller (`inboxCallerSubject`) or another user, such as an
|
|
20
|
+
* assignee (`inboxUserSubject`). The rules never read the session from `event` themselves.
|
|
21
|
+
*/
|
|
22
|
+
export type InboxSubject = {
|
|
23
|
+
user: {
|
|
24
|
+
id: string | number;
|
|
25
|
+
};
|
|
26
|
+
/** Holds `inbox:manage` (without a record). */
|
|
27
|
+
manages: () => Promise<boolean>;
|
|
28
|
+
/** Global roles, closed over `inherit`. */
|
|
29
|
+
roles: () => Promise<string[]>;
|
|
30
|
+
};
|
|
31
|
+
/** The caller as a subject, with the per-request caches. */
|
|
32
|
+
export declare function inboxCallerSubject(event: H3Event, user: {
|
|
33
|
+
id: string | number;
|
|
34
|
+
}): InboxSubject;
|
|
35
|
+
/** Another user as a subject: their own roles, and `inbox:manage` as their session would hold it. */
|
|
36
|
+
export declare function inboxUserSubject(event: H3Event, user: Parameters<typeof subjectAllowed>[1]): InboxSubject;
|
|
37
|
+
/** A hidden thread is seen only by people who hold its `hiddenBelow` role (roles inherit along the host's chain). */
|
|
38
|
+
export declare function inboxSeesHidden(subject: InboxSubject, hiddenBelow: string | null | undefined): Promise<boolean>;
|
|
39
|
+
/**
|
|
40
|
+
* The record rule of `inbox:read` and `inbox:reply` for a mailbox: staff with `inbox:manage` read every one, a team's
|
|
41
|
+
* leads read the team's, anyone else whom its grants (`@frigear-nu/auth`) admit. An empty list lets nobody else in, and
|
|
42
|
+
* a `public` or `signed-in` grant never counts (one stored before they were refused): a mailbox holds outsiders'
|
|
43
|
+
* messages, so it is never open to everyone, nor to everyone with an account.
|
|
44
|
+
*/
|
|
45
|
+
export declare function inboxCanAccessMailbox(event: H3Event, subject: InboxSubject, mailbox: InboxMailboxRow): Promise<boolean>;
|
|
46
|
+
/** The same rule for a thread: its `hiddenBelow` first, then its mailbox. */
|
|
47
|
+
export declare function inboxCanAccessThread(event: H3Event, subject: InboxSubject, thread: InboxThreadRow, mailbox?: InboxMailboxRow): Promise<boolean>;
|
|
48
|
+
/** The mailboxes the caller reads (`inbox:read` with each mailbox as the record). */
|
|
49
|
+
export declare function inboxReadableMailboxes(event: H3Event): Promise<InboxMailboxRow[]>;
|
|
50
|
+
/**
|
|
51
|
+
* Those of `threads` the caller reads: in a mailbox they read (`inboxReadableMailboxes`) and not hidden below a role
|
|
52
|
+
* they lack. The same rule as `inbox:read` with each thread as the record, with the mailboxes checked once.
|
|
53
|
+
*/
|
|
54
|
+
export declare function inboxVisibleThreads<T extends Pick<InboxThreadRow, 'mailboxId' | 'hiddenBelow'>>(event: H3Event, threads: T[]): Promise<T[]>;
|
|
55
|
+
/**
|
|
56
|
+
* The thread behind `:id` for a caller who passed `authorize(event, inbox:read)`: a thread they may not read (an
|
|
57
|
+
* unknown id, another mailbox, hidden from their role) is the same 404.
|
|
58
|
+
*/
|
|
59
|
+
export declare function getReadableInboxThreadOr404(event: H3Event, id: string): Promise<InboxThreadRow>;
|
|
60
|
+
/** What the caller may do with a thread they read. */
|
|
61
|
+
export declare function inboxAbilities(event: H3Event, thread: InboxThreadRow): Promise<InboxThreadAbilities>;
|
|
62
|
+
/**
|
|
63
|
+
* Whether user `userId` could read and answer `thread` themselves: they hold `inbox:reply`, its `hiddenBelow` role
|
|
64
|
+
* and access to its mailbox, all evaluated for them, not for the caller. `false` for an unknown user.
|
|
65
|
+
*/
|
|
66
|
+
export declare function inboxUserCanAccessThread(event: H3Event, userId: number, thread: Pick<InboxThreadRow, 'mailboxId' | 'hiddenBelow'>): Promise<boolean>;
|
|
67
|
+
/** 400 `validation_error` for an unknown user, 409 `assignee_no_access` for one who could not read and answer the thread. */
|
|
68
|
+
export declare function inboxAssertAssignee(event: H3Event, userId: number, thread: Pick<InboxThreadRow, 'mailboxId' | 'hiddenBelow'>): Promise<void>;
|
|
69
|
+
/** The most candidates `inboxAssigneeCandidates` answers, and the most users it looks at to find them. */
|
|
70
|
+
export declare const INBOX_ASSIGNEE_LIMIT = 50;
|
|
71
|
+
/**
|
|
72
|
+
* The users who could be assigned `thread` (`inboxUserCanAccessThread`, the rule `inboxAssertAssignee` enforces), by
|
|
73
|
+
* name, optionally those whose name contains `q`. Users are read in D1-sized pages; at most `INBOX_ASSIGNEE_LIMIT` are
|
|
74
|
+
* answered and `INBOX_ASSIGNEE_SCAN` looked at, so `q` narrows a large user base. It pages through `users` itself (an
|
|
75
|
+
* access check per row decides who counts), so it does not use `searchUserRefs`.
|
|
76
|
+
*/
|
|
77
|
+
export declare function inboxAssigneeCandidates(event: H3Event, thread: Pick<InboxThreadRow, 'mailboxId' | 'hiddenBelow'>, options?: {
|
|
78
|
+
q?: string;
|
|
79
|
+
}): Promise<InboxUserRef[]>;
|