abmp-npm 1.9.6 → 1.9.7
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/CONTACT_EMAIL_UPDATE_DEBUG.md +313 -0
- package/DEBUG_QUICKSTART.md +133 -0
- package/backend/consts.js +0 -2
- package/backend/contacts-methods-DEBUG.js +237 -0
- package/backend/contacts-methods-TEST.js +271 -0
- package/backend/contacts-methods.js +6 -1
- package/backend/daily-pull/process-member-methods.js +1 -1
- package/backend/data-hooks.js +1 -1
- package/backend/elevated-modules.js +1 -0
- package/backend/http-functions/httpFunctions.js +15 -1
- package/backend/index.js +2 -1
- package/backend/jobs.js +2 -1
- package/backend/login/index.js +7 -0
- package/backend/login/login-methods-factory.js +24 -0
- package/backend/{qa-login-methods.js → login/qa-login-methods.js} +15 -10
- package/backend/{sso-methods.js → login/sso-methods.js} +16 -19
- package/backend/members-data-methods.js +6 -11
- package/backend/tasks/tasks-configs.js +2 -2
- package/backend/test-methods.js +118 -0
- package/backend/utils.js +1 -1
- package/package.json +1 -1
- package/pages/LoadingPage.js +1 -1
- package/pages/QAPage.js +1 -1
- package/pages/SaveAlerts.js +13 -0
- package/pages/{selecBannerImages.js → SelectBannerImages.js} +2 -2
- package/pages/deleteConfirm.js +19 -0
- package/pages/index.js +3 -1
- package/public/consts.js +1 -1
- package/public/sso-auth-methods.js +1 -1
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
# Contact Email Update Investigation Guide
|
|
2
|
+
|
|
3
|
+
## Problem Description
|
|
4
|
+
|
|
5
|
+
Contact email updates in Wix CRM are not working after migration to npm package:
|
|
6
|
+
|
|
7
|
+
- ✅ Members data in Wix DB updates correctly
|
|
8
|
+
- ❌ Contact email in Wix CRM does not update
|
|
9
|
+
- ❌ No errors appear in logs
|
|
10
|
+
- ✅ Old implementation (before npm) works fine
|
|
11
|
+
|
|
12
|
+
## Key Differences Found
|
|
13
|
+
|
|
14
|
+
### OLD Implementation (Working)
|
|
15
|
+
|
|
16
|
+
```javascript
|
|
17
|
+
// From: src/backend/api.web.js (before npm migration)
|
|
18
|
+
import { contacts } from 'wix-crm.v2'; // ← Old package
|
|
19
|
+
import { elevate } from 'wix-auth'; // ← Old import style
|
|
20
|
+
|
|
21
|
+
// Elevated functions created INSIDE the function
|
|
22
|
+
async function updateContactInfo(contactId, updateInfoCallback, operationName) {
|
|
23
|
+
const elevatedGetContact = elevate(contacts.getContact);
|
|
24
|
+
const elevatedUpdateContact = elevate(contacts.updateContact);
|
|
25
|
+
|
|
26
|
+
const currentContact = await elevatedGetContact(contactId);
|
|
27
|
+
const updatedInfo = updateInfoCallback(currentContact.info);
|
|
28
|
+
|
|
29
|
+
// Passes updatedInfo DIRECTLY (not wrapped)
|
|
30
|
+
const result = await elevatedUpdateContact(
|
|
31
|
+
contactId,
|
|
32
|
+
updatedInfo, // ← Direct info object
|
|
33
|
+
currentContact.revision
|
|
34
|
+
);
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### NEW Implementation (Not Working)
|
|
40
|
+
|
|
41
|
+
```javascript
|
|
42
|
+
// From: abmp-npm/backend/contacts-methods.js
|
|
43
|
+
const { contacts } = require('@wix/crm'); // ← New package
|
|
44
|
+
const { auth } = require('@wix/essentials'); // ← New import style
|
|
45
|
+
|
|
46
|
+
// Elevated functions created at MODULE LEVEL
|
|
47
|
+
const elevatedGetContact = auth.elevate(contacts.getContact);
|
|
48
|
+
const elevatedUpdateContact = auth.elevate(contacts.updateContact);
|
|
49
|
+
|
|
50
|
+
async function updateContactInfo(contactId, updateInfoCallback, operationName) {
|
|
51
|
+
const contact = await elevatedGetContact(contactId);
|
|
52
|
+
const updatedInfo = updateInfoCallback(contact.info);
|
|
53
|
+
|
|
54
|
+
// Wraps updatedInfo in { info: }
|
|
55
|
+
await elevatedUpdateContact(
|
|
56
|
+
contactId,
|
|
57
|
+
{ info: updatedInfo }, // ← Wrapped in { info: }
|
|
58
|
+
contact.revision
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Potential Issues
|
|
64
|
+
|
|
65
|
+
### 1. Package Change: `wix-crm.v2` → `@wix/crm`
|
|
66
|
+
|
|
67
|
+
The API signature might have changed between these packages:
|
|
68
|
+
|
|
69
|
+
- **Old**: `updateContact(contactId, infoObject, revision)`
|
|
70
|
+
- **New**: `updateContact(contactId, { info: infoObject }, revision)` or `updateContact(contactId, contactObject, { revision })`
|
|
71
|
+
|
|
72
|
+
### 2. Elevation Scope
|
|
73
|
+
|
|
74
|
+
- **Old**: Functions elevated inside the function (per-call elevation)
|
|
75
|
+
- **New**: Functions elevated at module level (shared elevation)
|
|
76
|
+
|
|
77
|
+
This could cause issues with permissions or context.
|
|
78
|
+
|
|
79
|
+
### 3. Silent Failures
|
|
80
|
+
|
|
81
|
+
If the CRM update throws an error but it's being caught and not logged, it would appear to work but not actually update.
|
|
82
|
+
|
|
83
|
+
## Investigation Steps
|
|
84
|
+
|
|
85
|
+
I've created three debugging files for you:
|
|
86
|
+
|
|
87
|
+
### File 1: `contacts-methods-DEBUG.js`
|
|
88
|
+
|
|
89
|
+
This is your current implementation with extensive logging. It will show:
|
|
90
|
+
|
|
91
|
+
- Every step of the update process
|
|
92
|
+
- All data being passed
|
|
93
|
+
- Any errors (even if they're being caught)
|
|
94
|
+
- Success confirmations
|
|
95
|
+
|
|
96
|
+
### File 2: `contacts-methods-TEST.js`
|
|
97
|
+
|
|
98
|
+
This contains 4 different implementations to test:
|
|
99
|
+
|
|
100
|
+
- **V1**: Current style (wrapped in `{ info: }`)
|
|
101
|
+
- **V2**: Old style (direct info object)
|
|
102
|
+
- **V3**: Minimal payload (only changed fields)
|
|
103
|
+
- **V4**: Revision in options object
|
|
104
|
+
- **Elevation Test**: Checks if elevation is working at all
|
|
105
|
+
|
|
106
|
+
### File 3: `test-methods.js`
|
|
107
|
+
|
|
108
|
+
Web method wrappers you can call from the frontend to run the tests.
|
|
109
|
+
|
|
110
|
+
## How to Use
|
|
111
|
+
|
|
112
|
+
### Step 1: Update Backend Index
|
|
113
|
+
|
|
114
|
+
Add the test methods to your npm package exports:
|
|
115
|
+
|
|
116
|
+
```javascript
|
|
117
|
+
// In abmp-npm/backend/index.js
|
|
118
|
+
module.exports = {
|
|
119
|
+
...require('./forms-methods'),
|
|
120
|
+
...require('./search-filters-methods'),
|
|
121
|
+
...require('./jobs'),
|
|
122
|
+
...require('./utils'),
|
|
123
|
+
...require('./daily-pull'),
|
|
124
|
+
...require('./pac-api-methods'),
|
|
125
|
+
...require('./members-area-methods'),
|
|
126
|
+
...require('./members-data-methods'),
|
|
127
|
+
...require('./cms-data-methods'),
|
|
128
|
+
...require('./routers-methods'),
|
|
129
|
+
...require('./test-methods'), // ← Add this
|
|
130
|
+
};
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Step 2: Expose in Host Site
|
|
134
|
+
|
|
135
|
+
Add these web methods to your host site:
|
|
136
|
+
|
|
137
|
+
```javascript
|
|
138
|
+
// In abmp/src/backend/web-methods.web.js
|
|
139
|
+
import { Permissions, webMethod } from 'wix-web-module';
|
|
140
|
+
import {
|
|
141
|
+
// ... existing imports
|
|
142
|
+
runContactUpdateTests as _runContactUpdateTests,
|
|
143
|
+
testContactElevation as _testContactElevation,
|
|
144
|
+
testUpdateMemberContactInfo as _testUpdateMemberContactInfo,
|
|
145
|
+
} from 'abmp-npm/backend';
|
|
146
|
+
|
|
147
|
+
// ... existing exports
|
|
148
|
+
|
|
149
|
+
export const runContactUpdateTests = webMethod(Permissions.SiteMember, _runContactUpdateTests);
|
|
150
|
+
|
|
151
|
+
export const testContactElevation = webMethod(Permissions.SiteMember, _testContactElevation);
|
|
152
|
+
|
|
153
|
+
export const testUpdateMemberContactInfo = webMethod(
|
|
154
|
+
Permissions.SiteMember,
|
|
155
|
+
_testUpdateMemberContactInfo
|
|
156
|
+
);
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Step 3: Run Tests from Frontend
|
|
160
|
+
|
|
161
|
+
Option A - Test all variations:
|
|
162
|
+
|
|
163
|
+
```javascript
|
|
164
|
+
import { runContactUpdateTests } from 'backend/web-methods.web';
|
|
165
|
+
import wixData from 'wix-data';
|
|
166
|
+
|
|
167
|
+
// Get your member data (you need the contactId)
|
|
168
|
+
const memberData = await wixData.get('Members/PrivateMembersData', 'YOUR_MEMBER_ID');
|
|
169
|
+
const contactId = memberData.contactId;
|
|
170
|
+
|
|
171
|
+
// Run all test variations
|
|
172
|
+
const results = await runContactUpdateTests(contactId, 'newemail@test.com');
|
|
173
|
+
console.log('Test results:', results);
|
|
174
|
+
|
|
175
|
+
// Check Wix Site Monitoring logs for detailed output
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Option B - Test elevation only:
|
|
179
|
+
|
|
180
|
+
```javascript
|
|
181
|
+
import { testContactElevation } from 'backend/web-methods.web';
|
|
182
|
+
|
|
183
|
+
const results = await testContactElevation(contactId);
|
|
184
|
+
console.log('Elevation test results:', results);
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
Option C - Test with DEBUG logging (using your actual saveRegistrationData flow):
|
|
188
|
+
|
|
189
|
+
```javascript
|
|
190
|
+
import { testUpdateMemberContactInfo } from 'backend/web-methods.web';
|
|
191
|
+
import wixData from 'wix-data';
|
|
192
|
+
|
|
193
|
+
// Get existing member data
|
|
194
|
+
const existingData = await wixData.get('Members/PrivateMembersData', 'YOUR_MEMBER_ID');
|
|
195
|
+
|
|
196
|
+
// Create update data (as it would come from your form)
|
|
197
|
+
const updateData = {
|
|
198
|
+
...existingData,
|
|
199
|
+
contactFormEmail: 'newemail@test.com', // Change the email
|
|
200
|
+
firstName: existingData.firstName,
|
|
201
|
+
lastName: existingData.lastName,
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
// Test with DEBUG logging
|
|
205
|
+
const results = await testUpdateMemberContactInfo(updateData, existingData);
|
|
206
|
+
console.log('Debug test results:', results);
|
|
207
|
+
|
|
208
|
+
// Check Wix Site Monitoring logs for extensive output
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### Step 4: Check Logs
|
|
212
|
+
|
|
213
|
+
Go to your Wix Site Monitoring (Logs) and look for entries starting with:
|
|
214
|
+
|
|
215
|
+
- `[DEBUG]` - From the debug version
|
|
216
|
+
- `[TEST V1]`, `[TEST V2]`, etc. - From different test implementations
|
|
217
|
+
- `[TEST ELEVATION]` - From elevation tests
|
|
218
|
+
- `[TEST RUNNER]` - From the test runner
|
|
219
|
+
|
|
220
|
+
## What to Look For
|
|
221
|
+
|
|
222
|
+
### 1. Elevation Issues
|
|
223
|
+
|
|
224
|
+
If you see errors like:
|
|
225
|
+
|
|
226
|
+
- "Insufficient permissions"
|
|
227
|
+
- "Unauthorized"
|
|
228
|
+
- "Forbidden"
|
|
229
|
+
|
|
230
|
+
Then elevation is not working correctly.
|
|
231
|
+
|
|
232
|
+
### 2. API Signature Issues
|
|
233
|
+
|
|
234
|
+
If you see errors like:
|
|
235
|
+
|
|
236
|
+
- "Invalid parameter"
|
|
237
|
+
- "Expected object of type Contact"
|
|
238
|
+
- "Unexpected argument"
|
|
239
|
+
|
|
240
|
+
Then the API signature has changed between packages.
|
|
241
|
+
|
|
242
|
+
### 3. Silent Success
|
|
243
|
+
|
|
244
|
+
If all tests show "success" but the email still doesn't update in CRM:
|
|
245
|
+
|
|
246
|
+
- Check if the contact actually exists in CRM
|
|
247
|
+
- Check if there are any CRM automation rules blocking updates
|
|
248
|
+
- Check if the email field is locked/read-only
|
|
249
|
+
|
|
250
|
+
### 4. Which Version Works
|
|
251
|
+
|
|
252
|
+
If one of the test versions (V1, V2, V3, V4) works:
|
|
253
|
+
|
|
254
|
+
- That tells us the correct API signature to use
|
|
255
|
+
- Update the actual `contacts-methods.js` to match the working version
|
|
256
|
+
|
|
257
|
+
## Quick Fix Hypothesis
|
|
258
|
+
|
|
259
|
+
Based on the code comparison, my best guess is that the issue is with the API call signature. Try this fix first:
|
|
260
|
+
|
|
261
|
+
### Option 1: Use Old Style (Direct Info Object)
|
|
262
|
+
|
|
263
|
+
```javascript
|
|
264
|
+
// In contacts-methods.js, line 23
|
|
265
|
+
// CHANGE FROM:
|
|
266
|
+
await elevatedUpdateContact(contactId, { info: updatedInfo }, contact.revision);
|
|
267
|
+
|
|
268
|
+
// CHANGE TO:
|
|
269
|
+
await elevatedUpdateContact(contactId, updatedInfo, contact.revision);
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
### Option 2: Move Elevation Inside Function
|
|
273
|
+
|
|
274
|
+
```javascript
|
|
275
|
+
// In contacts-methods.js
|
|
276
|
+
// CHANGE FROM:
|
|
277
|
+
const elevatedGetContact = auth.elevate(contacts.getContact);
|
|
278
|
+
const elevatedUpdateContact = auth.elevate(contacts.updateContact);
|
|
279
|
+
|
|
280
|
+
async function updateContactInfo(contactId, updateInfoCallback, operationName) {
|
|
281
|
+
// ...
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// CHANGE TO:
|
|
285
|
+
async function updateContactInfo(contactId, updateInfoCallback, operationName) {
|
|
286
|
+
const elevatedGetContact = auth.elevate(contacts.getContact);
|
|
287
|
+
const elevatedUpdateContact = auth.elevate(contacts.updateContact);
|
|
288
|
+
// ...
|
|
289
|
+
}
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
## Next Steps
|
|
293
|
+
|
|
294
|
+
1. ✅ Add test files to npm package (already created)
|
|
295
|
+
2. ⬜ Release new npm version with test methods
|
|
296
|
+
3. ⬜ Install new version in host site
|
|
297
|
+
4. ⬜ Expose test web methods in host site
|
|
298
|
+
5. ⬜ Run tests from frontend
|
|
299
|
+
6. ⬜ Check logs to see which version works
|
|
300
|
+
7. ⬜ Apply the working solution to the actual code
|
|
301
|
+
8. ⬜ Remove test files and release final version
|
|
302
|
+
|
|
303
|
+
## Need More Help?
|
|
304
|
+
|
|
305
|
+
If the tests don't reveal the issue, we can:
|
|
306
|
+
|
|
307
|
+
1. Add even more detailed logging
|
|
308
|
+
2. Test with the actual Wix CRM dashboard to verify the contact exists
|
|
309
|
+
3. Check if there are any CRM automation rules or webhooks interfering
|
|
310
|
+
4. Test with a different contact to rule out data-specific issues
|
|
311
|
+
5. Compare the exact bytes being sent in the old vs new implementation
|
|
312
|
+
|
|
313
|
+
Let me know what the test results show!
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# Contact Email Update Investigation - Quick Start
|
|
2
|
+
|
|
3
|
+
## 🔍 Problem Summary
|
|
4
|
+
|
|
5
|
+
After migrating to npm package, contact email updates fail silently:
|
|
6
|
+
|
|
7
|
+
- ✅ Wix DB updates work
|
|
8
|
+
- ❌ CRM contact email doesn't update
|
|
9
|
+
- ❌ No errors in logs
|
|
10
|
+
|
|
11
|
+
## 🎯 Key Finding
|
|
12
|
+
|
|
13
|
+
The old code used `wix-crm.v2` while the new code uses `@wix/crm`. These have **different API signatures**!
|
|
14
|
+
|
|
15
|
+
**Old (Working)**:
|
|
16
|
+
|
|
17
|
+
```javascript
|
|
18
|
+
elevatedUpdateContact(contactId, infoObject, revision);
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
**New (Not Working?)**:
|
|
22
|
+
|
|
23
|
+
```javascript
|
|
24
|
+
elevatedUpdateContact(contactId, { info: infoObject }, revision);
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## 🚀 Quick Steps to Investigate
|
|
28
|
+
|
|
29
|
+
### 1. I've created 4 files for you:
|
|
30
|
+
|
|
31
|
+
- ✅ `contacts-methods-DEBUG.js` - Your code with extensive logging
|
|
32
|
+
- ✅ `contacts-methods-TEST.js` - 4 different API call variations
|
|
33
|
+
- ✅ `test-methods.js` - Web methods to run tests
|
|
34
|
+
- ✅ `CONTACT_EMAIL_UPDATE_DEBUG.md` - Full documentation
|
|
35
|
+
|
|
36
|
+
### 2. Release this version to test:
|
|
37
|
+
|
|
38
|
+
The test methods are already exported in `backend/index.js`.
|
|
39
|
+
You just need to:
|
|
40
|
+
|
|
41
|
+
1. Release new npm version
|
|
42
|
+
2. Expose test methods in host site `web-methods.web.js`
|
|
43
|
+
3. Run tests from frontend
|
|
44
|
+
4. Check logs to see which variation works
|
|
45
|
+
|
|
46
|
+
### 3. Expose test methods in host site:
|
|
47
|
+
|
|
48
|
+
Add to `abmp/src/backend/web-methods.web.js`:
|
|
49
|
+
|
|
50
|
+
```javascript
|
|
51
|
+
import {
|
|
52
|
+
// ... your existing imports
|
|
53
|
+
runContactUpdateTests as _runContactUpdateTests,
|
|
54
|
+
testContactElevation as _testContactElevation,
|
|
55
|
+
testUpdateMemberContactInfo as _testUpdateMemberContactInfo,
|
|
56
|
+
} from 'abmp-npm/backend';
|
|
57
|
+
|
|
58
|
+
// ... existing exports
|
|
59
|
+
|
|
60
|
+
export const runContactUpdateTests = webMethod(Permissions.SiteMember, _runContactUpdateTests);
|
|
61
|
+
|
|
62
|
+
export const testContactElevation = webMethod(Permissions.SiteMember, _testContactElevation);
|
|
63
|
+
|
|
64
|
+
export const testUpdateMemberContactInfo = webMethod(
|
|
65
|
+
Permissions.SiteMember,
|
|
66
|
+
_testUpdateMemberContactInfo
|
|
67
|
+
);
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### 4. Run tests from frontend:
|
|
71
|
+
|
|
72
|
+
```javascript
|
|
73
|
+
import { runContactUpdateTests } from 'backend/web-methods.web';
|
|
74
|
+
import wixData from 'wix-data';
|
|
75
|
+
|
|
76
|
+
// Get your contact ID from member data
|
|
77
|
+
const memberData = await wixData.get('Members/PrivateMembersData', 'YOUR_MEMBER_ID');
|
|
78
|
+
|
|
79
|
+
// Run all test variations
|
|
80
|
+
const results = await runContactUpdateTests(memberData.contactId, 'test@newemail.com');
|
|
81
|
+
|
|
82
|
+
console.log('Results:', results);
|
|
83
|
+
// Then check Wix Site Monitoring logs for detailed output
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### 5. Check which test works:
|
|
87
|
+
|
|
88
|
+
In Wix Site Monitoring, look for:
|
|
89
|
+
|
|
90
|
+
- ✅ `[TEST V1]` - Current implementation
|
|
91
|
+
- ✅ `[TEST V2]` - Old style (direct info object) ← **Most likely to work**
|
|
92
|
+
- ✅ `[TEST V3]` - Minimal payload
|
|
93
|
+
- ✅ `[TEST V4]` - Revision in options
|
|
94
|
+
|
|
95
|
+
### 6. Apply the fix:
|
|
96
|
+
|
|
97
|
+
Once you know which version works, update `contacts-methods.js` to match that signature.
|
|
98
|
+
|
|
99
|
+
## 🔧 Most Likely Fix
|
|
100
|
+
|
|
101
|
+
Based on the code comparison, try this first:
|
|
102
|
+
|
|
103
|
+
### Change line 23 in `contacts-methods.js`:
|
|
104
|
+
|
|
105
|
+
**FROM:**
|
|
106
|
+
|
|
107
|
+
```javascript
|
|
108
|
+
await elevatedUpdateContact(contactId, { info: updatedInfo }, contact.revision);
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
**TO:**
|
|
112
|
+
|
|
113
|
+
```javascript
|
|
114
|
+
await elevatedUpdateContact(contactId, updatedInfo, contact.revision);
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
This matches the old working implementation and might be the correct signature for the new package.
|
|
118
|
+
|
|
119
|
+
## 📖 Full Documentation
|
|
120
|
+
|
|
121
|
+
See `CONTACT_EMAIL_UPDATE_DEBUG.md` for complete details, analysis, and troubleshooting steps.
|
|
122
|
+
|
|
123
|
+
## ✅ What's Already Done
|
|
124
|
+
|
|
125
|
+
- ✅ Debugging files created
|
|
126
|
+
- ✅ Test variations created
|
|
127
|
+
- ✅ Test methods exported
|
|
128
|
+
- ⬜ Release new npm version
|
|
129
|
+
- ⬜ Expose in host site
|
|
130
|
+
- ⬜ Run tests
|
|
131
|
+
- ⬜ Apply fix
|
|
132
|
+
|
|
133
|
+
Let me know what the tests reveal!
|
package/backend/consts.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
const PAC_API_URL = 'https://members.abmp.com/eweb/api/Wix';
|
|
2
2
|
const SSO_TOKEN_AUTH_API_URL = 'https://members.professionalassistcorp.com/';
|
|
3
|
-
const SSO_TOKEN_AUTH_API_KEY = 'testkey';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* Valid configuration keys for getSiteConfigs function
|
|
@@ -41,5 +40,4 @@ module.exports = {
|
|
|
41
40
|
COMPILED_FILTERS_FIELDS,
|
|
42
41
|
MEMBERSHIPS_TYPES,
|
|
43
42
|
SSO_TOKEN_AUTH_API_URL,
|
|
44
|
-
SSO_TOKEN_AUTH_API_KEY,
|
|
45
43
|
};
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
const { contacts } = require('@wix/crm');
|
|
2
|
+
const { auth } = require('@wix/essentials');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* DEBUG VERSION with extensive logging
|
|
6
|
+
* This file helps investigate why contact email updates aren't working
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const elevatedGetContact = auth.elevate(contacts.getContact);
|
|
10
|
+
const elevatedUpdateContact = auth.elevate(contacts.updateContact);
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Generic contact update helper function - DEBUG VERSION
|
|
14
|
+
* @param {string} contactId - The contact ID in Wix CRM
|
|
15
|
+
* @param {function} updateInfoCallback - Function that returns the updated info object
|
|
16
|
+
* @param {string} operationName - Name of the operation for logging
|
|
17
|
+
*/
|
|
18
|
+
async function updateContactInfo(contactId, updateInfoCallback, operationName) {
|
|
19
|
+
console.log(`[DEBUG] Starting ${operationName}`);
|
|
20
|
+
console.log(`[DEBUG] contactId:`, contactId);
|
|
21
|
+
|
|
22
|
+
if (!contactId) {
|
|
23
|
+
console.error(`[DEBUG] ERROR: Contact ID is missing`);
|
|
24
|
+
throw new Error('Contact ID is required');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
console.log(`[DEBUG] Attempting to fetch contact...`);
|
|
29
|
+
const contact = await elevatedGetContact(contactId);
|
|
30
|
+
console.log(`[DEBUG] Contact fetched successfully:`, JSON.stringify(contact, null, 2));
|
|
31
|
+
|
|
32
|
+
const currentInfo = contact.info;
|
|
33
|
+
console.log(`[DEBUG] Current contact info:`, JSON.stringify(currentInfo, null, 2));
|
|
34
|
+
|
|
35
|
+
const updatedInfo = updateInfoCallback(currentInfo);
|
|
36
|
+
console.log(`[DEBUG] Updated info to send:`, JSON.stringify(updatedInfo, null, 2));
|
|
37
|
+
|
|
38
|
+
console.log(`[DEBUG] Contact revision:`, contact.revision);
|
|
39
|
+
console.log(`[DEBUG] Attempting to update contact...`);
|
|
40
|
+
|
|
41
|
+
// Try the new way (wrapping in { info: })
|
|
42
|
+
const result = await elevatedUpdateContact(contactId, { info: updatedInfo }, contact.revision);
|
|
43
|
+
console.log(`[DEBUG] Update result:`, JSON.stringify(result, null, 2));
|
|
44
|
+
|
|
45
|
+
console.log(`[DEBUG] ✅ ${operationName} completed successfully`);
|
|
46
|
+
return result;
|
|
47
|
+
} catch (error) {
|
|
48
|
+
console.error(`[DEBUG] ❌ Error in ${operationName}:`, error);
|
|
49
|
+
console.error(`[DEBUG] Error name:`, error.name);
|
|
50
|
+
console.error(`[DEBUG] Error message:`, error.message);
|
|
51
|
+
console.error(`[DEBUG] Error stack:`, error.stack);
|
|
52
|
+
console.error(`[DEBUG] Full error object:`, JSON.stringify(error, null, 2));
|
|
53
|
+
throw new Error(`Failed to ${operationName}: ${error.message}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Updates contact email in Wix CRM - DEBUG VERSION
|
|
59
|
+
* @param {string} contactId - The contact ID in Wix CRM
|
|
60
|
+
* @param {string} newEmail - The new email address
|
|
61
|
+
*/
|
|
62
|
+
async function updateContactEmail(contactId, newEmail) {
|
|
63
|
+
console.log(`[DEBUG] updateContactEmail called`);
|
|
64
|
+
console.log(`[DEBUG] contactId:`, contactId);
|
|
65
|
+
console.log(`[DEBUG] newEmail:`, newEmail);
|
|
66
|
+
|
|
67
|
+
if (!newEmail) {
|
|
68
|
+
console.error(`[DEBUG] ERROR: New email is missing`);
|
|
69
|
+
throw new Error('New email is required');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return await updateContactInfo(
|
|
73
|
+
contactId,
|
|
74
|
+
currentInfo => {
|
|
75
|
+
console.log(`[DEBUG] Building email update object...`);
|
|
76
|
+
const result = {
|
|
77
|
+
...currentInfo,
|
|
78
|
+
emails: {
|
|
79
|
+
items: [
|
|
80
|
+
{
|
|
81
|
+
email: newEmail,
|
|
82
|
+
primary: true,
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
console.log(`[DEBUG] Email update object built:`, JSON.stringify(result, null, 2));
|
|
88
|
+
return result;
|
|
89
|
+
},
|
|
90
|
+
'update contact email'
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Updates contact names in Wix CRM - DEBUG VERSION
|
|
96
|
+
* @param {string} contactId - The contact ID in Wix CRM
|
|
97
|
+
* @param {string} firstName - The new first name
|
|
98
|
+
* @param {string} lastName - The new last name
|
|
99
|
+
*/
|
|
100
|
+
async function updateContactNames(contactId, firstName, lastName) {
|
|
101
|
+
console.log(`[DEBUG] updateContactNames called`);
|
|
102
|
+
console.log(`[DEBUG] contactId:`, contactId);
|
|
103
|
+
console.log(`[DEBUG] firstName:`, firstName);
|
|
104
|
+
console.log(`[DEBUG] lastName:`, lastName);
|
|
105
|
+
|
|
106
|
+
if (!firstName && !lastName) {
|
|
107
|
+
console.error(`[DEBUG] ERROR: Both names are missing`);
|
|
108
|
+
throw new Error('At least one name field is required');
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return await updateContactInfo(
|
|
112
|
+
contactId,
|
|
113
|
+
currentInfo => {
|
|
114
|
+
console.log(`[DEBUG] Building names update object...`);
|
|
115
|
+
const result = {
|
|
116
|
+
...currentInfo,
|
|
117
|
+
name: {
|
|
118
|
+
first: firstName || currentInfo?.name?.first || '',
|
|
119
|
+
last: lastName || currentInfo?.name?.last || '',
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
console.log(`[DEBUG] Names update object built:`, JSON.stringify(result, null, 2));
|
|
123
|
+
return result;
|
|
124
|
+
},
|
|
125
|
+
'update contact names'
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Update fields if they have changed - DEBUG VERSION
|
|
131
|
+
* @param {Array} existingValues - Current values for comparison
|
|
132
|
+
* @param {Array} newValues - New values to compare against
|
|
133
|
+
* @param {Function} updater - Function to call if values changed
|
|
134
|
+
* @param {Function} argsBuilder - Function to build arguments for updater
|
|
135
|
+
*/
|
|
136
|
+
const updateIfChanged = (existingValues, newValues, updater, argsBuilder) => {
|
|
137
|
+
console.log(`[DEBUG] updateIfChanged called`);
|
|
138
|
+
console.log(`[DEBUG] existingValues:`, JSON.stringify(existingValues));
|
|
139
|
+
console.log(`[DEBUG] newValues:`, JSON.stringify(newValues));
|
|
140
|
+
|
|
141
|
+
const hasChanged = existingValues.some((val, idx) => {
|
|
142
|
+
const changed = val !== newValues[idx];
|
|
143
|
+
if (changed) {
|
|
144
|
+
console.log(`[DEBUG] Value changed at index ${idx}: "${val}" -> "${newValues[idx]}"`);
|
|
145
|
+
}
|
|
146
|
+
return changed;
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
console.log(`[DEBUG] hasChanged:`, hasChanged);
|
|
150
|
+
|
|
151
|
+
if (!hasChanged) {
|
|
152
|
+
console.log(`[DEBUG] No changes detected, skipping update`);
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
console.log(`[DEBUG] Changes detected, calling updater with args:`, argsBuilder(newValues));
|
|
157
|
+
return updater(...argsBuilder(newValues));
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Updates member contact information in CRM if fields have changed - DEBUG VERSION
|
|
162
|
+
* @param {Object} data - New member data
|
|
163
|
+
* @param {Object} existingMemberData - Existing member data
|
|
164
|
+
*/
|
|
165
|
+
const updateMemberContactInfo = async (data, existingMemberData) => {
|
|
166
|
+
console.log(`[DEBUG] ========================================`);
|
|
167
|
+
console.log(`[DEBUG] updateMemberContactInfo called`);
|
|
168
|
+
console.log(`[DEBUG] data:`, JSON.stringify(data, null, 2));
|
|
169
|
+
console.log(`[DEBUG] existingMemberData:`, JSON.stringify(existingMemberData, null, 2));
|
|
170
|
+
console.log(`[DEBUG] ========================================`);
|
|
171
|
+
|
|
172
|
+
const { contactId } = existingMemberData;
|
|
173
|
+
console.log(`[DEBUG] Extracted contactId:`, contactId);
|
|
174
|
+
|
|
175
|
+
if (!contactId) {
|
|
176
|
+
console.error(`[DEBUG] ERROR: contactId is missing from existingMemberData`);
|
|
177
|
+
throw new Error('contactId is required in existingMemberData');
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const updateConfig = [
|
|
181
|
+
{
|
|
182
|
+
fields: ['contactFormEmail'],
|
|
183
|
+
updater: updateContactEmail,
|
|
184
|
+
args: ([email]) => [contactId, email],
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
fields: ['firstName', 'lastName'],
|
|
188
|
+
updater: updateContactNames,
|
|
189
|
+
args: ([firstName, lastName]) => [contactId, firstName, lastName],
|
|
190
|
+
},
|
|
191
|
+
];
|
|
192
|
+
|
|
193
|
+
console.log(`[DEBUG] Processing update config...`);
|
|
194
|
+
|
|
195
|
+
const updatePromises = updateConfig
|
|
196
|
+
.map(({ fields, updater, args }, index) => {
|
|
197
|
+
console.log(`[DEBUG] Config ${index}: fields=${JSON.stringify(fields)}`);
|
|
198
|
+
const existingValues = fields.map(field => {
|
|
199
|
+
const value = existingMemberData[field];
|
|
200
|
+
console.log(`[DEBUG] Existing ${field}:`, value);
|
|
201
|
+
return value;
|
|
202
|
+
});
|
|
203
|
+
const newValues = fields.map(field => {
|
|
204
|
+
const value = data[field];
|
|
205
|
+
console.log(`[DEBUG] New ${field}:`, value);
|
|
206
|
+
return value;
|
|
207
|
+
});
|
|
208
|
+
return updateIfChanged(existingValues, newValues, updater, args);
|
|
209
|
+
})
|
|
210
|
+
.filter(Boolean);
|
|
211
|
+
|
|
212
|
+
console.log(`[DEBUG] Number of updates to perform:`, updatePromises.length);
|
|
213
|
+
|
|
214
|
+
if (updatePromises.length === 0) {
|
|
215
|
+
console.log(`[DEBUG] No updates needed, returning early`);
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
console.log(`[DEBUG] Executing ${updatePromises.length} update(s) in parallel...`);
|
|
220
|
+
|
|
221
|
+
try {
|
|
222
|
+
const results = await Promise.all(updatePromises);
|
|
223
|
+
console.log(`[DEBUG] All updates completed successfully`);
|
|
224
|
+
console.log(`[DEBUG] Results:`, JSON.stringify(results, null, 2));
|
|
225
|
+
console.log(`[DEBUG] ========================================`);
|
|
226
|
+
} catch (error) {
|
|
227
|
+
console.error(`[DEBUG] ❌ Error in Promise.all:`, error);
|
|
228
|
+
console.error(`[DEBUG] Error details:`, JSON.stringify(error, null, 2));
|
|
229
|
+
throw error;
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
module.exports = {
|
|
234
|
+
updateMemberContactInfo,
|
|
235
|
+
updateContactEmail, // Export for individual testing
|
|
236
|
+
updateContactNames, // Export for individual testing
|
|
237
|
+
};
|