@appwarden/middleware 3.0.0 → 3.0.2

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.
@@ -0,0 +1,50 @@
1
+ import {
2
+ getErrors
3
+ } from "./chunk-B5IE7V77.js";
4
+ import {
5
+ printMessage
6
+ } from "./chunk-7UTT3M2S.js";
7
+
8
+ // src/utils/build-lock-page-url.ts
9
+ function normalizeLockPageSlug(lockPageSlug) {
10
+ return lockPageSlug.startsWith("/") ? lockPageSlug : `/${lockPageSlug}`;
11
+ }
12
+ function buildLockPageUrl(lockPageSlug, requestUrl) {
13
+ const normalizedSlug = normalizeLockPageSlug(lockPageSlug);
14
+ return new URL(normalizedSlug, requestUrl);
15
+ }
16
+ function normalizeTrailingSlash(path) {
17
+ if (path === "/") return path;
18
+ return path.endsWith("/") ? path.slice(0, -1) : path;
19
+ }
20
+ function isOnLockPage(lockPageSlug, requestUrl) {
21
+ const normalizedSlug = normalizeTrailingSlash(
22
+ normalizeLockPageSlug(lockPageSlug)
23
+ );
24
+ const url = typeof requestUrl === "string" ? new URL(requestUrl) : requestUrl;
25
+ const normalizedPathname = normalizeTrailingSlash(url.pathname);
26
+ return normalizedPathname === normalizedSlug;
27
+ }
28
+
29
+ // src/utils/validate-config.ts
30
+ function validateConfig(config, schema) {
31
+ const result = schema.safeParse(config);
32
+ const hasErrors = !result.success;
33
+ if (hasErrors) {
34
+ const mappedErrors = getErrors(result.error);
35
+ if (mappedErrors.length > 0) {
36
+ for (const error of mappedErrors) {
37
+ console.error(printMessage(error));
38
+ }
39
+ } else {
40
+ console.error(printMessage(result.error.message));
41
+ }
42
+ }
43
+ return hasErrors;
44
+ }
45
+
46
+ export {
47
+ buildLockPageUrl,
48
+ isOnLockPage,
49
+ validateConfig
50
+ };
@@ -1,9 +1,3 @@
1
- // src/utils/build-lock-page-url.ts
2
- function buildLockPageUrl(lockPageSlug, requestUrl) {
3
- const normalizedSlug = lockPageSlug.startsWith("/") ? lockPageSlug : `/${lockPageSlug}`;
4
- return new URL(normalizedSlug, requestUrl);
5
- }
6
-
7
1
  // src/utils/create-redirect.ts
8
2
  var TEMPORARY_REDIRECT_STATUS = 302;
9
3
  var createRedirect = (url) => {
@@ -16,7 +10,6 @@ var createRedirect = (url) => {
16
10
  };
17
11
 
18
12
  export {
19
- buildLockPageUrl,
20
13
  TEMPORARY_REDIRECT_STATUS,
21
14
  createRedirect
22
15
  };
@@ -1,11 +1,12 @@
1
1
  import {
2
2
  TEMPORARY_REDIRECT_STATUS,
3
- buildLockPageUrl,
4
3
  createRedirect
5
- } from "../chunk-N6AUTMZO.js";
4
+ } from "../chunk-6M7BE3AW.js";
6
5
  import {
6
+ buildLockPageUrl,
7
+ isOnLockPage,
7
8
  validateConfig
8
- } from "../chunk-6PUA5YXP.js";
9
+ } from "../chunk-4JGYMZTR.js";
9
10
  import {
10
11
  checkLockStatus
11
12
  } from "../chunk-5DEXVBY6.js";
