@bizmap/sdk 0.0.98 → 0.0.100

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 +344 -349
  2. package/dist/main.js +30 -26
  3. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -80,13 +80,7 @@ var StandardTime = z5.string().trim().refine(
80
80
  (d) => d && d.replace(/^(01|(0[2-9])|(1[0-2])):(([1-5][0-9])|0[0-9]) (am|pm)/i, "").length === 0,
81
81
  'Invalid standard time: must match the pattern "hh:mm A"'
82
82
  );
83
- var Timestamp = z5.int().positive().superRefine((d, ctx) => {
84
- const totalDigits = d.toString().length;
85
- if (totalDigits < 10)
86
- ctx.addIssue("A timestamp must have at least (10) digits.");
87
- else if (totalDigits > 15)
88
- ctx.addIssue("A timestamp can't have more than (15) digits.");
89
- });
83
+ var Timestamp = z5.iso.datetime();
90
84
  var InviteResponse = z5.enum(["accepted", "declined"]);
91
85
  var TimeLog = z5.object({
92
86
  createdAt: Timestamp.readonly(),
@@ -780,13 +774,15 @@ var MedicalDetails = z20.object({
780
774
  });
781
775
 
782
776
  // src/schemas/appointment/Appointment.ts
783
- import * as z21 from "zod";
784
777
  import { sumOf as sumOf2 } from "@wavy/fn";
778
+ import * as z21 from "zod";
785
779
 
786
780
  // src/functions/calcAppointmentFee.ts
787
781
  import { sumOf } from "@wavy/fn";
788
782
  function calcAppointmentFee(appointment) {
789
- const subtotal = sumOf(appointment.charges?.map((c) => c.cost));
783
+ const subtotal = sumOf(
784
+ Object.values(appointment.charges || {})?.map((c) => c.cost)
785
+ );
790
786
  const discount = calcAdjustment(appointment.discounts, subtotal);
791
787
  const additionalFees = calcAdjustment(appointment.additionalFees, subtotal);
792
788
  const prepayments = calcAdjustment(appointment.prepayments, subtotal);
@@ -794,9 +790,10 @@ function calcAppointmentFee(appointment) {
794
790
  return subtotal + additionalFees - (discount + prepayments);
795
791
  }
796
792
  var calcAdjustment = (adjustments, subtotal) => {
797
- if (!adjustments || adjustments.length < 1) return 0;
793
+ const castedAdjustments = !adjustments ? [] : Object.values(adjustments);
794
+ if (!adjustments || castedAdjustments.length < 1) return 0;
798
795
  return sumOf(
799
- adjustments?.map(
796
+ castedAdjustments?.map(
800
797
  (d) => (d.fixedAmount?.value || 0) + (d.percentage ? d.percentage * 0.01 * subtotal : 0)
801
798
  )
802
799
  );
@@ -811,7 +808,6 @@ var MiniAppointmentDetails = z21.object({
811
808
  /** A random uid that identifies the document. */
812
809
  _id: z21.uuidv4(),
813
810
  // This helps to identify the urgency of the appointment
814
- // 3
815
811
  category: z21.int().min(1).max(3),
816
812
  /** The company's uid */
817
813
  src: CompanyState.shape._id,
@@ -830,12 +826,15 @@ var MiniAppointmentDetails = z21.object({
830
826
  */
831
827
  invoiceNo: InvoiceNo.optional(),
832
828
  /** The services that the client has done/will do. */
833
- charges: z21.array(PriceTag).max(20),
829
+ charges: CompanyBilling.shape.offeredServices.nullish().refine(
830
+ (d) => !d || Object.keys(d).length <= 20,
831
+ "Expected no more than (20) charges."
832
+ ),
834
833
  /**Required to calculate the accurate grandTotal of the charges */
835
- additionalFees: z21.array(PriceAdjustment).nullable().readonly(),
834
+ additionalFees: CompanyBilling.shape.additionalFees.nullish(),
836
835
  /**Required to calculate the accurate grandTotal of the charges */
837
- discounts: z21.array(PriceAdjustment).nullable().readonly(),
838
- prepayments: z21.array(PriceAdjustment).nullable(),
836
+ discounts: CompanyBilling.shape.discounts.nullish(),
837
+ prepayments: CompanyBilling.shape.prepayments.nullish(),
839
838
  /** The client's identity */
840
839
  clientUid: ClientIdentity.shape._id,
841
840
  /**
@@ -965,10 +964,11 @@ async function scheduleAppointment(request) {
965
964
  const companyUser = request.staff?.members[request.sender._id];
966
965
  const staffDetailsCopy = CompanyStaff.parse(structuredClone(request.staff));
967
966
  const stateCopy = CompanyState.parse(structuredClone(request.state));
967
+ const castedFormCharges = Object.values(request.form?.charges || {});
968
968
  let selectedDoctor = null;
969
969
  let selectedPhysAsst = null;
970
970
  const availableDoctors = findAvailableStaff("doc", staffDetailsCopy);
971
- const today = Date.now();
971
+ const today = new Date(Date.now()).toISOString();
972
972
  if (!companyUser || !companyUser?.roles?.includes?.("rcpst")) {
973
973
  throw new Error("Permissions missing.");
974
974
  }
@@ -1002,9 +1002,9 @@ async function scheduleAppointment(request) {
1002
1002
  staffDetailsCopy
1003
1003
  );
1004
1004
  }
1005
- if (request.preferences.serviceSelector === "scheduler" && (!request.form.charges || request.form.charges.length < 1)) {
1005
+ if (request.preferences.serviceSelector === "scheduler" && (!request.form.charges || castedFormCharges.length < 1)) {
1006
1006
  throw new Error("Insufficient services selected.");
1007
- } else if (request.preferences.serviceSelector === "scheduler" && request.billing.offeredServices.deployed && request.form.charges.find(
1007
+ } else if (request.preferences.serviceSelector === "scheduler" && request.billing.offeredServices.deployed && castedFormCharges.find(
1008
1008
  (charge) => !!Object.values(request.billing.offeredServices).find(
1009
1009
  (createdCharge) => findChanges(charge, createdCharge).length > 0
1010
1010
  )
@@ -1015,7 +1015,7 @@ async function scheduleAppointment(request) {
1015
1015
  throw new Error("Insufficient payment transactions recorded.");
1016
1016
  } else if (request.preferences.enforcePaidAppointments) {
1017
1017
  const maxIterations = Math.max(
1018
- request.form.charges.length,
1018
+ castedFormCharges.length,
1019
1019
  request.form.payments.length
1020
1020
  );
1021
1021
  let totalPaid = 0;
@@ -1049,15 +1049,19 @@ async function scheduleAppointment(request) {
1049
1049
  src: stateCopy._id,
1050
1050
  tkt: request.state.tktNoCounter,
1051
1051
  category: request.form.category,
1052
- discounts: Object.values(request.billing.discounts || {}).filter(
1053
- (disc) => !disc.isOptional
1052
+ discounts: Object.fromEntries(
1053
+ Object.entries(request.billing.discounts || {}).filter(
1054
+ ([_, disc]) => !disc.isOptional
1055
+ )
1054
1056
  ),
1055
- additionalFees: Object.values(request.billing.additionalFees || {}).filter(
1056
- (fee) => !fee.isOptional
1057
+ additionalFees: Object.fromEntries(
1058
+ Object.entries(request.billing.additionalFees || {}).filter(
1059
+ ([_, fee]) => !fee.isOptional
1060
+ )
1057
1061
  ),
1058
1062
  payments: request.preferences.enforcePaidAppointments ? request.form.payments : null,
1059
- prepayments: request.preferences.enforcePaidAppointments ? request.form.prepayments || [] : null,
1060
- charges: request.preferences.serviceSelector === "scheduler" ? request.form.charges : [],
1063
+ prepayments: request.preferences.enforcePaidAppointments ? request.form?.prepayments ?? null : null,
1064
+ charges: request.preferences.serviceSelector === "scheduler" ? request.form?.charges ?? null : null,
1061
1065
  client: await request.findClient(request.form.clientId),
1062
1066
  _hash: "aa.aa.aa",
1063
1067
  lastModified: null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bizmap/sdk",
3
- "version": "0.0.98",
3
+ "version": "0.0.100",
4
4
  "main": "./dist/main.js",
5
5
  "types": "./dist/main.d.ts",
6
6
  "type": "module",