From 148e316d2f82ff0ab23b943696ff4fa19b0177af Mon Sep 17 00:00:00 2001 From: tomholford Date: Fri, 19 May 2023 13:07:20 -0700 Subject: [PATCH] meta: deprecate @urbit/api See: #176 This is a tangential task to an ongoing effort to implement Userspace Permissions UI (#182) As a prerequisite for UP: the npm SDK which frontend developers use for integrating with Landscape APIs needs to be updated with interfaces for the new pokes and scries. Previously, this would be `@urbit/api`. However, per this PR the package is now deprecated: https://github.com/tloncorp/landscape/issues/176 Tlon has long had plans to release a successor to Indigo 1. The vision at this point is to create a new `@tloncorp/gear` package which will provide types for integrating with Landscape, as well as a component library and useful hooks for querying and managing state. So why this PR: Since the new package will not have the Webterm types and utility functions, I'm migrating them from the deprecated package to this repo. --- ui/App.tsx | 5 +- ui/Buffer.tsx | 5 +- ui/Tab.tsx | 4 +- ui/index.jsx | 2 +- ui/lib/blit.ts | 2 +- ui/lib/stye.ts | 2 +- ui/lib/types.ts | 61 +++++++++++++++++++ ui/lib/useAddSession.ts | 2 +- ui/lib/utils.ts | 19 ++++++ ui/package-lock.json | 131 ++++++++++++++-------------------------- ui/package.json | 5 +- ui/state.ts | 2 +- 12 files changed, 138 insertions(+), 102 deletions(-) create mode 100644 ui/lib/types.ts create mode 100644 ui/lib/utils.ts diff --git a/ui/App.tsx b/ui/App.tsx index fec315d..32ff77e 100644 --- a/ui/App.tsx +++ b/ui/App.tsx @@ -10,16 +10,13 @@ import { _dark, _light } from '@tlon/indigo-react'; import 'xterm/css/xterm.css'; -import { - scrySessions -} from '@urbit/api'; - import { ThemeProvider } from 'styled-components'; import { Tabs } from './Tabs'; import Buffer from './Buffer'; import { DEFAULT_SESSION } from './constants'; import { showSlog } from './lib/blit'; import { InfoButton } from './InfoButton'; +import { scrySessions } from './lib/utils'; const initSessions = async () => { const response = await api.scry(scrySessions()); diff --git a/ui/Buffer.tsx b/ui/Buffer.tsx index a10beca..65c368e 100644 --- a/ui/Buffer.tsx +++ b/ui/Buffer.tsx @@ -5,8 +5,8 @@ import bel from './lib/bel'; import api from './api'; import { - Belt, pokeTask, pokeBelt -} from '@urbit/api'; + pokeTask, pokeBelt +} from './lib/utils' import { Session } from './state'; import { useCallback, useEffect, useRef } from 'react'; import useTermState from './state'; @@ -16,6 +16,7 @@ import { makeTheme } from './lib/theme'; import { showBlit, csi, hasBell } from './lib/blit'; import { DEFAULT_SESSION, RESIZE_DEBOUNCE_MS, RESIZE_THRESHOLD_PX } from './constants'; import { retry } from './lib/retry'; +import { Belt } from 'lib/types'; const termConfig: ITerminalOptions = { logLevel: 'warn', diff --git a/ui/Tab.tsx b/ui/Tab.tsx index 513c4d4..5fa06fb 100644 --- a/ui/Tab.tsx +++ b/ui/Tab.tsx @@ -1,8 +1,8 @@ import { DEFAULT_SESSION } from './constants'; -import React, { useCallback, useEffect } from 'react'; +import React, { useCallback } from 'react'; import useTermState, { Session } from './state'; import api from './api'; -import { pokeTask } from '@urbit/api'; +import { pokeTask } from './lib/utils'; import { DelayedSpinner as Spinner } from './Spinner'; interface TabProps { diff --git a/ui/index.jsx b/ui/index.jsx index 3e66b97..55bc45e 100644 --- a/ui/index.jsx +++ b/ui/index.jsx @@ -1,7 +1,7 @@ import * as React from 'react'; import * as ReactDOM from 'react-dom'; import TermApp from './App'; -import { preSig } from '@urbit/api'; +import { preSig } from '@urbit/aura'; import cookies from 'browser-cookies'; function authRedirect() { diff --git a/ui/lib/blit.ts b/ui/lib/blit.ts index 289ed18..4a57dda 100644 --- a/ui/lib/blit.ts +++ b/ui/lib/blit.ts @@ -1,6 +1,6 @@ import { Terminal } from 'xterm'; import { saveAs } from 'file-saver'; -import { Blit, Stub, Stye } from '@urbit/api'; +import { Blit, Stub, Stye } from '../lib/types'; import { stye } from '../lib/stye'; export const csi = (cmd: string, ...args: number[]) => { diff --git a/ui/lib/stye.ts b/ui/lib/stye.ts index 599abb7..05c27ae 100644 --- a/ui/lib/stye.ts +++ b/ui/lib/stye.ts @@ -1,4 +1,4 @@ -import { Deco, Stye, Tint } from '@urbit/api'; +import { Deco, Stye, Tint } from './types'; const tint = (t: Tint) => { switch (t) { diff --git a/ui/lib/types.ts b/ui/lib/types.ts new file mode 100644 index 0000000..2f352a7 --- /dev/null +++ b/ui/lib/types.ts @@ -0,0 +1,61 @@ +// outputs +// + +export type TermUpdate = + | Blit; + +export type Tint = + | null + | 'r' | 'g' | 'b' | 'c' | 'm' | 'y' | 'k' | 'w' + | { r: number, g: number, b: number }; + +export type Deco = null | 'br' | 'un' | 'bl'; + +export type Stye = { + deco: Deco[], + back: Tint, + fore: Tint +}; + +export type Stub = { + stye: Stye, + text: string[] +} + +export type Blit = + | { bel: null } // make a noise + | { clr: null } // clear the screen + | { hop: number | { x: number, y: number } } // set cursor col/pos + | { klr: Stub[] } // put styled + | { mor: Blit[] } // multiple blits + | { nel: null } // newline + | { put: string[] } // put text at cursor + | { sag: { path: string, file: string } } // save to jamfile + | { sav: { path: string, file: string } } // save to file + | { url: string } // activate url + | { wyp: null } // wipe cursor line + +// inputs +// + +export type Bolt = + | string + | { aro: 'd' | 'l' | 'r' | 'u' } + | { bac: null } + | { del: null } + | { hit: { x: number, y: number } } + | { ret: null } + +export type Belt = + | Bolt + | { mod: { mod: 'ctl' | 'met' | 'hyp', key: Bolt } } + | { txt: Array } + +export type Task = + | { belt: Belt } + | { blew: { w: number, h: number } } + | { hail: null } + | { open: { term: string, apps: Array<{ who: string, app: string }> } } + | { shut: null } + +export type SessionTask = { session: string } & Task diff --git a/ui/lib/useAddSession.ts b/ui/lib/useAddSession.ts index 8a6e2c9..1e0f141 100644 --- a/ui/lib/useAddSession.ts +++ b/ui/lib/useAddSession.ts @@ -5,7 +5,7 @@ import { } from '../constants'; import useTermState from '../state'; import api from '../api'; -import { pokeTask } from '@urbit/api'; +import { pokeTask } from './utils'; import { useCallback } from 'react'; export const useAddSession = () => { diff --git a/ui/lib/utils.ts b/ui/lib/utils.ts new file mode 100644 index 0000000..28170d4 --- /dev/null +++ b/ui/lib/utils.ts @@ -0,0 +1,19 @@ +import { Poke, Scry } from '@urbit/http-api'; +import { Belt, Task, SessionTask } from './types'; + +export const pokeTask = (session: string, task: Task): Poke => ({ + app: 'herm', + mark: 'herm-task', + json: { session, ...task } +}); + +export const pokeBelt = ( + session: string, + belt: Belt +): Poke => pokeTask(session, { belt }); + +//NOTE scry will return string[] +export const scrySessions = (): Scry => ({ + app: 'herm', + path: `/sessions` +}); diff --git a/ui/package-lock.json b/ui/package-lock.json index 4870a3a..08ede24 100644 --- a/ui/package-lock.json +++ b/ui/package-lock.json @@ -12,11 +12,12 @@ "@babel/runtime": "^7.16.0", "@reach/menu-button": "^0.10.5", "@tlon/indigo-react": "^1.2.23", - "@urbit/api": "^2.3.0", - "@urbit/http-api": "^2.2.0", + "@urbit/aura": "^1.0.0", + "@urbit/http-api": "^2.3.0", "browser-cookies": "^1.2.0", "css-loader": "^3.6.0", "file-saver": "^2.0.5", + "immer": "^10.0.2", "lodash": "^4.17.21", "react": "^16.14.0", "react-dom": "^16.14.0", @@ -3584,16 +3585,16 @@ "url": "https://opencollective.com/typescript-eslint" } }, - "node_modules/@urbit/api": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/@urbit/api/-/api-2.3.0.tgz", - "integrity": "sha512-uC0GyerFy6WaFHkgauvuJ55in2AUAJgCv/bHPOiwOKbdJQF4QgMaECn5gu/7n3d1/RGdNPaKw28nh0GCZ0AQKA==", - "dependencies": { - "@babel/runtime": "^7.16.0", - "big-integer": "^1.6.48", - "core-js": "^3.19.1", - "immer": "^9.0.1", - "urbit-ob": "^5.0.1" + "node_modules/@urbit/aura": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@urbit/aura/-/aura-1.0.0.tgz", + "integrity": "sha512-IeP3uoDzZ0Rpn345auXK0y/BCcXTmpgAlOPbgf7n4eD35h56OnSoit1kuXKA21sWE19gFjK/wqZcz5ULjz2ADg==", + "engines": { + "node": ">=16", + "npm": ">=8" + }, + "peerDependencies": { + "big-integer": "^1.6.51" } }, "node_modules/@urbit/eslint-config": { @@ -3603,9 +3604,9 @@ "dev": true }, "node_modules/@urbit/http-api": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/@urbit/http-api/-/http-api-2.2.0.tgz", - "integrity": "sha512-8mSWXyz6PmCR+u8YunzoW4GPDmgG7r1uVIOIJuxSXPwT5bfXu3uq6UZ2Brju4atIm6Ef7kW0H1WdNo7fLwvM3g==", + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/@urbit/http-api/-/http-api-2.3.0.tgz", + "integrity": "sha512-3cKSdbBVcpoHqZLvoV23UK+nkqK0nFEBFKbaEwfBQE/NpkWf/7iP+mT7ldXTk7Uv/5bzDEBPqPB2fJNwdMQwcA==", "dependencies": { "@babel/runtime": "^7.12.5", "@microsoft/fetch-event-source": "^2.0.0", @@ -4652,9 +4653,10 @@ "dev": true }, "node_modules/big-integer": { - "version": "1.6.48", - "resolved": "https://registry.npmjs.org/big-integer/-/big-integer-1.6.48.tgz", - "integrity": "sha512-j51egjPa7/i+RdiRuJbPdJ2FIUYYPhvYLjzoYbcMMm62ooO6F94fETG4MTs46zPAF9Brs04OajboA/qTGuz78w==", + "version": "1.6.51", + "resolved": "https://registry.npmjs.org/big-integer/-/big-integer-1.6.51.tgz", + "integrity": "sha512-GPEid2Y9QU1Exl1rpO9B2IPJGHPSupF5GnVIP0blYvNOMer2bTvSWs1jGOUg04hTmu67nmLsQ9TBo1puaotBHg==", + "peer": true, "engines": { "node": ">=0.6" } @@ -5670,9 +5672,9 @@ } }, "node_modules/core-js": { - "version": "3.28.0", - "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.28.0.tgz", - "integrity": "sha512-GiZn9D4Z/rSYvTeg1ljAIsEqFm0LaN9gVtwDCrKL80zHtS31p9BAjmTxVqTQDMpwlMolJZOFntUG2uwyj7DAqw==", + "version": "3.30.2", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.30.2.tgz", + "integrity": "sha512-uBJiDmwqsbJCWHAwjrx3cvjbMXP7xD72Dmsn5LOJpiRmE3WbBbN5rCqQ2Qh6Ek6/eOrjlWngEynBWo4VxerQhg==", "hasInstallScript": true, "funding": { "type": "opencollective", @@ -9761,9 +9763,9 @@ } }, "node_modules/immer": { - "version": "9.0.6", - "resolved": "https://registry.npmjs.org/immer/-/immer-9.0.6.tgz", - "integrity": "sha512-G95ivKpy+EvVAnAab4fVa4YGYn24J1SpEktnJX7JJ45Bd7xqME/SCplFzYFmTbrkwZbQ4xJK1xMTUYBkN6pWsQ==", + "version": "10.0.2", + "resolved": "https://registry.npmjs.org/immer/-/immer-10.0.2.tgz", + "integrity": "sha512-Rx3CqeqQ19sxUtYV9CU911Vhy8/721wRFnJv3REVGWUmoAcIwzifTsdmJte/MV+0/XpM35LZdQMBGkRIoLPwQA==", "funding": { "type": "opencollective", "url": "https://opencollective.com/immer" @@ -13234,11 +13236,6 @@ "integrity": "sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==", "peer": true }, - "node_modules/lodash.chunk": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/lodash.chunk/-/lodash.chunk-4.2.0.tgz", - "integrity": "sha1-ZuXOH3btJ7QwPYxlEujRIW6BBrw=" - }, "node_modules/lodash.clonedeep": { "version": "4.5.0", "resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz", @@ -13257,11 +13254,6 @@ "integrity": "sha512-dS2j+W26TQ7taQBGN8Lbbq04ssV3emRw4NY58WErlTO29pIqS0HmoT5aJ9+TUQ1N3G+JOZSji4eugsWwGp9yPA==", "dev": true }, - "node_modules/lodash.isequal": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz", - "integrity": "sha1-QVxEePK8wwEgwizhDtMib30+GOA=" - }, "node_modules/lodash.merge": { "version": "4.6.2", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", @@ -17738,16 +17730,6 @@ "integrity": "sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==", "dev": true }, - "node_modules/urbit-ob": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/urbit-ob/-/urbit-ob-5.0.1.tgz", - "integrity": "sha512-qGNAwu87XNkW3g8ah4fUwmh2EKXtsdhEbyEiE5qX4Op17rhLH3HSkvu8g9z+MhqX51Uz9sf8ktvqJj/IRwETIQ==", - "dependencies": { - "bn.js": "^4.11.8", - "lodash.chunk": "^4.2.0", - "lodash.isequal": "^4.5.0" - } - }, "node_modules/uri-js": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", @@ -22430,17 +22412,11 @@ "eslint-visitor-keys": "^2.0.0" } }, - "@urbit/api": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/@urbit/api/-/api-2.3.0.tgz", - "integrity": "sha512-uC0GyerFy6WaFHkgauvuJ55in2AUAJgCv/bHPOiwOKbdJQF4QgMaECn5gu/7n3d1/RGdNPaKw28nh0GCZ0AQKA==", - "requires": { - "@babel/runtime": "^7.16.0", - "big-integer": "^1.6.48", - "core-js": "^3.19.1", - "immer": "^9.0.1", - "urbit-ob": "^5.0.1" - } + "@urbit/aura": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@urbit/aura/-/aura-1.0.0.tgz", + "integrity": "sha512-IeP3uoDzZ0Rpn345auXK0y/BCcXTmpgAlOPbgf7n4eD35h56OnSoit1kuXKA21sWE19gFjK/wqZcz5ULjz2ADg==", + "requires": {} }, "@urbit/eslint-config": { "version": "1.0.3", @@ -22449,9 +22425,9 @@ "dev": true }, "@urbit/http-api": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/@urbit/http-api/-/http-api-2.2.0.tgz", - "integrity": "sha512-8mSWXyz6PmCR+u8YunzoW4GPDmgG7r1uVIOIJuxSXPwT5bfXu3uq6UZ2Brju4atIm6Ef7kW0H1WdNo7fLwvM3g==", + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/@urbit/http-api/-/http-api-2.3.0.tgz", + "integrity": "sha512-3cKSdbBVcpoHqZLvoV23UK+nkqK0nFEBFKbaEwfBQE/NpkWf/7iP+mT7ldXTk7Uv/5bzDEBPqPB2fJNwdMQwcA==", "requires": { "@babel/runtime": "^7.12.5", "@microsoft/fetch-event-source": "^2.0.0", @@ -23290,9 +23266,10 @@ "dev": true }, "big-integer": { - "version": "1.6.48", - "resolved": "https://registry.npmjs.org/big-integer/-/big-integer-1.6.48.tgz", - "integrity": "sha512-j51egjPa7/i+RdiRuJbPdJ2FIUYYPhvYLjzoYbcMMm62ooO6F94fETG4MTs46zPAF9Brs04OajboA/qTGuz78w==" + "version": "1.6.51", + "resolved": "https://registry.npmjs.org/big-integer/-/big-integer-1.6.51.tgz", + "integrity": "sha512-GPEid2Y9QU1Exl1rpO9B2IPJGHPSupF5GnVIP0blYvNOMer2bTvSWs1jGOUg04hTmu67nmLsQ9TBo1puaotBHg==", + "peer": true }, "big.js": { "version": "5.2.2", @@ -24163,9 +24140,9 @@ "integrity": "sha1-Z29us8OZl8LuGsOpJP1hJHSPV40=" }, "core-js": { - "version": "3.28.0", - "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.28.0.tgz", - "integrity": "sha512-GiZn9D4Z/rSYvTeg1ljAIsEqFm0LaN9gVtwDCrKL80zHtS31p9BAjmTxVqTQDMpwlMolJZOFntUG2uwyj7DAqw==" + "version": "3.30.2", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.30.2.tgz", + "integrity": "sha512-uBJiDmwqsbJCWHAwjrx3cvjbMXP7xD72Dmsn5LOJpiRmE3WbBbN5rCqQ2Qh6Ek6/eOrjlWngEynBWo4VxerQhg==" }, "core-js-compat": { "version": "3.17.3", @@ -27298,9 +27275,9 @@ "dev": true }, "immer": { - "version": "9.0.6", - "resolved": "https://registry.npmjs.org/immer/-/immer-9.0.6.tgz", - "integrity": "sha512-G95ivKpy+EvVAnAab4fVa4YGYn24J1SpEktnJX7JJ45Bd7xqME/SCplFzYFmTbrkwZbQ4xJK1xMTUYBkN6pWsQ==" + "version": "10.0.2", + "resolved": "https://registry.npmjs.org/immer/-/immer-10.0.2.tgz", + "integrity": "sha512-Rx3CqeqQ19sxUtYV9CU911Vhy8/721wRFnJv3REVGWUmoAcIwzifTsdmJte/MV+0/XpM35LZdQMBGkRIoLPwQA==" }, "immutable": { "version": "4.2.4", @@ -29857,11 +29834,6 @@ "integrity": "sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==", "peer": true }, - "lodash.chunk": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/lodash.chunk/-/lodash.chunk-4.2.0.tgz", - "integrity": "sha1-ZuXOH3btJ7QwPYxlEujRIW6BBrw=" - }, "lodash.clonedeep": { "version": "4.5.0", "resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz", @@ -29880,11 +29852,6 @@ "integrity": "sha512-dS2j+W26TQ7taQBGN8Lbbq04ssV3emRw4NY58WErlTO29pIqS0HmoT5aJ9+TUQ1N3G+JOZSji4eugsWwGp9yPA==", "dev": true }, - "lodash.isequal": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz", - "integrity": "sha1-QVxEePK8wwEgwizhDtMib30+GOA=" - }, "lodash.merge": { "version": "4.6.2", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", @@ -33441,16 +33408,6 @@ } } }, - "urbit-ob": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/urbit-ob/-/urbit-ob-5.0.1.tgz", - "integrity": "sha512-qGNAwu87XNkW3g8ah4fUwmh2EKXtsdhEbyEiE5qX4Op17rhLH3HSkvu8g9z+MhqX51Uz9sf8ktvqJj/IRwETIQ==", - "requires": { - "bn.js": "^4.11.8", - "lodash.chunk": "^4.2.0", - "lodash.isequal": "^4.5.0" - } - }, "uri-js": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", diff --git a/ui/package.json b/ui/package.json index 8388007..729e3e6 100644 --- a/ui/package.json +++ b/ui/package.json @@ -9,11 +9,12 @@ "@babel/runtime": "^7.16.0", "@reach/menu-button": "^0.10.5", "@tlon/indigo-react": "^1.2.23", - "@urbit/api": "^2.3.0", - "@urbit/http-api": "^2.2.0", + "@urbit/aura": "^1.0.0", + "@urbit/http-api": "^2.3.0", "browser-cookies": "^1.2.0", "css-loader": "^3.6.0", "file-saver": "^2.0.5", + "immer": "^10.0.2", "lodash": "^4.17.21", "react": "^16.14.0", "react-dom": "^16.14.0", diff --git a/ui/state.ts b/ui/state.ts index d61d798..fa22e58 100644 --- a/ui/state.ts +++ b/ui/state.ts @@ -1,7 +1,7 @@ +import { produce } from 'immer'; import { Terminal } from 'xterm'; import { FitAddon } from 'xterm-addon-fit'; import create from 'zustand'; -import produce from 'immer'; export type Session = { term: Terminal,