sr-npm 1.7.10 → 1.7.12

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
@@ -1,4 +1,4 @@
1
- const {saveDataJobsToCMS,saveJobsDescriptionsAndLocationToCMS,aggregateJobsByFieldToCMS,referenceJobsToField} = require('./data');
1
+ const {saveDataJobsToCMS,saveJobsDescriptionsAndLocationToCMS,aggregateJobsByFieldToCMS,referenceJobsToField,createApiKeyCollectionAndFillIt} = require('./data');
2
2
  const { createCollectionIfMissing } = require('@hisense-staging/velo-npm/backend');
3
3
  const TASKS_NAMES = {
4
4
  SYNC_JOBS: 'syncJobsFromSRAPIToCMS',
@@ -11,6 +11,7 @@ const TASKS_NAMES = {
11
11
  CREATE_JOBS_COLLECTION: 'createJobsCollection',
12
12
  CREATE_CITIES_COLLECTION: 'createCitiesCollection',
13
13
  CREATE_AMOUNT_OF_JOBS_PER_DEPARTMENT_COLLECTION: 'createAmountOfJobsPerDepartmentCollection',
14
+ CREATE_API_KEY_COLLECTION_AND_FILL_IT: 'createApiKeyCollectionAndFillIt',
14
15
  }
15
16
 
16
17
 
@@ -93,6 +94,13 @@ const TASKS = {
93
94
  process:()=>referenceJobsToField({ referenceField: 'departmentref', sourceCollection: 'AmountOfJobsPerDepartment', jobField: 'department' }),
94
95
  shouldSkipCheck:()=>false,
95
96
  estimatedDurationSec:3
97
+ },
98
+ [TASKS_NAMES.CREATE_API_KEY_COLLECTION_AND_FILL_IT]: {
99
+ name: TASKS_NAMES.CREATE_API_KEY_COLLECTION_AND_FILL_IT,
100
+ getIdentifier:()=> "SHOULD_NEVER_SKIP",
101
+ process:()=>createApiKeyCollectionAndFillIt(),
102
+ shouldSkipCheck:()=>false,
103
+ estimatedDurationSec:3
96
104
  }
97
105
  }
98
106
 
@@ -100,6 +108,7 @@ const COLLECTIONS = {
100
108
  AMOUNT_OF_JOBS_PER_DEPARTMENT: 'AmountOfJobsPerDepartment',
101
109
  CITIES: 'cities',
102
110
  JOBS: 'Jobs',
111
+ API_KEY: 'ApiKey',
103
112
  }
104
113
 
105
114
  const COLLECTIONS_FIELDS = {
@@ -132,7 +141,9 @@ const COLLECTIONS_FIELDS = {
132
141
  {key:'departmentref', type: 'REFERENCE', typeMetadata: { reference: { referencedCollectionId: 'AmountOfJobsPerDepartment' } } },
133
142
  {key:'city', type: 'REFERENCE', typeMetadata: { reference: { referencedCollectionId: 'cities' } } },
134
143
  ],
135
-
144
+ API_KEY: [
145
+ {key:'token', type: 'TEXT'},
146
+ ],
136
147
  };
137
148
 
138
149
 
@@ -146,4 +157,5 @@ const TASK_TYPE = {
146
157
  TASK_TYPE,
147
158
  TASKS,
148
159
  COLLECTIONS,
160
+ COLLECTIONS_FIELDS,
149
161
  };
package/backend/data.js CHANGED
@@ -1,6 +1,10 @@
1
1
  const { items: wixData } = require('@wix/data');
2
2
  const { fetchPositionsFromSRAPI, fetchJobDescription } = require('./fetchPositionsFromSRAPI');
3
3
  const { chunkedBulkOperation } = require('./utils');
4
+ const { createCollectionIfMissing } = require('@hisense-staging/velo-npm/backend');
5
+ const { COLLECTIONS, COLLECTIONS_FIELDS } = require('./consts');
6
+ const { secrets } = require("wix-secrets-backend.v2");
7
+ const { elevate } = require("wix-auth");
4
8
 
5
9
  // Utility function to normalize city names
6
10
  function normalizeCityName(city) {
@@ -314,9 +318,36 @@ function fetchJobLocation(jobDetails) {
314
318
 
315
319
  }
316
320
 
321
+
322
+
323
+ function getSmartToken() {
324
+ const elevatedGetSecretValue = elevate(secrets.getSecretValue);
325
+ return elevatedGetSecretValue("x-smarttoken")
326
+ .then((secret) => {
327
+ return secret;
328
+ })
329
+ .catch((error) => {
330
+ console.error(error);
331
+ });
332
+ }
333
+
334
+
335
+ async function createApiKeyCollectionAndFillIt() {
336
+ console.log("Creating ApiKey collection and filling it with the smart token");
337
+ await createCollectionIfMissing(COLLECTIONS.API_KEY, COLLECTIONS_FIELDS.API_KEY);
338
+ console.log("Getting the smart token");
339
+ const token = await getSmartToken();
340
+ console.log("Inserting the smart token into the ApiKey collection");
341
+ await wixData.insert("ApiKey", {
342
+ token: token
343
+ });
344
+ console.log("Smart token inserted into the ApiKey collection");
345
+ }
346
+
317
347
  module.exports = {
318
348
  saveDataJobsToCMS,
319
349
  saveJobsDescriptionsAndLocationToCMS,
320
350
  aggregateJobsByFieldToCMS,
321
351
  referenceJobsToField,
352
+ createApiKeyCollectionAndFillIt,
322
353
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sr-npm",
3
- "version": "1.7.10",
3
+ "version": "1.7.12",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {