@fabriktor/client 0.0.80 → 0.0.82
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/crud.d.ts +4 -4
- package/dist/src/core/crud.js +4 -0
- package/dist/src/core/http.d.ts +5 -1
- package/dist/src/core/http.js +6 -1
- package/dist/src/core/idempotency.d.ts +1 -0
- package/dist/src/core/idempotency.js +1 -1
- package/dist/src/core/multipart.d.ts +2 -2
- package/dist/src/core/multipart.js +6 -1
- package/dist/src/storage/storage.d.ts +2 -2
- package/dist/src/storage/storage.js +2 -0
- package/package.json +2 -2
package/dist/src/core/crud.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { OperationResultValueKey, SearchResultResultsKey, type OperationResult, type SearchResult, type UpsertResult } from "@fabriktor/schema";
|
|
2
2
|
import type { TokenProvider } from "./auth.js";
|
|
3
3
|
import { type QueryOptions } from "./col.js";
|
|
4
|
-
import type { HTTPDoer } from "./http.js";
|
|
4
|
+
import type { HTTPDoer, RequestOptions } from "./http.js";
|
|
5
5
|
import type { CompletePayload, ReplaceOptionalField } from "./type.js";
|
|
6
6
|
export type OperationResultOf<T> = ReplaceOptionalField<OperationResult, typeof OperationResultValueKey, T>;
|
|
7
7
|
export type SearchResultOf<T> = ReplaceOptionalField<SearchResult, typeof SearchResultResultsKey, T[]>;
|
|
@@ -15,17 +15,17 @@ export type CRUDClientOptions = {
|
|
|
15
15
|
export type QueryOptionsCRUD = {
|
|
16
16
|
query?: QueryOptions;
|
|
17
17
|
};
|
|
18
|
-
export type InsertOneOptionsCRUD<In> = {
|
|
18
|
+
export type InsertOneOptionsCRUD<In> = RequestOptions & {
|
|
19
19
|
in: CompletePayload<In>;
|
|
20
20
|
};
|
|
21
21
|
export type UpsertOneOptionsCRUD<In> = {
|
|
22
22
|
in: CompletePayload<In>;
|
|
23
23
|
query?: QueryOptions;
|
|
24
24
|
};
|
|
25
|
-
export type FindOneOptionsCRUD = {
|
|
25
|
+
export type FindOneOptionsCRUD = Pick<RequestOptions, "signal"> & {
|
|
26
26
|
id: string;
|
|
27
27
|
};
|
|
28
|
-
export type ReplaceOneOptionsCRUD<In> = {
|
|
28
|
+
export type ReplaceOneOptionsCRUD<In> = Pick<RequestOptions, "signal"> & {
|
|
29
29
|
id: string;
|
|
30
30
|
in: Partial<In>;
|
|
31
31
|
};
|
package/dist/src/core/crud.js
CHANGED
|
@@ -45,6 +45,8 @@ export class CRUDClient {
|
|
|
45
45
|
method: HTTPMethodPost,
|
|
46
46
|
token,
|
|
47
47
|
body: opts.in,
|
|
48
|
+
signal: opts.signal,
|
|
49
|
+
idempotency_key: opts.idempotency_key,
|
|
48
50
|
});
|
|
49
51
|
}
|
|
50
52
|
async upsertOne(opts) {
|
|
@@ -72,6 +74,7 @@ export class CRUDClient {
|
|
|
72
74
|
id: opts.id,
|
|
73
75
|
}),
|
|
74
76
|
method: HTTPMethodGet,
|
|
77
|
+
signal: opts.signal,
|
|
75
78
|
token,
|
|
76
79
|
});
|
|
77
80
|
}
|
|
@@ -86,6 +89,7 @@ export class CRUDClient {
|
|
|
86
89
|
}),
|
|
87
90
|
method: HTTPMethodPatch,
|
|
88
91
|
token,
|
|
92
|
+
signal: opts.signal,
|
|
89
93
|
body: opts.in,
|
|
90
94
|
});
|
|
91
95
|
}
|
package/dist/src/core/http.d.ts
CHANGED
|
@@ -5,7 +5,11 @@ export declare const headerContentType = "content-type";
|
|
|
5
5
|
export declare const headerContentDisposition = "content-disposition";
|
|
6
6
|
export declare const prefixBearer = "Bearer";
|
|
7
7
|
export type Method = typeof HTTPMethodGet | typeof HTTPMethodPost | typeof HTTPMethodPatch | typeof HTTPMethodDelete;
|
|
8
|
-
export type
|
|
8
|
+
export type RequestOptions = {
|
|
9
|
+
signal?: AbortSignal;
|
|
10
|
+
idempotency_key?: string;
|
|
11
|
+
};
|
|
12
|
+
export type HTTPOptions<T> = RequestOptions & {
|
|
9
13
|
base_url: string;
|
|
10
14
|
path: string;
|
|
11
15
|
method: Method;
|
package/dist/src/core/http.js
CHANGED
|
@@ -51,6 +51,9 @@ export class HTTPClient {
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
async response(opts) {
|
|
54
|
+
if (opts.signal?.aborted) {
|
|
55
|
+
throw errHTTPRequestFailed(opts.signal.reason);
|
|
56
|
+
}
|
|
54
57
|
const h = headers(opts);
|
|
55
58
|
const requestBody = body(opts.body);
|
|
56
59
|
const idempotencyPath = idempotencyRequestPath(opts.path, requestBody);
|
|
@@ -59,6 +62,7 @@ export class HTTPClient {
|
|
|
59
62
|
store: this.idempotency,
|
|
60
63
|
method: opts.method,
|
|
61
64
|
path: idempotencyPath,
|
|
65
|
+
key: opts.idempotency_key,
|
|
62
66
|
});
|
|
63
67
|
let res;
|
|
64
68
|
try {
|
|
@@ -66,12 +70,13 @@ export class HTTPClient {
|
|
|
66
70
|
method: opts.method,
|
|
67
71
|
headers: h,
|
|
68
72
|
body: requestBody,
|
|
73
|
+
signal: opts.signal,
|
|
69
74
|
});
|
|
70
75
|
}
|
|
71
76
|
catch (err) {
|
|
72
77
|
throw errHTTPRequestFailed(err);
|
|
73
78
|
}
|
|
74
|
-
if (idempotencyToken !== undefined) {
|
|
79
|
+
if (idempotencyToken !== undefined && opts.idempotency_key === undefined) {
|
|
75
80
|
this.idempotency.reset(opts.method, idempotencyPath);
|
|
76
81
|
}
|
|
77
82
|
if (!res.ok) {
|
|
@@ -34,7 +34,7 @@ export function applyIdempotencyHeader(opts) {
|
|
|
34
34
|
if (!shouldUseIdempotency(opts.method)) {
|
|
35
35
|
return undefined;
|
|
36
36
|
}
|
|
37
|
-
const token = opts.store.get(opts.method, opts.path);
|
|
37
|
+
const token = opts.key ?? opts.store.get(opts.method, opts.path);
|
|
38
38
|
opts.headers.set(HeaderIdempotency, token);
|
|
39
39
|
return token;
|
|
40
40
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { HTTPMethodPost } from "@fabriktor/schema";
|
|
2
|
-
import type { Fetcher } from "./http.js";
|
|
2
|
+
import type { Fetcher, RequestOptions } from "./http.js";
|
|
3
3
|
import type { IdempotencyStore } from "./idempotency.js";
|
|
4
4
|
export type MultipartMethod = typeof HTTPMethodPost;
|
|
5
|
-
export type MultipartOptions = {
|
|
5
|
+
export type MultipartOptions = RequestOptions & {
|
|
6
6
|
base_url: string;
|
|
7
7
|
path: string;
|
|
8
8
|
method: MultipartMethod;
|
|
@@ -14,12 +14,16 @@ export class MultipartClient {
|
|
|
14
14
|
this.idempotency = opts.idempotency;
|
|
15
15
|
}
|
|
16
16
|
async do(opts) {
|
|
17
|
+
if (opts.signal?.aborted) {
|
|
18
|
+
throw errHTTPRequestFailed(opts.signal.reason);
|
|
19
|
+
}
|
|
17
20
|
const h = headers(opts);
|
|
18
21
|
const idempotencyToken = applyIdempotencyHeader({
|
|
19
22
|
headers: h,
|
|
20
23
|
store: this.idempotency,
|
|
21
24
|
method: opts.method,
|
|
22
25
|
path: opts.path,
|
|
26
|
+
key: opts.idempotency_key,
|
|
23
27
|
});
|
|
24
28
|
let res;
|
|
25
29
|
try {
|
|
@@ -27,12 +31,13 @@ export class MultipartClient {
|
|
|
27
31
|
method: opts.method,
|
|
28
32
|
headers: h,
|
|
29
33
|
body: opts.form,
|
|
34
|
+
signal: opts.signal,
|
|
30
35
|
});
|
|
31
36
|
}
|
|
32
37
|
catch (err) {
|
|
33
38
|
throw errHTTPRequestFailed(err);
|
|
34
39
|
}
|
|
35
|
-
if (idempotencyToken !== undefined) {
|
|
40
|
+
if (idempotencyToken !== undefined && opts.idempotency_key === undefined) {
|
|
36
41
|
this.idempotency.reset(opts.method, opts.path);
|
|
37
42
|
}
|
|
38
43
|
if (!res.ok) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type Object as StorageObject, type OperationResult, type PLStorageDownload, type RPStorageUpload } from "@fabriktor/schema";
|
|
2
2
|
import type { TokenProvider } from "../core/auth.js";
|
|
3
3
|
import type { DeleteOneOptionsCRUD, OperationResultOf } from "../core/crud.js";
|
|
4
|
-
import type { HTTPDoer } from "../core/http.js";
|
|
4
|
+
import type { HTTPDoer, RequestOptions } from "../core/http.js";
|
|
5
5
|
import { type MultipartDoer } from "../core/multipart.js";
|
|
6
6
|
import type { CompletePayload } from "../core/type.js";
|
|
7
7
|
export declare const storageCollections: readonly ["calls", "chat", "contacts", "jobs", "locations", "memos", "qr", "reports", "tickets", "users", "feed"];
|
|
@@ -10,7 +10,7 @@ export type StorageUploadFile = File | {
|
|
|
10
10
|
blob: Blob;
|
|
11
11
|
filename: string;
|
|
12
12
|
};
|
|
13
|
-
export type UploadStorageOptions = {
|
|
13
|
+
export type UploadStorageOptions = RequestOptions & {
|
|
14
14
|
owner_id: string;
|
|
15
15
|
uploader_id?: string;
|
|
16
16
|
full_quality?: boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fabriktor/client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.82",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -17,6 +17,6 @@
|
|
|
17
17
|
"typescript": "^6.0.3"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@fabriktor/schema": "0.0.
|
|
20
|
+
"@fabriktor/schema": "0.0.63"
|
|
21
21
|
}
|
|
22
22
|
}
|