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