Socket
Socket
Sign inDemoInstall

itty-router

Package Overview
Dependencies
0
Maintainers
2
Versions
264
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.1.0-next.1 to 4.1.0-next.2

2

flow.d.ts

@@ -1,2 +0,2 @@

import { RouterType, RouteHandler } from './Router';
import { RouteHandler, RouterType } from './Router';
import { CorsOptions } from './createCors';

@@ -3,0 +3,0 @@ export type FlowOptions = {

@@ -1,1 +0,1 @@

"use strict";const e=((e="text/plain; charset=utf-8",t)=>(o,s)=>{const{headers:r={},...n}=s||{};return"Response"===o?.constructor.name?o:new Response(t?t(o):o,{headers:{"content-type":e,...r},...n})})("application/json; charset=utf-8",JSON.stringify),t=e=>({400:"Bad Request",401:"Unauthorized",403:"Forbidden",404:"Not Found",500:"Internal Server Error"}[e]||"Unknown Error"),o=(o=500,s)=>{if(o instanceof Error){const{message:e,...r}=o;o=o.status||500,s={error:e||t(o),...r}}return s={status:o,..."object"==typeof s?s:{error:s||t(o)}},e(s,{status:o})};exports.flow=(t,s={})=>{const{format:r=e,error:n=o,cors:c,notFound:a=(()=>o(404))}=s;let i;return"function"==typeof a&&t.all("*",a),c&&(i=((e={})=>{const{origins:t=["*"],maxAge:o,methods:s=["GET"],headers:r={}}=e;let n;const c={"content-type":"application/json","Access-Control-Allow-Methods":s.join(", "),...r};return o&&(c["Access-Control-Max-Age"]=o),{corsify:e=>{if(!e)throw new Error("No fetch handler responded and no upstream to proxy to specified.");const{headers:t,status:o,body:s}=e;return[101,301,302,308].includes(o)||t.get("access-control-allow-origin")?e:new Response(s,{status:o,headers:{...Object.fromEntries(t),...c,...n,"content-type":t.get("content-type")}})},preflight:e=>{const o=[...new Set(["OPTIONS",...s])],r=e.headers.get("origin")||"";if(n=(t.includes(r)||t.includes("*"))&&{"Access-Control-Allow-Origin":r},"OPTIONS"===e.method){const t={...c,"Access-Control-Allow-Methods":o.join(", "),"Access-Control-Allow-Headers":e.headers.get("Access-Control-Request-Headers"),...n};return new Response(null,{headers:e.headers.get("Origin")&&e.headers.get("Access-Control-Request-Method")&&e.headers.get("Access-Control-Request-Headers")?t:{Allow:o.join(", ")}})}}}})(!0===c?void 0:c),t.routes.unshift(["ALL",/^(.*)?\/*$/,[i.preflight],"*"])),async(...e)=>{let o=t.handle(...e);return r&&(o=o.then(r)),n&&(o=o.catch(n)),c&&(o=o.then(i?.corsify)),o}};
"use strict";const e=((e="text/plain; charset=utf-8",t)=>(o,r)=>{const{headers:s={},...n}=r||{};return"Response"===o?.constructor.name?o:new Response(t?t(o):o,{headers:{"content-type":e,...s},...n})})("application/json; charset=utf-8",JSON.stringify),t=e=>({400:"Bad Request",401:"Unauthorized",403:"Forbidden",404:"Not Found",500:"Internal Server Error"}[e]||"Unknown Error"),o=(o=500,r)=>{if(o instanceof Error){const{message:e,...s}=o;o=o.status||500,r={error:e||t(o),...s}}return r={status:o,..."object"==typeof r?r:{error:r||t(o)}},e(r,{status:o})},r=e=>{e.proxy=new Proxy(e.proxy||e,{get:(t,o)=>{let r;return void 0!==(r=t[o])?r.bind?.(e)||r:t?.params?.[o]}})};exports.flow=(t,s={})=>{const{format:n=e,error:c=o,cors:a,notFound:i=(()=>o(404))}=s;let l;return"function"==typeof i&&t.all("*",i),a&&(l=((e={})=>{const{origins:t=["*"],maxAge:o,methods:r=["GET"],headers:s={}}=e;let n;const c={"content-type":"application/json","Access-Control-Allow-Methods":r.join(", "),...s};return o&&(c["Access-Control-Max-Age"]=o),{corsify:e=>{if(!e)throw new Error("No fetch handler responded and no upstream to proxy to specified.");const{headers:t,status:o,body:r}=e;return[101,301,302,308].includes(o)||t.get("access-control-allow-origin")?e:new Response(r,{status:o,headers:{...Object.fromEntries(t),...c,...n,"content-type":t.get("content-type")}})},preflight:e=>{const o=[...new Set(["OPTIONS",...r])],s=e.headers.get("origin")||"";if(n=(t.includes(s)||t.includes("*"))&&{"Access-Control-Allow-Origin":s},"OPTIONS"===e.method){const t={...c,"Access-Control-Allow-Methods":o.join(", "),"Access-Control-Allow-Headers":e.headers.get("Access-Control-Request-Headers"),...n};return new Response(null,{headers:e.headers.get("Origin")&&e.headers.get("Access-Control-Request-Method")&&e.headers.get("Access-Control-Request-Headers")?t:{Allow:o.join(", ")}})}}}})(!0===a?void 0:a),t.routes.unshift(["ALL",/^(.*)?\/*$/,[l.preflight,r],"*"])),async(...e)=>{let o=t.handle(...e);return n&&(o=o.then(n)),c&&(o=o.catch(c)),a&&(o=o.then(l?.corsify)),o}};

@@ -1,1 +0,1 @@

"use strict";const e=(e="text/plain; charset=utf-8",t)=>(o,r)=>{const{headers:s={},...n}=r||{};return"Response"===o?.constructor.name?o:new Response(t?t(o):o,{headers:{"content-type":e,...s},...n})},t=e("application/json; charset=utf-8",JSON.stringify),o=e=>({400:"Bad Request",401:"Unauthorized",403:"Forbidden",404:"Not Found",500:"Internal Server Error"}[e]||"Unknown Error"),r=(e=500,r)=>{if(e instanceof Error){const{message:t,...s}=e;e=e.status||500,r={error:t||o(e),...s}}return r={status:e,..."object"==typeof r?r:{error:r||o(e)}},t(r,{status:e})},s=(e={})=>{const{origins:t=["*"],maxAge:o,methods:r=["GET"],headers:s={}}=e;let n;const a={"content-type":"application/json","Access-Control-Allow-Methods":r.join(", "),...s};o&&(a["Access-Control-Max-Age"]=o);return{corsify:e=>{if(!e)throw new Error("No fetch handler responded and no upstream to proxy to specified.");const{headers:t,status:o,body:r}=e;return[101,301,302,308].includes(o)||t.get("access-control-allow-origin")?e:new Response(r,{status:o,headers:{...Object.fromEntries(t),...a,...n,"content-type":t.get("content-type")}})},preflight:e=>{const o=[...new Set(["OPTIONS",...r])],s=e.headers.get("origin")||"";if(n=(t.includes(s)||t.includes("*"))&&{"Access-Control-Allow-Origin":s},"OPTIONS"===e.method){const t={...a,"Access-Control-Allow-Methods":o.join(", "),"Access-Control-Allow-Headers":e.headers.get("Access-Control-Request-Headers"),...n};return new Response(null,{headers:e.headers.get("Origin")&&e.headers.get("Access-Control-Request-Method")&&e.headers.get("Access-Control-Request-Headers")?t:{Allow:o.join(", ")}})}}}};class n extends Error{status;constructor(e=500,t){super("object"==typeof t?t.error:t),"object"==typeof t&&Object.assign(this,t),this.status=e}}const a=e("text/html"),c=e("image/jpeg"),p=e("image/png"),i=e("image/webp");exports.Router=({base:e="",routes:t=[]}={})=>({__proto__:new Proxy({},{get:(o,r,s,n)=>(o,...a)=>t.push([r.toUpperCase(),RegExp(`^${(n=(e+o).replace(/\/+(\/|$)/g,"$1")).replace(/(\/?\.?):(\w+)\+/g,"($1(?<$2>*))").replace(/(\/?\.?):(\w+)/g,"($1(?<$2>[^$1/]+?))").replace(/\./g,"\\.").replace(/(\/?)\*/g,"($1.*)?")}/*$`),a,n])&&s}),routes:t,async handle(e,...o){let r,s,n=new URL(e.url),a=e.query={__proto__:null};for(let[e,t]of n.searchParams)a[e]=void 0===a[e]?t:[a[e],t].flat();for(let[a,c,p,i]of t)if((a===e.method||"ALL"===a)&&(s=n.pathname.match(c))){e.params=s.groups||{},e.route=i;for(let t of p)if(void 0!==(r=await t(e.proxy||e,...o)))return r}}}),exports.StatusError=n,exports.createCors=s,exports.createResponse=e,exports.error=r,exports.flow=(e,o={})=>{const{format:n=t,error:a=r,cors:c,notFound:p=(()=>r(404))}=o;let i;return"function"==typeof p&&e.all("*",p),c&&(i=s(!0===c?void 0:c),e.routes.unshift(["ALL",/^(.*)?\/*$/,[i.preflight],"*"])),async(...t)=>{let o=e.handle(...t);return n&&(o=o.then(n)),a&&(o=o.catch(a)),c&&(o=o.then(i?.corsify)),o}},exports.html=a,exports.jpeg=c,exports.json=t,exports.png=p,exports.status=(e,t)=>new Response(null,{...t,status:e}),exports.text=(e,t)=>new Response(String(e),t),exports.webp=i,exports.withContent=async e=>{e.headers.get("content-type")?.includes("json")&&(e.content=await e.json())},exports.withCookies=e=>{e.cookies=(e.headers.get("Cookie")||"").split(/;\s*/).map((e=>e.split(/=(.+)/))).reduce(((e,[t,o])=>o?(e[t]=o,e):e),{})},exports.withParams=e=>{e.proxy=new Proxy(e.proxy||e,{get:(t,o)=>{let r;return void 0!==(r=t[o])?r.bind?.(e)||r:t?.params?.[o]}})};
"use strict";const e=(e={})=>{const{origins:t=["*"],maxAge:o,methods:r=["GET"],headers:s={}}=e;let n;const a={"content-type":"application/json","Access-Control-Allow-Methods":r.join(", "),...s};o&&(a["Access-Control-Max-Age"]=o);return{corsify:e=>{if(!e)throw new Error("No fetch handler responded and no upstream to proxy to specified.");const{headers:t,status:o,body:r}=e;return[101,301,302,308].includes(o)||t.get("access-control-allow-origin")?e:new Response(r,{status:o,headers:{...Object.fromEntries(t),...a,...n,"content-type":t.get("content-type")}})},preflight:e=>{const o=[...new Set(["OPTIONS",...r])],s=e.headers.get("origin")||"";if(n=(t.includes(s)||t.includes("*"))&&{"Access-Control-Allow-Origin":s},"OPTIONS"===e.method){const t={...a,"Access-Control-Allow-Methods":o.join(", "),"Access-Control-Allow-Headers":e.headers.get("Access-Control-Request-Headers"),...n};return new Response(null,{headers:e.headers.get("Origin")&&e.headers.get("Access-Control-Request-Method")&&e.headers.get("Access-Control-Request-Headers")?t:{Allow:o.join(", ")}})}}}},t=(e="text/plain; charset=utf-8",t)=>(o,r)=>{const{headers:s={},...n}=r||{};return"Response"===o?.constructor.name?o:new Response(t?t(o):o,{headers:{"content-type":e,...s},...n})},o=t("application/json; charset=utf-8",JSON.stringify),r=e=>({400:"Bad Request",401:"Unauthorized",403:"Forbidden",404:"Not Found",500:"Internal Server Error"}[e]||"Unknown Error"),s=(e=500,t)=>{if(e instanceof Error){const{message:o,...s}=e;e=e.status||500,t={error:o||r(e),...s}}return t={status:e,..."object"==typeof t?t:{error:t||r(e)}},o(t,{status:e})},n=e=>{e.proxy=new Proxy(e.proxy||e,{get:(t,o)=>{let r;return void 0!==(r=t[o])?r.bind?.(e)||r:t?.params?.[o]}})};class a extends Error{status;constructor(e=500,t){super("object"==typeof t?t.error:t),"object"==typeof t&&Object.assign(this,t),this.status=e}}const c=t("text/html"),p=t("image/jpeg"),i=t("image/png"),l=t("image/webp");exports.Router=({base:e="",routes:t=[]}={})=>({__proto__:new Proxy({},{get:(o,r,s,n)=>(o,...a)=>t.push([r.toUpperCase(),RegExp(`^${(n=(e+o).replace(/\/+(\/|$)/g,"$1")).replace(/(\/?\.?):(\w+)\+/g,"($1(?<$2>*))").replace(/(\/?\.?):(\w+)/g,"($1(?<$2>[^$1/]+?))").replace(/\./g,"\\.").replace(/(\/?)\*/g,"($1.*)?")}/*$`),a,n])&&s}),routes:t,async handle(e,...o){let r,s,n=new URL(e.url),a=e.query={__proto__:null};for(let[e,t]of n.searchParams)a[e]=void 0===a[e]?t:[a[e],t].flat();for(let[a,c,p,i]of t)if((a===e.method||"ALL"===a)&&(s=n.pathname.match(c))){e.params=s.groups||{},e.route=i;for(let t of p)if(void 0!==(r=await t(e.proxy||e,...o)))return r}}}),exports.StatusError=a,exports.createCors=e,exports.createResponse=t,exports.error=s,exports.flow=(t,r={})=>{const{format:a=o,error:c=s,cors:p,notFound:i=(()=>s(404))}=r;let l;return"function"==typeof i&&t.all("*",i),p&&(l=e(!0===p?void 0:p),t.routes.unshift(["ALL",/^(.*)?\/*$/,[l.preflight,n],"*"])),async(...e)=>{let o=t.handle(...e);return a&&(o=o.then(a)),c&&(o=o.catch(c)),p&&(o=o.then(l?.corsify)),o}},exports.html=c,exports.jpeg=p,exports.json=o,exports.png=i,exports.status=(e,t)=>new Response(null,{...t,status:e}),exports.text=(e,t)=>new Response(String(e),t),exports.webp=l,exports.withContent=async e=>{e.headers.get("content-type")?.includes("json")&&(e.content=await e.json())},exports.withCookies=e=>{e.cookies=(e.headers.get("Cookie")||"").split(/;\s*/).map((e=>e.split(/=(.+)/))).reduce(((e,[t,o])=>o?(e[t]=o,e):e),{})},exports.withParams=n;
{
"name": "itty-router",
"version": "4.1.0-next.1",
"version": "4.1.0-next.2",
"description": "A tiny, zero-dependency router, designed to make beautiful APIs in any environment.",

@@ -101,2 +101,3 @@ "main": "./index.js",

"keywords": [
"itty",
"api",

@@ -106,3 +107,3 @@ "router",

"workers",
"worker",
"bun",
"serverless",

@@ -113,3 +114,4 @@ "cors",

"serviceworker",
"nested"
"http",
"nodejs"
],

@@ -130,4 +132,4 @@ "scripts": {

"build": "rollup -c",
"release:main": "release --tag --push --patch --src=dist",
"release": "release --tag --push --type=next --src=dist",
"release": "release --tag --push --patch --src=dist",
"release:next": "release --tag --push --type=next --src=dist",
"runtime:bun": "bun example/bun.ts",

@@ -134,0 +136,0 @@ "runtime:node": "node example/node.js"

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc