create-safest-tools 0.2.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/LICENSE +201 -0
- package/README.md +71 -0
- package/bin/create-safest-tools.mjs +12 -0
- package/package.json +34 -0
- package/src/cli.mjs +128 -0
- package/src/config.mjs +151 -0
- package/src/scaffold.mjs +30 -0
- package/template/LICENSE +201 -0
- package/template/README.md +35 -0
- package/template/console/README.md +28 -0
- package/template/console/analytics/AnalyticsWorkspace.tsx +55 -0
- package/template/console/analytics/controller.ts +133 -0
- package/template/console/analytics/events.ts +33 -0
- package/template/console/analytics/store.ts +33 -0
- package/template/console/analytics/types.ts +38 -0
- package/template/console/appeals/AppealWorkspace.tsx +73 -0
- package/template/console/appeals/controller.ts +125 -0
- package/template/console/appeals/events.ts +33 -0
- package/template/console/appeals/store.ts +35 -0
- package/template/console/appeals/types.ts +37 -0
- package/template/console/assistant/AssistantWorkspace.tsx +133 -0
- package/template/console/assistant/types.ts +34 -0
- package/template/console/auth/AccountJourney.tsx +69 -0
- package/template/console/auth/InvitationAcceptance.tsx +145 -0
- package/template/console/auth/OAuthButtons.tsx +78 -0
- package/template/console/auth/OperatorLogin.tsx +110 -0
- package/template/console/auth/PasswordRecovery.tsx +132 -0
- package/template/console/auth/account-route.ts +15 -0
- package/template/console/auth/browser-navigation.ts +7 -0
- package/template/console/auth/events.ts +15 -0
- package/template/console/command/CommandCentre.tsx +119 -0
- package/template/console/command/controller.ts +267 -0
- package/template/console/command/events.ts +19 -0
- package/template/console/command/store.ts +36 -0
- package/template/console/command/types.ts +61 -0
- package/template/console/components/AnalystIdentity.tsx +25 -0
- package/template/console/components/PageHeader.tsx +27 -0
- package/template/console/configuration/ConfigurationDialog.tsx +200 -0
- package/template/console/configuration/ConfigurationWorkspace.tsx +66 -0
- package/template/console/configuration/FormBuilder.tsx +143 -0
- package/template/console/configuration/api.ts +40 -0
- package/template/console/configuration/events.ts +14 -0
- package/template/console/configuration/types.ts +79 -0
- package/template/console/lib/format.ts +49 -0
- package/template/console/lib/http.ts +96 -0
- package/template/console/main.tsx +225 -0
- package/template/console/operations/OperationsWorkspace.tsx +126 -0
- package/template/console/operations/controller.ts +237 -0
- package/template/console/operations/events.ts +37 -0
- package/template/console/operations/store.ts +32 -0
- package/template/console/operations/types.ts +107 -0
- package/template/console/people/PeopleWorkspace.tsx +81 -0
- package/template/console/people/types.ts +25 -0
- package/template/console/profile/ProfileWorkspace.tsx +136 -0
- package/template/console/profile/events.ts +9 -0
- package/template/console/profile/types.ts +6 -0
- package/template/console/quality/QualityWorkspace.tsx +87 -0
- package/template/console/quality/controller.ts +154 -0
- package/template/console/quality/events.ts +34 -0
- package/template/console/quality/store.ts +36 -0
- package/template/console/quality/types.ts +70 -0
- package/template/console/queues/QueueEditor.tsx +173 -0
- package/template/console/queues/QueueWorkspace.tsx +109 -0
- package/template/console/queues/controller.ts +194 -0
- package/template/console/queues/events.ts +34 -0
- package/template/console/queues/store.ts +37 -0
- package/template/console/queues/types.ts +102 -0
- package/template/console/registry/RegistryDialog.tsx +198 -0
- package/template/console/registry/RegistryWorkspace.tsx +108 -0
- package/template/console/registry/events.ts +14 -0
- package/template/console/registry/types.ts +52 -0
- package/template/console/reports/ReportDrawer.tsx +159 -0
- package/template/console/reports/ReportWorkspace.tsx +90 -0
- package/template/console/reports/controller.ts +517 -0
- package/template/console/reports/events.ts +42 -0
- package/template/console/reports/store.ts +39 -0
- package/template/console/reports/types.ts +230 -0
- package/template/console/settings/BrandEditor.tsx +126 -0
- package/template/console/settings/ChannelDialog.tsx +241 -0
- package/template/console/settings/SettingsWorkspace.tsx +155 -0
- package/template/console/settings/events.ts +19 -0
- package/template/console/settings/handoff.ts +22 -0
- package/template/console/settings/types.ts +93 -0
- package/template/console/shell/WorkspaceShell.tsx +160 -0
- package/template/console/shell/controller.ts +182 -0
- package/template/console/shell/events.ts +25 -0
- package/template/console/shell/navigation.ts +61 -0
- package/template/console/shell/store.ts +56 -0
- package/template/console/shell/types.ts +86 -0
- package/template/console/workflows/CreateWorkflowDialog.tsx +87 -0
- package/template/console/workflows/WorkflowCanvas.tsx +42 -0
- package/template/console/workflows/WorkflowDialogs.tsx +6 -0
- package/template/console/workflows/WorkflowStudio.tsx +331 -0
- package/template/console/workflows/WorkflowWorkspace.tsx +82 -0
- package/template/console/workflows/events.ts +17 -0
- package/template/console/workflows/graph.ts +156 -0
- package/template/console/workflows/templates.ts +70 -0
- package/template/console/workflows/types.ts +201 -0
- package/template/gitignore.template +18 -0
- package/template/migrations/0001_reports_foundation.sql +444 -0
- package/template/migrations/0002_human_report_loop.sql +65 -0
- package/template/migrations/0003_delivery_reliability.sql +18 -0
- package/template/migrations/0004_public_intake.sql +14 -0
- package/template/migrations/0005_operations_visibility.sql +24 -0
- package/template/migrations/0006_ai_governance.sql +198 -0
- package/template/migrations/0007_ai_release_gates.sql +6 -0
- package/template/migrations/0008_retention_analytics_exports.sql +52 -0
- package/template/migrations/0009_retention_derived_copies.sql +14 -0
- package/template/migrations/0010_ai_quality_controls.sql +26 -0
- package/template/migrations/0011_analyst_presence.sql +28 -0
- package/template/migrations/0012_queue_policies.sql +87 -0
- package/template/migrations/0013_routing_agents.sql +63 -0
- package/template/migrations/0014_webhook_enrichments.sql +122 -0
- package/template/migrations/0015_queue_owned_ai.sql +55 -0
- package/template/migrations/0016_operator_accounts.sql +67 -0
- package/template/migrations/0017_operator_profiles_and_recovery.sql +33 -0
- package/template/migrations/0018_platform_configuration.sql +382 -0
- package/template/migrations/0019_workflow_authoring_runtime.sql +372 -0
- package/template/migrations/0020_tasks_findings_assistant_budgets.sql +427 -0
- package/template/migrations/0021_abuse_evidence_operations.sql +324 -0
- package/template/migrations/0022_workflow_dispatch_operations.sql +42 -0
- package/template/migrations/0023_component_connection_execution.sql +75 -0
- package/template/migrations/0024_access_runtime_integrity.sql +72 -0
- package/template/migrations/0025_installation_timezone.sql +11 -0
- package/template/migrations/0026_ai_and_egress_execution_controls.sql +49 -0
- package/template/migrations/0027_prompt_and_ai_registry.sql +37 -0
- package/template/migrations/0028_step_attempt_ai_provenance.sql +13 -0
- package/template/migrations/0029_evidence_fetch_transport.sql +5 -0
- package/template/migrations/0030_evidence_dlq_incidents.sql +45 -0
- package/template/migrations/0031_shadow_quality_integrity.sql +7 -0
- package/template/migrations/0032_action_delivery_outbox.sql +55 -0
- package/template/migrations/0033_configuration_and_assistant_drafts.sql +43 -0
- package/template/migrations/0034_installation_integrations.sql +31 -0
- package/template/migrations/0035_workspace_governance.sql +21 -0
- package/template/migrations/0036_published_routing_baseline.sql +15 -0
- package/template/migrations/0037_builtin_phishing_specialist.sql +71 -0
- package/template/migrations/0038_remove_deprecated_enrichment_runtime.sql +228 -0
- package/template/migrations/0039_secure_reporting_channels.sql +45 -0
- package/template/migrations/0040_notification_only_reporting.sql +24 -0
- package/template/migrations/0041_better_auth_credentials.sql +17 -0
- package/template/package.json +47 -0
- package/template/public/_headers +27 -0
- package/template/public/app-icon-192.png +0 -0
- package/template/public/app-icon-512.png +0 -0
- package/template/public/brand-icon.svg +7 -0
- package/template/public/brand-tokens.css +80 -0
- package/template/public/console/auth-shell.js +19340 -0
- package/template/public/customer-brand.js +58 -0
- package/template/public/embed/embed.css +139 -0
- package/template/public/embed/embed.js +408 -0
- package/template/public/embed/index.html +91 -0
- package/template/public/favicon.svg +7 -0
- package/template/public/fonts/Manrope-Variable.ttf +0 -0
- package/template/public/fonts/Newsreader-Italic-Variable.ttf +0 -0
- package/template/public/fonts/Newsreader-Variable.ttf +0 -0
- package/template/public/index.html +123 -0
- package/template/public/logo-primary.svg +7 -0
- package/template/public/logo-reversed.svg +7 -0
- package/template/public/manifest.webmanifest +21 -0
- package/template/public/public-report.js +184 -0
- package/template/public/report/index.html +39 -0
- package/template/public/report/public-report.css +20 -0
- package/template/public/social-card.png +0 -0
- package/template/public/styles.css +1521 -0
- package/template/public/widget.css +80 -0
- package/template/public/widget.js +220 -0
- package/template/reports.config.example.json +38 -0
- package/template/reports.schema.json +89 -0
- package/template/scripts/reports-auth-onboarding.mjs +180 -0
- package/template/scripts/reports-backup.mjs +276 -0
- package/template/scripts/reports-cloudflare-preflight.mjs +152 -0
- package/template/scripts/reports-deploy.mjs +173 -0
- package/template/scripts/reports-plan.mjs +226 -0
- package/template/scripts/reports-restore.mjs +180 -0
- package/template/scripts/reports-secrets.mjs +73 -0
- package/template/scripts/reports-uninstall-plan.mjs +32 -0
- package/template/src/agent-executor.ts +330 -0
- package/template/src/ai-observability.ts +163 -0
- package/template/src/ai-registry-validation.ts +244 -0
- package/template/src/ai-registry.ts +292 -0
- package/template/src/api-cursor.ts +84 -0
- package/template/src/assistant.ts +554 -0
- package/template/src/audit.ts +39 -0
- package/template/src/backup-service.ts +269 -0
- package/template/src/budget-control.ts +127 -0
- package/template/src/component-executor.ts +845 -0
- package/template/src/configuration-registry.ts +550 -0
- package/template/src/connection-egress.ts +430 -0
- package/template/src/connection-oauth.ts +368 -0
- package/template/src/evidence-service.ts +335 -0
- package/template/src/human-tasks.ts +316 -0
- package/template/src/index.ts +4114 -0
- package/template/src/installation-admin.ts +301 -0
- package/template/src/intake-abuse.ts +156 -0
- package/template/src/platform-registry-validation.ts +367 -0
- package/template/src/platform-registry.ts +753 -0
- package/template/src/report-admin.ts +342 -0
- package/template/src/report-ai-quality.ts +390 -0
- package/template/src/report-ai-validation.ts +80 -0
- package/template/src/report-ai.ts +857 -0
- package/template/src/report-auth.ts +292 -0
- package/template/src/report-better-auth.ts +583 -0
- package/template/src/report-context-schema.ts +132 -0
- package/template/src/report-context.ts +126 -0
- package/template/src/report-crypto.ts +142 -0
- package/template/src/report-delivery.ts +579 -0
- package/template/src/report-form-validation.ts +51 -0
- package/template/src/report-governance.ts +510 -0
- package/template/src/report-http.ts +90 -0
- package/template/src/report-operations.ts +685 -0
- package/template/src/report-operator-accounts.ts +810 -0
- package/template/src/report-presence.ts +398 -0
- package/template/src/report-queue-validation.ts +309 -0
- package/template/src/report-queues.ts +478 -0
- package/template/src/report-repository.ts +972 -0
- package/template/src/report-router-agent.ts +328 -0
- package/template/src/report-router-validation.ts +81 -0
- package/template/src/report-routing.ts +178 -0
- package/template/src/report-turnstile.ts +142 -0
- package/template/src/report-types.ts +224 -0
- package/template/src/report-validation.ts +279 -0
- package/template/src/report-workflow-validation.ts +119 -0
- package/template/src/report-workflow.ts +886 -0
- package/template/src/shadow-quality.ts +278 -0
- package/template/src/workflow-actions.ts +782 -0
- package/template/src/workflow-compiler.ts +230 -0
- package/template/src/workflow-dynamic-runtime.ts +613 -0
- package/template/src/workflow-effects.ts +316 -0
- package/template/src/workflow-expressions.ts +191 -0
- package/template/src/workflow-platform-types.ts +121 -0
- package/template/src/workflow-platform-validation.ts +540 -0
- package/template/src/workflow-repository.ts +916 -0
- package/template/src/workflow-runs.ts +686 -0
- package/template/src/workflow-simulator.ts +211 -0
- package/template/src/workspace-branding.ts +128 -0
- package/template/src/workspace-governance.ts +279 -0
- package/template/tsconfig.console.json +23 -0
- package/template/tsconfig.json +22 -0
- package/template/vite.console.config.ts +20 -0
- package/template/worker-configuration.d.ts +65 -0
package/template/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Safest Tools contributors
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Safest Resolve
|
|
2
|
+
|
|
3
|
+
Safest Resolve handles abuse, safety, fraud, and policy reports in the Cloudflare account that owns this project. Reports arrive through the signed widget, public form, or server API. A published routing version assigns the queue, and the pinned workflow records evidence checks, human review, messages, decisions, application actions, and appeals.
|
|
4
|
+
|
|
5
|
+
The service does not proxy or inspect normal application traffic. The customer application remains responsible for the content references it provides and for carrying out any approved action.
|
|
6
|
+
|
|
7
|
+
This project deploys one Worker, one D1 database, four private R2 buckets, a Dynamic Workflow, report and delivery Queues, an operations dead-letter Queue, a presence Durable Object, static assets, a Worker Loader, and a Workers AI binding. The Cloudflare account owner creates the Access application and owns every secret, webhook, log, and retained row.
|
|
8
|
+
|
|
9
|
+
Before deployment:
|
|
10
|
+
|
|
11
|
+
1. Review `reports.config.json` and `npm run setup:plan`.
|
|
12
|
+
2. Create a Cloudflare Access self-hosted application for `<reports-host>/v1/infrastructure/*`; put its 64-character AUD in `access.audience` and keep `access.ownerEmails` restricted to infrastructure owners.
|
|
13
|
+
3. Under Cloudflare Email Service → Email Sending, onboard the configured sender domain. Password verification, invitations, and password recovery to arbitrary recipients depend on domain onboarding.
|
|
14
|
+
4. Run `npm run setup`. The guided setup signs in through Wrangler, verifies Workers Paid before provisioning, creates owner-only local secrets, and walks through optional Google, GitHub, and Cloudflare OAuth credentials with exact callback URLs.
|
|
15
|
+
5. Bootstrap the infrastructure owner, then invite administrators and analysts from People. Invited users do not need Cloudflare accounts and can upload a JPEG, PNG, or WebP profile picture up to 2 MB. Names and workspace roles are always displayed separately.
|
|
16
|
+
6. Type the exact installation confirmation when setup requests it.
|
|
17
|
+
|
|
18
|
+
Setup creates D1, four private R2 buckets, and three Queues, applies report migrations, and deploys the Worker with Dynamic Workflows. After bootstrap, verify the `database`, `workflow_runtime`, `workers_ai`, `object_storage`, and `queues` setup features, then require an authenticated `GET /ready` response of 200. Public `GET /health` is liveness only. Better Auth owns password hashing, email verification, OAuth accounts, sessions, and one-time password-reset tokens in D1. Upgrades always back up D1 before migrations and deployment.
|
|
19
|
+
|
|
20
|
+
Administrators build and preview questions in **Configuration → Intake forms**, set the logo, colours, fonts, and shape in **Settings → Branding**, then choose a private hosted page, signed-in product widget, or anonymous product widget in **Settings → Reporting channels**. Hosted pages and anonymous widgets need no API key. Signed-in widgets use one small customer-backend endpoint; verified reporter, target, and registered trusted facts stay server-side while the browser receives only a short-lived opaque token. Every public submission is verified with Turnstile inside a Resolve-owned isolated frame.
|
|
21
|
+
|
|
22
|
+
Cloudflare Email Service and an `--email-from reports@example.com` address on an onboarded Email Sending domain are required for invitations, email verification, and password recovery. Participant notifications may still use a configured signed customer notification webhook.
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm run backup:plan
|
|
26
|
+
npm run backup
|
|
27
|
+
npm run restore:verify -- .safest/backups/<backup-directory>
|
|
28
|
+
npm run restore:plan -- .safest/backups/<backup-directory> --target-config reports.restore.config.json
|
|
29
|
+
npm run upgrade:plan
|
|
30
|
+
npm run upgrade
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
`npm run uninstall:plan` is deliberately read-only. It lists only the resources named by this installation and preserves D1, all private R2 buckets, and Access by default.
|
|
34
|
+
|
|
35
|
+
Verified backups contain the D1 export plus all objects from the four private R2 buckets, with a stable inventory and SHA-256 digests. They intentionally exclude pending Queue messages, live Workflow engine state, Worker secrets, external webhook state, and ephemeral analyst presence. Restore planning requires a separately named target installation and does not mutate Cloudflare.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Operator console
|
|
2
|
+
|
|
3
|
+
The console uses React, TypeScript, and Vite. Each product area keeps its DOM, typed state, controller, and API calls together.
|
|
4
|
+
|
|
5
|
+
## What runs in React
|
|
6
|
+
|
|
7
|
+
- **Account access:** sign-in, infrastructure-owner bootstrap, password reset, invitation acceptance, and optional profile-picture upload.
|
|
8
|
+
- **Workspace shell:** header, responsive navigation, current route, health, analyst identity, and permission-aware navigation.
|
|
9
|
+
- **Command centre:** metrics, work that needs attention, queue pressure, recent workflow runs, and setup actions.
|
|
10
|
+
- **Reports and appeals:** queue filters, presence, claims, participant messages, decisions, delivery history, workflow evidence, and separate appeal ownership.
|
|
11
|
+
- **Queues and workflows:** queue policy publication, routing rollout, workflow drafts, graph editing, checks, fixture tests, publishing, and queue pins.
|
|
12
|
+
- **Components and configuration:** component and connection records, outbound allowlists, intake forms, routing rules, decision policies, message templates, and the visual form builder.
|
|
13
|
+
- **Operations and quality:** AI samples, reviewer corrections, incidents, retries, dead-letter evidence, analytics, audit verification, and CSV export.
|
|
14
|
+
- **People and settings:** invitations, password-reset emails, roles, personal profiles, deployment checks, branding, and reporting channels.
|
|
15
|
+
- **Ask Safest:** scoped conversations, citations, read-only activity, and links back to reports.
|
|
16
|
+
|
|
17
|
+
`console/components/PageHeader.tsx` defines the shared page-title pattern. `console/shell/controller.ts` handles session hydration, route selection, health, and sign-out. `console/lib/http.ts` is the authenticated HTTP boundary; event payloads never carry passwords or credentials.
|
|
18
|
+
|
|
19
|
+
Build with `npm run build:console`. Vite writes the bundle to `public/console/auth-shell.js`, and the template build copies it into standalone installations.
|
|
20
|
+
|
|
21
|
+
## Implementation rules
|
|
22
|
+
|
|
23
|
+
1. Keep each complete user task in one product-area module.
|
|
24
|
+
2. A DOM node has exactly one React owner.
|
|
25
|
+
3. Put network and formatting logic in shared typed modules before a second screen needs it.
|
|
26
|
+
4. Preserve URLs, IDs, accessibility names, and server contracts while a slice moves.
|
|
27
|
+
5. Delete replaced listeners and selectors in the same change.
|
|
28
|
+
6. Verify changes with TypeScript, unit tests, and desktop/mobile browser tests.
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { useSyncExternalStore } from "react";
|
|
2
|
+
import { PageHeader } from "../components/PageHeader";
|
|
3
|
+
import { readable } from "../lib/format";
|
|
4
|
+
import { dispatchAnalyticsPeriod, dispatchAnalyticsRefresh, dispatchAuditVerification, dispatchReportExport } from "./events";
|
|
5
|
+
import { getAnalyticsWorkspaceSnapshot, subscribeToAnalyticsWorkspace } from "./store";
|
|
6
|
+
import type { AnalyticsSeriesRow } from "./types";
|
|
7
|
+
|
|
8
|
+
function metricTotal(series: AnalyticsSeriesRow[], metricKey: string, dimensionKey: string): number {
|
|
9
|
+
return series.filter((row) => row.metricKey === metricKey && row.dimensionKey === dimensionKey)
|
|
10
|
+
.reduce((sum, row) => sum + Number(row.value || 0), 0);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function readableDuration(seconds: number | null): string {
|
|
14
|
+
if (seconds === null) return "—";
|
|
15
|
+
if (seconds < 60) return `${seconds}s`;
|
|
16
|
+
if (seconds < 3600) return `${Math.round(seconds / 60)}m`;
|
|
17
|
+
if (seconds < 86400) return `${Math.round(seconds / 3600)}h`;
|
|
18
|
+
return `${Math.round(seconds / 86400)}d`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function AnalyticsWorkspace() {
|
|
22
|
+
const snapshot = useSyncExternalStore(subscribeToAnalyticsWorkspace, getAnalyticsWorkspaceSnapshot, getAnalyticsWorkspaceSnapshot);
|
|
23
|
+
const analytics = snapshot.analytics;
|
|
24
|
+
const received = analytics ? metricTotal(analytics.series, "reports_received", "source") : 0;
|
|
25
|
+
const decisions = analytics ? metricTotal(analytics.series, "decisions", "maker_type") : 0;
|
|
26
|
+
const backlog = analytics?.backlog.reduce((sum, row) => sum + Number(row.count || 0), 0) ?? 0;
|
|
27
|
+
const reasons = new Map<string, number>();
|
|
28
|
+
for (const row of analytics?.series ?? []) {
|
|
29
|
+
if (row.metricKey === "reports_received" && row.dimensionKey === "reason") reasons.set(row.dimensionValue, (reasons.get(row.dimensionValue) ?? 0) + Number(row.value || 0));
|
|
30
|
+
}
|
|
31
|
+
const reasonRows = [...reasons.entries()].sort((left, right) => right[1] - left[1]);
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<div className="page-stack" data-react-slice="analytics-workspace">
|
|
35
|
+
<PageHeader titleId="analytics-title" title="Reports and outcomes" description="Review report volume, decisions, backlogs, and audit checks.">
|
|
36
|
+
<div className="surface-buttons">
|
|
37
|
+
{snapshot.canVerifyAudit ? <button className="secondary" type="button" disabled={snapshot.auditPending} onClick={dispatchAuditVerification}>{snapshot.auditPending ? "Verifying…" : "Verify audit"}</button> : null}
|
|
38
|
+
{snapshot.canExport ? <button className="secondary" type="button" disabled={snapshot.exportPending} onClick={dispatchReportExport}>{snapshot.exportPending ? "Exporting…" : "Export CSV"}</button> : null}
|
|
39
|
+
<button className="secondary" type="button" disabled={snapshot.refreshing || !snapshot.canRead} onClick={dispatchAnalyticsRefresh}>{snapshot.refreshing ? "Refreshing…" : "Refresh"}</button>
|
|
40
|
+
</div>
|
|
41
|
+
</PageHeader>
|
|
42
|
+
<section className="surface analytics-surface" aria-labelledby="analytics-title">
|
|
43
|
+
<div className="surface-head analytics-toolbar"><div><h2>Last {snapshot.days} days</h2><p>Counts describe reports and recorded decisions, not verified incidents.</p></div><label>Period<select value={snapshot.days} onChange={(event) => dispatchAnalyticsPeriod(Number(event.currentTarget.value))}><option value="7">7 days</option><option value="30">30 days</option><option value="90">90 days</option><option value="180">180 days</option><option value="365">365 days</option></select></label></div>
|
|
44
|
+
<div className="analytics-metrics" aria-busy={snapshot.loading || snapshot.refreshing}>
|
|
45
|
+
<article><span>Reports received</span><strong>{snapshot.loading ? "—" : received}</strong><small>Allegations, not confirmed incidents</small></article>
|
|
46
|
+
<article><span>Decisions recorded</span><strong>{snapshot.loading ? "—" : decisions}</strong><small>Human and bounded AI</small></article>
|
|
47
|
+
<article><span>Median resolution</span><strong>{snapshot.loading ? "—" : readableDuration(analytics?.resolutionSeconds.median ?? null)}</strong><small>{snapshot.loading ? "P95 —" : `P95 ${readableDuration(analytics?.resolutionSeconds.p95 ?? null)}`}</small></article>
|
|
48
|
+
<article><span>Open backlog</span><strong>{snapshot.loading ? "—" : backlog}</strong><small>Across visible operational states</small></article>
|
|
49
|
+
</div>
|
|
50
|
+
{snapshot.loading ? <div className="skeleton-block" role="status" aria-label="Loading reports and outcomes" /> : <div className="analytics-body"><div><h3>Reports by allegation</h3><div className="analytics-list">{reasonRows.length ? reasonRows.map(([reason, count]) => <div key={reason}><span>{readable(reason)}</span><strong>{count}</strong></div>) : <p>No report reasons were recorded in this period.</p>}</div></div><div><h3>Safeguards</h3><p className="audit-verification">{snapshot.auditVerification}</p><ul>{(analytics?.limitations ?? []).map((limitation) => <li key={limitation}>{limitation}</li>)}</ul></div></div>}
|
|
51
|
+
<p className="error surface-error" role="alert">{snapshot.error}</p>
|
|
52
|
+
</section>
|
|
53
|
+
</div>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { authorizedFetch, errorMessage, requestJson } from "../lib/http";
|
|
2
|
+
import { readable } from "../lib/format";
|
|
3
|
+
import { getShellSnapshot, subscribeToShell } from "../shell/store";
|
|
4
|
+
import { analyticsEvents } from "./events";
|
|
5
|
+
import { getAnalyticsWorkspaceSnapshot, setAnalyticsWorkspaceSnapshot } from "./store";
|
|
6
|
+
import type { AnalyticsRecord, AnalyticsWorkspaceSnapshot } from "./types";
|
|
7
|
+
|
|
8
|
+
interface AnalyticsResponse { analytics: AnalyticsRecord }
|
|
9
|
+
interface AuditVerificationResponse {
|
|
10
|
+
verification: {
|
|
11
|
+
valid: boolean;
|
|
12
|
+
verifiedEntries: number;
|
|
13
|
+
verifiedAt: string;
|
|
14
|
+
failedSequence?: string | number;
|
|
15
|
+
reason?: string;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const initialSnapshot = (): AnalyticsWorkspaceSnapshot => ({
|
|
20
|
+
loading: true,
|
|
21
|
+
refreshing: false,
|
|
22
|
+
error: "",
|
|
23
|
+
days: 30,
|
|
24
|
+
canRead: false,
|
|
25
|
+
canVerifyAudit: false,
|
|
26
|
+
canExport: false,
|
|
27
|
+
auditPending: false,
|
|
28
|
+
exportPending: false,
|
|
29
|
+
auditVerification: "Audit not verified in this session.",
|
|
30
|
+
analytics: null,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
let actorId = "";
|
|
34
|
+
let started = false;
|
|
35
|
+
|
|
36
|
+
function withPermissions(snapshot: AnalyticsWorkspaceSnapshot): AnalyticsWorkspaceSnapshot {
|
|
37
|
+
const permissions = getShellSnapshot().session?.permissions;
|
|
38
|
+
return {
|
|
39
|
+
...snapshot,
|
|
40
|
+
canRead: permissions?.readAnalytics === true,
|
|
41
|
+
canVerifyAudit: permissions?.viewAudit === true,
|
|
42
|
+
canExport: permissions?.exportData === true,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function reset(): void {
|
|
47
|
+
setAnalyticsWorkspaceSnapshot(initialSnapshot());
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function loadAnalytics(): Promise<void> {
|
|
51
|
+
const session = getShellSnapshot().session;
|
|
52
|
+
if (!session?.permissions.readAnalytics) {
|
|
53
|
+
setAnalyticsWorkspaceSnapshot(withPermissions({ ...initialSnapshot(), loading: false }));
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const current = getAnalyticsWorkspaceSnapshot();
|
|
57
|
+
setAnalyticsWorkspaceSnapshot(withPermissions({ ...current, error: "", refreshing: !current.loading }));
|
|
58
|
+
try {
|
|
59
|
+
const result = await requestJson<AnalyticsResponse>(`/v1/admin/analytics?days=${current.days}`);
|
|
60
|
+
setAnalyticsWorkspaceSnapshot((snapshot) => withPermissions({ ...snapshot, analytics: result.analytics }));
|
|
61
|
+
} catch (cause) {
|
|
62
|
+
setAnalyticsWorkspaceSnapshot((snapshot) => ({ ...snapshot, error: errorMessage(cause, "Analytics could not be loaded.") }));
|
|
63
|
+
} finally {
|
|
64
|
+
setAnalyticsWorkspaceSnapshot((snapshot) => withPermissions({ ...snapshot, loading: false, refreshing: false }));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function exportReports(): Promise<void> {
|
|
69
|
+
const snapshot = getAnalyticsWorkspaceSnapshot();
|
|
70
|
+
if (!snapshot.canExport || snapshot.exportPending) return;
|
|
71
|
+
setAnalyticsWorkspaceSnapshot({ ...snapshot, error: "", exportPending: true });
|
|
72
|
+
try {
|
|
73
|
+
const response = await authorizedFetch(`/v1/admin/exports/reports.csv?days=${snapshot.days}`);
|
|
74
|
+
if (!response.ok) {
|
|
75
|
+
const result = await response.json().catch(() => ({})) as { error?: { message?: string } };
|
|
76
|
+
throw new Error(result.error?.message || "The report export could not be created.");
|
|
77
|
+
}
|
|
78
|
+
const url = URL.createObjectURL(await response.blob());
|
|
79
|
+
const link = document.createElement("a");
|
|
80
|
+
link.href = url;
|
|
81
|
+
link.download = `safest-resolve-${new Date().toISOString().slice(0, 10)}.csv`;
|
|
82
|
+
link.click();
|
|
83
|
+
URL.revokeObjectURL(url);
|
|
84
|
+
} catch (cause) {
|
|
85
|
+
setAnalyticsWorkspaceSnapshot((current) => ({ ...current, error: errorMessage(cause, "The report export could not be created.") }));
|
|
86
|
+
} finally {
|
|
87
|
+
setAnalyticsWorkspaceSnapshot((current) => ({ ...current, exportPending: false }));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async function verifyAudit(): Promise<void> {
|
|
92
|
+
const snapshot = getAnalyticsWorkspaceSnapshot();
|
|
93
|
+
if (!snapshot.canVerifyAudit || snapshot.auditPending) return;
|
|
94
|
+
setAnalyticsWorkspaceSnapshot({ ...snapshot, error: "", auditPending: true });
|
|
95
|
+
try {
|
|
96
|
+
const result = await requestJson<AuditVerificationResponse>("/v1/admin/audit/verify");
|
|
97
|
+
const verification = result.verification;
|
|
98
|
+
const message = verification.valid
|
|
99
|
+
? `${verification.verifiedEntries} chained entries verified at ${new Date(verification.verifiedAt).toLocaleTimeString()}.`
|
|
100
|
+
: `Audit verification failed at sequence ${verification.failedSequence || "unknown"}: ${readable(verification.reason)}.`;
|
|
101
|
+
setAnalyticsWorkspaceSnapshot((current) => ({ ...current, auditVerification: message }));
|
|
102
|
+
} catch (cause) {
|
|
103
|
+
setAnalyticsWorkspaceSnapshot((current) => ({ ...current, error: errorMessage(cause, "The audit chain could not be verified.") }));
|
|
104
|
+
} finally {
|
|
105
|
+
setAnalyticsWorkspaceSnapshot((current) => ({ ...current, auditPending: false }));
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function startAnalyticsController(): void {
|
|
110
|
+
if (started) return;
|
|
111
|
+
started = true;
|
|
112
|
+
subscribeToShell(() => {
|
|
113
|
+
const session = getShellSnapshot().session;
|
|
114
|
+
const nextActorId = session?.actor.id || "";
|
|
115
|
+
if (nextActorId === actorId) {
|
|
116
|
+
setAnalyticsWorkspaceSnapshot((snapshot) => withPermissions(snapshot));
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
actorId = nextActorId;
|
|
120
|
+
reset();
|
|
121
|
+
if (session) void loadAnalytics();
|
|
122
|
+
});
|
|
123
|
+
window.addEventListener(analyticsEvents.refresh, () => { void loadAnalytics(); });
|
|
124
|
+
window.addEventListener(analyticsEvents.period, (event) => {
|
|
125
|
+
if (!(event instanceof CustomEvent)) return;
|
|
126
|
+
const days = Number(event.detail?.days);
|
|
127
|
+
if (![7, 30, 90, 180, 365].includes(days)) return;
|
|
128
|
+
setAnalyticsWorkspaceSnapshot((snapshot) => ({ ...snapshot, days }));
|
|
129
|
+
void loadAnalytics();
|
|
130
|
+
});
|
|
131
|
+
window.addEventListener(analyticsEvents.verifyAudit, () => { void verifyAudit(); });
|
|
132
|
+
window.addEventListener(analyticsEvents.exportReports, () => { void exportReports(); });
|
|
133
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { AnalyticsWorkspaceSnapshot } from "./types";
|
|
2
|
+
|
|
3
|
+
export const analyticsEvents = {
|
|
4
|
+
state: "safest:analytics:state",
|
|
5
|
+
refresh: "safest:analytics:refresh",
|
|
6
|
+
period: "safest:analytics:period",
|
|
7
|
+
verifyAudit: "safest:analytics:verify-audit",
|
|
8
|
+
exportReports: "safest:analytics:export-reports",
|
|
9
|
+
} as const;
|
|
10
|
+
|
|
11
|
+
function dispatch<TDetail>(type: string, detail?: TDetail): void {
|
|
12
|
+
window.dispatchEvent(detail === undefined ? new Event(type) : new CustomEvent(type, { detail }));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function dispatchAnalyticsRefresh(): void { dispatch(analyticsEvents.refresh); }
|
|
16
|
+
export function dispatchAnalyticsPeriod(days: number): void { dispatch(analyticsEvents.period, { days }); }
|
|
17
|
+
export function dispatchAuditVerification(): void { dispatch(analyticsEvents.verifyAudit); }
|
|
18
|
+
export function dispatchReportExport(): void { dispatch(analyticsEvents.exportReports); }
|
|
19
|
+
|
|
20
|
+
export function isAnalyticsWorkspaceSnapshot(value: unknown): value is AnalyticsWorkspaceSnapshot {
|
|
21
|
+
if (!value || typeof value !== "object") return false;
|
|
22
|
+
const candidate = value as Partial<AnalyticsWorkspaceSnapshot>;
|
|
23
|
+
return typeof candidate.loading === "boolean"
|
|
24
|
+
&& typeof candidate.refreshing === "boolean"
|
|
25
|
+
&& typeof candidate.error === "string"
|
|
26
|
+
&& typeof candidate.days === "number"
|
|
27
|
+
&& typeof candidate.canRead === "boolean"
|
|
28
|
+
&& typeof candidate.canVerifyAudit === "boolean"
|
|
29
|
+
&& typeof candidate.canExport === "boolean"
|
|
30
|
+
&& typeof candidate.auditPending === "boolean"
|
|
31
|
+
&& typeof candidate.exportPending === "boolean"
|
|
32
|
+
&& typeof candidate.auditVerification === "string";
|
|
33
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { analyticsEvents, isAnalyticsWorkspaceSnapshot } from "./events";
|
|
2
|
+
import type { AnalyticsWorkspaceSnapshot } from "./types";
|
|
3
|
+
|
|
4
|
+
const subscribers = new Set<() => void>();
|
|
5
|
+
let snapshot: AnalyticsWorkspaceSnapshot = {
|
|
6
|
+
loading: true,
|
|
7
|
+
refreshing: false,
|
|
8
|
+
error: "",
|
|
9
|
+
days: 30,
|
|
10
|
+
canRead: false,
|
|
11
|
+
canVerifyAudit: false,
|
|
12
|
+
canExport: false,
|
|
13
|
+
auditPending: false,
|
|
14
|
+
exportPending: false,
|
|
15
|
+
auditVerification: "Audit not verified in this session.",
|
|
16
|
+
analytics: null,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
window.addEventListener(analyticsEvents.state, (event) => {
|
|
20
|
+
if (!(event instanceof CustomEvent) || !isAnalyticsWorkspaceSnapshot(event.detail)) return;
|
|
21
|
+
snapshot = event.detail;
|
|
22
|
+
for (const subscriber of subscribers) subscriber();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export function getAnalyticsWorkspaceSnapshot(): AnalyticsWorkspaceSnapshot { return snapshot; }
|
|
26
|
+
export function setAnalyticsWorkspaceSnapshot(next: AnalyticsWorkspaceSnapshot | ((current: AnalyticsWorkspaceSnapshot) => AnalyticsWorkspaceSnapshot)): void {
|
|
27
|
+
snapshot = typeof next === "function" ? next(snapshot) : next;
|
|
28
|
+
for (const subscriber of subscribers) subscriber();
|
|
29
|
+
}
|
|
30
|
+
export function subscribeToAnalyticsWorkspace(callback: () => void): () => void {
|
|
31
|
+
subscribers.add(callback);
|
|
32
|
+
return () => subscribers.delete(callback);
|
|
33
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export interface AnalyticsSeriesRow {
|
|
2
|
+
aggregateDate: string;
|
|
3
|
+
metricKey: string;
|
|
4
|
+
dimensionKey: string;
|
|
5
|
+
dimensionValue: string;
|
|
6
|
+
value: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface AnalyticsBacklogRow {
|
|
10
|
+
queueId?: string | null;
|
|
11
|
+
state: string;
|
|
12
|
+
count: number;
|
|
13
|
+
oldestAgeSeconds?: number | null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface AnalyticsRecord {
|
|
17
|
+
generatedAt: string;
|
|
18
|
+
fromDate: string;
|
|
19
|
+
days: number;
|
|
20
|
+
series: AnalyticsSeriesRow[];
|
|
21
|
+
backlog: AnalyticsBacklogRow[];
|
|
22
|
+
resolutionSeconds: { count: number; median: number | null; p90: number | null; p95: number | null };
|
|
23
|
+
limitations: string[];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface AnalyticsWorkspaceSnapshot {
|
|
27
|
+
loading: boolean;
|
|
28
|
+
refreshing: boolean;
|
|
29
|
+
error: string;
|
|
30
|
+
days: number;
|
|
31
|
+
canRead: boolean;
|
|
32
|
+
canVerifyAudit: boolean;
|
|
33
|
+
canExport: boolean;
|
|
34
|
+
auditPending: boolean;
|
|
35
|
+
exportPending: boolean;
|
|
36
|
+
auditVerification: string;
|
|
37
|
+
analytics: AnalyticsRecord | null;
|
|
38
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { useEffect, useRef, useState, useSyncExternalStore, type FormEvent } from "react";
|
|
2
|
+
import { readable, relativeTime } from "../lib/format";
|
|
3
|
+
import { PageHeader } from "../components/PageHeader";
|
|
4
|
+
import { dispatchAppealDecision, dispatchAppealRefresh, dispatchClaimAppeal, dispatchCloseAppeal, dispatchOpenAppeal } from "./events";
|
|
5
|
+
import { getAppealWorkspaceSnapshot, subscribeToAppealWorkspace } from "./store";
|
|
6
|
+
import type { AppealOutcome, AppealRecord } from "./types";
|
|
7
|
+
|
|
8
|
+
function AppealRow({ appeal }: { appeal: AppealRecord }) {
|
|
9
|
+
return (
|
|
10
|
+
<article className="appeal-row">
|
|
11
|
+
<div><strong>{appeal.reportReference}</strong><small>{readable(appeal.appellantAudience)} · {relativeTime(appeal.submittedAt)}<span className="appeal-mobile-meta"> · {readable(appeal.state)} · {appeal.reviewerId ? "Claimed" : "Unclaimed"}</span></small></div>
|
|
12
|
+
<span>{readable(appeal.state)}</span>
|
|
13
|
+
<span>{appeal.reviewerId ? "Claimed" : "Unclaimed"}</span>
|
|
14
|
+
<button className="secondary" type="button" onClick={() => dispatchOpenAppeal(appeal.id)}>Review</button>
|
|
15
|
+
</article>
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function AppealWorkspace() {
|
|
20
|
+
const snapshot = useSyncExternalStore(subscribeToAppealWorkspace, getAppealWorkspaceSnapshot, getAppealWorkspaceSnapshot);
|
|
21
|
+
return (
|
|
22
|
+
<div className="page-stack" data-react-slice="appeal-workspace">
|
|
23
|
+
<PageHeader titleId="appeals-title" title="Appeals" description="Review contested decisions with a separate human owner.">
|
|
24
|
+
<div className="surface-buttons"><button className="secondary" type="button" disabled={snapshot.refreshing || !snapshot.canReview} onClick={dispatchAppealRefresh}>{snapshot.refreshing ? "Refreshing…" : "Refresh"}</button></div>
|
|
25
|
+
</PageHeader>
|
|
26
|
+
<section className="surface appeals-surface" aria-labelledby="appeals-title">
|
|
27
|
+
<div className="appeal-list" aria-busy={snapshot.loading || snapshot.refreshing}>
|
|
28
|
+
{snapshot.loading ? <div className="skeleton-block" role="status" aria-label="Loading appeals" /> : snapshot.appeals.length ? snapshot.appeals.map((appeal) => <AppealRow appeal={appeal} key={appeal.id} />) : <div className="empty"><span aria-hidden="true">✓</span><h3>No appeals in this view</h3><p>New appeals will appear here when a participant contests a decision.</p></div>}
|
|
29
|
+
</div>
|
|
30
|
+
<p className="error surface-error" role="alert">{snapshot.error}</p>
|
|
31
|
+
</section>
|
|
32
|
+
</div>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function AppealDialog() {
|
|
37
|
+
const snapshot = useSyncExternalStore(subscribeToAppealWorkspace, getAppealWorkspaceSnapshot, getAppealWorkspaceSnapshot);
|
|
38
|
+
const dialogRef = useRef<HTMLDialogElement>(null);
|
|
39
|
+
const rationaleRef = useRef<HTMLTextAreaElement>(null);
|
|
40
|
+
const [outcome, setOutcome] = useState<AppealOutcome>("upheld");
|
|
41
|
+
const [rationale, setRationale] = useState("");
|
|
42
|
+
const [participantNotice, setParticipantNotice] = useState("");
|
|
43
|
+
const appeal = snapshot.detail.appeal;
|
|
44
|
+
const activeClaim = Boolean(appeal?.reviewerId && appeal.claimExpiresAt && Date.parse(appeal.claimExpiresAt) > Date.parse(snapshot.generatedAt));
|
|
45
|
+
const mine = Boolean(activeClaim && appeal?.reviewerId === snapshot.actorId);
|
|
46
|
+
const disabled = !mine || snapshot.detail.pendingAction === "decision";
|
|
47
|
+
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
const dialog = dialogRef.current;
|
|
50
|
+
if (!dialog) return;
|
|
51
|
+
if (snapshot.detail.appealId && !dialog.open) dialog.showModal();
|
|
52
|
+
if (!snapshot.detail.appealId && dialog.open) dialog.close();
|
|
53
|
+
}, [snapshot.detail.appealId]);
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
setOutcome("upheld");
|
|
56
|
+
setRationale("");
|
|
57
|
+
setParticipantNotice("");
|
|
58
|
+
if (snapshot.detail.appealId) rationaleRef.current?.focus();
|
|
59
|
+
}, [snapshot.detail.appealId]);
|
|
60
|
+
|
|
61
|
+
const submit = (event: FormEvent<HTMLFormElement>): void => {
|
|
62
|
+
event.preventDefault();
|
|
63
|
+
dispatchAppealDecision({ outcome, rationale, participantNotice });
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<dialog ref={dialogRef} className="detail-dialog appeal-dialog" aria-labelledby="appeal-reference" onCancel={(event) => { event.preventDefault(); dispatchCloseAppeal(); }} data-react-slice="appeal-dialog">
|
|
68
|
+
<div className="detail-head"><div><h2 id="appeal-reference">{appeal ? `${appeal.reportReference} appeal` : "Appeal"}</h2><p>{appeal ? readable(appeal.state) : "Loading appeal…"}</p></div><button className="icon-button" type="button" aria-label="Close appeal" onClick={dispatchCloseAppeal}>×</button></div>
|
|
69
|
+
{appeal ? <><p>{appeal.reason}</p><div className="claim-bar"><p>{mine ? "This appeal is claimed by you." : activeClaim ? "Another reviewer currently owns this appeal." : "Appeals require a separate human reviewer."}</p>{!activeClaim && snapshot.canReview ? <button className="primary" type="button" disabled={snapshot.detail.pendingAction === "claim"} onClick={dispatchClaimAppeal}>{snapshot.detail.pendingAction === "claim" ? "Claiming…" : "Claim appeal"}</button> : null}</div><form onSubmit={submit}><label>Outcome<select value={outcome} disabled={disabled} onChange={(event) => setOutcome(event.currentTarget.value as AppealOutcome)}><option value="upheld">Uphold</option><option value="modified">Modify</option><option value="reversed">Reverse</option></select></label><label>Internal rationale<textarea ref={rationaleRef} maxLength={8000} required disabled={disabled} value={rationale} onChange={(event) => setRationale(event.currentTarget.value)} /></label><label>Participant notice<textarea maxLength={4000} required disabled={disabled} value={participantNotice} onChange={(event) => setParticipantNotice(event.currentTarget.value)} /></label><button className="primary" type="submit" disabled={disabled}>{snapshot.detail.pendingAction === "decision" ? "Recording…" : "Record appeal decision"}</button></form></> : null}
|
|
70
|
+
<p className="error" role="alert">{snapshot.detail.error}</p>
|
|
71
|
+
</dialog>
|
|
72
|
+
);
|
|
73
|
+
}
|