@willbooster/shared-lib-blitz-next 3.0.8 → 3.1.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/README.md CHANGED
@@ -1 +1 @@
1
- # library
1
+ # @willbooster/shared-lib-blitz-next
@@ -1,2 +1,2 @@
1
- "use strict";exports.BasicAuthMiddleware=function(e){return async(t,a,r)=>{var s;const i=null!=(s=t.headers.authorization)?s:"",[n,u]=i.split(" "),o=Buffer.from(null!=u?u:"","base64").toString(),[c,d]=o.split(":");if("Basic"!==n||!c||!d||c!==e.username||d!==e.password)return a.setHeader("WWW-Authenticate",`Basic realm='${e.realm||"Secure Area"}'`),a.statusCode=401,void a.end("Unauthorized");await r()}};
1
+ "use strict";exports.BasicAuthMiddleware=function(e){return async(t,r,n)=>{var a;const s=null!=(a=t.headers.authorization)?a:"",[u,i]=s.split(" "),l=Buffer.from(`${e.username}:${e.password}`),o=Buffer.from(null!=i?i:"","base64");if("basic"!==(null==u?void 0:u.toLowerCase())||0===o.length||l.length!==o.length||!function(e,t){if(e.length!==t.length)return!1;let r=0;for(const[a,s]of e.entries()){var n;r|=s^(null!=(n=t[a])?n:0)}return 0===r}(o,l))return r.setHeader("WWW-Authenticate",`Basic realm='${e.realm||"Secure Area"}'`),r.statusCode=401,void r.end("Unauthorized");await n()}};
2
2
  //# sourceMappingURL=middleware.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"middleware.cjs","sources":["../src/middleware.ts"],"sourcesContent":["import type { RequestMiddleware } from 'blitz';\n\ntype BasicAuthMiddlewareOptions = {\n password: string;\n realm?: string;\n username: string;\n};\n\nexport function BasicAuthMiddleware(options: BasicAuthMiddlewareOptions): RequestMiddleware {\n return async (request, response, next) => {\n const authorizationHeader = request.headers.authorization ?? '';\n const [type, encodedCredentials] = authorizationHeader.split(' ');\n const credentials = Buffer.from(encodedCredentials ?? '', 'base64').toString();\n const [requestUsername, requestPassword] = credentials.split(':');\n\n if (\n type !== 'Basic' ||\n !requestUsername ||\n !requestPassword ||\n requestUsername !== options.username ||\n requestPassword !== options.password\n ) {\n response.setHeader('WWW-Authenticate', `Basic realm='${options.realm || 'Secure Area'}'`);\n response.statusCode = 401;\n response.end('Unauthorized');\n return;\n }\n\n await next();\n };\n}\n"],"names":["options","async","request","response","next","_request$headers$auth","authorizationHeader","headers","authorization","type","encodedCredentials","split","credentials","Buffer","from","toString","requestUsername","requestPassword","username","password","setHeader","realm","statusCode","end"],"mappings":"yCAQO,SAA6BA,GAClC,OAAOC,MAAOC,EAASC,EAAUC,KAAS,IAAAC,EACxC,MAAMC,EAAmD,OAAhCD,EAAGH,EAAQK,QAAQC,eAAaH,EAAI,IACtDI,EAAMC,GAAsBJ,EAAoBK,MAAM,KACvDC,EAAcC,OAAOC,KAAuB,MAAlBJ,EAAAA,EAAsB,GAAI,UAAUK,YAC7DC,EAAiBC,GAAmBL,EAAYD,MAAM,KAE7D,GACW,UAATF,IACCO,IACAC,GACDD,IAAoBhB,EAAQkB,UAC5BD,IAAoBjB,EAAQmB,SAK5B,OAHAhB,EAASiB,UAAU,mBAAoB,gBAAgBpB,EAAQqB,OAAS,kBACxElB,EAASmB,WAAa,SACtBnB,EAASoB,IAAI,sBAITnB,IAEV"}
