@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/folders/index.d.ts +16 -0
- package/dist/index.cjs +39 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +16 -0
- package/dist/index.mjs +39 -3
- package/dist/index.mjs.map +1 -1
- package/dist/sparkvault.js +1 -1
- package/dist/sparkvault.js.map +1 -1
- package/package.json +1 -1
package/dist/folders/index.d.ts
CHANGED
|
@@ -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
|
@@ -1370,7 +1370,7 @@ function buildRequestPath(literals, values) {
|
|
|
1370
1370
|
/**
|
|
1371
1371
|
* Encode query parameters, leaving out every unset value (`undefined`, `null`
|
|
1372
1372
|
* or `''`). Other values are sent as their string form, so `0` and `false`
|
|
1373
|
-
* are sent.
|
|
1373
|
+
* are sent. A space is sent as `%20`, never `+`.
|
|
1374
1374
|
* @param {Readonly<Record<string, string | number | boolean | null | undefined>> | undefined} params
|
|
1375
1375
|
* @returns {string} `?a=1&b=2`, or '' when no value is set.
|
|
1376
1376
|
*/
|
|
@@ -1380,7 +1380,12 @@ function queryString(params) {
|
|
|
1380
1380
|
if (value === undefined || value === null || value === '') continue;
|
|
1381
1381
|
search.append(key, String(value));
|
|
1382
1382
|
}
|
|
1383
|
-
|
|
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');
|
|
1384
1389
|
return query ? `?${query}` : '';
|
|
1385
1390
|
}
|
|
1386
1391
|
|
|
@@ -16121,6 +16126,37 @@ class FoldersModule {
|
|
|
16121
16126
|
const response = await this.http.get(apiPath `/v1/vaults/${vaultId}/folders`, { vat: vault.vatToken });
|
|
16122
16127
|
return (response.data.folders ?? []).map(mapFolder);
|
|
16123
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
|
+
}
|
|
16124
16160
|
/**
|
|
16125
16161
|
* Get a single folder.
|
|
16126
16162
|
*
|
|
@@ -17565,7 +17601,7 @@ class SparkVault {
|
|
|
17565
17601
|
}
|
|
17566
17602
|
/** Get the SDK version */
|
|
17567
17603
|
static get version() {
|
|
17568
|
-
return '11.
|
|
17604
|
+
return '11.3.0';
|
|
17569
17605
|
}
|
|
17570
17606
|
}
|
|
17571
17607
|
if (typeof window !== 'undefined') {
|