@becklyn/deployment-protection 0.1.0 → 0.2.0

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
@@ -23,33 +23,34 @@ npm i @becklyn/deployment-protection
23
23
 
24
24
  ### 1. Middleware / proxy
25
25
 
26
+ Next.js requires `config.matcher` to be a **string literal in the local middleware/proxy file**.
27
+ It cannot be imported from a package (Next analyzes the matcher statically at build time).
28
+
26
29
  **Next.js 16+ (`proxy.ts`):**
27
30
 
28
31
  ```ts
29
- import {
30
- deploymentProtectionMatcher,
31
- withDeploymentProtection,
32
- } from "@becklyn/deployment-protection";
32
+ import { withDeploymentProtection } from "@becklyn/deployment-protection";
33
33
 
34
34
  export const proxy = withDeploymentProtection();
35
35
 
36
36
  export const config = {
37
- matcher: deploymentProtectionMatcher,
37
+ matcher: [
38
+ "/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp|ico|css|js|map|txt|xml|woff2?)$).*)",
39
+ ],
38
40
  };
39
41
  ```
40
42
 
41
43
  **Next.js ≤15 (`middleware.ts`):**
42
44
 
43
45
  ```ts
44
- import {
45
- deploymentProtectionMatcher,
46
- withDeploymentProtection,
47
- } from "@becklyn/deployment-protection";
46
+ import { withDeploymentProtection } from "@becklyn/deployment-protection";
48
47
 
49
48
  export default withDeploymentProtection();
50
49
 
51
50
  export const config = {
52
- matcher: deploymentProtectionMatcher,
51
+ matcher: [
52
+ "/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp|ico|css|js|map|txt|xml|woff2?)$).*)",
53
+ ],
53
54
  };
54
55
  ```
55
56
 
@@ -135,7 +136,6 @@ Redeploy. Middleware stays installed but is a no-op.
135
136
 
