sr-npm 1.7.402 → 1.7.404
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 +9 -0
- package/backend/consts.js +2 -2
- package/backend/data.js +25 -3
- package/backend/fetchPositionsFromSRAPI.js +26 -5
- package/backend/secretsData.js +10 -2
- package/package.json +1 -1
|
@@ -3,6 +3,8 @@ const COLLECTIONS = {
|
|
|
3
3
|
CITIES: 'cities',
|
|
4
4
|
JOBS: 'Jobs',
|
|
5
5
|
COMPANY_ID: 'CompanyId',
|
|
6
|
+
API_KEY: 'ApiKey',
|
|
7
|
+
TEMPLATE_TYPE: 'templateType',
|
|
6
8
|
}
|
|
7
9
|
const JOBS_COLLECTION_FIELDS = {
|
|
8
10
|
LOCATION: 'location',
|
|
@@ -18,6 +20,7 @@ const JOBS_COLLECTION_FIELDS = {
|
|
|
18
20
|
CITY_TEXT: 'cityText',
|
|
19
21
|
IMAGE: 'image',
|
|
20
22
|
APPLY_LINK: 'applyLink',
|
|
23
|
+
REFER_FRIEND_LINK: 'referFriendLink',
|
|
21
24
|
}
|
|
22
25
|
const AMOUNT_OF_JOBS_PER_DEPARTMENT_COLLECTION_FIELDS = {
|
|
23
26
|
TITLE: 'title',
|
|
@@ -63,6 +66,12 @@ const COLLECTIONS_FIELDS = {
|
|
|
63
66
|
COMPANY_ID: [
|
|
64
67
|
{key:'companyId', type: 'TEXT'},
|
|
65
68
|
],
|
|
69
|
+
API_KEY: [
|
|
70
|
+
{key:'token', type: 'TEXT'},
|
|
71
|
+
],
|
|
72
|
+
TEMPLATE_TYPE: [
|
|
73
|
+
{key:'templateType', type: 'TEXT'},
|
|
74
|
+
],
|
|
66
75
|
};
|
|
67
76
|
|
|
68
77
|
|
package/backend/consts.js
CHANGED
|
@@ -65,8 +65,8 @@ const TASKS = {
|
|
|
65
65
|
},
|
|
66
66
|
[TASKS_NAMES.SYNC_JOBS_FAST]: {
|
|
67
67
|
name: TASKS_NAMES.SYNC_JOBS_FAST,
|
|
68
|
-
getIdentifier:
|
|
69
|
-
process:syncJobsFast,
|
|
68
|
+
getIdentifier:task=>task.data,
|
|
69
|
+
process:task=>syncJobsFast(task),
|
|
70
70
|
shouldSkipCheck:()=>false,
|
|
71
71
|
estimatedDurationSec:60
|
|
72
72
|
}
|
package/backend/data.js
CHANGED
|
@@ -4,7 +4,7 @@ const { createCollectionIfMissing } = require('@hisense-staging/velo-npm/backend
|
|
|
4
4
|
const { COLLECTIONS, COLLECTIONS_FIELDS,JOBS_COLLECTION_FIELDS } = require('./collectionConsts');
|
|
5
5
|
const { chunkedBulkOperation, countJobsPerGivenField, fillCityLocationAndLocationAddress ,prepareToSaveArray,normalizeCityName} = require('./utils');
|
|
6
6
|
const { getAllPositions } = require('./queries');
|
|
7
|
-
const { getCompanyId } = require('./secretsData');
|
|
7
|
+
const { getCompanyId, getSmartToken } = require('./secretsData');
|
|
8
8
|
|
|
9
9
|
function validatePosition(position) {
|
|
10
10
|
if (!position.id) {
|
|
@@ -286,7 +286,27 @@ function fetchJobLocation(jobDetails) {
|
|
|
286
286
|
return jobLocation;
|
|
287
287
|
}
|
|
288
288
|
|
|
289
|
-
|
|
289
|
+
async function createApiKeyCollectionAndFillIt() {
|
|
290
|
+
console.log("Creating ApiKey collection and filling it with the smart token");
|
|
291
|
+
await createCollectionIfMissing(COLLECTIONS.API_KEY, COLLECTIONS_FIELDS.API_KEY,null,'singleItem');
|
|
292
|
+
console.log("Getting the smart token ");
|
|
293
|
+
const token = await getSmartToken();
|
|
294
|
+
console.log("token is : ", token);
|
|
295
|
+
console.log("Inserting the smart token into the ApiKey collection");
|
|
296
|
+
try {
|
|
297
|
+
await wixData.insert(COLLECTIONS.API_KEY, {
|
|
298
|
+
token: token.value
|
|
299
|
+
});
|
|
300
|
+
console.log("Smart token inserted into the ApiKey collection");
|
|
301
|
+
} catch (error) {
|
|
302
|
+
if (error.message.includes("WDE0074: An item with _id [SINGLE_ITEM_ID] already exists")) {
|
|
303
|
+
console.log("Smart token already exists in the ApiKey collection");
|
|
304
|
+
}
|
|
305
|
+
else {
|
|
306
|
+
throw error;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
290
310
|
|
|
291
311
|
|
|
292
312
|
async function createCompanyIdCollectionAndFillIt() {
|
|
@@ -339,9 +359,11 @@ async function referenceJobs() {
|
|
|
339
359
|
console.log("finished referencing jobs");
|
|
340
360
|
}
|
|
341
361
|
|
|
342
|
-
async function syncJobsFast() {
|
|
362
|
+
async function syncJobsFast(templateType) {
|
|
363
|
+
console.log("templateType is : ", templateType);
|
|
343
364
|
console.log("Syncing jobs fast");
|
|
344
365
|
await createCompanyIdCollectionAndFillIt();
|
|
366
|
+
await createApiKeyCollectionAndFillIt();
|
|
345
367
|
await createCollections();
|
|
346
368
|
await clearCollections();
|
|
347
369
|
console.log("saving jobs data to CMS");
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const { fetch } = require('wix-fetch');
|
|
2
2
|
const { items: wixData } = require('@wix/data');
|
|
3
3
|
const { COLLECTIONS } = require('./collectionConsts');
|
|
4
|
-
|
|
5
|
-
async function makeSmartRecruitersRequest(path) {
|
|
4
|
+
|
|
5
|
+
async function makeSmartRecruitersRequest(path,smartToken) {
|
|
6
6
|
const baseUrl = 'https://api.smartrecruiters.com';
|
|
7
7
|
const fullUrl = `${baseUrl}${path}`;
|
|
8
8
|
|
|
@@ -12,7 +12,8 @@ async function makeSmartRecruitersRequest(path) {
|
|
|
12
12
|
headers: {
|
|
13
13
|
'Accept-Language': 'en',
|
|
14
14
|
'accept': 'application/json',
|
|
15
|
-
'Cookie': 'AWSALB=GYltFw3fLKortMxHR5vIOT1CuUROyhWNIX/qL8ZnPl1/8mhOcnIsBKYslzmNJPEzSy/jvNbO+6tXpH8yqcpQJagYt57MhbKlLqTSzoNq1G/w7TjOxPGR3UTdXW0d; AWSALBCORS=GYltFw3fLKortMxHR5vIOT1CuUROyhWNIX/qL8ZnPl1/8mhOcnIsBKYslzmNJPEzSy/jvNbO+6tXpH8yqcpQJagYt57MhbKlLqTSzoNq1G/w7TjOxPGR3UTdXW0d'
|
|
15
|
+
'Cookie': 'AWSALB=GYltFw3fLKortMxHR5vIOT1CuUROyhWNIX/qL8ZnPl1/8mhOcnIsBKYslzmNJPEzSy/jvNbO+6tXpH8yqcpQJagYt57MhbKlLqTSzoNq1G/w7TjOxPGR3UTdXW0d; AWSALBCORS=GYltFw3fLKortMxHR5vIOT1CuUROyhWNIX/qL8ZnPl1/8mhOcnIsBKYslzmNJPEzSy/jvNbO+6tXpH8yqcpQJagYt57MhbKlLqTSzoNq1G/w7TjOxPGR3UTdXW0d',
|
|
16
|
+
'x-smarttoken': smartToken
|
|
16
17
|
}
|
|
17
18
|
});
|
|
18
19
|
|
|
@@ -34,6 +35,8 @@ async function fetchPositionsFromSRAPI() {
|
|
|
34
35
|
let page = 0;
|
|
35
36
|
const MAX_PAGES = 30 // Safety limit to prevent infinite loops
|
|
36
37
|
const companyId = await getCompanyIdFromCMS();
|
|
38
|
+
const templateType = await getTemplateTypeFromCMS();
|
|
39
|
+
const smartToken = templateType==='INTERNAL' ? await getSmartTokenFromCMS():undefined;
|
|
37
40
|
console.log('Starting to fetch all positions with pagination...');
|
|
38
41
|
let offset=0;
|
|
39
42
|
|
|
@@ -42,10 +45,10 @@ async function fetchPositionsFromSRAPI() {
|
|
|
42
45
|
page++;
|
|
43
46
|
|
|
44
47
|
// Build the API path - first request has no page parameter, subsequent use nextPageId
|
|
45
|
-
const apiPath = `/v1/companies/${companyId}/postings?offset=${offset}`;
|
|
48
|
+
const apiPath = `/v1/companies/${companyId}/postings?offset=${offset}&destination=${templateType}`;
|
|
46
49
|
|
|
47
50
|
console.log(`Fetching page ${page} with path: ${apiPath}`);
|
|
48
|
-
const response = await makeSmartRecruitersRequest(apiPath);
|
|
51
|
+
const response = await makeSmartRecruitersRequest(apiPath,smartToken);
|
|
49
52
|
|
|
50
53
|
// Add positions from this page to our collection
|
|
51
54
|
if (response.content && Array.isArray(response.content)) {
|
|
@@ -108,6 +111,24 @@ async function getCompanyIdFromCMS() {
|
|
|
108
111
|
}
|
|
109
112
|
}
|
|
110
113
|
|
|
114
|
+
async function getSmartTokenFromCMS() {
|
|
115
|
+
const result = await wixData.query(COLLECTIONS.API_KEY).limit(1).find();
|
|
116
|
+
if (result.items.length > 0) {
|
|
117
|
+
return result.items[0].token;
|
|
118
|
+
} else {
|
|
119
|
+
throw new Error('[getSmartTokenFromCMS], No smarttoken found');
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
async function getTemplateTypeFromCMS() {
|
|
123
|
+
console.log("COLLECTIONS.TEMPLATE_TYPE is ",COLLECTIONS.TEMPLATE_TYPE)
|
|
124
|
+
const result = await wixData.query(COLLECTIONS.TEMPLATE_TYPE).limit(1).find();
|
|
125
|
+
if (result.items.length > 0) {
|
|
126
|
+
return result.items[0].templateType;
|
|
127
|
+
} else {
|
|
128
|
+
throw new Error('[getTemplateTypeFromCMS], No templateType found');
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
111
132
|
|
|
112
133
|
module.exports = {
|
|
113
134
|
fetchPositionsFromSRAPI,
|
package/backend/secretsData.js
CHANGED
|
@@ -2,7 +2,14 @@ const { secrets } = require("@wix/secrets");
|
|
|
2
2
|
const { auth } = require('@wix/essentials');
|
|
3
3
|
|
|
4
4
|
const getSecretValue = auth.elevate(secrets.getSecretValue);
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
function getSmartToken() {
|
|
7
|
+
return getSecretValue("x-smarttoken")
|
|
8
|
+
.then((secret) => {
|
|
9
|
+
return secret;
|
|
10
|
+
})
|
|
11
|
+
}
|
|
12
|
+
|
|
6
13
|
function getCompanyId() {
|
|
7
14
|
return getSecretValue("companyID")
|
|
8
15
|
.then((secret) => {
|
|
@@ -10,5 +17,6 @@ const getSecretValue = auth.elevate(secrets.getSecretValue);
|
|
|
10
17
|
})
|
|
11
18
|
}
|
|
12
19
|
module.exports = {
|
|
13
|
-
getCompanyId
|
|
20
|
+
getCompanyId,
|
|
21
|
+
getSmartToken
|
|
14
22
|
};
|