@jobsearch-works/firestore-models 1.0.29 → 1.0.31

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,38 @@ 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
+ declare namespace GmailMessage {
305
+ interface Model extends BaseModel {
306
+ messageId: string;
307
+ threadId?: string;
308
+ labelIds?: string[];
309
+ snippet?: string;
310
+ internalDate?: string;
311
+ payload?: {
312
+ headers?: Array<{
313
+ name: string;
314
+ value: string;
315
+ }>;
316
+ body?: {
317
+ data?: string;
318
+ };
319
+ parts?: Array<{
320
+ mimeType?: string;
321
+ body?: {
322
+ data?: string;
323
+ };
324
+ }>;
325
+ };
326
+ }
327
+ const collection: (clientId: string) => string;
328
+ const document: (clientId: string, messageId: string) => string;
329
+ const extractBody: (email: Model) => string;
330
+ const extractReceivedDate: (email: Model) => Date;
331
+ const extractSubject: (email: Model) => string;
332
+ const extractFromAddress: (email: Model) => string;
333
+ const formatEmailDate: (email: Model) => string;
334
+ const getEmailSender: (email: Model) => string;
335
+ const createNew: (messageId: string, threadId?: string, payload?: Model["payload"], labelIds?: string[], snippet?: string, internalDate?: string) => Model;
336
+ }
337
+
338
+ export { Agent, Application, ApplicationQuestion, AuthUser, Client, ClientData, ClientLogin, ClientQuestion, GmailMessage, 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,38 @@ 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
+ declare namespace GmailMessage {
305
+ interface Model extends BaseModel {
306
+ messageId: string;
307
+ threadId?: string;
308
+ labelIds?: string[];
309
+ snippet?: string;
310
+ internalDate?: string;
311
+ payload?: {
312
+ headers?: Array<{
313
+ name: string;
314
+ value: string;
315
+ }>;
316
+ body?: {
317
+ data?: string;
318
+ };
319
+ parts?: Array<{
320
+ mimeType?: string;
321
+ body?: {
322
+ data?: string;
323
+ };
324
+ }>;
325
+ };
326
+ }
327
+ const collection: (clientId: string) => string;
328
+ const document: (clientId: string, messageId: string) => string;
329
+ const extractBody: (email: Model) => string;
330
+ const extractReceivedDate: (email: Model) => Date;
331
+ const extractSubject: (email: Model) => string;
332
+ const extractFromAddress: (email: Model) => string;
333
+ const formatEmailDate: (email: Model) => string;
334
+ const getEmailSender: (email: Model) => string;
335
+ const createNew: (messageId: string, threadId?: string, payload?: Model["payload"], labelIds?: string[], snippet?: string, internalDate?: string) => Model;
336
+ }
337
+
338
+ export { Agent, Application, ApplicationQuestion, AuthUser, Client, ClientData, ClientLogin, ClientQuestion, GmailMessage, Vacancy, VacancySuggestion };
package/dist/index.js CHANGED
@@ -23,15 +23,14 @@ __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,
31
+ GmailMessage: () => GmailMessage,
32
32
  Vacancy: () => Vacancy,
33
- VacancySuggestion: () => VacancySuggestion,
34
- getAuthUserDocumentPath: () => getAuthUserDocumentPath
33
+ VacancySuggestion: () => VacancySuggestion
35
34
  });
36
35
  module.exports = __toCommonJS(src_exports);
37
36
 
@@ -87,17 +86,19 @@ var Application;
87
86
  })(Application || (Application = {}));
88
87
 
89
88
  // 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) => {
89
+ var AuthUser;
90
+ ((AuthUser2) => {
91
+ AuthUser2.collection = () => "users";
92
+ AuthUser2.document = (userId) => `users/${userId}`;
93
+ AuthUser2.getTimestampFields = () => [
94
+ "lastSignIn",
95
+ "createdAt",
96
+ "updatedAt"
97
+ ];
98
+ AuthUser2.isFirestoreTimestamp = (value) => {
97
99
  return typeof value === "object" && value !== null && ("seconds" in value || "_firestore_timestamp" in value);
98
- },
99
- // Create from Firebase user object
100
- fromFirebaseUser: (user) => {
100
+ };
101
+ AuthUser2.fromFirebaseUser = (user) => {
101
102
  return {
102
103
  id: user.uid,
103
104
  email: user.email,
@@ -105,16 +106,18 @@ var AuthUserUtils = {
105
106
  photoURL: user.photoURL,
106
107
  emailVerified: user.emailVerified,
107
108
  lastSignIn: (/* @__PURE__ */ new Date()).toISOString(),
108
- // Current timestamp for new logins
109
- createdAt: (/* @__PURE__ */ new Date()).toISOString()
109
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
110
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
110
111
  };
111
- },
112
- // Convert dates to display format
113
- formatDates: (user) => {
112
+ };
113
+ AuthUser2.format = (user) => {
114
+ return `${user.email}${user.displayName ? " (" + user.displayName + ")" : ""}`;
115
+ };
116
+ AuthUser2.formatDates = (user) => {
114
117
  const formatDate = (dateValue) => {
115
118
  if (!dateValue)
116
119
  return "N/A";
117
- const date = typeof dateValue === "string" ? new Date(dateValue) : dateValue;
120
+ const date = dateValue instanceof Date ? dateValue : new Date(dateValue);
118
121
  return date.toLocaleString();
119
122
  };
120
123
  return {
@@ -122,41 +125,49 @@ var AuthUserUtils = {
122
125
  createdAt: formatDate(user.createdAt),
123
126
  updatedAt: user.updatedAt ? formatDate(user.updatedAt) : void 0
124
127
  };
125
- },
126
- // Convert AuthUser to format for storage
127
- toFirestore: (user) => {
128
+ };
129
+ AuthUser2.toFirestore = (user) => {
128
130
  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
- }
131
+ (0, AuthUser2.getTimestampFields)().forEach((field) => {
132
+ if (data[field] instanceof Date) {
133
+ data[field] = data[field].toISOString();
134
+ } else if (!data[field]) {
135
+ if (field === "updatedAt") {
136
+ data.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
137
+ }
138
+ }
139
+ });
140
140
  return data;
141
- },
142
- // Convert from Firestore data to AuthUser
143
- fromFirestore: (data) => {
144
- const processedData = { ...data };
145
- const timestampFields = [];
146
- timestampFields.forEach((field) => {
141
+ };
142
+ AuthUser2.fromFirestore = (data) => {
143
+ const processed = { ...data };
144
+ (0, AuthUser2.getTimestampFields)().forEach((field) => {
147
145
  if (data[field]) {
148
- if (AuthUserUtils.isFirestoreTimestamp(data[field])) {
149
- processedData[field] = new Date(
146
+ if ((0, AuthUser2.isFirestoreTimestamp)(data[field])) {
147
+ processed[field] = new Date(
150
148
  data[field].seconds * 1e3
151
149
  ).toISOString();
152
150
  } else if (typeof data[field] === "string") {
153
- processedData[field] = data[field];
151
+ processed[field] = data[field];
154
152
  }
155
153
  }
156
154
  });
157
- return processedData;
158
- }
159
- };
155
+ return processed;
156
+ };
157
+ AuthUser2.createNew = (email, displayName, photoURL) => {
158
+ const now = (/* @__PURE__ */ new Date()).toISOString();
159
+ return {
160
+ id: void 0,
161
+ email,
162
+ displayName,
163
+ photoURL,
164
+ emailVerified: false,
165
+ lastSignIn: now,
166
+ createdAt: now,
167
+ updatedAt: now
168
+ };
169
+ };
170
+ })(AuthUser || (AuthUser = {}));
160
171
 
161
172
  // src/models/Client.ts
162
173
  var Client;
@@ -365,18 +376,92 @@ var Agent;
365
376
  };
366
377
  };
367
378
  })(Agent || (Agent = {}));
379
+
380
+ // src/models/GmailMessage.ts
381
+ var GmailMessage;
382
+ ((GmailMessage2) => {
383
+ GmailMessage2.collection = (clientId) => `clientEmails/${clientId}/messages`;
384
+ GmailMessage2.document = (clientId, messageId) => `${(0, GmailMessage2.collection)(clientId)}/${messageId}`;
385
+ GmailMessage2.extractBody = (email) => {
386
+ const payload = email.payload;
387
+ if (!payload)
388
+ return "No body available";
389
+ const getTextContent = (parts) => {
390
+ for (const part of parts) {
391
+ if (part.mimeType === "text/plain" && part.body?.data) {
392
+ return Buffer.from(part.body.data, "base64").toString();
393
+ }
394
+ }
395
+ return "";
396
+ };
397
+ if (payload.parts && Array.isArray(payload.parts)) {
398
+ return getTextContent(payload.parts) || "No body available";
399
+ }
400
+ if (payload.body?.data) {
401
+ return Buffer.from(payload.body.data, "base64").toString();
402
+ }
403
+ return "No body available";
404
+ };
405
+ GmailMessage2.extractReceivedDate = (email) => {
406
+ const headers = email.payload?.headers || [];
407
+ const dateHeader = headers.find(
408
+ (header) => header.name.toLowerCase() === "date"
409
+ );
410
+ if (dateHeader?.value) {
411
+ const parsedDate = new Date(dateHeader.value);
412
+ if (!isNaN(parsedDate.getTime())) {
413
+ return parsedDate;
414
+ }
415
+ }
416
+ if (email.internalDate) {
417
+ return new Date(parseInt(email.internalDate, 10));
418
+ }
419
+ return /* @__PURE__ */ new Date();
420
+ };
421
+ GmailMessage2.extractSubject = (email) => {
422
+ const headers = email.payload?.headers || [];
423
+ const subjectHeader = headers.find(
424
+ (header) => header.name.toLowerCase() === "subject"
425
+ );
426
+ return subjectHeader?.value || "No subject available";
427
+ };
428
+ GmailMessage2.extractFromAddress = (email) => {
429
+ const headers = email.payload?.headers || [];
430
+ const fromHeader = headers.find(
431
+ (header) => header.name.toLowerCase() === "from"
432
+ );
433
+ return fromHeader?.value || "No sender available";
434
+ };
435
+ GmailMessage2.formatEmailDate = (email) => {
436
+ const date = (0, GmailMessage2.extractReceivedDate)(email);
437
+ return date.toLocaleString();
438
+ };
439
+ GmailMessage2.getEmailSender = (email) => {
440
+ return (0, GmailMessage2.extractFromAddress)(email);
441
+ };
442
+ GmailMessage2.createNew = (messageId, threadId, payload, labelIds, snippet, internalDate) => {
443
+ return {
444
+ messageId,
445
+ threadId,
446
+ payload,
447
+ labelIds,
448
+ snippet,
449
+ internalDate,
450
+ createdAt: /* @__PURE__ */ new Date()
451
+ };
452
+ };
453
+ })(GmailMessage || (GmailMessage = {}));
368
454
  // Annotate the CommonJS export names for ESM import in node:
369
455
  0 && (module.exports = {
370
456
  Agent,
371
457
  Application,
372
458
  ApplicationQuestion,
373
- AuthUserCollectionPath,
374
- AuthUserUtils,
459
+ AuthUser,
375
460
  Client,
376
461
  ClientData,
377
462
  ClientLogin,
378
463
  ClientQuestion,
464
+ GmailMessage,
379
465
  Vacancy,
380
- VacancySuggestion,
381
- getAuthUserDocumentPath
466
+ VacancySuggestion
382
467
  });
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;
@@ -328,17 +340,91 @@ var Agent;
328
340
  };
