@jobsearch-works/firestore-models 1.0.28 → 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 {
@@ -288,4 +288,17 @@ declare namespace ApplicationQuestion {
288
288
  const createNew: (questionText: string, type: Type, answerText?: string) => ApplicationQuestion.Model;
289
289
  }
290
290
 
291
- export { Application, ApplicationQuestion, AuthUser, AuthUserCollectionPath, AuthUserUtils, Client, ClientData, ClientLogin, ClientQuestion, Vacancy, VacancySuggestion, getAuthUserDocumentPath };
291
+ declare namespace Agent {
292
+ interface Model extends BaseModel {
293
+ name: string;
294
+ email: string;
295
+ status: "active" | "inactive";
296
+ profilePicture?: string;
297
+ }
298
+ const collection: () => string;
299
+ const document: (agentId: string) => string;
300
+ const formatAgent: (agent: Agent.Model) => string;
301
+ const createNew: (name: string, email: string) => Agent.Model;
302
+ }
303
+
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 {
@@ -288,4 +288,17 @@ declare namespace ApplicationQuestion {
288
288
  const createNew: (questionText: string, type: Type, answerText?: string) => ApplicationQuestion.Model;
289
289
  }
290
290
 
291
- export { Application, ApplicationQuestion, AuthUser, AuthUserCollectionPath, AuthUserUtils, Client, ClientData, ClientLogin, ClientQuestion, Vacancy, VacancySuggestion, getAuthUserDocumentPath };
291
+ declare namespace Agent {
292
+ interface Model extends BaseModel {
293
+ name: string;
294
+ email: string;
295
+ status: "active" | "inactive";
296
+ profilePicture?: string;
297
+ }
298
+ const collection: () => string;
299
+ const document: (agentId: string) => string;
300
+ const formatAgent: (agent: Agent.Model) => string;
301
+ const createNew: (name: string, email: string) => Agent.Model;
302
+ }
303
+
304
+ export { Agent, Application, ApplicationQuestion, AuthUser, Client, ClientData, ClientLogin, ClientQuestion, Vacancy, VacancySuggestion };
package/dist/index.js CHANGED
@@ -20,17 +20,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var src_exports = {};
22
22
  __export(src_exports, {
23
+ Agent: () => Agent,
23
24
  Application: () => Application,
24
25
  ApplicationQuestion: () => ApplicationQuestion,
25
- AuthUserCollectionPath: () => AuthUserCollectionPath,
26
- AuthUserUtils: () => AuthUserUtils,
26
+ AuthUser: () => AuthUser,
27
27
  Client: () => Client,
28
28
  ClientData: () => ClientData,
29
29
  ClientLogin: () => ClientLogin,
30
30
  ClientQuestion: () => ClientQuestion,
31
31
  Vacancy: () => Vacancy,
32
- VacancySuggestion: () => VacancySuggestion,
33
- getAuthUserDocumentPath: () => getAuthUserDocumentPath
32
+ VacancySuggestion: () => VacancySuggestion
34
33
  });
35
34
  module.exports = __toCommonJS(src_exports);
36
35
 
@@ -86,17 +85,19 @@ var Application;
86
85
  })(Application || (Application = {}));
87
86
 
88
87
  // src/models/AuthUser.ts
