@sparkvault/sdk-js 15.7.0 → 15.8.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 +126 -0
- package/dist/index.cjs +4546 -4050
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +353 -6
- package/dist/index.mjs +4545 -4051
- package/dist/index.mjs.map +1 -1
- package/dist/products/help-desk/desk-id.d.ts +1 -1
- package/dist/products/help-desk/support-analytics-types.d.ts +2 -1
- package/dist/products/help-desk/support-analytics.d.ts +0 -1
- package/dist/products/help-desk/support-view.d.ts +0 -3
- package/dist/products/index.d.ts +5 -0
- package/dist/products/structured-ingots/index.d.ts +33 -0
- package/dist/products/structured-ingots/types-client.d.ts +19 -0
- package/dist/products/structured-ingots/types.d.ts +279 -0
- package/dist/products/structured-ingots/validation.d.ts +21 -0
- package/dist/sparks/index.d.ts +4 -3
- package/dist/sparkvault.js +1 -1
- package/dist/sparkvault.js.map +1 -1
- package/dist/vaults/index.d.ts +11 -0
- package/dist/vaults/types.d.ts +12 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
- [Install](#install)
|
|
11
11
|
- [Quickstart: sign in](#quickstart-sign-in)
|
|
12
12
|
- [Modules](#modules)
|
|
13
|
+
- [Structured Ingots](#structured-ingots)
|
|
13
14
|
- [Content Security Policy (CSP)](#content-security-policy-csp)
|
|
14
15
|
- [Browser support](#browser-support)
|
|
15
16
|
- [Build and release](#build-and-release)
|
|
@@ -129,11 +130,136 @@ app.post('/api/auth/login', async (req, res) => {
|
|
|
129
130
|
| `entropy` | Server-generated random values | [Entropy](https://sparkvault.com/api/docs/sdk-js/#reference-entropy) |
|
|
130
131
|
| `notify` | SparkVault's own inbox and Web Push, for a person signed in to SparkVault itself | [Notifications](https://sparkvault.com/api/docs/sdk-js/#reference-notify) |
|
|
131
132
|
| `products.notify` | Your Notify sends, your recipients' inboxes, send history, receipts and config (server-side, with `apiKey`) | [Notify API](https://sparkvault.com/api/docs/products/notify/) |
|
|
133
|
+
| `products.structuredIngots` | Typed secure records, version history, optional Types and streaming import/export | [Structured Ingots](#structured-ingots) |
|
|
132
134
|
| `products.helpDesk` | Customer ticket API, email verification and an optional injected form | [Help Desk](#help-desk) |
|
|
133
135
|
| `health` | API availability | [Health](https://sparkvault.com/api/docs/sdk-js/#health-api-reference) |
|
|
134
136
|
|
|
135
137
|
`products.identity`, `products.helpDesk`, `vaults.upload` and `health` send neither a Core JWT nor an `apiKey`. Help Desk uses only a desk customer session (`hdt_`), with cookies omitted. The upload widget needs the vault's Embedded Upload Widget setting enabled, with or without a `token`: it opens by reading the vault's upload info, a request that carries no VAT and is refused while the setting is off. The other modules call the Core API with a Core JWT (`accessToken` or `getAccessToken`) or, server-side, an `apiKey`; `notify` needs a SparkVault user's session JWT. Configuration, errors and TypeScript: the [reference](https://sparkvault.com/api/docs/sdk-js/#configuration-options).
|
|
136
138
|
|
|
139
|
+
## Structured Ingots
|
|
140
|
+
|
|
141
|
+
Store private application records in a vault, address them by ingot ID or `:name`,
|
|
142
|
+
and read ordinary JSON without a separate Spark redemption step. The SDK works
|
|
143
|
+
in Node and browsers; service API keys and NHI DVAKs belong on your backend.
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
import SparkVault from '@sparkvault/sdk-js';
|
|
147
|
+
|
|
148
|
+
const sv = SparkVault.init({
|
|
149
|
+
accountId: 'acc_YOUR_ACCOUNT_ID',
|
|
150
|
+
apiKey: process.env.SPARKVAULT_API_KEY!,
|
|
151
|
+
preloadConfig: false,
|
|
152
|
+
});
|
|
153
|
+
// A service key is restricted to one vault and read or read/write access.
|
|
154
|
+
// Unseal with an NHI DVAK for that vault; the SDK sends it as dvak_token.
|
|
155
|
+
const vault = await sv.vaults.unseal('vlt_YOUR_VAULT_ID', process.env.SPARKVAULT_NHI_DVAK!);
|
|
156
|
+
const records = sv.products.structuredIngots;
|
|
157
|
+
|
|
158
|
+
interface Profile { email: string; preferences: { contactAllowed: boolean } }
|
|
159
|
+
const profileType = await records.types.create(vault, {
|
|
160
|
+
name: 'profile',
|
|
161
|
+
schema: {
|
|
162
|
+
type: 'object',
|
|
163
|
+
properties: {
|
|
164
|
+
email: { type: 'string', format: 'email' },
|
|
165
|
+
preferences: {
|
|
166
|
+
type: 'object',
|
|
167
|
+
properties: { contactAllowed: { type: 'boolean' } },
|
|
168
|
+
required: ['contactAllowed'],
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
required: ['email', 'preferences'],
|
|
172
|
+
},
|
|
173
|
+
transforms: [{ path: '/email', operations: ['trim', 'lowercase'] }],
|
|
174
|
+
idempotencyKey: 'create-profile-type-v1',
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
await records.create<Profile>(vault, {
|
|
178
|
+
name: 'profile-customer-42',
|
|
179
|
+
data: { email: ' customer@example.com ', preferences: { contactAllowed: false } },
|
|
180
|
+
type: { typeId: profileType.typeId, version: profileType.version },
|
|
181
|
+
idempotencyKey: 'signup-customer-42',
|
|
182
|
+
});
|
|
183
|
+
const profile = await records.get<Profile>(vault, ':profile-customer-42');
|
|
184
|
+
await records.patch<Profile>(vault, profile.id, {
|
|
185
|
+
expectedVersion: profile.version,
|
|
186
|
+
set: { preferences: { contactAllowed: true } },
|
|
187
|
+
});
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
The TypeScript generic describes your expected data; an optional vault Type
|
|
191
|
+
enforces its shape on the server. Types have immutable versions. Use
|
|
192
|
+
`types.list`, `types.get(typeId, { version })`, `types.publish` and `types.archive`
|
|
193
|
+
with the vault as their first argument. Publishing requires `expectedVersion`;
|
|
194
|
+
existing records keep their pin. PATCH retains the pin unless `type` explicitly
|
|
195
|
+
changes it or is `null`. Transforms run before validation of the complete object.
|
|
196
|
+
`types.create` also accepts an optional stable `idempotencyKey` (8–128 printable
|
|
197
|
+
ASCII characters) to safely retry creation of the same named definition. Reuse
|
|
198
|
+
that key with the same schema and ordered transformations; a changed definition
|
|
199
|
+
conflicts. An omitted key keeps creation strict on name collisions.
|
|
200
|
+
A replay returns `created: false`, `replayed: true` and the original version-one
|
|
201
|
+
definition receipt, even if the Type has since been published or archived.
|
|
202
|
+
Call `types.get(vault, typeId)` for its current version and archive state.
|
|
203
|
+
|
|
204
|
+
PATCH and `restore(vault, ref, versionId, { expectedVersion })` require the
|
|
205
|
+
current object version. A concurrent change throws an error with
|
|
206
|
+
`statusCode === 412`; reread and reconcile the change. The SDK never retries a
|
|
207
|
+
mutation automatically. `history(vault, ref)` lists retained publications;
|
|
208
|
+
restore validates historical values against the current Type and creates a new
|
|
209
|
+
version. Configure retention with the vault's `structuredIngotVersionLimit`
|
|
210
|
+
setting. `delete(vault, ref)` deletes an object and its retained publications.
|
|
211
|
+
|
|
212
|
+
Create rejects an existing name; it never overwrites. Names follow the server's
|
|
213
|
+
Unicode caseless matching rules. An optional stable `idempotencyKey` contains
|
|
214
|
+
8–128 printable ASCII characters. A successful replay has `replayed: true` and
|
|
215
|
+
returns the original creation receipt, including its original version. Call
|
|
216
|
+
`get` when you need the object's current version. A different payload under the
|
|
217
|
+
same key fails. The name/key binding ends when the object is deleted or renamed.
|
|
218
|
+
Retries still require current authorization and an assignable Type. If that
|
|
219
|
+
Type has since been archived, use `get` to confirm the existing object.
|
|
220
|
+
|
|
221
|
+
`get(vault, ref, { keys: ['email'] })` projects exact top-level field names;
|
|
222
|
+
missing fields appear in `missingKeys`. An empty `keys` array is an empty
|
|
223
|
+
projection; omitting it reads the whole object. Values preserve JSON numbers,
|
|
224
|
+
booleans, nulls, arrays and nested objects. Binary leaves are explicit base64
|
|
225
|
+
strings identified by `binaryPaths`, for example
|
|
226
|
+
`{ data: { avatar: 'AAE=' }, binaryPaths: [['avatar']] }` on create. PATCH paths
|
|
227
|
+
are relative to `set`. No object shape is interpreted as a binary wrapper or
|
|
228
|
+
Spark reference. Invalid JSON values, including non-finite numbers and
|
|
229
|
+
`undefined`, fail before serialization.
|
|
230
|
+
|
|
231
|
+
`activity({ period: '24h' })` reads account activity using an account credential;
|
|
232
|
+
a vault-scoped service key cannot access account totals.
|
|
233
|
+
`vaultActivity(vault, { period: '7d' })` reads one vault's activity using its VAT.
|
|
234
|
+
Both return approximate request/read/write/error/conflict counts, latency
|
|
235
|
+
summaries and fixed UTC hour or day buckets. Latency estimates may be `null`;
|
|
236
|
+
`p95Overflow` identifies a percentile beyond the highest histogram bound. The
|
|
237
|
+
vault response also includes `objectCount` (`null` while unknown) and
|
|
238
|
+
`vaultStorageBytes`. Activity contains operational metadata, not object values.
|
|
239
|
+
|
|
240
|
+
`list(vault, { limit, cursor })` returns `{ items, count, nextCursor, hasMore }`.
|
|
241
|
+
The default page size is 25 and the maximum is 200. `iterate(vault, options)` is
|
|
242
|
+
an async iterator that follows empty continuation pages and rejects repeated
|
|
243
|
+
cursors; `maxPages` defaults to 10,000. `batchGet(vault, refs, { concurrency })`
|
|
244
|
+
accepts at most 100 references, defaults to four parallel reads and allows at
|
|
245
|
+
most eight. Its ordered outcomes have either `{ ref, ok: true, value }` or
|
|
246
|
+
`{ ref, ok: false, error }`.
|
|
247
|
+
|
|
248
|
+
`exportRecords(vault)` yields one `{ ok: true, record }` or
|
|
249
|
+
`{ ok: false, id, error }` at a time. Portable format version 1 includes `name`,
|
|
250
|
+
`data`, `binaryPaths`, the full pinned Type definition (or `null`), and source
|
|
251
|
+
ID/version. This is a sequence of reads, not a transactional snapshot; records
|
|
252
|
+
may change during export. A page-read failure terminates the iterator. The
|
|
253
|
+
caller chooses the encrypted destination and whether to persist any plaintext.
|
|
254
|
+
|
|
255
|
+
`importRecords(destinationVault, asyncRecords, options)` consumes portable
|
|
256
|
+
records one at a time and yields independent indexed outcomes. It only creates;
|
|
257
|
+
conflicting names fail. Typed records require an explicit
|
|
258
|
+
`mapType(definition) => { typeId, version }` callback to resolve or create the
|
|
259
|
+
destination Type. Types are never silently removed or rebound. An optional
|
|
260
|
+
`idempotencyKey(record)` callback supplies stable retry keys. Neither operation
|
|
261
|
+
loads a whole vault into memory.
|
|
262
|
+
|
|
137
263
|
## Notify projects
|
|
138
264
|
|
|
139
265
|
Use a named project for each separately operated product, brand or notification
|