1
+ {"version":3,"file":"middleware.cjs","sources":["../src/middleware.ts"],"sourcesContent":["import type { RequestMiddleware } from 'blitz';\n\ntype BasicAuthMiddlewareOptions = {\n password: string;\n realm?: string;\n username: 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): RequestMiddleware {\n return async (request, response, next) => {\n const authorizationHeader = request.headers.authorization ?? '';\n const [type, encodedCredentials] = authorizationHeader.split(' ');\n const expected = Buffer.from(`${options.username}:${options.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 response.setHeader('WWW-Authenticate', `Basic realm='${options.realm || 'Secure Area'}'`);\n response.statusCode = 401;\n response.end('Unauthorized');\n return;\n }\n\n await next();\n };\n}\n"],"names":["options","async","request","response","next","_request$headers$auth","authorizationHeader","headers","authorization","type","encodedCredentials","split","expected","Buffer","from","username","password","provided","toLowerCase","length","a","b","result","i","element","entries","_b$i","timingSafeEqual","setHeader","realm","statusCode","end"],"mappings":"yCAwBO,SAA6BA,GAClC,OAAOC,MAAOC,EAASC,EAAUC,KAAS,IAAAC,EACxC,MAAMC,EAAmD,OAAhCD,EAAGH,EAAQK,QAAQC,eAAaH,EAAI,IACtDI,EAAMC,GAAsBJ,EAAoBK,MAAM,KACvDC,EAAWC,OAAOC,KAAK,GAAGd,EAAQe,YAAYf,EAAQgB,YACtDC,EAAWJ,OAAOC,KAAuB,MAAlBJ,EAAAA,EAAsB,GAAI,UAEvD,GAC0B,WAApB,MAAJD,OAAI,EAAJA,EAAMS,gBACc,IAApBD,EAASE,QACTP,EAASO,SAAWF,EAASE,SAtBnC,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,CAaOK,CAAgBV,EAAUL,GAK3B,OAHAT,EAASyB,UAAU,mBAAoB,gBAAgB5B,EAAQ6B,OAAS,kBACxE1B,EAAS2B,WAAa,SACtB3B,EAAS4B,IAAI,sBAIT3B,IAEV"}
@@ -1,2 +1,2 @@
1
- function e(e){return async(a,r,t)=>{var n;const s=null!=(n=a.headers.authorization)?n:"",[i,u]=s.split(" "),o=Buffer.from(null!=u?u:"","base64").toString(),[l,c]=o.split(":");if("Basic"!==i||!l||!c||l!==e.username||c!==e.password)return r.setHeader("WWW-Authenticate",`Basic realm='${e.realm||"Secure Area"}'`),r.statusCode=401,void r.end("Unauthorized");await t()}}export{e as BasicAuthMiddleware};
1
+ function e(e){return async(r,t,n)=>{var a;const o=null!=(a=r.headers.authorization)?a:"",[u,l]=o.split(" "),s=Buffer.from(`${e.username}:${e.password}`),i=Buffer.from(null!=l?l:"","base64");if("basic"!==(null==u?void 0:u.toLowerCase())||0===i.length||s.length!==i.length||!function(e,r){if(e.length!==r.length)return!1;let t=0;for(const[a,o]of e.entries()){var n;t|=o^(null!=(n=r[a])?n:0)}return 0===t}(i,s))return t.setHeader("WWW-Authenticate",`Basic realm='${e.realm||"Secure Area"}'`),t.statusCode=401,void t.end("Unauthorized");await n()}}export{e as BasicAuthMiddleware};
2
2
  //# sourceMappingURL=middleware.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"middleware.js","sources":["../src/middleware.ts"],"sourcesContent":["import type { RequestMiddleware } from 'blitz';\n\ntype BasicAuthMiddlewareOptions = {\n password: string;\n realm?: string;\n username: string;\n};\n\nexport function BasicAuthMiddleware(options: BasicAuthMiddlewareOptions): RequestMiddleware {\n return async (request, response, next) => {\n const authorizationHeader = request.headers.authorization ?? '';\n const [type, encodedCredentials] = authorizationHeader.split(' ');\n const credentials = Buffer.from(encodedCredentials ?? '', 'base64').toString();\n const [requestUsername, requestPassword] = credentials.split(':');\n\n if (\n type !== 'Basic' ||\n !requestUsername ||\n !requestPassword ||\n requestUsername !== options.username ||\n requestPassword !== options.password\n ) {\n response.setHeader('WWW-Authenticate', `Basic realm='${options.realm || 'Secure Area'}'`);\n response.statusCode = 401;\n response.end('Unauthorized');\n return;\n }\n\n await next();\n };\n}\n"],"names":["BasicAuthMiddleware","options","async","request","response","next","_request$headers$auth","authorizationHeader","headers","authorization","type","encodedCredentials","split","credentials","Buffer","from","toString","requestUsername","requestPassword","username","password","setHeader","realm","statusCode","end"],"mappings":"AAQO,SAASA,EAAoBC,GAClC,OAAOC,MAAOC,EAASC,EAAUC,KAAS,IAAAC,EACxC,MAAMC,EAAmD,OAAhCD,EAAGH,EAAQK,QAAQC,eAAaH,EAAI,IACtDI,EAAMC,GAAsBJ,EAAoBK,MAAM,KACvDC,EAAcC,OAAOC,KAAuB,MAAlBJ,EAAAA,EAAsB,GAAI,UAAUK,YAC7DC,EAAiBC,GAAmBL,EAAYD,MAAM,KAE7D,GACW,UAATF,IACCO,IACAC,GACDD,IAAoBhB,EAAQkB,UAC5BD,IAAoBjB,EAAQmB,SAK5B,OAHAhB,EAASiB,UAAU,mBAAoB,gBAAgBpB,EAAQqB,OAAS,kBACxElB,EAASmB,WAAa,SACtBnB,EAASoB,IAAI,sBAITnB,IAEV"}
