@bizmap/sdk 0.0.133 → 0.0.135
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/main.d.ts +193 -158
- package/dist/main.js +272 -245
- package/package.json +2 -2
package/dist/main.js
CHANGED
|
@@ -37,46 +37,71 @@ var vitalKeys = z3.enum([
|
|
|
37
37
|
]);
|
|
38
38
|
|
|
39
39
|
// src/schemas/company/CompanyDetails.ts
|
|
40
|
-
import * as
|
|
40
|
+
import * as z15 from "zod";
|
|
41
41
|
|
|
42
42
|
// src/schemas/company/components/Billing.ts
|
|
43
|
-
import * as
|
|
43
|
+
import * as z8 from "zod";
|
|
44
44
|
|
|
45
|
-
// src/schemas/
|
|
46
|
-
import
|
|
45
|
+
// src/schemas/user/Details.ts
|
|
46
|
+
import { UserModel } from "@wavy/util";
|
|
47
|
+
import * as z6 from "zod";
|
|
47
48
|
|
|
48
|
-
// src/
|
|
49
|
+
// src/constants.ts
|
|
50
|
+
var NOTIF_ID_DELIM = "::";
|
|
51
|
+
var MAX_NAME_LENGTH = 21;
|
|
52
|
+
|
|
53
|
+
// src/schemas/company/components/utils.ts
|
|
49
54
|
import * as z4 from "zod";
|
|
50
|
-
var
|
|
55
|
+
var CompanyId = z4.string().toLowerCase().trim().min(3).max(63).transform(
|
|
56
|
+
(data) => data.replace(/-+/g, "-").replace(/_+/g, "_").replace(/\.+/g, ".").replace(/\s+/g, "")
|
|
57
|
+
).superRefine((data, ctx) => {
|
|
58
|
+
const invalidCharIdx = data.search(/[^a-z0-9\-_\.]/);
|
|
59
|
+
if (invalidCharIdx >= 0) {
|
|
60
|
+
const char = data[invalidCharIdx];
|
|
61
|
+
ctx.addIssue(
|
|
62
|
+
`${/"|'|`/.test(char) ? `(${char})` : `"${char}"`} is not an allowed character.`
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
if (!/[a-z]/.test(data[0])) {
|
|
66
|
+
ctx.addIssue("The first character must be a letter.");
|
|
67
|
+
}
|
|
68
|
+
if (!/[a-z0-9]/.test(data[data.length - 1])) {
|
|
69
|
+
ctx.addIssue("The last character must either be a letter or a number.");
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// src/schemas/utils/core.ts
|
|
74
|
+
import * as z5 from "zod";
|
|
75
|
+
var InvoiceNo = z5.string().trim().refine(
|
|
51
76
|
(d) => d && d.replace(
|
|
52
77
|
/^[0-9]{4}-(01|(0[2-9])|(1[0-2]))-(30|31|([1-2][0-9])|0[1-9])-[0-9]{7}/,
|
|
53
78
|
""
|
|
54
79
|
).length === 0,
|
|
55
80
|
'Invalid invoice no.: must match the pattern "yyyy-mm-dd-0000000"'
|
|
56
81
|
);
|
|
57
|
-
var Trn =
|
|
82
|
+
var Trn = z5.string().trim().refine(
|
|
58
83
|
(data) => data && data.replace(/^[0-9]{3}-[0-9]{3}-[0-9]{3}/, "").length === 0,
|
|
59
84
|
'Invalid trn: must match the pattern "000-000-000"'
|
|
60
85
|
);
|
|
61
|
-
var StandardTime =
|
|
86
|
+
var StandardTime = z5.string().trim().refine(
|
|
62
87
|
(d) => d && d.replace(/^(01|(0[2-9])|(1[0-2])):(([1-5][0-9])|0[0-9]) (am|pm)/i, "").length === 0,
|
|
63
88
|
'Invalid standard time: must match the pattern "hh:mm A"'
|
|
64
89
|
);
|
|
65
|
-
var Timestamp =
|
|
66
|
-
var InviteResponse =
|
|
67
|
-
var TimeLog =
|
|
90
|
+
var Timestamp = z5.iso.datetime();
|
|
91
|
+
var InviteResponse = z5.enum(["accepted", "declined"]);
|
|
92
|
+
var TimeLog = z5.object({
|
|
68
93
|
createdAt: Timestamp.readonly(),
|
|
69
94
|
lastModified: Timestamp.optional()
|
|
70
95
|
});
|
|
71
|
-
var TicketNo =
|
|
96
|
+
var TicketNo = z5.int().positive().refine(
|
|
72
97
|
(t) => t.toString().length <= 10,
|
|
73
98
|
"A ticket no. can only have (10) max digits."
|
|
74
99
|
).readonly();
|
|
75
|
-
var Reason =
|
|
76
|
-
value:
|
|
100
|
+
var Reason = z5.object({
|
|
101
|
+
value: z5.string().trim().min(3).max(100),
|
|
77
102
|
lastModified: Timestamp
|
|
78
103
|
});
|
|
79
|
-
var AlphaNumeric =
|
|
104
|
+
var AlphaNumeric = z5.string().trim().superRefine((data, ctx) => {
|
|
80
105
|
const invalidCharIdx = data.search(/[^a-z0-9]/i);
|
|
81
106
|
if (invalidCharIdx > -1) {
|
|
82
107
|
const char = `"'`.includes(data[invalidCharIdx]) ? `(${data[invalidCharIdx]})` : `"${data[invalidCharIdx]}"`;
|
|
@@ -84,86 +109,89 @@ var AlphaNumeric = z4.string().trim().superRefine((data, ctx) => {
|
|
|
84
109
|
}
|
|
85
110
|
});
|
|
86
111
|
|
|
112
|
+
// src/schemas/user/Details.ts
|
|
113
|
+
var UserDetails = z6.object({
|
|
114
|
+
...UserModel.shape,
|
|
115
|
+
_id: z6.uuidv4(),
|
|
116
|
+
name: z6.string().transform((data) => {
|
|
117
|
+
const [firstName = "", lastName = ""] = data.split(" ");
|
|
118
|
+
return (firstName + " " + lastName).trim();
|
|
119
|
+
}).superRefine((data, ctx) => {
|
|
120
|
+
data.split(" ").forEach((name, idx) => {
|
|
121
|
+
const nty = idx === 0 ? "First" : "Last";
|
|
122
|
+
if (idx === 0 && name.length < 2) {
|
|
123
|
+
ctx.addIssue(`${nty} name must have at least (2) characters.`);
|
|
124
|
+
}
|
|
125
|
+
if (name.length > MAX_NAME_LENGTH) {
|
|
126
|
+
ctx.addIssue(
|
|
127
|
+
`${nty} name can't have more than (${MAX_NAME_LENGTH}) characters.`
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}),
|
|
132
|
+
email: UserModel.shape.email,
|
|
133
|
+
publicKey: z6.string().optional(),
|
|
134
|
+
// Used to track the user's general purpose (gp) storage and the total storage used by
|
|
135
|
+
// their companies.
|
|
136
|
+
// storageTracker: ,
|
|
137
|
+
// storageTracker:
|
|
138
|
+
// .readonly(),
|
|
139
|
+
// usedStorageInBytes: z.number().min(0),
|
|
140
|
+
// notifications: z.array(Notification),
|
|
141
|
+
lastSignedIn: z6.object({
|
|
142
|
+
auto: Timestamp,
|
|
143
|
+
manual: Timestamp
|
|
144
|
+
}).partial(),
|
|
145
|
+
// This is useful for tracking the companies that a non-company owner belongs to.
|
|
146
|
+
companyIds: z6.array(CompanyId).min(1).optional(),
|
|
147
|
+
// resumeToken: z.uuidv4().optional(),
|
|
148
|
+
...TimeLog.shape
|
|
149
|
+
}).omit({ uid: true });
|
|
150
|
+
|
|
87
151
|
// src/schemas/utils/billing.ts
|
|
88
|
-
|
|
89
|
-
|
|
152
|
+
import * as z7 from "zod";
|
|
153
|
+
var PriceMod = z7.object({
|
|
154
|
+
description: z7.string().trim().min(3, "A description must have atleast (3) characters.").max(25, "A description can't have more that (25) characters.").superRefine((data, ctx) => {
|
|
90
155
|
const invalidCharIdx = data.search(/[^a-zA-Z0-9-\.:\(\)]/);
|
|
91
156
|
if (invalidCharIdx > -1) {
|
|
92
157
|
ctx.addIssue("");
|
|
93
158
|
}
|
|
94
159
|
}),
|
|
95
|
-
fixedAmount:
|
|
96
|
-
value:
|
|
160
|
+
fixedAmount: z7.object({
|
|
161
|
+
value: z7.number().min(0).max(1e6, "The max fixed amount is $1,000,000.00"),
|
|
97
162
|
currency: acceptedCurrencies
|
|
98
163
|
}),
|
|
99
|
-
percentage:
|
|
100
|
-
isOptional:
|
|
164
|
+
percentage: z7.number().min(0).max(1e3, "The max percentage is 1,000%"),
|
|
165
|
+
isOptional: z7.boolean(),
|
|
101
166
|
...TimeLog.shape
|
|
102
167
|
});
|
|
103
|
-
var PriceModList =
|
|
104
|
-
var PriceTag =
|
|
105
|
-
uid:
|
|
168
|
+
var PriceModList = z7.record(z7.uuidv4(), PriceMod);
|
|
169
|
+
var PriceTag = z7.object({
|
|
170
|
+
uid: z7.uuidv4(),
|
|
106
171
|
/**The name of the item that's being priced */
|
|
107
|
-
item:
|
|
108
|
-
cost:
|
|
172
|
+
item: z7.string().trim().min(3, "The price item must be atleast (3) characters long.").max(50, "The price item can't be more than (50) characters long."),
|
|
173
|
+
cost: z7.number().min(1, "The minimum allowed cost is $1.00").max(1e9, "The max allowed cost is $1,000,000,000.00."),
|
|
109
174
|
currency: acceptedCurrencies,
|
|
110
175
|
...TimeLog.shape
|
|
111
176
|
});
|
|
112
|
-
var Receipts =
|
|
177
|
+
var Receipts = z7.array(
|
|
113
178
|
PriceTag.omit({ uid: true, lastModified: true })
|
|
114
179
|
);
|
|
115
180
|
|
|
116
|
-
// src/schemas/company/components/State.ts
|
|
117
|
-
import * as z6 from "zod";
|
|
118
|
-
var CompanyState = z6.object({
|
|
119
|
-
_id: z6.string().toLowerCase().trim().min(3).max(63).transform(
|
|
120
|
-
(data) => data.replace(/-+/g, "-").replace(/_+/g, "_").replace(/\.+/g, ".").replace(/\s+/g, "")
|
|
121
|
-
).superRefine((data, ctx) => {
|
|
122
|
-
const invalidCharIdx = data.search(/[^a-z0-9\-_\.]/);
|
|
123
|
-
if (invalidCharIdx >= 0) {
|
|
124
|
-
const char = data[invalidCharIdx];
|
|
125
|
-
ctx.addIssue(
|
|
126
|
-
`${/"|'|`/.test(char) ? `(${char})` : `"${char}"`} is not an allowed character.`
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
if (!/[a-z]/.test(data[0])) {
|
|
130
|
-
ctx.addIssue("The first character must be a letter.");
|
|
131
|
-
}
|
|
132
|
-
if (!/[a-z0-9]/.test(data[data.length - 1])) {
|
|
133
|
-
ctx.addIssue("The last character must either be a letter or a number.");
|
|
134
|
-
}
|
|
135
|
-
}),
|
|
136
|
-
credits: z6.object({
|
|
137
|
-
current: z6.number(),
|
|
138
|
-
lastModified: Timestamp.optional()
|
|
139
|
-
}),
|
|
140
|
-
tierId: z6.object({
|
|
141
|
-
current: z6.string(),
|
|
142
|
-
lastModified: Timestamp.optional()
|
|
143
|
-
}),
|
|
144
|
-
count: z6.object({
|
|
145
|
-
invoiceNo: z6.int().min(0),
|
|
146
|
-
tktNo: z6.int().min(1)
|
|
147
|
-
}),
|
|
148
|
-
// distRoleIds: z.array(z.string()),
|
|
149
|
-
/** Data retention period in months */
|
|
150
|
-
// drpInMonths: z.int().min(1),
|
|
151
|
-
...TimeLog.shape
|
|
152
|
-
});
|
|
153
|
-
|
|
154
181
|
// src/schemas/company/components/Billing.ts
|
|
155
182
|
var MAX_COMPANY_PRICE_MODS = 100;
|
|
156
183
|
var createMod = (resource) => PriceModList.refine(
|
|
157
184
|
(d) => Object.values(d).length <= MAX_COMPANY_PRICE_MODS,
|
|
158
185
|
`Adding more than 100 ${resource}s is prohibited.`
|
|
159
186
|
);
|
|
160
|
-
var CompanyBilling =
|
|
161
|
-
_id:
|
|
187
|
+
var CompanyBilling = z8.object({
|
|
188
|
+
_id: CompanyId,
|
|
189
|
+
ownerId: UserDetails.shape._id,
|
|
162
190
|
additionalFees: createMod("additional fee").optional(),
|
|
163
191
|
discounts: createMod("discount").optional(),
|
|
164
192
|
/** Optionally deductable from bills */
|
|
165
193
|
prepayments: createMod("pre-payment").optional(),
|
|
166
|
-
offeredServices:
|
|
194
|
+
offeredServices: z8.record(z8.uuidv4(), PriceTag.omit({ uid: true })).superRefine((data, ctx) => {
|
|
167
195
|
const services = Object.entries(data);
|
|
168
196
|
if (services.length > 150) {
|
|
169
197
|
ctx.addIssue(
|
|
@@ -180,14 +208,14 @@ var MutableCompanyBilling = CompanyBilling.omit({
|
|
|
180
208
|
|
|
181
209
|
// src/schemas/company/components/Identity.ts
|
|
182
210
|
import { Address, PhoneNumber } from "@wavy/util";
|
|
183
|
-
import * as
|
|
211
|
+
import * as z10 from "zod";
|
|
184
212
|
|
|
185
213
|
// src/schemas/company/entities/Industry.ts
|
|
186
|
-
import * as
|
|
187
|
-
var CompanyIndustry =
|
|
188
|
-
healthcare:
|
|
189
|
-
medicalCare:
|
|
190
|
-
roles:
|
|
214
|
+
import * as z9 from "zod";
|
|
215
|
+
var CompanyIndustry = z9.object({
|
|
216
|
+
healthcare: z9.object({
|
|
217
|
+
medicalCare: z9.object({
|
|
218
|
+
roles: z9.enum(["doc", "physAsst"])
|
|
191
219
|
})
|
|
192
220
|
// "pharmaceuticals": z.object({
|
|
193
221
|
// })
|
|
@@ -198,9 +226,10 @@ var safeParseSector = (industry, sector) => {
|
|
|
198
226
|
};
|
|
199
227
|
|
|
200
228
|
// src/schemas/company/components/Identity.ts
|
|
201
|
-
var CompanyIdentity =
|
|
202
|
-
_id:
|
|
203
|
-
|
|
229
|
+
var CompanyIdentity = z10.object({
|
|
230
|
+
_id: CompanyId,
|
|
231
|
+
ownerId: UserDetails.shape._id,
|
|
232
|
+
alias: z10.string().trim().min(3).max(63).transform((data) => data.replace(/\s+/g, " ")).superRefine((data, ctx) => {
|
|
204
233
|
const invalidCharIdx = data.search(/[^a-z1-9 ]/i);
|
|
205
234
|
if (invalidCharIdx >= 0) {
|
|
206
235
|
ctx.addIssue(
|
|
@@ -209,18 +238,18 @@ var CompanyIdentity = z9.object({
|
|
|
209
238
|
}
|
|
210
239
|
}),
|
|
211
240
|
address: Address,
|
|
212
|
-
logo:
|
|
241
|
+
logo: z10.string().optional(),
|
|
213
242
|
industry: CompanyIndustry.keyof(),
|
|
214
|
-
sector:
|
|
215
|
-
email:
|
|
243
|
+
sector: z10.string(),
|
|
244
|
+
email: z10.email().max(45),
|
|
216
245
|
phoneNumber: PhoneNumber.optional(),
|
|
217
|
-
emailVerified:
|
|
218
|
-
verified:
|
|
219
|
-
legal:
|
|
220
|
-
regNo:
|
|
246
|
+
emailVerified: z10.boolean(),
|
|
247
|
+
verified: z10.boolean(),
|
|
248
|
+
legal: z10.object({
|
|
249
|
+
regNo: z10.string().max(20).readonly(),
|
|
221
250
|
// The company's registration number
|
|
222
|
-
trn:
|
|
223
|
-
gctRegNo:
|
|
251
|
+
trn: z10.string().regex(/[0-9]{3}-[0-9]{3}-[0-9]{3}/).nullish(),
|
|
252
|
+
gctRegNo: z10.string().max(15).nullish()
|
|
224
253
|
}).optional(),
|
|
225
254
|
...TimeLog.shape
|
|
226
255
|
}).superRefine((data, ctx) => {
|
|
@@ -247,19 +276,20 @@ var MutableCompanyIdentity = CompanyIdentity.pick({
|
|
|
247
276
|
});
|
|
248
277
|
|
|
249
278
|
// src/schemas/company/components/Preferences.ts
|
|
250
|
-
import * as
|
|
251
|
-
var CompanyPreference =
|
|
252
|
-
_id:
|
|
279
|
+
import * as z11 from "zod";
|
|
280
|
+
var CompanyPreference = z11.object({
|
|
281
|
+
_id: CompanyId,
|
|
282
|
+
ownerId: UserDetails.shape._id,
|
|
253
283
|
/** The user that's allowed to record the client's services. */
|
|
254
284
|
serviceSelector: companyServiceSelectors,
|
|
255
285
|
/** Pay per service */
|
|
256
|
-
pps:
|
|
286
|
+
pps: z11.boolean(),
|
|
257
287
|
/**
|
|
258
288
|
* @property RR (Round Robin): Even distribution.
|
|
259
289
|
* @property LOR (Least Outstanding Requests): Distribute based on availability.
|
|
260
290
|
*/
|
|
261
291
|
serviceDistAlg: serviceDistAlgs,
|
|
262
|
-
servicesDeployed:
|
|
292
|
+
servicesDeployed: z11.boolean(),
|
|
263
293
|
...TimeLog.shape
|
|
264
294
|
}).refine(
|
|
265
295
|
(data) => !data.pps || data.pps && data.serviceSelector === "scheduler",
|
|
@@ -270,69 +300,40 @@ var MutableCompanyPreferences = CompanyPreference.omit({
|
|
|
270
300
|
lastModified: true
|
|
271
301
|
});
|
|
272
302
|
|
|
303
|
+
// src/schemas/company/components/State.ts
|
|
304
|
+
import * as z12 from "zod";
|
|
305
|
+
var CompanyState = z12.object({
|
|
306
|
+
_id: CompanyId,
|
|
307
|
+
ownerId: UserDetails.shape._id,
|
|
308
|
+
credits: z12.object({
|
|
309
|
+
current: z12.number(),
|
|
310
|
+
lastModified: Timestamp.optional()
|
|
311
|
+
}),
|
|
312
|
+
tierId: z12.object({
|
|
313
|
+
current: z12.string(),
|
|
314
|
+
lastModified: Timestamp.optional()
|
|
315
|
+
}),
|
|
316
|
+
count: z12.object({
|
|
317
|
+
invoiceNo: z12.int().min(0),
|
|
318
|
+
tktNo: z12.int().min(1)
|
|
319
|
+
}),
|
|
320
|
+
// distRoleIds: z.array(z.string()),
|
|
321
|
+
/** Data retention period in months */
|
|
322
|
+
// drpInMonths: z.int().min(1),
|
|
323
|
+
...TimeLog.shape
|
|
324
|
+
});
|
|
325
|
+
|
|
273
326
|
// src/schemas/company/components/Staff.ts
|
|
274
327
|
import { distinct } from "@wavy/fn";
|
|
275
|
-
import * as
|
|
328
|
+
import * as z14 from "zod";
|
|
276
329
|
|
|
277
330
|
// src/functions/helper-functions.ts
|
|
278
331
|
import { camelCaseToLetter, upperFirst } from "@wavy/fn";
|
|
279
332
|
|
|
280
333
|
// src/schemas/company/entities/client/Details.ts
|
|
281
|
-
import * as
|
|
282
|
-
|
|
283
|
-
// src/schemas/user/Details.ts
|
|
284
|
-
import { UserModel } from "@wavy/util";
|
|
285
|
-
import * as z11 from "zod";
|
|
286
|
-
|
|
287
|
-
// src/constants.ts
|
|
288
|
-
var NOTIF_ID_DELIM = "::";
|
|
289
|
-
var MAX_NAME_LENGTH = 21;
|
|
290
|
-
|
|
291
|
-
// src/schemas/user/Details.ts
|
|
292
|
-
var UserDetails = z11.object({
|
|
293
|
-
...UserModel.shape,
|
|
294
|
-
_id: z11.uuidv4(),
|
|
295
|
-
name: z11.string().transform((data) => {
|
|
296
|
-
const [firstName = "", lastName = ""] = data.split(" ");
|
|
297
|
-
return (firstName + " " + lastName).trim();
|
|
298
|
-
}).superRefine((data, ctx) => {
|
|
299
|
-
data.split(" ").forEach((name, idx) => {
|
|
300
|
-
const nty = idx === 0 ? "First" : "Last";
|
|
301
|
-
if (idx === 0 && name.length < 2) {
|
|
302
|
-
ctx.addIssue(`${nty} name must have at least (2) characters.`);
|
|
303
|
-
}
|
|
304
|
-
if (name.length > MAX_NAME_LENGTH) {
|
|
305
|
-
ctx.addIssue(
|
|
306
|
-
`${nty} name can't have more than (${MAX_NAME_LENGTH}) characters.`
|
|
307
|
-
);
|
|
308
|
-
}
|
|
309
|
-
});
|
|
310
|
-
}),
|
|
311
|
-
email: UserModel.shape.email,
|
|
312
|
-
publicKey: z11.string().optional(),
|
|
313
|
-
// Used to track the user's general purpose (gp) storage and the total storage used by
|
|
314
|
-
// their companies.
|
|
315
|
-
usedStorageInBytes: z11.record(
|
|
316
|
-
CompanyState.shape._id.or(z11.literal("gp")),
|
|
317
|
-
z11.object({
|
|
318
|
-
current: z11.number().positive(),
|
|
319
|
-
...TimeLog.shape
|
|
320
|
-
})
|
|
321
|
-
).readonly(),
|
|
322
|
-
// notifications: z.array(Notification),
|
|
323
|
-
lastSignedIn: z11.object({
|
|
324
|
-
auto: Timestamp,
|
|
325
|
-
manual: Timestamp
|
|
326
|
-
}).partial(),
|
|
327
|
-
// This is useful for tracking the companies that a non-company owner belongs to.
|
|
328
|
-
companyIds: z11.array(CompanyState.shape._id).min(1).optional(),
|
|
329
|
-
// resumeToken: z.uuidv4().optional(),
|
|
330
|
-
...TimeLog.shape
|
|
331
|
-
}).omit({ uid: true });
|
|
332
|
-
|
|
333
|
-
// src/schemas/company/entities/client/Details.ts
|
|
334
|
+
import * as z13 from "zod";
|
|
334
335
|
import { Address as Address2, PhoneNumber as PhoneNumber2 } from "@wavy/util";
|
|
335
|
-
var Name =
|
|
336
|
+
var Name = z13.string().trim().min(2).max(MAX_NAME_LENGTH).transform((d) => d.replace(/-+/g, "-").replace(/'+/g, "'")).superRefine((data, ctx) => {
|
|
336
337
|
const invalidCharIdx = data.search(/[^a-z'-]/i);
|
|
337
338
|
if (invalidCharIdx >= 0) {
|
|
338
339
|
const char = data[invalidCharIdx].includes('"') ? `(${data[invalidCharIdx]})` : `"${data[invalidCharIdx]}"`;
|
|
@@ -346,31 +347,31 @@ var ClientDetails = UserDetails.pick({
|
|
|
346
347
|
phoneNumber: true,
|
|
347
348
|
photoUrl: true
|
|
348
349
|
}).safeExtend(
|
|
349
|
-
|
|
350
|
+
z13.object({
|
|
350
351
|
firstName: Name,
|
|
351
352
|
middleName: Name,
|
|
352
353
|
lastName: Name,
|
|
353
354
|
email: UserDetails.shape.email.optional(),
|
|
354
355
|
dob: Timestamp,
|
|
355
356
|
sex: genders,
|
|
356
|
-
isGlobal:
|
|
357
|
+
isGlobal: z13.boolean(),
|
|
357
358
|
origin: CompanyIdentity.shape._id,
|
|
358
|
-
visits:
|
|
359
|
+
visits: z13.record(CompanyIdentity.shape._id, z13.array(Timestamp).min(1)).optional(),
|
|
359
360
|
phoneNumber: PhoneNumber2.optional(),
|
|
360
361
|
// aka. National id
|
|
361
|
-
nid:
|
|
362
|
+
nid: z13.object({
|
|
362
363
|
trn: Trn,
|
|
363
364
|
nin: AlphaNumeric.toLowerCase().min(5).max(20),
|
|
364
365
|
passportNo: AlphaNumeric.toLowerCase().min(5).max(15)
|
|
365
366
|
}).partial().optional(),
|
|
366
367
|
// Don't hash the attributes, they can be used to help accurately identify a client by whoever is searching for
|
|
367
368
|
// the client
|
|
368
|
-
attributes:
|
|
369
|
+
attributes: z13.object({
|
|
369
370
|
motherMaidenName: Name,
|
|
370
371
|
fatherMiddleName: Name,
|
|
371
372
|
motherMiddleName: Name,
|
|
372
373
|
oldestSiblingMiddleName: Name,
|
|
373
|
-
firstSchoolName:
|
|
374
|
+
firstSchoolName: z13.string().trim().min(3).max(60)
|
|
374
375
|
}).partial().refine(
|
|
375
376
|
(data) => Object.keys(data).length > 0,
|
|
376
377
|
"At least (1) attribute must be defined."
|
|
@@ -414,39 +415,39 @@ var parseClientName = ({
|
|
|
414
415
|
}) => [firstName, middleName[0] + ".", lastName].join(" ");
|
|
415
416
|
|
|
416
417
|
// src/schemas/company/components/Staff.ts
|
|
417
|
-
var CompanyMemberRoles =
|
|
418
|
+
var CompanyMemberRoles = z14.array(companyUserRoles).transform((roles) => distinct(roles).sort()).refine((roles) => {
|
|
418
419
|
return !roles.find(
|
|
419
420
|
(role) => getIncompatibleRoles(role).some((r) => roles.includes(r))
|
|
420
421
|
);
|
|
421
422
|
}, "A user is not allowed to have conflicting roles.");
|
|
422
|
-
var CompanyStaff =
|
|
423
|
-
_id:
|
|
423
|
+
var CompanyStaff = z14.object({
|
|
424
|
+
_id: CompanyId,
|
|
424
425
|
ownerId: UserDetails.shape._id,
|
|
425
|
-
members:
|
|
426
|
+
members: z14.record(
|
|
426
427
|
UserDetails.shape._id,
|
|
427
|
-
|
|
428
|
+
z14.object({
|
|
428
429
|
invitedAt: Timestamp.optional(),
|
|
429
430
|
joinedAt: Timestamp,
|
|
430
|
-
lastSession:
|
|
431
|
+
lastSession: z14.object({
|
|
431
432
|
startedAt: Timestamp,
|
|
432
433
|
endedAt: Timestamp
|
|
433
434
|
}).partial().optional(),
|
|
434
435
|
roles: CompanyMemberRoles,
|
|
435
|
-
serviceCounter:
|
|
436
|
+
serviceCounter: z14.record(z14.literal(["undone", "done"]), z14.int().min(0)).optional()
|
|
436
437
|
})
|
|
437
438
|
),
|
|
438
439
|
/**
|
|
439
440
|
* @relationship one -> many
|
|
440
441
|
*@description A map of doctor `uids` to their assistants `uids` */
|
|
441
|
-
partnerMap:
|
|
442
|
+
partnerMap: z14.record(
|
|
442
443
|
UserDetails.shape._id,
|
|
443
|
-
|
|
444
|
+
z14.record(UserDetails.shape._id, z14.object({ addedAt: Timestamp }))
|
|
444
445
|
).optional(),
|
|
445
|
-
updateQueue:
|
|
446
|
+
updateQueue: z14.record(
|
|
446
447
|
UserDetails.shape._id,
|
|
447
|
-
|
|
448
|
-
$REMOVE:
|
|
449
|
-
$CHANGE_ROLES:
|
|
448
|
+
z14.object({
|
|
449
|
+
$REMOVE: z14.object({ addedAt: Timestamp }),
|
|
450
|
+
$CHANGE_ROLES: z14.object({
|
|
450
451
|
newRoles: CompanyMemberRoles,
|
|
451
452
|
addedAt: Timestamp
|
|
452
453
|
})
|
|
@@ -483,7 +484,7 @@ var MutableCompanyStaff = CompanyStaff.pick({
|
|
|
483
484
|
});
|
|
484
485
|
|
|
485
486
|
// src/schemas/company/CompanyDetails.ts
|
|
486
|
-
var CompanyDetails =
|
|
487
|
+
var CompanyDetails = z15.object({
|
|
487
488
|
_id: CompanyState.shape._id,
|
|
488
489
|
identity: CompanyIdentity.omit({ _id: true }),
|
|
489
490
|
// notifications: CompanyNotifications,
|
|
@@ -493,14 +494,14 @@ var CompanyDetails = z14.object({
|
|
|
493
494
|
billing: CompanyBilling.omit({ _id: true }),
|
|
494
495
|
staff: CompanyStaff.omit({ _id: true })
|
|
495
496
|
});
|
|
496
|
-
var _CompanyDetails =
|
|
497
|
+
var _CompanyDetails = z15.object({
|
|
497
498
|
identity: CompanyIdentity,
|
|
498
499
|
state: CompanyState,
|
|
499
500
|
preference: CompanyPreference,
|
|
500
501
|
billing: CompanyBilling,
|
|
501
502
|
staff: CompanyStaff
|
|
502
503
|
});
|
|
503
|
-
var MutableCompanyDetails =
|
|
504
|
+
var MutableCompanyDetails = z15.object({
|
|
504
505
|
_id: CompanyDetails.shape._id,
|
|
505
506
|
identity: MutableCompanyIdentity.partial().optional(),
|
|
506
507
|
preferences: MutableCompanyPreferences.partial().optional(),
|
|
@@ -509,28 +510,28 @@ var MutableCompanyDetails = z14.object({
|
|
|
509
510
|
});
|
|
510
511
|
|
|
511
512
|
// src/schemas/company/components/Notifications.ts
|
|
512
|
-
import * as
|
|
513
|
+
import * as z17 from "zod";
|
|
513
514
|
|
|
514
515
|
// src/schemas/Global.ts
|
|
515
|
-
import * as
|
|
516
|
-
var TierList =
|
|
516
|
+
import * as z16 from "zod";
|
|
517
|
+
var TierList = z16.record(
|
|
517
518
|
tiers,
|
|
518
|
-
|
|
519
|
-
cost:
|
|
520
|
-
perks:
|
|
519
|
+
z16.object({
|
|
520
|
+
cost: z16.number().min(0),
|
|
521
|
+
perks: z16.array(z16.string()).min(1)
|
|
521
522
|
})
|
|
522
523
|
).superRefine((data, ctx) => {
|
|
523
524
|
if (data.basic.cost !== 0) {
|
|
524
525
|
ctx.addIssue("The basic tier must always cost $0.00");
|
|
525
526
|
}
|
|
526
527
|
});
|
|
527
|
-
var Notification =
|
|
528
|
-
_id:
|
|
529
|
-
const isUUidV4 =
|
|
528
|
+
var Notification = z16.object({
|
|
529
|
+
_id: z16.string().superRefine((data, ctx) => {
|
|
530
|
+
const isUUidV4 = z16.uuidv4().safeParse(data).success;
|
|
530
531
|
if (isUUidV4) return;
|
|
531
532
|
let [from, to, nonce] = data.split(NOTIF_ID_DELIM);
|
|
532
533
|
nonce = nonce?.trim() || "";
|
|
533
|
-
const parsedFrom =
|
|
534
|
+
const parsedFrom = z16.uuidv4().or(z16.uuidv7()).safeParse(from);
|
|
534
535
|
if (!parsedFrom.success) {
|
|
535
536
|
ctx.addIssue({
|
|
536
537
|
code: "custom",
|
|
@@ -538,7 +539,7 @@ var Notification = z15.object({
|
|
|
538
539
|
path: ["from"]
|
|
539
540
|
});
|
|
540
541
|
}
|
|
541
|
-
const parsedTo =
|
|
542
|
+
const parsedTo = z16.uuidv4().safeParse(to);
|
|
542
543
|
if (!parsedTo.success) {
|
|
543
544
|
ctx.addIssue({
|
|
544
545
|
code: "custom",
|
|
@@ -554,19 +555,19 @@ var Notification = z15.object({
|
|
|
554
555
|
});
|
|
555
556
|
}
|
|
556
557
|
}),
|
|
557
|
-
code:
|
|
558
|
+
code: z16.literal([
|
|
558
559
|
"INVITE_RESPONSE",
|
|
559
560
|
"COMPANY_INVITE",
|
|
560
561
|
"DEV_MESSAGE",
|
|
561
562
|
"ALERT"
|
|
562
563
|
]),
|
|
563
|
-
payload:
|
|
564
|
-
isArchived:
|
|
565
|
-
rcpt:
|
|
566
|
-
src:
|
|
567
|
-
_id:
|
|
568
|
-
name:
|
|
569
|
-
photoUrl:
|
|
564
|
+
payload: z16.string(),
|
|
565
|
+
isArchived: z16.boolean().optional(),
|
|
566
|
+
rcpt: z16.uuidv4().or(z16.uuidv7()).nullable(),
|
|
567
|
+
src: z16.object({
|
|
568
|
+
_id: z16.uuidv4().or(z16.uuidv7()),
|
|
569
|
+
name: z16.string(),
|
|
570
|
+
photoUrl: z16.string().nullish()
|
|
570
571
|
}),
|
|
571
572
|
createdAt: Timestamp
|
|
572
573
|
}).superRefine((data, ctx) => {
|
|
@@ -577,7 +578,7 @@ var Notification = z15.object({
|
|
|
577
578
|
};
|
|
578
579
|
switch (data.code) {
|
|
579
580
|
case "COMPANY_INVITE":
|
|
580
|
-
if (!
|
|
581
|
+
if (!z16.jwt().safeParse(data.payload).success) {
|
|
581
582
|
ctx.addIssue("The payload of company invite must be a valid jwt.");
|
|
582
583
|
}
|
|
583
584
|
break;
|
|
@@ -598,25 +599,25 @@ var Notification = z15.object({
|
|
|
598
599
|
return data.code;
|
|
599
600
|
}
|
|
600
601
|
});
|
|
601
|
-
var CreditCurrency =
|
|
602
|
-
uid:
|
|
603
|
-
cost:
|
|
604
|
-
value:
|
|
602
|
+
var CreditCurrency = z16.object({
|
|
603
|
+
uid: z16.uuidv4(),
|
|
604
|
+
cost: z16.object({ value: z16.number().min(0), currency: acceptedCurrencies }),
|
|
605
|
+
value: z16.int().min(0),
|
|
605
606
|
...TimeLog.shape
|
|
606
607
|
});
|
|
607
|
-
var PaymentDetails =
|
|
608
|
+
var PaymentDetails = z16.object({
|
|
608
609
|
// Used to track the payments recorded by each paymentCollector
|
|
609
|
-
uid:
|
|
610
|
+
uid: z16.uuidv4(),
|
|
610
611
|
method: paymentMethods,
|
|
611
612
|
currency: acceptedCurrencies,
|
|
612
|
-
amount:
|
|
613
|
+
amount: z16.number().min(1),
|
|
613
614
|
// Rate chart id (used to identify the rate chart used to convert the amount )
|
|
614
615
|
// rcid: z.uuidv4(),
|
|
615
616
|
...TimeLog.shape
|
|
616
617
|
});
|
|
617
618
|
|
|
618
619
|
// src/schemas/company/components/Notifications.ts
|
|
619
|
-
var CompanyNotifications =
|
|
620
|
+
var CompanyNotifications = z17.array(Notification).refine(
|
|
620
621
|
(data) => data.every((notif) => notif.code !== "COMPANY_INVITE"),
|
|
621
622
|
"A company can't receive a company invite."
|
|
622
623
|
);
|
|
@@ -631,8 +632,8 @@ var ClientForm = ClientDetails.pick({
|
|
|
631
632
|
}).required();
|
|
632
633
|
|
|
633
634
|
// src/schemas/company/entities/CreateCompanyForm.ts
|
|
634
|
-
import * as
|
|
635
|
-
var CreateCompanyForm =
|
|
635
|
+
import * as z18 from "zod";
|
|
636
|
+
var CreateCompanyForm = z18.object({
|
|
636
637
|
alias: CompanyIdentity.shape.alias.optional(),
|
|
637
638
|
...CompanyIdentity.pick({
|
|
638
639
|
_id: true,
|
|
@@ -651,81 +652,81 @@ var CreateCompanyForm = z17.object({
|
|
|
651
652
|
});
|
|
652
653
|
|
|
653
654
|
// src/schemas/company/entities/Session.ts
|
|
654
|
-
import * as
|
|
655
|
-
var CompanySession =
|
|
656
|
-
_id:
|
|
657
|
-
user:
|
|
655
|
+
import * as z19 from "zod";
|
|
656
|
+
var CompanySession = z19.object({
|
|
657
|
+
_id: z19.uuidv4(),
|
|
658
|
+
user: z19.object({
|
|
658
659
|
_id: UserDetails.shape._id,
|
|
659
|
-
ip:
|
|
660
|
+
ip: z19.string(),
|
|
660
661
|
email: UserDetails.shape.email,
|
|
661
662
|
roles: CompanyMemberRoles,
|
|
662
|
-
available:
|
|
663
|
-
busy:
|
|
663
|
+
available: z19.boolean(),
|
|
664
|
+
busy: z19.boolean(),
|
|
664
665
|
serviceCounter: CompanyStaff.shape.members.valueType.shape.serviceCounter.nonoptional()
|
|
665
666
|
}),
|
|
666
|
-
companyId:
|
|
667
|
-
ttl:
|
|
668
|
-
expiresAfter:
|
|
667
|
+
companyId: CompanyId,
|
|
668
|
+
ttl: z19.number(),
|
|
669
|
+
expiresAfter: z19.date(),
|
|
669
670
|
// Add in a future update...
|
|
670
671
|
// logs: z.record(Timestamp, z.object({ resource: z.string(), action: "remove" })),
|
|
671
672
|
...TimeLog.shape
|
|
672
673
|
});
|
|
673
674
|
|
|
674
675
|
// src/schemas/company/entities/service/payloads/Medical.ts
|
|
675
|
-
import * as
|
|
676
|
-
var Vitals =
|
|
676
|
+
import * as z20 from "zod";
|
|
677
|
+
var Vitals = z20.record(
|
|
677
678
|
vitalKeys,
|
|
678
|
-
|
|
679
|
-
value:
|
|
679
|
+
z20.object({
|
|
680
|
+
value: z20.string().trim().regex(/^\d{0,3}((\/|\.)\d{1,3})?/),
|
|
680
681
|
lastModified: Timestamp.nullable()
|
|
681
682
|
})
|
|
682
683
|
);
|
|
683
|
-
var Medicine =
|
|
684
|
-
brand:
|
|
684
|
+
var Medicine = z20.object({
|
|
685
|
+
brand: z20.string().trim(),
|
|
685
686
|
expiresAt: Timestamp.nullish(),
|
|
686
|
-
quantity:
|
|
687
|
+
quantity: z20.string().trim().regex(/^\d+(\.\d{1,3})? ?[a-zA-Z]{1,20}/, {
|
|
687
688
|
error: "Failed to match the pattern <number>+(.<number>{1,3})? ?[a-zA-Z]{1,20}"
|
|
688
689
|
}),
|
|
689
|
-
refills:
|
|
690
|
-
directions:
|
|
690
|
+
refills: z20.string().trim().regex(/^[0-8]/, { error: "Must be between 0 and 8" }),
|
|
691
|
+
directions: z20.string().trim().max(100, { error: "Must be 100 characters or less" }),
|
|
691
692
|
...TimeLog.shape
|
|
692
693
|
});
|
|
693
|
-
var MedicalDetails =
|
|
694
|
+
var MedicalDetails = z20.object({
|
|
694
695
|
vitals: Vitals,
|
|
695
|
-
prescriptions:
|
|
696
|
-
doctorNote:
|
|
697
|
-
value:
|
|
696
|
+
prescriptions: z20.array(z20.array(Medicine)).nullish(),
|
|
697
|
+
doctorNote: z20.object({
|
|
698
|
+
value: z20.string(),
|
|
698
699
|
lastModified: Timestamp.nullable()
|
|
699
700
|
}),
|
|
700
|
-
physAsstNotes:
|
|
701
|
-
|
|
702
|
-
title:
|
|
703
|
-
content:
|
|
701
|
+
physAsstNotes: z20.array(
|
|
702
|
+
z20.object({
|
|
703
|
+
title: z20.string(),
|
|
704
|
+
content: z20.string(),
|
|
704
705
|
...TimeLog.shape
|
|
705
706
|
})
|
|
706
707
|
).optional()
|
|
707
708
|
});
|
|
708
709
|
|
|
709
710
|
// src/schemas/company/entities/service/ServiceDetails.ts
|
|
710
|
-
import * as
|
|
711
|
-
var ServiceSeverity =
|
|
712
|
-
"1":
|
|
713
|
-
"2":
|
|
714
|
-
"3":
|
|
711
|
+
import * as z21 from "zod";
|
|
712
|
+
var ServiceSeverity = z21.object({
|
|
713
|
+
"1": z21.literal("Emergency"),
|
|
714
|
+
"2": z21.literal("Important"),
|
|
715
|
+
"3": z21.literal("Average")
|
|
715
716
|
});
|
|
716
|
-
var ServiceDetails =
|
|
717
|
+
var ServiceDetails = z21.object({
|
|
717
718
|
/** A random uid that identifies the document. */
|
|
718
|
-
_id:
|
|
719
|
+
_id: z21.uuidv4(),
|
|
719
720
|
/** The amount of credits used to create the appointment */
|
|
720
|
-
_cost:
|
|
721
|
+
_cost: z21.number().readonly(),
|
|
721
722
|
// This helps to identify the urgency of the appointment
|
|
722
|
-
severity:
|
|
723
|
+
severity: z21.string().refine((data) => ServiceSeverity.keyof().safeParse(data).success),
|
|
723
724
|
/** The company's uid */
|
|
724
725
|
src: CompanyState.shape._id,
|
|
725
726
|
/** The ticket number */
|
|
726
727
|
tkt: TicketNo,
|
|
727
728
|
/**The reason for the service */
|
|
728
|
-
reason:
|
|
729
|
+
reason: z21.object({
|
|
729
730
|
value: Reason.shape.value,
|
|
730
731
|
...TimeLog.shape
|
|
731
732
|
}),
|
|
@@ -746,23 +747,23 @@ var ServiceDetails = z20.object({
|
|
|
746
747
|
/**Required to calculate the accurate grandTotal of the charges */
|
|
747
748
|
discounts: CompanyBilling.shape.discounts.optional(),
|
|
748
749
|
prepayments: CompanyBilling.shape.prepayments.optional(),
|
|
749
|
-
payments:
|
|
750
|
+
payments: z21.array(PaymentDetails).max(100).optional(),
|
|
750
751
|
/** The client's identity */
|
|
751
752
|
clientId: ClientDetails.shape._id,
|
|
752
753
|
/**
|
|
753
754
|
* Data that is specific to the entity (for now it's just medical data).
|
|
754
755
|
* It will only be defined for the participants that have access to it.
|
|
755
756
|
*/
|
|
756
|
-
payload:
|
|
757
|
+
payload: z21.object({
|
|
757
758
|
...MedicalDetails.shape,
|
|
758
759
|
lastModified: Timestamp.optional()
|
|
759
760
|
}).optional(),
|
|
760
761
|
/** Only defined when either the service provider or the client cancelled their appointment */
|
|
761
|
-
cancelled:
|
|
762
|
+
cancelled: z21.object({
|
|
762
763
|
/** The time that the confirm cancel button was clicked */
|
|
763
764
|
doneAt: Timestamp,
|
|
764
765
|
reason: Reason,
|
|
765
|
-
doneBy: companyUserRoles.extract(["doc", "physAsst", "rcpst"]).or(
|
|
766
|
+
doneBy: companyUserRoles.extract(["doc", "physAsst", "rcpst"]).or(z21.literal("client"))
|
|
766
767
|
}).optional(),
|
|
767
768
|
//** Add this after consulting with company owners about payment expectations */
|
|
768
769
|
// paymentDueDate: Timestamp.nullish(),
|
|
@@ -773,17 +774,17 @@ var ServiceDetails = z20.object({
|
|
|
773
774
|
* [1] Ommitted -> any user with that role that's from the same company can access the ServiceDetails.
|
|
774
775
|
* [1] Addded -> only the users that have that role and an id in the respective array can access the ServiceDetails.
|
|
775
776
|
*/
|
|
776
|
-
rbac:
|
|
777
|
-
timeline:
|
|
777
|
+
rbac: z21.record(companyUserRoles, z21.array(UserDetails.shape._id).optional()),
|
|
778
|
+
timeline: z21.record(
|
|
778
779
|
UserDetails.shape._id,
|
|
779
|
-
|
|
780
|
+
z21.object({
|
|
780
781
|
/** Removed to rely on a single source of truth (audit logs stored in s3)
|
|
781
782
|
* as it relates to a user's roles at any given time.
|
|
782
783
|
*/
|
|
783
784
|
// roles: CompanyMemberRoles,
|
|
784
785
|
postedAt: Timestamp,
|
|
785
786
|
// Use null as an indicator that this is intentionally undefined.
|
|
786
|
-
changes:
|
|
787
|
+
changes: z21.record(z21.string(), z21.any()).nullable()
|
|
787
788
|
}).optional()
|
|
788
789
|
),
|
|
789
790
|
// z.object({
|
|
@@ -805,15 +806,40 @@ var ServiceDetails = z20.object({
|
|
|
805
806
|
...TimeLog.shape
|
|
806
807
|
});
|
|
807
808
|
var MutableServiceDetails = ServiceDetails.safeExtend(
|
|
808
|
-
|
|
809
|
+
z21.object({
|
|
809
810
|
/**
|
|
810
811
|
* @description An encrypted copy of the last state of the appointment.
|
|
811
812
|
* @note Used to accurately update the appointment without having to query the database
|
|
812
813
|
*/
|
|
813
|
-
_hash:
|
|
814
|
+
_hash: z21.string()
|
|
814
815
|
}).shape
|
|
815
816
|
);
|
|
816
817
|
|
|
818
|
+
// src/schemas/user/Storage.ts
|
|
819
|
+
import * as z22 from "zod";
|
|
820
|
+
var UserStorage = z22.object({
|
|
821
|
+
_id: UserDetails.shape._id,
|
|
822
|
+
profile: z22.object({
|
|
823
|
+
current: z22.number().min(0),
|
|
824
|
+
class: z22.string().trim(),
|
|
825
|
+
lastModified: Timestamp.optional()
|
|
826
|
+
}),
|
|
827
|
+
company: z22.record(
|
|
828
|
+
CompanyId,
|
|
829
|
+
z22.object({
|
|
830
|
+
class: z22.string().trim(),
|
|
831
|
+
items: z22.record(
|
|
832
|
+
_CompanyDetails.keyof(),
|
|
833
|
+
z22.object({
|
|
834
|
+
current: z22.number().min(0),
|
|
835
|
+
lastModified: Timestamp.optional()
|
|
836
|
+
})
|
|
837
|
+
)
|
|
838
|
+
})
|
|
839
|
+
).optional(),
|
|
840
|
+
createdAt: Timestamp
|
|
841
|
+
});
|
|
842
|
+
|
|
817
843
|
// src/functions/calc.ts
|
|
818
844
|
import { sumOf } from "@wavy/fn";
|
|
819
845
|
function calcBalance(components, options) {
|
|
@@ -900,6 +926,7 @@ export {
|
|
|
900
926
|
Timestamp,
|
|
901
927
|
Trn,
|
|
902
928
|
UserDetails,
|
|
929
|
+
UserStorage,
|
|
903
930
|
Vitals,
|
|
904
931
|
_CompanyDetails,
|
|
905
932
|
acceptedCurrencies,
|