abmp-npm 1.8.30 → 1.8.32
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 +32 -2
- package/backend/consts.js +10 -2
- package/backend/contacts-methods.js +130 -0
- package/backend/daily-pull/bulk-process-methods.js +65 -0
- package/backend/daily-pull/consts.js +34 -0
- package/backend/daily-pull/index.js +4 -0
- package/backend/daily-pull/process-member-methods.js +290 -0
- package/backend/daily-pull/sync-to-cms-methods.js +114 -0
- package/backend/daily-pull/utils.js +78 -0
- package/backend/index.js +7 -2
- package/backend/jobs.js +30 -0
- package/backend/members-area-methods.js +48 -1
- package/backend/members-data-methods.js +95 -109
- package/backend/pac-api-methods.js +35 -0
- package/backend/tasks.js +37 -0
- package/backend/utils.js +74 -41
- package/eslint.config.js +1 -1
- package/package.json +4 -2
package/backend/utils.js
CHANGED
|
@@ -2,7 +2,7 @@ const { encode } = require('ngeohash');
|
|
|
2
2
|
|
|
3
3
|
const { COLLECTIONS } = require('../public/consts');
|
|
4
4
|
|
|
5
|
-
const { CONFIG_KEYS,
|
|
5
|
+
const { CONFIG_KEYS, GEO_HASH_PRECISION } = require('./consts');
|
|
6
6
|
const { wixData } = require('./elevated-modules');
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -81,43 +81,6 @@ function getAddressDisplayOptions(member) {
|
|
|
81
81
|
return displayOptions;
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
/**
|
|
85
|
-
* Get all interests from the database
|
|
86
|
-
* @returns {Promise<Array<string>>} Array of interest titles sorted alphabetically
|
|
87
|
-
*/
|
|
88
|
-
async function getInterestAll() {
|
|
89
|
-
try {
|
|
90
|
-
let res = await wixData.query('interests').limit(1000).find();
|
|
91
|
-
|
|
92
|
-
let interests = res.items.map(x => x.title);
|
|
93
|
-
|
|
94
|
-
while (res.hasNext()) {
|
|
95
|
-
res = await res.next();
|
|
96
|
-
interests.push(...res.items.map(x => x.title));
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// Sort the interests alphabetically (case-insensitive)
|
|
100
|
-
interests = interests.sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase()));
|
|
101
|
-
|
|
102
|
-
return interests;
|
|
103
|
-
} catch (e) {
|
|
104
|
-
console.error('Error in getInterestAll:', e);
|
|
105
|
-
throw e;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Generate geohash from addresses
|
|
111
|
-
* @param {Array} addresses - Array of address objects with latitude and longitude
|
|
112
|
-
* @returns {Array} Array of geohash strings
|
|
113
|
-
*/
|
|
114
|
-
function generateGeoHash(addresses) {
|
|
115
|
-
const geohash = addresses
|
|
116
|
-
?.filter(address => (isNaN(address?.latitude) && isNaN(address?.longitude) ? false : address))
|
|
117
|
-
?.map(address => encode(address.latitude, address.longitude, PRECISION));
|
|
118
|
-
return geohash && geohash.length > 0 ? geohash : [];
|
|
119
|
-
}
|
|
120
|
-
|
|
121
84
|
/**
|
|
122
85
|
* Checks if a URL already exists in the database for a different member (case-insensitive)
|
|
123
86
|
* @param {string} url - The URL to check
|
|
@@ -147,14 +110,84 @@ async function urlExists(url, excludeMemberId) {
|
|
|
147
110
|
return false;
|
|
148
111
|
}
|
|
149
112
|
}
|
|
113
|
+
const queryAllItems = async query => {
|
|
114
|
+
console.log('start query');
|
|
115
|
+
let oldResults = await query.find();
|
|
116
|
+
console.log(`found items: ${oldResults.items.length}`);
|
|
117
|
+
const allItems = oldResults.items;
|
|
118
|
+
while (oldResults.hasNext()) {
|
|
119
|
+
oldResults = await oldResults.next();
|
|
120
|
+
allItems.push(...oldResults.items);
|
|
121
|
+
}
|
|
122
|
+
console.log(`all items: ${allItems.length}`);
|
|
123
|
+
return allItems;
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* Batches large arrays into smaller chunks for processing
|
|
127
|
+
* @param {Array} array - Array to batch
|
|
128
|
+
* @param {number} batchSize - Size of each batch
|
|
129
|
+
* @returns {Array} - Array of batches
|
|
130
|
+
*/
|
|
131
|
+
const createBatches = (array, batchSize = 50) => {
|
|
132
|
+
const batches = [];
|
|
133
|
+
for (let i = 0; i < array.length; i += batchSize) {
|
|
134
|
+
batches.push(array.slice(i, i + batchSize));
|
|
135
|
+
}
|
|
136
|
+
return batches;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const generateGeoHash = addresses => {
|
|
140
|
+
const geohash = addresses
|
|
141
|
+
?.filter(address => (isNaN(address?.latitude) && isNaN(address?.longitude) ? false : address))
|
|
142
|
+
?.map(address => encode(address.latitude, address.longitude, GEO_HASH_PRECISION));
|
|
143
|
+
return geohash && geohash.length > 0 ? geohash : [];
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Validates if input is a non-empty array
|
|
148
|
+
* @param {*} input - Input to validate
|
|
149
|
+
* @returns {boolean} - True if input is a non-empty array
|
|
150
|
+
*/
|
|
151
|
+
const isValidArray = input => Array.isArray(input) && input.length > 0;
|
|
152
|
+
|
|
153
|
+
const normalizeUrlForComparison = url => {
|
|
154
|
+
if (!url) return url;
|
|
155
|
+
// Remove trailing pattern like "-1", "-2", etc.
|
|
156
|
+
return url.toLowerCase().replace(/-\d+$/, '');
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Checks URL uniqueness for a member
|
|
161
|
+
* @param {string} url - The URL to check
|
|
162
|
+
* @param {string} memberId - The member ID to exclude from the check
|
|
163
|
+
* @returns {Promise<Object>} Result object with isUnique boolean
|
|
164
|
+
*/
|
|
165
|
+
async function checkUrlUniqueness(url, memberId) {
|
|
166
|
+
if (!url || !memberId) {
|
|
167
|
+
throw new Error('Missing required parameters: url and memberId are required');
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
try {
|
|
171
|
+
const trimmedUrl = url.trim();
|
|
172
|
+
const exists = await urlExists(trimmedUrl, memberId);
|
|
173
|
+
|
|
174
|
+
return { isUnique: !exists };
|
|
175
|
+
} catch (error) {
|
|
176
|
+
console.error('Error checking URL uniqueness:', error);
|
|
177
|
+
throw new Error(`Failed to check URL uniqueness: ${error.message}`);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
150
180
|
|
|
151
181
|
module.exports = {
|
|
152
182
|
getSiteConfigs,
|
|
153
183
|
retrieveAllItems,
|
|
184
|
+
createBatches,
|
|
185
|
+
generateGeoHash,
|
|
186
|
+
isValidArray,
|
|
187
|
+
normalizeUrlForComparison,
|
|
188
|
+
queryAllItems,
|
|
189
|
+
checkUrlUniqueness,
|
|
154
190
|
formatDateToMonthYear,
|
|
155
191
|
isStudent,
|
|
156
192
|
getAddressDisplayOptions,
|
|
157
|
-
getInterestAll,
|
|
158
|
-
generateGeoHash,
|
|
159
|
-
urlExists,
|
|
160
193
|
};
|
package/eslint.config.js
CHANGED
|
@@ -31,7 +31,7 @@ module.exports = [
|
|
|
31
31
|
// Error prevention
|
|
32
32
|
'no-var': 'error',
|
|
33
33
|
'no-unused-vars': ['error', { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }],
|
|
34
|
-
'no-console': ['warn', { allow: ['warn', 'error', 'log', 'info'] }],
|
|
34
|
+
'no-console': ['warn', { allow: ['warn', 'error', 'log', 'info', 'group', 'groupEnd'] }],
|
|
35
35
|
'no-debugger': 'warn',
|
|
36
36
|
'no-duplicate-imports': 'error',
|
|
37
37
|
'no-unused-expressions': ['error', { allowShortCircuit: true, allowTernary: true }],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "abmp-npm",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.32",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
@@ -30,12 +30,14 @@
|
|
|
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.
|
|
33
|
+
"@wix/members": "^1.0.365",
|
|
34
|
+
"@wix/secrets": "^1.0.62",
|
|
34
35
|
"@wix/site-location": "^1.31.0",
|
|
35
36
|
"@wix/site-window": "^1.44.0",
|
|
36
37
|
"lodash": "^4.17.21",
|
|
37
38
|
"ngeohash": "^0.6.3",
|
|
38
39
|
"phone": "^3.1.67",
|
|
40
|
+
"psdev-task-manager": "1.1.7",
|
|
39
41
|
"psdev-utils": "1.1.1"
|
|
40
42
|
}
|
|
41
43
|
}
|