@ns8/ns8-shopify-switches
Advanced tools
Comparing version 1.0.189 to 1.0.190
@@ -7,2 +7,3 @@ "use strict"; | ||
const Logger_1 = require("./Logger"); | ||
const ns8_protect_api_client_1 = require("@ns8/ns8-protect-api-client"); | ||
const formatPhoneNumber = (phoneNumberString, countryCode) => { | ||
@@ -286,7 +287,10 @@ let phoneNumber; | ||
} | ||
exports.processCreateOrderActionContext = processCreateOrderActionContext; | ||
class ShopifyCreateOrderActionSwitch { | ||
async create(switchContext) { | ||
try { | ||
const order = await processCreateOrderActionContext(switchContext); | ||
return order; | ||
const orderExistsInProtect = await CreateOrderActionHelpers.scoredOrderExistsInProtect(switchContext); | ||
return orderExistsInProtect | ||
? undefined | ||
: await CreateOrderActionHelpers.processCreateOrderActionContext(switchContext); | ||
} | ||
@@ -300,2 +304,36 @@ catch (err) { | ||
exports.ShopifyCreateOrderActionSwitch = ShopifyCreateOrderActionSwitch; | ||
class CreateOrderActionHelpers { | ||
static async getExistingOrder(switchContext) { | ||
try { | ||
const accessToken = switchContext.merchant.accessTokens[0].id; | ||
const merchantId = switchContext.merchant.id; | ||
const protectApi = new ns8_protect_api_client_1.ProtectAPIClient(switchContext.apiBaseUrl); | ||
const order = await protectApi.getOrderByPlatformId(switchContext.data.order_id, accessToken, merchantId); | ||
return order; | ||
} | ||
catch (err) { | ||
return undefined; | ||
} | ||
} | ||
static orderHasBeenScored(order) { | ||
if (order && order.fraudAssessments) { | ||
const assessments = order.fraudAssessments; | ||
const eq8Assessment = assessments.find((assessment) => assessment.providerType === ns8_protect_models_1.ProviderType.EQ8); | ||
const minFraudAssessment = assessments.find((assessment) => assessment.providerType === ns8_protect_models_1.ProviderType.MIN_FRAUD); | ||
return eq8Assessment != null && minFraudAssessment != null; | ||
} | ||
return false; | ||
} | ||
static async scoredOrderExistsInProtect(switchContext) { | ||
const existingOrder = await CreateOrderActionHelpers.getExistingOrder(switchContext); | ||
if (existingOrder && CreateOrderActionHelpers.orderHasBeenScored(existingOrder)) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
static async processCreateOrderActionContext(switchContext) { | ||
return processCreateOrderActionContext(switchContext); | ||
} | ||
} | ||
exports.CreateOrderActionHelpers = CreateOrderActionHelpers; | ||
//# sourceMappingURL=ShopifyCreateOrderActionSwitch.js.map |
{ | ||
"name": "@ns8/ns8-shopify-switches", | ||
"version": "1.0.189", | ||
"version": "1.0.190", | ||
"description": "Custom switches for the shopify integration", | ||
@@ -16,3 +16,4 @@ "main": "dist/index.js", | ||
"lint": "tslint --project .", | ||
"test": "nyc mocha --colors" | ||
"test": "nyc mocha --colors", | ||
"test:only": "mocha --colors" | ||
}, | ||
@@ -34,2 +35,3 @@ "devDependencies": { | ||
"dependencies": { | ||
"@ns8/ns8-protect-api-client": "^0.0.8", | ||
"isomorphic-fetch": "^2.2.1", | ||
@@ -36,0 +38,0 @@ "libhoney": "^2.0.1", |
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 4 instances in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
98797
1212
11
7
+ Added@ns8/ns8-protect-api-client@0.0.8(transitive)
+ Addedstring_decoder@1.3.0(transitive)
+ Addedsuperagent@5.3.1(transitive)