@fabriktor/fx 0.0.30 → 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/billable/billable.d.ts +50 -0
- package/dist/src/billable/billable.js +74 -0
- package/dist/src/calls/calls.d.ts +33 -0
- package/dist/src/calls/calls.js +43 -0
- package/dist/src/chat/chat.d.ts +89 -0
- package/dist/src/chat/chat.js +194 -0
- package/dist/src/contacts/contacts.d.ts +67 -0
- package/dist/src/contacts/contacts.js +179 -0
- package/dist/src/core/err.d.ts +38 -11
- package/dist/src/core/err.js +29 -22
- package/dist/src/fx.d.ts +30 -8
- package/dist/src/fx.js +74 -11
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.js +5 -0
- package/dist/src/preferences/preferences.d.ts +2 -8
- package/dist/src/preferences/preferences.js +3 -14
- package/dist/src/session/session.d.ts +23 -11
- package/dist/src/session/session.js +27 -6
- package/dist/src/storage/storage.d.ts +70 -0
- package/dist/src/storage/storage.js +225 -0
- package/dist/src/users/users.d.ts +6 -25
- package/dist/src/users/users.js +35 -58
- package/package.json +3 -3
|
@@ -0,0 +1,179 @@
|
|
|
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 { Friend, Na, OldHire, } from "@fabriktor/schema";
|
|
7
|
+
import { errRequired, errValidation } from "../core/err.js";
|
|
8
|
+
const presenceIntervalMS = 120_000;
|
|
9
|
+
const msgOwnerIDRequired = "Owner ID is required.";
|
|
10
|
+
const msgContactIDRequired = "Contact ID is required.";
|
|
11
|
+
const msgRelationUpgradeInvalid = "Requested relation must be higher than the current relation.";
|
|
12
|
+
const msgRelationDowngradeInvalid = "Requested relation must be lower than the current relation.";
|
|
13
|
+
const msgPendingRelationRequired = "Contact request does not contain a pending relation.";
|
|
14
|
+
export class ContactsFX {
|
|
15
|
+
contacts;
|
|
16
|
+
constructor(opts) {
|
|
17
|
+
this.contacts = opts.contacts;
|
|
18
|
+
}
|
|
19
|
+
async loadContactIndex(opts) {
|
|
20
|
+
const owner_id = opts.owner_id.trim();
|
|
21
|
+
if (owner_id === "") {
|
|
22
|
+
throw errRequired({
|
|
23
|
+
field: "owner_id",
|
|
24
|
+
msg: msgOwnerIDRequired,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
const out = await this.contacts.findContacts();
|
|
28
|
+
const contacts = out.value ?? [];
|
|
29
|
+
const peer_ids = new Set();
|
|
30
|
+
for (const contact of contacts) {
|
|
31
|
+
const peer_id = contactPeerID(contact, owner_id);
|
|
32
|
+
if (peer_id !== undefined) {
|
|
33
|
+
peer_ids.add(peer_id);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
contacts,
|
|
38
|
+
peer_ids,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
async startPresence(opts) {
|
|
42
|
+
const initial = await this.contacts.signal();
|
|
43
|
+
opts.on_active(initial.value ?? []);
|
|
44
|
+
let stopped = false;
|
|
45
|
+
let running = false;
|
|
46
|
+
const tick = async () => {
|
|
47
|
+
if (stopped || running) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
running = true;
|
|
51
|
+
try {
|
|
52
|
+
const out = await this.contacts.signal();
|
|
53
|
+
if (!stopped) {
|
|
54
|
+
opts.on_active(out.value ?? []);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
if (!stopped) {
|
|
59
|
+
opts.on_error?.(err);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
finally {
|
|
63
|
+
running = false;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
const timer = setInterval(() => {
|
|
67
|
+
void tick();
|
|
68
|
+
}, presenceIntervalMS);
|
|
69
|
+
return {
|
|
70
|
+
stop() {
|
|
71
|
+
if (stopped) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
stopped = true;
|
|
75
|
+
clearInterval(timer);
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
async sendFriendRequest(opts) {
|
|
80
|
+
const contact_id = opts.contact_id.trim();
|
|
81
|
+
if (contact_id === "") {
|
|
82
|
+
throw errRequired({
|
|
83
|
+
field: "contact_id",
|
|
84
|
+
msg: msgContactIDRequired,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
return await this.contacts.insertOneContact({
|
|
88
|
+
in: {
|
|
89
|
+
contact_id,
|
|
90
|
+
is_pending: true,
|
|
91
|
+
relation: Na,
|
|
92
|
+
requested_relation: Friend,
|
|
93
|
+
is_archived: false,
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
async requestRelationUpgrade(opts) {
|
|
98
|
+
if (opts.requested_relation <= opts.contact.relation) {
|
|
99
|
+
throw errValidation({
|
|
100
|
+
field: "requested_relation",
|
|
101
|
+
msg: msgRelationUpgradeInvalid,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
return await this.replaceContact(opts.contact, {
|
|
105
|
+
is_pending: true,
|
|
106
|
+
relation: opts.contact.relation,
|
|
107
|
+
requested_relation: opts.requested_relation,
|
|
108
|
+
is_archived: false,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
async downgradeRelation(opts) {
|
|
112
|
+
if (opts.relation >= opts.contact.relation) {
|
|
113
|
+
throw errValidation({
|
|
114
|
+
field: "relation",
|
|
115
|
+
msg: msgRelationDowngradeInvalid,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
return await this.replaceContact(opts.contact, {
|
|
119
|
+
is_pending: false,
|
|
120
|
+
relation: opts.relation,
|
|
121
|
+
requested_relation: Na,
|
|
122
|
+
is_archived: false,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
async acceptContactRequest(opts) {
|
|
126
|
+
if (opts.contact.requested_relation === Na) {
|
|
127
|
+
throw errValidation({
|
|
128
|
+
field: "contact",
|
|
129
|
+
msg: msgPendingRelationRequired,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
return await this.replaceContact(opts.contact, {
|
|
133
|
+
is_pending: false,
|
|
134
|
+
relation: opts.contact.requested_relation,
|
|
135
|
+
requested_relation: Na,
|
|
136
|
+
is_archived: false,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
async rejectContactRequest(opts) {
|
|
140
|
+
return await this.replaceContact(opts.contact, {
|
|
141
|
+
is_archived: true,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
async endHireRelation(opts) {
|
|
145
|
+
return await this.replaceContact(opts.contact, {
|
|
146
|
+
is_pending: false,
|
|
147
|
+
relation: OldHire,
|
|
148
|
+
requested_relation: Na,
|
|
149
|
+
is_archived: false,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
async replaceContact(contact, overrides) {
|
|
153
|
+
return await this.contacts.replaceOneContact({
|
|
154
|
+
id: contact.id,
|
|
155
|
+
in: {
|
|
156
|
+
contact_id: contact.contact_id,
|
|
157
|
+
is_pending: contact.is_pending,
|
|
158
|
+
relation: contact.relation,
|
|
159
|
+
requested_relation: contact.requested_relation,
|
|
160
|
+
is_archived: contact.is_archived,
|
|
161
|
+
...overrides,
|
|
162
|
+
},
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
export function newContactsFX(opts) {
|
|
167
|
+
return new ContactsFX(opts);
|
|
168
|
+
}
|
|
169
|
+
function contactPeerID(contact, owner_id) {
|
|
170
|
+
const contact_owner_id = contact.owner_id.trim();
|
|
171
|
+
const contact_id = contact.contact_id.trim();
|
|
172
|
+
if (contact_owner_id === owner_id && contact_id !== "") {
|
|
173
|
+
return contact_id;
|
|
174
|
+
}
|
|
175
|
+
if (contact_id === owner_id && contact_owner_id !== "") {
|
|
176
|
+
return contact_owner_id;
|
|
177
|
+
}
|
|
178
|
+
return undefined;
|
|
179
|
+
}
|
package/dist/src/core/err.d.ts
CHANGED
|
@@ -1,26 +1,53 @@
|
|
|
1
1
|
export declare const FXErrKind: {
|
|
2
|
-
readonly
|
|
3
|
-
readonly
|
|
4
|
-
readonly
|
|
5
|
-
readonly PhoneCodeRequired: "phone_code_required";
|
|
2
|
+
readonly Required: "required";
|
|
3
|
+
readonly Validation: "validation";
|
|
4
|
+
readonly ResolveFailed: "resolve_failed";
|
|
6
5
|
readonly Unknown: "unknown";
|
|
7
6
|
};
|
|
8
7
|
export type FXErrKind = (typeof FXErrKind)[keyof typeof FXErrKind];
|
|
9
|
-
export type
|
|
8
|
+
export type FieldOf<T extends object> = Extract<keyof T, string>;
|
|
9
|
+
export type FXErrOptions<T extends object = Record<string, unknown>> = {
|
|
10
10
|
kind: FXErrKind;
|
|
11
11
|
msg: string;
|
|
12
|
+
field?: FieldOf<T>;
|
|
13
|
+
resource?: string;
|
|
14
|
+
cause?: unknown;
|
|
15
|
+
};
|
|
16
|
+
export type RequiredFXErrOptions<T extends object = Record<string, unknown>> = {
|
|
17
|
+
field: FieldOf<T>;
|
|
18
|
+
msg: string;
|
|
19
|
+
cause?: unknown;
|
|
20
|
+
};
|
|
21
|
+
export type ValidationFXErrOptions<T extends object = Record<string, unknown>> = {
|
|
22
|
+
field?: FieldOf<T>;
|
|
23
|
+
msg: string;
|
|
24
|
+
cause?: unknown;
|
|
25
|
+
};
|
|
26
|
+
export type ResolveFailedFXErrOptions<T extends object = Record<string, unknown>> = {
|
|
27
|
+
resource: string;
|
|
28
|
+
msg: string;
|
|
29
|
+
field?: FieldOf<T>;
|
|
30
|
+
cause?: unknown;
|
|
31
|
+
};
|
|
32
|
+
type FXErrRuntimeOptions = {
|
|
33
|
+
kind: FXErrKind;
|
|
34
|
+
msg: string;
|
|
35
|
+
field?: string;
|
|
36
|
+
resource?: string;
|
|
12
37
|
cause?: unknown;
|
|
13
38
|
};
|
|
14
39
|
export declare class FXErr extends Error {
|
|
15
40
|
readonly kind: FXErrKind;
|
|
41
|
+
readonly field?: string;
|
|
42
|
+
readonly resource?: string;
|
|
16
43
|
readonly cause?: unknown;
|
|
17
|
-
constructor(opts:
|
|
44
|
+
constructor(opts: FXErrRuntimeOptions);
|
|
18
45
|
}
|
|
19
|
-
export declare function errFX(opts: FXErrOptions): FXErr;
|
|
20
|
-
export declare function
|
|
21
|
-
export declare function
|
|
22
|
-
export declare function
|
|
23
|
-
export declare function errPhoneCodeRequired(): FXErr;
|
|
46
|
+
export declare function errFX<T extends object = Record<string, unknown>>(opts: FXErrOptions<T>): FXErr;
|
|
47
|
+
export declare function errRequired<T extends object = Record<string, unknown>>(opts: RequiredFXErrOptions<T>): FXErr;
|
|
48
|
+
export declare function errValidation<T extends object = Record<string, unknown>>(opts: ValidationFXErrOptions<T>): FXErr;
|
|
49
|
+
export declare function errResolveFailed<T extends object = Record<string, unknown>>(opts: ResolveFailedFXErrOptions<T>): FXErr;
|
|
24
50
|
export declare function errUnknown(cause: unknown): FXErr;
|
|
25
51
|
export declare function isFXErr(err: unknown): err is FXErr;
|
|
26
52
|
export declare function fxErrMessage(err: unknown): string;
|
|
53
|
+
export {};
|
package/dist/src/core/err.js
CHANGED
|
@@ -4,51 +4,58 @@
|
|
|
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
6
|
const msgUnknownFXErr = "Unknown FX error.";
|
|
7
|
-
const msgUnableToResolveUsername = "Unable to resolve username.";
|
|
8
|
-
const msgPhoneRequired = "Phone number is required.";
|
|
9
|
-
const msgPhoneCodeRequired = "Verification code is required.";
|
|
10
7
|
export const FXErrKind = {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
PhoneCodeRequired: "phone_code_required",
|
|
8
|
+
Required: "required",
|
|
9
|
+
Validation: "validation",
|
|
10
|
+
ResolveFailed: "resolve_failed",
|
|
15
11
|
Unknown: "unknown",
|
|
16
12
|
};
|
|
17
13
|
export class FXErr extends Error {
|
|
18
14
|
kind;
|
|
15
|
+
field;
|
|
16
|
+
resource;
|
|
19
17
|
cause;
|
|
20
18
|
constructor(opts) {
|
|
21
19
|
super(opts.msg);
|
|
22
20
|
this.name = new.target.name;
|
|
23
21
|
this.kind = opts.kind;
|
|
22
|
+
this.field = opts.field;
|
|
23
|
+
this.resource = opts.resource;
|
|
24
24
|
this.cause = opts.cause;
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
export function errFX(opts) {
|
|
28
|
-
return new FXErr(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
return new FXErr({
|
|
29
|
+
kind: opts.kind,
|
|
30
|
+
msg: opts.msg,
|
|
31
|
+
field: opts.field,
|
|
32
|
+
resource: opts.resource,
|
|
33
|
+
cause: opts.cause,
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
|
-
export function
|
|
36
|
+
export function errRequired(opts) {
|
|
37
37
|
return errFX({
|
|
38
|
-
kind: FXErrKind.
|
|
39
|
-
msg,
|
|
38
|
+
kind: FXErrKind.Required,
|
|
39
|
+
msg: opts.msg,
|
|
40
|
+
field: opts.field,
|
|
41
|
+
cause: opts.cause,
|
|
40
42
|
});
|
|
41
43
|
}
|
|
42
|
-
export function
|
|
44
|
+
export function errValidation(opts) {
|
|
43
45
|
return errFX({
|
|
44
|
-
kind: FXErrKind.
|
|
45
|
-
msg:
|
|
46
|
+
kind: FXErrKind.Validation,
|
|
47
|
+
msg: opts.msg,
|
|
48
|
+
field: opts.field,
|
|
49
|
+
cause: opts.cause,
|
|
46
50
|
});
|
|
47
51
|
}
|
|
48
|
-
export function
|
|
52
|
+
export function errResolveFailed(opts) {
|
|
49
53
|
return errFX({
|
|
50
|
-
kind: FXErrKind.
|
|
51
|
-
msg:
|
|
54
|
+
kind: FXErrKind.ResolveFailed,
|
|
55
|
+
msg: opts.msg,
|
|
56
|
+
field: opts.field,
|
|
57
|
+
resource: opts.resource,
|
|
58
|
+
cause: opts.cause,
|
|
52
59
|
});
|
|
53
60
|
}
|
|
54
61
|
export function errUnknown(cause) {
|
package/dist/src/fx.d.ts
CHANGED
|
@@ -1,28 +1,50 @@
|
|
|
1
|
-
import type { PreferencesOperator, TmpPhonesOperator, TmpUsernamesOperator, UsersOperator } from "@fabriktor/client";
|
|
1
|
+
import type { BillableOperator, CallsOperator, ChatOperator, ConnectionsOperator, ContactsOperator, NotificationsOperator, PreferencesOperator, StorageOperator, TmpPhonesOperator, TmpUsernamesOperator, UsersOperator } from "@fabriktor/client";
|
|
2
2
|
import type { AuthOperator } from "./auth/auth.js";
|
|
3
|
+
import type { BillableFX, BillableFXOperator } from "./billable/billable.js";
|
|
4
|
+
import type { CallsFX, CallsFXOperator } from "./calls/calls.js";
|
|
5
|
+
import type { ChatFX, ChatFXOperator } from "./chat/chat.js";
|
|
6
|
+
import type { ContactsFX, ContactsFXOperator } from "./contacts/contacts.js";
|
|
3
7
|
import type { PreferencesFX, PreferencesFXOperator } from "./preferences/preferences.js";
|
|
4
8
|
import type { SessionFX, SessionFXOperator } from "./session/session.js";
|
|
9
|
+
import type { StorageFX, StorageFXOperator } from "./storage/storage.js";
|
|
5
10
|
import type { UsersFX, UsersFXOperator } from "./users/users.js";
|
|
6
11
|
export type FXOptions = {
|
|
7
12
|
auth: AuthOperator;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
13
|
+
billable: BillableOperator;
|
|
14
|
+
calls: CallsOperator;
|
|
15
|
+
chat: ChatOperator;
|
|
16
|
+
connections: ConnectionsOperator;
|
|
17
|
+
contacts: ContactsOperator;
|
|
18
|
+
notifications: NotificationsOperator;
|
|
11
19
|
preferences: PreferencesOperator;
|
|
20
|
+
storage: StorageOperator;
|
|
21
|
+
tmp_phones: TmpPhonesOperator;
|
|
22
|
+
tmp_usernames: TmpUsernamesOperator;
|
|
23
|
+
users: UsersOperator;
|
|
12
24
|
};
|
|
13
25
|
export type DefaultFXOptions = {
|
|
14
26
|
base_url: string;
|
|
15
27
|
auth: AuthOperator;
|
|
16
28
|
};
|
|
17
29
|
export interface FXOperator {
|
|
18
|
-
|
|
19
|
-
|
|
30
|
+
billable: BillableFXOperator;
|
|
31
|
+
calls: CallsFXOperator;
|
|
32
|
+
chat: ChatFXOperator;
|
|
33
|
+
contacts: ContactsFXOperator;
|
|
20
34
|
preferences: PreferencesFXOperator;
|
|
35
|
+
session: SessionFXOperator;
|
|
36
|
+
storage: StorageFXOperator;
|
|
37
|
+
users: UsersFXOperator;
|
|
21
38
|
}
|
|
22
39
|
export declare class FX implements FXOperator {
|
|
23
|
-
|
|
24
|
-
|
|
40
|
+
billable: BillableFX;
|
|
41
|
+
calls: CallsFX;
|
|
42
|
+
chat: ChatFX;
|
|
43
|
+
contacts: ContactsFX;
|
|
25
44
|
preferences: PreferencesFX;
|
|
45
|
+
session: SessionFX;
|
|
46
|
+
storage: StorageFX;
|
|
47
|
+
users: UsersFX;
|
|
26
48
|
constructor(opts: FXOptions);
|
|
27
49
|
}
|
|
28
50
|
export declare function newFX(opts: FXOptions): FX;
|
package/dist/src/fx.js
CHANGED
|
@@ -1,28 +1,56 @@
|
|
|
1
|
-
// Copyright (C) Fabriktor, Inc. 2025-present.
|
|
1
|
+
// Copyright (C) Fab// Copyright (C) Fabriktor, Inc. 2025-present.
|
|
2
2
|
//
|
|
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 { newHTTPClient, newPreferencesClient, newTmpPhonesClient, newTmpUsernamesClient, newUsersClient, } from "@fabriktor/client";
|
|
6
|
+
import { newBillableClient, newCallsClient, newChatClient, newConnectionsClient, newContactsClient, newHTTPClient, newNotificationsClient, newPreferencesClient, newStorageClient, newTmpPhonesClient, newTmpUsernamesClient, newUsersClient, } from "@fabriktor/client";
|
|
7
|
+
import { newBillableFX } from "./billable/billable.js";
|
|
8
|
+
import { newCallsFX } from "./calls/calls.js";
|
|
9
|
+
import { newChatFX } from "./chat/chat.js";
|
|
10
|
+
import { newContactsFX } from "./contacts/contacts.js";
|
|
7
11
|
import { newPreferencesFX } from "./preferences/preferences.js";
|
|
8
12
|
import { newSessionFX } from "./session/session.js";
|
|
13
|
+
import { newStorageFX } from "./storage/storage.js";
|
|
9
14
|
import { newUsersFX } from "./users/users.js";
|
|
10
15
|
export class FX {
|
|
11
|
-
|
|
12
|
-
|
|
16
|
+
billable;
|
|
17
|
+
calls;
|
|
18
|
+
chat;
|
|
19
|
+
contacts;
|
|
13
20
|
preferences;
|
|
21
|
+
session;
|
|
22
|
+
storage;
|
|
23
|
+
users;
|
|
14
24
|
constructor(opts) {
|
|
25
|
+
this.billable = newBillableFX({
|
|
26
|
+
billable: opts.billable,
|
|
27
|
+
});
|
|
28
|
+
this.calls = newCallsFX({
|
|
29
|
+
calls: opts.calls,
|
|
30
|
+
notifications: opts.notifications,
|
|
31
|
+
});
|
|
32
|
+
this.chat = newChatFX({
|
|
33
|
+
chat: opts.chat,
|
|
34
|
+
});
|
|
35
|
+
this.contacts = newContactsFX({
|
|
36
|
+
contacts: opts.contacts,
|
|
37
|
+
});
|
|
38
|
+
this.preferences = newPreferencesFX({
|
|
39
|
+
preferences: opts.preferences,
|
|
40
|
+
});
|
|
41
|
+
this.storage = newStorageFX({
|
|
42
|
+
storage: opts.storage,
|
|
43
|
+
});
|
|
15
44
|
this.users = newUsersFX({
|
|
16
45
|
users: opts.users,
|
|
17
46
|
tmp_usernames: opts.tmp_usernames,
|
|
18
47
|
tmp_phones: opts.tmp_phones,
|
|
19
48
|
});
|
|
20
|
-
this.preferences = newPreferencesFX({
|
|
21
|
-
preferences: opts.preferences,
|
|
22
|
-
});
|
|
23
49
|
this.session = newSessionFX({
|
|
24
50
|
auth: opts.auth,
|
|
25
|
-
|
|
51
|
+
connections: opts.connections,
|
|
52
|
+
users: opts.users,
|
|
53
|
+
users_fx: this.users,
|
|
26
54
|
});
|
|
27
55
|
}
|
|
28
56
|
}
|
|
@@ -34,17 +62,32 @@ export function newDefaultFX(opts) {
|
|
|
34
62
|
const get_token = () => opts.auth.getToken();
|
|
35
63
|
return newFX({
|
|
36
64
|
auth: opts.auth,
|
|
37
|
-
|
|
65
|
+
billable: newBillableClient({
|
|
38
66
|
http,
|
|
39
67
|
base_url: opts.base_url,
|
|
40
68
|
get_token,
|
|
41
69
|
}),
|
|
42
|
-
|
|
70
|
+
calls: newCallsClient({
|
|
43
71
|
http,
|
|
44
72
|
base_url: opts.base_url,
|
|
45
73
|
get_token,
|
|
46
74
|
}),
|
|
47
|
-
|
|
75
|
+
chat: newChatClient({
|
|
76
|
+
http,
|
|
77
|
+
base_url: opts.base_url,
|
|
78
|
+
get_token,
|
|
79
|
+
}),
|
|
80
|
+
connections: newConnectionsClient({
|
|
81
|
+
http,
|
|
82
|
+
base_url: opts.base_url,
|
|
83
|
+
get_token,
|
|
84
|
+
}),
|
|
85
|
+
contacts: newContactsClient({
|
|
86
|
+
http,
|
|
87
|
+
base_url: opts.base_url,
|
|
88
|
+
get_token,
|
|
89
|
+
}),
|
|
90
|
+
notifications: newNotificationsClient({
|
|
48
91
|
http,
|
|
49
92
|
base_url: opts.base_url,
|
|
50
93
|
get_token,
|
|
@@ -54,5 +97,25 @@ export function newDefaultFX(opts) {
|
|
|
54
97
|
base_url: opts.base_url,
|
|
55
98
|
get_token,
|
|
56
99
|
}),
|
|
100
|
+
storage: newStorageClient({
|
|
101
|
+
http,
|
|
102
|
+
base_url: opts.base_url,
|
|
103
|
+
get_token,
|
|
104
|
+
}),
|
|
105
|
+
tmp_phones: newTmpPhonesClient({
|
|
106
|
+
http,
|
|
107
|
+
base_url: opts.base_url,
|
|
108
|
+
get_token,
|
|
109
|
+
}),
|
|
110
|
+
tmp_usernames: newTmpUsernamesClient({
|
|
111
|
+
http,
|
|
112
|
+
base_url: opts.base_url,
|
|
113
|
+
get_token,
|
|
114
|
+
}),
|
|
115
|
+
users: newUsersClient({
|
|
116
|
+
http,
|
|
117
|
+
base_url: opts.base_url,
|
|
118
|
+
get_token,
|
|
119
|
+
}),
|
|
57
120
|
});
|
|
58
121
|
}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
export * from "./auth/auth.js";
|
|
2
|
+
export * from "./billable/billable.js";
|
|
3
|
+
export * from "./calls/calls.js";
|
|
4
|
+
export * from "./chat/chat.js";
|
|
5
|
+
export * from "./contacts/contacts.js";
|
|
2
6
|
export * from "./core/err.js";
|
|
3
7
|
export * from "./fx.js";
|
|
4
8
|
export * from "./preferences/preferences.js";
|
|
5
9
|
export * from "./session/session.js";
|
|
10
|
+
export * from "./storage/storage.js";
|
|
6
11
|
export * from "./users/phone.js";
|
|
7
12
|
export * from "./users/username.js";
|
|
8
13
|
export * from "./users/users.js";
|
package/dist/src/index.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
export * from "./auth/auth.js";
|
|
2
|
+
export * from "./billable/billable.js";
|
|
3
|
+
export * from "./calls/calls.js";
|
|
4
|
+
export * from "./chat/chat.js";
|
|
5
|
+
export * from "./contacts/contacts.js";
|
|
2
6
|
export * from "./core/err.js";
|
|
3
7
|
export * from "./fx.js";
|
|
4
8
|
export * from "./preferences/preferences.js";
|
|
5
9
|
export * from "./session/session.js";
|
|
10
|
+
export * from "./storage/storage.js";
|
|
6
11
|
export * from "./users/phone.js";
|
|
7
12
|
export * from "./users/username.js";
|
|
8
13
|
export * from "./users/users.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type {
|
|
1
|
+
import type { OperationResult } from "@fabriktor/schema";
|
|
2
|
+
import type { PreferencesOperator } from "@fabriktor/client";
|
|
3
3
|
export type EnsurePrefLanguageOptions = {
|
|
4
4
|
owner_id: string;
|
|
5
5
|
language: string;
|
|
@@ -7,9 +7,6 @@ export type EnsurePrefLanguageOptions = {
|
|
|
7
7
|
speech_to_text_source_language?: string;
|
|
8
8
|
};
|
|
9
9
|
export interface PreferencesFXOperator {
|
|
10
|
-
queryPrefLanguages(opts?: QueryOptionsCRUD): Promise<OperationResultOf<PrefLanguage[]>>;
|
|
11
|
-
insertOnePrefLanguage(opts: InsertOneOptionsCRUD<InPrefLanguage>): Promise<OperationResult>;
|
|
12
|
-
replaceOnePrefLanguage(opts: ReplaceOneOptionsCRUD<InPrefLanguage>): Promise<OperationResult>;
|
|
13
10
|
ensurePrefLanguage(opts: EnsurePrefLanguageOptions): Promise<OperationResult>;
|
|
14
11
|
}
|
|
15
12
|
export type PreferencesFXOptions = {
|
|
@@ -18,9 +15,6 @@ export type PreferencesFXOptions = {
|
|
|
18
15
|
export declare class PreferencesFX implements PreferencesFXOperator {
|
|
19
16
|
private preferences;
|
|
20
17
|
constructor(opts: PreferencesFXOptions);
|
|
21
|
-
queryPrefLanguages(opts?: QueryOptionsCRUD): Promise<OperationResultOf<PrefLanguage[]>>;
|
|
22
|
-
insertOnePrefLanguage(opts: InsertOneOptionsCRUD<InPrefLanguage>): Promise<OperationResult>;
|
|
23
|
-
replaceOnePrefLanguage(opts: ReplaceOneOptionsCRUD<InPrefLanguage>): Promise<OperationResult>;
|
|
24
18
|
ensurePrefLanguage(opts: EnsurePrefLanguageOptions): Promise<OperationResult>;
|
|
25
19
|
}
|
|
26
20
|
export declare function newPreferencesFX(opts: PreferencesFXOptions): PreferencesFX;
|
|
@@ -3,28 +3,17 @@
|
|
|
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 {
|
|
6
|
+
import { queryParam } from "@fabriktor/client";
|
|
7
7
|
export class PreferencesFX {
|
|
8
8
|
preferences;
|
|
9
9
|
constructor(opts) {
|
|
10
10
|
this.preferences = opts.preferences;
|
|
11
11
|
}
|
|
12
|
-
async queryPrefLanguages(opts) {
|
|
13
|
-
return await this.preferences.queryPrefLanguages(opts);
|
|
14
|
-
}
|
|
15
|
-
async insertOnePrefLanguage(opts) {
|
|
16
|
-
return await this.preferences.insertOnePrefLanguage(opts);
|
|
17
|
-
}
|
|
18
|
-
async replaceOnePrefLanguage(opts) {
|
|
19
|
-
return await this.preferences.replaceOnePrefLanguage(opts);
|
|
20
|
-
}
|
|
21
12
|
async ensurePrefLanguage(opts) {
|
|
22
13
|
const out = await this.preferences.queryPrefLanguages({
|
|
23
|
-
query:
|
|
24
|
-
owner_id: opts.owner_id,
|
|
25
|
-
},
|
|
14
|
+
query: queryParam("owner_id", opts.owner_id),
|
|
26
15
|
});
|
|
27
|
-
const prefs = out
|
|
16
|
+
const prefs = out.value ?? [];
|
|
28
17
|
const pref = prefs[0];
|
|
29
18
|
const input = {
|
|
30
19
|
is_default: false,
|
|
@@ -1,26 +1,36 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { InConnection, InUser, PLUsersForgotPassword, PLUsersSignInLink, PLUsersVerifyEmail, UpsertResult } from "@fabriktor/schema";
|
|
2
|
+
import type { BootstrapOptions, ConnectionsOperator, OperationResultOf, UsersOperator } from "@fabriktor/client";
|
|
3
3
|
import type { AuthEmailOptions, AuthOperator } from "../auth/auth.js";
|
|
4
|
-
import type {
|
|
5
|
-
export
|
|
4
|
+
import type { UsersFXOperator } from "../users/users.js";
|
|
5
|
+
export declare const SignInMode: {
|
|
6
|
+
readonly Email: "email";
|
|
7
|
+
readonly Username: "username";
|
|
8
|
+
};
|
|
9
|
+
export type SignInMode = (typeof SignInMode)[keyof typeof SignInMode];
|
|
6
10
|
export type SignInOptions = {
|
|
7
11
|
mode: SignInMode;
|
|
8
12
|
identifier: string;
|
|
9
13
|
password: string;
|
|
14
|
+
connection: InConnection;
|
|
15
|
+
};
|
|
16
|
+
export type SignInWithEmailOptions = AuthEmailOptions & {
|
|
17
|
+
connection: InConnection;
|
|
10
18
|
};
|
|
11
19
|
export type SignUpAndBootstrapOptions = AuthEmailOptions & {
|
|
12
20
|
in: InUser;
|
|
13
21
|
};
|
|
14
22
|
export type SessionFXOptions = {
|
|
15
23
|
auth: AuthOperator;
|
|
16
|
-
|
|
24
|
+
connections: ConnectionsOperator;
|
|
25
|
+
users: UsersOperator;
|
|
26
|
+
users_fx: UsersFXOperator;
|
|
17
27
|
};
|
|
18
28
|
export interface SessionFXOperator {
|
|
19
29
|
startSignUp(opts: AuthEmailOptions): Promise<void>;
|
|
20
|
-
finishSignUp(opts: BootstrapOptions): Promise<
|
|
21
|
-
signUpAndBootstrap(opts: SignUpAndBootstrapOptions): Promise<
|
|
30
|
+
finishSignUp(opts: BootstrapOptions): Promise<OperationResultOf<UpsertResult>>;
|
|
31
|
+
signUpAndBootstrap(opts: SignUpAndBootstrapOptions): Promise<OperationResultOf<UpsertResult>>;
|
|
22
32
|
signIn(opts: SignInOptions): Promise<void>;
|
|
23
|
-
signInWithEmail(opts:
|
|
33
|
+
signInWithEmail(opts: SignInWithEmailOptions): Promise<void>;
|
|
24
34
|
signOut(): Promise<void>;
|
|
25
35
|
forgotPassword(opts: PLUsersForgotPassword): Promise<void>;
|
|
26
36
|
sendSignInLink(opts: PLUsersSignInLink): Promise<void>;
|
|
@@ -29,13 +39,15 @@ export interface SessionFXOperator {
|
|
|
29
39
|
}
|
|
30
40
|
export declare class SessionFX implements SessionFXOperator {
|
|
31
41
|
private auth;
|
|
42
|
+
private connections;
|
|
32
43
|
private users;
|
|
44
|
+
private users_fx;
|
|
33
45
|
constructor(opts: SessionFXOptions);
|
|
34
46
|
startSignUp(opts: AuthEmailOptions): Promise<void>;
|
|
35
|
-
finishSignUp(opts: BootstrapOptions): Promise<
|
|
36
|
-
signUpAndBootstrap(opts: SignUpAndBootstrapOptions): Promise<
|
|
47
|
+
finishSignUp(opts: BootstrapOptions): Promise<OperationResultOf<UpsertResult>>;
|
|
48
|
+
signUpAndBootstrap(opts: SignUpAndBootstrapOptions): Promise<OperationResultOf<UpsertResult>>;
|
|
37
49
|
signIn(opts: SignInOptions): Promise<void>;
|
|
38
|
-
signInWithEmail(opts:
|
|
50
|
+
signInWithEmail(opts: SignInWithEmailOptions): Promise<void>;
|
|
39
51
|
signOut(): Promise<void>;
|
|
40
52
|
forgotPassword(opts: PLUsersForgotPassword): Promise<void>;
|
|
41
53
|
sendSignInLink(opts: PLUsersSignInLink): Promise<void>;
|