From cbace9751bf58e625492ae7051a583b2cd5c85d6 Mon Sep 17 00:00:00 2001 From: Mentlegen <9807008+gentlementlegen@users.noreply.github.com> Date: Mon, 23 Sep 2024 19:49:24 +0900 Subject: [PATCH 1/8] feat: schema validation --- package.json | 3 ++- src/handlers/validator.ts | 39 +++++++++++++++++++++++++++++++++++++++ src/types/env.ts | 3 +++ src/types/plugin-input.ts | 7 +++++-- src/worker.ts | 27 +++++++++++++++++++-------- yarn.lock | 5 +++++ 6 files changed, 73 insertions(+), 11 deletions(-) create mode 100644 src/handlers/validator.ts diff --git a/package.json b/package.json index 2b82b40..0454670 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,8 @@ "@octokit/webhooks": "13.2.7", "@sinclair/typebox": "0.32.30", "@supabase/supabase-js": "2.43.2", - "commander": "12.1.0" + "commander": "12.1.0", + "typebox-validators": "0.3.5" }, "devDependencies": { "@commitlint/cli": "^18.6.1", diff --git a/src/handlers/validator.ts b/src/handlers/validator.ts new file mode 100644 index 0000000..3705fb7 --- /dev/null +++ b/src/handlers/validator.ts @@ -0,0 +1,39 @@ +import { Value } from "@sinclair/typebox/value"; +import { Env, envConfigValidator, envSchema } from "../types/env"; +import { CommandQuerySettings, commandQueryUserSchema, commandQueryUserSchemaValidator } from "../types/plugin-input"; + +export function validateAndDecodeSchemas(env: Env, rawSettings: object) { + const settings = Value.Default(commandQueryUserSchema, rawSettings) as CommandQuerySettings; + + if (!commandQueryUserSchemaValidator.test(settings)) { + const errorDetails: object[] = []; + for (const error of commandQueryUserSchemaValidator.errors(settings)) { + const errorMessage = { path: error.path, message: error.message, value: error.value }; + console.error(errorMessage); + errorDetails.push(errorMessage); + } + return new Response(JSON.stringify({ message: `Bad Request: the settings are invalid.`, errors: errorDetails }), { + status: 400, + headers: { "content-type": "application/json" }, + }); + } + + const decodedSettings = Value.Decode(commandQueryUserSchema, settings); + + if (!envConfigValidator.test(env)) { + const errorDetails: object[] = []; + for (const error of envConfigValidator.errors(env)) { + const errorMessage = { path: error.path, message: error.message, value: error.value }; + console.error(errorMessage); + errorDetails.push(errorMessage); + } + return new Response(JSON.stringify({ message: `Bad Request: the environment is invalid.`, errors: errorDetails }), { + status: 400, + headers: { "content-type": "application/json" }, + }); + } + + const decodedEnv = Value.Decode(envSchema, env); + + return { decodedEnv, decodedSettings }; +} diff --git a/src/types/env.ts b/src/types/env.ts index 0fc6dad..d08aa89 100644 --- a/src/types/env.ts +++ b/src/types/env.ts @@ -1,8 +1,11 @@ import { Type as T, StaticDecode } from "@sinclair/typebox"; +import { StandardValidator } from "typebox-validators"; export const envSchema = T.Object({ SUPABASE_URL: T.String(), SUPABASE_KEY: T.String(), }); +export const envConfigValidator = new StandardValidator(envSchema); + export type Env = StaticDecode; diff --git a/src/types/plugin-input.ts b/src/types/plugin-input.ts index a515e68..bcc2821 100644 --- a/src/types/plugin-input.ts +++ b/src/types/plugin-input.ts @@ -1,4 +1,5 @@ import { EmitterWebhookEvent as WebhookEvent, EmitterWebhookEventName as WebhookEventName } from "@octokit/webhooks"; +import { StandardValidator } from "typebox-validators"; import { SupportedEvents } from "./context"; import { StaticDecode, Type as T } from "@sinclair/typebox"; @@ -11,11 +12,13 @@ export interface PluginInputs { ref: string; } -export const commandQueryUserScheme = T.Object({ +export const commandQueryUserSchema = T.Object({ /** * Allows any user to query anyone else. If false, only org members can query others. */ allowPublicQuery: T.Boolean({ default: true }), }); -export type CommandQuerySettings = StaticDecode; +export const commandQueryUserSchemaValidator = new StandardValidator(commandQueryUserSchema); + +export type CommandQuerySettings = StaticDecode; diff --git a/src/worker.ts b/src/worker.ts index bbfb6a7..b937a86 100644 --- a/src/worker.ts +++ b/src/worker.ts @@ -1,18 +1,25 @@ -import { Value } from "@sinclair/typebox/value"; +import manifest from "../manifest.json"; +import { validateAndDecodeSchemas } from "./handlers/validator"; import { run } from "./run"; import { Env } from "./types/env"; -import { commandQueryUserScheme } from "./types/plugin-input"; -import manifest from "../manifest.json"; export default { async fetch(request: Request, env: Env): Promise { try { - if (request.method === "GET") { - const url = new URL(request.url); - if (url.pathname === "/manifest.json") { + const url = new URL(request.url); + if (url.pathname === "/manifest") { + if (request.method === "GET") { return new Response(JSON.stringify(manifest), { headers: { "content-type": "application/json" }, }); + } else if (request.method === "POST") { + const webhookPayload = await request.json(); + + const result = validateAndDecodeSchemas(env, webhookPayload.settings); + if (result instanceof Response) { + return result; + } + return new Response(JSON.stringify({ message: "Schema is valid" }), { status: 200, headers: { "content-type": "application/json" } }); } } if (request.method !== "POST") { @@ -29,8 +36,12 @@ export default { }); } const webhookPayload = await request.json(); - webhookPayload.settings = Value.Decode(commandQueryUserScheme, Value.Default(commandQueryUserScheme, webhookPayload.settings)); - await run(webhookPayload, env); + const result = validateAndDecodeSchemas(env, webhookPayload.settings); + if (result instanceof Response) { + return result; + } + webhookPayload.settings = result.decodedSettings; + await run(webhookPayload, result.decodedEnv); return new Response(JSON.stringify("OK"), { status: 200, headers: { "content-type": "application/json" } }); } catch (error) { return handleUncaughtError(error); diff --git a/yarn.lock b/yarn.lock index 2d66814..a2ea2af 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6806,6 +6806,11 @@ type-fest@^4.9.0: resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-4.10.3.tgz#ff01cb0a1209f59583d61e1312de9715e7ea4874" integrity sha512-JLXyjizi072smKGGcZiAJDCNweT8J+AuRxmPZ1aG7TERg4ijx9REl8CNhbr36RV4qXqL1gO1FF9HL8OkVmmrsA== +typebox-validators@0.3.5: + version "0.3.5" + resolved "https://registry.yarnpkg.com/typebox-validators/-/typebox-validators-0.3.5.tgz#b913bad0a87571ffe0edd01d2b6090a268e1ecc9" + integrity sha512-FXrmSUAN6bSGxDANResNCZQ8VRRLr5bSyy73/HyqSXGdiVuogppGAoRocy7NTVZY4Wc2sWUofmWwwIXE6OxS6Q== + typed-array-buffer@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/typed-array-buffer/-/typed-array-buffer-1.0.1.tgz#0608ffe6bca71bf15a45bff0ca2604107a1325f5" From 49c7bf4aa8d7ac9639c60c887f9ad6d7fa2b3f81 Mon Sep 17 00:00:00 2001 From: Mentlegen <9807008+gentlementlegen@users.noreply.github.com> Date: Mon, 23 Sep 2024 20:02:35 +0900 Subject: [PATCH 2/8] chore: fixed errors --- src/handlers/validator.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/handlers/validator.ts b/src/handlers/validator.ts index 3705fb7..4995623 100644 --- a/src/handlers/validator.ts +++ b/src/handlers/validator.ts @@ -1,4 +1,4 @@ -import { Value } from "@sinclair/typebox/value"; +import { Value, ValueError } from "@sinclair/typebox/value"; import { Env, envConfigValidator, envSchema } from "../types/env"; import { CommandQuerySettings, commandQueryUserSchema, commandQueryUserSchemaValidator } from "../types/plugin-input"; @@ -6,11 +6,10 @@ export function validateAndDecodeSchemas(env: Env, rawSettings: object) { const settings = Value.Default(commandQueryUserSchema, rawSettings) as CommandQuerySettings; if (!commandQueryUserSchemaValidator.test(settings)) { - const errorDetails: object[] = []; + const errorDetails: ValueError[] = []; for (const error of commandQueryUserSchemaValidator.errors(settings)) { - const errorMessage = { path: error.path, message: error.message, value: error.value }; - console.error(errorMessage); - errorDetails.push(errorMessage); + console.error(error); + errorDetails.push(error); } return new Response(JSON.stringify({ message: `Bad Request: the settings are invalid.`, errors: errorDetails }), { status: 400, @@ -21,11 +20,10 @@ export function validateAndDecodeSchemas(env: Env, rawSettings: object) { const decodedSettings = Value.Decode(commandQueryUserSchema, settings); if (!envConfigValidator.test(env)) { - const errorDetails: object[] = []; + const errorDetails: ValueError[] = []; for (const error of envConfigValidator.errors(env)) { - const errorMessage = { path: error.path, message: error.message, value: error.value }; - console.error(errorMessage); - errorDetails.push(errorMessage); + console.error(error); + errorDetails.push(error); } return new Response(JSON.stringify({ message: `Bad Request: the environment is invalid.`, errors: errorDetails }), { status: 400, From e3e0a40a62d7e849ef05c3cc7fefac2eeeb56eda Mon Sep 17 00:00:00 2001 From: Mentlegen <9807008+gentlementlegen@users.noreply.github.com> Date: Mon, 23 Sep 2024 22:03:25 +0900 Subject: [PATCH 3/8] chore: fixed errors --- src/handlers/validator.ts | 34 +++++++++++++++++----------------- src/worker.ts | 14 ++++---------- 2 files changed, 21 insertions(+), 27 deletions(-) diff --git a/src/handlers/validator.ts b/src/handlers/validator.ts index 4995623..5f09e91 100644 --- a/src/handlers/validator.ts +++ b/src/handlers/validator.ts @@ -1,37 +1,37 @@ -import { Value, ValueError } from "@sinclair/typebox/value"; +import { TransformDecodeCheckError, TransformDecodeError, Value, ValueError } from "@sinclair/typebox/value"; import { Env, envConfigValidator, envSchema } from "../types/env"; import { CommandQuerySettings, commandQueryUserSchema, commandQueryUserSchemaValidator } from "../types/plugin-input"; export function validateAndDecodeSchemas(env: Env, rawSettings: object) { + const errors: ValueError[] = []; const settings = Value.Default(commandQueryUserSchema, rawSettings) as CommandQuerySettings; if (!commandQueryUserSchemaValidator.test(settings)) { - const errorDetails: ValueError[] = []; for (const error of commandQueryUserSchemaValidator.errors(settings)) { console.error(error); - errorDetails.push(error); + errors.push(error); } - return new Response(JSON.stringify({ message: `Bad Request: the settings are invalid.`, errors: errorDetails }), { - status: 400, - headers: { "content-type": "application/json" }, - }); } - const decodedSettings = Value.Decode(commandQueryUserSchema, settings); - if (!envConfigValidator.test(env)) { - const errorDetails: ValueError[] = []; for (const error of envConfigValidator.errors(env)) { console.error(error); - errorDetails.push(error); + errors.push(error); } - return new Response(JSON.stringify({ message: `Bad Request: the environment is invalid.`, errors: errorDetails }), { - status: 400, - headers: { "content-type": "application/json" }, - }); } - const decodedEnv = Value.Decode(envSchema, env); + if (errors.length) { + throw { errors }; + } - return { decodedEnv, decodedSettings }; + try { + const decodedEnv = Value.Decode(envSchema, env); + const decodedSettings = Value.Decode(commandQueryUserSchema, settings); + return { decodedEnv, decodedSettings }; + } catch (e) { + if (e instanceof TransformDecodeCheckError || e instanceof TransformDecodeError) { + throw { errors: [e.error] }; + } + throw e; + } } diff --git a/src/worker.ts b/src/worker.ts index b937a86..b540de8 100644 --- a/src/worker.ts +++ b/src/worker.ts @@ -15,10 +15,7 @@ export default { } else if (request.method === "POST") { const webhookPayload = await request.json(); - const result = validateAndDecodeSchemas(env, webhookPayload.settings); - if (result instanceof Response) { - return result; - } + validateAndDecodeSchemas(env, webhookPayload.settings); return new Response(JSON.stringify({ message: "Schema is valid" }), { status: 200, headers: { "content-type": "application/json" } }); } } @@ -37,9 +34,6 @@ export default { } const webhookPayload = await request.json(); const result = validateAndDecodeSchemas(env, webhookPayload.settings); - if (result instanceof Response) { - return result; - } webhookPayload.settings = result.decodedSettings; await run(webhookPayload, result.decodedEnv); return new Response(JSON.stringify("OK"), { status: 200, headers: { "content-type": "application/json" } }); @@ -49,8 +43,8 @@ export default { }, }; -function handleUncaughtError(error: unknown) { - console.error(error); +function handleUncaughtError(errors: unknown) { + console.error(errors); const status = 500; - return new Response(JSON.stringify({ error }), { status: status, headers: { "content-type": "application/json" } }); + return new Response(JSON.stringify(errors), { status: status, headers: { "content-type": "application/json" } }); } From 7fc5f99caabdca572084d4fb48d8aa560cc6c8f3 Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Fri, 4 Oct 2024 01:49:26 +0900 Subject: [PATCH 4/8] chore: configuration generation --- .github/workflows/update-configuration.yml | 58 +++++++ .github/workflows/worker-deploy.yml | 2 +- package.json | 4 +- yarn.lock | 169 ++++++++++++++------- 4 files changed, 171 insertions(+), 62 deletions(-) create mode 100644 .github/workflows/update-configuration.yml diff --git a/.github/workflows/update-configuration.yml b/.github/workflows/update-configuration.yml new file mode 100644 index 0000000..2490c49 --- /dev/null +++ b/.github/workflows/update-configuration.yml @@ -0,0 +1,58 @@ +name: "Update Configuration" + +on: + workflow_dispatch: + push: + +jobs: + update: + name: "Update Configuration in manifest.json" + runs-on: ubuntu-latest + permissions: write-all + + steps: + - uses: actions/checkout@v4 + + - name: Setup node + uses: actions/setup-node@v4 + with: + node-version: "20.10.0" + + - name: Install deps and run configuration update + run: | + yarn install --immutable --immutable-cache --check-cache + yarn tsc --noCheck --project tsconfig.json + + - name: Update manifest configuration using GitHub Script + uses: actions/github-script@v7 + with: + script: | + const fs = require('fs'); + const path = require('path'); + + const { pluginSettingsSchema } = require('./src/types'); + + const manifestPath = path.resolve("${{ github.workspace }}", './manifest.json'); + const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8')); + + const configuration = JSON.stringify(pluginSettingsSchema); + + manifest["configuration"] = JSON.parse(configuration); + + const updatedManifest = JSON.stringify(manifest, null, 2) + console.log('Updated manifest:', updatedManifest); + fs.writeFileSync(manifestPath, updatedManifest); + + - name: Commit and Push generated types + run: | + git config --global user.name 'ubiquity-os[bot]' + git config --global user.email 'ubiquity-os[bot]@users.noreply.github.com' + git add ./manifest.json + if [ -n "$(git diff-index --cached --name-only HEAD)" ]; then + git commit -m "chore: updated generated configuration" || echo "Lint-staged check failed" + git push origin HEAD:${{ github.ref_name }} + else + echo "No changes to commit" + fi + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/worker-deploy.yml b/.github/workflows/worker-deploy.yml index fd23929..88c690e 100644 --- a/.github/workflows/worker-deploy.yml +++ b/.github/workflows/worker-deploy.yml @@ -35,7 +35,7 @@ jobs: id: wrangler_deploy uses: cloudflare/wrangler-action@v3 with: - wranglerVersion: "3.61.0" + wranglerVersion: "3.79.0" apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} secrets: | diff --git a/package.json b/package.json index 0454670..de29bbc 100644 --- a/package.json +++ b/package.json @@ -68,8 +68,8 @@ "prettier": "^3.2.5", "supabase": "1.167.4", "ts-jest": "29.1.2", - "typescript": "^5.3.3", - "wrangler": "3.57.0" + "typescript": "5.6.2", + "wrangler": "3.79.0" }, "lint-staged": { "*.ts": [ diff --git a/yarn.lock b/yarn.lock index a2ea2af..dd1e811 100644 --- a/yarn.lock +++ b/yarn.lock @@ -323,37 +323,45 @@ dependencies: statuses "^2.0.1" -"@cloudflare/kv-asset-handler@0.3.2": - version "0.3.2" - resolved "https://registry.yarnpkg.com/@cloudflare/kv-asset-handler/-/kv-asset-handler-0.3.2.tgz#06437b75664729823ac9033b89f06a3b078e4f55" - integrity sha512-EeEjMobfuJrwoctj7FA1y1KEbM0+Q1xSjobIEyie9k4haVEBB7vkDvsasw1pM3rO39mL2akxIAzLMUAtrMHZhA== +"@cloudflare/kv-asset-handler@0.3.4": + version "0.3.4" + resolved "https://registry.yarnpkg.com/@cloudflare/kv-asset-handler/-/kv-asset-handler-0.3.4.tgz#5cc152847c8ae4d280ec5d7f4f6ba8c976b585c3" + integrity sha512-YLPHc8yASwjNkmcDMQMY35yiWjoKAKnhUbPRszBRS0YgH+IXtsMp61j+yTcnCE3oO2DgP0U3iejLC8FTtKDC8Q== dependencies: mime "^3.0.0" -"@cloudflare/workerd-darwin-64@1.20240512.0": - version "1.20240512.0" - resolved "https://registry.yarnpkg.com/@cloudflare/workerd-darwin-64/-/workerd-darwin-64-1.20240512.0.tgz#9c72a4d960e1bd69a83d1917b6be54254fc93742" - integrity sha512-VMp+CsSHFALQiBzPdQ5dDI4T1qwLu0mQ0aeKVNDosXjueN0f3zj/lf+mFil5/9jBbG3t4mG0y+6MMnalP9Lobw== +"@cloudflare/workerd-darwin-64@1.20240925.0": + version "1.20240925.0" + resolved "https://registry.yarnpkg.com/@cloudflare/workerd-darwin-64/-/workerd-darwin-64-1.20240925.0.tgz#f78fe394f73540594609d8e05a2da7feb46c76c0" + integrity sha512-KdLnSXuzB65CbqZPm+qYzk+zkQ1tUNPaaRGYVd/jPYAxwwtfTUQdQ+ahDPwVVs2tmQELKy7ZjQjf2apqSWUfjw== -"@cloudflare/workerd-darwin-arm64@1.20240512.0": - version "1.20240512.0" - resolved "https://registry.yarnpkg.com/@cloudflare/workerd-darwin-arm64/-/workerd-darwin-arm64-1.20240512.0.tgz#e7dba44d6eb59b13ccf8c92c089e5c6126b76e6e" - integrity sha512-lZktXGmzMrB5rJqY9+PmnNfv1HKlj/YLZwMjPfF0WVKHUFdvQbAHsi7NlKv6mW9uIvlZnS+K4sIkWc0MDXcRnA== +"@cloudflare/workerd-darwin-arm64@1.20240925.0": + version "1.20240925.0" + resolved "https://registry.yarnpkg.com/@cloudflare/workerd-darwin-arm64/-/workerd-darwin-arm64-1.20240925.0.tgz#f03b17177744ad898bb12610d15cc0a9744abfe6" + integrity sha512-MiQ6uUmCXjsXgWNV+Ock2tp2/tYqNJGzjuaH6jFioeRF+//mz7Tv7J7EczOL4zq+TH8QFOh0/PUsLyazIWVGng== -"@cloudflare/workerd-linux-64@1.20240512.0": - version "1.20240512.0" - resolved "https://registry.yarnpkg.com/@cloudflare/workerd-linux-64/-/workerd-linux-64-1.20240512.0.tgz#fd226eae1d5895820111144c0b09abc0e0bdd434" - integrity sha512-wrHvqCZZqXz6Y3MUTn/9pQNsvaoNjbJpuA6vcXsXu8iCzJi911iVW2WUEBX+MpUWD+mBIP0oXni5tTlhkokOPw== +"@cloudflare/workerd-linux-64@1.20240925.0": + version "1.20240925.0" + resolved "https://registry.yarnpkg.com/@cloudflare/workerd-linux-64/-/workerd-linux-64-1.20240925.0.tgz#fe0366b804b957acf5012d889e94163bab806a57" + integrity sha512-Rjix8jsJMfsInmq3Hm3fmiRQ+rwzuWRPV1pg/OWhMSfNP7Qp2RCU+RGkhgeR9Z5eNAje0Sn2BMrFq4RvF9/yRA== -"@cloudflare/workerd-linux-arm64@1.20240512.0": - version "1.20240512.0" - resolved "https://registry.yarnpkg.com/@cloudflare/workerd-linux-arm64/-/workerd-linux-arm64-1.20240512.0.tgz#64d79e06019e8fb52e82d7898d14eed4cdfdeb6b" - integrity sha512-YPezHMySL9J9tFdzxz390eBswQ//QJNYcZolz9Dgvb3FEfdpK345cE/bsWbMOqw5ws2f82l388epoenghtYvAg== +"@cloudflare/workerd-linux-arm64@1.20240925.0": + version "1.20240925.0" + resolved "https://registry.yarnpkg.com/@cloudflare/workerd-linux-arm64/-/workerd-linux-arm64-1.20240925.0.tgz#fcf82de06def420972c661a6021c87683cd8fbdc" + integrity sha512-VYIPeMHQRtbwQoIjUwS/zULlywPxyDvo46XkTpIW5MScEChfqHvAYviQ7TzYGx6Q+gmZmN+DUB2KOMx+MEpCxA== -"@cloudflare/workerd-windows-64@1.20240512.0": - version "1.20240512.0" - resolved "https://registry.yarnpkg.com/@cloudflare/workerd-windows-64/-/workerd-windows-64-1.20240512.0.tgz#c4cd1673a690b9f7f8fb413a9ff16592cdf847f1" - integrity sha512-SxKapDrIYSscMR7lGIp/av0l6vokjH4xQ9ACxHgXh+OdOus9azppSmjaPyw4/ePvg7yqpkaNjf9o258IxWtvKQ== +"@cloudflare/workerd-windows-64@1.20240925.0": + version "1.20240925.0" + resolved "https://registry.yarnpkg.com/@cloudflare/workerd-windows-64/-/workerd-windows-64-1.20240925.0.tgz#0a5c82b95b03a94591cc8a1830f28d2e41ff7685" + integrity sha512-C8peGvaU5R51bIySi1VbyfRgwNSSRknqoFSnSbSBI3uTN3THTB3UnmRKy7GXJDmyjgXuT9Pcs1IgaWNubLtNtw== + +"@cloudflare/workers-shared@0.5.4": + version "0.5.4" + resolved "https://registry.yarnpkg.com/@cloudflare/workers-shared/-/workers-shared-0.5.4.tgz#bbf8f03b79a6bc0169ad66a6015ebe579d36753a" + integrity sha512-PNL/0TjKRdUHa1kwgVdqUNJVZ9ez4kacsi8omz+gv859EvJmsVuGiMAClY2YfJnC9LVKhKCcjqmFgKNXG9/IXA== + dependencies: + mime "^3.0.0" + zod "^3.22.3" "@commitlint/cli@^18.6.1": version "18.6.1" @@ -3109,6 +3117,11 @@ define-properties@^1.1.3, define-properties@^1.2.0, define-properties@^1.2.1: has-property-descriptors "^1.0.0" object-keys "^1.1.1" +defu@^6.1.4: + version "6.1.4" + resolved "https://registry.yarnpkg.com/defu/-/defu-6.1.4.tgz#4e0c9cf9ff68fe5f3d7f2765cc1a012dfdcb0479" + integrity sha512-mEQCMmwJu317oSz8CwdIOdwf3xMif1ttiM8LTufzc3g6kR+9Pe236twL8j3IYT1F7GfRgGcW6MWxzZjLIkuHIg== + deprecation@^2.0.0: version "2.3.1" resolved "https://registry.yarnpkg.com/deprecation/-/deprecation-2.3.1.tgz#6368cbdb40abf3373b525ac87e4a260c3a700919" @@ -5288,10 +5301,10 @@ min-indent@^1.0.0: resolved "https://registry.yarnpkg.com/min-indent/-/min-indent-1.0.1.tgz#a63f681673b30571fbe8bc25686ae746eefa9869" integrity sha512-I9jwMn07Sy/IwOj3zVkVik2JTvgpaykDZEigL6Rx6N9LbMywwUSMtxET+7lVoDLLd3O3IXwJwvuuns8UB/HeAg== -miniflare@3.20240512.0: - version "3.20240512.0" - resolved "https://registry.yarnpkg.com/miniflare/-/miniflare-3.20240512.0.tgz#2ca99ca04cffead8dcfe002f0d179fae1d649b55" - integrity sha512-X0PlKR0AROKpxFoJNmRtCMIuJxj+ngEcyTOlEokj2rAQ0TBwUhB4/1uiPvdI6ofW5NugPOD1uomAv+gLjwsLDQ== +miniflare@3.20240925.0: + version "3.20240925.0" + resolved "https://registry.yarnpkg.com/miniflare/-/miniflare-3.20240925.0.tgz#a291998dedf90bfb4bcfdad033ba030851ff9171" + integrity sha512-2LmQbKHf0n6ertUKhT+Iltixi53giqDH7P71+wCir3OnGyXIODqYwOECx1mSDNhYThpxM2dav8UdPn6SQiMoXw== dependencies: "@cspotcode/source-map-support" "0.8.1" acorn "^8.8.0" @@ -5300,11 +5313,11 @@ miniflare@3.20240512.0: exit-hook "^2.2.1" glob-to-regexp "^0.4.1" stoppable "^1.1.0" - undici "^5.28.2" - workerd "1.20240512.0" - ws "^8.11.0" + undici "^5.28.4" + workerd "1.20240925.0" + ws "^8.17.1" youch "^3.2.2" - zod "^3.20.6" + zod "^3.22.3" minimatch@9.0.3, minimatch@^9.0.0, minimatch@^9.0.1: version "9.0.3" @@ -5596,6 +5609,11 @@ object.assign@^4.1.5: has-symbols "^1.0.3" object-keys "^1.1.1" +ohash@^1.1.4: + version "1.1.4" + resolved "https://registry.yarnpkg.com/ohash/-/ohash-1.1.4.tgz#ae8d83014ab81157d2c285abf7792e2995fadd72" + integrity sha512-FlDryZAahJmEF3VR3w1KogSEdWX3WhA5GPakFx4J81kEAiHyLMpdLLElS8n8dfNadMgAne/MywcvmogzscVt4g== + once@^1.3.0, once@^1.3.1, once@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1" @@ -5786,6 +5804,11 @@ path-to-regexp@^6.2.0: resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-6.2.1.tgz#d54934d6798eb9e5ef14e7af7962c945906918e5" integrity sha512-JLyh7xT1kizaEvcaXOQwOc2/Yhw6KZOvPf1S8401UyLk86CU79LN3vl7ztXGm/pZ+YjoyAJ4rxmHwbkBXJX+yw== +path-to-regexp@^6.3.0: + version "6.3.0" + resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-6.3.0.tgz#2b6a26a337737a8e1416f9272ed0766b1c0389f4" + integrity sha512-Yhpw4T9C6hPpgPeA28us07OJeqZ5EzQTkbfwuhsUg0c237RomFoETJgmp2sa3F/41gfLE6G5cqcYwznmeEeOlQ== + path-type@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/path-type/-/path-type-3.0.0.tgz#cef31dc8e0a1a3bb0d105c0cd97cf3bf47f4e36f" @@ -5798,6 +5821,11 @@ path-type@^4.0.0: resolved "https://registry.yarnpkg.com/path-type/-/path-type-4.0.0.tgz#84ed01c0a7ba380afe09d90a8c180dcd9d03043b" integrity sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw== +pathe@^1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/pathe/-/pathe-1.1.2.tgz#6c4cb47a945692e48a1ddd6e4094d170516437ec" + integrity sha512-whLdWMYL2TwI08hn8/ZqAbrVemu0LNaNNJZX73O6qaIdCTfXutsLhMkjdENX0qhsQ9uIimo4/aQOmXkoon2nDQ== + picocolors@1.0.0, picocolors@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.0.0.tgz#cb5bdc74ff3f51892236eaf79d68bc44564ab81c" @@ -6347,7 +6375,7 @@ source-map-support@0.5.13: buffer-from "^1.0.0" source-map "^0.6.0" -source-map@0.6.1, source-map@^0.6.0, source-map@^0.6.1: +source-map@^0.6.0, source-map@^0.6.1: version "0.6.1" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263" integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g== @@ -6857,10 +6885,15 @@ typedarray-to-buffer@^3.1.5: dependencies: is-typedarray "^1.0.0" -typescript@^5.3.3: - version "5.3.3" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.3.3.tgz#b3ce6ba258e72e6305ba66f5c9b452aaee3ffe37" - integrity sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw== +typescript@5.6.2: + version "5.6.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.6.2.tgz#d1de67b6bef77c41823f822df8f0b3bcff60a5a0" + integrity sha512-NW8ByodCSNCwZeghjN3o+JX5OFH0Ojg6sadjEKY4huZ52TqbJTJnDo5+Tw98lSy63NZvi4n+ez5m2u5d4PkZyw== + +ufo@^1.5.4: + version "1.5.4" + resolved "https://registry.yarnpkg.com/ufo/-/ufo-1.5.4.tgz#16d6949674ca0c9e0fbbae1fa20a71d7b1ded754" + integrity sha512-UsUk3byDzKd04EyoZ7U4DOlxQaD14JUKQl6/P7wiX4FNvUfm3XL246n9W5AmqwW5RSFJ27NAuM0iLscAOYUiGQ== unbox-primitive@^1.0.2: version "1.0.2" @@ -6877,13 +6910,23 @@ undici-types@~5.26.4: resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617" integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA== -undici@^5.28.2: +undici@^5.28.4: version "5.28.4" resolved "https://registry.yarnpkg.com/undici/-/undici-5.28.4.tgz#6b280408edb6a1a604a9b20340f45b422e373068" integrity sha512-72RFADWFqKmUb2hmmvNODKL3p9hcB6Gt2DOQMis1SEBaV6a4MH8soBvzg+95CYhCKPFedut2JY9bMfrDl9D23g== dependencies: "@fastify/busboy" "^2.0.0" +"unenv@npm:unenv-nightly@2.0.0-20240919-125358-9a64854": + version "2.0.0-20240919-125358-9a64854" + resolved "https://registry.yarnpkg.com/unenv-nightly/-/unenv-nightly-2.0.0-20240919-125358-9a64854.tgz#13f6812c7b12b9521ea05c6d49259d136e093acd" + integrity sha512-XjsgUTrTHR7iw+k/SRTNjh6EQgwpC9voygnoCJo5kh4hKqsSDHUW84MhL9EsHTNfLctvVBHaSw8e2k3R2fKXsQ== + dependencies: + defu "^6.1.4" + ohash "^1.1.4" + pathe "^1.1.2" + ufo "^1.5.4" + unescape-js@^1.0.5: version "1.1.4" resolved "https://registry.yarnpkg.com/unescape-js/-/unescape-js-1.1.4.tgz#4bc6389c499cb055a98364a0b3094e1c3d5da395" @@ -7068,35 +7111,38 @@ which@^4.0.0: dependencies: isexe "^3.1.1" -workerd@1.20240512.0: - version "1.20240512.0" - resolved "https://registry.yarnpkg.com/workerd/-/workerd-1.20240512.0.tgz#235047894d29b755effb18907fc55503930182fc" - integrity sha512-VUBmR1PscAPHEE0OF/G2K7/H1gnr9aDWWZzdkIgWfNKkv8dKFCT75H+GJtUHjfwqz3rYCzaNZmatSXOpLGpF8A== +workerd@1.20240925.0: + version "1.20240925.0" + resolved "https://registry.yarnpkg.com/workerd/-/workerd-1.20240925.0.tgz#0a2602eabfa7e1d01d89ff2b600ed359be9b515d" + integrity sha512-/Jj6+yLwfieZGEt3Kx4+5MoufuC3g/8iFaIh4MPBNGJOGYmdSKXvgCqz09m2+tVCYnysRfbq2zcbVxJRBfOCqQ== optionalDependencies: - "@cloudflare/workerd-darwin-64" "1.20240512.0" - "@cloudflare/workerd-darwin-arm64" "1.20240512.0" - "@cloudflare/workerd-linux-64" "1.20240512.0" - "@cloudflare/workerd-linux-arm64" "1.20240512.0" - "@cloudflare/workerd-windows-64" "1.20240512.0" - -wrangler@3.57.0: - version "3.57.0" - resolved "https://registry.yarnpkg.com/wrangler/-/wrangler-3.57.0.tgz#4c8f30e07a185ecef2c1a467323c084020c3d765" - integrity sha512-izK3AZtlFoTq8N0EZjLOQ7hqwsjaXCc1cbNKuhsLJjDX1jB1YZBDPhIhtXL4VVzkJAcH+0Zw2gguOePFCHNaxw== - dependencies: - "@cloudflare/kv-asset-handler" "0.3.2" + "@cloudflare/workerd-darwin-64" "1.20240925.0" + "@cloudflare/workerd-darwin-arm64" "1.20240925.0" + "@cloudflare/workerd-linux-64" "1.20240925.0" + "@cloudflare/workerd-linux-arm64" "1.20240925.0" + "@cloudflare/workerd-windows-64" "1.20240925.0" + +wrangler@3.79.0: + version "3.79.0" + resolved "https://registry.yarnpkg.com/wrangler/-/wrangler-3.79.0.tgz#c23b08ba06bff752b650a567a7fcbe03e4036914" + integrity sha512-29wzQWc5qNKtD3bSyAEX11j/U5IIk8xy2/ZJ4wljJlS5ppff8qGqI+LtlLmqjqTSeQqFLb87xRkms0YFUgNLXg== + dependencies: + "@cloudflare/kv-asset-handler" "0.3.4" + "@cloudflare/workers-shared" "0.5.4" "@esbuild-plugins/node-globals-polyfill" "^0.2.3" "@esbuild-plugins/node-modules-polyfill" "^0.2.2" blake3-wasm "^2.1.5" chokidar "^3.5.3" esbuild "0.17.19" - miniflare "3.20240512.0" + miniflare "3.20240925.0" nanoid "^3.3.3" - path-to-regexp "^6.2.0" + path-to-regexp "^6.3.0" resolve "^1.22.8" resolve.exports "^2.0.2" selfsigned "^2.0.1" - source-map "0.6.1" + source-map "^0.6.1" + unenv "npm:unenv-nightly@2.0.0-20240919-125358-9a64854" + workerd "1.20240925.0" xxhash-wasm "^1.0.1" optionalDependencies: fsevents "~2.3.2" @@ -7177,11 +7223,16 @@ write-file-atomic@^5.0.0: imurmurhash "^0.1.4" signal-exit "^4.0.1" -ws@^8.11.0, ws@^8.14.2: +ws@^8.14.2: version "8.17.0" resolved "https://registry.yarnpkg.com/ws/-/ws-8.17.0.tgz#d145d18eca2ed25aaf791a183903f7be5e295fea" integrity sha512-uJq6108EgZMAl20KagGkzCKfMEjxmKvZHG7Tlq0Z6nOky7YF7aq4mOx6xK8TJ/i1LeK4Qus7INktacctDgY8Ow== +ws@^8.17.1: + version "8.18.0" + resolved "https://registry.yarnpkg.com/ws/-/ws-8.18.0.tgz#0d7505a6eafe2b0e712d232b42279f53bc289bbc" + integrity sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw== + xdg-basedir@^5.0.1: version "5.1.0" resolved "https://registry.yarnpkg.com/xdg-basedir/-/xdg-basedir-5.1.0.tgz#1efba19425e73be1bc6f2a6ceb52a3d2c884c0c9" @@ -7269,7 +7320,7 @@ zod@3.22.4: resolved "https://registry.yarnpkg.com/zod/-/zod-3.22.4.tgz#f31c3a9386f61b1f228af56faa9255e845cf3fff" integrity sha512-iC+8Io04lddc+mVqQ9AZ7OQ2MrUKGN+oIQyq1vemgt46jwCwLfhq7/pwnBnNXXXZb8VTVLKwp9EDkx+ryxIWmg== -zod@^3.20.6: +zod@^3.22.3: version "3.23.8" resolved "https://registry.yarnpkg.com/zod/-/zod-3.23.8.tgz#e37b957b5d52079769fb8097099b592f0ef4067d" integrity sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g== From fb85f62d1863fabf85ac7ccef1c415be9e804712 Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Fri, 4 Oct 2024 01:52:17 +0900 Subject: [PATCH 5/8] chore: configuration generation --- src/handlers/validator.ts | 6 +++--- src/types/plugin-input.ts | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/handlers/validator.ts b/src/handlers/validator.ts index 5f09e91..45e1f26 100644 --- a/src/handlers/validator.ts +++ b/src/handlers/validator.ts @@ -1,10 +1,10 @@ import { TransformDecodeCheckError, TransformDecodeError, Value, ValueError } from "@sinclair/typebox/value"; import { Env, envConfigValidator, envSchema } from "../types/env"; -import { CommandQuerySettings, commandQueryUserSchema, commandQueryUserSchemaValidator } from "../types/plugin-input"; +import { CommandQuerySettings, pluginSettingsSchema, commandQueryUserSchemaValidator } from "../types/plugin-input"; export function validateAndDecodeSchemas(env: Env, rawSettings: object) { const errors: ValueError[] = []; - const settings = Value.Default(commandQueryUserSchema, rawSettings) as CommandQuerySettings; + const settings = Value.Default(pluginSettingsSchema, rawSettings) as CommandQuerySettings; if (!commandQueryUserSchemaValidator.test(settings)) { for (const error of commandQueryUserSchemaValidator.errors(settings)) { @@ -26,7 +26,7 @@ export function validateAndDecodeSchemas(env: Env, rawSettings: object) { try { const decodedEnv = Value.Decode(envSchema, env); - const decodedSettings = Value.Decode(commandQueryUserSchema, settings); + const decodedSettings = Value.Decode(pluginSettingsSchema, settings); return { decodedEnv, decodedSettings }; } catch (e) { if (e instanceof TransformDecodeCheckError || e instanceof TransformDecodeError) { diff --git a/src/types/plugin-input.ts b/src/types/plugin-input.ts index bcc2821..f8ddde2 100644 --- a/src/types/plugin-input.ts +++ b/src/types/plugin-input.ts @@ -12,13 +12,13 @@ export interface PluginInputs { ref: string; } -export const commandQueryUserSchema = T.Object({ +export const pluginSettingsSchema = T.Object({ /** * Allows any user to query anyone else. If false, only org members can query others. */ allowPublicQuery: T.Boolean({ default: true }), }); -export const commandQueryUserSchemaValidator = new StandardValidator(commandQueryUserSchema); +export const commandQueryUserSchemaValidator = new StandardValidator(pluginSettingsSchema); -export type CommandQuerySettings = StaticDecode; +export type CommandQuerySettings = StaticDecode; From fcd3c6f619fcd8e534a4d34b5559719c77ac93fe Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Fri, 4 Oct 2024 01:55:11 +0900 Subject: [PATCH 6/8] chore: configuration generation --- .github/workflows/update-configuration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update-configuration.yml b/.github/workflows/update-configuration.yml index 2490c49..55038ef 100644 --- a/.github/workflows/update-configuration.yml +++ b/.github/workflows/update-configuration.yml @@ -30,7 +30,7 @@ jobs: const fs = require('fs'); const path = require('path'); - const { pluginSettingsSchema } = require('./src/types'); + const { pluginSettingsSchema } = require('./src/types/plugin-input'); const manifestPath = path.resolve("${{ github.workspace }}", './manifest.json'); const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8')); From f80a6fd510f10d1b84fc633849f44f06cdcb7505 Mon Sep 17 00:00:00 2001 From: "ubiquity-os[bot]" Date: Thu, 3 Oct 2024 16:56:00 +0000 Subject: [PATCH 7/8] chore: updated generated configuration --- manifest.json | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/manifest.json b/manifest.json index cc0a0b1..62bbb8b 100644 --- a/manifest.json +++ b/manifest.json @@ -1,11 +1,25 @@ { "name": "Query user", "description": "Queries a user and retrieves its related information, such as the wallet, the label access control, or the current XP.", - "ubiquity:listeners": [ "issue_comment.created" ], + "ubiquity:listeners": [ + "issue_comment.created" + ], "commands": { "query": { "ubiquity:example": "/query @ubiquibot", "description": "Returns the user's wallet, access, and multiplier information." } + }, + "configuration": { + "type": "object", + "properties": { + "allowPublicQuery": { + "default": true, + "type": "boolean" + } + }, + "required": [ + "allowPublicQuery" + ] } -} +} \ No newline at end of file From c5028d4961e7d815e5dc8ca94f9068ea0b8f4d33 Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Fri, 4 Oct 2024 02:02:27 +0900 Subject: [PATCH 8/8] chore: configuration generation --- src/worker.ts | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/worker.ts b/src/worker.ts index b540de8..392eb3e 100644 --- a/src/worker.ts +++ b/src/worker.ts @@ -7,17 +7,10 @@ export default { async fetch(request: Request, env: Env): Promise { try { const url = new URL(request.url); - if (url.pathname === "/manifest") { - if (request.method === "GET") { - return new Response(JSON.stringify(manifest), { - headers: { "content-type": "application/json" }, - }); - } else if (request.method === "POST") { - const webhookPayload = await request.json(); - - validateAndDecodeSchemas(env, webhookPayload.settings); - return new Response(JSON.stringify({ message: "Schema is valid" }), { status: 200, headers: { "content-type": "application/json" } }); - } + if (url.pathname === "/manifest" && request.method === "GET") { + return new Response(JSON.stringify(manifest), { + headers: { "content-type": "application/json" }, + }); } if (request.method !== "POST") { return new Response(JSON.stringify({ error: `Only POST requests are supported.` }), {