@fabriktor/client 0.0.28 → 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/billable/billable.d.ts +213 -0
- package/dist/src/billable/billable.js +441 -0
- package/dist/src/calls/calls.d.ts +34 -0
- package/dist/src/calls/calls.js +65 -0
- package/dist/src/chat/chat.d.ts +97 -0
- package/dist/src/chat/chat.js +224 -0
- package/dist/src/contacts/contacts.d.ts +37 -0
- package/dist/src/contacts/contacts.js +94 -0
- package/dist/src/core/col.d.ts +7 -1
- package/dist/src/core/col.js +29 -14
- package/dist/src/core/crud.d.ts +1 -1
- package/dist/src/core/crud.js +1 -1
- package/dist/src/core/http.d.ts +3 -4
- package/dist/src/core/http.js +3 -3
- package/dist/src/core/idempotency.js +1 -1
- package/dist/src/core/multipart.d.ts +25 -0
- package/dist/src/core/multipart.js +93 -0
- package/dist/src/feed/feed.d.ts +65 -0
- package/dist/src/feed/feed.js +130 -0
- package/dist/src/fulfillments/fulfillments.d.ts +36 -0
- package/dist/src/fulfillments/fulfillments.js +68 -0
- package/dist/src/index.d.ts +14 -0
- package/dist/src/index.js +14 -0
- package/dist/src/jobs/jobs.d.ts +69 -0
- package/dist/src/jobs/jobs.js +143 -0
- package/dist/src/marketplace/marketplace.d.ts +49 -0
- package/dist/src/marketplace/marketplace.js +94 -0
- package/dist/src/payments/payments.d.ts +154 -0
- package/dist/src/payments/payments.js +328 -0
- package/dist/src/payrolls/payrolls.d.ts +179 -0
- package/dist/src/payrolls/payrolls.js +380 -0
- package/dist/src/processes/processes.d.ts +3 -3
- package/dist/src/routes/routes.d.ts +93 -0
- package/dist/src/routes/routes.js +185 -0
- package/dist/src/storage/storage.d.ts +124 -0
- package/dist/src/storage/storage.js +242 -0
- package/dist/src/timesheets/timesheets.d.ts +49 -0
- package/dist/src/timesheets/timesheets.js +105 -0
- package/dist/src/users/tmp_phones.d.ts +1 -1
- package/dist/src/users/tmp_usernames.d.ts +5 -4
- package/dist/src/users/users.d.ts +13 -12
- package/dist/src/users/users.js +4 -1
- package/package.json +3 -2
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type Event, type InEvent, type OperationResult, type PLCallsMintVideoToken } from "@fabriktor/schema";
|
|
2
|
+
import type { TokenProvider } from "../core/auth.js";
|
|
3
|
+
import type { DeleteManyOptionsCRUD, DeleteOneOptionsCRUD, FindOneOptionsCRUD, InsertOneOptionsCRUD, OperationResultOf, QueryOptionsCRUD, ReplaceOneOptionsCRUD } from "../core/crud.js";
|
|
4
|
+
import type { HTTPDoer } from "../core/http.js";
|
|
5
|
+
export type MintVideoTokenOptions = PLCallsMintVideoToken;
|
|
6
|
+
export type CallsClientOptions = {
|
|
7
|
+
http: HTTPDoer;
|
|
8
|
+
base_url: string;
|
|
9
|
+
get_token?: TokenProvider;
|
|
10
|
+
};
|
|
11
|
+
export interface CallsOperator {
|
|
12
|
+
queryEvents(opts?: QueryOptionsCRUD): Promise<OperationResultOf<Event[]>>;
|
|
13
|
+
insertOneEvent(opts: InsertOneOptionsCRUD<InEvent>): Promise<OperationResult>;
|
|
14
|
+
findOneEvent(opts: FindOneOptionsCRUD): Promise<OperationResultOf<Event>>;
|
|
15
|
+
replaceOneEvent(opts: ReplaceOneOptionsCRUD<InEvent>): Promise<OperationResult>;
|
|
16
|
+
deleteOneEvent(opts: DeleteOneOptionsCRUD): Promise<OperationResult>;
|
|
17
|
+
deleteManyEvents(opts?: DeleteManyOptionsCRUD): Promise<OperationResultOf<number>>;
|
|
18
|
+
mintVideoToken(opts: MintVideoTokenOptions): Promise<OperationResultOf<string>>;
|
|
19
|
+
}
|
|
20
|
+
export declare class CallsClient implements CallsOperator {
|
|
21
|
+
private events;
|
|
22
|
+
private http;
|
|
23
|
+
private base_url;
|
|
24
|
+
private get_token?;
|
|
25
|
+
constructor(opts: CallsClientOptions);
|
|
26
|
+
queryEvents(opts?: QueryOptionsCRUD): Promise<OperationResultOf<Event[]>>;
|
|
27
|
+
insertOneEvent(opts: InsertOneOptionsCRUD<InEvent>): Promise<OperationResult>;
|
|
28
|
+
findOneEvent(opts: FindOneOptionsCRUD): Promise<OperationResultOf<Event>>;
|
|
29
|
+
replaceOneEvent(opts: ReplaceOneOptionsCRUD<InEvent>): Promise<OperationResult>;
|
|
30
|
+
deleteOneEvent(opts: DeleteOneOptionsCRUD): Promise<OperationResult>;
|
|
31
|
+
deleteManyEvents(opts?: DeleteManyOptionsCRUD): Promise<OperationResultOf<number>>;
|
|
32
|
+
mintVideoToken(opts: MintVideoTokenOptions): Promise<OperationResultOf<string>>;
|
|
33
|
+
}
|
|
34
|
+
export declare function newCallsClient(opts: CallsClientOptions): CallsClient;
|
|
@@ -0,0 +1,65 @@
|
|
|
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 { ColCallsEvents, HTTPMethodPost, PathCallsMint, PathCallsVidTokens, SvcCalls, } from "@fabriktor/schema";
|
|
7
|
+
import { requiredToken } from "../core/auth.js";
|
|
8
|
+
import { newCRUDClient } from "../core/crud.js";
|
|
9
|
+
import { buildPath } from "../core/path.js";
|
|
10
|
+
export class CallsClient {
|
|
11
|
+
events;
|
|
12
|
+
http;
|
|
13
|
+
base_url;
|
|
14
|
+
get_token;
|
|
15
|
+
constructor(opts) {
|
|
16
|
+
this.events = newCRUDClient({
|
|
17
|
+
http: opts.http,
|
|
18
|
+
base_url: opts.base_url,
|
|
19
|
+
svc: SvcCalls,
|
|
20
|
+
col: ColCallsEvents,
|
|
21
|
+
get_token: opts.get_token,
|
|
22
|
+
});
|
|
23
|
+
this.http = opts.http;
|
|
24
|
+
this.base_url = opts.base_url;
|
|
25
|
+
this.get_token = opts.get_token;
|
|
26
|
+
}
|
|
27
|
+
async queryEvents(opts) {
|
|
28
|
+
return await this.events.query(opts);
|
|
29
|
+
}
|
|
30
|
+
async insertOneEvent(opts) {
|
|
31
|
+
return await this.events.insertOne(opts);
|
|
32
|
+
}
|
|
33
|
+
async findOneEvent(opts) {
|
|
34
|
+
return await this.events.findOne(opts);
|
|
35
|
+
}
|
|
36
|
+
async replaceOneEvent(opts) {
|
|
37
|
+
return await this.events.replaceOne(opts);
|
|
38
|
+
}
|
|
39
|
+
async deleteOneEvent(opts) {
|
|
40
|
+
return await this.events.deleteOne(opts);
|
|
41
|
+
}
|
|
42
|
+
async deleteManyEvents(opts) {
|
|
43
|
+
return await this.events.deleteMany(opts);
|
|
44
|
+
}
|
|
45
|
+
async mintVideoToken(opts) {
|
|
46
|
+
const token = await requiredToken(this.get_token);
|
|
47
|
+
return await this.http.do({
|
|
48
|
+
base_url: this.base_url,
|
|
49
|
+
path: vidTokenPath(PathCallsMint),
|
|
50
|
+
method: HTTPMethodPost,
|
|
51
|
+
token,
|
|
52
|
+
body: opts,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export function newCallsClient(opts) {
|
|
57
|
+
return new CallsClient(opts);
|
|
58
|
+
}
|
|
59
|
+
function vidTokenPath(action) {
|
|
60
|
+
return buildPath({
|
|
61
|
+
svc: SvcCalls,
|
|
62
|
+
col: PathCallsVidTokens,
|
|
63
|
+
action,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { type Chat, type ChatRoom, type ChatRoomMember, type ID, type InChat, type InChatRoom, type InChatRoomMember, type OperationResult, type PLChatEnsure, type PLChatReact } from "@fabriktor/schema";
|
|
2
|
+
import type { TokenProvider } from "../core/auth.js";
|
|
3
|
+
import type { DeleteManyOptionsCRUD, DeleteOneOptionsCRUD, FindOneOptionsCRUD, InsertOneOptionsCRUD, OperationResultOf, QueryOptionsCRUD, ReplaceOneOptionsCRUD, SearchManyOptionsCRUD, SearchResultOf } from "../core/crud.js";
|
|
4
|
+
import type { HTTPDoer } from "../core/http.js";
|
|
5
|
+
export type ReactChatOptions = PLChatReact;
|
|
6
|
+
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
|
+
export type WSChatsOptions = {
|
|
15
|
+
owner_id: string;
|
|
16
|
+
chat_room_id: string;
|
|
17
|
+
on_message: WSMessageHandler<Chat>;
|
|
18
|
+
on_error?: WSErrorHandler;
|
|
19
|
+
on_close?: WSCloseHandler;
|
|
20
|
+
};
|
|
21
|
+
export type WSChatRoomsOptions = {
|
|
22
|
+
id: string;
|
|
23
|
+
on_message: WSMessageHandler<ChatRoom>;
|
|
24
|
+
on_error?: WSErrorHandler;
|
|
25
|
+
on_close?: WSCloseHandler;
|
|
26
|
+
};
|
|
27
|
+
export type WSChatRoomOptions = {
|
|
28
|
+
owner_id: string;
|
|
29
|
+
on_message: WSMessageHandler<ChatRoom>;
|
|
30
|
+
on_error?: WSErrorHandler;
|
|
31
|
+
on_close?: WSCloseHandler;
|
|
32
|
+
};
|
|
33
|
+
export type ChatClientOptions = {
|
|
34
|
+
http: HTTPDoer;
|
|
35
|
+
base_url: string;
|
|
36
|
+
get_token?: TokenProvider;
|
|
37
|
+
};
|
|
38
|
+
export interface ChatOperator {
|
|
39
|
+
queryChats(opts?: QueryOptionsCRUD): Promise<OperationResultOf<Chat[]>>;
|
|
40
|
+
queryChatRooms(opts?: QueryOptionsCRUD): Promise<OperationResultOf<ChatRoom[]>>;
|
|
41
|
+
queryChatRoomMembers(opts?: QueryOptionsCRUD): Promise<OperationResultOf<ChatRoomMember[]>>;
|
|
42
|
+
insertOneChat(opts: InsertOneOptionsCRUD<InChat>): Promise<OperationResult>;
|
|
43
|
+
findOneChat(opts: FindOneOptionsCRUD): Promise<OperationResultOf<Chat>>;
|
|
44
|
+
findOneChatRoom(opts: FindOneOptionsCRUD): Promise<OperationResultOf<ChatRoom>>;
|
|
45
|
+
findOneChatRoomMember(opts: FindOneOptionsCRUD): Promise<OperationResultOf<ChatRoomMember>>;
|
|
46
|
+
replaceOneChat(opts: ReplaceOneOptionsCRUD<InChat>): Promise<OperationResult>;
|
|
47
|
+
replaceOneChatRoom(opts: ReplaceOneOptionsCRUD<InChatRoom>): Promise<OperationResult>;
|
|
48
|
+
replaceOneChatRoomMember(opts: ReplaceOneOptionsCRUD<InChatRoomMember>): Promise<OperationResult>;
|
|
49
|
+
deleteOneChat(opts: DeleteOneOptionsCRUD): Promise<OperationResult>;
|
|
50
|
+
deleteOneChatRoom(opts: DeleteOneOptionsCRUD): Promise<OperationResult>;
|
|
51
|
+
deleteOneChatRoomMember(opts: DeleteOneOptionsCRUD): Promise<OperationResult>;
|
|
52
|
+
deleteManyChats(opts?: DeleteManyOptionsCRUD): Promise<OperationResultOf<number>>;
|
|
53
|
+
deleteManyChatRooms(opts?: DeleteManyOptionsCRUD): Promise<OperationResultOf<number>>;
|
|
54
|
+
deleteManyChatRoomMembers(opts?: DeleteManyOptionsCRUD): Promise<OperationResultOf<number>>;
|
|
55
|
+
searchManyChats(opts?: SearchManyOptionsCRUD): Promise<OperationResultOf<SearchResultOf<Chat>>>;
|
|
56
|
+
searchManyChatRooms(opts?: SearchManyOptionsCRUD): Promise<OperationResultOf<SearchResultOf<ChatRoom>>>;
|
|
57
|
+
searchManyChatRoomMembers(opts?: SearchManyOptionsCRUD): Promise<OperationResultOf<SearchResultOf<ChatRoomMember>>>;
|
|
58
|
+
reactChat(opts: ReactChatOptions): Promise<void>;
|
|
59
|
+
ensureChatRoom(opts: EnsureChatRoomOptions): Promise<ID>;
|
|
60
|
+
wsChats(opts: WSChatsOptions): Promise<WSConnection<Chat>>;
|
|
61
|
+
wsChatRooms(opts: WSChatRoomsOptions): Promise<WSConnection<ChatRoom>>;
|
|
62
|
+
wsChatRoom(opts: WSChatRoomOptions): Promise<WSConnection<ChatRoom>>;
|
|
63
|
+
}
|
|
64
|
+
export declare class ChatClient implements ChatOperator {
|
|
65
|
+
private chats;
|
|
66
|
+
private chat_rooms;
|
|
67
|
+
private chat_room_members;
|
|
68
|
+
private http;
|
|
69
|
+
private base_url;
|
|
70
|
+
private get_token?;
|
|
71
|
+
constructor(opts: ChatClientOptions);
|
|
72
|
+
queryChats(opts?: QueryOptionsCRUD): Promise<OperationResultOf<Chat[]>>;
|
|
73
|
+
queryChatRooms(opts?: QueryOptionsCRUD): Promise<OperationResultOf<ChatRoom[]>>;
|
|
74
|
+
queryChatRoomMembers(opts?: QueryOptionsCRUD): Promise<OperationResultOf<ChatRoomMember[]>>;
|
|
75
|
+
insertOneChat(opts: InsertOneOptionsCRUD<InChat>): Promise<OperationResult>;
|
|
76
|
+
findOneChat(opts: FindOneOptionsCRUD): Promise<OperationResultOf<Chat>>;
|
|
77
|
+
findOneChatRoom(opts: FindOneOptionsCRUD): Promise<OperationResultOf<ChatRoom>>;
|
|
78
|
+
findOneChatRoomMember(opts: FindOneOptionsCRUD): Promise<OperationResultOf<ChatRoomMember>>;
|
|
79
|
+
replaceOneChat(opts: ReplaceOneOptionsCRUD<InChat>): Promise<OperationResult>;
|
|
80
|
+
replaceOneChatRoom(opts: ReplaceOneOptionsCRUD<InChatRoom>): Promise<OperationResult>;
|
|
81
|
+
replaceOneChatRoomMember(opts: ReplaceOneOptionsCRUD<InChatRoomMember>): Promise<OperationResult>;
|
|
82
|
+
deleteOneChat(opts: DeleteOneOptionsCRUD): Promise<OperationResult>;
|
|
83
|
+
deleteOneChatRoom(opts: DeleteOneOptionsCRUD): Promise<OperationResult>;
|
|
84
|
+
deleteOneChatRoomMember(opts: DeleteOneOptionsCRUD): Promise<OperationResult>;
|
|
85
|
+
deleteManyChats(opts?: DeleteManyOptionsCRUD): Promise<OperationResultOf<number>>;
|
|
86
|
+
deleteManyChatRooms(opts?: DeleteManyOptionsCRUD): Promise<OperationResultOf<number>>;
|
|
87
|
+
deleteManyChatRoomMembers(opts?: DeleteManyOptionsCRUD): Promise<OperationResultOf<number>>;
|
|
88
|
+
searchManyChats(opts?: SearchManyOptionsCRUD): Promise<OperationResultOf<SearchResultOf<Chat>>>;
|
|
89
|
+
searchManyChatRooms(opts?: SearchManyOptionsCRUD): Promise<OperationResultOf<SearchResultOf<ChatRoom>>>;
|
|
90
|
+
searchManyChatRoomMembers(opts?: SearchManyOptionsCRUD): Promise<OperationResultOf<SearchResultOf<ChatRoomMember>>>;
|
|
91
|
+
reactChat(opts: ReactChatOptions): Promise<void>;
|
|
92
|
+
ensureChatRoom(opts: EnsureChatRoomOptions): Promise<ID>;
|
|
93
|
+
wsChats(opts: WSChatsOptions): Promise<WSConnection<Chat>>;
|
|
94
|
+
wsChatRooms(opts: WSChatRoomsOptions): Promise<WSConnection<ChatRoom>>;
|
|
95
|
+
wsChatRoom(opts: WSChatRoomOptions): Promise<WSConnection<ChatRoom>>;
|
|
96
|
+
}
|
|
97
|
+
export declare function newChatClient(opts: ChatClientOptions): ChatClient;
|
|
@@ -0,0 +1,224 @@
|
|
|
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 { ColChatChatRoomMembers, ColChatChatRooms, ColChatChats, HTTPMethodPost, PathChatEnsure, PathChatReact, PathChatWS, PathChatWSMine, SvcChat, } from "@fabriktor/schema";
|
|
7
|
+
import { requiredToken } from "../core/auth.js";
|
|
8
|
+
import { queryParam, queryParams, withQuery } from "../core/col.js";
|
|
9
|
+
import { newCRUDClient } from "../core/crud.js";
|
|
10
|
+
import { buildPath } from "../core/path.js";
|
|
11
|
+
const protocolFirebase = "firebase";
|
|
12
|
+
const schemeHTTP = "http:";
|
|
13
|
+
const schemeHTTPS = "https:";
|
|
14
|
+
const schemeWS = "ws:";
|
|
15
|
+
const schemeWSS = "wss:";
|
|
16
|
+
export class ChatClient {
|
|
17
|
+
chats;
|
|
18
|
+
chat_rooms;
|
|
19
|
+
chat_room_members;
|
|
20
|
+
http;
|
|
21
|
+
base_url;
|
|
22
|
+
get_token;
|
|
23
|
+
constructor(opts) {
|
|
24
|
+
this.chats = newCRUDClient({
|
|
25
|
+
http: opts.http,
|
|
26
|
+
base_url: opts.base_url,
|
|
27
|
+
svc: SvcChat,
|
|
28
|
+
col: ColChatChats,
|
|
29
|
+
get_token: opts.get_token,
|
|
30
|
+
});
|
|
31
|
+
this.chat_rooms = newCRUDClient({
|
|
32
|
+
http: opts.http,
|
|
33
|
+
base_url: opts.base_url,
|
|
34
|
+
svc: SvcChat,
|
|
35
|
+
col: ColChatChatRooms,
|
|
36
|
+
get_token: opts.get_token,
|
|
37
|
+
});
|
|
38
|
+
this.chat_room_members = newCRUDClient({
|
|
39
|
+
http: opts.http,
|
|
40
|
+
base_url: opts.base_url,
|
|
41
|
+
svc: SvcChat,
|
|
42
|
+
col: ColChatChatRoomMembers,
|
|
43
|
+
get_token: opts.get_token,
|
|
44
|
+
});
|
|
45
|
+
this.http = opts.http;
|
|
46
|
+
this.base_url = opts.base_url;
|
|
47
|
+
this.get_token = opts.get_token;
|
|
48
|
+
}
|
|
49
|
+
async queryChats(opts) {
|
|
50
|
+
return await this.chats.query(opts);
|
|
51
|
+
}
|
|
52
|
+
async queryChatRooms(opts) {
|
|
53
|
+
return await this.chat_rooms.query(opts);
|
|
54
|
+
}
|
|
55
|
+
async queryChatRoomMembers(opts) {
|
|
56
|
+
return await this.chat_room_members.query(opts);
|
|
57
|
+
}
|
|
58
|
+
async insertOneChat(opts) {
|
|
59
|
+
return await this.chats.insertOne(opts);
|
|
60
|
+
}
|
|
61
|
+
async findOneChat(opts) {
|
|
62
|
+
return await this.chats.findOne(opts);
|
|
63
|
+
}
|
|
64
|
+
async findOneChatRoom(opts) {
|
|
65
|
+
return await this.chat_rooms.findOne(opts);
|
|
66
|
+
}
|
|
67
|
+
async findOneChatRoomMember(opts) {
|
|
68
|
+
return await this.chat_room_members.findOne(opts);
|
|
69
|
+
}
|
|
70
|
+
async replaceOneChat(opts) {
|
|
71
|
+
return await this.chats.replaceOne(opts);
|
|
72
|
+
}
|
|
73
|
+
async replaceOneChatRoom(opts) {
|
|
74
|
+
return await this.chat_rooms.replaceOne(opts);
|
|
75
|
+
}
|
|
76
|
+
async replaceOneChatRoomMember(opts) {
|
|
77
|
+
return await this.chat_room_members.replaceOne(opts);
|
|
78
|
+
}
|
|
79
|
+
async deleteOneChat(opts) {
|
|
80
|
+
return await this.chats.deleteOne(opts);
|
|
81
|
+
}
|
|
82
|
+
async deleteOneChatRoom(opts) {
|
|
83
|
+
return await this.chat_rooms.deleteOne(opts);
|
|
84
|
+
}
|
|
85
|
+
async deleteOneChatRoomMember(opts) {
|
|
86
|
+
return await this.chat_room_members.deleteOne(opts);
|
|
87
|
+
}
|
|
88
|
+
async deleteManyChats(opts) {
|
|
89
|
+
return await this.chats.deleteMany(opts);
|
|
90
|
+
}
|
|
91
|
+
async deleteManyChatRooms(opts) {
|
|
92
|
+
return await this.chat_rooms.deleteMany(opts);
|
|
93
|
+
}
|
|
94
|
+
async deleteManyChatRoomMembers(opts) {
|
|
95
|
+
return await this.chat_room_members.deleteMany(opts);
|
|
96
|
+
}
|
|
97
|
+
async searchManyChats(opts) {
|
|
98
|
+
return await this.chats.searchMany(opts);
|
|
99
|
+
}
|
|
100
|
+
async searchManyChatRooms(opts) {
|
|
101
|
+
return await this.chat_rooms.searchMany(opts);
|
|
102
|
+
}
|
|
103
|
+
async searchManyChatRoomMembers(opts) {
|
|
104
|
+
return await this.chat_room_members.searchMany(opts);
|
|
105
|
+
}
|
|
106
|
+
async reactChat(opts) {
|
|
107
|
+
const token = await requiredToken(this.get_token);
|
|
108
|
+
return await this.http.do({
|
|
109
|
+
base_url: this.base_url,
|
|
110
|
+
path: chatPath(PathChatReact),
|
|
111
|
+
method: HTTPMethodPost,
|
|
112
|
+
token,
|
|
113
|
+
body: opts,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
async ensureChatRoom(opts) {
|
|
117
|
+
const token = await requiredToken(this.get_token);
|
|
118
|
+
return await this.http.do({
|
|
119
|
+
base_url: this.base_url,
|
|
120
|
+
path: chatRoomPath(PathChatEnsure),
|
|
121
|
+
method: HTTPMethodPost,
|
|
122
|
+
token,
|
|
123
|
+
body: opts,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
async wsChats(opts) {
|
|
127
|
+
const token = await requiredToken(this.get_token);
|
|
128
|
+
return openWS({
|
|
129
|
+
base_url: this.base_url,
|
|
130
|
+
path: withQuery(chatPath(PathChatWS), {
|
|
131
|
+
query: queryParams({
|
|
132
|
+
owner_id: opts.owner_id,
|
|
133
|
+
chat_room_id: opts.chat_room_id,
|
|
134
|
+
}),
|
|
135
|
+
}),
|
|
136
|
+
token,
|
|
137
|
+
on_message: opts.on_message,
|
|
138
|
+
on_error: opts.on_error,
|
|
139
|
+
on_close: opts.on_close,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
async wsChatRooms(opts) {
|
|
143
|
+
const token = await requiredToken(this.get_token);
|
|
144
|
+
return openWS({
|
|
145
|
+
base_url: this.base_url,
|
|
146
|
+
path: withQuery(chatRoomPath(PathChatWS), {
|
|
147
|
+
query: queryParam("id", opts.id),
|
|
148
|
+
}),
|
|
149
|
+
token,
|
|
150
|
+
on_message: opts.on_message,
|
|
151
|
+
on_error: opts.on_error,
|
|
152
|
+
on_close: opts.on_close,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
async wsChatRoom(opts) {
|
|
156
|
+
const token = await requiredToken(this.get_token);
|
|
157
|
+
return openWS({
|
|
158
|
+
base_url: this.base_url,
|
|
159
|
+
path: withQuery(chatRoomPath(PathChatWSMine), {
|
|
160
|
+
query: queryParam("owner_id", opts.owner_id),
|
|
161
|
+
}),
|
|
162
|
+
token,
|
|
163
|
+
on_message: opts.on_message,
|
|
164
|
+
on_error: opts.on_error,
|
|
165
|
+
on_close: opts.on_close,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
export function newChatClient(opts) {
|
|
170
|
+
return new ChatClient(opts);
|
|
171
|
+
}
|
|
172
|
+
function chatPath(action) {
|
|
173
|
+
return buildPath({
|
|
174
|
+
svc: SvcChat,
|
|
175
|
+
col: ColChatChats,
|
|
176
|
+
action,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
function chatRoomPath(action) {
|
|
180
|
+
return buildPath({
|
|
181
|
+
svc: SvcChat,
|
|
182
|
+
col: ColChatChatRooms,
|
|
183
|
+
action,
|
|
184
|
+
});
|
|
185
|
+
}
|
|
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
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type Contact, type ID, type InContact, type OperationResult, type PLContactsGenerateQR, type Signal } from "@fabriktor/schema";
|
|
2
|
+
import type { TokenProvider } from "../core/auth.js";
|
|
3
|
+
import type { DeleteOneOptionsCRUD, FindOneOptionsCRUD, InsertOneOptionsCRUD, OperationResultOf, ReplaceOneOptionsCRUD } from "../core/crud.js";
|
|
4
|
+
import type { HTTPDoer } from "../core/http.js";
|
|
5
|
+
export type GenerateQROptions = PLContactsGenerateQR;
|
|
6
|
+
export type SignalOptions = Signal;
|
|
7
|
+
export type ContactsClientOptions = {
|
|
8
|
+
http: HTTPDoer;
|
|
9
|
+
base_url: string;
|
|
10
|
+
get_token?: TokenProvider;
|
|
11
|
+
};
|
|
12
|
+
export interface ContactsOperator {
|
|
13
|
+
insertOneContact(opts: InsertOneOptionsCRUD<InContact>): Promise<OperationResult>;
|
|
14
|
+
findOneContact(opts: FindOneOptionsCRUD): Promise<OperationResultOf<Contact>>;
|
|
15
|
+
replaceOneContact(opts: ReplaceOneOptionsCRUD<InContact>): Promise<OperationResult>;
|
|
16
|
+
deleteOneContact(opts: DeleteOneOptionsCRUD): Promise<OperationResult>;
|
|
17
|
+
signal(opts: SignalOptions): Promise<OperationResultOf<ID[]>>;
|
|
18
|
+
suggest(): Promise<OperationResultOf<ID[]>>;
|
|
19
|
+
generateQR(opts: GenerateQROptions): Promise<void>;
|
|
20
|
+
findContacts(): Promise<OperationResultOf<Contact[]>>;
|
|
21
|
+
}
|
|
22
|
+
export declare class ContactsClient implements ContactsOperator {
|
|
23
|
+
private contacts;
|
|
24
|
+
private http;
|
|
25
|
+
private base_url;
|
|
26
|
+
private get_token?;
|
|
27
|
+
constructor(opts: ContactsClientOptions);
|
|
28
|
+
insertOneContact(opts: InsertOneOptionsCRUD<InContact>): Promise<OperationResult>;
|
|
29
|
+
findOneContact(opts: FindOneOptionsCRUD): Promise<OperationResultOf<Contact>>;
|
|
30
|
+
replaceOneContact(opts: ReplaceOneOptionsCRUD<InContact>): Promise<OperationResult>;
|
|
31
|
+
deleteOneContact(opts: DeleteOneOptionsCRUD): Promise<OperationResult>;
|
|
32
|
+
signal(opts: SignalOptions): Promise<OperationResultOf<ID[]>>;
|
|
33
|
+
suggest(): Promise<OperationResultOf<ID[]>>;
|
|
34
|
+
generateQR(opts: GenerateQROptions): Promise<void>;
|
|
35
|
+
findContacts(): Promise<OperationResultOf<Contact[]>>;
|
|
36
|
+
}
|
|
37
|
+
export declare function newContactsClient(opts: ContactsClientOptions): ContactsClient;
|
|
@@ -0,0 +1,94 @@
|
|
|
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 { ColContactsContacts, ColContactsSignals, HTTPMethodGet, HTTPMethodPost, PathContactsFind, PathContactsQR, PathContactsSignal, PathContactsSuggest, SvcContacts, } from "@fabriktor/schema";
|
|
7
|
+
import { requiredToken } from "../core/auth.js";
|
|
8
|
+
import { newCRUDClient } from "../core/crud.js";
|
|
9
|
+
import { buildPath } from "../core/path.js";
|
|
10
|
+
export class ContactsClient {
|
|
11
|
+
contacts;
|
|
12
|
+
http;
|
|
13
|
+
base_url;
|
|
14
|
+
get_token;
|
|
15
|
+
constructor(opts) {
|
|
16
|
+
this.contacts = newCRUDClient({
|
|
17
|
+
http: opts.http,
|
|
18
|
+
base_url: opts.base_url,
|
|
19
|
+
svc: SvcContacts,
|
|
20
|
+
col: ColContactsContacts,
|
|
21
|
+
get_token: opts.get_token,
|
|
22
|
+
});
|
|
23
|
+
this.http = opts.http;
|
|
24
|
+
this.base_url = opts.base_url;
|
|
25
|
+
this.get_token = opts.get_token;
|
|
26
|
+
}
|
|
27
|
+
async insertOneContact(opts) {
|
|
28
|
+
return await this.contacts.insertOne(opts);
|
|
29
|
+
}
|
|
30
|
+
async findOneContact(opts) {
|
|
31
|
+
return await this.contacts.findOne(opts);
|
|
32
|
+
}
|
|
33
|
+
async replaceOneContact(opts) {
|
|
34
|
+
return await this.contacts.replaceOne(opts);
|
|
35
|
+
}
|
|
36
|
+
async deleteOneContact(opts) {
|
|
37
|
+
return await this.contacts.deleteOne(opts);
|
|
38
|
+
}
|
|
39
|
+
async signal(opts) {
|
|
40
|
+
const token = await requiredToken(this.get_token);
|
|
41
|
+
return await this.http.do({
|
|
42
|
+
base_url: this.base_url,
|
|
43
|
+
path: signalPath(PathContactsSignal),
|
|
44
|
+
method: HTTPMethodPost,
|
|
45
|
+
token,
|
|
46
|
+
body: opts,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
async suggest() {
|
|
50
|
+
const token = await requiredToken(this.get_token);
|
|
51
|
+
return await this.http.do({
|
|
52
|
+
base_url: this.base_url,
|
|
53
|
+
path: contactPath(PathContactsSuggest),
|
|
54
|
+
method: HTTPMethodGet,
|
|
55
|
+
token,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
async generateQR(opts) {
|
|
59
|
+
const token = await requiredToken(this.get_token);
|
|
60
|
+
return await this.http.do({
|
|
61
|
+
base_url: this.base_url,
|
|
62
|
+
path: contactPath(PathContactsQR),
|
|
63
|
+
method: HTTPMethodPost,
|
|
64
|
+
token,
|
|
65
|
+
body: opts,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
async findContacts() {
|
|
69
|
+
const token = await requiredToken(this.get_token);
|
|
70
|
+
return await this.http.do({
|
|
71
|
+
base_url: this.base_url,
|
|
72
|
+
path: contactPath(PathContactsFind),
|
|
73
|
+
method: HTTPMethodGet,
|
|
74
|
+
token,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
export function newContactsClient(opts) {
|
|
79
|
+
return new ContactsClient(opts);
|
|
80
|
+
}
|
|
81
|
+
function contactPath(action) {
|
|
82
|
+
return buildPath({
|
|
83
|
+
svc: SvcContacts,
|
|
84
|
+
col: ColContactsContacts,
|
|
85
|
+
action,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
function signalPath(action) {
|
|
89
|
+
return buildPath({
|
|
90
|
+
svc: SvcContacts,
|
|
91
|
+
col: ColContactsSignals,
|
|
92
|
+
action,
|
|
93
|
+
});
|
|
94
|
+
}
|
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/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
|
-
import type { HTTPDoer } from "./http.js";
|
|
4
3
|
import { type QueryOptions } from "./col.js";
|
|
4
|
+
import type { HTTPDoer } from "./http.js";
|
|
5
5
|
export type OperationResultOf<T> = Omit<OperationResult, typeof OperationResultValueKey> & {
|
|
6
6
|
[OperationResultValueKey]?: T;
|
|
7
7
|
};
|
package/dist/src/core/crud.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
4
4
|
// not use this file except in compliance with the License. You may obtain
|
|
5
5
|
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
import { HTTPMethodDelete, HTTPMethodGet, HTTPMethodPatch, HTTPMethodPost,
|
|
6
|
+
import { HTTPMethodDelete, HTTPMethodGet, HTTPMethodPatch, HTTPMethodPost, OperationResultValueKey, PathSearch, SearchResultResultsKey, } from "@fabriktor/schema";
|
|
7
7
|
import { requiredToken } from "./auth.js";
|
|
8
8
|
import { collectionPath, idPath, withQuery } from "./col.js";
|
|
9
9
|
import { buildPath } from "./path.js";
|
package/dist/src/core/http.d.ts
CHANGED
|
@@ -1,10 +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";
|
|
3
|
+
export declare const headerAuthorization = "authorization";
|
|
4
|
+
export declare const headerContentType = "content-type";
|
|
5
|
+
export declare const prefixBearer = "Bearer";
|
|
4
6
|
export type Method = typeof HTTPMethodGet | typeof HTTPMethodPost | typeof HTTPMethodPatch | typeof HTTPMethodDelete;
|
|
5
|
-
export type Op<T> = Omit<OperationResult, "value"> & {
|
|
6
|
-
value?: T;
|
|
7
|
-
};
|
|
8
7
|
export type HTTPOptions<T> = {
|
|
9
8
|
base_url: string;
|
|
10
9
|
path: string;
|
package/dist/src/core/http.js
CHANGED
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
import { MimeJSON, } from "@fabriktor/schema";
|
|
7
7
|
import { errFromHTTP, errHTTPRequestFailed, errHTTPResponseInvalid, } from "./err.js";
|
|
8
8
|
import { applyIdempotencyHeader, DefaultIdempotencyStore, } from "./idempotency.js";
|
|
9
|
-
const headerAuthorization = "authorization";
|
|
10
|
-
const headerContentType = "content-type";
|
|
11
|
-
const prefixBearer = "Bearer";
|
|
9
|
+
export const headerAuthorization = "authorization";
|
|
10
|
+
export const headerContentType = "content-type";
|
|
11
|
+
export const prefixBearer = "Bearer";
|
|
12
12
|
export class WebFetcher {
|
|
13
13
|
async fetch(input, init) {
|
|
14
14
|
return await fetch(input, init);
|