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
17 changes: 9 additions & 8 deletions src/batchUploader.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Batch } from '@mparticle/event-models';
import Constants from './constants';
import { SDKEvent, MParticleWebSDK, SDKLoggerApi } from './sdkRuntimeModels';
import { SDKEvent, SDKLoggerApi } from './sdkRuntimeModels';
import { convertEvents } from './sdkToEventsApiConverter';
import { MessageType } from './types';
import { getRampNumber, isEmpty } from './utils';
Expand All @@ -12,6 +12,7 @@ import {
IFetchPayload,
} from './uploaders';
import { IMParticleUser } from './identity-user-interfaces';
import { IMParticleWebSDKInstance } from './mp-instance';

/**
* BatchUploader contains all the logic to store/retrieve events and batches
Expand All @@ -36,7 +37,7 @@ export class BatchUploader {
uploadIntervalMillis: number;
eventsQueuedForProcessing: SDKEvent[];
batchesQueuedForProcessing: Batch[];
mpInstance: MParticleWebSDK;
mpInstance: IMParticleWebSDKInstance;
uploadUrl: string;
batchingEnabled: boolean;
private eventVault: SessionStorageVault<SDKEvent[]>;
Expand All @@ -46,10 +47,10 @@ export class BatchUploader {

/**
* Creates an instance of a BatchUploader
* @param {MParticleWebSDK} mpInstance - the mParticle SDK instance
* @param {IMParticleWebSDKInstance} mpInstance - the mParticle SDK instance
* @param {number} uploadInterval - the desired upload interval in milliseconds
*/
constructor(mpInstance: MParticleWebSDK, uploadInterval: number) {
constructor(mpInstance: IMParticleWebSDKInstance, uploadInterval: number) {
this.mpInstance = mpInstance;
this.uploadIntervalMillis = uploadInterval;
this.batchingEnabled =
Expand Down Expand Up @@ -208,7 +209,7 @@ export class BatchUploader {
private static createNewBatches(
sdkEvents: SDKEvent[],
defaultUser: IMParticleUser,
mpInstance: MParticleWebSDK
mpInstance: IMParticleWebSDKInstance
): Batch[] | null {
if (!defaultUser || !sdkEvents || !sdkEvents.length) {
return null;
Expand Down Expand Up @@ -280,9 +281,9 @@ export class BatchUploader {
* @param triggerFuture whether to trigger the loop again - for manual/forced uploads this should be false
* @param useBeacon whether to use the beacon API - used when the page is being unloaded
*/
private async prepareAndUpload(
triggerFuture: boolean,
useBeacon: boolean
public async prepareAndUpload(
triggerFuture: boolean = false,
useBeacon: boolean = false,
): Promise<void> {
// Fetch current user so that events can be grouped by MPID
const currentUser = this.mpInstance.Identity.getCurrentUser();
Expand Down
6 changes: 3 additions & 3 deletions src/configAPIClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { DataPlanConfig } from '@mparticle/web-sdk';
import {
BooleanStringLowerCase,
DataPlanResult,
MParticleWebSDK,
SDKEventCustomFlags,
SDKInitConfig,
} from './sdkRuntimeModels';
Expand All @@ -14,6 +13,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 @@ -82,7 +82,7 @@ export interface IConfigResponse {
export interface IConfigAPIClient {
apiKey: string;
config: SDKInitConfig;
mpInstance: MParticleWebSDK;
mpInstance: IMParticleWebSDKInstance;
getSDKConfiguration: () => Promise<IConfigResponse>;
}

Expand Down Expand Up @@ -113,7 +113,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
10 changes: 2 additions & 8 deletions src/consent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import {
GDPRConsentState,
PrivacyConsentState,
} from '@mparticle/web-sdk';
import { MParticleWebSDK } from './sdkRuntimeModels';
import { Dictionary, isObject } from './utils';
import KitFilterHelper from './kitFilterHelper';
import Constants from './constants';
import { IMParticleUser } from './identity-user-interfaces';
import { IMParticleWebSDKInstance } from './mp-instance';

const { CCPAPurpose } = Constants;

Expand Down Expand Up @@ -36,12 +36,6 @@ export interface SDKConsentApi {
createGDPRConsent: ICreatePrivacyConsentFunction;
createCCPAConsent: ICreatePrivacyConsentFunction;
createConsentState: (consentState?: ConsentState) => ConsentState;
ConsentSerialization: IConsentSerialization;
createPrivacyConsent: ICreatePrivacyConsentFunction;
isEnabledForUserConsent: (
consentRules: IConsentRules,
user: IMParticleUser
) => boolean;
}

export interface IConsentSerialization {
Expand Down Expand Up @@ -120,7 +114,7 @@ export interface IConsent {
ConsentSerialization: IConsentSerialization;
}

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

// this function is called when consent is required to
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
6 changes: 3 additions & 3 deletions src/events.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export interface IEvents {
logOptOut(): void;
logProductActionEvent(
productActionType: valueof<typeof ProductActionType>,
product: SDKProduct,
product: SDKProduct | SDKProduct[],
attrs?: SDKEventAttrs,
customFlags?: SDKEventCustomFlags,
transactionAttributes?: TransactionAttributes,
Expand All @@ -68,13 +68,13 @@ export interface IEvents {
): void;
logPurchaseEvent(
transactionAttributes: TransactionAttributes,
product: SDKProduct,
product: SDKProduct | SDKProduct[],
attrs?: SDKEventAttrs,
customFlags?: SDKEventCustomFlags
): void;
logRefundEvent(
transactionAttributes: TransactionAttributes,
product: SDKProduct,
product: SDKProduct | SDKProduct[],
attrs?: SDKEventAttrs,
customFlags?: SDKEventCustomFlags
): void;
Expand Down
6 changes: 3 additions & 3 deletions src/identity-user-interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ export interface IdentityModifyResultBody {
}

export interface mParticleUserCart {
add(product: Product, logEvent: boolean): void;
remove(product: Product, logEvent: boolean): void;
add(product: SDKProduct | SDKProduct[], logEvent: boolean): void;
remove(product: SDKProduct | SDKProduct[], logEvent: boolean): void;
clear(): void;
getCartProducts(): Product[];
getCartProducts(): SDKProduct[];
}

// https://go.mparticle.com/work/SQDSDKS-5196
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
11 changes: 5 additions & 6 deletions src/mockBatchCreator.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// This file is used ONLY for the mParticle ESLint plugin. It should NOT be used otherwise!

import ServerModel from './serverModel';
import { SDKEvent, BaseEvent, MParticleWebSDK } from './sdkRuntimeModels';
import { SDKEvent, BaseEvent } from './sdkRuntimeModels';
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 +14,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 +117,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
Loading
Loading