@ns8/ns8-shopify-switches
Advanced tools
Comparing version 1.0.206 to 1.0.207
@@ -6,3 +6,3 @@ "use strict"; | ||
class CreateOrderActionHelpers { | ||
static async getExistingOrder(switchContext) { | ||
static async getExistingOrder(switchContext, platformOrderId) { | ||
try { | ||
@@ -12,3 +12,3 @@ const accessToken = switchContext.merchant.accessTokens[0].id; | ||
const protectApi = new ns8_protect_api_client_1.ProtectAPIClient(switchContext.apiBaseUrl); | ||
const order = await protectApi.getOrderByPlatformId(switchContext.data.order_id, accessToken, merchantId); | ||
const order = await protectApi.getOrderByPlatformId(platformOrderId, accessToken, merchantId); | ||
return order; | ||
@@ -31,4 +31,4 @@ } | ||
} | ||
static async scoredOrderExistsInProtect(switchContext) { | ||
const existingOrder = await CreateOrderActionHelpers.getExistingOrder(switchContext); | ||
static async scoredOrderExistsInProtect(switchContext, platformOrderId) { | ||
const existingOrder = await CreateOrderActionHelpers.getExistingOrder(switchContext, platformOrderId); | ||
if (existingOrder && CreateOrderActionHelpers.orderHasBeenScored(existingOrder)) { | ||
@@ -49,4 +49,10 @@ return true; | ||
} | ||
static getOrderIdFromTransaction(switchContext) { | ||
return switchContext.data.order_id; | ||
} | ||
static getOrderIdFromOrder(switchContext) { | ||
return switchContext.data.id; | ||
} | ||
} | ||
exports.CreateOrderActionHelpers = CreateOrderActionHelpers; | ||
//# sourceMappingURL=CreateOrderActionHelpers.js.map |
@@ -9,8 +9,10 @@ "use strict"; | ||
try { | ||
const orderExistsInProtect = await CreateOrderActionHelpers_1.CreateOrderActionHelpers.scoredOrderExistsInProtect(switchContext); | ||
if (orderExistsInProtect) { | ||
return undefined; | ||
} | ||
if (CreateOrderActionHelpers_1.CreateOrderActionHelpers.dataIsOrderTransaction(switchContext)) { | ||
ns8_switch_utils_1.Logger.log({ message: 'Received data from order_transactions/create webhook' }, { orderId: switchContext.data.order_id, merchant: switchContext.merchant.domain }, 'ShopifyCreateOrderActionSwitch'); | ||
const orderIdFromTransaction = CreateOrderActionHelpers_1.CreateOrderActionHelpers.getOrderIdFromTransaction(switchContext); | ||
const orderExistsInProtect = await CreateOrderActionHelpers_1.CreateOrderActionHelpers.scoredOrderExistsInProtect(switchContext, orderIdFromTransaction); | ||
if (orderExistsInProtect) { | ||
await this.logIfOrderAlreadyExists(switchContext, orderIdFromTransaction, 'order_transactions/create'); | ||
return undefined; | ||
} | ||
ns8_switch_utils_1.Logger.log({ message: 'Received data from order_transactions/create webhook' }, { orderId: orderIdFromTransaction, merchant: switchContext.merchant.domain }, 'ShopifyCreateOrderActionSwitch'); | ||
await ns8_switch_utils_1.Logger.flush(); | ||
@@ -20,5 +22,11 @@ return await orderTransformer_1.createNS8OrderFromShopifyTransaction(switchContext); | ||
if (CreateOrderActionHelpers_1.CreateOrderActionHelpers.dataIsOrder(switchContext)) { | ||
const orderIdFromOrder = CreateOrderActionHelpers_1.CreateOrderActionHelpers.getOrderIdFromOrder(switchContext); | ||
const orderExistsInProtect = await CreateOrderActionHelpers_1.CreateOrderActionHelpers.scoredOrderExistsInProtect(switchContext, orderIdFromOrder); | ||
if (orderExistsInProtect) { | ||
await this.logIfOrderAlreadyExists(switchContext, orderIdFromOrder, 'orders/create'); | ||
return undefined; | ||
} | ||
const logOutput = { message: 'Received data from orders/create webhook' }; | ||
const logContext = { | ||
orderId: switchContext.data.id, | ||
orderId: orderIdFromOrder, | ||
merchant: switchContext.merchant.domain, | ||
@@ -47,4 +55,13 @@ }; | ||
} | ||
async logIfOrderAlreadyExists(switchContext, orderId, flow) { | ||
ns8_switch_utils_1.Logger.log({ | ||
domain: switchContext.merchant.domain, | ||
shopifyOrderId: orderId, | ||
method: 'logIfOrderAlreadyExists', | ||
fromWebhook: flow, | ||
}, switchContext, 'logIfOrderAlreadyExists'); | ||
await ns8_switch_utils_1.Logger.flush(); | ||
} | ||
} | ||
exports.ShopifyCreateOrderActionSwitch = ShopifyCreateOrderActionSwitch; | ||
//# sourceMappingURL=ShopifyCreateOrderActionSwitch.js.map |
{ | ||
"name": "@ns8/ns8-shopify-switches", | ||
"version": "1.0.206", | ||
"version": "1.0.207", | ||
"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
Sorry, the diff of this file is not supported yet
107640
1277