@cosmicdrift/kumiko-samples 0.377.0 → 0.378.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/package.json +1 -1
- package/packages/bundled-features/package.json +1 -1
- package/packages/bundled-features/src/cap-counter/changes.json +12 -0
- package/packages/bundled-features/src/cap-counter/stock-cap-guard.ts +9 -0
- package/packages/bundled-features/src/config/web/i18n.ts +1 -0
- package/packages/bundled-features/src/inbound-mail-foundation/changes.json +6 -0
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/list-accounts.query.ts +11 -4
- package/packages/bundled-features/src/mail-foundation/changes.json +6 -0
- package/packages/bundled-features/src/mail-foundation/i18n.ts +3 -2
- package/packages/bundled-features/src/mail-transport-smtp/i18n.ts +1 -1
- package/packages/bundled-features/src/template-resolver/changes.json +20 -0
- package/packages/bundled-features/src/template-resolver/compile-document-body.ts +61 -3
- package/packages/bundled-features/src/template-resolver/constants.ts +3 -0
- package/packages/bundled-features/src/template-resolver/document-blocks.ts +3 -1
- package/packages/bundled-features/src/template-resolver/document-images.ts +29 -0
- package/packages/bundled-features/src/template-resolver/document-sanitizer.ts +35 -0
- package/packages/bundled-features/src/template-resolver/document-schema.ts +5 -0
- package/packages/bundled-features/src/template-resolver/feature.ts +77 -36
- package/packages/bundled-features/src/template-resolver/handlers/collection-item.query.ts +1 -1
- package/packages/bundled-features/src/template-resolver/handlers/collection-list.query.ts +1 -1
- package/packages/bundled-features/src/template-resolver/handlers/collection-set.write.ts +2 -6
- package/packages/bundled-features/src/template-resolver/handlers/collection-shared.ts +0 -6
- package/packages/bundled-features/src/template-resolver/handlers/copy-locale.write.ts +67 -58
- package/packages/bundled-features/src/template-resolver/handlers/discard-draft.write.ts +36 -13
- package/packages/bundled-features/src/template-resolver/handlers/import-bundle.write.ts +37 -28
- package/packages/bundled-features/src/template-resolver/handlers/overview.query.ts +66 -62
- package/packages/bundled-features/src/template-resolver/handlers/patch-draft.write.ts +105 -96
- package/packages/bundled-features/src/template-resolver/handlers/reset-to-system.write.ts +62 -49
- package/packages/bundled-features/src/template-resolver/handlers/resource-link-pdf.write.ts +44 -29
- package/packages/bundled-features/src/template-resolver/handlers/resource-remove.write.ts +52 -36
- package/packages/bundled-features/src/template-resolver/handlers/resource-upload.write.ts +126 -106
- package/packages/bundled-features/src/template-resolver/handlers/send-test-shared.ts +38 -0
- package/packages/bundled-features/src/template-resolver/handlers/send-test-status.query.ts +31 -0
- package/packages/bundled-features/src/template-resolver/handlers/send-test.write.ts +105 -111
- package/packages/bundled-features/src/template-resolver/handlers/set.write.ts +110 -103
- package/packages/bundled-features/src/template-resolver/handlers/toggle-status.write.ts +56 -28
- package/packages/bundled-features/src/template-resolver/handlers/upsert-tenant.write.ts +38 -29
- package/packages/bundled-features/src/template-resolver/index.ts +8 -1
- package/packages/bundled-features/src/template-resolver/qualified-names.ts +2 -0
- package/packages/bundled-features/src/template-resolver/template-edit-policy.ts +91 -0
- package/packages/bundled-features/src/template-resolver/template-preview.ts +8 -2
- package/packages/bundled-features/src/template-resolver/template-validation.ts +31 -10
- package/packages/bundled-features/src/template-resolver/web/document-editor-extensions.ts +29 -0
- package/packages/bundled-features/src/template-resolver/web/document-tiptap-editor.tsx +42 -4
- package/packages/bundled-features/src/template-resolver/web/document-toolbar-blocks.ts +2 -0
- package/packages/bundled-features/src/template-resolver/web/i18n.ts +6 -0
- package/samples/apps/ui-walkthrough/src/app/help-action.tsx +37 -0
- package/samples/apps/ui-walkthrough/src/app/seed-templates.ts +2 -0
- package/samples/apps/ui-walkthrough/src/app/shell.tsx +6 -0
- package/samples/apps/ui-walkthrough/src/app/template-seed-data.ts +20 -0
- package/samples/apps/ui-walkthrough/src/features/rental/feature.ts +65 -1
- package/samples/apps/ui-walkthrough/src/features/rental/i18n.ts +70 -0
- package/samples/apps/ui-walkthrough/src/features/rental/invoice-receive.ts +20 -0
- package/samples/apps/ui-walkthrough/src/features/rental/lease-support.ts +15 -0
- package/samples/apps/ui-walkthrough/src/features/rental/qualified-names.ts +2 -0
- package/samples/apps/ui-walkthrough/src/features/rental/screens.ts +79 -0
- package/samples/apps/ui-walkthrough/src/features/rental/web/index.ts +2 -0
- package/samples/apps/ui-walkthrough/src/features/rental/web/upload-standard-layout.tsx +61 -0
- package/samples/apps/ui-walkthrough/src/features/tasks/i18n.ts +8 -0
- package/samples/apps/ui-walkthrough/src/run-config.ts +32 -3
- package/samples/apps/use-all-bundled/feature-manifest.json +2 -2
- package/samples/recipes/delivery-notifications/README.md +1 -1
- package/samples/recipes/embedded/README.md +8 -0
- package/samples/recipes/embedded/src/feature.ts +8 -0
- package/samples/recipes/embedded/src/handlers/invoice-receive.write.ts +38 -0
- package/samples/recipes/embedded/src/screens/invoice-receive.screen.ts +59 -0
|
@@ -5,46 +5,62 @@ import * as z from "zod";
|
|
|
5
5
|
import { requireForTenant } from "../../shared/index.ts";
|
|
6
6
|
import { parseLinkedResourceEntries } from "../linked-resources.ts";
|
|
7
7
|
import { type TemplateResourceRow, templateResourcesTable } from "../table.ts";
|
|
8
|
+
import {
|
|
9
|
+
refuseTemplateEditById,
|
|
10
|
+
type TemplateEditPolicy,
|
|
11
|
+
templateEditAccess,
|
|
12
|
+
} from "../template-edit-policy.ts";
|
|
8
13
|
import { resourceKeySchema, resourceTargetTenantId } from "./resource-shared.ts";
|
|
9
14
|
import { executor } from "./shared.ts";
|
|
10
15
|
|
|
11
16
|
// The FileRef itself stays: copy-locale and tenant overrides can share ids and there is
|
|
12
17
|
// no reference count to tell when the last user is gone.
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
18
|
+
export function makeResourceRemoveWrite(policy: TemplateEditPolicy) {
|
|
19
|
+
return defineWriteHandler({
|
|
20
|
+
name: "resource-remove",
|
|
21
|
+
schema: z.object({
|
|
22
|
+
templateId: z.string().min(1),
|
|
23
|
+
key: resourceKeySchema,
|
|
24
|
+
/** Cross-tenant target — SystemAdmin only. */
|
|
25
|
+
tenantIdOverride: z.string().min(1).optional(),
|
|
26
|
+
}),
|
|
27
|
+
access: templateEditAccess(policy.tenantEditable),
|
|
28
|
+
description:
|
|
29
|
+
"Unlinks a resource key from a template, whether it holds an image, an attached file or a linked PDF template; removing a key the template does not have succeeds without a change. Outside the templates the app lists in tenantEditable only a SystemAdmin may use it.",
|
|
30
|
+
handler: async (event, ctx) => {
|
|
31
|
+
const { templateId, key } = event.payload;
|
|
32
|
+
const tenantId = resourceTargetTenantId(event.payload.tenantIdOverride, event.user.tenantId);
|
|
33
|
+
const refused = await refuseTemplateEditById(
|
|
34
|
+
ctx.db,
|
|
35
|
+
policy,
|
|
36
|
+
event.user,
|
|
37
|
+
tenantId,
|
|
38
|
+
templateId,
|
|
39
|
+
);
|
|
40
|
+
if (refused !== null) return refused;
|
|
41
|
+
const { db, streamTenantId } = requireForTenant(ctx, tenantId);
|
|
42
|
+
const row = await fetchOne<TemplateResourceRow>(db, templateResourcesTable, {
|
|
43
|
+
tenantId,
|
|
44
|
+
id: templateId,
|
|
45
|
+
});
|
|
46
|
+
if (row === undefined)
|
|
47
|
+
return writeFailure(new NotFoundError("template-resource", templateId));
|
|
33
48
|
|
|
34
|
-
|
|
35
|
-
|
|
49
|
+
const { [key]: removed, ...remaining } = parseLinkedResourceEntries(row.linkedResources);
|
|
50
|
+
if (removed === undefined) return { isSuccess: true as const, data: { key, removed: false } };
|
|
36
51
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
});
|
|
52
|
+
const updated = await executor.update(
|
|
53
|
+
{
|
|
54
|
+
id: row.id,
|
|
55
|
+
version: row.version,
|
|
56
|
+
changes: { linkedResources: JSON.stringify(remaining) },
|
|
57
|
+
},
|
|
58
|
+
event.user,
|
|
59
|
+
db,
|
|
60
|
+
{ streamTenantId },
|
|
61
|
+
);
|
|
62
|
+
if (!updated.isSuccess) return updated;
|
|
63
|
+
return { isSuccess: true as const, data: { key, removed: true } };
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
}
|
|
@@ -26,6 +26,11 @@ import {
|
|
|
26
26
|
storePreparedTemplateAttachment,
|
|
27
27
|
storePreparedTemplateResource,
|
|
28
28
|
} from "../store-template-resource.ts";
|
|
29
|
+
import {
|
|
30
|
+
refuseTemplateEditById,
|
|
31
|
+
type TemplateEditPolicy,
|
|
32
|
+
templateEditAccess,
|
|
33
|
+
} from "../template-edit-policy.ts";
|
|
29
34
|
import { RESOURCE_PURPOSES, resourceKeySchema, resourceTargetTenantId } from "./resource-shared.ts";
|
|
30
35
|
|
|
31
36
|
type AttachmentTarget = {
|
|
@@ -48,127 +53,142 @@ function attachmentTargetOf(input: {
|
|
|
48
53
|
// Purpose "image": stores a re-encoded image as a FileRef and, with templateId + key, links it into
|
|
49
54
|
// the template; without templateId it only creates the FileRef (the branding logo upload path).
|
|
50
55
|
// Purpose "attachment": stores the file as uploaded and links it as a mail attachment.
|
|
51
|
-
export
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}),
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
const maxBytes = await readTemplateResourceMaxBytes(ctx.config, ctx.registry);
|
|
89
|
-
|
|
90
|
-
// The source is read from the session tenant only: with tenantIdOverride the upload
|
|
91
|
-
// sits in the admin's own tenant while the normalized file lands in the target tenant.
|
|
92
|
-
// Only the caller's own unclaimed upload qualifies, so a record-attached image of
|
|
93
|
-
// someone else cannot be copied into a template.
|
|
94
|
-
let source: Awaited<ReturnType<typeof readFileRefContent>>;
|
|
95
|
-
try {
|
|
96
|
-
source = await readFileRefContent({
|
|
97
|
-
db: ctx.db,
|
|
98
|
-
filesForTenant: (tid) => fileContextForTenant(ctx, ctx.user.tenantId, tid),
|
|
99
|
-
fileRefId: sourceFileRefId,
|
|
100
|
-
allowedTenantIds: [event.user.tenantId],
|
|
101
|
-
unclaimedUploadOf: event.user.id,
|
|
102
|
-
maxBytes,
|
|
103
|
-
});
|
|
104
|
-
} catch (cause) {
|
|
105
|
-
if (cause instanceof FileRefTooLargeError) {
|
|
56
|
+
export function makeResourceUploadWrite(policy: TemplateEditPolicy) {
|
|
57
|
+
return defineWriteHandler({
|
|
58
|
+
name: "resource-upload",
|
|
59
|
+
schema: z
|
|
60
|
+
.object({
|
|
61
|
+
templateId: z.string().min(1).optional(),
|
|
62
|
+
key: resourceKeySchema.optional(),
|
|
63
|
+
/** An unclaimed upload of the caller (POST /api/files without entityType). */
|
|
64
|
+
sourceFileRefId: z.uuid(),
|
|
65
|
+
/** Cross-tenant target — SystemAdmin only. */
|
|
66
|
+
tenantIdOverride: z.string().min(1).optional(),
|
|
67
|
+
/** "attachment" links a PDF/PNG/JPEG as a file attached to every mail of the template. */
|
|
68
|
+
purpose: z.enum(RESOURCE_PURPOSES).default("image"),
|
|
69
|
+
/** Name the recipient sees; required for purpose "attachment". */
|
|
70
|
+
fileName: z.string().optional(),
|
|
71
|
+
})
|
|
72
|
+
.refine(
|
|
73
|
+
(p) => p.purpose === "attachment" || (p.templateId === undefined) === (p.key === undefined),
|
|
74
|
+
{
|
|
75
|
+
message: "templateId and key must be given together",
|
|
76
|
+
path: ["key"],
|
|
77
|
+
},
|
|
78
|
+
),
|
|
79
|
+
access: templateEditAccess(policy.tenantEditable),
|
|
80
|
+
description:
|
|
81
|
+
"Turns a file uploaded via POST /api/files (multipart, no entityType) into a template resource. With purpose image (default) the upload is checked against the resource-max-bytes cap, re-encoded to a supported image format and stored as a new file; with templateId and key it is linked into that template under the key, without them only the file is created. With purpose attachment, templateId, key and fileName are required: a PDF, PNG or JPEG is stored unchanged and linked into a mail template as a file attached to every mail sent from it, at most 10 per template. A cap above the files route's maxUploadSize has no effect. Only a SystemAdmin and the roles of the templates the app lists in tenantEditable may use it; such a role may link only into those templates.",
|
|
82
|
+
beforeTransaction: async (
|
|
83
|
+
event,
|
|
84
|
+
ctx,
|
|
85
|
+
): Promise<BeforeTransactionResult<PreparedTemplateFile>> => {
|
|
86
|
+
const { templateId, key, sourceFileRefId, purpose, fileName } = event.payload;
|
|
87
|
+
const attachmentTarget =
|
|
88
|
+
purpose === "attachment" ? attachmentTargetOf({ templateId, key, fileName }) : null;
|
|
89
|
+
if (purpose === "attachment" && attachmentTarget === null) {
|
|
106
90
|
return writeFailure(
|
|
107
|
-
new UnprocessableError(TemplateResolverErrors.
|
|
108
|
-
i18nKey: "templateResolver.errors.
|
|
109
|
-
details: {
|
|
91
|
+
new UnprocessableError(TemplateResolverErrors.attachmentInvalid, {
|
|
92
|
+
i18nKey: "templateResolver.errors.attachment.invalid",
|
|
93
|
+
details: { code: "target_required" },
|
|
110
94
|
}),
|
|
111
95
|
);
|
|
112
96
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
97
|
+
if (templateId !== undefined) {
|
|
98
|
+
const refused = await refuseTemplateEditById(
|
|
99
|
+
ctx.db,
|
|
100
|
+
policy,
|
|
101
|
+
event.user,
|
|
102
|
+
resourceTargetTenantId(event.payload.tenantIdOverride, event.user.tenantId),
|
|
103
|
+
templateId,
|
|
104
|
+
);
|
|
105
|
+
if (refused !== null) return refused;
|
|
106
|
+
}
|
|
107
|
+
const maxBytes = await readTemplateResourceMaxBytes(ctx.config, ctx.registry);
|
|
116
108
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
109
|
+
// The source is read from the session tenant only: with tenantIdOverride the upload
|
|
110
|
+
// sits in the admin's own tenant while the normalized file lands in the target tenant.
|
|
111
|
+
// Only the caller's own unclaimed upload qualifies, so a record-attached image of
|
|
112
|
+
// someone else cannot be copied into a template.
|
|
113
|
+
let source: Awaited<ReturnType<typeof readFileRefContent>>;
|
|
114
|
+
try {
|
|
115
|
+
source = await readFileRefContent({
|
|
116
|
+
db: ctx.db,
|
|
117
|
+
filesForTenant: (tid) => fileContextForTenant(ctx, ctx.user.tenantId, tid),
|
|
118
|
+
fileRefId: sourceFileRefId,
|
|
119
|
+
allowedTenantIds: [event.user.tenantId],
|
|
120
|
+
unclaimedUploadOf: event.user.id,
|
|
121
|
+
maxBytes,
|
|
122
|
+
});
|
|
123
|
+
} catch (cause) {
|
|
124
|
+
if (cause instanceof FileRefTooLargeError) {
|
|
125
|
+
return writeFailure(
|
|
126
|
+
new UnprocessableError(TemplateResolverErrors.resourceTooLarge, {
|
|
127
|
+
i18nKey: "templateResolver.errors.resource.tooLarge",
|
|
128
|
+
details: { maxBytes, size: cause.size },
|
|
129
|
+
}),
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
throw cause;
|
|
133
|
+
}
|
|
134
|
+
if (source === null) return writeFailure(new NotFoundError("file-ref", sourceFileRefId));
|
|
135
|
+
|
|
136
|
+
// The source upload stays as an unclaimed file: bundled-features cannot reach the fileRef executor to delete it.
|
|
137
|
+
const tenantId = resourceTargetTenantId(event.payload.tenantIdOverride, event.user.tenantId);
|
|
138
|
+
if (attachmentTarget !== null) {
|
|
139
|
+
return prepareTemplateAttachmentBeforeTransaction({
|
|
140
|
+
ctx,
|
|
141
|
+
user: event.user,
|
|
142
|
+
tenantId,
|
|
143
|
+
bytes: source.content,
|
|
144
|
+
maxBytes,
|
|
145
|
+
...attachmentTarget,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
return prepareTemplateResourceBeforeTransaction({
|
|
121
149
|
ctx,
|
|
122
150
|
user: event.user,
|
|
123
151
|
tenantId,
|
|
124
152
|
bytes: source.content,
|
|
125
153
|
maxBytes,
|
|
126
|
-
...
|
|
154
|
+
...(templateId !== undefined && { templateId }),
|
|
155
|
+
...(key !== undefined && { key }),
|
|
127
156
|
});
|
|
128
|
-
}
|
|
129
|
-
|
|
157
|
+
},
|
|
158
|
+
handler: async (
|
|
159
|
+
event,
|
|
130
160
|
ctx,
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}),
|
|
154
|
-
);
|
|
161
|
+
): Promise<WriteResult<StoredTemplateResource | StoredTemplateAttachment>> => {
|
|
162
|
+
const { templateId, key } = event.payload;
|
|
163
|
+
const tenantId = resourceTargetTenantId(event.payload.tenantIdOverride, event.user.tenantId);
|
|
164
|
+
const { prepared } = event;
|
|
165
|
+
if (prepared.kind === "attachment") {
|
|
166
|
+
// The phase accepts attachments only with a complete target, so these are set.
|
|
167
|
+
if (templateId === undefined || key === undefined) {
|
|
168
|
+
return writeFailure(
|
|
169
|
+
new UnprocessableError(TemplateResolverErrors.attachmentInvalid, {
|
|
170
|
+
i18nKey: "templateResolver.errors.attachment.invalid",
|
|
171
|
+
details: { code: "target_required" },
|
|
172
|
+
}),
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
return storePreparedTemplateAttachment({
|
|
176
|
+
ctx,
|
|
177
|
+
user: event.user,
|
|
178
|
+
tenantId,
|
|
179
|
+
prepared,
|
|
180
|
+
templateId,
|
|
181
|
+
key,
|
|
182
|
+
});
|
|
155
183
|
}
|
|
156
|
-
return
|
|
184
|
+
return storePreparedTemplateResource({
|
|
157
185
|
ctx,
|
|
158
186
|
user: event.user,
|
|
159
187
|
tenantId,
|
|
160
188
|
prepared,
|
|
161
|
-
templateId,
|
|
162
|
-
key,
|
|
189
|
+
...(templateId !== undefined && { templateId }),
|
|
190
|
+
...(key !== undefined && { key }),
|
|
163
191
|
});
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
user: event.user,
|
|
168
|
-
tenantId,
|
|
169
|
-
prepared,
|
|
170
|
-
...(templateId !== undefined && { templateId }),
|
|
171
|
-
...(key !== undefined && { key }),
|
|
172
|
-
});
|
|
173
|
-
},
|
|
174
|
-
});
|
|
192
|
+
},
|
|
193
|
+
});
|
|
194
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { HandlerContext, Registry, SessionUser } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
import {
|
|
3
|
+
type ChannelContext,
|
|
4
|
+
collectChannels,
|
|
5
|
+
createEmailAttachmentReader,
|
|
6
|
+
EMAIL_CHANNEL_NAME,
|
|
7
|
+
} from "../../delivery/index.ts";
|
|
8
|
+
import { fileContextForTenant } from "../../file-foundation/index.ts";
|
|
9
|
+
|
|
10
|
+
export function emailChannelOf(registry: Registry) {
|
|
11
|
+
return collectChannels(registry).find((channel) => channel.name === EMAIL_CHANNEL_NAME);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function testMailChannelContext(ctx: HandlerContext, user: SessionUser): ChannelContext {
|
|
15
|
+
return {
|
|
16
|
+
db: ctx.db,
|
|
17
|
+
registry: ctx.registry,
|
|
18
|
+
sseBroker: undefined,
|
|
19
|
+
tenantId: user.tenantId,
|
|
20
|
+
secrets: ctx.secrets,
|
|
21
|
+
config: ctx.config,
|
|
22
|
+
readAttachment: createEmailAttachmentReader(
|
|
23
|
+
ctx.db,
|
|
24
|
+
ctx.registry,
|
|
25
|
+
user.tenantId,
|
|
26
|
+
ctx.config,
|
|
27
|
+
(tenantId) => fileContextForTenant(ctx, ctx.user.tenantId, tenantId),
|
|
28
|
+
),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export async function resolveTestMailAddress(
|
|
33
|
+
channel: NonNullable<ReturnType<typeof emailChannelOf>>,
|
|
34
|
+
channelContext: ChannelContext,
|
|
35
|
+
user: SessionUser,
|
|
36
|
+
): Promise<string | null> {
|
|
37
|
+
return (await channel.resolve?.(user.id, channelContext)) ?? null;
|
|
38
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { defineQueryHandler } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
import * as z from "zod";
|
|
3
|
+
import {
|
|
4
|
+
emailChannelOf,
|
|
5
|
+
resolveTestMailAddress,
|
|
6
|
+
testMailChannelContext,
|
|
7
|
+
} from "./send-test-shared.ts";
|
|
8
|
+
|
|
9
|
+
export type SendTestStatus =
|
|
10
|
+
| { readonly canSend: true; readonly reason: null }
|
|
11
|
+
| { readonly canSend: false; readonly reason: "no_channel" | "no_address" };
|
|
12
|
+
|
|
13
|
+
export const sendTestStatusQuery = defineQueryHandler({
|
|
14
|
+
name: "send-test-status",
|
|
15
|
+
schema: z.object({}),
|
|
16
|
+
access: { roles: ["TenantAdmin", "SystemAdmin"] },
|
|
17
|
+
description:
|
|
18
|
+
"Tells whether send-test can reach the calling user: canSend is true when an email channel is mounted and resolves an address for the caller, otherwise reason is no_channel or no_address; the address itself is never returned.",
|
|
19
|
+
handler: async (query, ctx): Promise<SendTestStatus> => {
|
|
20
|
+
const channel = emailChannelOf(ctx.registry);
|
|
21
|
+
if (channel === undefined) return { canSend: false, reason: "no_channel" };
|
|
22
|
+
const address = await resolveTestMailAddress(
|
|
23
|
+
channel,
|
|
24
|
+
testMailChannelContext(ctx, query.user),
|
|
25
|
+
query.user,
|
|
26
|
+
);
|
|
27
|
+
return address === null
|
|
28
|
+
? { canSend: false, reason: "no_address" }
|
|
29
|
+
: { canSend: true, reason: null };
|
|
30
|
+
},
|
|
31
|
+
});
|