sr-npm 1.7.409 → 1.7.411

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,9 +2,8 @@ const COLLECTIONS = {
2
2
  AMOUNT_OF_JOBS_PER_DEPARTMENT: 'AmountOfJobsPerDepartment',
3
3
  CITIES: 'cities',
4
4
  JOBS: 'Jobs',
5
- COMPANY_ID: 'CompanyId',
6
- API_KEY: 'ApiKey',
7
5
  TEMPLATE_TYPE: 'templateType',
6
+ SECRET_MANAGER_MIRROR: 'SecretManagerMirror',
8
7
  }
9
8
  const JOBS_COLLECTION_FIELDS = {
10
9
  LOCATION: 'location',
@@ -63,15 +62,13 @@ const COLLECTIONS_FIELDS = {
63
62
  {key:'city', type: 'REFERENCE', typeMetadata: { reference: { referencedCollectionId: COLLECTIONS.CITIES } } },
64
63
  { key: 'image', type: 'IMAGE' },
65
64
  ],
66
- COMPANY_ID: [
67
- {key:'companyId', type: 'TEXT'},
68
- ],
69
- API_KEY: [
70
- {key:'token', type: 'TEXT'},
71
- ],
72
65
  TEMPLATE_TYPE: [
73
66
  {key:'templateType', type: 'TEXT'},
74
67
  ],
68
+ SECRET_MANAGER_MIRROR: [
69
+ {key:'tokenName', type: 'TEXT'},
70
+ {key:'tokenValue', type: 'TEXT'},
71
+ ],
75
72
  };
76
73
 
77
74
 
package/backend/consts.js CHANGED
@@ -10,7 +10,7 @@ const TASKS_NAMES = {
10
10
  AGGREGATE_JOBS_BY_FIELD_TO_CMS: 'aggregateJobsByFieldToCMS',
11
11
  REFERENCE_JOBS: 'referenceJobs',
12
12
  CREATE_COLLECTIONS: 'createCollections',
13
- CREATE_COMPANY_ID_COLLECTION_AND_FILL_IT: 'createCompanyIdCollectionAndFillIt',
13
+ CREATE_SECRET_MANAGER_MIRROR_AND_FILL_IT: 'createSecretManagerMirrorAndFillIt',
14
14
  SYNC_JOBS_FAST: 'syncJobsFast',
15
15
  }
16
16
 
@@ -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:task=>task.data.templateType,
69
- process:templateType=>syncJobsFast(templateType),
68
+ getIdentifier:()=>"SHOULD_NEVER_SKIP",
69
+ process:syncJobsFast,
70
70
  shouldSkipCheck:()=>false,
71
71
  estimatedDurationSec:60
72
72
  }
package/backend/data.js CHANGED
@@ -286,52 +286,7 @@ function fetchJobLocation(jobDetails) {
286
286
  return jobLocation;
287
287
  }
288
288
 
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
- }
310
-
311
289
 
312
- async function createCompanyIdCollectionAndFillIt() {
313
- console.log("Creating CompanyId collection and filling it with the company ID");
314
- await createCollectionIfMissing(COLLECTIONS.COMPANY_ID, COLLECTIONS_FIELDS.COMPANY_ID,null,'singleItem');
315
- console.log("Getting the company ID ");
316
- const companyId = await getCompanyId();
317
- console.log("companyId is : ", companyId);
318
- console.log("Inserting the company ID into the CompanyId collection");
319
- try {
320
- await wixData.insert(COLLECTIONS.COMPANY_ID, {
321
- companyId: companyId.value
322
- });
323
- console.log("company ID inserted into the CompanyId collection");
324
- } catch (error) {
325
- if (error.message.includes("WDE0074: An item with _id [SINGLE_ITEM_ID] already exists")) {
326
- console.log("company ID already exists in the CompanyId collection");
327
- }
328
- else {
329
- throw error;
330
- }
331
- }
332
-
333
-
334
- }
335
290
 
