@ns8/ns8-switchboard-operator
Advanced tools
Comparing version
@@ -7,3 +7,3 @@ import { UninstallSwitch, SwitchContext } from 'ns8-switchboard-interfaces'; | ||
constructor(uninstallSwitches?: UninstallSwitch[], v2Client?: V2Client); | ||
uninstall(switchContext: SwitchContext): Promise<any>; | ||
uninstall(switchContext: SwitchContext): Promise<void>; | ||
} |
@@ -10,16 +10,10 @@ "use strict"; | ||
async uninstall(switchContext) { | ||
let hasValidUninstall = true; | ||
let switchIndex = 0; | ||
while (switchIndex < this.uninstallSwitches.length && hasValidUninstall) { | ||
switchContext.data = await this.uninstallSwitches[switchIndex].uninstall(switchContext); | ||
hasValidUninstall = switchContext.data && switchContext.data !== null; | ||
switchIndex = switchIndex + 1; | ||
for (let i = 0; i < this.uninstallSwitches.length; i = i + 1) { | ||
await this.uninstallSwitches[i].uninstall(switchContext); | ||
} | ||
if (hasValidUninstall) { | ||
const v2BaseUrl = switchContext.apiBaseUrl; | ||
const v2Token = switchContext.merchant.shops[0].accessTokens[0].id; | ||
return this.v2Client.withAuthToken(v2Token) | ||
.withBaseUrl(v2BaseUrl) | ||
.uninstall(switchContext.data); | ||
} | ||
const v2BaseUrl = switchContext.apiBaseUrl; | ||
const v2Token = switchContext.merchant.shops[0].accessTokens[0].id; | ||
return this.v2Client.withAuthToken(v2Token) | ||
.withBaseUrl(v2BaseUrl) | ||
.uninstall(); | ||
} | ||
@@ -26,0 +20,0 @@ } |
@@ -14,4 +14,5 @@ /// <reference types="node" /> | ||
updateMerchant(merchant: Merchant): Promise<Merchant>; | ||
uninstall(uninstall: any): Promise<any>; | ||
uninstall(): Promise<void>; | ||
updateOrderStatus(update: any): Promise<any>; | ||
private checkForErrorResponse; | ||
} |
@@ -29,6 +29,3 @@ "use strict"; | ||
const response = await fetch(url, { method, body, headers }); | ||
if (response.status > V2Client.MAX_SUCCESS_CODE) { | ||
const err = { status: response.status, body: await response.json() }; | ||
throw new Error(`Protect API error: ${JSON.stringify(err)}`); | ||
} | ||
await this.checkForErrorResponse(response); | ||
return response.json(); | ||
@@ -39,4 +36,10 @@ } | ||
} | ||
async uninstall(uninstall) { | ||
return { uninstall }; | ||
async uninstall() { | ||
const method = 'DELETE'; | ||
const headers = { | ||
Authorization: `Bearer ${this.authToken}`, | ||
}; | ||
const url = `${this.baseUrl}/merchants/current`; | ||
const response = await fetch(url, { method, headers }); | ||
await this.checkForErrorResponse(response); | ||
} | ||
@@ -46,2 +49,8 @@ async updateOrderStatus(update) { | ||
} | ||
async checkForErrorResponse(response) { | ||
if (response.status > V2Client.MAX_SUCCESS_CODE) { | ||
const err = { status: response.status, body: await response.json() }; | ||
throw new Error(`Protect API error: ${JSON.stringify(err)}`); | ||
} | ||
} | ||
} | ||
@@ -48,0 +57,0 @@ V2Client.MAX_SUCCESS_CODE = 399; |
{ | ||
"name": "@ns8/ns8-switchboard-operator", | ||
"version": "1.0.39", | ||
"version": "1.0.40", | ||
"description": "Operator project contains switchboard interfaces and orchestration code", | ||
@@ -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
17959
1.17%245
1.66%2
100%