sr-npm 3.1.27 → 3.1.29

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
@@ -16,6 +16,8 @@ const { chunkedBulkOperation,
16
16
  let customValuesToJobs = {}
17
17
  let locationToJobs = {}
18
18
  let siteconfig;
19
+ let customFieldsLabels = {}
20
+ let customFieldsValues = {}
19
21
  const EXCLUDED_CUSTOM_FIELDS = new Set(["Department","Country"]);
20
22
 
21
23
  function getBrand(customField) {
@@ -114,11 +116,9 @@ function getCustomFieldsAndValuesFromPosition(position, customFieldsLabels, cust
114
116
  }
115
117
  }
116
118
 
117
- async function saveJobsDataToCMS() {
119
+ async function retrieveJobsData() {
118
120
  const positions = await fetchPositionsFromSRAPI();
119
121
  const sourcePositions = await filterBasedOnBrand(positions);
120
- const customFieldsLabels = {}
121
- const customFieldsValues = {}
122
122
 
123
123
  const { templateType } = await getApiKeys();
124
124
  if(siteconfig===undefined) {
@@ -164,10 +164,6 @@ async function saveJobsDataToCMS() {
164
164
  return basicJob;
165
165
  });
166
166
 
167
- if (siteconfig.customFields==="true") {
168
- await populateCustomFieldsCollection(customFieldsLabels,templateType);
169
- await populateCustomValuesCollection(customFieldsValues);
170
- }
171
167
 
172
168
  // Sort jobs by title (ascending, case-insensitive, numeric-aware)
173
169
  jobsData.sort((a, b) => {
@@ -175,35 +171,7 @@ async function saveJobsDataToCMS() {
175
171
  const titleB = b.title || '';
176
172
  return titleA.localeCompare(titleB, undefined, { sensitivity: 'base', numeric: true });
177
173
  });
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}`);
174
+ return jobsData;
207
175
  }
208
176
 
209
177
  async function insertJobsReference(id, valueId) {
@@ -222,6 +190,7 @@ async function populateCustomFieldsCollection(customFields,templateType) {
222
190
  _id: ID,
223
191
  })
224
192
  }
193
+
225
194
  await wixData.bulkSave(COLLECTIONS.CUSTOM_FIELDS, fieldstoinsert);
226
195
  }
227
196
  async function populateCustomValuesCollection(customFieldsValues) {
@@ -243,51 +212,16 @@ async function populateCustomValuesCollection(customFieldsValues) {
243
212
  await wixData.bulkSave(COLLECTIONS.CUSTOM_VALUES, valuesToinsert);
244
213
  }
245
214
 
246
- async function saveJobsDescriptionsAndLocationApplyUrlReferencesToCMS() {
215
+ async function retrieveJobsDescriptionsAndLocationApplyUrlReferences(jobsWithNoDescriptions) {
247
216
  console.log('🚀 Starting job descriptions update process for ALL jobs');
248
217
 
249
218
  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
219
 
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
220
  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);
221
+
222
+ const jobsWithDescriptions=await Promise.all(jobsWithNoDescriptions.map( async job => {
223
+ const jobDetails = await fetchJobDescription(job._id);
224
+ const richContentDescription= await htmlRichContentConverter(jobDetails.jobAd.sections,richContentConverterToken);
291
225
  const jobLocation = fetchJobLocation(jobDetails);
292
226
  const {applyLink , referFriendLink} = fetchApplyAndReferFriendLink(jobDetails);
293
227
  const updatedJob = {
@@ -297,40 +231,10 @@ async function saveJobsDescriptionsAndLocationApplyUrlReferencesToCMS() {
297
231
  applyLink: applyLink,
298
232
  referFriendLink: referFriendLink,
299
233
  };
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
- });
234
+ return updatedJob;
235
+ }))
236
+ return {success: true, updatedJobs: jobsWithDescriptions};
318
237
 
319
-
320
-
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
238
  } catch (error) {
335
239
  console.error('❌ Error in updateJobDescriptions:', error);
336
240
  throw error;
@@ -375,14 +279,7 @@ async function getAllCustomValues() {
375
279
  return customValuesQuery;
376
280
  }
377
281
 
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
- }
282
+
386
283
 
387
284
  /**
388
285
  * @param {Object} params
@@ -507,20 +404,45 @@ async function syncJobsFast() {
507
404
  try{
508
405
  console.log("Syncing jobs fast");
509
406
  await createCollections();
510
- await clearCollections();
407
+
511
408
  await fillSecretManagerMirror();
512
409
 
513
- console.log("saving jobs data to CMS");
514
- await saveJobsDataToCMS();
515
- console.log("saved jobs data to CMS successfully");
410
+ console.log("retrieving jobs data from SR API");
411
+
412
+ const jobsData = await retrieveJobsData();
413
+
414
+ console.log("retrieved jobs data from SR API successfully");
516
415
 
517
- console.log("saving jobs descriptions and location apply url to CMS");
518
- await saveJobsDescriptionsAndLocationApplyUrlReferencesToCMS();
416
+ console.log("retrieving jobs descriptions and location apply url from SR API");
417
+
418
+ const status=await retrieveJobsDescriptionsAndLocationApplyUrlReferences(jobsData);
419
+ if(status.success){
420
+
421
+ await clearCollections();
422
+ const updatedJobs=status.updatedJobs;
423
+
424
+ if (siteconfig.customFields==="true") {
425
+ const { templateType } = await getApiKeys();
426
+ console.log("populating custom fields and values collections");
427
+ await populateCustomFieldsCollection(customFieldsLabels,templateType);
428
+ await populateCustomValuesCollection(customFieldsValues);
429
+ console.log("populated custom fields and values collections successfully");
430
+ }
431
+ console.log("saving jobs to CMS");
432
+ await saveJobsToCMS(updatedJobs);
433
+ console.log("saved jobs to CMS successfully");
434
+
435
+ if (siteconfig.customFields==="true") {
436
+ await insertJobsReferencesToCustomValuesCollection();
437
+ }
438
+ }
439
+ console.log("saved jobs data, descriptions and location apply url to CMS successfully");
519
440
 
520
- console.log("saved jobs descriptions and location apply url to CMS successfully");
521
441
  await aggregateJobs();
522
442
  await referenceJobs();
443
+
523
444
  console.log("syncing jobs fast finished successfully");
445
+
524
446
  }
525
447
  catch (error) {
526
448
  error.message="Error syncing jobs: "+error.message;
@@ -529,7 +451,47 @@ async function syncJobsFast() {
529
451
 
530
452
  }
531
453
 
454
+ async function saveJobsToCMS(updatedJobs) {
455
+
456
+ const chunkSize = 1000;
457
+ let totalSaved = 0;
458
+ const totalChunks = Math.ceil(updatedJobs.length / chunkSize);
532
459
 
460
+ console.log(
461
+ `Processing ${updatedJobs.length} jobs in ${totalChunks} chunks of max ${chunkSize} items each`
462
+ );
463
+
464
+ await chunkedBulkOperation({
465
+ items: updatedJobs,
466
+ chunkSize,
467
+ processChunk: async (chunk, chunkNumber) => {
468
+ console.log(`Saving chunk ${chunkNumber}/${totalChunks}: ${chunk.length} jobs`);
469
+ try {
470
+ const result = await wixData.bulkSave(COLLECTIONS.JOBS, chunk);
471
+ const saved = result.inserted + result.updated || chunk.length;
472
+ totalSaved += saved;
473
+ console.log(
474
+ `✓ Chunk ${chunkNumber} saved successfully. Inserted: ${result.inserted}, Updated: ${result.updated}`
475
+ );
476
+ } catch (error) {
477
+ console.error(`✗ Error saving chunk ${chunkNumber}:`, error);
478
+ throw error;
479
+ }
480
+ },
481
+ });
482
+ console.log(`✓ All chunks processed. Total jobs saved: ${totalSaved}/${updatedJobs.length}`);
483
+ }
484
+
485
+ async function insertJobsReferencesToCustomValuesCollection() {
486
+ console.log("inserting jobs references to custom values collection");
487
+
488
+ let customValues = await getAllCustomValues();
489
+
490
+ for (const value of customValues.items) {
491
+ await insertJobsReference(value._id, value.valueId);
492
+ }
493
+ console.log("inserted jobs references to custom values collection successfully");
494
+ }
533
495
  async function clearCollections() {
534
496
  console.log("clearing collections");
535
497
  if(siteconfig===undefined) {
@@ -538,8 +500,8 @@ async function clearCollections() {
538
500
  await Promise.all([
539
501
  wixData.truncate(COLLECTIONS.CITIES),
540
502
  wixData.truncate(COLLECTIONS.AMOUNT_OF_JOBS_PER_DEPARTMENT),
541
- wixData.truncate(COLLECTIONS.JOBS),
542
503
  wixData.truncate(COLLECTIONS.BRANDS),
504
+ wixData.truncate(COLLECTIONS.JOBS),
543
505
  siteconfig.customFields==="true" ? wixData.truncate(COLLECTIONS.CUSTOM_VALUES) : null,
544
506
  siteconfig.customFields==="true" ? wixData.truncate(COLLECTIONS.CUSTOM_FIELDS) : null,
545
507
  ]);
@@ -589,8 +551,8 @@ module.exports = {
589
551
  referenceJobs,
590
552
  aggregateJobs,
591
553
  createCollections,
592
- saveJobsDataToCMS,
593
- saveJobsDescriptionsAndLocationApplyUrlReferencesToCMS,
554
+ saveJobsDataToCMS: retrieveJobsData,
555
+ saveJobsDescriptionsAndLocationApplyUrlReferencesToCMS: retrieveJobsDescriptionsAndLocationApplyUrlReferences,
594
556
  aggregateJobsByFieldToCMS,
595
557
  referenceJobsToField,
596
558
  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.29",
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
  }