Skip to content

Commit

Permalink
CNI - Connection Reference/Defintion Visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
jasoncomes committed Aug 5, 2024
1 parent 8b0189f commit 63474c3
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 51 deletions.
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": "9.0.8",
"version": "9.1.0",
"description": "Utility library for building Prismatic components",
"keywords": ["prismatic"],
"main": "dist/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/spectral/src/serverTypes/convertComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const convertInput = (
collection === "keyvaluelist" && typeof label === "object" ? label.key : undefined;

return {
...omit(rest, ["onPremControlled"]),
...omit(rest, ["onPremControlled", "permissionAndVisibilityType", "visibleToOrgDeployer"]),
key,
type,
default: defaultValue ?? InputFieldDefaultMap[type],
Expand Down
8 changes: 8 additions & 0 deletions packages/spectral/src/serverTypes/convertIntegration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,13 +524,21 @@ const convertConfigVar = (
return result;
}

const meta = convertInputPermissionAndVisibility(
pick(input, ["permissionAndVisibilityType", "visibleToOrgDeployer"]) as {
permissionAndVisibilityType?: PermissionAndVisibilityType;
visibleToOrgDeployer?: boolean;
},
);

const defaultValue = input.collection ? [] : "";

return {
...result,
[key]: {
type: input.collection ? "complex" : "value",
value: input.default || defaultValue,
meta,
},
};
}, {}),
Expand Down
20 changes: 3 additions & 17 deletions packages/spectral/src/types/ComponentRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ComponentManifest, PermissionAndVisibilityType } from ".";
import { Prettify, UnionToIntersection } from "./utils";
import type { ComponentManifest, ConfigVarVisibility } from ".";
import type { Prettify, UnionToIntersection } from "./utils";

/**
* Root ComponentRegistry type exposed for augmentation.
Expand Down Expand Up @@ -29,19 +29,6 @@ export type ComponentRegistry = keyof IntegrationDefinitionComponentRegistry ext
: never
>;

export interface ConnectionInputPermissionAndVisibility {
/**
* Optional value that sets the permission and visibility of the Config Var. @default "customer"
*
* "customer" - Customers can view and edit the Config Var.
* "embedded" - Customers cannot view or update the Config Var as the value will be set programmatically.
* "organization" - Customers cannot view or update the Config Var as it will always have a default value or be set by the organization.
*/
permissionAndVisibilityType?: PermissionAndVisibilityType;
/** Optional value that specifies whether this Config Var is visible to an Organization deployer. @default true */
visibleToOrgDeployer?: boolean;
}

export type ConfigVarExpression = { configVar: string };
export type ValueExpression<TValueType = unknown> = {
value: TValueType;
Expand All @@ -58,8 +45,7 @@ type ComponentReferenceTypeValueMap<
actions: ValueExpression<TValue>;
triggers: ValueExpression<TValue> | ConfigVarExpression;
dataSources: ValueExpression<TValue> | ConfigVarExpression;
connections: (ValueExpression<TValue> | ConfigVarExpression) &
ConnectionInputPermissionAndVisibility;
connections: (ValueExpression<TValue> | ConfigVarExpression) & ConfigVarVisibility;
},
> = TMap;

Expand Down
87 changes: 57 additions & 30 deletions packages/spectral/src/types/ConfigVars.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import {
DataSourceDefinition,
ConnectionDefinition,
Inputs,
DataSourceType,
Connection,
JSONForm,
ObjectFieldMap,
ObjectSelection,
ConfigVarResultCollection,
Schedule,
CollectionDataSourceType,
DataSourceReference,
type DataSourceDefinition,
type ConnectionDefinition,
type Inputs,
type DataSourceType,
type Connection,
type JSONForm,
type ObjectFieldMap,
type ObjectSelection,
type ConfigVarResultCollection,
type Schedule,
type CollectionDataSourceType,
type DataSourceReference,
isComponentReference,
ConfigPage,
ConfigPages,
ConfigPageElement,
ComponentRegistryDataSource,
ComponentRegistryConnection,
UserLevelConfigPages,
type ConfigPage,
type ConfigPages,
type ConfigPageElement,
type ComponentRegistryDataSource,
type ComponentRegistryConnection,
type UserLevelConfigPages,
type ConnectionInput,
} from ".";
import { Prettify, UnionToIntersection } from "./utils";
import type { Prettify, UnionToIntersection } from "./utils";