136
137
  ```ts
137
138
  import {
138
- deploymentProtectionMatcher,
139
139
  handleDeploymentProtection,
140
140
  resolveConfig,
141
141
  withDeploymentProtection,
@@ -144,7 +144,12 @@ import {
144
144
 
145
145
  - `withDeploymentProtection(options?)` / `withDeploymentProtection(next, options?)` — middleware/proxy factory
146
146
  - `handleDeploymentProtection(request, options?)` — framework-agnostic core (`null` = continue)
147
- - `deploymentProtectionMatcher` — recommended matcher array
147
+
148
+ Recommended matcher (must be pasted as a string literal in your middleware/proxy file — see above):
149
+
150
+ ```ts
151
+ "/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp|ico|css|js|map|txt|xml|woff2?)$).*)";
152
+ ```
148
153
 
149
154
  ## Security notes
150
155
 
@@ -10,6 +10,4 @@ export declare const VERCEL_CALLBACK_PATH = "/_becklyn/deployment-protection/ver
10
10
  export declare const BYPASS_HEADER = "x-vercel-protection-bypass";
11
11
  export declare const SET_BYPASS_COOKIE_HEADER = "x-vercel-set-bypass-cookie";
12
12
  export declare const DEFAULT_SESSION_TTL_SECONDS: number;
13
- /** Recommended Next.js matcher for full-site protection. */
14
- export declare const deploymentProtectionMatcher: string[];
15
13
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB,yBAAyB,CAAC;AAC1D,eAAO,MAAM,kBAAkB,wBAAwB,CAAC;AACxD,eAAO,MAAM,kBAAkB,6BAA6B,CAAC;AAC7D,eAAO,MAAM,kBAAkB,6BAA6B,CAAC;AAC7D,eAAO,MAAM,qBAAqB,gCAAgC,CAAC;AACnE,eAAO,MAAM,mBAAmB,8BAA8B,CAAC;AAE/D,eAAO,MAAM,oBAAoB,oCAAoC,CAAC;AACtE,eAAO,MAAM,qBAAqB,2CAAmC,CAAC;AACtE,eAAO,MAAM,oBAAoB,oDAA4C,CAAC;AAE9E,eAAO,MAAM,aAAa,+BAA+B,CAAC;AAC1D,eAAO,MAAM,wBAAwB,+BAA+B,CAAC;AAErE,eAAO,MAAM,2BAA2B,QAAoB,CAAC;AAE7D,4DAA4D;AAC5D,eAAO,MAAM,2BAA2B,UAEvC,CAAC"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB,yBAAyB,CAAC;AAC1D,eAAO,MAAM,kBAAkB,wBAAwB,CAAC;AACxD,eAAO,MAAM,kBAAkB,6BAA6B,CAAC;AAC7D,eAAO,MAAM,kBAAkB,6BAA6B,CAAC;AAC7D,eAAO,MAAM,qBAAqB,gCAAgC,CAAC;AACnE,eAAO,MAAM,mBAAmB,8BAA8B,CAAC;AAE/D,eAAO,MAAM,oBAAoB,oCAAoC,CAAC;AACtE,eAAO,MAAM,qBAAqB,2CAAmC,CAAC;AACtE,eAAO,MAAM,oBAAoB,oDAA4C,CAAC;AAE9E,eAAO,MAAM,aAAa,+BAA+B,CAAC;AAC1D,eAAO,MAAM,wBAAwB,+BAA+B,CAAC;AAErE,eAAO,MAAM,2BAA2B,QAAoB,CAAC"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.deploymentProtectionMatcher = exports.DEFAULT_SESSION_TTL_SECONDS = exports.SET_BYPASS_COOKIE_HEADER = exports.BYPASS_HEADER = exports.VERCEL_CALLBACK_PATH = exports.VERCEL_AUTHORIZE_PATH = exports.INTERNAL_PATH_PREFIX = exports.OAUTH_RETURN_COOKIE = exports.OAUTH_VERIFIER_COOKIE = exports.OAUTH_NONCE_COOKIE = exports.OAUTH_STATE_COOKIE = exports.BYPASS_COOKIE_NAME = exports.SESSION_COOKIE_NAME = void 0;
3
+ exports.DEFAULT_SESSION_TTL_SECONDS = exports.SET_BYPASS_COOKIE_HEADER = exports.BYPASS_HEADER = exports.VERCEL_CALLBACK_PATH = exports.VERCEL_AUTHORIZE_PATH = exports.INTERNAL_PATH_PREFIX = exports.OAUTH_RETURN_COOKIE = exports.OAUTH_VERIFIER_COOKIE = exports.OAUTH_NONCE_COOKIE = exports.OAUTH_STATE_COOKIE = exports.BYPASS_COOKIE_NAME = exports.SESSION_COOKIE_NAME = void 0;
4
4
  exports.SESSION_COOKIE_NAME = "__becklyn_dp_session";
5
5
  exports.BYPASS_COOKIE_NAME = "__becklyn_dp_bypass";
6
6
  exports.OAUTH_STATE_COOKIE = "__becklyn_dp_oauth_state";
@@ -13,7 +13,3 @@ exports.VERCEL_CALLBACK_PATH = `${exports.INTERNAL_PATH_PREFIX}/vercel/callback`
13
13
  exports.BYPASS_HEADER = "x-vercel-protection-bypass";
14
14
  exports.SET_BYPASS_COOKIE_HEADER = "x-vercel-set-bypass-cookie";
15
15
  exports.DEFAULT_SESSION_TTL_SECONDS = 60 * 60 * 24 * 14; // 14 days
16
- /** Recommended Next.js matcher for full-site protection. */
17
- exports.deploymentProtectionMatcher = [
18
- "/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp|ico|css|js|map|txt|xml|woff2?)$).*)",
19
- ];
@@ -1,4 +1,4 @@
1
- export { deploymentProtectionMatcher, INTERNAL_PATH_PREFIX, VERCEL_AUTHORIZE_PATH, VERCEL_CALLBACK_PATH, } from "./constants";
1
+ export { INTERNAL_PATH_PREFIX, VERCEL_AUTHORIZE_PATH, VERCEL_CALLBACK_PATH } from "./constants";
2
2
  export { handleDeploymentProtection } from "./handler";
3
3
  export { withDeploymentProtection } from "./middleware";
4
4
  export { resolveConfig, hasPasswordAuth, hasVercelAuth, isProtectionActive } from "./config";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,2BAA2B,EAC3B,oBAAoB,EACpB,qBAAqB,EACrB,oBAAoB,GACvB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,0BAA0B,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAC7F,YAAY,EACR,UAAU,EACV,0BAA0B,EAC1B,2BAA2B,EAC3B,WAAW,EACX,cAAc,GACjB,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAChG,OAAO,EAAE,0BAA0B,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAC7F,YAAY,EACR,UAAU,EACV,0BAA0B,EAC1B,2BAA2B,EAC3B,WAAW,EACX,cAAc,GACjB,MAAM,SAAS,CAAC"}
package/dist/cjs/index.js CHANGED
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isProtectionActive = exports.hasVercelAuth = exports.hasPasswordAuth = exports.resolveConfig = exports.withDeploymentProtection = exports.handleDeploymentProtection = exports.VERCEL_CALLBACK_PATH = exports.VERCEL_AUTHORIZE_PATH = exports.INTERNAL_PATH_PREFIX = exports.deploymentProtectionMatcher = void 0;
3
+ exports.isProtectionActive = exports.hasVercelAuth = exports.hasPasswordAuth = exports.resolveConfig = exports.withDeploymentProtection = exports.handleDeploymentProtection = exports.VERCEL_CALLBACK_PATH = exports.VERCEL_AUTHORIZE_PATH = exports.INTERNAL_PATH_PREFIX = void 0;
4
4
  var constants_1 = require("./constants");
5
- Object.defineProperty(exports, "deploymentProtectionMatcher", { enumerable: true, get: function () { return constants_1.deploymentProtectionMatcher; } });
6
5
  Object.defineProperty(exports, "INTERNAL_PATH_PREFIX", { enumerable: true, get: function () { return constants_1.INTERNAL_PATH_PREFIX; } });
7
6
  Object.defineProperty(exports, "VERCEL_AUTHORIZE_PATH", { enumerable: true, get: function () { return constants_1.VERCEL_AUTHORIZE_PATH; } });
8
7
  Object.defineProperty(exports, "VERCEL_CALLBACK_PATH", { enumerable: true, get: function () { return constants_1.VERCEL_CALLBACK_PATH; } });
@@ -1,25 +1,36 @@
1
1
  import { type NextRequest, NextResponse } from "next/server";
2
- import { deploymentProtectionMatcher } from "./constants";
3
2
  import type { DeploymentProtectionOptions } from "./types";
4
3
  type NextMiddleware = (request: NextRequest, event?: unknown) => Response | NextResponse | Promise<Response | NextResponse | undefined | void> | undefined | void;
5
4
  export type WithDeploymentProtectionArgs = [] | [DeploymentProtectionOptions] | [NextMiddleware] | [NextMiddleware, DeploymentProtectionOptions];
6
5
  /**
7
6
  * Next.js middleware / proxy wrapper.
8
7
  *
8
+ * Next.js only accepts a statically analyzable `config.matcher` in the local
9
+ * middleware/proxy file. Do not import a matcher from this package — paste the
10
+ * recommended pattern inline (see README).
11
+ *
9
12
  * @example middleware.ts (Next ≤15)
10
13
  * ```ts