1
+ {"version":3,"file":"middleware.js","sources":["../src/middleware.ts"],"sourcesContent":["import type { RequestMiddleware } from 'blitz';\n\ntype BasicAuthMiddlewareOptions = {\n password: string;\n realm?: string;\n username: 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): RequestMiddleware {\n return async (request, response, next) => {\n const authorizationHeader = request.headers.authorization ?? '';\n const [type, encodedCredentials] = authorizationHeader.split(' ');\n const expected = Buffer.from(`${options.username}:${options.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 response.setHeader('WWW-Authenticate', `Basic realm='${options.realm || 'Secure Area'}'`);\n response.statusCode = 401;\n response.end('Unauthorized');\n return;\n }\n\n await next();\n };\n}\n"],"names":["BasicAuthMiddleware","options","async","request","response","next","_request$headers$auth","authorizationHeader","headers","authorization","type","encodedCredentials","split","expected","Buffer","from","username","password","provided","toLowerCase","length","a","b","result","i","element","entries","_b$i","timingSafeEqual","setHeader","realm","statusCode","end"],"mappings":"AAwBO,SAASA,EAAoBC,GAClC,OAAOC,MAAOC,EAASC,EAAUC,KAAS,IAAAC,EACxC,MAAMC,EAAmD,OAAhCD,EAAGH,EAAQK,QAAQC,eAAaH,EAAI,IACtDI,EAAMC,GAAsBJ,EAAoBK,MAAM,KACvDC,EAAWC,OAAOC,KAAK,GAAGd,EAAQe,YAAYf,EAAQgB,YACtDC,EAAWJ,OAAOC,KAAuB,MAAlBJ,EAAAA,EAAsB,GAAI,UAEvD,GAC0B,WAApB,MAAJD,OAAI,EAAJA,EAAMS,gBACc,IAApBD,EAASE,QACTP,EAASO,SAAWF,EAASE,SAtBnC,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,CAaOK,CAAgBV,EAAUL,GAK3B,OAHAT,EAASyB,UAAU,mBAAoB,gBAAgB5B,EAAQ6B,OAAS,kBACxE1B,EAAS2B,WAAa,SACtB3B,EAAS4B,IAAI,sBAIT3B,IAEV"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/shared-lib-blitz-next",
3
- "version": "3.0.8",
3
+ "version": "3.1.1",
4
4
  "license": "Apache-2.0",
5
5
  "author": "WillBooster Inc.",
6
6
  "sideEffects": false,