@willbooster/shared-lib-next 1.0.0 → 1.0.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.
@@ -1,2 +1,2 @@
1
- "use strict";var e=require("node:crypto"),r=require("next/server.js");exports.BasicAuthMiddleware=function(s){var n,t,a;const u=null!=(n=s.username)?n:process.env.BASIC_AUTH_USERNAME,o=null!=(t=s.password)?t:process.env.BASIC_AUTH_PASSWORD,l=null!=(a=s.realm)?a:process.env.BASIC_AUTH_REALM;return u||o?s=>{var n;const t=null!=(n=s.headers.get("authorization"))?n:"",[a,i]=t.split(" "),c=Buffer.from(`${u}:${o}`),A=Buffer.from(null!=i?i:"","base64");return"basic"===(null==a?void 0:a.toLowerCase())&&0!==A.length&&c.length===A.length&&e.timingSafeEqual(A,c)?r.NextResponse.next():new r.NextResponse("Unauthorized",{headers:{"WWW-Authenticate":`Basic realm="${l||"Secure Area"}"`},status:401})}:()=>r.NextResponse.next()};
1
+ "use strict";var e=require("next/server.js");exports.BasicAuthMiddleware=function(r){var n,t,s;const l=null!=(n=r.username)?n:process.env.BASIC_AUTH_USERNAME,u=null!=(t=r.password)?t:process.env.BASIC_AUTH_PASSWORD,o=null!=(s=r.realm)?s:process.env.BASIC_AUTH_REALM;return l||u?r=>{var n;const t=null!=(n=r.headers.get("authorization"))?n:"",[s,a]=t.split(" "),i=Buffer.from(`${l}:${u}`),c=Buffer.from(null!=a?a:"","base64");return"basic"===(null==s?void 0:s.toLowerCase())&&0!==c.length&&i.length===c.length&&function(e,r){if(e.length!==r.length)return!1;let n=0;for(const[s,l]of e.entries()){var t;n|=l^(null!=(t=r[s])?t:0)}return 0===n}(c,i)?e.NextResponse.next():new e.NextResponse("Unauthorized",{headers:{"WWW-Authenticate":`Basic realm="${o||"Secure Area"}"`},status:401})}:()=>e.NextResponse.next()};
2
2
  //# sourceMappingURL=middleware.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"middleware.cjs","sources":["../src/middleware.ts"],"sourcesContent":["import crypto from 'node:crypto';\n\nimport { NextResponse } from 'next/server.js';\nimport type { NextRequest } from 'next/server.js';\n\ntype BasicAuthMiddlewareOptions = {\n username?: string;\n password?: string;\n realm?: string;\n};\n\nexport function BasicAuthMiddleware(options: BasicAuthMiddlewareOptions): (request: NextRequest) => NextResponse {\n const username = options.username ?? process.env.BASIC_AUTH_USERNAME;\n const password = options.password ?? process.env.BASIC_AUTH_PASSWORD;\n const realm = options.realm ?? process.env.BASIC_AUTH_REALM;\n\n if (!username && !password) return () => NextResponse.next();\n\n return (request) => {\n const authorizationHeader = request.headers.get('authorization') ?? '';\n const [type, encodedCredentials] = authorizationHeader.split(' ');\n const expected = Buffer.from(`${username}:${password}`);\n const provided = Buffer.from(encodedCredentials ?? '', 'base64');\n\n if (\n type?.toLowerCase() !== 'basic' ||\n provided.length === 0 ||\n expected.length !== provided.length ||\n !crypto.timingSafeEqual(provided, expected)\n ) {\n return new NextResponse('Unauthorized', {\n headers: { 'WWW-Authenticate': `Basic realm=\"${realm || 'Secure Area'}\"` },\n status: 401,\n });\n }\n\n return NextResponse.next();\n };\n}\n"],"names":["options","_options$username","_options$password","_options$realm","username","process","env","BASIC_AUTH_USERNAME","password","BASIC_AUTH_PASSWORD","realm","BASIC_AUTH_REALM","request","_request$headers$get","authorizationHeader","headers","get","type","encodedCredentials","split","expected","Buffer","from","provided","toLowerCase","length","crypto","timingSafeEqual","NextResponse","next","status"],"mappings":"kGAWO,SAA6BA,GAA6E,IAAAC,EAAAC,EAAAC,EAC/G,MAAMC,EAA2B,OAAnBH,EAAGD,EAAQI,UAAQH,EAAII,QAAQC,IAAIC,oBAC3CC,EAA2B,OAAnBN,EAAGF,EAAQQ,UAAQN,EAAIG,QAAQC,IAAIG,oBAC3CC,EAAqB,OAAhBP,EAAGH,EAAQU,OAAKP,EAAIE,QAAQC,IAAIK,iBAE3C,OAAKP,GAAaI,EAEVI,IAAY,IAAAC,EAClB,MAAMC,EAA0D,OAAvCD,EAAGD,EAAQG,QAAQC,IAAI,kBAAgBH,EAAI,IAC7DI,EAAMC,GAAsBJ,EAAoBK,MAAM,KACvDC,EAAWC,OAAOC,KAAK,GAAGlB,KAAYI,KACtCe,EAAWF,OAAOC,KAAuB,MAAlBJ,EAAAA,EAAsB,GAAI,UAEvD,MAC0B,WAApB,MAAJD,OAAI,EAAJA,EAAMO,gBACc,IAApBD,EAASE,QACTL,EAASK,SAAWF,EAASE,QAC5BC,EAAOC,gBAAgBJ,EAAUH,GAQ7BQ,EAAAA,aAAaC,OANX,IAAID,EAAAA,aAAa,eAAgB,CACtCb,QAAS,CAAE,mBAAoB,gBAAgBL,GAAS,kBACxDoB,OAAQ,OAhBqB,IAAMF,EAAAA,aAAaC,MAsBxD"}
