sr-npm 1.7.264 → 1.7.266
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/data.js +2 -28
- package/backend/fetchPositionsFromSRAPI.js +4 -4
- package/backend/secretsData.js +31 -0
- package/package.json +1 -1
package/backend/data.js
CHANGED
|
@@ -2,11 +2,9 @@ const { items: wixData, collections } = 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 } = require('./collectionConsts');
|
|
5
|
-
const { secrets } = require("@wix/secrets");
|
|
6
|
-
const { auth } = require('@wix/essentials');
|
|
7
5
|
const { chunkedBulkOperation, delay, countJobsPerGivenField, fillCityLocationAndLocationAddress ,prepareToSaveArray,normalizeCityName} = require('./utils');
|
|
8
6
|
const { getAllPositions } = require('./queries');
|
|
9
|
-
|
|
7
|
+
const secretsData = require('./secretsData');
|
|
10
8
|
|
|
11
9
|
function validatePosition(position) {
|
|
12
10
|
if (!position.id) {
|
|
@@ -289,36 +287,13 @@ function fetchJobLocation(jobDetails) {
|
|
|
289
287
|
}
|
|
290
288
|
|
|
291
289
|
|
|
292
|
-
function getSmartToken() {
|
|
293
|
-
const elevatedGetSecretValue = auth.elevate(secrets.getSecretValue);
|
|
294
|
-
return elevatedGetSecretValue("x-smarttoken")
|
|
295
|
-
.then((secret) => {
|
|
296
|
-
return secret;
|
|
297
|
-
})
|
|
298
|
-
.catch((error) => {
|
|
299
|
-
console.error(error);
|
|
300
|
-
throw error;
|
|
301
|
-
});
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
function getCompanyId() {
|
|
305
|
-
const elevatedGetSecretValue = auth.elevate(secrets.getSecretValue);
|
|
306
|
-
return elevatedGetSecretValue("companyID")
|
|
307
|
-
.then((secret) => {
|
|
308
|
-
return secret;
|
|
309
|
-
})
|
|
310
|
-
.catch((error) => {
|
|
311
|
-
console.error(error);
|
|
312
|
-
throw error;
|
|
313
|
-
});
|
|
314
|
-
}
|
|
315
290
|
|
|
316
291
|
|
|
317
292
|
async function createApiKeyCollectionAndFillIt() {
|
|
318
293
|
console.log("Creating ApiKey collection and filling it with the smart token");
|
|
319
294
|
await createCollectionIfMissing(COLLECTIONS.API_KEY, COLLECTIONS_FIELDS.API_KEY,null,'singleItem');
|
|
320
295
|
console.log("Getting the smart token");
|
|
321
|
-
const token = await getSmartToken();
|
|
296
|
+
const token = await secretsData.getSmartToken();
|
|
322
297
|
console.log("token is : ", token);
|
|
323
298
|
console.log("Inserting the smart token into the ApiKey collection");
|
|
324
299
|
await wixData.insert(COLLECTIONS.API_KEY, {
|
|
@@ -389,5 +364,4 @@ module.exports = {
|
|
|
389
364
|
aggregateJobsByFieldToCMS,
|
|
390
365
|
referenceJobsToField,
|
|
391
366
|
createApiKeyCollectionAndFillIt,
|
|
392
|
-
getCompanyId
|
|
393
367
|
};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
const { fetch } = require('wix-fetch');
|
|
2
2
|
const { items: wixData } = require('@wix/data');
|
|
3
3
|
const { COLLECTIONS } = require('./collectionConsts');
|
|
4
|
-
const
|
|
4
|
+
const secretsData = require('./secretsData');
|
|
5
5
|
async function makeSmartRecruitersRequest(path,token) {
|
|
6
6
|
const baseUrl = 'https://api.smartrecruiters.com'; // PROD
|
|
7
7
|
// const baseUrl = 'https://bayank2.wixstudio.com/my-site-3//_functions'; // TEST
|
|
8
8
|
const fullUrl = `${baseUrl}${path}`;
|
|
9
9
|
|
|
10
|
-
//console.log(`Making request to: ${fullUrl}`);
|
|
10
|
+
//console.log(`Making request to: ${fullUrl}`);
|
|
11
11
|
try {
|
|
12
12
|
const response = await fetch(fullUrl, {
|
|
13
13
|
method: 'GET',
|
|
@@ -38,7 +38,7 @@ async function fetchPositionsFromSRAPI() {
|
|
|
38
38
|
let page = 0;
|
|
39
39
|
const MAX_PAGES = 30 // Safety limit to prevent infinite loops
|
|
40
40
|
const token = await getSmartTokenFromCMS();
|
|
41
|
-
const companyId=await getCompanyId();
|
|
41
|
+
const companyId = await secretsData.getCompanyId();
|
|
42
42
|
console.log('Starting to fetch all positions with pagination...');
|
|
43
43
|
let offset=0;
|
|
44
44
|
|
|
@@ -47,7 +47,7 @@ async function fetchPositionsFromSRAPI() {
|
|
|
47
47
|
page++;
|
|
48
48
|
|
|
49
49
|
// Build the API path - first request has no page parameter, subsequent use nextPageId
|
|
50
|
-
let apiPath = `/v1/companies/${companyId}/postings?offset=${offset}`;
|
|
50
|
+
let apiPath = `/v1/companies/${companyId.value}/postings?offset=${offset}`;
|
|
51
51
|
if (nextPageId) {
|
|
52
52
|
apiPath += `&pageId=${nextPageId}`;
|
|
53
53
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const { secrets } = require("@wix/secrets");
|
|
2
|
+
const { auth } = require('@wix/essentials');
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
function getSmartToken() {
|
|
6
|
+
const elevatedGetSecretValue = auth.elevate(secrets.getSecretValue);
|
|
7
|
+
return elevatedGetSecretValue("x-smarttoken")
|
|
8
|
+
.then((secret) => {
|
|
9
|
+
return secret;
|
|
10
|
+
})
|
|
11
|
+
.catch((error) => {
|
|
12
|
+
console.error(error);
|
|
13
|
+
throw error;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function getCompanyId() {
|
|
18
|
+
const elevatedGetSecretValue = auth.elevate(secrets.getSecretValue);
|
|
19
|
+
return elevatedGetSecretValue("companyID")
|
|
20
|
+
.then((secret) => {
|
|
21
|
+
return secret;
|
|
22
|
+
})
|
|
23
|
+
.catch((error) => {
|
|
24
|
+
console.error(error);
|
|
25
|
+
throw error;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
module.exports = {
|
|
29
|
+
getSmartToken,
|
|
30
|
+
getCompanyId
|
|
31
|
+
};
|