sr-npm 1.7.474 → 1.7.476
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/backend/collectionConsts.js +13 -1
- package/backend/data.js +12 -4
- package/backend/secretsData.js +2 -2
- package/backend/utils.js +9 -16
- package/package.json +1 -1
|
@@ -4,6 +4,7 @@ const COLLECTIONS = {
|
|
|
4
4
|
JOBS: 'Jobs',
|
|
5
5
|
TEMPLATE_TYPE: 'templateType',
|
|
6
6
|
SECRET_MANAGER_MIRROR: 'SecretManagerMirror',
|
|
7
|
+
BRANDS: 'Brands',
|
|
7
8
|
}
|
|
8
9
|
const JOBS_COLLECTION_FIELDS = {
|
|
9
10
|
LOCATION: 'location',
|
|
@@ -20,12 +21,17 @@ const JOBS_COLLECTION_FIELDS = {
|
|
|
20
21
|
IMAGE: 'image',
|
|
21
22
|
APPLY_LINK: 'applyLink',
|
|
22
23
|
REFER_FRIEND_LINK: 'referFriendLink',
|
|
24
|
+
BRAND: 'brand',
|
|
25
|
+
BRAND_REF: 'brandRef',
|
|
23
26
|
}
|
|
24
27
|
const AMOUNT_OF_JOBS_PER_DEPARTMENT_COLLECTION_FIELDS = {
|
|
25
28
|
TITLE: 'title',
|
|
26
29
|
COUNT: 'count',
|
|
27
30
|
IMAGE: 'image',
|
|
28
31
|
}
|
|
32
|
+
const BRANDS_COLLECTION_FIELDS = {
|
|
33
|
+
BRAND: 'brand',
|
|
34
|
+
}
|
|
29
35
|
const CITIES_COLLECTION_FIELDS = {
|
|
30
36
|
TITLE: 'title',
|
|
31
37
|
CITY: 'city',
|
|
@@ -57,9 +63,11 @@ const COLLECTIONS_FIELDS = {
|
|
|
57
63
|
{key:'jobDescription', type: 'OBJECT'},
|
|
58
64
|
{key:'cityText', type: 'TEXT'},
|
|
59
65
|
{key:'applyLink', type: 'URL'},
|
|
60
|
-
{key:'referFriendLink', type: 'URL'},
|
|
66
|
+
{key:'referFriendLink', type: 'URL'},
|
|
67
|
+
{key:'brand', type: 'TEXT'},
|
|
61
68
|
{key:'departmentref', type: 'REFERENCE', typeMetadata: { reference: { referencedCollectionId: COLLECTIONS.AMOUNT_OF_JOBS_PER_DEPARTMENT } } },
|
|
62
69
|
{key:'city', type: 'REFERENCE', typeMetadata: { reference: { referencedCollectionId: COLLECTIONS.CITIES } } },
|
|
70
|
+
{key:'brandRef', type: 'REFERENCE', typeMetadata: { reference: { referencedCollectionId: COLLECTIONS.BRANDS } } },
|
|
63
71
|
{ key: 'image', type: 'IMAGE' },
|
|
64
72
|
],
|
|
65
73
|
TEMPLATE_TYPE: [
|
|
@@ -69,6 +77,9 @@ const COLLECTIONS_FIELDS = {
|
|
|
69
77
|
{key:'tokenName', type: 'TEXT'},
|
|
70
78
|
{key:'tokenValue', type: 'TEXT'},
|
|
71
79
|
],
|
|
80
|
+
BRANDS: [
|
|
81
|
+
{key:'brand', type: 'TEXT'},
|
|
82
|
+
],
|
|
72
83
|
};
|
|
73
84
|
|
|
74
85
|
const TEMPLATE_TYPE = {
|
|
@@ -89,6 +100,7 @@ const COLLECTIONS_FIELDS = {
|
|
|
89
100
|
JOBS_COLLECTION_FIELDS,
|
|
90
101
|
AMOUNT_OF_JOBS_PER_DEPARTMENT_COLLECTION_FIELDS,
|
|
91
102
|
CITIES_COLLECTION_FIELDS,
|
|
103
|
+
BRANDS_COLLECTION_FIELDS,
|
|
92
104
|
TEMPLATE_TYPE,
|
|
93
105
|
TOKEN_NAME,
|
|
94
106
|
};
|
package/backend/data.js
CHANGED
|
@@ -2,10 +2,15 @@ const { items: wixData } = require('@wix/data');
|
|
|
2
2
|
const { fetchPositionsFromSRAPI, fetchJobDescription } = require('./fetchPositionsFromSRAPI');
|
|
3
3
|
const { createCollectionIfMissing } = require('@hisense-staging/velo-npm/backend');
|
|
4
4
|
const { COLLECTIONS, COLLECTIONS_FIELDS,JOBS_COLLECTION_FIELDS,TEMPLATE_TYPE,TOKEN_NAME } = require('./collectionConsts');
|
|
5
|
-
const { chunkedBulkOperation, countJobsPerGivenField, fillCityLocationAndLocationAddress ,prepareToSaveArray,
|
|
5
|
+
const { chunkedBulkOperation, countJobsPerGivenField, fillCityLocationAndLocationAddress ,prepareToSaveArray,normalizeString} = require('./utils');
|
|
6
6
|
const { getAllPositions } = require('./queries');
|
|
7
7
|
const { getCompanyId, getSmartToken } = require('./secretsData');
|
|
8
8
|
|
|
9
|
+
function getBrand(customField) {
|
|
10
|
+
const brand = customField.find(field => field.fieldLabel === 'Brands')?.valueLabel;
|
|
11
|
+
return brand ? normalizeString(brand) : '';
|
|
12
|
+
}
|
|
13
|
+
|
|
9
14
|
function validatePosition(position) {
|
|
10
15
|
if (!position.id) {
|
|
11
16
|
throw new Error('Position id is required');
|
|
@@ -30,7 +35,7 @@ async function saveJobsDataToCMS() {
|
|
|
30
35
|
_id: position.id,
|
|
31
36
|
title: position.name || '',
|
|
32
37
|
department: position.department?.label || 'Other',
|
|
33
|
-
cityText:
|
|
38
|
+
cityText: normalizeString(position.location?.city).trim(),
|
|
34
39
|
location: position.location && Object.keys(position.location).length > 0
|
|
35
40
|
? position.location
|
|
36
41
|
: {
|
|
@@ -46,6 +51,7 @@ async function saveJobsDataToCMS() {
|
|
|
46
51
|
country: position.location?.country || '',
|
|
47
52
|
remote: position.location?.remote || false,
|
|
48
53
|
language: position.language?.label || '',
|
|
54
|
+
brand: getBrand(position.customField),
|
|
49
55
|
jobDescription: null, // Will be filled later
|
|
50
56
|
};
|
|
51
57
|
return basicJob;
|
|
@@ -294,7 +300,8 @@ async function createCollections() {
|
|
|
294
300
|
[createCollectionIfMissing(COLLECTIONS.JOBS, JOBS_COLLECTION_FIELDS.JOBS,{ insert: 'ADMIN', update: 'ADMIN', remove: 'ADMIN', read: 'ANYONE' }),
|
|
295
301
|
createCollectionIfMissing(COLLECTIONS.CITIES, COLLECTIONS_FIELDS.CITIES),
|
|
296
302
|
createCollectionIfMissing(COLLECTIONS.AMOUNT_OF_JOBS_PER_DEPARTMENT, COLLECTIONS_FIELDS.AMOUNT_OF_JOBS_PER_DEPARTMENT),
|
|
297
|
-
createCollectionIfMissing(COLLECTIONS.SECRET_MANAGER_MIRROR, COLLECTIONS_FIELDS.SECRET_MANAGER_MIRROR)
|
|
303
|
+
createCollectionIfMissing(COLLECTIONS.SECRET_MANAGER_MIRROR, COLLECTIONS_FIELDS.SECRET_MANAGER_MIRROR),
|
|
304
|
+
createCollectionIfMissing(COLLECTIONS.BRANDS, COLLECTIONS_FIELDS.BRANDS)
|
|
298
305
|
]);
|
|
299
306
|
console.log("finished creating Collections");
|
|
300
307
|
}
|
|
@@ -312,6 +319,7 @@ async function referenceJobs() {
|
|
|
312
319
|
console.log("Reference jobs");
|
|
313
320
|
await referenceJobsToField({ referenceField: JOBS_COLLECTION_FIELDS.DEPARTMENT_REF, sourceCollection: COLLECTIONS.AMOUNT_OF_JOBS_PER_DEPARTMENT, jobField: JOBS_COLLECTION_FIELDS.DEPARTMENT });
|
|
314
321
|
await referenceJobsToField({ referenceField: JOBS_COLLECTION_FIELDS.CITY, sourceCollection: COLLECTIONS.CITIES, jobField: JOBS_COLLECTION_FIELDS.CITY_TEXT });
|
|
322
|
+
await referenceJobsToField({ referenceField: JOBS_COLLECTION_FIELDS.BRAND_REF, sourceCollection: COLLECTIONS.BRANDS, jobField: JOBS_COLLECTION_FIELDS.BRAND });
|
|
315
323
|
console.log("finished referencing jobs");
|
|
316
324
|
}
|
|
317
325
|
|
|
@@ -374,7 +382,7 @@ async function fillSecretManagerMirror() {
|
|
|
374
382
|
});
|
|
375
383
|
console.log("x-smarttoken inserted into the SecretManagerMirror collection");
|
|
376
384
|
} catch (error) {
|
|
377
|
-
console.
|
|
385
|
+
console.warn("Error with inserting x-smarttoken into the SecretManagerMirror collection:", error);
|
|
378
386
|
}
|
|
379
387
|
}
|
|
380
388
|
|
package/backend/secretsData.js
CHANGED
|
@@ -19,8 +19,8 @@ function getSmartToken() {
|
|
|
19
19
|
.then((secret) => {
|
|
20
20
|
return secret;
|
|
21
21
|
}).catch(async (error) => {
|
|
22
|
-
console.
|
|
23
|
-
console.
|
|
22
|
+
console.warn("Error retrieving secret value: ", error)
|
|
23
|
+
console.warn("Retrying with getTokenFromCMS")
|
|
24
24
|
const secret = await getTokenFromCMS(tokenName);
|
|
25
25
|
return secret
|
|
26
26
|
})
|
package/backend/utils.js
CHANGED
|
@@ -35,7 +35,7 @@ function prepareToSaveArray(jobsPerField, cityLocations, field,citylocationAddre
|
|
|
35
35
|
return Object.entries(jobsPerField).map(([value, amount]) => {
|
|
36
36
|
const loc = cityLocations[value] || {};
|
|
37
37
|
const locAddress = citylocationAddress[value] || {};
|
|
38
|
-
value =
|
|
38
|
+
value = normalizeString(value).trim();
|
|
39
39
|
return {
|
|
40
40
|
title: value,
|
|
41
41
|
_id: value.replace(/\s+/g, ''),
|
|
@@ -48,29 +48,22 @@ function prepareToSaveArray(jobsPerField, cityLocations, field,citylocationAddre
|
|
|
48
48
|
} else {
|
|
49
49
|
return Object.entries(jobsPerField).map(([value, amount]) => ({
|
|
50
50
|
title: value,
|
|
51
|
-
_id:
|
|
51
|
+
_id: normalizeString(value).replace(/&/g, 'and'),
|
|
52
52
|
count: amount,
|
|
53
53
|
}));
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
function
|
|
58
|
-
if (!
|
|
57
|
+
function normalizeString(str) {
|
|
58
|
+
if (!str) return str;
|
|
59
59
|
// Remove accents/diacritics, trim whitespace
|
|
60
|
-
return
|
|
60
|
+
return str
|
|
61
61
|
.normalize('NFD')
|
|
62
62
|
.replace(/\p{Diacritic}/gu, '')
|
|
63
|
-
.
|
|
63
|
+
.replace(/[^A-Za-z0-9-]/g, '')
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
if (!input) return '';
|
|
68
|
-
const withoutDiacritics = String(input)
|
|
69
|
-
.normalize('NFD')
|
|
70
|
-
.replace(/\p{Diacritic}/gu, '');
|
|
71
|
-
const withAnd = withoutDiacritics.replace(/&/g, 'and');
|
|
72
|
-
return withAnd.replace(/[^A-Za-z0-9-]/g, '');
|
|
73
|
-
}
|
|
66
|
+
|
|
74
67
|
|
|
75
68
|
module.exports = {
|
|
76
69
|
chunkedBulkOperation,
|
|
@@ -78,6 +71,6 @@ module.exports = {
|
|
|
78
71
|
countJobsPerGivenField,
|
|
79
72
|
fillCityLocationAndLocationAddress,
|
|
80
73
|
prepareToSaveArray,
|
|
81
|
-
|
|
82
|
-
|
|
74
|
+
normalizeString,
|
|
75
|
+
|
|
83
76
|
};
|