sr-npm 3.1.27 → 3.1.28

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.
@@ -46,6 +46,7 @@ const TWG_JOBS_COLLECTION_FIELDS={
46
46
  }
47
47
 
48
48
  const CATEGORY_CUSTOM_FIELD_ID_IN_CMS='5cd8c873c9e77c0008aa7d23';
49
+ const COMPANY_SEGMENT_CUSTOM_FIELD_ID_IN_CMS='5cd8c7ebc9e77c00072d8bc7';
49
50
 
50
51
  // used for filters - don't add anything else here
51
52
  const fieldTitlesInCMS={
@@ -88,6 +89,7 @@ module.exports = {
88
89
  FiltersIds,
89
90
  fieldTitlesInCMS,
90
91
  CATEGORY_CUSTOM_FIELD_ID_IN_CMS,
92
+ COMPANY_SEGMENT_CUSTOM_FIELD_ID_IN_CMS,
91
93
  possibleUrlParams,
92
94
  TWG_JOBS_COLLECTION_FIELDS,
93
95
  PRIMARY_SEARCH_STATES,
package/backend/consts.js CHANGED
@@ -68,7 +68,7 @@ const TASKS = {
68
68
  getIdentifier:()=>"SHOULD_NEVER_SKIP",
69
69
  process:syncJobsFast,
70
70
  shouldSkipCheck:()=>false,
71
- estimatedDurationSec:60
71
+ estimatedDurationSec:120
72
72
  }
73
73
  }
74
74
 
package/backend/data.js CHANGED
@@ -114,7 +114,7 @@ function getCustomFieldsAndValuesFromPosition(position, customFieldsLabels, cust
114
114
  }
115
115
  }
116
116
 
117
- async function saveJobsDataToCMS() {
117
+ async function retrieveJobsData() {
118
118
  const positions = await fetchPositionsFromSRAPI();
119
119
  const sourcePositions = await filterBasedOnBrand(positions);
120
120
  const customFieldsLabels = {}
@@ -165,6 +165,7 @@ async function saveJobsDataToCMS() {
165
165
  });
166
166
 
167
167
  if (siteconfig.customFields==="true") {
168
+
168
169
  await populateCustomFieldsCollection(customFieldsLabels,templateType);
169
170
  await populateCustomValuesCollection(customFieldsValues);
170
171
  }
@@ -175,35 +176,7 @@ async function saveJobsDataToCMS() {
175
176
  const titleB = b.title || '';
176
177
  return titleA.localeCompare(titleB, undefined, { sensitivity: 'base', numeric: true });
177
178
  });
178
-
179
- const chunkSize = 1000;
180
- let totalSaved = 0;
181
- const totalChunks = Math.ceil(jobsData.length / chunkSize);
182
-
183
- console.log(
184
- `Processing ${jobsData.length} jobs in ${totalChunks} chunks of max ${chunkSize} items each`
185
- );
186
- console.log("truncating jobs collection");
187
- await wixData.truncate(COLLECTIONS.JOBS);
188
- await chunkedBulkOperation({
189
- items: jobsData,
190
- chunkSize,
191
- processChunk: async (chunk, chunkNumber) => {
192
- console.log(`Saving chunk ${chunkNumber}/${totalChunks}: ${chunk.length} jobs`);
193
- try {
194
- const result = await wixData.bulkSave(COLLECTIONS.JOBS, chunk);
195
- const saved = result.inserted + result.updated || chunk.length;
196
- totalSaved += saved;
197
- console.log(
198
- `✓ Chunk ${chunkNumber} saved successfully. Inserted: ${result.inserted}, Updated: ${result.updated}`
199
- );
200
- } catch (error) {
201
- console.error(`✗ Error saving chunk ${chunkNumber}:`, error);
202
- throw error;
203
- }
204
- },
205
- });
206
- console.log(`✓ All chunks processed. Total jobs saved: ${totalSaved}/${jobsData.length}`);
179
+ return jobsData;
207
180
  }
208
181
 
