@fabriktor/fx 0.0.66 → 0.0.68
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/payments/payments.d.ts +20 -0
- package/dist/src/payments/payments.js +57 -0
- package/dist/src/preferences/preferences.d.ts +37 -1
- package/dist/src/preferences/preferences.js +66 -3
- package/dist/src/privacy/privacy.d.ts +18 -2
- package/dist/src/privacy/privacy.js +36 -18
- package/package.json +1 -1
|
@@ -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),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type PrivacyExport, type PrivacyOperator } from "@fabriktor/client";
|
|
2
2
|
import { type AccountLock, type DeletionRequest } from "@fabriktor/schema";
|
|
3
3
|
type DeletionRequestInsertOptions = Parameters<PrivacyOperator["insertOneDeletionRequest"]>[0];
|
|
4
4
|
type DeletionRequestReplaceOptions = Parameters<PrivacyOperator["replaceOneDeletionRequest"]>[0];
|
|
@@ -11,8 +11,17 @@ export type ReplaceAccountLockOptions = AccountLockReplaceOptions;
|
|
|
11
11
|
export type PrivacyFXOptions = {
|
|
12
12
|
privacy: PrivacyOperator;
|
|
13
13
|
};
|
|
14
|
-
export type
|
|
14
|
+
export type GetAccountLockOptions = {
|
|
15
15
|
owner_id: string;
|
|
16
|
+
};
|
|
17
|
+
export type RequestAccountDeletionOptions = CreateDeletionRequestOptions & {
|
|
18
|
+
owner_id: string;
|
|
19
|
+
};
|
|
20
|
+
export type AccountDeletion = {
|
|
21
|
+
request: DeletionRequest;
|
|
22
|
+
lock: AccountLock;
|
|
23
|
+
};
|
|
24
|
+
export type WatchAccountLockOptions = GetAccountLockOptions & {
|
|
16
25
|
on_lock: (lock: AccountLock) => void;
|
|
17
26
|
on_error?: (err: unknown) => void;
|
|
18
27
|
};
|
|
@@ -20,18 +29,25 @@ export type StopAccountLockWatch = () => void;
|
|
|
20
29
|
export interface PrivacyFXOperator {
|
|
21
30
|
createDeletionRequest(opts: CreateDeletionRequestOptions): Promise<DeletionRequest>;
|
|
22
31
|
replaceDeletionRequest(opts: ReplaceDeletionRequestOptions): Promise<DeletionRequest>;
|
|
32
|
+
requestAccountDeletion(opts: RequestAccountDeletionOptions): Promise<AccountDeletion>;
|
|
23
33
|
createAccountLock(opts: CreateAccountLockOptions): Promise<AccountLock>;
|
|
24
34
|
replaceAccountLock(opts: ReplaceAccountLockOptions): Promise<AccountLock>;
|
|
35
|
+
getAccountLock(opts: GetAccountLockOptions): Promise<AccountLock | undefined>;
|
|
25
36
|
watchAccountLock(opts: WatchAccountLockOptions): Promise<StopAccountLockWatch>;
|
|
37
|
+
exportData(): Promise<PrivacyExport>;
|
|
26
38
|
}
|
|
27
39
|
export declare class PrivacyFX implements PrivacyFXOperator {
|
|
28
40
|
private privacy;
|
|
29
41
|
constructor(opts: PrivacyFXOptions);
|
|
30
42
|
createDeletionRequest(opts: CreateDeletionRequestOptions): Promise<DeletionRequest>;
|
|
31
43
|
replaceDeletionRequest(opts: ReplaceDeletionRequestOptions): Promise<DeletionRequest>;
|
|
44
|
+
requestAccountDeletion(opts: RequestAccountDeletionOptions): Promise<AccountDeletion>;
|
|
32
45
|
createAccountLock(opts: CreateAccountLockOptions): Promise<AccountLock>;
|
|
33
46
|
replaceAccountLock(opts: ReplaceAccountLockOptions): Promise<AccountLock>;
|
|
47
|
+
getAccountLock(opts: GetAccountLockOptions): Promise<AccountLock | undefined>;
|
|
34
48
|
watchAccountLock(opts: WatchAccountLockOptions): Promise<StopAccountLockWatch>;
|
|
49
|
+
exportData(): Promise<PrivacyExport>;
|
|
50
|
+
private requiredOwnerID;
|
|
35
51
|
private resolveDeletionRequest;
|
|
36
52
|
private resolveAccountLock;
|
|
37
53
|
private findOwnerAccountLock;
|
|
@@ -3,8 +3,9 @@
|
|
|
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 {
|
|
7
|
-
import {
|
|
6
|
+
import { queryParam, } from "@fabriktor/client";
|
|
7
|
+
import { OwnerIDKey, ZeroID, } from "@fabriktor/schema";
|
|
8
|
+
import { errRequired, errResolveFailed } from "../core/err.js";
|
|
8
9
|
import { requiredOperationID } from "../core/id.js";
|
|
9
10
|
const accountLockIntervalMs = 60 * 60 * 1000;
|
|
10
11
|
const resourceDeletionRequest = "deletion_request";
|
|
@@ -14,6 +15,7 @@ const msgCreatedDeletionRequestIDMissing = "Created deletion request response di
|
|
|
14
15
|
const msgDeletionRequestMissing = "Deletion request could not be resolved after the mutation.";
|
|
15
16
|
const msgCreatedAccountLockIDMissing = "Created account lock response did not contain an ID.";
|
|
16
17
|
const msgAccountLockMissing = "Account lock could not be resolved after the mutation.";
|
|
18
|
+
const msgDeletionAccountLockMissing = "Account lock could not be resolved after the deletion request.";
|
|
17
19
|
export class PrivacyFX {
|
|
18
20
|
privacy;
|
|
19
21
|
constructor(opts) {
|
|
@@ -28,6 +30,18 @@ export class PrivacyFX {
|
|
|
28
30
|
await this.privacy.replaceOneDeletionRequest(opts);
|
|
29
31
|
return await this.resolveDeletionRequest(opts.id);
|
|
30
32
|
}
|
|
33
|
+
async requestAccountDeletion(opts) {
|
|
34
|
+
const owner_id = this.requiredOwnerID(opts.owner_id);
|
|
35
|
+
const request = await this.createDeletionRequest({ in: opts.in });
|
|
36
|
+
const lock = await this.findOwnerAccountLock(owner_id);
|
|
37
|
+
if (lock === undefined) {
|
|
38
|
+
throw errResolveFailed({
|
|
39
|
+
resource: resourceAccountLock,
|
|
40
|
+
msg: msgDeletionAccountLockMissing,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
return { request, lock };
|
|
44
|
+
}
|
|
31
45
|
async createAccountLock(opts) {
|
|
32
46
|
const out = await this.privacy.insertOneAccountLock(opts);
|
|
33
47
|
const id = requiredOperationID(out, msgCreatedAccountLockIDMissing);
|
|
@@ -37,14 +51,11 @@ export class PrivacyFX {
|
|
|
37
51
|
await this.privacy.replaceOneAccountLock(opts);
|
|
38
52
|
return await this.resolveAccountLock(opts.id);
|
|
39
53
|
}
|
|
54
|
+
async getAccountLock(opts) {
|
|
55
|
+
return await this.findOwnerAccountLock(this.requiredOwnerID(opts.owner_id));
|
|
56
|
+
}
|
|
40
57
|
async watchAccountLock(opts) {
|
|
41
|
-
const owner_id = opts.owner_id
|
|
42
|
-
if (owner_id === "" || owner_id === ZeroID) {
|
|
43
|
-
throw errRequired({
|
|
44
|
-
field: "owner_id",
|
|
45
|
-
msg: msgOwnerIDRequired,
|
|
46
|
-
});
|
|
47
|
-
}
|
|
58
|
+
const owner_id = this.requiredOwnerID(opts.owner_id);
|
|
48
59
|
const initial_lock = await this.findOwnerAccountLock(owner_id);
|
|
49
60
|
if (initial_lock !== undefined) {
|
|
50
61
|
opts.on_lock(initial_lock);
|
|
@@ -89,10 +100,21 @@ export class PrivacyFX {
|
|
|
89
100
|
}
|
|
90
101
|
};
|
|
91
102
|
}
|
|
103
|
+
async exportData() {
|
|
104
|
+
return await this.privacy.exportData();
|
|
105
|
+
}
|
|
106
|
+
requiredOwnerID(owner_id) {
|
|
107
|
+
const id = owner_id.trim();
|
|
108
|
+
if (id === "" || id === ZeroID) {
|
|
109
|
+
throw errRequired({
|
|
110
|
+
field: "owner_id",
|
|
111
|
+
msg: msgOwnerIDRequired,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
return id;
|
|
115
|
+
}
|
|
92
116
|
async resolveDeletionRequest(id) {
|
|
93
|
-
const out = await this.privacy.findOneDeletionRequest({
|
|
94
|
-
id,
|
|
95
|
-
});
|
|
117
|
+
const out = await this.privacy.findOneDeletionRequest({ id });
|
|
96
118
|
const deletion_request = out.value;
|
|
97
119
|
if (deletion_request === undefined) {
|
|
98
120
|
throw errResolveFailed({
|
|
@@ -103,9 +125,7 @@ export class PrivacyFX {
|
|
|
103
125
|
return deletion_request;
|
|
104
126
|
}
|
|
105
127
|
async resolveAccountLock(id) {
|
|
106
|
-
const out = await this.privacy.findOneAccountLock({
|
|
107
|
-
id,
|
|
108
|
-
});
|
|
128
|
+
const out = await this.privacy.findOneAccountLock({ id });
|
|
109
129
|
const account_lock = out.value;
|
|
110
130
|
if (account_lock === undefined) {
|
|
111
131
|
throw errResolveFailed({
|
|
@@ -117,9 +137,7 @@ export class PrivacyFX {
|
|
|
117
137
|
}
|
|
118
138
|
async findOwnerAccountLock(owner_id) {
|
|
119
139
|
const out = await this.privacy.queryAccountLocks({
|
|
120
|
-
query:
|
|
121
|
-
owner_id,
|
|
122
|
-
},
|
|
140
|
+
query: queryParam(OwnerIDKey, owner_id),
|
|
123
141
|
});
|
|
124
142
|
return out.value?.[0];
|
|
125
143
|
}
|