@pairz/directory 1.0.0-rc.81 → 1.0.0-rc.82
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/actions/host.d.ts +1 -0
- package/actions/host.js +43 -8
- package/actions/invite.js +1 -1
- package/collections/invite.d.ts +3 -3
- package/collections/invite.js +1 -1
- package/collections/org-host.d.ts +19 -2
- package/collections/org-host.js +19 -4
- package/mod.d.ts +3 -1
- package/mod.js +5 -2
- package/package.json +2 -2
- package/shared/member.d.ts +1 -1
- package/shared/member.js +21 -1
- package/shared/state.d.ts +2 -1
- package/shared/state.js +7 -1
package/actions/host.d.ts
CHANGED
package/actions/host.js
CHANGED
|
@@ -4,18 +4,34 @@
|
|
|
4
4
|
* shared/member.ts). The system's: `member` has checked the host isn't the
|
|
5
5
|
* app's own.
|
|
6
6
|
*
|
|
7
|
-
* - `host.claim` `{ org, host, target? }`: the host is the org's
|
|
8
|
-
* its target changes); refused when it's another org's
|
|
9
|
-
*
|
|
7
|
+
* - `host.claim` `{ org, host, target?, preview? }`: the host is the org's
|
|
8
|
+
* (again: its target changes); refused when it's another org's. A name,
|
|
9
|
+
* `<name>.*`, claims that first label on every domain (see
|
|
10
|
+
* collections/org-host.ts);
|
|
11
|
+
* - `host.release` `{ org, host }`: it's no longer the org's (if it was);
|
|
12
|
+
* - `host.free` `{ org, host }`: whether the org may claim it (nobody's, or
|
|
13
|
+
* its own already).
|
|
10
14
|
*/
|
|
11
15
|
import { defineAction, forbidden } from "pairz";
|
|
12
|
-
/**
|
|
13
|
-
|
|
16
|
+
/**
|
|
17
|
+
* A host, as claims keep it: lowercase letters, digits, dots and hyphens,
|
|
18
|
+
* and a port maybe; or a name, `<label>.*`.
|
|
19
|
+
*/
|
|
20
|
+
const host = {
|
|
21
|
+
type: "string",
|
|
22
|
+
pattern: "^([a-z0-9.-]+(:[0-9]{1,5})?|[a-z0-9-]+\\.\\*)$",
|
|
23
|
+
maxLength: 253,
|
|
24
|
+
};
|
|
14
25
|
export const claimHostAction = defineAction({
|
|
15
26
|
description: "Makes a host an org's (its requests go to the org's routes, or to a target)",
|
|
16
27
|
input: {
|
|
17
28
|
type: "object",
|
|
18
|
-
properties: {
|
|
29
|
+
properties: {
|
|
30
|
+
org: { type: "string" },
|
|
31
|
+
host,
|
|
32
|
+
target: { type: "string" },
|
|
33
|
+
preview: { type: "string" },
|
|
34
|
+
},
|
|
19
35
|
required: ["org", "host"],
|
|
20
36
|
additionalProperties: false,
|
|
21
37
|
},
|
|
@@ -24,16 +40,22 @@ export const claimHostAction = defineAction({
|
|
|
24
40
|
const had = await hosts.findOne({ _id: input.host });
|
|
25
41
|
if (had && had.org !== input.org)
|
|
26
42
|
throw forbidden(`${input.host} is another org's.`);
|
|
43
|
+
const kept = {
|
|
44
|
+
...(input.target ? { target: input.target } : {}),
|
|
45
|
+
...(input.preview ? { preview: input.preview } : {}),
|
|
46
|
+
};
|
|
27
47
|
if (had) {
|
|
48
|
+
const gone = Object.fromEntries(["target", "preview"].filter((k) => !(k in kept)).map((k) => [k, ""]));
|
|
28
49
|
await hosts.updateOne({ _id: input.host }, {
|
|
29
|
-
...(
|
|
50
|
+
...(Object.keys(kept).length ? { $set: kept } : {}),
|
|
51
|
+
...(Object.keys(gone).length ? { $unset: gone } : {}),
|
|
30
52
|
});
|
|
31
53
|
}
|
|
32
54
|
else {
|
|
33
55
|
await hosts.insertOne({
|
|
34
56
|
_id: input.host,
|
|
35
57
|
org: input.org,
|
|
36
|
-
...
|
|
58
|
+
...kept,
|
|
37
59
|
at: new Date().toISOString(),
|
|
38
60
|
});
|
|
39
61
|
}
|
|
@@ -53,3 +75,16 @@ export const releaseHostAction = defineAction({
|
|
|
53
75
|
return { released: gone.deletedCount > 0 };
|
|
54
76
|
},
|
|
55
77
|
});
|
|
78
|
+
export const freeHostAction = defineAction({
|
|
79
|
+
description: "Whether an org may claim a host: nobody's, or its own already",
|
|
80
|
+
input: {
|
|
81
|
+
type: "object",
|
|
82
|
+
properties: { org: { type: "string" }, host },
|
|
83
|
+
required: ["org", "host"],
|
|
84
|
+
additionalProperties: false,
|
|
85
|
+
},
|
|
86
|
+
run: async (ctx, input) => {
|
|
87
|
+
const had = await ctx.db.collection("orgHost").findOne({ _id: input.host });
|
|
88
|
+
return { free: !had || had.org === input.org };
|
|
89
|
+
},
|
|
90
|
+
});
|
package/actions/invite.js
CHANGED
|
@@ -12,7 +12,7 @@ export const sendInviteAction = defineAction({
|
|
|
12
12
|
properties: {
|
|
13
13
|
org: { type: "string" },
|
|
14
14
|
email: { type: "string", pattern: "^[^@\\s]+@[^@\\s]+$" },
|
|
15
|
-
role: { type: "string", enum: ["admin", "member", "guest"] },
|
|
15
|
+
role: { type: "string", enum: ["admin", "finance", "member", "guest"] },
|
|
16
16
|
by: { type: "string" },
|
|
17
17
|
from: { type: "string" },
|
|
18
18
|
},
|
package/collections/invite.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ declare const inviteSchema: {
|
|
|
15
15
|
};
|
|
16
16
|
readonly role: {
|
|
17
17
|
readonly type: "string";
|
|
18
|
-
readonly enum: readonly ["admin", "member", "guest"];
|
|
18
|
+
readonly enum: readonly ["admin", "finance", "member", "guest"];
|
|
19
19
|
};
|
|
20
20
|
/** Who sent it, and their name, for the invited to see. */
|
|
21
21
|
readonly by: {
|
|
@@ -37,7 +37,7 @@ export declare const invite: Omit<import("pairz").CollectionDef, "queries" | "sc
|
|
|
37
37
|
at: string;
|
|
38
38
|
org: string;
|
|
39
39
|
email: string;
|
|
40
|
-
role: "admin" | "member" | "guest";
|
|
40
|
+
role: "admin" | "finance" | "member" | "guest";
|
|
41
41
|
by: string;
|
|
42
42
|
}>>> | undefined;
|
|
43
43
|
} & {
|
|
@@ -52,7 +52,7 @@ export declare const invite: Omit<import("pairz").CollectionDef, "queries" | "sc
|
|
|
52
52
|
};
|
|
53
53
|
readonly role: {
|
|
54
54
|
readonly type: "string";
|
|
55
|
-
readonly enum: readonly ["admin", "member", "guest"];
|
|
55
|
+
readonly enum: readonly ["admin", "finance", "member", "guest"];
|
|
56
56
|
};
|
|
57
57
|
/** Who sent it, and their name, for the invited to see. */
|
|
58
58
|
readonly by: {
|
package/collections/invite.js
CHANGED
|
@@ -9,7 +9,7 @@ const inviteSchema = {
|
|
|
9
9
|
properties: {
|
|
10
10
|
org: { type: "string" },
|
|
11
11
|
email: { type: "string" },
|
|
12
|
-
role: { type: "string", enum: ["admin", "member", "guest"] },
|
|
12
|
+
role: { type: "string", enum: ["admin", "finance", "member", "guest"] },
|
|
13
13
|
/** Who sent it, and their name, for the invited to see. */
|
|
14
14
|
by: { type: "string" },
|
|
15
15
|
from: { type: "string" },
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Hosts orgs claimed (`
|
|
3
|
-
*
|
|
2
|
+
* Hosts orgs claimed (`shop.example.com`, an app's own): the directory
|
|
3
|
+
* hands a request to one to that org's routes by host (see
|
|
4
4
|
* routes/forward.ts), and the app's front sends it straight to `target`
|
|
5
5
|
* when there's one (an app running elsewhere: its Cloud Run URL). A host is
|
|
6
6
|
* one org's at a time.
|
|
7
|
+
*
|
|
8
|
+
* A name (`<name>.*`, its `_id`) is a host's first label on whichever
|
|
9
|
+
* domain: `shop` claims `shop.pairz.app` and `shop.copilotz.app` at once
|
|
10
|
+
* (a name published on every publish domain, a preview's label on every
|
|
11
|
+
* preview domain), so the domains can change without claiming again. A
|
|
12
|
+
* host's own claim comes first; the org's runtime checks the domain.
|
|
7
13
|
*/
|
|
8
14
|
import { type Infer } from "pairz";
|
|
9
15
|
declare const orgHostSchema: {
|
|
@@ -17,6 +23,10 @@ declare const orgHostSchema: {
|
|
|
17
23
|
readonly target: {
|
|
18
24
|
readonly type: "string";
|
|
19
25
|
};
|
|
26
|
+
/** What it serves in the org (a preview's label), for whoever reads the claims. */
|
|
27
|
+
readonly preview: {
|
|
28
|
+
readonly type: "string";
|
|
29
|
+
};
|
|
20
30
|
readonly at: {
|
|
21
31
|
readonly type: "string";
|
|
22
32
|
};
|
|
@@ -27,6 +37,7 @@ export declare const orgHost: Omit<import("pairz").CollectionDef, "queries" | "s
|
|
|
27
37
|
queries?: Record<string, import("pairz").QueryDef<import("pairz").WithId<{
|
|
28
38
|
[x: string]: unknown;
|
|
29
39
|
target?: string | undefined;
|
|
40
|
+
preview?: string | undefined;
|
|
30
41
|
at: string;
|
|
31
42
|
org: string;
|
|
32
43
|
}>>> | undefined;
|
|
@@ -42,6 +53,10 @@ export declare const orgHost: Omit<import("pairz").CollectionDef, "queries" | "s
|
|
|
42
53
|
readonly target: {
|
|
43
54
|
readonly type: "string";
|
|
44
55
|
};
|
|
56
|
+
/** What it serves in the org (a preview's label), for whoever reads the claims. */
|
|
57
|
+
readonly preview: {
|
|
58
|
+
readonly type: "string";
|
|
59
|
+
};
|
|
45
60
|
readonly at: {
|
|
46
61
|
readonly type: "string";
|
|
47
62
|
};
|
|
@@ -52,4 +67,6 @@ export declare const orgHost: Omit<import("pairz").CollectionDef, "queries" | "s
|
|
|
52
67
|
export type OrgHost = Infer<typeof orgHostSchema> & {
|
|
53
68
|
_id: string;
|
|
54
69
|
};
|
|
70
|
+
/** A host's first label, as a name's claim keeps it: `shop.pairz.app` is `shop.*`. */
|
|
71
|
+
export declare const nameOf: (host: string) => string;
|
|
55
72
|
export {};
|
package/collections/org-host.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Hosts orgs claimed (`
|
|
3
|
-
*
|
|
2
|
+
* Hosts orgs claimed (`shop.example.com`, an app's own): the directory
|
|
3
|
+
* hands a request to one to that org's routes by host (see
|
|
4
4
|
* routes/forward.ts), and the app's front sends it straight to `target`
|
|
5
5
|
* when there's one (an app running elsewhere: its Cloud Run URL). A host is
|
|
6
6
|
* one org's at a time.
|
|
7
|
+
*
|
|
8
|
+
* A name (`<name>.*`, its `_id`) is a host's first label on whichever
|
|
9
|
+
* domain: `shop` claims `shop.pairz.app` and `shop.copilotz.app` at once
|
|
10
|
+
* (a name published on every publish domain, a preview's label on every
|
|
11
|
+
* preview domain), so the domains can change without claiming again. A
|
|
12
|
+
* host's own claim comes first; the org's runtime checks the domain.
|
|
7
13
|
*/
|
|
8
14
|
import { defineCollection } from "pairz";
|
|
9
15
|
const orgHostSchema = {
|
|
@@ -13,6 +19,8 @@ const orgHostSchema = {
|
|
|
13
19
|
org: { type: "string" },
|
|
14
20
|
/** Where the front sends its requests, rather than to the app. */
|
|
15
21
|
target: { type: "string" },
|
|
22
|
+
/** What it serves in the org (a preview's label), for whoever reads the claims. */
|
|
23
|
+
preview: { type: "string" },
|
|
16
24
|
at: { type: "string" },
|
|
17
25
|
},
|
|
18
26
|
required: ["org", "at"],
|
|
@@ -21,10 +29,17 @@ export const orgHost = defineCollection({
|
|
|
21
29
|
schema: orgHostSchema,
|
|
22
30
|
indexes: [["org"]],
|
|
23
31
|
queries: {
|
|
24
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
* Whose a host is, and where its requests go: `{ org, target? }`, or
|
|
34
|
+
* null. Its own claim, else its first label's name. The system's.
|
|
35
|
+
*/
|
|
25
36
|
resolve: async (hosts, params) => {
|
|
26
|
-
const
|
|
37
|
+
const host = String(params.host ?? "").toLowerCase();
|
|
38
|
+
const found = await hosts.findOne({ _id: host }) ??
|
|
39
|
+
(/^[^.*]+\.[^*]/.test(host) ? await hosts.findOne({ _id: nameOf(host) }) : null);
|
|
27
40
|
return found ? { org: found.org, ...(found.target ? { target: found.target } : {}) } : null;
|
|
28
41
|
},
|
|
29
42
|
},
|
|
30
43
|
});
|
|
44
|
+
/** A host's first label, as a name's claim keeps it: `shop.pairz.app` is `shop.*`. */
|
|
45
|
+
export const nameOf = (host) => `${host.split(".")[0]}.*`;
|
package/mod.d.ts
CHANGED
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
* sign in, in front of every org's. It knows who signs in (the identity
|
|
5
5
|
* plugin's people, by their sign-in method), which orgs each belongs to,
|
|
6
6
|
* invitations to orgs by email, where each org lives, the hosts orgs claimed
|
|
7
|
-
* (a
|
|
7
|
+
* (a custom domain, an app's; or a name, a first label on every domain: a
|
|
8
|
+
* published app's, a preview's; `orgHost.resolve` says whose), and
|
|
9
|
+
* platform staff.
|
|
8
10
|
* An org's own data (its people's roles, spaces, conversations) lives in the
|
|
9
11
|
* org: each is a runtime of its own, opened on its first use and closed when
|
|
10
12
|
* idle (the app's `runtimes(open)`, in `directory.orgs`), with
|
package/mod.js
CHANGED
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
* sign in, in front of every org's. It knows who signs in (the identity
|
|
5
5
|
* plugin's people, by their sign-in method), which orgs each belongs to,
|
|
6
6
|
* invitations to orgs by email, where each org lives, the hosts orgs claimed
|
|
7
|
-
* (a
|
|
7
|
+
* (a custom domain, an app's; or a name, a first label on every domain: a
|
|
8
|
+
* published app's, a preview's; `orgHost.resolve` says whose), and
|
|
9
|
+
* platform staff.
|
|
8
10
|
* An org's own data (its people's roles, spaces, conversations) lives in the
|
|
9
11
|
* org: each is a runtime of its own, opened on its first use and closed when
|
|
10
12
|
* idle (the app's `runtimes(open)`, in `directory.orgs`), with
|
|
@@ -57,7 +59,7 @@ import { RESOLVE, RESOLVE_BEFORE } from "./shared/http.js";
|
|
|
57
59
|
import { member } from "./shared/member.js";
|
|
58
60
|
import { createOrgAction, deleteOrgAction, enterOrgAction, leaveOrgAction, listOrgsAction, myOrgsAction, placeOrgAction, renameOrgAction, reportOrgAction, suspendOrgAction, } from "./actions/org.js";
|
|
59
61
|
import { answerInviteAction, cancelInviteAction, myInvitesAction, orgInvitesAction, sendInviteAction, } from "./actions/invite.js";
|
|
60
|
-
import { claimHostAction, releaseHostAction } from "./actions/host.js";
|
|
62
|
+
import { claimHostAction, freeHostAction, releaseHostAction } from "./actions/host.js";
|
|
61
63
|
import { claimCodeAction, createCodeAction, listCodesAction, revokeCodeAction, } from "./actions/code.js";
|
|
62
64
|
import { creditCode } from "./collections/credit-code.js";
|
|
63
65
|
import { invite } from "./collections/invite.js";
|
|
@@ -87,6 +89,7 @@ const plugin = definePlugin({
|
|
|
87
89
|
"invite.cancel": cancelInviteAction,
|
|
88
90
|
"host.claim": claimHostAction,
|
|
89
91
|
"host.release": releaseHostAction,
|
|
92
|
+
"host.free": freeHostAction,
|
|
90
93
|
"code.create": createCodeAction,
|
|
91
94
|
"code.claim": claimCodeAction,
|
|
92
95
|
"code.list": listCodesAction,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pairz/directory",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.82",
|
|
4
4
|
"description": "Many orgs behind one address: who signs in, which orgs they belong to, and going between them. A Pairz plugin.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pairz",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"dependencies": {},
|
|
57
57
|
"peerDependencies": {
|
|
58
58
|
"@types/react": "^19.3.0",
|
|
59
|
-
"pairz": "1.0.0-rc.
|
|
59
|
+
"pairz": "1.0.0-rc.82",
|
|
60
60
|
"react": "^19.3.1"
|
|
61
61
|
},
|
|
62
62
|
"peerDependenciesMeta": {
|
package/shared/member.d.ts
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* - **The app's own hosts** (`resources.hosts`, the directory's): a host an
|
|
12
12
|
* org claimed reaches only its host routes.
|
|
13
13
|
* - **How it reaches the directory** (`resources.directory`): invitations,
|
|
14
|
-
* who leaves, its name, the hosts it claims, and gift codes.
|
|
14
|
+
* who leaves, its name, the hosts and names it claims, and gift codes.
|
|
15
15
|
* - **Its `/enter`**, which only the directory's handoff opens (see
|
|
16
16
|
* routes/enter.ts).
|
|
17
17
|
*/
|
package/shared/member.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* - **The app's own hosts** (`resources.hosts`, the directory's): a host an
|
|
12
12
|
* org claimed reaches only its host routes.
|
|
13
13
|
* - **How it reaches the directory** (`resources.directory`): invitations,
|
|
14
|
-
* who leaves, its name, the hosts it claims, and gift codes.
|
|
14
|
+
* who leaves, its name, the hosts and names it claims, and gift codes.
|
|
15
15
|
* - **Its `/enter`**, which only the directory's handoff opens (see
|
|
16
16
|
* routes/enter.ts).
|
|
17
17
|
*/
|
|
@@ -62,6 +62,26 @@ export function member(dir, org) {
|
|
|
62
62
|
await ask("host.release", { host: name });
|
|
63
63
|
forget(resources, { host: name });
|
|
64
64
|
},
|
|
65
|
+
/**
|
|
66
|
+
* Makes a name the org's: a host's first label, on every domain
|
|
67
|
+
* (`shop` for `shop.pairz.app` and `shop.copilotz.app`), its requests
|
|
68
|
+
* its routes' by host; one across the whole app. Refused when it's
|
|
69
|
+
* another org's.
|
|
70
|
+
*/
|
|
71
|
+
claimName: async (name, claim = {}) => {
|
|
72
|
+
await ask("host.claim", {
|
|
73
|
+
host: `${name}.*`,
|
|
74
|
+
...(claim.preview ? { preview: claim.preview } : {}),
|
|
75
|
+
});
|
|
76
|
+
forget(resources, { name });
|
|
77
|
+
},
|
|
78
|
+
/** The name is no longer the org's. */
|
|
79
|
+
releaseName: async (name) => {
|
|
80
|
+
await ask("host.release", { host: `${name}.*` });
|
|
81
|
+
forget(resources, { name });
|
|
82
|
+
},
|
|
83
|
+
/** Whether the org may claim a name: nobody's, or its own already. */
|
|
84
|
+
nameFree: (name) => ask("host.free", { host: `${name}.*` }).then((r) => r.free),
|
|
65
85
|
/** A gift code's credits, for this org. */
|
|
66
86
|
claimCode: (code, person) => ask("code.claim", {
|
|
67
87
|
code,
|
package/shared/state.d.ts
CHANGED
|
@@ -46,10 +46,11 @@ export declare const infoOf: (dir: Asks, resources: Resources, org: string) => P
|
|
|
46
46
|
export declare const plainHost: (host: string) => string;
|
|
47
47
|
/** Whose a host is, kept a minute. */
|
|
48
48
|
export declare const claimOf: (dir: Asks, resources: Resources, host: string) => Promise<Claim | null>;
|
|
49
|
-
/** Forgets what's kept of an org, or
|
|
49
|
+
/** Forgets what's kept of an org, a host, or a name (every host it's the first label of) here: it just changed. */
|
|
50
50
|
export declare function forget(resources: Resources, what: {
|
|
51
51
|
org?: string;
|
|
52
52
|
host?: string;
|
|
53
|
+
name?: string;
|
|
53
54
|
}): void;
|
|
54
55
|
/** Who goes into an org: what the directory signs, and the org's `/enter` reads. */
|
|
55
56
|
export type Handoff = {
|
package/shared/state.js
CHANGED
|
@@ -55,13 +55,19 @@ export const infoOf = (dir, resources, org) => kept(stateOf(resources).info, org
|
|
|
55
55
|
export const plainHost = (host) => String(host ?? "").trim().toLowerCase().replace(/\.$/, "");
|
|
56
56
|
/** Whose a host is, kept a minute. */
|
|
57
57
|
export const claimOf = (dir, resources, host) => kept(stateOf(resources).claims, plainHost(host), CLAIMS_MS, () => dir.query("orgHost.resolve", { host: plainHost(host) }));
|
|
58
|
-
/** Forgets what's kept of an org, or
|
|
58
|
+
/** Forgets what's kept of an org, a host, or a name (every host it's the first label of) here: it just changed. */
|
|
59
59
|
export function forget(resources, what) {
|
|
60
60
|
const state = stateOf(resources);
|
|
61
61
|
if (what.org !== undefined)
|
|
62
62
|
state.info.delete(what.org);
|
|
63
63
|
if (what.host !== undefined)
|
|
64
64
|
state.claims.delete(plainHost(what.host));
|
|
65
|
+
if (what.name !== undefined) {
|
|
66
|
+
for (const host of state.claims.keys()) {
|
|
67
|
+
if (host.split(".")[0] === what.name)
|
|
68
|
+
state.claims.delete(host);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
65
71
|
}
|
|
66
72
|
/** A handoff, signed: the query of the org's `/enter`. */
|
|
67
73
|
export async function signHandoff(resources, handoff) {
|