@fabriktor/client 0.0.28 → 0.0.31

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.
Files changed (43) hide show
  1. package/dist/src/billable/billable.d.ts +213 -0
  2. package/dist/src/billable/billable.js +441 -0
  3. package/dist/src/calls/calls.d.ts +34 -0
  4. package/dist/src/calls/calls.js +65 -0
  5. package/dist/src/chat/chat.d.ts +97 -0
  6. package/dist/src/chat/chat.js +224 -0
  7. package/dist/src/contacts/contacts.d.ts +37 -0
  8. package/dist/src/contacts/contacts.js +94 -0
  9. package/dist/src/core/col.d.ts +7 -1
  10. package/dist/src/core/col.js +29 -14
  11. package/dist/src/core/crud.d.ts +1 -1
  12. package/dist/src/core/crud.js +1 -1
  13. package/dist/src/core/http.d.ts +3 -4
  14. package/dist/src/core/http.js +3 -3
  15. package/dist/src/core/idempotency.js +1 -1
  16. package/dist/src/core/multipart.d.ts +25 -0
  17. package/dist/src/core/multipart.js +93 -0
  18. package/dist/src/feed/feed.d.ts +65 -0
  19. package/dist/src/feed/feed.js +130 -0
  20. package/dist/src/fulfillments/fulfillments.d.ts +36 -0
  21. package/dist/src/fulfillments/fulfillments.js +68 -0
  22. package/dist/src/index.d.ts +14 -0
  23. package/dist/src/index.js +14 -0
  24. package/dist/src/jobs/jobs.d.ts +69 -0
  25. package/dist/src/jobs/jobs.js +143 -0
  26. package/dist/src/marketplace/marketplace.d.ts +49 -0
  27. package/dist/src/marketplace/marketplace.js +94 -0
  28. package/dist/src/payments/payments.d.ts +154 -0
  29. package/dist/src/payments/payments.js +328 -0
  30. package/dist/src/payrolls/payrolls.d.ts +179 -0
  31. package/dist/src/payrolls/payrolls.js +380 -0
  32. package/dist/src/processes/processes.d.ts +3 -3
  33. package/dist/src/routes/routes.d.ts +93 -0
  34. package/dist/src/routes/routes.js +185 -0
  35. package/dist/src/storage/storage.d.ts +124 -0
  36. package/dist/src/storage/storage.js +242 -0
  37. package/dist/src/timesheets/timesheets.d.ts +49 -0
  38. package/dist/src/timesheets/timesheets.js +105 -0
  39. package/dist/src/users/tmp_phones.d.ts +1 -1
  40. package/dist/src/users/tmp_usernames.d.ts +5 -4
  41. package/dist/src/users/users.d.ts +13 -12
  42. package/dist/src/users/users.js +4 -1
  43. package/package.json +3 -2
@@ -0,0 +1,124 @@
1
+ import { type Object as StorageObject, type OperationResult, type PLStorageDownload, type RPStorageUpload } from "@fabriktor/schema";
2
+ import type { TokenProvider } from "../core/auth.js";
3
+ import type { DeleteManyOptionsCRUD, DeleteOneOptionsCRUD, OperationResultOf } from "../core/crud.js";
4
+ import type { HTTPDoer } from "../core/http.js";
5
+ import { type MultipartDoer } from "../core/multipart.js";
6
+ export declare const storageCollections: readonly ["calls", "chat", "contacts", "jobs", "locations", "memos", "qr", "reports", "tickets", "users"];
7
+ export type StorageCollection = (typeof storageCollections)[number];
8
+ export type StorageUploadFile = File | {
9
+ blob: Blob;
10
+ filename: string;
11
+ };
12
+ export type UploadStorageOptions = {
13
+ owner_id: string;
14
+ uploader_id?: string;
15
+ full_quality?: boolean;
16
+ files: StorageUploadFile[];
17
+ };
18
+ export type DownloadStorageOptions = PLStorageDownload;
19
+ export type StorageClientOptions = {
20
+ http: HTTPDoer;
21
+ base_url: string;
22
+ get_token?: TokenProvider;
23
+ multipart?: MultipartDoer;
24
+ };
25
+ export interface StorageOperator {
26
+ upload(col: StorageCollection, opts: UploadStorageOptions): Promise<OperationResultOf<RPStorageUpload>>;
27
+ download(col: StorageCollection, opts: DownloadStorageOptions): Promise<OperationResultOf<StorageObject[]>>;
28
+ deleteOne(col: StorageCollection, opts: DeleteOneOptionsCRUD): Promise<OperationResult>;
29
+ deleteMany(col: StorageCollection, opts?: DeleteManyOptionsCRUD): Promise<OperationResultOf<number>>;
30
+ uploadCalls(opts: UploadStorageOptions): Promise<OperationResultOf<RPStorageUpload>>;
31
+ downloadCalls(opts: DownloadStorageOptions): Promise<OperationResultOf<StorageObject[]>>;
32
+ deleteOneCallObject(opts: DeleteOneOptionsCRUD): Promise<OperationResult>;
33
+ deleteManyCallObjects(opts?: DeleteManyOptionsCRUD): Promise<OperationResultOf<number>>;
34
+ uploadChat(opts: UploadStorageOptions): Promise<OperationResultOf<RPStorageUpload>>;
35
+ downloadChat(opts: DownloadStorageOptions): Promise<OperationResultOf<StorageObject[]>>;
36
+ deleteOneChatObject(opts: DeleteOneOptionsCRUD): Promise<OperationResult>;
37
+ deleteManyChatObjects(opts?: DeleteManyOptionsCRUD): Promise<OperationResultOf<number>>;
38
+ uploadContacts(opts: UploadStorageOptions): Promise<OperationResultOf<RPStorageUpload>>;
39
+ downloadContacts(opts: DownloadStorageOptions): Promise<OperationResultOf<StorageObject[]>>;
40
+ deleteOneContactObject(opts: DeleteOneOptionsCRUD): Promise<OperationResult>;
41
+ deleteManyContactObjects(opts?: DeleteManyOptionsCRUD): Promise<OperationResultOf<number>>;
42
+ uploadJobs(opts: UploadStorageOptions): Promise<OperationResultOf<RPStorageUpload>>;
43
+ downloadJobs(opts: DownloadStorageOptions): Promise<OperationResultOf<StorageObject[]>>;
44
+ deleteOneJobObject(opts: DeleteOneOptionsCRUD): Promise<OperationResult>;
45
+ deleteManyJobObjects(opts?: DeleteManyOptionsCRUD): Promise<OperationResultOf<number>>;
46
+ uploadLocations(opts: UploadStorageOptions): Promise<OperationResultOf<RPStorageUpload>>;
47
+ downloadLocations(opts: DownloadStorageOptions): Promise<OperationResultOf<StorageObject[]>>;
48
+ deleteOneLocationObject(opts: DeleteOneOptionsCRUD): Promise<OperationResult>;
49
+ deleteManyLocationObjects(opts?: DeleteManyOptionsCRUD): Promise<OperationResultOf<number>>;
50
+ uploadMemos(opts: UploadStorageOptions): Promise<OperationResultOf<RPStorageUpload>>;
51
+ downloadMemos(opts: DownloadStorageOptions): Promise<OperationResultOf<StorageObject[]>>;
52
+ deleteOneMemoObject(opts: DeleteOneOptionsCRUD): Promise<OperationResult>;
53
+ deleteManyMemoObjects(opts?: DeleteManyOptionsCRUD): Promise<OperationResultOf<number>>;
54
+ uploadQR(opts: UploadStorageOptions): Promise<OperationResultOf<RPStorageUpload>>;
55
+ downloadQR(opts: DownloadStorageOptions): Promise<OperationResultOf<StorageObject[]>>;
56
+ deleteOneQRObject(opts: DeleteOneOptionsCRUD): Promise<OperationResult>;
57
+ deleteManyQRObjects(opts?: DeleteManyOptionsCRUD): Promise<OperationResultOf<number>>;
58
+ uploadReports(opts: UploadStorageOptions): Promise<OperationResultOf<RPStorageUpload>>;
59
+ downloadReports(opts: DownloadStorageOptions): Promise<OperationResultOf<StorageObject[]>>;
60
+ deleteOneReportObject(opts: DeleteOneOptionsCRUD): Promise<OperationResult>;
61
+ deleteManyReportObjects(opts?: DeleteManyOptionsCRUD): Promise<OperationResultOf<number>>;
62
+ uploadTickets(opts: UploadStorageOptions): Promise<OperationResultOf<RPStorageUpload>>;
63
+ downloadTickets(opts: DownloadStorageOptions): Promise<OperationResultOf<StorageObject[]>>;
64
+ deleteOneTicketObject(opts: DeleteOneOptionsCRUD): Promise<OperationResult>;
65
+ deleteManyTicketObjects(opts?: DeleteManyOptionsCRUD): Promise<OperationResultOf<number>>;
66
+ uploadUsers(opts: UploadStorageOptions): Promise<OperationResultOf<RPStorageUpload>>;
67
+ downloadUsers(opts: DownloadStorageOptions): Promise<OperationResultOf<StorageObject[]>>;
68
+ deleteOneUserObject(opts: DeleteOneOptionsCRUD): Promise<OperationResult>;
69
+ deleteManyUserObjects(opts?: DeleteManyOptionsCRUD): Promise<OperationResultOf<number>>;
70
+ }
71
+ export declare class StorageClient implements StorageOperator {
72
+ private objects;
73
+ private http;
74
+ private multipart;
75
+ private base_url;
76
+ private get_token?;
77
+ constructor(opts: StorageClientOptions);
78
+ upload(col: StorageCollection, opts: UploadStorageOptions): Promise<OperationResultOf<RPStorageUpload>>;
79
+ download(col: StorageCollection, opts: DownloadStorageOptions): Promise<OperationResultOf<StorageObject[]>>;
80
+ deleteOne(col: StorageCollection, opts: DeleteOneOptionsCRUD): Promise<OperationResult>;
81
+ deleteMany(col: StorageCollection, opts?: DeleteManyOptionsCRUD): Promise<OperationResultOf<number>>;
82
+ uploadCalls(opts: UploadStorageOptions): Promise<OperationResultOf<RPStorageUpload>>;
83
+ downloadCalls(opts: DownloadStorageOptions): Promise<OperationResultOf<StorageObject[]>>;
84
+ deleteOneCallObject(opts: DeleteOneOptionsCRUD): Promise<OperationResult>;
85
+ deleteManyCallObjects(opts?: DeleteManyOptionsCRUD): Promise<OperationResultOf<number>>;
86
+ uploadChat(opts: UploadStorageOptions): Promise<OperationResultOf<RPStorageUpload>>;
87
+ downloadChat(opts: DownloadStorageOptions): Promise<OperationResultOf<StorageObject[]>>;
88
+ deleteOneChatObject(opts: DeleteOneOptionsCRUD): Promise<OperationResult>;
89
+ deleteManyChatObjects(opts?: DeleteManyOptionsCRUD): Promise<OperationResultOf<number>>;
90
+ uploadContacts(opts: UploadStorageOptions): Promise<OperationResultOf<RPStorageUpload>>;
91
+ downloadContacts(opts: DownloadStorageOptions): Promise<OperationResultOf<StorageObject[]>>;
92
+ deleteOneContactObject(opts: DeleteOneOptionsCRUD): Promise<OperationResult>;
93
+ deleteManyContactObjects(opts?: DeleteManyOptionsCRUD): Promise<OperationResultOf<number>>;
94
+ uploadJobs(opts: UploadStorageOptions): Promise<OperationResultOf<RPStorageUpload>>;
95
+ downloadJobs(opts: DownloadStorageOptions): Promise<OperationResultOf<StorageObject[]>>;
96
+ deleteOneJobObject(opts: DeleteOneOptionsCRUD): Promise<OperationResult>;
97
+ deleteManyJobObjects(opts?: DeleteManyOptionsCRUD): Promise<OperationResultOf<number>>;
98
+ uploadLocations(opts: UploadStorageOptions): Promise<OperationResultOf<RPStorageUpload>>;
99
+ downloadLocations(opts: DownloadStorageOptions): Promise<OperationResultOf<StorageObject[]>>;
100
+ deleteOneLocationObject(opts: DeleteOneOptionsCRUD): Promise<OperationResult>;
101
+ deleteManyLocationObjects(opts?: DeleteManyOptionsCRUD): Promise<OperationResultOf<number>>;
102
+ uploadMemos(opts: UploadStorageOptions): Promise<OperationResultOf<RPStorageUpload>>;
103
+ downloadMemos(opts: DownloadStorageOptions): Promise<OperationResultOf<StorageObject[]>>;
104
+ deleteOneMemoObject(opts: DeleteOneOptionsCRUD): Promise<OperationResult>;
105
+ deleteManyMemoObjects(opts?: DeleteManyOptionsCRUD): Promise<OperationResultOf<number>>;
106
+ uploadQR(opts: UploadStorageOptions): Promise<OperationResultOf<RPStorageUpload>>;
107
+ downloadQR(opts: DownloadStorageOptions): Promise<OperationResultOf<StorageObject[]>>;
108
+ deleteOneQRObject(opts: DeleteOneOptionsCRUD): Promise<OperationResult>;
109
+ deleteManyQRObjects(opts?: DeleteManyOptionsCRUD): Promise<OperationResultOf<number>>;
110
+ uploadReports(opts: UploadStorageOptions): Promise<OperationResultOf<RPStorageUpload>>;
111
+ downloadReports(opts: DownloadStorageOptions): Promise<OperationResultOf<StorageObject[]>>;
112
+ deleteOneReportObject(opts: DeleteOneOptionsCRUD): Promise<OperationResult>;
113
+ deleteManyReportObjects(opts?: DeleteManyOptionsCRUD): Promise<OperationResultOf<number>>;
114
+ uploadTickets(opts: UploadStorageOptions): Promise<OperationResultOf<RPStorageUpload>>;
115
+ downloadTickets(opts: DownloadStorageOptions): Promise<OperationResultOf<StorageObject[]>>;
116
+ deleteOneTicketObject(opts: DeleteOneOptionsCRUD): Promise<OperationResult>;
117
+ deleteManyTicketObjects(opts?: DeleteManyOptionsCRUD): Promise<OperationResultOf<number>>;
118
+ uploadUsers(opts: UploadStorageOptions): Promise<OperationResultOf<RPStorageUpload>>;
119
+ downloadUsers(opts: DownloadStorageOptions): Promise<OperationResultOf<StorageObject[]>>;
120
+ deleteOneUserObject(opts: DeleteOneOptionsCRUD): Promise<OperationResult>;
121
+ deleteManyUserObjects(opts?: DeleteManyOptionsCRUD): Promise<OperationResultOf<number>>;
122
+ private object;
123
+ }
124
+ export declare function newStorageClient(opts: StorageClientOptions): StorageClient;
@@ -0,0 +1,242 @@
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
+ import { ColStorageCalls, ColStorageChat, ColStorageContacts, ColStorageJobs, ColStorageLocations, ColStorageMemos, ColStorageQR, ColStorageReports, ColStorageTickets, ColStorageUsers, HTTPMethodPost, PathStorageDownload, PathStorageUpload, SvcStorage, } from "@fabriktor/schema";
7
+ import { requiredToken } from "../core/auth.js";
8
+ import { withQuery } from "../core/col.js";
9
+ import { newCRUDClient } from "../core/crud.js";
10
+ import { newMultipartClient } from "../core/multipart.js";
11
+ import { buildPath } from "../core/path.js";
12
+ const queryOwnerID = "owner_id";
13
+ const queryUploaderID = "uploader_id";
14
+ const queryFullQuality = "full_quality";
15
+ const fileFieldName = "file";
16
+ export const storageCollections = [
17
+ ColStorageCalls,
18
+ ColStorageChat,
19
+ ColStorageContacts,
20
+ ColStorageJobs,
21
+ ColStorageLocations,
22
+ ColStorageMemos,
23
+ ColStorageQR,
24
+ ColStorageReports,
25
+ ColStorageTickets,
26
+ ColStorageUsers,
27
+ ];
28
+ export class StorageClient {
29
+ objects;
30
+ http;
31
+ multipart;
32
+ base_url;
33
+ get_token;
34
+ constructor(opts) {
35
+ this.objects = new Map(storageCollections.map((col) => [
36
+ col,
37
+ newCRUDClient({
38
+ http: opts.http,
39
+ base_url: opts.base_url,
40
+ svc: SvcStorage,
41
+ col,
42
+ get_token: opts.get_token,
43
+ }),
44
+ ]));
45
+ this.http = opts.http;
46
+ this.multipart = opts.multipart ?? newMultipartClient();
47
+ this.base_url = opts.base_url;
48
+ this.get_token = opts.get_token;
49
+ }
50
+ async upload(col, opts) {
51
+ const token = await requiredToken(this.get_token);
52
+ return await this.multipart.do({
53
+ base_url: this.base_url,
54
+ path: uploadPath(col, opts),
55
+ method: HTTPMethodPost,
56
+ token,
57
+ form: uploadForm(opts),
58
+ });
59
+ }
60
+ async download(col, opts) {
61
+ const token = await requiredToken(this.get_token);
62
+ return await this.http.do({
63
+ base_url: this.base_url,
64
+ path: storagePath(col, PathStorageDownload),
65
+ method: HTTPMethodPost,
66
+ token,
67
+ body: opts,
68
+ });
69
+ }
70
+ async deleteOne(col, opts) {
71
+ return await this.object(col).deleteOne(opts);
72
+ }
73
+ async deleteMany(col, opts) {
74
+ return await this.object(col).deleteMany(opts);
75
+ }
76
+ async uploadCalls(opts) {
77
+ return await this.upload(ColStorageCalls, opts);
78
+ }
79
+ async downloadCalls(opts) {
80
+ return await this.download(ColStorageCalls, opts);
81
+ }
82
+ async deleteOneCallObject(opts) {
83
+ return await this.deleteOne(ColStorageCalls, opts);
84
+ }
85
+ async deleteManyCallObjects(opts) {
86
+ return await this.deleteMany(ColStorageCalls, opts);
87
+ }
88
+ async uploadChat(opts) {
89
+ return await this.upload(ColStorageChat, opts);
90
+ }
91
+ async downloadChat(opts) {
92
+ return await this.download(ColStorageChat, opts);
93
+ }
94
+ async deleteOneChatObject(opts) {
95
+ return await this.deleteOne(ColStorageChat, opts);
96
+ }
97
+ async deleteManyChatObjects(opts) {
98
+ return await this.deleteMany(ColStorageChat, opts);
99
+ }
100
+ async uploadContacts(opts) {
101
+ return await this.upload(ColStorageContacts, opts);
102
+ }
103
+ async downloadContacts(opts) {
104
+ return await this.download(ColStorageContacts, opts);
105
+ }
106
+ async deleteOneContactObject(opts) {
107
+ return await this.deleteOne(ColStorageContacts, opts);
108
+ }
109
+ async deleteManyContactObjects(opts) {
110
+ return await this.deleteMany(ColStorageContacts, opts);
111
+ }
112
+ async uploadJobs(opts) {
113
+ return await this.upload(ColStorageJobs, opts);
114
+ }
115
+ async downloadJobs(opts) {
116
+ return await this.download(ColStorageJobs, opts);
117
+ }
118
+ async deleteOneJobObject(opts) {
119
+ return await this.deleteOne(ColStorageJobs, opts);
120
+ }
121
+ async deleteManyJobObjects(opts) {
122
+ return await this.deleteMany(ColStorageJobs, opts);
123
+ }
124
+ async uploadLocations(opts) {
125
+ return await this.upload(ColStorageLocations, opts);
126
+ }
127
+ async downloadLocations(opts) {
128
+ return await this.download(ColStorageLocations, opts);
129
+ }
130
+ async deleteOneLocationObject(opts) {
131
+ return await this.deleteOne(ColStorageLocations, opts);
132
+ }
133
+ async deleteManyLocationObjects(opts) {
134
+ return await this.deleteMany(ColStorageLocations, opts);
135
+ }
136
+ async uploadMemos(opts) {
137
+ return await this.upload(ColStorageMemos, opts);
138
+ }
139
+ async downloadMemos(opts) {
140
+ return await this.download(ColStorageMemos, opts);
141
+ }
142
+ async deleteOneMemoObject(opts) {
143
+ return await this.deleteOne(ColStorageMemos, opts);
144
+ }
145
+ async deleteManyMemoObjects(opts) {
146
+ return await this.deleteMany(ColStorageMemos, opts);
147
+ }
148
+ async uploadQR(opts) {
149
+ return await this.upload(ColStorageQR, opts);
150
+ }
151
+ async downloadQR(opts) {
152
+ return await this.download(ColStorageQR, opts);
153
+ }
154
+ async deleteOneQRObject(opts) {
155
+ return await this.deleteOne(ColStorageQR, opts);
156
+ }
157
+ async deleteManyQRObjects(opts) {
158
+ return await this.deleteMany(ColStorageQR, opts);
159
+ }
160
+ async uploadReports(opts) {
161
+ return await this.upload(ColStorageReports, opts);
162
+ }
163
+ async downloadReports(opts) {
164
+ return await this.download(ColStorageReports, opts);
165
+ }
166
+ async deleteOneReportObject(opts) {
167
+ return await this.deleteOne(ColStorageReports, opts);
168
+ }
169
+ async deleteManyReportObjects(opts) {
170
+ return await this.deleteMany(ColStorageReports, opts);
171
+ }
172
+ async uploadTickets(opts) {
173
+ return await this.upload(ColStorageTickets, opts);
174
+ }
175
+ async downloadTickets(opts) {
176
+ return await this.download(ColStorageTickets, opts);
177
+ }
178
+ async deleteOneTicketObject(opts) {
179
+ return await this.deleteOne(ColStorageTickets, opts);
180
+ }
181
+ async deleteManyTicketObjects(opts) {
182
+ return await this.deleteMany(ColStorageTickets, opts);
183
+ }
184
+ async uploadUsers(opts) {
185
+ return await this.upload(ColStorageUsers, opts);
186
+ }
187
+ async downloadUsers(opts) {
188
+ return await this.download(ColStorageUsers, opts);
189
+ }
190
+ async deleteOneUserObject(opts) {
191
+ return await this.deleteOne(ColStorageUsers, opts);
192
+ }
193
+ async deleteManyUserObjects(opts) {
194
+ return await this.deleteMany(ColStorageUsers, opts);
195
+ }
196
+ object(col) {
197
+ const c = this.objects.get(col);
198
+ if (c === undefined) {
199
+ throw new Error(`unknown storage collection: ${col}`);
200
+ }
201
+ return c;
202
+ }
203
+ }
204
+ export function newStorageClient(opts) {
205
+ return new StorageClient(opts);
206
+ }
207
+ function uploadPath(col, opts) {
208
+ return withQuery(storagePath(col, PathStorageUpload), {
209
+ query: {
210
+ [queryOwnerID]: opts.owner_id,
211
+ [queryUploaderID]: opts.uploader_id,
212
+ [queryFullQuality]: opts.full_quality,
213
+ },
214
+ });
215
+ }
216
+ function storagePath(col, action) {
217
+ return buildPath({
218
+ svc: SvcStorage,
219
+ col,
220
+ action,
221
+ });
222
+ }
223
+ function uploadForm(opts) {
224
+ if (opts.files.length === 0) {
225
+ throw new Error("upload requires at least one file");
226
+ }
227
+ const form = new FormData();
228
+ for (const f of opts.files) {
229
+ appendFile(form, f);
230
+ }
231
+ return form;
232
+ }
233
+ function appendFile(form, f) {
234
+ if (isFile(f)) {
235
+ form.append(fileFieldName, f, f.name);
236
+ return;
237
+ }
238
+ form.append(fileFieldName, f.blob, f.filename);
239
+ }
240
+ function isFile(f) {
241
+ return typeof File !== "undefined" && f instanceof File;
242
+ }
@@ -0,0 +1,49 @@
1
+ import { type InSummary, type InWeekSheet, type OperationResult, type PLTimesheetsApprove, type PLTimesheetsSync, type Punch, type Summary, type WeekSheet } from "@fabriktor/schema";
2
+ import type { TokenProvider } from "../core/auth.js";
3
+ import type { DeleteManyOptionsCRUD, DeleteOneOptionsCRUD, FindOneOptionsCRUD, OperationResultOf, QueryOptionsCRUD, ReplaceOneOptionsCRUD } from "../core/crud.js";
4
+ import type { HTTPDoer } from "../core/http.js";
5
+ export type ApproveTimesheetsOptions = PLTimesheetsApprove;
6
+ export type SyncTimesheetsOptions = PLTimesheetsSync;
7
+ export type PunchTimesheetOptions = Punch;
8
+ export type TimesheetsClientOptions = {
9
+ http: HTTPDoer;
10
+ base_url: string;
11
+ get_token?: TokenProvider;
12
+ };
13
+ export interface TimesheetsOperator {
14
+ queryWeekSheets(opts?: QueryOptionsCRUD): Promise<OperationResultOf<WeekSheet[]>>;
15
+ findOneWeekSheet(opts: FindOneOptionsCRUD): Promise<OperationResultOf<WeekSheet>>;
16
+ replaceOneWeekSheet(opts: ReplaceOneOptionsCRUD<InWeekSheet>): Promise<OperationResult>;
17
+ deleteOneWeekSheet(opts: DeleteOneOptionsCRUD): Promise<OperationResult>;
18
+ deleteManyWeekSheets(opts?: DeleteManyOptionsCRUD): Promise<OperationResultOf<number>>;
19
+ querySummaries(opts?: QueryOptionsCRUD): Promise<OperationResultOf<Summary[]>>;
20
+ findOneSummary(opts: FindOneOptionsCRUD): Promise<OperationResultOf<Summary>>;
21
+ replaceOneSummary(opts: ReplaceOneOptionsCRUD<InSummary>): Promise<OperationResult>;
22
+ deleteOneSummary(opts: DeleteOneOptionsCRUD): Promise<OperationResult>;
23
+ deleteManySummaries(opts?: DeleteManyOptionsCRUD): Promise<OperationResultOf<number>>;
24
+ approve(opts: ApproveTimesheetsOptions): Promise<void>;
25
+ sync(opts: SyncTimesheetsOptions): Promise<void>;
26
+ punch(opts: PunchTimesheetOptions): Promise<OperationResult>;
27
+ }
28
+ export declare class TimesheetsClient implements TimesheetsOperator {
29
+ private weeksheets;
30
+ private summaries;
31
+ private http;
32
+ private base_url;
33
+ private get_token?;
34
+ constructor(opts: TimesheetsClientOptions);
35
+ queryWeekSheets(opts?: QueryOptionsCRUD): Promise<OperationResultOf<WeekSheet[]>>;
36
+ findOneWeekSheet(opts: FindOneOptionsCRUD): Promise<OperationResultOf<WeekSheet>>;
37
+ replaceOneWeekSheet(opts: ReplaceOneOptionsCRUD<InWeekSheet>): Promise<OperationResult>;
38
+ deleteOneWeekSheet(opts: DeleteOneOptionsCRUD): Promise<OperationResult>;
39
+ deleteManyWeekSheets(opts?: DeleteManyOptionsCRUD): Promise<OperationResultOf<number>>;
40
+ querySummaries(opts?: QueryOptionsCRUD): Promise<OperationResultOf<Summary[]>>;
41
+ findOneSummary(opts: FindOneOptionsCRUD): Promise<OperationResultOf<Summary>>;
42
+ replaceOneSummary(opts: ReplaceOneOptionsCRUD<InSummary>): Promise<OperationResult>;
43
+ deleteOneSummary(opts: DeleteOneOptionsCRUD): Promise<OperationResult>;
44
+ deleteManySummaries(opts?: DeleteManyOptionsCRUD): Promise<OperationResultOf<number>>;
45
+ approve(opts: ApproveTimesheetsOptions): Promise<void>;
46
+ sync(opts: SyncTimesheetsOptions): Promise<void>;
47
+ punch(opts: PunchTimesheetOptions): Promise<OperationResult>;
48
+ }
49
+ export declare function newTimesheetsClient(opts: TimesheetsClientOptions): TimesheetsClient;
@@ -0,0 +1,105 @@
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
+ import { ColTimesheetsSummaries, ColTimesheetsWeekSheets, HTTPMethodPost, PathTimesheetsApprove, PathTimesheetsPunch, PathTimesheetsSync, SvcTimesheets, } from "@fabriktor/schema";
7
+ import { requiredToken } from "../core/auth.js";
8
+ import { newCRUDClient } from "../core/crud.js";
9
+ import { buildPath } from "../core/path.js";
10
+ export class TimesheetsClient {
11
+ weeksheets;
12
+ summaries;
13
+ http;
14
+ base_url;
15
+ get_token;
16
+ constructor(opts) {
17
+ this.weeksheets = newCRUDClient({
18
+ http: opts.http,
19
+ base_url: opts.base_url,
20
+ svc: SvcTimesheets,
21
+ col: ColTimesheetsWeekSheets,
22
+ get_token: opts.get_token,
23
+ });
24
+ this.summaries = newCRUDClient({
25
+ http: opts.http,
26
+ base_url: opts.base_url,
27
+ svc: SvcTimesheets,
28
+ col: ColTimesheetsSummaries,
29
+ get_token: opts.get_token,
30
+ });
31
+ this.http = opts.http;
32
+ this.base_url = opts.base_url;
33
+ this.get_token = opts.get_token;
34
+ }
35
+ async queryWeekSheets(opts) {
36
+ return await this.weeksheets.query(opts);
37
+ }
38
+ async findOneWeekSheet(opts) {
39
+ return await this.weeksheets.findOne(opts);
40
+ }
41
+ async replaceOneWeekSheet(opts) {
42
+ return await this.weeksheets.replaceOne(opts);
43
+ }
44
+ async deleteOneWeekSheet(opts) {
45
+ return await this.weeksheets.deleteOne(opts);
46
+ }
47
+ async deleteManyWeekSheets(opts) {
48
+ return await this.weeksheets.deleteMany(opts);
49
+ }
50
+ async querySummaries(opts) {
51
+ return await this.summaries.query(opts);
52
+ }
53
+ async findOneSummary(opts) {
54
+ return await this.summaries.findOne(opts);
55
+ }
56
+ async replaceOneSummary(opts) {
57
+ return await this.summaries.replaceOne(opts);
58
+ }
59
+ async deleteOneSummary(opts) {
60
+ return await this.summaries.deleteOne(opts);
61
+ }
62
+ async deleteManySummaries(opts) {
63
+ return await this.summaries.deleteMany(opts);
64
+ }
65
+ async approve(opts) {
66
+ const token = await requiredToken(this.get_token);
67
+ return await this.http.do({
68
+ base_url: this.base_url,
69
+ path: weekSheetPath(PathTimesheetsApprove),
70
+ method: HTTPMethodPost,
71
+ token,
72
+ body: opts,
73
+ });
74
+ }
75
+ async sync(opts) {
76
+ const token = await requiredToken(this.get_token);
77
+ return await this.http.do({
78
+ base_url: this.base_url,
79
+ path: weekSheetPath(PathTimesheetsSync),
80
+ method: HTTPMethodPost,
81
+ token,
82
+ body: opts,
83
+ });
84
+ }
85
+ async punch(opts) {
86
+ const token = await requiredToken(this.get_token);
87
+ return await this.http.do({
88
+ base_url: this.base_url,
89
+ path: weekSheetPath(PathTimesheetsPunch),
90
+ method: HTTPMethodPost,
91
+ token,
92
+ body: opts,
93
+ });
94
+ }
95
+ }
96
+ export function newTimesheetsClient(opts) {
97
+ return new TimesheetsClient(opts);
98
+ }
99
+ function weekSheetPath(action) {
100
+ return buildPath({
101
+ svc: SvcTimesheets,
102
+ col: ColTimesheetsWeekSheets,
103
+ action,
104
+ });
105
+ }
@@ -1,4 +1,4 @@
1
- import type { PLUsersSendCode, PLUsersVerifyCode } from "@fabriktor/schema";
1
+ import { type PLUsersSendCode, type PLUsersVerifyCode } from "@fabriktor/schema";
2
2
  import type { TokenProvider } from "../core/auth.js";
