@sparkvault/sdk-js 15.9.0 → 15.10.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 +36 -6
- package/dist/index.cjs +277 -33
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +104 -24
- package/dist/index.mjs +277 -33
- package/dist/index.mjs.map +1 -1
- package/dist/ingots/history.d.ts +4 -0
- package/dist/ingots/index.d.ts +22 -5
- package/dist/ingots/revision.d.ts +4 -0
- package/dist/ingots/types.d.ts +63 -0
- package/dist/products/structured-ingots/index.d.ts +3 -5
- package/dist/products/structured-ingots/types.d.ts +25 -11
- package/dist/products/structured-ingots/validation.d.ts +5 -1
- package/dist/sparkvault.js +1 -1
- package/dist/sparkvault.js.map +1 -1
- package/dist/vaults/index.d.ts +10 -3
- package/dist/vaults/types.d.ts +8 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -181,8 +181,9 @@ await records.create<Profile>(vault, {
|
|
|
181
181
|
idempotencyKey: 'signup-customer-42',
|
|
182
182
|
});
|
|
183
183
|
const profile = await records.get<Profile>(vault, ':profile-customer-42');
|
|
184
|
+
if (!profile.revision) throw new Error('This server does not support guarded object revisions');
|
|
184
185
|
await records.patch<Profile>(vault, profile.id, {
|
|
185
|
-
|
|
186
|
+
expectedRevision: profile.revision,
|
|
186
187
|
set: { preferences: { contactAllowed: true } },
|
|
187
188
|
});
|
|
188
189
|
```
|
|
@@ -201,13 +202,42 @@ A replay returns `created: false`, `replayed: true` and the original version-one
|
|
|
201
202
|
definition receipt, even if the Type has since been published or archived.
|
|
202
203
|
Call `types.get(vault, typeId)` for its current version and archive state.
|
|
203
204
|
|
|
204
|
-
PATCH and `restore(vault, ref, versionId, {
|
|
205
|
-
|
|
205
|
+
PATCH and `restore(vault, ref, versionId, { expectedRevision })` accept the
|
|
206
|
+
opaque `revision` returned by a read. It binds both the object's identity and
|
|
207
|
+
the publication read, so a deletion and recreation under the same name cannot
|
|
208
|
+
pass the guard. Use the returned object ID for mutations where possible.
|
|
209
|
+
The older `expectedVersion` numeric guard remains supported; it does not
|
|
210
|
+
identify an object recreated under a reused name. Supplying both guards
|
|
211
|
+
requires both to match. A concurrent change throws an error with
|
|
206
212
|
`statusCode === 412`; reread and reconcile the change. The SDK never retries a
|
|
207
|
-
mutation automatically.
|
|
213
|
+
mutation automatically. A timeout can occur after publication: it is an
|
|
214
|
+
uncertain outcome, not proof that nothing changed.
|
|
215
|
+
`history(vault, ref)` lists retained publications;
|
|
208
216
|
restore validates historical values against the current Type and creates a new
|
|
209
|
-
version.
|
|
210
|
-
|
|
217
|
+
version. Retention is the Vault's `ingotVersionLimit` setting, shared with
|
|
218
|
+
ordinary files and defaulting to zero previous versions. An interactive company
|
|
219
|
+
administrator sets it with `vaults.updateVersionHistory(vaultId, { versionLimit })`
|
|
220
|
+
(0–50). Current content is additional; lowering the limit takes effect on each
|
|
221
|
+
ingot's next successful content change. The old `structuredIngotVersionLimit`
|
|
222
|
+
property and `updateStructuredIngotSettings` method remain compatibility aliases. `delete(vault, ref, { expectedRevision })` deletes only the inspected
|
|
223
|
+
publication and its retained history. Omitting the option preserves deliberate
|
|
224
|
+
unconditional deletion. Older server responses may omit `revision`; do not
|
|
225
|
+
silently drop the guard when a workflow requires conditional writes.
|
|
226
|
+
|
|
227
|
+
Ordinary vault files share the same contract: `ingots.get` exposes `revision`,
|
|
228
|
+
and `ingots.replace` and `ingots.delete` accept `expectedRevision`. For a
|
|
229
|
+
read-modify-write of file contents, `ingots.downloadWithRevision` returns
|
|
230
|
+
`{ blob, revision }` from the bytes Forge actually served. A download link's
|
|
231
|
+
metadata describes the earlier mint, so it should not be used as proof of the
|
|
232
|
+
downloaded content's revision.
|
|
233
|
+
|
|
234
|
+
`ingots.listVersions(vault, ingotId)` lists previous file publications newest first,
|
|
235
|
+
excluding current content. `ingots.downloadVersion(vault, ingotId, versionId)`
|
|
236
|
+
downloads one retained publication and verifies the content-version header on the
|
|
237
|
+
received bytes. It refuses a pruned version or a response that cannot prove the
|
|
238
|
+
requested publication; it never substitutes current content. Use
|
|
239
|
+
`ingots.createVersionDownloadLink` only when your integration needs the URL itself.
|
|
240
|
+
Structured objects keep their product-specific history and type-aware restore.
|
|
211
241
|
|
|
212
242
|
Create rejects an existing name; it never overwrites. Names follow the server's
|
|
213
243
|
Unicode caseless matching rules. An optional stable `idempotencyKey` contains
|
package/dist/index.cjs
CHANGED
|
@@ -13272,6 +13272,47 @@ function readIngotAccess(entry) {
|
|
|
13272
13272
|
};
|
|
13273
13273
|
}
|
|
13274
13274
|
|
|
13275
|
+
/**
|
|
13276
|
+
* Opaque optimistic-concurrency identity for one publication of one ingot.
|
|
13277
|
+
* A legacy publication has no content marker, but still names its immutable
|
|
13278
|
+
* ingot id: deleting and recreating a logical name never reuses its revision.
|
|
13279
|
+
* This is a precondition, not a credential or a content digest.
|
|
13280
|
+
*/
|
|
13281
|
+
|
|
13282
|
+
const INGOT_REVISION_MAX_LENGTH = 4096;
|
|
13283
|
+
const MAX_CONTENT_VERSION_LENGTH = 256;
|
|
13284
|
+
|
|
13285
|
+
/** @returns {string} A portable, canonical revision for the actual publication. */
|
|
13286
|
+
function formatIngotRevision(ingotId, contentVersion) {
|
|
13287
|
+
if (!isResourceIdOf('ingot', ingotId) ||
|
|
13288
|
+
(contentVersion !== null && (typeof contentVersion !== 'string' || !contentVersion.length || contentVersion.length > MAX_CONTENT_VERSION_LENGTH))) {
|
|
13289
|
+
throw new TypeError('An ingot revision requires an ingot id and its content version');
|
|
13290
|
+
}
|
|
13291
|
+
try {
|
|
13292
|
+
return `ir1:${ingotId}:${contentVersion === null ? '' : encodeURIComponent(contentVersion)}`;
|
|
13293
|
+
} catch {
|
|
13294
|
+
throw new TypeError('An ingot revision requires a valid content version');
|
|
13295
|
+
}
|
|
13296
|
+
}
|
|
13297
|
+
|
|
13298
|
+
/** @returns {{ ingotId: string, contentVersion: string|null }} */
|
|
13299
|
+
function parseIngotRevision(revision) {
|
|
13300
|
+
if (typeof revision !== 'string' || revision.length > INGOT_REVISION_MAX_LENGTH) {
|
|
13301
|
+
throw new TypeError('revision must be an opaque ingot revision returned by the server');
|
|
13302
|
+
}
|
|
13303
|
+
const parts = revision.split(':');
|
|
13304
|
+
if (parts.length !== 3 || parts[0] !== 'ir1') {
|
|
13305
|
+
throw new TypeError('revision must be an opaque ingot revision returned by the server');
|
|
13306
|
+
}
|
|
13307
|
+
try {
|
|
13308
|
+
const contentVersion = parts[2] === '' ? null : decodeURIComponent(parts[2]);
|
|
13309
|
+
if (formatIngotRevision(parts[1], contentVersion) !== revision) throw new TypeError();
|
|
13310
|
+
return { ingotId: parts[1], contentVersion };
|
|
13311
|
+
} catch {
|
|
13312
|
+
throw new TypeError('revision must be an opaque ingot revision returned by the server');
|
|
13313
|
+
}
|
|
13314
|
+
}
|
|
13315
|
+
|
|
13275
13316
|
/**
|
|
13276
13317
|
* SparkVault Debug Logger
|
|
13277
13318
|
*
|
|
@@ -13673,6 +13714,11 @@ async function attemptWith(source, state, options) {
|
|
|
13673
13714
|
assertDownloadUrl(link, options.isAllowedHost);
|
|
13674
13715
|
}
|
|
13675
13716
|
catch (error) {
|
|
13717
|
+
// A successful HTTP response that failed local validation is an answer,
|
|
13718
|
+
// not a lost connection. Retrying cannot make its publication safe to use.
|
|
13719
|
+
if (error instanceof SparkVaultError && error.code === 'invalid_response') {
|
|
13720
|
+
return { ok: false, error, outcome: FINAL };
|
|
13721
|
+
}
|
|
13676
13722
|
if (!(error instanceof SparkVaultError) || typeof error.statusCode !== 'number') {
|
|
13677
13723
|
return { ok: false, error, outcome: UNANSWERED };
|
|
13678
13724
|
}
|
|
@@ -13739,6 +13785,12 @@ async function attemptDownload(link, state, options) {
|
|
|
13739
13785
|
const outcome = classifyTransferResponse({ status: response.status, headers: (name) => response.headers.get(name) });
|
|
13740
13786
|
return { ok: false, error: await refusedDownloadError(response, outcome, controller), outcome };
|
|
13741
13787
|
}
|
|
13788
|
+
// Every response contributes bytes, including a 206 continuation. Never
|
|
13789
|
+
// let a resumed response bypass the caller's publication precondition.
|
|
13790
|
+
const contentVersion = response.headers.get('x-content-version') || null;
|
|
13791
|
+
if (expectedContentVersion && contentVersion && contentVersion !== expectedContentVersion) {
|
|
13792
|
+
return { ok: false, error: new SparkVaultError(CONTENT_CHANGED_MESSAGE, 'content_changed'), outcome: FINAL };
|
|
13793
|
+
}
|
|
13742
13794
|
if (resume && response.status === 206) {
|
|
13743
13795
|
const continued = continuation(response, resume);
|
|
13744
13796
|
if (continued instanceof SparkVaultError)
|
|
@@ -13747,10 +13799,6 @@ async function attemptDownload(link, state, options) {
|
|
|
13747
13799
|
}
|
|
13748
13800
|
else {
|
|
13749
13801
|
received.discard();
|
|
13750
|
-
const contentVersion = response.headers.get('x-content-version') || null;
|
|
13751
|
-
if (expectedContentVersion && contentVersion && contentVersion !== expectedContentVersion) {
|
|
13752
|
-
return { ok: false, error: new SparkVaultError(CONTENT_CHANGED_MESSAGE, 'content_changed'), outcome: FINAL };
|
|
13753
|
-
}
|
|
13754
13802
|
held = {
|
|
13755
13803
|
contentType: response.headers.get('content-type') ?? '',
|
|
13756
13804
|
contentVersion,
|
|
@@ -13857,7 +13905,9 @@ function resumeValidator(headers) {
|
|
|
13857
13905
|
*/
|
|
13858
13906
|
function continuation(response, resume) {
|
|
13859
13907
|
const etag = response.headers.get('etag');
|
|
13860
|
-
|
|
13908
|
+
const contentVersion = response.headers.get('x-content-version');
|
|
13909
|
+
if ((etag !== null && etag.replace(/^W\//, '') !== resume.validator) ||
|
|
13910
|
+
(contentVersion && resume.held.contentVersion && contentVersion !== resume.held.contentVersion)) {
|
|
13861
13911
|
return new SparkVaultError(CONTENT_CHANGED_MESSAGE, 'content_changed');
|
|
13862
13912
|
}
|
|
13863
13913
|
const range = CONTENT_RANGE.exec(response.headers.get('content-range') ?? '');
|
|
@@ -13993,6 +14043,51 @@ class ReceivedBytes {
|
|
|
13993
14043
|
}
|
|
13994
14044
|
}
|
|
13995
14045
|
|
|
14046
|
+
/** Validate an opaque server revision without interpreting it as a credential. */
|
|
14047
|
+
function expectedRevision(value) {
|
|
14048
|
+
if (value === undefined)
|
|
14049
|
+
return undefined;
|
|
14050
|
+
try {
|
|
14051
|
+
parseIngotRevision(value);
|
|
14052
|
+
return value;
|
|
14053
|
+
}
|
|
14054
|
+
catch {
|
|
14055
|
+
throw new ValidationError('expectedRevision must be a revision returned by an ingot read');
|
|
14056
|
+
}
|
|
14057
|
+
}
|
|
14058
|
+
/** Older servers omit the revision; never invent a precondition from metadata. */
|
|
14059
|
+
function readRevision(value) {
|
|
14060
|
+
if (value === undefined)
|
|
14061
|
+
return undefined;
|
|
14062
|
+
try {
|
|
14063
|
+
parseIngotRevision(value);
|
|
14064
|
+
return value;
|
|
14065
|
+
}
|
|
14066
|
+
catch {
|
|
14067
|
+
throw new SparkVaultError('The server returned an invalid ingot revision', 'invalid_response');
|
|
14068
|
+
}
|
|
14069
|
+
}
|
|
14070
|
+
|
|
14071
|
+
/** Core files and Structured Ingots expose the same retained publication metadata. */
|
|
14072
|
+
function mapIngotHistory(data) {
|
|
14073
|
+
return {
|
|
14074
|
+
id: data.ingot_id,
|
|
14075
|
+
versionLimit: data.version_limit,
|
|
14076
|
+
versions: data.versions.map(version => ({
|
|
14077
|
+
versionId: version.version_id,
|
|
14078
|
+
publishedAt: version.published_at,
|
|
14079
|
+
sizeBytes: version.size_bytes,
|
|
14080
|
+
...(version.content_type === undefined ? {} : { contentType: version.content_type }),
|
|
14081
|
+
})),
|
|
14082
|
+
};
|
|
14083
|
+
}
|
|
14084
|
+
function requireVersionId(value) {
|
|
14085
|
+
if (typeof value !== 'string' || !/^[A-Za-z0-9:_-]{1,128}$/.test(value)) {
|
|
14086
|
+
throw new ValidationError('versionId must name a retained publication');
|
|
14087
|
+
}
|
|
14088
|
+
return value;
|
|
14089
|
+
}
|
|
14090
|
+
|
|
13996
14091
|
/**
|
|
13997
14092
|
* Folders Module
|
|
13998
14093
|
*
|
|
@@ -15536,12 +15631,16 @@ class IngotsModule {
|
|
|
15536
15631
|
* before the replacement is staged where there is no XMLHttpRequest.
|
|
15537
15632
|
*
|
|
15538
15633
|
* @example
|
|
15539
|
-
* await sv.ingots.
|
|
15634
|
+
* const original = await sv.ingots.downloadWithRevision(unsealed, 'ing_abc');
|
|
15635
|
+
* await sv.ingots.replace(unsealed, 'ing_abc', {
|
|
15636
|
+
* file: updatedFile, expectedRevision: original.revision,
|
|
15637
|
+
* });
|
|
15540
15638
|
*/
|
|
15541
15639
|
async replace(vault, ingotId, options) {
|
|
15542
15640
|
this.validateFile(options.file);
|
|
15543
15641
|
const vaultId = requireVaultId(vault);
|
|
15544
15642
|
const id = requireResourceId(ingotId, 'ingotId');
|
|
15643
|
+
const revision = expectedRevision(options.expectedRevision);
|
|
15545
15644
|
const name = options.name ?? getBlobName(options.file);
|
|
15546
15645
|
const contentType = sentContentType(options);
|
|
15547
15646
|
assertBrowserTransfer();
|
|
@@ -15551,6 +15650,7 @@ class IngotsModule {
|
|
|
15551
15650
|
...(contentType !== undefined && { content_type: contentType }),
|
|
15552
15651
|
size_bytes: options.file.size,
|
|
15553
15652
|
...(options.contentHmac && { content_hmac: options.contentHmac }),
|
|
15653
|
+
...(revision === undefined ? {} : { expected_revision: revision }),
|
|
15554
15654
|
}, { vat: vault.vatToken }).catch((error) => {
|
|
15555
15655
|
throw stagingRefusalOf(error);
|
|
15556
15656
|
});
|
|
@@ -15592,12 +15692,16 @@ class IngotsModule {
|
|
|
15592
15692
|
* Delete an ingot.
|
|
15593
15693
|
*
|
|
15594
15694
|
* @example
|
|
15595
|
-
* await sv.ingots.
|
|
15695
|
+
* const original = await sv.ingots.get(unsealed, 'ing_abc');
|
|
15696
|
+
* if (!original.revision) throw new Error('This server does not support guarded deletion');
|
|
15697
|
+
* await sv.ingots.delete(unsealed, original.id, { expectedRevision: original.revision });
|
|
15596
15698
|
*/
|
|
15597
|
-
async delete(vault, ingotId) {
|
|
15699
|
+
async delete(vault, ingotId, options = {}) {
|
|
15598
15700
|
const vaultId = requireVaultId(vault);
|
|
15599
15701
|
const id = requireResourceId(ingotId, 'ingotId');
|
|
15600
|
-
await this.http.delete(apiPath `/v1/vaults/${vaultId}/ingots/${id}`, {
|
|
15702
|
+
await this.http.delete(apiPath `/v1/vaults/${vaultId}/ingots/${id}`, {
|
|
15703
|
+
vat: vault.vatToken, query: { expected_revision: expectedRevision(options.expectedRevision) },
|
|
15704
|
+
});
|
|
15601
15705
|
}
|
|
15602
15706
|
/**
|
|
15603
15707
|
* Get ingot metadata.
|
|
@@ -15690,6 +15794,49 @@ class IngotsModule {
|
|
|
15690
15794
|
});
|
|
15691
15795
|
return mapFolderContents(response.data);
|
|
15692
15796
|
}
|
|
15797
|
+
/** List previous publications of a file, newest first. Structured objects use their product's history method. */
|
|
15798
|
+
async listVersions(vault, ingotId) {
|
|
15799
|
+
const vaultId = requireVaultId(vault);
|
|
15800
|
+
const id = requireResourceId(ingotId, 'ingotId');
|
|
15801
|
+
const { data } = await this.http.get(apiPath `/v1/vaults/${vaultId}/ingots/${id}/versions`, { vat: vault.vatToken });
|
|
15802
|
+
return mapIngotHistory(data);
|
|
15803
|
+
}
|
|
15804
|
+
/** Mint a one-use link to a retained file publication; use downloadVersion to verify the served bytes. */
|
|
15805
|
+
async createVersionDownloadLink(vault, ingotId, versionId) {
|
|
15806
|
+
const vaultId = requireVaultId(vault);
|
|
15807
|
+
const id = requireResourceId(ingotId, 'ingotId');
|
|
15808
|
+
const version = requireVersionId(versionId);
|
|
15809
|
+
const { data } = await this.http.post(apiPath `/v1/vaults/${vaultId}/ingots/${id}/versions/${version}/download`, undefined, { vat: vault.vatToken });
|
|
15810
|
+
if (data.ingot_id !== id || data.content_version !== version) {
|
|
15811
|
+
throw new SparkVaultError('The server returned a different retained publication', 'invalid_response');
|
|
15812
|
+
}
|
|
15813
|
+
assertDownloadUrl(data.download_url, this.allowsTransferHost);
|
|
15814
|
+
return {
|
|
15815
|
+
id: data.ingot_id,
|
|
15816
|
+
downloadUrl: data.download_url,
|
|
15817
|
+
size: data.size_bytes,
|
|
15818
|
+
contentVersion: data.content_version,
|
|
15819
|
+
expiresAt: data.expires_at,
|
|
15820
|
+
...(data.revision === undefined ? {} : { revision: readRevision(data.revision) }),
|
|
15821
|
+
...(data.name === undefined ? {} : { name: data.name }),
|
|
15822
|
+
...(data.content_type === undefined ? {} : { contentType: data.content_type }),
|
|
15823
|
+
};
|
|
15824
|
+
}
|
|
15825
|
+
/** Download a retained file publication; never substitutes the current bytes if history is unavailable. */
|
|
15826
|
+
async downloadVersion(vault, ingotId, versionId) {
|
|
15827
|
+
requireVaultId(vault);
|
|
15828
|
+
requireResourceId(ingotId, 'ingotId');
|
|
15829
|
+
const version = requireVersionId(versionId);
|
|
15830
|
+
const mint = async () => (await this.createVersionDownloadLink(vault, ingotId, version)).downloadUrl;
|
|
15831
|
+
const download = await fetchMintedDownload(mint, {
|
|
15832
|
+
isAllowedHost: this.allowsTransferHost, expectedContentVersion: version,
|
|
15833
|
+
});
|
|
15834
|
+
// Older transfer servers can omit the header; metadata from the mint is not proof of the bytes served.
|
|
15835
|
+
if (download.contentVersion !== version) {
|
|
15836
|
+
throw new SparkVaultError('The download did not identify the requested retained publication', 'invalid_response');
|
|
15837
|
+
}
|
|
15838
|
+
return download.blob;
|
|
15839
|
+
}
|
|
15693
15840
|
/**
|
|
15694
15841
|
* Create a signed download link for an ingot (discrete primitive).
|
|
15695
15842
|
*
|
|
@@ -15717,6 +15864,7 @@ class IngotsModule {
|
|
|
15717
15864
|
return {
|
|
15718
15865
|
downloadUrl: response.data.download_url,
|
|
15719
15866
|
contentVersion: response.data.content_version ?? null,
|
|
15867
|
+
...(response.data.revision === undefined ? {} : { revision: readRevision(response.data.revision) }),
|
|
15720
15868
|
id: response.data.ingot_id,
|
|
15721
15869
|
name: response.data.name,
|
|
15722
15870
|
size: response.data.size_bytes,
|
|
@@ -15750,8 +15898,19 @@ class IngotsModule {
|
|
|
15750
15898
|
* link.click();
|
|
15751
15899
|
*/
|
|
15752
15900
|
async download(vault, ingotId, options = {}) {
|
|
15901
|
+
return (await this.downloadWithRevision(vault, ingotId, options)).blob;
|
|
15902
|
+
}
|
|
15903
|
+
/**
|
|
15904
|
+
* Download bytes with their identity-bound revision. Use the returned revision
|
|
15905
|
+
* for replace/delete preconditions; the link's earlier metadata may already
|
|
15906
|
+
* have been superseded when Forge begins serving the bytes.
|
|
15907
|
+
*/
|
|
15908
|
+
async downloadWithRevision(vault, ingotId, options = {}) {
|
|
15909
|
+
requireVaultId(vault);
|
|
15910
|
+
const id = requireResourceId(ingotId, 'ingotId');
|
|
15753
15911
|
const mint = async () => (await this.createDownloadLink(vault, ingotId, options)).downloadUrl;
|
|
15754
|
-
|
|
15912
|
+
const download = await fetchMintedDownload(mint, { isAllowedHost: this.allowsTransferHost });
|
|
15913
|
+
return { blob: download.blob, revision: formatIngotRevision(id, download.contentVersion) };
|
|
15755
15914
|
}
|
|
15756
15915
|
/**
|
|
15757
15916
|
* Get an ingot's sharing configuration.
|
|
@@ -15947,6 +16106,7 @@ function mapIngot(wire) {
|
|
|
15947
16106
|
folderId: wire.folder_id ?? null,
|
|
15948
16107
|
contentHmac: wire.content_hmac ?? null,
|
|
15949
16108
|
contentVersion: wire.content_version ?? null,
|
|
16109
|
+
...(wire.revision === undefined ? {} : { revision: readRevision(wire.revision) }),
|
|
15950
16110
|
};
|
|
15951
16111
|
}
|
|
15952
16112
|
function mapFolderContents(wire) {
|
|
@@ -21393,6 +21553,16 @@ function integer(value, field, minimum, maximum) {
|
|
|
21393
21553
|
return value;
|
|
21394
21554
|
}
|
|
21395
21555
|
function expectedVersion(value) { return integer(value, 'expectedVersion', 1, 0xFFFFFFFF); }
|
|
21556
|
+
function mutationPrecondition(options) {
|
|
21557
|
+
const revision = expectedRevision(options.expectedRevision);
|
|
21558
|
+
const version = options.expectedVersion;
|
|
21559
|
+
if (version !== undefined)
|
|
21560
|
+
expectedVersion(version);
|
|
21561
|
+
if (revision === undefined && version === undefined) {
|
|
21562
|
+
throw new ValidationError('expectedRevision or expectedVersion is required');
|
|
21563
|
+
}
|
|
21564
|
+
return { expected_revision: revision, expected_version: version };
|
|
21565
|
+
}
|
|
21396
21566
|
function keysQuery(keys) {
|
|
21397
21567
|
if (keys === undefined)
|
|
21398
21568
|
return undefined;
|
|
@@ -21524,6 +21694,7 @@ class StructuredIngotTypesModule {
|
|
|
21524
21694
|
|
|
21525
21695
|
function mutation(wire) {
|
|
21526
21696
|
return { id: wire.ingot_id, version: wire.version, keyCount: wire.key_count, type: readPin(wire.type),
|
|
21697
|
+
...(wire.revision === undefined ? {} : { revision: readRevision(wire.revision) }),
|
|
21527
21698
|
...(wire.created_at === undefined ? {} : { createdAt: wire.created_at }),
|
|
21528
21699
|
...(wire.updated_at === undefined ? {} : { updatedAt: wire.updated_at }),
|
|
21529
21700
|
...(wire.created === undefined ? {} : { created: wire.created }),
|
|
@@ -21568,6 +21739,7 @@ class StructuredIngotsModule {
|
|
|
21568
21739
|
if (data.inline !== true)
|
|
21569
21740
|
throw new SparkVaultError('This server did not return a typed record response', 'invalid_response');
|
|
21570
21741
|
return { id: data.ingot_id, name: data.name, version: data.version, keyCount: data.key_count,
|
|
21742
|
+
...(data.revision === undefined ? {} : { revision: readRevision(data.revision) }),
|
|
21571
21743
|
values: data.values, missingKeys: data.missing_keys, type: readPin(data.type),
|
|
21572
21744
|
binaryPaths: data.binary_paths ?? data.binary_keys?.map((key) => [key]) ?? [],
|
|
21573
21745
|
createdAt: data.created_at, updatedAt: data.updated_at };
|
|
@@ -21576,6 +21748,7 @@ class StructuredIngotsModule {
|
|
|
21576
21748
|
const id = requireVault(vault);
|
|
21577
21749
|
const { data } = await this.http.get(apiPath `/v1/products/structured-ingots/${id}`, { vat: vault.vatToken, query: pageQuery(options) });
|
|
21578
21750
|
return page(data, data.ingots.map((record) => ({ id: record.ingot_id, name: record.name, sizeBytes: record.size_bytes,
|
|
21751
|
+
...(record.revision == null ? {} : { revision: readRevision(record.revision) }),
|
|
21579
21752
|
createdAt: record.created_at, updatedAt: record.updated_at ?? null })));
|
|
21580
21753
|
}
|
|
21581
21754
|
iterate(vault, options = {}) {
|
|
@@ -21592,36 +21765,35 @@ class StructuredIngotsModule {
|
|
|
21592
21765
|
async patch(vault, ref, options) {
|
|
21593
21766
|
const id = requireVault(vault);
|
|
21594
21767
|
const record = requireRef(ref);
|
|
21595
|
-
|
|
21768
|
+
const precondition = mutationPrecondition(options);
|
|
21596
21769
|
if (options.set !== undefined)
|
|
21597
21770
|
validateValues(options.set);
|
|
21598
21771
|
if (options.delete !== undefined && (!Array.isArray(options.delete) || options.delete.some((key) => typeof key !== 'string' || !key.length))) {
|
|
21599
21772
|
throw new ValidationError('delete must contain non-empty field names');
|
|
21600
21773
|
}
|
|
21601
21774
|
validateBinaryPaths(options.binaryPaths);
|
|
21602
|
-
const { data } = await this.http.patch(apiPath `/v1/products/structured-ingots/${id}/${record}`, {
|
|
21775
|
+
const { data } = await this.http.patch(apiPath `/v1/products/structured-ingots/${id}/${record}`, { ...precondition, set: options.set, delete: options.delete, type: wirePin(options.type), binary_paths: options.binaryPaths }, { vat: vault.vatToken });
|
|
21603
21776
|
return mutation(data);
|
|
21604
21777
|
}
|
|
21605
|
-
async delete(vault, ref) {
|
|
21778
|
+
async delete(vault, ref, options = {}) {
|
|
21606
21779
|
const id = requireVault(vault);
|
|
21607
21780
|
const record = requireRef(ref);
|
|
21608
|
-
await this.http.delete(apiPath `/v1/products/structured-ingots/${id}/${record}`, {
|
|
21781
|
+
await this.http.delete(apiPath `/v1/products/structured-ingots/${id}/${record}`, {
|
|
21782
|
+
vat: vault.vatToken, query: { expected_revision: expectedRevision(options.expectedRevision) },
|
|
21783
|
+
});
|
|
21609
21784
|
}
|
|
21610
21785
|
async history(vault, ref) {
|
|
21611
21786
|
const id = requireVault(vault);
|
|
21612
21787
|
const record = requireRef(ref);
|
|
21613
21788
|
const { data } = await this.http.get(apiPath `/v1/products/structured-ingots/${id}/${record}/versions`, { vat: vault.vatToken });
|
|
21614
|
-
return
|
|
21615
|
-
versionId: version.version_id, publishedAt: version.published_at, sizeBytes: version.size_bytes,
|
|
21616
|
-
})) };
|
|
21789
|
+
return mapIngotHistory(data);
|
|
21617
21790
|
}
|
|
21618
21791
|
async restore(vault, ref, versionId, options) {
|
|
21619
21792
|
const id = requireVault(vault);
|
|
21620
21793
|
const record = requireRef(ref);
|
|
21621
|
-
|
|
21622
|
-
|
|
21623
|
-
|
|
21624
|
-
const { data } = await this.http.post(apiPath `/v1/products/structured-ingots/${id}/${record}/versions/${versionId}/restore`, { expected_version: options.expectedVersion }, { vat: vault.vatToken });
|
|
21794
|
+
const precondition = mutationPrecondition(options);
|
|
21795
|
+
requireVersionId(versionId);
|
|
21796
|
+
const { data } = await this.http.post(apiPath `/v1/products/structured-ingots/${id}/${record}/versions/${versionId}/restore`, precondition, { vat: vault.vatToken });
|
|
21625
21797
|
return mutation(data);
|
|
21626
21798
|
}
|
|
21627
21799
|
/** Bounded parallel reads with independent, ordered success/error outcomes. */
|
|
@@ -21789,8 +21961,70 @@ function unsealRequestBody(key, ttlSeconds) {
|
|
|
21789
21961
|
return ttlSeconds === undefined ? { [field]: trimmed } : { [field]: trimmed, ttl_seconds: ttlSeconds };
|
|
21790
21962
|
}
|
|
21791
21963
|
|
|
21792
|
-
/**
|
|
21793
|
-
|
|
21964
|
+
/**
|
|
21965
|
+
* The apps that manage ingots, each by the id its ingots carry as `managed_by`:
|
|
21966
|
+
* the one statement of those ids, of the name each app goes by, of whether an
|
|
21967
|
+
* app manages a row (isManagedIngot), and of whose rows Core seals server-side
|
|
21968
|
+
* (isServerSealedIngot). Each app marks every ingot it creates
|
|
21969
|
+
* with its own (Structured Ingots also calls Core as it, since Core lets only
|
|
21970
|
+
* the internal invoker an ingot's `managed_by` names create or touch one);
|
|
21971
|
+
* Core, the console, the mobile app and the Slack app ask isManagedIngot of a
|
|
21972
|
+
* row, and the mobile app names the app on the row's sheet. An app's ingot is
|
|
21973
|
+
* the app's: Core's file routes act on it only for the app, the vault shares
|
|
21974
|
+
* it with no one, the app included, and no request files it in a folder
|
|
21975
|
+
* (docs/APPS.md → Managed Ingots).
|
|
21976
|
+
*
|
|
21977
|
+
* A value is stored on every ingot its app creates and never changes on the
|
|
21978
|
+
* row (`managed_by` is immutable), so an id here is never renamed: a new
|
|
21979
|
+
* value would leave every existing ingot naming one no app answers to.
|
|
21980
|
+
*
|
|
21981
|
+
* BROWSER-SAFE: data and pure functions, no imports.
|
|
21982
|
+
*/
|
|
21983
|
+
|
|
21984
|
+
const MANAGED_BY = Object.freeze({
|
|
21985
|
+
/** A Structured Ingots record, Identity's directory profiles among them. */
|
|
21986
|
+
STRUCTURED_INGOTS: 'structured-ingots',
|
|
21987
|
+
/** An encrypted catalog of a Structured Ingots type's immutable definitions. */
|
|
21988
|
+
STRUCTURED_INGOT_TYPES: 'structured-ingot-types',
|
|
21989
|
+
/** A help desk message body, email original, attachment or requester export part. */
|
|
21990
|
+
HELP_DESK: 'product-help-desk',
|
|
21991
|
+
/** A Messaging message, compacted page or attachment. */
|
|
21992
|
+
MESSAGING: 'product-messaging'
|
|
21993
|
+
});
|
|
21994
|
+
|
|
21995
|
+
/** Each app's name, as UI copy names the product (docs/DESIGN.md → Voice & copy). */
|
|
21996
|
+
new Map([
|
|
21997
|
+
[MANAGED_BY.STRUCTURED_INGOTS, 'Structured Ingots'],
|
|
21998
|
+
[MANAGED_BY.STRUCTURED_INGOT_TYPES, 'Structured Ingots'],
|
|
21999
|
+
[MANAGED_BY.HELP_DESK, 'Secure Help Desk'],
|
|
22000
|
+
[MANAGED_BY.MESSAGING, 'Messaging']
|
|
22001
|
+
]);
|
|
22002
|
+
|
|
22003
|
+
/**
|
|
22004
|
+
* The apps inside Core whose ingots Core writes server-side, sealing content
|
|
22005
|
+
* it is handed in one call (apps/api UnifiedIngotService.sealIngotContent):
|
|
22006
|
+
* each such ingot lies at the vault root, at an id its app derives from its
|
|
22007
|
+
* own keys, and holds no name claim. Every other ingot, a Structured Ingots
|
|
22008
|
+
* record's included, is created through Core's upload path and holds its name
|
|
22009
|
+
* by a claim.
|
|
22010
|
+
*/
|
|
22011
|
+
new Set([MANAGED_BY.HELP_DESK, MANAGED_BY.MESSAGING]);
|
|
22012
|
+
|
|
22013
|
+
/** Maximum previous publications retained for each user file or object. */
|
|
22014
|
+
const MAX_INGOT_VERSIONS = 50;
|
|
22015
|
+
|
|
22016
|
+
/** Existing vaults retain only current content until retention is enabled. */
|
|
22017
|
+
function ingotVersionLimit(vault) {
|
|
22018
|
+
const limit = vault?.ingot_version_limit === undefined
|
|
22019
|
+
? (vault?.structured_ingot_version_limit === undefined ? 0 : vault.structured_ingot_version_limit)
|
|
22020
|
+
: vault.ingot_version_limit;
|
|
22021
|
+
// Malformed stored settings must never silently disable retention and purge
|
|
22022
|
+
// history. Every writer uses the same bounded integer contract.
|
|
22023
|
+
if (!Number.isSafeInteger(limit) || limit < 0 || limit > MAX_INGOT_VERSIONS) {
|
|
22024
|
+
throw new RangeError('Invalid ingot version limit');
|
|
22025
|
+
}
|
|
22026
|
+
return limit;
|
|
22027
|
+
}
|
|
21794
22028
|
|
|
21795
22029
|
/**
|
|
21796
22030
|
* Upload Widget Chrome
|
|
@@ -24536,7 +24770,7 @@ class VaultsModule {
|
|
|
24536
24770
|
createdAt: v.created_at,
|
|
24537
24771
|
ingotCount: v.ingot_count,
|
|
24538
24772
|
storageBytes: v.storage_bytes,
|
|
24539
|
-
...(v
|
|
24773
|
+
...mapVersionHistory(v),
|
|
24540
24774
|
...(v.structured_ingots_enabled === undefined ? {} : { structuredIngotsEnabled: v.structured_ingots_enabled }),
|
|
24541
24775
|
...mapLifecycle(v),
|
|
24542
24776
|
})),
|
|
@@ -24575,19 +24809,23 @@ class VaultsModule {
|
|
|
24575
24809
|
};
|
|
24576
24810
|
}
|
|
24577
24811
|
/**
|
|
24578
|
-
* Retain this many previous versions of each structured object (0–50
|
|
24579
|
-
* Interactive company administrators only. Applies on each
|
|
24580
|
-
* successful change; retained versions count toward storage usage.
|
|
24812
|
+
* Retain this many previous versions of each file or structured object (0–50,
|
|
24813
|
+
* default 0). Interactive company administrators only. Applies on each ingot's
|
|
24814
|
+
* next successful content change; retained versions count toward storage usage.
|
|
24581
24815
|
*/
|
|
24582
|
-
async
|
|
24816
|
+
async updateVersionHistory(vaultId, settings) {
|
|
24583
24817
|
const id = requireResourceId(vaultId, 'vaultId');
|
|
24584
24818
|
const limit = settings?.versionLimit;
|
|
24585
|
-
if (!Number.isSafeInteger(limit) || limit < 0 || limit >
|
|
24586
|
-
throw new ValidationError(`versionLimit must be a whole number from 0 to ${
|
|
24819
|
+
if (!Number.isSafeInteger(limit) || limit < 0 || limit > MAX_INGOT_VERSIONS) {
|
|
24820
|
+
throw new ValidationError(`versionLimit must be a whole number from 0 to ${MAX_INGOT_VERSIONS}`);
|
|
24587
24821
|
}
|
|
24588
|
-
const response = await this.http.put(apiPath `/v1/vaults/${id}/
|
|
24822
|
+
const response = await this.http.put(apiPath `/v1/vaults/${id}/version-history`, { version_limit: limit });
|
|
24589
24823
|
return { vaultId: response.data.vault_id, versionLimit: response.data.version_limit };
|
|
24590
24824
|
}
|
|
24825
|
+
/** @deprecated Use updateVersionHistory; retention applies to files and structured objects. */
|
|
24826
|
+
async updateStructuredIngotSettings(vaultId, settings) {
|
|
24827
|
+
return this.updateVersionHistory(vaultId, settings);
|
|
24828
|
+
}
|
|
24591
24829
|
/**
|
|
24592
24830
|
* Rename a vault.
|
|
24593
24831
|
*
|
|
@@ -24851,6 +25089,12 @@ function mapLifecycle(v) {
|
|
|
24851
25089
|
deletionScheduleId: v.deletion_schedule_id,
|
|
24852
25090
|
};
|
|
24853
25091
|
}
|
|
25092
|
+
function mapVersionHistory(v) {
|
|
25093
|
+
if (v.ingot_version_limit === undefined && v.structured_ingot_version_limit === undefined)
|
|
25094
|
+
return {};
|
|
25095
|
+
const limit = ingotVersionLimit(v);
|
|
25096
|
+
return { ingotVersionLimit: limit, structuredIngotVersionLimit: limit };
|
|
25097
|
+
}
|
|
24854
25098
|
function mapVaultDetail(v) {
|
|
24855
25099
|
return {
|
|
24856
25100
|
id: v.vault_id,
|
|
@@ -24859,7 +25103,7 @@ function mapVaultDetail(v) {
|
|
|
24859
25103
|
...mapLifecycle(v),
|
|
24860
25104
|
ingotCount: v.ingot_count ?? 0,
|
|
24861
25105
|
storageBytes: v.storage_bytes ?? 0,
|
|
24862
|
-
...(v
|
|
25106
|
+
...mapVersionHistory(v),
|
|
24863
25107
|
...(v.structured_ingots_enabled === undefined ? {} : { structuredIngotsEnabled: v.structured_ingots_enabled }),
|
|
24864
25108
|
createdAt: v.created_at,
|
|
24865
25109
|
lastUnsealedAt: v.last_unsealed_at ?? null,
|
|
@@ -25653,7 +25897,7 @@ class SparkVault {
|
|
|
25653
25897
|
}
|
|
25654
25898
|
/** Get the SDK version */
|
|
25655
25899
|
static get version() {
|
|
25656
|
-
return '15.
|
|
25900
|
+
return '15.10.0';
|
|
25657
25901
|
}
|
|
25658
25902
|
}
|
|
25659
25903
|
if (typeof window !== 'undefined') {
|