@cotal-ai/core 0.11.5 → 0.12.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.
@@ -1,4 +1,5 @@
1
1
  import { type Extension } from "./registry.js";
2
+ import type { SecretStore } from "./secret-store.js";
2
3
  /**
3
4
  * The one extension kind an identity/auth implementation registers so a composition root can turn
4
5
  * on USER-MODE auth (the human-owner identity plane over per-agent NATS identity) WITHOUT importing
@@ -14,21 +15,29 @@ import { type Extension } from "./registry.js";
14
15
  * No provider registered ⇒ user-mode auth is unavailable and requesting it MUST fail loud (no
15
16
  * static fallback) — a library root that never imports the auth package simply cannot serve a
16
17
  * user-auth space.
18
+ *
19
+ * TWO state surfaces, split by the {@link SecretStore} seam: the provider's SECRET material
20
+ * (callout account, issuer keys, owner secret, service key projection) rides the `store` each
21
+ * method receives — the CALLER composes it (locally the workspace's `.cotal`-rooted filesystem
22
+ * store; a hosted composition injects KMS/Vault), the provider never discovers one ambiently.
23
+ * The provider's NON-SEAM state (the actor ledger, the IdP pin, service runtime discovery)
24
+ * stays under `dir`, the local state directory.
17
25
  */
