microapps-automation-helper
Advanced tools
Comparing version 1.0.9 to 1.0.10
{ | ||
"name": "microapps-automation-helper", | ||
"version": "1.0.9", | ||
"description": "> citrix-iws is a library which provides common functions to test integration between Microapps Admin and Citrix Worskspace", | ||
"version": "1.0.10", | ||
"description": "> library which provides common functions to test integration between Microapps Admin and Citrix Worskspace", | ||
"main": "index.js", | ||
@@ -11,4 +11,4 @@ "types": "main.d.ts", | ||
"otplib": "^12.0.1", | ||
"playwright": "^1.4.0", | ||
"typescript": "^4.0.2" | ||
"playwright": "^1.5.2", | ||
"typescript": "^4.0.5" | ||
}, | ||
@@ -15,0 +15,0 @@ "devDependencies": {}, |
152
src/api.ts
@@ -62,3 +62,6 @@ import axios from "axios"; | ||
async getBundleCatalogue({ authInstance, microappsAdminUrl }: GetBundleCatalogue) { | ||
async getBundleCatalogue({ | ||
authInstance, | ||
microappsAdminUrl, | ||
}: GetBundleCatalogue) { | ||
try { | ||
@@ -81,3 +84,7 @@ return await authInstance({ | ||
*/ | ||
async updateBundleCatalogue({ authInstance, microappsAdminUrl, catalogueId }: UpdateBundleCatalogue) { | ||
async updateBundleCatalogue({ | ||
authInstance, | ||
microappsAdminUrl, | ||
catalogueId, | ||
}: UpdateBundleCatalogue) { | ||
try { | ||
@@ -125,3 +132,7 @@ return await authInstance({ | ||
*/ | ||
async getIntegration({ authInstance, microappsAdminUrl, integrationId }: GetIntegration) { | ||
async getIntegration({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationId, | ||
}: GetIntegration) { | ||
return await authInstance({ | ||
@@ -140,3 +151,7 @@ url: `${microappsAdminUrl}/api/service/${integrationId}`, | ||
*/ | ||
async integrationLogout({ authInstance, microappsAdminUrl, integrationId }: IntegrationLogout) { | ||
async integrationLogout({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationId, | ||
}: IntegrationLogout) { | ||
try { | ||
@@ -160,3 +175,8 @@ return await authInstance({ | ||
*/ | ||
async validateConfiguration({ authInstance, microappsAdminUrl, serviceKey, configuration }: ValidateConfiguration) { | ||
async validateConfiguration({ | ||
authInstance, | ||
microappsAdminUrl, | ||
serviceKey, | ||
configuration, | ||
}: ValidateConfiguration) { | ||
try { | ||
@@ -205,3 +225,7 @@ return await authInstance({ | ||
*/ | ||
async getProcessStatus({ authInstance, microappsAdminUrl, processId }: GetProcessStatus) { | ||
async getProcessStatus({ | ||
authInstance, | ||
microappsAdminUrl, | ||
processId, | ||
}: GetProcessStatus) { | ||
try { | ||
@@ -224,3 +248,7 @@ return await authInstance({ | ||
*/ | ||
async getEntities({ authInstance, microappsAdminUrl, integrationId }: GetEntities) { | ||
async getEntities({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationId, | ||
}: GetEntities) { | ||
try { | ||
@@ -244,3 +272,8 @@ return await authInstance({ | ||
*/ | ||
async createEntity({ authInstance, microappsAdminUrl, integrationId, entityData }: CreateEntity) { | ||
async createEntity({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationId, | ||
entityData, | ||
}: CreateEntity) { | ||
try { | ||
@@ -264,3 +297,7 @@ return await authInstance({ | ||
*/ | ||
async finalizeConfig({ authInstance, microappsAdminUrl, integrationId }: FinalizeConfig) { | ||
async finalizeConfig({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationId, | ||
}: FinalizeConfig) { | ||
try { | ||
@@ -301,3 +338,7 @@ return await authInstance({ | ||
*/ | ||
async getNotifications({ authInstance, microappsAdminUrl, appId }: GetNotifications) { | ||
async getNotifications({ | ||
authInstance, | ||
microappsAdminUrl, | ||
appId, | ||
}: GetNotifications) { | ||
try { | ||
@@ -319,3 +360,7 @@ return await authInstance({ | ||
*/ | ||
async runNotificationEvent({ authInstance, microappsAdminUrl, notificationId }: RunNotificationEvent) { | ||
async runNotificationEvent({ | ||
authInstance, | ||
microappsAdminUrl, | ||
notificationId, | ||
}: RunNotificationEvent) { | ||
try { | ||
@@ -378,3 +423,7 @@ return await authInstance({ | ||
*/ | ||
async deleteIntegration({ authInstance, microappsAdminUrl, integrationId }: DeleteIntegration) { | ||
async deleteIntegration({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationId, | ||
}: DeleteIntegration) { | ||
try { | ||
@@ -398,3 +447,8 @@ return await authInstance({ | ||
*/ | ||
async getDomain({ authInstance, cwaAPI, citrixCloudCustomerId, workspaceIdentityProvider }: GetDomain) { | ||
async getDomain({ | ||
authInstance, | ||
cwaAPI, | ||
citrixCloudCustomerId, | ||
workspaceIdentityProvider, | ||
}: GetDomain) { | ||
try { | ||
@@ -426,3 +480,5 @@ switch (workspaceIdentityProvider) { | ||
default: | ||
console.log(`getDomain is currently not implemented for this idp: ${workspaceIdentityProvider}`); | ||
console.log( | ||
`getDomain is currently not implemented for this idp: ${workspaceIdentityProvider}` | ||
); | ||
break; | ||
@@ -509,3 +565,9 @@ } | ||
}: UpdateSubscribers) { | ||
const { accountName, displayName, universalClaims, identityInformation, isGroup } = userDetail[0]; | ||
const { | ||
accountName, | ||
displayName, | ||
universalClaims, | ||
identityInformation, | ||
isGroup, | ||
} = userDetail[0]; | ||
@@ -532,3 +594,5 @@ const getOID = universalClaims.filter((value: string) => { | ||
ipForUpdate = null; | ||
console.log(`Adding subscribers is currently not implemented for this idp`); | ||
console.log( | ||
`Adding subscribers is currently not implemented for this idp` | ||
); | ||
break; | ||
@@ -572,3 +636,7 @@ } | ||
*/ | ||
async getSubscribers({ authInstance, microappsAdminUrl, appId }: GetSubscribers) { | ||
async getSubscribers({ | ||
authInstance, | ||
microappsAdminUrl, | ||
appId, | ||
}: GetSubscribers) { | ||
try { | ||
@@ -594,3 +662,9 @@ return await authInstance({ | ||
*/ | ||
async exportIntegration({ authInstance, microappsAdminUrl, integrationId, filePath, params }: ExportIntegration) { | ||
async exportIntegration({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationId, | ||
filePath, | ||
params, | ||
}: ExportIntegration) { | ||
let response; | ||
@@ -608,3 +682,5 @@ try { | ||
await response.data.pipe(fs.createWriteStream(path.resolve(__dirname, filePath))); | ||
await response.data.pipe( | ||
fs.createWriteStream(path.resolve(__dirname, filePath)) | ||
); | ||
} | ||
@@ -619,4 +695,8 @@ | ||
*/ | ||
async getIntegrationLog({ authInstance, microappsAdminUrl, integrationId, integrationType }: GetIntegrationLog) { | ||
async getIntegrationLog({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationId, | ||
integrationType, | ||
}: GetIntegrationLog) { | ||
try { | ||
@@ -639,3 +719,8 @@ return await authInstance({ | ||
*/ | ||
async addSecrets({ authInstance, microappsAdminUrl, integrationId, data }: AddSecrets) { | ||
async addSecrets({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationId, | ||
data, | ||
}: AddSecrets) { | ||
try { | ||
@@ -651,2 +736,19 @@ return await authInstance({ | ||
} | ||
/** | ||
* Get microapp info - pages, components etc... | ||
* @param {Object} authInstance - Authorized instance for API calls | ||
* @param {string} microappsAdminUrl - Microapps admin url | ||
* @param {string} appId - Id of microapp | ||
*/ | ||
async getAppInfo({ authInstance, microappsAdminUrl, appId }: GetAppInfo) { | ||
try { | ||
return await authInstance({ | ||
url: `${microappsAdminUrl}/api/app/${appId}`, | ||
method: "GET", | ||
}); | ||
} catch (error) { | ||
throw error.stack; | ||
} | ||
} | ||
} | ||
@@ -825,1 +927,7 @@ | ||
}; | ||
export type GetAppInfo = { | ||
authInstance: any; | ||
microappsAdminUrl: string; | ||
appId: string; | ||
}; |
@@ -1,8 +0,8 @@ | ||
import { Page } from 'playwright'; | ||
import FormData from 'form-data'; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import assert from 'assert'; | ||
import { CitrixCloud } from './citrixCloud'; | ||
import { API } from './api'; | ||
import { Page } from "playwright"; | ||
import FormData from "form-data"; | ||
import fs from "fs"; | ||
import path from "path"; | ||
import assert from "assert"; | ||
import { CitrixCloud } from "./citrixCloud"; | ||
import { API } from "./api"; | ||
@@ -13,945 +13,1231 @@ const citrixCloud = new CitrixCloud(); | ||
export class MicroappsAdmin extends API { | ||
constructor() { | ||
super(); | ||
} | ||
constructor() { | ||
super(); | ||
} | ||
/** | ||
* Login to cloud | ||
* @param {string} - Microapps cloud login url | ||
* @param {string} - Username | ||
* @param {string} - Password | ||
*/ | ||
/** | ||
* Login to cloud | ||
* @param {string} - Microapps cloud login url | ||
* @param {string} - Username | ||
* @param {string} - Password | ||
*/ | ||
async login({ page, url, username, password, mfa = null, secretKey }: MicroappsAdminLogin) { | ||
await page.goto(url, { waitUntil: 'domcontentloaded' }); | ||
await page.waitForSelector('#username'); | ||
await page.type('#username', username); | ||
await page.waitForSelector('#password'); | ||
await page.type('#password', password); | ||
await page.waitForSelector('#submit'); | ||
await page.click('#submit'); | ||
async login({ | ||
page, | ||
url, | ||
username, | ||
password, | ||
mfa = null, | ||
secretKey, | ||
}: MicroappsAdminLogin) { | ||
await page.goto(url, { waitUntil: "domcontentloaded" }); | ||
await page.waitForSelector("#username"); | ||
await page.type("#username", username); | ||
await page.waitForSelector("#password"); | ||
await page.type("#password", password); | ||
await page.waitForSelector("#submit"); | ||
await page.click("#submit"); | ||
if (mfa) { | ||
const authCode = await citrixCloud.getAuthenticatorCode({ secretKey }); | ||
if (mfa) { | ||
const authCode = await citrixCloud.getAuthenticatorCode({ secretKey }); | ||
await page.waitForSelector('input[inputmode]'); | ||
for (let i = 0; i < 6; i++) { | ||
await page.type(`input[inputmode][name="${i}"]`, authCode[i]); | ||
} | ||
await page.waitForSelector("input[inputmode]"); | ||
for (let i = 0; i < 6; i++) { | ||
await page.type(`input[inputmode][name="${i}"]`, authCode[i]); | ||
} | ||
await page.waitForSelector('button[type="button"]:not([disabled])'); | ||
await page.click('button[type="button"]:not([disabled])'); | ||
await page.waitForSelector('button[type="button"]:not([disabled])'); | ||
await page.click('button[type="button"]:not([disabled])'); | ||
try { | ||
for (;;) { | ||
if ((await page.$(`input[inputmode][name="0"][value="${authCode[0]}"]`)) !== null) { | ||
await page.waitForTimeout(300); | ||
} else break; | ||
} | ||
} catch (error) {} | ||
try { | ||
for (;;) { | ||
if ( | ||
(await page.$( | ||
`input[inputmode][name="0"][value="${authCode[0]}"]` | ||
)) !== null | ||
) { | ||
await page.waitForTimeout(300); | ||
} else break; | ||
} | ||
} catch (error) {} | ||
} | ||
} | ||
/** | ||
* Get Integration Id | ||
* @param {Object} authInstance - Authorized instance for API calls | ||
* @param {string} microappsAdminUrl - Microapps admin url | ||
* @param {string} integrationName - Name of integration | ||
*/ | ||
/** | ||
* Get Integration Id | ||
* @param {Object} authInstance - Authorized instance for API calls | ||
* @param {string} microappsAdminUrl - Microapps admin url | ||
* @param {string} integrationName - Name of integration | ||
*/ | ||
async getIntegrationId({ authInstance, microappsAdminUrl, integrationName }: GetIntegrationId) { | ||
const integrations = await this.getIntegrations({ authInstance, microappsAdminUrl }); | ||
const integration = integrations.data.find((e: { title: string }) => e.title === integrationName); | ||
return integration.id; | ||
} | ||
async getIntegrationId({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationName, | ||
}: GetIntegrationId) { | ||
const integrations = await this.getIntegrations({ | ||
authInstance, | ||
microappsAdminUrl, | ||
}); | ||
const integration = integrations.data.find( | ||
(e: { title: string }) => e.title === integrationName | ||
); | ||
return integration.id; | ||
} | ||
/** | ||
* Delete credentiaslds from credentials wallet for specific inregration | ||
* @param {Object} authInstance - Authorized instance for API calls | ||
* @param {string} microappsAdminUrl - Microapps admin url | ||
* @param {string} integrationName - Name of integration | ||
* @param {number} repeatCount - Set count for retries | ||
*/ | ||
/** | ||
* Delete credentiaslds from credentials wallet for specific inregration | ||
* @param {Object} authInstance - Authorized instance for API calls | ||
* @param {string} microappsAdminUrl - Microapps admin url | ||
* @param {string} integrationName - Name of integration | ||
* @param {number} repeatCount - Set count for retries | ||
*/ | ||
async oauthLogout({ authInstance, microappsAdminUrl, integrationName, repeatCount = 1 }: OauthLogout) { | ||
const integrationId = await this.getIntegrationId({ authInstance, microappsAdminUrl, integrationName }); | ||
for (let i = 0; i < repeatCount; i++) { | ||
await this.integrationLogout({ authInstance, microappsAdminUrl, integrationId }); | ||
} | ||
async oauthLogout({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationName, | ||
repeatCount = 1, | ||
}: OauthLogout) { | ||
const integrationId = await this.getIntegrationId({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationName, | ||
}); | ||
for (let i = 0; i < repeatCount; i++) { | ||
await this.integrationLogout({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationId, | ||
}); | ||
} | ||
} | ||
/** | ||
* Wait for syncronization and check the result of sync | ||
* @param {Function} getIntegration - Fetch status of integration | ||
* @param {string} synchronizationType - Set type of syncronization full/incremental | ||
*/ | ||
/** | ||
* Wait for syncronization and check the result of sync | ||
* @param {Function} getIntegration - Fetch status of integration | ||
* @param {string} synchronizationType - Set type of syncronization full/incremental | ||
*/ | ||
async waitForSync({ getIntegration, synchronizationType }: WaitForSync) { | ||
let lastRunSuccess; | ||
let cancelled; | ||
let running; | ||
async waitForSync({ getIntegration, synchronizationType }: WaitForSync) { | ||
let lastRunSuccess; | ||
let cancelled; | ||
let running; | ||
for (;;) { | ||
const integration = await getIntegration(); | ||
const jobRuns = integration.data.jobRuns; | ||
const getJobRunDetail = jobRuns.find((job: { synchronizationTypeId: string }) => { | ||
return job.synchronizationTypeId === synchronizationType; | ||
}); | ||
for (;;) { | ||
const integration = await getIntegration(); | ||
const jobRuns = integration.data.jobRuns; | ||
const getJobRunDetail = jobRuns.find( | ||
(job: { synchronizationTypeId: string }) => { | ||
return job.synchronizationTypeId === synchronizationType; | ||
} | ||
); | ||
running = getJobRunDetail.running; | ||
running = getJobRunDetail.running; | ||
cancelled = getJobRunDetail.cancelled; | ||
cancelled = getJobRunDetail.cancelled; | ||
lastRunSuccess = getJobRunDetail.lastRunSuccess; | ||
lastRunSuccess = getJobRunDetail.lastRunSuccess; | ||
if ((await running) === false) { | ||
break; | ||
} | ||
await new Promise((resolve) => setTimeout(resolve, 5000)); | ||
} | ||
if ((await running) === false) { | ||
break; | ||
} | ||
await new Promise((resolve) => setTimeout(resolve, 5000)); | ||
} | ||
if ((await lastRunSuccess) === false) { | ||
throw new Error(`Sync failed!`); | ||
} else if (cancelled === true) { | ||
throw new Error(`Sync was cancelled!`); | ||
} | ||
if ((await lastRunSuccess) === false) { | ||
throw new Error(`Sync failed!`); | ||
} else if (cancelled === true) { | ||
throw new Error(`Sync was cancelled!`); | ||
} | ||
} | ||
/** | ||
* Run syncronization for specific Integration | ||
* @param {Object} authInstance - Authorized instance for API calls | ||
* @param {string} microappsAdminUrl - Microapps admin url | ||
* @param {string} integrationName - Name of integration | ||
* @param {string} synchronizationType - Set type of syncronization full/incremental | ||
*/ | ||
/** | ||
* Run syncronization for specific Integration | ||
* @param {Object} authInstance - Authorized instance for API calls | ||
* @param {string} microappsAdminUrl - Microapps admin url | ||
* @param {string} integrationName - Name of integration | ||
* @param {string} synchronizationType - Set type of syncronization full/incremental | ||
*/ | ||
async runSynchronization({ | ||
async runSynchronization({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationName, | ||
synchronizationType, | ||
}: RunSynchronization) { | ||
const integrationId = await this.getIntegrationId({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationName, | ||
}); | ||
const integration = await this.getIntegration({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationId, | ||
}); | ||
const jobRuns = integration.data.jobRuns; | ||
const getJobRunDetail = jobRuns.find( | ||
(job: { synchronizationTypeId: string }) => { | ||
return job.synchronizationTypeId === synchronizationType; | ||
} | ||
); | ||
if (getJobRunDetail === undefined) { | ||
await this.startSynchronization({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationName, | ||
integrationId, | ||
synchronizationType, | ||
}: RunSynchronization) { | ||
const integrationId = await this.getIntegrationId({ | ||
}); | ||
await this.waitForSync({ | ||
getIntegration: () => | ||
this.getIntegration({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationName, | ||
}); | ||
const integration = await this.getIntegration({ authInstance, microappsAdminUrl, integrationId }); | ||
const jobRuns = integration.data.jobRuns; | ||
const getJobRunDetail = jobRuns.find((job: { synchronizationTypeId: string }) => { | ||
return job.synchronizationTypeId === synchronizationType; | ||
}); | ||
if (getJobRunDetail === undefined) { | ||
await this.startSynchronization({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationId, | ||
synchronizationType, | ||
}); | ||
await this.waitForSync({ | ||
getIntegration: () => this.getIntegration({ authInstance, microappsAdminUrl, integrationId }), | ||
synchronizationType, | ||
}); | ||
} else if (getJobRunDetail.running === true) { | ||
await this.waitForSync({ | ||
getIntegration: () => this.getIntegration({ authInstance, microappsAdminUrl, integrationId }), | ||
synchronizationType, | ||
}); | ||
} else { | ||
await this.startSynchronization({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationId, | ||
synchronizationType, | ||
}); | ||
await this.waitForSync({ | ||
getIntegration: () => this.getIntegration({ authInstance, microappsAdminUrl, integrationId }), | ||
synchronizationType, | ||
}); | ||
} | ||
} | ||
/** | ||
* Create HTTP Integration | ||
* @param {Object} authInstance - Authorized instance for API calls | ||
* @param {string} microappsAdminUrl - Microapps admin url | ||
* @param {string} integrationName - Name of integration | ||
* @param {string} integrationConfiguration - Additional integration configuration | ||
*/ | ||
async createHTTPIntegration({ | ||
integrationId, | ||
}), | ||
synchronizationType, | ||
}); | ||
} else if (getJobRunDetail.running === true) { | ||
await this.waitForSync({ | ||
getIntegration: () => | ||
this.getIntegration({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationId, | ||
}), | ||
synchronizationType, | ||
}); | ||
} else { | ||
await this.startSynchronization({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationName, | ||
integrationConfiguration, | ||
}: CreateHTTPIntegration) { | ||
const bundleCatalogue = await this.getBundleCatalogue({ authInstance, microappsAdminUrl }); | ||
const bundleCatalogueData = bundleCatalogue.data; | ||
const catalogueDetail = bundleCatalogueData.find((e: any) => e.title === integrationName && e.type === 'HTTP'); | ||
const catalogueId = catalogueDetail.uniqueId; | ||
const createdConnector = await this.updateBundleCatalogue({ authInstance, microappsAdminUrl, catalogueId }); | ||
const integrationId = createdConnector.data.id; | ||
integrationId, | ||
synchronizationType, | ||
}); | ||
await this.updateintegrationConfiguration({ | ||
await this.waitForSync({ | ||
getIntegration: () => | ||
this.getIntegration({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationId, | ||
integrationConfiguration, | ||
}); | ||
return integrationId; | ||
}), | ||
synchronizationType, | ||
}); | ||
} | ||
} | ||
/** | ||
* Wait for process status | ||
* @param {Object} authInstance - Authorized instance for API calls | ||
* @param {string} status - specific status of process | ||
* @param {string} microappsAdminUrl - Microapps admin url | ||
* @param {string} processId - Id of process | ||
*/ | ||
/** | ||
* Create HTTP Integration | ||
* @param {Object} authInstance - Authorized instance for API calls | ||
* @param {string} microappsAdminUrl - Microapps admin url | ||
* @param {string} integrationName - Name of integration | ||
* @param {string} integrationConfiguration - Additional integration configuration | ||
*/ | ||
async waitForProcessStatus({ authInstance, status, microappsAdminUrl, processId }: WaitForProcessStatus) { | ||
let processStatus; | ||
for (let i = 0; i < 35; i++) { | ||
processStatus = await this.getProcessStatus({ authInstance, microappsAdminUrl, processId }); | ||
if (processStatus.data.message !== undefined) { | ||
console.log(processStatus.data.message); | ||
} | ||
async createHTTPIntegration({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationName, | ||
integrationConfiguration, | ||
}: CreateHTTPIntegration) { | ||
const bundleCatalogue = await this.getBundleCatalogue({ | ||
authInstance, | ||
microappsAdminUrl, | ||
}); | ||
const bundleCatalogueData = bundleCatalogue.data; | ||
const catalogueDetail = bundleCatalogueData.find( | ||
(e: any) => e.title === integrationName && e.type === "HTTP" | ||
); | ||
const catalogueId = catalogueDetail.uniqueId; | ||
const createdConnector = await this.updateBundleCatalogue({ | ||
authInstance, | ||
microappsAdminUrl, | ||
catalogueId, | ||
}); | ||
const integrationId = createdConnector.data.id; | ||
if ((await processStatus.data.status) === status) { | ||
break; | ||
} | ||
await new Promise((resolve) => setTimeout(resolve, 5000)); | ||
} | ||
if ((await processStatus.data.status) !== status) { | ||
throw new Error(`Process status is: ${processStatus.data.status}`); | ||
} | ||
return processStatus; | ||
} | ||
await this.updateintegrationConfiguration({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationId, | ||
integrationConfiguration, | ||
}); | ||
/** | ||
* Create Java Integration | ||
* @param {Object} authInstance - Authorized instance for API calls | ||
* @param {string} microappsAdminUrl - Microapps admin url | ||
* @param {string} integrationName - Name of integration | ||
* @param {string} integrationConfiguration - Additional integration configuration | ||
*/ | ||
return integrationId; | ||
} | ||
async createJavaIntegration({ | ||
/** | ||
* Wait for process status | ||
* @param {Object} authInstance - Authorized instance for API calls | ||
* @param {string} status - specific status of process | ||
* @param {string} microappsAdminUrl - Microapps admin url | ||
* @param {string} processId - Id of process | ||
*/ | ||
async waitForProcessStatus({ | ||
authInstance, | ||
status, | ||
microappsAdminUrl, | ||
processId, | ||
}: WaitForProcessStatus) { | ||
let processStatus; | ||
for (let i = 0; i < 35; i++) { | ||
processStatus = await this.getProcessStatus({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationConfiguration, | ||
withEntities = true, | ||
serviceType = null, | ||
serviceKey, | ||
name = '', | ||
}: CreateJavaIntegration) { | ||
let processId: string; | ||
processId, | ||
}); | ||
if (processStatus.data.message !== undefined) { | ||
console.log(processStatus.data.message); | ||
} | ||
const configurationParameters = integrationConfiguration.serviceData.configuration.configurationParameters; | ||
if ((await processStatus.data.status) === status) { | ||
break; | ||
} | ||
await new Promise((resolve) => setTimeout(resolve, 5000)); | ||
} | ||
if ((await processStatus.data.status) !== status) { | ||
throw new Error(`Process status is: ${processStatus.data.status}`); | ||
} | ||
return processStatus; | ||
} | ||
const responseValidation = await this.validateConfiguration({ | ||
authInstance, | ||
microappsAdminUrl, | ||
serviceKey, | ||
configuration: configurationParameters, | ||
}); | ||
/** | ||
* Create Java Integration | ||
* @param {Object} authInstance - Authorized instance for API calls | ||
* @param {string} microappsAdminUrl - Microapps admin url | ||
* @param {string} integrationName - Name of integration | ||
* @param {string} integrationConfiguration - Additional integration configuration | ||
*/ | ||
const responseValidationBody = JSON.stringify(responseValidation.data); | ||
if (!responseValidationBody.includes('ok')) { | ||
throw new Error('Configuration is not valid!'); | ||
} | ||
async createJavaIntegration({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationConfiguration, | ||
withEntities = true, | ||
serviceType = null, | ||
serviceKey, | ||
name = "", | ||
}: CreateJavaIntegration) { | ||
let processId: string; | ||
const app = await this.addApp({ authInstance, microappsAdminUrl, data: integrationConfiguration }); | ||
const configurationParameters = | ||
integrationConfiguration.serviceData.configuration | ||
.configurationParameters; | ||
processId = app.data.processId; | ||
const responseValidation = await this.validateConfiguration({ | ||
authInstance, | ||
microappsAdminUrl, | ||
serviceKey, | ||
configuration: configurationParameters, | ||
}); | ||
const processStatus = await this.waitForProcessStatus({ | ||
authInstance, | ||
getProcessStatus: () => this.getProcessStatus({ authInstance, microappsAdminUrl, processId }), | ||
status: 'DONE', | ||
microappsAdminUrl, | ||
processId, | ||
}); | ||
const responseValidationBody = JSON.stringify(responseValidation.data); | ||
if (!responseValidationBody.includes("ok")) { | ||
throw new Error("Configuration is not valid!"); | ||
} | ||
const integrationId = processStatus.data.detail.service.id; | ||
const app = await this.addApp({ | ||
authInstance, | ||
microappsAdminUrl, | ||
data: integrationConfiguration, | ||
}); | ||
let entities; | ||
let entityFilters; | ||
processId = app.data.processId; | ||
// Some connectors have different flow for getting entities | ||
if (serviceType === 'Service Now' || serviceType === 'Salesforce') { | ||
const services = await this.getIntegration({ authInstance, microappsAdminUrl, integrationId }); | ||
const processStatus = await this.waitForProcessStatus({ | ||
authInstance, | ||
getProcessStatus: () => | ||
this.getProcessStatus({ authInstance, microappsAdminUrl, processId }), | ||
status: "DONE", | ||
microappsAdminUrl, | ||
processId, | ||
}); | ||
entities = services.data.configuration.entities; | ||
const integrationId = processStatus.data.detail.service.id; | ||
entityFilters = services.data.configuration.entityFilters; | ||
} else { | ||
const response = await this.getEntities({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationId, | ||
}); | ||
let entities; | ||
let entityFilters; | ||
processId = response.data.processId; | ||
// Some connectors have different flow for getting entities | ||
if (serviceType === "Service Now" || serviceType === "Salesforce") { | ||
const services = await this.getIntegration({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationId, | ||
}); | ||
await this.waitForProcessStatus({ | ||
authInstance, | ||
getProcessStatus: () => this.getProcessStatus({ authInstance, microappsAdminUrl, processId }), | ||
status: 'DONE', | ||
microappsAdminUrl, | ||
processId, | ||
}); | ||
entities = services.data.configuration.entities; | ||
const processDetail = await this.getProcessStatus({ authInstance, microappsAdminUrl, processId }); | ||
entities = processDetail.data.detail.data.entities; | ||
entityFilters = processDetail.data.detail.data.entityFilters; | ||
} | ||
entityFilters = services.data.configuration.entityFilters; | ||
} else { | ||
const response = await this.getEntities({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationId, | ||
}); | ||
const entityNames: any[] = []; | ||
processId = response.data.processId; | ||
entities.forEach((el: { name: any }) => entityNames.push(el.name)); | ||
await this.waitForProcessStatus({ | ||
authInstance, | ||
getProcessStatus: () => | ||
this.getProcessStatus({ authInstance, microappsAdminUrl, processId }), | ||
status: "DONE", | ||
microappsAdminUrl, | ||
processId, | ||
}); | ||
const entityData = { | ||
entityNames: entityNames, | ||
entityAttributeNamesMap: {}, | ||
entityFilters: entityFilters, | ||
}; | ||
if (withEntities) { | ||
const entity = await this.createEntity({ authInstance, microappsAdminUrl, integrationId, entityData }); | ||
processId = entity.data.processId; | ||
await this.waitForProcessStatus({ | ||
authInstance, | ||
getProcessStatus: () => this.getProcessStatus({ authInstance, microappsAdminUrl, processId }), | ||
status: 'DONE', | ||
microappsAdminUrl, | ||
processId, | ||
}); | ||
await this.finalizeConfig({ authInstance, microappsAdminUrl, integrationId }); | ||
} | ||
const processDetail = await this.getProcessStatus({ | ||
authInstance, | ||
microappsAdminUrl, | ||
processId, | ||
}); | ||
entities = processDetail.data.detail.data.entities; | ||
entityFilters = processDetail.data.detail.data.entityFilters; | ||
} | ||
/** | ||
* Get type of Integration | ||
* @param {Object} authInstance - Authorized instance for API calls | ||
* @param {string} microappsAdminUrl - Microapps admin url | ||
* @param {string} integrationName - Name of integration | ||
*/ | ||
const entityNames: any[] = []; | ||
async getIntegrationType({ authInstance, microappsAdminUrl, integrationName }: GetIntegrationType) { | ||
const integrations = await this.getIntegrations({ authInstance, microappsAdminUrl }); | ||
entities.forEach((el: { name: any }) => entityNames.push(el.name)); | ||
const integrationsData = integrations.data; | ||
const entityData = { | ||
entityNames: entityNames, | ||
entityAttributeNamesMap: {}, | ||
entityFilters: entityFilters, | ||
}; | ||
const findIntegrationType = integrationsData.find((integration: { title: string }) => { | ||
return integration.title === integrationName; | ||
}); | ||
if (withEntities) { | ||
const entity = await this.createEntity({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationId, | ||
entityData, | ||
}); | ||
const integrationType = findIntegrationType.serviceType; | ||
return integrationType; | ||
} | ||
processId = entity.data.processId; | ||
/** | ||
* Get status of Integration | ||
* @param {Object} authInstance - Authorized instance for API calls | ||
* @param {string} microappsAdminUrl - Microapps admin url | ||
* @param {string} integrationName - Name of integration | ||
*/ | ||
async getStatusIntegration({ authInstance, microappsAdminUrl, integrationName }: GetStatusIntegration) { | ||
try { | ||
const serviceId = await this.getIntegrationId({ authInstance, microappsAdminUrl, integrationName }); | ||
return serviceId; | ||
} catch (e) { | ||
return null; | ||
} | ||
await this.waitForProcessStatus({ | ||
authInstance, | ||
getProcessStatus: () => | ||
this.getProcessStatus({ authInstance, microappsAdminUrl, processId }), | ||
status: "DONE", | ||
microappsAdminUrl, | ||
processId, | ||
}); | ||
await this.finalizeConfig({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationId, | ||
}); | ||
} | ||
} | ||
/** | ||
* Import integration | ||
* @param {Object} authInstance - Authorized instance for API calls | ||
* @param {string} microappsAdminUrl - Microapps admin url | ||
* @param {string} pathToFile - path to file.mapp which should be imported | ||
*/ | ||
/** | ||
* Get type of Integration | ||
* @param {Object} authInstance - Authorized instance for API calls | ||
* @param {string} microappsAdminUrl - Microapps admin url | ||
* @param {string} integrationName - Name of integration | ||
*/ | ||
async importIntegration({ authInstance, microappsAdminUrl, pathToFile }: ImportIntegration) { | ||
const form: any = new FormData(); | ||
let response; | ||
async getIntegrationType({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationName, | ||
}: GetIntegrationType) { | ||
const integrations = await this.getIntegrations({ | ||
authInstance, | ||
microappsAdminUrl, | ||
}); | ||
form.append('file', fs.createReadStream(path.resolve(__dirname, pathToFile))); | ||
const integrationsData = integrations.data; | ||
try { | ||
response = await authInstance({ | ||
url: `${microappsAdminUrl}/api/service/import`, | ||
method: 'POST', | ||
headers: { | ||
'content-type': `multipart/form-data; boundary=${form._boundary}`, | ||
}, | ||
data: form, | ||
}); | ||
} catch (error) { | ||
throw error.stack; | ||
} | ||
const findIntegrationType = integrationsData.find( | ||
(integration: { title: string }) => { | ||
return integration.title === integrationName; | ||
} | ||
); | ||
await assert.deepStrictEqual( | ||
response.status, | ||
200, | ||
`Response status ${response.status} doesn't match expected 200` | ||
); | ||
return response; | ||
} | ||
const integrationType = findIntegrationType.serviceType; | ||
return integrationType; | ||
} | ||
/** | ||
* Rename integration | ||
* @param {Object} authInstance - Authorized instance for API calls | ||
* @param {string} microappsAdminUrl - Microapps admin url | ||
* @param {string} integrationName - Name of integration | ||
* @param {string} newIntegrationName - New Name of integration | ||
* @param {string} integrationConfiguration - Configuration for integration | ||
*/ | ||
/** | ||
* Get status of Integration | ||
* @param {Object} authInstance - Authorized instance for API calls | ||
* @param {string} microappsAdminUrl - Microapps admin url | ||
* @param {string} integrationName - Name of integration | ||
*/ | ||
async renameIntegration({ | ||
async getStatusIntegration({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationName, | ||
}: GetStatusIntegration) { | ||
try { | ||
const serviceId = await this.getIntegrationId({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationName, | ||
newIntegrationName, | ||
integrationConfiguration, | ||
}: RenameIntegration) { | ||
const integrationType = await this.getIntegrationType({ authInstance, microappsAdminUrl, integrationName }); | ||
const data = { | ||
serviceType: integrationType, | ||
title: newIntegrationName, | ||
}; | ||
const integrationId = await this.getStatusIntegration({ authInstance, microappsAdminUrl, integrationName }); | ||
}); | ||
return serviceId; | ||
} catch (e) { | ||
return null; | ||
} | ||
} | ||
await this.updateintegrationConfiguration({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationId, | ||
integrationConfiguration, | ||
}); | ||
/** | ||
* Import integration | ||
* @param {Object} authInstance - Authorized instance for API calls | ||
* @param {string} microappsAdminUrl - Microapps admin url | ||
* @param {string} pathToFile - path to file.mapp which should be imported | ||
*/ | ||
const integrations = await this.getIntegrations({ authInstance, microappsAdminUrl }); | ||
const integrationsData = integrations.data; | ||
const IntegrationDetail = integrationsData.filter((e: { title: any; id: any }) => { | ||
return e.title === integrationName && e.id === newIntegrationName; | ||
}); | ||
async importIntegration({ | ||
authInstance, | ||
microappsAdminUrl, | ||
pathToFile, | ||
}: ImportIntegration) { | ||
const form: any = new FormData(); | ||
let response; | ||
console.log( | ||
`Integration ${integrationName} with id: ${IntegrationDetail[0].id} was renamed to: ${integrationsData[0].title}` | ||
); | ||
form.append( | ||
"file", | ||
fs.createReadStream(path.resolve(__dirname, pathToFile)) | ||
); | ||
try { | ||
response = await authInstance({ | ||
url: `${microappsAdminUrl}/api/service/import`, | ||
method: "POST", | ||
headers: { | ||
"content-type": `multipart/form-data; boundary=${form._boundary}`, | ||
}, | ||
data: form, | ||
}); | ||
} catch (error) { | ||
throw error.stack; | ||
} | ||
/** | ||
* Export Application | ||
* @param {Object} authInstance - Authorized instance for API calls | ||
* @param {string} microappsAdminUrl - Microapps admin url | ||
* @param {string} appId - Id of target App | ||
* @param {string} pathToFile - path where file should be saved | ||
*/ | ||
await assert.deepStrictEqual( | ||
response.status, | ||
200, | ||
`Response status ${response.status} doesn't match expected 200` | ||
); | ||
return response; | ||
} | ||
async exportApp({ authInstance, microappsAdminUrl, appId, pathToFile }: ExportApp) { | ||
let response; | ||
try { | ||
response = await authInstance({ | ||
method: 'GET', | ||
url: `${microappsAdminUrl}/api/app/${appId}/export`, | ||
responseType: 'stream', | ||
}); | ||
} catch (error) { | ||
throw error.stack; | ||
} | ||
await response.data.pipe(fs.createWriteStream(path.resolve(__dirname, pathToFile))); | ||
/** | ||
* Rename integration | ||
* @param {Object} authInstance - Authorized instance for API calls | ||
* @param {string} microappsAdminUrl - Microapps admin url | ||
* @param {string} integrationName - Name of integration | ||
* @param {string} newIntegrationName - New Name of integration | ||
* @param {string} integrationConfiguration - Configuration for integration | ||
*/ | ||
async renameIntegration({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationName, | ||
newIntegrationName, | ||
integrationConfiguration, | ||
}: RenameIntegration) { | ||
const integrationType = await this.getIntegrationType({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationName, | ||
}); | ||
const data = { | ||
serviceType: integrationType, | ||
title: newIntegrationName, | ||
}; | ||
const integrationId = await this.getStatusIntegration({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationName, | ||
}); | ||
await this.updateintegrationConfiguration({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationId, | ||
integrationConfiguration, | ||
}); | ||
const integrations = await this.getIntegrations({ | ||
authInstance, | ||
microappsAdminUrl, | ||
}); | ||
const integrationsData = integrations.data; | ||
const IntegrationDetail = integrationsData.filter( | ||
(e: { title: any; id: any }) => { | ||
return e.title === integrationName && e.id === newIntegrationName; | ||
} | ||
); | ||
console.log( | ||
`Integration ${integrationName} with id: ${IntegrationDetail[0].id} was renamed to: ${integrationsData[0].title}` | ||
); | ||
} | ||
/** | ||
* Export Application | ||
* @param {Object} authInstance - Authorized instance for API calls | ||
* @param {string} microappsAdminUrl - Microapps admin url | ||
* @param {string} appId - Id of target App | ||
* @param {string} pathToFile - path where file should be saved | ||
*/ | ||
async exportApp({ | ||
authInstance, | ||
microappsAdminUrl, | ||
appId, | ||
pathToFile, | ||
}: ExportApp) { | ||
let response; | ||
try { | ||
response = await authInstance({ | ||
method: "GET", | ||
url: `${microappsAdminUrl}/api/app/${appId}/export`, | ||
responseType: "stream", | ||
}); | ||
} catch (error) { | ||
throw error.stack; | ||
} | ||
await response.data.pipe( | ||
fs.createWriteStream(path.resolve(__dirname, pathToFile)) | ||
); | ||
} | ||
/** | ||
* Get Id of Microapp | ||
* @param {Object} authInstance - Authorized instance for API calls | ||
* @param {string} microappsAdminUrl - Microapps admin url | ||
* @param {string} integrationId - Name of integration | ||
* @param {string} appName - Name Application | ||
*/ | ||
/** | ||
* Get Id of Microapp | ||
* @param {Object} authInstance - Authorized instance for API calls | ||
* @param {string} microappsAdminUrl - Microapps admin url | ||
* @param {string} integrationId - Name of integration | ||
* @param {string} appName - Name Application | ||
*/ | ||
async getMicroAppId({ authInstance, microappsAdminUrl, integrationId, appName }: GetMicroAppId) { | ||
let apps; | ||
try { | ||
apps = await this.getApps({ authInstance, microappsAdminUrl }); | ||
const appsData = apps.data; | ||
const getAppDetail = appsData.filter( | ||
(app: { app: { title: string; serviceId: string } }) => | ||
app.app.title === appName && app.app.serviceId === integrationId | ||
); | ||
async getMicroAppId({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationId, | ||
appName, | ||
}: GetMicroAppId) { | ||
let apps; | ||
try { | ||
apps = await this.getApps({ authInstance, microappsAdminUrl }); | ||
const appsData = apps.data; | ||
const getAppDetail = appsData.filter( | ||
(app: { app: { title: string; serviceId: string } }) => | ||
app.app.title === appName && app.app.serviceId === integrationId | ||
); | ||
return getAppDetail[0].id; | ||
} catch (e) { | ||
console.log(e); | ||
return null; | ||
} | ||
return getAppDetail[0].id; | ||
} catch (e) { | ||
console.log(e); | ||
return null; | ||
} | ||
} | ||
/** | ||
* Get Id of Notification | ||
* @param {Object} authInstance - Authorized instance for API calls | ||
* @param {string} microappsAdminUrl - Microapps admin url | ||
* @param {string} appId - Name of App | ||
* @param {string} notificationName - Name of Notification | ||
*/ | ||
/** | ||
* Get Id of Notification | ||
* @param {Object} authInstance - Authorized instance for API calls | ||
* @param {string} microappsAdminUrl - Microapps admin url | ||
* @param {string} appId - Name of App | ||
* @param {string} notificationName - Name of Notification | ||
*/ | ||
async getNotificationId({ authInstance, microappsAdminUrl, appId, notificationName }: GetNotificationId) { | ||
const notifications = await this.getNotifications({ | ||
authInstance, | ||
microappsAdminUrl, | ||
appId, | ||
}); | ||
async getNotificationId({ | ||
authInstance, | ||
microappsAdminUrl, | ||
appId, | ||
notificationName, | ||
}: GetNotificationId) { | ||
const notifications = await this.getNotifications({ | ||
authInstance, | ||
microappsAdminUrl, | ||
appId, | ||
}); | ||
const notificationsData = notifications.data; | ||
const notificationsData = notifications.data; | ||
const getNotificationId = notificationsData.find((e: { label: string }) => { | ||
return e.label === notificationName; | ||
}); | ||
const getNotificationId = notificationsData.find((e: { label: string }) => { | ||
return e.label === notificationName; | ||
}); | ||
const notificationId = getNotificationId.id; | ||
const notificationId = getNotificationId.id; | ||
return notificationId; | ||
} | ||
return notificationId; | ||
} | ||
/** | ||
* Run a Event | ||
* @param {Object} authInstance - Authorized instance for API calls | ||
* @param {string} microappsAdminUrl - Microapps admin url | ||
* @param {string} integrationName - Name of Integration | ||
* @param {string} appName - Name of App | ||
* @param {string} notificationName - Name of Notification | ||
*/ | ||
/** | ||
* Run a Event | ||
* @param {Object} authInstance - Authorized instance for API calls | ||
* @param {string} microappsAdminUrl - Microapps admin url | ||
* @param {string} integrationName - Name of Integration | ||
* @param {string} appName - Name of App | ||
* @param {string} notificationName - Name of Notification | ||
*/ | ||
async runEvent({ authInstance, microappsAdminUrl, integrationName, appName, notificationName }: RunEvent) { | ||
let notifications; | ||
const integrationId = await this.getIntegrationId({ authInstance, microappsAdminUrl, integrationName }); | ||
async runEvent({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationName, | ||
appName, | ||
notificationName, | ||
}: RunEvent) { | ||
let notifications; | ||
const integrationId = await this.getIntegrationId({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationName, | ||
}); | ||
const appId = await this.getMicroAppId({ authInstance, microappsAdminUrl, integrationId, appName }); | ||
const appId = await this.getMicroAppId({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationId, | ||
appName, | ||
}); | ||
const notificationId = await this.getNotificationId({ | ||
authInstance, | ||
appId, | ||
microappsAdminUrl, | ||
notificationName, | ||
}); | ||
const notificationId = await this.getNotificationId({ | ||
authInstance, | ||
appId, | ||
microappsAdminUrl, | ||
notificationName, | ||
}); | ||
await this.runNotificationEvent({ authInstance, microappsAdminUrl, notificationId }); | ||
await this.runNotificationEvent({ | ||
authInstance, | ||
microappsAdminUrl, | ||
notificationId, | ||
}); | ||
for (let i = 0; i < 10; i++) { | ||
notifications = await this.getNotifications({ authInstance, microappsAdminUrl, appId }); | ||
for (let i = 0; i < 10; i++) { | ||
notifications = await this.getNotifications({ | ||
authInstance, | ||
microappsAdminUrl, | ||
appId, | ||
}); | ||
const running = notifications.data[0].running; | ||
const running = notifications.data[0].running; | ||
if ((await running) === false) { | ||
break; | ||
} | ||
if ((await running) === false) { | ||
break; | ||
} | ||
await new Promise((resolve) => setTimeout(resolve, 5000)); | ||
} | ||
const lastRunStatus = notifications.data[0].lastRunStatus; | ||
if ((await lastRunStatus) !== 'SUCCESS') { | ||
throw new Error('Event run failed!'); | ||
} | ||
await new Promise((resolve) => setTimeout(resolve, 5000)); | ||
} | ||
const lastRunStatus = notifications.data[0].lastRunStatus; | ||
if ((await lastRunStatus) !== "SUCCESS") { | ||
throw new Error("Event run failed!"); | ||
} | ||
} | ||
async checkAppMissconfigurations({ authInstance, microappsAdminUrl, appId }: CheckAppMissconfigurations) { | ||
const response = await this.integrityCheck({ authInstance, microappsAdminUrl }); | ||
const responseBody = response.data; | ||
const missconfigurations: any = responseBody.filter((e: { appId: string }) => e.appId === appId); | ||
async checkAppMissconfigurations({ | ||
authInstance, | ||
microappsAdminUrl, | ||
appId, | ||
}: CheckAppMissconfigurations) { | ||
const response = await this.integrityCheck({ | ||
authInstance, | ||
microappsAdminUrl, | ||
}); | ||
const responseBody = response.data; | ||
const missconfigurations: any = responseBody.filter( | ||
(e: { appId: string }) => e.appId === appId | ||
); | ||
if (!Array.isArray(missconfigurations) || !missconfigurations.length) { | ||
console.log(`appId: ${appId} has no missconfigurations`); | ||
} | ||
console.log('missconfigurations: ', missconfigurations); | ||
if (!Array.isArray(missconfigurations) || !missconfigurations.length) { | ||
console.log(`appId: ${appId} has no missconfigurations`); | ||
} | ||
//TO-DO add config as parametr | ||
async addSubscriber({ authInstance, appId, user, config }: AddSubscriber) { | ||
const { microappsAdminUrl, citrixCloudCustomerId, cwaAPI, workspaceIdentityProvider } = config; | ||
// Get Domains | ||
const domains = await this.getDomain({ | ||
authInstance, | ||
cwaAPI, | ||
citrixCloudCustomerId, | ||
workspaceIdentityProvider, | ||
}); | ||
console.log("missconfigurations: ", missconfigurations); | ||
} | ||
const actionSubscribe = 'Add'; | ||
let domainName; | ||
let forestName; | ||
let idpType; | ||
//TO-DO add config as parametr | ||
async addSubscriber({ authInstance, appId, user, config }: AddSubscriber) { | ||
const { | ||
microappsAdminUrl, | ||
citrixCloudCustomerId, | ||
cwaAPI, | ||
workspaceIdentityProvider, | ||
} = config; | ||
// Get Domains | ||
const domains = await this.getDomain({ | ||
authInstance, | ||
cwaAPI, | ||
citrixCloudCustomerId, | ||
workspaceIdentityProvider, | ||
}); | ||
switch (workspaceIdentityProvider) { | ||
case 'ad': | ||
case 'netscaler': | ||
domainName = domains.data.domains[0].domainName; | ||
forestName = domains.data.domains[0].forestName; | ||
idpType = 'AD'; | ||
break; | ||
case 'aad': | ||
const domainsData = domains.data; | ||
const domainDetail = domainsData.filter((domain: { idpType: string }) => { | ||
return domain.idpType === 'AzureAd'; | ||
}); | ||
domainName = 'todo'; | ||
forestName = domainDetail[0].idpProperties.tid; | ||
idpType = 'AZUREAD'; | ||
break; | ||
case 'okta': | ||
domainName = null; | ||
forestName = null; | ||
idpType = 'OKTA'; | ||
break; | ||
default: | ||
console.log( | ||
`Adding subscribers is currently not implemented for this idp: ${workspaceIdentityProvider}` | ||
); | ||
break; | ||
} | ||
const actionSubscribe = "Add"; | ||
let domainName; | ||
let forestName; | ||
let idpType; | ||
// Get user | ||
const users = await this.getUsers({ | ||
authInstance, | ||
cwaAPI, | ||
domainName, | ||
forestName, | ||
appId, | ||
query: user, | ||
citrixCloudCustomerId, | ||
idpType, | ||
}); | ||
let userDetail = users.data.results; | ||
switch (workspaceIdentityProvider) { | ||
case "ad": | ||
case "netscaler": | ||
domainName = domains.data.domains[0].domainName; | ||
forestName = domains.data.domains[0].forestName; | ||
idpType = "AD"; | ||
break; | ||
case "aad": | ||
const domainsData = domains.data; | ||
const domainDetail = domainsData.filter( | ||
(domain: { idpType: string }) => { | ||
return domain.idpType === "AzureAd"; | ||
} | ||
); | ||
domainName = "todo"; | ||
forestName = domainDetail[0].idpProperties.tid; | ||
idpType = "AZUREAD"; | ||
break; | ||
case "okta": | ||
domainName = null; | ||
forestName = null; | ||
idpType = "OKTA"; | ||
break; | ||
default: | ||
console.log( | ||
`Adding subscribers is currently not implemented for this idp: ${workspaceIdentityProvider}` | ||
); | ||
break; | ||
} | ||
if (userDetail.length > 1) { | ||
// filter group to subscribe | ||
const userData = users.data.results; | ||
userDetail = userData.filter((e: { accountName: string }) => { | ||
return e.accountName === user; | ||
}); | ||
} | ||
// Get user | ||
const users = await this.getUsers({ | ||
authInstance, | ||
cwaAPI, | ||
domainName, | ||
forestName, | ||
appId, | ||
query: user, | ||
citrixCloudCustomerId, | ||
idpType, | ||
}); | ||
let userDetail = users.data.results; | ||
// Update Subscribers | ||
await this.updateSubscribers({ | ||
authInstance, | ||
microappsAdminUrl, | ||
assign: actionSubscribe, | ||
userDetail, | ||
appId, | ||
domainName, | ||
forestName, | ||
workspaceIdentityProvider, | ||
}); | ||
await this.getSubscribers({ | ||
authInstance, | ||
microappsAdminUrl, | ||
appId, | ||
}); | ||
if (userDetail.length > 1) { | ||
// filter group to subscribe | ||
const userData = users.data.results; | ||
userDetail = userData.filter((e: { accountName: string }) => { | ||
return e.accountName === user; | ||
}); | ||
} | ||
async addSubscribers({ authInstance, integrationName, microapps, microappsAdminUrl, config }: AddSubscribers) { | ||
const integrationId = await this.getIntegrationId({ authInstance, microappsAdminUrl, integrationName }); | ||
const subscribe = async ({ microapps, microapp, authInstance, integrationId }: Subscribe) => { | ||
console.log(`[${integrationName}] - Adding subscribers for: ${microapp}`); | ||
const subscribers = microapps[microapp].subscribers; | ||
const microappId = await this.getMicroAppId({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationId, | ||
appName: microapp, | ||
}); | ||
for (const subscriber of subscribers) { | ||
await this.addSubscriber({ | ||
authInstance, | ||
appId: microappId, | ||
user: subscriber, | ||
config | ||
}); | ||
} | ||
return { microapp }; | ||
}; | ||
// Update Subscribers | ||
await this.updateSubscribers({ | ||
authInstance, | ||
microappsAdminUrl, | ||
assign: actionSubscribe, | ||
userDetail, | ||
appId, | ||
domainName, | ||
forestName, | ||
workspaceIdentityProvider, | ||
}); | ||
const microappsPromises = []; | ||
for (const microapp in microapps) { | ||
microappsPromises.push(subscribe({ microapps, microapp, authInstance, integrationId })); | ||
} | ||
await this.getSubscribers({ | ||
authInstance, | ||
microappsAdminUrl, | ||
appId, | ||
}); | ||
} | ||
async addSubscribers({ | ||
authInstance, | ||
integrationName, | ||
microapps, | ||
microappsAdminUrl, | ||
config, | ||
}: AddSubscribers) { | ||
const integrationId = await this.getIntegrationId({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationName, | ||
}); | ||
return await Promise.all(microappsPromises); | ||
const subscribe = async ({ | ||
microapps, | ||
microapp, | ||
authInstance, | ||
integrationId, | ||
}: Subscribe) => { | ||
console.log(`[${integrationName}] - Adding subscribers for: ${microapp}`); | ||
const subscribers = microapps[microapp].subscribers; | ||
const microappId = await this.getMicroAppId({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationId, | ||
appName: microapp, | ||
}); | ||
for (const subscriber of subscribers) { | ||
await this.addSubscriber({ | ||
authInstance, | ||
appId: microappId, | ||
user: subscriber, | ||
config, | ||
}); | ||
} | ||
return { microapp }; | ||
}; | ||
const microappsPromises = []; | ||
for (const microapp in microapps) { | ||
microappsPromises.push( | ||
subscribe({ microapps, microapp, authInstance, integrationId }) | ||
); | ||
} | ||
/** | ||
* Import Integration from an exported Integration file | ||
* | ||
* @param {Page} page - Methods to interact with a single tab or extension background page in Browser | ||
* @param {string} filePath - Path to the exported Integration file that will be imported | ||
*/ | ||
async importIntegrationUI({ page, microappsAdminUrl, filePath }: ImportIntegrationUI) { | ||
await page.waitForSelector('[data-testid="add-integration-button"]'); | ||
await page.click('[data-testid="add-integration-button"]'); | ||
await page.waitForSelector('[data-testid="new-integration-upload"]'); | ||
await page.click('[data-testid="new-integration-upload"]'); | ||
return await Promise.all(microappsPromises); | ||
} | ||
/** | ||
* Import Integration from an exported Integration file | ||
* | ||
* @param {Page} page - Methods to interact with a single tab or extension background page in Browser | ||
* @param {string} filePath - Path to the exported Integration file that will be imported | ||
*/ | ||
async importIntegrationUI({ | ||
page, | ||
microappsAdminUrl, | ||
filePath, | ||
}: ImportIntegrationUI) { | ||
await page.waitForSelector('[data-testid="add-integration-button"]'); | ||
await page.click('[data-testid="add-integration-button"]'); | ||
const uploadFile: any = await page.$('input[type=file]'); | ||
await uploadFile.setInputFiles(path.resolve(__dirname, filePath)); | ||
await page.waitForSelector('[data-testid="new-integration-upload"]'); | ||
await page.click('[data-testid="new-integration-upload"]'); | ||
await page.waitForSelector('[data-testid="upload-submit-button"]'); | ||
await page.click('[data-testid="upload-submit-button"]'); | ||
const uploadFile: any = await page.$("input[type=file]"); | ||
await uploadFile.setInputFiles(path.resolve(__dirname, filePath)); | ||
await page.waitForResponse( | ||
(response: { url: () => string; status: () => number }) => | ||
response.url() === `${microappsAdminUrl}/api/service/import` && response.status() === 200 | ||
); | ||
} | ||
await page.waitForSelector('[data-testid="upload-submit-button"]'); | ||
await page.click('[data-testid="upload-submit-button"]'); | ||
/** | ||
* Imports MicroApp to @param integrationName Integration from an exported MicroApp file | ||
* | ||
* @param {Page} page - Methods to interact with a single tab or extension background page in Browser | ||
* @param {string} microappsAdminUrl - MicroApps Admin URL | ||
* @param {string} filePath - Path to the exported MicroApp file that will be imported | ||
* @param {string} integrationName - Name of Integration in which the MicroApp will be imported | ||
*/ | ||
async importMicroAppUI({ page, microappsAdminUrl, filePath, integrationName }: ImportMicroAppUI) { | ||
await page.waitForSelector( | ||
`//div[@data-testid="integration-name-${integrationName}"] //button[@data-testid="toggle-integration-options-dropdown"]` | ||
); | ||
await page.click( | ||
`//div[@data-testid="integration-name-${integrationName}"] //button[@data-testid="toggle-integration-options-dropdown"]` | ||
); | ||
await page.waitForResponse( | ||
(response: { url: () => string; status: () => number }) => | ||
response.url() === `${microappsAdminUrl}/api/service/import` && | ||
response.status() === 200 | ||
); | ||
} | ||
await page.waitForSelector( | ||
`//div[@data-testid="integration-name-${integrationName}"] //button[@data-testid="open-import-app"]` | ||
); | ||
await page.click( | ||
`//div[@data-testid="integration-name-${integrationName}"] //button[@data-testid="open-import-app"]` | ||
); | ||
/** | ||
* Imports MicroApp to @param integrationName Integration from an exported MicroApp file | ||
* | ||
* @param {Page} page - Methods to interact with a single tab or extension background page in Browser | ||
* @param {string} microappsAdminUrl - MicroApps Admin URL | ||
* @param {string} filePath - Path to the exported MicroApp file that will be imported | ||
* @param {string} integrationName - Name of Integration in which the MicroApp will be imported | ||
*/ | ||
async importMicroAppUI({ | ||
page, | ||
microappsAdminUrl, | ||
filePath, | ||
integrationName, | ||
}: ImportMicroAppUI) { | ||
await page.waitForSelector( | ||
`//div[@data-testid="integration-name-${integrationName}"] //button[@data-testid="toggle-integration-options-dropdown"]` | ||
); | ||
await page.click( | ||
`//div[@data-testid="integration-name-${integrationName}"] //button[@data-testid="toggle-integration-options-dropdown"]` | ||
); | ||
const uploadFile: any = await page.$('input[type=file]'); | ||
await uploadFile.setInputFiles(path.resolve(__dirname, filePath)); | ||
await page.waitForSelector('[data-testid="upload-submit-button"]'); | ||
await page.click('[data-testid="upload-submit-button"]'); | ||
await page.waitForSelector( | ||
`//div[@data-testid="integration-name-${integrationName}"] //button[@data-testid="open-import-app"]` | ||
); | ||
await page.click( | ||
`//div[@data-testid="integration-name-${integrationName}"] //button[@data-testid="open-import-app"]` | ||
); | ||
await page.waitForResponse( | ||
(response: { url: () => string; status: () => number }) => | ||
response.url() === `${microappsAdminUrl}/api/app` && response.status() === 200 | ||
); | ||
} | ||
const uploadFile: any = await page.$("input[type=file]"); | ||
await uploadFile.setInputFiles(path.resolve(__dirname, filePath)); | ||
await page.waitForSelector('[data-testid="upload-submit-button"]'); | ||
await page.click('[data-testid="upload-submit-button"]'); | ||
/** | ||
* Exports @param integrationName integation | ||
* | ||
* @param {Page} page - Methods to interact with a single tab or extension background page in Browser | ||
* @param {string} integrationName - Name of Integration which will be exported | ||
*/ | ||
async exportIntegrationUI({ page, integrationName }: ExportIntegrationUI) { | ||
await page.waitForSelector( | ||
`//div[@data-testid="integration-name-${integrationName}"] //button[@data-testid="toggle-integration-options-dropdown"]` | ||
); | ||
await page.click( | ||
`//div[@data-testid="integration-name-${integrationName}"] //button[@data-testid="toggle-integration-options-dropdown"]` | ||
); | ||
await page.waitForResponse( | ||
(response: { url: () => string; status: () => number }) => | ||
response.url() === `${microappsAdminUrl}/api/app` && | ||
response.status() === 200 | ||
); | ||
} | ||
await page.waitForSelector( | ||
`//div[@data-testid="integration-name-${integrationName}"] //button[@data-testid="open-export-integration"]` | ||
); | ||
await page.click( | ||
`//div[@data-testid="integration-name-${integrationName}"] //button[@data-testid="open-export-integration"]` | ||
); | ||
/** | ||
* Exports @param integrationName integation | ||
* | ||
* @param {Page} page - Methods to interact with a single tab or extension background page in Browser | ||
* @param {string} integrationName - Name of Integration which will be exported | ||
*/ | ||
async exportIntegrationUI({ page, integrationName }: ExportIntegrationUI) { | ||
await page.waitForSelector( | ||
`//div[@data-testid="integration-name-${integrationName}"] //button[@data-testid="toggle-integration-options-dropdown"]` | ||
); | ||
await page.click( | ||
`//div[@data-testid="integration-name-${integrationName}"] //button[@data-testid="toggle-integration-options-dropdown"]` | ||
); | ||
await page.waitForSelector(`//legend[(text()= 'Include Microapps')]`); | ||
await page.waitForSelector( | ||
`//div[@data-testid="integration-name-${integrationName}"] //button[@data-testid="open-export-integration"]` | ||
); | ||
await page.click( | ||
`//div[@data-testid="integration-name-${integrationName}"] //button[@data-testid="open-export-integration"]` | ||
); | ||
await page.click(`//button[@data-testid="export-integration-commit-button"]`); | ||
await page.waitForSelector(`//legend[(text()= 'Include Microapps')]`); | ||
const download = await page.waitForEvent('download'); | ||
await page.click( | ||
`//button[@data-testid="export-integration-commit-button"]` | ||
); | ||
if ((await download.path()) === null) { | ||
throw new Error('No file was downloaded'); | ||
} | ||
const download = await page.waitForEvent("download"); | ||
if ((await download.path()) === null) { | ||
throw new Error("No file was downloaded"); | ||
} | ||
} | ||
/** | ||
* Export @param appName MicroApp from @param integrationName Integration | ||
* | ||
* @param {Page} page - Methods to interact with a single tab or extension background page in Browser | ||
* @param {string} integrationName - Name of Integration in which the MicroApp will be imported | ||
* @param {string} appName - Name of MicroApp that will be exported | ||
*/ | ||
async exportMicroAppsUI({ page, integrationName, appName }: ExportMicroAppUI) { | ||
await page.waitForSelector( | ||
`//div[@data-testid="integration-name-${integrationName}"] //tr[descendant::a[contains(text(), "${appName}")]] //button[starts-with(@class, "PlainButton")]` | ||
); | ||
await page.click( | ||
`//div[@data-testid="integration-name-${integrationName}"] //tr[descendant::a[contains(text(), "${appName}")]] //button[starts-with(@class, "PlainButton")]` | ||
); | ||
await page.waitForSelector( | ||
`//div[@data-testid="integration-name-${integrationName}"] //tr[descendant::a[contains(text(), "${appName}")]] //button[@data-testid="do-app-export"]` | ||
); | ||
await page.click( | ||
`//div[@data-testid="integration-name-${integrationName}"] //tr[descendant::a[contains(text(), "${appName}")]] //button[@data-testid="do-app-export"]` | ||
); | ||
const download = await page.waitForEvent('download'); | ||
/** | ||
* Export @param appName MicroApp from @param integrationName Integration | ||
* | ||
* @param {Page} page - Methods to interact with a single tab or extension background page in Browser | ||
* @param {string} integrationName - Name of Integration in which the MicroApp will be imported | ||
* @param {string} appName - Name of MicroApp that will be exported | ||
*/ | ||
async exportMicroAppsUI({ | ||
page, | ||
integrationName, | ||
appName, | ||
}: ExportMicroAppUI) { | ||
await page.waitForSelector( | ||
`//div[@data-testid="integration-name-${integrationName}"] //tr[descendant::a[contains(text(), "${appName}")]] //button[starts-with(@class, "PlainButton")]` | ||
); | ||
await page.click( | ||
`//div[@data-testid="integration-name-${integrationName}"] //tr[descendant::a[contains(text(), "${appName}")]] //button[starts-with(@class, "PlainButton")]` | ||
); | ||
await page.waitForSelector( | ||
`//div[@data-testid="integration-name-${integrationName}"] //tr[descendant::a[contains(text(), "${appName}")]] //button[@data-testid="do-app-export"]` | ||
); | ||
await page.click( | ||
`//div[@data-testid="integration-name-${integrationName}"] //tr[descendant::a[contains(text(), "${appName}")]] //button[@data-testid="do-app-export"]` | ||
); | ||
const download = await page.waitForEvent("download"); | ||
if ((await download.path()) === null) { | ||
throw new Error('No file was downloaded'); | ||
} | ||
if ((await download.path()) === null) { | ||
throw new Error("No file was downloaded"); | ||
} | ||
} | ||
/** | ||
* Returns last duration of Synchronization | ||
* | ||
* @param {Object} authInstance - Authorized instance for API calls | ||
* @param {string} microappsAdminUrl - Microapps admin url | ||
* @param {string} integrationName - Name of Integration | ||
*/ | ||
async getLastTimeSync({ authInstance, microappsAdminUrl, integrationName }: GetLastSyncTime) { | ||
const regex = new RegExp(/\d*:\d*:\d*.\d*/); | ||
/** | ||
* Returns last duration of Synchronization | ||
* | ||
* @param {Object} authInstance - Authorized instance for API calls | ||
* @param {string} microappsAdminUrl - Microapps admin url | ||
* @param {string} integrationName - Name of Integration | ||
*/ | ||
async getLastTimeSync({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationName, | ||
}: GetLastSyncTime) { | ||
const regex = new RegExp(/\d*:\d*:\d*.\d*/); | ||
const integrationId = await this.getIntegrationId({ authInstance, microappsAdminUrl, integrationName}); | ||
const integrationId = await this.getIntegrationId({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationName, | ||
}); | ||
const integrationType = await this.getIntegrationType({authInstance, microappsAdminUrl, integrationName}); | ||
const integrationType = await this.getIntegrationType({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationName, | ||
}); | ||
const logs = await this.getIntegrationLog({ authInstance, microappsAdminUrl, integrationId, integrationType }); | ||
const logs = await this.getIntegrationLog({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationId, | ||
integrationType, | ||
}); | ||
for (const line of logs.data.data){ | ||
if (line.message.includes('Service synchronization finished in')){ | ||
return line.message.match(regex)[0]; | ||
} | ||
} | ||
for (const line of logs.data.data) { | ||
if (line.message.includes("Service synchronization finished in")) { | ||
return line.message.match(regex)[0]; | ||
} | ||
} | ||
} | ||
/** | ||
* Returns Id of component | ||
* | ||
* @param {Object} authInstance - Authorized instance for API calls | ||
* @param {string} microappsAdminUrl - Microapps admin url | ||
* @param {string} integrationName - Name of Integration | ||
* @param {string} appName - Name of Microapp | ||
* @param {string} componentLabel - Label of Component | ||
*/ | ||
async getComponentId({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationName, | ||
appName, | ||
pageName, | ||
componentLabel, | ||
}: GetComponentId) { | ||
const integrationId = await this.getIntegrationId({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationName, | ||
}); | ||
const appId = await this.getMicroAppId({ | ||
authInstance, | ||
microappsAdminUrl, | ||
integrationId, | ||
appName, | ||
}); | ||
const selectedAppData = await this.getAppInfo({ | ||
authInstance, | ||
microappsAdminUrl, | ||
appId, | ||
}); | ||
const pagesData = selectedAppData.data.app.pages; | ||
const getPage = pagesData.filter( | ||
(app: { title: any }) => app.title === pageName | ||
); | ||
const components = getPage[0].components; | ||
const getComponent = components.filter( | ||
(component: { label: any }) => component.label === componentLabel | ||
); | ||
const componentId = getComponent[0].id; | ||
return componentId; | ||
} | ||
} | ||
export type MicroappsAdminLogin = { | ||
page: Page; | ||
url: string; | ||
username: string; | ||
password: string; | ||
mfa: any | boolean; | ||
secretKey: string; | ||
page: Page; | ||
url: string; | ||
username: string; | ||
password: string; | ||
mfa: any | boolean; | ||
secretKey: string; | ||
}; | ||
export type GetIntegrationId = { | ||
authInstance: any; | ||
microappsAdminUrl: string; | ||
integrationName: string; | ||
authInstance: any; | ||
microappsAdminUrl: string; | ||
integrationName: string; | ||
}; | ||
export type OauthLogout = { | ||
authInstance: any; | ||
microappsAdminUrl: string; | ||
integrationName: string; | ||
repeatCount?: number; | ||
authInstance: any; | ||
microappsAdminUrl: string; | ||
integrationName: string; | ||
repeatCount?: number; | ||
}; | ||
export type WaitForSync = { | ||
getIntegration: () => any; | ||
synchronizationType: string; | ||
getIntegration: () => any; | ||
synchronizationType: string; | ||
}; | ||
export type RunSynchronization = { | ||
authInstance: any; | ||
microappsAdminUrl: string; | ||
integrationName: string; | ||
synchronizationType: string; | ||
authInstance: any; | ||
microappsAdminUrl: string; | ||
integrationName: string; | ||
synchronizationType: string; | ||
}; | ||
export type CreateHTTPIntegration = { | ||
authInstance: any; | ||
microappsAdminUrl: string; | ||
integrationName: string; | ||
integrationConfiguration: any; | ||
authInstance: any; | ||
microappsAdminUrl: string; | ||
integrationName: string; | ||
integrationConfiguration: any; | ||
}; | ||
export type WaitForProcessStatus = { | ||
authInstance: any; | ||
getProcessStatus: () => any; | ||
status: string; | ||
microappsAdminUrl: string; | ||
processId: string; | ||
authInstance: any; | ||
getProcessStatus: () => any; | ||
status: string; | ||
microappsAdminUrl: string; | ||
processId: string; | ||
}; | ||
export type CreateJavaIntegration = { | ||
authInstance: any; | ||
microappsAdminUrl: string; | ||
data: string; | ||
integrationConfiguration: any; | ||
withEntities: boolean; | ||
serviceType: any; | ||
serviceKey: string; | ||
name: string; | ||
authInstance: any; | ||
microappsAdminUrl: string; | ||
data: string; | ||
integrationConfiguration: any; | ||
withEntities: boolean; | ||
serviceType: any; | ||
serviceKey: string; | ||
name: string; | ||
}; | ||
export type GetIntegrationType = { | ||
authInstance: any; | ||
microappsAdminUrl: string; | ||
integrationName: string; | ||
authInstance: any; | ||
microappsAdminUrl: string; | ||
integrationName: string; | ||
}; | ||
export type GetStatusIntegration = { | ||
authInstance: any; | ||
microappsAdminUrl: string; | ||
integrationName: string; | ||
authInstance: any; | ||
microappsAdminUrl: string; | ||
integrationName: string; | ||
}; | ||
export type ImportIntegration = { | ||
authInstance: any; | ||
microappsAdminUrl: string; | ||
pathToFile: string; | ||
authInstance: any; | ||
microappsAdminUrl: string; | ||
pathToFile: string; | ||
}; | ||
export type RenameIntegration = { | ||
authInstance: any; | ||
microappsAdminUrl: string; | ||
integrationName: string; | ||
newIntegrationName: string; | ||
integrationConfiguration: string; | ||
authInstance: any; | ||
microappsAdminUrl: string; | ||
integrationName: string; | ||
newIntegrationName: string; | ||
integrationConfiguration: string; | ||
}; | ||
export type ExportApp = { | ||
authInstance: any; | ||
microappsAdminUrl: string; | ||
appId: string; | ||
pathToFile: string; | ||
authInstance: any; | ||
microappsAdminUrl: string; | ||
appId: string; | ||
pathToFile: string; | ||
}; | ||
export type GetMicroAppId = { | ||
authInstance: any; | ||
microappsAdminUrl: string; | ||
integrationId: string; | ||
appName: string; | ||
authInstance: any; | ||
microappsAdminUrl: string; | ||
integrationId: string; | ||
appName: string; | ||
}; | ||
export type GetNotificationId = { | ||
authInstance: any; | ||
microappsAdminUrl: string; | ||
appId: string; | ||
notificationName: string; | ||
authInstance: any; | ||
microappsAdminUrl: string; | ||
appId: string; | ||
notificationName: string; | ||
}; | ||
export type RunEvent = { | ||
authInstance: any; | ||
microappsAdminUrl: string; | ||
integrationName: string; | ||
appName: string; | ||
notificationName: string; | ||
authInstance: any; | ||
microappsAdminUrl: string; | ||
integrationName: string; | ||
appName: string; | ||
notificationName: string; | ||
}; | ||
export type CheckAppMissconfigurations = { | ||
authInstance: any; | ||
microappsAdminUrl: string; | ||
appId: string; | ||
authInstance: any; | ||
microappsAdminUrl: string; | ||
appId: string; | ||
}; | ||
@@ -963,3 +1249,3 @@ | ||
filePath: string; | ||
} | ||
}; | ||
@@ -971,3 +1257,3 @@ export type ImportMicroAppUI = { | ||
integrationName: string; | ||
} | ||
}; | ||
export type AddSubscriber = { | ||
@@ -998,3 +1284,3 @@ authInstance: any; | ||
integrationName: string; | ||
} | ||
}; | ||
@@ -1005,8 +1291,17 @@ export type ExportMicroAppUI = { | ||
integrationName: string; | ||
} | ||
}; | ||
export type GetLastSyncTime = { | ||
authInstance: any; | ||
microappsAdminUrl: string; | ||
integrationName: string; | ||
} | ||
authInstance: any; | ||
microappsAdminUrl: string; | ||
integrationName: string; | ||
}; | ||
export type GetComponentId = { | ||
authInstance: any; | ||
microappsAdminUrl: string; | ||
integrationName: string; | ||
appName: string; | ||
pageName: string; | ||
componentLabel: string; | ||
}; |
@@ -16,3 +16,9 @@ import { Page, BrowserContext } from "playwright"; | ||
*/ | ||
async login({ page, workspaceUrl, workspaceUsername, workspacePassword, workspaceIdentityProvider }: Login) { | ||
async login({ | ||
page, | ||
workspaceUrl, | ||
workspaceUsername, | ||
workspacePassword, | ||
workspaceIdentityProvider, | ||
}: Login) { | ||
console.log("Login to Workspace", new Date()); | ||
@@ -99,3 +105,5 @@ await page.goto(workspaceUrl, { waitUntil: "domcontentloaded" }); | ||
console.log(`Choosing action ${actionName}`, new Date()); | ||
await page.click(`//button[descendant::div[@title="${integrationName}"]] //div[contains(text(), "${actionName}")]`); | ||
await page.click( | ||
`//button[descendant::div[@title="${integrationName}"]] //div[contains(text(), "${actionName}")]` | ||
); | ||
} | ||
@@ -112,3 +120,5 @@ | ||
const notifications = await page.waitForResponse( | ||
(response: any) => response.url().match(new RegExp("notification")) && response.status() === 200 | ||
(response: any) => | ||
response.url().match(new RegExp("notification")) && | ||
response.status() === 200 | ||
); | ||
@@ -127,3 +137,9 @@ const notificationsBody = await notifications.json(); | ||
*/ | ||
async waitForFeedCardId({ page, repeatMax = 50, waitTime = 5000, recordId, notificationId = "" }: WaitForFeedCardId) { | ||
async waitForFeedCardId({ | ||
page, | ||
repeatMax = 50, | ||
waitTime = 5000, | ||
recordId, | ||
notificationId = "", | ||
}: WaitForFeedCardId) { | ||
let feedCardId; | ||
@@ -138,4 +154,10 @@ for (let i = 0; i < repeatMax; i++) { | ||
const feedCardDetail = data.filter( | ||
(e: { recordId: string | string[]; source: { notification: { id: string | string[] } } }) => { | ||
return e.recordId.includes(recordId) && e.source.notification.id.includes(notificationId); | ||
(e: { | ||
recordId: string | string[]; | ||
source: { notification: { id: string | string[] } }; | ||
}) => { | ||
return ( | ||
e.recordId.includes(recordId) && | ||
e.source.notification.id.includes(notificationId) | ||
); | ||
} | ||
@@ -180,6 +202,10 @@ ); | ||
await Promise.race([ | ||
page.waitForSelector(`xpath=//div[contains(text(), "We're unable to process your request")]`), | ||
page.waitForSelector( | ||
`xpath=//div[contains(text(), "We're unable to process your request")]` | ||
), | ||
page.waitForSelector(`xpath=//div[contains(text(), '${text}')]`), | ||
]); | ||
const alertPopUp = await page.$$(`xpath=//div[contains(text(), "We're unable to process your request")]`); | ||
const alertPopUp = await page.$$( | ||
`xpath=//div[contains(text(), "We're unable to process your request")]` | ||
); | ||
if (alertPopUp.length !== 0) { | ||
@@ -228,3 +254,6 @@ throw new Error("Service action failed"); | ||
const cookies = response.headers["set-cookie"]; | ||
const jSessionId = await getCookie({ cookies: cookies, cookieName: "JSESSIONID" }); | ||
const jSessionId = await getCookie({ | ||
cookies: cookies, | ||
cookieName: "JSESSIONID", | ||
}); | ||
return { citrixToken, jSessionId }; | ||
@@ -243,3 +272,9 @@ } | ||
}: GetDsauthTokens) { | ||
await this.login({ page, workspaceUrl, workspaceUsername, workspacePassword, workspaceIdentityProvider }); | ||
await this.login({ | ||
page, | ||
workspaceUrl, | ||
workspaceUsername, | ||
workspacePassword, | ||
workspaceIdentityProvider, | ||
}); | ||
const cookies = await context.cookies(); | ||
@@ -261,3 +296,7 @@ const csfrTokenCookie = cookies.find((e) => e.name === "CsrfToken"); | ||
}); | ||
const { citrixToken, jSessionId } = await this.getTokens({ builderDomain, authDomain, oneTimeToken }); | ||
const { citrixToken, jSessionId } = await this.getTokens({ | ||
builderDomain, | ||
authDomain, | ||
oneTimeToken, | ||
}); | ||
@@ -267,9 +306,44 @@ return { citrixToken, jSessionId }; | ||
async createDsAuthInstance({ citrixToken, jSessionId }: CreateDsAuthInstance) { | ||
async createDsAuthInstance({ | ||
citrixToken, | ||
jSessionId, | ||
}: CreateDsAuthInstance) { | ||
const dSauthInstance = axios.create({}); | ||
dSauthInstance.defaults.headers.common["citrix-csrf-token"] = `${citrixToken}`; | ||
dSauthInstance.defaults.headers.common["cookie"] = `JSESSIONID=${jSessionId}`; | ||
dSauthInstance.defaults.headers.common[ | ||
"citrix-csrf-token" | ||
] = `${citrixToken}`; | ||
dSauthInstance.defaults.headers.common[ | ||
"cookie" | ||
] = `JSESSIONID=${jSessionId}`; | ||
dSauthInstance.defaults.timeout = 90000; | ||
return dSauthInstance; | ||
} | ||
async getUserData({ | ||
dSauthInstance, | ||
microappsAdminUrl, | ||
appId, | ||
componentId, | ||
dataLimit, | ||
initiatorType, | ||
initiatorData, | ||
pageId, | ||
authDomain, | ||
}: GetUserData) { | ||
const response = await dSauthInstance({ | ||
url: `${microappsAdminUrl}/app/api/app/${appId}/component/${componentId}/data`, | ||
method: "GET", | ||
queryParameters: { | ||
offset: 0, | ||
limit: dataLimit, | ||
orderDirection: "ASC", | ||
initiator_type: initiatorType, | ||
initiator_id: pageId, | ||
initiator_appId: appId, | ||
initiator_data: initiatorData, | ||
authDomain, | ||
}, | ||
}); | ||
return response.data.data; | ||
} | ||
} | ||
@@ -352,1 +426,13 @@ | ||
}; | ||
export type GetUserData = { | ||
dSauthInstance: any; | ||
microappsAdminUrl: string; | ||
appId: string; | ||
componentId: string; | ||
dataLimit: string; | ||
initiatorType: string; | ||
initiatorData: string; | ||
pageId: string; | ||
authDomain: string; | ||
}; |
5749
237883
Updatedplaywright@^1.5.2
Updatedtypescript@^4.0.5