209
182
  async function insertJobsReference(id, valueId) {
@@ -243,51 +216,16 @@ async function populateCustomValuesCollection(customFieldsValues) {
243
216
  await wixData.bulkSave(COLLECTIONS.CUSTOM_VALUES, valuesToinsert);
244
217
  }
245
218
 
246
- async function saveJobsDescriptionsAndLocationApplyUrlReferencesToCMS() {
219
+ async function retrieveJobsDescriptionsAndLocationApplyUrlReferences(jobsWithNoDescriptions) {
247
220
  console.log('🚀 Starting job descriptions update process for ALL jobs');
248
221
 
249
222
  try {
250
- let jobsWithNoDescriptions = await getJobsWithNoDescriptions();
251
-
252
- if (siteconfig.customFields==="true") {
253
- let customValues = await getAllCustomValues();
254
-
255
- console.log("inserting jobs references to custom values collection");
256
- console.log("customValues: ",customValues)
257
- console.log("customValues.items: ",customValues.items)
258
-
259
- for (const value of customValues.items) {
260
- await insertJobsReference(value._id, value.valueId);
261
- }
262
- console.log("inserted jobs references to custom values collection successfully");
263
- }
264
223
 
265
- let totalUpdated = 0;
266
- let totalFailed = 0;
267
- let totalProcessed = 0;
268
-
269
- console.log(
270
- `Total jobs in database without descriptions: ${jobsWithNoDescriptions?.items?.length}`
271
- );
272
-
273
- if (jobsWithNoDescriptions.items.length === 0) {
274
- console.log('No jobs found in database');
275
- return { success: true, message: 'No jobs found' };
276
- }
277
-
278
-
279
- const API_CHUNK_SIZE = 80;
280
- const pageChunks = Math.ceil(jobsWithNoDescriptions.items.length / API_CHUNK_SIZE);
281
224
  const richContentConverterToken = await getTokenFromCMS(TOKEN_NAME.RICH_CONTENT_CONVERTER_TOKEN);
282
- await chunkedBulkOperation({
283
- items: jobsWithNoDescriptions.items,
284
- chunkSize: API_CHUNK_SIZE,
285
- processChunk: async (chunk, chunkNumber) => {
286
- console.log(` Processing API chunk ${chunkNumber}/${pageChunks} (${chunk.length} jobs)`);
287
- const chunkPromises = chunk.map(async job => {
288
- try {
289
- const jobDetails = await fetchJobDescription(job._id);
290
- const richContentDescription=await htmlRichContentConverter(jobDetails.jobAd.sections,richContentConverterToken);
225
+
226
+ const jobsWithDescriptions=await Promise.all(jobsWithNoDescriptions.map( async job => {
227
+ const jobDetails = await fetchJobDescription(job._id);
228
+ const richContentDescription= await htmlRichContentConverter(jobDetails.jobAd.sections,richContentConverterToken);
291
229
  const jobLocation = fetchJobLocation(jobDetails);
292
230
  const {applyLink , referFriendLink} = fetchApplyAndReferFriendLink(jobDetails);
293
231
  const updatedJob = {
@@ -297,40 +235,10 @@ async function saveJobsDescriptionsAndLocationApplyUrlReferencesToCMS() {
297
235
  applyLink: applyLink,
298
236
  referFriendLink: referFriendLink,
299
237
  };
300
- await wixData.update(COLLECTIONS.JOBS, updatedJob);
301
- return { success: true, jobId: job._id, title: job.title };
302
- } catch (error) {
303
- console.error(` ❌ Failed to update ${job.title} (${job._id}):`, error);
304
- return { success: false, jobId: job._id, title: job.title, error: error.message };
305
- }
306
- });
307
- const chunkResults = await Promise.all(chunkPromises);
308
- const chunkSuccesses = chunkResults.filter(r => r.success).length;
309
- const chunkFailures = chunkResults.filter(r => !r.success).length;
310
- totalUpdated += chunkSuccesses;
311
- totalFailed += chunkFailures;
312
- totalProcessed += chunk.length;
313
- console.log(
314
- ` API chunk ${chunkNumber} completed: ${chunkSuccesses} success, ${chunkFailures} failed`
315
- );
316
- },
317
- });
318
-
319
-
238
+ return updatedJob;
239
+ }))
240
+ return {success: true, updatedJobs: jobsWithDescriptions};
320
241
 
321
- console.log(`\n✅ Finished updating ALL job descriptions`);
322
- console.log(`📊 Final Results:`);
323
- console.log(` Total jobs processed: ${totalProcessed}`);
324
- console.log(` Total updated: ${totalUpdated}`);
325
- console.log(` Total failed: ${totalFailed}`);
326
-
327
- return {
328
- success: true,
329
- totalProcessed: totalProcessed,
330
- totalUpdated: totalUpdated,
331
- totalFailed: totalFailed,
332
- message: `Successfully updated ${totalUpdated} job descriptions out of ${totalProcessed} total jobs`,
333
- };
334
242
  } catch (error) {
335
243
  console.error('❌ Error in updateJobDescriptions:', error);
336
244
  throw error;
@@ -375,14 +283,7 @@ async function getAllCustomValues() {
375
283
  return customValuesQuery;
376
284
  }
377
285
 
378
- async function getJobsWithNoDescriptions() {
379
- let jobswithoutdescriptionsQuery = await wixData
380
- .query(COLLECTIONS.JOBS)
381
- .limit(1000)
382
- .isEmpty('jobDescription')
383
- .find();
384
- return jobswithoutdescriptionsQuery;
385
- }
286
+
386
287
 
387
288
  /**
388
289
  * @param {Object} params
@@ -507,20 +408,36 @@ async function syncJobsFast() {
507
408
  try{
508
409
  console.log("Syncing jobs fast");
509
410
  await createCollections();
510
- await clearCollections();
411
+
511
412
  await fillSecretManagerMirror();
512
413
 
513
- console.log("saving jobs data to CMS");
514
- await saveJobsDataToCMS();
515
- console.log("saved jobs data to CMS successfully");
414
+ console.log("retrieving jobs data from SR API");
415
+
416
+ const jobsData = await retrieveJobsData();
417
+
418
+ console.log("retrieved jobs data from SR API successfully");
516
419
 
517
- console.log("saving jobs descriptions and location apply url to CMS");
518
- await saveJobsDescriptionsAndLocationApplyUrlReferencesToCMS();
420
+ console.log("retrieving jobs descriptions and location apply url from SR API");
421
+
422
+ const status=await retrieveJobsDescriptionsAndLocationApplyUrlReferences(jobsData);
423
+ if(status.success){
424
+
425
+ await clearCollections();
426
+ const updatedJobs=status.updatedJobs;
427
+ console.log("saving jobs to CMS");
428
+ await saveJobsToCMS(updatedJobs);
429
+
430
+ if (siteconfig.customFields==="true") {
431
+ await insertJobsReferencesToCustomValuesCollection();
432
+ }
433
+ }
434
+ console.log("saved jobs data, descriptions and location apply url to CMS successfully");
519
435
 
520
- console.log("saved jobs descriptions and location apply url to CMS successfully");
521
436
  await aggregateJobs();
522
437
  await referenceJobs();
438
+
523
439
  console.log("syncing jobs fast finished successfully");
440
+
524
441
  }
525
442
  catch (error) {
526
443
  error.message="Error syncing jobs: "+error.message;
@@ -529,7 +446,46 @@ async function syncJobsFast() {
529
446
 
530
447
  }
531
448
 
449
+ async function saveJobsToCMS(updatedJobs) {
450
+ const chunkSize = 1000;
451
+ let totalSaved = 0;
452
+ const totalChunks = Math.ceil(updatedJobs.length / chunkSize);
453
+
454
+ console.log(
455
+ `Processing ${updatedJobs.length} jobs in ${totalChunks} chunks of max ${chunkSize} items each`
456
+ );
457
+
458
+ await chunkedBulkOperation({
459
+ items: updatedJobs,
460
+ chunkSize,
461
+ processChunk: async (chunk, chunkNumber) => {
462
+ console.log(`Saving chunk ${chunkNumber}/${totalChunks}: ${chunk.length} jobs`);
463
+ try {
464
+ const result = await wixData.bulkSave(COLLECTIONS.JOBS, chunk);
465
+ const saved = result.inserted + result.updated || chunk.length;
466
+ totalSaved += saved;
467
+ console.log(
468
+ `✓ Chunk ${chunkNumber} saved successfully. Inserted: ${result.inserted}, Updated: ${result.updated}`
469
+ );
470
+ } catch (error) {
471
+ console.error(`✗ Error saving chunk ${chunkNumber}:`, error);
472
+ throw error;
473
+ }
474
+ },
475
+ });
476
+ console.log(`✓ All chunks processed. Total jobs saved: ${totalSaved}/${updatedJobs.length}`);
477
+ }
478
+
479
+ async function insertJobsReferencesToCustomValuesCollection() {
480
+ console.log("inserting jobs references to custom values collection");
532
481
 
482
+ let customValues = await getAllCustomValues();
483
+
484
+ for (const value of customValues.items) {
485
+ await insertJobsReference(value._id, value.valueId);
486
+ }
487
+ console.log("inserted jobs references to custom values collection successfully");
488
+ }
533
489
  async function clearCollections() {
534
490
  console.log("clearing collections");
535
491
  if(siteconfig===undefined) {
@@ -538,8 +494,8 @@ async function clearCollections() {
538
494
  await Promise.all([
539
495
  wixData.truncate(COLLECTIONS.CITIES),
540
496
  wixData.truncate(COLLECTIONS.AMOUNT_OF_JOBS_PER_DEPARTMENT),
541
- wixData.truncate(COLLECTIONS.JOBS),
542
497
  wixData.truncate(COLLECTIONS.BRANDS),
498
+ wixData.truncate(COLLECTIONS.JOBS),
543
499
  siteconfig.customFields==="true" ? wixData.truncate(COLLECTIONS.CUSTOM_VALUES) : null,
544
500
  siteconfig.customFields==="true" ? wixData.truncate(COLLECTIONS.CUSTOM_FIELDS) : null,
545
501
  ]);
@@ -589,8 +545,8 @@ module.exports = {
589
545
  referenceJobs,
590
546
  aggregateJobs,
591
547
  createCollections,
592
- saveJobsDataToCMS,
593
- saveJobsDescriptionsAndLocationApplyUrlReferencesToCMS,
548
+ saveJobsDataToCMS: retrieveJobsData,
549
+ saveJobsDescriptionsAndLocationApplyUrlReferencesToCMS: retrieveJobsDescriptionsAndLocationApplyUrlReferences,
594
550
  aggregateJobsByFieldToCMS,
595
551
  referenceJobsToField,
596
552
  fillSecretManagerMirror,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sr-npm",
3
- "version": "3.1.27",
3
+ "version": "3.1.28",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -40,6 +40,7 @@ let secondarySearchIsFilled=false // whether the secondary search is filled with
40
40
  let keywordAllJobs; // all jobs that are displayed in the jobs repeater when the keyword is filled
41
41
  let ActivateURLOnchange=true; // whether to activate the url onchange
42
42
  let considerAllJobs=false; // whether to consider all jobs or not
43
+ let collapseFilterBoxWhenWindowReduced=false; // whether to collapse the filter box when the window is reduced
43
44
  const pagination = {
44
45
  pageSize: 10,
45
46
  currentPage: 1,
@@ -64,10 +65,10 @@ async function careersMultiBoxesPageOnReady(_$w,urlParams) {
64
65
  });
65
66
 
66
67
  handleFilterButton(_$w);
67
-
68
68
  setInterval(async () => {
69
69
  const windowinfo=await window.getBoundingRect();
70
70
  if(windowinfo.window.width>1000){
71
+
71
72
  handleWindowResize(_$w,true);
72
73
  }
73
74
  else{
@@ -80,6 +81,7 @@ async function careersMultiBoxesPageOnReady(_$w,urlParams) {
80
81
 
81
82
  async function handleWindowResize(_$w,desktop=false) {
82
83
  if(desktop){
84
+ collapseFilterBoxWhenWindowReduced=true;
83
85
  MOBILE_FILTER_BOX_SELECTORS.forEach(selector => {
84
86
  _$w(selector).expand();
85
87
  });
@@ -91,9 +93,15 @@ async function handleWindowResize(_$w,desktop=false) {
91
93
  _$w(CAREERS_PAGE_SELECTORS.REFINE_SEARCH_BUTTON).collapse();
92
94
  }
93
95
  else{
96
+ const formFactor = await window.formFactor();
97
+ if(formFactor==="Desktop" && collapseFilterBoxWhenWindowReduced){
98
+ _$w(CAREERS_PAGE_SELECTORS.FILTER_BOX).collapse();
99
+ collapseFilterBoxWhenWindowReduced=false;
100
+ }
94
101
  if(_$w(CAREERS_PAGE_SELECTORS.FILTER_ICON).collapsed && _$w(CAREERS_PAGE_SELECTORS.EXIT_BUTTON).collapsed && _$w(CAREERS_PAGE_SELECTORS.REFINE_SEARCH_BUTTON).collapsed){
95
102
  _$w(CAREERS_PAGE_SELECTORS.FILTER_ICON).expand();
96
103
  }
104
+
97
105
  }
98
106
 
99
107
  }
@@ -178,6 +186,10 @@ async function handleFilterButton(_$w) {
178
186
  _$w(selector).collapse();
179
187
  });
180
188
  }
189
+ else
190
+ {
191
+ collapseFilterBoxWhenWindowReduced=true
192
+ }
181
193
 
182
194
  }
183
195
 
@@ -5,13 +5,34 @@ const { TWG_JOBS_COLLECTION_FIELDS } = require('../backend/careersMultiBoxesPage
5
5
  const { items: wixData } = require('@wix/data');
6
6
  const { location } = require("@wix/site-location");
7
7
  const{isElementExistOnPage} = require('psdev-utils');
8
+ const { COMPANY_SEGMENT_CUSTOM_FIELD_ID_IN_CMS } = require('../backend/careersMultiBoxesPageIds');
8
9
  const {
9
10
  appendQueryParams
10
11
  } = require('../public/utils');
11
12
 
12
13
 
14
+ let siteconfig;
15
+ let multiRefField;
13
16
  async function positionPageOnReady(_$w) {
14
- console.log("positionPageOnReady called");
17
+ if(siteconfig===undefined) {
18
+ siteconfig = await wixData.query(COLLECTIONS.SITE_CONFIGS).find().then(result => result.items[0]);
19
+ }
20
+ const item = await _$w('#datasetJobsItem').getCurrentItem();
21
+
22
+ if(siteconfig.customFields==="true") {
23
+ multiRefField=await getPositionWithMultiRefField(item._id);
24
+
25
+
26
+ const companysegmentValue=multiRefField.filter(field => field.customField===COMPANY_SEGMENT_CUSTOM_FIELD_ID_IN_CMS && field.title===siteconfig.showNotifyMeForCompanySegment);
27
+
28
+ if(companysegmentValue===undefined || companysegmentValue.length===0) {
29
+
30
+ _$w("#notifyMe").hide()
31
+ console.log(`companysegmentValue is ${siteconfig.showNotifyMeForCompanySegment}, hiding notifyMe`);
32
+ }
33
+
34
+
35
+ }
15
36
  await bind(_$w);
16
37
 
17
38
 
@@ -35,6 +56,8 @@ async function getCategoryValue(customValues) {
35
56
  const item = await _$w('#datasetJobsItem').getCurrentItem();
36
57
  console.log("item: ",item);
37
58
 
59
+
60
+
38
61
  handleReferFriendButton(_$w,item);
39
62
  handleApplyButton(_$w,item);
40
63
 
@@ -49,9 +72,7 @@ async function getCategoryValue(customValues) {
49
72
  if(isElementExistOnPage(_$w('#relatedJobsRepNoDepartment'))) // when there is no department, we filter based on category
50
73
  {
51
74
 
52
- const multiRefField=await getPositionWithMultiRefField(item._id);
53
- const categoryValue=await getCategoryValue(multiRefField);
54
-
75
+ const categoryValue=await getCategoryValue(multiRefField);
55
76
  if(isElementExistOnPage(_$w('#jobCategory'))) {
56
77
  _$w('#jobCategory').text = categoryValue.title;
57
78
  }