pi-cloudflare 0.10.2 → 0.11.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 (293) hide show
  1. package/README.md +78 -180
  2. package/package.json +7 -42
  3. package/plugin.json +3 -3
  4. package/skills/agents-sdk/SKILL.md +17 -36
  5. package/skills/agents-sdk/references/client-sdk.md +7 -106
  6. package/skills/agents-sdk/references/human-in-the-loop.md +6 -63
  7. package/skills/agents-sdk/references/mcp.md +9 -184
  8. package/skills/agents-sdk/references/queue-retries.md +12 -73
  9. package/skills/agents-sdk/references/server-driven-messages.md +4 -60
  10. package/skills/agents-sdk/references/state-scheduling.md +10 -166
  11. package/skills/agents-sdk/references/streaming-chat.md +11 -193
  12. package/skills/agents-sdk/references/webhooks-push.md +2 -2
  13. package/skills/agents-sdk/references/workflows.md +14 -125
  14. package/skills/cloudflare/SKILL.md +135 -248
  15. package/skills/cloudflare/references/ai-gateway/README.md +17 -165
  16. package/skills/cloudflare/references/ai-gateway/configuration.md +14 -107
  17. package/skills/cloudflare/references/ai-gateway/dynamic-routing.md +12 -79
  18. package/skills/cloudflare/references/ai-gateway/features.md +22 -96
  19. package/skills/cloudflare/references/ai-gateway/sdk-integration.md +17 -112
  20. package/skills/cloudflare/references/ai-gateway/troubleshooting.md +14 -86
  21. package/skills/cloudflare/references/ai-search/README.md +17 -130
  22. package/skills/cloudflare/references/ai-search/api.md +10 -84
  23. package/skills/cloudflare/references/ai-search/configuration.md +16 -88
  24. package/skills/cloudflare/references/ai-search/gotchas.md +13 -81
  25. package/skills/cloudflare/references/ai-search/patterns.md +12 -82
  26. package/skills/cloudflare/references/analytics-engine/api.md +1 -1
  27. package/skills/cloudflare/references/api/README.md +2 -2
  28. package/skills/cloudflare/references/api/configuration.md +1 -1
  29. package/skills/cloudflare/references/bindings/README.md +11 -117
  30. package/skills/cloudflare/references/bindings/api.md +17 -201
  31. package/skills/cloudflare/references/bindings/configuration.md +20 -188
  32. package/skills/cloudflare/references/bindings/gotchas.md +16 -206
  33. package/skills/cloudflare/references/bindings/patterns.md +15 -195
  34. package/skills/cloudflare/references/bot-management/README.md +1 -1
  35. package/skills/cloudflare/references/browser-rendering/README.md +13 -73
  36. package/skills/cloudflare/references/browser-rendering/api.md +9 -105
  37. package/skills/cloudflare/references/browser-rendering/configuration.md +9 -75
  38. package/skills/cloudflare/references/browser-rendering/gotchas.md +12 -85
  39. package/skills/cloudflare/references/browser-rendering/patterns.md +9 -88
  40. package/skills/cloudflare/references/c3/README.md +6 -5
  41. package/skills/cloudflare/references/c3/api.md +3 -4
  42. package/skills/cloudflare/references/c3/patterns.md +4 -6
  43. package/skills/cloudflare/references/cache-reserve/README.md +1 -1
  44. package/skills/cloudflare/references/containers/README.md +15 -77
  45. package/skills/cloudflare/references/containers/api.md +13 -187
  46. package/skills/cloudflare/references/containers/configuration.md +15 -188
  47. package/skills/cloudflare/references/containers/gotchas.md +16 -178
  48. package/skills/cloudflare/references/containers/patterns.md +14 -198
  49. package/skills/cloudflare/references/cron-triggers/README.md +13 -92
  50. package/skills/cloudflare/references/cron-triggers/api.md +11 -191
  51. package/skills/cloudflare/references/cron-triggers/configuration.md +11 -175
  52. package/skills/cloudflare/references/cron-triggers/gotchas.md +13 -195
  53. package/skills/cloudflare/references/cron-triggers/patterns.md +12 -184
  54. package/skills/cloudflare/references/d1/README.md +9 -127
  55. package/skills/cloudflare/references/d1/api.md +16 -194
  56. package/skills/cloudflare/references/d1/configuration.md +16 -189
  57. package/skills/cloudflare/references/d1/gotchas.md +16 -96
  58. package/skills/cloudflare/references/d1/patterns.md +14 -183
  59. package/skills/cloudflare/references/do-storage/README.md +11 -70
  60. package/skills/cloudflare/references/do-storage/api.md +11 -99
  61. package/skills/cloudflare/references/do-storage/configuration.md +11 -107
  62. package/skills/cloudflare/references/do-storage/gotchas.md +12 -147
  63. package/skills/cloudflare/references/do-storage/patterns.md +11 -190
  64. package/skills/cloudflare/references/do-storage/testing.md +8 -178
  65. package/skills/cloudflare/references/email-routing/README.md +14 -84
  66. package/skills/cloudflare/references/email-routing/api.md +10 -192
  67. package/skills/cloudflare/references/email-routing/configuration.md +13 -186
  68. package/skills/cloudflare/references/email-routing/gotchas.md +12 -193
  69. package/skills/cloudflare/references/email-routing/patterns.md +10 -226
  70. package/skills/cloudflare/references/email-workers/README.md +13 -146
  71. package/skills/cloudflare/references/email-workers/api.md +12 -234
  72. package/skills/cloudflare/references/email-workers/configuration.md +14 -110
  73. package/skills/cloudflare/references/email-workers/gotchas.md +15 -125
  74. package/skills/cloudflare/references/email-workers/patterns.md +14 -100
  75. package/skills/cloudflare/references/flagship/README.md +2 -2
  76. package/skills/cloudflare/references/hyperdrive/README.md +17 -72
  77. package/skills/cloudflare/references/hyperdrive/api.md +19 -136
  78. package/skills/cloudflare/references/hyperdrive/configuration.md +27 -159
  79. package/skills/cloudflare/references/hyperdrive/gotchas.md +15 -72
  80. package/skills/cloudflare/references/hyperdrive/patterns.md +12 -187
  81. package/skills/cloudflare/references/images/README.md +9 -58
  82. package/skills/cloudflare/references/images/api.md +13 -96
  83. package/skills/cloudflare/references/images/configuration.md +17 -211
  84. package/skills/cloudflare/references/images/gotchas.md +16 -99
  85. package/skills/cloudflare/references/images/patterns.md +16 -115
  86. package/skills/cloudflare/references/kv/README.md +9 -83
  87. package/skills/cloudflare/references/kv/api.md +12 -154
  88. package/skills/cloudflare/references/kv/configuration.md +11 -139
  89. package/skills/cloudflare/references/kv/gotchas.md +15 -129
  90. package/skills/cloudflare/references/kv/patterns.md +15 -190
  91. package/skills/cloudflare/references/miniflare/README.md +15 -98
  92. package/skills/cloudflare/references/miniflare/api.md +16 -187
  93. package/skills/cloudflare/references/miniflare/configuration.md +12 -169
  94. package/skills/cloudflare/references/miniflare/gotchas.md +15 -160
  95. package/skills/cloudflare/references/miniflare/patterns.md +15 -177
  96. package/skills/cloudflare/references/network-interconnect/README.md +1 -1
  97. package/skills/cloudflare/references/network-interconnect/gotchas.md +1 -1
  98. package/skills/cloudflare/references/network-interconnect/patterns.md +1 -1
  99. package/skills/cloudflare/references/observability/README.md +20 -81
  100. package/skills/cloudflare/references/observability/api.md +20 -164
  101. package/skills/cloudflare/references/observability/configuration.md +18 -164
  102. package/skills/cloudflare/references/observability/gotchas.md +19 -109
  103. package/skills/cloudflare/references/observability/patterns.md +12 -103
  104. package/skills/cloudflare/references/pages/README.md +13 -81
  105. package/skills/cloudflare/references/pages/api.md +10 -201
  106. package/skills/cloudflare/references/pages/configuration.md +16 -201
  107. package/skills/cloudflare/references/pages/gotchas.md +13 -197
  108. package/skills/cloudflare/references/pages/patterns.md +11 -200
  109. package/skills/cloudflare/references/pages-functions/README.md +13 -91
  110. package/skills/cloudflare/references/pages-functions/api.md +10 -140
  111. package/skills/cloudflare/references/pages-functions/configuration.md +11 -119
  112. package/skills/cloudflare/references/pages-functions/gotchas.md +17 -94
  113. package/skills/cloudflare/references/pages-functions/patterns.md +12 -133
  114. package/skills/cloudflare/references/pipelines/README.md +1 -1
  115. package/skills/cloudflare/references/pulumi/README.md +2 -2
  116. package/skills/cloudflare/references/queues/README.md +15 -87
  117. package/skills/cloudflare/references/queues/api.md +10 -200
  118. package/skills/cloudflare/references/queues/configuration.md +18 -142
  119. package/skills/cloudflare/references/queues/gotchas.md +16 -204
  120. package/skills/cloudflare/references/queues/patterns.md +19 -218
  121. package/skills/cloudflare/references/r2/README.md +17 -86
  122. package/skills/cloudflare/references/r2/api.md +14 -198
  123. package/skills/cloudflare/references/r2/configuration.md +17 -163
  124. package/skills/cloudflare/references/r2/gotchas.md +15 -188
  125. package/skills/cloudflare/references/r2/patterns.md +16 -191
  126. package/skills/cloudflare/references/r2-data-catalog/README.md +11 -70
  127. package/skills/cloudflare/references/r2-data-catalog/api.md +14 -89
  128. package/skills/cloudflare/references/r2-data-catalog/configuration.md +15 -96
  129. package/skills/cloudflare/references/r2-data-catalog/gotchas.md +14 -51
  130. package/skills/cloudflare/references/r2-data-catalog/patterns.md +11 -116
  131. package/skills/cloudflare/references/realtime-sfu/README.md +1 -1
  132. package/skills/cloudflare/references/realtimekit/README.md +1 -1
  133. package/skills/cloudflare/references/secrets-store/README.md +14 -66
  134. package/skills/cloudflare/references/secrets-store/api.md +14 -193
  135. package/skills/cloudflare/references/secrets-store/configuration.md +16 -176
  136. package/skills/cloudflare/references/secrets-store/gotchas.md +14 -92
  137. package/skills/cloudflare/references/secrets-store/patterns.md +14 -194
  138. package/skills/cloudflare/references/smart-placement/README.md +2 -2
  139. package/skills/cloudflare/references/static-assets/README.md +15 -59
  140. package/skills/cloudflare/references/static-assets/api.md +12 -195
  141. package/skills/cloudflare/references/static-assets/configuration.md +16 -186
  142. package/skills/cloudflare/references/static-assets/gotchas.md +18 -162
  143. package/skills/cloudflare/references/static-assets/patterns.md +13 -185
  144. package/skills/cloudflare/references/stream/README.md +15 -107
  145. package/skills/cloudflare/references/stream/api-live.md +16 -193
  146. package/skills/cloudflare/references/stream/api.md +19 -197
  147. package/skills/cloudflare/references/stream/configuration.md +16 -139
  148. package/skills/cloudflare/references/stream/gotchas.md +16 -128
  149. package/skills/cloudflare/references/stream/patterns.md +20 -182
  150. package/skills/cloudflare/references/tail-workers/README.md +14 -82
  151. package/skills/cloudflare/references/tail-workers/api.md +10 -197
  152. package/skills/cloudflare/references/tail-workers/configuration.md +13 -174
  153. package/skills/cloudflare/references/tail-workers/gotchas.md +12 -188
  154. package/skills/cloudflare/references/tail-workers/patterns.md +11 -176
  155. package/skills/cloudflare/references/terraform/README.md +2 -2
  156. package/skills/cloudflare/references/tunnel/README.md +13 -122
  157. package/skills/cloudflare/references/tunnel/api.md +11 -190
  158. package/skills/cloudflare/references/tunnel/configuration.md +12 -155
  159. package/skills/cloudflare/references/tunnel/gotchas.md +12 -144
  160. package/skills/cloudflare/references/tunnel/networking.md +12 -166
  161. package/skills/cloudflare/references/tunnel/patterns.md +12 -189
  162. package/skills/cloudflare/references/vectorize/README.md +15 -126
  163. package/skills/cloudflare/references/vectorize/api.md +14 -84
  164. package/skills/cloudflare/references/vectorize/configuration.md +14 -83
  165. package/skills/cloudflare/references/vectorize/gotchas.md +12 -73
  166. package/skills/cloudflare/references/vectorize/patterns.md +17 -83
  167. package/skills/cloudflare/references/waf/README.md +15 -107
  168. package/skills/cloudflare/references/waf/api.md +17 -202
  169. package/skills/cloudflare/references/waf/configuration.md +14 -199
  170. package/skills/cloudflare/references/waf/gotchas.md +15 -200
  171. package/skills/cloudflare/references/waf/patterns.md +13 -193
  172. package/skills/cloudflare/references/workerd/README.md +2 -2
  173. package/skills/cloudflare/references/workers-ai/README.md +14 -187
  174. package/skills/cloudflare/references/workers-ai/api.md +10 -109
  175. package/skills/cloudflare/references/workers-ai/configuration.md +11 -92
  176. package/skills/cloudflare/references/workers-ai/gotchas.md +12 -111
  177. package/skills/cloudflare/references/workers-ai/patterns.md +9 -115
  178. package/skills/cloudflare/references/workers-for-platforms/README.md +3 -3
  179. package/skills/cloudflare/references/workers-vpc/README.md +1 -1
  180. package/skills/cloudflare/references/workflows/README.md +15 -69
  181. package/skills/cloudflare/references/workflows/api.md +12 -213
  182. package/skills/cloudflare/references/workflows/configuration.md +16 -150
  183. package/skills/cloudflare/references/workflows/gotchas.md +17 -88
  184. package/skills/cloudflare/references/workflows/patterns.md +19 -164
  185. package/skills/cloudflare-api-token/SKILL.md +1 -1
  186. package/skills/cloudflare-cf-cli/SKILL.md +44 -13
  187. package/skills/cloudflare-email-service/SKILL.md +6 -36
  188. package/skills/cloudflare-email-service/references/rest-api.md +12 -179
  189. package/skills/cloudflare-email-service/references/sending.md +17 -250
  190. package/skills/cloudflare-one/SKILL.md +4 -2
  191. package/skills/cloudflare-one-migrations/SKILL.md +1 -1
  192. package/skills/cloudflare-token-roll/SKILL.md +2 -5
  193. package/skills/durable-objects/SKILL.md +10 -16
  194. package/skills/durable-objects/references/rules.md +17 -293
  195. package/skills/durable-objects/references/testing.md +16 -257
  196. package/skills/nextjs-on-cloudflare/SKILL.md +33 -0
  197. package/skills/sandbox-migrate-to-next/SKILL.md +2 -2
  198. package/skills/sandbox-next/SKILL.md +3 -2
  199. package/skills/sandbox-next/references/api-quick-ref.md +15 -90
  200. package/skills/sandbox-stable/SKILL.md +1 -1
  201. package/skills/turnstile-spin/SKILL.md +14 -8
  202. package/skills/workers-best-practices/SKILL.md +36 -103
  203. package/skills/workers-best-practices/references/configuration.md +139 -0
  204. package/skills/workers-best-practices/references/platform-apis.md +51 -0
  205. package/skills/workers-best-practices/references/{rules.md → runtime-patterns.md} +9 -134
  206. package/skills/wrangler/SKILL.md +48 -901
  207. package/bin/setup.mjs +0 -119
  208. package/dist/api-token.d.ts +0 -12
  209. package/dist/api-token.d.ts.map +0 -1
  210. package/dist/api-token.js +0 -23
  211. package/dist/api-token.js.map +0 -1
  212. package/dist/auth-flow.d.ts +0 -15
  213. package/dist/auth-flow.d.ts.map +0 -1
  214. package/dist/auth-flow.js +0 -90
  215. package/dist/auth-flow.js.map +0 -1
  216. package/dist/client.d.ts +0 -18
  217. package/dist/client.d.ts.map +0 -1
  218. package/dist/client.js +0 -47
  219. package/dist/client.js.map +0 -1
  220. package/dist/config.d.ts +0 -20
  221. package/dist/config.d.ts.map +0 -1
  222. package/dist/config.js +0 -10
  223. package/dist/config.js.map +0 -1
  224. package/dist/index.d.ts +0 -22
  225. package/dist/index.d.ts.map +0 -1
  226. package/dist/index.js +0 -65
  227. package/dist/index.js.map +0 -1
  228. package/dist/mcp-server.d.ts +0 -2
  229. package/dist/mcp-server.d.ts.map +0 -1
  230. package/dist/mcp-server.js +0 -106
  231. package/dist/mcp-server.js.map +0 -1
  232. package/dist/oauth.d.ts +0 -44
  233. package/dist/oauth.d.ts.map +0 -1
  234. package/dist/oauth.js +0 -135
  235. package/dist/oauth.js.map +0 -1
  236. package/dist/proxy.d.ts +0 -30
  237. package/dist/proxy.d.ts.map +0 -1
  238. package/dist/proxy.js +0 -41
  239. package/dist/proxy.js.map +0 -1
  240. package/dist/result-caps.d.ts +0 -23
  241. package/dist/result-caps.d.ts.map +0 -1
  242. package/dist/result-caps.js +0 -75
  243. package/dist/result-caps.js.map +0 -1
  244. package/dist/runtime.d.ts +0 -72
  245. package/dist/runtime.d.ts.map +0 -1
  246. package/dist/runtime.js +0 -249
  247. package/dist/runtime.js.map +0 -1
  248. package/dist/servers.d.ts +0 -19
  249. package/dist/servers.d.ts.map +0 -1
  250. package/dist/servers.js +0 -40
  251. package/dist/servers.js.map +0 -1
  252. package/dist/token-store.d.ts +0 -32
  253. package/dist/token-store.d.ts.map +0 -1
  254. package/dist/token-store.js +0 -61
  255. package/dist/token-store.js.map +0 -1
  256. package/dist/tool-cache.d.ts +0 -25
  257. package/dist/tool-cache.d.ts.map +0 -1
  258. package/dist/tool-cache.js +0 -43
  259. package/dist/tool-cache.js.map +0 -1
  260. package/mcp.json +0 -15
  261. package/skills/cloudflare/references/agents-sdk/README.md +0 -89
  262. package/skills/cloudflare/references/agents-sdk/api.md +0 -190
  263. package/skills/cloudflare/references/agents-sdk/configuration.md +0 -182
  264. package/skills/cloudflare/references/agents-sdk/gotchas.md +0 -158
  265. package/skills/cloudflare/references/agents-sdk/patterns.md +0 -192
  266. package/skills/cloudflare/references/durable-objects/README.md +0 -185
  267. package/skills/cloudflare/references/durable-objects/api.md +0 -187
  268. package/skills/cloudflare/references/durable-objects/configuration.md +0 -160
  269. package/skills/cloudflare/references/durable-objects/gotchas.md +0 -197
  270. package/skills/cloudflare/references/durable-objects/patterns.md +0 -201
  271. package/skills/cloudflare/references/sandbox/README.md +0 -96
  272. package/skills/cloudflare/references/sandbox/api.md +0 -198
  273. package/skills/cloudflare/references/sandbox/configuration.md +0 -143
  274. package/skills/cloudflare/references/sandbox/gotchas.md +0 -194
  275. package/skills/cloudflare/references/sandbox/patterns.md +0 -201
  276. package/skills/cloudflare/references/turnstile/README.md +0 -99
  277. package/skills/cloudflare/references/turnstile/api.md +0 -240
  278. package/skills/cloudflare/references/turnstile/configuration.md +0 -222
  279. package/skills/cloudflare/references/turnstile/gotchas.md +0 -218
  280. package/skills/cloudflare/references/turnstile/patterns.md +0 -193
  281. package/skills/cloudflare/references/workers/README.md +0 -108
  282. package/skills/cloudflare/references/workers/api.md +0 -195
  283. package/skills/cloudflare/references/workers/configuration.md +0 -185
  284. package/skills/cloudflare/references/workers/frameworks.md +0 -197
  285. package/skills/cloudflare/references/workers/gotchas.md +0 -137
  286. package/skills/cloudflare/references/workers/patterns.md +0 -198
  287. package/skills/cloudflare/references/wrangler/README.md +0 -135
  288. package/skills/cloudflare/references/wrangler/api.md +0 -188
  289. package/skills/cloudflare/references/wrangler/configuration.md +0 -197
  290. package/skills/cloudflare/references/wrangler/gotchas.md +0 -197
  291. package/skills/cloudflare/references/wrangler/patterns.md +0 -209
  292. package/skills/cloudflare-auth-setup/SKILL.md +0 -59
  293. package/skills/workers-best-practices/references/review.md +0 -174
