sr-npm 1.7.9 → 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 +43 -3
- 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) {
|
|
@@ -300,20 +305,55 @@ function fetchJobLocation(jobDetails) {
|
|
|
300
305
|
},
|
|
301
306
|
city: jobDetails.location.city,
|
|
302
307
|
country: jobDetails.location.country,
|
|
303
|
-
formatted:
|
|
308
|
+
formatted: [
|
|
309
|
+
jobDetails.location.city,
|
|
310
|
+
jobDetails.location.region,
|
|
311
|
+
jobDetails.location.regionCode,
|
|
312
|
+
jobDetails.location.country
|
|
313
|
+
].filter(Boolean).join(', '),
|
|
304
314
|
streetAddress: {},
|
|
305
315
|
subdivision: "",
|
|
306
316
|
postalCode: ""
|
|
307
317
|
};
|
|
308
|
-
|
|
309
|
-
console.log("jobLocation", jobLocation);
|
|
310
318
|
return jobLocation;
|
|
311
319
|
|
|
312
320
|
}
|
|
313
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
|
+
|
|
314
352
|
module.exports = {
|
|
315
353
|
saveDataJobsToCMS,
|
|
316
354
|
saveJobsDescriptionsAndLocationToCMS,
|
|
317
355
|
aggregateJobsByFieldToCMS,
|
|
318
356
|
referenceJobsToField,
|
|
357
|
+
createApiKeyCollectionAndFillIt,
|
|
358
|
+
getSmartToken,
|
|
319
359
|
};
|