@fabriktor/fx 0.0.66 → 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.
|
@@ -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,6 +36,27 @@ 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
|
+
};
|
|
39
60
|
export type GetPrefLanguageOptions = {
|
|
40
61
|
owner_id: string;
|
|
41
62
|
};
|
|
@@ -54,10 +75,16 @@ export interface PreferencesFXOperator {
|
|
|
54
75
|
replacePrefPayment(opts: ReplacePrefPaymentOptions): Promise<PrefPayment>;
|
|
55
76
|
createPrefClient(opts: CreatePrefClientOptions): Promise<PrefClient>;
|
|
56
77
|
replacePrefClient(opts: ReplacePrefClientOptions): Promise<PrefClient>;
|
|
78
|
+
getPrefClient(opts: GetPrefClientOptions): Promise<PrefClient>;
|
|
79
|
+
savePrefClient(opts: SavePrefClientOptions): Promise<PrefClient>;
|
|
57
80
|
createPrefEmployee(opts: CreatePrefEmployeeOptions): Promise<PrefEmployee>;
|
|
58
81
|
replacePrefEmployee(opts: ReplacePrefEmployeeOptions): Promise<PrefEmployee>;
|
|
82
|
+
getPrefEmployee(opts: GetPrefEmployeeOptions): Promise<PrefEmployee>;
|
|
83
|
+
savePrefEmployee(opts: SavePrefEmployeeOptions): Promise<PrefEmployee>;
|
|
59
84
|
createPrefCompany(opts: CreatePrefCompanyOptions): Promise<PrefCompany>;
|
|
60
85
|
replacePrefCompany(opts: ReplacePrefCompanyOptions): Promise<PrefCompany>;
|
|
86
|
+
getPrefCompany(opts: GetPrefCompanyOptions): Promise<PrefCompany>;
|
|
87
|
+
savePrefCompany(opts: SavePrefCompanyOptions): Promise<PrefCompany>;
|
|
61
88
|
createPrefVisibility(opts: CreatePrefVisibilityOptions): Promise<PrefVisibility>;
|
|
62
89
|
replacePrefVisibility(opts: ReplacePrefVisibilityOptions): Promise<PrefVisibility>;
|
|
63
90
|
createPrefLanguage(opts: CreatePrefLanguageOptions): Promise<PrefLanguage>;
|
|
@@ -82,10 +109,16 @@ export declare class PreferencesFX implements PreferencesFXOperator {
|
|
|
82
109
|
replacePrefPayment(opts: ReplacePrefPaymentOptions): Promise<PrefPayment>;
|
|
83
110
|
createPrefClient(opts: CreatePrefClientOptions): Promise<PrefClient>;
|
|
84
111
|
replacePrefClient(opts: ReplacePrefClientOptions): Promise<PrefClient>;
|
|
112
|
+
getPrefClient(opts: GetPrefClientOptions): Promise<PrefClient>;
|
|
113
|
+
savePrefClient(opts: SavePrefClientOptions): Promise<PrefClient>;
|
|
85
114
|
createPrefEmployee(opts: CreatePrefEmployeeOptions): Promise<PrefEmployee>;
|
|
86
115
|
replacePrefEmployee(opts: ReplacePrefEmployeeOptions): Promise<PrefEmployee>;
|
|
116
|
+
getPrefEmployee(opts: GetPrefEmployeeOptions): Promise<PrefEmployee>;
|
|
117
|
+
savePrefEmployee(opts: SavePrefEmployeeOptions): Promise<PrefEmployee>;
|
|
87
118
|
createPrefCompany(opts: CreatePrefCompanyOptions): Promise<PrefCompany>;
|
|
88
119
|
replacePrefCompany(opts: ReplacePrefCompanyOptions): Promise<PrefCompany>;
|
|
120
|
+
getPrefCompany(opts: GetPrefCompanyOptions): Promise<PrefCompany>;
|
|
121
|
+
savePrefCompany(opts: SavePrefCompanyOptions): Promise<PrefCompany>;
|
|
89
122
|
createPrefVisibility(opts: CreatePrefVisibilityOptions): Promise<PrefVisibility>;
|
|
90
123
|
replacePrefVisibility(opts: ReplacePrefVisibilityOptions): Promise<PrefVisibility>;
|
|
91
124
|
createPrefLanguage(opts: CreatePrefLanguageOptions): Promise<PrefLanguage>;
|
|
@@ -99,6 +132,9 @@ export declare class PreferencesFX implements PreferencesFXOperator {
|
|
|
99
132
|
createPrefTutorial(opts: CreatePrefTutorialOptions): Promise<PrefTutorial>;
|
|
100
133
|
replacePrefTutorial(opts: ReplacePrefTutorialOptions): Promise<PrefTutorial>;
|
|
101
134
|
ensurePrefLanguage(opts: EnsurePrefLanguageOptions): Promise<OperationResult>;
|
|
135
|
+
private queryPrefClient;
|
|
136
|
+
private queryPrefEmployee;
|
|
137
|
+
private queryPrefCompany;
|
|
102
138
|
private queryPrefLanguage;
|
|
103
139
|
private findPrefPayment;
|
|
104
140
|
private findPrefClient;
|
|
@@ -57,6 +57,19 @@ export class PreferencesFX {
|
|
|
57
57
|
await this.preferences.replaceOnePrefClient(opts);
|
|
58
58
|
return await this.findPrefClient(opts.id);
|
|
59
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
|
+
}
|
|
60
73
|
async createPrefEmployee(opts) {
|
|
61
74
|
const out = await this.preferences.insertOnePrefEmployee(opts);
|
|
62
75
|
const id = requiredOperationID(out, msgCreatedPrefEmployeeIDMissing);
|
|
@@ -66,6 +79,22 @@ export class PreferencesFX {
|
|
|
66
79
|
await this.preferences.replaceOnePrefEmployee(opts);
|
|
67
80
|
return await this.findPrefEmployee(opts.id);
|
|
68
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
|
+
}
|
|
69
98
|
async createPrefCompany(opts) {
|
|
70
99
|
const out = await this.preferences.insertOnePrefCompany(opts);
|
|
71
100
|
const id = requiredOperationID(out, msgCreatedPrefCompanyIDMissing);
|
|
@@ -75,6 +104,22 @@ export class PreferencesFX {
|
|
|
75
104
|
await this.preferences.replaceOnePrefCompany(opts);
|
|
76
105
|
return await this.findPrefCompany(opts.id);
|
|
77
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
|
+
}
|
|
78
123
|
async createPrefVisibility(opts) {
|
|
79
124
|
const out = await this.preferences.insertOnePrefVisibility(opts);
|
|
80
125
|
const id = requiredOperationID(out, msgCreatedPrefVisibilityIDMissing);
|
|
@@ -148,14 +193,14 @@ export class PreferencesFX {
|
|
|
148
193
|
return await this.findPrefTutorial(opts.id);
|
|
149
194
|
}
|
|
150
195
|
async ensurePrefLanguage(opts) {
|
|
151
|
-
const pref = await this.
|
|
196
|
+
const pref = await this.getPrefLanguage({ owner_id: opts.owner_id });
|
|
152
197
|
const input = {
|
|
153
198
|
is_default: false,
|
|
154
199
|
language: opts.language,
|
|
155
200
|
country: opts.country,
|
|
156
|
-
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,
|
|
157
202
|
};
|
|
158
|
-
if (
|
|
203
|
+
if (pref.is_default) {
|
|
159
204
|
return await this.preferences.insertOnePrefLanguage({
|
|
160
205
|
in: input,
|
|
161
206
|
});
|
|
@@ -174,6 +219,24 @@ export class PreferencesFX {
|
|
|
174
219
|
in: input,
|
|
175
220
|
});
|
|
176
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
|
+
}
|
|
177
240
|
async queryPrefLanguage(owner_id) {
|
|
178
241
|
const out = await this.preferences.queryPrefLanguages({
|
|
179
242
|
query: queryParam(OwnerIDKey, owner_id),
|