@sparkvault/sdk-js 11.2.6 → 11.3.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/index.d.ts CHANGED
@@ -2965,6 +2965,22 @@ declare class FoldersModule {
2965
2965
  * const folders = await sv.folders.list(unsealed);
2966
2966
  */
2967
2967
  list(vault: UnsealedVault): Promise<Folder[]>;
2968
+ /**
2969
+ * The folder at `path`, or null when the vault has none there. `path` is an
2970
+ * upload's folder path (`folder` on an upload): slash-delimited from the
2971
+ * vault root, each name matched in any case, validated by the API as an
2972
+ * upload's is. The API reads only that path, never the vault's folder list.
2973
+ *
2974
+ * @throws ValidationError when `path` is not a non-empty string: an empty
2975
+ * value is left out of the query, which would ask for every folder instead
2976
+ * of the one at a path
2977
+ * @throws SparkVaultError (`invalid_response`) when the answer is not one
2978
+ * folder or none
2979
+ *
2980
+ * @example
2981
+ * const invoices = await sv.folders.findByPath(unsealed, 'Clients/Acme/Invoices');
2982
+ */
2983
+ findByPath(vault: UnsealedVault, path: string): Promise<Folder | null>;
2968
2984
  /**
2969
2985
  * Get a single folder.
2970
2986
  *
package/dist/index.mjs CHANGED
@@ -1366,7 +1366,7 @@ function buildRequestPath(literals, values) {
1366
1366
  /**
1367
1367
  * Encode query parameters, leaving out every unset value (`undefined`, `null`
1368
1368
  * or `''`). Other values are sent as their string form, so `0` and `false`
1369
- * are sent.
1369
+ * are sent. A space is sent as `%20`, never `+`.
1370
1370
  * @param {Readonly<Record<string, string | number | boolean | null | undefined>> | undefined} params
1371
1371
  * @returns {string} `?a=1&b=2`, or '' when no value is set.
1372
1372
  */
@@ -1376,7 +1376,12 @@ function queryString(params) {
1376
1376
  if (value === undefined || value === null || value === '') continue;
1377
1377
  search.append(key, String(value));
1378
1378
  }
1379
- const query = search.toString();
1379
+ // URLSearchParams writes a space as `+`, which only a form decoder reads
1380
+ // back as a space: a gateway or adapter that percent-decodes the query
1381
+ // (decodeURIComponent) hands the handler a literal `+`. `%20` is a space to
1382
+ // every decoder. The swap is exact because URLSearchParams has already
1383
+ // written each literal `+` as `%2B`, so every `+` left is a space.
1384
+ const query = search.toString().replace(/\+/g, '%20');
1380
1385
  return query ? `?${query}` : '';
1381
1386
  }
1382
1387
 
@@ -16117,6 +16122,37 @@ class FoldersModule {
16117
16122
  const response = await this.http.get(apiPath `/v1/vaults/${vaultId}/folders`, { vat: vault.vatToken });
16118
16123
  return (response.data.folders ?? []).map(mapFolder);
16119
16124
  }
16125
+ /**
16126
+ * The folder at `path`, or null when the vault has none there. `path` is an
16127
+ * upload's folder path (`folder` on an upload): slash-delimited from the
16128
+ * vault root, each name matched in any case, validated by the API as an
16129
+ * upload's is. The API reads only that path, never the vault's folder list.
16130
+ *
16131
+ * @throws ValidationError when `path` is not a non-empty string: an empty
16132
+ * value is left out of the query, which would ask for every folder instead
16133
+ * of the one at a path
16134
+ * @throws SparkVaultError (`invalid_response`) when the answer is not one
16135
+ * folder or none
16136
+ *
16137
+ * @example
16138
+ * const invoices = await sv.folders.findByPath(unsealed, 'Clients/Acme/Invoices');
16139
+ */
16140
+ async findByPath(vault, path) {
16141
+ const vaultId = requireVaultId(vault);
16142
+ if (typeof path !== 'string' || path.trim() === '') {
16143
+ throw new ValidationError('path must be a non-empty string', { field: 'path' });
16144
+ }
16145
+ const response = await this.http.get(apiPath `/v1/vaults/${vaultId}/folders`, { vat: vault.vatToken, query: { path } });
16146
+ // Exactly one folder or none: anything else (no list, or a list of
16147
+ // several) is not an answer to one path, and never picks a folder.
16148
+ const folders = response.data?.folders;
16149
+ if (!Array.isArray(folders) || folders.length > 1) {
16150
+ throw new SparkVaultError('A folder path lookup answered neither one folder nor none', 'invalid_response', undefined, {
16151
+ count: Array.isArray(folders) ? folders.length : null,
16152
+ });
16153
+ }
16154
+ return folders.length === 1 ? mapFolder(folders[0]) : null;
16155
+ }
16120
16156
  /**
16121
16157
  * Get a single folder.
16122
16158
  *
@@ -17561,7 +17597,7 @@ class SparkVault {
17561
17597
  }
17562
17598
  /** Get the SDK version */
17563
17599
  static get version() {
17564
- return '11.2.6';
17600
+ return '11.3.0';
17565
17601
  }
17566
17602
  }
17567
17603
  if (typeof window !== 'undefined') {