From b925592ebcc8fe9fea41dcaec8b9c81ef37a20a1 Mon Sep 17 00:00:00 2001 From: Ramin Date: Thu, 29 Feb 2024 00:38:32 +0330 Subject: [PATCH 01/13] add badge revoke reminder events --- src/services/notificationService.ts | 16 ++++++++++++++++ src/types/notifications.ts | 2 ++ 2 files changed, 18 insertions(+) diff --git a/src/services/notificationService.ts b/src/services/notificationService.ts index 1af262d..b4c618c 100644 --- a/src/services/notificationService.ts +++ b/src/services/notificationService.ts @@ -96,6 +96,22 @@ const activityCreator = (payload: any, orttoEventName: NOTIFICATIONS_EVENT_NAMES "str:cm:verified-status": 'revoked', } break + case NOTIFICATIONS_EVENT_NAMES.PROJECT_BADGE_REVOKE_WARNING: + attributes = { + "str:cm:projecttitle": payload.title, + "str:cm:email": payload.email, + "str:cm:projectupdatelink": payload.projectLink + '?tab=updates', + "str:cm:user-id": payload.userId?.toString(), + } + break + case NOTIFICATIONS_EVENT_NAMES.PROJECT_BADGE_REVOKE_LAST_WARNING: + attributes = { + "str:cm:projecttitle": payload.title, + "str:cm:email": payload.email, + "str:cm:projectupdatelink": payload.projectLink + '?tab=updates', + "str:cm:user-id": payload.userId?.toString(), + } + break default: logger.debug('activityCreator() invalid event name', orttoEventName) } diff --git a/src/types/notifications.ts b/src/types/notifications.ts index a57883c..5626469 100644 --- a/src/types/notifications.ts +++ b/src/types/notifications.ts @@ -56,4 +56,6 @@ export const ORTTO_EVENT_NAMES = { [NOTIFICATIONS_EVENT_NAMES.PROJECT_UNVERIFIED]: 'project-verification', [NOTIFICATIONS_EVENT_NAMES.PROJECT_VERIFIED]: 'project-verification', [NOTIFICATIONS_EVENT_NAMES.PROJECT_BADGE_REVOKED]: 'project-verification', + [NOTIFICATIONS_EVENT_NAMES.PROJECT_BADGE_REVOKE_WARNING]: 'first-update-warning', + [NOTIFICATIONS_EVENT_NAMES.PROJECT_BADGE_REVOKE_LAST_WARNING]: 'second-update-warning', } \ No newline at end of file From deb60b835de0730e6fb695d034c4b6e2c4f9d6d6 Mon Sep 17 00:00:00 2001 From: Carlos Date: Wed, 6 Mar 2024 08:22:03 -0500 Subject: [PATCH 02/13] add superfluid tokens email --- src/services/notificationService.ts | 8 ++++++++ src/types/notifications.ts | 2 ++ src/utils/validators/segmentAndMetadataValidators.ts | 11 +++++++++++ 3 files changed, 21 insertions(+) diff --git a/src/services/notificationService.ts b/src/services/notificationService.ts index f1c9139..6f39f08 100644 --- a/src/services/notificationService.ts +++ b/src/services/notificationService.ts @@ -24,6 +24,14 @@ const activityCreator = (payload: any, orttoEventName: NOTIFICATIONS_EVENT_NAMES } let attributes; switch (orttoEventName) { + case NOTIFICATIONS_EVENT_NAMES.USER_SUPER_TOKENS_CRITICAL: + attributes = { + "str:cm:tokensymbol": payload.tokenSymbol, + "str:cm:email": payload.email, + "str:cm:userId": payload.userId, + "str:cm:criticalDate": payload.criticalDate, + } + break; case NOTIFICATIONS_EVENT_NAMES.DONATION_RECEIVED: attributes = { "str:cm:projecttitle": payload.title, diff --git a/src/types/notifications.ts b/src/types/notifications.ts index b45be84..2eeef97 100644 --- a/src/types/notifications.ts +++ b/src/types/notifications.ts @@ -1,4 +1,5 @@ export enum NOTIFICATIONS_EVENT_NAMES { + USER_SUPER_TOKENS_CRITICAL = 'Supertokens critical', DRAFTED_PROJECT_ACTIVATED = 'Draft published', PROJECT_LISTED = 'Project listed', PROJECT_UNLISTED = 'Project unlisted', @@ -47,6 +48,7 @@ export enum NOTIFICATIONS_EVENT_NAMES { } export const ORTTO_EVENT_NAMES = { + [NOTIFICATIONS_EVENT_NAMES.USER_SUPER_TOKENS_CRITICAL]: 'superfluid-balance-warning', [NOTIFICATIONS_EVENT_NAMES.DONATION_RECEIVED]: 'testing-donation-received', [NOTIFICATIONS_EVENT_NAMES.DRAFTED_PROJECT_ACTIVATED]: 'project-created', [NOTIFICATIONS_EVENT_NAMES.PROJECT_LISTED]: 'project-listed', diff --git a/src/utils/validators/segmentAndMetadataValidators.ts b/src/utils/validators/segmentAndMetadataValidators.ts index cc3e8ab..c94b826 100644 --- a/src/utils/validators/segmentAndMetadataValidators.ts +++ b/src/utils/validators/segmentAndMetadataValidators.ts @@ -141,12 +141,23 @@ const givBackReadyClaimSchema = Joi.object({ amount: Joi.string().required(), }); +const superFluidTokenTrackerSchema = Joi.object({ + tokenSymbol: Joi.string().required(), + email: Joi.string().required(), + userId: Joi.number().required(), + criticalDate: Joi.string().required(), +}); + export const SEGMENT_METADATA_SCHEMA_VALIDATOR: { [key: string]: { segment: ObjectSchema | null; metadata: ObjectSchema | null; }; } = { + userSuperTokensCritical: { + metadata: null, + segment: superFluidTokenTrackerSchema, + }, draftedProjectSavedValidator: { metadata: projectTitleProjectLinkSchema, segment: projectRelatedTrackerSchema, From 7700be6b39d9914f405f1044407e2c5110954d6b Mon Sep 17 00:00:00 2001 From: Ramin Date: Wed, 27 Mar 2024 02:48:27 +0330 Subject: [PATCH 03/13] add isRecurringDonation and SUPER_TOKENS_CRITICAL fields and validators --- src/services/notificationService.ts | 4 +++- src/utils/validators/segmentAndMetadataValidators.ts | 2 ++ src/validators/schemaValidators.ts | 6 ++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/services/notificationService.ts b/src/services/notificationService.ts index 6f39f08..f0517dc 100644 --- a/src/services/notificationService.ts +++ b/src/services/notificationService.ts @@ -28,12 +28,14 @@ const activityCreator = (payload: any, orttoEventName: NOTIFICATIONS_EVENT_NAMES attributes = { "str:cm:tokensymbol": payload.tokenSymbol, "str:cm:email": payload.email, - "str:cm:userId": payload.userId, + "str:cm:userId": payload.userId?.toString(), "str:cm:criticalDate": payload.criticalDate, + "bol:cm:isended": payload.isEnded, } break; case NOTIFICATIONS_EVENT_NAMES.DONATION_RECEIVED: attributes = { + "bol:cm:isrecurringdonation": !!payload.isRecurringDonation, "str:cm:projecttitle": payload.title, "str:cm:donationamount": payload.amount.toString(), "str:cm:donationtoken": payload.token, diff --git a/src/utils/validators/segmentAndMetadataValidators.ts b/src/utils/validators/segmentAndMetadataValidators.ts index c94b826..785f5f6 100644 --- a/src/utils/validators/segmentAndMetadataValidators.ts +++ b/src/utils/validators/segmentAndMetadataValidators.ts @@ -92,6 +92,7 @@ const donationTrackerSchema = Joi.object({ donationValueEth: Joi.number().greater(0).allow(null), verified: Joi.boolean().allow(null), transakStatus: Joi.string().allow(null), + isRecurringDonation: Joi.boolean().allow(null), }); const projectTitleProjectLinkSchema = Joi.object({ @@ -146,6 +147,7 @@ const superFluidTokenTrackerSchema = Joi.object({ email: Joi.string().required(), userId: Joi.number().required(), criticalDate: Joi.string().required(), + isEnded: Joi.boolean(), }); export const SEGMENT_METADATA_SCHEMA_VALIDATOR: { diff --git a/src/validators/schemaValidators.ts b/src/validators/schemaValidators.ts index 3ba478e..8e45ec4 100644 --- a/src/validators/schemaValidators.ts +++ b/src/validators/schemaValidators.ts @@ -75,6 +75,12 @@ export const sendNotificationValidator = Joi.object({ donationValueEth: Joi.number().allow(null), verified: Joi.boolean(), transakStatus: Joi.string().allow(null).allow(''), + isRecurringDonation: Joi.boolean().allow(null), + + //Super token critical attributes + criticalDate: Joi.string(), + isEnded: Joi.boolean(), + tokenSymbol: Joi.string(), //Project related attributes lastName: Joi.string().allow(null).allow(''), From bb67e9fb43ea5cab1f4eb9f85bb453c92dc32bca Mon Sep 17 00:00:00 2001 From: Carlos Date: Thu, 28 Mar 2024 02:30:34 -0500 Subject: [PATCH 04/13] add in-app notifications for emails of superfluid --- ...711607882826-addSuperfluidNotifications.ts | 161 ++++++++++++++++++ src/entities/notificationSetting.ts | 1 + src/entities/notificationType.ts | 1 + .../segmentAndMetadataValidators.ts | 2 +- 4 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 migrations/1711607882826-addSuperfluidNotifications.ts diff --git a/migrations/1711607882826-addSuperfluidNotifications.ts b/migrations/1711607882826-addSuperfluidNotifications.ts new file mode 100644 index 0000000..681a0f1 --- /dev/null +++ b/migrations/1711607882826-addSuperfluidNotifications.ts @@ -0,0 +1,161 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; +import { NOTIFICATION_CATEGORY_GROUPS } from '../src/entities/notificationSetting'; +import { NOTIFICATION_CATEGORY } from '../src/types/general'; +import { MICRO_SERVICES } from '../src/utils/utils'; +import { + NotificationType, + SCHEMA_VALIDATORS_NAMES, +} from '../src/entities/notificationType'; + +export const superFluidNotificationTypes = [ + { + name: 'One month left in stream balance', + description: 'Stream balance of underlying token will run out in 1 month', + microService: MICRO_SERVICES.givethio, + category: NOTIFICATION_CATEGORY.GIV_ECONOMY, + icon: '', + schemaValidator: SCHEMA_VALIDATORS_NAMES.SUPERFLUID, + emailNotifierService: null, + emailNotificationId: null, + pushNotifierService: null, + categoryGroup: NOTIFICATION_CATEGORY_GROUPS.SUPERFLUID, + title: 'One Month Left in Stream Balance', + htmlTemplate: [ + { + type: 'p', + content: 'Your Stream Balance of ', + }, + { + type: 'a', + content: '{underlyingTokenSymbol}', + href: '#', // Placeholder for dynamic token symbol link + }, + { + type: 'p', + content: ' on ', + }, + { + type: 'a', + content: '{network}', + href: '#', // Placeholder for dynamic network link + }, + { + type: 'p', + content: ' will run out in 1 month, ', + }, + { + type: 'a', + content: 'top-up here.', + href: 'Link to my recurring donations tab', // Actual link goes here + }, + ], + content: + 'Your Stream Balance of {underlyingTokenSymbol} on {network} will run out in 1 month, top-up here.', + }, + { + name: 'One week left in stream balance', + description: 'Stream balance of underlying token will run out in 1 week', + microService: MICRO_SERVICES.givethio, + category: NOTIFICATION_CATEGORY.GIV_ECONOMY, + icon: '', + schemaValidator: SCHEMA_VALIDATORS_NAMES.SUPERFLUID, + emailNotifierService: null, + emailNotificationId: null, + pushNotifierService: null, + categoryGroup: NOTIFICATION_CATEGORY_GROUPS.SUPERFLUID, + title: 'One Week Left in Stream Balance', + htmlTemplate: [ + { + type: 'p', + content: 'Your Stream Balance of ', + }, + { + type: 'a', + content: '{underlyingTokenSymbol}', + href: '#', // Placeholder for dynamic token symbol link + }, + { + type: 'p', + content: ' on ', + }, + { + type: 'a', + content: '{network}', + href: '#', // Placeholder for dynamic network link + }, + { + type: 'p', + content: ' will run out in 1 week, ', + }, + { + type: 'a', + content: 'top-up here.', + href: 'Link to my recurring donations tab', // Actual link goes here + }, + ], + content: + 'Your Stream Balance of {underlyingTokenSymbol} on {network} will run out in 1 week, top-up here.', + }, + { + name: 'Stream balance depleted', + description: 'Stream balance in token has run out of funds', + microService: MICRO_SERVICES.givethio, + category: NOTIFICATION_CATEGORY.GIV_ECONOMY, + icon: '', + schemaValidator: SCHEMA_VALIDATORS_NAMES.SUPERFLUID, + emailNotifierService: null, + emailNotificationId: null, + pushNotifierService: null, + categoryGroup: NOTIFICATION_CATEGORY_GROUPS.SUPERFLUID, + title: 'Stream Balance Depleted', + htmlTemplate: [ + { + type: 'p', + content: 'Your Stream Balance in ', + }, + { + type: 'a', + content: '{tokenSymbol}', + href: '#', // Placeholder for dynamic token symbol link + }, + { + type: 'p', + content: ' on ', + }, + { + type: 'a', + content: '{network}', + href: '#', // Placeholder for dynamic network link + }, + { + type: 'p', + content: + ' has run out of funds, subsequently some of your recurring donations have ended. ', + }, + { + type: 'a', + content: 'Manage your Recurring Donations', + href: 'Link to manage recurring donations', // Actual link goes here + }, + ], + content: + 'Your Stream Balance in {tokenSymbol} on {network} has run out of funds, subsequently some of your recurring donations have ended. Manage your Recurring Donations', + }, +]; + +export class addSuperfluidNotifications1711607882826 + implements MigrationInterface +{ + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.manager.save( + NotificationType, + superFluidNotificationTypes, + ); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `DELETE FROM notification_type WHERE "categoryGroup" = 'superfluid';`, + ); + } +} diff --git a/src/entities/notificationSetting.ts b/src/entities/notificationSetting.ts index dacea8e..fbc62d4 100644 --- a/src/entities/notificationSetting.ts +++ b/src/entities/notificationSetting.ts @@ -13,6 +13,7 @@ import { NotificationType } from './notificationType'; import { UserAddress } from './userAddress'; export const NOTIFICATION_CATEGORY_GROUPS = { + SUPERFLUID: 'superfluid', GIVPOWER_ALLOCATIONS: 'givPowerAllocations', PROJECT_BOOSTING_STATUS: 'projectBoostStatus', SELF_BOOSTING_STATUS: 'yourBoostStatus', diff --git a/src/entities/notificationType.ts b/src/entities/notificationType.ts index d5c6b8d..b7c3fec 100644 --- a/src/entities/notificationType.ts +++ b/src/entities/notificationType.ts @@ -16,6 +16,7 @@ import { NotificationSetting } from './notificationSetting'; // Export Object with Schemas to N1 lookup export const SCHEMA_VALIDATORS_NAMES = { + SUPERFLUID: 'superFluidTokenTrackerSchema', ADMIN_MESSAGE: 'adminMessage', RAW_HTML_BROADCAST: 'rawHtmlBroadcast', DRAFTED_PROJECT_SAVED: 'draftedProjectSavedValidator', diff --git a/src/utils/validators/segmentAndMetadataValidators.ts b/src/utils/validators/segmentAndMetadataValidators.ts index 785f5f6..f79a84c 100644 --- a/src/utils/validators/segmentAndMetadataValidators.ts +++ b/src/utils/validators/segmentAndMetadataValidators.ts @@ -157,7 +157,7 @@ export const SEGMENT_METADATA_SCHEMA_VALIDATOR: { }; } = { userSuperTokensCritical: { - metadata: null, + metadata: superFluidTokenTrackerSchema, segment: superFluidTokenTrackerSchema, }, draftedProjectSavedValidator: { From 5bdb2bfa7fd7ae1af5edcc4f47de777d38ad21e9 Mon Sep 17 00:00:00 2001 From: Ramin Date: Tue, 9 Apr 2024 21:10:12 +0330 Subject: [PATCH 05/13] add SuperFluid Notification For All Users --- ...87-addSuperFluidNotificationForAllUsers.ts | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 migrations/1712683625687-addSuperFluidNotificationForAllUsers.ts diff --git a/migrations/1712683625687-addSuperFluidNotificationForAllUsers.ts b/migrations/1712683625687-addSuperFluidNotificationForAllUsers.ts new file mode 100644 index 0000000..e4160cf --- /dev/null +++ b/migrations/1712683625687-addSuperFluidNotificationForAllUsers.ts @@ -0,0 +1,34 @@ +import { MigrationInterface, QueryRunner } from "typeorm" + +export class addSuperFluidNotificationForAllUsers1712683625687 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + // First, select all unique userAddressIds + const uniqueUserAddresses = await queryRunner.query(` + SELECT DISTINCT "userAddressId" FROM "notification_setting"; + `); + + // Then, for each unique userAddressId, insert the required rows + for (const address of uniqueUserAddresses) { + await queryRunner.query(` + INSERT INTO "notification_setting" ( + "allowNotifications", + "allowEmailNotification", + "allowDappPushNotification", + "notificationTypeId", + "userAddressId" + ) VALUES + (true, true, true, 66, '${address.userAddressId}'), + (true, true, true, 67, '${address.userAddressId}'), + (true, true, true, 68, '${address.userAddressId}'); + `); + } + } + + public async down(queryRunner: QueryRunner): Promise { + // To revert, delete the rows with the specific notificationTypeIds for all userAddressIds + await queryRunner.query(` + DELETE FROM "notification_setting" + WHERE "notificationTypeId" IN (66, 67, 68); + `); + } +} From 59632f507547c1f910b8c92bec83818b6d6893fb Mon Sep 17 00:00:00 2001 From: Ramin Date: Tue, 9 Apr 2024 21:41:39 +0330 Subject: [PATCH 06/13] fetch superfluid type ids from DB --- ...87-addSuperFluidNotificationForAllUsers.ts | 49 ++++++++++++------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/migrations/1712683625687-addSuperFluidNotificationForAllUsers.ts b/migrations/1712683625687-addSuperFluidNotificationForAllUsers.ts index e4160cf..7c24869 100644 --- a/migrations/1712683625687-addSuperFluidNotificationForAllUsers.ts +++ b/migrations/1712683625687-addSuperFluidNotificationForAllUsers.ts @@ -2,33 +2,44 @@ import { MigrationInterface, QueryRunner } from "typeorm" export class addSuperFluidNotificationForAllUsers1712683625687 implements MigrationInterface { public async up(queryRunner: QueryRunner): Promise { - // First, select all unique userAddressIds - const uniqueUserAddresses = await queryRunner.query(` + // Fetch the notificationTypeIds for the "superfluid" categoryGroup + const notificationTypeIds = await queryRunner.query(` + SELECT "id" FROM "notification_type" WHERE "categoryGroup" = 'superfluid'; + `); + + // Fetch all unique userAddressIds + const userAddressIds = await queryRunner.query(` SELECT DISTINCT "userAddressId" FROM "notification_setting"; `); - // Then, for each unique userAddressId, insert the required rows - for (const address of uniqueUserAddresses) { - await queryRunner.query(` - INSERT INTO "notification_setting" ( - "allowNotifications", - "allowEmailNotification", - "allowDappPushNotification", - "notificationTypeId", - "userAddressId" - ) VALUES - (true, true, true, 66, '${address.userAddressId}'), - (true, true, true, 67, '${address.userAddressId}'), - (true, true, true, 68, '${address.userAddressId}'); - `); + // For each userAddressId, insert a new row for each notificationTypeId + for (const { userAddressId } of userAddressIds) { + for (const { id: notificationTypeId } of notificationTypeIds) { + await queryRunner.query(` + INSERT INTO "notification_setting" ( + "allowNotifications", + "allowEmailNotification", + "allowDappPushNotification", + "notificationTypeId", + "userAddressId" + ) VALUES (true, true, true, ${notificationTypeId}, ${userAddressId}); + `); + } } } public async down(queryRunner: QueryRunner): Promise { - // To revert, delete the rows with the specific notificationTypeIds for all userAddressIds + // Fetch the notificationTypeIds for the "superfluid" categoryGroup + const notificationTypeIds = await queryRunner.query(` + SELECT "id" FROM "notification_type" WHERE "categoryGroup" = 'superfluid'; + `); + + // Convert fetched rows to a list of IDs for the IN clause + const ids = notificationTypeIds.map((nt: { id: any; }) => nt.id).join(', '); + + // Delete the rows with the fetched notificationTypeIds for all userAddressIds await queryRunner.query(` - DELETE FROM "notification_setting" - WHERE "notificationTypeId" IN (66, 67, 68); + DELETE FROM "notification_setting" WHERE "notificationTypeId" IN (${ids}); `); } } From ddfae671620b3c96c19903aecb9ca91ee0430f24 Mon Sep 17 00:00:00 2001 From: Ramin Date: Wed, 10 Apr 2024 00:25:41 +0330 Subject: [PATCH 07/13] add SUPER_TOKENS NOTIFICATIONS_EVENT_NAMES --- src/services/notificationService.ts | 45 ++++++++++++++++++++--------- src/types/notifications.ts | 8 +++-- 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/src/services/notificationService.ts b/src/services/notificationService.ts index f0517dc..7ff5550 100644 --- a/src/services/notificationService.ts +++ b/src/services/notificationService.ts @@ -24,12 +24,29 @@ const activityCreator = (payload: any, orttoEventName: NOTIFICATIONS_EVENT_NAMES } let attributes; switch (orttoEventName) { - case NOTIFICATIONS_EVENT_NAMES.USER_SUPER_TOKENS_CRITICAL: + case NOTIFICATIONS_EVENT_NAMES.SUPER_TOKENS_BALANCE_DEPLETED: attributes = { "str:cm:tokensymbol": payload.tokenSymbol, "str:cm:email": payload.email, "str:cm:userId": payload.userId?.toString(), - "str:cm:criticalDate": payload.criticalDate, + "bol:cm:isended": payload.isEnded, + } + break; + case NOTIFICATIONS_EVENT_NAMES.SUPER_TOKENS_BALANCE_WEEK: + attributes = { + "str:cm:tokensymbol": payload.tokenSymbol, + "str:cm:email": payload.email, + "str:cm:userId": payload.userId?.toString(), + "str:cm:criticalDate": 'week', + "bol:cm:isended": payload.isEnded, + } + break; + case NOTIFICATIONS_EVENT_NAMES.SUPER_TOKENS_BALANCE_MONTH: + attributes = { + "str:cm:tokensymbol": payload.tokenSymbol, + "str:cm:email": payload.email, + "str:cm:userId": payload.userId?.toString(), + "str:cm:criticalDate": 'month', "bol:cm:isended": payload.isEnded, } break; @@ -184,6 +201,17 @@ export const sendNotification = async ( userAddressId: userAddress.id, }); + const shouldSendEmail = + body.sendEmail && notificationSetting?.allowEmailNotification; + let emailStatus = shouldSendEmail + ? EMAIL_STATUSES.WAITING_TO_BE_SEND + : EMAIL_STATUSES.NO_NEED_TO_SEND; + + const segmentValidator = + SEGMENT_METADATA_SCHEMA_VALIDATOR[ + notificationType?.schemaValidator as string + ]?.segment; + logger.debug('notificationController.sendNotification()', { notificationSetting, notificationTypeId: notificationType.id, @@ -200,19 +228,10 @@ export const sendNotification = async ( payload: body.segment?.payload, sendEmail: body.sendEmail, sendSegment: body.sendSegment, + segmentValidator, + eventName: body.eventName, }); - const shouldSendEmail = - body.sendEmail && notificationSetting?.allowEmailNotification; - let emailStatus = shouldSendEmail - ? EMAIL_STATUSES.WAITING_TO_BE_SEND - : EMAIL_STATUSES.NO_NEED_TO_SEND; - - const segmentValidator = - SEGMENT_METADATA_SCHEMA_VALIDATOR[ - notificationType?.schemaValidator as string - ]?.segment; - if (shouldSendEmail && body.sendSegment && segmentValidator) { const emailData = body.segment?.payload; validateWithJoiSchema(emailData, segmentValidator); diff --git a/src/types/notifications.ts b/src/types/notifications.ts index 2eeef97..81c253f 100644 --- a/src/types/notifications.ts +++ b/src/types/notifications.ts @@ -1,5 +1,4 @@ export enum NOTIFICATIONS_EVENT_NAMES { - USER_SUPER_TOKENS_CRITICAL = 'Supertokens critical', DRAFTED_PROJECT_ACTIVATED = 'Draft published', PROJECT_LISTED = 'Project listed', PROJECT_UNLISTED = 'Project unlisted', @@ -45,10 +44,15 @@ export enum NOTIFICATIONS_EVENT_NAMES { PROJECT_HAS_RISEN_IN_THE_RANK = 'Your Project has risen in the rank', PROJECT_HAS_A_NEW_RANK = 'Your project has a new rank', YOUR_PROJECT_GOT_A_RANK = 'Your project got a rank', + SUPER_TOKENS_BALANCE_WEEK = 'One week left in stream balance', + SUPER_TOKENS_BALANCE_MONTH = 'One month left in stream balance', + SUPER_TOKENS_BALANCE_DEPLETED = 'Stream balance depleted', } export const ORTTO_EVENT_NAMES = { - [NOTIFICATIONS_EVENT_NAMES.USER_SUPER_TOKENS_CRITICAL]: 'superfluid-balance-warning', + [NOTIFICATIONS_EVENT_NAMES.SUPER_TOKENS_BALANCE_WEEK]: 'superfluid-balance-warning', + [NOTIFICATIONS_EVENT_NAMES.SUPER_TOKENS_BALANCE_MONTH]: 'superfluid-balance-warning', + [NOTIFICATIONS_EVENT_NAMES.SUPER_TOKENS_BALANCE_DEPLETED]: 'superfluid-balance-warning', [NOTIFICATIONS_EVENT_NAMES.DONATION_RECEIVED]: 'testing-donation-received', [NOTIFICATIONS_EVENT_NAMES.DRAFTED_PROJECT_ACTIVATED]: 'project-created', [NOTIFICATIONS_EVENT_NAMES.PROJECT_LISTED]: 'project-listed', From f2104896cc630e52fdde8dbf63f5a7bcd3d256d7 Mon Sep 17 00:00:00 2001 From: Ramin Date: Wed, 10 Apr 2024 01:15:34 +0330 Subject: [PATCH 08/13] add logs --- src/services/notificationService.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/services/notificationService.ts b/src/services/notificationService.ts index 7ff5550..83ef9db 100644 --- a/src/services/notificationService.ts +++ b/src/services/notificationService.ts @@ -173,6 +173,7 @@ export const sendNotification = async ( success: boolean; message?: string; }> => { + logger.debug('notificationController.sendNotification() init', body); const { userWalletAddress, projectId } = body; if (body.trackId && (await findNotificationByTrackId(body.trackId))) { // We dont throw error in this case but dont create new notification neither From 0185d730aa4eef17203a1e6d09c811aad917fc7c Mon Sep 17 00:00:00 2001 From: Ramin Date: Wed, 10 Apr 2024 01:54:06 +0330 Subject: [PATCH 09/13] fix SCHEMA_VALIDATORS_NAMES for SUPERFLUID --- src/entities/notificationType.ts | 2 +- src/utils/validators/segmentAndMetadataValidators.ts | 1 - src/validators/schemaValidators.ts | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/entities/notificationType.ts b/src/entities/notificationType.ts index b7c3fec..a4077b9 100644 --- a/src/entities/notificationType.ts +++ b/src/entities/notificationType.ts @@ -16,7 +16,7 @@ import { NotificationSetting } from './notificationSetting'; // Export Object with Schemas to N1 lookup export const SCHEMA_VALIDATORS_NAMES = { - SUPERFLUID: 'superFluidTokenTrackerSchema', + SUPERFLUID: 'userSuperTokensCritical', ADMIN_MESSAGE: 'adminMessage', RAW_HTML_BROADCAST: 'rawHtmlBroadcast', DRAFTED_PROJECT_SAVED: 'draftedProjectSavedValidator', diff --git a/src/utils/validators/segmentAndMetadataValidators.ts b/src/utils/validators/segmentAndMetadataValidators.ts index f79a84c..5b44286 100644 --- a/src/utils/validators/segmentAndMetadataValidators.ts +++ b/src/utils/validators/segmentAndMetadataValidators.ts @@ -146,7 +146,6 @@ const superFluidTokenTrackerSchema = Joi.object({ tokenSymbol: Joi.string().required(), email: Joi.string().required(), userId: Joi.number().required(), - criticalDate: Joi.string().required(), isEnded: Joi.boolean(), }); diff --git a/src/validators/schemaValidators.ts b/src/validators/schemaValidators.ts index 8e45ec4..1eb9aab 100644 --- a/src/validators/schemaValidators.ts +++ b/src/validators/schemaValidators.ts @@ -78,7 +78,6 @@ export const sendNotificationValidator = Joi.object({ isRecurringDonation: Joi.boolean().allow(null), //Super token critical attributes - criticalDate: Joi.string(), isEnded: Joi.boolean(), tokenSymbol: Joi.string(), From 05e777f146ab91f592fadbeac09e48b0a830fe64 Mon Sep 17 00:00:00 2001 From: Ramin Date: Wed, 10 Apr 2024 03:00:42 +0330 Subject: [PATCH 10/13] fix metadata SCHEMA on userSuperTokensCritical --- .../validators/segmentAndMetadataValidators.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/utils/validators/segmentAndMetadataValidators.ts b/src/utils/validators/segmentAndMetadataValidators.ts index 5b44286..583889a 100644 --- a/src/utils/validators/segmentAndMetadataValidators.ts +++ b/src/utils/validators/segmentAndMetadataValidators.ts @@ -142,7 +142,16 @@ const givBackReadyClaimSchema = Joi.object({ amount: Joi.string().required(), }); -const superFluidTokenTrackerSchema = Joi.object({ +const superFluidTokenMetadataSchema = Joi.object({ + tokenSymbol: Joi.string().required(), + email: Joi.string().required(), + userId: Joi.number().required(), + isEnded: Joi.boolean(), + projectTitle: Joi.string(), + projectLink: Joi.string(), +}); + +const superFluidTokenSegmentSchema = Joi.object({ tokenSymbol: Joi.string().required(), email: Joi.string().required(), userId: Joi.number().required(), @@ -156,8 +165,8 @@ export const SEGMENT_METADATA_SCHEMA_VALIDATOR: { }; } = { userSuperTokensCritical: { - metadata: superFluidTokenTrackerSchema, - segment: superFluidTokenTrackerSchema, + metadata: superFluidTokenMetadataSchema, + segment: superFluidTokenSegmentSchema, }, draftedProjectSavedValidator: { metadata: projectTitleProjectLinkSchema, From 8cb5b9cf25636679302e10ed1eed11c97d59e731 Mon Sep 17 00:00:00 2001 From: Carlos Date: Wed, 10 Apr 2024 01:46:55 -0500 Subject: [PATCH 11/13] modify migration template --- ...711607882826-addSuperfluidNotifications.ts | 46 ++++++++----------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/migrations/1711607882826-addSuperfluidNotifications.ts b/migrations/1711607882826-addSuperfluidNotifications.ts index 681a0f1..0f9d8dc 100644 --- a/migrations/1711607882826-addSuperfluidNotifications.ts +++ b/migrations/1711607882826-addSuperfluidNotifications.ts @@ -12,7 +12,7 @@ export const superFluidNotificationTypes = [ name: 'One month left in stream balance', description: 'Stream balance of underlying token will run out in 1 month', microService: MICRO_SERVICES.givethio, - category: NOTIFICATION_CATEGORY.GIV_ECONOMY, + category: NOTIFICATION_CATEGORY.GENERAL, icon: '', schemaValidator: SCHEMA_VALIDATORS_NAMES.SUPERFLUID, emailNotifierService: null, @@ -26,18 +26,16 @@ export const superFluidNotificationTypes = [ content: 'Your Stream Balance of ', }, { - type: 'a', - content: '{underlyingTokenSymbol}', - href: '#', // Placeholder for dynamic token symbol link + type: 'p', + content: '$tokenSymbol', }, { type: 'p', content: ' on ', }, { - type: 'a', - content: '{network}', - href: '#', // Placeholder for dynamic network link + type: 'p', + content: '$network', }, { type: 'p', @@ -46,17 +44,17 @@ export const superFluidNotificationTypes = [ { type: 'a', content: 'top-up here.', - href: 'Link to my recurring donations tab', // Actual link goes here + href: '$recurringDonationLink', // Actual link goes here }, ], content: - 'Your Stream Balance of {underlyingTokenSymbol} on {network} will run out in 1 month, top-up here.', + 'Your Stream Balance of {token} on {network} will run out in 1 month, top-up here.', }, { name: 'One week left in stream balance', description: 'Stream balance of underlying token will run out in 1 week', microService: MICRO_SERVICES.givethio, - category: NOTIFICATION_CATEGORY.GIV_ECONOMY, + category: NOTIFICATION_CATEGORY.GENERAL, icon: '', schemaValidator: SCHEMA_VALIDATORS_NAMES.SUPERFLUID, emailNotifierService: null, @@ -70,18 +68,16 @@ export const superFluidNotificationTypes = [ content: 'Your Stream Balance of ', }, { - type: 'a', - content: '{underlyingTokenSymbol}', - href: '#', // Placeholder for dynamic token symbol link + type: 'p', + content: '$tokenSymbol', }, { type: 'p', content: ' on ', }, { - type: 'a', - content: '{network}', - href: '#', // Placeholder for dynamic network link + type: 'p', + content: '$network', }, { type: 'p', @@ -90,17 +86,17 @@ export const superFluidNotificationTypes = [ { type: 'a', content: 'top-up here.', - href: 'Link to my recurring donations tab', // Actual link goes here + href: '$recurringDonationLink', // Actual link goes here }, ], content: - 'Your Stream Balance of {underlyingTokenSymbol} on {network} will run out in 1 week, top-up here.', + 'Your Stream Balance of {token symbol} on {network} will run out in 1 week, top-up here.', }, { name: 'Stream balance depleted', description: 'Stream balance in token has run out of funds', microService: MICRO_SERVICES.givethio, - category: NOTIFICATION_CATEGORY.GIV_ECONOMY, + category: NOTIFICATION_CATEGORY.GENERAL, icon: '', schemaValidator: SCHEMA_VALIDATORS_NAMES.SUPERFLUID, emailNotifierService: null, @@ -114,18 +110,16 @@ export const superFluidNotificationTypes = [ content: 'Your Stream Balance in ', }, { - type: 'a', - content: '{tokenSymbol}', - href: '#', // Placeholder for dynamic token symbol link + type: 'p', + content: '$tokenSymbol', }, { type: 'p', content: ' on ', }, { - type: 'a', - content: '{network}', - href: '#', // Placeholder for dynamic network link + type: 'p', + content: '$network', }, { type: 'p', @@ -135,7 +129,7 @@ export const superFluidNotificationTypes = [ { type: 'a', content: 'Manage your Recurring Donations', - href: 'Link to manage recurring donations', // Actual link goes here + href: '$recurringDonationLink', // Actual link goes here }, ], content: From fcc5f9fe285d2bfb84006e4e7efcf08b6500f5ae Mon Sep 17 00:00:00 2001 From: Ramin Date: Wed, 10 Apr 2024 16:58:18 +0330 Subject: [PATCH 12/13] fix Recurring Donations network name and link --- .../1711607882826-addSuperfluidNotifications.ts | 12 ++++++------ src/services/notificationService.ts | 3 +-- src/utils/validators/segmentAndMetadataValidators.ts | 2 ++ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/migrations/1711607882826-addSuperfluidNotifications.ts b/migrations/1711607882826-addSuperfluidNotifications.ts index 0f9d8dc..323695f 100644 --- a/migrations/1711607882826-addSuperfluidNotifications.ts +++ b/migrations/1711607882826-addSuperfluidNotifications.ts @@ -35,7 +35,7 @@ export const superFluidNotificationTypes = [ }, { type: 'p', - content: '$network', + content: '$networkName', }, { type: 'p', @@ -44,7 +44,7 @@ export const superFluidNotificationTypes = [ { type: 'a', content: 'top-up here.', - href: '$recurringDonationLink', // Actual link goes here + href: '$recurringDonationTab', // Actual link goes here }, ], content: @@ -77,7 +77,7 @@ export const superFluidNotificationTypes = [ }, { type: 'p', - content: '$network', + content: '$networkName', }, { type: 'p', @@ -86,7 +86,7 @@ export const superFluidNotificationTypes = [ { type: 'a', content: 'top-up here.', - href: '$recurringDonationLink', // Actual link goes here + href: '$recurringDonationTab', // Actual link goes here }, ], content: @@ -119,7 +119,7 @@ export const superFluidNotificationTypes = [ }, { type: 'p', - content: '$network', + content: '$networkName', }, { type: 'p', @@ -129,7 +129,7 @@ export const superFluidNotificationTypes = [ { type: 'a', content: 'Manage your Recurring Donations', - href: '$recurringDonationLink', // Actual link goes here + href: '$recurringDonationTab', // Actual link goes here }, ], content: diff --git a/src/services/notificationService.ts b/src/services/notificationService.ts index 83ef9db..1c2cded 100644 --- a/src/services/notificationService.ts +++ b/src/services/notificationService.ts @@ -173,7 +173,6 @@ export const sendNotification = async ( success: boolean; message?: string; }> => { - logger.debug('notificationController.sendNotification() init', body); const { userWalletAddress, projectId } = body; if (body.trackId && (await findNotificationByTrackId(body.trackId))) { // We dont throw error in this case but dont create new notification neither @@ -229,7 +228,7 @@ export const sendNotification = async ( payload: body.segment?.payload, sendEmail: body.sendEmail, sendSegment: body.sendSegment, - segmentValidator, + segmentValidator: !!segmentValidator, eventName: body.eventName, }); diff --git a/src/utils/validators/segmentAndMetadataValidators.ts b/src/utils/validators/segmentAndMetadataValidators.ts index 583889a..d943134 100644 --- a/src/utils/validators/segmentAndMetadataValidators.ts +++ b/src/utils/validators/segmentAndMetadataValidators.ts @@ -149,6 +149,8 @@ const superFluidTokenMetadataSchema = Joi.object({ isEnded: Joi.boolean(), projectTitle: Joi.string(), projectLink: Joi.string(), + networkName: Joi.string().required(), + recurringDonationTab: Joi.string().required(), }); const superFluidTokenSegmentSchema = Joi.object({ From 2559a3e9ab694e3050aea12fc3065251284b3ded Mon Sep 17 00:00:00 2001 From: Ramin Date: Wed, 10 Apr 2024 17:35:52 +0330 Subject: [PATCH 13/13] remove content --- migrations/1711607882826-addSuperfluidNotifications.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/migrations/1711607882826-addSuperfluidNotifications.ts b/migrations/1711607882826-addSuperfluidNotifications.ts index 323695f..327f341 100644 --- a/migrations/1711607882826-addSuperfluidNotifications.ts +++ b/migrations/1711607882826-addSuperfluidNotifications.ts @@ -47,8 +47,6 @@ export const superFluidNotificationTypes = [ href: '$recurringDonationTab', // Actual link goes here }, ], - content: - 'Your Stream Balance of {token} on {network} will run out in 1 month, top-up here.', }, { name: 'One week left in stream balance', @@ -89,8 +87,6 @@ export const superFluidNotificationTypes = [ href: '$recurringDonationTab', // Actual link goes here }, ], - content: - 'Your Stream Balance of {token symbol} on {network} will run out in 1 week, top-up here.', }, { name: 'Stream balance depleted', @@ -132,8 +128,6 @@ export const superFluidNotificationTypes = [ href: '$recurringDonationTab', // Actual link goes here }, ], - content: - 'Your Stream Balance in {tokenSymbol} on {network} has run out of funds, subsequently some of your recurring donations have ended. Manage your Recurring Donations', }, ];