3
3
  import type { HTTPDoer } from "../core/http.js";
4
4
  export type SendPhoneVerificationOptions = PLUsersSendCode;
@@ -1,10 +1,11 @@
1
- import type { PLUsersUsername } from "@fabriktor/schema";
1
+ import { type PLUsersUsername } from "@fabriktor/schema";
2
2
  import type { TokenProvider } from "../core/auth.js";
3
- import type { HTTPDoer, Op } from "../core/http.js";
3
+ import type { OperationResultOf } from "../core/crud.js";
4
+ import type { HTTPDoer } from "../core/http.js";
4
5
  export type VerifyUsernameOptions = PLUsersUsername;
5
6
  export type UsernameVerification = string[];
6
7
  export interface TmpUsernamesOperator {
7
- verify(opts: VerifyUsernameOptions): Promise<Op<UsernameVerification>>;
8
+ verify(opts: VerifyUsernameOptions): Promise<OperationResultOf<UsernameVerification>>;
8
9
  }
9
10
  export type TmpUsernamesClientOptions = {
10
11
  http: HTTPDoer;
@@ -16,6 +17,6 @@ export declare class TmpUsernamesClient implements TmpUsernamesOperator {
16
17
  private base_url;
17
18
  private get_token?;
18
19
  constructor(opts: TmpUsernamesClientOptions);
19
- verify(opts: VerifyUsernameOptions): Promise<Op<UsernameVerification>>;
20
+ verify(opts: VerifyUsernameOptions): Promise<OperationResultOf<UsernameVerification>>;
20
21
  }
21
22
  export declare function newTmpUsernamesClient(opts: TmpUsernamesClientOptions): TmpUsernamesClient;
@@ -1,6 +1,7 @@
1
- import type { InUser, OperationResult, PLUsersContactList, PLUsersForgotPassword, PLUsersResolveUsername, PLUsersVerifyEmail, PLUsersSignInLink, UpsertResult, User } from "@fabriktor/schema";
1
+ import { type InUser, type OperationResult, type PLUsersContactList, type PLUsersForgotPassword, type PLUsersResolveUsername, type PLUsersSignInLink, type PLUsersVerifyEmail, type UpsertResult, type User } from "@fabriktor/schema";
2
2
  import type { TokenProvider } from "../core/auth.js";
3
- import type { HTTPDoer, Op } from "../core/http.js";
3
+ import type { OperationResultOf } from "../core/crud.js";
4
+ import type { HTTPDoer } from "../core/http.js";
4
5
  export type BootstrapOptions = {
5
6
  in: InUser;
6
7
  };
@@ -17,15 +18,15 @@ export type GetByUIDOptions = {
17
18
  uid: string;
18
19
  };
19
20
  export interface UsersOperator {
20
- bootstrap(opts: BootstrapOptions): Promise<Op<UpsertResult>>;
21
+ bootstrap(opts: BootstrapOptions): Promise<OperationResultOf<UpsertResult>>;
21
22
  sync(): Promise<OperationResult>;
22
23
  sendEmailVerification(opts: SendEmailVerificationOptions): Promise<void>;
23
24
  forgotPassword(opts: ForgotPasswordOptions): Promise<void>;
24
25
  sendSignInLink(opts: SendSignInLinkOptions): Promise<void>;
25
- resolveUsername(opts: ResolveUsernameOptions): Promise<Op<string>>;
26
- match(opts: MatchOptions): Promise<Op<User[]>>;
27
- search(opts: SearchOptions): Promise<Op<User[]>>;
28
- getByUID(opts: GetByUIDOptions): Promise<Op<User[]>>;
26
+ resolveUsername(opts: ResolveUsernameOptions): Promise<OperationResultOf<string>>;
27
+ match(opts: MatchOptions): Promise<OperationResultOf<User[]>>;
28
+ search(opts: SearchOptions): Promise<OperationResultOf<User[]>>;
29
+ getByUID(opts: GetByUIDOptions): Promise<OperationResultOf<User[]>>;
29
30
  }
30
31
  export type UsersClientOptions = {
31
32
  http: HTTPDoer;
@@ -37,14 +38,14 @@ export declare class UsersClient implements UsersOperator {
37
38
  private base_url;
38
39
  private get_token?;
39
40
  constructor(opts: UsersClientOptions);
40
- bootstrap(opts: BootstrapOptions): Promise<Op<UpsertResult>>;
41
+ bootstrap(opts: BootstrapOptions): Promise<OperationResultOf<UpsertResult>>;
41
42
  sync(): Promise<OperationResult>;
42
43
  sendEmailVerification(opts: SendEmailVerificationOptions): Promise<void>;
43
44
  forgotPassword(opts: ForgotPasswordOptions): Promise<void>;
44
45
  sendSignInLink(opts: SendSignInLinkOptions): Promise<void>;
45
- resolveUsername(opts: ResolveUsernameOptions): Promise<Op<string>>;
46
- match(opts: MatchOptions): Promise<Op<User[]>>;
47
- search(opts: SearchOptions): Promise<Op<User[]>>;
48
- getByUID(opts: GetByUIDOptions): Promise<Op<User[]>>;
46
+ resolveUsername(opts: ResolveUsernameOptions): Promise<OperationResultOf<string>>;
47
+ match(opts: MatchOptions): Promise<OperationResultOf<User[]>>;
48
+ search(opts: SearchOptions): Promise<OperationResultOf<User[]>>;
49
+ getByUID(opts: GetByUIDOptions): Promise<OperationResultOf<User[]>>;
49
50
  }
50
51
  export declare function newUsersClient(opts: UsersClientOptions): UsersClient;
@@ -5,6 +5,7 @@
5
5
  // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6
6
  import { ColUsersUsers, HTTPMethodGet, HTTPMethodPost, PathSearch, PathUsersBootstrap, PathUsersForgotPassword, PathUsersMatch, PathUsersResolveUsername, PathUsersSendEmailVerification, PathUsersSendSignInLink, PathUsersSync, SvcUsers, } from "@fabriktor/schema";
7
7
  import { requiredToken } from "../core/auth.js";
8
+ import { queryParam, withQuery } from "../core/col.js";
8
9
  import { buildPath } from "../core/path.js";
9
10
  export class UsersClient {
10
11
  http;
@@ -105,7 +106,9 @@ export class UsersClient {
105
106
  const token = await requiredToken(this.get_token);
106
107
  return await this.http.do({
107
108
  base_url: this.base_url,
108
- path: `${collectionPath()}?uid=${encodeURIComponent(opts.uid)}`,
109
+ path: withQuery(collectionPath(), {
110
+ query: queryParam("uid", opts.uid),
111
+ }),
109
112
  method: HTTPMethodGet,
110
113
  token,
111
114
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabriktor/client",
3
- "version": "0.0.28",
3
+ "version": "0.0.31",
4
4
  "description": "![Fabriktor Logo](./img/fabriktor-character.gif)",
5
5
  "type": "module",
6
6
  "exports": {
@@ -17,6 +17,7 @@
17
17
  "typescript": "^6.0.3"
18
18
  },
19
19
  "dependencies": {
20
- "@fabriktor/schema": "^0.0.21"
20
+ "@fabriktor/client": "0.0.25",
21
+ "@fabriktor/schema": "0.0.27"
21
22
  }
22
23
  }