@sparkvault/sdk-js 11.2.6 → 11.3.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.
@@ -17,6 +17,22 @@ export declare class FoldersModule {
17
17
  * const folders = await sv.folders.list(unsealed);
18
18
  */
19
19
  list(vault: UnsealedVault): Promise<Folder[]>;
20
+ /**
21
+ * The folder at `path`, or null when the vault has none there. `path` is an
22
+ * upload's folder path (`folder` on an upload): slash-delimited from the
23
+ * vault root, each name matched in any case, validated by the API as an
24
+ * upload's is. The API reads only that path, never the vault's folder list.
25
+ *
26
+ * @throws ValidationError when `path` is not a non-empty string: an empty
27
+ * value is left out of the query, which would ask for every folder instead
28
+ * of the one at a path
29
+ * @throws SparkVaultError (`invalid_response`) when the answer is not one
30
+ * folder or none
31
+ *
32
+ * @example
33
+ * const invoices = await sv.folders.findByPath(unsealed, 'Clients/Acme/Invoices');
34
+ */
35
+ findByPath(vault: UnsealedVault, path: string): Promise<Folder | null>;
20
36
  /**
21
37
  * Get a single folder.
22
38
  *
package/dist/index.cjs CHANGED
@@ -933,6 +933,10 @@ const RESOURCE_ID_PREFIXES = Object.freeze({
933
933
  attachment: 'hda',
934
934
  folder: 'fld',
935
935
  helpDeskJob: 'hdj',
936
+ knowledgeBaseArticle: 'hdkba',
937
+ knowledgeBaseCategory: 'hdkbc',
938
+ knowledgeBaseRevision: 'hdkbr',
939
+ knowledgeBaseAsset: 'hdkbm',
936
940
  ingot: 'ing',
937
941
  invite: 'inv',
938
942
  notification: 'ntf',
@@ -1370,7 +1374,7 @@ function buildRequestPath(literals, values) {
1370
1374
  /**
1371
1375
  * Encode query parameters, leaving out every unset value (`undefined`, `null`
1372
1376
  * or `''`). Other values are sent as their string form, so `0` and `false`
1373
- * are sent.
1377
+ * are sent. A space is sent as `%20`, never `+`.
1374
1378
  * @param {Readonly<Record<string, string | number | boolean | null | undefined>> | undefined} params
1375
1379
  * @returns {string} `?a=1&b=2`, or '' when no value is set.
1376
1380
  */
@@ -1380,7 +1384,12 @@ function queryString(params) {
1380
1384
  if (value === undefined || value === null || value === '') continue;
1381
1385
  search.append(key, String(value));
1382
1386
  }
1383
- const query = search.toString();
1387
+ // URLSearchParams writes a space as `+`, which only a form decoder reads
1388
+ // back as a space: a gateway or adapter that percent-decodes the query
1389
+ // (decodeURIComponent) hands the handler a literal `+`. `%20` is a space to
1390
+ // every decoder. The swap is exact because URLSearchParams has already
1391
+ // written each literal `+` as `%2B`, so every `+` left is a space.
1392
+ const query = search.toString().replace(/\+/g, '%20');
1384
1393
  return query ? `?${query}` : '';
1385
1394
  }
1386
1395
 
@@ -16121,6 +16130,37 @@ class FoldersModule {
16121
16130
  const response = await this.http.get(apiPath `/v1/vaults/${vaultId}/folders`, { vat: vault.vatToken });
16122
16131
  return (response.data.folders ?? []).map(mapFolder);
16123
16132
  }
16133
+ /**
16134
+ * The folder at `path`, or null when the vault has none there. `path` is an
16135
+ * upload's folder path (`folder` on an upload): slash-delimited from the
16136
+ * vault root, each name matched in any case, validated by the API as an
16137
+ * upload's is. The API reads only that path, never the vault's folder list.
16138
+ *
16139
+ * @throws ValidationError when `path` is not a non-empty string: an empty
16140
+ * value is left out of the query, which would ask for every folder instead
16141
+ * of the one at a path
16142
+ * @throws SparkVaultError (`invalid_response`) when the answer is not one
16143
+ * folder or none
16144
+ *
16145
+ * @example
16146
+ * const invoices = await sv.folders.findByPath(unsealed, 'Clients/Acme/Invoices');
16147
+ */
16148
+ async findByPath(vault, path) {
16149
+ const vaultId = requireVaultId(vault);
16150
+ if (typeof path !== 'string' || path.trim() === '') {
16151
+ throw new ValidationError('path must be a non-empty string', { field: 'path' });
16152
+ }
16153
+ const response = await this.http.get(apiPath `/v1/vaults/${vaultId}/folders`, { vat: vault.vatToken, query: { path } });
16154
+ // Exactly one folder or none: anything else (no list, or a list of
16155
+ // several) is not an answer to one path, and never picks a folder.
16156
+ const folders = response.data?.folders;
16157
+ if (!Array.isArray(folders) || folders.length > 1) {
16158
+ throw new SparkVaultError('A folder path lookup answered neither one folder nor none', 'invalid_response', undefined, {
16159
+ count: Array.isArray(folders) ? folders.length : null,
16160
+ });
16161
+ }
16162
+ return folders.length === 1 ? mapFolder(folders[0]) : null;
16163
+ }
16124
16164
  /**
16125
16165
  * Get a single folder.
16126
16166
  *
@@ -17565,7 +17605,7 @@ class SparkVault {
17565
17605
  }
17566
17606
  /** Get the SDK version */
17567
17607
  static get version() {
17568
- return '11.2.6';
17608
+ return '11.3.1';
17569
17609
  }
17570
17610
  }
17571
17611
  if (typeof window !== 'undefined') {