@willbooster/shared-lib-next 1.0.1 → 1.0.3

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 +1 @@
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
+ {"version":3,"file":"middleware.cjs","sources":["../src/middleware.ts"],"sourcesContent":["import { NextResponse } from 'next/server.js';\nimport type { NextRequest } from 'next/server.js';\n\ninterface 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,9 +1,9 @@
1
1
  import { NextResponse } from 'next/server.js';
2
2
  import type { NextRequest } from 'next/server.js';
3
- type BasicAuthMiddlewareOptions = {
3
+ interface BasicAuthMiddlewareOptions {
4
4
  username?: string;
5
5
  password?: string;
6
6
  realm?: string;
7
- };
7
+ }
8
8
  export declare function BasicAuthMiddleware(options: BasicAuthMiddlewareOptions): (request: NextRequest) => NextResponse;
9
9
  export {};
@@ -1 +1 @@
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"}
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\ninterface 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.1",
3
+ "version": "1.0.3",
4
4
  "license": "Apache-2.0",
5
5
  "author": "WillBooster Inc.",
6
6
  "sideEffects": false,
@@ -39,29 +39,29 @@
39
39
  "prettier": "@willbooster/prettier-config",
40
40
  "devDependencies": {
41
41
  "@types/eslint": "9.6.1",
42
- "@types/micromatch": "4.0.9",
43
- "@willbooster/eslint-config-ts": "11.4.7",
44
- "@willbooster/prettier-config": "10.2.0",
45
- "build-ts": "16.0.8",
46
- "eslint": "9.37.0",
42
+ "@types/micromatch": "4.0.10",
43
+ "@willbooster/eslint-config-ts": "11.4.10",
44
+ "@willbooster/prettier-config": "10.2.1",
45
+ "build-ts": "16.0.12",
46
+ "eslint": "9.39.1",
47
47
  "eslint-config-flat-gitignore": "2.1.0",
48
48
  "eslint-config-prettier": "10.1.8",
49
49
  "eslint-import-resolver-typescript": "4.4.4",
50
50
  "eslint-plugin-import-x": "4.16.1",
51
51
  "eslint-plugin-sort-class-members": "1.21.0",
52
52
  "eslint-plugin-sort-destructure-keys": "2.0.0",
53
- "eslint-plugin-unicorn": "61.0.2",
54
- "eslint-plugin-unused-imports": "4.2.0",
55
- "globals": "16.4.0",
56
- "lint-staged": "16.2.3",
53
+ "eslint-plugin-unicorn": "62.0.0",
54
+ "eslint-plugin-unused-imports": "4.3.0",
55
+ "globals": "16.5.0",
56
+ "lint-staged": "16.2.6",
57
57
  "micromatch": "4.0.8",
58
- "next": "15.5.4",
58
+ "next": "16.0.0",
59
59
  "prettier": "3.6.2",
60
- "prettier-plugin-java": "2.7.5",
60
+ "prettier-plugin-java": "2.7.7",
61
61
  "sort-package-json": "3.4.0",
62
62
  "typescript": "5.9.3",
63
- "typescript-eslint": "8.45.0",
64
- "vitest": "3.2.4"
63
+ "typescript-eslint": "8.46.3",
64
+ "vitest": "4.0.3"
65
65
  },
66
66
  "peerDependencies": {
67
67
  "next": "*"