@c9up/warden 0.1.26 → 0.1.27
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/dist/WardenProvider.d.ts +1 -0
- package/dist/WardenProvider.d.ts.map +1 -1
- package/dist/WardenProvider.js +16 -2
- package/dist/WardenProvider.js.map +1 -1
- package/dist/native.d.ts.map +1 -1
- package/dist/native.js +7 -23
- package/dist/native.js.map +1 -1
- package/dist/quasar.d.ts +6 -9
- package/dist/quasar.d.ts.map +1 -1
- package/dist/quasar.js +17 -47
- package/dist/quasar.js.map +1 -1
- package/dist/services/main.d.ts +10 -0
- package/dist/services/main.d.ts.map +1 -1
- package/dist/services/main.js +12 -0
- package/dist/services/main.js.map +1 -1
- package/dist/vendor/nativeBinary.d.ts +43 -0
- package/dist/vendor/nativeBinary.d.ts.map +1 -0
- package/dist/vendor/nativeBinary.js +99 -0
- package/dist/vendor/nativeBinary.js.map +1 -0
- package/dist/vendor/quasarConnection.d.ts +35 -0
- package/dist/vendor/quasarConnection.d.ts.map +1 -0
- package/dist/vendor/quasarConnection.js +62 -0
- package/dist/vendor/quasarConnection.js.map +1 -0
- package/index.win32-x64-msvc.node +0 -0
- package/package.json +1 -1
- package/src/WardenProvider.ts +18 -2
- package/src/native.ts +7 -25
- package/src/quasar.ts +18 -64
- package/src/services/main.ts +13 -0
- package/src/vendor/nativeBinary.ts +110 -0
- package/src/vendor/quasarConnection.ts +129 -0
package/dist/WardenProvider.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WardenProvider.d.ts","sourceRoot":"","sources":["../src/WardenProvider.ts"],"names":[],"mappings":"AAAA,OAAO,oBAAoB,CAAC;AAa5B,UAAU,eAAe;IACxB,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,GAAG,IAAI,CAAC;IACxD,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC1C;AAED,UAAU,iBAAiB;IAC1B,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAAC;CAC7C;AAED,MAAM,WAAW,gBAAgB;IAChC,SAAS,EAAE,eAAe,CAAC;IAC3B,MAAM,EAAE,iBAAiB,CAAC;CAC1B;AAED,MAAM,CAAC,OAAO,OAAO,cAAc;;
|
|
1
|
+
{"version":3,"file":"WardenProvider.d.ts","sourceRoot":"","sources":["../src/WardenProvider.ts"],"names":[],"mappings":"AAAA,OAAO,oBAAoB,CAAC;AAa5B,UAAU,eAAe;IACxB,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,GAAG,IAAI,CAAC;IACxD,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC1C;AAED,UAAU,iBAAiB;IAC1B,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAAC;CAC7C;AAED,MAAM,WAAW,gBAAgB;IAChC,SAAS,EAAE,eAAe,CAAC;IAC3B,MAAM,EAAE,iBAAiB,CAAC;CAC1B;AAED,MAAM,CAAC,OAAO,OAAO,cAAc;;IAItB,SAAS,CAAC,GAAG,EAAE,gBAAgB;gBAArB,GAAG,EAAE,gBAAgB;IAE3C,QAAQ;IAoIF,IAAI;IASJ,QAAQ;CAgFd"}
|
package/dist/WardenProvider.js
CHANGED
|
@@ -4,12 +4,14 @@ import { WardenError } from "./errors.js";
|
|
|
4
4
|
import { MfaManager } from "./mfa/MfaManager.js";
|
|
5
5
|
import { MemoryRightsStore } from "./rights/MemoryRightsStore.js";
|
|
6
6
|
import { RightsResolver } from "./rights/RightsResolver.js";
|
|
7
|
-
import { setAuth } from "./services/main.js";
|
|
7
|
+
import { clearAuth, getAuth, setAuth } from "./services/main.js";
|
|
8
8
|
import { ApiKeyStrategy } from "./strategies/ApiKeyStrategy.js";
|
|
9
9
|
import { JwtStrategy } from "./strategies/JwtStrategy.js";
|
|
10
10
|
import { SessionStrategy } from "./strategies/SessionStrategy.js";
|
|
11
11
|
export default class WardenProvider {
|
|
12
12
|
app;
|
|
13
|
+
/** The manager this provider installed, so shutdown only clears its own. */
|
|
14
|
+
#auth;
|
|
13
15
|
constructor(app) {
|
|
14
16
|
this.app = app;
|
|
15
17
|
}
|
|
@@ -137,10 +139,22 @@ export default class WardenProvider {
|
|
|
137
139
|
}
|
|
138
140
|
async boot() {
|
|
139
141
|
const manager = await this.app.container.resolve(AuthManager);
|
|
140
|
-
if (manager instanceof AuthManager)
|
|
142
|
+
if (manager instanceof AuthManager) {
|
|
143
|
+
this.#auth = manager;
|
|
141
144
|
setAuth(manager);
|
|
145
|
+
}
|
|
142
146
|
await this.#registerTemplateTags();
|
|
143
147
|
}
|
|
148
|
+
async shutdown() {
|
|
149
|
+
// Release the module-level singleton, but only while it is still ours.
|
|
150
|
+
// A stopped application left a dead AuthManager reachable through
|
|
151
|
+
// `import auth from '@c9up/warden/services/main'`; and with two
|
|
152
|
+
// applications in one process, clearing unconditionally would take the
|
|
153
|
+
// survivor's auth down with it.
|
|
154
|
+
if (this.#auth !== undefined && getAuth() === this.#auth)
|
|
155
|
+
clearAuth();
|
|
156
|
+
this.#auth = undefined;
|
|
157
|
+
}
|
|
144
158
|
/**
|
|
145
159
|
* Publish `@can` / `@cannot` to the template engine, as AdonisJS's bouncer
|
|
146
160
|
* does. A migrated template keeps `@can('PostPolicy.edit', post) … @endcan`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WardenProvider.js","sourceRoot":"","sources":["../src/WardenProvider.ts"],"names":[],"mappings":"AAAA,OAAO,oBAAoB,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAqB,MAAM,kBAAkB,CAAC;AAElE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,UAAU,E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,MAAM,KAAK,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE,CAAC;YACvC,IAAI,CAAC;gBACJ,MAAM,OAAO,GAAY,MAAM,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;gBACjE,KAAK,MAAM,SAAS,IAAI;oBACvB,OAAO;oBACP,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,YAAY,CAAC;iBAC1C,EAAE,CAAC;oBACH,IACC,OAAO,SAAS,KAAK,QAAQ;wBAC7B,SAAS,KAAK,IAAI;wBAClB,OAAO,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,aAAa,CAAC,KAAK,UAAU,EAC1D,CAAC;wBACF,OAAO;4BACN,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC,IAAI,CACtD,SAAS,CACT;yBACD,CAAC;oBACH,CAAC;gBACF,CAAC;YACF,CAAC;YAAC,MAAM,CAAC;gBACR,mDAAmD;YACpD,CAAC;QACF,CAAC;QACD,OAAO,SAAS,CAAC;IAClB,CAAC;CACD"}
|
package/dist/native.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../src/native.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../src/native.ts"],"names":[],"mappings":"AASA;;;;;;GAMG;AACH,MAAM,MAAM,YAAY,GAAG,cAAc,uBAAuB,CAAC,CAAC;AASlE,2CAA2C;AAC3C,wBAAgB,iBAAiB,IAAI,OAAO,CAE3C;AAED,kFAAkF;AAClF,wBAAgB,YAAY,IAAI,YAAY,GAAG,SAAS,CAEvD"}
|
package/dist/native.js
CHANGED
|
@@ -5,29 +5,13 @@
|
|
|
5
5
|
* other consumer) throws `E_WARDEN_NAPI_REQUIRED` at use time. Password
|
|
6
6
|
* hashing is the sole responsibility of `@c9up/sigil` (story 40.1).
|
|
7
7
|
*/
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
"linux-x64": "linux-x64-gnu",
|
|
16
|
-
"linux-arm64": "linux-arm64-gnu",
|
|
17
|
-
"darwin-x64": "darwin-x64",
|
|
18
|
-
"darwin-arm64": "darwin-arm64",
|
|
19
|
-
"win32-x64": "win32-x64-msvc",
|
|
20
|
-
};
|
|
21
|
-
let native;
|
|
22
|
-
try {
|
|
23
|
-
const suffix = platformMap[`${platform}-${arch}`];
|
|
24
|
-
if (suffix) {
|
|
25
|
-
native = nodeRequire(join(currentDir, `../index.${suffix}.node`));
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
catch {
|
|
29
|
-
// Binary not available — JwtStrategy will throw E_WARDEN_NAPI_REQUIRED at use time.
|
|
30
|
-
}
|
|
8
|
+
import { loadNativeBinary } from "./vendor/nativeBinary.js";
|
|
9
|
+
// Absent is not an error here: `JwtStrategy` throws E_WARDEN_NAPI_REQUIRED at
|
|
10
|
+
// use time, which names what the caller was trying to do. The loader reports
|
|
11
|
+
// what happened and this decides — the platform table itself is shared, since
|
|
12
|
+
// a package that misses a new target fails only on that platform.
|
|
13
|
+
const attempt = loadNativeBinary();
|
|
14
|
+
const native = attempt.loaded ? attempt.binary : undefined;
|
|
31
15
|
/** Whether the Rust NAPI engine loaded. */
|
|
32
16
|
export function isNativeAvailable() {
|
|
33
17
|
return native !== undefined;
|
package/dist/native.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native.js","sourceRoot":"","sources":["../src/native.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"native.js","sourceRoot":"","sources":["../src/native.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAW5D,8EAA8E;AAC9E,6EAA6E;AAC7E,8EAA8E;AAC9E,kEAAkE;AAClE,MAAM,OAAO,GAAG,gBAAgB,EAAgB,CAAC;AACjD,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;AAE3D,2CAA2C;AAC3C,MAAM,UAAU,iBAAiB;IAChC,OAAO,MAAM,KAAK,SAAS,CAAC;AAC7B,CAAC;AAED,kFAAkF;AAClF,MAAM,UAAU,YAAY;IAC3B,OAAO,MAAM,CAAC;AACf,CAAC"}
|
package/dist/quasar.d.ts
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Resolving a Redis connection by name, from `@c9up/quasar`.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* The shape is checked before use rather than asserted, the same way warden
|
|
10
|
-
* duck-types its host framework.
|
|
4
|
+
* The loading, the shape check and the messages are the same in every package
|
|
5
|
+
* that offers a Redis-backed option, so they are vendored rather than written
|
|
6
|
+
* again: `src/vendor/quasarConnection.ts`, generated from one source. What is
|
|
7
|
+
* specific to this package — the commands it issues, and what it does with
|
|
8
|
+
* them — stays here, because that is the part a reader needs.
|
|
11
9
|
*/
|
|
12
10
|
import type { RedisLikeClient } from "./RedisBlacklistDriver.js";
|
|
13
11
|
/**
|
|
14
|
-
* A resolver
|
|
15
|
-
* loaded on the first revocation check, not at config time.
|
|
12
|
+
* A resolver — quasar is loaded on first use, not at config time.
|
|
16
13
|
*/
|
|
17
14
|
export declare function quasarConnection(name?: string): () => Promise<RedisLikeClient>;
|
|
18
15
|
//# sourceMappingURL=quasar.d.ts.map
|
package/dist/quasar.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quasar.d.ts","sourceRoot":"","sources":["../src/quasar.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"quasar.d.ts","sourceRoot":"","sources":["../src/quasar.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAOjE;;GAEG;AACH,wBAAgB,gBAAgB,CAC/B,IAAI,CAAC,EAAE,MAAM,GACX,MAAM,OAAO,CAAC,eAAe,CAAC,CAShC"}
|
package/dist/quasar.js
CHANGED
|
@@ -1,56 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Resolving a Redis connection by name, from `@c9up/quasar`.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* The shape is checked before use rather than asserted, the same way warden
|
|
10
|
-
* duck-types its host framework.
|
|
4
|
+
* The loading, the shape check and the messages are the same in every package
|
|
5
|
+
* that offers a Redis-backed option, so they are vendored rather than written
|
|
6
|
+
* again: `src/vendor/quasarConnection.ts`, generated from one source. What is
|
|
7
|
+
* specific to this package — the commands it issues, and what it does with
|
|
8
|
+
* them — stays here, because that is the part a reader needs.
|
|
11
9
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
function isRedisLikeClient(value) {
|
|
18
|
-
if (typeof value !== "object" || value === null)
|
|
19
|
-
return false;
|
|
20
|
-
// The commands this driver actually issues — the whole of `RedisLikeClient`.
|
|
21
|
-
// A connection missing one would fail on the first revocation, far from the
|
|
22
|
-
// cause. Nothing more: the driver documents itself as needing only `set`
|
|
23
|
-
// with an "EX" ttl and `exists`, so demanding sets or key scans here would
|
|
24
|
-
// reject a client that works perfectly well.
|
|
25
|
-
const required = ["set", "exists"];
|
|
26
|
-
return required.every((name) => typeof Reflect.get(value, name) === "function");
|
|
27
|
-
}
|
|
10
|
+
import { quasarConnection as loadQuasarConnection } from "./vendor/quasarConnection.js";
|
|
11
|
+
// Only what the driver documents itself as needing: `set` with an "EX" ttl,
|
|
12
|
+
// and `exists`. Demanding key scans here would reject a client that works.
|
|
13
|
+
const REQUIRED = ["set", "exists"];
|
|
28
14
|
/**
|
|
29
|
-
* A resolver
|
|
30
|
-
* loaded on the first revocation check, not at config time.
|
|
15
|
+
* A resolver — quasar is loaded on first use, not at config time.
|
|
31
16
|
*/
|
|
32
17
|
export function quasarConnection(name) {
|
|
33
|
-
return async () => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
throw new Error(`Warden: the "${name ?? "default"}" blacklist asks for a quasar connection, but @c9up/quasar is not installed.\n` +
|
|
41
|
-
" pnpm add @c9up/quasar", { cause });
|
|
42
|
-
}
|
|
43
|
-
const manager = isConnectionSource(loaded)
|
|
44
|
-
? loaded
|
|
45
|
-
: Reflect.get(Object(loaded), "default");
|
|
46
|
-
if (!isConnectionSource(manager)) {
|
|
47
|
-
throw new Error("Warden: @c9up/quasar/services/main did not expose a connection() manager");
|
|
48
|
-
}
|
|
49
|
-
const connection = manager.connection(name);
|
|
50
|
-
if (!isRedisLikeClient(connection)) {
|
|
51
|
-
throw new Error(`Warden: quasar connection "${name ?? "default"}" does not carry the commands this blacklist needs`);
|
|
52
|
-
}
|
|
53
|
-
return connection;
|
|
54
|
-
};
|
|
18
|
+
return async () => loadQuasarConnection({
|
|
19
|
+
pkg: "warden",
|
|
20
|
+
name,
|
|
21
|
+
required: REQUIRED,
|
|
22
|
+
what: "the token blacklist",
|
|
23
|
+
raise: (_reason, message, cause) => new Error(message, { cause }),
|
|
24
|
+
});
|
|
55
25
|
}
|
|
56
26
|
//# sourceMappingURL=quasar.js.map
|
package/dist/quasar.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quasar.js","sourceRoot":"","sources":["../src/quasar.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"quasar.js","sourceRoot":"","sources":["../src/quasar.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,gBAAgB,IAAI,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAExF,4EAA4E;AAC5E,2EAA2E;AAC3E,MAAM,QAAQ,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAU,CAAC;AAE5C;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAC/B,IAAa;IAEb,OAAO,KAAK,IAAI,EAAE,CACjB,oBAAoB,CAAkB;QACrC,GAAG,EAAE,QAAQ;QACb,IAAI;QACJ,QAAQ,EAAE,QAAQ;QAClB,IAAI,EAAE,qBAAqB;QAC3B,KAAK,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC;KACjE,CAAC,CAAC;AACL,CAAC"}
|
package/dist/services/main.d.ts
CHANGED
|
@@ -14,6 +14,16 @@ import type { AuthManager } from "../AuthManager.js";
|
|
|
14
14
|
export declare function setAuth(value: AuthManager): void;
|
|
15
15
|
/** @internal Read the singleton (or `undefined` pre-boot). */
|
|
16
16
|
export declare function getAuth(): AuthManager | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* @internal Release the singleton, so a shut-down application does not leave a
|
|
19
|
+
* dead AuthManager reachable through `services/main`.
|
|
20
|
+
*
|
|
21
|
+
* The caller checks ownership first (`getAuth() === mine`). Two applications in
|
|
22
|
+
* one process share this module, and the one shutting down must not clear a
|
|
23
|
+
* manager the other has since installed — for auth, that would leave the
|
|
24
|
+
* survivor authenticating against nothing, or throwing on every guarded route.
|
|
25
|
+
*/
|
|
26
|
+
export declare function clearAuth(): void;
|
|
17
27
|
declare const auth: AuthManager;
|
|
18
28
|
export default auth;
|
|
19
29
|
//# sourceMappingURL=main.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/services/main.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIrD,+DAA+D;AAC/D,wBAAgB,OAAO,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,CAEhD;AAED,8DAA8D;AAC9D,wBAAgB,OAAO,IAAI,WAAW,GAAG,SAAS,CAEjD;AAED,QAAA,MAAM,IAAI,EAAE,WAWV,CAAC;AAEH,eAAe,IAAI,CAAC"}
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/services/main.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIrD,+DAA+D;AAC/D,wBAAgB,OAAO,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,CAEhD;AAED,8DAA8D;AAC9D,wBAAgB,OAAO,IAAI,WAAW,GAAG,SAAS,CAEjD;AAED;;;;;;;;GAQG;AACH,wBAAgB,SAAS,IAAI,IAAI,CAEhC;AAED,QAAA,MAAM,IAAI,EAAE,WAWV,CAAC;AAEH,eAAe,IAAI,CAAC"}
|
package/dist/services/main.js
CHANGED
|
@@ -18,6 +18,18 @@ export function setAuth(value) {
|
|
|
18
18
|
export function getAuth() {
|
|
19
19
|
return instance;
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* @internal Release the singleton, so a shut-down application does not leave a
|
|
23
|
+
* dead AuthManager reachable through `services/main`.
|
|
24
|
+
*
|
|
25
|
+
* The caller checks ownership first (`getAuth() === mine`). Two applications in
|
|
26
|
+
* one process share this module, and the one shutting down must not clear a
|
|
27
|
+
* manager the other has since installed — for auth, that would leave the
|
|
28
|
+
* survivor authenticating against nothing, or throwing on every guarded route.
|
|
29
|
+
*/
|
|
30
|
+
export function clearAuth() {
|
|
31
|
+
instance = undefined;
|
|
32
|
+
}
|
|
21
33
|
const auth = new Proxy({}, {
|
|
22
34
|
get(_target, prop) {
|
|
23
35
|
if (!instance) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/services/main.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,IAAI,QAAiC,CAAC;AAEtC,+DAA+D;AAC/D,MAAM,UAAU,OAAO,CAAC,KAAkB;IACzC,QAAQ,GAAG,KAAK,CAAC;AAClB,CAAC;AAED,8DAA8D;AAC9D,MAAM,UAAU,OAAO;IACtB,OAAO,QAAQ,CAAC;AACjB,CAAC;AAED,MAAM,IAAI,GAAgB,IAAI,KAAK,CAAC,EAAiB,EAAE;IACtD,GAAG,CAAC,OAAO,EAAE,IAAI;QAChB,IAAI,CAAC,QAAQ,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CACd,4EAA4E;gBAC3E,2EAA2E,CAC5E,CAAC;QACH,CAAC;QACD,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;QACpD,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IACnE,CAAC;CACD,CAAC,CAAC;AAEH,eAAe,IAAI,CAAC"}
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/services/main.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,IAAI,QAAiC,CAAC;AAEtC,+DAA+D;AAC/D,MAAM,UAAU,OAAO,CAAC,KAAkB;IACzC,QAAQ,GAAG,KAAK,CAAC;AAClB,CAAC;AAED,8DAA8D;AAC9D,MAAM,UAAU,OAAO;IACtB,OAAO,QAAQ,CAAC;AACjB,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,SAAS;IACxB,QAAQ,GAAG,SAAS,CAAC;AACtB,CAAC;AAED,MAAM,IAAI,GAAgB,IAAI,KAAK,CAAC,EAAiB,EAAE;IACtD,GAAG,CAAC,OAAO,EAAE,IAAI;QAChB,IAAI,CAAC,QAAQ,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CACd,4EAA4E;gBAC3E,2EAA2E,CAC5E,CAAC;QACH,CAAC;QACD,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;QACpD,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IACnE,CAAC;CACD,CAAC,CAAC;AAEH,eAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every `platform-arch` a binary is built for.
|
|
3
|
+
*
|
|
4
|
+
* For the message a package raises when it refuses: "no binary for
|
|
5
|
+
* linux-riscv64" is only actionable next to the list of what there IS.
|
|
6
|
+
*/
|
|
7
|
+
export declare function supportedTargets(): readonly string[];
|
|
8
|
+
/** The suffix a given `platform-arch` builds under, or `undefined`. */
|
|
9
|
+
export declare function nativeTargetSuffix(target: string): string | undefined;
|
|
10
|
+
/** The suffix for THIS platform, or `undefined` where no binary is built. */
|
|
11
|
+
export declare function nativeBinarySuffix(): string | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Why the binary is not there, phrased for whoever has to fix it.
|
|
14
|
+
*
|
|
15
|
+
* "not found" and "not built for your platform" call for different actions,
|
|
16
|
+
* and a single "unavailable" leaves the reader to guess which one they are
|
|
17
|
+
* looking at.
|
|
18
|
+
*/
|
|
19
|
+
export declare function unavailableReason(cause?: unknown): string;
|
|
20
|
+
/**
|
|
21
|
+
* `musl` builds under a different suffix, and the failure is otherwise
|
|
22
|
+
* baffling: the file is there, and `require` still refuses it. Worth saying so
|
|
23
|
+
* in a message rather than leaving a reader to discover glibc.
|
|
24
|
+
*/
|
|
25
|
+
export declare function muslHint(): string;
|
|
26
|
+
/** What a load attempt did, so the caller can apply its own policy. */
|
|
27
|
+
export type NativeBinaryResult<T> = {
|
|
28
|
+
loaded: true;
|
|
29
|
+
binary: T;
|
|
30
|
+
} | {
|
|
31
|
+
loaded: false;
|
|
32
|
+
suffix: string | undefined;
|
|
33
|
+
cause?: unknown;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Load `<package root>/index.<suffix>.node`.
|
|
37
|
+
*
|
|
38
|
+
* The path is fixed rather than passed: this file is generated into
|
|
39
|
+
* `<package>/src/vendor/`, so the package root is always two levels up, from
|
|
40
|
+
* `src` and from `dist` alike.
|
|
41
|
+
*/
|
|
42
|
+
export declare function loadNativeBinary<T>(): NativeBinaryResult<T>;
|
|
43
|
+
//# sourceMappingURL=nativeBinary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nativeBinary.d.ts","sourceRoot":"","sources":["../../src/vendor/nativeBinary.ts"],"names":[],"mappings":"AAoCA;;;;;GAKG;AACH,wBAAgB,gBAAgB,IAAI,SAAS,MAAM,EAAE,CAEpD;AAED,uEAAuE;AACvE,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAErE;AAED,6EAA6E;AAC7E,wBAAgB,kBAAkB,IAAI,MAAM,GAAG,SAAS,CAEvD;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,CAQzD;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,IAAI,MAAM,CAIjC;AAED,uEAAuE;AACvE,MAAM,MAAM,kBAAkB,CAAC,CAAC,IAC7B;IAAE,MAAM,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,CAAC,CAAA;CAAE,GAC3B;IAAE,MAAM,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAElE;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,KAAK,kBAAkB,CAAC,CAAC,CAAC,CAa3D"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// Generated from scripts/vendor/nativeBinary.ts — do not edit.
|
|
2
|
+
//
|
|
3
|
+
// This package is published and built from its own repository, so the file
|
|
4
|
+
// has to exist here rather than be imported. `pnpm vendor:sync` rewrites it,
|
|
5
|
+
// and `pnpm vendor:check` fails if this copy has drifted from the original.
|
|
6
|
+
/**
|
|
7
|
+
* Finding the NAPI binary a package ships beside itself.
|
|
8
|
+
*
|
|
9
|
+
* Every package with a Rust engine repeats the same table: napi-rs names its
|
|
10
|
+
* artefacts `index.<platform>-<arch>-<abi>.node`, and the mapping from Node's
|
|
11
|
+
* `platform`/`arch` to that suffix is the part that must never differ between
|
|
12
|
+
* packages. Adding a target means adding it everywhere, and a package that
|
|
13
|
+
* missed the edit fails only on that platform — which is exactly the failure
|
|
14
|
+
* nobody reproduces.
|
|
15
|
+
*
|
|
16
|
+
* What is NOT here is the policy. Some packages degrade when the binary is
|
|
17
|
+
* absent and answer `undefined`; others refuse loudly with build instructions.
|
|
18
|
+
* Both are right for their package, so the loader reports what happened and
|
|
19
|
+
* the caller decides.
|
|
20
|
+
*/
|
|
21
|
+
import { createRequire } from "node:module";
|
|
22
|
+
import { dirname, join } from "node:path";
|
|
23
|
+
import { arch, platform } from "node:process";
|
|
24
|
+
import { fileURLToPath } from "node:url";
|
|
25
|
+
/** Node's `platform-arch` → the suffix napi-rs builds under. */
|
|
26
|
+
const TARGETS = {
|
|
27
|
+
"linux-x64": "linux-x64-gnu",
|
|
28
|
+
"linux-arm64": "linux-arm64-gnu",
|
|
29
|
+
"darwin-x64": "darwin-x64",
|
|
30
|
+
"darwin-arm64": "darwin-arm64",
|
|
31
|
+
"win32-x64": "win32-x64-msvc",
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Every `platform-arch` a binary is built for.
|
|
35
|
+
*
|
|
36
|
+
* For the message a package raises when it refuses: "no binary for
|
|
37
|
+
* linux-riscv64" is only actionable next to the list of what there IS.
|
|
38
|
+
*/
|
|
39
|
+
export function supportedTargets() {
|
|
40
|
+
return Object.keys(TARGETS);
|
|
41
|
+
}
|
|
42
|
+
/** The suffix a given `platform-arch` builds under, or `undefined`. */
|
|
43
|
+
export function nativeTargetSuffix(target) {
|
|
44
|
+
return TARGETS[target];
|
|
45
|
+
}
|
|
46
|
+
/** The suffix for THIS platform, or `undefined` where no binary is built. */
|
|
47
|
+
export function nativeBinarySuffix() {
|
|
48
|
+
return nativeTargetSuffix(`${platform}-${arch}`);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Why the binary is not there, phrased for whoever has to fix it.
|
|
52
|
+
*
|
|
53
|
+
* "not found" and "not built for your platform" call for different actions,
|
|
54
|
+
* and a single "unavailable" leaves the reader to guess which one they are
|
|
55
|
+
* looking at.
|
|
56
|
+
*/
|
|
57
|
+
export function unavailableReason(cause) {
|
|
58
|
+
if (cause !== undefined) {
|
|
59
|
+
return `failed to load (${cause instanceof Error ? cause.message : String(cause)})`;
|
|
60
|
+
}
|
|
61
|
+
const target = `${platform}-${arch}`;
|
|
62
|
+
return nativeTargetSuffix(target) !== undefined
|
|
63
|
+
? "binary not found"
|
|
64
|
+
: `no prebuilt binary for ${target}`;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* `musl` builds under a different suffix, and the failure is otherwise
|
|
68
|
+
* baffling: the file is there, and `require` still refuses it. Worth saying so
|
|
69
|
+
* in a message rather than leaving a reader to discover glibc.
|
|
70
|
+
*/
|
|
71
|
+
export function muslHint() {
|
|
72
|
+
return platform === "linux"
|
|
73
|
+
? " On Alpine/musl, the gnu binary will not load — build the musl target."
|
|
74
|
+
: "";
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Load `<package root>/index.<suffix>.node`.
|
|
78
|
+
*
|
|
79
|
+
* The path is fixed rather than passed: this file is generated into
|
|
80
|
+
* `<package>/src/vendor/`, so the package root is always two levels up, from
|
|
81
|
+
* `src` and from `dist` alike.
|
|
82
|
+
*/
|
|
83
|
+
export function loadNativeBinary() {
|
|
84
|
+
const suffix = nativeBinarySuffix();
|
|
85
|
+
if (suffix === undefined)
|
|
86
|
+
return { loaded: false, suffix };
|
|
87
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
88
|
+
try {
|
|
89
|
+
const nodeRequire = createRequire(import.meta.url);
|
|
90
|
+
return {
|
|
91
|
+
loaded: true,
|
|
92
|
+
binary: nodeRequire(join(here, `../../index.${suffix}.node`)),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
catch (cause) {
|
|
96
|
+
return { loaded: false, suffix, cause };
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=nativeBinary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nativeBinary.js","sourceRoot":"","sources":["../../src/vendor/nativeBinary.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,EAAE;AACF,2EAA2E;AAC3E,6EAA6E;AAC7E,4EAA4E;AAE5E;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,gEAAgE;AAChE,MAAM,OAAO,GAA2B;IACvC,WAAW,EAAE,eAAe;IAC5B,aAAa,EAAE,iBAAiB;IAChC,YAAY,EAAE,YAAY;IAC1B,cAAc,EAAE,cAAc;IAC9B,WAAW,EAAE,gBAAgB;CAC7B,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAA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C,GAAG,CAAC,CAAC;QACnD,OAAO;YACN,MAAM,EAAE,IAAI;YACZ,MAAM,EAAE,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,eAAe,MAAM,OAAO,CAAC,CAAM;SAClE,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;IACzC,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export interface QuasarConnectionRequest {
|
|
2
|
+
/** The package asking. It prefixes every message this can raise. */
|
|
3
|
+
pkg: string;
|
|
4
|
+
/**
|
|
5
|
+
* How this package builds an error.
|
|
6
|
+
*
|
|
7
|
+
* Not optional, and not `new Error` by default: a package with its own
|
|
8
|
+
* error type carries codes (`E_<PKG>_<REASON>`) that a caller catches on,
|
|
9
|
+
* and a shared helper throwing a bare Error would silently drop them. The
|
|
10
|
+
* two reasons are distinguished so the codes can be too.
|
|
11
|
+
*/
|
|
12
|
+
raise: (reason: "quasar-missing" | "incomplete-connection", message: string, cause?: unknown) => Error;
|
|
13
|
+
/** Connection name, or `undefined` for quasar's default. */
|
|
14
|
+
name?: string;
|
|
15
|
+
/** The commands the caller will actually issue. */
|
|
16
|
+
required: readonly string[];
|
|
17
|
+
/** What the caller does with them, for the message that names a gap. */
|
|
18
|
+
what: string;
|
|
19
|
+
/**
|
|
20
|
+
* A second way out, when this package has one.
|
|
21
|
+
*
|
|
22
|
+
* Several of them accept a client object directly, so "pass a client
|
|
23
|
+
* instead of a connection name" is actionable — and it was in each
|
|
24
|
+
* package's own message before this was shared. Dropping it to unify the
|
|
25
|
+
* wording would have made the error strictly less useful.
|
|
26
|
+
*/
|
|
27
|
+
alternative?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The named connection, checked for the commands the caller needs BEFORE it is
|
|
31
|
+
* handed over — a connection missing one would otherwise fail on the first
|
|
32
|
+
* command, far from the line that asked for it.
|
|
33
|
+
*/
|
|
34
|
+
export declare function quasarConnection<T>(request: QuasarConnectionRequest): Promise<T>;
|
|
35
|
+
//# sourceMappingURL=quasarConnection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quasarConnection.d.ts","sourceRoot":"","sources":["../../src/vendor/quasarConnection.ts"],"names":[],"mappings":"AAiDA,MAAM,WAAW,uBAAuB;IACvC,oEAAoE;IACpE,GAAG,EAAE,MAAM,CAAC;IACZ;;;;;;;OAOG;IACH,KAAK,EAAE,CACN,MAAM,EAAE,gBAAgB,GAAG,uBAAuB,EAClD,OAAO,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,OAAO,KACX,KAAK,CAAC;IACX,4DAA4D;IAC5D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,mDAAmD;IACnD,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,wEAAwE;IACxE,IAAI,EAAE,MAAM,CAAC;IACb;;;;;;;OAOG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CAAC,CAAC,EACvC,OAAO,EAAE,uBAAuB,GAC9B,OAAO,CAAC,CAAC,CAAC,CAuCZ"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// Generated from scripts/vendor/quasarConnection.ts — do not edit.
|
|
2
|
+
//
|
|
3
|
+
// This package is published and built from its own repository, so the file
|
|
4
|
+
// has to exist here rather than be imported. `pnpm vendor:sync` rewrites it,
|
|
5
|
+
// and `pnpm vendor:check` fails if this copy has drifted from the original.
|
|
6
|
+
/**
|
|
7
|
+
* Read a member without assuming how the object answers.
|
|
8
|
+
*
|
|
9
|
+
* Two shapes have to work, and they disagree about `in`. Quasar's accessor is
|
|
10
|
+
* a Proxy over an empty null-prototype object with only a `get` trap, so
|
|
11
|
+
* `"connection" in manager` is FALSE while reading it returns the function —
|
|
12
|
+
* gating on `in` rejected the real manager. And a module namespace under a
|
|
13
|
+
* test double RAISES for an export it does not have, rather than answering
|
|
14
|
+
* undefined, so a bare read fails on the mock. Reading through a catch is what
|
|
15
|
+
* satisfies both.
|
|
16
|
+
*/
|
|
17
|
+
function readMember(value, name) {
|
|
18
|
+
if (typeof value !== "object" || value === null)
|
|
19
|
+
return undefined;
|
|
20
|
+
try {
|
|
21
|
+
return Reflect.get(value, name);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function isConnectionSource(value) {
|
|
28
|
+
return typeof readMember(value, "connection") === "function";
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The named connection, checked for the commands the caller needs BEFORE it is
|
|
32
|
+
* handed over — a connection missing one would otherwise fail on the first
|
|
33
|
+
* command, far from the line that asked for it.
|
|
34
|
+
*/
|
|
35
|
+
export async function quasarConnection(request) {
|
|
36
|
+
const { pkg, name, required, what, raise, alternative } = request;
|
|
37
|
+
const specifier = "@c9up/quasar/services/main";
|
|
38
|
+
let loaded;
|
|
39
|
+
try {
|
|
40
|
+
loaded = await import(/* @vite-ignore */ specifier);
|
|
41
|
+
}
|
|
42
|
+
catch (cause) {
|
|
43
|
+
throw raise("quasar-missing", `[${pkg}] ${what} asks for the quasar connection "${name ?? "default"}", but @c9up/quasar is not installed.\n` +
|
|
44
|
+
` pnpm add @c9up/quasar${alternative ? `, ${alternative}` : ""}`, cause);
|
|
45
|
+
}
|
|
46
|
+
const manager = isConnectionSource(loaded)
|
|
47
|
+
? loaded
|
|
48
|
+
: Reflect.get(Object(loaded), "default");
|
|
49
|
+
if (!isConnectionSource(manager)) {
|
|
50
|
+
throw raise("quasar-missing", `[${pkg}] @c9up/quasar/services/main did not expose a connection() manager`);
|
|
51
|
+
}
|
|
52
|
+
const connection = manager.connection(name);
|
|
53
|
+
const missing = required.filter((command) => typeof readMember(connection, command) !== "function");
|
|
54
|
+
if (missing.length > 0) {
|
|
55
|
+
throw raise("incomplete-connection", `[${pkg}] the quasar connection${name ? ` '${name}'` : ""} is missing ${missing.join(", ")}, which ${what} issues`);
|
|
56
|
+
}
|
|
57
|
+
// Load-bearing: every member of `required` has just been checked to be a
|
|
58
|
+
// function on this object. The caller names the type it needs because only
|
|
59
|
+
// the caller knows which commands it asked for.
|
|
60
|
+
return connection;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=quasarConnection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quasarConnection.js","sourceRoot":"","sources":["../../src/vendor/quasarConnection.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,EAAE;AACF,2EAA2E;AAC3E,6EAA6E;AAC7E,4EAA4E;AAqB5E;;;;;;;;;;GAUG;AACH,SAAS,UAAU,CAAC,KAAc,EAAE,IAAY;IAC/C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,SAAS,CAAC;IAClE,IAAI,CAAC;QACJ,OAAO,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACjC,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,SAAS,CAAC;IAClB,CAAC;AACF,CAAC;AAED,SAAS,kBAAkB,CAAC,KAAc;IACzC,OAAO,OAAO,UAAU,CAAC,KAAK,EAAE,YAAY,CAAC,KAAK,UAAU,CAAC;AAC9D,CAAC;AAmCD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACrC,OAAgC;IAEhC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAClE,MAAM,SAAS,GAAG,4BAA4B,CAAC;IAC/C,IAAI,MAAe,CAAC;IACpB,IAAI,CAAC;QACJ,MAAM,GAAG,MAAM,MAAM,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;IACrD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,MAAM,KAAK,CACV,gBAAgB,EAChB,IAAI,GAAG,KAAK,IAAI,oCAAoC,IAAI,IAAI,SAAS,yCAAyC;YAC7G,0BAA0B,WAAW,CAAC,CAAC,CAAC,KAAK,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAClE,KAAK,CACL,CAAC;IACH,CAAC;IAED,MAAM,OAAO,GAAG,kBAAkB,CAAC,MAAM,CAAC;QACzC,CAAC,CAAC,MAAM;QACR,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC,CAAC;IAC1C,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,EAAE,CAAC;QAClC,MAAM,KAAK,CACV,gBAAgB,EAChB,IAAI,GAAG,oEAAoE,CAC3E,CAAC;IACH,CAAC;IAED,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAC5C,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAC9B,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,UAAU,CAAC,UAAU,EAAE,OAAO,CAAC,KAAK,UAAU,CAClE,CAAC;IACF,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,MAAM,KAAK,CACV,uBAAuB,EACvB,IAAI,GAAG,0BAA0B,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,GAAG,CAAC,CAAC,CAAC,EAAE,eAAe,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,IAAI,SAAS,CAClH,CAAC;IACH,CAAC;IACD,yEAAyE;IACzE,2EAA2E;IAC3E,gDAAgD;IAChD,OAAO,UAAe,CAAC;AACxB,CAAC"}
|
|
Binary file
|
package/package.json
CHANGED
package/src/WardenProvider.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { MfaManager } from "./mfa/MfaManager.js";
|
|
|
6
6
|
import type { BouncerRegistry } from "./middleware.js";
|
|
7
7
|
import { MemoryRightsStore } from "./rights/MemoryRightsStore.js";
|
|
8
8
|
import { RightsResolver } from "./rights/RightsResolver.js";
|
|
9
|
-
import { setAuth } from "./services/main.js";
|
|
9
|
+
import { clearAuth, getAuth, setAuth } from "./services/main.js";
|
|
10
10
|
import { ApiKeyStrategy } from "./strategies/ApiKeyStrategy.js";
|
|
11
11
|
import { JwtStrategy } from "./strategies/JwtStrategy.js";
|
|
12
12
|
import { SessionStrategy } from "./strategies/SessionStrategy.js";
|
|
@@ -26,6 +26,9 @@ export interface WardenAppContext {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export default class WardenProvider {
|
|
29
|
+
/** The manager this provider installed, so shutdown only clears its own. */
|
|
30
|
+
#auth: AuthManager | undefined;
|
|
31
|
+
|
|
29
32
|
constructor(protected app: WardenAppContext) {}
|
|
30
33
|
|
|
31
34
|
register() {
|
|
@@ -162,10 +165,23 @@ export default class WardenProvider {
|
|
|
162
165
|
|
|
163
166
|
async boot() {
|
|
164
167
|
const manager = await this.app.container.resolve(AuthManager);
|
|
165
|
-
if (manager instanceof AuthManager)
|
|
168
|
+
if (manager instanceof AuthManager) {
|
|
169
|
+
this.#auth = manager;
|
|
170
|
+
setAuth(manager);
|
|
171
|
+
}
|
|
166
172
|
await this.#registerTemplateTags();
|
|
167
173
|
}
|
|
168
174
|
|
|
175
|
+
async shutdown() {
|
|
176
|
+
// Release the module-level singleton, but only while it is still ours.
|
|
177
|
+
// A stopped application left a dead AuthManager reachable through
|
|
178
|
+
// `import auth from '@c9up/warden/services/main'`; and with two
|
|
179
|
+
// applications in one process, clearing unconditionally would take the
|
|
180
|
+
// survivor's auth down with it.
|
|
181
|
+
if (this.#auth !== undefined && getAuth() === this.#auth) clearAuth();
|
|
182
|
+
this.#auth = undefined;
|
|
183
|
+
}
|
|
184
|
+
|
|
169
185
|
/**
|
|
170
186
|
* Publish `@can` / `@cannot` to the template engine, as AdonisJS's bouncer
|
|
171
187
|
* does. A migrated template keeps `@can('PostPolicy.edit', post) … @endcan`
|
package/src/native.ts
CHANGED
|
@@ -5,21 +5,7 @@
|
|
|
5
5
|
* other consumer) throws `E_WARDEN_NAPI_REQUIRED` at use time. Password
|
|
6
6
|
* hashing is the sole responsibility of `@c9up/sigil` (story 40.1).
|
|
7
7
|
*/
|
|
8
|
-
import {
|
|
9
|
-
import { dirname, join } from "node:path";
|
|
10
|
-
import { arch, platform } from "node:process";
|
|
11
|
-
import { fileURLToPath } from "node:url";
|
|
12
|
-
|
|
13
|
-
const nodeRequire = createRequire(import.meta.url);
|
|
14
|
-
const currentDir = dirname(fileURLToPath(import.meta.url));
|
|
15
|
-
|
|
16
|
-
const platformMap: Record<string, string> = {
|
|
17
|
-
"linux-x64": "linux-x64-gnu",
|
|
18
|
-
"linux-arm64": "linux-arm64-gnu",
|
|
19
|
-
"darwin-x64": "darwin-x64",
|
|
20
|
-
"darwin-arm64": "darwin-arm64",
|
|
21
|
-
"win32-x64": "win32-x64-msvc",
|
|
22
|
-
};
|
|
8
|
+
import { loadNativeBinary } from "./vendor/nativeBinary.js";
|
|
23
9
|
|
|
24
10
|
/**
|
|
25
11
|
* The engine's surface, as the Rust declares it.
|
|
@@ -30,16 +16,12 @@ const platformMap: Record<string, string> = {
|
|
|
30
16
|
*/
|
|
31
17
|
export type NativeWarden = typeof import("./native/generated.js");
|
|
32
18
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
} catch {
|
|
41
|
-
// Binary not available — JwtStrategy will throw E_WARDEN_NAPI_REQUIRED at use time.
|
|
42
|
-
}
|
|
19
|
+
// Absent is not an error here: `JwtStrategy` throws E_WARDEN_NAPI_REQUIRED at
|
|
20
|
+
// use time, which names what the caller was trying to do. The loader reports
|
|
21
|
+
// what happened and this decides — the platform table itself is shared, since
|
|
22
|
+
// a package that misses a new target fails only on that platform.
|
|
23
|
+
const attempt = loadNativeBinary<NativeWarden>();
|
|
24
|
+
const native = attempt.loaded ? attempt.binary : undefined;
|
|
43
25
|
|
|
44
26
|
/** Whether the Rust NAPI engine loaded. */
|
|
45
27
|
export function isNativeAvailable(): boolean {
|
package/src/quasar.ts
CHANGED
|
@@ -1,78 +1,32 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Resolving a Redis connection by name, from `@c9up/quasar`.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* The shape is checked before use rather than asserted, the same way warden
|
|
10
|
-
* duck-types its host framework.
|
|
4
|
+
* The loading, the shape check and the messages are the same in every package
|
|
5
|
+
* that offers a Redis-backed option, so they are vendored rather than written
|
|
6
|
+
* again: `src/vendor/quasarConnection.ts`, generated from one source. What is
|
|
7
|
+
* specific to this package — the commands it issues, and what it does with
|
|
8
|
+
* them — stays here, because that is the part a reader needs.
|
|
11
9
|
*/
|
|
12
10
|
|
|
13
11
|
import type { RedisLikeClient } from "./RedisBlacklistDriver.js";
|
|
12
|
+
import { quasarConnection as loadQuasarConnection } from "./vendor/quasarConnection.js";
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function isConnectionSource(value: unknown): value is ConnectionSource {
|
|
21
|
-
return (
|
|
22
|
-
typeof value === "object" &&
|
|
23
|
-
value !== null &&
|
|
24
|
-
typeof Reflect.get(value, "connection") === "function"
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function isRedisLikeClient(value: unknown): value is RedisLikeClient {
|
|
29
|
-
if (typeof value !== "object" || value === null) return false;
|
|
30
|
-
// The commands this driver actually issues — the whole of `RedisLikeClient`.
|
|
31
|
-
// A connection missing one would fail on the first revocation, far from the
|
|
32
|
-
// cause. Nothing more: the driver documents itself as needing only `set`
|
|
33
|
-
// with an "EX" ttl and `exists`, so demanding sets or key scans here would
|
|
34
|
-
// reject a client that works perfectly well.
|
|
35
|
-
const required = ["set", "exists"];
|
|
36
|
-
return required.every(
|
|
37
|
-
(name) => typeof Reflect.get(value, name) === "function",
|
|
38
|
-
);
|
|
39
|
-
}
|
|
14
|
+
// Only what the driver documents itself as needing: `set` with an "EX" ttl,
|
|
15
|
+
// and `exists`. Demanding key scans here would reject a client that works.
|
|
16
|
+
const REQUIRED = ["set", "exists"] as const;
|
|
40
17
|
|
|
41
18
|
/**
|
|
42
|
-
* A resolver
|
|
43
|
-
* loaded on the first revocation check, not at config time.
|
|
19
|
+
* A resolver — quasar is loaded on first use, not at config time.
|
|
44
20
|
*/
|
|
45
21
|
export function quasarConnection(
|
|
46
22
|
name?: string,
|
|
47
23
|
): () => Promise<RedisLikeClient> {
|
|
48
|
-
return async () =>
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
" pnpm add @c9up/quasar",
|
|
57
|
-
{ cause },
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const manager = isConnectionSource(loaded)
|
|
62
|
-
? loaded
|
|
63
|
-
: Reflect.get(Object(loaded), "default");
|
|
64
|
-
if (!isConnectionSource(manager)) {
|
|
65
|
-
throw new Error(
|
|
66
|
-
"Warden: @c9up/quasar/services/main did not expose a connection() manager",
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const connection = manager.connection(name);
|
|
71
|
-
if (!isRedisLikeClient(connection)) {
|
|
72
|
-
throw new Error(
|
|
73
|
-
`Warden: quasar connection "${name ?? "default"}" does not carry the commands this blacklist needs`,
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
return connection;
|
|
77
|
-
};
|
|
24
|
+
return async () =>
|
|
25
|
+
loadQuasarConnection<RedisLikeClient>({
|
|
26
|
+
pkg: "warden",
|
|
27
|
+
name,
|
|
28
|
+
required: REQUIRED,
|
|
29
|
+
what: "the token blacklist",
|
|
30
|
+
raise: (_reason, message, cause) => new Error(message, { cause }),
|
|
31
|
+
});
|
|
78
32
|
}
|
package/src/services/main.ts
CHANGED
|
@@ -24,6 +24,19 @@ export function getAuth(): AuthManager | undefined {
|
|
|
24
24
|
return instance;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
/**
|
|
28
|
+
* @internal Release the singleton, so a shut-down application does not leave a
|
|
29
|
+
* dead AuthManager reachable through `services/main`.
|
|
30
|
+
*
|
|
31
|
+
* The caller checks ownership first (`getAuth() === mine`). Two applications in
|
|
32
|
+
* one process share this module, and the one shutting down must not clear a
|
|
33
|
+
* manager the other has since installed — for auth, that would leave the
|
|
34
|
+
* survivor authenticating against nothing, or throwing on every guarded route.
|
|
35
|
+
*/
|
|
36
|
+
export function clearAuth(): void {
|
|
37
|
+
instance = undefined;
|
|
38
|
+
}
|
|
39
|
+
|
|
27
40
|
const auth: AuthManager = new Proxy({} as AuthManager, {
|
|
28
41
|
get(_target, prop) {
|
|
29
42
|
if (!instance) {
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// Generated from scripts/vendor/nativeBinary.ts — do not edit.
|
|
2
|
+
//
|
|
3
|
+
// This package is published and built from its own repository, so the file
|
|
4
|
+
// has to exist here rather than be imported. `pnpm vendor:sync` rewrites it,
|
|
5
|
+
// and `pnpm vendor:check` fails if this copy has drifted from the original.
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Finding the NAPI binary a package ships beside itself.
|
|
9
|
+
*
|
|
10
|
+
* Every package with a Rust engine repeats the same table: napi-rs names its
|
|
11
|
+
* artefacts `index.<platform>-<arch>-<abi>.node`, and the mapping from Node's
|
|
12
|
+
* `platform`/`arch` to that suffix is the part that must never differ between
|
|
13
|
+
* packages. Adding a target means adding it everywhere, and a package that
|
|
14
|
+
* missed the edit fails only on that platform — which is exactly the failure
|
|
15
|
+
* nobody reproduces.
|
|
16
|
+
*
|
|
17
|
+
* What is NOT here is the policy. Some packages degrade when the binary is
|
|
18
|
+
* absent and answer `undefined`; others refuse loudly with build instructions.
|
|
19
|
+
* Both are right for their package, so the loader reports what happened and
|
|
20
|
+
* the caller decides.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { createRequire } from "node:module";
|
|
24
|
+
import { dirname, join } from "node:path";
|
|
25
|
+
import { arch, platform } from "node:process";
|
|
26
|
+
import { fileURLToPath } from "node:url";
|
|
27
|
+
|
|
28
|
+
/** Node's `platform-arch` → the suffix napi-rs builds under. */
|
|
29
|
+
const TARGETS: Record<string, string> = {
|
|
30
|
+
"linux-x64": "linux-x64-gnu",
|
|
31
|
+
"linux-arm64": "linux-arm64-gnu",
|
|
32
|
+
"darwin-x64": "darwin-x64",
|
|
33
|
+
"darwin-arm64": "darwin-arm64",
|
|
34
|
+
"win32-x64": "win32-x64-msvc",
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Every `platform-arch` a binary is built for.
|
|
39
|
+
*
|
|
40
|
+
* For the message a package raises when it refuses: "no binary for
|
|
41
|
+
* linux-riscv64" is only actionable next to the list of what there IS.
|
|
42
|
+
*/
|
|
43
|
+
export function supportedTargets(): readonly string[] {
|
|
44
|
+
return Object.keys(TARGETS);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** The suffix a given `platform-arch` builds under, or `undefined`. */
|
|
48
|
+
export function nativeTargetSuffix(target: string): string | undefined {
|
|
49
|
+
return TARGETS[target];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The suffix for THIS platform, or `undefined` where no binary is built. */
|
|
53
|
+
export function nativeBinarySuffix(): string | undefined {
|
|
54
|
+
return nativeTargetSuffix(`${platform}-${arch}`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Why the binary is not there, phrased for whoever has to fix it.
|
|
59
|
+
*
|
|
60
|
+
* "not found" and "not built for your platform" call for different actions,
|
|
61
|
+
* and a single "unavailable" leaves the reader to guess which one they are
|
|
62
|
+
* looking at.
|
|
63
|
+
*/
|
|
64
|
+
export function unavailableReason(cause?: unknown): string {
|
|
65
|
+
if (cause !== undefined) {
|
|
66
|
+
return `failed to load (${cause instanceof Error ? cause.message : String(cause)})`;
|
|
67
|
+
}
|
|
68
|
+
const target = `${platform}-${arch}`;
|
|
69
|
+
return nativeTargetSuffix(target) !== undefined
|
|
70
|
+
? "binary not found"
|
|
71
|
+
: `no prebuilt binary for ${target}`;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* `musl` builds under a different suffix, and the failure is otherwise
|
|
76
|
+
* baffling: the file is there, and `require` still refuses it. Worth saying so
|
|
77
|
+
* in a message rather than leaving a reader to discover glibc.
|
|
78
|
+
*/
|
|
79
|
+
export function muslHint(): string {
|
|
80
|
+
return platform === "linux"
|
|
81
|
+
? " On Alpine/musl, the gnu binary will not load — build the musl target."
|
|
82
|
+
: "";
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** What a load attempt did, so the caller can apply its own policy. */
|
|
86
|
+
export type NativeBinaryResult<T> =
|
|
87
|
+
| { loaded: true; binary: T }
|
|
88
|
+
| { loaded: false; suffix: string | undefined; cause?: unknown };
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Load `<package root>/index.<suffix>.node`.
|
|
92
|
+
*
|
|
93
|
+
* The path is fixed rather than passed: this file is generated into
|
|
94
|
+
* `<package>/src/vendor/`, so the package root is always two levels up, from
|
|
95
|
+
* `src` and from `dist` alike.
|
|
96
|
+
*/
|
|
97
|
+
export function loadNativeBinary<T>(): NativeBinaryResult<T> {
|
|
98
|
+
const suffix = nativeBinarySuffix();
|
|
99
|
+
if (suffix === undefined) return { loaded: false, suffix };
|
|
100
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
101
|
+
try {
|
|
102
|
+
const nodeRequire = createRequire(import.meta.url);
|
|
103
|
+
return {
|
|
104
|
+
loaded: true,
|
|
105
|
+
binary: nodeRequire(join(here, `../../index.${suffix}.node`)) as T,
|
|
106
|
+
};
|
|
107
|
+
} catch (cause) {
|
|
108
|
+
return { loaded: false, suffix, cause };
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// Generated from scripts/vendor/quasarConnection.ts — do not edit.
|
|
2
|
+
//
|
|
3
|
+
// This package is published and built from its own repository, so the file
|
|
4
|
+
// has to exist here rather than be imported. `pnpm vendor:sync` rewrites it,
|
|
5
|
+
// and `pnpm vendor:check` fails if this copy has drifted from the original.
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Resolving a Redis connection by name, from `@c9up/quasar`.
|
|
9
|
+
*
|
|
10
|
+
* No package here depends on quasar: it is an optional peer, and this module
|
|
11
|
+
* never imports it statically — the specifier is built at runtime so the
|
|
12
|
+
* TypeScript build stays free of it too. A host that never names a connection
|
|
13
|
+
* neither installs it nor pays for it.
|
|
14
|
+
*
|
|
15
|
+
* What varies between callers is passed in rather than copied: which commands
|
|
16
|
+
* they will issue, and what they are doing with them. Both end up in the
|
|
17
|
+
* message, because "the connection is missing lpop" is only useful next to
|
|
18
|
+
* "which the queue's atomic pop issues".
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/** The slice of quasar's manager this needs: a connection, by name. */
|
|
22
|
+
interface ConnectionSource {
|
|
23
|
+
connection(name?: string): unknown;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Read a member without assuming how the object answers.
|
|
28
|
+
*
|
|
29
|
+
* Two shapes have to work, and they disagree about `in`. Quasar's accessor is
|
|
30
|
+
* a Proxy over an empty null-prototype object with only a `get` trap, so
|
|
31
|
+
* `"connection" in manager` is FALSE while reading it returns the function —
|
|
32
|
+
* gating on `in` rejected the real manager. And a module namespace under a
|
|
33
|
+
* test double RAISES for an export it does not have, rather than answering
|
|
34
|
+
* undefined, so a bare read fails on the mock. Reading through a catch is what
|
|
35
|
+
* satisfies both.
|
|
36
|
+
*/
|
|
37
|
+
function readMember(value: unknown, name: string): unknown {
|
|
38
|
+
if (typeof value !== "object" || value === null) return undefined;
|
|
39
|
+
try {
|
|
40
|
+
return Reflect.get(value, name);
|
|
41
|
+
} catch {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function isConnectionSource(value: unknown): value is ConnectionSource {
|
|
47
|
+
return typeof readMember(value, "connection") === "function";
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface QuasarConnectionRequest {
|
|
51
|
+
/** The package asking. It prefixes every message this can raise. */
|
|
52
|
+
pkg: string;
|
|
53
|
+
/**
|
|
54
|
+
* How this package builds an error.
|
|
55
|
+
*
|
|
56
|
+
* Not optional, and not `new Error` by default: a package with its own
|
|
57
|
+
* error type carries codes (`E_<PKG>_<REASON>`) that a caller catches on,
|
|
58
|
+
* and a shared helper throwing a bare Error would silently drop them. The
|
|
59
|
+
* two reasons are distinguished so the codes can be too.
|
|
60
|
+
*/
|
|
61
|
+
raise: (
|
|
62
|
+
reason: "quasar-missing" | "incomplete-connection",
|
|
63
|
+
message: string,
|
|
64
|
+
cause?: unknown,
|
|
65
|
+
) => Error;
|
|
66
|
+
/** Connection name, or `undefined` for quasar's default. */
|
|
67
|
+
name?: string;
|
|
68
|
+
/** The commands the caller will actually issue. */
|
|
69
|
+
required: readonly string[];
|
|
70
|
+
/** What the caller does with them, for the message that names a gap. */
|
|
71
|
+
what: string;
|
|
72
|
+
/**
|
|
73
|
+
* A second way out, when this package has one.
|
|
74
|
+
*
|
|
75
|
+
* Several of them accept a client object directly, so "pass a client
|
|
76
|
+
* instead of a connection name" is actionable — and it was in each
|
|
77
|
+
* package's own message before this was shared. Dropping it to unify the
|
|
78
|
+
* wording would have made the error strictly less useful.
|
|
79
|
+
*/
|
|
80
|
+
alternative?: string;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The named connection, checked for the commands the caller needs BEFORE it is
|
|
85
|
+
* handed over — a connection missing one would otherwise fail on the first
|
|
86
|
+
* command, far from the line that asked for it.
|
|
87
|
+
*/
|
|
88
|
+
export async function quasarConnection<T>(
|
|
89
|
+
request: QuasarConnectionRequest,
|
|
90
|
+
): Promise<T> {
|
|
91
|
+
const { pkg, name, required, what, raise, alternative } = request;
|
|
92
|
+
const specifier = "@c9up/quasar/services/main";
|
|
93
|
+
let loaded: unknown;
|
|
94
|
+
try {
|
|
95
|
+
loaded = await import(/* @vite-ignore */ specifier);
|
|
96
|
+
} catch (cause) {
|
|
97
|
+
throw raise(
|
|
98
|
+
"quasar-missing",
|
|
99
|
+
`[${pkg}] ${what} asks for the quasar connection "${name ?? "default"}", but @c9up/quasar is not installed.\n` +
|
|
100
|
+
` pnpm add @c9up/quasar${alternative ? `, ${alternative}` : ""}`,
|
|
101
|
+
cause,
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const manager = isConnectionSource(loaded)
|
|
106
|
+
? loaded
|
|
107
|
+
: Reflect.get(Object(loaded), "default");
|
|
108
|
+
if (!isConnectionSource(manager)) {
|
|
109
|
+
throw raise(
|
|
110
|
+
"quasar-missing",
|
|
111
|
+
`[${pkg}] @c9up/quasar/services/main did not expose a connection() manager`,
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const connection = manager.connection(name);
|
|
116
|
+
const missing = required.filter(
|
|
117
|
+
(command) => typeof readMember(connection, command) !== "function",
|
|
118
|
+
);
|
|
119
|
+
if (missing.length > 0) {
|
|
120
|
+
throw raise(
|
|
121
|
+
"incomplete-connection",
|
|
122
|
+
`[${pkg}] the quasar connection${name ? ` '${name}'` : ""} is missing ${missing.join(", ")}, which ${what} issues`,
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
// Load-bearing: every member of `required` has just been checked to be a
|
|
126
|
+
// function on this object. The caller names the type it needs because only
|
|
127
|
+
// the caller knows which commands it asked for.
|
|
128
|
+
return connection as T;
|
|
129
|
+
}
|