@blackcode_sa/metaestetics-api 1.15.17-staging.5 → 1.15.17-staging.7

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.
@@ -4961,7 +4961,7 @@ var ClinicAggregationService = class {
4961
4961
  try {
4962
4962
  await groupRef.update({
4963
4963
  clinicsInfo: admin8.firestore.FieldValue.arrayUnion(clinicInfo),
4964
- clinicIds: admin8.firestore.FieldValue.arrayUnion(clinicId),
4964
+ clinics: admin8.firestore.FieldValue.arrayUnion(clinicId),
4965
4965
  updatedAt: admin8.firestore.FieldValue.serverTimestamp()
4966
4966
  });
4967
4967
  console.log(
@@ -4883,7 +4883,7 @@ var ClinicAggregationService = class {
4883
4883
  try {
4884
4884
  await groupRef.update({
4885
4885
  clinicsInfo: admin8.firestore.FieldValue.arrayUnion(clinicInfo),
4886
- clinicIds: admin8.firestore.FieldValue.arrayUnion(clinicId),
4886
+ clinics: admin8.firestore.FieldValue.arrayUnion(clinicId),
4887
4887
  updatedAt: admin8.firestore.FieldValue.serverTimestamp()
4888
4888
  });
4889
4889
  console.log(
package/dist/index.js CHANGED
@@ -10542,7 +10542,7 @@ var removeMedicationUtil = async (db, patientId, medicationIndex, requesterId, r
10542
10542
  // src/services/patient/utils/profile.utils.ts
10543
10543
  var import_firestore26 = require("firebase/firestore");
10544
10544
  var import_zod13 = require("zod");
10545
- var createPatientProfileUtil = async (db, data, generateId2) => {
10545
+ var createPatientProfileUtil = async (db, data, generateId) => {
10546
10546
  var _a, _b;
10547
10547
  try {
10548
10548
  console.log("[createPatientProfileUtil] Starting patient profile creation");
@@ -10552,7 +10552,7 @@ var createPatientProfileUtil = async (db, data, generateId2) => {
10552
10552
  "userRef is required to create a standard patient profile."
10553
10553
  );
10554
10554
  }
10555
- const patientId = generateId2();
10555
+ const patientId = generateId();
10556
10556
  console.log(`[createPatientProfileUtil] Generated patientId: ${patientId}`);
10557
10557
  const patientData = {
10558
10558
  id: patientId,
@@ -10886,7 +10886,7 @@ var createPatientTokenSchema = import_zod14.z.object({
10886
10886
  });
10887
10887
 
10888
10888
  // src/services/patient/utils/token.utils.ts
10889
- var createPatientTokenUtil = async (db, data, createdBy, generateId2) => {
10889
+ var createPatientTokenUtil = async (db, data, createdBy, generateId) => {
10890
10890
  var _a;
10891
10891
  const validatedData = createPatientTokenSchema.parse(data);
10892
10892
  const patientRef = getPatientDocRef(db, validatedData.patientId);
@@ -10897,9 +10897,9 @@ var createPatientTokenUtil = async (db, data, createdBy, generateId2) => {
10897
10897
  );
10898
10898
  }
10899
10899
  const expiration = validatedData.expiresAt || new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3);
10900
- const tokenString = generateId2().slice(0, 6).toUpperCase();
10900
+ const tokenString = generateId().slice(0, 6).toUpperCase();
10901
10901
  const token = {
10902
- id: generateId2(),
10902
+ id: generateId(),
10903
10903
  token: tokenString,
10904
10904
  patientId: validatedData.patientId,
10905
10905
  email: validatedData.email,
@@ -15637,14 +15637,12 @@ async function uploadMultiplePhotos(photos, entityType, entityId, photoType, app
15637
15637
  }
15638
15638
 
15639
15639
  // src/services/clinic/utils/clinic-group.utils.ts
15640
- function generateId() {
15641
- const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
15642
- const timestamp = Date.now().toString(36);
15643
- const randomPart = Array.from(
15644
- { length: 12 },
15640
+ function generateTokenCode() {
15641
+ const chars = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
15642
+ return Array.from(
15643
+ { length: 6 },
15645
15644
  () => chars.charAt(Math.floor(Math.random() * chars.length))
15646
15645
  ).join("");
15647
- return `${randomPart}-${timestamp}`;
15648
15646
  }
15649
15647
  async function createClinicGroup(db, data, ownerId, isDefault = false, clinicAdminService, app) {
15650
15648
  console.log("[CLINIC_GROUP] Starting clinic group creation", {
@@ -15936,7 +15934,7 @@ async function createAdminToken(db, groupId, creatorAdminId, app, data) {
15936
15934
  const tokenRef = (0, import_firestore41.doc)(adminTokensRef(db, groupId));
15937
15935
  const token = {
15938
15936
  id: tokenRef.id,
15939
- token: generateId(),
15937
+ token: generateTokenCode(),
15940
15938
  status: "active" /* ACTIVE */,
15941
15939
  email,
15942
15940
  clinicGroupId: groupId,
@@ -17799,7 +17797,6 @@ var AuthService = class extends BaseService {
17799
17797
  });
17800
17798
  console.log("[AUTH] Updating admin with clinic group ID");
17801
17799
  await clinicAdminService.updateClinicAdmin(adminProfile.id, {
17802
- // Use admin profile ID, not user UID
17803
17800
  clinicGroupId: clinicGroup.id
17804
17801
  });
17805
17802
  console.log("[AUTH] Admin updated with clinic group ID successfully");
@@ -18683,8 +18680,8 @@ function getClinicSyncedCalendarDocRef(db, clinicId, syncedCalendarId) {
18683
18680
  }
18684
18681
 
18685
18682
  // src/services/calendar/utils/clinic.utils.ts
18686
- async function createClinicCalendarEventUtil(db, clinicId, eventData, generateId2) {
18687
- const eventId = generateId2();
18683
+ async function createClinicCalendarEventUtil(db, clinicId, eventData, generateId) {
18684
+ const eventId = generateId();
18688
18685
  const eventRef = getClinicCalendarEventDocRef(db, clinicId, eventId);
18689
18686
  const newEvent = {
18690
18687
  id: eventId,
@@ -18734,8 +18731,8 @@ async function checkAutoConfirmAppointmentsUtil(db, clinicId) {
18734
18731
 
18735
18732
  // src/services/calendar/utils/patient.utils.ts
18736
18733
  var import_firestore49 = require("firebase/firestore");
18737
- async function createPatientCalendarEventUtil(db, patientId, eventData, generateId2) {
18738
- const eventId = generateId2();
18734
+ async function createPatientCalendarEventUtil(db, patientId, eventData, generateId) {
18735
+ const eventId = generateId();
18739
18736
  const eventRef = getPatientCalendarEventDocRef(db, patientId, eventId);
18740
18737
  const newEvent = {
18741
18738
  id: eventId,
@@ -18766,8 +18763,8 @@ async function updatePatientCalendarEventUtil(db, patientId, eventId, updateData
18766
18763
 
18767
18764
  // src/services/calendar/utils/practitioner.utils.ts
18768
18765
  var import_firestore50 = require("firebase/firestore");
18769
- async function createPractitionerCalendarEventUtil(db, practitionerId, eventData, generateId2) {
18770
- const eventId = generateId2();
18766
+ async function createPractitionerCalendarEventUtil(db, practitionerId, eventData, generateId) {
18767
+ const eventId = generateId();
18771
18768
  const eventRef = getPractitionerCalendarEventDocRef(
18772
18769
  db,
18773
18770
  practitionerId,
@@ -18805,8 +18802,8 @@ async function updatePractitionerCalendarEventUtil(db, practitionerId, eventId,
18805
18802
  }
18806
18803
 
18807
18804
  // src/services/calendar/utils/appointment.utils.ts
18808
- async function createAppointmentUtil(db, clinicId, practitionerId, patientId, eventData, generateId2) {
18809
- const eventId = generateId2();
18805
+ async function createAppointmentUtil(db, clinicId, practitionerId, patientId, eventData, generateId) {
18806
+ const eventId = generateId();
18810
18807
  const autoConfirm = await checkAutoConfirmAppointmentsUtil(db, clinicId);
18811
18808
  const initialStatus = autoConfirm ? "confirmed" /* CONFIRMED */ : "pending" /* PENDING */;
18812
18809
  const appointmentData = {
@@ -18972,8 +18969,8 @@ async function searchCalendarEventsUtil(db, params) {
18972
18969
 
18973
18970
  // src/services/calendar/utils/synced-calendar.utils.ts
18974
18971
  var import_firestore52 = require("firebase/firestore");
18975
- async function createPractitionerSyncedCalendarUtil(db, practitionerId, calendarData, generateId2) {
18976
- const calendarId = generateId2();
18972
+ async function createPractitionerSyncedCalendarUtil(db, practitionerId, calendarData, generateId) {
18973
+ const calendarId = generateId();
18977
18974
  const calendarRef = getPractitionerSyncedCalendarDocRef(
18978
18975
  db,
18979
18976
  practitionerId,
@@ -18992,8 +18989,8 @@ async function createPractitionerSyncedCalendarUtil(db, practitionerId, calendar
18992
18989
  updatedAt: import_firestore52.Timestamp.now()
18993
18990
  };
18994
18991
  }
18995
- async function createPatientSyncedCalendarUtil(db, patientId, calendarData, generateId2) {
18996
- const calendarId = generateId2();
18992
+ async function createPatientSyncedCalendarUtil(db, patientId, calendarData, generateId) {
18993
+ const calendarId = generateId();
18997
18994
  const calendarRef = getPatientSyncedCalendarDocRef(db, patientId, calendarId);
18998
18995
  const newCalendar = {
18999
18996
  id: calendarId,
@@ -19008,8 +19005,8 @@ async function createPatientSyncedCalendarUtil(db, patientId, calendarData, gene
19008
19005
  updatedAt: import_firestore52.Timestamp.now()
19009
19006
  };
19010
19007
  }
19011
- async function createClinicSyncedCalendarUtil(db, clinicId, calendarData, generateId2) {
19012
- const calendarId = generateId2();
19008
+ async function createClinicSyncedCalendarUtil(db, clinicId, calendarData, generateId) {
19009
+ const calendarId = generateId();
19013
19010
  const calendarRef = getClinicSyncedCalendarDocRef(db, clinicId, calendarId);
19014
19011
  const newCalendar = {
19015
19012
  id: calendarId,
package/dist/index.mjs CHANGED
@@ -10509,7 +10509,7 @@ import {
10509
10509
  doc as doc16
10510
10510
  } from "firebase/firestore";
10511
10511
  import { z as z13 } from "zod";
10512
- var createPatientProfileUtil = async (db, data, generateId2) => {
10512
+ var createPatientProfileUtil = async (db, data, generateId) => {
10513
10513
  var _a, _b;
10514
10514
  try {
10515
10515
  console.log("[createPatientProfileUtil] Starting patient profile creation");
@@ -10519,7 +10519,7 @@ var createPatientProfileUtil = async (db, data, generateId2) => {
10519
10519
  "userRef is required to create a standard patient profile."
10520
10520
  );
10521
10521
  }
10522
- const patientId = generateId2();
10522
+ const patientId = generateId();
10523
10523
  console.log(`[createPatientProfileUtil] Generated patientId: ${patientId}`);
10524
10524
  const patientData = {
10525
10525
  id: patientId,
@@ -10864,7 +10864,7 @@ var createPatientTokenSchema = z14.object({
10864
10864
  });
10865
10865
 
10866
10866
  // src/services/patient/utils/token.utils.ts
10867
- var createPatientTokenUtil = async (db, data, createdBy, generateId2) => {
10867
+ var createPatientTokenUtil = async (db, data, createdBy, generateId) => {
10868
10868
  var _a;
10869
10869
  const validatedData = createPatientTokenSchema.parse(data);
10870
10870
  const patientRef = getPatientDocRef(db, validatedData.patientId);
@@ -10875,9 +10875,9 @@ var createPatientTokenUtil = async (db, data, createdBy, generateId2) => {
10875
10875
  );
10876
10876
  }
10877
10877
  const expiration = validatedData.expiresAt || new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3);
10878
- const tokenString = generateId2().slice(0, 6).toUpperCase();
10878
+ const tokenString = generateId().slice(0, 6).toUpperCase();
10879
10879
  const token = {
10880
- id: generateId2(),
10880
+ id: generateId(),
10881
10881
  token: tokenString,
10882
10882
  patientId: validatedData.patientId,
10883
10883
  email: validatedData.email,
@@ -15666,14 +15666,12 @@ async function uploadMultiplePhotos(photos, entityType, entityId, photoType, app
15666
15666
  }
15667
15667
 
15668
15668
  // src/services/clinic/utils/clinic-group.utils.ts
15669
- function generateId() {
15670
- const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
15671
- const timestamp = Date.now().toString(36);
15672
- const randomPart = Array.from(
15673
- { length: 12 },
15669
+ function generateTokenCode() {
15670
+ const chars = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
15671
+ return Array.from(
15672
+ { length: 6 },
15674
15673
  () => chars.charAt(Math.floor(Math.random() * chars.length))
15675
15674
  ).join("");
15676
- return `${randomPart}-${timestamp}`;
15677
15675
  }
15678
15676
  async function createClinicGroup(db, data, ownerId, isDefault = false, clinicAdminService, app) {
15679
15677
  console.log("[CLINIC_GROUP] Starting clinic group creation", {
@@ -15965,7 +15963,7 @@ async function createAdminToken(db, groupId, creatorAdminId, app, data) {
15965
15963
  const tokenRef = doc28(adminTokensRef(db, groupId));
15966
15964
  const token = {
15967
15965
  id: tokenRef.id,
15968
- token: generateId(),
15966
+ token: generateTokenCode(),
15969
15967
  status: "active" /* ACTIVE */,
15970
15968
  email,
15971
15969
  clinicGroupId: groupId,
@@ -17868,7 +17866,6 @@ var AuthService = class extends BaseService {
17868
17866
  });
17869
17867
  console.log("[AUTH] Updating admin with clinic group ID");
17870
17868
  await clinicAdminService.updateClinicAdmin(adminProfile.id, {
17871
- // Use admin profile ID, not user UID
17872
17869
  clinicGroupId: clinicGroup.id
17873
17870
  });
17874
17871
  console.log("[AUTH] Admin updated with clinic group ID successfully");
@@ -18774,8 +18771,8 @@ function getClinicSyncedCalendarDocRef(db, clinicId, syncedCalendarId) {
18774
18771
  }
18775
18772
 
18776
18773
  // src/services/calendar/utils/clinic.utils.ts
18777
- async function createClinicCalendarEventUtil(db, clinicId, eventData, generateId2) {
18778
- const eventId = generateId2();
18774
+ async function createClinicCalendarEventUtil(db, clinicId, eventData, generateId) {
18775
+ const eventId = generateId();
18779
18776
  const eventRef = getClinicCalendarEventDocRef(db, clinicId, eventId);
18780
18777
  const newEvent = {
18781
18778
  id: eventId,
@@ -18837,8 +18834,8 @@ import {
18837
18834
  Timestamp as Timestamp25,
18838
18835
  serverTimestamp as serverTimestamp26
18839
18836
  } from "firebase/firestore";
18840
- async function createPatientCalendarEventUtil(db, patientId, eventData, generateId2) {
18841
- const eventId = generateId2();
18837
+ async function createPatientCalendarEventUtil(db, patientId, eventData, generateId) {
18838
+ const eventId = generateId();
18842
18839
  const eventRef = getPatientCalendarEventDocRef(db, patientId, eventId);
18843
18840
  const newEvent = {
18844
18841
  id: eventId,
@@ -18881,8 +18878,8 @@ import {
18881
18878
  Timestamp as Timestamp26,
18882
18879
  serverTimestamp as serverTimestamp27
18883
18880
  } from "firebase/firestore";
18884
- async function createPractitionerCalendarEventUtil(db, practitionerId, eventData, generateId2) {
18885
- const eventId = generateId2();
18881
+ async function createPractitionerCalendarEventUtil(db, practitionerId, eventData, generateId) {
18882
+ const eventId = generateId();
18886
18883
  const eventRef = getPractitionerCalendarEventDocRef(
18887
18884
  db,
18888
18885
  practitionerId,
@@ -18920,8 +18917,8 @@ async function updatePractitionerCalendarEventUtil(db, practitionerId, eventId,
18920
18917
  }
18921
18918
 
18922
18919
  // src/services/calendar/utils/appointment.utils.ts
18923
- async function createAppointmentUtil(db, clinicId, practitionerId, patientId, eventData, generateId2) {
18924
- const eventId = generateId2();
18920
+ async function createAppointmentUtil(db, clinicId, practitionerId, patientId, eventData, generateId) {
18921
+ const eventId = generateId();
18925
18922
  const autoConfirm = await checkAutoConfirmAppointmentsUtil(db, clinicId);
18926
18923
  const initialStatus = autoConfirm ? "confirmed" /* CONFIRMED */ : "pending" /* PENDING */;
18927
18924
  const appointmentData = {
@@ -19111,8 +19108,8 @@ import {
19111
19108
  Timestamp as Timestamp28,
19112
19109
  serverTimestamp as serverTimestamp29
19113
19110
  } from "firebase/firestore";
19114
- async function createPractitionerSyncedCalendarUtil(db, practitionerId, calendarData, generateId2) {
19115
- const calendarId = generateId2();
19111
+ async function createPractitionerSyncedCalendarUtil(db, practitionerId, calendarData, generateId) {
19112
+ const calendarId = generateId();
19116
19113
  const calendarRef = getPractitionerSyncedCalendarDocRef(
19117
19114
  db,
19118
19115
  practitionerId,
@@ -19131,8 +19128,8 @@ async function createPractitionerSyncedCalendarUtil(db, practitionerId, calendar
19131
19128
  updatedAt: Timestamp28.now()
19132
19129
  };
19133
19130
  }
19134
- async function createPatientSyncedCalendarUtil(db, patientId, calendarData, generateId2) {
19135
- const calendarId = generateId2();
19131
+ async function createPatientSyncedCalendarUtil(db, patientId, calendarData, generateId) {
19132
+ const calendarId = generateId();
19136
19133
  const calendarRef = getPatientSyncedCalendarDocRef(db, patientId, calendarId);
19137
19134
  const newCalendar = {
19138
19135
  id: calendarId,
@@ -19147,8 +19144,8 @@ async function createPatientSyncedCalendarUtil(db, patientId, calendarData, gene
19147
19144
  updatedAt: Timestamp28.now()
19148
19145
  };
19149
19146
  }
19150
- async function createClinicSyncedCalendarUtil(db, clinicId, calendarData, generateId2) {
19151
- const calendarId = generateId2();
19147
+ async function createClinicSyncedCalendarUtil(db, clinicId, calendarData, generateId) {
19148
+ const calendarId = generateId();
19152
19149
  const calendarRef = getClinicSyncedCalendarDocRef(db, clinicId, calendarId);
19153
19150
  const newCalendar = {
19154
19151
  id: calendarId,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@blackcode_sa/metaestetics-api",
3
3
  "private": false,
4
- "version": "1.15.17-staging.5",
4
+ "version": "1.15.17-staging.7",
5
5
  "description": "Firebase authentication service with anonymous upgrade support",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.mjs",
@@ -59,7 +59,7 @@ export class ClinicAggregationService {
59
59
  try {
60
60
  await groupRef.update({
61
61
  clinicsInfo: admin.firestore.FieldValue.arrayUnion(clinicInfo),
62
- clinicIds: admin.firestore.FieldValue.arrayUnion(clinicId),
62
+ clinics: admin.firestore.FieldValue.arrayUnion(clinicId),
63
63
  updatedAt: admin.firestore.FieldValue.serverTimestamp(),
64
64
  });
65
65
 
@@ -319,11 +319,12 @@ export class AuthService extends BaseService {
319
319
  // Now update the admin with the group ID
320
320
  console.log('[AUTH] Updating admin with clinic group ID');
321
321
  await clinicAdminService.updateClinicAdmin(adminProfile.id, {
322
- // Use admin profile ID, not user UID
323
322
  clinicGroupId: clinicGroup.id,
324
323
  });
325
324
  console.log('[AUTH] Admin updated with clinic group ID successfully');
326
325
 
326
+ // adminsInfo is populated by onCreateClinicAdmin Firestore trigger
327
+
327
328
  // Get the updated admin profile
328
329
  adminProfile = await clinicAdminService.getClinicAdmin(adminProfile.id);
329
330
  } catch (groupCreationError) {
@@ -50,6 +50,18 @@ function generateId(): string {
50
50
  return `${randomPart}-${timestamp}`;
51
51
  }
52
52
 
53
+ /**
54
+ * Generates a short 6-character uppercase alphanumeric token code.
55
+ * Used for admin registration tokens — easy to read, type, and share.
56
+ * 36^6 = ~2.1 billion combinations, collision risk negligible for active tokens.
57
+ */
58
+ function generateTokenCode(): string {
59
+ const chars = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"; // no I/1/O/0 to avoid confusion
60
+ return Array.from({ length: 6 }, () =>
61
+ chars.charAt(Math.floor(Math.random() * chars.length))
62
+ ).join("");
63
+ }
64
+
53
65
  /**
54
66
  * Creates a new clinic group
55
67
  * @param db - Firestore database instance
@@ -372,9 +384,10 @@ export async function addAdminToGroup(
372
384
  adminId,
373
385
  groupId,
374
386
  });
375
- return; // Admin is already in the group
387
+ return;
376
388
  }
377
389
 
390
+ // Only add the admin ID — adminsInfo is populated by onCreateClinicAdmin trigger
378
391
  console.log("[CLINIC_GROUP] Updating group with new admin");
379
392
  await updateClinicGroup(
380
393
  db,
@@ -501,7 +514,7 @@ export async function createAdminToken(
501
514
  const tokenRef = doc(adminTokensRef(db, groupId));
502
515
  const token: AdminToken = {
503
516
  id: tokenRef.id,
504
- token: generateId(),
517
+ token: generateTokenCode(),
505
518
  status: AdminTokenStatus.ACTIVE,
506
519
  email,
507
520
  clinicGroupId: groupId,