@fabriktor/client 0.0.29 → 0.0.32
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.d.ts +7 -13
- package/dist/src/chat/chat.js +8 -61
- 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/core/ws.d.ts +16 -0
- package/dist/src/core/ws.js +51 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- 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.d.ts
CHANGED
|
@@ -2,15 +2,9 @@ import { type Chat, type ChatRoom, type ChatRoomMember, type ID, type InChat, ty
|
|
|
2
2
|
import type { TokenProvider } from "../core/auth.js";
|
|
3
3
|
import type { DeleteManyOptionsCRUD, DeleteOneOptionsCRUD, FindOneOptionsCRUD, InsertOneOptionsCRUD, OperationResultOf, QueryOptionsCRUD, ReplaceOneOptionsCRUD, SearchManyOptionsCRUD, SearchResultOf } from "../core/crud.js";
|
|
4
4
|
import type { HTTPDoer } from "../core/http.js";
|
|
5
|
+
import { type WSCloseHandler, type WSConnection, type WSErrorHandler, type WSMessageHandler } from "../core/ws.js";
|
|
5
6
|
export type ReactChatOptions = PLChatReact;
|
|
6
7
|
export type EnsureChatRoomOptions = PLChatEnsure;
|
|
7
|
-
export type WSMessageHandler<T> = (v: T, ev: MessageEvent<string>) => void;
|
|
8
|
-
export type WSErrorHandler = (ev: Event) => void;
|
|
9
|
-
export type WSCloseHandler = (ev: CloseEvent) => void;
|
|
10
|
-
export type WSConnection<T> = {
|
|
11
|
-
socket: WebSocket;
|
|
12
|
-
close(code?: number, reason?: string): void;
|
|
13
|
-
};
|
|
14
8
|
export type WSChatsOptions = {
|
|
15
9
|
owner_id: string;
|
|
16
10
|
chat_room_id: string;
|
|
@@ -57,9 +51,9 @@ export interface ChatOperator {
|
|
|
57
51
|
searchManyChatRoomMembers(opts?: SearchManyOptionsCRUD): Promise<OperationResultOf<SearchResultOf<ChatRoomMember>>>;
|
|
58
52
|
reactChat(opts: ReactChatOptions): Promise<void>;
|
|
59
53
|
ensureChatRoom(opts: EnsureChatRoomOptions): Promise<ID>;
|
|
60
|
-
wsChats(opts: WSChatsOptions): Promise<WSConnection
|
|
61
|
-
wsChatRooms(opts: WSChatRoomsOptions): Promise<WSConnection
|
|
62
|
-
wsChatRoom(opts: WSChatRoomOptions): Promise<WSConnection
|
|
54
|
+
wsChats(opts: WSChatsOptions): Promise<WSConnection>;
|
|
55
|
+
wsChatRooms(opts: WSChatRoomsOptions): Promise<WSConnection>;
|
|
56
|
+
wsChatRoom(opts: WSChatRoomOptions): Promise<WSConnection>;
|
|
63
57
|
}
|
|
64
58
|
export declare class ChatClient implements ChatOperator {
|
|
65
59
|
private chats;
|
|
@@ -90,8 +84,8 @@ export declare class ChatClient implements ChatOperator {
|
|
|
90
84
|
searchManyChatRoomMembers(opts?: SearchManyOptionsCRUD): Promise<OperationResultOf<SearchResultOf<ChatRoomMember>>>;
|
|
91
85
|
reactChat(opts: ReactChatOptions): Promise<void>;
|
|
92
86
|
ensureChatRoom(opts: EnsureChatRoomOptions): Promise<ID>;
|
|
93
|
-
wsChats(opts: WSChatsOptions): Promise<WSConnection
|
|
94
|
-
wsChatRooms(opts: WSChatRoomsOptions): Promise<WSConnection
|
|
95
|
-
wsChatRoom(opts: WSChatRoomOptions): Promise<WSConnection
|
|
87
|
+
wsChats(opts: WSChatsOptions): Promise<WSConnection>;
|
|
88
|
+
wsChatRooms(opts: WSChatRoomsOptions): Promise<WSConnection>;
|
|
89
|
+
wsChatRoom(opts: WSChatRoomOptions): Promise<WSConnection>;
|
|
96
90
|
}
|
|
97
91
|
export declare function newChatClient(opts: ChatClientOptions): ChatClient;
|
package/dist/src/chat/chat.js
CHANGED
|
@@ -5,16 +5,10 @@
|
|
|
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 schemeHTTP = "http:";
|
|
12
|
-
const schemeHTTPS = "https:";
|
|
13
|
-
const schemeWS = "ws:";
|
|
14
|
-
const schemeWSS = "wss:";
|
|
15
|
-
const queryID = "id";
|
|
16
|
-
const queryOwnerID = "owner_id";
|
|
17
|
-
const queryChatRoomID = "chat_room_id";
|
|
11
|
+
import { openWS, } from "../core/ws.js";
|
|
18
12
|
export class ChatClient {
|
|
19
13
|
chats;
|
|
20
14
|
chat_rooms;
|
|
@@ -130,8 +124,10 @@ export class ChatClient {
|
|
|
130
124
|
return openWS({
|
|
131
125
|
base_url: this.base_url,
|
|
132
126
|
path: withQuery(chatPath(PathChatWS), {
|
|
133
|
-
|
|
134
|
-
|
|
127
|
+
query: queryParams({
|
|
128
|
+
owner_id: opts.owner_id,
|
|
129
|
+
chat_room_id: opts.chat_room_id,
|
|
130
|
+
}),
|
|
135
131
|
}),
|
|
136
132
|
token,
|
|
137
133
|
on_message: opts.on_message,
|
|
@@ -144,7 +140,7 @@ export class ChatClient {
|
|
|
144
140
|
return openWS({
|
|
145
141
|
base_url: this.base_url,
|
|
146
142
|
path: withQuery(chatRoomPath(PathChatWS), {
|
|
147
|
-
|
|
143
|
+
query: queryParam("id", opts.id),
|
|
148
144
|
}),
|
|
149
145
|
token,
|
|
150
146
|
on_message: opts.on_message,
|
|
@@ -157,7 +153,7 @@ export class ChatClient {
|
|
|
157
153
|
return openWS({
|
|
158
154
|
base_url: this.base_url,
|
|
159
155
|
path: withQuery(chatRoomPath(PathChatWSMine), {
|
|
160
|
-
|
|
156
|
+
query: queryParam("owner_id", opts.owner_id),
|
|
161
157
|
}),
|
|
162
158
|
token,
|
|
163
159
|
on_message: opts.on_message,
|
|
@@ -183,52 +179,3 @@ function chatRoomPath(action) {
|
|
|
183
179
|
action,
|
|
184
180
|
});
|
|
185
181
|
}
|
|
186
|
-
function openWS(opts) {
|
|
187
|
-
const socket = new WebSocket(wsURL(opts.base_url, opts.path), [
|
|
188
|
-
protocolFirebase,
|
|
189
|
-
opts.token,
|
|
190
|
-
]);
|
|
191
|
-
socket.addEventListener("message", (ev) => {
|
|
192
|
-
if (typeof ev.data !== "string") {
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
opts.on_message(JSON.parse(ev.data), ev);
|
|
196
|
-
});
|
|
197
|
-
if (opts.on_error !== undefined) {
|
|
198
|
-
socket.addEventListener("error", opts.on_error);
|
|
199
|
-
}
|
|
200
|
-
if (opts.on_close !== undefined) {
|
|
201
|
-
socket.addEventListener("close", opts.on_close);
|
|
202
|
-
}
|
|
203
|
-
return {
|
|
204
|
-
socket,
|
|
205
|
-
close(code, reason) {
|
|
206
|
-
socket.close(code, reason);
|
|
207
|
-
},
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
function wsURL(base, path) {
|
|
211
|
-
const u = new URL(path.replace(/^\/+/g, ""), ensureSlash(base));
|
|
212
|
-
if (u.protocol === schemeHTTPS) {
|
|
213
|
-
u.protocol = schemeWSS;
|
|
214
|
-
return u.toString();
|
|
215
|
-
}
|
|
216
|
-
if (u.protocol === schemeHTTP) {
|
|
217
|
-
u.protocol = schemeWS;
|
|
218
|
-
return u.toString();
|
|
219
|
-
}
|
|
220
|
-
return u.toString();
|
|
221
|
-
}
|
|
222
|
-
function ensureSlash(x) {
|
|
223
|
-
return x.endsWith("/") ? x : `${x}/`;
|
|
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;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type WSMessageHandler<T> = (v: T, ev: MessageEvent<string>) => void;
|
|
2
|
+
export type WSErrorHandler = (ev: Event) => void;
|
|
3
|
+
export type WSCloseHandler = (ev: CloseEvent) => void;
|
|
4
|
+
export type WSConnection = {
|
|
5
|
+
socket: WebSocket;
|
|
6
|
+
close(code?: number, reason?: string): void;
|
|
7
|
+
};
|
|
8
|
+
export type OpenWSOptions<T> = {
|
|
9
|
+
base_url: string;
|
|
10
|
+
path: string;
|
|
11
|
+
token: string;
|
|
12
|
+
on_message: WSMessageHandler<T>;
|
|
13
|
+
on_error?: WSErrorHandler;
|
|
14
|
+
on_close?: WSCloseHandler;
|
|
15
|
+
};
|
|
16
|
+
export declare function openWS<T>(opts: OpenWSOptions<T>): WSConnection;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// Copyright (C) Fabriktor, Inc. 2025-present.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
4
|
+
// not use this file except in compliance with the License. You may obtain
|
|
5
|
+
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
import { HTTPScheme, HTTPSScheme } from "@fabriktor/schema";
|
|
7
|
+
const protocolFirebase = "firebase";
|
|
8
|
+
const schemeWS = "ws:";
|
|
9
|
+
const schemeWSS = "wss:";
|
|
10
|
+
export function openWS(opts) {
|
|
11
|
+
const socket = new WebSocket(wsURL(opts.base_url, opts.path), [
|
|
12
|
+
protocolFirebase,
|
|
13
|
+
opts.token,
|
|
14
|
+
]);
|
|
15
|
+
socket.addEventListener("message", (ev) => {
|
|
16
|
+
if (typeof ev.data !== "string") {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
opts.on_message(JSON.parse(ev.data), ev);
|
|
20
|
+
});
|
|
21
|
+
if (opts.on_error !== undefined) {
|
|
22
|
+
socket.addEventListener("error", opts.on_error);
|
|
23
|
+
}
|
|
24
|
+
if (opts.on_close !== undefined) {
|
|
25
|
+
socket.addEventListener("close", opts.on_close);
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
socket,
|
|
29
|
+
close(code, reason) {
|
|
30
|
+
socket.close(code, reason);
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function wsURL(base, path) {
|
|
35
|
+
const u = new URL(path.replace(/^\/+/g, ""), ensureSlash(base));
|
|
36
|
+
if (u.protocol === protocolOf(HTTPSScheme)) {
|
|
37
|
+
u.protocol = schemeWSS;
|
|
38
|
+
return u.toString();
|
|
39
|
+
}
|
|
40
|
+
if (u.protocol === protocolOf(HTTPScheme)) {
|
|
41
|
+
u.protocol = schemeWS;
|
|
42
|
+
return u.toString();
|
|
43
|
+
}
|
|
44
|
+
return u.toString();
|
|
45
|
+
}
|
|
46
|
+
function protocolOf(scheme) {
|
|
47
|
+
return `${scheme}:`;
|
|
48
|
+
}
|
|
49
|
+
function ensureSlash(x) {
|
|
50
|
+
return x.endsWith("/") ? x : `${x}/`;
|
|
51
|
+
}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export * from "./core/http.js";
|
|
|
11
11
|
export * from "./core/idempotency.js";
|
|
12
12
|
export * from "./core/multipart.js";
|
|
13
13
|
export * from "./core/path.js";
|
|
14
|
+
export * from "./core/ws.js";
|
|
14
15
|
export * from "./feed/feed.js";
|
|
15
16
|
export * from "./fulfillments/fulfillments.js";
|
|
16
17
|
export * from "./jobs/jobs.js";
|
package/dist/src/index.js
CHANGED
|
@@ -11,6 +11,7 @@ export * from "./core/http.js";
|
|
|
11
11
|
export * from "./core/idempotency.js";
|
|
12
12
|
export * from "./core/multipart.js";
|
|
13
13
|
export * from "./core/path.js";
|
|
14
|
+
export * from "./core/ws.js";
|
|
14
15
|
export * from "./feed/feed.js";
|
|
15
16
|
export * from "./fulfillments/fulfillments.js";
|
|
16
17
|
export * from "./jobs/jobs.js";
|
|
@@ -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
|
});
|