-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathsdkRuntimeModels.ts
More file actions
422 lines (381 loc) · 12.7 KB
/
Copy pathsdkRuntimeModels.ts
File metadata and controls
422 lines (381 loc) · 12.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
import * as EventsApi from '@mparticle/event-models';
import { DataPlanVersion } from '@mparticle/data-planning-models';
import {
MPConfiguration,
MPID,
SDKEventOptions,
SDKEventAttrs,
Callback,
} from '@mparticle/web-sdk';
import { IntegrationAttribute, IntegrationAttributes, IStore, WrapperSDKTypes } from './store';
import Validators from './validators';
import { Dictionary, valueof } from './utils';
import { IKitConfigs } from './configAPIClient';
import { SDKConsentApi, SDKConsentState } from './consent';
import MPSideloadedKit from './sideloadedKit';
import { ISessionManager } from './sessionManager';
import { ConfiguredKit, MPForwarder, UnregisteredKit } from './forwarders.interfaces';
import {
SDKIdentityApi,
IAliasCallback,
} from './identity.interfaces';
import {
ISDKUserAttributeChangeData,
ISDKUserIdentityChanges,
IMParticleUser,
ISDKUserIdentity,
IdentityCallback,
ISDKUserAttributes,
} from './identity-user-interfaces';
import {
CommerceEventType,
EventType,
IdentityType,
ProductActionType,
PromotionActionType,
} from './types';
import { IPixelConfiguration } from './cookieSyncManager';
import _BatchValidator from './mockBatchCreator';
import { SDKECommerceAPI } from './ecommerce.interfaces';
import { IErrorLogMessage, IMParticleWebSDKInstance, IntegrationDelays } from './mp-instance';
import Constants from './constants';
import RoktManager, { IRoktLauncherOptions } from './roktManager';
import { IConsoleLogger } from './logger';
// TODO: Resolve this with version in @mparticle/web-sdk
export type SDKEventCustomFlags = Dictionary<any>;
export interface SDKEvent {
DeviceId: string;
IsFirstRun: boolean;
EventName: string;
EventCategory: number;
UserAttributes?: ISDKUserAttributes;
UserIdentities?: ISDKUserIdentity[];
SourceMessageId: string;
MPID: string;
EventAttributes?: { [key: string]: string };
SDKVersion: string;
SessionId: string;
SessionStartDate: number;
SessionLength?: number;
currentSessionMPIDs?: string[];
Timestamp: number;
EventDataType: number;
Debug: boolean;
Location?: SDKGeoLocation;
OptOut?: boolean;
CustomFlags?: SDKEventCustomFlags;
AppVersion?: string;
AppName?: string;
Package?: string;
ConsentState?: SDKConsentState;
IntegrationAttributes?: IntegrationAttributes;
ProductAction?: SDKProductAction;
PromotionAction?: SDKPromotionAction;
ProductImpressions?: SDKProductImpression[];
ShoppingCart?: SDKShoppingCart;
UserIdentityChanges?: ISDKUserIdentityChanges;
UserAttributeChanges?: ISDKUserAttributeChangeData;
CurrencyCode: string;
DataPlan?: SDKDataPlan;
LaunchReferral?: string;
ExpandedEventCount: number;
ActiveTimeOnSite: number;
IsBackgroundAST?: boolean;
}
export interface SDKGeoLocation {
lat: number | string;
lng: number | string;
}
export interface SDKDataPlan {
PlanVersion?: number | null;
PlanId?: string | null;
}
export interface SDKShoppingCart {
ProductList?: SDKProduct[];
}
export interface SDKPromotionAction {
PromotionActionType: string;
PromotionList?: SDKPromotion[];
}
export interface SDKPromotion {
Id?: string;
Name?: string;
Creative?: string;
Position?: string;
}
export interface SDKImpression {
Name: string;
Product: SDKProduct;
}
export interface SDKProductImpression {
ProductImpressionList?: string;
ProductList?: SDKProduct[];
}
export enum SDKProductActionType {
Unknown = 0,
AddToCart = 1,
RemoveFromCart = 2,
Checkout = 3,
CheckoutOption = 4,
Click = 5,
ViewDetail = 6,
Purchase = 7,
Refund = 8,
AddToWishlist = 9,
RemoveFromWishlist = 10,
}
export interface SDKProductAction {
ProductActionType: SDKProductActionType;
CheckoutStep?: number;
CheckoutOptions?: string;
ProductList?: SDKProduct[];
TransactionId?: string;
Affiliation?: string;
CouponCode?: string;
TotalAmount?: number;
ShippingAmount?: number;
TaxAmount?: number;
}
export interface SDKProduct {
Sku?: string;
Name?: string;
Price?: number;
Quantity?: number;
Brand?: string;
Variant?: string;
Category?: string;
Position?: number;
CouponCode?: string;
TotalAmount?: number;
// https://go.mparticle.com/work/SQDSDKS-4801
Attributes?: Record<string, unknown> | null;
}
// https://go.mparticle.com/work/SQDSDKS-6949
export interface MParticleWebSDK {
addForwarder(forwarder: UnregisteredKit): void;
IdentityType: typeof IdentityType;
CommerceEventType: typeof CommerceEventType;
EventType: typeof EventType;
PromotionType: typeof PromotionActionType;
ProductActionType: typeof ProductActionType;
Identity: SDKIdentityApi;
Logger: SDKLoggerApi;
Consent: SDKConsentApi;
_resetForTests(
MPConfig?: SDKInitConfig,
keepPersistence?: boolean,
instance?: IMParticleWebSDKInstance,
): void;
configurePixel(config: IPixelConfiguration): void;
endSession(): void;
init(apiKey: string, config: SDKInitConfig, instanceName?: string): void;
_getActiveForwarders(): ConfiguredKit[];
_getIntegrationDelays(): IntegrationDelays;
_setIntegrationDelay(module: number, shouldDelayIntegration: boolean): void;
_setWrapperSDKInfo(name: WrapperSDKTypes, version: string): void;
getAppName(): string;
getAppVersion(): string;
getDeviceId(): string;
setDeviceId(deviceId: string): void;
getEnvironment(): valueof<typeof Constants.Environment>;
setSessionAttribute(key: string, value: string): void;
getVersion(): string;
upload(): void;
setLogLevel(logLevel: LogLevelType): void;
setPosition(lat: number | string, lng: number | string): void;
startNewSession(): void;
logEvent(
eventName: string,
eventType?: valueof<typeof EventType>,
attrs?: SDKEventAttrs,
customFlags?: SDKEventCustomFlags,
eventOptions?: SDKEventOptions
): void;
logBaseEvent(event: BaseEvent, eventOptions?: SDKEventOptions): void;
logError(error: IErrorLogMessage, attrs?: SDKEventAttrs): 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;
isInitialized(): boolean;
ready(f: Function): void;
// https://go.mparticle.com/work/SQDSDKS-7072
reset(instance?: IMParticleWebSDKInstance): void;
setAppName(name: string): void;
setAppVersion(version: string): void;
setOptOut(isOptingOut: boolean): void;
// https://go.mparticle.com/work/SQDSDKS-7063
startTrackingLocation(callback?: Callback): void;
stopTrackingLocation(): void;
generateHash(value: string): string;
setIntegrationAttribute(integrationModuleId: number, attrs: IntegrationAttribute): void;
getIntegrationAttributes(integrationModuleId: number): IntegrationAttribute;
captureTiming(metricName: string): void;
}
// https://go.mparticle.com/work/SQDSDKS-4805
// https://go.mparticle.com/work/SQDSDKS-6949
export interface IMParticleInstanceManager extends MParticleWebSDK {
// https://go.mparticle.com/work/SQDSDKS-5053
// Private Properties
_BatchValidator: _BatchValidator;
_instances: Dictionary<IMParticleWebSDKInstance>;
_isTestEnv?: boolean;
// Public Properties
config: SDKInitConfig;
isIOS?: boolean;
MPSideloadedKit: typeof MPSideloadedKit;
Rokt: RoktManager;
// https://go.mparticle.com/work/SQDSDKS-7060
sessionManager: Pick<ISessionManager, 'getSession'>;
Store: IStore;
// Public Methods
getInstance(instanceName?: string): IMParticleWebSDKInstance;
}
// Used in cases where server requires booleans as strings
export type BooleanStringLowerCase = 'false' | 'true';
export type BooleanStringTitleCase = 'False' | 'True';
export type LogLevelType = (typeof LogLevelType)[keyof typeof LogLevelType];
export const LogLevelType = {
None: 'none',
Verbose: 'verbose',
Warning: 'warning',
Error: 'error',
} as const;
// TODO: This should eventually be moved into wherever init logic lives
// TODO: Replace/Merge this with MPConfiguration in @types/mparticle__web-sdk
// SDK Init Config represents the config that is passed into mParticle.init when
// the sdk is initialized.
// Currently, this extends MPConfiguration in @types/mparticle__web-sdk
// and the two will be merged in once the Store module is refactored
export interface SDKInitConfig
extends Omit<MPConfiguration, 'dataPlan' | 'logLevel'> {
dataPlan?: DataPlanConfig | KitBlockerDataPlan; // TODO: These should be eventually split into two different attributes
logLevel?: LogLevelType;
kitConfigs?: IKitConfigs[];
kits?: Dictionary<UnregisteredKit>;
sideloadedKits?: MPForwarder[];
dataPlanOptions?: KitBlockerOptions;
flags?: Dictionary;
pixelConfigs?: IPixelConfiguration[];
aliasMaxWindow?: number;
deviceId?: string;
forceHttps?: boolean;
aliasUrl?: string;
configUrl?: string;
identityUrl?: string;
integrationDelayTimeout?: number;
isIOS?: boolean;
maxProducts?: number;
requestConfig?: boolean;
sessionTimeout?: number;
useNativeSdk?: boolean;
useCookieStorage?: boolean;
v1SecureServiceUrl?: string;
v2SecureServiceUrl?: string;
v3SecureServiceUrl?: string;
domain?: string;
workspaceToken?: string;
isDevelopmentMode?: boolean;
// https://go.mparticle.com/work/SQDSDKS-6460
identityCallback?: IdentityCallback;
launcherOptions?: IRoktLauncherOptions;
rq?: Function[] | any[];
logger?: IConsoleLogger;
}
export interface DataPlanConfig {
planId?: string;
planVersion?: number;
document?: DataPlanResult; // when the data plan comes from the server via /mparticle.js
}
export interface SDKHelpersApi {
canLog?(): boolean;
createMainStorageName?(workspaceToken: string): string;
createServiceUrl(url: string, devToken?: string): string;
createXHR?(cb: () => void): XMLHttpRequest;
extend?(...args: any[]);
findKeyInObject?(obj: any, key: string): string;
parseNumber?(value: string | number): number;
generateUniqueId();
generateHash?(value: string): string;
// https://go.mparticle.com/work/SQDSDKS-6317
getFeatureFlag?(feature: string): boolean | string; // TODO: Feature Constants should be converted to enum
invokeAliasCallback(
aliasCallback: IAliasCallback,
number: number,
errorMessage: string
): void;
isDelayedByIntegration?(
delayedIntegrations: Dictionary<boolean>,
timeoutStart: number,
now: number
): boolean;
isEventType?(type: valueof<typeof EventType>): boolean;
isObject?(item: any);
invokeCallback?(
callback: IdentityCallback,
code: number,
body: string,
mParticleUser?: IMParticleUser,
previousMpid?: MPID
): void;
sanitizeAttributes?(
attrs: SDKEventAttrs,
name: string
): Dictionary<string> | null;
Validators: typeof Validators;
}
export interface SDKLoggerApi {
error(arg0: string): void;
verbose(arg0: string): void;
warning(arg0: string): void;
setLogLevel(logLevel: LogLevelType): void;
}
// TODO: Merge this with IStore in store.ts
export interface SDKStoreApi {
isEnabled: boolean;
isFirstRun: boolean;
devToken: string;
SDKConfig: SDKConfigApi;
sessionId?: string;
deviceId?: string;
}
export interface SDKConfigApi {
v3SecureServiceUrl?: string;
isDevelopmentMode: boolean;
appVersion?: string;
onCreateBatch(batch: EventsApi.Batch): EventsApi.Batch;
}
export interface BaseEvent {
messageType: number;
name?: string;
eventType?: number;
data?: SDKEventAttrs;
customFlags?: { [key: string]: string };
toEventAPIObject?(): SDKEvent;
sourceMessageId?: string;
userAttributeChanges?: ISDKUserAttributeChangeData;
userIdentityChanges?: ISDKUserIdentityChanges;
}
export interface KitBlockerOptions {
dataPlanVersion: DataPlanVersion;
blockUserAttributes: boolean;
blockEventAttributes: boolean;
blockEvents: boolean;
blockUserIdentities: boolean;
}
export interface KitBlockerDataPlan {
document: DataPlanResult;
}
export interface DataPlanResult {
dtpn?: {
vers: DataPlanVersion;
blok: {
ev: boolean;
ea: boolean;
ua: boolean;
id: boolean;
};
};
error_message?: string;
}