@mparticle/web-sdk 2.15.4 → 2.16.1
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 +89 -42
- package/dist/mparticle.esm.js +89 -42
- package/dist/mparticle.js +366 -332
- package/package.json +3 -5
- package/src/batchUploader.ts +10 -3
- package/src/{constants.js → constants.ts} +2 -2
- package/src/helpers.js +16 -220
- package/src/mp-instance.js +8 -0
- package/src/sdkRuntimeModels.ts +4 -0
- package/src/sdkToEventsApiConverter.ts +1 -0
- package/src/serverModel.js +1 -0
- package/src/store.js +16 -0
- package/src/utils.ts +82 -0
- package/src/validators.ts +165 -0
package/dist/mparticle.js
CHANGED
|
@@ -721,176 +721,175 @@ var mParticle = (function () {
|
|
|
721
721
|
TriggerUploadType: TriggerUploadType
|
|
722
722
|
};
|
|
723
723
|
|
|
724
|
-
var version = "2.
|
|
724
|
+
var version = "2.16.1";
|
|
725
725
|
|
|
726
726
|
var Constants = {
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
727
|
+
sdkVersion: version,
|
|
728
|
+
sdkVendor: 'mparticle',
|
|
729
|
+
platform: 'web',
|
|
730
|
+
Messages: {
|
|
731
|
+
ErrorMessages: {
|
|
732
|
+
NoToken: 'A token must be specified.',
|
|
733
|
+
EventNameInvalidType: 'Event name must be a valid string value.',
|
|
734
|
+
EventDataInvalidType: 'Event data must be a valid object hash.',
|
|
735
|
+
LoggingDisabled: 'Event logging is currently disabled.',
|
|
736
|
+
CookieParseError: 'Could not parse cookie',
|
|
737
|
+
EventEmpty: 'Event object is null or undefined, cancelling send',
|
|
738
|
+
APIRequestEmpty: 'APIRequest is null or undefined, cancelling send',
|
|
739
|
+
NoEventType: 'Event type must be specified.',
|
|
740
|
+
TransactionIdRequired: 'Transaction ID is required',
|
|
741
|
+
TransactionRequired: 'A transaction attributes object is required',
|
|
742
|
+
PromotionIdRequired: 'Promotion ID is required',
|
|
743
|
+
BadAttribute: 'Attribute value cannot be object or array',
|
|
744
|
+
BadKey: 'Key value cannot be object or array',
|
|
745
|
+
BadLogPurchase: 'Transaction attributes and a product are both required to log a purchase, https://docs.mparticle.com/?javascript#measuring-transactions'
|
|
746
|
+
},
|
|
747
|
+
InformationMessages: {
|
|
748
|
+
CookieSearch: 'Searching for cookie',
|
|
749
|
+
CookieFound: 'Cookie found, parsing values',
|
|
750
|
+
CookieNotFound: 'Cookies not found',
|
|
751
|
+
CookieSet: 'Setting cookie',
|
|
752
|
+
CookieSync: 'Performing cookie sync',
|
|
753
|
+
SendBegin: 'Starting to send event',
|
|
754
|
+
SendIdentityBegin: 'Starting to send event to identity server',
|
|
755
|
+
SendWindowsPhone: 'Sending event to Windows Phone container',
|
|
756
|
+
SendIOS: 'Calling iOS path: ',
|
|
757
|
+
SendAndroid: 'Calling Android JS interface method: ',
|
|
758
|
+
SendHttp: 'Sending event to mParticle HTTP service',
|
|
759
|
+
SendAliasHttp: 'Sending alias request to mParticle HTTP service',
|
|
760
|
+
SendIdentityHttp: 'Sending event to mParticle HTTP service',
|
|
761
|
+
StartingNewSession: 'Starting new Session',
|
|
762
|
+
StartingLogEvent: 'Starting to log event',
|
|
763
|
+
StartingLogOptOut: 'Starting to log user opt in/out',
|
|
764
|
+
StartingEndSession: 'Starting to end session',
|
|
765
|
+
StartingInitialization: 'Starting to initialize',
|
|
766
|
+
StartingLogCommerceEvent: 'Starting to log commerce event',
|
|
767
|
+
StartingAliasRequest: 'Starting to Alias MPIDs',
|
|
768
|
+
LoadingConfig: 'Loading configuration options',
|
|
769
|
+
AbandonLogEvent: 'Cannot log event, logging disabled or developer token not set',
|
|
770
|
+
AbandonAliasUsers: 'Cannot Alias Users, logging disabled or developer token not set',
|
|
771
|
+
AbandonStartSession: 'Cannot start session, logging disabled or developer token not set',
|
|
772
|
+
AbandonEndSession: 'Cannot end session, logging disabled or developer token not set',
|
|
773
|
+
NoSessionToEnd: 'Cannot end session, no active session found'
|
|
774
|
+
},
|
|
775
|
+
ValidationMessages: {
|
|
776
|
+
ModifyIdentityRequestUserIdentitiesPresent: 'identityRequests to modify require userIdentities to be present. Request not sent to server. Please fix and try again',
|
|
777
|
+
IdentityRequesetInvalidKey: 'There is an invalid key on your identityRequest object. It can only contain a `userIdentities` object and a `onUserAlias` function. Request not sent to server. Please fix and try again.',
|
|
778
|
+
OnUserAliasType: 'The onUserAlias value must be a function. The onUserAlias provided is of type',
|
|
779
|
+
UserIdentities: 'The userIdentities key must be an object with keys of identityTypes and values of strings. Request not sent to server. Please fix and try again.',
|
|
780
|
+
UserIdentitiesInvalidKey: 'There is an invalid identity key on your `userIdentities` object within the identityRequest. Request not sent to server. Please fix and try again.',
|
|
781
|
+
UserIdentitiesInvalidValues: 'All user identity values must be strings or null. Request not sent to server. Please fix and try again.',
|
|
782
|
+
AliasMissingMpid: 'Alias Request must contain both a destinationMpid and a sourceMpid',
|
|
783
|
+
AliasNonUniqueMpid: "Alias Request's destinationMpid and sourceMpid must be unique",
|
|
784
|
+
AliasMissingTime: 'Alias Request must have both a startTime and an endTime',
|
|
785
|
+
AliasStartBeforeEndTime: "Alias Request's endTime must be later than its startTime"
|
|
786
|
+
}
|
|
746
787
|
},
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
LoadingConfig: 'Loading configuration options',
|
|
769
|
-
AbandonLogEvent: 'Cannot log event, logging disabled or developer token not set',
|
|
770
|
-
AbandonAliasUsers: 'Cannot Alias Users, logging disabled or developer token not set',
|
|
771
|
-
AbandonStartSession: 'Cannot start session, logging disabled or developer token not set',
|
|
772
|
-
AbandonEndSession: 'Cannot end session, logging disabled or developer token not set',
|
|
773
|
-
NoSessionToEnd: 'Cannot end session, no active session found'
|
|
788
|
+
NativeSdkPaths: {
|
|
789
|
+
LogEvent: 'logEvent',
|
|
790
|
+
SetUserTag: 'setUserTag',
|
|
791
|
+
RemoveUserTag: 'removeUserTag',
|
|
792
|
+
SetUserAttribute: 'setUserAttribute',
|
|
793
|
+
RemoveUserAttribute: 'removeUserAttribute',
|
|
794
|
+
SetSessionAttribute: 'setSessionAttribute',
|
|
795
|
+
AddToCart: 'addToCart',
|
|
796
|
+
RemoveFromCart: 'removeFromCart',
|
|
797
|
+
ClearCart: 'clearCart',
|
|
798
|
+
LogOut: 'logOut',
|
|
799
|
+
SetUserAttributeList: 'setUserAttributeList',
|
|
800
|
+
RemoveAllUserAttributes: 'removeAllUserAttributes',
|
|
801
|
+
GetUserAttributesLists: 'getUserAttributesLists',
|
|
802
|
+
GetAllUserAttributes: 'getAllUserAttributes',
|
|
803
|
+
Identify: 'identify',
|
|
804
|
+
Logout: 'logout',
|
|
805
|
+
Login: 'login',
|
|
806
|
+
Modify: 'modify',
|
|
807
|
+
Alias: 'aliasUsers',
|
|
808
|
+
Upload: 'upload'
|
|
774
809
|
},
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
configUrl: 'jssdkcdns.mparticle.com/JS/v2/',
|
|
859
|
-
identityUrl: 'identity.mparticle.com/v1/',
|
|
860
|
-
aliasUrl: 'jssdks.mparticle.com/v1/identity/'
|
|
861
|
-
},
|
|
862
|
-
Base64CookieKeys: {
|
|
863
|
-
csm: 1,
|
|
864
|
-
sa: 1,
|
|
865
|
-
ss: 1,
|
|
866
|
-
ua: 1,
|
|
867
|
-
ui: 1,
|
|
868
|
-
csd: 1,
|
|
869
|
-
ia: 1,
|
|
870
|
-
con: 1
|
|
871
|
-
},
|
|
872
|
-
SDKv2NonMPIDCookieKeys: {
|
|
873
|
-
gs: 1,
|
|
874
|
-
cu: 1,
|
|
875
|
-
l: 1,
|
|
876
|
-
globalSettings: 1,
|
|
877
|
-
currentUserMPID: 1
|
|
878
|
-
},
|
|
879
|
-
HTTPCodes: {
|
|
880
|
-
noHttpCoverage: -1,
|
|
881
|
-
activeIdentityRequest: -2,
|
|
882
|
-
activeSession: -3,
|
|
883
|
-
validationIssue: -4,
|
|
884
|
-
nativeIdentityRequest: -5,
|
|
885
|
-
loggingDisabledOrMissingAPIKey: -6,
|
|
886
|
-
tooManyRequests: 429
|
|
887
|
-
},
|
|
888
|
-
FeatureFlags: {
|
|
889
|
-
ReportBatching: 'reportBatching',
|
|
890
|
-
EventsV3: 'eventsV3',
|
|
891
|
-
EventBatchingIntervalMillis: 'eventBatchingIntervalMillis'
|
|
892
|
-
},
|
|
893
|
-
DefaultInstance: 'default_instance'
|
|
810
|
+
StorageNames: {
|
|
811
|
+
localStorageName: 'mprtcl-api',
|
|
812
|
+
// Name of the mP localstorage, had cp and pb even if cookies were used, skipped v2
|
|
813
|
+
localStorageNameV3: 'mprtcl-v3',
|
|
814
|
+
// v3 Name of the mP localstorage, final version on SDKv1
|
|
815
|
+
cookieName: 'mprtcl-api',
|
|
816
|
+
// v1 Name of the cookie stored on the user's machine
|
|
817
|
+
cookieNameV2: 'mprtcl-v2',
|
|
818
|
+
// v2 Name of the cookie stored on the user's machine. Removed keys with no values, moved cartProducts and productBags to localStorage.
|
|
819
|
+
cookieNameV3: 'mprtcl-v3',
|
|
820
|
+
// v3 Name of the cookie stored on the user's machine. Base64 encoded keys in Base64CookieKeys object, final version on SDKv1
|
|
821
|
+
localStorageNameV4: 'mprtcl-v4',
|
|
822
|
+
// v4 Name of the mP localstorage, Current Version
|
|
823
|
+
localStorageProductsV4: 'mprtcl-prodv4',
|
|
824
|
+
// The name for mP localstorage that contains products for cartProducs and productBags
|
|
825
|
+
cookieNameV4: 'mprtcl-v4',
|
|
826
|
+
// v4 Name of the cookie stored on the user's machine. Base64 encoded keys in Base64CookieKeys object, current version on SDK v2
|
|
827
|
+
currentStorageName: 'mprtcl-v4',
|
|
828
|
+
currentStorageProductsName: 'mprtcl-prodv4'
|
|
829
|
+
},
|
|
830
|
+
DefaultConfig: {
|
|
831
|
+
cookieDomain: null,
|
|
832
|
+
// If null, defaults to current location.host
|
|
833
|
+
cookieExpiration: 365,
|
|
834
|
+
// Cookie expiration time in days
|
|
835
|
+
logLevel: null,
|
|
836
|
+
// What logging will be provided in the console
|
|
837
|
+
timeout: 300,
|
|
838
|
+
// timeout in milliseconds for logging functions
|
|
839
|
+
sessionTimeout: 30,
|
|
840
|
+
// Session timeout in minutes
|
|
841
|
+
maxProducts: 20,
|
|
842
|
+
// Number of products persisted in cartProducts and productBags
|
|
843
|
+
forwarderStatsTimeout: 5000,
|
|
844
|
+
// Milliseconds for forwarderStats timeout
|
|
845
|
+
integrationDelayTimeout: 5000,
|
|
846
|
+
// Milliseconds for forcing the integration delay to un-suspend event queueing due to integration partner errors
|
|
847
|
+
maxCookieSize: 3000,
|
|
848
|
+
// Number of bytes for cookie size to not exceed
|
|
849
|
+
aliasMaxWindow: 90,
|
|
850
|
+
// Max age of Alias request startTime, in days
|
|
851
|
+
uploadInterval: 0 // Maximum milliseconds in between batch uploads, below 500 will mean immediate upload
|
|
852
|
+
},
|
|
853
|
+
DefaultUrls: {
|
|
854
|
+
v1SecureServiceUrl: 'jssdks.mparticle.com/v1/JS/',
|
|
855
|
+
v2SecureServiceUrl: 'jssdks.mparticle.com/v2/JS/',
|
|
856
|
+
v3SecureServiceUrl: 'jssdks.mparticle.com/v3/JS/',
|
|
857
|
+
configUrl: 'jssdkcdns.mparticle.com/JS/v2/',
|
|
858
|
+
identityUrl: 'identity.mparticle.com/v1/',
|
|
859
|
+
aliasUrl: 'jssdks.mparticle.com/v1/identity/'
|
|
860
|
+
},
|
|
861
|
+
Base64CookieKeys: {
|
|
862
|
+
csm: 1,
|
|
863
|
+
sa: 1,
|
|
864
|
+
ss: 1,
|
|
865
|
+
ua: 1,
|
|
866
|
+
ui: 1,
|
|
867
|
+
csd: 1,
|
|
868
|
+
ia: 1,
|
|
869
|
+
con: 1
|
|
870
|
+
},
|
|
871
|
+
SDKv2NonMPIDCookieKeys: {
|
|
872
|
+
gs: 1,
|
|
873
|
+
cu: 1,
|
|
874
|
+
l: 1,
|
|
875
|
+
globalSettings: 1,
|
|
876
|
+
currentUserMPID: 1
|
|
877
|
+
},
|
|
878
|
+
HTTPCodes: {
|
|
879
|
+
noHttpCoverage: -1,
|
|
880
|
+
activeIdentityRequest: -2,
|
|
881
|
+
activeSession: -3,
|
|
882
|
+
validationIssue: -4,
|
|
883
|
+
nativeIdentityRequest: -5,
|
|
884
|
+
loggingDisabledOrMissingAPIKey: -6,
|
|
885
|
+
tooManyRequests: 429
|
|
886
|
+
},
|
|
887
|
+
FeatureFlags: {
|
|
888
|
+
ReportBatching: 'reportBatching',
|
|
889
|
+
EventsV3: 'eventsV3',
|
|
890
|
+
EventBatchingIntervalMillis: 'eventBatchingIntervalMillis'
|
|
891
|
+
},
|
|
892
|
+
DefaultInstance: 'default_instance'
|
|
894
893
|
};
|
|
895
894
|
|
|
896
895
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
@@ -2335,7 +2334,8 @@ var mParticle = (function () {
|
|
|
2335
2334
|
sdk_version: lastEvent.SDKVersion,
|
|
2336
2335
|
application_info: {
|
|
2337
2336
|
application_version: lastEvent.AppVersion,
|
|
2338
|
-
application_name: lastEvent.AppName
|
|
2337
|
+
application_name: lastEvent.AppName,
|
|
2338
|
+
"package": lastEvent.Package
|
|
2339
2339
|
},
|
|
2340
2340
|
device_info: {
|
|
2341
2341
|
platform: dist_13.web,
|
|
@@ -3234,9 +3234,14 @@ var mParticle = (function () {
|
|
|
3234
3234
|
}
|
|
3235
3235
|
for (var _i2 = 0, _Array$from2 = Array.from(eventsBySession.entries()); _i2 < _Array$from2.length; _i2++) {
|
|
3236
3236
|
var _entry = _Array$from2[_i2];
|
|
3237
|
-
var
|
|
3238
|
-
|
|
3239
|
-
|
|
3237
|
+
var uploadBatchObject = convertEvents(mpid, _entry[1], mpInstance);
|
|
3238
|
+
var onCreateBatchCallback = mpInstance._Store.SDKConfig.onCreateBatch;
|
|
3239
|
+
if (onCreateBatchCallback) {
|
|
3240
|
+
uploadBatchObject = onCreateBatchCallback(uploadBatchObject);
|
|
3241
|
+
uploadBatchObject.mutated = true;
|
|
3242
|
+
}
|
|
3243
|
+
if (uploadBatchObject) {
|
|
3244
|
+
newUploads.push(uploadBatchObject);
|
|
3240
3245
|
}
|
|
3241
3246
|
}
|
|
3242
3247
|
}
|
|
@@ -3638,8 +3643,163 @@ var mParticle = (function () {
|
|
|
3638
3643
|
}));
|
|
3639
3644
|
});
|
|
3640
3645
|
|
|
3641
|
-
|
|
3642
|
-
|
|
3646
|
+
function _readOnlyError(name) {
|
|
3647
|
+
throw new Error("\"" + name + "\" is read-only");
|
|
3648
|
+
}
|
|
3649
|
+
|
|
3650
|
+
var readOnlyError = _readOnlyError;
|
|
3651
|
+
|
|
3652
|
+
var inArray = function inArray(items, name) {
|
|
3653
|
+
var i = 0;
|
|
3654
|
+
if (Array.prototype.indexOf) {
|
|
3655
|
+
return items.indexOf(name, 0) >= 0;
|
|
3656
|
+
}
|
|
3657
|
+
else {
|
|
3658
|
+
for (var n = items.length; i < n; readOnlyError("i")) {
|
|
3659
|
+
if (i in items && items[i] === name) {
|
|
3660
|
+
return true;
|
|
3661
|
+
}
|
|
3662
|
+
}
|
|
3663
|
+
}
|
|
3664
|
+
return false;
|
|
3665
|
+
};
|
|
3666
|
+
var findKeyInObject = function findKeyInObject(obj, key) {
|
|
3667
|
+
if (key && obj) {
|
|
3668
|
+
for (var prop in obj) {
|
|
3669
|
+
if (obj.hasOwnProperty(prop) && prop.toLowerCase() === key.toLowerCase()) {
|
|
3670
|
+
return prop;
|
|
3671
|
+
}
|
|
3672
|
+
}
|
|
3673
|
+
}
|
|
3674
|
+
return null;
|
|
3675
|
+
};
|
|
3676
|
+
var isObject = function isObject(value) {
|
|
3677
|
+
var objType = Object.prototype.toString.call(value);
|
|
3678
|
+
return objType === '[object Object]' || objType === '[object Error]';
|
|
3679
|
+
};
|
|
3680
|
+
var parseNumber = function parseNumber(value) {
|
|
3681
|
+
if (isNaN(value) || !isFinite(value)) {
|
|
3682
|
+
return 0;
|
|
3683
|
+
}
|
|
3684
|
+
var floatValue = parseFloat(value);
|
|
3685
|
+
return isNaN(floatValue) ? 0 : floatValue;
|
|
3686
|
+
}; // FIXME: REFACTOR for V3
|
|
3687
|
+
// only used in store.js to sanitize server-side formatting of
|
|
3688
|
+
// booleans when checking for `isDevelopmentMode`
|
|
3689
|
+
// Should be removed in v3
|
|
3690
|
+
var returnConvertedBoolean = function returnConvertedBoolean(data) {
|
|
3691
|
+
if (data === 'false' || data === '0') {
|
|
3692
|
+
return false;
|
|
3693
|
+
}
|
|
3694
|
+
else {
|
|
3695
|
+
return Boolean(data);
|
|
3696
|
+
}
|
|
3697
|
+
};
|
|
3698
|
+
var decoded = function decoded(s) {
|
|
3699
|
+
return decodeURIComponent(s.replace(/\+/g, ' '));
|
|
3700
|
+
};
|
|
3701
|
+
var converted = function converted(s) {
|
|
3702
|
+
if (s.indexOf('"') === 0) {
|
|
3703
|
+
s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
|
|
3704
|
+
}
|
|
3705
|
+
return s;
|
|
3706
|
+
};
|
|
3707
|
+
|
|
3708
|
+
var Validators = {
|
|
3709
|
+
isValidAttributeValue: function isValidAttributeValue(value) {
|
|
3710
|
+
return value !== undefined && !isObject(value) && !Array.isArray(value);
|
|
3711
|
+
},
|
|
3712
|
+
// Neither null nor undefined can be a valid Key
|
|
3713
|
+
isValidKeyValue: function isValidKeyValue(key) {
|
|
3714
|
+
return Boolean(key && !isObject(key) && !Array.isArray(key) && !this.isFunction(key));
|
|
3715
|
+
},
|
|
3716
|
+
isStringOrNumber: function isStringOrNumber(value) {
|
|
3717
|
+
return typeof value === 'string' || typeof value === 'number';
|
|
3718
|
+
},
|
|
3719
|
+
isNumber: function isNumber(value) {
|
|
3720
|
+
return typeof value === 'number';
|
|
3721
|
+
},
|
|
3722
|
+
isFunction: function isFunction(fn) {
|
|
3723
|
+
return typeof fn === 'function';
|
|
3724
|
+
},
|
|
3725
|
+
validateIdentities: function validateIdentities(identityApiData, method) {
|
|
3726
|
+
var validIdentityRequestKeys = {
|
|
3727
|
+
userIdentities: 1,
|
|
3728
|
+
onUserAlias: 1,
|
|
3729
|
+
copyUserAttributes: 1
|
|
3730
|
+
};
|
|
3731
|
+
if (identityApiData) {
|
|
3732
|
+
if (method === 'modify') {
|
|
3733
|
+
if (isObject(identityApiData.userIdentities) && !Object.keys(identityApiData.userIdentities).length || !isObject(identityApiData.userIdentities)) {
|
|
3734
|
+
return {
|
|
3735
|
+
valid: false,
|
|
3736
|
+
error: Constants.Messages.ValidationMessages.ModifyIdentityRequestUserIdentitiesPresent
|
|
3737
|
+
};
|
|
3738
|
+
}
|
|
3739
|
+
}
|
|
3740
|
+
for (var key in identityApiData) {
|
|
3741
|
+
if (identityApiData.hasOwnProperty(key)) {
|
|
3742
|
+
if (!validIdentityRequestKeys[key]) {
|
|
3743
|
+
return {
|
|
3744
|
+
valid: false,
|
|
3745
|
+
error: Constants.Messages.ValidationMessages.IdentityRequesetInvalidKey
|
|
3746
|
+
};
|
|
3747
|
+
}
|
|
3748
|
+
if (key === 'onUserAlias' && !Validators.isFunction(identityApiData[key])) {
|
|
3749
|
+
return {
|
|
3750
|
+
valid: false,
|
|
3751
|
+
// FIXME: Validates type safety
|
|
3752
|
+
error: Constants.Messages.ValidationMessages.OnUserAliasType + _typeof_1(identityApiData[key])
|
|
3753
|
+
};
|
|
3754
|
+
}
|
|
3755
|
+
}
|
|
3756
|
+
}
|
|
3757
|
+
if (Object.keys(identityApiData).length === 0) {
|
|
3758
|
+
return {
|
|
3759
|
+
valid: true
|
|
3760
|
+
};
|
|
3761
|
+
}
|
|
3762
|
+
else {
|
|
3763
|
+
// identityApiData.userIdentities can't be undefined
|
|
3764
|
+
if (identityApiData.userIdentities === undefined) {
|
|
3765
|
+
return {
|
|
3766
|
+
valid: false,
|
|
3767
|
+
error: Constants.Messages.ValidationMessages.UserIdentities
|
|
3768
|
+
}; // identityApiData.userIdentities can be null, but if it isn't null or undefined (above conditional), it must be an object
|
|
3769
|
+
}
|
|
3770
|
+
else if (identityApiData.userIdentities !== null && !isObject(identityApiData.userIdentities)) {
|
|
3771
|
+
return {
|
|
3772
|
+
valid: false,
|
|
3773
|
+
error: Constants.Messages.ValidationMessages.UserIdentities
|
|
3774
|
+
};
|
|
3775
|
+
}
|
|
3776
|
+
if (isObject(identityApiData.userIdentities) && Object.keys(identityApiData.userIdentities).length) {
|
|
3777
|
+
for (var identityType in identityApiData.userIdentities) {
|
|
3778
|
+
if (identityApiData.userIdentities.hasOwnProperty(identityType)) {
|
|
3779
|
+
if (Types.IdentityType.getIdentityType(identityType) === false) {
|
|
3780
|
+
return {
|
|
3781
|
+
valid: false,
|
|
3782
|
+
error: Constants.Messages.ValidationMessages.UserIdentitiesInvalidKey
|
|
3783
|
+
};
|
|
3784
|
+
}
|
|
3785
|
+
if (!(typeof identityApiData.userIdentities[identityType] === 'string' || identityApiData.userIdentities[identityType] === null)) {
|
|
3786
|
+
return {
|
|
3787
|
+
valid: false,
|
|
3788
|
+
error: Constants.Messages.ValidationMessages.UserIdentitiesInvalidValues
|
|
3789
|
+
};
|
|
3790
|
+
}
|
|
3791
|
+
}
|
|
3792
|
+
}
|
|
3793
|
+
}
|
|
3794
|
+
}
|
|
3795
|
+
}
|
|
3796
|
+
return {
|
|
3797
|
+
valid: true
|
|
3798
|
+
};
|
|
3799
|
+
}
|
|
3800
|
+
};
|
|
3801
|
+
|
|
3802
|
+
var StorageNames = Constants.StorageNames;
|
|
3643
3803
|
function Helpers(mpInstance) {
|
|
3644
3804
|
var self = this;
|
|
3645
3805
|
|
|
@@ -3651,14 +3811,6 @@ var mParticle = (function () {
|
|
|
3651
3811
|
return false;
|
|
3652
3812
|
};
|
|
3653
3813
|
|
|
3654
|
-
this.returnConvertedBoolean = function (data) {
|
|
3655
|
-
if (data === 'false' || data === '0') {
|
|
3656
|
-
return false;
|
|
3657
|
-
} else {
|
|
3658
|
-
return Boolean(data);
|
|
3659
|
-
}
|
|
3660
|
-
};
|
|
3661
|
-
|
|
3662
3814
|
this.getFeatureFlag = function (feature) {
|
|
3663
3815
|
if (mpInstance._Store.SDKConfig.flags.hasOwnProperty(feature)) {
|
|
3664
3816
|
return mpInstance._Store.SDKConfig.flags[feature];
|
|
@@ -3844,25 +3996,6 @@ var mParticle = (function () {
|
|
|
3844
3996
|
return target;
|
|
3845
3997
|
};
|
|
3846
3998
|
|
|
3847
|
-
this.isObject = function (value) {
|
|
3848
|
-
var objType = Object.prototype.toString.call(value);
|
|
3849
|
-
return objType === '[object Object]' || objType === '[object Error]';
|
|
3850
|
-
};
|
|
3851
|
-
|
|
3852
|
-
this.inArray = function (items, name) {
|
|
3853
|
-
var i = 0;
|
|
3854
|
-
|
|
3855
|
-
if (Array.prototype.indexOf) {
|
|
3856
|
-
return items.indexOf(name, 0) >= 0;
|
|
3857
|
-
} else {
|
|
3858
|
-
for (var n = items.length; i < n; i++) {
|
|
3859
|
-
if (i in items && items[i] === name) {
|
|
3860
|
-
return true;
|
|
3861
|
-
}
|
|
3862
|
-
}
|
|
3863
|
-
}
|
|
3864
|
-
};
|
|
3865
|
-
|
|
3866
3999
|
this.createServiceUrl = function (secureServiceUrl, devToken) {
|
|
3867
4000
|
var serviceScheme = window.mParticle && mpInstance._Store.SDKConfig.forceHttps ? 'https://' : window.location.protocol + '//';
|
|
3868
4001
|
var baseUrl;
|
|
@@ -3998,30 +4131,6 @@ var mParticle = (function () {
|
|
|
3998
4131
|
return filteredUserAttributes;
|
|
3999
4132
|
};
|
|
4000
4133
|
|
|
4001
|
-
this.findKeyInObject = function (obj, key) {
|
|
4002
|
-
if (key && obj) {
|
|
4003
|
-
for (var prop in obj) {
|
|
4004
|
-
if (obj.hasOwnProperty(prop) && prop.toLowerCase() === key.toLowerCase()) {
|
|
4005
|
-
return prop;
|
|
4006
|
-
}
|
|
4007
|
-
}
|
|
4008
|
-
}
|
|
4009
|
-
|
|
4010
|
-
return null;
|
|
4011
|
-
};
|
|
4012
|
-
|
|
4013
|
-
this.decoded = function (s) {
|
|
4014
|
-
return decodeURIComponent(s.replace(pluses, ' '));
|
|
4015
|
-
};
|
|
4016
|
-
|
|
4017
|
-
this.converted = function (s) {
|
|
4018
|
-
if (s.indexOf('"') === 0) {
|
|
4019
|
-
s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
|
|
4020
|
-
}
|
|
4021
|
-
|
|
4022
|
-
return s;
|
|
4023
|
-
};
|
|
4024
|
-
|
|
4025
4134
|
this.isEventType = function (type) {
|
|
4026
4135
|
for (var prop in Types.EventType) {
|
|
4027
4136
|
if (Types.EventType.hasOwnProperty(prop)) {
|
|
@@ -4034,17 +4143,8 @@ var mParticle = (function () {
|
|
|
4034
4143
|
return false;
|
|
4035
4144
|
};
|
|
4036
4145
|
|
|
4037
|
-
this.parseNumber = function (value) {
|
|
4038
|
-
if (isNaN(value) || !isFinite(value)) {
|
|
4039
|
-
return 0;
|
|
4040
|
-
}
|
|
4041
|
-
|
|
4042
|
-
var floatValue = parseFloat(value);
|
|
4043
|
-
return isNaN(floatValue) ? 0 : floatValue;
|
|
4044
|
-
};
|
|
4045
|
-
|
|
4046
4146
|
this.parseStringOrNumber = function (value) {
|
|
4047
|
-
if (
|
|
4147
|
+
if (Validators.isStringOrNumber(value)) {
|
|
4048
4148
|
return value;
|
|
4049
4149
|
} else {
|
|
4050
4150
|
return null;
|
|
@@ -4101,104 +4201,6 @@ var mParticle = (function () {
|
|
|
4101
4201
|
return sanitizedAttrs;
|
|
4102
4202
|
};
|
|
4103
4203
|
|
|
4104
|
-
this.Validators = {
|
|
4105
|
-
isValidAttributeValue: function isValidAttributeValue(value) {
|
|
4106
|
-
return value !== undefined && !self.isObject(value) && !Array.isArray(value);
|
|
4107
|
-
},
|
|
4108
|
-
// Neither null nor undefined can be a valid Key
|
|
4109
|
-
isValidKeyValue: function isValidKeyValue(key) {
|
|
4110
|
-
return Boolean(key && !self.isObject(key) && !Array.isArray(key));
|
|
4111
|
-
},
|
|
4112
|
-
isStringOrNumber: function isStringOrNumber(value) {
|
|
4113
|
-
return typeof value === 'string' || typeof value === 'number';
|
|
4114
|
-
},
|
|
4115
|
-
isNumber: function isNumber(value) {
|
|
4116
|
-
return typeof value === 'number';
|
|
4117
|
-
},
|
|
4118
|
-
isFunction: function isFunction(fn) {
|
|
4119
|
-
return typeof fn === 'function';
|
|
4120
|
-
},
|
|
4121
|
-
validateIdentities: function validateIdentities(identityApiData, method) {
|
|
4122
|
-
var validIdentityRequestKeys = {
|
|
4123
|
-
userIdentities: 1,
|
|
4124
|
-
onUserAlias: 1,
|
|
4125
|
-
copyUserAttributes: 1
|
|
4126
|
-
};
|
|
4127
|
-
|
|
4128
|
-
if (identityApiData) {
|
|
4129
|
-
if (method === 'modify') {
|
|
4130
|
-
if (self.isObject(identityApiData.userIdentities) && !Object.keys(identityApiData.userIdentities).length || !self.isObject(identityApiData.userIdentities)) {
|
|
4131
|
-
return {
|
|
4132
|
-
valid: false,
|
|
4133
|
-
error: Constants.Messages.ValidationMessages.ModifyIdentityRequestUserIdentitiesPresent
|
|
4134
|
-
};
|
|
4135
|
-
}
|
|
4136
|
-
}
|
|
4137
|
-
|
|
4138
|
-
for (var key in identityApiData) {
|
|
4139
|
-
if (identityApiData.hasOwnProperty(key)) {
|
|
4140
|
-
if (!validIdentityRequestKeys[key]) {
|
|
4141
|
-
return {
|
|
4142
|
-
valid: false,
|
|
4143
|
-
error: Constants.Messages.ValidationMessages.IdentityRequesetInvalidKey
|
|
4144
|
-
};
|
|
4145
|
-
}
|
|
4146
|
-
|
|
4147
|
-
if (key === 'onUserAlias' && !mpInstance._Helpers.Validators.isFunction(identityApiData[key])) {
|
|
4148
|
-
return {
|
|
4149
|
-
valid: false,
|
|
4150
|
-
error: Constants.Messages.ValidationMessages.OnUserAliasType + _typeof_1(identityApiData[key])
|
|
4151
|
-
};
|
|
4152
|
-
}
|
|
4153
|
-
}
|
|
4154
|
-
}
|
|
4155
|
-
|
|
4156
|
-
if (Object.keys(identityApiData).length === 0) {
|
|
4157
|
-
return {
|
|
4158
|
-
valid: true
|
|
4159
|
-
};
|
|
4160
|
-
} else {
|
|
4161
|
-
// identityApiData.userIdentities can't be undefined
|
|
4162
|
-
if (identityApiData.userIdentities === undefined) {
|
|
4163
|
-
return {
|
|
4164
|
-
valid: false,
|
|
4165
|
-
error: Constants.Messages.ValidationMessages.UserIdentities
|
|
4166
|
-
}; // identityApiData.userIdentities can be null, but if it isn't null or undefined (above conditional), it must be an object
|
|
4167
|
-
} else if (identityApiData.userIdentities !== null && !self.isObject(identityApiData.userIdentities)) {
|
|
4168
|
-
return {
|
|
4169
|
-
valid: false,
|
|
4170
|
-
error: Constants.Messages.ValidationMessages.UserIdentities
|
|
4171
|
-
};
|
|
4172
|
-
}
|
|
4173
|
-
|
|
4174
|
-
if (self.isObject(identityApiData.userIdentities) && Object.keys(identityApiData.userIdentities).length) {
|
|
4175
|
-
for (var identityType in identityApiData.userIdentities) {
|
|
4176
|
-
if (identityApiData.userIdentities.hasOwnProperty(identityType)) {
|
|
4177
|
-
if (Types.IdentityType.getIdentityType(identityType) === false) {
|
|
4178
|
-
return {
|
|
4179
|
-
valid: false,
|
|
4180
|
-
error: Constants.Messages.ValidationMessages.UserIdentitiesInvalidKey
|
|
4181
|
-
};
|
|
4182
|
-
}
|
|
4183
|
-
|
|
4184
|
-
if (!(typeof identityApiData.userIdentities[identityType] === 'string' || identityApiData.userIdentities[identityType] === null)) {
|
|
4185
|
-
return {
|
|
4186
|
-
valid: false,
|
|
4187
|
-
error: Constants.Messages.ValidationMessages.UserIdentitiesInvalidValues
|
|
4188
|
-
};
|
|
4189
|
-
}
|
|
4190
|
-
}
|
|
4191
|
-
}
|
|
4192
|
-
}
|
|
4193
|
-
}
|
|
4194
|
-
}
|
|
4195
|
-
|
|
4196
|
-
return {
|
|
4197
|
-
valid: true
|
|
4198
|
-
};
|
|
4199
|
-
}
|
|
4200
|
-
};
|
|
4201
|
-
|
|
4202
4204
|
this.isDelayedByIntegration = function (delayedIntegrations, timeoutStart, now) {
|
|
4203
4205
|
if (now - timeoutStart > mpInstance._Store.SDKConfig.integrationDelayTimeout) {
|
|
4204
4206
|
return false;
|
|
@@ -4233,7 +4235,18 @@ var mParticle = (function () {
|
|
|
4233
4235
|
|
|
4234
4236
|
this.isSlug = function (str) {
|
|
4235
4237
|
return str === slugify(str);
|
|
4236
|
-
};
|
|
4238
|
+
}; // Utility Functions
|
|
4239
|
+
|
|
4240
|
+
|
|
4241
|
+
this.converted = converted;
|
|
4242
|
+
this.findKeyInObject = findKeyInObject;
|
|
4243
|
+
this.parseNumber = parseNumber;
|
|
4244
|
+
this.inArray = inArray;
|
|
4245
|
+
this.isObject = isObject;
|
|
4246
|
+
this.decoded = decoded;
|
|
4247
|
+
this.returnConvertedBoolean = returnConvertedBoolean; // Imported Validators
|
|
4248
|
+
|
|
4249
|
+
this.Validators = Validators;
|
|
4237
4250
|
}
|
|
4238
4251
|
|
|
4239
4252
|
var Messages$1 = Constants.Messages;
|
|
@@ -5284,6 +5297,10 @@ var mParticle = (function () {
|
|
|
5284
5297
|
this.SDKConfig.appName = config.appName;
|
|
5285
5298
|
}
|
|
5286
5299
|
|
|
5300
|
+
if (config.hasOwnProperty('package')) {
|
|
5301
|
+
this.SDKConfig["package"] = config["package"];
|
|
5302
|
+
}
|
|
5303
|
+
|
|
5287
5304
|
if (config.hasOwnProperty('integrationDelayTimeout')) {
|
|
5288
5305
|
this.SDKConfig.integrationDelayTimeout = config.integrationDelayTimeout;
|
|
5289
5306
|
} else {
|
|
@@ -5374,6 +5391,16 @@ var mParticle = (function () {
|
|
|
5374
5391
|
}
|
|
5375
5392
|
}
|
|
5376
5393
|
|
|
5394
|
+
if (config.hasOwnProperty('onCreateBatch')) {
|
|
5395
|
+
if (typeof config.onCreateBatch === 'function') {
|
|
5396
|
+
this.SDKConfig.onCreateBatch = config.onCreateBatch;
|
|
5397
|
+
} else {
|
|
5398
|
+
mpInstance.Logger.error('config.onCreateBatch must be a function'); // set to undefined because all items are set on createSDKConfig
|
|
5399
|
+
|
|
5400
|
+
this.SDKConfig.onCreateBatch = undefined;
|
|
5401
|
+
}
|
|
5402
|
+
}
|
|
5403
|
+
|
|
5377
5404
|
if (!config.hasOwnProperty('flags')) {
|
|
5378
5405
|
this.SDKConfig.flags = {};
|
|
5379
5406
|
}
|
|
@@ -7674,6 +7701,7 @@ var mParticle = (function () {
|
|
|
7674
7701
|
ExpandedEventCount: 0,
|
|
7675
7702
|
AppVersion: mpInstance.getAppVersion(),
|
|
7676
7703
|
AppName: mpInstance.getAppName(),
|
|
7704
|
+
Package: mpInstance._Store.SDKConfig["package"],
|
|
7677
7705
|
ClientGeneratedId: mpInstance._Store.clientId,
|
|
7678
7706
|
DeviceId: mpInstance._Store.deviceId,
|
|
7679
7707
|
IntegrationAttributes: mpInstance._Store.integrationAttributes,
|
|
@@ -11187,6 +11215,12 @@ var mParticle = (function () {
|
|
|
11187
11215
|
|
|
11188
11216
|
if (config.flags) {
|
|
11189
11217
|
if (config.flags.hasOwnProperty(Constants.FeatureFlags.EventsV3)) {
|
|
11218
|
+
// TODO: Remove this after 8/12/2022
|
|
11219
|
+
if (config.flags[Constants.FeatureFlags.EventsV3] !== '100') {
|
|
11220
|
+
var message = 'mParticle will be enabling Event Batching for all customers on July 12, 2022. ' + 'For more details, please see our docs: https://docs.mparticle.com/developers/sdk/web/getting-started/';
|
|
11221
|
+
mpInstance.Logger.warning(message);
|
|
11222
|
+
}
|
|
11223
|
+
|
|
11190
11224
|
mpInstance._Store.SDKConfig.flags[Constants.FeatureFlags.EventsV3] = config.flags[Constants.FeatureFlags.EventsV3];
|
|
11191
11225
|
}
|
|
11192
11226
|
|