11
- * import {withDeploymentProtection, deploymentProtectionMatcher} from "@becklyn/deployment-protection";
14
+ * import {withDeploymentProtection} from "@becklyn/deployment-protection";
12
15
  * export default withDeploymentProtection();
13
- * export const config = { matcher: deploymentProtectionMatcher };
16
+ * export const config = {
17
+ * matcher: [
18
+ * "/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp|ico|css|js|map|txt|xml|woff2?)$).*)",
19
+ * ],
20
+ * };
14
21
  * ```
15
22
  *
16
23
  * @example proxy.ts (Next 16+)
17
24
  * ```ts
18
- * import {withDeploymentProtection, deploymentProtectionMatcher} from "@becklyn/deployment-protection";
25
+ * import {withDeploymentProtection} from "@becklyn/deployment-protection";
19
26
  * export const proxy = withDeploymentProtection();
20
- * export const config = { matcher: deploymentProtectionMatcher };
27
+ * export const config = {
28
+ * matcher: [
29
+ * "/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp|ico|css|js|map|txt|xml|woff2?)$).*)",
30
+ * ],
31
+ * };
21
32
  * ```
22
33
  */
23
34
  export declare function withDeploymentProtection(...args: WithDeploymentProtectionArgs): (request: NextRequest, event?: unknown) => Promise<Response | NextResponse>;
24
- export { deploymentProtectionMatcher };
35
+ export {};
25
36
  //# sourceMappingURL=middleware.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC;AAE1D,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,SAAS,CAAC;AAE3D,KAAK,cAAc,GAAG,CAClB,OAAO,EAAE,WAAW,EACpB,KAAK,CAAC,EAAE,OAAO,KAEb,QAAQ,GACR,YAAY,GACZ,OAAO,CAAC,QAAQ,GAAG,YAAY,GAAG,SAAS,GAAG,IAAI,CAAC,GACnD,SAAS,GACT,IAAI,CAAC;AAEX,MAAM,MAAM,4BAA4B,GAClC,EAAE,GACF,CAAC,2BAA2B,CAAC,GAC7B,CAAC,cAAc,CAAC,GAChB,CAAC,cAAc,EAAE,2BAA2B,CAAC,CAAC;AA8DpD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,wBAAwB,CAAC,GAAG,IAAI,EAAE,4BAA4B,IAgBtE,SAAS,WAAW,EACpB,QAAQ,OAAO,KAChB,OAAO,CAAC,QAAQ,GAAG,YAAY,CAAC,CActC;AAED,OAAO,EAAE,2BAA2B,EAAE,CAAC"}
1
+ {"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE7D,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,SAAS,CAAC;AAE3D,KAAK,cAAc,GAAG,CAClB,OAAO,EAAE,WAAW,EACpB,KAAK,CAAC,EAAE,OAAO,KAEb,QAAQ,GACR,YAAY,GACZ,OAAO,CAAC,QAAQ,GAAG,YAAY,GAAG,SAAS,GAAG,IAAI,CAAC,GACnD,SAAS,GACT,IAAI,CAAC;AAEX,MAAM,MAAM,4BAA4B,GAClC,EAAE,GACF,CAAC,2BAA2B,CAAC,GAC7B,CAAC,cAAc,CAAC,GAChB,CAAC,cAAc,EAAE,2BAA2B,CAAC,CAAC;AA8DpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,wBAAwB,CAAC,GAAG,IAAI,EAAE,4BAA4B,IAgBtE,SAAS,WAAW,EACpB,QAAQ,OAAO,KAChB,OAAO,CAAC,QAAQ,GAAG,YAAY,CAAC,CActC"}
@@ -1,10 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.deploymentProtectionMatcher = void 0;
4
3
  exports.withDeploymentProtection = withDeploymentProtection;
5
4
  const server_1 = require("next/server");
6
- const constants_1 = require("./constants");
7
- Object.defineProperty(exports, "deploymentProtectionMatcher", { enumerable: true, get: function () { return constants_1.deploymentProtectionMatcher; } });
8
5
  const handler_1 = require("./handler");
9
6
  function isOptions(value) {
10
7
  return (typeof value === "object" &&
@@ -52,18 +49,30 @@ function copyHeaders(from, to, skipLocation) {
52
49
  /**
53
50
  * Next.js middleware / proxy wrapper.
54
51
  *
52
+ * Next.js only accepts a statically analyzable `config.matcher` in the local
53
+ * middleware/proxy file. Do not import a matcher from this package — paste the
54
+ * recommended pattern inline (see README).
55
+ *
55
56
  * @example middleware.ts (Next ≤15)
56
57
  * ```ts
