@fabriktor/client 0.0.29 → 0.0.31
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/chat/chat.js +7 -17
- package/dist/src/core/col.d.ts +7 -1
- package/dist/src/core/col.js +29 -14
- package/dist/src/core/http.d.ts +0 -4
- package/dist/src/storage/storage.js +6 -13
- package/dist/src/users/tmp_usernames.d.ts +4 -3
- package/dist/src/users/users.d.ts +12 -11
- package/dist/src/users/users.js +4 -1
- package/package.json +1 -1
package/dist/src/chat/chat.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
6
|
import { ColChatChatRoomMembers, ColChatChatRooms, ColChatChats, HTTPMethodPost, PathChatEnsure, PathChatReact, PathChatWS, PathChatWSMine, SvcChat, } from "@fabriktor/schema";
|
|
7
7
|
import { requiredToken } from "../core/auth.js";
|
|
8
|
+
import { queryParam, queryParams, withQuery } from "../core/col.js";
|
|
8
9
|
import { newCRUDClient } from "../core/crud.js";
|
|
9
10
|
import { buildPath } from "../core/path.js";
|
|
10
11
|
const protocolFirebase = "firebase";
|
|
@@ -12,9 +13,6 @@ const schemeHTTP = "http:";
|
|
|
12
13
|
const schemeHTTPS = "https:";
|
|
13
14
|
const schemeWS = "ws:";
|
|
14
15
|
const schemeWSS = "wss:";
|
|
15
|
-
const queryID = "id";
|
|
16
|
-
const queryOwnerID = "owner_id";
|
|
17
|
-
const queryChatRoomID = "chat_room_id";
|
|
18
16
|
export class ChatClient {
|
|
19
17
|
chats;
|
|
20
18
|
chat_rooms;
|
|
@@ -130,8 +128,10 @@ export class ChatClient {
|
|
|
130
128
|
return openWS({
|
|
131
129
|
base_url: this.base_url,
|
|
132
130
|
path: withQuery(chatPath(PathChatWS), {
|
|
133
|
-
|
|
134
|
-
|
|
131
|
+
query: queryParams({
|
|
132
|
+
owner_id: opts.owner_id,
|
|
133
|
+
chat_room_id: opts.chat_room_id,
|
|
134
|
+
}),
|
|
135
135
|
}),
|
|
136
136
|
token,
|
|
137
137
|
on_message: opts.on_message,
|
|
@@ -144,7 +144,7 @@ export class ChatClient {
|
|
|
144
144
|
return openWS({
|
|
145
145
|
base_url: this.base_url,
|
|
146
146
|
path: withQuery(chatRoomPath(PathChatWS), {
|
|
147
|
-
|
|
147
|
+
query: queryParam("id", opts.id),
|
|
148
148
|
}),
|
|
149
149
|
token,
|
|
150
150
|
on_message: opts.on_message,
|
|
@@ -157,7 +157,7 @@ export class ChatClient {
|
|
|
157
157
|
return openWS({
|
|
158
158
|
base_url: this.base_url,
|
|
159
159
|
path: withQuery(chatRoomPath(PathChatWSMine), {
|
|
160
|
-
|
|
160
|
+
query: queryParam("owner_id", opts.owner_id),
|
|
161
161
|
}),
|
|
162
162
|
token,
|
|
163
163
|
on_message: opts.on_message,
|
|
@@ -222,13 +222,3 @@ function wsURL(base, path) {
|
|
|
222
222
|
function ensureSlash(x) {
|
|
223
223
|
return x.endsWith("/") ? x : `${x}/`;
|
|
224
224
|
}
|
|
225
|
-
function withQuery(path, query) {
|
|
226
|
-
const q = new URLSearchParams();
|
|
227
|
-
for (const [k, v] of Object.entries(query)) {
|
|
228
|
-
if (v !== undefined && v.trim() !== "") {
|
|
229
|
-
q.set(k, v);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
const s = q.toString();
|
|
233
|
-
return s === "" ? path : `${path}?${s}`;
|
|
234
|
-
}
|
package/dist/src/core/col.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
export type FieldOf<T> = Extract<keyof T, string>;
|
|
1
2
|
export type QueryValue = string | number | boolean | undefined | null;
|
|
2
|
-
export type
|
|
3
|
+
export type QueryInputValue = QueryValue | QueryValue[];
|
|
4
|
+
export type QueryOptions = Record<string, QueryInputValue>;
|
|
5
|
+
export type TypedQueryOptions<T> = Partial<Record<FieldOf<T>, QueryInputValue>>;
|
|
3
6
|
export type CollectionPathOptions = {
|
|
4
7
|
svc: string;
|
|
5
8
|
col: string;
|
|
@@ -12,4 +15,7 @@ export type BuildQueryOptions = {
|
|
|
12
15
|
};
|
|
13
16
|
export declare function collectionPath(opts: CollectionPathOptions): string;
|
|
14
17
|
export declare function idPath(opts: IDPathOptions): string;
|
|
18
|
+
export declare function queryParam<T>(key: FieldOf<T>, value: QueryInputValue): QueryOptions;
|
|
19
|
+
export declare function queryParams<T>(query: TypedQueryOptions<T>): QueryOptions;
|
|
20
|
+
export declare function mergeQueryOptions(...queries: Array<QueryOptions | undefined>): QueryOptions;
|
|
15
21
|
export declare function withQuery(path: string, opts?: BuildQueryOptions): string;
|
package/dist/src/core/col.js
CHANGED
|
@@ -17,26 +17,23 @@ export function idPath(opts) {
|
|
|
17
17
|
id: opts.id,
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
|
+
export function queryParam(key, value) {
|
|
21
|
+
return { [key]: value };
|
|
22
|
+
}
|
|
23
|
+
export function queryParams(query) {
|
|
24
|
+
return query;
|
|
25
|
+
}
|
|
26
|
+
export function mergeQueryOptions(...queries) {
|
|
27
|
+
return Object.assign({}, ...queries);
|
|
28
|
+
}
|
|
20
29
|
export function withQuery(path, opts) {
|
|
21
30
|
const query = opts?.query;
|
|
22
|
-
if (
|
|
31
|
+
if (query === undefined) {
|
|
23
32
|
return path;
|
|
24
33
|
}
|
|
25
34
|
const params = new URLSearchParams();
|
|
26
35
|
for (const [key, value] of Object.entries(query)) {
|
|
27
|
-
|
|
28
|
-
continue;
|
|
29
|
-
}
|
|
30
|
-
if (Array.isArray(value)) {
|
|
31
|
-
for (const item of value) {
|
|
32
|
-
if (item === undefined || item === null) {
|
|
33
|
-
continue;
|
|
34
|
-
}
|
|
35
|
-
params.append(key, String(item));
|
|
36
|
-
}
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
params.set(key, String(value));
|
|
36
|
+
appendQueryValue(params, key, value);
|
|
40
37
|
}
|
|
41
38
|
const raw = params.toString();
|
|
42
39
|
if (raw === "") {
|
|
@@ -44,3 +41,21 @@ export function withQuery(path, opts) {
|
|
|
44
41
|
}
|
|
45
42
|
return `${path}?${raw}`;
|
|
46
43
|
}
|
|
44
|
+
function appendQueryValue(params, key, value) {
|
|
45
|
+
if (value === undefined || value === null) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (Array.isArray(value)) {
|
|
49
|
+
for (const item of value) {
|
|
50
|
+
appendQuerySingleValue(params, key, item);
|
|
51
|
+
}
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
appendQuerySingleValue(params, key, value);
|
|
55
|
+
}
|
|
56
|
+
function appendQuerySingleValue(params, key, value) {
|
|
57
|
+
if (value === undefined || value === null) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
params.append(key, String(value));
|
|
61
|
+
}
|
package/dist/src/core/http.d.ts
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import { HTTPMethodDelete, HTTPMethodGet, HTTPMethodPatch, HTTPMethodPost } from "@fabriktor/schema";
|
|
2
|
-
import type { OperationResult } from "@fabriktor/schema";
|
|
3
2
|
import type { IdempotencyStore } from "./idempotency.js";
|
|
4
3
|
export declare const headerAuthorization = "authorization";
|
|
5
4
|
export declare const headerContentType = "content-type";
|
|
6
5
|
export declare const prefixBearer = "Bearer";
|
|
7
6
|
export type Method = typeof HTTPMethodGet | typeof HTTPMethodPost | typeof HTTPMethodPatch | typeof HTTPMethodDelete;
|
|
8
|
-
export type Op<T> = Omit<OperationResult, "value"> & {
|
|
9
|
-
value?: T;
|
|
10
|
-
};
|
|
11
7
|
export type HTTPOptions<T> = {
|
|
12
8
|
base_url: string;
|
|
13
9
|
path: string;
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
6
|
import { ColStorageCalls, ColStorageChat, ColStorageContacts, ColStorageJobs, ColStorageLocations, ColStorageMemos, ColStorageQR, ColStorageReports, ColStorageTickets, ColStorageUsers, HTTPMethodPost, PathStorageDownload, PathStorageUpload, SvcStorage, } from "@fabriktor/schema";
|
|
7
7
|
import { requiredToken } from "../core/auth.js";
|
|
8
|
+
import { withQuery } from "../core/col.js";
|
|
8
9
|
import { newCRUDClient } from "../core/crud.js";
|
|
9
10
|
import { newMultipartClient } from "../core/multipart.js";
|
|
10
11
|
import { buildPath } from "../core/path.js";
|
|
@@ -205,9 +206,11 @@ export function newStorageClient(opts) {
|
|
|
205
206
|
}
|
|
206
207
|
function uploadPath(col, opts) {
|
|
207
208
|
return withQuery(storagePath(col, PathStorageUpload), {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
209
|
+
query: {
|
|
210
|
+
[queryOwnerID]: opts.owner_id,
|
|
211
|
+
[queryUploaderID]: opts.uploader_id,
|
|
212
|
+
[queryFullQuality]: opts.full_quality,
|
|
213
|
+
},
|
|
211
214
|
});
|
|
212
215
|
}
|
|
213
216
|
function storagePath(col, action) {
|
|
@@ -237,13 +240,3 @@ function appendFile(form, f) {
|
|
|
237
240
|
function isFile(f) {
|
|
238
241
|
return typeof File !== "undefined" && f instanceof File;
|
|
239
242
|
}
|
|
240
|
-
function withQuery(path, query) {
|
|
241
|
-
const q = new URLSearchParams();
|
|
242
|
-
for (const [k, v] of Object.entries(query)) {
|
|
243
|
-
if (v !== undefined && v.trim() !== "") {
|
|
244
|
-
q.set(k, v);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
const s = q.toString();
|
|
248
|
-
return s === "" ? path : `${path}?${s}`;
|
|
249
|
-
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { type PLUsersUsername } from "@fabriktor/schema";
|
|
2
2
|
import type { TokenProvider } from "../core/auth.js";
|
|
3
|
-
import type {
|
|
3
|
+
import type { OperationResultOf } from "../core/crud.js";
|
|
4
|
+
import type { HTTPDoer } from "../core/http.js";
|
|
4
5
|
export type VerifyUsernameOptions = PLUsersUsername;
|
|
5
6
|
export type UsernameVerification = string[];
|
|
6
7
|
export interface TmpUsernamesOperator {
|
|
7
|
-
verify(opts: VerifyUsernameOptions): Promise<
|
|
8
|
+
verify(opts: VerifyUsernameOptions): Promise<OperationResultOf<UsernameVerification>>;
|
|
8
9
|
}
|
|
9
10
|
export type TmpUsernamesClientOptions = {
|
|
10
11
|
http: HTTPDoer;
|
|
@@ -16,6 +17,6 @@ export declare class TmpUsernamesClient implements TmpUsernamesOperator {
|
|
|
16
17
|
private base_url;
|
|
17
18
|
private get_token?;
|
|
18
19
|
constructor(opts: TmpUsernamesClientOptions);
|
|
19
|
-
verify(opts: VerifyUsernameOptions): Promise<
|
|
20
|
+
verify(opts: VerifyUsernameOptions): Promise<OperationResultOf<UsernameVerification>>;
|
|
20
21
|
}
|
|
21
22
|
export declare function newTmpUsernamesClient(opts: TmpUsernamesClientOptions): TmpUsernamesClient;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type InUser, type OperationResult, type PLUsersContactList, type PLUsersForgotPassword, type PLUsersResolveUsername, type PLUsersSignInLink, type PLUsersVerifyEmail, type UpsertResult, type User } from "@fabriktor/schema";
|
|
2
2
|
import type { TokenProvider } from "../core/auth.js";
|
|
3
|
-
import type {
|
|
3
|
+
import type { OperationResultOf } from "../core/crud.js";
|
|
4
|
+
import type { HTTPDoer } from "../core/http.js";
|
|
4
5
|
export type BootstrapOptions = {
|
|
5
6
|
in: InUser;
|
|
6
7
|
};
|
|
@@ -17,15 +18,15 @@ export type GetByUIDOptions = {
|
|
|
17
18
|
uid: string;
|
|
18
19
|
};
|
|
19
20
|
export interface UsersOperator {
|
|
20
|
-
bootstrap(opts: BootstrapOptions): Promise<
|
|
21
|
+
bootstrap(opts: BootstrapOptions): Promise<OperationResultOf<UpsertResult>>;
|
|
21
22
|
sync(): Promise<OperationResult>;
|
|
22
23
|
sendEmailVerification(opts: SendEmailVerificationOptions): Promise<void>;
|
|
23
24
|
forgotPassword(opts: ForgotPasswordOptions): Promise<void>;
|
|
24
25
|
sendSignInLink(opts: SendSignInLinkOptions): Promise<void>;
|
|
25
|
-
resolveUsername(opts: ResolveUsernameOptions): Promise<
|
|
26
|
-
match(opts: MatchOptions): Promise<
|
|
27
|
-
search(opts: SearchOptions): Promise<
|
|
28
|
-
getByUID(opts: GetByUIDOptions): Promise<
|
|
26
|
+
resolveUsername(opts: ResolveUsernameOptions): Promise<OperationResultOf<string>>;
|
|
27
|
+
match(opts: MatchOptions): Promise<OperationResultOf<User[]>>;
|
|
28
|
+
search(opts: SearchOptions): Promise<OperationResultOf<User[]>>;
|
|
29
|
+
getByUID(opts: GetByUIDOptions): Promise<OperationResultOf<User[]>>;
|
|
29
30
|
}
|
|
30
31
|
export type UsersClientOptions = {
|
|
31
32
|
http: HTTPDoer;
|
|
@@ -37,14 +38,14 @@ export declare class UsersClient implements UsersOperator {
|
|
|
37
38
|
private base_url;
|
|
38
39
|
private get_token?;
|
|
39
40
|
constructor(opts: UsersClientOptions);
|
|
40
|
-
bootstrap(opts: BootstrapOptions): Promise<
|
|
41
|
+
bootstrap(opts: BootstrapOptions): Promise<OperationResultOf<UpsertResult>>;
|
|
41
42
|
sync(): Promise<OperationResult>;
|
|
42
43
|
sendEmailVerification(opts: SendEmailVerificationOptions): Promise<void>;
|
|
43
44
|
forgotPassword(opts: ForgotPasswordOptions): Promise<void>;
|
|
44
45
|
sendSignInLink(opts: SendSignInLinkOptions): Promise<void>;
|
|
45
|
-
resolveUsername(opts: ResolveUsernameOptions): Promise<
|
|
46
|
-
match(opts: MatchOptions): Promise<
|
|
47
|
-
search(opts: SearchOptions): Promise<
|
|
48
|
-
getByUID(opts: GetByUIDOptions): Promise<
|
|
46
|
+
resolveUsername(opts: ResolveUsernameOptions): Promise<OperationResultOf<string>>;
|
|
47
|
+
match(opts: MatchOptions): Promise<OperationResultOf<User[]>>;
|
|
48
|
+
search(opts: SearchOptions): Promise<OperationResultOf<User[]>>;
|
|
49
|
+
getByUID(opts: GetByUIDOptions): Promise<OperationResultOf<User[]>>;
|
|
49
50
|
}
|
|
50
51
|
export declare function newUsersClient(opts: UsersClientOptions): UsersClient;
|
package/dist/src/users/users.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
6
|
import { ColUsersUsers, HTTPMethodGet, HTTPMethodPost, PathSearch, PathUsersBootstrap, PathUsersForgotPassword, PathUsersMatch, PathUsersResolveUsername, PathUsersSendEmailVerification, PathUsersSendSignInLink, PathUsersSync, SvcUsers, } from "@fabriktor/schema";
|
|
7
7
|
import { requiredToken } from "../core/auth.js";
|
|
8
|
+
import { queryParam, withQuery } from "../core/col.js";
|
|
8
9
|
import { buildPath } from "../core/path.js";
|
|
9
10
|
export class UsersClient {
|
|
10
11
|
http;
|
|
@@ -105,7 +106,9 @@ export class UsersClient {
|
|
|
105
106
|
const token = await requiredToken(this.get_token);
|
|
106
107
|
return await this.http.do({
|
|
107
108
|
base_url: this.base_url,
|
|
108
|
-
path:
|
|
109
|
+
path: withQuery(collectionPath(), {
|
|
110
|
+
query: queryParam("uid", opts.uid),
|
|
111
|
+
}),
|
|
109
112
|
method: HTTPMethodGet,
|
|
110
113
|
token,
|
|
111
114
|
});
|