@c9up/warden 0.1.25 → 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/RedisBlacklistDriver.d.ts.map +1 -1
- package/dist/RedisBlacklistDriver.js +12 -2
- package/dist/RedisBlacklistDriver.js.map +1 -1
- package/dist/WardenProvider.d.ts +2 -0
- package/dist/WardenProvider.d.ts.map +1 -1
- package/dist/WardenProvider.js +29 -3
- package/dist/WardenProvider.js.map +1 -1
- package/dist/augmentations.d.ts +27 -1
- package/dist/augmentations.d.ts.map +1 -1
- package/dist/augmentations.js +9 -1
- package/dist/augmentations.js.map +1 -1
- package/dist/bouncer/Bouncer.d.ts.map +1 -1
- package/dist/bouncer/Bouncer.js +2 -1
- package/dist/bouncer/Bouncer.js.map +1 -1
- package/dist/bouncer/PolicyAuthorizer.d.ts.map +1 -1
- package/dist/bouncer/PolicyAuthorizer.js +2 -1
- package/dist/bouncer/PolicyAuthorizer.js.map +1 -1
- package/dist/bouncer/emitSafely.d.ts +18 -0
- package/dist/bouncer/emitSafely.d.ts.map +1 -0
- package/dist/bouncer/emitSafely.js +22 -0
- package/dist/bouncer/emitSafely.js.map +1 -0
- package/dist/bouncer/types.d.ts +10 -1
- package/dist/bouncer/types.d.ts.map +1 -1
- package/dist/mfa/BackupCodesProvider.js +2 -2
- package/dist/mfa/BackupCodesProvider.js.map +1 -1
- package/dist/mfa/MfaManager.js +1 -1
- package/dist/mfa/MfaManager.js.map +1 -1
- package/dist/mfa/TotpProvider.js +6 -5
- package/dist/mfa/TotpProvider.js.map +1 -1
- package/dist/mfa/base32.js +2 -2
- package/dist/mfa/base32.js.map +1 -1
- package/dist/mfa/webauthn-codec.d.ts.map +1 -1
- package/dist/mfa/webauthn-codec.js +11 -4
- package/dist/mfa/webauthn-codec.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.darwin-arm64.node +0 -0
- package/index.darwin-x64.node +0 -0
- package/index.linux-arm64-gnu.node +0 -0
- package/index.linux-x64-gnu.node +0 -0
- package/index.win32-x64-msvc.node +0 -0
- package/package.json +3 -2
- package/scripts/build-napi-types.mjs +4 -3
- package/scripts/generate-napi-types.mjs +9 -6
- package/src/RedisBlacklistDriver.ts +15 -5
- package/src/WardenProvider.ts +31 -5
- package/src/augmentations.ts +28 -1
- package/src/bouncer/Bouncer.ts +2 -1
- package/src/bouncer/PolicyAuthorizer.ts +2 -1
- package/src/bouncer/emitSafely.ts +28 -0
- package/src/bouncer/types.ts +10 -1
- package/src/mfa/BackupCodesProvider.ts +2 -2
- package/src/mfa/MfaManager.ts +1 -1
- package/src/mfa/TotpProvider.ts +6 -6
- package/src/mfa/base32.ts +2 -2
- package/src/mfa/webauthn-codec.ts +11 -4
- 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
|
@@ -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
|
+
}
|