@sparkvault/sdk-js 13.0.0 → 13.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # SparkVault JavaScript SDK
2
2
 
3
- `@sparkvault/sdk-js` is SparkVault's SDK for browsers and Node 18+. A web page signs people in through SparkVault Identity, uploads ingots and embeds the encrypted upload widget; a backend sends Notify notifications and manages vaults, ingots, folders, sparks and entropy over the Core API. Uploads need a browser's XMLHttpRequest: in Node, an `ingots` upload rejects with `code` `environment_unsupported` before any request to Forge, though `ingots.upload` and `ingots.replace` first stage the ingot or its replacement on the server.
3
+ `@sparkvault/sdk-js` is SparkVault's SDK for browsers and Node 18+. A web page signs people in through SparkVault Identity, uploads ingots and embeds the encrypted upload widget; a backend sends Notify notifications and manages vaults, ingots, folders, sparks and entropy over the Core API. Uploads need a browser's XMLHttpRequest: in Node, an `ingots` upload or replacement rejects with `code` `environment_unsupported` before any request, so nothing is staged; a server stages with `ingots.createUpload` and sends the file over tus itself.
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/@sparkvault/sdk-js.svg)](https://www.npmjs.com/package/@sparkvault/sdk-js)
6
6
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
package/dist/errors.d.ts CHANGED
@@ -19,9 +19,9 @@ export declare class SparkVaultError extends Error {
19
19
  * refused call of a data-plane module (`vaults`, `ingots`, `folders`,
20
20
  * `sparks`, `entropy`, `notify`, `products.notify`); `api_error` when the
21
21
  * answer named none (a gateway's HTML). A typed refusal's `code` names its
22
- * class of failure: one per 400 (`validation_error`) and 401
23
- * (`authentication_error`), two per 402 (`PLAN_REQUIRED`, `QUOTA_EXCEEDED`)
24
- * and 403 (`authorization_error`, `NOTIFY_SUBSCRIPTION_REQUIRED`;
22
+ * class of failure: one per 400 (`validation_error`), two per 401
23
+ * (`authentication_error`, `UNAUTHORIZED`), 402 (`PLAN_REQUIRED`,
24
+ * `QUOTA_EXCEEDED`) and 403 (`authorization_error`, `NOTIFY_SUBSCRIPTION_REQUIRED`;
25
25
  * http.ts createErrorFromResponse), so this is what tells apart two
26
26
  * refusals that share a code.
27
27
  * Undefined on an error the SDK raised itself, on the Identity product's
@@ -36,6 +36,15 @@ export declare class SparkVaultError extends Error {
36
36
  export declare class AuthenticationError extends SparkVaultError {
37
37
  constructor(message: string, details?: Record<string, unknown>, retryAfterMs?: number | null, serviceCode?: string);
38
38
  }
39
+ /**
40
+ * A key the request presents was refused (401 UNAUTHORIZED): the DVAK an
41
+ * unseal names is invalid or revoked. The caller's own credential stood, so
42
+ * this is no ended session, and signing in again changes nothing: present a
43
+ * live key. Every other 401 is an {@link AuthenticationError}.
44
+ */
45
+ export declare class UnauthorizedError extends SparkVaultError {
46
+ constructor(message: string, details?: Record<string, unknown>, retryAfterMs?: number | null, serviceCode?: string);
47
+ }
39
48
  export declare class AuthorizationError extends SparkVaultError {
40
49
  constructor(message: string, details?: Record<string, unknown>, retryAfterMs?: number | null, serviceCode?: string);
41
50
  }
package/dist/index.cjs CHANGED
@@ -790,6 +790,19 @@ class AuthenticationError extends SparkVaultError {
790
790
  Object.setPrototypeOf(this, AuthenticationError.prototype);
791
791
  }
792
792
  }
793
+ /**
794
+ * A key the request presents was refused (401 UNAUTHORIZED): the DVAK an
795
+ * unseal names is invalid or revoked. The caller's own credential stood, so
796
+ * this is no ended session, and signing in again changes nothing: present a
797
+ * live key. Every other 401 is an {@link AuthenticationError}.
798
+ */
799
+ class UnauthorizedError extends SparkVaultError {
800
+ constructor(message, details, retryAfterMs = null, serviceCode) {
801
+ super(message, 'UNAUTHORIZED', 401, details, retryAfterMs, serviceCode);
802
+ this.name = 'UnauthorizedError';
803
+ Object.setPrototypeOf(this, UnauthorizedError.prototype);
804
+ }
805
+ }
793
806
  class AuthorizationError extends SparkVaultError {
794
807
  constructor(message, details, retryAfterMs = null, serviceCode) {
795
808
  super(message, 'authorization_error', 403, details, retryAfterMs, serviceCode);
@@ -1558,6 +1571,10 @@ class HttpClient {
1558
1571
  case 400:
1559
1572
  return new ValidationError(message, details, retryAfterMs, code);
1560
1573
  case 401:
1574
+ // A refused key the request carries (an unseal's DVAK) is no ended
1575
+ // session: its own class, so a caller never signs out over it.
1576
+ if (code === 'UNAUTHORIZED')
1577
+ return new UnauthorizedError(message, details, retryAfterMs, code);
1561
1578
  return new AuthenticationError(message, details, retryAfterMs, code);
1562
1579
  case 402:
1563
1580
  if (code === 'QUOTA_EXCEEDED')
@@ -12229,7 +12246,12 @@ function stagingRefusalOf(error) {
12229
12246
  function cancelledError() {
12230
12247
  return new UploadApiError('Upload cancelled', 'cancelled', 0);
12231
12248
  }
12232
- /** Refuse a transfer where the browser's XMLHttpRequest is missing: a chunk's upload progress needs it. */
12249
+ /**
12250
+ * Refuse a transfer where the browser's XMLHttpRequest is missing (a server
12251
+ * process: Node has fetch and no XMLHttpRequest): a chunk's upload progress
12252
+ * needs it. A flow that stages its upload with Core first checks this before
12253
+ * the staging request, so a run that cannot transfer stages nothing.
12254
+ */
12233
12255
  function assertBrowserTransfer() {
12234
12256
  if (typeof XMLHttpRequest === 'undefined') {
12235
12257
  throw new UploadApiError('XMLHttpRequest is required for browser uploads', 'environment_unsupported', 0);
@@ -15840,7 +15862,8 @@ class VaultsModule {
15840
15862
  return mapVaultDetail(response.data);
15841
15863
  }
15842
15864
  /**
15843
- * Get a vault's public-sharing configuration.
15865
+ * Get a vault's public-sharing configuration. Every sharing write below
15866
+ * answers the same configuration as that write left it.
15844
15867
  *
15845
15868
  * @example
15846
15869
  * const sharing = await sv.vaults.getSharingConfig('vlt_abc');
@@ -15930,7 +15953,9 @@ class VaultsModule {
15930
15953
  };
15931
15954
  }
15932
15955
  /**
15933
- * Get a vault's upload-channel configuration.
15956
+ * Get a vault's upload-channel configuration. Every upload write below
15957
+ * answers the same configuration as that write left it: both channels, the
15958
+ * shared settings, and the portal's URL while the portal is on.
15934
15959
  *
15935
15960
  * @example
15936
15961
  * const upload = await sv.vaults.getUploadConfig('vlt_abc');
@@ -15998,17 +16023,7 @@ class VaultsModule {
15998
16023
  throw new ValidationError('VMK is required');
15999
16024
  }
16000
16025
  const response = await this.http.post(apiPath `/v1/vaults/${id}/upload/${channel}/${action}`, action === 'enable' ? { vmk } : undefined);
16001
- const d = response.data;
16002
- return {
16003
- vaultId: d.vault_id,
16004
- uploadPortalEnabled: d.upload_portal_enabled ?? (channel === 'portal' && action === 'enable'),
16005
- uploadPortalEnabledAt: channel === 'portal' && action === 'enable' ? d.enabled_at ?? null : null,
16006
- uploadWidgetEnabled: d.upload_widget_enabled ?? (channel === 'widget' && action === 'enable'),
16007
- uploadWidgetEnabledAt: channel === 'widget' && action === 'enable' ? d.enabled_at ?? null : null,
16008
- maxSizeBytes: null,
16009
- notificationEmail: null,
16010
- portalUrl: d.portal_url,
16011
- };
16026
+ return mapUploadSettings(response.data);
16012
16027
  }
16013
16028
  validateCreateOptions(options) {
16014
16029
  // A name's length is Core's to decide (it answers a ValidationError naming
@@ -16971,7 +16986,10 @@ class IngotsModule {
16971
16986
  * `upload_received_publishing`: every byte is received, and the server
16972
16987
  * finishes the publication on its own, so never upload the file again; a
16973
16988
  * caller that kept the session (`onSessionCreated`) learns what became of
16974
- * it with {@link resumeUpload}.
16989
+ * it with {@link resumeUpload}. A chunk's upload progress needs the
16990
+ * browser's XMLHttpRequest: where there is none (a Node server) it rejects
16991
+ * with code `environment_unsupported` before any request; a server sends
16992
+ * the bytes over tus to `uploadUrl` itself.
16975
16993
  *
16976
16994
  * @param options.signal - Cancels this transfer (it rejects with code
16977
16995
  * `cancelled`); other transfers carry on.
@@ -17060,7 +17078,10 @@ class IngotsModule {
17060
17078
  * any way but one the server received whole ({@link isReceivedUploadFailure}:
17061
17079
  * the server publishes or ends that one on its own) is given up: the end of
17062
17080
  * it with the file its create made ({@link endUpload}) starts as it
17063
- * rejects, without holding up its own error.
17081
+ * rejects, without holding up its own error. It needs the browser's
17082
+ * XMLHttpRequest, as {@link sendUpload} does: in a server process it
17083
+ * rejects with code `environment_unsupported` before any request, so no
17084
+ * create stages an ingot it cannot send.
17064
17085
  *
17065
17086
  * @example
17066
17087
  * const ingot = await sv.ingots.upload(unsealed, {
@@ -17073,6 +17094,7 @@ class IngotsModule {
17073
17094
  throw new ValidationError('Provide folder or folderId, not both');
17074
17095
  }
17075
17096
  const name = options.name ?? getBlobName(options.file);
17097
+ assertBrowserTransfer();
17076
17098
  const created = await this.requestUploadSession(vault, {
17077
17099
  name,
17078
17100
  content_type: sentContentType(options),
@@ -17109,7 +17131,8 @@ class IngotsModule {
17109
17131
  /**
17110
17132
  * Replace an existing ingot's content (high-level flow). Rejects as
17111
17133
  * {@link upload} does, a replacement another upload of the same ingot
17112
- * superseded included (`upload_refused`).
17134
+ * superseded included (`upload_refused`), and `environment_unsupported`
17135
+ * before the replacement is staged where there is no XMLHttpRequest.
17113
17136
  *
17114
17137
  * @example
17115
17138
  * await sv.ingots.replace(unsealed, 'ing_abc', { file: updatedFile });
@@ -17120,6 +17143,7 @@ class IngotsModule {
17120
17143
  const id = requireResourceId(ingotId, 'ingotId');
17121
17144
  const name = options.name ?? getBlobName(options.file);
17122
17145
  const contentType = sentContentType(options);
17146
+ assertBrowserTransfer();
17123
17147
  const response = await this.http.put(apiPath `/v1/vaults/${vaultId}/ingots/${id}`, {
17124
17148
  name,
17125
17149
  // Omitted, Core keeps the ingot's stored type (ReplaceIngotOptions.contentType).
@@ -17187,7 +17211,9 @@ class IngotsModule {
17187
17211
  return mapIngot(response.data);
17188
17212
  }
17189
17213
  /**
17190
- * List ingots in an unsealed vault.
17214
+ * List ingots in an unsealed vault, one page at a time in the vault index's
17215
+ * order: follow `nextCursor`. `sortBy` orders only the page answered; for
17216
+ * one order across a vault, search or list a folder's contents.
17191
17217
  *
17192
17218
  * @example
17193
17219
  * const { ingots } = await sv.ingots.list(unsealed);
@@ -18292,7 +18318,7 @@ class SparkVault {
18292
18318
  }
18293
18319
  /** Get the SDK version */
18294
18320
  static get version() {
18295
- return '13.0.0';
18321
+ return '13.0.1';
18296
18322
  }
18297
18323
  }
18298
18324
  if (typeof window !== 'undefined') {
@@ -18323,6 +18349,7 @@ exports.SparkVault = SparkVault;
18323
18349
  exports.SparkVaultError = SparkVaultError;
18324
18350
  exports.SparksModule = SparksModule;
18325
18351
  exports.TimeoutError = TimeoutError;
18352
+ exports.UnauthorizedError = UnauthorizedError;
18326
18353
  exports.UserCancelledError = UserCancelledError;
18327
18354
  exports.ValidationError = ValidationError;
18328
18355
  exports.VaultsModule = VaultsModule;