From 36e5d310f2b148a49d0a0a7547486651268bd688 Mon Sep 17 00:00:00 2001 From: Daniel Brooks Date: Mon, 26 Aug 2024 08:11:53 -0700 Subject: [PATCH] fix(session): not erroring on session id missing (#698) --- .../src/unleashClient/strategy/accountAge.ts | 9 ++------- .../src/unleashClient/strategy/accountAgeAtStart.ts | 13 ++----------- .../src/unleashClient/strategy/hasUserModel.ts | 8 +------- .../src/unleashClient/strategy/newUser.ts | 9 ++------- .../src/unleashClient/strategy/newUserInLocale.ts | 9 ++------- .../src/unleashClient/strategy/userInLocale.ts | 8 +------- servers/feature-flags/src/utils/customErrors.ts | 7 ------- servers/shareable-lists-api/package.json | 2 +- 8 files changed, 11 insertions(+), 54 deletions(-) diff --git a/servers/feature-flags/src/unleashClient/strategy/accountAge.ts b/servers/feature-flags/src/unleashClient/strategy/accountAge.ts index b90996893..82c2c6373 100644 --- a/servers/feature-flags/src/unleashClient/strategy/accountAge.ts +++ b/servers/feature-flags/src/unleashClient/strategy/accountAge.ts @@ -1,7 +1,7 @@ import { Strategy } from 'unleash-client'; import { UnleashContext } from '../../graphql/typeDefs'; import { normalizedStrategyValue } from 'unleash-client/lib/strategy/util'; -import { AccountAgeError, SessionIdError } from '../../utils/customErrors'; +import { AccountAgeError } from '../../utils/customErrors'; import * as Sentry from '@sentry/node'; const DAY_IN_MILLISECONDS = 86400000; @@ -15,12 +15,7 @@ export class AccountAgeStrategy extends Strategy { try { const groupId = parameters.groupId || context.featureToggle || ''; const percentage = Number(parameters.rollout); - const stickinessId = context.userId || context.sessionId; - - // If there is no sticky id - if (!stickinessId || !stickinessId?.length) { - throw new SessionIdError('No Stickiness ID Provided'); - } + const stickinessId = context.userId || context.sessionId || ''; // Check for valid start date const accountAge = parameters?.accountAge; diff --git a/servers/feature-flags/src/unleashClient/strategy/accountAgeAtStart.ts b/servers/feature-flags/src/unleashClient/strategy/accountAgeAtStart.ts index 858fc4de5..424996491 100644 --- a/servers/feature-flags/src/unleashClient/strategy/accountAgeAtStart.ts +++ b/servers/feature-flags/src/unleashClient/strategy/accountAgeAtStart.ts @@ -1,11 +1,7 @@ import { Strategy } from 'unleash-client'; import { UnleashContext } from '../../graphql/typeDefs'; import { normalizedStrategyValue } from 'unleash-client/lib/strategy/util'; -import { - StartDateError, - AccountAgeError, - SessionIdError, -} from '../../utils/customErrors'; +import { StartDateError, AccountAgeError } from '../../utils/customErrors'; import * as Sentry from '@sentry/node'; const DAY_IN_MILLISECONDS = 86400000; @@ -19,12 +15,7 @@ export class AccountAgeAtStartStrategy extends Strategy { try { const groupId = parameters.groupId || context.featureToggle || ''; const percentage = Number(parameters.rollout); - const stickinessId = context.userId || context.sessionId; - - // If there is no sticky id - if (!stickinessId || !stickinessId?.length) { - throw new SessionIdError('No Stickiness ID Provided'); - } + const stickinessId = context.userId || context.sessionId || ''; // Check for valid start date const startDate = Date.parse(parameters?.startDate); diff --git a/servers/feature-flags/src/unleashClient/strategy/hasUserModel.ts b/servers/feature-flags/src/unleashClient/strategy/hasUserModel.ts index 928d3ed11..edb0d4888 100644 --- a/servers/feature-flags/src/unleashClient/strategy/hasUserModel.ts +++ b/servers/feature-flags/src/unleashClient/strategy/hasUserModel.ts @@ -1,7 +1,6 @@ import { Strategy } from 'unleash-client'; import { UnleashContext, RecItUserProfile } from '../../graphql/typeDefs'; import { normalizedStrategyValue } from 'unleash-client/lib/strategy/util'; -import { SessionIdError } from '../../utils/customErrors'; import * as Sentry from '@sentry/node'; export class HasUserModel extends Strategy { @@ -13,12 +12,7 @@ export class HasUserModel extends Strategy { try { const groupId = parameters.groupId || context.featureToggle || ''; const percentage = Number(parameters.rollout); - const stickinessId = context.userId || context.sessionId; - - // If there is no sticky id - if (!stickinessId || !stickinessId?.length) { - throw new SessionIdError('No Stickiness ID Provided'); - } + const stickinessId = context.userId || context.sessionId || ''; // Users without a user profile are not eligible. const userProfileString = context?.properties?.recItUserProfile; diff --git a/servers/feature-flags/src/unleashClient/strategy/newUser.ts b/servers/feature-flags/src/unleashClient/strategy/newUser.ts index 458f0f9c7..ac98280b6 100644 --- a/servers/feature-flags/src/unleashClient/strategy/newUser.ts +++ b/servers/feature-flags/src/unleashClient/strategy/newUser.ts @@ -1,7 +1,7 @@ import { Strategy } from 'unleash-client'; import { UnleashContext } from '../../graphql/typeDefs'; import { normalizedStrategyValue } from 'unleash-client/lib/strategy/util'; -import { StartDateError, SessionIdError } from '../../utils/customErrors'; +import { StartDateError } from '../../utils/customErrors'; import * as Sentry from '@sentry/node'; export class NewUserStrategy extends Strategy { @@ -13,12 +13,7 @@ export class NewUserStrategy extends Strategy { try { const groupId = parameters.groupId || context.featureToggle || ''; const percentage = Number(parameters.rollout); - const stickinessId = context.userId || context.sessionId; - - // If there is no sticky id - if (!stickinessId || !stickinessId?.length) { - throw new SessionIdError('No Stickiness ID Provided'); - } + const stickinessId = context.userId || context.sessionId || ''; // Check for valid start date const startDate = Date.parse(parameters?.startDate); diff --git a/servers/feature-flags/src/unleashClient/strategy/newUserInLocale.ts b/servers/feature-flags/src/unleashClient/strategy/newUserInLocale.ts index 8fb3398c6..ecdc98907 100644 --- a/servers/feature-flags/src/unleashClient/strategy/newUserInLocale.ts +++ b/servers/feature-flags/src/unleashClient/strategy/newUserInLocale.ts @@ -2,7 +2,7 @@ import { Strategy } from 'unleash-client'; import { UnleashContext } from '../../graphql/typeDefs'; import { normalizedStrategyValue } from 'unleash-client/lib/strategy/util'; import { pocketSupportedLocales } from '../../utils/pocketSupportedLocales'; -import { StartDateError, SessionIdError } from '../../utils/customErrors'; +import { StartDateError } from '../../utils/customErrors'; import * as Sentry from '@sentry/node'; export class NewUserInLocaleStrategy extends Strategy { @@ -14,12 +14,7 @@ export class NewUserInLocaleStrategy extends Strategy { try { const groupId = parameters.groupId || context.featureToggle || ''; const percentage = Number(parameters.rollout); - const stickinessId = context.userId || context.sessionId; - - // If there is no sticky id - if (!stickinessId || !stickinessId?.length) { - throw new SessionIdError('No Stickiness ID Provided'); - } + const stickinessId = context.userId || context.sessionId || ''; // Check for language const passedLocale = context?.properties?.locale || 'en'; diff --git a/servers/feature-flags/src/unleashClient/strategy/userInLocale.ts b/servers/feature-flags/src/unleashClient/strategy/userInLocale.ts index 8a94c98ab..26cc3459e 100644 --- a/servers/feature-flags/src/unleashClient/strategy/userInLocale.ts +++ b/servers/feature-flags/src/unleashClient/strategy/userInLocale.ts @@ -1,7 +1,6 @@ import { Strategy } from 'unleash-client'; import { UnleashContext } from '../../graphql/typeDefs'; import { normalizedStrategyValue } from 'unleash-client/lib/strategy/util'; -import { SessionIdError } from '../../utils/customErrors'; import * as Sentry from '@sentry/node'; export class UserInLocaleStrategy extends Strategy { @@ -13,12 +12,7 @@ export class UserInLocaleStrategy extends Strategy { try { const groupId = parameters.groupId || context.featureToggle || ''; const percentage = Number(parameters.rollout); - const stickinessId = context.userId || context.sessionId; - - // If there is no sticky id - if (!stickinessId || !stickinessId?.length) { - throw new SessionIdError('No Stickiness ID Provided'); - } + const stickinessId = context.userId || context.sessionId || ''; // Check for locale const locale = context?.properties?.locale; diff --git a/servers/feature-flags/src/utils/customErrors.ts b/servers/feature-flags/src/utils/customErrors.ts index 12925bfc8..d3da68463 100644 --- a/servers/feature-flags/src/utils/customErrors.ts +++ b/servers/feature-flags/src/utils/customErrors.ts @@ -18,10 +18,3 @@ export class AccountCreatedAtError extends Error { this.name = 'AccountCreatedAtError'; } } - -export class SessionIdError extends Error { - constructor(message: string) { - super(message); - this.name = 'SessionIdError'; - } -} diff --git a/servers/shareable-lists-api/package.json b/servers/shareable-lists-api/package.json index 2ad1e4a40..8ec9b116c 100644 --- a/servers/shareable-lists-api/package.json +++ b/servers/shareable-lists-api/package.json @@ -79,4 +79,4 @@ "prisma": { "seed": "ts-node --emit=false prisma/seed.ts" } -} \ No newline at end of file +}