@kottera/tera-web 0.0.0-stage → 0.1.0-rc.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/NOTICE +28 -0
- package/README.md +56 -2
- package/dist/client.d.ts +223 -0
- package/dist/client.js +500 -0
- package/dist/feed/connection.d.ts +179 -0
- package/dist/feed/connection.js +457 -0
- package/dist/feed/sse.d.ts +51 -0
- package/dist/feed/sse.js +134 -0
- package/dist/generated/feed.d.ts +199 -0
- package/dist/generated/feed.js +16 -0
- package/dist/generated/kit.d.ts +374 -0
- package/dist/generated/kit.js +258 -0
- package/dist/generated/shares.d.ts +214 -0
- package/dist/generated/shares.js +17 -0
- package/dist/generated/workorder-events.d.ts +47 -0
- package/dist/generated/workorder-events.js +10 -0
- package/dist/generated/workorder.d.ts +3775 -0
- package/dist/generated/workorder.js +74 -0
- package/dist/generated/wsstream.d.ts +34 -0
- package/dist/generated/wsstream.js +28 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +24 -0
- package/dist/phone.d.ts +11 -0
- package/dist/phone.js +24 -0
- package/dist/routes.d.ts +32 -0
- package/dist/routes.js +69 -0
- package/dist/signin.d.ts +48 -0
- package/dist/signin.js +74 -0
- package/dist/stepup.d.ts +87 -0
- package/dist/stepup.js +66 -0
- package/dist/stream/connection.d.ts +145 -0
- package/dist/stream/connection.js +377 -0
- package/dist/terminal/view.d.ts +168 -0
- package/dist/terminal/view.js +546 -0
- package/dist/terminalwire/codec.d.ts +182 -0
- package/dist/terminalwire/codec.js +556 -0
- package/dist/terminalwire/collapse.d.ts +4 -0
- package/dist/terminalwire/collapse.js +7 -0
- package/dist/unreached.d.ts +26 -0
- package/dist/unreached.js +30 -0
- package/package.json +32 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Kottera
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Kottera SDK
|
|
2
|
+
Copyright 2026 Kottera
|
|
3
|
+
|
|
4
|
+
This product includes software developed by Kottera.
|
|
5
|
+
|
|
6
|
+
The Kottera SDK (github.com/kottera/sdk) is the public, stable surface of the
|
|
7
|
+
Kottera platform: the capability contract and schema, the tool SDK, the connector
|
|
8
|
+
SDK contract and the standalone connector-authoring SDK, credential specifications
|
|
9
|
+
and keychain resolution, the KPP provider-protocol handshake and its env/conn
|
|
10
|
+
dialect frame schemas, and the sandbox/telemetry OTLP-JSON frame schemas
|
|
11
|
+
(ADR-059 Part 1, surfaces 1-4). It is licensed under the Apache License, Version
|
|
12
|
+
2.0; see the LICENSE file in this directory.
|
|
13
|
+
|
|
14
|
+
This SDK module MUST NOT import any github.com/kottera/kottera/... package. The
|
|
15
|
+
Kottera daemon (`tera`) is a separate, private-source work and is NOT licensed
|
|
16
|
+
under this Apache License; it is distributed as a free-to-use binary governed by
|
|
17
|
+
the Kottera End User License Agreement that accompanies each release.
|
|
18
|
+
|
|
19
|
+
----------------------------------------------------------------------------------
|
|
20
|
+
Third-party components
|
|
21
|
+
----------------------------------------------------------------------------------
|
|
22
|
+
|
|
23
|
+
This module depends on third-party Go packages resolved via go.mod / go.sum. Their
|
|
24
|
+
copyrights and licenses are held by their respective authors and are reproduced in
|
|
25
|
+
the third-party license inventory bundled with each release (the `licenses/`
|
|
26
|
+
directory produced by the release SBOM tooling). No third-party dependency of this
|
|
27
|
+
module is licensed under a copyleft license (GPL/LGPL/AGPL); all are permissive
|
|
28
|
+
(Apache-2.0, MIT, BSD-2-Clause, or BSD-3-Clause).
|
package/README.md
CHANGED
|
@@ -1,3 +1,57 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @kottera/tera-web
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The browser half of a UI over tera ([ADR-162](../../docs/adr/ADR-162-a-ui-over-tera.md)
|
|
4
|
+
D4): a framework-free TypeScript client for the `/tera/v1/` routes a plugin's
|
|
5
|
+
webui kit serves (D3). It carries no UI component — the framework is the
|
|
6
|
+
author's — and has no runtime dependencies. It is not yet published.
|
|
7
|
+
|
|
8
|
+
## Layout
|
|
9
|
+
|
|
10
|
+
| Path | What it holds |
|
|
11
|
+
|------|---------------|
|
|
12
|
+
| `src/index.ts` | The package's one entry point. Everything public is re-exported here. |
|
|
13
|
+
| `src/routes.ts` | The route prefix, `routePath`, and the app's base (`appBase`, `underBase`) every route and the sign-out are reached under. |
|
|
14
|
+
| `src/client.ts` | `TeraClient`, the typed client over D3's routes (D4 items 1, 3 and 4): `me()`, `invoke(capability, params)`, `feed(options)` (a `FeedConnection` read with the client's fetch), `stream(options)` (a `StreamConnection` probed with the client's fetch), `terminal(options)` (a `TerminalView` opened the same way), `upload(file, options)` with progress, and `signOut()`. A kit refusal throws `KitRequestError`; a verb's refusal answers as its verdict. |
|
|
15
|
+
| `src/phone.ts` | `phoneURL(me, location, base?)`, the "Open on your phone" link (ADR-177 D4): `me().phone_path` resolved against the app's base (`/` by default, `/plugins/<name>/` on a path-based installation), with `next` set to `location.href`, fragment included. tera's proxy sends it on to tera's phone page, which draws the page's URL as a QR code, so the page needs no knowledge of tera's URL. A `phone_path` that is not relative to the base throws. |
|
|
16
|
+
| `src/signin.ts` | Signing in again after tera forgets the page's session, as a daemon restart does: `isSignInRequired(response)` recognises the UI proxy's 401 `sign_in_required`, and `reSignIn()` loads the page again, which signs the person in with no prompt while their tera session lives. `TeraClient`, `FeedConnection` and `StreamConnection` do it on their own, once; a page reading its own routes with its own `fetch` applies `isSignInRequired`. |
|
|
17
|
+
| `src/unreached.ts` | The codes tera's UI proxy answers the page's script with in the kit's envelope when the plugin did not answer: `PLUGIN_BUSY` and `PLUGIN_STARTING` (503, with `Retry-After`), `PLUGIN_RUNNER_UNREACHABLE` and `PLUGIN_NOT_ANSWERING` (502), all retryable, listed as `PLUGIN_UNREACHED_CODES`. |
|
|
18
|
+
| `src/stepup.ts` | A person's step-up from the page's side (ADR-173 D11): the step-up header, the `return_to` the navigation fallback carries, and `StepUpError`. Every `TeraClient` request — `me()`, `invoke()`, `upload()` and `fetch(path)` to the plugin's own routes — has the person confirm a `step_up_required` and sends the request once more; `stepUp(id)` reads `GET /tera/v1/step-ups/{id}`. |
|
|
19
|
+
| `src/generated/` | The contract, generated from the committed schemas under `sdk/plugin/webui/schema/`, `sdk/workorder/schema/`, `sdk/feed/schema/`, `sdk/shares/schema/` and `sdk/wsstream/schema/` (D4 item 1; the share types, ADR-174 D14; the close codes, ADR-181 D15): one type per schema, the kit's route table as `KIT_ROUTE_TABLE`, a closed set of named constants as a map by name (`STREAM_CLOSE_CODES`), and the maps from a route or a feed event to the type it carries. Never hand-edited, and never hand-write a type it declares: `make web-types` regenerates it, and `TestWebTypes_MatchCommitted` (`cmd/internal/genwebtypes`) fails on a hand edit or a stale generation. |
|
|
20
|
+
| `src/feed/` | The feed connection (D4 item 2). Its `backfill` option is `all` by default, the run's stored history first, which the daemon serves only to a connection narrowed to one run; a work-order-events feed, or any feed not narrowed to one Work Order, is opened with `backfill: "none"`, or it is refused `backfill_scope_too_broad`. |
|
|
21
|
+
| `src/stream/` | `StreamConnection`, one WebSocket to a kit stream route (ADR-181 D9, D11 item 1), reopened by the close code the far side chose: after backoff on `going_away`, `retry_later` and any code it does not know, at once on `reconnect` (three in 30 seconds, then backoff), never on `refused` or `too_big`, and on a normal closure as the protocol above said with `onNormalClose`. A failed handshake is settled by one probe of `GET /tera/v1/me`; more than 1 MiB unsent is a defect, closed and reconnected; `reconnect(reason)` gives up on a socket the protocol above finds dead; `close()` is the page's own end. |
|
|
22
|
+
| `src/terminal/` | `TerminalView`, one view of an attended session's terminal (ADR-181 D11 item 2): `terminalwire` over a `StreamConnection` to the kit's terminal route, holding ADR-180's client duties itself — the resume offset in bytes handed to the renderer, an `ACK` only for bytes the renderer's `parsed` callback reported, at most 64 KiB of `INPUT` beyond `INPUT_ACK` (a paste queued in the view), a one-byte keystroke the window cannot hold sent as `SIGNAL` (P-R2), input dropped while history is drawn, `CONTROL {take}` before a viewer's first keystroke, `RESIZE` only while the view sets the size, and the step after each `CLOSE` reason. The renderer is named by its shape (`TerminalRenderer`, which xterm.js's `Terminal` meets), so xterm.js is the page's dependency, not the package's. Its tests drive it with a scripted socket and a recording renderer; no real browser runs here. |
|
|
23
|
+
| `src/**/*.test.ts` | The suite, beside what it tests. |
|
|
24
|
+
|
|
25
|
+
## Tests
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
make test-web-sdk
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
runs `node --test` inside this directory on the host's `node`, at or above
|
|
32
|
+
`package.json`'s `engines.node`. Nothing is installed: the tests use only
|
|
33
|
+
`node:test` and `node:assert`, and node strips the sources' types itself, so
|
|
34
|
+
write only erasable TypeScript (no `enum`, no `namespace`, no parameter
|
|
35
|
+
properties) and import siblings by their `.ts` name. The gate runs the same
|
|
36
|
+
suite for any diff under `sdk/web/`
|
|
37
|
+
([`docs/testing-infrastructure.md`](../../docs/testing-infrastructure.md),
|
|
38
|
+
"The browser package").
|
|
39
|
+
|
|
40
|
+
The gate does not type-check: `tsc` would have to be fetched. `tsconfig.json`
|
|
41
|
+
is here for an author with one, `tsc -p sdk/web`. What the gate does run over
|
|
42
|
+
the generated types is `src/contract.test.ts`: every committed schema has a
|
|
43
|
+
generated type, the route table is the committed one, and a fixture of each
|
|
44
|
+
D3 shape, annotated with its generated type, is valid against its schema.
|
|
45
|
+
|
|
46
|
+
## Open on your phone
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
const me = await client.me();
|
|
50
|
+
link.href = phoneURL(me, window.location, "/plugins/wb/"); // omit the base at the root of the plugin's own origin
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
The link is the plugin's own `_tera/phone`, under its base. tera's proxy
|
|
54
|
+
redirects it to tera's `/oauth/phone` only for a page under this
|
|
55
|
+
installation's own base, and to the app's base for any other. The fragment
|
|
56
|
+
rides along, but survives on the phone only when no sign-in intervenes, so a
|
|
57
|
+
deep link a phone must open on its first visit routes by path or query.
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { FeedConnection, type FeedConnectionOptions } from "./feed/connection.ts";
|
|
2
|
+
import { StreamConnection, type StreamConnectionOptions } from "./stream/connection.ts";
|
|
3
|
+
import { TerminalView, type TerminalViewOptions } from "./terminal/view.ts";
|
|
4
|
+
import type { KitError, KitInvokeResponse, KitMeResponse, KitStepUpResponse, KitUploadResponse } from "./generated/kit.ts";
|
|
5
|
+
import { type StepUpChallenge, type StepUpOptions } from "./stepup.ts";
|
|
6
|
+
/** The body of a kit failure: the envelope's `error` member. */
|
|
7
|
+
export type KitErrorBody = KitError["error"];
|
|
8
|
+
/** A verb's refusal, as the kit passed it through: the reply envelope's `error` member. */
|
|
9
|
+
export type VerbRefusal = NonNullable<KitInvokeResponse["error"]>;
|
|
10
|
+
/**
|
|
11
|
+
* What {@link TeraClient.invoke} answers when the verb ran: its result, or its
|
|
12
|
+
* refusal. `Result` is the verb's result type — for a Work Order verb, the
|
|
13
|
+
* generated `WorkOrder<Verb>Result`.
|
|
14
|
+
*/
|
|
15
|
+
export type InvokeVerdict<Result = unknown> = {
|
|
16
|
+
readonly status: "success";
|
|
17
|
+
readonly result: Result;
|
|
18
|
+
} | {
|
|
19
|
+
readonly status: "error";
|
|
20
|
+
readonly error: VerbRefusal;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* The `code` of a {@link KitRequestError} whose answer was not the kit's
|
|
24
|
+
* envelope — a proxy's page, a dropped body, a success that is not the
|
|
25
|
+
* route's JSON. It is this package's, never one the kit sends.
|
|
26
|
+
*/
|
|
27
|
+
export declare const UNRECOGNIZED_RESPONSE = "unrecognized_response";
|
|
28
|
+
/**
|
|
29
|
+
* A kit route that did not answer as the route: the kit's own refusal, or
|
|
30
|
+
* something that was not the route's answer at all.
|
|
31
|
+
*/
|
|
32
|
+
export declare class KitRequestError extends Error {
|
|
33
|
+
/** The HTTP status the route answered with. */
|
|
34
|
+
readonly status: number;
|
|
35
|
+
/**
|
|
36
|
+
* The envelope's code, as it arrived — one of the kit's `KitErrorCode`s, or
|
|
37
|
+
* a code this package does not know, kept as it is — or
|
|
38
|
+
* {@link UNRECOGNIZED_RESPONSE} when there was no envelope.
|
|
39
|
+
*/
|
|
40
|
+
readonly code: string;
|
|
41
|
+
/** Whether the identical request may succeed if sent again later. Branch on this, never on a list of codes. */
|
|
42
|
+
readonly retryable: boolean;
|
|
43
|
+
/** How long to wait before retrying, when the envelope said. */
|
|
44
|
+
readonly retryAfterMs: number | undefined;
|
|
45
|
+
/** The envelope's structured detail, when it carried any. */
|
|
46
|
+
readonly data: unknown;
|
|
47
|
+
/** The envelope as it arrived, or null when the answer carried none. */
|
|
48
|
+
readonly envelope: KitErrorBody | null;
|
|
49
|
+
constructor(status: number, envelope: KitErrorBody | null, fallback: string);
|
|
50
|
+
}
|
|
51
|
+
/** The progress of one upload's body. */
|
|
52
|
+
export interface UploadProgress {
|
|
53
|
+
/** Bytes sent so far. */
|
|
54
|
+
readonly loaded: number;
|
|
55
|
+
/** Bytes to send: the file's size. */
|
|
56
|
+
readonly total: number;
|
|
57
|
+
}
|
|
58
|
+
export interface UploadOptions {
|
|
59
|
+
/** The file's name; the `File`'s own name when absent. Required by the route: an upload with neither is refused before it is sent. */
|
|
60
|
+
filename?: string;
|
|
61
|
+
/** The file's media type; the `Blob`'s own type, or `application/octet-stream`, when absent. */
|
|
62
|
+
contentType?: string;
|
|
63
|
+
/** A description of the file, carried to the artifact. */
|
|
64
|
+
description?: string;
|
|
65
|
+
/** Called as the body is sent. */
|
|
66
|
+
onProgress?: (progress: UploadProgress) => void;
|
|
67
|
+
/** Aborting it cancels the upload, which then rejects with an `AbortError`. */
|
|
68
|
+
signal?: AbortSignal;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The part of `XMLHttpRequest` the upload helper uses. Upload progress is the
|
|
72
|
+
* reason it is not `fetch`: a fetch reports nothing while its body is sent.
|
|
73
|
+
*/
|
|
74
|
+
export interface UploadRequest {
|
|
75
|
+
open(method: string, url: string): void;
|
|
76
|
+
setRequestHeader(name: string, value: string): void;
|
|
77
|
+
send(body: Blob): void;
|
|
78
|
+
abort(): void;
|
|
79
|
+
readonly status: number;
|
|
80
|
+
readonly responseText: string;
|
|
81
|
+
getResponseHeader(name: string): string | null;
|
|
82
|
+
withCredentials: boolean;
|
|
83
|
+
onload: ((ev: unknown) => void) | null;
|
|
84
|
+
onerror: ((ev: unknown) => void) | null;
|
|
85
|
+
onabort: ((ev: unknown) => void) | null;
|
|
86
|
+
readonly upload: {
|
|
87
|
+
onprogress: ((ev: {
|
|
88
|
+
loaded: number;
|
|
89
|
+
total: number;
|
|
90
|
+
lengthComputable: boolean;
|
|
91
|
+
}) => void) | null;
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
export interface TeraClientOptions {
|
|
95
|
+
/**
|
|
96
|
+
* The path the app is served under on its origin: `/`, the default, on a
|
|
97
|
+
* plugin's own origin, and `/plugins/<name>/` on an installation that serves
|
|
98
|
+
* plugins by path. Every route, and the sign-out, is reached under it.
|
|
99
|
+
*/
|
|
100
|
+
base?: string;
|
|
101
|
+
/** The fetch every route but the upload is read with; the page's own when absent. */
|
|
102
|
+
fetch?: typeof fetch;
|
|
103
|
+
/** Makes the upload's request; `new XMLHttpRequest()` when absent. */
|
|
104
|
+
uploadRequest?: () => UploadRequest;
|
|
105
|
+
/** Sends the page to a path or URL; `location.assign` when absent. */
|
|
106
|
+
navigate?: (path: string) => void;
|
|
107
|
+
/** How a step-up is confirmed: the window, the page's URL and the polling. */
|
|
108
|
+
stepUp?: StepUpOptions;
|
|
109
|
+
}
|
|
110
|
+
/** The options of {@link TeraClient.feed}: a {@link FeedConnection}'s, with the opener the client's own. */
|
|
111
|
+
export type FeedOptions = Omit<FeedConnectionOptions, "open" | "base">;
|
|
112
|
+
/** The options of {@link TeraClient.stream}: a {@link StreamConnection}'s, with the probe's fetch the client's own. */
|
|
113
|
+
export type StreamOptions = Omit<StreamConnectionOptions, "fetch" | "base" | "reSignIn">;
|
|
114
|
+
/** What {@link TeraClient.terminal} takes: a view's options but what the client supplies. */
|
|
115
|
+
export type TerminalOptions = Omit<TerminalViewOptions, "fetch" | "base" | "reSignIn">;
|
|
116
|
+
export declare class TeraClient {
|
|
117
|
+
private readonly base;
|
|
118
|
+
private readonly fetchFn;
|
|
119
|
+
private readonly uploadRequest;
|
|
120
|
+
private readonly navigate;
|
|
121
|
+
private readonly openWindow;
|
|
122
|
+
private readonly pageURL;
|
|
123
|
+
private readonly sleep;
|
|
124
|
+
private readonly pollMs;
|
|
125
|
+
/** Whether the step-up the page was loaded back with has been taken up. */
|
|
126
|
+
private resumeTaken;
|
|
127
|
+
/** Whether this client has loaded the page again to sign in. */
|
|
128
|
+
private signingIn;
|
|
129
|
+
constructor(options?: TeraClientOptions);
|
|
130
|
+
/** `GET /tera/v1/me`: who is signed in, and where to send them to sign out. */
|
|
131
|
+
me(): Promise<KitMeResponse>;
|
|
132
|
+
/**
|
|
133
|
+
* `POST /tera/v1/invoke/{capability}`: invokes one capability as the
|
|
134
|
+
* signed-in person, with `params` as its params, and answers the verb's
|
|
135
|
+
* verdict. A refusal by the verb answers `{ status: "error" }`; only the
|
|
136
|
+
* kit's own refusal, or an answer that is not the route's, throws.
|
|
137
|
+
*
|
|
138
|
+
* const got = await client.invoke<WorkOrderGetResult, WorkOrderGetParams>("work_order.get", { id });
|
|
139
|
+
* if (got.status === "success") show(got.result);
|
|
140
|
+
*/
|
|
141
|
+
invoke<Result = unknown, Params = unknown>(capability: string, params?: Params): Promise<InvokeVerdict<Result>>;
|
|
142
|
+
private invokeOnce;
|
|
143
|
+
/**
|
|
144
|
+
* A {@link FeedConnection} over `GET /tera/v1/feeds/{feed}`, read with this
|
|
145
|
+
* client's fetch. It is not started: call `start()` on it, and `stop()` when
|
|
146
|
+
* the page no longer wants it.
|
|
147
|
+
*/
|
|
148
|
+
feed(options: FeedOptions): FeedConnection;
|
|
149
|
+
/**
|
|
150
|
+
* A {@link StreamConnection} to one of the kit's stream routes, its failed
|
|
151
|
+
* handshakes probed with this client's fetch. It opens at once: call
|
|
152
|
+
* `close()` on it when the page no longer wants it.
|
|
153
|
+
*/
|
|
154
|
+
stream(options: StreamOptions): StreamConnection;
|
|
155
|
+
/**
|
|
156
|
+
* A {@link TerminalView} of an attended session's terminal at the kit's
|
|
157
|
+
* terminal route, its failed handshakes probed with this client's fetch. It
|
|
158
|
+
* opens at once: call `detach()` on it when the pane closes.
|
|
159
|
+
*/
|
|
160
|
+
terminal(options: TerminalOptions): TerminalView;
|
|
161
|
+
/**
|
|
162
|
+
* `POST /tera/v1/uploads`: sends one file as the signed-in person and
|
|
163
|
+
* answers the staged artifact, whose `handle` a Work Order's attachments
|
|
164
|
+
* name. Its name and description travel percent-encoded (UTF-8) in the
|
|
165
|
+
* route's headers, and `onProgress` reports the body as it is sent.
|
|
166
|
+
*/
|
|
167
|
+
upload(file: Blob, options?: UploadOptions): Promise<KitUploadResponse>;
|
|
168
|
+
private uploadOnce;
|
|
169
|
+
/**
|
|
170
|
+
* `GET /tera/v1/step-ups/{id}`: where one of the person's own step-ups is in
|
|
171
|
+
* its life. A step-up that is not theirs is thrown as tera's 404, as an id
|
|
172
|
+
* no step-up carries is.
|
|
173
|
+
*/
|
|
174
|
+
stepUp(id: string): Promise<KitStepUpResponse>;
|
|
175
|
+
/**
|
|
176
|
+
* A request to one of the plugin's own routes, `path` relative to the app's
|
|
177
|
+
* base (`reviews/7/finish`), same-origin. A `step_up_required` answer in the
|
|
178
|
+
* kit's envelope — what `webui.RequireStepUp` writes — is confirmed by the
|
|
179
|
+
* person and the request sent once more with `Tera-Step-Up`; any other
|
|
180
|
+
* answer, a success or a refusal, is returned as it arrived. A body sent
|
|
181
|
+
* again must be one that can be: a string, a `Blob`, `FormData` or a
|
|
182
|
+
* buffer, never a stream. A `sign_in_required` answer loads the page again
|
|
183
|
+
* ({@link TeraClient.reSignIn}) and is returned as it arrived.
|
|
184
|
+
*/
|
|
185
|
+
fetch(path: string, init?: RequestInit): Promise<Response>;
|
|
186
|
+
/**
|
|
187
|
+
* Loads the page again to sign the person in to the plugin's origin: a
|
|
188
|
+
* top-level navigation to the page's own URL, which tera's UI proxy answers
|
|
189
|
+
* with its silent sign-in. The client does it itself on a
|
|
190
|
+
* `sign_in_required` answer; a page calls it for one it read on its own.
|
|
191
|
+
* It navigates once per client: a second call does nothing.
|
|
192
|
+
*/
|
|
193
|
+
reSignIn(): void;
|
|
194
|
+
/** Loads the page again when `request` rejects as `sign_in_required`, and rejects as it did. */
|
|
195
|
+
private signInOnRefusal;
|
|
196
|
+
/**
|
|
197
|
+
* Has the person confirm the step-up `challenge` names, and answers its id
|
|
198
|
+
* once it is satisfied, to send the act again with. It opens the step-up's
|
|
199
|
+
* page in a new window, or navigates to it with a `return_to` naming this
|
|
200
|
+
* page when the browser opens none, and reads its state every poll interval
|
|
201
|
+
* until it is satisfied, declined or expired, closing the window it opened.
|
|
202
|
+
*
|
|
203
|
+
* Rejects with a {@link StepUpError} when the step-up ends unconfirmed, the
|
|
204
|
+
* person closes its window while it still waits, or the page navigated away
|
|
205
|
+
* to confirm it. A page loaded back from that navigation carries the id, and
|
|
206
|
+
* the first step-up it is asked for resumes that one when it is satisfied.
|
|
207
|
+
*/
|
|
208
|
+
confirmStepUp(challenge: StepUpChallenge): Promise<string>;
|
|
209
|
+
/** The step-up this page was loaded back with, once. */
|
|
210
|
+
private takeResumed;
|
|
211
|
+
private fetchSameOrigin;
|
|
212
|
+
/**
|
|
213
|
+
* Signs the person out: navigates to the `signout_path` `me()` answers,
|
|
214
|
+
* tera's own sign-out, resolved against the app's base. A `signout_path`
|
|
215
|
+
* that is not a path relative to the base — a root-absolute path, or one
|
|
216
|
+
* naming another origin — is refused rather than followed.
|
|
217
|
+
*/
|
|
218
|
+
signOut(): Promise<void>;
|
|
219
|
+
/** A kit route's path under the app's base. */
|
|
220
|
+
private route;
|
|
221
|
+
private json;
|
|
222
|
+
private jsonOnce;
|
|
223
|
+
}
|