From b20eb361d4b892ba613cc23cc1af3b3041b577ae Mon Sep 17 00:00:00 2001 From: Himanshu Garg Date: Wed, 6 Nov 2024 17:57:54 +0530 Subject: [PATCH] fix(api): refactor SupportService to use environment variable for API key and improve staging condition --- apps/web/src/config/index.ts | 2 +- .../src/custom-providers/index.ts | 2 +- .../src/services/support.service.ts | 17 ++++++++--------- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/apps/web/src/config/index.ts b/apps/web/src/config/index.ts index 9358e07ab16..3eb73a93319 100644 --- a/apps/web/src/config/index.ts +++ b/apps/web/src/config/index.ts @@ -53,7 +53,7 @@ export const IS_SELF_HOSTED = window._env_.REACT_APP_IS_SELF_HOSTED === 'true' || process.env.REACT_APP_IS_SELF_HOSTED === 'true'; // To test feature in prod and staging. Excluding self host and local -export const IS_NOVU_PROD_STAGING = !IS_SELF_HOSTED && (ENV === 'production' || ENV === 'prod' || ENV === 'dev'); +export const IS_NOVU_PROD_STAGING = !IS_SELF_HOSTED && !API_ROOT.includes('localhost'); export const REACT_APP_VERSION = process.env.NOVU_VERSION; diff --git a/libs/application-generic/src/custom-providers/index.ts b/libs/application-generic/src/custom-providers/index.ts index 8a924e7c7eb..b6884532679 100644 --- a/libs/application-generic/src/custom-providers/index.ts +++ b/libs/application-generic/src/custom-providers/index.ts @@ -91,7 +91,7 @@ export const distributedLockService = { export const supportService = { provide: SupportService, useFactory: async () => { - const service = new SupportService(process.env.PLAIN_SUPPORT_KEY); + const service = new SupportService(); return service; }, diff --git a/libs/application-generic/src/services/support.service.ts b/libs/application-generic/src/services/support.service.ts index d1e60f183de..1b10dafb389 100644 --- a/libs/application-generic/src/services/support.service.ts +++ b/libs/application-generic/src/services/support.service.ts @@ -5,12 +5,11 @@ const LOG_CONTEXT = 'SupportService'; export class SupportService { private plainClient: PlainClient; - constructor(private plainKey?: string | null) { - if (this.plainKey) { - this.plainClient = new PlainClient({ - apiKey: this.plainKey, - }); - } + private readonly plainKey: string; + constructor() { + this.plainKey = process.env.PLAIN_SUPPORT_KEY; + this.plainClient = new PlainClient({ apiKey: this.plainKey }); + Logger.log(`Initialized PlainClient`, LOG_CONTEXT); } async upsertCustomer({ emailAddress, fullName, novuUserId }) { @@ -27,7 +26,7 @@ export class SupportService { fullName, }, onUpdate: { - externalId: novuUserId, + externalId: { value: novuUserId }, email: { email: emailAddress, isVerified: true, @@ -41,7 +40,7 @@ export class SupportService { Logger.error( { emailAddress, fullName, error: res.error }, res.error.message, - LOG_CONTEXT, + LOG_CONTEXT ); throw new Error(res.error.message); } else { @@ -67,7 +66,7 @@ export class SupportService { Logger.error( { plainCustomerId, threadText, error: res.error }, res.error.message, - LOG_CONTEXT, + LOG_CONTEXT ); throw new Error(res.error.message); } else {