@blackcode_sa/metaestetics-api 1.7.7 → 1.7.8
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 +55 -3
- package/dist/index.mjs +55 -3
- package/package.json +1 -1
- package/src/services/practitioner/practitioner.service.ts +62 -3
package/dist/index.js
CHANGED
|
@@ -4471,15 +4471,42 @@ var PractitionerService = class extends BaseService {
|
|
|
4471
4471
|
this.db,
|
|
4472
4472
|
`${PRACTITIONERS_COLLECTION}/${practitionerId}/${REGISTER_TOKENS_COLLECTION}`
|
|
4473
4473
|
);
|
|
4474
|
+
console.log(
|
|
4475
|
+
`[PRACTITIONER] Validating token for practitioner ${practitionerId}`,
|
|
4476
|
+
{
|
|
4477
|
+
tokenString,
|
|
4478
|
+
timestamp: import_firestore16.Timestamp.now().toDate()
|
|
4479
|
+
}
|
|
4480
|
+
);
|
|
4474
4481
|
const q = (0, import_firestore16.query)(
|
|
4475
4482
|
tokensRef,
|
|
4476
4483
|
(0, import_firestore16.where)("token", "==", tokenString),
|
|
4477
4484
|
(0, import_firestore16.where)("status", "==", "active" /* ACTIVE */),
|
|
4478
4485
|
(0, import_firestore16.where)("expiresAt", ">", import_firestore16.Timestamp.now())
|
|
4479
4486
|
);
|
|
4480
|
-
|
|
4481
|
-
|
|
4482
|
-
|
|
4487
|
+
try {
|
|
4488
|
+
const tokenSnapshot = await (0, import_firestore16.getDocs)(q);
|
|
4489
|
+
console.log(
|
|
4490
|
+
`[PRACTITIONER] Token query results for practitioner ${practitionerId}`,
|
|
4491
|
+
{
|
|
4492
|
+
found: !tokenSnapshot.empty,
|
|
4493
|
+
count: tokenSnapshot.size
|
|
4494
|
+
}
|
|
4495
|
+
);
|
|
4496
|
+
if (!tokenSnapshot.empty) {
|
|
4497
|
+
const tokenData = tokenSnapshot.docs[0].data();
|
|
4498
|
+
console.log(`[PRACTITIONER] Valid token found`, {
|
|
4499
|
+
tokenId: tokenData.id,
|
|
4500
|
+
expiresAt: tokenData.expiresAt.toDate()
|
|
4501
|
+
});
|
|
4502
|
+
return tokenData;
|
|
4503
|
+
}
|
|
4504
|
+
} catch (error) {
|
|
4505
|
+
console.error(
|
|
4506
|
+
`[PRACTITIONER] Error validating token for practitioner ${practitionerId}:`,
|
|
4507
|
+
error
|
|
4508
|
+
);
|
|
4509
|
+
throw error;
|
|
4483
4510
|
}
|
|
4484
4511
|
}
|
|
4485
4512
|
return null;
|
|
@@ -4693,15 +4720,36 @@ var PractitionerService = class extends BaseService {
|
|
|
4693
4720
|
* @returns The claimed practitioner profile or null if token is invalid
|
|
4694
4721
|
*/
|
|
4695
4722
|
async validateTokenAndClaimProfile(tokenString, userId) {
|
|
4723
|
+
console.log("[PRACTITIONER] Validating token for claiming profile", {
|
|
4724
|
+
tokenString,
|
|
4725
|
+
userId
|
|
4726
|
+
});
|
|
4696
4727
|
const token = await this.validateToken(tokenString);
|
|
4697
4728
|
if (!token) {
|
|
4729
|
+
console.log(
|
|
4730
|
+
"[PRACTITIONER] Token validation failed - token not found or not valid",
|
|
4731
|
+
{
|
|
4732
|
+
tokenString
|
|
4733
|
+
}
|
|
4734
|
+
);
|
|
4698
4735
|
return null;
|
|
4699
4736
|
}
|
|
4737
|
+
console.log("[PRACTITIONER] Token successfully validated", {
|
|
4738
|
+
tokenId: token.id,
|
|
4739
|
+
practitionerId: token.practitionerId
|
|
4740
|
+
});
|
|
4700
4741
|
const practitioner = await this.getPractitioner(token.practitionerId);
|
|
4701
4742
|
if (!practitioner) {
|
|
4743
|
+
console.log("[PRACTITIONER] Practitioner not found", {
|
|
4744
|
+
practitionerId: token.practitionerId
|
|
4745
|
+
});
|
|
4702
4746
|
return null;
|
|
4703
4747
|
}
|
|
4704
4748
|
if (practitioner.status !== "draft" /* DRAFT */) {
|
|
4749
|
+
console.log("[PRACTITIONER] Practitioner status is not DRAFT", {
|
|
4750
|
+
practitionerId: practitioner.id,
|
|
4751
|
+
status: practitioner.status
|
|
4752
|
+
});
|
|
4705
4753
|
throw new Error("This practitioner profile has already been claimed");
|
|
4706
4754
|
}
|
|
4707
4755
|
const existingPractitioner = await this.getPractitionerByUserRef(userId);
|
|
@@ -4713,6 +4761,10 @@ var PractitionerService = class extends BaseService {
|
|
|
4713
4761
|
status: "active" /* ACTIVE */
|
|
4714
4762
|
});
|
|
4715
4763
|
await this.markTokenAsUsed(token.id, token.practitionerId, userId);
|
|
4764
|
+
console.log("[PRACTITIONER] Profile claimed successfully", {
|
|
4765
|
+
practitionerId: updatedPractitioner.id,
|
|
4766
|
+
userId
|
|
4767
|
+
});
|
|
4716
4768
|
return updatedPractitioner;
|
|
4717
4769
|
}
|
|
4718
4770
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -4364,15 +4364,42 @@ var PractitionerService = class extends BaseService {
|
|
|
4364
4364
|
this.db,
|
|
4365
4365
|
`${PRACTITIONERS_COLLECTION}/${practitionerId}/${REGISTER_TOKENS_COLLECTION}`
|
|
4366
4366
|
);
|
|
4367
|
+
console.log(
|
|
4368
|
+
`[PRACTITIONER] Validating token for practitioner ${practitionerId}`,
|
|
4369
|
+
{
|
|
4370
|
+
tokenString,
|
|
4371
|
+
timestamp: Timestamp9.now().toDate()
|
|
4372
|
+
}
|
|
4373
|
+
);
|
|
4367
4374
|
const q = query6(
|
|
4368
4375
|
tokensRef,
|
|
4369
4376
|
where6("token", "==", tokenString),
|
|
4370
4377
|
where6("status", "==", "active" /* ACTIVE */),
|
|
4371
4378
|
where6("expiresAt", ">", Timestamp9.now())
|
|
4372
4379
|
);
|
|
4373
|
-
|
|
4374
|
-
|
|
4375
|
-
|
|
4380
|
+
try {
|
|
4381
|
+
const tokenSnapshot = await getDocs6(q);
|
|
4382
|
+
console.log(
|
|
4383
|
+
`[PRACTITIONER] Token query results for practitioner ${practitionerId}`,
|
|
4384
|
+
{
|
|
4385
|
+
found: !tokenSnapshot.empty,
|
|
4386
|
+
count: tokenSnapshot.size
|
|
4387
|
+
}
|
|
4388
|
+
);
|
|
4389
|
+
if (!tokenSnapshot.empty) {
|
|
4390
|
+
const tokenData = tokenSnapshot.docs[0].data();
|
|
4391
|
+
console.log(`[PRACTITIONER] Valid token found`, {
|
|
4392
|
+
tokenId: tokenData.id,
|
|
4393
|
+
expiresAt: tokenData.expiresAt.toDate()
|
|
4394
|
+
});
|
|
4395
|
+
return tokenData;
|
|
4396
|
+
}
|
|
4397
|
+
} catch (error) {
|
|
4398
|
+
console.error(
|
|
4399
|
+
`[PRACTITIONER] Error validating token for practitioner ${practitionerId}:`,
|
|
4400
|
+
error
|
|
4401
|
+
);
|
|
4402
|
+
throw error;
|
|
4376
4403
|
}
|
|
4377
4404
|
}
|
|
4378
4405
|
return null;
|
|
@@ -4586,15 +4613,36 @@ var PractitionerService = class extends BaseService {
|
|
|
4586
4613
|
* @returns The claimed practitioner profile or null if token is invalid
|
|
4587
4614
|
*/
|
|
4588
4615
|
async validateTokenAndClaimProfile(tokenString, userId) {
|
|
4616
|
+
console.log("[PRACTITIONER] Validating token for claiming profile", {
|
|
4617
|
+
tokenString,
|
|
4618
|
+
userId
|
|
4619
|
+
});
|
|
4589
4620
|
const token = await this.validateToken(tokenString);
|
|
4590
4621
|
if (!token) {
|
|
4622
|
+
console.log(
|
|
4623
|
+
"[PRACTITIONER] Token validation failed - token not found or not valid",
|
|
4624
|
+
{
|
|
4625
|
+
tokenString
|
|
4626
|
+
}
|
|
4627
|
+
);
|
|
4591
4628
|
return null;
|
|
4592
4629
|
}
|
|
4630
|
+
console.log("[PRACTITIONER] Token successfully validated", {
|
|
4631
|
+
tokenId: token.id,
|
|
4632
|
+
practitionerId: token.practitionerId
|
|
4633
|
+
});
|
|
4593
4634
|
const practitioner = await this.getPractitioner(token.practitionerId);
|
|
4594
4635
|
if (!practitioner) {
|
|
4636
|
+
console.log("[PRACTITIONER] Practitioner not found", {
|
|
4637
|
+
practitionerId: token.practitionerId
|
|
4638
|
+
});
|
|
4595
4639
|
return null;
|
|
4596
4640
|
}
|
|
4597
4641
|
if (practitioner.status !== "draft" /* DRAFT */) {
|
|
4642
|
+
console.log("[PRACTITIONER] Practitioner status is not DRAFT", {
|
|
4643
|
+
practitionerId: practitioner.id,
|
|
4644
|
+
status: practitioner.status
|
|
4645
|
+
});
|
|
4598
4646
|
throw new Error("This practitioner profile has already been claimed");
|
|
4599
4647
|
}
|
|
4600
4648
|
const existingPractitioner = await this.getPractitionerByUserRef(userId);
|
|
@@ -4606,6 +4654,10 @@ var PractitionerService = class extends BaseService {
|
|
|
4606
4654
|
status: "active" /* ACTIVE */
|
|
4607
4655
|
});
|
|
4608
4656
|
await this.markTokenAsUsed(token.id, token.practitionerId, userId);
|
|
4657
|
+
console.log("[PRACTITIONER] Profile claimed successfully", {
|
|
4658
|
+
practitionerId: updatedPractitioner.id,
|
|
4659
|
+
userId
|
|
4660
|
+
});
|
|
4609
4661
|
return updatedPractitioner;
|
|
4610
4662
|
}
|
|
4611
4663
|
/**
|
package/package.json
CHANGED
|
@@ -446,6 +446,14 @@ export class PractitionerService extends BaseService {
|
|
|
446
446
|
`${PRACTITIONERS_COLLECTION}/${practitionerId}/${REGISTER_TOKENS_COLLECTION}`
|
|
447
447
|
);
|
|
448
448
|
|
|
449
|
+
console.log(
|
|
450
|
+
`[PRACTITIONER] Validating token for practitioner ${practitionerId}`,
|
|
451
|
+
{
|
|
452
|
+
tokenString,
|
|
453
|
+
timestamp: Timestamp.now().toDate(),
|
|
454
|
+
}
|
|
455
|
+
);
|
|
456
|
+
|
|
449
457
|
const q = query(
|
|
450
458
|
tokensRef,
|
|
451
459
|
where("token", "==", tokenString),
|
|
@@ -453,9 +461,31 @@ export class PractitionerService extends BaseService {
|
|
|
453
461
|
where("expiresAt", ">", Timestamp.now())
|
|
454
462
|
);
|
|
455
463
|
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
464
|
+
try {
|
|
465
|
+
const tokenSnapshot = await getDocs(q);
|
|
466
|
+
console.log(
|
|
467
|
+
`[PRACTITIONER] Token query results for practitioner ${practitionerId}`,
|
|
468
|
+
{
|
|
469
|
+
found: !tokenSnapshot.empty,
|
|
470
|
+
count: tokenSnapshot.size,
|
|
471
|
+
}
|
|
472
|
+
);
|
|
473
|
+
|
|
474
|
+
if (!tokenSnapshot.empty) {
|
|
475
|
+
const tokenData = tokenSnapshot.docs[0].data() as PractitionerToken;
|
|
476
|
+
console.log(`[PRACTITIONER] Valid token found`, {
|
|
477
|
+
tokenId: tokenData.id,
|
|
478
|
+
expiresAt: tokenData.expiresAt.toDate(),
|
|
479
|
+
});
|
|
480
|
+
return tokenData;
|
|
481
|
+
}
|
|
482
|
+
} catch (error) {
|
|
483
|
+
console.error(
|
|
484
|
+
`[PRACTITIONER] Error validating token for practitioner ${practitionerId}:`,
|
|
485
|
+
error
|
|
486
|
+
);
|
|
487
|
+
// Re-throw the error to be handled by the caller
|
|
488
|
+
throw error;
|
|
459
489
|
}
|
|
460
490
|
}
|
|
461
491
|
|
|
@@ -730,19 +760,43 @@ export class PractitionerService extends BaseService {
|
|
|
730
760
|
userId: string
|
|
731
761
|
): Promise<Practitioner | null> {
|
|
732
762
|
// Find the token
|
|
763
|
+
console.log("[PRACTITIONER] Validating token for claiming profile", {
|
|
764
|
+
tokenString,
|
|
765
|
+
userId,
|
|
766
|
+
});
|
|
767
|
+
|
|
733
768
|
const token = await this.validateToken(tokenString);
|
|
769
|
+
|
|
734
770
|
if (!token) {
|
|
771
|
+
console.log(
|
|
772
|
+
"[PRACTITIONER] Token validation failed - token not found or not valid",
|
|
773
|
+
{
|
|
774
|
+
tokenString,
|
|
775
|
+
}
|
|
776
|
+
);
|
|
735
777
|
return null; // Token not found or not valid
|
|
736
778
|
}
|
|
737
779
|
|
|
780
|
+
console.log("[PRACTITIONER] Token successfully validated", {
|
|
781
|
+
tokenId: token.id,
|
|
782
|
+
practitionerId: token.practitionerId,
|
|
783
|
+
});
|
|
784
|
+
|
|
738
785
|
// Get the practitioner profile
|
|
739
786
|
const practitioner = await this.getPractitioner(token.practitionerId);
|
|
740
787
|
if (!practitioner) {
|
|
788
|
+
console.log("[PRACTITIONER] Practitioner not found", {
|
|
789
|
+
practitionerId: token.practitionerId,
|
|
790
|
+
});
|
|
741
791
|
return null; // Practitioner not found
|
|
742
792
|
}
|
|
743
793
|
|
|
744
794
|
// Ensure practitioner is in DRAFT status
|
|
745
795
|
if (practitioner.status !== PractitionerStatus.DRAFT) {
|
|
796
|
+
console.log("[PRACTITIONER] Practitioner status is not DRAFT", {
|
|
797
|
+
practitionerId: practitioner.id,
|
|
798
|
+
status: practitioner.status,
|
|
799
|
+
});
|
|
746
800
|
throw new Error("This practitioner profile has already been claimed");
|
|
747
801
|
}
|
|
748
802
|
|
|
@@ -761,6 +815,11 @@ export class PractitionerService extends BaseService {
|
|
|
761
815
|
// Mark the token as used
|
|
762
816
|
await this.markTokenAsUsed(token.id, token.practitionerId, userId);
|
|
763
817
|
|
|
818
|
+
console.log("[PRACTITIONER] Profile claimed successfully", {
|
|
819
|
+
practitionerId: updatedPractitioner.id,
|
|
820
|
+
userId,
|
|
821
|
+
});
|
|
822
|
+
|
|
764
823
|
return updatedPractitioner;
|
|
765
824
|
}
|
|
766
825
|
|