@cosmicdrift/kumiko-bundled-features 0.412.0 → 0.413.1
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/api-docs/anchors.js +1 -1
- 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/data-retention/feature.js +3 -2
- 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/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/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/scope-events-check.js +7 -4
- 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/data-retention/changes.json +6 -0
- package/src/{contact → helpdesk}/changes.json +18 -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 → helpdesk}/challenge.d.ts +0 -0
- /package/dist/{contact/client/contact-website-client.js → helpdesk/client/helpdesk-website-client.js} +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
|
@@ -25,7 +25,7 @@ export type CreateAdminShellOptions = {
|
|
|
25
25
|
* createMetricsFeature / createSystemMetricsFeature. Panels exist only for
|
|
26
26
|
* ids in this list. Default DEFAULT_METRICS. */
|
|
27
27
|
readonly metrics?: readonly MetricDefinition[];
|
|
28
|
-
/** Panels appended to the platform overview, for tiles a mounted feature owns (e.g. the
|
|
28
|
+
/** Panels appended to the platform overview, for tiles a mounted feature owns (e.g. the helpdesk inbox count). */
|
|
29
29
|
readonly extraPlatformPanels?: readonly DashboardPanelDefinition[];
|
|
30
30
|
};
|
|
31
31
|
export declare function createAdminShellFeature(options?: CreateAdminShellOptions): FeatureDefinition;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const QN_TYPE_SEGMENTS = new Set(["query", "write"]);
|
|
2
2
|
const HEADING_SEPARATOR = ": ";
|
|
3
|
-
/** `
|
|
3
|
+
/** `ticketing:write:ticket:close` becomes ["ticket", "close"]: the feature prefix and
|
|
4
4
|
* the `query`/`write` kind are noise inside a page that already names both. */
|
|
5
5
|
function tailSegments(qn) {
|
|
6
6
|
const segments = qn.split(":");
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const AUTH_EMAIL_PASSWORD_BOOT_RULES: {
|
|
2
|
+
readonly hmacSecretTooShort: {
|
|
3
|
+
readonly id: "auth-email-password/hmac-secret-too-short";
|
|
4
|
+
readonly summary: "Each configured token hmacSecret is at least the minimum length.";
|
|
5
|
+
readonly fix: "Pass an hmacSecret of at least the minimum length.";
|
|
6
|
+
};
|
|
7
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export const AUTH_EMAIL_PASSWORD_BOOT_RULES = {
|
|
2
|
+
hmacSecretTooShort: {
|
|
3
|
+
id: "auth-email-password/hmac-secret-too-short",
|
|
4
|
+
summary: "Each configured token hmacSecret is at least the minimum length.",
|
|
5
|
+
fix: "Pass an hmacSecret of at least the minimum length.",
|
|
6
|
+
},
|
|
7
|
+
};
|
|
@@ -21,7 +21,7 @@ import { createSignupRequestHandler, } from "./handlers/signup-request.write.js"
|
|
|
21
21
|
import { createSwitchTenantMfaGateHandler } from "./handlers/switch-tenant-mfa-gate.write.js";
|
|
22
22
|
import { createVerifyEmailHandler } from "./handlers/verify-email.write.js";
|
|
23
23
|
import { AUTH_MAIL_VARIABLES, authMailLocalizedTemplate, INVITE_MAIL_VARIABLES, sendsMagicLinkMail, } from "./mail-notifications.js";
|
|
24
|
-
import {
|
|
24
|
+
import { assertSignedTokenSecretsLongEnough } from "./validate-options.js";
|
|
25
25
|
import { AUTH_EMAIL_PASSWORD_MAIL_I18N } from "./web/mail-i18n.js";
|
|
26
26
|
/**
|
|
27
27
|
* Env-vars contract for the `auth-email-password` feature.
|
|
@@ -51,18 +51,11 @@ export const authEmailPasswordEnvSchema = z.object({
|
|
|
51
51
|
// identity lookups (via ctx.dispatch.queryAs) and on the tenant feature for
|
|
52
52
|
// membership resolution. No direct imports of foreign tables.
|
|
53
53
|
export function createAuthEmailPasswordFeature(opts = {}) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
if (opts.emailVerification && opts.emailVerification.hmacSecret.length < MIN_HMAC_SECRET_LENGTH) {
|
|
61
|
-
throw new Error(`[auth-email-password] emailVerification.hmacSecret must be ≥${MIN_HMAC_SECRET_LENGTH} chars (HMAC-SHA256 token signing)`);
|
|
62
|
-
}
|
|
63
|
-
if (opts.accountUnlock && opts.accountUnlock.hmacSecret.length < MIN_HMAC_SECRET_LENGTH) {
|
|
64
|
-
throw new Error(`[auth-email-password] accountUnlock.hmacSecret must be ≥${MIN_HMAC_SECRET_LENGTH} chars (HMAC-SHA256 token signing)`);
|
|
65
|
-
}
|
|
54
|
+
assertSignedTokenSecretsLongEnough({
|
|
55
|
+
passwordReset: opts.passwordReset,
|
|
56
|
+
emailVerification: opts.emailVerification,
|
|
57
|
+
accountUnlock: opts.accountUnlock,
|
|
58
|
+
});
|
|
66
59
|
const strictVerification = opts.emailVerification !== undefined && (opts.emailVerification.mode ?? "strict") === "strict";
|
|
67
60
|
const feature = defineFeature("auth-email-password", (r) => {
|
|
68
61
|
r.describe("Provides email+password authentication: the always-on handlers are `login`, `changePassword`, and `logout`; optional flows — password reset, email verification, magic-link self-signup, tenant invite, and account-unlock — are registered only when you pass their respective option objects (`passwordReset`, `emailVerification`, `signup`, `invite`, `accountUnlock`) to `createAuthEmailPasswordFeature(opts)`. All five magic-link flows dispatch their mail through the `delivery` feature via `ctx.notify`, so mounting any of them additionally requires `delivery`. Tokens are HMAC-signed (reset/verify/unlock) or opaque-random in Redis (signup/invite). `accountUnlock` is the self-service escape hatch for `accountLockout`'s monotonic failure-counter (#1266): confirming the mailed token clears the Redis lockout state without touching the user entity. Requires the `user` and `tenant` features, and declares `JWT_SECRET` (≥ 32 chars) in `authEmailPasswordEnvSchema` so a missing secret surfaces at boot validation rather than on the first login attempt.");
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { bootRuleError } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
import { AUTH_EMAIL_PASSWORD_BOOT_RULES } from "./boot-rules.js";
|
|
3
|
+
import { MIN_HMAC_SECRET_LENGTH } from "./web/constants.js";
|
|
4
|
+
// ≥32 chars, symmetric to the JWT_SECRET env check: a short HMAC secret
|
|
5
|
+
// makes reset/verify tokens forgeable — that's account takeover, so the
|
|
6
|
+
// factory fails fast instead of trusting the caller.
|
|
7
|
+
export function assertSignedTokenSecretsLongEnough(signedTokenFlows) {
|
|
8
|
+
for (const [optionName, flow] of Object.entries(signedTokenFlows)) {
|
|
9
|
+
if (flow && flow.hmacSecret.length < MIN_HMAC_SECRET_LENGTH) {
|
|
10
|
+
throw bootRuleError(AUTH_EMAIL_PASSWORD_BOOT_RULES.hmacSecretTooShort, {
|
|
11
|
+
message: `[auth-email-password] ${optionName}.hmacSecret must be ≥${MIN_HMAC_SECRET_LENGTH} chars (HMAC-SHA256 token signing)`,
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare const BILLING_FOUNDATION_BOOT_RULES: {
|
|
2
|
+
readonly consumerProtectionInvalid: {
|
|
3
|
+
readonly id: "billing-foundation/consumer-protection-invalid";
|
|
4
|
+
readonly summary: "consumerProtection options carry non-empty texts, a valid operator email, a valid termination scope and valid legal links.";
|
|
5
|
+
readonly fix: "Fix the consumerProtection option named in the error message.";
|
|
6
|
+
};
|
|
7
|
+
readonly baseUrlInvalid: {
|
|
8
|
+
readonly id: "billing-foundation/base-url-invalid";
|
|
9
|
+
readonly summary: "baseUrl is a parseable absolute http or https URL.";
|
|
10
|
+
readonly fix: "Pass an absolute http(s) URL as baseUrl.";
|
|
11
|
+
};
|
|
12
|
+
readonly baseUrlRequired: {
|
|
13
|
+
readonly id: "billing-foundation/base-url-required";
|
|
14
|
+
readonly summary: "baseUrl is set whenever consumerProtection or a catalog is configured.";
|
|
15
|
+
readonly fix: "Pass baseUrl, checkout redirect URLs are built from it.";
|
|
16
|
+
};
|
|
17
|
+
readonly catalogInvalid: {
|
|
18
|
+
readonly id: "billing-foundation/catalog-invalid";
|
|
19
|
+
readonly summary: "The catalog declares unique plans, root-relative paths, view roles and a valid contact card.";
|
|
20
|
+
readonly fix: "Fix the catalog option named in the error message.";
|
|
21
|
+
};
|
|
22
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export const BILLING_FOUNDATION_BOOT_RULES = {
|
|
2
|
+
consumerProtectionInvalid: {
|
|
3
|
+
id: "billing-foundation/consumer-protection-invalid",
|
|
4
|
+
summary: "consumerProtection options carry non-empty texts, a valid operator email, a valid termination scope and valid legal links.",
|
|
5
|
+
fix: "Fix the consumerProtection option named in the error message.",
|
|
6
|
+
},
|
|
7
|
+
baseUrlInvalid: {
|
|
8
|
+
id: "billing-foundation/base-url-invalid",
|
|
9
|
+
summary: "baseUrl is a parseable absolute http or https URL.",
|
|
10
|
+
fix: "Pass an absolute http(s) URL as baseUrl.",
|
|
11
|
+
},
|
|
12
|
+
baseUrlRequired: {
|
|
13
|
+
id: "billing-foundation/base-url-required",
|
|
14
|
+
summary: "baseUrl is set whenever consumerProtection or a catalog is configured.",
|
|
15
|
+
fix: "Pass baseUrl, checkout redirect URLs are built from it.",
|
|
16
|
+
},
|
|
17
|
+
catalogInvalid: {
|
|
18
|
+
id: "billing-foundation/catalog-invalid",
|
|
19
|
+
summary: "The catalog declares unique plans, root-relative paths, view roles and a valid contact card.",
|
|
20
|
+
fix: "Fix the catalog option named in the error message.",
|
|
21
|
+
},
|
|
22
|
+
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { bootRuleError } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
import { BILLING_FOUNDATION_BOOT_RULES } from "./boot-rules.js";
|
|
1
3
|
// Feature-definition-time validation for createBillingFoundationFeature's
|
|
2
4
|
// options — split out of feature.ts to keep that file at registration-only
|
|
3
5
|
// concerns (app-feature-structure guard's 300-line budget). Internal — not
|
|
@@ -30,7 +32,9 @@ function validateProviderTexts(cp) {
|
|
|
30
32
|
continue;
|
|
31
33
|
for (const locale of ["de", "en"]) {
|
|
32
34
|
if (!text[locale]?.trim()) {
|
|
33
|
-
throw
|
|
35
|
+
throw bootRuleError(BILLING_FOUNDATION_BOOT_RULES.consumerProtectionInvalid, {
|
|
36
|
+
message: `createBillingFoundationFeature: consumerProtection.providerTexts.${providerName}.${textName} needs a non-empty "${locale}" entry.`,
|
|
37
|
+
});
|
|
34
38
|
}
|
|
35
39
|
}
|
|
36
40
|
}
|
|
@@ -38,22 +42,32 @@ function validateProviderTexts(cp) {
|
|
|
38
42
|
}
|
|
39
43
|
function validateConsumerProtection(cp) {
|
|
40
44
|
if (cp.termsTextBlock.trim() === "") {
|
|
41
|
-
throw
|
|
45
|
+
throw bootRuleError(BILLING_FOUNDATION_BOOT_RULES.consumerProtectionInvalid, {
|
|
46
|
+
message: "createBillingFoundationFeature: consumerProtection.termsTextBlock is empty.",
|
|
47
|
+
});
|
|
42
48
|
}
|
|
43
49
|
for (const locale of ["de", "en"]) {
|
|
44
50
|
if (!cp.vatNote[locale]?.trim()) {
|
|
45
|
-
throw
|
|
51
|
+
throw bootRuleError(BILLING_FOUNDATION_BOOT_RULES.consumerProtectionInvalid, {
|
|
52
|
+
message: `createBillingFoundationFeature: consumerProtection.vatNote needs a non-empty "${locale}" entry.`,
|
|
53
|
+
});
|
|
46
54
|
}
|
|
47
55
|
}
|
|
48
56
|
validateProviderTexts(cp);
|
|
49
57
|
if (!z.email().safeParse(cp.operatorEmail).success) {
|
|
50
|
-
throw
|
|
58
|
+
throw bootRuleError(BILLING_FOUNDATION_BOOT_RULES.consumerProtectionInvalid, {
|
|
59
|
+
message: `createBillingFoundationFeature: consumerProtection.operatorEmail "${cp.operatorEmail}" is not a valid email address.`,
|
|
60
|
+
});
|
|
51
61
|
}
|
|
52
62
|
if (cp.oneOffItemLabel !== undefined && typeof cp.oneOffItemLabel !== "function") {
|
|
53
|
-
throw
|
|
63
|
+
throw bootRuleError(BILLING_FOUNDATION_BOOT_RULES.consumerProtectionInvalid, {
|
|
64
|
+
message: "createBillingFoundationFeature: consumerProtection.oneOffItemLabel must be a function.",
|
|
65
|
+
});
|
|
54
66
|
}
|
|
55
67
|
if (cp.terminationScope !== undefined && !isTerminationScope(cp.terminationScope)) {
|
|
56
|
-
throw
|
|
68
|
+
throw bootRuleError(BILLING_FOUNDATION_BOOT_RULES.consumerProtectionInvalid, {
|
|
69
|
+
message: `createBillingFoundationFeature: consumerProtection.terminationScope "${String(cp.terminationScope)}" must be one of ${TERMINATION_SCOPES.map((scope) => `"${scope}"`).join(", ")}.`,
|
|
70
|
+
});
|
|
57
71
|
}
|
|
58
72
|
if (isLegalLinkSet(cp.legalLinks)) {
|
|
59
73
|
validateLegalLinkSet(cp.legalLinks, "legalLinks");
|
|
@@ -66,7 +80,9 @@ function validatePerLocaleLegalLinks(legalLinks) {
|
|
|
66
80
|
for (const locale of CONSENT_LOCALES) {
|
|
67
81
|
const set = legalLinks[locale];
|
|
68
82
|
if (!set) {
|
|
69
|
-
throw
|
|
83
|
+
throw bootRuleError(BILLING_FOUNDATION_BOOT_RULES.consumerProtectionInvalid, {
|
|
84
|
+
message: `createBillingFoundationFeature: consumerProtection.legalLinks needs a "${locale}" entry when given per locale.`,
|
|
85
|
+
});
|
|
70
86
|
}
|
|
71
87
|
validateLegalLinkSet(set, `legalLinks.${locale}`);
|
|
72
88
|
}
|
|
@@ -77,18 +93,24 @@ function validateLegalLinkSet(set, path) {
|
|
|
77
93
|
if (key === "refund" && link === undefined)
|
|
78
94
|
continue;
|
|
79
95
|
if (typeof link !== "string" || !isRootRelativeOrHttpsUrl(link)) {
|
|
80
|
-
throw
|
|
96
|
+
throw bootRuleError(BILLING_FOUNDATION_BOOT_RULES.consumerProtectionInvalid, {
|
|
97
|
+
message: `createBillingFoundationFeature: consumerProtection.${path}.${key} "${link}" must be a root-relative path ("/..." not "//") or an absolute https URL.`,
|
|
98
|
+
});
|
|
81
99
|
}
|
|
82
100
|
}
|
|
83
101
|
}
|
|
84
102
|
function validateContactCard(contact) {
|
|
85
103
|
for (const key of ["labelKey", "actionLabelKey"]) {
|
|
86
104
|
if (contact[key].trim() === "") {
|
|
87
|
-
throw
|
|
105
|
+
throw bootRuleError(BILLING_FOUNDATION_BOOT_RULES.catalogInvalid, {
|
|
106
|
+
message: `createBillingFoundationFeature: catalog.contact.${key} must not be empty.`,
|
|
107
|
+
});
|
|
88
108
|
}
|
|
89
109
|
}
|
|
90
110
|
if (!isContactCardHref(contact.href)) {
|
|
91
|
-
throw
|
|
111
|
+
throw bootRuleError(BILLING_FOUNDATION_BOOT_RULES.catalogInvalid, {
|
|
112
|
+
message: `createBillingFoundationFeature: catalog.contact.href "${contact.href}" must be an absolute https: or mailto: URL.`,
|
|
113
|
+
});
|
|
92
114
|
}
|
|
93
115
|
}
|
|
94
116
|
function validateBaseUrl(baseUrl) {
|
|
@@ -97,10 +119,14 @@ function validateBaseUrl(baseUrl) {
|
|
|
97
119
|
parsed = new URL(baseUrl);
|
|
98
120
|
}
|
|
99
121
|
catch {
|
|
100
|
-
throw
|
|
122
|
+
throw bootRuleError(BILLING_FOUNDATION_BOOT_RULES.baseUrlInvalid, {
|
|
123
|
+
message: `createBillingFoundationFeature: baseUrl "${baseUrl}" is not a parseable absolute URL.`,
|
|
124
|
+
});
|
|
101
125
|
}
|
|
102
126
|
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
103
|
-
throw
|
|
127
|
+
throw bootRuleError(BILLING_FOUNDATION_BOOT_RULES.baseUrlInvalid, {
|
|
128
|
+
message: `createBillingFoundationFeature: baseUrl "${baseUrl}" must use http or https (parsed protocol "${parsed.protocol}").`,
|
|
129
|
+
});
|
|
104
130
|
}
|
|
105
131
|
}
|
|
106
132
|
/** Validates `options` and throws a plain `Error` with a clear message at
|
|
@@ -112,7 +138,9 @@ export function validateOptions(options) {
|
|
|
112
138
|
validateBaseUrl(options.baseUrl);
|
|
113
139
|
if (options.consumerProtection) {
|
|
114
140
|
if (options.baseUrl === undefined) {
|
|
115
|
-
throw
|
|
141
|
+
throw bootRuleError(BILLING_FOUNDATION_BOOT_RULES.baseUrlRequired, {
|
|
142
|
+
message: "createBillingFoundationFeature: consumerProtection requires baseUrl (checkout redirect URLs are built from it).",
|
|
143
|
+
});
|
|
116
144
|
}
|
|
117
145
|
validateConsumerProtection(options.consumerProtection);
|
|
118
146
|
}
|
|
@@ -121,15 +149,21 @@ export function validateOptions(options) {
|
|
|
121
149
|
if (!catalog)
|
|
122
150
|
return;
|
|
123
151
|
if (options.baseUrl === undefined) {
|
|
124
|
-
throw
|
|
152
|
+
throw bootRuleError(BILLING_FOUNDATION_BOOT_RULES.baseUrlRequired, {
|
|
153
|
+
message: "createBillingFoundationFeature: catalog requires baseUrl (plan checkouts need it to build success/cancel/return URLs).",
|
|
154
|
+
});
|
|
125
155
|
}
|
|
126
156
|
if (catalog.plans.length === 0) {
|
|
127
|
-
throw
|
|
157
|
+
throw bootRuleError(BILLING_FOUNDATION_BOOT_RULES.catalogInvalid, {
|
|
158
|
+
message: "createBillingFoundationFeature: catalog.plans must not be empty.",
|
|
159
|
+
});
|
|
128
160
|
}
|
|
129
161
|
const seen = new Set();
|
|
130
162
|
for (const tier of catalog.plans) {
|
|
131
163
|
if (seen.has(tier)) {
|
|
132
|
-
throw
|
|
164
|
+
throw bootRuleError(BILLING_FOUNDATION_BOOT_RULES.catalogInvalid, {
|
|
165
|
+
message: `createBillingFoundationFeature: catalog.plans has a duplicate tier "${tier}".`,
|
|
166
|
+
});
|
|
133
167
|
}
|
|
134
168
|
seen.add(tier);
|
|
135
169
|
}
|
|
@@ -139,11 +173,15 @@ export function validateOptions(options) {
|
|
|
139
173
|
["returnPath", catalog.returnPath],
|
|
140
174
|
]) {
|
|
141
175
|
if (path !== undefined && !isRootRelativePath(path)) {
|
|
142
|
-
throw
|
|
176
|
+
throw bootRuleError(BILLING_FOUNDATION_BOOT_RULES.catalogInvalid, {
|
|
177
|
+
message: `createBillingFoundationFeature: catalog.${key} "${path}" must start with "/" and not "//".`,
|
|
178
|
+
});
|
|
143
179
|
}
|
|
144
180
|
}
|
|
145
181
|
if (catalog.viewRoles.length === 0) {
|
|
146
|
-
throw
|
|
182
|
+
throw bootRuleError(BILLING_FOUNDATION_BOOT_RULES.catalogInvalid, {
|
|
183
|
+
message: "createBillingFoundationFeature: catalog.viewRoles must not be empty.",
|
|
184
|
+
});
|
|
147
185
|
}
|
|
148
186
|
if (catalog.contact !== undefined)
|
|
149
187
|
validateContactCard(catalog.contact);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const CAP_OVERVIEW_BOOT_RULES: {
|
|
2
|
+
readonly emptyCaps: {
|
|
3
|
+
readonly id: "cap-overview/empty-caps";
|
|
4
|
+
readonly summary: "createCapOverviewFeature receives at least one cap.";
|
|
5
|
+
readonly fix: "Pass a non-empty caps list.";
|
|
6
|
+
};
|
|
7
|
+
readonly unknownListCap: {
|
|
8
|
+
readonly id: "cap-overview/unknown-list-cap";
|
|
9
|
+
readonly summary: "listCaps only references cap ids declared in caps.";
|
|
10
|
+
readonly fix: "Use ids from caps in listCaps.";
|
|
11
|
+
};
|
|
12
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const CAP_OVERVIEW_BOOT_RULES = {
|
|
2
|
+
emptyCaps: {
|
|
3
|
+
id: "cap-overview/empty-caps",
|
|
4
|
+
summary: "createCapOverviewFeature receives at least one cap.",
|
|
5
|
+
fix: "Pass a non-empty caps list.",
|
|
6
|
+
},
|
|
7
|
+
unknownListCap: {
|
|
8
|
+
id: "cap-overview/unknown-list-cap",
|
|
9
|
+
summary: "listCaps only references cap ids declared in caps.",
|
|
10
|
+
fix: "Use ids from caps in listCaps.",
|
|
11
|
+
},
|
|
12
|
+
};
|
|
@@ -15,8 +15,9 @@
|
|
|
15
15
|
// - No nav wiring — a separate cut adds `r.nav(...)` entries.
|
|
16
16
|
//
|
|
17
17
|
// **Boot-Dependencies:** tenant, tier-engine, billing-foundation.
|
|
18
|
-
import { defineFeature } from "@cosmicdrift/kumiko-framework/engine";
|
|
18
|
+
import { bootRuleError, defineFeature, } from "@cosmicdrift/kumiko-framework/engine";
|
|
19
19
|
import { resolveCapUsageRoles } from "./access.js";
|
|
20
|
+
import { CAP_OVERVIEW_BOOT_RULES } from "./boot-rules.js";
|
|
20
21
|
import { createCapsUsageQuery } from "./handlers/caps-usage.query.js";
|
|
21
22
|
import { createTenantCapsListQuery } from "./handlers/tenant-caps-list.query.js";
|
|
22
23
|
import { tenantOptionsQuery } from "./handlers/tenant-options.query.js";
|
|
@@ -25,14 +26,18 @@ import { createMyCapsScreen, createTenantCapListScreen, platformTenantCapsScreen
|
|
|
25
26
|
import { CAP_OVERVIEW_FEATURE } from "./web/constants.js";
|
|
26
27
|
export function createCapOverviewFeature(opts) {
|
|
27
28
|
if (opts.caps.length === 0) {
|
|
28
|
-
throw
|
|
29
|
+
throw bootRuleError(CAP_OVERVIEW_BOOT_RULES.emptyCaps, {
|
|
30
|
+
message: "createCapOverviewFeature: `caps` must not be empty.",
|
|
31
|
+
});
|
|
29
32
|
}
|
|
30
33
|
const usageRoles = resolveCapUsageRoles(opts.usageVisibleTo);
|
|
31
34
|
const capIds = new Set(opts.caps.map((cap) => cap.id));
|
|
32
35
|
const listCaps = opts.listCaps ?? opts.caps.slice(0, 3).map((cap) => cap.id);
|
|
33
36
|
for (const id of listCaps) {
|
|
34
37
|
if (!capIds.has(id)) {
|
|
35
|
-
throw
|
|
38
|
+
throw bootRuleError(CAP_OVERVIEW_BOOT_RULES.unknownListCap, {
|
|
39
|
+
message: `createCapOverviewFeature: listCaps references unknown cap id "${id}" — known ids: ${[...capIds].join(", ")}`,
|
|
40
|
+
});
|
|
36
41
|
}
|
|
37
42
|
}
|
|
38
43
|
return defineFeature(CAP_OVERVIEW_FEATURE, (r) => {
|
|
@@ -35,8 +35,8 @@ export function createDataRetentionFeature() {
|
|
|
35
35
|
// Cross-feature API for the forget flow and cleanup job
|
|
36
36
|
r.exposesApi("retention.policyFor");
|
|
37
37
|
r.queryHandler(policyForQuery);
|
|
38
|
-
// Autonomous retention cleanup. perTenant fan-out (one run per
|
|
39
|
-
//
|
|
38
|
+
// Autonomous retention cleanup. perTenant fan-out (one run per active
|
|
39
|
+
// tenant plus the system tenant, like soft-delete-cleanup): runRetentionCleanup's raw
|
|
40
40
|
// query helpers need the unfiltered runner, so the handler declares
|
|
41
41
|
// escapeHatch and reaches for ctx.db.unsafeRaw(). Without this cron,
|
|
42
42
|
// retention rules are configured but never enforced.
|
|
@@ -44,6 +44,7 @@ export function createDataRetentionFeature() {
|
|
|
44
44
|
name: "retention-cleanup",
|
|
45
45
|
trigger: { maintenance: true },
|
|
46
46
|
perTenant: true,
|
|
47
|
+
includeSystemTenant: true,
|
|
47
48
|
concurrency: "skip",
|
|
48
49
|
escapeHatch: {
|
|
49
50
|
reason: "retention cleanup runs raw deletes and preset lookups; every statement filters by this run's tenantId",
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const DOCUMENTS_BOOT_RULES: {
|
|
2
|
+
readonly negativeExpiringWithinDays: {
|
|
3
|
+
readonly id: "documents/negative-expiring-within-days";
|
|
4
|
+
readonly summary: "expiringWithinDays is not negative.";
|
|
5
|
+
readonly fix: "Pass zero or a positive number.";
|
|
6
|
+
};
|
|
7
|
+
readonly categoryLabelUnknownCategory: {
|
|
8
|
+
readonly id: "documents/category-label-unknown-category";
|
|
9
|
+
readonly summary: "categoryLabels only names categories listed in categories.";
|
|
10
|
+
readonly fix: "Add the category to categories or drop its label.";
|
|
11
|
+
};
|
|
12
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const DOCUMENTS_BOOT_RULES = {
|
|
2
|
+
negativeExpiringWithinDays: {
|
|
3
|
+
id: "documents/negative-expiring-within-days",
|
|
4
|
+
summary: "expiringWithinDays is not negative.",
|
|
5
|
+
fix: "Pass zero or a positive number.",
|
|
6
|
+
},
|
|
7
|
+
categoryLabelUnknownCategory: {
|
|
8
|
+
id: "documents/category-label-unknown-category",
|
|
9
|
+
summary: "categoryLabels only names categories listed in categories.",
|
|
10
|
+
fix: "Add the category to categories or drop its label.",
|
|
11
|
+
},
|
|
12
|
+
};
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
// records through link rows. A document is readable only through a record the viewer can read,
|
|
3
3
|
// and only while the owner of its file is readable too (EntityDefinition.readGate). Documents
|
|
4
4
|
// come from capture rules (a file saved into a configured field) or from the system-only import.
|
|
5
|
-
import { defineEntityCreateHandler, defineEntityDeleteHandler, defineEntityDetailHandler, defineEntityListHandler, defineEntityUpdateHandler, defineFeature, } from "@cosmicdrift/kumiko-framework/engine";
|
|
5
|
+
import { bootRuleError, defineEntityCreateHandler, defineEntityDeleteHandler, defineEntityDetailHandler, defineEntityListHandler, defineEntityUpdateHandler, defineFeature, } from "@cosmicdrift/kumiko-framework/engine";
|
|
6
|
+
import { DOCUMENTS_BOOT_RULES } from "./boot-rules.js";
|
|
6
7
|
import { registerCapture, validateCaptureRules } from "./capture.js";
|
|
7
8
|
import { DEFAULT_ADMIN_ROLES, DEFAULT_DOCUMENT_ACCESS, DEFAULT_EXPIRING_WITHIN_DAYS, DOCUMENT_ENTITY, DOCUMENT_LINK_ENTITY, DOCUMENTS_FEATURE_NAME, } from "./constants.js";
|
|
8
9
|
import { createDocumentEntity, createDocumentLinkEntity, } from "./entity.js";
|
|
@@ -111,11 +112,15 @@ function registerDocuments(r, opts) {
|
|
|
111
112
|
}
|
|
112
113
|
export function createDocumentsFeature(opts) {
|
|
113
114
|
if (opts.expiringWithinDays !== undefined && opts.expiringWithinDays < 0) {
|
|
114
|
-
throw
|
|
115
|
+
throw bootRuleError(DOCUMENTS_BOOT_RULES.negativeExpiringWithinDays, {
|
|
116
|
+
message: "createDocumentsFeature({ expiringWithinDays }) must not be negative.",
|
|
117
|
+
});
|
|
115
118
|
}
|
|
116
119
|
for (const category of Object.keys(opts.categoryLabels ?? {})) {
|
|
117
120
|
if (!opts.categories.includes(category)) {
|
|
118
|
-
throw
|
|
121
|
+
throw bootRuleError(DOCUMENTS_BOOT_RULES.categoryLabelUnknownCategory, {
|
|
122
|
+
message: `createDocumentsFeature({ categoryLabels }) names "${category}", which is not in categories.`,
|
|
123
|
+
});
|
|
119
124
|
}
|
|
120
125
|
}
|
|
121
126
|
return defineFeature(DOCUMENTS_FEATURE_NAME, (r) => registerDocuments(r, opts));
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const FILE_DERIVATIVES_BOOT_RULES: {
|
|
2
|
+
readonly publicTenantResolutionWithoutApexResolver: {
|
|
3
|
+
readonly id: "file-derivatives/public-tenant-resolution-without-apex-resolver";
|
|
4
|
+
readonly summary: "publicTenantResolution is only set together with resolveApexTenant.";
|
|
5
|
+
readonly fix: "Pass resolveApexTenant or drop publicTenantResolution.";
|
|
6
|
+
};
|
|
7
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export const FILE_DERIVATIVES_BOOT_RULES = {
|
|
2
|
+
publicTenantResolutionWithoutApexResolver: {
|
|
3
|
+
id: "file-derivatives/public-tenant-resolution-without-apex-resolver",
|
|
4
|
+
summary: "publicTenantResolution is only set together with resolveApexTenant.",
|
|
5
|
+
fix: "Pass resolveApexTenant or drop publicTenantResolution.",
|
|
6
|
+
},
|
|
7
|
+
};
|
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
// configurable, so this feature has no `r.config` and no
|
|
7
7
|
// `r.extensionSelector`.
|
|
8
8
|
import { cachedResponse, computeRevisionEtag } from "@cosmicdrift/kumiko-framework/api";
|
|
9
|
-
import { defineFeature, EXT_DERIVATIVE_OVERLAY_RESOLVER, EXT_DERIVATIVE_PUBLIC_PREDICATE, EXT_DERIVATIVE_RENDERER, isUuid, } from "@cosmicdrift/kumiko-framework/engine";
|
|
9
|
+
import { bootRuleError, defineFeature, EXT_DERIVATIVE_OVERLAY_RESOLVER, EXT_DERIVATIVE_PUBLIC_PREDICATE, EXT_DERIVATIVE_RENDERER, isUuid, } from "@cosmicdrift/kumiko-framework/engine";
|
|
10
10
|
import { RateLimitError } from "@cosmicdrift/kumiko-framework/errors";
|
|
11
|
+
import { FILE_DERIVATIVES_BOOT_RULES } from "./boot-rules.js";
|
|
11
12
|
import { PUBLIC_VARIANT_QN, publicVariantQuery } from "./handlers/public-variant.query.js";
|
|
12
13
|
import { PUBLIC_VARIANT_BY_FILE_REF_QN, publicVariantByFileRefQuery, } from "./handlers/public-variant-by-file-ref.query.js";
|
|
13
14
|
const FEATURE_NAME = "file-derivatives";
|
|
@@ -42,7 +43,9 @@ const VARIANT_NAME_RE = /^[a-zA-Z0-9_-]{1,64}$/;
|
|
|
42
43
|
export function createFileDerivativesFeature(opts = {}) {
|
|
43
44
|
const basePath = opts.basePath ?? "/media";
|
|
44
45
|
if (opts.publicTenantResolution !== undefined && !opts.resolveApexTenant) {
|
|
45
|
-
throw
|
|
46
|
+
throw bootRuleError(FILE_DERIVATIVES_BOOT_RULES.publicTenantResolutionWithoutApexResolver, {
|
|
47
|
+
message: "createFileDerivativesFeature: publicTenantResolution requires resolveApexTenant — it only changes which tenant a variant is read from, resolveApexTenant still gates the host.",
|
|
48
|
+
});
|
|
46
49
|
}
|
|
47
50
|
return defineFeature(FEATURE_NAME, (r) => {
|
|
48
51
|
r.describe("Declares the `derivativeRenderer` extension point. `ctx.services.derivatives.variant(fileRefId, spec, name)` derives a variant of a tracked FileRef the first time it's requested and reuses the stored result afterwards (derive-on-first-use, keyed by a hash of the spec). Mount at least one `derivatives-*` renderer feature alongside this one — without a registered renderer for the FileRef's MIME type, every `variant(...)` call throws. Also declares the `derivativePublicPredicate` extension point (`r.useExtension(EXT_DERIVATIVE_PUBLIC_PREDICATE, '<entityType>', { isPublic })`) and, when `createFileDerivativesFeature({resolveApexTenant})` is passed a host-resolver, mounts an anonymous `GET {basePath}/:fileRefId/:variant` route that serves any variant name the FileRef's field declared in its `variants` for a FileRef whose entityType has a registered predicate returning true — default-deny (404) otherwise, same as an unknown FileRef or an undeclared variant name. The route's only rate-limit (`per: \"ip\"`) depends on the server's `trustedProxyHops` matching the deployment's actual reverse-proxy count — at the default 0 it ignores `x-forwarded-for` entirely, so every caller shares one bucket until that's configured. `publicTenantResolution: \"fileRef\"` keeps resolveApexTenant as the host gate but reads the variant from the FileRef row's own tenant instead of the host's, so one shared platform host serves every tenant's public variants — each FileRef-tenant's own `isPublic` predicate still default-denies. Also declares the `derivativeOverlayResolver` extension point (`r.useExtension(EXT_DERIVATIVE_OVERLAY_RESOLVER, '<entityType>', { resolve })`), used to turn a variant's `overlays[].dataToken` into the actual QR payload for that FileRef's entityType before the variant is rendered — a variant declaring a `qr` overlay throws at request-time if no resolver is registered for the FileRef's entityType.");
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const FOLDERS_BOOT_RULES: {
|
|
2
|
+
readonly emptyParentsAllowlist: {
|
|
3
|
+
readonly id: "folders/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
|
+
};
|
package/dist/folders/feature.js
CHANGED
|
@@ -14,8 +14,9 @@
|
|
|
14
14
|
// generic entity handlers), set-folder (put/move), clear-folder (unfile).
|
|
15
15
|
// Deferred: reparenting with cycle-check (folder:update CAN change parentId, but
|
|
16
16
|
// no UI exposes it in v1 — folders-view guards cycles defensively).
|
|
17
|
-
import { defineEntityCreateHandler, defineEntityDetailHandler, defineEntityListHandler, defineEntityUpdateHandler, defineFeature, } from "@cosmicdrift/kumiko-framework/engine";
|
|
17
|
+
import { bootRuleError, defineEntityCreateHandler, defineEntityDetailHandler, defineEntityListHandler, defineEntityUpdateHandler, defineFeature, } from "@cosmicdrift/kumiko-framework/engine";
|
|
18
18
|
import { assertNoWhereRuleInOwnershipWrite, resolveFeatureAccess } from "../shared/index.js";
|
|
19
|
+
import { FOLDERS_BOOT_RULES } from "./boot-rules.js";
|
|
19
20
|
import { createFolderAssignmentEntity, folderEntity } from "./entity.js";
|
|
20
21
|
import { createClearFolderHandler } from "./handlers/clear-folder.write.js";
|
|
21
22
|
import { createDeleteFolderHandler } from "./handlers/delete-folder.write.js";
|
|
@@ -75,10 +76,12 @@ export function createFoldersFeature(opts = {}) {
|
|
|
75
76
|
}
|
|
76
77
|
assertNoWhereRuleInOwnershipWrite("createFoldersFeature", opts.ownership?.write);
|
|
77
78
|
if (opts.parents !== undefined && opts.parents.length === 0) {
|
|
78
|
-
throw
|
|
79
|
-
"
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
throw bootRuleError(FOLDERS_BOOT_RULES.emptyParentsAllowlist, {
|
|
80
|
+
message: "createFoldersFeature({ parents }): parents must not be an empty array — " +
|
|
81
|
+
"an empty allowlist rejects every set-folder call and hides every " +
|
|
82
|
+
"assignment row. Omit `parents` to keep every registered entity " +
|
|
83
|
+
"admissible as a host instead.",
|
|
84
|
+
});
|
|
82
85
|
}
|
|
83
86
|
const access = resolveFeatureAccess(opts, DEFAULT_FOLDER_ACCESS);
|
|
84
87
|
return defineFeature(FOLDERS_FEATURE_NAME, (r) => registerFolders(r, access, opts.toggleable, opts.ownership, opts.parents));
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const HELPDESK_BOOT_RULES: {
|
|
2
|
+
readonly invalidProofOfWorkBits: {
|
|
3
|
+
readonly id: "helpdesk/invalid-proof-of-work-bits";
|
|
4
|
+
readonly summary: "spamProtection.proofOfWorkBits is an integer within the allowed range.";
|
|
5
|
+
readonly fix: "Use an integer inside the documented bounds.";
|
|
6
|
+
};
|
|
7
|
+
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { randomBytes } from "node:crypto";
|
|
2
2
|
import * as z from "zod";
|
|
3
|
-
import {
|
|
3
|
+
import { HELPDESK_CHALLENGE_REDIS_PREFIX } from "./web/constants.js";
|
|
4
4
|
const CHALLENGE_BYTES = 16;
|
|
5
5
|
const StoredChallengeSchema = z.object({
|
|
6
6
|
issuedAtMs: z.number().int().nonnegative(),
|
|
7
7
|
bits: z.number().int().positive(),
|
|
8
8
|
});
|
|
9
|
-
const challengeKey = (challenge) => `${
|
|
9
|
+
const challengeKey = (challenge) => `${HELPDESK_CHALLENGE_REDIS_PREFIX}${challenge}`;
|
|
10
10
|
export async function issueChallenge(redis, args) {
|
|
11
11
|
const challenge = randomBytes(CHALLENGE_BYTES).toString("base64url");
|
|
12
12
|
const stored = { issuedAtMs: args.nowMs, bits: args.bits };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const HELPDESK_CLIENT_SOURCE = "(function () {\n \"use strict\";\n\n var QUERY_PATH = \"/api/query\";\n var WRITE_PATH = \"/api/write\";\n var CHALLENGE_QUERY = \"helpdesk:query:challenge\";\n var SUBMIT_WRITE = \"helpdesk:write:submit\";\n var CSRF_COOKIE_NAME = \"kumiko_csrf\";\n var CSRF_HEADER_NAME = \"X-CSRF-Token\";\n var LOCALE_HEADER_NAME = \"X-Locale\";\n var SLICE_MS = 12;\n\n var K = new Uint32Array([\n 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,\n 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,\n 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,\n 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,\n 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,\n 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,\n 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,\n 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2\n ]);\n var H0 = [0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19];\n\n var block = new Uint8Array(64);\n var words = new Uint32Array(64);\n var digest = new Uint32Array(8);\n\n function rotr(x, n) {\n return (x >>> n) | (x << (32 - n));\n }\n\n // One 64-byte block only: challenge, colon and decimal nonce stay far below 56 bytes.\n function sha256Block() {\n var i;\n for (i = 0; i < 16; i++) {\n words[i] = (block[i * 4] << 24) | (block[i * 4 + 1] << 16) | (block[i * 4 + 2] << 8) | block[i * 4 + 3];\n }\n for (i = 16; i < 64; i++) {\n var w15 = words[i - 15];\n var w2 = words[i - 2];\n var s0 = rotr(w15, 7) ^ rotr(w15, 18) ^ (w15 >>> 3);\n var s1 = rotr(w2, 17) ^ rotr(w2, 19) ^ (w2 >>> 10);\n words[i] = (words[i - 16] + s0 + words[i - 7] + s1) | 0;\n }\n var a = H0[0], b = H0[1], c = H0[2], d = H0[3], e = H0[4], f = H0[5], g = H0[6], h = H0[7];\n for (i = 0; i < 64; i++) {\n var t1 = (h + (rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25)) + ((e & f) ^ (~e & g)) + K[i] + words[i]) | 0;\n var t2 = ((rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22)) + ((a & b) ^ (a & c) ^ (b & c))) | 0;\n h = g; g = f; f = e; e = (d + t1) | 0; d = c; c = b; b = a; a = (t1 + t2) | 0;\n }\n digest[0] = (H0[0] + a) | 0; digest[1] = (H0[1] + b) | 0; digest[2] = (H0[2] + c) | 0; digest[3] = (H0[3] + d) | 0;\n digest[4] = (H0[4] + e) | 0; digest[5] = (H0[5] + f) | 0; digest[6] = (H0[6] + g) | 0; digest[7] = (H0[7] + h) | 0;\n }\n\n function hasLeadingZeroBits(bits) {\n var i = 0;\n var remaining = bits;\n while (remaining >= 32) {\n if (digest[i] !== 0) return false;\n i++;\n remaining -= 32;\n }\n if (remaining === 0) return true;\n return (digest[i] >>> (32 - remaining)) === 0;\n }\n\n function solveProofOfWork(challenge, bits) {\n return new Promise(function (resolve, reject) {\n var prefix = challenge + \":\";\n if (prefix.length > 40) {\n reject(new Error(\"challenge too long\"));\n return;\n }\n var i;\n block.fill(0);\n for (i = 0; i < prefix.length; i++) block[i] = prefix.charCodeAt(i);\n var counter = 0;\n\n function step() {\n var deadline = Date.now() + SLICE_MS;\n do {\n var nonce = String(counter);\n var length = prefix.length + nonce.length;\n for (i = 0; i < nonce.length; i++) block[prefix.length + i] = nonce.charCodeAt(i);\n block[length] = 0x80;\n var bitLength = length * 8;\n block[62] = (bitLength >>> 8) & 0xff;\n block[63] = bitLength & 0xff;\n sha256Block();\n if (hasLeadingZeroBits(bits)) {\n resolve(nonce);\n return;\n }\n counter++;\n } while (counter % 256 !== 0 || Date.now() < deadline);\n setTimeout(step, 0);\n }\n step();\n });\n }\n\n function readCsrfToken() {\n var parts = document.cookie.split(\";\");\n for (var i = 0; i < parts.length; i++) {\n var part = parts[i].trim();\n var separator = part.indexOf(\"=\");\n if (separator > 0 && part.slice(0, separator) === CSRF_COOKIE_NAME) {\n return decodeURIComponent(part.slice(separator + 1));\n }\n }\n return undefined;\n }\n\n function pageLocale() {\n var language = (document.documentElement.lang || \"\").toLowerCase().split(\"-\")[0];\n return language === \"de\" ? \"de-DE\" : \"en-US\";\n }\n\n function postJson(path, body) {\n var headers = { \"Content-Type\": \"application/json\" };\n headers[LOCALE_HEADER_NAME] = pageLocale();\n var csrf = readCsrfToken();\n if (csrf !== undefined) headers[CSRF_HEADER_NAME] = csrf;\n return fetch(path, {\n method: \"POST\",\n credentials: \"omit\",\n headers: headers,\n body: JSON.stringify(body)\n }).then(function (response) {\n return response.json().then(\n function (json) { return { status: response.status, response: response, body: json }; },\n function () { return { status: response.status, response: response, body: undefined }; }\n );\n });\n }\n\n function retryAfterOf(result) {\n var header = result.response.headers.get(\"Retry-After\");\n if (header !== null && /^[0-9]+$/.test(header)) return Number(header);\n var error = result.body && result.body.error;\n var seconds = error && error.details && error.details.retryAfterSeconds;\n return typeof seconds === \"number\" ? seconds : undefined;\n }\n\n var pending = null;\n\n function startChallenge() {\n return postJson(QUERY_PATH, { type: CHALLENGE_QUERY, payload: {} }).then(function (result) {\n var data = result.body && result.body.data;\n if (result.status !== 200 || !data || typeof data.challenge !== \"string\") {\n throw new Error(\"challenge failed\");\n }\n var solved = solveProofOfWork(data.challenge, data.bits);\n solved.catch(function () {});\n return { challenge: data.challenge, solved: solved, options: { phone: data.phone, kinds: data.kinds } };\n });\n }\n\n function ensureChallenge() {\n if (pending === null) {\n pending = startChallenge();\n pending.catch(function () { pending = null; });\n }\n return pending;\n }\n\n function load() {\n return ensureChallenge().then(function (state) { return state.options; });\n }\n\n function submit(fields) {\n return ensureChallenge().then(function (state) {\n pending = null;\n return state.solved.then(function (nonce) {\n var payload = {};\n for (var key in fields) {\n if (Object.prototype.hasOwnProperty.call(fields, key)) payload[key] = fields[key];\n }\n payload.challenge = state.challenge;\n payload.nonce = nonce;\n if (payload.locale === undefined) payload.locale = document.documentElement.lang || \"en\";\n return postJson(WRITE_PATH, { type: SUBMIT_WRITE, payload: payload });\n });\n }).then(function (result) {\n if (result.status === 429) {\n var retryAfterSeconds = retryAfterOf(result);\n return retryAfterSeconds === undefined\n ? { kind: \"rate-limited\" }\n : { kind: \"rate-limited\", retryAfterSeconds: retryAfterSeconds };\n }\n if (result.status === 200 && result.body && result.body.isSuccess === true) return { kind: \"sent\" };\n return { kind: \"failed\" };\n }, function () {\n return { kind: \"failed\" };\n });\n }\n\n window.KumikoHelpdesk = { load: load, submit: submit };\n})();\n";
|
package/dist/{contact/client/contact-client-source.js → helpdesk/client/helpdesk-client-source.js}
RENAMED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// The browser client ships as a string so it survives the tsc-only dist build, which copies no
|
|
2
2
|
// loose .js assets. Keep it free of backslashes, backticks and template placeholders.
|
|
3
|
-
export const
|
|
3
|
+
export const HELPDESK_CLIENT_SOURCE = `(function () {
|
|
4
4
|
"use strict";
|
|
5
5
|
|
|
6
6
|
var QUERY_PATH = "/api/query";
|
|
7
7
|
var WRITE_PATH = "/api/write";
|
|
8
|
-
var CHALLENGE_QUERY = "
|
|
9
|
-
var SUBMIT_WRITE = "
|
|
8
|
+
var CHALLENGE_QUERY = "helpdesk:query:challenge";
|
|
9
|
+
var SUBMIT_WRITE = "helpdesk:write:submit";
|
|
10
10
|
var CSRF_COOKIE_NAME = "kumiko_csrf";
|
|
11
11
|
var CSRF_HEADER_NAME = "X-CSRF-Token";
|
|
12
12
|
var LOCALE_HEADER_NAME = "X-Locale";
|
|
@@ -198,6 +198,6 @@ export const CONTACT_CLIENT_SOURCE = `(function () {
|
|
|
198
198
|
});
|
|
199
199
|
}
|
|
200
200
|
|
|
201
|
-
window.
|
|
201
|
+
window.KumikoHelpdesk = { load: load, submit: submit };
|
|
202
202
|
})();
|
|
203
203
|
`;
|