@fabriktor/fx 0.0.90 → 0.0.92
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 -0
- package/dist/src/billable/billable.js +83 -13
- package/dist/src/core/search.d.ts +1 -0
- package/dist/src/core/search.js +15 -0
- package/dist/src/jobs/jobs.d.ts +3 -1
- package/dist/src/jobs/jobs.js +5 -1
- package/dist/src/preferences/preferences.d.ts +12 -0
- package/dist/src/preferences/preferences.js +34 -0
- package/package.json +1 -1
|
@@ -64,6 +64,7 @@ export type CreateTaxOptions = TaxInsertOptions;
|
|
|
64
64
|
export type ReplaceTaxOptions = TaxReplaceOptions;
|
|
65
65
|
export type SearchTaxesOptions = OwnerSearchOptions;
|
|
66
66
|
export type SearchTaxesPage = SearchPage<Tax>;
|
|
67
|
+
export type SearchAllTaxesOptions = Omit<SearchTaxesOptions, "page">;
|
|
67
68
|
export type CreateTmpBillNumberOptions = TmpBillNumberInsertOptions;
|
|
68
69
|
export type ReplaceTmpBillNumberOptions = TmpBillNumberReplaceOptions;
|
|
69
70
|
export type SearchTmpBillNumbersOptions = OwnerSearchOptions;
|
|
@@ -181,6 +182,7 @@ export interface BillableFXOperator {
|
|
|
181
182
|
createTax(opts: CreateTaxOptions): Promise<Tax>;
|
|
182
183
|
replaceTax(opts: ReplaceTaxOptions): Promise<Tax>;
|
|
183
184
|
searchTaxes(opts: SearchTaxesOptions): Promise<SearchTaxesPage>;
|
|
185
|
+
searchAllTaxes(opts: SearchAllTaxesOptions): Promise<Tax[]>;
|
|
184
186
|
createTmpBillNumber(opts: CreateTmpBillNumberOptions): Promise<TmpBillNumber>;
|
|
185
187
|
replaceTmpBillNumber(opts: ReplaceTmpBillNumberOptions): Promise<TmpBillNumber>;
|
|
186
188
|
searchTmpBillNumbers(opts: SearchTmpBillNumbersOptions): Promise<SearchTmpBillNumbersPage>;
|
|
@@ -236,6 +238,7 @@ export declare class BillableFX implements BillableFXOperator {
|
|
|
236
238
|
createTax(opts: CreateTaxOptions): Promise<Tax>;
|
|
237
239
|
replaceTax(opts: ReplaceTaxOptions): Promise<Tax>;
|
|
238
240
|
searchTaxes(opts: SearchTaxesOptions): Promise<SearchTaxesPage>;
|
|
241
|
+
searchAllTaxes(opts: SearchAllTaxesOptions): Promise<Tax[]>;
|
|
239
242
|
createTmpBillNumber(opts: CreateTmpBillNumberOptions): Promise<TmpBillNumber>;
|
|
240
243
|
replaceTmpBillNumber(opts: ReplaceTmpBillNumberOptions): Promise<TmpBillNumber>;
|
|
241
244
|
searchTmpBillNumbers(opts: SearchTmpBillNumbersOptions): Promise<SearchTmpBillNumbersPage>;
|
|
@@ -270,8 +273,15 @@ export declare class BillableFX implements BillableFXOperator {
|
|
|
270
273
|
private findVendorInvoice;
|
|
271
274
|
private findWarehouse;
|
|
272
275
|
}
|
|
276
|
+
export type BillableAccessRecord = {
|
|
277
|
+
owner_id: string;
|
|
278
|
+
employer_id?: string;
|
|
279
|
+
};
|
|
273
280
|
export declare function billableCanReadResource(context: BillableReadContext, resource: BillableReadResource): boolean;
|
|
274
281
|
export declare function billableCanCreateResource(context: BillableReadContext, resource: BillableReadResource): boolean;
|
|
282
|
+
export declare function billableCanWriteResource(context: BillableReadContext, resource: BillableReadResource): boolean;
|
|
283
|
+
export declare function billableCanWriteRecord(context: BillableReadContext, resource: BillableReadResource, record: BillableAccessRecord | null | undefined): boolean;
|
|
284
|
+
export declare function billableCanDeleteRecord(context: BillableReadContext, resource: BillableReadResource, record: BillableAccessRecord | null | undefined): boolean;
|
|
275
285
|
export declare function billableOwnsRecord(context: BillableReadContext, record: {
|
|
276
286
|
owner_id: string;
|
|
277
287
|
} | null | undefined): boolean;
|
|
@@ -8,7 +8,7 @@ import { BillTypeDynamic, BillTypeFixed, UserTypeEmployee, UserTypeEmployer, } f
|
|
|
8
8
|
import { errRequired, errResolveFailed, errValidation } from "../core/err.js";
|
|
9
9
|
import { requiredOperationID, resolvedID } from "../core/id.js";
|
|
10
10
|
import { runPreActionCheck } from "../core/pre-action.js";
|
|
11
|
-
import { runOwnerScopeFilteredSearch, runOwnerScopeSearch, runOwnerSearch, withOwnerQuery, } from "../core/search.js";
|
|
11
|
+
import { collectSearchResults, runOwnerScopeFilteredSearch, runOwnerScopeSearch, runOwnerSearch, withOwnerQuery, } from "../core/search.js";
|
|
12
12
|
const resourceBill = "bill";
|
|
13
13
|
const msgCreatedBillIDMissing = "Created bill response did not contain an ID.";
|
|
14
14
|
const msgBillMissing = "Bill could not be resolved after the mutation.";
|
|
@@ -281,6 +281,12 @@ export class BillableFX {
|
|
|
281
281
|
search: (searchOpts) => this.billable.searchManyTaxes(searchOpts),
|
|
282
282
|
});
|
|
283
283
|
}
|
|
284
|
+
async searchAllTaxes(opts) {
|
|
285
|
+
return await collectSearchResults((page) => this.searchTaxes({
|
|
286
|
+
...opts,
|
|
287
|
+
page,
|
|
288
|
+
}));
|
|
289
|
+
}
|
|
284
290
|
async createTmpBillNumber(opts) {
|
|
285
291
|
const out = await this.billable.insertOneTmpBillNumber(opts);
|
|
286
292
|
const id = requiredOperationID(out, msgCreatedTmpBillNumberIDMissing);
|
|
@@ -596,19 +602,79 @@ export class BillableFX {
|
|
|
596
602
|
return value;
|
|
597
603
|
}
|
|
598
604
|
}
|
|
605
|
+
const billableResourceAccessPolicy = {
|
|
606
|
+
[BillableReadResource.Bill]: {
|
|
607
|
+
employee_read: false,
|
|
608
|
+
employee_write: false,
|
|
609
|
+
},
|
|
610
|
+
[BillableReadResource.BillableFolder]: {
|
|
611
|
+
employee_read: false,
|
|
612
|
+
employee_write: false,
|
|
613
|
+
},
|
|
614
|
+
[BillableReadResource.Charge]: {
|
|
615
|
+
employee_read: true,
|
|
616
|
+
employee_write: true,
|
|
617
|
+
},
|
|
618
|
+
[BillableReadResource.Equipment]: {
|
|
619
|
+
employee_read: true,
|
|
620
|
+
employee_write: false,
|
|
621
|
+
},
|
|
622
|
+
[BillableReadResource.Item]: {
|
|
623
|
+
employee_read: true,
|
|
624
|
+
employee_write: false,
|
|
625
|
+
},
|
|
626
|
+
[BillableReadResource.LaborRate]: {
|
|
627
|
+
employee_read: false,
|
|
628
|
+
employee_write: false,
|
|
629
|
+
},
|
|
630
|
+
[BillableReadResource.MeterReading]: {
|
|
631
|
+
employee_read: true,
|
|
632
|
+
employee_write: true,
|
|
633
|
+
},
|
|
634
|
+
[BillableReadResource.Quantifier]: {
|
|
635
|
+
employee_read: true,
|
|
636
|
+
employee_write: false,
|
|
637
|
+
},
|
|
638
|
+
[BillableReadResource.Tax]: {
|
|
639
|
+
employee_read: false,
|
|
640
|
+
employee_write: false,
|
|
641
|
+
},
|
|
642
|
+
[BillableReadResource.TmpBillNumber]: {
|
|
643
|
+
employee_read: false,
|
|
644
|
+
employee_write: false,
|
|
645
|
+
},
|
|
646
|
+
[BillableReadResource.VendorInvoice]: {
|
|
647
|
+
employee_read: false,
|
|
648
|
+
employee_write: false,
|
|
649
|
+
},
|
|
650
|
+
[BillableReadResource.Warehouse]: {
|
|
651
|
+
employee_read: true,
|
|
652
|
+
employee_write: false,
|
|
653
|
+
},
|
|
654
|
+
};
|
|
599
655
|
export function billableCanReadResource(context, resource) {
|
|
600
|
-
if (context.active_mode
|
|
656
|
+
if (context.active_mode === UserTypeEmployer) {
|
|
601
657
|
return true;
|
|
602
658
|
}
|
|
603
|
-
return
|
|
659
|
+
return (context.active_mode === UserTypeEmployee &&
|
|
660
|
+
billableResourceAccessPolicy[resource].employee_read);
|
|
604
661
|
}
|
|
605
662
|
export function billableCanCreateResource(context, resource) {
|
|
663
|
+
return billableCanWriteResource(context, resource);
|
|
664
|
+
}
|
|
665
|
+
export function billableCanWriteResource(context, resource) {
|
|
606
666
|
if (context.active_mode === UserTypeEmployer) {
|
|
607
667
|
return true;
|
|
608
668
|
}
|
|
609
669
|
return (context.active_mode === UserTypeEmployee &&
|
|
610
|
-
|
|
611
|
-
|
|
670
|
+
billableResourceAccessPolicy[resource].employee_write);
|
|
671
|
+
}
|
|
672
|
+
export function billableCanWriteRecord(context, resource, record) {
|
|
673
|
+
return (billableCanWriteResource(context, resource) &&
|
|
674
|
+
billableRecordBelongsToActor(context, resource, record));
|
|
675
|
+
}
|
|
676
|
+
export function billableCanDeleteRecord(context, resource, record) {
|
|
677
|
+
return billableCanWriteRecord(context, resource, record);
|
|
612
678
|
}
|
|
613
679
|
export function billableOwnsRecord(context, record) {
|
|
614
680
|
return record !== null && record !== undefined && record.owner_id === context.owner_id;
|
|
@@ -616,14 +682,18 @@ export function billableOwnsRecord(context, record) {
|
|
|
616
682
|
export function billableCatalogOwnerIDs(context) {
|
|
617
683
|
return catalogOwnerIDs(context);
|
|
618
684
|
}
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
685
|
+
function billableRecordBelongsToActor(context, resource, record) {
|
|
686
|
+
if (record === null || record === undefined) {
|
|
687
|
+
return false;
|
|
688
|
+
}
|
|
689
|
+
if (record.owner_id === context.owner_id) {
|
|
690
|
+
return true;
|
|
691
|
+
}
|
|
692
|
+
return (context.active_mode === UserTypeEmployer &&
|
|
693
|
+
(resource === BillableReadResource.Charge ||
|
|
694
|
+
resource === BillableReadResource.MeterReading) &&
|
|
695
|
+
record.employer_id === context.owner_id);
|
|
696
|
+
}
|
|
627
697
|
function catalogOwnerIDs(context, employer_scope_ids) {
|
|
628
698
|
if (context.active_mode === UserTypeEmployee) {
|
|
629
699
|
return restrictOwnerIDs(context.employment.active_employer_ids, employer_scope_ids);
|
|
@@ -41,6 +41,7 @@ export type SearchPage<T> = {
|
|
|
41
41
|
next_page: number;
|
|
42
42
|
done: boolean;
|
|
43
43
|
};
|
|
44
|
+
export declare function collectSearchResults<T>(search: (page: number) => Promise<SearchPage<T>>): Promise<T[]>;
|
|
44
45
|
export declare function withOwnerQuery(owner_id: string, query?: SearchQuery): SearchQuery;
|
|
45
46
|
export declare function runOwnerSearch<T>(opts: RunOwnerSearchOptions<T>): Promise<SearchPage<T>>;
|
|
46
47
|
export declare function runOwnerScopeSearch<T extends {
|
package/dist/src/core/search.js
CHANGED
|
@@ -6,6 +6,21 @@
|
|
|
6
6
|
import { OwnerIDKey, SearchPageKey, SearchPerPageKey, SearchQueryKey, SearchResultResultsKey, } from "@fabriktor/schema";
|
|
7
7
|
const firstSearchPage = 1;
|
|
8
8
|
const defaultSearchPerPage = 30;
|
|
9
|
+
export async function collectSearchResults(search) {
|
|
10
|
+
const results = [];
|
|
11
|
+
let page = firstSearchPage;
|
|
12
|
+
while (true) {
|
|
13
|
+
const out = await search(page);
|
|
14
|
+
results.push(...out.results);
|
|
15
|
+
if (!out.has_more) {
|
|
16
|
+
return results;
|
|
17
|
+
}
|
|
18
|
+
if (out.next_page <= page) {
|
|
19
|
+
return results;
|
|
20
|
+
}
|
|
21
|
+
page = out.next_page;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
9
24
|
export function withOwnerQuery(owner_id, query) {
|
|
10
25
|
return {
|
|
11
26
|
...query,
|
package/dist/src/jobs/jobs.d.ts
CHANGED
|
@@ -32,7 +32,9 @@ export type SearchLocationsOptions = OwnerSearchOptions & {
|
|
|
32
32
|
export type SearchAccessibleLocationsOptions = SearchOptions & {
|
|
33
33
|
is_archived?: boolean;
|
|
34
34
|
};
|
|
35
|
-
export type SearchJobProgramsOptions = OwnerSearchOptions
|
|
35
|
+
export type SearchJobProgramsOptions = OwnerSearchOptions & {
|
|
36
|
+
location_id?: string;
|
|
37
|
+
};
|
|
36
38
|
export type SearchJobsOptions = OwnerSearchOptions & {
|
|
37
39
|
location_id?: string;
|
|
38
40
|
};
|
package/dist/src/jobs/jobs.js
CHANGED
|
@@ -168,8 +168,12 @@ export class JobsFX {
|
|
|
168
168
|
};
|
|
169
169
|
}
|
|
170
170
|
async searchJobPrograms(opts) {
|
|
171
|
+
const { location_id, ...searchOpts } = opts;
|
|
171
172
|
return await runOwnerSearch({
|
|
172
|
-
...
|
|
173
|
+
...searchOpts,
|
|
174
|
+
query: location_id === undefined
|
|
175
|
+
? undefined
|
|
176
|
+
: queryParams({ job_location_id: location_id }),
|
|
173
177
|
search: (searchOpts) => this.jobs.searchManyJobPrograms(searchOpts),
|
|
174
178
|
});
|
|
175
179
|
}
|
|
@@ -57,6 +57,16 @@ export type SavePrefCompanyOptions = {
|
|
|
57
57
|
current: PrefCompany;
|
|
58
58
|
in: InPrefCompany;
|
|
59
59
|
};
|
|
60
|
+
export declare const PrefCompanyDocumentNote: {
|
|
61
|
+
readonly Invoice: "invoice";
|
|
62
|
+
readonly Estimate: "estimate";
|
|
63
|
+
};
|
|
64
|
+
export type PrefCompanyDocumentNote = (typeof PrefCompanyDocumentNote)[keyof typeof PrefCompanyDocumentNote];
|
|
65
|
+
export type SavePrefCompanyDocumentNoteOptions = {
|
|
66
|
+
current: PrefCompany;
|
|
67
|
+
kind: PrefCompanyDocumentNote;
|
|
68
|
+
note: string;
|
|
69
|
+
};
|
|
60
70
|
export type GetPrefLanguageOptions = {
|
|
61
71
|
owner_id: string;
|
|
62
72
|
};
|
|
@@ -85,6 +95,7 @@ export interface PreferencesFXOperator {
|
|
|
85
95
|
replacePrefCompany(opts: ReplacePrefCompanyOptions): Promise<PrefCompany>;
|
|
86
96
|
getPrefCompany(opts: GetPrefCompanyOptions): Promise<PrefCompany>;
|
|
87
97
|
savePrefCompany(opts: SavePrefCompanyOptions): Promise<PrefCompany>;
|
|
98
|
+
savePrefCompanyDocumentNote(opts: SavePrefCompanyDocumentNoteOptions): Promise<PrefCompany>;
|
|
88
99
|
createPrefVisibility(opts: CreatePrefVisibilityOptions): Promise<PrefVisibility>;
|
|
89
100
|
replacePrefVisibility(opts: ReplacePrefVisibilityOptions): Promise<PrefVisibility>;
|
|
90
101
|
createPrefLanguage(opts: CreatePrefLanguageOptions): Promise<PrefLanguage>;
|
|
@@ -119,6 +130,7 @@ export declare class PreferencesFX implements PreferencesFXOperator {
|
|
|
119
130
|
replacePrefCompany(opts: ReplacePrefCompanyOptions): Promise<PrefCompany>;
|
|
120
131
|
getPrefCompany(opts: GetPrefCompanyOptions): Promise<PrefCompany>;
|
|
121
132
|
savePrefCompany(opts: SavePrefCompanyOptions): Promise<PrefCompany>;
|
|
133
|
+
savePrefCompanyDocumentNote(opts: SavePrefCompanyDocumentNoteOptions): Promise<PrefCompany>;
|
|
122
134
|
createPrefVisibility(opts: CreatePrefVisibilityOptions): Promise<PrefVisibility>;
|
|
123
135
|
replacePrefVisibility(opts: ReplacePrefVisibilityOptions): Promise<PrefVisibility>;
|
|
124
136
|
createPrefLanguage(opts: CreatePrefLanguageOptions): Promise<PrefLanguage>;
|
|
@@ -34,6 +34,10 @@ const msgPrefEmailMissing = "Email preference could not be resolved after the mu
|
|
|
34
34
|
const resourcePrefTutorial = "pref_tutorial";
|
|
35
35
|
const msgCreatedPrefTutorialIDMissing = "Created tutorial preference response did not contain an ID.";
|
|
36
36
|
const msgPrefTutorialMissing = "Tutorial preference could not be resolved after the mutation.";
|
|
37
|
+
export const PrefCompanyDocumentNote = {
|
|
38
|
+
Invoice: "invoice",
|
|
39
|
+
Estimate: "estimate",
|
|
40
|
+
};
|
|
37
41
|
export class PreferencesFX {
|
|
38
42
|
preferences;
|
|
39
43
|
constructor(opts) {
|
|
@@ -120,6 +124,16 @@ export class PreferencesFX {
|
|
|
120
124
|
? await this.createPrefCompany({ in: input })
|
|
121
125
|
: await this.replacePrefCompany({ id: opts.current.id, in: input });
|
|
122
126
|
}
|
|
127
|
+
async savePrefCompanyDocumentNote(opts) {
|
|
128
|
+
const input = prefCompanyInput(opts.current);
|
|
129
|
+
if (opts.kind === PrefCompanyDocumentNote.Invoice) {
|
|
130
|
+
input.invoice_note = opts.note;
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
input.estimate_note = opts.note;
|
|
134
|
+
}
|
|
135
|
+
return await this.savePrefCompany({ current: opts.current, in: input });
|
|
136
|
+
}
|
|
123
137
|
async createPrefVisibility(opts) {
|
|
124
138
|
const out = await this.preferences.insertOnePrefVisibility(opts);
|
|
125
139
|
const id = requiredOperationID(out, msgCreatedPrefVisibilityIDMissing);
|
|
@@ -361,6 +375,26 @@ export class PreferencesFX {
|
|
|
361
375
|
return pref_tutorial;
|
|
362
376
|
}
|
|
363
377
|
}
|
|
378
|
+
function prefCompanyInput(pref) {
|
|
379
|
+
return {
|
|
380
|
+
is_default: pref.is_default,
|
|
381
|
+
pause_duration_in_minutes: pref.pause_duration_in_minutes,
|
|
382
|
+
lunch_duration_in_minutes: pref.lunch_duration_in_minutes,
|
|
383
|
+
work_day_start_hour: pref.work_day_start_hour,
|
|
384
|
+
work_day_end_hour: pref.work_day_end_hour,
|
|
385
|
+
max_work_hours: pref.max_work_hours,
|
|
386
|
+
max_transport_hours: pref.max_transport_hours,
|
|
387
|
+
non_remunerated_transport_hours: pref.non_remunerated_transport_hours,
|
|
388
|
+
salary_rate: pref.salary_rate,
|
|
389
|
+
transport_rate: pref.transport_rate,
|
|
390
|
+
vendor_invoice_rate: pref.vendor_invoice_rate,
|
|
391
|
+
period_offset: pref.period_offset,
|
|
392
|
+
payment_terms: pref.payment_terms,
|
|
393
|
+
invoice_note: pref.invoice_note,
|
|
394
|
+
estimate_note: pref.estimate_note,
|
|
395
|
+
tax_ids: pref.tax_ids.map((taxID) => ({ ...taxID })),
|
|
396
|
+
};
|
|
397
|
+
}
|
|
364
398
|
export function newPreferencesFX(opts) {
|
|
365
399
|
return new PreferencesFX(opts);
|
|
366
400
|
}
|