@sparkvault/sdk-js 12.0.3 → 12.0.5

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.
@@ -11,7 +11,7 @@
11
11
  */
12
12
  import { type ResolvedConfig } from '../config';
13
13
  import { HttpClient } from '../http';
14
- import type { UnsealedVault, Ingot, IngotUpload, CreatedIngot, IngotDownloadLink, CreateUploadOptions, UploadIngotOptions, SendUploadOptions, ResumeUploadOptions, UploadSession, ReplaceIngotOptions, ListIngotsOptions, ListContentsOptions, FolderContents, SearchIngotsOptions, IngotPage, IngotSharingConfig, UpdateIngotSharingOptions, IngotInvite, IngotAccessLogPage, AccessLogsOptions, HashCheckResponse } from './types';
14
+ import type { UnsealedVault, Ingot, IngotUpload, UploadEnd, CreatedIngot, IngotDownloadLink, CreateUploadOptions, UploadIngotOptions, SendUploadOptions, ResumeUploadOptions, UploadSession, ReplaceIngotOptions, ListIngotsOptions, ListContentsOptions, FolderContents, SearchIngotsOptions, IngotPage, IngotSharingConfig, UpdateIngotSharingOptions, IngotInvitation, IngotAccessLogPage, AccessLogsOptions, HashCheckResponse } from './types';
15
15
  export declare class IngotsModule {
16
16
  private readonly config;
17
17
  private readonly http;
@@ -24,7 +24,9 @@ export declare class IngotsModule {
24
24
  * transfer yourself; otherwise prefer {@link upload}. A create another
25
25
  * upload of the same file superseded before its token was issued rejects
26
26
  * with code `upload_refused` (`details.coreCode` UPLOAD_SUPERSEDED): the
27
- * later upload is the one kept, so a new upload is no remedy.
27
+ * later upload is the one kept, so a new upload is no remedy. An upload
28
+ * you give up (you cancel its transfer, or it fails for good) ends with the
29
+ * file its create made through {@link endUpload}, given this result.
28
30
  *
29
31
  * @example
30
32
  * const session = await sv.ingots.createUpload({
@@ -34,6 +36,37 @@ export declare class IngotsModule {
34
36
  * console.log(session.uploadUrl);
35
37
  */
36
38
  createUpload(options: CreateUploadOptions): Promise<IngotUpload>;
39
+ /**
40
+ * End an upload you give up (you cancelled its transfer, or it failed for
41
+ * good) with the file its create made ({@link createUpload}'s result): the
42
+ * server deletes the ingot only while it is still that upload's unfinished
43
+ * file, ending the upload first, so a publication racing the end is decided
44
+ * before anything goes. Never give up one the server received whole
45
+ * ({@link isReceivedUploadFailure}): the server publishes or ends it on its
46
+ * own. Resolves `deleted` once the vault holds the file no longer, deleted
47
+ * now or already gone. Resolves `kept` when this end deleted nothing, which
48
+ * {@link get} shows as it is now: the upload published the file, or a later
49
+ * upload took it over, before the end reached the server, or, with no
50
+ * request sent, the create did not make it (`created: false`) or names no
51
+ * upload (`uploadId: null`), since a delete without its upload would take
52
+ * whatever file stands. Any other failure rejects, the file left as it was.
53
+ * {@link upload} ends an upload it cannot finish this way by itself.
54
+ *
55
+ * @example
56
+ * const upload = await sv.ingots.createUpload({ vault: unsealed, name: file.name,
57
+ * contentType: file.type, sizeBytes: file.size });
58
+ * try {
59
+ * await sv.ingots.sendUpload(upload.uploadUrl, file, { signal: controller.signal });
60
+ * } catch (error) {
61
+ * if (!isReceivedUploadFailure(error) &&
62
+ * await sv.ingots.endUpload(unsealed, upload) === 'kept') {
63
+ * // The end deleted nothing (the upload published the file, say): show it as it is.
64
+ * showIngot(await sv.ingots.get(unsealed, upload.id));
65
+ * }
66
+ * throw error;
67
+ * }
68
+ */
69
+ endUpload(vault: UnsealedVault, upload: Pick<IngotUpload, 'id' | 'created' | 'uploadId'>): Promise<UploadEnd>;
37
70
  /**
38
71
  * Send a file's bytes to an upload session — the `uploadUrl` a
39
72
  * {@link createUpload} returned — over the resumable transfer every SDK
@@ -120,7 +153,11 @@ export declare class IngotsModule {
120
153
  * server refused — another upload of it superseded this one, at its create
121
154
  * or while it streamed, the storage pool cannot take it, or its vault is
122
155
  * scheduled for deletion (a 409 `VAULT_DELETION_SCHEDULED`) — rejects with
123
- * code `upload_refused`, as {@link sendUpload} does.
156
+ * code `upload_refused`, as {@link sendUpload} does. An upload that rejects
157
+ * any way but one the server received whole ({@link isReceivedUploadFailure}:
158
+ * the server publishes or ends that one on its own) is given up: the end of
159
+ * it with the file its create made ({@link endUpload}) starts as it
160
+ * rejects, without holding up its own error.
124
161
  *
125
162
  * @example
126
163
  * const ingot = await sv.ingots.upload(unsealed, {
@@ -128,6 +165,12 @@ export declare class IngotsModule {
128
165
  * });
129
166
  */
130
167
  upload(vault: UnsealedVault, options: UploadIngotOptions): Promise<CreatedIngot>;
168
+ /**
169
+ * End an upload this flow gave up ({@link endUpload}) without holding up
170
+ * the error its caller is answered with: an end that fails leaves the file
171
+ * to the server's expiry of abandoned uploads, and is logged.
172
+ */
173
+ private endGivenUp;
131
174
  /**
132
175
  * Replace an existing ingot's content (high-level flow). Rejects as
133
176
  * {@link upload} does, a replacement another upload of the same ingot
@@ -253,13 +296,16 @@ export declare class IngotsModule {
253
296
  */
254
297
  updateSharingConfig(vault: UnsealedVault, ingotId: string, config: UpdateIngotSharingOptions): Promise<IngotSharingConfig>;
255
298
  /**
256
- * Invite an identity to a shared ingot. The identity type (email or phone)
257
- * is inferred server-side from the identity value.
299
+ * Invite an identity to an ingot's invite-only share, or share an ingot not
300
+ * yet shared invite-only with it. A public or authenticated share refuses
301
+ * it (a ValidationError) and changes nothing: set its visibility to
302
+ * `invite_only` first. The identity type (email or phone) is inferred
303
+ * server-side from the identity value.
258
304
  *
259
305
  * @example
260
306
  * await sv.ingots.addInvite(unsealed, 'ing_abc', 'user@example.com');
261
307
  */
262
- addInvite(vault: UnsealedVault, ingotId: string, identity: string): Promise<IngotInvite>;
308
+ addInvite(vault: UnsealedVault, ingotId: string, identity: string): Promise<IngotInvitation>;
263
309
  /**
264
310
  * Revoke an ingot sharing invite.
265
311
  *
@@ -302,5 +348,6 @@ export declare class IngotsModule {
302
348
  }
303
349
  export { NAME_CONFLICT_POLICIES } from './types';
304
350
  export { fetchDownload } from './fetch-download';
351
+ export { isReceivedUploadFailure } from '../vaults/upload/api';
305
352
  export type { FetchDownloadOptions, FetchedDownload } from './fetch-download';
306
- export type { NameConflictPolicy, UnsealedVault, Ingot, IngotUpload, CreatedIngot, IngotDownloadLink, CreateUploadOptions, UploadIngotOptions, SendUploadOptions, ResumeUploadOptions, UploadSession, ReplaceIngotOptions, ListIngotsOptions, ListContentsOptions, FolderContents, SearchIngotsOptions, IngotPage, IngotSharingConfig, UpdateIngotSharingOptions, IngotInvite, IngotAccessLog, IngotAccessLogPage, AccessLogsOptions, HashCheckResponse, } from './types';
353
+ export type { NameConflictPolicy, UnsealedVault, Ingot, IngotUpload, UploadEnd, CreatedIngot, IngotDownloadLink, CreateUploadOptions, UploadIngotOptions, SendUploadOptions, ResumeUploadOptions, UploadSession, ReplaceIngotOptions, ListIngotsOptions, ListContentsOptions, FolderContents, SearchIngotsOptions, IngotPage, IngotSharingConfig, UpdateIngotSharingOptions, IngotInvite, IngotInvitation, IngotAccessLog, IngotAccessLogPage, AccessLogsOptions, HashCheckResponse, } from './types';
@@ -16,8 +16,10 @@ export type { UnsealedVault };
16
16
  * - `upsert` (the server default): the upload replaces the holder's content.
17
17
  * - `complete_pending`: a holder whose own upload never finalized is completed
18
18
  * (`created: false`); a published holder is refused with a 409 CONFLICT whose
19
- * `details` are `{ reason: 'NAME_HELD', ingot_id, status, size_bytes }`, and
20
- * is left untouched.
19
+ * `details.reason` is `'NAME_HELD'`, and is left untouched. The details
20
+ * describe the holder (`ingot_id`, `status`, `size_bytes`) unless another
21
+ * app manages it or another request claimed the name first, when they carry
22
+ * the reason alone.
21
23
  * - `refuse`: any holder, its upload finished or not, is refused with that
22
24
  * same 409 and left untouched; the create only ever mints.
23
25
  * - `new_name`: the holder is never touched; the ingot is minted under the
@@ -87,7 +89,22 @@ export interface IngotUpload {
87
89
  * ingot already holding the name (false, as `onNameConflict` allowed).
88
90
  */
89
91
  created: boolean;
92
+ /**
93
+ * The upload the create staged onto the ingot (Core's `upload_id`): the id
94
+ * Forge keys the upload's session by, and the `contentVersion` the ingot
95
+ * reads once the upload publishes. Giving the upload up ends it with the
96
+ * file the create made through this id (`endUpload`). Null when the server
97
+ * named none.
98
+ */
99
+ uploadId: string | null;
90
100
  }
101
+ /**
102
+ * What became of a given-up upload's file (`endUpload`): `deleted`, the vault
103
+ * holds it no longer (this end deleted it, or it was already gone); `kept`,
104
+ * this end deleted nothing, and a read of it by id (`get`) shows the file as
105
+ * it is now.
106
+ */
107
+ export type UploadEnd = 'deleted' | 'kept';
91
108
  /** A finalized ingot, returned by the high-level upload/replace flows. */
92
109
  export interface CreatedIngot {
93
110
  /** Ingot ID */
@@ -292,6 +309,16 @@ export interface IngotSharingConfig {
292
309
  shared: boolean;
293
310
  /** Visibility mode */
294
311
  visibility?: 'invite_only' | 'authenticated' | 'public';
312
+ /** The share's permanent files.sv URL, the link its recipients open; null while the ingot is not shared */
313
+ publicUrl: string | null;
314
+ /** The share's link code (the URL's last segment); null while the ingot is not shared */
315
+ linkCode: string | null;
316
+ /** Whether the vault's public file sharing is on */
317
+ sharingEnabled: boolean;
318
+ /** Whether the vault makes every ingot public, which pins this one to public */
319
+ vaultAllIngotsPublic: boolean;
320
+ /** The vault's share recipient session length, in seconds */
321
+ sessionLengthSeconds: number;
295
322
  /** Active invites */
296
323
  invites?: IngotInvite[];
297
324
  }
@@ -310,6 +337,15 @@ export interface IngotInvite {
310
337
  identity: string;
311
338
  /** Identity type */
312
339
  identityType: 'email' | 'phone';
340
+ /** When this identity was invited (Unix seconds) */
341
+ invitedAt: number;
342
+ }
343
+ /** An invitation addInvite made or resent. */
344
+ export interface IngotInvitation extends IngotInvite {
345
+ /** The URL this invitee was sent: the share's files.sv URL, with their own token when the share invites several */
346
+ shareUrl: string;
347
+ /** Whether the invitation was delivered by email or text */
348
+ delivered: boolean;
313
349
  }
314
350
  /**
315
351
  * An ingot access-log entry: a download that delivered the file, a SparkLink
@@ -377,9 +413,13 @@ export interface ReplaceIngotResponse {
377
413
  forge_url: string;
378
414
  expires_at: number;
379
415
  }
380
- /** POST /ingots — `created` says whether the name was minted or its holder staged onto. */
416
+ /**
417
+ * POST /ingots — `created` says whether the name was minted or its holder
418
+ * staged onto, and `upload_id` names the upload the create staged.
419
+ */
381
420
  export interface CreateIngotResponse extends ReplaceIngotResponse {
382
421
  created: boolean;
422
+ upload_id?: string;
383
423
  }
384
424
  export interface ListIngotsResponse {
385
425
  ingots: IngotWire[];
@@ -410,9 +450,17 @@ export interface DownloadIngotResponse {
410
450
  size_bytes: number;
411
451
  content_type: string;
412
452
  }
453
+ /** A sharing answer (apps/api/src/ingots/sharing.js formatSharingConfig). */
413
454
  export interface IngotSharingConfigResponse {
455
+ ingot_id: string;
456
+ vault_id: string;
457
+ sharing_enabled: boolean;
414
458
  shared: boolean;
415
- visibility?: 'invite_only' | 'authenticated' | 'public';
459
+ visibility?: 'invite_only' | 'authenticated' | 'public' | null;
460
+ public_url: string | null;
461
+ link_code: string | null;
462
+ vault_all_ingots_public: boolean;
463
+ session_length_seconds: number;
416
464
  invites?: IngotInviteResponse[];
417
465
  }
418
466
  /** An invite as the sharing answers carry it (apps/api/src/ingots/sharing.js). */
@@ -420,4 +468,11 @@ export interface IngotInviteResponse {
420
468
  invite_id: string;
421
469
  identity: string;
422
470
  identity_type: 'email' | 'phone';
471
+ expires_at: null;
472
+ created_at: number;
473
+ }
474
+ /** An invite answer (apps/api/src/ingots/sharing.js inviteIdentity). */
475
+ export interface IngotInvitationResponse extends IngotInviteResponse {
476
+ share_url: string;
477
+ delivered: boolean;
423
478
  }