@appwarden/middleware 3.2.1 → 3.4.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 +257 -22
- package/chunk-3MKVGKH7.js +81 -0
- package/chunk-G4RRFNHY.js +332 -0
- package/chunk-HCGLR3Z3.js +97 -0
- package/{chunk-ZX5QO4Y2.js → chunk-QVRWMYGL.js} +31 -58
- package/{chunk-COV6SHCD.js → chunk-U3T4R5KZ.js} +2 -4
- package/chunk-YBWFEBZC.js +53 -0
- package/cloudflare/astro.d.ts +4 -0
- package/cloudflare/astro.js +54 -11
- package/cloudflare/nextjs.d.ts +4 -0
- package/cloudflare/nextjs.js +57 -10
- package/cloudflare/react-router.d.ts +5 -0
- package/cloudflare/react-router.js +54 -11
- package/cloudflare/tanstack-start.d.ts +5 -0
- package/cloudflare/tanstack-start.js +54 -11
- package/cloudflare-36BOGAYU.js +28 -0
- package/cloudflare.d.ts +440 -8
- package/cloudflare.js +44 -54
- package/index.d.ts +2 -1
- package/index.js +5 -4
- package/package.json +8 -3
- package/{use-content-security-policy-DjRTjIpm.d.ts → use-content-security-policy-DUYpyUPy.d.ts} +1 -18
- package/use-content-security-policy-Dvc-oObb.d.ts +17 -0
- package/vercel.d.ts +688 -0
- package/vercel.js +82 -13
- package/chunk-A5XGYLYS.js +0 -196
- package/chunk-L5EQIJZB.js +0 -54
- package/chunk-MDODCAA3.js +0 -232
package/README.md
CHANGED
|
@@ -1,50 +1,283 @@
|
|
|
1
1
|
# @appwarden/middleware
|
|
2
2
|
|
|
3
|
-
](https://appwarden.io/docs/reference/appwarden-middleware)
|
|
4
|
+
[](https://github.com/appwarden/middleware)
|
|
4
5
|
[](https://www.npmjs.com/package/@appwarden/middleware)
|
|
5
6
|
[](https://docs.npmjs.com/generating-provenance-statements)
|
|
7
|
+

|
|
6
8
|
[](https://opensource.org/licenses/MIT)
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
## Core Features
|
|
9
11
|
|
|
10
|
-
|
|
12
|
+
- **Discord Integration**: Quarantine your website via Discord commands (`/quarantine [un]lock`)
|
|
13
|
+
- **Instant Quarantine**: Immediately redirects all visitors to a lock page when activated to stop in progress attacks.
|
|
14
|
+
- **Nonce-based Content Security Policy (See [Feature Compatibility](#feature-compatibility))**: Deploy a nonce-based Content Security Policy (CSP) using HTML rewriting on Cloudflare where supported.
|
|
15
|
+
- **Minimal Runtime Overhead**: Negligible performance impact by using `event.waitUntil` for status checks
|
|
11
16
|
|
|
12
|
-
###
|
|
17
|
+
### Feature Compatibility
|
|
13
18
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
The table below summarizes which Appwarden features are available on each platform, including quarantine enforcement and Content Security Policy (CSP) support (with or without nonces).
|
|
20
|
+
|
|
21
|
+
| Platform / Adapter | Package / entrypoint | Quarantine | CSP | CSP Nonce |
|
|
22
|
+
| --------------------------------------- | ------------------------------------------------- | ---------- | --- | --------- |
|
|
23
|
+
| Cloudflare – Universal middleware | `@appwarden/middleware/cloudflare` | ✅ | ✅ | ✅ |
|
|
24
|
+
| Cloudflare – Astro | `@appwarden/middleware/cloudflare/astro` | ✅ | ✅ | ✅ |
|
|
25
|
+
| Cloudflare – React Router | `@appwarden/middleware/cloudflare/react-router` | ✅ | ✅ | ✅ |
|
|
26
|
+
| Cloudflare – TanStack Start | `@appwarden/middleware/cloudflare/tanstack-start` | ✅ | ✅ | ✅ |
|
|
27
|
+
| Cloudflare – Next.js (OpenNext adapter) | `@appwarden/middleware/cloudflare/nextjs` | ✅ | ✅ | ❌ |
|
|
28
|
+
| Vercel - Universal middleware | `@appwarden/middleware/vercel` | ✅ | ✅ | ❌ |
|
|
29
|
+
|
|
30
|
+
Nonce-based CSP requires HTML rewriting and is only available on Cloudflare. Next.js on Cloudflare (OpenNext) and Vercel Edge Middleware apply CSP headers only and do **not** support nonces. If you are using Next.js on Cloudflare, please use the Cloudflare Universal middleware for CSP nonce support.
|
|
31
|
+
|
|
32
|
+
## Configuration
|
|
33
|
+
|
|
34
|
+
The following options are shared across the Cloudflare and Vercel middleware bundles.
|
|
35
|
+
|
|
36
|
+
### `lockPageSlug`
|
|
37
|
+
|
|
38
|
+
The path or route (for example, `/maintenance`) to redirect users to when the domain is quarantined.
|
|
39
|
+
This should be a working page on your site, such as a maintenance or status page, that
|
|
40
|
+
explains why the website is temporarily unavailable.
|
|
41
|
+
|
|
42
|
+
### `contentSecurityPolicy`
|
|
43
|
+
|
|
44
|
+
Controls the [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) headers that Appwarden adds.
|
|
45
|
+
|
|
46
|
+
- `mode` (optional) controls how the CSP is applied:
|
|
47
|
+
- `"disabled"` – no CSP header is sent.
|
|
48
|
+
- `"report-only"` – sends the `Content-Security-Policy-Report-Only` header so violations are
|
|
49
|
+
reported (for example in the browser console) but not blocked.
|
|
50
|
+
- `"enforced"` – sends the `Content-Security-Policy` header so violations are actively blocked.
|
|
51
|
+
|
|
52
|
+
When developing or iterating on your CSP, we recommend starting with `"report-only"` so you can
|
|
53
|
+
identify and fix violations before switching to `"enforced"`.
|
|
54
|
+
|
|
55
|
+
- `directives` (optional) is an object whose keys are CSP directive names and whose values are
|
|
56
|
+
arrays of allowed sources. For example:
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
contentSecurityPolicy: {
|
|
60
|
+
mode: "enforced",
|
|
61
|
+
directives: {
|
|
62
|
+
"script-src": ["'self'", "{{nonce}}"],
|
|
63
|
+
},
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
To add a nonce to a directive (See [Feature Compatibility](#feature-compatibility)), include the `"{{nonce}}"` placeholder in the list of sources.
|
|
68
|
+
|
|
69
|
+
### `appwardenApiToken`
|
|
70
|
+
|
|
71
|
+
The Appwarden API token used to authenticate requests to the Appwarden API. See the
|
|
72
|
+
[API token management guide](https://appwarden.io/docs/guides/api-token-management) for details on creating and
|
|
73
|
+
managing your token.
|
|
74
|
+
|
|
75
|
+
Treat this token as a secret (similar to a password): do not commit it to source control and store
|
|
76
|
+
it in environment variables or secret management where possible. Appwarden stores API tokens using
|
|
77
|
+
AES-GCM encryption and does not display them after creation.
|
|
78
|
+
|
|
79
|
+
### `cacheUrl` (Vercel only)
|
|
80
|
+
|
|
81
|
+
The URL or connection string of the cache provider (for example, Upstash or Vercel Edge Config)
|
|
82
|
+
that stores the quarantine status for your domain. See the
|
|
83
|
+
[Vercel integration guide](https://appwarden.io/docs/guides/vercel-middleware-integration#3-configure-a-cache-provider)
|
|
84
|
+
for cache provider configuration details.
|
|
85
|
+
|
|
86
|
+
### `vercelApiToken` (Vercel only)
|
|
87
|
+
|
|
88
|
+
A Vercel API token that Appwarden uses to manage the Vercel Edge Config cache provider that synchronizes the quarantine status of your domain.
|
|
89
|
+
See the [Vercel integration guide](https://appwarden.io/docs/guides/vercel-middleware-integration#3-configure-a-cache-provider)
|
|
90
|
+
for cache provider configuration details.
|
|
91
|
+
|
|
92
|
+
Appwarden never stores or logs your Vercel API token; it is used only to manage the quarantine status cache for your domain.
|
|
18
93
|
|
|
19
94
|
## Installation
|
|
20
95
|
|
|
21
96
|
Compatible with websites powered by [Cloudflare](https://developers.cloudflare.com/workers/static-assets/) or [Vercel](https://vercel.com).
|
|
22
97
|
|
|
23
|
-
For
|
|
98
|
+
For more background and advanced configuration, see the [Appwarden documentation](https://appwarden.io/docs).
|
|
99
|
+
|
|
100
|
+
### 1. Cloudflare
|
|
101
|
+
|
|
102
|
+
#### 1.1 Universal Middleware (direct Cloudflare Worker usage)
|
|
103
|
+
|
|
104
|
+
The **Universal Middleware** (`@appwarden/middleware/cloudflare`) is the recommended way to install Appwarden on Cloudflare. The easiest way to deploy this universal middleware is via our [build-cloudflare-action](https://github.com/appwarden/build-cloudflare-action); see the [Cloudflare integration guide](https://appwarden.io/docs/guides/cloudflare-middleware-integration#1-set-up-the-github-actions-workflow) for workflow details. If you prefer to manage your own Cloudflare Worker instead of using the GitHub Action, you can mount the universal Cloudflare middleware directly using the `@appwarden/middleware/cloudflare` bundle:
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
// src/worker.ts
|
|
108
|
+
import { createAppwardenMiddleware } from "@appwarden/middleware/cloudflare"
|
|
109
|
+
|
|
110
|
+
const appwardenHandler = createAppwardenMiddleware((cloudflare) => ({
|
|
111
|
+
debug: cloudflare.env.DEBUG === "true",
|
|
112
|
+
lockPageSlug: cloudflare.env.LOCK_PAGE_SLUG,
|
|
113
|
+
appwardenApiToken: cloudflare.env.APPWARDEN_API_TOKEN,
|
|
114
|
+
contentSecurityPolicy: {
|
|
115
|
+
mode: cloudflare.env.CSP_MODE,
|
|
116
|
+
directives: cloudflare.env.CSP_DIRECTIVES,
|
|
117
|
+
},
|
|
118
|
+
}))
|
|
24
119
|
|
|
25
|
-
|
|
120
|
+
export default {
|
|
121
|
+
fetch(request: Request, env: CloudflareEnv, ctx: ExecutionContext) {
|
|
122
|
+
return appwardenHandler(request, env, ctx)
|
|
123
|
+
},
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
See the Cloudflare integration docs on [appwarden.io](https://appwarden.io/docs) for environment variable setup and deployment details.
|
|
128
|
+
|
|
129
|
+
#### 1.2 Cloudflare framework adapters
|
|
130
|
+
|
|
131
|
+
If you cannot use `build-cloudflare-action`, you can mount Appwarden inside your application using framework-specific adapters.
|
|
132
|
+
|
|
133
|
+
> Currently, framework adapters do not automatically reflect your Appwarden domain configuration. You must manually provide the `lockPageSlug` and `contentSecurityPolicy` configuration in your code.
|
|
134
|
+
|
|
135
|
+
##### Astro on Cloudflare
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
// src/middleware.ts
|
|
139
|
+
import { sequence } from "astro:middleware"
|
|
140
|
+
import { createAppwardenMiddleware } from "@appwarden/middleware/cloudflare/astro"
|
|
141
|
+
|
|
142
|
+
const appwarden = createAppwardenMiddleware((cloudflare) => ({
|
|
143
|
+
lockPageSlug: cloudflare.env.APPWARDEN_LOCK_PAGE_SLUG,
|
|
144
|
+
appwardenApiToken: cloudflare.env.APPWARDEN_API_TOKEN,
|
|
145
|
+
debug: cloudflare.env.APPWARDEN_DEBUG === "true",
|
|
146
|
+
contentSecurityPolicy: {
|
|
147
|
+
mode: "enforced",
|
|
148
|
+
directives: {
|
|
149
|
+
"script-src": ["'self'", "{{nonce}}"],
|
|
150
|
+
"style-src": ["'self'", "{{nonce}}"],
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
}))
|
|
154
|
+
|
|
155
|
+
export const onRequest = sequence(appwarden)
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
See the [Astro + Cloudflare guide](https://appwarden.io/docs/guides/astro-cloudflare) for more details.
|
|
159
|
+
|
|
160
|
+
##### React Router on Cloudflare
|
|
161
|
+
|
|
162
|
+
```ts
|
|
163
|
+
// app/root.tsx
|
|
164
|
+
import { createAppwardenMiddleware } from "@appwarden/middleware/cloudflare/react-router"
|
|
165
|
+
import type { CloudflareContext } from "@appwarden/middleware/cloudflare/react-router"
|
|
166
|
+
|
|
167
|
+
export const unstable_middleware = [
|
|
168
|
+
createAppwardenMiddleware((cloudflare: CloudflareContext) => ({
|
|
169
|
+
lockPageSlug: cloudflare.env.APPWARDEN_LOCK_PAGE_SLUG,
|
|
170
|
+
appwardenApiToken: cloudflare.env.APPWARDEN_API_TOKEN,
|
|
171
|
+
debug: cloudflare.env.APPWARDEN_DEBUG === "true",
|
|
172
|
+
contentSecurityPolicy: {
|
|
173
|
+
mode: "enforced",
|
|
174
|
+
directives: {
|
|
175
|
+
"script-src": ["'self'", "{{nonce}}"],
|
|
176
|
+
"style-src": ["'self'", "{{nonce}}"],
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
})),
|
|
180
|
+
]
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
See the [React Router + Cloudflare guide](https://appwarden.io/docs/guides/react-router-cloudflare) for full usage and context setup.
|
|
184
|
+
|
|
185
|
+
##### TanStack Start on Cloudflare
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
// src/start.ts
|
|
189
|
+
import { createStart } from "@tanstack/react-start"
|
|
190
|
+
import { createAppwardenMiddleware } from "@appwarden/middleware/cloudflare/tanstack-start"
|
|
191
|
+
import type { TanStackStartCloudflareContext } from "@appwarden/middleware/cloudflare/tanstack-start"
|
|
192
|
+
|
|
193
|
+
const appwardenMiddleware = createAppwardenMiddleware(
|
|
194
|
+
(cloudflare: TanStackStartCloudflareContext) => ({
|
|
195
|
+
lockPageSlug: cloudflare.env.APPWARDEN_LOCK_PAGE_SLUG,
|
|
196
|
+
appwardenApiToken: cloudflare.env.APPWARDEN_API_TOKEN,
|
|
197
|
+
debug: cloudflare.env.APPWARDEN_DEBUG === "true",
|
|
198
|
+
contentSecurityPolicy: {
|
|
199
|
+
mode: "enforced",
|
|
200
|
+
directives: {
|
|
201
|
+
"script-src": ["'self'", "{{nonce}}"],
|
|
202
|
+
"style-src": ["'self'", "{{nonce}}"],
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
}),
|
|
206
|
+
)
|
|
207
|
+
|
|
208
|
+
export const start = createStart(() => ({
|
|
209
|
+
requestMiddleware: [appwardenMiddleware],
|
|
210
|
+
}))
|
|
211
|
+
```
|
|
26
212
|
|
|
27
|
-
|
|
213
|
+
See the [TanStack Start + Cloudflare guide](https://appwarden.io/docs/guides/tanstack-start-cloudflare) for more details.
|
|
28
214
|
|
|
29
|
-
|
|
215
|
+
##### Next.js on Cloudflare (OpenNext)
|
|
30
216
|
|
|
31
|
-
|
|
217
|
+
```ts
|
|
218
|
+
// middleware.ts or proxy.ts
|
|
219
|
+
import { createAppwardenMiddleware } from "@appwarden/middleware/cloudflare/nextjs"
|
|
32
220
|
|
|
33
|
-
|
|
221
|
+
export const config = {
|
|
222
|
+
matcher: ["/((?!api|_next/static|_next/image|favicon.ico).*)"],
|
|
223
|
+
}
|
|
34
224
|
|
|
35
|
-
|
|
225
|
+
export default createAppwardenMiddleware((cloudflare) => ({
|
|
226
|
+
lockPageSlug: cloudflare.env.APPWARDEN_LOCK_PAGE_SLUG,
|
|
227
|
+
appwardenApiToken: cloudflare.env.APPWARDEN_API_TOKEN,
|
|
228
|
+
debug: cloudflare.env.APPWARDEN_DEBUG === "true",
|
|
229
|
+
// Headers-only CSP (no HTML rewriting, no nonce support; do not use `{{nonce}}` here)
|
|
230
|
+
contentSecurityPolicy: {
|
|
231
|
+
mode: "report-only",
|
|
232
|
+
directives: {
|
|
233
|
+
"script-src": ["'self'"],
|
|
234
|
+
"style-src": ["'self'", "'unsafe-inline'"],
|
|
235
|
+
},
|
|
236
|
+
},
|
|
237
|
+
}))
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
This adapter applies CSP **headers only** before origin (no HTML rewriting, no nonce injection). Nonce-based CSP (`{{nonce}}`) is **not supported** in this adapter; CSP directives must not include `{{nonce}}`.
|
|
36
241
|
|
|
37
|
-
|
|
242
|
+
### 2. Vercel
|
|
38
243
|
|
|
39
|
-
|
|
244
|
+
To use Appwarden as Vercel Edge Middleware, use the `@appwarden/middleware/vercel` bundle:
|
|
40
245
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
246
|
+
```ts
|
|
247
|
+
// middleware.ts (Next.js app on Vercel)
|
|
248
|
+
import { createAppwardenMiddleware } from "@appwarden/middleware/vercel"
|
|
249
|
+
import type { VercelMiddlewareFunction } from "@appwarden/middleware/vercel"
|
|
45
250
|
|
|
46
|
-
|
|
251
|
+
const appwardenMiddleware: VercelMiddlewareFunction = createAppwardenMiddleware(
|
|
252
|
+
{
|
|
253
|
+
// Edge Config or Upstash KV URL
|
|
254
|
+
cacheUrl: process.env.APPWARDEN_CACHE_URL!,
|
|
255
|
+
// Required when using Vercel Edge Config
|
|
256
|
+
vercelApiToken: process.env.APPWARDEN_VERCEL_API_TOKEN!,
|
|
257
|
+
appwardenApiToken: process.env.APPWARDEN_API_TOKEN!,
|
|
258
|
+
lockPageSlug: "/maintenance",
|
|
259
|
+
contentSecurityPolicy: {
|
|
260
|
+
mode: "report-only",
|
|
261
|
+
directives: {
|
|
262
|
+
"script-src": ["'self'"],
|
|
263
|
+
"style-src": ["'self'", "'unsafe-inline'"],
|
|
264
|
+
},
|
|
265
|
+
},
|
|
266
|
+
},
|
|
267
|
+
)
|
|
268
|
+
|
|
269
|
+
export default appwardenMiddleware
|
|
270
|
+
```
|
|
47
271
|
|
|
272
|
+
Nonce-based CSP (`{{nonce}}`) is **not supported** in Vercel Edge Middleware; CSP directives must not include `{{nonce}}`.
|
|
273
|
+
|
|
274
|
+
## Supported platforms
|
|
275
|
+
|
|
276
|
+
- [All websites on Cloudflare](https://appwarden.io/docs/guides/cloudflare-middleware-integration)
|
|
277
|
+
- [Astro on Cloudflare](https://appwarden.io/docs/guides/astro-cloudflare)
|
|
278
|
+
- [React Router on Cloudflare](https://appwarden.io/docs/guides/react-router-cloudflare)
|
|
279
|
+
- [TanStack Start on Cloudflare](https://appwarden.io/docs/guides/tanstack-start-cloudflare)
|
|
280
|
+
- [Next.js on Cloudflare (OpenNext)](https://appwarden.io/docs/guides/nextjs-cloudflare)
|
|
48
281
|
- [All websites on Vercel](https://appwarden.io/docs/guides/vercel-integration)
|
|
49
282
|
|
|
50
283
|
## Contributing
|
|
@@ -80,6 +313,8 @@ pnpm test
|
|
|
80
313
|
|
|
81
314
|
## Security
|
|
82
315
|
|
|
316
|
+
Please review our [security policy](SECURITY.md) for details on how we handle vulnerabilities and how to report a security issue.
|
|
317
|
+
|
|
83
318
|
This package is published with npm trusted publishers, to prevent npm token exfiltration, and provenance enabled, which provides a verifiable link between the published package and its source code. For more information, see [npm provenance documentation](https://docs.npmjs.com/generating-provenance-statements).
|
|
84
319
|
|
|
85
320
|
## License
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MemoryCache,
|
|
3
|
+
debug
|
|
4
|
+
} from "./chunk-QVRWMYGL.js";
|
|
5
|
+
import {
|
|
6
|
+
APPWARDEN_CACHE_KEY,
|
|
7
|
+
APPWARDEN_TEST_ROUTE
|
|
8
|
+
} from "./chunk-HCGLR3Z3.js";
|
|
9
|
+
import {
|
|
10
|
+
deleteEdgeValue,
|
|
11
|
+
getLockValue,
|
|
12
|
+
store,
|
|
13
|
+
syncEdgeValue
|
|
14
|
+
} from "./chunk-G4RRFNHY.js";
|
|
15
|
+
|
|
16
|
+
// src/core/check-lock-status.ts
|
|
17
|
+
var createContext = async (config) => {
|
|
18
|
+
const requestUrl = new URL(config.request.url);
|
|
19
|
+
const keyName = APPWARDEN_CACHE_KEY;
|
|
20
|
+
const provider = "cloudflare-cache";
|
|
21
|
+
const debugFn = debug(config.debug ?? false);
|
|
22
|
+
const edgeCache = store.json(
|
|
23
|
+
{
|
|
24
|
+
serviceOrigin: requestUrl.origin,
|
|
25
|
+
cache: await caches.open("appwarden:lock"),
|
|
26
|
+
debug: debugFn
|
|
27
|
+
},
|
|
28
|
+
keyName
|
|
29
|
+
);
|
|
30
|
+
return {
|
|
31
|
+
keyName,
|
|
32
|
+
request: config.request,
|
|
33
|
+
edgeCache,
|
|
34
|
+
requestUrl,
|
|
35
|
+
provider,
|
|
36
|
+
debug: debugFn,
|
|
37
|
+
lockPageSlug: config.lockPageSlug,
|
|
38
|
+
appwardenApiToken: config.appwardenApiToken,
|
|
39
|
+
appwardenApiHostname: config.appwardenApiHostname,
|
|
40
|
+
waitUntil: config.waitUntil
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
var resolveLockStatus = async (context) => {
|
|
44
|
+
const { lockValue, shouldDeleteEdgeValue } = await getLockValue(context);
|
|
45
|
+
if (lockValue) {
|
|
46
|
+
context.debug("Lock value resolved from cache");
|
|
47
|
+
}
|
|
48
|
+
if (shouldDeleteEdgeValue) {
|
|
49
|
+
context.debug("Deleting corrupted cache value");
|
|
50
|
+
await deleteEdgeValue(context);
|
|
51
|
+
}
|
|
52
|
+
const isTestRoute = context.requestUrl.pathname === APPWARDEN_TEST_ROUTE;
|
|
53
|
+
const isTestLock = isTestRoute && !MemoryCache.isTestExpired(lockValue) && !!lockValue;
|
|
54
|
+
return {
|
|
55
|
+
isLocked: !!lockValue?.isLocked || isTestLock,
|
|
56
|
+
isTestLock,
|
|
57
|
+
lockValue,
|
|
58
|
+
wasDeleted: shouldDeleteEdgeValue ?? false
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
var checkLockStatus = async (config) => {
|
|
62
|
+
const context = await createContext(config);
|
|
63
|
+
let { isLocked, isTestLock, lockValue, wasDeleted } = await resolveLockStatus(context);
|
|
64
|
+
if (MemoryCache.isExpired(lockValue) || wasDeleted) {
|
|
65
|
+
if (!lockValue || wasDeleted || lockValue.isLocked) {
|
|
66
|
+
context.debug(
|
|
67
|
+
"Cache expired/missing/corrupted or site is locked - syncing with API synchronously"
|
|
68
|
+
);
|
|
69
|
+
await syncEdgeValue(context);
|
|
70
|
+
({ isLocked, isTestLock } = await resolveLockStatus(context));
|
|
71
|
+
} else {
|
|
72
|
+
context.debug("Cache expired but site unlocked - syncing in background");
|
|
73
|
+
config.waitUntil(syncEdgeValue(context));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return { isLocked, isTestLock };
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export {
|
|
80
|
+
checkLockStatus
|
|
81
|
+
};
|