@cosmicdrift/kumiko-bundled-features 0.411.0 → 0.413.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/admin-shell/feature.d.ts +1 -1
- package/dist/agent-tools/agent-doc-lint.d.ts +9 -0
- package/dist/agent-tools/agent-doc-lint.js +42 -5
- package/dist/agent-tools/agent-manifest.d.ts +0 -1
- package/dist/agent-tools/agent-manifest.js +9 -99
- package/dist/agent-tools/api-docs/anchors.d.ts +14 -0
- package/dist/agent-tools/api-docs/anchors.js +49 -0
- package/dist/agent-tools/api-docs/check.d.ts +7 -0
- package/dist/agent-tools/api-docs/check.js +15 -0
- package/dist/agent-tools/api-docs/collect-events.d.ts +10 -0
- package/dist/agent-tools/api-docs/collect-events.js +90 -0
- package/dist/agent-tools/api-docs/collect.d.ts +15 -0
- package/dist/agent-tools/api-docs/collect.js +108 -0
- package/dist/agent-tools/api-docs/curl.d.ts +5 -0
- package/dist/agent-tools/api-docs/curl.js +24 -0
- package/dist/agent-tools/api-docs/error-table.d.ts +9 -0
- package/dist/agent-tools/api-docs/error-table.js +31 -0
- package/dist/agent-tools/api-docs/examples.d.ts +16 -0
- package/dist/agent-tools/api-docs/examples.js +25 -0
- package/dist/agent-tools/api-docs/generate.d.ts +19 -0
- package/dist/agent-tools/api-docs/generate.js +104 -0
- package/dist/agent-tools/api-docs/index-json.d.ts +15 -0
- package/dist/agent-tools/api-docs/index-json.js +6 -0
- package/dist/agent-tools/api-docs/index.d.ts +9 -0
- package/dist/agent-tools/api-docs/index.js +6 -0
- package/dist/agent-tools/api-docs/list-parameters.d.ts +61 -0
- package/dist/agent-tools/api-docs/list-parameters.js +28 -0
- package/dist/agent-tools/api-docs/markdown.d.ts +29 -0
- package/dist/agent-tools/api-docs/markdown.js +48 -0
- package/dist/agent-tools/api-docs/menu-path.d.ts +8 -0
- package/dist/agent-tools/api-docs/menu-path.js +60 -0
- package/dist/agent-tools/api-docs/model.d.ts +76 -0
- package/dist/agent-tools/api-docs/problems.d.ts +32 -0
- package/dist/agent-tools/api-docs/problems.js +28 -0
- package/dist/agent-tools/api-docs/render-events.d.ts +12 -0
- package/dist/agent-tools/api-docs/render-events.js +55 -0
- package/dist/agent-tools/api-docs/render-openapi.d.ts +10 -0
- package/dist/agent-tools/api-docs/render-openapi.js +170 -0
- package/dist/agent-tools/api-docs/render-overview.d.ts +11 -0
- package/dist/agent-tools/api-docs/render-overview.js +60 -0
- package/dist/agent-tools/api-docs/render-reference.d.ts +14 -0
- package/dist/agent-tools/api-docs/render-reference.js +50 -0
- package/dist/agent-tools/api-docs/render-tokens.d.ts +12 -0
- package/dist/agent-tools/api-docs/render-tokens.js +101 -0
- package/dist/agent-tools/api-docs/schema-fields.d.ts +16 -0
- package/dist/agent-tools/api-docs/schema-fields.js +141 -0
- package/dist/agent-tools/api-docs/section-ids.d.ts +25 -0
- package/dist/agent-tools/api-docs/section-ids.js +26 -0
- package/dist/agent-tools/api-docs/system-only.d.ts +5 -0
- package/dist/agent-tools/api-docs/system-only.js +7 -0
- package/dist/agent-tools/api-docs/texts/de.d.ts +123 -0
- package/dist/agent-tools/api-docs/texts/de.js +123 -0
- package/dist/agent-tools/api-docs/texts/en.d.ts +123 -0
- package/dist/agent-tools/api-docs/texts/en.js +123 -0
- package/dist/agent-tools/api-docs/texts/es.d.ts +123 -0
- package/dist/agent-tools/api-docs/texts/es.js +123 -0
- package/dist/agent-tools/api-docs/texts/fr.d.ts +123 -0
- package/dist/agent-tools/api-docs/texts/fr.js +123 -0
- package/dist/agent-tools/api-docs/texts/index.d.ts +14 -0
- package/dist/agent-tools/api-docs/texts/index.js +55 -0
- package/dist/agent-tools/api-docs/texts/it.d.ts +123 -0
- package/dist/agent-tools/api-docs/texts/it.js +123 -0
- package/dist/agent-tools/api-docs/texts/types.d.ts +18 -0
- package/dist/agent-tools/api-docs/texts/types.js +104 -0
- package/dist/agent-tools/api-docs/ui-writes.d.ts +12 -0
- package/dist/agent-tools/api-docs/ui-writes.js +73 -0
- package/dist/agent-tools/handler-schema.d.ts +5 -0
- package/dist/agent-tools/handler-schema.js +37 -0
- package/dist/agent-tools/index.d.ts +2 -1
- package/dist/agent-tools/index.js +2 -1
- package/dist/agent-tools/labels.d.ts +26 -0
- package/dist/agent-tools/labels.js +131 -0
- package/dist/auth-email-password/boot-rules.d.ts +7 -0
- package/dist/auth-email-password/boot-rules.js +7 -0
- package/dist/auth-email-password/feature.js +6 -13
- package/dist/auth-email-password/validate-options.d.ts +5 -0
- package/dist/auth-email-password/validate-options.js +15 -0
- package/dist/billing-foundation/boot-rules.d.ts +22 -0
- package/dist/billing-foundation/boot-rules.js +22 -0
- package/dist/billing-foundation/validate-options.js +56 -18
- package/dist/cap-overview/boot-rules.d.ts +12 -0
- package/dist/cap-overview/boot-rules.js +12 -0
- package/dist/cap-overview/feature.js +8 -3
- package/dist/documents/boot-rules.d.ts +12 -0
- package/dist/documents/boot-rules.js +12 -0
- package/dist/documents/feature.js +8 -3
- package/dist/file-derivatives/boot-rules.d.ts +7 -0
- package/dist/file-derivatives/boot-rules.js +7 -0
- package/dist/file-derivatives/feature.js +5 -2
- package/dist/folders/boot-rules.d.ts +7 -0
- package/dist/folders/boot-rules.js +7 -0
- package/dist/folders/feature.js +8 -5
- package/dist/helpdesk/boot-rules.d.ts +7 -0
- package/dist/helpdesk/boot-rules.js +7 -0
- package/dist/{contact → helpdesk}/challenge.js +2 -2
- package/dist/helpdesk/client/helpdesk-client-source.d.ts +1 -0
- package/dist/{contact/client/contact-client-source.js → helpdesk/client/helpdesk-client-source.js} +4 -4
- package/dist/helpdesk/client/helpdesk-website-client.d.ts +26 -0
- package/dist/helpdesk/client/helpdesk-website-client.js +1 -0
- package/dist/helpdesk/client/index.d.ts +2 -0
- package/dist/helpdesk/client/index.js +1 -0
- package/dist/{contact → helpdesk}/entity.d.ts +6 -6
- package/dist/{contact → helpdesk}/entity.js +31 -27
- package/dist/helpdesk/feature.d.ts +3 -0
- package/dist/{contact → helpdesk}/feature.js +43 -39
- package/dist/{contact → helpdesk}/handlers/attempts.d.ts +2 -2
- package/dist/helpdesk/handlers/challenge.query.d.ts +9 -0
- package/dist/{contact → helpdesk}/handlers/challenge.query.js +5 -5
- package/dist/helpdesk/handlers/forward-request.write.d.ts +9 -0
- package/dist/{contact → helpdesk}/handlers/forward-request.write.js +17 -15
- package/dist/{contact → helpdesk}/handlers/mark-done.write.d.ts +2 -2
- package/dist/{contact → helpdesk}/handlers/mark-done.write.js +8 -8
- package/dist/{contact → helpdesk}/handlers/notify-reporter-in-app.write.d.ts +2 -2
- package/dist/{contact → helpdesk}/handlers/notify-reporter-in-app.write.js +11 -11
- package/dist/{contact → helpdesk}/handlers/open-count.js +2 -2
- package/dist/{contact → helpdesk}/handlers/open-count.query.js +4 -4
- package/dist/{contact → helpdesk}/handlers/replies.query.js +6 -6
- package/dist/{contact → helpdesk}/handlers/reply.write.d.ts +4 -4
- package/dist/{contact → helpdesk}/handlers/reply.write.js +16 -16
- package/dist/helpdesk/handlers/report.write.d.ts +16 -0
- package/dist/{contact → helpdesk}/handlers/report.write.js +17 -17
- package/dist/helpdesk/handlers/request-delivery.query.d.ts +16 -0
- package/dist/{contact → helpdesk}/handlers/request-delivery.query.js +24 -24
- package/dist/{contact → helpdesk}/handlers/request-detail.query.d.ts +3 -3
- package/dist/{contact → helpdesk}/handlers/request-detail.query.js +10 -10
- package/dist/{contact → helpdesk}/handlers/request-list.query.js +2 -2
- package/dist/helpdesk/handlers/send-reply-mail.write.d.ts +8 -0
- package/dist/{contact → helpdesk}/handlers/send-reply-mail.write.js +15 -15
- package/dist/helpdesk/handlers/send-test.write.d.ts +5 -0
- package/dist/{contact → helpdesk}/handlers/send-test.write.js +10 -10
- package/dist/{contact → helpdesk}/handlers/submit.write.d.ts +4 -4
- package/dist/{contact → helpdesk}/handlers/submit.write.js +17 -17
- package/dist/{contact → helpdesk}/handlers/take-over-uploads.js +5 -5
- package/dist/{contact → helpdesk}/i18n.d.ts +1 -1
- package/dist/{contact → helpdesk}/i18n.js +78 -75
- package/dist/helpdesk/index.d.ts +5 -0
- package/dist/helpdesk/index.js +4 -0
- package/dist/{contact → helpdesk}/lib.d.ts +5 -5
- package/dist/{contact → helpdesk}/lib.js +16 -16
- package/dist/{contact → helpdesk}/mail.d.ts +20 -20
- package/dist/{contact → helpdesk}/mail.js +47 -47
- package/dist/{contact → helpdesk}/options.d.ts +6 -6
- package/dist/helpdesk/options.js +36 -0
- package/dist/helpdesk/panels.d.ts +2 -0
- package/dist/helpdesk/panels.js +21 -0
- package/dist/{contact → helpdesk}/payloads.d.ts +11 -11
- package/dist/{contact → helpdesk}/payloads.js +28 -28
- package/dist/helpdesk/screens.d.ts +5 -0
- package/dist/{contact → helpdesk}/screens.js +87 -87
- package/dist/{contact → helpdesk}/subject.js +3 -3
- package/dist/helpdesk/user-data-hooks.d.ts +3 -0
- package/dist/{contact → helpdesk}/user-data-hooks.js +15 -15
- package/dist/helpdesk/web/constants.d.ts +127 -0
- package/dist/helpdesk/web/constants.js +126 -0
- package/dist/helpdesk/web/index.d.ts +1 -0
- package/dist/helpdesk/web/index.js +1 -0
- package/dist/host-routing/boot-rules.d.ts +22 -0
- package/dist/host-routing/boot-rules.js +22 -0
- package/dist/host-routing/validate-options.js +35 -11
- package/dist/inbound-mail-foundation/entities.d.ts +84 -0
- package/dist/inbound-mail-foundation/entities.js +96 -71
- package/dist/inbound-mail-foundation/feature.js +2 -2
- package/dist/jobs/boot-rules.d.ts +7 -0
- package/dist/jobs/boot-rules.js +7 -0
- package/dist/jobs/feature.js +5 -2
- package/dist/legal-pages/boot-rules.d.ts +17 -0
- package/dist/legal-pages/boot-rules.js +17 -0
- package/dist/legal-pages/feature.js +5 -2
- package/dist/legal-pages/lib/validate-routes.js +11 -3
- package/dist/metrics/boot-rules.d.ts +12 -0
- package/dist/metrics/boot-rules.js +12 -0
- package/dist/metrics/validate.js +8 -2
- package/dist/notes-history/boot-rules.d.ts +7 -0
- package/dist/notes-history/boot-rules.js +7 -0
- package/dist/notes-history/feature.js +7 -4
- package/dist/personal-access-tokens/boot-rules.d.ts +7 -0
- package/dist/personal-access-tokens/boot-rules.js +7 -0
- package/dist/personal-access-tokens/feature.d.ts +1 -0
- package/dist/personal-access-tokens/feature.js +4 -2
- package/dist/personal-access-tokens/handlers/create.write.js +2 -2
- package/dist/personal-access-tokens/i18n.js +5 -1
- package/dist/personal-access-tokens/index.d.ts +4 -2
- package/dist/personal-access-tokens/index.js +29 -2
- package/dist/personal-access-tokens/scope-events-check.d.ts +3 -0
- package/dist/personal-access-tokens/scope-events-check.js +21 -0
- package/dist/personal-access-tokens/screens.js +8 -2
- package/dist/personal-access-tokens/web/constants.d.ts +1 -0
- package/dist/personal-access-tokens/web/constants.js +1 -0
- package/dist/personal-access-tokens/web/scopes.d.ts +2 -0
- package/dist/personal-access-tokens/web/scopes.js +12 -0
- package/dist/presence/boot-rules.d.ts +7 -0
- package/dist/presence/boot-rules.js +7 -0
- package/dist/presence/options.js +5 -1
- package/dist/readiness/boot-rules.d.ts +12 -0
- package/dist/readiness/boot-rules.js +12 -0
- package/dist/readiness/probe-boot-check.js +8 -3
- package/dist/shared/assert-no-where-rule-in-ownership-write.d.ts +1 -1
- package/dist/shared/assert-no-where-rule-in-ownership-write.js +11 -7
- package/dist/shared/boot-rules.d.ts +7 -0
- package/dist/shared/boot-rules.js +7 -0
- package/dist/subscription-mollie/boot-rules.d.ts +17 -0
- package/dist/subscription-mollie/boot-rules.js +17 -0
- package/dist/subscription-mollie/feature.js +13 -6
- package/dist/tags/boot-rules.d.ts +7 -0
- package/dist/tags/boot-rules.js +7 -0
- package/dist/tags/feature.js +8 -5
- package/dist/template-resolver/boot-rules.d.ts +17 -0
- package/dist/template-resolver/boot-rules.js +17 -0
- package/dist/template-resolver/feature.js +14 -5
- package/dist/tenant/boot-rules.d.ts +7 -0
- package/dist/tenant/boot-rules.js +7 -0
- package/dist/tenant/feature.js +5 -2
- package/kumiko-es-tables.json +4 -4
- package/package.json +29 -29
- package/src/agent-tools/changes.json +24 -0
- package/src/{contact → helpdesk}/changes.json +6 -0
- package/src/inbound-mail-foundation/changes.json +6 -0
- package/src/personal-access-tokens/changes.json +6 -0
- package/dist/contact/client/contact-client-source.d.ts +0 -1
- package/dist/contact/client/contact-website-client.d.ts +0 -26
- package/dist/contact/client/index.d.ts +0 -2
- package/dist/contact/client/index.js +0 -1
- package/dist/contact/feature.d.ts +0 -3
- package/dist/contact/handlers/challenge.query.d.ts +0 -9
- package/dist/contact/handlers/forward-request.write.d.ts +0 -9
- package/dist/contact/handlers/report.write.d.ts +0 -16
- package/dist/contact/handlers/request-delivery.query.d.ts +0 -16
- package/dist/contact/handlers/send-reply-mail.write.d.ts +0 -8
- package/dist/contact/handlers/send-test.write.d.ts +0 -5
- package/dist/contact/index.d.ts +0 -5
- package/dist/contact/index.js +0 -4
- package/dist/contact/options.js +0 -32
- package/dist/contact/panels.d.ts +0 -2
- package/dist/contact/panels.js +0 -21
- package/dist/contact/screens.d.ts +0 -5
- package/dist/contact/user-data-hooks.d.ts +0 -3
- package/dist/contact/web/constants.d.ts +0 -127
- package/dist/contact/web/constants.js +0 -126
- package/dist/contact/web/index.d.ts +0 -1
- package/dist/contact/web/index.js +0 -1
- /package/dist/{contact/client/contact-website-client.js → agent-tools/api-docs/model.js} +0 -0
- /package/dist/{contact → helpdesk}/challenge.d.ts +0 -0
- /package/dist/{contact → helpdesk}/handlers/access.d.ts +0 -0
- /package/dist/{contact → helpdesk}/handlers/access.js +0 -0
- /package/dist/{contact → helpdesk}/handlers/attempts.js +0 -0
- /package/dist/{contact → helpdesk}/handlers/open-count.d.ts +0 -0
- /package/dist/{contact → helpdesk}/handlers/open-count.query.d.ts +0 -0
- /package/dist/{contact → helpdesk}/handlers/replies.query.d.ts +0 -0
- /package/dist/{contact → helpdesk}/handlers/request-list.query.d.ts +0 -0
- /package/dist/{contact → helpdesk}/handlers/take-over-uploads.d.ts +0 -0
- /package/dist/{contact → helpdesk}/pow.d.ts +0 -0
- /package/dist/{contact → helpdesk}/pow.js +0 -0
- /package/dist/{contact → helpdesk}/subject.d.ts +0 -0
- /package/dist/{contact → helpdesk}/user-agent.d.ts +0 -0
- /package/dist/{contact → helpdesk}/user-agent.js +0 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { collectPiiSubjectFields } from "@cosmicdrift/kumiko-framework/crypto";
|
|
2
|
-
import { deriveEntityTableMeta } from "@cosmicdrift/kumiko-framework/db";
|
|
2
|
+
import { deriveEntityTableMeta, physicalColumnName } from "@cosmicdrift/kumiko-framework/db";
|
|
3
3
|
import { access, createBooleanField, createEntity, createFilesField, createLongTextField, createNumberField, createTextField, createTimestampField, } from "@cosmicdrift/kumiko-framework/engine";
|
|
4
|
+
import { DEFAULT_INBOUND_MAIL_ADMIN_ROLES, DEFAULT_INBOUND_MAIL_USER_ROLES } from "./mail-roles.js";
|
|
4
5
|
// ============================================================================
|
|
5
6
|
// Read models for the three event-sourced aggregates
|
|
6
7
|
// ============================================================================
|
|
@@ -68,79 +69,103 @@ export const mailAccountEntity = createEntity({
|
|
|
68
69
|
connectedAt: createTimestampField({ required: true }),
|
|
69
70
|
},
|
|
70
71
|
});
|
|
72
|
+
// Mirrors isVisibleToCaller (handlers/scope-visibility.ts) for the roles of the detail query:
|
|
73
|
+
// shared rows and the caller's own personal mailbox, no admin exception. The read gate of other
|
|
74
|
+
// entities (readGate.fileOwner) reads it; the hand-written message queries do not apply it.
|
|
75
|
+
function ownMailboxOrSharedRead(memberRoles) {
|
|
76
|
+
const rule = {
|
|
77
|
+
kind: "where",
|
|
78
|
+
where: (user, ctx) => {
|
|
79
|
+
const owner = `"${ctx.tableName}"."${physicalColumnName(ctx.table, "ownerUserId")}"`;
|
|
80
|
+
return {
|
|
81
|
+
sqlText: `(${owner} IS NULL OR ${owner} = '' OR ${owner} = $${ctx.paramStart})`,
|
|
82
|
+
params: [user.id],
|
|
83
|
+
};
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
return Object.fromEntries(memberRoles.map((role) => [role, rule]));
|
|
87
|
+
}
|
|
71
88
|
/** An incoming mail (envelope + snippet, NO body — bodyRef
|
|
72
89
|
* points to file-foundation). PK = aggregateId =
|
|
73
90
|
* inboundMessageAggregateId(accountId, providerMessageId). */
|
|
74
|
-
export
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
91
|
+
export function createInboundMessageEntity(memberRoles) {
|
|
92
|
+
return createEntity({
|
|
93
|
+
access: { read: ownMailboxOrSharedRead(memberRoles) },
|
|
94
|
+
table: "read_inbound_messages",
|
|
95
|
+
fields: {
|
|
96
|
+
accountId: createTextField({
|
|
97
|
+
required: true,
|
|
98
|
+
maxLength: 36,
|
|
99
|
+
personal: false,
|
|
100
|
+
reason: "technical_reference",
|
|
101
|
+
}),
|
|
102
|
+
// Scope is inherited from the account at ingest time: messages from a
|
|
103
|
+
// personal mailbox are visible only to the owner, without joining read_mail_accounts.
|
|
104
|
+
ownerUserId: createTextField({ maxLength: 36, personal: false, reason: "pseudonymous_fk" }),
|
|
105
|
+
messageIdHeader: createTextField({
|
|
106
|
+
required: true,
|
|
107
|
+
maxLength: 500,
|
|
108
|
+
personal: false,
|
|
109
|
+
reason: "technical_reference",
|
|
110
|
+
}),
|
|
111
|
+
threadKey: createTextField({
|
|
112
|
+
required: true,
|
|
113
|
+
maxLength: 500,
|
|
114
|
+
personal: false,
|
|
115
|
+
reason: "technical_reference",
|
|
116
|
+
}),
|
|
117
|
+
from: createTextField({ required: true, maxLength: 2000, personal: "tenant", find: "none" }),
|
|
118
|
+
// JSON-stringified string[] — als Ganzes encrypted.
|
|
119
|
+
to: createTextField({ maxLength: 8000, personal: "tenant", find: "none" }),
|
|
120
|
+
cc: createTextField({ maxLength: 8000, personal: "tenant", find: "none" }),
|
|
121
|
+
subject: createTextField({ maxLength: 4000, personal: "tenant", find: "none" }),
|
|
122
|
+
snippet: createTextField({ maxLength: 4000, personal: "tenant", find: "none" }),
|
|
123
|
+
receivedAt: createTimestampField({ required: true }),
|
|
124
|
+
bodyRef: createTextField({ maxLength: 500, personal: false, reason: "technical_reference" }),
|
|
125
|
+
scope: createTextField({ maxLength: 200, personal: false, reason: "technical_reference" }),
|
|
126
|
+
// Full plaintext, capped at 32_000 characters before encryption (ciphertext is ~2.3x plus envelope).
|
|
127
|
+
// Null on rows from before the column; list-messages never selects it.
|
|
128
|
+
bodyText: createLongTextField({ maxLength: 200_000, personal: "tenant", find: "none" }),
|
|
129
|
+
bodyTextTruncated: createBooleanField(),
|
|
130
|
+
// Sanitized HTML of the mail (sanitizeInboundHtml), null when the mail has none or it was too large.
|
|
131
|
+
bodyHtml: createLongTextField({ maxLength: 500_000, personal: "tenant", find: "none" }),
|
|
132
|
+
// Bound to the message (entityType = the aggregate type), so the file guard answers with the
|
|
133
|
+
// mail's visibility. The fileRefs are bound at ingest, the projection copies the ids.
|
|
134
|
+
attachmentFileIds: createFilesField({ personal: false, reason: "technical_reference" }),
|
|
135
|
+
// JSON-stringified SkippedInboundAttachment[]: nullable JSON stays a text column
|
|
136
|
+
// (jsonb fields are NOT NULL), like to/cc.
|
|
137
|
+
skippedAttachments: createTextField({
|
|
138
|
+
maxLength: 20_000,
|
|
139
|
+
personal: false,
|
|
140
|
+
reason: "technical_reference",
|
|
141
|
+
}),
|
|
142
|
+
// JSON-stringified SenderAuthentication or "null"; a SQL null (rows from before the column) reads as null.
|
|
143
|
+
senderAuthentication: createTextField({
|
|
144
|
+
maxLength: 4000,
|
|
145
|
+
personal: false,
|
|
146
|
+
reason: "technical_reference",
|
|
147
|
+
}),
|
|
148
|
+
// "complete" | "snippet" | "unavailable"; null counts as "snippet".
|
|
149
|
+
contentState: createTextField({
|
|
150
|
+
maxLength: 20,
|
|
151
|
+
personal: false,
|
|
152
|
+
reason: "technical_reference",
|
|
153
|
+
}),
|
|
154
|
+
// One of INBOUND_CONTENT_UNAVAILABLE_REASONS; null while the content is there or not yet missing.
|
|
155
|
+
contentUnavailableReason: createTextField({
|
|
156
|
+
maxLength: 30,
|
|
157
|
+
personal: false,
|
|
158
|
+
reason: "technical_reference",
|
|
159
|
+
}),
|
|
160
|
+
},
|
|
161
|
+
attachedFileAccess: "record-only",
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
// Same fields for every role set; table and PII lists do not depend on the roles.
|
|
165
|
+
export const inboundMessageEntity = createInboundMessageEntity([
|
|
166
|
+
...DEFAULT_INBOUND_MAIL_ADMIN_ROLES,
|
|
167
|
+
...DEFAULT_INBOUND_MAIL_USER_ROLES,
|
|
168
|
+
]);
|
|
144
169
|
/** Thread-Rollup. PK = aggregateId = mailThreadAggregateId(tenantId,
|
|
145
170
|
* threadKey). */
|
|
146
171
|
export const mailThreadEntity = createEntity({
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
// archives all streams and deletes the rows.
|
|
23
23
|
import { defineFeature, EXT_TENANT_DATA } from "@cosmicdrift/kumiko-framework/engine";
|
|
24
24
|
import { INBOUND_MAIL_FOUNDATION_FEATURE, INBOUND_MAIL_PROVIDER_EXTENSION } from "./constants.js";
|
|
25
|
-
import {
|
|
25
|
+
import { createInboundMessageEntity, mailAccountEntity, mailThreadEntity, seenMessageTable, syncCursorTable, } from "./entities.js";
|
|
26
26
|
import { INBOUND_MESSAGE_AGGREGATE_TYPE, INBOUND_MESSAGE_CONTENT_FETCHED_EVENT_QN, INBOUND_MESSAGE_CONTENT_FETCHED_EVENT_SHORT, INBOUND_MESSAGE_RECEIVED_EVENT_QN, INBOUND_MESSAGE_RECEIVED_EVENT_SHORT, inboundMessageContentFetchedEventPayloadSchema, inboundMessageEventPayloadSchema, MAIL_ACCOUNT_AGGREGATE_TYPE, MAIL_ACCOUNT_CONNECTED_EVENT_QN, MAIL_ACCOUNT_CONNECTED_EVENT_SHORT, MAIL_ACCOUNT_DISCONNECTED_EVENT_QN, MAIL_ACCOUNT_DISCONNECTED_EVENT_SHORT, MAIL_ACCOUNT_UPDATED_EVENT_QN, MAIL_ACCOUNT_UPDATED_EVENT_SHORT, MAIL_THREAD_AGGREGATE_TYPE, MAIL_THREAD_UPDATED_EVENT_QN, MAIL_THREAD_UPDATED_EVENT_SHORT, mailAccountEventPayloadSchema, mailThreadEventPayloadSchema, } from "./events.js";
|
|
27
27
|
import { createAcknowledgeQuarantineHandler } from "./handlers/acknowledge-quarantine.write.js";
|
|
28
28
|
import { attachMessageContentHandler } from "./handlers/attach-message-content.write.js";
|
|
@@ -151,7 +151,7 @@ export function createInboundMailFoundationFeature(options = {}) {
|
|
|
151
151
|
name: "inbound-message",
|
|
152
152
|
source: INBOUND_MESSAGE_AGGREGATE_TYPE,
|
|
153
153
|
table: inboundMessagesProjectionTable,
|
|
154
|
-
entity:
|
|
154
|
+
entity: createInboundMessageEntity(roles.memberRoles),
|
|
155
155
|
apply: {
|
|
156
156
|
[INBOUND_MESSAGE_RECEIVED_EVENT_QN]: applyInboundMessageReceived,
|
|
157
157
|
[INBOUND_MESSAGE_CONTENT_FETCHED_EVENT_QN]: applyInboundMessageContentFetched,
|
package/dist/jobs/feature.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { defineFeature } from "@cosmicdrift/kumiko-framework/engine";
|
|
1
|
+
import { bootRuleError, defineFeature, } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
import { JOBS_BOOT_RULES } from "./boot-rules.js";
|
|
2
3
|
import { catalogQuery } from "./handlers/catalog.query.js";
|
|
3
4
|
import { consumerDisableWrite, consumerEnableWrite, consumerRestartWrite, consumerSkipWrite, } from "./handlers/consumer.write.js";
|
|
4
5
|
import { consumerDetailQuery, consumersQuery } from "./handlers/consumers.query.js";
|
|
@@ -22,7 +23,9 @@ export function createJobsFeature(options = {}) {
|
|
|
22
23
|
const staleRunTimeoutHours = options.staleRunTimeoutHours ?? DEFAULT_JOB_RUN_STALE_TIMEOUT_HOURS;
|
|
23
24
|
const readRoles = options.readRoles ?? [];
|
|
24
25
|
if (readRoles.includes("anonymous")) {
|
|
25
|
-
throw
|
|
26
|
+
throw bootRuleError(JOBS_BOOT_RULES.anonymousReadRole, {
|
|
27
|
+
message: `createJobsFeature: readRoles must not contain "anonymous" — job status and failures are only readable by members of the tenant.`,
|
|
28
|
+
});
|
|
26
29
|
}
|
|
27
30
|
return defineFeature("jobs", (r) => {
|
|
28
31
|
r.adoptsBundledLists();
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare const LEGAL_PAGES_BOOT_RULES: {
|
|
2
|
+
readonly invalidRoute: {
|
|
3
|
+
readonly id: "legal-pages/invalid-route";
|
|
4
|
+
readonly summary: "Legal page routes declare path, slug and lang, and the path starts with a slash.";
|
|
5
|
+
readonly fix: "Fix the route named in the error message.";
|
|
6
|
+
};
|
|
7
|
+
readonly duplicateRoutePath: {
|
|
8
|
+
readonly id: "legal-pages/duplicate-route-path";
|
|
9
|
+
readonly summary: "Legal page route paths are unique.";
|
|
10
|
+
readonly fix: "Remove or rename the duplicate route.";
|
|
11
|
+
};
|
|
12
|
+
readonly routesWithoutRequiredBlocks: {
|
|
13
|
+
readonly id: "legal-pages/routes-without-required-blocks";
|
|
14
|
+
readonly summary: "Custom routes that miss the default required blocks pass requiredBlocks explicitly.";
|
|
15
|
+
readonly fix: "Pass requiredBlocks (or an empty array) alongside custom routes.";
|
|
16
|
+
};
|
|
17
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export const LEGAL_PAGES_BOOT_RULES = {
|
|
2
|
+
invalidRoute: {
|
|
3
|
+
id: "legal-pages/invalid-route",
|
|
4
|
+
summary: "Legal page routes declare path, slug and lang, and the path starts with a slash.",
|
|
5
|
+
fix: "Fix the route named in the error message.",
|
|
6
|
+
},
|
|
7
|
+
duplicateRoutePath: {
|
|
8
|
+
id: "legal-pages/duplicate-route-path",
|
|
9
|
+
summary: "Legal page route paths are unique.",
|
|
10
|
+
fix: "Remove or rename the duplicate route.",
|
|
11
|
+
},
|
|
12
|
+
routesWithoutRequiredBlocks: {
|
|
13
|
+
id: "legal-pages/routes-without-required-blocks",
|
|
14
|
+
summary: "Custom routes that miss the default required blocks pass requiredBlocks explicitly.",
|
|
15
|
+
fix: "Pass requiredBlocks (or an empty array) alongside custom routes.",
|
|
16
|
+
},
|
|
17
|
+
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { computeRevisionEtag, etagMatches } from "@cosmicdrift/kumiko-framework/api";
|
|
2
|
-
import { defineFeature, SYSTEM_TENANT_ID, } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
import { bootRuleError, defineFeature, SYSTEM_TENANT_ID, } from "@cosmicdrift/kumiko-framework/engine";
|
|
3
3
|
import { escapeHtml } from "@cosmicdrift/kumiko-renderer/headless";
|
|
4
4
|
import { cachedSecurePageResponse, redirectToCanonicalPath, slashVariantOf, } from "../page-render/index.js";
|
|
5
|
+
import { LEGAL_PAGES_BOOT_RULES } from "./boot-rules.js";
|
|
5
6
|
import { runLegalPagesBootCheck } from "./lib/boot-check.js";
|
|
6
7
|
import { validateRoutes } from "./lib/validate-routes.js";
|
|
7
8
|
import { renderMarkdownToHtml, wrapInLayout } from "./markdown.js";
|
|
@@ -35,7 +36,9 @@ export function createLegalPagesFeature(opts = {}) {
|
|
|
35
36
|
if (opts.routes !== undefined && opts.routes.length > 0 && opts.requiredBlocks === undefined) {
|
|
36
37
|
const coversDefaultBlock = LEGAL_REQUIRED_BLOCKS.some((block) => opts.routes?.some((route) => route.slug === block.slug && route.lang === block.lang));
|
|
37
38
|
if (!coversDefaultBlock) {
|
|
38
|
-
throw
|
|
39
|
+
throw bootRuleError(LEGAL_PAGES_BOOT_RULES.routesWithoutRequiredBlocks, {
|
|
40
|
+
message: "legal-pages: custom `routes` without `requiredBlocks` — pass `requiredBlocks` explicitly (or `[]`)",
|
|
41
|
+
});
|
|
39
42
|
}
|
|
40
43
|
}
|
|
41
44
|
const alternatesBySlug = alternatesBySlugOf(routes);
|
|
@@ -1,16 +1,24 @@
|
|
|
1
|
+
import { bootRuleError } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
import { LEGAL_PAGES_BOOT_RULES } from "../boot-rules.js";
|
|
1
3
|
// Validated once at feature-build time (not per-request) so a config typo
|
|
2
4
|
// fails app startup instead of surfacing as a confusing 404 later.
|
|
3
5
|
export function validateRoutes(routes) {
|
|
4
6
|
const seenPaths = new Set();
|
|
5
7
|
for (const route of routes) {
|
|
6
8
|
if (!route.path || !route.slug || !route.lang) {
|
|
7
|
-
throw
|
|
9
|
+
throw bootRuleError(LEGAL_PAGES_BOOT_RULES.invalidRoute, {
|
|
10
|
+
message: `legal-pages: route is missing a required field (path/slug/lang): ${JSON.stringify(route)}`,
|
|
11
|
+
});
|
|
8
12
|
}
|
|
9
13
|
if (!route.path.startsWith("/")) {
|
|
10
|
-
throw
|
|
14
|
+
throw bootRuleError(LEGAL_PAGES_BOOT_RULES.invalidRoute, {
|
|
15
|
+
message: `legal-pages: route path must start with "/", got "${route.path}"`,
|
|
16
|
+
});
|
|
11
17
|
}
|
|
12
18
|
if (seenPaths.has(route.path)) {
|
|
13
|
-
throw
|
|
19
|
+
throw bootRuleError(LEGAL_PAGES_BOOT_RULES.duplicateRoutePath, {
|
|
20
|
+
message: `legal-pages: duplicate route path "${route.path}"`,
|
|
21
|
+
});
|
|
14
22
|
}
|
|
15
23
|
seenPaths.add(route.path);
|
|
16
24
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const METRICS_BOOT_RULES: {
|
|
2
|
+
readonly duplicateMetricId: {
|
|
3
|
+
readonly id: "metrics/duplicate-metric-id";
|
|
4
|
+
readonly summary: "Metric ids passed to the metrics factory are unique.";
|
|
5
|
+
readonly fix: "Rename one of the metrics.";
|
|
6
|
+
};
|
|
7
|
+
readonly invalidMetric: {
|
|
8
|
+
readonly id: "metrics/invalid-metric";
|
|
9
|
+
readonly summary: "Each metric passed to the metrics factory has a kebab-case id and a valid definition.";
|
|
10
|
+
readonly fix: "Fix the metric named in the error message.";
|
|
11
|
+
};
|
|
12
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const METRICS_BOOT_RULES = {
|
|
2
|
+
duplicateMetricId: {
|
|
3
|
+
id: "metrics/duplicate-metric-id",
|
|
4
|
+
summary: "Metric ids passed to the metrics factory are unique.",
|
|
5
|
+
fix: "Rename one of the metrics.",
|
|
6
|
+
},
|
|
7
|
+
invalidMetric: {
|
|
8
|
+
id: "metrics/invalid-metric",
|
|
9
|
+
summary: "Each metric passed to the metrics factory has a kebab-case id and a valid definition.",
|
|
10
|
+
fix: "Fix the metric named in the error message.",
|
|
11
|
+
},
|
|
12
|
+
};
|
package/dist/metrics/validate.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { extractTableInfo, isTimestamptzType } from "@cosmicdrift/kumiko-framework/db";
|
|
2
|
+
import { bootRuleError } from "@cosmicdrift/kumiko-framework/engine";
|
|
3
|
+
import { METRICS_BOOT_RULES } from "./boot-rules.js";
|
|
2
4
|
import { filterValueKindOf, metricFilterEntries, RESERVED_PAYLOAD_KEYS } from "./filters.js";
|
|
3
5
|
import { METRIC_RANGES } from "./web/constants.js";
|
|
4
6
|
const KEBAB_ID = /^[a-z][a-z0-9]*(-[a-z0-9]+)*$/;
|
|
@@ -11,7 +13,9 @@ export function validateMetrics(metrics) {
|
|
|
11
13
|
const seen = new Set();
|
|
12
14
|
for (const metric of metrics) {
|
|
13
15
|
if (seen.has(metric.id)) {
|
|
14
|
-
throw
|
|
16
|
+
throw bootRuleError(METRICS_BOOT_RULES.duplicateMetricId, {
|
|
17
|
+
message: `metrics: duplicate metric id "${metric.id}"`,
|
|
18
|
+
});
|
|
15
19
|
}
|
|
16
20
|
seen.add(metric.id);
|
|
17
21
|
validateMetric(metric);
|
|
@@ -19,7 +23,9 @@ export function validateMetrics(metrics) {
|
|
|
19
23
|
}
|
|
20
24
|
function validateMetric(metric) {
|
|
21
25
|
const fail = (reason) => {
|
|
22
|
-
throw
|
|
26
|
+
throw bootRuleError(METRICS_BOOT_RULES.invalidMetric, {
|
|
27
|
+
message: `metrics: metric "${metric.id}" ${reason}`,
|
|
28
|
+
});
|
|
23
29
|
};
|
|
24
30
|
if (!KEBAB_ID.test(metric.id))
|
|
25
31
|
fail("has an id that is not kebab-case");
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const NOTES_HISTORY_BOOT_RULES: {
|
|
2
|
+
readonly emptyParentsAllowlist: {
|
|
3
|
+
readonly id: "notes-history/empty-parents-allowlist";
|
|
4
|
+
readonly summary: "The parents allowlist is omitted or non-empty.";
|
|
5
|
+
readonly fix: "Omit parents or list at least one entity.";
|
|
6
|
+
};
|
|
7
|
+
};
|
|
@@ -12,8 +12,9 @@
|
|
|
12
12
|
// Only create + list are registered — no update, no delete. A correction is
|
|
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
|
-
import { defineEntityListHandler, defineFeature, } from "@cosmicdrift/kumiko-framework/engine";
|
|
15
|
+
import { bootRuleError, defineEntityListHandler, defineFeature, } from "@cosmicdrift/kumiko-framework/engine";
|
|
16
16
|
import { assertNoWhereRuleInOwnershipWrite, resolveFeatureAccess } from "../shared/index.js";
|
|
17
|
+
import { NOTES_HISTORY_BOOT_RULES } from "./boot-rules.js";
|
|
17
18
|
import { createNoteEntryEntity, noteMentionEntity } from "./entity.js";
|
|
18
19
|
import { createNoteEntryExecutor } from "./executor.js";
|
|
19
20
|
import { createAddNoteHandler } from "./handlers/add-note.write.js";
|
|
@@ -56,9 +57,11 @@ export function createNotesHistoryFeature(opts = {}) {
|
|
|
56
57
|
// that's a config mistake, not a valid allowlist. Omit `parents` instead
|
|
57
58
|
// of passing an empty array.
|
|
58
59
|
if (opts.parents !== undefined && opts.parents.length === 0) {
|
|
59
|
-
throw
|
|
60
|
-
"
|
|
61
|
-
|
|
60
|
+
throw bootRuleError(NOTES_HISTORY_BOOT_RULES.emptyParentsAllowlist, {
|
|
61
|
+
message: "createNotesHistoryFeature({ parents }): parents must not be an empty array — " +
|
|
62
|
+
"an empty allowlist rejects every add-note call. Omit `parents` to allow " +
|
|
63
|
+
"any registered entity the caller can read as a note parent.",
|
|
64
|
+
});
|
|
62
65
|
}
|
|
63
66
|
return defineFeature(NOTES_HISTORY_FEATURE_NAME, (r) => registerNotesHistory(r, resolveFeatureAccess(opts, DEFAULT_NOTES_HISTORY_ACCESS), opts.ownership, opts.parents));
|
|
64
67
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const PERSONAL_ACCESS_TOKENS_BOOT_RULES: {
|
|
2
|
+
readonly scopeEventWithoutContract: {
|
|
3
|
+
readonly id: "personal-access-tokens/scope-event-without-contract";
|
|
4
|
+
readonly summary: "Events listed in PAT scopes have a public webhook contract.";
|
|
5
|
+
readonly fix: "Declare the event with r.defineWebhookEvent or opt the entity into webhookEvents.";
|
|
6
|
+
};
|
|
7
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export const PERSONAL_ACCESS_TOKENS_BOOT_RULES = {
|
|
2
|
+
scopeEventWithoutContract: {
|
|
3
|
+
id: "personal-access-tokens/scope-event-without-contract",
|
|
4
|
+
summary: "Events listed in PAT scopes have a public webhook contract.",
|
|
5
|
+
fix: "Declare the event with r.defineWebhookEvent or opt the entity into webhookEvents.",
|
|
6
|
+
},
|
|
7
|
+
};
|
|
@@ -25,6 +25,7 @@ export type PersonalAccessTokensOptions = {
|
|
|
25
25
|
};
|
|
26
26
|
export type PatFeatureExports = {
|
|
27
27
|
readonly rateLimit: PatRateLimit;
|
|
28
|
+
readonly scopes: PatScopeConfig;
|
|
28
29
|
readonly bindAutoRevokeOnPasswordChange: BindPatAutoRevokeOnPasswordChange;
|
|
29
30
|
};
|
|
30
31
|
export declare function createPersonalAccessTokensFeature(options: PersonalAccessTokensOptions): FeatureDefinition;
|
|
@@ -12,6 +12,7 @@ import { PAT_FEATURE_I18N, patScopeOptionTranslations } from "./i18n.js";
|
|
|
12
12
|
import { PAT_REVOKED_EVENT_SHORT, patRevokedSchema } from "./pat-revoked-event.js";
|
|
13
13
|
import { createPatResolver } from "./resolver.js";
|
|
14
14
|
import { apiTokenEntity } from "./schema/api-token.js";
|
|
15
|
+
import { validateScopeEventContracts } from "./scope-events-check.js";
|
|
15
16
|
import { createPatMintScreen, patListScreen } from "./screens.js";
|
|
16
17
|
import { API_TOKEN_ENTITY_NAME, PAT_DEFAULT_RATE_LIMIT, PAT_FEATURE, } from "./web/constants.js";
|
|
17
18
|
// Password-change is the only field-level trigger — see the postSave hook
|
|
@@ -70,6 +71,7 @@ export function createPersonalAccessTokensFeature(options) {
|
|
|
70
71
|
// different path. No projection: the payload IS the read, consumed
|
|
71
72
|
// directly off the event-store NOTIFY.
|
|
72
73
|
r.defineEvent(PAT_REVOKED_EVENT_SHORT, patRevokedSchema, { piiFields: "none" });
|
|
74
|
+
r.bootCheck(({ features }) => validateScopeEventContracts(scopes, features));
|
|
73
75
|
// Password-change auto-revoke — mirrors sessions' own
|
|
74
76
|
// autoRevokeOnPasswordChange postSave hook, including WHY it's a
|
|
75
77
|
// late-bind callback rather than direct ctx.db use: user:write:user:update
|
|
@@ -123,12 +125,12 @@ export function createPersonalAccessTokensFeature(options) {
|
|
|
123
125
|
r.translations({ keys: { ...PAT_FEATURE_I18N, ...patScopeOptionTranslations(scopes) } });
|
|
124
126
|
// rateLimit flows into feature.exports so run-prod-app builds the
|
|
125
127
|
// limiter from the same declaration — single source of truth. `scopes`
|
|
126
|
-
// is
|
|
127
|
-
// available-scopes, so it doesn't need to round-trip through exports.
|
|
128
|
+
// is also exported so the API-docs generator can read the catalog.
|
|
128
129
|
return {
|
|
129
130
|
handlers,
|
|
130
131
|
queries,
|
|
131
132
|
bindAutoRevokeOnPasswordChange,
|
|
133
|
+
scopes,
|
|
132
134
|
rateLimit: options.rateLimit ?? PAT_DEFAULT_RATE_LIMIT,
|
|
133
135
|
};
|
|
134
136
|
});
|
|
@@ -7,7 +7,7 @@ import { encryptForDirectWrite, unprocessable, verifyPassword } from "../../shar
|
|
|
7
7
|
import { UserQueries } from "../../user/index.js";
|
|
8
8
|
import { mintPatToken } from "../hash.js";
|
|
9
9
|
import { apiTokenEntity, apiTokenTable } from "../schema/api-token.js";
|
|
10
|
-
import { API_TOKEN_ENTITY_NAME, PAT_DEFAULT_EXPIRES_IN_DAYS, PatErrors } from "../web/constants.js";
|
|
10
|
+
import { API_TOKEN_ENTITY_NAME, PAT_DEFAULT_EXPIRES_IN_DAYS, PAT_MAX_EXPIRES_IN_DAYS, PatErrors, } from "../web/constants.js";
|
|
11
11
|
// @wrapper-known error-helper
|
|
12
12
|
function reauthFailed() {
|
|
13
13
|
return unprocessable(PatErrors.reauthRequired, "errors.reauthRequired");
|
|
@@ -27,7 +27,7 @@ export function createPatCreateHandler(opts = {}) {
|
|
|
27
27
|
schema: z.object({
|
|
28
28
|
name: z.string().min(1).max(120),
|
|
29
29
|
scopes: z.array(z.string().min(1)).min(1),
|
|
30
|
-
expiresInDays: z.number().int().positive().max(
|
|
30
|
+
expiresInDays: z.number().int().positive().max(PAT_MAX_EXPIRES_IN_DAYS).optional(),
|
|
31
31
|
currentPassword: z.string().min(1),
|
|
32
32
|
mfaCode: z.string().optional(),
|
|
33
33
|
}),
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { ACTION_FORM_ENTITY } from "@cosmicdrift/kumiko-framework/ui-types";
|
|
2
2
|
import { fieldLabelKey, fieldOptionLabelKey } from "@cosmicdrift/kumiko-renderer/headless";
|
|
3
|
-
import { PAT_FEATURE } from "./web/constants.js";
|
|
3
|
+
import { PAT_FEATURE, PatHandlers } from "./web/constants.js";
|
|
4
4
|
const mintFieldKey = (field) => fieldLabelKey(PAT_FEATURE, ACTION_FORM_ENTITY, field);
|
|
5
5
|
const scopeOptionKey = (grant) => fieldOptionLabelKey(PAT_FEATURE, ACTION_FORM_ENTITY, "scopes", grant);
|
|
6
6
|
// The generated scope labels are English only; apps translate them under this key.
|
|
7
7
|
export const patScopeOptionKey = (domain, level) => scopeOptionKey(`${domain}:${level}`);
|
|
8
|
+
// The revoke handler has no entity and no action form, so its title and field label only exist here.
|
|
9
|
+
const patRevokeKey = (suffix) => `${PatHandlers.revoke}:${suffix}`;
|
|
8
10
|
export const PAT_FEATURE_I18N = {
|
|
9
11
|
"screen:api-tokens.title": { en: "Personal Access Tokens" },
|
|
10
12
|
"screen:api-token-create.title": { en: "Create a new token" },
|
|
@@ -19,6 +21,8 @@ export const PAT_FEATURE_I18N = {
|
|
|
19
21
|
"pat.list.status.expired": { en: "Expired" },
|
|
20
22
|
"pat.list.revoke": { en: "Revoke" },
|
|
21
23
|
"pat.list.revoke.confirm": { en: "Revoke this token? Anything using it will stop working." },
|
|
24
|
+
[patRevokeKey("title")]: { en: "Revoke token" },
|
|
25
|
+
[patRevokeKey("field:id")]: { en: "Token" },
|
|
22
26
|
"pat.create.title": { en: "Create a new token" },
|
|
23
27
|
"pat.create.submit": { en: "Create token" },
|
|
24
28
|
"pat.create.reauth": { en: "Confirm your identity" },
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { FeatureDefinition } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
2
|
import { type PatRateLimit } from "./web/constants.ts";
|
|
3
|
+
import type { PatScopeConfig } from "./web/scopes.ts";
|
|
3
4
|
export type { BindPatAutoRevokeOnPasswordChange, PersonalAccessTokensOptions } from "./feature.ts";
|
|
4
5
|
export { bindPatAutoRevokeOnPasswordChangeFromFeature, createPersonalAccessTokensFeature, } from "./feature.ts";
|
|
5
6
|
export type { CreatePatOptions, PatMfaVerifyResult } from "./handlers/create.write.ts";
|
|
@@ -10,7 +11,8 @@ export { createPatResolver } from "./resolver.ts";
|
|
|
10
11
|
export { revokeAllPatTokensForUser } from "./revoke-for-user.ts";
|
|
11
12
|
export { apiTokenEntity, apiTokenTable } from "./schema/api-token.ts";
|
|
12
13
|
export type { PatRateLimit } from "./web/constants.ts";
|
|
13
|
-
export { PAT_DEFAULT_RATE_LIMIT, PAT_FEATURE, PatHandlers, PatQueries } from "./web/constants.ts";
|
|
14
|
+
export { PAT_DEFAULT_EXPIRES_IN_DAYS, PAT_DEFAULT_RATE_LIMIT, PAT_FEATURE, PAT_MAX_EXPIRES_IN_DAYS, PAT_SCREEN_ID, PatHandlers, PatQueries, } from "./web/constants.ts";
|
|
14
15
|
export type { PatScopeConfig, PatScopeDef } from "./web/scopes.ts";
|
|
15
|
-
export { expandScopes } from "./web/scopes.ts";
|
|
16
|
+
export { expandScopeEvents, expandScopes } from "./web/scopes.ts";
|
|
17
|
+
export declare function patScopesFromFeature(feature: FeatureDefinition): PatScopeConfig | undefined;
|
|
16
18
|
export declare function patRateLimitFromFeature(feature: FeatureDefinition): PatRateLimit;
|
|
@@ -6,8 +6,35 @@ export { PAT_REVOKED_AGGREGATE_TYPE, PAT_REVOKED_EVENT_QN, PAT_REVOKED_EVENT_SHO
|
|
|
6
6
|
export { createPatResolver } from "./resolver.js";
|
|
7
7
|
export { revokeAllPatTokensForUser } from "./revoke-for-user.js";
|
|
8
8
|
export { apiTokenEntity, apiTokenTable } from "./schema/api-token.js";
|
|
9
|
-
export { PAT_DEFAULT_RATE_LIMIT, PAT_FEATURE, PatHandlers, PatQueries } from "./web/constants.js";
|
|
10
|
-
export { expandScopes } from "./web/scopes.js";
|
|
9
|
+
export { PAT_DEFAULT_EXPIRES_IN_DAYS, PAT_DEFAULT_RATE_LIMIT, PAT_FEATURE, PAT_MAX_EXPIRES_IN_DAYS, PAT_SCREEN_ID, PatHandlers, PatQueries, } from "./web/constants.js";
|
|
10
|
+
export { expandScopeEvents, expandScopes } from "./web/scopes.js";
|
|
11
|
+
function isStringArray(value) {
|
|
12
|
+
return Array.isArray(value) && value.every((entry) => typeof entry === "string");
|
|
13
|
+
}
|
|
14
|
+
function isPatScopeDef(value) {
|
|
15
|
+
if (!value || typeof value !== "object")
|
|
16
|
+
return false;
|
|
17
|
+
if (!("label" in value) || typeof value.label !== "string")
|
|
18
|
+
return false;
|
|
19
|
+
if (!("read" in value) || !isStringArray(value.read))
|
|
20
|
+
return false;
|
|
21
|
+
if ("write" in value && value.write !== undefined && !isStringArray(value.write))
|
|
22
|
+
return false;
|
|
23
|
+
return !("events" in value) || value.events === undefined || isStringArray(value.events);
|
|
24
|
+
}
|
|
25
|
+
function isPatScopeConfig(value) {
|
|
26
|
+
return !!value && typeof value === "object" && Object.values(value).every(isPatScopeDef);
|
|
27
|
+
}
|
|
28
|
+
// Reads the scope catalog off a mounted PAT feature's exports; undefined for any other feature.
|
|
29
|
+
export function patScopesFromFeature(feature) {
|
|
30
|
+
const exports = feature.exports;
|
|
31
|
+
if (exports && typeof exports === "object" && "scopes" in exports) {
|
|
32
|
+
const { scopes } = exports;
|
|
33
|
+
if (isPatScopeConfig(scopes))
|
|
34
|
+
return scopes;
|
|
35
|
+
}
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
11
38
|
// Reads the per-token rate-limit config off a mounted PAT feature's exports.
|
|
12
39
|
// Falls back to the default when absent. run-prod-app uses this to build the
|
|
13
40
|
// limiter from the same declaration the feature was given.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { bootRuleError, createWebhookContractResolver, } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
import { PERSONAL_ACCESS_TOKENS_BOOT_RULES } from "./boot-rules.js";
|
|
3
|
+
import { PAT_FEATURE } from "./web/constants.js";
|
|
4
|
+
function entityNameOf(qualifiedName) {
|
|
5
|
+
const dot = qualifiedName.lastIndexOf(".");
|
|
6
|
+
return dot > 0 ? qualifiedName.slice(0, dot) : qualifiedName;
|
|
7
|
+
}
|
|
8
|
+
export function validateScopeEventContracts(scopes, features) {
|
|
9
|
+
const resolver = createWebhookContractResolver(features);
|
|
10
|
+
for (const [domain, def] of Object.entries(scopes)) {
|
|
11
|
+
for (const qn of def.events ?? []) {
|
|
12
|
+
if (resolver.get(qn))
|
|
13
|
+
continue;
|
|
14
|
+
throw bootRuleError(PERSONAL_ACCESS_TOKENS_BOOT_RULES.scopeEventWithoutContract, {
|
|
15
|
+
message: `[${PAT_FEATURE}] scope "${domain}" lists event "${qn}" without a public contract. ` +
|
|
16
|
+
"Declare it with r.defineWebhookEvent(...), or set webhookEvents: true on the entity to release its <entity>.created/.updated/.deleted events " +
|
|
17
|
+
`(entity "${entityNameOf(qn)}" has no such opt-in); internal r.defineEvent events are never released.`,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|