From 11afc08f658713f9dbb5cd49b508dcdc1ea9c6d4 Mon Sep 17 00:00:00 2001 From: Dmitry S Date: Fri, 26 Jan 2024 23:21:34 -0500 Subject: [PATCH] (core) Improve API Console and link from Document Settings. Summary: Changes to building and serving: - Remove unpkg dependencies, add npm module for swagger-ui-dist instead. - Move apiconsole JS logic into core/app/client/apiconsole.ts, and use TypeScript. - Add symlinks to swagger in static/ and core/static/. - Refactor loadScript, and add loadCssFile; use these to load swagger-ui resources. Changes to console itself: - Support docId, workspaceId, orgId URL parameters. When present, the matching value in dropdowns is moved to the front and marked as "(Current)". - Fix the ordering of example values, particularly for workspaces. - Remove unwanted example values. - Hide confusing "Authorize" button. - Hide API keys, and rely consistently on cookies for executing API calls. Integration into Grist: - Added a button to Document Settings, just under document ID in "API". - The button opens a separate page, passing in org, workspace, and doc info for the current doc. Test Plan: Only tested manually, no automated tests yet. Reviewers: jarek Reviewed By: jarek Differential Revision: https://phab.getgrist.com/D4173 --- app/client/apiconsole.ts | 323 ++++++++++++++++++++++++++ app/client/app.js | 15 +- app/client/exposeModulesForTests.js | 2 +- app/client/lib/loadScript.js | 19 -- app/client/lib/loadScript.ts | 23 ++ app/client/ui/DocumentSettings.ts | 15 ++ app/client/ui/Tools.ts | 11 - app/common/UserAPI.ts | 8 +- app/server/lib/ActiveDoc.ts | 8 +- app/server/lib/DocApi.ts | 4 +- app/server/lib/TableMetadataLoader.ts | 8 +- buildtools/webpack.config.js | 1 + package.json | 2 + static/apiconsole.html | 224 +----------------- static/swagger-ui-bundle.js | 1 + static/swagger-ui.css | 1 + yarn.lock | 10 + 17 files changed, 409 insertions(+), 266 deletions(-) create mode 100644 app/client/apiconsole.ts delete mode 100644 app/client/lib/loadScript.js create mode 100644 app/client/lib/loadScript.ts create mode 120000 static/swagger-ui-bundle.js create mode 120000 static/swagger-ui.css diff --git a/app/client/apiconsole.ts b/app/client/apiconsole.ts new file mode 100644 index 00000000..50cfbb4d --- /dev/null +++ b/app/client/apiconsole.ts @@ -0,0 +1,323 @@ +import {loadCssFile, loadScript} from 'app/client/lib/loadScript'; +import type {AppModel} from 'app/client/models/AppModel'; +import {urlState} from 'app/client/models/gristUrlState'; +import {reportError} from 'app/client/models/errors'; +import {setUpPage} from 'app/client/ui/setUpPage'; +import {DocAPIImpl} from 'app/common/UserAPI'; +import type {RecordWithStringId} from 'app/plugin/DocApiTypes'; +import {dom, styled} from 'grainjs'; +import type SwaggerUI from 'swagger-ui'; + +/** + * This loads the swagger resources as if included as separate - + + diff --git a/static/swagger-ui-bundle.js b/static/swagger-ui-bundle.js new file mode 120000 index 00000000..21d1190f --- /dev/null +++ b/static/swagger-ui-bundle.js @@ -0,0 +1 @@ +../node_modules/swagger-ui-dist/swagger-ui-bundle.js \ No newline at end of file diff --git a/static/swagger-ui.css b/static/swagger-ui.css new file mode 120000 index 00000000..8ccaab51 --- /dev/null +++ b/static/swagger-ui.css @@ -0,0 +1 @@ +../node_modules/swagger-ui-dist/swagger-ui.css \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 06375a60..3e1b04a3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -944,6 +944,11 @@ dependencies: "@types/node" "*" +"@types/swagger-ui@3.52.4": + version "3.52.4" + resolved "https://registry.yarnpkg.com/@types/swagger-ui/-/swagger-ui-3.52.4.tgz#96c4886e8f86ae392f8d940bf7029cf490a51c72" + integrity sha512-7NV7q8BfupqdQxr26OkM0g0YEPB9uXnKGzXadgcearvI9MoCHt3F72lPTX3fZZIlrr21DC0IK26wcDMZ37oFDA== + "@types/tmp@0.0.33": version "0.0.33" resolved "https://registry.npmjs.org/@types/tmp/-/tmp-0.0.33.tgz" @@ -7435,6 +7440,11 @@ supports-preserve-symlinks-flag@^1.0.0: resolved "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz" integrity sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w== +swagger-ui-dist@5.11.0: + version "5.11.0" + resolved "https://registry.yarnpkg.com/swagger-ui-dist/-/swagger-ui-dist-5.11.0.tgz#9bcfd75278b1fa9c36fe52f206f8fc611470547c" + integrity sha512-j0PIATqQSEFGOLmiJOJZj1X1Jt6bFIur3JpY7+ghliUnfZs0fpWDdHEkn9q7QUlBtKbkn6TepvSxTqnE8l3s0A== + symbol-tree@^3.2.4: version "3.2.4" resolved "https://registry.npmjs.org/symbol-tree/-/symbol-tree-3.2.4.tgz"