@jobsearch-works/firestore-models 1.0.29 → 1.0.30

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.d.mts CHANGED
@@ -61,35 +61,35 @@ declare namespace Application {
61
61
  const updateStatus: (application: Application.Model, newStatus: Application.Model["status"]) => Application.Model;
62
62
  }
63
63
 
64
- interface FirestoreTimestamp {
65
- seconds: number;
66
- nanoseconds: number;
67
- _firestore_timestamp?: boolean;
68
- }
69
- /**
70
- * AuthUser interface - replaces the old class-based model
71
- */
72
- interface AuthUser extends BaseModel {
73
- email: string;
74
- displayName?: string;
75
- photoURL?: string;
76
- lastSignIn?: Date | string;
77
- emailVerified?: boolean;
78
- }
79
- declare const AuthUserCollectionPath = "users";
80
- declare const getAuthUserDocumentPath: (userId: string) => string;
81
- declare const AuthUserUtils: {
82
- getTimestampFields: () => string[];
83
- isFirestoreTimestamp: (value: any) => value is FirestoreTimestamp;
84
- fromFirebaseUser: (user: any) => AuthUser;
85
- formatDates: (user: AuthUser) => {
64
+ declare namespace AuthUser {
65
+ export interface Model extends BaseModel {
66
+ email: string;
67
+ displayName?: string;
68
+ photoURL?: string;
69
+ lastSignIn?: string;
70
+ emailVerified?: boolean;
71
+ }
72
+ interface FirestoreTimestamp {
73
+ seconds: number;
74
+ nanoseconds: number;
75
+ _firestore_timestamp?: boolean;
76
+ }
77
+ export const collection: () => string;
78
+ export const document: (userId: string) => string;
79
+ export const getTimestampFields: () => (keyof Model)[];
80
+ export const isFirestoreTimestamp: (value: any) => value is FirestoreTimestamp;
81
+ export const fromFirebaseUser: (user: any) => Model;
82
+ export const format: (user: Model) => string;
83
+ export const formatDates: (user: Model) => {
86
84
  lastSignIn: string;
87
85
  createdAt: string;
88
86
  updatedAt?: string;
89
87
  };
90
- toFirestore: (user: AuthUser) => Record<string, any>;
91
- fromFirestore: (data: Record<string, any>) => AuthUser;
92
- };
88
+ export const toFirestore: (user: Model) => Record<string, any>;
89
+ export const fromFirestore: (data: Record<string, any>) => Model;
90
+ export const createNew: (email: string, displayName?: string, photoURL?: string) => Model;
91
+ export {};
92
+ }
93
93
 
94
94
  declare namespace Client {
95
95
  interface Model extends BaseModel {
@@ -301,4 +301,4 @@ declare namespace Agent {
301
301
  const createNew: (name: string, email: string) => Agent.Model;
302
302
  }
303
303
 
304
- export { Agent, Application, ApplicationQuestion, AuthUser, AuthUserCollectionPath, AuthUserUtils, Client, ClientData, ClientLogin, ClientQuestion, Vacancy, VacancySuggestion, getAuthUserDocumentPath };
304
+ export { Agent, Application, ApplicationQuestion, AuthUser, Client, ClientData, ClientLogin, ClientQuestion, Vacancy, VacancySuggestion };
package/dist/index.d.ts CHANGED
@@ -61,35 +61,35 @@ declare namespace Application {
61
61
  const updateStatus: (application: Application.Model, newStatus: Application.Model["status"]) => Application.Model;
62
62
  }
63
63
 
64
- interface FirestoreTimestamp {
65
- seconds: number;
66
- nanoseconds: number;
67
- _firestore_timestamp?: boolean;
68
- }
69
- /**
70
- * AuthUser interface - replaces the old class-based model
71
- */
72
- interface AuthUser extends BaseModel {
73
- email: string;
74
- displayName?: string;
75
- photoURL?: string;
76
- lastSignIn?: Date | string;
77
- emailVerified?: boolean;
78
- }
79
- declare const AuthUserCollectionPath = "users";
80
- declare const getAuthUserDocumentPath: (userId: string) => string;
81
- declare const AuthUserUtils: {
82
- getTimestampFields: () => string[];
83
- isFirestoreTimestamp: (value: any) => value is FirestoreTimestamp;
84
- fromFirebaseUser: (user: any) => AuthUser;
85
- formatDates: (user: AuthUser) => {
64
+ declare namespace AuthUser {
65
+ export interface Model extends BaseModel {
66
+ email: string;
67
+ displayName?: string;
68
+ photoURL?: string;
69
+ lastSignIn?: string;
70
+ emailVerified?: boolean;
71
+ }
72
+ interface FirestoreTimestamp {
73
+ seconds: number;
74
+ nanoseconds: number;
75
+ _firestore_timestamp?: boolean;
76
+ }
77
+ export const collection: () => string;
78
+ export const document: (userId: string) => string;
79
+ export const getTimestampFields: () => (keyof Model)[];
80
+ export const isFirestoreTimestamp: (value: any) => value is FirestoreTimestamp;
81
+ export const fromFirebaseUser: (user: any) => Model;
82
+ export const format: (user: Model) => string;
83
+ export const formatDates: (user: Model) => {
86
84
  lastSignIn: string;
87
85
  createdAt: string;
88
86
  updatedAt?: string;
89
87
  };
90
- toFirestore: (user: AuthUser) => Record<string, any>;
91
- fromFirestore: (data: Record<string, any>) => AuthUser;
92
- };
88
+ export const toFirestore: (user: Model) => Record<string, any>;
89
+ export const fromFirestore: (data: Record<string, any>) => Model;
90
+ export const createNew: (email: string, displayName?: string, photoURL?: string) => Model;
91
+ export {};
92
+ }
93
93
 
94
94
  declare namespace Client {
95
95
  interface Model extends BaseModel {
@@ -301,4 +301,4 @@ declare namespace Agent {
301
301
  const createNew: (name: string, email: string) => Agent.Model;
302
302
  }
303
303
 
304
- export { Agent, Application, ApplicationQuestion, AuthUser, AuthUserCollectionPath, AuthUserUtils, Client, ClientData, ClientLogin, ClientQuestion, Vacancy, VacancySuggestion, getAuthUserDocumentPath };
304
+ export { Agent, Application, ApplicationQuestion, AuthUser, Client, ClientData, ClientLogin, ClientQuestion, Vacancy, VacancySuggestion };
package/dist/index.js CHANGED
@@ -23,15 +23,13 @@ __export(src_exports, {
23
23
  Agent: () => Agent,
24
24
  Application: () => Application,
25
25
  ApplicationQuestion: () => ApplicationQuestion,
26
- AuthUserCollectionPath: () => AuthUserCollectionPath,
27
- AuthUserUtils: () => AuthUserUtils,
26
+ AuthUser: () => AuthUser,
28
27
  Client: () => Client,
29
28
  ClientData: () => ClientData,
30
29
  ClientLogin: () => ClientLogin,
31
30
  ClientQuestion: () => ClientQuestion,
32
31
  Vacancy: () => Vacancy,
33
- VacancySuggestion: () => VacancySuggestion,
34
- getAuthUserDocumentPath: () => getAuthUserDocumentPath
32
+ VacancySuggestion: () => VacancySuggestion
35
33
  });
36
34
  module.exports = __toCommonJS(src_exports);
37
35
 
@@ -87,17 +85,19 @@ var Application;
87
85
  })(Application || (Application = {}));
88
86
 
89
87
  // src/models/AuthUser.ts
90
- var AuthUserCollectionPath = "users";
91
- var getAuthUserDocumentPath = (userId) => `users/${userId}`;
92
- var AuthUserUtils = {
93
- // Get timestamp fields for AuthUser
94
- getTimestampFields: () => [],
95
- // Check if value is a Firestore timestamp
96
- isFirestoreTimestamp: (value) => {
88
+ var AuthUser;
89
+ ((AuthUser2) => {
90
+ AuthUser2.collection = () => "users";
91
+ AuthUser2.document = (userId) => `users/${userId}`;
92
+ AuthUser2.getTimestampFields = () => [
93
+ "lastSignIn",
94
+ "createdAt",
95
+ "updatedAt"
96
+ ];
97
+ AuthUser2.isFirestoreTimestamp = (value) => {
97
98
  return typeof value === "object" && value !== null && ("seconds" in value || "_firestore_timestamp" in value);
98
- },
99
- // Create from Firebase user object
100
- fromFirebaseUser: (user) => {
99
+ };
100
+ AuthUser2.fromFirebaseUser = (user) => {
101
101
  return {
102
102
  id: user.uid,
103
103
  email: user.email,
@@ -105,16 +105,18 @@ var AuthUserUtils = {
105
105
  photoURL: user.photoURL,
106
106
  emailVerified: user.emailVerified,
107
107
  lastSignIn: (/* @__PURE__ */ new Date()).toISOString(),
108
- // Current timestamp for new logins
109
- createdAt: (/* @__PURE__ */ new Date()).toISOString()
108
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
109
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
110
110
  };
111
- },
112
- // Convert dates to display format
113
- formatDates: (user) => {
111
+ };
112
+ AuthUser2.format = (user) => {
113
+ return `${user.email}${user.displayName ? " (" + user.displayName + ")" : ""}`;
114
+ };
115
+ AuthUser2.formatDates = (user) => {
114
116
  const formatDate = (dateValue) => {
115
117
  if (!dateValue)
116
118
  return "N/A";
117
- const date = typeof dateValue === "string" ? new Date(dateValue) : dateValue;
119
+ const date = dateValue instanceof Date ? dateValue : new Date(dateValue);
118
120
  return date.toLocaleString();
119
121
  };
120
122
  return {
@@ -122,41 +124,49 @@ var AuthUserUtils = {
122
124
  createdAt: formatDate(user.createdAt),
123
125
  updatedAt: user.updatedAt ? formatDate(user.updatedAt) : void 0
124
126
  };
125
- },
126
- // Convert AuthUser to format for storage
127
- toFirestore: (user) => {
127
+ };
128
+ AuthUser2.toFirestore = (user) => {
128
129
  const { id, ...data } = user;
129
- if (data.lastSignIn && data.lastSignIn instanceof Date) {
130
- data.lastSignIn = data.lastSignIn.toISOString();
131
- }
132
- if (data.createdAt && data.createdAt instanceof Date) {
133
- data.createdAt = data.createdAt.toISOString();
134
- }
135
- if (data.updatedAt && data.updatedAt instanceof Date) {
136
- data.updatedAt = data.updatedAt.toISOString();
137
- } else {
138
- data.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
139
- }
130
+ (0, AuthUser2.getTimestampFields)().forEach((field) => {
131
+ if (data[field] instanceof Date) {
132
+ data[field] = data[field].toISOString();
133
+ } else if (!data[field]) {
134
+ if (field === "updatedAt") {
135
+ data.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
136
+ }
137
+ }
138
+ });
140
139
  return data;
141
- },
142
- // Convert from Firestore data to AuthUser
143
- fromFirestore: (data) => {
144
- const processedData = { ...data };
145
- const timestampFields = [];
146
- timestampFields.forEach((field) => {
140
+ };
141
+ AuthUser2.fromFirestore = (data) => {
142
+ const processed = { ...data };
143
+ (0, AuthUser2.getTimestampFields)().forEach((field) => {
147
144
  if (data[field]) {
148
- if (AuthUserUtils.isFirestoreTimestamp(data[field])) {
149
- processedData[field] = new Date(
145
+ if ((0, AuthUser2.isFirestoreTimestamp)(data[field])) {
146
+ processed[field] = new Date(
150
147
  data[field].seconds * 1e3
151
148
  ).toISOString();
152
149
  } else if (typeof data[field] === "string") {
153
- processedData[field] = data[field];
150
+ processed[field] = data[field];
154
151
  }
155
152
  }
156
153
  });
157
- return processedData;
158
- }
159
- };
154
+ return processed;
155
+ };
156
+ AuthUser2.createNew = (email, displayName, photoURL) => {
157
+ const now = (/* @__PURE__ */ new Date()).toISOString();
158
+ return {
159
+ id: void 0,
160
+ email,
161
+ displayName,
162
+ photoURL,
163
+ emailVerified: false,
164
+ lastSignIn: now,
165
+ createdAt: now,
166
+ updatedAt: now
167
+ };
168
+ };
169
+ })(AuthUser || (AuthUser = {}));
160
170
 
161
171
  // src/models/Client.ts
162
172
  var Client;
@@ -370,13 +380,11 @@ var Agent;
370
380
  Agent,
371
381
  Application,
372
382
  ApplicationQuestion,
373
- AuthUserCollectionPath,
374
- AuthUserUtils,
383
+ AuthUser,
375
384
  Client,
376
385
  ClientData,
377
386
  ClientLogin,
378
387
  ClientQuestion,
379
388
  Vacancy,
380
- VacancySuggestion,
381
- getAuthUserDocumentPath
389
+ VacancySuggestion
382
390
  });
package/dist/index.mjs CHANGED
@@ -50,17 +50,19 @@ var Application;
50
50
  })(Application || (Application = {}));
51
51
 
52
52
  // src/models/AuthUser.ts
53
- var AuthUserCollectionPath = "users";
54
- var getAuthUserDocumentPath = (userId) => `users/${userId}`;
55
- var AuthUserUtils = {
56
- // Get timestamp fields for AuthUser
57
- getTimestampFields: () => [],
58
- // Check if value is a Firestore timestamp
59
- isFirestoreTimestamp: (value) => {
53
+ var AuthUser;
54
+ ((AuthUser2) => {
55
+ AuthUser2.collection = () => "users";
56
+ AuthUser2.document = (userId) => `users/${userId}`;
57
+ AuthUser2.getTimestampFields = () => [
58
+ "lastSignIn",
59
+ "createdAt",
60
+ "updatedAt"
61
+ ];
62
+ AuthUser2.isFirestoreTimestamp = (value) => {
60
63
  return typeof value === "object" && value !== null && ("seconds" in value || "_firestore_timestamp" in value);
61
- },
62
- // Create from Firebase user object
63
- fromFirebaseUser: (user) => {
64
+ };
65
+ AuthUser2.fromFirebaseUser = (user) => {
64
66
  return {
65
67
  id: user.uid,
66
68
  email: user.email,
@@ -68,16 +70,18 @@ var AuthUserUtils = {
68
70
  photoURL: user.photoURL,
69
71
  emailVerified: user.emailVerified,
70
72
  lastSignIn: (/* @__PURE__ */ new Date()).toISOString(),
71
- // Current timestamp for new logins
72
- createdAt: (/* @__PURE__ */ new Date()).toISOString()
73
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
74
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
73
75
  };
74
- },
75
- // Convert dates to display format
76
- formatDates: (user) => {
76
+ };
77
+ AuthUser2.format = (user) => {
78
+ return `${user.email}${user.displayName ? " (" + user.displayName + ")" : ""}`;
79
+ };
80
+ AuthUser2.formatDates = (user) => {
77
81
  const formatDate = (dateValue) => {
78
82
  if (!dateValue)
79
83
  return "N/A";
80
- const date = typeof dateValue === "string" ? new Date(dateValue) : dateValue;
84
+ const date = dateValue instanceof Date ? dateValue : new Date(dateValue);
81
85
  return date.toLocaleString();
82
86
  };
83
87
  return {
@@ -85,41 +89,49 @@ var AuthUserUtils = {
85
89
  createdAt: formatDate(user.createdAt),
86
90
  updatedAt: user.updatedAt ? formatDate(user.updatedAt) : void 0
87
91
  };
88
- },
89
- // Convert AuthUser to format for storage
90
- toFirestore: (user) => {
92
+ };
93
+ AuthUser2.toFirestore = (user) => {
91
94
  const { id, ...data } = user;
92
- if (data.lastSignIn && data.lastSignIn instanceof Date) {
93
- data.lastSignIn = data.lastSignIn.toISOString();
94
- }
95
- if (data.createdAt && data.createdAt instanceof Date) {
96
- data.createdAt = data.createdAt.toISOString();
97
- }
98
- if (data.updatedAt && data.updatedAt instanceof Date) {
99
- data.updatedAt = data.updatedAt.toISOString();
100
- } else {
101
- data.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
102
- }
95
+ (0, AuthUser2.getTimestampFields)().forEach((field) => {
96
+ if (data[field] instanceof Date) {
97
+ data[field] = data[field].toISOString();
98
+ } else if (!data[field]) {
99
+ if (field === "updatedAt") {
100
+ data.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
101
+ }
102
+ }
103
+ });
103
104
  return data;
104
- },
105
- // Convert from Firestore data to AuthUser
106
- fromFirestore: (data) => {
107
- const processedData = { ...data };
108
- const timestampFields = [];
109
- timestampFields.forEach((field) => {
105
+ };
106
+ AuthUser2.fromFirestore = (data) => {
107
+ const processed = { ...data };
108
+ (0, AuthUser2.getTimestampFields)().forEach((field) => {
110
109
  if (data[field]) {
111
- if (AuthUserUtils.isFirestoreTimestamp(data[field])) {
112
- processedData[field] = new Date(
110
+ if ((0, AuthUser2.isFirestoreTimestamp)(data[field])) {
111
+ processed[field] = new Date(
113
112
  data[field].seconds * 1e3
114
113
  ).toISOString();
115
114
  } else if (typeof data[field] === "string") {
116
- processedData[field] = data[field];
115
+ processed[field] = data[field];
117
116
  }
118
117
  }
119
118
  });
120
- return processedData;
121
- }
122
- };
119
+ return processed;
120
+ };
121
+ AuthUser2.createNew = (email, displayName, photoURL) => {
122
+ const now = (/* @__PURE__ */ new Date()).toISOString();
123
+ return {
124
+ id: void 0,
125
+ email,
126
+ displayName,
127
+ photoURL,
128
+ emailVerified: false,
129
+ lastSignIn: now,
130
+ createdAt: now,
131
+ updatedAt: now
132
+ };
133
+ };
134
+ })(AuthUser || (AuthUser = {}));
123
135
 
124
136
  // src/models/Client.ts
125
137
  var Client;
@@ -332,13 +344,11 @@ export {
332
344
  Agent,
333
345
  Application,
334
346
  ApplicationQuestion,
335
- AuthUserCollectionPath,
336
- AuthUserUtils,
347
+ AuthUser,
337
348
  Client,
338
349
  ClientData,
339
350
  ClientLogin,
340
351
  ClientQuestion,
341
352
  Vacancy,
342
- VacancySuggestion,
343
- getAuthUserDocumentPath
353
+ VacancySuggestion
344
354
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jobsearch-works/firestore-models",
3
- "version": "1.0.29",
3
+ "version": "1.0.30",
4
4
  "description": "A shared library for standardizing Firestore document schemas and paths across multiple projects",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",