@fabriktor/fx 0.0.65 → 0.0.67
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/fx.d.ts +5 -1
- package/dist/src/fx.js +12 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/payments/payments.d.ts +20 -0
- package/dist/src/payments/payments.js +57 -0
- package/dist/src/preferences/preferences.d.ts +49 -1
- package/dist/src/preferences/preferences.js +100 -7
- package/dist/src/processes/processes.d.ts +27 -0
- package/dist/src/processes/processes.js +38 -0
- package/package.json +1 -1
package/dist/src/fx.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BillableOperator, CallsOperator, ChatOperator, ConnectionsOperator, ContactsOperator, FeedOperator, FulfillmentsOperator, JobsOperator, MarketplaceOperator, MemosOperator, NotificationsOperator, PaymentsOperator, PayrollsOperator, PreferencesOperator, PrivacyOperator, RoutesOperator, StorageOperator, TimesheetsOperator, TmpPhonesOperator, TmpUsernamesOperator, UsersOperator } from "@fabriktor/client";
|
|
1
|
+
import type { BillableOperator, CallsOperator, ChatOperator, ConnectionsOperator, ContactsOperator, FeedOperator, FulfillmentsOperator, JobsOperator, MarketplaceOperator, MemosOperator, NotificationsOperator, PaymentsOperator, PayrollsOperator, PreferencesOperator, PrivacyOperator, ProcessesOperator, RoutesOperator, StorageOperator, TimesheetsOperator, TmpPhonesOperator, TmpUsernamesOperator, UsersOperator } from "@fabriktor/client";
|
|
2
2
|
import type { AuthOperator } from "./auth/auth.js";
|
|
3
3
|
import type { BillableFX, BillableFXOperator } from "./billable/billable.js";
|
|
4
4
|
import type { CallsFX, CallsFXOperator } from "./calls/calls.js";
|
|
@@ -14,6 +14,7 @@ import type { PaymentsFX, PaymentsFXOperator } from "./payments/payments.js";
|
|
|
14
14
|
import type { PayrollsFX, PayrollsFXOperator } from "./payrolls/payrolls.js";
|
|
15
15
|
import type { PreferencesFX, PreferencesFXOperator } from "./preferences/preferences.js";
|
|
16
16
|
import type { PrivacyFX, PrivacyFXOperator } from "./privacy/privacy.js";
|
|
17
|
+
import type { ProcessesFX, ProcessesFXOperator } from "./processes/processes.js";
|
|
17
18
|
import type { RoutesFX, RoutesFXOperator } from "./routes/routes.js";
|
|
18
19
|
import type { SessionFX, SessionFXOperator } from "./session/session.js";
|
|
19
20
|
import type { StorageFX, StorageFXOperator } from "./storage/storage.js";
|
|
@@ -36,6 +37,7 @@ export type FXOptions = {
|
|
|
36
37
|
payrolls: PayrollsOperator;
|
|
37
38
|
preferences: PreferencesOperator;
|
|
38
39
|
privacy: PrivacyOperator;
|
|
40
|
+
processes: ProcessesOperator;
|
|
39
41
|
routes: RoutesOperator;
|
|
40
42
|
storage: StorageOperator;
|
|
41
43
|
timesheets: TimesheetsOperator;
|
|
@@ -68,6 +70,7 @@ export interface FXOperator {
|
|
|
68
70
|
payrolls: PayrollsFXOperator;
|
|
69
71
|
preferences: PreferencesFXOperator;
|
|
70
72
|
privacy: PrivacyFXOperator;
|
|
73
|
+
processes: ProcessesFXOperator;
|
|
71
74
|
routes: RoutesFXOperator;
|
|
72
75
|
session: SessionFXOperator;
|
|
73
76
|
storage: StorageFXOperator;
|
|
@@ -89,6 +92,7 @@ export declare class FX implements FXOperator {
|
|
|
89
92
|
payrolls: PayrollsFX;
|
|
90
93
|
preferences: PreferencesFX;
|
|
91
94
|
privacy: PrivacyFX;
|
|
95
|
+
processes: ProcessesFX;
|
|
92
96
|
routes: RoutesFX;
|
|
93
97
|
session: SessionFX;
|
|
94
98
|
storage: StorageFX;
|
package/dist/src/fx.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 { newBillableClient, newCallsClient, newChatClient, newConnectionsClient, newContactsClient, newFeedClient, newFulfillmentsClient, newHTTPClient, newJobsClient, newMarketplaceClient, newMemosClient, newNotificationsClient, newPaymentsClient, newPayrollsClient, newPreferencesClient, newPrivacyClient, newRoutesClient, newStorageClient, newTimesheetsClient, newTmpPhonesClient, newTmpUsernamesClient, newUsersClient, } from "@fabriktor/client";
|
|
6
|
+
import { newBillableClient, newCallsClient, newChatClient, newConnectionsClient, newContactsClient, newFeedClient, newFulfillmentsClient, newHTTPClient, newJobsClient, newMarketplaceClient, newMemosClient, newNotificationsClient, newPaymentsClient, newPayrollsClient, newPreferencesClient, newPrivacyClient, newProcessesClient, newRoutesClient, newStorageClient, newTimesheetsClient, newTmpPhonesClient, newTmpUsernamesClient, newUsersClient, } from "@fabriktor/client";
|
|
7
7
|
import { newBillableFX } from "./billable/billable.js";
|
|
8
8
|
import { newCallsFX } from "./calls/calls.js";
|
|
9
9
|
import { newChatFX } from "./chat/chat.js";
|
|
@@ -18,6 +18,7 @@ import { newPaymentsFX } from "./payments/payments.js";
|
|
|
18
18
|
import { newPayrollsFX } from "./payrolls/payrolls.js";
|
|
19
19
|
import { newPreferencesFX } from "./preferences/preferences.js";
|
|
20
20
|
import { newPrivacyFX } from "./privacy/privacy.js";
|
|
21
|
+
import { newProcessesFX } from "./processes/processes.js";
|
|
21
22
|
import { newRoutesFX } from "./routes/routes.js";
|
|
22
23
|
import { newSessionFX } from "./session/session.js";
|
|
23
24
|
import { newStorageFX } from "./storage/storage.js";
|
|
@@ -38,6 +39,7 @@ export class FX {
|
|
|
38
39
|
payrolls;
|
|
39
40
|
preferences;
|
|
40
41
|
privacy;
|
|
42
|
+
processes;
|
|
41
43
|
routes;
|
|
42
44
|
session;
|
|
43
45
|
storage;
|
|
@@ -83,6 +85,10 @@ export class FX {
|
|
|
83
85
|
this.privacy = newPrivacyFX({
|
|
84
86
|
privacy: opts.privacy,
|
|
85
87
|
});
|
|
88
|
+
this.processes = newProcessesFX({
|
|
89
|
+
processes: opts.processes,
|
|
90
|
+
preferences_fx: this.preferences,
|
|
91
|
+
});
|
|
86
92
|
this.routes = newRoutesFX({
|
|
87
93
|
routes: opts.routes,
|
|
88
94
|
});
|
|
@@ -197,6 +203,11 @@ export function newDefaultFX(opts) {
|
|
|
197
203
|
base_url: opts.base_url,
|
|
198
204
|
get_token,
|
|
199
205
|
}),
|
|
206
|
+
processes: newProcessesClient({
|
|
207
|
+
http,
|
|
208
|
+
base_url: opts.base_url,
|
|
209
|
+
get_token,
|
|
210
|
+
}),
|
|
200
211
|
routes: newRoutesClient({
|
|
201
212
|
http,
|
|
202
213
|
base_url: opts.base_url,
|
package/dist/src/index.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export * from "./payments/payments.js";
|
|
|
18
18
|
export * from "./payrolls/payrolls.js";
|
|
19
19
|
export * from "./preferences/preferences.js";
|
|
20
20
|
export * from "./privacy/privacy.js";
|
|
21
|
+
export * from "./processes/processes.js";
|
|
21
22
|
export * from "./routes/routes.js";
|
|
22
23
|
export * from "./session/session.js";
|
|
23
24
|
export * from "./storage/storage.js";
|
package/dist/src/index.js
CHANGED
|
@@ -18,6 +18,7 @@ export * from "./payments/payments.js";
|
|
|
18
18
|
export * from "./payrolls/payrolls.js";
|
|
19
19
|
export * from "./preferences/preferences.js";
|
|
20
20
|
export * from "./privacy/privacy.js";
|
|
21
|
+
export * from "./processes/processes.js";
|
|
21
22
|
export * from "./routes/routes.js";
|
|
22
23
|
export * from "./session/session.js";
|
|
23
24
|
export * from "./storage/storage.js";
|
|
@@ -61,6 +61,24 @@ export type CreateCreditLedgerEntryOptions = CreditLedgerEntryInsertOptions;
|
|
|
61
61
|
export type ReplaceCreditLedgerEntryOptions = CreditLedgerEntryReplaceOptions;
|
|
62
62
|
export type SearchCreditLedgerOptions = SearchPaymentRecordsOptions;
|
|
63
63
|
export type SearchCreditLedgerPage = SearchPage<CreditLedgerEntry>;
|
|
64
|
+
export declare const PmtAccountAccessStatus: {
|
|
65
|
+
readonly Missing: "missing";
|
|
66
|
+
readonly OnboardingRequired: "onboarding_required";
|
|
67
|
+
readonly RequirementsDue: "requirements_due";
|
|
68
|
+
readonly Ready: "ready";
|
|
69
|
+
};
|
|
70
|
+
export type PmtAccountAccessStatus = (typeof PmtAccountAccessStatus)[keyof typeof PmtAccountAccessStatus];
|
|
71
|
+
export type PmtAccountAccess = {
|
|
72
|
+
account: PmtAccount | null;
|
|
73
|
+
status: PmtAccountAccessStatus;
|
|
74
|
+
ready: boolean;
|
|
75
|
+
};
|
|
76
|
+
export type GetPmtAccountAccessOptions = {
|
|
77
|
+
owner_id: string;
|
|
78
|
+
};
|
|
79
|
+
export declare function isPmtAccountReady(account: PmtAccount | null): boolean;
|
|
80
|
+
export declare function currentPmtAccount(accounts: readonly PmtAccount[]): PmtAccount | null;
|
|
81
|
+
export declare function pmtAccountAccess(account: PmtAccount | null): PmtAccountAccess;
|
|
64
82
|
export declare const PublicPaymentSessionStatus: {
|
|
65
83
|
readonly NotFound: "not_found";
|
|
66
84
|
readonly Ready: "ready";
|
|
@@ -99,6 +117,7 @@ export interface PaymentsFXOperator {
|
|
|
99
117
|
continuePmtAccountOnboarding(opts: ContinuePmtAccountOnboardingOptions): Promise<ContinuePmtAccountOnboardingResult>;
|
|
100
118
|
replacePmtAccount(opts: ReplacePmtAccountOptions): Promise<PmtAccount>;
|
|
101
119
|
searchPmtAccounts(opts: SearchPmtAccountsOptions): Promise<SearchPmtAccountsPage>;
|
|
120
|
+
getPmtAccountAccess(opts: GetPmtAccountAccessOptions): Promise<PmtAccountAccess>;
|
|
102
121
|
createPmtBankAccount(opts: CreatePmtBankAccountOptions): Promise<PmtBankAccount>;
|
|
103
122
|
replacePmtBankAccount(opts: ReplacePmtBankAccountOptions): Promise<PmtBankAccount>;
|
|
104
123
|
searchPmtBankAccounts(opts: SearchPmtBankAccountsOptions): Promise<SearchPmtBankAccountsPage>;
|
|
@@ -136,6 +155,7 @@ export declare class PaymentsFX implements PaymentsFXOperator {
|
|
|
136
155
|
continuePmtAccountOnboarding(opts: ContinuePmtAccountOnboardingOptions): Promise<ContinuePmtAccountOnboardingResult>;
|
|
137
156
|
replacePmtAccount(opts: ReplacePmtAccountOptions): Promise<PmtAccount>;
|
|
138
157
|
searchPmtAccounts(opts: SearchPmtAccountsOptions): Promise<SearchPmtAccountsPage>;
|
|
158
|
+
getPmtAccountAccess(opts: GetPmtAccountAccessOptions): Promise<PmtAccountAccess>;
|
|
139
159
|
createPmtBankAccount(opts: CreatePmtBankAccountOptions): Promise<PmtBankAccount>;
|
|
140
160
|
replacePmtBankAccount(opts: ReplacePmtBankAccountOptions): Promise<PmtBankAccount>;
|
|
141
161
|
searchPmtBankAccounts(opts: SearchPmtBankAccountsOptions): Promise<SearchPmtBankAccountsPage>;
|
|
@@ -46,6 +46,47 @@ const msgPublicSessionConsumed = "Public payment session has already been consum
|
|
|
46
46
|
const msgPublicAmountInvalid = "Public payment amount must be a positive integer.";
|
|
47
47
|
const msgPublicBalanceInvalid = "Public payment session balance is invalid.";
|
|
48
48
|
const msgPublicAmountExceedsBalance = "Public payment amount cannot exceed the session balance.";
|
|
49
|
+
export const PmtAccountAccessStatus = {
|
|
50
|
+
Missing: "missing",
|
|
51
|
+
OnboardingRequired: "onboarding_required",
|
|
52
|
+
RequirementsDue: "requirements_due",
|
|
53
|
+
Ready: "ready",
|
|
54
|
+
};
|
|
55
|
+
export function isPmtAccountReady(account) {
|
|
56
|
+
return (account !== null &&
|
|
57
|
+
!account.psp_deactivate &&
|
|
58
|
+
account.psp_id.trim() !== "" &&
|
|
59
|
+
account.psp_id !== ZeroID &&
|
|
60
|
+
account.is_onboarded &&
|
|
61
|
+
!account.is_currently_due &&
|
|
62
|
+
!account.is_external_account_due);
|
|
63
|
+
}
|
|
64
|
+
export function currentPmtAccount(accounts) {
|
|
65
|
+
return (accounts.find(isPmtAccountReady) ??
|
|
66
|
+
accounts.find((account) => !account.psp_deactivate) ??
|
|
67
|
+
null);
|
|
68
|
+
}
|
|
69
|
+
export function pmtAccountAccess(account) {
|
|
70
|
+
if (account === null) {
|
|
71
|
+
return { account, status: PmtAccountAccessStatus.Missing, ready: false };
|
|
72
|
+
}
|
|
73
|
+
if (account.is_currently_due ||
|
|
74
|
+
account.is_external_account_due) {
|
|
75
|
+
return {
|
|
76
|
+
account,
|
|
77
|
+
status: PmtAccountAccessStatus.RequirementsDue,
|
|
78
|
+
ready: false,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
if (!isPmtAccountReady(account)) {
|
|
82
|
+
return {
|
|
83
|
+
account,
|
|
84
|
+
status: PmtAccountAccessStatus.OnboardingRequired,
|
|
85
|
+
ready: false,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
return { account, status: PmtAccountAccessStatus.Ready, ready: true };
|
|
89
|
+
}
|
|
49
90
|
export const PublicPaymentSessionStatus = {
|
|
50
91
|
NotFound: "not_found",
|
|
51
92
|
Ready: "ready",
|
|
@@ -119,6 +160,22 @@ export class PaymentsFX {
|
|
|
119
160
|
per_page: opts.per_page,
|
|
120
161
|
});
|
|
121
162
|
}
|
|
163
|
+
async getPmtAccountAccess(opts) {
|
|
164
|
+
const accounts = [];
|
|
165
|
+
let page = 1;
|
|
166
|
+
while (true) {
|
|
167
|
+
const out = await this.searchPmtAccounts({
|
|
168
|
+
owner_id: opts.owner_id,
|
|
169
|
+
page,
|
|
170
|
+
});
|
|
171
|
+
accounts.push(...out.results);
|
|
172
|
+
const account = currentPmtAccount(accounts);
|
|
173
|
+
if (isPmtAccountReady(account) || out.done) {
|
|
174
|
+
return pmtAccountAccess(account);
|
|
175
|
+
}
|
|
176
|
+
page = out.next_page;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
122
179
|
async createPmtBankAccount(opts) {
|
|
123
180
|
const out = await this.payments.insertOnePmtBankAccount(opts);
|
|
124
181
|
const id = requiredOperationID(out, msgCreatedPmtBankAccountIDMissing);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PreferencesOperator } from "@fabriktor/client";
|
|
2
|
-
import { type OperationResult, type PrefPayment, type PrefClient, type PrefEmployee, type PrefCompany, type PrefVisibility, type PrefLanguage, type PrefNotif, type PrefEmail, type PrefTutorial } from "@fabriktor/schema";
|
|
2
|
+
import { type InPrefClient, type InPrefCompany, type InPrefEmployee, type OperationResult, type PrefPayment, type PrefClient, type PrefEmployee, type PrefCompany, type PrefVisibility, type PrefLanguage, type PrefNotif, type PrefEmail, type PrefTutorial } from "@fabriktor/schema";
|
|
3
3
|
type PrefPaymentInsertOptions = Parameters<PreferencesOperator["insertOnePrefPayment"]>[0];
|
|
4
4
|
type PrefPaymentReplaceOptions = Parameters<PreferencesOperator["replaceOnePrefPayment"]>[0];
|
|
5
5
|
type PrefClientInsertOptions = Parameters<PreferencesOperator["insertOnePrefClient"]>[0];
|
|
@@ -36,25 +36,61 @@ export type CreatePrefEmailOptions = PrefEmailInsertOptions;
|
|
|
36
36
|
export type ReplacePrefEmailOptions = PrefEmailReplaceOptions;
|
|
37
37
|
export type CreatePrefTutorialOptions = PrefTutorialInsertOptions;
|
|
38
38
|
export type ReplacePrefTutorialOptions = PrefTutorialReplaceOptions;
|
|
39
|
+
export type GetPrefClientOptions = {
|
|
40
|
+
owner_id: string;
|
|
41
|
+
};
|
|
42
|
+
export type GetPrefEmployeeOptions = {
|
|
43
|
+
owner_id: string;
|
|
44
|
+
};
|
|
45
|
+
export type GetPrefCompanyOptions = {
|
|
46
|
+
owner_id: string;
|
|
47
|
+
};
|
|
48
|
+
export type SavePrefClientOptions = {
|
|
49
|
+
current: PrefClient;
|
|
50
|
+
in: InPrefClient;
|
|
51
|
+
};
|
|
52
|
+
export type SavePrefEmployeeOptions = {
|
|
53
|
+
current: PrefEmployee;
|
|
54
|
+
in: InPrefEmployee;
|
|
55
|
+
};
|
|
56
|
+
export type SavePrefCompanyOptions = {
|
|
57
|
+
current: PrefCompany;
|
|
58
|
+
in: InPrefCompany;
|
|
59
|
+
};
|
|
60
|
+
export type GetPrefLanguageOptions = {
|
|
61
|
+
owner_id: string;
|
|
62
|
+
};
|
|
39
63
|
export type EnsurePrefLanguageOptions = {
|
|
40
64
|
owner_id: string;
|
|
41
65
|
language: string;
|
|
42
66
|
country: string;
|
|
43
67
|
speech_to_text_source_language?: string;
|
|
44
68
|
};
|
|
69
|
+
export type SaveSpeechToTextSourceLanguageOptions = {
|
|
70
|
+
owner_id: string;
|
|
71
|
+
speech_to_text_source_language: string;
|
|
72
|
+
};
|
|
45
73
|
export interface PreferencesFXOperator {
|
|
46
74
|
createPrefPayment(opts: CreatePrefPaymentOptions): Promise<PrefPayment>;
|
|
47
75
|
replacePrefPayment(opts: ReplacePrefPaymentOptions): Promise<PrefPayment>;
|
|
48
76
|
createPrefClient(opts: CreatePrefClientOptions): Promise<PrefClient>;
|
|
49
77
|
replacePrefClient(opts: ReplacePrefClientOptions): Promise<PrefClient>;
|
|
78
|
+
getPrefClient(opts: GetPrefClientOptions): Promise<PrefClient>;
|
|
79
|
+
savePrefClient(opts: SavePrefClientOptions): Promise<PrefClient>;
|
|
50
80
|
createPrefEmployee(opts: CreatePrefEmployeeOptions): Promise<PrefEmployee>;
|
|
51
81
|
replacePrefEmployee(opts: ReplacePrefEmployeeOptions): Promise<PrefEmployee>;
|
|
82
|
+
getPrefEmployee(opts: GetPrefEmployeeOptions): Promise<PrefEmployee>;
|
|
83
|
+
savePrefEmployee(opts: SavePrefEmployeeOptions): Promise<PrefEmployee>;
|
|
52
84
|
createPrefCompany(opts: CreatePrefCompanyOptions): Promise<PrefCompany>;
|
|
53
85
|
replacePrefCompany(opts: ReplacePrefCompanyOptions): Promise<PrefCompany>;
|
|
86
|
+
getPrefCompany(opts: GetPrefCompanyOptions): Promise<PrefCompany>;
|
|
87
|
+
savePrefCompany(opts: SavePrefCompanyOptions): Promise<PrefCompany>;
|
|
54
88
|
createPrefVisibility(opts: CreatePrefVisibilityOptions): Promise<PrefVisibility>;
|
|
55
89
|
replacePrefVisibility(opts: ReplacePrefVisibilityOptions): Promise<PrefVisibility>;
|
|
56
90
|
createPrefLanguage(opts: CreatePrefLanguageOptions): Promise<PrefLanguage>;
|
|
57
91
|
replacePrefLanguage(opts: ReplacePrefLanguageOptions): Promise<PrefLanguage>;
|
|
92
|
+
getPrefLanguage(opts: GetPrefLanguageOptions): Promise<PrefLanguage>;
|
|
93
|
+
saveSpeechToTextSourceLanguage(opts: SaveSpeechToTextSourceLanguageOptions): Promise<PrefLanguage>;
|
|
58
94
|
createPrefNotif(opts: CreatePrefNotifOptions): Promise<PrefNotif>;
|
|
59
95
|
replacePrefNotif(opts: ReplacePrefNotifOptions): Promise<PrefNotif>;
|
|
60
96
|
createPrefEmail(opts: CreatePrefEmailOptions): Promise<PrefEmail>;
|
|
@@ -73,14 +109,22 @@ export declare class PreferencesFX implements PreferencesFXOperator {
|
|
|
73
109
|
replacePrefPayment(opts: ReplacePrefPaymentOptions): Promise<PrefPayment>;
|
|
74
110
|
createPrefClient(opts: CreatePrefClientOptions): Promise<PrefClient>;
|
|
75
111
|
replacePrefClient(opts: ReplacePrefClientOptions): Promise<PrefClient>;
|
|
112
|
+
getPrefClient(opts: GetPrefClientOptions): Promise<PrefClient>;
|
|
113
|
+
savePrefClient(opts: SavePrefClientOptions): Promise<PrefClient>;
|
|
76
114
|
createPrefEmployee(opts: CreatePrefEmployeeOptions): Promise<PrefEmployee>;
|
|
77
115
|
replacePrefEmployee(opts: ReplacePrefEmployeeOptions): Promise<PrefEmployee>;
|
|
116
|
+
getPrefEmployee(opts: GetPrefEmployeeOptions): Promise<PrefEmployee>;
|
|
117
|
+
savePrefEmployee(opts: SavePrefEmployeeOptions): Promise<PrefEmployee>;
|
|
78
118
|
createPrefCompany(opts: CreatePrefCompanyOptions): Promise<PrefCompany>;
|
|
79
119
|
replacePrefCompany(opts: ReplacePrefCompanyOptions): Promise<PrefCompany>;
|
|
120
|
+
getPrefCompany(opts: GetPrefCompanyOptions): Promise<PrefCompany>;
|
|
121
|
+
savePrefCompany(opts: SavePrefCompanyOptions): Promise<PrefCompany>;
|
|
80
122
|
createPrefVisibility(opts: CreatePrefVisibilityOptions): Promise<PrefVisibility>;
|
|
81
123
|
replacePrefVisibility(opts: ReplacePrefVisibilityOptions): Promise<PrefVisibility>;
|
|
82
124
|
createPrefLanguage(opts: CreatePrefLanguageOptions): Promise<PrefLanguage>;
|
|
83
125
|
replacePrefLanguage(opts: ReplacePrefLanguageOptions): Promise<PrefLanguage>;
|
|
126
|
+
getPrefLanguage(opts: GetPrefLanguageOptions): Promise<PrefLanguage>;
|
|
127
|
+
saveSpeechToTextSourceLanguage(opts: SaveSpeechToTextSourceLanguageOptions): Promise<PrefLanguage>;
|
|
84
128
|
createPrefNotif(opts: CreatePrefNotifOptions): Promise<PrefNotif>;
|
|
85
129
|
replacePrefNotif(opts: ReplacePrefNotifOptions): Promise<PrefNotif>;
|
|
86
130
|
createPrefEmail(opts: CreatePrefEmailOptions): Promise<PrefEmail>;
|
|
@@ -88,6 +132,10 @@ export declare class PreferencesFX implements PreferencesFXOperator {
|
|
|
88
132
|
createPrefTutorial(opts: CreatePrefTutorialOptions): Promise<PrefTutorial>;
|
|
89
133
|
replacePrefTutorial(opts: ReplacePrefTutorialOptions): Promise<PrefTutorial>;
|
|
90
134
|
ensurePrefLanguage(opts: EnsurePrefLanguageOptions): Promise<OperationResult>;
|
|
135
|
+
private queryPrefClient;
|
|
136
|
+
private queryPrefEmployee;
|
|
137
|
+
private queryPrefCompany;
|
|
138
|
+
private queryPrefLanguage;
|
|
91
139
|
private findPrefPayment;
|
|
92
140
|
private findPrefClient;
|
|
93
141
|
private findPrefEmployee;
|
|
@@ -4,6 +4,7 @@
|
|
|
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
|
import { queryParam } from "@fabriktor/client";
|
|
7
|
+
import { OwnerIDKey, } from "@fabriktor/schema";
|
|
7
8
|
import { errResolveFailed } from "../core/err.js";
|
|
8
9
|
import { requiredOperationID } from "../core/id.js";
|
|
9
10
|
const resourcePrefPayment = "pref_payment";
|
|
@@ -56,6 +57,19 @@ export class PreferencesFX {
|
|
|
56
57
|
await this.preferences.replaceOnePrefClient(opts);
|
|
57
58
|
return await this.findPrefClient(opts.id);
|
|
58
59
|
}
|
|
60
|
+
async getPrefClient(opts) {
|
|
61
|
+
const pref = await this.queryPrefClient(opts.owner_id);
|
|
62
|
+
if (pref === undefined) {
|
|
63
|
+
throw errResolveFailed({ resource: resourcePrefClient, msg: msgPrefClientMissing });
|
|
64
|
+
}
|
|
65
|
+
return pref;
|
|
66
|
+
}
|
|
67
|
+
async savePrefClient(opts) {
|
|
68
|
+
const input = { ...opts.in, is_default: false };
|
|
69
|
+
return opts.current.is_default
|
|
70
|
+
? await this.createPrefClient({ in: input })
|
|
71
|
+
: await this.replacePrefClient({ id: opts.current.id, in: input });
|
|
72
|
+
}
|
|
59
73
|
async createPrefEmployee(opts) {
|
|
60
74
|
const out = await this.preferences.insertOnePrefEmployee(opts);
|
|
61
75
|
const id = requiredOperationID(out, msgCreatedPrefEmployeeIDMissing);
|
|
@@ -65,6 +79,22 @@ export class PreferencesFX {
|
|
|
65
79
|
await this.preferences.replaceOnePrefEmployee(opts);
|
|
66
80
|
return await this.findPrefEmployee(opts.id);
|
|
67
81
|
}
|
|
82
|
+
async getPrefEmployee(opts) {
|
|
83
|
+
const pref = await this.queryPrefEmployee(opts.owner_id);
|
|
84
|
+
if (pref === undefined) {
|
|
85
|
+
throw errResolveFailed({
|
|
86
|
+
resource: resourcePrefEmployee,
|
|
87
|
+
msg: msgPrefEmployeeMissing,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
return pref;
|
|
91
|
+
}
|
|
92
|
+
async savePrefEmployee(opts) {
|
|
93
|
+
const input = { ...opts.in, is_default: false };
|
|
94
|
+
return opts.current.is_default
|
|
95
|
+
? await this.createPrefEmployee({ in: input })
|
|
96
|
+
: await this.replacePrefEmployee({ id: opts.current.id, in: input });
|
|
97
|
+
}
|
|
68
98
|
async createPrefCompany(opts) {
|
|
69
99
|
const out = await this.preferences.insertOnePrefCompany(opts);
|
|
70
100
|
const id = requiredOperationID(out, msgCreatedPrefCompanyIDMissing);
|
|
@@ -74,6 +104,22 @@ export class PreferencesFX {
|
|
|
74
104
|
await this.preferences.replaceOnePrefCompany(opts);
|
|
75
105
|
return await this.findPrefCompany(opts.id);
|
|
76
106
|
}
|
|
107
|
+
async getPrefCompany(opts) {
|
|
108
|
+
const pref = await this.queryPrefCompany(opts.owner_id);
|
|
109
|
+
if (pref === undefined) {
|
|
110
|
+
throw errResolveFailed({
|
|
111
|
+
resource: resourcePrefCompany,
|
|
112
|
+
msg: msgPrefCompanyMissing,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
return pref;
|
|
116
|
+
}
|
|
117
|
+
async savePrefCompany(opts) {
|
|
118
|
+
const input = { ...opts.in, is_default: false };
|
|
119
|
+
return opts.current.is_default
|
|
120
|
+
? await this.createPrefCompany({ in: input })
|
|
121
|
+
: await this.replacePrefCompany({ id: opts.current.id, in: input });
|
|
122
|
+
}
|
|
77
123
|
async createPrefVisibility(opts) {
|
|
78
124
|
const out = await this.preferences.insertOnePrefVisibility(opts);
|
|
79
125
|
const id = requiredOperationID(out, msgCreatedPrefVisibilityIDMissing);
|
|
@@ -92,6 +138,33 @@ export class PreferencesFX {
|
|
|
92
138
|
await this.preferences.replaceOnePrefLanguage(opts);
|
|
93
139
|
return await this.findPrefLanguage(opts.id);
|
|
94
140
|
}
|
|
141
|
+
async getPrefLanguage(opts) {
|
|
142
|
+
const pref_language = await this.queryPrefLanguage(opts.owner_id);
|
|
143
|
+
if (pref_language === undefined) {
|
|
144
|
+
throw errResolveFailed({
|
|
145
|
+
resource: resourcePrefLanguage,
|
|
146
|
+
msg: msgPrefLanguageMissing,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
return pref_language;
|
|
150
|
+
}
|
|
151
|
+
async saveSpeechToTextSourceLanguage(opts) {
|
|
152
|
+
const pref = await this.getPrefLanguage({ owner_id: opts.owner_id });
|
|
153
|
+
if (!pref.is_default &&
|
|
154
|
+
pref.speech_to_text_source_language === opts.speech_to_text_source_language) {
|
|
155
|
+
return pref;
|
|
156
|
+
}
|
|
157
|
+
const input = {
|
|
158
|
+
is_default: false,
|
|
159
|
+
country: pref.country,
|
|
160
|
+
language: pref.language,
|
|
161
|
+
speech_to_text_source_language: opts.speech_to_text_source_language,
|
|
162
|
+
};
|
|
163
|
+
if (pref.is_default) {
|
|
164
|
+
return await this.createPrefLanguage({ in: input });
|
|
165
|
+
}
|
|
166
|
+
return await this.replacePrefLanguage({ id: pref.id, in: input });
|
|
167
|
+
}
|
|
95
168
|
async createPrefNotif(opts) {
|
|
96
169
|
const out = await this.preferences.insertOnePrefNotif(opts);
|
|
97
170
|
const id = requiredOperationID(out, msgCreatedPrefNotifIDMissing);
|
|
@@ -120,18 +193,14 @@ export class PreferencesFX {
|
|
|
120
193
|
return await this.findPrefTutorial(opts.id);
|
|
121
194
|
}
|
|
122
195
|
async ensurePrefLanguage(opts) {
|
|
123
|
-
const
|
|
124
|
-
query: queryParam("owner_id", opts.owner_id),
|
|
125
|
-
});
|
|
126
|
-
const prefs = out.value ?? [];
|
|
127
|
-
const pref = prefs[0];
|
|
196
|
+
const pref = await this.getPrefLanguage({ owner_id: opts.owner_id });
|
|
128
197
|
const input = {
|
|
129
198
|
is_default: false,
|
|
130
199
|
language: opts.language,
|
|
131
200
|
country: opts.country,
|
|
132
|
-
speech_to_text_source_language: opts.speech_to_text_source_language ??
|
|
201
|
+
speech_to_text_source_language: opts.speech_to_text_source_language ?? pref.speech_to_text_source_language,
|
|
133
202
|
};
|
|
134
|
-
if (
|
|
203
|
+
if (pref.is_default) {
|
|
135
204
|
return await this.preferences.insertOnePrefLanguage({
|
|
136
205
|
in: input,
|
|
137
206
|
});
|
|
@@ -150,6 +219,30 @@ export class PreferencesFX {
|
|
|
150
219
|
in: input,
|
|
151
220
|
});
|
|
152
221
|
}
|
|
222
|
+
async queryPrefClient(owner_id) {
|
|
223
|
+
const out = await this.preferences.queryPrefClients({
|
|
224
|
+
query: queryParam(OwnerIDKey, owner_id),
|
|
225
|
+
});
|
|
226
|
+
return out.value?.[0];
|
|
227
|
+
}
|
|
228
|
+
async queryPrefEmployee(owner_id) {
|
|
229
|
+
const out = await this.preferences.queryPrefEmployees({
|
|
230
|
+
query: queryParam(OwnerIDKey, owner_id),
|
|
231
|
+
});
|
|
232
|
+
return out.value?.[0];
|
|
233
|
+
}
|
|
234
|
+
async queryPrefCompany(owner_id) {
|
|
235
|
+
const out = await this.preferences.queryPrefCompanies({
|
|
236
|
+
query: queryParam(OwnerIDKey, owner_id),
|
|
237
|
+
});
|
|
238
|
+
return out.value?.[0];
|
|
239
|
+
}
|
|
240
|
+
async queryPrefLanguage(owner_id) {
|
|
241
|
+
const out = await this.preferences.queryPrefLanguages({
|
|
242
|
+
query: queryParam(OwnerIDKey, owner_id),
|
|
243
|
+
});
|
|
244
|
+
return out.value?.[0];
|
|
245
|
+
}
|
|
153
246
|
async findPrefPayment(id) {
|
|
154
247
|
const out = await this.preferences.findOnePrefPayment({
|
|
155
248
|
id,
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ProcessesOperator, SpeechToTextOptions } from "@fabriktor/client";
|
|
2
|
+
import type { PrefLanguage } from "@fabriktor/schema";
|
|
3
|
+
import type { PreferencesFXOperator } from "../preferences/preferences.js";
|
|
4
|
+
export type SpeechToTextAndSaveSourceLanguageOptions = {
|
|
5
|
+
owner_id: string;
|
|
6
|
+
speech_to_text: SpeechToTextOptions;
|
|
7
|
+
};
|
|
8
|
+
export type SpeechToTextAndSaveSourceLanguageResult = {
|
|
9
|
+
transcription: string;
|
|
10
|
+
preference: PrefLanguage;
|
|
11
|
+
};
|
|
12
|
+
export type ProcessesFXOptions = {
|
|
13
|
+
processes: ProcessesOperator;
|
|
14
|
+
preferences_fx: PreferencesFXOperator;
|
|
15
|
+
};
|
|
16
|
+
export interface ProcessesFXOperator {
|
|
17
|
+
speechToText(opts: SpeechToTextOptions): Promise<string>;
|
|
18
|
+
speechToTextAndSaveSourceLanguage(opts: SpeechToTextAndSaveSourceLanguageOptions): Promise<SpeechToTextAndSaveSourceLanguageResult>;
|
|
19
|
+
}
|
|
20
|
+
export declare class ProcessesFX implements ProcessesFXOperator {
|
|
21
|
+
private processes;
|
|
22
|
+
private preferences_fx;
|
|
23
|
+
constructor(opts: ProcessesFXOptions);
|
|
24
|
+
speechToText(opts: SpeechToTextOptions): Promise<string>;
|
|
25
|
+
speechToTextAndSaveSourceLanguage(opts: SpeechToTextAndSaveSourceLanguageOptions): Promise<SpeechToTextAndSaveSourceLanguageResult>;
|
|
26
|
+
}
|
|
27
|
+
export declare function newProcessesFX(opts: ProcessesFXOptions): ProcessesFX;
|
|
@@ -0,0 +1,38 @@
|
|
|
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 { errResolveFailed } from "../core/err.js";
|
|
7
|
+
const resourceSpeechToTextTranscription = "speech_to_text_transcription";
|
|
8
|
+
const msgSpeechToTextTranscriptionMissing = "Speech-to-text response did not include a transcription.";
|
|
9
|
+
export class ProcessesFX {
|
|
10
|
+
processes;
|
|
11
|
+
preferences_fx;
|
|
12
|
+
constructor(opts) {
|
|
13
|
+
this.processes = opts.processes;
|
|
14
|
+
this.preferences_fx = opts.preferences_fx;
|
|
15
|
+
}
|
|
16
|
+
async speechToText(opts) {
|
|
17
|
+
const out = await this.processes.speechToText(opts);
|
|
18
|
+
const transcription = out.value?.transcriptions.at(0)?.text.trim() ?? "";
|
|
19
|
+
if (transcription === "") {
|
|
20
|
+
throw errResolveFailed({
|
|
21
|
+
resource: resourceSpeechToTextTranscription,
|
|
22
|
+
msg: msgSpeechToTextTranscriptionMissing,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return transcription;
|
|
26
|
+
}
|
|
27
|
+
async speechToTextAndSaveSourceLanguage(opts) {
|
|
28
|
+
const preference = await this.preferences_fx.saveSpeechToTextSourceLanguage({
|
|
29
|
+
owner_id: opts.owner_id,
|
|
30
|
+
speech_to_text_source_language: opts.speech_to_text.audio_locale,
|
|
31
|
+
});
|
|
32
|
+
const transcription = await this.speechToText(opts.speech_to_text);
|
|
33
|
+
return { transcription, preference };
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export function newProcessesFX(opts) {
|
|
37
|
+
return new ProcessesFX(opts);
|
|
38
|
+
}
|