@vesviet/agent-skills 5.6.0 → 5.6.1
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/INDEX.md +1 -1
- package/README.md +1 -1
- package/VERSION +1 -1
- package/adapters/antigravity/a2a-config.template.yaml +1 -1
- package/adapters/antigravity/role-skill-index.json +1 -1
- package/adapters/claude/CLAUDE_ADAPTER.md +1 -1
- package/adapters/cursor/README.md +185 -185
- package/bin/agent-skills.mjs +17 -14
- package/core/contracts/schemas/api-contract-spec.json +191 -191
- package/core/contracts/schemas/feature-ticket.json +1293 -1293
- package/core/contracts/schemas/pull-request-spec.json +338 -338
- package/core/contracts/schemas/references/detailed/01-solution-and-governance.md +19 -19
- package/core/contracts/schemas/references/detailed/02-engineering-delivery.md +93 -93
- package/core/contracts/schemas/references/detailed/04-finance-accounting-and-compliance.md +54 -54
- package/core/contracts/schemas/references/detailed/05-design-and-content.md +92 -92
- package/core/contracts/schemas/references/detailed/06-seo-and-publishing.md +48 -48
- package/core/contracts/schemas/references/detailed/07-a2a-protocol.md +85 -85
- package/core/contracts/schemas/test-report.json +530 -530
- package/core/roles/references/business-analyst-responsibilities.md +207 -207
- package/core/roles/references/frontend-developer-responsibilities.md +275 -275
- package/core/roles/system-engineer.md +465 -465
- package/core/skills/agent/agent-memory-compaction/references/anchored-schema-and-compaction-algorithms.md +141 -141
- package/core/skills/backend/build-mcp-server/SKILL.md +100 -100
- package/core/skills/backend/implement-structured-outputs/SKILL.md +94 -94
- package/core/skills/business/elicit-requirements/SKILL.md +102 -102
- package/core/skills/business/elicit-requirements/references/elicitation-techniques-and-babok-criteria.md +60 -60
- package/core/skills/business/trace-requirements-impact/SKILL.md +97 -97
- package/core/skills/business/trace-requirements-impact/references/rtm-graph-and-prioritization-models.md +109 -109
- package/core/skills/business/write-use-cases/SKILL.md +106 -106
- package/core/skills/business/write-use-cases/references/cockburn-scoping-and-13-field-template.md +135 -135
- package/core/skills/document/pptx/scripts/add_slide.py +0 -0
- package/core/skills/document/pptx/scripts/clean.py +0 -0
- package/core/skills/document/pptx/scripts/thumbnail.py +0 -0
- package/core/skills/document/xlsx/scripts/recalc.py +0 -0
- package/core/skills/documentation/write-documentation/SKILL.md +143 -143
- package/core/skills/documentation/write-tech-radar/SKILL.md +149 -149
- package/core/skills/foundation/accessibility-review/SKILL.md +160 -160
- package/core/skills/foundation/release-notes/SKILL.md +192 -192
- package/core/skills/foundation/webapp-server-runner/scripts/with_server.py +0 -0
- package/core/skills/foundation/write-product-brief/SKILL.md +160 -160
- package/core/skills/platform/cloudflare-email-service/SKILL.md +166 -166
- package/core/skills/platform/cloudflare-email-service/references/routing.md +199 -199
- package/core/skills/platform/debug-workers-edge/SKILL.md +111 -111
- package/core/skills/platform/sandbox-sdk/SKILL.md +183 -183
- package/core/skills/platform/setup-gpu-finops/SKILL.md +107 -107
- package/core/skills/platform/setup-llm-gateway/SKILL.md +108 -108
- package/core/skills/platform/turnstile-spin/SKILL.md +118 -118
- package/core/skills/platform/turnstile-spin/scripts/auth-probe.sh +0 -0
- package/core/skills/platform/turnstile-spin/scripts/fetch-secret.sh +0 -0
- package/core/skills/platform/turnstile-spin/scripts/persist-skill.sh +0 -0
- package/core/skills/platform/turnstile-spin/scripts/validate.sh +0 -0
- package/core/skills/platform/turnstile-spin/scripts/widget-create.sh +0 -0
- package/core/skills/platform/turnstile-spin/scripts/worker-deploy.sh +0 -0
- package/core/skills/platform/turnstile-spin/templates/worker/src/index.ts +199 -199
- package/core/skills/platform/turnstile-spin/templates/worker/wrangler.toml +31 -31
- package/core/skills/platform/web-perf/SKILL.md +151 -151
- package/core/skills/platform/workers-best-practices/references/rules.md +463 -463
- package/core/skills/product/build-story-map/SKILL.md +104 -104
- package/core/skills/product/build-story-map/references/story-mapping-and-cpm-scheduling.md +101 -101
- package/core/skills/product/define-product-strategy/SKILL.md +105 -105
- package/core/skills/product/define-product-strategy/references/strategy-frameworks-and-pr-faq.md +142 -142
- package/core/skills/product/model-saas-metrics/SKILL.md +104 -104
- package/core/skills/product/model-saas-metrics/references/saas-unit-economics-and-pricing.md +110 -110
- package/core/skills/product/prioritize-roadmap/SKILL.md +106 -106
- package/core/skills/product/prioritize-roadmap/references/prioritization-scoring-and-kill-criteria.md +105 -105
- package/core/skills/repo-ops/commit-code/SKILL.md +190 -190
- package/core/skills/repo-ops/commit-code/references/multi-repo-and-deployment.md +21 -21
- package/core/skills/repo-ops/navigate-service/SKILL.md +199 -199
- package/core/skills/repo-ops/review-code/references/process-and-format.md +100 -100
- package/core/skills/repo-ops/review-service/SKILL.md +186 -186
- package/core/skills/repo-ops/troubleshoot-service/SKILL.md +127 -127
- package/core/skills/repo-ops/troubleshoot-service/references/failure-modes-and-security.md +22 -22
- package/core/skills/repo-ops/troubleshoot-service/references/suggested-process.md +110 -110
- package/core/skills/security-data/security-audit/SKILL.md +119 -119
- package/core/workflows/add-new-feature.md +212 -212
- package/core/workflows/agent-a2a-delegation.md +142 -142
- package/core/workflows/bug-fix.md +147 -147
- package/core/workflows/build-deploy.md +208 -208
- package/core/workflows/code-review.md +137 -137
- package/core/workflows/dependency-upgrade.md +193 -193
- package/core/workflows/feature-delivery.md +149 -149
- package/core/workflows/hotfix-production.md +172 -172
- package/core/workflows/qa-validation.md +231 -231
- package/core/workflows/refactoring.md +154 -154
- package/core/workflows/revert-deployment.md +147 -147
- package/core/workflows/security-incident-response.md +191 -191
- package/core/workflows/seo-content-lifecycle.md +91 -91
- package/core/workflows/service-review-release.md +223 -223
- package/core/workflows/setup-new-service.md +214 -214
- package/core/workflows/tech-repo-review.md +245 -245
- package/core/workflows/troubleshooting.md +241 -241
- package/overlays/astro-cloudflare/README.md +93 -93
- package/overlays/data-analyst-stack/README.md +109 -109
- package/overlays/data-analyst-stack/rules/metric-dashboard-templates.md +135 -135
- package/overlays/data-analyst-stack/rules/stack-conventions.md +80 -80
- package/overlays/ecommerce-microservices/README.md +65 -65
- package/overlays/go-microservices/README.md +78 -78
- package/overlays/go-microservices/rules/go-conventions.md +223 -223
- package/overlays/laravel-filament/README.md +90 -90
- package/overlays/laravel-filament/rules/laravel-conventions.md +220 -220
- package/overlays/laravel-filament/skills/develop-laravel-feature/SKILL.md +141 -141
- package/overlays/laravel-filament/workflows/deploy-laravel.md +133 -133
- package/overlays/obj-configurator/rules/obj-project-rules.md +111 -111
- package/overlays/obj-configurator/skills/develop-obj-feature/SKILL.md +71 -71
- package/overlays/r3f-stack/README.md +89 -89
- package/overlays/r3f-stack/rules/stub.md +43 -43
- package/overlays/r3f-stack/skills/debug-3d-scene/SKILL.md +166 -166
- package/overlays/r3f-stack/skills/integrate-r3f-three-legacy/SKILL.md +159 -159
- package/overlays/r3f-stack/skills/optimize-3d-assets/SKILL.md +128 -128
- package/overlays/seo-publishing/rules/site-mix-and-cannibalization.md +52 -52
- package/overlays/ui-design-system/rules/handoff-conventions.md +73 -73
- package/package.json +2 -2
- package/core/README.md +0 -53
|
@@ -1,199 +1,199 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* turnstile-siteverify — the managed siteverify backend for Turnstile Spin.
|
|
3
|
-
*
|
|
4
|
-
* A drop-in implementation of Cloudflare Turnstile server-side validation
|
|
5
|
-
* built entirely on Workers. Customers deploy this Worker into their account
|
|
6
|
-
* via Turnstile Spin (AI system or Deploy-to-Cloudflare button) and point
|
|
7
|
-
* their frontend at it.
|
|
8
|
-
*
|
|
9
|
-
* Accepts both `application/x-www-form-urlencoded` and `application/json`
|
|
10
|
-
* bodies. Forwards the token to Cloudflare's siteverify endpoint using a
|
|
11
|
-
* secret stored as a Worker secret. Emits structured logs visible in Workers
|
|
12
|
-
* Observability.
|
|
13
|
-
*
|
|
14
|
-
* Endpoints:
|
|
15
|
-
* POST / siteverify proxy (main entry point)
|
|
16
|
-
* POST /siteverify alias of POST /
|
|
17
|
-
* GET /health health check, returns {ok: true, version}
|
|
18
|
-
* GET / same as /health
|
|
19
|
-
* GET /post-deploy the post-deploy form (served from public/)
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
import { SiteverifyError, errorResponse } from './errors.js';
|
|
23
|
-
import { logSiteverify } from './observability.js';
|
|
24
|
-
import { validate } from './validate.js';
|
|
25
|
-
import type { Env, SiteverifyRequest } from './types.js';
|
|
26
|
-
|
|
27
|
-
export const WORKER_VERSION = '1.0.0';
|
|
28
|
-
|
|
29
|
-
function corsHeaders(env: Env): Record<string, string> {
|
|
30
|
-
return {
|
|
31
|
-
'Access-Control-Allow-Origin': env.ALLOWED_ORIGIN || '*',
|
|
32
|
-
'Access-Control-Allow-Methods': 'POST, GET, OPTIONS',
|
|
33
|
-
'Access-Control-Allow-Headers': 'Content-Type, Idempotency-Key',
|
|
34
|
-
'Access-Control-Max-Age': '86400',
|
|
35
|
-
Vary: 'Origin',
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function jsonResponse(body: unknown, status: number, env: Env): Response {
|
|
40
|
-
return new Response(JSON.stringify(body, null, 2), {
|
|
41
|
-
status,
|
|
42
|
-
headers: {
|
|
43
|
-
'Content-Type': 'application/json; charset=utf-8',
|
|
44
|
-
...corsHeaders(env),
|
|
45
|
-
},
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
async function parseBody(request: Request): Promise<SiteverifyRequest> {
|
|
50
|
-
const contentType = request.headers.get('content-type') || '';
|
|
51
|
-
|
|
52
|
-
if (contentType.includes('application/json')) {
|
|
53
|
-
const body = (await request.json()) as Record<string, unknown>;
|
|
54
|
-
return {
|
|
55
|
-
// `response` is accepted for compatibility with code migrated from reCAPTCHA/hCaptcha,
|
|
56
|
-
// whose backends POST {secret, response, remoteip}. Spin's Worker holds the secret,
|
|
57
|
-
// so callers should send {token} or {cf-turnstile-response}; we accept {response}
|
|
58
|
-
|
|
59
|
-
token: String(body.token ?? body['cf-turnstile-response'] ?? body.response ?? ''),
|
|
60
|
-
remoteip: body.remoteip ? String(body.remoteip) : undefined,
|
|
61
|
-
idempotency_key: body.idempotency_key ? String(body.idempotency_key) : undefined,
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (contentType.includes('application/x-www-form-urlencoded') || contentType.includes('multipart/form-data')) {
|
|
66
|
-
const form = await request.formData();
|
|
67
|
-
return {
|
|
68
|
-
token: String(form.get('token') ?? form.get('cf-turnstile-response') ?? form.get('response') ?? ''),
|
|
69
|
-
remoteip: form.get('remoteip') ? String(form.get('remoteip')) : undefined,
|
|
70
|
-
idempotency_key: form.get('idempotency_key') ? String(form.get('idempotency_key')) : undefined,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
throw new SiteverifyError(
|
|
75
|
-
415,
|
|
76
|
-
'invalid-content-type',
|
|
77
|
-
`Unsupported Content-Type: ${contentType || '(missing)'}. Use application/json or application/x-www-form-urlencoded.`,
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
async function handleSiteverify(request: Request, env: Env): Promise<Response> {
|
|
82
|
-
const startedAt = Date.now();
|
|
83
|
-
let parsed: SiteverifyRequest;
|
|
84
|
-
try {
|
|
85
|
-
parsed = await parseBody(request);
|
|
86
|
-
} catch (err) {
|
|
87
|
-
if (err instanceof SiteverifyError) {
|
|
88
|
-
const body = errorResponse(err.code, Date.now() - startedAt, WORKER_VERSION);
|
|
89
|
-
logSiteverify('error', {
|
|
90
|
-
durationMs: Date.now() - startedAt,
|
|
91
|
-
errorCodes: [err.code],
|
|
92
|
-
remoteipPresent: false,
|
|
93
|
-
idempotencyKeyPresent: false,
|
|
94
|
-
});
|
|
95
|
-
return jsonResponse(body, err.status, env);
|
|
96
|
-
}
|
|
97
|
-
// Body parse failure (malformed JSON, etc.)
|
|
98
|
-
const body = errorResponse('bad-request', Date.now() - startedAt, WORKER_VERSION);
|
|
99
|
-
logSiteverify('error', {
|
|
100
|
-
durationMs: Date.now() - startedAt,
|
|
101
|
-
errorCodes: ['bad-request'],
|
|
102
|
-
remoteipPresent: false,
|
|
103
|
-
idempotencyKeyPresent: false,
|
|
104
|
-
});
|
|
105
|
-
return jsonResponse(body, 400, env);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// Fall back to CF-Connecting-IP if customer didn't pass remoteip explicitly.
|
|
109
|
-
const remoteip = parsed.remoteip ?? request.headers.get('CF-Connecting-IP') ?? undefined;
|
|
110
|
-
const requestForValidate: SiteverifyRequest = { ...parsed, remoteip };
|
|
111
|
-
|
|
112
|
-
try {
|
|
113
|
-
const { response, upstreamStatus, durationMs } = await validate(requestForValidate, env, WORKER_VERSION);
|
|
114
|
-
|
|
115
|
-
logSiteverify(response.success ? 'ok' : 'fail', {
|
|
116
|
-
durationMs,
|
|
117
|
-
upstreamStatus,
|
|
118
|
-
errorCodes: response['error-codes'],
|
|
119
|
-
cdataValue: response.cdata,
|
|
120
|
-
remoteipPresent: !!remoteip,
|
|
121
|
-
idempotencyKeyPresent: !!parsed.idempotency_key,
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
// Per spec, return 200 even on validation failure — callers should check
|
|
125
|
-
// response.success, not the HTTP status. (Matches Cloudflare's own
|
|
126
|
-
// siteverify behavior; the Worker is a thin proxy.)
|
|
127
|
-
return jsonResponse(response, 200, env);
|
|
128
|
-
} catch (err) {
|
|
129
|
-
if (err instanceof SiteverifyError) {
|
|
130
|
-
const body = errorResponse(err.code, Date.now() - startedAt, WORKER_VERSION);
|
|
131
|
-
logSiteverify('error', {
|
|
132
|
-
durationMs: Date.now() - startedAt,
|
|
133
|
-
errorCodes: [err.code],
|
|
134
|
-
remoteipPresent: !!remoteip,
|
|
135
|
-
idempotencyKeyPresent: !!parsed.idempotency_key,
|
|
136
|
-
});
|
|
137
|
-
return jsonResponse(body, err.status, env);
|
|
138
|
-
}
|
|
139
|
-
const body = errorResponse('internal-error', Date.now() - startedAt, WORKER_VERSION);
|
|
140
|
-
logSiteverify('error', {
|
|
141
|
-
durationMs: Date.now() - startedAt,
|
|
142
|
-
errorCodes: ['internal-error'],
|
|
143
|
-
remoteipPresent: !!remoteip,
|
|
144
|
-
idempotencyKeyPresent: !!parsed.idempotency_key,
|
|
145
|
-
});
|
|
146
|
-
return jsonResponse(body, 500, env);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
function handleHealth(env: Env): Response {
|
|
151
|
-
return jsonResponse(
|
|
152
|
-
{
|
|
153
|
-
ok: true,
|
|
154
|
-
version: WORKER_VERSION,
|
|
155
|
-
service: 'turnstile-siteverify',
|
|
156
|
-
docs: 'https://developers.cloudflare.com/turnstile/spin/',
|
|
157
|
-
},
|
|
158
|
-
200,
|
|
159
|
-
env,
|
|
160
|
-
);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
export default {
|
|
164
|
-
async fetch(request: Request, env: Env): Promise<Response> {
|
|
165
|
-
if (request.method === 'OPTIONS') {
|
|
166
|
-
return new Response(null, { status: 204, headers: corsHeaders(env) });
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
const url = new URL(request.url);
|
|
170
|
-
|
|
171
|
-
if (request.method === 'GET' && (url.pathname === '/' || url.pathname === '/health' || url.pathname === '/healthz')) {
|
|
172
|
-
return handleHealth(env);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// Post-deploy form (served from public/post-deploy.html via the ASSETS binding).
|
|
176
|
-
// The form prefills the Worker URL and lets a Deploy-button user create a widget
|
|
177
|
-
// without leaving the flow.
|
|
178
|
-
if (request.method === 'GET' && url.pathname === '/post-deploy') {
|
|
179
|
-
if (env.ASSETS) {
|
|
180
|
-
return env.ASSETS.fetch(new Request(new URL('/post-deploy.html', url.origin)));
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
const isSiteverifyPath = url.pathname === '/' || url.pathname === '/siteverify';
|
|
185
|
-
if (request.method === 'POST' && isSiteverifyPath) {
|
|
186
|
-
return handleSiteverify(request, env);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
return jsonResponse(
|
|
190
|
-
{
|
|
191
|
-
success: false,
|
|
192
|
-
'error-codes': ['bad-request'],
|
|
193
|
-
hint: 'POST a Turnstile token to / (or /siteverify) as JSON or form-encoded body.',
|
|
194
|
-
},
|
|
195
|
-
404,
|
|
196
|
-
env,
|
|
197
|
-
);
|
|
198
|
-
},
|
|
199
|
-
} satisfies ExportedHandler<Env>;
|
|
1
|
+
/**
|
|
2
|
+
* turnstile-siteverify — the managed siteverify backend for Turnstile Spin.
|
|
3
|
+
*
|
|
4
|
+
* A drop-in implementation of Cloudflare Turnstile server-side validation
|
|
5
|
+
* built entirely on Workers. Customers deploy this Worker into their account
|
|
6
|
+
* via Turnstile Spin (AI system or Deploy-to-Cloudflare button) and point
|
|
7
|
+
* their frontend at it.
|
|
8
|
+
*
|
|
9
|
+
* Accepts both `application/x-www-form-urlencoded` and `application/json`
|
|
10
|
+
* bodies. Forwards the token to Cloudflare's siteverify endpoint using a
|
|
11
|
+
* secret stored as a Worker secret. Emits structured logs visible in Workers
|
|
12
|
+
* Observability.
|
|
13
|
+
*
|
|
14
|
+
* Endpoints:
|
|
15
|
+
* POST / siteverify proxy (main entry point)
|
|
16
|
+
* POST /siteverify alias of POST /
|
|
17
|
+
* GET /health health check, returns {ok: true, version}
|
|
18
|
+
* GET / same as /health
|
|
19
|
+
* GET /post-deploy the post-deploy form (served from public/)
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { SiteverifyError, errorResponse } from './errors.js';
|
|
23
|
+
import { logSiteverify } from './observability.js';
|
|
24
|
+
import { validate } from './validate.js';
|
|
25
|
+
import type { Env, SiteverifyRequest } from './types.js';
|
|
26
|
+
|
|
27
|
+
export const WORKER_VERSION = '1.0.0';
|
|
28
|
+
|
|
29
|
+
function corsHeaders(env: Env): Record<string, string> {
|
|
30
|
+
return {
|
|
31
|
+
'Access-Control-Allow-Origin': env.ALLOWED_ORIGIN || '*',
|
|
32
|
+
'Access-Control-Allow-Methods': 'POST, GET, OPTIONS',
|
|
33
|
+
'Access-Control-Allow-Headers': 'Content-Type, Idempotency-Key',
|
|
34
|
+
'Access-Control-Max-Age': '86400',
|
|
35
|
+
Vary: 'Origin',
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function jsonResponse(body: unknown, status: number, env: Env): Response {
|
|
40
|
+
return new Response(JSON.stringify(body, null, 2), {
|
|
41
|
+
status,
|
|
42
|
+
headers: {
|
|
43
|
+
'Content-Type': 'application/json; charset=utf-8',
|
|
44
|
+
...corsHeaders(env),
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function parseBody(request: Request): Promise<SiteverifyRequest> {
|
|
50
|
+
const contentType = request.headers.get('content-type') || '';
|
|
51
|
+
|
|
52
|
+
if (contentType.includes('application/json')) {
|
|
53
|
+
const body = (await request.json()) as Record<string, unknown>;
|
|
54
|
+
return {
|
|
55
|
+
// `response` is accepted for compatibility with code migrated from reCAPTCHA/hCaptcha,
|
|
56
|
+
// whose backends POST {secret, response, remoteip}. Spin's Worker holds the secret,
|
|
57
|
+
// so callers should send {token} or {cf-turnstile-response}; we accept {response}
|
|
58
|
+
|
|
59
|
+
token: String(body.token ?? body['cf-turnstile-response'] ?? body.response ?? ''),
|
|
60
|
+
remoteip: body.remoteip ? String(body.remoteip) : undefined,
|
|
61
|
+
idempotency_key: body.idempotency_key ? String(body.idempotency_key) : undefined,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (contentType.includes('application/x-www-form-urlencoded') || contentType.includes('multipart/form-data')) {
|
|
66
|
+
const form = await request.formData();
|
|
67
|
+
return {
|
|
68
|
+
token: String(form.get('token') ?? form.get('cf-turnstile-response') ?? form.get('response') ?? ''),
|
|
69
|
+
remoteip: form.get('remoteip') ? String(form.get('remoteip')) : undefined,
|
|
70
|
+
idempotency_key: form.get('idempotency_key') ? String(form.get('idempotency_key')) : undefined,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
throw new SiteverifyError(
|
|
75
|
+
415,
|
|
76
|
+
'invalid-content-type',
|
|
77
|
+
`Unsupported Content-Type: ${contentType || '(missing)'}. Use application/json or application/x-www-form-urlencoded.`,
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function handleSiteverify(request: Request, env: Env): Promise<Response> {
|
|
82
|
+
const startedAt = Date.now();
|
|
83
|
+
let parsed: SiteverifyRequest;
|
|
84
|
+
try {
|
|
85
|
+
parsed = await parseBody(request);
|
|
86
|
+
} catch (err) {
|
|
87
|
+
if (err instanceof SiteverifyError) {
|
|
88
|
+
const body = errorResponse(err.code, Date.now() - startedAt, WORKER_VERSION);
|
|
89
|
+
logSiteverify('error', {
|
|
90
|
+
durationMs: Date.now() - startedAt,
|
|
91
|
+
errorCodes: [err.code],
|
|
92
|
+
remoteipPresent: false,
|
|
93
|
+
idempotencyKeyPresent: false,
|
|
94
|
+
});
|
|
95
|
+
return jsonResponse(body, err.status, env);
|
|
96
|
+
}
|
|
97
|
+
// Body parse failure (malformed JSON, etc.)
|
|
98
|
+
const body = errorResponse('bad-request', Date.now() - startedAt, WORKER_VERSION);
|
|
99
|
+
logSiteverify('error', {
|
|
100
|
+
durationMs: Date.now() - startedAt,
|
|
101
|
+
errorCodes: ['bad-request'],
|
|
102
|
+
remoteipPresent: false,
|
|
103
|
+
idempotencyKeyPresent: false,
|
|
104
|
+
});
|
|
105
|
+
return jsonResponse(body, 400, env);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Fall back to CF-Connecting-IP if customer didn't pass remoteip explicitly.
|
|
109
|
+
const remoteip = parsed.remoteip ?? request.headers.get('CF-Connecting-IP') ?? undefined;
|
|
110
|
+
const requestForValidate: SiteverifyRequest = { ...parsed, remoteip };
|
|
111
|
+
|
|
112
|
+
try {
|
|
113
|
+
const { response, upstreamStatus, durationMs } = await validate(requestForValidate, env, WORKER_VERSION);
|
|
114
|
+
|
|
115
|
+
logSiteverify(response.success ? 'ok' : 'fail', {
|
|
116
|
+
durationMs,
|
|
117
|
+
upstreamStatus,
|
|
118
|
+
errorCodes: response['error-codes'],
|
|
119
|
+
cdataValue: response.cdata,
|
|
120
|
+
remoteipPresent: !!remoteip,
|
|
121
|
+
idempotencyKeyPresent: !!parsed.idempotency_key,
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// Per spec, return 200 even on validation failure — callers should check
|
|
125
|
+
// response.success, not the HTTP status. (Matches Cloudflare's own
|
|
126
|
+
// siteverify behavior; the Worker is a thin proxy.)
|
|
127
|
+
return jsonResponse(response, 200, env);
|
|
128
|
+
} catch (err) {
|
|
129
|
+
if (err instanceof SiteverifyError) {
|
|
130
|
+
const body = errorResponse(err.code, Date.now() - startedAt, WORKER_VERSION);
|
|
131
|
+
logSiteverify('error', {
|
|
132
|
+
durationMs: Date.now() - startedAt,
|
|
133
|
+
errorCodes: [err.code],
|
|
134
|
+
remoteipPresent: !!remoteip,
|
|
135
|
+
idempotencyKeyPresent: !!parsed.idempotency_key,
|
|
136
|
+
});
|
|
137
|
+
return jsonResponse(body, err.status, env);
|
|
138
|
+
}
|
|
139
|
+
const body = errorResponse('internal-error', Date.now() - startedAt, WORKER_VERSION);
|
|
140
|
+
logSiteverify('error', {
|
|
141
|
+
durationMs: Date.now() - startedAt,
|
|
142
|
+
errorCodes: ['internal-error'],
|
|
143
|
+
remoteipPresent: !!remoteip,
|
|
144
|
+
idempotencyKeyPresent: !!parsed.idempotency_key,
|
|
145
|
+
});
|
|
146
|
+
return jsonResponse(body, 500, env);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function handleHealth(env: Env): Response {
|
|
151
|
+
return jsonResponse(
|
|
152
|
+
{
|
|
153
|
+
ok: true,
|
|
154
|
+
version: WORKER_VERSION,
|
|
155
|
+
service: 'turnstile-siteverify',
|
|
156
|
+
docs: 'https://developers.cloudflare.com/turnstile/spin/',
|
|
157
|
+
},
|
|
158
|
+
200,
|
|
159
|
+
env,
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export default {
|
|
164
|
+
async fetch(request: Request, env: Env): Promise<Response> {
|
|
165
|
+
if (request.method === 'OPTIONS') {
|
|
166
|
+
return new Response(null, { status: 204, headers: corsHeaders(env) });
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const url = new URL(request.url);
|
|
170
|
+
|
|
171
|
+
if (request.method === 'GET' && (url.pathname === '/' || url.pathname === '/health' || url.pathname === '/healthz')) {
|
|
172
|
+
return handleHealth(env);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Post-deploy form (served from public/post-deploy.html via the ASSETS binding).
|
|
176
|
+
// The form prefills the Worker URL and lets a Deploy-button user create a widget
|
|
177
|
+
// without leaving the flow.
|
|
178
|
+
if (request.method === 'GET' && url.pathname === '/post-deploy') {
|
|
179
|
+
if (env.ASSETS) {
|
|
180
|
+
return env.ASSETS.fetch(new Request(new URL('/post-deploy.html', url.origin)));
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const isSiteverifyPath = url.pathname === '/' || url.pathname === '/siteverify';
|
|
185
|
+
if (request.method === 'POST' && isSiteverifyPath) {
|
|
186
|
+
return handleSiteverify(request, env);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return jsonResponse(
|
|
190
|
+
{
|
|
191
|
+
success: false,
|
|
192
|
+
'error-codes': ['bad-request'],
|
|
193
|
+
hint: 'POST a Turnstile token to / (or /siteverify) as JSON or form-encoded body.',
|
|
194
|
+
},
|
|
195
|
+
404,
|
|
196
|
+
env,
|
|
197
|
+
);
|
|
198
|
+
},
|
|
199
|
+
} satisfies ExportedHandler<Env>;
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
name = "turnstile-siteverify"
|
|
2
|
-
main = "src/index.ts"
|
|
3
|
-
compatibility_date = "2026-05-01"
|
|
4
|
-
compatibility_flags = ["nodejs_compat"]
|
|
5
|
-
|
|
6
|
-
# Serve the post-deploy form (public/post-deploy.html) as a static asset.
|
|
7
|
-
# After deploy, customers land on /post-deploy.html with their Worker URL
|
|
8
|
-
# prefilled, and can create a Turnstile widget without leaving the flow.
|
|
9
|
-
[assets]
|
|
10
|
-
directory = "./public"
|
|
11
|
-
binding = "ASSETS"
|
|
12
|
-
|
|
13
|
-
# Workers Observability — structured logs, latency tracking, error rates
|
|
14
|
-
# all surface in the Worker's Observability tab in the dashboard.
|
|
15
|
-
[observability]
|
|
16
|
-
enabled = true
|
|
17
|
-
|
|
18
|
-
[vars]
|
|
19
|
-
# CORS allowed origin. Override per-environment.
|
|
20
|
-
# In production, set this to your customer-facing domain (e.g. "https://example.com").
|
|
21
|
-
# Leaving as "*" for development; production deploys MUST set this explicitly.
|
|
22
|
-
ALLOWED_ORIGIN = "*"
|
|
23
|
-
# Optional: defense against cross-site token replay. If set, the Worker
|
|
24
|
-
# rejects siteverify responses whose hostname doesn't match. Set this to
|
|
25
|
-
# your customer-facing domain (e.g. "www.example.com") for additional safety
|
|
26
|
-
|
|
27
|
-
LOG_LEVEL = "info"
|
|
28
|
-
# Secrets — never commit. Set via:
|
|
29
|
-
# wrangler secret put TURNSTILE_SECRET_KEY
|
|
30
|
-
# For local dev, create .dev.vars (gitignored) with:
|
|
31
|
-
|
|
1
|
+
name = "turnstile-siteverify"
|
|
2
|
+
main = "src/index.ts"
|
|
3
|
+
compatibility_date = "2026-05-01"
|
|
4
|
+
compatibility_flags = ["nodejs_compat"]
|
|
5
|
+
|
|
6
|
+
# Serve the post-deploy form (public/post-deploy.html) as a static asset.
|
|
7
|
+
# After deploy, customers land on /post-deploy.html with their Worker URL
|
|
8
|
+
# prefilled, and can create a Turnstile widget without leaving the flow.
|
|
9
|
+
[assets]
|
|
10
|
+
directory = "./public"
|
|
11
|
+
binding = "ASSETS"
|
|
12
|
+
|
|
13
|
+
# Workers Observability — structured logs, latency tracking, error rates
|
|
14
|
+
# all surface in the Worker's Observability tab in the dashboard.
|
|
15
|
+
[observability]
|
|
16
|
+
enabled = true
|
|
17
|
+
|
|
18
|
+
[vars]
|
|
19
|
+
# CORS allowed origin. Override per-environment.
|
|
20
|
+
# In production, set this to your customer-facing domain (e.g. "https://example.com").
|
|
21
|
+
# Leaving as "*" for development; production deploys MUST set this explicitly.
|
|
22
|
+
ALLOWED_ORIGIN = "*"
|
|
23
|
+
# Optional: defense against cross-site token replay. If set, the Worker
|
|
24
|
+
# rejects siteverify responses whose hostname doesn't match. Set this to
|
|
25
|
+
# your customer-facing domain (e.g. "www.example.com") for additional safety
|
|
26
|
+
|
|
27
|
+
LOG_LEVEL = "info"
|
|
28
|
+
# Secrets — never commit. Set via:
|
|
29
|
+
# wrangler secret put TURNSTILE_SECRET_KEY
|
|
30
|
+
# For local dev, create .dev.vars (gitignored) with:
|
|
31
|
+
|