abmp-npm 1.1.51 → 1.6.0
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/cms-data-methods.js +2 -6
- package/backend/consts.js +2 -10
- package/backend/index.js +0 -6
- package/backend/members-area-methods.js +1 -48
- package/backend/members-data-methods.js +0 -111
- package/backend/utils.js +1 -54
- package/package.json +2 -4
- package/pages/PersonalDetailsForm.js +1989 -0
- package/pages/index.js +1 -0
- package/backend/daily-pull/bulk-process-methods.js +0 -65
- package/backend/daily-pull/consts.js +0 -34
- package/backend/daily-pull/index.js +0 -4
- package/backend/daily-pull/process-member-methods.js +0 -290
- package/backend/daily-pull/sync-to-cms-methods.js +0 -114
- package/backend/daily-pull/utils.js +0 -78
- package/backend/jobs.js +0 -30
- package/backend/pac-api-methods.js +0 -35
- package/backend/tasks.js +0 -37
|
@@ -4,11 +4,7 @@ const { COLLECTIONS, MEMBERS_FIELDS } = require('../public/consts.js');
|
|
|
4
4
|
const { findMainAddress } = require('../public/Utils/sharedUtils.js');
|
|
5
5
|
const { calculateDistance, shuffleArray } = require('../public/Utils/sharedUtils.js');
|
|
6
6
|
|
|
7
|
-
const {
|
|
8
|
-
GEO_HASH_PRECISION,
|
|
9
|
-
MAX__MEMBERS_SEARCH_RESULTS,
|
|
10
|
-
WIX_QUERY_MAX_LIMIT,
|
|
11
|
-
} = require('./consts.js');
|
|
7
|
+
const { PRECISION, MAX__MEMBERS_SEARCH_RESULTS, WIX_QUERY_MAX_LIMIT } = require('./consts.js');
|
|
12
8
|
const { wixData } = require('./elevated-modules');
|
|
13
9
|
|
|
14
10
|
function buildMembersSearchQuery(data) {
|
|
@@ -96,7 +92,7 @@ function buildMembersSearchQuery(data) {
|
|
|
96
92
|
query = applyFilterToQuery(query, config, filter);
|
|
97
93
|
});
|
|
98
94
|
if (isUserLocationEnabled && isSearchingNearby) {
|
|
99
|
-
const userGeohash = geohash.encode(filter.latitude, filter.longitude,
|
|
95
|
+
const userGeohash = geohash.encode(filter.latitude, filter.longitude, PRECISION);
|
|
100
96
|
const neighborGeohashes = geohash.neighbors(userGeohash);
|
|
101
97
|
const geohashList = [userGeohash, ...neighborGeohashes];
|
|
102
98
|
query = query.hasSome('locHash', geohashList);
|
package/backend/consts.js
CHANGED
|
@@ -8,21 +8,13 @@ const CONFIG_KEYS = {
|
|
|
8
8
|
SITE_ASSOCIATION: 'SITE_ASSOCIATION',
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
+
const PRECISION = 3;
|
|
11
12
|
const MAX__MEMBERS_SEARCH_RESULTS = 120;
|
|
12
13
|
const WIX_QUERY_MAX_LIMIT = 1000;
|
|
13
14
|
|
|
14
|
-
const TASKS_NAMES = {
|
|
15
|
-
ScheduleDailyMembersDataSync: 'ScheduleDailyMembersDataSync',
|
|
16
|
-
ScheduleMembersDataPerAction: 'ScheduleMembersDataPerAction',
|
|
17
|
-
SyncMembers: 'SyncMembers',
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const GEO_HASH_PRECISION = 3;
|
|
21
|
-
|
|
22
15
|
module.exports = {
|
|
23
16
|
CONFIG_KEYS,
|
|
17
|
+
PRECISION,
|
|
24
18
|
MAX__MEMBERS_SEARCH_RESULTS,
|
|
25
19
|
WIX_QUERY_MAX_LIMIT,
|
|
26
|
-
TASKS_NAMES,
|
|
27
|
-
GEO_HASH_PRECISION,
|
|
28
20
|
};
|
package/backend/index.js
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
module.exports = {
|
|
2
2
|
...require('./forms-methods'),
|
|
3
3
|
...require('./search-filters-methods'),
|
|
4
|
-
...require('./jobs'),
|
|
5
|
-
...require('./utils'), //TODO: remove it once we finish NPM movement
|
|
6
|
-
...require('./daily-pull'), //TODO: remove it once we finish NPM movement
|
|
7
|
-
...require('./pac-api-methods'), //TODO: remove it once we finish NPM movement
|
|
8
|
-
...require('./members-area-methods'), //TODO: remove it once we finish NPM movement
|
|
9
|
-
...require('./members-data-methods'), //TODO: remove it once we finish NPM movement
|
|
10
4
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const { auth } = require('@wix/essentials');
|
|
2
|
-
const { members
|
|
2
|
+
const { members } = require('@wix/members');
|
|
3
3
|
const elevatedCreateMember = auth.elevate(members.createMember);
|
|
4
4
|
|
|
5
5
|
function prepareContactData(partner) {
|
|
@@ -31,53 +31,6 @@ const createSiteMember = async memberDetails => {
|
|
|
31
31
|
}
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
-
/**
|
|
35
|
-
* Updates Wix member login email if the member has a contactId (registered Wix member)
|
|
36
|
-
* @param {Object} member - Member object with contactId and email
|
|
37
|
-
* @param {Object} result - Result object to track Wix member updates
|
|
38
|
-
*/
|
|
39
|
-
async function updateWixMemberLoginEmail(member, result = {}) {
|
|
40
|
-
if (!member.contactId) {
|
|
41
|
-
console.log(`Member ${member.memberId} has no contactId - skipping Wix login email update`);
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
try {
|
|
46
|
-
console.log(
|
|
47
|
-
`Updating Wix login email for member ${member.memberId} (contactId: ${member.contactId})`
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
const updatedWixMember = await authentication.changeLoginEmail(member.contactId, member.email);
|
|
51
|
-
|
|
52
|
-
console.log(
|
|
53
|
-
`✅ Successfully updated Wix login email for member ${member.memberId}: ${updatedWixMember.loginEmail}`
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
if (!result.wixMemberUpdates) {
|
|
57
|
-
result.wixMemberUpdates = { successful: 0, failed: 0 };
|
|
58
|
-
}
|
|
59
|
-
result.wixMemberUpdates.successful++;
|
|
60
|
-
} catch (error) {
|
|
61
|
-
console.error(`❌ Failed to update Wix login email for member ${member.memberId}:`, error);
|
|
62
|
-
|
|
63
|
-
if (!result.wixMemberUpdates) {
|
|
64
|
-
result.wixMemberUpdates = { successful: 0, failed: 0 };
|
|
65
|
-
}
|
|
66
|
-
result.wixMemberUpdates.failed++;
|
|
67
|
-
|
|
68
|
-
if (!result.wixMemberErrors) {
|
|
69
|
-
result.wixMemberErrors = [];
|
|
70
|
-
}
|
|
71
|
-
result.wixMemberErrors.push({
|
|
72
|
-
memberId: member.memberId,
|
|
73
|
-
contactId: member.contactId,
|
|
74
|
-
email: member.email,
|
|
75
|
-
error: error.message,
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
34
|
module.exports = {
|
|
81
35
|
createSiteMember,
|
|
82
|
-
updateWixMemberLoginEmail,
|
|
83
36
|
};
|
|
@@ -2,7 +2,6 @@ const { COLLECTIONS } = require('../public/consts');
|
|
|
2
2
|
|
|
3
3
|
const { wixData } = require('./elevated-modules');
|
|
4
4
|
const { createSiteMember } = require('./members-area-methods');
|
|
5
|
-
const { createBatches, normalizeUrlForComparison, queryAllItems } = require('./utils');
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* Retrieves member data by member ID
|
|
@@ -50,117 +49,7 @@ async function createContactAndMemberIfNew(memberData) {
|
|
|
50
49
|
}
|
|
51
50
|
}
|
|
52
51
|
|
|
53
|
-
/**
|
|
54
|
-
* Performs bulk save operation for member data
|
|
55
|
-
* @param {Array} memberDataList - Array of member data objects to save
|
|
56
|
-
* @returns {Promise<Object>} - Bulk save operation result
|
|
57
|
-
*/
|
|
58
|
-
async function bulkSaveMembers(memberDataList) {
|
|
59
|
-
if (!Array.isArray(memberDataList) || memberDataList.length === 0) {
|
|
60
|
-
throw new Error('Invalid member data list provided for bulk save');
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
try {
|
|
64
|
-
// bulkSave all with batches of 1000 items as this is the Velo limit for bulkSave
|
|
65
|
-
const batches = createBatches(memberDataList, 1000);
|
|
66
|
-
return await Promise.all(
|
|
67
|
-
batches.map(batch => wixData.bulkSave(COLLECTIONS.MEMBERS_DATA, batch))
|
|
68
|
-
);
|
|
69
|
-
} catch (error) {
|
|
70
|
-
console.error('Error bulk saving members:', error);
|
|
71
|
-
throw new Error(`Bulk save failed: ${error.message}`);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Retrieves member data by member ID
|
|
76
|
-
* @param {string} memberId - The member ID to search for
|
|
77
|
-
* @returns {Promise<Object|null>} - Member data or null if not found
|
|
78
|
-
*/
|
|
79
|
-
async function findMemberById(memberId) {
|
|
80
|
-
if (!memberId) {
|
|
81
|
-
throw new Error('Member ID is required');
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
try {
|
|
85
|
-
const queryResult = await wixData
|
|
86
|
-
.query(COLLECTIONS.MEMBERS_DATA)
|
|
87
|
-
.eq('memberId', memberId)
|
|
88
|
-
.find();
|
|
89
|
-
|
|
90
|
-
return queryResult.items.length > 0 ? queryResult.items[0] : null;
|
|
91
|
-
} catch (error) {
|
|
92
|
-
throw new Error(`Failed to retrieve member data: ${error.message}`);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Method to get member by slug with flexible filtering options
|
|
98
|
-
* @param {Object} options - Query options
|
|
99
|
-
* @param {string} options.slug - The slug to search for
|
|
100
|
-
* @param {boolean} options.excludeDropped - Whether to exclude dropped members (default: true)
|
|
101
|
-
* @param {boolean} options.excludeSearchedMember - Whether to exclude a specific member (default: false)
|
|
102
|
-
* @param {string|number} [options.memberId] - Member ID to exclude when excludeSearchedMember is true (optional)
|
|
103
|
-
* @param {boolean} [options.queryAllMatches=false] - Whether to query all matches or just the first one (default: false)
|
|
104
|
-
* @returns {Promise<Object|null>} - Member data or null if not found
|
|
105
|
-
*/
|
|
106
|
-
async function getMemberBySlug({
|
|
107
|
-
slug,
|
|
108
|
-
excludeDropped = true,
|
|
109
|
-
excludeSearchedMember = false,
|
|
110
|
-
memberId = null,
|
|
111
|
-
queryAllMatches = false,
|
|
112
|
-
}) {
|
|
113
|
-
if (!slug) return null;
|
|
114
|
-
|
|
115
|
-
try {
|
|
116
|
-
let query = wixData.query(COLLECTIONS.MEMBERS_DATA).contains('url', slug);
|
|
117
|
-
|
|
118
|
-
if (excludeDropped) {
|
|
119
|
-
query = query.ne('action', 'drop');
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (excludeSearchedMember && memberId) {
|
|
123
|
-
query = query.ne('memberId', memberId);
|
|
124
|
-
}
|
|
125
|
-
let membersList;
|
|
126
|
-
if (queryAllMatches) {
|
|
127
|
-
query = query.limit(1000);
|
|
128
|
-
membersList = await queryAllItems(query);
|
|
129
|
-
} else {
|
|
130
|
-
membersList = await query.find().then(res => res.items);
|
|
131
|
-
}
|
|
132
|
-
let matchingMembers = membersList.filter(
|
|
133
|
-
item => item.url && item.url.toLowerCase() === slug.toLowerCase()
|
|
134
|
-
);
|
|
135
|
-
if (queryAllMatches) {
|
|
136
|
-
matchingMembers = membersList
|
|
137
|
-
.filter(
|
|
138
|
-
//remove trailing "-1", "-2", etc.
|
|
139
|
-
item => item.url && normalizeUrlForComparison(item.url) === slug.toLowerCase()
|
|
140
|
-
)
|
|
141
|
-
.sort((a, b) => b.url.toLowerCase().localeCompare(a.url.toLowerCase()));
|
|
142
|
-
}
|
|
143
|
-
if (matchingMembers.length > 1) {
|
|
144
|
-
const queryResultMsg = `Multiple members found with same slug ${slug} membersIds are : [${matchingMembers
|
|
145
|
-
.map(member => member.memberId)
|
|
146
|
-
.join(', ')}]`;
|
|
147
|
-
if (!queryAllMatches) {
|
|
148
|
-
throw new Error(queryResultMsg);
|
|
149
|
-
} else {
|
|
150
|
-
console.log(queryResultMsg);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
return matchingMembers[0] || null;
|
|
154
|
-
} catch (error) {
|
|
155
|
-
console.error('Error getting member by slug:', error);
|
|
156
|
-
throw error;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
52
|
module.exports = {
|
|
161
53
|
findMemberByWixDataId,
|
|
162
54
|
createContactAndMemberIfNew,
|
|
163
|
-
bulkSaveMembers,
|
|
164
|
-
findMemberById,
|
|
165
|
-
getMemberBySlug,
|
|
166
55
|
};
|
package/backend/utils.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
const { encode } = require('ngeohash');
|
|
2
|
-
|
|
3
1
|
const { COLLECTIONS } = require('../public/consts');
|
|
4
2
|
|
|
5
|
-
const { CONFIG_KEYS
|
|
3
|
+
const { CONFIG_KEYS } = require('./consts');
|
|
6
4
|
const { wixData } = require('./elevated-modules');
|
|
7
5
|
|
|
8
6
|
/**
|
|
@@ -41,58 +39,7 @@ const retrieveAllItems = async collectionName => {
|
|
|
41
39
|
return allItems;
|
|
42
40
|
};
|
|
43
41
|
|
|
44
|
-
const queryAllItems = async query => {
|
|
45
|
-
console.log('start query');
|
|
46
|
-
let oldResults = await query.find();
|
|
47
|
-
console.log(`found items: ${oldResults.items.length}`);
|
|
48
|
-
const allItems = oldResults.items;
|
|
49
|
-
while (oldResults.hasNext()) {
|
|
50
|
-
oldResults = await oldResults.next();
|
|
51
|
-
allItems.push(...oldResults.items);
|
|
52
|
-
}
|
|
53
|
-
console.log(`all items: ${allItems.length}`);
|
|
54
|
-
return allItems;
|
|
55
|
-
};
|
|
56
|
-
/**
|
|
57
|
-
* Batches large arrays into smaller chunks for processing
|
|
58
|
-
* @param {Array} array - Array to batch
|
|
59
|
-
* @param {number} batchSize - Size of each batch
|
|
60
|
-
* @returns {Array} - Array of batches
|
|
61
|
-
*/
|
|
62
|
-
const createBatches = (array, batchSize = 50) => {
|
|
63
|
-
const batches = [];
|
|
64
|
-
for (let i = 0; i < array.length; i += batchSize) {
|
|
65
|
-
batches.push(array.slice(i, i + batchSize));
|
|
66
|
-
}
|
|
67
|
-
return batches;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
const generateGeoHash = addresses => {
|
|
71
|
-
const geohash = addresses
|
|
72
|
-
?.filter(address => (isNaN(address?.latitude) && isNaN(address?.longitude) ? false : address))
|
|
73
|
-
?.map(address => encode(address.latitude, address.longitude, GEO_HASH_PRECISION));
|
|
74
|
-
return geohash && geohash.length > 0 ? geohash : [];
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Validates if input is a non-empty array
|
|
79
|
-
* @param {*} input - Input to validate
|
|
80
|
-
* @returns {boolean} - True if input is a non-empty array
|
|
81
|
-
*/
|
|
82
|
-
const isValidArray = input => Array.isArray(input) && input.length > 0;
|
|
83
|
-
|
|
84
|
-
const normalizeUrlForComparison = url => {
|
|
85
|
-
if (!url) return url;
|
|
86
|
-
// Remove trailing pattern like "-1", "-2", etc.
|
|
87
|
-
return url.toLowerCase().replace(/-\d+$/, '');
|
|
88
|
-
};
|
|
89
|
-
|
|
90
42
|
module.exports = {
|
|
91
43
|
getSiteConfigs,
|
|
92
44
|
retrieveAllItems,
|
|
93
|
-
createBatches,
|
|
94
|
-
generateGeoHash,
|
|
95
|
-
isValidArray,
|
|
96
|
-
normalizeUrlForComparison,
|
|
97
|
-
queryAllItems,
|
|
98
45
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "abmp-npm",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
@@ -30,13 +30,11 @@
|
|
|
30
30
|
"@wix/crm": "^1.0.1061",
|
|
31
31
|
"@wix/data": "^1.0.303",
|
|
32
32
|
"@wix/essentials": "^0.1.28",
|
|
33
|
-
"@wix/members": "^1.0.
|
|
34
|
-
"@wix/secrets": "^1.0.62",
|
|
33
|
+
"@wix/members": "^1.0.330",
|
|
35
34
|
"@wix/site-location": "^1.31.0",
|
|
36
35
|
"@wix/site-window": "^1.44.0",
|
|
37
36
|
"ngeohash": "^0.6.3",
|
|
38
37
|
"phone": "^3.1.67",
|
|
39
|
-
"psdev-task-manager": "1.1.7",
|
|
40
38
|
"psdev-utils": "1.1.1"
|
|
41
39
|
}
|
|
42
40
|
}
|