@cosmicdrift/kumiko-samples 0.410.0 → 0.412.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/packages/bundled-features/package.json +31 -1
- package/packages/bundled-features/src/agent-tools/agent-doc-lint.ts +64 -3
- package/packages/bundled-features/src/agent-tools/agent-manifest.ts +13 -130
- package/packages/bundled-features/src/agent-tools/api-docs/anchors.ts +60 -0
- package/packages/bundled-features/src/agent-tools/api-docs/check.ts +25 -0
- package/packages/bundled-features/src/agent-tools/api-docs/collect-events.ts +140 -0
- package/packages/bundled-features/src/agent-tools/api-docs/collect.ts +175 -0
- package/packages/bundled-features/src/agent-tools/api-docs/curl.ts +28 -0
- package/packages/bundled-features/src/agent-tools/api-docs/error-table.ts +45 -0
- package/packages/bundled-features/src/agent-tools/api-docs/examples.ts +43 -0
- package/packages/bundled-features/src/agent-tools/api-docs/generate.ts +179 -0
- package/packages/bundled-features/src/agent-tools/api-docs/index-json.ts +29 -0
- package/packages/bundled-features/src/agent-tools/api-docs/index.ts +21 -0
- package/packages/bundled-features/src/agent-tools/api-docs/list-parameters.ts +38 -0
- package/packages/bundled-features/src/agent-tools/api-docs/markdown.ts +70 -0
- package/packages/bundled-features/src/agent-tools/api-docs/menu-path.ts +82 -0
- package/packages/bundled-features/src/agent-tools/api-docs/model.ts +83 -0
- package/packages/bundled-features/src/agent-tools/api-docs/problems.ts +58 -0
- package/packages/bundled-features/src/agent-tools/api-docs/render-events.ts +76 -0
- package/packages/bundled-features/src/agent-tools/api-docs/render-openapi.ts +216 -0
- package/packages/bundled-features/src/agent-tools/api-docs/render-overview.ts +86 -0
- package/packages/bundled-features/src/agent-tools/api-docs/render-reference.ts +79 -0
- package/packages/bundled-features/src/agent-tools/api-docs/render-tokens.ts +136 -0
- package/packages/bundled-features/src/agent-tools/api-docs/schema-fields.ts +167 -0
- package/packages/bundled-features/src/agent-tools/api-docs/section-ids.ts +28 -0
- package/packages/bundled-features/src/agent-tools/api-docs/system-only.ts +11 -0
- package/packages/bundled-features/src/agent-tools/api-docs/texts/de.ts +166 -0
- package/packages/bundled-features/src/agent-tools/api-docs/texts/en.ts +159 -0
- package/packages/bundled-features/src/agent-tools/api-docs/texts/es.ts +162 -0
- package/packages/bundled-features/src/agent-tools/api-docs/texts/fr.ts +169 -0
- package/packages/bundled-features/src/agent-tools/api-docs/texts/index.ts +67 -0
- package/packages/bundled-features/src/agent-tools/api-docs/texts/it.ts +165 -0
- package/packages/bundled-features/src/agent-tools/api-docs/texts/types.ts +130 -0
- package/packages/bundled-features/src/agent-tools/api-docs/ui-writes.ts +81 -0
- package/packages/bundled-features/src/agent-tools/changes.json +24 -0
- package/packages/bundled-features/src/agent-tools/handler-schema.ts +45 -0
- package/packages/bundled-features/src/agent-tools/index.ts +24 -0
- package/packages/bundled-features/src/agent-tools/labels.ts +181 -0
- package/packages/bundled-features/src/auth-email-password/changes.json +24 -0
- package/packages/bundled-features/src/auth-email-password/seeding.ts +84 -6
- package/packages/bundled-features/src/auth-email-password/web/i18n.ts +1 -0
- package/packages/bundled-features/src/auth-email-password/web/signup-screen.tsx +48 -3
- package/packages/bundled-features/src/auth-email-password/web/static-account.ts +190 -0
- package/packages/bundled-features/src/auth-email-password/web/static-client.ts +226 -0
- package/packages/bundled-features/src/foundation-shared/demo-admin-env.ts +11 -0
- package/packages/bundled-features/src/foundation-shared/index.ts +5 -1
- package/packages/bundled-features/src/inbound-mail-foundation/changes.json +6 -0
- package/packages/bundled-features/src/inbound-mail-foundation/entities.ts +99 -71
- package/packages/bundled-features/src/inbound-mail-foundation/feature.ts +2 -2
- package/packages/bundled-features/src/inbound-provider-imap/changes.json +6 -0
- package/packages/bundled-features/src/inbound-provider-imap/imap-client.ts +3 -1
- package/packages/bundled-features/src/personal-access-tokens/changes.json +6 -0
- package/packages/bundled-features/src/personal-access-tokens/feature.ts +5 -2
- package/packages/bundled-features/src/personal-access-tokens/handlers/create.write.ts +7 -2
- package/packages/bundled-features/src/personal-access-tokens/i18n.ts +6 -1
- package/packages/bundled-features/src/personal-access-tokens/index.ts +37 -2
- package/packages/bundled-features/src/personal-access-tokens/scope-events-check.ts +28 -0
- package/packages/bundled-features/src/personal-access-tokens/screens.ts +9 -1
- package/packages/bundled-features/src/personal-access-tokens/web/constants.ts +1 -0
- package/packages/bundled-features/src/personal-access-tokens/web/scopes.ts +14 -0
- package/packages/bundled-features/src/presence/changes.json +8 -0
- package/packages/bundled-features/src/presence/feature.ts +25 -0
- package/packages/bundled-features/src/presence/handlers/heartbeat.write.ts +52 -0
- package/packages/bundled-features/src/presence/handlers/leave.write.ts +41 -0
- package/packages/bundled-features/src/presence/handlers/list.query.ts +39 -0
- package/packages/bundled-features/src/presence/index.ts +7 -0
- package/packages/bundled-features/src/presence/options.ts +30 -0
- package/packages/bundled-features/src/presence/payloads.ts +26 -0
- package/packages/bundled-features/src/presence/room.ts +65 -0
- package/packages/bundled-features/src/presence/store.ts +185 -0
- package/packages/bundled-features/src/sessions/feature.ts +6 -2
- package/packages/bundled-features/src/sessions/handlers/last-activity-probe.route.ts +19 -0
- package/packages/bundled-features/src/tenant-inactivity/changes.json +12 -0
- package/packages/bundled-features/src/tenant-inactivity/check-inactive-tenants.ts +14 -6
- package/packages/bundled-features/src/tenant-inactivity/constants.ts +4 -1
- package/packages/bundled-features/src/tenant-inactivity/handlers/inactivity-state.query.ts +2 -1
- package/packages/bundled-features/src/tenant-inactivity/handlers/keep-account.write.ts +2 -1
- package/packages/bundled-features/src/tenant-inactivity/options.ts +1 -0
- package/packages/bundled-features/src/tenant-inactivity/remote-activity.ts +6 -1
- package/packages/bundled-features/src/tenant-inactivity/static-keep-account.ts +37 -0
- package/packages/bundled-features/src/tenant-lifecycle/constants.ts +2 -0
- package/packages/bundled-features/src/tenant-lifecycle/handlers/cancel-destruction.write.ts +6 -2
- package/packages/bundled-features/src/tenant-lifecycle/handlers/request-destruction.write.ts +2 -1
- package/packages/bundled-features/src/tenant-lifecycle/index.ts +1 -0
- package/packages/bundled-features/src/waitlist/changes.json +6 -0
- package/packages/bundled-features/src/waitlist/static-submit.ts +56 -0
- package/samples/apps/styleguide/src/features/widgets/i18n.ts +143 -0
- package/samples/apps/styleguide/src/features/widgets/web/VariantsDemo.tsx +276 -0
- package/samples/apps/styleguide/src/features/widgets/web/Widgets.tsx +3 -0
- package/samples/apps/styleguide/src/features/workboard/feature.ts +1 -0
- package/samples/apps/use-all-bundled/feature-manifest.json +23 -1
- package/samples/apps/use-all-bundled/src/run-config.ts +3 -0
- package/samples/recipes/api-docs/README.md +52 -0
- package/samples/recipes/api-docs/api-docs/de/events.md +62 -0
- package/samples/recipes/api-docs/api-docs/de/overview.md +100 -0
- package/samples/recipes/api-docs/api-docs/de/reference/tickets.md +305 -0
- package/samples/recipes/api-docs/api-docs/de/tokens.md +66 -0
- package/samples/recipes/api-docs/api-docs/en/events.md +62 -0
- package/samples/recipes/api-docs/api-docs/en/overview.md +100 -0
- package/samples/recipes/api-docs/api-docs/en/reference/tickets.md +305 -0
- package/samples/recipes/api-docs/api-docs/en/tokens.md +66 -0
- package/samples/recipes/api-docs/api-docs/index.json +371 -0
- package/samples/recipes/api-docs/api-docs/openapi.json +982 -0
- package/samples/recipes/api-docs/api-examples/ticket-close.json +21 -0
- package/samples/recipes/api-docs/api-examples/ticket-create.json +42 -0
- package/samples/recipes/api-docs/api-examples/ticket-detail.json +28 -0
- package/samples/recipes/api-docs/api-examples/ticket-list.json +31 -0
- package/samples/recipes/api-docs/api-examples/ticket-update.json +54 -0
- package/samples/recipes/api-docs/api-examples/webhooks/ticket-closed.json +8 -0
- package/samples/recipes/api-docs/api-examples/webhooks/ticket-created.json +10 -0
- package/samples/recipes/api-docs/kumiko.config.ts +33 -0
- package/samples/recipes/api-docs/package.json +14 -0
- package/samples/recipes/api-docs/src/feature.ts +218 -0
- package/samples/recipes/api-docs/tsconfig.json +22 -0
- package/samples/recipes/realtime-sse/README.md +1 -0
- package/samples/recipes/realtime-sse/package.json +1 -0
- package/samples/recipes/realtime-sse/src/feature.ts +9 -0
- package/samples/recipes/record-detail-layout/README.md +1 -0
- package/samples/recipes/record-detail-layout/src/feature.ts +10 -0
- package/samples/recipes/wizard-form/README.md +9 -0
- package/samples/recipes/wizard-form/src/feature.ts +13 -2
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
// DOM-free request core for the static clients (plain Astro scripts): fetch plus pure logic only.
|
|
2
|
+
// It must not import the renderer, React or anything that touches `window` at import time.
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
CSRF_COOKIE_BASE,
|
|
6
|
+
sessionCookieNameCandidates,
|
|
7
|
+
} from "@cosmicdrift/kumiko-types/session-cookies";
|
|
8
|
+
import { propertyOf } from "@cosmicdrift/kumiko-types/type-guards";
|
|
9
|
+
import {
|
|
10
|
+
failureFromErrorField,
|
|
11
|
+
isRecord,
|
|
12
|
+
type KnownLoginFailureReason,
|
|
13
|
+
parseRetryAfterSeconds,
|
|
14
|
+
} from "./login-failure.ts";
|
|
15
|
+
|
|
16
|
+
export const STATIC_NETWORK_REASON = "network";
|
|
17
|
+
export const STATIC_RATE_LIMITED_REASON = "rate_limited" satisfies KnownLoginFailureReason;
|
|
18
|
+
export const STATIC_UNKNOWN_REASON = "unknown";
|
|
19
|
+
export const STATIC_UNAUTHENTICATED_REASON = "unauthenticated";
|
|
20
|
+
// A mail client that cuts the link short sends a token below the schema's minimum length; pages
|
|
21
|
+
// show that as the invalid-link state, not as a generic failure.
|
|
22
|
+
export const STATIC_MALFORMED_TOKEN_REASON = "malformed_token";
|
|
23
|
+
|
|
24
|
+
export type StaticFailure = {
|
|
25
|
+
readonly kind: "failure";
|
|
26
|
+
readonly reason: KnownLoginFailureReason | (string & {});
|
|
27
|
+
readonly message?: string;
|
|
28
|
+
readonly retryAfterSeconds?: number;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type StaticSuccess<TData> = { readonly kind: "success"; readonly data: TData };
|
|
32
|
+
|
|
33
|
+
export type StaticResult<TData> = StaticSuccess<TData> | StaticFailure;
|
|
34
|
+
|
|
35
|
+
export type StaticRequestOptions = {
|
|
36
|
+
/** Sent as `X-Locale`, which picks the language of mails the request triggers. */
|
|
37
|
+
readonly locale?: string;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const CSRF_HEADER_NAME = "X-CSRF-Token";
|
|
41
|
+
const LOCALE_HEADER_NAME = "X-Locale";
|
|
42
|
+
const WRITE_PATH = "/api/write";
|
|
43
|
+
const QUERY_PATH = "/api/query";
|
|
44
|
+
|
|
45
|
+
export function staticFailure(
|
|
46
|
+
reason: string,
|
|
47
|
+
extras: { readonly message?: string; readonly retryAfterSeconds?: number } = {},
|
|
48
|
+
): StaticFailure {
|
|
49
|
+
return {
|
|
50
|
+
kind: "failure",
|
|
51
|
+
reason,
|
|
52
|
+
...(extras.message !== undefined && { message: extras.message }),
|
|
53
|
+
...(extras.retryAfterSeconds !== undefined && { retryAfterSeconds: extras.retryAfterSeconds }),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function staticSuccess<TData>(data: TData): StaticSuccess<TData> {
|
|
58
|
+
return { kind: "success", data };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function readDocumentCookie(): string {
|
|
62
|
+
const cookie = propertyOf(propertyOf(globalThis, "document"), "cookie");
|
|
63
|
+
return typeof cookie === "string" ? cookie : "";
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// A malformed escape in a foreign cookie must not break the request; it just carries no CSRF header.
|
|
67
|
+
function decodeURIComponentOrNull(value: string): string | null {
|
|
68
|
+
try {
|
|
69
|
+
return decodeURIComponent(value);
|
|
70
|
+
} catch {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Anonymous visitors have no CSRF cookie and send no header; a visitor who is signed in on the
|
|
76
|
+
// same origin (invite acceptance) echoes it like the SPA does.
|
|
77
|
+
export function csrfHeaderFromCookie(cookieSource: string): Record<string, string> {
|
|
78
|
+
const valuesByName = new Map<string, string>();
|
|
79
|
+
for (const pair of cookieSource.split(/;\s*/)) {
|
|
80
|
+
const eq = pair.indexOf("=");
|
|
81
|
+
if (eq < 0) continue;
|
|
82
|
+
const name = pair.slice(0, eq);
|
|
83
|
+
if (!valuesByName.has(name)) valuesByName.set(name, pair.slice(eq + 1));
|
|
84
|
+
}
|
|
85
|
+
for (const name of sessionCookieNameCandidates(CSRF_COOKIE_BASE)) {
|
|
86
|
+
const value = valuesByName.get(name);
|
|
87
|
+
if (value !== undefined && value.length > 0) {
|
|
88
|
+
const decoded = decodeURIComponentOrNull(value);
|
|
89
|
+
if (decoded !== null) return { [CSRF_HEADER_NAME]: decoded };
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return {};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function failsOnlyOnToken(error: unknown): boolean {
|
|
96
|
+
if (!isRecord(error) || error["code"] !== "validation_error") return false;
|
|
97
|
+
const details = error["details"];
|
|
98
|
+
const fields = isRecord(details) ? details["fields"] : undefined;
|
|
99
|
+
return (
|
|
100
|
+
Array.isArray(fields) &&
|
|
101
|
+
fields.length > 0 &&
|
|
102
|
+
fields.every((field) => isRecord(field) && field["path"] === "token")
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function failureFromBody(body: Record<string, unknown>): StaticFailure {
|
|
107
|
+
const error = body["error"];
|
|
108
|
+
if (failsOnlyOnToken(error)) return staticFailure(STATIC_MALFORMED_TOKEN_REASON);
|
|
109
|
+
const { reason, message, retryAfterSeconds } = failureFromErrorField(
|
|
110
|
+
error,
|
|
111
|
+
STATIC_UNKNOWN_REASON,
|
|
112
|
+
);
|
|
113
|
+
return staticFailure(reason, { message, retryAfterSeconds });
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Mirrors the 401 members of `MiddlewareRejectCode` in framework/src/api/auth-middleware.ts
|
|
117
|
+
// (not exported there, and the server must not be imported into browser code).
|
|
118
|
+
const SIGNED_OUT_REASONS: ReadonlySet<string> = new Set([
|
|
119
|
+
STATIC_UNAUTHENTICATED_REASON,
|
|
120
|
+
"missing_token",
|
|
121
|
+
"invalid_token",
|
|
122
|
+
"session_invalid",
|
|
123
|
+
]);
|
|
124
|
+
|
|
125
|
+
/** True when the server says there is no usable session; wrong credentials are not signed-out. */
|
|
126
|
+
export function isSignedOutFailure(result: StaticResult<unknown>): boolean {
|
|
127
|
+
return result.kind === "failure" && SIGNED_OUT_REASONS.has(result.reason);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async function readJsonRecord(res: Response): Promise<Record<string, unknown>> {
|
|
131
|
+
const parsed: unknown = await res.json().catch(() => ({}));
|
|
132
|
+
return isRecord(parsed) ? parsed : {};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export async function postJson(
|
|
136
|
+
path: string,
|
|
137
|
+
payload: Record<string, unknown>,
|
|
138
|
+
options: StaticRequestOptions = {},
|
|
139
|
+
): Promise<StaticResult<Record<string, unknown>>> {
|
|
140
|
+
let res: Response;
|
|
141
|
+
try {
|
|
142
|
+
res = await fetch(path, {
|
|
143
|
+
method: "POST",
|
|
144
|
+
credentials: "same-origin",
|
|
145
|
+
headers: {
|
|
146
|
+
"Content-Type": "application/json",
|
|
147
|
+
...(options.locale !== undefined && { [LOCALE_HEADER_NAME]: options.locale }),
|
|
148
|
+
...csrfHeaderFromCookie(readDocumentCookie()),
|
|
149
|
+
},
|
|
150
|
+
body: JSON.stringify(payload),
|
|
151
|
+
});
|
|
152
|
+
} catch {
|
|
153
|
+
return staticFailure(STATIC_NETWORK_REASON);
|
|
154
|
+
}
|
|
155
|
+
const body = await readJsonRecord(res);
|
|
156
|
+
if (res.status === 429) {
|
|
157
|
+
const fromBody = failureFromBody(body).retryAfterSeconds;
|
|
158
|
+
const retryAfterSeconds = parseRetryAfterSeconds(res.headers.get("Retry-After")) ?? fromBody;
|
|
159
|
+
return staticFailure(STATIC_RATE_LIMITED_REASON, { retryAfterSeconds });
|
|
160
|
+
}
|
|
161
|
+
if (!res.ok || body["isSuccess"] === false) {
|
|
162
|
+
const failure = failureFromBody(body);
|
|
163
|
+
// Session-less calls to session-only routes may answer 401 without a usable code.
|
|
164
|
+
return res.status === 401 && failure.reason === STATIC_UNKNOWN_REASON
|
|
165
|
+
? staticFailure(STATIC_UNAUTHENTICATED_REASON, {
|
|
166
|
+
message: failure.message,
|
|
167
|
+
retryAfterSeconds: failure.retryAfterSeconds,
|
|
168
|
+
})
|
|
169
|
+
: failure;
|
|
170
|
+
}
|
|
171
|
+
return staticSuccess(body);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export async function dispatchWrite(
|
|
175
|
+
type: string,
|
|
176
|
+
payload: Record<string, unknown>,
|
|
177
|
+
options?: StaticRequestOptions,
|
|
178
|
+
): Promise<StaticResult<unknown>> {
|
|
179
|
+
const result = await postJson(WRITE_PATH, { type, payload }, options);
|
|
180
|
+
return result.kind === "success" ? staticSuccess(result.data["data"]) : result;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export async function dispatchQuery(
|
|
184
|
+
type: string,
|
|
185
|
+
payload: Record<string, unknown>,
|
|
186
|
+
options?: StaticRequestOptions,
|
|
187
|
+
): Promise<StaticResult<unknown>> {
|
|
188
|
+
const result = await postJson(QUERY_PATH, { type, payload }, options);
|
|
189
|
+
return result.kind === "success" ? staticSuccess(result.data["data"]) : result;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export type UrlTokenSource = "query" | "fragment";
|
|
193
|
+
|
|
194
|
+
export const URL_TOKEN_PARAM = "token";
|
|
195
|
+
|
|
196
|
+
function paramsOf(url: URL, source: UrlTokenSource): URLSearchParams {
|
|
197
|
+
return source === "query" ? url.searchParams : new URLSearchParams(url.hash.replace(/^#/, ""));
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export function readUrlToken(href: string, source: UrlTokenSource): string {
|
|
201
|
+
return paramsOf(new URL(href), source).get(URL_TOKEN_PARAM) ?? "";
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Single-use tokens must not linger in history or the Referer once the page has read them.
|
|
205
|
+
export function hrefWithoutUrlToken(href: string, source: UrlTokenSource): string {
|
|
206
|
+
const url = new URL(href);
|
|
207
|
+
const params = paramsOf(url, source);
|
|
208
|
+
if (!params.has(URL_TOKEN_PARAM)) return href;
|
|
209
|
+
params.delete(URL_TOKEN_PARAM);
|
|
210
|
+
if (source === "query") {
|
|
211
|
+
url.search = params.toString();
|
|
212
|
+
} else {
|
|
213
|
+
const rest = params.toString();
|
|
214
|
+
url.hash = rest === "" ? "" : `#${rest}`;
|
|
215
|
+
}
|
|
216
|
+
return url.toString();
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** Reads the token from the current page and removes it from the address bar. Browser only. */
|
|
220
|
+
export function takeUrlToken(source: UrlTokenSource): string {
|
|
221
|
+
const href = window.location.href;
|
|
222
|
+
const token = readUrlToken(href, source);
|
|
223
|
+
const scrubbed = hrefWithoutUrlToken(href, source);
|
|
224
|
+
if (scrubbed !== href) window.history.replaceState(null, "", scrubbed);
|
|
225
|
+
return token;
|
|
226
|
+
}
|
|
@@ -22,3 +22,14 @@ export const demoAdminEnvSchema = z.object({
|
|
|
22
22
|
DEMO_SYSADMIN_PASSWORD: seedPassword("Password of the seeded SystemAdmin."),
|
|
23
23
|
DEMO_TENANT_ID: z.uuid().optional().describe("Id of the seeded demo tenant. Default: generated."),
|
|
24
24
|
});
|
|
25
|
+
|
|
26
|
+
export const BOOTSTRAP_ADMIN_EMAIL_ENV = "KUMIKO_BOOTSTRAP_ADMIN_EMAIL";
|
|
27
|
+
|
|
28
|
+
export const bootstrapAdminEnvSchema = z.object({
|
|
29
|
+
[BOOTSTRAP_ADMIN_EMAIL_ENV]: z
|
|
30
|
+
.email()
|
|
31
|
+
.optional()
|
|
32
|
+
.describe(
|
|
33
|
+
"Login of the person who created the app; the first start makes it the admin without a password, set via password reset.",
|
|
34
|
+
),
|
|
35
|
+
});
|
|
@@ -3,7 +3,11 @@
|
|
|
3
3
|
|
|
4
4
|
export { buildInfoEnvSchema } from "./build-info-env.ts";
|
|
5
5
|
export { requireDefined, requireNonEmpty, requireSecretSet } from "./config-helpers.ts";
|
|
6
|
-
export {
|
|
6
|
+
export {
|
|
7
|
+
BOOTSTRAP_ADMIN_EMAIL_ENV,
|
|
8
|
+
bootstrapAdminEnvSchema,
|
|
9
|
+
demoAdminEnvSchema,
|
|
10
|
+
} from "./demo-admin-env.ts";
|
|
7
11
|
export { isHostAllowlisted, readHostAllowlistFromEnv } from "./host-allowlist.ts";
|
|
8
12
|
export { sanitizeMailDisplayName } from "./mail-display-name.ts";
|
|
9
13
|
export {
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"version": "0.412.0",
|
|
4
|
+
"type": "fix",
|
|
5
|
+
"title": "documents filed from a mail attachment are visible to whoever may read the mail",
|
|
6
|
+
"detail": "The `inbound-message` read model now declares `access.read` for the member roles: shared mailboxes are readable by every member, a personal mailbox only by its owner, admins included. `createInboundMessageEntity(memberRoles)` builds the entity for the configured roles; `inboundMessageEntity` stays exported with the default roles. The message queries filter rows as before and do not use this rule."
|
|
7
|
+
},
|
|
2
8
|
{
|
|
3
9
|
"version": "0.409.0",
|
|
4
10
|
"type": "fix",
|
|
@@ -1,5 +1,5 @@
|
|
|
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 {
|
|
4
4
|
access,
|
|
5
5
|
createBooleanField,
|
|
@@ -10,6 +10,8 @@ import {
|
|
|
10
10
|
createTextField,
|
|
11
11
|
createTimestampField,
|
|
12
12
|
} from "@cosmicdrift/kumiko-framework/engine";
|
|
13
|
+
import type { OwnershipMap, OwnershipRule } from "@cosmicdrift/kumiko-types/ownership";
|
|
14
|
+
import { DEFAULT_INBOUND_MAIL_ADMIN_ROLES, DEFAULT_INBOUND_MAIL_USER_ROLES } from "./mail-roles.ts";
|
|
13
15
|
|
|
14
16
|
// ============================================================================
|
|
15
17
|
// Read models for the three event-sourced aggregates
|
|
@@ -80,79 +82,105 @@ export const mailAccountEntity = createEntity({
|
|
|
80
82
|
},
|
|
81
83
|
});
|
|
82
84
|
|
|
85
|
+
// Mirrors isVisibleToCaller (handlers/scope-visibility.ts) for the roles of the detail query:
|
|
86
|
+
// shared rows and the caller's own personal mailbox, no admin exception. The read gate of other
|
|
87
|
+
// entities (readGate.fileOwner) reads it; the hand-written message queries do not apply it.
|
|
88
|
+
function ownMailboxOrSharedRead(memberRoles: readonly string[]): OwnershipMap {
|
|
89
|
+
const rule: OwnershipRule = {
|
|
90
|
+
kind: "where",
|
|
91
|
+
where: (user, ctx) => {
|
|
92
|
+
const owner = `"${ctx.tableName}"."${physicalColumnName(ctx.table, "ownerUserId")}"`;
|
|
93
|
+
return {
|
|
94
|
+
sqlText: `(${owner} IS NULL OR ${owner} = '' OR ${owner} = $${ctx.paramStart})`,
|
|
95
|
+
params: [user.id],
|
|
96
|
+
};
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
return Object.fromEntries(memberRoles.map((role) => [role, rule]));
|
|
100
|
+
}
|
|
101
|
+
|
|
83
102
|
/** An incoming mail (envelope + snippet, NO body — bodyRef
|
|
84
103
|
* points to file-foundation). PK = aggregateId =
|
|
85
104
|
* inboundMessageAggregateId(accountId, providerMessageId). */
|
|
86
|
-
export
|
|
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
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
105
|
+
export function createInboundMessageEntity(memberRoles: readonly string[]) {
|
|
106
|
+
return createEntity({
|
|
107
|
+
access: { read: ownMailboxOrSharedRead(memberRoles) },
|
|
108
|
+
table: "read_inbound_messages",
|
|
109
|
+
fields: {
|
|
110
|
+
accountId: createTextField({
|
|
111
|
+
required: true,
|
|
112
|
+
maxLength: 36,
|
|
113
|
+
personal: false,
|
|
114
|
+
reason: "technical_reference",
|
|
115
|
+
}),
|
|
116
|
+
// Scope is inherited from the account at ingest time: messages from a
|
|
117
|
+
// personal mailbox are visible only to the owner, without joining read_mail_accounts.
|
|
118
|
+
ownerUserId: createTextField({ maxLength: 36, personal: false, reason: "pseudonymous_fk" }),
|
|
119
|
+
messageIdHeader: createTextField({
|
|
120
|
+
required: true,
|
|
121
|
+
maxLength: 500,
|
|
122
|
+
personal: false,
|
|
123
|
+
reason: "technical_reference",
|
|
124
|
+
}),
|
|
125
|
+
threadKey: createTextField({
|
|
126
|
+
required: true,
|
|
127
|
+
maxLength: 500,
|
|
128
|
+
personal: false,
|
|
129
|
+
reason: "technical_reference",
|
|
130
|
+
}),
|
|
131
|
+
from: createTextField({ required: true, maxLength: 2000, personal: "tenant", find: "none" }),
|
|
132
|
+
// JSON-stringified string[] — als Ganzes encrypted.
|
|
133
|
+
to: createTextField({ maxLength: 8000, personal: "tenant", find: "none" }),
|
|
134
|
+
cc: createTextField({ maxLength: 8000, personal: "tenant", find: "none" }),
|
|
135
|
+
subject: createTextField({ maxLength: 4000, personal: "tenant", find: "none" }),
|
|
136
|
+
snippet: createTextField({ maxLength: 4000, personal: "tenant", find: "none" }),
|
|
137
|
+
receivedAt: createTimestampField({ required: true }),
|
|
138
|
+
bodyRef: createTextField({ maxLength: 500, personal: false, reason: "technical_reference" }),
|
|
139
|
+
scope: createTextField({ maxLength: 200, personal: false, reason: "technical_reference" }),
|
|
140
|
+
// Full plaintext, capped at 32_000 characters before encryption (ciphertext is ~2.3x plus envelope).
|
|
141
|
+
// Null on rows from before the column; list-messages never selects it.
|
|
142
|
+
bodyText: createLongTextField({ maxLength: 200_000, personal: "tenant", find: "none" }),
|
|
143
|
+
bodyTextTruncated: createBooleanField(),
|
|
144
|
+
// Sanitized HTML of the mail (sanitizeInboundHtml), null when the mail has none or it was too large.
|
|
145
|
+
bodyHtml: createLongTextField({ maxLength: 500_000, personal: "tenant", find: "none" }),
|
|
146
|
+
// Bound to the message (entityType = the aggregate type), so the file guard answers with the
|
|
147
|
+
// mail's visibility. The fileRefs are bound at ingest, the projection copies the ids.
|
|
148
|
+
attachmentFileIds: createFilesField({ personal: false, reason: "technical_reference" }),
|
|
149
|
+
// JSON-stringified SkippedInboundAttachment[]: nullable JSON stays a text column
|
|
150
|
+
// (jsonb fields are NOT NULL), like to/cc.
|
|
151
|
+
skippedAttachments: createTextField({
|
|
152
|
+
maxLength: 20_000,
|
|
153
|
+
personal: false,
|
|
154
|
+
reason: "technical_reference",
|
|
155
|
+
}),
|
|
156
|
+
// JSON-stringified SenderAuthentication or "null"; a SQL null (rows from before the column) reads as null.
|
|
157
|
+
senderAuthentication: createTextField({
|
|
158
|
+
maxLength: 4000,
|
|
159
|
+
personal: false,
|
|
160
|
+
reason: "technical_reference",
|
|
161
|
+
}),
|
|
162
|
+
// "complete" | "snippet" | "unavailable"; null counts as "snippet".
|
|
163
|
+
contentState: createTextField({
|
|
164
|
+
maxLength: 20,
|
|
165
|
+
personal: false,
|
|
166
|
+
reason: "technical_reference",
|
|
167
|
+
}),
|
|
168
|
+
// One of INBOUND_CONTENT_UNAVAILABLE_REASONS; null while the content is there or not yet missing.
|
|
169
|
+
contentUnavailableReason: createTextField({
|
|
170
|
+
maxLength: 30,
|
|
171
|
+
personal: false,
|
|
172
|
+
reason: "technical_reference",
|
|
173
|
+
}),
|
|
174
|
+
},
|
|
175
|
+
attachedFileAccess: "record-only",
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Same fields for every role set; table and PII lists do not depend on the roles.
|
|
180
|
+
export const inboundMessageEntity = createInboundMessageEntity([
|
|
181
|
+
...DEFAULT_INBOUND_MAIL_ADMIN_ROLES,
|
|
182
|
+
...DEFAULT_INBOUND_MAIL_USER_ROLES,
|
|
183
|
+
]);
|
|
156
184
|
|
|
157
185
|
/** Thread-Rollup. PK = aggregateId = mailThreadAggregateId(tenantId,
|
|
158
186
|
* threadKey). */
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
import { defineFeature, EXT_TENANT_DATA } from "@cosmicdrift/kumiko-framework/engine";
|
|
25
25
|
import { INBOUND_MAIL_FOUNDATION_FEATURE, INBOUND_MAIL_PROVIDER_EXTENSION } from "./constants.ts";
|
|
26
26
|
import {
|
|
27
|
-
|
|
27
|
+
createInboundMessageEntity,
|
|
28
28
|
mailAccountEntity,
|
|
29
29
|
mailThreadEntity,
|
|
30
30
|
seenMessageTable,
|
|
@@ -208,7 +208,7 @@ export function createInboundMailFoundationFeature(options: InboundMailRoleOptio
|
|
|
208
208
|
name: "inbound-message",
|
|
209
209
|
source: INBOUND_MESSAGE_AGGREGATE_TYPE,
|
|
210
210
|
table: inboundMessagesProjectionTable,
|
|
211
|
-
entity:
|
|
211
|
+
entity: createInboundMessageEntity(roles.memberRoles),
|
|
212
212
|
apply: {
|
|
213
213
|
[INBOUND_MESSAGE_RECEIVED_EVENT_QN]: applyInboundMessageReceived,
|
|
214
214
|
[INBOUND_MESSAGE_CONTENT_FETCHED_EVENT_QN]: applyInboundMessageContentFetched,
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"version": "0.411.0",
|
|
4
|
+
"type": "fix",
|
|
5
|
+
"title": "IMAP polling works again for mailboxes given as a host name",
|
|
6
|
+
"detail": "Since 0.393 the host guard resolves every host name to its IP, and the IMAP client then overrode the TLS `servername` with undefined, so the certificate was checked against the IP and every poll ended in InboundTransientError. The pinned host name now goes to tls as the servername; IP-literal hosts still connect without SNI. SMTP was not affected: nodemailer receives the original name as `servername`."
|
|
7
|
+
},
|
|
2
8
|
{
|
|
3
9
|
"version": "0.395.0",
|
|
4
10
|
"type": "fix",
|
|
@@ -90,6 +90,8 @@ export async function createImapClient(
|
|
|
90
90
|
// ("servername argument must be an string"). Overriding it through `tls` with undefined makes the
|
|
91
91
|
// socket connect without SNI; the certificate is still verified against the IP. Not setting the
|
|
92
92
|
// option at all (as for SMTP, where nodemailer omits a falsy servername) does not help here.
|
|
93
|
+
// A host pinned to its resolved IP carries the original name, which must reach tls as the SNI name
|
|
94
|
+
// and certificate identity instead of being blanked.
|
|
93
95
|
export function imapClientOptions(
|
|
94
96
|
doc: ImapCredentialDocument,
|
|
95
97
|
target: Awaited<ReturnType<typeof resolveMailConnectTarget>>,
|
|
@@ -99,7 +101,7 @@ export function imapClientOptions(
|
|
|
99
101
|
port: doc.port,
|
|
100
102
|
secure: doc.secure,
|
|
101
103
|
...(target.servername && { servername: target.servername }),
|
|
102
|
-
...(isIP(target.host) !== 0 && { tls: { servername:
|
|
104
|
+
...(isIP(target.host) !== 0 && { tls: { servername: target.servername } }),
|
|
103
105
|
auth: doc.password
|
|
104
106
|
? { user: doc.user, pass: doc.password }
|
|
105
107
|
: { user: doc.user, accessToken: doc.accessToken as string },
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"version": "0.412.0",
|
|
4
|
+
"type": "improvement",
|
|
5
|
+
"title": "token scopes list the webhook events they release",
|
|
6
|
+
"detail": "`PatScopeDef.events` takes exact event names (no globs). Holding the scope at read or write level is enough to subscribe, `expandScopeEvents(config, granted)` returns the union. Boot fails when a scope lists an event without a public contract, for example an internal `r.defineEvent`. Revoking a token now has a title and a field label in every bundle locale."
|
|
7
|
+
},
|
|
2
8
|
{
|
|
3
9
|
"version": "0.385.0",
|
|
4
10
|
"type": "improvement",
|
|
@@ -19,6 +19,7 @@ import { PAT_FEATURE_I18N, patScopeOptionTranslations } from "./i18n.ts";
|
|
|
19
19
|
import { PAT_REVOKED_EVENT_SHORT, patRevokedSchema } from "./pat-revoked-event.ts";
|
|
20
20
|
import { createPatResolver } from "./resolver.ts";
|
|
21
21
|
import { apiTokenEntity } from "./schema/api-token.ts";
|
|
22
|
+
import { validateScopeEventContracts } from "./scope-events-check.ts";
|
|
22
23
|
import { createPatMintScreen, patListScreen } from "./screens.ts";
|
|
23
24
|
import {
|
|
24
25
|
API_TOKEN_ENTITY_NAME,
|
|
@@ -84,6 +85,7 @@ export type PersonalAccessTokensOptions = {
|
|
|
84
85
|
|
|
85
86
|
export type PatFeatureExports = {
|
|
86
87
|
readonly rateLimit: PatRateLimit;
|
|
88
|
+
readonly scopes: PatScopeConfig;
|
|
87
89
|
readonly bindAutoRevokeOnPasswordChange: BindPatAutoRevokeOnPasswordChange;
|
|
88
90
|
};
|
|
89
91
|
|
|
@@ -138,6 +140,7 @@ export function createPersonalAccessTokensFeature(
|
|
|
138
140
|
// different path. No projection: the payload IS the read, consumed
|
|
139
141
|
// directly off the event-store NOTIFY.
|
|
140
142
|
r.defineEvent(PAT_REVOKED_EVENT_SHORT, patRevokedSchema, { piiFields: "none" });
|
|
143
|
+
r.bootCheck(({ features }) => validateScopeEventContracts(scopes, features));
|
|
141
144
|
|
|
142
145
|
// Password-change auto-revoke — mirrors sessions' own
|
|
143
146
|
// autoRevokeOnPasswordChange postSave hook, including WHY it's a
|
|
@@ -195,12 +198,12 @@ export function createPersonalAccessTokensFeature(
|
|
|
195
198
|
|
|
196
199
|
// rateLimit flows into feature.exports so run-prod-app builds the
|
|
197
200
|
// limiter from the same declaration — single source of truth. `scopes`
|
|
198
|
-
// is
|
|
199
|
-
// available-scopes, so it doesn't need to round-trip through exports.
|
|
201
|
+
// is also exported so the API-docs generator can read the catalog.
|
|
200
202
|
return {
|
|
201
203
|
handlers,
|
|
202
204
|
queries,
|
|
203
205
|
bindAutoRevokeOnPasswordChange,
|
|
206
|
+
scopes,
|
|
204
207
|
rateLimit: options.rateLimit ?? PAT_DEFAULT_RATE_LIMIT,
|
|
205
208
|
} satisfies { handlers: unknown; queries: unknown } & PatFeatureExports;
|
|
206
209
|
});
|
|
@@ -12,7 +12,12 @@ import { encryptForDirectWrite, unprocessable, verifyPassword } from "../../shar
|
|
|
12
12
|
import { UserQueries } from "../../user/index.ts";
|
|
13
13
|
import { mintPatToken } from "../hash.ts";
|
|
14
14
|
import { apiTokenEntity, apiTokenTable } from "../schema/api-token.ts";
|
|
15
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
API_TOKEN_ENTITY_NAME,
|
|
17
|
+
PAT_DEFAULT_EXPIRES_IN_DAYS,
|
|
18
|
+
PAT_MAX_EXPIRES_IN_DAYS,
|
|
19
|
+
PatErrors,
|
|
20
|
+
} from "../web/constants.ts";
|
|
16
21
|
|
|
17
22
|
export type PatMfaVerifyResult = { readonly enrolled: boolean; readonly ok: boolean };
|
|
18
23
|
|
|
@@ -49,7 +54,7 @@ export function createPatCreateHandler(opts: CreatePatOptions = {}) {
|
|
|
49
54
|
schema: z.object({
|
|
50
55
|
name: z.string().min(1).max(120),
|
|
51
56
|
scopes: z.array(z.string().min(1)).min(1),
|
|
52
|
-
expiresInDays: z.number().int().positive().max(
|
|
57
|
+
expiresInDays: z.number().int().positive().max(PAT_MAX_EXPIRES_IN_DAYS).optional(),
|
|
53
58
|
currentPassword: z.string().min(1),
|
|
54
59
|
mfaCode: z.string().optional(),
|
|
55
60
|
}),
|
|
@@ -1,6 +1,6 @@
|
|
|
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.ts";
|
|
3
|
+
import { PAT_FEATURE, PatHandlers } from "./web/constants.ts";
|
|
4
4
|
import type { PatScopeConfig } from "./web/scopes.ts";
|
|
5
5
|
|
|
6
6
|
const mintFieldKey = (field: string): string =>
|
|
@@ -12,6 +12,9 @@ const scopeOptionKey = (grant: string): string =>
|
|
|
12
12
|
export const patScopeOptionKey = (domain: string, level: "read" | "write"): string =>
|
|
13
13
|
scopeOptionKey(`${domain}:${level}`);
|
|
14
14
|
|
|
15
|
+
// The revoke handler has no entity and no action form, so its title and field label only exist here.
|
|
16
|
+
const patRevokeKey = (suffix: string): string => `${PatHandlers.revoke}:${suffix}`;
|
|
17
|
+
|
|
15
18
|
type LocalizedString = { readonly en: string };
|
|
16
19
|
|
|
17
20
|
export const PAT_FEATURE_I18N: Readonly<Record<string, LocalizedString>> = {
|
|
@@ -29,6 +32,8 @@ export const PAT_FEATURE_I18N: Readonly<Record<string, LocalizedString>> = {
|
|
|
29
32
|
"pat.list.status.expired": { en: "Expired" },
|
|
30
33
|
"pat.list.revoke": { en: "Revoke" },
|
|
31
34
|
"pat.list.revoke.confirm": { en: "Revoke this token? Anything using it will stop working." },
|
|
35
|
+
[patRevokeKey("title")]: { en: "Revoke token" },
|
|
36
|
+
[patRevokeKey("field:id")]: { en: "Token" },
|
|
32
37
|
|
|
33
38
|
"pat.create.title": { en: "Create a new token" },
|
|
34
39
|
"pat.create.submit": { en: "Create token" },
|