UNPKG

@shipengine/connect

Version:

The official developer tooling for building ShipEngine connect apps

54 lines 2.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createOrFindTestAccounts = void 0; const tslib_1 = require("tslib"); const api_client_1 = require("../api-client"); const log_symbols_1 = tslib_1.__importDefault(require("log-symbols")); const cli_ux_1 = tslib_1.__importDefault(require("cli-ux")); /** * Find or create a test account and return the information. */ async function createOrFindTestAccounts(client, platformApp, supportedCountries) { const testAccounts = []; const sellers = await client.sellers.getSellersForAppId(platformApp.id); const productInfo = platformApp.productInfos.find((info) => info.product === 'ShipStation'); const testUrl = productInfo && productInfo.loginUrl; // The older sellers didn't have country specific log ins const oldEmail = `${platformApp.id}@test.com`; const oldSeller = sellers.find((account) => account.email === oldEmail); if (oldSeller) { testAccounts.push({ email: oldEmail, country: 'N/A', password: platformApp.id, testUrl, }); } for (let idx = 0; idx < supportedCountries.length; idx++) { const country = supportedCountries[idx]; const email = `${platformApp.id}+${country}@test.com`; if (!sellers.some((seller) => seller.email === email)) { cli_ux_1.default.action.start(`Creating ${country} test account`); let success = true; try { await client.sellers.createSeller(platformApp.id, email, platformApp.id, country); } catch (error) { if (error.code !== api_client_1.ApiClientErrors.BadRequest) { success = false; console.log(error); } } cli_ux_1.default.action.stop(`${success ? log_symbols_1.default.success : log_symbols_1.default.error}`); } testAccounts.push({ email, country, password: platformApp.id, testUrl, }); } return testAccounts; } exports.createOrFindTestAccounts = createOrFindTestAccounts; //# sourceMappingURL=create-or-find-test-account.js.map