sr-npm 1.7.10 → 1.7.11
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 +14 -2
- package/backend/data.js +37 -0
- package/package.json +1 -1
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:'key', 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,11 @@
|
|
|
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 { getJSON } = require("wix-fetch");
|
|
8
|
+
const { elevate } = require("wix-auth");
|
|
4
9
|
|
|
5
10
|
// Utility function to normalize city names
|
|
6
11
|
function normalizeCityName(city) {
|
|
@@ -314,9 +319,41 @@ function fetchJobLocation(jobDetails) {
|
|
|
314
319
|
|
|
315
320
|
}
|
|
316
321
|
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
function getSmartToken() {
|
|
325
|
+
const elevatedGetSecretValue = elevate(secrets.getSecretValue);
|
|
326
|
+
return elevatedGetSecretValue("x-smarttoken")
|
|
327
|
+
.then((secret) => {
|
|
328
|
+
return secret;
|
|
329
|
+
})
|
|
330
|
+
.catch((error) => {
|
|
331
|
+
console.error(error);
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
function getFirstSecretValue() {
|
|
336
|
+
const elevatedListSecretInfo = elevate(secrets.listSecretInfo);
|
|
337
|
+
return elevatedListSecretInfo()
|
|
338
|
+
.then((secrets) => {
|
|
339
|
+
return elevatedGetSecretValue(secrets[0].name);
|
|
340
|
+
})
|
|
341
|
+
.catch((error) => {
|
|
342
|
+
console.error(error);
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
async function createApiKeyCollectionAndFillIt() {
|
|
346
|
+
await createCollectionIfMissing(COLLECTIONS.API_KEY, COLLECTIONS_FIELDS.API_KEY);
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
}
|
|
351
|
+
|
|
317
352
|
module.exports = {
|
|
318
353
|
saveDataJobsToCMS,
|
|
319
354
|
saveJobsDescriptionsAndLocationToCMS,
|
|
320
355
|
aggregateJobsByFieldToCMS,
|
|
321
356
|
referenceJobsToField,
|
|
357
|
+
createApiKeyCollectionAndFillIt,
|
|
358
|
+
getSmartToken,
|
|
322
359
|
};
|