mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-29 05:41:46 +02:00
Start of plugin types refactor
This commit is contained in:
2
plugin-runtime-types/src/helpers.ts
Normal file
2
plugin-runtime-types/src/helpers.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export type AtLeast<T, K extends keyof T> = Partial<T> & Pick<T, K>;
|
||||
export type SingleOrArray<T> = T[] | T;
|
||||
3
plugin-runtime-types/src/index.ts
Normal file
3
plugin-runtime-types/src/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export type * from './models';
|
||||
export type * from './plugins';
|
||||
export type * from './themes';
|
||||
1
plugin-runtime-types/src/models/index.ts
Normal file
1
plugin-runtime-types/src/models/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './types';
|
||||
135
plugin-runtime-types/src/models/types.ts
Normal file
135
plugin-runtime-types/src/models/types.ts
Normal file
@@ -0,0 +1,135 @@
|
||||
export interface BaseModel {
|
||||
readonly model: string;
|
||||
readonly id: string;
|
||||
readonly createdAt: string;
|
||||
readonly updatedAt: string;
|
||||
}
|
||||
|
||||
export interface Workspace extends BaseModel {
|
||||
readonly model: 'workspace';
|
||||
name: string;
|
||||
description: string;
|
||||
variables: EnvironmentVariable[];
|
||||
settingValidateCertificates: boolean;
|
||||
settingFollowRedirects: boolean;
|
||||
settingRequestTimeout: number;
|
||||
}
|
||||
|
||||
export interface EnvironmentVariable {
|
||||
name: string;
|
||||
value: string;
|
||||
enabled?: boolean;
|
||||
}
|
||||
|
||||
export interface Folder extends BaseModel {
|
||||
readonly workspaceId: string;
|
||||
readonly model: 'folder';
|
||||
folderId: string | null;
|
||||
sortPriority: number;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface Environment extends BaseModel {
|
||||
readonly workspaceId: string;
|
||||
readonly model: 'environment';
|
||||
name: string;
|
||||
variables: EnvironmentVariable[];
|
||||
}
|
||||
|
||||
export interface HttpHeader {
|
||||
name: string;
|
||||
value: string;
|
||||
enabled?: boolean;
|
||||
}
|
||||
|
||||
export interface HttpUrlParameter {
|
||||
name: string;
|
||||
value: string;
|
||||
enabled?: boolean;
|
||||
}
|
||||
|
||||
export interface GrpcMetadataEntry {
|
||||
name: string;
|
||||
value: string;
|
||||
enabled?: boolean;
|
||||
}
|
||||
|
||||
export interface GrpcRequest extends BaseModel {
|
||||
readonly workspaceId: string;
|
||||
readonly model: 'grpc_request';
|
||||
folderId: string | null;
|
||||
sortPriority: number;
|
||||
name: string;
|
||||
url: string;
|
||||
service: string | null;
|
||||
method: string | null;
|
||||
message: string;
|
||||
authentication: Record<string, string | number | boolean | null | undefined>;
|
||||
authenticationType: string | null;
|
||||
metadata: GrpcMetadataEntry[];
|
||||
}
|
||||
|
||||
export interface GrpcEvent extends BaseModel {
|
||||
readonly workspaceId: string;
|
||||
readonly requestId: string;
|
||||
readonly connectionId: string;
|
||||
readonly model: 'grpc_event';
|
||||
content: string;
|
||||
status: number | null;
|
||||
error: string | null;
|
||||
eventType:
|
||||
| 'info'
|
||||
| 'error'
|
||||
| 'client_message'
|
||||
| 'server_message'
|
||||
| 'connection_start'
|
||||
| 'connection_end';
|
||||
metadata: Record<string, string>;
|
||||
}
|
||||
|
||||
export interface GrpcConnection extends BaseModel {
|
||||
readonly workspaceId: string;
|
||||
readonly requestId: string;
|
||||
readonly model: 'grpc_connection';
|
||||
service: string;
|
||||
method: string;
|
||||
elapsed: number;
|
||||
elapsedConnection: number;
|
||||
status: number;
|
||||
url: string;
|
||||
error: string | null;
|
||||
trailers: Record<string, string>;
|
||||
}
|
||||
|
||||
export interface HttpRequest extends BaseModel {
|
||||
readonly workspaceId: string;
|
||||
readonly model: 'http_request';
|
||||
folderId: string | null;
|
||||
sortPriority: number;
|
||||
name: string;
|
||||
url: string;
|
||||
urlParameters: HttpUrlParameter[];
|
||||
body: Record<string, unknown>;
|
||||
bodyType: string | null;
|
||||
authentication: Record<string, string | number | boolean | null | undefined>;
|
||||
authenticationType: string | null;
|
||||
method: string;
|
||||
headers: HttpHeader[];
|
||||
}
|
||||
|
||||
export interface HttpResponse extends BaseModel {
|
||||
readonly workspaceId: string;
|
||||
readonly model: 'http_response';
|
||||
readonly requestId: string;
|
||||
readonly bodyPath: string | null;
|
||||
readonly contentLength: number | null;
|
||||
readonly error: string;
|
||||
readonly status: number;
|
||||
readonly elapsed: number;
|
||||
readonly elapsedHeaders: number;
|
||||
readonly statusReason: string;
|
||||
readonly version: string;
|
||||
readonly remoteAddr: string;
|
||||
readonly url: string;
|
||||
readonly headers: HttpHeader[];
|
||||
}
|
||||
11
plugin-runtime-types/src/plugins/context.ts
Normal file
11
plugin-runtime-types/src/plugins/context.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { HttpRequest, HttpResponse } from '../models';
|
||||
|
||||
export type YaakContext = {
|
||||
metadata: {
|
||||
getVersion(): Promise<string>;
|
||||
};
|
||||
httpRequest: {
|
||||
send(id: string): Promise<HttpResponse>;
|
||||
getById(id: string): Promise<HttpRequest | null>;
|
||||
};
|
||||
};
|
||||
16
plugin-runtime-types/src/plugins/import.ts
Normal file
16
plugin-runtime-types/src/plugins/import.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { AtLeast } from '../helpers';
|
||||
import { Environment, Folder, HttpRequest, Workspace } from '../models';
|
||||
import { YaakContext } from './context';
|
||||
|
||||
export type ImportPluginResponse = null | {
|
||||
resources: Partial<{
|
||||
workspaces: AtLeast<Workspace, 'name' | 'id' | 'model'>[];
|
||||
environments: AtLeast<Environment, 'name' | 'id' | 'model' | 'workspaceId'>[];
|
||||
httpRequests: AtLeast<HttpRequest, 'name' | 'id' | 'model' | 'workspaceId'>[];
|
||||
folders: AtLeast<Folder, 'name' | 'id' | 'model' | 'workspaceId'>[];
|
||||
}>;
|
||||
};
|
||||
|
||||
export type ImporterPlugin = {
|
||||
onImport(ctx: YaakContext, fileContents: string): Promise<ImportPluginResponse>;
|
||||
};
|
||||
13
plugin-runtime-types/src/plugins/index.ts
Normal file
13
plugin-runtime-types/src/plugins/index.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { SingleOrArray } from '../helpers';
|
||||
import { ImporterPlugin } from './import';
|
||||
import { ThemePlugin } from './theme';
|
||||
|
||||
/**
|
||||
* The global structure of a Yaak plugin
|
||||
*/
|
||||
export type YaakPlugin = {
|
||||
/** One or many plugins to import data into Yaak */
|
||||
importers?: SingleOrArray<ImporterPlugin>;
|
||||
/** One or many themes to customize the Yaak UI */
|
||||
themes?: SingleOrArray<ThemePlugin>;
|
||||
};
|
||||
5
plugin-runtime-types/src/plugins/theme.ts
Normal file
5
plugin-runtime-types/src/plugins/theme.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { Theme } from '../themes';
|
||||
|
||||
export type ThemePlugin = {
|
||||
theme: Theme;
|
||||
};
|
||||
44
plugin-runtime-types/src/themes/index.ts
Normal file
44
plugin-runtime-types/src/themes/index.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
export type Colors = {
|
||||
surface: string;
|
||||
surfaceHighlight?: string;
|
||||
surfaceActive?: string;
|
||||
|
||||
text: string;
|
||||
textSubtle?: string;
|
||||
textSubtlest?: string;
|
||||
|
||||
border?: string;
|
||||
borderSubtle?: string;
|
||||
borderFocus?: string;
|
||||
|
||||
shadow?: string;
|
||||
backdrop?: string;
|
||||
selection?: string;
|
||||
|
||||
primary?: string;
|
||||
secondary?: string;
|
||||
info?: string;
|
||||
success?: string;
|
||||
notice?: string;
|
||||
warning?: string;
|
||||
danger?: string;
|
||||
};
|
||||
|
||||
export type Theme = Colors & {
|
||||
id: string;
|
||||
name: string;
|
||||
components?: Partial<{
|
||||
dialog: Partial<Colors>;
|
||||
menu: Partial<Colors>;
|
||||
toast: Partial<Colors>;
|
||||
sidebar: Partial<Colors>;
|
||||
responsePane: Partial<Colors>;
|
||||
appHeader: Partial<Colors>;
|
||||
button: Partial<Colors>;
|
||||
banner: Partial<Colors>;
|
||||
placeholder: Partial<Colors>;
|
||||
urlBar: Partial<Colors>;
|
||||
editor: Partial<Colors>;
|
||||
input: Partial<Colors>;
|
||||
}>;
|
||||
};
|
||||
Reference in New Issue
Block a user