Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/apiClient.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import Constants from './constants';
import Types from './types';
import { BatchUploader } from './batchUploader';
import { MParticleWebSDK, SDKEvent, SDKDataPlan } from './sdkRuntimeModels';
import { SDKEvent, SDKDataPlan } from './sdkRuntimeModels';
import KitBlocker from './kitBlocking';
import { Dictionary, getRampNumber, isEmpty, parseNumber } from './utils';
import { Dictionary, isEmpty, parseNumber } from './utils';
import { IUploadObject } from './serverModel';
import { MPForwarder } from './forwarders.interfaces';
import { IMParticleUser, ISDKUserAttributes } from './identity-user-interfaces';
import { AsyncUploader, FetchUploader, XHRUploader } from './uploaders';
import { IMParticleWebSDKInstance } from './mp-instance';

export interface IAPIClient {
uploader: BatchUploader | null;
Expand Down Expand Up @@ -43,7 +44,7 @@ export interface IForwardingStatsData {

export default function APIClient(
this: IAPIClient,
mpInstance: MParticleWebSDK,
mpInstance: IMParticleWebSDKInstance,
kitBlocker: KitBlocker
) {
this.uploader = null;
Expand Down
3 changes: 2 additions & 1 deletion src/configAPIClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
XHRUploader,
} from './uploaders';
import { IPixelConfiguration } from './cookieSyncManager';
import { IMParticleWebSDKInstance } from './mp-instance';

export interface IKitConfigs extends IKitFilterSettings {
name: string;
Expand Down Expand Up @@ -113,7 +114,7 @@ export default function ConfigAPIClient(
this: IConfigAPIClient,
apiKey: string,
config: SDKInitConfig,
mpInstance: MParticleWebSDK
mpInstance: IMParticleWebSDKInstance
): void {
const baseUrl = 'https://' + mpInstance._Store.SDKConfig.configUrl;
const { isDevelopmentMode } = config;
Expand Down
4 changes: 2 additions & 2 deletions src/cookieSyncManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {
createCookieSyncUrl,
} from './utils';
import Constants from './constants';
import { MParticleWebSDK } from './sdkRuntimeModels';
import { MPID } from '@mparticle/web-sdk';
import { IConsentRules } from './consent';
import { IMParticleWebSDKInstance } from './mp-instance';

const { Messages } = Constants;
const { InformationMessages } = Messages;
Expand Down Expand Up @@ -47,7 +47,7 @@ export interface ICookieSyncManager {

export default function CookieSyncManager(
this: ICookieSyncManager,
mpInstance: MParticleWebSDK
mpInstance: IMParticleWebSDKInstance
) {
const self = this;

Expand Down
4 changes: 2 additions & 2 deletions src/identityApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
IdentityResultBody,
IIdentityResponse,
} from './identity-user-interfaces';
import { MParticleWebSDK } from './sdkRuntimeModels';
import { IMParticleWebSDKInstance } from './mp-instance';

const { HTTPCodes, Messages, IdentityMethods } = Constants;

Expand Down Expand Up @@ -82,7 +82,7 @@ interface IAliasErrorResponse extends IdentityApiError {}

export default function IdentityAPIClient(
this: IIdentityApiClient,
mpInstance: MParticleWebSDK
mpInstance: IMParticleWebSDKInstance
) {
this.sendAliasRequest = async function(
aliasRequest: IAliasRequest,
Expand Down
5 changes: 3 additions & 2 deletions src/kitBlocking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { SDKEvent, MParticleWebSDK, KitBlockerDataPlan, SDKProduct } from './sdk
import { BaseEvent, EventTypeEnum, CommerceEvent, ScreenViewEvent, CustomEvent } from '@mparticle/event-models';
import Types from './types'
import { DataPlanPoint } from '@mparticle/data-planning-models';
import { IMParticleWebSDKInstance } from './mp-instance';

/*
TODO: Including this as a workaround because attempting to import it from
Expand Down Expand Up @@ -41,9 +42,9 @@ export default class KitBlocker {
blockUserAttributes = false;
blockUserIdentities = false;
kitBlockingEnabled = false;
mpInstance: MParticleWebSDK;
mpInstance: IMParticleWebSDKInstance;

constructor(dataPlan: KitBlockerDataPlan, mpInstance: MParticleWebSDK) {
constructor(dataPlan: KitBlockerDataPlan, mpInstance: IMParticleWebSDKInstance) {
// if data plan is not requested, the data plan is {document: null}
if (dataPlan && !dataPlan.document) {
this.kitBlockingEnabled = false;
Expand Down
7 changes: 4 additions & 3 deletions src/mockBatchCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { convertEvents } from './sdkToEventsApiConverter';
import * as EventsApi from '@mparticle/event-models';
import { Batch } from '@mparticle/event-models';
import { IMPSideloadedKit } from './sideloadedKit';
import { IMParticleWebSDKInstance } from './mp-instance';

const mockFunction = function() {
return null;
Expand All @@ -15,15 +16,15 @@ export default class _BatchValidator {
return ({
// Certain Helper, Store, and Identity properties need to be mocked to be used in the `returnBatch` method
_Helpers: {
sanitizeAttributes: window.mParticle.getInstance()._Helpers
sanitizeAttributes: (window.mParticle.getInstance() as unknown as IMParticleWebSDKInstance)._Helpers
.sanitizeAttributes,
generateHash: function() {
return 'mockHash';
},
generateUniqueId: function() {
return 'mockId';
},
extend: window.mParticle.getInstance()._Helpers.extend,
extend: (window.mParticle.getInstance() as unknown as IMParticleWebSDKInstance)._Helpers.extend,
createServiceUrl: mockFunction,
parseNumber: mockFunction,
isObject: mockFunction,
Expand Down Expand Up @@ -118,7 +119,7 @@ export default class _BatchValidator {
logLevel: 'none',
setPosition: mockFunction,
upload: mockFunction,
} as unknown) as MParticleWebSDK;
} as unknown) as IMParticleWebSDKInstance;
}

private createSDKEventFunction(event): SDKEvent {
Expand Down
4 changes: 2 additions & 2 deletions src/sdkToEventsApiConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
SDKProduct,
SDKPromotion,
SDKProductActionType,
MParticleWebSDK,
} from './sdkRuntimeModels';
import * as EventsApi from '@mparticle/event-models';
import {
Expand All @@ -17,6 +16,7 @@ import { Dictionary, isEmpty } from './utils';
import { ISDKUserIdentity } from './identity-user-interfaces';
import { SDKIdentityTypeEnum } from './identity.interfaces';
import Constants from './constants';
import { IMParticleWebSDKInstance } from './mp-instance';

const {
FeatureFlags
Expand All @@ -35,7 +35,7 @@ interface Batch extends EventsApi.Batch {
export function convertEvents(
mpid: string,
sdkEvents: SDKEvent[],
mpInstance: MParticleWebSDK
mpInstance: IMParticleWebSDKInstance
): Batch | null {
if (!mpid) {
return null;
Expand Down
4 changes: 2 additions & 2 deletions src/sessionManager.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { MPID } from '@mparticle/web-sdk';
import Constants from './constants';
import { IPersistenceMinified } from './persistence.interfaces';
import { MParticleWebSDK } from './sdkRuntimeModels';
import Types from './types';
import { generateDeprecationMessage } from './utils';
import { IMParticleUser } from './identity-user-interfaces';
import { IMParticleWebSDKInstance } from './mp-instance';

const { Messages } = Constants;

Expand All @@ -26,7 +26,7 @@ export interface ISessionManager {

export default function SessionManager(
this: ISessionManager,
mpInstance: MParticleWebSDK
mpInstance: IMParticleWebSDKInstance
) {
const self = this;

Expand Down
30 changes: 15 additions & 15 deletions test/jest/cookieSyncManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import CookieSyncManager, {
CookieSyncDates,
isLastSyncDateExpired
} from '../../src/cookieSyncManager';
import { MParticleWebSDK } from '../../src/sdkRuntimeModels';
import { IMParticleWebSDKInstance } from '../../src/mp-instance';
import { testMPID } from '../src/config/constants';

const pixelSettings: IPixelConfiguration = {
Expand Down Expand Up @@ -43,7 +43,7 @@ describe('CookieSyncManager', () => {
getMPID: () => testMPID,
}),
},
} as unknown) as MParticleWebSDK;
} as unknown) as IMParticleWebSDKInstance;

const cookieSyncManager = new CookieSyncManager(mockMPInstance);
cookieSyncManager.performCookieSync = jest.fn();
Expand Down Expand Up @@ -78,7 +78,7 @@ describe('CookieSyncManager', () => {
getMPID: () => testMPID,
}),
},
} as unknown) as MParticleWebSDK;
} as unknown) as IMParticleWebSDKInstance;

const cookieSyncManager = new CookieSyncManager(mockMPInstance);
cookieSyncManager.performCookieSync = jest.fn();
Expand All @@ -99,7 +99,7 @@ describe('CookieSyncManager', () => {
csd: {}
}}),
},
} as unknown) as MParticleWebSDK;
} as unknown) as IMParticleWebSDKInstance;

const cookieSyncManager = new CookieSyncManager(mockMPInstance);
cookieSyncManager.performCookieSync = jest.fn();
Expand All @@ -120,7 +120,7 @@ describe('CookieSyncManager', () => {
csd: {}
}}),
},
} as unknown) as MParticleWebSDK;
} as unknown) as IMParticleWebSDKInstance;

const cookieSyncManager = new CookieSyncManager(mockMPInstance);
cookieSyncManager.performCookieSync = jest.fn();
Expand Down Expand Up @@ -158,7 +158,7 @@ describe('CookieSyncManager', () => {
_Consent: {
isEnabledForUserConsent: jest.fn().mockReturnValue(true),
},
} as unknown) as MParticleWebSDK;
} as unknown) as IMParticleWebSDKInstance;

const cookieSyncManager = new CookieSyncManager(mockMPInstance);
cookieSyncManager.performCookieSync = jest.fn();
Expand Down Expand Up @@ -197,7 +197,7 @@ describe('CookieSyncManager', () => {
getMPID: () => testMPID,
}),
},
} as unknown) as MParticleWebSDK;
} as unknown) as IMParticleWebSDKInstance;

const cookieSyncManager = new CookieSyncManager(mockMPInstance);
cookieSyncManager.performCookieSync = jest.fn();
Expand Down Expand Up @@ -229,7 +229,7 @@ describe('CookieSyncManager', () => {
getMPID: () => testMPID,
}),
},
} as unknown) as MParticleWebSDK;
} as unknown) as IMParticleWebSDKInstance;

const cookieSyncManager = new CookieSyncManager(mockMPInstance);
cookieSyncManager.performCookieSync = jest.fn();
Expand Down Expand Up @@ -268,7 +268,7 @@ describe('CookieSyncManager', () => {
getMPID: () => testMPID,
}),
},
} as unknown) as MParticleWebSDK;
} as unknown) as IMParticleWebSDKInstance;

const cookieSyncManager = new CookieSyncManager(mockMPInstance);
cookieSyncManager.performCookieSync = jest.fn();
Expand Down Expand Up @@ -305,7 +305,7 @@ describe('CookieSyncManager', () => {
Logger: {
verbose: jest.fn(),
},
} as unknown) as MParticleWebSDK;
} as unknown) as IMParticleWebSDKInstance;

const cookieSyncManager = new CookieSyncManager(mockMPInstance);
cookieSyncManager.performCookieSync = jest.fn();
Expand All @@ -329,7 +329,7 @@ describe('CookieSyncManager', () => {
_Persistence: {
getPersistence: () => ({}),
},
} as unknown) as MParticleWebSDK;
} as unknown) as IMParticleWebSDKInstance;

const cookieSyncManager = new CookieSyncManager(mockMPInstance);
cookieSyncManager.performCookieSync = jest.fn();
Expand Down Expand Up @@ -370,7 +370,7 @@ describe('CookieSyncManager', () => {
Logger: {
verbose: loggerSpy,
},
} as unknown) as MParticleWebSDK;
} as unknown) as IMParticleWebSDKInstance;

const cookieSyncManager = new CookieSyncManager(mockMPInstance);
cookieSyncManager.performCookieSync = jest.fn();
Expand Down Expand Up @@ -413,7 +413,7 @@ describe('CookieSyncManager', () => {
Logger: {
verbose: loggerSpy,
},
} as unknown) as MParticleWebSDK;
} as unknown) as IMParticleWebSDKInstance;

const cookieSyncManager = new CookieSyncManager(mockMPInstance);
cookieSyncManager.performCookieSync = jest.fn();
Expand Down Expand Up @@ -457,7 +457,7 @@ describe('CookieSyncManager', () => {
Logger: {
verbose: jest.fn(),
},
} as unknown) as MParticleWebSDK;
} as unknown) as IMParticleWebSDKInstance;

const cookieSyncManager = new CookieSyncManager(mockMPInstance);

Expand Down Expand Up @@ -521,7 +521,7 @@ describe('CookieSyncManager', () => {
Logger: {
verbose: loggerSpy,
},
} as unknown) as MParticleWebSDK;
} as unknown) as IMParticleWebSDKInstance;

const cookieSyncManager = new CookieSyncManager(mockMPInstance);

Expand Down
4 changes: 2 additions & 2 deletions test/src/config/setup.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { MPConfig, workspaceToken } from './constants';
import { MParticleWebSDK } from '../../../src/sdkRuntimeModels';
import { IMParticleInstanceManager } from '../../../src/sdkRuntimeModels';

declare global {
interface Window {
mParticle: MParticleWebSDK;
mParticle: IMParticleInstanceManager;
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/src/tests-apiClient.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Types from '../../src/types';
import { apiKey, MPConfig } from './config/constants';
import { MParticleWebSDK } from '../../src/sdkRuntimeModels';
import { expect } from 'chai';
import { IMParticleUser } from '../../src/identity-user-interfaces';
import { IMParticleInstanceManager } from '../../src/sdkRuntimeModels';

declare global {
interface Window {
mParticle: MParticleWebSDK;
mParticle: IMParticleInstanceManager;
}
}

Expand Down
6 changes: 3 additions & 3 deletions test/src/tests-audience-manager.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import sinon from 'sinon';
import fetchMock from 'fetch-mock/esm/client';
import { expect } from 'chai';
import { urls, apiKey, MPConfig, testMPID } from './config/constants';
import { urls, apiKey, testMPID } from './config/constants';
import Constants from '../../src/constants';
import { MParticleWebSDK, SDKLoggerApi } from '../../src/sdkRuntimeModels';
import { IMParticleInstanceManager, SDKLoggerApi } from '../../src/sdkRuntimeModels';
import AudienceManager, {
IAudienceMemberships, IAudienceMembershipsServerResponse
} from '../../src/audienceManager';
Expand All @@ -13,7 +13,7 @@ const { fetchMockSuccess } = Utils;

declare global {
interface Window {
mParticle: MParticleWebSDK;
mParticle: IMParticleInstanceManager;
fetchMock: any;
}
}
Expand Down
5 changes: 2 additions & 3 deletions test/src/tests-batchUploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import sinon from 'sinon';
import { urls, apiKey, MPConfig, testMPID } from './config/constants';
import {
BaseEvent,
MParticleWebSDK,
IMParticleInstanceManager,
SDKEvent,
SDKProductActionType,
} from '../../src/sdkRuntimeModels';
import { Batch, CustomEventData } from '@mparticle/event-models';
import Utils from './config/utils';
Expand All @@ -18,7 +17,7 @@ const { fetchMockSuccess, waitForCondition, hasIdentifyReturned } = Utils;

declare global {
interface Window {
mParticle: MParticleWebSDK;
mParticle: IMParticleInstanceManager;
}
}

Expand Down
Loading
Loading