@@ -54,6 +55,9 @@ function createAppwardenMiddleware(configFn) {
54
55
  if (hasError) {
55
56
  return next();
56
57
  }
58
+ if (isOnLockPage(config.lockPageSlug, request.url)) {
59
+ return next();
60
+ }
57
61
  const result = await checkLockStatus({
58
62
  request,
59
63
  appwardenApiToken: config.appwardenApiToken,
@@ -1,10 +1,11 @@
1
1
  import {
2
- TEMPORARY_REDIRECT_STATUS,
3
- buildLockPageUrl
4
- } from "../chunk-N6AUTMZO.js";
2
+ TEMPORARY_REDIRECT_STATUS
3
+ } from "../chunk-6M7BE3AW.js";
5
4
  import {
5
+ buildLockPageUrl,
6
+ isOnLockPage,
6
7
  validateConfig
7
- } from "../chunk-6PUA5YXP.js";
8
+ } from "../chunk-4JGYMZTR.js";
8
9
  import {
9
10
  checkLockStatus
10
11
  } from "../chunk-5DEXVBY6.js";
@@ -49,6 +50,9 @@ function createAppwardenMiddleware(configFn) {
49
50
  if (hasError) {
50
51
  return NextResponse.next();
51
52
  }
53
+ if (isOnLockPage(config.lockPageSlug, request.url)) {
54
+ return NextResponse.next();
55
+ }
52
56
  const result = await checkLockStatus({
53
57
  request,
54
58
  appwardenApiToken: config.appwardenApiToken,
@@ -1,10 +1,11 @@
1
1
  import {
2
- buildLockPageUrl,
3
2
  createRedirect
4
- } from "../chunk-N6AUTMZO.js";
3
+ } from "../chunk-6M7BE3AW.js";
5
4
  import {
5
+ buildLockPageUrl,
6
+ isOnLockPage,
6
7
  validateConfig
7
- } from "../chunk-6PUA5YXP.js";
8
+ } from "../chunk-4JGYMZTR.js";
8
9
  import {
9
10
  checkLockStatus
10
11
  } from "../chunk-5DEXVBY6.js";
@@ -52,6 +53,9 @@ function createAppwardenMiddleware(configFn) {
52
53
  if (hasError) {
53
54
  return next();
54
55
  }
56
+ if (isOnLockPage(config.lockPageSlug, request.url)) {
57
+ return next();
58
+ }
55
59
  const result = await checkLockStatus({
56
60
  request,
57
61
  appwardenApiToken: config.appwardenApiToken,
@@ -1,10 +1,11 @@
1
1
  import {
2
- buildLockPageUrl,
3
2
  createRedirect
4
- } from "../chunk-N6AUTMZO.js";
3
+ } from "../chunk-6M7BE3AW.js";
5
4
  import {
5
+ buildLockPageUrl,
6
+ isOnLockPage,
6
7
  validateConfig
7
- } from "../chunk-6PUA5YXP.js";
8
+ } from "../chunk-4JGYMZTR.js";
8
9
  import {
9
10
  checkLockStatus
10
11
  } from "../chunk-5DEXVBY6.js";
@@ -55,6 +56,9 @@ function createAppwardenMiddleware(configFn) {
55
56
  if (hasError) {
56
57
  return next();
57
58
  }
59
+ if (isOnLockPage(config.lockPageSlug, request.url)) {
60
+ return next();
61
+ }
58
62
  const result = await checkLockStatus({
59
63
  request,
60
64
  appwardenApiToken: config.appwardenApiToken,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appwarden/middleware",
3
- "version": "3.0.0",
3
+ "version": "3.0.2",
4
4
  "description": "Instantly shut off access your app deployed on Cloudflare or Vercel",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/vercel.js CHANGED
@@ -3,8 +3,9 @@ import {
3
3
  isValidCacheUrl
4
4
  } from "./chunk-QEFORWCW.js";
5
5
  import {
6
+ isOnLockPage,
6
7
  validateConfig
7
- } from "./chunk-6PUA5YXP.js";
8
+ } from "./chunk-4JGYMZTR.js";
8
9
  import {
9
10
  LockValue,
10
11
  MemoryCache
@@ -210,6 +211,9 @@ function createAppwardenMiddleware(config) {
210
211
  if (!parsedConfig.lockPageSlug) {
211
212
  return NextResponse.next();
212
213
  }
214
+ if (isOnLockPage(parsedConfig.lockPageSlug, request.url)) {
215
+ return NextResponse.next();
216
+ }
213
217
  const provider = isCacheUrl.edgeConfig(parsedConfig.cacheUrl) ? "edge-config" : "upstash";
214
218
  const cacheValue = memoryCache.get(APPWARDEN_CACHE_KEY);
215
219
  const shouldRecheck = MemoryCache.isExpired(cacheValue);
package/chunk-6PUA5YXP.js DELETED
@@ -1,27 +0,0 @@
1
- import {
2
- getErrors
3
- } from "./chunk-B5IE7V77.js";
4
- import {
5
- printMessage
6
- } from "./chunk-7UTT3M2S.js";
7
-
8
- // src/utils/validate-config.ts
9
- function validateConfig(config, schema) {
10
- const result = schema.safeParse(config);
11
- const hasErrors = !result.success;
12
- if (hasErrors) {
13
- const mappedErrors = getErrors(result.error);
14
- if (mappedErrors.length > 0) {
15
- for (const error of mappedErrors) {
16
- console.error(printMessage(error));
17
- }
18
- } else {
19
- console.error(printMessage(result.error.message));
20
- }
21
- }
22
- return hasErrors;
23
- }
24
-
25
- export {
26
- validateConfig
27
- };