From 4f2f70591be8c610cdefa89c931edaeda3f2ce2a Mon Sep 17 00:00:00 2001 From: Jason Comes Date: Thu, 25 Apr 2024 13:51:09 -0500 Subject: [PATCH] Configure Instance - Add `integrationid, instanceId` props to method --- package-lock.json | 4 +- package.json | 2 +- src/lib/configureInstance.ts | 81 +++++++++++++++++++++++++++++++----- src/lib/index.ts | 10 ++++- src/types/index.ts | 7 +++- 5 files changed, 88 insertions(+), 16 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8cc6c62..2d0fd4e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@prismatic-io/embedded", - "version": "2.6.3", + "version": "2.7.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@prismatic-io/embedded", - "version": "2.6.3", + "version": "2.7.0", "license": "MIT", "dependencies": { "@prismatic-io/spectral": "^8.0.3", diff --git a/package.json b/package.json index c3d0dea..e6353d0 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "url": "https://github.com/prismatic-io/embedded.git" }, "license": "MIT", - "version": "2.6.3", + "version": "2.7.0", "main": "dist/index.js", "types": "dist/index.d.ts", "files": [ diff --git a/src/lib/configureInstance.ts b/src/lib/configureInstance.ts index 79be22d..02220bf 100644 --- a/src/lib/configureInstance.ts +++ b/src/lib/configureInstance.ts @@ -2,20 +2,79 @@ import { Options } from "../types/options"; import { assertInit } from "../utils/assertInit"; import { setIframe } from "../utils/iframe"; -export type ConfigureInstanceProps = Options & { +type ConfigureInstancesBase = Options & { + skipRedirectOnRemove: boolean; +}; + +export type ConfigureInstanceWithIntegrationName = ConfigureInstancesBase & { integrationName: string; - skipRedirectOnRemove?: boolean; }; -export const configureInstance = ({ - integrationName, - skipRedirectOnRemove, - ...options -}: ConfigureInstanceProps) => { +export type ConfigureInstanceWithIntegrationId = ConfigureInstancesBase & { + integrationId: string; +}; + +export type ConfigureInstanceWithInstanceId = ConfigureInstancesBase & { + instanceId: string; +}; + +export type ConfigureInstanceProps = + | ConfigureInstanceWithIntegrationName + | ConfigureInstanceWithIntegrationId + | ConfigureInstanceWithInstanceId; + +export const configureInstance = ({ ...props }: ConfigureInstanceProps) => { assertInit("configureInstance"); - setIframe("/find-integration-marketplace/", options, { - integrationName, - ...(skipRedirectOnRemove ? { skipRedirectOnRemove: "true" } : {}), - }); + if ("instanceId" in props && props.instanceId) { + const { instanceId, skipRedirectOnRemove, ...options } = props; + + return setIframe("/find-integration-marketplace/", options, { + instanceId, + ...(skipRedirectOnRemove ? { skipRedirectOnRemove: "true" } : {}), + }); + } + + if ("integrationId" in props && props.integrationId) { + const { integrationId, skipRedirectOnRemove, ...options } = props; + + return setIframe("/find-integration-marketplace/", options, { + integrationId, + ...(skipRedirectOnRemove ? { skipRedirectOnRemove: "true" } : {}), + }); + } + + if ("integrationName" in props && props.integrationName) { + const { integrationName, skipRedirectOnRemove, ...options } = props; + + setIframe("/find-integration-marketplace/", options, { + integrationName, + ...(skipRedirectOnRemove ? { skipRedirectOnRemove: "true" } : {}), + }); + } +}; + +configureInstance({ + integrationName: "test", + instanceId: "123", + skipRedirectOnRemove: true, + selector: "#root", +}); + +export const isConfigureInstanceWithIntegrationName = ( + props: ConfigureInstanceProps +): props is ConfigureInstanceWithIntegrationName => { + return "integrationName" in props; +}; + +export const isConfigureInstanceWithIntegrationId = ( + props: ConfigureInstanceProps +): props is ConfigureInstanceWithIntegrationId => { + return "integrationId" in props; +}; + +export const isConfigureInstanceWithInstanceId = ( + props: ConfigureInstanceProps +): props is ConfigureInstanceWithInstanceId => { + return "instanceId" in props; }; diff --git a/src/lib/index.ts b/src/lib/index.ts index 769d8ea..7cddddd 100644 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -1,4 +1,9 @@ -import { configureInstance } from "./configureInstance"; +import { + configureInstance, + isConfigureInstanceWithInstanceId, + isConfigureInstanceWithIntegrationId, + isConfigureInstanceWithIntegrationName, +} from "./configureInstance"; export { authenticate } from "./authenticate"; export { @@ -7,6 +12,9 @@ export { * @deprecated Use configureInstance instead, this will be removed in the next major version (v3.0.0) */ configureInstance as configureIntegration, // alias for backwards compatibility + isConfigureInstanceWithInstanceId, + isConfigureInstanceWithIntegrationId, + isConfigureInstanceWithIntegrationName, }; export { graphqlRequest } from "./graphqlRequest"; export { init, EMBEDDED_DEFAULTS } from "./init"; diff --git a/src/types/index.ts b/src/types/index.ts index 787c27f..34e2831 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -65,6 +65,11 @@ export { SetConfigVarsProps } from "../lib/setConfigVars"; export { GraphqlRequestProps } from "../lib/graphqlRequest"; -export { ConfigureInstanceProps } from "../lib/configureInstance"; +export { + ConfigureInstanceProps, + ConfigureInstanceWithInstanceId, + ConfigureInstanceWithIntegrationId, + ConfigureInstanceWithIntegrationName, +} from "../lib/configureInstance"; export { AuthenticateProps } from "../lib/authenticate";