-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DEV-2064] Refactor resync error handler (#1285)
* sync user wip * sync user * changeset * Update .changeset/cuddly-cats-retire.md Co-authored-by: Marco Ponchia <[email protected]> * Update packages/active-campaign-client/src/index.ts Co-authored-by: Marco Ponchia <[email protected]> * Update packages/active-campaign-client/src/index.ts Co-authored-by: Marco Ponchia <[email protected]> * Update packages/active-campaign-client/src/helpers/resyncUser.ts Co-authored-by: Marco Ponchia <[email protected]> * pr comments * bulk add contact * bulk add contact * resync user * changeset * Update packages/active-campaign-client/src/clients/activeCampaignClient.ts Co-authored-by: Marco Ponchia <[email protected]> * Update packages/active-campaign-client/src/handlers/resyncUserHandler.ts Co-authored-by: Marco Ponchia <[email protected]> * pr changes * Update packages/active-campaign-client/src/helpers/fetchSubscribedWebinarsFromDynamo.ts Co-authored-by: Marco Ponchia <[email protected]> * Update packages/active-campaign-client/.env.example Co-authored-by: marcobottaro <[email protected]> * Update packages/active-campaign-client/src/handlers/resyncUserHandler.ts Co-authored-by: Marco Ponchia <[email protected]> * pr changes * add makeContactPayload * Add types * refactor AC client * add getListByName return type * refactor getListIdByName and add error manage to sqsQueueHandler * Add addOrUpdateContact helper * add getNewWebinarsAndUnsubsriptionLists * add addArrayOfListToContact and removeArrayOfListFromContact helpers * Update resync user handlers * Fix manageError * Fix after merge * add changeset * Fix list ac client call * Refactor env var for test * fix make payload * fix resync function * Apply suggestions from code review Co-authored-by: marcobottaro <[email protected]> * Fix after review * Apply suggestions from code review Co-authored-by: marcobottaro <[email protected]> --------- Co-authored-by: t <[email protected]> Co-authored-by: tommaso1 <[email protected]> Co-authored-by: marcobottaro <[email protected]>
- Loading branch information
1 parent
fb6d962
commit 3f202f7
Showing
17 changed files
with
344 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"active-campaign-client": minor | ||
--- | ||
|
||
Refactor resyncUserHandler to align contacts and subscriptions in Active Campaign |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
AC_BASE_URL=your_account_url | ||
AC_API_KEY=your_api_key | ||
SENDER_URL=localhost:3000 | ||
AWS_REGION="region" | ||
AWS_USER_POOL_ID="region_DFWF81fRa" | ||
COGNITO_USER_ID=66ae52a0-f051-7080-04a1-465b3a4f44cc | ||
LIST_NAME=test-webinar-1732097286071 | ||
COGNITO_USER_POOL_ID="your_region" | ||
AC_BASE_URL_PARAM='/ac/base_url' | ||
AC_API_KEY_PARAM='/ac/api_key' | ||
|
||
TEST_AC_BASE_URL=your_account_url | ||
TEST_AC_API_KEY=your_api_key | ||
TEST_AC_LIST_ID=28 | ||
TEST_COGNITO_USER_ID=66ae52a0-f051-7080-04a1-465b3a4f44cc | ||
TEST_LIST_NAME=test-webinar-1732097286071 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 42 additions & 51 deletions
93
packages/active-campaign-client/src/handlers/resyncUserHandler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
packages/active-campaign-client/src/helpers/addArrayOfListToContact.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { addContactToList } from './manageListSubscription'; | ||
|
||
export async function addArrayOfListToContact(event: { | ||
readonly webinarSlugs: ReadonlyArray<string>; | ||
readonly cognitoUsername: string; | ||
readonly resyncTimeoutMilliseconds: number; | ||
}) { | ||
const { webinarSlugs, cognitoUsername, resyncTimeoutMilliseconds } = event; | ||
// eslint-disable-next-line functional/prefer-readonly-type | ||
const subscriptionsWithErrors: string[] = []; | ||
await webinarSlugs.reduce( | ||
async (prevPromise: Promise<void>, webinarSlug: string) => { | ||
await prevPromise; | ||
try { | ||
const result = await addContactToList(cognitoUsername, webinarSlug); | ||
console.log('Add contact to list result:', result, webinarSlug); // TODO: Remove after testing | ||
await new Promise((resolve) => | ||
setTimeout(resolve, resyncTimeoutMilliseconds) | ||
); // wait to avoid rate limiting | ||
} catch (e) { | ||
subscriptionsWithErrors.push(webinarSlug); | ||
} | ||
}, | ||
Promise.resolve() | ||
); | ||
|
||
if (subscriptionsWithErrors.length > 0) { | ||
console.error( | ||
'Error adding contact to list', | ||
subscriptionsWithErrors.join(',') | ||
); | ||
return false; | ||
} | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.