@mparticle/web-sdk 2.32.1 → 2.32.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 +62 -93
- package/dist/mparticle.esm.js +62 -93
- package/dist/mparticle.js +627 -665
- package/package.json +1 -1
- package/src/apiClient.ts +4 -1
- package/src/audienceManager.ts +2 -2
- package/src/batchUploader.ts +28 -22
- package/src/configAPIClient.ts +2 -2
- package/src/constants.ts +8 -0
- package/src/ecommerce.interfaces.ts +201 -0
- package/src/ecommerce.js +9 -0
- package/src/events.interfaces.ts +83 -0
- package/src/events.js +3 -0
- package/src/forwarders.interfaces.ts +0 -3
- package/src/identity-user-interfaces.ts +9 -9
- package/src/identity.js +2 -3
- package/src/identityApiClient.ts +351 -0
- package/src/integrationCapture.ts +7 -5
- package/src/kitFilterHelper.ts +6 -7
- package/src/mp-instance.js +3 -3
- package/src/sdkRuntimeModels.ts +34 -17
- package/src/sdkToEventsApiConverter.ts +1 -1
- package/src/serverModel.ts +1 -1
- package/src/sideloadedKit.ts +12 -11
- package/src/types.ts +404 -0
- package/src/uploaders.ts +4 -4
- package/src/utils.ts +1 -1
- package/src/aliasRequestApiClient.ts +0 -90
- package/src/identityApiClient.interfaces.ts +0 -44
- package/src/identityApiClient.js +0 -131
- package/src/type-utils.ts +0 -66
- package/src/types.interfaces.ts +0 -56
- package/src/types.js +0 -338
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
import Constants, { HTTP_ACCEPTED, HTTP_BAD_REQUEST, HTTP_OK } from './constants';
|
|
2
|
+
import {
|
|
3
|
+
AsyncUploader,
|
|
4
|
+
FetchUploader,
|
|
5
|
+
XHRUploader,
|
|
6
|
+
IFetchPayload,
|
|
7
|
+
} from './uploaders';
|
|
8
|
+
import { CACHE_HEADER } from './identity-utils';
|
|
9
|
+
import { parseNumber, valueof } from './utils';
|
|
10
|
+
import {
|
|
11
|
+
IAliasCallback,
|
|
12
|
+
IAliasRequest,
|
|
13
|
+
IdentityAPIMethod,
|
|
14
|
+
IIdentity,
|
|
15
|
+
IIdentityAPIRequestData,
|
|
16
|
+
} from './identity.interfaces';
|
|
17
|
+
import {
|
|
18
|
+
IdentityApiData,
|
|
19
|
+
MPID,
|
|
20
|
+
UserIdentities,
|
|
21
|
+
} from '@mparticle/web-sdk';
|
|
22
|
+
import {
|
|
23
|
+
IdentityCallback,
|
|
24
|
+
IdentityResultBody,
|
|
25
|
+
IIdentityResponse,
|
|
26
|
+
} from './identity-user-interfaces';
|
|
27
|
+
import { MParticleWebSDK } from './sdkRuntimeModels';
|
|
28
|
+
|
|
29
|
+
const { HTTPCodes, Messages, IdentityMethods } = Constants;
|
|
30
|
+
|
|
31
|
+
const { Modify } = IdentityMethods;
|
|
32
|
+
|
|
33
|
+
export interface IIdentityApiClient {
|
|
34
|
+
sendAliasRequest: (
|
|
35
|
+
aliasRequest: IAliasRequest,
|
|
36
|
+
aliasCallback: IAliasCallback
|
|
37
|
+
) => Promise<void>;
|
|
38
|
+
sendIdentityRequest: (
|
|
39
|
+
identityApiRequest: IIdentityAPIRequestData,
|
|
40
|
+
method: IdentityAPIMethod,
|
|
41
|
+
callback: IdentityCallback,
|
|
42
|
+
originalIdentityApiData: IdentityApiData,
|
|
43
|
+
parseIdentityResponse: IIdentity['parseIdentityResponse'],
|
|
44
|
+
mpid: MPID,
|
|
45
|
+
knownIdentities: UserIdentities
|
|
46
|
+
) => Promise<void>;
|
|
47
|
+
getUploadUrl: (method: IdentityAPIMethod, mpid: MPID) => string;
|
|
48
|
+
getIdentityResponseFromFetch: (
|
|
49
|
+
response: Response,
|
|
50
|
+
responseBody: IdentityResultBody
|
|
51
|
+
) => IIdentityResponse;
|
|
52
|
+
getIdentityResponseFromXHR: (response: XMLHttpRequest) => IIdentityResponse;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// A successfull Alias request will return a 202 with no body
|
|
56
|
+
export interface IAliasResponseBody {}
|
|
57
|
+
|
|
58
|
+
interface IdentityApiRequestPayload extends IFetchPayload {
|
|
59
|
+
headers: {
|
|
60
|
+
Accept: string;
|
|
61
|
+
'Content-Type': string;
|
|
62
|
+
'x-mp-key': string;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
type HTTP_STATUS_CODES = typeof HTTP_OK | typeof HTTP_ACCEPTED;
|
|
67
|
+
|
|
68
|
+
interface IdentityApiError {
|
|
69
|
+
code: string;
|
|
70
|
+
message: string;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
interface IdentityApiErrorResponse {
|
|
74
|
+
Errors: IdentityApiError[],
|
|
75
|
+
ErrorCode: string,
|
|
76
|
+
StatusCode: valueof<HTTP_STATUS_CODES>;
|
|
77
|
+
RequestId: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// All Identity Api Responses have the same structure, except for Alias
|
|
81
|
+
interface IAliasErrorResponse extends IdentityApiError {}
|
|
82
|
+
|
|
83
|
+
export default function IdentityAPIClient(
|
|
84
|
+
this: IIdentityApiClient,
|
|
85
|
+
mpInstance: MParticleWebSDK
|
|
86
|
+
) {
|
|
87
|
+
this.sendAliasRequest = async function(
|
|
88
|
+
aliasRequest: IAliasRequest,
|
|
89
|
+
aliasCallback: IAliasCallback
|
|
90
|
+
) {
|
|
91
|
+
const { verbose, error } = mpInstance.Logger;
|
|
92
|
+
const { invokeAliasCallback } = mpInstance._Helpers;
|
|
93
|
+
const { aliasUrl } = mpInstance._Store.SDKConfig;
|
|
94
|
+
const { devToken: apiKey } = mpInstance._Store;
|
|
95
|
+
|
|
96
|
+
verbose(Messages.InformationMessages.SendAliasHttp);
|
|
97
|
+
|
|
98
|
+
// https://go.mparticle.com/work/SQDSDKS-6750
|
|
99
|
+
const uploadUrl = `https://${aliasUrl}${apiKey}/Alias`;
|
|
100
|
+
const uploader: AsyncUploader = window.fetch
|
|
101
|
+
? new FetchUploader(uploadUrl)
|
|
102
|
+
: new XHRUploader(uploadUrl);
|
|
103
|
+
|
|
104
|
+
// https://go.mparticle.com/work/SQDSDKS-6568
|
|
105
|
+
const uploadPayload: IFetchPayload = {
|
|
106
|
+
method: 'post',
|
|
107
|
+
headers: {
|
|
108
|
+
Accept: 'text/plain;charset=UTF-8',
|
|
109
|
+
'Content-Type': 'application/json',
|
|
110
|
+
},
|
|
111
|
+
body: JSON.stringify(aliasRequest),
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
try {
|
|
115
|
+
const response: Response = await uploader.upload(uploadPayload);
|
|
116
|
+
|
|
117
|
+
let aliasResponseBody: IAliasResponseBody;
|
|
118
|
+
let message: string;
|
|
119
|
+
let errorMessage: string;
|
|
120
|
+
|
|
121
|
+
switch (response.status) {
|
|
122
|
+
// A successfull Alias request will return without a body
|
|
123
|
+
case HTTP_ACCEPTED:
|
|
124
|
+
case HTTP_OK:
|
|
125
|
+
// https://go.mparticle.com/work/SQDSDKS-6670
|
|
126
|
+
message = 'Received Alias Response from server: ' + JSON.stringify(response.status);
|
|
127
|
+
break;
|
|
128
|
+
|
|
129
|
+
// Our Alias Request API will 400 if there is an issue with the request body (ie timestamps are too far
|
|
130
|
+
// in the past or MPIDs don't exist).
|
|
131
|
+
// A 400 will return an error in the response body and will go through the happy path to report the error
|
|
132
|
+
case HTTP_BAD_REQUEST:
|
|
133
|
+
// response.json will always exist on a fetch, but can only be await-ed when the
|
|
134
|
+
// response is not empty, otherwise it will throw an error.
|
|
135
|
+
if (response.json) {
|
|
136
|
+
try {
|
|
137
|
+
aliasResponseBody = await response.json();
|
|
138
|
+
} catch (e) {
|
|
139
|
+
verbose('The request has no response body');
|
|
140
|
+
}
|
|
141
|
+
} else {
|
|
142
|
+
// https://go.mparticle.com/work/SQDSDKS-6568
|
|
143
|
+
// XHRUploader returns the response as a string that we need to parse
|
|
144
|
+
const xhrResponse = (response as unknown) as XMLHttpRequest;
|
|
145
|
+
|
|
146
|
+
aliasResponseBody = xhrResponse.responseText
|
|
147
|
+
? JSON.parse(xhrResponse.responseText)
|
|
148
|
+
: '';
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const errorResponse: IAliasErrorResponse = aliasResponseBody as unknown as IAliasErrorResponse;
|
|
152
|
+
|
|
153
|
+
if (errorResponse?.message) {
|
|
154
|
+
errorMessage = errorResponse.message;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
message =
|
|
158
|
+
'Issue with sending Alias Request to mParticle Servers, received HTTP Code of ' +
|
|
159
|
+
response.status;
|
|
160
|
+
|
|
161
|
+
if (errorResponse?.code) {
|
|
162
|
+
message += ' - ' + errorResponse.code;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
break;
|
|
166
|
+
|
|
167
|
+
// Any unhandled errors, such as 500 or 429, will be caught here as well
|
|
168
|
+
default: {
|
|
169
|
+
throw new Error('Received HTTP Code of ' + response.status);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
verbose(message);
|
|
175
|
+
invokeAliasCallback(aliasCallback, response.status, errorMessage);
|
|
176
|
+
} catch (e) {
|
|
177
|
+
const errorMessage = (e as Error).message || e.toString();
|
|
178
|
+
error('Error sending alias request to mParticle servers. ' + errorMessage);
|
|
179
|
+
invokeAliasCallback(
|
|
180
|
+
aliasCallback,
|
|
181
|
+
HTTPCodes.noHttpCoverage,
|
|
182
|
+
errorMessage,
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
this.sendIdentityRequest = async function(
|
|
188
|
+
identityApiRequest: IIdentityAPIRequestData,
|
|
189
|
+
method: IdentityAPIMethod,
|
|
190
|
+
callback: IdentityCallback,
|
|
191
|
+
originalIdentityApiData: IdentityApiData,
|
|
192
|
+
parseIdentityResponse: IIdentity['parseIdentityResponse'],
|
|
193
|
+
mpid: MPID,
|
|
194
|
+
knownIdentities: UserIdentities
|
|
195
|
+
) {
|
|
196
|
+
const { verbose, error } = mpInstance.Logger;
|
|
197
|
+
const { invokeCallback } = mpInstance._Helpers;
|
|
198
|
+
|
|
199
|
+
verbose(Messages.InformationMessages.SendIdentityBegin);
|
|
200
|
+
if (!identityApiRequest) {
|
|
201
|
+
error(Messages.ErrorMessages.APIRequestEmpty);
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
verbose(Messages.InformationMessages.SendIdentityHttp);
|
|
205
|
+
|
|
206
|
+
if (mpInstance._Store.identityCallInFlight) {
|
|
207
|
+
invokeCallback(
|
|
208
|
+
callback,
|
|
209
|
+
HTTPCodes.activeIdentityRequest,
|
|
210
|
+
'There is currently an Identity request processing. Please wait for this to return before requesting again'
|
|
211
|
+
);
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const previousMPID = mpid || null;
|
|
216
|
+
const uploadUrl = this.getUploadUrl(method, mpid);
|
|
217
|
+
|
|
218
|
+
const uploader: AsyncUploader = window.fetch
|
|
219
|
+
? new FetchUploader(uploadUrl)
|
|
220
|
+
: new XHRUploader(uploadUrl);
|
|
221
|
+
|
|
222
|
+
// https://go.mparticle.com/work/SQDSDKS-6568
|
|
223
|
+
const fetchPayload: IdentityApiRequestPayload = {
|
|
224
|
+
method: 'post',
|
|
225
|
+
headers: {
|
|
226
|
+
Accept: 'text/plain;charset=UTF-8',
|
|
227
|
+
'Content-Type': 'application/json',
|
|
228
|
+
'x-mp-key': mpInstance._Store.devToken,
|
|
229
|
+
},
|
|
230
|
+
body: JSON.stringify(identityApiRequest),
|
|
231
|
+
};
|
|
232
|
+
mpInstance._Store.identityCallInFlight = true;
|
|
233
|
+
|
|
234
|
+
try {
|
|
235
|
+
const response: Response = await uploader.upload(fetchPayload);
|
|
236
|
+
|
|
237
|
+
let identityResponse: IIdentityResponse;
|
|
238
|
+
let message: string;
|
|
239
|
+
|
|
240
|
+
switch (response.status) {
|
|
241
|
+
case HTTP_ACCEPTED:
|
|
242
|
+
case HTTP_OK:
|
|
243
|
+
|
|
244
|
+
// Our Identity API will return a 400 error if there is an issue with the requeest body
|
|
245
|
+
// such as if the body is empty or one of the attributes is missing or malformed
|
|
246
|
+
// A 400 will return an error in the response body and will go through the happy path to report the error
|
|
247
|
+
case HTTP_BAD_REQUEST:
|
|
248
|
+
|
|
249
|
+
// FetchUploader returns the response as a JSON object that we have to await
|
|
250
|
+
if (response.json) {
|
|
251
|
+
// https://go.mparticle.com/work/SQDSDKS-6568
|
|
252
|
+
// FetchUploader returns the response as a JSON object that we have to await
|
|
253
|
+
const responseBody: IdentityResultBody = await response.json();
|
|
254
|
+
|
|
255
|
+
identityResponse = this.getIdentityResponseFromFetch(
|
|
256
|
+
response,
|
|
257
|
+
responseBody
|
|
258
|
+
);
|
|
259
|
+
} else {
|
|
260
|
+
identityResponse = this.getIdentityResponseFromXHR(
|
|
261
|
+
(response as unknown) as XMLHttpRequest
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (identityResponse.status === HTTP_BAD_REQUEST) {
|
|
266
|
+
const errorResponse: IdentityApiErrorResponse = identityResponse.responseText as unknown as IdentityApiErrorResponse;
|
|
267
|
+
message = 'Issue with sending Identity Request to mParticle Servers, received HTTP Code of ' + identityResponse.status;
|
|
268
|
+
|
|
269
|
+
if (errorResponse?.Errors) {
|
|
270
|
+
const errorMessage = errorResponse.Errors.map((error) => error.message).join(', ');
|
|
271
|
+
message += ' - ' + errorMessage;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
} else {
|
|
275
|
+
message = 'Received Identity Response from server: ';
|
|
276
|
+
message += JSON.stringify(identityResponse.responseText);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
break;
|
|
280
|
+
|
|
281
|
+
// Our Identity API will return:
|
|
282
|
+
// - 401 if the `x-mp-key` is incorrect or missing
|
|
283
|
+
// - 403 if the there is a permission or account issue related to the `x-mp-key`
|
|
284
|
+
// 401 and 403 have no response bodies and should be rejected outright
|
|
285
|
+
default: {
|
|
286
|
+
throw new Error('Received HTTP Code of ' + response.status);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
mpInstance._Store.identityCallInFlight = false;
|
|
291
|
+
|
|
292
|
+
verbose(message);
|
|
293
|
+
parseIdentityResponse(
|
|
294
|
+
identityResponse,
|
|
295
|
+
previousMPID,
|
|
296
|
+
callback,
|
|
297
|
+
originalIdentityApiData,
|
|
298
|
+
method,
|
|
299
|
+
knownIdentities,
|
|
300
|
+
false
|
|
301
|
+
);
|
|
302
|
+
} catch (err) {
|
|
303
|
+
mpInstance._Store.identityCallInFlight = false;
|
|
304
|
+
|
|
305
|
+
const errorMessage = (err as Error).message || err.toString();
|
|
306
|
+
|
|
307
|
+
error('Error sending identity request to servers' + ' - ' + errorMessage);
|
|
308
|
+
invokeCallback(
|
|
309
|
+
callback,
|
|
310
|
+
HTTPCodes.noHttpCoverage,
|
|
311
|
+
errorMessage,
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
this.getUploadUrl = (method: IdentityAPIMethod, mpid: MPID) => {
|
|
317
|
+
const uploadServiceUrl: string = mpInstance._Helpers.createServiceUrl(
|
|
318
|
+
mpInstance._Store.SDKConfig.identityUrl
|
|
319
|
+
);
|
|
320
|
+
|
|
321
|
+
const uploadUrl: string =
|
|
322
|
+
method === Modify
|
|
323
|
+
? uploadServiceUrl + mpid + '/' + method
|
|
324
|
+
: uploadServiceUrl + method;
|
|
325
|
+
|
|
326
|
+
return uploadUrl;
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
this.getIdentityResponseFromFetch = (
|
|
330
|
+
response: Response,
|
|
331
|
+
responseBody: IdentityResultBody
|
|
332
|
+
): IIdentityResponse => ({
|
|
333
|
+
status: response.status,
|
|
334
|
+
responseText: responseBody,
|
|
335
|
+
cacheMaxAge: parseInt(response.headers.get(CACHE_HEADER)) || 0,
|
|
336
|
+
expireTimestamp: 0,
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
this.getIdentityResponseFromXHR = (
|
|
340
|
+
response: XMLHttpRequest
|
|
341
|
+
): IIdentityResponse => ({
|
|
342
|
+
status: response.status,
|
|
343
|
+
responseText: response.responseText
|
|
344
|
+
? JSON.parse(response.responseText)
|
|
345
|
+
: {},
|
|
346
|
+
cacheMaxAge: parseNumber(
|
|
347
|
+
response.getResponseHeader(CACHE_HEADER) || ''
|
|
348
|
+
),
|
|
349
|
+
expireTimestamp: 0,
|
|
350
|
+
});
|
|
351
|
+
}
|
|
@@ -222,10 +222,12 @@ export default class IntegrationCapture {
|
|
|
222
222
|
private filterMappings(
|
|
223
223
|
outputType: valueof<typeof IntegrationOutputs>
|
|
224
224
|
): IntegrationIdMapping {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
225
|
+
const filteredMappings: IntegrationIdMapping = {};
|
|
226
|
+
for (const key in integrationMapping) {
|
|
227
|
+
if (integrationMapping[key].output === outputType) {
|
|
228
|
+
filteredMappings[key] = integrationMapping[key];
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return filteredMappings;
|
|
230
232
|
}
|
|
231
233
|
}
|
package/src/kitFilterHelper.ts
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
import { generateHash } from "./utils";
|
|
1
|
+
import { generateHash, valueof } from "./utils";
|
|
2
2
|
// TODO: https://mparticle-eng.atlassian.net/browse/SQDSDKS-5381
|
|
3
|
-
import {
|
|
4
|
-
import Constants from './constants';
|
|
3
|
+
import { EventType, IdentityType } from "./types";
|
|
5
4
|
|
|
6
5
|
export default class KitFilterHelper {
|
|
7
|
-
static hashEventType(eventType:
|
|
6
|
+
static hashEventType(eventType: valueof<typeof EventType>): number {
|
|
8
7
|
return generateHash(eventType as unknown as string);
|
|
9
8
|
};
|
|
10
9
|
|
|
11
|
-
static hashEventName(eventName: string, eventType:
|
|
10
|
+
static hashEventName(eventName: string, eventType: valueof<typeof EventType>): number {
|
|
12
11
|
return generateHash(eventType + eventName);
|
|
13
12
|
};
|
|
14
13
|
|
|
15
|
-
static hashEventAttributeKey(eventType:
|
|
14
|
+
static hashEventAttributeKey(eventType: valueof<typeof EventType>, eventName: string, customAttributeName: string): number {
|
|
16
15
|
return generateHash(eventType + eventName + customAttributeName);
|
|
17
16
|
}
|
|
18
17
|
|
|
@@ -22,7 +21,7 @@ export default class KitFilterHelper {
|
|
|
22
21
|
|
|
23
22
|
// User Identities are not actually hashed, this method is named this way to
|
|
24
23
|
// be consistent with the filter class. UserIdentityType is also a number
|
|
25
|
-
static hashUserIdentity(userIdentity: IdentityType): IdentityType {
|
|
24
|
+
static hashUserIdentity(userIdentity: typeof IdentityType): typeof IdentityType {
|
|
26
25
|
return userIdentity;
|
|
27
26
|
}
|
|
28
27
|
|
package/src/mp-instance.js
CHANGED
|
@@ -212,8 +212,8 @@ export default function mParticleInstance(instanceName) {
|
|
|
212
212
|
*/
|
|
213
213
|
this.getEnvironment = function() {
|
|
214
214
|
return self._Store.SDKConfig.isDevelopmentMode
|
|
215
|
-
?
|
|
216
|
-
:
|
|
215
|
+
? Constants.Environment.Development
|
|
216
|
+
: Constants.Environment.Production;
|
|
217
217
|
};
|
|
218
218
|
/**
|
|
219
219
|
* Returns the mParticle SDK version number
|
|
@@ -824,7 +824,7 @@ export default function mParticleInstance(instanceName) {
|
|
|
824
824
|
* @for mParticle.eCommerce
|
|
825
825
|
* @method logCheckout
|
|
826
826
|
* @param {Number} step checkout step number
|
|
827
|
-
* @param {String} option
|
|
827
|
+
* @param {String} checkout option string
|
|
828
828
|
* @param {Object} attrs
|
|
829
829
|
* @param {Object} [customFlags] Custom flags for the event
|
|
830
830
|
* @deprecated
|
package/src/sdkRuntimeModels.ts
CHANGED
|
@@ -3,12 +3,13 @@ import { DataPlanVersion } from '@mparticle/data-planning-models';
|
|
|
3
3
|
import {
|
|
4
4
|
MPConfiguration,
|
|
5
5
|
MPID,
|
|
6
|
-
Callback,
|
|
7
6
|
IdentityApiData,
|
|
7
|
+
SDKEventOptions,
|
|
8
|
+
SDKEventAttrs,
|
|
8
9
|
} from '@mparticle/web-sdk';
|
|
9
10
|
import { IStore } from './store';
|
|
10
11
|
import Validators from './validators';
|
|
11
|
-
import { Dictionary } from './utils';
|
|
12
|
+
import { Dictionary, valueof } from './utils';
|
|
12
13
|
import { IServerModel } from './serverModel';
|
|
13
14
|
import { IKitConfigs } from './configAPIClient';
|
|
14
15
|
import { SDKConsentApi, SDKConsentState } from './consent';
|
|
@@ -29,10 +30,17 @@ import {
|
|
|
29
30
|
IdentityCallback,
|
|
30
31
|
ISDKUserAttributes,
|
|
31
32
|
} from './identity-user-interfaces';
|
|
32
|
-
import {
|
|
33
|
+
import {
|
|
34
|
+
CommerceEventType,
|
|
35
|
+
EventType,
|
|
36
|
+
IdentityType,
|
|
37
|
+
PromotionActionType,
|
|
38
|
+
} from './types';
|
|
33
39
|
import IntegrationCapture from './integrationCapture';
|
|
34
40
|
import { INativeSdkHelpers } from './nativeSdkHelpers.interfaces';
|
|
35
41
|
import { ICookieSyncManager, IPixelConfiguration } from './cookieSyncManager';
|
|
42
|
+
import { IEvents } from './events.interfaces';
|
|
43
|
+
import { IECommerce, SDKECommerceAPI } from './ecommerce.interfaces';
|
|
36
44
|
|
|
37
45
|
// TODO: Resolve this with version in @mparticle/web-sdk
|
|
38
46
|
export type SDKEventCustomFlags = Dictionary<any>;
|
|
@@ -100,6 +108,11 @@ export interface SDKPromotion {
|
|
|
100
108
|
Position?: string;
|
|
101
109
|
}
|
|
102
110
|
|
|
111
|
+
export interface SDKImpression {
|
|
112
|
+
Name: string;
|
|
113
|
+
Product: SDKProduct;
|
|
114
|
+
}
|
|
115
|
+
|
|
103
116
|
export interface SDKProductImpression {
|
|
104
117
|
ProductImpressionList?: string;
|
|
105
118
|
ProductList?: SDKProduct[];
|
|
@@ -143,18 +156,18 @@ export interface SDKProduct {
|
|
|
143
156
|
Position?: number;
|
|
144
157
|
CouponCode?: string;
|
|
145
158
|
TotalAmount?: number;
|
|
146
|
-
Attributes?: { [key: string]: string };
|
|
147
|
-
}
|
|
148
159
|
|
|
149
|
-
//
|
|
150
|
-
|
|
151
|
-
logEvent?(event: BaseEvent): void;
|
|
160
|
+
// https://go.mparticle.com/work/SQDSDKS-4801
|
|
161
|
+
Attributes?: Record<string, unknown> | null;
|
|
152
162
|
}
|
|
153
163
|
|
|
154
164
|
export interface MParticleWebSDK {
|
|
155
165
|
addForwarder(mockForwarder: MPForwarder): void;
|
|
156
166
|
_IntegrationCapture: IntegrationCapture;
|
|
157
|
-
IdentityType:
|
|
167
|
+
IdentityType: valueof<typeof IdentityType>;
|
|
168
|
+
CommerceEventType: valueof<typeof CommerceEventType>;
|
|
169
|
+
EventType: valueof<typeof EventType>;
|
|
170
|
+
PromotionType: valueof<typeof PromotionActionType>;
|
|
158
171
|
_Identity: IIdentity;
|
|
159
172
|
Identity: SDKIdentityApi;
|
|
160
173
|
Logger: SDKLoggerApi;
|
|
@@ -165,6 +178,7 @@ export interface MParticleWebSDK {
|
|
|
165
178
|
_Forwarders: any;
|
|
166
179
|
_Helpers: SDKHelpersApi;
|
|
167
180
|
_Events: IEvents;
|
|
181
|
+
_Ecommerce: IECommerce;
|
|
168
182
|
config: SDKInitConfig;
|
|
169
183
|
_ServerModel: IServerModel;
|
|
170
184
|
_SessionManager: ISessionManager;
|
|
@@ -189,7 +203,7 @@ export interface MParticleWebSDK {
|
|
|
189
203
|
getDeviceId(): string;
|
|
190
204
|
setDeviceId(deviceId: string): void;
|
|
191
205
|
setSessionAttribute(key: string, value: string): void;
|
|
192
|
-
getInstance(): MParticleWebSDK; //
|
|
206
|
+
getInstance(instanceName?: string): MParticleWebSDK; // https://go.mparticle.com/work/SQDSDKS-4804
|
|
193
207
|
ServerModel();
|
|
194
208
|
upload();
|
|
195
209
|
setLogLevel(logLevel: LogLevelType): void;
|
|
@@ -197,16 +211,18 @@ export interface MParticleWebSDK {
|
|
|
197
211
|
startNewSession(): void;
|
|
198
212
|
logEvent(
|
|
199
213
|
eventName: string,
|
|
200
|
-
eventType?:
|
|
201
|
-
attrs?:
|
|
202
|
-
customFlags?: SDKEventCustomFlags
|
|
214
|
+
eventType?: valueof<typeof EventType>,
|
|
215
|
+
attrs?: SDKEventAttrs,
|
|
216
|
+
customFlags?: SDKEventCustomFlags,
|
|
217
|
+
eventOptions?: SDKEventOptions
|
|
203
218
|
): void;
|
|
204
|
-
logBaseEvent(event:
|
|
205
|
-
eCommerce:
|
|
219
|
+
logBaseEvent(event: BaseEvent, eventOptions?: SDKEventOptions): void;
|
|
220
|
+
eCommerce: SDKECommerceAPI;
|
|
206
221
|
logLevel: string;
|
|
207
222
|
ProductActionType: SDKProductActionType;
|
|
208
223
|
generateHash(value: string): string;
|
|
209
224
|
isIOS?: boolean;
|
|
225
|
+
sessionManager: Pick<ISessionManager, 'getSession'>; // https://go.mparticle.com/work/SQDSDKS-6949
|
|
210
226
|
}
|
|
211
227
|
|
|
212
228
|
// Used in cases where server requires booleans as strings
|
|
@@ -285,10 +301,11 @@ export interface SDKHelpersApi {
|
|
|
285
301
|
timeoutStart: number,
|
|
286
302
|
now: number
|
|
287
303
|
): boolean;
|
|
304
|
+
isEventType?(type: valueof<typeof EventType>): boolean;
|
|
288
305
|
isObject?(item: any);
|
|
289
306
|
invokeCallback?(
|
|
290
|
-
callback:
|
|
291
|
-
code:
|
|
307
|
+
callback: IdentityCallback,
|
|
308
|
+
code: number,
|
|
292
309
|
body: string,
|
|
293
310
|
mParticleUser?: IMParticleUser,
|
|
294
311
|
previousMpid?: MPID
|
|
@@ -373,7 +373,7 @@ export function convertProducts(
|
|
|
373
373
|
price: sdkProduct.Price,
|
|
374
374
|
quantity: sdkProduct.Quantity,
|
|
375
375
|
coupon_code: sdkProduct.CouponCode,
|
|
376
|
-
custom_attributes: sdkProduct.Attributes,
|
|
376
|
+
custom_attributes: sdkProduct.Attributes as Record<string, string>,
|
|
377
377
|
};
|
|
378
378
|
products.push(product);
|
|
379
379
|
}
|
package/src/serverModel.ts
CHANGED
package/src/sideloadedKit.ts
CHANGED
|
@@ -6,22 +6,23 @@ import {
|
|
|
6
6
|
IKitFilterSettings,
|
|
7
7
|
} from './configAPIClient';
|
|
8
8
|
import { UnregisteredKit } from './forwarders.interfaces';
|
|
9
|
-
import {
|
|
9
|
+
import { EventType, IdentityType } from './types';
|
|
10
|
+
import { valueof } from './utils';
|
|
10
11
|
|
|
11
12
|
export interface IMPSideloadedKit {
|
|
12
13
|
kitInstance: UnregisteredKit;
|
|
13
14
|
filterDictionary: IKitFilterSettings;
|
|
14
15
|
|
|
15
|
-
addEventTypeFilter(eventType:
|
|
16
|
-
addEventNameFilter(eventType:
|
|
16
|
+
addEventTypeFilter(eventType: valueof<typeof EventType>): void;
|
|
17
|
+
addEventNameFilter(eventType: valueof<typeof EventType>, eventName: string): void;
|
|
17
18
|
addEventAttributeFilter(
|
|
18
|
-
eventType:
|
|
19
|
+
eventType: valueof<typeof EventType>,
|
|
19
20
|
eventName: string,
|
|
20
21
|
customAttributeKey: string
|
|
21
22
|
): void;
|
|
22
23
|
addScreenNameFilter(screenName: string): void;
|
|
23
24
|
addScreenAttributeFilter(screenName: string, screenAttribute: string): void;
|
|
24
|
-
addUserIdentityFilter(userIdentity: IdentityType): void;
|
|
25
|
+
addUserIdentityFilter(userIdentity: typeof IdentityType): void;
|
|
25
26
|
addUserAttributeFilter(userAttributeKey: string): void;
|
|
26
27
|
}
|
|
27
28
|
|
|
@@ -57,13 +58,13 @@ export default class MPSideloadedKit implements IMPSideloadedKit{
|
|
|
57
58
|
this.kitInstance = unregisteredKitInstance;
|
|
58
59
|
}
|
|
59
60
|
|
|
60
|
-
public addEventTypeFilter(eventType:
|
|
61
|
+
public addEventTypeFilter(eventType: valueof<typeof EventType>): void {
|
|
61
62
|
const hashedEventType = KitFilterHelper.hashEventType(eventType);
|
|
62
63
|
this.filterDictionary.eventTypeFilters.push(hashedEventType);
|
|
63
64
|
}
|
|
64
65
|
|
|
65
66
|
public addEventNameFilter(
|
|
66
|
-
eventType:
|
|
67
|
+
eventType: valueof<typeof EventType>,
|
|
67
68
|
eventName: string
|
|
68
69
|
): void {
|
|
69
70
|
const hashedEventName = KitFilterHelper.hashEventName(
|
|
@@ -74,7 +75,7 @@ export default class MPSideloadedKit implements IMPSideloadedKit{
|
|
|
74
75
|
}
|
|
75
76
|
|
|
76
77
|
public addEventAttributeFilter(
|
|
77
|
-
eventType:
|
|
78
|
+
eventType: valueof<typeof EventType>,
|
|
78
79
|
eventName: string,
|
|
79
80
|
customAttributeKey: string
|
|
80
81
|
): void {
|
|
@@ -89,7 +90,7 @@ export default class MPSideloadedKit implements IMPSideloadedKit{
|
|
|
89
90
|
public addScreenNameFilter(screenName: string): void {
|
|
90
91
|
const hashedScreenName = KitFilterHelper.hashEventName(
|
|
91
92
|
screenName,
|
|
92
|
-
|
|
93
|
+
EventType.Unknown,
|
|
93
94
|
);
|
|
94
95
|
this.filterDictionary.screenNameFilters.push(hashedScreenName);
|
|
95
96
|
}
|
|
@@ -99,7 +100,7 @@ export default class MPSideloadedKit implements IMPSideloadedKit{
|
|
|
99
100
|
screenAttribute: string
|
|
100
101
|
): void {
|
|
101
102
|
const hashedScreenAttribute = KitFilterHelper.hashEventAttributeKey(
|
|
102
|
-
|
|
103
|
+
EventType.Unknown,
|
|
103
104
|
screenName,
|
|
104
105
|
screenAttribute
|
|
105
106
|
);
|
|
@@ -108,7 +109,7 @@ export default class MPSideloadedKit implements IMPSideloadedKit{
|
|
|
108
109
|
);
|
|
109
110
|
}
|
|
110
111
|
|
|
111
|
-
public addUserIdentityFilter(userIdentity: IdentityType): void {
|
|
112
|
+
public addUserIdentityFilter(userIdentity: typeof IdentityType): void {
|
|
112
113
|
const hashedIdentityType = KitFilterHelper.hashUserIdentity(
|
|
113
114
|
userIdentity
|
|
114
115
|
);
|