@bizmap/sdk 0.0.116 → 0.0.117

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 (3) hide show
  1. package/dist/main.d.ts +204 -223
  2. package/dist/main.js +76 -91
  3. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -75,7 +75,7 @@ var Timestamp = z5.iso.datetime();
75
75
  var InviteResponse = z5.enum(["accepted", "declined"]);
76
76
  var TimeLog = z5.object({
77
77
  createdAt: Timestamp.readonly(),
78
- lastModified: Timestamp.nullish()
78
+ lastModified: Timestamp.optional()
79
79
  });
80
80
  var TicketNo = z5.int().positive().refine(
81
81
  (t) => t.toString().length <= 10,
@@ -145,26 +145,25 @@ var CompanyState = z7.object({
145
145
  }),
146
146
  credits: z7.object({
147
147
  current: z7.number(),
148
- lastModified: Timestamp.nullable()
148
+ lastModified: Timestamp.optional()
149
149
  }),
150
150
  maxStaff: z7.object({
151
151
  current: z7.int().min(1),
152
- lastModified: Timestamp.nullable()
152
+ lastModified: Timestamp.optional()
153
153
  }),
154
154
  usedStorageInBytes: z7.object({
155
155
  current: z7.number(),
156
- lastModified: Timestamp.nullable()
156
+ lastModified: Timestamp.optional()
157
157
  }),
158
158
  /** Data retention period in months */
159
- drpInMonths: z7.int().min(1),
159
+ // drpInMonths: z.int().min(1),
160
160
  /** A counter for the company's invoice no.
161
161
  * @note This should only be null when the cycle resets
162
162
  */
163
163
  invoiceNoCounter: z7.int().min(1),
164
164
  /** A counter for the company's ticket no. */
165
165
  tktNoCounter: z7.int().min(1),
166
- lastSavedAt: Timestamp.nullable(),
167
- lastModified: Timestamp.nullable(),
166
+ lastModified: Timestamp.optional(),
168
167
  version: Version,
169
168
  createdAt: Timestamp
170
169
  });
@@ -190,7 +189,7 @@ var CompanyBilling = z8.object({
190
189
  }
191
190
  }),
192
191
  version: Version,
193
- lastModified: Timestamp.nullable()
192
+ lastModified: Timestamp.optional()
194
193
  });
