1616// Uses portions of code from jQuery
1717// jQuery v1.10.2 | (c) 2005, 2013 jQuery Foundation, Inc. | jquery.org/license
1818
19- import Types from './types' ;
19+ import { EventType , IdentityType , CommerceEventType , PromotionActionType , ProductActionType , MessageType } from './types' ;
2020import Constants from './constants' ;
21- import APIClient from './apiClient' ;
21+ import APIClient , { IAPIClient } from './apiClient' ;
2222import Helpers from './helpers' ;
2323import NativeSdkHelpers from './nativeSdkHelpers' ;
24- import CookieSyncManager from './cookieSyncManager' ;
25- import SessionManager from './sessionManager' ;
24+ import CookieSyncManager , { ICookieSyncManager , IPixelConfiguration } from './cookieSyncManager' ;
25+ import SessionManager , { ISessionManager } from './sessionManager' ;
2626import Ecommerce from './ecommerce' ;
27- import Store from './store' ;
27+ import Store , { IntegrationAttribute , IStore } from './store' ;
2828import Logger from './logger' ;
2929import Persistence from './persistence' ;
3030import Events from './events' ;
3131import Forwarders from './forwarders' ;
32- import ServerModel from './serverModel' ;
32+ import ServerModel , { IServerModel } from './serverModel' ;
3333import ForwardingStatsUploader from './forwardingStatsUploader' ;
3434import Identity from './identity' ;
35- import Consent from './consent' ;
35+ import Consent , { IConsent } from './consent' ;
3636import KitBlocker from './kitBlocking' ;
3737import ConfigAPIClient from './configAPIClient' ;
3838import IdentityAPIClient from './identityApiClient' ;
39- import { isFunction } from './utils' ;
39+ import { isFunction , valueof } from './utils' ;
4040import { LocalStorageVault } from './vault' ;
4141import { removeExpiredIdentityCacheDates } from './identity-utils' ;
4242import IntegrationCapture from './integrationCapture' ;
43- import { processReadyQueue } from './pre-init-utils' ;
43+ import { IPreInit , processReadyQueue } from './pre-init-utils' ;
44+ import { BaseEvent , MParticleWebSDK , SDKEventCustomFlags , SDKHelpersApi , } from './sdkRuntimeModels' ;
45+ import { Callback , SDKEventAttrs , SDKEventOptions } from '@mparticle/web-sdk' ;
46+ import { IIdentity } from './identity.interfaces' ;
47+ import { IEvents } from './events.interfaces' ;
48+ import { IECommerce } from './ecommerce.interfaces' ;
49+ import { INativeSdkHelpers } from './nativeSdkHelpers.interfaces' ;
50+ import { IPersistence } from './persistence.interfaces' ;
51+
52+ export interface IErrorLogMessage {
53+ message ?: string ;
54+ name ?: string ;
55+ stack ?: string ;
56+ }
57+
58+ export interface IErrorLogMessageMinified {
59+ m ?: string ;
60+ s ?: string ;
61+ t ?: string ;
62+ }
63+
64+ export type IntegrationDelays = { [ key : number ] : boolean } ;
65+
66+ // https://go.mparticle.com/work/SQDSDKS-6949
67+ export interface IMParticleWebSDKInstance extends MParticleWebSDK {
68+ _instanceName : string ;
69+ _preInit : IPreInit ;
70+
71+ _APIClient : IAPIClient ;
72+ _CookieSyncManager : ICookieSyncManager ;
73+ _Consent : IConsent ;
74+ _Ecommerce : IECommerce ;
75+ _Events : IEvents ;
76+ _Forwarders : any ;
77+ _ForwardingStatsUploader : ForwardingStatsUploader ;
78+ _Helpers : SDKHelpersApi ;
79+ _Identity : IIdentity ;
80+ _IdentityAPIClient : typeof IdentityAPIClient ;
81+ _IntegrationCapture : IntegrationCapture ;
82+ _NativeSdkHelpers : INativeSdkHelpers ;
83+ _Persistence : IPersistence ;
84+ _SessionManager : ISessionManager ;
85+ _Store : IStore ;
86+ _ServerModel : IServerModel ;
87+
88+
89+
90+ configurePixel ( config : IPixelConfiguration ) : void ;
91+ reset ( instance : IMParticleWebSDKInstance ) : void ;
92+ ready ( f : Function ) : void ;
93+ isInitialized ( ) : boolean ;
94+ getEnvironment ( ) : valueof < typeof Constants . Environment > ;
95+ getVersion ( ) : string ;
96+ setAppVersion ( version : string ) : void ;
97+ setAppName ( name : string ) : void ;
98+ startTrackingLocation ( callback ?: Callback ) : void ;
99+ stopTrackingLocation ( ) : void ;
100+ logError ( error : IErrorLogMessage | string , attrs ?: any ) : void ;
101+
102+ // TODO: Define EventInfo
103+ logLink ( selector : string , eventName : string , eventType : valueof < typeof EventType > , eventInfo : any ) : void ;
104+ logForm ( selector : string , eventName : string , eventType : valueof < typeof EventType > , eventInfo : any ) : void ;
105+ logPageView ( eventName : string , attrs ?: SDKEventAttrs , customFlags ?: SDKEventCustomFlags , eventOptions ?: SDKEventOptions ) : void ;
106+ setOptOut ( isOptingOut : boolean ) : void ;
107+
108+ // QUESTION: Should integration ID be a number or a string?
109+ setIntegrationAttribute ( integrationId : number , attrs : IntegrationAttribute ) : void ;
110+ getIntegrationAttributes ( integrationId : number ) : IntegrationAttribute ;
111+ }
44112
45113const { Messages, HTTPCodes, FeatureFlags } = Constants ;
46114const { ReportBatching, CaptureIntegrationSpecificIds } = FeatureFlags ;
@@ -59,7 +127,7 @@ const { StartingInitialization } = Messages.InformationMessages;
59127 * @class mParticle & mParticleInstance
60128 */
61129
62- export default function mParticleInstance ( instanceName ) {
130+ export default function mParticleInstance ( this : IMParticleWebSDKInstance , instanceName : string ) {
63131 var self = this ;
64132 // These classes are for internal use only. Not documented for public consumption
65133 this . _instanceName = instanceName ;
@@ -82,11 +150,12 @@ export default function mParticleInstance(instanceName) {
82150 this . _IntegrationCapture = new IntegrationCapture ( ) ;
83151
84152 // required for forwarders once they reference the mparticle instance
85- this . IdentityType = Types . IdentityType ;
86- this . EventType = Types . EventType ;
87- this . CommerceEventType = Types . CommerceEventType ;
88- this . PromotionType = Types . PromotionActionType ;
89- this . ProductActionType = Types . ProductActionType ;
153+ this . IdentityType = IdentityType ;
154+ this . EventType = EventType as unknown as valueof < typeof EventType > ;
155+ this . CommerceEventType = CommerceEventType as unknown as valueof < typeof CommerceEventType > ;
156+ this . PromotionType = PromotionActionType as unknown as valueof < typeof PromotionActionType > ;
157+ this . ProductActionType = ProductActionType as unknown as valueof < typeof ProductActionType > ;
158+
90159
91160 this . _Identity = new Identity ( this ) ;
92161 this . Identity = this . _Identity . IdentityAPI ;
@@ -372,7 +441,7 @@ export default function mParticleInstance(instanceName) {
372441 }
373442
374443 if ( ! event . eventType ) {
375- event . eventType = Types . EventType . Unknown ;
444+ event . eventType = EventType . Unknown ;
376445 }
377446
378447 if ( ! self . _Helpers . canLog ( ) ) {
@@ -417,15 +486,15 @@ export default function mParticleInstance(instanceName) {
417486 }
418487
419488 if ( ! eventType ) {
420- eventType = Types . EventType . Unknown ;
489+ eventType = EventType . Unknown ;
421490 }
422491
423492 if ( ! self . _Helpers . isEventType ( eventType ) ) {
424493 self . Logger . error (
425494 'Invalid event type: ' +
426495 eventType +
427496 ', must be one of: \n' +
428- JSON . stringify ( Types . EventType )
497+ JSON . stringify ( EventType )
429498 ) ;
430499 return ;
431500 }
@@ -437,12 +506,12 @@ export default function mParticleInstance(instanceName) {
437506
438507 self . _Events . logEvent (
439508 {
440- messageType : Types . MessageType . PageEvent ,
509+ messageType : MessageType . PageEvent ,
441510 name : eventName ,
442511 data : eventInfo ,
443512 eventType : eventType ,
444513 customFlags : customFlags ,
445- } ,
514+ } as BaseEvent ,
446515 eventOptions
447516 ) ;
448517 } ;
@@ -471,8 +540,9 @@ export default function mParticleInstance(instanceName) {
471540 } ;
472541 }
473542
474- var data = {
475- m : error . message ? error . message : error ,
543+ // FIXME: Replace var with const/let
544+ var data : IErrorLogMessageMinified = {
545+ m : error . message ? error . message : error as string ,
476546 s : 'Error' ,
477547 t : error . stack || null ,
478548 } ;
@@ -485,10 +555,11 @@ export default function mParticleInstance(instanceName) {
485555 }
486556
487557 self . _Events . logEvent ( {
488- messageType : Types . MessageType . CrashReport ,
558+ messageType : MessageType . CrashReport ,
489559 name : error . name ? error . name : 'Error' ,
490- data : data ,
491- eventType : Types . EventType . Other ,
560+ // data: data, // QUESTION: Is this a bug? This should be eventType
561+ eventType : EventType . Other ,
562+ data : data as { [ key : string ] : string } ,
492563 } ) ;
493564 } ;
494565 /**
@@ -571,10 +642,10 @@ export default function mParticleInstance(instanceName) {
571642
572643 self . _Events . logEvent (
573644 {
574- messageType : Types . MessageType . PageView ,
645+ messageType : MessageType . PageView ,
575646 name : eventName ,
576- data : attrs ,
577- eventType : Types . EventType . Unknown ,
647+ data : attrs as { [ key : string ] : string } ,
648+ eventType : EventType . Unknown ,
578649 customFlags : customFlags ,
579650 } ,
580651 eventOptions
0 commit comments