@thejob/util 1.0.24 → 1.0.26
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/cjs/completeness/completeness.d.ts +8 -1
- package/dist/cjs/completeness/completeness.d.ts.map +1 -1
- package/dist/cjs/completeness/completeness.js +101 -116
- package/dist/cjs/user/utils.d.ts +35 -0
- package/dist/cjs/user/utils.d.ts.map +1 -1
- package/dist/cjs/user/utils.js +56 -0
- package/dist/esm/completeness/completeness.d.ts +8 -1
- package/dist/esm/completeness/completeness.d.ts.map +1 -1
- package/dist/esm/completeness/completeness.js +100 -117
- package/dist/esm/user/utils.d.ts +35 -0
- package/dist/esm/user/utils.d.ts.map +1 -1
- package/dist/esm/user/utils.js +55 -0
- package/package.json +2 -2
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { TCompletenessScoreSchema, TUserCompletenessSchema, TUserSchema } from "@thejob/schema";
|
|
2
|
+
/**
|
|
3
|
+
* Calculates the profile completeness score for a given user object.
|
|
4
|
+
* Pure function — no database calls required.
|
|
5
|
+
*
|
|
6
|
+
* Mirrors the section weights used in UsersService.getCompleteness().
|
|
7
|
+
*/
|
|
8
|
+
export declare function calculateProfileCompleteness(user: Partial<TUserSchema>): Record<keyof TUserCompletenessSchema, TCompletenessScoreSchema>;
|
|
2
9
|
//# sourceMappingURL=completeness.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"completeness.d.ts","sourceRoot":"","sources":["../../../src/completeness/completeness.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"completeness.d.ts","sourceRoot":"","sources":["../../../src/completeness/completeness.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,uBAAuB,EACvB,WAAW,EAEZ,MAAM,gBAAgB,CAAC;AAGxB;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAC1C,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,GACzB,MAAM,CAAC,MAAM,uBAAuB,EAAE,wBAAwB,CAAC,CA6GjE"}
|
|
@@ -1,119 +1,104 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
3
|
+
exports.calculateProfileCompleteness = calculateProfileCompleteness;
|
|
4
|
+
const schema_1 = require("@thejob/schema");
|
|
5
|
+
const utils_1 = require("../common/utils");
|
|
6
|
+
/**
|
|
7
|
+
* Calculates the profile completeness score for a given user object.
|
|
8
|
+
* Pure function — no database calls required.
|
|
9
|
+
*
|
|
10
|
+
* Mirrors the section weights used in UsersService.getCompleteness().
|
|
11
|
+
*/
|
|
12
|
+
function calculateProfileCompleteness(user) {
|
|
13
|
+
const { educations, workExperiences, projects, skills, languages, interests, certifications, socialAccounts, additionalInfo, } = user;
|
|
14
|
+
// General (7 steps: name, headline, aboutMe, email, mobile, location, image)
|
|
15
|
+
const generalTotalSteps = 7;
|
|
16
|
+
const generalCompletedSteps = [
|
|
17
|
+
!!user.name,
|
|
18
|
+
!!user.headline,
|
|
19
|
+
!!user.aboutMe,
|
|
20
|
+
!!user.email,
|
|
21
|
+
!!user.mobile,
|
|
22
|
+
!!user.location,
|
|
23
|
+
!!user.image,
|
|
24
|
+
].filter(Boolean).length;
|
|
25
|
+
// Sections with 1 step each (has at least one item)
|
|
26
|
+
const workExperiencesCompleted = workExperiences?.length ? 1 : 0;
|
|
27
|
+
const educationsCompleted = educations?.length ? 1 : 0;
|
|
28
|
+
const projectsCompleted = projects?.length ? 1 : 0;
|
|
29
|
+
const skillsCompleted = skills?.length ? 1 : 0;
|
|
30
|
+
const languagesCompleted = languages?.length ? 1 : 0;
|
|
31
|
+
const interestsCompleted = interests?.length ? 1 : 0;
|
|
32
|
+
const certificationsCompleted = certifications?.length ? 1 : 0;
|
|
33
|
+
const socialAccountsCompleted = socialAccounts?.length ? 1 : 0;
|
|
34
|
+
const additionalInfoCompleted = additionalInfo?.length ? 1 : 0;
|
|
35
|
+
// Overview total excludes additionalInfo (matches original service logic)
|
|
36
|
+
const totalSteps = generalTotalSteps + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1; // 15
|
|
37
|
+
const completedSteps = generalCompletedSteps +
|
|
38
|
+
workExperiencesCompleted +
|
|
39
|
+
educationsCompleted +
|
|
40
|
+
projectsCompleted +
|
|
41
|
+
skillsCompleted +
|
|
42
|
+
languagesCompleted +
|
|
43
|
+
interestsCompleted +
|
|
44
|
+
certificationsCompleted +
|
|
45
|
+
socialAccountsCompleted;
|
|
46
|
+
const score = (completedSteps / totalSteps) * 100;
|
|
47
|
+
return {
|
|
48
|
+
[schema_1.UserDetailType.Overview]: {
|
|
49
|
+
score: (0, utils_1.toPositiveWholeNumber)(score),
|
|
50
|
+
completedSteps,
|
|
51
|
+
totalSteps,
|
|
52
|
+
},
|
|
53
|
+
[schema_1.UserDetailType.General]: {
|
|
54
|
+
score: (0, utils_1.toPositiveWholeNumber)((generalCompletedSteps / generalTotalSteps) * 100),
|
|
55
|
+
completedSteps: generalCompletedSteps,
|
|
56
|
+
totalSteps: generalTotalSteps,
|
|
57
|
+
},
|
|
58
|
+
[schema_1.UserDetailType.WorkExperiences]: {
|
|
59
|
+
score: (0, utils_1.toPositiveWholeNumber)(workExperiencesCompleted * 100),
|
|
60
|
+
completedSteps: workExperiencesCompleted,
|
|
61
|
+
totalSteps: 1,
|
|
62
|
+
},
|
|
63
|
+
[schema_1.UserDetailType.Educations]: {
|
|
64
|
+
score: (0, utils_1.toPositiveWholeNumber)(educationsCompleted * 100),
|
|
65
|
+
completedSteps: educationsCompleted,
|
|
66
|
+
totalSteps: 1,
|
|
67
|
+
},
|
|
68
|
+
[schema_1.UserDetailType.Projects]: {
|
|
69
|
+
score: (0, utils_1.toPositiveWholeNumber)(projectsCompleted * 100),
|
|
70
|
+
completedSteps: projectsCompleted,
|
|
71
|
+
totalSteps: 1,
|
|
72
|
+
},
|
|
73
|
+
[schema_1.UserDetailType.Skills]: {
|
|
74
|
+
score: (0, utils_1.toPositiveWholeNumber)(skillsCompleted * 100),
|
|
75
|
+
completedSteps: skillsCompleted,
|
|
76
|
+
totalSteps: 1,
|
|
77
|
+
},
|
|
78
|
+
[schema_1.UserDetailType.Languages]: {
|
|
79
|
+
score: (0, utils_1.toPositiveWholeNumber)(languagesCompleted * 100),
|
|
80
|
+
completedSteps: languagesCompleted,
|
|
81
|
+
totalSteps: 1,
|
|
82
|
+
},
|
|
83
|
+
[schema_1.UserDetailType.Interests]: {
|
|
84
|
+
score: (0, utils_1.toPositiveWholeNumber)(interestsCompleted * 100),
|
|
85
|
+
completedSteps: interestsCompleted,
|
|
86
|
+
totalSteps: 1,
|
|
87
|
+
},
|
|
88
|
+
[schema_1.UserDetailType.Certifications]: {
|
|
89
|
+
score: (0, utils_1.toPositiveWholeNumber)(certificationsCompleted * 100),
|
|
90
|
+
completedSteps: certificationsCompleted,
|
|
91
|
+
totalSteps: 1,
|
|
92
|
+
},
|
|
93
|
+
[schema_1.UserDetailType.SocialAccounts]: {
|
|
94
|
+
score: (0, utils_1.toPositiveWholeNumber)(socialAccountsCompleted * 100),
|
|
95
|
+
completedSteps: socialAccountsCompleted,
|
|
96
|
+
totalSteps: 1,
|
|
97
|
+
},
|
|
98
|
+
[schema_1.UserDetailType.AdditionalInfo]: {
|
|
99
|
+
score: (0, utils_1.toPositiveWholeNumber)(additionalInfoCompleted * 100),
|
|
100
|
+
completedSteps: additionalInfoCompleted,
|
|
101
|
+
totalSteps: 1,
|
|
102
|
+
},
|
|
41
103
|
};
|
|
42
|
-
|
|
43
|
-
const fieldSchema = schemaFields[key];
|
|
44
|
-
if (!fieldSchema)
|
|
45
|
-
continue;
|
|
46
|
-
const currentPath = prefix ? `${prefix}.${key}` : key;
|
|
47
|
-
processField(key, fieldSchema, currentPath);
|
|
48
|
-
}
|
|
49
|
-
return extractedFields;
|
|
50
|
-
};
|
|
51
|
-
// const getValueByPath = (data: any, path: string) => {
|
|
52
|
-
// const parts = path.replace("[]", "").split(".");
|
|
53
|
-
// return parts.reduce((acc, part) => {
|
|
54
|
-
// if (acc === undefined || acc === null) return undefined;
|
|
55
|
-
// const match = part.match(/^(\d+)$/);
|
|
56
|
-
// if (match && match[1]) {
|
|
57
|
-
// const index = parseInt(match[1]);
|
|
58
|
-
// return Array.isArray(acc) ? acc[index] : undefined;
|
|
59
|
-
// }
|
|
60
|
-
// return acc[part];
|
|
61
|
-
// }, data);
|
|
62
|
-
// };
|
|
63
|
-
// export const getCompletenessScore = <T>(
|
|
64
|
-
// schema: any,
|
|
65
|
-
// data: T | T[],
|
|
66
|
-
// options: CompletenessOptions = { includeOptionals: false }
|
|
67
|
-
// ): CompletenessScore => {
|
|
68
|
-
// const { includeOptionals = false, emptyArrayScore } = options;
|
|
69
|
-
// if (Array.isArray(data)) {
|
|
70
|
-
// if (data.length === 0) {
|
|
71
|
-
// return {
|
|
72
|
-
// score: emptyArrayScore === "perfect" ? 100 : 0,
|
|
73
|
-
// completedSteps: 0,
|
|
74
|
-
// totalSteps: 0,
|
|
75
|
-
// children: [],
|
|
76
|
-
// };
|
|
77
|
-
// }
|
|
78
|
-
// const children = data.map((item) =>
|
|
79
|
-
// getCompletenessScore(schema, item, options)
|
|
80
|
-
// );
|
|
81
|
-
// const contentScore =
|
|
82
|
-
// children.reduce((sum, child) => sum + child.score, 0) / children.length;
|
|
83
|
-
// return {
|
|
84
|
-
// score: Math.round(contentScore),
|
|
85
|
-
// completedSteps: children.reduce((sum, c) => sum + c.completedSteps, 0),
|
|
86
|
-
// totalSteps: children.reduce((sum, c) => sum + c.totalSteps, 0),
|
|
87
|
-
// children,
|
|
88
|
-
// };
|
|
89
|
-
// }
|
|
90
|
-
// const fields = extractFields(schema, "", includeOptionals);
|
|
91
|
-
// const requiredFields = fields.filter((f) => f.required);
|
|
92
|
-
// const totalSteps = includeOptionals ? fields.length : requiredFields.length;
|
|
93
|
-
// let completedSteps = 0;
|
|
94
|
-
// const meta = {
|
|
95
|
-
// steps: fields.map((f) => f.key),
|
|
96
|
-
// completed: [] as string[],
|
|
97
|
-
// incomplete: [] as string[],
|
|
98
|
-
// };
|
|
99
|
-
// fields.forEach(({ key, required }) => {
|
|
100
|
-
// const value = getValueByPath(data, key);
|
|
101
|
-
// const exists = value !== undefined && value !== null && value !== "";
|
|
102
|
-
// if (exists) {
|
|
103
|
-
// meta.completed.push(key);
|
|
104
|
-
// if (includeOptionals || required) completedSteps++;
|
|
105
|
-
// } else {
|
|
106
|
-
// if (includeOptionals || required) meta.incomplete.push(key);
|
|
107
|
-
// }
|
|
108
|
-
// });
|
|
109
|
-
// const score =
|
|
110
|
-
// totalSteps > 0 ? Math.floor((completedSteps / totalSteps) * 100) : 100;
|
|
111
|
-
// return {
|
|
112
|
-
// score,
|
|
113
|
-
// completedSteps: includeOptionals
|
|
114
|
-
// ? completedSteps
|
|
115
|
-
// : Math.min(completedSteps, requiredFields.length),
|
|
116
|
-
// totalSteps,
|
|
117
|
-
// meta,
|
|
118
|
-
// };
|
|
119
|
-
// };
|
|
104
|
+
}
|
package/dist/cjs/user/utils.d.ts
CHANGED
|
@@ -1,3 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prepares a user profile for vector embedding by creating a semantic narrative.
|
|
3
|
+
* Mirrors prepareJobForEmbedding() — same "Label: Value" format for Voyage AI.
|
|
4
|
+
*
|
|
5
|
+
* Strategy:
|
|
6
|
+
* 1. Core identity (headline + location)
|
|
7
|
+
* 2. About me (intent/personality signal)
|
|
8
|
+
* 3. Flattened structured data (skills, experience, education)
|
|
9
|
+
*/
|
|
10
|
+
export declare function prepareUserForEmbedding(user: {
|
|
11
|
+
headline?: string;
|
|
12
|
+
aboutMe?: string;
|
|
13
|
+
location?: {
|
|
14
|
+
city?: string;
|
|
15
|
+
stateCode?: string;
|
|
16
|
+
state?: string;
|
|
17
|
+
country?: string;
|
|
18
|
+
};
|
|
19
|
+
skills?: Array<{
|
|
20
|
+
name: string;
|
|
21
|
+
}>;
|
|
22
|
+
experienceLevel?: string;
|
|
23
|
+
workExperiences?: Array<{
|
|
24
|
+
title?: string;
|
|
25
|
+
company?: string;
|
|
26
|
+
}>;
|
|
27
|
+
educations?: Array<{
|
|
28
|
+
degree?: string;
|
|
29
|
+
fieldOfStudy?: string;
|
|
30
|
+
institution?: string;
|
|
31
|
+
}>;
|
|
32
|
+
languages?: Array<{
|
|
33
|
+
name: string;
|
|
34
|
+
}>;
|
|
35
|
+
}): string;
|
|
1
36
|
export declare const parseName: (name: string | {
|
|
2
37
|
first: string;
|
|
3
38
|
last?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/user/utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE;WAAvB,MAAM;WAAS,MAAM;CAWtE,CAAC"}
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/user/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE;IAC5C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACnF,MAAM,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACjC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,eAAe,CAAC,EAAE,KAAK,CAAC;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC9D,UAAU,CAAC,EAAE,KAAK,CAAC;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACrF,SAAS,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACrC,GAAG,MAAM,CA8CT;AAED,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE;WAAvB,MAAM;WAAS,MAAM;CAWtE,CAAC"}
|
package/dist/cjs/user/utils.js
CHANGED
|
@@ -1,6 +1,62 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseName = void 0;
|
|
4
|
+
exports.prepareUserForEmbedding = prepareUserForEmbedding;
|
|
5
|
+
/**
|
|
6
|
+
* Prepares a user profile for vector embedding by creating a semantic narrative.
|
|
7
|
+
* Mirrors prepareJobForEmbedding() — same "Label: Value" format for Voyage AI.
|
|
8
|
+
*
|
|
9
|
+
* Strategy:
|
|
10
|
+
* 1. Core identity (headline + location)
|
|
11
|
+
* 2. About me (intent/personality signal)
|
|
12
|
+
* 3. Flattened structured data (skills, experience, education)
|
|
13
|
+
*/
|
|
14
|
+
function prepareUserForEmbedding(user) {
|
|
15
|
+
const headline = user.headline?.trim() || '';
|
|
16
|
+
const about = user.aboutMe?.replace(/\n/g, ' ').trim() || '';
|
|
17
|
+
const locationParts = [
|
|
18
|
+
user.location?.city,
|
|
19
|
+
user.location?.stateCode || user.location?.state,
|
|
20
|
+
user.location?.country,
|
|
21
|
+
].filter(Boolean);
|
|
22
|
+
const location = locationParts.join(', ');
|
|
23
|
+
const skillsList = user.skills
|
|
24
|
+
?.map((s) => s.name.toLowerCase())
|
|
25
|
+
.filter(Boolean)
|
|
26
|
+
.join(', ') || '';
|
|
27
|
+
const experienceList = user.workExperiences
|
|
28
|
+
?.map((w) => [w.title, w.company].filter(Boolean).join(' at '))
|
|
29
|
+
.filter(Boolean)
|
|
30
|
+
.join('; ') || '';
|
|
31
|
+
const educationList = user.educations
|
|
32
|
+
?.map((e) => [e.degree, e.fieldOfStudy, e.institution ? `at ${e.institution}` : '']
|
|
33
|
+
.filter(Boolean)
|
|
34
|
+
.join(' '))
|
|
35
|
+
.filter(Boolean)
|
|
36
|
+
.join('; ') || '';
|
|
37
|
+
const languagesList = user.languages
|
|
38
|
+
?.map((l) => l.name)
|
|
39
|
+
.filter(Boolean)
|
|
40
|
+
.join(', ') || '';
|
|
41
|
+
const parts = [];
|
|
42
|
+
if (headline)
|
|
43
|
+
parts.push(`Headline: ${headline}`);
|
|
44
|
+
if (about)
|
|
45
|
+
parts.push(`About: ${about}`);
|
|
46
|
+
if (skillsList)
|
|
47
|
+
parts.push(`Skills: ${skillsList}`);
|
|
48
|
+
if (location)
|
|
49
|
+
parts.push(`Location: ${location}`);
|
|
50
|
+
if (user.experienceLevel)
|
|
51
|
+
parts.push(`Level: ${user.experienceLevel}`);
|
|
52
|
+
if (experienceList)
|
|
53
|
+
parts.push(`Experience: ${experienceList}`);
|
|
54
|
+
if (educationList)
|
|
55
|
+
parts.push(`Education: ${educationList}`);
|
|
56
|
+
if (languagesList)
|
|
57
|
+
parts.push(`Languages: ${languagesList}`);
|
|
58
|
+
return parts.join('. ').replace(/\s\s+/g, ' ').trim();
|
|
59
|
+
}
|
|
4
60
|
const parseName = (name) => {
|
|
5
61
|
if (typeof name === "string") {
|
|
6
62
|
const nameParts = name.trim().split(/\s+/); // Split by spaces, ensuring no extra whitespace
|
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { TCompletenessScoreSchema, TUserCompletenessSchema, TUserSchema } from "@thejob/schema";
|
|
2
|
+
/**
|
|
3
|
+
* Calculates the profile completeness score for a given user object.
|
|
4
|
+
* Pure function — no database calls required.
|
|
5
|
+
*
|
|
6
|
+
* Mirrors the section weights used in UsersService.getCompleteness().
|
|
7
|
+
*/
|
|
8
|
+
export declare function calculateProfileCompleteness(user: Partial<TUserSchema>): Record<keyof TUserCompletenessSchema, TCompletenessScoreSchema>;
|
|
2
9
|
//# sourceMappingURL=completeness.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"completeness.d.ts","sourceRoot":"","sources":["../../../src/completeness/completeness.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"completeness.d.ts","sourceRoot":"","sources":["../../../src/completeness/completeness.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,uBAAuB,EACvB,WAAW,EAEZ,MAAM,gBAAgB,CAAC;AAGxB;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAC1C,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,GACzB,MAAM,CAAC,MAAM,uBAAuB,EAAE,wBAAwB,CAAC,CA6GjE"}
|
|
@@ -1,118 +1,101 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
1
|
+
import { UserDetailType, } from "@thejob/schema";
|
|
2
|
+
import { toPositiveWholeNumber } from "../common/utils";
|
|
3
|
+
/**
|
|
4
|
+
* Calculates the profile completeness score for a given user object.
|
|
5
|
+
* Pure function — no database calls required.
|
|
6
|
+
*
|
|
7
|
+
* Mirrors the section weights used in UsersService.getCompleteness().
|
|
8
|
+
*/
|
|
9
|
+
export function calculateProfileCompleteness(user) {
|
|
10
|
+
const { educations, workExperiences, projects, skills, languages, interests, certifications, socialAccounts, additionalInfo, } = user;
|
|
11
|
+
// General (7 steps: name, headline, aboutMe, email, mobile, location, image)
|
|
12
|
+
const generalTotalSteps = 7;
|
|
13
|
+
const generalCompletedSteps = [
|
|
14
|
+
!!user.name,
|
|
15
|
+
!!user.headline,
|
|
16
|
+
!!user.aboutMe,
|
|
17
|
+
!!user.email,
|
|
18
|
+
!!user.mobile,
|
|
19
|
+
!!user.location,
|
|
20
|
+
!!user.image,
|
|
21
|
+
].filter(Boolean).length;
|
|
22
|
+
// Sections with 1 step each (has at least one item)
|
|
23
|
+
const workExperiencesCompleted = workExperiences?.length ? 1 : 0;
|
|
24
|
+
const educationsCompleted = educations?.length ? 1 : 0;
|
|
25
|
+
const projectsCompleted = projects?.length ? 1 : 0;
|
|
26
|
+
const skillsCompleted = skills?.length ? 1 : 0;
|
|
27
|
+
const languagesCompleted = languages?.length ? 1 : 0;
|
|
28
|
+
const interestsCompleted = interests?.length ? 1 : 0;
|
|
29
|
+
const certificationsCompleted = certifications?.length ? 1 : 0;
|
|
30
|
+
const socialAccountsCompleted = socialAccounts?.length ? 1 : 0;
|
|
31
|
+
const additionalInfoCompleted = additionalInfo?.length ? 1 : 0;
|
|
32
|
+
// Overview total excludes additionalInfo (matches original service logic)
|
|
33
|
+
const totalSteps = generalTotalSteps + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1; // 15
|
|
34
|
+
const completedSteps = generalCompletedSteps +
|
|
35
|
+
workExperiencesCompleted +
|
|
36
|
+
educationsCompleted +
|
|
37
|
+
projectsCompleted +
|
|
38
|
+
skillsCompleted +
|
|
39
|
+
languagesCompleted +
|
|
40
|
+
interestsCompleted +
|
|
41
|
+
certificationsCompleted +
|
|
42
|
+
socialAccountsCompleted;
|
|
43
|
+
const score = (completedSteps / totalSteps) * 100;
|
|
44
|
+
return {
|
|
45
|
+
[UserDetailType.Overview]: {
|
|
46
|
+
score: toPositiveWholeNumber(score),
|
|
47
|
+
completedSteps,
|
|
48
|
+
totalSteps,
|
|
49
|
+
},
|
|
50
|
+
[UserDetailType.General]: {
|
|
51
|
+
score: toPositiveWholeNumber((generalCompletedSteps / generalTotalSteps) * 100),
|
|
52
|
+
completedSteps: generalCompletedSteps,
|
|
53
|
+
totalSteps: generalTotalSteps,
|
|
54
|
+
},
|
|
55
|
+
[UserDetailType.WorkExperiences]: {
|
|
56
|
+
score: toPositiveWholeNumber(workExperiencesCompleted * 100),
|
|
57
|
+
completedSteps: workExperiencesCompleted,
|
|
58
|
+
totalSteps: 1,
|
|
59
|
+
},
|
|
60
|
+
[UserDetailType.Educations]: {
|
|
61
|
+
score: toPositiveWholeNumber(educationsCompleted * 100),
|
|
62
|
+
completedSteps: educationsCompleted,
|
|
63
|
+
totalSteps: 1,
|
|
64
|
+
},
|
|
65
|
+
[UserDetailType.Projects]: {
|
|
66
|
+
score: toPositiveWholeNumber(projectsCompleted * 100),
|
|
67
|
+
completedSteps: projectsCompleted,
|
|
68
|
+
totalSteps: 1,
|
|
69
|
+
},
|
|
70
|
+
[UserDetailType.Skills]: {
|
|
71
|
+
score: toPositiveWholeNumber(skillsCompleted * 100),
|
|
72
|
+
completedSteps: skillsCompleted,
|
|
73
|
+
totalSteps: 1,
|
|
74
|
+
},
|
|
75
|
+
[UserDetailType.Languages]: {
|
|
76
|
+
score: toPositiveWholeNumber(languagesCompleted * 100),
|
|
77
|
+
completedSteps: languagesCompleted,
|
|
78
|
+
totalSteps: 1,
|
|
79
|
+
},
|
|
80
|
+
[UserDetailType.Interests]: {
|
|
81
|
+
score: toPositiveWholeNumber(interestsCompleted * 100),
|
|
82
|
+
completedSteps: interestsCompleted,
|
|
83
|
+
totalSteps: 1,
|
|
84
|
+
},
|
|
85
|
+
[UserDetailType.Certifications]: {
|
|
86
|
+
score: toPositiveWholeNumber(certificationsCompleted * 100),
|
|
87
|
+
completedSteps: certificationsCompleted,
|
|
88
|
+
totalSteps: 1,
|
|
89
|
+
},
|
|
90
|
+
[UserDetailType.SocialAccounts]: {
|
|
91
|
+
score: toPositiveWholeNumber(socialAccountsCompleted * 100),
|
|
92
|
+
completedSteps: socialAccountsCompleted,
|
|
93
|
+
totalSteps: 1,
|
|
94
|
+
},
|
|
95
|
+
[UserDetailType.AdditionalInfo]: {
|
|
96
|
+
score: toPositiveWholeNumber(additionalInfoCompleted * 100),
|
|
97
|
+
completedSteps: additionalInfoCompleted,
|
|
98
|
+
totalSteps: 1,
|
|
99
|
+
},
|
|
39
100
|
};
|
|
40
|
-
|
|
41
|
-
const fieldSchema = schemaFields[key];
|
|
42
|
-
if (!fieldSchema)
|
|
43
|
-
continue;
|
|
44
|
-
const currentPath = prefix ? `${prefix}.${key}` : key;
|
|
45
|
-
processField(key, fieldSchema, currentPath);
|
|
46
|
-
}
|
|
47
|
-
return extractedFields;
|
|
48
|
-
};
|
|
49
|
-
export {};
|
|
50
|
-
// const getValueByPath = (data: any, path: string) => {
|
|
51
|
-
// const parts = path.replace("[]", "").split(".");
|
|
52
|
-
// return parts.reduce((acc, part) => {
|
|
53
|
-
// if (acc === undefined || acc === null) return undefined;
|
|
54
|
-
// const match = part.match(/^(\d+)$/);
|
|
55
|
-
// if (match && match[1]) {
|
|
56
|
-
// const index = parseInt(match[1]);
|
|
57
|
-
// return Array.isArray(acc) ? acc[index] : undefined;
|
|
58
|
-
// }
|
|
59
|
-
// return acc[part];
|
|
60
|
-
// }, data);
|
|
61
|
-
// };
|
|
62
|
-
// export const getCompletenessScore = <T>(
|
|
63
|
-
// schema: any,
|
|
64
|
-
// data: T | T[],
|
|
65
|
-
// options: CompletenessOptions = { includeOptionals: false }
|
|
66
|
-
// ): CompletenessScore => {
|
|
67
|
-
// const { includeOptionals = false, emptyArrayScore } = options;
|
|
68
|
-
// if (Array.isArray(data)) {
|
|
69
|
-
// if (data.length === 0) {
|
|
70
|
-
// return {
|
|
71
|
-
// score: emptyArrayScore === "perfect" ? 100 : 0,
|
|
72
|
-
// completedSteps: 0,
|
|
73
|
-
// totalSteps: 0,
|
|
74
|
-
// children: [],
|
|
75
|
-
// };
|
|
76
|
-
// }
|
|
77
|
-
// const children = data.map((item) =>
|
|
78
|
-
// getCompletenessScore(schema, item, options)
|
|
79
|
-
// );
|
|
80
|
-
// const contentScore =
|
|
81
|
-
// children.reduce((sum, child) => sum + child.score, 0) / children.length;
|
|
82
|
-
// return {
|
|
83
|
-
// score: Math.round(contentScore),
|
|
84
|
-
// completedSteps: children.reduce((sum, c) => sum + c.completedSteps, 0),
|
|
85
|
-
// totalSteps: children.reduce((sum, c) => sum + c.totalSteps, 0),
|
|
86
|
-
// children,
|
|
87
|
-
// };
|
|
88
|
-
// }
|
|
89
|
-
// const fields = extractFields(schema, "", includeOptionals);
|
|
90
|
-
// const requiredFields = fields.filter((f) => f.required);
|
|
91
|
-
// const totalSteps = includeOptionals ? fields.length : requiredFields.length;
|
|
92
|
-
// let completedSteps = 0;
|
|
93
|
-
// const meta = {
|
|
94
|
-
// steps: fields.map((f) => f.key),
|
|
95
|
-
// completed: [] as string[],
|
|
96
|
-
// incomplete: [] as string[],
|
|
97
|
-
// };
|
|
98
|
-
// fields.forEach(({ key, required }) => {
|
|
99
|
-
// const value = getValueByPath(data, key);
|
|
100
|
-
// const exists = value !== undefined && value !== null && value !== "";
|
|
101
|
-
// if (exists) {
|
|
102
|
-
// meta.completed.push(key);
|
|
103
|
-
// if (includeOptionals || required) completedSteps++;
|
|
104
|
-
// } else {
|
|
105
|
-
// if (includeOptionals || required) meta.incomplete.push(key);
|
|
106
|
-
// }
|
|
107
|
-
// });
|
|
108
|
-
// const score =
|
|
109
|
-
// totalSteps > 0 ? Math.floor((completedSteps / totalSteps) * 100) : 100;
|
|
110
|
-
// return {
|
|
111
|
-
// score,
|
|
112
|
-
// completedSteps: includeOptionals
|
|
113
|
-
// ? completedSteps
|
|
114
|
-
// : Math.min(completedSteps, requiredFields.length),
|
|
115
|
-
// totalSteps,
|
|
116
|
-
// meta,
|
|
117
|
-
// };
|
|
118
|
-
// };
|
|
101
|
+
}
|
package/dist/esm/user/utils.d.ts
CHANGED
|
@@ -1,3 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prepares a user profile for vector embedding by creating a semantic narrative.
|
|
3
|
+
* Mirrors prepareJobForEmbedding() — same "Label: Value" format for Voyage AI.
|
|
4
|
+
*
|
|
5
|
+
* Strategy:
|
|
6
|
+
* 1. Core identity (headline + location)
|
|
7
|
+
* 2. About me (intent/personality signal)
|
|
8
|
+
* 3. Flattened structured data (skills, experience, education)
|
|
9
|
+
*/
|
|
10
|
+
export declare function prepareUserForEmbedding(user: {
|
|
11
|
+
headline?: string;
|
|
12
|
+
aboutMe?: string;
|
|
13
|
+
location?: {
|
|
14
|
+
city?: string;
|
|
15
|
+
stateCode?: string;
|
|
16
|
+
state?: string;
|
|
17
|
+
country?: string;
|
|
18
|
+
};
|
|
19
|
+
skills?: Array<{
|
|
20
|
+
name: string;
|
|
21
|
+
}>;
|
|
22
|
+
experienceLevel?: string;
|
|
23
|
+
workExperiences?: Array<{
|
|
24
|
+
title?: string;
|
|
25
|
+
company?: string;
|
|
26
|
+
}>;
|
|
27
|
+
educations?: Array<{
|
|
28
|
+
degree?: string;
|
|
29
|
+
fieldOfStudy?: string;
|
|
30
|
+
institution?: string;
|
|
31
|
+
}>;
|
|
32
|
+
languages?: Array<{
|
|
33
|
+
name: string;
|
|
34
|
+
}>;
|
|
35
|
+
}): string;
|
|
1
36
|
export declare const parseName: (name: string | {
|
|
2
37
|
first: string;
|
|
3
38
|
last?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/user/utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE;WAAvB,MAAM;WAAS,MAAM;CAWtE,CAAC"}
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/user/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE;IAC5C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACnF,MAAM,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACjC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,eAAe,CAAC,EAAE,KAAK,CAAC;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC9D,UAAU,CAAC,EAAE,KAAK,CAAC;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACrF,SAAS,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACrC,GAAG,MAAM,CA8CT;AAED,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE;WAAvB,MAAM;WAAS,MAAM;CAWtE,CAAC"}
|
package/dist/esm/user/utils.js
CHANGED
|
@@ -1,3 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prepares a user profile for vector embedding by creating a semantic narrative.
|
|
3
|
+
* Mirrors prepareJobForEmbedding() — same "Label: Value" format for Voyage AI.
|
|
4
|
+
*
|
|
5
|
+
* Strategy:
|
|
6
|
+
* 1. Core identity (headline + location)
|
|
7
|
+
* 2. About me (intent/personality signal)
|
|
8
|
+
* 3. Flattened structured data (skills, experience, education)
|
|
9
|
+
*/
|
|
10
|
+
export function prepareUserForEmbedding(user) {
|
|
11
|
+
const headline = user.headline?.trim() || '';
|
|
12
|
+
const about = user.aboutMe?.replace(/\n/g, ' ').trim() || '';
|
|
13
|
+
const locationParts = [
|
|
14
|
+
user.location?.city,
|
|
15
|
+
user.location?.stateCode || user.location?.state,
|
|
16
|
+
user.location?.country,
|
|
17
|
+
].filter(Boolean);
|
|
18
|
+
const location = locationParts.join(', ');
|
|
19
|
+
const skillsList = user.skills
|
|
20
|
+
?.map((s) => s.name.toLowerCase())
|
|
21
|
+
.filter(Boolean)
|
|
22
|
+
.join(', ') || '';
|
|
23
|
+
const experienceList = user.workExperiences
|
|
24
|
+
?.map((w) => [w.title, w.company].filter(Boolean).join(' at '))
|
|
25
|
+
.filter(Boolean)
|
|
26
|
+
.join('; ') || '';
|
|
27
|
+
const educationList = user.educations
|
|
28
|
+
?.map((e) => [e.degree, e.fieldOfStudy, e.institution ? `at ${e.institution}` : '']
|
|
29
|
+
.filter(Boolean)
|
|
30
|
+
.join(' '))
|
|
31
|
+
.filter(Boolean)
|
|
32
|
+
.join('; ') || '';
|
|
33
|
+
const languagesList = user.languages
|
|
34
|
+
?.map((l) => l.name)
|
|
35
|
+
.filter(Boolean)
|
|
36
|
+
.join(', ') || '';
|
|
37
|
+
const parts = [];
|
|
38
|
+
if (headline)
|
|
39
|
+
parts.push(`Headline: ${headline}`);
|
|
40
|
+
if (about)
|
|
41
|
+
parts.push(`About: ${about}`);
|
|
42
|
+
if (skillsList)
|
|
43
|
+
parts.push(`Skills: ${skillsList}`);
|
|
44
|
+
if (location)
|
|
45
|
+
parts.push(`Location: ${location}`);
|
|
46
|
+
if (user.experienceLevel)
|
|
47
|
+
parts.push(`Level: ${user.experienceLevel}`);
|
|
48
|
+
if (experienceList)
|
|
49
|
+
parts.push(`Experience: ${experienceList}`);
|
|
50
|
+
if (educationList)
|
|
51
|
+
parts.push(`Education: ${educationList}`);
|
|
52
|
+
if (languagesList)
|
|
53
|
+
parts.push(`Languages: ${languagesList}`);
|
|
54
|
+
return parts.join('. ').replace(/\s\s+/g, ' ').trim();
|
|
55
|
+
}
|
|
1
56
|
export const parseName = (name) => {
|
|
2
57
|
if (typeof name === "string") {
|
|
3
58
|
const nameParts = name.trim().split(/\s+/); // Split by spaces, ensuring no extra whitespace
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thejob/util",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.26",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"types": "dist/esm/index.d.ts",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"typescript": "^5.7.3"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@thejob/schema": "^1.0.
|
|
37
|
+
"@thejob/schema": "^1.0.97",
|
|
38
38
|
"dayjs": "^1.11.13",
|
|
39
39
|
"mongoose": "^8.11.0",
|
|
40
40
|
"nanoid": "3.3.5",
|