57
- * import {withDeploymentProtection, deploymentProtectionMatcher} from "@becklyn/deployment-protection";
58
+ * import {withDeploymentProtection} from "@becklyn/deployment-protection";
58
59
  * export default withDeploymentProtection();
59
- * export const config = { matcher: deploymentProtectionMatcher };
60
+ * export const config = {
61
+ * matcher: [
62
+ * "/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp|ico|css|js|map|txt|xml|woff2?)$).*)",
63
+ * ],
64
+ * };
60
65
  * ```
61
66
  *
62
67
  * @example proxy.ts (Next 16+)
63
68
  * ```ts
64
- * import {withDeploymentProtection, deploymentProtectionMatcher} from "@becklyn/deployment-protection";
69
+ * import {withDeploymentProtection} from "@becklyn/deployment-protection";
65
70
  * export const proxy = withDeploymentProtection();
66
- * export const config = { matcher: deploymentProtectionMatcher };
71
+ * export const config = {
72
+ * matcher: [
73
+ * "/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp|ico|css|js|map|txt|xml|woff2?)$).*)",
74
+ * ],
75
+ * };
67
76
  * ```
68
77
  */
69
78
  function withDeploymentProtection(...args) {
@@ -10,6 +10,4 @@ export declare const VERCEL_CALLBACK_PATH = "/_becklyn/deployment-protection/ver
10
10
  export declare const BYPASS_HEADER = "x-vercel-protection-bypass";
11
11
  export declare const SET_BYPASS_COOKIE_HEADER = "x-vercel-set-bypass-cookie";
12
12
  export declare const DEFAULT_SESSION_TTL_SECONDS: number;
13
- /** Recommended Next.js matcher for full-site protection. */
14
- export declare const deploymentProtectionMatcher: string[];
15
13
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB,yBAAyB,CAAC;AAC1D,eAAO,MAAM,kBAAkB,wBAAwB,CAAC;AACxD,eAAO,MAAM,kBAAkB,6BAA6B,CAAC;AAC7D,eAAO,MAAM,kBAAkB,6BAA6B,CAAC;AAC7D,eAAO,MAAM,qBAAqB,gCAAgC,CAAC;AACnE,eAAO,MAAM,mBAAmB,8BAA8B,CAAC;AAE/D,eAAO,MAAM,oBAAoB,oCAAoC,CAAC;AACtE,eAAO,MAAM,qBAAqB,2CAAmC,CAAC;AACtE,eAAO,MAAM,oBAAoB,oDAA4C,CAAC;AAE9E,eAAO,MAAM,aAAa,+BAA+B,CAAC;AAC1D,eAAO,MAAM,wBAAwB,+BAA+B,CAAC;AAErE,eAAO,MAAM,2BAA2B,QAAoB,CAAC;AAE7D,4DAA4D;AAC5D,eAAO,MAAM,2BAA2B,UAEvC,CAAC"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB,yBAAyB,CAAC;AAC1D,eAAO,MAAM,kBAAkB,wBAAwB,CAAC;AACxD,eAAO,MAAM,kBAAkB,6BAA6B,CAAC;AAC7D,eAAO,MAAM,kBAAkB,6BAA6B,CAAC;AAC7D,eAAO,MAAM,qBAAqB,gCAAgC,CAAC;AACnE,eAAO,MAAM,mBAAmB,8BAA8B,CAAC;AAE/D,eAAO,MAAM,oBAAoB,oCAAoC,CAAC;AACtE,eAAO,MAAM,qBAAqB,2CAAmC,CAAC;AACtE,eAAO,MAAM,oBAAoB,oDAA4C,CAAC;AAE9E,eAAO,MAAM,aAAa,+BAA+B,CAAC;AAC1D,eAAO,MAAM,wBAAwB,+BAA+B,CAAC;AAErE,eAAO,MAAM,2BAA2B,QAAoB,CAAC"}
@@ -10,7 +10,3 @@ export const VERCEL_CALLBACK_PATH = `${INTERNAL_PATH_PREFIX}/vercel/callback`;
10
10
  export const BYPASS_HEADER = "x-vercel-protection-bypass";
11
11
  export const SET_BYPASS_COOKIE_HEADER = "x-vercel-set-bypass-cookie";
12
12
  export const DEFAULT_SESSION_TTL_SECONDS = 60 * 60 * 24 * 14; // 14 days
13
- /** Recommended Next.js matcher for full-site protection. */
14
- export const deploymentProtectionMatcher = [
15
- "/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp|ico|css|js|map|txt|xml|woff2?)$).*)",
16
- ];
@@ -1,4 +1,4 @@
1
- export { deploymentProtectionMatcher, INTERNAL_PATH_PREFIX, VERCEL_AUTHORIZE_PATH, VERCEL_CALLBACK_PATH, } from "./constants";
1
+ export { INTERNAL_PATH_PREFIX, VERCEL_AUTHORIZE_PATH, VERCEL_CALLBACK_PATH } from "./constants";
2
2
  export { handleDeploymentProtection } from "./handler";
3
3
  export { withDeploymentProtection } from "./middleware";
4
4
  export { resolveConfig, hasPasswordAuth, hasVercelAuth, isProtectionActive } from "./config";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,2BAA2B,EAC3B,oBAAoB,EACpB,qBAAqB,EACrB,oBAAoB,GACvB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,0BAA0B,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAC7F,YAAY,EACR,UAAU,EACV,0BAA0B,EAC1B,2BAA2B,EAC3B,WAAW,EACX,cAAc,GACjB,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAChG,OAAO,EAAE,0BAA0B,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAC7F,YAAY,EACR,UAAU,EACV,0BAA0B,EAC1B,2BAA2B,EAC3B,WAAW,EACX,cAAc,GACjB,MAAM,SAAS,CAAC"}
package/dist/es/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { deploymentProtectionMatcher, INTERNAL_PATH_PREFIX, VERCEL_AUTHORIZE_PATH, VERCEL_CALLBACK_PATH, } from "./constants";
1
+ export { INTERNAL_PATH_PREFIX, VERCEL_AUTHORIZE_PATH, VERCEL_CALLBACK_PATH } from "./constants";
2
2
  export { handleDeploymentProtection } from "./handler";
3
3
  export { withDeploymentProtection } from "./middleware";
4
4
  export { resolveConfig, hasPasswordAuth, hasVercelAuth, isProtectionActive } from "./config";
@@ -1,25 +1,36 @@
1
1
  import { type NextRequest, NextResponse } from "next/server";
2
- import { deploymentProtectionMatcher } from "./constants";
3
2
  import type { DeploymentProtectionOptions } from "./types";
4
3
  type NextMiddleware = (request: NextRequest, event?: unknown) => Response | NextResponse | Promise<Response | NextResponse | undefined | void> | undefined | void;
5
4
  export type WithDeploymentProtectionArgs = [] | [DeploymentProtectionOptions] | [NextMiddleware] | [NextMiddleware, DeploymentProtectionOptions];
6
5
  /**
7
6
  * Next.js middleware / proxy wrapper.
8
7
  *
8
+ * Next.js only accepts a statically analyzable `config.matcher` in the local
9
+ * middleware/proxy file. Do not import a matcher from this package — paste the
10
+ * recommended pattern inline (see README).
11
+ *
9
12
  * @example middleware.ts (Next ≤15)
10
13
  * ```ts
