@fabriktor/client 0.0.32 → 0.0.34
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/src/core/err.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { HTTPErr, WrenchErr } from "@fabriktor/schema";
|
|
|
2
2
|
export declare const ClientErrKind: {
|
|
3
3
|
readonly AuthTokenProviderMissing: "auth_token_provider_missing";
|
|
4
4
|
readonly AuthTokenEmpty: "auth_token_empty";
|
|
5
|
+
readonly InvalidArgument: "invalid_argument";
|
|
5
6
|
readonly HTTPError: "http_error";
|
|
6
7
|
readonly HTTPRequestFailed: "http_request_failed";
|
|
7
8
|
readonly HTTPResponseInvalid: "http_response_invalid";
|
|
@@ -15,6 +16,10 @@ export type ClientErrOptions = {
|
|
|
15
16
|
app_err?: WrenchErr;
|
|
16
17
|
cause?: unknown;
|
|
17
18
|
};
|
|
19
|
+
export type InvalidArgumentClientErrOptions = {
|
|
20
|
+
msg: string;
|
|
21
|
+
cause?: unknown;
|
|
22
|
+
};
|
|
18
23
|
export declare class ClientErr extends Error {
|
|
19
24
|
readonly kind: ClientErrKind;
|
|
20
25
|
readonly status?: number;
|
|
@@ -23,6 +28,7 @@ export declare class ClientErr extends Error {
|
|
|
23
28
|
constructor(opts: ClientErrOptions);
|
|
24
29
|
}
|
|
25
30
|
export declare function errClient(opts: ClientErrOptions): ClientErr;
|
|
31
|
+
export declare function errInvalidArgument(opts: InvalidArgumentClientErrOptions): ClientErr;
|
|
26
32
|
export declare function errFromHTTP(err: HTTPErr): ClientErr;
|
|
27
33
|
export declare function errAuthTokenProviderMissing(): ClientErr;
|
|
28
34
|
export declare function errAuthTokenEmpty(): ClientErr;
|
package/dist/src/core/err.js
CHANGED
|
@@ -7,6 +7,7 @@ const msgUnknownClientErr = "Unknown client error.";
|
|
|
7
7
|
export const ClientErrKind = {
|
|
8
8
|
AuthTokenProviderMissing: "auth_token_provider_missing",
|
|
9
9
|
AuthTokenEmpty: "auth_token_empty",
|
|
10
|
+
InvalidArgument: "invalid_argument",
|
|
10
11
|
HTTPError: "http_error",
|
|
11
12
|
HTTPRequestFailed: "http_request_failed",
|
|
12
13
|
HTTPResponseInvalid: "http_response_invalid",
|
|
@@ -29,6 +30,13 @@ export class ClientErr extends Error {
|
|
|
29
30
|
export function errClient(opts) {
|
|
30
31
|
return new ClientErr(opts);
|
|
31
32
|
}
|
|
33
|
+
export function errInvalidArgument(opts) {
|
|
34
|
+
return errClient({
|
|
35
|
+
kind: ClientErrKind.InvalidArgument,
|
|
36
|
+
msg: opts.msg,
|
|
37
|
+
cause: opts.cause,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
32
40
|
export function errFromHTTP(err) {
|
|
33
41
|
return errClient({
|
|
34
42
|
kind: ClientErrKind.HTTPError,
|
|
@@ -7,12 +7,14 @@ import { ColStorageCalls, ColStorageChat, ColStorageContacts, ColStorageJobs, Co
|
|
|
7
7
|
import { requiredToken } from "../core/auth.js";
|
|
8
8
|
import { withQuery } from "../core/col.js";
|
|
9
9
|
import { newCRUDClient } from "../core/crud.js";
|
|
10
|
+
import { errInvalidArgument } from "../core/err.js";
|
|
10
11
|
import { newMultipartClient } from "../core/multipart.js";
|
|
11
12
|
import { buildPath } from "../core/path.js";
|
|
12
13
|
const queryOwnerID = "owner_id";
|
|
13
14
|
const queryUploaderID = "uploader_id";
|
|
14
15
|
const queryFullQuality = "full_quality";
|
|
15
16
|
const fileFieldName = "file";
|
|
17
|
+
const msgUploadRequiresFile = "Upload requires at least one file.";
|
|
16
18
|
export const storageCollections = [
|
|
17
19
|
ColStorageCalls,
|
|
18
20
|
ColStorageChat,
|
|
@@ -48,13 +50,14 @@ export class StorageClient {
|
|
|
48
50
|
this.get_token = opts.get_token;
|
|
49
51
|
}
|
|
50
52
|
async upload(col, opts) {
|
|
53
|
+
const form = uploadForm(opts);
|
|
51
54
|
const token = await requiredToken(this.get_token);
|
|
52
55
|
return await this.multipart.do({
|
|
53
56
|
base_url: this.base_url,
|
|
54
57
|
path: uploadPath(col, opts),
|
|
55
58
|
method: HTTPMethodPost,
|
|
56
59
|
token,
|
|
57
|
-
form
|
|
60
|
+
form,
|
|
58
61
|
});
|
|
59
62
|
}
|
|
60
63
|
async download(col, opts) {
|
|
@@ -196,7 +199,9 @@ export class StorageClient {
|
|
|
196
199
|
object(col) {
|
|
197
200
|
const c = this.objects.get(col);
|
|
198
201
|
if (c === undefined) {
|
|
199
|
-
throw
|
|
202
|
+
throw errInvalidArgument({
|
|
203
|
+
msg: `Unknown storage collection: ${col}.`,
|
|
204
|
+
});
|
|
200
205
|
}
|
|
201
206
|
return c;
|
|
202
207
|
}
|
|
@@ -222,7 +227,9 @@ function storagePath(col, action) {
|
|
|
222
227
|
}
|
|
223
228
|
function uploadForm(opts) {
|
|
224
229
|
if (opts.files.length === 0) {
|
|
225
|
-
throw
|
|
230
|
+
throw errInvalidArgument({
|
|
231
|
+
msg: msgUploadRequiresFile,
|
|
232
|
+
});
|
|
226
233
|
}
|
|
227
234
|
const form = new FormData();
|
|
228
235
|
for (const f of opts.files) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fabriktor/client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.34",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -18,6 +18,6 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@fabriktor/client": "0.0.25",
|
|
21
|
-
"@fabriktor/schema": "0.0.
|
|
21
|
+
"@fabriktor/schema": "0.0.28"
|
|
22
22
|
}
|
|
23
23
|
}
|