@appwarden/middleware 2.0.0 → 3.0.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
@@ -1,6 +1,6 @@
1
1
  # @appwarden/middleware
2
2
 
3
- ![Test Coverage](https://img.shields.io/badge/coverage-95.82%25-brightgreen)
3
+ ![Test Coverage](https://img.shields.io/badge/coverage-95.95%25-brightgreen)
4
4
  [![npm version](https://img.shields.io/npm/v/@appwarden/middleware.svg)](https://www.npmjs.com/package/@appwarden/middleware)
5
5
  [![npm provenance](https://img.shields.io/badge/npm-provenance-green)](https://docs.npmjs.com/generating-provenance-statements)
6
6
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
@@ -1,11 +1,13 @@
1
+ import { Runtime } from '@astrojs/cloudflare';
2
+ import { APIContext, MiddlewareHandler } from 'astro';
3
+
1
4
  /**
2
5
  * Cloudflare runtime context provided by Astro on Cloudflare Workers.
3
- * This is the shape of `context.locals.runtime` when using @astrojs/cloudflare adapter.
6
+ * This is extracted from the locals object when using @astrojs/cloudflare adapter.
7
+ *
8
+ * Note: Uses generic CloudflareEnv which should be defined in the user's project.
4
9
  */
5
- interface AstroCloudflareRuntime {
6
- env: CloudflareEnv;
7
- ctx: ExecutionContext;
8
- }
10
+ type AstroCloudflareRuntime = Runtime<CloudflareEnv>["runtime"];
9
11
  /**
10
12
  * Configuration for the Appwarden middleware.
11
13
  */
@@ -26,24 +28,18 @@ interface AstroAppwardenConfig {
26
28
  type AstroConfigFn = (runtime: AstroCloudflareRuntime) => AstroAppwardenConfig;
27
29
  /**
28
30
  * Astro middleware context type.
29
- * This matches Astro's APIContext shape for middleware.
31
+ * Re-exported from Astro's official APIContext type for type compatibility.
32
+ *
33
+ * @deprecated Use `APIContext` from 'astro' directly. This alias is kept for backward compatibility.
30
34
  */
31
- interface AstroMiddlewareContext {
32
- /** The incoming request */
33
- request: Request;
34
- /** Object for storing request-specific data */
35
- locals: {
36
- runtime?: AstroCloudflareRuntime;
37
- [key: string]: unknown;
38
- };
39
- /** Helper to create redirect responses */
40
- redirect: (path: string, status?: number) => Response;
41
- }
35
+ type AstroMiddlewareContext = APIContext;
42
36
  /**
43
37
  * Astro middleware function signature.
44
- * This matches the onRequest export type in Astro's middleware system.
38
+ * This is an alias for Astro's official MiddlewareHandler type for type compatibility.
39
+ *
40
+ * @deprecated Use `MiddlewareHandler` from 'astro' directly. This alias is kept for backward compatibility.
45
41
  */
46
- type AstroMiddlewareFunction = (context: AstroMiddlewareContext, next: () => Promise<Response>) => Promise<Response>;
42
+ type AstroMiddlewareFunction = MiddlewareHandler;
47
43
  /**
48
44
  * Creates an Appwarden middleware function for Astro.
49
45
  *
@@ -67,6 +63,6 @@ type AstroMiddlewareFunction = (context: AstroMiddlewareContext, next: () => Pro
67
63
  * @param configFn - A function that receives the Cloudflare runtime and returns the config
68
64
  * @returns An Astro middleware function
69
65
  */
70
- declare function createAppwardenMiddleware(configFn: AstroConfigFn): AstroMiddlewareFunction;
66
+ declare function createAppwardenMiddleware(configFn: AstroConfigFn): MiddlewareHandler;
71
67
 
72
68
  export { type AstroAppwardenConfig, type AstroCloudflareRuntime, type AstroConfigFn, type AstroMiddlewareContext, type AstroMiddlewareFunction, createAppwardenMiddleware };
@@ -34,7 +34,8 @@ var AstroCloudflareConfigSchema = z.object({
34
34
  // src/adapters/astro-cloudflare.ts
35
35
  function createAppwardenMiddleware(configFn) {
36
36
  return async (context, next) => {
37
- const { request, locals } = context;
37
+ const { request } = context;
38
+ const locals = context.locals;
38
39
  try {
39
40
  const runtime = locals.runtime;
40
41
  if (!runtime) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appwarden/middleware",
3
- "version": "2.0.0",
3
+ "version": "3.0.0",
4
4
  "description": "Instantly shut off access your app deployed on Cloudflare or Vercel",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -63,11 +63,19 @@
63
63
  "zod": "^3.25.76"
64
64
  },
65
65
  "peerDependencies": {
66
+ "@astrojs/cloudflare": ">=11.0.0",
66
67
  "@opennextjs/cloudflare": ">=1.0.0",
67
68
  "@vercel/functions": ">=1.0.0",
69
+ "astro": ">=4.0.0",
68
70
  "next": ">=14"
69
71
  },
70
72
  "peerDependenciesMeta": {
73
+ "astro": {
74
+ "optional": true
75
+ },
76
+ "@astrojs/cloudflare": {
77
+ "optional": true
78
+ },
71
79
  "next": {
72
80
  "optional": true
73
81
  },
@@ -94,7 +102,8 @@
94
102
  "jws@=4.0.0": ">=4.0.1",
95
103
  "@smithy/config-resolver@<4.4.0": ">=4.4.0",
96
104
  "@isaacs/brace-expansion@<=5.0.0": ">=5.0.1",
97
- "npm@<=11.8.0": ">=11.9.0"
105
+ "npm@<=11.8.0": ">=11.9.0",
106
+ "wrangler@>=4.0.0 <4.59.1": ">=4.59.1"
98
107
  }
99
108
  }
100
109
  }