11
- * import {withDeploymentProtection, deploymentProtectionMatcher} from "@becklyn/deployment-protection";
14
+ * import {withDeploymentProtection} from "@becklyn/deployment-protection";
12
15
  * export default withDeploymentProtection();
13
- * export const config = { matcher: deploymentProtectionMatcher };
16
+ * export const config = {
17
+ * matcher: [
18
+ * "/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp|ico|css|js|map|txt|xml|woff2?)$).*)",
19
+ * ],
20
+ * };
14
21
  * ```
15
22
  *
16
23
  * @example proxy.ts (Next 16+)
17
24
  * ```ts
18
- * import {withDeploymentProtection, deploymentProtectionMatcher} from "@becklyn/deployment-protection";
25
+ * import {withDeploymentProtection} from "@becklyn/deployment-protection";
19
26
  * export const proxy = withDeploymentProtection();
20
- * export const config = { matcher: deploymentProtectionMatcher };
27
+ * export const config = {
28
+ * matcher: [
29
+ * "/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp|ico|css|js|map|txt|xml|woff2?)$).*)",
30
+ * ],
31
+ * };
21
32
  * ```
22
33
  */
23
34
  export declare function withDeploymentProtection(...args: WithDeploymentProtectionArgs): (request: NextRequest, event?: unknown) => Promise<Response | NextResponse>;
24
- export { deploymentProtectionMatcher };
35
+ export {};
25
36
  //# sourceMappingURL=middleware.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC;AAE1D,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,SAAS,CAAC;AAE3D,KAAK,cAAc,GAAG,CAClB,OAAO,EAAE,WAAW,EACpB,KAAK,CAAC,EAAE,OAAO,KAEb,QAAQ,GACR,YAAY,GACZ,OAAO,CAAC,QAAQ,GAAG,YAAY,GAAG,SAAS,GAAG,IAAI,CAAC,GACnD,SAAS,GACT,IAAI,CAAC;AAEX,MAAM,MAAM,4BAA4B,GAClC,EAAE,GACF,CAAC,2BAA2B,CAAC,GAC7B,CAAC,cAAc,CAAC,GAChB,CAAC,cAAc,EAAE,2BAA2B,CAAC,CAAC;AA8DpD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,wBAAwB,CAAC,GAAG,IAAI,EAAE,4BAA4B,IAgBtE,SAAS,WAAW,EACpB,QAAQ,OAAO,KAChB,OAAO,CAAC,QAAQ,GAAG,YAAY,CAAC,CActC;AAED,OAAO,EAAE,2BAA2B,EAAE,CAAC"}
1
+ {"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE7D,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,SAAS,CAAC;AAE3D,KAAK,cAAc,GAAG,CAClB,OAAO,EAAE,WAAW,EACpB,KAAK,CAAC,EAAE,OAAO,KAEb,QAAQ,GACR,YAAY,GACZ,OAAO,CAAC,QAAQ,GAAG,YAAY,GAAG,SAAS,GAAG,IAAI,CAAC,GACnD,SAAS,GACT,IAAI,CAAC;AAEX,MAAM,MAAM,4BAA4B,GAClC,EAAE,GACF,CAAC,2BAA2B,CAAC,GAC7B,CAAC,cAAc,CAAC,GAChB,CAAC,cAAc,EAAE,2BAA2B,CAAC,CAAC;AA8DpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,wBAAwB,CAAC,GAAG,IAAI,EAAE,4BAA4B,IAgBtE,SAAS,WAAW,EACpB,QAAQ,OAAO,KAChB,OAAO,CAAC,QAAQ,GAAG,YAAY,CAAC,CActC"}
@@ -1,5 +1,4 @@
1
1
  import { NextResponse } from "next/server";
2
- import { deploymentProtectionMatcher } from "./constants";
3
2
  import { handleDeploymentProtection } from "./handler";
4
3
  function isOptions(value) {
5
4
  return (typeof value === "object" &&
@@ -47,18 +46,30 @@ function copyHeaders(from, to, skipLocation) {
47
46
  /**
48
47
  * Next.js middleware / proxy wrapper.
49
48
  *
49
+ * Next.js only accepts a statically analyzable `config.matcher` in the local
50
+ * middleware/proxy file. Do not import a matcher from this package — paste the
51
+ * recommended pattern inline (see README).
52
+ *
50
53
  * @example middleware.ts (Next ≤15)
51
54
  * ```ts
