@cosmicdrift/kumiko-samples 0.406.0 → 0.410.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 -4
- package/packages/bundled-features/src/account-security/feature.ts +9 -1
- package/packages/bundled-features/src/admin-shell/changes.json +6 -0
- package/packages/bundled-features/src/admin-shell/feature.ts +4 -1
- package/packages/bundled-features/src/agent-tools/agent-manifest.ts +1 -0
- package/packages/bundled-features/src/agent-tools/changes.json +6 -0
- package/packages/bundled-features/src/agent-tools/tool-catalog.ts +1 -0
- package/packages/bundled-features/src/agent-tools/types.ts +4 -0
- package/packages/bundled-features/src/audit/event-classification.ts +1 -0
- package/packages/bundled-features/src/auth-email-password/bootstrap.ts +1 -0
- package/packages/bundled-features/src/auth-email-password/errors.ts +18 -66
- package/packages/bundled-features/src/auth-email-password/handlers/login-options.query.ts +1 -1
- package/packages/bundled-features/src/auth-email-password/handlers/self-registration-status.query.ts +1 -1
- package/packages/bundled-features/src/auth-email-password/web/auth-client.ts +30 -64
- package/packages/bundled-features/src/auth-email-password/web/auth-redirect.ts +2 -2
- package/packages/bundled-features/src/auth-email-password/web/confirm-account-unlock-screen.tsx +20 -66
- package/packages/bundled-features/src/auth-email-password/web/index.ts +1 -0
- package/packages/bundled-features/src/auth-email-password/web/read-path-param.ts +8 -0
- package/packages/bundled-features/src/auth-email-password/web/return-path.ts +3 -2
- package/packages/bundled-features/src/auth-email-password/web/token-confirm-screen.tsx +97 -0
- package/packages/bundled-features/src/auth-email-password/web/verify-email-screen.tsx +20 -68
- package/packages/bundled-features/src/auth-foundation/boot-checks.ts +22 -15
- package/packages/bundled-features/src/auth-foundation/boot-rules.ts +33 -0
- package/packages/bundled-features/src/auth-mfa/errors.ts +12 -42
- package/packages/bundled-features/src/auth-mfa/feature-exports.ts +6 -45
- package/packages/bundled-features/src/auth-mfa/feature.ts +8 -19
- package/packages/bundled-features/src/auth-mfa/web/mfa-client.ts +19 -33
- package/packages/bundled-features/src/billing-foundation/consumer-protection/termination-notify.ts +1 -0
- package/packages/bundled-features/src/billing-foundation/web/plan-price.ts +20 -7
- package/packages/bundled-features/src/cap-counter/stock-cap-guard.ts +1 -0
- package/packages/bundled-features/src/channel-in-app/changes.json +7 -0
- package/packages/bundled-features/src/channel-in-app/feature.ts +2 -0
- package/packages/bundled-features/src/channel-in-app/handlers/read-state-by-keys.query.ts +35 -0
- package/packages/bundled-features/src/channel-in-app/in-app-channel.ts +1 -0
- package/packages/bundled-features/src/channel-in-app/tables.ts +5 -1
- package/packages/bundled-features/src/compliance-profiles/handlers/sub-processors.query.ts +4 -1
- package/packages/bundled-features/src/contact/challenge.ts +41 -0
- package/packages/bundled-features/src/contact/changes.json +33 -0
- package/packages/bundled-features/src/contact/client/contact-client-source.ts +203 -0
- package/packages/bundled-features/src/contact/client/contact-website-client.ts +29 -0
- package/packages/bundled-features/src/contact/client/index.ts +9 -0
- package/packages/bundled-features/src/contact/entity.ts +168 -0
- package/packages/bundled-features/src/contact/feature.ts +174 -0
- package/packages/bundled-features/src/contact/handlers/access.ts +17 -0
- package/packages/bundled-features/src/contact/handlers/attempts.ts +76 -0
- package/packages/bundled-features/src/contact/handlers/challenge.query.ts +44 -0
- package/packages/bundled-features/src/contact/handlers/forward-request.write.ts +98 -0
- package/packages/bundled-features/src/contact/handlers/mark-done.write.ts +40 -0
- package/packages/bundled-features/src/contact/handlers/notify-reporter-in-app.write.ts +48 -0
- package/packages/bundled-features/src/contact/handlers/open-count.query.ts +15 -0
- package/packages/bundled-features/src/contact/handlers/open-count.ts +17 -0
- package/packages/bundled-features/src/contact/handlers/replies.query.ts +29 -0
- package/packages/bundled-features/src/contact/handlers/reply.write.ts +197 -0
- package/packages/bundled-features/src/contact/handlers/report.write.ts +126 -0
- package/packages/bundled-features/src/contact/handlers/request-delivery.query.ts +143 -0
- package/packages/bundled-features/src/contact/handlers/request-detail.query.ts +50 -0
- package/packages/bundled-features/src/contact/handlers/request-list.query.ts +14 -0
- package/packages/bundled-features/src/contact/handlers/send-reply-mail.write.ts +124 -0
- package/packages/bundled-features/src/contact/handlers/send-test.write.ts +45 -0
- package/packages/bundled-features/src/contact/handlers/submit.write.ts +194 -0
- package/packages/bundled-features/src/contact/handlers/take-over-uploads.ts +47 -0
- package/packages/bundled-features/src/contact/i18n.ts +192 -0
- package/packages/bundled-features/src/contact/index.ts +29 -0
- package/packages/bundled-features/src/contact/lib.ts +176 -0
- package/packages/bundled-features/src/contact/mail.ts +401 -0
- package/packages/bundled-features/src/contact/options.ts +95 -0
- package/packages/bundled-features/src/contact/panels.ts +28 -0
- package/packages/bundled-features/src/contact/payloads.ts +106 -0
- package/packages/bundled-features/src/contact/pow.ts +22 -0
- package/packages/bundled-features/src/contact/screens.ts +507 -0
- package/packages/bundled-features/src/contact/subject.ts +13 -0
- package/packages/bundled-features/src/contact/user-agent.ts +39 -0
- package/packages/bundled-features/src/contact/user-data-hooks.ts +180 -0
- package/packages/bundled-features/src/contact/web/constants.ts +160 -0
- package/packages/bundled-features/src/contact/web/index.ts +29 -0
- package/packages/bundled-features/src/crypto-shredding/handlers/forget-subject.write.ts +5 -16
- package/packages/bundled-features/src/data-retention/changes.json +6 -0
- package/packages/bundled-features/src/data-retention/feature.ts +16 -2
- package/packages/bundled-features/src/data-retention/index.ts +5 -0
- package/packages/bundled-features/src/data-retention/run-retention-cleanup.ts +138 -41
- package/packages/bundled-features/src/data-retention/tenant-destruction-hold.ts +196 -0
- package/packages/bundled-features/src/delivery/address-opt-out.ts +1 -0
- package/packages/bundled-features/src/delivery/changes.json +7 -0
- package/packages/bundled-features/src/delivery/channel-context.ts +2 -0
- package/packages/bundled-features/src/delivery/delivery-service.ts +29 -5
- package/packages/bundled-features/src/delivery/events.ts +2 -0
- package/packages/bundled-features/src/delivery/feature.ts +3 -2
- package/packages/bundled-features/src/delivery/handlers/attempts-by-keys.query.ts +55 -0
- package/packages/bundled-features/src/delivery/handlers/log.query.ts +1 -1
- package/packages/bundled-features/src/delivery/jobs.ts +5 -0
- package/packages/bundled-features/src/delivery/tables.ts +13 -2
- package/packages/bundled-features/src/delivery/types.ts +3 -0
- package/packages/bundled-features/src/delivery/unsubscribe-page.ts +2 -0
- package/packages/bundled-features/src/delivery/web/delivery-channel-cell.tsx +1 -1
- package/packages/bundled-features/src/delivery/web/delivery-error-cell.tsx +1 -1
- package/packages/bundled-features/src/delivery/web/delivery-status-cell.tsx +1 -1
- package/packages/bundled-features/src/delivery/web/delivery-time-cell.tsx +3 -2
- package/packages/bundled-features/src/delivery/web/delivery-type-cell.tsx +1 -1
- package/packages/bundled-features/src/delivery/web/public-names.ts +1 -0
- package/packages/bundled-features/src/document-ingest-foundation/boot-checks.ts +14 -9
- package/packages/bundled-features/src/document-ingest-foundation/boot-rules.ts +22 -0
- package/packages/bundled-features/src/document-ingest-foundation/changes.json +6 -0
- package/packages/bundled-features/src/document-ingest-foundation/events.ts +17 -0
- package/packages/bundled-features/src/document-ingest-foundation/feature.ts +39 -1
- package/packages/bundled-features/src/document-ingest-foundation/index.ts +10 -0
- package/packages/bundled-features/src/document-ingest-foundation/report-ingest-progress.ts +43 -0
- package/packages/bundled-features/src/document-ingest-foundation/tables.ts +43 -0
- package/packages/bundled-features/src/file-derivatives/handlers/public-variant-by-file-ref.query.ts +1 -1
- package/packages/bundled-features/src/file-derivatives/handlers/public-variant.query.ts +1 -1
- package/packages/bundled-features/src/files-tenant-data/changes.json +6 -0
- package/packages/bundled-features/src/files-tenant-data/hooks.ts +4 -1
- package/packages/bundled-features/src/folders/web/folder-manager.tsx +8 -9
- package/packages/bundled-features/src/folders/web/folder-section.tsx +1 -1
- package/packages/bundled-features/src/form-draft-user-data/index.ts +2 -0
- package/packages/bundled-features/src/inbound-mail-foundation/changes.json +13 -0
- package/packages/bundled-features/src/inbound-mail-foundation/entities.ts +2 -0
- package/packages/bundled-features/src/inbound-mail-foundation/events.ts +2 -0
- package/packages/bundled-features/src/inbound-mail-foundation/feature.ts +6 -6
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/attach-message-content.write.ts +7 -0
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/ingest-message.write.ts +6 -0
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/list-messages.query.ts +6 -2
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/message-content.query.ts +3 -0
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/message-content.ts +19 -0
- package/packages/bundled-features/src/inbound-mail-foundation/projection.ts +2 -0
- package/packages/bundled-features/src/inbound-mail-foundation/sanitize-inbound-html.ts +150 -0
- package/packages/bundled-features/src/inbound-mail-foundation/types.ts +1 -0
- package/packages/bundled-features/src/jobs/job-run-logger.ts +24 -25
- package/packages/bundled-features/src/ledger/handlers/reports.query.ts +46 -31
- package/packages/bundled-features/src/ledger/recurring.ts +1 -0
- package/packages/bundled-features/src/managed-pages/handlers/branding.query.ts +1 -1
- package/packages/bundled-features/src/managed-pages/handlers/by-slug.query.ts +1 -1
- package/packages/bundled-features/src/managed-pages/handlers/by-tenant-published.query.ts +1 -1
- package/packages/bundled-features/src/notes-history/web/notes-section.tsx +3 -1
- package/packages/bundled-features/src/personal-access-tokens/feature.ts +9 -17
- package/packages/bundled-features/src/personal-access-tokens/handlers/create.write.ts +2 -7
- package/packages/bundled-features/src/secrets/changes.json +6 -0
- package/packages/bundled-features/src/secrets/handlers/delete.write.ts +8 -4
- package/packages/bundled-features/src/secrets/handlers/list.query.ts +6 -3
- package/packages/bundled-features/src/secrets/handlers/set.write.ts +9 -4
- package/packages/bundled-features/src/secrets/secret-scope.ts +33 -0
- package/packages/bundled-features/src/seo/handlers/seo-config.query.ts +1 -1
- package/packages/bundled-features/src/sessions/changes.json +6 -0
- package/packages/bundled-features/src/sessions/feature.ts +21 -18
- package/packages/bundled-features/src/sessions/handlers/last-activity-probe.query.ts +53 -0
- package/packages/bundled-features/src/sessions/handlers/last-activity-probe.route.ts +39 -0
- package/packages/bundled-features/src/sessions/screens.ts +1 -0
- package/packages/bundled-features/src/sessions/session-callbacks.ts +13 -12
- package/packages/bundled-features/src/sessions/web/i18n.ts +4 -1
- package/packages/bundled-features/src/shared/assert-billing-live.ts +14 -0
- package/packages/bundled-features/src/shared/collect-extension-options.ts +12 -0
- package/packages/bundled-features/src/shared/index.ts +16 -0
- package/packages/bundled-features/src/shared/late-bound-slot.ts +19 -0
- package/packages/bundled-features/src/shared/mail-locale-templates.ts +7 -1
- package/packages/bundled-features/src/shared/price-env-shape.ts +44 -0
- package/packages/bundled-features/src/shared/purge-row-file-refs.ts +1 -1
- package/packages/bundled-features/src/shared/read-feature-export-fn.ts +16 -0
- package/packages/bundled-features/src/shared/signup-handover.ts +3 -4
- package/packages/bundled-features/src/shared/tenant-destruction-hold.ts +49 -0
- package/packages/bundled-features/src/shared/unprocessable.ts +19 -0
- package/packages/bundled-features/src/shared/web/index.ts +3 -0
- package/packages/bundled-features/src/subscription-paddle/checkout-config.query.ts +1 -1
- package/packages/bundled-features/src/subscription-paddle/feature.ts +7 -15
- package/packages/bundled-features/src/subscription-paddle/runtime.ts +4 -7
- package/packages/bundled-features/src/subscription-stripe/feature.ts +7 -15
- package/packages/bundled-features/src/subscription-stripe/runtime.ts +4 -7
- package/packages/bundled-features/src/tags/entity.ts +1 -0
- package/packages/bundled-features/src/tags/web/tag-chip.tsx +14 -0
- package/packages/bundled-features/src/tags/web/tag-filter.tsx +4 -5
- package/packages/bundled-features/src/tags/web/tag-manager.tsx +1 -1
- package/packages/bundled-features/src/tags/web/tag-section.tsx +3 -6
- package/packages/bundled-features/src/tags/web/tags-cell.tsx +4 -5
- package/packages/bundled-features/src/template-resolver/compile-document-body.ts +27 -15
- package/packages/bundled-features/src/template-resolver/handlers/by-slug.query.ts +1 -1
- package/packages/bundled-features/src/template-resolver/handlers/by-tenant.query.ts +12 -9
- package/packages/bundled-features/src/template-resolver/handlers/discard-draft.write.ts +1 -0
- package/packages/bundled-features/src/template-resolver/handlers/overview.query.ts +1 -0
- package/packages/bundled-features/src/template-resolver/handlers/send-test.write.ts +5 -5
- package/packages/bundled-features/src/template-resolver/handlers/toggle-status.write.ts +3 -0
- package/packages/bundled-features/src/template-resolver/linked-resources.ts +11 -6
- package/packages/bundled-features/src/template-resolver/store-template-resource.ts +15 -12
- package/packages/bundled-features/src/template-resolver/web/document-images.ts +6 -6
- package/packages/bundled-features/src/template-resolver/web/document-insert-fields.tsx +41 -36
- package/packages/bundled-features/src/template-resolver/web/document-schema.ts +11 -12
- package/packages/bundled-features/src/template-resolver/web/tiptap-attribute-parse-rule.ts +19 -0
- package/packages/bundled-features/src/tenant/i18n.ts +3 -0
- package/packages/bundled-features/src/tenant/schema/tenant.ts +1 -0
- package/packages/bundled-features/src/tenant/web/member-roles-cell.tsx +1 -1
- package/packages/bundled-features/src/tenant/web/member-status-cell.tsx +1 -1
- package/packages/bundled-features/src/tenant-inactivity/changes.json +8 -0
- package/packages/bundled-features/src/tenant-inactivity/check-inactive-tenants.ts +260 -0
- package/packages/bundled-features/src/tenant-inactivity/constants.ts +12 -0
- package/packages/bundled-features/src/tenant-inactivity/email-templates.ts +24 -0
- package/packages/bundled-features/src/tenant-inactivity/feature.ts +66 -0
- package/packages/bundled-features/src/tenant-inactivity/handlers/inactivity-state.query.ts +49 -0
- package/packages/bundled-features/src/tenant-inactivity/handlers/keep-account.write.ts +59 -0
- package/packages/bundled-features/src/tenant-inactivity/inactivity-plan.ts +187 -0
- package/packages/bundled-features/src/tenant-inactivity/index.ts +5 -0
- package/packages/bundled-features/src/tenant-inactivity/keep-token.ts +44 -0
- package/packages/bundled-features/src/tenant-inactivity/mail-notifications.ts +62 -0
- package/packages/bundled-features/src/tenant-inactivity/options.ts +38 -0
- package/packages/bundled-features/src/tenant-inactivity/remote-activity.ts +32 -0
- package/packages/bundled-features/src/tenant-inactivity/state-store.ts +71 -0
- package/packages/bundled-features/src/tenant-inactivity/state-table.ts +50 -0
- package/packages/bundled-features/src/tenant-lifecycle/boot-checks.ts +8 -6
- package/packages/bundled-features/src/tenant-lifecycle/boot-rules.ts +16 -0
- package/packages/bundled-features/src/tenant-lifecycle/changes.json +18 -0
- package/packages/bundled-features/src/tenant-lifecycle/feature.ts +24 -1
- package/packages/bundled-features/src/tenant-lifecycle/handlers/request-destruction.write.ts +12 -87
- package/packages/bundled-features/src/tenant-lifecycle/index.ts +4 -0
- package/packages/bundled-features/src/tenant-lifecycle/request-tenant-destruction.ts +108 -0
- package/packages/bundled-features/src/tenant-lifecycle/retention-config-destroy-hooks.ts +62 -0
- package/packages/bundled-features/src/tenant-lifecycle/run-tenant-destroy.ts +58 -5
- package/packages/bundled-features/src/tenant-lifecycle/stages.ts +31 -2
- package/packages/bundled-features/src/tenant-lifecycle/testing.ts +1 -1
- package/packages/bundled-features/src/tier-engine/caps-for-tier-from-map.ts +16 -0
- package/packages/bundled-features/src/tier-engine/changes.json +6 -0
- package/packages/bundled-features/src/tier-engine/compose-app.ts +21 -20
- package/packages/bundled-features/src/tier-engine/index.ts +1 -0
- package/packages/bundled-features/src/user-data-rights/feature.ts +2 -0
- package/packages/bundled-features/src/user-data-rights/handlers/confirm-deletion-by-token.write.ts +4 -1
- package/packages/bundled-features/src/user-data-rights/handlers/download-by-token.query.ts +1 -0
- package/packages/bundled-features/src/user-data-rights/handlers/request-deletion-by-email.write.ts +4 -1
- package/packages/bundled-features/src/user-data-rights/run-forget-cleanup.ts +2 -0
- package/packages/bundled-features/src/user-data-rights/web/privacy-center-screen.tsx +1 -1
- package/packages/bundled-features/src/user-data-rights/zip-path.ts +1 -0
- package/packages/bundled-features/src/user-data-rights-defaults/hooks/config-value.userdata-hook.ts +8 -27
- package/packages/bundled-features/src/user-data-rights-defaults/hooks/delivery-attempt.userdata-hook.ts +11 -8
- package/packages/bundled-features/src/user-data-rights-defaults/hooks/forget-own-rows-delete-hook.ts +42 -0
- package/packages/bundled-features/src/user-data-rights-defaults/hooks/notification-preference.userdata-hook.ts +8 -27
- package/packages/bundled-features/src/user-profile/handlers/change-email.write.ts +2 -6
- package/packages/bundled-features/src/user-profile/web/profile-screen.tsx +2 -3
- package/packages/bundled-features/src/waitlist/changes.json +6 -0
- package/packages/bundled-features/src/waitlist/handlers/submit.write.ts +1 -2
- package/samples/apps/styleguide/src/features/widgets/i18n.ts +6 -0
- package/samples/apps/styleguide/src/features/widgets/web/InboxReaderExamples.tsx +158 -0
- package/samples/apps/styleguide/src/features/widgets/web/Widgets.tsx +2 -0
- package/samples/apps/styleguide/src/features/widgets/web/sample-pdf.ts +28 -0
- package/samples/apps/use-all-bundled/feature-manifest.json +113 -2
- package/samples/apps/use-all-bundled/kumiko/migrations/0063_contact.rebuild.json +4 -0
- package/samples/apps/use-all-bundled/package.json +1 -0
- package/samples/apps/use-all-bundled/src/app/client.tsx +3 -0
- package/samples/apps/use-all-bundled/src/app/screens-feature.ts +46 -2
- package/samples/apps/use-all-bundled/src/run-config.ts +23 -1
- package/samples/recipes/anonymous-access/README.md +2 -0
- package/samples/recipes/anonymous-access/src/feature.ts +7 -1
- package/samples/recipes/contact/README.md +52 -0
- package/samples/recipes/contact/package.json +12 -0
- package/samples/recipes/contact/src/feature.ts +27 -0
- package/samples/recipes/delivery-notifications/src/feature.ts +3 -0
- package/samples/recipes/record-detail-layout/src/feature.ts +9 -1
- package/samples/recipes/search/README.md +2 -0
- package/samples/recipes/search/src/feature.ts +27 -2
- package/samples/recipes/secrets-demo/README.md +1 -0
- package/samples/recipes/secrets-demo/src/feature.ts +56 -0
- package/samples/recipes/tenant-inactivity/README.md +21 -0
- package/samples/recipes/tenant-inactivity/package.json +12 -0
|
@@ -23,7 +23,7 @@ export const byTenantPublishedQuery = defineQueryHandler({
|
|
|
23
23
|
* logic in by-slug.query. */
|
|
24
24
|
tenantIdOverride: z.string().min(1).optional(),
|
|
25
25
|
}),
|
|
26
|
-
access: { roles: ["anonymous", "User", "TenantAdmin", "SystemAdmin"] },
|
|
26
|
+
access: { roles: ["anonymous", "User", "TenantAdmin", "SystemAdmin"], anySignedIn: true },
|
|
27
27
|
rateLimit: { per: "ip+handler", limit: 60, windowSeconds: 60 },
|
|
28
28
|
description:
|
|
29
29
|
"Lists every published page of a tenant with slug, language, title and last-change time but no body; use it to enumerate the public pages for sitemap.xml or llms.txt, rather than by-slug which fetches one page's content.",
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
import {
|
|
14
14
|
formatWhen,
|
|
15
15
|
useDispatcher,
|
|
16
|
+
useLocale,
|
|
16
17
|
usePrimitives,
|
|
17
18
|
useQuery,
|
|
18
19
|
useTranslation,
|
|
@@ -49,6 +50,7 @@ export function NotesSection({
|
|
|
49
50
|
}): ReactNode {
|
|
50
51
|
const { Banner, Button, Grid, Heading, Text, Input } = usePrimitives();
|
|
51
52
|
const t = useTranslation();
|
|
53
|
+
const locale = useLocale().locale();
|
|
52
54
|
const dispatcher = useDispatcher();
|
|
53
55
|
const enabled = entityId !== null;
|
|
54
56
|
const notes = useQuery<NoteListResponse>(
|
|
@@ -176,7 +178,7 @@ export function NotesSection({
|
|
|
176
178
|
n.authorName,
|
|
177
179
|
t("notesHistory.section.authorUnknown"),
|
|
178
180
|
),
|
|
179
|
-
date: formatWhen(n.insertedAt),
|
|
181
|
+
date: formatWhen(n.insertedAt, locale),
|
|
180
182
|
})}
|
|
181
183
|
</Text>
|
|
182
184
|
</div>
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
type FeatureDefinition,
|
|
10
10
|
type ProjectionListScreenDefinition,
|
|
11
11
|
} from "@cosmicdrift/kumiko-framework/engine";
|
|
12
|
+
import { createLateBoundSlot, readFeatureExportFn } from "../shared/index.ts";
|
|
12
13
|
import { availabilityQuery } from "./handlers/availability.query.ts";
|
|
13
14
|
import { buildAvailableScopesQuery } from "./handlers/available-scopes.query.ts";
|
|
14
15
|
import { type CreatePatOptions, createPatCreateHandler } from "./handlers/create.write.ts";
|
|
@@ -44,15 +45,10 @@ export type BindPatAutoRevokeOnPasswordChange = (
|
|
|
44
45
|
export function bindPatAutoRevokeOnPasswordChangeFromFeature(
|
|
45
46
|
feature: FeatureDefinition,
|
|
46
47
|
): BindPatAutoRevokeOnPasswordChange | undefined {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
// @cast-boundary feature-exports — feature.exports is untyped by design
|
|
52
|
-
return bindAutoRevokeOnPasswordChange as BindPatAutoRevokeOnPasswordChange;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return undefined;
|
|
48
|
+
return readFeatureExportFn<BindPatAutoRevokeOnPasswordChange>(
|
|
49
|
+
feature,
|
|
50
|
+
"bindAutoRevokeOnPasswordChange",
|
|
51
|
+
);
|
|
56
52
|
}
|
|
57
53
|
|
|
58
54
|
export type PersonalAccessTokensOptions = {
|
|
@@ -151,12 +147,13 @@ export function createPersonalAccessTokensFeature(
|
|
|
151
147
|
// run{Prod,Dev}App has a real db handle.
|
|
152
148
|
// Explicit option wins; the runtime binding is replaceable so a second boot of the same
|
|
153
149
|
// feature instance binds its own database.
|
|
154
|
-
|
|
150
|
+
const autoRevokeSlot = createLateBoundSlot<(userId: string) => Promise<number>>();
|
|
155
151
|
r.hook({
|
|
156
152
|
type: "postSave",
|
|
157
153
|
target: { allOf: "user" },
|
|
158
154
|
handler: async (result) => {
|
|
159
|
-
const autoRevokeOnPasswordChange =
|
|
155
|
+
const autoRevokeOnPasswordChange =
|
|
156
|
+
options.autoRevokeOnPasswordChange ?? autoRevokeSlot.current();
|
|
160
157
|
// skip: nothing bound — same late-bind pattern as sessions/feature.ts
|
|
161
158
|
if (!autoRevokeOnPasswordChange) return;
|
|
162
159
|
// skip: brand-new user, no PATs can exist yet
|
|
@@ -168,12 +165,7 @@ export function createPersonalAccessTokensFeature(
|
|
|
168
165
|
await autoRevokeOnPasswordChange(String(result.id));
|
|
169
166
|
},
|
|
170
167
|
});
|
|
171
|
-
const bindAutoRevokeOnPasswordChange: BindPatAutoRevokeOnPasswordChange =
|
|
172
|
-
boundAutoRevoke = revoker;
|
|
173
|
-
return () => {
|
|
174
|
-
if (boundAutoRevoke === revoker) boundAutoRevoke = undefined;
|
|
175
|
-
};
|
|
176
|
-
};
|
|
168
|
+
const bindAutoRevokeOnPasswordChange: BindPatAutoRevokeOnPasswordChange = autoRevokeSlot.bind;
|
|
177
169
|
|
|
178
170
|
const handlers = {
|
|
179
171
|
create: r.writeHandler(createPatCreateHandler({ mfaVerifier: options.mfaVerifier })),
|
|
@@ -5,11 +5,10 @@ import {
|
|
|
5
5
|
type HandlerContext,
|
|
6
6
|
type TenantId,
|
|
7
7
|
} from "@cosmicdrift/kumiko-framework/engine";
|
|
8
|
-
import { UnprocessableError, writeFailure } from "@cosmicdrift/kumiko-framework/errors";
|
|
9
8
|
import { generateId } from "@cosmicdrift/kumiko-framework/utils";
|
|
10
9
|
import { Temporal } from "@cosmicdrift/kumiko-types/temporal";
|
|
11
10
|
import * as z from "zod";
|
|
12
|
-
import { encryptForDirectWrite, verifyPassword } from "../../shared/index.ts";
|
|
11
|
+
import { encryptForDirectWrite, unprocessable, verifyPassword } from "../../shared/index.ts";
|
|
13
12
|
import { UserQueries } from "../../user/index.ts";
|
|
14
13
|
import { mintPatToken } from "../hash.ts";
|
|
15
14
|
import { apiTokenEntity, apiTokenTable } from "../schema/api-token.ts";
|
|
@@ -32,11 +31,7 @@ export type CreatePatOptions = {
|
|
|
32
31
|
|
|
33
32
|
// @wrapper-known error-helper
|
|
34
33
|
function reauthFailed() {
|
|
35
|
-
return
|
|
36
|
-
new UnprocessableError(PatErrors.reauthRequired, {
|
|
37
|
-
i18nKey: "errors.reauthRequired",
|
|
38
|
-
}),
|
|
39
|
-
);
|
|
34
|
+
return unprocessable(PatErrors.reauthRequired, "errors.reauthRequired");
|
|
40
35
|
}
|
|
41
36
|
|
|
42
37
|
// Mint a PAT for the calling user in their active tenant. The plaintext token
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"version": "0.409.0",
|
|
4
|
+
"type": "improvement",
|
|
5
|
+
"title": "configEdit screens with scope system may map secretKeys",
|
|
6
|
+
"detail": "`secrets:write:set`, `secrets:write:delete` and `secrets:query:list` accept `scope: \"system\"`. The target is always the system tenant, chosen on the server, and only a SystemAdmin may use it (everyone else gets 403). The configEdit body sends the scope for system-scope screens; the boot validator now only rejects secretKeys on user-scope screens. The secrets access rule must include `SystemAdmin` for such a screen to work, for example `createSecretsFeature({ roles: [\"TenantAdmin\", \"SystemAdmin\"] })`. Values never go to the client."
|
|
7
|
+
},
|
|
2
8
|
{
|
|
3
9
|
"version": "0.389.0",
|
|
4
10
|
"type": "fix",
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { type AccessRule, defineWriteHandler } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
-
import { failNotFound } from "@cosmicdrift/kumiko-framework/errors";
|
|
2
|
+
import { failNotFound, writeFailure } from "@cosmicdrift/kumiko-framework/errors";
|
|
3
3
|
import * as z from "zod";
|
|
4
4
|
import { announceSecretChange } from "../announce-secret-change.ts";
|
|
5
5
|
import { JOIN_REQUEST_TRANSACTION_REASON, requireSecretsContext } from "../feature.ts";
|
|
6
|
+
import { resolveSecretTarget, secretScopeSchema } from "../secret-scope.ts";
|
|
6
7
|
import { DEFAULT_SECRETS_ACCESS, SecretsHandlers } from "../web/constants.ts";
|
|
7
8
|
import { checkSecretKeyWrite } from "../write-gate.ts";
|
|
8
9
|
|
|
@@ -10,10 +11,11 @@ export function createDeleteHandler(access: AccessRule = DEFAULT_SECRETS_ACCESS)
|
|
|
10
11
|
return defineWriteHandler({
|
|
11
12
|
name: "delete",
|
|
12
13
|
description:
|
|
13
|
-
"Permanently removes the stored secret under the given key for the caller's tenant, breaking every feature that depends on that credential.",
|
|
14
|
+
"Permanently removes the stored secret under the given key for the caller's tenant (or, with scope system and the SystemAdmin role, the platform-wide one), breaking every feature that depends on that credential.",
|
|
14
15
|
agent: { risk: "high" },
|
|
15
16
|
schema: z.object({
|
|
16
17
|
key: z.string().min(1).max(100),
|
|
18
|
+
scope: secretScopeSchema,
|
|
17
19
|
}),
|
|
18
20
|
access,
|
|
19
21
|
escapeHatch: { grants: ["unsafeRaw"], reason: JOIN_REQUEST_TRANSACTION_REASON },
|
|
@@ -22,15 +24,17 @@ export function createDeleteHandler(access: AccessRule = DEFAULT_SECRETS_ACCESS)
|
|
|
22
24
|
{ secrets: ctx.services.secrets, user: ctx.user },
|
|
23
25
|
SecretsHandlers.delete,
|
|
24
26
|
).withRunner(ctx.db.unsafeRaw());
|
|
27
|
+
const target = resolveSecretTarget(event.user, event.payload.scope);
|
|
28
|
+
if (!target.ok) return writeFailure(target.error);
|
|
25
29
|
const gate = checkSecretKeyWrite(ctx.registry, event.user.roles, event.payload.key, {
|
|
26
30
|
allowUndeclared: true,
|
|
27
31
|
});
|
|
28
32
|
if (!gate.ok) return gate.failure;
|
|
29
|
-
const removed = await secrets.delete(
|
|
33
|
+
const removed = await secrets.delete(target.tenantId, event.payload.key, {
|
|
30
34
|
deletedBy: event.user.id,
|
|
31
35
|
});
|
|
32
36
|
if (!removed) return failNotFound("tenant-secret", event.payload.key);
|
|
33
|
-
announceSecretChange(ctx,
|
|
37
|
+
announceSecretChange(ctx, target.tenantId, event.payload.key);
|
|
34
38
|
return { isSuccess: true, data: { key: event.payload.key } };
|
|
35
39
|
},
|
|
36
40
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type AccessRule, defineQueryHandler } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
2
|
import * as z from "zod";
|
|
3
|
+
import { resolveSecretTarget, secretScopeSchema } from "../secret-scope.ts";
|
|
3
4
|
import { tenantSecretsTable } from "../table.ts";
|
|
4
5
|
import { DEFAULT_SECRETS_ACCESS } from "../web/constants.ts";
|
|
5
6
|
|
|
@@ -10,10 +11,12 @@ export function createListHandler(access: AccessRule = DEFAULT_SECRETS_ACCESS) {
|
|
|
10
11
|
return defineQueryHandler({
|
|
11
12
|
name: "list",
|
|
12
13
|
description:
|
|
13
|
-
"Lists the secrets stored for the caller's tenant by key with a redacted preview, hint, key version and rotation date — never the plaintext; use it to check which credentials are set.",
|
|
14
|
-
schema: z.object({}),
|
|
14
|
+
"Lists the secrets stored for the caller's tenant (or, with scope system and the SystemAdmin role, the platform-wide ones) by key with a redacted preview, hint, key version and rotation date — never the plaintext; use it to check which credentials are set.",
|
|
15
|
+
schema: z.object({ scope: secretScopeSchema }),
|
|
15
16
|
access,
|
|
16
17
|
handler: async (event, ctx) => {
|
|
18
|
+
const target = resolveSecretTarget(event.user, event.payload.scope);
|
|
19
|
+
if (!target.ok) throw target.error;
|
|
17
20
|
const rows = await ctx.db.selectMany<{
|
|
18
21
|
key: string;
|
|
19
22
|
kekVersion: number;
|
|
@@ -22,7 +25,7 @@ export function createListHandler(access: AccessRule = DEFAULT_SECRETS_ACCESS) {
|
|
|
22
25
|
insertedAt: unknown;
|
|
23
26
|
}>(
|
|
24
27
|
tenantSecretsTable,
|
|
25
|
-
{ tenantId:
|
|
28
|
+
{ tenantId: target.tenantId },
|
|
26
29
|
{
|
|
27
30
|
orderBy: { col: "key", direction: "asc" },
|
|
28
31
|
},
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { type AccessRule, defineWriteHandler } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
import { writeFailure } from "@cosmicdrift/kumiko-framework/errors";
|
|
2
3
|
import * as z from "zod";
|
|
3
4
|
import { announceSecretChange } from "../announce-secret-change.ts";
|
|
4
5
|
import { JOIN_REQUEST_TRANSACTION_REASON, requireSecretsContext } from "../feature.ts";
|
|
6
|
+
import { resolveSecretTarget, secretScopeSchema } from "../secret-scope.ts";
|
|
5
7
|
import { DEFAULT_SECRETS_ACCESS, SecretsHandlers } from "../web/constants.ts";
|
|
6
8
|
import { checkSecretKeyWrite, checkSecretValue } from "../write-gate.ts";
|
|
7
9
|
|
|
@@ -9,7 +11,7 @@ export function createSetHandler(access: AccessRule = DEFAULT_SECRETS_ACCESS) {
|
|
|
9
11
|
return defineWriteHandler({
|
|
10
12
|
name: "set",
|
|
11
13
|
description:
|
|
12
|
-
"Stores or replaces one encrypted secret for the caller's tenant under the given key, together with a redacted preview and optional hint; use it to enter or rotate a credential.",
|
|
14
|
+
"Stores or replaces one encrypted secret for the caller's tenant (or, with scope system and the SystemAdmin role, the platform-wide one) under the given key, together with a redacted preview and optional hint; use it to enter or rotate a credential.",
|
|
13
15
|
// `value` is the plaintext credential: as a tool call it would travel to
|
|
14
16
|
// the model provider before it is ever encrypted at rest.
|
|
15
17
|
agent: { expose: false },
|
|
@@ -21,6 +23,7 @@ export function createSetHandler(access: AccessRule = DEFAULT_SECRETS_ACCESS) {
|
|
|
21
23
|
// handler derives a generic one (first-3-chars + bullets).
|
|
22
24
|
redactedPreview: z.string().max(50).optional(),
|
|
23
25
|
hint: z.string().max(200).optional(),
|
|
26
|
+
scope: secretScopeSchema,
|
|
24
27
|
}),
|
|
25
28
|
access,
|
|
26
29
|
escapeHatch: { grants: ["unsafeRaw"], reason: JOIN_REQUEST_TRANSACTION_REASON },
|
|
@@ -29,7 +32,9 @@ export function createSetHandler(access: AccessRule = DEFAULT_SECRETS_ACCESS) {
|
|
|
29
32
|
{ secrets: ctx.services.secrets, user: ctx.user },
|
|
30
33
|
SecretsHandlers.set,
|
|
31
34
|
).withRunner(ctx.db.unsafeRaw());
|
|
32
|
-
const { key, value, redactedPreview, hint } = event.payload;
|
|
35
|
+
const { key, value, redactedPreview, hint, scope } = event.payload;
|
|
36
|
+
const target = resolveSecretTarget(event.user, scope);
|
|
37
|
+
if (!target.ok) return writeFailure(target.error);
|
|
33
38
|
|
|
34
39
|
// Preview-priority: explicit payload param > feature-declared redact
|
|
35
40
|
// (via r.secret()) > generic default. A feature that declared a
|
|
@@ -44,12 +49,12 @@ export function createSetHandler(access: AccessRule = DEFAULT_SECRETS_ACCESS) {
|
|
|
44
49
|
? () => redactedPreview
|
|
45
50
|
: (featureRedact ?? defaultRedact);
|
|
46
51
|
|
|
47
|
-
await secrets.set(
|
|
52
|
+
await secrets.set(target.tenantId, key, value, {
|
|
48
53
|
redact: redactFn,
|
|
49
54
|
...(hint ? { hint } : {}),
|
|
50
55
|
updatedBy: event.user.id,
|
|
51
56
|
});
|
|
52
|
-
announceSecretChange(ctx,
|
|
57
|
+
announceSecretChange(ctx, target.tenantId, key);
|
|
53
58
|
|
|
54
59
|
return {
|
|
55
60
|
isSuccess: true,
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type SessionUser,
|
|
3
|
+
SYSTEM_TENANT_ID,
|
|
4
|
+
type TenantId,
|
|
5
|
+
} from "@cosmicdrift/kumiko-framework/engine";
|
|
6
|
+
import { AccessDeniedError } from "@cosmicdrift/kumiko-framework/errors";
|
|
7
|
+
import * as z from "zod";
|
|
8
|
+
|
|
9
|
+
export const SYSTEM_ADMIN_ROLE = "SystemAdmin";
|
|
10
|
+
|
|
11
|
+
// "system" targets the platform-wide secrets under SYSTEM_TENANT_ID (settings a SystemAdmin
|
|
12
|
+
// edits for the whole app). The target is never taken from the payload, only chosen here.
|
|
13
|
+
export const secretScopeSchema = z.enum(["tenant", "system"]).optional();
|
|
14
|
+
|
|
15
|
+
export type SecretScope = z.infer<typeof secretScopeSchema>;
|
|
16
|
+
|
|
17
|
+
export type SecretTarget =
|
|
18
|
+
| { readonly ok: true; readonly tenantId: TenantId }
|
|
19
|
+
| { readonly ok: false; readonly error: AccessDeniedError };
|
|
20
|
+
|
|
21
|
+
export function resolveSecretTarget(
|
|
22
|
+
user: Pick<SessionUser, "tenantId" | "roles">,
|
|
23
|
+
scope: SecretScope,
|
|
24
|
+
): SecretTarget {
|
|
25
|
+
if (scope !== "system") return { ok: true, tenantId: user.tenantId };
|
|
26
|
+
if (!user.roles.includes(SYSTEM_ADMIN_ROLE)) {
|
|
27
|
+
return {
|
|
28
|
+
ok: false,
|
|
29
|
+
error: new AccessDeniedError({ message: "system-scope secrets need the SystemAdmin role" }),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
return { ok: true, tenantId: SYSTEM_TENANT_ID };
|
|
33
|
+
}
|
|
@@ -17,7 +17,7 @@ import { SEO_CONFIG_QN } from "../constants.ts";
|
|
|
17
17
|
export const seoConfigQuery = defineQueryHandler({
|
|
18
18
|
name: "config",
|
|
19
19
|
schema: z.object({}),
|
|
20
|
-
access: { roles: ["anonymous", "User", "TenantAdmin", "SystemAdmin"] },
|
|
20
|
+
access: { roles: ["anonymous", "User", "TenantAdmin", "SystemAdmin"], anySignedIn: true },
|
|
21
21
|
rateLimit: { per: "ip+handler", limit: 60, windowSeconds: 60 },
|
|
22
22
|
description:
|
|
23
23
|
"Reads the tenant's SEO metadata settings — organization name and logo URL, Twitter site handle, LLMs summary and default OG image — as plain strings; use it to inspect what the sitemap, llms.txt and page meta tags will publish.",
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"version": "0.407.0",
|
|
4
|
+
"type": "improvement",
|
|
5
|
+
"title": "clock option and lastActivityProbeSecret",
|
|
6
|
+
"detail": "createSessionsFeature and createSessionCallbacks accept a clock option for deterministic tests. With lastActivityProbeSecret set, the sessions feature serves GET /sessions/last-activity for other apps of the same account (Bearer secret, constant-time compare, rate limited, 401 otherwise); the secret must be at least 32 characters, shorter ones fail at boot; without the option no route exists. fetchRemoteAppLastActivity({ url, secret }) from tenant-inactivity reads it as an activity source and uses internal egress restricted to the origin of the URL."
|
|
7
|
+
},
|
|
2
8
|
{
|
|
3
9
|
"version": "0.390.0",
|
|
4
10
|
"type": "fix",
|
|
@@ -9,9 +9,12 @@ import {
|
|
|
9
9
|
defineFeature,
|
|
10
10
|
type FeatureDefinition,
|
|
11
11
|
} from "@cosmicdrift/kumiko-framework/engine";
|
|
12
|
+
import type { Clock } from "@cosmicdrift/kumiko-types/tz-context";
|
|
13
|
+
import { createLateBoundSlot, readFeatureExportFn } from "../shared/index.ts";
|
|
12
14
|
import { USER_SESSION_ENTITY_NAME } from "./constants.ts";
|
|
13
15
|
import { cleanupJob } from "./handlers/cleanup.job.ts";
|
|
14
16
|
import { createDetailQuery } from "./handlers/detail.query.ts";
|
|
17
|
+
import { registerLastActivityProbe } from "./handlers/last-activity-probe.route.ts";
|
|
15
18
|
import { createListQuery } from "./handlers/list.query.ts";
|
|
16
19
|
import { mineQuery } from "./handlers/mine.query.ts";
|
|
17
20
|
import { revokeWrite } from "./handlers/revoke.write.ts";
|
|
@@ -57,6 +60,11 @@ export type SessionsFeatureOptions = {
|
|
|
57
60
|
// IP/user-agent of every session in the tenant. A preset name, not a role array, because
|
|
58
61
|
// dedupeOptions must stay primitive.
|
|
59
62
|
readonly adminAccess?: "admin" | "systemAdmin";
|
|
63
|
+
// Real time unless a test injects a manual clock; makes session times deterministic.
|
|
64
|
+
readonly clock?: Clock;
|
|
65
|
+
// Opt-in: serves GET /sessions/last-activity to a sibling app presenting this secret as a
|
|
66
|
+
// Bearer token. Answers the newest session activity across every tenant of this app.
|
|
67
|
+
readonly lastActivityProbeSecret?: string;
|
|
60
68
|
};
|
|
61
69
|
|
|
62
70
|
// The returned unbind only clears the binding while it is still this revoker, so a stack that
|
|
@@ -71,15 +79,10 @@ export type BindRevokeAllOtherSessions = (revoker: SessionAllOthersRevoker) => (
|
|
|
71
79
|
export function bindAutoRevokeFromFeature(
|
|
72
80
|
feature: FeatureDefinition,
|
|
73
81
|
): BindAutoRevokeOnPasswordChange | undefined {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
// @cast-boundary feature-exports — feature.exports is untyped by design
|
|
79
|
-
return bindAutoRevokeOnPasswordChange as BindAutoRevokeOnPasswordChange;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return undefined;
|
|
82
|
+
return readFeatureExportFn<BindAutoRevokeOnPasswordChange>(
|
|
83
|
+
feature,
|
|
84
|
+
"bindAutoRevokeOnPasswordChange",
|
|
85
|
+
);
|
|
83
86
|
}
|
|
84
87
|
|
|
85
88
|
// The sessions feature registers the store_user_sessions table (as an
|
|
@@ -145,6 +148,7 @@ export function createSessionsFeature(options?: SessionsFeatureOptions): Feature
|
|
|
145
148
|
const callbacks = createSessionCallbacks({
|
|
146
149
|
db: deps.db,
|
|
147
150
|
...(options?.expiresInMs !== undefined && { expiresInMs: options.expiresInMs }),
|
|
151
|
+
...(options?.clock !== undefined && { clock: options.clock }),
|
|
148
152
|
});
|
|
149
153
|
return {
|
|
150
154
|
creator: callbacks.sessionCreator,
|
|
@@ -195,6 +199,9 @@ export function createSessionsFeature(options?: SessionsFeatureOptions): Feature
|
|
|
195
199
|
),
|
|
196
200
|
});
|
|
197
201
|
|
|
202
|
+
const probeSecret = options?.lastActivityProbeSecret;
|
|
203
|
+
if (probeSecret !== undefined) registerLastActivityProbe(r, probeSecret);
|
|
204
|
+
|
|
198
205
|
// Cross-feature entity hook on "user". `r.entityHook` (NOT `r.hook`) is
|
|
199
206
|
// the supported cross-feature path: entity-keyed, not prefixed by the
|
|
200
207
|
// registering feature. Fires after every successful write on any
|
|
@@ -217,12 +224,12 @@ export function createSessionsFeature(options?: SessionsFeatureOptions): Feature
|
|
|
217
224
|
// Explicit option wins; the runtime binding is replaceable so a second boot of the same
|
|
218
225
|
// feature instance (a new app or test stack in one process) binds its own database.
|
|
219
226
|
const explicitAutoRevoke = options?.autoRevokeOnPasswordChange;
|
|
220
|
-
|
|
227
|
+
const autoRevokeSlot = createLateBoundSlot<SessionMassRevoker>();
|
|
221
228
|
r.hook({
|
|
222
229
|
type: "postSave",
|
|
223
230
|
target: { allOf: "user" },
|
|
224
231
|
handler: async (ctx) => {
|
|
225
|
-
const autoRevoke = explicitAutoRevoke ??
|
|
232
|
+
const autoRevoke = explicitAutoRevoke ?? autoRevokeSlot.current();
|
|
226
233
|
// skip: nothing bound — stateless-JWT deployments without a runtime
|
|
227
234
|
// that calls bindAutoRevokeOnPasswordChange keep the old behavior.
|
|
228
235
|
if (!autoRevoke) return;
|
|
@@ -237,12 +244,7 @@ export function createSessionsFeature(options?: SessionsFeatureOptions): Feature
|
|
|
237
244
|
},
|
|
238
245
|
});
|
|
239
246
|
|
|
240
|
-
const bindAutoRevokeOnPasswordChange: BindAutoRevokeOnPasswordChange =
|
|
241
|
-
boundAutoRevoke = revoker;
|
|
242
|
-
return () => {
|
|
243
|
-
if (boundAutoRevoke === revoker) boundAutoRevoke = undefined;
|
|
244
|
-
};
|
|
245
|
-
};
|
|
247
|
+
const bindAutoRevokeOnPasswordChange: BindAutoRevokeOnPasswordChange = autoRevokeSlot.bind;
|
|
246
248
|
|
|
247
249
|
r.translations({ keys: SESSIONS_I18N });
|
|
248
250
|
|
|
@@ -259,6 +261,7 @@ export function createSessionsFeature(options?: SessionsFeatureOptions): Feature
|
|
|
259
261
|
|
|
260
262
|
return { handlers, queries, bindAutoRevokeOnPasswordChange };
|
|
261
263
|
},
|
|
262
|
-
|
|
264
|
+
// A clock object is not a comparable dedupe option; a stack that injects one never dedupes.
|
|
265
|
+
options?.clock === undefined ? { dedupeOptions: options ?? {} } : undefined,
|
|
263
266
|
);
|
|
264
267
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { timingSafeEqual } from "node:crypto";
|
|
2
|
+
import { defineQueryHandler } from "@cosmicdrift/kumiko-framework/engine";
|
|
3
|
+
import { AccessDeniedError, InternalError } from "@cosmicdrift/kumiko-framework/errors";
|
|
4
|
+
import { Temporal } from "@cosmicdrift/kumiko-types/temporal";
|
|
5
|
+
import * as z from "zod";
|
|
6
|
+
import { userSessionTable } from "../schema/user-session.ts";
|
|
7
|
+
|
|
8
|
+
export const LAST_ACTIVITY_PROBE_QUERY = "sessions:query:last-activity-probe";
|
|
9
|
+
|
|
10
|
+
const EPOCH = Temporal.Instant.fromEpochMilliseconds(0);
|
|
11
|
+
|
|
12
|
+
const PROBE_ESCAPE_HATCH_REASON =
|
|
13
|
+
"answers one sibling app with the newest session activity across every tenant of this app, guarded by a shared secret";
|
|
14
|
+
|
|
15
|
+
function secretsMatch(provided: string, expected: string): boolean {
|
|
16
|
+
const providedBytes = Buffer.from(provided);
|
|
17
|
+
const expectedBytes = Buffer.from(expected);
|
|
18
|
+
return (
|
|
19
|
+
providedBytes.length === expectedBytes.length && timingSafeEqual(providedBytes, expectedBytes)
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// The route's systemQuery runs as an anonymous user, so the query must accept that role. The
|
|
24
|
+
// secret is checked here as well as in the route, so no other dispatch path that reaches the
|
|
25
|
+
// query can expose the app-wide activity time without it.
|
|
26
|
+
export function createLastActivityProbeQuery(secret: string) {
|
|
27
|
+
return defineQueryHandler({
|
|
28
|
+
name: "last-activity-probe",
|
|
29
|
+
schema: z.object({ bearerToken: z.string().min(1).max(512) }),
|
|
30
|
+
access: { roles: ["anonymous"] },
|
|
31
|
+
agent: { expose: false },
|
|
32
|
+
rateLimit: { per: "ip", limit: 30, windowSeconds: 60 },
|
|
33
|
+
escapeHatch: { grants: ["crossTenantReads"], reason: PROBE_ESCAPE_HATCH_REASON },
|
|
34
|
+
description:
|
|
35
|
+
"Returns the newest session activity time across every tenant of this app to a sibling app that presents the shared probe secret.",
|
|
36
|
+
handler: async (query, ctx) => {
|
|
37
|
+
if (!secretsMatch(query.payload.bearerToken, secret)) {
|
|
38
|
+
throw new AccessDeniedError();
|
|
39
|
+
}
|
|
40
|
+
if (!ctx.crossTenantReads) {
|
|
41
|
+
throw new InternalError({
|
|
42
|
+
message: "sessions last-activity probe: crossTenantReads missing",
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
const [newest] = await ctx.crossTenantReads.selectMany<{ lastSeenAt: Temporal.Instant }>(
|
|
46
|
+
userSessionTable,
|
|
47
|
+
{ lastSeenAt: { gte: EPOCH } },
|
|
48
|
+
{ limit: 1, orderBy: { col: "lastSeenAt", direction: "desc" } },
|
|
49
|
+
);
|
|
50
|
+
return { lastActivityAt: newest ? newest.lastSeenAt.toString() : null };
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type FeatureRegistrar, SYSTEM_TENANT_ID } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
import {
|
|
3
|
+
createLastActivityProbeQuery,
|
|
4
|
+
LAST_ACTIVITY_PROBE_QUERY,
|
|
5
|
+
} from "./last-activity-probe.query.ts";
|
|
6
|
+
|
|
7
|
+
// The route is reachable anonymously, so a short secret would be guessable within the rate limit.
|
|
8
|
+
const MIN_PROBE_SECRET_LENGTH = 32;
|
|
9
|
+
|
|
10
|
+
export function registerLastActivityProbe(r: FeatureRegistrar, secret: string): void {
|
|
11
|
+
if (secret.length < MIN_PROBE_SECRET_LENGTH) {
|
|
12
|
+
throw new Error(
|
|
13
|
+
`sessions: lastActivityProbeSecret must be at least ${MIN_PROBE_SECRET_LENGTH} characters`,
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
r.queryHandler(createLastActivityProbeQuery(secret));
|
|
17
|
+
r.httpRoute({
|
|
18
|
+
method: "GET",
|
|
19
|
+
// A string literal so feature-ast can read the route; r.httpRoute paths stay outside /api/*.
|
|
20
|
+
path: "/sessions/last-activity",
|
|
21
|
+
anonymous: true,
|
|
22
|
+
rateLimit: { per: "ip+handler", limit: 30, windowSeconds: 60 },
|
|
23
|
+
handler: async (c, { systemQuery }) => {
|
|
24
|
+
const bearerToken = /^Bearer (.+)$/.exec(c.req.header("authorization") ?? "")?.[1];
|
|
25
|
+
if (bearerToken === undefined) return c.body(null, 401);
|
|
26
|
+
try {
|
|
27
|
+
const answer = await systemQuery(
|
|
28
|
+
LAST_ACTIVITY_PROBE_QUERY,
|
|
29
|
+
{ bearerToken },
|
|
30
|
+
SYSTEM_TENANT_ID,
|
|
31
|
+
);
|
|
32
|
+
return c.json(answer);
|
|
33
|
+
} catch {
|
|
34
|
+
// Wrong secret and any handler failure look the same to the caller.
|
|
35
|
+
return c.body(null, 401);
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
}
|
|
@@ -118,6 +118,7 @@ export const createSessionDetailScreen = (
|
|
|
118
118
|
export const sessionMineScreen: ProjectionListScreenDefinition = {
|
|
119
119
|
id: SESSION_MINE_SCREEN_ID,
|
|
120
120
|
type: "projectionList",
|
|
121
|
+
description: i18nKey("sessions.mine.description"),
|
|
121
122
|
query: SessionQueries.mine,
|
|
122
123
|
columns: [
|
|
123
124
|
{
|
|
@@ -16,6 +16,7 @@ import { buildSessionRoles, SYSTEM_TENANT_ID } from "@cosmicdrift/kumiko-framewo
|
|
|
16
16
|
import { append } from "@cosmicdrift/kumiko-framework/event-store";
|
|
17
17
|
import { generateId, parseRoles } from "@cosmicdrift/kumiko-framework/utils";
|
|
18
18
|
import { Temporal } from "@cosmicdrift/kumiko-types/temporal";
|
|
19
|
+
import type { Clock } from "@cosmicdrift/kumiko-types/tz-context";
|
|
19
20
|
import { encryptForDirectWrite } from "../shared/index.ts";
|
|
20
21
|
import { tenantMembershipsTable } from "../tenant/index.ts";
|
|
21
22
|
import { isPrincipalRowBlocked, type UserStatus, userTable } from "../user/index.ts";
|
|
@@ -31,6 +32,8 @@ import {
|
|
|
31
32
|
sessionRevokedSchema,
|
|
32
33
|
} from "./session-revoked-event.ts";
|
|
33
34
|
|
|
35
|
+
const realClock: Clock = { now: () => Temporal.Now.instant() };
|
|
36
|
+
|
|
34
37
|
type SettledLookup<T> = { readonly ok: true; readonly value: T } | { readonly ok: false };
|
|
35
38
|
|
|
36
39
|
function settleLookup<T>(lookup: Promise<T>): Promise<SettledLookup<T>> {
|
|
@@ -60,6 +63,8 @@ export type SessionCallbacksOptions = {
|
|
|
60
63
|
// Session lifetime. MVP uses a single flat window; per-app policies can
|
|
61
64
|
// come later (e.g. longer for "remember me", shorter for admin).
|
|
62
65
|
readonly expiresInMs?: number;
|
|
66
|
+
// Real time unless a test injects a manual clock to age sessions deterministically.
|
|
67
|
+
readonly clock?: Clock;
|
|
63
68
|
};
|
|
64
69
|
|
|
65
70
|
export type SessionCallbacks = {
|
|
@@ -73,11 +78,12 @@ export type SessionCallbacks = {
|
|
|
73
78
|
export function createSessionCallbacks(opts: SessionCallbacksOptions): SessionCallbacks {
|
|
74
79
|
const ttlMs = opts.expiresInMs ?? DEFAULT_SESSION_EXPIRY_MS;
|
|
75
80
|
const { db } = opts;
|
|
81
|
+
const clock = opts.clock ?? realClock;
|
|
76
82
|
|
|
77
83
|
return {
|
|
78
84
|
async sessionCreator(user: SessionUser, meta: SessionMetadata): Promise<string> {
|
|
79
85
|
const sid = generateId();
|
|
80
|
-
const now =
|
|
86
|
+
const now = clock.now();
|
|
81
87
|
const expiresAt = now.add({ milliseconds: ttlMs });
|
|
82
88
|
await insertOne(
|
|
83
89
|
db,
|
|
@@ -114,7 +120,7 @@ export function createSessionCallbacks(opts: SessionCallbacksOptions): SessionCa
|
|
|
114
120
|
const result = await updateMany<{ userId: string }>(
|
|
115
121
|
tx,
|
|
116
122
|
userSessionTable,
|
|
117
|
-
{ revokedAt:
|
|
123
|
+
{ revokedAt: clock.now() },
|
|
118
124
|
{ id: sid, revokedAt: null },
|
|
119
125
|
);
|
|
120
126
|
|
|
@@ -170,7 +176,7 @@ export function createSessionCallbacks(opts: SessionCallbacksOptions): SessionCa
|
|
|
170
176
|
if (row.revokedAt !== null) return "revoked";
|
|
171
177
|
// Temporal-native clock read (Sprint F migration) — keeps the feature
|
|
172
178
|
// free of raw Date.now() for consistency with the rest of the codebase.
|
|
173
|
-
if (row.expiresAt.epochMilliseconds <=
|
|
179
|
+
if (row.expiresAt.epochMilliseconds <= clock.now().epochMilliseconds) {
|
|
174
180
|
return "expired";
|
|
175
181
|
}
|
|
176
182
|
|
|
@@ -185,15 +191,10 @@ export function createSessionCallbacks(opts: SessionCallbacksOptions): SessionCa
|
|
|
185
191
|
|
|
186
192
|
// Hourly, not per-request: this check runs on every authenticated
|
|
187
193
|
// request, so a write here has to stay off the hot path.
|
|
188
|
-
const nowMs =
|
|
194
|
+
const nowMs = clock.now().epochMilliseconds;
|
|
189
195
|
if (!row.lastSeenAt || row.lastSeenAt.epochMilliseconds + LAST_SEEN_REFRESH_MS <= nowMs) {
|
|
190
196
|
try {
|
|
191
|
-
await updateMany(
|
|
192
|
-
db,
|
|
193
|
-
userSessionTable,
|
|
194
|
-
{ lastSeenAt: Temporal.Now.instant() },
|
|
195
|
-
{ id: sid },
|
|
196
|
-
);
|
|
197
|
+
await updateMany(db, userSessionTable, { lastSeenAt: clock.now() }, { id: sid });
|
|
197
198
|
} catch {
|
|
198
199
|
// fail-open: a refresh failure must not block the session check
|
|
199
200
|
}
|
|
@@ -243,7 +244,7 @@ export function createSessionCallbacks(opts: SessionCallbacksOptions): SessionCa
|
|
|
243
244
|
const result = await updateMany(
|
|
244
245
|
tx,
|
|
245
246
|
userSessionTable,
|
|
246
|
-
{ revokedAt:
|
|
247
|
+
{ revokedAt: clock.now() },
|
|
247
248
|
{ userId, revokedAt: null },
|
|
248
249
|
);
|
|
249
250
|
|
|
@@ -280,7 +281,7 @@ export function createSessionCallbacks(opts: SessionCallbacksOptions): SessionCa
|
|
|
280
281
|
const result = await updateMany(
|
|
281
282
|
tx,
|
|
282
283
|
userSessionTable,
|
|
283
|
-
{ revokedAt:
|
|
284
|
+
{ revokedAt: clock.now() },
|
|
284
285
|
currentSid
|
|
285
286
|
? { userId, revokedAt: null, id: { ne: currentSid } }
|
|
286
287
|
: { userId, revokedAt: null },
|
|
@@ -19,7 +19,10 @@ export const SESSIONS_I18N: Readonly<Record<string, LocalizedString>> = {
|
|
|
19
19
|
"sessions.detail.field.revokedAt": { en: "Revoked" },
|
|
20
20
|
"sessions.detail.field.ip": { en: "IP address" },
|
|
21
21
|
"sessions.detail.field.userAgent": { en: "User agent" },
|
|
22
|
-
"screen:my-sessions.title": { en: "
|
|
22
|
+
"screen:my-sessions.title": { en: "Signed-in devices" },
|
|
23
|
+
"sessions.mine.description": {
|
|
24
|
+
en: "Devices you are currently signed in on. Sign out unfamiliar devices here.",
|
|
25
|
+
},
|
|
23
26
|
"sessions.mine.col.ip": { en: "IP address" },
|
|
24
27
|
"sessions.mine.col.userAgent": { en: "Device" },
|
|
25
28
|
"sessions.mine.col.current": { en: "Session" },
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ConfigKeyHandle, HandlerContext } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
import { FeatureDisabledError } from "@cosmicdrift/kumiko-framework/errors";
|
|
3
|
+
|
|
4
|
+
export async function assertBillingLive(
|
|
5
|
+
ctx: HandlerContext,
|
|
6
|
+
billingLiveHandle: ConfigKeyHandle<"boolean">,
|
|
7
|
+
featureName: string,
|
|
8
|
+
handlerName: string,
|
|
9
|
+
): Promise<void> {
|
|
10
|
+
const live = ctx.config ? await ctx.config(billingLiveHandle) : undefined;
|
|
11
|
+
if (live !== true) {
|
|
12
|
+
throw new FeatureDisabledError(featureName, handlerName);
|
|
13
|
+
}
|
|
14
|
+
}
|