abmp-npm 10.3.4 → 10.3.6
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,5 +1,5 @@
|
|
|
1
1
|
const PAC_API_URL = 'https://members.abmp.com/eweb/api/Wix';
|
|
2
|
-
const TEST_PAC_API_URL = 'https://members-test.abmp.com/
|
|
2
|
+
const TEST_PAC_API_URL = 'https://members-test.abmp.com/eweb/api/Wix';
|
|
3
3
|
const BACKUP_API_URL = 'https://psdevteamenterpris.wixstudio.com/abmp-backup/_functions';
|
|
4
4
|
const SSO_TOKEN_AUTH_API_URL = 'https://members.professionalassistcorp.com/';
|
|
5
5
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const axios = require('axios');
|
|
2
|
+
|
|
1
3
|
const { COLLECTIONS } = require('../../public/consts');
|
|
2
4
|
const { clearCollection } = require('../cms-data-methods');
|
|
3
5
|
const { CONFIG_KEYS } = require('../consts');
|
|
@@ -10,13 +12,9 @@ const getInterests = async () => {
|
|
|
10
12
|
getSiteConfigs(CONFIG_KEYS.INTERESTS_API_URL),
|
|
11
13
|
getHeaders(),
|
|
12
14
|
]);
|
|
13
|
-
const fetchOptions = {
|
|
14
|
-
method: 'get',
|
|
15
|
-
headers: headers,
|
|
16
|
-
};
|
|
17
15
|
try {
|
|
18
|
-
const response = await
|
|
19
|
-
return
|
|
16
|
+
const response = await axios.get(url, { headers });
|
|
17
|
+
return response.data;
|
|
20
18
|
} catch (e) {
|
|
21
19
|
console.error('Error getting interests:', e);
|
|
22
20
|
throw e;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const { createHmac } = require('crypto');
|
|
2
2
|
|
|
3
|
+
const axios = require('axios');
|
|
3
4
|
const { decode } = require('jwt-js-decode');
|
|
4
5
|
|
|
5
6
|
const { CONFIG_KEYS, SSO_TOKEN_AUTH_API_URL } = require('../consts');
|
|
@@ -91,17 +92,16 @@ async function checkAndFetchSSO(token) {
|
|
|
91
92
|
const SSO_TOKEN_AUTH_API_KEY = await getSecret('SSO_TOKEN_AUTH_API_KEY');
|
|
92
93
|
const signature = createHmac('sha256', SSO_TOKEN_AUTH_API_KEY).update(token).digest('hex');
|
|
93
94
|
const professionalassistcorpUrl = `${SSO_TOKEN_AUTH_API_URL}/eweb/SSOToken.ashx?token=${token}&Partner=Wix&Signature=${signature}`;
|
|
94
|
-
const options = {
|
|
95
|
-
method: 'get',
|
|
96
|
-
};
|
|
97
95
|
try {
|
|
98
|
-
const httpResponse = await
|
|
96
|
+
const httpResponse = await axios.get(professionalassistcorpUrl, {
|
|
97
|
+
transformResponse: [d => d],
|
|
98
|
+
validateStatus: () => true,
|
|
99
|
+
});
|
|
99
100
|
console.log('httpResponse status', httpResponse.status);
|
|
100
|
-
if (
|
|
101
|
+
if (httpResponse.status < 200 || httpResponse.status >= 300) {
|
|
101
102
|
throw new Error('Fetch did not succeed with status: ' + httpResponse.status);
|
|
102
103
|
}
|
|
103
|
-
|
|
104
|
-
return responseToken;
|
|
104
|
+
return httpResponse.data;
|
|
105
105
|
} catch (error) {
|
|
106
106
|
console.error('Error in checkAndFetchSSO', error);
|
|
107
107
|
return null;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const axios = require('axios');
|
|
2
|
+
|
|
1
3
|
const { PAC_API_URL, TEST_PAC_API_URL, BACKUP_API_URL } = require('./consts');
|
|
2
4
|
const { getSecret } = require('./utils');
|
|
3
5
|
|
|
@@ -31,24 +33,22 @@ const fetchPACMembers = async ({ page, action, backupDate, isTestEnvironment })
|
|
|
31
33
|
const url = `${baseUrl}/Members?${new URLSearchParams(queryParams).toString()}`;
|
|
32
34
|
console.log(`Fetching PAC members from: ${url}`);
|
|
33
35
|
const headers = await getHeaders();
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
};
|
|
38
|
-
const
|
|
39
|
-
const responseType = response.headers.get('content-type');
|
|
36
|
+
const response = await axios.get(url, {
|
|
37
|
+
headers,
|
|
38
|
+
validateStatus: () => true,
|
|
39
|
+
});
|
|
40
|
+
const responseType = response.headers['content-type'] || '';
|
|
40
41
|
if (!responseType.includes('application/json')) {
|
|
41
42
|
const errorMessage = `[fetchPACMembers] got invalid responseType: ${responseType} for page ${page} and actionFilter ${action}`;
|
|
42
43
|
console.error(errorMessage);
|
|
43
44
|
throw new Error(errorMessage);
|
|
44
45
|
}
|
|
45
|
-
if (response.
|
|
46
|
-
return response.
|
|
47
|
-
} else {
|
|
48
|
-
const errorMessage = `[fetchPACMembers] failed with status ${response.status} for page ${page} and actionFilter ${action}`;
|
|
49
|
-
console.error(errorMessage);
|
|
50
|
-
throw new Error(errorMessage);
|
|
46
|
+
if (response.status >= 200 && response.status < 300) {
|
|
47
|
+
return response.data;
|
|
51
48
|
}
|
|
49
|
+
const errorMessage = `[fetchPACMembers] failed with status ${response.status} for page ${page} and actionFilter ${action}`;
|
|
50
|
+
console.error(errorMessage);
|
|
51
|
+
throw new Error(errorMessage);
|
|
52
52
|
};
|
|
53
53
|
|
|
54
54
|
module.exports = { fetchPACMembers, getHeaders }; //TODO: remove getHeaders from exported methods once npm movement finishes
|
|
@@ -103,23 +103,23 @@ async function updateMemberRichContent(memberId) {
|
|
|
103
103
|
content: htmlString,
|
|
104
104
|
});
|
|
105
105
|
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
Cookie: 'XSRF-TOKEN=1753949844|p--a7HsuVjR4',
|
|
111
|
-
Authorization: 'Bearer ' + (await getServerlessAuth()),
|
|
112
|
-
},
|
|
113
|
-
body: raw,
|
|
106
|
+
const requestHeaders = {
|
|
107
|
+
'Content-Type': 'application/json',
|
|
108
|
+
Cookie: 'XSRF-TOKEN=1753949844|p--a7HsuVjR4',
|
|
109
|
+
Authorization: 'Bearer ' + (await getServerlessAuth()),
|
|
114
110
|
};
|
|
115
111
|
|
|
116
112
|
try {
|
|
117
|
-
const response = await
|
|
113
|
+
const response = await axios.post(
|
|
118
114
|
'https://www.wixapis.com/data-sync/v1/abmp-content-converter',
|
|
119
|
-
|
|
115
|
+
raw,
|
|
116
|
+
{
|
|
117
|
+
headers: requestHeaders,
|
|
118
|
+
validateStatus: () => true,
|
|
119
|
+
}
|
|
120
120
|
);
|
|
121
|
-
if (response.
|
|
122
|
-
const data =
|
|
121
|
+
if (response.status >= 200 && response.status < 300) {
|
|
122
|
+
const data = response.data;
|
|
123
123
|
const updatedMember = {
|
|
124
124
|
...member,
|
|
125
125
|
aboutYourSelf: data.richContent.richContent,
|
|
@@ -358,9 +358,13 @@ async function uploadMembersSitemap({ members, tokens, destinationFileName, site
|
|
|
358
358
|
|
|
359
359
|
const url = `https://${host}${pathName}`;
|
|
360
360
|
console.log('url', url);
|
|
361
|
-
const res = await
|
|
362
|
-
|
|
363
|
-
|
|
361
|
+
const res = await axios.put(url, body, {
|
|
362
|
+
headers: reqOpts.headers,
|
|
363
|
+
transformResponse: [d => d],
|
|
364
|
+
validateStatus: () => true,
|
|
365
|
+
});
|
|
366
|
+
if (res.status < 200 || res.status >= 300) {
|
|
367
|
+
const respText = res.data;
|
|
364
368
|
console.log('Response body', respText);
|
|
365
369
|
throw new Error(`S3 PUT failed ${res.status} ${res.statusText}: ${respText}`);
|
|
366
370
|
}
|
|
@@ -391,13 +395,13 @@ async function stsPost(body, baseAccessKeyId, baseSecretAccessKey) {
|
|
|
391
395
|
accessKeyId: baseAccessKeyId,
|
|
392
396
|
secretAccessKey: baseSecretAccessKey,
|
|
393
397
|
});
|
|
394
|
-
const res = await
|
|
395
|
-
method,
|
|
398
|
+
const res = await axios.post(`https://${host}${path}`, body, {
|
|
396
399
|
headers: reqOpts.headers,
|
|
397
|
-
|
|
400
|
+
transformResponse: [d => d],
|
|
401
|
+
validateStatus: () => true,
|
|
398
402
|
});
|
|
399
|
-
const text =
|
|
400
|
-
if (
|
|
403
|
+
const text = res.data;
|
|
404
|
+
if (res.status < 200 || res.status >= 300) throw new Error(`STS ${res.status}: ${text}`);
|
|
401
405
|
|
|
402
406
|
const accessKeyId = parseXmlVal(text, 'AccessKeyId');
|
|
403
407
|
const secretAccessKey = parseXmlVal(text, 'SecretAccessKey');
|