Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ const Constants = {
platform: 'web',
Messages: {
DeprecationMessages: {
MethodIsDeprecatedPostfix:
'is a deprecated method and will be removed in future releases',
MethodHasBeenDeprecated: 'has been deprecated.',
MethodMarkedForDeprecationPostfix:
'is a deprecated method and will be removed in future releases.',
AlternativeMethodPrefix: 'Please use the alternate method:',
},
ErrorMessages: {
Expand Down Expand Up @@ -232,11 +233,10 @@ export const HTTP_SERVER_ERROR = 500 as const;

export type PrivacyControl = 'functional' | 'targeting';

export type StorageTypes = 'SDKState' | 'Products' | 'OfflineEvents' | 'IdentityCache' | 'TimeOnSite';
export type StorageTypes = 'SDKState' | 'OfflineEvents' | 'IdentityCache' | 'TimeOnSite';

export const StoragePrivacyMap: Record<StorageTypes, PrivacyControl> = {
SDKState: 'functional',
Products: 'targeting',
OfflineEvents: 'functional',
IdentityCache: 'functional',
TimeOnSite: 'targeting',
Expand Down
10 changes: 0 additions & 10 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,16 +376,6 @@ export default function Helpers(mpInstance) {
}
};

this.createProductStorageName = function(workspaceToken) {
if (workspaceToken) {
return (
StorageNames.currentStorageProductsName + '_' + workspaceToken
);
} else {
return StorageNames.currentStorageProductsName;
}
};

// TODO: Refactor SDK to directly use these methods
// https://go.mparticle.com/work/SQDSDKS-5239
// Utility Functions
Expand Down
4 changes: 2 additions & 2 deletions src/identity-user-interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ export interface IdentityModifyResultBody {
}

export interface mParticleUserCart {
add(product: SDKProduct | SDKProduct[], logEvent: boolean): void;
remove(product: SDKProduct | SDKProduct[], logEvent: boolean): void;
add(): void;
remove(): void;
clear(): void;
getCartProducts(): SDKProduct[];
}
Expand Down
2 changes: 1 addition & 1 deletion src/identity.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,5 +206,5 @@ export interface IIdentity {
/**
* @deprecated
*/
mParticleUserCart(mpid: MPID): mParticleUserCart;
mParticleUserCart(): mParticleUserCart;
}
167 changes: 29 additions & 138 deletions src/identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,7 @@ export default function Identity(mpInstance) {
mpInstance.Logger.warning(
'Deprecated function Identity.getCurrentUser().getCart() will be removed in future releases'
);
return self.mParticleUserCart(mpid);
return self.mParticleUserCart();
},

/**
Expand Down Expand Up @@ -1286,133 +1286,37 @@ export default function Identity(mpInstance) {
* @class mParticle.Identity.getCurrentUser().getCart()
* @deprecated
*/
this.mParticleUserCart = function(mpid) {
this.mParticleUserCart = function() {
return {
/**
* Adds a cart product to the user cart
* @method add
* @param {Object} product the product
* @param {Boolean} [logEvent] a boolean to log adding of the cart object. If blank, no logging occurs.
* @deprecated
*/
add: function(product, logEvent) {
add: function() {
mpInstance.Logger.warning(
'Deprecated function Identity.getCurrentUser().getCart().add() will be removed in future releases'
generateDeprecationMessage(
'Identity.getCurrentUser().getCart().add()',
true,
'eCommerce.logProductAction()',
'https://docs.mparticle.com/developers/sdk/web/commerce-tracking'
)
);
var allProducts, userProducts, arrayCopy;

arrayCopy = Array.isArray(product)
? product.slice()
: [product];
arrayCopy.forEach(function(product) {
product.Attributes = mpInstance._Helpers.sanitizeAttributes(
product.Attributes
);
});

if (mpInstance._Store.webviewBridgeEnabled) {
mpInstance._NativeSdkHelpers.sendToNative(
Constants.NativeSdkPaths.AddToCart,
JSON.stringify(arrayCopy)
);
} else {
mpInstance._SessionManager.resetSessionTimer();

userProducts = mpInstance._Persistence.getUserProductsFromLS(
mpid
);

userProducts = userProducts.concat(arrayCopy);

if (logEvent === true) {
mpInstance._Events.logProductActionEvent(
Types.ProductActionType.AddToCart,
arrayCopy
);
}

var productsForMemory = {};
productsForMemory[mpid] = { cp: userProducts };

if (
userProducts.length >
mpInstance._Store.SDKConfig.maxProducts
) {
mpInstance.Logger.verbose(
'The cart contains ' +
userProducts.length +
' items. Only ' +
mpInstance._Store.SDKConfig.maxProducts +
' can currently be saved in cookies.'
);
userProducts = userProducts.slice(
-mpInstance._Store.SDKConfig.maxProducts
);
}

allProducts = mpInstance._Persistence.getAllUserProductsFromLS();
allProducts[mpid].cp = userProducts;

mpInstance._Persistence.setCartProducts(allProducts);
}
},
/**
* Removes a cart product from the current user cart
* @method remove
* @param {Object} product the product
* @param {Boolean} [logEvent] a boolean to log adding of the cart object. If blank, no logging occurs.
* @deprecated
*/
remove: function(product, logEvent) {
remove: function() {
mpInstance.Logger.warning(
'Deprecated function Identity.getCurrentUser().getCart().remove() will be removed in future releases'
generateDeprecationMessage(
'Identity.getCurrentUser().getCart().remove()',
true,
'eCommerce.logProductAction()',
'https://docs.mparticle.com/developers/sdk/web/commerce-tracking'
)
);
var allProducts,
userProducts,
cartIndex = -1,
cartItem = null;

if (mpInstance._Store.webviewBridgeEnabled) {
mpInstance._NativeSdkHelpers.sendToNative(
Constants.NativeSdkPaths.RemoveFromCart,
JSON.stringify(product)
);
} else {
mpInstance._SessionManager.resetSessionTimer();

userProducts = mpInstance._Persistence.getUserProductsFromLS(
mpid
);

if (userProducts) {
userProducts.forEach(function(cartProduct, i) {
if (cartProduct.Sku === product.Sku) {
cartIndex = i;
cartItem = cartProduct;
}
});

if (cartIndex > -1) {
userProducts.splice(cartIndex, 1);

if (logEvent === true) {
mpInstance._Events.logProductActionEvent(
Types.ProductActionType.RemoveFromCart,
cartItem
);
}
}
}

var productsForMemory = {};
productsForMemory[mpid] = { cp: userProducts };

allProducts = mpInstance._Persistence.getAllUserProductsFromLS();

allProducts[mpid].cp = userProducts;

mpInstance._Persistence.setCartProducts(allProducts);
}
},
/**
* Clears the user's cart
Expand All @@ -1421,31 +1325,13 @@ export default function Identity(mpInstance) {
*/
clear: function() {
mpInstance.Logger.warning(
'Deprecated function Identity.getCurrentUser().getCart().clear() will be removed in future releases'
generateDeprecationMessage(
'Identity.getCurrentUser().getCart().clear()',
true,
'',
'https://docs.mparticle.com/developers/sdk/web/commerce-tracking'
)
);

var allProducts;

if (mpInstance._Store.webviewBridgeEnabled) {
mpInstance._NativeSdkHelpers.sendToNative(
Constants.NativeSdkPaths.ClearCart
);
} else {
mpInstance._SessionManager.resetSessionTimer();
allProducts = mpInstance._Persistence.getAllUserProductsFromLS();

if (
allProducts &&
allProducts[mpid] &&
allProducts[mpid].cp
) {
allProducts[mpid].cp = [];

allProducts[mpid].cp = [];

mpInstance._Persistence.setCartProducts(allProducts);
}
}
},
/**
* Returns all cart products
Expand All @@ -1455,9 +1341,14 @@ export default function Identity(mpInstance) {
*/
getCartProducts: function() {
mpInstance.Logger.warning(
'Deprecated function Identity.getCurrentUser().getCart().getCartProducts() will be removed in future releases'
generateDeprecationMessage(
'Identity.getCurrentUser().getCart().getCartProducts()',
true,
'eCommerce.logProductAction()',
'https://docs.mparticle.com/developers/sdk/web/commerce-tracking'
)
);
return mpInstance._Persistence.getCartProducts(mpid);
return [];
},
};
};
Expand Down
45 changes: 19 additions & 26 deletions src/mp-instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import Consent, { IConsent } from './consent';
import KitBlocker from './kitBlocking';
import ConfigAPIClient, { IKitConfigs } from './configAPIClient';
import IdentityAPIClient from './identityApiClient';
import { isFunction, parseConfig, valueof } from './utils';
import { isFunction, parseConfig, valueof, generateDeprecationMessage } from './utils';
import { DisabledVault, LocalStorageVault } from './vault';
import { removeExpiredIdentityCacheDates } from './identity-utils';
import IntegrationCapture from './integrationCapture';
Expand Down Expand Up @@ -706,16 +706,13 @@ export default function mParticleInstance(this: IMParticleWebSDKInstance, instan
*/
add: function(product, logEventBoolean) {
self.Logger.warning(
'Deprecated function eCommerce.Cart.add() will be removed in future releases'
generateDeprecationMessage(
'eCommerce.Cart.add()',
true,
'eCommerce.logProductAction()',
'https://docs.mparticle.com/developers/sdk/web/commerce-tracking'
)
);
let mpid;
const currentUser = self.Identity.getCurrentUser();
if (currentUser) {
mpid = currentUser.getMPID();
}
self._Identity
.mParticleUserCart(mpid)
.add(product, logEventBoolean);
},
/**
* Removes a product from the cart
Expand All @@ -726,16 +723,13 @@ export default function mParticleInstance(this: IMParticleWebSDKInstance, instan
*/
remove: function(product, logEventBoolean) {
self.Logger.warning(
'Deprecated function eCommerce.Cart.remove() will be removed in future releases'
generateDeprecationMessage(
'eCommerce.Cart.remove()',
true,
'eCommerce.logProductAction()',
'https://docs.mparticle.com/developers/sdk/web/commerce-tracking'
)
);
let mpid;
const currentUser = self.Identity.getCurrentUser();
if (currentUser) {
mpid = currentUser.getMPID();
}
self._Identity
.mParticleUserCart(mpid)
.remove(product, logEventBoolean);
},
/**
* Clears the cart
Expand All @@ -744,14 +738,13 @@ export default function mParticleInstance(this: IMParticleWebSDKInstance, instan
*/
clear: function() {
self.Logger.warning(
'Deprecated function eCommerce.Cart.clear() will be removed in future releases'
generateDeprecationMessage(
'eCommerce.Cart.clear()',
true,
'',
'https://docs.mparticle.com/developers/sdk/web/commerce-tracking'
)
);
let mpid;
const currentUser = self.Identity.getCurrentUser();
if (currentUser) {
mpid = currentUser.getMPID();
}
self._Identity.mParticleUserCart(mpid).clear();
},
},
/**
Expand Down
5 changes: 0 additions & 5 deletions src/persistence.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,8 @@ export interface IPersistence {
useLocalStorage(): boolean;
initializeStorage(): void;
update(): void;
storeProductsInMemory(products: Product[], mpid: MPID): void;
storeDataInMemory(obj: IPersistenceMinified, currentMPID: MPID): void;
determineLocalStorageAvailability(storage: Storage): boolean;
getUserProductsFromLS(mpid: MPID): Product[];
getAllUserProductsFromLS(): Product[];
setLocalStorage(): void;
getLocalStorage(): IPersistenceMinified | null;
expireCookies(cookieName: string): void;
Expand All @@ -120,8 +117,6 @@ export interface IPersistence {
decodePersistence(persistenceString: string): string;
getCookieDomain(): string;
getDomain(doc: string, locationHostname: string): string;
getCartProducts(mpid: MPID): Product[];
setCartProducts(allProducts: Product[]): void;
saveUserCookieSyncDatesToPersistence(mpid: MPID, csd: CookieSyncDates): void;
savePersistence(persistance: IPersistenceMinified): void;
getPersistence(): IPersistenceMinified;
Expand Down
Loading
Loading