@copilotz/directory 1.0.0-rc.80 → 1.0.0-rc.81
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 +1 -1
- package/README.md +9 -68
- package/contract.d.ts +1 -8
- package/contract.js +1 -8
- package/mod.d.ts +2 -67
- package/mod.js +2 -122
- package/package.json +9 -35
- package/web.d.ts +2 -36
- package/web.js +2 -57
- package/WORDS.md +0 -198
- package/actions/code.d.ts +0 -4
- package/actions/code.js +0 -135
- package/actions/host.d.ts +0 -2
- package/actions/host.js +0 -55
- package/actions/invite.d.ts +0 -5
- package/actions/invite.js +0 -129
- package/actions/org.d.ts +0 -10
- package/actions/org.js +0 -273
- package/collections/credit-code.d.ts +0 -107
- package/collections/credit-code.js +0 -28
- package/collections/invite.d.ts +0 -74
- package/collections/invite.js +0 -20
- package/collections/membership.d.ts +0 -65
- package/collections/membership.js +0 -22
- package/collections/org-host.d.ts +0 -55
- package/collections/org-host.js +0 -30
- package/collections/org.d.ts +0 -134
- package/collections/org.js +0 -58
- package/collections/staff.d.ts +0 -35
- package/collections/staff.js +0 -12
- package/routes/console.d.ts +0 -26
- package/routes/console.js +0 -129
- package/routes/enter.d.ts +0 -18
- package/routes/enter.js +0 -47
- package/routes/forward.d.ts +0 -35
- package/routes/forward.js +0 -119
- package/routes/orgs.d.ts +0 -25
- package/routes/orgs.js +0 -113
- package/routes/signout.d.ts +0 -11
- package/routes/signout.js +0 -36
- package/shared/enter.d.ts +0 -36
- package/shared/enter.js +0 -82
- package/shared/http.d.ts +0 -42
- package/shared/http.js +0 -77
- package/shared/member.d.ts +0 -21
- package/shared/member.js +0 -73
- package/shared/settings.d.ts +0 -53
- package/shared/settings.js +0 -16
- package/shared/state.d.ts +0 -74
- package/shared/state.js +0 -101
- package/views/web/codes.d.ts +0 -27
- package/views/web/codes.js +0 -50
- package/views/web/console-codes.d.ts +0 -37
- package/views/web/console-codes.js +0 -166
- package/views/web/console.d.ts +0 -37
- package/views/web/console.js +0 -224
- package/views/web/lists.d.ts +0 -48
- package/views/web/lists.js +0 -42
- package/views/web/org.d.ts +0 -12
- package/views/web/org.js +0 -62
- package/views/web/orgs.d.ts +0 -148
- package/views/web/orgs.js +0 -253
- package/views/web/style.d.ts +0 -6
- package/views/web/style.js +0 -197
- package/views/web/switcher.d.ts +0 -81
- package/views/web/switcher.js +0 -367
- package/views/web/words.d.ts +0 -10
- package/views/web/words.js +0 -206
package/collections/org.d.ts
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Orgs, as the directory routes them: a name, a kind (`personal` for the one
|
|
3
|
-
* everyone has, `team` for those people make), who made it, and where its
|
|
4
|
-
* rows live (`placement`: the schema it shares, or has to itself). An org's
|
|
5
|
-
* own data (its people's roles, its spaces) lives in the org, never here.
|
|
6
|
-
* `summary` is what the org last reported, for the platform console.
|
|
7
|
-
*/
|
|
8
|
-
import { type Infer } from "copilotz";
|
|
9
|
-
declare const orgSchema: {
|
|
10
|
-
readonly type: "object";
|
|
11
|
-
readonly properties: {
|
|
12
|
-
readonly name: {
|
|
13
|
-
readonly type: "string";
|
|
14
|
-
};
|
|
15
|
-
readonly kind: {
|
|
16
|
-
readonly type: "string";
|
|
17
|
-
readonly enum: readonly ["personal", "team"];
|
|
18
|
-
};
|
|
19
|
-
/** Who made it (a person, by their sign-in id). */
|
|
20
|
-
readonly by: {
|
|
21
|
-
readonly type: "string";
|
|
22
|
-
};
|
|
23
|
-
readonly placement: {
|
|
24
|
-
readonly type: "object";
|
|
25
|
-
readonly properties: {
|
|
26
|
-
readonly schema: {
|
|
27
|
-
readonly type: "string";
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
readonly required: readonly ["schema"];
|
|
31
|
-
};
|
|
32
|
-
/** A suspended org lets nobody in. */
|
|
33
|
-
readonly suspended: {
|
|
34
|
-
readonly type: "boolean";
|
|
35
|
-
};
|
|
36
|
-
readonly summary: {
|
|
37
|
-
readonly type: "object";
|
|
38
|
-
readonly properties: {
|
|
39
|
-
readonly people: {
|
|
40
|
-
readonly type: "number";
|
|
41
|
-
};
|
|
42
|
-
readonly spaces: {
|
|
43
|
-
readonly type: "number";
|
|
44
|
-
};
|
|
45
|
-
readonly active: {
|
|
46
|
-
readonly type: "string";
|
|
47
|
-
};
|
|
48
|
-
readonly at: {
|
|
49
|
-
readonly type: "string";
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
readonly at: {
|
|
54
|
-
readonly type: "string";
|
|
55
|
-
};
|
|
56
|
-
};
|
|
57
|
-
readonly required: readonly ["name", "kind", "by", "placement", "at"];
|
|
58
|
-
};
|
|
59
|
-
export declare const org: Omit<import("copilotz").CollectionDef, "queries" | "schema"> & {
|
|
60
|
-
queries?: Record<string, import("copilotz").QueryDef<import("copilotz").WithId<{
|
|
61
|
-
[x: string]: unknown;
|
|
62
|
-
suspended?: boolean | undefined;
|
|
63
|
-
summary?: {
|
|
64
|
-
[x: string]: unknown;
|
|
65
|
-
at?: string | undefined;
|
|
66
|
-
people?: number | undefined;
|
|
67
|
-
spaces?: number | undefined;
|
|
68
|
-
active?: string | undefined;
|
|
69
|
-
} | undefined;
|
|
70
|
-
placement: {
|
|
71
|
-
[x: string]: unknown;
|
|
72
|
-
schema: string;
|
|
73
|
-
};
|
|
74
|
-
at: string;
|
|
75
|
-
name: string;
|
|
76
|
-
kind: "personal" | "team";
|
|
77
|
-
by: string;
|
|
78
|
-
}>>> | undefined;
|
|
79
|
-
} & {
|
|
80
|
-
schema: {
|
|
81
|
-
readonly type: "object";
|
|
82
|
-
readonly properties: {
|
|
83
|
-
readonly name: {
|
|
84
|
-
readonly type: "string";
|
|
85
|
-
};
|
|
86
|
-
readonly kind: {
|
|
87
|
-
readonly type: "string";
|
|
88
|
-
readonly enum: readonly ["personal", "team"];
|
|
89
|
-
};
|
|
90
|
-
/** Who made it (a person, by their sign-in id). */
|
|
91
|
-
readonly by: {
|
|
92
|
-
readonly type: "string";
|
|
93
|
-
};
|
|
94
|
-
readonly placement: {
|
|
95
|
-
readonly type: "object";
|
|
96
|
-
readonly properties: {
|
|
97
|
-
readonly schema: {
|
|
98
|
-
readonly type: "string";
|
|
99
|
-
};
|
|
100
|
-
};
|
|
101
|
-
readonly required: readonly ["schema"];
|
|
102
|
-
};
|
|
103
|
-
/** A suspended org lets nobody in. */
|
|
104
|
-
readonly suspended: {
|
|
105
|
-
readonly type: "boolean";
|
|
106
|
-
};
|
|
107
|
-
readonly summary: {
|
|
108
|
-
readonly type: "object";
|
|
109
|
-
readonly properties: {
|
|
110
|
-
readonly people: {
|
|
111
|
-
readonly type: "number";
|
|
112
|
-
};
|
|
113
|
-
readonly spaces: {
|
|
114
|
-
readonly type: "number";
|
|
115
|
-
};
|
|
116
|
-
readonly active: {
|
|
117
|
-
readonly type: "string";
|
|
118
|
-
};
|
|
119
|
-
readonly at: {
|
|
120
|
-
readonly type: "string";
|
|
121
|
-
};
|
|
122
|
-
};
|
|
123
|
-
};
|
|
124
|
-
readonly at: {
|
|
125
|
-
readonly type: "string";
|
|
126
|
-
};
|
|
127
|
-
};
|
|
128
|
-
readonly required: readonly ["name", "kind", "by", "placement", "at"];
|
|
129
|
-
};
|
|
130
|
-
};
|
|
131
|
-
export type Org = Infer<typeof orgSchema> & {
|
|
132
|
-
_id: string;
|
|
133
|
-
};
|
|
134
|
-
export {};
|
package/collections/org.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Orgs, as the directory routes them: a name, a kind (`personal` for the one
|
|
3
|
-
* everyone has, `team` for those people make), who made it, and where its
|
|
4
|
-
* rows live (`placement`: the schema it shares, or has to itself). An org's
|
|
5
|
-
* own data (its people's roles, its spaces) lives in the org, never here.
|
|
6
|
-
* `summary` is what the org last reported, for the platform console.
|
|
7
|
-
*/
|
|
8
|
-
import { defineCollection } from "copilotz";
|
|
9
|
-
const orgSchema = {
|
|
10
|
-
type: "object",
|
|
11
|
-
properties: {
|
|
12
|
-
name: { type: "string" },
|
|
13
|
-
kind: { type: "string", enum: ["personal", "team"] },
|
|
14
|
-
/** Who made it (a person, by their sign-in id). */
|
|
15
|
-
by: { type: "string" },
|
|
16
|
-
placement: {
|
|
17
|
-
type: "object",
|
|
18
|
-
properties: { schema: { type: "string" } },
|
|
19
|
-
required: ["schema"],
|
|
20
|
-
},
|
|
21
|
-
/** A suspended org lets nobody in. */
|
|
22
|
-
suspended: { type: "boolean" },
|
|
23
|
-
summary: {
|
|
24
|
-
type: "object",
|
|
25
|
-
properties: {
|
|
26
|
-
people: { type: "number" },
|
|
27
|
-
spaces: { type: "number" },
|
|
28
|
-
active: { type: "string" },
|
|
29
|
-
at: { type: "string" },
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
at: { type: "string" },
|
|
33
|
-
},
|
|
34
|
-
required: ["name", "kind", "by", "placement", "at"],
|
|
35
|
-
};
|
|
36
|
-
export const org = defineCollection({
|
|
37
|
-
schema: orgSchema,
|
|
38
|
-
indexes: [["by"]],
|
|
39
|
-
queries: {
|
|
40
|
-
/**
|
|
41
|
-
* An org as the directory opens it (its name, kind, placement, and
|
|
42
|
-
* whether it's suspended), or null. The system's: the directory's routes
|
|
43
|
-
* ask it for every request they forward, and the app, to open an org.
|
|
44
|
-
*/
|
|
45
|
-
info: async (orgs, params) => {
|
|
46
|
-
const found = await orgs.findOne({ _id: String(params.org ?? "") });
|
|
47
|
-
return found
|
|
48
|
-
? {
|
|
49
|
-
id: found._id,
|
|
50
|
-
name: found.name,
|
|
51
|
-
kind: found.kind,
|
|
52
|
-
placement: found.placement,
|
|
53
|
-
...(found.suspended ? { suspended: true } : {}),
|
|
54
|
-
}
|
|
55
|
-
: null;
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
});
|
package/collections/staff.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Platform staff, by verified email: they enter any org, reaching all of it,
|
|
3
|
-
* and what they do there is on its record as theirs. The `directory`
|
|
4
|
-
* resource's `staff` list seeds them.
|
|
5
|
-
*/
|
|
6
|
-
import { type Infer } from "copilotz";
|
|
7
|
-
declare const staffSchema: {
|
|
8
|
-
readonly type: "object";
|
|
9
|
-
readonly properties: {
|
|
10
|
-
readonly at: {
|
|
11
|
-
readonly type: "string";
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
readonly required: readonly ["at"];
|
|
15
|
-
};
|
|
16
|
-
export declare const staff: Omit<import("copilotz").CollectionDef, "queries" | "schema"> & {
|
|
17
|
-
queries?: Record<string, import("copilotz").QueryDef<import("copilotz").WithId<{
|
|
18
|
-
[x: string]: unknown;
|
|
19
|
-
at: string;
|
|
20
|
-
}>>> | undefined;
|
|
21
|
-
} & {
|
|
22
|
-
schema: {
|
|
23
|
-
readonly type: "object";
|
|
24
|
-
readonly properties: {
|
|
25
|
-
readonly at: {
|
|
26
|
-
readonly type: "string";
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
readonly required: readonly ["at"];
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
export type Staff = Infer<typeof staffSchema> & {
|
|
33
|
-
_id: string;
|
|
34
|
-
};
|
|
35
|
-
export {};
|
package/collections/staff.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Platform staff, by verified email: they enter any org, reaching all of it,
|
|
3
|
-
* and what they do there is on its record as theirs. The `directory`
|
|
4
|
-
* resource's `staff` list seeds them.
|
|
5
|
-
*/
|
|
6
|
-
import { defineCollection } from "copilotz";
|
|
7
|
-
const staffSchema = {
|
|
8
|
-
type: "object",
|
|
9
|
-
properties: { at: { type: "string" } },
|
|
10
|
-
required: ["at"],
|
|
11
|
-
};
|
|
12
|
-
export const staff = defineCollection({ schema: staffSchema });
|
package/routes/console.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Staff's console (platform staff only, by their sign-in or the email they
|
|
3
|
-
* verified; anyone else, a 403):
|
|
4
|
-
*
|
|
5
|
-
* - `GET /console/orgs`: every org, with what each last reported;
|
|
6
|
-
* - `POST /console/orgs/<id>` `{ suspended?, name? }`;
|
|
7
|
-
* - `POST /console/orgs/<id>/move` `{ schema }`: its rows to another schema
|
|
8
|
-
* (closed first, then opened there on its next use);
|
|
9
|
-
* - `GET /console/orgs/<id>/export`: its rows, as SQL, to save;
|
|
10
|
-
* - `POST /console/orgs/<id>/delete` `{ confirm: <its name> }`: closed, its
|
|
11
|
-
* rows dropped, and it's forgotten.
|
|
12
|
-
*
|
|
13
|
-
* The rows' part is the app's (`operations` in the directory's settings);
|
|
14
|
-
* without it, a 501. Gift codes: `GET /console/codes`; `POST /console/codes`
|
|
15
|
-
* `{ amount, expires?, until?, note? }` (the code, shown this once); `POST
|
|
16
|
-
* /console/codes/revoke` `{ id }`.
|
|
17
|
-
*/
|
|
18
|
-
import { type Route } from "copilotz";
|
|
19
|
-
/** `GET /console/orgs`. */
|
|
20
|
-
export declare const consoleOrgsRoute: Route;
|
|
21
|
-
/** `/console/orgs/<id>` and `/console/orgs/<id>/<what>`: staff's operations on an org. */
|
|
22
|
-
export declare const operateRoute: Route;
|
|
23
|
-
/** `GET /console/codes` and `POST /console/codes`. */
|
|
24
|
-
export declare const codesRoute: Route;
|
|
25
|
-
/** `POST /console/codes/revoke` `{ id }`. */
|
|
26
|
-
export declare const revokeCodeRoute: Route;
|
package/routes/console.js
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Staff's console (platform staff only, by their sign-in or the email they
|
|
3
|
-
* verified; anyone else, a 403):
|
|
4
|
-
*
|
|
5
|
-
* - `GET /console/orgs`: every org, with what each last reported;
|
|
6
|
-
* - `POST /console/orgs/<id>` `{ suspended?, name? }`;
|
|
7
|
-
* - `POST /console/orgs/<id>/move` `{ schema }`: its rows to another schema
|
|
8
|
-
* (closed first, then opened there on its next use);
|
|
9
|
-
* - `GET /console/orgs/<id>/export`: its rows, as SQL, to save;
|
|
10
|
-
* - `POST /console/orgs/<id>/delete` `{ confirm: <its name> }`: closed, its
|
|
11
|
-
* rows dropped, and it's forgotten.
|
|
12
|
-
*
|
|
13
|
-
* The rows' part is the app's (`operations` in the directory's settings);
|
|
14
|
-
* without it, a 501. Gift codes: `GET /console/codes`; `POST /console/codes`
|
|
15
|
-
* `{ amount, expires?, until?, note? }` (the code, shown this once); `POST
|
|
16
|
-
* /console/codes/revoke` `{ id }`.
|
|
17
|
-
*/
|
|
18
|
-
import { failure } from "copilotz";
|
|
19
|
-
import { personIn, profileOf } from "../shared/enter.js";
|
|
20
|
-
import { json, orgsOf } from "../shared/http.js";
|
|
21
|
-
import { settingsOf } from "../shared/settings.js";
|
|
22
|
-
import { forget } from "../shared/state.js";
|
|
23
|
-
/** The staff member the directory's session is, or a 403. */
|
|
24
|
-
async function staffOnly(ctx) {
|
|
25
|
-
if (ctx.actor.kind !== "person")
|
|
26
|
-
throw failure("forbidden", "Staff only", { public: true });
|
|
27
|
-
const person = personIn(ctx);
|
|
28
|
-
const email = (await profileOf(ctx.runtime, person))?.email;
|
|
29
|
-
const { staff } = await ctx.runtime.call("org.mine", {
|
|
30
|
-
person,
|
|
31
|
-
...(email ? { email } : {}),
|
|
32
|
-
});
|
|
33
|
-
if (!staff)
|
|
34
|
-
throw failure("forbidden", "Staff only", { public: true });
|
|
35
|
-
return person;
|
|
36
|
-
}
|
|
37
|
-
const body = async (request) => await request.json().catch(() => ({}));
|
|
38
|
-
/** `GET /console/orgs`. */
|
|
39
|
-
export const consoleOrgsRoute = async (request, ctx) => {
|
|
40
|
-
if (request.method !== "GET")
|
|
41
|
-
return json({ error: "Only GET" }, 405);
|
|
42
|
-
await staffOnly(ctx);
|
|
43
|
-
return json(await ctx.runtime.call("org.list", {}));
|
|
44
|
-
};
|
|
45
|
-
/** `/console/orgs/<id>` and `/console/orgs/<id>/<what>`: staff's operations on an org. */
|
|
46
|
-
export const operateRoute = async (request, ctx) => {
|
|
47
|
-
await staffOnly(ctx);
|
|
48
|
-
const { runtime, params } = ctx;
|
|
49
|
-
const resources = runtime.describe().resources;
|
|
50
|
-
const org = decodeURIComponent(params.org);
|
|
51
|
-
const what = params.what ? decodeURIComponent(params.what) : "";
|
|
52
|
-
const info = await runtime.query("org.info", { org });
|
|
53
|
-
if (!info)
|
|
54
|
-
return json({ error: "No such org" }, 404);
|
|
55
|
-
const ops = settingsOf({ resources }).operations ?? {};
|
|
56
|
-
if (request.method === "GET" && what === "export") {
|
|
57
|
-
if (!ops.export)
|
|
58
|
-
return json({ error: "This app doesn't export orgs" }, 501);
|
|
59
|
-
return new Response(await ops.export(info), {
|
|
60
|
-
headers: {
|
|
61
|
-
"content-type": "application/sql; charset=utf-8",
|
|
62
|
-
"content-disposition": `attachment; filename="${info.id}.sql"`,
|
|
63
|
-
"cache-control": "no-store",
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
if (request.method !== "POST")
|
|
68
|
-
return json({ error: "Not found" }, 404);
|
|
69
|
-
const asked = await body(request);
|
|
70
|
-
switch (what) {
|
|
71
|
-
case "": {
|
|
72
|
-
if (typeof asked.suspended === "boolean") {
|
|
73
|
-
await runtime.call("org.suspend", { org: info.id, suspended: asked.suspended });
|
|
74
|
-
}
|
|
75
|
-
if (typeof asked.name === "string" && asked.name.trim()) {
|
|
76
|
-
await runtime.call("org.rename", { org: info.id, name: asked.name.trim() });
|
|
77
|
-
}
|
|
78
|
-
forget(resources, { org: info.id });
|
|
79
|
-
return json({ org: info.id });
|
|
80
|
-
}
|
|
81
|
-
case "move": {
|
|
82
|
-
if (!ops.move)
|
|
83
|
-
return json({ error: "This app doesn't move orgs" }, 501);
|
|
84
|
-
const to = { schema: String(asked.schema ?? "").trim() };
|
|
85
|
-
if (!/^[a-z][a-z0-9_]{0,62}$/.test(to.schema)) {
|
|
86
|
-
return json({ error: "A schema name (lowercase letters, digits, _)" }, 400);
|
|
87
|
-
}
|
|
88
|
-
if (to.schema === info.placement.schema)
|
|
89
|
-
return json({ org: info.id, placement: to });
|
|
90
|
-
// Nothing writes while its rows move: it opens again where they went.
|
|
91
|
-
await orgsOf(runtime).close(info.id);
|
|
92
|
-
await ops.move(info, to);
|
|
93
|
-
await runtime.call("org.place", { org: info.id, placement: to });
|
|
94
|
-
forget(resources, { org: info.id });
|
|
95
|
-
return json({ org: info.id, placement: to });
|
|
96
|
-
}
|
|
97
|
-
case "delete": {
|
|
98
|
-
if (!ops.drop)
|
|
99
|
-
return json({ error: "This app doesn't delete orgs" }, 501);
|
|
100
|
-
// Typing its name confirms it: nothing of it is kept.
|
|
101
|
-
if (asked.confirm !== info.name) {
|
|
102
|
-
return json({ error: "Type the org's name to delete it" }, 400);
|
|
103
|
-
}
|
|
104
|
-
await orgsOf(runtime).close(info.id);
|
|
105
|
-
await ops.drop(info);
|
|
106
|
-
await runtime.call("org.delete", { org: info.id });
|
|
107
|
-
forget(resources, { org: info.id });
|
|
108
|
-
return json({ deleted: info.id });
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
return json({ error: "Not found" }, 404);
|
|
112
|
-
};
|
|
113
|
-
/** `GET /console/codes` and `POST /console/codes`. */
|
|
114
|
-
export const codesRoute = async (request, ctx) => {
|
|
115
|
-
const person = await staffOnly(ctx);
|
|
116
|
-
if (request.method === "GET")
|
|
117
|
-
return json(await ctx.runtime.call("code.list", {}));
|
|
118
|
-
if (request.method !== "POST")
|
|
119
|
-
return json({ error: "Only GET and POST" }, 405);
|
|
120
|
-
return await ctx.runtime.call("code.create", { ...await body(request), by: person }).then((made) => json(made), (error) => json({ error: error.message }, 400));
|
|
121
|
-
};
|
|
122
|
-
/** `POST /console/codes/revoke` `{ id }`. */
|
|
123
|
-
export const revokeCodeRoute = async (request, ctx) => {
|
|
124
|
-
if (request.method !== "POST")
|
|
125
|
-
return json({ error: "Only POST" }, 405);
|
|
126
|
-
await staffOnly(ctx);
|
|
127
|
-
const { id } = await body(request);
|
|
128
|
-
return await ctx.runtime.call("code.revoke", { id }).then(() => json({}), (error) => json({ error: error.message }, 400));
|
|
129
|
-
};
|
package/routes/enter.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `POST /enter`, an org's own (under its address: `/o/<org>/enter`), which
|
|
3
|
-
* only the directory's handoff opens (see shared/enter.ts): the person it
|
|
4
|
-
* signs goes into this org. As a sign-in does: what the directory verified
|
|
5
|
-
* about them is kept (`person.set`), they join with the handoff's role the
|
|
6
|
-
* first time (`org.join`; staff who don't belong, never), and a session
|
|
7
|
-
* starts (`session.start`), set in the org's cookie (identity's `session`,
|
|
8
|
-
* which this org's runtime names `s_<org>`). A session they already hold
|
|
9
|
-
* here, as the same person and the same standing, stays. Then `{ org }`, or
|
|
10
|
-
* a redirect to the page they asked for (`to`).
|
|
11
|
-
*/
|
|
12
|
-
import type { Route } from "copilotz";
|
|
13
|
-
/** The org's `/enter`, checking handoffs with the key of `directory` (its resources). */
|
|
14
|
-
export declare const enterRoute: (directory: Record<string, Record<string, unknown>>, org: {
|
|
15
|
-
id: string;
|
|
16
|
-
name: string;
|
|
17
|
-
kind: string;
|
|
18
|
-
}) => Route;
|
package/routes/enter.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { SESSION } from "copilotz/plugins/access/contract";
|
|
2
|
-
import { json } from "../shared/http.js";
|
|
3
|
-
import { readHandoff } from "../shared/state.js";
|
|
4
|
-
/** A path on the app (never another host's): where a handoff may send the browser. */
|
|
5
|
-
const onApp = (to) => to.startsWith("/") && !to.startsWith("//") && !to.includes("\\");
|
|
6
|
-
/** The org's `/enter`, checking handoffs with the key of `directory` (its resources). */
|
|
7
|
-
export const enterRoute = (directory, org) => async (request, { runtime, cookies }) => {
|
|
8
|
-
if (request.method !== "POST")
|
|
9
|
-
return json({ error: "Only POST" }, 405);
|
|
10
|
-
const handoff = await readHandoff(directory, new URL(request.url).searchParams);
|
|
11
|
-
if (!handoff || handoff.org !== org.id) {
|
|
12
|
-
return json({ error: "Only the directory sends people in here" }, 403);
|
|
13
|
-
}
|
|
14
|
-
if (handoff.to !== undefined && !onApp(handoff.to)) {
|
|
15
|
-
return json({ error: "Not a page of the app" }, 400);
|
|
16
|
-
}
|
|
17
|
-
const { person } = handoff;
|
|
18
|
-
const staff = handoff.staff === true;
|
|
19
|
-
await runtime.call("person.set", {
|
|
20
|
-
person,
|
|
21
|
-
...(handoff.email ? { email: handoff.email } : {}),
|
|
22
|
-
...(handoff.name ? { name: handoff.name } : {}),
|
|
23
|
-
...(handoff.picture ? { picture: handoff.picture } : {}),
|
|
24
|
-
});
|
|
25
|
-
// Staff going into an org they don't belong to aren't made one of its people.
|
|
26
|
-
if (!staff || handoff.role) {
|
|
27
|
-
await runtime.call("org.join", { person, ...(handoff.role ? { role: handoff.role } : {}) });
|
|
28
|
-
}
|
|
29
|
-
const held = cookies.get(SESSION);
|
|
30
|
-
const kept = held
|
|
31
|
-
? await runtime.query("credential.actor", { secret: held }).catch(() => null)
|
|
32
|
-
: null;
|
|
33
|
-
const session = kept?.id === person && (kept.staff === true) === staff
|
|
34
|
-
? held
|
|
35
|
-
: (await runtime.call("session.start", {
|
|
36
|
-
person,
|
|
37
|
-
...(staff ? { staff: true } : {}),
|
|
38
|
-
})).session;
|
|
39
|
-
cookies.set(SESSION, session);
|
|
40
|
-
if (handoff.to) {
|
|
41
|
-
return new Response(null, {
|
|
42
|
-
status: 302,
|
|
43
|
-
headers: { location: handoff.to, "cache-control": "no-store" },
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
return json({ org: { id: org.id, name: org.name, kind: org.kind } });
|
|
47
|
-
};
|
package/routes/forward.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* What the directory hands to an org's runtime, the request untouched (its
|
|
3
|
-
* path, its body, its socket): the org's own runtime answers it (its page,
|
|
4
|
-
* its `/connect` and socket under its address, its webhooks, its routes),
|
|
5
|
-
* by the org's own `who`.
|
|
6
|
-
*
|
|
7
|
-
* - **By its address** (`/o/<org>/…`): whatever reaches an org without a
|
|
8
|
-
* browser's session (its API with a key, its webhooks, its computers), and
|
|
9
|
-
* its page's `/connect` and socket. A 404 for no such org, a 403 for a
|
|
10
|
-
* suspended one.
|
|
11
|
-
* - **By the browser's cookie** (`/*`, matched last): the org the browser is
|
|
12
|
-
* in (`org`), with its session there (`s_<org>`). A page asked for without
|
|
13
|
-
* one (signed in at the directory, but in no org yet, or its session there
|
|
14
|
-
* gone, or the org no longer theirs) goes in first: the one they were in,
|
|
15
|
-
* else their last, else their own, made now; then the same page again
|
|
16
|
-
* (302). Anything else with no org is the lobby's (the sign-in page, the
|
|
17
|
-
* app's settings), as is everything for someone signed in nowhere.
|
|
18
|
-
* - **Hosts orgs claimed** (`*` for every host but the app's own, which the
|
|
19
|
-
* app names: `resources.hosts`): the org that claimed it, for its
|
|
20
|
-
* routes by host alone (its runtime has the app's hosts too); a host
|
|
21
|
-
* nobody claimed, a 404.
|
|
22
|
-
* - `GET /__copilotz/hosts/resolve?host=<h>`: whose a host is, `{ org,
|
|
23
|
-
* target? }` (or 404), for the app's front alone (it carries the front's
|
|
24
|
-
* secret, `resources.caller.front`), on any host: the front sends a host
|
|
25
|
-
* with a target (an app's service) straight there.
|
|
26
|
-
*/
|
|
27
|
-
import { type Route } from "copilotz";
|
|
28
|
-
/** `/o/<org>` and `/o/<org>/…`: that org, by its address. */
|
|
29
|
-
export declare const addressedRoute: Route;
|
|
30
|
-
/** `/*`: the org the browser is in, going in first when a page needs it to. */
|
|
31
|
-
export declare const currentRoute: Route;
|
|
32
|
-
/** `GET /__copilotz/hosts/resolve?host=`: whose a host is, for the front alone. */
|
|
33
|
-
export declare const resolveRoute: Route;
|
|
34
|
-
/** Every host but the app's own: the org that claimed it, its routes by host alone. */
|
|
35
|
-
export declare const claimedRoute: Route;
|
package/routes/forward.js
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* What the directory hands to an org's runtime, the request untouched (its
|
|
3
|
-
* path, its body, its socket): the org's own runtime answers it (its page,
|
|
4
|
-
* its `/connect` and socket under its address, its webhooks, its routes),
|
|
5
|
-
* by the org's own `who`.
|
|
6
|
-
*
|
|
7
|
-
* - **By its address** (`/o/<org>/…`): whatever reaches an org without a
|
|
8
|
-
* browser's session (its API with a key, its webhooks, its computers), and
|
|
9
|
-
* its page's `/connect` and socket. A 404 for no such org, a 403 for a
|
|
10
|
-
* suspended one.
|
|
11
|
-
* - **By the browser's cookie** (`/*`, matched last): the org the browser is
|
|
12
|
-
* in (`org`), with its session there (`s_<org>`). A page asked for without
|
|
13
|
-
* one (signed in at the directory, but in no org yet, or its session there
|
|
14
|
-
* gone, or the org no longer theirs) goes in first: the one they were in,
|
|
15
|
-
* else their last, else their own, made now; then the same page again
|
|
16
|
-
* (302). Anything else with no org is the lobby's (the sign-in page, the
|
|
17
|
-
* app's settings), as is everything for someone signed in nowhere.
|
|
18
|
-
* - **Hosts orgs claimed** (`*` for every host but the app's own, which the
|
|
19
|
-
* app names: `resources.hosts`): the org that claimed it, for its
|
|
20
|
-
* routes by host alone (its runtime has the app's hosts too); a host
|
|
21
|
-
* nobody claimed, a 404.
|
|
22
|
-
* - `GET /__copilotz/hosts/resolve?host=<h>`: whose a host is, `{ org,
|
|
23
|
-
* target? }` (or 404), for the app's front alone (it carries the front's
|
|
24
|
-
* secret, `resources.caller.front`), on any host: the front sends a host
|
|
25
|
-
* with a target (an app's service) straight there.
|
|
26
|
-
*/
|
|
27
|
-
import { failure, vouched } from "copilotz";
|
|
28
|
-
import { enter, landing, personIn, profileOf, report } from "../shared/enter.js";
|
|
29
|
-
import { CURRENT, json, navigating, orgCookie, orgsOf, RESOLVE } from "../shared/http.js";
|
|
30
|
-
import { settingsOf } from "../shared/settings.js";
|
|
31
|
-
import { claimOf, infoOf } from "../shared/state.js";
|
|
32
|
-
/** The request, answered by an org's runtime, open for it: as it came. */
|
|
33
|
-
async function into(dir, org, request) {
|
|
34
|
-
const runtime = await orgsOf(dir).get(org);
|
|
35
|
-
if (!runtime)
|
|
36
|
-
return json({ error: "No such org" }, 404);
|
|
37
|
-
report(dir, org, runtime);
|
|
38
|
-
return await runtime.fetch(request);
|
|
39
|
-
}
|
|
40
|
-
/** What answers someone signed in nowhere: the lobby the app gives (its sign-in page). */
|
|
41
|
-
async function lobby(dir, request) {
|
|
42
|
-
const given = settingsOf({ resources: dir.describe().resources }).lobby;
|
|
43
|
-
return given ? await given.fetch(request) : json({ error: "Not signed in" }, 401);
|
|
44
|
-
}
|
|
45
|
-
/** `/o/<org>` and `/o/<org>/…`: that org, by its address. */
|
|
46
|
-
export const addressedRoute = async (request, { runtime, params }) => {
|
|
47
|
-
const org = decodeURIComponent(params.org);
|
|
48
|
-
const info = await infoOf(runtime, runtime.describe().resources, org);
|
|
49
|
-
if (!info)
|
|
50
|
-
return json({ error: "No such org" }, 404);
|
|
51
|
-
if (info.suspended)
|
|
52
|
-
return json({ error: "This org is suspended." }, 403);
|
|
53
|
-
return await into(runtime, info.id, request);
|
|
54
|
-
};
|
|
55
|
-
/** `/*`: the org the browser is in, going in first when a page needs it to. */
|
|
56
|
-
export const currentRoute = async (request, ctx) => {
|
|
57
|
-
const { runtime, cookies } = ctx;
|
|
58
|
-
const resources = runtime.describe().resources;
|
|
59
|
-
const page = navigating(request);
|
|
60
|
-
const org = cookies.get(CURRENT);
|
|
61
|
-
const name = org ? orgCookie(org) : undefined;
|
|
62
|
-
const held = name ? cookies.get(name) : undefined;
|
|
63
|
-
const info = org && held ? await infoOf(runtime, resources, org) : null;
|
|
64
|
-
if (info && !info.suspended) {
|
|
65
|
-
// A page goes on only with a session that's still someone there.
|
|
66
|
-
const open = page ? await orgsOf(runtime).get(info.id) : undefined;
|
|
67
|
-
const good = !page ||
|
|
68
|
-
!!await open?.query("credential.actor", { secret: held }).catch(() => null);
|
|
69
|
-
if (good)
|
|
70
|
-
return await into(runtime, info.id, request);
|
|
71
|
-
}
|
|
72
|
-
else if (info && !page) {
|
|
73
|
-
return json({ error: "This org is suspended." }, 403);
|
|
74
|
-
}
|
|
75
|
-
if (ctx.actor.kind !== "person" || !page)
|
|
76
|
-
return await lobby(runtime, request);
|
|
77
|
-
// A page, for someone signed in at the directory: in the org they were in, else one that's theirs.
|
|
78
|
-
const person = personIn(ctx);
|
|
79
|
-
const profile = await profileOf(runtime, person);
|
|
80
|
-
const called = profile?.name ?? profile?.email ?? person;
|
|
81
|
-
const url = new URL(request.url);
|
|
82
|
-
const to = url.pathname + url.search;
|
|
83
|
-
const first = org && !info?.suspended ? org : await landing(runtime, person, called, org);
|
|
84
|
-
try {
|
|
85
|
-
return await enter(request, ctx, first, { to });
|
|
86
|
-
}
|
|
87
|
-
catch (error) {
|
|
88
|
-
if (error.code !== "forbidden")
|
|
89
|
-
throw error;
|
|
90
|
-
return await enter(request, ctx, await landing(runtime, person, called, first), { to });
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
/** `GET /__copilotz/hosts/resolve?host=`: whose a host is, for the front alone. */
|
|
94
|
-
export const resolveRoute = async (request, { runtime }) => {
|
|
95
|
-
if (request.method !== "GET")
|
|
96
|
-
return json({ error: "Only GET" }, 405);
|
|
97
|
-
const resources = runtime.describe().resources;
|
|
98
|
-
const front = resources.caller?.front;
|
|
99
|
-
if (!vouched(request, front))
|
|
100
|
-
return json({ error: "The front's only" }, 403);
|
|
101
|
-
const host = new URL(request.url).searchParams.get("host") ?? "";
|
|
102
|
-
const claim = await claimOf(runtime, resources, host);
|
|
103
|
-
return claim ? json(claim) : json({ error: "Nobody's host" }, 404);
|
|
104
|
-
};
|
|
105
|
-
/** Every host but the app's own: the org that claimed it, its routes by host alone. */
|
|
106
|
-
export const claimedRoute = async (request, ctx) => {
|
|
107
|
-
const { runtime } = ctx;
|
|
108
|
-
const url = new URL(request.url);
|
|
109
|
-
if (url.pathname === RESOLVE)
|
|
110
|
-
return await resolveRoute(request, ctx);
|
|
111
|
-
const resources = runtime.describe().resources;
|
|
112
|
-
const claim = await claimOf(runtime, resources, url.host);
|
|
113
|
-
const info = claim ? await infoOf(runtime, resources, claim.org) : null;
|
|
114
|
-
if (!info)
|
|
115
|
-
return json({ error: "Not found" }, 404);
|
|
116
|
-
if (info.suspended)
|
|
117
|
-
throw failure("forbidden", "This org is suspended.", { public: true });
|
|
118
|
-
return await into(runtime, info.id, request);
|
|
119
|
-
};
|
package/routes/orgs.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The orgs of whoever the directory's session is (each a 401 for anyone
|
|
3
|
-
* else; what goes wrong answers its code's status, its words only when
|
|
4
|
-
* they're for anyone):
|
|
5
|
-
*
|
|
6
|
-
* - `GET /orgs`: who's signed in, the org they're in (`current`), the orgs
|
|
7
|
-
* they belong to (the last entered first), the invitations waiting for
|
|
8
|
-
* their email, whether they're platform staff, and whether the session
|
|
9
|
-
* they hold in the org they're in is staff's (`asStaff`);
|
|
10
|
-
* - `POST /orgs` `{ name }`: makes a team org, its maker its owner, and
|
|
11
|
-
* goes into it;
|
|
12
|
-
* - `POST /orgs/enter` `{ org, staff? }`: goes into another (staff into any,
|
|
13
|
-
* as staff when they ask: `staff: true`);
|
|
14
|
-
* - `POST /orgs/invites/answer` `{ invite, accept }`: joins its org (and
|
|
15
|
-
* goes into it) or declines (`{ joined: false }`).
|
|
16
|
-
*
|
|
17
|
-
* Going into an org answers `{ org }`, with its cookies (see shared/enter.ts).
|
|
18
|
-
*/
|
|
19
|
-
import { type Route } from "copilotz";
|
|
20
|
-
/** `GET /orgs` and `POST /orgs`. */
|
|
21
|
-
export declare const orgsRoute: Route;
|
|
22
|
-
/** `POST /orgs/enter` `{ org, staff? }`. */
|
|
23
|
-
export declare const enterOrgRoute: Route;
|
|
24
|
-
/** `POST /orgs/invites/answer` `{ invite, accept }`. */
|
|
25
|
-
export declare const answerInviteRoute: Route;
|