@c9up/warden 0.1.26 → 0.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/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/mfa/OtpProvider.d.ts +39 -1
- package/dist/mfa/OtpProvider.d.ts.map +1 -1
- package/dist/mfa/OtpProvider.js +97 -5
- package/dist/mfa/OtpProvider.js.map +1 -1
- package/dist/mfa/WebauthnProvider.d.ts +60 -10
- package/dist/mfa/WebauthnProvider.d.ts.map +1 -1
- package/dist/mfa/WebauthnProvider.js +207 -47
- package/dist/mfa/WebauthnProvider.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/mfa/OtpProvider.ts +133 -6
- package/src/mfa/WebauthnProvider.ts +289 -71
- 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,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
|
+
}
|