@appwarden/middleware 1.4.3 → 1.5.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-92.74%25-brightgreen)
3
+ ![Test Coverage](https://img.shields.io/badge/coverage-97.14%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)
@@ -49,6 +49,7 @@ var CSPModeSchema = z2.union([
49
49
  z2.literal("enforced")
50
50
  ]).optional().default("disabled");
51
51
  var UseCSPInputSchema = z2.object({
52
+ hostname: z2.string().optional(),
52
53
  mode: CSPModeSchema,
53
54
  directives: CSPDirectivesSchema.optional().refine(
54
55
  (val) => {
@@ -114,6 +115,9 @@ var useContentSecurityPolicy = (input) => {
114
115
  const config = parsedInput.data;
115
116
  return async (context, next) => {
116
117
  await next();
118
+ if (config.hostname && context.hostname !== config.hostname) {
119
+ return;
120
+ }
117
121
  const { response } = context;
118
122
  if (
119
123
  // if the csp is disabled
package/cloudflare.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { B as Bindings } from './cloudflare-2PkEr25r.js';
2
2
  import { z } from 'zod';
3
- import { M as Middleware } from './use-content-security-policy-C89AROtC.js';
4
- export { u as useContentSecurityPolicy } from './use-content-security-policy-C89AROtC.js';
3
+ import { M as Middleware } from './use-content-security-policy-Cgy0nz3J.js';
4
+ export { u as useContentSecurityPolicy } from './use-content-security-policy-Cgy0nz3J.js';
5
5
 
6
6
  declare const ConfigFnInputSchema: z.ZodFunction<z.ZodTuple<[z.ZodType<{
7
7
  env: CloudflareEnv;
@@ -11,9 +11,16 @@ declare const ConfigFnInputSchema: z.ZodFunction<z.ZodTuple<[z.ZodType<{
11
11
  env: CloudflareEnv;
12
12
  cf: Record<string, unknown>;
13
13
  ctx: unknown;
14
- }>], z.ZodUnknown>, z.ZodObject<{
14
+ }>], z.ZodUnknown>, z.ZodEffects<z.ZodObject<{
15
15
  debug: z.ZodDefault<z.ZodEffects<z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodBoolean]>>, boolean, string | boolean | undefined>>;
16
- lockPageSlug: z.ZodString;
16
+ lockPageSlug: z.ZodOptional<z.ZodString>;
17
+ multidomainConfig: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
18
+ lockPageSlug: z.ZodString;
19
+ }, "strip", z.ZodTypeAny, {
20
+ lockPageSlug: string;
21
+ }, {
22
+ lockPageSlug: string;
23
+ }>>>;
17
24
  appwardenApiToken: z.ZodEffects<z.ZodString, string, string>;
18
25
  } & {
19
26
  middleware: z.ZodDefault<z.ZodObject<{
@@ -25,19 +32,25 @@ declare const ConfigFnInputSchema: z.ZodFunction<z.ZodTuple<[z.ZodType<{
25
32
  }>>;
26
33
  }, "strip", z.ZodTypeAny, {
27
34
  debug: boolean;
28
- lockPageSlug: string;
29
35
  appwardenApiToken: string;
30
36
  middleware: {
31
37
  before: Middleware[];
32
38
  };
39
+ lockPageSlug?: string | undefined;
40
+ multidomainConfig?: Record<string, {
41
+ lockPageSlug: string;
42
+ }> | undefined;
33
43
  }, {
34
- lockPageSlug: string;
35
44
  appwardenApiToken: string;
45
+ lockPageSlug?: string | undefined;
36
46
  debug?: string | boolean | undefined;
47
+ multidomainConfig?: Record<string, {
48
+ lockPageSlug: string;
49
+ }> | undefined;
37
50
  middleware?: {
38
51
  before?: Middleware[] | undefined;
39
52
  } | undefined;
40
- }>>;
53
+ }>, any, any>>;
41
54
  type CloudflareConfigType = ReturnType<z.infer<typeof ConfigFnInputSchema>>;
42
55
 
43
56
  declare const withAppwarden: (inputFn: CloudflareConfigType) => ExportedHandlerFetchHandler<Bindings>;
package/cloudflare.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  useContentSecurityPolicy
3
- } from "./chunk-GTGPYCQY.js";
3
+ } from "./chunk-TP5CHUTK.js";
4
4
  import {
5
5
  BooleanSchema,
6
6
  LockValue,
@@ -23,17 +23,32 @@ import { z as z2 } from "zod";
23
23
 
24
24
  // src/schemas/use-appwarden.ts
25
25
  import { z } from "zod";
26
+ var AppwardenMultidomainConfigSchema = z.record(
27
+ z.string(),
28
+ z.object({
29
+ lockPageSlug: z.string()
30
+ })
31
+ );
26
32
  var UseAppwardenInputSchema = z.object({
27
33
  debug: BooleanSchema.default(false),
28
- lockPageSlug: z.string(),
34
+ lockPageSlug: z.string().optional(),
35
+ multidomainConfig: AppwardenMultidomainConfigSchema.optional(),
29
36
  appwardenApiToken: z.string().refine((val) => !!val, { path: ["appwardenApiToken"] })
30
37
  });
38
+ var lockPageSlugRefinement = (schema) => schema.refine(
39
+ (data) => data.lockPageSlug || data.multidomainConfig,
40
+ {
41
+ message: "Either lockPageSlug or multidomainConfig must be provided"
42
+ }
43
+ );
31
44
 
32
45
  // src/schemas/cloudflare.ts
33
46
  var ConfigFnInputSchema = z2.function().args(z2.custom()).returns(
34
- UseAppwardenInputSchema.extend({
35
- middleware: z2.object({ before: z2.custom().array().default([]) }).default({})
36
- })
47
+ lockPageSlugRefinement(
48
+ UseAppwardenInputSchema.extend({
49
+ middleware: z2.object({ before: z2.custom().array().default([]) }).default({})
50
+ })
51
+ )
37
52
  );
38
53
 
39
54
  // src/utils/middleware.ts
@@ -312,6 +327,10 @@ var useAppwarden = (input) => async (context, next) => {
312
327
  const isHTMLRequest = response.headers.get("Content-Type")?.includes("text/html");
313
328
  const isMonitoringRequest = request.headers.get("User-Agent") === APPWARDEN_USER_AGENT;
314
329
  if (isHTMLRequest && !isMonitoringRequest) {
330
+ const lockPageSlug = input.multidomainConfig?.[requestUrl.hostname]?.lockPageSlug ?? input.lockPageSlug;
331
+ if (!lockPageSlug) {
332
+ return;
333
+ }
315
334
  const innerContext = {
316
335
  keyName,
317
336
  request,
@@ -319,7 +338,7 @@ var useAppwarden = (input) => async (context, next) => {
319
338
  requestUrl,
320
339
  provider,
321
340
  debug: input.debug,
322
- lockPageSlug: input.lockPageSlug,
341
+ lockPageSlug,
323
342
  appwardenApiToken: input.appwardenApiToken,
324
343
  waitUntil: (fn) => context.waitUntil(fn)
325
344
  };
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
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-C89AROtC.js';
2
+ export { C as CSPDirectivesSchema, a as CSPModeSchema, M as Middleware, u as useContentSecurityPolicy } from './use-content-security-policy-Cgy0nz3J.js';
3
3
  import { z } from 'zod';
4
4
 
5
5
  declare const LOCKDOWN_TEST_EXPIRY_MS: number;
package/index.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  CSPDirectivesSchema,
8
8
  CSPModeSchema,
9
9
  useContentSecurityPolicy
10
- } from "./chunk-GTGPYCQY.js";
10
+ } from "./chunk-TP5CHUTK.js";
11
11
  import {
12
12
  APPWARDEN_CACHE_KEY,
13
13
  APPWARDEN_USER_AGENT,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appwarden/middleware",
3
- "version": "1.4.3",
3
+ "version": "1.5.0",
4
4
  "description": "Instantly shut off access your app deployed on Cloudflare or Vercel",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -95,6 +95,7 @@ declare const CSPDirectivesSchema: z.ZodUnion<[z.ZodString, z.ZodObject<{
95
95
  }>]>;
96
96
  declare const CSPModeSchema: z.ZodDefault<z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"disabled">, z.ZodLiteral<"report-only">, z.ZodLiteral<"enforced">]>>>;
97
97
  declare const UseCSPInputSchema: z.ZodEffects<z.ZodObject<{
98
+ hostname: z.ZodOptional<z.ZodString>;
98
99
  mode: z.ZodDefault<z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"disabled">, z.ZodLiteral<"report-only">, z.ZodLiteral<"enforced">]>>>;
99
100
  directives: z.ZodEffects<z.ZodEffects<z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodObject<{
100
101
  "default-src": z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodString, z.ZodBoolean]>>;
@@ -316,6 +317,7 @@ declare const UseCSPInputSchema: z.ZodEffects<z.ZodObject<{
316
317
  "trusted-types"?: string | boolean | string[] | undefined;
317
318
  "require-trusted-types-for"?: string | boolean | string[] | undefined;
318
319
  } | undefined;
320
+ hostname?: string | undefined;
319
321
  }, {
320
322
  mode?: "disabled" | "report-only" | "enforced" | undefined;
321
323
  directives?: string | {
@@ -346,6 +348,7 @@ declare const UseCSPInputSchema: z.ZodEffects<z.ZodObject<{
346
348
  "trusted-types"?: string | boolean | string[] | undefined;
347
349
  "require-trusted-types-for"?: string | boolean | string[] | undefined;
348
350
  } | undefined;
351
+ hostname?: string | undefined;
349
352
  }>, {
350
353
  mode: "disabled" | "report-only" | "enforced";
351
354
  directives?: {
@@ -376,6 +379,7 @@ declare const UseCSPInputSchema: z.ZodEffects<z.ZodObject<{
376
379
  "trusted-types"?: string | boolean | string[] | undefined;
377
380
  "require-trusted-types-for"?: string | boolean | string[] | undefined;
378
381
  } | undefined;
382
+ hostname?: string | undefined;
379
383
  }, {
380
384
  mode?: "disabled" | "report-only" | "enforced" | undefined;
381
385
  directives?: string | {
@@ -406,6 +410,7 @@ declare const UseCSPInputSchema: z.ZodEffects<z.ZodObject<{
406
410
  "trusted-types"?: string | boolean | string[] | undefined;
407
411
  "require-trusted-types-for"?: string | boolean | string[] | undefined;
408
412
  } | undefined;
413
+ hostname?: string | undefined;
409
414
  }>;
410
415
  type UseCSPInput = z.infer<typeof UseCSPInputSchema>;
411
416