@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.
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
@@ -929,6 +929,10 @@ const RESOURCE_ID_PREFIXES = Object.freeze({
929
929
  attachment: 'hda',
930
930
  folder: 'fld',
931
931
  helpDeskJob: 'hdj',
932
+ knowledgeBaseArticle: 'hdkba',
933
+ knowledgeBaseCategory: 'hdkbc',
934
+ knowledgeBaseRevision: 'hdkbr',
935
+ knowledgeBaseAsset: 'hdkbm',
932
936
  ingot: 'ing',
933
937
  invite: 'inv',
934
938
  notification: 'ntf',
@@ -1366,7 +1370,7 @@ function buildRequestPath(literals, values) {
1366
1370
  /**
1367
1371
  * Encode query parameters, leaving out every unset value (`undefined`, `null`
1368
1372
  * or `''`). Other values are sent as their string form, so `0` and `false`
1369
- * are sent.
1373
+ * are sent. A space is sent as `%20`, never `+`.
1370
1374
  * @param {Readonly<Record<string, string | number | boolean | null | undefined>> | undefined} params
1371
1375
  * @returns {string} `?a=1&b=2`, or '' when no value is set.
1372
1376
  */
@@ -1376,7 +1380,12 @@ function queryString(params) {
1376
1380
  if (value === undefined || value === null || value === '') continue;
1377
1381
  search.append(key, String(value));
1378
1382
  }
1379
- const query = search.toString();
1383
+ // URLSearchParams writes a space as `+`, which only a form decoder reads
1384
+ // back as a space: a gateway or adapter that percent-decodes the query
1385
+ // (decodeURIComponent) hands the handler a literal `+`. `%20` is a space to
1386
+ // every decoder. The swap is exact because URLSearchParams has already
1387
+ // written each literal `+` as `%2B`, so every `+` left is a space.
1388
+ const query = search.toString().replace(/\+/g, '%20');
1380
1389
  return query ? `?${query}` : '';
1381
1390
  }
1382
1391
 
@@ -16117,6 +16126,37 @@ class FoldersModule {
16117
16126
  const response = await this.http.get(apiPath `/v1/vaults/${vaultId}/folders`, { vat: vault.vatToken });
16118
16127
  return (response.data.folders ?? []).map(mapFolder);
16119
16128
  }
16129
+ /**
16130
+ * The folder at `path`, or null when the vault has none there. `path` is an
16131
+ * upload's folder path (`folder` on an upload): slash-delimited from the
16132
+ * vault root, each name matched in any case, validated by the API as an
16133
+ * upload's is. The API reads only that path, never the vault's folder list.
16134
+ *
16135
+ * @throws ValidationError when `path` is not a non-empty string: an empty
16136
+ * value is left out of the query, which would ask for every folder instead
16137
+ * of the one at a path
16138
+ * @throws SparkVaultError (`invalid_response`) when the answer is not one
16139
+ * folder or none
16140
+ *
16141
+ * @example
16142
+ * const invoices = await sv.folders.findByPath(unsealed, 'Clients/Acme/Invoices');
16143
+ */
16144
+ async findByPath(vault, path) {
16145
+ const vaultId = requireVaultId(vault);
16146
+ if (typeof path !== 'string' || path.trim() === '') {
16147
+ throw new ValidationError('path must be a non-empty string', { field: 'path' });
16148
+ }
16149
+ const response = await this.http.get(apiPath `/v1/vaults/${vaultId}/folders`, { vat: vault.vatToken, query: { path } });
16150
+ // Exactly one folder or none: anything else (no list, or a list of
16151
+ // several) is not an answer to one path, and never picks a folder.
16152
+ const folders = response.data?.folders;
16153
+ if (!Array.isArray(folders) || folders.length > 1) {
16154
+ throw new SparkVaultError('A folder path lookup answered neither one folder nor none', 'invalid_response', undefined, {
16155
+ count: Array.isArray(folders) ? folders.length : null,
16156
+ });
16157
+ }
16158
+ return folders.length === 1 ? mapFolder(folders[0]) : null;
16159
+ }
16120
16160
  /**
16121
16161
  * Get a single folder.
16122
16162
  *
@@ -17561,7 +17601,7 @@ class SparkVault {
17561
17601
  }
17562
17602
  /** Get the SDK version */
17563
17603
  static get version() {
17564
- return '11.2.6';
17604
+ return '11.3.1';
17565
17605
  }
17566
17606
  }
17567
17607
  if (typeof window !== 'undefined') {