abmp-npm 1.1.95 → 1.1.97
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.
|
@@ -11,7 +11,7 @@ const elevatedCreateContact = auth.elevate(contacts.createContact);
|
|
|
11
11
|
* @param {boolean} allowDuplicates - Allow duplicates if contact with same email already exists, will be true only when handling existing members, after that should be removed
|
|
12
12
|
* @returns {Promise<Object>} - Contact data
|
|
13
13
|
*/
|
|
14
|
-
async function
|
|
14
|
+
async function createContact(contactData, allowDuplicates = false) {
|
|
15
15
|
if (!contactData || !(contactData.contactFormEmail || contactData.email)) {
|
|
16
16
|
throw new Error('Contact data is required');
|
|
17
17
|
}
|
|
@@ -22,10 +22,10 @@ async function createSiteContact(contactData, allowDuplicates = false) {
|
|
|
22
22
|
first: contactData.firstName,
|
|
23
23
|
last: contactData.lastName,
|
|
24
24
|
},
|
|
25
|
-
emails:
|
|
26
|
-
items: [{ email: contactData.contactFormEmail || contactData.email, primary: true }],
|
|
27
|
-
|
|
28
|
-
phones: { items: phones.map(phone => ({ phone })) },
|
|
25
|
+
emails: [
|
|
26
|
+
{ items: [{ email: contactData.contactFormEmail || contactData.email, primary: true }] },
|
|
27
|
+
],
|
|
28
|
+
phones: [{ items: phones.map(phone => ({ phone })) }],
|
|
29
29
|
};
|
|
30
30
|
const createContactResponse = await elevatedCreateContact(contactInfo, { allowDuplicates });
|
|
31
31
|
return createContactResponse.contact._id;
|
|
@@ -157,5 +157,5 @@ const updateMemberContactInfo = async (data, existingMemberData) => {
|
|
|
157
157
|
|
|
158
158
|
module.exports = {
|
|
159
159
|
updateMemberContactInfo,
|
|
160
|
-
|
|
160
|
+
createContact,
|
|
161
161
|
};
|
|
@@ -5,7 +5,7 @@ const { decode } = require('jwt-js-decode');
|
|
|
5
5
|
const { CONFIG_KEYS, SSO_TOKEN_AUTH_API_URL } = require('../consts');
|
|
6
6
|
const { MEMBER_ACTIONS } = require('../daily-pull/consts');
|
|
7
7
|
const { getCurrentMember } = require('../members-area-methods');
|
|
8
|
-
const {
|
|
8
|
+
const { getMemberByContactId, prepareMemberForSSOLogin } = require('../members-data-methods');
|
|
9
9
|
const {
|
|
10
10
|
formatDateToMonthYear,
|
|
11
11
|
getAddressDisplayOptions,
|
|
@@ -37,12 +37,12 @@ async function validateMemberToken(memberIdInput) {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
const [dbMember, siteConfigs] = await Promise.all([
|
|
40
|
-
|
|
40
|
+
getMemberByContactId(member._id),
|
|
41
41
|
getSiteConfigs(),
|
|
42
42
|
]);
|
|
43
43
|
const siteAssociation = siteConfigs[CONFIG_KEYS.SITE_ASSOCIATION];
|
|
44
44
|
const membersExternalPortalUrl = siteConfigs[CONFIG_KEYS.MEMBERS_EXTERNAL_PORTAL_URL];
|
|
45
|
-
console.log('dbMember by
|
|
45
|
+
console.log('dbMember by contact id is:', dbMember);
|
|
46
46
|
console.log('member._id', member._id);
|
|
47
47
|
|
|
48
48
|
if (!dbMember?._id) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const { COLLECTIONS } = require('../public/consts');
|
|
2
2
|
|
|
3
3
|
const { MEMBERSHIPS_TYPES } = require('./consts');
|
|
4
|
-
const { updateMemberContactInfo,
|
|
4
|
+
const { updateMemberContactInfo, createContact } = require('./contacts-methods');
|
|
5
5
|
const { MEMBER_ACTIONS } = require('./daily-pull/consts');
|
|
6
6
|
const { wixData } = require('./elevated-modules');
|
|
7
7
|
const { createSiteMember, getCurrentMember } = require('./members-area-methods');
|
|
@@ -42,17 +42,14 @@ async function createContactAndMemberIfNew(memberData) {
|
|
|
42
42
|
phones: memberData.phones,
|
|
43
43
|
contactFormEmail: memberData.contactFormEmail || memberData.email,
|
|
44
44
|
};
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
needsWixContact && createSiteContact(toCreateMemberData),
|
|
50
|
-
].filter(Boolean);
|
|
51
|
-
const [newWixMemberId, newWixContactId] = await Promise.all(createPromises);
|
|
45
|
+
const [wixMemberId, wixContactId] = await Promise.all([
|
|
46
|
+
createSiteMember(toCreateMemberData),
|
|
47
|
+
createContact(toCreateMemberData),
|
|
48
|
+
]);
|
|
52
49
|
let memberDataWithContactId = {
|
|
53
50
|
...memberData,
|
|
54
|
-
wixMemberId
|
|
55
|
-
wixContactId
|
|
51
|
+
wixMemberId,
|
|
52
|
+
wixContactId,
|
|
56
53
|
};
|
|
57
54
|
const updatedResult = await updateMember(memberDataWithContactId);
|
|
58
55
|
memberDataWithContactId = {
|
|
@@ -176,26 +173,26 @@ async function getMemberBySlug({
|
|
|
176
173
|
}
|
|
177
174
|
}
|
|
178
175
|
|
|
179
|
-
async function
|
|
180
|
-
if (!
|
|
181
|
-
throw new Error('
|
|
176
|
+
async function getMemberByContactId(contactId) {
|
|
177
|
+
if (!contactId) {
|
|
178
|
+
throw new Error('Contact ID is required');
|
|
182
179
|
}
|
|
183
180
|
try {
|
|
184
181
|
const members = await wixData
|
|
185
182
|
.query(COLLECTIONS.MEMBERS_DATA)
|
|
186
|
-
.eq('
|
|
183
|
+
.eq('contactId', contactId)
|
|
187
184
|
.limit(2)
|
|
188
185
|
.find()
|
|
189
186
|
.then(res => res.items);
|
|
190
187
|
if (members.length > 1) {
|
|
191
188
|
throw new Error(
|
|
192
|
-
`[
|
|
189
|
+
`[getMemberByContactId] Multiple members found with contactId ${contactId} membersIds are : [${members.map(member => member.memberId).join(', ')}]`
|
|
193
190
|
);
|
|
194
191
|
}
|
|
195
192
|
return members[0] || null;
|
|
196
193
|
} catch (error) {
|
|
197
194
|
throw new Error(
|
|
198
|
-
`[
|
|
195
|
+
`[getMemberByContactId] Failed to retrieve member by contactId ${contactId} data: ${error.message}`
|
|
199
196
|
);
|
|
200
197
|
}
|
|
201
198
|
}
|
|
@@ -459,11 +456,11 @@ const getQAUsers = async () => {
|
|
|
459
456
|
* @param {Object} memberData - Member data from DB
|
|
460
457
|
* @returns {Promise<Object>} - Member data with contactId
|
|
461
458
|
*/
|
|
462
|
-
async function
|
|
459
|
+
async function ensureMemberHasContact(memberData) {
|
|
463
460
|
if (!memberData) {
|
|
464
461
|
throw new Error('Member data is required');
|
|
465
462
|
}
|
|
466
|
-
if (!memberData.
|
|
463
|
+
if (!memberData.contactId) {
|
|
467
464
|
const memberDataWithContactId = await createContactAndMemberIfNew(memberData);
|
|
468
465
|
return memberDataWithContactId;
|
|
469
466
|
}
|
|
@@ -481,7 +478,7 @@ async function prepareMemberForSSOLogin(data) {
|
|
|
481
478
|
throw new Error(`Member data not found for memberId ${memberId}`);
|
|
482
479
|
}
|
|
483
480
|
console.log('memberData', memberData);
|
|
484
|
-
return await
|
|
481
|
+
return await ensureMemberHasContact(memberData);
|
|
485
482
|
} catch (error) {
|
|
486
483
|
console.error('Error in prepareMemberForSSOLogin', error.message);
|
|
487
484
|
throw error;
|
|
@@ -498,7 +495,7 @@ async function prepareMemberForQALogin(email) {
|
|
|
498
495
|
throw new Error(`Member data not found for email ${email}`);
|
|
499
496
|
}
|
|
500
497
|
console.log('memberData', memberData);
|
|
501
|
-
return await
|
|
498
|
+
return await ensureMemberHasContact(memberData);
|
|
502
499
|
} catch (error) {
|
|
503
500
|
console.error('Error in prepareMemberForQALogin', error.message);
|
|
504
501
|
throw error;
|
|
@@ -520,7 +517,7 @@ async function trackButtonClick({ pageName, buttonName }) {
|
|
|
520
517
|
return null;
|
|
521
518
|
}
|
|
522
519
|
|
|
523
|
-
const dbMember = await
|
|
520
|
+
const dbMember = await getMemberByContactId(wixMember._id);
|
|
524
521
|
|
|
525
522
|
if (!dbMember) {
|
|
526
523
|
console.warn(
|
|
@@ -557,7 +554,7 @@ module.exports = {
|
|
|
557
554
|
bulkSaveMembers,
|
|
558
555
|
findMemberById,
|
|
559
556
|
getMemberBySlug,
|
|
560
|
-
|
|
557
|
+
getMemberByContactId,
|
|
561
558
|
getAllEmptyAboutYouMembers,
|
|
562
559
|
updateMember,
|
|
563
560
|
getAllMembersWithExternalImages,
|
|
@@ -138,20 +138,27 @@ async function updateMemberRichContent(memberId) {
|
|
|
138
138
|
async function updateMemberProfileImage(memberId) {
|
|
139
139
|
try {
|
|
140
140
|
const member = await findMemberByWixDataId(memberId);
|
|
141
|
-
|
|
141
|
+
const trimmedProfileImage = member.profileImage.trim();
|
|
142
142
|
// Check if member has an external profile image URL
|
|
143
|
-
if (
|
|
143
|
+
if (
|
|
144
|
+
!trimmedProfileImage ||
|
|
145
|
+
trimmedProfileImage.startsWith('wix:') ||
|
|
146
|
+
trimmedProfileImage.startsWith('https://static.wixstatic.com')
|
|
147
|
+
) {
|
|
144
148
|
console.log(`Member ${memberId} already has Wix-hosted image or no image`);
|
|
145
149
|
return { success: true, message: 'No update needed' };
|
|
146
150
|
}
|
|
147
151
|
|
|
148
152
|
// Validate image URL format before attempting download
|
|
149
|
-
if (!isValidImageUrl(
|
|
150
|
-
console.log(`Member ${memberId} has invalid image URL format: ${
|
|
153
|
+
if (!isValidImageUrl(trimmedProfileImage)) {
|
|
154
|
+
console.log(`Member ${memberId} has invalid image URL format: ${trimmedProfileImage}`);
|
|
151
155
|
return { success: true, message: 'Invalid image URL format - skipped' };
|
|
152
156
|
}
|
|
153
157
|
|
|
154
|
-
|
|
158
|
+
// Encode URL to handle spaces and special characters in the path
|
|
159
|
+
const encodedImageUrl = encodeURI(trimmedProfileImage);
|
|
160
|
+
|
|
161
|
+
const response = await axios.get(encodedImageUrl, {
|
|
155
162
|
responseType: 'arraybuffer',
|
|
156
163
|
headers: {
|
|
157
164
|
'User-Agent':
|