@jimhoyd/urlcode 0.3.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 (254) hide show
  1. package/CONTRIBUTING.md +80 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +20 -0
  4. package/README.md +342 -0
  5. package/ROADMAP.md +248 -0
  6. package/SECURITY.md +40 -0
  7. package/data/agents/LICENSES/ai-robots-txt.txt +24 -0
  8. package/data/agents/LICENSES/crawler-user-agents.txt +23 -0
  9. package/data/agents/ai-crawlers.json +1240 -0
  10. package/data/agents/crawlers.json +10515 -0
  11. package/data/agents/index.d.ts +3 -0
  12. package/data/agents/index.js +2453 -0
  13. package/data/agents/monitoring.json +1520 -0
  14. package/data/agents/seo.json +3865 -0
  15. package/dist/BUILD-MANIFEST.json +60 -0
  16. package/dist/adapters.js +59 -0
  17. package/dist/agent-lists.js +59 -0
  18. package/dist/assets.js +129 -0
  19. package/dist/authoring.js +68 -0
  20. package/dist/aws.js +110 -0
  21. package/dist/build-cloudflare.js +164 -0
  22. package/dist/cli.js +185 -0
  23. package/dist/client-address.js +85 -0
  24. package/dist/cloudflare.js +165 -0
  25. package/dist/compliance-rules/baseline.js +98 -0
  26. package/dist/compliance-rules/privacy.js +38 -0
  27. package/dist/compliance-rules/shared.js +62 -0
  28. package/dist/compliance-rules/strict.js +61 -0
  29. package/dist/compliance.js +219 -0
  30. package/dist/config-worker.js +9 -0
  31. package/dist/config.js +172 -0
  32. package/dist/errors.js +8 -0
  33. package/dist/function-sources.js +54 -0
  34. package/dist/function-worker.js +105 -0
  35. package/dist/functions.js +174 -0
  36. package/dist/guest-api.js +114 -0
  37. package/dist/header-validation.js +18 -0
  38. package/dist/http-policy.js +74 -0
  39. package/dist/http-response.js +84 -0
  40. package/dist/index.js +11 -0
  41. package/dist/link-api.js +136 -0
  42. package/dist/link-cli.js +141 -0
  43. package/dist/link-events.js +76 -0
  44. package/dist/link-records.js +31 -0
  45. package/dist/link-store-worker.js +150 -0
  46. package/dist/link-store.js +250 -0
  47. package/dist/logging.js +22 -0
  48. package/dist/management-policy.js +41 -0
  49. package/dist/match.js +124 -0
  50. package/dist/observability.js +242 -0
  51. package/dist/plugins.js +74 -0
  52. package/dist/policies/agents.js +248 -0
  53. package/dist/policies/cache.js +297 -0
  54. package/dist/policies/compression.js +187 -0
  55. package/dist/policies/security.js +0 -0
  56. package/dist/policies/throttle.js +131 -0
  57. package/dist/policies.js +142 -0
  58. package/dist/policy.js +55 -0
  59. package/dist/prerender.js +165 -0
  60. package/dist/project-tests.js +23 -0
  61. package/dist/readiness.js +216 -0
  62. package/dist/router.js +166 -0
  63. package/dist/runtime.js +244 -0
  64. package/dist/scaffold.js +0 -0
  65. package/dist/scripts/operational-drills.js +75 -0
  66. package/dist/server.js +270 -0
  67. package/dist/site.js +0 -0
  68. package/dist/sqlite-version.js +6 -0
  69. package/dist/types/adapters.d.ts +12 -0
  70. package/dist/types/agent-lists.d.ts +5 -0
  71. package/dist/types/assets.d.ts +13 -0
  72. package/dist/types/authoring.d.ts +2 -0
  73. package/dist/types/aws.d.ts +35 -0
  74. package/dist/types/build-cloudflare.d.ts +14 -0
  75. package/dist/types/cli.d.ts +2 -0
  76. package/dist/types/client-address.d.ts +9 -0
  77. package/dist/types/cloudflare.d.ts +75 -0
  78. package/dist/types/compliance-rules/baseline.d.ts +12 -0
  79. package/dist/types/compliance-rules/privacy.d.ts +6 -0
  80. package/dist/types/compliance-rules/shared.d.ts +24 -0
  81. package/dist/types/compliance-rules/strict.d.ts +9 -0
  82. package/dist/types/compliance.d.ts +119 -0
  83. package/dist/types/config-worker.d.ts +1 -0
  84. package/dist/types/config.d.ts +21 -0
  85. package/dist/types/errors.d.ts +7 -0
  86. package/dist/types/function-sources.d.ts +21 -0
  87. package/dist/types/function-worker.d.ts +1 -0
  88. package/dist/types/functions.d.ts +92 -0
  89. package/dist/types/guest-api.d.ts +16 -0
  90. package/dist/types/header-validation.d.ts +2 -0
  91. package/dist/types/http-policy.d.ts +39 -0
  92. package/dist/types/http-response.d.ts +43 -0
  93. package/dist/types/index.d.ts +11 -0
  94. package/dist/types/link-api.d.ts +30 -0
  95. package/dist/types/link-cli.d.ts +36 -0
  96. package/dist/types/link-events.d.ts +27 -0
  97. package/dist/types/link-records.d.ts +11 -0
  98. package/dist/types/link-store-worker.d.ts +1 -0
  99. package/dist/types/link-store.d.ts +130 -0
  100. package/dist/types/logging.d.ts +9 -0
  101. package/dist/types/management-policy.d.ts +9 -0
  102. package/dist/types/match.d.ts +81 -0
  103. package/dist/types/observability.d.ts +104 -0
  104. package/dist/types/plugins.d.ts +27 -0
  105. package/dist/types/policies/agents.d.ts +86 -0
  106. package/dist/types/policies/cache.d.ts +82 -0
  107. package/dist/types/policies/compression.d.ts +41 -0
  108. package/dist/types/policies/security.d.ts +37 -0
  109. package/dist/types/policies/throttle.d.ts +55 -0
  110. package/dist/types/policies.d.ts +36 -0
  111. package/dist/types/policy.d.ts +21 -0
  112. package/dist/types/prerender.d.ts +31 -0
  113. package/dist/types/project-tests.d.ts +13 -0
  114. package/dist/types/readiness.d.ts +121 -0
  115. package/dist/types/router.d.ts +11 -0
  116. package/dist/types/runtime.d.ts +91 -0
  117. package/dist/types/scaffold.d.ts +17 -0
  118. package/dist/types/server.d.ts +37 -0
  119. package/dist/types/site.d.ts +12 -0
  120. package/dist/types/sqlite-version.d.ts +1 -0
  121. package/dist/types/types.d.ts +332 -0
  122. package/dist/types/vercel.d.ts +12 -0
  123. package/dist/types.js +177 -0
  124. package/dist/vercel.js +65 -0
  125. package/docs/AI-AUTHORING.md +113 -0
  126. package/docs/ASSETS.md +106 -0
  127. package/docs/AWS.md +77 -0
  128. package/docs/BEST-PRACTICES.md +267 -0
  129. package/docs/CAPACITY.md +208 -0
  130. package/docs/CLOUDFLARE.md +110 -0
  131. package/docs/COMPLIANCE.md +242 -0
  132. package/docs/DYNAMIC-LINKS.md +561 -0
  133. package/docs/FUNCTION-SECURITY.md +113 -0
  134. package/docs/HTTP.md +129 -0
  135. package/docs/INSTALL.md +90 -0
  136. package/docs/LOAD-TESTING.md +91 -0
  137. package/docs/LOCAL-DEVELOPMENT.md +99 -0
  138. package/docs/MANAGEMENT-SECURITY.md +82 -0
  139. package/docs/MIDDLEWARE.md +83 -0
  140. package/docs/MONITORING.md +132 -0
  141. package/docs/OBSERVABILITY.md +229 -0
  142. package/docs/OPERATIONAL-PROOF.md +42 -0
  143. package/docs/OPERATIONS.md +207 -0
  144. package/docs/ORGANIZATION.md +135 -0
  145. package/docs/PERFORMANCE.md +72 -0
  146. package/docs/PLUGINS.md +234 -0
  147. package/docs/POLICIES.md +489 -0
  148. package/docs/PRERENDER.md +193 -0
  149. package/docs/PROJECT-DIRECTION.md +51 -0
  150. package/docs/READINESS.md +125 -0
  151. package/docs/README.md +58 -0
  152. package/docs/RELEASE-READINESS.md +95 -0
  153. package/docs/RELEASE-SECURITY.md +72 -0
  154. package/docs/RESILIENCE.md +160 -0
  155. package/docs/ROUTING.md +95 -0
  156. package/docs/SANDBOX-REVIEW.md +59 -0
  157. package/docs/SCAFFOLDING.md +72 -0
  158. package/docs/SECURITY-AUDIT.md +124 -0
  159. package/docs/SITE.md +150 -0
  160. package/docs/SPECIFICATION.md +232 -0
  161. package/docs/SPIKE-EXTENSIONS.md +475 -0
  162. package/docs/STANDARDS.md +303 -0
  163. package/docs/STARTERS.md +51 -0
  164. package/docs/TUNNELS.md +75 -0
  165. package/docs/TYPESCRIPT.md +102 -0
  166. package/docs/VERCEL.md +107 -0
  167. package/docs/YAML-GUIDE.md +521 -0
  168. package/docs/YAML-REFERENCE.md +328 -0
  169. package/docs/policies/agents.md +182 -0
  170. package/docs/policies/cache.md +139 -0
  171. package/docs/policies/compression.md +168 -0
  172. package/docs/policies/security.md +160 -0
  173. package/docs/policies/throttle.md +103 -0
  174. package/examples/assets/.env.example +1 -0
  175. package/examples/assets/.gitattributes +2 -0
  176. package/examples/assets/Makefile +30 -0
  177. package/examples/assets/README.md +18 -0
  178. package/examples/assets/functions/hello.mjs +3 -0
  179. package/examples/assets/gitignore.template +7 -0
  180. package/examples/assets/public/about.html +2 -0
  181. package/examples/assets/public/assets/example.txt +1 -0
  182. package/examples/assets/public/guide.txt +1 -0
  183. package/examples/assets/tests/requests.json +44 -0
  184. package/examples/assets/urlcode.yaml +27 -0
  185. package/examples/aws/README.md +13 -0
  186. package/examples/aws/handler.mjs +5 -0
  187. package/examples/aws/public/index.html +3 -0
  188. package/examples/aws/public/notes.txt +1 -0
  189. package/examples/aws/template.yaml +33 -0
  190. package/examples/aws/tests/requests.json +9 -0
  191. package/examples/aws/urlcode.yaml +19 -0
  192. package/examples/cloudflare/README.md +18 -0
  193. package/examples/cloudflare/package.json +14 -0
  194. package/examples/cloudflare/tests/requests.json +9 -0
  195. package/examples/cloudflare/urlcode.yaml +24 -0
  196. package/examples/cloudflare/wrangler.toml +5 -0
  197. package/examples/compliance/README.md +20 -0
  198. package/examples/compliance/rules.mjs +65 -0
  199. package/examples/cookbook/README.md +21 -0
  200. package/examples/cookbook/functions/choice.mjs +4 -0
  201. package/examples/cookbook/functions/echo.mjs +3 -0
  202. package/examples/cookbook/functions/hello.mjs +3 -0
  203. package/examples/cookbook/functions/text.mjs +3 -0
  204. package/examples/cookbook/middleware/headers.mjs +6 -0
  205. package/examples/cookbook/public/about.html +1 -0
  206. package/examples/cookbook/public/assets/index.html +1 -0
  207. package/examples/cookbook/public/assets/site.css +1 -0
  208. package/examples/cookbook/public/favicon.svg +1 -0
  209. package/examples/cookbook/public/guide.txt +1 -0
  210. package/examples/cookbook/public/llms.txt +6 -0
  211. package/examples/cookbook/routes/code.yaml +55 -0
  212. package/examples/cookbook/routes/files.yaml +17 -0
  213. package/examples/cookbook/routes/policies.yaml +28 -0
  214. package/examples/cookbook/routes/redirects.yaml +38 -0
  215. package/examples/cookbook/routes/responses.yaml +26 -0
  216. package/examples/cookbook/tests/requests.json +254 -0
  217. package/examples/cookbook/urlcode.yaml +22 -0
  218. package/examples/live-links/README.md +11 -0
  219. package/examples/live-links/tests/requests.json +6 -0
  220. package/examples/live-links/urlcode.yaml +16 -0
  221. package/examples/monitoring/blackbox-jobs.yaml +37 -0
  222. package/examples/monitoring/prometheus-rules.yaml +88 -0
  223. package/examples/monitoring/prometheus-scrape.yaml +20 -0
  224. package/examples/monitoring/vector.toml +65 -0
  225. package/examples/prerender/README.md +48 -0
  226. package/examples/prerender/functions/page.mjs +6 -0
  227. package/examples/prerender/middleware/template.mjs +29 -0
  228. package/examples/prerender/prerender.d.mts +4 -0
  229. package/examples/prerender/prerender.mjs +63 -0
  230. package/examples/prerender/tests/requests.json +39 -0
  231. package/examples/prerender/urlcode.yaml +50 -0
  232. package/examples/tunnel/dev-with-ngrok.sh +61 -0
  233. package/examples/vercel/README.md +13 -0
  234. package/examples/vercel/api/index.js +5 -0
  235. package/examples/vercel/package.json +8 -0
  236. package/examples/vercel/public/index.html +3 -0
  237. package/examples/vercel/public/notes.txt +1 -0
  238. package/examples/vercel/tests/requests.json +48 -0
  239. package/examples/vercel/urlcode.yaml +19 -0
  240. package/examples/vercel/vercel.json +10 -0
  241. package/llms.txt +46 -0
  242. package/package.json +123 -0
  243. package/schemas/urlcode.schema.json +1230 -0
  244. package/starters/default/.gitattributes +1 -0
  245. package/starters/default/Makefile +30 -0
  246. package/starters/default/README.md +34 -0
  247. package/starters/default/functions/hello.mjs +3 -0
  248. package/starters/default/gitignore.template +8 -0
  249. package/starters/default/middleware/headers.mjs +6 -0
  250. package/starters/default/routes/functions.yaml +20 -0
  251. package/starters/default/routes/marketing/links.yaml +7 -0
  252. package/starters/default/starter.json +5 -0
  253. package/starters/default/tests/requests.json +56 -0
  254. package/starters/default/urlcode.yaml +8 -0
