@cosmicdrift/kumiko-bundled-features 0.404.1 → 0.406.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/dist/auth-email-password/mail-notifications.d.ts +3 -3
- package/dist/auth-email-password/mail-notifications.js +10 -34
- package/dist/auth-email-password/web/default-topbar-actions.d.ts +6 -1
- package/dist/auth-email-password/web/default-topbar-actions.js +2 -2
- package/dist/auth-email-password/web/index.d.ts +2 -0
- package/dist/auth-email-password/web/index.js +1 -0
- package/dist/auth-email-password/web/invite-accept-screen.js +6 -41
- package/dist/auth-email-password/web/tenant-label.d.ts +2 -0
- package/dist/auth-email-password/web/tenant-label.js +10 -0
- package/dist/auth-email-password/web/tenant-menu-items.js +2 -7
- package/dist/auth-email-password/web/tenant-switcher.js +5 -12
- package/dist/auth-email-password/web/use-redirect-authed-from-login.d.ts +7 -0
- package/dist/auth-email-password/web/use-redirect-authed-from-login.js +30 -0
- package/dist/auth-foundation/feature.js +8 -21
- package/dist/auth-mfa/handlers/reencrypt.job.js +7 -15
- package/dist/auth-mfa/hmac-token-codec.d.ts +6 -1
- package/dist/auth-mfa/hmac-token-codec.js +8 -10
- package/dist/auth-mfa/mfa-challenge-token.js +2 -8
- package/dist/auth-mfa/mfa-preauth-setup-token.js +2 -8
- package/dist/auth-mfa/mfa-setup-token.d.ts +2 -8
- package/dist/auth-mfa/mfa-setup-token.js +8 -45
- package/dist/billing-foundation/consumer-protection/termination-revoke.js +3 -11
- package/dist/billing-foundation/feature.js +1 -5
- package/dist/billing-foundation/handlers/process-event.write.js +2 -6
- package/dist/billing-foundation/handlers/process-payment-event.write.js +2 -6
- package/dist/billing-foundation/index.d.ts +2 -0
- package/dist/billing-foundation/index.js +2 -0
- package/dist/billing-foundation/projection.js +12 -21
- package/dist/billing-foundation/provider-event-seen.d.ts +5 -0
- package/dist/billing-foundation/provider-event-seen.js +7 -0
- package/dist/billing-foundation/provider-shared.d.ts +11 -0
- package/dist/billing-foundation/provider-shared.js +44 -0
- package/dist/billing-foundation/tenant-destroy-hook.js +5 -4
- package/dist/channel-email/feature.js +1 -1
- package/dist/config/handlers/reencrypt.job.js +7 -15
- package/dist/delivery/delivery-service.js +2 -8
- package/dist/file-derivatives/feature.js +9 -21
- package/dist/file-foundation/feature.js +2 -6
- package/dist/files-tenant-data/hooks.js +1 -6
- package/dist/folders/feature.js +2 -9
- package/dist/folders/web/folder-manager.js +7 -26
- package/dist/folders/web/folder-section.js +5 -24
- package/dist/form-draft/handlers/save.write.d.ts +9 -0
- package/dist/form-draft/handlers/save.write.js +3 -7
- package/dist/inbound-mail-foundation/feature.js +2 -6
- package/dist/inbound-mail-foundation/oauth-state.js +5 -13
- package/dist/inbound-mail-foundation/tenant-destroy-hook.d.ts +1 -1
- package/dist/inbound-mail-foundation/tenant-destroy-hook.js +3 -18
- package/dist/jobs/handlers/tenant-failures.query.js +1 -15
- package/dist/jobs/handlers/tenant-runs.query.js +1 -14
- package/dist/jobs/job-run-logger.js +19 -23
- package/dist/jobs/parse-subject.d.ts +1 -0
- package/dist/jobs/parse-subject.js +15 -0
- package/dist/ledger/feature.js +2 -8
- package/dist/mail-foundation/feature.js +3 -7
- package/dist/managed-pages/render-page-body.js +4 -12
- package/dist/notes-history/feature.js +2 -9
- package/dist/personal-access-tokens/handlers/list.query.js +1 -9
- package/dist/personal-access-tokens/hash.js +2 -2
- package/dist/personal-access-tokens/parse-scope-names.d.ts +1 -0
- package/dist/personal-access-tokens/parse-scope-names.js +10 -0
- package/dist/personal-access-tokens/resolver.js +1 -9
- package/dist/renderer-foundation/feature.js +3 -14
- package/dist/secrets/handlers/rotate.job.js +7 -18
- package/dist/shared/collect-extension-options.d.ts +4 -0
- package/dist/shared/collect-extension-options.js +8 -0
- package/dist/shared/hmac-signature.d.ts +2 -0
- package/dist/shared/hmac-signature.js +10 -0
- package/dist/shared/index.d.ts +6 -0
- package/dist/shared/index.js +6 -0
- package/dist/shared/is-unique-constraint-failure.d.ts +2 -0
- package/dist/shared/is-unique-constraint-failure.js +7 -0
- package/dist/shared/mail-locale-templates.d.ts +12 -0
- package/dist/shared/mail-locale-templates.js +36 -0
- package/dist/shared/resolve-feature-access.d.ts +7 -0
- package/dist/shared/resolve-feature-access.js +8 -0
- package/dist/shared/signed-token.js +4 -14
- package/dist/shared/single-use-token-store.js +2 -2
- package/dist/shared/stream-tenant-derived-state.js +1 -5
- package/dist/shared/tenant-db-cache.d.ts +3 -0
- package/dist/shared/tenant-db-cache.js +14 -0
- package/dist/shared/web/status-banner.d.ts +15 -0
- package/dist/shared/web/status-banner.js +13 -0
- package/dist/shared/web/use-dispatched-writes.d.ts +8 -0
- package/dist/shared/web/use-dispatched-writes.js +29 -0
- package/dist/subscription-paddle/feature.js +2 -15
- package/dist/subscription-paddle/price-methods.d.ts +2 -5
- package/dist/subscription-paddle/price-methods.js +5 -26
- package/dist/subscription-paddle/runtime.d.ts +1 -1
- package/dist/subscription-paddle/runtime.js +3 -16
- package/dist/subscription-stripe/feature.js +2 -17
- package/dist/subscription-stripe/plugin-methods.d.ts +2 -5
- package/dist/subscription-stripe/plugin-methods.js +3 -18
- package/dist/subscription-stripe/runtime.js +3 -19
- package/dist/tags/feature.js +2 -9
- package/dist/tags/web/tag-manager.js +5 -24
- package/dist/tags/web/tag-section.js +3 -12
- package/dist/template-resolver/handlers/tenant-overrides.query.js +3 -9
- package/dist/tenant/handlers/decrypt-member-users.d.ts +10 -0
- package/dist/tenant/handlers/decrypt-member-users.js +17 -0
- package/dist/tenant/handlers/members.query.js +2 -17
- package/dist/tenant/handlers/team-list.query.js +4 -17
- package/dist/tenant-lifecycle/archive-and-delete-tenant-rows.d.ts +5 -0
- package/dist/tenant-lifecycle/archive-and-delete-tenant-rows.js +20 -0
- package/dist/tenant-lifecycle/constants.d.ts +1 -0
- package/dist/tenant-lifecycle/constants.js +5 -0
- package/dist/tenant-lifecycle/events.d.ts +2 -0
- package/dist/tenant-lifecycle/events.js +2 -0
- package/dist/tenant-lifecycle/feature.js +1 -1
- package/dist/tenant-lifecycle/index.d.ts +2 -1
- package/dist/tenant-lifecycle/index.js +2 -1
- package/dist/tenant-lifecycle/run-tenant-destroy.d.ts +2 -0
- package/dist/tenant-lifecycle/run-tenant-destroy.js +42 -7
- package/dist/tenant-lifecycle/stages.d.ts +1 -0
- package/dist/tenant-lifecycle/stages.js +4 -1
- package/dist/tier-engine/feature.js +1 -1
- package/dist/user-data-rights/build-hook-db.d.ts +11 -0
- package/dist/user-data-rights/build-hook-db.js +22 -0
- package/dist/user-data-rights/handlers/request-export.write.js +2 -12
- package/dist/user-data-rights/mail-notifications.d.ts +3 -3
- package/dist/user-data-rights/mail-notifications.js +10 -34
- package/dist/user-data-rights/run-forget-cleanup.d.ts +1 -1
- package/dist/user-data-rights/run-forget-cleanup.js +2 -21
- package/dist/user-data-rights/run-user-export.d.ts +1 -1
- package/dist/user-data-rights/run-user-export.js +2 -21
- package/dist/user-data-rights/token-helpers.js +2 -14
- package/dist/user-data-rights/web/privacy-center-screen.js +1 -11
- package/dist/user-profile/web/profile-screen.js +1 -11
- package/package.json +20 -20
- package/src/auth-email-password/changes.json +6 -0
- package/src/auth-mfa/changes.json +6 -0
- package/src/billing-foundation/changes.json +6 -0
- package/src/shared/changes.json +6 -0
- package/src/tenant-lifecycle/changes.json +18 -0
|
@@ -14,31 +14,16 @@
|
|
|
14
14
|
// The actual PII erasure uses crypto-shredding: eraseSubjectKeys deletes the
|
|
15
15
|
// tenant subject key, making event-log payloads AND any ciphertext copies
|
|
16
16
|
// unreadable. These hooks dispose of the rows.
|
|
17
|
-
import {
|
|
18
|
-
import { archiveStream } from "@cosmicdrift/kumiko-framework/event-store";
|
|
17
|
+
import { archiveAndDeleteTenantRows } from "../tenant-lifecycle/index.js";
|
|
19
18
|
import { seenMessageTable, syncCursorTable } from "./entities.js";
|
|
20
19
|
import { INBOUND_MESSAGE_AGGREGATE_TYPE, MAIL_ACCOUNT_AGGREGATE_TYPE, MAIL_THREAD_AGGREGATE_TYPE, } from "./events.js";
|
|
21
20
|
import { ingestFailureTable } from "./ingest-failures.js";
|
|
22
21
|
import { inboundMessagesProjectionTable, mailAccountsProjectionTable, mailThreadsProjectionTable, } from "./projection.js";
|
|
23
22
|
import { quarantineTable } from "./quarantine-entities.js";
|
|
24
|
-
const ARCHIVED_BY = "tenant-lifecycle:destroy";
|
|
25
|
-
const REASON = "tenant_destroy";
|
|
26
23
|
// archiveStream sits outside TenantDb's own methods — needs the escape hatch.
|
|
27
24
|
export const INBOUND_MAIL_TENANT_DESTROY_ARCHIVE_REASON = "tenant-destroy archives each inbound-mail entity's event-streams before the projection rows are deleted";
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const rows = await ctx.db.selectMany(table, { tenantId: ctx.tenantId });
|
|
31
|
-
for (const row of rows) {
|
|
32
|
-
await archiveStream(ctx.db.unsafeRaw(), {
|
|
33
|
-
tenantId: ctx.tenantId,
|
|
34
|
-
aggregateId: row.id,
|
|
35
|
-
aggregateType,
|
|
36
|
-
archivedBy: ARCHIVED_BY,
|
|
37
|
-
reason: REASON,
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
await ctx.db.deleteMany(table, { tenantId: ctx.tenantId });
|
|
41
|
-
return rows.map((row) => row.id);
|
|
25
|
+
function archiveAndDeleteRows(ctx, table, aggregateType) {
|
|
26
|
+
return archiveAndDeleteTenantRows(ctx, table, aggregateType, INBOUND_MAIL_TENANT_DESTROY_ARCHIVE_REASON);
|
|
42
27
|
}
|
|
43
28
|
export async function mailAccountTenantDestroyHook(ctx) {
|
|
44
29
|
const accountIds = await archiveAndDeleteRows(ctx, mailAccountsProjectionTable, MAIL_ACCOUNT_AGGREGATE_TYPE);
|
|
@@ -2,24 +2,10 @@ import { selectMany } from "@cosmicdrift/kumiko-framework/db";
|
|
|
2
2
|
import { access, defineQueryHandler } from "@cosmicdrift/kumiko-framework/engine";
|
|
3
3
|
import { InternalError } from "@cosmicdrift/kumiko-framework/errors";
|
|
4
4
|
import { serializeJobSubject } from "@cosmicdrift/kumiko-framework/jobs";
|
|
5
|
-
import { parseJsonSafe } from "@cosmicdrift/kumiko-framework/utils";
|
|
6
5
|
import * as z from "zod";
|
|
6
|
+
import { parseSubject } from "../parse-subject.js";
|
|
7
7
|
import { tenantJobFailuresTable } from "../tenant-job-failure-table.js";
|
|
8
8
|
const DEFAULT_LIMIT = 50;
|
|
9
|
-
function isSubjectEntry(value) {
|
|
10
|
-
return Array.isArray(value) && typeof value[0] === "string";
|
|
11
|
-
}
|
|
12
|
-
function parseSubject(stored) {
|
|
13
|
-
if (stored === null)
|
|
14
|
-
return null;
|
|
15
|
-
// A corrupt subject must not fail the whole list — the record still tells
|
|
16
|
-
// the tenant which job failed and why. parseJsonSafe only survives a
|
|
17
|
-
// SyntaxError, so the shape needs its own check.
|
|
18
|
-
const parsed = parseJsonSafe(stored, null);
|
|
19
|
-
if (!Array.isArray(parsed))
|
|
20
|
-
return null;
|
|
21
|
-
return Object.fromEntries(parsed.filter(isSubjectEntry));
|
|
22
|
-
}
|
|
23
9
|
export function createTenantFailuresQuery(readRoles) {
|
|
24
10
|
return defineQueryHandler({
|
|
25
11
|
name: "failures",
|
|
@@ -2,23 +2,10 @@ import { selectMany } from "@cosmicdrift/kumiko-framework/db";
|
|
|
2
2
|
import { access, defineQueryHandler } from "@cosmicdrift/kumiko-framework/engine";
|
|
3
3
|
import { InternalError } from "@cosmicdrift/kumiko-framework/errors";
|
|
4
4
|
import { serializeJobSubject } from "@cosmicdrift/kumiko-framework/jobs";
|
|
5
|
-
import { parseJsonSafe } from "@cosmicdrift/kumiko-framework/utils";
|
|
6
5
|
import * as z from "zod";
|
|
6
|
+
import { parseSubject } from "../parse-subject.js";
|
|
7
7
|
import { tenantJobRunsTable } from "../tenant-job-run-table.js";
|
|
8
8
|
const DEFAULT_LIMIT = 50;
|
|
9
|
-
function isSubjectEntry(value) {
|
|
10
|
-
return Array.isArray(value) && typeof value[0] === "string";
|
|
11
|
-
}
|
|
12
|
-
function parseSubject(stored) {
|
|
13
|
-
if (stored === null)
|
|
14
|
-
return null;
|
|
15
|
-
// A corrupt subject must not fail the whole list; parseJsonSafe only
|
|
16
|
-
// survives a SyntaxError, so the shape needs its own check.
|
|
17
|
-
const parsed = parseJsonSafe(stored, null);
|
|
18
|
-
if (!Array.isArray(parsed))
|
|
19
|
-
return null;
|
|
20
|
-
return Object.fromEntries(parsed.filter(isSubjectEntry));
|
|
21
|
-
}
|
|
22
9
|
export function createTenantRunsQuery(readRoles) {
|
|
23
10
|
return defineQueryHandler({
|
|
24
11
|
name: "tenant-runs",
|
|
@@ -80,6 +80,18 @@ async function encryptLogMessages(logs, triggeredById) {
|
|
|
80
80
|
message: await encryptOrSentinel(kms, subject, log.message, "message"),
|
|
81
81
|
}));
|
|
82
82
|
}
|
|
83
|
+
async function insertEncryptedRunLogs(db, runId, triggeredById, logs) {
|
|
84
|
+
// skip: empty log batch — the worker ran silent, no child rows to insert
|
|
85
|
+
if (logs.length === 0)
|
|
86
|
+
return;
|
|
87
|
+
const encryptedLogs = await encryptLogMessages(logs, triggeredById);
|
|
88
|
+
await insertMany(db, jobRunLogsTable, encryptedLogs.map((log) => ({
|
|
89
|
+
runId,
|
|
90
|
+
level: log.level,
|
|
91
|
+
message: log.message,
|
|
92
|
+
timestamp: parseJobInstant(log.timestamp),
|
|
93
|
+
})));
|
|
94
|
+
}
|
|
83
95
|
// Mirrors encryptFailureError for the failure-path `error` column:
|
|
84
96
|
// stored alongside logs[].message under the same triggering user's DEK, so
|
|
85
97
|
// a log/error pair from the same failed run decrypt together or erase
|
|
@@ -210,7 +222,7 @@ async function recordTenantRunOutcome(db, jobName, bullJobId, outcome, result) {
|
|
|
210
222
|
// A failed attempt BullMQ will retry goes back to waiting: the tenant keeps
|
|
211
223
|
// seeing pending work, not a failure the next attempt may still resolve.
|
|
212
224
|
if (result === "failed" && !outcome.finalAttempt) {
|
|
213
|
-
await
|
|
225
|
+
await markTenantRunQueued(db, key.tenantId, jobName, bullJobId, now);
|
|
214
226
|
// skip: retry pending, the row stays active until the final attempt
|
|
215
227
|
return;
|
|
216
228
|
}
|
|
@@ -242,7 +254,10 @@ async function requeueTenantRun(db, jobName, bullJobId, meta) {
|
|
|
242
254
|
// skip: system-tenant run, no tenant-scoped query reads it
|
|
243
255
|
if (!key)
|
|
244
256
|
return;
|
|
245
|
-
await
|
|
257
|
+
await markTenantRunQueued(db, key.tenantId, jobName, bullJobId, Temporal.Now.instant());
|
|
258
|
+
}
|
|
259
|
+
async function markTenantRunQueued(db, tenantId, jobName, bullJobId, updatedAt) {
|
|
260
|
+
await inTenantScope(tenantId, () => updateMany(db, tenantJobRunsTable, { status: "queued", startedAt: null, finishedAt: null, updatedAt }, { tenantId, jobName, bullJobId }));
|
|
246
261
|
}
|
|
247
262
|
async function dropTenantRunQueued(db, jobName, bullJobId, meta) {
|
|
248
263
|
await inTenantScope(meta.tenantId, () => deleteMany(db, tenantJobRunsTable, {
|
|
@@ -420,17 +435,7 @@ export function createJobRunLogger(opts) {
|
|
|
420
435
|
modifiedAt: Temporal.Now.instant(),
|
|
421
436
|
modifiedById: "system",
|
|
422
437
|
}, { id: runId });
|
|
423
|
-
|
|
424
|
-
// insert; the status update above already recorded completion.
|
|
425
|
-
if (payload.logs.length > 0) {
|
|
426
|
-
const encryptedLogs = await encryptLogMessages(payload.logs, triggeredById);
|
|
427
|
-
await insertMany(db, jobRunLogsTable, encryptedLogs.map((log) => ({
|
|
428
|
-
runId,
|
|
429
|
-
level: log.level,
|
|
430
|
-
message: log.message,
|
|
431
|
-
timestamp: parseJobInstant(log.timestamp),
|
|
432
|
-
})));
|
|
433
|
-
}
|
|
438
|
+
await insertEncryptedRunLogs(db, runId, triggeredById, payload.logs);
|
|
434
439
|
runIdByBullJobId.delete(bullJobId); // immediate cleanup on terminal callback
|
|
435
440
|
},
|
|
436
441
|
onJobFailed: async (jobName, bullJobId, error, logs, outcome) => {
|
|
@@ -471,16 +476,7 @@ export function createJobRunLogger(opts) {
|
|
|
471
476
|
modifiedAt: now,
|
|
472
477
|
modifiedById: "system",
|
|
473
478
|
}, { id: runId });
|
|
474
|
-
|
|
475
|
-
if (payload.logs.length > 0) {
|
|
476
|
-
const encryptedLogs = await encryptLogMessages(payload.logs, triggeredById);
|
|
477
|
-
await insertMany(db, jobRunLogsTable, encryptedLogs.map((log) => ({
|
|
478
|
-
runId,
|
|
479
|
-
level: log.level,
|
|
480
|
-
message: log.message,
|
|
481
|
-
timestamp: parseJobInstant(log.timestamp),
|
|
482
|
-
})));
|
|
483
|
-
}
|
|
479
|
+
await insertEncryptedRunLogs(db, runId, triggeredById, payload.logs);
|
|
484
480
|
runIdByBullJobId.delete(bullJobId); // immediate cleanup on terminal callback
|
|
485
481
|
},
|
|
486
482
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function parseSubject(stored: string | null): Record<string, unknown> | null;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { parseJsonSafe } from "@cosmicdrift/kumiko-framework/utils";
|
|
2
|
+
function isSubjectEntry(value) {
|
|
3
|
+
return Array.isArray(value) && typeof value[0] === "string";
|
|
4
|
+
}
|
|
5
|
+
// A corrupt subject must not fail the whole list: the record still tells the
|
|
6
|
+
// tenant which job failed. parseJsonSafe only survives a SyntaxError, so the
|
|
7
|
+
// shape needs its own check.
|
|
8
|
+
export function parseSubject(stored) {
|
|
9
|
+
if (stored === null)
|
|
10
|
+
return null;
|
|
11
|
+
const parsed = parseJsonSafe(stored, null);
|
|
12
|
+
if (!Array.isArray(parsed))
|
|
13
|
+
return null;
|
|
14
|
+
return Object.fromEntries(parsed.filter(isSubjectEntry));
|
|
15
|
+
}
|
package/dist/ledger/feature.js
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
//
|
|
13
13
|
// Spec: kumiko-platform/docs/plans/ledger-feature.md
|
|
14
14
|
import { defineEntityCreateHandler, defineEntityDetailHandler, defineEntityListHandler, defineEntityUpdateHandler, defineFeature, } from "@cosmicdrift/kumiko-framework/engine";
|
|
15
|
+
import { resolveFeatureAccess } from "../shared/index.js";
|
|
15
16
|
import { accountEntity, scheduleEntity, transactionEntity } from "./entity.js";
|
|
16
17
|
import { createConfirmSchedulePeriodHandler } from "./handlers/confirm-schedule-period.write.js";
|
|
17
18
|
import { createCreateTransactionHandler } from "./handlers/create-transaction.write.js";
|
|
@@ -91,19 +92,12 @@ function registerLedger(r, access, toggleable) {
|
|
|
91
92
|
r.queryHandler(createBalanceSheetHandler(access));
|
|
92
93
|
}
|
|
93
94
|
const defaultLedgerFeature = defineFeature(LEDGER_FEATURE_NAME, (r) => registerLedger(r, DEFAULT_LEDGER_ACCESS, undefined));
|
|
94
|
-
function resolveAccess(opts) {
|
|
95
|
-
if (opts.access !== undefined)
|
|
96
|
-
return opts.access;
|
|
97
|
-
if (opts.roles !== undefined)
|
|
98
|
-
return { roles: opts.roles };
|
|
99
|
-
return DEFAULT_LEDGER_ACCESS;
|
|
100
|
-
}
|
|
101
95
|
// Options wrapper. Without options returns the module-level singleton (no
|
|
102
96
|
// rebuild). access/roles/toggleable build a fresh feature-definition.
|
|
103
97
|
export function createLedgerFeature(opts = {}) {
|
|
104
98
|
if (opts.access === undefined && opts.roles === undefined && opts.toggleable === undefined) {
|
|
105
99
|
return defaultLedgerFeature;
|
|
106
100
|
}
|
|
107
|
-
const access =
|
|
101
|
+
const access = resolveFeatureAccess(opts, DEFAULT_LEDGER_ACCESS);
|
|
108
102
|
return defineFeature(LEDGER_FEATURE_NAME, (r) => registerLedger(r, access, opts.toggleable));
|
|
109
103
|
}
|
|
@@ -58,13 +58,9 @@ export function createMailFoundationFeature() {
|
|
|
58
58
|
// Plugin extension-point. Provider-features register here. The
|
|
59
59
|
// entityName at registration time becomes the value tenants pick in
|
|
60
60
|
// `provider` config-key (e.g. "smtp", "brevo-api").
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
// usage, factory looks it up at request-time. Same shape as
|
|
65
|
-
// delivery's extendsRegistrar.
|
|
66
|
-
},
|
|
67
|
-
});
|
|
61
|
+
// The registry stores the usage, factory looks it up at request-time. Same shape as
|
|
62
|
+
// delivery's extendsRegistrar.
|
|
63
|
+
r.extendsRegistrar(MAIL_TRANSPORT_EXTENSION, {});
|
|
68
64
|
// Empty = this tenant has no own provider: tenantMailTransport yields null and
|
|
69
65
|
// channel-email uses the app transport, so empty is a valid choice a tenant can
|
|
70
66
|
// return to (reset in the settings mask) and readiness must not flag it.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createFallbackLogger } from "@cosmicdrift/kumiko-framework/logging";
|
|
2
|
+
import { createLruCache } from "@cosmicdrift/kumiko-framework/utils";
|
|
2
3
|
import { renderSafeMarkdown } from "../page-render/index.js";
|
|
3
4
|
import { sanitizeDocumentHtml } from "../template-resolver/index.js";
|
|
4
5
|
const defaultLog = createFallbackLogger("managed-pages");
|
|
@@ -7,8 +8,7 @@ const MAX_CACHED_BODIES = 500;
|
|
|
7
8
|
// hundreds of MB. A bigger body is still served, just re-rendered per request.
|
|
8
9
|
const MAX_CACHED_BODY_LENGTH = 256 * 1024;
|
|
9
10
|
// Every write bumps the version, so a (page, version) key never serves stale
|
|
10
|
-
// HTML.
|
|
11
|
-
// key the least recently used one.
|
|
11
|
+
// HTML.
|
|
12
12
|
function cacheKeyOf(page) {
|
|
13
13
|
return [page.tenantId, page.slug, page.lang, page.version, page.updatedAt, page.bodyFormat].join("\u0000");
|
|
14
14
|
}
|
|
@@ -20,7 +20,7 @@ export function createPageBodyRenderer(deps = {}) {
|
|
|
20
20
|
const sanitizeDocument = deps.sanitizeDocument ?? sanitizeDocumentHtml;
|
|
21
21
|
const renderMarkdown = deps.renderMarkdown ?? renderSafeMarkdown;
|
|
22
22
|
const maxEntries = deps.maxEntries ?? MAX_CACHED_BODIES;
|
|
23
|
-
const cache =
|
|
23
|
+
const cache = createLruCache({ maxEntries });
|
|
24
24
|
function renderUncached(page, log) {
|
|
25
25
|
if (page.bodyFormat === "markdown")
|
|
26
26
|
return renderMarkdown(page.body);
|
|
@@ -36,20 +36,12 @@ export function createPageBodyRenderer(deps = {}) {
|
|
|
36
36
|
return (page, log = defaultLog) => {
|
|
37
37
|
const key = cacheKeyOf(page);
|
|
38
38
|
const cached = cache.get(key);
|
|
39
|
-
if (cached !== undefined)
|
|
40
|
-
cache.delete(key);
|
|
41
|
-
cache.set(key, cached);
|
|
39
|
+
if (cached !== undefined)
|
|
42
40
|
return cached;
|
|
43
|
-
}
|
|
44
41
|
const html = renderUncached(page, log);
|
|
45
42
|
if (html.length > MAX_CACHED_BODY_LENGTH)
|
|
46
43
|
return html;
|
|
47
44
|
cache.set(key, html);
|
|
48
|
-
if (cache.size > maxEntries) {
|
|
49
|
-
const oldest = cache.keys().next();
|
|
50
|
-
if (!oldest.done)
|
|
51
|
-
cache.delete(oldest.value);
|
|
52
|
-
}
|
|
53
45
|
return html;
|
|
54
46
|
};
|
|
55
47
|
}
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// a new entry, not an edit; see entity.ts for why that still satisfies GDPR
|
|
14
14
|
// erasure without a delete path.
|
|
15
15
|
import { defineEntityListHandler, defineFeature, } from "@cosmicdrift/kumiko-framework/engine";
|
|
16
|
-
import { assertNoWhereRuleInOwnershipWrite } from "../shared/index.js";
|
|
16
|
+
import { assertNoWhereRuleInOwnershipWrite, resolveFeatureAccess } from "../shared/index.js";
|
|
17
17
|
import { createNoteEntryEntity, noteMentionEntity } from "./entity.js";
|
|
18
18
|
import { createNoteEntryExecutor } from "./executor.js";
|
|
19
19
|
import { createAddNoteHandler } from "./handlers/add-note.write.js";
|
|
@@ -42,13 +42,6 @@ function registerNotesHistory(r, access, ownership, parents) {
|
|
|
42
42
|
r.translations({ keys: NOTES_HISTORY_FEATURE_I18N });
|
|
43
43
|
}
|
|
44
44
|
const defaultNotesHistoryFeature = defineFeature(NOTES_HISTORY_FEATURE_NAME, (r) => registerNotesHistory(r, DEFAULT_NOTES_HISTORY_ACCESS, undefined, undefined));
|
|
45
|
-
function resolveAccess(opts) {
|
|
46
|
-
if (opts.access !== undefined)
|
|
47
|
-
return opts.access;
|
|
48
|
-
if (opts.roles !== undefined)
|
|
49
|
-
return { roles: opts.roles };
|
|
50
|
-
return DEFAULT_NOTES_HISTORY_ACCESS;
|
|
51
|
-
}
|
|
52
45
|
// Options wrapper. Without options returns the module-level singleton (no
|
|
53
46
|
// rebuild). access/roles/ownership build a fresh feature-definition.
|
|
54
47
|
export function createNotesHistoryFeature(opts = {}) {
|
|
@@ -67,5 +60,5 @@ export function createNotesHistoryFeature(opts = {}) {
|
|
|
67
60
|
"an empty allowlist rejects every add-note call. Omit `parents` to allow " +
|
|
68
61
|
"any registered entity the caller can read as a note parent.");
|
|
69
62
|
}
|
|
70
|
-
return defineFeature(NOTES_HISTORY_FEATURE_NAME, (r) => registerNotesHistory(r,
|
|
63
|
+
return defineFeature(NOTES_HISTORY_FEATURE_NAME, (r) => registerNotesHistory(r, resolveFeatureAccess(opts, DEFAULT_NOTES_HISTORY_ACCESS), opts.ownership, opts.parents));
|
|
71
64
|
}
|
|
@@ -4,6 +4,7 @@ import { isOneOf } from "@cosmicdrift/kumiko-types/type-guards";
|
|
|
4
4
|
import * as z from "zod";
|
|
5
5
|
import { decryptStoredPii } from "../../shared/index.js";
|
|
6
6
|
import { isExpiredAt } from "../expiry.js";
|
|
7
|
+
import { parseScopeNames } from "../parse-scope-names.js";
|
|
7
8
|
import { apiTokenTable } from "../schema/api-token.js";
|
|
8
9
|
// `sort` arrives raw from the client's query string. selectMany's orderBy has
|
|
9
10
|
// no column-existence check — an unrecognised field just gets snake_cased and
|
|
@@ -20,15 +21,6 @@ function tokenStatus(row) {
|
|
|
20
21
|
return "expired";
|
|
21
22
|
return "active";
|
|
22
23
|
}
|
|
23
|
-
function parseScopeNames(raw) {
|
|
24
|
-
try {
|
|
25
|
-
const parsed = JSON.parse(raw);
|
|
26
|
-
return Array.isArray(parsed) ? parsed.filter((s) => typeof s === "string") : [];
|
|
27
|
-
}
|
|
28
|
-
catch {
|
|
29
|
-
return [];
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
24
|
// The caller's own tokens — metadata only, never the hash or plaintext.
|
|
33
25
|
// Includes revoked/expired rows so the UI can show history; `prefix` is the
|
|
34
26
|
// only fragment of the secret ever exposed.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
1
|
import { generateToken, PAT_TOKEN_PREFIX } from "@cosmicdrift/kumiko-framework/api";
|
|
2
|
+
import { hashOpaqueTokenSync } from "@cosmicdrift/kumiko-framework/crypto";
|
|
3
3
|
import { PAT_PREFIX_DISPLAY_LENGTH } from "./web/constants.js";
|
|
4
4
|
// A PAT is high-entropy (32 random bytes from generateToken). A single SHA-256
|
|
5
5
|
// is the right hash here: fast on the per-request auth path, and there's no
|
|
@@ -7,7 +7,7 @@ import { PAT_PREFIX_DISPLAY_LENGTH } from "./web/constants.js";
|
|
|
7
7
|
// passwords). Only the hash is persisted — the plaintext exists once, in the
|
|
8
8
|
// create response.
|
|
9
9
|
export function hashPatToken(rawToken) {
|
|
10
|
-
return
|
|
10
|
+
return hashOpaqueTokenSync(rawToken);
|
|
11
11
|
}
|
|
12
12
|
export function mintPatToken() {
|
|
13
13
|
const raw = `${PAT_TOKEN_PREFIX}${generateToken()}`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function parseScopeNames(raw: string): string[];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Drops non-string entries rather than rejecting the whole array.
|
|
2
|
+
export function parseScopeNames(raw) {
|
|
3
|
+
try {
|
|
4
|
+
const parsed = JSON.parse(raw);
|
|
5
|
+
return Array.isArray(parsed) ? parsed.filter((s) => typeof s === "string") : [];
|
|
6
|
+
}
|
|
7
|
+
catch {
|
|
8
|
+
return [];
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { fetchOne } from "@cosmicdrift/kumiko-framework/db";
|
|
2
2
|
import { isExpiredAt } from "./expiry.js";
|
|
3
3
|
import { hashPatToken } from "./hash.js";
|
|
4
|
+
import { parseScopeNames } from "./parse-scope-names.js";
|
|
4
5
|
import { resolvePatRoles } from "./roles.js";
|
|
5
6
|
import { apiTokenTable } from "./schema/api-token.js";
|
|
6
7
|
import { expandScopes } from "./web/scopes.js";
|
|
@@ -32,12 +33,3 @@ export function createPatResolver(opts) {
|
|
|
32
33
|
};
|
|
33
34
|
};
|
|
34
35
|
}
|
|
35
|
-
function parseScopeNames(raw) {
|
|
36
|
-
try {
|
|
37
|
-
const parsed = JSON.parse(raw);
|
|
38
|
-
return Array.isArray(parsed) ? parsed.filter((s) => typeof s === "string") : [];
|
|
39
|
-
}
|
|
40
|
-
catch {
|
|
41
|
-
return [];
|
|
42
|
-
}
|
|
43
|
-
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { defineFeature } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
import { collectExtensionOptions } from "../shared/index.js";
|
|
2
3
|
import { RENDERER_EXTENSION } from "./constants.js";
|
|
3
4
|
import { isRendererRegistrationPlugin } from "./types.js";
|
|
4
5
|
// renderer-foundation — plugin foundation for renderers (HTML mail, PDF,
|
|
@@ -18,13 +19,7 @@ export function createRendererFoundationFeature() {
|
|
|
18
19
|
recommended: false,
|
|
19
20
|
});
|
|
20
21
|
r.requires({ features: ["template-resolver"] });
|
|
21
|
-
r.extendsRegistrar(RENDERER_EXTENSION, {
|
|
22
|
-
onRegister: () => {
|
|
23
|
-
// Plugin conformance check could go here: validate the shape of
|
|
24
|
-
// options (kinds, render function present). No shape check currently —
|
|
25
|
-
// the caller's TypeScript type safety applies.
|
|
26
|
-
},
|
|
27
|
-
});
|
|
22
|
+
r.extendsRegistrar(RENDERER_EXTENSION, {});
|
|
28
23
|
return {};
|
|
29
24
|
});
|
|
30
25
|
}
|
|
@@ -34,11 +29,5 @@ export function createRendererFoundationFeature() {
|
|
|
34
29
|
//
|
|
35
30
|
// Symmetric to collectChannels / collectRenderers in delivery-service.
|
|
36
31
|
export function collectRendererPlugins(registry) {
|
|
37
|
-
|
|
38
|
-
return usages.map((usage) => {
|
|
39
|
-
if (!isRendererRegistrationPlugin(usage.options)) {
|
|
40
|
-
throw new Error(`${RENDERER_EXTENSION} registration for "${usage.entityName}" has invalid options`);
|
|
41
|
-
}
|
|
42
|
-
return { name: usage.entityName, ...usage.options };
|
|
43
|
-
});
|
|
32
|
+
return collectExtensionOptions(registry, RENDERER_EXTENSION, isRendererRegistrationPlugin);
|
|
44
33
|
}
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
import { createEventStoreExecutor, createTenantDb, selectMany, } from "@cosmicdrift/kumiko-framework/db";
|
|
20
20
|
import { InternalError } from "@cosmicdrift/kumiko-framework/errors";
|
|
21
21
|
import { decodeStoredEnvelope, encodeStoredEnvelope, rewrapDek, } from "@cosmicdrift/kumiko-framework/secrets";
|
|
22
|
-
import { runChunkedMigration } from "../../shared/index.js";
|
|
22
|
+
import { createTenantDbCache, runChunkedMigration, } from "../../shared/index.js";
|
|
23
23
|
import { tenantSecretEntity, tenantSecretsTable } from "../table.js";
|
|
24
24
|
const DEFAULT_BATCH_SIZE = 100;
|
|
25
25
|
const DEFAULT_MAX_FAILURES = 10;
|
|
@@ -40,23 +40,12 @@ export async function rotateJob(rawPayload, ctx, db) {
|
|
|
40
40
|
const deadline = payload.maxDurationMs
|
|
41
41
|
? Date.now() + payload.maxDurationMs
|
|
42
42
|
: Number.POSITIVE_INFINITY;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (!existing) {
|
|
50
|
-
existing = createTenantDb({
|
|
51
|
-
db,
|
|
52
|
-
tenantId,
|
|
53
|
-
mode: "system",
|
|
54
|
-
reason: "secret key rotation job re-encrypts secrets of every tenant",
|
|
55
|
-
});
|
|
56
|
-
tdbCache.set(tenantId, existing);
|
|
57
|
-
}
|
|
58
|
-
return existing;
|
|
59
|
-
}
|
|
43
|
+
const tdbFor = createTenantDbCache((tenantId) => createTenantDb({
|
|
44
|
+
db,
|
|
45
|
+
tenantId,
|
|
46
|
+
mode: "system",
|
|
47
|
+
reason: "secret key rotation job re-encrypts secrets of every tenant",
|
|
48
|
+
}));
|
|
60
49
|
// A partial batch means the ne-filter is exhausted — the next re-query
|
|
61
50
|
// would only re-serve rows that failed above; end the run instead.
|
|
62
51
|
let sawPartialBatch = false;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Registry } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
export declare function collectExtensionOptions<TOptions extends object>(registry: Registry, extension: string, isOptions: (candidate: unknown) => candidate is TOptions): Array<{
|
|
3
|
+
name: string;
|
|
4
|
+
} & TOptions>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export function collectExtensionOptions(registry, extension, isOptions) {
|
|
2
|
+
return registry.getExtensionUsages(extension).map((usage) => {
|
|
3
|
+
if (!isOptions(usage.options)) {
|
|
4
|
+
throw new Error(`${extension} registration for "${usage.entityName}" has invalid options`);
|
|
5
|
+
}
|
|
6
|
+
return { name: usage.entityName, ...usage.options };
|
|
7
|
+
});
|
|
8
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createHmac, timingSafeEqual } from "node:crypto";
|
|
2
|
+
export function signHmacSha256Base64Url(input, secret) {
|
|
3
|
+
return createHmac("sha256", secret).update(input).digest("base64url");
|
|
4
|
+
}
|
|
5
|
+
export function hmacSignatureMatches(expectedBase64Url, providedBase64Url) {
|
|
6
|
+
const expectedBuf = Buffer.from(expectedBase64Url, "base64url");
|
|
7
|
+
const providedBuf = Buffer.from(providedBase64Url, "base64url");
|
|
8
|
+
// timingSafeEqual throws on a length mismatch, and the throw itself is a timing signal.
|
|
9
|
+
return expectedBuf.length === providedBuf.length && timingSafeEqual(expectedBuf, providedBuf);
|
|
10
|
+
}
|
package/dist/shared/index.d.ts
CHANGED
|
@@ -3,13 +3,17 @@ export { assertNoWhereRuleInOwnershipWrite } from "./assert-no-where-rule-in-own
|
|
|
3
3
|
export { attachmentFileNameSchema, sanitizePdfAttachmentFileName, } from "./attachment-file-name.ts";
|
|
4
4
|
export { type ChunkedMigrationOptions, type ChunkedMigrationResult, type ChunkedMigrationStopReason, type MigrationRowOutcome, runChunkedMigration, } from "./chunked-entity-migration.ts";
|
|
5
5
|
export { classifyStoredEnvelope, type StoredEnvelopeClassification, } from "./classify-stored-envelope.ts";
|
|
6
|
+
export { collectExtensionOptions } from "./collect-extension-options.ts";
|
|
6
7
|
export { decryptStoredPii, decryptStoredUserEmail } from "./decrypt-stored-pii.ts";
|
|
7
8
|
export { encryptForDirectWrite } from "./encrypt-for-direct-write.ts";
|
|
8
9
|
export { entitiesOf } from "./entities-of.ts";
|
|
9
10
|
export { isWithinGracePeriod } from "./grace-period.ts";
|
|
11
|
+
export { hmacSignatureMatches, signHmacSha256Base64Url } from "./hmac-signature.ts";
|
|
10
12
|
export { isIdentityV3Hash, verifyIdentityV3Hash } from "./identity-v3-hash.ts";
|
|
11
13
|
export { isTenantDb } from "./is-tenant-db.ts";
|
|
14
|
+
export { isUniqueConstraintFailure } from "./is-unique-constraint-failure.ts";
|
|
12
15
|
export { createLockoutCounter, type LockoutCounterState } from "./lockout-counter.ts";
|
|
16
|
+
export { createMailLocaleTemplates } from "./mail-locale-templates.ts";
|
|
13
17
|
export { mailHeading, mailParagraph, mailParagraphWithLink, mailRepeatedRows, } from "./mail-template-body.ts";
|
|
14
18
|
export { mapWithConcurrency } from "./map-with-concurrency.ts";
|
|
15
19
|
export { denyUnlessJoinRowParentVisible, hostRowIsGone, joinRowParentIsVisible, parentRowIsVisible, } from "./parent-visibility.ts";
|
|
@@ -20,6 +24,7 @@ export { rateLimitedTextResponse } from "./rate-limited-text-response.ts";
|
|
|
20
24
|
export { redactBotTokens, redactEmailAddresses, redactErrorText, redactUrls, } from "./redact.ts";
|
|
21
25
|
export { REDACTED_PII_PLACEHOLDER, redactPiiCiphertext } from "./redact-pii-ciphertext.ts";
|
|
22
26
|
export { requireForTenant } from "./require-for-tenant.ts";
|
|
27
|
+
export { resolveFeatureAccess } from "./resolve-feature-access.ts";
|
|
23
28
|
export { extensionForResourceContentType, isResourceImageContentType, isResourceImageFormat, RESOURCE_IMAGE_FORMATS, type ResourceImageContentType, type ResourceImageFormat, } from "./resource-image-formats.ts";
|
|
24
29
|
export { type RowBoundGrantResult, redeemRowBoundGrant, signRowBoundGrant, } from "./row-bound-grant.ts";
|
|
25
30
|
export { runInSubTransaction } from "./run-in-sub-transaction.ts";
|
|
@@ -32,4 +37,5 @@ export { createSingleUseTokenStore, hashSingleUseToken } from "./single-use-toke
|
|
|
32
37
|
export { backfillAggregateStreamTenants, type StreamBackfillCandidate, type StreamBackfillFailure, type StreamBackfillOptions, type StreamBackfillResult, type StreamTenantTarget, } from "./stream-tenant-backfill.ts";
|
|
33
38
|
export { createSearchBucketCleanup, type DerivedStateMode, rebuildAndReindex, type StreamBackfillStepFailure, stepFailures, } from "./stream-tenant-derived-state.ts";
|
|
34
39
|
export type { SystemQueryFn } from "./system-query.ts";
|
|
40
|
+
export { createTenantDbCache } from "./tenant-db-cache.ts";
|
|
35
41
|
export { type BurnResult, burnToken, unburnToken } from "./token-burn-store.ts";
|
package/dist/shared/index.js
CHANGED
|
@@ -3,13 +3,17 @@ export { assertNoWhereRuleInOwnershipWrite } from "./assert-no-where-rule-in-own
|
|
|
3
3
|
export { attachmentFileNameSchema, sanitizePdfAttachmentFileName, } from "./attachment-file-name.js";
|
|
4
4
|
export { runChunkedMigration, } from "./chunked-entity-migration.js";
|
|
5
5
|
export { classifyStoredEnvelope, } from "./classify-stored-envelope.js";
|
|
6
|
+
export { collectExtensionOptions } from "./collect-extension-options.js";
|
|
6
7
|
export { decryptStoredPii, decryptStoredUserEmail } from "./decrypt-stored-pii.js";
|
|
7
8
|
export { encryptForDirectWrite } from "./encrypt-for-direct-write.js";
|
|
8
9
|
export { entitiesOf } from "./entities-of.js";
|
|
9
10
|
export { isWithinGracePeriod } from "./grace-period.js";
|
|
11
|
+
export { hmacSignatureMatches, signHmacSha256Base64Url } from "./hmac-signature.js";
|
|
10
12
|
export { isIdentityV3Hash, verifyIdentityV3Hash } from "./identity-v3-hash.js";
|
|
11
13
|
export { isTenantDb } from "./is-tenant-db.js";
|
|
14
|
+
export { isUniqueConstraintFailure } from "./is-unique-constraint-failure.js";
|
|
12
15
|
export { createLockoutCounter } from "./lockout-counter.js";
|
|
16
|
+
export { createMailLocaleTemplates } from "./mail-locale-templates.js";
|
|
13
17
|
export { mailHeading, mailParagraph, mailParagraphWithLink, mailRepeatedRows, } from "./mail-template-body.js";
|
|
14
18
|
export { mapWithConcurrency } from "./map-with-concurrency.js";
|
|
15
19
|
export { denyUnlessJoinRowParentVisible, hostRowIsGone, joinRowParentIsVisible, parentRowIsVisible, } from "./parent-visibility.js";
|
|
@@ -20,6 +24,7 @@ export { rateLimitedTextResponse } from "./rate-limited-text-response.js";
|
|
|
20
24
|
export { redactBotTokens, redactEmailAddresses, redactErrorText, redactUrls, } from "./redact.js";
|
|
21
25
|
export { REDACTED_PII_PLACEHOLDER, redactPiiCiphertext } from "./redact-pii-ciphertext.js";
|
|
22
26
|
export { requireForTenant } from "./require-for-tenant.js";
|
|
27
|
+
export { resolveFeatureAccess } from "./resolve-feature-access.js";
|
|
23
28
|
export { extensionForResourceContentType, isResourceImageContentType, isResourceImageFormat, RESOURCE_IMAGE_FORMATS, } from "./resource-image-formats.js";
|
|
24
29
|
export { redeemRowBoundGrant, signRowBoundGrant, } from "./row-bound-grant.js";
|
|
25
30
|
export { runInSubTransaction } from "./run-in-sub-transaction.js";
|
|
@@ -31,4 +36,5 @@ export { EXT_SIGNUP_HANDOVER, findSignupHandoverProvider, isSignupHandoverProvid
|
|
|
31
36
|
export { createSingleUseTokenStore, hashSingleUseToken } from "./single-use-token-store.js";
|
|
32
37
|
export { backfillAggregateStreamTenants, } from "./stream-tenant-backfill.js";
|
|
33
38
|
export { createSearchBucketCleanup, rebuildAndReindex, stepFailures, } from "./stream-tenant-derived-state.js";
|
|
39
|
+
export { createTenantDbCache } from "./tenant-db-cache.js";
|
|
34
40
|
export { burnToken, unburnToken } from "./token-burn-store.js";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { propertyOf } from "@cosmicdrift/kumiko-types/type-guards";
|
|
2
|
+
// The executor reports a unique-index race as a WriteFailure(unique_violation)
|
|
3
|
+
// whose details name the violated constraint.
|
|
4
|
+
export function isUniqueConstraintFailure(failure, constraint) {
|
|
5
|
+
return (propertyOf(failure.error, "code") === "unique_violation" &&
|
|
6
|
+
propertyOf(propertyOf(failure.error, "details"), "constraintName") === constraint);
|
|
7
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { NotificationLocalizedTemplate } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
type MailLocaleTemplateConfig<Kind extends string> = {
|
|
3
|
+
readonly kinds: readonly Kind[];
|
|
4
|
+
readonly notificationTypes: Readonly<Record<Kind, string>>;
|
|
5
|
+
readonly subjectKey: (kind: Kind) => string;
|
|
6
|
+
readonly bodyFor: (kind: Kind, locale: string) => string;
|
|
7
|
+
};
|
|
8
|
+
export declare function createMailLocaleTemplates<Kind extends string>(config: MailLocaleTemplateConfig<Kind>): {
|
|
9
|
+
templateLocale: (notificationType: string, requestedLocale: string) => string;
|
|
10
|
+
localizedTemplate: (kind: Kind) => () => NotificationLocalizedTemplate;
|
|
11
|
+
};
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { hasMailTranslationKey, listMailLocales, mailT, resolveMailLocale, } from "@cosmicdrift/kumiko-framework/i18n";
|
|
2
|
+
export function createMailLocaleTemplates(config) {
|
|
3
|
+
const subjectKeyByType = new Map(config.kinds.map((kind) => [config.notificationTypes[kind], config.subjectKey(kind)]));
|
|
4
|
+
// A registered locale whose bundle lacks the subject key has no template (see
|
|
5
|
+
// localizedTemplate); the renderer has no locale fallback, so the sender must
|
|
6
|
+
// pick a locale that has one or the mail would not go out at all.
|
|
7
|
+
const templateLocale = (notificationType, requestedLocale) => {
|
|
8
|
+
const locale = resolveMailLocale(requestedLocale);
|
|
9
|
+
const key = subjectKeyByType.get(notificationType);
|
|
10
|
+
return key !== undefined && hasMailTranslationKey(locale, key) ? locale : "en";
|
|
11
|
+
};
|
|
12
|
+
// Evaluated when the registry is built, after every locale feature has
|
|
13
|
+
// registered its mail translations. English always ships; another locale only
|
|
14
|
+
// gets a template when it has its own subject, so a missing translation never
|
|
15
|
+
// silently becomes an English mail in that locale's slot.
|
|
16
|
+
const localizedTemplate = (kind) => {
|
|
17
|
+
const kindSubjectKey = config.subjectKey(kind);
|
|
18
|
+
return () => {
|
|
19
|
+
const locales = [
|
|
20
|
+
"en",
|
|
21
|
+
...listMailLocales().filter((locale) => locale !== "en" && hasMailTranslationKey(locale, kindSubjectKey)),
|
|
22
|
+
];
|
|
23
|
+
return Object.fromEntries(locales.map((locale) => [
|
|
24
|
+
locale,
|
|
25
|
+
{
|
|
26
|
+
body: config.bodyFor(kind, locale),
|
|
27
|
+
meta: {
|
|
28
|
+
subject: mailT(locale, kindSubjectKey, { app: "{{appName}}" }),
|
|
29
|
+
category: "transactional",
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
]));
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
return { templateLocale, localizedTemplate };
|
|
36
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AccessRule } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
type FeatureAccessOptions = {
|
|
3
|
+
readonly access?: AccessRule;
|
|
4
|
+
readonly roles?: readonly string[];
|
|
5
|
+
};
|
|
6
|
+
export declare function resolveFeatureAccess(opts: FeatureAccessOptions, defaultAccess: AccessRule): AccessRule;
|
|
7
|
+
export {};
|