Skip to content

Commit

Permalink
Clean up interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
alexs-mparticle committed Jan 28, 2025
1 parent feab01f commit 89f458e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 37 deletions.
26 changes: 6 additions & 20 deletions src/mp-instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import NativeSdkHelpers from './nativeSdkHelpers';
import CookieSyncManager, { ICookieSyncManager, IPixelConfiguration } from './cookieSyncManager';
import SessionManager, { ISessionManager } from './sessionManager';
import Ecommerce from './ecommerce';
import Store, { IntegrationAttribute, IStore } from './store';
import Store, { IStore } from './store';
import Logger from './logger';
import Persistence from './persistence';
import Events from './events';
Expand All @@ -41,8 +41,8 @@ import { LocalStorageVault } from './vault';
import { removeExpiredIdentityCacheDates } from './identity-utils';
import IntegrationCapture from './integrationCapture';
import { IPreInit, processReadyQueue } from './pre-init-utils';
import { BaseEvent, MParticleWebSDK, SDKEventCustomFlags, SDKHelpersApi, } from './sdkRuntimeModels';
import { Callback, SDKEventAttrs, SDKEventOptions } from '@mparticle/web-sdk';
import { BaseEvent, MParticleWebSDK, SDKHelpersApi, } from './sdkRuntimeModels';
import { Callback, SDKEventAttrs } from '@mparticle/web-sdk';
import { IIdentity } from './identity.interfaces';
import { IEvents } from './events.interfaces';
import { IECommerce } from './ecommerce.interfaces';
Expand Down Expand Up @@ -85,29 +85,17 @@ export interface IMParticleWebSDKInstance extends MParticleWebSDK {
_Store: IStore;
_ServerModel: IServerModel;



configurePixel(config: IPixelConfiguration): void;
reset(instance: IMParticleWebSDKInstance): void;
ready(f: Function): void;
isInitialized(): boolean;
getEnvironment(): valueof<typeof Constants.Environment>;
getVersion(): string;
logError(error: IErrorLogMessage, attrs?: SDKEventAttrs): void;
setAppVersion(version: string): void;
setAppName(name: string): void;
startTrackingLocation(callback?: Callback): void;
stopTrackingLocation(): void;
logError(error: IErrorLogMessage | string, attrs?: any): void;

// TODO: Define EventInfo
logLink(selector: string, eventName: string, eventType: valueof<typeof EventType>, eventInfo: any): void;
logForm(selector: string, eventName: string, eventType: valueof<typeof EventType>, eventInfo: any): void;
logPageView(eventName: string, attrs?: SDKEventAttrs, customFlags?: SDKEventCustomFlags, eventOptions?: SDKEventOptions): void;
setOptOut(isOptingOut: boolean): void;

// QUESTION: Should integration ID be a number or a string?
setIntegrationAttribute(integrationId: number, attrs: IntegrationAttribute): void;
getIntegrationAttributes(integrationId: number): IntegrationAttribute;
}

const { Messages, HTTPCodes, FeatureFlags } = Constants;
Expand Down Expand Up @@ -540,8 +528,7 @@ export default function mParticleInstance(this: IMParticleWebSDKInstance, instan
};
}

