abmp-npm 1.1.87 → 1.1.89

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.
@@ -8,6 +8,7 @@ const {
8
8
  GEO_HASH_PRECISION,
9
9
  MAX__MEMBERS_SEARCH_RESULTS,
10
10
  WIX_QUERY_MAX_LIMIT,
11
+ MEMBERSHIPS_TYPES,
11
12
  } = require('./consts.js');
12
13
  const { wixData } = require('./elevated-modules');
13
14
 
@@ -31,6 +32,7 @@ function buildMembersSearchQuery(data) {
31
32
  .query(COLLECTIONS.MEMBERS_DATA)
32
33
  .ne('optOut', true)
33
34
  .ne('action', 'drop')
35
+ .ne('memberships.membertype', MEMBERSHIPS_TYPES.PAC_STAFF)
34
36
  .eq('isVisible', true);
35
37
  let filterConfig = [
36
38
  {
@@ -105,7 +107,7 @@ function buildMembersSearchQuery(data) {
105
107
  query = query.contains('fullName', filter.searchText);
106
108
  }
107
109
  if (!includeStudents) {
108
- query = query.ne('memberships.membertype', 'Student');
110
+ query = query.ne('memberships.membertype', MEMBERSHIPS_TYPES.STUDENT);
109
111
  }
110
112
  return query;
111
113
  },
@@ -14,13 +14,18 @@ async function updateContactInfo(contactId, updateInfoCallback, operationName) {
14
14
  if (!contactId) {
15
15
  throw new Error('Contact ID is required');
16
16
  }
17
-
17
+ console.log('updateContactInfo contactId', contactId);
18
+ console.log('updateContactInfo operationName', operationName);
18
19
  try {
19
20
  const contact = await elevatedGetContact(contactId);
21
+ console.log('updateContactInfo contact', contact);
20
22
  const currentInfo = contact.info;
23
+ console.log('updateContactInfo currentInfo', currentInfo);
21
24
  const updatedInfo = updateInfoCallback(currentInfo);
22
-
23
- await elevatedUpdateContact(contactId, updatedInfo, contact.revision);
25
+ console.log('updateContactInfo updatedInfo', updatedInfo);
26
+ const updatedContact = await elevatedUpdateContact(contactId, updatedInfo, contact.revision);
27
+ console.log('updateContactInfo updatedContact', updatedContact);
28
+ return updatedContact;
24
29
  } catch (error) {
25
30
  console.error(`Error in ${operationName}:`, error);
26
31
  throw new Error(`Failed to ${operationName}: ${error.message}`);
@@ -33,6 +38,8 @@ async function updateContactInfo(contactId, updateInfoCallback, operationName) {
33
38
  * @param {string} newEmail - The new email address
34
39
  */
35
40
  async function updateContactEmail(contactId, newEmail) {
41
+ console.log('updateContactEmail contactId', contactId);
42
+ console.log('updateContactEmail newEmail', newEmail);
36
43
  if (!newEmail) {
37
44
  throw new Error('New email is required');
38
45
  }
@@ -88,6 +95,7 @@ async function updateContactNames(contactId, firstName, lastName) {
88
95
  const updateIfChanged = (existingValues, newValues, updater, argsBuilder) => {
89
96
  const hasChanged = existingValues.some((val, idx) => val !== newValues[idx]);
90
97
  if (!hasChanged) return null;
98
+ console.log('updateIfChanged hasChanged', hasChanged);
91
99
  return updater(...argsBuilder(newValues));
92
100
  };
93
101
 
@@ -98,7 +106,7 @@ const updateIfChanged = (existingValues, newValues, updater, argsBuilder) => {
98
106
  */
99
107
  const updateMemberContactInfo = async (data, existingMemberData) => {
100
108
  const { contactId } = existingMemberData;
101
-
109
+ console.log('updateMemberContactInfo contactId', contactId);
102
110
  const updateConfig = [
103
111
  {
104
112
  fields: ['contactFormEmail'],
@@ -120,7 +128,9 @@ const updateMemberContactInfo = async (data, existingMemberData) => {
120
128
  })
121
129
  .filter(Boolean);
122
130
 
123
- await Promise.all(updatePromises);
131
+ const resp = await Promise.all(updatePromises);
132
+ console.log('updateMemberContactInfo updatePromises', resp);
133
+ return resp;
124
134
  };
125
135
 
126
136
  module.exports = {
@@ -9,7 +9,8 @@ const { queryAllItems, chunkArray } = require('../utils');
9
9
  const { TASKS_NAMES } = require('./consts');
10
10
 
11
11
  const COLLECTION_WITH_URLS = 'MembersDataWithUrls';
12
- const CHUNK_SIZE = 5000; // 5k members per task
12
+ const CHUNK_SIZE = 5000; // 5k members per task for migration
13
+ const GENERATION_CHUNK_SIZE = 1000; // 1k members per task for URL generation
13
14
 
14
15
  /**
15
16
  * Step 1: Migrate existing URLs from backup collection
@@ -201,7 +202,7 @@ async function scheduleGenerateMissingUrls() {
201
202
  };
202
203
  }
203
204
 
204
- const chunks = chunkArray(membersToUpdate, CHUNK_SIZE);
205
+ const chunks = chunkArray(membersToUpdate, GENERATION_CHUNK_SIZE);
205
206
 
206
207
  for (let i = 0; i < chunks.length; i++) {
207
208
  const chunk = chunks[i];
@@ -255,11 +256,25 @@ async function generateUrlsChunk(data) {
255
256
  };
256
257
 
257
258
  try {
258
- // Fetch all members at once using hasSome
259
- console.log(`Fetching ${memberIds.length} members from database...`);
260
- const members = await queryAllItems(
261
- wixData.query(COLLECTIONS.MEMBERS_DATA).hasSome('_id', memberIds)
259
+ // Fetch members in smaller batches to avoid cursor size limits
260
+ // hasSome with too many IDs creates cursors that exceed Wix's 150KB limit
261
+ const FETCH_BATCH_SIZE = 200;
262
+ console.log(
263
+ `Fetching ${memberIds.length} members from database in batches of ${FETCH_BATCH_SIZE}...`
262
264
  );
265
+
266
+ const members = [];
267
+ const idBatches = chunkArray(memberIds, FETCH_BATCH_SIZE);
268
+
269
+ for (let i = 0; i < idBatches.length; i++) {
270
+ const idBatch = idBatches[i];
271
+ const batchMembers = await queryAllItems(
272
+ wixData.query(COLLECTIONS.MEMBERS_DATA).hasSome('_id', idBatch)
273
+ );
274
+ members.push(...batchMembers);
275
+ console.log(`Fetched batch ${i + 1}/${idBatches.length}: ${batchMembers.length} members`);
276
+ }
277
+
263
278
  console.log(`Found ${members.length} members in database`);
264
279
 
265
280
  // Create a map of _id -> member for quick lookup
@@ -292,7 +307,7 @@ async function generateUrlsChunk(data) {
292
307
  try {
293
308
  const uniqueUrl = await ensureUniqueUrl({
294
309
  url: '',
295
- memberId: member._id,
310
+ memberId: member.memberId,
296
311
  fullName: name || '', // Let ensureUniqueUrl handle fallback for empty names
297
312
  });
298
313
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "abmp-npm",
3
- "version": "1.1.87",
3
+ "version": "1.1.89",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "check-cycles": "madge --circular .",