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..357e9b9 100644 --- a/src/lib/configureInstance.ts +++ b/src/lib/configureInstance.ts @@ -2,20 +2,72 @@ 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) { + const { instanceId, skipRedirectOnRemove, ...options } = props; + + return setIframe("/find-integration-marketplace/", options, { + instanceId, + ...(skipRedirectOnRemove ? { skipRedirectOnRemove: "true" } : {}), + }); + } + + if ("integrationId" in props) { + const { integrationId, skipRedirectOnRemove, ...options } = props; + + return setIframe("/find-integration-marketplace/", options, { + integrationId, + ...(skipRedirectOnRemove ? { skipRedirectOnRemove: "true" } : {}), + }); + } + + if ("integrationName" in props) { + const { integrationName, skipRedirectOnRemove, ...options } = props; + + setIframe("/find-integration-marketplace/", options, { + integrationName, + ...(skipRedirectOnRemove ? { skipRedirectOnRemove: "true" } : {}), + }); + } +}; + +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";