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.
Files changed (240) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +71 -0
  3. package/bin/create-safest-tools.mjs +12 -0
  4. package/package.json +34 -0
  5. package/src/cli.mjs +128 -0
  6. package/src/config.mjs +151 -0
  7. package/src/scaffold.mjs +30 -0
  8. package/template/LICENSE +201 -0
  9. package/template/README.md +35 -0
  10. package/template/console/README.md +28 -0
  11. package/template/console/analytics/AnalyticsWorkspace.tsx +55 -0
  12. package/template/console/analytics/controller.ts +133 -0
  13. package/template/console/analytics/events.ts +33 -0
  14. package/template/console/analytics/store.ts +33 -0
  15. package/template/console/analytics/types.ts +38 -0
  16. package/template/console/appeals/AppealWorkspace.tsx +73 -0
  17. package/template/console/appeals/controller.ts +125 -0
  18. package/template/console/appeals/events.ts +33 -0
  19. package/template/console/appeals/store.ts +35 -0
  20. package/template/console/appeals/types.ts +37 -0
  21. package/template/console/assistant/AssistantWorkspace.tsx +133 -0
  22. package/template/console/assistant/types.ts +34 -0
  23. package/template/console/auth/AccountJourney.tsx +69 -0
  24. package/template/console/auth/InvitationAcceptance.tsx +145 -0
  25. package/template/console/auth/OAuthButtons.tsx +78 -0
  26. package/template/console/auth/OperatorLogin.tsx +110 -0
  27. package/template/console/auth/PasswordRecovery.tsx +132 -0
  28. package/template/console/auth/account-route.ts +15 -0
  29. package/template/console/auth/browser-navigation.ts +7 -0
  30. package/template/console/auth/events.ts +15 -0
  31. package/template/console/command/CommandCentre.tsx +119 -0
  32. package/template/console/command/controller.ts +267 -0
  33. package/template/console/command/events.ts +19 -0
  34. package/template/console/command/store.ts +36 -0
  35. package/template/console/command/types.ts +61 -0
  36. package/template/console/components/AnalystIdentity.tsx +25 -0
  37. package/template/console/components/PageHeader.tsx +27 -0
  38. package/template/console/configuration/ConfigurationDialog.tsx +200 -0
  39. package/template/console/configuration/ConfigurationWorkspace.tsx +66 -0
  40. package/template/console/configuration/FormBuilder.tsx +143 -0
  41. package/template/console/configuration/api.ts +40 -0
  42. package/template/console/configuration/events.ts +14 -0
  43. package/template/console/configuration/types.ts +79 -0
  44. package/template/console/lib/format.ts +49 -0
  45. package/template/console/lib/http.ts +96 -0
  46. package/template/console/main.tsx +225 -0
  47. package/template/console/operations/OperationsWorkspace.tsx +126 -0
  48. package/template/console/operations/controller.ts +237 -0
  49. package/template/console/operations/events.ts +37 -0
  50. package/template/console/operations/store.ts +32 -0
  51. package/template/console/operations/types.ts +107 -0
  52. package/template/console/people/PeopleWorkspace.tsx +81 -0
  53. package/template/console/people/types.ts +25 -0
  54. package/template/console/profile/ProfileWorkspace.tsx +136 -0
  55. package/template/console/profile/events.ts +9 -0
  56. package/template/console/profile/types.ts +6 -0
  57. package/template/console/quality/QualityWorkspace.tsx +87 -0
  58. package/template/console/quality/controller.ts +154 -0
  59. package/template/console/quality/events.ts +34 -0
  60. package/template/console/quality/store.ts +36 -0
  61. package/template/console/quality/types.ts +70 -0
  62. package/template/console/queues/QueueEditor.tsx +173 -0
  63. package/template/console/queues/QueueWorkspace.tsx +109 -0
  64. package/template/console/queues/controller.ts +194 -0
  65. package/template/console/queues/events.ts +34 -0
  66. package/template/console/queues/store.ts +37 -0
  67. package/template/console/queues/types.ts +102 -0
  68. package/template/console/registry/RegistryDialog.tsx +198 -0
  69. package/template/console/registry/RegistryWorkspace.tsx +108 -0
  70. package/template/console/registry/events.ts +14 -0
  71. package/template/console/registry/types.ts +52 -0
  72. package/template/console/reports/ReportDrawer.tsx +159 -0
  73. package/template/console/reports/ReportWorkspace.tsx +90 -0
  74. package/template/console/reports/controller.ts +517 -0
  75. package/template/console/reports/events.ts +42 -0
  76. package/template/console/reports/store.ts +39 -0
  77. package/template/console/reports/types.ts +230 -0
  78. package/template/console/settings/BrandEditor.tsx +126 -0
  79. package/template/console/settings/ChannelDialog.tsx +241 -0
  80. package/template/console/settings/SettingsWorkspace.tsx +155 -0
  81. package/template/console/settings/events.ts +19 -0
  82. package/template/console/settings/handoff.ts +22 -0
  83. package/template/console/settings/types.ts +93 -0
  84. package/template/console/shell/WorkspaceShell.tsx +160 -0
  85. package/template/console/shell/controller.ts +182 -0
  86. package/template/console/shell/events.ts +25 -0
  87. package/template/console/shell/navigation.ts +61 -0
  88. package/template/console/shell/store.ts +56 -0
  89. package/template/console/shell/types.ts +86 -0
  90. package/template/console/workflows/CreateWorkflowDialog.tsx +87 -0
  91. package/template/console/workflows/WorkflowCanvas.tsx +42 -0
  92. package/template/console/workflows/WorkflowDialogs.tsx +6 -0
  93. package/template/console/workflows/WorkflowStudio.tsx +331 -0
  94. package/template/console/workflows/WorkflowWorkspace.tsx +82 -0
  95. package/template/console/workflows/events.ts +17 -0
  96. package/template/console/workflows/graph.ts +156 -0
  97. package/template/console/workflows/templates.ts +70 -0
  98. package/template/console/workflows/types.ts +201 -0
  99. package/template/gitignore.template +18 -0
  100. package/template/migrations/0001_reports_foundation.sql +444 -0
  101. package/template/migrations/0002_human_report_loop.sql +65 -0
  102. package/template/migrations/0003_delivery_reliability.sql +18 -0
  103. package/template/migrations/0004_public_intake.sql +14 -0
  104. package/template/migrations/0005_operations_visibility.sql +24 -0
  105. package/template/migrations/0006_ai_governance.sql +198 -0
  106. package/template/migrations/0007_ai_release_gates.sql +6 -0
  107. package/template/migrations/0008_retention_analytics_exports.sql +52 -0
  108. package/template/migrations/0009_retention_derived_copies.sql +14 -0
  109. package/template/migrations/0010_ai_quality_controls.sql +26 -0
  110. package/template/migrations/0011_analyst_presence.sql +28 -0
  111. package/template/migrations/0012_queue_policies.sql +87 -0
  112. package/template/migrations/0013_routing_agents.sql +63 -0
  113. package/template/migrations/0014_webhook_enrichments.sql +122 -0
  114. package/template/migrations/0015_queue_owned_ai.sql +55 -0
  115. package/template/migrations/0016_operator_accounts.sql +67 -0
  116. package/template/migrations/0017_operator_profiles_and_recovery.sql +33 -0
  117. package/template/migrations/0018_platform_configuration.sql +382 -0
  118. package/template/migrations/0019_workflow_authoring_runtime.sql +372 -0
  119. package/template/migrations/0020_tasks_findings_assistant_budgets.sql +427 -0
  120. package/template/migrations/0021_abuse_evidence_operations.sql +324 -0
  121. package/template/migrations/0022_workflow_dispatch_operations.sql +42 -0
  122. package/template/migrations/0023_component_connection_execution.sql +75 -0
  123. package/template/migrations/0024_access_runtime_integrity.sql +72 -0
  124. package/template/migrations/0025_installation_timezone.sql +11 -0
  125. package/template/migrations/0026_ai_and_egress_execution_controls.sql +49 -0
  126. package/template/migrations/0027_prompt_and_ai_registry.sql +37 -0
  127. package/template/migrations/0028_step_attempt_ai_provenance.sql +13 -0
  128. package/template/migrations/0029_evidence_fetch_transport.sql +5 -0
  129. package/template/migrations/0030_evidence_dlq_incidents.sql +45 -0
  130. package/template/migrations/0031_shadow_quality_integrity.sql +7 -0
  131. package/template/migrations/0032_action_delivery_outbox.sql +55 -0
  132. package/template/migrations/0033_configuration_and_assistant_drafts.sql +43 -0
  133. package/template/migrations/0034_installation_integrations.sql +31 -0
  134. package/template/migrations/0035_workspace_governance.sql +21 -0
  135. package/template/migrations/0036_published_routing_baseline.sql +15 -0
  136. package/template/migrations/0037_builtin_phishing_specialist.sql +71 -0
  137. package/template/migrations/0038_remove_deprecated_enrichment_runtime.sql +228 -0
  138. package/template/migrations/0039_secure_reporting_channels.sql +45 -0
  139. package/template/migrations/0040_notification_only_reporting.sql +24 -0
  140. package/template/migrations/0041_better_auth_credentials.sql +17 -0
  141. package/template/package.json +47 -0
  142. package/template/public/_headers +27 -0
  143. package/template/public/app-icon-192.png +0 -0
  144. package/template/public/app-icon-512.png +0 -0
  145. package/template/public/brand-icon.svg +7 -0
  146. package/template/public/brand-tokens.css +80 -0
  147. package/template/public/console/auth-shell.js +19340 -0
  148. package/template/public/customer-brand.js +58 -0
  149. package/template/public/embed/embed.css +139 -0
  150. package/template/public/embed/embed.js +408 -0
  151. package/template/public/embed/index.html +91 -0
  152. package/template/public/favicon.svg +7 -0
  153. package/template/public/fonts/Manrope-Variable.ttf +0 -0
  154. package/template/public/fonts/Newsreader-Italic-Variable.ttf +0 -0
  155. package/template/public/fonts/Newsreader-Variable.ttf +0 -0
  156. package/template/public/index.html +123 -0
  157. package/template/public/logo-primary.svg +7 -0
  158. package/template/public/logo-reversed.svg +7 -0
  159. package/template/public/manifest.webmanifest +21 -0
  160. package/template/public/public-report.js +184 -0
  161. package/template/public/report/index.html +39 -0
  162. package/template/public/report/public-report.css +20 -0
  163. package/template/public/social-card.png +0 -0
  164. package/template/public/styles.css +1521 -0
  165. package/template/public/widget.css +80 -0
  166. package/template/public/widget.js +220 -0
  167. package/template/reports.config.example.json +38 -0
  168. package/template/reports.schema.json +89 -0
  169. package/template/scripts/reports-auth-onboarding.mjs +180 -0
  170. package/template/scripts/reports-backup.mjs +276 -0
  171. package/template/scripts/reports-cloudflare-preflight.mjs +152 -0
  172. package/template/scripts/reports-deploy.mjs +173 -0
  173. package/template/scripts/reports-plan.mjs +226 -0
  174. package/template/scripts/reports-restore.mjs +180 -0
  175. package/template/scripts/reports-secrets.mjs +73 -0
  176. package/template/scripts/reports-uninstall-plan.mjs +32 -0
  177. package/template/src/agent-executor.ts +330 -0
  178. package/template/src/ai-observability.ts +163 -0
  179. package/template/src/ai-registry-validation.ts +244 -0
  180. package/template/src/ai-registry.ts +292 -0
  181. package/template/src/api-cursor.ts +84 -0
  182. package/template/src/assistant.ts +554 -0
  183. package/template/src/audit.ts +39 -0
  184. package/template/src/backup-service.ts +269 -0
  185. package/template/src/budget-control.ts +127 -0
  186. package/template/src/component-executor.ts +845 -0
  187. package/template/src/configuration-registry.ts +550 -0
  188. package/template/src/connection-egress.ts +430 -0
  189. package/template/src/connection-oauth.ts +368 -0
  190. package/template/src/evidence-service.ts +335 -0
  191. package/template/src/human-tasks.ts +316 -0
  192. package/template/src/index.ts +4114 -0
  193. package/template/src/installation-admin.ts +301 -0
  194. package/template/src/intake-abuse.ts +156 -0
  195. package/template/src/platform-registry-validation.ts +367 -0
  196. package/template/src/platform-registry.ts +753 -0
  197. package/template/src/report-admin.ts +342 -0
  198. package/template/src/report-ai-quality.ts +390 -0
  199. package/template/src/report-ai-validation.ts +80 -0
  200. package/template/src/report-ai.ts +857 -0
  201. package/template/src/report-auth.ts +292 -0
  202. package/template/src/report-better-auth.ts +583 -0
  203. package/template/src/report-context-schema.ts +132 -0
  204. package/template/src/report-context.ts +126 -0
  205. package/template/src/report-crypto.ts +142 -0
  206. package/template/src/report-delivery.ts +579 -0
  207. package/template/src/report-form-validation.ts +51 -0
  208. package/template/src/report-governance.ts +510 -0
  209. package/template/src/report-http.ts +90 -0
  210. package/template/src/report-operations.ts +685 -0
  211. package/template/src/report-operator-accounts.ts +810 -0
  212. package/template/src/report-presence.ts +398 -0
  213. package/template/src/report-queue-validation.ts +309 -0
  214. package/template/src/report-queues.ts +478 -0
  215. package/template/src/report-repository.ts +972 -0
  216. package/template/src/report-router-agent.ts +328 -0
  217. package/template/src/report-router-validation.ts +81 -0
  218. package/template/src/report-routing.ts +178 -0
  219. package/template/src/report-turnstile.ts +142 -0
  220. package/template/src/report-types.ts +224 -0
  221. package/template/src/report-validation.ts +279 -0
  222. package/template/src/report-workflow-validation.ts +119 -0
  223. package/template/src/report-workflow.ts +886 -0
  224. package/template/src/shadow-quality.ts +278 -0
  225. package/template/src/workflow-actions.ts +782 -0
  226. package/template/src/workflow-compiler.ts +230 -0
  227. package/template/src/workflow-dynamic-runtime.ts +613 -0
  228. package/template/src/workflow-effects.ts +316 -0
  229. package/template/src/workflow-expressions.ts +191 -0
  230. package/template/src/workflow-platform-types.ts +121 -0
  231. package/template/src/workflow-platform-validation.ts +540 -0
  232. package/template/src/workflow-repository.ts +916 -0
  233. package/template/src/workflow-runs.ts +686 -0
  234. package/template/src/workflow-simulator.ts +211 -0
  235. package/template/src/workspace-branding.ts +128 -0
  236. package/template/src/workspace-governance.ts +279 -0
  237. package/template/tsconfig.console.json +23 -0
  238. package/template/tsconfig.json +22 -0
  239. package/template/vite.console.config.ts +20 -0
  240. package/template/worker-configuration.d.ts +65 -0