195
194
  var MutableCompanyBilling = CompanyBilling.omit({
196
195
  uid: true,
@@ -216,9 +215,7 @@ var getInvalidSectorError = (industry, sector) => `Invalid sector: "${sector}" i
216
215
  // src/schemas/company/components/Identity.ts
217
216
  var CompanyIdentity = z10.object({
218
217
  _id: CompanyState.shape._id,
219
- alias: z10.string().trim().min(3).max(63).transform(
220
- (data) => data.replace(/[^a-z1-9 ]/gi, "").replace(/\s+/g, " ")
221
- ).superRefine((data, ctx) => {
218
+ alias: z10.string().trim().min(3).max(63).transform((data) => data.replace(/\s+/g, " ")).superRefine((data, ctx) => {
222
219
  const invalidCharIdx = data.search(/[^a-z1-9 ]/i);
223
220
  if (invalidCharIdx >= 0) {
224
221
  ctx.addIssue(
@@ -227,18 +224,18 @@ var CompanyIdentity = z10.object({
227
224
  }
228
225
  }),
229
226
  address: Address.optional(),
230
- logo: z10.string().nullish(),
227
+ logo: z10.string().optional(),
231
228
  industry: CompanyIndustry.keyof().readonly(),
232
229
  sector: z10.string(),
233
230
  contact: z10.object({
234
- email: z10.email().max(25),
231
+ email: z10.email().max(45),
235
232
  phoneNumber: PhoneNumber.optional(),
236
233
  emailVerified: z10.boolean()
237
234
  }),
238
235
  // Can only be changed by the server
239
236
  tier: z10.object({
240
237
  current: tiers,
241
- lastModified: Timestamp.nullable()
238
+ lastModified: Timestamp.optional()
242
239
  }),
243
240
  isVerified: z10.boolean(),
244
241
  legal: z10.object({
@@ -248,7 +245,7 @@ var CompanyIdentity = z10.object({
248
245
  gctRegNo: z10.string().max(15).nullish()
249
246
  }).optional(),
250
247
  version: Version,
251
- lastModified: Timestamp.nullable()
248
+ lastModified: Timestamp.optional()
252
249
  }).superRefine((data, ctx) => {
253
250
  const hasLegalInfo = "legal" in data;
254
251
  if (data.isVerified && !hasLegalInfo) {
@@ -403,10 +400,10 @@ var CompanyPreferences = z13.object({
403
400
  * @property RR (Round Robin): Even distribution.
404
401
  * @property LOR (Least Outstanding Requests): Distribute based on availability.
405
402
  */
406
- apptDistAlg: appointmentDistAlgs.default("RR"),
403
+ apptDistAlg: appointmentDistAlgs,
407
404
  servicesDeployed: z13.boolean(),
408
405
  version: Version,
409
- lastModified: Timestamp.nullable()
406
+ lastModified: Timestamp.optional()
410
407
  }).refine(
411
408
  (data) => !data.enforcePaidAppointments || data.enforcePaidAppointments && data.serviceSelector === "scheduler",
412
409
  'Enforcing paid appointments is only allowed when the service selector is the "scheduler".'
@@ -451,13 +448,13 @@ var UserDetails = z14.object({
451
448
  });
452
449
  }),
453
450
  email: UserModel.shape.email,
454
- publicKey: z14.string().nullable(),
451
+ publicKey: z14.string().optional(),
455
452
  // notifications: z.array(Notification),
456
453
  version: Version.default(1),
457
454
  lastSignedIn: z14.object({
458
455
  auto: Timestamp,
459
456
  manual: Timestamp
460
- }).partial(),
457
+ }).partial().optional(),
461
458
  companyUids: z14.array(CompanyState.shape._id).min(1).optional(),
462
459
  // resumeToken: z.uuidv4().optional(),
463
460
  ...TimeLog.shape
@@ -508,7 +505,7 @@ var ClientIdentity = UserDetails.pick({
508
505
  }).partial().refine(
509
506
  (data) => Object.keys(data).length > 0,
510
507
  "At least (1) attribute must be defined."
511
- ),
508
+ ).optional(),
512
509
  address: Address2.optional(),
513
510
  linkedTo: UserDetails.shape._id.optional()
514
511
  }).shape
@@ -578,11 +575,11 @@ var CompanyUserSession = z16.object({
578
575
  deviceId: z16.string().trim().min(15),
579
576
  isAvailable: z16.object({
580
577
  value: z16.boolean(),
581
- lastModified: Timestamp.nullable()
578
+ lastModified: Timestamp.optional()
582
579
  }),
583
580
  isBusy: z16.object({
584
581
  value: z16.boolean(),
585
- lastModified: Timestamp.nullable()
582
+ lastModified: Timestamp.optional()
586
583
  }),
587
584
  appointments: z16.record(z16.literal(["ongoing", "completed"]), z16.int().min(0)),
588
585
  roles: z16.array(companyUserRoles).transform((roles) => {
@@ -597,7 +594,7 @@ var CompanyUserSession = z16.object({
597
594
  );
598
595
  }, "A user is not allowed to have conflicting roles."),
599
596
  ttl: z16.number(),
600
- lastModified: Timestamp.nullable(),
597
+ lastModified: Timestamp.optional(),
601
598
  expiresAfter: z16.date()
602
599
  });
603
600
  var MiniCompanyUser2 = z16.object({
@@ -610,9 +607,9 @@ var MiniCompanyUser2 = z16.object({
610
607
  appointments: true
611
608
  }).shape,
612
609
  /** The time before the company session gets deleted */
613
- lastActive: Timestamp.nullable(),
614
- inviteSent: Timestamp.nullish(),
615
- inviteAccepted: Timestamp.nullable()
610
+ lastActive: Timestamp.optional(),
611
+ inviteSent: Timestamp.optional(),
612
+ inviteAccepted: Timestamp.optional()
616
613
  });
617
614
  var CompanyUser2 = z16.object({
618
615
  ...MiniCompanyUser2.shape,
@@ -648,14 +645,14 @@ var MiniRawCompanyStaff = z17.object({
648
645
  }).partial()
649
646
  ),
650
647
  version: Version,
651
- lastModified: Timestamp.nullable()
648
+ lastModified: Timestamp.optional()
652
649
  });
653
650
  var RawCompanyStaff = z17.object({
654
651
  ...MiniRawCompanyStaff.shape,
655
652
  members: z17.record(CompanyUser2.shape._id, CompanyUser2.omit({ _id: true }))
656
653
  });
657
- var transformStaff = (object18) => {
658
- return object18.transform((d) => {
654
+ var transformStaff = (object17) => {
655
+ return object17.transform((d) => {
659
656
  const copy = structuredClone(d);
660
657
  for (const uid of Object.keys(copy.updateQueue)) {
661
658
  if (uid in copy.members) {
@@ -731,19 +728,9 @@ var MutableCompanyDetails = z18.object({
731
728
  staff: MutableCompanyStaff.partial().optional()
732
729
  });
733
730
 
734
- // src/schemas/company/utils/InviteList.ts
735
- import * as z19 from "zod";
736
- var CompanyInviteList = z19.record(
737
- CompanyUser2.shape.email,
738
- z19.object({ createdAt: Timestamp, roles: CompanyUser2.shape.roles })
739
- ).refine(
740
- (data) => Object.keys(data).length > 0,
741
- "Insufficient amount of members invited."
742
- );
743
-
744
731
  // src/schemas/company/utils/CreateCompanyForm.ts
745
- import * as z20 from "zod";
746
- var CreateCompanyForm = z20.object({
732
+ import * as z19 from "zod";
733
+ var CreateCompanyForm = z19.object({
747
734
  _id: CompanyIdentity.shape._id,
748
735
  alias: CompanyIdentity.shape.alias.optional(),
749
736
  logo: CompanyIdentity.shape.logo.optional(),
@@ -758,35 +745,35 @@ var CreateCompanyForm = z20.object({
758
745
  });
759
746
 
760
747
  // src/schemas/appointment/components/Medical.ts
761
- import * as z21 from "zod";
762
- var Vitals = z21.record(
748
+ import * as z20 from "zod";
749
+ var Vitals = z20.record(
763
750
  vitalKeys,
764
- z21.object({
765
- value: z21.string().trim().regex(/^\d{0,3}((\/|\.)\d{1,3})?/),
751
+ z20.object({
752
+ value: z20.string().trim().regex(/^\d{0,3}((\/|\.)\d{1,3})?/),
766
753
  lastModified: Timestamp.nullable()
767
754
  })
768
755
  );
769
- var Medicine = z21.object({
770
- brand: z21.string().trim(),
756
+ var Medicine = z20.object({
757
+ brand: z20.string().trim(),
771
758
  expiresAt: Timestamp.nullish(),
772
- quantity: z21.string().trim().regex(/^\d+(\.\d{1,3})? ?[a-zA-Z]{1,20}/, {
759
+ quantity: z20.string().trim().regex(/^\d+(\.\d{1,3})? ?[a-zA-Z]{1,20}/, {
773
760
  error: "Failed to match the pattern <number>+(.<number>{1,3})? ?[a-zA-Z]{1,20}"
774
761
  }),
775
- refills: z21.string().trim().regex(/^[0-8]/, { error: "Must be between 0 and 8" }),
776
- directions: z21.string().trim().max(100, { error: "Must be 100 characters or less" }),
762
+ refills: z20.string().trim().regex(/^[0-8]/, { error: "Must be between 0 and 8" }),
763
+ directions: z20.string().trim().max(100, { error: "Must be 100 characters or less" }),
777
764
  ...TimeLog.shape
778
765
  });
779
- var MedicalDetails = z21.object({
766
+ var MedicalDetails = z20.object({
780
767
  vitals: Vitals,
781
- prescriptions: z21.array(z21.array(Medicine)).nullish(),
782
- doctorNote: z21.object({
783
- value: z21.string(),
768
+ prescriptions: z20.array(z20.array(Medicine)).nullish(),
769
+ doctorNote: z20.object({
770
+ value: z20.string(),
784
771
  lastModified: Timestamp.nullable()
785
772
  }),
786
- physAsstNotes: z21.array(
787
- z21.object({
788
- title: z21.string(),
789
- content: z21.string(),
773
+ physAsstNotes: z20.array(
774
+ z20.object({
775
+ title: z20.string(),
776
+ content: z20.string(),
790
777
  ...TimeLog.shape
791
778
  })
792
779
  ).optional()
@@ -794,7 +781,7 @@ var MedicalDetails = z21.object({
794
781
 
795
782
  // src/schemas/appointment/Appointment.ts
796
783
  import { sumOf as sumOf2 } from "@wavy/fn";
797
- import * as z22 from "zod";
784
+ import * as z21 from "zod";
798
785
 
799
786
  // src/functions/calc.ts
800
787
  import { sumOf } from "@wavy/fn";
@@ -823,26 +810,26 @@ var calcPriceMod = (mods, subtotal) => {
823
810
  };
824
811
 
825
812
  // src/schemas/appointment/Appointment.ts
826
- var TimelineActivity = z22.object({
813
+ var TimelineActivity = z21.object({
827
814
  postedAt: Timestamp.nullish(),
828
815
  userUid: CompanyUser2.shape._id.nonoptional()
829
816
  });
830
- var AppointmentSeverity = z22.object({
831
- "1": z22.literal("Emergency"),
832
- "2": z22.literal("Important"),
833
- "3": z22.literal("Average")
817
+ var AppointmentSeverity = z21.object({
818
+ "1": z21.literal("Emergency"),
819
+ "2": z21.literal("Important"),
820
+ "3": z21.literal("Average")
834
821
  });
835
- var MiniAppointmentDetails = z22.object({
822
+ var MiniAppointmentDetails = z21.object({
836
823
  /** A random uid that identifies the document. */
837
- _id: z22.uuidv4(),
824
+ _id: z21.uuidv4(),
838
825
  // This helps to identify the urgency of the appointment
839
- severity: z22.string().refine((data) => AppointmentSeverity.keyof().safeParse(data).success),
826
+ severity: z21.string().refine((data) => AppointmentSeverity.keyof().safeParse(data).success),
840
827
  /** The company's uid */
841
828
  src: CompanyState.shape._id,
842
829
  /** The ticket number */
843
830
  tkt: TicketNo,
844
831
  /**The reason for the service */
845
- reason: z22.object({
832
+ reason: z21.object({
846
833
  value: Reason.shape.value,
847
834
  ...TimeLog.shape
848
835
  }),
@@ -859,23 +846,23 @@ var MiniAppointmentDetails = z22.object({
859
846
  "Expected no more than (20) charges."
860
847
  ),
861
848
  /**Required to calculate the accurate grandTotal of the charges */
862
- additionalFees: CompanyBilling.shape.additionalFees.nullish(),
849
+ additionalFees: CompanyBilling.shape.additionalFees.optional(),
863
850
  /**Required to calculate the accurate grandTotal of the charges */
864
- discounts: CompanyBilling.shape.discounts.nullish(),
865
- prepayments: CompanyBilling.shape.prepayments.nullish(),
866
- payments: z22.array(PaymentDetails).max(100).nullish(),
851
+ discounts: CompanyBilling.shape.discounts.optional(),
852
+ prepayments: CompanyBilling.shape.prepayments.optional(),
853
+ payments: z21.array(PaymentDetails).max(100).optional(),
867
854
  /** The client's identity */
868
855
  clientUid: ClientIdentity.shape._id,
869
856
  /**
870
857
  * Data that is specific to the entity (for now it's just medical data).
871
858
  * It will only be defined for the participants that have access to it.
872
859
  */
873
- payload: z22.object({
860
+ payload: z21.object({
874
861
  ...MedicalDetails.shape,
875
- lastModified: z22.number().nullable()
876
- }).nullish(),
862
+ lastModified: z21.number().nullable()
863
+ }).optional(),
877
864
  /** Only defined when either the service provider or the client cancelled their appointment */
878
- cancelled: z22.object({
865
+ cancelled: z21.object({
879
866
  /** The time that the confirm cancel button was clicked */
880
867
  doneAt: Timestamp,
881
868
  reason: Reason,
@@ -885,16 +872,16 @@ var MiniAppointmentDetails = z22.object({
885
872
  // paymentDueDate: Timestamp.nullish(),
886
873
  // The user that is currently modifying the appointment
887
874
  lockedBy: UserDetails.shape._id.optional(),
888
- timeline: z22.object({
875
+ timeline: z21.object({
889
876
  scheduler: TimelineActivity,
890
- physAsst: TimelineActivity.or(z22.literal("none")),
877
+ physAsst: TimelineActivity.or(z21.literal("none")),
891
878
  doctor: TimelineActivity,
892
879
  // Array used to accurately record payments made by the "a/r" and the "cshr"
893
- debtCollector: z22.array(
894
- z22.object({
880
+ debtCollector: z21.array(
881
+ z21.object({
895
882
  ...TimelineActivity.shape,
896
883
  // Payment uid -> collection time
897
- collectedPayments: z22.record(z22.uuidv4(), Timestamp)
884
+ collectedPayments: z21.record(z21.uuidv4(), Timestamp)
898
885
  })
899
886
  ).min(1).nullable()
900
887
  }),
@@ -913,19 +900,19 @@ var MiniAppointmentDetails = z22.object({
913
900
  });
914
901
  var AppointmentDetails = MiniAppointmentDetails.omit({
915
902
  clientUid: true
916
- }).extend(z22.object({ client: ClientIdentity }).shape);
903
+ }).extend(z21.object({ client: ClientIdentity }).shape);
917
904
  var MutableAppointmentDetails = AppointmentDetails.safeExtend(
918
- z22.object({
905
+ z21.object({
919
906
  /**
920
907
  * @description An encrypted copy of the last state of the appointment.
921
908
  * @note Used to accurately update the appointment without having to query the database
922
909
  */
923
- _hash: z22.string()
910
+ _hash: z21.string()
924
911
  }).shape
925
912
  );
926
- var ScheduleAppointmentForm = z22.object({
913
+ var ScheduleAppointmentForm = z21.object({
927
914
  clientId: ClientIdentity.shape._id,
928
- serviceProviderId: CompanyUser2.shape._id.or(z22.literal("next")),
915
+ serviceProviderId: CompanyUser2.shape._id.or(z21.literal("next")),
929
916
  category: AppointmentDetails.shape.severity,
930
917
  appointmentReason: AppointmentDetails.shape.reason,
931
918
  charges: AppointmentDetails.shape.charges.optional(),
@@ -935,7 +922,7 @@ var ScheduleAppointmentForm = z22.object({
935
922
  });
936
923
 
937
924
  // src/functions/scheduleAppointment.ts
938
- import { findChanges, omit, TODO } from "@wavy/fn";
925
+ import { findChanges, omit, omitNils, TODO } from "@wavy/fn";
939
926
  import { v4 } from "uuid";
940
927
 
941
928
  // src/functions/findAvailableStaff.ts
@@ -1072,7 +1059,7 @@ async function scheduleAppointment(request) {
1072
1059
  staffDetailsCopy.members[selectedPhysAsst].appointments.ongoing++;
1073
1060
  }
1074
1061
  staffDetailsCopy.lastModified = today;
1075
- const appointment = {
1062
+ const appointment = omitNils({
1076
1063
  _id: v4(),
1077
1064
  src: stateCopy._id,
1078
1065
  tkt: request.state.tktNoCounter,
@@ -1093,7 +1080,6 @@ async function scheduleAppointment(request) {
1093
1080
  charges: request.preferences.serviceSelector === "scheduler" ? request.form?.charges ?? null : null,
1094
1081
  client: await request.findClient(request.form.clientId),
1095
1082
  _hash: "aa.aa.aa",
1096
- lastModified: null,
1097
1083
  timeline: {
1098
1084
  scheduler: { userUid: request.sender._id, postedAt: today },
1099
1085
  doctor: { userUid: selectedDoctor },
@@ -1105,7 +1091,7 @@ async function scheduleAppointment(request) {
1105
1091
  }
1106
1092
  },
1107
1093
  createdAt: today
1108
- };
1094
+ });
1109
1095
  appointment._hash = request.createHash(omit(appointment, ["_hash"]));
1110
1096
  return {
1111
1097
  updates: {
@@ -1143,7 +1129,6 @@ export {
1143
1129
  CompanyDetails,
1144
1130
  CompanyIdentity,
1145
1131
  CompanyIndustry,
1146
- CompanyInviteList,
1147
1132
  CompanyNotifications,
1148
1133
  CompanyPreferences,
1149
1134
  CompanyStaff,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bizmap/sdk",
3
- "version": "0.0.116",
3
+ "version": "0.0.117",
4
4
  "main": "./dist/main.js",
5
5
  "types": "./dist/main.d.ts",
6
6
  "type": "module",