@blackcode_sa/metaestetics-api 1.7.42 → 1.7.44

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
@@ -882,12 +882,21 @@ var passwordSchema = import_zod4.z.string().min(8, "Password must be at least 8
882
882
  );
883
883
  var userRoleSchema = import_zod4.z.nativeEnum(UserRole);
884
884
  var userRolesSchema = import_zod4.z.array(userRoleSchema).min(1, "User must have at least one role").max(3, "User cannot have more than 3 roles");
885
- var timestampSchema = import_zod4.z.custom((data) => {
886
- if (data && typeof data === "object" && "isEqual" in data) {
887
- return true;
888
- }
889
- return data && typeof data === "object" && "toDate" in data && "seconds" in data && "nanoseconds" in data;
890
- }, "Must be a Timestamp object or serverTimestamp");
885
+ var timestampSchema = import_zod4.z.custom(
886
+ (data) => {
887
+ if (data && typeof data === "object" && "isEqual" in data) {
888
+ return true;
889
+ }
890
+ if (data && typeof data === "object" && "toDate" in data && "seconds" in data && "nanoseconds" in data) {
891
+ return true;
892
+ }
893
+ if (data instanceof Date) {
894
+ return true;
895
+ }
896
+ return false;
897
+ },
898
+ "Must be a Timestamp object, Date object, or serverTimestamp"
899
+ );
891
900
  var clinicAdminOptionsSchema = import_zod4.z.object({
892
901
  isGroupOwner: import_zod4.z.boolean(),
893
902
  groupToken: import_zod4.z.string().optional(),
@@ -914,9 +923,9 @@ var userSchema = import_zod4.z.object({
914
923
  email: import_zod4.z.string().email().nullable(),
915
924
  roles: import_zod4.z.array(userRoleSchema),
916
925
  isAnonymous: import_zod4.z.boolean(),
917
- createdAt: timestampSchema,
918
- updatedAt: timestampSchema,
919
- lastLoginAt: timestampSchema,
926
+ createdAt: import_zod4.z.any(),
927
+ updatedAt: import_zod4.z.any(),
928
+ lastLoginAt: import_zod4.z.any(),
920
929
  patientProfile: import_zod4.z.string().optional(),
921
930
  practitionerProfile: import_zod4.z.string().optional(),
922
931
  adminProfile: import_zod4.z.string().optional()
@@ -1700,11 +1709,16 @@ var timestampSchema2 = import_zod5.z.union([
1700
1709
  seconds: import_zod5.z.number(),
1701
1710
  nanoseconds: import_zod5.z.number()
1702
1711
  }),
1703
- import_zod5.z.instanceof(import_firestore4.Timestamp)
1712
+ import_zod5.z.instanceof(import_firestore4.Timestamp),
1713
+ import_zod5.z.instanceof(Date)
1714
+ // Add support for Date objects that Firestore returns on client
1704
1715
  ]).transform((data) => {
1705
1716
  if (data instanceof import_firestore4.Timestamp) {
1706
1717
  return data;
1707
1718
  }
1719
+ if (data instanceof Date) {
1720
+ return import_firestore4.Timestamp.fromDate(data);
1721
+ }
1708
1722
  return new import_firestore4.Timestamp(data.seconds, data.nanoseconds);
1709
1723
  });
1710
1724
 
@@ -5941,7 +5955,7 @@ var UserService = class extends BaseService {
5941
5955
  const q = (0, import_firestore19.query)((0, import_firestore19.collection)(this.db, USERS_COLLECTION), ...constraints);
5942
5956
  const querySnapshot = await (0, import_firestore19.getDocs)(q);
5943
5957
  const users = querySnapshot.docs.map((doc36) => doc36.data());
5944
- return Promise.all(users.map((userData) => userSchema.parse(userData)));
5958
+ return users.map((userData) => userSchema.parse(userData));
5945
5959
  }
5946
5960
  /**
5947
5961
  * Ažurira timestamp poslednjeg logovanja
package/dist/index.mjs CHANGED
@@ -657,12 +657,21 @@ var passwordSchema = z4.string().min(8, "Password must be at least 8 characters"
657
657
  );
658
658
  var userRoleSchema = z4.nativeEnum(UserRole);
659
659
  var userRolesSchema = z4.array(userRoleSchema).min(1, "User must have at least one role").max(3, "User cannot have more than 3 roles");
660
- var timestampSchema = z4.custom((data) => {
661
- if (data && typeof data === "object" && "isEqual" in data) {
662
- return true;
663
- }
664
- return data && typeof data === "object" && "toDate" in data && "seconds" in data && "nanoseconds" in data;
665
- }, "Must be a Timestamp object or serverTimestamp");
660
+ var timestampSchema = z4.custom(
661
+ (data) => {
662
+ if (data && typeof data === "object" && "isEqual" in data) {
663
+ return true;
664
+ }
665
+ if (data && typeof data === "object" && "toDate" in data && "seconds" in data && "nanoseconds" in data) {
666
+ return true;
667
+ }
668
+ if (data instanceof Date) {
669
+ return true;
670
+ }
671
+ return false;
672
+ },
673
+ "Must be a Timestamp object, Date object, or serverTimestamp"
674
+ );
666
675
  var clinicAdminOptionsSchema = z4.object({
667
676
  isGroupOwner: z4.boolean(),
668
677
  groupToken: z4.string().optional(),
@@ -689,9 +698,9 @@ var userSchema = z4.object({
689
698
  email: z4.string().email().nullable(),
690
699
  roles: z4.array(userRoleSchema),
691
700
  isAnonymous: z4.boolean(),
692
- createdAt: timestampSchema,
693
- updatedAt: timestampSchema,
694
- lastLoginAt: timestampSchema,
701
+ createdAt: z4.any(),
702
+ updatedAt: z4.any(),
703
+ lastLoginAt: z4.any(),
695
704
  patientProfile: z4.string().optional(),
696
705
  practitionerProfile: z4.string().optional(),
697
706
  adminProfile: z4.string().optional()
@@ -1527,11 +1536,16 @@ var timestampSchema2 = z5.union([
1527
1536
  seconds: z5.number(),
1528
1537
  nanoseconds: z5.number()
1529
1538
  }),
1530
- z5.instanceof(Timestamp2)
1539
+ z5.instanceof(Timestamp2),
1540
+ z5.instanceof(Date)
1541
+ // Add support for Date objects that Firestore returns on client
1531
1542
  ]).transform((data) => {
1532
1543
  if (data instanceof Timestamp2) {
1533
1544
  return data;
1534
1545
  }
1546
+ if (data instanceof Date) {
1547
+ return Timestamp2.fromDate(data);
1548
+ }
1535
1549
  return new Timestamp2(data.seconds, data.nanoseconds);
1536
1550
  });
1537
1551
 
@@ -5846,7 +5860,7 @@ var UserService = class extends BaseService {
5846
5860
  const q = query8(collection8(this.db, USERS_COLLECTION), ...constraints);
5847
5861
  const querySnapshot = await getDocs8(q);
5848
5862
  const users = querySnapshot.docs.map((doc36) => doc36.data());
5849
- return Promise.all(users.map((userData) => userSchema.parse(userData)));
5863
+ return users.map((userData) => userSchema.parse(userData));
5850
5864
  }
5851
5865
  /**
5852
5866
  * Ažurira timestamp poslednjeg logovanja
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@blackcode_sa/metaestetics-api",
3
3
  "private": false,
4
- "version": "1.7.42",
4
+ "version": "1.7.44",
5
5
  "description": "Firebase authentication service with anonymous upgrade support",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.mjs",
@@ -264,7 +264,7 @@ export class UserService extends BaseService {
264
264
  }
265
265
 
266
266
  const userData = userDoc.data();
267
- return userSchema.parse(userData);
267
+ return userSchema.parse(userData) as User;
268
268
  }
269
269
 
270
270
  /**
@@ -278,7 +278,7 @@ export class UserService extends BaseService {
278
278
  if (querySnapshot.empty) return null;
279
279
 
280
280
  const userData = querySnapshot.docs[0].data();
281
- return userSchema.parse(userData);
281
+ return userSchema.parse(userData) as User;
282
282
  }
283
283
 
284
284
  async getUsersByRole(role: UserRole): Promise<User[]> {
@@ -289,7 +289,7 @@ export class UserService extends BaseService {
289
289
  const querySnapshot = await getDocs(q);
290
290
 
291
291
  const users = querySnapshot.docs.map((doc) => doc.data());
292
- return Promise.all(users.map((userData) => userSchema.parse(userData)));
292
+ return users.map((userData) => userSchema.parse(userData) as User);
293
293
  }
294
294
 
295
295
  /**
@@ -14,9 +14,9 @@ export interface User {
14
14
  email: string | null;
15
15
  roles: UserRole[];
16
16
  isAnonymous: boolean;
17
- createdAt: Timestamp | FieldValue;
18
- updatedAt: Timestamp | FieldValue;
19
- lastLoginAt: Timestamp | FieldValue;
17
+ createdAt: any;
18
+ updatedAt: any;
19
+ lastLoginAt: any;
20
20
  patientProfile?: string;
21
21
  practitionerProfile?: string;
22
22
  adminProfile?: string;
@@ -1,7 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { Timestamp } from "firebase/firestore";
3
3
 
4
- // Create a custom schema for Timestamp that properly handles both raw objects and Timestamp instances
4
+ // Create a custom schema for Timestamp that properly handles Timestamp instances, raw objects, and Date objects
5
5
  export const timestampSchema = z
6
6
  .union([
7
7
  z.object({
@@ -9,11 +9,16 @@ export const timestampSchema = z
9
9
  nanoseconds: z.number(),
10
10
  }),
11
11
  z.instanceof(Timestamp),
12
+ z.instanceof(Date), // Add support for Date objects that Firestore returns on client
12
13
  ])
13
14
  .transform((data) => {
14
15
  if (data instanceof Timestamp) {
15
16
  return data;
16
17
  }
18
+ if (data instanceof Date) {
19
+ // Convert Date back to Timestamp for consistency
20
+ return Timestamp.fromDate(data);
21
+ }
17
22
  return new Timestamp(data.seconds, data.nanoseconds);
18
23
  });
19
24
 
@@ -24,21 +24,33 @@ export const userRolesSchema = z
24
24
  .min(1, "User must have at least one role")
25
25
  .max(3, "User cannot have more than 3 roles");
26
26
 
27
- export const timestampSchema = z.custom<Timestamp | FieldValue>((data) => {
28
- // If it's a serverTimestamp (FieldValue), it's valid
29
- if (data && typeof data === "object" && "isEqual" in data) {
30
- return true;
31
- }
27
+ export const timestampSchema = z.custom<Timestamp | FieldValue | Date>(
28
+ (data) => {
29
+ // If it's a serverTimestamp (FieldValue), it's valid
30
+ if (data && typeof data === "object" && "isEqual" in data) {
31
+ return true;
32
+ }
32
33
 
33
- // If it's a Timestamp object, validate its structure
34
- return (
35
- data &&
36
- typeof data === "object" &&
37
- "toDate" in data &&
38
- "seconds" in data &&
39
- "nanoseconds" in data
40
- );
41
- }, "Must be a Timestamp object or serverTimestamp");
34
+ // If it's a Timestamp object, validate its structure
35
+ if (
36
+ data &&
37
+ typeof data === "object" &&
38
+ "toDate" in data &&
39
+ "seconds" in data &&
40
+ "nanoseconds" in data
41
+ ) {
42
+ return true;
43
+ }
44
+
45
+ // If it's a JavaScript Date object (what Firestore returns on client), it's valid
46
+ if (data instanceof Date) {
47
+ return true;
48
+ }
49
+
50
+ return false;
51
+ },
52
+ "Must be a Timestamp object, Date object, or serverTimestamp"
53
+ );
42
54
 
43
55
  /**
44
56
  * Validaciona šema za clinic admin opcije pri kreiranju
@@ -78,9 +90,9 @@ export const userSchema = z.object({
78
90
  email: z.string().email().nullable(),
79
91
  roles: z.array(userRoleSchema),
80
92
  isAnonymous: z.boolean(),
81
- createdAt: timestampSchema,
82
- updatedAt: timestampSchema,
83
- lastLoginAt: timestampSchema,
93
+ createdAt: z.any(),
94
+ updatedAt: z.any(),
95
+ lastLoginAt: z.any(),
84
96
  patientProfile: z.string().optional(),
85
97
  practitionerProfile: z.string().optional(),
86
98
  adminProfile: z.string().optional(),