abmp-npm 10.3.3 → 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/nfpactest/eweb/api/Wix';
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,27 +1,18 @@
1
1
  const { items } = require('@wix/data');
2
2
  const { auth } = require('@wix/essentials');
3
3
 
4
- // @wix/data does not support suppressAuth currently, so we need to elevate it.
5
- // Elevation is deferred (called per-invocation) because @wix/data's `items.*`
6
- // methods are not guaranteed to be populated at module-load time in the Velo
7
- // cloud runtime — accessing them eagerly throws "Cannot read properties of
8
- // undefined (reading 'insert')" while loading the module.
9
- const elevated =
10
- method =>
11
- (...args) =>
12
- auth.elevate(items[method])(...args);
13
-
4
+ // @wix/data does not support suppressAuth currently, so we need to elevate it
14
5
  const wixData = {
15
- insert: elevated('insert'),
16
- update: elevated('update'),
17
- bulkInsert: elevated('bulkInsert'),
18
- query: elevated('query'),
19
- save: elevated('save'),
20
- remove: elevated('remove'),
21
- get: elevated('get'),
22
- truncate: elevated('truncate'),
23
- bulkSave: elevated('bulkSave'),
24
- search: elevated('search'),
6
+ insert: auth.elevate(items.insert),
7
+ update: auth.elevate(items.update),
8
+ bulkInsert: auth.elevate(items.bulkInsert),
9
+ query: auth.elevate(items.query),
10
+ save: auth.elevate(items.save),
11
+ remove: auth.elevate(items.remove),
12
+ get: auth.elevate(items.get),
13
+ truncate: auth.elevate(items.truncate),
14
+ bulkSave: auth.elevate(items.bulkSave),
15
+ search: auth.elevate(items.search),
25
16
  //TODO: add other methods here as needed
26
17
  };
27
18
  module.exports = { wixData };
@@ -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 fetch(url, fetchOptions);
19
- return await response.json();
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 fetch(professionalassistcorpUrl, options);
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 (!httpResponse.ok) {
101
+ if (httpResponse.status < 200 || httpResponse.status >= 300) {
101
102
  throw new Error('Fetch did not succeed with status: ' + httpResponse.status);
102
103
  }
103
- const responseToken = await httpResponse.text();
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 fetchOptions = {
35
- method: 'get',
36
- headers: headers,
37
- };
38
- const response = await fetch(url, fetchOptions);
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.ok) {
46
- return response.json();
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 requestOptions = {
107
- method: 'post',
108
- headers: {
109
- 'Content-Type': 'application/json',
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 fetch(
113
+ const response = await axios.post(
118
114
  'https://www.wixapis.com/data-sync/v1/abmp-content-converter',
119
- requestOptions
115
+ raw,
116
+ {
117
+ headers: requestHeaders,
118
+ validateStatus: () => true,
119
+ }
120
120
  );
121
- if (response.ok) {
122
- const data = await response.json();
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 fetch(url, { method, headers: reqOpts.headers, body });
362
- if (!res.ok) {
363
- const respText = await res.text();
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 fetch(`https://${host}${path}`, {
395
- method,
398
+ const res = await axios.post(`https://${host}${path}`, body, {
396
399
  headers: reqOpts.headers,
397
- body,
400
+ transformResponse: [d => d],
401
+ validateStatus: () => true,
398
402
  });
399
- const text = await res.text();
400
- if (!res.ok) throw new Error(`STS ${res.status}: ${text}`);
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');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "abmp-npm",
3
- "version": "10.3.3",
3
+ "version": "10.3.6",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "check-cycles": "madge --circular .",