52
- * import {withDeploymentProtection, deploymentProtectionMatcher} from "@becklyn/deployment-protection";
55
+ * import {withDeploymentProtection} from "@becklyn/deployment-protection";
53
56
  * export default withDeploymentProtection();
54
- * export const config = { matcher: deploymentProtectionMatcher };
57
+ * export const config = {
58
+ * matcher: [
59
+ * "/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp|ico|css|js|map|txt|xml|woff2?)$).*)",
60
+ * ],
61
+ * };
55
62
  * ```
56
63
  *
57
64
  * @example proxy.ts (Next 16+)
58
65
  * ```ts
59
- * import {withDeploymentProtection, deploymentProtectionMatcher} from "@becklyn/deployment-protection";
66
+ * import {withDeploymentProtection} from "@becklyn/deployment-protection";
60
67
  * export const proxy = withDeploymentProtection();
61
- * export const config = { matcher: deploymentProtectionMatcher };
68
+ * export const config = {
69
+ * matcher: [
70
+ * "/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp|ico|css|js|map|txt|xml|woff2?)$).*)",
71
+ * ],
72
+ * };
62
73
  * ```
63
74
  */
64
75
  export function withDeploymentProtection(...args) {
@@ -88,4 +99,3 @@ export function withDeploymentProtection(...args) {
88
99
  return NextResponse.next();
89
100
  };
90
101
  }
91
- export { deploymentProtectionMatcher };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@becklyn/deployment-protection",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "license": "MIT",
5
5
  "description": "Simple shared username/password + Sign in with Vercel gate for Next.js deployments",
6
6
  "homepage": "https://github.com/Becklyn-Studios/ts-libs/tree/main/packages/deployment-protection",