// FIXME: Replace var with const/let
var data: IErrorLogMessageMinified = {
const data: IErrorLogMessageMinified = {
m: error.message ? error.message : error as string,
s: 'Error',
t: error.stack || null,
Expand All @@ -557,9 +544,8 @@ export default function mParticleInstance(this: IMParticleWebSDKInstance, instan
self._Events.logEvent({
messageType: MessageType.CrashReport,
name: error.name ? error.name : 'Error',
// data: data, // QUESTION: Is this a bug? This should be eventType
eventType: EventType.Other,
data: data as { [key: string]: string },
data: data as SDKEventAttrs,
});
};
/**
Expand Down
28 changes: 11 additions & 17 deletions src/sdkRuntimeModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { IMPSideloadedKit } from './sideloadedKit';
import { ISessionManager } from './sessionManager';
import { Kit, MPForwarder } from './forwarders.interfaces';
import {
IIdentity,
SDKIdentityApi,
IAliasCallback,
} from './identity.interfaces';
Expand All @@ -38,8 +37,8 @@ import {
} from './types';
import { IPixelConfiguration } from './cookieSyncManager';
import _BatchValidator from './mockBatchCreator';
import { SDKECommerceAPI } from './ecommerce.interfaces';
import { IErrorLogMessage, IMParticleWebSDKInstance, IntegrationDelays } from './mp-instance';
import { SDKECommerceAPI } from './ecommerce.interfaces';
import { IMParticleWebSDKInstance, IntegrationDelays } from './mp-instance';
import Constants from './constants';

// TODO: Resolve this with version in @mparticle/web-sdk
Expand Down Expand Up @@ -200,6 +199,10 @@ export interface MParticleWebSDK {
eventOptions?: SDKEventOptions
): void;
logBaseEvent(event: BaseEvent, eventOptions?: SDKEventOptions): void;
logLink(selector: string, eventName: string, eventType: valueof<typeof EventType>, eventInfo: SDKEventAttrs): void;
logForm(selector: string, eventName: string, eventType: valueof<typeof EventType>, eventInfo: SDKEventAttrs): void;
logPageView(eventName: string, attrs?: SDKEventAttrs, customFlags?: SDKEventCustomFlags, eventOptions?: SDKEventOptions): void;
setOptOut(isOptingOut: boolean): void;
eCommerce: SDKECommerceAPI;

// QUESTION: Is this still used?
Expand All @@ -208,6 +211,9 @@ export interface MParticleWebSDK {
ProductActionType: valueof<typeof ProductActionType>;
generateHash(value: string): string;

// QUESTION: Should integration ID be a number or a string?
setIntegrationAttribute(integrationId: number, attrs: IntegrationAttribute): void;
getIntegrationAttributes(integrationId: number): IntegrationAttribute;
}

// https://go.mparticle.com/work/SQDSDKS-4805
Expand Down Expand Up @@ -235,13 +241,6 @@ export interface IMParticleInstanceManager extends MParticleWebSDK {
getInstance(instanceName?: string): IMParticleWebSDKInstance;
getVersion(): string;
isInitialized(): boolean;

// TODO: Define EventInfo
logError(error: IErrorLogMessage | string, attrs?: any): void;
logForm(selector: string, eventName: string, eventType: valueof<typeof EventType>, eventInfo: any): void;
logLink(selector: string, eventName: string, eventType: valueof<typeof EventType>, eventInfo: any): void;
logPageView(eventName: string, attrs?: SDKEventAttrs, customFlags?: SDKEventCustomFlags, eventOptions?: SDKEventOptions): void;


ready(f: Function): void;
reset(instance: IMParticleWebSDKInstance): void;
Expand All @@ -251,11 +250,6 @@ export interface IMParticleInstanceManager extends MParticleWebSDK {
startTrackingLocation(callback?: Callback): void;
stopTrackingLocation(): void;


// QUESTION: Should integration ID be a number or a string?
setIntegrationAttribute(integrationId: number, attrs: IntegrationAttribute): void;
getIntegrationAttributes(integrationId: number): IntegrationAttribute;

// @deprecated
sessionManager: Pick<ISessionManager, 'getSession'>;
}
Expand Down Expand Up @@ -350,7 +344,7 @@ export interface SDKHelpersApi {
previousMpid?: MPID
): void;
sanitizeAttributes?(
attrs: Dictionary<string>,
attrs: SDKEventAttrs,
name: string
): Dictionary<string> | null;
Validators: typeof Validators;
Expand Down Expand Up @@ -384,7 +378,7 @@ export interface BaseEvent {
messageType: number;
name?: string;
eventType?: number;
data?: { [key: string]: string };
data?: SDKEventAttrs;
customFlags?: { [key: string]: string };
toEventAPIObject?(): SDKEvent;
sourceMessageId?: string;
Expand Down

0 comments on commit 89f458e

Please sign in to comment.