@mparticle/web-sdk 2.18.1 → 2.18.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mparticle.common.js +14 -12
- package/dist/mparticle.esm.js +14 -12
- package/dist/mparticle.js +237 -190
- package/package.json +1 -1
- package/src/{apiClient.js → apiClient.ts} +60 -20
- package/src/configAPIClient.ts +141 -0
- package/src/consent.interfaces.ts +89 -0
- package/src/mockBatchCreator.ts +15 -5
- package/src/mp-instance.js +20 -0
- package/src/mparticle-instance-manager.js +3 -0
- package/src/sdkRuntimeModels.ts +35 -32
- package/src/sdkToEventsApiConverter.ts +64 -59
- package/src/serverModel.ts +6 -26
- package/src/store.ts +16 -3
- package/src/configAPIClient.js +0 -67
|
@@ -1,15 +1,51 @@
|
|
|
1
1
|
import Constants from './constants';
|
|
2
2
|
import Types from './types';
|
|
3
3
|
import { BatchUploader } from './batchUploader';
|
|
4
|
+
import {
|
|
5
|
+
MParticleUser,
|
|
6
|
+
MParticleWebSDK,
|
|
7
|
+
MPForwarder,
|
|
8
|
+
SDKEvent,
|
|
9
|
+
} from './sdkRuntimeModels';
|
|
10
|
+
import KitBlocker from './kitBlocking';
|
|
11
|
+
import { Dictionary } from './utils';
|
|
12
|
+
import { IUploadObject } from './serverModel';
|
|
4
13
|
|
|
5
|
-
|
|
14
|
+
const Messages = Constants.Messages;
|
|
6
15
|
|
|
7
|
-
export
|
|
16
|
+
export type ForwardingStatsData = Dictionary<any>;
|
|
17
|
+
|
|
18
|
+
export interface IAPIClient {
|
|
19
|
+
uploader: BatchUploader | null;
|
|
20
|
+
queueEventForBatchUpload: (event: SDKEvent) => void;
|
|
21
|
+
shouldEnableBatching: () => boolean;
|
|
22
|
+
processQueuedEvents: () => void;
|
|
23
|
+
appendUserInfoToEvents: (user: MParticleUser, events: SDKEvent[]) => void;
|
|
24
|
+
sendEventToServer: (event: SDKEvent, _options?: Dictionary<any>) => void;
|
|
25
|
+
sendSingleEventToServer: (event: SDKEvent) => void;
|
|
26
|
+
sendBatchForwardingStatsToServer: (
|
|
27
|
+
forwardingStatsData: ForwardingStatsData,
|
|
28
|
+
xhr: XMLHttpRequest
|
|
29
|
+
) => void;
|
|
30
|
+
sendSingleForwardingStatsToServer: (
|
|
31
|
+
forwardingStatsData: ForwardingStatsData
|
|
32
|
+
) => void;
|
|
33
|
+
prepareForwardingStats: (
|
|
34
|
+
forwarder: MPForwarder,
|
|
35
|
+
event: IUploadObject
|
|
36
|
+
) => void;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export default function APIClient(
|
|
40
|
+
this: IAPIClient,
|
|
41
|
+
mpInstance: MParticleWebSDK,
|
|
42
|
+
kitBlocker: KitBlocker
|
|
43
|
+
) {
|
|
8
44
|
this.uploader = null;
|
|
9
|
-
|
|
10
|
-
this.queueEventForBatchUpload = function(event) {
|
|
45
|
+
const self = this;
|
|
46
|
+
this.queueEventForBatchUpload = function(event: SDKEvent) {
|
|
11
47
|
if (!this.uploader) {
|
|
12
|
-
|
|
48
|
+
const millis = mpInstance._Helpers.getFeatureFlag(
|
|
13
49
|
Constants.FeatureFlags.EventBatchingIntervalMillis
|
|
14
50
|
);
|
|
15
51
|
this.uploader = new BatchUploader(mpInstance, millis);
|
|
@@ -22,7 +58,7 @@ export default function APIClient(mpInstance, kitBlocker) {
|
|
|
22
58
|
this.shouldEnableBatching = function() {
|
|
23
59
|
// Returns a string of a number that must be parsed
|
|
24
60
|
// Invalid strings will be parsed to NaN which is falsey
|
|
25
|
-
|
|
61
|
+
const eventsV3Percentage = parseInt(
|
|
26
62
|
mpInstance._Helpers.getFeatureFlag(Constants.FeatureFlags.EventsV3),
|
|
27
63
|
10
|
|
28
64
|
);
|
|
@@ -31,20 +67,20 @@ export default function APIClient(mpInstance, kitBlocker) {
|
|
|
31
67
|
return false;
|
|
32
68
|
}
|
|
33
69
|
|
|
34
|
-
|
|
70
|
+
const rampNumber = mpInstance._Helpers.getRampNumber(
|
|
35
71
|
mpInstance._Store.deviceId
|
|
36
72
|
);
|
|
37
73
|
return eventsV3Percentage >= rampNumber;
|
|
38
74
|
};
|
|
39
75
|
|
|
40
76
|
this.processQueuedEvents = function() {
|
|
41
|
-
|
|
77
|
+
let mpid,
|
|
42
78
|
currentUser = mpInstance.Identity.getCurrentUser();
|
|
43
79
|
if (currentUser) {
|
|
44
80
|
mpid = currentUser.getMPID();
|
|
45
81
|
}
|
|
46
82
|
if (mpInstance._Store.eventQueue.length && mpid) {
|
|
47
|
-
|
|
83
|
+
const localQueueCopy = mpInstance._Store.eventQueue;
|
|
48
84
|
mpInstance._Store.eventQueue = [];
|
|
49
85
|
this.appendUserInfoToEvents(currentUser, localQueueCopy);
|
|
50
86
|
localQueueCopy.forEach(function(event) {
|
|
@@ -62,10 +98,10 @@ export default function APIClient(mpInstance, kitBlocker) {
|
|
|
62
98
|
};
|
|
63
99
|
|
|
64
100
|
this.sendEventToServer = function(event, _options) {
|
|
65
|
-
|
|
101
|
+
const defaultOptions = {
|
|
66
102
|
shouldUploadEvent: true,
|
|
67
103
|
};
|
|
68
|
-
|
|
104
|
+
const options = mpInstance._Helpers.extend(defaultOptions, _options);
|
|
69
105
|
|
|
70
106
|
if (mpInstance._Store.webviewBridgeEnabled) {
|
|
71
107
|
mpInstance._NativeSdkHelpers.sendToNative(
|
|
@@ -75,7 +111,7 @@ export default function APIClient(mpInstance, kitBlocker) {
|
|
|
75
111
|
return;
|
|
76
112
|
}
|
|
77
113
|
|
|
78
|
-
|
|
114
|
+
let mpid,
|
|
79
115
|
currentUser = mpInstance.Identity.getCurrentUser();
|
|
80
116
|
if (currentUser) {
|
|
81
117
|
mpid = currentUser.getMPID();
|
|
@@ -126,7 +162,7 @@ export default function APIClient(mpInstance, kitBlocker) {
|
|
|
126
162
|
if (event.EventDataType === Types.MessageType.Media) {
|
|
127
163
|
return;
|
|
128
164
|
}
|
|
129
|
-
|
|
165
|
+
let xhr,
|
|
130
166
|
xhrCallback = function() {
|
|
131
167
|
if (xhr.readyState === 4) {
|
|
132
168
|
mpInstance.Logger.verbose(
|
|
@@ -153,7 +189,9 @@ export default function APIClient(mpInstance, kitBlocker) {
|
|
|
153
189
|
);
|
|
154
190
|
xhr.send(
|
|
155
191
|
JSON.stringify(
|
|
156
|
-
mpInstance._ServerModel.convertEventToDTO(
|
|
192
|
+
mpInstance._ServerModel.convertEventToDTO(
|
|
193
|
+
event as IUploadObject
|
|
194
|
+
)
|
|
157
195
|
)
|
|
158
196
|
);
|
|
159
197
|
} catch (e) {
|
|
@@ -165,7 +203,8 @@ export default function APIClient(mpInstance, kitBlocker) {
|
|
|
165
203
|
};
|
|
166
204
|
|
|
167
205
|
this.sendBatchForwardingStatsToServer = function(forwardingStatsData, xhr) {
|
|
168
|
-
|
|
206
|
+
let url;
|
|
207
|
+
let data;
|
|
169
208
|
try {
|
|
170
209
|
url = mpInstance._Helpers.createServiceUrl(
|
|
171
210
|
mpInstance._Store.SDKConfig.v2SecureServiceUrl,
|
|
@@ -188,9 +227,10 @@ export default function APIClient(mpInstance, kitBlocker) {
|
|
|
188
227
|
};
|
|
189
228
|
|
|
190
229
|
this.sendSingleForwardingStatsToServer = function(forwardingStatsData) {
|
|
191
|
-
|
|
230
|
+
let url;
|
|
231
|
+
let data;
|
|
192
232
|
try {
|
|
193
|
-
|
|
233
|
+
const xhrCallback = function() {
|
|
194
234
|
if (xhr.readyState === 4) {
|
|
195
235
|
if (xhr.status === 202) {
|
|
196
236
|
mpInstance.Logger.verbose(
|
|
@@ -201,7 +241,7 @@ export default function APIClient(mpInstance, kitBlocker) {
|
|
|
201
241
|
}
|
|
202
242
|
}
|
|
203
243
|
};
|
|
204
|
-
|
|
244
|
+
const xhr = mpInstance._Helpers.createXHR(xhrCallback);
|
|
205
245
|
url = mpInstance._Helpers.createServiceUrl(
|
|
206
246
|
mpInstance._Store.SDKConfig.v1SecureServiceUrl,
|
|
207
247
|
mpInstance._Store.devToken
|
|
@@ -220,8 +260,8 @@ export default function APIClient(mpInstance, kitBlocker) {
|
|
|
220
260
|
};
|
|
221
261
|
|
|
222
262
|
this.prepareForwardingStats = function(forwarder, event) {
|
|
223
|
-
|
|
224
|
-
|
|
263
|
+
let forwardingStatsData;
|
|
264
|
+
const queue = mpInstance._Forwarders.getForwarderStatsQueue();
|
|
225
265
|
|
|
226
266
|
if (forwarder && forwarder.isVisible) {
|
|
227
267
|
forwardingStatsData = {
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { DataPlanConfig } from '@mparticle/web-sdk';
|
|
2
|
+
import {
|
|
3
|
+
BooleanStringLowerCase,
|
|
4
|
+
DataPlanResult,
|
|
5
|
+
MParticleWebSDK,
|
|
6
|
+
SDKEventCustomFlags,
|
|
7
|
+
SDKInitConfig,
|
|
8
|
+
} from './sdkRuntimeModels';
|
|
9
|
+
import { Dictionary } from './utils';
|
|
10
|
+
|
|
11
|
+
export type SDKCompleteInitCallback = (
|
|
12
|
+
apiKey: string,
|
|
13
|
+
config: SDKInitConfig,
|
|
14
|
+
mpInstance: MParticleWebSDK
|
|
15
|
+
) => void;
|
|
16
|
+
|
|
17
|
+
export interface IKitConfigs {
|
|
18
|
+
name: string;
|
|
19
|
+
moduleId: number;
|
|
20
|
+
isDebug: boolean;
|
|
21
|
+
isVisible: boolean;
|
|
22
|
+
isDebugString: BooleanStringLowerCase;
|
|
23
|
+
hasDebugString: BooleanStringLowerCase;
|
|
24
|
+
settings: Dictionary;
|
|
25
|
+
screenNameFilters: number[];
|
|
26
|
+
screenAttributeFilters: number[];
|
|
27
|
+
userIdentityFilters: number[];
|
|
28
|
+
userAttributeFilters: number[];
|
|
29
|
+
eventNameFilters: number[];
|
|
30
|
+
eventTypeFilters: number[];
|
|
31
|
+
attributeFilters: number[];
|
|
32
|
+
filteringEventAttributeValue: Dictionary;
|
|
33
|
+
filteringConsentRuleValues: Dictionary;
|
|
34
|
+
consentRegulationFilters: number[];
|
|
35
|
+
consentRegulationPurposeFilters: number[];
|
|
36
|
+
messageTypeFilters: number[];
|
|
37
|
+
messageTypeStateFilters: number[];
|
|
38
|
+
eventSubscriptionId: number;
|
|
39
|
+
excludeAnonymousUser: boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface IPixelConfig {
|
|
43
|
+
name: string;
|
|
44
|
+
moduleId: number;
|
|
45
|
+
esId: number;
|
|
46
|
+
isDebug: boolean;
|
|
47
|
+
isProduction: boolean;
|
|
48
|
+
settings: Dictionary;
|
|
49
|
+
frequencyCap: number;
|
|
50
|
+
pixelUrl: string;
|
|
51
|
+
redirectUrl: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface IConfigResponse {
|
|
55
|
+
appName: string;
|
|
56
|
+
dataPlanResult: DataPlanResult;
|
|
57
|
+
kitConfigs: IKitConfigs[];
|
|
58
|
+
serviceUrl: string;
|
|
59
|
+
secureServiceUrl: string;
|
|
60
|
+
minWebviewBridgeVersion: number;
|
|
61
|
+
workspaceToken: string;
|
|
62
|
+
pixelConfigs: IPixelConfig[];
|
|
63
|
+
flags: SDKEventCustomFlags;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface IConfigAPIClient {
|
|
67
|
+
getSDKConfiguration: (
|
|
68
|
+
apiKey: string,
|
|
69
|
+
config: SDKInitConfig,
|
|
70
|
+
completeSDKInitialization: SDKCompleteInitCallback,
|
|
71
|
+
mpInstance: MParticleWebSDK
|
|
72
|
+
) => void;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export default function ConfigAPIClient(this: IConfigAPIClient) {
|
|
76
|
+
this.getSDKConfiguration = (
|
|
77
|
+
apiKey,
|
|
78
|
+
config,
|
|
79
|
+
completeSDKInitialization,
|
|
80
|
+
mpInstance
|
|
81
|
+
): void => {
|
|
82
|
+
let url: string;
|
|
83
|
+
try {
|
|
84
|
+
const xhrCallback = function() {
|
|
85
|
+
if (xhr.readyState === 4) {
|
|
86
|
+
// when a 200 returns, merge current config with what comes back from config, prioritizing user inputted config
|
|
87
|
+
if (xhr.status === 200) {
|
|
88
|
+
config = mpInstance._Helpers.extend(
|
|
89
|
+
{},
|
|
90
|
+
config,
|
|
91
|
+
JSON.parse(xhr.responseText)
|
|
92
|
+
);
|
|
93
|
+
completeSDKInitialization(apiKey, config, mpInstance);
|
|
94
|
+
mpInstance.Logger.verbose(
|
|
95
|
+
'Successfully received configuration from server'
|
|
96
|
+
);
|
|
97
|
+
} else {
|
|
98
|
+
// if for some reason a 200 doesn't return, then we initialize with the just the passed through config
|
|
99
|
+
completeSDKInitialization(apiKey, config, mpInstance);
|
|
100
|
+
mpInstance.Logger.verbose(
|
|
101
|
+
'Issue with receiving configuration from server, received HTTP Code of ' +
|
|
102
|
+
xhr.status
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const xhr = mpInstance._Helpers.createXHR(xhrCallback);
|
|
109
|
+
url =
|
|
110
|
+
'https://' +
|
|
111
|
+
mpInstance._Store.SDKConfig.configUrl +
|
|
112
|
+
apiKey +
|
|
113
|
+
'/config?env=';
|
|
114
|
+
if (config.isDevelopmentMode) {
|
|
115
|
+
url = url + '1';
|
|
116
|
+
} else {
|
|
117
|
+
url = url + '0';
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const dataPlan = config.dataPlan as DataPlanConfig;
|
|
121
|
+
if (dataPlan) {
|
|
122
|
+
if (dataPlan.planId) {
|
|
123
|
+
url = url + '&plan_id=' + dataPlan.planId || '';
|
|
124
|
+
}
|
|
125
|
+
if (dataPlan.planVersion) {
|
|
126
|
+
url = url + '&plan_version=' + dataPlan.planVersion || '';
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (xhr) {
|
|
131
|
+
xhr.open('get', url);
|
|
132
|
+
xhr.send(null);
|
|
133
|
+
}
|
|
134
|
+
} catch (e) {
|
|
135
|
+
completeSDKInitialization(apiKey, config, mpInstance);
|
|
136
|
+
mpInstance.Logger.error(
|
|
137
|
+
'Error getting forwarder configuration from mParticle servers.'
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// TODO: Migrate this to Consent.ts when that is created
|
|
2
|
+
import { ConsentState, PrivacyConsentState } from '@mparticle/web-sdk';
|
|
3
|
+
|
|
4
|
+
export interface IGDPRConsentObject {
|
|
5
|
+
purpose: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface ICCPAConsentObject {
|
|
9
|
+
purpose: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface IConsentJSONObject {
|
|
13
|
+
gdpr?: Partial<IGDPRConsentObject>;
|
|
14
|
+
ccpa?: Partial<ICCPAConsentObject>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface ICreatePrivacyConsentFunction {
|
|
18
|
+
(
|
|
19
|
+
consented: boolean,
|
|
20
|
+
timestamp?: number,
|
|
21
|
+
consentDocument?: string,
|
|
22
|
+
location?: string,
|
|
23
|
+
hardwareId?: string
|
|
24
|
+
): PrivacyConsentState | null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// TODO: Refactor this with Consent Namespace in @types/mparticle-web-sdk
|
|
28
|
+
// https://go.mparticle.com/work/SQDSDKS-5009
|
|
29
|
+
export interface SDKConsentApi {
|
|
30
|
+
createGDPRConsent: ICreatePrivacyConsentFunction;
|
|
31
|
+
createCCPAConsent: ICreatePrivacyConsentFunction;
|
|
32
|
+
createConsentState: (consentState?: ConsentState) => ConsentState;
|
|
33
|
+
ConsentSerialization: IConsentSerialization;
|
|
34
|
+
createPrivacyConsent: ICreatePrivacyConsentFunction;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface IConsentSerialization {
|
|
38
|
+
toMinifiedJsonObject: (state: ConsentState) => IConsentJSONObject;
|
|
39
|
+
fromMinifiedJsonObject: (json: IConsentJSONObject) => ConsentState;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// TODO: Resolve discrepency between ConsentState and SDKConsentState
|
|
43
|
+
// https://go.mparticle.com/work/SQDSDKS-5009
|
|
44
|
+
export interface SDKConsentState
|
|
45
|
+
extends Omit<ConsentState, 'getGDPRConsentState' | 'getCCPAConsentState'> {
|
|
46
|
+
getGDPRConsentState(): SDKGDPRConsentState;
|
|
47
|
+
getCCPAConsentState(): SDKCCPAConsentState;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface SDKGDPRConsentState {
|
|
51
|
+
[key: string]: SDKConsentStateData;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// TODO: Resolve discrepency between ConsentState and SDKConsentState
|
|
55
|
+
// https://go.mparticle.com/work/SQDSDKS-5009
|
|
56
|
+
// Specifically PrivacyConsentState, GDPRConsentState and CCPAConsentState
|
|
57
|
+
// Treat all attributes as required, but we had to override this
|
|
58
|
+
// to be optional for a bugfix:
|
|
59
|
+
// https://github.com/mParticle/mparticle-web-sdk/commit/3b11ead79f25b417737442a4fabd6435750f46b8
|
|
60
|
+
export interface SDKConsentStateData {
|
|
61
|
+
Consented: boolean;
|
|
62
|
+
Timestamp?: number;
|
|
63
|
+
ConsentDocument?: string;
|
|
64
|
+
Location?: string;
|
|
65
|
+
HardwareId?: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface SDKCCPAConsentState extends SDKConsentStateData {}
|
|
69
|
+
|
|
70
|
+
export interface IPrivacyV2DTO {
|
|
71
|
+
c: boolean; // Consented
|
|
72
|
+
ts: number; // Timestamp
|
|
73
|
+
d: string; // Document
|
|
74
|
+
l: string; // Location
|
|
75
|
+
h: string; // HardwareID
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface IGDPRConsentStateDTO {
|
|
79
|
+
[key: string]: IPrivacyV2DTO;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface ICCPAConsentStateDTO {
|
|
83
|
+
data_sale_opt_out: IPrivacyV2DTO;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface IConsentStateDTO {
|
|
87
|
+
gdpr?: IGDPRConsentStateDTO;
|
|
88
|
+
ccpa?: ICCPAConsentStateDTO;
|
|
89
|
+
}
|
package/src/mockBatchCreator.ts
CHANGED
|
@@ -7,15 +7,15 @@ import * as EventsApi from '@mparticle/event-models';
|
|
|
7
7
|
|
|
8
8
|
const mockFunction = function () {
|
|
9
9
|
return null;
|
|
10
|
-
}
|
|
10
|
+
};
|
|
11
11
|
export default class _BatchValidator {
|
|
12
12
|
private getMPInstance() {
|
|
13
13
|
return {
|
|
14
14
|
// Certain Helper, Store, and Identity properties need to be mocked to be used in the `returnBatch` method
|
|
15
15
|
_Helpers: {
|
|
16
|
-
sanitizeAttributes:
|
|
17
|
-
.sanitizeAttributes,
|
|
18
|
-
generateUniqueId: function() {
|
|
16
|
+
sanitizeAttributes:
|
|
17
|
+
window.mParticle.getInstance()._Helpers.sanitizeAttributes,
|
|
18
|
+
generateUniqueId: function () {
|
|
19
19
|
return 'mockId';
|
|
20
20
|
},
|
|
21
21
|
extend: window.mParticle.getInstance()._Helpers.extend,
|
|
@@ -28,6 +28,11 @@ export default class _BatchValidator {
|
|
|
28
28
|
_resetForTests: mockFunction,
|
|
29
29
|
_APIClient: null,
|
|
30
30
|
_Consent: null,
|
|
31
|
+
_Forwarders: null,
|
|
32
|
+
_NativeSdkHelpers: null,
|
|
33
|
+
_Persistence: null,
|
|
34
|
+
_preInit: null,
|
|
35
|
+
Consent: null,
|
|
31
36
|
_ServerModel: null,
|
|
32
37
|
_SessionManager: null,
|
|
33
38
|
_Store: {
|
|
@@ -69,6 +74,11 @@ export default class _BatchValidator {
|
|
|
69
74
|
kits: {},
|
|
70
75
|
configuredForwarders: [],
|
|
71
76
|
pixelConfigurations: [],
|
|
77
|
+
wrapperSDKInfo: {
|
|
78
|
+
name: 'none',
|
|
79
|
+
version: null,
|
|
80
|
+
isInfoSet: false,
|
|
81
|
+
},
|
|
72
82
|
SDKConfig: {
|
|
73
83
|
isDevelopmentMode: false,
|
|
74
84
|
onCreateBatch: mockFunction,
|
|
@@ -102,7 +112,7 @@ export default class _BatchValidator {
|
|
|
102
112
|
logLevel: 'none',
|
|
103
113
|
setPosition: mockFunction,
|
|
104
114
|
upload: mockFunction,
|
|
105
|
-
};
|
|
115
|
+
} as MParticleWebSDK;
|
|
106
116
|
}
|
|
107
117
|
|
|
108
118
|
returnBatch(event: BaseEvent) {
|
package/src/mp-instance.js
CHANGED
|
@@ -1261,6 +1261,26 @@ export default function mParticleInstance(instanceName) {
|
|
|
1261
1261
|
self._APIClient.processQueuedEvents();
|
|
1262
1262
|
}
|
|
1263
1263
|
};
|
|
1264
|
+
|
|
1265
|
+
// Internal use only. Used by our wrapper SDKs to identify themselves during initialization.
|
|
1266
|
+
this._setWrapperSDKInfo = function(name, version) {
|
|
1267
|
+
var queued = queueIfNotInitialized(function() {
|
|
1268
|
+
self._setWrapperSDKInfo(name, version);
|
|
1269
|
+
}, self);
|
|
1270
|
+
|
|
1271
|
+
if (queued) return;
|
|
1272
|
+
|
|
1273
|
+
if (
|
|
1274
|
+
self._Store.wrapperSDKInfo === undefined ||
|
|
1275
|
+
!self._Store.wrapperSDKInfo.isInfoSet
|
|
1276
|
+
) {
|
|
1277
|
+
self._Store.wrapperSDKInfo = {
|
|
1278
|
+
name: name,
|
|
1279
|
+
version: version,
|
|
1280
|
+
isInfoSet: true,
|
|
1281
|
+
};
|
|
1282
|
+
}
|
|
1283
|
+
};
|
|
1264
1284
|
}
|
|
1265
1285
|
|
|
1266
1286
|
// Some (server) config settings need to be returned before they are set on SDKConfig in a self hosted environment
|
|
@@ -472,6 +472,9 @@ function mParticle() {
|
|
|
472
472
|
this._getActiveForwarders = function() {
|
|
473
473
|
return self.getInstance()._getActiveForwarders();
|
|
474
474
|
};
|
|
475
|
+
this._setWrapperSDKInfo = function(name, version) {
|
|
476
|
+
self.getInstance()._setWrapperSDKInfo(name, version);
|
|
477
|
+
};
|
|
475
478
|
}
|
|
476
479
|
|
|
477
480
|
var mparticleInstance = new mParticle();
|
package/src/sdkRuntimeModels.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import * as EventsApi from '@mparticle/event-models';
|
|
2
|
-
import {
|
|
3
|
-
import { DataPlanVersion, DataPlan } from '@mparticle/data-planning-models';
|
|
2
|
+
import { DataPlanVersion } from '@mparticle/data-planning-models';
|
|
4
3
|
import { MPConfiguration, IdentityApiData } from '@mparticle/web-sdk';
|
|
5
|
-
import { IStore
|
|
4
|
+
import { IStore } from './store';
|
|
6
5
|
import Validators from './validators';
|
|
7
6
|
import { Dictionary } from './utils';
|
|
8
7
|
import { IServerModel } from './serverModel';
|
|
9
|
-
|
|
8
|
+
import { IKitConfigs } from './configAPIClient';
|
|
9
|
+
import { SDKConsentApi, SDKConsentState } from './consent.interfaces';
|
|
10
10
|
|
|
11
11
|
// TODO: Resolve this with version in @mparticle/web-sdk
|
|
12
12
|
export type SDKEventCustomFlags = Dictionary<any>;
|
|
@@ -131,12 +131,17 @@ export interface MParticleWebSDK {
|
|
|
131
131
|
Logger: SDKLoggerApi;
|
|
132
132
|
_APIClient: any; // TODO: Set up API Client
|
|
133
133
|
_Store: IStore;
|
|
134
|
+
_Forwarders: any;
|
|
134
135
|
_Helpers: SDKHelpersApi;
|
|
135
136
|
config: SDKInitConfig;
|
|
136
137
|
_ServerModel: IServerModel;
|
|
137
138
|
_SessionManager: any; // TODO: Set up Session Manager
|
|
138
|
-
_Consent:
|
|
139
|
-
|
|
139
|
+
_Consent: SDKConsentApi;
|
|
140
|
+
Consent: SDKConsentApi;
|
|
141
|
+
_NativeSdkHelpers: any; // TODO: Set up API
|
|
142
|
+
_Persistence: any; // TODO: Set up Persistence API
|
|
143
|
+
_preInit: any; // TODO: Set up API
|
|
144
|
+
_resetForTests(MPConfig?: SDKInitConfig): void;
|
|
140
145
|
init(apiKey: string, config: SDKInitConfig, instanceName?: string): void;
|
|
141
146
|
getAppName(): string;
|
|
142
147
|
getAppVersion(): string;
|
|
@@ -158,10 +163,13 @@ export interface MParticleWebSDK {
|
|
|
158
163
|
isIOS?: boolean;
|
|
159
164
|
}
|
|
160
165
|
|
|
166
|
+
// Used in cases where server requires booleans as strings
|
|
167
|
+
export type BooleanStringLowerCase = 'false' | 'true';
|
|
168
|
+
export type BooleanStringTitleCase = 'False' | 'True';
|
|
169
|
+
|
|
161
170
|
export type LogLevelType = 'none' | 'verbose' | 'warning' | 'error';
|
|
162
171
|
|
|
163
172
|
// TODO: Create true types for Kits and Kit Configs
|
|
164
|
-
export type KitConfigs = Dictionary;
|
|
165
173
|
export type Kit = Dictionary;
|
|
166
174
|
export type MPForwarder = Dictionary;
|
|
167
175
|
|
|
@@ -172,11 +180,11 @@ export type MPForwarder = Dictionary;
|
|
|
172
180
|
// Currently, this extends MPConfiguration in @types/mparticle__web-sdk
|
|
173
181
|
// and the two will be merged in once the Store module is refactored
|
|
174
182
|
export interface SDKInitConfig
|
|
175
|
-
extends Omit<MPConfiguration, 'dataPlan' | 'logLevel'> {
|
|
183
|
+
extends Omit<MPConfiguration, 'dataPlan' | 'logLevel'> {
|
|
176
184
|
dataPlan?: DataPlanConfig | KitBlockerDataPlan; // TODO: These should be eventually split into two different attributes
|
|
177
185
|
logLevel?: LogLevelType;
|
|
178
186
|
|
|
179
|
-
kitConfigs?:
|
|
187
|
+
kitConfigs?: IKitConfigs[];
|
|
180
188
|
kits?: Dictionary<Kit>;
|
|
181
189
|
dataPlanOptions?: KitBlockerOptions;
|
|
182
190
|
flags?: Dictionary;
|
|
@@ -216,12 +224,23 @@ export interface SDKIdentityApi {
|
|
|
216
224
|
|
|
217
225
|
export interface SDKHelpersApi {
|
|
218
226
|
createServiceUrl(arg0: string, arg1: string): void;
|
|
219
|
-
|
|
220
|
-
|
|
227
|
+
createXHR?(cb: () => void): XMLHttpRequest;
|
|
228
|
+
extend?(...args: any[]);
|
|
229
|
+
parseNumber?(value: string | number): number;
|
|
221
230
|
generateUniqueId();
|
|
222
|
-
|
|
231
|
+
getFeatureFlag?(feature: string); // TODO: Feature Constants should be converted to enum
|
|
232
|
+
getRampNumber?(deviceId: string): number;
|
|
233
|
+
isDelayedByIntegration?(
|
|
234
|
+
delayedIntegrations: Dictionary<boolean>,
|
|
235
|
+
timeoutStart: number,
|
|
236
|
+
now: number
|
|
237
|
+
): boolean;
|
|
238
|
+
isObject?(item: any);
|
|
223
239
|
returnConvertedBoolean(data: string | boolean | number): boolean;
|
|
224
|
-
sanitizeAttributes(
|
|
240
|
+
sanitizeAttributes?(
|
|
241
|
+
attrs: Dictionary<string>,
|
|
242
|
+
name: string
|
|
243
|
+
): Dictionary<string> | null;
|
|
225
244
|
Validators: typeof Validators;
|
|
226
245
|
}
|
|
227
246
|
|
|
@@ -247,6 +266,9 @@ export interface SDKConfigApi {
|
|
|
247
266
|
appVersion?: string;
|
|
248
267
|
onCreateBatch(batch: EventsApi.Batch): EventsApi.Batch;
|
|
249
268
|
}
|
|
269
|
+
|
|
270
|
+
// FIXME: Resolve with User in @types/mparticle-web-sdk
|
|
271
|
+
// https://go.mparticle.com/work/SQDSDKS-5033
|
|
250
272
|
export interface MParticleUser {
|
|
251
273
|
getMPID(): string;
|
|
252
274
|
getConsentState(): any; // FIXME:
|
|
@@ -254,25 +276,6 @@ export interface MParticleUser {
|
|
|
254
276
|
getUserIdentities(): IdentityApiData; // FIXME: Is this correct?
|
|
255
277
|
}
|
|
256
278
|
|
|
257
|
-
export interface SDKConsentState {
|
|
258
|
-
getGDPRConsentState(): SDKGDPRConsentState;
|
|
259
|
-
getCCPAConsentState(): SDKCCPAConsentState;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
export interface SDKGDPRConsentState {
|
|
263
|
-
[key: string]: SDKConsentStateData;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
export interface SDKConsentStateData {
|
|
267
|
-
Consented: boolean;
|
|
268
|
-
Timestamp?: number;
|
|
269
|
-
ConsentDocument?: string;
|
|
270
|
-
Location?: string;
|
|
271
|
-
HardwareId?: string;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
export interface SDKCCPAConsentState extends SDKConsentStateData {}
|
|
275
|
-
|
|
276
279
|
export interface SDKUserIdentityChangeData {
|
|
277
280
|
New: Identity;
|
|
278
281
|
Old: Identity;
|