sr-npm 1.7.411 → 1.7.413
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.
|
@@ -2,7 +2,7 @@ const { fetch } = require('wix-fetch');
|
|
|
2
2
|
const { items: wixData } = require('@wix/data');
|
|
3
3
|
const { COLLECTIONS } = require('./collectionConsts');
|
|
4
4
|
|
|
5
|
-
async function makeSmartRecruitersRequest(path
|
|
5
|
+
async function makeSmartRecruitersRequest(path) {
|
|
6
6
|
const baseUrl = 'https://api.smartrecruiters.com';
|
|
7
7
|
const fullUrl = `${baseUrl}${path}`;
|
|
8
8
|
|
|
@@ -14,7 +14,9 @@ async function makeSmartRecruitersRequest(path,templateTYpe) {
|
|
|
14
14
|
'Cookie': 'AWSALB=GYltFw3fLKortMxHR5vIOT1CuUROyhWNIX/qL8ZnPl1/8mhOcnIsBKYslzmNJPEzSy/jvNbO+6tXpH8yqcpQJagYt57MhbKlLqTSzoNq1G/w7TjOxPGR3UTdXW0d; AWSALBCORS=GYltFw3fLKortMxHR5vIOT1CuUROyhWNIX/qL8ZnPl1/8mhOcnIsBKYslzmNJPEzSy/jvNbO+6tXpH8yqcpQJagYt57MhbKlLqTSzoNq1G/w7TjOxPGR3UTdXW0d'
|
|
15
15
|
};
|
|
16
16
|
//here is the only place where we check templateType
|
|
17
|
+
const templateType = await getTemplateTypeFromCMS();
|
|
17
18
|
if (templateType === 'INTERNAL') {
|
|
19
|
+
const smartToken = await getSmartTokenFromCMS();
|
|
18
20
|
headers['x-smarttoken'] = smartToken;
|
|
19
21
|
}
|
|
20
22
|
const response = await fetch(fullUrl, {
|
|
@@ -39,7 +41,7 @@ async function fetchPositionsFromSRAPI() {
|
|
|
39
41
|
let totalFound = 0;
|
|
40
42
|
let page = 0;
|
|
41
43
|
const MAX_PAGES = 30 // Safety limit to prevent infinite loops
|
|
42
|
-
const {companyId,templateType
|
|
44
|
+
const {companyId,templateType} = await getApiKeys();
|
|
43
45
|
console.log('Starting to fetch all positions with pagination...');
|
|
44
46
|
let offset=0;
|
|
45
47
|
|
|
@@ -50,7 +52,7 @@ async function fetchPositionsFromSRAPI() {
|
|
|
50
52
|
const apiPath = `/v1/companies/${companyId}/postings?offset=${offset}&destination=${templateType}`;
|
|
51
53
|
|
|
52
54
|
console.log(`Fetching page ${page} with path: ${apiPath}`);
|
|
53
|
-
const response = await makeSmartRecruitersRequest(apiPath
|
|
55
|
+
const response = await makeSmartRecruitersRequest(apiPath);
|
|
54
56
|
|
|
55
57
|
// Add positions from this page to our collection
|
|
56
58
|
if (response.content && Array.isArray(response.content)) {
|
|
@@ -100,23 +102,23 @@ async function fetchPositionsFromSRAPI() {
|
|
|
100
102
|
}
|
|
101
103
|
|
|
102
104
|
async function fetchJobDescription(jobId) {
|
|
103
|
-
const {companyId
|
|
104
|
-
return await makeSmartRecruitersRequest(`/v1/companies/${companyId}/postings/${jobId}
|
|
105
|
+
const {companyId} = await getApiKeys();
|
|
106
|
+
return await makeSmartRecruitersRequest(`/v1/companies/${companyId}/postings/${jobId}`);
|
|
105
107
|
}
|
|
106
108
|
|
|
107
109
|
async function getCompanyIdFromCMS() {
|
|
108
|
-
const result = await wixData.query(COLLECTIONS.
|
|
110
|
+
const result = await wixData.query(COLLECTIONS.SECRET_MANAGER_MIRROR).eq('tokenName','companyId').find();
|
|
109
111
|
if (result.items.length > 0) {
|
|
110
|
-
return result.items[0].
|
|
112
|
+
return result.items[0].tokenValue;
|
|
111
113
|
} else {
|
|
112
114
|
throw new Error('[getCompanyIdFromCMS], No companyId found');
|
|
113
115
|
}
|
|
114
116
|
}
|
|
115
117
|
|
|
116
118
|
async function getSmartTokenFromCMS() {
|
|
117
|
-
const result = await wixData.query(COLLECTIONS.
|
|
119
|
+
const result = await wixData.query(COLLECTIONS.SECRET_MANAGER_MIRROR).eq('tokenName','x-smarttoken').find();
|
|
118
120
|
if (result.items.length > 0) {
|
|
119
|
-
return result.items[0].
|
|
121
|
+
return result.items[0].tokenValue;
|
|
120
122
|
} else {
|
|
121
123
|
throw new Error('[getSmartTokenFromCMS], No smarttoken found');
|
|
122
124
|
}
|
|
@@ -134,8 +136,7 @@ async function getTemplateTypeFromCMS() {
|
|
|
134
136
|
async function getApiKeys() {
|
|
135
137
|
const companyId = await getCompanyIdFromCMS();
|
|
136
138
|
const templateType = await getTemplateTypeFromCMS();
|
|
137
|
-
|
|
138
|
-
return {companyId,templateType,smartToken};
|
|
139
|
+
return {companyId,templateType};
|
|
139
140
|
}
|
|
140
141
|
|
|
141
142
|
module.exports = {
|