@nuskin/mobile-cart
Advanced tools
Comparing version 3.0.12 to 3.0.13-0
@@ -324,3 +324,2 @@ "use strict"; | ||
* @param quantity | ||
* @param oneTime | ||
* @param agelocme | ||
@@ -332,3 +331,2 @@ */ | ||
quantity = 1, | ||
oneTime, | ||
agelocme = null, | ||
@@ -368,10 +366,9 @@ optionalBundleSkus = [] | ||
const authToken = await getAuthToken(); | ||
data.forEach(async dataItem => { | ||
const { | ||
anonymousCartId, | ||
itemCount | ||
} = await api.addSkuToCart(dataItem.sku, quantity, authToken, oneTime ?? !isItemSubscriptionOnly(dataItem), agelocme); | ||
setAnonymousCartId(anonymousCartId); | ||
setQuantity(itemCount); | ||
}); | ||
const oneTimeArray = data.map(item => !isItemSubscriptionOnly(item)); | ||
const { | ||
anonymousCartId, | ||
itemCount | ||
} = await api.addSkuArrayToCart(data, quantity, authToken, oneTimeArray, agelocme); | ||
setAnonymousCartId(anonymousCartId); | ||
setQuantity(itemCount); | ||
} catch (error) { | ||
@@ -378,0 +375,0 @@ console.log('addSkuToCart exception', error); |
@@ -161,2 +161,7 @@ "use strict"; | ||
/** | ||
* Placeholder. | ||
*/ | ||
const addSkuArrayToCart = async () => {}; | ||
/** | ||
* Merges an anonymous cart into a user's cart after the user logs in. | ||
@@ -195,5 +200,6 @@ */ | ||
getCartPageHeaders, | ||
setData | ||
setData, | ||
addSkuArrayToCart | ||
}; | ||
exports.default = _default; | ||
//# sourceMappingURL=KrCartApi.js.map |
@@ -147,2 +147,51 @@ "use strict"; | ||
/** | ||
* Builds the payload object when adding an array of products to the cart. | ||
* | ||
* @param productsArray - product SKU array | ||
* @param quantity - The quantity to add | ||
* @param oneTime - product's oneTime or subscription purchase array | ||
* @param agelocme - information about skin consultation product | ||
* @param gpid - global product ID for the product | ||
* @returns | ||
*/ | ||
const getArrayPayload = function (productsArray) { | ||
let quantity = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; | ||
let oneTime = arguments.length > 2 ? arguments[2] : undefined; | ||
let agelocme = arguments.length > 3 ? arguments[3] : undefined; | ||
let gpid = arguments.length > 4 ? arguments[4] : undefined; | ||
const actionsObject = (sku, index) => { | ||
return { | ||
action: 'add', | ||
product: { | ||
gpid, | ||
oneTime: oneTime[index], | ||
quantity, | ||
sku, | ||
...(agelocme && { | ||
agelocmeCode: agelocme.code | ||
}), | ||
...(agelocme && { | ||
agelocmeName: agelocme.name | ||
}), | ||
...(agelocme && { | ||
agelocmeLabel: agelocme.label | ||
}) | ||
} | ||
}; | ||
}; | ||
const payload = { | ||
country, | ||
type: 'market', | ||
version: -1, | ||
actions: productsArray.map((item, index) => { | ||
return actionsObject(item.sku, index); | ||
}) | ||
}; | ||
if (userId) { | ||
payload.accountId = userId; | ||
} | ||
return payload; | ||
}; | ||
/** | ||
* Builds the update url for either a user's cart or an anonymous cart | ||
@@ -226,2 +275,36 @@ * | ||
/** | ||
* Adds a product or array of products to a user's or anonymous persistent cart. | ||
* | ||
* @param productsArray - array of products | ||
* @param quantity - quantity to add | ||
* @param oneTime - add to cart as oneTime or subscription | ||
* @param agelocme - contains agelocMe information if applicable | ||
*/ | ||
const addSkuArrayToCart = async function (productsArray) { | ||
let quantity = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; | ||
let authToken = arguments.length > 2 ? arguments[2] : undefined; | ||
let oneTime = arguments.length > 3 ? arguments[3] : undefined; | ||
let agelocme = arguments.length > 4 ? arguments[4] : undefined; | ||
let itemCount = 0; | ||
try { | ||
let cart; | ||
const response = await (0, _axiosUtil.axios)({ | ||
method: 'PUT', | ||
url: getUpdateUrl(), | ||
headers: getHeaders(authToken), | ||
data: getArrayPayload(productsArray, quantity, oneTime, agelocme, '') | ||
}); | ||
cart = response.data.cart; | ||
itemCount = getItemCount(cart); | ||
anonymousCartId = userId ? '' : cart ? cart.id : ''; | ||
} catch (err) { | ||
console.log('addSkuToCart exception', err); | ||
} | ||
return { | ||
anonymousCartId, | ||
itemCount | ||
}; | ||
}; | ||
/** | ||
* Non-Korean markets do not need to login before loading checkout webview. | ||
@@ -241,2 +324,3 @@ * @returns boolean | ||
addSkuToCart, | ||
addSkuArrayToCart, | ||
mergeAnonymousCart, | ||
@@ -243,0 +327,0 @@ getCartPageHeaders |
@@ -315,3 +315,2 @@ /* eslint-disable */ | ||
* @param quantity | ||
* @param oneTime | ||
* @param agelocme | ||
@@ -323,3 +322,2 @@ */ | ||
quantity = 1, | ||
oneTime, | ||
agelocme = null, | ||
@@ -359,10 +357,9 @@ optionalBundleSkus = [] | ||
const authToken = await getAuthToken(); | ||
data.forEach(async dataItem => { | ||
const { | ||
anonymousCartId, | ||
itemCount | ||
} = await api.addSkuToCart(dataItem.sku, quantity, authToken, oneTime ?? !isItemSubscriptionOnly(dataItem), agelocme); | ||
setAnonymousCartId(anonymousCartId); | ||
setQuantity(itemCount); | ||
}); | ||
const oneTimeArray = data.map(item => !isItemSubscriptionOnly(item)); | ||
const { | ||
anonymousCartId, | ||
itemCount | ||
} = await api.addSkuArrayToCart(data, quantity, authToken, oneTimeArray, agelocme); | ||
setAnonymousCartId(anonymousCartId); | ||
setQuantity(itemCount); | ||
} catch (error) { | ||
@@ -369,0 +366,0 @@ console.log('addSkuToCart exception', error); |
@@ -154,2 +154,7 @@ /* eslint-disable */ | ||
/** | ||
* Placeholder. | ||
*/ | ||
const addSkuArrayToCart = async () => {}; | ||
/** | ||
* Merges an anonymous cart into a user's cart after the user logs in. | ||
@@ -188,4 +193,5 @@ */ | ||
getCartPageHeaders, | ||
setData | ||
setData, | ||
addSkuArrayToCart | ||
}; | ||
//# sourceMappingURL=KrCartApi.js.map |
@@ -140,2 +140,51 @@ /* eslint-disable */ | ||
/** | ||
* Builds the payload object when adding an array of products to the cart. | ||
* | ||
* @param productsArray - product SKU array | ||
* @param quantity - The quantity to add | ||
* @param oneTime - product's oneTime or subscription purchase array | ||
* @param agelocme - information about skin consultation product | ||
* @param gpid - global product ID for the product | ||
* @returns | ||
*/ | ||
const getArrayPayload = function (productsArray) { | ||
let quantity = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; | ||
let oneTime = arguments.length > 2 ? arguments[2] : undefined; | ||
let agelocme = arguments.length > 3 ? arguments[3] : undefined; | ||
let gpid = arguments.length > 4 ? arguments[4] : undefined; | ||
const actionsObject = (sku, index) => { | ||
return { | ||
action: 'add', | ||
product: { | ||
gpid, | ||
oneTime: oneTime[index], | ||
quantity, | ||
sku, | ||
...(agelocme && { | ||
agelocmeCode: agelocme.code | ||
}), | ||
...(agelocme && { | ||
agelocmeName: agelocme.name | ||
}), | ||
...(agelocme && { | ||
agelocmeLabel: agelocme.label | ||
}) | ||
} | ||
}; | ||
}; | ||
const payload = { | ||
country, | ||
type: 'market', | ||
version: -1, | ||
actions: productsArray.map((item, index) => { | ||
return actionsObject(item.sku, index); | ||
}) | ||
}; | ||
if (userId) { | ||
payload.accountId = userId; | ||
} | ||
return payload; | ||
}; | ||
/** | ||
* Builds the update url for either a user's cart or an anonymous cart | ||
@@ -219,2 +268,36 @@ * | ||
/** | ||
* Adds a product or array of products to a user's or anonymous persistent cart. | ||
* | ||
* @param productsArray - array of products | ||
* @param quantity - quantity to add | ||
* @param oneTime - add to cart as oneTime or subscription | ||
* @param agelocme - contains agelocMe information if applicable | ||
*/ | ||
const addSkuArrayToCart = async function (productsArray) { | ||
let quantity = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; | ||
let authToken = arguments.length > 2 ? arguments[2] : undefined; | ||
let oneTime = arguments.length > 3 ? arguments[3] : undefined; | ||
let agelocme = arguments.length > 4 ? arguments[4] : undefined; | ||
let itemCount = 0; | ||
try { | ||
let cart; | ||
const response = await axios({ | ||
method: 'PUT', | ||
url: getUpdateUrl(), | ||
headers: getHeaders(authToken), | ||
data: getArrayPayload(productsArray, quantity, oneTime, agelocme, '') | ||
}); | ||
cart = response.data.cart; | ||
itemCount = getItemCount(cart); | ||
anonymousCartId = userId ? '' : cart ? cart.id : ''; | ||
} catch (err) { | ||
console.log('addSkuToCart exception', err); | ||
} | ||
return { | ||
anonymousCartId, | ||
itemCount | ||
}; | ||
}; | ||
/** | ||
* Non-Korean markets do not need to login before loading checkout webview. | ||
@@ -234,2 +317,3 @@ * @returns boolean | ||
addSkuToCart, | ||
addSkuArrayToCart, | ||
mergeAnonymousCart, | ||
@@ -236,0 +320,0 @@ getCartPageHeaders |
@@ -6,2 +6,3 @@ import type { EID } from '@nuskin/ns-login-react-native'; | ||
addSkuToCart(sku: string, quantity: number, authToken?: any, oneTime?: boolean, agelocme?: any): any; | ||
addSkuArrayToCart(productsArray: any[], quantity: number, authToken?: any, oneTime?: boolean[], agelocme?: any): any; | ||
mergeAnonymousCart?(eid: EID | undefined): any; | ||
@@ -8,0 +9,0 @@ canCheckout(): boolean; |
@@ -17,3 +17,4 @@ declare const _default: { | ||
setData: (data: any) => void; | ||
addSkuArrayToCart: () => Promise<void>; | ||
}; | ||
export default _default; |
@@ -14,2 +14,6 @@ import type { EID } from '@nuskin/ns-login-react-native'; | ||
}>; | ||
addSkuArrayToCart: (productsArray: any[], quantity: number | undefined, authToken: any, oneTime: boolean[], agelocme: AgelocMe) => Promise<{ | ||
anonymousCartId: any; | ||
itemCount: number; | ||
}>; | ||
mergeAnonymousCart: (eid: EID) => Promise<{ | ||
@@ -16,0 +20,0 @@ anonymousCartId: any; |
{ | ||
"name": "@nuskin/mobile-cart", | ||
"private": false, | ||
"version": "3.0.12", | ||
"version": "3.0.13-0", | ||
"repository": { | ||
@@ -143,3 +143,3 @@ "type": "git", | ||
}, | ||
"commithash": "a243af48f293f3c6333495f1b6dfefe4f80ce69e", | ||
"commithash": "1597b57308fa486f6f9c7b9670ac587a6a422573", | ||
"author": { | ||
@@ -146,0 +146,0 @@ "name": "Arnel Nuqui", |
@@ -13,2 +13,9 @@ import type { EID } from '@nuskin/ns-login-react-native'; | ||
): any; | ||
addSkuArrayToCart( | ||
productsArray: any[], | ||
quantity: number, | ||
authToken?: any, | ||
oneTime?: boolean[], | ||
agelocme?: any | ||
): any; | ||
mergeAnonymousCart?(eid: EID | undefined): any; | ||
@@ -15,0 +22,0 @@ canCheckout(): boolean; |
@@ -153,3 +153,12 @@ /* eslint-disable */ | ||
/** | ||
* Placeholder. | ||
*/ | ||
const addSkuArrayToCart = async ( | ||
) => { | ||
} | ||
/** | ||
* Merges an anonymous cart into a user's cart after the user logs in. | ||
@@ -192,2 +201,3 @@ */ | ||
setData, | ||
addSkuArrayToCart, | ||
} |
@@ -140,2 +140,49 @@ /* eslint-disable */ | ||
/** | ||
* Builds the payload object when adding an array of products to the cart. | ||
* | ||
* @param productsArray - product SKU array | ||
* @param quantity - The quantity to add | ||
* @param oneTime - product's oneTime or subscription purchase array | ||
* @param agelocme - information about skin consultation product | ||
* @param gpid - global product ID for the product | ||
* @returns | ||
*/ | ||
const getArrayPayload = ( | ||
productsArray: any[], | ||
quantity: number = 1, | ||
oneTime: boolean[], | ||
agelocme?: AgelocMe, | ||
gpid?: string | ||
) => { | ||
const actionsObject = (sku: any, index: number) => { | ||
return { | ||
action: 'add', | ||
product: { | ||
gpid, | ||
oneTime: oneTime[index], | ||
quantity, | ||
sku, | ||
...(agelocme && { agelocmeCode: agelocme.code }), | ||
...(agelocme && { agelocmeName: agelocme.name }), | ||
...(agelocme && { agelocmeLabel: agelocme.label }), | ||
}, | ||
} | ||
} | ||
const payload: any = { | ||
country, | ||
type: 'market', | ||
version: -1, | ||
actions: productsArray.map((item, index) => { | ||
return actionsObject(item.sku, index) | ||
}) | ||
}; | ||
if (userId) { | ||
payload.accountId = userId; | ||
} | ||
return payload; | ||
}; | ||
/** | ||
* Builds the update url for either a user's cart or an anonymous cart | ||
@@ -219,2 +266,37 @@ * | ||
/** | ||
* Adds a product or array of products to a user's or anonymous persistent cart. | ||
* | ||
* @param productsArray - array of products | ||
* @param quantity - quantity to add | ||
* @param oneTime - add to cart as oneTime or subscription | ||
* @param agelocme - contains agelocMe information if applicable | ||
*/ | ||
const addSkuArrayToCart = async ( | ||
productsArray: any[], | ||
quantity: number = 1, | ||
authToken: any, | ||
oneTime: boolean[], | ||
agelocme: AgelocMe | ||
) => { | ||
let itemCount = 0; | ||
try { | ||
let cart; | ||
const response = await axios({ | ||
method: 'PUT', | ||
url: getUpdateUrl(), | ||
headers: getHeaders(authToken), | ||
data: getArrayPayload(productsArray, quantity, oneTime, agelocme, ''), | ||
}); | ||
cart = response.data.cart; | ||
itemCount = getItemCount(cart); | ||
anonymousCartId = userId ? '' : cart ? cart.id : ''; | ||
} catch (err) { | ||
console.log('addSkuToCart exception', err); | ||
} | ||
return {anonymousCartId, itemCount}; | ||
}; | ||
/** | ||
* Non-Korean markets do not need to login before loading checkout webview. | ||
@@ -236,4 +318,5 @@ * @returns boolean | ||
addSkuToCart, | ||
addSkuArrayToCart, | ||
mergeAnonymousCart, | ||
getCartPageHeaders | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
301093
4194
2