sr-npm 1.7.417 → 1.7.419

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/consts.js CHANGED
@@ -73,6 +73,15 @@ const TASKS = {
73
73
  }
74
74
 
75
75
 
76
+ const TEMPLATE_TYPE = {
77
+ INTERNAL: 'INTERNAL',
78
+ EXTERNAL: 'PUBLIC',
79
+ }
80
+
81
+ const TOKEN_NAME = {
82
+ COMPANY_ID: 'companyId',
83
+ SMART_TOKEN: 'x-smarttoken',
84
+ }
76
85
 
77
86
  const TASK_TYPE = {
78
87
  SCHEDULED: 'scheduled',
@@ -83,5 +92,7 @@ const TASK_TYPE = {
83
92
  TASKS_NAMES,
84
93
  TASK_TYPE,
85
94
  TASKS,
86
- QUERY_MAX_LIMIT
95
+ QUERY_MAX_LIMIT,
96
+ TEMPLATE_TYPE,
97
+ TOKEN_NAME
87
98
  };
package/backend/data.js CHANGED
@@ -4,6 +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{TEMPLATE_TYPE,TOKEN_NAME} = require('./consts');
7
8
  const { getCompanyId, getSmartToken } = require('./secretsData');
8
9
 
9
10
  function validatePosition(position) {
@@ -348,14 +349,14 @@ async function clearCollections() {
348
349
  async function markTemplateAsExternal() {
349
350
  await createCollectionIfMissing(COLLECTIONS.TEMPLATE_TYPE, COLLECTIONS_FIELDS.TEMPLATE_TYPE,null,'singleItem');
350
351
  await wixData.save(COLLECTIONS.TEMPLATE_TYPE, {
351
- templateType: "PUBLIC"
352
+ templateType: TEMPLATE_TYPE.EXTERNAL
352
353
  });
353
354
  }
354
355
 
355
356
  async function markTemplateAsInternal() {
356
357
  await createCollectionIfMissing(COLLECTIONS.TEMPLATE_TYPE, COLLECTIONS_FIELDS.TEMPLATE_TYPE,null,'singleItem');
357
358
  await wixData.save(COLLECTIONS.TEMPLATE_TYPE, {
358
- templateType: "INTERNAL"
359
+ templateType: TEMPLATE_TYPE.INTERNAL
359
360
  });
360
361
  }
361
362
 
@@ -364,14 +365,14 @@ async function fillSecretManagerMirror() {
364
365
  const companyId = await getCompanyId();
365
366
  console.log("companyId is : ", companyId);
366
367
  await wixData.insert(COLLECTIONS.SECRET_MANAGER_MIRROR, {
367
- tokenName: "companyId",
368
+ tokenName: TOKEN_NAME.COMPANY_ID,
368
369
  tokenValue: companyId.value
369
370
  });
370
371
  console.log("companyId inserted into the SecretManagerMirror collection");
371
372
  try{
372
373
  const token = await getSmartToken();
373
374
  await wixData.insert(COLLECTIONS.SECRET_MANAGER_MIRROR, {
374
- tokenName: "x-smarttoken",
375
+ tokenName: TOKEN_NAME.SMART_TOKEN,
375
376
  tokenValue: token.value
376
377
  });
377
378
  console.log("x-smarttoken inserted into the SecretManagerMirror collection");
@@ -1,6 +1,7 @@
1
1
  const { fetch } = require('wix-fetch');
2
2
  const { items: wixData } = require('@wix/data');
3
3
  const { COLLECTIONS } = require('./collectionConsts');
4
+ const { TEMPLATE_TYPE,TOKEN_NAME } = require('./consts');
4
5
 
5
6
  async function makeSmartRecruitersRequest(path,templateType) {
6
7
  const baseUrl = 'https://api.smartrecruiters.com';
@@ -14,9 +15,8 @@ async function makeSmartRecruitersRequest(path,templateType) {
14
15
  'Cookie': 'AWSALB=GYltFw3fLKortMxHR5vIOT1CuUROyhWNIX/qL8ZnPl1/8mhOcnIsBKYslzmNJPEzSy/jvNbO+6tXpH8yqcpQJagYt57MhbKlLqTSzoNq1G/w7TjOxPGR3UTdXW0d; AWSALBCORS=GYltFw3fLKortMxHR5vIOT1CuUROyhWNIX/qL8ZnPl1/8mhOcnIsBKYslzmNJPEzSy/jvNbO+6tXpH8yqcpQJagYt57MhbKlLqTSzoNq1G/w7TjOxPGR3UTdXW0d'
15
16
  };
16
17
  //here is the only place where we check templateType
17
- if (templateType === 'INTERNAL') {
18
- const smartToken = await getSmartTokenFromCMS();
19
- console.log("smartToken is ",smartToken);
18
+ if (templateType === TEMPLATE_TYPE.INTERNAL) {
19
+ const smartToken = await getTokenFromCMS(TOKEN_NAME.SMART_TOKEN);
20
20
  headers['x-smarttoken'] = smartToken;
21
21
  }
22
22
  const response = await fetch(fullUrl, {
@@ -106,21 +106,13 @@ async function fetchJobDescription(jobId) {
106
106
  return await makeSmartRecruitersRequest(`/v1/companies/${companyId}/postings/${jobId}`,templateType);
107
107
  }
108
108
 
109
- async function getCompanyIdFromCMS() {
110
- const result = await wixData.query(COLLECTIONS.SECRET_MANAGER_MIRROR).eq('tokenName','companyId').find();
111
- if (result.items.length > 0) {
112
- return result.items[0].tokenValue;
113
- } else {
114
- throw new Error('[getCompanyIdFromCMS], No companyId found');
115
- }
116
- }
117
109
 
118
- async function getSmartTokenFromCMS() {
119
- const result = await wixData.query(COLLECTIONS.SECRET_MANAGER_MIRROR).eq('tokenName','x-smarttoken').find();
110
+ async function getTokenFromCMS(tokenName) {
111
+ const result = await wixData.query(COLLECTIONS.SECRET_MANAGER_MIRROR).eq('tokenName',tokenName).find();
120
112
  if (result.items.length > 0) {
121
113
  return result.items[0].tokenValue;
122
114
  } else {
123
- throw new Error('[getSmartTokenFromCMS], No smarttoken found');
115
+ throw new Error(`[getTokenFromCMS], No ${tokenName} found`);
124
116
  }
125
117
  }
126
118
  async function getTemplateTypeFromCMS() {
@@ -133,7 +125,7 @@ async function getTemplateTypeFromCMS() {
133
125
  }
134
126
 
135
127
  async function getApiKeys() {
136
- const companyId = await getCompanyIdFromCMS();
128
+ const companyId = await getTokenFromCMS(TOKEN_NAME.COMPANY_ID);
137
129
  const templateType = await getTemplateTypeFromCMS();
138
130
  return {companyId,templateType};
139
131
  }
@@ -141,5 +133,5 @@ async function getApiKeys() {
141
133
  module.exports = {
142
134
  fetchPositionsFromSRAPI,
143
135
  fetchJobDescription,
144
- getCompanyIdFromCMS
136
+ getTokenFromCMS
145
137
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sr-npm",
3
- "version": "1.7.417",
3
+ "version": "1.7.419",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {