abmp-npm 1.8.31 → 1.8.33
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 +8 -13
- 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 +123 -126
- package/backend/pac-api-methods.js +35 -0
- package/backend/tasks.js +37 -0
- package/backend/utils.js +58 -53
- package/eslint.config.js +1 -1
- package/package.json +4 -2
package/backend/utils.js
CHANGED
|
@@ -2,8 +2,9 @@ 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
|
+
const { urlExists } = require('./members-data-methods');
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Retrieves site configuration values from the database
|
|
@@ -81,80 +82,84 @@ function getAddressDisplayOptions(member) {
|
|
|
81
82
|
return displayOptions;
|
|
82
83
|
}
|
|
83
84
|
|
|
85
|
+
const queryAllItems = async query => {
|
|
86
|
+
console.log('start query');
|
|
87
|
+
let oldResults = await query.find();
|
|
88
|
+
console.log(`found items: ${oldResults.items.length}`);
|
|
89
|
+
const allItems = oldResults.items;
|
|
90
|
+
while (oldResults.hasNext()) {
|
|
91
|
+
oldResults = await oldResults.next();
|
|
92
|
+
allItems.push(...oldResults.items);
|
|
93
|
+
}
|
|
94
|
+
console.log(`all items: ${allItems.length}`);
|
|
95
|
+
return allItems;
|
|
96
|
+
};
|
|
84
97
|
/**
|
|
85
|
-
*
|
|
86
|
-
* @
|
|
98
|
+
* Batches large arrays into smaller chunks for processing
|
|
99
|
+
* @param {Array} array - Array to batch
|
|
100
|
+
* @param {number} batchSize - Size of each batch
|
|
101
|
+
* @returns {Array} - Array of batches
|
|
87
102
|
*/
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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;
|
|
103
|
+
const createBatches = (array, batchSize = 50) => {
|
|
104
|
+
const batches = [];
|
|
105
|
+
for (let i = 0; i < array.length; i += batchSize) {
|
|
106
|
+
batches.push(array.slice(i, i + batchSize));
|
|
106
107
|
}
|
|
107
|
-
|
|
108
|
+
return batches;
|
|
109
|
+
};
|
|
108
110
|
|
|
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) {
|
|
111
|
+
const generateGeoHash = addresses => {
|
|
115
112
|
const geohash = addresses
|
|
116
113
|
?.filter(address => (isNaN(address?.latitude) && isNaN(address?.longitude) ? false : address))
|
|
117
|
-
?.map(address => encode(address.latitude, address.longitude,
|
|
114
|
+
?.map(address => encode(address.latitude, address.longitude, GEO_HASH_PRECISION));
|
|
118
115
|
return geohash && geohash.length > 0 ? geohash : [];
|
|
119
|
-
}
|
|
116
|
+
};
|
|
120
117
|
|
|
121
118
|
/**
|
|
122
|
-
*
|
|
123
|
-
* @param {
|
|
124
|
-
* @
|
|
125
|
-
* @returns {Promise<boolean>} - True if URL exists for another member
|
|
119
|
+
* Validates if input is a non-empty array
|
|
120
|
+
* @param {*} input - Input to validate
|
|
121
|
+
* @returns {boolean} - True if input is a non-empty array
|
|
126
122
|
*/
|
|
127
|
-
|
|
128
|
-
if (!url) return false;
|
|
129
|
-
|
|
130
|
-
try {
|
|
131
|
-
let query = wixData.query(COLLECTIONS.MEMBERS_DATA).contains('url', url).ne('action', 'drop');
|
|
123
|
+
const isValidArray = input => Array.isArray(input) && input.length > 0;
|
|
132
124
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
125
|
+
const normalizeUrlForComparison = url => {
|
|
126
|
+
if (!url) return url;
|
|
127
|
+
// Remove trailing pattern like "-1", "-2", etc.
|
|
128
|
+
return url.toLowerCase().replace(/-\d+$/, '');
|
|
129
|
+
};
|
|
136
130
|
|
|
137
|
-
|
|
131
|
+
/**
|
|
132
|
+
* Checks URL uniqueness for a member
|
|
133
|
+
* @param {string} url - The URL to check
|
|
134
|
+
* @param {string} memberId - The member ID to exclude from the check
|
|
135
|
+
* @returns {Promise<Object>} Result object with isUnique boolean
|
|
136
|
+
*/
|
|
137
|
+
async function checkUrlUniqueness(url, memberId) {
|
|
138
|
+
if (!url || !memberId) {
|
|
139
|
+
throw new Error('Missing required parameters: url and memberId are required');
|
|
140
|
+
}
|
|
138
141
|
|
|
139
|
-
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
);
|
|
142
|
+
try {
|
|
143
|
+
const trimmedUrl = url.trim();
|
|
144
|
+
const exists = await urlExists(trimmedUrl, memberId);
|
|
143
145
|
|
|
144
|
-
return
|
|
146
|
+
return { isUnique: !exists };
|
|
145
147
|
} catch (error) {
|
|
146
|
-
console.error('Error checking URL
|
|
147
|
-
|
|
148
|
+
console.error('Error checking URL uniqueness:', error);
|
|
149
|
+
throw new Error(`Failed to check URL uniqueness: ${error.message}`);
|
|
148
150
|
}
|
|
149
151
|
}
|
|
150
152
|
|
|
151
153
|
module.exports = {
|
|
152
154
|
getSiteConfigs,
|
|
153
155
|
retrieveAllItems,
|
|
156
|
+
createBatches,
|
|
157
|
+
generateGeoHash,
|
|
158
|
+
isValidArray,
|
|
159
|
+
normalizeUrlForComparison,
|
|
160
|
+
queryAllItems,
|
|
161
|
+
checkUrlUniqueness,
|
|
154
162
|
formatDateToMonthYear,
|
|
155
163
|
isStudent,
|
|
156
164
|
getAddressDisplayOptions,
|
|
157
|
-
getInterestAll,
|
|
158
|
-
generateGeoHash,
|
|
159
|
-
urlExists,
|
|
160
165
|
};
|
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.33",
|
|
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
|
}
|