@sparkvault/sdk-js 2.2.5 → 4.0.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/dist/auto-init.d.ts +1 -1
- package/dist/entropy/index.d.ts +28 -0
- package/dist/entropy/types.d.ts +32 -0
- package/dist/folders/index.d.ts +77 -0
- package/dist/folders/types.d.ts +64 -0
- package/dist/http.d.ts +3 -1
- package/dist/index.d.ts +982 -78
- package/dist/ingots/index.d.ts +183 -0
- package/dist/ingots/types.d.ts +286 -0
- package/dist/{identity → products/identity}/api.d.ts +3 -3
- package/dist/{identity → products/identity}/embedder.d.ts +1 -1
- package/dist/{identity → products/identity}/index.d.ts +7 -7
- package/dist/{identity → products/identity}/utils.d.ts +1 -1
- package/dist/products/index.d.ts +18 -0
- package/dist/sparks/index.d.ts +65 -0
- package/dist/sparks/types.d.ts +174 -0
- package/dist/sparkvault.cjs.js +1077 -101
- package/dist/sparkvault.cjs.js.map +1 -1
- package/dist/sparkvault.esm.js +1071 -102
- package/dist/sparkvault.esm.js.map +1 -1
- package/dist/sparkvault.js +1 -1
- package/dist/sparkvault.js.map +1 -1
- package/dist/vaults/index.d.ts +102 -34
- package/dist/vaults/types.d.ts +121 -57
- package/dist/vaults/upload/api.d.ts +1 -1
- package/package.json +1 -1
- /package/dist/{identity → products/identity}/container.d.ts +0 -0
- /package/dist/{identity → products/identity}/handlers/index.d.ts +0 -0
- /package/dist/{identity → products/identity}/handlers/passkey-handler.d.ts +0 -0
- /package/dist/{identity → products/identity}/handlers/sparklink-handler.d.ts +0 -0
- /package/dist/{identity → products/identity}/handlers/totp-handler.d.ts +0 -0
- /package/dist/{identity → products/identity}/inline-container.d.ts +0 -0
- /package/dist/{identity → products/identity}/methods.d.ts +0 -0
- /package/dist/{identity → products/identity}/modal.d.ts +0 -0
- /package/dist/{identity → products/identity}/renderer.d.ts +0 -0
- /package/dist/{identity → products/identity}/state.d.ts +0 -0
- /package/dist/{identity → products/identity}/styles.d.ts +0 -0
- /package/dist/{identity → products/identity}/types.d.ts +0 -0
- /package/dist/{identity → products/identity}/utils/cooldown-timer.d.ts +0 -0
- /package/dist/{identity → products/identity}/utils/index.d.ts +0 -0
- /package/dist/{identity → products/identity}/views/backup-verify.d.ts +0 -0
- /package/dist/{identity → products/identity}/views/base.d.ts +0 -0
- /package/dist/{identity → products/identity}/views/error.d.ts +0 -0
- /package/dist/{identity → products/identity}/views/icons.d.ts +0 -0
- /package/dist/{identity → products/identity}/views/identity-input.d.ts +0 -0
- /package/dist/{identity → products/identity}/views/index.d.ts +0 -0
- /package/dist/{identity → products/identity}/views/loading.d.ts +0 -0
- /package/dist/{identity → products/identity}/views/method-select.d.ts +0 -0
- /package/dist/{identity → products/identity}/views/origin-not-allowed.d.ts +0 -0
- /package/dist/{identity → products/identity}/views/passkey-prompt.d.ts +0 -0
- /package/dist/{identity → products/identity}/views/passkey.d.ts +0 -0
- /package/dist/{identity → products/identity}/views/product-not-configured.d.ts +0 -0
- /package/dist/{identity → products/identity}/views/service-unavailable.d.ts +0 -0
- /package/dist/{identity → products/identity}/views/sparklink-waiting.d.ts +0 -0
- /package/dist/{identity → products/identity}/views/totp-verify.d.ts +0 -0
- /package/dist/{identity → products/identity}/views/two-factor.d.ts +0 -0
package/dist/sparkvault.cjs.js
CHANGED
|
@@ -341,6 +341,12 @@ class HttpClient {
|
|
|
341
341
|
post(path, body, options) {
|
|
342
342
|
return this.request(path, { ...options, method: 'POST', body });
|
|
343
343
|
}
|
|
344
|
+
put(path, body, options) {
|
|
345
|
+
return this.request(path, { ...options, method: 'PUT', body });
|
|
346
|
+
}
|
|
347
|
+
patch(path, body, options) {
|
|
348
|
+
return this.request(path, { ...options, method: 'PATCH', body });
|
|
349
|
+
}
|
|
344
350
|
delete(path, options) {
|
|
345
351
|
return this.request(path, { ...options, method: 'DELETE' });
|
|
346
352
|
}
|
|
@@ -7662,13 +7668,13 @@ function attachClickHandler(selector, onClick) {
|
|
|
7662
7668
|
* Supports passkey, TOTP, SparkLink, and social authentication.
|
|
7663
7669
|
*
|
|
7664
7670
|
* @example Dialog mode (immediate)
|
|
7665
|
-
* const result = await sv.identity.verify();
|
|
7671
|
+
* const result = await sv.products.identity.verify();
|
|
7666
7672
|
*
|
|
7667
7673
|
* @example Dialog mode (attached to clicks)
|
|
7668
|
-
* sv.identity.attach('.login-btn');
|
|
7674
|
+
* sv.products.identity.attach('.login-btn');
|
|
7669
7675
|
*
|
|
7670
7676
|
* @example Inline mode
|
|
7671
|
-
* const result = await sv.identity.verify({ target: '#auth-container' });
|
|
7677
|
+
* const result = await sv.products.identity.verify({ target: '#auth-container' });
|
|
7672
7678
|
*/
|
|
7673
7679
|
function isTokenClaims(payload) {
|
|
7674
7680
|
if (typeof payload !== 'object' || payload === null) {
|
|
@@ -7703,11 +7709,11 @@ class IdentityModule {
|
|
|
7703
7709
|
* - With `target`: Renders inline into the specified element
|
|
7704
7710
|
*
|
|
7705
7711
|
* @example Dialog mode
|
|
7706
|
-
* const result = await sv.identity.verify();
|
|
7712
|
+
* const result = await sv.products.identity.verify();
|
|
7707
7713
|
* console.log(result.token, result.identity);
|
|
7708
7714
|
*
|
|
7709
7715
|
* @example Inline mode
|
|
7710
|
-
* const result = await sv.identity.verify({
|
|
7716
|
+
* const result = await sv.products.identity.verify({
|
|
7711
7717
|
* target: '#auth-container',
|
|
7712
7718
|
* email: 'user@example.com'
|
|
7713
7719
|
* });
|
|
@@ -7807,7 +7813,7 @@ class IdentityModule {
|
|
|
7807
7813
|
* @returns Cleanup function to remove event listeners
|
|
7808
7814
|
*
|
|
7809
7815
|
* @example
|
|
7810
|
-
* const cleanup = sv.identity.attach('.login-btn', {
|
|
7816
|
+
* const cleanup = sv.products.identity.attach('.login-btn', {
|
|
7811
7817
|
* onSuccess: (result) => console.log('Verified:', result.identity)
|
|
7812
7818
|
* });
|
|
7813
7819
|
*
|
|
@@ -8012,6 +8018,19 @@ class IdentityModule {
|
|
|
8012
8018
|
}
|
|
8013
8019
|
}
|
|
8014
8020
|
|
|
8021
|
+
/**
|
|
8022
|
+
* Products Module
|
|
8023
|
+
*
|
|
8024
|
+
* Namespace for SparkVault first-party products. Each product is a
|
|
8025
|
+
* self-contained surface (UI + API) the account can enable independently.
|
|
8026
|
+
* Currently exposes `identity`; future products attach here alongside it.
|
|
8027
|
+
*/
|
|
8028
|
+
class ProductsModule {
|
|
8029
|
+
constructor(config) {
|
|
8030
|
+
this.identity = new IdentityModule(config);
|
|
8031
|
+
}
|
|
8032
|
+
}
|
|
8033
|
+
|
|
8015
8034
|
/**
|
|
8016
8035
|
* Upload API
|
|
8017
8036
|
*
|
|
@@ -8148,7 +8167,7 @@ class UploadApi extends SparkVaultApi {
|
|
|
8148
8167
|
* Upload a file to Forge over the TUS resumable protocol (v1.0.0).
|
|
8149
8168
|
*
|
|
8150
8169
|
* The single canonical browser transfer path — the upload widget and the
|
|
8151
|
-
* authenticated `
|
|
8170
|
+
* authenticated `ingots.upload` flow both go through here (CLAUDE.md: one
|
|
8152
8171
|
* transfer path). Creates the session, PATCHes chunks sized by the server's
|
|
8153
8172
|
* `X-Chunk-Size` (50MB default, which keeps every request under CDN body
|
|
8154
8173
|
* caps such as Cloudflare's 100MB), validates every server-reported offset,
|
|
@@ -11101,15 +11120,15 @@ class VaultUploadModule {
|
|
|
11101
11120
|
/**
|
|
11102
11121
|
* Vaults Module
|
|
11103
11122
|
*
|
|
11104
|
-
* Create and manage encrypted vaults
|
|
11105
|
-
*
|
|
11123
|
+
* Create and manage encrypted vaults (the control plane). Uses Triple
|
|
11124
|
+
* Zero-Trust encryption (SVMK + AMK + VMK). Ingot, folder, spark, and entropy
|
|
11125
|
+
* operations live in their own modules; this module owns the vault record,
|
|
11126
|
+
* its sharing/upload configuration, and the browser upload widget.
|
|
11106
11127
|
*/
|
|
11107
11128
|
class VaultsModule {
|
|
11108
11129
|
constructor(config, http) {
|
|
11109
|
-
this.config = config;
|
|
11110
11130
|
this.http = http;
|
|
11111
11131
|
this.uploadModule = new VaultUploadModule(config);
|
|
11112
|
-
this.uploadApi = new UploadApi(config);
|
|
11113
11132
|
// Create callable that also has attach/close/pop/render methods
|
|
11114
11133
|
const uploadFn = ((options) => this.uploadModule.upload(options));
|
|
11115
11134
|
uploadFn.attach = (selector, options) => this.uploadModule.attach(selector, options);
|
|
@@ -11130,14 +11149,12 @@ class VaultsModule {
|
|
|
11130
11149
|
this.validateCreateOptions(options);
|
|
11131
11150
|
const response = await this.http.post('/v1/vaults', {
|
|
11132
11151
|
name: options.name,
|
|
11133
|
-
hosted_vmk: options.hostedVmk ?? false,
|
|
11134
11152
|
});
|
|
11135
11153
|
return {
|
|
11136
11154
|
id: response.data.vault_id,
|
|
11137
11155
|
name: response.data.name,
|
|
11138
11156
|
vmk: response.data.vmk,
|
|
11139
11157
|
createdAt: response.data.created_at,
|
|
11140
|
-
hostedVmk: response.data.hosted_vmk,
|
|
11141
11158
|
};
|
|
11142
11159
|
}
|
|
11143
11160
|
/**
|
|
@@ -11146,16 +11163,13 @@ class VaultsModule {
|
|
|
11146
11163
|
*
|
|
11147
11164
|
* @example
|
|
11148
11165
|
* const unsealed = await sv.vaults.unseal('vlt_abc', vmk);
|
|
11149
|
-
* console.log('
|
|
11166
|
+
* console.log('Token:', unsealed.vatToken);
|
|
11150
11167
|
*/
|
|
11151
11168
|
async unseal(vaultId, vmk) {
|
|
11152
|
-
|
|
11153
|
-
throw new ValidationError('Vault ID is required');
|
|
11154
|
-
}
|
|
11169
|
+
const cleanId = this.normalizeVaultId(vaultId);
|
|
11155
11170
|
if (!vmk) {
|
|
11156
11171
|
throw new ValidationError('VMK is required');
|
|
11157
11172
|
}
|
|
11158
|
-
const cleanId = vaultId.startsWith('vlt_') ? vaultId : `vlt_${vaultId}`;
|
|
11159
11173
|
const response = await this.http.post(`/v1/vaults/${cleanId}/unseal`, { vmk });
|
|
11160
11174
|
if (!response.data.vat) {
|
|
11161
11175
|
throw new ValidationError('Unseal response did not include a vault access token');
|
|
@@ -11183,79 +11197,523 @@ class VaultsModule {
|
|
|
11183
11197
|
createdAt: v.created_at,
|
|
11184
11198
|
ingotCount: v.ingot_count,
|
|
11185
11199
|
storageBytes: v.storage_bytes,
|
|
11186
|
-
hostedVmk: v.hosted_vmk,
|
|
11187
11200
|
}));
|
|
11188
11201
|
}
|
|
11189
11202
|
/**
|
|
11190
|
-
*
|
|
11191
|
-
*
|
|
11203
|
+
* Get a single vault's detail.
|
|
11204
|
+
*
|
|
11205
|
+
* @example
|
|
11206
|
+
* const vault = await sv.vaults.get('vlt_abc');
|
|
11207
|
+
* console.log(vault.status, vault.ingotCount);
|
|
11208
|
+
*/
|
|
11209
|
+
async get(vaultId) {
|
|
11210
|
+
const cleanId = this.normalizeVaultId(vaultId);
|
|
11211
|
+
const response = await this.http.get(`/v1/vaults/${cleanId}`);
|
|
11212
|
+
const v = response.data;
|
|
11213
|
+
return {
|
|
11214
|
+
id: v.vault_id,
|
|
11215
|
+
name: v.name,
|
|
11216
|
+
description: v.description ?? null,
|
|
11217
|
+
status: v.status,
|
|
11218
|
+
ingotCount: v.ingot_count ?? 0,
|
|
11219
|
+
storageBytes: v.storage_bytes ?? 0,
|
|
11220
|
+
createdAt: v.created_at,
|
|
11221
|
+
lastUnsealedAt: v.last_unsealed_at ?? null,
|
|
11222
|
+
unsealCount: v.unseal_count ?? 0,
|
|
11223
|
+
};
|
|
11224
|
+
}
|
|
11225
|
+
/**
|
|
11226
|
+
* Rename a vault.
|
|
11227
|
+
*
|
|
11228
|
+
* @example
|
|
11229
|
+
* await sv.vaults.update('vlt_abc', { name: 'Renamed Vault' });
|
|
11230
|
+
*/
|
|
11231
|
+
async update(vaultId, options) {
|
|
11232
|
+
const cleanId = this.normalizeVaultId(vaultId);
|
|
11233
|
+
if (!options.name?.trim()) {
|
|
11234
|
+
throw new ValidationError('Vault name is required');
|
|
11235
|
+
}
|
|
11236
|
+
const response = await this.http.put(`/v1/vaults/${cleanId}`, {
|
|
11237
|
+
name: options.name,
|
|
11238
|
+
});
|
|
11239
|
+
const v = response.data;
|
|
11240
|
+
return {
|
|
11241
|
+
id: v.vault_id,
|
|
11242
|
+
name: v.name,
|
|
11243
|
+
description: v.description ?? null,
|
|
11244
|
+
updatedAt: v.updated_at,
|
|
11245
|
+
};
|
|
11246
|
+
}
|
|
11247
|
+
/**
|
|
11248
|
+
* Seal a vault, revoking all active access tokens.
|
|
11249
|
+
*
|
|
11250
|
+
* @example
|
|
11251
|
+
* await sv.vaults.seal('vlt_abc');
|
|
11252
|
+
*/
|
|
11253
|
+
async seal(vaultId) {
|
|
11254
|
+
const cleanId = this.normalizeVaultId(vaultId);
|
|
11255
|
+
await this.http.post(`/v1/vaults/${cleanId}/seal`);
|
|
11256
|
+
}
|
|
11257
|
+
/**
|
|
11258
|
+
* Delete a vault and all its ingots. This action is irreversible!
|
|
11192
11259
|
*
|
|
11193
11260
|
* @example
|
|
11194
11261
|
* await sv.vaults.delete('vlt_abc', vmk);
|
|
11195
11262
|
*/
|
|
11196
11263
|
async delete(vaultId, vmk) {
|
|
11197
|
-
const cleanId =
|
|
11264
|
+
const cleanId = this.normalizeVaultId(vaultId);
|
|
11198
11265
|
await this.http.delete(`/v1/vaults/${cleanId}`, {
|
|
11199
11266
|
headers: { 'X-VMK': vmk },
|
|
11200
11267
|
});
|
|
11201
11268
|
}
|
|
11202
11269
|
/**
|
|
11203
|
-
*
|
|
11270
|
+
* Get a vault's public-sharing configuration.
|
|
11204
11271
|
*
|
|
11205
11272
|
* @example
|
|
11206
|
-
* const
|
|
11207
|
-
* file: myFile,
|
|
11208
|
-
* name: 'document.pdf'
|
|
11209
|
-
* });
|
|
11273
|
+
* const sharing = await sv.vaults.getSharingConfig('vlt_abc');
|
|
11210
11274
|
*/
|
|
11211
|
-
async
|
|
11212
|
-
this.
|
|
11213
|
-
const
|
|
11214
|
-
|
|
11215
|
-
|
|
11216
|
-
|
|
11217
|
-
|
|
11218
|
-
|
|
11219
|
-
|
|
11220
|
-
|
|
11275
|
+
async getSharingConfig(vaultId) {
|
|
11276
|
+
const cleanId = this.normalizeVaultId(vaultId);
|
|
11277
|
+
const response = await this.http.get(`/v1/vaults/${cleanId}/sharing`);
|
|
11278
|
+
return mapSharingConfig$1(response.data);
|
|
11279
|
+
}
|
|
11280
|
+
/**
|
|
11281
|
+
* Enable public sharing for a vault.
|
|
11282
|
+
*
|
|
11283
|
+
* @example
|
|
11284
|
+
* await sv.vaults.enableSharing('vlt_abc', vmk, { sessionLengthSeconds: 3600 });
|
|
11285
|
+
*/
|
|
11286
|
+
async enableSharing(vaultId, vmk, options = {}) {
|
|
11287
|
+
const cleanId = this.normalizeVaultId(vaultId);
|
|
11288
|
+
if (!vmk) {
|
|
11289
|
+
throw new ValidationError('VMK is required');
|
|
11290
|
+
}
|
|
11291
|
+
const response = await this.http.post(`/v1/vaults/${cleanId}/sharing/enable`, {
|
|
11292
|
+
vmk,
|
|
11293
|
+
all_ingots_public: options.allIngotsPublic,
|
|
11294
|
+
session_length_seconds: options.sessionLengthSeconds,
|
|
11221
11295
|
});
|
|
11222
|
-
|
|
11223
|
-
|
|
11224
|
-
|
|
11296
|
+
return mapSharingConfig$1(response.data);
|
|
11297
|
+
}
|
|
11298
|
+
/**
|
|
11299
|
+
* Disable public sharing for a vault.
|
|
11300
|
+
*
|
|
11301
|
+
* @example
|
|
11302
|
+
* await sv.vaults.disableSharing('vlt_abc');
|
|
11303
|
+
*/
|
|
11304
|
+
async disableSharing(vaultId) {
|
|
11305
|
+
const cleanId = this.normalizeVaultId(vaultId);
|
|
11306
|
+
const response = await this.http.post(`/v1/vaults/${cleanId}/sharing/disable`);
|
|
11307
|
+
return mapSharingConfig$1(response.data);
|
|
11308
|
+
}
|
|
11309
|
+
/**
|
|
11310
|
+
* Update a vault's sharing configuration (without changing enabled state).
|
|
11311
|
+
*
|
|
11312
|
+
* @example
|
|
11313
|
+
* await sv.vaults.updateSharingConfig('vlt_abc', { allIngotsPublic: true });
|
|
11314
|
+
*/
|
|
11315
|
+
async updateSharingConfig(vaultId, config) {
|
|
11316
|
+
const cleanId = this.normalizeVaultId(vaultId);
|
|
11317
|
+
const response = await this.http.put(`/v1/vaults/${cleanId}/sharing`, {
|
|
11318
|
+
all_ingots_public: config.allIngotsPublic,
|
|
11319
|
+
session_length_seconds: config.sessionLengthSeconds,
|
|
11320
|
+
});
|
|
11321
|
+
return mapSharingConfig$1(response.data);
|
|
11322
|
+
}
|
|
11323
|
+
/**
|
|
11324
|
+
* Get a vault's access-log retention window.
|
|
11325
|
+
*
|
|
11326
|
+
* @example
|
|
11327
|
+
* const { retentionSeconds } = await sv.vaults.getAccessLogRetention('vlt_abc');
|
|
11328
|
+
*/
|
|
11329
|
+
async getAccessLogRetention(vaultId) {
|
|
11330
|
+
const cleanId = this.normalizeVaultId(vaultId);
|
|
11331
|
+
const response = await this.http.get(`/v1/vaults/${cleanId}/access-log-retention`);
|
|
11332
|
+
return {
|
|
11333
|
+
vaultId: response.data.vault_id,
|
|
11334
|
+
retentionSeconds: response.data.access_log_retention_seconds,
|
|
11335
|
+
};
|
|
11336
|
+
}
|
|
11337
|
+
/**
|
|
11338
|
+
* Update a vault's access-log retention window.
|
|
11339
|
+
*
|
|
11340
|
+
* @example
|
|
11341
|
+
* await sv.vaults.updateAccessLogRetention('vlt_abc', 7776000);
|
|
11342
|
+
*/
|
|
11343
|
+
async updateAccessLogRetention(vaultId, seconds) {
|
|
11344
|
+
const cleanId = this.normalizeVaultId(vaultId);
|
|
11345
|
+
const response = await this.http.put(`/v1/vaults/${cleanId}/access-log-retention`, { access_log_retention_seconds: seconds });
|
|
11346
|
+
return {
|
|
11347
|
+
vaultId: response.data.vault_id,
|
|
11348
|
+
retentionSeconds: response.data.access_log_retention_seconds,
|
|
11349
|
+
};
|
|
11350
|
+
}
|
|
11351
|
+
/**
|
|
11352
|
+
* Get a vault's upload-channel configuration.
|
|
11353
|
+
*
|
|
11354
|
+
* @example
|
|
11355
|
+
* const upload = await sv.vaults.getUploadConfig('vlt_abc');
|
|
11356
|
+
*/
|
|
11357
|
+
async getUploadConfig(vaultId) {
|
|
11358
|
+
const cleanId = this.normalizeVaultId(vaultId);
|
|
11359
|
+
const response = await this.http.get(`/v1/vaults/${cleanId}/upload`);
|
|
11360
|
+
return mapUploadSettings(response.data);
|
|
11361
|
+
}
|
|
11362
|
+
/**
|
|
11363
|
+
* Enable the public upload portal for a vault.
|
|
11364
|
+
*
|
|
11365
|
+
* @example
|
|
11366
|
+
* await sv.vaults.enableUploadPortal('vlt_abc', vmk);
|
|
11367
|
+
*/
|
|
11368
|
+
async enableUploadPortal(vaultId, vmk) {
|
|
11369
|
+
return this.toggleUploadChannel(vaultId, 'portal', 'enable', vmk);
|
|
11370
|
+
}
|
|
11371
|
+
/**
|
|
11372
|
+
* Disable the public upload portal for a vault.
|
|
11373
|
+
*
|
|
11374
|
+
* @example
|
|
11375
|
+
* await sv.vaults.disableUploadPortal('vlt_abc');
|
|
11376
|
+
*/
|
|
11377
|
+
async disableUploadPortal(vaultId) {
|
|
11378
|
+
return this.toggleUploadChannel(vaultId, 'portal', 'disable');
|
|
11379
|
+
}
|
|
11380
|
+
/**
|
|
11381
|
+
* Enable the upload widget for a vault.
|
|
11382
|
+
*
|
|
11383
|
+
* @example
|
|
11384
|
+
* await sv.vaults.enableUploadWidget('vlt_abc', vmk);
|
|
11385
|
+
*/
|
|
11386
|
+
async enableUploadWidget(vaultId, vmk) {
|
|
11387
|
+
return this.toggleUploadChannel(vaultId, 'widget', 'enable', vmk);
|
|
11388
|
+
}
|
|
11389
|
+
/**
|
|
11390
|
+
* Disable the upload widget for a vault.
|
|
11391
|
+
*
|
|
11392
|
+
* @example
|
|
11393
|
+
* await sv.vaults.disableUploadWidget('vlt_abc');
|
|
11394
|
+
*/
|
|
11395
|
+
async disableUploadWidget(vaultId) {
|
|
11396
|
+
return this.toggleUploadChannel(vaultId, 'widget', 'disable');
|
|
11397
|
+
}
|
|
11398
|
+
/**
|
|
11399
|
+
* Update a vault's upload settings (max size, notification email).
|
|
11400
|
+
*
|
|
11401
|
+
* @example
|
|
11402
|
+
* await sv.vaults.updateUploadConfig('vlt_abc', { maxSizeBytes: 1048576 });
|
|
11403
|
+
*/
|
|
11404
|
+
async updateUploadConfig(vaultId, config) {
|
|
11405
|
+
const cleanId = this.normalizeVaultId(vaultId);
|
|
11406
|
+
const body = {};
|
|
11407
|
+
if (config.maxSizeBytes !== undefined)
|
|
11408
|
+
body.max_size_bytes = config.maxSizeBytes;
|
|
11409
|
+
if (config.notificationEmail !== undefined)
|
|
11410
|
+
body.notification_email = config.notificationEmail;
|
|
11411
|
+
const response = await this.http.put(`/v1/vaults/${cleanId}/upload`, body);
|
|
11412
|
+
return mapUploadSettings(response.data);
|
|
11413
|
+
}
|
|
11414
|
+
async toggleUploadChannel(vaultId, channel, action, vmk) {
|
|
11415
|
+
const cleanId = this.normalizeVaultId(vaultId);
|
|
11416
|
+
if (action === 'enable' && !vmk) {
|
|
11417
|
+
throw new ValidationError('VMK is required');
|
|
11225
11418
|
}
|
|
11226
|
-
const
|
|
11227
|
-
|
|
11228
|
-
|
|
11229
|
-
|
|
11230
|
-
|
|
11419
|
+
const response = await this.http.post(`/v1/vaults/${cleanId}/upload/${channel}/${action}`, action === 'enable' ? { vmk } : undefined);
|
|
11420
|
+
const d = response.data;
|
|
11421
|
+
return {
|
|
11422
|
+
vaultId: d.vault_id,
|
|
11423
|
+
uploadPortalEnabled: d.upload_portal_enabled ?? (channel === 'portal' && action === 'enable'),
|
|
11424
|
+
uploadPortalEnabledAt: channel === 'portal' && action === 'enable' ? d.enabled_at ?? null : null,
|
|
11425
|
+
uploadWidgetEnabled: d.upload_widget_enabled ?? (channel === 'widget' && action === 'enable'),
|
|
11426
|
+
uploadWidgetEnabledAt: channel === 'widget' && action === 'enable' ? d.enabled_at ?? null : null,
|
|
11427
|
+
maxSizeBytes: null,
|
|
11428
|
+
notificationEmail: null,
|
|
11429
|
+
portalUrl: d.portal_url,
|
|
11430
|
+
};
|
|
11431
|
+
}
|
|
11432
|
+
normalizeVaultId(vaultId) {
|
|
11433
|
+
if (!vaultId) {
|
|
11434
|
+
throw new ValidationError('Vault ID is required');
|
|
11435
|
+
}
|
|
11436
|
+
return vaultId.startsWith('vlt_') ? vaultId : `vlt_${vaultId}`;
|
|
11437
|
+
}
|
|
11438
|
+
validateCreateOptions(options) {
|
|
11439
|
+
if (!options.name?.trim()) {
|
|
11440
|
+
throw new ValidationError('Vault name is required');
|
|
11441
|
+
}
|
|
11442
|
+
if (options.name.length > 255) {
|
|
11443
|
+
throw new ValidationError('Vault name must be 255 characters or less');
|
|
11444
|
+
}
|
|
11445
|
+
}
|
|
11446
|
+
}
|
|
11447
|
+
function mapSharingConfig$1(wire) {
|
|
11448
|
+
return {
|
|
11449
|
+
vaultId: wire.vault_id,
|
|
11450
|
+
publicSharingEnabled: wire.public_sharing_enabled,
|
|
11451
|
+
allIngotsPublic: wire.all_ingots_public,
|
|
11452
|
+
sessionLengthSeconds: wire.session_length_seconds ?? null,
|
|
11453
|
+
enabledAt: wire.enabled_at ?? null,
|
|
11454
|
+
};
|
|
11455
|
+
}
|
|
11456
|
+
function mapUploadSettings(wire) {
|
|
11457
|
+
return {
|
|
11458
|
+
vaultId: wire.vault_id,
|
|
11459
|
+
uploadPortalEnabled: wire.upload_portal_enabled,
|
|
11460
|
+
uploadPortalEnabledAt: wire.upload_portal_enabled_at ?? null,
|
|
11461
|
+
uploadWidgetEnabled: wire.upload_widget_enabled,
|
|
11462
|
+
uploadWidgetEnabledAt: wire.upload_widget_enabled_at ?? null,
|
|
11463
|
+
maxSizeBytes: wire.max_size_bytes ?? null,
|
|
11464
|
+
notificationEmail: wire.notification_email ?? null,
|
|
11465
|
+
portalUrl: wire.portal_url,
|
|
11466
|
+
};
|
|
11467
|
+
}
|
|
11468
|
+
|
|
11469
|
+
/**
|
|
11470
|
+
* Ingots Module
|
|
11471
|
+
*
|
|
11472
|
+
* Data-plane operations on the contents of an *unsealed* vault. Every method
|
|
11473
|
+
* takes the {@link UnsealedVault} returned by `sv.vaults.unseal(...)` and
|
|
11474
|
+
* authenticates with its short-lived Vault Access Token (VAT).
|
|
11475
|
+
*
|
|
11476
|
+
* Uploads and downloads run over the single canonical Forge TUS transfer path
|
|
11477
|
+
* (shared with the public upload widget), with server-side finalization and
|
|
11478
|
+
* download-host allowlisting enforced — no per-size branching.
|
|
11479
|
+
*/
|
|
11480
|
+
const DOWNLOAD_MAX_ATTEMPTS = 3;
|
|
11481
|
+
const DOWNLOAD_RETRY_BASE_MS = 500;
|
|
11482
|
+
const DOWNLOAD_FETCH_TIMEOUT_MS = 300000;
|
|
11483
|
+
class IngotsModule {
|
|
11484
|
+
constructor(config, http) {
|
|
11485
|
+
this.config = config;
|
|
11486
|
+
this.http = http;
|
|
11487
|
+
this.uploadApi = new UploadApi(config);
|
|
11488
|
+
}
|
|
11489
|
+
/**
|
|
11490
|
+
* Create an ingot upload session (discrete primitive).
|
|
11491
|
+
*
|
|
11492
|
+
* Reserves the ingot record and returns the Forge upload URL (carrying the
|
|
11493
|
+
* ISTK upload session token). Use this when you want to drive the TUS
|
|
11494
|
+
* transfer yourself; otherwise prefer {@link upload}.
|
|
11495
|
+
*
|
|
11496
|
+
* @example
|
|
11497
|
+
* const session = await sv.ingots.createUpload({
|
|
11498
|
+
* vault: unsealed, name: 'report.pdf',
|
|
11499
|
+
* contentType: 'application/pdf', sizeBytes: file.size,
|
|
11500
|
+
* });
|
|
11501
|
+
* console.log(session.uploadUrl);
|
|
11502
|
+
*/
|
|
11503
|
+
async createUpload(options) {
|
|
11504
|
+
if (!options.name?.trim()) {
|
|
11505
|
+
throw new ValidationError('Ingot name is required');
|
|
11506
|
+
}
|
|
11507
|
+
if (!Number.isFinite(options.sizeBytes) || options.sizeBytes < 1) {
|
|
11508
|
+
throw new ValidationError('sizeBytes must be a positive number');
|
|
11509
|
+
}
|
|
11510
|
+
if (options.folder && options.folderId) {
|
|
11511
|
+
throw new ValidationError('Provide folder or folderId, not both');
|
|
11512
|
+
}
|
|
11513
|
+
const created = await this.requestUploadSession(options.vault, {
|
|
11514
|
+
name: options.name,
|
|
11515
|
+
content_type: options.contentType,
|
|
11516
|
+
size_bytes: options.sizeBytes,
|
|
11517
|
+
folder: options.folder,
|
|
11518
|
+
folderId: options.folderId,
|
|
11519
|
+
});
|
|
11231
11520
|
return {
|
|
11232
11521
|
id: created.ingot_id,
|
|
11233
11522
|
name: created.name,
|
|
11234
11523
|
contentType: created.content_type,
|
|
11235
11524
|
size: created.size_bytes,
|
|
11236
|
-
|
|
11525
|
+
uploadUrl: created.forge_url,
|
|
11526
|
+
expiresAt: created.expires_at,
|
|
11237
11527
|
};
|
|
11238
11528
|
}
|
|
11239
11529
|
/**
|
|
11240
|
-
*
|
|
11530
|
+
* Upload a file as a new ingot (high-level flow).
|
|
11531
|
+
*
|
|
11532
|
+
* Creates the upload session, streams the file to Forge over TUS, then
|
|
11533
|
+
* confirms the server finalized the upload before resolving.
|
|
11534
|
+
*
|
|
11535
|
+
* @example
|
|
11536
|
+
* const ingot = await sv.ingots.upload(unsealed, {
|
|
11537
|
+
* file: myFile, name: 'document.pdf'
|
|
11538
|
+
* });
|
|
11539
|
+
*/
|
|
11540
|
+
async upload(vault, options) {
|
|
11541
|
+
this.validateFile(options.file);
|
|
11542
|
+
if (options.folder && options.folderId) {
|
|
11543
|
+
throw new ValidationError('Provide folder or folderId, not both');
|
|
11544
|
+
}
|
|
11545
|
+
const name = options.name ?? getBlobName(options.file);
|
|
11546
|
+
const contentType = options.contentType ?? options.file.type ?? 'application/octet-stream';
|
|
11547
|
+
const created = await this.requestUploadSession(vault, {
|
|
11548
|
+
name,
|
|
11549
|
+
content_type: contentType,
|
|
11550
|
+
size_bytes: options.file.size,
|
|
11551
|
+
folder: options.folder,
|
|
11552
|
+
folderId: options.folderId,
|
|
11553
|
+
});
|
|
11554
|
+
return this.transferAndFinalize(created, options.file, options.onProgress);
|
|
11555
|
+
}
|
|
11556
|
+
/**
|
|
11557
|
+
* Replace an existing ingot's content (high-level flow).
|
|
11558
|
+
*
|
|
11559
|
+
* @example
|
|
11560
|
+
* await sv.ingots.replace(unsealed, 'ing_abc', { file: updatedFile });
|
|
11561
|
+
*/
|
|
11562
|
+
async replace(vault, ingotId, options) {
|
|
11563
|
+
this.validateFile(options.file);
|
|
11564
|
+
const cleanId = normalizeIngotId(ingotId);
|
|
11565
|
+
const name = options.name ?? getBlobName(options.file);
|
|
11566
|
+
const contentType = options.contentType ?? options.file.type ?? 'application/octet-stream';
|
|
11567
|
+
const response = await this.http.put(`/v1/vaults/${vault.id}/ingots/${cleanId}`, { name, content_type: contentType, size_bytes: options.file.size }, { headers: { 'X-Vault-Access-Token': vault.vatToken } });
|
|
11568
|
+
if (!response.data.forge_url) {
|
|
11569
|
+
throw new ValidationError('Replace endpoint did not return a Forge upload URL');
|
|
11570
|
+
}
|
|
11571
|
+
return this.transferAndFinalize(response.data, options.file, options.onProgress);
|
|
11572
|
+
}
|
|
11573
|
+
/**
|
|
11574
|
+
* Rename an ingot.
|
|
11575
|
+
*
|
|
11576
|
+
* @example
|
|
11577
|
+
* await sv.ingots.rename(unsealed, 'ing_abc', 'new-name.pdf');
|
|
11578
|
+
*/
|
|
11579
|
+
async rename(vault, ingotId, name) {
|
|
11580
|
+
if (!name?.trim()) {
|
|
11581
|
+
throw new ValidationError('Ingot name is required');
|
|
11582
|
+
}
|
|
11583
|
+
const cleanId = normalizeIngotId(ingotId);
|
|
11584
|
+
const response = await this.http.patch(`/v1/vaults/${vault.id}/ingots/${cleanId}`, { name }, { headers: { 'X-Vault-Access-Token': vault.vatToken } });
|
|
11585
|
+
return mapIngot(response.data);
|
|
11586
|
+
}
|
|
11587
|
+
/**
|
|
11588
|
+
* Move an ingot to a folder, or to the vault root with `null`.
|
|
11589
|
+
*
|
|
11590
|
+
* @example
|
|
11591
|
+
* await sv.ingots.move(unsealed, 'ing_abc', 'fld_xyz');
|
|
11592
|
+
* await sv.ingots.move(unsealed, 'ing_abc', null); // root
|
|
11593
|
+
*/
|
|
11594
|
+
async move(vault, ingotId, folderId) {
|
|
11595
|
+
const cleanId = normalizeIngotId(ingotId);
|
|
11596
|
+
const response = await this.http.patch(`/v1/vaults/${vault.id}/ingots/${cleanId}`, { folder_id: folderId }, { headers: { 'X-Vault-Access-Token': vault.vatToken } });
|
|
11597
|
+
return mapIngot(response.data);
|
|
11598
|
+
}
|
|
11599
|
+
/**
|
|
11600
|
+
* Delete an ingot.
|
|
11601
|
+
*
|
|
11602
|
+
* @example
|
|
11603
|
+
* await sv.ingots.delete(unsealed, 'ing_abc');
|
|
11604
|
+
*/
|
|
11605
|
+
async delete(vault, ingotId) {
|
|
11606
|
+
const cleanId = normalizeIngotId(ingotId);
|
|
11607
|
+
await this.http.delete(`/v1/vaults/${vault.id}/ingots/${cleanId}`, {
|
|
11608
|
+
headers: { 'X-Vault-Access-Token': vault.vatToken },
|
|
11609
|
+
});
|
|
11610
|
+
}
|
|
11611
|
+
/**
|
|
11612
|
+
* Get ingot metadata.
|
|
11613
|
+
*
|
|
11614
|
+
* @example
|
|
11615
|
+
* const ingot = await sv.ingots.get(unsealed, 'ing_abc');
|
|
11616
|
+
*/
|
|
11617
|
+
async get(vault, ingotId) {
|
|
11618
|
+
const cleanId = normalizeIngotId(ingotId);
|
|
11619
|
+
const response = await this.http.get(`/v1/vaults/${vault.id}/ingots/${cleanId}`, { headers: { 'X-Vault-Access-Token': vault.vatToken } });
|
|
11620
|
+
return mapIngot(response.data);
|
|
11621
|
+
}
|
|
11622
|
+
/**
|
|
11623
|
+
* List ingots in an unsealed vault.
|
|
11624
|
+
*
|
|
11625
|
+
* @example
|
|
11626
|
+
* const { ingots } = await sv.ingots.list(unsealed);
|
|
11627
|
+
*/
|
|
11628
|
+
async list(vault, options = {}) {
|
|
11629
|
+
const query = buildQuery$1({
|
|
11630
|
+
limit: options.limit,
|
|
11631
|
+
cursor: options.cursor,
|
|
11632
|
+
sort_by: options.sortBy,
|
|
11633
|
+
sort_order: options.sortOrder,
|
|
11634
|
+
});
|
|
11635
|
+
const response = await this.http.get(`/v1/vaults/${vault.id}/ingots${query}`, { headers: { 'X-Vault-Access-Token': vault.vatToken } });
|
|
11636
|
+
return mapIngotPage(response.data);
|
|
11637
|
+
}
|
|
11638
|
+
/**
|
|
11639
|
+
* Search ingots in an unsealed vault.
|
|
11640
|
+
*
|
|
11641
|
+
* @example
|
|
11642
|
+
* const { ingots } = await sv.ingots.search(unsealed, { q: 'invoice' });
|
|
11643
|
+
*/
|
|
11644
|
+
async search(vault, options = {}) {
|
|
11645
|
+
const query = buildQuery$1({
|
|
11646
|
+
q: options.q,
|
|
11647
|
+
file_type: options.fileType,
|
|
11648
|
+
min_size: options.minSize,
|
|
11649
|
+
max_size: options.maxSize,
|
|
11650
|
+
limit: options.limit,
|
|
11651
|
+
cursor: options.cursor,
|
|
11652
|
+
sort_order: options.sortOrder,
|
|
11653
|
+
});
|
|
11654
|
+
const response = await this.http.get(`/v1/vaults/${vault.id}/ingots/search${query}`, { headers: { 'X-Vault-Access-Token': vault.vatToken } });
|
|
11655
|
+
return mapIngotPage(response.data);
|
|
11656
|
+
}
|
|
11657
|
+
/**
|
|
11658
|
+
* List the contents (ingots) of a folder, or the vault root.
|
|
11659
|
+
*
|
|
11660
|
+
* @example
|
|
11661
|
+
* const { ingots } = await sv.ingots.listContents(unsealed, { folderId: 'fld_x' });
|
|
11662
|
+
*/
|
|
11663
|
+
async listContents(vault, options = {}) {
|
|
11664
|
+
const query = buildQuery$1({
|
|
11665
|
+
folder_id: options.folderId,
|
|
11666
|
+
limit: options.limit,
|
|
11667
|
+
cursor: options.cursor,
|
|
11668
|
+
sort_by: options.sortBy,
|
|
11669
|
+
sort_order: options.sortOrder,
|
|
11670
|
+
type: options.type,
|
|
11671
|
+
});
|
|
11672
|
+
const response = await this.http.get(`/v1/vaults/${vault.id}/contents${query}`, { headers: { 'X-Vault-Access-Token': vault.vatToken } });
|
|
11673
|
+
return mapIngotPage(response.data);
|
|
11674
|
+
}
|
|
11675
|
+
/**
|
|
11676
|
+
* Create a signed download link for an ingot (discrete primitive).
|
|
11677
|
+
*
|
|
11678
|
+
* Validates the returned URL against the download-host allowlist. Use this
|
|
11679
|
+
* when you want the URL itself; otherwise prefer {@link download}.
|
|
11241
11680
|
*
|
|
11242
11681
|
* @example
|
|
11243
|
-
* const
|
|
11682
|
+
* const link = await sv.ingots.createDownloadLink(unsealed, 'ing_abc');
|
|
11683
|
+
* window.location.href = link.downloadUrl;
|
|
11684
|
+
*/
|
|
11685
|
+
async createDownloadLink(vault, ingotId) {
|
|
11686
|
+
const cleanId = normalizeIngotId(ingotId);
|
|
11687
|
+
const response = await this.http.post(`/v1/vaults/${vault.id}/ingots/${cleanId}/download`, undefined, { headers: { 'X-Vault-Access-Token': vault.vatToken } });
|
|
11688
|
+
if (!response.data.download_url) {
|
|
11689
|
+
throw new ValidationError('Download endpoint did not return a download URL');
|
|
11690
|
+
}
|
|
11691
|
+
this.validateDownloadUrl(response.data.download_url);
|
|
11692
|
+
return {
|
|
11693
|
+
downloadUrl: response.data.download_url,
|
|
11694
|
+
id: response.data.ingot_id,
|
|
11695
|
+
name: response.data.name,
|
|
11696
|
+
size: response.data.size_bytes,
|
|
11697
|
+
contentType: response.data.content_type,
|
|
11698
|
+
};
|
|
11699
|
+
}
|
|
11700
|
+
/**
|
|
11701
|
+
* Download an ingot as a Blob (high-level flow).
|
|
11702
|
+
*
|
|
11703
|
+
* Requests a fresh signed link on every attempt (server URLs are
|
|
11704
|
+
* short-lived) and retries transient transport failures with exponential
|
|
11705
|
+
* backoff. Validation failures (bad host, non-HTTPS) are never retried.
|
|
11706
|
+
*
|
|
11707
|
+
* @example
|
|
11708
|
+
* const blob = await sv.ingots.download(unsealed, 'ing_abc');
|
|
11244
11709
|
* const url = URL.createObjectURL(blob);
|
|
11245
11710
|
*/
|
|
11246
|
-
async
|
|
11247
|
-
const cleanId = ingotId.startsWith('ing_') ? ingotId : `ing_${ingotId}`;
|
|
11711
|
+
async download(vault, ingotId) {
|
|
11248
11712
|
let lastError = null;
|
|
11249
11713
|
for (let attempt = 1; attempt <= DOWNLOAD_MAX_ATTEMPTS; attempt++) {
|
|
11250
11714
|
try {
|
|
11251
|
-
const
|
|
11252
|
-
|
|
11253
|
-
});
|
|
11254
|
-
if (!response.data.download_url) {
|
|
11255
|
-
throw new ValidationError('Download endpoint did not return a download URL');
|
|
11256
|
-
}
|
|
11257
|
-
this.validateDownloadUrl(response.data.download_url);
|
|
11258
|
-
return await fetchBlobWithTimeout(response.data.download_url);
|
|
11715
|
+
const link = await this.createDownloadLink(vault, ingotId);
|
|
11716
|
+
return await fetchBlobWithTimeout(link.downloadUrl, DOWNLOAD_FETCH_TIMEOUT_MS);
|
|
11259
11717
|
}
|
|
11260
11718
|
catch (err) {
|
|
11261
11719
|
lastError = err instanceof Error ? err : new Error(String(err));
|
|
@@ -11268,49 +11726,118 @@ class VaultsModule {
|
|
|
11268
11726
|
throw lastError ?? new Error('Download failed');
|
|
11269
11727
|
}
|
|
11270
11728
|
/**
|
|
11271
|
-
*
|
|
11729
|
+
* Get an ingot's sharing configuration.
|
|
11272
11730
|
*
|
|
11273
11731
|
* @example
|
|
11274
|
-
* const
|
|
11275
|
-
* ingots.forEach(i => console.log(i.name, i.size));
|
|
11732
|
+
* const sharing = await sv.ingots.getSharingConfig(unsealed, 'ing_abc');
|
|
11276
11733
|
*/
|
|
11277
|
-
async
|
|
11278
|
-
const
|
|
11279
|
-
|
|
11280
|
-
|
|
11281
|
-
return response.data.ingots.map((i) => ({
|
|
11282
|
-
id: i.ingot_id,
|
|
11283
|
-
name: i.name,
|
|
11284
|
-
contentType: i.content_type,
|
|
11285
|
-
size: i.size_bytes,
|
|
11286
|
-
createdAt: i.created_at,
|
|
11287
|
-
}));
|
|
11734
|
+
async getSharingConfig(vault, ingotId) {
|
|
11735
|
+
const cleanId = normalizeIngotId(ingotId);
|
|
11736
|
+
const response = await this.http.get(`/v1/vaults/${vault.id}/ingots/${cleanId}/sharing`, { headers: { 'X-Vault-Access-Token': vault.vatToken } });
|
|
11737
|
+
return mapSharingConfig(response.data);
|
|
11288
11738
|
}
|
|
11289
11739
|
/**
|
|
11290
|
-
*
|
|
11740
|
+
* Update an ingot's sharing configuration.
|
|
11291
11741
|
*
|
|
11292
11742
|
* @example
|
|
11293
|
-
* await sv.
|
|
11743
|
+
* await sv.ingots.updateSharingConfig(unsealed, 'ing_abc', { shared: true });
|
|
11294
11744
|
*/
|
|
11295
|
-
async
|
|
11296
|
-
const cleanId = ingotId
|
|
11297
|
-
await this.http.
|
|
11298
|
-
|
|
11299
|
-
});
|
|
11745
|
+
async updateSharingConfig(vault, ingotId, config) {
|
|
11746
|
+
const cleanId = normalizeIngotId(ingotId);
|
|
11747
|
+
const response = await this.http.put(`/v1/vaults/${vault.id}/ingots/${cleanId}/sharing`, { shared: config.shared, visibility: config.visibility }, { headers: { 'X-Vault-Access-Token': vault.vatToken } });
|
|
11748
|
+
return mapSharingConfig(response.data);
|
|
11300
11749
|
}
|
|
11301
|
-
|
|
11302
|
-
|
|
11303
|
-
|
|
11750
|
+
/**
|
|
11751
|
+
* Invite an identity to a shared ingot. The identity type (email or phone)
|
|
11752
|
+
* is inferred server-side from the identity value.
|
|
11753
|
+
*
|
|
11754
|
+
* @example
|
|
11755
|
+
* await sv.ingots.addInvite(unsealed, 'ing_abc', 'user@example.com');
|
|
11756
|
+
* await sv.ingots.addInvite(unsealed, 'ing_abc', 'user@example.com', { expiresInSeconds: 86400 });
|
|
11757
|
+
*/
|
|
11758
|
+
async addInvite(vault, ingotId, identity, options = {}) {
|
|
11759
|
+
if (!identity?.trim()) {
|
|
11760
|
+
throw new ValidationError('Invite identity is required');
|
|
11304
11761
|
}
|
|
11305
|
-
|
|
11306
|
-
|
|
11762
|
+
const cleanId = normalizeIngotId(ingotId);
|
|
11763
|
+
const response = await this.http.post(`/v1/vaults/${vault.id}/ingots/${cleanId}/sharing/invite`, { identity, expires_in_seconds: options.expiresInSeconds }, { headers: { 'X-Vault-Access-Token': vault.vatToken } });
|
|
11764
|
+
return mapInvite(response.data);
|
|
11765
|
+
}
|
|
11766
|
+
/**
|
|
11767
|
+
* Revoke an ingot sharing invite.
|
|
11768
|
+
*
|
|
11769
|
+
* @example
|
|
11770
|
+
* await sv.ingots.revokeInvite(unsealed, 'ing_abc', 'inv_123');
|
|
11771
|
+
*/
|
|
11772
|
+
async revokeInvite(vault, ingotId, inviteId) {
|
|
11773
|
+
if (!inviteId?.trim()) {
|
|
11774
|
+
throw new ValidationError('Invite ID is required');
|
|
11775
|
+
}
|
|
11776
|
+
const cleanId = normalizeIngotId(ingotId);
|
|
11777
|
+
await this.http.delete(`/v1/vaults/${vault.id}/ingots/${cleanId}/sharing/invite/${inviteId}`, { headers: { 'X-Vault-Access-Token': vault.vatToken } });
|
|
11778
|
+
}
|
|
11779
|
+
/**
|
|
11780
|
+
* Get an ingot's access logs.
|
|
11781
|
+
*
|
|
11782
|
+
* @example
|
|
11783
|
+
* const { logs } = await sv.ingots.getAccessLogs(unsealed, 'ing_abc');
|
|
11784
|
+
*/
|
|
11785
|
+
async getAccessLogs(vault, ingotId, options = {}) {
|
|
11786
|
+
const cleanId = normalizeIngotId(ingotId);
|
|
11787
|
+
const query = buildQuery$1({ limit: options.limit, cursor: options.cursor });
|
|
11788
|
+
const response = await this.http.get(`/v1/vaults/${vault.id}/ingots/${cleanId}/audit-logs${query}`, { headers: { 'X-Vault-Access-Token': vault.vatToken } });
|
|
11789
|
+
const entries = response.data.entries ?? [];
|
|
11790
|
+
return {
|
|
11791
|
+
logs: entries.map(mapAccessLog),
|
|
11792
|
+
nextCursor: response.data.next_cursor,
|
|
11793
|
+
};
|
|
11794
|
+
}
|
|
11795
|
+
/**
|
|
11796
|
+
* Request a Forge upload session for a new ingot.
|
|
11797
|
+
* Shared by createUpload and upload — the single ingot-create path.
|
|
11798
|
+
*/
|
|
11799
|
+
async requestUploadSession(vault, body) {
|
|
11800
|
+
const payload = {
|
|
11801
|
+
name: body.name,
|
|
11802
|
+
content_type: body.content_type ?? 'application/octet-stream',
|
|
11803
|
+
size_bytes: body.size_bytes,
|
|
11804
|
+
};
|
|
11805
|
+
// folder_path (find-or-create) and folder_id (existing folder) are
|
|
11806
|
+
// mutually exclusive server-side; a path takes precedence when both given.
|
|
11807
|
+
if (body.folder) {
|
|
11808
|
+
payload.folder_path = body.folder;
|
|
11307
11809
|
}
|
|
11810
|
+
else if (body.folderId) {
|
|
11811
|
+
payload.folder_id = body.folderId;
|
|
11812
|
+
}
|
|
11813
|
+
const response = await this.http.post(`/v1/vaults/${vault.id}/ingots`, payload, { headers: { 'X-Vault-Access-Token': vault.vatToken } });
|
|
11814
|
+
if (!response.data.forge_url) {
|
|
11815
|
+
throw new ValidationError('Upload endpoint did not return a Forge upload URL');
|
|
11816
|
+
}
|
|
11817
|
+
return response.data;
|
|
11818
|
+
}
|
|
11819
|
+
/**
|
|
11820
|
+
* Run the canonical TUS transfer for a created/replaced ingot, then confirm
|
|
11821
|
+
* the server finalized the upload before reporting success.
|
|
11822
|
+
*/
|
|
11823
|
+
async transferAndFinalize(created, file, onProgress) {
|
|
11824
|
+
const uploadUrl = await this.uploadApi.uploadFileToForge(file, created.forge_url, onProgress);
|
|
11825
|
+
// Confirm the server actually finalized the upload before reporting
|
|
11826
|
+
// success — the TUS loop's offsets alone don't prove the final chunk
|
|
11827
|
+
// committed and the ingot went active.
|
|
11828
|
+
await this.uploadApi.verifyUploadFinalized(uploadUrl, file.size);
|
|
11829
|
+
return {
|
|
11830
|
+
id: created.ingot_id,
|
|
11831
|
+
name: created.name,
|
|
11832
|
+
contentType: created.content_type,
|
|
11833
|
+
size: created.size_bytes,
|
|
11834
|
+
};
|
|
11308
11835
|
}
|
|
11309
|
-
|
|
11310
|
-
if (!
|
|
11836
|
+
validateFile(file) {
|
|
11837
|
+
if (!file) {
|
|
11311
11838
|
throw new ValidationError('File is required');
|
|
11312
11839
|
}
|
|
11313
|
-
if (
|
|
11840
|
+
if (file.size === 0) {
|
|
11314
11841
|
throw new ValidationError('File cannot be empty');
|
|
11315
11842
|
}
|
|
11316
11843
|
}
|
|
@@ -11326,7 +11853,7 @@ class VaultsModule {
|
|
|
11326
11853
|
throw new ValidationError('Download URL must use HTTPS');
|
|
11327
11854
|
}
|
|
11328
11855
|
const allowedHosts = this.config.allowedDownloadHostPatterns;
|
|
11329
|
-
if (!allowedHosts.some(pattern => pattern.test(parsed.hostname))) {
|
|
11856
|
+
if (!allowedHosts.some((pattern) => pattern.test(parsed.hostname))) {
|
|
11330
11857
|
throw new ValidationError('Invalid download URL from server');
|
|
11331
11858
|
}
|
|
11332
11859
|
}
|
|
@@ -11337,24 +11864,89 @@ function getBlobName(file) {
|
|
|
11337
11864
|
}
|
|
11338
11865
|
return 'unnamed';
|
|
11339
11866
|
}
|
|
11340
|
-
|
|
11341
|
-
|
|
11867
|
+
function normalizeIngotId(ingotId) {
|
|
11868
|
+
if (!ingotId) {
|
|
11869
|
+
throw new ValidationError('Ingot ID is required');
|
|
11870
|
+
}
|
|
11871
|
+
return ingotId.startsWith('ing_') ? ingotId : `ing_${ingotId}`;
|
|
11872
|
+
}
|
|
11873
|
+
function mapIngot(wire) {
|
|
11874
|
+
return {
|
|
11875
|
+
id: wire.ingot_id,
|
|
11876
|
+
name: wire.name,
|
|
11877
|
+
contentType: wire.content_type,
|
|
11878
|
+
size: wire.size_bytes,
|
|
11879
|
+
status: wire.status ?? 'active',
|
|
11880
|
+
createdAt: wire.created_at ?? 0,
|
|
11881
|
+
folderId: wire.folder_id ?? null,
|
|
11882
|
+
};
|
|
11883
|
+
}
|
|
11884
|
+
function mapIngotPage(response) {
|
|
11885
|
+
return {
|
|
11886
|
+
ingots: (response.ingots ?? []).map(mapIngot),
|
|
11887
|
+
nextCursor: response.next_cursor,
|
|
11888
|
+
};
|
|
11889
|
+
}
|
|
11890
|
+
function mapSharingConfig(wire) {
|
|
11891
|
+
return {
|
|
11892
|
+
shared: wire.shared,
|
|
11893
|
+
visibility: wire.visibility,
|
|
11894
|
+
invites: wire.invites?.map(mapInvite),
|
|
11895
|
+
};
|
|
11896
|
+
}
|
|
11897
|
+
function mapInvite(wire) {
|
|
11898
|
+
return {
|
|
11899
|
+
id: wire.id ?? wire.invite_id ?? '',
|
|
11900
|
+
identity: wire.identity,
|
|
11901
|
+
identityType: wire.identity_type ?? 'email',
|
|
11902
|
+
};
|
|
11903
|
+
}
|
|
11904
|
+
function mapAccessLog(entry) {
|
|
11905
|
+
const eventType = entry.event_type ?? entry.action ?? '';
|
|
11906
|
+
const action = eventType.includes('download') ? 'download' : 'view';
|
|
11907
|
+
const actor = entry.actor;
|
|
11908
|
+
return {
|
|
11909
|
+
id: entry.log_id ?? entry.event_id ?? entry.id ?? String(entry.timestamp ?? entry.created_at ?? ''),
|
|
11910
|
+
action,
|
|
11911
|
+
identity: actor?.email ??
|
|
11912
|
+
entry.actor_email ??
|
|
11913
|
+
entry.identity ??
|
|
11914
|
+
actor?.id ??
|
|
11915
|
+
actor?.user_id ??
|
|
11916
|
+
actor?.api_key_id ??
|
|
11917
|
+
entry.actor_id ??
|
|
11918
|
+
'Unknown',
|
|
11919
|
+
ipAddress: entry.ip_address ?? '',
|
|
11920
|
+
userAgent: entry.user_agent ?? '',
|
|
11921
|
+
timestamp: entry.timestamp ?? entry.created_at ?? 0,
|
|
11922
|
+
};
|
|
11923
|
+
}
|
|
11924
|
+
function buildQuery$1(params) {
|
|
11925
|
+
const search = new URLSearchParams();
|
|
11926
|
+
for (const [key, value] of Object.entries(params)) {
|
|
11927
|
+
if (value === undefined || value === null || value === '')
|
|
11928
|
+
continue;
|
|
11929
|
+
search.append(key, String(value));
|
|
11930
|
+
}
|
|
11931
|
+
const query = search.toString();
|
|
11932
|
+
return query ? `?${query}` : '';
|
|
11933
|
+
}
|
|
11342
11934
|
function delayExponential(attempt) {
|
|
11343
|
-
return new Promise(resolve => setTimeout(resolve, DOWNLOAD_RETRY_BASE_MS * 2 ** (attempt - 1)));
|
|
11935
|
+
return new Promise((resolve) => setTimeout(resolve, DOWNLOAD_RETRY_BASE_MS * 2 ** (attempt - 1)));
|
|
11344
11936
|
}
|
|
11345
11937
|
function isRetryableDownloadError(err) {
|
|
11346
11938
|
// Server contract / client-side validation errors aren't fixed by retrying.
|
|
11347
11939
|
if (err instanceof ValidationError)
|
|
11348
11940
|
return false;
|
|
11349
|
-
// Network errors carry a status code only when
|
|
11350
|
-
//
|
|
11941
|
+
// Network errors carry a status code only when one was attached; treat any
|
|
11942
|
+
// explicitly-4xx response (except 408/429) as a permanent failure.
|
|
11351
11943
|
const status = err.statusCode;
|
|
11352
11944
|
if (typeof status === 'number' && status >= 400 && status < 500 && status !== 408 && status !== 429) {
|
|
11353
11945
|
return false;
|
|
11354
11946
|
}
|
|
11355
11947
|
return true;
|
|
11356
11948
|
}
|
|
11357
|
-
async function fetchBlobWithTimeout(url, timeout
|
|
11949
|
+
async function fetchBlobWithTimeout(url, timeout) {
|
|
11358
11950
|
const controller = new AbortController();
|
|
11359
11951
|
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
11360
11952
|
try {
|
|
@@ -11364,13 +11956,386 @@ async function fetchBlobWithTimeout(url, timeout = 300000) {
|
|
|
11364
11956
|
error.statusCode = response.status;
|
|
11365
11957
|
throw error;
|
|
11366
11958
|
}
|
|
11367
|
-
return response.blob();
|
|
11959
|
+
return await response.blob();
|
|
11368
11960
|
}
|
|
11369
11961
|
finally {
|
|
11370
11962
|
clearTimeout(timeoutId);
|
|
11371
11963
|
}
|
|
11372
11964
|
}
|
|
11373
11965
|
|
|
11966
|
+
/**
|
|
11967
|
+
* Folders Module
|
|
11968
|
+
*
|
|
11969
|
+
* Organize ingots within an *unsealed* vault. Every method takes the
|
|
11970
|
+
* {@link UnsealedVault} returned by `sv.vaults.unseal(...)` and authenticates
|
|
11971
|
+
* with its short-lived Vault Access Token (VAT).
|
|
11972
|
+
*/
|
|
11973
|
+
class FoldersModule {
|
|
11974
|
+
constructor(http) {
|
|
11975
|
+
this.http = http;
|
|
11976
|
+
}
|
|
11977
|
+
/**
|
|
11978
|
+
* List all folders in a vault (flat list — build the tree client-side).
|
|
11979
|
+
*
|
|
11980
|
+
* @example
|
|
11981
|
+
* const folders = await sv.folders.list(unsealed);
|
|
11982
|
+
*/
|
|
11983
|
+
async list(vault) {
|
|
11984
|
+
const response = await this.http.get(`/v1/vaults/${vault.id}/folders`, { headers: { 'X-Vault-Access-Token': vault.vatToken } });
|
|
11985
|
+
return (response.data.folders ?? []).map(mapFolder);
|
|
11986
|
+
}
|
|
11987
|
+
/**
|
|
11988
|
+
* Get a single folder.
|
|
11989
|
+
*
|
|
11990
|
+
* @example
|
|
11991
|
+
* const folder = await sv.folders.get(unsealed, 'fld_abc');
|
|
11992
|
+
*/
|
|
11993
|
+
async get(vault, folderId) {
|
|
11994
|
+
const cleanId = requireFolderId(folderId);
|
|
11995
|
+
const response = await this.http.get(`/v1/vaults/${vault.id}/folders/${cleanId}`, { headers: { 'X-Vault-Access-Token': vault.vatToken } });
|
|
11996
|
+
return mapFolder(response.data);
|
|
11997
|
+
}
|
|
11998
|
+
/**
|
|
11999
|
+
* Get a folder's breadcrumb trail (Root → … → folder).
|
|
12000
|
+
*
|
|
12001
|
+
* @example
|
|
12002
|
+
* const trail = await sv.folders.getBreadcrumb(unsealed, 'fld_abc');
|
|
12003
|
+
*/
|
|
12004
|
+
async getBreadcrumb(vault, folderId) {
|
|
12005
|
+
const cleanId = requireFolderId(folderId);
|
|
12006
|
+
const response = await this.http.get(`/v1/vaults/${vault.id}/folders/${cleanId}`, { headers: { 'X-Vault-Access-Token': vault.vatToken } });
|
|
12007
|
+
return (response.data.breadcrumb ?? []).map((item) => ({
|
|
12008
|
+
id: item.folder_id,
|
|
12009
|
+
name: item.name,
|
|
12010
|
+
}));
|
|
12011
|
+
}
|
|
12012
|
+
/**
|
|
12013
|
+
* Create a folder.
|
|
12014
|
+
*
|
|
12015
|
+
* @example
|
|
12016
|
+
* const folder = await sv.folders.create(unsealed, { name: 'Invoices' });
|
|
12017
|
+
*/
|
|
12018
|
+
async create(vault, data) {
|
|
12019
|
+
if (!data.name?.trim()) {
|
|
12020
|
+
throw new ValidationError('Folder name is required');
|
|
12021
|
+
}
|
|
12022
|
+
const response = await this.http.post(`/v1/vaults/${vault.id}/folders`, { name: data.name, parent_id: data.parentId ?? null }, { headers: { 'X-Vault-Access-Token': vault.vatToken } });
|
|
12023
|
+
return mapFolder(response.data);
|
|
12024
|
+
}
|
|
12025
|
+
/**
|
|
12026
|
+
* Update a folder (rename, move, pin/unpin).
|
|
12027
|
+
*
|
|
12028
|
+
* @example
|
|
12029
|
+
* await sv.folders.update(unsealed, 'fld_abc', { name: 'Renamed' });
|
|
12030
|
+
*/
|
|
12031
|
+
async update(vault, folderId, data) {
|
|
12032
|
+
const cleanId = requireFolderId(folderId);
|
|
12033
|
+
const body = {};
|
|
12034
|
+
if (data.name !== undefined)
|
|
12035
|
+
body.name = data.name;
|
|
12036
|
+
if (data.parentId !== undefined)
|
|
12037
|
+
body.parent_id = data.parentId;
|
|
12038
|
+
if (data.pinned !== undefined)
|
|
12039
|
+
body.pinned = data.pinned;
|
|
12040
|
+
const response = await this.http.put(`/v1/vaults/${vault.id}/folders/${cleanId}`, body, { headers: { 'X-Vault-Access-Token': vault.vatToken } });
|
|
12041
|
+
return mapFolder(response.data);
|
|
12042
|
+
}
|
|
12043
|
+
/**
|
|
12044
|
+
* Move a folder under a new parent, or to the vault root with `null`.
|
|
12045
|
+
*
|
|
12046
|
+
* @example
|
|
12047
|
+
* await sv.folders.move(unsealed, 'fld_abc', 'fld_parent');
|
|
12048
|
+
*/
|
|
12049
|
+
move(vault, folderId, newParentId) {
|
|
12050
|
+
return this.update(vault, folderId, { parentId: newParentId });
|
|
12051
|
+
}
|
|
12052
|
+
/**
|
|
12053
|
+
* Pin or unpin a folder.
|
|
12054
|
+
*
|
|
12055
|
+
* @example
|
|
12056
|
+
* await sv.folders.togglePin(unsealed, 'fld_abc', true);
|
|
12057
|
+
*/
|
|
12058
|
+
togglePin(vault, folderId, pinned) {
|
|
12059
|
+
return this.update(vault, folderId, { pinned });
|
|
12060
|
+
}
|
|
12061
|
+
/**
|
|
12062
|
+
* Delete a folder.
|
|
12063
|
+
*
|
|
12064
|
+
* @example
|
|
12065
|
+
* await sv.folders.delete(unsealed, 'fld_abc');
|
|
12066
|
+
*/
|
|
12067
|
+
async delete(vault, folderId) {
|
|
12068
|
+
const cleanId = requireFolderId(folderId);
|
|
12069
|
+
await this.http.delete(`/v1/vaults/${vault.id}/folders/${cleanId}`, {
|
|
12070
|
+
headers: { 'X-Vault-Access-Token': vault.vatToken },
|
|
12071
|
+
});
|
|
12072
|
+
}
|
|
12073
|
+
/**
|
|
12074
|
+
* Move an ingot into a folder, or to the vault root with `null`.
|
|
12075
|
+
*
|
|
12076
|
+
* @example
|
|
12077
|
+
* await sv.folders.moveIngot(unsealed, 'ing_abc', 'fld_xyz');
|
|
12078
|
+
*/
|
|
12079
|
+
async moveIngot(vault, ingotId, folderId) {
|
|
12080
|
+
if (!ingotId) {
|
|
12081
|
+
throw new ValidationError('Ingot ID is required');
|
|
12082
|
+
}
|
|
12083
|
+
const cleanIngotId = ingotId.startsWith('ing_') ? ingotId : `ing_${ingotId}`;
|
|
12084
|
+
await this.http.patch(`/v1/vaults/${vault.id}/ingots/${cleanIngotId}`, { folder_id: folderId }, {
|
|
12085
|
+
headers: { 'X-Vault-Access-Token': vault.vatToken },
|
|
12086
|
+
});
|
|
12087
|
+
}
|
|
12088
|
+
}
|
|
12089
|
+
function requireFolderId(folderId) {
|
|
12090
|
+
if (!folderId) {
|
|
12091
|
+
throw new ValidationError('Folder ID is required');
|
|
12092
|
+
}
|
|
12093
|
+
return folderId;
|
|
12094
|
+
}
|
|
12095
|
+
function mapFolder(wire) {
|
|
12096
|
+
return {
|
|
12097
|
+
id: wire.folder_id,
|
|
12098
|
+
name: wire.name,
|
|
12099
|
+
parentId: wire.parent_id ?? null,
|
|
12100
|
+
pinned: wire.pinned ?? false,
|
|
12101
|
+
createdAt: wire.created_at ?? 0,
|
|
12102
|
+
updatedAt: wire.updated_at ?? 0,
|
|
12103
|
+
};
|
|
12104
|
+
}
|
|
12105
|
+
|
|
12106
|
+
/**
|
|
12107
|
+
* Sparks Module
|
|
12108
|
+
*
|
|
12109
|
+
* Create, read, share, and delete end-to-end encrypted, read-once ephemeral
|
|
12110
|
+
* secrets. Sparks are account-scoped — no vault or VAT is involved.
|
|
12111
|
+
*/
|
|
12112
|
+
class SparksModule {
|
|
12113
|
+
constructor(http) {
|
|
12114
|
+
this.http = http;
|
|
12115
|
+
}
|
|
12116
|
+
/**
|
|
12117
|
+
* List sparks for the account.
|
|
12118
|
+
*
|
|
12119
|
+
* @example
|
|
12120
|
+
* const { sparks } = await sv.sparks.list();
|
|
12121
|
+
*/
|
|
12122
|
+
async list(options = {}) {
|
|
12123
|
+
const query = buildQuery({
|
|
12124
|
+
kindling: options.kindling,
|
|
12125
|
+
status: options.status,
|
|
12126
|
+
limit: options.limit,
|
|
12127
|
+
cursor: options.cursor,
|
|
12128
|
+
});
|
|
12129
|
+
const response = await this.http.get(`/v1/sparks${query}`);
|
|
12130
|
+
return {
|
|
12131
|
+
sparks: (response.data.sparks ?? []).map(mapSummary),
|
|
12132
|
+
nextCursor: response.data.next_cursor,
|
|
12133
|
+
};
|
|
12134
|
+
}
|
|
12135
|
+
/**
|
|
12136
|
+
* Read (and burn) a spark. Reading is destructive — the spark can be read
|
|
12137
|
+
* exactly once.
|
|
12138
|
+
*
|
|
12139
|
+
* @example
|
|
12140
|
+
* const spark = await sv.sparks.get('spk_abc');
|
|
12141
|
+
* console.log(spark.payload);
|
|
12142
|
+
*/
|
|
12143
|
+
async get(sparkId) {
|
|
12144
|
+
requireSparkId(sparkId);
|
|
12145
|
+
const response = await this.http.get(`/v1/sparks/${encodeURIComponent(sparkId)}`);
|
|
12146
|
+
const data = response.data;
|
|
12147
|
+
return {
|
|
12148
|
+
id: data.spark_id,
|
|
12149
|
+
payload: data.payload,
|
|
12150
|
+
contentType: data.content_type ?? 'text/plain',
|
|
12151
|
+
size: data.size_bytes,
|
|
12152
|
+
status: data.status,
|
|
12153
|
+
createdAt: data.created_at,
|
|
12154
|
+
burnedAt: data.burned_at,
|
|
12155
|
+
filename: data.filename,
|
|
12156
|
+
};
|
|
12157
|
+
}
|
|
12158
|
+
/**
|
|
12159
|
+
* Create a spark.
|
|
12160
|
+
*
|
|
12161
|
+
* @example
|
|
12162
|
+
* const spark = await sv.sparks.create({ payload: 'top secret', ttlMinutes: 60 });
|
|
12163
|
+
*/
|
|
12164
|
+
async create(options) {
|
|
12165
|
+
if (typeof options.payload !== 'string' || options.payload.length === 0) {
|
|
12166
|
+
throw new ValidationError('Spark payload is required');
|
|
12167
|
+
}
|
|
12168
|
+
const body = {
|
|
12169
|
+
payload: options.payload,
|
|
12170
|
+
content_type: options.contentType,
|
|
12171
|
+
ttl_minutes: options.ttlMinutes,
|
|
12172
|
+
kindling: options.kindling,
|
|
12173
|
+
filename: options.filename,
|
|
12174
|
+
};
|
|
12175
|
+
if (options.withKindling) {
|
|
12176
|
+
body.with_kindling = true;
|
|
12177
|
+
}
|
|
12178
|
+
const response = await this.http.post('/v1/sparks', body);
|
|
12179
|
+
const data = response.data;
|
|
12180
|
+
return {
|
|
12181
|
+
id: data.spark_id,
|
|
12182
|
+
size: data.size_bytes,
|
|
12183
|
+
status: data.status,
|
|
12184
|
+
createdAt: data.created_at,
|
|
12185
|
+
expiresAt: data.expires_at,
|
|
12186
|
+
ttlMinutes: data.ttl_minutes,
|
|
12187
|
+
filename: data.filename,
|
|
12188
|
+
kindling: data.kindling,
|
|
12189
|
+
};
|
|
12190
|
+
}
|
|
12191
|
+
/**
|
|
12192
|
+
* Delete a spark.
|
|
12193
|
+
*
|
|
12194
|
+
* @example
|
|
12195
|
+
* await sv.sparks.delete('spk_abc');
|
|
12196
|
+
*/
|
|
12197
|
+
async delete(sparkId) {
|
|
12198
|
+
requireSparkId(sparkId);
|
|
12199
|
+
await this.http.delete(`/v1/sparks/${encodeURIComponent(sparkId)}`);
|
|
12200
|
+
}
|
|
12201
|
+
/**
|
|
12202
|
+
* Share a spark via a public SparkLink (x.sv URL).
|
|
12203
|
+
*
|
|
12204
|
+
* @example
|
|
12205
|
+
* const share = await sv.sparks.share('spk_abc', { visibility: 'public' });
|
|
12206
|
+
* console.log(share.shareUrl);
|
|
12207
|
+
*/
|
|
12208
|
+
async share(sparkId, options = {}) {
|
|
12209
|
+
requireSparkId(sparkId);
|
|
12210
|
+
const response = await this.http.patch(`/v1/sparks/${encodeURIComponent(sparkId)}/share`, {
|
|
12211
|
+
visibility: options.visibility,
|
|
12212
|
+
invites: options.invites,
|
|
12213
|
+
expires_in_seconds: options.expiresInSeconds,
|
|
12214
|
+
});
|
|
12215
|
+
return mapShare(response.data);
|
|
12216
|
+
}
|
|
12217
|
+
/**
|
|
12218
|
+
* Get a spark's sharing status.
|
|
12219
|
+
*
|
|
12220
|
+
* @example
|
|
12221
|
+
* const share = await sv.sparks.getShare('spk_abc');
|
|
12222
|
+
*/
|
|
12223
|
+
async getShare(sparkId) {
|
|
12224
|
+
requireSparkId(sparkId);
|
|
12225
|
+
const response = await this.http.get(`/v1/sparks/${encodeURIComponent(sparkId)}/share`);
|
|
12226
|
+
return mapShare(response.data);
|
|
12227
|
+
}
|
|
12228
|
+
/**
|
|
12229
|
+
* Unshare a spark (delete its SparkLink).
|
|
12230
|
+
*
|
|
12231
|
+
* @example
|
|
12232
|
+
* await sv.sparks.unshare('spk_abc');
|
|
12233
|
+
*/
|
|
12234
|
+
async unshare(sparkId) {
|
|
12235
|
+
requireSparkId(sparkId);
|
|
12236
|
+
const response = await this.http.delete(`/v1/sparks/${encodeURIComponent(sparkId)}/share`);
|
|
12237
|
+
return mapShare(response.data);
|
|
12238
|
+
}
|
|
12239
|
+
}
|
|
12240
|
+
function requireSparkId(sparkId) {
|
|
12241
|
+
if (!sparkId || typeof sparkId !== 'string') {
|
|
12242
|
+
throw new ValidationError('Spark ID is required');
|
|
12243
|
+
}
|
|
12244
|
+
}
|
|
12245
|
+
function mapSummary(wire) {
|
|
12246
|
+
return {
|
|
12247
|
+
id: wire.spark_id,
|
|
12248
|
+
contentType: wire.content_type ?? 'text/plain',
|
|
12249
|
+
size: wire.size_bytes,
|
|
12250
|
+
status: wire.status,
|
|
12251
|
+
createdAt: wire.created_at,
|
|
12252
|
+
expiresAt: wire.expires_at,
|
|
12253
|
+
burnedAt: wire.burned_at ?? null,
|
|
12254
|
+
timeRemaining: wire.time_remaining ?? 0,
|
|
12255
|
+
filename: wire.filename,
|
|
12256
|
+
kindling: wire.kindling,
|
|
12257
|
+
};
|
|
12258
|
+
}
|
|
12259
|
+
function mapShare(wire) {
|
|
12260
|
+
return {
|
|
12261
|
+
shared: wire.shared,
|
|
12262
|
+
shareUrl: wire.share_url,
|
|
12263
|
+
linkCode: wire.link_code,
|
|
12264
|
+
visibility: wire.visibility,
|
|
12265
|
+
invites: wire.invites,
|
|
12266
|
+
expiresAt: wire.expires_at,
|
|
12267
|
+
createdAt: wire.created_at,
|
|
12268
|
+
};
|
|
12269
|
+
}
|
|
12270
|
+
function buildQuery(params) {
|
|
12271
|
+
const search = new URLSearchParams();
|
|
12272
|
+
for (const [key, value] of Object.entries(params)) {
|
|
12273
|
+
if (value === undefined || value === '')
|
|
12274
|
+
continue;
|
|
12275
|
+
search.append(key, String(value));
|
|
12276
|
+
}
|
|
12277
|
+
const query = search.toString();
|
|
12278
|
+
return query ? `?${query}` : '';
|
|
12279
|
+
}
|
|
12280
|
+
|
|
12281
|
+
/**
|
|
12282
|
+
* Entropy Module
|
|
12283
|
+
*
|
|
12284
|
+
* Generate cryptographically strong random values from the SparkVault
|
|
12285
|
+
* hardware-backed entropy service.
|
|
12286
|
+
*/
|
|
12287
|
+
class EntropyModule {
|
|
12288
|
+
constructor(http) {
|
|
12289
|
+
this.http = http;
|
|
12290
|
+
}
|
|
12291
|
+
/**
|
|
12292
|
+
* Generate random entropy in the requested format.
|
|
12293
|
+
*
|
|
12294
|
+
* @example
|
|
12295
|
+
* const { value } = await sv.entropy.generate({ bytes: 32, format: 'hex' });
|
|
12296
|
+
*/
|
|
12297
|
+
async generate(options) {
|
|
12298
|
+
this.validateByteCount(options.bytes);
|
|
12299
|
+
const response = await this.http.post('/v1/entropy/generate', {
|
|
12300
|
+
num_bytes: options.bytes,
|
|
12301
|
+
format: options.format ?? 'hex',
|
|
12302
|
+
});
|
|
12303
|
+
const data = response.data;
|
|
12304
|
+
return {
|
|
12305
|
+
value: data.value,
|
|
12306
|
+
numBytes: data.num_bytes,
|
|
12307
|
+
format: data.format,
|
|
12308
|
+
referenceId: data.reference_id,
|
|
12309
|
+
};
|
|
12310
|
+
}
|
|
12311
|
+
/**
|
|
12312
|
+
* Generate `n` random bytes as a Uint8Array.
|
|
12313
|
+
*
|
|
12314
|
+
* @example
|
|
12315
|
+
* const key = await sv.entropy.generateBytes(32);
|
|
12316
|
+
*/
|
|
12317
|
+
async generateBytes(n) {
|
|
12318
|
+
this.validateByteCount(n);
|
|
12319
|
+
const result = await this.generate({ bytes: n, format: 'base64url' });
|
|
12320
|
+
if (typeof result.value !== 'string' || result.value.length === 0) {
|
|
12321
|
+
throw new SparkVaultError('Entropy endpoint returned no value', 'invalid_response');
|
|
12322
|
+
}
|
|
12323
|
+
const bytes = base64urlDecode(result.value);
|
|
12324
|
+
if (bytes.length !== n) {
|
|
12325
|
+
throw new SparkVaultError(`Entropy length mismatch: expected ${n}, got ${bytes.length}`, 'invalid_response');
|
|
12326
|
+
}
|
|
12327
|
+
return bytes;
|
|
12328
|
+
}
|
|
12329
|
+
validateByteCount(bytes) {
|
|
12330
|
+
if (!Number.isInteger(bytes) || bytes < 1 || bytes > 1024) {
|
|
12331
|
+
throw new ValidationError('Entropy byte count must be an integer from 1 to 1024', {
|
|
12332
|
+
field: 'bytes',
|
|
12333
|
+
received: bytes,
|
|
12334
|
+
});
|
|
12335
|
+
}
|
|
12336
|
+
}
|
|
12337
|
+
}
|
|
12338
|
+
|
|
11374
12339
|
/**
|
|
11375
12340
|
* SparkVault Debug Logger
|
|
11376
12341
|
*
|
|
@@ -11469,7 +12434,7 @@ const logger = {
|
|
|
11469
12434
|
*
|
|
11470
12435
|
* <script>
|
|
11471
12436
|
* // SDK is ready - just use it
|
|
11472
|
-
* SparkVault.identity.attach('.login-btn', {
|
|
12437
|
+
* SparkVault.products.identity.attach('.login-btn', {
|
|
11473
12438
|
* onSuccess: (result) => console.log('Verified:', result.identity)
|
|
11474
12439
|
* });
|
|
11475
12440
|
* </script>
|
|
@@ -11521,7 +12486,7 @@ function autoInit(SparkVaultClass) {
|
|
|
11521
12486
|
/**
|
|
11522
12487
|
* SparkVault JavaScript SDK
|
|
11523
12488
|
*
|
|
11524
|
-
* A unified SDK for Identity and
|
|
12489
|
+
* A unified SDK for Identity, Vaults, Ingots, Folders, Sparks, and Entropy.
|
|
11525
12490
|
*
|
|
11526
12491
|
* @example CDN Usage (Recommended)
|
|
11527
12492
|
* ```html
|
|
@@ -11531,8 +12496,8 @@ function autoInit(SparkVaultClass) {
|
|
|
11531
12496
|
* ></script>
|
|
11532
12497
|
*
|
|
11533
12498
|
* <script>
|
|
11534
|
-
* // SDK auto-initializes. Use JavaScript API:
|
|
11535
|
-
* SparkVault.identity.attach('.login-btn', {
|
|
12499
|
+
* // SDK auto-initializes. Use the JavaScript API:
|
|
12500
|
+
* SparkVault.products.identity.attach('.login-btn', {
|
|
11536
12501
|
* onSuccess: (result) => console.log('Verified:', result.identity)
|
|
11537
12502
|
* });
|
|
11538
12503
|
* </script>
|
|
@@ -11544,7 +12509,7 @@ function autoInit(SparkVaultClass) {
|
|
|
11544
12509
|
*
|
|
11545
12510
|
* const sv = SparkVault.init({ accountId: 'acc_your_account' });
|
|
11546
12511
|
*
|
|
11547
|
-
* const result = await sv.identity.verify();
|
|
12512
|
+
* const result = await sv.products.identity.verify();
|
|
11548
12513
|
* console.log(result.identity, result.identityType);
|
|
11549
12514
|
* ```
|
|
11550
12515
|
*/
|
|
@@ -11553,8 +12518,12 @@ class SparkVault {
|
|
|
11553
12518
|
validateConfig(config);
|
|
11554
12519
|
this.config = resolveConfig(config);
|
|
11555
12520
|
const http = new HttpClient(this.config);
|
|
11556
|
-
this.
|
|
12521
|
+
this.products = new ProductsModule(this.config);
|
|
11557
12522
|
this.vaults = new VaultsModule(this.config, http);
|
|
12523
|
+
this.ingots = new IngotsModule(this.config, http);
|
|
12524
|
+
this.folders = new FoldersModule(http);
|
|
12525
|
+
this.sparks = new SparksModule(http);
|
|
12526
|
+
this.entropy = new EntropyModule(http);
|
|
11558
12527
|
this.health = new HealthModule(this.config);
|
|
11559
12528
|
}
|
|
11560
12529
|
/**
|
|
@@ -11585,15 +12554,22 @@ if (typeof window !== 'undefined') {
|
|
|
11585
12554
|
|
|
11586
12555
|
exports.AuthenticationError = AuthenticationError;
|
|
11587
12556
|
exports.AuthorizationError = AuthorizationError;
|
|
12557
|
+
exports.EntropyModule = EntropyModule;
|
|
12558
|
+
exports.FoldersModule = FoldersModule;
|
|
12559
|
+
exports.IdentityModule = IdentityModule;
|
|
12560
|
+
exports.IngotsModule = IngotsModule;
|
|
11588
12561
|
exports.NetworkError = NetworkError;
|
|
11589
12562
|
exports.PlanRequiredError = PlanRequiredError;
|
|
11590
12563
|
exports.PopupBlockedError = PopupBlockedError;
|
|
12564
|
+
exports.ProductsModule = ProductsModule;
|
|
11591
12565
|
exports.QuotaExceededError = QuotaExceededError;
|
|
11592
12566
|
exports.SparkVault = SparkVault;
|
|
11593
12567
|
exports.SparkVaultError = SparkVaultError;
|
|
12568
|
+
exports.SparksModule = SparksModule;
|
|
11594
12569
|
exports.TimeoutError = TimeoutError;
|
|
11595
12570
|
exports.UserCancelledError = UserCancelledError;
|
|
11596
12571
|
exports.ValidationError = ValidationError;
|
|
12572
|
+
exports.VaultsModule = VaultsModule;
|
|
11597
12573
|
exports.default = SparkVault;
|
|
11598
12574
|
exports.logger = logger;
|
|
11599
12575
|
exports.setDebugMode = setDebugMode;
|