@appwarden/middleware 1.5.0 → 1.5.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,6 +1,6 @@
1
1
  # @appwarden/middleware
2
2
 
3
- ![Test Coverage](https://img.shields.io/badge/coverage-97.14%25-brightgreen)
3
+ ![Test Coverage](https://img.shields.io/badge/coverage-97%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)
@@ -94,6 +94,7 @@ type Bindings = {
94
94
  CSP_MODE: "disabled" | "report-only" | "enforced";
95
95
  CSP_DIRECTIVES: string | ContentSecurityPolicyType;
96
96
  APPWARDEN_API_TOKEN: string;
97
+ APPWARDEN_API_HOSTNAME?: string;
97
98
  };
98
99
 
99
100
  export type { Bindings as B };
package/cloudflare.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { B as Bindings } from './cloudflare-2PkEr25r.js';
1
+ import { B as Bindings } from './cloudflare-0sboFQGC.js';
2
2
  import { z } from 'zod';
3
- import { M as Middleware } from './use-content-security-policy-Cgy0nz3J.js';
4
- export { u as useContentSecurityPolicy } from './use-content-security-policy-Cgy0nz3J.js';
3
+ import { M as Middleware } from './use-content-security-policy-D4ccKJVd.js';
4
+ export { u as useContentSecurityPolicy } from './use-content-security-policy-D4ccKJVd.js';
5
5
 
6
6
  declare const ConfigFnInputSchema: z.ZodFunction<z.ZodTuple<[z.ZodType<{
7
7
  env: CloudflareEnv;
@@ -22,6 +22,7 @@ declare const ConfigFnInputSchema: z.ZodFunction<z.ZodTuple<[z.ZodType<{
22
22
  lockPageSlug: string;
23
23
  }>>>;
24
24
  appwardenApiToken: z.ZodEffects<z.ZodString, string, string>;
25
+ appwardenApiHostname: z.ZodOptional<z.ZodString>;
25
26
  } & {
26
27
  middleware: z.ZodDefault<z.ZodObject<{
27
28
  before: z.ZodDefault<z.ZodArray<z.ZodType<Middleware, z.ZodTypeDef, Middleware>, "many">>;
@@ -40,6 +41,7 @@ declare const ConfigFnInputSchema: z.ZodFunction<z.ZodTuple<[z.ZodType<{
40
41
  multidomainConfig?: Record<string, {
41
42
  lockPageSlug: string;
42
43
  }> | undefined;
44
+ appwardenApiHostname?: string | undefined;
43
45
  }, {
44
46
  appwardenApiToken: string;
45
47
  lockPageSlug?: string | undefined;
@@ -47,6 +49,7 @@ declare const ConfigFnInputSchema: z.ZodFunction<z.ZodTuple<[z.ZodType<{
47
49
  multidomainConfig?: Record<string, {
48
50
  lockPageSlug: string;
49
51
  }> | undefined;
52
+ appwardenApiHostname?: string | undefined;
50
53
  middleware?: {
51
54
  before?: Middleware[] | undefined;
52
55
  } | undefined;
package/cloudflare.js CHANGED
@@ -33,12 +33,13 @@ var UseAppwardenInputSchema = z.object({
33
33
  debug: BooleanSchema.default(false),
34
34
  lockPageSlug: z.string().optional(),
35
35
  multidomainConfig: AppwardenMultidomainConfigSchema.optional(),
36
- appwardenApiToken: z.string().refine((val) => !!val, { path: ["appwardenApiToken"] })
36
+ appwardenApiToken: z.string().refine((val) => !!val, { path: ["appwardenApiToken"] }),
37
+ appwardenApiHostname: z.string().optional()
37
38
  });
38
39
  var lockPageSlugRefinement = (schema) => schema.refine(
39
40
  (data) => data.lockPageSlug || data.multidomainConfig,
40
41
  {
41
- message: "Either lockPageSlug or multidomainConfig must be provided"
42
+ message: "lockPageSlug must be provided"
42
43
  }
43
44
  );
44
45
 
@@ -213,10 +214,12 @@ var APIError = class extends Error {
213
214
  this.name = "APIError";
214
215
  }
215
216
  };
217
+ var DEFAULT_API_HOSTNAME = "https://api.appwarden.io";
216
218
  var syncEdgeValue = async (context) => {
217
219
  debug(`syncing with api`);
218
220
  try {
219
- const response = await fetch(new URL("/v1/status/check", "https://api.appwarden.io"), {
221
+ const apiHostname = context.appwardenApiHostname ?? DEFAULT_API_HOSTNAME;
222
+ const response = await fetch(new URL("/v1/status/check", apiHostname), {
220
223
  method: "POST",
221
224
  headers: { "content-type": "application/json" },
222
225
  body: JSON.stringify({
@@ -340,6 +343,7 @@ var useAppwarden = (input) => async (context, next) => {
340
343
  debug: input.debug,
341
344
  lockPageSlug,
342
345
  appwardenApiToken: input.appwardenApiToken,
346
+ appwardenApiHostname: input.appwardenApiHostname,
343
347
  waitUntil: (fn) => context.waitUntil(fn)
344
348
  };
345
349
  await maybeQuarantine(innerContext, {
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export { B as Bindings } from './cloudflare-2PkEr25r.js';
2
- export { C as CSPDirectivesSchema, a as CSPModeSchema, M as Middleware, u as useContentSecurityPolicy } from './use-content-security-policy-Cgy0nz3J.js';
1
+ export { B as Bindings } from './cloudflare-0sboFQGC.js';
2
+ export { C as CSPDirectivesSchema, a as CSPModeSchema, M as Middleware, u as useContentSecurityPolicy } from './use-content-security-policy-D4ccKJVd.js';
3
3
  import { z } from 'zod';
4
4
 
5
5
  declare const LOCKDOWN_TEST_EXPIRY_MS: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appwarden/middleware",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "Instantly shut off access your app deployed on Cloudflare or Vercel",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -1,4 +1,4 @@
1
- import './cloudflare-2PkEr25r.js';
1
+ import './cloudflare-0sboFQGC.js';
2
2
  import { z } from 'zod';
3
3
 
4
4
  interface MiddlewareContext {
package/vercel.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as next_dist_server_web_types from 'next/dist/server/web/types';
2
2
  import * as next_server from 'next/server';
3
- import './cloudflare-2PkEr25r.js';
3
+ import './cloudflare-0sboFQGC.js';
4
4
  import { z } from 'zod';
5
5
 
6
6
  declare const BaseNextJsConfigSchema: z.ZodObject<{