@fabriktor/fx 0.0.39 → 0.0.40
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 +164 -1
- package/dist/src/billable/billable.js +436 -0
- package/dist/src/calls/calls.d.ts +11 -0
- package/dist/src/calls/calls.js +26 -0
- package/dist/src/chat/chat.d.ts +22 -1
- package/dist/src/chat/chat.js +33 -25
- package/dist/src/contacts/contacts.d.ts +12 -2
- package/dist/src/contacts/contacts.js +33 -7
- package/dist/src/core/id.d.ts +3 -0
- package/dist/src/core/id.js +24 -0
- package/dist/src/feed/feed.d.ts +39 -3
- package/dist/src/feed/feed.js +85 -7
- package/dist/src/fulfillments/fulfillments.d.ts +32 -0
- package/dist/src/fulfillments/fulfillments.js +54 -0
- package/dist/src/fx.d.ts +5 -1
- package/dist/src/fx.js +11 -1
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +2 -0
- package/dist/src/jobs/jobs.d.ts +52 -4
- package/dist/src/jobs/jobs.js +120 -9
- package/dist/src/marketplace/marketplace.d.ts +29 -1
- package/dist/src/marketplace/marketplace.js +64 -1
- package/dist/src/memos/memos.js +4 -28
- package/dist/src/payments/payments.d.ts +112 -1
- package/dist/src/payments/payments.js +291 -15
- package/dist/src/payrolls/payrolls.d.ts +134 -1
- package/dist/src/payrolls/payrolls.js +364 -0
- package/dist/src/preferences/preferences.d.ts +83 -1
- package/dist/src/preferences/preferences.js +227 -0
- package/dist/src/privacy/privacy.d.ts +21 -2
- package/dist/src/privacy/privacy.js +56 -5
- package/dist/src/routes/routes.d.ts +63 -3
- package/dist/src/routes/routes.js +151 -1
- package/dist/src/timesheets/timesheets.d.ts +11 -1
- package/dist/src/timesheets/timesheets.js +39 -1
- package/package.json +2 -2
|
@@ -4,11 +4,121 @@
|
|
|
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 { errResolveFailed } from "../core/err.js";
|
|
8
|
+
import { requiredOperationID } from "../core/id.js";
|
|
9
|
+
const resourcePrefPayment = "pref_payment";
|
|
10
|
+
const msgCreatedPrefPaymentIDMissing = "Created preference payment response did not contain an ID.";
|
|
11
|
+
const msgPrefPaymentMissing = "Preference payment could not be resolved after the mutation.";
|
|
12
|
+
const resourcePrefClient = "pref_client";
|
|
13
|
+
const msgCreatedPrefClientIDMissing = "Created client preference response did not contain an ID.";
|
|
14
|
+
const msgPrefClientMissing = "Client preference could not be resolved after the mutation.";
|
|
15
|
+
const resourcePrefEmployee = "pref_employee";
|
|
16
|
+
const msgCreatedPrefEmployeeIDMissing = "Created employee preference response did not contain an ID.";
|
|
17
|
+
const msgPrefEmployeeMissing = "Employee preference could not be resolved after the mutation.";
|
|
18
|
+
const resourcePrefCompany = "pref_company";
|
|
19
|
+
const msgCreatedPrefCompanyIDMissing = "Created company preference response did not contain an ID.";
|
|
20
|
+
const msgPrefCompanyMissing = "Company preference could not be resolved after the mutation.";
|
|
21
|
+
const resourcePrefVisibility = "pref_visibility";
|
|
22
|
+
const msgCreatedPrefVisibilityIDMissing = "Created visibility preference response did not contain an ID.";
|
|
23
|
+
const msgPrefVisibilityMissing = "Visibility preference could not be resolved after the mutation.";
|
|
24
|
+
const resourcePrefLanguage = "pref_language";
|
|
25
|
+
const msgCreatedPrefLanguageIDMissing = "Created language preference response did not contain an ID.";
|
|
26
|
+
const msgPrefLanguageMissing = "Language preference could not be resolved after the mutation.";
|
|
27
|
+
const resourcePrefNotif = "pref_notif";
|
|
28
|
+
const msgCreatedPrefNotifIDMissing = "Created notification preference response did not contain an ID.";
|
|
29
|
+
const msgPrefNotifMissing = "Notification preference could not be resolved after the mutation.";
|
|
30
|
+
const resourcePrefEmail = "pref_email";
|
|
31
|
+
const msgCreatedPrefEmailIDMissing = "Created email preference response did not contain an ID.";
|
|
32
|
+
const msgPrefEmailMissing = "Email preference could not be resolved after the mutation.";
|
|
33
|
+
const resourcePrefTutorial = "pref_tutorial";
|
|
34
|
+
const msgCreatedPrefTutorialIDMissing = "Created tutorial preference response did not contain an ID.";
|
|
35
|
+
const msgPrefTutorialMissing = "Tutorial preference could not be resolved after the mutation.";
|
|
7
36
|
export class PreferencesFX {
|
|
8
37
|
preferences;
|
|
9
38
|
constructor(opts) {
|
|
10
39
|
this.preferences = opts.preferences;
|
|
11
40
|
}
|
|
41
|
+
async createPrefPayment(opts) {
|
|
42
|
+
const out = await this.preferences.insertOnePrefPayment(opts);
|
|
43
|
+
const id = requiredOperationID(out, msgCreatedPrefPaymentIDMissing);
|
|
44
|
+
return await this.findPrefPayment(id);
|
|
45
|
+
}
|
|
46
|
+
async replacePrefPayment(opts) {
|
|
47
|
+
await this.preferences.replaceOnePrefPayment(opts);
|
|
48
|
+
return await this.findPrefPayment(opts.id);
|
|
49
|
+
}
|
|
50
|
+
async createPrefClient(opts) {
|
|
51
|
+
const out = await this.preferences.insertOnePrefClient(opts);
|
|
52
|
+
const id = requiredOperationID(out, msgCreatedPrefClientIDMissing);
|
|
53
|
+
return await this.findPrefClient(id);
|
|
54
|
+
}
|
|
55
|
+
async replacePrefClient(opts) {
|
|
56
|
+
await this.preferences.replaceOnePrefClient(opts);
|
|
57
|
+
return await this.findPrefClient(opts.id);
|
|
58
|
+
}
|
|
59
|
+
async createPrefEmployee(opts) {
|
|
60
|
+
const out = await this.preferences.insertOnePrefEmployee(opts);
|
|
61
|
+
const id = requiredOperationID(out, msgCreatedPrefEmployeeIDMissing);
|
|
62
|
+
return await this.findPrefEmployee(id);
|
|
63
|
+
}
|
|
64
|
+
async replacePrefEmployee(opts) {
|
|
65
|
+
await this.preferences.replaceOnePrefEmployee(opts);
|
|
66
|
+
return await this.findPrefEmployee(opts.id);
|
|
67
|
+
}
|
|
68
|
+
async createPrefCompany(opts) {
|
|
69
|
+
const out = await this.preferences.insertOnePrefCompany(opts);
|
|
70
|
+
const id = requiredOperationID(out, msgCreatedPrefCompanyIDMissing);
|
|
71
|
+
return await this.findPrefCompany(id);
|
|
72
|
+
}
|
|
73
|
+
async replacePrefCompany(opts) {
|
|
74
|
+
await this.preferences.replaceOnePrefCompany(opts);
|
|
75
|
+
return await this.findPrefCompany(opts.id);
|
|
76
|
+
}
|
|
77
|
+
async createPrefVisibility(opts) {
|
|
78
|
+
const out = await this.preferences.insertOnePrefVisibility(opts);
|
|
79
|
+
const id = requiredOperationID(out, msgCreatedPrefVisibilityIDMissing);
|
|
80
|
+
return await this.findPrefVisibility(id);
|
|
81
|
+
}
|
|
82
|
+
async replacePrefVisibility(opts) {
|
|
83
|
+
await this.preferences.replaceOnePrefVisibility(opts);
|
|
84
|
+
return await this.findPrefVisibility(opts.id);
|
|
85
|
+
}
|
|
86
|
+
async createPrefLanguage(opts) {
|
|
87
|
+
const out = await this.preferences.insertOnePrefLanguage(opts);
|
|
88
|
+
const id = requiredOperationID(out, msgCreatedPrefLanguageIDMissing);
|
|
89
|
+
return await this.findPrefLanguage(id);
|
|
90
|
+
}
|
|
91
|
+
async replacePrefLanguage(opts) {
|
|
92
|
+
await this.preferences.replaceOnePrefLanguage(opts);
|
|
93
|
+
return await this.findPrefLanguage(opts.id);
|
|
94
|
+
}
|
|
95
|
+
async createPrefNotif(opts) {
|
|
96
|
+
const out = await this.preferences.insertOnePrefNotif(opts);
|
|
97
|
+
const id = requiredOperationID(out, msgCreatedPrefNotifIDMissing);
|
|
98
|
+
return await this.findPrefNotif(id);
|
|
99
|
+
}
|
|
100
|
+
async replacePrefNotif(opts) {
|
|
101
|
+
await this.preferences.replaceOnePrefNotif(opts);
|
|
102
|
+
return await this.findPrefNotif(opts.id);
|
|
103
|
+
}
|
|
104
|
+
async createPrefEmail(opts) {
|
|
105
|
+
const out = await this.preferences.insertOnePrefEmail(opts);
|
|
106
|
+
const id = requiredOperationID(out, msgCreatedPrefEmailIDMissing);
|
|
107
|
+
return await this.findPrefEmail(id);
|
|
108
|
+
}
|
|
109
|
+
async replacePrefEmail(opts) {
|
|
110
|
+
await this.preferences.replaceOnePrefEmail(opts);
|
|
111
|
+
return await this.findPrefEmail(opts.id);
|
|
112
|
+
}
|
|
113
|
+
async createPrefTutorial(opts) {
|
|
114
|
+
const out = await this.preferences.insertOnePrefTutorial(opts);
|
|
115
|
+
const id = requiredOperationID(out, msgCreatedPrefTutorialIDMissing);
|
|
116
|
+
return await this.findPrefTutorial(id);
|
|
117
|
+
}
|
|
118
|
+
async replacePrefTutorial(opts) {
|
|
119
|
+
await this.preferences.replaceOnePrefTutorial(opts);
|
|
120
|
+
return await this.findPrefTutorial(opts.id);
|
|
121
|
+
}
|
|
12
122
|
async ensurePrefLanguage(opts) {
|
|
13
123
|
const out = await this.preferences.queryPrefLanguages({
|
|
14
124
|
query: queryParam("owner_id", opts.owner_id),
|
|
@@ -40,6 +150,123 @@ export class PreferencesFX {
|
|
|
40
150
|
in: input,
|
|
41
151
|
});
|
|
42
152
|
}
|
|
153
|
+
async findPrefPayment(id) {
|
|
154
|
+
const out = await this.preferences.findOnePrefPayment({
|
|
155
|
+
id,
|
|
156
|
+
});
|
|
157
|
+
const pref_payment = out.value;
|
|
158
|
+
if (pref_payment === undefined) {
|
|
159
|
+
throw errResolveFailed({
|
|
160
|
+
resource: resourcePrefPayment,
|
|
161
|
+
msg: msgPrefPaymentMissing,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
return pref_payment;
|
|
165
|
+
}
|
|
166
|
+
async findPrefClient(id) {
|
|
167
|
+
const out = await this.preferences.findOnePrefClient({
|
|
168
|
+
id,
|
|
169
|
+
});
|
|
170
|
+
const pref_client = out.value;
|
|
171
|
+
if (pref_client === undefined) {
|
|
172
|
+
throw errResolveFailed({
|
|
173
|
+
resource: resourcePrefClient,
|
|
174
|
+
msg: msgPrefClientMissing,
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
return pref_client;
|
|
178
|
+
}
|
|
179
|
+
async findPrefEmployee(id) {
|
|
180
|
+
const out = await this.preferences.findOnePrefEmployee({
|
|
181
|
+
id,
|
|
182
|
+
});
|
|
183
|
+
const pref_employee = out.value;
|
|
184
|
+
if (pref_employee === undefined) {
|
|
185
|
+
throw errResolveFailed({
|
|
186
|
+
resource: resourcePrefEmployee,
|
|
187
|
+
msg: msgPrefEmployeeMissing,
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
return pref_employee;
|
|
191
|
+
}
|
|
192
|
+
async findPrefCompany(id) {
|
|
193
|
+
const out = await this.preferences.findOnePrefCompany({
|
|
194
|
+
id,
|
|
195
|
+
});
|
|
196
|
+
const pref_company = out.value;
|
|
197
|
+
if (pref_company === undefined) {
|
|
198
|
+
throw errResolveFailed({
|
|
199
|
+
resource: resourcePrefCompany,
|
|
200
|
+
msg: msgPrefCompanyMissing,
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
return pref_company;
|
|
204
|
+
}
|
|
205
|
+
async findPrefVisibility(id) {
|
|
206
|
+
const out = await this.preferences.findOnePrefVisibility({
|
|
207
|
+
id,
|
|
208
|
+
});
|
|
209
|
+
const pref_visibility = out.value;
|
|
210
|
+
if (pref_visibility === undefined) {
|
|
211
|
+
throw errResolveFailed({
|
|
212
|
+
resource: resourcePrefVisibility,
|
|
213
|
+
msg: msgPrefVisibilityMissing,
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
return pref_visibility;
|
|
217
|
+
}
|
|
218
|
+
async findPrefLanguage(id) {
|
|
219
|
+
const out = await this.preferences.findOnePrefLanguage({
|
|
220
|
+
id,
|
|
221
|
+
});
|
|
222
|
+
const pref_language = out.value;
|
|
223
|
+
if (pref_language === undefined) {
|
|
224
|
+
throw errResolveFailed({
|
|
225
|
+
resource: resourcePrefLanguage,
|
|
226
|
+
msg: msgPrefLanguageMissing,
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
return pref_language;
|
|
230
|
+
}
|
|
231
|
+
async findPrefNotif(id) {
|
|
232
|
+
const out = await this.preferences.findOnePrefNotif({
|
|
233
|
+
id,
|
|
234
|
+
});
|
|
235
|
+
const pref_notif = out.value;
|
|
236
|
+
if (pref_notif === undefined) {
|
|
237
|
+
throw errResolveFailed({
|
|
238
|
+
resource: resourcePrefNotif,
|
|
239
|
+
msg: msgPrefNotifMissing,
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
return pref_notif;
|
|
243
|
+
}
|
|
244
|
+
async findPrefEmail(id) {
|
|
245
|
+
const out = await this.preferences.findOnePrefEmail({
|
|
246
|
+
id,
|
|
247
|
+
});
|
|
248
|
+
const pref_email = out.value;
|
|
249
|
+
if (pref_email === undefined) {
|
|
250
|
+
throw errResolveFailed({
|
|
251
|
+
resource: resourcePrefEmail,
|
|
252
|
+
msg: msgPrefEmailMissing,
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
return pref_email;
|
|
256
|
+
}
|
|
257
|
+
async findPrefTutorial(id) {
|
|
258
|
+
const out = await this.preferences.findOnePrefTutorial({
|
|
259
|
+
id,
|
|
260
|
+
});
|
|
261
|
+
const pref_tutorial = out.value;
|
|
262
|
+
if (pref_tutorial === undefined) {
|
|
263
|
+
throw errResolveFailed({
|
|
264
|
+
resource: resourcePrefTutorial,
|
|
265
|
+
msg: msgPrefTutorialMissing,
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
return pref_tutorial;
|
|
269
|
+
}
|
|
43
270
|
}
|
|
44
271
|
export function newPreferencesFX(opts) {
|
|
45
272
|
return new PreferencesFX(opts);
|
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
import { type AccountLock } from "@fabriktor/schema";
|
|
2
1
|
import type { PrivacyOperator } from "@fabriktor/client";
|
|
2
|
+
import { type AccountLock, type DeletionRequest } from "@fabriktor/schema";
|
|
3
|
+
type DeletionRequestInsertOptions = Parameters<PrivacyOperator["insertOneDeletionRequest"]>[0];
|
|
4
|
+
type DeletionRequestReplaceOptions = Parameters<PrivacyOperator["replaceOneDeletionRequest"]>[0];
|
|
5
|
+
type AccountLockInsertOptions = Parameters<PrivacyOperator["insertOneAccountLock"]>[0];
|
|
6
|
+
type AccountLockReplaceOptions = Parameters<PrivacyOperator["replaceOneAccountLock"]>[0];
|
|
7
|
+
export type CreateDeletionRequestOptions = DeletionRequestInsertOptions;
|
|
8
|
+
export type ReplaceDeletionRequestOptions = DeletionRequestReplaceOptions;
|
|
9
|
+
export type CreateAccountLockOptions = AccountLockInsertOptions;
|
|
10
|
+
export type ReplaceAccountLockOptions = AccountLockReplaceOptions;
|
|
3
11
|
export type PrivacyFXOptions = {
|
|
4
12
|
privacy: PrivacyOperator;
|
|
5
13
|
};
|
|
@@ -10,12 +18,23 @@ export type WatchAccountLockOptions = {
|
|
|
10
18
|
};
|
|
11
19
|
export type StopAccountLockWatch = () => void;
|
|
12
20
|
export interface PrivacyFXOperator {
|
|
21
|
+
createDeletionRequest(opts: CreateDeletionRequestOptions): Promise<DeletionRequest>;
|
|
22
|
+
replaceDeletionRequest(opts: ReplaceDeletionRequestOptions): Promise<DeletionRequest>;
|
|
23
|
+
createAccountLock(opts: CreateAccountLockOptions): Promise<AccountLock>;
|
|
24
|
+
replaceAccountLock(opts: ReplaceAccountLockOptions): Promise<AccountLock>;
|
|
13
25
|
watchAccountLock(opts: WatchAccountLockOptions): Promise<StopAccountLockWatch>;
|
|
14
26
|
}
|
|
15
27
|
export declare class PrivacyFX implements PrivacyFXOperator {
|
|
16
28
|
private privacy;
|
|
17
29
|
constructor(opts: PrivacyFXOptions);
|
|
30
|
+
createDeletionRequest(opts: CreateDeletionRequestOptions): Promise<DeletionRequest>;
|
|
31
|
+
replaceDeletionRequest(opts: ReplaceDeletionRequestOptions): Promise<DeletionRequest>;
|
|
32
|
+
createAccountLock(opts: CreateAccountLockOptions): Promise<AccountLock>;
|
|
33
|
+
replaceAccountLock(opts: ReplaceAccountLockOptions): Promise<AccountLock>;
|
|
18
34
|
watchAccountLock(opts: WatchAccountLockOptions): Promise<StopAccountLockWatch>;
|
|
19
|
-
private
|
|
35
|
+
private resolveDeletionRequest;
|
|
36
|
+
private resolveAccountLock;
|
|
37
|
+
private findOwnerAccountLock;
|
|
20
38
|
}
|
|
21
39
|
export declare function newPrivacyFX(opts: PrivacyFXOptions): PrivacyFX;
|
|
40
|
+
export {};
|
|
@@ -3,15 +3,40 @@
|
|
|
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 { ZeroID } from "@fabriktor/schema";
|
|
7
|
-
import { errRequired } from "../core/err.js";
|
|
6
|
+
import { ZeroID, } from "@fabriktor/schema";
|
|
7
|
+
import { errRequired, errResolveFailed, } from "../core/err.js";
|
|
8
|
+
import { requiredOperationID } from "../core/id.js";
|
|
8
9
|
const accountLockIntervalMs = 60 * 60 * 1000;
|
|
10
|
+
const resourceDeletionRequest = "deletion_request";
|
|
11
|
+
const resourceAccountLock = "account_lock";
|
|
9
12
|
const msgOwnerIDRequired = "Owner ID is required.";
|
|
13
|
+
const msgCreatedDeletionRequestIDMissing = "Created deletion request response did not contain an ID.";
|
|
14
|
+
const msgDeletionRequestMissing = "Deletion request could not be resolved after the mutation.";
|
|
15
|
+
const msgCreatedAccountLockIDMissing = "Created account lock response did not contain an ID.";
|
|
16
|
+
const msgAccountLockMissing = "Account lock could not be resolved after the mutation.";
|
|
10
17
|
export class PrivacyFX {
|
|
11
18
|
privacy;
|
|
12
19
|
constructor(opts) {
|
|
13
20
|
this.privacy = opts.privacy;
|
|
14
21
|
}
|
|
22
|
+
async createDeletionRequest(opts) {
|
|
23
|
+
const out = await this.privacy.insertOneDeletionRequest(opts);
|
|
24
|
+
const id = requiredOperationID(out, msgCreatedDeletionRequestIDMissing);
|
|
25
|
+
return await this.resolveDeletionRequest(id);
|
|
26
|
+
}
|
|
27
|
+
async replaceDeletionRequest(opts) {
|
|
28
|
+
await this.privacy.replaceOneDeletionRequest(opts);
|
|
29
|
+
return await this.resolveDeletionRequest(opts.id);
|
|
30
|
+
}
|
|
31
|
+
async createAccountLock(opts) {
|
|
32
|
+
const out = await this.privacy.insertOneAccountLock(opts);
|
|
33
|
+
const id = requiredOperationID(out, msgCreatedAccountLockIDMissing);
|
|
34
|
+
return await this.resolveAccountLock(id);
|
|
35
|
+
}
|
|
36
|
+
async replaceAccountLock(opts) {
|
|
37
|
+
await this.privacy.replaceOneAccountLock(opts);
|
|
38
|
+
return await this.resolveAccountLock(opts.id);
|
|
39
|
+
}
|
|
15
40
|
async watchAccountLock(opts) {
|
|
16
41
|
const owner_id = opts.owner_id.trim();
|
|
17
42
|
if (owner_id === "" || owner_id === ZeroID) {
|
|
@@ -20,7 +45,7 @@ export class PrivacyFX {
|
|
|
20
45
|
msg: msgOwnerIDRequired,
|
|
21
46
|
});
|
|
22
47
|
}
|
|
23
|
-
const initial_lock = await this.
|
|
48
|
+
const initial_lock = await this.findOwnerAccountLock(owner_id);
|
|
24
49
|
if (initial_lock !== undefined) {
|
|
25
50
|
opts.on_lock(initial_lock);
|
|
26
51
|
return () => { };
|
|
@@ -37,7 +62,7 @@ export class PrivacyFX {
|
|
|
37
62
|
return;
|
|
38
63
|
}
|
|
39
64
|
try {
|
|
40
|
-
const lock = await this.
|
|
65
|
+
const lock = await this.findOwnerAccountLock(owner_id);
|
|
41
66
|
if (stopped) {
|
|
42
67
|
return;
|
|
43
68
|
}
|
|
@@ -64,7 +89,33 @@ export class PrivacyFX {
|
|
|
64
89
|
}
|
|
65
90
|
};
|
|
66
91
|
}
|
|
67
|
-
async
|
|
92
|
+
async resolveDeletionRequest(id) {
|
|
93
|
+
const out = await this.privacy.findOneDeletionRequest({
|
|
94
|
+
id,
|
|
95
|
+
});
|
|
96
|
+
const deletion_request = out.value;
|
|
97
|
+
if (deletion_request === undefined) {
|
|
98
|
+
throw errResolveFailed({
|
|
99
|
+
resource: resourceDeletionRequest,
|
|
100
|
+
msg: msgDeletionRequestMissing,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
return deletion_request;
|
|
104
|
+
}
|
|
105
|
+
async resolveAccountLock(id) {
|
|
106
|
+
const out = await this.privacy.findOneAccountLock({
|
|
107
|
+
id,
|
|
108
|
+
});
|
|
109
|
+
const account_lock = out.value;
|
|
110
|
+
if (account_lock === undefined) {
|
|
111
|
+
throw errResolveFailed({
|
|
112
|
+
resource: resourceAccountLock,
|
|
113
|
+
msg: msgAccountLockMissing,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
return account_lock;
|
|
117
|
+
}
|
|
118
|
+
async findOwnerAccountLock(owner_id) {
|
|
68
119
|
const out = await this.privacy.queryAccountLocks({
|
|
69
120
|
query: {
|
|
70
121
|
owner_id,
|
|
@@ -1,22 +1,82 @@
|
|
|
1
1
|
import type { RoutesOperator } from "@fabriktor/client";
|
|
2
|
+
import { type ClientAvailability, type Route, type RouteTeam, type Tag, type Tracking } from "@fabriktor/schema";
|
|
3
|
+
import { type SearchPage } from "../core/search.js";
|
|
2
4
|
type RouteInsertOptions = Parameters<RoutesOperator["insertOneRoute"]>[0];
|
|
5
|
+
type RouteReplaceOptions = Parameters<RoutesOperator["replaceOneRoute"]>[0];
|
|
6
|
+
type TagInsertOptions = Parameters<RoutesOperator["insertOneTag"]>[0];
|
|
7
|
+
type TagReplaceOptions = Parameters<RoutesOperator["replaceOneTag"]>[0];
|
|
8
|
+
type ClientAvailabilityInsertOptions = Parameters<RoutesOperator["insertOneClientAvailability"]>[0];
|
|
9
|
+
type ClientAvailabilityReplaceOptions = Parameters<RoutesOperator["replaceOneClientAvailability"]>[0];
|
|
10
|
+
type TrackingInsertOptions = Parameters<RoutesOperator["insertOneTracking"]>[0];
|
|
11
|
+
type TrackingReplaceOptions = Parameters<RoutesOperator["replaceOneTracking"]>[0];
|
|
12
|
+
type RouteTeamInsertOptions = Parameters<RoutesOperator["insertOneRouteTeam"]>[0];
|
|
13
|
+
type RouteTeamReplaceOptions = Parameters<RoutesOperator["replaceOneRouteTeam"]>[0];
|
|
3
14
|
type RouteInsert = RouteInsertOptions["in"];
|
|
4
15
|
type RouteAvailability = NonNullable<Awaited<ReturnType<RoutesOperator["getAvailability"]>>["value"]>;
|
|
16
|
+
type SearchRouteRecordsOptions = {
|
|
17
|
+
owner_id: string;
|
|
18
|
+
q?: string;
|
|
19
|
+
page?: number;
|
|
20
|
+
per_page?: number;
|
|
21
|
+
};
|
|
5
22
|
export type CreateRouteOptions = {
|
|
6
23
|
in: RouteInsert;
|
|
7
24
|
availability: RouteAvailability;
|
|
8
25
|
};
|
|
9
|
-
export type
|
|
26
|
+
export type CreateValidatedRouteResult = Awaited<ReturnType<RoutesOperator["insertOneRoute"]>>;
|
|
27
|
+
export type CreateRouteResult = CreateValidatedRouteResult;
|
|
28
|
+
export type ReplaceRouteOptions = RouteReplaceOptions;
|
|
29
|
+
export type CreateTagOptions = TagInsertOptions;
|
|
30
|
+
export type ReplaceTagOptions = TagReplaceOptions;
|
|
31
|
+
export type SearchTagsOptions = SearchRouteRecordsOptions;
|
|
32
|
+
export type SearchTagsPage = SearchPage<Tag>;
|
|
33
|
+
export type CreateClientAvailabilityOptions = ClientAvailabilityInsertOptions;
|
|
34
|
+
export type ReplaceClientAvailabilityOptions = ClientAvailabilityReplaceOptions;
|
|
35
|
+
export type CreateTrackingOptions = TrackingInsertOptions;
|
|
36
|
+
export type ReplaceTrackingOptions = TrackingReplaceOptions;
|
|
37
|
+
export type CreateRouteTeamOptions = RouteTeamInsertOptions;
|
|
38
|
+
export type ReplaceRouteTeamOptions = RouteTeamReplaceOptions;
|
|
39
|
+
export type SearchRouteTeamsOptions = SearchRouteRecordsOptions;
|
|
40
|
+
export type SearchRouteTeamsPage = SearchPage<RouteTeam>;
|
|
10
41
|
export type RoutesFXOptions = {
|
|
11
42
|
routes: RoutesOperator;
|
|
12
43
|
};
|
|
13
44
|
export interface RoutesFXOperator {
|
|
14
|
-
createRoute(opts: CreateRouteOptions): Promise<
|
|
45
|
+
createRoute(opts: CreateRouteOptions): Promise<Route>;
|
|
46
|
+
createValidatedRoute(opts: CreateRouteOptions): Promise<CreateValidatedRouteResult>;
|
|
47
|
+
replaceRoute(opts: ReplaceRouteOptions): Promise<Route>;
|
|
48
|
+
createTag(opts: CreateTagOptions): Promise<Tag>;
|
|
49
|
+
replaceTag(opts: ReplaceTagOptions): Promise<Tag>;
|
|
50
|
+
searchTags(opts: SearchTagsOptions): Promise<SearchTagsPage>;
|
|
51
|
+
createClientAvailability(opts: CreateClientAvailabilityOptions): Promise<ClientAvailability>;
|
|
52
|
+
replaceClientAvailability(opts: ReplaceClientAvailabilityOptions): Promise<ClientAvailability>;
|
|
53
|
+
createTracking(opts: CreateTrackingOptions): Promise<Tracking>;
|
|
54
|
+
replaceTracking(opts: ReplaceTrackingOptions): Promise<Tracking>;
|
|
55
|
+
createRouteTeam(opts: CreateRouteTeamOptions): Promise<RouteTeam>;
|
|
56
|
+
replaceRouteTeam(opts: ReplaceRouteTeamOptions): Promise<RouteTeam>;
|
|
57
|
+
searchRouteTeams(opts: SearchRouteTeamsOptions): Promise<SearchRouteTeamsPage>;
|
|
15
58
|
}
|
|
16
59
|
export declare class RoutesFX implements RoutesFXOperator {
|
|
17
60
|
private routes;
|
|
18
61
|
constructor(opts: RoutesFXOptions);
|
|
19
|
-
createRoute(opts: CreateRouteOptions): Promise<
|
|
62
|
+
createRoute(opts: CreateRouteOptions): Promise<Route>;
|
|
63
|
+
createValidatedRoute(opts: CreateRouteOptions): Promise<CreateValidatedRouteResult>;
|
|
64
|
+
replaceRoute(opts: ReplaceRouteOptions): Promise<Route>;
|
|
65
|
+
createTag(opts: CreateTagOptions): Promise<Tag>;
|
|
66
|
+
replaceTag(opts: ReplaceTagOptions): Promise<Tag>;
|
|
67
|
+
searchTags(opts: SearchTagsOptions): Promise<SearchTagsPage>;
|
|
68
|
+
createClientAvailability(opts: CreateClientAvailabilityOptions): Promise<ClientAvailability>;
|
|
69
|
+
replaceClientAvailability(opts: ReplaceClientAvailabilityOptions): Promise<ClientAvailability>;
|
|
70
|
+
createTracking(opts: CreateTrackingOptions): Promise<Tracking>;
|
|
71
|
+
replaceTracking(opts: ReplaceTrackingOptions): Promise<Tracking>;
|
|
72
|
+
createRouteTeam(opts: CreateRouteTeamOptions): Promise<RouteTeam>;
|
|
73
|
+
replaceRouteTeam(opts: ReplaceRouteTeamOptions): Promise<RouteTeam>;
|
|
74
|
+
searchRouteTeams(opts: SearchRouteTeamsOptions): Promise<SearchRouteTeamsPage>;
|
|
75
|
+
private findRoute;
|
|
76
|
+
private findTag;
|
|
77
|
+
private findClientAvailability;
|
|
78
|
+
private findTracking;
|
|
79
|
+
private findRouteTeam;
|
|
20
80
|
}
|
|
21
81
|
export declare function newRoutesFX(opts: RoutesFXOptions): RoutesFX;
|
|
22
82
|
export {};
|
|
@@ -3,10 +3,28 @@
|
|
|
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 { OwnerIDKey, } from "@fabriktor/schema";
|
|
7
|
+
import { errResolveFailed, errValidation } from "../core/err.js";
|
|
8
|
+
import { requiredOperationID } from "../core/id.js";
|
|
9
|
+
import { runSearch } from "../core/search.js";
|
|
7
10
|
const maxHour = 23;
|
|
8
11
|
const maxMinute = 59;
|
|
9
12
|
const maxMinuteOfDay = 1440;
|
|
13
|
+
const resourceRoute = "route";
|
|
14
|
+
const resourceTag = "tag";
|
|
15
|
+
const resourceClientAvailability = "client_availability";
|
|
16
|
+
const resourceTracking = "tracking";
|
|
17
|
+
const resourceRouteTeam = "route_team";
|
|
18
|
+
const msgCreatedRouteIDMissing = "Created route response did not contain an ID.";
|
|
19
|
+
const msgRouteMissing = "Route could not be resolved after the mutation.";
|
|
20
|
+
const msgCreatedTagIDMissing = "Created tag response did not contain an ID.";
|
|
21
|
+
const msgTagMissing = "Tag could not be resolved after the mutation.";
|
|
22
|
+
const msgCreatedClientAvailabilityIDMissing = "Created client availability response did not contain an ID.";
|
|
23
|
+
const msgClientAvailabilityMissing = "Client availability could not be resolved after the mutation.";
|
|
24
|
+
const msgCreatedTrackingIDMissing = "Created tracking response did not contain an ID.";
|
|
25
|
+
const msgTrackingMissing = "Tracking could not be resolved after the mutation.";
|
|
26
|
+
const msgCreatedRouteTeamIDMissing = "Created route team response did not contain an ID.";
|
|
27
|
+
const msgRouteTeamMissing = "Route team could not be resolved after the mutation.";
|
|
10
28
|
const msgGlobalWindowSameDay = "The global route window must stay within one calendar day.";
|
|
11
29
|
const msgGlobalWindowInvalid = "The global route window is invalid.";
|
|
12
30
|
const msgEmployeeDuplicate = "An employee cannot be selected in more than one vehicle.";
|
|
@@ -21,11 +39,143 @@ export class RoutesFX {
|
|
|
21
39
|
this.routes = opts.routes;
|
|
22
40
|
}
|
|
23
41
|
async createRoute(opts) {
|
|
42
|
+
const out = await this.createValidatedRoute(opts);
|
|
43
|
+
const id = requiredOperationID(out, msgCreatedRouteIDMissing);
|
|
44
|
+
return await this.findRoute(id);
|
|
45
|
+
}
|
|
46
|
+
async createValidatedRoute(opts) {
|
|
24
47
|
validateRoute(opts.in, opts.availability);
|
|
25
48
|
return await this.routes.insertOneRoute({
|
|
26
49
|
in: opts.in,
|
|
27
50
|
});
|
|
28
51
|
}
|
|
52
|
+
async replaceRoute(opts) {
|
|
53
|
+
await this.routes.replaceOneRoute(opts);
|
|
54
|
+
return await this.findRoute(opts.id);
|
|
55
|
+
}
|
|
56
|
+
async createTag(opts) {
|
|
57
|
+
const out = await this.routes.insertOneTag(opts);
|
|
58
|
+
const id = requiredOperationID(out, msgCreatedTagIDMissing);
|
|
59
|
+
return await this.findTag(id);
|
|
60
|
+
}
|
|
61
|
+
async replaceTag(opts) {
|
|
62
|
+
await this.routes.replaceOneTag(opts);
|
|
63
|
+
return await this.findTag(opts.id);
|
|
64
|
+
}
|
|
65
|
+
async searchTags(opts) {
|
|
66
|
+
return await runSearch({
|
|
67
|
+
search: (searchOpts) => this.routes.searchManyTags(searchOpts),
|
|
68
|
+
query: {
|
|
69
|
+
[OwnerIDKey]: opts.owner_id,
|
|
70
|
+
},
|
|
71
|
+
q: opts.q,
|
|
72
|
+
page: opts.page,
|
|
73
|
+
per_page: opts.per_page,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
async createClientAvailability(opts) {
|
|
77
|
+
const out = await this.routes.insertOneClientAvailability(opts);
|
|
78
|
+
const id = requiredOperationID(out, msgCreatedClientAvailabilityIDMissing);
|
|
79
|
+
return await this.findClientAvailability(id);
|
|
80
|
+
}
|
|
81
|
+
async replaceClientAvailability(opts) {
|
|
82
|
+
await this.routes.replaceOneClientAvailability(opts);
|
|
83
|
+
return await this.findClientAvailability(opts.id);
|
|
84
|
+
}
|
|
85
|
+
async createTracking(opts) {
|
|
86
|
+
const out = await this.routes.insertOneTracking(opts);
|
|
87
|
+
const id = requiredOperationID(out, msgCreatedTrackingIDMissing);
|
|
88
|
+
return await this.findTracking(id);
|
|
89
|
+
}
|
|
90
|
+
async replaceTracking(opts) {
|
|
91
|
+
await this.routes.replaceOneTracking(opts);
|
|
92
|
+
return await this.findTracking(opts.id);
|
|
93
|
+
}
|
|
94
|
+
async createRouteTeam(opts) {
|
|
95
|
+
const out = await this.routes.insertOneRouteTeam(opts);
|
|
96
|
+
const id = requiredOperationID(out, msgCreatedRouteTeamIDMissing);
|
|
97
|
+
return await this.findRouteTeam(id);
|
|
98
|
+
}
|
|
99
|
+
async replaceRouteTeam(opts) {
|
|
100
|
+
await this.routes.replaceOneRouteTeam(opts);
|
|
101
|
+
return await this.findRouteTeam(opts.id);
|
|
102
|
+
}
|
|
103
|
+
async searchRouteTeams(opts) {
|
|
104
|
+
return await runSearch({
|
|
105
|
+
search: (searchOpts) => this.routes.searchManyRouteTeams(searchOpts),
|
|
106
|
+
query: {
|
|
107
|
+
[OwnerIDKey]: opts.owner_id,
|
|
108
|
+
},
|
|
109
|
+
q: opts.q,
|
|
110
|
+
page: opts.page,
|
|
111
|
+
per_page: opts.per_page,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
async findRoute(id) {
|
|
115
|
+
const out = await this.routes.findOneRoute({
|
|
116
|
+
id,
|
|
117
|
+
});
|
|
118
|
+
const route = out.value;
|
|
119
|
+
if (route === undefined) {
|
|
120
|
+
throw errResolveFailed({
|
|
121
|
+
resource: resourceRoute,
|
|
122
|
+
msg: msgRouteMissing,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
return route;
|
|
126
|
+
}
|
|
127
|
+
async findTag(id) {
|
|
128
|
+
const out = await this.routes.findOneTag({
|
|
129
|
+
id,
|
|
130
|
+
});
|
|
131
|
+
const tag = out.value;
|
|
132
|
+
if (tag === undefined) {
|
|
133
|
+
throw errResolveFailed({
|
|
134
|
+
resource: resourceTag,
|
|
135
|
+
msg: msgTagMissing,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
return tag;
|
|
139
|
+
}
|
|
140
|
+
async findClientAvailability(id) {
|
|
141
|
+
const out = await this.routes.findOneClientAvailability({
|
|
142
|
+
id,
|
|
143
|
+
});
|
|
144
|
+
const client_availability = out.value;
|
|
145
|
+
if (client_availability === undefined) {
|
|
146
|
+
throw errResolveFailed({
|
|
147
|
+
resource: resourceClientAvailability,
|
|
148
|
+
msg: msgClientAvailabilityMissing,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
return client_availability;
|
|
152
|
+
}
|
|
153
|
+
async findTracking(id) {
|
|
154
|
+
const out = await this.routes.findOneTracking({
|
|
155
|
+
id,
|
|
156
|
+
});
|
|
157
|
+
const tracking = out.value;
|
|
158
|
+
if (tracking === undefined) {
|
|
159
|
+
throw errResolveFailed({
|
|
160
|
+
resource: resourceTracking,
|
|
161
|
+
msg: msgTrackingMissing,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
return tracking;
|
|
165
|
+
}
|
|
166
|
+
async findRouteTeam(id) {
|
|
167
|
+
const out = await this.routes.findOneRouteTeam({
|
|
168
|
+
id,
|
|
169
|
+
});
|
|
170
|
+
const route_team = out.value;
|
|
171
|
+
if (route_team === undefined) {
|
|
172
|
+
throw errResolveFailed({
|
|
173
|
+
resource: resourceRouteTeam,
|
|
174
|
+
msg: msgRouteTeamMissing,
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
return route_team;
|
|
178
|
+
}
|
|
29
179
|
}
|
|
30
180
|
export function newRoutesFX(opts) {
|
|
31
181
|
return new RoutesFX(opts);
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import { type Date as SchemaDate, type OperationResult, type WeekSheet } from "@fabriktor/schema";
|
|
1
|
+
import { type Date as SchemaDate, type OperationResult, type Summary, type WeekSheet } from "@fabriktor/schema";
|
|
2
2
|
import type { TimesheetsOperator } from "@fabriktor/client";
|
|
3
3
|
type PunchPayload = Parameters<TimesheetsOperator["punch"]>[0];
|
|
4
|
+
type WeekSheetReplaceOptions = Parameters<TimesheetsOperator["replaceOneWeekSheet"]>[0];
|
|
5
|
+
type SummaryReplaceOptions = Parameters<TimesheetsOperator["replaceOneSummary"]>[0];
|
|
6
|
+
export type ReplaceWeekSheetOptions = WeekSheetReplaceOptions;
|
|
7
|
+
export type ReplaceSummaryOptions = SummaryReplaceOptions;
|
|
4
8
|
export type TimesheetsFXOptions = {
|
|
5
9
|
timesheets: TimesheetsOperator;
|
|
6
10
|
};
|
|
@@ -57,6 +61,8 @@ export type ApproveWeekSheetsOptions = {
|
|
|
57
61
|
week_sheets: WeekSheet[];
|
|
58
62
|
};
|
|
59
63
|
export interface TimesheetsFXOperator {
|
|
64
|
+
replaceWeekSheet(opts: ReplaceWeekSheetOptions): Promise<WeekSheet>;
|
|
65
|
+
replaceSummary(opts: ReplaceSummaryOptions): Promise<Summary>;
|
|
60
66
|
punchControls(opts: PunchControlsOptions): PunchControls;
|
|
61
67
|
punchIn(opts: PunchInOptions): Promise<OperationResult>;
|
|
62
68
|
punchOut(opts: PunchOutOptions): Promise<OperationResult>;
|
|
@@ -73,6 +79,8 @@ export declare class TimesheetsFX implements TimesheetsFXOperator {
|
|
|
73
79
|
private timesheets;
|
|
74
80
|
private punch_in_progress;
|
|
75
81
|
constructor(opts: TimesheetsFXOptions);
|
|
82
|
+
replaceWeekSheet(opts: ReplaceWeekSheetOptions): Promise<WeekSheet>;
|
|
83
|
+
replaceSummary(opts: ReplaceSummaryOptions): Promise<Summary>;
|
|
76
84
|
punchControls(opts: PunchControlsOptions): PunchControls;
|
|
77
85
|
punchIn(opts: PunchInOptions): Promise<OperationResult>;
|
|
78
86
|
punchOut(opts: PunchOutOptions): Promise<OperationResult>;
|
|
@@ -84,6 +92,8 @@ export declare class TimesheetsFX implements TimesheetsFXOperator {
|
|
|
84
92
|
syncWeek(opts: SyncWeekOptions): Promise<void>;
|
|
85
93
|
syncDays(opts: SyncDaysOptions): Promise<void>;
|
|
86
94
|
approveWeekSheets(opts: ApproveWeekSheetsOptions): Promise<void>;
|
|
95
|
+
private findWeekSheet;
|
|
96
|
+
private findSummary;
|
|
87
97
|
private syncSheets;
|
|
88
98
|
private runPunch;
|
|
89
99
|
}
|