Skip to content

Commit 57823b6

Browse files
committed
chore: simplify StorageTypes for better type safety
1 parent 0b69930 commit 57823b6

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
@@ -233,10 +233,10 @@ export const HTTP_SERVER_ERROR = 500 as const;
233233
// Privacy dependency map for storage keys
234234
export type PrivacyControl = 'functional' | 'targeting';
235235

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

238-
export const StoragePrivacyMap: Record<typeof StorageTypes[number], PrivacyControl> = {
239-
SDKState : 'functional',
238+
export const StoragePrivacyMap: Record<StorageTypes, PrivacyControl> = {
239+
SDKState: 'functional',
240240
Products: 'targeting',
241241
Events: 'functional',
242242
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,
@@ -216,7 +216,7 @@ export interface IStore {
216216
setNoFunctional?(noFunctional: boolean): void;
217217
getNoTargeting?(): boolean;
218218
setNoTargeting?(noTargeting: boolean): void;
219-
getPrivacyFlag?(storageType: typeof StorageTypes[number]): boolean;
219+
getPrivacyFlag?(storageType: StorageTypes): boolean;
220220

221221
getDeviceId?(): string;
222222
setDeviceId?(deviceId: string): void;
@@ -609,8 +609,8 @@ export default function Store(
609609
this.noTargeting = noTargeting;
610610
};
611611

612-
this.getPrivacyFlag = (storageType: typeof StorageTypes[number]): boolean => {
613-
const privacyControl = StoragePrivacyMap[storageType];
612+
this.getPrivacyFlag = (storageType: StorageTypes): boolean => {
613+
const privacyControl: PrivacyControl = StoragePrivacyMap[storageType];
614614
if (privacyControl === 'functional') {
615615
return this.getNoFunctional();
616616
}

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)