Skip to content

Commit

Permalink
fix(api): invalidation (#5810)
Browse files Browse the repository at this point in the history
* fix: invalidation

* fix: user id
  • Loading branch information
scopsy authored Jun 24, 2024
1 parent 67558e8 commit 36aa672
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
1 change: 0 additions & 1 deletion apps/api/src/app/inbox/usecases/session/session.usecase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export class Session {
SelectIntegrationCommand.create({
environmentId: environment._id,
organizationId: environment._organizationId,
userId: command.subscriberId,
channelType: ChannelTypeEnum.IN_APP,
providerId: InAppProviderIdEnum.Novu,
filterData: {},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { BadRequestException, Injectable, NotFoundException, Inject, Logger, ConflictException } from '@nestjs/common';
import { BadRequestException, ConflictException, Inject, Injectable, Logger, NotFoundException } from '@nestjs/common';
import { IntegrationEntity, IntegrationRepository } from '@novu/dal';
import {
AnalyticsService,
encryptCredentials,
buildIntegrationKey,
encryptCredentials,
GetFeatureFlag,
GetFeatureFlagCommand,
InvalidateCacheService,
} from '@novu/application-generic';
import { CHANNELS_WITH_PRIMARY } from '@novu/shared';
import { CHANNELS_WITH_PRIMARY, FeatureFlagsKeysEnum } from '@novu/shared';

import { UpdateIntegrationCommand } from './update-integration.command';
import { CheckIntegration } from '../check-integration/check-integration.usecase';
Expand All @@ -19,7 +21,8 @@ export class UpdateIntegration {
constructor(
private invalidateCache: InvalidateCacheService,
private integrationRepository: IntegrationRepository,
private analyticsService: AnalyticsService
private analyticsService: AnalyticsService,
private getFeatureFlag: GetFeatureFlag
) {}

private async calculatePriorityAndPrimaryForActive({
Expand Down Expand Up @@ -123,11 +126,22 @@ export class UpdateIntegration {
active: command.active,
});

await this.invalidateCache.invalidateQuery({
key: buildIntegrationKey().invalidate({
_organizationId: command.organizationId,
}),
});
const isInvalidationDisabled = await this.getFeatureFlag.execute(
GetFeatureFlagCommand.create({
userId: command.userId,
environmentId: command.environmentId as string,
organizationId: command.organizationId,
key: FeatureFlagsKeysEnum.IS_INTEGRATION_INVALIDATION_DISABLED,
})
);

if (!isInvalidationDisabled) {
await this.invalidateCache.invalidateQuery({
key: buildIntegrationKey().invalidate({
_organizationId: command.organizationId,
}),
});
}

const environmentId = command.environmentId ?? existingIntegration._environmentId;

Expand Down
1 change: 1 addition & 0 deletions libs/shared/src/types/feature-flags/feature-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export enum FeatureFlagsKeysEnum {
IS_TEAM_MEMBER_INVITE_NUDGE_ENABLED = 'IS_TEAM_MEMBER_INVITE_NUDGE_ENABLED',
IS_V2_EXPERIENCE_ENABLED = 'IS_V2_EXPERIENCE_ENABLED',
IS_MIXPANEL_RECORDING_ENABLED = 'IS_MIXPANEL_RECORDING_ENABLED',
IS_INTEGRATION_INVALIDATION_DISABLED = 'IS_INTEGRATION_INVALIDATION_DISABLED',
}
2 changes: 1 addition & 1 deletion libs/shared/src/types/feature-flags/flags.types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* The required format for a boolean flag key.
*/
export type IFlagKey = `IS_${Uppercase<string>}_ENABLED`;
export type IFlagKey = `IS_${Uppercase<string>}_ENABLED` | `IS_${Uppercase<string>}_DISABLED`;

/**
* Helper function to test that enum keys and values match correct format.
Expand Down

0 comments on commit 36aa672

Please sign in to comment.