@ns8/ns8-shopify-switches
Advanced tools
Comparing version 1.0.155 to 1.0.156
@@ -98,9 +98,13 @@ "use strict"; | ||
})); | ||
const makeTestSession = () => new ns8_protect_models_1.Session({ | ||
ip: '23.117.48.221', | ||
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14) ' + | ||
const makeTestClientDetails = () => ({ | ||
accept_language: 'en-us', | ||
browser_height: null, | ||
browser_ip: '23.117.48.221', | ||
browser_width: null, | ||
session_hash: null, | ||
user_agent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14) ' + | ||
'AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Safari/605.1.15', | ||
acceptLanguage: 'en-us', | ||
}); | ||
const parseDemoSession = (noteAttributes = []) => { | ||
exports.makeTestClientDetails = makeTestClientDetails; | ||
const parseDemoNoteAttributes = (noteAttributes = []) => { | ||
const ip = noteAttributes | ||
@@ -118,3 +122,3 @@ .filter((note) => note.name === 'ip') | ||
.join(); | ||
return mapSession({ | ||
return { | ||
accept_language: acceptLanguage, | ||
@@ -126,5 +130,5 @@ browser_height: null, | ||
user_agent: userAgent, | ||
}); | ||
}; | ||
}; | ||
exports.parseDemoSession = parseDemoSession; | ||
exports.parseDemoNoteAttributes = parseDemoNoteAttributes; | ||
const mapSession = (clientDetails) => { | ||
@@ -138,2 +142,29 @@ const { accept_language, browser_ip, user_agent, } = clientDetails; | ||
}; | ||
const getClientDetails = (order) => { | ||
const minimumIpAddressLength = 7; | ||
const { client_details, note_attributes, source_name, test, } = order; | ||
let clientDetails; | ||
if (source_name === 'demo' && (!client_details || Object.keys(client_details).length === 0)) { | ||
clientDetails = parseDemoNoteAttributes(note_attributes); | ||
} | ||
else if (test && (!client_details || Object.keys(client_details).length === 0)) { | ||
clientDetails = makeTestClientDetails(); | ||
} | ||
else if (client_details && Object.keys(client_details).length > 0) { | ||
clientDetails = client_details; | ||
} | ||
else { | ||
clientDetails = new Error(`Client details cannot be derived from this order.`); | ||
} | ||
if (!(clientDetails instanceof Error)) { | ||
if (!clientDetails.browser_ip || clientDetails.browser_ip.length < minimumIpAddressLength) { | ||
clientDetails = new Error('Invalid Client Details object: IP Address.'); | ||
} | ||
} | ||
if (clientDetails instanceof Error) { | ||
clientDetails.message = `${clientDetails.message} ${JSON.stringify(order)}`; | ||
} | ||
return clientDetails; | ||
}; | ||
exports.getClientDetails = getClientDetails; | ||
class ShopifyCreateOrderActionSwitch { | ||
@@ -161,25 +192,20 @@ async create(switchContext) { | ||
const { id: merchantId } = switchContext.merchant; | ||
const { id, name, currency, billing_address, shipping_address, customer, total_price, line_items = [], created_at, client_details, test, source_name, note_attributes, } = shopifyOrder; | ||
const addresses = []; | ||
if (billing_address) { | ||
addresses.push(mapAddress(billing_address, 'BILLING')); | ||
const clientDetails = getClientDetails(shopifyOrder); | ||
const { id, name, currency, billing_address, shipping_address, customer, total_price, line_items = [], created_at, } = shopifyOrder; | ||
if (clientDetails instanceof Error) { | ||
console.log(clientDetails); | ||
} | ||
if (shipping_address) { | ||
addresses.push(mapAddress(shipping_address, 'SHIPPING')); | ||
} | ||
let protectCustomer; | ||
if (customer) { | ||
protectCustomer = mapCustomer(customer); | ||
} | ||
let session; | ||
if (source_name === 'demo' && (!client_details || Object.keys(client_details).length === 0)) { | ||
session = parseDemoSession(note_attributes); | ||
} | ||
else if (test && (!client_details || Object.keys(client_details).length === 0)) { | ||
session = makeTestSession(); | ||
} | ||
else if (client_details && Object.keys(client_details).length > 0) { | ||
session = mapSession(client_details); | ||
} | ||
if (session && session.ip) { | ||
else { | ||
const session = mapSession(clientDetails); | ||
if (billing_address) { | ||
addresses.push(mapAddress(billing_address, 'BILLING')); | ||
} | ||
if (shipping_address) { | ||
addresses.push(mapAddress(shipping_address, 'SHIPPING')); | ||
} | ||
let protectCustomer; | ||
if (customer) { | ||
protectCustomer = mapCustomer(customer); | ||
} | ||
return new ns8_protect_models_1.Order({ | ||
@@ -201,5 +227,2 @@ name, | ||
} | ||
console.log('This order cannot be created due to lack of session data.' + | ||
`Domain: ${switchContext.merchant.domain} ` + | ||
`Shopify Order ID: ${order_id}`); | ||
} | ||
@@ -206,0 +229,0 @@ else { |
{ | ||
"name": "@ns8/ns8-shopify-switches", | ||
"version": "1.0.155", | ||
"version": "1.0.156", | ||
"description": "Custom switches for the shopify integration", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
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
76609
909