@adonis-agora/crypto-integrations 0.0.0-stage → 0.1.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/CHANGELOG.md +23 -0
- package/LICENSE +21 -0
- package/README.md +23 -2
- package/dist/src/agent.d.ts +25 -0
- package/dist/src/agent.d.ts.map +1 -0
- package/dist/src/agent.js +31 -0
- package/dist/src/agent.js.map +1 -0
- package/dist/src/authkit.d.ts +25 -0
- package/dist/src/authkit.d.ts.map +1 -0
- package/dist/src/authkit.js +33 -0
- package/dist/src/authkit.js.map +1 -0
- package/dist/src/config.d.ts +26 -0
- package/dist/src/config.d.ts.map +1 -0
- package/dist/src/config.js +32 -0
- package/dist/src/config.js.map +1 -0
- package/dist/src/durable.d.ts +74 -0
- package/dist/src/durable.d.ts.map +1 -0
- package/dist/src/durable.js +124 -0
- package/dist/src/durable.js.map +1 -0
- package/dist/src/flags.d.ts +43 -0
- package/dist/src/flags.d.ts.map +1 -0
- package/dist/src/flags.js +44 -0
- package/dist/src/flags.js.map +1 -0
- package/dist/src/http.d.ts +37 -0
- package/dist/src/http.d.ts.map +1 -0
- package/dist/src/http.js +35 -0
- package/dist/src/http.js.map +1 -0
- package/dist/src/index.d.ts +6 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +6 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/keys.d.ts +7 -0
- package/dist/src/keys.d.ts.map +1 -0
- package/dist/src/keys.js +7 -0
- package/dist/src/keys.js.map +1 -0
- package/dist/src/kms.d.ts +35 -0
- package/dist/src/kms.d.ts.map +1 -0
- package/dist/src/kms.js +117 -0
- package/dist/src/kms.js.map +1 -0
- package/dist/src/payloads.d.ts +28 -0
- package/dist/src/payloads.d.ts.map +1 -0
- package/dist/src/payloads.js +41 -0
- package/dist/src/payloads.js.map +1 -0
- package/dist/src/source.d.ts +24 -0
- package/dist/src/source.d.ts.map +1 -0
- package/dist/src/source.js +14 -0
- package/dist/src/source.js.map +1 -0
- package/package.json +93 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# @adonis-agora/crypto-integrations
|
|
2
|
+
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#5](https://github.com/DavideCarvalho/adonis-agora-crypto/pull/5) [`6b141b5`](https://github.com/DavideCarvalho/adonis-agora-crypto/commit/6b141b5b4ca090c39f60d72d0581beec60863504) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - The 0.x integrations package, so the rc libs stay untouched.
|
|
8
|
+
|
|
9
|
+
- `/authkit`, `/agent`, `/config`: a crypto-kit KMS root backed by the crypto server under each lib's
|
|
10
|
+
key convention (`authkit-root`, `agent-poppy-root`, `config-root`) plus an `agora:doctor` check
|
|
11
|
+
that the key exists, is `aes256-gcm`, and that this process can seal and open with it (missing key,
|
|
12
|
+
wrong type, missing capabilities and a changed root each get their own message and fix).
|
|
13
|
+
- `/durable`: `encryptedTransport` and `encryptedControlPlane` decorators over ready instances —
|
|
14
|
+
task `input`, step `output`/`error`, heartbeat `progress` and control-plane `event` payloads are
|
|
15
|
+
sealed; ids, step names, groups, priorities, attempts, `from`/`runId` and queue metadata stay in
|
|
16
|
+
clear so routing and dedupe are unchanged. `onControl` keeps broker order, and the docs state the
|
|
17
|
+
NestJS interop caveat.
|
|
18
|
+
- `/flags`: an envelope `fetch` for `transports.http` and the posthog/clickhouse sinks.
|
|
19
|
+
- `/http`: an envelope `fetch` for any call (authkit token requests, config tenant fetches) plus the
|
|
20
|
+
receiver middleware re-exports.
|
|
21
|
+
|
|
22
|
+
Every helper accepts `{ client }` (remote server) or `{ service, partition }` (embedded server), so
|
|
23
|
+
the same integration works in `standalone`, `control-plane` and `tenant`.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Davi 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/README.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @adonis-agora/crypto-integrations
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The 0.x package that plugs `@adonis-agora/crypto` into the other Agora libs without touching them.
|
|
4
|
+
One subpath per seam; every helper takes `{ source, key? }`, where `source` is `{ client }` (remote)
|
|
5
|
+
or `{ service, partition }` (the server embedded in the app).
|
|
6
|
+
|
|
7
|
+
| Subpath | What it gives you | Default key |
|
|
8
|
+
| --- | --- | --- |
|
|
9
|
+
| `@adonis-agora/crypto-integrations/authkit` | KMS root for authkit-server (`crypto.kms`) + doctor check | `authkit-root` |
|
|
10
|
+
| `…/agent` | KMS root for agent's poppy connections + doctor check | `agent-poppy-root` |
|
|
11
|
+
| `…/config` | KMS root for the config control plane + doctor check | `config-root` |
|
|
12
|
+
| `…/durable` | `encryptedTransport` / `encryptedControlPlane` decorators | `durable-tasks` (you name it) |
|
|
13
|
+
| `…/flags` | envelope `fetch` for `transports.http` and the posthog/clickhouse sinks | `flags-events` |
|
|
14
|
+
| `…/http` | envelope `fetch` for any call (authkit token, config tenant, …) + middleware re-exports | you name it |
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { configKms, configKmsCheck } from '@adonis-agora/crypto-integrations/config'
|
|
18
|
+
|
|
19
|
+
export default defineConfig({
|
|
20
|
+
crypto: { kms: configKms({ source: { client: crypto } }) },
|
|
21
|
+
})
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Docs: <https://davidecarvalho.github.io/agora/docs/crypto/integrations>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { AgoraDoctorCheck } from '@adonis-agora/crypto';
|
|
2
|
+
import type { KmsAdapterLike } from '@adonis-agora/crypto-client';
|
|
3
|
+
import { type KmsCheckOptions, type KmsIntegrationOptions } from './kms.js';
|
|
4
|
+
/** agent's poppy-connections root: the refresh tokens, DPoP keys and delegated keys it keeps. */
|
|
5
|
+
export declare const AGENT_ROOT_KEY: "agent-poppy-root";
|
|
6
|
+
/** The package the check reports under. */
|
|
7
|
+
export declare const AGENT_PACKAGE = "@adonis-agora/agent";
|
|
8
|
+
/**
|
|
9
|
+
* The KMS root for agent's poppy connections:
|
|
10
|
+
*
|
|
11
|
+
* ```ts title="config/poppy.ts"
|
|
12
|
+
* crypto: { kms: agentPoppyKms({ source: { client: crypto } }) }
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* Each connection's state (refresh token, DPoP and delegated private keys, sign-in flows) is sealed
|
|
16
|
+
* with a data key wrapped by `agent-poppy-root`.
|
|
17
|
+
*/
|
|
18
|
+
export declare function agentPoppyKms(options: Omit<KmsIntegrationOptions, 'key'> & {
|
|
19
|
+
key?: string;
|
|
20
|
+
}): KmsAdapterLike;
|
|
21
|
+
/** `agora:doctor --lib agent`: `agent-poppy-root` exists and this process can use it. */
|
|
22
|
+
export declare function agentPoppyKmsCheck(options: Omit<KmsCheckOptions, 'lib' | 'packageName' | 'key'> & {
|
|
23
|
+
key?: string;
|
|
24
|
+
}): AgoraDoctorCheck;
|
|
25
|
+
//# sourceMappingURL=agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/agent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAElE,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,qBAAqB,EAA0B,MAAM,UAAU,CAAC;AAEpG,iGAAiG;AACjG,eAAO,MAAM,cAAc,oBAAkB,CAAC;AAC9C,2CAA2C;AAC3C,eAAO,MAAM,aAAa,wBAAwB,CAAC;AAEnD;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,IAAI,CAAC,qBAAqB,EAAE,KAAK,CAAC,GAAG;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAC7D,cAAc,CAGhB;AAED,yFAAyF;AACzF,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,IAAI,CAAC,eAAe,EAAE,KAAK,GAAG,aAAa,GAAG,KAAK,CAAC,GAAG;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAC/E,gBAAgB,CAQlB"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ROOT_KEYS } from './keys.js';
|
|
2
|
+
import { kmsDoctorCheck, kmsFor } from './kms.js';
|
|
3
|
+
/** agent's poppy-connections root: the refresh tokens, DPoP keys and delegated keys it keeps. */
|
|
4
|
+
export const AGENT_ROOT_KEY = ROOT_KEYS.agent;
|
|
5
|
+
/** The package the check reports under. */
|
|
6
|
+
export const AGENT_PACKAGE = '@adonis-agora/agent';
|
|
7
|
+
/**
|
|
8
|
+
* The KMS root for agent's poppy connections:
|
|
9
|
+
*
|
|
10
|
+
* ```ts title="config/poppy.ts"
|
|
11
|
+
* crypto: { kms: agentPoppyKms({ source: { client: crypto } }) }
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* Each connection's state (refresh token, DPoP and delegated private keys, sign-in flows) is sealed
|
|
15
|
+
* with a data key wrapped by `agent-poppy-root`.
|
|
16
|
+
*/
|
|
17
|
+
export function agentPoppyKms(options) {
|
|
18
|
+
const key = options.key ?? AGENT_ROOT_KEY;
|
|
19
|
+
return kmsFor(key, { ...options, key });
|
|
20
|
+
}
|
|
21
|
+
/** `agora:doctor --lib agent`: `agent-poppy-root` exists and this process can use it. */
|
|
22
|
+
export function agentPoppyKmsCheck(options) {
|
|
23
|
+
return kmsDoctorCheck({
|
|
24
|
+
...options,
|
|
25
|
+
lib: 'agent',
|
|
26
|
+
packageName: AGENT_PACKAGE,
|
|
27
|
+
key: options.key ?? AGENT_ROOT_KEY,
|
|
28
|
+
title: 'KMS root for poppy connections',
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../../src/agent.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAoD,cAAc,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEpG,iGAAiG;AACjG,MAAM,CAAC,MAAM,cAAc,GAAG,SAAS,CAAC,KAAK,CAAC;AAC9C,2CAA2C;AAC3C,MAAM,CAAC,MAAM,aAAa,GAAG,qBAAqB,CAAC;AAEnD;;;;;;;;;GASG;AACH,MAAM,UAAU,aAAa,CAC3B,OAA8D;IAE9D,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,cAAc,CAAC;IAC1C,OAAO,MAAM,CAAC,GAAG,EAAE,EAAE,GAAG,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC;AAC1C,CAAC;AAED,yFAAyF;AACzF,MAAM,UAAU,kBAAkB,CAChC,OAAgF;IAEhF,OAAO,cAAc,CAAC;QACpB,GAAG,OAAO;QACV,GAAG,EAAE,OAAO;QACZ,WAAW,EAAE,aAAa;QAC1B,GAAG,EAAE,OAAO,CAAC,GAAG,IAAI,cAAc;QAClC,KAAK,EAAE,gCAAgC;KACxC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { AgoraDoctorCheck } from '@adonis-agora/crypto';
|
|
2
|
+
import type { KmsAdapterLike } from '@adonis-agora/crypto-client';
|
|
3
|
+
import { type KmsCheckOptions, type KmsIntegrationOptions } from './kms.js';
|
|
4
|
+
/** authkit-server's root key: its keystore (JWKS private keys) and account secrets. */
|
|
5
|
+
export declare const AUTHKIT_ROOT_KEY: "authkit-root";
|
|
6
|
+
/** The package the check reports under. */
|
|
7
|
+
export declare const AUTHKIT_PACKAGE = "@adonis-agora/authkit-server";
|
|
8
|
+
/**
|
|
9
|
+
* The KMS root for authkit-server:
|
|
10
|
+
*
|
|
11
|
+
* ```ts title="config/authkit.ts"
|
|
12
|
+
* crypto: { kms: authkitKms({ source: { client: crypto } }) }
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* Every private key authkit keeps (JWKS signing keys, TOTP secrets) is then sealed with a data key
|
|
16
|
+
* wrapped by `authkit-root`, so rotating that key rotates the fleet.
|
|
17
|
+
*/
|
|
18
|
+
export declare function authkitKms(options: Omit<KmsIntegrationOptions, 'key'> & {
|
|
19
|
+
key?: string;
|
|
20
|
+
}): KmsAdapterLike;
|
|
21
|
+
/** `agora:doctor --lib authkit`: `authkit-root` exists and this process can use it. */
|
|
22
|
+
export declare function authkitKmsCheck(options: Omit<KmsCheckOptions, 'lib' | 'packageName' | 'key'> & {
|
|
23
|
+
key?: string;
|
|
24
|
+
}): AgoraDoctorCheck;
|
|
25
|
+
//# sourceMappingURL=authkit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authkit.d.ts","sourceRoot":"","sources":["../../src/authkit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAElE,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,qBAAqB,EAA0B,MAAM,UAAU,CAAC;AAEpG,uFAAuF;AACvF,eAAO,MAAM,gBAAgB,gBAAoB,CAAC;AAClD,2CAA2C;AAC3C,eAAO,MAAM,eAAe,iCAAiC,CAAC;AAE9D;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CACxB,OAAO,EAAE,IAAI,CAAC,qBAAqB,EAAE,KAAK,CAAC,GAAG;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAC7D,cAAc,CAKhB;AAED,uFAAuF;AACvF,wBAAgB,eAAe,CAC7B,OAAO,EAAE,IAAI,CAAC,eAAe,EAAE,KAAK,GAAG,aAAa,GAAG,KAAK,CAAC,GAAG;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAC/E,gBAAgB,CAQlB"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ROOT_KEYS } from './keys.js';
|
|
2
|
+
import { kmsDoctorCheck, kmsFor } from './kms.js';
|
|
3
|
+
/** authkit-server's root key: its keystore (JWKS private keys) and account secrets. */
|
|
4
|
+
export const AUTHKIT_ROOT_KEY = ROOT_KEYS.authkit;
|
|
5
|
+
/** The package the check reports under. */
|
|
6
|
+
export const AUTHKIT_PACKAGE = '@adonis-agora/authkit-server';
|
|
7
|
+
/**
|
|
8
|
+
* The KMS root for authkit-server:
|
|
9
|
+
*
|
|
10
|
+
* ```ts title="config/authkit.ts"
|
|
11
|
+
* crypto: { kms: authkitKms({ source: { client: crypto } }) }
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* Every private key authkit keeps (JWKS signing keys, TOTP secrets) is then sealed with a data key
|
|
15
|
+
* wrapped by `authkit-root`, so rotating that key rotates the fleet.
|
|
16
|
+
*/
|
|
17
|
+
export function authkitKms(options) {
|
|
18
|
+
return kmsFor(options.key ?? AUTHKIT_ROOT_KEY, {
|
|
19
|
+
...options,
|
|
20
|
+
key: options.key ?? AUTHKIT_ROOT_KEY,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/** `agora:doctor --lib authkit`: `authkit-root` exists and this process can use it. */
|
|
24
|
+
export function authkitKmsCheck(options) {
|
|
25
|
+
return kmsDoctorCheck({
|
|
26
|
+
...options,
|
|
27
|
+
lib: 'authkit',
|
|
28
|
+
packageName: AUTHKIT_PACKAGE,
|
|
29
|
+
key: options.key ?? AUTHKIT_ROOT_KEY,
|
|
30
|
+
title: 'KMS root for the keystore and account secrets',
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=authkit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authkit.js","sourceRoot":"","sources":["../../src/authkit.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAoD,cAAc,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEpG,uFAAuF;AACvF,MAAM,CAAC,MAAM,gBAAgB,GAAG,SAAS,CAAC,OAAO,CAAC;AAClD,2CAA2C;AAC3C,MAAM,CAAC,MAAM,eAAe,GAAG,8BAA8B,CAAC;AAE9D;;;;;;;;;GASG;AACH,MAAM,UAAU,UAAU,CACxB,OAA8D;IAE9D,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,IAAI,gBAAgB,EAAE;QAC7C,GAAG,OAAO;QACV,GAAG,EAAE,OAAO,CAAC,GAAG,IAAI,gBAAgB;KACrC,CAAC,CAAC;AACL,CAAC;AAED,uFAAuF;AACvF,MAAM,UAAU,eAAe,CAC7B,OAAgF;IAEhF,OAAO,cAAc,CAAC;QACpB,GAAG,OAAO;QACV,GAAG,EAAE,SAAS;QACd,WAAW,EAAE,eAAe;QAC5B,GAAG,EAAE,OAAO,CAAC,GAAG,IAAI,gBAAgB;QACpC,KAAK,EAAE,+CAA+C;KACvD,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { AgoraDoctorCheck } from '@adonis-agora/crypto';
|
|
2
|
+
import type { KmsAdapterLike } from '@adonis-agora/crypto-client';
|
|
3
|
+
import { type KmsCheckOptions, type KmsIntegrationOptions } from './kms.js';
|
|
4
|
+
/** config's root: every secret entry (`crypto:secrets`, `vault://` aside) is sealed under it. */
|
|
5
|
+
export declare const CONFIG_ROOT_KEY: "config-root";
|
|
6
|
+
/** The package the check reports under. */
|
|
7
|
+
export declare const CONFIG_PACKAGE = "@adonis-agora/config";
|
|
8
|
+
/**
|
|
9
|
+
* The KMS root for `@adonis-agora/config`:
|
|
10
|
+
*
|
|
11
|
+
* ```ts title="config/config.ts"
|
|
12
|
+
* crypto: { kms: configKms({ source: { client: crypto } }) }
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* The control plane keeps no secret key material: each secret carries a data key wrapped by
|
|
16
|
+
* `config-root` on the crypto server. Tenants read their scope as usual; the reveal command still
|
|
17
|
+
* opens it, now with a key the control plane does not own.
|
|
18
|
+
*/
|
|
19
|
+
export declare function configKms(options: Omit<KmsIntegrationOptions, 'key'> & {
|
|
20
|
+
key?: string;
|
|
21
|
+
}): KmsAdapterLike;
|
|
22
|
+
/** `agora:doctor --lib config`: `config-root` exists and this process can use it. */
|
|
23
|
+
export declare function configKmsCheck(options: Omit<KmsCheckOptions, 'lib' | 'packageName' | 'key'> & {
|
|
24
|
+
key?: string;
|
|
25
|
+
}): AgoraDoctorCheck;
|
|
26
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAElE,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,qBAAqB,EAA0B,MAAM,UAAU,CAAC;AAEpG,iGAAiG;AACjG,eAAO,MAAM,eAAe,eAAmB,CAAC;AAChD,2CAA2C;AAC3C,eAAO,MAAM,cAAc,yBAAyB,CAAC;AAErD;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CACvB,OAAO,EAAE,IAAI,CAAC,qBAAqB,EAAE,KAAK,CAAC,GAAG;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAC7D,cAAc,CAGhB;AAED,qFAAqF;AACrF,wBAAgB,cAAc,CAC5B,OAAO,EAAE,IAAI,CAAC,eAAe,EAAE,KAAK,GAAG,aAAa,GAAG,KAAK,CAAC,GAAG;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAC/E,gBAAgB,CAQlB"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ROOT_KEYS } from './keys.js';
|
|
2
|
+
import { kmsDoctorCheck, kmsFor } from './kms.js';
|
|
3
|
+
/** config's root: every secret entry (`crypto:secrets`, `vault://` aside) is sealed under it. */
|
|
4
|
+
export const CONFIG_ROOT_KEY = ROOT_KEYS.config;
|
|
5
|
+
/** The package the check reports under. */
|
|
6
|
+
export const CONFIG_PACKAGE = '@adonis-agora/config';
|
|
7
|
+
/**
|
|
8
|
+
* The KMS root for `@adonis-agora/config`:
|
|
9
|
+
*
|
|
10
|
+
* ```ts title="config/config.ts"
|
|
11
|
+
* crypto: { kms: configKms({ source: { client: crypto } }) }
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* The control plane keeps no secret key material: each secret carries a data key wrapped by
|
|
15
|
+
* `config-root` on the crypto server. Tenants read their scope as usual; the reveal command still
|
|
16
|
+
* opens it, now with a key the control plane does not own.
|
|
17
|
+
*/
|
|
18
|
+
export function configKms(options) {
|
|
19
|
+
const key = options.key ?? CONFIG_ROOT_KEY;
|
|
20
|
+
return kmsFor(key, { ...options, key });
|
|
21
|
+
}
|
|
22
|
+
/** `agora:doctor --lib config`: `config-root` exists and this process can use it. */
|
|
23
|
+
export function configKmsCheck(options) {
|
|
24
|
+
return kmsDoctorCheck({
|
|
25
|
+
...options,
|
|
26
|
+
lib: 'config',
|
|
27
|
+
packageName: CONFIG_PACKAGE,
|
|
28
|
+
key: options.key ?? CONFIG_ROOT_KEY,
|
|
29
|
+
title: 'KMS root for the secrets',
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAoD,cAAc,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEpG,iGAAiG;AACjG,MAAM,CAAC,MAAM,eAAe,GAAG,SAAS,CAAC,MAAM,CAAC;AAChD,2CAA2C;AAC3C,MAAM,CAAC,MAAM,cAAc,GAAG,sBAAsB,CAAC;AAErD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,SAAS,CACvB,OAA8D;IAE9D,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,eAAe,CAAC;IAC3C,OAAO,MAAM,CAAC,GAAG,EAAE,EAAE,GAAG,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC;AAC1C,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,cAAc,CAC5B,OAAgF;IAEhF,OAAO,cAAc,CAAC;QACpB,GAAG,OAAO;QACV,GAAG,EAAE,QAAQ;QACb,WAAW,EAAE,cAAc;QAC3B,GAAG,EAAE,OAAO,CAAC,GAAG,IAAI,eAAe;QACnC,KAAK,EAAE,0BAA0B;KAClC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { CipherSource } from './source.js';
|
|
2
|
+
/**
|
|
3
|
+
* The parts of durable's `Transport`/`ControlPlane` these decorators understand, declared
|
|
4
|
+
* structurally: `@adonis-agora/durable` stays an optional peer and nothing is imported at runtime.
|
|
5
|
+
*/
|
|
6
|
+
export interface TransportLike {
|
|
7
|
+
dispatch(task: {
|
|
8
|
+
input?: unknown;
|
|
9
|
+
} & Record<string, unknown>): Promise<void>;
|
|
10
|
+
onResult(handler: (result: {
|
|
11
|
+
output?: unknown;
|
|
12
|
+
error?: unknown;
|
|
13
|
+
} & Record<string, unknown>) => Promise<void>): void;
|
|
14
|
+
onHeartbeat?(handler: (beat: {
|
|
15
|
+
progress?: unknown;
|
|
16
|
+
} & Record<string, unknown>) => Promise<void>): void;
|
|
17
|
+
}
|
|
18
|
+
export interface ControlPlaneLike {
|
|
19
|
+
publishControl(message: {
|
|
20
|
+
kind: string;
|
|
21
|
+
event?: unknown;
|
|
22
|
+
} & Record<string, unknown>): Promise<void>;
|
|
23
|
+
onControl(handler: (message: {
|
|
24
|
+
kind: string;
|
|
25
|
+
event?: unknown;
|
|
26
|
+
} & Record<string, unknown>) => void): void;
|
|
27
|
+
}
|
|
28
|
+
export interface DurableEncryptionOptions {
|
|
29
|
+
source: CipherSource;
|
|
30
|
+
/** The key that seals the payloads (e.g. `durable-tasks`). */
|
|
31
|
+
key: string;
|
|
32
|
+
/** Extra context bound into the AAD, e.g. `tasks` for the transport and `control` for the plane. */
|
|
33
|
+
aad?: string;
|
|
34
|
+
/** Refuse a plain payload instead of passing it through. Default `false` (rollout friendly). */
|
|
35
|
+
strict?: boolean;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Encrypts a durable **transport**'s payloads and leaves routing metadata in clear:
|
|
39
|
+
*
|
|
40
|
+
* - `dispatch`: `task.input` is sealed; `runId`, `seq`, `stepId`, `name`, `group`, `priority`,
|
|
41
|
+
* `attempt`, `traceparent` and the dedupe keys stay readable, so queues route and dedupe exactly
|
|
42
|
+
* as before;
|
|
43
|
+
* - `onResult`: `result.output` (and a step error) is opened; status and ids stay clear;
|
|
44
|
+
* - `onHeartbeat`: `beat.progress` is sealed/opened; liveness ids stay clear.
|
|
45
|
+
*
|
|
46
|
+
* ```ts title="config/durable.ts"
|
|
47
|
+
* transport: encryptedTransport(transports.redis({ connection: 'main' }), {
|
|
48
|
+
* source: { client: crypto },
|
|
49
|
+
* key: 'durable-tasks',
|
|
50
|
+
* })
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* The decorator wraps an already-built instance (durable accepts one), so the app keeps whatever
|
|
54
|
+
* transport it had and the crypto server owns the payload key.
|
|
55
|
+
*/
|
|
56
|
+
export declare function encryptedTransport<T extends TransportLike>(inner: T, options: DurableEncryptionOptions): T;
|
|
57
|
+
/**
|
|
58
|
+
* Encrypts a durable **control plane**'s event payloads: a `{ kind: 'event', event }` message
|
|
59
|
+
* carries a sealed `event`; `cancel`, `enqueued` and `schedulePause` messages are routing only and
|
|
60
|
+
* travel in clear, as do `kind`, `runId`, `from` and the schedule key.
|
|
61
|
+
*
|
|
62
|
+
* ```ts title="config/durable.ts"
|
|
63
|
+
* controlPlane: encryptedControlPlane(new RedisControlPlane({ connection: 'main' }), {
|
|
64
|
+
* source: { client: crypto },
|
|
65
|
+
* key: 'durable-tasks',
|
|
66
|
+
* })
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* **Interop:** an encrypted channel is not readable by a plain consumer. A NestJS fleet (or any
|
|
70
|
+
* service without this decorator) on the same Redis channel sees sealed events it cannot open, so
|
|
71
|
+
* both sides must be upgraded together, or the encrypted plane must run on its own channel.
|
|
72
|
+
*/
|
|
73
|
+
export declare function encryptedControlPlane<T extends ControlPlaneLike>(inner: T, options: DurableEncryptionOptions): T;
|
|
74
|
+
//# sourceMappingURL=durable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"durable.d.ts","sourceRoot":"","sources":["../../src/durable.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7E,QAAQ,CACN,OAAO,EAAE,CACP,MAAM,EAAE;QAAE,MAAM,CAAC,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KACpE,OAAO,CAAC,IAAI,CAAC,GACjB,IAAI,CAAC;IACR,WAAW,CAAC,CACV,OAAO,EAAE,CAAC,IAAI,EAAE;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,GACjF,IAAI,CAAC;CACT;AAED,MAAM,WAAW,gBAAgB;IAC/B,cAAc,CACZ,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACnE,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,SAAS,CACP,OAAO,EAAE,CAAC,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,GACtF,IAAI,CAAC;CACT;AAED,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,YAAY,CAAC;IACrB,8DAA8D;IAC9D,GAAG,EAAE,MAAM,CAAC;IACZ,oGAAoG;IACpG,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,gGAAgG;IAChG,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,aAAa,EACxD,KAAK,EAAE,CAAC,EACR,OAAO,EAAE,wBAAwB,GAChC,CAAC,CAkDH;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,gBAAgB,EAC9D,KAAK,EAAE,CAAC,EACR,OAAO,EAAE,wBAAwB,GAChC,CAAC,CAmDH"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { sealedPayloads } from './payloads.js';
|
|
2
|
+
/**
|
|
3
|
+
* Encrypts a durable **transport**'s payloads and leaves routing metadata in clear:
|
|
4
|
+
*
|
|
5
|
+
* - `dispatch`: `task.input` is sealed; `runId`, `seq`, `stepId`, `name`, `group`, `priority`,
|
|
6
|
+
* `attempt`, `traceparent` and the dedupe keys stay readable, so queues route and dedupe exactly
|
|
7
|
+
* as before;
|
|
8
|
+
* - `onResult`: `result.output` (and a step error) is opened; status and ids stay clear;
|
|
9
|
+
* - `onHeartbeat`: `beat.progress` is sealed/opened; liveness ids stay clear.
|
|
10
|
+
*
|
|
11
|
+
* ```ts title="config/durable.ts"
|
|
12
|
+
* transport: encryptedTransport(transports.redis({ connection: 'main' }), {
|
|
13
|
+
* source: { client: crypto },
|
|
14
|
+
* key: 'durable-tasks',
|
|
15
|
+
* })
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* The decorator wraps an already-built instance (durable accepts one), so the app keeps whatever
|
|
19
|
+
* transport it had and the crypto server owns the payload key.
|
|
20
|
+
*/
|
|
21
|
+
export function encryptedTransport(inner, options) {
|
|
22
|
+
const payloads = sealedPayloads({
|
|
23
|
+
source: options.source,
|
|
24
|
+
key: options.key,
|
|
25
|
+
aad: options.aad ?? 'durable:transport',
|
|
26
|
+
...(options.strict !== undefined ? { strict: options.strict } : {}),
|
|
27
|
+
actor: 'durable:transport',
|
|
28
|
+
});
|
|
29
|
+
return new Proxy(inner, {
|
|
30
|
+
get(target, property) {
|
|
31
|
+
if (property === 'dispatch') {
|
|
32
|
+
return async (task) => {
|
|
33
|
+
const sealed = { ...task, input: await payloads.seal(task.input) };
|
|
34
|
+
return target.dispatch(sealed);
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
if (property === 'onResult') {
|
|
38
|
+
return (handler) => target.onResult(async (result) => {
|
|
39
|
+
handler({
|
|
40
|
+
...result,
|
|
41
|
+
...(result.output !== undefined
|
|
42
|
+
? { output: await payloads.open(result.output) }
|
|
43
|
+
: {}),
|
|
44
|
+
...(result.error !== undefined ? { error: await payloads.open(result.error) } : {}),
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
if (property === 'onHeartbeat' && typeof target.onHeartbeat === 'function') {
|
|
49
|
+
return (handler) => target.onHeartbeat(async (beat) => {
|
|
50
|
+
handler({
|
|
51
|
+
...beat,
|
|
52
|
+
...(beat.progress !== undefined
|
|
53
|
+
? { progress: await payloads.open(beat.progress) }
|
|
54
|
+
: {}),
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
const value = Reflect.get(target, property, target);
|
|
59
|
+
return typeof value === 'function' ? value.bind(target) : value;
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Encrypts a durable **control plane**'s event payloads: a `{ kind: 'event', event }` message
|
|
65
|
+
* carries a sealed `event`; `cancel`, `enqueued` and `schedulePause` messages are routing only and
|
|
66
|
+
* travel in clear, as do `kind`, `runId`, `from` and the schedule key.
|
|
67
|
+
*
|
|
68
|
+
* ```ts title="config/durable.ts"
|
|
69
|
+
* controlPlane: encryptedControlPlane(new RedisControlPlane({ connection: 'main' }), {
|
|
70
|
+
* source: { client: crypto },
|
|
71
|
+
* key: 'durable-tasks',
|
|
72
|
+
* })
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* **Interop:** an encrypted channel is not readable by a plain consumer. A NestJS fleet (or any
|
|
76
|
+
* service without this decorator) on the same Redis channel sees sealed events it cannot open, so
|
|
77
|
+
* both sides must be upgraded together, or the encrypted plane must run on its own channel.
|
|
78
|
+
*/
|
|
79
|
+
export function encryptedControlPlane(inner, options) {
|
|
80
|
+
const payloads = sealedPayloads({
|
|
81
|
+
source: options.source,
|
|
82
|
+
key: options.key,
|
|
83
|
+
aad: options.aad ?? 'durable:control',
|
|
84
|
+
...(options.strict !== undefined ? { strict: options.strict } : {}),
|
|
85
|
+
actor: 'durable:control',
|
|
86
|
+
});
|
|
87
|
+
return new Proxy(inner, {
|
|
88
|
+
get(target, property) {
|
|
89
|
+
if (property === 'publishControl') {
|
|
90
|
+
return async (message) => {
|
|
91
|
+
const outgoing = message.kind === 'event' && message.event !== undefined
|
|
92
|
+
? { ...message, event: await payloads.seal(message.event) }
|
|
93
|
+
: message;
|
|
94
|
+
return target.publishControl(outgoing);
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
if (property === 'onControl') {
|
|
98
|
+
return (handler) => {
|
|
99
|
+
// `onControl` is synchronous and decryption is not: a serialized chain keeps the order the
|
|
100
|
+
// broker delivered (a `completed` can never overtake the `started` before it).
|
|
101
|
+
let chain = Promise.resolve();
|
|
102
|
+
target.onControl((message) => {
|
|
103
|
+
// Every message goes through the chain, encrypted or not: an `enqueued` that arrives
|
|
104
|
+
// after a `completed` must not overtake it just because it needed no decryption.
|
|
105
|
+
chain = chain.then(async () => {
|
|
106
|
+
if (message.kind !== 'event' || message.event === undefined) {
|
|
107
|
+
handler(message);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
handler({ ...message, event: await payloads.open(message.event) });
|
|
111
|
+
});
|
|
112
|
+
chain = chain.catch((error) => {
|
|
113
|
+
// Dropping an event silently would leave a run unobserved; fail loudly instead.
|
|
114
|
+
console.error('[@adonis-agora/crypto-integrations] a control event did not open', error);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
const value = Reflect.get(target, property, target);
|
|
120
|
+
return typeof value === 'function' ? value.bind(target) : value;
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=durable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"durable.js","sourceRoot":"","sources":["../../src/durable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAsC/C;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,kBAAkB,CAChC,KAAQ,EACR,OAAiC;IAEjC,MAAM,QAAQ,GAAG,cAAc,CAAC;QAC9B,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,GAAG,EAAE,OAAO,CAAC,GAAG,IAAI,mBAAmB;QACvC,GAAG,CAAC,OAAO,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACnE,KAAK,EAAE,mBAAmB;KAC3B,CAAC,CAAC;IAEH,OAAO,IAAI,KAAK,CAAC,KAAK,EAAE;QACtB,GAAG,CAAC,MAAM,EAAE,QAAQ;YAClB,IAAI,QAAQ,KAAK,UAAU,EAAE,CAAC;gBAC5B,OAAO,KAAK,EAAE,IAAmD,EAAE,EAAE;oBACnE,MAAM,MAAM,GAAG,EAAE,GAAG,IAAI,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AAE;oBACF,2FAA2F;oBAC3F,+EAA+E;oBAC/E,IAAI,KAAK,GAAkB,OAAO,CAAC,OAAO,EAAE,CAAC;oBAC7C,MAAM,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,EAAE;wBAC3B,qFAAqF;wBACrF,iFAAiF;wBACjF,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE;4BAC5B,IAAI,OAAO,CAAC,IAAI,KAAK,OAAO,IAAI,OAAO,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;gCAC5D,OAAO,CAAC,OAAO,CAAC,CAAC;gCACjB,OAAO;4BACT,CAAC;4BACD,OAAO,CAAC,EAAE,GAAG,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;wBACrE,CAAC,CAAC,CAAC;wBACH,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;4BACrC,gFAAgF;4BAChF,OAAO,CAAC,KAAK,CACX,kEAAkE,EAClE,KAAK,CACN,CAAC;wBACJ,CAAC,CAAC,CAAC;oBACL,CAAC,CAAC,CAAC;gBACL,CAAC,CAAC;YACJ,CAAC;YACD,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;YACpD,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;QAClE,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type CipherSource } from './source.js';
|
|
2
|
+
/** The key a flags app uses for its event hop by default. */
|
|
3
|
+
export declare const FLAGS_EVENTS_KEY = "flags-events";
|
|
4
|
+
export interface FlagsEnvelopeOptions {
|
|
5
|
+
source: CipherSource;
|
|
6
|
+
/** Default `flags-events`. */
|
|
7
|
+
key?: string;
|
|
8
|
+
/** Extra context bound into the AAD (e.g. the partition). */
|
|
9
|
+
aad?: string;
|
|
10
|
+
/** How old an envelope may be, in seconds. Default `300`. */
|
|
11
|
+
maxAgeSec?: number;
|
|
12
|
+
/** The underlying fetch (tests, or a tracing/metered wrapper). Default `globalThis.fetch`. */
|
|
13
|
+
fetch?: typeof fetch;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The envelope `fetch` for flags:
|
|
17
|
+
*
|
|
18
|
+
* ```ts title="config/flags.ts"
|
|
19
|
+
* const envelope = flagsEnvelope({ source: { client: crypto }, aad: 'flags' })
|
|
20
|
+
*
|
|
21
|
+
* transport: transports.http({
|
|
22
|
+
* url: env.get('FLAGS_URL'),
|
|
23
|
+
* token,
|
|
24
|
+
* partition: 'streaming',
|
|
25
|
+
* ...envelope, // { fetch }
|
|
26
|
+
* })
|
|
27
|
+
*
|
|
28
|
+
* sinks: [
|
|
29
|
+
* sinks.posthog({ apiKey, ...envelope }),
|
|
30
|
+
* sinks.clickhouse({ url, ...envelope }),
|
|
31
|
+
* ]
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* `transports.http` and the posthog/clickhouse sinks take a `fetch`; every batch they send is
|
|
35
|
+
* sealed to the flags server, which opens it with the same key. The tenant ruleset fetch
|
|
36
|
+
* (`remote_source.ts`) does not expose a `fetch` yet — see the integrations docs for that seam.
|
|
37
|
+
*/
|
|
38
|
+
export declare function flagsEnvelope(options: FlagsEnvelopeOptions): {
|
|
39
|
+
fetch: typeof fetch;
|
|
40
|
+
};
|
|
41
|
+
/** Just the `fetch`, for `transports.http({ ..., fetch })`. */
|
|
42
|
+
export declare function flagsEnvelopeFetch(options: FlagsEnvelopeOptions): typeof fetch;
|
|
43
|
+
//# sourceMappingURL=flags.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flags.d.ts","sourceRoot":"","sources":["../../src/flags.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,YAAY,EAAa,MAAM,aAAa,CAAC;AAE3D,6DAA6D;AAC7D,eAAO,MAAM,gBAAgB,iBAAiB,CAAC;AAE/C,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,YAAY,CAAC;IACrB,8BAA8B;IAC9B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,6DAA6D;IAC7D,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,6DAA6D;IAC7D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,8FAA8F;IAC9F,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;CACtB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG;IAAE,KAAK,EAAE,OAAO,KAAK,CAAA;CAAE,CAWpF;AAED,+DAA+D;AAC/D,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,KAAK,CAE9E"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { cryptoFetch } from '@adonis-agora/crypto-client';
|
|
2
|
+
import { cipherFor } from './source.js';
|
|
3
|
+
/** The key a flags app uses for its event hop by default. */
|
|
4
|
+
export const FLAGS_EVENTS_KEY = 'flags-events';
|
|
5
|
+
/**
|
|
6
|
+
* The envelope `fetch` for flags:
|
|
7
|
+
*
|
|
8
|
+
* ```ts title="config/flags.ts"
|
|
9
|
+
* const envelope = flagsEnvelope({ source: { client: crypto }, aad: 'flags' })
|
|
10
|
+
*
|
|
11
|
+
* transport: transports.http({
|
|
12
|
+
* url: env.get('FLAGS_URL'),
|
|
13
|
+
* token,
|
|
14
|
+
* partition: 'streaming',
|
|
15
|
+
* ...envelope, // { fetch }
|
|
16
|
+
* })
|
|
17
|
+
*
|
|
18
|
+
* sinks: [
|
|
19
|
+
* sinks.posthog({ apiKey, ...envelope }),
|
|
20
|
+
* sinks.clickhouse({ url, ...envelope }),
|
|
21
|
+
* ]
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* `transports.http` and the posthog/clickhouse sinks take a `fetch`; every batch they send is
|
|
25
|
+
* sealed to the flags server, which opens it with the same key. The tenant ruleset fetch
|
|
26
|
+
* (`remote_source.ts`) does not expose a `fetch` yet — see the integrations docs for that seam.
|
|
27
|
+
*/
|
|
28
|
+
export function flagsEnvelope(options) {
|
|
29
|
+
const key = options.key ?? FLAGS_EVENTS_KEY;
|
|
30
|
+
return {
|
|
31
|
+
fetch: cryptoFetch({
|
|
32
|
+
client: cipherFor(options.source, 'flags:events'),
|
|
33
|
+
key,
|
|
34
|
+
...(options.aad !== undefined ? { aad: options.aad } : {}),
|
|
35
|
+
...(options.maxAgeSec !== undefined ? { maxAgeSec: options.maxAgeSec } : {}),
|
|
36
|
+
...(options.fetch !== undefined ? { fetch: options.fetch } : {}),
|
|
37
|
+
}),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/** Just the `fetch`, for `transports.http({ ..., fetch })`. */
|
|
41
|
+
export function flagsEnvelopeFetch(options) {
|
|
42
|
+
return flagsEnvelope(options).fetch;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=flags.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flags.js","sourceRoot":"","sources":["../../src/flags.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAqB,SAAS,EAAE,MAAM,aAAa,CAAC;AAE3D,6DAA6D;AAC7D,MAAM,CAAC,MAAM,gBAAgB,GAAG,cAAc,CAAC;AAc/C;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,aAAa,CAAC,OAA6B;IACzD,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,gBAAgB,CAAC;IAC5C,OAAO;QACL,KAAK,EAAE,WAAW,CAAC;YACjB,MAAM,EAAE,SAAS,CAAC,OAAO,CAAC,MAAM,EAAE,cAAc,CAAC;YACjD,GAAG;YACH,GAAG,CAAC,OAAO,CAAC,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAC1D,GAAG,CAAC,OAAO,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAC5E,GAAG,CAAC,OAAO,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACjE,CAAC;KACH,CAAC;AACJ,CAAC;AAED,+DAA+D;AAC/D,MAAM,UAAU,kBAAkB,CAAC,OAA6B;IAC9D,OAAO,aAAa,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The generic HTTP seam: an envelope `fetch` for any service-to-service call, the receiver
|
|
3
|
+
* middleware, and the encrypted reply.
|
|
4
|
+
*
|
|
5
|
+
* - `authkitTenantToken({ issuer, clientId, clientSecret, resource, ...envelope })` — the token
|
|
6
|
+
* request to authkit is encrypted too;
|
|
7
|
+
* - `createConfigClient({ url, partition, token, ...envelope })` — the tenant's config fetch;
|
|
8
|
+
* - `createFlagsClient({ url, fetch: envelope.fetch })` (or `flagsEnvelope` from `/flags`).
|
|
9
|
+
*/
|
|
10
|
+
export { type CryptoEnvelopeMiddlewareOptions, type CryptoEnvelopeReplyOptions, type CryptoEnvelopeState, cryptoEnvelopeMiddleware, cryptoEnvelopeReply, serviceCipher, } from '@adonis-agora/crypto';
|
|
11
|
+
export { CryptoEnvelopeError, type CryptoEnvelopeErrorCode, type CryptoEnvelopeOptions, cryptoEnvelope, cryptoFetch, ENVELOPE_FIELD, ENVELOPE_HEADER, ENVELOPE_VERSION, type EnvelopeCipher, } from '@adonis-agora/crypto-client';
|
|
12
|
+
export { type CipherSource, cipherFor } from './source.js';
|
|
13
|
+
import { type CipherSource } from './source.js';
|
|
14
|
+
export interface HttpEnvelopeOptions {
|
|
15
|
+
source: CipherSource;
|
|
16
|
+
/** The key both sides use for this hop (e.g. `svc-flags`). */
|
|
17
|
+
key: string;
|
|
18
|
+
/** Extra context bound into the AAD. */
|
|
19
|
+
aad?: string;
|
|
20
|
+
/** How old an envelope may be, in seconds. Default `300`. */
|
|
21
|
+
maxAgeSec?: number;
|
|
22
|
+
/** The underlying fetch (tests, or a tracing/metered wrapper). Default `globalThis.fetch`. */
|
|
23
|
+
fetch?: typeof fetch;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* `{ fetch }`, spreadable into any client that takes one:
|
|
27
|
+
*
|
|
28
|
+
* ```ts
|
|
29
|
+
* const envelope = httpEnvelope({ source: { client: crypto }, key: 'svc-config' })
|
|
30
|
+
* const token = authkitTenantToken({ issuer, clientId, clientSecret, resource, ...envelope })
|
|
31
|
+
* const config = createConfigClient({ url, partition: 'streaming', token, ...envelope })
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function httpEnvelope(options: HttpEnvelopeOptions): {
|
|
35
|
+
fetch: typeof fetch;
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/http.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EACL,KAAK,+BAA+B,EACpC,KAAK,0BAA0B,EAC/B,KAAK,mBAAmB,EACxB,wBAAwB,EACxB,mBAAmB,EACnB,aAAa,GACd,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,mBAAmB,EACnB,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,EAC1B,cAAc,EACd,WAAW,EACX,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,KAAK,cAAc,GACpB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,KAAK,YAAY,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAG3D,OAAO,EAAE,KAAK,YAAY,EAAa,MAAM,aAAa,CAAC;AAE3D,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,YAAY,CAAC;IACrB,8DAA8D;IAC9D,GAAG,EAAE,MAAM,CAAC;IACZ,wCAAwC;IACxC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,6DAA6D;IAC7D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,8FAA8F;IAC9F,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;CACtB;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG;IAAE,KAAK,EAAE,OAAO,KAAK,CAAA;CAAE,CAUlF"}
|
package/dist/src/http.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The generic HTTP seam: an envelope `fetch` for any service-to-service call, the receiver
|
|
3
|
+
* middleware, and the encrypted reply.
|
|
4
|
+
*
|
|
5
|
+
* - `authkitTenantToken({ issuer, clientId, clientSecret, resource, ...envelope })` — the token
|
|
6
|
+
* request to authkit is encrypted too;
|
|
7
|
+
* - `createConfigClient({ url, partition, token, ...envelope })` — the tenant's config fetch;
|
|
8
|
+
* - `createFlagsClient({ url, fetch: envelope.fetch })` (or `flagsEnvelope` from `/flags`).
|
|
9
|
+
*/
|
|
10
|
+
export { cryptoEnvelopeMiddleware, cryptoEnvelopeReply, serviceCipher, } from '@adonis-agora/crypto';
|
|
11
|
+
export { CryptoEnvelopeError, cryptoEnvelope, cryptoFetch, ENVELOPE_FIELD, ENVELOPE_HEADER, ENVELOPE_VERSION, } from '@adonis-agora/crypto-client';
|
|
12
|
+
export { cipherFor } from './source.js';
|
|
13
|
+
import { cryptoFetch } from '@adonis-agora/crypto-client';
|
|
14
|
+
import { cipherFor } from './source.js';
|
|
15
|
+
/**
|
|
16
|
+
* `{ fetch }`, spreadable into any client that takes one:
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* const envelope = httpEnvelope({ source: { client: crypto }, key: 'svc-config' })
|
|
20
|
+
* const token = authkitTenantToken({ issuer, clientId, clientSecret, resource, ...envelope })
|
|
21
|
+
* const config = createConfigClient({ url, partition: 'streaming', token, ...envelope })
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export function httpEnvelope(options) {
|
|
25
|
+
return {
|
|
26
|
+
fetch: cryptoFetch({
|
|
27
|
+
client: cipherFor(options.source, 'http:envelope'),
|
|
28
|
+
key: options.key,
|
|
29
|
+
...(options.aad !== undefined ? { aad: options.aad } : {}),
|
|
30
|
+
...(options.maxAgeSec !== undefined ? { maxAgeSec: options.maxAgeSec } : {}),
|
|
31
|
+
...(options.fetch !== undefined ? { fetch: options.fetch } : {}),
|
|
32
|
+
}),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=http.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/http.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAIL,wBAAwB,EACxB,mBAAmB,EACnB,aAAa,GACd,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,mBAAmB,EAGnB,cAAc,EACd,WAAW,EACX,cAAc,EACd,eAAe,EACf,gBAAgB,GAEjB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAqB,SAAS,EAAE,MAAM,aAAa,CAAC;AAE3D,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAqB,SAAS,EAAE,MAAM,aAAa,CAAC;AAc3D;;;;;;;;GAQG;AACH,MAAM,UAAU,YAAY,CAAC,OAA4B;IACvD,OAAO;QACL,KAAK,EAAE,WAAW,CAAC;YACjB,MAAM,EAAE,SAAS,CAAC,OAAO,CAAC,MAAM,EAAE,eAAe,CAAC;YAClD,GAAG,EAAE,OAAO,CAAC,GAAG;YAChB,GAAG,CAAC,OAAO,CAAC,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAC1D,GAAG,CAAC,OAAO,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAC5E,GAAG,CAAC,OAAO,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACjE,CAAC;KACH,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { type ControlPlaneLike, type DurableEncryptionOptions, encryptedControlPlane, encryptedTransport, type TransportLike, } from './durable.js';
|
|
2
|
+
export { ROOT_KEYS } from './keys.js';
|
|
3
|
+
export { type KmsCheckOptions, type KmsIntegrationOptions, kmsDoctorCheck, kmsFor, } from './kms.js';
|
|
4
|
+
export { SEALED_FIELD, type SealedPayloads, type SealedPayloadsOptions, type SealedValue, sealedPayloads, } from './payloads.js';
|
|
5
|
+
export { type Cipher, type CipherSource, cipherFor, describeSource } from './source.js';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,wBAAwB,EAC7B,qBAAqB,EACrB,kBAAkB,EAClB,KAAK,aAAa,GACnB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,qBAAqB,EAC1B,cAAc,EACd,MAAM,GACP,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,YAAY,EACZ,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC1B,KAAK,WAAW,EAChB,cAAc,GACf,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,YAAY,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { encryptedControlPlane, encryptedTransport, } from './durable.js';
|
|
2
|
+
export { ROOT_KEYS } from './keys.js';
|
|
3
|
+
export { kmsDoctorCheck, kmsFor, } from './kms.js';
|
|
4
|
+
export { SEALED_FIELD, sealedPayloads, } from './payloads.js';
|
|
5
|
+
export { cipherFor, describeSource } from './source.js';
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,qBAAqB,EACrB,kBAAkB,GAEnB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAGL,cAAc,EACd,MAAM,GACP,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,YAAY,EAIZ,cAAc,GACf,MAAM,eAAe,CAAC;AACvB,OAAO,EAAkC,SAAS,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** The key conventions this package uses, one per lib. Overridable, but these are the defaults. */
|
|
2
|
+
export declare const ROOT_KEYS: {
|
|
3
|
+
readonly authkit: 'authkit-root';
|
|
4
|
+
readonly agent: 'agent-poppy-root';
|
|
5
|
+
readonly config: 'config-root';
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=keys.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../../src/keys.ts"],"names":[],"mappings":"AAAA,mGAAmG;AACnG,eAAO,MAAM,SAAS;aACpB,OAAO,EAAE,cAAc;aACvB,KAAK,EAAE,kBAAkB;aACzB,MAAM,EAAE,aAAa;CACb,CAAC"}
|
package/dist/src/keys.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keys.js","sourceRoot":"","sources":["../../src/keys.ts"],"names":[],"mappings":"AAAA,mGAAmG;AACnG,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,OAAO,EAAE,cAAc;IACvB,KAAK,EAAE,kBAAkB;IACzB,MAAM,EAAE,aAAa;CACb,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { AgoraDoctorCheck } from '@adonis-agora/crypto';
|
|
2
|
+
import { type KmsAdapterLike } from '@adonis-agora/crypto-client';
|
|
3
|
+
import { type CipherSource } from './source.js';
|
|
4
|
+
/** Options every KMS integration shares: where the keys live, and which key is the root. */
|
|
5
|
+
export interface KmsIntegrationOptions {
|
|
6
|
+
source: CipherSource;
|
|
7
|
+
/** The root key's name. Each subpath defaults to its lib's convention (`authkit-root`, …). */
|
|
8
|
+
key?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Bind every wrapped data key to the keyring's `purpose` (the default). Keep it on: it is what
|
|
11
|
+
* stops a data key wrapped for `config:secrets` from being unwrapped for another lib.
|
|
12
|
+
*/
|
|
13
|
+
bindPurpose?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The crypto-kit `KmsAdapter` backed by the crypto server, under one key. Every value the lib seals
|
|
17
|
+
* then carries a data key wrapped by that key: rotating it (`node ace crypto:keys:rotate <key>`)
|
|
18
|
+
* rotates the whole fleet, and no key material lives in the app.
|
|
19
|
+
*/
|
|
20
|
+
export declare function kmsFor(key: string, options: KmsIntegrationOptions): KmsAdapterLike;
|
|
21
|
+
export interface KmsCheckOptions extends KmsIntegrationOptions {
|
|
22
|
+
/** The lib the check reports under (`authkit`, `agent`, `config`). */
|
|
23
|
+
lib: string;
|
|
24
|
+
/** The npm package the check names. */
|
|
25
|
+
packageName: string;
|
|
26
|
+
/** Check title. Default states the key. */
|
|
27
|
+
title?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The `agora:doctor` check for a KMS root: the key exists, it is an `aes256-gcm` key, and this
|
|
31
|
+
* process can actually encrypt and decrypt with it (the token's capabilities, the key material and
|
|
32
|
+
* the crypto server itself). It is `deep`: it makes a round trip and leaves two audit rows.
|
|
33
|
+
*/
|
|
34
|
+
export declare function kmsDoctorCheck(options: KmsCheckOptions): AgoraDoctorCheck;
|
|
35
|
+
//# sourceMappingURL=kms.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kms.d.ts","sourceRoot":"","sources":["../../src/kms.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAmB,KAAK,cAAc,EAAE,MAAM,6BAA6B,CAAC;AACnF,OAAO,EAAE,KAAK,YAAY,EAAa,MAAM,aAAa,CAAC;AAE3D,4FAA4F;AAC5F,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,YAAY,CAAC;IACrB,8FAA8F;IAC9F,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,qBAAqB,GAAG,cAAc,CAMlF;AAED,MAAM,WAAW,eAAgB,SAAQ,qBAAqB;IAC5D,sEAAsE;IACtE,GAAG,EAAE,MAAM,CAAC;IACZ,uCAAuC;IACvC,WAAW,EAAE,MAAM,CAAC;IACpB,2CAA2C;IAC3C,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,eAAe,GAAG,gBAAgB,CAiFzE"}
|
package/dist/src/kms.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { cryptoServerKms } from '@adonis-agora/crypto-client';
|
|
2
|
+
import { cipherFor } from './source.js';
|
|
3
|
+
/**
|
|
4
|
+
* The crypto-kit `KmsAdapter` backed by the crypto server, under one key. Every value the lib seals
|
|
5
|
+
* then carries a data key wrapped by that key: rotating it (`node ace crypto:keys:rotate <key>`)
|
|
6
|
+
* rotates the whole fleet, and no key material lives in the app.
|
|
7
|
+
*/
|
|
8
|
+
export function kmsFor(key, options) {
|
|
9
|
+
return cryptoServerKms({
|
|
10
|
+
client: cipherFor(options.source, `kms:${key}`),
|
|
11
|
+
key,
|
|
12
|
+
...(options.bindPurpose !== undefined ? { bindPurpose: options.bindPurpose } : {}),
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The `agora:doctor` check for a KMS root: the key exists, it is an `aes256-gcm` key, and this
|
|
17
|
+
* process can actually encrypt and decrypt with it (the token's capabilities, the key material and
|
|
18
|
+
* the crypto server itself). It is `deep`: it makes a round trip and leaves two audit rows.
|
|
19
|
+
*/
|
|
20
|
+
export function kmsDoctorCheck(options) {
|
|
21
|
+
const key = options.key ?? '';
|
|
22
|
+
return {
|
|
23
|
+
id: `${options.lib}.kms`,
|
|
24
|
+
lib: options.lib,
|
|
25
|
+
package: options.packageName,
|
|
26
|
+
title: options.title ?? `KMS root "${key}"`,
|
|
27
|
+
cost: 'deep',
|
|
28
|
+
run: async () => {
|
|
29
|
+
const cipher = cipherFor(options.source, 'doctor');
|
|
30
|
+
let view;
|
|
31
|
+
try {
|
|
32
|
+
view = await describeKey(options.source, key);
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
const status = error.status;
|
|
36
|
+
if (status === 404) {
|
|
37
|
+
return {
|
|
38
|
+
status: 'error',
|
|
39
|
+
message: `The crypto server has no key "${key}", so this app seals with a key that does not exist.`,
|
|
40
|
+
fix: `Create it: node ace crypto:keys:create ${key} --type aes256-gcm (and grant this app crypto:encrypt:${key} / crypto:decrypt:${key}).`,
|
|
41
|
+
docs: 'https://davidecarvalho.github.io/agora/docs/crypto/kms',
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
status: 'error',
|
|
46
|
+
message: `Could not read the key "${key}": ${error.message}`,
|
|
47
|
+
fix: 'Check the crypto server URL and the token (whoami answers what the token may do).',
|
|
48
|
+
docs: 'https://davidecarvalho.github.io/agora/docs/crypto/authentication',
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
if (view === null) {
|
|
52
|
+
return {
|
|
53
|
+
status: 'error',
|
|
54
|
+
message: `The crypto server has no key "${key}".`,
|
|
55
|
+
fix: `Create it: node ace crypto:keys:create ${key} --type aes256-gcm.`,
|
|
56
|
+
docs: 'https://davidecarvalho.github.io/agora/docs/crypto/kms',
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
if (view.type !== 'aes256-gcm') {
|
|
60
|
+
return {
|
|
61
|
+
status: 'error',
|
|
62
|
+
message: `The key "${key}" is ${view.type}; a KMS root must be aes256-gcm.`,
|
|
63
|
+
fix: `Create an aes256-gcm key under a new name and point this integration at it.`,
|
|
64
|
+
docs: 'https://davidecarvalho.github.io/agora/docs/crypto/keys',
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
const probe = `agora:doctor:${Date.now()}`;
|
|
68
|
+
try {
|
|
69
|
+
const { ciphertext } = await cipher.encrypt({ key, plaintext: probe });
|
|
70
|
+
const { plaintext } = await cipher.decrypt({ key, ciphertext });
|
|
71
|
+
if (plaintext !== probe) {
|
|
72
|
+
return {
|
|
73
|
+
status: 'error',
|
|
74
|
+
message: `The round trip through "${key}" came back different.`,
|
|
75
|
+
fix: 'Check the root keyring of the crypto server (APP_KEY / crypto.keys / its KMS).',
|
|
76
|
+
docs: 'https://davidecarvalho.github.io/agora/docs/crypto/keys',
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
const status = error.status;
|
|
82
|
+
if (status === 403) {
|
|
83
|
+
return {
|
|
84
|
+
status: 'error',
|
|
85
|
+
message: `The token cannot use "${key}" (403): the app's capabilities are missing.`,
|
|
86
|
+
fix: `Grant crypto:encrypt:${key} and crypto:decrypt:${key} to this app's client.`,
|
|
87
|
+
docs: 'https://davidecarvalho.github.io/agora/docs/crypto/authentication',
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
status: 'error',
|
|
92
|
+
message: `The round trip through "${key}" failed: ${error.message}`,
|
|
93
|
+
fix: 'Check that the crypto server is up and its root keyring is the one that sealed this key.',
|
|
94
|
+
docs: 'https://davidecarvalho.github.io/agora/docs/crypto/doctor',
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
status: 'ok',
|
|
99
|
+
message: `"${key}" exists (${view.type}, v${view.latestVersion ?? '?'}) and this process sealed and opened a value with it.`,
|
|
100
|
+
};
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/** Reads a key's metadata through whichever source is configured. */
|
|
105
|
+
async function describeKey(source, key) {
|
|
106
|
+
if ('client' in source) {
|
|
107
|
+
const view = await source.client.getKey(key);
|
|
108
|
+
return { type: view.type, latestVersion: view.latestVersion };
|
|
109
|
+
}
|
|
110
|
+
const view = await source.service.getKey({
|
|
111
|
+
partition: source.partition,
|
|
112
|
+
capabilities: ['crypto:keys:read'],
|
|
113
|
+
actor: source.actor ?? 'doctor',
|
|
114
|
+
}, key);
|
|
115
|
+
return { type: view.type, latestVersion: view.latestVersion };
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=kms.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{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KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,QAAQ;KAChC,EACD,GAAG,CACJ,CAAC;IACF,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,aAAa,EAAE,IAAI,CAAC,aAAa,EAAE,CAAC;AAChE,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type CipherSource } from './source.js';
|
|
2
|
+
/** The field that marks a sealed payload, so a mixed fleet can tell it from a plain value. */
|
|
3
|
+
export declare const SEALED_FIELD = "agoraSealed";
|
|
4
|
+
export interface SealedValue {
|
|
5
|
+
[SEALED_FIELD]: string;
|
|
6
|
+
}
|
|
7
|
+
export interface SealedPayloadsOptions {
|
|
8
|
+
source: CipherSource;
|
|
9
|
+
/** The key that seals the payloads (per hop, e.g. `durable-tasks`). */
|
|
10
|
+
key: string;
|
|
11
|
+
/** Extra context bound into the AAD (a direction, a queue family). */
|
|
12
|
+
aad?: string;
|
|
13
|
+
/** Refuse a plain value instead of passing it through. Default `false` (rollout friendly). */
|
|
14
|
+
strict?: boolean;
|
|
15
|
+
actor?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface SealedPayloads {
|
|
18
|
+
seal(value: unknown): Promise<SealedValue>;
|
|
19
|
+
open<T = unknown>(value: unknown): Promise<T>;
|
|
20
|
+
isSealed(value: unknown): value is SealedValue;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Payload sealing with **no freshness window**: a queued task may sit for hours, so `iat` would
|
|
24
|
+
* only produce false refusals. Confidentiality and integrity come from AES-GCM; replay protection
|
|
25
|
+
* stays where the queue already has it (ids, dedupe, queue semantics) — the ids stay in clear.
|
|
26
|
+
*/
|
|
27
|
+
export declare function sealedPayloads(options: SealedPayloadsOptions): SealedPayloads;
|
|
28
|
+
//# sourceMappingURL=payloads.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payloads.d.ts","sourceRoot":"","sources":["../../src/payloads.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAa,MAAM,aAAa,CAAC;AAE3D,8FAA8F;AAC9F,eAAO,MAAM,YAAY,gBAAgB,CAAC;AAE1C,MAAM,WAAW,WAAW;IAC1B,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,YAAY,CAAC;IACrB,uEAAuE;IACvE,GAAG,EAAE,MAAM,CAAC;IACZ,sEAAsE;IACtE,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,8FAA8F;IAC9F,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IAC3C,IAAI,CAAC,CAAC,GAAG,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAC9C,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAAC;CAChD;AAOD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,cAAc,CA8B7E"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { cipherFor } from './source.js';
|
|
2
|
+
/** The field that marks a sealed payload, so a mixed fleet can tell it from a plain value. */
|
|
3
|
+
export const SEALED_FIELD = 'agoraSealed';
|
|
4
|
+
const isSealed = (value) => typeof value === 'object' &&
|
|
5
|
+
value !== null &&
|
|
6
|
+
typeof value[SEALED_FIELD] === 'string';
|
|
7
|
+
/**
|
|
8
|
+
* Payload sealing with **no freshness window**: a queued task may sit for hours, so `iat` would
|
|
9
|
+
* only produce false refusals. Confidentiality and integrity come from AES-GCM; replay protection
|
|
10
|
+
* stays where the queue already has it (ids, dedupe, queue semantics) — the ids stay in clear.
|
|
11
|
+
*/
|
|
12
|
+
export function sealedPayloads(options) {
|
|
13
|
+
const cipher = cipherFor(options.source, options.actor ?? 'payloads');
|
|
14
|
+
const aad = `agora:payload:v1:${options.aad ?? ''}`;
|
|
15
|
+
return {
|
|
16
|
+
isSealed,
|
|
17
|
+
async seal(value) {
|
|
18
|
+
const { ciphertext } = await cipher.encrypt({
|
|
19
|
+
key: options.key,
|
|
20
|
+
plaintext: JSON.stringify(value ?? null),
|
|
21
|
+
aad,
|
|
22
|
+
});
|
|
23
|
+
return { [SEALED_FIELD]: ciphertext };
|
|
24
|
+
},
|
|
25
|
+
async open(value) {
|
|
26
|
+
if (!isSealed(value)) {
|
|
27
|
+
if (options.strict === true) {
|
|
28
|
+
throw new Error('crypto: expected a sealed payload; is the other side of this hop also encrypted?');
|
|
29
|
+
}
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
const { plaintext } = await cipher.decrypt({
|
|
33
|
+
key: options.key,
|
|
34
|
+
ciphertext: value[SEALED_FIELD],
|
|
35
|
+
aad,
|
|
36
|
+
});
|
|
37
|
+
return JSON.parse(plaintext);
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=payloads.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payloads.js","sourceRoot":"","sources":["../../src/payloads.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,SAAS,EAAE,MAAM,aAAa,CAAC;AAE3D,8FAA8F;AAC9F,MAAM,CAAC,MAAM,YAAY,GAAG,aAAa,CAAC;AAuB1C,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAwB,EAAE,CACxD,OAAO,KAAK,KAAK,QAAQ;IACzB,KAAK,KAAK,IAAI;IACd,OAAQ,KAAiC,CAAC,YAAY,CAAC,KAAK,QAAQ,CAAC;AAEvE;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,OAA8B;IAC3D,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,UAAU,CAAC,CAAC;IACtE,MAAM,GAAG,GAAG,oBAAoB,OAAO,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC;IACpD,OAAO;QACL,QAAQ;QACR,KAAK,CAAC,IAAI,CAAC,KAAK;YACd,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;gBAC1C,GAAG,EAAE,OAAO,CAAC,GAAG;gBAChB,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,IAAI,IAAI,CAAC;gBACxC,GAAG;aACJ,CAAC,CAAC;YACH,OAAO,EAAE,CAAC,YAAY,CAAC,EAAE,UAAU,EAAE,CAAC;QACxC,CAAC;QACD,KAAK,CAAC,IAAI,CAAc,KAAc;YACpC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;gBACrB,IAAI,OAAO,CAAC,MAAM,KAAK,IAAI,EAAE,CAAC;oBAC5B,MAAM,IAAI,KAAK,CACb,kFAAkF,CACnF,CAAC;gBACJ,CAAC;gBACD,OAAO,KAAU,CAAC;YACpB,CAAC;YACD,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;gBACzC,GAAG,EAAE,OAAO,CAAC,GAAG;gBAChB,UAAU,EAAE,KAAK,CAAC,YAAY,CAAC;gBAC/B,GAAG;aACJ,CAAC,CAAC;YACH,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAM,CAAC;QACpC,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { CryptoService } from '@adonis-agora/crypto';
|
|
2
|
+
import type { CryptoClient, EnvelopeCipher } from '@adonis-agora/crypto-client';
|
|
3
|
+
/**
|
|
4
|
+
* Where the keys live. Both work with every integration:
|
|
5
|
+
*
|
|
6
|
+
* - `{ client }` — a remote crypto server (`topology: 'tenant'`), or one reached over HTTP from an
|
|
7
|
+
* app that is not the server;
|
|
8
|
+
* - `{ service, partition }` — the crypto server embedded in this app (`standalone` /
|
|
9
|
+
* `control-plane`): the calls run in process, no HTTP hop, same audit.
|
|
10
|
+
*/
|
|
11
|
+
export type CipherSource = {
|
|
12
|
+
client: CryptoClient;
|
|
13
|
+
} | {
|
|
14
|
+
service: CryptoService;
|
|
15
|
+
partition: string;
|
|
16
|
+
actor?: string;
|
|
17
|
+
};
|
|
18
|
+
/** The two calls every integration needs (`encrypt` / `decrypt` on one key). */
|
|
19
|
+
export type Cipher = EnvelopeCipher;
|
|
20
|
+
/** Normalizes both sources into the cipher the integrations use. */
|
|
21
|
+
export declare function cipherFor(source: CipherSource, actor?: string): Cipher;
|
|
22
|
+
/** The library name a source belongs to, for error messages. */
|
|
23
|
+
export declare function describeSource(source: CipherSource): string;
|
|
24
|
+
//# sourceMappingURL=source.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../../src/source.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAEhF;;;;;;;GAOG;AACH,MAAM,MAAM,YAAY,GACpB;IAAE,MAAM,EAAE,YAAY,CAAA;CAAE,GACxB;IAAE,OAAO,EAAE,aAAa,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAElE,gFAAgF;AAChF,MAAM,MAAM,MAAM,GAAG,cAAc,CAAC;AAEpC,oEAAoE;AACpE,wBAAgB,SAAS,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK,SAAgB,GAAG,MAAM,CAG7E;AAED,gEAAgE;AAChE,wBAAgB,cAAc,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CAI3D"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { serviceCipher } from '@adonis-agora/crypto';
|
|
2
|
+
/** Normalizes both sources into the cipher the integrations use. */
|
|
3
|
+
export function cipherFor(source, actor = 'integration') {
|
|
4
|
+
if ('client' in source)
|
|
5
|
+
return source.client;
|
|
6
|
+
return serviceCipher(source.service, source.partition, source.actor ?? actor);
|
|
7
|
+
}
|
|
8
|
+
/** The library name a source belongs to, for error messages. */
|
|
9
|
+
export function describeSource(source) {
|
|
10
|
+
return 'client' in source
|
|
11
|
+
? 'remote crypto server'
|
|
12
|
+
: `embedded crypto server (${source.partition})`;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source.js","sourceRoot":"","sources":["../../src/source.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAkBrD,oEAAoE;AACpE,MAAM,UAAU,SAAS,CAAC,MAAoB,EAAE,KAAK,GAAG,aAAa;IACnE,IAAI,QAAQ,IAAI,MAAM;QAAE,OAAO,MAAM,CAAC,MAAM,CAAC;IAC7C,OAAO,aAAa,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,KAAK,IAAI,KAAK,CAAC,CAAC;AAChF,CAAC;AAED,gEAAgE;AAChE,MAAM,UAAU,cAAc,CAAC,MAAoB;IACjD,OAAO,QAAQ,IAAI,MAAM;QACvB,CAAC,CAAC,sBAAsB;QACxB,CAAC,CAAC,2BAA2B,MAAM,CAAC,SAAS,GAAG,CAAC;AACrD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,96 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonis-agora/crypto-integrations",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Seams between @adonis-agora/crypto and the other Agora libs — KMS roots for authkit, agent and config, encrypted durable transport/control-plane, envelope fetch for flags and any service-to-service call. Kept at 0.x so the rc libs stay untouched.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/DavideCarvalho/adonis-agora-crypto.git",
|
|
9
|
+
"directory": "packages/integrations"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://davidecarvalho.github.io/agora/docs/crypto/integrations",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/DavideCarvalho/adonis-agora-crypto/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"adonisjs",
|
|
17
|
+
"adonis",
|
|
18
|
+
"crypto",
|
|
19
|
+
"integrations",
|
|
20
|
+
"kms",
|
|
21
|
+
"agora"
|
|
22
|
+
],
|
|
23
|
+
"author": "Davi Carvalho <davi@goflip.ai>",
|
|
24
|
+
"type": "module",
|
|
25
|
+
"main": "./dist/src/index.js",
|
|
26
|
+
"types": "./dist/src/index.d.ts",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/src/index.d.ts",
|
|
30
|
+
"import": "./dist/src/index.js",
|
|
31
|
+
"default": "./dist/src/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./authkit": {
|
|
34
|
+
"types": "./dist/src/authkit.d.ts",
|
|
35
|
+
"import": "./dist/src/authkit.js",
|
|
36
|
+
"default": "./dist/src/authkit.js"
|
|
37
|
+
},
|
|
38
|
+
"./agent": {
|
|
39
|
+
"types": "./dist/src/agent.d.ts",
|
|
40
|
+
"import": "./dist/src/agent.js",
|
|
41
|
+
"default": "./dist/src/agent.js"
|
|
42
|
+
},
|
|
43
|
+
"./config": {
|
|
44
|
+
"types": "./dist/src/config.d.ts",
|
|
45
|
+
"import": "./dist/src/config.js",
|
|
46
|
+
"default": "./dist/src/config.js"
|
|
47
|
+
},
|
|
48
|
+
"./durable": {
|
|
49
|
+
"types": "./dist/src/durable.d.ts",
|
|
50
|
+
"import": "./dist/src/durable.js",
|
|
51
|
+
"default": "./dist/src/durable.js"
|
|
52
|
+
},
|
|
53
|
+
"./flags": {
|
|
54
|
+
"types": "./dist/src/flags.d.ts",
|
|
55
|
+
"import": "./dist/src/flags.js",
|
|
56
|
+
"default": "./dist/src/flags.js"
|
|
57
|
+
},
|
|
58
|
+
"./http": {
|
|
59
|
+
"types": "./dist/src/http.d.ts",
|
|
60
|
+
"import": "./dist/src/http.js",
|
|
61
|
+
"default": "./dist/src/http.js"
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"files": [
|
|
65
|
+
"dist/",
|
|
66
|
+
"README.md",
|
|
67
|
+
"CHANGELOG.md"
|
|
68
|
+
],
|
|
69
|
+
"dependencies": {
|
|
70
|
+
"@adonis-agora/crypto": "^0.3.0",
|
|
71
|
+
"@adonis-agora/crypto-client": "^0.2.0",
|
|
72
|
+
"@adonis-agora/crypto-core": "^0.1.0"
|
|
73
|
+
},
|
|
74
|
+
"peerDependencies": {
|
|
75
|
+
"@adonis-agora/durable": ">=1.0.0-rc.0 <2.0.0"
|
|
76
|
+
},
|
|
77
|
+
"peerDependenciesMeta": {
|
|
78
|
+
"@adonis-agora/durable": {
|
|
79
|
+
"optional": true
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
"devDependencies": {
|
|
83
|
+
"@types/node": "26.6.6",
|
|
84
|
+
"typescript": "7.0.2",
|
|
85
|
+
"vitest": "5.1.0"
|
|
86
|
+
},
|
|
87
|
+
"engines": {
|
|
88
|
+
"node": ">=24"
|
|
89
|
+
},
|
|
90
|
+
"scripts": {
|
|
91
|
+
"build": "tsc -p tsconfig.json",
|
|
92
|
+
"test": "vitest run --passWithNoTests",
|
|
93
|
+
"test:watch": "vitest",
|
|
94
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
95
|
+
}
|
|
6
96
|
}
|