Skip to content

Commit

Permalink
Configure Instance - Add integrationid, instanceId props to method
Browse files Browse the repository at this point in the history
  • Loading branch information
jasoncomes committed Apr 25, 2024
1 parent b0274fa commit 4f2f705
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 16 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
81 changes: 70 additions & 11 deletions src/lib/configureInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
10 changes: 9 additions & 1 deletion src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { configureInstance } from "./configureInstance";
import {
configureInstance,
isConfigureInstanceWithInstanceId,
isConfigureInstanceWithIntegrationId,
isConfigureInstanceWithIntegrationName,
} from "./configureInstance";

export { authenticate } from "./authenticate";
export {
Expand All @@ -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";
Expand Down
7 changes: 6 additions & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

0 comments on commit 4f2f705

Please sign in to comment.