Skip to content

Commit 8fda71b

Browse files
refactor: Migrate mParticle Instance Imports
1 parent 89f458e commit 8fda71b

30 files changed

+140
-166
lines changed

src/apiClient.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import Constants from './constants';
22
import Types from './types';
33
import { BatchUploader } from './batchUploader';
4-
import { MParticleWebSDK, SDKEvent, SDKDataPlan } from './sdkRuntimeModels';
4+
import { SDKEvent, SDKDataPlan } from './sdkRuntimeModels';
55
import KitBlocker from './kitBlocking';
6-
import { Dictionary, getRampNumber, isEmpty, parseNumber } from './utils';
6+
import { Dictionary, isEmpty, parseNumber } from './utils';
77
import { IUploadObject } from './serverModel';
88
import { MPForwarder } from './forwarders.interfaces';
99
import { IMParticleUser, ISDKUserAttributes } from './identity-user-interfaces';
1010
import { AsyncUploader, FetchUploader, XHRUploader } from './uploaders';
11+
import { IMParticleWebSDKInstance } from './mp-instance';
1112

1213
export interface IAPIClient {
1314
uploader: BatchUploader | null;
@@ -43,7 +44,7 @@ export interface IForwardingStatsData {
4344

4445
export default function APIClient(
4546
this: IAPIClient,
46-
mpInstance: MParticleWebSDK,
47+
mpInstance: IMParticleWebSDKInstance,
4748
kitBlocker: KitBlocker
4849
) {
4950
this.uploader = null;

src/configAPIClient.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
XHRUploader,
1515
} from './uploaders';
1616
import { IPixelConfiguration } from './cookieSyncManager';
17+
import { IMParticleWebSDKInstance } from './mp-instance';
1718

1819
export interface IKitConfigs extends IKitFilterSettings {
1920
name: string;
@@ -113,7 +114,7 @@ export default function ConfigAPIClient(
113114
this: IConfigAPIClient,
114115
apiKey: string,
115116
config: SDKInitConfig,
116-
mpInstance: MParticleWebSDK
117+
mpInstance: IMParticleWebSDKInstance
117118
): void {
118119
const baseUrl = 'https://' + mpInstance._Store.SDKConfig.configUrl;
119120
const { isDevelopmentMode } = config;

src/cookieSyncManager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import {
44
createCookieSyncUrl,
55
} from './utils';
66
import Constants from './constants';
7-
import { MParticleWebSDK } from './sdkRuntimeModels';
87
import { MPID } from '@mparticle/web-sdk';
98
import { IConsentRules } from './consent';
9+
import { IMParticleWebSDKInstance } from './mp-instance';
1010

1111
const { Messages } = Constants;
1212
const { InformationMessages } = Messages;
@@ -47,7 +47,7 @@ export interface ICookieSyncManager {
4747

4848
export default function CookieSyncManager(
4949
this: ICookieSyncManager,
50-
mpInstance: MParticleWebSDK
50+
mpInstance: IMParticleWebSDKInstance
5151
) {
5252
const self = this;
5353

src/identityApiClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
IdentityResultBody,
2525
IIdentityResponse,
2626
} from './identity-user-interfaces';
27-
import { MParticleWebSDK } from './sdkRuntimeModels';
27+
import { IMParticleWebSDKInstance } from './mp-instance';
2828

2929
const { HTTPCodes, Messages, IdentityMethods } = Constants;
3030

@@ -82,7 +82,7 @@ interface IAliasErrorResponse extends IdentityApiError {}
8282

8383
export default function IdentityAPIClient(
8484
this: IIdentityApiClient,
85-
mpInstance: MParticleWebSDK
85+
mpInstance: IMParticleWebSDKInstance
8686
) {
8787
this.sendAliasRequest = async function(
8888
aliasRequest: IAliasRequest,

src/kitBlocking.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { SDKEvent, MParticleWebSDK, KitBlockerDataPlan, SDKProduct } from './sdk
33
import { BaseEvent, EventTypeEnum, CommerceEvent, ScreenViewEvent, CustomEvent } from '@mparticle/event-models';
44
import Types from './types'
55
import { DataPlanPoint } from '@mparticle/data-planning-models';
6+
import { IMParticleWebSDKInstance } from './mp-instance';
67

78
/*
89
TODO: Including this as a workaround because attempting to import it from
@@ -41,9 +42,9 @@ export default class KitBlocker {
4142
blockUserAttributes = false;
4243
blockUserIdentities = false;
4344
kitBlockingEnabled = false;
44-
mpInstance: MParticleWebSDK;
45+
mpInstance: IMParticleWebSDKInstance;
4546

46-
constructor(dataPlan: KitBlockerDataPlan, mpInstance: MParticleWebSDK) {
47+
constructor(dataPlan: KitBlockerDataPlan, mpInstance: IMParticleWebSDKInstance) {
4748
// if data plan is not requested, the data plan is {document: null}
4849
if (dataPlan && !dataPlan.document) {
4950
this.kitBlockingEnabled = false;

src/mockBatchCreator.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { convertEvents } from './sdkToEventsApiConverter';
66
import * as EventsApi from '@mparticle/event-models';
77
import { Batch } from '@mparticle/event-models';
88
import { IMPSideloadedKit } from './sideloadedKit';
9+
import { IMParticleWebSDKInstance } from './mp-instance';
910

1011
const mockFunction = function() {
1112
return null;
@@ -15,15 +16,15 @@ export default class _BatchValidator {
1516
return ({
1617
// Certain Helper, Store, and Identity properties need to be mocked to be used in the `returnBatch` method
1718
_Helpers: {
18-
sanitizeAttributes: window.mParticle.getInstance()._Helpers
19+
sanitizeAttributes: (window.mParticle.getInstance() as unknown as IMParticleWebSDKInstance)._Helpers
1920
.sanitizeAttributes,
2021
generateHash: function() {
2122
return 'mockHash';
2223
},
2324
generateUniqueId: function() {
2425
return 'mockId';
2526
},
26-
extend: window.mParticle.getInstance()._Helpers.extend,
27+
extend: (window.mParticle.getInstance() as unknown as IMParticleWebSDKInstance)._Helpers.extend,
2728
createServiceUrl: mockFunction,
2829
parseNumber: mockFunction,
2930
isObject: mockFunction,
@@ -118,7 +119,7 @@ export default class _BatchValidator {
118119
logLevel: 'none',
119120
setPosition: mockFunction,
120121
upload: mockFunction,
121-
} as unknown) as MParticleWebSDK;
122+
} as unknown) as IMParticleWebSDKInstance;
122123
}
123124

124125
private createSDKEventFunction(event): SDKEvent {

src/sdkToEventsApiConverter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
SDKProduct,
55
SDKPromotion,
66
SDKProductActionType,
7-
MParticleWebSDK,
87
} from './sdkRuntimeModels';
98
import * as EventsApi from '@mparticle/event-models';
109
import {
@@ -17,6 +16,7 @@ import { Dictionary, isEmpty } from './utils';
1716
import { ISDKUserIdentity } from './identity-user-interfaces';
1817
import { SDKIdentityTypeEnum } from './identity.interfaces';
1918
import Constants from './constants';
19+
import { IMParticleWebSDKInstance } from './mp-instance';
2020

2121
const {
2222
FeatureFlags
@@ -35,7 +35,7 @@ interface Batch extends EventsApi.Batch {
3535
export function convertEvents(
3636
mpid: string,
3737
sdkEvents: SDKEvent[],
38-
mpInstance: MParticleWebSDK
38+
mpInstance: IMParticleWebSDKInstance
3939
): Batch | null {
4040
if (!mpid) {
4141
return null;

src/sessionManager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { MPID } from '@mparticle/web-sdk';
22
import Constants from './constants';
33
import { IPersistenceMinified } from './persistence.interfaces';
4-
import { MParticleWebSDK } from './sdkRuntimeModels';
54
import Types from './types';
65
import { generateDeprecationMessage } from './utils';
76
import { IMParticleUser } from './identity-user-interfaces';
7+
import { IMParticleWebSDKInstance } from './mp-instance';
88

99
const { Messages } = Constants;
1010

@@ -26,7 +26,7 @@ export interface ISessionManager {
2626

2727
export default function SessionManager(
2828
this: ISessionManager,
29-
mpInstance: MParticleWebSDK
29+
mpInstance: IMParticleWebSDKInstance
3030
) {
3131
const self = this;
3232

test/jest/cookieSyncManager.spec.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import CookieSyncManager, {
44
CookieSyncDates,
55
isLastSyncDateExpired
66
} from '../../src/cookieSyncManager';
7-
import { MParticleWebSDK } from '../../src/sdkRuntimeModels';
7+
import { IMParticleWebSDKInstance } from '../../src/mp-instance';
88
import { testMPID } from '../src/config/constants';
99

1010
const pixelSettings: IPixelConfiguration = {
@@ -43,7 +43,7 @@ describe('CookieSyncManager', () => {
4343
getMPID: () => testMPID,
4444
}),
4545
},
46-
} as unknown) as MParticleWebSDK;
46+
} as unknown) as IMParticleWebSDKInstance;
4747

4848
const cookieSyncManager = new CookieSyncManager(mockMPInstance);
4949
cookieSyncManager.performCookieSync = jest.fn();
@@ -78,7 +78,7 @@ describe('CookieSyncManager', () => {
7878
getMPID: () => testMPID,
7979
}),
8080
},
81-
} as unknown) as MParticleWebSDK;
81+
} as unknown) as IMParticleWebSDKInstance;
8282

8383
const cookieSyncManager = new CookieSyncManager(mockMPInstance);
8484
cookieSyncManager.performCookieSync = jest.fn();
@@ -99,7 +99,7 @@ describe('CookieSyncManager', () => {
9999
csd: {}
100100
}}),
101101
},
102-
} as unknown) as MParticleWebSDK;
102+
} as unknown) as IMParticleWebSDKInstance;
103103

104104
const cookieSyncManager = new CookieSyncManager(mockMPInstance);
105105
cookieSyncManager.performCookieSync = jest.fn();
@@ -120,7 +120,7 @@ describe('CookieSyncManager', () => {
120120
csd: {}
121121
}}),
122122
},
123-
} as unknown) as MParticleWebSDK;
123+
} as unknown) as IMParticleWebSDKInstance;
124124

125125
const cookieSyncManager = new CookieSyncManager(mockMPInstance);
126126
cookieSyncManager.performCookieSync = jest.fn();
@@ -158,7 +158,7 @@ describe('CookieSyncManager', () => {
158158
_Consent: {
159159
isEnabledForUserConsent: jest.fn().mockReturnValue(true),
160160
},
161-
} as unknown) as MParticleWebSDK;
161+
} as unknown) as IMParticleWebSDKInstance;
162162

163163
const cookieSyncManager = new CookieSyncManager(mockMPInstance);
164164
cookieSyncManager.performCookieSync = jest.fn();
@@ -197,7 +197,7 @@ describe('CookieSyncManager', () => {
197197
getMPID: () => testMPID,
198198
}),
199199
},
200-
} as unknown) as MParticleWebSDK;
200+
} as unknown) as IMParticleWebSDKInstance;
201201

202202
const cookieSyncManager = new CookieSyncManager(mockMPInstance);
203203
cookieSyncManager.performCookieSync = jest.fn();
@@ -229,7 +229,7 @@ describe('CookieSyncManager', () => {
229229
getMPID: () => testMPID,
230230
}),
231231
},
232-
} as unknown) as MParticleWebSDK;
232+
} as unknown) as IMParticleWebSDKInstance;
233233

234234
const cookieSyncManager = new CookieSyncManager(mockMPInstance);
235235
cookieSyncManager.performCookieSync = jest.fn();
@@ -268,7 +268,7 @@ describe('CookieSyncManager', () => {
268268
getMPID: () => testMPID,
269269
}),
270270
},
271-
} as unknown) as MParticleWebSDK;
271+
} as unknown) as IMParticleWebSDKInstance;
272272

273273
const cookieSyncManager = new CookieSyncManager(mockMPInstance);
274274
cookieSyncManager.performCookieSync = jest.fn();
@@ -305,7 +305,7 @@ describe('CookieSyncManager', () => {
305305
Logger: {
306306
verbose: jest.fn(),
307307
},
308-
} as unknown) as MParticleWebSDK;
308+
} as unknown) as IMParticleWebSDKInstance;
309309

310310
const cookieSyncManager = new CookieSyncManager(mockMPInstance);
311311
cookieSyncManager.performCookieSync = jest.fn();
@@ -329,7 +329,7 @@ describe('CookieSyncManager', () => {
329329
_Persistence: {
330330
getPersistence: () => ({}),
331331
},
332-
} as unknown) as MParticleWebSDK;
332+
} as unknown) as IMParticleWebSDKInstance;
333333

334334
const cookieSyncManager = new CookieSyncManager(mockMPInstance);
335335
cookieSyncManager.performCookieSync = jest.fn();
@@ -370,7 +370,7 @@ describe('CookieSyncManager', () => {
370370
Logger: {
371371
verbose: loggerSpy,
372372
},
373-
} as unknown) as MParticleWebSDK;
373+
} as unknown) as IMParticleWebSDKInstance;
374374

375375
const cookieSyncManager = new CookieSyncManager(mockMPInstance);
376376
cookieSyncManager.performCookieSync = jest.fn();
@@ -413,7 +413,7 @@ describe('CookieSyncManager', () => {
413413
Logger: {
414414
verbose: loggerSpy,
415415
},
416-
} as unknown) as MParticleWebSDK;
416+
} as unknown) as IMParticleWebSDKInstance;
417417

418418
const cookieSyncManager = new CookieSyncManager(mockMPInstance);
419419
cookieSyncManager.performCookieSync = jest.fn();
@@ -457,7 +457,7 @@ describe('CookieSyncManager', () => {
457457
Logger: {
458458
verbose: jest.fn(),
459459
},
460-
} as unknown) as MParticleWebSDK;
460+
} as unknown) as IMParticleWebSDKInstance;
461461

462462
const cookieSyncManager = new CookieSyncManager(mockMPInstance);
463463

@@ -521,7 +521,7 @@ describe('CookieSyncManager', () => {
521521
Logger: {
522522
verbose: loggerSpy,
523523
},
524-
} as unknown) as MParticleWebSDK;
524+
} as unknown) as IMParticleWebSDKInstance;
525525

526526
const cookieSyncManager = new CookieSyncManager(mockMPInstance);
527527

test/src/config/setup.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { MPConfig, workspaceToken } from './constants';
2-
import { MParticleWebSDK } from '../../../src/sdkRuntimeModels';
2+
import { IMParticleInstanceManager } from '../../../src/sdkRuntimeModels';
33

44
declare global {
55
interface Window {
6-
mParticle: MParticleWebSDK;
6+
mParticle: IMParticleInstanceManager;
77
}
88
}
99

0 commit comments

Comments
 (0)