package/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.
package/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # create-safest-tools
2
+
3
+ Create a customer-owned Safest Resolve report-resolution service on Cloudflare.
4
+
5
+ Safest Resolve accepts explicit reports from an embedded widget, a public page, or a server API, then runs the published workflow for each report type. Application traffic continues to use its existing path.
6
+
7
+ ## Quick start
8
+
9
+ You need Node.js 20.12+, a Cloudflare account with Workers, Dynamic Workflows, Worker Loaders, D1, R2, Queues, Durable Objects, Workers AI, and Access available, plus an HTTPS hostname for the reports service.
10
+
11
+ ```bash
12
+ npx create-safest-tools safest-resolve \
13
+ --yes \
14
+ --name acme-resolve \
15
+ --public-url https://reports.example.com \
16
+ --origin https://app.example.com \
17
+ --admin-email infrastructure@example.com \
18
+ --access-aud <cloudflare-access-application-aud> \
19
+ --email-from reports@example.com
20
+ ```
21
+
22
+ The `--email-from` address must belong to a domain onboarded under Cloudflare Email Service → Email Sending. Domain onboarding permits delivery to arbitrary invited users; invitations, email verification, and forgot-password delivery use this address.
23
+
24
+ The command creates a local project and prints a read-only infrastructure plan. It does not change Cloudflare unless `--deploy` is supplied or the generated project’s `npm run setup` command is run and explicitly confirmed.
25
+
26
+ The generated installation owns:
27
+
28
+ - one reports Worker and its dashboard, widget, and public form;
29
+ - one D1 database containing report, policy, audit, workflow, AI, and analytics records;
30
+ - four private R2 buckets for operator profile pictures, workflow artifacts, evidence, and generated exports;
31
+ - report jobs, delivery jobs, and operations dead-letter Queues;
32
+ - one Dynamic Workflow and a Worker Loader for compiled durable workflow execution;
33
+ - one SQLite-backed Durable Object class for analyst presence;
34
+ - a Workers AI binding and customer-supplied secrets;
35
+ - a customer-created Cloudflare Access application for infrastructure-owner bootstrap only.
36
+
37
+ The reports service stores customer application references by default. Webhook enrichments receive only their explicitly published input allowlist and return schema-validated, expiring facts with signed provenance.
38
+
39
+ ## Safe deployment
40
+
41
+ In the generated project:
42
+
43
+ ```bash
44
+ npm run secrets:init
45
+ npm run setup:plan
46
+ npm run setup
47
+ ```
48
+
49
+ `setup:plan` lists exact resource names and exits without modifying Cloudflare. `setup` opens Wrangler's Cloudflare login when needed, lets you choose the owning account, and fails closed unless it can verify an active Workers Paid subscription. It then guides Google, GitHub, and Cloudflare OAuth configuration with exact callback URLs and masked secret input. Nothing is provisioned until the exact `DEPLOY <installation-id>` confirmation.
50
+
51
+ Create a Cloudflare Access self-hosted application for `<reports-host>/v1/infrastructure/*` first and copy its 64-character audience into `reports.config.json`. The allowlisted infrastructure engineer uses it to bootstrap the Safest owner account. The owner then invites administrators, and administrators invite analysts. Those invited users sign in with Safest accounts and do not need Cloudflare accounts.
52
+
53
+ Invited users may join with a password or any configured OAuth provider, then choose a natural display name and optional JPEG, PNG, or WebP profile picture up to 2 MB. Better Auth stores credentials, OAuth accounts, sessions, verification state, and one-time password-reset tokens in D1. Cloudflare Email Service sends invitations, verification links, and 30-minute password-reset links.
54
+
55
+ ## Lifecycle
56
+
57
+ ```bash
58
+ npm run backup:plan
59
+ npm run backup
60
+ npm run restore:verify -- .safest/backups/<backup-directory>
61
+ npm run restore:plan -- .safest/backups/<backup-directory> --target-config reports.restore.config.json
62
+ npm run upgrade:plan
63
+ npm run upgrade
64
+ npm run uninstall:plan
65
+ ```
66
+
67
+ Backups contain the D1 export and every object in the four private R2 buckets, with stable inventories and SHA-256 verification. They intentionally exclude pending Queue messages, live Workflow engine state, Worker secrets, external provider state, and ephemeral presence. Restore verification is local; restore planning requires a separate target installation and never mutates Cloudflare. Upgrade runs a verified backup before forward-only migrations and deployment.
68
+
69
+ The uninstall command is intentionally plan-only: it identifies the exact reporting resources but does not delete them. D1, all private R2 buckets, Access, and secrets are preserved by default.
70
+
71
+ Run `npx create-safest-tools --help` for all options.
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env node
2
+ import { runCli } from "../src/cli.mjs";
3
+
4
+ runCli(process.argv.slice(2)).catch((error) => {
5
+ if (error?.code === "SAFEST_CANCELLED") {
6
+ console.error("\nNothing was created.");
7
+ process.exitCode = 130;
8
+ return;
9
+ }
10
+ console.error(`\nCould not create Safest Resolve: ${error instanceof Error ? error.message : String(error)}`);
11
+ process.exitCode = 1;
12
+ });
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "create-safest-tools",
3
+ "version": "0.2.0",
4
+ "description": "Create customer-owned abuse-reporting infrastructure on Cloudflare",
5
+ "type": "module",
6
+ "license": "Apache-2.0",
7
+ "homepage": "https://safest.tools",
8
+ "keywords": [
9
+ "cloudflare",
10
+ "workers",
11
+ "trust-and-safety",
12
+ "abuse-reporting",
13
+ "resolution-workflows"
14
+ ],
15
+ "bin": {
16
+ "create-safest-tools": "bin/create-safest-tools.mjs"
17
+ },
18
+ "files": [
19
+ "bin",
20
+ "src",
21
+ "template"
22
+ ],
23
+ "scripts": {
24
+ "build:template": "node scripts/build-template.mjs",
25
+ "prepack": "npm run build:template",
26
+ "test": "node --test test/*.test.mjs"
27
+ },
28
+ "engines": {
29
+ "node": ">=20.12.0"
30
+ },
31
+ "publishConfig": {
32
+ "access": "public"
33
+ }
34
+ }
package/src/cli.mjs ADDED
@@ -0,0 +1,128 @@
1
+ import { spawn } from "node:child_process";
2
+ import { basename, resolve } from "node:path";
3
+ import { createInterface } from "node:readline/promises";
4
+ import { fileURLToPath } from "node:url";
5
+ import { buildConfiguration } from "./config.mjs";
6
+ import { scaffoldProject, validateGeneratedConfiguration } from "./scaffold.mjs";
7
+
8
+ const packageRoot = fileURLToPath(new URL("..", import.meta.url));
9
+ const defaultTemplateDirectory = resolve(packageRoot, "template");
10
+
11
+ function usage() {
12
+ return `Create customer-owned abuse-reporting infrastructure on Cloudflare
13
+
14
+ Usage:
15
+ npx create-safest-tools [directory]
16
+ npx create-safest-tools safest-resolve --yes --name acme-resolve \\
17
+ --public-url https://reports.example.com --origin https://app.example.com \\
18
+ --admin-email infrastructure@example.com --access-aud <cloudflare-access-aud> \\
19
+ --email-from reports@example.com
20
+
21
+ Options:
22
+ --name id Stable installation/resource prefix
23
+ --public-url origin Public report, widget, and console origin
24
+ --origin origin Allowed embedding/application origin; repeat as needed
25
+ --admin-email email Infrastructure owner allowed through Access; repeat as needed
26
+ --access-aud value Audience of the owner-bootstrap Cloudflare Access app
27
+ --email-from address Address on an onboarded Email Sending domain (required)
28
+ --yes Do not prompt for omitted optional values
29
+ --skip-install Create files without running npm install or setup:plan
30
+ --deploy Run setup after scaffolding (still requires exact confirmation)
31
+ --dry-run Print configuration and resource plan without writing
32
+ --help Show this help
33
+ --version Show the package version
34
+
35
+ This product does not proxy or inspect application requests. Applications submit
36
+ reports explicitly through the widget, public form, or server API.
37
+ `;
38
+ }
39
+
40
+ function valueAfter(argv, index, option) {
41
+ const value = argv[index + 1];
42
+ if (!value || value.startsWith("-")) throw new Error(`${option} needs a value`);
43
+ return value;
44
+ }
45
+
46
+ export function parseArguments(argv) {
47
+ const result = {
48
+ directory: null, installationName: null, publicBaseUrl: null, allowedOrigins: [],
49
+ adminEmails: [], accessAudience: null, emailFromAddress: null, yes: false, skipInstall: false,
50
+ deploy: false, dryRun: false, help: false, version: false,
51
+ };
52
+ for (let index = 0; index < argv.length; index += 1) {
53
+ const argument = argv[index];
54
+ if (!argument.startsWith("-")) {
55
+ if (result.directory) throw new Error("only one project directory can be provided");
56
+ result.directory = argument;
57
+ } else if (argument === "--yes" || argument === "-y") result.yes = true;
58
+ else if (argument === "--skip-install") result.skipInstall = true;
59
+ else if (argument === "--deploy") result.deploy = true;
60
+ else if (argument === "--dry-run") result.dryRun = true;
61
+ else if (argument === "--help" || argument === "-h") result.help = true;
62
+ else if (argument === "--version" || argument === "-v") result.version = true;
63
+ else if (["--name", "--public-url", "--origin", "--admin-email", "--access-aud", "--email-from"].includes(argument)) {
64
+ const value = valueAfter(argv, index, argument);
65
+ index += 1;
66
+ if (argument === "--name") result.installationName = value;
67
+ else if (argument === "--public-url") result.publicBaseUrl = value;
68
+ else if (argument === "--origin") result.allowedOrigins.push(value);
69
+ else if (argument === "--admin-email") result.adminEmails.push(...value.split(","));
70
+ else if (argument === "--access-aud") result.accessAudience = value;
71
+ else result.emailFromAddress = value;
72
+ } else throw new Error(`unknown option: ${argument}`);
73
+ }
74
+ if (result.deploy && result.skipInstall) throw new Error("--deploy cannot be used with --skip-install");
75
+ return result;
76
+ }
77
+
78
+ function command(program, args, { cwd, label }) {
79
+ return new Promise((resolvePromise, reject) => {
80
+ const child = spawn(program, args, { cwd, stdio: "inherit", env: process.env });
81
+ child.once("error", reject);
82
+ child.once("exit", (code, signal) => code === 0 ? resolvePromise() : reject(new Error(`${label} failed${signal ? ` with signal ${signal}` : ` with exit code ${code}`}`)));
83
+ });
84
+ }
85
+
86
+ async function ask(input, prompt, fallback = "") {
87
+ const answer = (await input.question(`${prompt}${fallback ? ` (${fallback})` : ""}: `)).trim();
88
+ return answer || fallback;
89
+ }
90
+
91
+ async function completeInteractive(options, input) {
92
+ options.installationName ||= await ask(input, "Installation name", "safest-resolve");
93
+ options.publicBaseUrl ||= await ask(input, "Public reports origin", "https://reports.example.com");
94
+ if (!options.allowedOrigins.length) options.allowedOrigins.push(await ask(input, "Application origin allowed to embed the report form", "https://app.example.com"));
95
+ if (!options.adminEmails.length) options.adminEmails.push(await ask(input, "Infrastructure owner email"));
96
+ options.accessAudience ||= await ask(input, "Cloudflare Access application AUD (leave placeholder if it is not created yet)", "replace-with-the-cloudflare-access-application-aud");
97
+ options.emailFromAddress ||= await ask(input, "Sender address on a Cloudflare Email Sending domain");
98
+ return options;
99
+ }
100
+
101
+ export async function runCli(argv, dependencies = {}) {
102
+ const output = dependencies.output ?? console;
103
+ const options = parseArguments(argv);
104
+ if (options.help) { output.log(usage()); return { status: "help" }; }
105
+ if (options.version) { output.log("0.2.0"); return { status: "version" }; }
106
+ const interactive = dependencies.interactive ?? (process.stdin.isTTY && !options.yes);
107
+ if (interactive) {
108
+ const input = createInterface({ input: process.stdin, output: process.stdout });
109
+ try { await completeInteractive(options, input); } finally { input.close(); }
110
+ }
111
+ const configuration = buildConfiguration(options);
112
+ const templateDirectory = dependencies.templateDirectory ?? defaultTemplateDirectory;
113
+ const plan = await validateGeneratedConfiguration(templateDirectory, configuration);
114
+ if (options.dryRun) {
115
+ output.log(JSON.stringify({ configuration, plan }, null, 2));
116
+ return { status: "dry-run", configuration, plan };
117
+ }
118
+ const directory = resolve(options.directory ?? configuration.installationId);
119
+ await scaffoldProject({ directory, templateDirectory, configuration });
120
+ output.log(`Created ${basename(directory)} with the customer-owned Safest Resolve workflow stack.`);
121
+ if (!options.skipInstall) {
122
+ await command("npm", ["install"], { cwd: directory, label: "dependency installation" });
123
+ await command("npm", ["run", "setup:plan"], { cwd: directory, label: "report infrastructure plan" });
124
+ }
125
+ if (options.deploy) await command("npm", ["run", "setup"], { cwd: directory, label: "confirmed Cloudflare setup" });
126
+ else output.log(`Next: review ${directory}/reports.config.json, run npm run setup:plan, then npm run setup for guided Cloudflare and authentication onboarding.`);
127
+ return { status: "created", directory, configuration, plan };
128
+ }
package/src/config.mjs ADDED
@@ -0,0 +1,151 @@
1
+ const SLUG = /^[a-z](?:[a-z0-9-]{0,61}[a-z0-9])?$/u;
2
+ const EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]+$/u;
3
+
4
+ function slug(value, field, fallback) {
5
+ const normalized = String(value || fallback || "").trim().toLowerCase()
6
+ .replace(/[^a-z0-9]+/gu, "-").replace(/^-+|-+$/gu, "").slice(0, 63);
7
+ if (!SLUG.test(normalized)) throw new Error(`${field} must start with a letter and use lowercase letters, numbers, or hyphens`);
8
+ return normalized;
9
+ }
10
+
11
+ function httpsOrigin(value, field) {
12
+ let url;
13
+ try { url = new URL(String(value || "")); } catch { throw new Error(`${field} must be a valid HTTPS origin`); }
14
+ if (url.protocol !== "https:" || url.username || url.password || url.search || url.hash || (url.pathname && url.pathname !== "/")) {
15
+ throw new Error(`${field} must be an HTTPS origin without credentials, path, query, or fragment`);
16
+ }
17
+ return url.origin;
18
+ }
19
+
20
+ function emails(values) {
21
+ const result = [...new Set((values ?? []).map((value) => String(value).trim().toLowerCase()).filter(Boolean))];
22
+ if (result.some((value) => !EMAIL.test(value))) throw new Error("every --admin-email must be a valid email address");
23
+ return result;
24
+ }
25
+
26
+ function optionalEmail(value, field) {
27
+ const result = String(value ?? "").trim().toLowerCase();
28
+ if (result && !EMAIL.test(result)) throw new Error(`${field} must be a valid email address`);
29
+ return result;
30
+ }
31
+
32
+ function resource(base, suffix) {
33
+ const prefix = base.slice(0, 63 - suffix.length - 1).replace(/-+$/u, "");
34
+ return `${prefix}-${suffix}`;
35
+ }
36
+
37
+ export function buildConfiguration(options) {
38
+ const installationId = slug(options.installationName, "installation name", "safest-resolve");
39
+ const publicBaseUrl = httpsOrigin(options.publicBaseUrl, "public URL");
40
+ const allowedOrigins = [...new Set((options.allowedOrigins ?? []).map((value, index) => httpsOrigin(value, `allowed origin ${index + 1}`)))];
41
+ if (!allowedOrigins.length) throw new Error("at least one --origin is required for widget and API embedding");
42
+ const adminEmails = emails(options.adminEmails);
43
+ if (!adminEmails.length) throw new Error("at least one --admin-email is required");
44
+ const accessAudience = String(options.accessAudience ?? "replace-with-the-cloudflare-access-application-aud").trim();
45
+ const emailFromAddress = optionalEmail(options.emailFromAddress, "email sender");
46
+ if (!emailFromAddress) throw new Error("--email-from is required and its domain must be onboarded to Cloudflare Email Sending");
47
+ const resources = {
48
+ workerName: resource(installationId, "worker"),
49
+ databaseName: resource(installationId, "db"),
50
+ profileMediaBucketName: resource(installationId, "profile-media"),
51
+ workflowArtifactsBucketName: resource(installationId, "workflow-artifacts"),
52
+ evidenceBucketName: resource(installationId, "evidence"),
53
+ exportsBucketName: resource(installationId, "exports"),
54
+ workflowName: resource(installationId, "workflows"),
55
+ reportQueueName: resource(installationId, "report-jobs"),
56
+ deliveryQueueName: resource(installationId, "delivery-jobs"),
57
+ operationsDlqName: resource(installationId, "operations-dlq"),
58
+ };
59
+ const publicHostname = new URL(publicBaseUrl).hostname.toLowerCase();
60
+ if (publicHostname.endsWith(".workers.dev") && publicHostname.split(".")[0] !== resources.workerName) {
61
+ throw new Error(`a workers.dev public URL must start with the generated Worker name ${resources.workerName}`);
62
+ }
63
+ return {
64
+ $schema: "./reports.schema.json",
65
+ schemaVersion: 1,
66
+ installationId,
67
+ resources,
68
+ publicBaseUrl,
69
+ allowedOrigins,
70
+ access: {
71
+ audience: accessAudience,
72
+ ownerEmails: adminEmails,
73
+ },
74
+ email: { enabled: true, fromAddress: emailFromAddress },
75
+ auth: { password: true, providers: [] },
76
+ retention: { reportsDays: 365, messagesDays: 180, appealWindowDays: 30 },
77
+ };
78
+ }
79
+
80
+ export function buildWranglerConfiguration(config) {
81
+ const publicHostname = new URL(config.publicBaseUrl).hostname.toLowerCase();
82
+ const wrangler = {
83
+ $schema: "node_modules/wrangler/config-schema.json",
84
+ name: config.resources.workerName,
85
+ main: "src/index.ts",
86
+ compatibility_date: "2026-08-28",
87
+ compatibility_flags: ["nodejs_compat"],
88
+ workers_dev: true,
89
+ preview_urls: true,
90
+ observability: { enabled: true },
91
+ ai: { binding: "AI", remote: true },
92
+ assets: { directory: "public", binding: "ASSETS", run_worker_first: true },
93
+ r2_buckets: [
94
+ { binding: "PROFILE_MEDIA", bucket_name: config.resources.profileMediaBucketName },
95
+ { binding: "WORKFLOW_ARTIFACTS", bucket_name: config.resources.workflowArtifactsBucketName },
96
+ { binding: "EVIDENCE_OBJECTS", bucket_name: config.resources.evidenceBucketName },
97
+ { binding: "EXPORTS", bucket_name: config.resources.exportsBucketName },
98
+ ],
99
+ worker_loaders: [{ binding: "LOADER" }],
100
+ workflows: [{
101
+ name: config.resources.workflowName,
102
+ binding: "WORKFLOWS",
103
+ class_name: "DynamicWorkflow",
104
+ limits: { steps: 1000 },
105
+ }],
106
+ durable_objects: { bindings: [{ name: "WORKSPACE_PRESENCE", class_name: "WorkspacePresence" }] },
107
+ exports: { WorkspacePresence: { type: "durable-object", storage: "sqlite" } },
108
+ d1_databases: [{ binding: "DB", database_name: config.resources.databaseName, migrations_dir: "migrations" }],
109
+ queues: {
110
+ producers: [
111
+ { binding: "CONTROL_JOBS", queue: config.resources.reportQueueName },
112
+ { binding: "REPORT_JOBS", queue: config.resources.reportQueueName },
113
+ { binding: "DELIVERY_JOBS", queue: config.resources.deliveryQueueName },
114
+ ],
115
+ consumers: [
116
+ { queue: config.resources.reportQueueName, max_batch_size: 10, max_batch_timeout: 5, max_retries: 5, dead_letter_queue: config.resources.operationsDlqName },
117
+ { queue: config.resources.deliveryQueueName, max_batch_size: 10, max_batch_timeout: 5, max_retries: 8, dead_letter_queue: config.resources.operationsDlqName },
118
+ { queue: config.resources.operationsDlqName, max_batch_size: 10, max_batch_timeout: 5, max_retries: 0 },
119
+ ],
120
+ },
121
+ vars: {
122
+ PUBLIC_BASE_URL: config.publicBaseUrl,
123
+ ALLOWED_ORIGINS: config.allowedOrigins.join(","),
124
+ CONTEXT_TOKEN_TTL_SECONDS: "300",
125
+ CLAIM_TTL_MINUTES: "15",
126
+ REPORT_RETENTION_DAYS: String(config.retention.reportsDays),
127
+ MESSAGE_RETENTION_DAYS: String(config.retention.messagesDays),
128
+ APPEAL_WINDOW_DAYS: String(config.retention.appealWindowDays),
129
+ ALLOWED_ACTION_CODES: "",
130
+ OPERATIONS_DLQ_NAME: config.resources.operationsDlqName,
131
+ PUBLIC_INTEGRATION_ID: "default",
132
+ PUBLIC_REPORT_LIMIT_PER_10_MINUTES: "5",
133
+ PUBLIC_REPORT_SURGE_PER_5_MINUTES: "250",
134
+ ACCESS_AUD: config.access.audience,
135
+ INFRASTRUCTURE_OWNER_EMAILS: config.access.ownerEmails.join(","),
136
+ TURNSTILE_SITE_KEY: "",
137
+ ACTION_WEBHOOK_URL: "",
138
+ NOTIFICATION_WEBHOOK_URL: "",
139
+ OPERATOR_NOTIFICATION_WEBHOOK_URL: "",
140
+ AUTH_EMAIL_FROM: config.email.fromAddress,
141
+ EMAIL_FROM_ADDRESS: config.email.fromAddress,
142
+ EMAIL_SUBJECT_PREFIX: "Safest report update",
143
+ },
144
+ triggers: { crons: ["*/5 * * * *"] },
145
+ };
146
+ if (!publicHostname.endsWith(".workers.dev")) {
147
+ wrangler.routes = [{ pattern: publicHostname, custom_domain: true }];
148
+ }
149
+ wrangler.send_email = [{ name: "EMAIL" }];
150
+ return wrangler;
151
+ }
@@ -0,0 +1,30 @@
1
+ import { cp, mkdir, readdir, writeFile } from "node:fs/promises";
2
+ import { resolve } from "node:path";
3
+ import { pathToFileURL } from "node:url";
4
+ import { buildWranglerConfiguration } from "./config.mjs";
5
+
6
+ export async function assertEmptyDestination(directory) {
7
+ try {
8
+ const entries = await readdir(directory);
9
+ if (entries.length) throw new Error(`destination is not empty: ${directory}`);
10
+ } catch (error) {
11
+ if (error?.code !== "ENOENT") throw error;
12
+ }
13
+ }
14
+
15
+ export async function scaffoldProject({ directory, templateDirectory, configuration }) {
16
+ const destination = resolve(directory);
17
+ await assertEmptyDestination(destination);
18
+ await mkdir(destination, { recursive: true });
19
+ await cp(templateDirectory, destination, { recursive: true });
20
+ await writeFile(resolve(destination, "reports.config.json"), `${JSON.stringify(configuration, null, 2)}\n`);
21
+ await writeFile(resolve(destination, "wrangler.jsonc"), `${JSON.stringify(buildWranglerConfiguration(configuration), null, 2)}\n`);
22
+ try { await cp(resolve(destination, "gitignore.template"), resolve(destination, ".gitignore")); } catch (error) { if (error?.code !== "ENOENT") throw error; }
23
+ return destination;
24
+ }
25
+
26
+ export async function validateGeneratedConfiguration(templateDirectory, configuration) {
27
+ const module = await import(pathToFileURL(resolve(templateDirectory, "scripts/reports-plan.mjs")).href);
28
+ const config = module.parseReportsConfig(configuration);
29
+ return module.buildReportsPlan(config);
30
+ }