copilotz 1.0.0-rc.21 → 1.0.0-rc.23
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/CHANGELOG.md +320 -1
- package/README.md +217 -87
- package/hosts/orgs/mod.d.ts +33 -13
- package/hosts/orgs/mod.js +183 -84
- package/hosts/web/address.d.ts +11 -0
- package/hosts/web/address.js +46 -0
- package/hosts/web/assets.js +11 -5
- package/hosts/web/entrances.d.ts +250 -0
- package/hosts/web/entrances.js +362 -0
- package/hosts/web/host.d.ts +15 -3
- package/hosts/web/host.js +31 -18
- package/hosts/web/mod.d.ts +4 -2
- package/hosts/web/mod.js +6 -0
- package/hosts/web/node/bundle.d.ts +5 -0
- package/hosts/web/node/bundle.js +1 -1
- package/hosts/web/node/mod.d.ts +6 -4
- package/hosts/web/node/mod.js +6 -4
- package/hosts/web/node/serve.d.ts +20 -23
- package/hosts/web/node/serve.js +10 -21
- package/hosts/web/routes.d.ts +23 -17
- package/hosts/web/routes.js +56 -32
- package/hosts/web/server.d.ts +89 -44
- package/hosts/web/server.js +208 -108
- package/hosts/web/signin.d.ts +7 -10
- package/hosts/web/signin.js +6 -3
- package/hosts/web/surface.d.ts +20 -0
- package/hosts/web/surface.js +42 -0
- package/hosts/web/theme/css.d.ts +2 -1
- package/hosts/web/theme/css.js +9 -2
- package/hosts/web/tickets.d.ts +14 -1
- package/hosts/web/tickets.js +30 -7
- package/hosts/web/widget.d.ts +31 -0
- package/hosts/web/widget.js +429 -0
- package/hosts/web/widgets.d.ts +43 -0
- package/hosts/web/widgets.js +117 -0
- package/package.json +5 -1
- package/plugins/access/contacts/actions/forget.js +3 -1
- package/plugins/access/contacts/actions/start.js +18 -8
- package/plugins/access/contacts/collections/contact.d.ts +2 -2
- package/plugins/access/contacts/collections/contact.js +1 -1
- package/plugins/access/contacts/contract.d.ts +5 -5
- package/plugins/access/contacts/contract.js +5 -5
- package/plugins/access/contacts/mod.d.ts +4 -0
- package/plugins/access/contacts/mod.js +4 -0
- package/plugins/access/contacts/views/contact.js +1 -0
- package/plugins/access/dev/actions/sign-in.d.ts +1 -0
- package/plugins/access/dev/actions/sign-in.js +38 -0
- package/plugins/access/dev/mod.d.ts +17 -0
- package/plugins/access/dev/mod.js +31 -0
- package/plugins/access/dev/shared/nearby.d.ts +2 -0
- package/plugins/access/dev/shared/nearby.js +27 -0
- package/plugins/access/directory/actions/invite.js +2 -2
- package/plugins/access/directory/actions/org.js +11 -8
- package/plugins/access/directory/collections/credit-code.d.ts +1 -1
- package/plugins/access/google/actions/sign-in.js +2 -0
- package/plugins/access/google/mod.d.ts +4 -2
- package/plugins/access/google/mod.js +15 -2
- package/plugins/access/identity/actions/session.js +5 -3
- package/plugins/access/identity/mod.d.ts +4 -2
- package/plugins/access/identity/mod.js +17 -2
- package/plugins/access/mod.d.ts +7 -0
- package/plugins/access/mod.js +1 -0
- package/plugins/access/spaces/shared/declared.d.ts +1 -1
- package/plugins/access/spaces/shared/rules.d.ts +16 -5
- package/plugins/access/spaces/shared/rules.js +74 -6
- package/plugins/agents/chat/actions/send.d.ts +21 -0
- package/plugins/agents/chat/actions/send.js +72 -13
- package/plugins/agents/chat/collections/file.d.ts +15 -0
- package/plugins/agents/chat/collections/file.js +12 -3
- package/plugins/agents/chat/collections/live.d.ts +11 -0
- package/plugins/agents/chat/collections/live.js +11 -1
- package/plugins/agents/chat/collections/message.d.ts +1 -1
- package/plugins/agents/chat/collections/wait.d.ts +1 -1
- package/plugins/agents/chat/contract.d.ts +3 -2
- package/plugins/agents/chat/contract.js +1 -0
- package/plugins/agents/chat/mod.d.ts +9 -3
- package/plugins/agents/chat/mod.js +28 -7
- package/plugins/agents/chat/processors/failed.js +8 -3
- package/plugins/agents/chat/processors/turn.js +6 -3
- package/plugins/agents/chat/shared/agents.js +11 -2
- package/plugins/agents/chat/shared/live.d.ts +4 -2
- package/plugins/agents/chat/shared/live.js +2 -1
- package/plugins/agents/chat/shared/types.d.ts +8 -0
- package/plugins/agents/history/collections/outline.d.ts +2 -2
- package/plugins/agents/openapi/shared/files.js +2 -0
- package/plugins/agents/routines/collections/routine.d.ts +1 -1
- package/plugins/billing/credits/collections/plan.d.ts +2 -2
- package/plugins/billing/credits/collections/room.d.ts +1 -1
- package/plugins/billing/usage/collections/rollup.d.ts +2 -2
- package/plugins/billing/usage/collections/usage.d.ts +2 -2
- package/plugins/compute/cloud/actions/pool.js +2 -0
- package/plugins/compute/cloud/actions/remote.js +4 -2
- package/plugins/compute/cloud/actions/vms.js +2 -0
- package/plugins/compute/cloud/collections/pool-vm.d.ts +1 -1
- package/plugins/compute/computers/actions/admit.js +2 -0
- package/plugins/compute/computers/actions/code.js +2 -0
- package/plugins/compute/computers/actions/enrollment.js +2 -0
- package/plugins/compute/computers/actions/work.js +3 -0
- package/plugins/compute/computers/program/version.d.ts +1 -1
- package/plugins/compute/computers/program/version.js +1 -1
- package/plugins/compute/computers/resources/downloads.js +1 -1
- package/plugins/compute/computers/resources/previews.js +5 -2
- package/plugins/interfaces/maintenance/mod.d.ts +3 -1
- package/plugins/interfaces/maintenance/mod.js +3 -1
- package/plugins/interfaces/mcp/actions/call.d.ts +4 -0
- package/plugins/interfaces/mcp/actions/call.js +120 -18
- package/plugins/interfaces/mcp/actions/conversation.d.ts +1 -0
- package/plugins/interfaces/mcp/actions/conversation.js +49 -0
- package/plugins/interfaces/mcp/actions/prune.js +5 -3
- package/plugins/interfaces/mcp/collections/opening.d.ts +24 -0
- package/plugins/interfaces/mcp/collections/opening.js +28 -0
- package/plugins/interfaces/mcp/mod.d.ts +27 -3
- package/plugins/interfaces/mcp/mod.js +42 -7
- package/plugins/interfaces/mcp/resources/server.d.ts +13 -4
- package/plugins/interfaces/mcp/resources/server.js +163 -21
- package/plugins/interfaces/mcp/resources/tools.d.ts +88 -12
- package/plugins/interfaces/mcp/resources/tools.js +113 -19
- package/plugins/interfaces/mcp/resources/widgets.d.ts +161 -0
- package/plugins/interfaces/mcp/resources/widgets.js +246 -0
- package/plugins/interfaces/mcp/shared/keys.d.ts +25 -19
- package/plugins/interfaces/mcp/shared/keys.js +55 -9
- package/plugins/interfaces/mcp/shared/settings.d.ts +70 -37
- package/plugins/interfaces/mcp/shared/settings.js +64 -39
- package/plugins/interfaces/mcp/views/offered.d.ts +1 -1
- package/plugins/interfaces/mod.d.ts +2 -1
- package/plugins/interfaces/mod.js +2 -1
- package/plugins/interfaces/voice/collections/blocked.d.ts +2 -2
- package/plugins/interfaces/voice/collections/call.d.ts +3 -3
- package/plugins/interfaces/voice/contract.d.ts +1 -1
- package/plugins/interfaces/voice/mod.d.ts +3 -3
- package/plugins/interfaces/voice/mod.js +3 -3
- package/plugins/interfaces/voice/resources/relay.d.ts +5 -3
- package/plugins/interfaces/voice/resources/relay.js +17 -6
- package/plugins/interfaces/voice/resources/tools.js +2 -0
- package/plugins/interfaces/voice/shared/settings.d.ts +5 -0
- package/plugins/interfaces/voice/views/call.d.ts +18 -11
- package/plugins/interfaces/voice/views/call.js +15 -3
- package/plugins/interfaces/voice/views/message.d.ts +1 -1
- package/plugins/interfaces/web/actions/arrive.d.ts +1 -0
- package/plugins/interfaces/web/actions/arrive.js +120 -0
- package/plugins/interfaces/web/actions/prune.d.ts +1 -0
- package/plugins/interfaces/web/actions/prune.js +51 -0
- package/plugins/interfaces/web/actions/sending.d.ts +1 -0
- package/plugins/interfaces/web/actions/sending.js +222 -0
- package/plugins/interfaces/web/actions/spent.d.ts +2 -0
- package/plugins/interfaces/web/actions/spent.js +59 -0
- package/plugins/interfaces/web/collections/rate.d.ts +122 -0
- package/plugins/interfaces/web/collections/rate.js +37 -0
- package/plugins/interfaces/web/collections/visitor.d.ts +110 -0
- package/plugins/interfaces/web/collections/visitor.js +64 -0
- package/plugins/interfaces/web/contract.d.ts +4 -0
- package/plugins/interfaces/web/contract.js +1 -0
- package/plugins/interfaces/web/lines.d.ts +36 -0
- package/plugins/interfaces/web/lines.js +78 -0
- package/plugins/interfaces/web/processors/forget.d.ts +10 -0
- package/plugins/interfaces/web/processors/forget.js +14 -0
- package/plugins/interfaces/web/resources/entrance.d.ts +47 -0
- package/plugins/interfaces/web/resources/entrance.js +83 -0
- package/plugins/interfaces/web/resources/spend.d.ts +2 -0
- package/plugins/interfaces/web/resources/spend.js +62 -0
- package/plugins/interfaces/web/shared/budget.d.ts +65 -0
- package/plugins/interfaces/web/shared/budget.js +134 -0
- package/plugins/interfaces/web/shared/lines.d.ts +158 -0
- package/plugins/interfaces/web/shared/lines.js +156 -0
- package/plugins/interfaces/web/shared/secret.d.ts +33 -0
- package/plugins/interfaces/web/shared/secret.js +86 -0
- package/plugins/interfaces/whatsapp/collections/phone.d.ts +1 -1
- package/plugins/interfaces/whatsapp/mod.d.ts +1 -1
- package/plugins/interfaces/whatsapp/mod.js +1 -1
- package/plugins/interfaces/whatsapp/views/message.d.ts +1 -1
- package/plugins/models/contract.d.ts +1 -1
- package/plugins/models/shared/generate.js +13 -4
- package/plugins/models/shared/transcribe.js +7 -1
- package/plugins/models/shared/use.d.ts +16 -2
- package/plugins/models/shared/use.js +20 -0
- package/runtime/browsers.d.ts +153 -17
- package/runtime/browsers.js +336 -30
- package/runtime/cache.js +25 -5
- package/runtime/caller.d.ts +117 -0
- package/runtime/caller.js +215 -0
- package/runtime/client.d.ts +47 -3
- package/runtime/client.js +132 -42
- package/runtime/define.d.ts +30 -9
- package/runtime/executor.js +7 -6
- package/runtime/expiring.d.ts +23 -0
- package/runtime/expiring.js +64 -0
- package/runtime/links.d.ts +27 -4
- package/runtime/links.js +49 -11
- package/runtime/memory.js +102 -15
- package/runtime/mod.d.ts +3 -1
- package/runtime/mod.js +3 -1
- package/runtime/mongo.d.ts +12 -0
- package/runtime/mongo.js +44 -0
- package/runtime/observe.js +82 -9
- package/runtime/ops.d.ts +9 -1
- package/runtime/owner.d.ts +14 -1
- package/runtime/owner.js +78 -23
- package/runtime/reads.js +2 -2
- package/runtime/registry.js +9 -3
- package/runtime/runtime.d.ts +7 -0
- package/runtime/runtime.js +1 -0
- package/runtime/timers.js +2 -0
- package/runtime/views.d.ts +1 -1
- package/runtime/views.js +2 -2
- package/runtime/wire.d.ts +1 -1
- package/stores/sql/postgres/maintenance.d.ts +8 -1
- package/stores/sql/postgres/maintenance.js +76 -9
- package/stores/sql/postgres/mod.d.ts +12 -4
- package/stores/sql/postgres/mod.js +21 -8
- package/plugins/interfaces/mcp/shared/caller.d.ts +0 -45
- package/plugins/interfaces/mcp/shared/caller.js +0 -99
package/hosts/web/server.d.ts
CHANGED
|
@@ -1,34 +1,51 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The web host's server half:
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* The web host's server half: one host for every app, whose parts are what
|
|
3
|
+
* the app's plugins declare. It reaches the runtime by name only: the
|
|
4
|
+
* resources below, and the queries and Actions they name.
|
|
5
|
+
*
|
|
6
|
+
* | Part | Comes from | Without it |
|
|
7
|
+
* | --- | --- | --- |
|
|
8
|
+
* | Routes: webhooks, APIs, sockets of their own | the `routes` resource | — |
|
|
9
|
+
* | The page and its code | `code` (the app's front ends, its shell among them, bundled) | no page: the routes, and `/health` |
|
|
10
|
+
* | Who a browser is | the `entrances` resource (identity's session; web lines) | nobody |
|
|
11
|
+
* | Browsers connecting | `tickets`, for whoever an entrance says | no browser connects |
|
|
12
|
+
* | Signing in | the `signIn` resource (Google sign-in, dev sign-in) | none |
|
|
6
13
|
*
|
|
7
14
|
* - `GET /app/<file>`: the browser's code (the web host, its shell, the front
|
|
8
15
|
* ends), as bundled with code splitting: the entry, which the page loads
|
|
9
16
|
* and browsers ask again for, and the chunks its dynamic imports load
|
|
10
17
|
* (math, a terminal) when first needed, each named by its content, so
|
|
11
18
|
* browsers keep them for a year.
|
|
12
|
-
* - `POST /
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
19
|
+
* - `POST /connect`: who the request is (see entrances.ts), traded for a
|
|
20
|
+
* one-time ticket: `{ ticket, actor, name? }`. Its cookies say, the first
|
|
21
|
+
* entrance's that's someone; with none, an entrance may let them in now
|
|
22
|
+
* (a visitor of a web line, from what the page asks: `{ line }`), setting
|
|
23
|
+
* its cookie. From the app's own page only (`Origin`); 401 for nobody, 429
|
|
24
|
+
* (with `retry-after`) past a limit: a web line's, or the tickets anyone
|
|
25
|
+
* may have in a minute (`createTickets`).
|
|
26
|
+
* - `POST /signin/<name>` (a way the app's plugins declare; `local` ones
|
|
27
|
+
* from this machine, to this machine only: `fromHere`, by the socket's
|
|
28
|
+
* address and the host, with no proxy's headers): a session, set as an
|
|
29
|
+
* httpOnly cookie. `POST /signout`: ends it, ends the browsers connected
|
|
30
|
+
* as whoever it was, and clears every entrance's cookie. A cookie still
|
|
31
|
+
* held under its name from before it was the host's alone (`session`, now
|
|
32
|
+
* `__Host-session`) is ended and cleared on `/connect` and sign-out. What
|
|
33
|
+
* the host answers in JSON (these, `/connect`) is never cached (`no-store`).
|
|
17
34
|
* - The socket (`/oxian`): Oxian's worker protocol, which the app hands over. The
|
|
18
35
|
* runtime takes browsers there once it declares it: `transports: [socket]`.
|
|
19
36
|
* - `GET /assets/…`: the app's own files (`assets`: a brand's fonts and their
|
|
20
37
|
* stylesheet, images), by exact path, with their types and caching; anything
|
|
21
38
|
* else there is a 404 (see `assets.ts`). Under `/assets/copilotz/`, the host's
|
|
22
|
-
* own, with no configuration: the default theme's fonts, its PNG
|
|
23
|
-
* the page's SVG icon, drawn from the theme's mark (`theme/files/`).
|
|
24
|
-
* - `GET /files/<id>`: a file someone sent, as the
|
|
25
|
-
* (chat's `file.content`),
|
|
26
|
-
* (see `files.ts`).
|
|
39
|
+
* own, with the page and no configuration: the default theme's fonts, its PNG
|
|
40
|
+
* icon, and the page's SVG icon, drawn from the theme's mark (`theme/files/`).
|
|
41
|
+
* - `GET /files/<id>`: a file someone sent, as whoever the request is reaches
|
|
42
|
+
* it (chat's `file.content`), or by a link signed for it, with ranges for
|
|
43
|
+
* audio; `?download=1` saves it (see `files.ts`).
|
|
27
44
|
* - Plugins' own paths, their `routes` resource: a webhook, an OAuth callback,
|
|
28
|
-
* an API, a download, a socket of their own (see `routes.ts`)
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
45
|
+
* an API, a download, a socket of their own (see `routes.ts`), called as
|
|
46
|
+
* whoever the request is, else a visitor. A request to a host a route takes
|
|
47
|
+
* (a preview's) is that route's alone, whatever its path: never the page,
|
|
48
|
+
* the code or the socket.
|
|
32
49
|
* - `GET /manifest.webmanifest` and `GET /sw.js`: the app, installable: its
|
|
33
50
|
* manifest (name, colours, icons drawn from the theme's mark) and its
|
|
34
51
|
* service worker, which keeps the code at hand and offers new versions
|
|
@@ -39,40 +56,63 @@
|
|
|
39
56
|
* head also has the theme's icon (the mark, and its PNG), the browser's
|
|
40
57
|
* colour around the page (`theme-color`: each scheme's `background`), and
|
|
41
58
|
* its fonts, fetched at once but not waited for: the colours paint first,
|
|
42
|
-
* and the host applies the fonts' stylesheet as it starts.
|
|
59
|
+
* and the host applies the fonts' stylesheet as it starts. Without a page,
|
|
60
|
+
* `GET /health` says it's up (unless a route takes it), and anything else
|
|
61
|
+
* is a 404.
|
|
62
|
+
*
|
|
63
|
+
* Something going wrong answers its code's status (`refusal`: 400, 403, 404,
|
|
64
|
+
* 429, else 500, logged), and its words only when they're for anyone.
|
|
43
65
|
*
|
|
44
66
|
* It answers `Request`s with `Response`s and nothing else (no files, no
|
|
45
|
-
* sockets of its own), so it runs on Deno, Node, Bun or a worker alike.
|
|
67
|
+
* sockets of its own), so it runs on Deno, Node, Bun or a worker alike. A
|
|
68
|
+
* listener of the app's own says where each request came from
|
|
69
|
+
* (`setClientAddress`), as Copilotz's (`copilotz/web/node`) and Oxian's do.
|
|
46
70
|
*/
|
|
47
71
|
import type { Runtime } from "../../runtime/mod.js";
|
|
48
72
|
import { type Asset } from "./assets.js";
|
|
49
73
|
import type { Theme } from "./theme/default.js";
|
|
50
74
|
import { type Front } from "./routes.js";
|
|
51
75
|
import type { Tickets } from "./tickets.js";
|
|
76
|
+
import type { Widgets } from "./widgets.js";
|
|
52
77
|
export type WebServerOptions = {
|
|
53
78
|
runtime: Runtime;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
79
|
+
/**
|
|
80
|
+
* What browsers connect with: one-time tickets, for whoever the app's
|
|
81
|
+
* entrances say a request is (the runtime admits them: `admit:
|
|
82
|
+
* tickets.admit`). Without it, no browser connects here.
|
|
83
|
+
*/
|
|
84
|
+
tickets?: Tickets;
|
|
85
|
+
/**
|
|
86
|
+
* The browser's code, bundled (or a function that bundles it, once): the
|
|
87
|
+
* app's front ends, its shell among them. Without it, there's no page: the
|
|
88
|
+
* app's routes, and `/health`.
|
|
89
|
+
*/
|
|
90
|
+
code?: Code | (() => Code | Promise<Code>);
|
|
91
|
+
/**
|
|
92
|
+
* Oxian's WebSocket upgrade, for `/oxian` (its Deno adapter's
|
|
93
|
+
* `handler(runtime.hypervisor)`). Without it, no socket here.
|
|
94
|
+
*/
|
|
95
|
+
upgrade?(request: Request): Response | Promise<Response>;
|
|
59
96
|
title?: string;
|
|
60
|
-
/**
|
|
61
|
-
|
|
62
|
-
clientId: string;
|
|
63
|
-
};
|
|
64
|
-
/** Sign in by name, from this machine only: for trying things out. */
|
|
65
|
-
dev?: boolean;
|
|
97
|
+
/** The page's language (`pt-BR`), for browsers, readers and translators: English unless said. */
|
|
98
|
+
lang?: string;
|
|
66
99
|
/**
|
|
67
|
-
* The
|
|
68
|
-
* host
|
|
100
|
+
* The name each cookie an entrance declares goes by here (its own, unless
|
|
101
|
+
* said), each then this host's alone (`__Host-` wherever it's Secure, as an
|
|
102
|
+
* entrance's `hostOnly` makes it): a host serving many orgs keeps each
|
|
103
|
+
* org's apart, and none that another host under its domain could set
|
|
104
|
+
* (`hosts/orgs`).
|
|
69
105
|
*/
|
|
70
|
-
cookie?: string;
|
|
106
|
+
cookie?: (name: string) => string;
|
|
71
107
|
/**
|
|
72
|
-
*
|
|
73
|
-
*
|
|
108
|
+
* Where people sign in, when not here: a host serving many orgs signs
|
|
109
|
+
* them in once, at its directory, and serves that itself. Its orgs' pages
|
|
110
|
+
* show the directory's ways to sign in (`at`), and nothing here signs in
|
|
111
|
+
* or out.
|
|
74
112
|
*/
|
|
75
|
-
signIn?:
|
|
113
|
+
signIn?: {
|
|
114
|
+
at: Runtime;
|
|
115
|
+
};
|
|
76
116
|
/**
|
|
77
117
|
* Where this app is under its host, when it isn't the root: a host serving
|
|
78
118
|
* many orgs serves each also under `/o/<org>` (`hosts/orgs`), for what
|
|
@@ -102,13 +142,22 @@ export type WebServerOptions = {
|
|
|
102
142
|
/**
|
|
103
143
|
* The app's front (a Cloudflare worker before it): a request carrying its
|
|
104
144
|
* secret (`x-copilotz-front`) is for the host it forwards
|
|
105
|
-
* (`x-forwarded-host`), which routes by host go by.
|
|
106
|
-
* without the secret, forwarded headers are ignored.
|
|
145
|
+
* (`x-forwarded-host`), which routes by host and the page's origin go by.
|
|
146
|
+
* Without it, or without the secret, forwarded headers are ignored.
|
|
107
147
|
*/
|
|
108
148
|
front?: Front;
|
|
149
|
+
/**
|
|
150
|
+
* The app's widgets (`widgetsOf`): its web Views drawn inside an outside assistant (an MCP
|
|
151
|
+
* Apps host such as ChatGPT), which the MCP interface's routes serve and snapshot. Without
|
|
152
|
+
* them, MCP's lines offer tools with no widgets.
|
|
153
|
+
*/
|
|
154
|
+
widgets?: Widgets;
|
|
109
155
|
};
|
|
110
156
|
export type { Asset };
|
|
111
|
-
export { type
|
|
157
|
+
export { type SnapshotOptions, type Widgets, widgetsOf, type WidgetsOptions } from "./widgets.js";
|
|
158
|
+
export { clientAddress, setClientAddress } from "./address.js";
|
|
159
|
+
export { type Arrived, cookieOf, type Door, type Entrance, hostCookie, setCookie, type SignIn, siteOf, type Whom, whomOf, } from "./entrances.js";
|
|
160
|
+
export { type Front, hostMatches, hostOf, type HttpAnswer, type HttpRequest, httpRequest, type Route, type RouteSocket, type Served, VISITOR, } from "./routes.js";
|
|
112
161
|
/**
|
|
113
162
|
* Bundled code: its files by name (`deno bundle --code-splitting --outdir`'s),
|
|
114
163
|
* the entry and the chunks it imports by relative path, and which one the
|
|
@@ -125,8 +174,4 @@ export declare const socket: {
|
|
|
125
174
|
readonly path: "/oxian";
|
|
126
175
|
};
|
|
127
176
|
};
|
|
128
|
-
/** A cookie a request carries, by name. */
|
|
129
|
-
export declare const cookieOf: (request: Request, name?: string) => string | undefined;
|
|
130
|
-
/** A session, as an httpOnly cookie: Secure unless this is the machine itself, over http. */
|
|
131
|
-
export declare const setCookie: (url: URL, value: string, maxAge: number, name?: string) => string;
|
|
132
177
|
export declare function webServer(options: WebServerOptions): (request: Request) => Promise<Response>;
|
package/hosts/web/server.js
CHANGED
|
@@ -1,28 +1,51 @@
|
|
|
1
|
+
import { clientAddress } from "./address.js";
|
|
1
2
|
import { assetServer } from "./assets.js";
|
|
3
|
+
import { arriving, cookieOf, cookieSafe, fromHere, fromPage, jsonOf, recognise, refusal, retireAll, setCookie, signInPage, signInsOf, whomOf, } from "./entrances.js";
|
|
2
4
|
import { fileServer } from "./files.js";
|
|
3
5
|
import { MANIFEST, manifestOf, precacheOf, versionOf, WORKER, workerOf } from "./pwa.js";
|
|
4
6
|
import { BASE } from "./style.js";
|
|
5
7
|
import { fontsOf, fromGoogle, plainColour, preloadsOf, themeCss } from "./theme/css.js";
|
|
6
8
|
import { HOST_ASSETS, hostFiles } from "./theme/files/mod.js";
|
|
7
|
-
import { routeServer } from "./routes.js";
|
|
9
|
+
import { hostOf, routeServer } from "./routes.js";
|
|
8
10
|
import { ownPath } from "./theme/own-path.js";
|
|
9
11
|
import { pictureOf } from "./theme/picture.js";
|
|
10
|
-
export {
|
|
12
|
+
export { widgetsOf } from "./widgets.js";
|
|
13
|
+
export { clientAddress, setClientAddress } from "./address.js";
|
|
14
|
+
export { cookieOf, hostCookie, setCookie, siteOf, whomOf, } from "./entrances.js";
|
|
15
|
+
export { hostMatches, hostOf, httpRequest, VISITOR, } from "./routes.js";
|
|
11
16
|
/** Where the code is served. */
|
|
12
17
|
const CODE = "/app/";
|
|
13
|
-
|
|
18
|
+
/** How long a session a sign-in starts is kept in its cookie: 30 days. */
|
|
19
|
+
const SESSION = 30 * 86_400;
|
|
20
|
+
/** Where a host without a page says it's up. */
|
|
21
|
+
const HEALTH = "/health";
|
|
14
22
|
/** Where browsers connect: the runtime's transport for them, which `upgrade` serves. */
|
|
15
23
|
export const socket = { type: "websocket", config: { path: "/oxian" } };
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
headers
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
/** What the host answers in JSON is someone's (a ticket, a session's cookie): never kept. */
|
|
25
|
+
const json = (value, init = {}) => {
|
|
26
|
+
const headers = new Headers({ "content-type": "application/json", "cache-control": "no-store" });
|
|
27
|
+
for (const [name, value] of new Headers(init.headers))
|
|
28
|
+
headers.set(name, value);
|
|
29
|
+
for (const cookie of init.cookies ?? [])
|
|
30
|
+
headers.append("set-cookie", cookie);
|
|
31
|
+
return new Response(JSON.stringify(value), { status: init.status ?? 200, headers });
|
|
32
|
+
};
|
|
33
|
+
const plain = (status, text) => new Response(text, { status, headers: { "content-type": "text/plain; charset=utf-8" } });
|
|
34
|
+
/**
|
|
35
|
+
* An error as the host answers it (see `refusal`), and past a limit, when to
|
|
36
|
+
* try again (`retryAfter`, in seconds, when the error says; else a minute).
|
|
37
|
+
*/
|
|
38
|
+
const refused = (error, fallback, cookies = []) => {
|
|
39
|
+
const { status, error: said } = refusal(error, fallback);
|
|
40
|
+
const wait = error?.retryAfter;
|
|
41
|
+
return json({ error: said }, {
|
|
42
|
+
status,
|
|
43
|
+
cookies,
|
|
44
|
+
...(status === 429
|
|
45
|
+
? { headers: { "retry-after": String(typeof wait === "number" ? wait : 60) } }
|
|
46
|
+
: {}),
|
|
47
|
+
});
|
|
48
|
+
};
|
|
26
49
|
/** The page's icons: the mark (as the host draws it, or the image it is) and the theme's PNG. */
|
|
27
50
|
const icons = (theme) => {
|
|
28
51
|
const mark = pictureOf(theme.logo?.mark);
|
|
@@ -98,17 +121,16 @@ const installable = (options) => {
|
|
|
98
121
|
* (`interactive-widget`, where browsers take it). Zoom stays: nothing caps
|
|
99
122
|
* the scale, so people can still pinch to read.
|
|
100
123
|
*/
|
|
101
|
-
const page = (options, entry) => `<!doctype html>
|
|
102
|
-
<html lang="en">
|
|
124
|
+
const page = (options, entry, signIn) => `<!doctype html>
|
|
125
|
+
<html lang="${quoted(options.lang ?? "en")}">
|
|
103
126
|
<head>
|
|
104
127
|
<meta charset="utf-8">
|
|
105
128
|
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover, interactive-widget=resizes-content">
|
|
106
|
-
${look(options.theme)}${installable(options)}<title>${options.title ?? "Copilotz"}</title>
|
|
129
|
+
${look(options.theme)}${installable(options)}<title>${quoted(options.title ?? "Copilotz")}</title>
|
|
107
130
|
<script id="copilotz-config" type="application/json">${
|
|
108
131
|
// Escaped, so nothing in it can end the script.
|
|
109
132
|
JSON.stringify({
|
|
110
|
-
|
|
111
|
-
dev: options.dev ?? false,
|
|
133
|
+
signIn,
|
|
112
134
|
...(options.base ? { base: options.base } : {}),
|
|
113
135
|
...(options.socket ? { socket: options.socket } : {}),
|
|
114
136
|
})
|
|
@@ -120,14 +142,14 @@ JSON.stringify({
|
|
|
120
142
|
</body>
|
|
121
143
|
</html>`;
|
|
122
144
|
export function webServer(options) {
|
|
123
|
-
const { runtime, tickets } = options;
|
|
124
|
-
const
|
|
125
|
-
const signIn = options.signIn ?? true;
|
|
145
|
+
const { runtime, tickets, front } = options;
|
|
146
|
+
const here = !options.signIn;
|
|
126
147
|
const taken = Object.keys(options.assets ?? {}).find((path) => path.startsWith(HOST_ASSETS));
|
|
127
148
|
if (taken) {
|
|
128
149
|
throw new Error(`webServer: can't serve "${taken}": ${HOST_ASSETS} is the web host's own; use another path`);
|
|
129
150
|
}
|
|
130
|
-
const
|
|
151
|
+
const paged = options.code !== undefined;
|
|
152
|
+
const assets = assetServer({ ...(paged ? hostFiles(options.theme) : {}), ...options.assets });
|
|
131
153
|
let bundled;
|
|
132
154
|
/** The code, bundled once; its files' names are plain, so they go in the page as they are. */
|
|
133
155
|
const code = () => bundled ??= Promise.resolve(typeof options.code === "function" ? options.code() : options.code)
|
|
@@ -138,13 +160,22 @@ export function webServer(options) {
|
|
|
138
160
|
}
|
|
139
161
|
return made;
|
|
140
162
|
});
|
|
141
|
-
|
|
142
|
-
const whom =
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
};
|
|
163
|
+
// Who a request is, by the app's entrances (checked now: a bad declaration stops the start).
|
|
164
|
+
const whom = whomOf(runtime, {
|
|
165
|
+
...(options.cookie ? { cookie: options.cookie } : {}),
|
|
166
|
+
...(front ? { front } : {}),
|
|
167
|
+
});
|
|
168
|
+
const signIns = here ? signInsOf(runtime, whom.entrances) : new Map();
|
|
169
|
+
/** Whether browsers connect here: someone to be, and tickets to connect with. */
|
|
170
|
+
const connecting = !!tickets && whom.entrances.length > 0;
|
|
171
|
+
/** What the page shows of the ways to sign in: here, or where the host signs people in. */
|
|
172
|
+
let shown;
|
|
173
|
+
const signInShown = () => shown ??= signInPage(options.signIn?.at ?? runtime);
|
|
146
174
|
const files = fileServer(runtime, whom);
|
|
147
|
-
const routes = routeServer(runtime, whom,
|
|
175
|
+
const routes = routeServer(runtime, whom, {
|
|
176
|
+
...(front ? { front } : {}),
|
|
177
|
+
...(options.widgets ? { widgets: options.widgets } : {}),
|
|
178
|
+
});
|
|
148
179
|
/** The service worker, for this version of the code: its version is the code's own. */
|
|
149
180
|
let worker;
|
|
150
181
|
const serviceWorker = () => worker ??= code().then(async (made) => workerOf({
|
|
@@ -155,18 +186,129 @@ export function webServer(options) {
|
|
|
155
186
|
...(options.theme ? { theme: options.theme } : {}),
|
|
156
187
|
...(options.title ? { title: options.title } : {}),
|
|
157
188
|
}));
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
189
|
+
const notFound = () => paged ? json({ error: "Not found" }, { status: 404 }) : plain(404, "Not found");
|
|
190
|
+
const elsewhere = () => json({ error: "Not from this app's page" }, { status: 403 });
|
|
191
|
+
/** `POST /connect`: who the request is, or someone let in now, traded for a ticket. */
|
|
192
|
+
const connect = async (request) => {
|
|
193
|
+
if (!fromPage(request, front))
|
|
194
|
+
return elsewhere();
|
|
195
|
+
if (!connecting)
|
|
196
|
+
return json({ error: "Not signed in" }, { status: 401 });
|
|
197
|
+
const asked = await jsonOf(request);
|
|
198
|
+
if (!asked)
|
|
199
|
+
return json({ error: "Send a JSON object, of 16 KiB at most" }, { status: 400 });
|
|
200
|
+
let came;
|
|
201
|
+
try {
|
|
202
|
+
const address = clientAddress(request);
|
|
203
|
+
came = await arriving(runtime, whom, request, {
|
|
204
|
+
runtime,
|
|
205
|
+
asked,
|
|
206
|
+
host: hostOf(request, front),
|
|
207
|
+
...(address ? { address } : {}),
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
catch (error) {
|
|
211
|
+
return refused(error, "Couldn't connect");
|
|
212
|
+
}
|
|
213
|
+
// What it held under a cookie's name from before it was the host's alone ends, and goes.
|
|
214
|
+
const cookies = [...came.cookies, ...await retireAll(runtime, whom, request)];
|
|
215
|
+
const { actor } = came;
|
|
216
|
+
if (!actor)
|
|
217
|
+
return json({ error: "Not signed in" }, { status: 401, cookies });
|
|
218
|
+
let ticket;
|
|
219
|
+
try {
|
|
220
|
+
ticket = tickets.issue(actor);
|
|
221
|
+
}
|
|
222
|
+
catch (error) {
|
|
223
|
+
return refused(error, "Couldn't connect", cookies);
|
|
224
|
+
}
|
|
225
|
+
// What the page shows them as: a person's name as they signed in, else their email.
|
|
226
|
+
const profile = actor.kind === "person"
|
|
227
|
+
? await runtime.query("person.profile", {
|
|
228
|
+
person: actor.id,
|
|
229
|
+
}).catch(() => null)
|
|
230
|
+
: null;
|
|
231
|
+
const name = profile?.name ?? profile?.email;
|
|
232
|
+
return json({
|
|
233
|
+
ticket,
|
|
234
|
+
actor: { kind: actor.kind, id: actor.id },
|
|
235
|
+
...(name ? { name } : {}),
|
|
236
|
+
}, { cookies });
|
|
237
|
+
};
|
|
238
|
+
/** `POST /signin/<name>`: a way the app declares, its session kept in its entrance's cookie. */
|
|
239
|
+
const signIn = async (request, name) => {
|
|
240
|
+
const method = signIns.get(name);
|
|
241
|
+
if (!method || (method.local && !fromHere(request, front)))
|
|
242
|
+
return notFound();
|
|
243
|
+
if (!fromPage(request, front))
|
|
244
|
+
return elsewhere();
|
|
245
|
+
const asked = await jsonOf(request);
|
|
246
|
+
if (!asked)
|
|
247
|
+
return json({ error: "Send a JSON object, of 16 KiB at most" }, { status: 400 });
|
|
248
|
+
let answered;
|
|
249
|
+
try {
|
|
250
|
+
answered = await runtime.call(method.action, asked);
|
|
251
|
+
}
|
|
252
|
+
catch (error) {
|
|
253
|
+
return refused(error, "Couldn't sign in");
|
|
254
|
+
}
|
|
255
|
+
const { person, session } = answered;
|
|
256
|
+
if (typeof person !== "string" || !person || !cookieSafe(session)) {
|
|
257
|
+
throw new Error(`signIn.${name}: ${method.action} answered no person, or no session`);
|
|
258
|
+
}
|
|
259
|
+
const entrance = whom.entrances.find((e) => e.name === method.entrance);
|
|
260
|
+
const site = whom.site(request);
|
|
261
|
+
return json({ person }, {
|
|
262
|
+
cookies: [
|
|
263
|
+
setCookie(site, session, SESSION, whom.named(entrance, site), entrance.sameSite),
|
|
264
|
+
],
|
|
265
|
+
});
|
|
266
|
+
};
|
|
267
|
+
/**
|
|
268
|
+
* `POST /signout`: what each entrance's cookie is ends, the browsers
|
|
269
|
+
* connected as them go (`runtime.disconnect`: one comes back only with a
|
|
270
|
+
* cookie that's still someone), so do tickets handed out to them not yet
|
|
271
|
+
* used (`tickets.end`), and every cookie goes, those under a name
|
|
272
|
+
* from before it was the host's alone too (`retireAll`).
|
|
273
|
+
*/
|
|
274
|
+
const signOut = async (request) => {
|
|
275
|
+
if (!fromPage(request, front))
|
|
276
|
+
return elsewhere();
|
|
277
|
+
const site = whom.site(request);
|
|
278
|
+
const cookies = [];
|
|
279
|
+
for (const entrance of whom.entrances) {
|
|
280
|
+
const name = whom.named(entrance, site);
|
|
281
|
+
const secret = cookieOf(request, name);
|
|
282
|
+
if (secret === undefined)
|
|
283
|
+
continue;
|
|
284
|
+
const actor = await recognise(runtime, entrance, secret).catch(() => null);
|
|
285
|
+
if (actor && entrance.end) {
|
|
286
|
+
await runtime.call(entrance.end, { secret }, { actor }).catch(() => { });
|
|
287
|
+
}
|
|
288
|
+
if (actor) {
|
|
289
|
+
runtime.disconnect(actor);
|
|
290
|
+
options.tickets?.end?.(actor);
|
|
291
|
+
}
|
|
292
|
+
cookies.push(setCookie(site, "", 0, name, entrance.sameSite));
|
|
293
|
+
}
|
|
294
|
+
cookies.push(...await retireAll(runtime, whom, request));
|
|
295
|
+
return json({}, { cookies });
|
|
296
|
+
};
|
|
161
297
|
return async (request) => {
|
|
162
298
|
// Routes first: a host a route takes is all its own (the host's paths are never routes').
|
|
163
|
-
const
|
|
164
|
-
if (
|
|
165
|
-
return await
|
|
299
|
+
const routed = routes(request);
|
|
300
|
+
if (routed)
|
|
301
|
+
return await routed;
|
|
166
302
|
const url = new URL(request.url);
|
|
167
303
|
const route = `${request.method} ${url.pathname}`;
|
|
304
|
+
if (!paged && (request.method === "GET" || request.method === "HEAD") && url.pathname === HEALTH) {
|
|
305
|
+
return plain(200, "ok");
|
|
306
|
+
}
|
|
307
|
+
const served = assets(request) ?? files(request);
|
|
308
|
+
if (served)
|
|
309
|
+
return await served;
|
|
168
310
|
try {
|
|
169
|
-
if (request.method === "GET" && url.pathname.startsWith(CODE)) {
|
|
311
|
+
if (paged && request.method === "GET" && url.pathname.startsWith(CODE)) {
|
|
170
312
|
const { entry, files } = await code();
|
|
171
313
|
const name = url.pathname.slice(CODE.length);
|
|
172
314
|
if (!Object.hasOwn(files, name))
|
|
@@ -178,86 +320,44 @@ export function webServer(options) {
|
|
|
178
320
|
},
|
|
179
321
|
});
|
|
180
322
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
? await runtime.query("person.profile", {
|
|
204
|
-
person: actor.id,
|
|
205
|
-
}).catch(() => null)
|
|
206
|
-
: null;
|
|
207
|
-
const name = profile?.name ?? profile?.email;
|
|
208
|
-
return json({
|
|
209
|
-
ticket: tickets.issue(actor),
|
|
210
|
-
person: actor.id,
|
|
211
|
-
...(name ? { name } : {}),
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
case "POST /signin/google": {
|
|
215
|
-
if (!options.google || !signIn)
|
|
216
|
-
break;
|
|
217
|
-
const { idToken } = await request.json();
|
|
218
|
-
const { session, person } = await runtime.call("google.sign-in", { idToken });
|
|
219
|
-
return signedIn(url, session, person);
|
|
220
|
-
}
|
|
221
|
-
case "POST /signin/dev": {
|
|
222
|
-
if (!options.dev || !signIn || !loopback(url))
|
|
223
|
-
break;
|
|
224
|
-
const { name } = await request.json();
|
|
225
|
-
const person = String(name ?? "").trim().toLowerCase();
|
|
226
|
-
const email = /^[a-z0-9._+-]{1,64}@[a-z0-9.-]{1,64}$/.test(person);
|
|
227
|
-
if (!email && !/^[a-z0-9._-]{1,40}$/.test(person)) {
|
|
228
|
-
return json({ error: "A name (letters, digits, . _ -) or an email" }, { status: 400 });
|
|
229
|
-
}
|
|
230
|
-
if (email)
|
|
231
|
-
await runtime.call("person.set", { person, email: person });
|
|
232
|
-
const { session } = await runtime.call("session.start", { person });
|
|
233
|
-
return signedIn(url, session, person);
|
|
234
|
-
}
|
|
235
|
-
case "POST /signout": {
|
|
236
|
-
if (!signIn)
|
|
237
|
-
break;
|
|
238
|
-
const secret = cookieOf(request, name);
|
|
239
|
-
if (secret) {
|
|
240
|
-
const actor = await runtime.query("credential.actor", { secret });
|
|
241
|
-
if (actor) {
|
|
242
|
-
await runtime.call("session.end", { session: secret }, { actor }).catch(() => { });
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
return json({}, { headers: { "set-cookie": setCookie(url, "", 0, name) } });
|
|
323
|
+
if (paged && route === `GET ${MANIFEST}`) {
|
|
324
|
+
return new Response(JSON.stringify(manifestOf(options.theme, options.title)), {
|
|
325
|
+
headers: {
|
|
326
|
+
"content-type": "application/manifest+json; charset=utf-8",
|
|
327
|
+
"cache-control": "no-cache",
|
|
328
|
+
},
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
if (paged && route === `GET ${WORKER}`) {
|
|
332
|
+
return new Response(await serviceWorker(), {
|
|
333
|
+
headers: {
|
|
334
|
+
"content-type": "text/javascript; charset=utf-8",
|
|
335
|
+
"cache-control": "no-cache",
|
|
336
|
+
"service-worker-allowed": "/",
|
|
337
|
+
},
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
if (route === "POST /connect" && (paged || connecting))
|
|
341
|
+
return await connect(request);
|
|
342
|
+
if (here && connecting && request.method === "POST") {
|
|
343
|
+
if (url.pathname.startsWith("/signin/")) {
|
|
344
|
+
return await signIn(request, url.pathname.slice("/signin/".length));
|
|
246
345
|
}
|
|
346
|
+
if (url.pathname === "/signout")
|
|
347
|
+
return await signOut(request);
|
|
247
348
|
}
|
|
248
|
-
if (url.pathname === socket.config.path)
|
|
249
|
-
return await options.upgrade(request);
|
|
250
|
-
|
|
251
|
-
|
|
349
|
+
if (url.pathname === socket.config.path) {
|
|
350
|
+
return options.upgrade ? await options.upgrade(request) : notFound();
|
|
351
|
+
}
|
|
352
|
+
if (paged && request.method === "GET" && !url.pathname.startsWith("/signin")) {
|
|
353
|
+
return new Response(page(options, (await code()).entry, signInShown()), {
|
|
252
354
|
headers: { "content-type": "text/html; charset=utf-8" },
|
|
253
355
|
});
|
|
254
356
|
}
|
|
255
|
-
return
|
|
357
|
+
return notFound();
|
|
256
358
|
}
|
|
257
359
|
catch (error) {
|
|
258
|
-
return
|
|
259
|
-
status: 400,
|
|
260
|
-
});
|
|
360
|
+
return refused(error, "Something went wrong");
|
|
261
361
|
}
|
|
262
362
|
};
|
|
263
363
|
}
|
package/hosts/web/signin.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Signing in, before anyone is connected
|
|
3
|
-
*
|
|
2
|
+
* Signing in, before anyone is connected, the ways the app's plugins declare
|
|
3
|
+
* (the server's `signIn`): with Google (`google`: its button, for the client
|
|
4
|
+
* id it gives), or by name on this machine (`dev`). Either sets the session cookie;
|
|
4
5
|
* the page then starts over, connected, where the server lands them (with
|
|
5
6
|
* many orgs, the one they were in last; their own the first time), with a
|
|
6
7
|
* word on where they're going while it does. Beside the form, what the app
|
|
@@ -9,13 +10,9 @@
|
|
|
9
10
|
* app's theme; on a phone, one column.
|
|
10
11
|
*/
|
|
11
12
|
import { type ReactNode } from "react";
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
dev: boolean;
|
|
17
|
-
};
|
|
18
|
-
export declare function SignIn({ config }: {
|
|
19
|
-
config: Config;
|
|
13
|
+
/** The ways to sign in the server declares, by name, each with what its button needs. */
|
|
14
|
+
type Ways = Record<string, Record<string, unknown>>;
|
|
15
|
+
export declare function SignIn({ signIn }: {
|
|
16
|
+
signIn: Ways;
|
|
20
17
|
}): ReactNode;
|
|
21
18
|
export {};
|
package/hosts/web/signin.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
/**
|
|
3
|
-
* Signing in, before anyone is connected
|
|
4
|
-
*
|
|
3
|
+
* Signing in, before anyone is connected, the ways the app's plugins declare
|
|
4
|
+
* (the server's `signIn`): with Google (`google`: its button, for the client
|
|
5
|
+
* id it gives), or by name on this machine (`dev`). Either sets the session cookie;
|
|
5
6
|
* the page then starts over, connected, where the server lands them (with
|
|
6
7
|
* many orgs, the one they were in last; their own the first time), with a
|
|
7
8
|
* word on where they're going while it does. Beside the form, what the app
|
|
@@ -115,7 +116,9 @@ const POINTS = [
|
|
|
115
116
|
text: "Your own, and your teams': switch between them in a click. Invitations wait for you here.",
|
|
116
117
|
},
|
|
117
118
|
];
|
|
118
|
-
export function SignIn({
|
|
119
|
+
export function SignIn({ signIn }) {
|
|
120
|
+
const clientId = typeof signIn.google?.clientId === "string" ? signIn.google.clientId : undefined;
|
|
121
|
+
const config = { google: clientId ? { clientId } : null, dev: !!signIn.dev };
|
|
119
122
|
const [name, setName] = useState("");
|
|
120
123
|
const [error, setError] = useState();
|
|
121
124
|
const [busy, setBusy] = useState(false);
|