336
291
  async function createCollections() {
337
292
  console.log("Creating collections");
@@ -359,13 +314,11 @@ async function referenceJobs() {
359
314
  console.log("finished referencing jobs");
360
315
  }
361
316
 
362
- async function syncJobsFast(templateType) {
317
+ async function syncJobsFast() {
363
318
  console.log("Syncing jobs fast");
364
- await createCompanyIdCollectionAndFillIt();
365
- if(templateType==='INTERNAL')
366
- {
367
- await createApiKeyCollectionAndFillIt();
368
- }
319
+ //database
320
+
321
+ await createSecretManagerMirrorAndFillIt();
369
322
  await createCollections();
370
323
  await clearCollections();
371
324
  console.log("saving jobs data to CMS");
@@ -389,14 +342,54 @@ async function clearCollections() {
389
342
  console.log("cleared collections successfully");
390
343
  }
391
344
 
345
+ async function markTemplateAsExternal() {
346
+ await createCollectionIfMissing(COLLECTIONS.TEMPLATE_TYPE, COLLECTIONS_FIELDS.TEMPLATE_TYPE,null,'singleItem');
347
+ await wixData.save(COLLECTIONS.TEMPLATE_TYPE, {
348
+ templateType: "PUBLIC"
349
+ });
350
+ }
351
+
352
+ async function markTemplateAsInternal() {
353
+ await createCollectionIfMissing(COLLECTIONS.TEMPLATE_TYPE, COLLECTIONS_FIELDS.TEMPLATE_TYPE,null,'singleItem');
354
+ await wixData.save(COLLECTIONS.TEMPLATE_TYPE, {
355
+ templateType: "INTERNAL"
356
+ });
357
+ }
358
+
359
+ async function createSecretManagerMirrorAndFillIt() {
360
+ console.log("Creating SecretManagerMirror collection and filling it");
361
+ await createCollectionIfMissing(COLLECTIONS.SECRET_MANAGER_MIRROR, COLLECTIONS_FIELDS.SECRET_MANAGER_MIRROR);
362
+ console.log("Getting the company ID ");
363
+ const companyId = await getCompanyId();
364
+ console.log("companyId is : ", companyId);
365
+ await wixData.insert(COLLECTIONS.SECRET_MANAGER_MIRROR, {
366
+ tokenName: "companyId",
367
+ tokenValue: companyId.value
368
+ });
369
+ console.log("companyId inserted into the SecretManagerMirror collection");
370
+ try{
371
+ const token = await getSmartToken();
372
+ await wixData.insert(COLLECTIONS.SECRET_MANAGER_MIRROR, {
373
+ tokenName: "x-smarttoken",
374
+ tokenValue: token.value
375
+ });
376
+ console.log("x-smarttoken inserted into the SecretManagerMirror collection");
377
+ } catch (error) {
378
+ console.log("Error creating SecretManagerMirror collection:", error);
379
+ }
380
+ }
381
+
382
+
392
383
  module.exports = {
393
384
  syncJobsFast,
394
385
  referenceJobs,
395
386
  aggregateJobs,
396
387
  createCollections,
397
- saveJobsDataToCMS,
398
- saveJobsDescriptionsAndLocationApplyUrlToCMS,
399
- aggregateJobsByFieldToCMS,
400
- referenceJobsToField,
401
- createCompanyIdCollectionAndFillIt,
388
+ saveJobsDataToCMS,
389
+ saveJobsDescriptionsAndLocationApplyUrlToCMS,
390
+ aggregateJobsByFieldToCMS,
391
+ referenceJobsToField,
392
+ createSecretManagerMirrorAndFillIt,
393
+ markTemplateAsExternal,
394
+ markTemplateAsInternal,
402
395
  };
@@ -2,19 +2,24 @@ 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,smartToken) {
5
+ async function makeSmartRecruitersRequest(path,templateTYpe) {
6
6
  const baseUrl = 'https://api.smartrecruiters.com';
7
7
  const fullUrl = `${baseUrl}${path}`;
8
8
 
9
9
  try {
10
+ //if templatetype is internal make headers object with x-smarttoken
11
+ const headers = {
12
+ 'Accept-Language': 'en',
13
+ 'accept': 'application/json',
14
+ 'Cookie': 'AWSALB=GYltFw3fLKortMxHR5vIOT1CuUROyhWNIX/qL8ZnPl1/8mhOcnIsBKYslzmNJPEzSy/jvNbO+6tXpH8yqcpQJagYt57MhbKlLqTSzoNq1G/w7TjOxPGR3UTdXW0d; AWSALBCORS=GYltFw3fLKortMxHR5vIOT1CuUROyhWNIX/qL8ZnPl1/8mhOcnIsBKYslzmNJPEzSy/jvNbO+6tXpH8yqcpQJagYt57MhbKlLqTSzoNq1G/w7TjOxPGR3UTdXW0d'
15
+ };
16
+ //here is the only place where we check templateType
17
+ if (templateType === 'INTERNAL') {
18
+ headers['x-smarttoken'] = smartToken;
19
+ }
10
20
  const response = await fetch(fullUrl, {
11
21
  method: 'GET',
12
- headers: {
13
- 'Accept-Language': 'en',
14
- 'accept': 'application/json',
15
- 'Cookie': 'AWSALB=GYltFw3fLKortMxHR5vIOT1CuUROyhWNIX/qL8ZnPl1/8mhOcnIsBKYslzmNJPEzSy/jvNbO+6tXpH8yqcpQJagYt57MhbKlLqTSzoNq1G/w7TjOxPGR3UTdXW0d; AWSALBCORS=GYltFw3fLKortMxHR5vIOT1CuUROyhWNIX/qL8ZnPl1/8mhOcnIsBKYslzmNJPEzSy/jvNbO+6tXpH8yqcpQJagYt57MhbKlLqTSzoNq1G/w7TjOxPGR3UTdXW0d',
16
- 'x-smarttoken': smartToken
17
- }
22
+ headers: headers
18
23
  });
19
24
 
20
25
  if (response.ok) {
@@ -34,7 +39,7 @@ async function fetchPositionsFromSRAPI() {
34
39
  let totalFound = 0;
35
40
  let page = 0;
36
41
  const MAX_PAGES = 30 // Safety limit to prevent infinite loops
37
- const {companyId,templateType,smartToken} = await getApiKeysFromCMS();
42
+ const {companyId,templateType,smartToken} = await getApiKeys();
38
43
  console.log('Starting to fetch all positions with pagination...');
39
44
  let offset=0;
40
45
 
@@ -95,7 +100,7 @@ async function fetchPositionsFromSRAPI() {
95
100
  }
96
101
 
97
102
  async function fetchJobDescription(jobId) {
98
- const {companyId,smartToken} = await getApiKeysFromCMS();
103
+ const {companyId,smartToken} = await getApiKeys();
99
104
  return await makeSmartRecruitersRequest(`/v1/companies/${companyId}/postings/${jobId}`,smartToken);
100
105
  }
101
106
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sr-npm",
3
- "version": "1.7.409",
3
+ "version": "1.7.411",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {