@mparticle/web-sdk 2.32.2 → 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/src/types.ts ADDED
@@ -0,0 +1,404 @@
1
+ import Constants from './constants';
2
+ import { isNumber, parseNumber, valueof } from './utils';
3
+
4
+ interface IdentitiesByType {
5
+ [key: number]: string;
6
+ }
7
+
8
+ export const MessageType = {
9
+ SessionStart: 1 as const,
10
+ SessionEnd: 2 as const,
11
+ PageView: 3 as const,
12
+ PageEvent: 4 as const,
13
+ CrashReport: 5 as const,
14
+ OptOut: 6 as const,
15
+ AppStateTransition: 10 as const,
16
+ Profile: 14 as const,
17
+ Commerce: 16 as const,
18
+ Media: 20 as const,
19
+ UserAttributeChange: 17 as const,
20
+ UserIdentityChange: 18 as const,
21
+ };
22
+
23
+ export const EventType = {
24
+ Unknown: 0 as const,
25
+ Navigation: 1 as const,
26
+ Location: 2 as const,
27
+ Search: 3 as const,
28
+ Transaction: 4 as const,
29
+ UserContent: 5 as const,
30
+ UserPreference: 6 as const,
31
+ Social: 7 as const,
32
+ Other: 8 as const,
33
+ Media: 9 as const,
34
+
35
+ getName(id: number): string {
36
+ switch (id) {
37
+ case EventType.Unknown:
38
+ return 'Unknown';
39
+ case EventType.Navigation:
40
+ return 'Navigation';
41
+ case EventType.Location:
42
+ return 'Location';
43
+ case EventType.Search:
44
+ return 'Search';
45
+ case EventType.Transaction:
46
+ return 'Transaction';
47
+ case EventType.UserContent:
48
+ return 'User Content';
49
+ case EventType.UserPreference:
50
+ return 'User Preference';
51
+ case EventType.Social:
52
+ return 'Social';
53
+ case CommerceEventType.ProductAddToCart:
54
+ return 'Product Added to Cart';
55
+ case CommerceEventType.ProductAddToWishlist:
56
+ return 'Product Added to Wishlist';
57
+ case CommerceEventType.ProductCheckout:
58
+ return 'Product Checkout';
59
+ case CommerceEventType.ProductCheckoutOption:
60
+ return 'Product Checkout Options';
61
+ case CommerceEventType.ProductClick:
62
+ return 'Product Click';
63
+ case CommerceEventType.ProductImpression:
64
+ return 'Product Impression';
65
+ case CommerceEventType.ProductPurchase:
66
+ return 'Product Purchased';
67
+ case CommerceEventType.ProductRefund:
68
+ return 'Product Refunded';
69
+ case CommerceEventType.ProductRemoveFromCart:
70
+ return 'Product Removed From Cart';
71
+ case CommerceEventType.ProductRemoveFromWishlist:
72
+ return 'Product Removed from Wishlist';
73
+ case CommerceEventType.ProductViewDetail:
74
+ return 'Product View Details';
75
+ case CommerceEventType.PromotionClick:
76
+ return 'Promotion Click';
77
+ case CommerceEventType.PromotionView:
78
+ return 'Promotion View';
79
+ default:
80
+ return 'Other';
81
+ }
82
+ },
83
+ };
84
+
85
+ // Continuation of EventType enum above, but in seperate object since we don't expose these to end user
86
+ export const CommerceEventType = {
87
+ ProductAddToCart: 10 as const,
88
+ ProductRemoveFromCart: 11 as const,
89
+ ProductCheckout: 12 as const,
90
+ ProductCheckoutOption: 13 as const,
91
+ ProductClick: 14 as const,
92
+ ProductViewDetail: 15 as const,
93
+ ProductPurchase: 16 as const,
94
+ ProductRefund: 17 as const,
95
+ PromotionView: 18 as const,
96
+ PromotionClick: 19 as const,
97
+ ProductAddToWishlist: 20 as const,
98
+ ProductRemoveFromWishlist: 21 as const,
99
+ ProductImpression: 22 as const,
100
+ };
101
+
102
+ export const IdentityType = {
103
+ Other: 0 as const,
104
+ CustomerId: 1 as const,
105
+ Facebook: 2 as const,
106
+ Twitter: 3 as const,
107
+ Google: 4 as const,
108
+ Microsoft: 5 as const,
109
+ Yahoo: 6 as const,
110
+ Email: 7 as const,
111
+ FacebookCustomAudienceId: 9 as const,
112
+ Other2: 10 as const,
113
+ Other3: 11 as const,
114
+ Other4: 12 as const,
115
+ Other5: 13 as const,
116
+ Other6: 14 as const,
117
+ Other7: 15 as const,
118
+ Other8: 16 as const,
119
+ Other9: 17 as const,
120
+ Other10: 18 as const,
121
+ MobileNumber: 19 as const,
122
+ PhoneNumber2: 20 as const,
123
+ PhoneNumber3: 21 as const,
124
+
125
+ isValid(identityType: number): boolean {
126
+ if (typeof identityType === 'number') {
127
+ for (const prop in IdentityType) {
128
+ if (IdentityType.hasOwnProperty(prop)) {
129
+ if (IdentityType[prop] === identityType) {
130
+ return true;
131
+ }
132
+ }
133
+ }
134
+ }
135
+
136
+ return false;
137
+ },
138
+
139
+ getName: (identityType: number): string => {
140
+ switch (identityType) {
141
+ case window.mParticle.IdentityType.CustomerId:
142
+ return 'Customer ID';
143
+ case window.mParticle.IdentityType.Facebook:
144
+ return 'Facebook ID';
145
+ case window.mParticle.IdentityType.Twitter:
146
+ return 'Twitter ID';
147
+ case window.mParticle.IdentityType.Google:
148
+ return 'Google ID';
149
+ case window.mParticle.IdentityType.Microsoft:
150
+ return 'Microsoft ID';
151
+ case window.mParticle.IdentityType.Yahoo:
152
+ return 'Yahoo ID';
153
+ case window.mParticle.IdentityType.Email:
154
+ return 'Email';
155
+ case window.mParticle.IdentityType.FacebookCustomAudienceId:
156
+ return 'Facebook App User ID';
157
+ default:
158
+ return 'Other ID';
159
+ }
160
+ },
161
+
162
+ getIdentityType: (
163
+ identityName: string
164
+ ): valueof<typeof IdentityType> | boolean => {
165
+ switch (identityName) {
166
+ case 'other':
167
+ return IdentityType.Other;
168
+ case 'customerid':
169
+ return IdentityType.CustomerId;
170
+ case 'facebook':
171
+ return IdentityType.Facebook;
172
+ case 'twitter':
173
+ return IdentityType.Twitter;
174
+ case 'google':
175
+ return IdentityType.Google;
176
+ case 'microsoft':
177
+ return IdentityType.Microsoft;
178
+ case 'yahoo':
179
+ return IdentityType.Yahoo;
180
+ case 'email':
181
+ return IdentityType.Email;
182
+ case 'facebookcustomaudienceid':
183
+ return IdentityType.FacebookCustomAudienceId;
184
+ case 'other2':
185
+ return IdentityType.Other2;
186
+ case 'other3':
187
+ return IdentityType.Other3;
188
+ case 'other4':
189
+ return IdentityType.Other4;
190
+ case 'other5':
191
+ return IdentityType.Other5;
192
+ case 'other6':
193
+ return IdentityType.Other6;
194
+ case 'other7':
195
+ return IdentityType.Other7;
196
+ case 'other8':
197
+ return IdentityType.Other8;
198
+ case 'other9':
199
+ return IdentityType.Other9;
200
+ case 'other10':
201
+ return IdentityType.Other10;
202
+ case 'mobile_number':
203
+ return IdentityType.MobileNumber;
204
+ case 'phone_number_2':
205
+ return IdentityType.PhoneNumber2;
206
+ case 'phone_number_3':
207
+ return IdentityType.PhoneNumber3;
208
+ default:
209
+ return false;
210
+ }
211
+ },
212
+
213
+ getIdentityName: (identityType: number): string | null => {
214
+ switch (identityType) {
215
+ case IdentityType.Other:
216
+ return 'other';
217
+ case IdentityType.CustomerId:
218
+ return 'customerid';
219
+ case IdentityType.Facebook:
220
+ return 'facebook';
221
+ case IdentityType.Twitter:
222
+ return 'twitter';
223
+ case IdentityType.Google:
224
+ return 'google';
225
+ case IdentityType.Microsoft:
226
+ return 'microsoft';
227
+ case IdentityType.Yahoo:
228
+ return 'yahoo';
229
+ case IdentityType.Email:
230
+ return 'email';
231
+ case IdentityType.FacebookCustomAudienceId:
232
+ return 'facebookcustomaudienceid';
233
+ case IdentityType.Other2:
234
+ return 'other2';
235
+ case IdentityType.Other3:
236
+ return 'other3';
237
+ case IdentityType.Other4:
238
+ return 'other4';
239
+ case IdentityType.Other5:
240
+ return 'other5';
241
+ case IdentityType.Other6:
242
+ return 'other6';
243
+ case IdentityType.Other7:
244
+ return 'other7';
245
+ case IdentityType.Other8:
246
+ return 'other8';
247
+ case IdentityType.Other9:
248
+ return 'other9';
249
+ case IdentityType.Other10:
250
+ return 'other10';
251
+ case IdentityType.MobileNumber:
252
+ return 'mobile_number';
253
+ case IdentityType.PhoneNumber2:
254
+ return 'phone_number_2';
255
+ case IdentityType.PhoneNumber3:
256
+ return 'phone_number_3';
257
+ default:
258
+ return null;
259
+ }
260
+ },
261
+
262
+ // Strips out functions from Identity Types for easier lookups
263
+ getValuesAsStrings: (): string[] =>
264
+ Object.values(IdentityType)
265
+ .map(value => (isNumber(value) ? value.toString() : undefined))
266
+ .filter(value => value !== undefined) as string[],
267
+
268
+ getNewIdentitiesByName: (
269
+ newIdentitiesByType: IdentitiesByType
270
+ ): IdentitiesByType => {
271
+ const newIdentitiesByName: IdentitiesByType = {};
272
+ const identityTypeValuesAsStrings: string[] = IdentityType.getValuesAsStrings();
273
+
274
+ for (const key in newIdentitiesByType) {
275
+ // IdentityTypes are stored as numbers but are passed in as strings
276
+ if (identityTypeValuesAsStrings.includes(key)) {
277
+ const identityNameKey = IdentityType.getIdentityName(
278
+ parseNumber(key)
279
+ );
280
+ newIdentitiesByName[identityNameKey] = newIdentitiesByType[key];
281
+ }
282
+ }
283
+
284
+ return newIdentitiesByName;
285
+ },
286
+ };
287
+
288
+ export const ProductActionType = {
289
+ Unknown: 0 as const,
290
+ AddToCart: 1 as const,
291
+ RemoveFromCart: 2 as const,
292
+ Checkout: 3 as const,
293
+ CheckoutOption: 4 as const,
294
+ Click: 5 as const,
295
+ ViewDetail: 6 as const,
296
+ Purchase: 7 as const,
297
+ Refund: 8 as const,
298
+ AddToWishlist: 9 as const,
299
+ RemoveFromWishlist: 10 as const,
300
+
301
+ getName: (id: number): string => {
302
+ switch (id) {
303
+ case ProductActionType.AddToCart:
304
+ return 'Add to Cart';
305
+ case ProductActionType.RemoveFromCart:
306
+ return 'Remove from Cart';
307
+ case ProductActionType.Checkout:
308
+ return 'Checkout';
309
+ case ProductActionType.CheckoutOption:
310
+ return 'Checkout Option';
311
+ case ProductActionType.Click:
312
+ return 'Click';
313
+ case ProductActionType.ViewDetail:
314
+ return 'View Detail';
315
+ case ProductActionType.Purchase:
316
+ return 'Purchase';
317
+ case ProductActionType.Refund:
318
+ return 'Refund';
319
+ case ProductActionType.AddToWishlist:
320
+ return 'Add to Wishlist';
321
+ case ProductActionType.RemoveFromWishlist:
322
+ return 'Remove from Wishlist';
323
+ default:
324
+ return 'Unknown';
325
+ }
326
+ },
327
+
328
+ // these are the action names used by server and mobile SDKs when expanding a CommerceEvent
329
+ getExpansionName: (id: number) => {
330
+ switch (id) {
331
+ case ProductActionType.AddToCart:
332
+ return 'add_to_cart';
333
+ case ProductActionType.RemoveFromCart:
334
+ return 'remove_from_cart';
335
+ case ProductActionType.Checkout:
336
+ return 'checkout';
337
+ case ProductActionType.CheckoutOption:
338
+ return 'checkout_option';
339
+ case ProductActionType.Click:
340
+ return 'click';
341
+ case ProductActionType.ViewDetail:
342
+ return 'view_detail';
343
+ case ProductActionType.Purchase:
344
+ return 'purchase';
345
+ case ProductActionType.Refund:
346
+ return 'refund';
347
+ case ProductActionType.AddToWishlist:
348
+ return 'add_to_wishlist';
349
+ case ProductActionType.RemoveFromWishlist:
350
+ return 'remove_from_wishlist';
351
+ default:
352
+ return 'unknown';
353
+ }
354
+ },
355
+ };
356
+
357
+ export const PromotionActionType = {
358
+ Unknown: 0 as const,
359
+ PromotionView: 1 as const,
360
+ PromotionClick: 2 as const,
361
+
362
+ getName: (id: number): string => {
363
+ switch (id) {
364
+ case PromotionActionType.PromotionView:
365
+ return 'view';
366
+ case PromotionActionType.PromotionClick:
367
+ return 'click';
368
+ default:
369
+ return 'unknown';
370
+ }
371
+ },
372
+
373
+ // these are the names that the server and mobile SDKs use while expanding CommerceEvent
374
+ getExpansionName: (id: number): string => {
375
+ switch (id) {
376
+ case PromotionActionType.PromotionView:
377
+ return 'view';
378
+ case PromotionActionType.PromotionClick:
379
+ return 'click';
380
+ default:
381
+ return 'unknown';
382
+ }
383
+ },
384
+ };
385
+
386
+ export const ProfileMessageType = {
387
+ Logout: 3 as const,
388
+ };
389
+
390
+ export const ApplicationTransitionType = {
391
+ AppInit: 1 as const,
392
+ };
393
+
394
+ export default {
395
+ MessageType,
396
+ EventType,
397
+ CommerceEventType,
398
+ IdentityType,
399
+ ProfileMessageType,
400
+ ApplicationTransitionType,
401
+ ProductActionType,
402
+ PromotionActionType,
403
+ Environment: Constants.Environment,
404
+ } as const;
package/src/utils.ts CHANGED
@@ -8,7 +8,7 @@ type valueof<T> = T[keyof T];
8
8
  // Placeholder for Dictionary-like Types