18
26
  export interface AuthProvider extends Extension {
19
27
  readonly kind: "auth-provider";
20
28
  /**
21
- * Ensure this space's user-auth material exists under `input.dir` (generated + persisted on the
22
- * first call, reused verbatim after — account identities and signing keys MUST be stable across
23
- * restarts or previously-issued credentials break) and describe what the composition root must
24
- * wire up. Idempotent. This call may hold the provisioning seeds BRIEFLY; the long-lived service
29
+ * Ensure this space's user-auth material exists (generated + persisted on the first call, reused
30
+ * verbatim after — account identities and signing keys MUST be stable across restarts or
31
+ * previously-issued credentials break) and describe what the composition root must wire up.
32
+ * Secret material persists through `input.store`; non-seam state under `input.dir`. Idempotent. This call may hold the provisioning seeds BRIEFLY; the long-lived service
25
33
  * process must load only provider-owned projected files written here, never the space's full
26
34
  * trust bundle.
27
35
  */
28
36
  prepareServer(input: AuthPrepareInput): Promise<AuthPrepared>;
29
37
  /**
30
38
  * CLIENT side: produce the connect material for a user-mode space from THIS machine's session
31
- * state (the login cache + the provider's space-scoped state under `dir`). `actor` is the
39
+ * state (the login cache + the provider's space-scoped state secrets in `store`, the rest
40
+ * under `dir`). `actor` is the
32
41
  * ledger-granted agent-instance the caller connects as. Returns what {@link EndpointOptions}'
33
42
  * user mode consumes (`bearer` + `sentinelCreds`). MUST fail loud with the EXACT operator
34
43
  * action when anything is missing — not logged in (`cotal login --idp …`), the auth service
@@ -41,6 +50,7 @@ export interface AuthProvider extends Extension {
41
50
  * `spawn -f`) ride. An under-scoped or unknown view MUST fail loud with the exact re-grant.
42
51
  */
43
52
  userCredentials(opts: {
53
+ store: SecretStore;
44
54
  dir: string;
45
55
  space: string;
46
56
  actor: string;
@@ -54,9 +64,10 @@ export interface AuthProvider extends Extension {
54
64
  * offline from the login session + the space's local user-auth material (no IdP round trip).
55
65
  * The spawn paths use it to answer "whose agents are these": a foreground/manifest spawn runs
56
66
  * the agents under the OPERATOR's owner. MUST fail loud when not logged in (naming the exact
57
- * `cotal login --idp …` line) or when the space has no user-auth material under `dir`.
67
+ * `cotal login --idp …` line) or when the space has no user-auth material (in `store`/`dir`).
58
68
  */
59
69
  ownerForLogin(opts: {
70
+ store: SecretStore;
60
71
  dir: string;
61
72
  space: string;
62
73
  }): Promise<string>;
@@ -64,10 +75,11 @@ export interface AuthProvider extends Extension {
64
75
  * Read-only OFFLINE introspection for status surfaces (`cotal status`): this machine's cached
65
76
  * login for the space and — where the space's ledger is locally readable — whether that login's
66
77
  * `actor` is granted. Never network-bound and never a mint; "not signed in" is a REPORTED state
67
- * here, not a thrown one. Throws only when the space has no user-auth material under `dir`
78
+ * here, not a thrown one. Throws only when the space has no user-auth material in `store`/`dir`
68
79
  * (there is nothing to report status about).
69
80
  */
70
81
  userStatus(opts: {
82
+ store: SecretStore;
71
83
  dir: string;
72
84
  space: string;
73
85
  actor: string;
@@ -78,9 +90,10 @@ export interface AuthProvider extends Extension {
78
90
  * connect payloads". Returns the ONE-TIME plaintext agent secret (persisted only as a hash;
79
91
  * the caller delivers it to the agent process via a 0600 file and never sees it again) plus
80
92
  * the sentinel creds the agent presents alongside its bearers. Upsert — re-granting an actor
81
- * rotates its secret. MUST fail loud when the space has no user-auth material under `dir`.
93
+ * rotates its secret. MUST fail loud when the space has no user-auth material in `store`/`dir`.
82
94
  */
83
95
  grantAgent(opts: {
96
+ store: SecretStore;
84
97
  dir: string;
85
98
  space: string;
86
99
  owner: string;
@@ -116,6 +129,45 @@ export interface AuthProvider extends Extension {
116
129
  owner: string;
117
130
  actor: string;
118
131
  }): Promise<string[] | undefined>;
132
+ /**
133
+ * Remove this provider's SECRET material for a space from the given store — the DELETE half of
134
+ * the seam pair (every kind that reads and writes through a {@link SecretStore} must be
135
+ * deletable through it, or a reset wipes local identity while an injected backend keeps the old
136
+ * secrets authoritative: split authority, and the next provision mixes a fresh trust bundle
137
+ * with stale stable identities). Attempts EVERY owned key even when one fails (each delete is
138
+ * idempotent by the store contract, so a failed pass is retryable as-is), then throws with the
139
+ * collected failures. Touches ONLY the store — non-seam state (ledger, IdP pin, discovery) is
140
+ * the caller's local-reset concern, swept only AFTER this succeeds.
141
+ */
142
+ deprovisionSecrets(opts: {
143
+ store: SecretStore;
144
+ space: string;
145
+ }): Promise<void>;
146
+ /**
147
+ * Read-only OFFLINE continuity commitment for this space's existing user-auth trust state. The
148
+ * provider defines `scheme`; `value` is safe to place in a backup manifest and MUST commit to the
149
+ * account identity, owner derivation, IdP/issuer pins, and every interactive + managed authority
150
+ * row. Missing or malformed state throws. This method must never create, repair, rotate, or mint.
151
+ */
152
+ trustFingerprint(opts: {
153
+ store: SecretStore;
154
+ dir: string;
155
+ space: string;
156
+ }): Promise<AuthTrustFingerprint>;
157
+ /**
158
+ * Validate that retained managed-agent material still names the SAME live principal and authority
159
+ * row. This is the resume path: it must reuse the supplied token/sentinel, never call
160
+ * {@link grantAgent}, rotate a token, create a row, or provision a replacement identity.
161
+ */
162
+ validateRetainedAgent(opts: {
163
+ store: SecretStore;
164
+ dir: string;
165
+ space: string;
166
+ owner: string;
167
+ actor: string;
168
+ actorToken: string;
169
+ sentinelCreds: string;
170
+ }): Promise<RetainedAgentAuthority>;
119
171
  /**
120
172
  * Registry name of the provider's self-registered {@link Command} that prints ONE fresh agent
121
173
  * bearer to stdout and exits (flags: `--dir <state-dir> --space <space> --owner <o> --actor <a>
@@ -124,6 +176,21 @@ export interface AuthProvider extends Extension {
124
176
  * runtime only runs an argv and reads a line. */
125
177
  readonly agentBearerCommand: string;
126
178
  }
179
+ /** Provider-defined, versioned manifest-safe commitment. Callers compare both fields exactly. */
180
+ export interface AuthTrustFingerprint {
181
+ scheme: string;
182
+ value: string;
183
+ }
184
+ /** Existing managed row returned after retained secret + sentinel validation. */
185
+ export interface RetainedAgentAuthority {
186
+ owner: string;
187
+ actor: string;
188
+ scope: string[];
189
+ allowSubscribe: string[];
190
+ allowPublish: string[];
191
+ role?: string;
192
+ parent?: string;
193
+ }
127
194
  /** The ONE registered auth provider, or a thrown sentence naming the fix. More than one registered
128
195
  * is ambiguous and refuses just as loudly — there is no pick-the-first fallback. Lives in core so
129
196
  * every surface that resolves the provider generically (CLI, manager) shares one resolution. */
@@ -165,8 +232,13 @@ export interface AuthPrepareInput {
165
232
  pub: string;
166
233
  signingSeed: string;
167
234
  };
168
- /** The provider's OWN state dir. The caller keys it — today `<root>/.cotal/auth/<space>`; a
169
- * future (broker, space) key is a caller change, never an on-disk format break. */
235
+ /** Where the provider's SECRET material persists (callout account, issuer keys, owner secret,
236
+ * service key projection) caller-composed, keys are the provider's own. Locally the
237
+ * workspace's `.cotal`-rooted filesystem store; a hosted composition injects its backend. */
238
+ store: SecretStore;
239
+ /** The provider's OWN state dir for NON-SEAM state (actor ledger, IdP pin, service runtime
240
+ * discovery). The caller keys it — today `<root>/.cotal/auth/<space>`; a future
241
+ * (broker, space) key is a caller change, never an on-disk format break. */
170
242
  dir: string;
171
243
  /** The operator's external identity-provider base URL (`up --user-auth --idp <url>`), OPAQUE to
172
244
  * core — the provider pins/persists it (first call requires one; a later call must match the
@@ -1 +1 @@
1
- {"version":3,"file":"auth-provider.d.ts","sourceRoot":"","sources":["../src/auth-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,SAAS,EAAE,MAAM,eAAe,CAAC;AAEzD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,YAAa,SAAQ,SAAS;IAC7C,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC;IAC/B;;;;;;;OAOG;IACH,aAAa,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IAC9D;;;;;;;;;;;;;OAaG;IACH,eAAe,CAAC,IAAI,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACxI;;;;;;OAMG;IACH,aAAa,CAAC,IAAI,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACrE;;;;;;OAMG;IACH,UAAU,CAAC,IAAI,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IACzF;;;;;;;OAOG;IACH,UAAU,CAAC,IAAI,EAAE;QACf,GAAG,EAAE,MAAM,CAAC;QACZ,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,EAAE,CAAC;QAChB,cAAc,EAAE,MAAM,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-provider.js","sourceRoot":"","sources":["../src/auth-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAkB,MAAM,eAAe,CAAC;AAiKzD;;iGAEiG;AACjG,MAAM,UAAU,mBAAmB;IACjC,MAAM,SAAS,GAAG,QAAQ,CAAC,GAAG,CAAe,eAAe,CAAC,CAAC;IAC9D,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC;QACxB,MAAM,IAAI,KAAK,CACb,yKAAyK,CAC1K,CAAC;IACJ,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,uCAAuC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,gCAAgC,CAAC,CAAC;IAClI,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC;AACtB,CAAC"}
@@ -0,0 +1,55 @@
1
+ import { StoreCompression, type StreamConfig } from "@nats-io/jetstream";
2
+ export type SpaceBackupSelection = "full" | "registry";
3
+ export type SpaceBackupStreamClass = "messages" | "registry" | "authorization";
4
+ export type SpaceBackupExcludedClass = "transient" | "derived" | "lease";
5
+ export interface SpaceBackupStream {
6
+ name: string;
7
+ class: SpaceBackupStreamClass;
8
+ }
9
+ export interface SpaceBackupExcludedStream {
10
+ name: string;
11
+ class: SpaceBackupExcludedClass;
12
+ }
13
+ export interface SpaceBackupInventory {
14
+ backedUp: readonly SpaceBackupStream[];
15
+ excluded: readonly SpaceBackupExcludedStream[];
16
+ full: readonly string[];
17
+ registry: readonly string[];
18
+ }
19
+ /** The complete Cotal stream inventory at a stable backup cut. Only the eight `backedUp` streams
20
+ * enter a full artifact; the four excluded streams are transient, derived, or leases. */
21
+ export declare function spaceBackupInventory(space: string): SpaceBackupInventory;
22
+ /** Reject a missing, foreign, or additional stream before selecting artifact components. */
23
+ export declare function validateSpaceBackupInventory(space: string, actualNames: readonly string[]): SpaceBackupInventory;
24
+ export interface BackupStreamState {
25
+ messages: number;
26
+ bytes: number;
27
+ first_seq: number;
28
+ last_seq: number;
29
+ consumer_count: number;
30
+ first_ts?: string;
31
+ last_ts?: string;
32
+ deleted?: number[];
33
+ num_deleted?: number;
34
+ num_subjects?: number;
35
+ subjects?: Record<string, number>;
36
+ lost?: {
37
+ msgs?: number[] | null;
38
+ bytes?: number;
39
+ };
40
+ }
41
+ /** The NATS 2.10 stream-config surface Cotal permits in an artifact or restore request. */
42
+ export type CanonicalBackupStreamConfig = Pick<StreamConfig, "name" | "subjects" | "retention" | "storage" | "max_consumers" | "max_msgs" | "max_bytes" | "max_age" | "max_msgs_per_subject" | "max_msg_size" | "discard" | "num_replicas" | "duplicate_window" | "allow_direct" | "mirror_direct" | "discard_new_per_subject" | "allow_rollup_hdrs" | "deny_delete" | "deny_purge" | "sealed" | "consumer_limits"> & {
43
+ no_ack: boolean;
44
+ compression: typeof StoreCompression.None;
45
+ };
46
+ export declare const BACKUP_MAX_MSGS_PER_SUBJECT = 1000;
47
+ export declare const BACKUP_PLANE3_DEDUP_WINDOW_MS: number;
48
+ /** Current canonical config for one of the eight backed-up streams. Restore callers must use this
49
+ * config, not the config embedded in untrusted snapshot bytes. */
50
+ export declare function canonicalBackupStreamConfig(space: string, stream: string): CanonicalBackupStreamConfig;
51
+ /** Validate every active and security-sensitive stream setting, including explicit rejection of
52
+ * mirrors, sources, transforms, republish, placement, sealing, metadata, and future active features. */
53
+ export declare function validateCanonicalBackupStreamConfig(space: string, stream: string, actual: Readonly<Record<string, unknown>>): CanonicalBackupStreamConfig;
54
+ export declare function validateBackupStreamState(state: Readonly<Record<string, unknown>>): BackupStreamState;
55
+ //# sourceMappingURL=backup-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backup-config.d.ts","sourceRoot":"","sources":["../src/backup-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,gBAAgB,EAChB,KAAK,YAAY,EAClB,MAAM,oBAAoB,CAAC;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AClC,IAAI,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CACnD;AAED,2FAA2F;AAC3F,MAAM,MAAM,2BAA2B,GAAG,IAAI,CAC5C,YAAY,EACV,MAAM,GACN,UAAU,GACV,WAAW,GACX,SAAS,GACT,eAAe,GACf,UAAU,GACV,WAAW,GACX,SAAS,GACT,sBAAsB,GACtB,cAAc,GACd,SAAS,GACT,cAAc,GACd,kBAAkB,GAClB,cAAc,GACd,eAAe,GACf,yBAAyB,GACzB,mBAAmB,GACnB,aAAa,GACb,YAAY,GACZ,QAAQ,GACR,iBAAiB,CACpB,GAAG;IACF,MAAM,EAAE,OAAO,CAAC;IAChB,WAAW,EAAE,OAAO,gBAAgB,CAAC,IAAI,CAAC;CAC3C,CAAC;AAGF,eAAO,MAAM,2BAA2B,OAAO,CAAC;AAChD,eAAO,MAAM,6BAA6B,QAAqB,CAAC;AA+BhE;kEACkE;AAClE,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,2BAA2B,CAuCtG;AAiCD;wGACwG;AACxG,wBAAgB,mCAAmC,CACjD,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GACxC,2BAA2B,CA8B7B;AAED,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,iBAAiB,CA4DrG"}
@@ -0,0 +1,243 @@
1
+ import { DiscardPolicy, RetentionPolicy, StorageType, StoreCompression, } from "@nats-io/jetstream";
2
+ import { nanos } from "@nats-io/transport-node";
3
+ import { aclBucket, channelBucket, chatStream, deliveryBucket, dlvStream, dmStream, inboxStream, managerBucket, membersBucket, membershipBucket, presenceBucket, spacePrefix, taskStream, } from "./subjects.js";
4
+ /** The complete Cotal stream inventory at a stable backup cut. Only the eight `backedUp` streams
5
+ * enter a full artifact; the four excluded streams are transient, derived, or leases. */
6
+ export function spaceBackupInventory(space) {
7
+ const registry = `KV_${channelBucket(space)}`;
8
+ const backedUp = [
9
+ { name: registry, class: "registry" },
10
+ { name: chatStream(space), class: "messages" },
11
+ { name: dmStream(space), class: "messages" },
12
+ { name: taskStream(space), class: "messages" },
13
+ { name: inboxStream(space), class: "messages" },
14
+ { name: dlvStream(space), class: "messages" },
15
+ { name: `KV_${aclBucket(space)}`, class: "authorization" },
16
+ { name: `KV_${membersBucket(space)}`, class: "authorization" },
17
+ ];
18
+ const excluded = [
19
+ { name: `KV_${presenceBucket(space)}`, class: "transient" },
20
+ { name: `KV_${membershipBucket(space)}`, class: "derived" },
21
+ { name: `KV_${deliveryBucket(space)}`, class: "lease" },
22
+ { name: `KV_${managerBucket(space)}`, class: "lease" },
23
+ ];
24
+ return {
25
+ backedUp,
26
+ excluded,
27
+ full: backedUp.map((s) => s.name),
28
+ registry: [registry],
29
+ };
30
+ }
31
+ /** Reject a missing, foreign, or additional stream before selecting artifact components. */
32
+ export function validateSpaceBackupInventory(space, actualNames) {
33
+ const inventory = spaceBackupInventory(space);
34
+ const expected = [...inventory.full, ...inventory.excluded.map((s) => s.name)].sort();
35
+ const actual = [...actualNames].sort();
36
+ if (new Set(actual).size !== actual.length)
37
+ throw new Error("space backup inventory contains duplicate stream names");
38
+ if (JSON.stringify(actual) !== JSON.stringify(expected)) {
39
+ const expectedSet = new Set(expected);
40
+ const actualSet = new Set(actual);
41
+ const missing = expected.filter((name) => !actualSet.has(name));
42
+ const unexpected = actual.filter((name) => !expectedSet.has(name));
43
+ throw new Error(`space backup inventory mismatch: missing [${missing.join(", ")}], unexpected [${unexpected.join(", ")}]`);
44
+ }
45
+ return inventory;
46
+ }
47
+ const DEFAULT_DUPLICATE_WINDOW = nanos(2 * 60 * 1000);
48
+ export const BACKUP_MAX_MSGS_PER_SUBJECT = 1000;
49
+ export const BACKUP_PLANE3_DEDUP_WINDOW_MS = 2 * 60 * 60 * 1000;
50
+ const PLANE3_DUPLICATE_WINDOW = nanos(BACKUP_PLANE3_DEDUP_WINDOW_MS);
51
+ function baseConfig(name, subjects) {
52
+ return {
53
+ name,
54
+ subjects,
55
+ retention: RetentionPolicy.Limits,
56
+ storage: StorageType.File,
57
+ max_consumers: -1,
58
+ max_msgs: -1,
59
+ max_bytes: -1,
60
+ max_age: 0,
61
+ max_msgs_per_subject: -1,
62
+ max_msg_size: -1,
63
+ discard: DiscardPolicy.Old,
64
+ num_replicas: 1,
65
+ no_ack: false,
66
+ duplicate_window: DEFAULT_DUPLICATE_WINDOW,
67
+ compression: StoreCompression.None,
68
+ allow_direct: false,
69
+ mirror_direct: false,
70
+ discard_new_per_subject: false,
71
+ allow_rollup_hdrs: false,
72
+ deny_delete: false,
73
+ deny_purge: false,
74
+ sealed: false,
75
+ consumer_limits: {},
76
+ };
77
+ }
78
+ /** Current canonical config for one of the eight backed-up streams. Restore callers must use this
79
+ * config, not the config embedded in untrusted snapshot bytes. */
80
+ export function canonicalBackupStreamConfig(space, stream) {
81
+ const p = spacePrefix(space);
82
+ if (stream === chatStream(space)) {
83
+ return {
84
+ ...baseConfig(stream, [`${p}.chat.>`]),
85
+ max_msgs_per_subject: BACKUP_MAX_MSGS_PER_SUBJECT,
86
+ allow_direct: true,
87
+ };
88
+ }
89
+ if (stream === dmStream(space))
90
+ return baseConfig(stream, [`${p}.inst.>`]);
91
+ if (stream === taskStream(space)) {
92
+ return { ...baseConfig(stream, [`${p}.svc.>`]), retention: RetentionPolicy.Workqueue };
93
+ }
94
+ if (stream === inboxStream(space)) {
95
+ return {
96
+ ...baseConfig(stream, [`${p}.dinbox.>`]),
97
+ max_msgs_per_subject: BACKUP_MAX_MSGS_PER_SUBJECT,
98
+ duplicate_window: PLANE3_DUPLICATE_WINDOW,
99
+ };
100
+ }
101
+ if (stream === dlvStream(space)) {
102
+ return {
103
+ ...baseConfig(stream, [`${p}.dlv.>`]),
104
+ max_msgs_per_subject: BACKUP_MAX_MSGS_PER_SUBJECT,
105
+ duplicate_window: PLANE3_DUPLICATE_WINDOW,
106
+ };
107
+ }
108
+ for (const bucket of [channelBucket(space), aclBucket(space), membersBucket(space)]) {
109
+ if (stream === `KV_${bucket}`) {
110
+ return {
111
+ ...baseConfig(stream, [`$KV.${bucket}.>`]),
112
+ max_msgs_per_subject: 1,
113
+ discard: DiscardPolicy.New,
114
+ allow_direct: true,
115
+ allow_rollup_hdrs: true,
116
+ };
117
+ }
118
+ }
119
+ throw new Error(`stream ${JSON.stringify(stream)} is not a backed-up stream for space ${JSON.stringify(space)}`);
120
+ }
121
+ const INERT_CONFIG_DEFAULTS = {
122
+ description: "",
123
+ template_owner: "",
124
+ first_seq: 0,
125
+ placement: null,
126
+ mirror: null,
127
+ sources: [],
128
+ subject_transform: null,
129
+ republish: null,
130
+ metadata: {},
131
+ allow_msg_ttl: false,
132
+ subject_delete_marker_ttl: 0,
133
+ allow_msg_schedules: false,
134
+ allow_atomic: false,
135
+ allow_batched: false,
136
+ allow_msg_counter: false,
137
+ persist_mode: "",
138
+ };
139
+ function normalize(value) {
140
+ if (Array.isArray(value))
141
+ return value.map(normalize);
142
+ if (value && typeof value === "object") {
143
+ return Object.fromEntries(Object.entries(value)
144
+ .sort(([a], [b]) => a.localeCompare(b))
145
+ .map(([key, item]) => [key, normalize(item)]));
146
+ }
147
+ return value;
148
+ }
149
+ /** Validate every active and security-sensitive stream setting, including explicit rejection of
150
+ * mirrors, sources, transforms, republish, placement, sealing, metadata, and future active features. */
151
+ export function validateCanonicalBackupStreamConfig(space, stream, actual) {
152
+ const expected = canonicalBackupStreamConfig(space, stream);
153
+ const known = new Set([...Object.keys(expected), ...Object.keys(INERT_CONFIG_DEFAULTS)]);
154
+ const unknown = Object.keys(actual).filter((key) => !known.has(key));
155
+ if (unknown.length)
156
+ throw new Error(`${stream} config has unsupported fields: ${unknown.sort().join(", ")}`);
157
+ const comparable = {};
158
+ for (const [key, expectedValue] of Object.entries(expected))
159
+ comparable[key] = actual[key] === undefined ? expectedValue : actual[key];
160
+ for (const [key, expectedValue] of Object.entries(INERT_CONFIG_DEFAULTS)) {
161
+ const actualValue = actual[key];
162
+ comparable[key] = actualValue === undefined || actualValue === null ? expectedValue : actualValue;
163
+ }
164
+ // Newer servers annotate a request-level floor in their reserved metadata namespace. It is
165
+ // server-owned protocol bookkeeping, not caller configuration; no other metadata is canonical.
166
+ if (comparable.metadata &&
167
+ typeof comparable.metadata === "object" &&
168
+ !Array.isArray(comparable.metadata) &&
169
+ Object.entries(comparable.metadata)
170
+ .every(([key, value]) => key.startsWith("_nats.") && typeof value === "string"))
171
+ comparable.metadata = {};
172
+ const target = { ...expected, ...INERT_CONFIG_DEFAULTS };
173
+ if (JSON.stringify(normalize(comparable)) !== JSON.stringify(normalize(target))) {
174
+ const drift = Object.keys(target).filter((key) => JSON.stringify(normalize(comparable[key])) !== JSON.stringify(normalize(target[key])));
175
+ throw new Error(`${stream} config is not canonical: ${drift.map((key) => `${key}=${JSON.stringify(comparable[key])}`).join(", ")}`);
176
+ }
177
+ return expected;
178
+ }
179
+ export function validateBackupStreamState(state) {
180
+ const allowed = new Set([
181
+ "messages", "bytes", "first_seq", "last_seq", "consumer_count", "first_ts", "last_ts",
182
+ "deleted", "num_deleted", "num_subjects", "subjects", "lost",
183
+ ]);
184
+ const unknown = Object.keys(state).filter((key) => !allowed.has(key));
185
+ if (unknown.length)
186
+ throw new Error(`stream state has unsupported fields: ${unknown.sort().join(", ")}`);
187
+ for (const key of ["messages", "bytes", "first_seq", "last_seq", "consumer_count"]) {
188
+ const value = state[key];
189
+ if (!Number.isSafeInteger(value) || value < 0)
190
+ throw new Error(`stream state ${key} must be a non-negative safe integer`);
191
+ }
192
+ const messages = state.messages;
193
+ const firstSequence = state.first_seq;
194
+ const lastSequence = state.last_seq;
195
+ if (messages === 0) {
196
+ const initial = firstSequence === 0 && lastSequence === 0;
197
+ const exhausted = lastSequence < Number.MAX_SAFE_INTEGER && firstSequence === lastSequence + 1;
198
+ if (!initial && !exhausted)
199
+ throw new Error("empty stream state must be initial or exhausted at last_seq + 1");
200
+ }
201
+ else {
202
+ if (firstSequence < 1 || firstSequence > lastSequence)
203
+ throw new Error("non-empty stream state has an invalid first/last sequence window");
204
+ if (messages > lastSequence - firstSequence + 1)
205
+ throw new Error("stream state messages exceed its first/last sequence window");
206
+ }
207
+ for (const seq of state.deleted ?? [])
208
+ if (!Number.isSafeInteger(seq) || seq < 1)
209
+ throw new Error("stream state deleted sequences must be positive safe integers");
210
+ for (const key of ["num_deleted", "num_subjects"]) {
211
+ const value = state[key];
212
+ if (value !== undefined && (!Number.isSafeInteger(value) || value < 0))
213
+ throw new Error(`stream state ${key} must be a non-negative safe integer`);
214
+ }
215
+ for (const key of ["first_ts", "last_ts"]) {
216
+ const value = state[key];
217
+ if (value !== undefined && (typeof value !== "string" || Number.isNaN(Date.parse(value))))
218
+ throw new Error(`stream state ${key} must be an ISO timestamp`);
219
+ }
220
+ if (state.subjects !== undefined) {
221
+ if (!state.subjects || typeof state.subjects !== "object" || Array.isArray(state.subjects))
222
+ throw new Error("stream state subjects must be an object");
223
+ for (const count of Object.values(state.subjects))
224
+ if (!Number.isSafeInteger(count) || count < 0)
225
+ throw new Error("stream state subject counts must be non-negative safe integers");
226
+ }
227
+ if (state.lost !== undefined) {
228
+ if (!state.lost || typeof state.lost !== "object" || Array.isArray(state.lost))
229
+ throw new Error("stream state lost must be an object");
230
+ const lost = state.lost;
231
+ const lostUnknown = Object.keys(lost).filter((key) => key !== "msgs" && key !== "bytes");
232
+ if (lostUnknown.length)
233
+ throw new Error(`stream state lost has unsupported fields: ${lostUnknown.join(", ")}`);
234
+ if (lost.bytes !== undefined && (!Number.isSafeInteger(lost.bytes) || lost.bytes < 0))
235
+ throw new Error("stream state lost.bytes must be a non-negative safe integer");
236
+ if (lost.msgs !== undefined && lost.msgs !== null) {
237
+ if (!Array.isArray(lost.msgs) || lost.msgs.some((seq) => !Number.isSafeInteger(seq) || seq < 1))
238
+ throw new Error("stream state lost.msgs must contain positive safe integers");
239
+ }
240
+ }
241
+ return state;
242
+ }
243
+ //# sourceMappingURL=backup-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backup-config.js","sourceRoot":"","sources":["../src/backup-config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,eAAe,EACf,WAAW,EACX,gBAAgB,GAEjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EACL,SAAS,EACT,aAAa,EACb,UAAU,EACV,cAAc,EACd,SAAS,EACT,QAAQ,EACR,WAAW,EACX,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,WAAW,EACX,UAAU,GACX,MAAM,eAAe,CAAC;AAuBvB;yFACyF;AACzF,MAAM,UAAU,oBAAoB,CAAC,KAAa;IAChD,MAAM,QAAQ,GAAG,MAAM,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;IAC9C,MAAM,QAAQ,GAAwB;QACpC,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE;QACrC,EAAE,IAAI,EAAE,UAAU,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE;QAC9C,EAAE,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE;QAC5C,EAAE,IAAI,EAAE,UAAU,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE;QAC9C,EAAE,IAAI,EAAE,WAAW,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE;QAC/C,EAAE,IAAI,EAAE,SAAS,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE;QAC7C,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC,KAA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AC,IAAI,CAAC;YAC5E,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;QACzD,MAAM,IAAI,GAAG,KAAK,CAAC,IAA+B,CAAC;QACnD,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,KAAK,MAAM,IAAI,GAAG,KAAK,OAAO,CAAC,CAAC;QACzF,IAAI,WAAW,CAAC,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,6CAA6C,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC/G,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS,IAAI,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,IAAK,IAAI,CAAC,KAAgB,GAAG,CAAC,CAAC;YAC/F,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAC;QACjF,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;YAClD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,CAAC;gBAC7F,MAAM,IAAI,KAAK,CAAC,4DAA4D,CAAC,CAAC;QAClF,CAAC;IACH,CAAC;IACD,OAAO,KAAqC,CAAC;AAC/C,CAAC"}
@@ -0,0 +1,86 @@
1
+ import { type ConsumerConfig, type ConsumerInfo } from "@nats-io/jetstream";
2
+ import { type NatsConnection } from "@nats-io/transport-node";
3
+ import { type BackupStreamState, type SpaceBackupSelection } from "./backup-config.js";
4
+ export declare class JetStreamBackupError extends Error {
5
+ readonly code?: number | undefined;
6
+ readonly errCode?: number | undefined;
7
+ constructor(message: string, code?: number | undefined, errCode?: number | undefined);
8
+ }
9
+ export interface StreamSnapshotMetadata {
10
+ config: Record<string, unknown>;
11
+ state: BackupStreamState;
12
+ }
13
+ export interface DownloadStreamSnapshotOptions {
14
+ deliverSubject: string;
15
+ onChunk(chunk: Uint8Array): void | Promise<void>;
16
+ timeoutMs?: number;
17
+ /** Per-chunk sink deadline. Must stay below the server's two-second snapshot flow timeout. */
18
+ sinkTimeoutMs?: number;
19
+ checkMessages?: boolean;
20
+ }
21
+ /** Download a no-consumer native snapshot through one ordered, deadline-bounded sink. Each ackable
22
+ * binary chunk is ACKed only after its sink call succeeds. Completion requires a clean empty EOF
23
+ * after all accepted chunks. */
24
+ export declare function downloadStreamSnapshot(nc: NatsConnection, stream: string, opts: DownloadStreamSnapshotOptions): Promise<StreamSnapshotMetadata>;
25
+ export interface StreamRestoreSession {
26
+ stream: string;
27
+ deliverSubject: string;
28
+ }
29
+ /** Initiate restore with caller-supplied, current canonical config and separately validated state.
30
+ * Snapshot-embedded config is never trusted or sent to the target broker. */
31
+ export declare function initiateStreamRestore(nc: NatsConnection, space: string, stream: string, config: Readonly<Record<string, unknown>>, state: Readonly<Record<string, unknown>>, timeoutMs?: number): Promise<StreamRestoreSession>;
32
+ /** Upload one non-empty binary restore chunk and await the server's storage ACK. */
33
+ export declare function uploadStreamRestoreChunk(nc: NatsConnection, session: StreamRestoreSession, chunk: Uint8Array, timeoutMs?: number): Promise<void>;
34
+ export interface StreamRestoreResult {
35
+ config: Record<string, unknown>;
36
+ state: BackupStreamState;
37
+ }
38
+ /** Send the empty EOF request and require the final stream-create response. */
39
+ export declare function finalizeStreamRestore(nc: NatsConnection, session: StreamRestoreSession, timeoutMs?: number): Promise<StreamRestoreResult>;
40
+ export interface PersistentConsumerCheckpoint {
41
+ stream: string;
42
+ name: string;
43
+ ackFloorStreamSequence: number;
44
+ creationLowerBound: number;
45
+ streamState: Pick<BackupStreamState, "messages" | "first_seq" | "last_seq">;
46
+ }
47
+ /** Validate one recognized Cotal pull durable. Limits-retention consumers accept the checkpoint
48
+ * migration shape; TASK remains canonical WorkQueue DeliverAll. */
49
+ export declare function validatePersistentConsumer(space: string, stream: string, info: ConsumerInfo): void;
50
+ /** Validate the complete consumer inventory for all eight streams and extract conservative checkpoints. */
51
+ export declare function validatePersistentConsumerInventory(space: string, consumersByStream: Readonly<Record<string, readonly ConsumerInfo[]>>, statesByStream: Readonly<Record<string, BackupStreamState>>): PersistentConsumerCheckpoint[];
52
+ /** Recreate a validated pull durable. Limits-retention consumers start after the contiguous ACK
53
+ * floor and original lower bound; TASK uses WorkQueue DeliverAll because ACKed entries left the stream. */
54
+ export declare function consumerConfigFromCheckpoint(space: string, checkpoint: PersistentConsumerCheckpoint): Partial<ConsumerConfig>;
55
+ /** Recreate one validated checkpoint through the NATS 2.10 extended create API, whose subject pins
56
+ * stream, durable name, and its canonical single filter. */
57
+ export declare function recreateConsumerCheckpoint(nc: NatsConnection, space: string, checkpoint: PersistentConsumerCheckpoint, timeoutMs?: number): Promise<ConsumerInfo>;
58
+ export type BackupPermissionScope = {
59
+ operation: "snapshot";
60
+ stream: string;
61
+ deliverSubject: string;
62
+ } | {
63
+ operation: "inspect";
64
+ selection: SpaceBackupSelection;
65
+ };
66
+ export type RestorePermissionScope = {
67
+ operation: "initiate";
68
+ stream: string;
69
+ } | {
70
+ operation: "upload";
71
+ stream: string;
72
+ deliverSubject: string;
73
+ } | {
74
+ operation: "validate";
75
+ stream: string;
76
+ } | {
77
+ operation: "checkpoint";
78
+ checkpoint: PersistentConsumerCheckpoint;
79
+ };
80
+ /** Exact snapshot permission set. It has no stream read/admin verbs beyond one snapshot API; chunk
81
+ * ACK authority is created dynamically for the exact reply received, never granted as a wildcard. */
82
+ export declare function backupProfilePermissions(space: string, connId: string, scope: BackupPermissionScope): Record<string, unknown>;
83
+ /** Restore initiation, exact-ID upload, stream validation, and one-checkpoint recreation are disjoint
84
+ * credentials. No phase inherits a body-read verb or another phase's mutation authority. */
85
+ export declare function restoreProfilePermissions(space: string, connId: string, scope: RestorePermissionScope): Record<string, unknown>;
86
+ //# sourceMappingURL=backup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backup.d.ts","sourceRoot":"","sources":["../src/backup.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,cAAc,EACnB,KAAK,YAAY,EAClB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAmB,KAAK,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC/E,OAAO,EAKL,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EAC1B,MAAM,oBAAoB,CAAC;AA2B5B,qBAAa,oBAAqB,SAAQ,KAAK;IAChB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM;IAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM;gBAAlE,OAAO,EAAE,MAAM,EAAW,IAAI,CAAC,EAAE,MAAM,YAAA,EAAW,OAAO,CAAC,EAAE,MAAM,YAAA;CAI/E;AAED,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,KAAK,EAAE,iBAAiB,CAAC;CAC1B;AAED,MAAM,WAAW,6BAA6B;IAC5C,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,8FAA8F;IAC9F,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAwDD;;gCAEgC;AAChC,wBAAsB,sBAAsB,CAC1C,EAAE,EAAE,cAAc,EAClB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,6BAA6B,GAClC,OAAO,CAAC,sBAAsB,CAAC,CA+GjC;AAED,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,C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