@adonis-agora/authkit-vault-aws 0.3.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/LICENSE +21 -0
- package/build/index.d.ts +2 -0
- package/build/index.js +1 -0
- package/build/src/vault.d.ts +18 -0
- package/build/src/vault.js +77 -0
- package/package.json +58 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Davi de Carvalho
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/build/index.d.ts
ADDED
package/build/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createKeystoreVault } from './src/vault.js';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Estrutura mínima compatível com o KeystoreVault do authkit-server. */
|
|
2
|
+
export interface KeystoreVaultLike {
|
|
3
|
+
read(): Promise<string | null>;
|
|
4
|
+
write(blob: string): Promise<void>;
|
|
5
|
+
head?(): Promise<string | null>;
|
|
6
|
+
}
|
|
7
|
+
/** Seam injetável (get/put/version) — testável sem SDK. */
|
|
8
|
+
export interface SecretBackend {
|
|
9
|
+
get(): Promise<string | null>;
|
|
10
|
+
put(blob: string): Promise<void>;
|
|
11
|
+
version?(): Promise<string | null>;
|
|
12
|
+
}
|
|
13
|
+
export interface AwsVaultConfig {
|
|
14
|
+
secretId: string;
|
|
15
|
+
region?: string;
|
|
16
|
+
backend?: SecretBackend;
|
|
17
|
+
}
|
|
18
|
+
export declare function createKeystoreVault(cfg: AwsVaultConfig): KeystoreVaultLike;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return path;
|
|
8
|
+
};
|
|
9
|
+
class ExternalSecretVault {
|
|
10
|
+
backend;
|
|
11
|
+
constructor(backend) {
|
|
12
|
+
this.backend = backend;
|
|
13
|
+
}
|
|
14
|
+
read() {
|
|
15
|
+
return this.backend.get();
|
|
16
|
+
}
|
|
17
|
+
write(blob) {
|
|
18
|
+
return this.backend.put(blob);
|
|
19
|
+
}
|
|
20
|
+
async head() {
|
|
21
|
+
return this.backend.version ? this.backend.version() : this.backend.get();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export function createKeystoreVault(cfg) {
|
|
25
|
+
return new ExternalSecretVault(cfg.backend ?? makeAwsBackend(cfg));
|
|
26
|
+
}
|
|
27
|
+
function makeAwsBackend(cfg) {
|
|
28
|
+
// Indireção via variável: o SDK é peer/opcional e pode não estar instalado;
|
|
29
|
+
// o specifier não é resolvido em build-time pelo tsc.
|
|
30
|
+
const spec = '@aws-sdk/client-secrets-manager';
|
|
31
|
+
let sdkP;
|
|
32
|
+
let clientP;
|
|
33
|
+
const sdk = () => (sdkP ??= import(__rewriteRelativeImportExtension(spec)));
|
|
34
|
+
const client = async () => (clientP ??= (async () => {
|
|
35
|
+
const s = await sdk();
|
|
36
|
+
return new s.SecretsManagerClient(cfg.region ? { region: cfg.region } : {});
|
|
37
|
+
})());
|
|
38
|
+
return {
|
|
39
|
+
async get() {
|
|
40
|
+
const s = await sdk();
|
|
41
|
+
const c = await client();
|
|
42
|
+
try {
|
|
43
|
+
const r = await c.send(new s.GetSecretValueCommand({ SecretId: cfg.secretId }));
|
|
44
|
+
return r.SecretString ?? null;
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
if (e?.name === 'ResourceNotFoundException')
|
|
48
|
+
return null;
|
|
49
|
+
throw e;
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
async put(blob) {
|
|
53
|
+
const s = await sdk();
|
|
54
|
+
const c = await client();
|
|
55
|
+
try {
|
|
56
|
+
await c.send(new s.PutSecretValueCommand({ SecretId: cfg.secretId, SecretString: blob }));
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
if (e?.name === 'ResourceNotFoundException')
|
|
60
|
+
await c.send(new s.CreateSecretCommand({ Name: cfg.secretId, SecretString: blob }));
|
|
61
|
+
else
|
|
62
|
+
throw e;
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
async version() {
|
|
66
|
+
const s = await sdk();
|
|
67
|
+
const c = await client();
|
|
68
|
+
try {
|
|
69
|
+
const r = await c.send(new s.GetSecretValueCommand({ SecretId: cfg.secretId }));
|
|
70
|
+
return r.VersionId ?? null;
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@adonis-agora/authkit-vault-aws",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "AWS Secrets Manager keystore vault for the AuthKit JWKS keystore (createKeystoreVault).",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "dudousxd",
|
|
7
|
+
"homepage": "https://github.com/DavideCarvalho/adonis-authkit/tree/main/packages/authkit-vault-aws#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/DavideCarvalho/adonis-authkit.git",
|
|
11
|
+
"directory": "packages/authkit-vault-aws"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/DavideCarvalho/adonis-authkit/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"adonisjs",
|
|
18
|
+
"authkit",
|
|
19
|
+
"keystore",
|
|
20
|
+
"jwks",
|
|
21
|
+
"aws",
|
|
22
|
+
"secrets-manager"
|
|
23
|
+
],
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"type": "module",
|
|
28
|
+
"main": "./build/index.js",
|
|
29
|
+
"types": "./build/index.d.ts",
|
|
30
|
+
"files": [
|
|
31
|
+
"build"
|
|
32
|
+
],
|
|
33
|
+
"exports": {
|
|
34
|
+
".": "./build/index.js",
|
|
35
|
+
"./types": "./build/index.js"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"@aws-sdk/client-secrets-manager": ">=3"
|
|
39
|
+
},
|
|
40
|
+
"peerDependenciesMeta": {
|
|
41
|
+
"@aws-sdk/client-secrets-manager": {
|
|
42
|
+
"optional": true
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@adonisjs/tsconfig": "2.0.0",
|
|
47
|
+
"@japa/assert": "4.2.0",
|
|
48
|
+
"@japa/runner": "5.3.0",
|
|
49
|
+
"@poppinss/ts-exec": "1.4.4",
|
|
50
|
+
"@types/node": "25.9.1",
|
|
51
|
+
"typescript": "6.0.3"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "tsc",
|
|
55
|
+
"typecheck": "tsc --noEmit",
|
|
56
|
+
"test": "node --import=@poppinss/ts-exec bin/test.ts"
|
|
57
|
+
}
|
|
58
|
+
}
|