acrylblends 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +22 -16
- package/dist/index.js +65 -20
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/plugins/acryl-inspect/LICENSE +21 -0
- package/plugins/acryl-inspect/plugin.json +12 -0
- package/plugins/acryl-inspect/src/index.ts +3 -0
- package/plugins/acryl-inspect/src/report.ts +126 -0
- package/plugins/acryl-inspect/src/service.ts +68 -0
- package/plugins/acryl-inspect/tests/report.spec.ts +63 -0
- package/plugins/acryl-inspect/tests/service.spec.ts +121 -0
- package/plugins/acryl-inspect/upstream.json +18 -0
- package/plugins/acryl-node-server/LICENSE +47 -0
- package/plugins/acryl-node-server/plugin.json +13 -0
- package/plugins/acryl-node-server/src/adapter/conninfo.ts +23 -0
- package/plugins/acryl-node-server/src/adapter/early-hints.ts +55 -0
- package/plugins/acryl-node-server/src/adapter/error.ts +11 -0
- package/plugins/acryl-node-server/src/adapter/headers.ts +249 -0
- package/plugins/acryl-node-server/src/adapter/index.ts +6 -0
- package/plugins/acryl-node-server/src/adapter/listener.ts +540 -0
- package/plugins/acryl-node-server/src/adapter/request.ts +797 -0
- package/plugins/acryl-node-server/src/adapter/response.ts +186 -0
- package/plugins/acryl-node-server/src/adapter/serve-static.ts +238 -0
- package/plugins/acryl-node-server/src/adapter/server.ts +36 -0
- package/plugins/acryl-node-server/src/adapter/types.ts +82 -0
- package/plugins/acryl-node-server/src/adapter/url.ts +42 -0
- package/plugins/acryl-node-server/src/adapter/utils/response/constants.ts +1 -0
- package/plugins/acryl-node-server/src/adapter/utils/response.ts +4 -0
- package/plugins/acryl-node-server/src/adapter/utils/stream.ts +88 -0
- package/plugins/acryl-node-server/src/adapter/utils.ts +96 -0
- package/plugins/acryl-node-server/src/adapter/websocket-types.ts +45 -0
- package/plugins/acryl-node-server/src/adapter/websocket.ts +375 -0
- package/plugins/acryl-node-server/src/index.ts +107 -0
- package/plugins/acryl-node-server/tests/adapter/app.ts +76 -0
- package/plugins/acryl-node-server/tests/adapter/assets/.static/plain.txt +1 -0
- package/plugins/acryl-node-server/tests/adapter/assets/favicon.ico +0 -0
- package/plugins/acryl-node-server/tests/adapter/assets/secret.txt +1 -0
- package/plugins/acryl-node-server/tests/adapter/assets/static/acryl.html +1 -0
- package/plugins/acryl-node-server/tests/adapter/assets/static/admin/secret.txt +1 -0
- package/plugins/acryl-node-server/tests/adapter/assets/static/data.json +5 -0
- package/plugins/acryl-node-server/tests/adapter/assets/static/extensionless +1 -0
- package/plugins/acryl-node-server/tests/adapter/assets/static/foo..bar.txt +0 -0
- package/plugins/acryl-node-server/tests/adapter/assets/static/index.html +1 -0
- package/plugins/acryl-node-server/tests/adapter/assets/static/plain.txt +1 -0
- package/plugins/acryl-node-server/tests/adapter/assets/static-with-context-path/plain.txt +1 -0
- package/plugins/acryl-node-server/tests/adapter/assets/static-with-precompressed/hello.bin +1 -0
- package/plugins/acryl-node-server/tests/adapter/assets/static-with-precompressed/hello.bin.br +1 -0
- package/plugins/acryl-node-server/tests/adapter/assets/static-with-precompressed/hello.txt +1 -0
- package/plugins/acryl-node-server/tests/adapter/assets/static-with-precompressed/hello.txt.br +1 -0
- package/plugins/acryl-node-server/tests/adapter/assets/static-with-precompressed/hello.txt.zst +1 -0
- package/plugins/acryl-node-server/tests/adapter/conninfo.test.ts +34 -0
- package/plugins/acryl-node-server/tests/adapter/content-length.test.ts +248 -0
- package/plugins/acryl-node-server/tests/adapter/early-hints.test.ts +457 -0
- package/plugins/acryl-node-server/tests/adapter/fixtures/keys/agent1-cert.pem +23 -0
- package/plugins/acryl-node-server/tests/adapter/fixtures/keys/agent1-key.pem +27 -0
- package/plugins/acryl-node-server/tests/adapter/headers.test.ts +252 -0
- package/plugins/acryl-node-server/tests/adapter/helpers/request.ts +190 -0
- package/plugins/acryl-node-server/tests/adapter/listener.test.ts +727 -0
- package/plugins/acryl-node-server/tests/adapter/request-client-disconnect.test.ts +189 -0
- package/plugins/acryl-node-server/tests/adapter/request.test.ts +1230 -0
- package/plugins/acryl-node-server/tests/adapter/response.test.ts +285 -0
- package/plugins/acryl-node-server/tests/adapter/serve-static.test.ts +849 -0
- package/plugins/acryl-node-server/tests/adapter/server-socket.test.ts +790 -0
- package/plugins/acryl-node-server/tests/adapter/server.test.ts +1302 -0
- package/plugins/acryl-node-server/tests/adapter/setup.ts +16 -0
- package/plugins/acryl-node-server/tests/adapter/url.test.ts +76 -0
- package/plugins/acryl-node-server/tests/adapter/utils/response.test.ts +23 -0
- package/plugins/acryl-node-server/tests/adapter/utils/stream.test.ts +75 -0
- package/plugins/acryl-node-server/tests/adapter/utils.test.ts +235 -0
- package/plugins/acryl-node-server/tests/adapter/websocket.test.ts +260 -0
- package/plugins/acryl-node-server/tests/server.spec.ts +141 -0
- package/plugins/acryl-node-server/upstream.json +18 -0
- package/plugins/acryl-router/LICENSE +47 -0
- package/plugins/acryl-router/plugin.json +13 -0
- package/plugins/acryl-router/src/client.ts +2 -0
- package/plugins/acryl-router/src/connection.ts +42 -0
- package/plugins/acryl-router/src/core/app-base.ts +544 -0
- package/plugins/acryl-router/src/core/app.test.ts +3833 -0
- package/plugins/acryl-router/src/core/app.ts +34 -0
- package/plugins/acryl-router/src/core/client/client.test.ts +2313 -0
- package/plugins/acryl-router/src/core/client/client.ts +249 -0
- package/plugins/acryl-router/src/core/client/fetch-result-please.ts +95 -0
- package/plugins/acryl-router/src/core/client/index.ts +17 -0
- package/plugins/acryl-router/src/core/client/types.test.ts +149 -0
- package/plugins/acryl-router/src/core/client/types.ts +393 -0
- package/plugins/acryl-router/src/core/client/utils.test.ts +405 -0
- package/plugins/acryl-router/src/core/client/utils.ts +117 -0
- package/plugins/acryl-router/src/core/compose.test.ts +751 -0
- package/plugins/acryl-router/src/core/compose.ts +73 -0
- package/plugins/acryl-router/src/core/context.test.ts +629 -0
- package/plugins/acryl-router/src/core/context.ts +781 -0
- package/plugins/acryl-router/src/core/helper/accepts/accepts.test.ts +344 -0
- package/plugins/acryl-router/src/core/helper/accepts/accepts.ts +96 -0
- package/plugins/acryl-router/src/core/helper/accepts/index.ts +6 -0
- package/plugins/acryl-router/src/core/helper/adapter/index.test.ts +55 -0
- package/plugins/acryl-router/src/core/helper/adapter/index.ts +90 -0
- package/plugins/acryl-router/src/core/helper/conninfo/index.ts +6 -0
- package/plugins/acryl-router/src/core/helper/conninfo/types.ts +45 -0
- package/plugins/acryl-router/src/core/helper/cookie/index.test.ts +510 -0
- package/plugins/acryl-router/src/core/helper/cookie/index.ts +146 -0
- package/plugins/acryl-router/src/core/helper/factory/index.test.ts +434 -0
- package/plugins/acryl-router/src/core/helper/factory/index.ts +375 -0
- package/plugins/acryl-router/src/core/helper/html/index.test.ts +78 -0
- package/plugins/acryl-router/src/core/helper/html/index.ts +57 -0
- package/plugins/acryl-router/src/core/helper/route/index.test.ts +259 -0
- package/plugins/acryl-router/src/core/helper/route/index.ts +144 -0
- package/plugins/acryl-router/src/core/helper/streaming/index.ts +9 -0
- package/plugins/acryl-router/src/core/helper/streaming/sse.ts +101 -0
- package/plugins/acryl-router/src/core/helper/streaming/stream.test.ts +128 -0
- package/plugins/acryl-router/src/core/helper/streaming/stream.ts +45 -0
- package/plugins/acryl-router/src/core/helper/streaming/text.test.ts +34 -0
- package/plugins/acryl-router/src/core/helper/streaming/text.ts +15 -0
- package/plugins/acryl-router/src/core/helper/streaming/utils.ts +11 -0
- package/plugins/acryl-router/src/core/helper/testing/index.test.ts +42 -0
- package/plugins/acryl-router/src/core/helper/testing/index.ts +28 -0
- package/plugins/acryl-router/src/core/helper/websocket/index.test.ts +124 -0
- package/plugins/acryl-router/src/core/helper/websocket/index.ts +140 -0
- package/plugins/acryl-router/src/core/http-exception.test.ts +45 -0
- package/plugins/acryl-router/src/core/http-exception.ts +77 -0
- package/plugins/acryl-router/src/core/index.ts +53 -0
- package/plugins/acryl-router/src/core/middleware/basic-auth/index.test.ts +434 -0
- package/plugins/acryl-router/src/core/middleware/basic-auth/index.ts +152 -0
- package/plugins/acryl-router/src/core/middleware/bearer-auth/index.test.ts +1018 -0
- package/plugins/acryl-router/src/core/middleware/bearer-auth/index.ts +220 -0
- package/plugins/acryl-router/src/core/middleware/body-limit/index.test.ts +273 -0
- package/plugins/acryl-router/src/core/middleware/body-limit/index.ts +110 -0
- package/plugins/acryl-router/src/core/middleware/combine/index.test.ts +355 -0
- package/plugins/acryl-router/src/core/middleware/combine/index.ts +171 -0
- package/plugins/acryl-router/src/core/middleware/compress/index.test.ts +535 -0
- package/plugins/acryl-router/src/core/middleware/compress/index.ts +142 -0
- package/plugins/acryl-router/src/core/middleware/context-storage/index.test.ts +43 -0
- package/plugins/acryl-router/src/core/middleware/context-storage/index.ts +58 -0
- package/plugins/acryl-router/src/core/middleware/cors/index.test.ts +532 -0
- package/plugins/acryl-router/src/core/middleware/cors/index.ts +163 -0
- package/plugins/acryl-router/src/core/middleware/csrf/index.test.ts +534 -0
- package/plugins/acryl-router/src/core/middleware/csrf/index.ts +150 -0
- package/plugins/acryl-router/src/core/middleware/etag/digest.test.ts +21 -0
- package/plugins/acryl-router/src/core/middleware/etag/digest.ts +95 -0
- package/plugins/acryl-router/src/core/middleware/etag/index.test.ts +503 -0
- package/plugins/acryl-router/src/core/middleware/etag/index.ts +135 -0
- package/plugins/acryl-router/src/core/middleware/ip-restriction/index.test.ts +217 -0
- package/plugins/acryl-router/src/core/middleware/ip-restriction/index.ts +278 -0
- package/plugins/acryl-router/src/core/middleware/jwk/index.test.ts +1135 -0
- package/plugins/acryl-router/src/core/middleware/jwk/index.ts +1 -0
- package/plugins/acryl-router/src/core/middleware/jwk/jwk.ts +195 -0
- package/plugins/acryl-router/src/core/middleware/jwk/keys.test.json +48 -0
- package/plugins/acryl-router/src/core/middleware/jwt/index.test.ts +802 -0
- package/plugins/acryl-router/src/core/middleware/jwt/index.ts +9 -0
- package/plugins/acryl-router/src/core/middleware/jwt/jwt.ts +189 -0
- package/plugins/acryl-router/src/core/middleware/language/index.test.ts +552 -0
- package/plugins/acryl-router/src/core/middleware/language/index.ts +12 -0
- package/plugins/acryl-router/src/core/middleware/language/language.ts +314 -0
- package/plugins/acryl-router/src/core/middleware/logger/index.test.ts +204 -0
- package/plugins/acryl-router/src/core/middleware/logger/index.ts +95 -0
- package/plugins/acryl-router/src/core/middleware/method-not-allowed/index.test.ts +292 -0
- package/plugins/acryl-router/src/core/middleware/method-not-allowed/index.ts +141 -0
- package/plugins/acryl-router/src/core/middleware/method-override/index.test.ts +221 -0
- package/plugins/acryl-router/src/core/middleware/method-override/index.ts +147 -0
- package/plugins/acryl-router/src/core/middleware/powered-by/index.test.ts +37 -0
- package/plugins/acryl-router/src/core/middleware/powered-by/index.ts +35 -0
- package/plugins/acryl-router/src/core/middleware/pretty-json/index.test.ts +218 -0
- package/plugins/acryl-router/src/core/middleware/pretty-json/index.ts +67 -0
- package/plugins/acryl-router/src/core/middleware/request-id/index.test.ts +168 -0
- package/plugins/acryl-router/src/core/middleware/request-id/index.ts +7 -0
- package/plugins/acryl-router/src/core/middleware/request-id/request-id.ts +59 -0
- package/plugins/acryl-router/src/core/middleware/secure-headers/index.test.ts +671 -0
- package/plugins/acryl-router/src/core/middleware/secure-headers/index.ts +8 -0
- package/plugins/acryl-router/src/core/middleware/secure-headers/permissions-policy.ts +101 -0
- package/plugins/acryl-router/src/core/middleware/secure-headers/secure-headers.ts +340 -0
- package/plugins/acryl-router/src/core/middleware/serve-static/index.test.ts +450 -0
- package/plugins/acryl-router/src/core/middleware/serve-static/index.ts +135 -0
- package/plugins/acryl-router/src/core/middleware/serve-static/path.test.ts +50 -0
- package/plugins/acryl-router/src/core/middleware/serve-static/path.ts +25 -0
- package/plugins/acryl-router/src/core/middleware/timeout/index.test.ts +70 -0
- package/plugins/acryl-router/src/core/middleware/timeout/index.ts +58 -0
- package/plugins/acryl-router/src/core/middleware/timing/index.test.ts +310 -0
- package/plugins/acryl-router/src/core/middleware/timing/index.ts +8 -0
- package/plugins/acryl-router/src/core/middleware/timing/timing.ts +256 -0
- package/plugins/acryl-router/src/core/middleware/trailing-slash/index.test.ts +381 -0
- package/plugins/acryl-router/src/core/middleware/trailing-slash/index.ts +156 -0
- package/plugins/acryl-router/src/core/request/constants.ts +1 -0
- package/plugins/acryl-router/src/core/request.test.ts +751 -0
- package/plugins/acryl-router/src/core/request.ts +502 -0
- package/plugins/acryl-router/src/core/router/common.case.test.ts +1132 -0
- package/plugins/acryl-router/src/core/router/linear-router/index.ts +6 -0
- package/plugins/acryl-router/src/core/router/linear-router/router.test.ts +80 -0
- package/plugins/acryl-router/src/core/router/linear-router/router.ts +152 -0
- package/plugins/acryl-router/src/core/router/pattern-router/index.ts +6 -0
- package/plugins/acryl-router/src/core/router/pattern-router/router.test.ts +46 -0
- package/plugins/acryl-router/src/core/router/pattern-router/router.ts +54 -0
- package/plugins/acryl-router/src/core/router/reg-exp-router/index.ts +7 -0
- package/plugins/acryl-router/src/core/router/reg-exp-router/matcher.ts +33 -0
- package/plugins/acryl-router/src/core/router/reg-exp-router/node.ts +170 -0
- package/plugins/acryl-router/src/core/router/reg-exp-router/prepared-router.test.ts +154 -0
- package/plugins/acryl-router/src/core/router/reg-exp-router/prepared-router.ts +165 -0
- package/plugins/acryl-router/src/core/router/reg-exp-router/router.test.ts +265 -0
- package/plugins/acryl-router/src/core/router/reg-exp-router/router.ts +174 -0
- package/plugins/acryl-router/src/core/router/reg-exp-router/trie.ts +84 -0
- package/plugins/acryl-router/src/core/router/smart-router/index.ts +6 -0
- package/plugins/acryl-router/src/core/router/smart-router/router.test.ts +13 -0
- package/plugins/acryl-router/src/core/router/smart-router/router.ts +70 -0
- package/plugins/acryl-router/src/core/router/trie-router/index.ts +6 -0
- package/plugins/acryl-router/src/core/router/trie-router/node.test.ts +896 -0
- package/plugins/acryl-router/src/core/router/trie-router/node.ts +221 -0
- package/plugins/acryl-router/src/core/router/trie-router/router.test.ts +8 -0
- package/plugins/acryl-router/src/core/router/trie-router/router.ts +18 -0
- package/plugins/acryl-router/src/core/router/utils.ts +1 -0
- package/plugins/acryl-router/src/core/router.ts +103 -0
- package/plugins/acryl-router/src/core/types.test.ts +4134 -0
- package/plugins/acryl-router/src/core/types.ts +2782 -0
- package/plugins/acryl-router/src/core/utils/accept.test.ts +299 -0
- package/plugins/acryl-router/src/core/utils/accept.ts +268 -0
- package/plugins/acryl-router/src/core/utils/basic-auth.test.ts +56 -0
- package/plugins/acryl-router/src/core/utils/basic-auth.ts +26 -0
- package/plugins/acryl-router/src/core/utils/body.test.ts +496 -0
- package/plugins/acryl-router/src/core/utils/body.ts +263 -0
- package/plugins/acryl-router/src/core/utils/buffer.test.ts +147 -0
- package/plugins/acryl-router/src/core/utils/buffer.ts +117 -0
- package/plugins/acryl-router/src/core/utils/color.test.ts +23 -0
- package/plugins/acryl-router/src/core/utils/color.ts +56 -0
- package/plugins/acryl-router/src/core/utils/compress.ts +10 -0
- package/plugins/acryl-router/src/core/utils/concurrent.test.ts +69 -0
- package/plugins/acryl-router/src/core/utils/concurrent.ts +55 -0
- package/plugins/acryl-router/src/core/utils/constants.ts +4 -0
- package/plugins/acryl-router/src/core/utils/cookie.test.ts +460 -0
- package/plugins/acryl-router/src/core/utils/cookie.ts +281 -0
- package/plugins/acryl-router/src/core/utils/crypto.test.ts +43 -0
- package/plugins/acryl-router/src/core/utils/crypto.ts +58 -0
- package/plugins/acryl-router/src/core/utils/encode.test.ts +61 -0
- package/plugins/acryl-router/src/core/utils/encode.ts +34 -0
- package/plugins/acryl-router/src/core/utils/filepath.test.ts +78 -0
- package/plugins/acryl-router/src/core/utils/filepath.ts +60 -0
- package/plugins/acryl-router/src/core/utils/handler.ts +15 -0
- package/plugins/acryl-router/src/core/utils/headers.ts +355 -0
- package/plugins/acryl-router/src/core/utils/html.test.ts +16 -0
- package/plugins/acryl-router/src/core/utils/html.ts +182 -0
- package/plugins/acryl-router/src/core/utils/http-status.ts +72 -0
- package/plugins/acryl-router/src/core/utils/ipaddr.test.ts +149 -0
- package/plugins/acryl-router/src/core/utils/ipaddr.ts +374 -0
- package/plugins/acryl-router/src/core/utils/jwt/index.ts +7 -0
- package/plugins/acryl-router/src/core/utils/jwt/jwa.test.ts +86 -0
- package/plugins/acryl-router/src/core/utils/jwt/jwa.ts +38 -0
- package/plugins/acryl-router/src/core/utils/jwt/jws.ts +235 -0
- package/plugins/acryl-router/src/core/utils/jwt/jwt.test.ts +1788 -0
- package/plugins/acryl-router/src/core/utils/jwt/jwt.ts +292 -0
- package/plugins/acryl-router/src/core/utils/jwt/types.ts +157 -0
- package/plugins/acryl-router/src/core/utils/jwt/utf8.ts +7 -0
- package/plugins/acryl-router/src/core/utils/mime.test.ts +64 -0
- package/plugins/acryl-router/src/core/utils/mime.ts +94 -0
- package/plugins/acryl-router/src/core/utils/stream.test.ts +212 -0
- package/plugins/acryl-router/src/core/utils/stream.ts +107 -0
- package/plugins/acryl-router/src/core/utils/types.test.ts +295 -0
- package/plugins/acryl-router/src/core/utils/types.ts +123 -0
- package/plugins/acryl-router/src/core/utils/url.test.ts +384 -0
- package/plugins/acryl-router/src/core/utils/url.ts +337 -0
- package/plugins/acryl-router/src/core/validator/index.ts +8 -0
- package/plugins/acryl-router/src/core/validator/utils.test.ts +82 -0
- package/plugins/acryl-router/src/core/validator/utils.ts +69 -0
- package/plugins/acryl-router/src/core/validator/validator.test.ts +1488 -0
- package/plugins/acryl-router/src/core/validator/validator.ts +185 -0
- package/plugins/acryl-router/src/helpers/index.ts +13 -0
- package/plugins/acryl-router/src/helpers/schema-validator.ts +35 -0
- package/plugins/acryl-router/src/index.ts +6 -0
- package/plugins/acryl-router/src/middleware/index.ts +25 -0
- package/plugins/acryl-router/src/middleware/loopback-only.ts +88 -0
- package/plugins/acryl-router/src/service.ts +356 -0
- package/plugins/acryl-router/tests/docs-examples.spec.ts +152 -0
- package/plugins/acryl-router/tests/live-install.spec.ts +64 -0
- package/plugins/acryl-router/tests/loader.spec.ts +72 -0
- package/plugins/acryl-router/tests/service.spec.ts +409 -0
- package/plugins/acryl-router/tests/shadow-state.spec.ts +79 -0
- package/plugins/acryl-router/upstream.json +20 -0
- package/plugins/acryl-router-http/LICENSE +21 -0
- package/plugins/acryl-router-http/plugin.json +12 -0
- package/plugins/acryl-router-http/src/bridge.ts +54 -0
- package/plugins/acryl-router-http/src/index.ts +63 -0
- package/plugins/acryl-router-http/src/serve.ts +24 -0
- package/plugins/acryl-router-http/tests/adapter.spec.ts +174 -0
- package/plugins/acryl-router-http/tests/stream.spec.ts +133 -0
- package/plugins/acryl-router-http/tests/surfaces.spec.ts +101 -0
- package/plugins/acryl-router-http/upstream.json +22 -0
- package/plugins/acryl-state/LICENSE +21 -0
- package/plugins/acryl-state/NOTICE +30 -0
- package/plugins/acryl-state/plugin.json +12 -0
- package/plugins/acryl-state/src/cell.ts +67 -0
- package/plugins/acryl-state/src/index.ts +3 -0
- package/plugins/acryl-state/src/react.ts +11 -0
- package/plugins/acryl-state/src/service.ts +119 -0
- package/plugins/acryl-state/tests/cell.spec.ts +71 -0
- package/plugins/acryl-state/tests/react.spec.ts +39 -0
- package/plugins/acryl-state/tests/service.spec.ts +132 -0
- package/plugins/acryl-state/upstream.json +22 -0
- package/plugins/builder/script.ts +6 -10
- package/plugins/extensions/index.ts +20 -3
- package/plugins/extensions/resolve.ts +28 -3
- package/plugins/openai/prompt.ts +12 -6
- package/plugins/tasks/index.ts +14 -0
- package/plugins/tsconfig.json +14 -5
- package/templates/agent/blend.yaml +5 -7
- package/templates/agent/src/app.ts +8 -8
- package/templates/agent/src/routes.ts +39 -38
- package/templates/agent/template.json +3 -3
- package/templates/agent/test/builder.test.ts +22 -14
- package/templates/agent/test/model.test.ts +3 -3
- package/templates/agent/tsconfig.json +8 -5
- package/templates/{app → blank}/blend.yaml +3 -3
- package/templates/{app → blank}/src/app.ts +5 -5
- package/templates/blank/src/routes.ts +16 -0
- package/templates/blank/template.json +1 -0
- package/templates/{app → blank}/test/app.test.ts +1 -1
- package/templates/{app → blank}/tsconfig.json +2 -4
- package/templates/todo/README.md +27 -0
- package/templates/todo/blend.yaml +25 -0
- package/templates/todo/gitignore +2 -0
- package/templates/todo/package.json +23 -0
- package/templates/todo/src/app.ts +71 -0
- package/templates/todo/src/main.ts +19 -0
- package/templates/todo/src/page.ts +28 -0
- package/templates/todo/src/todo.ts +123 -0
- package/templates/todo/template.json +1 -0
- package/templates/todo/test/todo.test.ts +145 -0
- package/templates/todo/tsconfig.json +17 -0
- package/templates/todo/upstream.json +12 -0
- package/plugins/events/index.ts +0 -42
- package/plugins/events/plugin.json +0 -9
- package/plugins/http/index.ts +0 -64
- package/plugins/http/plugin.json +0 -10
- package/plugins/server/index.ts +0 -138
- package/plugins/server/plugin.json +0 -10
- package/templates/app/src/routes.ts +0 -14
- package/templates/app/template.json +0 -1
- /package/templates/{app → blank}/README.md +0 -0
- /package/templates/{app → blank}/gitignore +0 -0
- /package/templates/{app → blank}/package.json +0 -0
- /package/templates/{app → blank}/src/main.ts +0 -0
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* JSON Web Signature (JWS)
|
|
4
|
+
* https://datatracker.ietf.org/doc/html/rfc7515
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { getRuntimeKey } from '../../helper/adapter/index.ts'
|
|
8
|
+
import { decodeBase64 } from '../encode.ts'
|
|
9
|
+
import type { SignatureAlgorithm } from './jwa.ts'
|
|
10
|
+
import { CryptoKeyUsage, JwtAlgorithmNotImplemented } from './types.ts'
|
|
11
|
+
import { utf8Encoder } from './utf8.ts'
|
|
12
|
+
import type { BufferSource } from '../types.ts'
|
|
13
|
+
|
|
14
|
+
type KeyImporterAlgorithm = Parameters<typeof crypto.subtle.importKey>[2]
|
|
15
|
+
type KeyAlgorithm =
|
|
16
|
+
| AlgorithmIdentifier
|
|
17
|
+
| RsaHashedImportParams
|
|
18
|
+
| (RsaPssParams & RsaHashedImportParams)
|
|
19
|
+
| (EcdsaParams & EcKeyImportParams)
|
|
20
|
+
| HmacImportParams
|
|
21
|
+
|
|
22
|
+
// Extending the JsonWebKey interface to include the "kid" property.
|
|
23
|
+
// https://datatracker.ietf.org/doc/html/rfc7515#section-4.1.4
|
|
24
|
+
export interface AppJsonWebKey extends JsonWebKey {
|
|
25
|
+
kid?: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type SignatureKey = string | AppJsonWebKey | CryptoKey
|
|
29
|
+
|
|
30
|
+
export async function signing(
|
|
31
|
+
privateKey: SignatureKey,
|
|
32
|
+
alg: SignatureAlgorithm,
|
|
33
|
+
data: BufferSource
|
|
34
|
+
): Promise<ArrayBuffer> {
|
|
35
|
+
const algorithm = getKeyAlgorithm(alg)
|
|
36
|
+
const cryptoKey = await importPrivateKey(privateKey, algorithm)
|
|
37
|
+
return await crypto.subtle.sign(algorithm, cryptoKey, data)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export async function verifying(
|
|
41
|
+
publicKey: SignatureKey,
|
|
42
|
+
alg: SignatureAlgorithm,
|
|
43
|
+
signature: BufferSource,
|
|
44
|
+
data: BufferSource
|
|
45
|
+
): Promise<boolean> {
|
|
46
|
+
const algorithm = getKeyAlgorithm(alg)
|
|
47
|
+
const cryptoKey = await importPublicKey(publicKey, algorithm)
|
|
48
|
+
return await crypto.subtle.verify(algorithm, cryptoKey, signature, data)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function pemToBinary(pem: string): Uint8Array<ArrayBuffer> {
|
|
52
|
+
return decodeBase64(pem.replace(/-+(BEGIN|END).*?-+/g, '').replace(/\s/g, ''))
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async function importPrivateKey(key: SignatureKey, alg: KeyImporterAlgorithm): Promise<CryptoKey> {
|
|
56
|
+
if (!crypto.subtle || !crypto.subtle.importKey) {
|
|
57
|
+
throw new Error('`crypto.subtle.importKey` is undefined. JWT auth middleware requires it.')
|
|
58
|
+
}
|
|
59
|
+
if (isCryptoKey(key)) {
|
|
60
|
+
if (key.type !== 'private' && key.type !== 'secret') {
|
|
61
|
+
throw new Error(
|
|
62
|
+
`unexpected key type: CryptoKey.type is ${key.type}, expected private or secret`
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
return key
|
|
66
|
+
}
|
|
67
|
+
const usages = [CryptoKeyUsage.Sign]
|
|
68
|
+
if (typeof key === 'object') {
|
|
69
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey#json_web_key_import
|
|
70
|
+
return await crypto.subtle.importKey('jwk', key, alg, false, usages)
|
|
71
|
+
}
|
|
72
|
+
if (key.includes('PRIVATE')) {
|
|
73
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey#pkcs_8_import
|
|
74
|
+
return await crypto.subtle.importKey('pkcs8', pemToBinary(key), alg, false, usages)
|
|
75
|
+
}
|
|
76
|
+
return await crypto.subtle.importKey('raw', utf8Encoder.encode(key), alg, false, usages)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async function importPublicKey(key: SignatureKey, alg: KeyImporterAlgorithm): Promise<CryptoKey> {
|
|
80
|
+
if (!crypto.subtle || !crypto.subtle.importKey) {
|
|
81
|
+
throw new Error('`crypto.subtle.importKey` is undefined. JWT auth middleware requires it.')
|
|
82
|
+
}
|
|
83
|
+
if (isCryptoKey(key)) {
|
|
84
|
+
if (key.type === 'public' || key.type === 'secret') {
|
|
85
|
+
return key
|
|
86
|
+
}
|
|
87
|
+
key = await exportPublicJwkFrom(key)
|
|
88
|
+
}
|
|
89
|
+
if (typeof key === 'string' && key.includes('PRIVATE')) {
|
|
90
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey#pkcs_8_import
|
|
91
|
+
const privateKey = await crypto.subtle.importKey('pkcs8', pemToBinary(key), alg, true, [
|
|
92
|
+
CryptoKeyUsage.Sign,
|
|
93
|
+
])
|
|
94
|
+
key = await exportPublicJwkFrom(privateKey)
|
|
95
|
+
}
|
|
96
|
+
const usages = [CryptoKeyUsage.Verify]
|
|
97
|
+
if (typeof key === 'object') {
|
|
98
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey#json_web_key_import
|
|
99
|
+
return await crypto.subtle.importKey('jwk', key, alg, false, usages)
|
|
100
|
+
}
|
|
101
|
+
if (key.includes('PUBLIC')) {
|
|
102
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey#subjectpublickeyinfo_import
|
|
103
|
+
return await crypto.subtle.importKey('spki', pemToBinary(key), alg, false, usages)
|
|
104
|
+
}
|
|
105
|
+
return await crypto.subtle.importKey('raw', utf8Encoder.encode(key), alg, false, usages)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// https://datatracker.ietf.org/doc/html/rfc7517
|
|
109
|
+
async function exportPublicJwkFrom(privateKey: CryptoKey): Promise<JsonWebKey> {
|
|
110
|
+
if (privateKey.type !== 'private') {
|
|
111
|
+
throw new Error(`unexpected key type: ${privateKey.type}`)
|
|
112
|
+
}
|
|
113
|
+
if (!privateKey.extractable) {
|
|
114
|
+
throw new Error('unexpected private key is unextractable')
|
|
115
|
+
}
|
|
116
|
+
const jwk = await crypto.subtle.exportKey('jwk', privateKey)
|
|
117
|
+
const { kty } = jwk // common
|
|
118
|
+
const { alg, e, n } = jwk // rsa
|
|
119
|
+
const { crv, x, y } = jwk // elliptic-curve
|
|
120
|
+
return { kty, alg, e, n, crv, x, y, key_ops: [CryptoKeyUsage.Verify] }
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function getKeyAlgorithm(name: SignatureAlgorithm): KeyAlgorithm {
|
|
124
|
+
switch (name) {
|
|
125
|
+
case 'HS256':
|
|
126
|
+
return {
|
|
127
|
+
name: 'HMAC',
|
|
128
|
+
hash: {
|
|
129
|
+
name: 'SHA-256',
|
|
130
|
+
},
|
|
131
|
+
} satisfies HmacImportParams
|
|
132
|
+
case 'HS384':
|
|
133
|
+
return {
|
|
134
|
+
name: 'HMAC',
|
|
135
|
+
hash: {
|
|
136
|
+
name: 'SHA-384',
|
|
137
|
+
},
|
|
138
|
+
} satisfies HmacImportParams
|
|
139
|
+
case 'HS512':
|
|
140
|
+
return {
|
|
141
|
+
name: 'HMAC',
|
|
142
|
+
hash: {
|
|
143
|
+
name: 'SHA-512',
|
|
144
|
+
},
|
|
145
|
+
} satisfies HmacImportParams
|
|
146
|
+
case 'RS256':
|
|
147
|
+
return {
|
|
148
|
+
name: 'RSASSA-PKCS1-v1_5',
|
|
149
|
+
hash: {
|
|
150
|
+
name: 'SHA-256',
|
|
151
|
+
},
|
|
152
|
+
} satisfies RsaHashedImportParams
|
|
153
|
+
case 'RS384':
|
|
154
|
+
return {
|
|
155
|
+
name: 'RSASSA-PKCS1-v1_5',
|
|
156
|
+
hash: {
|
|
157
|
+
name: 'SHA-384',
|
|
158
|
+
},
|
|
159
|
+
} satisfies RsaHashedImportParams
|
|
160
|
+
case 'RS512':
|
|
161
|
+
return {
|
|
162
|
+
name: 'RSASSA-PKCS1-v1_5',
|
|
163
|
+
hash: {
|
|
164
|
+
name: 'SHA-512',
|
|
165
|
+
},
|
|
166
|
+
} satisfies RsaHashedImportParams
|
|
167
|
+
case 'PS256':
|
|
168
|
+
return {
|
|
169
|
+
name: 'RSA-PSS',
|
|
170
|
+
hash: {
|
|
171
|
+
name: 'SHA-256',
|
|
172
|
+
},
|
|
173
|
+
saltLength: 32, // 256 >> 3
|
|
174
|
+
} satisfies RsaPssParams & RsaHashedImportParams
|
|
175
|
+
case 'PS384':
|
|
176
|
+
return {
|
|
177
|
+
name: 'RSA-PSS',
|
|
178
|
+
hash: {
|
|
179
|
+
name: 'SHA-384',
|
|
180
|
+
},
|
|
181
|
+
saltLength: 48, // 384 >> 3
|
|
182
|
+
} satisfies RsaPssParams & RsaHashedImportParams
|
|
183
|
+
case 'PS512':
|
|
184
|
+
return {
|
|
185
|
+
name: 'RSA-PSS',
|
|
186
|
+
hash: {
|
|
187
|
+
name: 'SHA-512',
|
|
188
|
+
},
|
|
189
|
+
saltLength: 64, // 512 >> 3,
|
|
190
|
+
} satisfies RsaPssParams & RsaHashedImportParams
|
|
191
|
+
case 'ES256':
|
|
192
|
+
return {
|
|
193
|
+
name: 'ECDSA',
|
|
194
|
+
hash: {
|
|
195
|
+
name: 'SHA-256',
|
|
196
|
+
},
|
|
197
|
+
namedCurve: 'P-256',
|
|
198
|
+
} satisfies EcdsaParams & EcKeyImportParams
|
|
199
|
+
case 'ES384':
|
|
200
|
+
return {
|
|
201
|
+
name: 'ECDSA',
|
|
202
|
+
hash: {
|
|
203
|
+
name: 'SHA-384',
|
|
204
|
+
},
|
|
205
|
+
namedCurve: 'P-384',
|
|
206
|
+
} satisfies EcdsaParams & EcKeyImportParams
|
|
207
|
+
case 'ES512':
|
|
208
|
+
return {
|
|
209
|
+
name: 'ECDSA',
|
|
210
|
+
hash: {
|
|
211
|
+
name: 'SHA-512',
|
|
212
|
+
},
|
|
213
|
+
namedCurve: 'P-521',
|
|
214
|
+
} satisfies EcdsaParams & EcKeyImportParams
|
|
215
|
+
case 'EdDSA':
|
|
216
|
+
// Currently, supported only Safari and Deno, Node.js.
|
|
217
|
+
// See: https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/verify
|
|
218
|
+
return {
|
|
219
|
+
name: 'Ed25519',
|
|
220
|
+
namedCurve: 'Ed25519',
|
|
221
|
+
}
|
|
222
|
+
default:
|
|
223
|
+
throw new JwtAlgorithmNotImplemented(name)
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function isCryptoKey(key: SignatureKey): key is CryptoKey {
|
|
228
|
+
const runtime = getRuntimeKey()
|
|
229
|
+
// @ts-expect-error CryptoKey hasn't exported to global in node v18
|
|
230
|
+
if (runtime === 'node' && !!crypto.webcrypto) {
|
|
231
|
+
// @ts-expect-error CryptoKey hasn't exported to global in node v18
|
|
232
|
+
return key instanceof crypto.webcrypto.CryptoKey
|
|
233
|
+
}
|
|
234
|
+
return key instanceof CryptoKey
|
|
235
|
+
}
|