1
+ {"version":3,"file":"middleware.cjs","sources":["../src/middleware.ts"],"sourcesContent":["import { NextResponse } from 'next/server.js';\nimport type { NextRequest } from 'next/server.js';\n\ntype BasicAuthMiddlewareOptions = {\n username?: string;\n password?: string;\n realm?: string;\n};\n\n/**\n * Timing-safe comparison of two buffers to prevent timing attacks.\n * This implementation works in all JavaScript environments (Node.js, Edge, Browser).\n */\nfunction timingSafeEqual(a: Buffer, b: Buffer): boolean {\n if (a.length !== b.length) {\n return false;\n }\n\n let result = 0;\n for (const [i, element] of a.entries()) {\n result |= element ^ (b[i] ?? 0);\n }\n return result === 0;\n}\n\nexport function BasicAuthMiddleware(options: BasicAuthMiddlewareOptions): (request: NextRequest) => NextResponse {\n const username = options.username ?? process.env.BASIC_AUTH_USERNAME;\n const password = options.password ?? process.env.BASIC_AUTH_PASSWORD;\n const realm = options.realm ?? process.env.BASIC_AUTH_REALM;\n\n if (!username && !password) return () => NextResponse.next();\n\n return (request) => {\n const authorizationHeader = request.headers.get('authorization') ?? '';\n const [type, encodedCredentials] = authorizationHeader.split(' ');\n const expected = Buffer.from(`${username}:${password}`);\n const provided = Buffer.from(encodedCredentials ?? '', 'base64');\n\n if (\n type?.toLowerCase() !== 'basic' ||\n provided.length === 0 ||\n expected.length !== provided.length ||\n !timingSafeEqual(provided, expected)\n ) {\n return new NextResponse('Unauthorized', {\n headers: { 'WWW-Authenticate': `Basic realm=\"${realm || 'Secure Area'}\"` },\n status: 401,\n });\n }\n\n return NextResponse.next();\n };\n}\n"],"names":["options","_options$username","_options$password","_options$realm","username","process","env","BASIC_AUTH_USERNAME","password","BASIC_AUTH_PASSWORD","realm","BASIC_AUTH_REALM","request","_request$headers$get","authorizationHeader","headers","get","type","encodedCredentials","split","expected","Buffer","from","provided","toLowerCase","length","a","b","result","i","element","entries","_b$i","timingSafeEqual","NextResponse","next","status"],"mappings":"yEAyBO,SAA6BA,GAA6E,IAAAC,EAAAC,EAAAC,EAC/G,MAAMC,EAA2B,OAAnBH,EAAGD,EAAQI,UAAQH,EAAII,QAAQC,IAAIC,oBAC3CC,EAA2B,OAAnBN,EAAGF,EAAQQ,UAAQN,EAAIG,QAAQC,IAAIG,oBAC3CC,EAAqB,OAAhBP,EAAGH,EAAQU,OAAKP,EAAIE,QAAQC,IAAIK,iBAE3C,OAAKP,GAAaI,EAEVI,IAAY,IAAAC,EAClB,MAAMC,EAA0D,OAAvCD,EAAGD,EAAQG,QAAQC,IAAI,kBAAgBH,EAAI,IAC7DI,EAAMC,GAAsBJ,EAAoBK,MAAM,KACvDC,EAAWC,OAAOC,KAAK,GAAGlB,KAAYI,KACtCe,EAAWF,OAAOC,KAAuB,MAAlBJ,EAAAA,EAAsB,GAAI,UAEvD,MAC0B,WAApB,MAAJD,OAAI,EAAJA,EAAMO,gBACc,IAApBD,EAASE,QACTL,EAASK,SAAWF,EAASE,QA5BnC,SAAyBC,EAAWC,GAClC,GAAID,EAAED,SAAWE,EAAEF,OACjB,OAAO,EAGT,IAAIG,EAAS,EACb,IAAK,MAAOC,EAAGC,KAAYJ,EAAEK,UAAW,CAAA,IAAAC,EACtCJ,GAAUE,GAAe,OAARE,EAAIL,EAAEE,IAAEG,EAAI,EAC/B,CACA,OAAkB,IAAXJ,CACT,CAmBOK,CAAgBV,EAAUH,GAQtBc,EAAAA,aAAaC,OANX,IAAID,EAAAA,aAAa,eAAgB,CACtCnB,QAAS,CAAE,mBAAoB,gBAAgBL,GAAS,kBACxD0B,OAAQ,OAhBqB,IAAMF,EAAAA,aAAaC,MAsBxD"}
@@ -1,2 +1,2 @@
1
- import e from"node:crypto";import{NextResponse as r}from"next/server.js";function n(n){var t,o,s;const a=null!=(t=n.username)?t:process.env.BASIC_AUTH_USERNAME,l=null!=(o=n.password)?o:process.env.BASIC_AUTH_PASSWORD,u=null!=(s=n.realm)?s:process.env.BASIC_AUTH_REALM;return a||l?n=>{var t;const o=null!=(t=n.headers.get("authorization"))?t:"",[s,i]=o.split(" "),c=Buffer.from(`${a}:${l}`),A=Buffer.from(null!=i?i:"","base64");return"basic"===(null==s?void 0:s.toLowerCase())&&0!==A.length&&c.length===A.length&&e.timingSafeEqual(A,c)?r.next():new r("Unauthorized",{headers:{"WWW-Authenticate":`Basic realm="${u||"Secure Area"}"`},status:401})}:()=>r.next()}export{n as BasicAuthMiddleware};
1
+ import{NextResponse as e}from"next/server.js";function r(r){var n,t,s;const l=null!=(n=r.username)?n:process.env.BASIC_AUTH_USERNAME,o=null!=(t=r.password)?t:process.env.BASIC_AUTH_PASSWORD,u=null!=(s=r.realm)?s:process.env.BASIC_AUTH_REALM;return l||o?r=>{var n;const t=null!=(n=r.headers.get("authorization"))?n:"",[s,a]=t.split(" "),i=Buffer.from(`${l}:${o}`),c=Buffer.from(null!=a?a:"","base64");return"basic"===(null==s?void 0:s.toLowerCase())&&0!==c.length&&i.length===c.length&&function(e,r){if(e.length!==r.length)return!1;let n=0;for(const[s,l]of e.entries()){var t;n|=l^(null!=(t=r[s])?t:0)}return 0===n}(c,i)?e.next():new e("Unauthorized",{headers:{"WWW-Authenticate":`Basic realm="${u||"Secure Area"}"`},status:401})}:()=>e.next()}export{r as BasicAuthMiddleware};
2
2
  //# sourceMappingURL=middleware.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"middleware.js","sources":["../src/middleware.ts"],"sourcesContent":["import crypto from 'node:crypto';\n\nimport { NextResponse } from 'next/server.js';\nimport type { NextRequest } from 'next/server.js';\n\ntype BasicAuthMiddlewareOptions = {\n username?: string;\n password?: string;\n realm?: string;\n};\n\nexport function BasicAuthMiddleware(options: BasicAuthMiddlewareOptions): (request: NextRequest) => NextResponse {\n const username = options.username ?? process.env.BASIC_AUTH_USERNAME;\n const password = options.password ?? process.env.BASIC_AUTH_PASSWORD;\n const realm = options.realm ?? process.env.BASIC_AUTH_REALM;\n\n if (!username && !password) return () => NextResponse.next();\n\n return (request) => {\n const authorizationHeader = request.headers.get('authorization') ?? '';\n const [type, encodedCredentials] = authorizationHeader.split(' ');\n const expected = Buffer.from(`${username}:${password}`);\n const provided = Buffer.from(encodedCredentials ?? '', 'base64');\n\n if (\n type?.toLowerCase() !== 'basic' ||\n provided.length === 0 ||\n expected.length !== provided.length ||\n !crypto.timingSafeEqual(provided, expected)\n ) {\n return new NextResponse('Unauthorized', {\n headers: { 'WWW-Authenticate': `Basic realm=\"${realm || 'Secure Area'}\"` },\n status: 401,\n });\n }\n\n return NextResponse.next();\n };\n}\n"],"names":["BasicAuthMiddleware","options","_options$username","_options$password","_options$realm","username","process","env","BASIC_AUTH_USERNAME","password","BASIC_AUTH_PASSWORD","realm","BASIC_AUTH_REALM","request","_request$headers$get","authorizationHeader","headers","get","type","encodedCredentials","split","expected","Buffer","from","provided","toLowerCase","length","crypto","timingSafeEqual","NextResponse","next","status"],"mappings":"yEAWO,SAASA,EAAoBC,GAA6E,IAAAC,EAAAC,EAAAC,EAC/G,MAAMC,EAA2B,OAAnBH,EAAGD,EAAQI,UAAQH,EAAII,QAAQC,IAAIC,oBAC3CC,EAA2B,OAAnBN,EAAGF,EAAQQ,UAAQN,EAAIG,QAAQC,IAAIG,oBAC3CC,EAAqB,OAAhBP,EAAGH,EAAQU,OAAKP,EAAIE,QAAQC,IAAIK,iBAE3C,OAAKP,GAAaI,EAEVI,IAAY,IAAAC,EAClB,MAAMC,EAA0D,OAAvCD,EAAGD,EAAQG,QAAQC,IAAI,kBAAgBH,EAAI,IAC7DI,EAAMC,GAAsBJ,EAAoBK,MAAM,KACvDC,EAAWC,OAAOC,KAAK,GAAGlB,KAAYI,KACtCe,EAAWF,OAAOC,KAAuB,MAAlBJ,EAAAA,EAAsB,GAAI,UAEvD,MAC0B,WAApB,MAAJD,OAAI,EAAJA,EAAMO,gBACc,IAApBD,EAASE,QACTL,EAASK,SAAWF,EAASE,QAC5BC,EAAOC,gBAAgBJ,EAAUH,GAQ7BQ,EAAaC,OANX,IAAID,EAAa,eAAgB,CACtCb,QAAS,CAAE,mBAAoB,gBAAgBL,GAAS,kBACxDoB,OAAQ,OAhBqB,IAAMF,EAAaC,MAsBxD"}