/** Supported data types for Config Vars. */
export type ConfigVarDataType =
Expand Down Expand Up @@ -70,19 +71,14 @@ type ConfigVarDataTypeRuntimeValueMap<
/** Choices of collection types for multi-value Config Vars. */
export type CollectionType = "valuelist" | "keyvaluelist";

export type PermissionAndVisibilityType = "customer" | "embedded" | "organization";

type ConfigVarSingleDataType = Extract<
ConfigVarDataType,
"schedule" | "objectSelection" | "objectFieldMap" | "jsonForm"
>;

/** Common attribute shared by all types of Config Vars. */
type BaseConfigVar = {
/** A unique, unchanging value that is used to maintain identity for the Config Var even if the key changes. */
stableKey: string;
/** Optional description for this Config Var. */
description?: string;
export type PermissionAndVisibilityType = "customer" | "embedded" | "organization";

export interface ConfigVarVisibility {
/**
* Optional value that sets the permission and visibility of the Config Var. @default "customer"
*
Expand All @@ -93,7 +89,28 @@ type BaseConfigVar = {
permissionAndVisibilityType?: PermissionAndVisibilityType;
/** Optional value that specifies whether this Config Var is visible to an Organization deployer. @default true */
visibleToOrgDeployer?: boolean;
};
}

interface ConfigVarInputVisibility {
/**
* Optional value that sets the permission and visibility of the Config Var Input. @default "customer"
*
* "customer" - Customers can view and edit the Config Var Input.
* "embedded" - Customers cannot view or update the Config Var Input as the value will be set programmatically.
* "organization" - Customers cannot view or update the Config Var Input as it will always have a default value or be set by the organization.
*/
permissionAndVisibilityType?: PermissionAndVisibilityType;
/** Optional value that specifies whether this Config Var Input is visible to an Organization deployer. @default true */
visibleToOrgDeployer?: boolean;
}

/** Common attribute shared by all types of Config Vars. */
type BaseConfigVar = {
/** A unique, unchanging value that is used to maintain identity for the Config Var even if the key changes. */
stableKey: string;
/** Optional description for this Config Var. */
description?: string;
} & ConfigVarVisibility;

type GetDynamicProperties<
TValue,
Expand Down Expand Up @@ -232,8 +249,18 @@ type BaseConnectionConfigVar = BaseConfigVar & {
dataType: "connection";
};

type ConnectionDefinitionConfigVar = BaseConnectionConfigVar &
Omit<ConnectionDefinition, "label" | "comments" | "key">;
type ConnectionDefinitionConfigVar =
ConnectionDefinition extends infer TConnectionDefinitionType extends ConnectionDefinition
? TConnectionDefinitionType extends infer TConnectionDefinition extends ConnectionDefinition
? BaseConnectionConfigVar &
Omit<TConnectionDefinition, "inputs" | "label" | "comments" | "key"> & {
inputs: {
[Key in keyof TConnectionDefinition["inputs"]]: TConnectionDefinition["inputs"][Key] &
ConfigVarInputVisibility;
};
}
: never
: never;

type OnPremiseConnectionConfigTypeEnum = "allowed" | "disallowed" | "required";

Expand Down
2 changes: 1 addition & 1 deletion packages/spectral/src/types/ConnectionDefinition.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ConnectionInput, OnPremConnectionInput } from ".";
import type { ConnectionInput, OnPremConnectionInput } from ".";

export enum OAuth2Type {
ClientCredentials = "client_credentials",
Expand Down
4 changes: 3 additions & 1 deletion packages/spectral/src/types/Inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ export type ConnectionInput = (
| TextInputField
| PasswordInputField
| BooleanInputField
) & { shown?: boolean };
) & {
shown?: boolean;
};

export type OnPremConnectionInput = {
onPremControlled: true;
Expand Down

0 comments on commit 63474c3

Please sign in to comment.