329
341
  };
330
342
  })(Agent || (Agent = {}));
343
+
344
+ // src/models/GmailMessage.ts
345
+ var GmailMessage;
346
+ ((GmailMessage2) => {
347
+ GmailMessage2.collection = (clientId) => `clientEmails/${clientId}/messages`;
348
+ GmailMessage2.document = (clientId, messageId) => `${(0, GmailMessage2.collection)(clientId)}/${messageId}`;
349
+ GmailMessage2.extractBody = (email) => {
350
+ const payload = email.payload;
351
+ if (!payload)
352
+ return "No body available";
353
+ const getTextContent = (parts) => {
354
+ for (const part of parts) {
355
+ if (part.mimeType === "text/plain" && part.body?.data) {
356
+ return Buffer.from(part.body.data, "base64").toString();
357
+ }
358
+ }
359
+ return "";
360
+ };
361
+ if (payload.parts && Array.isArray(payload.parts)) {
362
+ return getTextContent(payload.parts) || "No body available";
363
+ }
364
+ if (payload.body?.data) {
365
+ return Buffer.from(payload.body.data, "base64").toString();
366
+ }
367
+ return "No body available";
368
+ };
369
+ GmailMessage2.extractReceivedDate = (email) => {
370
+ const headers = email.payload?.headers || [];
371
+ const dateHeader = headers.find(
372
+ (header) => header.name.toLowerCase() === "date"
373
+ );
374
+ if (dateHeader?.value) {
375
+ const parsedDate = new Date(dateHeader.value);
376
+ if (!isNaN(parsedDate.getTime())) {
377
+ return parsedDate;
378
+ }
379
+ }
380
+ if (email.internalDate) {
381
+ return new Date(parseInt(email.internalDate, 10));
382
+ }
383
+ return /* @__PURE__ */ new Date();
384
+ };
385
+ GmailMessage2.extractSubject = (email) => {
386
+ const headers = email.payload?.headers || [];
387
+ const subjectHeader = headers.find(
388
+ (header) => header.name.toLowerCase() === "subject"
389
+ );
390
+ return subjectHeader?.value || "No subject available";
391
+ };
392
+ GmailMessage2.extractFromAddress = (email) => {
393
+ const headers = email.payload?.headers || [];
394
+ const fromHeader = headers.find(
395
+ (header) => header.name.toLowerCase() === "from"
396
+ );
397
+ return fromHeader?.value || "No sender available";
398
+ };
399
+ GmailMessage2.formatEmailDate = (email) => {
400
+ const date = (0, GmailMessage2.extractReceivedDate)(email);
401
+ return date.toLocaleString();
402
+ };
403
+ GmailMessage2.getEmailSender = (email) => {
404
+ return (0, GmailMessage2.extractFromAddress)(email);
405
+ };
406
+ GmailMessage2.createNew = (messageId, threadId, payload, labelIds, snippet, internalDate) => {
407
+ return {
408
+ messageId,
409
+ threadId,
410
+ payload,
411
+ labelIds,
412
+ snippet,
413
+ internalDate,
414
+ createdAt: /* @__PURE__ */ new Date()
415
+ };
416
+ };
417
+ })(GmailMessage || (GmailMessage = {}));
331
418
  export {
332
419
  Agent,
333
420
  Application,
334
421
  ApplicationQuestion,
335
- AuthUserCollectionPath,
336
- AuthUserUtils,
422
+ AuthUser,
337
423
  Client,
338
424
  ClientData,
339
425
  ClientLogin,
340
426
  ClientQuestion,
427
+ GmailMessage,
341
428
  Vacancy,
342
- VacancySuggestion,
343
- getAuthUserDocumentPath
429
+ VacancySuggestion
344
430
  };
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.31",
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",