@mparticle/web-sdk
Advanced tools
Comparing version 2.19.0 to 2.19.1
{ | ||
"name": "@mparticle/web-sdk", | ||
"version": "2.19.0", | ||
"version": "2.19.1", | ||
"description": "mParticle core SDK for web applications", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0", |
@@ -192,3 +192,3 @@ import Constants from './constants'; | ||
JSON.stringify( | ||
mpInstance._ServerModel.convertEventToDTO( | ||
mpInstance._ServerModel.convertEventToV2DTO( | ||
event as IUploadObject | ||
@@ -195,0 +195,0 @@ ) |
@@ -7,3 +7,6 @@ import Constants from './constants'; | ||
var self = this; | ||
// Public | ||
this.attemptCookieSync = function(previousMPID, mpid, mpidIsNotInCookies) { | ||
// TODO: These should move inside the for loop | ||
var pixelConfig, | ||
@@ -16,2 +19,3 @@ lastSyncDateForModule, | ||
// TODO: Make this exit quicker instead of nested | ||
if (mpid && !mpInstance._Store.webviewBridgeEnabled) { | ||
@@ -25,2 +29,3 @@ mpInstance._Store.pixelConfigurations.forEach(function( | ||
// TODO: Replace with isEmpty | ||
if ( | ||
@@ -33,9 +38,19 @@ pixelSettings.filteringConsentRuleValues && | ||
} | ||
pixelConfig = { | ||
// Kit Module ID | ||
moduleId: pixelSettings.moduleId, | ||
// Tells you how often we should do a cookie sync (in days) | ||
frequencyCap: pixelSettings.frequencyCap, | ||
// Url for cookie sync pixel | ||
pixelUrl: self.replaceAmp(pixelSettings.pixelUrl), | ||
// TODO: Document requirements for redirectUrl | ||
redirectUrl: pixelSettings.redirectUrl | ||
? self.replaceAmp(pixelSettings.redirectUrl) | ||
: null, | ||
// Filtering rules as defined in UI | ||
filteringConsentRuleValues: | ||
@@ -45,2 +60,3 @@ pixelSettings.filteringConsentRuleValues, | ||
// TODO: combine replaceMPID and replaceAmp into sanitizeUrl function | ||
url = self.replaceMPID(pixelConfig.pixelUrl, mpid); | ||
@@ -51,4 +67,9 @@ redirect = pixelConfig.redirectUrl | ||
urlWithRedirect = url + encodeURIComponent(redirect); | ||
// TODO: Refactor so that Persistence is only called once | ||
// outside of the loop | ||
var persistence = mpInstance._Persistence.getPersistence(); | ||
// TODO: Is there a historic reason for checking for previousMPID? | ||
// it does not appear to be passed in anywhere | ||
if (previousMPID && previousMPID !== mpid) { | ||
@@ -71,2 +92,4 @@ if (persistence && persistence[mpid]) { | ||
} else { | ||
// TODO: Refactor to check for the inverse and exit early | ||
// rather than nesting | ||
if (persistence[mpid]) { | ||
@@ -87,5 +110,10 @@ if (!persistence[mpid].csd) { | ||
if ( | ||
// TODO: Turn this into a convenience method for readability? | ||
// We use similar comparisons elsewhere in the SDK, | ||
// so perhaps we can make a time comparison convenience method | ||
new Date().getTime() > | ||
new Date(lastSyncDateForModule).getTime() + | ||
pixelConfig.frequencyCap * | ||
// TODO: Turn these numbers into a constant so | ||
// we can remember what this number is for | ||
60 * | ||
@@ -123,2 +151,3 @@ 1000 * | ||
// Private | ||
this.replaceMPID = function(string, mpid) { | ||
@@ -128,2 +157,4 @@ return string.replace('%%mpid%%', mpid); | ||
// Private | ||
// TODO: Rename function to replaceAmpWithAmpersand | ||
this.replaceAmp = function(string) { | ||
@@ -133,2 +164,3 @@ return string.replace(/&/g, '&'); | ||
// Private | ||
this.performCookieSync = function( | ||
@@ -146,5 +178,12 @@ url, | ||
// we should not check if its enabled if the user has a blank consent | ||
// TODO: We should do this check outside of this function | ||
if (requiresConsent && mpidIsNotInCookies) { | ||
return; | ||
} | ||
// TODO: Refactor so that check is made outside of the function. | ||
// Cache or store the boolean so that it only gets called once per | ||
// cookie sync attempt per module. | ||
// Currently, attemptCookieSync is called as a loop and therefore this | ||
// function polls the user object and consent multiple times. | ||
if ( | ||
@@ -160,2 +199,3 @@ mpInstance._Consent.isEnabledForUserConsent( | ||
img.onload = function() { | ||
// TODO: Break this out into a convenience method so we can unit test | ||
cookieSyncDates[moduleId.toString()] = new Date().getTime(); | ||
@@ -162,0 +202,0 @@ mpInstance._Persistence.saveUserCookieSyncDatesToPersistence( |
@@ -18,2 +18,5 @@ // This file is used ONLY for the mParticle ESLint plugin. It should NOT be used otherwise! | ||
window.mParticle.getInstance()._Helpers.sanitizeAttributes, | ||
generateHash: function () { | ||
return 'mockHash'; | ||
}, | ||
generateUniqueId: function () { | ||
@@ -20,0 +23,0 @@ return 'mockId'; |
@@ -9,3 +9,3 @@ import * as EventsApi from '@mparticle/event-models'; | ||
import { IKitConfigs } from './configAPIClient'; | ||
import { SDKConsentApi, SDKConsentState } from './consent.interfaces'; | ||
import { SDKConsentApi, SDKConsentState } from './consent'; | ||
@@ -163,3 +163,3 @@ // TODO: Resolve this with version in @mparticle/web-sdk | ||
ProductActionType: SDKProductActionType; | ||
generateHash(value: string); | ||
generateHash(value: string): string; | ||
isIOS?: boolean; | ||
@@ -233,2 +233,3 @@ } | ||
generateUniqueId(); | ||
generateHash?(value: string): string; | ||
getFeatureFlag?(feature: string); // TODO: Feature Constants should be converted to enum | ||
@@ -277,3 +278,3 @@ getRampNumber?(deviceId: string): number; | ||
getMPID(): string; | ||
getConsentState(): any; // FIXME: | ||
getConsentState(): SDKConsentState; | ||
getAllUserAttributes(): any; // FIXME; | ||
@@ -280,0 +281,0 @@ getUserIdentities(): IdentityApiData; // FIXME: Is this correct? |
@@ -16,3 +16,3 @@ import { | ||
SDKCCPAConsentState, | ||
} from './consent.interfaces'; | ||
} from './consent'; | ||
import Types from './types'; | ||
@@ -19,0 +19,0 @@ import { isEmpty } from './utils'; |
@@ -20,7 +20,7 @@ // TODO: This file is no longer the server model because the web SDK payload | ||
import { | ||
IConsentStateDTO, | ||
IGDPRConsentStateDTO, | ||
IConsentStateV2DTO, | ||
IGDPRConsentStateV2DTO, | ||
IPrivacyV2DTO, | ||
SDKConsentState, | ||
} from './consent.interfaces'; | ||
} from './consent'; | ||
@@ -31,3 +31,3 @@ const MessageType = Types.MessageType; | ||
// TODO: Confirm which attributes are optional | ||
export interface IServerDTO { | ||
export interface IServerV2DTO { | ||
id: string | number; | ||
@@ -66,3 +66,3 @@ nm: string | number; | ||
smpids?: MPID[]; | ||
con?: IConsentStateDTO; | ||
con?: IConsentStateV2DTO; | ||
fr?: boolean; | ||
@@ -75,3 +75,3 @@ iu?: boolean; // isUpgrade | ||
sc?: { | ||
pl: IProductDTO[]; | ||
pl: IProductV2DTO[]; | ||
}; | ||
@@ -82,3 +82,3 @@ pd?: { | ||
co: string; | ||
pl: IProductDTO[]; | ||
pl: IProductV2DTO[]; | ||
ta: string; | ||
@@ -93,9 +93,9 @@ ti: string; | ||
an: string; | ||
pl: IPromotionDTO[]; | ||
pl: IPromotionV2DTO[]; | ||
}; | ||
pi?: IProductImpressionDTO[]; | ||
pi?: IProductImpressionV2DTO[]; | ||
pet?: number; | ||
} | ||
export interface IProductDTO { | ||
export interface IProductV2DTO { | ||
id: string | number; | ||
@@ -114,3 +114,3 @@ nm: string | number; | ||
export interface IPromotionDTO { | ||
export interface IPromotionV2DTO { | ||
id: string | number; | ||
@@ -122,5 +122,5 @@ nm: string | number; | ||
export interface IProductImpressionDTO { | ||
export interface IProductImpressionV2DTO { | ||
pil: string; | ||
pl: IProductDTO[]; | ||
pl: IProductV2DTO[]; | ||
} | ||
@@ -140,5 +140,5 @@ | ||
export interface IServerModel { | ||
convertEventToDTO: (event: IUploadObject) => IServerDTO; | ||
convertEventToV2DTO: (event: IUploadObject) => IServerV2DTO; | ||
createEventObject: (event: BaseEvent, user?: MParticleUser) => SDKEvent; | ||
convertToConsentStateDTO: (state: SDKConsentState) => IConsentStateDTO; | ||
convertToConsentStateV2DTO: (state: SDKConsentState) => IConsentStateV2DTO; | ||
appendUserInfo: (user: MParticleUser, event: SDKEvent) => void; | ||
@@ -148,3 +148,3 @@ } | ||
// TODO: Make this a pure function that returns a new object | ||
function convertCustomFlags(event: SDKEvent, dto: IServerDTO) { | ||
function convertCustomFlags(event: SDKEvent, dto: IServerV2DTO) { | ||
var valueArray: string[] = []; | ||
@@ -184,3 +184,3 @@ dto.flags = {}; | ||
function convertProductToDTO(product: SDKProduct): IProductDTO { | ||
function convertProductToV2DTO(product: SDKProduct): IProductV2DTO { | ||
return { | ||
@@ -201,3 +201,3 @@ id: parseStringOrNumber(product.Sku), | ||
function convertProductListToDTO(productList: SDKProduct[]): IProductDTO[] { | ||
function convertProductListToV2DTO(productList: SDKProduct[]): IProductV2DTO[] { | ||
if (!productList) { | ||
@@ -208,3 +208,3 @@ return []; | ||
return productList.map(function(product) { | ||
return convertProductToDTO(product); | ||
return convertProductToV2DTO(product); | ||
}); | ||
@@ -261,12 +261,12 @@ } | ||
this.convertToConsentStateDTO = function( | ||
this.convertToConsentStateV2DTO = function( | ||
state: SDKConsentState | ||
): IConsentStateDTO { | ||
): IConsentStateV2DTO { | ||
if (!state) { | ||
return null; | ||
} | ||
var jsonObject: IConsentStateDTO = {}; | ||
var jsonObject: IConsentStateV2DTO = {}; | ||
var gdprConsentState = state.getGDPRConsentState(); | ||
if (gdprConsentState) { | ||
var gdpr: IGDPRConsentStateDTO = {}; | ||
var gdpr: IGDPRConsentStateV2DTO = {}; | ||
jsonObject.gdpr = gdpr; | ||
@@ -309,3 +309,3 @@ for (var purpose in gdprConsentState) { | ||
return jsonObject as IConsentStateDTO; | ||
return jsonObject as IConsentStateV2DTO; | ||
}; | ||
@@ -426,4 +426,4 @@ | ||
this.convertEventToDTO = function(event: IUploadObject): IServerDTO { | ||
var dto: Partial<IServerDTO> = { | ||
this.convertEventToV2DTO = function(event: IUploadObject): IServerV2DTO { | ||
var dto: Partial<IServerV2DTO> = { | ||
n: event.EventName, | ||
@@ -460,3 +460,3 @@ et: event.EventCategory, | ||
var consent = self.convertToConsentStateDTO(event.ConsentState); | ||
var consent = self.convertToConsentStateV2DTO(event.ConsentState); | ||
if (consent) { | ||
@@ -478,3 +478,3 @@ dto.con = consent; | ||
if (event.CustomFlags) { | ||
convertCustomFlags(event, dto as IServerDTO); | ||
convertCustomFlags(event, dto as IServerV2DTO); | ||
} | ||
@@ -488,3 +488,5 @@ | ||
dto.sc = { | ||
pl: convertProductListToDTO(event.ShoppingCart.ProductList), | ||
pl: convertProductListToV2DTO( | ||
event.ShoppingCart.ProductList | ||
), | ||
}; | ||
@@ -500,3 +502,3 @@ } | ||
co: event.ProductAction.CheckoutOptions, | ||
pl: convertProductListToDTO( | ||
pl: convertProductListToV2DTO( | ||
event.ProductAction.ProductList | ||
@@ -535,3 +537,3 @@ ), | ||
pil: impression.ProductImpressionList, | ||
pl: convertProductListToDTO(impression.ProductList), | ||
pl: convertProductListToV2DTO(impression.ProductList), | ||
}; | ||
@@ -544,4 +546,4 @@ }); | ||
return dto as IServerDTO; | ||
return dto as IServerV2DTO; | ||
}; | ||
} |
@@ -26,3 +26,3 @@ import { Batch } from '@mparticle/event-models'; | ||
import { isNumber, isDataPlanSlug, Dictionary } from './utils'; | ||
import { SDKConsentState } from './consent.interfaces'; | ||
import { SDKConsentState } from './consent'; | ||
@@ -223,5 +223,6 @@ // This represents the runtime configuration of the SDK AFTER | ||
if (config.hasOwnProperty('isDevelopmentMode')) { | ||
this.SDKConfig.isDevelopmentMode = mpInstance._Helpers.returnConvertedBoolean( | ||
config.isDevelopmentMode | ||
); | ||
this.SDKConfig.isDevelopmentMode = | ||
mpInstance._Helpers.returnConvertedBoolean( | ||
config.isDevelopmentMode | ||
); | ||
} else { | ||
@@ -228,0 +229,0 @@ this.SDKConfig.isDevelopmentMode = false; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1446629
25600
39