@lokalise/fastify-bullboard-plugin 3.1.0 → 3.2.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 +13 -0
- package/dist/basicAuth.d.ts +11 -1
- package/dist/basicAuth.js +22 -1
- package/dist/basicAuth.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -52,6 +52,19 @@ not cover routes that only share the string prefix, such as `/bullet`. A trailin
|
|
|
52
52
|
Entries are full route paths. If BullBoard is registered inside a plugin with its own prefix, list the full path,
|
|
53
53
|
e.g. `'/admin/bull'` for a `/bull` mount under `/admin`.
|
|
54
54
|
|
|
55
|
+
To protect everything by default instead, pass a `skipList` in place of `enableList`. Every route then requires
|
|
56
|
+
credentials, including the root redirect and unmatched URLs, except the listed route paths:
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
await app.register(basicAuth, {
|
|
60
|
+
config: { isEnabled: true, username: 'username', password: 'pass' },
|
|
61
|
+
skipList: new Set(['/health', '/metrics']),
|
|
62
|
+
})
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
`skipList` entries are matched exactly against the registered route path, so `'/health'` does not skip
|
|
66
|
+
`/health/deep`. Pass either `enableList` or `skipList`, not both.
|
|
67
|
+
|
|
55
68
|
## BullMQ Pro support
|
|
56
69
|
|
|
57
70
|
The plugin supports both standard BullMQ queues and BullMQ Pro queues, including mixing
|
package/dist/basicAuth.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export type AuthConfig = {
|
|
|
5
5
|
};
|
|
6
6
|
type BasicAuthOptions = {
|
|
7
7
|
config: AuthConfig;
|
|
8
|
+
} & ({
|
|
8
9
|
/**
|
|
9
10
|
* Paths that require basic auth. Each entry protects the path itself and every route under it,
|
|
10
11
|
* e.g. `/bull` (or `/bull/`) covers `/bull`, `/bull/api/queues` and `/bull/static/*`, but not `/bullet`.
|
|
@@ -12,6 +13,15 @@ type BasicAuthOptions = {
|
|
|
12
13
|
* The root path `/` is matched exactly, so it does not protect the whole app. Empty entries are ignored.
|
|
13
14
|
*/
|
|
14
15
|
enableList: Set<string>;
|
|
15
|
-
|
|
16
|
+
skipList?: never;
|
|
17
|
+
} | {
|
|
18
|
+
/**
|
|
19
|
+
* Route paths that do not require basic auth; every other route does, including unmatched ones.
|
|
20
|
+
* Entries are matched exactly against the registered route path, e.g. `/health` skips `/health` only,
|
|
21
|
+
* and `/users/:id` skips that parametric route.
|
|
22
|
+
*/
|
|
23
|
+
skipList: Set<string>;
|
|
24
|
+
enableList?: never;
|
|
25
|
+
});
|
|
16
26
|
export declare const basicAuth: import("fastify").FastifyPluginCallback<BasicAuthOptions, import("fastify").RawServerDefault, import("fastify").FastifyTypeProviderDefault, import("fastify").FastifyBaseLogger>;
|
|
17
27
|
export {};
|
package/dist/basicAuth.js
CHANGED
|
@@ -47,10 +47,31 @@ function enableListAuthHandler(enableList) {
|
|
|
47
47
|
return done('Needs auth');
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
|
+
function skipListAuthHandler(skipList) {
|
|
51
|
+
return (req, _res, done) => {
|
|
52
|
+
if (req.routeOptions.url && skipList.has(req.routeOptions.url)) {
|
|
53
|
+
return done(); // success: skip the rest of the handlers
|
|
54
|
+
}
|
|
55
|
+
// Fail here to go to the next handler (basicAuth). String for performance, it also works
|
|
56
|
+
return done('Needs auth');
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function resolveAccessHandler(pluginOptions) {
|
|
60
|
+
const { enableList, skipList } = pluginOptions;
|
|
61
|
+
if (enableList && skipList) {
|
|
62
|
+
throw new Error('basic-auth: enableList and skipList are mutually exclusive, pass only one');
|
|
63
|
+
}
|
|
64
|
+
if (skipList)
|
|
65
|
+
return skipListAuthHandler(skipList);
|
|
66
|
+
if (enableList)
|
|
67
|
+
return enableListAuthHandler(enableList);
|
|
68
|
+
throw new Error('basic-auth: either enableList or skipList is required');
|
|
69
|
+
}
|
|
50
70
|
async function plugin(fastify, pluginOptions) {
|
|
51
71
|
if (!pluginOptions.config.isEnabled) {
|
|
52
72
|
return;
|
|
53
73
|
}
|
|
74
|
+
const accessHandler = resolveAccessHandler(pluginOptions);
|
|
54
75
|
if (!fastify.auth) {
|
|
55
76
|
await fastify.register(fastifyAuth);
|
|
56
77
|
}
|
|
@@ -59,7 +80,7 @@ async function plugin(fastify, pluginOptions) {
|
|
|
59
80
|
authenticate: true,
|
|
60
81
|
});
|
|
61
82
|
fastify.after(() => {
|
|
62
|
-
fastify.addHook('onRequest', fastify.auth([
|
|
83
|
+
fastify.addHook('onRequest', fastify.auth([accessHandler, fastify.basicAuth]));
|
|
63
84
|
});
|
|
64
85
|
}
|
|
65
86
|
export const basicAuth = fp(plugin, {
|
package/dist/basicAuth.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"basicAuth.js","sourceRoot":"","sources":["../src/basicAuth.ts"],"names":[],"mappings":"AACA,OAAO,WAAW,MAAM,eAAe,CAAA;AACvC,OAAO,gBAAgB,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAErD,OAAO,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"basicAuth.js","sourceRoot":"","sources":["../src/basicAuth.ts"],"names":[],"mappings":"AACA,OAAO,WAAW,MAAM,eAAe,CAAA;AACvC,OAAO,gBAAgB,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAErD,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAgC/B,SAAS,QAAQ,CAAC,MAAkB;IAClC,OAAO,CACL,QAAgB,EAChB,QAAgB,EAChB,IAAoB,EACpB,MAAoB,EACpB,IAA2B,EAC3B,EAAE;QACF,IAAI,QAAQ,KAAK,MAAM,CAAC,QAAQ,IAAI,QAAQ,KAAK,MAAM,CAAC,QAAQ,EAAE,CAAC;YACjE,IAAI,EAAE,CAAA;QAC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