Skip to content

Commit b9b7d9a

Browse files
committed
chore: simplify StorageTypes for better type safety
1 parent 030b747 commit b9b7d9a

3 files changed

Lines changed: 8 additions & 8 deletions

File tree

src/constants.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,10 @@ export const HTTP_SERVER_ERROR = 500 as const;
219219
// Privacy dependency map for storage keys
220220
export type PrivacyControl = 'functional' | 'targeting';
221221

222-
export const StorageTypes = ['SDKState', 'Products', 'Events', 'Batches', 'IdCache', 'TimeOnSite'];
222+
export type StorageTypes = 'SDKState' | 'Products' | 'Events' | 'Batches' | 'IdCache' | 'TimeOnSite';
223223

224-
export const StoragePrivacyMap: Record<typeof StorageTypes[number], PrivacyControl> = {
225-
SDKState : 'functional',
224+
export const StoragePrivacyMap: Record<StorageTypes, PrivacyControl> = {
225+
SDKState: 'functional',
226226
Products: 'targeting',
227227
Events: 'functional',
228228
Batches: 'functional',

src/store.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
UserIdentities,
99
} from '@mparticle/web-sdk';
1010
import { IKitConfigs } from './configAPIClient';
11-
import Constants, { StoragePrivacyMap, StorageTypes } from './constants';
11+
import Constants, { PrivacyControl, StoragePrivacyMap, StorageTypes } from './constants';
1212
import {
1313
DataPlanResult,
1414
KitBlockerOptions,
@@ -201,7 +201,7 @@ export interface IStore {
201201
setNoFunctional?(noFunctional: boolean): void;
202202
getNoTargeting?(): boolean;
203203
setNoTargeting?(noTargeting: boolean): void;
204-
getPrivacyFlag?(storageType: typeof StorageTypes[number]): boolean;
204+
getPrivacyFlag?(storageType: StorageTypes): boolean;
205205

206206
getDeviceId?(): string;
207207
setDeviceId?(deviceId: string): void;
@@ -591,8 +591,8 @@ export default function Store(
591591
this.noTargeting = noTargeting;
592592
};
593593

594-
this.getPrivacyFlag = (storageType: typeof StorageTypes[number]): boolean => {
595-
const privacyControl = StoragePrivacyMap[storageType];
594+
this.getPrivacyFlag = (storageType: StorageTypes): boolean => {
595+
const privacyControl: PrivacyControl = StoragePrivacyMap[storageType];
596596
if (privacyControl === 'functional') {
597597
return this.getNoFunctional();
598598
}

test/jest/batchUploader.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('BatchUploader', () => {
2222
storageName: 'mprtcl-v4_abcdef',
2323
getNoFunctional: function(this: any) { return this.noFunctional; },
2424
getNoTargeting: function(this: any) { return this.noTargeting; },
25-
getPrivacyFlag: function(this: any, storageType: typeof StorageTypes[number]) {
25+
getPrivacyFlag: function(this: any, storageType: StorageTypes) {
2626
const privacyControl = StoragePrivacyMap[storageType];
2727
if (privacyControl === 'functional') {
2828
return this.getNoFunctional();

0 commit comments

Comments
 (0)