@fabriktor/fx 0.0.84 → 0.0.85
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 +30 -25
- package/dist/src/billable/billable.js +100 -25
- package/dist/src/users/users.d.ts +11 -0
- package/dist/src/users/users.js +80 -1
- package/package.json +3 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import
|
|
1
|
+
import { type BillableOperator } from "@fabriktor/client";
|
|
2
|
+
import { type Bill, BillableFolder, Charge, Equipment, Item, LaborRate, MeterReading, Quantifier, Tax, TmpBillNumber, VendorInvoice, Warehouse } from "@fabriktor/schema";
|
|
3
3
|
import { type OwnerSearchOptions, type SearchPage } from "../core/search.js";
|
|
4
4
|
type GenerateBillPayload = Parameters<BillableOperator["generateBill"]>[0];
|
|
5
5
|
type BillInsertOptions = Parameters<BillableOperator["insertOneBill"]>[0];
|
|
@@ -66,7 +66,10 @@ export type CreateTmpBillNumberOptions = TmpBillNumberInsertOptions;
|
|
|
66
66
|
export type ReplaceTmpBillNumberOptions = TmpBillNumberReplaceOptions;
|
|
67
67
|
export type SearchTmpBillNumbersOptions = OwnerSearchOptions;
|
|
68
68
|
export type SearchTmpBillNumbersPage = SearchPage<TmpBillNumber>;
|
|
69
|
-
export type CreateVendorInvoiceOptions = VendorInvoiceInsertOptions
|
|
69
|
+
export type CreateVendorInvoiceOptions = VendorInvoiceInsertOptions & {
|
|
70
|
+
owner_id: string;
|
|
71
|
+
allow_duplicate?: boolean;
|
|
72
|
+
};
|
|
70
73
|
export type ReplaceVendorInvoiceOptions = VendorInvoiceReplaceOptions;
|
|
71
74
|
export type SearchVendorInvoicesOptions = OwnerSearchOptions;
|
|
72
75
|
export type SearchVendorInvoicesPage = SearchPage<VendorInvoice>;
|
|
@@ -81,7 +84,7 @@ export type GenerateFixedEstimateOptions = {
|
|
|
81
84
|
in: GenerateBillPayload;
|
|
82
85
|
};
|
|
83
86
|
export type AcceptFixedEstimateOptions = {
|
|
84
|
-
|
|
87
|
+
estimate: Bill;
|
|
85
88
|
};
|
|
86
89
|
export type GenerateDynamicEstimateOptions = {
|
|
87
90
|
in: GenerateBillPayload;
|
|
@@ -93,10 +96,14 @@ export type GenerateDynamicBillOptions = {
|
|
|
93
96
|
export type MarkLocationAchievedOptions = {
|
|
94
97
|
in: GenerateBillPayload;
|
|
95
98
|
};
|
|
96
|
-
export type
|
|
97
|
-
|
|
99
|
+
export type CancelBillOptions = {
|
|
100
|
+
in: GenerateBillPayload;
|
|
101
|
+
};
|
|
98
102
|
export type VendorInvoiceFromBillOptions = Parameters<BillableOperator["vendorInvoiceFromBill"]>[0];
|
|
99
|
-
export
|
|
103
|
+
export declare const BillablePreActionReason: {
|
|
104
|
+
readonly VendorInvoiceNumberExists: "vendor_invoice_number_exists";
|
|
105
|
+
};
|
|
106
|
+
export type BillablePreActionReason = (typeof BillablePreActionReason)[keyof typeof BillablePreActionReason];
|
|
100
107
|
export interface BillableFXOperator {
|
|
101
108
|
createBill(opts: CreateBillOptions): Promise<Bill>;
|
|
102
109
|
replaceBill(opts: ReplaceBillOptions): Promise<Bill>;
|
|
@@ -134,15 +141,13 @@ export interface BillableFXOperator {
|
|
|
134
141
|
createWarehouse(opts: CreateWarehouseOptions): Promise<Warehouse>;
|
|
135
142
|
replaceWarehouse(opts: ReplaceWarehouseOptions): Promise<Warehouse>;
|
|
136
143
|
searchWarehouses(opts: SearchWarehousesOptions): Promise<SearchWarehousesPage>;
|
|
137
|
-
generateFixedEstimate(opts: GenerateFixedEstimateOptions): Promise<
|
|
138
|
-
acceptFixedEstimate(opts: AcceptFixedEstimateOptions): Promise<
|
|
139
|
-
generateDynamicEstimate(opts: GenerateDynamicEstimateOptions): Promise<
|
|
140
|
-
generateDynamicBill(opts: GenerateDynamicBillOptions): Promise<
|
|
141
|
-
markLocationAchieved(opts: MarkLocationAchievedOptions): Promise<
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
vendorInvoiceFromBill(opts: VendorInvoiceFromBillOptions): Promise<OperationResult>;
|
|
145
|
-
setItemQuantity(opts: SetItemQuantityOptions): Promise<void>;
|
|
144
|
+
generateFixedEstimate(opts: GenerateFixedEstimateOptions): Promise<Bill>;
|
|
145
|
+
acceptFixedEstimate(opts: AcceptFixedEstimateOptions): Promise<Bill>;
|
|
146
|
+
generateDynamicEstimate(opts: GenerateDynamicEstimateOptions): Promise<Bill>;
|
|
147
|
+
generateDynamicBill(opts: GenerateDynamicBillOptions): Promise<Bill>;
|
|
148
|
+
markLocationAchieved(opts: MarkLocationAchievedOptions): Promise<Bill>;
|
|
149
|
+
cancelBill(opts: CancelBillOptions): Promise<Bill>;
|
|
150
|
+
vendorInvoiceFromBill(opts: VendorInvoiceFromBillOptions): Promise<VendorInvoice>;
|
|
146
151
|
}
|
|
147
152
|
export declare class BillableFX implements BillableFXOperator {
|
|
148
153
|
private billable;
|
|
@@ -183,15 +188,15 @@ export declare class BillableFX implements BillableFXOperator {
|
|
|
183
188
|
createWarehouse(opts: CreateWarehouseOptions): Promise<Warehouse>;
|
|
184
189
|
replaceWarehouse(opts: ReplaceWarehouseOptions): Promise<Warehouse>;
|
|
185
190
|
searchWarehouses(opts: SearchWarehousesOptions): Promise<SearchWarehousesPage>;
|
|
186
|
-
generateFixedEstimate(opts: GenerateFixedEstimateOptions): Promise<
|
|
187
|
-
acceptFixedEstimate(opts: AcceptFixedEstimateOptions): Promise<
|
|
188
|
-
generateDynamicEstimate(opts: GenerateDynamicEstimateOptions): Promise<
|
|
189
|
-
generateDynamicBill(opts: GenerateDynamicBillOptions): Promise<
|
|
190
|
-
markLocationAchieved(opts: MarkLocationAchievedOptions): Promise<
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
191
|
+
generateFixedEstimate(opts: GenerateFixedEstimateOptions): Promise<Bill>;
|
|
192
|
+
acceptFixedEstimate(opts: AcceptFixedEstimateOptions): Promise<Bill>;
|
|
193
|
+
generateDynamicEstimate(opts: GenerateDynamicEstimateOptions): Promise<Bill>;
|
|
194
|
+
generateDynamicBill(opts: GenerateDynamicBillOptions): Promise<Bill>;
|
|
195
|
+
markLocationAchieved(opts: MarkLocationAchievedOptions): Promise<Bill>;
|
|
196
|
+
cancelBill(opts: CancelBillOptions): Promise<Bill>;
|
|
197
|
+
vendorInvoiceFromBill(opts: VendorInvoiceFromBillOptions): Promise<VendorInvoice>;
|
|
198
|
+
private generateBill;
|
|
199
|
+
private checkVendorInvoiceNumber;
|
|
195
200
|
private findBill;
|
|
196
201
|
private findBillableFolder;
|
|
197
202
|
private findCharge;
|
|
@@ -3,11 +3,12 @@
|
|
|
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 {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
import { queryParams } from "@fabriktor/client";
|
|
7
|
+
import { BillTypeDynamic, BillTypeFixed, } from "@fabriktor/schema";
|
|
8
|
+
import { errRequired, errResolveFailed, errValidation } from "../core/err.js";
|
|
9
|
+
import { requiredOperationID, resolvedID } from "../core/id.js";
|
|
10
|
+
import { runPreActionCheck } from "../core/pre-action.js";
|
|
11
|
+
import { runOwnerSearch, withOwnerQuery, } from "../core/search.js";
|
|
11
12
|
const resourceBill = "bill";
|
|
12
13
|
const msgCreatedBillIDMissing = "Created bill response did not contain an ID.";
|
|
13
14
|
const msgBillMissing = "Bill could not be resolved after the mutation.";
|
|
@@ -44,6 +45,15 @@ const msgVendorInvoiceMissing = "Vendor invoice could not be resolved after the
|
|
|
44
45
|
const resourceWarehouse = "warehouse";
|
|
45
46
|
const msgCreatedWarehouseIDMissing = "Created warehouse response did not contain an ID.";
|
|
46
47
|
const msgWarehouseMissing = "Warehouse could not be resolved after the mutation.";
|
|
48
|
+
const msgOwnerIDRequired = "Owner ID is required.";
|
|
49
|
+
const msgEstimateIDRequired = "Fixed estimate ID is required.";
|
|
50
|
+
const msgFixedEstimateRequired = "Only a fixed estimate can be accepted.";
|
|
51
|
+
const msgInternalFixedEstimateRequired = "Only an internal fixed estimate can be accepted in Fabriktor.";
|
|
52
|
+
const msgCanceledEstimate = "A canceled fixed estimate cannot be accepted.";
|
|
53
|
+
const msgEstimateAlreadyAccepted = "This fixed estimate is already accepted.";
|
|
54
|
+
export const BillablePreActionReason = {
|
|
55
|
+
VendorInvoiceNumberExists: "vendor_invoice_number_exists",
|
|
56
|
+
};
|
|
47
57
|
export class BillableFX {
|
|
48
58
|
billable;
|
|
49
59
|
constructor(opts) {
|
|
@@ -200,7 +210,21 @@ export class BillableFX {
|
|
|
200
210
|
});
|
|
201
211
|
}
|
|
202
212
|
async createVendorInvoice(opts) {
|
|
203
|
-
const
|
|
213
|
+
const owner_id = opts.owner_id.trim();
|
|
214
|
+
if (!owner_id) {
|
|
215
|
+
throw errRequired({
|
|
216
|
+
field: "owner_id",
|
|
217
|
+
msg: msgOwnerIDRequired,
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
const input = {
|
|
221
|
+
...opts.in,
|
|
222
|
+
number: opts.in.number.trim(),
|
|
223
|
+
};
|
|
224
|
+
if (!opts.allow_duplicate) {
|
|
225
|
+
await this.checkVendorInvoiceNumber(owner_id, input.number);
|
|
226
|
+
}
|
|
227
|
+
const out = await this.billable.insertOneVendorInvoice({ in: input });
|
|
204
228
|
const id = requiredOperationID(out, msgCreatedVendorInvoiceIDMissing);
|
|
205
229
|
return await this.findVendorInvoice(id);
|
|
206
230
|
}
|
|
@@ -230,46 +254,62 @@ export class BillableFX {
|
|
|
230
254
|
});
|
|
231
255
|
}
|
|
232
256
|
async generateFixedEstimate(opts) {
|
|
233
|
-
return await this.
|
|
234
|
-
type:
|
|
257
|
+
return await this.generateBill(billWith(opts.in, {
|
|
258
|
+
type: BillTypeFixed,
|
|
235
259
|
is_estimate: true,
|
|
236
260
|
}));
|
|
237
261
|
}
|
|
238
262
|
async acceptFixedEstimate(opts) {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
263
|
+
const estimate_id = fixedEstimateID(opts);
|
|
264
|
+
const out = await this.billable.acceptFixedEstimate({ estimate_id });
|
|
265
|
+
const id = requiredOperationID(out, msgCreatedBillIDMissing);
|
|
266
|
+
return await this.findBill(id);
|
|
243
267
|
}
|
|
244
268
|
async generateDynamicEstimate(opts) {
|
|
245
|
-
return await this.
|
|
246
|
-
type:
|
|
269
|
+
return await this.generateBill(billWith(opts.in, {
|
|
270
|
+
type: BillTypeDynamic,
|
|
247
271
|
is_estimate: true,
|
|
272
|
+
upfront_rate: 0,
|
|
248
273
|
}));
|
|
249
274
|
}
|
|
250
275
|
async generateDynamicBill(opts) {
|
|
251
|
-
return await this.
|
|
252
|
-
type:
|
|
276
|
+
return await this.generateBill(billWith(opts.in, {
|
|
277
|
+
type: BillTypeDynamic,
|
|
253
278
|
is_estimate: false,
|
|
279
|
+
upfront_rate: 0,
|
|
254
280
|
exclude_billed: opts.exclude_billed,
|
|
255
281
|
}));
|
|
256
282
|
}
|
|
257
283
|
async markLocationAchieved(opts) {
|
|
258
|
-
return await this.
|
|
284
|
+
return await this.generateBill(billWith(opts.in, {
|
|
259
285
|
is_location_achieved: true,
|
|
260
286
|
}));
|
|
261
287
|
}
|
|
262
|
-
async
|
|
263
|
-
return await this.
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
return await this.billable.periodsFromDates(opts);
|
|
288
|
+
async cancelBill(opts) {
|
|
289
|
+
return await this.generateBill(billWith(opts.in, {
|
|
290
|
+
is_canceled: true,
|
|
291
|
+
}));
|
|
267
292
|
}
|
|
268
293
|
async vendorInvoiceFromBill(opts) {
|
|
269
|
-
|
|
294
|
+
const out = await this.billable.vendorInvoiceFromBill(opts);
|
|
295
|
+
const id = requiredOperationID(out, msgCreatedVendorInvoiceIDMissing);
|
|
296
|
+
return await this.findVendorInvoice(id);
|
|
297
|
+
}
|
|
298
|
+
async generateBill(input) {
|
|
299
|
+
const out = await this.billable.generateBill(input);
|
|
300
|
+
const id = requiredOperationID(out, msgCreatedBillIDMissing);
|
|
301
|
+
return await this.findBill(id);
|
|
270
302
|
}
|
|
271
|
-
async
|
|
272
|
-
await
|
|
303
|
+
async checkVendorInvoiceNumber(owner_id, number) {
|
|
304
|
+
await runPreActionCheck({
|
|
305
|
+
reason: BillablePreActionReason.VendorInvoiceNumberExists,
|
|
306
|
+
allowed: async () => {
|
|
307
|
+
const out = await this.billable.queryVendorInvoices({
|
|
308
|
+
query: withOwnerQuery(owner_id, queryParams({ number })),
|
|
309
|
+
});
|
|
310
|
+
return (out.value?.length ?? 0) === 0;
|
|
311
|
+
},
|
|
312
|
+
});
|
|
273
313
|
}
|
|
274
314
|
async findBill(id) {
|
|
275
315
|
const out = await this.billable.findOneBill({
|
|
@@ -431,6 +471,41 @@ export class BillableFX {
|
|
|
431
471
|
export function newBillableFX(opts) {
|
|
432
472
|
return new BillableFX(opts);
|
|
433
473
|
}
|
|
474
|
+
function fixedEstimateID(opts) {
|
|
475
|
+
const estimate = opts.estimate;
|
|
476
|
+
const id = resolvedID(estimate.id);
|
|
477
|
+
if (id === undefined) {
|
|
478
|
+
throw errRequired({
|
|
479
|
+
field: "estimate",
|
|
480
|
+
msg: msgEstimateIDRequired,
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
if (!estimate.is_estimate || estimate.type !== BillTypeFixed) {
|
|
484
|
+
throw errValidation({
|
|
485
|
+
field: "estimate",
|
|
486
|
+
msg: msgFixedEstimateRequired,
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
if (!estimate.is_internal_client) {
|
|
490
|
+
throw errValidation({
|
|
491
|
+
field: "estimate",
|
|
492
|
+
msg: msgInternalFixedEstimateRequired,
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
if (estimate.is_canceled) {
|
|
496
|
+
throw errValidation({
|
|
497
|
+
field: "estimate",
|
|
498
|
+
msg: msgCanceledEstimate,
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
if (resolvedID(estimate.accepted_bill_id) !== undefined) {
|
|
502
|
+
throw errValidation({
|
|
503
|
+
field: "estimate",
|
|
504
|
+
msg: msgEstimateAlreadyAccepted,
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
return id;
|
|
508
|
+
}
|
|
434
509
|
function billWith(x, overrides) {
|
|
435
510
|
return {
|
|
436
511
|
...x,
|
|
@@ -6,6 +6,12 @@ export type VerifyUsernameOptions = Parameters<TmpUsernamesOperator["verify"]>[0
|
|
|
6
6
|
export type GenerateUsernamesOptions = VerifyUsernameOptions;
|
|
7
7
|
export type SearchUsersOptions = GetByUIDOptions & Omit<RunSearchOptions<User>, "search">;
|
|
8
8
|
export type SearchUsersPage = SearchPage<User>;
|
|
9
|
+
export type ExternalUserInput = Omit<InUser, "account_identity" | "active_mode" | "privacy">;
|
|
10
|
+
export type CreateExternalUserOptions = {
|
|
11
|
+
in: ExternalUserInput;
|
|
12
|
+
};
|
|
13
|
+
export type SearchExternalUsersOptions = SearchUsersOptions;
|
|
14
|
+
export type SearchExternalUsersPage = SearchUsersPage;
|
|
9
15
|
export type UserProfileInput = Pick<InUser, "first_name" | "last_name" | "phone" | "company_name" | "privacy"> & InAddress;
|
|
10
16
|
export type UpdateUserProfileOptions = GetByUIDOptions & {
|
|
11
17
|
id: string;
|
|
@@ -36,6 +42,8 @@ export type UsersFXOptions = {
|
|
|
36
42
|
};
|
|
37
43
|
export interface UsersFXOperator {
|
|
38
44
|
searchUsers(opts: SearchUsersOptions): Promise<SearchUsersPage>;
|
|
45
|
+
createExternalUser(opts: CreateExternalUserOptions): Promise<User>;
|
|
46
|
+
searchExternalUsers(opts: SearchExternalUsersOptions): Promise<SearchExternalUsersPage>;
|
|
39
47
|
updateUserProfile(opts: UpdateUserProfileOptions): Promise<User>;
|
|
40
48
|
updateUserPhone(opts: UpdateUserPhoneOptions): Promise<User>;
|
|
41
49
|
switchActiveMode(opts: SwitchActiveModeOptions): Promise<User>;
|
|
@@ -52,6 +60,8 @@ export declare class UsersFX implements UsersFXOperator {
|
|
|
52
60
|
private tmp_phones;
|
|
53
61
|
constructor(opts: UsersFXOptions);
|
|
54
62
|
searchUsers(opts: SearchUsersOptions): Promise<SearchUsersPage>;
|
|
63
|
+
createExternalUser(opts: CreateExternalUserOptions): Promise<User>;
|
|
64
|
+
searchExternalUsers(opts: SearchExternalUsersOptions): Promise<SearchExternalUsersPage>;
|
|
55
65
|
updateUserProfile(opts: UpdateUserProfileOptions): Promise<User>;
|
|
56
66
|
updateUserPhone(opts: UpdateUserPhoneOptions): Promise<User>;
|
|
57
67
|
switchActiveMode(opts: SwitchActiveModeOptions): Promise<User>;
|
|
@@ -61,6 +71,7 @@ export declare class UsersFX implements UsersFXOperator {
|
|
|
61
71
|
generateUsernames(opts: GenerateUsernamesOptions): Promise<OperationResultOf<UsernameVerification>>;
|
|
62
72
|
sendPhoneCode(opts: SendPhoneCodeOptions): Promise<void>;
|
|
63
73
|
verifyPhoneCode(opts: VerifyPhoneCodeOptions): Promise<void>;
|
|
74
|
+
private findExternalUser;
|
|
64
75
|
private updatedUser;
|
|
65
76
|
}
|
|
66
77
|
export declare function newUsersFX(opts: UsersFXOptions): UsersFX;
|
package/dist/src/users/users.js
CHANGED
|
@@ -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 { UserTypeClient, UserTypeEmployee, UserTypeEmployer, } from "@fabriktor/schema";
|
|
6
|
+
import { UserTypeClient, UserTypeEmployee, UserTypeEmployer, UserTypeExternal, } from "@fabriktor/schema";
|
|
7
7
|
import { errRequired, errResolveFailed, errValidation, } from "../core/err.js";
|
|
8
|
+
import { requiredOperationID } from "../core/id.js";
|
|
8
9
|
import { runSearch, } from "../core/search.js";
|
|
9
10
|
import { normalizePhone, normalizePhoneCode, validatePhone, validatePhoneCode, } from "./phone.js";
|
|
10
11
|
import { normalizeUsername, validateUsernameFormat } from "./username.js";
|
|
@@ -15,6 +16,8 @@ const msgFirstNameRequired = "First name is required.";
|
|
|
15
16
|
const msgLastNameRequired = "Last name is required.";
|
|
16
17
|
const msgAddressRequired = "A complete address is required.";
|
|
17
18
|
const msgUserMissingAfterUpdate = "User could not be resolved after the account update.";
|
|
19
|
+
const msgCreatedExternalUserIDMissing = "Created external user response did not contain an ID.";
|
|
20
|
+
const msgExternalUserMissing = "External user could not be resolved after creation.";
|
|
18
21
|
const msgInvalidActiveMode = "Active mode is not available for this account identity.";
|
|
19
22
|
const msgWorkIdentityRequiresClient = "A work identity can only be established from a client account.";
|
|
20
23
|
const msgInvalidWorkIdentity = "Work identity must be employee or employer.";
|
|
@@ -39,6 +42,33 @@ export class UsersFX {
|
|
|
39
42
|
}),
|
|
40
43
|
});
|
|
41
44
|
}
|
|
45
|
+
async createExternalUser(opts) {
|
|
46
|
+
const input = normalizeExternalUserInput(opts.in);
|
|
47
|
+
validateExternalUserInput(input);
|
|
48
|
+
const out = await this.users.insertOneUser({
|
|
49
|
+
in: {
|
|
50
|
+
...input,
|
|
51
|
+
account_identity: UserTypeExternal,
|
|
52
|
+
active_mode: UserTypeExternal,
|
|
53
|
+
privacy: {
|
|
54
|
+
is_searchable: false,
|
|
55
|
+
is_messageable: false,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
const id = requiredOperationID(out, msgCreatedExternalUserIDMissing);
|
|
60
|
+
return await this.findExternalUser(id);
|
|
61
|
+
}
|
|
62
|
+
async searchExternalUsers(opts) {
|
|
63
|
+
const { uid, ...searchOpts } = opts;
|
|
64
|
+
return await runSearch({
|
|
65
|
+
...searchOpts,
|
|
66
|
+
search: async (opts) => await this.users.searchManyExternalUsers({
|
|
67
|
+
...opts,
|
|
68
|
+
uid,
|
|
69
|
+
}),
|
|
70
|
+
});
|
|
71
|
+
}
|
|
42
72
|
async updateUserProfile(opts) {
|
|
43
73
|
const input = normalizeUserProfileInput(opts.in);
|
|
44
74
|
validateUserProfileInput(input);
|
|
@@ -145,6 +175,17 @@ export class UsersFX {
|
|
|
145
175
|
code,
|
|
146
176
|
});
|
|
147
177
|
}
|
|
178
|
+
async findExternalUser(id) {
|
|
179
|
+
const out = await this.users.findOneUser({ id });
|
|
180
|
+
const user = out.value;
|
|
181
|
+
if (user === undefined) {
|
|
182
|
+
throw errResolveFailed({
|
|
183
|
+
resource: resourceUser,
|
|
184
|
+
msg: msgExternalUserMissing,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
return user;
|
|
188
|
+
}
|
|
148
189
|
async updatedUser(uid) {
|
|
149
190
|
const out = await this.users.getByUID({ uid });
|
|
150
191
|
const user = out.value?.[0];
|
|
@@ -160,6 +201,44 @@ export class UsersFX {
|
|
|
160
201
|
export function newUsersFX(opts) {
|
|
161
202
|
return new UsersFX(opts);
|
|
162
203
|
}
|
|
204
|
+
function normalizeExternalUserInput(input) {
|
|
205
|
+
return {
|
|
206
|
+
...input,
|
|
207
|
+
username: normalizeUsername(input.username),
|
|
208
|
+
first_name: input.first_name.trim(),
|
|
209
|
+
last_name: input.last_name.trim(),
|
|
210
|
+
phone: input.phone.trim(),
|
|
211
|
+
company_name: input.company_name.trim(),
|
|
212
|
+
street: input.street.trim(),
|
|
213
|
+
city: input.city.trim(),
|
|
214
|
+
state: input.state.trim(),
|
|
215
|
+
postal_code: input.postal_code.trim(),
|
|
216
|
+
country: input.country.trim(),
|
|
217
|
+
formatted_address: input.formatted_address.trim(),
|
|
218
|
+
place_name: input.place_name.trim(),
|
|
219
|
+
place_id: input.place_id.trim(),
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
function validateExternalUserInput(input) {
|
|
223
|
+
if (!input.first_name) {
|
|
224
|
+
throw errRequired({
|
|
225
|
+
field: "first_name",
|
|
226
|
+
msg: msgFirstNameRequired,
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
if (!input.last_name) {
|
|
230
|
+
throw errRequired({
|
|
231
|
+
field: "last_name",
|
|
232
|
+
msg: msgLastNameRequired,
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
if (input.phone && !validatePhone(input.phone)) {
|
|
236
|
+
throw errValidation({
|
|
237
|
+
field: "phone",
|
|
238
|
+
msg: msgPhoneRequired,
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
}
|
|
163
242
|
function normalizeUserProfileInput(input) {
|
|
164
243
|
return {
|
|
165
244
|
first_name: input.first_name.trim(),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fabriktor/fx",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.85",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"typescript": "^6.0.3"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@fabriktor/client": "0.0.
|
|
21
|
-
"@fabriktor/schema": "0.0.
|
|
20
|
+
"@fabriktor/client": "0.0.72",
|
|
21
|
+
"@fabriktor/schema": "0.0.55"
|
|
22
22
|
}
|
|
23
23
|
}
|