89
- var AuthUserCollectionPath = "users";
90
- var getAuthUserDocumentPath = (userId) => `users/${userId}`;
91
- var AuthUserUtils = {
92
- // Get timestamp fields for AuthUser
93
- getTimestampFields: () => [],
94
- // Check if value is a Firestore timestamp
95
- 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) => {
96
98
  return typeof value === "object" && value !== null && ("seconds" in value || "_firestore_timestamp" in value);
97
- },
98
- // Create from Firebase user object
99
- fromFirebaseUser: (user) => {
99
+ };
100
+ AuthUser2.fromFirebaseUser = (user) => {
100
101
  return {
101
102
  id: user.uid,
102
103
  email: user.email,
@@ -104,16 +105,18 @@ var AuthUserUtils = {
104
105
  photoURL: user.photoURL,
105
106
  emailVerified: user.emailVerified,
106
107
  lastSignIn: (/* @__PURE__ */ new Date()).toISOString(),
107
- // Current timestamp for new logins
108
- createdAt: (/* @__PURE__ */ new Date()).toISOString()
108
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
109
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
109
110
  };
110
- },
111
- // Convert dates to display format
112
- formatDates: (user) => {
111
+ };
112
+ AuthUser2.format = (user) => {
113
+ return `${user.email}${user.displayName ? " (" + user.displayName + ")" : ""}`;
114
+ };
115
+ AuthUser2.formatDates = (user) => {
113
116
  const formatDate = (dateValue) => {
114
117
  if (!dateValue)
115
118
  return "N/A";
116
- const date = typeof dateValue === "string" ? new Date(dateValue) : dateValue;
119
+ const date = dateValue instanceof Date ? dateValue : new Date(dateValue);
117
120
  return date.toLocaleString();
118
121
  };
119
122
  return {
@@ -121,41 +124,49 @@ var AuthUserUtils = {
121
124
  createdAt: formatDate(user.createdAt),
122
125
  updatedAt: user.updatedAt ? formatDate(user.updatedAt) : void 0
123
126
  };
124
- },
125
- // Convert AuthUser to format for storage
126
- toFirestore: (user) => {
127
+ };
128
+ AuthUser2.toFirestore = (user) => {
127
129
  const { id, ...data } = user;
128
- if (data.lastSignIn && data.lastSignIn instanceof Date) {
129
- data.lastSignIn = data.lastSignIn.toISOString();
130
- }
131
- if (data.createdAt && data.createdAt instanceof Date) {
132
- data.createdAt = data.createdAt.toISOString();
133
- }
134
- if (data.updatedAt && data.updatedAt instanceof Date) {
135
- data.updatedAt = data.updatedAt.toISOString();
136
- } else {
137
- data.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
138
- }
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
+ });
139
139
  return data;
140
- },
141
- // Convert from Firestore data to AuthUser
142
- fromFirestore: (data) => {
143
- const processedData = { ...data };
144
- const timestampFields = [];
145
- timestampFields.forEach((field) => {
140
+ };
141
+ AuthUser2.fromFirestore = (data) => {
142
+ const processed = { ...data };
143
+ (0, AuthUser2.getTimestampFields)().forEach((field) => {
146
144
  if (data[field]) {
147
- if (AuthUserUtils.isFirestoreTimestamp(data[field])) {
148
- processedData[field] = new Date(
145
+ if ((0, AuthUser2.isFirestoreTimestamp)(data[field])) {
146
+ processed[field] = new Date(
149
147
  data[field].seconds * 1e3
150
148
  ).toISOString();
151
149
  } else if (typeof data[field] === "string") {
152
- processedData[field] = data[field];
150
+ processed[field] = data[field];
153
151
  }
154
152
  }
155
153
  });
156
- return processedData;
157
- }
158
- };
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 = {}));
159
170
 
160
171
  // src/models/Client.ts
161
172
  var Client;
@@ -346,17 +357,34 @@ var ApplicationQuestion;
346
357
  };
347
358
  };
348
359
  })(ApplicationQuestion || (ApplicationQuestion = {}));
360
+
361
+ // src/models/Agent.ts
362
+ var Agent;
363
+ ((Agent2) => {
364
+ Agent2.collection = () => "agents";
365
+ Agent2.document = (agentId) => `agents/${agentId}`;
366
+ Agent2.formatAgent = (agent) => {
367
+ return `${agent.name} (${agent.email}) - ${agent.status}`;
368
+ };
369
+ Agent2.createNew = (name, email) => {
370
+ return {
371
+ name,
372
+ email,
373
+ status: "active",
374
+ createdAt: (/* @__PURE__ */ new Date()).toISOString()
375
+ };
376
+ };
377
+ })(Agent || (Agent = {}));
349
378
  // Annotate the CommonJS export names for ESM import in node:
350
379
  0 && (module.exports = {
380
+ Agent,
351
381
  Application,
352
382
  ApplicationQuestion,
353
- AuthUserCollectionPath,
354
- AuthUserUtils,
383
+ AuthUser,
355
384
  Client,
356
385
  ClientData,
357
386
  ClientLogin,
358
387
  ClientQuestion,
359
388
  Vacancy,
360
- VacancySuggestion,
361
- getAuthUserDocumentPath
389
+ VacancySuggestion
362
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;
@@ -310,16 +322,33 @@ var ApplicationQuestion;
310
322
  };
311
323
  };
312
324
  })(ApplicationQuestion || (ApplicationQuestion = {}));
325
+
326
+ // src/models/Agent.ts
327
+ var Agent;
328
+ ((Agent2) => {
329
+ Agent2.collection = () => "agents";
330
+ Agent2.document = (agentId) => `agents/${agentId}`;
331
+ Agent2.formatAgent = (agent) => {
332
+ return `${agent.name} (${agent.email}) - ${agent.status}`;
333
+ };
334
+ Agent2.createNew = (name, email) => {
335
+ return {
336
+ name,
337
+ email,
338
+ status: "active",
339
+ createdAt: (/* @__PURE__ */ new Date()).toISOString()
340
+ };
341
+ };
342
+ })(Agent || (Agent = {}));
313
343
  export {
344
+ Agent,
314
345
  Application,
315
346
  ApplicationQuestion,
316
- AuthUserCollectionPath,
317
- AuthUserUtils,
347
+ AuthUser,
318
348
  Client,
319
349
  ClientData,
320
350
  ClientLogin,
321
351
  ClientQuestion,
322
352
  Vacancy,
323
- VacancySuggestion,
324
- getAuthUserDocumentPath
353
+ VacancySuggestion
325
354
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jobsearch-works/firestore-models",
3
- "version": "1.0.28",
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",