diff --git a/.eslintrc.cjs b/.eslintrc.cjs index eb33d92c..d050f7a6 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -15,8 +15,8 @@ module.exports = { }, ignorePatterns: [ 'scripts/**/*', - 'plugin-runtime/**/*', - 'plugin-runtime-types/**/*', + 'packages/plugin-runtime/**/*', + 'packages/plugin-runtime-types/**/*', 'src-tauri/**/*', 'src-web/tailwind.config.cjs', 'src-web/vite.config.ts', diff --git a/package.json b/package.json index 2354641d..3ee67761 100644 --- a/package.json +++ b/package.json @@ -7,8 +7,8 @@ "url": "git+https://github.com/mountain-loop/yaak.git" }, "workspaces": [ - "plugin-runtime", - "plugin-runtime-types", + "packages/plugin-runtime", + "packages/plugin-runtime-types", "src-tauri/yaak-license", "src-tauri/yaak-models", "src-tauri/yaak-plugins", diff --git a/plugin-runtime-types/.gitignore b/packages/plugin-runtime-types/.gitignore similarity index 100% rename from plugin-runtime-types/.gitignore rename to packages/plugin-runtime-types/.gitignore diff --git a/plugin-runtime-types/package-lock.json b/packages/plugin-runtime-types/package-lock.json similarity index 100% rename from plugin-runtime-types/package-lock.json rename to packages/plugin-runtime-types/package-lock.json diff --git a/plugin-runtime-types/package.json b/packages/plugin-runtime-types/package.json similarity index 68% rename from plugin-runtime-types/package.json rename to packages/plugin-runtime-types/package.json index 8904f0c4..31aea7dd 100644 --- a/plugin-runtime-types/package.json +++ b/packages/plugin-runtime-types/package.json @@ -11,8 +11,8 @@ "build": "run-s build:copy-types build:tsc", "build:tsc": "tsc", "build:copy-types": "run-p build:copy-types:*", - "build:copy-types:root": "cpy --flat ../src-tauri/yaak-plugin-runtime/bindings/*.ts ./src/bindings", - "build:copy-types:next": "cpy --flat ../src-tauri/yaak-plugin-runtime/bindings/serde_json/*.ts ./src/bindings/serde_json", + "build:copy-types:root": "cpy --flat ../../src-tauri/yaak-plugin-runtime/bindings/*.ts ./src/bindings", + "build:copy-types:next": "cpy --flat ../../src-tauri/yaak-plugin-runtime/bindings/serde_json/*.ts ./src/bindings/serde_json", "prepublishOnly": "npm run build" }, "dependencies": { diff --git a/packages/plugin-runtime-types/src/bindings/events.ts b/packages/plugin-runtime-types/src/bindings/events.ts new file mode 100644 index 00000000..88f08ff3 --- /dev/null +++ b/packages/plugin-runtime-types/src/bindings/events.ts @@ -0,0 +1,338 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { + Environment, + Folder, + GrpcRequest, + HttpRequest, + HttpResponse, + Workspace, +} from './models'; +import type { JsonValue } from './serde_json/JsonValue'; + +export type BootRequest = { dir: string; watch: boolean }; + +export type BootResponse = { name: string; version: string; capabilities: Array }; + +export type CallHttpRequestActionArgs = { httpRequest: HttpRequest }; + +export type CallHttpRequestActionRequest = { + key: string; + pluginRefId: string; + args: CallHttpRequestActionArgs; +}; + +export type CallTemplateFunctionArgs = { + purpose: RenderPurpose; + values: { [key in string]?: string }; +}; + +export type CallTemplateFunctionRequest = { name: string; args: CallTemplateFunctionArgs }; + +export type CallTemplateFunctionResponse = { value: string | null }; + +export type Color = + | 'custom' + | 'default' + | 'primary' + | 'secondary' + | 'info' + | 'success' + | 'notice' + | 'warning' + | 'danger'; + +export type CopyTextRequest = { text: string }; + +export type ExportHttpRequestRequest = { httpRequest: HttpRequest }; + +export type ExportHttpRequestResponse = { content: string }; + +export type FilterRequest = { content: string; filter: string }; + +export type FilterResponse = { content: string }; + +export type FindHttpResponsesRequest = { requestId: string; limit?: number }; + +export type FindHttpResponsesResponse = { httpResponses: Array }; + +export type GetHttpRequestActionsRequest = Record; + +export type GetHttpRequestActionsResponse = { + actions: Array; + pluginRefId: string; +}; + +export type GetHttpRequestByIdRequest = { id: string }; + +export type GetHttpRequestByIdResponse = { httpRequest: HttpRequest | null }; + +export type GetTemplateFunctionsResponse = { + functions: Array; + pluginRefId: string; +}; + +export type HttpRequestAction = { key: string; label: string; icon?: Icon }; + +export type Icon = 'copy' | 'info' | 'check_circle' | 'alert_triangle' | '_unknown'; + +export type ImportRequest = { content: string }; + +export type ImportResources = { + workspaces: Array; + environments: Array; + folders: Array; + httpRequests: Array; + grpcRequests: Array; +}; + +export type ImportResponse = { resources: ImportResources }; + +export type InternalEvent = { + id: string; + pluginRefId: string; + replyId: string | null; + payload: InternalEventPayload; + windowContext: WindowContext; +}; + +export type InternalEventPayload = + | ({ type: 'boot_request' } & BootRequest) + | ({ type: 'boot_response' } & BootResponse) + | { type: 'reload_request' } + | { type: 'reload_response' } + | { type: 'terminate_request' } + | { type: 'terminate_response' } + | ({ type: 'import_request' } & ImportRequest) + | ({ type: 'import_response' } & ImportResponse) + | ({ type: 'filter_request' } & FilterRequest) + | ({ type: 'filter_response' } & FilterResponse) + | ({ type: 'export_http_request_request' } & ExportHttpRequestRequest) + | ({ type: 'export_http_request_response' } & ExportHttpRequestResponse) + | ({ type: 'send_http_request_request' } & SendHttpRequestRequest) + | ({ type: 'send_http_request_response' } & SendHttpRequestResponse) + | ({ type: 'get_http_request_actions_request' } & GetHttpRequestActionsRequest) + | ({ type: 'get_http_request_actions_response' } & GetHttpRequestActionsResponse) + | ({ type: 'call_http_request_action_request' } & CallHttpRequestActionRequest) + | { type: 'get_template_functions_request' } + | ({ type: 'get_template_functions_response' } & GetTemplateFunctionsResponse) + | ({ type: 'call_template_function_request' } & CallTemplateFunctionRequest) + | ({ type: 'call_template_function_response' } & CallTemplateFunctionResponse) + | ({ type: 'copy_text_request' } & CopyTextRequest) + | ({ type: 'render_http_request_request' } & RenderHttpRequestRequest) + | ({ type: 'render_http_request_response' } & RenderHttpRequestResponse) + | ({ type: 'template_render_request' } & TemplateRenderRequest) + | ({ type: 'template_render_response' } & TemplateRenderResponse) + | ({ type: 'show_toast_request' } & ShowToastRequest) + | ({ type: 'prompt_text_request' } & PromptTextRequest) + | ({ type: 'prompt_text_response' } & PromptTextResponse) + | ({ type: 'get_http_request_by_id_request' } & GetHttpRequestByIdRequest) + | ({ type: 'get_http_request_by_id_response' } & GetHttpRequestByIdResponse) + | ({ type: 'find_http_responses_request' } & FindHttpResponsesRequest) + | ({ type: 'find_http_responses_response' } & FindHttpResponsesResponse) + | { type: 'empty_response' }; + +export type OpenFileFilter = { + name: string; + /** + * File extensions to require + */ + extensions: Array; +}; + +export type PromptTextRequest = { + id: string; + title: string; + label: string; + description?: string; + defaultValue?: string; + placeholder?: string; + /** + * Text to add to the confirmation button + */ + confirmText?: string; + /** + * Text to add to the cancel button + */ + cancelText?: string; + /** + * Require the user to enter a non-empty value + */ + require?: boolean; +}; + +export type PromptTextResponse = { value: string | null }; + +export type RenderHttpRequestRequest = { httpRequest: HttpRequest; purpose: RenderPurpose }; + +export type RenderHttpRequestResponse = { httpRequest: HttpRequest }; + +export type RenderPurpose = 'send' | 'preview'; + +export type SendHttpRequestRequest = { httpRequest: HttpRequest }; + +export type SendHttpRequestResponse = { httpResponse: HttpResponse }; + +export type ShowToastRequest = { message: string; color?: Color; icon?: Icon }; + +export type TemplateFunction = { + name: string; + description?: string; + /** + * Also support alternative names. This is useful for not breaking existing + * tags when changing the `name` property + */ + aliases?: Array; + args: Array; +}; + +export type TemplateFunctionArg = + | ({ type: 'text' } & TemplateFunctionTextArg) + | ({ + type: 'select'; + } & TemplateFunctionSelectArg) + | ({ type: 'checkbox' } & TemplateFunctionCheckboxArg) + | ({ + type: 'http_request'; + } & TemplateFunctionHttpRequestArg) + | ({ type: 'file' } & TemplateFunctionFileArg); + +export type TemplateFunctionBaseArg = { + /** + * The name of the argument. Should be `camelCase` format + */ + name: string; + /** + * Whether the user must fill in the argument + */ + optional?: boolean; + /** + * The label of the input + */ + label?: string; + /** + * The default value + */ + defaultValue?: string; +}; + +export type TemplateFunctionCheckboxArg = { + /** + * The name of the argument. Should be `camelCase` format + */ + name: string; + /** + * Whether the user must fill in the argument + */ + optional?: boolean; + /** + * The label of the input + */ + label?: string; + /** + * The default value + */ + defaultValue?: string; +}; + +export type TemplateFunctionFileArg = { + /** + * The title of the file selection window + */ + title: string; + /** + * Allow selecting multiple files + */ + multiple?: boolean; + directory?: boolean; + defaultPath?: string; + filters?: Array; + /** + * The name of the argument. Should be `camelCase` format + */ + name: string; + /** + * Whether the user must fill in the argument + */ + optional?: boolean; + /** + * The label of the input + */ + label?: string; + /** + * The default value + */ + defaultValue?: string; +}; + +export type TemplateFunctionHttpRequestArg = { + /** + * The name of the argument. Should be `camelCase` format + */ + name: string; + /** + * Whether the user must fill in the argument + */ + optional?: boolean; + /** + * The label of the input + */ + label?: string; + /** + * The default value + */ + defaultValue?: string; +}; + +export type TemplateFunctionSelectArg = { + /** + * The options that will be available in the select input + */ + options: Array; + /** + * The name of the argument. Should be `camelCase` format + */ + name: string; + /** + * Whether the user must fill in the argument + */ + optional?: boolean; + /** + * The label of the input + */ + label?: string; + /** + * The default value + */ + defaultValue?: string; +}; + +export type TemplateFunctionSelectOption = { label: string; value: string }; + +export type TemplateFunctionTextArg = { + /** + * Placeholder for the text input + */ + placeholder?: string; + /** + * The name of the argument. Should be `camelCase` format + */ + name: string; + /** + * Whether the user must fill in the argument + */ + optional?: boolean; + /** + * The label of the input + */ + label?: string; + /** + * The default value + */ + defaultValue?: string; +}; + +export type TemplateRenderRequest = { data: JsonValue; purpose: RenderPurpose }; + +export type TemplateRenderResponse = { data: JsonValue }; + +export type WindowContext = { type: 'none' } | { type: 'label'; label: string }; diff --git a/plugin-runtime-types/src/bindings/models.ts b/packages/plugin-runtime-types/src/bindings/models.ts similarity index 100% rename from plugin-runtime-types/src/bindings/models.ts rename to packages/plugin-runtime-types/src/bindings/models.ts diff --git a/plugin-runtime-types/src/bindings/serde_json/JsonValue.ts b/packages/plugin-runtime-types/src/bindings/serde_json/JsonValue.ts similarity index 100% rename from plugin-runtime-types/src/bindings/serde_json/JsonValue.ts rename to packages/plugin-runtime-types/src/bindings/serde_json/JsonValue.ts diff --git a/plugin-runtime-types/src/helpers.ts b/packages/plugin-runtime-types/src/helpers.ts similarity index 100% rename from plugin-runtime-types/src/helpers.ts rename to packages/plugin-runtime-types/src/helpers.ts diff --git a/plugin-runtime-types/src/index.ts b/packages/plugin-runtime-types/src/index.ts similarity index 100% rename from plugin-runtime-types/src/index.ts rename to packages/plugin-runtime-types/src/index.ts diff --git a/plugin-runtime-types/src/plugins/Context.ts b/packages/plugin-runtime-types/src/plugins/Context.ts similarity index 98% rename from plugin-runtime-types/src/plugins/Context.ts rename to packages/plugin-runtime-types/src/plugins/Context.ts index 0c1d897b..251d0164 100644 --- a/plugin-runtime-types/src/plugins/Context.ts +++ b/packages/plugin-runtime-types/src/plugins/Context.ts @@ -1,4 +1,4 @@ -import { +import type { FindHttpResponsesRequest, FindHttpResponsesResponse, GetHttpRequestByIdRequest, diff --git a/plugin-runtime-types/src/plugins/FilterPlugin.ts b/packages/plugin-runtime-types/src/plugins/FilterPlugin.ts similarity index 87% rename from plugin-runtime-types/src/plugins/FilterPlugin.ts rename to packages/plugin-runtime-types/src/plugins/FilterPlugin.ts index 32cd2f26..7e57a196 100644 --- a/plugin-runtime-types/src/plugins/FilterPlugin.ts +++ b/packages/plugin-runtime-types/src/plugins/FilterPlugin.ts @@ -1,4 +1,4 @@ -import { Context } from './Context'; +import type { Context } from './Context'; export type FilterPluginResponse = string[]; diff --git a/plugin-runtime-types/src/plugins/HttpRequestActionPlugin.ts b/packages/plugin-runtime-types/src/plugins/HttpRequestActionPlugin.ts similarity index 55% rename from plugin-runtime-types/src/plugins/HttpRequestActionPlugin.ts rename to packages/plugin-runtime-types/src/plugins/HttpRequestActionPlugin.ts index 66b87edf..06b62586 100644 --- a/plugin-runtime-types/src/plugins/HttpRequestActionPlugin.ts +++ b/packages/plugin-runtime-types/src/plugins/HttpRequestActionPlugin.ts @@ -1,5 +1,5 @@ -import { CallHttpRequestActionArgs, HttpRequestAction } from '..'; -import { Context } from './Context'; +import type { CallHttpRequestActionArgs, HttpRequestAction } from '..'; +import type { Context } from './Context'; export type HttpRequestActionPlugin = HttpRequestAction & { onSelect(ctx: Context, args: CallHttpRequestActionArgs): Promise | void; diff --git a/plugin-runtime-types/src/plugins/ImporterPlugin.ts b/packages/plugin-runtime-types/src/plugins/ImporterPlugin.ts similarity index 77% rename from plugin-runtime-types/src/plugins/ImporterPlugin.ts rename to packages/plugin-runtime-types/src/plugins/ImporterPlugin.ts index b9ea23a0..23775ed8 100644 --- a/plugin-runtime-types/src/plugins/ImporterPlugin.ts +++ b/packages/plugin-runtime-types/src/plugins/ImporterPlugin.ts @@ -1,6 +1,6 @@ -import { Environment, Folder, GrpcRequest, HttpRequest, Workspace } from '..'; -import { AtLeast } from '../helpers'; -import { Context } from './Context'; +import type { Environment, Folder, GrpcRequest, HttpRequest, Workspace } from '..'; +import type { AtLeast } from '../helpers'; +import type { Context } from './Context'; export type ImportPluginResponse = null | { workspaces: AtLeast[]; diff --git a/plugin-runtime-types/src/plugins/TemplateFunctionPlugin.ts b/packages/plugin-runtime-types/src/plugins/TemplateFunctionPlugin.ts similarity index 56% rename from plugin-runtime-types/src/plugins/TemplateFunctionPlugin.ts rename to packages/plugin-runtime-types/src/plugins/TemplateFunctionPlugin.ts index a0ed36ea..ed15f6e2 100644 --- a/plugin-runtime-types/src/plugins/TemplateFunctionPlugin.ts +++ b/packages/plugin-runtime-types/src/plugins/TemplateFunctionPlugin.ts @@ -1,5 +1,5 @@ -import { CallTemplateFunctionArgs, TemplateFunction } from '..'; -import { Context } from './Context'; +import type { CallTemplateFunctionArgs, TemplateFunction } from '..'; +import type { Context } from './Context'; export type TemplateFunctionPlugin = TemplateFunction & { onRender(ctx: Context, args: CallTemplateFunctionArgs): Promise; diff --git a/plugin-runtime-types/src/plugins/ThemePlugin.ts b/packages/plugin-runtime-types/src/plugins/ThemePlugin.ts similarity index 62% rename from plugin-runtime-types/src/plugins/ThemePlugin.ts rename to packages/plugin-runtime-types/src/plugins/ThemePlugin.ts index ab832e43..342f36fd 100644 --- a/plugin-runtime-types/src/plugins/ThemePlugin.ts +++ b/packages/plugin-runtime-types/src/plugins/ThemePlugin.ts @@ -1,5 +1,5 @@ -import { Theme } from '../themes'; -import { Context } from './Context'; +import type { Theme } from '../themes'; +import type { Context } from './Context'; export type ThemePlugin = { name: string; diff --git a/plugin-runtime-types/src/plugins/index.ts b/packages/plugin-runtime-types/src/plugins/index.ts similarity index 50% rename from plugin-runtime-types/src/plugins/index.ts rename to packages/plugin-runtime-types/src/plugins/index.ts index 95f77053..528fcf03 100644 --- a/plugin-runtime-types/src/plugins/index.ts +++ b/packages/plugin-runtime-types/src/plugins/index.ts @@ -1,8 +1,8 @@ -import { FilterPlugin } from './FilterPlugin'; -import { HttpRequestActionPlugin } from './HttpRequestActionPlugin'; -import { ImporterPlugin } from './ImporterPlugin'; -import { TemplateFunctionPlugin } from './TemplateFunctionPlugin'; -import { ThemePlugin } from './ThemePlugin'; +import type { FilterPlugin } from './FilterPlugin'; +import type { HttpRequestActionPlugin } from './HttpRequestActionPlugin'; +import type { ImporterPlugin } from './ImporterPlugin'; +import type { TemplateFunctionPlugin } from './TemplateFunctionPlugin'; +import type { ThemePlugin } from './ThemePlugin'; export type { Context } from './Context'; diff --git a/plugin-runtime-types/src/themes/index.ts b/packages/plugin-runtime-types/src/themes/index.ts similarity index 100% rename from plugin-runtime-types/src/themes/index.ts rename to packages/plugin-runtime-types/src/themes/index.ts diff --git a/plugin-runtime-types/tsconfig.json b/packages/plugin-runtime-types/tsconfig.json similarity index 100% rename from plugin-runtime-types/tsconfig.json rename to packages/plugin-runtime-types/tsconfig.json diff --git a/plugin-runtime/.gitignore b/packages/plugin-runtime/.gitignore similarity index 100% rename from plugin-runtime/.gitignore rename to packages/plugin-runtime/.gitignore diff --git a/plugin-runtime/package.json b/packages/plugin-runtime/package.json similarity index 73% rename from plugin-runtime/package.json rename to packages/plugin-runtime/package.json index 057d790d..0d44286b 100644 --- a/plugin-runtime/package.json +++ b/packages/plugin-runtime/package.json @@ -3,9 +3,9 @@ "scripts": { "bootstrap": "npm run build", "build": "run-p build:*", - "build:main": "esbuild src/index.ts --bundle --platform=node --outfile=../src-tauri/vendored/plugin-runtime/index.cjs", - "build:worker": "esbuild src/index.worker.ts --bundle --platform=node --outfile=../src-tauri/vendored/plugin-runtime/index.worker.cjs", - "build:proto": "grpc_tools_node_protoc --ts_proto_out=src/gen --ts_proto_opt=outputServices=nice-grpc,outputServices=generic-definitions,useExactTypes=false --proto_path=../proto ../proto/plugins/*.proto" + "build:main": "esbuild src/index.ts --bundle --platform=node --outfile=../../src-tauri/vendored/plugin-runtime/index.cjs", + "build:worker": "esbuild src/index.worker.ts --bundle --platform=node --outfile=../../src-tauri/vendored/plugin-runtime/index.worker.cjs", + "build:proto": "grpc_tools_node_protoc --ts_proto_out=src/gen --ts_proto_opt=outputServices=nice-grpc,outputServices=generic-definitions,useExactTypes=false --proto_path=../../proto ../../proto/plugins/*.proto" }, "dependencies": { "intercept-stdout": "^0.1.2", diff --git a/plugin-runtime/src/EventChannel.ts b/packages/plugin-runtime/src/EventChannel.ts similarity index 81% rename from plugin-runtime/src/EventChannel.ts rename to packages/plugin-runtime/src/EventChannel.ts index 9e51623f..9286ab2f 100644 --- a/plugin-runtime/src/EventChannel.ts +++ b/packages/plugin-runtime/src/EventChannel.ts @@ -1,6 +1,6 @@ -import { InternalEvent } from '@yaakapp/api'; +import type { InternalEvent } from '@yaakapp/api'; import EventEmitter from 'node:events'; -import { EventStreamEvent } from './gen/plugins/runtime'; +import type { EventStreamEvent } from './gen/plugins/runtime'; export class EventChannel { emitter: EventEmitter = new EventEmitter(); diff --git a/plugin-runtime/src/PluginHandle.ts b/packages/plugin-runtime/src/PluginHandle.ts similarity index 87% rename from plugin-runtime/src/PluginHandle.ts rename to packages/plugin-runtime/src/PluginHandle.ts index 4f457a9d..7c4ae52b 100644 --- a/plugin-runtime/src/PluginHandle.ts +++ b/packages/plugin-runtime/src/PluginHandle.ts @@ -1,8 +1,8 @@ -import { BootRequest, InternalEvent } from '@yaakapp-internal/plugins'; +import type { BootRequest, InternalEvent } from '@yaakapp-internal/plugins'; import path from 'node:path'; import { Worker } from 'node:worker_threads'; -import { EventChannel } from './EventChannel'; -import { PluginWorkerData } from './index.worker'; +import type { EventChannel } from './EventChannel'; +import type { PluginWorkerData } from './index.worker'; export class PluginHandle { #worker: Worker; diff --git a/plugin-runtime/src/gen/plugins/runtime.ts b/packages/plugin-runtime/src/gen/plugins/runtime.ts similarity index 100% rename from plugin-runtime/src/gen/plugins/runtime.ts rename to packages/plugin-runtime/src/gen/plugins/runtime.ts diff --git a/plugin-runtime/src/index.ts b/packages/plugin-runtime/src/index.ts similarity index 90% rename from plugin-runtime/src/index.ts rename to packages/plugin-runtime/src/index.ts index 08310cfc..754e1acc 100644 --- a/plugin-runtime/src/index.ts +++ b/packages/plugin-runtime/src/index.ts @@ -1,7 +1,8 @@ -import { InternalEvent } from '@yaakapp/api'; +import type { InternalEvent } from '@yaakapp/api'; import { createChannel, createClient, Status } from 'nice-grpc'; import { EventChannel } from './EventChannel'; -import { PluginRuntimeClient, PluginRuntimeDefinition } from './gen/plugins/runtime'; +import type { PluginRuntimeClient} from './gen/plugins/runtime'; +import { PluginRuntimeDefinition } from './gen/plugins/runtime'; import { PluginHandle } from './PluginHandle'; const port = process.env.PORT || '50051'; diff --git a/plugin-runtime/src/index.worker.ts b/packages/plugin-runtime/src/index.worker.ts similarity index 96% rename from plugin-runtime/src/index.worker.ts rename to packages/plugin-runtime/src/index.worker.ts index a1ccc290..5bce613a 100644 --- a/plugin-runtime/src/index.worker.ts +++ b/packages/plugin-runtime/src/index.worker.ts @@ -1,4 +1,4 @@ -import { +import type { BootRequest, FindHttpResponsesResponse, GetHttpRequestByIdResponse, @@ -13,12 +13,13 @@ import { TemplateRenderResponse, WindowContext, } from '@yaakapp-internal/plugins'; -import { Context } from '@yaakapp/api'; -import { HttpRequestActionPlugin } from '@yaakapp/api/lib/plugins/HttpRequestActionPlugin'; -import { TemplateFunctionPlugin } from '@yaakapp/api/lib/plugins/TemplateFunctionPlugin'; +import type { Context } from '@yaakapp/api'; +import type { HttpRequestActionPlugin } from '@yaakapp/api/lib/plugins/HttpRequestActionPlugin'; +import type { TemplateFunctionPlugin } from '@yaakapp/api/lib/plugins/TemplateFunctionPlugin'; import interceptStdout from 'intercept-stdout'; import * as console from 'node:console'; -import { readFileSync, Stats, statSync, watch } from 'node:fs'; +import type { Stats} from 'node:fs'; +import { readFileSync, statSync, watch } from 'node:fs'; import path from 'node:path'; import * as util from 'node:util'; import { parentPort, workerData } from 'node:worker_threads'; @@ -200,7 +201,7 @@ async function initialize() { // Message comes into the plugin to be processed parentPort!.on('message', async (event: InternalEvent) => { - let { windowContext, payload, id: replyId } = event; + const { windowContext, payload, id: replyId } = event; const ctx = newCtx(event); try { if (payload.type === 'boot_request') { diff --git a/plugin-runtime/tsconfig.json b/packages/plugin-runtime/tsconfig.json similarity index 100% rename from plugin-runtime/tsconfig.json rename to packages/plugin-runtime/tsconfig.json diff --git a/plugin-runtime-types/src/bindings/events.ts b/plugin-runtime-types/src/bindings/events.ts deleted file mode 100644 index 65a536b0..00000000 --- a/plugin-runtime-types/src/bindings/events.ts +++ /dev/null @@ -1,237 +0,0 @@ -// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. -import type { Environment } from "./models"; -import type { Folder } from "./models"; -import type { GrpcRequest } from "./models"; -import type { HttpRequest } from "./models"; -import type { HttpResponse } from "./models"; -import type { JsonValue } from "./serde_json/JsonValue"; -import type { Workspace } from "./models"; - -export type BootRequest = { dir: string, watch: boolean, }; - -export type BootResponse = { name: string, version: string, capabilities: Array, }; - -export type CallHttpRequestActionArgs = { httpRequest: HttpRequest, }; - -export type CallHttpRequestActionRequest = { key: string, pluginRefId: string, args: CallHttpRequestActionArgs, }; - -export type CallTemplateFunctionArgs = { purpose: RenderPurpose, values: { [key in string]?: string }, }; - -export type CallTemplateFunctionRequest = { name: string, args: CallTemplateFunctionArgs, }; - -export type CallTemplateFunctionResponse = { value: string | null, }; - -export type Color = "custom" | "default" | "primary" | "secondary" | "info" | "success" | "notice" | "warning" | "danger"; - -export type CopyTextRequest = { text: string, }; - -export type ExportHttpRequestRequest = { httpRequest: HttpRequest, }; - -export type ExportHttpRequestResponse = { content: string, }; - -export type FilterRequest = { content: string, filter: string, }; - -export type FilterResponse = { content: string, }; - -export type FindHttpResponsesRequest = { requestId: string, limit?: number, }; - -export type FindHttpResponsesResponse = { httpResponses: Array, }; - -export type GetHttpRequestActionsRequest = Record; - -export type GetHttpRequestActionsResponse = { actions: Array, pluginRefId: string, }; - -export type GetHttpRequestByIdRequest = { id: string, }; - -export type GetHttpRequestByIdResponse = { httpRequest: HttpRequest | null, }; - -export type GetTemplateFunctionsResponse = { functions: Array, pluginRefId: string, }; - -export type HttpRequestAction = { key: string, label: string, icon?: Icon, }; - -export type Icon = "copy" | "info" | "check_circle" | "alert_triangle" | "_unknown"; - -export type ImportRequest = { content: string, }; - -export type ImportResources = { workspaces: Array, environments: Array, folders: Array, httpRequests: Array, grpcRequests: Array, }; - -export type ImportResponse = { resources: ImportResources, }; - -export type InternalEvent = { id: string, pluginRefId: string, replyId: string | null, payload: InternalEventPayload, windowContext: WindowContext, }; - -export type InternalEventPayload = { "type": "boot_request" } & BootRequest | { "type": "boot_response" } & BootResponse | { "type": "reload_request" } | { "type": "reload_response" } | { "type": "terminate_request" } | { "type": "terminate_response" } | { "type": "import_request" } & ImportRequest | { "type": "import_response" } & ImportResponse | { "type": "filter_request" } & FilterRequest | { "type": "filter_response" } & FilterResponse | { "type": "export_http_request_request" } & ExportHttpRequestRequest | { "type": "export_http_request_response" } & ExportHttpRequestResponse | { "type": "send_http_request_request" } & SendHttpRequestRequest | { "type": "send_http_request_response" } & SendHttpRequestResponse | { "type": "get_http_request_actions_request" } & GetHttpRequestActionsRequest | { "type": "get_http_request_actions_response" } & GetHttpRequestActionsResponse | { "type": "call_http_request_action_request" } & CallHttpRequestActionRequest | { "type": "get_template_functions_request" } | { "type": "get_template_functions_response" } & GetTemplateFunctionsResponse | { "type": "call_template_function_request" } & CallTemplateFunctionRequest | { "type": "call_template_function_response" } & CallTemplateFunctionResponse | { "type": "copy_text_request" } & CopyTextRequest | { "type": "render_http_request_request" } & RenderHttpRequestRequest | { "type": "render_http_request_response" } & RenderHttpRequestResponse | { "type": "template_render_request" } & TemplateRenderRequest | { "type": "template_render_response" } & TemplateRenderResponse | { "type": "show_toast_request" } & ShowToastRequest | { "type": "prompt_text_request" } & PromptTextRequest | { "type": "prompt_text_response" } & PromptTextResponse | { "type": "get_http_request_by_id_request" } & GetHttpRequestByIdRequest | { "type": "get_http_request_by_id_response" } & GetHttpRequestByIdResponse | { "type": "find_http_responses_request" } & FindHttpResponsesRequest | { "type": "find_http_responses_response" } & FindHttpResponsesResponse | { "type": "empty_response" }; - -export type OpenFileFilter = { name: string, -/** - * File extensions to require - */ -extensions: Array, }; - -export type PromptTextRequest = { id: string, title: string, label: string, description?: string, defaultValue?: string, placeholder?: string, -/** - * Text to add to the confirmation button - */ -confirmText?: string, -/** - * Text to add to the cancel button - */ -cancelText?: string, -/** - * Require the user to enter a non-empty value - */ -require?: boolean, }; - -export type PromptTextResponse = { value: string | null, }; - -export type RenderHttpRequestRequest = { httpRequest: HttpRequest, purpose: RenderPurpose, }; - -export type RenderHttpRequestResponse = { httpRequest: HttpRequest, }; - -export type RenderPurpose = "send" | "preview"; - -export type SendHttpRequestRequest = { httpRequest: HttpRequest, }; - -export type SendHttpRequestResponse = { httpResponse: HttpResponse, }; - -export type ShowToastRequest = { message: string, color?: Color, icon?: Icon, }; - -export type TemplateFunction = { name: string, description?: string, -/** - * Also support alternative names. This is useful for not breaking existing - * tags when changing the `name` property - */ -aliases?: Array, args: Array, }; - -export type TemplateFunctionArg = { "type": "text" } & TemplateFunctionTextArg | { "type": "select" } & TemplateFunctionSelectArg | { "type": "checkbox" } & TemplateFunctionCheckboxArg | { "type": "http_request" } & TemplateFunctionHttpRequestArg | { "type": "file" } & TemplateFunctionFileArg; - -export type TemplateFunctionBaseArg = { -/** - * The name of the argument. Should be `camelCase` format - */ -name: string, -/** - * Whether the user must fill in the argument - */ -optional?: boolean, -/** - * The label of the input - */ -label?: string, -/** - * The default value - */ -defaultValue?: string, }; - -export type TemplateFunctionCheckboxArg = { -/** - * The name of the argument. Should be `camelCase` format - */ -name: string, -/** - * Whether the user must fill in the argument - */ -optional?: boolean, -/** - * The label of the input - */ -label?: string, -/** - * The default value - */ -defaultValue?: string, }; - -export type TemplateFunctionFileArg = { -/** - * The title of the file selection window - */ -title: string, -/** - * Allow selecting multiple files - */ -multiple?: boolean, directory?: boolean, defaultPath?: string, filters?: Array, -/** - * The name of the argument. Should be `camelCase` format - */ -name: string, -/** - * Whether the user must fill in the argument - */ -optional?: boolean, -/** - * The label of the input - */ -label?: string, -/** - * The default value - */ -defaultValue?: string, }; - -export type TemplateFunctionHttpRequestArg = { -/** - * The name of the argument. Should be `camelCase` format - */ -name: string, -/** - * Whether the user must fill in the argument - */ -optional?: boolean, -/** - * The label of the input - */ -label?: string, -/** - * The default value - */ -defaultValue?: string, }; - -export type TemplateFunctionSelectArg = { -/** - * The options that will be available in the select input - */ -options: Array, -/** - * The name of the argument. Should be `camelCase` format - */ -name: string, -/** - * Whether the user must fill in the argument - */ -optional?: boolean, -/** - * The label of the input - */ -label?: string, -/** - * The default value - */ -defaultValue?: string, }; - -export type TemplateFunctionSelectOption = { label: string, value: string, }; - -export type TemplateFunctionTextArg = { -/** - * Placeholder for the text input - */ -placeholder?: string, -/** - * The name of the argument. Should be `camelCase` format - */ -name: string, -/** - * Whether the user must fill in the argument - */ -optional?: boolean, -/** - * The label of the input - */ -label?: string, -/** - * The default value - */ -defaultValue?: string, }; - -export type TemplateRenderRequest = { data: JsonValue, purpose: RenderPurpose, }; - -export type TemplateRenderResponse = { data: JsonValue, }; - -export type WindowContext = { "type": "none" } | { "type": "label", label: string, }; diff --git a/src-tauri/vendored/plugins/importer-curl/build/index.js b/src-tauri/vendored/plugins/importer-curl/build/index.js index 7241e951..7ad523af 100644 --- a/src-tauri/vendored/plugins/importer-curl/build/index.js +++ b/src-tauri/vendored/plugins/importer-curl/build/index.js @@ -265,30 +265,31 @@ __export(src_exports, { module.exports = __toCommonJS(src_exports); var import_shell_quote = __toESM(require_shell_quote()); var DATA_FLAGS = ["d", "data", "data-raw", "data-urlencode", "data-binary", "data-ascii"]; -var SUPPORTED_ARGS = [ - ["url"], - // Specify the URL explicitly - ["user", "u"], - // Authentication - ["digest"], - // Apply auth as digest - ["header", "H"], +var SUPPORTED_FLAGS = [ ["cookie", "b"], - ["get", "G"], - // Put the post data in the URL ["d", "data"], // Add url encoded data + ["data-ascii"], + ["data-binary"], ["data-raw"], ["data-urlencode"], - ["data-binary"], - ["data-ascii"], + ["digest"], + // Apply auth as digest ["form", "F"], // Add multipart data + ["get", "G"], + // Put the post data in the URL + ["header", "H"], ["request", "X"], // Request method + ["url"], + // Specify the URL explicitly + ["url-query"], + ["user", "u"], + // Authentication DATA_FLAGS ].flatMap((v) => v); -var BOOL_FLAGS = ["G", "get", "digest"]; +var BOOLEAN_FLAGS = ["G", "get", "digest"]; function pluginHookImport(_ctx, rawData) { if (!rawData.match(/^\s*curl /)) { return null; @@ -345,7 +346,7 @@ function pluginHookImport(_ctx, rawData) { }; } function importCommand(parseEntries, workspaceId) { - const pairsByName = {}; + const flagsByName = {}; const singletons = []; for (let i = 1; i < parseEntries.length; i++) { let parseEntry = parseEntries[i]; @@ -355,12 +356,12 @@ function importCommand(parseEntries, workspaceId) { if (typeof parseEntry === "string" && parseEntry.match(/^-{1,2}[\w-]+/)) { const isSingleDash = parseEntry[0] === "-" && parseEntry[1] !== "-"; let name = parseEntry.replace(/^-{1,2}/, ""); - if (!SUPPORTED_ARGS.includes(name)) { + if (!SUPPORTED_FLAGS.includes(name)) { continue; } let value; const nextEntry = parseEntries[i + 1]; - const hasValue = !BOOL_FLAGS.includes(name); + const hasValue = !BOOLEAN_FLAGS.includes(name); if (isSingleDash && name.length > 1) { value = name.slice(1); name = name.slice(0, 1); @@ -370,31 +371,42 @@ function importCommand(parseEntries, workspaceId) { } else { value = true; } - pairsByName[name] = pairsByName[name] || []; - pairsByName[name].push(value); + flagsByName[name] = flagsByName[name] || []; + flagsByName[name].push(value); } else if (parseEntry) { singletons.push(parseEntry); } } let urlParameters; let url; - const urlArg = getPairValue(pairsByName, singletons[0] || "", ["url"]); + const urlArg = getPairValue(flagsByName, singletons[0] || "", ["url"]); const [baseUrl, search] = splitOnce(urlArg, "?"); urlParameters = search?.split("&").map((p) => { const v = splitOnce(p, "="); return { name: decodeURIComponent(v[0] ?? ""), value: decodeURIComponent(v[1] ?? ""), enabled: true }; }) ?? []; url = baseUrl ?? urlArg; - const [username, password] = getPairValue(pairsByName, "", ["u", "user"]).split(/:(.*)$/); - const isDigest = getPairValue(pairsByName, false, ["digest"]); + for (const p of flagsByName["url-query"] ?? []) { + if (typeof p !== "string") { + continue; + } + const [name, value] = p.split("="); + urlParameters.push({ + name: name ?? "", + value: value ?? "", + enabled: true + }); + } + const [username, password] = getPairValue(flagsByName, "", ["u", "user"]).split(/:(.*)$/); + const isDigest = getPairValue(flagsByName, false, ["digest"]); const authenticationType = username ? isDigest ? "digest" : "basic" : null; const authentication = username ? { username: username.trim(), password: (password ?? "").trim() } : {}; const headers = [ - ...pairsByName["header"] || [], - ...pairsByName["H"] || [] + ...flagsByName["header"] || [], + ...flagsByName["H"] || [] ].map((header) => { const [name, value] = header.split(/:(.*)$/); if (!value) { @@ -411,8 +423,8 @@ function importCommand(parseEntries, workspaceId) { }; }); const cookieHeaderValue = [ - ...pairsByName["cookie"] || [], - ...pairsByName["b"] || [] + ...flagsByName["cookie"] || [], + ...flagsByName["b"] || [] ].map((str) => { const name = str.split("=", 1)[0]; const value = str.replace(`${name}=`, ""); @@ -428,12 +440,12 @@ function importCommand(parseEntries, workspaceId) { enabled: true }); } - const dataParameters = pairsToDataParameters(pairsByName); + const dataParameters = pairsToDataParameters(flagsByName); const contentTypeHeader = headers.find((header) => header.name.toLowerCase() === "content-type"); const mimeType = contentTypeHeader ? contentTypeHeader.value.split(";")[0] : null; const formDataParams = [ - ...pairsByName["form"] || [], - ...pairsByName["F"] || [] + ...flagsByName["form"] || [], + ...flagsByName["F"] || [] ].map((str) => { const parts = str.split("="); const name = parts[0] ?? ""; @@ -451,7 +463,7 @@ function importCommand(parseEntries, workspaceId) { }); let body = {}; let bodyType = null; - const bodyAsGET = getPairValue(pairsByName, false, ["G", "get"]); + const bodyAsGET = getPairValue(flagsByName, false, ["G", "get"]); if (dataParameters.length > 0 && bodyAsGET) { urlParameters.push(...dataParameters); } else if (dataParameters.length > 0 && (mimeType == null || mimeType === "application/x-www-form-urlencoded")) { @@ -486,7 +498,7 @@ function importCommand(parseEntries, workspaceId) { }); } } - let method = getPairValue(pairsByName, "", ["X", "request"]).toUpperCase(); + let method = getPairValue(flagsByName, "", ["X", "request"]).toUpperCase(); if (method === "" && body) { method = "text" in body || "form" in body ? "POST" : "GET"; } diff --git a/src-tauri/vendored/plugins/importer-insomnia/build/index.js b/src-tauri/vendored/plugins/importer-insomnia/build/index.js index a09e9f14..1179a35e 100644 --- a/src-tauri/vendored/plugins/importer-insomnia/build/index.js +++ b/src-tauri/vendored/plugins/importer-insomnia/build/index.js @@ -7233,7 +7233,6 @@ function pluginHookImport(ctx, contents) { }; const workspacesToImport = parsed.resources.filter(isWorkspace); for (const workspaceToImport of workspacesToImport) { - console.log("IMPORT WORKSPACE", workspaceToImport); resources.workspaces.push({ id: convertId(workspaceToImport._id), createdAt: new Date(workspacesToImport.created ?? Date.now()).toISOString().replace("Z", ""), diff --git a/src-tauri/yaak-license/index.ts b/src-tauri/yaak-license/index.ts index 39f55308..eedd5167 100644 --- a/src-tauri/yaak-license/index.ts +++ b/src-tauri/yaak-license/index.ts @@ -16,9 +16,12 @@ export function useLicense() { // Check the license again after a license is activated useEffect(() => { - listen('license-activated', () => { - queryClient.invalidateQueries({ queryKey: CHECK_QUERY_KEY }).catch(console.error); - }).catch(console.error); + const unlisten = listen('license-activated', async () => { + await queryClient.invalidateQueries({ queryKey: CHECK_QUERY_KEY }); + }); + return () => { + unlisten.then((fn) => fn()); + }; }, []); const CHECK_QUERY_KEY = ['license.check']; diff --git a/src-web/hooks/useListenToTauriEvent.ts b/src-web/hooks/useListenToTauriEvent.ts index d99f12db..21ff7eea 100644 --- a/src-web/hooks/useListenToTauriEvent.ts +++ b/src-web/hooks/useListenToTauriEvent.ts @@ -8,7 +8,7 @@ import {useEffect} from 'react'; */ export function useListenToTauriEvent(event: EventName, fn: EventCallback) { useEffect(() => { - const unlisten = listen( + const unlisten = listen( event, fn, // Listen to `emit_all()` events or events specific to the current window