@sparkvault/sdk-js 15.7.1 → 15.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.
@@ -10,6 +10,7 @@ import { HttpClient } from '../http';
10
10
  import { IdentityModule } from './identity';
11
11
  import { NotifyProductModule } from './notify';
12
12
  import { HelpDeskModule } from './help-desk';
13
+ import { StructuredIngotsModule } from './structured-ingots';
13
14
  export declare class ProductsModule {
14
15
  /** Identity verification product (passkey, OTP, SparkLink, social). */
15
16
  readonly identity: IdentityModule;
@@ -21,6 +22,8 @@ export declare class ProductsModule {
21
22
  readonly notify: NotifyProductModule;
22
23
  /** Customer-only help desk API and optional injected ticket form. */
23
24
  readonly helpDesk: HelpDeskModule;
25
+ /** Encrypted structured records, optional types, and retained object history. */
26
+ readonly structuredIngots: StructuredIngotsModule;
24
27
  /**
25
28
  * `http` defaults to a client over the same resolved config so constructing
26
29
  * this module standalone stays a one-argument call.
@@ -30,6 +33,8 @@ export declare class ProductsModule {
30
33
  export { IdentityModule } from './identity';
31
34
  export { NotifyProductModule, NotifyProjectsModule, NOTIFY_PRESETS, buildNotifyPresetSend } from './notify';
32
35
  export { HelpDeskModule, HelpDeskClient } from './help-desk';
36
+ export { StructuredIngotsModule, StructuredIngotTypesModule } from './structured-ingots';
37
+ export type * from './structured-ingots/types';
33
38
  export type * from './help-desk/types';
34
39
  export type * from './help-desk/form-types';
35
40
  export type * from './help-desk/support-types';
@@ -0,0 +1,33 @@
1
+ import { HttpClient } from '../../http';
2
+ import type { UnsealedVault } from '../../vaults/types';
3
+ import { StructuredIngotTypesModule } from './types-client';
4
+ import type { BatchGetStructuredIngotsOptions, CreateStructuredIngotOptions, GetStructuredIngotOptions, ImportStructuredIngotsOptions, PatchStructuredIngotOptions, PortableStructuredIngot, StructuredExportOutcome, StructuredImportOutcome, StructuredIngot, StructuredIngotHistory, StructuredIngotMutation, StructuredIngotSummary, StructuredIterateOptions, StructuredPage, StructuredPageOptions, StructuredReadOutcome, StructuredValues, StructuredAccountActivity, StructuredActivityOptions, StructuredVaultActivity } from './types';
5
+ /** Typed record operations using the caller's existing account and vault session. */
6
+ export declare class StructuredIngotsModule {
7
+ private readonly http;
8
+ readonly types: StructuredIngotTypesModule;
9
+ constructor(http: HttpClient);
10
+ /** Approximate account activity; requires an account credential, not a scoped service key. */
11
+ activity(options?: StructuredActivityOptions): Promise<StructuredAccountActivity>;
12
+ /** Approximate operational counters for one authorized, unsealed vault. */
13
+ vaultActivity(vault: UnsealedVault, options?: StructuredActivityOptions): Promise<StructuredVaultActivity>;
14
+ get<T extends object = StructuredValues>(vault: UnsealedVault, ref: string, options?: GetStructuredIngotOptions): Promise<StructuredIngot<T>>;
15
+ list(vault: UnsealedVault, options?: StructuredPageOptions): Promise<StructuredPage<StructuredIngotSummary>>;
16
+ iterate(vault: UnsealedVault, options?: StructuredIterateOptions): AsyncGenerator<StructuredIngotSummary>;
17
+ /** Names use the server's documented Unicode caseless matching rules. */
18
+ create<T extends object = StructuredValues>(vault: UnsealedVault, options: CreateStructuredIngotOptions<T>): Promise<StructuredIngotMutation>;
19
+ patch<T extends object = StructuredValues>(vault: UnsealedVault, ref: string, options: PatchStructuredIngotOptions<T>): Promise<StructuredIngotMutation>;
20
+ delete(vault: UnsealedVault, ref: string): Promise<void>;
21
+ history(vault: UnsealedVault, ref: string): Promise<StructuredIngotHistory>;
22
+ restore(vault: UnsealedVault, ref: string, versionId: string, options: {
23
+ expectedVersion: number;
24
+ }): Promise<StructuredIngotMutation>;
25
+ /** Bounded parallel reads with independent, ordered success/error outcomes. */
26
+ batchGet<T extends object = StructuredValues>(vault: UnsealedVault, refs: string[], options?: BatchGetStructuredIngotsOptions): Promise<StructuredReadOutcome<T>[]>;
27
+ /** Sequential record reads, not a transactionally consistent vault snapshot. */
28
+ exportRecords(vault: UnsealedVault, options?: StructuredIterateOptions): AsyncGenerator<StructuredExportOutcome>;
29
+ /** Imports create records. Existing names fail; typed imports need explicit mapping. */
30
+ importRecords(vault: UnsealedVault, records: AsyncIterable<PortableStructuredIngot> | Iterable<PortableStructuredIngot>, options?: ImportStructuredIngotsOptions): AsyncGenerator<StructuredImportOutcome>;
31
+ }
32
+ export { StructuredIngotTypesModule } from './types-client';
33
+ export type * from './types';
@@ -0,0 +1,19 @@
1
+ import { HttpClient } from '../../http';
2
+ import type { UnsealedVault } from '../../vaults/types';
3
+ import type { CreateStructuredTypeOptions, PublishStructuredTypeOptions, StructuredIterateOptions, StructuredPage, StructuredPageOptions, StructuredTypeDefinition, StructuredTypeCreation, StructuredTypeSummary } from './types';
4
+ /** Definitions live inside the same encrypted vault as the records they validate. */
5
+ export declare class StructuredIngotTypesModule {
6
+ private readonly http;
7
+ constructor(http: HttpClient);
8
+ list(vault: UnsealedVault, options?: StructuredPageOptions): Promise<StructuredPage<StructuredTypeSummary>>;
9
+ iterate(vault: UnsealedVault, options?: StructuredIterateOptions): AsyncGenerator<StructuredTypeSummary>;
10
+ get(vault: UnsealedVault, typeId: string, options?: {
11
+ version?: number;
12
+ }): Promise<StructuredTypeDefinition>;
13
+ create(vault: UnsealedVault, options: CreateStructuredTypeOptions): Promise<StructuredTypeCreation>;
14
+ publish(vault: UnsealedVault, typeId: string, options: PublishStructuredTypeOptions): Promise<StructuredTypeDefinition>;
15
+ archive(vault: UnsealedVault, typeId: string): Promise<{
16
+ typeId: string;
17
+ archived: true;
18
+ }>;
19
+ }
@@ -0,0 +1,279 @@
1
+ /** JSON values travel without implicit coercion. Binary leaves use explicit paths. */
2
+ export type StructuredJsonValue = null | boolean | number | string | StructuredJsonValue[] | {
3
+ [key: string]: StructuredJsonValue;
4
+ };
5
+ export type StructuredValues = Record<string, StructuredJsonValue>;
6
+ export type StructuredBinaryPath = Array<string | number>;
7
+ export interface StructuredTypePin {
8
+ typeId: string;
9
+ version: number;
10
+ }
11
+ export interface StructuredPageOptions {
12
+ limit?: number;
13
+ cursor?: string;
14
+ }
15
+ export interface StructuredIterateOptions extends StructuredPageOptions {
16
+ /** Bound continuation tracking; default 10,000 pages, maximum 100,000. */
17
+ maxPages?: number;
18
+ }
19
+ export interface StructuredPage<T> {
20
+ items: T[];
21
+ count: number;
22
+ nextCursor: string | null;
23
+ hasMore: boolean;
24
+ }
25
+ export interface StructuredIngotSummary {
26
+ id: string;
27
+ name: string;
28
+ sizeBytes: number;
29
+ createdAt: number;
30
+ updatedAt: number | null;
31
+ }
32
+ export interface StructuredIngot<T extends object = StructuredValues> {
33
+ id: string;
34
+ name: string;
35
+ version: number;
36
+ keyCount: number;
37
+ values: T;
38
+ missingKeys: string[];
39
+ /** Each path identifies a base64 string representing binary bytes. */
40
+ binaryPaths: StructuredBinaryPath[];
41
+ type: StructuredTypePin | null;
42
+ createdAt: number;
43
+ updatedAt: number;
44
+ }
45
+ export interface StructuredIngotMutation {
46
+ id: string;
47
+ version: number;
48
+ keyCount: number;
49
+ type: StructuredTypePin | null;
50
+ createdAt?: number;
51
+ updatedAt?: number;
52
+ created?: boolean;
53
+ /** A creation receipt replay; its version is not a fresh read of current content. */
54
+ replayed?: boolean;
55
+ }
56
+ export interface GetStructuredIngotOptions {
57
+ keys?: string[];
58
+ }
59
+ export interface CreateStructuredIngotOptions<T extends object = StructuredValues> {
60
+ name: string;
61
+ data: T;
62
+ type?: StructuredTypePin | null;
63
+ binaryPaths?: StructuredBinaryPath[];
64
+ /** 8–128 printable ASCII characters; bound to this name and semantic payload. */
65
+ idempotencyKey?: string;
66
+ }
67
+ export interface PatchStructuredIngotOptions<T extends object = StructuredValues> {
68
+ expectedVersion: number;
69
+ set?: Partial<T>;
70
+ delete?: string[];
71
+ /** Omitted preserves the current type; null explicitly removes it. */
72
+ type?: StructuredTypePin | null;
73
+ /** Paths are relative to the `set` object. */
74
+ binaryPaths?: StructuredBinaryPath[];
75
+ }
76
+ export interface StructuredIngotVersion {
77
+ versionId: string;
78
+ publishedAt: number;
79
+ sizeBytes: number;
80
+ }
81
+ export interface StructuredIngotHistory {
82
+ id: string;
83
+ versionLimit: number;
84
+ versions: StructuredIngotVersion[];
85
+ }
86
+ export type StructuredActivityPeriod = '24h' | '7d';
87
+ export interface StructuredActivityOptions {
88
+ period?: StructuredActivityPeriod;
89
+ }
90
+ export interface StructuredActivityTotals {
91
+ requests: number;
92
+ reads: number;
93
+ writes: number;
94
+ errors: number;
95
+ conflicts: number;
96
+ averageLatencyMs: number | null;
97
+ p95UpperBoundMs: number | null;
98
+ p95Overflow: boolean;
99
+ }
100
+ export interface StructuredActivity {
101
+ period: StructuredActivityPeriod;
102
+ interval: 'hour' | 'day';
103
+ asOf: number;
104
+ windowStart: number;
105
+ windowEnd: number;
106
+ totals: StructuredActivityTotals;
107
+ series: Array<StructuredActivityTotals & {
108
+ start: number;
109
+ end: number;
110
+ }>;
111
+ }
112
+ export interface StructuredAccountActivity extends StructuredActivity {
113
+ scope: 'account';
114
+ }
115
+ export interface StructuredVaultActivity extends StructuredActivity {
116
+ vaultId: string;
117
+ objectCount: number | null;
118
+ vaultStorageBytes: number;
119
+ }
120
+ export interface StructuredTypeTransform {
121
+ /** JSON Pointer to a field; transformations are explicit and ordered. */
122
+ path: string;
123
+ operations: Array<'trim' | 'lowercase' | 'uppercase'>;
124
+ }
125
+ export interface StructuredTypeSummary {
126
+ typeId: string;
127
+ name: string;
128
+ createdAt: number;
129
+ updatedAt: number | null;
130
+ }
131
+ export interface StructuredTypeDefinition extends StructuredTypeSummary {
132
+ version: number;
133
+ latestVersion: number;
134
+ archived: boolean;
135
+ schema: StructuredValues;
136
+ transforms: StructuredTypeTransform[];
137
+ }
138
+ export interface StructuredTypeCreation extends StructuredTypeDefinition {
139
+ created: boolean;
140
+ /** Original version-one receipt; use types.get for current metadata. */
141
+ replayed?: boolean;
142
+ }
143
+ export interface CreateStructuredTypeOptions {
144
+ name: string;
145
+ schema: StructuredValues;
146
+ transforms?: StructuredTypeTransform[];
147
+ /** 8–128 printable ASCII characters; bound to this name and definition. */
148
+ idempotencyKey?: string;
149
+ }
150
+ export interface PublishStructuredTypeOptions {
151
+ expectedVersion: number;
152
+ schema: StructuredValues;
153
+ transforms?: StructuredTypeTransform[];
154
+ }
155
+ export type StructuredOutcome<T> = {
156
+ ok: true;
157
+ value: T;
158
+ } | {
159
+ ok: false;
160
+ error: unknown;
161
+ };
162
+ export type StructuredReadOutcome<T extends object = StructuredValues> = StructuredOutcome<StructuredIngot<T>> & {
163
+ ref: string;
164
+ };
165
+ export interface BatchGetStructuredIngotsOptions extends GetStructuredIngotOptions {
166
+ /** Default 4; maximum 8 simultaneous requests. At most 100 references. */
167
+ concurrency?: number;
168
+ }
169
+ export interface PortableStructuredType {
170
+ name: string;
171
+ schema: StructuredValues;
172
+ transforms: StructuredTypeTransform[];
173
+ source: StructuredTypePin;
174
+ }
175
+ export interface PortableStructuredIngot {
176
+ format: 'sparkvault-structured-ingot';
177
+ formatVersion: 1;
178
+ name: string;
179
+ data: StructuredValues;
180
+ binaryPaths: StructuredBinaryPath[];
181
+ type: PortableStructuredType | null;
182
+ source: {
183
+ id: string;
184
+ version: number;
185
+ };
186
+ }
187
+ export type StructuredExportOutcome = {
188
+ ok: true;
189
+ record: PortableStructuredIngot;
190
+ } | {
191
+ ok: false;
192
+ id: string;
193
+ error: unknown;
194
+ };
195
+ export interface ImportStructuredIngotsOptions {
196
+ /** Required for typed records. Resolve or create an explicit destination type. */
197
+ mapType?: (definition: PortableStructuredType) => StructuredTypePin | Promise<StructuredTypePin>;
198
+ /** Return a stable key for retrying this exact record; the SDK never invents one. */
199
+ idempotencyKey?: (record: PortableStructuredIngot) => string | undefined;
200
+ }
201
+ export type StructuredImportOutcome = StructuredOutcome<StructuredIngotMutation> & {
202
+ index: number;
203
+ name: string | null;
204
+ };
205
+ export interface StructuredTypePinWire {
206
+ type_id: string;
207
+ version: number;
208
+ }
209
+ export interface StructuredIngotSummaryWire {
210
+ ingot_id: string;
211
+ name: string;
212
+ size_bytes: number;
213
+ created_at: number;
214
+ updated_at?: number | null;
215
+ }
216
+ export interface StructuredIngotWire<T extends object = StructuredValues> {
217
+ ingot_id: string;
218
+ name: string;
219
+ version: number;
220
+ key_count: number;
221
+ values: T;
222
+ missing_keys: string[];
223
+ binary_paths?: StructuredBinaryPath[];
224
+ binary_keys?: string[];
225
+ type?: StructuredTypePinWire | null;
226
+ inline: boolean;
227
+ created_at: number;
228
+ updated_at: number;
229
+ }
230
+ export interface StructuredMutationWire {
231
+ ingot_id: string;
232
+ version: number;
233
+ key_count: number;
234
+ type?: StructuredTypePinWire | null;
235
+ created_at?: number;
236
+ updated_at?: number;
237
+ created?: boolean;
238
+ replayed?: boolean;
239
+ }
240
+ export interface StructuredTypeSummaryWire {
241
+ type_id: string;
242
+ name: string;
243
+ created_at: number;
244
+ updated_at: number | null;
245
+ }
246
+ export interface StructuredTypeDefinitionWire extends StructuredTypeSummaryWire {
247
+ version: number;
248
+ latest_version: number;
249
+ archived: boolean;
250
+ schema: StructuredValues;
251
+ transforms: StructuredTypeTransform[];
252
+ }
253
+ export interface StructuredPageWire {
254
+ count: number;
255
+ next_cursor?: string | null;
256
+ has_more: boolean;
257
+ }
258
+ export interface StructuredActivityTotalsWire {
259
+ requests: number;
260
+ reads: number;
261
+ writes: number;
262
+ errors: number;
263
+ conflicts: number;
264
+ average_latency_ms: number | null;
265
+ p95_upper_bound_ms: number | null;
266
+ p95_overflow: boolean;
267
+ }
268
+ export interface StructuredActivityWire {
269
+ period: StructuredActivityPeriod;
270
+ interval: 'hour' | 'day';
271
+ as_of: number;
272
+ window_start: number;
273
+ window_end: number;
274
+ totals: StructuredActivityTotalsWire;
275
+ series: Array<StructuredActivityTotalsWire & {
276
+ start: number;
277
+ end: number;
278
+ }>;
279
+ }
@@ -0,0 +1,21 @@
1
+ import type { UnsealedVault } from '../../vaults/types';
2
+ import type { StructuredBinaryPath, StructuredPageOptions, StructuredPageWire, StructuredPage, StructuredTypePin, StructuredTypePinWire } from './types';
3
+ export declare function requireVault(vault: UnsealedVault): string;
4
+ export declare function requireRef(ref: string): string;
5
+ export declare function integer(value: number, field: string, minimum: number, maximum: number): number;
6
+ export declare function expectedVersion(value: number): number;
7
+ export declare function keysQuery(keys: string[] | undefined): string | undefined;
8
+ export declare function pageQuery(options: StructuredPageOptions): {
9
+ limit?: number;
10
+ cursor?: string;
11
+ };
12
+ export declare function page<T>(wire: StructuredPageWire, items: T[]): StructuredPage<T>;
13
+ export declare function wirePin(pin: StructuredTypePin | null | undefined): StructuredTypePinWire | null | undefined;
14
+ export declare function readPin(pin: StructuredTypePinWire | null | undefined): StructuredTypePin | null;
15
+ export declare function validateValues(data: object): void;
16
+ export declare function validateBinaryPaths(paths: StructuredBinaryPath[] | undefined): void;
17
+ export declare function idempotencyHeaders(key: string | undefined): Record<string, string> | undefined;
18
+ /** Empty pages are legitimate; a repeated cursor is never drained forever. */
19
+ export declare function iteratePages<T>(read: (options: StructuredPageOptions) => Promise<StructuredPage<T>>, options?: StructuredPageOptions & {
20
+ maxPages?: number;
21
+ }): AsyncGenerator<T>;
@@ -2,8 +2,8 @@
2
2
  * Sparks Module
3
3
  *
4
4
  * Create, read, share, and delete ephemeral secrets, sealed server-side under
5
- * platform-held keys and read once. Sparks are account-scoped — no vault or
6
- * VAT is involved.
5
+ * platform-held keys and read once. Ordinary Sparks are account-scoped;
6
+ * values derived from Structured Ingots require the source vault's VAT.
7
7
  */
8
8
  import { HttpClient } from '../http';
9
9
  import type { Spark, CreatedSpark, ListSparksOptions, SparkPage, CreateSparkOptions, ShareSparkOptions, SparkLinkActionOptions, SparkShare, SparkInviteResend } from './types';
@@ -20,12 +20,13 @@ export declare class SparksModule {
20
20
  /**
21
21
  * Read (and burn) a spark. Reading is destructive — the spark can be read
22
22
  * exactly once.
23
+ * Supply the source vault's VAT for a Structured Ingots field Spark.
23
24
  *
24
25
  * @example
25
26
  * const spark = await sv.sparks.get('spk_abc');
26
27
  * console.log(spark.payload);
27
28
  */
28
- get(sparkId: string): Promise<Spark>;
29
+ get(sparkId: string, vat?: string): Promise<Spark>;
29
30
  /**
30
31
  * Create a spark. A link spark (contentType text/uri-list, the payload its
31
32
  * destination URL) is created with its x.sv link, `linkUrl`.