@blackcode_sa/metaestetics-api 1.14.10 → 1.14.12

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/index.js CHANGED
@@ -12880,6 +12880,11 @@ var PractitionerService = class extends BaseService {
12880
12880
  var UserService = class extends BaseService {
12881
12881
  constructor(db, auth, app, patientService, clinicAdminService, practitionerService) {
12882
12882
  super(db, auth, app);
12883
+ if (!this.auth.__userServiceId) {
12884
+ this.auth.__userServiceId = "user-service-" + Date.now();
12885
+ }
12886
+ console.log("[USER_SERVICE] Constructor - auth ID:", this.auth.__userServiceId);
12887
+ console.log("[USER_SERVICE] Constructor - auth.__authServiceId:", this.auth.__authServiceId || "NOT SET");
12883
12888
  if (!patientService) {
12884
12889
  patientService = new PatientService(db, auth, app);
12885
12890
  }
@@ -12908,6 +12913,7 @@ var UserService = class extends BaseService {
12908
12913
  async createUser(firebaseUser, roles = ["patient" /* PATIENT */], options) {
12909
12914
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
12910
12915
  console.log("[USER_SERVICE] ====== CREATE USER DEBUG ======");
12916
+ console.log(this.auth);
12911
12917
  console.log("[USER_SERVICE] Auth instance ID:", ((_a = this.auth) == null ? void 0 : _a.__debugId) || "no-id");
12912
12918
  console.log("[USER_SERVICE] Current auth state:", {
12913
12919
  currentUser: ((_c = (_b = this.auth) == null ? void 0 : _b.currentUser) == null ? void 0 : _c.uid) || "NULL",
@@ -15378,9 +15384,15 @@ var validatePractitionerProfileData = async (profileData) => {
15378
15384
  // src/services/auth/auth.service.ts
15379
15385
  var AuthService = class extends BaseService {
15380
15386
  constructor(db, auth, app, userService) {
15387
+ var _a;
15381
15388
  super(db, auth, app);
15382
15389
  this.googleProvider = new import_auth8.GoogleAuthProvider();
15383
15390
  this.userService = userService || new UserService(db, auth, app);
15391
+ if (!this.auth.__authServiceId) {
15392
+ this.auth.__authServiceId = "auth-service-" + Date.now();
15393
+ }
15394
+ console.log("[AUTH] AuthService constructor - auth ID:", this.auth.__authServiceId);
15395
+ console.log("[AUTH] AuthService constructor - userService.auth ID:", ((_a = this.userService.auth) == null ? void 0 : _a.__authServiceId) || "NOT SET");
15384
15396
  }
15385
15397
  /**
15386
15398
  * Waits for Firebase Auth state to settle after sign-in.
@@ -15984,7 +15996,7 @@ var AuthService = class extends BaseService {
15984
15996
  * @returns Object containing user and claimed practitioner
15985
15997
  */
15986
15998
  async claimDraftProfilesWithGoogle(idToken, practitionerIds) {
15987
- var _a, _b;
15999
+ var _a, _b, _c;
15988
16000
  try {
15989
16001
  console.log("[AUTH] Starting claim draft profiles with Google", {
15990
16002
  practitionerIdsCount: practitionerIds.length,
@@ -16009,11 +16021,40 @@ var AuthService = class extends BaseService {
16009
16021
  console.log("[AUTH] User document does not exist, creating it...");
16010
16022
  }
16011
16023
  if (!user) {
16012
- console.log("[AUTH] Creating user document for:", firebaseUser.uid);
16013
- user = await this.userService.createUser(firebaseUser, ["practitioner" /* PRACTITIONER */], {
16014
- skipProfileCreation: true
16024
+ console.log("[AUTH] Creating user document DIRECTLY for:", firebaseUser.uid);
16025
+ console.log("[AUTH] Using THIS.auth.currentUser:", ((_c = this.auth.currentUser) == null ? void 0 : _c.uid) || "NULL");
16026
+ console.log("[AUTH] Using THIS.db:", this.db ? "EXISTS" : "NULL");
16027
+ const userData = {
16028
+ uid: firebaseUser.uid,
16029
+ email: firebaseUser.email,
16030
+ roles: ["practitioner" /* PRACTITIONER */],
16031
+ isAnonymous: firebaseUser.isAnonymous || false,
16032
+ createdAt: (0, import_firestore40.serverTimestamp)(),
16033
+ updatedAt: (0, import_firestore40.serverTimestamp)(),
16034
+ lastLoginAt: (0, import_firestore40.serverTimestamp)()
16035
+ };
16036
+ console.log("[AUTH] Attempting setDoc directly with userData:", {
16037
+ uid: userData.uid,
16038
+ email: userData.email,
16039
+ roles: userData.roles
16015
16040
  });
16016
- console.log("[AUTH] User document created successfully:", user.uid);
16041
+ try {
16042
+ await (0, import_firestore40.setDoc)((0, import_firestore40.doc)(this.db, USERS_COLLECTION, firebaseUser.uid), userData);
16043
+ console.log("[AUTH] \u2705 setDoc SUCCEEDED directly!");
16044
+ const userDoc = await (0, import_firestore40.getDoc)((0, import_firestore40.doc)(this.db, USERS_COLLECTION, firebaseUser.uid));
16045
+ if (!userDoc.exists()) {
16046
+ throw new Error("User document was not created");
16047
+ }
16048
+ user = userDoc.data();
16049
+ console.log("[AUTH] User document created successfully:", user.uid);
16050
+ } catch (error) {
16051
+ console.error("[AUTH] \u274C setDoc FAILED directly:", {
16052
+ errorCode: error == null ? void 0 : error.code,
16053
+ errorMessage: error == null ? void 0 : error.message,
16054
+ uid: firebaseUser.uid
16055
+ });
16056
+ throw error;
16057
+ }
16017
16058
  }
16018
16059
  let practitioner;
16019
16060
  if (practitionerIds.length === 1) {
package/dist/index.mjs CHANGED
@@ -7122,9 +7122,13 @@ import {
7122
7122
  } from "firebase/auth";
7123
7123
  import {
7124
7124
  collection as collection21,
7125
+ doc as doc25,
7126
+ getDoc as getDoc27,
7127
+ setDoc as setDoc16,
7125
7128
  query as query21,
7126
7129
  getDocs as getDocs21,
7127
- runTransaction
7130
+ runTransaction,
7131
+ serverTimestamp as serverTimestamp21
7128
7132
  } from "firebase/firestore";
7129
7133
 
7130
7134
  // src/types/user/index.ts
@@ -12903,6 +12907,11 @@ var PractitionerService = class extends BaseService {
12903
12907
  var UserService = class extends BaseService {
12904
12908
  constructor(db, auth, app, patientService, clinicAdminService, practitionerService) {
12905
12909
  super(db, auth, app);
12910
+ if (!this.auth.__userServiceId) {
12911
+ this.auth.__userServiceId = "user-service-" + Date.now();
12912
+ }
12913
+ console.log("[USER_SERVICE] Constructor - auth ID:", this.auth.__userServiceId);
12914
+ console.log("[USER_SERVICE] Constructor - auth.__authServiceId:", this.auth.__authServiceId || "NOT SET");
12906
12915
  if (!patientService) {
12907
12916
  patientService = new PatientService(db, auth, app);
12908
12917
  }
@@ -12931,6 +12940,7 @@ var UserService = class extends BaseService {
12931
12940
  async createUser(firebaseUser, roles = ["patient" /* PATIENT */], options) {
12932
12941
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
12933
12942
  console.log("[USER_SERVICE] ====== CREATE USER DEBUG ======");
12943
+ console.log(this.auth);
12934
12944
  console.log("[USER_SERVICE] Auth instance ID:", ((_a = this.auth) == null ? void 0 : _a.__debugId) || "no-id");
12935
12945
  console.log("[USER_SERVICE] Current auth state:", {
12936
12946
  currentUser: ((_c = (_b = this.auth) == null ? void 0 : _b.currentUser) == null ? void 0 : _c.uid) || "NULL",
@@ -15465,9 +15475,15 @@ var validatePractitionerProfileData = async (profileData) => {
15465
15475
  // src/services/auth/auth.service.ts
15466
15476
  var AuthService = class extends BaseService {
15467
15477
  constructor(db, auth, app, userService) {
15478
+ var _a;
15468
15479
  super(db, auth, app);
15469
15480
  this.googleProvider = new GoogleAuthProvider();
15470
15481
  this.userService = userService || new UserService(db, auth, app);
15482
+ if (!this.auth.__authServiceId) {
15483
+ this.auth.__authServiceId = "auth-service-" + Date.now();
15484
+ }
15485
+ console.log("[AUTH] AuthService constructor - auth ID:", this.auth.__authServiceId);
15486
+ console.log("[AUTH] AuthService constructor - userService.auth ID:", ((_a = this.userService.auth) == null ? void 0 : _a.__authServiceId) || "NOT SET");
15471
15487
  }
15472
15488
  /**
15473
15489
  * Waits for Firebase Auth state to settle after sign-in.
@@ -16071,7 +16087,7 @@ var AuthService = class extends BaseService {
16071
16087
  * @returns Object containing user and claimed practitioner
16072
16088
  */
16073
16089
  async claimDraftProfilesWithGoogle(idToken, practitionerIds) {
16074
- var _a, _b;
16090
+ var _a, _b, _c;
16075
16091
  try {
16076
16092
  console.log("[AUTH] Starting claim draft profiles with Google", {
16077
16093
  practitionerIdsCount: practitionerIds.length,
@@ -16096,11 +16112,40 @@ var AuthService = class extends BaseService {
16096
16112
  console.log("[AUTH] User document does not exist, creating it...");
16097
16113
  }
16098
16114
  if (!user) {
16099
- console.log("[AUTH] Creating user document for:", firebaseUser.uid);
16100
- user = await this.userService.createUser(firebaseUser, ["practitioner" /* PRACTITIONER */], {
16101
- skipProfileCreation: true
16115
+ console.log("[AUTH] Creating user document DIRECTLY for:", firebaseUser.uid);
16116
+ console.log("[AUTH] Using THIS.auth.currentUser:", ((_c = this.auth.currentUser) == null ? void 0 : _c.uid) || "NULL");
16117
+ console.log("[AUTH] Using THIS.db:", this.db ? "EXISTS" : "NULL");
16118
+ const userData = {
16119
+ uid: firebaseUser.uid,
16120
+ email: firebaseUser.email,
16121
+ roles: ["practitioner" /* PRACTITIONER */],
16122
+ isAnonymous: firebaseUser.isAnonymous || false,
16123
+ createdAt: serverTimestamp21(),
16124
+ updatedAt: serverTimestamp21(),
16125
+ lastLoginAt: serverTimestamp21()
16126
+ };
16127
+ console.log("[AUTH] Attempting setDoc directly with userData:", {
16128
+ uid: userData.uid,
16129
+ email: userData.email,
16130
+ roles: userData.roles
16102
16131
  });
16103
- console.log("[AUTH] User document created successfully:", user.uid);
16132
+ try {
16133
+ await setDoc16(doc25(this.db, USERS_COLLECTION, firebaseUser.uid), userData);
16134
+ console.log("[AUTH] \u2705 setDoc SUCCEEDED directly!");
16135
+ const userDoc = await getDoc27(doc25(this.db, USERS_COLLECTION, firebaseUser.uid));
16136
+ if (!userDoc.exists()) {
16137
+ throw new Error("User document was not created");
16138
+ }
16139
+ user = userDoc.data();
16140
+ console.log("[AUTH] User document created successfully:", user.uid);
16141
+ } catch (error) {
16142
+ console.error("[AUTH] \u274C setDoc FAILED directly:", {
16143
+ errorCode: error == null ? void 0 : error.code,
16144
+ errorMessage: error == null ? void 0 : error.message,
16145
+ uid: firebaseUser.uid
16146
+ });
16147
+ throw error;
16148
+ }
16104
16149
  }
16105
16150
  let practitioner;
16106
16151
  if (practitionerIds.length === 1) {
@@ -16532,7 +16577,7 @@ var AuthService = class extends BaseService {
16532
16577
  };
16533
16578
 
16534
16579
  // src/services/calendar/calendar.v2.service.ts
16535
- import { Timestamp as Timestamp29, serverTimestamp as serverTimestamp26 } from "firebase/firestore";
16580
+ import { Timestamp as Timestamp29, serverTimestamp as serverTimestamp27 } from "firebase/firestore";
16536
16581
  import {
16537
16582
  doc as doc32,
16538
16583
  getDoc as getDoc33,
@@ -16557,7 +16602,7 @@ import {
16557
16602
  where as where22,
16558
16603
  orderBy as orderBy8,
16559
16604
  Timestamp as Timestamp23,
16560
- serverTimestamp as serverTimestamp21
16605
+ serverTimestamp as serverTimestamp22
16561
16606
  } from "firebase/firestore";
16562
16607
 
16563
16608
  // src/services/calendar/utils/docs.utils.ts
@@ -16606,8 +16651,8 @@ async function createClinicCalendarEventUtil(db, clinicId, eventData, generateId
16606
16651
  const newEvent = {
16607
16652
  id: eventId,
16608
16653
  ...eventData,
16609
- createdAt: serverTimestamp21(),
16610
- updatedAt: serverTimestamp21()
16654
+ createdAt: serverTimestamp22(),
16655
+ updatedAt: serverTimestamp22()
16611
16656
  };
16612
16657
  await setDoc17(eventRef, newEvent);
16613
16658
  return {
@@ -16620,7 +16665,7 @@ async function updateClinicCalendarEventUtil(db, clinicId, eventId, updateData)
16620
16665
  const eventRef = getClinicCalendarEventDocRef(db, clinicId, eventId);
16621
16666
  const updates = {
16622
16667
  ...updateData,
16623
- updatedAt: serverTimestamp21()
16668
+ updatedAt: serverTimestamp22()
16624
16669
  };
16625
16670
  await updateDoc22(eventRef, updates);
16626
16671
  const updatedDoc = await getDoc28(eventRef);
@@ -16661,7 +16706,7 @@ import {
16661
16706
  where as where23,
16662
16707
  orderBy as orderBy9,
16663
16708
  Timestamp as Timestamp24,
16664
- serverTimestamp as serverTimestamp22
16709
+ serverTimestamp as serverTimestamp23
16665
16710
  } from "firebase/firestore";
16666
16711
  async function createPatientCalendarEventUtil(db, patientId, eventData, generateId2) {
16667
16712
  const eventId = generateId2();
@@ -16669,8 +16714,8 @@ async function createPatientCalendarEventUtil(db, patientId, eventData, generate
16669
16714
  const newEvent = {
16670
16715
  id: eventId,
16671
16716
  ...eventData,
16672
- createdAt: serverTimestamp22(),
16673
- updatedAt: serverTimestamp22()
16717
+ createdAt: serverTimestamp23(),
16718
+ updatedAt: serverTimestamp23()
16674
16719
  };
16675
16720
  await setDoc18(eventRef, newEvent);
16676
16721
  return {
@@ -16683,7 +16728,7 @@ async function updatePatientCalendarEventUtil(db, patientId, eventId, updateData
16683
16728
  const eventRef = getPatientCalendarEventDocRef(db, patientId, eventId);
16684
16729
  const updates = {
16685
16730
  ...updateData,
16686
- updatedAt: serverTimestamp22()
16731
+ updatedAt: serverTimestamp23()
16687
16732
  };
16688
16733
  await updateDoc23(eventRef, updates);
16689
16734
  const updatedDoc = await getDoc29(eventRef);
@@ -16705,7 +16750,7 @@ import {
16705
16750
  where as where24,
16706
16751
  orderBy as orderBy10,
16707
16752
  Timestamp as Timestamp25,
16708
- serverTimestamp as serverTimestamp23
16753
+ serverTimestamp as serverTimestamp24
16709
16754
  } from "firebase/firestore";
16710
16755
  async function createPractitionerCalendarEventUtil(db, practitionerId, eventData, generateId2) {
16711
16756
  const eventId = generateId2();
@@ -16717,8 +16762,8 @@ async function createPractitionerCalendarEventUtil(db, practitionerId, eventData
16717
16762
  const newEvent = {
16718
16763
  id: eventId,
16719
16764
  ...eventData,
16720
- createdAt: serverTimestamp23(),
16721
- updatedAt: serverTimestamp23()
16765
+ createdAt: serverTimestamp24(),
16766
+ updatedAt: serverTimestamp24()
16722
16767
  };
16723
16768
  await setDoc19(eventRef, newEvent);
16724
16769
  return {
@@ -16735,7 +16780,7 @@ async function updatePractitionerCalendarEventUtil(db, practitionerId, eventId,
16735
16780
  );
16736
16781
  const updates = {
16737
16782
  ...updateData,
16738
- updatedAt: serverTimestamp23()
16783
+ updatedAt: serverTimestamp24()
16739
16784
  };
16740
16785
  await updateDoc24(eventRef, updates);
16741
16786
  const updatedDoc = await getDoc30(eventRef);
@@ -16808,7 +16853,7 @@ import {
16808
16853
  where as where25,
16809
16854
  orderBy as orderBy11,
16810
16855
  Timestamp as Timestamp26,
16811
- serverTimestamp as serverTimestamp24
16856
+ serverTimestamp as serverTimestamp25
16812
16857
  } from "firebase/firestore";
16813
16858
  async function searchCalendarEventsUtil(db, params) {
16814
16859
  const { searchLocation, entityId, ...filters } = params;
@@ -16913,7 +16958,7 @@ import {
16913
16958
  query as query26,
16914
16959
  orderBy as orderBy12,
16915
16960
  Timestamp as Timestamp27,
16916
- serverTimestamp as serverTimestamp25
16961
+ serverTimestamp as serverTimestamp26
16917
16962
  } from "firebase/firestore";
16918
16963
  async function createPractitionerSyncedCalendarUtil(db, practitionerId, calendarData, generateId2) {
16919
16964
  const calendarId = generateId2();
@@ -16925,8 +16970,8 @@ async function createPractitionerSyncedCalendarUtil(db, practitionerId, calendar
16925
16970
  const newCalendar = {
16926
16971
  id: calendarId,
16927
16972
  ...calendarData,
16928
- createdAt: serverTimestamp25(),
16929
- updatedAt: serverTimestamp25()
16973
+ createdAt: serverTimestamp26(),
16974
+ updatedAt: serverTimestamp26()
16930
16975
  };
16931
16976
  await setDoc21(calendarRef, newCalendar);
16932
16977
  return {
@@ -16941,8 +16986,8 @@ async function createPatientSyncedCalendarUtil(db, patientId, calendarData, gene
16941
16986
  const newCalendar = {
16942
16987
  id: calendarId,
16943
16988
  ...calendarData,
16944
- createdAt: serverTimestamp25(),
16945
- updatedAt: serverTimestamp25()
16989
+ createdAt: serverTimestamp26(),
16990
+ updatedAt: serverTimestamp26()
16946
16991
  };
16947
16992
  await setDoc21(calendarRef, newCalendar);
16948
16993
  return {
@@ -16957,8 +17002,8 @@ async function createClinicSyncedCalendarUtil(db, clinicId, calendarData, genera
16957
17002
  const newCalendar = {
16958
17003
  id: calendarId,
16959
17004
  ...calendarData,
16960
- createdAt: serverTimestamp25(),
16961
- updatedAt: serverTimestamp25()
17005
+ createdAt: serverTimestamp26(),
17006
+ updatedAt: serverTimestamp26()
16962
17007
  };
16963
17008
  await setDoc21(calendarRef, newCalendar);
16964
17009
  return {
@@ -17030,7 +17075,7 @@ async function updatePractitionerSyncedCalendarUtil(db, practitionerId, calendar
17030
17075
  );
17031
17076
  const updates = {
17032
17077
  ...updateData,
17033
- updatedAt: serverTimestamp25()
17078
+ updatedAt: serverTimestamp26()
17034
17079
  };
17035
17080
  await updateDoc26(calendarRef, updates);
17036
17081
  const updatedDoc = await getDoc32(calendarRef);
@@ -17043,7 +17088,7 @@ async function updatePatientSyncedCalendarUtil(db, patientId, calendarId, update
17043
17088
  const calendarRef = getPatientSyncedCalendarDocRef(db, patientId, calendarId);
17044
17089
  const updates = {
17045
17090
  ...updateData,
17046
- updatedAt: serverTimestamp25()
17091
+ updatedAt: serverTimestamp26()
17047
17092
  };
17048
17093
  await updateDoc26(calendarRef, updates);
17049
17094
  const updatedDoc = await getDoc32(calendarRef);
@@ -17056,7 +17101,7 @@ async function updateClinicSyncedCalendarUtil(db, clinicId, calendarId, updateDa
17056
17101
  const calendarRef = getClinicSyncedCalendarDocRef(db, clinicId, calendarId);
17057
17102
  const updates = {
17058
17103
  ...updateData,
17059
- updatedAt: serverTimestamp25()
17104
+ updatedAt: serverTimestamp26()
17060
17105
  };
17061
17106
  await updateDoc26(calendarRef, updates);
17062
17107
  const updatedDoc = await getDoc32(calendarRef);
@@ -18278,8 +18323,8 @@ var CalendarServiceV2 = class extends BaseService {
18278
18323
  const newEvent = {
18279
18324
  id: eventId,
18280
18325
  ...eventData,
18281
- createdAt: serverTimestamp26(),
18282
- updatedAt: serverTimestamp26()
18326
+ createdAt: serverTimestamp27(),
18327
+ updatedAt: serverTimestamp27()
18283
18328
  };
18284
18329
  await setDoc22(eventRef, newEvent);
18285
18330
  return {
@@ -18495,7 +18540,7 @@ var CalendarServiceV2 = class extends BaseService {
18495
18540
  end: Timestamp29.fromDate(endTime)
18496
18541
  },
18497
18542
  description: externalEvent.description || "",
18498
- updatedAt: serverTimestamp26()
18543
+ updatedAt: serverTimestamp27()
18499
18544
  });
18500
18545
  console.log(`Updated local event ${eventId} from external event`);
18501
18546
  } catch (error) {
@@ -18522,7 +18567,7 @@ var CalendarServiceV2 = class extends BaseService {
18522
18567
  );
18523
18568
  await updateDoc27(eventRef, {
18524
18569
  status,
18525
- updatedAt: serverTimestamp26()
18570
+ updatedAt: serverTimestamp27()
18526
18571
  });
18527
18572
  console.log(`Updated event ${eventId} status to ${status}`);
18528
18573
  } catch (error) {
@@ -18923,7 +18968,7 @@ var CalendarServiceV2 = class extends BaseService {
18923
18968
  }
18924
18969
  await updateDoc27(eventRef, {
18925
18970
  syncedCalendarEventId: syncIds,
18926
- updatedAt: serverTimestamp26()
18971
+ updatedAt: serverTimestamp27()
18927
18972
  });
18928
18973
  console.log(
18929
18974
  `Updated event ${eventId} with sync ID ${syncEvent.eventId}`
@@ -19146,7 +19191,7 @@ var CalendarServiceV2 = class extends BaseService {
19146
19191
  };
19147
19192
 
19148
19193
  // src/services/calendar/calendar.v3.service.ts
19149
- import { Timestamp as Timestamp30, serverTimestamp as serverTimestamp27 } from "firebase/firestore";
19194
+ import { Timestamp as Timestamp30, serverTimestamp as serverTimestamp28 } from "firebase/firestore";
19150
19195
  import { doc as doc33, getDoc as getDoc34, setDoc as setDoc23, updateDoc as updateDoc28, deleteDoc as deleteDoc15 } from "firebase/firestore";
19151
19196
  var CalendarServiceV3 = class extends BaseService {
19152
19197
  /**
@@ -19181,8 +19226,8 @@ var CalendarServiceV3 = class extends BaseService {
19181
19226
  status: "confirmed" /* CONFIRMED */,
19182
19227
  // Blocking events are always confirmed
19183
19228
  syncStatus: "internal" /* INTERNAL */,
19184
- createdAt: serverTimestamp27(),
19185
- updatedAt: serverTimestamp27()
19229
+ createdAt: serverTimestamp28(),
19230
+ updatedAt: serverTimestamp28()
19186
19231
  };
19187
19232
  if (params.entityType === "practitioner") {
19188
19233
  eventData.practitionerProfileId = params.entityId;
@@ -19212,7 +19257,7 @@ var CalendarServiceV3 = class extends BaseService {
19212
19257
  throw new Error(`Blocking event with ID ${params.eventId} not found`);
19213
19258
  }
19214
19259
  const updateData = {
19215
- updatedAt: serverTimestamp27()
19260
+ updatedAt: serverTimestamp28()
19216
19261
  };
19217
19262
  if (params.eventName !== void 0) {
19218
19263
  updateData.eventName = params.eventName;
@@ -19459,7 +19504,7 @@ import {
19459
19504
  setDoc as setDoc24,
19460
19505
  deleteDoc as deleteDoc16,
19461
19506
  Timestamp as Timestamp31,
19462
- serverTimestamp as serverTimestamp28,
19507
+ serverTimestamp as serverTimestamp29,
19463
19508
  orderBy as orderBy13,
19464
19509
  limit as limit12
19465
19510
  } from "firebase/firestore";
@@ -19621,7 +19666,7 @@ var PractitionerInviteService = class extends BaseService {
19621
19666
  const updateData = {
19622
19667
  status: "accepted" /* ACCEPTED */,
19623
19668
  acceptedAt: Timestamp31.now(),
19624
- updatedAt: serverTimestamp28()
19669
+ updatedAt: serverTimestamp29()
19625
19670
  };
19626
19671
  const docRef = doc34(this.db, PRACTITIONER_INVITES_COLLECTION, inviteId);
19627
19672
  await updateDoc29(docRef, updateData);
@@ -19653,7 +19698,7 @@ var PractitionerInviteService = class extends BaseService {
19653
19698
  status: "rejected" /* REJECTED */,
19654
19699
  rejectionReason: rejectionReason || null,
19655
19700
  rejectedAt: Timestamp31.now(),
19656
- updatedAt: serverTimestamp28()
19701
+ updatedAt: serverTimestamp29()
19657
19702
  };
19658
19703
  const docRef = doc34(this.db, PRACTITIONER_INVITES_COLLECTION, inviteId);
19659
19704
  await updateDoc29(docRef, updateData);
@@ -19685,7 +19730,7 @@ var PractitionerInviteService = class extends BaseService {
19685
19730
  status: "cancelled" /* CANCELLED */,
19686
19731
  cancelReason: cancelReason || null,
19687
19732
  cancelledAt: Timestamp31.now(),
19688
- updatedAt: serverTimestamp28()
19733
+ updatedAt: serverTimestamp29()
19689
19734
  };
19690
19735
  const docRef = doc34(this.db, PRACTITIONER_INVITES_COLLECTION, inviteId);
19691
19736
  await updateDoc29(docRef, updateData);
@@ -20959,7 +21004,7 @@ import {
20959
21004
  updateDoc as updateDoc34,
20960
21005
  setDoc as setDoc27,
20961
21006
  deleteDoc as deleteDoc19,
20962
- serverTimestamp as serverTimestamp31,
21007
+ serverTimestamp as serverTimestamp32,
20963
21008
  writeBatch as writeBatch6,
20964
21009
  orderBy as orderBy18,
20965
21010
  limit as limit16,
@@ -21445,8 +21490,8 @@ var ProcedureService = class extends BaseService {
21445
21490
  const procedureRef = doc39(this.db, PROCEDURES_COLLECTION, procedureId);
21446
21491
  await setDoc27(procedureRef, {
21447
21492
  ...newProcedure,
21448
- createdAt: serverTimestamp31(),
21449
- updatedAt: serverTimestamp31()
21493
+ createdAt: serverTimestamp32(),
21494
+ updatedAt: serverTimestamp32()
21450
21495
  });
21451
21496
  const savedDoc = await getDoc40(procedureRef);
21452
21497
  return savedDoc.data();
@@ -21573,8 +21618,8 @@ var ProcedureService = class extends BaseService {
21573
21618
  const procedureRef = doc39(this.db, PROCEDURES_COLLECTION, newProcedureId);
21574
21619
  await setDoc27(procedureRef, {
21575
21620
  ...newProcedure,
21576
- createdAt: serverTimestamp31(),
21577
- updatedAt: serverTimestamp31()
21621
+ createdAt: serverTimestamp32(),
21622
+ updatedAt: serverTimestamp32()
21578
21623
  });
21579
21624
  const savedDoc = await getDoc40(procedureRef);
21580
21625
  return savedDoc.data();
@@ -21675,8 +21720,8 @@ var ProcedureService = class extends BaseService {
21675
21720
  const procedureRef = doc39(this.db, PROCEDURES_COLLECTION, newProcedureId);
21676
21721
  batch.set(procedureRef, {
21677
21722
  ...newProcedure,
21678
- createdAt: serverTimestamp31(),
21679
- updatedAt: serverTimestamp31()
21723
+ createdAt: serverTimestamp32(),
21724
+ updatedAt: serverTimestamp32()
21680
21725
  });
21681
21726
  }
21682
21727
  await batch.commit();
@@ -21880,8 +21925,8 @@ var ProcedureService = class extends BaseService {
21880
21925
  console.log("\u{1F525}\u{1F525}\u{1F525} NO UNDEFINED FIELDS - Proceeding with batch.set");
21881
21926
  batch.set(procedureRef, {
21882
21927
  ...newProcedure,
21883
- createdAt: serverTimestamp31(),
21884
- updatedAt: serverTimestamp31()
21928
+ createdAt: serverTimestamp32(),
21929
+ updatedAt: serverTimestamp32()
21885
21930
  });
21886
21931
  }
21887
21932
  await batch.commit();
@@ -22115,7 +22160,7 @@ var ProcedureService = class extends BaseService {
22115
22160
  }
22116
22161
  await updateDoc34(procedureRef, {
22117
22162
  ...updatedProcedureData,
22118
- updatedAt: serverTimestamp31()
22163
+ updatedAt: serverTimestamp32()
22119
22164
  });
22120
22165
  const updatedSnapshot = await getDoc40(procedureRef);
22121
22166
  return updatedSnapshot.data();
@@ -22133,7 +22178,7 @@ var ProcedureService = class extends BaseService {
22133
22178
  }
22134
22179
  await updateDoc34(procedureRef, {
22135
22180
  isActive: false,
22136
- updatedAt: serverTimestamp31()
22181
+ updatedAt: serverTimestamp32()
22137
22182
  });
22138
22183
  }
22139
22184
  /**
@@ -22810,8 +22855,8 @@ var ProcedureService = class extends BaseService {
22810
22855
  const procedureRef = doc39(this.db, PROCEDURES_COLLECTION, procedureId);
22811
22856
  await setDoc27(procedureRef, {
22812
22857
  ...newProcedure,
22813
- createdAt: serverTimestamp31(),
22814
- updatedAt: serverTimestamp31()
22858
+ createdAt: serverTimestamp32(),
22859
+ updatedAt: serverTimestamp32()
22815
22860
  });
22816
22861
  const savedDoc = await getDoc40(procedureRef);
22817
22862
  return savedDoc.data();
@@ -22894,7 +22939,7 @@ import {
22894
22939
  where as where34,
22895
22940
  setDoc as setDoc28,
22896
22941
  deleteDoc as deleteDoc20,
22897
- serverTimestamp as serverTimestamp32
22942
+ serverTimestamp as serverTimestamp33
22898
22943
  } from "firebase/firestore";
22899
22944
  import { z as z27 } from "zod";
22900
22945
  var ReviewService = class extends BaseService {
@@ -23048,8 +23093,8 @@ var ReviewService = class extends BaseService {
23048
23093
  reviewSchema.parse(review);
23049
23094
  const firestoreData = {
23050
23095
  ...review,
23051
- createdAt: serverTimestamp32(),
23052
- updatedAt: serverTimestamp32()
23096
+ createdAt: serverTimestamp33(),
23097
+ updatedAt: serverTimestamp33()
23053
23098
  };
23054
23099
  Object.keys(firestoreData).forEach((key) => {
23055
23100
  if (firestoreData[key] === void 0) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@blackcode_sa/metaestetics-api",
3
3
  "private": false,
4
- "version": "1.14.10",
4
+ "version": "1.14.12",
5
5
  "description": "Firebase authentication service with anonymous upgrade support",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.mjs",
@@ -35,6 +35,7 @@ import {
35
35
  Timestamp,
36
36
  runTransaction,
37
37
  Firestore,
38
+ serverTimestamp,
38
39
  } from 'firebase/firestore';
39
40
  import { FirebaseApp } from 'firebase/app';
40
41
  import { User, UserRole, USERS_COLLECTION } from '../../types';
@@ -90,6 +91,17 @@ export class AuthService extends BaseService {
90
91
  constructor(db: Firestore, auth: Auth, app: FirebaseApp, userService: UserService) {
91
92
  super(db, auth, app);
92
93
  this.userService = userService || new UserService(db, auth, app);
94
+
95
+ // DEBUG: Tag the auth instances to track them
96
+ // @ts-ignore
97
+ if (!this.auth.__authServiceId) {
98
+ // @ts-ignore
99
+ this.auth.__authServiceId = 'auth-service-' + Date.now();
100
+ }
101
+ // @ts-ignore
102
+ console.log('[AUTH] AuthService constructor - auth ID:', this.auth.__authServiceId);
103
+ // @ts-ignore
104
+ console.log('[AUTH] AuthService constructor - userService.auth ID:', (this.userService as any).auth?.__authServiceId || 'NOT SET');
93
105
  }
94
106
 
95
107
  /**
@@ -898,13 +910,47 @@ export class AuthService extends BaseService {
898
910
  console.log('[AUTH] User document does not exist, creating it...');
899
911
  }
900
912
 
901
- // Step 2: Create User document if it doesn't exist (NOT in transaction - matches token flow)
913
+ // Step 2: Create User document directly (bypassing UserService to test auth instance issue)
902
914
  if (!user) {
903
- console.log('[AUTH] Creating user document for:', firebaseUser.uid);
904
- user = await this.userService.createUser(firebaseUser, [UserRole.PRACTITIONER], {
905
- skipProfileCreation: true,
915
+ console.log('[AUTH] Creating user document DIRECTLY for:', firebaseUser.uid);
916
+ console.log('[AUTH] Using THIS.auth.currentUser:', this.auth.currentUser?.uid || 'NULL');
917
+ console.log('[AUTH] Using THIS.db:', this.db ? 'EXISTS' : 'NULL');
918
+
919
+ const userData = {
920
+ uid: firebaseUser.uid,
921
+ email: firebaseUser.email,
922
+ roles: [UserRole.PRACTITIONER],
923
+ isAnonymous: firebaseUser.isAnonymous || false,
924
+ createdAt: serverTimestamp(),
925
+ updatedAt: serverTimestamp(),
926
+ lastLoginAt: serverTimestamp(),
927
+ };
928
+
929
+ console.log('[AUTH] Attempting setDoc directly with userData:', {
930
+ uid: userData.uid,
931
+ email: userData.email,
932
+ roles: userData.roles,
906
933
  });
907
- console.log('[AUTH] User document created successfully:', user.uid);
934
+
935
+ try {
936
+ await setDoc(doc(this.db, USERS_COLLECTION, firebaseUser.uid), userData);
937
+ console.log('[AUTH] ✅ setDoc SUCCEEDED directly!');
938
+
939
+ // Fetch the created user
940
+ const userDoc = await getDoc(doc(this.db, USERS_COLLECTION, firebaseUser.uid));
941
+ if (!userDoc.exists()) {
942
+ throw new Error('User document was not created');
943
+ }
944
+ user = userDoc.data() as User;
945
+ console.log('[AUTH] User document created successfully:', user.uid);
946
+ } catch (error: any) {
947
+ console.error('[AUTH] ❌ setDoc FAILED directly:', {
948
+ errorCode: error?.code,
949
+ errorMessage: error?.message,
950
+ uid: firebaseUser.uid,
951
+ });
952
+ throw error;
953
+ }
908
954
  }
909
955
 
910
956
  // Step 3: Claim the draft profiles
@@ -45,6 +45,17 @@ export class UserService extends BaseService {
45
45
  ) {
46
46
  super(db, auth, app);
47
47
 
48
+ // DEBUG: Tag the auth instance
49
+ // @ts-ignore
50
+ if (!this.auth.__userServiceId) {
51
+ // @ts-ignore
52
+ this.auth.__userServiceId = 'user-service-' + Date.now();
53
+ }
54
+ // @ts-ignore
55
+ console.log('[USER_SERVICE] Constructor - auth ID:', this.auth.__userServiceId);
56
+ // @ts-ignore
57
+ console.log('[USER_SERVICE] Constructor - auth.__authServiceId:', this.auth.__authServiceId || 'NOT SET');
58
+
48
59
  // Kreiramo servise samo ako nisu prosleđeni
49
60
  if (!patientService) {
50
61
  patientService = new PatientService(db, auth, app);
@@ -92,6 +103,7 @@ export class UserService extends BaseService {
92
103
  // DEBUG LOGGING - Check auth state before creating user document
93
104
  console.log('[USER_SERVICE] ====== CREATE USER DEBUG ======');
94
105
  // @ts-ignore - Debug: Check auth instance ID
106
+ console.log(this.auth)
95
107
  console.log('[USER_SERVICE] Auth instance ID:', (this.auth as any)?.__debugId || 'no-id');
96
108
  console.log('[USER_SERVICE] Current auth state:', {
97
109
  currentUser: this.auth?.currentUser?.uid || 'NULL',