@appwarden/middleware 1.1.3 → 1.1.5

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,5 +1,25 @@
1
1
  # @appwarden/middleware
2
2
 
3
- Instantly shut off all access to a domain from your Discord server.
3
+ > Read the docs [to learn more](https://appwarden.io/docs)
4
4
 
5
- Read the docs [to get started](https://appwarden.io/docs/getting-started#for-projects-deployed-on-cloudflare-pages)
5
+ ## Stop in progress attacks in their tracks
6
+
7
+ Instantly halt all external access to a domain from your Discord server
8
+
9
+ ```
10
+ /quarantine lock your.app.io
11
+ ```
12
+
13
+ ## Installation
14
+
15
+ Compatible with websites powered by [Cloudflare](https://developers.cloudflare.com/pages/) or [Vercel](https://vercel.com).
16
+
17
+ ### Cloudflare
18
+
19
+ We recommend using the [`@appwarden/build-cloudflare-action`](https://github.com/appwarden/build-cloudflare-action) Github Action to deploy on Cloudflare.
20
+
21
+ > Read the docs [to get started](https://appwarden.io/docs/guides/cloudflare-integration)
22
+
23
+ ### Vercel
24
+
25
+ > Read the docs [to get started](https://appwarden.io/docs/guides/vercel-integration)
@@ -10,7 +10,7 @@ import {
10
10
  printMessage,
11
11
  removedHeaders,
12
12
  renderLockPage
13
- } from "./chunk-5UMKWIJW.js";
13
+ } from "./chunk-GC5FS43G.js";
14
14
 
15
15
  // src/utils/cloudflare/cloudflare-cache.ts
16
16
  var store = {
@@ -18,12 +18,7 @@ var store = {
18
18
  const cacheKeyUrl = new URL(cacheKey, context.serviceOrigin);
19
19
  return {
20
20
  getValue: () => getCacheValue(context, cacheKeyUrl),
21
- updateValue: (json) => updateCacheValue(
22
- context,
23
- cacheKeyUrl,
24
- json,
25
- options?.cacheExpirationSeconds
26
- ),
21
+ updateValue: (json) => updateCacheValue(context, cacheKeyUrl, json, options?.ttl),
27
22
  deleteValue: () => clearCache(context, cacheKeyUrl)
28
23
  };
29
24
  }
@@ -37,20 +32,20 @@ var getCacheValue = async (context, cacheKey) => {
37
32
  debug(`[${cacheKey.pathname}] Cache MATCH!`);
38
33
  return match;
39
34
  };
40
- var updateCacheValue = async (context, cacheKey, value, cacheExpirationSeconds) => {
35
+ var updateCacheValue = async (context, cacheKey, value, ttl) => {
41
36
  debug(
42
37
  "updating cache...",
43
- cacheKey.pathname,
38
+ cacheKey.href,
44
39
  value,
45
- cacheExpirationSeconds ? `expires in ${cacheExpirationSeconds}s` : ""
40
+ ttl ? `expires in ${ttl}s` : ""
46
41
  );
47
42
  await context.cache.put(
48
43
  cacheKey,
49
44
  new Response(JSON.stringify(value), {
50
45
  headers: {
51
46
  "content-type": "application/json",
52
- ...cacheExpirationSeconds && {
53
- "cache-control": `max-age=${cacheExpirationSeconds}`
47
+ ...ttl && {
48
+ "cache-control": `max-age=${ttl}`
54
49
  }
55
50
  }
56
51
  })
@@ -85,8 +80,8 @@ var getLockValue = async (context) => {
85
80
  try {
86
81
  let shouldDeleteEdgeValue = false;
87
82
  let cacheResponse, lockValue = {
88
- isLockedTest: 0,
89
83
  isLocked: 0,
84
+ isLockedTest: 0,
90
85
  lastCheck: Date.now(),
91
86
  code: ""
92
87
  };
@@ -128,7 +123,7 @@ var getLockValue = async (context) => {
128
123
  var insertErrorLogs = async (context, error) => {
129
124
  const errors = getErrors(error);
130
125
  for (const err of errors) {
131
- console.error(printMessage(err));
126
+ console.log(printMessage(err));
132
127
  }
133
128
  return new HTMLRewriter().on("body", {
134
129
  element: (elem) => {
@@ -197,21 +192,20 @@ var syncEdgeValue = async (context) => {
197
192
  if (result.error) {
198
193
  throw new APIError(result.error.message);
199
194
  }
200
- if (result.content) {
201
- try {
202
- const parsedValue = LockValue.omit({ lastCheck: true }).parse(
203
- result.content
204
- );
205
- debug(
206
- `syncing with api...DONE ${JSON.stringify(parsedValue, null, 2)}`
207
- );
208
- await context.edgeCache.updateValue({
209
- ...parsedValue,
210
- lastCheck: Date.now()
211
- });
212
- } catch (error) {
213
- throw new APIError(`Failed to parse check endpoint result - ${error}`);
214
- }
195
+ if (!result.content) {
196
+ throw new APIError("no content from api");
197
+ }
198
+ try {
199
+ const parsedValue = LockValue.omit({ lastCheck: true }).parse(
200
+ result.content
201
+ );
202
+ debug(`syncing with api...DONE ${JSON.stringify(parsedValue, null, 2)}`);
203
+ await context.edgeCache.updateValue({
204
+ ...parsedValue,
205
+ lastCheck: Date.now()
206
+ });
207
+ } catch (error) {
208
+ throw new APIError(`Failed to parse check endpoint result - ${error}`);
215
209
  }
216
210
  }
217
211
  } catch (e) {
@@ -89,7 +89,7 @@ var errorsMap = {
89
89
  ["DirectivesRequired" /* DirectivesRequired */]: '`CSP_DIRECTIVES` must be provided when `CSP_MODE` is "report-only" or "enforced"',
90
90
  ["DirectivesBadParse" /* DirectivesBadParse */]: "Failed to parse `CSP_DIRECTIVES`. Is it a valid JSON string?"
91
91
  },
92
- appwardenApiToken: "Please provide a valid `appwardenApiToken`. Learn more at https://appwarden.com/docs/api-tokens."
92
+ appwardenApiToken: "Please provide a valid `appwardenApiToken`. Learn more at https://appwarden.com/docs/guides/api-token-management."
93
93
  };
94
94
  var getErrors = (error) => {
95
95
  const matches = [];
@@ -308,7 +308,7 @@ var AppwardenConfigSchema = BaseNextJsConfigSchema.refine(
308
308
  }
309
309
  ).refine((data) => !!data.appwardenApiToken, {
310
310
  message: printMessage(
311
- "Please provide a valid `appwardenApiToken`. Learn more at https://appwarden.com/docs/api-tokens."
311
+ "Please provide a valid `appwardenApiToken`. Learn more at https://appwarden.com/docs/guides/api-token-management."
312
312
  ),
313
313
  path: ["appwardenApiToken"]
314
314
  });
@@ -473,7 +473,11 @@ var CSPDirectivesSchema = z8.union([
473
473
  z8.string(),
474
474
  ContentSecurityPolicySchema
475
475
  ]);
476
- var CSPModeSchema = z8.literal("disabled").or(z8.literal("report-only")).or(z8.literal("enforced")).optional().default("disabled");
476
+ var CSPModeSchema = z8.union([
477
+ z8.literal("disabled"),
478
+ z8.literal("report-only"),
479
+ z8.literal("enforced")
480
+ ]).optional().default("disabled");
477
481
  var UseCSPInputSchema = z8.object({
478
482
  mode: CSPModeSchema,
479
483
  directives: CSPDirectivesSchema.optional().refine(
package/cloudflare.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { M as Middleware, B as Bindings } from './use-content-security-policy-DBWKjDEH.js';
2
- export { u as useContentSecurityPolicy } from './use-content-security-policy-DBWKjDEH.js';
1
+ import { M as Middleware, B as Bindings } from './use-content-security-policy-UyG9yvVs.js';
2
+ export { u as useContentSecurityPolicy } from './use-content-security-policy-UyG9yvVs.js';
3
3
  import { z } from 'zod';
4
4
 
5
5
  declare const ConfigFnInputSchema: z.ZodFunction<z.ZodTuple<[z.ZodType<{
package/cloudflare.js CHANGED
@@ -2,11 +2,11 @@ import {
2
2
  insertErrorLogs,
3
3
  useAppwarden,
4
4
  useContentSecurityPolicy
5
- } from "./chunk-3STKCAEA.js";
5
+ } from "./chunk-CGJ2UT3T.js";
6
6
  import {
7
7
  ConfigFnInputSchema,
8
8
  usePipeline
9
- } from "./chunk-5UMKWIJW.js";
9
+ } from "./chunk-GC5FS43G.js";
10
10
 
11
11
  // src/runners/appwarden-on-cloudflare.ts
12
12
  import { ZodError } from "zod";
package/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { B as Bindings, C as CSPDirectivesSchema, a as CSPModeSchema, M as Middleware, u as useContentSecurityPolicy } from './use-content-security-policy-DBWKjDEH.js';
1
+ export { B as Bindings, C as CSPDirectivesSchema, a as CSPModeSchema, M as Middleware, u as useContentSecurityPolicy } from './use-content-security-policy-UyG9yvVs.js';
2
2
  import { z } from 'zod';
3
3
 
4
4
  declare const LOCKDOWN_TEST_EXPIRY_MS: number;
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  useContentSecurityPolicy
3
- } from "./chunk-3STKCAEA.js";
3
+ } from "./chunk-CGJ2UT3T.js";
4
4
  import {
5
5
  APPWARDEN_CACHE_KEY,
6
6
  APPWARDEN_USER_AGENT,
@@ -10,7 +10,7 @@ import {
10
10
  getEdgeConfigId,
11
11
  isCacheUrl,
12
12
  isValidCacheUrl
13
- } from "./chunk-5UMKWIJW.js";
13
+ } from "./chunk-GC5FS43G.js";
14
14
  export {
15
15
  APPWARDEN_CACHE_KEY,
16
16
  APPWARDEN_USER_AGENT,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appwarden/middleware",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "description": "Instantly shut off access your app deployed on Cloudflare or Vercel",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -16,7 +16,7 @@
16
16
  "monitoring"
17
17
  ],
18
18
  "dependencies": {
19
- "@cloudflare/next-on-pages": "1.13.2",
19
+ "@cloudflare/next-on-pages": "1.13.5",
20
20
  "@upstash/redis": "^1.30.0",
21
21
  "@vercel/edge-config": "^1.1.0",
22
22
  "zod": "^3"
@@ -188,9 +188,9 @@ declare const CSPDirectivesSchema: z.ZodUnion<[z.ZodString, z.ZodObject<{
188
188
  "trusted-types"?: string | boolean | string[] | undefined;
189
189
  "require-trusted-types-for"?: string | boolean | string[] | undefined;
190
190
  }>]>;
191
- declare const CSPModeSchema: z.ZodDefault<z.ZodOptional<z.ZodUnion<[z.ZodUnion<[z.ZodLiteral<"disabled">, z.ZodLiteral<"report-only">]>, z.ZodLiteral<"enforced">]>>>;
191
+ declare const CSPModeSchema: z.ZodDefault<z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"disabled">, z.ZodLiteral<"report-only">, z.ZodLiteral<"enforced">]>>>;
192
192
  declare const UseCSPInputSchema: z.ZodEffects<z.ZodObject<{
193
- mode: z.ZodDefault<z.ZodOptional<z.ZodUnion<[z.ZodUnion<[z.ZodLiteral<"disabled">, z.ZodLiteral<"report-only">]>, z.ZodLiteral<"enforced">]>>>;
193
+ mode: z.ZodDefault<z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"disabled">, z.ZodLiteral<"report-only">, z.ZodLiteral<"enforced">]>>>;
194
194
  directives: z.ZodEffects<z.ZodEffects<z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodObject<{
195
195
  "default-src": z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodString, z.ZodBoolean]>>;
196
196
  "script-src": z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodString, z.ZodBoolean]>>;
package/vercel.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  isCacheUrl,
12
12
  printMessage,
13
13
  syncEdgeValue
14
- } from "./chunk-5UMKWIJW.js";
14
+ } from "./chunk-GC5FS43G.js";
15
15
 
16
16
  // src/runners/appwarden-on-vercel.ts
17
17
  import { NextResponse } from "next/server";