@fabriktor/fx 0.0.93 → 0.0.95
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 +10 -17
- package/dist/src/billable/billable.js +35 -16
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/users/email.d.ts +2 -0
- package/dist/src/users/email.js +11 -0
- package/dist/src/users/users.js +16 -0
- package/package.json +4 -3
|
@@ -4,8 +4,6 @@ import type { ContactsFXOperator, EmploymentOwnerScope } from "../contacts/conta
|
|
|
4
4
|
import { type OwnerSearchOptions, type SearchOptions, type SearchPage, type SearchQuery } from "../core/search.js";
|
|
5
5
|
type GenerateBillPayload = Parameters<BillableOperator["generateBill"]>[0];
|
|
6
6
|
export type SalaryEstimateInput = GenerateBillPayload["salary_estimate"];
|
|
7
|
-
type BillInsertOptions = Parameters<BillableOperator["insertOneBill"]>[0];
|
|
8
|
-
type BillReplaceOptions = Parameters<BillableOperator["replaceOneBill"]>[0];
|
|
9
7
|
type BillableFolderInsertOptions = Parameters<BillableOperator["insertOneBillableFolder"]>[0];
|
|
10
8
|
type BillableFolderReplaceOptions = Parameters<BillableOperator["replaceOneBillableFolder"]>[0];
|
|
11
9
|
type ChargeInsertOptions = Parameters<BillableOperator["insertOneCharge"]>[0];
|
|
@@ -28,8 +26,6 @@ type VendorInvoiceInsertOptions = Parameters<BillableOperator["insertOneVendorIn
|
|
|
28
26
|
type VendorInvoiceReplaceOptions = Parameters<BillableOperator["replaceOneVendorInvoice"]>[0];
|
|
29
27
|
type WarehouseInsertOptions = Parameters<BillableOperator["insertOneWarehouse"]>[0];
|
|
30
28
|
type WarehouseReplaceOptions = Parameters<BillableOperator["replaceOneWarehouse"]>[0];
|
|
31
|
-
export type CreateBillOptions = BillInsertOptions;
|
|
32
|
-
export type ReplaceBillOptions = BillReplaceOptions;
|
|
33
29
|
export type SearchBillsOptions = OwnerSearchOptions;
|
|
34
30
|
export type SearchBillsPage = SearchPage<Bill>;
|
|
35
31
|
export type CreateBillableFolderOptions = BillableFolderInsertOptions;
|
|
@@ -137,11 +133,8 @@ export type GenerateDynamicBillOptions = {
|
|
|
137
133
|
exclude_billed?: boolean;
|
|
138
134
|
};
|
|
139
135
|
export declare function zeroSalaryEstimate(): SalaryEstimateInput;
|
|
140
|
-
export type
|
|
141
|
-
|
|
142
|
-
};
|
|
143
|
-
export type CancelBillOptions = {
|
|
144
|
-
in: GenerateBillPayload;
|
|
136
|
+
export type BillActionOptions = {
|
|
137
|
+
bill: Bill;
|
|
145
138
|
};
|
|
146
139
|
export type VendorInvoiceFromBillOptions = Parameters<BillableOperator["vendorInvoiceFromBill"]>[0];
|
|
147
140
|
export declare const BillablePreActionReason: {
|
|
@@ -150,8 +143,6 @@ export declare const BillablePreActionReason: {
|
|
|
150
143
|
export type BillablePreActionReason = (typeof BillablePreActionReason)[keyof typeof BillablePreActionReason];
|
|
151
144
|
export interface BillableFXOperator {
|
|
152
145
|
loadReadContext(opts: LoadBillableReadContextOptions): Promise<BillableReadContext>;
|
|
153
|
-
createBill(opts: CreateBillOptions): Promise<Bill>;
|
|
154
|
-
replaceBill(opts: ReplaceBillOptions): Promise<Bill>;
|
|
155
146
|
searchBills(opts: SearchBillsOptions): Promise<SearchBillsPage>;
|
|
156
147
|
createBillableFolder(opts: CreateBillableFolderOptions): Promise<BillableFolder>;
|
|
157
148
|
replaceBillableFolder(opts: ReplaceBillableFolderOptions): Promise<BillableFolder>;
|
|
@@ -197,8 +188,9 @@ export interface BillableFXOperator {
|
|
|
197
188
|
acceptFixedEstimate(opts: AcceptFixedEstimateOptions): Promise<Bill>;
|
|
198
189
|
generateDynamicEstimate(opts: GenerateDynamicEstimateOptions): Promise<Bill>;
|
|
199
190
|
generateDynamicBill(opts: GenerateDynamicBillOptions): Promise<Bill>;
|
|
200
|
-
|
|
201
|
-
cancelBill(opts:
|
|
191
|
+
completeBill(opts: BillActionOptions): Promise<Bill>;
|
|
192
|
+
cancelBill(opts: BillActionOptions): Promise<Bill>;
|
|
193
|
+
retryBillReport(opts: BillActionOptions): Promise<Bill>;
|
|
202
194
|
vendorInvoiceFromBill(opts: VendorInvoiceFromBillOptions): Promise<VendorInvoice>;
|
|
203
195
|
}
|
|
204
196
|
export declare class BillableFX implements BillableFXOperator {
|
|
@@ -206,8 +198,6 @@ export declare class BillableFX implements BillableFXOperator {
|
|
|
206
198
|
private contacts_fx;
|
|
207
199
|
constructor(opts: BillableFXOptions);
|
|
208
200
|
loadReadContext(opts: LoadBillableReadContextOptions): Promise<BillableReadContext>;
|
|
209
|
-
createBill(opts: CreateBillOptions): Promise<Bill>;
|
|
210
|
-
replaceBill(opts: ReplaceBillOptions): Promise<Bill>;
|
|
211
201
|
searchBills(opts: SearchBillsOptions): Promise<SearchBillsPage>;
|
|
212
202
|
createBillableFolder(opts: CreateBillableFolderOptions): Promise<BillableFolder>;
|
|
213
203
|
replaceBillableFolder(opts: ReplaceBillableFolderOptions): Promise<BillableFolder>;
|
|
@@ -253,8 +243,9 @@ export declare class BillableFX implements BillableFXOperator {
|
|
|
253
243
|
acceptFixedEstimate(opts: AcceptFixedEstimateOptions): Promise<Bill>;
|
|
254
244
|
generateDynamicEstimate(opts: GenerateDynamicEstimateOptions): Promise<Bill>;
|
|
255
245
|
generateDynamicBill(opts: GenerateDynamicBillOptions): Promise<Bill>;
|
|
256
|
-
|
|
257
|
-
cancelBill(opts:
|
|
246
|
+
completeBill(opts: BillActionOptions): Promise<Bill>;
|
|
247
|
+
cancelBill(opts: BillActionOptions): Promise<Bill>;
|
|
248
|
+
retryBillReport(opts: BillActionOptions): Promise<Bill>;
|
|
258
249
|
vendorInvoiceFromBill(opts: VendorInvoiceFromBillOptions): Promise<VendorInvoice>;
|
|
259
250
|
private generateBill;
|
|
260
251
|
private checkVendorInvoiceNumber;
|
|
@@ -287,4 +278,6 @@ export declare function billableOwnsRecord(context: BillableReadContext, record:
|
|
|
287
278
|
} | null | undefined): boolean;
|
|
288
279
|
export declare function billableCatalogOwnerIDs(context: BillableReadContext): string[];
|
|
289
280
|
export declare function newBillableFX(opts: BillableFXOptions): BillableFX;
|
|
281
|
+
export declare function billableCanCompleteBill(bill: Bill): boolean;
|
|
282
|
+
export declare function billableCanCancelBill(bill: Bill): boolean;
|
|
290
283
|
export {};
|
|
@@ -51,6 +51,10 @@ const msgFixedEstimateRequired = "Only a fixed estimate can be accepted.";
|
|
|
51
51
|
const msgInternalFixedEstimateRequired = "Only an internal fixed estimate can be accepted in Fabriktor.";
|
|
52
52
|
const msgCanceledEstimate = "A canceled fixed estimate cannot be accepted.";
|
|
53
53
|
const msgEstimateAlreadyAccepted = "This fixed estimate is already accepted.";
|
|
54
|
+
const msgBillIDRequired = "Bill ID is required.";
|
|
55
|
+
const msgBillIDMissing = "Bill response did not contain an ID.";
|
|
56
|
+
const msgCompletableBillRequired = "Only an uncanceled invoice can be completed.";
|
|
57
|
+
const msgAcceptedEstimateCancellation = "Cancel the accepted invoice instead of its estimate.";
|
|
54
58
|
export const BillableReadResource = {
|
|
55
59
|
Bill: "bill",
|
|
56
60
|
BillableFolder: "billable_folder",
|
|
@@ -102,15 +106,6 @@ export class BillableFX {
|
|
|
102
106
|
employment,
|
|
103
107
|
};
|
|
104
108
|
}
|
|
105
|
-
async createBill(opts) {
|
|
106
|
-
const out = await this.billable.insertOneBill(opts);
|
|
107
|
-
const id = requiredOperationID(out, msgCreatedBillIDMissing);
|
|
108
|
-
return await this.findBill(id);
|
|
109
|
-
}
|
|
110
|
-
async replaceBill(opts) {
|
|
111
|
-
await this.billable.replaceOneBill(opts);
|
|
112
|
-
return await this.findBill(opts.id);
|
|
113
|
-
}
|
|
114
109
|
async searchBills(opts) {
|
|
115
110
|
return await runOwnerSearch({
|
|
116
111
|
...opts,
|
|
@@ -381,15 +376,26 @@ export class BillableFX {
|
|
|
381
376
|
salary_estimate: zeroSalaryEstimate(),
|
|
382
377
|
}));
|
|
383
378
|
}
|
|
384
|
-
async
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
379
|
+
async completeBill(opts) {
|
|
380
|
+
const bill_id = billActionID(opts);
|
|
381
|
+
if (opts.bill.is_estimate || opts.bill.is_canceled) {
|
|
382
|
+
throw errValidation({ field: "bill", msg: msgCompletableBillRequired });
|
|
383
|
+
}
|
|
384
|
+
const out = await this.billable.completeBill({ bill_id });
|
|
385
|
+
return await this.findBill(requiredOperationID(out, msgBillIDMissing));
|
|
388
386
|
}
|
|
389
387
|
async cancelBill(opts) {
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
388
|
+
const bill_id = billActionID(opts);
|
|
389
|
+
if (opts.bill.is_estimate && resolvedID(opts.bill.accepted_bill_id) !== undefined) {
|
|
390
|
+
throw errValidation({ field: "bill", msg: msgAcceptedEstimateCancellation });
|
|
391
|
+
}
|
|
392
|
+
const out = await this.billable.cancelBill({ bill_id });
|
|
393
|
+
return await this.findBill(requiredOperationID(out, msgBillIDMissing));
|
|
394
|
+
}
|
|
395
|
+
async retryBillReport(opts) {
|
|
396
|
+
const bill_id = billActionID(opts);
|
|
397
|
+
const out = await this.billable.retryBillReport({ bill_id });
|
|
398
|
+
return await this.findBill(requiredOperationID(out, msgBillIDMissing));
|
|
393
399
|
}
|
|
394
400
|
async vendorInvoiceFromBill(opts) {
|
|
395
401
|
const out = await this.billable.vendorInvoiceFromBill(opts);
|
|
@@ -737,6 +743,19 @@ function timestamp(value) {
|
|
|
737
743
|
export function newBillableFX(opts) {
|
|
738
744
|
return new BillableFX(opts);
|
|
739
745
|
}
|
|
746
|
+
function billActionID(opts) {
|
|
747
|
+
const id = resolvedID(opts.bill.id);
|
|
748
|
+
if (id === undefined) {
|
|
749
|
+
throw errRequired({ field: "bill", msg: msgBillIDRequired });
|
|
750
|
+
}
|
|
751
|
+
return id;
|
|
752
|
+
}
|
|
753
|
+
export function billableCanCompleteBill(bill) {
|
|
754
|
+
return !bill.is_estimate && !bill.is_canceled && !bill.is_location_achieved;
|
|
755
|
+
}
|
|
756
|
+
export function billableCanCancelBill(bill) {
|
|
757
|
+
return !bill.is_canceled && (!bill.is_estimate || resolvedID(bill.accepted_bill_id) === undefined);
|
|
758
|
+
}
|
|
740
759
|
function fixedEstimateID(opts) {
|
|
741
760
|
const estimate = opts.estimate;
|
|
742
761
|
const id = resolvedID(estimate.id);
|
package/dist/src/index.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ export * from "./routes/routes.js";
|
|
|
25
25
|
export * from "./session/session.js";
|
|
26
26
|
export * from "./storage/storage.js";
|
|
27
27
|
export * from "./timesheets/timesheets.js";
|
|
28
|
+
export * from "./users/email.js";
|
|
28
29
|
export * from "./users/phone.js";
|
|
29
30
|
export * from "./users/username.js";
|
|
30
31
|
export * from "./users/users.js";
|
package/dist/src/index.js
CHANGED
|
@@ -25,6 +25,7 @@ export * from "./routes/routes.js";
|
|
|
25
25
|
export * from "./session/session.js";
|
|
26
26
|
export * from "./storage/storage.js";
|
|
27
27
|
export * from "./timesheets/timesheets.js";
|
|
28
|
+
export * from "./users/email.js";
|
|
28
29
|
export * from "./users/phone.js";
|
|
29
30
|
export * from "./users/username.js";
|
|
30
31
|
export * from "./users/users.js";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Copyright (C) Fabriktor, Inc. 2025-present.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
4
|
+
// not use this file except in compliance with the License. You may obtain
|
|
5
|
+
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
export function normalizeEmail(value) {
|
|
7
|
+
return value.trim();
|
|
8
|
+
}
|
|
9
|
+
export function isValidEmail(value) {
|
|
10
|
+
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(normalizeEmail(value));
|
|
11
|
+
}
|
package/dist/src/users/users.js
CHANGED
|
@@ -8,12 +8,15 @@ import { errRequired, errResolveFailed, errValidation, } from "../core/err.js";
|
|
|
8
8
|
import { requiredOperationID } from "../core/id.js";
|
|
9
9
|
import { runSearch, } from "../core/search.js";
|
|
10
10
|
import { normalizePhone, normalizePhoneCode, validatePhone, validatePhoneCode, } from "./phone.js";
|
|
11
|
+
import { normalizeEmail, isValidEmail } from "./email.js";
|
|
11
12
|
import { normalizeUsername, validateUsernameFormat } from "./username.js";
|
|
12
13
|
const msgUnableToResolveUsername = "Unable to resolve username.";
|
|
13
14
|
const msgPhoneRequired = "Phone number is required.";
|
|
14
15
|
const msgPhoneCodeRequired = "Verification code is required.";
|
|
15
16
|
const msgFirstNameRequired = "First name is required.";
|
|
16
17
|
const msgLastNameRequired = "Last name is required.";
|
|
18
|
+
const msgEmailRequired = "Email is required.";
|
|
19
|
+
const msgEmailInvalid = "Email address is invalid.";
|
|
17
20
|
const msgAddressRequired = "A complete address is required.";
|
|
18
21
|
const msgUserMissingAfterUpdate = "User could not be resolved after the account update.";
|
|
19
22
|
const msgCreatedExternalUserIDMissing = "Created external user response did not contain an ID.";
|
|
@@ -207,6 +210,7 @@ function normalizeExternalUserInput(input) {
|
|
|
207
210
|
username: normalizeUsername(input.username),
|
|
208
211
|
first_name: input.first_name.trim(),
|
|
209
212
|
last_name: input.last_name.trim(),
|
|
213
|
+
email: normalizeEmail(input.email),
|
|
210
214
|
phone: input.phone.trim(),
|
|
211
215
|
company_name: input.company_name.trim(),
|
|
212
216
|
street: input.street.trim(),
|
|
@@ -232,6 +236,18 @@ function validateExternalUserInput(input) {
|
|
|
232
236
|
msg: msgLastNameRequired,
|
|
233
237
|
});
|
|
234
238
|
}
|
|
239
|
+
if (!input.email) {
|
|
240
|
+
throw errRequired({
|
|
241
|
+
field: "email",
|
|
242
|
+
msg: msgEmailRequired,
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
if (!isValidEmail(input.email)) {
|
|
246
|
+
throw errValidation({
|
|
247
|
+
field: "email",
|
|
248
|
+
msg: msgEmailInvalid,
|
|
249
|
+
});
|
|
250
|
+
}
|
|
235
251
|
if (input.phone && !validatePhone(input.phone)) {
|
|
236
252
|
throw errValidation({
|
|
237
253
|
field: "phone",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fabriktor/fx",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.95",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
"typescript": "^6.0.3"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@fabriktor/client": "0.0.
|
|
21
|
-
"@fabriktor/
|
|
20
|
+
"@fabriktor/client": "0.0.76",
|
|
21
|
+
"@fabriktor/fx": "0.0.94",
|
|
22
|
+
"@fabriktor/schema": "0.0.59"
|
|
22
23
|
}
|
|
23
24
|
}
|