@c9up/warden 0.2.5 → 0.2.7
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 +74 -5
- package/dist/AccessToken.d.ts +257 -0
- package/dist/AccessToken.d.ts.map +1 -0
- package/dist/AccessToken.js +370 -0
- package/dist/AccessToken.js.map +1 -0
- package/dist/AttemptStore.d.ts +16 -2
- package/dist/AttemptStore.d.ts.map +1 -1
- package/dist/AttemptStore.js +38 -12
- package/dist/AttemptStore.js.map +1 -1
- package/dist/AuthManager.d.ts +44 -8
- package/dist/AuthManager.d.ts.map +1 -1
- package/dist/AuthManager.js +42 -11
- package/dist/AuthManager.js.map +1 -1
- package/dist/AuthRateLimiter.d.ts +16 -3
- package/dist/AuthRateLimiter.d.ts.map +1 -1
- package/dist/AuthRateLimiter.js +25 -6
- package/dist/AuthRateLimiter.js.map +1 -1
- package/dist/Authenticator.d.ts +98 -10
- package/dist/Authenticator.d.ts.map +1 -1
- package/dist/Authenticator.js +223 -19
- package/dist/Authenticator.js.map +1 -1
- package/dist/Guard.d.ts.map +1 -1
- package/dist/Guard.js +17 -5
- package/dist/Guard.js.map +1 -1
- package/dist/RedisBlacklistDriver.d.ts.map +1 -1
- package/dist/RedisBlacklistDriver.js +11 -0
- package/dist/RedisBlacklistDriver.js.map +1 -1
- package/dist/RefreshTokenStore.d.ts +37 -6
- package/dist/RefreshTokenStore.d.ts.map +1 -1
- package/dist/RefreshTokenStore.js +51 -10
- package/dist/RefreshTokenStore.js.map +1 -1
- package/dist/ResilientBlacklistDriver.d.ts +23 -6
- package/dist/ResilientBlacklistDriver.d.ts.map +1 -1
- package/dist/ResilientBlacklistDriver.js +26 -9
- package/dist/ResilientBlacklistDriver.js.map +1 -1
- package/dist/TokenBlacklist.d.ts +3 -1
- package/dist/TokenBlacklist.d.ts.map +1 -1
- package/dist/TokenBlacklist.js +27 -1
- package/dist/TokenBlacklist.js.map +1 -1
- package/dist/WardenProvider.d.ts +2 -0
- package/dist/WardenProvider.d.ts.map +1 -1
- package/dist/WardenProvider.js +4 -58
- package/dist/WardenProvider.js.map +1 -1
- package/dist/authFinder.d.ts +58 -0
- package/dist/authFinder.d.ts.map +1 -0
- package/dist/authFinder.js +77 -0
- package/dist/authFinder.js.map +1 -0
- package/dist/bearer.d.ts +12 -0
- package/dist/bearer.d.ts.map +1 -0
- package/dist/bearer.js +19 -0
- package/dist/bearer.js.map +1 -0
- package/dist/bouncer/Bouncer.d.ts +2 -2
- package/dist/bouncer/Bouncer.d.ts.map +1 -1
- package/dist/bouncer/Bouncer.js +17 -4
- package/dist/bouncer/Bouncer.js.map +1 -1
- package/dist/bouncer/PolicyAuthorizer.d.ts +1 -1
- package/dist/bouncer/PolicyAuthorizer.d.ts.map +1 -1
- package/dist/bouncer/PolicyAuthorizer.js +1 -1
- package/dist/bouncer/PolicyAuthorizer.js.map +1 -1
- package/dist/bouncer/evaluate.d.ts +5 -1
- package/dist/bouncer/evaluate.d.ts.map +1 -1
- package/dist/bouncer/evaluate.js +7 -6
- package/dist/bouncer/evaluate.js.map +1 -1
- package/dist/config.d.ts +8 -4
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +4 -1
- package/dist/config.js.map +1 -1
- package/dist/errors.d.ts +28 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +63 -2
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +10 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -4
- package/dist/index.js.map +1 -1
- package/dist/mfa/MfaManager.d.ts +33 -8
- package/dist/mfa/MfaManager.d.ts.map +1 -1
- package/dist/mfa/MfaManager.js +69 -20
- package/dist/mfa/MfaManager.js.map +1 -1
- package/dist/mfa/TotpProvider.d.ts.map +1 -1
- package/dist/mfa/TotpProvider.js +8 -0
- package/dist/mfa/TotpProvider.js.map +1 -1
- package/dist/mfa/WebauthnProvider.d.ts +22 -0
- package/dist/mfa/WebauthnProvider.d.ts.map +1 -1
- package/dist/mfa/WebauthnProvider.js +57 -12
- package/dist/mfa/WebauthnProvider.js.map +1 -1
- package/dist/middleware.d.ts +13 -3
- package/dist/middleware.d.ts.map +1 -1
- package/dist/middleware.js +28 -6
- package/dist/middleware.js.map +1 -1
- package/dist/native.d.ts +6 -2
- package/dist/native.d.ts.map +1 -1
- package/dist/native.js +19 -2
- package/dist/native.js.map +1 -1
- package/dist/quasar.d.ts.map +1 -1
- package/dist/quasar.js +8 -1
- package/dist/quasar.js.map +1 -1
- package/dist/rights/RightsResolver.d.ts +10 -0
- package/dist/rights/RightsResolver.d.ts.map +1 -1
- package/dist/rights/RightsResolver.js +23 -0
- package/dist/rights/RightsResolver.js.map +1 -1
- package/dist/sanitize.d.ts.map +1 -1
- package/dist/sanitize.js +3 -1
- package/dist/sanitize.js.map +1 -1
- package/dist/services/main.d.ts.map +1 -1
- package/dist/services/main.js +12 -2
- package/dist/services/main.js.map +1 -1
- package/dist/standalone.d.ts +24 -3
- package/dist/standalone.d.ts.map +1 -1
- package/dist/standalone.js +22 -32
- package/dist/standalone.js.map +1 -1
- package/dist/strategies/ApiKeyStrategy.d.ts +46 -12
- package/dist/strategies/ApiKeyStrategy.d.ts.map +1 -1
- package/dist/strategies/ApiKeyStrategy.js +76 -37
- package/dist/strategies/ApiKeyStrategy.js.map +1 -1
- package/dist/strategies/BasicAuthStrategy.d.ts.map +1 -1
- package/dist/strategies/BasicAuthStrategy.js +5 -2
- package/dist/strategies/BasicAuthStrategy.js.map +1 -1
- package/dist/strategies/JwtStrategy.d.ts +6 -2
- package/dist/strategies/JwtStrategy.d.ts.map +1 -1
- package/dist/strategies/JwtStrategy.js +58 -11
- package/dist/strategies/JwtStrategy.js.map +1 -1
- package/dist/strategies/SessionStrategy.d.ts.map +1 -1
- package/dist/strategies/SessionStrategy.js +4 -1
- package/dist/strategies/SessionStrategy.js.map +1 -1
- package/dist/templateTags.d.ts +42 -0
- package/dist/templateTags.d.ts.map +1 -0
- package/dist/templateTags.js +82 -0
- package/dist/templateTags.js.map +1 -0
- package/dist/vendor/nativeBinary.d.ts +26 -2
- package/dist/vendor/nativeBinary.d.ts.map +1 -1
- package/dist/vendor/nativeBinary.js +63 -6
- package/dist/vendor/nativeBinary.js.map +1 -1
- package/dist/vendor/quasarConnection.d.ts +44 -3
- package/dist/vendor/quasarConnection.d.ts.map +1 -1
- package/dist/vendor/quasarConnection.js +64 -23
- package/dist/vendor/quasarConnection.js.map +1 -1
- 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 +9 -5
- package/src/AccessToken.ts +550 -0
- package/src/AttemptStore.ts +42 -13
- package/src/AuthManager.ts +75 -18
- package/src/AuthRateLimiter.ts +24 -8
- package/src/Authenticator.ts +282 -22
- package/src/Guard.ts +18 -5
- package/src/RedisBlacklistDriver.ts +11 -0
- package/src/RefreshTokenStore.ts +79 -13
- package/src/ResilientBlacklistDriver.ts +30 -9
- package/src/TokenBlacklist.ts +28 -1
- package/src/WardenProvider.ts +6 -83
- package/src/authFinder.ts +118 -0
- package/src/bearer.ts +16 -0
- package/src/bouncer/Bouncer.ts +21 -6
- package/src/bouncer/PolicyAuthorizer.ts +1 -1
- package/src/bouncer/evaluate.ts +7 -10
- package/src/config.ts +8 -4
- package/src/errors.ts +80 -2
- package/src/index.ts +29 -0
- package/src/mfa/MfaManager.ts +98 -22
- package/src/mfa/TotpProvider.ts +15 -2
- package/src/mfa/WebauthnProvider.ts +77 -13
- package/src/middleware.ts +52 -8
- package/src/native.ts +20 -4
- package/src/quasar.ts +13 -2
- package/src/rights/RightsResolver.ts +27 -0
- package/src/sanitize.ts +4 -2
- package/src/services/main.ts +14 -2
- package/src/standalone.ts +75 -37
- package/src/strategies/ApiKeyStrategy.ts +117 -42
- package/src/strategies/BasicAuthStrategy.ts +7 -2
- package/src/strategies/JwtStrategy.ts +61 -10
- package/src/strategies/SessionStrategy.ts +4 -1
- package/src/templateTags.ts +117 -0
- package/src/vendor/nativeBinary.ts +82 -6
- package/src/vendor/quasarConnection.ts +105 -22
- package/stubs/config/auth.stub +3 -0
- package/scripts/build-napi-types.mjs +0 -69
- package/scripts/copy-napi.mjs +0 -75
- package/scripts/generate-napi-types.mjs +0 -156
package/scripts/copy-napi.mjs
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { copyFileSync, existsSync } from 'node:fs'
|
|
2
|
-
import { dirname, join, resolve } from 'node:path'
|
|
3
|
-
import { arch, env, platform } from 'node:process'
|
|
4
|
-
import { fileURLToPath } from 'node:url'
|
|
5
|
-
|
|
6
|
-
const here = dirname(fileURLToPath(import.meta.url))
|
|
7
|
-
const root = join(here, '..')
|
|
8
|
-
const CRATE = 'warden_engine_napi'
|
|
9
|
-
const TAG = '[warden:napi]'
|
|
10
|
-
|
|
11
|
-
// Rust target triple -> { suffix, os }. Set CARGO_BUILD_TARGET to cross-compile
|
|
12
|
-
// (e.g. build the x86_64-apple-darwin binary on an arm64 macOS runner). When
|
|
13
|
-
// unset we fall back to the host platform/arch and the default target/release.
|
|
14
|
-
const tripleMap = {
|
|
15
|
-
'x86_64-unknown-linux-gnu': { suffix: 'linux-x64-gnu', os: 'linux' },
|
|
16
|
-
'aarch64-unknown-linux-gnu': { suffix: 'linux-arm64-gnu', os: 'linux' },
|
|
17
|
-
'x86_64-apple-darwin': { suffix: 'darwin-x64', os: 'darwin' },
|
|
18
|
-
'aarch64-apple-darwin': { suffix: 'darwin-arm64', os: 'darwin' },
|
|
19
|
-
'x86_64-pc-windows-msvc': { suffix: 'win32-x64-msvc', os: 'win32' },
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const hostSuffixMap = {
|
|
23
|
-
'linux-x64': 'linux-x64-gnu',
|
|
24
|
-
'linux-arm64': 'linux-arm64-gnu',
|
|
25
|
-
'darwin-x64': 'darwin-x64',
|
|
26
|
-
'darwin-arm64': 'darwin-arm64',
|
|
27
|
-
'win32-x64': 'win32-x64-msvc',
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// Cargo writes its artifacts under CARGO_TARGET_DIR when that is set — a
|
|
31
|
-
// shared cache, a CI mount — so they are not under this package's `target/` at
|
|
32
|
-
// all. A relative value is resolved against the directory cargo ran in, which
|
|
33
|
-
// is this package root.
|
|
34
|
-
const targetDir = env.CARGO_TARGET_DIR
|
|
35
|
-
? resolve(root, env.CARGO_TARGET_DIR)
|
|
36
|
-
: join(root, 'target')
|
|
37
|
-
|
|
38
|
-
const triple = env.CARGO_BUILD_TARGET ?? ''
|
|
39
|
-
let suffix
|
|
40
|
-
let os
|
|
41
|
-
let releaseDir
|
|
42
|
-
if (triple) {
|
|
43
|
-
const entry = tripleMap[triple]
|
|
44
|
-
if (!entry) {
|
|
45
|
-
throw new Error(`${TAG} unsupported CARGO_BUILD_TARGET: ${triple}`)
|
|
46
|
-
}
|
|
47
|
-
suffix = entry.suffix
|
|
48
|
-
os = entry.os
|
|
49
|
-
releaseDir = join(targetDir, triple, 'release')
|
|
50
|
-
} else {
|
|
51
|
-
suffix = hostSuffixMap[`${platform}-${arch}`]
|
|
52
|
-
os = platform
|
|
53
|
-
releaseDir = join(targetDir, 'release')
|
|
54
|
-
if (!suffix) {
|
|
55
|
-
throw new Error(`${TAG} unsupported platform/arch: ${platform}-${arch}`)
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const candidates =
|
|
60
|
-
os === 'win32'
|
|
61
|
-
? [join(releaseDir, `${CRATE}.dll`), join(releaseDir, `lib${CRATE}.dll`)]
|
|
62
|
-
: os === 'darwin'
|
|
63
|
-
? [join(releaseDir, `lib${CRATE}.dylib`)]
|
|
64
|
-
: [join(releaseDir, `lib${CRATE}.so`)]
|
|
65
|
-
|
|
66
|
-
const source = candidates.find((candidate) => existsSync(candidate))
|
|
67
|
-
if (!source) {
|
|
68
|
-
throw new Error(
|
|
69
|
-
`${TAG} native library not found. Looked for:\n${candidates.map((p) => `- ${p}`).join('\n')}`,
|
|
70
|
-
)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const target = join(root, `index.${suffix}.node`)
|
|
74
|
-
copyFileSync(source, target)
|
|
75
|
-
console.log(`${TAG} copied ${source} -> ${target}`)
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Generate the TypeScript surface of the native module FROM the Rust.
|
|
4
|
-
*
|
|
5
|
-
* `napi-derive`'s `type-def` feature emits one JSON line per exported item
|
|
6
|
-
* while cargo compiles. Those lines are the source of truth: they are derived
|
|
7
|
-
* from the `#[napi]` items themselves, so a signature cannot drift from the
|
|
8
|
-
* Rust without this file changing.
|
|
9
|
-
*
|
|
10
|
-
* Hand-written interfaces are what this replaces, and they do drift — nothing
|
|
11
|
-
* on the TypeScript side notices when a `pub fn` gains a parameter or stops
|
|
12
|
-
* being `async`.
|
|
13
|
-
*
|
|
14
|
-
* One thing napi-rs cannot infer: the shape of a `JsFunction` callback. It
|
|
15
|
-
* emits `(...args: any[]) => any`. Any such parameter is refined below, by
|
|
16
|
-
* name, and the script fails if a refinement no longer matches anything — so
|
|
17
|
-
* the table cannot rot either.
|
|
18
|
-
*
|
|
19
|
-
* TYPE_DEF_TMP_PATH=<file> cargo build -p <crate>
|
|
20
|
-
* node scripts/generate-napi-types.mjs <file> <out.d.ts>
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
import { readFileSync, writeFileSync } from 'node:fs'
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Callback signatures napi-rs erases to `any`, restored here.
|
|
27
|
-
*
|
|
28
|
-
* Keyed by `<owner>.<method>`; the value replaces the whole parameter. Every
|
|
29
|
-
* entry must match, or the script fails: a stale refinement is how a hand
|
|
30
|
-
* annotation quietly stops describing the Rust.
|
|
31
|
-
*
|
|
32
|
-
* Empty while this crate exposes no `JsFunction` parameter — add an entry the
|
|
33
|
-
* day one appears, rather than letting an `any` through.
|
|
34
|
-
*/
|
|
35
|
-
const CALLBACK_REFINEMENTS = {}
|
|
36
|
-
|
|
37
|
-
const [input, output] = process.argv.slice(2)
|
|
38
|
-
if (!input || !output) {
|
|
39
|
-
console.error('usage: generate-napi-types.mjs <type-def file> <out.d.ts>')
|
|
40
|
-
process.exit(2)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const entries = readFileSync(input, 'utf8')
|
|
44
|
-
.split('\n')
|
|
45
|
-
.map((l) => l.trim())
|
|
46
|
-
.filter(Boolean)
|
|
47
|
-
.map((l) => JSON.parse(l))
|
|
48
|
-
|
|
49
|
-
const used = new Set()
|
|
50
|
-
|
|
51
|
-
/** Apply the refinements that belong to `owner`, tracking which ones matched. */
|
|
52
|
-
function refine(owner, body) {
|
|
53
|
-
let out = body
|
|
54
|
-
for (const [key, { from, to }] of Object.entries(CALLBACK_REFINEMENTS)) {
|
|
55
|
-
const [entryOwner] = key.split('.')
|
|
56
|
-
if (entryOwner !== owner) continue
|
|
57
|
-
if (out.includes(from)) {
|
|
58
|
-
out = out.replace(from, to)
|
|
59
|
-
used.add(key)
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return out
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* JSDoc as emitted by napi-derive, indented to sit above its member.
|
|
67
|
-
*
|
|
68
|
-
* `*` followed by `/` inside the text closes the comment early — a Rust doc
|
|
69
|
-
* example holding a cron expression (`0 */5 * * *`) is enough to do it, and
|
|
70
|
-
* the generated file then fails to parse. Escaped rather than stripped, so the
|
|
71
|
-
* example still reads correctly.
|
|
72
|
-
*/
|
|
73
|
-
function docBlock(doc, indent = '') {
|
|
74
|
-
if (!doc) return ''
|
|
75
|
-
// Escape every `*/` EXCEPT the one that closes the block. A Rust doc example
|
|
76
|
-
// holding a cron expression (`0 */5 * * *`) closes the comment early
|
|
77
|
-
// otherwise, and the generated file stops parsing — but escaping the closer
|
|
78
|
-
// too breaks it just as thoroughly, whether the block spans one line or many.
|
|
79
|
-
const closer = doc.lastIndexOf('*/')
|
|
80
|
-
const escaped =
|
|
81
|
-
closer === -1
|
|
82
|
-
? doc
|
|
83
|
-
: doc.slice(0, closer).replaceAll('*/', '*\\/') + doc.slice(closer)
|
|
84
|
-
return (
|
|
85
|
-
escaped
|
|
86
|
-
.split('\n')
|
|
87
|
-
.filter((l) => l.length > 0)
|
|
88
|
-
.map((l) => `${indent}${l}`)
|
|
89
|
-
.join('\n') + '\n'
|
|
90
|
-
)
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const interfaces = entries.filter((e) => e.kind === 'interface')
|
|
94
|
-
const structs = entries.filter((e) => e.kind === 'struct')
|
|
95
|
-
const impls = new Map(entries.filter((e) => e.kind === 'impl').map((e) => [e.name, e]))
|
|
96
|
-
const fns = entries.filter((e) => e.kind === 'fn')
|
|
97
|
-
|
|
98
|
-
const out = [
|
|
99
|
-
'// GENERATED FROM THE RUST — do not edit.',
|
|
100
|
-
'//',
|
|
101
|
-
"// Produced by scripts/generate-napi-types.mjs from napi-derive's type-def",
|
|
102
|
-
'// output. Editing this file by hand puts it back where it started: a',
|
|
103
|
-
'// description that can disagree with the code it describes.',
|
|
104
|
-
'',
|
|
105
|
-
]
|
|
106
|
-
|
|
107
|
-
for (const iface of interfaces) {
|
|
108
|
-
out.push(docBlock(iface.js_doc))
|
|
109
|
-
out.push(`export interface ${iface.name} {`)
|
|
110
|
-
for (const line of iface.def.split('\n')) {
|
|
111
|
-
out.push(line ? ` ${line.trim()}` : '')
|
|
112
|
-
}
|
|
113
|
-
out.push('}', '')
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
for (const struct of structs) {
|
|
117
|
-
const impl = impls.get(struct.name)
|
|
118
|
-
out.push(docBlock(struct.js_doc))
|
|
119
|
-
out.push(`export declare class ${struct.name} {`)
|
|
120
|
-
if (impl) {
|
|
121
|
-
for (const line of refine(struct.name, impl.def).split('\n')) {
|
|
122
|
-
out.push(line ? ` ${line.trim()}` : '')
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
out.push('}', '')
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
for (const fn of fns) {
|
|
129
|
-
out.push(docBlock(fn.js_doc))
|
|
130
|
-
// napi-derive emits the whole declaration for a function, unlike a struct
|
|
131
|
-
// where `def` holds only the members.
|
|
132
|
-
const declaration = fn.def.trim()
|
|
133
|
-
// napi-derive 3 emits a bare `function name(...)` where 2 emitted the
|
|
134
|
-
// signature after the name; concatenating onto the former produced
|
|
135
|
-
// `function xfunction x(...)`.
|
|
136
|
-
const rendered = declaration.startsWith('export declare function')
|
|
137
|
-
? declaration
|
|
138
|
-
: declaration.startsWith('function ')
|
|
139
|
-
? `export declare ${declaration}`
|
|
140
|
-
: `export declare function ${fn.name}${declaration}`
|
|
141
|
-
out.push(`${rendered};`, '')
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
const stale = Object.keys(CALLBACK_REFINEMENTS).filter((k) => !used.has(k))
|
|
145
|
-
if (stale.length > 0) {
|
|
146
|
-
console.error(
|
|
147
|
-
`[napi-types] refinement(s) that matched nothing: ${stale.join(', ')}\n` +
|
|
148
|
-
'[napi-types] the Rust changed under them — update or remove the entry.',
|
|
149
|
-
)
|
|
150
|
-
process.exit(1)
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
writeFileSync(output, out.join('\n'))
|
|
154
|
-
console.log(
|
|
155
|
-
`[napi-types] ${output} — ${interfaces.length} interface(s), ${structs.length} class(es), ${fns.length} function(s)`,
|
|
156
|
-
)
|