9
9
  export type Dictionary<V = any> = Record<string, V>;
10
10
 
11
- export type Environment = 'development' | 'production';
11
+ export type Environment = valueof<typeof Constants.Environment>;
12
12
 
13
13
  const createCookieString = (value: string): string =>
14
14
  replaceCommasWithPipes(replaceQuotesWithApostrophes(value));
package/src/type-utils.ts DELETED
@@ -1,66 +0,0 @@
1
- import { IdentityType } from './types.interfaces';
2
- import { parseNumber } from './utils';
3
-
4
- export interface IIdentitiesByType {
5
- [key: number]: string;
6
- }
7
-
8
- export function getNewIdentitiesByName(newIdentitiesByType: IIdentitiesByType) {
9
- const newIdentitiesByName = {};
10
-
11
- for (var key in newIdentitiesByType) {
12
- const identityNameKey = getIdentityName(parseNumber(key));
13
- newIdentitiesByName[identityNameKey] = newIdentitiesByType[key];
14
- }
15
-
16
- return newIdentitiesByName;
17
- }
18
-
19
- export function getIdentityName(identityType: IdentityType): string | null {
20
- switch (identityType) {
21
- case IdentityType.Other:
22
- return 'other';
23
- case IdentityType.CustomerId:
24
- return 'customerid';
25
- case IdentityType.Facebook:
26
- return 'facebook';
27
- case IdentityType.Twitter:
28
- return 'twitter';
29
- case IdentityType.Google:
30
- return 'google';
31
- case IdentityType.Microsoft:
32
- return 'microsoft';
33
- case IdentityType.Yahoo:
34
- return 'yahoo';
35
- case IdentityType.Email:
36
- return 'email';
37
- case IdentityType.FacebookCustomAudienceId:
38
- return 'facebookcustomaudienceid';
39
- case IdentityType.Other2:
40
- return 'other2';
41
- case IdentityType.Other3:
42
- return 'other3';
43
- case IdentityType.Other4:
44
- return 'other4';
45
- case IdentityType.Other5:
46
- return 'other5';
47
- case IdentityType.Other6:
48
- return 'other6';
49
- case IdentityType.Other7:
50
- return 'other7';
51
- case IdentityType.Other8:
52
- return 'other8';
53
- case IdentityType.Other9:
54
- return 'other9';
55
- case IdentityType.Other10:
56
- return 'other10';
57
- case IdentityType.MobileNumber:
58
- return 'mobile_number';
59
- case IdentityType.PhoneNumber2:
60
- return 'phone_number_2';
61
- case IdentityType.PhoneNumber3:
62
- return 'phone_number_3';
63
- default:
64
- return null;
65
- }
66
- }
@@ -1,56 +0,0 @@
1
- export enum EventTypeEnum {
2
- Unknown,
3
- Navigation,
4
- Location,
5
- Search,
6
- Transaction,
7
- UserContent,
8
- UserPreference,
9
- Social,
10
- Other,
11
- Media,
12
- }
13
-
14
- // TODO: https://mparticle-eng.atlassian.net/browse/SQDSDKS-5403
15
- export enum MessageType {
16
- SessionStart = 1,
17
- SessionEnd = 2,
18
- PageView = 3,
19
- PageEvent = 4,
20
- CrashReport = 5,
21
- OptOut = 6,
22
- AppStateTransition = 10,
23
- Profile = 14,
24
- Commerce = 16,
25
- UserAttributeChange = 17,
26
- UserIdentityChange = 18,
27
- Media = 20,
28
- };
29
-
30
- export enum IdentityType {
31
- Other = 0,
32
- CustomerId = 1,
33
- Facebook = 2,
34
- Twitter = 3,
35
- Google = 4,
36
- Microsoft = 5,
37
- Yahoo = 6,
38
- Email = 7,
39
- FacebookCustomAudienceId = 9,
40
- Other2 = 10,
41
- Other3 = 11,
42
- Other4 = 12,
43
- Other5 = 13,
44
- Other6 = 14,
45
- Other7 = 15,
46
- Other8 = 16,
47
- Other9 = 17,
48
- Other10 = 18,
49
- MobileNumber = 19,
50
- PhoneNumber2 = 20,
51
- PhoneNumber3 = 21,
52
- }
53
-
54
- export interface IIdentityType {
55
- getIdentityType(identityType: string): IdentityType | null;
56
- }