@@ -1,105 +1,14 @@
1
1
  # Observability Patterns
2
2
 
3
- ## Usage-Based Billing
4
-
5
- ```typescript
6
- env.ANALYTICS.writeDataPoint({
7
- blobs: [customerId, request.url, request.method],
8
- doubles: [1], // request_count
9
- indexes: [customerId]
10
- });
11
- ```
12
-
13
- ```sql
14
- SELECT blob1 AS customer_id, SUM(_sample_interval * double1) AS total_calls
15
- FROM api_usage WHERE timestamp >= DATE_TRUNC('month', NOW())
16
- GROUP BY customer_id
17
- ```
18
-
19
- ## Performance Monitoring
20
-
21
- ```typescript
22
- const start = Date.now();
23
- const response = await fetch(url);
24
- env.ANALYTICS.writeDataPoint({
25
- blobs: [url, response.status.toString()],
26
- doubles: [Date.now() - start, response.status]
27
- });
28
- ```
29
-
30
- ```sql
31
- SELECT blob1 AS url, AVG(double1) AS avg_ms, percentile(double1, 0.95) AS p95_ms
32
- FROM fetch_metrics WHERE timestamp >= NOW() - INTERVAL '1' HOUR
33
- GROUP BY url
34
- ```
35
-
36
- ## Error Tracking
37
-
38
- ```typescript
39
- env.ANALYTICS.writeDataPoint({
40
- blobs: [error.name, request.url, request.method],
41
- doubles: [1],
42
- indexes: [error.name]
43
- });
44
- ```
45
-
46
- ## Multi-Tenant Tracking
47
-
48
- ```typescript
49
- env.ANALYTICS.writeDataPoint({
50
- indexes: [tenantId], // efficient filtering
51
- blobs: [tenantId, url.pathname, method, status],
52
- doubles: [1, duration, bytesSize]
53
- });
54
- ```
55
-
56
- ## Tail Worker Log Filtering
57
-
58
- ```typescript
59
- export default {
60
- async tail(events, env, ctx) {
61
- const critical = events.filter(e =>
62
- e.exceptions.length > 0 || e.event.wallTime > 1000000
63
- );
64
- if (critical.length === 0) return;
65
-
66
- ctx.waitUntil(
67
- fetch('https://logging.example.com/ingest', {
68
- method: 'POST',
69
- headers: { 'Authorization': `Bearer ${env.API_KEY}` },
70
- body: JSON.stringify(critical.map(e => ({
71
- outcome: e.event.outcome,
72
- cpu_ms: e.event.cpuTime / 1000,
73
- errors: e.exceptions
74
- })))
75
- })
76
- );
77
- }
78
- };
79
- ```
80
-
81
- ## OpenTelemetry Export
82
-
83
- ```typescript
84
- export default {
85
- async tail(events, env, ctx) {
86
- const otelSpans = events.map(e => ({
87
- traceId: generateId(32),
88
- spanId: generateId(16),
89
- name: e.scriptName || 'worker.request',
90
- attributes: [
91
- { key: 'worker.outcome', value: { stringValue: e.event.outcome } },
92
- { key: 'worker.cpu_time_us', value: { intValue: String(e.event.cpuTime) } }
93
- ]
94
- }));
95
-
96
- ctx.waitUntil(
97
- fetch('https://api.honeycomb.io/v1/traces', {
98
- method: 'POST',
99
- headers: { 'X-Honeycomb-Team': env.HONEYCOMB_KEY },
100
- body: JSON.stringify({ resourceSpans: [{ scopeSpans: [{ spans: otelSpans }] }] })
101
- })
102
- );
103
- }
104
- };
105
- ```
3
+ Use these decisions alongside the linked implementation guides. Application event schemas, billing policies, alert thresholds, and delivery behavior still need to be designed for the application.
4
+
5
+ | Task | Design decision and documentation |
6
+ | --- | --- |
7
+ | Usage-based billing | Define the billable event, tenant identity, time window, and accuracy requirements. Start with the maintained [Analytics Engine billing recipe](https://developers.cloudflare.com/analytics/analytics-engine/recipes/usage-based-billing-for-your-saas-product/) and [sampling guidance](https://developers.cloudflare.com/analytics/analytics-engine/sampling/); assess whether sampled estimates satisfy the billing contract. |
8
+ | Performance monitoring | Use [built-in metrics](https://developers.cloudflare.com/workers/observability/metrics-and-analytics/) for aggregate health and [traces](https://developers.cloudflare.com/workers/observability/traces/) to investigate dependency latency. Custom measurements need consistent units and aggregation semantics; check [runtime timers](https://developers.cloudflare.com/workers/runtime-apis/performance/) before measuring CPU-only work. |
9
+ | Error tracking | Emit structured context without secrets, investigate with [Query Builder](https://developers.cloudflare.com/workers/observability/query-builder/), and choose [Tail Workers](https://developers.cloudflare.com/workers/observability/logs/tail-workers/) if custom alert processing is needed. Define thresholds and duplicate handling for your alert destination. |
10
+ | Multi-tenant tracking | Choose the tenant dimension and consistent field positions using [Analytics Engine get started](https://developers.cloudflare.com/analytics/analytics-engine/get-started/) and [sampling guidance](https://developers.cloudflare.com/analytics/analytics-engine/sampling/). Enforce tenant authorization in the application that exposes analytics; a dataset index is not an access-control boundary. |
11
+ | Tail Worker filtering | Use the current [Tail handler schema](https://developers.cloudflare.com/workers/runtime-apis/handlers/tail/) for outcomes, exceptions, and timing fields, with [Tail configuration](https://developers.cloudflare.com/workers/observability/logs/tail-workers/) for producer wiring. Define filtering, redaction, and downstream failure handling for the destination. |
12
+ | OpenTelemetry export | Prefer the maintained [OTLP export integration](https://developers.cloudflare.com/workers/observability/exporting-opentelemetry-data/) for supported destinations. For Honeycomb, follow [Export to Honeycomb](https://developers.cloudflare.com/workers/observability/exporting-opentelemetry-data/honeycomb/) instead of synthesizing spans from Tail events. |
13
+
14
+ Use [Workers Logpush](https://developers.cloudflare.com/workers/observability/logs/logpush/) when the requirement is Workers Trace Event delivery to a supported log destination. Use a Tail Worker when custom processing is required beyond the configured export integration.
@@ -1,88 +1,20 @@
1
1
  # Cloudflare Pages
2
2
 
3
- JAMstack platform for full-stack apps on Cloudflare's global network.
3
+ Use this reference when maintaining an existing Pages project. For new applications, start with Workers as recommended in the [Pages framework guidance](https://developers.cloudflare.com/pages/framework-guides/). Fetch current documentation before implementing.
4
4
 
5
- ## Key Features
6
-
7
- - **Git-based deploys**: Auto-deploy from GitHub/GitLab
8
- - **Preview deployments**: Unique URL per branch/PR
9
- - **Pages Functions**: File-based serverless routing (Workers runtime)
10
- - **Static + dynamic**: Smart asset caching + edge compute
11
- - **Smart Placement**: Automatic function optimization based on traffic patterns
12
- - **Framework optimized**: SvelteKit, Astro, Nuxt, Qwik, Solid Start
13
-
14
- ## Deployment Methods
15
-
16
- ### 1. Git Integration (Production)
17
- Dashboard → Workers & Pages → Create → Connect to Git → Configure build
18
-
19
- ### 2. Direct Upload
20
- ```bash
21
- npx wrangler pages deploy ./dist --project-name=my-project
22
- npx wrangler pages deploy ./dist --project-name=my-project --branch=staging
23
- ```
24
-
25
- ### 3. C3 CLI
26
- ```bash
27
- npm create cloudflare@latest my-app
28
- # Select framework → auto-setup + deploy
29
- ```
30
-
31
- ## vs Workers
32
-
33
- - **Pages**: Static sites, JAMstack, frameworks, git workflow, file-based routing
34
- - **Workers**: Pure APIs, complex routing, WebSockets, scheduled tasks, email handlers
35
- - **Combine**: Pages Functions use Workers runtime, can bind to Workers
36
-
37
- ## Quick Start
38
-
39
- ```bash
40
- # Create
41
- npm create cloudflare@latest
42
-
43
- # Local dev
44
- npx wrangler pages dev ./dist
45
-
46
- # Deploy
47
- npx wrangler pages deploy ./dist --project-name=my-project
48
-
49
- # Types
50
- npx wrangler types --path='./functions/types.d.ts'
51
-
52
- # Secrets
53
- echo "value" | npx wrangler pages secret put KEY --project-name=my-project
54
-
55
- # Logs
56
- npx wrangler pages deployment tail --project-name=my-project
57
- ```
58
-
59
- ## Resources
60
-
61
- - [Pages Docs](https://developers.cloudflare.com/pages/)
62
- - [Functions API](https://developers.cloudflare.com/pages/functions/api-reference/)
63
- - [Framework Guides](https://developers.cloudflare.com/pages/framework-guides/)
64
- - [Discord #functions](https://discord.com/channels/595317990191398933/910978223968518144)
65
-
66
- ## Reading Order
67
-
68
- **New to Pages?** Start here:
69
- 1. README.md (you are here) - Overview & quick start
70
- 2. [configuration.md](./configuration.md) - Project setup, wrangler.jsonc, bindings
71
- 3. [api.md](./api.md) - Functions API, routing, context
72
- 4. [patterns.md](./patterns.md) - Common implementations
73
- 5. [gotchas.md](./gotchas.md) - Troubleshooting & pitfalls
74
-
75
- **Quick reference?** Jump to relevant file above.
5
+ | Task | Documentation |
6
+ | --- | --- |
7
+ | Configure the existing build | [Build configuration](https://developers.cloudflare.com/pages/configuration/build-configuration/) |
8
+ | Manage automatic deployments from a repository | [Git integration](https://developers.cloudflare.com/pages/configuration/git-integration/) |
9
+ | Deploy prebuilt output | [Direct Upload](https://developers.cloudflare.com/pages/get-started/direct-upload/) |
10
+ | Implement server-side requests | [Functions API reference](https://developers.cloudflare.com/pages/functions/api-reference/) |
11
+ | Plan a move to Workers | [Migrate from Pages to Workers](https://developers.cloudflare.com/workers/static-assets/migration-guides/migrate-from-pages/) |
76
12
 
77
13
  ## In This Reference
78
14
 
79
- - [configuration.md](./configuration.md) - wrangler.jsonc, build, env vars, Smart Placement
80
- - [api.md](./api.md) - Functions API, bindings, context, advanced mode
81
- - [patterns.md](./patterns.md) - Full-stack patterns, framework integration
82
- - [gotchas.md](./gotchas.md) - Build issues, limits, debugging, framework warnings
83
-
84
- ## See Also
15
+ - [configuration.md](./configuration.md) — build output, environments, and static rules
16
+ - [api.md](./api.md) — request handling and framework integration
17
+ - [patterns.md](./patterns.md) — project decisions and migration
18
+ - [gotchas.md](./gotchas.md) — build, routing, and deployment investigation
85
19
 
86
- - [pages-functions](../pages-functions/) - File-based routing, middleware
87
- - [d1](../d1/) - SQL database for Pages Functions
88
- - [kv](../kv/) - Key-value storage for caching/state
20
+ See [Pages Functions](../pages-functions/README.md) for handler-focused navigation. Identify the existing deployment method and framework before proposing changes.
@@ -1,204 +1,13 @@
1
- # Functions API
1
+ # Pages Request Handling
2
2
 
3
- ## File-Based Routing
3
+ Use the current Pages API and the project framework guide rather than translating a generic Worker example into Pages.
4
4
 
5
- ```
6
- /functions/index.ts → example.com/
7
- /functions/api/users.ts → example.com/api/users
8
- /functions/api/users/[id].ts → example.com/api/users/:id
9
- /functions/api/users/[[path]].ts → example.com/api/users/* (catchall)
10
- /functions/_middleware.ts → Runs before all routes
11
- ```
5
+ | Task | Documentation |
6
+ | --- | --- |
7
+ | Implement handlers and use context or asset fallback | [Functions API reference](https://developers.cloudflare.com/pages/functions/api-reference/) |
8
+ | Resolve dynamic paths and invocation routes | [Routing](https://developers.cloudflare.com/pages/functions/routing/) |
9
+ | Apply shared request logic | [Middleware](https://developers.cloudflare.com/pages/functions/middleware/) |
10
+ | Understand framework-generated Worker output | [Advanced mode](https://developers.cloudflare.com/pages/functions/advanced-mode/) |
11
+ | Find the guide for the existing framework | [Framework guides](https://developers.cloudflare.com/pages/framework-guides/) |
12
12
 
13
- **Rules**: `[param]` = single segment, `[[param]]` = multi-segment catchall, more specific wins.
14
-
15
- ## Request Handlers
16
-
17
- ```typescript
18
- import type { PagesFunction } from '@cloudflare/workers-types';
19
-
20
- interface Env {
21
- DB: D1Database;
22
- KV: KVNamespace;
23
- }
24
-
25
- // All methods
26
- export const onRequest: PagesFunction<Env> = async (context) => {
27
- return new Response('All methods');
28
- };
29
-
30
- // Method-specific
31
- export const onRequestGet: PagesFunction<Env> = async (context) => {
32
- const { request, env, params, data } = context;
33
-
34
- const user = await env.DB.prepare(
35
- 'SELECT * FROM users WHERE id = ?'
36
- ).bind(params.id).first();
37
-
38
- return Response.json(user);
39
- };
40
-
41
- export const onRequestPost: PagesFunction<Env> = async (context) => {
42
- const body = await context.request.json();
43
- return Response.json({ success: true });
44
- };
45
-
46
- // Also: onRequestPut, onRequestPatch, onRequestDelete, onRequestHead, onRequestOptions
47
- ```
48
-
49
- ## Context Object
50
-
51
- ```typescript
52
- interface EventContext<Env, Params, Data> {
53
- request: Request; // HTTP request
54
- env: Env; // Bindings (KV, D1, R2, etc.)
55
- params: Params; // Route parameters
56
- data: Data; // Middleware-shared data
57
- waitUntil: (promise: Promise<any>) => void; // Background tasks
58
- next: () => Promise<Response>; // Next handler
59
- passThroughOnException: () => void; // Error fallback (not in advanced mode)
60
- }
61
- ```
62
-
63
- ## Dynamic Routes
64
-
65
- ```typescript
66
- // Single segment: functions/users/[id].ts
67
- export const onRequestGet: PagesFunction = async ({ params }) => {
68
- // /users/123 → params.id = "123"
69
- return Response.json({ userId: params.id });
70
- };
71
-
72
- // Multi-segment: functions/files/[[path]].ts
73
- export const onRequestGet: PagesFunction = async ({ params }) => {
74
- // /files/docs/api/v1.md → params.path = ["docs", "api", "v1.md"]
75
- const filePath = (params.path as string[]).join('/');
76
- return new Response(filePath);
77
- };
78
- ```
79
-
80
- ## Middleware
81
-
82
- ```typescript
83
- // functions/_middleware.ts
84
- // Single
85
- export const onRequest: PagesFunction = async (context) => {
86
- const response = await context.next();
87
- response.headers.set('X-Custom-Header', 'value');
88
- return response;
89
- };
90
-
91
- // Chained (runs in order)
92
- const errorHandler: PagesFunction = async (context) => {
93
- try {
94
- return await context.next();
95
- } catch (err) {
96
- return new Response(err.message, { status: 500 });
97
- }
98
- };
99
-
100
- const auth: PagesFunction = async (context) => {
101
- const token = context.request.headers.get('Authorization');
102
- if (!token) return new Response('Unauthorized', { status: 401 });
103
- context.data.userId = await verifyToken(token);
104
- return context.next();
105
- };
106
-
107
- export const onRequest = [errorHandler, auth];
108
- ```
109
-
110
- **Scope**: `functions/_middleware.ts` → all; `functions/api/_middleware.ts` → `/api/*` only
111
-
112
- ## Bindings Usage
113
-
114
- ```typescript
115
- export const onRequestGet: PagesFunction<Env> = async ({ env }) => {
116
- // KV
117
- const cached = await env.KV.get('key', 'json');
118
- await env.KV.put('key', JSON.stringify({data: 'value'}), {expirationTtl: 3600});
119
-
120
- // D1
121
- const result = await env.DB.prepare('SELECT * FROM users WHERE id = ?').bind(userId).first();
122
-
123
- // R2, Queue, AI - see respective reference docs
124
-
125
- return Response.json({success: true});
126
- };
127
- ```
128
-
129
- ## Advanced Mode
130
-
131
- Full Workers API, bypasses file-based routing:
132
-
133
- ```javascript
134
- // functions/_worker.js
135
- export default {
136
- async fetch(request, env, ctx) {
137
- const url = new URL(request.url);
138
-
139
- // Custom routing
140
- if (url.pathname.startsWith('/api/')) {
141
- return new Response('API response');
142
- }
143
-
144
- // REQUIRED: Serve static assets
145
- return env.ASSETS.fetch(request);
146
- }
147
- };
148
- ```
149
-
150
- **When to use**: WebSockets, complex routing, scheduled handlers, email handlers.
151
-
152
- ## Smart Placement
153
-
154
- Automatically optimizes function execution location based on traffic patterns.
155
-
156
- **Configuration** (in wrangler.jsonc):
157
- ```jsonc
158
- {
159
- "placement": {
160
- "mode": "smart" // Enables optimization (default: off)
161
- }
162
- }
163
- ```
164
-
165
- **How it works**: Analyzes traffic patterns over time and places functions closer to users or data sources (e.g., D1 databases). Requires no code changes.
166
-
167
- **Trade-offs**: Initial requests may see slightly higher latency during learning period (hours-days). Performance improves as system optimizes.
168
-
169
- **When to use**: Global apps with centralized databases or geographically concentrated traffic sources.
170
-
171
- ## getRequestContext (Framework SSR)
172
-
173
- Access bindings in framework code:
174
-
175
- ```typescript
176
- // SvelteKit
177
- import type { RequestEvent } from '@sveltejs/kit';
178
- export async function load({ platform }: RequestEvent) {
179
- const data = await platform.env.DB.prepare('SELECT * FROM users').all();
180
- return { users: data.results };
181
- }
182
-
183
- // Astro
184
- const { DB } = Astro.locals.runtime.env;
185
- const data = await DB.prepare('SELECT * FROM users').all();
186
-
187
- // Solid Start (server function)
188
- import { getRequestEvent } from 'solid-js/web';
189
- const event = getRequestEvent();
190
- const data = await event.locals.runtime.env.DB.prepare('SELECT * FROM users').all();
191
- ```
192
-
193
- **✅ Supported adapters** (2026):
194
- - **SvelteKit**: `@sveltejs/adapter-cloudflare`
195
- - **Astro**: Built-in Cloudflare adapter
196
- - **Nuxt**: Set `nitro.preset: 'cloudflare-pages'` in `nuxt.config.ts`
197
- - **Qwik**: Built-in Cloudflare adapter
198
- - **Solid Start**: `@solidjs/start-cloudflare-pages`
199
-
200
- **❌ Deprecated/Unsupported**:
201
- - **Next.js**: Official adapter (`@cloudflare/next-on-pages`) deprecated. Use Vercel or self-host on Workers.
202
- - **Remix**: Official adapter (`@remix-run/cloudflare-pages`) deprecated. Migrate to supported frameworks.
203
-
204
- See [gotchas.md](./gotchas.md#framework-specific) for migration guidance.
13
+ First identify whether routing comes from the Functions directory or generated advanced-mode output. See [Pages Functions APIs](../pages-functions/api.md) for focused handler tasks and [patterns.md](./patterns.md) for migration decisions.
@@ -1,201 +1,16 @@
1
- # Configuration
2
-
3
- ## wrangler.jsonc
4
-
5
- ```jsonc
6
- {
7
- "name": "my-pages-project",
8
- "pages_build_output_dir": "./dist",
9
- "compatibility_date": "2026-01-01", // Use current date for new projects
10
- "compatibility_flags": ["nodejs_compat"],
11
- "placement": {
12
- "mode": "smart" // Optional: Enable Smart Placement
13
- },
14
- "kv_namespaces": [{"binding": "KV", "id": "abcd1234..."}],
15
- "d1_databases": [{"binding": "DB", "database_id": "xxxx-xxxx", "database_name": "production-db"}],
16
- "r2_buckets": [{"binding": "BUCKET", "bucket_name": "my-bucket"}],
17
- "durable_objects": {"bindings": [{"name": "COUNTER", "class_name": "Counter", "script_name": "counter-worker"}]},
18
- "services": [{"binding": "API", "service": "api-worker"}],
19
- "queues": {"producers": [{"binding": "QUEUE", "queue": "my-queue"}]},
20
- "vectorize": [{"binding": "VECTORIZE", "index_name": "my-index"}],
21
- "ai": {"binding": "AI"},
22
- "analytics_engine_datasets": [{"binding": "ANALYTICS"}],
23
- "vars": {"API_URL": "https://api.example.com", "ENVIRONMENT": "production"},
24
- "env": {
25
- "preview": {
26
- "vars": {"API_URL": "https://staging-api.example.com"},
27
- "kv_namespaces": [{"binding": "KV", "id": "preview-namespace-id"}]
28
- }
29
- }
30
- }
31
- ```
32
-
33
- ## Build Config
34
-
35
- **Git deployment**: Dashboard → Project → Settings → Build settings
36
- Set build command, output dir, env vars. Framework auto-detection configures automatically.
37
-
38
- ## Environment Variables
39
-
40
- ### Local (.dev.vars)
41
- ```bash
42
- # .dev.vars (never commit)
43
- SECRET_KEY="local-secret-key"
44
- API_TOKEN="dev-token-123"
45
- ```
46
-
47
- ### Production
48
- ```bash
49
- echo "secret-value" | npx wrangler pages secret put SECRET_KEY --project-name=my-project
50
- npx wrangler pages secret list --project-name=my-project
51
- npx wrangler pages secret delete SECRET_KEY --project-name=my-project
52
- ```
53
-
54
- Access: `env.SECRET_KEY`
55
-
56
- ## Static Config Files
57
-
58
- ### _redirects
59
- Place in build output (e.g., `dist/_redirects`):
60
-
61
- ```txt
62
- /old-page /new-page 301 # 301 redirect
63
- /blog/* /news/:splat 301 # Splat wildcard
64
- /users/:id /members/:id 301 # Placeholders
65
- /api/* /api-v2/:splat 200 # Proxy (no redirect)
66
- ```
67
-
68
- **Limits**: 2,100 total (2,000 static + 100 dynamic), 1,000 char/line
69
- **Note**: Functions take precedence
70
-
71
- ### _headers
72
- ```txt
73
- /secure/*
74
- X-Frame-Options: DENY
75
- X-Content-Type-Options: nosniff
76
-
77
- /api/*
78
- Access-Control-Allow-Origin: *
79
-
80
- /static/*
81
- Cache-Control: public, max-age=31536000, immutable
82
- ```
83
-
84
- **Limits**: 100 rules, 2,000 char/line
85
- **Note**: Only static assets; Functions set headers in Response
86
-
87
- ### _routes.json
88
- Controls which requests invoke Functions (auto-generated for most frameworks):
89
-
90
- ```json
91
- {
92
- "version": 1,
93
- "include": ["/*"],
94
- "exclude": ["/build/*", "/static/*", "/assets/*", "/*.{ico,png,jpg,css,js}"]
95
- }
96
- ```
97
-
98
- **Purpose**: Functions are metered; static requests are free. `exclude` takes precedence. Max 100 rules, 100 char/rule.
99
-
100
- ## TypeScript
101
-
102
- ```bash
103
- npx wrangler types --path='./functions/types.d.ts'
104
- ```
105
-
106
- Point `types` in `functions/tsconfig.json` to generated file.
107
-
108
- ## Smart Placement
109
-
110
- Automatically optimizes function execution location based on request patterns.
111
-
112
- ```jsonc
113
- {
114
- "placement": {
115
- "mode": "smart" // Enable optimization (default: off)
116
- }
117
- }
118
- ```
119
-
120
- **How it works**: System analyzes traffic over hours/days and places function execution closer to:
121
- - User clusters (e.g., regional traffic)
122
- - Data sources (e.g., D1 database primary location)
123
-
124
- **Benefits**:
125
- - Lower latency for read-heavy apps with centralized databases
126
- - Better performance for apps with regional traffic patterns
127
-
128
- **Trade-offs**:
129
- - Initial learning period: First requests may be slower while system optimizes
130
- - Optimization time: Performance improves over 24-48 hours
131
-
132
- **When to enable**: Global apps with D1/Durable Objects in specific regions, or apps with concentrated geographic traffic.
133
-
134
- **When to skip**: Evenly distributed global traffic with no data locality constraints.
135
-
136
- ## Remote Bindings (Local Dev)
137
-
138
- Connect local dev server to production bindings instead of local mocks:
139
-
140
- ```bash
141
- # All bindings remote
142
- npx wrangler pages dev ./dist --remote
143
-
144
- # Specific bindings remote (others local)
145
- npx wrangler pages dev ./dist --remote --kv=KV --d1=DB
146
- ```
147
-
148
- **Use cases**:
149
- - Test against production data (read-only operations)
150
- - Debug binding-specific behavior
151
- - Validate changes before deployment
152
-
153
- **⚠️ Warning**:
154
- - Writes affect **real production data**
155
- - Use only for read-heavy debugging or with non-production accounts
156
- - Consider creating separate preview environments instead
157
-
158
- **Requirements**: Must be logged in (`npx wrangler login`) with access to bindings.
159
-
160
- ## Local Dev
161
-
162
- ```bash
163
- # Basic
164
- npx wrangler pages dev ./dist
165
-
166
- # With bindings
167
- npx wrangler pages dev ./dist --kv KV --d1 DB=local-db-id
168
-
169
- # Remote bindings (production data)
170
- npx wrangler pages dev ./dist --remote
171
-
172
- # Persistence
173
- npx wrangler pages dev ./dist --persist-to=./.wrangler/state/v3
174
-
175
- # Proxy mode (SSR frameworks)
176
- npx wrangler pages dev -- npm run dev
177
- ```
178
-
179
- ## Limits (as of Jan 2026)
180
-
181
- | Resource | Free | Paid |
182
- |----------|------|------|
183
- | **Functions Requests** | 100k/day | Unlimited (metered) |
184
- | **Function CPU Time** | 10ms/req | 30s default, 5min max (Workers Paid) |
185
- | **Function Memory** | 128MB | 128MB |
186
- | **Script Size** | 1MB compressed | 10MB compressed |
187
- | **Deployments** | 500/month | 5,000/month |
188
- | **Files per Deploy** | 20,000 | 20,000 |
189
- | **File Size** | 25MB | 25MB |
190
- | **Build Time** | 20min | 20min |
191
- | **Redirects** | 2,100 (2k static + 100 dynamic) | Same |
192
- | **Header Rules** | 100 | 100 |
193
- | **Route Rules** | 100 | 100 |
194
- | **Subrequests** | 50/request | 10,000/request (Workers Paid) |
195
-
196
- **Notes**:
197
- - Functions use Workers runtime; Workers Paid plan increases limits
198
- - Free plan sufficient for most projects
199
- - Static requests always free (not counted toward limits)
200
-
201
- [Full limits](https://developers.cloudflare.com/pages/platform/limits/)
1
+ # Pages Configuration
2
+
3
+ Inspect the existing project configuration and build output before changing deployment settings.
4
+
5
+ | Task | Documentation |
6
+ | --- | --- |
7
+ | Set build commands, root/output directories, and build variables | [Build configuration](https://developers.cloudflare.com/pages/configuration/build-configuration/) |
8
+ | Manage Wrangler configuration, environments, and dashboard migration | [Functions configuration](https://developers.cloudflare.com/pages/functions/wrangler-configuration/) |
9
+ | Configure resource bindings, variables, and secrets | [Bindings](https://developers.cloudflare.com/pages/functions/bindings/) |
10
+ | Set static response headers | [Headers](https://developers.cloudflare.com/pages/configuration/headers/) |
11
+ | Configure static redirects and rewrites | [Redirects](https://developers.cloudflare.com/pages/configuration/redirects/) |
12
+ | Choose which requests invoke Functions | [Routing](https://developers.cloudflare.com/pages/functions/routing/) |
13
+ | Configure monorepo project boundaries | [Monorepos](https://developers.cloudflare.com/pages/configuration/monorepos/) |
14
+ | Run the project locally | [Local development](https://developers.cloudflare.com/pages/functions/local-development/) |
15
+
16
+ Distinguish build-time variables from runtime bindings, and check preview and production separately. Determine whether the framework owns generated routing files before editing them. See [Pages Functions configuration](../pages-functions/configuration.md) for types and placement.