Skip to content

Commit

Permalink
fix(session): not erroring on session id missing (#698)
Browse files Browse the repository at this point in the history
  • Loading branch information
bassrock authored Aug 26, 2024
1 parent 2e92049 commit 36e5d31
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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;
Expand Down
9 changes: 2 additions & 7 deletions servers/feature-flags/src/unleashClient/strategy/newUser.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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;
Expand Down
7 changes: 0 additions & 7 deletions servers/feature-flags/src/utils/customErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
}
2 changes: 1 addition & 1 deletion servers/shareable-lists-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,4 @@
"prisma": {
"seed": "ts-node --emit=false prisma/seed.ts"
}
}
}

0 comments on commit 36e5d31

Please sign in to comment.