create-safest-tools 0.6.0 → 0.7.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/README.md +3 -3
- package/package.json +2 -2
- package/src/config.mjs +2 -2
- package/src/update.mjs +10 -1
- package/template/README.md +2 -2
- package/template/console/README.md +2 -2
- package/template/console/analytics/AnalyticsWorkspace.tsx +49 -36
- package/template/console/analytics/controller.ts +10 -2
- package/template/console/analytics/types.ts +7 -0
- package/template/console/appeals/AppealFollowup.tsx +171 -0
- package/template/console/appeals/AppealWorkspace.tsx +33 -4
- package/template/console/appeals/RecordAppealDialog.tsx +42 -0
- package/template/console/appeals/appeal-corrections.css +29 -0
- package/template/console/appeals/controller.ts +40 -14
- package/template/console/appeals/events.ts +1 -0
- package/template/console/appeals/types.ts +6 -0
- package/template/console/appeals/useAppealDraftGuard.ts +12 -0
- package/template/console/assistant/AssistantWorkspace.tsx +28 -5
- package/template/console/command/CommandCentre.tsx +101 -64
- package/template/console/command/controller.ts +80 -70
- package/template/console/command/events.ts +1 -2
- package/template/console/command/presentation.ts +29 -0
- package/template/console/command/store.ts +4 -4
- package/template/console/command/types.ts +26 -21
- package/template/console/configuration/ConfigurationBuilders.tsx +101 -0
- package/template/console/configuration/ConfigurationDialog.tsx +28 -13
- package/template/console/configuration/ConfigurationWorkspace.tsx +21 -8
- package/template/console/configuration/types.ts +1 -1
- package/template/console/lib/priority.ts +13 -0
- package/template/console/operations/CaseEscalations.tsx +142 -0
- package/template/console/operations/OperationsWorkspace.tsx +2 -0
- package/template/console/operations/case-escalations.css +20 -0
- package/template/console/people/PeopleWorkspace.tsx +8 -4
- package/template/console/people/PersonAccessDialog.tsx +40 -0
- package/template/console/people/types.ts +1 -0
- package/template/console/profile/ProfileWorkspace.tsx +1 -1
- package/template/console/registry/IntegrationSetup.tsx +41 -0
- package/template/console/registry/IntegrationVerification.tsx +54 -0
- package/template/console/registry/RegistryDetailsDialog.tsx +2 -2
- package/template/console/registry/RegistryDialog.tsx +56 -27
- package/template/console/registry/RegistryWorkspace.tsx +10 -5
- package/template/console/registry/integration-verification.css +25 -0
- package/template/console/reports/CaseActions.tsx +81 -0
- package/template/console/reports/CaseContinuity.tsx +27 -0
- package/template/console/reports/CaseNotices.tsx +48 -0
- package/template/console/reports/CaseOwnership.tsx +78 -0
- package/template/console/reports/CaseReviewTasks.tsx +148 -0
- package/template/console/reports/EnrichmentFindings.tsx +148 -0
- package/template/console/reports/InvestigationBrief.tsx +29 -0
- package/template/console/reports/ReportDrawer.tsx +122 -67
- package/template/console/reports/ReportWorkspace.tsx +112 -23
- package/template/console/reports/controller.ts +125 -60
- package/template/console/reports/events.ts +9 -2
- package/template/console/reports/load-inbox.ts +17 -0
- package/template/console/reports/presence-presentation.ts +52 -0
- package/template/console/reports/private-drafts.ts +32 -0
- package/template/console/reports/store.ts +2 -2
- package/template/console/reports/types.ts +50 -2
- package/template/console/reports/use-editing-access.ts +13 -0
- package/template/console/settings/SettingsWorkspace.tsx +1 -1
- package/template/console/shell/WorkspaceShell.tsx +55 -29
- package/template/console/shell/WorkspaceUpdateNotice.tsx +48 -0
- package/template/console/shell/controller.ts +23 -16
- package/template/console/shell/navigation.ts +30 -39
- package/template/console/workflows/CreatePlaybookDialog.tsx +73 -0
- package/template/console/workflows/PlaybookExamples.tsx +160 -0
- package/template/console/workflows/PlaybookFields.tsx +109 -0
- package/template/console/workflows/PlaybookGuideEditor.tsx +125 -0
- package/template/console/workflows/PlaybookHistory.tsx +106 -0
- package/template/console/workflows/WorkflowDialogs.tsx +2 -1
- package/template/console/workflows/WorkflowStudio.tsx +108 -39
- package/template/console/workflows/WorkflowWorkspace.tsx +9 -7
- package/template/console/workflows/templates.ts +3 -3
- package/template/console/workflows/types.ts +11 -0
- package/template/migrations/0001_safest_resolve_baseline.sql +0 -1
- package/template/migrations/0002_playbook_publication_evidence.sql +36 -0
- package/template/migrations/0003_action_confirmation.sql +24 -0
- package/template/migrations/0004_notice_recovery.sql +22 -0
- package/template/migrations/0005_appeal_continuity.sql +17 -0
- package/template/migrations/0006_case_ownership.sql +23 -0
- package/template/migrations/0007_integration_verification.sql +21 -0
- package/template/migrations/0008_case_escalations.sql +135 -0
- package/template/migrations/0009_participant_continuation.sql +61 -0
- package/template/migrations/0010_appeal_corrections.sql +41 -0
- package/template/npm-shrinkwrap.json +8036 -0
- package/template/package.json +31 -22
- package/template/public/_headers +16 -1
- package/template/public/console/auth-shell.js +22151 -14847
- package/template/public/console/release.json +1 -0
- package/template/public/console/workspace-features.css +2 -0
- package/template/public/embed/embed.css +3 -0
- package/template/public/embed/embed.js +19 -1
- package/template/public/embed/index.html +2 -0
- package/template/public/index.html +9 -6
- package/template/public/participant.css +2 -0
- package/template/public/participant.html +13 -0
- package/template/public/participant.js +111 -0
- package/template/public/public-report.js +21 -1
- package/template/public/report/index.html +1 -1
- package/template/public/styles.css +599 -83
- package/template/public/workspace.css +124 -0
- package/template/scripts/reports-plan.mjs +1 -1
- package/template/shared/case-escalations.ts +31 -0
- package/template/shared/integration-progress.ts +27 -0
- package/template/shared/notice-inputs.ts +3 -0
- package/template/shared/playbook-resources.ts +14 -0
- package/template/shared/playbooks.ts +249 -0
- package/template/src/agent-executor.ts +25 -8
- package/template/src/ai-observability.ts +14 -13
- package/template/src/ai-registry-validation.ts +1 -1
- package/template/src/appeal-continuity.ts +75 -0
- package/template/src/appeal-correction-state.ts +46 -0
- package/template/src/appeal-corrections.ts +112 -0
- package/template/src/appeal-decisions.ts +85 -0
- package/template/src/assistant.ts +3 -4
- package/template/src/case-escalations.ts +223 -0
- package/template/src/case-investigator.ts +179 -0
- package/template/src/component-executor.ts +5 -4
- package/template/src/configuration-registry.ts +4 -1
- package/template/src/connection-oauth.ts +12 -3
- package/template/src/database-readiness.ts +14 -0
- package/template/src/human-tasks.ts +152 -55
- package/template/src/index.ts +191 -29
- package/template/src/installation-admin.ts +2 -1
- package/template/src/integration-progress.ts +45 -0
- package/template/src/integration-verification.ts +249 -0
- package/template/src/investigation-evidence.ts +95 -0
- package/template/src/investigator-fixture.ts +30 -0
- package/template/src/notice-delivery.ts +19 -0
- package/template/src/notice-recovery.ts +81 -0
- package/template/src/operator-scope.ts +31 -0
- package/template/src/participant-access.ts +163 -0
- package/template/src/participant-case.ts +87 -0
- package/template/src/participant-customer-access.ts +93 -0
- package/template/src/participant-recovery.ts +43 -0
- package/template/src/participant-routes.ts +67 -0
- package/template/src/platform-registry-validation.ts +25 -2
- package/template/src/platform-registry.ts +10 -7
- package/template/src/playbook-resources.ts +58 -0
- package/template/src/report-admin.ts +9 -2
- package/template/src/report-auth.ts +1 -28
- package/template/src/report-better-auth.ts +18 -6
- package/template/src/report-delivery.ts +149 -148
- package/template/src/report-email-inbound.ts +33 -22
- package/template/src/report-email-template.ts +5 -2
- package/template/src/report-email.ts +7 -30
- package/template/src/report-governance.ts +42 -45
- package/template/src/report-http.ts +37 -2
- package/template/src/report-operations.ts +30 -67
- package/template/src/report-operator-accounts.ts +7 -6
- package/template/src/report-ownership.ts +64 -0
- package/template/src/report-presence.ts +15 -9
- package/template/src/report-repository.ts +16 -7
- package/template/src/report-turnstile.ts +7 -3
- package/template/src/report-types.ts +1 -0
- package/template/src/report-workflow.ts +183 -249
- package/template/src/workflow-actions.ts +248 -156
- package/template/src/workflow-compiler.ts +63 -12
- package/template/src/workflow-dynamic-runtime.ts +20 -9
- package/template/src/workflow-effects.ts +117 -39
- package/template/src/workflow-event-transport.ts +16 -0
- package/template/src/workflow-expressions.ts +30 -0
- package/template/src/workflow-loader-code.ts +21 -0
- package/template/src/workflow-platform-types.ts +3 -0
- package/template/src/workflow-platform-validation.ts +23 -1
- package/template/src/workflow-repository.ts +131 -28
- package/template/src/workflow-runs.ts +61 -13
- package/template/src/workflow-simulator.ts +7 -4
- package/template/src/workspace-governance.ts +6 -4
- package/template/tsconfig.json +1 -0
- package/template/vite.console.config.ts +30 -2
- package/template/worker-configuration.d.ts +3 -2
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { PlaybookResources } from "../shared/playbook-resources";
|
|
2
|
+
import type { JsonObject } from "./workflow-platform-types";
|
|
3
|
+
|
|
4
|
+
function parsed<T>(value: string, fallback: T): T {
|
|
5
|
+
try { return JSON.parse(value) as T; } catch { return fallback; }
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/** A secret-free catalogue for authors. Execution rechecks every pinned capability. */
|
|
9
|
+
export async function loadPlaybookResources(db: D1Database): Promise<PlaybookResources> {
|
|
10
|
+
const [queues, policies, capabilities, agents, notices, forms] = await Promise.all([
|
|
11
|
+
db.prepare("SELECT id, name FROM queue_definitions WHERE installation_id = 'default' AND status = 'active' AND enabled = 1 AND queue_kind = 'human' ORDER BY name").all<PlaybookResources["queues"][number]>(),
|
|
12
|
+
db.prepare("SELECT id, title AS name, version, rules_json AS rulesJson FROM policy_versions WHERE installation_id = 'default' AND published_at IS NOT NULL ORDER BY title, version DESC").all<{ id: string; name: string; version: number; rulesJson: string }>(),
|
|
13
|
+
db.prepare(`SELECT d.id, d.name, d.description, v.id AS versionId, d.effect_class AS effect,
|
|
14
|
+
d.status, v.retired_at AS retiredAt, cv.retired_at AS connectionRetiredAt,
|
|
15
|
+
c.id AS connectionId, c.name AS connectionName, c.status AS connectionStatus,
|
|
16
|
+
v.input_schema_json AS inputSchemaJson, v.allowed_input_fields_json AS allowedFieldsJson,
|
|
17
|
+
v.approval_policy_json AS approvalJson
|
|
18
|
+
FROM component_definitions d JOIN component_versions v ON v.id = d.active_version_id
|
|
19
|
+
LEFT JOIN connection_versions cv ON cv.id = v.connection_version_id
|
|
20
|
+
LEFT JOIN connection_definitions c ON c.id = cv.connection_id
|
|
21
|
+
WHERE d.installation_id = 'default' AND d.status != 'archived' ORDER BY d.name`).all<{
|
|
22
|
+
id: string; name: string; description: string; versionId: string; effect: "read_only" | "side_effecting";
|
|
23
|
+
status: string; retiredAt: string | null; connectionRetiredAt: string | null; connectionId: string | null; connectionName: string | null; connectionStatus: string | null;
|
|
24
|
+
inputSchemaJson: string; allowedFieldsJson: string; approvalJson: string;
|
|
25
|
+
}>(),
|
|
26
|
+
db.prepare(`SELECT d.id, d.name, v.id AS versionId, m.provider, m.model
|
|
27
|
+
FROM agent_definitions d JOIN agent_versions v ON v.id = d.active_version_id
|
|
28
|
+
JOIN model_alias_versions m ON m.id = v.model_alias_version_id
|
|
29
|
+
JOIN model_aliases a ON a.id = m.alias_id
|
|
30
|
+
WHERE d.installation_id = 'default' AND d.status = 'active' AND d.agent_kind = 'specialist'
|
|
31
|
+
AND v.retired_at IS NULL AND m.retired_at IS NULL AND a.status = 'active' AND m.provider='workers_ai' AND m.model LIKE '@cf/%' ORDER BY d.name`).all<PlaybookResources["agents"][number]>(),
|
|
32
|
+
db.prepare(`SELECT id, template_key AS name, audience, body_template AS body, version
|
|
33
|
+
FROM message_template_versions WHERE installation_id = 'default' AND published_at IS NOT NULL
|
|
34
|
+
AND purpose IN ('outcome', 'affected_user_notice') ORDER BY template_key, version DESC`).all<PlaybookResources["notices"][number]>(),
|
|
35
|
+
db.prepare(`SELECT reasons_json AS reasonsJson, target_types_json AS targetsJson, fields_json AS fieldsJson
|
|
36
|
+
FROM report_form_versions WHERE installation_id='default' AND published_at IS NOT NULL AND retired_at IS NULL ORDER BY version DESC, id`).all<{ reasonsJson: string; targetsJson: string; fieldsJson: string }>(),
|
|
37
|
+
]);
|
|
38
|
+
const reasons = new Map<string, string>(), targets = new Set<string>(), fields = new Map<string, string>([
|
|
39
|
+
["target.reference", "Reported content or account reference"], ["target.type", "Reported target type"],
|
|
40
|
+
["report.reason_code", "Report reason"], ["report.public_reference", "Case reference"],
|
|
41
|
+
]);
|
|
42
|
+
for (const form of forms.results) {
|
|
43
|
+
for (const reason of parsed<{ code: string; label: string }[]>(form.reasonsJson, [])) if (typeof reason.code === "string" && typeof reason.label === "string" && !reasons.has(reason.code)) reasons.set(reason.code, reason.label);
|
|
44
|
+
for (const target of parsed<string[]>(form.targetsJson, [])) if (typeof target === "string") targets.add(target);
|
|
45
|
+
for (const field of parsed<{ key: string; label: string }[]>(form.fieldsJson, [])) if (typeof field.key === "string" && typeof field.label === "string" && !fields.has(`answers.${field.key}`)) fields.set(`answers.${field.key}`, field.label);
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
scope: { reasons: [...reasons].map(([code, label]) => ({ code, label })), targetTypes: [...targets], fields: [...fields].map(([path, label]) => ({ path, label })) },
|
|
49
|
+
queues: queues.results,
|
|
50
|
+
policies: policies.results.map(({ rulesJson, ...policy }) => ({ ...policy, rules: parsed<PlaybookResources["policies"][number]["rules"]>(rulesJson, []) })),
|
|
51
|
+
capabilities: capabilities.results.map(({ status, retiredAt, connectionRetiredAt, connectionStatus, inputSchemaJson, allowedFieldsJson, approvalJson, ...capability }) => {
|
|
52
|
+
const approval = parsed<{ mode?: string }>(approvalJson, {}).mode;
|
|
53
|
+
return { ...capability, available: status === "active" && !retiredAt && (!capability.connectionId || (connectionStatus === "active" && !connectionRetiredAt)),
|
|
54
|
+
inputSchema: parsed<JsonObject>(inputSchemaJson, {}), allowedFields: parsed<string[]>(allowedFieldsJson, []), approval: approval === "human" || approval === "bounded_auto" ? approval : null };
|
|
55
|
+
}),
|
|
56
|
+
agents: agents.results, notices: notices.results,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -247,7 +247,14 @@ export async function listReportActions(db: D1Database, reportId: string): Promi
|
|
|
247
247
|
p.payload_digest AS payloadDigest, p.authority_mode AS authorityMode,
|
|
248
248
|
p.operation_id AS operationId, p.compensates_proposal_id AS compensatesProposalId,
|
|
249
249
|
p.delivery_attempt_count AS attemptCount, p.last_error_code AS errorCode,
|
|
250
|
-
p.delivery_terminal AS terminal, p.created_at AS createdAt, p.updated_at AS updatedAt
|
|
250
|
+
p.delivery_terminal AS terminal, p.created_at AS createdAt, p.updated_at AS updatedAt,
|
|
251
|
+
p.accepted_at AS acceptedAt, p.confirmed_at AS confirmedAt, p.confirmation_deadline_at AS confirmationDeadlineAt,
|
|
252
|
+
p.delivery_cycle AS deliveryCycle,
|
|
253
|
+
CASE WHEN p.state = 'applied' AND p.confirmed_at IS NULL THEN 'legacy_applied'
|
|
254
|
+
WHEN p.accepted_at IS NOT NULL AND p.delivery_terminal = 0 THEN 'awaiting_confirmation' ELSE p.state END AS confirmationState,
|
|
255
|
+
(SELECT name FROM component_definitions WHERE id = (SELECT definition_id FROM component_versions WHERE id = p.component_version_id)) AS capabilityName,
|
|
256
|
+
CASE WHEN p.state = 'failed' AND p.delivery_terminal = 1 AND json_extract(p.approval_policy_json, '$.expires_at') > strftime('%Y-%m-%dT%H:%M:%fZ','now')
|
|
257
|
+
AND EXISTS (SELECT 1 FROM workflow_runs WHERE id = p.run_id AND state NOT IN ('terminated','cancelled')) THEN 1 ELSE 0 END AS retryable
|
|
251
258
|
FROM action_proposals p WHERE p.report_id = ?1 ORDER BY p.created_at DESC, p.id DESC
|
|
252
259
|
`).bind(reportId).all<Record<string, unknown>>(),
|
|
253
260
|
db.prepare(`
|
|
@@ -260,7 +267,7 @@ export async function listReportActions(db: D1Database, reportId: string): Promi
|
|
|
260
267
|
]);
|
|
261
268
|
const combined: Record<string, unknown>[] = [...proposals.results, ...decisions.results];
|
|
262
269
|
return combined
|
|
263
|
-
.map<Record<string, unknown>>((row) => ({ ...row, terminal: row.terminal === 1 }))
|
|
270
|
+
.map<Record<string, unknown>>((row) => ({ ...row, terminal: row.terminal === 1, retryable: row.retryable === 1 }))
|
|
264
271
|
.sort((a, b) => String(b.createdAt).localeCompare(String(a.createdAt)) || String(b.id).localeCompare(String(a.id)));
|
|
265
272
|
}
|
|
266
273
|
|
|
@@ -90,34 +90,7 @@ export async function requireOperator(
|
|
|
90
90
|
return session;
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
export
|
|
94
|
-
if (session.queueScope === null || session.queueScope === undefined) return;
|
|
95
|
-
if (!queueId || !session.queueScope.includes(queueId)) throw new ApiError(403, "operator_queue_scope_denied", "Your role is not authorized for this queue.");
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export async function assertOperatorReportAccess(
|
|
99
|
-
db: D1Database,
|
|
100
|
-
session: OperatorSession,
|
|
101
|
-
reportId: string,
|
|
102
|
-
): Promise<void> {
|
|
103
|
-
if (session.queueScope === null || session.queueScope === undefined) return;
|
|
104
|
-
const report = await db.prepare(`SELECT queue_id AS queueId FROM reports WHERE id = ?1 LIMIT 1`)
|
|
105
|
-
.bind(reportId).first<{ queueId: string | null }>();
|
|
106
|
-
if (!report) throw new ApiError(404, "report_not_found", "The report does not exist.");
|
|
107
|
-
assertOperatorQueueAccess(session, report.queueId);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export async function assertOperatorWorkflowRunAccess(
|
|
111
|
-
db: D1Database,
|
|
112
|
-
session: OperatorSession,
|
|
113
|
-
runId: string,
|
|
114
|
-
): Promise<void> {
|
|
115
|
-
if (session.queueScope === null || session.queueScope === undefined) return;
|
|
116
|
-
const run = await db.prepare(`SELECT queue_id AS queueId FROM workflow_runs WHERE id = ?1 LIMIT 1`)
|
|
117
|
-
.bind(runId).first<{ queueId: string | null }>();
|
|
118
|
-
if (!run) throw new ApiError(404, "workflow_run_not_found", "The workflow run does not exist.");
|
|
119
|
-
assertOperatorQueueAccess(session, run.queueId);
|
|
120
|
-
}
|
|
93
|
+
export { assertOperatorQueueAccess, assertOperatorReportAccess, assertOperatorWorkflowRunAccess } from "./operator-scope";
|
|
121
94
|
|
|
122
95
|
export function projectOperatorFields<T>(session: OperatorSession, resource: string, value: T): T {
|
|
123
96
|
if (session.fieldScope === null || session.fieldScope === undefined) return value;
|
|
@@ -5,6 +5,7 @@ import type { GenericOAuthConfig } from "better-auth/plugins/generic-oauth";
|
|
|
5
5
|
import { authenticationEmailBinding } from "./report-email";
|
|
6
6
|
import { renderAuthenticationEmail } from "./report-email-template";
|
|
7
7
|
import type { AuthenticationEmailKind } from "./report-email-template";
|
|
8
|
+
import { readBoundedBytes, readJsonObject } from "./report-http";
|
|
8
9
|
import { loadWorkspaceBrand } from "./workspace-branding";
|
|
9
10
|
|
|
10
11
|
const INVITATION_COOKIE = "safest_invitation";
|
|
@@ -332,13 +333,21 @@ function cloudflareProvider(env: BetterAuthEnv): GenericOAuthConfig | null {
|
|
|
332
333
|
headers: { authorization: `Bearer ${tokens.accessToken}`, accept: "application/json" },
|
|
333
334
|
});
|
|
334
335
|
if (!response.ok) {
|
|
335
|
-
response.body?.cancel();
|
|
336
|
+
await response.body?.cancel().catch(() => undefined);
|
|
336
337
|
return null;
|
|
337
338
|
}
|
|
338
|
-
|
|
339
|
+
let envelope: {
|
|
339
340
|
success?: boolean;
|
|
340
341
|
result?: { id?: string; email?: string; first_name?: string; last_name?: string };
|
|
341
342
|
};
|
|
343
|
+
try {
|
|
344
|
+
const bytes = await readBoundedBytes(response.body, 32 * 1024, () => new Error("cloudflare_profile_too_large"));
|
|
345
|
+
const parsed: unknown = JSON.parse(new TextDecoder().decode(bytes));
|
|
346
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return null;
|
|
347
|
+
envelope = parsed;
|
|
348
|
+
} catch {
|
|
349
|
+
return null;
|
|
350
|
+
}
|
|
342
351
|
const profile = envelope.success ? envelope.result : undefined;
|
|
343
352
|
if (!profile?.id || !profile.email) return null;
|
|
344
353
|
const name = [profile.first_name, profile.last_name].filter(Boolean).join(" ").trim();
|
|
@@ -646,6 +655,11 @@ function ownerSetupError(status = 400): Response {
|
|
|
646
655
|
}, { status, headers: { "cache-control": "no-store", "referrer-policy": "no-referrer" } });
|
|
647
656
|
}
|
|
648
657
|
|
|
658
|
+
async function linkToken(request: Request): Promise<string> {
|
|
659
|
+
const body = await readJsonObject(request, 8 * 1024);
|
|
660
|
+
return typeof body.token === "string" ? body.token : "";
|
|
661
|
+
}
|
|
662
|
+
|
|
649
663
|
export async function inspectOwnerSetup(request: Request, env: BetterAuthEnv): Promise<Response> {
|
|
650
664
|
if (request.method !== "POST") return new Response("Method Not Allowed", { status: 405, headers: { allow: "POST" } });
|
|
651
665
|
if (!await enforceOwnerSetupRateLimit(request, env)) {
|
|
@@ -653,8 +667,7 @@ export async function inspectOwnerSetup(request: Request, env: BetterAuthEnv): P
|
|
|
653
667
|
error: { code: "owner_setup_rate_limited", message: "Too many setup attempts. Try again in ten minutes." },
|
|
654
668
|
}, { status: 429, headers: { "cache-control": "no-store", "retry-after": String(OWNER_SETUP_WINDOW_SECONDS) } });
|
|
655
669
|
}
|
|
656
|
-
const
|
|
657
|
-
const token = typeof body?.token === "string" ? body.token : "";
|
|
670
|
+
const token = await linkToken(request);
|
|
658
671
|
if (!/^[A-Za-z0-9_-]{43,200}$/u.test(token)) return ownerSetupError();
|
|
659
672
|
const now = new Date().toISOString();
|
|
660
673
|
const setup = await env.DB.prepare(`
|
|
@@ -695,8 +708,7 @@ export async function inspectInvitation(
|
|
|
695
708
|
env: BetterAuthEnv,
|
|
696
709
|
): Promise<Response> {
|
|
697
710
|
if (request.method !== "POST") return new Response("Method Not Allowed", { status: 405, headers: { allow: "POST" } });
|
|
698
|
-
const
|
|
699
|
-
const token = typeof body?.token === "string" ? body.token : "";
|
|
711
|
+
const token = await linkToken(request);
|
|
700
712
|
const invitation = await findPendingInvitationByToken(env, token);
|
|
701
713
|
if (!invitation) {
|
|
702
714
|
return Response.json({ error: { code: "invalid_invitation", message: "This invitation link is invalid or expired." } }, { status: 400 });
|