sr-npm 3.1.3 → 3.1.5

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.
@@ -14,6 +14,7 @@ const COLLECTIONS = {
14
14
  const JOBS_COLLECTION_FIELDS = {
15
15
  LOCATION: 'location',
16
16
  TITLE: 'title',
17
+ SLUG: 'slug',
17
18
  LOCATION_ADDRESS: 'locationAddress',
18
19
  COUNTRY: 'country',
19
20
  DEPARTMENT: 'department',
@@ -77,6 +78,7 @@ const COLLECTIONS_FIELDS = {
77
78
  JOBS: [
78
79
  {key:'location', type: 'OBJECT'},
79
80
  {key:'title', type: 'TEXT'},
81
+ {key:'slug', type: 'TEXT'},
80
82
  {key:'locationAddress', type: 'ADDRESS'},
81
83
  {key:'country', type: 'TEXT'},
82
84
  {key:'department', type: 'TEXT'},
@@ -133,6 +135,7 @@ const COLLECTIONS_FIELDS = {
133
135
  COMPANY_ID: 'companyId',
134
136
  SMART_TOKEN: 'x-smarttoken',
135
137
  DESIRED_BRAND: 'desiredBrand',
138
+ RICH_CONTENT_CONVERTER_TOKEN: 'richContentConverterToken',
136
139
  }
137
140
 
138
141
 
package/backend/data.js CHANGED
@@ -1,10 +1,17 @@
1
1
  const { items: wixData } = require('@wix/data');
2
- const { fetchPositionsFromSRAPI, fetchJobDescription } = require('./fetchPositionsFromSRAPI');
2
+ const { fetchPositionsFromSRAPI, fetchJobDescription, htmlRichContentConverter } = require('./fetchPositionsFromSRAPI');
3
3
  const { createCollectionIfMissing } = require('@hisense-staging/velo-npm/backend');
4
- const { COLLECTIONS, COLLECTIONS_FIELDS,JOBS_COLLECTION_FIELDS,TEMPLATE_TYPE,TOKEN_NAME,CUSTOM_VALUES_COLLECTION_FIELDS } = require('./collectionConsts');
5
- const { chunkedBulkOperation, countJobsPerGivenField, fillCityLocationAndLocationAddress ,prepareToSaveArray,normalizeString} = require('./utils');
4
+
6
5
  const { getAllPositions } = require('./queries');
7
6
  const { retrieveSecretVal, getTokenFromCMS ,getApiKeys} = require('./secretsData');
7
+ const { COLLECTIONS, COLLECTIONS_FIELDS,JOBS_COLLECTION_FIELDS,TEMPLATE_TYPE,TOKEN_NAME,CUSTOM_VALUES_COLLECTION_FIELDS } = require('./collectionConsts');
8
+ const { chunkedBulkOperation,
9
+ countJobsPerGivenField,
10
+ fillCityLocationAndLocationAddress,
11
+ prepareToSaveArray,
12
+ normalizeString,
13
+ generateSlug}
14
+ = require('./utils');
8
15
 
9
16
  let customValuesToJobs = {}
10
17
  let locationToJobs = {}
@@ -110,7 +117,7 @@ async function saveJobsDataToCMS() {
110
117
  const customFieldsLabels = {}
111
118
  const customFieldsValues = {}
112
119
 
113
- const {companyId,templateType} = await getApiKeys();
120
+ const {companyId ,templateType} = await getApiKeys();
114
121
  if(siteconfig===undefined) {
115
122
  await getSiteConfig();
116
123
  }
@@ -120,6 +127,7 @@ async function saveJobsDataToCMS() {
120
127
  const basicJob = {
121
128
  _id: position.id,
122
129
  title: position.name || '',
130
+ slug: generateSlug(position.name || ''),
123
131
  department: position.department?.label || 'Other',
124
132
  cityText: normalizeString(position.location?.city),
125
133
  location: position.location && Object.keys(position.location).length > 0
@@ -261,7 +269,7 @@ async function saveJobsDescriptionsAndLocationApplyUrlReferencesToCMS() {
261
269
 
262
270
  const API_CHUNK_SIZE = 80;
263
271
  const pageChunks = Math.ceil(jobsWithNoDescriptions.items.length / API_CHUNK_SIZE);
264
-
272
+ const richContentConverterToken = await getTokenFromCMS(TOKEN_NAME.RICH_CONTENT_CONVERTER_TOKEN);
265
273
  await chunkedBulkOperation({
266
274
  items: jobsWithNoDescriptions.items,
267
275
  chunkSize: API_CHUNK_SIZE,
@@ -270,14 +278,13 @@ async function saveJobsDescriptionsAndLocationApplyUrlReferencesToCMS() {
270
278
  const chunkPromises = chunk.map(async job => {
271
279
  try {
272
280
  const jobDetails = await fetchJobDescription(job._id);
281
+ const richContentDescription=await htmlRichContentConverter(jobDetails.jobAd.sections,richContentConverterToken);
273
282
  const jobLocation = fetchJobLocation(jobDetails);
274
283
  const {applyLink , referFriendLink} = fetchApplyAndReferFriendLink(jobDetails);
275
-
276
-
277
284
  const updatedJob = {
278
285
  ...job,
279
286
  locationAddress: jobLocation,
280
- jobDescription: jobDetails.jobAd.sections,
287
+ jobDescription: richContentDescription,
281
288
  applyLink: applyLink,
282
289
  referFriendLink: referFriendLink,
283
290
  };
@@ -114,11 +114,44 @@ async function fetchJobDescription(jobId,testObject=undefined) {
114
114
  return await makeSmartRecruitersRequest(`/v1/companies/${companyId}/postings/${jobId}`,templateType);
115
115
  }
116
116
 
117
+ async function htmlRichContentConverter(sections,richContentConverterToken) {
118
+ const richContentObject = {}
119
+ for (const [sectionTitle, sectionData] of Object.entries(sections)) {
120
+ if (sectionData.text) {
121
+ const raw = JSON.stringify({
122
+ content: sectionData.text,
123
+ });
124
+ const requestOptions = {
125
+ method: 'post',
126
+ headers: {
127
+ 'Content-Type': 'application/json',
128
+ Cookie: 'XSRF-TOKEN=1753949844|p--a7HsuVjR4',
129
+ Authorization: 'Bearer '+richContentConverterToken,
130
+ },
131
+ body: raw,
132
+ };
133
+ const response = await fetch(
134
+ 'https://www.wixapis.com/data-sync/v1/abmp-content-converter',
135
+ requestOptions
136
+ );
137
+ if (response.ok) {
138
+ const data = await response.json();
139
+ richContentObject[sectionTitle] = data.richContent.richContent;
140
+ }
141
+ else {
142
+ throw new Error("Error converting html to rich content response: "+response);
143
+ }
144
+ }
145
+ }
146
+ return richContentObject;
147
+ }
148
+
117
149
 
118
150
 
119
151
 
120
152
  module.exports = {
121
153
  fetchPositionsFromSRAPI,
122
154
  fetchJobDescription,
123
- makeSmartRecruitersRequest
155
+ makeSmartRecruitersRequest,
156
+ htmlRichContentConverter
124
157
  };
package/backend/utils.js CHANGED
@@ -65,6 +65,12 @@ function normalizeString(str) {
65
65
  .trim();
66
66
  }
67
67
 
68
+ function generateSlug(title){
69
+ return title
70
+ .replace(/[^a-zA-Z0-9-]+/g, "-") // allow uppercase AND lowercase letters
71
+ .replace(/-+/g, "-") // collapse multiple hyphens
72
+ .replace(/^-|-$/g, ""); // remove leading/trailing hyphens
73
+ }
68
74
 
69
75
 
70
76
  module.exports = {
@@ -74,5 +80,5 @@ module.exports = {
74
80
  fillCityLocationAndLocationAddress,
75
81
  prepareToSaveArray,
76
82
  normalizeString,
77
-
83
+ generateSlug,
78
84
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sr-npm",
3
- "version": "3.1.3",
3
+ "version": "3.1.5",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -595,7 +595,6 @@ async function secondarySearch(_$w,query) {
595
595
  }
596
596
  secondarySearchIsFilled=true
597
597
  }
598
-
599
598
  handlePaginationButtons(_$w);
600
599
  updateTotalJobsCountText(_$w);
601
600
  await refreshFacetCounts(_$w);
@@ -5,7 +5,6 @@ const { items: wixData } = require('@wix/data');
5
5
  const { location } = require("@wix/site-location");
6
6
  const{isElementExistOnPage} = require('psdev-utils');
7
7
  const {
8
- htmlToText,
9
8
  appendQueryParams
10
9
  } = require('../public/utils');
11
10
 
@@ -40,17 +39,14 @@ async function getCategoryValue(customValues) {
40
39
 
41
40
  handleReferFriendButton(_$w,item);
42
41
  handleApplyButton(_$w,item);
43
-
44
42
 
45
-
46
-
47
- _$w('#companyDescriptionText').text = htmlToText(item.jobDescription.companyDescription.text);
48
- _$w('#responsibilitiesText').text = htmlToText(item.jobDescription.jobDescription.text);
49
- _$w('#qualificationsText').text = htmlToText(item.jobDescription.qualifications.text);
43
+ _$w('#companyDescriptionText').content = item.jobDescription.companyDescription;
44
+ _$w('#responsibilitiesText').content = item.jobDescription.jobDescription;
45
+ _$w('#qualificationsText').content = item.jobDescription.qualifications;
50
46
  _$w('#relatedJobsTitleText').text = `More ${item.department} Positions`;
51
47
  if(isElementExistOnPage(_$w('#additionalInfoText')))
52
48
  {
53
- _$w('#additionalInfoText').text = htmlToText(item.jobDescription.additionalInformation.text);
49
+ _$w('#additionalInfoText').content = item.jobDescription.additionalInformation;
54
50
  }
55
51
  if(isElementExistOnPage(_$w('#relatedJobsRepNoDepartment'))) // when there is no department, we filter based on category
56
52
  {