acrylblends 0.4.1 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +73 -0
- package/README.md +325 -0
- package/docs/framework/README.md +51 -51
- package/docs/framework/UPSTREAM.md +1 -1
- package/docs/framework/agents/index.md +24 -0
- package/docs/framework/api/acryl.md +259 -0
- package/docs/framework/api/context.md +527 -0
- package/docs/framework/api/exception.md +80 -0
- package/docs/framework/api/index.md +12 -0
- package/docs/framework/api/presets.md +65 -0
- package/docs/framework/api/request.md +396 -0
- package/docs/framework/api/routing.md +303 -0
- package/docs/framework/{api-summary.md → api/summary.md} +19 -17
- package/docs/framework/concepts/benchmarks.md +26 -0
- package/docs/framework/concepts/developer-experience.md +5 -0
- package/docs/framework/concepts/middleware.md +21 -0
- package/docs/framework/concepts/motivation.md +14 -0
- package/docs/framework/concepts/routers.md +63 -0
- package/docs/framework/concepts/stacks.md +235 -0
- package/docs/framework/concepts/web-standard.md +37 -0
- package/docs/framework/{getting-started.md → cordis/acryl-in-a-cordis-app.md} +16 -16
- package/docs/framework/{concepts.md → cordis/concepts.md} +2 -2
- package/docs/framework/cordis/middleware.md +8 -0
- package/docs/framework/{migration-from-0-3.md → cordis/migration-from-0-3.md} +16 -13
- package/docs/framework/cordis/migration-from-0-4.md +14 -0
- package/docs/framework/{migration-from-dsh-webserver.md → cordis/migration-from-dsh-webserver.md} +13 -7
- package/docs/framework/{routing.md → cordis/mounting.md} +5 -108
- package/docs/framework/{node-server.md → cordis/node-server.md} +4 -4
- package/docs/framework/{surfaces.md → cordis/surfaces.md} +2 -2
- package/docs/framework/cordis/transport-and-cancellation.md +57 -0
- package/docs/framework/{validation.md → cordis/validation.md} +9 -9
- package/docs/framework/getting-started/basic.md +196 -0
- package/docs/framework/getting-started/bun.md +221 -0
- package/docs/framework/getting-started/nodejs.md +344 -0
- package/docs/framework/getting-started/other-runtimes.md +23 -0
- package/docs/framework/guides/best-practices.md +231 -0
- package/docs/framework/guides/create-acrylblends.md +79 -0
- package/docs/framework/guides/examples.md +3 -0
- package/docs/framework/guides/faq.md +19 -0
- package/docs/framework/guides/helpers.md +33 -0
- package/docs/framework/guides/jsx-dom.md +299 -0
- package/docs/framework/guides/jsx.md +440 -0
- package/docs/framework/guides/middleware.md +253 -0
- package/docs/framework/guides/rpc.md +886 -0
- package/docs/framework/guides/testing.md +133 -0
- package/docs/framework/guides/validation.md +383 -0
- package/docs/framework/helpers/accepts.md +60 -0
- package/docs/framework/helpers/adapter.md +87 -0
- package/docs/framework/helpers/conninfo.md +112 -0
- package/docs/framework/helpers/cookie.md +232 -0
- package/docs/framework/helpers/css.md +285 -0
- package/docs/framework/helpers/dev.md +67 -0
- package/docs/framework/helpers/factory.md +180 -0
- package/docs/framework/helpers/html.md +123 -0
- package/docs/framework/helpers/jwt.md +184 -0
- package/docs/framework/helpers/proxy.md +118 -0
- package/docs/framework/helpers/route.md +143 -0
- package/docs/framework/helpers/ssg.md +393 -0
- package/docs/framework/helpers/streaming.md +119 -0
- package/docs/framework/helpers/testing.md +101 -0
- package/docs/framework/helpers/websocket.md +215 -0
- package/docs/framework/middleware/builtin/basic-auth.md +165 -0
- package/docs/framework/middleware/builtin/bearer-auth.md +138 -0
- package/docs/framework/middleware/builtin/body-limit.md +71 -0
- package/docs/framework/middleware/builtin/cache.md +122 -0
- package/docs/framework/middleware/builtin/combine.md +94 -0
- package/docs/framework/middleware/builtin/compress.md +59 -0
- package/docs/framework/middleware/builtin/context-storage.md +78 -0
- package/docs/framework/middleware/builtin/cors.md +135 -0
- package/docs/framework/middleware/builtin/csrf.md +105 -0
- package/docs/framework/middleware/builtin/etag.md +54 -0
- package/docs/framework/middleware/builtin/ip-restriction.md +69 -0
- package/docs/framework/middleware/builtin/jsx-renderer.md +286 -0
- package/docs/framework/middleware/builtin/jwk.md +192 -0
- package/docs/framework/middleware/builtin/jwt.md +145 -0
- package/docs/framework/middleware/builtin/language.md +232 -0
- package/docs/framework/middleware/builtin/logger.md +74 -0
- package/docs/framework/middleware/builtin/loopback-only.md +31 -0
- package/docs/framework/middleware/builtin/method-not-allowed.md +48 -0
- package/docs/framework/middleware/builtin/method-override.md +80 -0
- package/docs/framework/middleware/builtin/mount.md +106 -0
- package/docs/framework/middleware/builtin/pretty-json.md +53 -0
- package/docs/framework/middleware/builtin/request-id.md +94 -0
- package/docs/framework/middleware/builtin/secure-headers.md +247 -0
- package/docs/framework/middleware/builtin/timeout.md +98 -0
- package/docs/framework/middleware/builtin/timing.md +101 -0
- package/docs/framework/middleware/builtin/trailing-slash.md +74 -0
- package/docs/framework/middleware/third-party.md +4 -0
- package/docs/framework/upstream.json +3 -3
- package/lib/accepts-XBuZPVRI.js +52 -0
- package/lib/accepts.d.ts +33 -0
- package/lib/accepts.js +2 -0
- package/lib/acryl-base.d.ts +2 -0
- package/lib/acryl-base.js +332 -0
- package/lib/adapter.d.ts +12 -0
- package/lib/adapter.js +37 -0
- package/lib/app-BM0rTCp7.js +26 -0
- package/lib/app-CmAYW1Al.d.ts +21 -0
- package/lib/basic-auth.d.ts +72 -0
- package/lib/basic-auth.js +95 -0
- package/lib/bearer-auth.d.ts +89 -0
- package/lib/bearer-auth.js +94 -0
- package/lib/body-limit.d.ts +42 -0
- package/lib/body-limit.js +66 -0
- package/lib/client-BHTr318g.js +266 -0
- package/lib/client.d.ts +3 -0
- package/lib/client.js +2 -0
- package/lib/combine.d.ts +85 -0
- package/lib/combine.js +137 -0
- package/lib/compose-BuW2B6PZ.js +50 -0
- package/lib/compress.d.ts +38 -0
- package/lib/compress.js +79 -0
- package/lib/connection-C7xgP1hP.js +24 -0
- package/lib/conninfo.d.ts +25 -0
- package/lib/conninfo.js +2 -0
- package/lib/constants-Dy7ZvN1H.js +4 -0
- package/lib/context-Bm7rI-oK.d.ts +1234 -0
- package/lib/context-DDO0cfuP.js +365 -0
- package/lib/context-storage.d.ts +38 -0
- package/lib/context-storage.js +52 -0
- package/lib/cookie-ClMaKDQf.d.ts +40 -0
- package/lib/cookie.d.ts +24 -0
- package/lib/cookie.js +82 -0
- package/lib/cors.d.ts +52 -0
- package/lib/cors.js +106 -0
- package/lib/csrf.d.ts +75 -0
- package/lib/csrf.js +101 -0
- package/lib/etag.d.ts +40 -0
- package/lib/etag.js +135 -0
- package/lib/factory.d.ts +35 -0
- package/lib/factory.js +30 -0
- package/lib/headers-tu2YYN8T.d.ts +11 -0
- package/lib/html.d.ts +6 -0
- package/lib/html.js +31 -0
- package/lib/http-exception.d.ts +57 -0
- package/lib/http-exception.js +54 -0
- package/lib/http-status-DaAwGAFL.d.ts +35 -0
- package/lib/index-B-3F4wt2.d.ts +12 -0
- package/lib/index-UTBmM3GX.d.ts +68 -0
- package/lib/index-oOClm_Xk.d.ts +45 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.js +28 -0
- package/lib/ip-restriction.d.ts +68 -0
- package/lib/ip-restriction.js +166 -0
- package/lib/jwk.d.ts +52 -0
- package/lib/jwk.js +117 -0
- package/lib/jwt-BGJBw5AF.js +403 -0
- package/lib/jwt-Dg493Tai.d.ts +51 -0
- package/lib/jwt.d.ts +72 -0
- package/lib/jwt.js +115 -0
- package/lib/language.d.ts +88 -0
- package/lib/language.js +198 -0
- package/lib/logger.d.ts +22 -0
- package/lib/logger.js +54 -0
- package/lib/loopback-only.d.ts +45 -0
- package/lib/loopback-only.js +90 -0
- package/lib/method-not-allowed.d.ts +47 -0
- package/lib/method-not-allowed.js +82 -0
- package/lib/method-override.d.ts +46 -0
- package/lib/method-override.js +103 -0
- package/lib/mime-BQOYHl-l.d.ts +72 -0
- package/lib/node-server/conninfo.d.ts +11 -0
- package/lib/node-server/conninfo.js +19 -0
- package/lib/node-server/serve-static.d.ts +19 -0
- package/lib/node-server/serve-static.js +2 -0
- package/lib/node-server.d.ts +103 -0
- package/lib/node-server.js +1325 -0
- package/lib/powered-by.d.ts +28 -0
- package/lib/powered-by.js +24 -0
- package/lib/pretty-json.d.ts +40 -0
- package/lib/pretty-json.js +39 -0
- package/lib/reg-exp-router-DC1R3qoY.js +363 -0
- package/lib/request-id.d.ts +45 -0
- package/lib/request-id.js +34 -0
- package/lib/request.d.ts +2 -0
- package/lib/request.js +323 -0
- package/lib/route.d.ts +78 -0
- package/lib/route.js +126 -0
- package/lib/router/linear-router.d.ts +11 -0
- package/lib/router/linear-router.js +96 -0
- package/lib/router/pattern-router.d.ts +11 -0
- package/lib/router/pattern-router.js +41 -0
- package/lib/router/reg-exp-router.d.ts +35 -0
- package/lib/router/reg-exp-router.js +2 -0
- package/lib/router/smart-router.d.ts +15 -0
- package/lib/router/smart-router.js +2 -0
- package/lib/router/trie-router.d.ts +11 -0
- package/lib/router/trie-router.js +2 -0
- package/lib/router-CvUxUTOq.d.ts +99 -0
- package/lib/router.d.ts +2 -0
- package/lib/router.js +35 -0
- package/lib/schema-validator.d.ts +28 -0
- package/lib/schema-validator.js +22 -0
- package/lib/secure-headers.d.ts +125 -0
- package/lib/secure-headers.js +163 -0
- package/lib/serve-static-Dw_m6KxR.js +213 -0
- package/lib/serve-static.d.ts +31 -0
- package/lib/serve-static.js +77 -0
- package/lib/smart-router-C5CZ5XSM.js +49 -0
- package/lib/stream-CPdqZ0Fp.d.ts +34 -0
- package/lib/streaming-DHST3Scg.js +96 -0
- package/lib/streaming.d.ts +23 -0
- package/lib/streaming.js +2 -0
- package/lib/testing.d.ts +10 -0
- package/lib/testing.js +17 -0
- package/lib/timeout.d.ts +30 -0
- package/lib/timeout.js +42 -0
- package/lib/timing.d.ts +130 -0
- package/lib/timing.js +183 -0
- package/lib/trailing-slash.d.ts +91 -0
- package/lib/trailing-slash.js +85 -0
- package/lib/trie-router-CfFbapzL.js +146 -0
- package/lib/types-CDO6I3B0.d.ts +40 -0
- package/lib/types-CHesD1KG.d.ts +195 -0
- package/lib/types-CwrQjlaM.d.ts +105 -0
- package/lib/types-DR95J00T.d.ts +29 -0
- package/lib/types.d.ts +2 -0
- package/lib/types.js +4 -0
- package/lib/utils/accept.d.ts +9 -0
- package/lib/utils/accept.js +193 -0
- package/lib/utils/basic-auth.d.ts +8 -0
- package/lib/utils/basic-auth.js +20 -0
- package/lib/utils/body.d.ts +2 -0
- package/lib/utils/body.js +94 -0
- package/lib/utils/buffer.d.ts +19 -0
- package/lib/utils/buffer.js +51 -0
- package/lib/utils/color.d.ts +24 -0
- package/lib/utils/color.js +37 -0
- package/lib/utils/compress.d.ts +11 -0
- package/lib/utils/compress.js +11 -0
- package/lib/utils/concurrent.d.ts +17 -0
- package/lib/utils/concurrent.js +30 -0
- package/lib/utils/constants.d.ts +7 -0
- package/lib/utils/constants.js +7 -0
- package/lib/utils/cookie.d.ts +2 -0
- package/lib/utils/cookie.js +125 -0
- package/lib/utils/crypto.d.ts +14 -0
- package/lib/utils/crypto.js +34 -0
- package/lib/utils/encode.d.ts +11 -0
- package/lib/utils/encode.js +33 -0
- package/lib/utils/filepath.d.ts +14 -0
- package/lib/utils/filepath.js +25 -0
- package/lib/utils/handler.d.ts +9 -0
- package/lib/utils/handler.js +12 -0
- package/lib/utils/headers.d.ts +2 -0
- package/lib/utils/headers.js +1 -0
- package/lib/utils/html.d.ts +46 -0
- package/lib/utils/html.js +103 -0
- package/lib/utils/http-status.d.ts +2 -0
- package/lib/utils/http-status.js +1 -0
- package/lib/utils/ipaddr.d.ts +56 -0
- package/lib/utils/ipaddr.js +238 -0
- package/lib/utils/jwt.d.ts +24 -0
- package/lib/utils/jwt.js +2 -0
- package/lib/utils/mime.d.ts +2 -0
- package/lib/utils/mime.js +77 -0
- package/lib/utils/stream.d.ts +2 -0
- package/lib/utils/stream.js +88 -0
- package/lib/utils/types.d.ts +2 -0
- package/lib/utils/types.js +1 -0
- package/lib/utils/url.d.ts +46 -0
- package/lib/utils/url.js +197 -0
- package/lib/utils-dw8lxqjL.js +4 -0
- package/lib/validator-D84mq-dO.js +65 -0
- package/lib/validator.d.ts +42 -0
- package/lib/validator.js +2 -0
- package/lib/ws.d.ts +2 -0
- package/lib/ws.js +53 -0
- package/package.json +312 -14
- package/plugins/acryl-inspect/src/service.ts +2 -2
- package/plugins/acryl-inspect/tests/service.spec.ts +3 -3
- package/plugins/acryl-inspect/upstream.json +2 -2
- package/plugins/acryl-node-server/tests/adapter/app.ts +2 -2
- package/plugins/acryl-node-server/tests/adapter/assets/static/acryl.html +1 -1
- package/plugins/acryl-node-server/tests/adapter/assets/static/index.html +1 -1
- package/plugins/acryl-node-server/tests/adapter/conninfo.test.ts +2 -2
- package/plugins/acryl-node-server/tests/adapter/content-length.test.ts +4 -4
- package/plugins/acryl-node-server/tests/adapter/early-hints.test.ts +5 -5
- package/plugins/acryl-node-server/tests/adapter/request-client-disconnect.test.ts +2 -2
- package/plugins/acryl-node-server/tests/adapter/serve-static.test.ts +20 -20
- package/plugins/acryl-node-server/tests/adapter/server-socket.test.ts +2 -2
- package/plugins/acryl-node-server/tests/adapter/server.test.ts +60 -50
- package/plugins/acryl-node-server/tests/adapter/utils/response.test.ts +4 -4
- package/plugins/acryl-node-server/tests/adapter/websocket.test.ts +9 -9
- package/plugins/acryl-node-server/tests/server.spec.ts +6 -6
- package/plugins/acryl-node-server/upstream.json +2 -2
- package/plugins/acryl-router/src/client.ts +1 -1
- package/plugins/acryl-router/src/connection.ts +2 -2
- package/plugins/acryl-router/src/core/app-base.ts +29 -29
- package/plugins/acryl-router/src/core/app.test.ts +175 -175
- package/plugins/acryl-router/src/core/app.ts +8 -8
- package/plugins/acryl-router/src/core/client/client.test.ts +76 -76
- package/plugins/acryl-router/src/core/client/client.ts +2 -2
- package/plugins/acryl-router/src/core/client/fetch-result-please.ts +1 -1
- package/plugins/acryl-router/src/core/client/index.ts +1 -1
- package/plugins/acryl-router/src/core/client/types.test.ts +6 -6
- package/plugins/acryl-router/src/core/client/types.ts +16 -16
- package/plugins/acryl-router/src/core/client/utils.test.ts +2 -2
- package/plugins/acryl-router/src/core/context.test.ts +4 -4
- package/plugins/acryl-router/src/core/context.ts +6 -6
- package/plugins/acryl-router/src/core/helper/accepts/accepts.test.ts +3 -3
- package/plugins/acryl-router/src/core/helper/accepts/index.ts +1 -1
- package/plugins/acryl-router/src/core/helper/adapter/index.test.ts +6 -6
- package/plugins/acryl-router/src/core/helper/adapter/index.ts +1 -1
- package/plugins/acryl-router/src/core/helper/conninfo/index.ts +1 -1
- package/plugins/acryl-router/src/core/helper/cookie/index.test.ts +8 -8
- package/plugins/acryl-router/src/core/helper/cookie/index.ts +1 -1
- package/plugins/acryl-router/src/core/helper/factory/index.test.ts +9 -9
- package/plugins/acryl-router/src/core/helper/factory/index.ts +10 -10
- package/plugins/acryl-router/src/core/helper/html/index.test.ts +4 -4
- package/plugins/acryl-router/src/core/helper/html/index.ts +1 -1
- package/plugins/acryl-router/src/core/helper/route/index.test.ts +7 -7
- package/plugins/acryl-router/src/core/helper/route/index.ts +8 -8
- package/plugins/acryl-router/src/core/helper/streaming/index.ts +1 -1
- package/plugins/acryl-router/src/core/helper/testing/index.test.ts +6 -6
- package/plugins/acryl-router/src/core/helper/testing/index.ts +4 -4
- package/plugins/acryl-router/src/core/helper/websocket/index.ts +2 -1
- package/plugins/acryl-router/src/core/http-exception.ts +1 -1
- package/plugins/acryl-router/src/core/index.ts +9 -9
- package/plugins/acryl-router/src/core/middleware/basic-auth/index.test.ts +6 -6
- package/plugins/acryl-router/src/core/middleware/basic-auth/index.ts +3 -3
- package/plugins/acryl-router/src/core/middleware/bearer-auth/index.test.ts +5 -5
- package/plugins/acryl-router/src/core/middleware/bearer-auth/index.ts +3 -3
- package/plugins/acryl-router/src/core/middleware/body-limit/index.test.ts +6 -6
- package/plugins/acryl-router/src/core/middleware/body-limit/index.ts +3 -3
- package/plugins/acryl-router/src/core/middleware/combine/index.test.ts +9 -9
- package/plugins/acryl-router/src/core/middleware/combine/index.ts +7 -7
- package/plugins/acryl-router/src/core/middleware/compress/index.test.ts +9 -9
- package/plugins/acryl-router/src/core/middleware/compress/index.ts +3 -3
- package/plugins/acryl-router/src/core/middleware/context-storage/index.test.ts +5 -5
- package/plugins/acryl-router/src/core/middleware/context-storage/index.ts +4 -4
- package/plugins/acryl-router/src/core/middleware/cors/index.test.ts +7 -7
- package/plugins/acryl-router/src/core/middleware/cors/index.ts +3 -3
- package/plugins/acryl-router/src/core/middleware/csrf/index.test.ts +10 -10
- package/plugins/acryl-router/src/core/middleware/csrf/index.ts +3 -3
- package/plugins/acryl-router/src/core/middleware/etag/index.test.ts +42 -42
- package/plugins/acryl-router/src/core/middleware/etag/index.ts +4 -4
- package/plugins/acryl-router/src/core/middleware/ip-restriction/index.test.ts +4 -4
- package/plugins/acryl-router/src/core/middleware/ip-restriction/index.ts +6 -6
- package/plugins/acryl-router/src/core/middleware/jwk/index.test.ts +16 -16
- package/plugins/acryl-router/src/core/middleware/jwk/jwk.ts +7 -6
- package/plugins/acryl-router/src/core/middleware/jwt/index.test.ts +16 -16
- package/plugins/acryl-router/src/core/middleware/jwt/jwt.ts +4 -3
- package/plugins/acryl-router/src/core/middleware/language/index.test.ts +3 -3
- package/plugins/acryl-router/src/core/middleware/language/language.ts +3 -3
- package/plugins/acryl-router/src/core/middleware/logger/index.test.ts +5 -5
- package/plugins/acryl-router/src/core/middleware/logger/index.ts +4 -4
- package/plugins/acryl-router/src/core/middleware/method-not-allowed/index.test.ts +24 -24
- package/plugins/acryl-router/src/core/middleware/method-not-allowed/index.ts +8 -8
- package/plugins/acryl-router/src/core/middleware/method-override/index.test.ts +5 -5
- package/plugins/acryl-router/src/core/middleware/method-override/index.ts +6 -6
- package/plugins/acryl-router/src/core/middleware/powered-by/index.test.ts +4 -4
- package/plugins/acryl-router/src/core/middleware/powered-by/index.ts +6 -6
- package/plugins/acryl-router/src/core/middleware/pretty-json/index.test.ts +30 -30
- package/plugins/acryl-router/src/core/middleware/pretty-json/index.ts +4 -4
- package/plugins/acryl-router/src/core/middleware/request-id/index.test.ts +15 -15
- package/plugins/acryl-router/src/core/middleware/request-id/request-id.ts +3 -3
- package/plugins/acryl-router/src/core/middleware/secure-headers/index.test.ts +35 -35
- package/plugins/acryl-router/src/core/middleware/secure-headers/secure-headers.ts +3 -3
- package/plugins/acryl-router/src/core/middleware/serve-static/index.test.ts +23 -23
- package/plugins/acryl-router/src/core/middleware/serve-static/index.ts +1 -1
- package/plugins/acryl-router/src/core/middleware/timeout/index.test.ts +2 -2
- package/plugins/acryl-router/src/core/middleware/timeout/index.ts +3 -3
- package/plugins/acryl-router/src/core/middleware/timing/index.test.ts +14 -14
- package/plugins/acryl-router/src/core/middleware/timing/timing.ts +3 -3
- package/plugins/acryl-router/src/core/middleware/trailing-slash/index.test.ts +7 -7
- package/plugins/acryl-router/src/core/middleware/trailing-slash/index.ts +7 -7
- package/plugins/acryl-router/src/core/request.test.ts +42 -42
- package/plugins/acryl-router/src/core/request.ts +6 -6
- package/plugins/acryl-router/src/core/router/linear-router/index.ts +1 -1
- package/plugins/acryl-router/src/core/router/pattern-router/index.ts +1 -1
- package/plugins/acryl-router/src/core/router/reg-exp-router/index.ts +1 -1
- package/plugins/acryl-router/src/core/router/smart-router/index.ts +1 -1
- package/plugins/acryl-router/src/core/router/trie-router/index.ts +1 -1
- package/plugins/acryl-router/src/core/types.test.ts +115 -115
- package/plugins/acryl-router/src/core/types.ts +72 -72
- package/plugins/acryl-router/src/core/utils/body.ts +8 -8
- package/plugins/acryl-router/src/core/utils/html.ts +1 -1
- package/plugins/acryl-router/src/core/utils/jwt/jws.ts +3 -3
- package/plugins/acryl-router/src/core/utils/jwt/jwt.test.ts +2 -2
- package/plugins/acryl-router/src/core/utils/jwt/jwt.ts +3 -3
- package/plugins/acryl-router/src/core/utils/jwt/types.ts +1 -1
- package/plugins/acryl-router/src/core/utils/types.ts +42 -0
- package/plugins/acryl-router/src/core/utils/url.test.ts +2 -2
- package/plugins/acryl-router/src/core/validator/index.ts +1 -1
- package/plugins/acryl-router/src/core/validator/validator.test.ts +28 -28
- package/plugins/acryl-router/src/deprecated.ts +15 -0
- package/plugins/acryl-router/src/index.ts +3 -2
- package/plugins/acryl-router/src/service.ts +10 -10
- package/plugins/acryl-router/tests/docs-examples.spec.ts +11 -11
- package/plugins/acryl-router/tests/live-install.spec.ts +2 -2
- package/plugins/acryl-router/tests/loader.spec.ts +3 -3
- package/plugins/acryl-router/tests/loopback-only.spec.ts +4 -4
- package/plugins/acryl-router/tests/no-dom/consumer.ts +11 -0
- package/plugins/acryl-router/tests/no-dom/tsconfig.json +13 -0
- package/plugins/acryl-router/tests/service.spec.ts +23 -23
- package/plugins/acryl-router/upstream.json +3 -3
- package/plugins/acryl-router-http/tests/adapter.spec.ts +3 -3
- package/plugins/acryl-router-http/tests/surfaces.spec.ts +2 -2
- package/plugins/acryl-router-http/upstream.json +2 -2
- package/plugins/acryl-state/src/service.ts +2 -2
- package/plugins/acryl-state/upstream.json +2 -2
- package/plugins/builder/script.ts +2 -2
- package/plugins/extensions/resolve.ts +70 -10
- package/plugins/openai/prompt.ts +5 -5
- package/shared/AGENTS.core.md +16 -9
- package/templates/agent/src/routes.ts +2 -2
- package/templates/agent/test/model.test.ts +2 -2
- package/templates/agent/tsconfig.json +40 -0
- package/templates/blank/src/routes.ts +2 -2
- package/templates/todo/src/todo.ts +2 -2
- package/templates/todo/upstream.json +2 -2
- package/docs/framework/context.md +0 -129
- package/docs/framework/helpers.md +0 -118
- package/docs/framework/middleware.md +0 -154
- package/docs/framework/request.md +0 -106
- /package/docs/framework/{plugin-lifecycle.md → cordis/plugin-lifecycle.md} +0 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
//#region ../../plugins/acryl-router/src/core/utils/html.ts
|
|
2
|
+
/**
|
|
3
|
+
* @module
|
|
4
|
+
* HTML utility.
|
|
5
|
+
*/
|
|
6
|
+
const HtmlEscapedCallbackPhase = {
|
|
7
|
+
Stringify: 1,
|
|
8
|
+
BeforeStream: 2,
|
|
9
|
+
Stream: 3
|
|
10
|
+
};
|
|
11
|
+
const raw = (value, callbacks) => {
|
|
12
|
+
const escapedString = new String(value);
|
|
13
|
+
escapedString.isEscaped = true;
|
|
14
|
+
escapedString.callbacks = callbacks;
|
|
15
|
+
return escapedString;
|
|
16
|
+
};
|
|
17
|
+
const escapeRe = /[&<>'"]/;
|
|
18
|
+
const stringBufferToString = async (buffer, callbacks) => {
|
|
19
|
+
let str = "";
|
|
20
|
+
callbacks ||= [];
|
|
21
|
+
const resolvedBuffer = await Promise.all(buffer);
|
|
22
|
+
for (let i = resolvedBuffer.length - 1;; i--) {
|
|
23
|
+
str += resolvedBuffer[i];
|
|
24
|
+
i--;
|
|
25
|
+
if (i < 0) break;
|
|
26
|
+
let r = resolvedBuffer[i];
|
|
27
|
+
if (typeof r === "object") callbacks.push(...r.callbacks || []);
|
|
28
|
+
const isEscaped = r.isEscaped;
|
|
29
|
+
r = await (typeof r === "object" ? r.toString() : r);
|
|
30
|
+
if (typeof r === "object") callbacks.push(...r.callbacks || []);
|
|
31
|
+
if (r.isEscaped ?? isEscaped) str += r;
|
|
32
|
+
else {
|
|
33
|
+
const buf = [str];
|
|
34
|
+
escapeToBuffer(r, buf);
|
|
35
|
+
str = buf[0];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return raw(str, callbacks);
|
|
39
|
+
};
|
|
40
|
+
const escapeToBuffer = (str, buffer) => {
|
|
41
|
+
const match = str.search(escapeRe);
|
|
42
|
+
if (match === -1) {
|
|
43
|
+
buffer[0] += str;
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
let escape;
|
|
47
|
+
let index;
|
|
48
|
+
let lastIndex = 0;
|
|
49
|
+
for (index = match; index < str.length; index++) {
|
|
50
|
+
switch (str.charCodeAt(index)) {
|
|
51
|
+
case 34:
|
|
52
|
+
escape = """;
|
|
53
|
+
break;
|
|
54
|
+
case 39:
|
|
55
|
+
escape = "'";
|
|
56
|
+
break;
|
|
57
|
+
case 38:
|
|
58
|
+
escape = "&";
|
|
59
|
+
break;
|
|
60
|
+
case 60:
|
|
61
|
+
escape = "<";
|
|
62
|
+
break;
|
|
63
|
+
case 62:
|
|
64
|
+
escape = ">";
|
|
65
|
+
break;
|
|
66
|
+
default: continue;
|
|
67
|
+
}
|
|
68
|
+
buffer[0] += str.substring(lastIndex, index) + escape;
|
|
69
|
+
lastIndex = index + 1;
|
|
70
|
+
}
|
|
71
|
+
buffer[0] += str.substring(lastIndex, index);
|
|
72
|
+
};
|
|
73
|
+
const resolveCallbackSync = (str) => {
|
|
74
|
+
const callbacks = str.callbacks;
|
|
75
|
+
if (!callbacks?.length) return str;
|
|
76
|
+
const buffer = [str];
|
|
77
|
+
const context = {};
|
|
78
|
+
callbacks.forEach((c) => c({
|
|
79
|
+
phase: HtmlEscapedCallbackPhase.Stringify,
|
|
80
|
+
buffer,
|
|
81
|
+
context
|
|
82
|
+
}));
|
|
83
|
+
return buffer[0];
|
|
84
|
+
};
|
|
85
|
+
const resolveCallback = async (str, phase, preserveCallbacks, context, buffer) => {
|
|
86
|
+
if (typeof str === "object" && !(str instanceof String)) {
|
|
87
|
+
if (!(str instanceof Promise)) str = str.toString();
|
|
88
|
+
if (str instanceof Promise) str = await str;
|
|
89
|
+
}
|
|
90
|
+
const callbacks = str.callbacks;
|
|
91
|
+
if (!callbacks?.length) return Promise.resolve(str);
|
|
92
|
+
if (buffer) buffer[0] += str;
|
|
93
|
+
else buffer = [str];
|
|
94
|
+
const resStr = Promise.all(callbacks.map((c) => c({
|
|
95
|
+
phase,
|
|
96
|
+
buffer,
|
|
97
|
+
context
|
|
98
|
+
}))).then((res) => Promise.all(res.filter(Boolean).map((str) => resolveCallback(str, phase, false, context, buffer))).then(() => buffer[0]));
|
|
99
|
+
if (preserveCallbacks) return raw(await resStr, callbacks);
|
|
100
|
+
else return resStr;
|
|
101
|
+
};
|
|
102
|
+
//#endregion
|
|
103
|
+
export { HtmlEscapedCallbackPhase, escapeToBuffer, raw, resolveCallback, resolveCallbackSync, stringBufferToString };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as InfoStatusCode, c as StatusCode, d as UnofficialStatusCode, i as DeprecatedStatusCode, l as SuccessStatusCode, n as ContentfulStatusCode, o as RedirectStatusCode, r as ContentlessStatusCode, s as ServerErrorStatusCode, t as ClientErrorStatusCode, u as UnOfficalStatusCode } from "../http-status-DaAwGAFL.js";
|
|
2
|
+
export { ClientErrorStatusCode, ContentfulStatusCode, ContentlessStatusCode, DeprecatedStatusCode, InfoStatusCode, RedirectStatusCode, ServerErrorStatusCode, StatusCode, SuccessStatusCode, UnOfficalStatusCode, UnofficialStatusCode };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { t as AddressType } from "../types-CDO6I3B0.js";
|
|
2
|
+
|
|
3
|
+
//#region ../../plugins/acryl-router/src/core/utils/ipaddr.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Expand IPv6 Address
|
|
6
|
+
* @param ipV6 Shorten IPv6 Address
|
|
7
|
+
* @return expanded IPv6 Address
|
|
8
|
+
*/
|
|
9
|
+
declare const expandIPv6: (ipV6: string) => string;
|
|
10
|
+
declare const INVALID_IP_ADDRESS_ERROR_CODE = "ERR_INVALID_IP_ADDRESS";
|
|
11
|
+
type InvalidIPAddressError = TypeError & {
|
|
12
|
+
code: typeof INVALID_IP_ADDRESS_ERROR_CODE;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Distinct Remote Addr
|
|
16
|
+
* @param remoteAddr Remote Addr
|
|
17
|
+
*/
|
|
18
|
+
declare const distinctRemoteAddr: (remoteAddr: string) => AddressType;
|
|
19
|
+
/**
|
|
20
|
+
* Convert IPv4 to Uint8Array
|
|
21
|
+
* @param ipv4 IPv4 Address
|
|
22
|
+
* @returns BigInt
|
|
23
|
+
*/
|
|
24
|
+
declare const convertIPv4ToBinary: (ipv4: string) => bigint;
|
|
25
|
+
/**
|
|
26
|
+
* Convert IPv6 to Uint8Array
|
|
27
|
+
* @param ipv6 IPv6 Address
|
|
28
|
+
* @returns BigInt
|
|
29
|
+
*/
|
|
30
|
+
declare const convertIPv6ToBinary: (ipv6: string) => bigint;
|
|
31
|
+
/**
|
|
32
|
+
* Convert a binary representation of an IPv4 address to a string.
|
|
33
|
+
* @param ipV4 binary IPv4 Address
|
|
34
|
+
* @return IPv4 Address in string
|
|
35
|
+
*/
|
|
36
|
+
declare const convertIPv4BinaryToString: (ipV4: bigint) => string;
|
|
37
|
+
/**
|
|
38
|
+
* Check if a binary IPv6 address is an IPv4-mapped IPv6 address (::ffff:x.x.x.x)
|
|
39
|
+
* @param ipv6binary binary IPv6 Address
|
|
40
|
+
* @return true if the address is an IPv4-mapped IPv6 address
|
|
41
|
+
*/
|
|
42
|
+
declare const isIPv4MappedIPv6: (ipv6binary: bigint) => boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Extract the IPv4 portion from an IPv4-mapped IPv6 address
|
|
45
|
+
* @param ipv6binary binary IPv4-mapped IPv6 Address
|
|
46
|
+
* @return binary IPv4 Address
|
|
47
|
+
*/
|
|
48
|
+
declare const convertIPv4MappedIPv6ToIPv4: (ipv6binary: bigint) => bigint;
|
|
49
|
+
/**
|
|
50
|
+
* Convert a binary representation of an IPv6 address to a string.
|
|
51
|
+
* @param ipV6 binary IPv6 Address
|
|
52
|
+
* @return normalized IPv6 Address in string
|
|
53
|
+
*/
|
|
54
|
+
declare const convertIPv6BinaryToString: (ipV6: bigint) => string;
|
|
55
|
+
//#endregion
|
|
56
|
+
export { INVALID_IP_ADDRESS_ERROR_CODE, InvalidIPAddressError, convertIPv4BinaryToString, convertIPv4MappedIPv6ToIPv4, convertIPv4ToBinary, convertIPv6BinaryToString, convertIPv6ToBinary, distinctRemoteAddr, expandIPv6, isIPv4MappedIPv6 };
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
//#region ../../plugins/acryl-router/src/core/utils/ipaddr.ts
|
|
2
|
+
/**
|
|
3
|
+
* Expand IPv6 Address
|
|
4
|
+
* @param ipV6 Shorten IPv6 Address
|
|
5
|
+
* @return expanded IPv6 Address
|
|
6
|
+
*/
|
|
7
|
+
const expandIPv6 = (ipV6) => {
|
|
8
|
+
const sections = ipV6.split(":");
|
|
9
|
+
const lastSection = sections.at(-1);
|
|
10
|
+
if (IPV4_REGEX.test(lastSection)) {
|
|
11
|
+
const octets = lastSection.split(".").map(Number);
|
|
12
|
+
sections.splice(-1, 1, (octets[0] << 8 | octets[1]).toString(16), (octets[2] << 8 | octets[3]).toString(16));
|
|
13
|
+
}
|
|
14
|
+
for (let i = 0; i < sections.length; i++) {
|
|
15
|
+
const node = sections[i];
|
|
16
|
+
if (node !== "") sections[i] = node.padStart(4, "0");
|
|
17
|
+
else {
|
|
18
|
+
while (sections[i + 1] === "") sections.splice(i + 1, 1);
|
|
19
|
+
sections[i] = new Array(8 - sections.length + 1).fill("0000").join(":");
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return sections.join(":");
|
|
23
|
+
};
|
|
24
|
+
const IPV4_OCTET_PART = "(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])";
|
|
25
|
+
const IPV4_REGEX = new RegExp(`^(?:${IPV4_OCTET_PART}\\.){3}${IPV4_OCTET_PART}$`);
|
|
26
|
+
const INVALID_IP_ADDRESS_ERROR_CODE = "ERR_INVALID_IP_ADDRESS";
|
|
27
|
+
const CHAR_CODE_0 = 48;
|
|
28
|
+
const CHAR_CODE_9 = 57;
|
|
29
|
+
const CHAR_CODE_A = 65;
|
|
30
|
+
const CHAR_CODE_F = 70;
|
|
31
|
+
const CHAR_CODE_a = 97;
|
|
32
|
+
const CHAR_CODE_f = 102;
|
|
33
|
+
const CHAR_CODE_DOT = 46;
|
|
34
|
+
const CHAR_CODE_COLON = 58;
|
|
35
|
+
const CHAR_CODE_PERCENT = 37;
|
|
36
|
+
/**
|
|
37
|
+
* Distinct Remote Addr
|
|
38
|
+
* @param remoteAddr Remote Addr
|
|
39
|
+
*/
|
|
40
|
+
const distinctRemoteAddr = (remoteAddr) => {
|
|
41
|
+
if (IPV4_REGEX.test(remoteAddr)) return "IPv4";
|
|
42
|
+
if (remoteAddr.includes(":")) return "IPv6";
|
|
43
|
+
};
|
|
44
|
+
const createInvalidIPAddressError = (message) => {
|
|
45
|
+
const error = new TypeError(message);
|
|
46
|
+
error.code = INVALID_IP_ADDRESS_ERROR_CODE;
|
|
47
|
+
return error;
|
|
48
|
+
};
|
|
49
|
+
const throwInvalidIPv4Address = (ipv4) => {
|
|
50
|
+
throw createInvalidIPAddressError(`Invalid IPv4 address: ${ipv4}`);
|
|
51
|
+
};
|
|
52
|
+
const throwInvalidIPv6Address = (ipv6) => {
|
|
53
|
+
throw createInvalidIPAddressError(`Invalid IPv6 address: ${ipv6}`);
|
|
54
|
+
};
|
|
55
|
+
const parseIPv4ToBinary = (ipv4, start, end, onInvalid) => {
|
|
56
|
+
let result = 0n;
|
|
57
|
+
let octets = 0;
|
|
58
|
+
let octet = 0;
|
|
59
|
+
let digits = 0;
|
|
60
|
+
let firstDigit = 0;
|
|
61
|
+
for (let i = start; i <= end; i++) {
|
|
62
|
+
const code = i < end ? ipv4.charCodeAt(i) : CHAR_CODE_DOT;
|
|
63
|
+
if (code >= CHAR_CODE_0 && code <= CHAR_CODE_9) {
|
|
64
|
+
if (digits === 0) firstDigit = code;
|
|
65
|
+
else if (firstDigit === CHAR_CODE_0) onInvalid();
|
|
66
|
+
octet = octet * 10 + code - CHAR_CODE_0;
|
|
67
|
+
if (octet > 255) onInvalid();
|
|
68
|
+
digits++;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (code !== CHAR_CODE_DOT || digits === 0 || octets === 4) onInvalid();
|
|
72
|
+
result = (result << 8n) + BigInt(octet);
|
|
73
|
+
octets++;
|
|
74
|
+
octet = 0;
|
|
75
|
+
digits = 0;
|
|
76
|
+
}
|
|
77
|
+
if (octets !== 4) onInvalid();
|
|
78
|
+
return result;
|
|
79
|
+
};
|
|
80
|
+
const parseIPv6HexCode = (code) => {
|
|
81
|
+
if (code >= CHAR_CODE_0 && code <= CHAR_CODE_9) return code - CHAR_CODE_0;
|
|
82
|
+
if (code >= CHAR_CODE_A && code <= CHAR_CODE_F) return code - CHAR_CODE_A + 10;
|
|
83
|
+
if (code >= CHAR_CODE_a && code <= CHAR_CODE_f) return code - CHAR_CODE_a + 10;
|
|
84
|
+
return -1;
|
|
85
|
+
};
|
|
86
|
+
const isIPv6LinkLocal = (ipv6binary) => ipv6binary >> 118n === 1018n;
|
|
87
|
+
/**
|
|
88
|
+
* Convert IPv4 to Uint8Array
|
|
89
|
+
* @param ipv4 IPv4 Address
|
|
90
|
+
* @returns BigInt
|
|
91
|
+
*/
|
|
92
|
+
const convertIPv4ToBinary = (ipv4) => {
|
|
93
|
+
return parseIPv4ToBinary(ipv4, 0, ipv4.length, () => throwInvalidIPv4Address(ipv4));
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Convert IPv6 to Uint8Array
|
|
97
|
+
* @param ipv6 IPv6 Address
|
|
98
|
+
* @returns BigInt
|
|
99
|
+
*/
|
|
100
|
+
const convertIPv6ToBinary = (ipv6) => {
|
|
101
|
+
const length = ipv6.length;
|
|
102
|
+
const sections = [];
|
|
103
|
+
let hasZoneId = false;
|
|
104
|
+
let compressAt = -1;
|
|
105
|
+
let index = 0;
|
|
106
|
+
if (length === 0) throwInvalidIPv6Address(ipv6);
|
|
107
|
+
while (index < length) {
|
|
108
|
+
if (sections.length > 8) throwInvalidIPv6Address(ipv6);
|
|
109
|
+
let code = ipv6.charCodeAt(index);
|
|
110
|
+
if (code === CHAR_CODE_PERCENT) {
|
|
111
|
+
if (index + 1 === length) throwInvalidIPv6Address(ipv6);
|
|
112
|
+
hasZoneId = true;
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
if (code === CHAR_CODE_COLON) {
|
|
116
|
+
if (index + 1 < length && ipv6.charCodeAt(index + 1) === CHAR_CODE_COLON) {
|
|
117
|
+
if (compressAt !== -1) throwInvalidIPv6Address(ipv6);
|
|
118
|
+
compressAt = sections.length;
|
|
119
|
+
index += 2;
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
throwInvalidIPv6Address(ipv6);
|
|
123
|
+
}
|
|
124
|
+
let value = 0;
|
|
125
|
+
let digits = 0;
|
|
126
|
+
const sectionStart = index;
|
|
127
|
+
while (index < length) {
|
|
128
|
+
code = ipv6.charCodeAt(index);
|
|
129
|
+
const hex = parseIPv6HexCode(code);
|
|
130
|
+
if (hex === -1) break;
|
|
131
|
+
if (digits === 4) throwInvalidIPv6Address(ipv6);
|
|
132
|
+
value = value << 4 | hex;
|
|
133
|
+
digits++;
|
|
134
|
+
index++;
|
|
135
|
+
}
|
|
136
|
+
if (index < length && ipv6.charCodeAt(index) === CHAR_CODE_DOT) {
|
|
137
|
+
let ipv4End = length;
|
|
138
|
+
for (let i = index; i < length; i++) if (ipv6.charCodeAt(i) === CHAR_CODE_PERCENT) {
|
|
139
|
+
if (i + 1 === length) throwInvalidIPv6Address(ipv6);
|
|
140
|
+
hasZoneId = true;
|
|
141
|
+
ipv4End = i;
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
const ipv4 = parseIPv4ToBinary(ipv6, sectionStart, ipv4End, () => throwInvalidIPv6Address(ipv6));
|
|
145
|
+
sections.push(Number(ipv4 >> 16n & 65535n), Number(ipv4 & 65535n));
|
|
146
|
+
index = length;
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
if (digits === 0) throwInvalidIPv6Address(ipv6);
|
|
150
|
+
sections.push(value);
|
|
151
|
+
if (index === length) break;
|
|
152
|
+
code = ipv6.charCodeAt(index);
|
|
153
|
+
if (code === CHAR_CODE_PERCENT) {
|
|
154
|
+
if (index + 1 === length) throwInvalidIPv6Address(ipv6);
|
|
155
|
+
hasZoneId = true;
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
if (code !== CHAR_CODE_COLON) throwInvalidIPv6Address(ipv6);
|
|
159
|
+
if (index + 1 < length && ipv6.charCodeAt(index + 1) === CHAR_CODE_COLON) {
|
|
160
|
+
if (compressAt !== -1) throwInvalidIPv6Address(ipv6);
|
|
161
|
+
compressAt = sections.length;
|
|
162
|
+
index += 2;
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
index++;
|
|
166
|
+
if (index === length) throwInvalidIPv6Address(ipv6);
|
|
167
|
+
}
|
|
168
|
+
if (compressAt === -1 ? sections.length !== 8 : sections.length >= 8) throwInvalidIPv6Address(ipv6);
|
|
169
|
+
let result = 0n;
|
|
170
|
+
const zeros = compressAt === -1 ? 0 : 8 - sections.length;
|
|
171
|
+
const firstSectionEnd = compressAt === -1 ? sections.length : compressAt;
|
|
172
|
+
for (let i = 0; i < firstSectionEnd; i++) {
|
|
173
|
+
result <<= 16n;
|
|
174
|
+
result += BigInt(sections[i]);
|
|
175
|
+
}
|
|
176
|
+
for (let i = 0; i < zeros; i++) result <<= 16n;
|
|
177
|
+
for (let i = firstSectionEnd; i < sections.length; i++) {
|
|
178
|
+
result <<= 16n;
|
|
179
|
+
result += BigInt(sections[i]);
|
|
180
|
+
}
|
|
181
|
+
if (hasZoneId && !isIPv6LinkLocal(result)) throwInvalidIPv6Address(ipv6);
|
|
182
|
+
return result;
|
|
183
|
+
};
|
|
184
|
+
/**
|
|
185
|
+
* Convert a binary representation of an IPv4 address to a string.
|
|
186
|
+
* @param ipV4 binary IPv4 Address
|
|
187
|
+
* @return IPv4 Address in string
|
|
188
|
+
*/
|
|
189
|
+
const convertIPv4BinaryToString = (ipV4) => {
|
|
190
|
+
const sections = [];
|
|
191
|
+
for (let i = 0; i < 4; i++) sections.push(ipV4 >> BigInt(8 * (3 - i)) & 255n);
|
|
192
|
+
return sections.join(".");
|
|
193
|
+
};
|
|
194
|
+
/**
|
|
195
|
+
* Check if a binary IPv6 address is an IPv4-mapped IPv6 address (::ffff:x.x.x.x)
|
|
196
|
+
* @param ipv6binary binary IPv6 Address
|
|
197
|
+
* @return true if the address is an IPv4-mapped IPv6 address
|
|
198
|
+
*/
|
|
199
|
+
const isIPv4MappedIPv6 = (ipv6binary) => ipv6binary >> 32n === 65535n;
|
|
200
|
+
/**
|
|
201
|
+
* Extract the IPv4 portion from an IPv4-mapped IPv6 address
|
|
202
|
+
* @param ipv6binary binary IPv4-mapped IPv6 Address
|
|
203
|
+
* @return binary IPv4 Address
|
|
204
|
+
*/
|
|
205
|
+
const convertIPv4MappedIPv6ToIPv4 = (ipv6binary) => ipv6binary & 4294967295n;
|
|
206
|
+
/**
|
|
207
|
+
* Convert a binary representation of an IPv6 address to a string.
|
|
208
|
+
* @param ipV6 binary IPv6 Address
|
|
209
|
+
* @return normalized IPv6 Address in string
|
|
210
|
+
*/
|
|
211
|
+
const convertIPv6BinaryToString = (ipV6) => {
|
|
212
|
+
if (ipV6 === 0n) return "::";
|
|
213
|
+
if (isIPv4MappedIPv6(ipV6)) return `::ffff:${convertIPv4BinaryToString(convertIPv4MappedIPv6ToIPv4(ipV6))}`;
|
|
214
|
+
const sections = [];
|
|
215
|
+
for (let i = 0; i < 8; i++) sections.push((ipV6 >> BigInt(16 * (7 - i)) & 65535n).toString(16));
|
|
216
|
+
let currentZeroStart = -1;
|
|
217
|
+
let maxZeroStart = -1;
|
|
218
|
+
let maxZeroEnd = -1;
|
|
219
|
+
for (let i = 0; i < 8; i++) if (sections[i] === "0") {
|
|
220
|
+
if (currentZeroStart === -1) currentZeroStart = i;
|
|
221
|
+
} else if (currentZeroStart > -1) {
|
|
222
|
+
if (i - currentZeroStart > maxZeroEnd - maxZeroStart) {
|
|
223
|
+
maxZeroStart = currentZeroStart;
|
|
224
|
+
maxZeroEnd = i;
|
|
225
|
+
}
|
|
226
|
+
currentZeroStart = -1;
|
|
227
|
+
}
|
|
228
|
+
if (currentZeroStart > -1) {
|
|
229
|
+
if (8 - currentZeroStart > maxZeroEnd - maxZeroStart) {
|
|
230
|
+
maxZeroStart = currentZeroStart;
|
|
231
|
+
maxZeroEnd = 8;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
if (maxZeroStart !== -1 && maxZeroEnd - maxZeroStart > 1) sections.splice(maxZeroStart, maxZeroEnd - maxZeroStart, ":");
|
|
235
|
+
return sections.join(":").replace(/:{2,}/g, "::");
|
|
236
|
+
};
|
|
237
|
+
//#endregion
|
|
238
|
+
export { INVALID_IP_ADDRESS_ERROR_CODE, convertIPv4BinaryToString, convertIPv4MappedIPv6ToIPv4, convertIPv4ToBinary, convertIPv6BinaryToString, convertIPv6ToBinary, distinctRemoteAddr, expandIPv6, isIPv4MappedIPv6 };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { a as SignatureKey, c as SignatureAlgorithm, i as AcrylJsonWebKey, n as VerifyOptions, r as VerifyOptionsWithAlg, s as AsymmetricAlgorithm, t as TokenHeader } from "../jwt-Dg493Tai.js";
|
|
2
|
+
import { t as JWTPayload } from "../types-DR95J00T.js";
|
|
3
|
+
|
|
4
|
+
//#region ../../plugins/acryl-router/src/core/utils/jwt/index.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* @module
|
|
7
|
+
* JWT utility.
|
|
8
|
+
*/
|
|
9
|
+
declare const Jwt: {
|
|
10
|
+
sign: (payload: JWTPayload, privateKey: SignatureKey, alg?: SignatureAlgorithm) => Promise<string>;
|
|
11
|
+
verify: (token: string, publicKey: SignatureKey, algOrOptions: SignatureAlgorithm | VerifyOptionsWithAlg) => Promise<JWTPayload>;
|
|
12
|
+
decode: (token: string) => {
|
|
13
|
+
header: TokenHeader;
|
|
14
|
+
payload: JWTPayload;
|
|
15
|
+
};
|
|
16
|
+
verifyWithJwks: (token: string, options: {
|
|
17
|
+
keys?: AcrylJsonWebKey[];
|
|
18
|
+
jwks_uri?: string;
|
|
19
|
+
verification?: VerifyOptions;
|
|
20
|
+
allowedAlgorithms: readonly AsymmetricAlgorithm[];
|
|
21
|
+
}, init?: RequestInit) => Promise<JWTPayload>;
|
|
22
|
+
};
|
|
23
|
+
//#endregion
|
|
24
|
+
export { Jwt };
|
package/lib/utils/jwt.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
//#region ../../plugins/acryl-router/src/core/utils/mime.ts
|
|
2
|
+
/**
|
|
3
|
+
* @module
|
|
4
|
+
* MIME utility.
|
|
5
|
+
*/
|
|
6
|
+
const getMimeType = (filename, mimes = baseMimes) => {
|
|
7
|
+
const match = filename.match(/\.([a-zA-Z0-9]+?)$/);
|
|
8
|
+
if (!match) return;
|
|
9
|
+
return mimes[match[1].toLowerCase()];
|
|
10
|
+
};
|
|
11
|
+
const getExtension = (mimeType) => {
|
|
12
|
+
const baseType = mimeType.split(";", 1)[0].trim();
|
|
13
|
+
for (const ext in baseMimes) {
|
|
14
|
+
const stored = baseMimes[ext];
|
|
15
|
+
if (stored === mimeType || stored.split(";", 1)[0].trim() === baseType) return ext;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
const baseMimes = {
|
|
19
|
+
aac: "audio/aac",
|
|
20
|
+
avi: "video/x-msvideo",
|
|
21
|
+
avif: "image/avif",
|
|
22
|
+
av1: "video/av1",
|
|
23
|
+
bin: "application/octet-stream",
|
|
24
|
+
bmp: "image/bmp",
|
|
25
|
+
css: "text/css; charset=utf-8",
|
|
26
|
+
csv: "text/csv; charset=utf-8",
|
|
27
|
+
eot: "application/vnd.ms-fontobject",
|
|
28
|
+
epub: "application/epub+zip",
|
|
29
|
+
gif: "image/gif",
|
|
30
|
+
gz: "application/gzip",
|
|
31
|
+
htm: "text/html; charset=utf-8",
|
|
32
|
+
html: "text/html; charset=utf-8",
|
|
33
|
+
ico: "image/x-icon",
|
|
34
|
+
ics: "text/calendar; charset=utf-8",
|
|
35
|
+
jpeg: "image/jpeg",
|
|
36
|
+
jpg: "image/jpeg",
|
|
37
|
+
js: "text/javascript; charset=utf-8",
|
|
38
|
+
json: "application/json",
|
|
39
|
+
jsonld: "application/ld+json",
|
|
40
|
+
map: "application/json",
|
|
41
|
+
mid: "audio/x-midi",
|
|
42
|
+
midi: "audio/x-midi",
|
|
43
|
+
mjs: "text/javascript; charset=utf-8",
|
|
44
|
+
mp3: "audio/mpeg",
|
|
45
|
+
mp4: "video/mp4",
|
|
46
|
+
mpeg: "video/mpeg",
|
|
47
|
+
oga: "audio/ogg",
|
|
48
|
+
ogv: "video/ogg",
|
|
49
|
+
ogx: "application/ogg",
|
|
50
|
+
opus: "audio/opus",
|
|
51
|
+
otf: "font/otf",
|
|
52
|
+
pdf: "application/pdf",
|
|
53
|
+
png: "image/png",
|
|
54
|
+
rtf: "application/rtf",
|
|
55
|
+
svg: "image/svg+xml; charset=utf-8",
|
|
56
|
+
tif: "image/tiff",
|
|
57
|
+
tiff: "image/tiff",
|
|
58
|
+
ts: "video/mp2t",
|
|
59
|
+
ttf: "font/ttf",
|
|
60
|
+
txt: "text/plain; charset=utf-8",
|
|
61
|
+
wasm: "application/wasm",
|
|
62
|
+
webm: "video/webm",
|
|
63
|
+
weba: "audio/webm",
|
|
64
|
+
webmanifest: "application/manifest+json",
|
|
65
|
+
webp: "image/webp",
|
|
66
|
+
woff: "font/woff",
|
|
67
|
+
woff2: "font/woff2",
|
|
68
|
+
xhtml: "application/xhtml+xml; charset=utf-8",
|
|
69
|
+
xml: "application/xml; charset=utf-8",
|
|
70
|
+
zip: "application/zip",
|
|
71
|
+
"3gp": "video/3gpp",
|
|
72
|
+
"3g2": "video/3gpp2",
|
|
73
|
+
gltf: "model/gltf+json",
|
|
74
|
+
glb: "model/gltf-binary"
|
|
75
|
+
};
|
|
76
|
+
//#endregion
|
|
77
|
+
export { getExtension, getMimeType, baseMimes as mimes };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
//#region ../../plugins/acryl-router/src/core/utils/stream.ts
|
|
2
|
+
/**
|
|
3
|
+
* @module
|
|
4
|
+
* Stream utility.
|
|
5
|
+
*/
|
|
6
|
+
var StreamingApi = class {
|
|
7
|
+
writer;
|
|
8
|
+
encoder;
|
|
9
|
+
writable;
|
|
10
|
+
abortSubscribers = [];
|
|
11
|
+
responseReadable;
|
|
12
|
+
/**
|
|
13
|
+
* Whether the stream has been aborted.
|
|
14
|
+
*/
|
|
15
|
+
aborted = false;
|
|
16
|
+
/**
|
|
17
|
+
* Whether the stream has been closed normally.
|
|
18
|
+
*/
|
|
19
|
+
closed = false;
|
|
20
|
+
constructor(writable, _readable) {
|
|
21
|
+
this.writable = writable;
|
|
22
|
+
this.writer = writable.getWriter();
|
|
23
|
+
this.encoder = new TextEncoder();
|
|
24
|
+
const reader = _readable.getReader();
|
|
25
|
+
this.abortSubscribers.push(async () => {
|
|
26
|
+
await reader.cancel();
|
|
27
|
+
});
|
|
28
|
+
this.responseReadable = new ReadableStream({
|
|
29
|
+
async pull(controller) {
|
|
30
|
+
const { done, value } = await reader.read();
|
|
31
|
+
done ? controller.close() : controller.enqueue(value);
|
|
32
|
+
},
|
|
33
|
+
cancel: () => {
|
|
34
|
+
if (!this.closed) this.abort();
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
async write(input) {
|
|
39
|
+
try {
|
|
40
|
+
if (typeof input === "string") input = this.encoder.encode(input);
|
|
41
|
+
await this.writer.write(input);
|
|
42
|
+
} catch {}
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
async writeln(input) {
|
|
46
|
+
await this.write(input + "\n");
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
sleep(ms) {
|
|
50
|
+
return new Promise((res) => setTimeout(res, ms));
|
|
51
|
+
}
|
|
52
|
+
async close() {
|
|
53
|
+
this.closed = true;
|
|
54
|
+
try {
|
|
55
|
+
await this.writer.close();
|
|
56
|
+
} catch {}
|
|
57
|
+
}
|
|
58
|
+
async pipe(body) {
|
|
59
|
+
this.writer.releaseLock();
|
|
60
|
+
try {
|
|
61
|
+
await body.pipeTo(this.writable, {
|
|
62
|
+
preventClose: true,
|
|
63
|
+
preventAbort: true
|
|
64
|
+
});
|
|
65
|
+
} finally {
|
|
66
|
+
this.writer = this.writable.getWriter();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
onAbort(listener) {
|
|
70
|
+
this.abortSubscribers.push(listener);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Abort the stream.
|
|
74
|
+
* You can call this method when stream is aborted by external event.
|
|
75
|
+
*/
|
|
76
|
+
abort() {
|
|
77
|
+
if (!this.aborted) {
|
|
78
|
+
this.aborted = true;
|
|
79
|
+
this.abortSubscribers.forEach((subscriber) => {
|
|
80
|
+
try {
|
|
81
|
+
Promise.resolve(subscriber()).catch(() => {});
|
|
82
|
+
} catch {}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
//#endregion
|
|
88
|
+
export { StreamingApi };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { C as SimplifyDeepArray, S as Simplify, T as UnionToIntersection, _ as JsonWebKey, a as Equal, b as RemoveBlankRecord, c as IfAnyThenEmptyObject, d as IsAny, f as JSONArray, g as JSONValue, h as JSONPrimitive, i as CryptoKey, l as InterfaceToType, m as JSONParsed, n as BufferSource, o as Expect, p as JSONObject, r as CloseEvent, s as HasRequiredKeys, t as BinaryType, u as InvalidJSONValue, v as MessageEvent, w as StringLiteralUnion, x as RequiredKeysOf, y as NotEqual } from "../types-CwrQjlaM.js";
|
|
2
|
+
export { BinaryType, BufferSource, CloseEvent, CryptoKey, Equal, Expect, HasRequiredKeys, IfAnyThenEmptyObject, InterfaceToType, InvalidJSONValue, IsAny, JSONArray, JSONObject, JSONParsed, JSONPrimitive, JSONValue, JsonWebKey, MessageEvent, NotEqual, RemoveBlankRecord, RequiredKeysOf, Simplify, SimplifyDeepArray, StringLiteralUnion, UnionToIntersection };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
//#region ../../plugins/acryl-router/src/core/utils/url.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* @module
|
|
4
|
+
* URL utility.
|
|
5
|
+
*/
|
|
6
|
+
type Pattern = readonly [string, string, RegExp | true] | '*';
|
|
7
|
+
declare const splitPath: (path: string) => string[];
|
|
8
|
+
declare const splitRoutingPath: (routePath: string) => string[];
|
|
9
|
+
declare const getPattern: (label: string, next?: string) => Pattern | null;
|
|
10
|
+
type Decoder = (str: string) => string;
|
|
11
|
+
declare const tryDecode: (str: string, decoder: Decoder) => string;
|
|
12
|
+
/**
|
|
13
|
+
* Try to apply decodeURI() to given string.
|
|
14
|
+
* If it fails, skip invalid percent encoding or invalid UTF-8 sequences, and apply decodeURI() to the rest as much as possible.
|
|
15
|
+
* @param str The string to decode.
|
|
16
|
+
* @returns The decoded string that sometimes contains undecodable percent encoding.
|
|
17
|
+
* @example
|
|
18
|
+
* tryDecodeURI('Hello%20World') // 'Hello World'
|
|
19
|
+
* tryDecodeURI('Hello%20World/%A4%A2') // 'Hello World/%A4%A2'
|
|
20
|
+
*/
|
|
21
|
+
declare const tryDecodeURI: (str: string) => string;
|
|
22
|
+
declare const getPath: (request: Request) => string;
|
|
23
|
+
/**
|
|
24
|
+
* @deprecated
|
|
25
|
+
* Use the `URL` API instead.
|
|
26
|
+
*/
|
|
27
|
+
declare const getQueryStrings: (url: string) => string;
|
|
28
|
+
declare const getPathNoStrict: (request: Request) => string;
|
|
29
|
+
/**
|
|
30
|
+
* Merge paths.
|
|
31
|
+
* @param {string[]} ...paths - The paths to merge.
|
|
32
|
+
* @returns {string} The merged path.
|
|
33
|
+
* @example
|
|
34
|
+
* mergePath('/api', '/users') // '/api/users'
|
|
35
|
+
* mergePath('/api/', '/users') // '/api/users'
|
|
36
|
+
* mergePath('/api', '/') // '/api'
|
|
37
|
+
* mergePath('/api/', '/') // '/api/'
|
|
38
|
+
*/
|
|
39
|
+
declare const mergePath: (...paths: string[]) => string;
|
|
40
|
+
declare const checkOptionalParameter: (path: string) => string[] | null;
|
|
41
|
+
declare const tryDecodeURIComponent: (str: string) => string;
|
|
42
|
+
declare const getQueryParam: (url: string, key?: string) => string | undefined | Record<string, string>;
|
|
43
|
+
declare const getQueryParams: (url: string, key?: string) => string[] | undefined | Record<string, string[]>;
|
|
44
|
+
declare const decodeURIComponent_: typeof decodeURIComponent;
|
|
45
|
+
//#endregion
|
|
46
|
+
export { Pattern, checkOptionalParameter, decodeURIComponent_, getPath, getPathNoStrict, getPattern, getQueryParam, getQueryParams, getQueryStrings, mergePath, splitPath, splitRoutingPath, tryDecode, tryDecodeURI, tryDecodeURIComponent };
|