Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On Premise Connection Configuration #176

Merged
merged 2 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/generator-spectral/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
],
"dependencies": {
"@apidevtools/swagger-parser": "10.1.0",
"@prismatic-io/spectral": "8.0.3",
"@prismatic-io/spectral": "8.0.4",
"lodash": "4.17.21",
"number-to-words": "1.2.4",
"openapi-types": "11.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/spectral/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@prismatic-io/spectral",
"version": "8.0.3",
"version": "8.0.4",
"description": "Utility library for building Prismatic components",
"keywords": [
"prismatic"
Expand Down
11 changes: 11 additions & 0 deletions packages/spectral/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
TriggerPayload,
DataSourceConfigVar,
ConfigPages,
OnPremiseConnectionDefinition,
} from "./types";
import { convertComponent } from "./serverTypes/convert";
import { convertIntegration } from "./serverTypes/convertIntegration";
Expand Down Expand Up @@ -184,6 +185,16 @@ export const connection = <T extends DefaultConnectionDefinition>(
definition: T
): T => definition;

/**
* For information on writing custom component connections using on-premise resources, see
* https://prismatic.io/docs/custom-components/writing-custom-components/#adding-connections.
* @param definition An OnPremiseConnectionDefinition object that describes the type of a connection for a custom component action or trigger, and information on how it should be displayed in the Prismatic WebApp.
* @returns This function validates the shape of the `definition` object provided and returns the same connection object.
*/
export const onPremiseConnection = <T extends OnPremiseConnectionDefinition>(
definition: T
): T => definition;

/**
* For information on writing custom component connections, see
* https://prismatic.io/docs/custom-components/writing-custom-components/#adding-connections.
Expand Down
2 changes: 1 addition & 1 deletion packages/spectral/src/serverTypes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export interface Connection {
comments?: string;
oauth2Type?: OAuth2Type;
iconPath?: string;
inputs: (Input & { shown?: boolean })[];
inputs: (Input & { shown?: boolean; onPremiseControlled?: boolean })[];
}

export interface ConnectionValue {
Expand Down
64 changes: 64 additions & 0 deletions packages/spectral/src/types-tests/ConnectionDefinition.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { expectAssignable, expectNotAssignable } from "tsd";
import { onPremiseConnection, OnPremiseConnectionDefinition } from "..";

const valid = onPremiseConnection({
key: "basic",
label: "Basic Connection",
inputs: {
host: {
label: "Host",
placeholder: "Host",
type: "string",
required: true,
shown: true,
onPremiseControlled: true,
example: "192.168.0.1",
},
port: {
label: "Port",
placeholder: "Port",
type: "string",
required: true,
shown: true,
onPremiseControlled: true,
default: "1433",
},
username: {
label: "Username",
placeholder: "Username",
type: "string",
required: false,
shown: true,
},
password: {
label: "Password",
placeholder: "Password",
type: "password",
required: false,
shown: true,
},
},
});
expectAssignable<OnPremiseConnectionDefinition>(valid);

const invalid = {
key: "basic",
label: "Basic Connection",
inputs: {
username: {
label: "Username",
placeholder: "Username",
type: "string",
required: false,
shown: true,
},
password: {
label: "Password",
placeholder: "Password",
type: "password",
required: false,
shown: true,
},
},
};
expectNotAssignable<OnPremiseConnectionDefinition>(invalid);
15 changes: 13 additions & 2 deletions packages/spectral/src/types/ConnectionDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ export interface DefaultConnectionDefinition extends BaseConnectionDefinition {
};
}

type OnPremiseConnectionInput = ConnectionInput & { onPremiseControlled: true };

export interface OnPremiseConnectionDefinition
extends BaseConnectionDefinition {
inputs: {
host: OnPremiseConnectionInput;
port: OnPremiseConnectionInput;
[key: string]: ConnectionInput;
};
}

interface OAuth2AuthorizationCodeConnectionDefinition
extends BaseConnectionDefinition {
oauth2Type: OAuth2Type.AuthorizationCode;
Expand Down Expand Up @@ -57,5 +68,5 @@ export type OAuth2ConnectionDefinition =

export type ConnectionDefinition =
| DefaultConnectionDefinition
| OAuth2AuthorizationCodeConnectionDefinition
| OAuth2ClientCredentialConnectionDefinition;
| OnPremiseConnectionDefinition
| OAuth2ConnectionDefinition;
Loading