1
+ {"version":3,"file":"middleware.js","sources":["../src/middleware.ts"],"sourcesContent":["import { NextResponse } from 'next/server.js';\nimport type { NextRequest } from 'next/server.js';\n\ntype BasicAuthMiddlewareOptions = {\n username?: string;\n password?: string;\n realm?: string;\n};\n\n/**\n * Timing-safe comparison of two buffers to prevent timing attacks.\n * This implementation works in all JavaScript environments (Node.js, Edge, Browser).\n */\nfunction timingSafeEqual(a: Buffer, b: Buffer): boolean {\n if (a.length !== b.length) {\n return false;\n }\n\n let result = 0;\n for (const [i, element] of a.entries()) {\n result |= element ^ (b[i] ?? 0);\n }\n return result === 0;\n}\n\nexport function BasicAuthMiddleware(options: BasicAuthMiddlewareOptions): (request: NextRequest) => NextResponse {\n const username = options.username ?? process.env.BASIC_AUTH_USERNAME;\n const password = options.password ?? process.env.BASIC_AUTH_PASSWORD;\n const realm = options.realm ?? process.env.BASIC_AUTH_REALM;\n\n if (!username && !password) return () => NextResponse.next();\n\n return (request) => {\n const authorizationHeader = request.headers.get('authorization') ?? '';\n const [type, encodedCredentials] = authorizationHeader.split(' ');\n const expected = Buffer.from(`${username}:${password}`);\n const provided = Buffer.from(encodedCredentials ?? '', 'base64');\n\n if (\n type?.toLowerCase() !== 'basic' ||\n provided.length === 0 ||\n expected.length !== provided.length ||\n !timingSafeEqual(provided, expected)\n ) {\n return new NextResponse('Unauthorized', {\n headers: { 'WWW-Authenticate': `Basic realm=\"${realm || 'Secure Area'}\"` },\n status: 401,\n });\n }\n\n return NextResponse.next();\n };\n}\n"],"names":["BasicAuthMiddleware","options","_options$username","_options$password","_options$realm","username","process","env","BASIC_AUTH_USERNAME","password","BASIC_AUTH_PASSWORD","realm","BASIC_AUTH_REALM","request","_request$headers$get","authorizationHeader","headers","get","type","encodedCredentials","split","expected","Buffer","from","provided","toLowerCase","length","a","b","result","i","element","entries","_b$i","timingSafeEqual","NextResponse","next","status"],"mappings":"8CAyBO,SAASA,EAAoBC,GAA6E,IAAAC,EAAAC,EAAAC,EAC/G,MAAMC,EAA2B,OAAnBH,EAAGD,EAAQI,UAAQH,EAAII,QAAQC,IAAIC,oBAC3CC,EAA2B,OAAnBN,EAAGF,EAAQQ,UAAQN,EAAIG,QAAQC,IAAIG,oBAC3CC,EAAqB,OAAhBP,EAAGH,EAAQU,OAAKP,EAAIE,QAAQC,IAAIK,iBAE3C,OAAKP,GAAaI,EAEVI,IAAY,IAAAC,EAClB,MAAMC,EAA0D,OAAvCD,EAAGD,EAAQG,QAAQC,IAAI,kBAAgBH,EAAI,IAC7DI,EAAMC,GAAsBJ,EAAoBK,MAAM,KACvDC,EAAWC,OAAOC,KAAK,GAAGlB,KAAYI,KACtCe,EAAWF,OAAOC,KAAuB,MAAlBJ,EAAAA,EAAsB,GAAI,UAEvD,MAC0B,WAApB,MAAJD,OAAI,EAAJA,EAAMO,gBACc,IAApBD,EAASE,QACTL,EAASK,SAAWF,EAASE,QA5BnC,SAAyBC,EAAWC,GAClC,GAAID,EAAED,SAAWE,EAAEF,OACjB,OAAO,EAGT,IAAIG,EAAS,EACb,IAAK,MAAOC,EAAGC,KAAYJ,EAAEK,UAAW,CAAA,IAAAC,EACtCJ,GAAUE,GAAe,OAARE,EAAIL,EAAEE,IAAEG,EAAI,EAC/B,CACA,OAAkB,IAAXJ,CACT,CAmBOK,CAAgBV,EAAUH,GAQtBc,EAAaC,OANX,IAAID,EAAa,eAAgB,CACtCnB,QAAS,CAAE,mBAAoB,gBAAgBL,GAAS,kBACxD0B,OAAQ,OAhBqB,IAAMF,EAAaC,MAsBxD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/shared-lib-next",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "license": "Apache-2.0",
5
5
  "author": "WillBooster Inc.",
6
6
  "sideEffects": false,