@@ -0,0 +1 @@
1
+ * text=auto eol=lf
@@ -0,0 +1,30 @@
1
+ .DEFAULT_GOAL := help
2
+
3
+ # Install the runtime separately, or override: URLCODE='node /path/to/urlcode/src/cli.js'
4
+ URLCODE ?= urlcode
5
+ HOST ?= 127.0.0.1
6
+ PORT ?= 3000
7
+
8
+ .PHONY: help dev serve validate test doctor
9
+ help:
10
+ @echo "make dev Run this app with reload and .env.local"
11
+ @echo "make validate Validate this app and its local bindings"
12
+ @echo "make test Run this app's HTTP assertions"
13
+ @echo "make serve Run a fixed snapshot, without local dotenv"
14
+ @echo "make doctor Show runtime/platform details"
15
+ @echo "Options: PORT=3001 HOST=127.0.0.1 URLCODE=urlcode"
16
+
17
+ dev:
18
+ $(URLCODE) dev --project . --host "$(HOST)" --port "$(PORT)"
19
+ serve:
20
+ $(URLCODE) serve --project . --host "$(HOST)" --port "$(PORT)"
21
+ validate:
22
+ $(URLCODE) validate --local --project .
23
+ test:
24
+ $(URLCODE) test --project .
25
+ doctor:
26
+ $(URLCODE) doctor
27
+
28
+ .PHONY: routes audit benchmark
29
+ routes audit benchmark:
30
+ $(URLCODE) $@ --project . $(ARGS)
@@ -0,0 +1,34 @@
1
+ # Your URLCode project
2
+
3
+ One starter: a URL that runs your function, and a regular redirect.
4
+ Created with `urlcode init ../my-links`. No template choice is needed.
5
+
6
+ ```sh
7
+ urlcode dev
8
+ # In another terminal:
9
+ urlcode test
10
+ urlcode audit --expect-routes 2
11
+ urlcode benchmark --requests 1000 --concurrency 2
12
+ ```
13
+
14
+ Visit http://127.0.0.1:3000/hello/Ada or http://127.0.0.1:3000/go.
15
+ `urlcode.yaml` loads `routes/functions.yaml` and `routes/marketing/links.yaml`.
16
+ Organize those files however you like; references are relative to the project root.
17
+ The function route uses `middleware/headers.mjs` to add a response header around
18
+ `await next()`. Edit or reuse it on other routes as needed.
19
+ GET/HEAD, redirect 302 and no-store defaults keep YAML short. Valid edits reload.
20
+
21
+ This app uses the runtime you installed separately (compatible with 0.1.0).
22
+ Without a global install, invoke `node /path/to/urlcode/src/cli.ts` instead of
23
+ `urlcode`. Optional Make shortcuts accept `URLCODE='node /path/to/urlcode/src/cli.ts'`.
24
+ For a cloneable project with a pinned npm runtime dependency, use
25
+ [urlcode-template](https://github.com/jimhoyd-com/urlcode-template). Both start
26
+ with the same two route examples. No runtime fork or provider account is needed.
27
+
28
+ Keep this app in your own Git repository. Secrets stay in ignored `.env.local`
29
+ or provider environment values, with external operator policy for function grants.
30
+ See [security](https://github.com/jimhoyd-com/urlcode/blob/main/docs/FUNCTION-SECURITY.md)
31
+ and [readiness](https://github.com/jimhoyd-com/urlcode/blob/main/docs/READINESS.md).
32
+ Add routes and assertions as your app grows; update the expected count deliberately.
33
+ URLCode is licensed under the Apache License 2.0. `gitignore.template` is initializer packaging
34
+ source and can be removed after `.gitignore` exists.
@@ -0,0 +1,3 @@
1
+ export default function hello(request, { args }) {
2
+ return Response.json({ message: `Hello, ${args.name}!` });
3
+ }
@@ -0,0 +1,8 @@
1
+ node_modules/
2
+ .env
3
+ .env.*
4
+ !.env.example
5
+ .urlcode/
6
+ .urlcode-edit-*/
7
+ urlcode.yaml.lock
8
+ .DS_Store
@@ -0,0 +1,6 @@
1
+ // Reusable logic around a route: run downstream, then add a response header.
2
+ export default async function headers(request, context, next) {
3
+ const response = await next();
4
+ response.headers.set('x-example-middleware', 'active');
5
+ return response;
6
+ }
@@ -0,0 +1,20 @@
1
+ # yaml-language-server: $schema=https://raw.githubusercontent.com/jimhoyd-com/urlcode/669632fb4f188f293a0f622847f87ee019c0627f/schemas/urlcode.schema.json
2
+ # File locations do not change route paths. GET/HEAD are the default methods.
3
+ version: "1"
4
+ routes:
5
+ # Your code runs when this URL is requested.
6
+ /hello/{name}:
7
+ parameters:
8
+ - name: name
9
+ in: path
10
+ required: true
11
+ schema: {type: string, minLength: 1, maxLength: 80}
12
+ middleware:
13
+ - source: middleware/headers.mjs
14
+ function:
15
+ source: functions/hello.mjs
16
+ args:
17
+ name: {from: path, name: name}
18
+ response:
19
+ headers:
20
+ X-Powered-By: URLCode
@@ -0,0 +1,7 @@
1
+ # yaml-language-server: $schema=https://raw.githubusercontent.com/jimhoyd-com/urlcode/669632fb4f188f293a0f622847f87ee019c0627f/schemas/urlcode.schema.json
2
+ version: "1"
3
+ routes:
4
+ # A regular redirect needs no custom code.
5
+ /go:
6
+ redirect:
7
+ url: https://example.com
@@ -0,0 +1,5 @@
1
+ {
2
+ "compatibleRuntime": "0.1.0",
3
+ "runtimeRepository": "https://github.com/jimhoyd-com/urlcode",
4
+ "templateRepository": "https://github.com/jimhoyd-com/urlcode-template"
5
+ }
@@ -0,0 +1,56 @@
1
+ [
2
+ {
3
+ "path": "/hello/Ada",
4
+ "status": 200,
5
+ "expectBody": "{\"message\":\"Hello, Ada!\"}",
6
+ "expectHeaders": {
7
+ "x-powered-by": "URLCode",
8
+ "cache-control": "no-store",
9
+ "x-example-middleware": "active"
10
+ }
11
+ },
12
+ {
13
+ "path": "/hello/Ada",
14
+ "method": "HEAD",
15
+ "status": 200,
16
+ "expectBody": "",
17
+ "expectHeaders": {
18
+ "x-example-middleware": "active"
19
+ }
20
+ },
21
+ {
22
+ "path": "/go",
23
+ "status": 302,
24
+ "expectHeaders": {
25
+ "location": "https://example.com/"
26
+ }
27
+ },
28
+ {
29
+ "path": "/go",
30
+ "method": "POST",
31
+ "status": 405,
32
+ "expectHeaders": {
33
+ "allow": "GET, HEAD"
34
+ }
35
+ },
36
+ {
37
+ "path": "/missing",
38
+ "status": 404
39
+ },
40
+ {
41
+ "path": "/hello/Ada",
42
+ "method": "POST",
43
+ "status": 405,
44
+ "expectHeaders": {
45
+ "allow": "GET, HEAD"
46
+ }
47
+ },
48
+ {
49
+ "path": "/hello/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
50
+ "status": 400
51
+ },
52
+ {
53
+ "path": "/hello/%ZZ",
54
+ "status": 400
55
+ }
56
+ ]
@@ -0,0 +1,8 @@
1
+ # yaml-language-server: $schema=https://raw.githubusercontent.com/jimhoyd-com/urlcode/669632fb4f188f293a0f622847f87ee019c0627f/schemas/urlcode.schema.json
2
+ # Organize files however you like; list their paths from this project root.
3
+ version: "1"
4
+ dynamicLinks: false
5
+ includes:
6
+ - routes/functions.yaml
7
+ - routes/marketing/links.yaml
8
+ routes: {}