@serfab/cadre-host 0.7.1 → 0.9.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/README.md +296 -101
- package/dist/auth/trust-circle.d.ts +45 -7
- package/dist/auth/trust-circle.js +116 -59
- package/dist/auth/trust-circle.js.map +1 -1
- package/dist/auth/types.d.ts +4 -1
- package/dist/auth/types.js.map +1 -1
- package/dist/bin/host.js +426 -112
- package/dist/bin/host.js.map +1 -1
- package/dist/donation/donation-service.d.ts +136 -0
- package/dist/donation/donation-service.js +306 -0
- package/dist/donation/donation-service.js.map +1 -0
- package/dist/donation/donation-store.d.ts +42 -0
- package/dist/donation/donation-store.js +141 -0
- package/dist/donation/donation-store.js.map +1 -0
- package/dist/donation/grant-service.d.ts +71 -0
- package/dist/donation/grant-service.js +163 -0
- package/dist/donation/grant-service.js.map +1 -0
- package/dist/donation/grant-store.d.ts +38 -0
- package/dist/donation/grant-store.js +135 -0
- package/dist/donation/grant-store.js.map +1 -0
- package/dist/donation/index.d.ts +18 -0
- package/dist/donation/index.js +16 -0
- package/dist/donation/index.js.map +1 -0
- package/dist/donation/types.d.ts +175 -0
- package/dist/donation/types.js +40 -0
- package/dist/donation/types.js.map +1 -0
- package/dist/index.d.ts +12 -6
- package/dist/index.js +8 -3
- package/dist/index.js.map +1 -1
- package/dist/installer/browser.js +16 -17
- package/dist/installer/browser.js.map +1 -1
- package/dist/installer/config.d.ts +51 -0
- package/dist/installer/config.js +14 -1
- package/dist/installer/config.js.map +1 -1
- package/dist/installer/index.d.ts +7 -2
- package/dist/installer/index.js +17 -10
- package/dist/installer/index.js.map +1 -1
- package/dist/installer/service-host/launchd.js +1 -1
- package/dist/installer/service-host/launchd.js.map +1 -1
- package/dist/installer/service-host/systemd.js +1 -1
- package/dist/installer/service-host/systemd.js.map +1 -1
- package/dist/installer/wizard.d.ts +4 -0
- package/dist/installer/wizard.js +5 -1
- package/dist/installer/wizard.js.map +1 -1
- package/dist/nat/index.d.ts +1 -1
- package/dist/nat/nat-service.d.ts +45 -3
- package/dist/nat/nat-service.js +116 -3
- package/dist/nat/nat-service.js.map +1 -1
- package/dist/nat/secrets/index.d.ts +7 -0
- package/dist/nat/secrets/index.js +28 -2
- package/dist/nat/secrets/index.js.map +1 -1
- package/dist/nat/types.d.ts +3 -1
- package/dist/nat/types.js.map +1 -1
- package/dist/orchestrator/host-process-orchestrator.d.ts +68 -1
- package/dist/orchestrator/host-process-orchestrator.js +272 -39
- package/dist/orchestrator/host-process-orchestrator.js.map +1 -1
- package/dist/orchestrator/index.d.ts +3 -2
- package/dist/orchestrator/index.js +1 -1
- package/dist/orchestrator/index.js.map +1 -1
- package/dist/orchestrator/state-store.d.ts +6 -5
- package/dist/orchestrator/state-store.js +10 -2
- package/dist/orchestrator/state-store.js.map +1 -1
- package/dist/orchestrator/types.d.ts +45 -10
- package/dist/orchestrator/types.js.map +1 -1
- package/dist/owner/index.d.ts +11 -0
- package/dist/owner/index.js +11 -0
- package/dist/owner/index.js.map +1 -0
- package/dist/owner/owner-node-client.d.ts +95 -0
- package/dist/owner/owner-node-client.js +167 -0
- package/dist/owner/owner-node-client.js.map +1 -0
- package/dist/push/index.d.ts +67 -0
- package/dist/push/index.js +101 -0
- package/dist/push/index.js.map +1 -0
- package/dist/server/error-handler.d.ts +17 -0
- package/dist/server/error-handler.js +45 -0
- package/dist/server/error-handler.js.map +1 -1
- package/dist/server/index.d.ts +26 -2
- package/dist/server/index.js +37 -16
- package/dist/server/index.js.map +1 -1
- package/dist/server/routes/grants-admin.d.ts +17 -0
- package/dist/server/routes/grants-admin.js +32 -0
- package/dist/server/routes/grants-admin.js.map +1 -0
- package/dist/server/routes/grants.d.ts +28 -0
- package/dist/server/routes/grants.js +163 -0
- package/dist/server/routes/grants.js.map +1 -0
- package/dist/server/routes/nodes.d.ts +5 -3
- package/dist/server/routes/nodes.js +39 -24
- package/dist/server/routes/nodes.js.map +1 -1
- package/dist/server/routes/settings.d.ts +6 -1
- package/dist/server/routes/settings.js +5 -2
- package/dist/server/routes/settings.js.map +1 -1
- package/dist/server/routes/status.d.ts +8 -4
- package/dist/server/routes/status.js +9 -4
- package/dist/server/routes/status.js.map +1 -1
- package/dist/server/static.d.ts +12 -0
- package/dist/server/static.js +24 -7
- package/dist/server/static.js.map +1 -1
- package/dist/ui/assets/index-BlMXQPSw.js +14 -0
- package/dist/ui/assets/{index-C9uChk2P.js.map → index-BlMXQPSw.js.map} +1 -1
- package/dist/ui/index.html +1 -1
- package/dist/update/apply.d.ts +23 -1
- package/dist/update/apply.js +46 -4
- package/dist/update/apply.js.map +1 -1
- package/dist/update/index.d.ts +14 -3
- package/dist/update/index.js +35 -2
- package/dist/update/index.js.map +1 -1
- package/dist/update/manifest.d.ts +28 -9
- package/dist/update/manifest.js +56 -29
- package/dist/update/manifest.js.map +1 -1
- package/dist/update/release-key.d.ts +18 -7
- package/dist/update/release-key.js +29 -14
- package/dist/update/release-key.js.map +1 -1
- package/dist/update/sign.d.ts +46 -0
- package/dist/update/sign.js +53 -0
- package/dist/update/sign.js.map +1 -0
- package/package.json +9 -4
- package/service/README.md +95 -86
- package/src/__tests__/cli-invite.smoke.test.ts +6 -1
- package/src/__tests__/cli-nat.smoke.test.ts +6 -1
- package/src/__tests__/cli.smoke.test.ts +6 -1
- package/src/__tests__/host-owner.smoke.test.ts +123 -0
- package/src/__tests__/orchestrator-owner.test.ts +198 -0
- package/src/__tests__/orchestrator-pin-keys.test.ts +153 -0
- package/src/__tests__/orchestrator-push.test.ts +145 -0
- package/src/auth/__tests__/trust-circle-integration.test.ts +44 -25
- package/src/auth/__tests__/trust-circle.test.ts +91 -24
- package/src/auth/trust-circle.ts +363 -304
- package/src/auth/types.ts +4 -1
- package/src/bin/host.ts +1258 -905
- package/src/donation/__tests__/donation-service.test.ts +290 -0
- package/src/donation/__tests__/grant-service.test.ts +213 -0
- package/src/donation/__tests__/grant-store.test.ts +113 -0
- package/src/donation/donation-service.ts +392 -0
- package/src/donation/donation-store.ts +164 -0
- package/src/donation/grant-service.ts +200 -0
- package/src/donation/grant-store.ts +152 -0
- package/src/donation/index.ts +49 -0
- package/src/donation/types.ts +220 -0
- package/src/index.ts +66 -3
- package/src/installer/__tests__/config.test.ts +27 -1
- package/src/installer/__tests__/installer.smoke.test.ts +94 -0
- package/src/installer/__tests__/wizard.test.ts +5 -1
- package/src/installer/browser.ts +40 -42
- package/src/installer/config.ts +61 -1
- package/src/installer/index.ts +23 -12
- package/src/installer/service-host/launchd.ts +1 -1
- package/src/installer/service-host/systemd.ts +1 -1
- package/src/installer/wizard.ts +12 -1
- package/src/nat/__tests__/ddns-updater.test.ts +1 -1
- package/src/nat/__tests__/nat-service.test.ts +192 -0
- package/src/nat/__tests__/port-mapper.test.ts +1 -1
- package/src/nat/__tests__/secrets.test.ts +23 -1
- package/src/nat/index.ts +1 -1
- package/src/nat/nat-service.ts +131 -5
- package/src/nat/secrets/index.ts +32 -2
- package/src/nat/types.ts +3 -1
- package/src/orchestrator/host-process-orchestrator.ts +322 -54
- package/src/orchestrator/index.ts +9 -2
- package/src/orchestrator/state-store.ts +21 -3
- package/src/orchestrator/types.ts +48 -2
- package/src/owner/__tests__/owner-node-client.test.ts +194 -0
- package/src/owner/index.ts +12 -0
- package/src/owner/owner-node-client.ts +233 -0
- package/src/push/__tests__/push.test.ts +90 -0
- package/src/push/index.ts +146 -0
- package/src/server/__tests__/error-handler.test.ts +26 -4
- package/src/server/__tests__/grants-admin-route.test.ts +73 -0
- package/src/server/__tests__/grants-route.test.ts +189 -0
- package/src/server/__tests__/nodes-route.test.ts +90 -10
- package/src/server/__tests__/publishers.test.ts +1 -1
- package/src/server/__tests__/server.smoke.test.ts +75 -0
- package/src/server/__tests__/settings-route.test.ts +17 -0
- package/src/server/__tests__/static.test.ts +145 -0
- package/src/server/__tests__/status-route.test.ts +23 -2
- package/src/server/error-handler.ts +47 -0
- package/src/server/index.ts +62 -17
- package/src/server/routes/grants-admin.ts +41 -0
- package/src/server/routes/grants.ts +186 -0
- package/src/server/routes/nodes.ts +49 -26
- package/src/server/routes/settings.ts +11 -3
- package/src/server/routes/status.ts +18 -8
- package/src/server/static.ts +24 -8
- package/src/update/__tests__/apply.test.ts +58 -1
- package/src/update/__tests__/manifest.test.ts +41 -6
- package/src/update/__tests__/release-key.test.ts +42 -0
- package/src/update/__tests__/sign.test.ts +78 -0
- package/src/update/__tests__/update-service.integration.test.ts +44 -9
- package/src/update/apply.ts +46 -4
- package/src/update/index.ts +41 -3
- package/src/update/manifest.ts +214 -172
- package/src/update/release-key.ts +31 -15
- package/src/update/sign.ts +74 -0
- package/dist/ui/assets/index-C9uChk2P.js +0 -14
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Public + internal types for the HostProcessOrchestrator.
|
|
3
3
|
*/
|
|
4
4
|
import type { ChildProcess } from 'node:child_process';
|
|
5
|
+
import type { PushCredentials } from '@serfab/cadre-core';
|
|
5
6
|
/** User-facing configuration for `HostProcessOrchestrator`. */
|
|
6
7
|
export interface HostProcessConfig {
|
|
7
8
|
/** Root directory under which per-container workdirs live. */
|
|
@@ -28,6 +29,29 @@ export interface HostProcessConfig {
|
|
|
28
29
|
spawn?: {
|
|
29
30
|
entrypoint?: string;
|
|
30
31
|
};
|
|
32
|
+
/**
|
|
33
|
+
* Resolver for the platform push credentials (FCM/APNs) to inject into a
|
|
34
|
+
* spawned strand-participating node's `cadre.json` (`config.push`). Called
|
|
35
|
+
* fresh on EVERY spawn/re-spawn so the secret store stays the source of truth
|
|
36
|
+
* and no raw private key is ever persisted in `state.json`. Returns `undefined`
|
|
37
|
+
* when no push credentials are configured (the default — push is opt-in). The
|
|
38
|
+
* resolver itself is responsible for rejecting a partial credential set.
|
|
39
|
+
*/
|
|
40
|
+
pushResolver?: PushCredentialsResolver;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Resolves the push credentials to inject into a node being spawned. Re-invoked
|
|
44
|
+
* per spawn so a restart re-reads the secret store rather than replaying stale
|
|
45
|
+
* (or persisted) material. See {@link HostProcessConfig.pushResolver}.
|
|
46
|
+
*/
|
|
47
|
+
export type PushCredentialsResolver = () => Promise<PushCredentials | undefined>;
|
|
48
|
+
/** Per-child allocated ports. `admin` carries the loopback admin channel (6.6). */
|
|
49
|
+
export interface NodePorts {
|
|
50
|
+
health: number;
|
|
51
|
+
metrics: number;
|
|
52
|
+
p2p: number;
|
|
53
|
+
/** Loopback admin-channel port. Bound only by the owner node. */
|
|
54
|
+
admin: number;
|
|
31
55
|
}
|
|
32
56
|
/** In-memory record per managed child. */
|
|
33
57
|
export interface Handle {
|
|
@@ -36,14 +60,12 @@ export interface Handle {
|
|
|
36
60
|
pid: number;
|
|
37
61
|
startupToken: string;
|
|
38
62
|
workdir: string;
|
|
39
|
-
ports:
|
|
40
|
-
health: number;
|
|
41
|
-
metrics: number;
|
|
42
|
-
p2p: number;
|
|
43
|
-
};
|
|
63
|
+
ports: NodePorts;
|
|
44
64
|
spawnedAt: string;
|
|
45
65
|
partyId: string;
|
|
46
66
|
profile: 'storage' | 'transaction';
|
|
67
|
+
/** True for the admin's owner node (binds the admin channel). */
|
|
68
|
+
owner?: boolean;
|
|
47
69
|
/** Live ChildProcess reference; absent after re-attach via init(). */
|
|
48
70
|
child?: ChildProcess;
|
|
49
71
|
/** Marked false when init() finds the PID dead or token mismatched. */
|
|
@@ -61,11 +83,24 @@ export interface ManagedNodeInfo {
|
|
|
61
83
|
status: 'running' | 'stopped';
|
|
62
84
|
spawnedAt: string;
|
|
63
85
|
workdir: string;
|
|
64
|
-
ports:
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
86
|
+
ports: NodePorts;
|
|
87
|
+
/** True for the admin's owner node. */
|
|
88
|
+
owner?: boolean;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Persisted spawn parameters for the admin's owner node. Stored alongside
|
|
92
|
+
* the handles so an orchestrator restart can re-spawn the owner node from
|
|
93
|
+
* `/api/nodes/:id/{start,restart}` without the caller re-supplying them.
|
|
94
|
+
*/
|
|
95
|
+
export interface OwnerSpawnConfig {
|
|
96
|
+
/** Absolute path to the host's libp2p protobuf identity (`identity.key`). */
|
|
97
|
+
identityPath: string;
|
|
98
|
+
/** Control-network partyId (the host's installId). */
|
|
99
|
+
partyId: string;
|
|
100
|
+
/** External libp2p port — mapped to the child's listen address. */
|
|
101
|
+
libp2pPort: number;
|
|
102
|
+
/** Node profile. Defaults to `storage` (the household node holds strands). */
|
|
103
|
+
profile?: 'storage' | 'transaction';
|
|
69
104
|
}
|
|
70
105
|
/**
|
|
71
106
|
* Listener invoked when a managed node's lifecycle state changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/orchestrator/types.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/orchestrator/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AA8GH,MAAM,eAAe,GAAG,GAAG,CAAC;AAE5B;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,GAAW,EAAE,KAAa;IACvD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,EAAE,CAAC;QACvC,MAAM,IAAI,KAAK,CAAC,8BAA8B,GAAG,EAAE,CAAC,CAAC;IACvD,CAAC;IACD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC;QAC1D,MAAM,IAAI,KAAK,CAAC,gCAAgC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAC3E,CAAC;IACD,OAAO,GAAG,GAAG,GAAG,eAAe,GAAG,KAAK,EAAE,CAAC;AAC5C,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,EAAU;IACvC,MAAM,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;IACxC,IAAI,GAAG,IAAI,CAAC,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,uBAAuB,EAAE,EAAE,CAAC,CAAC;IAC/C,CAAC;IACD,MAAM,GAAG,GAAG,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC;IAClD,MAAM,KAAK,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;IAChC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC7D,MAAM,IAAI,KAAK,CAAC,uBAAuB,EAAE,EAAE,CAAC,CAAC;IAC/C,CAAC;IACD,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Owner-node delegation surface for cadre-host.
|
|
3
|
+
*
|
|
4
|
+
* The manager process spawns the admin's owner cadre node (via
|
|
5
|
+
* `HostProcessOrchestrator`) and delegates owner/membership/identity
|
|
6
|
+
* operations to it over the loopback admin channel using
|
|
7
|
+
* {@link OwnerNodeClient}. See `docs/cadre-host.md` § Control-plane
|
|
8
|
+
* separation.
|
|
9
|
+
*/
|
|
10
|
+
export { OwnerNodeClient, OwnerNodeUnavailableError } from './owner-node-client.js';
|
|
11
|
+
export type { OwnerNodeClientOptions } from './owner-node-client.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Owner-node delegation surface for cadre-host.
|
|
3
|
+
*
|
|
4
|
+
* The manager process spawns the admin's owner cadre node (via
|
|
5
|
+
* `HostProcessOrchestrator`) and delegates owner/membership/identity
|
|
6
|
+
* operations to it over the loopback admin channel using
|
|
7
|
+
* {@link OwnerNodeClient}. See `docs/cadre-host.md` § Control-plane
|
|
8
|
+
* separation.
|
|
9
|
+
*/
|
|
10
|
+
export { OwnerNodeClient, OwnerNodeUnavailableError } from './owner-node-client.js';
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/owner/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,eAAe,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP client for the owner node's loopback admin channel (the 6.6
|
|
3
|
+
* `cadre-node-admin-channel` contract).
|
|
4
|
+
*
|
|
5
|
+
* cadre-host's manager process holds no in-process `CadreNode`; it spawns the
|
|
6
|
+
* admin's owner node as a managed child (see `HostProcessOrchestrator`)
|
|
7
|
+
* and delegates all owner/membership/identity operations to it over this
|
|
8
|
+
* client. The client implements **both** trimmed `CadreNodeLike` interfaces —
|
|
9
|
+
* the trust-circle one (`auth/trust-circle.ts`) and the NAT one
|
|
10
|
+
* (`nat/nat-service.ts`) — plus `pushInviteAddresses` and `addDrone` (the
|
|
11
|
+
* node-donation requester side).
|
|
12
|
+
*
|
|
13
|
+
* Transport: `Authorization: Bearer <token>` against
|
|
14
|
+
* `http://127.0.0.1:<adminPort>`. Every response uses the cadre-provider
|
|
15
|
+
* envelope `{ ok: true, data }` / `{ ok: false, error: { code, message } }`.
|
|
16
|
+
* A refused connection, a transport error, or any non-2xx response surfaces
|
|
17
|
+
* as {@link OwnerNodeUnavailableError}; the trust-circle / NAT services
|
|
18
|
+
* translate that into a `node_unavailable` domain error so the management API
|
|
19
|
+
* returns a clear 503 rather than a raw 500.
|
|
20
|
+
*/
|
|
21
|
+
import type { CadreInvite, DroneInitResult } from '@serfab/cadre-core';
|
|
22
|
+
import type { OwnerAdminEndpoint } from '../orchestrator/index.js';
|
|
23
|
+
import type { CadreNodeLike as TrustCircleCadreNodeLike } from '../auth/trust-circle.js';
|
|
24
|
+
import type { CadreNodeLike as NatCadreNodeLike } from '../nat/nat-service.js';
|
|
25
|
+
/**
|
|
26
|
+
* Raised when the owner node's admin channel can't be reached or returns
|
|
27
|
+
* a non-success response. Carries the node's stable error `code` when one was
|
|
28
|
+
* present in the envelope (e.g. `not_ready`, `not_authorized`).
|
|
29
|
+
*/
|
|
30
|
+
export declare class OwnerNodeUnavailableError extends Error {
|
|
31
|
+
/** The admin-channel error code, when the node answered with an envelope. */
|
|
32
|
+
readonly nodeCode?: string;
|
|
33
|
+
constructor(message: string, nodeCode?: string);
|
|
34
|
+
}
|
|
35
|
+
/** Endpoint provided directly or via a getter (so it tracks re-spawns). */
|
|
36
|
+
type EndpointSource = OwnerAdminEndpoint | (() => OwnerAdminEndpoint | undefined) | undefined;
|
|
37
|
+
export interface OwnerNodeClientOptions {
|
|
38
|
+
/** Fetch override for tests. Defaults to the global `fetch`. */
|
|
39
|
+
fetch?: typeof fetch;
|
|
40
|
+
}
|
|
41
|
+
export declare class OwnerNodeClient implements TrustCircleCadreNodeLike, NatCadreNodeLike {
|
|
42
|
+
private readonly endpointSource;
|
|
43
|
+
private readonly fetchImpl;
|
|
44
|
+
/**
|
|
45
|
+
* @param endpoint Either a fixed `{ baseUrl, token }` or a getter returning
|
|
46
|
+
* the current endpoint (pass `orchestrator.getOwnerAdminEndpoint`
|
|
47
|
+
* bound, so a restart's new bearer token is picked up automatically).
|
|
48
|
+
*/
|
|
49
|
+
constructor(endpoint: EndpointSource, opts?: OwnerNodeClientOptions);
|
|
50
|
+
createInvite(token?: string, expiresInMs?: number): Promise<{
|
|
51
|
+
invite: CadreInvite;
|
|
52
|
+
encodedInvite: string;
|
|
53
|
+
}>;
|
|
54
|
+
acceptPhone(options: {
|
|
55
|
+
phonePeerId: string;
|
|
56
|
+
token?: string;
|
|
57
|
+
}, issuedInvite?: CadreInvite): Promise<void>;
|
|
58
|
+
removePeer(peerId: string): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Encode an invite for out-of-band delivery. The admin contract has no
|
|
61
|
+
* encode route (the mint route already returns `encodedInvite`), so this
|
|
62
|
+
* mirrors cadre-core's encoding (`base64url(JSON.stringify(invite))`).
|
|
63
|
+
*/
|
|
64
|
+
encodeInvite(invite: CadreInvite): string;
|
|
65
|
+
listMembers(): Promise<Array<{
|
|
66
|
+
peerId: string;
|
|
67
|
+
multiaddr: string | null;
|
|
68
|
+
}>>;
|
|
69
|
+
isMember(peerId: string): Promise<boolean>;
|
|
70
|
+
/** Authorized-membership surface (excludes self) — see {@link listMembers} for the addressable one. */
|
|
71
|
+
listAuthorizedMembers(): Promise<Array<{
|
|
72
|
+
peerId: string;
|
|
73
|
+
multiaddr: string | null;
|
|
74
|
+
}>>;
|
|
75
|
+
isAuthorizedMember(peerId: string): Promise<boolean>;
|
|
76
|
+
getPeerId(): Promise<string>;
|
|
77
|
+
getMultiaddrs(): Promise<string[]>;
|
|
78
|
+
/**
|
|
79
|
+
* Mint a seed authorizing a drone — a provider-hosted / donated node — to join
|
|
80
|
+
* this node's cadre. The node signs the seed with its own authority key; only
|
|
81
|
+
* the signed, public `encodedSeed` is returned (the private key never leaves
|
|
82
|
+
* the node). This is the requester ("phone") side of the node-donation flow:
|
|
83
|
+
* the donor host presents the returned seed to the donated node's `POST /seed`.
|
|
84
|
+
*/
|
|
85
|
+
addDrone(options: {
|
|
86
|
+
dronePeerId: string;
|
|
87
|
+
droneMultiaddrs: string[];
|
|
88
|
+
}): Promise<DroneInitResult>;
|
|
89
|
+
/** Push the NAT-resolved addresses the node should embed in future invites. */
|
|
90
|
+
pushInviteAddresses(addresses: string[]): Promise<void>;
|
|
91
|
+
private resolveEndpoint;
|
|
92
|
+
private request;
|
|
93
|
+
private parseEnvelope;
|
|
94
|
+
}
|
|
95
|
+
export {};
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP client for the owner node's loopback admin channel (the 6.6
|
|
3
|
+
* `cadre-node-admin-channel` contract).
|
|
4
|
+
*
|
|
5
|
+
* cadre-host's manager process holds no in-process `CadreNode`; it spawns the
|
|
6
|
+
* admin's owner node as a managed child (see `HostProcessOrchestrator`)
|
|
7
|
+
* and delegates all owner/membership/identity operations to it over this
|
|
8
|
+
* client. The client implements **both** trimmed `CadreNodeLike` interfaces —
|
|
9
|
+
* the trust-circle one (`auth/trust-circle.ts`) and the NAT one
|
|
10
|
+
* (`nat/nat-service.ts`) — plus `pushInviteAddresses` and `addDrone` (the
|
|
11
|
+
* node-donation requester side).
|
|
12
|
+
*
|
|
13
|
+
* Transport: `Authorization: Bearer <token>` against
|
|
14
|
+
* `http://127.0.0.1:<adminPort>`. Every response uses the cadre-provider
|
|
15
|
+
* envelope `{ ok: true, data }` / `{ ok: false, error: { code, message } }`.
|
|
16
|
+
* A refused connection, a transport error, or any non-2xx response surfaces
|
|
17
|
+
* as {@link OwnerNodeUnavailableError}; the trust-circle / NAT services
|
|
18
|
+
* translate that into a `node_unavailable` domain error so the management API
|
|
19
|
+
* returns a clear 503 rather than a raw 500.
|
|
20
|
+
*/
|
|
21
|
+
import debug from 'debug';
|
|
22
|
+
const log = debug('cadre:host:owner-client');
|
|
23
|
+
/**
|
|
24
|
+
* Raised when the owner node's admin channel can't be reached or returns
|
|
25
|
+
* a non-success response. Carries the node's stable error `code` when one was
|
|
26
|
+
* present in the envelope (e.g. `not_ready`, `not_authorized`).
|
|
27
|
+
*/
|
|
28
|
+
export class OwnerNodeUnavailableError extends Error {
|
|
29
|
+
constructor(message, nodeCode) {
|
|
30
|
+
super(message);
|
|
31
|
+
this.name = 'OwnerNodeUnavailableError';
|
|
32
|
+
if (nodeCode !== undefined)
|
|
33
|
+
this.nodeCode = nodeCode;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export class OwnerNodeClient {
|
|
37
|
+
/**
|
|
38
|
+
* @param endpoint Either a fixed `{ baseUrl, token }` or a getter returning
|
|
39
|
+
* the current endpoint (pass `orchestrator.getOwnerAdminEndpoint`
|
|
40
|
+
* bound, so a restart's new bearer token is picked up automatically).
|
|
41
|
+
*/
|
|
42
|
+
constructor(endpoint, opts = {}) {
|
|
43
|
+
this.endpointSource = endpoint;
|
|
44
|
+
this.fetchImpl = opts.fetch ?? fetch;
|
|
45
|
+
}
|
|
46
|
+
// --- trust-circle CadreNodeLike ---
|
|
47
|
+
async createInvite(token, expiresInMs) {
|
|
48
|
+
const body = {};
|
|
49
|
+
if (token !== undefined)
|
|
50
|
+
body.token = token;
|
|
51
|
+
if (expiresInMs !== undefined)
|
|
52
|
+
body.expiresInMs = expiresInMs;
|
|
53
|
+
return await this.request('POST', '/admin/invites', body);
|
|
54
|
+
}
|
|
55
|
+
async acceptPhone(options, issuedInvite) {
|
|
56
|
+
const body = { phonePeerId: options.phonePeerId };
|
|
57
|
+
if (options.token !== undefined)
|
|
58
|
+
body.token = options.token;
|
|
59
|
+
if (issuedInvite !== undefined)
|
|
60
|
+
body.issuedInvite = issuedInvite;
|
|
61
|
+
await this.request('POST', '/admin/accept-phone', body);
|
|
62
|
+
}
|
|
63
|
+
async removePeer(peerId) {
|
|
64
|
+
await this.request('DELETE', `/admin/members/${encodeURIComponent(peerId)}`);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Encode an invite for out-of-band delivery. The admin contract has no
|
|
68
|
+
* encode route (the mint route already returns `encodedInvite`), so this
|
|
69
|
+
* mirrors cadre-core's encoding (`base64url(JSON.stringify(invite))`).
|
|
70
|
+
*/
|
|
71
|
+
encodeInvite(invite) {
|
|
72
|
+
return Buffer.from(JSON.stringify(invite), 'utf8').toString('base64url');
|
|
73
|
+
}
|
|
74
|
+
async listMembers() {
|
|
75
|
+
const data = await this.request('GET', '/admin/members');
|
|
76
|
+
return data.members;
|
|
77
|
+
}
|
|
78
|
+
async isMember(peerId) {
|
|
79
|
+
const data = await this.request('GET', `/admin/members/${encodeURIComponent(peerId)}`);
|
|
80
|
+
return data.member;
|
|
81
|
+
}
|
|
82
|
+
/** Authorized-membership surface (excludes self) — see {@link listMembers} for the addressable one. */
|
|
83
|
+
async listAuthorizedMembers() {
|
|
84
|
+
const data = await this.request('GET', '/admin/authorized-members');
|
|
85
|
+
return data.members;
|
|
86
|
+
}
|
|
87
|
+
async isAuthorizedMember(peerId) {
|
|
88
|
+
const data = await this.request('GET', `/admin/authorized-members/${encodeURIComponent(peerId)}`);
|
|
89
|
+
return data.member;
|
|
90
|
+
}
|
|
91
|
+
// --- NAT CadreNodeLike ---
|
|
92
|
+
async getPeerId() {
|
|
93
|
+
const data = await this.request('GET', '/admin/identity');
|
|
94
|
+
return data.peerId ?? '';
|
|
95
|
+
}
|
|
96
|
+
async getMultiaddrs() {
|
|
97
|
+
const data = await this.request('GET', '/admin/multiaddrs');
|
|
98
|
+
return data.multiaddrs;
|
|
99
|
+
}
|
|
100
|
+
// --- drone seeding (node-donation requester side) ---
|
|
101
|
+
/**
|
|
102
|
+
* Mint a seed authorizing a drone — a provider-hosted / donated node — to join
|
|
103
|
+
* this node's cadre. The node signs the seed with its own authority key; only
|
|
104
|
+
* the signed, public `encodedSeed` is returned (the private key never leaves
|
|
105
|
+
* the node). This is the requester ("phone") side of the node-donation flow:
|
|
106
|
+
* the donor host presents the returned seed to the donated node's `POST /seed`.
|
|
107
|
+
*/
|
|
108
|
+
async addDrone(options) {
|
|
109
|
+
return await this.request('POST', '/admin/add-drone', {
|
|
110
|
+
dronePeerId: options.dronePeerId,
|
|
111
|
+
droneMultiaddrs: options.droneMultiaddrs,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
// --- push-model invite addresses ---
|
|
115
|
+
/** Push the NAT-resolved addresses the node should embed in future invites. */
|
|
116
|
+
async pushInviteAddresses(addresses) {
|
|
117
|
+
await this.request('PUT', '/admin/invite-addresses', { addresses });
|
|
118
|
+
}
|
|
119
|
+
// --- internals ---
|
|
120
|
+
resolveEndpoint() {
|
|
121
|
+
const ep = typeof this.endpointSource === 'function' ? this.endpointSource() : this.endpointSource;
|
|
122
|
+
if (!ep) {
|
|
123
|
+
throw new OwnerNodeUnavailableError('Owner node admin endpoint is not available');
|
|
124
|
+
}
|
|
125
|
+
return ep;
|
|
126
|
+
}
|
|
127
|
+
async request(method, path, body) {
|
|
128
|
+
const ep = this.resolveEndpoint();
|
|
129
|
+
const headers = { authorization: `Bearer ${ep.token}` };
|
|
130
|
+
const init = { method, headers };
|
|
131
|
+
if (body !== undefined) {
|
|
132
|
+
headers['content-type'] = 'application/json';
|
|
133
|
+
init.body = JSON.stringify(body);
|
|
134
|
+
}
|
|
135
|
+
let res;
|
|
136
|
+
try {
|
|
137
|
+
res = await this.fetchImpl(`${ep.baseUrl}${path}`, init);
|
|
138
|
+
}
|
|
139
|
+
catch (err) {
|
|
140
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
141
|
+
log('admin %s %s transport error: %s', method, path, message);
|
|
142
|
+
throw new OwnerNodeUnavailableError(`Owner node unreachable: ${message}`);
|
|
143
|
+
}
|
|
144
|
+
const envelope = await this.parseEnvelope(res);
|
|
145
|
+
if (!res.ok || !envelope.ok) {
|
|
146
|
+
const code = envelope.error?.code;
|
|
147
|
+
const message = envelope.error?.message ?? `admin ${method} ${path} → HTTP ${res.status}`;
|
|
148
|
+
log('admin %s %s failed: [%s] %s', method, path, code ?? res.status, message);
|
|
149
|
+
throw new OwnerNodeUnavailableError(message, code);
|
|
150
|
+
}
|
|
151
|
+
return envelope.data;
|
|
152
|
+
}
|
|
153
|
+
async parseEnvelope(res) {
|
|
154
|
+
try {
|
|
155
|
+
const parsed = await res.json();
|
|
156
|
+
if (parsed && typeof parsed === 'object') {
|
|
157
|
+
return parsed;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
// Non-JSON body — fall through to an empty envelope; status drives the
|
|
162
|
+
// ok/non-ok decision in the caller.
|
|
163
|
+
}
|
|
164
|
+
return {};
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=owner-node-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"owner-node-client.js","sourceRoot":"","sources":["../../src/owner/owner-node-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAO1B,MAAM,GAAG,GAAG,KAAK,CAAC,yBAAyB,CAAC,CAAC;AAE7C;;;;GAIG;AACH,MAAM,OAAO,yBAA0B,SAAQ,KAAK;IAIlD,YAAY,OAAe,EAAE,QAAiB;QAC5C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;QACxC,IAAI,QAAQ,KAAK,SAAS;YAAE,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IACvD,CAAC;CACF;AAaD,MAAM,OAAO,eAAe;IAI1B;;;;OAIG;IACH,YAAY,QAAwB,EAAE,OAA+B,EAAE;QACrE,IAAI,CAAC,cAAc,GAAG,QAAQ,CAAC;QAC/B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC;IACvC,CAAC;IAED,qCAAqC;IAErC,KAAK,CAAC,YAAY,CAChB,KAAc,EACd,WAAoB;QAEpB,MAAM,IAAI,GAA4B,EAAE,CAAC;QACzC,IAAI,KAAK,KAAK,SAAS;YAAE,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QAC5C,IAAI,WAAW,KAAK,SAAS;YAAE,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC9D,OAAO,MAAM,IAAI,CAAC,OAAO,CACvB,MAAM,EACN,gBAAgB,EAChB,IAAI,CACL,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,WAAW,CACf,OAAgD,EAChD,YAA0B;QAE1B,MAAM,IAAI,GAA4B,EAAE,WAAW,EAAE,OAAO,CAAC,WAAW,EAAE,CAAC;QAC3E,IAAI,OAAO,CAAC,KA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I,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YAC9E,MAAM,IAAI,yBAAyB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QACrD,CAAC;QACD,OAAO,QAAQ,CAAC,IAAS,CAAC;IAC5B,CAAC;IAEO,KAAK,CAAC,aAAa,CAAC,GAAa;QAKvC,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;YAChC,IAAI,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;gBACzC,OAAO,MAAuF,CAAC;YACjG,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,uEAAuE;YACvE,oCAAoC;QACtC,CAAC;QACD,OAAO,EAAE,CAAC;IACZ,CAAC;CACF"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Push (FCM/APNs) credential storage + resolution for cadre-host.
|
|
3
|
+
*
|
|
4
|
+
* The platform-push secrets a self-hosted deployment provisions live in the host
|
|
5
|
+
* secret store (keytar with file-store fallback — the same store DDNS tokens use);
|
|
6
|
+
* the non-secret app-config bits (APNs bundle id / sandbox toggle, cooldown /
|
|
7
|
+
* debounce) live in `host.config.json` (`PushSettings`). At node-spawn time the
|
|
8
|
+
* orchestrator's `pushResolver` calls {@link resolvePushCredentials}, which reads
|
|
9
|
+
* BOTH and merges them into the `PushCredentials` block written into the spawned
|
|
10
|
+
* node's `cadre.json`.
|
|
11
|
+
*
|
|
12
|
+
* Secret hygiene: the FCM service-account fields and the APNs `.p8` key are stored
|
|
13
|
+
* ONLY in the secret store, never in `host.config.json` and never in `state.json`.
|
|
14
|
+
* They are re-read on every spawn so a restart picks up rotated keys, and the
|
|
15
|
+
* resolver redacts on any log line. A partial credential set (a present platform
|
|
16
|
+
* missing required fields) is rejected — fail fast, not at first push.
|
|
17
|
+
*/
|
|
18
|
+
import type { PushCredentials } from '@serfab/cadre-core';
|
|
19
|
+
import type { SecretsStore } from '../nat/secrets/index.js';
|
|
20
|
+
import type { PushSettings } from '../installer/config.js';
|
|
21
|
+
/** Push platform whose secret bundle lives in the secret store. */
|
|
22
|
+
export type PushSecretPlatform = 'fcm' | 'apns';
|
|
23
|
+
/** Build the secret-store account key for a platform's credential bundle. */
|
|
24
|
+
export declare function pushAccount(platform: PushSecretPlatform): string;
|
|
25
|
+
/** FCM secret bundle persisted in the secret store (the whole set is sensitive). */
|
|
26
|
+
export interface FcmSecret {
|
|
27
|
+
projectId: string;
|
|
28
|
+
clientEmail: string;
|
|
29
|
+
/** Service-account RSA private key, PEM. */
|
|
30
|
+
privateKey: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* APNs secret bundle persisted in the secret store. `bundleId` / `production` are
|
|
34
|
+
* NOT here — they are non-secret app-config in {@link PushSettings}.
|
|
35
|
+
*/
|
|
36
|
+
export interface ApnsSecret {
|
|
37
|
+
keyId: string;
|
|
38
|
+
teamId: string;
|
|
39
|
+
/** `.p8` ES256 private key, PEM. */
|
|
40
|
+
privateKey: string;
|
|
41
|
+
}
|
|
42
|
+
/** Store (or replace) the FCM service-account secret bundle. */
|
|
43
|
+
export declare function setFcmSecret(secrets: SecretsStore, secret: FcmSecret): Promise<void>;
|
|
44
|
+
/** Store (or replace) the APNs auth-key secret bundle. */
|
|
45
|
+
export declare function setApnsSecret(secrets: SecretsStore, secret: ApnsSecret): Promise<void>;
|
|
46
|
+
/** Remove a platform's secret bundle. Returns true if one was present. */
|
|
47
|
+
export declare function clearPushSecret(secrets: SecretsStore, platform: PushSecretPlatform): Promise<boolean>;
|
|
48
|
+
/**
|
|
49
|
+
* Resolve the full {@link PushCredentials} block to inject into a spawned node,
|
|
50
|
+
* merging the secret-store bundles with the non-secret {@link PushSettings}.
|
|
51
|
+
*
|
|
52
|
+
* Returns `undefined` when NO platform is configured (push is opt-in — the node
|
|
53
|
+
* then constructs no fan-out). Throws when a configured platform is incomplete
|
|
54
|
+
* (e.g. APNs secret present but `bundleId` unset), so a misconfig surfaces at the
|
|
55
|
+
* spawn boundary rather than silently at first push.
|
|
56
|
+
*/
|
|
57
|
+
export declare function resolvePushCredentials(secrets: SecretsStore, settings: PushSettings | undefined): Promise<PushCredentials | undefined>;
|
|
58
|
+
/**
|
|
59
|
+
* A description of which push platforms are configured, for the `push status` CLI
|
|
60
|
+
* and any UI — derived without exposing any secret material.
|
|
61
|
+
*/
|
|
62
|
+
export interface PushStatus {
|
|
63
|
+
fcm: boolean;
|
|
64
|
+
apns: boolean;
|
|
65
|
+
}
|
|
66
|
+
/** Report which platforms have a stored secret bundle (no secret material). */
|
|
67
|
+
export declare function pushStatus(secrets: SecretsStore): Promise<PushStatus>;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Push (FCM/APNs) credential storage + resolution for cadre-host.
|
|
3
|
+
*
|
|
4
|
+
* The platform-push secrets a self-hosted deployment provisions live in the host
|
|
5
|
+
* secret store (keytar with file-store fallback — the same store DDNS tokens use);
|
|
6
|
+
* the non-secret app-config bits (APNs bundle id / sandbox toggle, cooldown /
|
|
7
|
+
* debounce) live in `host.config.json` (`PushSettings`). At node-spawn time the
|
|
8
|
+
* orchestrator's `pushResolver` calls {@link resolvePushCredentials}, which reads
|
|
9
|
+
* BOTH and merges them into the `PushCredentials` block written into the spawned
|
|
10
|
+
* node's `cadre.json`.
|
|
11
|
+
*
|
|
12
|
+
* Secret hygiene: the FCM service-account fields and the APNs `.p8` key are stored
|
|
13
|
+
* ONLY in the secret store, never in `host.config.json` and never in `state.json`.
|
|
14
|
+
* They are re-read on every spawn so a restart picks up rotated keys, and the
|
|
15
|
+
* resolver redacts on any log line. A partial credential set (a present platform
|
|
16
|
+
* missing required fields) is rejected — fail fast, not at first push.
|
|
17
|
+
*/
|
|
18
|
+
import debug from 'debug';
|
|
19
|
+
import { validatePushCredentials } from '@serfab/cadre-core';
|
|
20
|
+
const log = debug('cadre:host:push');
|
|
21
|
+
/** Build the secret-store account key for a platform's credential bundle. */
|
|
22
|
+
export function pushAccount(platform) {
|
|
23
|
+
return `push:${platform}`;
|
|
24
|
+
}
|
|
25
|
+
/** Store (or replace) the FCM service-account secret bundle. */
|
|
26
|
+
export async function setFcmSecret(secrets, secret) {
|
|
27
|
+
await secrets.set(pushAccount('fcm'), JSON.stringify(secret));
|
|
28
|
+
}
|
|
29
|
+
/** Store (or replace) the APNs auth-key secret bundle. */
|
|
30
|
+
export async function setApnsSecret(secrets, secret) {
|
|
31
|
+
await secrets.set(pushAccount('apns'), JSON.stringify(secret));
|
|
32
|
+
}
|
|
33
|
+
/** Remove a platform's secret bundle. Returns true if one was present. */
|
|
34
|
+
export async function clearPushSecret(secrets, platform) {
|
|
35
|
+
return secrets.delete(pushAccount(platform));
|
|
36
|
+
}
|
|
37
|
+
/** Read a platform's stored secret bundle, or null when unset. */
|
|
38
|
+
async function readSecret(secrets, platform) {
|
|
39
|
+
const raw = await secrets.get(pushAccount(platform));
|
|
40
|
+
if (raw === null)
|
|
41
|
+
return null;
|
|
42
|
+
try {
|
|
43
|
+
return JSON.parse(raw);
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
throw new Error(`Stored ${platform} push secret is not valid JSON: ${err.message}`, { cause: err });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Resolve the full {@link PushCredentials} block to inject into a spawned node,
|
|
51
|
+
* merging the secret-store bundles with the non-secret {@link PushSettings}.
|
|
52
|
+
*
|
|
53
|
+
* Returns `undefined` when NO platform is configured (push is opt-in — the node
|
|
54
|
+
* then constructs no fan-out). Throws when a configured platform is incomplete
|
|
55
|
+
* (e.g. APNs secret present but `bundleId` unset), so a misconfig surfaces at the
|
|
56
|
+
* spawn boundary rather than silently at first push.
|
|
57
|
+
*/
|
|
58
|
+
export async function resolvePushCredentials(secrets, settings) {
|
|
59
|
+
const fcmSecret = await readSecret(secrets, 'fcm');
|
|
60
|
+
const apnsSecret = await readSecret(secrets, 'apns');
|
|
61
|
+
if (!fcmSecret && !apnsSecret)
|
|
62
|
+
return undefined;
|
|
63
|
+
const push = {};
|
|
64
|
+
if (fcmSecret) {
|
|
65
|
+
const fcm = {
|
|
66
|
+
projectId: fcmSecret.projectId,
|
|
67
|
+
clientEmail: fcmSecret.clientEmail,
|
|
68
|
+
privateKey: fcmSecret.privateKey,
|
|
69
|
+
};
|
|
70
|
+
push.fcm = fcm;
|
|
71
|
+
}
|
|
72
|
+
if (apnsSecret) {
|
|
73
|
+
const apns = {
|
|
74
|
+
keyId: apnsSecret.keyId,
|
|
75
|
+
teamId: apnsSecret.teamId,
|
|
76
|
+
bundleId: settings?.apns?.bundleId ?? '',
|
|
77
|
+
privateKey: apnsSecret.privateKey,
|
|
78
|
+
...(settings?.apns?.production !== undefined ? { production: settings.apns.production } : {}),
|
|
79
|
+
};
|
|
80
|
+
push.apns = apns;
|
|
81
|
+
}
|
|
82
|
+
if (settings?.cooldownMs !== undefined)
|
|
83
|
+
push.cooldownMs = settings.cooldownMs;
|
|
84
|
+
if (settings?.debounceMs !== undefined)
|
|
85
|
+
push.debounceMs = settings.debounceMs;
|
|
86
|
+
const errors = validatePushCredentials(push);
|
|
87
|
+
if (errors.length > 0) {
|
|
88
|
+
throw new Error(`Invalid push credentials: ${errors.join('; ')}`);
|
|
89
|
+
}
|
|
90
|
+
log('resolved push credentials (fcm=%s apns=%s)', !!push.fcm, !!push.apns);
|
|
91
|
+
return push;
|
|
92
|
+
}
|
|
93
|
+
/** Report which platforms have a stored secret bundle (no secret material). */
|
|
94
|
+
export async function pushStatus(secrets) {
|
|
95
|
+
const accounts = await secrets.list();
|
|
96
|
+
return {
|
|
97
|
+
fcm: accounts.includes(pushAccount('fcm')),
|
|
98
|
+
apns: accounts.includes(pushAccount('apns')),
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","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CAAC,UAAU,CAAC;IAC9E,IAAI,QAAQ,EAAE,UAAU,KAAK,SAAS;QAAE,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAC;IAE9E,MAAM,MAAM,GAAG,uBAAuB,CAAC,IAAI,CAAC,CAAC;IAC7C,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,6BAA6B,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACpE,CAAC;IACD,GAAG,CAAC,4CAA4C,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3E,OAAO,IAAI,CAAC;AACd,CAAC;AAWD,+EAA+E;AAC/E,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,OAAqB;IACpD,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,IAAI,EAAE,CAAC;IACtC,OAAO;QACL,GAAG,EAAE,QAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QAC1C,IAAI,EAAE,QAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;KAC7C,CAAC;AACJ,CAAC"}
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* invalid_label, invalid_token → 400
|
|
8
8
|
* not_found, already_redeemed → 404
|
|
9
9
|
* expired → 410
|
|
10
|
+
* node_unavailable → 503
|
|
10
11
|
* storage_error → 500
|
|
11
12
|
* - NatError
|
|
12
13
|
* invalid_config, ddns_provider_unknown,
|
|
@@ -14,12 +15,28 @@
|
|
|
14
15
|
* secrets_unavailable, storage_error,
|
|
15
16
|
* mapping_failed, router_unreachable,
|
|
16
17
|
* ip_detection_failed, ddns_update_failed → 500
|
|
18
|
+
* node_unavailable → 503
|
|
17
19
|
* - UpdateErrorException
|
|
18
20
|
* manifest_invalid, no_update_available,
|
|
19
21
|
* min_previous_version → 400
|
|
20
22
|
* apply_in_progress → 409
|
|
21
23
|
* signature_invalid, unsupported_state_version,
|
|
22
24
|
* apply_failed, rollback_failed, storage_error → 500
|
|
25
|
+
* - GrantError
|
|
26
|
+
* invalid_label, invalid_max_nodes,
|
|
27
|
+
* invalid_ttl → 400
|
|
28
|
+
* not_found → 404
|
|
29
|
+
* storage_error → 500
|
|
30
|
+
* - DonationError
|
|
31
|
+
* invalid_request → 400
|
|
32
|
+
* unauthorized → 401
|
|
33
|
+
* forbidden → 403
|
|
34
|
+
* not_found → 404
|
|
35
|
+
* invalid_state → 409
|
|
36
|
+
* quota_exceeded → 429
|
|
37
|
+
* orchestrator_error, storage_error → 500
|
|
38
|
+
* seed_failed → 502
|
|
39
|
+
* peer_unavailable → 503
|
|
23
40
|
* - everything else → 500 (code "internal")
|
|
24
41
|
*/
|
|
25
42
|
import type { FastifyInstance } from 'fastify';
|