sr-npm 1.7.18 → 1.7.20

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.
@@ -1,9 +1,11 @@
1
1
  const { fetch } = require('wix-fetch');
2
+ const { items: wixData } = require('@wix/data');
2
3
 
3
- async function makeSmartRecruitersRequest(path) {
4
+ async function makeSmartRecruitersRequest(path,token) {
4
5
  // const baseUrl = 'https://api.smartrecruiters.com'; // PROD
5
6
  const baseUrl = 'https://aoxley54.wixstudio.com/external-template/_functions'; // TEST
6
7
  const fullUrl = `${baseUrl}${path}`;
8
+
7
9
  //console.log(`Making request to: ${fullUrl}`);
8
10
  try {
9
11
  const response = await fetch(fullUrl, {
@@ -11,7 +13,7 @@ async function makeSmartRecruitersRequest(path) {
11
13
  headers: {
12
14
  'Accept-Language': 'en',
13
15
  'accept': 'application/json',
14
- 'x-smarttoken': 'DCRA1-1d30ea5fe9be42d9b9ae94ff933ebef5',
16
+ 'x-smarttoken': token,
15
17
  'Cookie': 'AWSALB=GYltFw3fLKortMxHR5vIOT1CuUROyhWNIX/qL8ZnPl1/8mhOcnIsBKYslzmNJPEzSy/jvNbO+6tXpH8yqcpQJagYt57MhbKlLqTSzoNq1G/w7TjOxPGR3UTdXW0d; AWSALBCORS=GYltFw3fLKortMxHR5vIOT1CuUROyhWNIX/qL8ZnPl1/8mhOcnIsBKYslzmNJPEzSy/jvNbO+6tXpH8yqcpQJagYt57MhbKlLqTSzoNq1G/w7TjOxPGR3UTdXW0d'
16
18
  }
17
19
  });
@@ -34,6 +36,7 @@ async function fetchPositionsFromSRAPI() {
34
36
  let nextPageId = null; // Start with no page ID for the first request
35
37
  let pageCount = 0;
36
38
  const MAX_PAGES = 30 // Safety limit to prevent infinite loops
39
+ const token = await getSmartTokenFromCMS();
37
40
 
38
41
  console.log('Starting to fetch all positions with pagination...');
39
42
 
@@ -48,7 +51,7 @@ async function fetchPositionsFromSRAPI() {
48
51
  }
49
52
 
50
53
  console.log(`Fetching page ${pageCount} with path: ${apiPath}`);
51
- const response = await makeSmartRecruitersRequest(apiPath);
54
+ const response = await makeSmartRecruitersRequest(apiPath,token);
52
55
 
53
56
  // Add positions from this page to our collection
54
57
  if (response.content && Array.isArray(response.content)) {
@@ -108,6 +111,15 @@ async function fetchJobDescription(jobId) {
108
111
  return await makeSmartRecruitersRequest(`/jobs/${jobId}`);
109
112
  }
110
113
 
114
+ async function getSmartTokenFromCMS() {
115
+ const result = await wixData.query("ApiKey").limit(1).find();
116
+ if (result.items.length > 0) {
117
+ return result.items[0].token; // This is your string token
118
+ } else {
119
+ return null; // No token found
120
+ }
121
+ }
122
+
111
123
 
112
124
  module.exports = {
113
125
  fetchPositionsFromSRAPI,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sr-npm",
3
- "version": "1.7.18",
3
+ "version": "1.7.20",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {