@pairz/directory 0.0.1 → 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/LICENSE +21 -0
- package/README.md +70 -1
- package/WORDS.md +198 -0
- package/actions/code.d.ts +4 -0
- package/actions/code.js +135 -0
- package/actions/host.d.ts +3 -0
- package/actions/host.js +90 -0
- package/actions/invite.d.ts +5 -0
- package/actions/invite.js +129 -0
- package/actions/org.d.ts +10 -0
- package/actions/org.js +273 -0
- package/collections/credit-code.d.ts +107 -0
- package/collections/credit-code.js +28 -0
- package/collections/invite.d.ts +74 -0
- package/collections/invite.js +20 -0
- package/collections/membership.d.ts +65 -0
- package/collections/membership.js +22 -0
- package/collections/org-host.d.ts +72 -0
- package/collections/org-host.js +45 -0
- package/collections/org.d.ts +134 -0
- package/collections/org.js +58 -0
- package/collections/staff.d.ts +35 -0
- package/collections/staff.js +12 -0
- package/contract.d.ts +8 -0
- package/contract.js +8 -0
- package/mod.d.ts +69 -0
- package/mod.js +126 -0
- package/package.json +63 -3
- package/routes/console.d.ts +26 -0
- package/routes/console.js +129 -0
- package/routes/enter.d.ts +18 -0
- package/routes/enter.js +47 -0
- package/routes/forward.d.ts +35 -0
- package/routes/forward.js +120 -0
- package/routes/orgs.d.ts +25 -0
- package/routes/orgs.js +113 -0
- package/routes/signout.d.ts +11 -0
- package/routes/signout.js +36 -0
- package/shared/enter.d.ts +36 -0
- package/shared/enter.js +82 -0
- package/shared/http.d.ts +44 -0
- package/shared/http.js +79 -0
- package/shared/member.d.ts +21 -0
- package/shared/member.js +93 -0
- package/shared/settings.d.ts +53 -0
- package/shared/settings.js +16 -0
- package/shared/state.d.ts +75 -0
- package/shared/state.js +107 -0
- package/views/web/codes.d.ts +27 -0
- package/views/web/codes.js +50 -0
- package/views/web/console-codes.d.ts +37 -0
- package/views/web/console-codes.js +166 -0
- package/views/web/console.d.ts +37 -0
- package/views/web/console.js +224 -0
- package/views/web/lists.d.ts +48 -0
- package/views/web/lists.js +42 -0
- package/views/web/org.d.ts +12 -0
- package/views/web/org.js +62 -0
- package/views/web/orgs.d.ts +148 -0
- package/views/web/orgs.js +253 -0
- package/views/web/style.d.ts +6 -0
- package/views/web/style.js +197 -0
- package/views/web/switcher.d.ts +81 -0
- package/views/web/switcher.js +367 -0
- package/views/web/words.d.ts +10 -0
- package/views/web/words.js +206 -0
- package/web.d.ts +36 -0
- package/web.js +57 -0
package/actions/org.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const createOrgAction: import("pairz").ActionDef;
|
|
2
|
+
export declare const myOrgsAction: import("pairz").ActionDef;
|
|
3
|
+
export declare const enterOrgAction: import("pairz").ActionDef;
|
|
4
|
+
export declare const leaveOrgAction: import("pairz").ActionDef;
|
|
5
|
+
export declare const renameOrgAction: import("pairz").ActionDef;
|
|
6
|
+
export declare const suspendOrgAction: import("pairz").ActionDef;
|
|
7
|
+
export declare const reportOrgAction: import("pairz").ActionDef;
|
|
8
|
+
export declare const listOrgsAction: import("pairz").ActionDef;
|
|
9
|
+
export declare const placeOrgAction: import("pairz").ActionDef;
|
|
10
|
+
export declare const deleteOrgAction: import("pairz").ActionDef;
|
package/actions/org.js
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Orgs and who belongs: what the directory's routes ask as people sign in,
|
|
3
|
+
* make orgs, switch between them and are let in. All are the system's: the
|
|
4
|
+
* routes have verified who's asking (their directory session) before they
|
|
5
|
+
* call. Which org one is, for every request, is a query (`org.info`).
|
|
6
|
+
*
|
|
7
|
+
* - `org.create`: a new org (everyone's personal one, or a team's), its
|
|
8
|
+
* maker in it as its owner, placed in the shared schema;
|
|
9
|
+
* - `org.mine`: the orgs someone belongs to, the one they were in last first;
|
|
10
|
+
* - `org.enter`: whether someone may go in (a member, or staff), and how:
|
|
11
|
+
* the role they join with the first time, and where the org lives;
|
|
12
|
+
* - `org.leave`: someone no longer belongs (their org took them out);
|
|
13
|
+
* - `org.suspend`, `org.rename`, `org.report` (its summary), `org.list`,
|
|
14
|
+
* `org.place` (its rows moved), `org.delete`.
|
|
15
|
+
*/
|
|
16
|
+
import { defineAction, failure } from "pairz";
|
|
17
|
+
import { isStaff, placementOf } from "../shared/settings.js";
|
|
18
|
+
const person = { type: "string" };
|
|
19
|
+
export const createOrgAction = defineAction({
|
|
20
|
+
description: "Makes an org (personal or a team's); its maker belongs as its owner",
|
|
21
|
+
input: {
|
|
22
|
+
type: "object",
|
|
23
|
+
properties: {
|
|
24
|
+
name: { type: "string" },
|
|
25
|
+
kind: { type: "string", enum: ["personal", "team"] },
|
|
26
|
+
by: person,
|
|
27
|
+
id: { type: "string" },
|
|
28
|
+
},
|
|
29
|
+
required: ["name", "by"],
|
|
30
|
+
additionalProperties: false,
|
|
31
|
+
},
|
|
32
|
+
run: async (ctx, input) => {
|
|
33
|
+
const kind = input.kind ?? "team";
|
|
34
|
+
if (kind === "personal") {
|
|
35
|
+
const had = await ctx.db.collection("org").findOne({ by: input.by, kind });
|
|
36
|
+
if (had)
|
|
37
|
+
return { org: had._id, created: false };
|
|
38
|
+
}
|
|
39
|
+
const id = input.id ?? `${kind === "personal" ? "p" : "o"}-${crypto.randomUUID().slice(0, 12)}`;
|
|
40
|
+
const at = new Date().toISOString();
|
|
41
|
+
await ctx.transaction(async (tx) => {
|
|
42
|
+
await tx.db.collection("org").insertOne({
|
|
43
|
+
_id: id,
|
|
44
|
+
name: input.name,
|
|
45
|
+
kind,
|
|
46
|
+
by: input.by,
|
|
47
|
+
placement: placementOf(ctx, id),
|
|
48
|
+
at,
|
|
49
|
+
});
|
|
50
|
+
await tx.db.collection("membership").insertOne({
|
|
51
|
+
_id: `${id}|${input.by}`,
|
|
52
|
+
org: id,
|
|
53
|
+
person: input.by,
|
|
54
|
+
role: "owner",
|
|
55
|
+
at,
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
return { org: id, created: true };
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
export const myOrgsAction = defineAction({
|
|
62
|
+
description: "The orgs someone belongs to, the one they were in last first, and if they're staff",
|
|
63
|
+
input: {
|
|
64
|
+
type: "object",
|
|
65
|
+
properties: { person, email: { type: "string" } },
|
|
66
|
+
required: ["person"],
|
|
67
|
+
additionalProperties: false,
|
|
68
|
+
},
|
|
69
|
+
run: async (ctx, input) => {
|
|
70
|
+
const memberships = await ctx.db.collection("membership").find({
|
|
71
|
+
person: input.person,
|
|
72
|
+
});
|
|
73
|
+
const orgs = memberships.length
|
|
74
|
+
? await ctx.db.collection("org").find({
|
|
75
|
+
_id: { $in: memberships.map((m) => m.org) },
|
|
76
|
+
})
|
|
77
|
+
: [];
|
|
78
|
+
const entered = new Map(memberships.map((m) => [m.org, m.entered ?? ""]));
|
|
79
|
+
return {
|
|
80
|
+
orgs: orgs
|
|
81
|
+
.map((o) => ({
|
|
82
|
+
id: o._id,
|
|
83
|
+
name: o.name,
|
|
84
|
+
kind: o.kind,
|
|
85
|
+
...(o.suspended ? { suspended: true } : {}),
|
|
86
|
+
}))
|
|
87
|
+
// The last entered first, then personal before teams, then by name.
|
|
88
|
+
.sort((a, b) => (entered.get(b.id) ?? "").localeCompare(entered.get(a.id) ?? "") ||
|
|
89
|
+
(a.kind === b.kind ? a.name.localeCompare(b.name) : a.kind === "personal" ? -1 : 1)),
|
|
90
|
+
staff: await isStaff(ctx, input.person, input.email),
|
|
91
|
+
};
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
export const enterOrgAction = defineAction({
|
|
95
|
+
description: "Whether someone may go into an org, and how: the role they join with, whether as staff " +
|
|
96
|
+
"(asked for, or staff who don't belong to it), and where it lives",
|
|
97
|
+
input: {
|
|
98
|
+
type: "object",
|
|
99
|
+
properties: {
|
|
100
|
+
org: { type: "string" },
|
|
101
|
+
person,
|
|
102
|
+
email: { type: "string" },
|
|
103
|
+
staff: { type: "boolean" },
|
|
104
|
+
},
|
|
105
|
+
required: ["org", "person"],
|
|
106
|
+
additionalProperties: false,
|
|
107
|
+
},
|
|
108
|
+
run: async (ctx, input) => {
|
|
109
|
+
const org = await ctx.db.collection("org").findOne({ _id: input.org });
|
|
110
|
+
if (!org) {
|
|
111
|
+
throw failure("forbidden", "No such org, or not one you belong to.", { public: true });
|
|
112
|
+
}
|
|
113
|
+
const memberships = ctx.db.collection("membership");
|
|
114
|
+
const mine = await memberships.findOne({ _id: `${input.org}|${input.person}` });
|
|
115
|
+
// Staff who belong to an org go in as one of its people, unless they ask.
|
|
116
|
+
const staff = (!mine || input.staff === true) &&
|
|
117
|
+
await isStaff(ctx, input.person, input.email);
|
|
118
|
+
if (!mine && !staff) {
|
|
119
|
+
throw failure("forbidden", "No such org, or not one you belong to.", { public: true });
|
|
120
|
+
}
|
|
121
|
+
if (input.staff === true && !staff)
|
|
122
|
+
throw failure("forbidden", "Staff only.", { public: true });
|
|
123
|
+
if (org.suspended && !staff) {
|
|
124
|
+
throw failure("forbidden", "This org is suspended.", { public: true });
|
|
125
|
+
}
|
|
126
|
+
if (mine) {
|
|
127
|
+
await memberships.updateOne({ _id: mine._id }, {
|
|
128
|
+
$set: { entered: new Date().toISOString() },
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
org: { id: org._id, name: org.name, kind: org.kind, placement: org.placement },
|
|
133
|
+
...(mine?.role ? { role: mine.role } : {}),
|
|
134
|
+
staff,
|
|
135
|
+
};
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
export const leaveOrgAction = defineAction({
|
|
139
|
+
description: "Someone no longer belongs to an org",
|
|
140
|
+
input: {
|
|
141
|
+
type: "object",
|
|
142
|
+
properties: { org: { type: "string" }, person },
|
|
143
|
+
required: ["org", "person"],
|
|
144
|
+
additionalProperties: false,
|
|
145
|
+
},
|
|
146
|
+
run: async (ctx, input) => {
|
|
147
|
+
const left = await ctx.db.collection("membership").deleteOne({
|
|
148
|
+
_id: `${input.org}|${input.person}`,
|
|
149
|
+
});
|
|
150
|
+
return { left: left.deletedCount > 0 };
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
export const renameOrgAction = defineAction({
|
|
154
|
+
description: "Renames an org",
|
|
155
|
+
input: {
|
|
156
|
+
type: "object",
|
|
157
|
+
properties: { org: { type: "string" }, name: { type: "string", minLength: 1 } },
|
|
158
|
+
required: ["org", "name"],
|
|
159
|
+
additionalProperties: false,
|
|
160
|
+
},
|
|
161
|
+
run: async (ctx, input) => {
|
|
162
|
+
await ctx.db.collection("org").updateOne({ _id: input.org }, { $set: { name: input.name } });
|
|
163
|
+
return { name: input.name };
|
|
164
|
+
},
|
|
165
|
+
});
|
|
166
|
+
export const suspendOrgAction = defineAction({
|
|
167
|
+
description: "Suspends an org (nobody but staff goes in) or lifts it",
|
|
168
|
+
input: {
|
|
169
|
+
type: "object",
|
|
170
|
+
properties: { org: { type: "string" }, suspended: { type: "boolean" } },
|
|
171
|
+
required: ["org", "suspended"],
|
|
172
|
+
additionalProperties: false,
|
|
173
|
+
},
|
|
174
|
+
run: async (ctx, input) => {
|
|
175
|
+
await ctx.db.collection("org").updateOne({ _id: input.org }, {
|
|
176
|
+
...(input.suspended ? { $set: { suspended: true } } : { $unset: { suspended: "" } }),
|
|
177
|
+
});
|
|
178
|
+
return { suspended: input.suspended };
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
export const reportOrgAction = defineAction({
|
|
182
|
+
description: "Keeps what an org last reported of itself, for the console",
|
|
183
|
+
input: {
|
|
184
|
+
type: "object",
|
|
185
|
+
properties: {
|
|
186
|
+
org: { type: "string" },
|
|
187
|
+
people: { type: "number" },
|
|
188
|
+
spaces: { type: "number" },
|
|
189
|
+
active: { type: "string" },
|
|
190
|
+
},
|
|
191
|
+
required: ["org"],
|
|
192
|
+
additionalProperties: false,
|
|
193
|
+
},
|
|
194
|
+
run: async (ctx, { org, ...summary }) => {
|
|
195
|
+
await ctx.db.collection("org").updateOne({ _id: org }, {
|
|
196
|
+
$set: { summary: { ...summary, at: new Date().toISOString() } },
|
|
197
|
+
});
|
|
198
|
+
return {};
|
|
199
|
+
},
|
|
200
|
+
});
|
|
201
|
+
export const listOrgsAction = defineAction({
|
|
202
|
+
description: "Every org, newest first, with what each last reported: for staff's console",
|
|
203
|
+
input: {
|
|
204
|
+
type: "object",
|
|
205
|
+
properties: { limit: { type: "number" }, skip: { type: "number" } },
|
|
206
|
+
additionalProperties: false,
|
|
207
|
+
},
|
|
208
|
+
run: async (ctx, input) => {
|
|
209
|
+
const orgs = await ctx.db.collection("org").find({}, {
|
|
210
|
+
sort: { at: -1 },
|
|
211
|
+
limit: input.limit ?? 200,
|
|
212
|
+
skip: input.skip ?? 0,
|
|
213
|
+
});
|
|
214
|
+
const counts = await ctx.db.collection("membership").aggregate([
|
|
215
|
+
{ $group: { _id: "$org", n: { $sum: 1 } } },
|
|
216
|
+
]);
|
|
217
|
+
const members = new Map(counts.map((c) => [c._id, c.n]));
|
|
218
|
+
return {
|
|
219
|
+
orgs: orgs.map((o) => ({
|
|
220
|
+
id: o._id,
|
|
221
|
+
name: o.name,
|
|
222
|
+
kind: o.kind,
|
|
223
|
+
by: o.by,
|
|
224
|
+
placement: o.placement,
|
|
225
|
+
members: members.get(o._id) ?? 0,
|
|
226
|
+
...(o.suspended ? { suspended: true } : {}),
|
|
227
|
+
...(o.summary ? { summary: o.summary } : {}),
|
|
228
|
+
at: o.at,
|
|
229
|
+
})),
|
|
230
|
+
};
|
|
231
|
+
},
|
|
232
|
+
});
|
|
233
|
+
export const placeOrgAction = defineAction({
|
|
234
|
+
description: "Says where an org's rows now live (after they were moved there)",
|
|
235
|
+
input: {
|
|
236
|
+
type: "object",
|
|
237
|
+
properties: {
|
|
238
|
+
org: { type: "string" },
|
|
239
|
+
placement: {
|
|
240
|
+
type: "object",
|
|
241
|
+
properties: { schema: { type: "string" } },
|
|
242
|
+
required: ["schema"],
|
|
243
|
+
additionalProperties: false,
|
|
244
|
+
},
|
|
245
|
+
},
|
|
246
|
+
required: ["org", "placement"],
|
|
247
|
+
additionalProperties: false,
|
|
248
|
+
},
|
|
249
|
+
run: async (ctx, input) => {
|
|
250
|
+
await ctx.db.collection("org").updateOne({ _id: input.org }, {
|
|
251
|
+
$set: { placement: input.placement },
|
|
252
|
+
});
|
|
253
|
+
return { placement: input.placement };
|
|
254
|
+
},
|
|
255
|
+
});
|
|
256
|
+
export const deleteOrgAction = defineAction({
|
|
257
|
+
description: "Forgets an org: it, who belonged, its invitations and hosts (its rows are dropped apart)",
|
|
258
|
+
input: {
|
|
259
|
+
type: "object",
|
|
260
|
+
properties: { org: { type: "string" } },
|
|
261
|
+
required: ["org"],
|
|
262
|
+
additionalProperties: false,
|
|
263
|
+
},
|
|
264
|
+
run: async (ctx, input) => {
|
|
265
|
+
await ctx.transaction(async (tx) => {
|
|
266
|
+
await tx.db.collection("membership").deleteMany({ org: input.org });
|
|
267
|
+
await tx.db.collection("invite").deleteMany({ org: input.org });
|
|
268
|
+
await tx.db.collection("orgHost").deleteMany({ org: input.org });
|
|
269
|
+
await tx.db.collection("org").deleteOne({ _id: input.org });
|
|
270
|
+
});
|
|
271
|
+
return { deleted: input.org };
|
|
272
|
+
},
|
|
273
|
+
});
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gift codes: credits waiting to be claimed into an org, which may not exist
|
|
3
|
+
* yet. Kept here because they aren't any org's until someone claims one. Only a
|
|
4
|
+
* code's hash is kept (`_id`), and the code is shown once. A purchase made
|
|
5
|
+
* outside the app can wait the same way.
|
|
6
|
+
*/
|
|
7
|
+
import { type Infer } from "pairz";
|
|
8
|
+
declare const creditCodeSchema: {
|
|
9
|
+
readonly type: "object";
|
|
10
|
+
readonly properties: {
|
|
11
|
+
/** USD, and the first day the credits no longer count (`YYYY-MM-DD`); none: they don't lapse. */
|
|
12
|
+
readonly amount: {
|
|
13
|
+
readonly type: "number";
|
|
14
|
+
};
|
|
15
|
+
readonly expires: {
|
|
16
|
+
readonly type: "string";
|
|
17
|
+
};
|
|
18
|
+
/** The last moment it can be claimed; none: until it is. */
|
|
19
|
+
readonly until: {
|
|
20
|
+
readonly type: "string";
|
|
21
|
+
};
|
|
22
|
+
/** What it's for, as the credits will say. */
|
|
23
|
+
readonly note: {
|
|
24
|
+
readonly type: "string";
|
|
25
|
+
};
|
|
26
|
+
readonly by: {
|
|
27
|
+
readonly type: "string";
|
|
28
|
+
};
|
|
29
|
+
readonly at: {
|
|
30
|
+
readonly type: "string";
|
|
31
|
+
};
|
|
32
|
+
/** Who took it, and when; or that it was taken back. */
|
|
33
|
+
readonly org: {
|
|
34
|
+
readonly type: "string";
|
|
35
|
+
};
|
|
36
|
+
readonly person: {
|
|
37
|
+
readonly type: "string";
|
|
38
|
+
};
|
|
39
|
+
readonly claimed: {
|
|
40
|
+
readonly type: "string";
|
|
41
|
+
};
|
|
42
|
+
readonly revoked: {
|
|
43
|
+
readonly type: "string";
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
readonly required: readonly ["amount", "by", "at"];
|
|
47
|
+
};
|
|
48
|
+
export declare const creditCode: Omit<import("pairz").CollectionDef, "queries" | "schema"> & {
|
|
49
|
+
queries?: Record<string, import("pairz").QueryDef<import("pairz").WithId<{
|
|
50
|
+
[x: string]: unknown;
|
|
51
|
+
org?: string | undefined;
|
|
52
|
+
person?: string | undefined;
|
|
53
|
+
expires?: string | undefined;
|
|
54
|
+
until?: string | undefined;
|
|
55
|
+
note?: string | undefined;
|
|
56
|
+
claimed?: string | undefined;
|
|
57
|
+
revoked?: string | undefined;
|
|
58
|
+
at: string;
|
|
59
|
+
by: string;
|
|
60
|
+
amount: number;
|
|
61
|
+
}>>> | undefined;
|
|
62
|
+
} & {
|
|
63
|
+
schema: {
|
|
64
|
+
readonly type: "object";
|
|
65
|
+
readonly properties: {
|
|
66
|
+
/** USD, and the first day the credits no longer count (`YYYY-MM-DD`); none: they don't lapse. */
|
|
67
|
+
readonly amount: {
|
|
68
|
+
readonly type: "number";
|
|
69
|
+
};
|
|
70
|
+
readonly expires: {
|
|
71
|
+
readonly type: "string";
|
|
72
|
+
};
|
|
73
|
+
/** The last moment it can be claimed; none: until it is. */
|
|
74
|
+
readonly until: {
|
|
75
|
+
readonly type: "string";
|
|
76
|
+
};
|
|
77
|
+
/** What it's for, as the credits will say. */
|
|
78
|
+
readonly note: {
|
|
79
|
+
readonly type: "string";
|
|
80
|
+
};
|
|
81
|
+
readonly by: {
|
|
82
|
+
readonly type: "string";
|
|
83
|
+
};
|
|
84
|
+
readonly at: {
|
|
85
|
+
readonly type: "string";
|
|
86
|
+
};
|
|
87
|
+
/** Who took it, and when; or that it was taken back. */
|
|
88
|
+
readonly org: {
|
|
89
|
+
readonly type: "string";
|
|
90
|
+
};
|
|
91
|
+
readonly person: {
|
|
92
|
+
readonly type: "string";
|
|
93
|
+
};
|
|
94
|
+
readonly claimed: {
|
|
95
|
+
readonly type: "string";
|
|
96
|
+
};
|
|
97
|
+
readonly revoked: {
|
|
98
|
+
readonly type: "string";
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
readonly required: readonly ["amount", "by", "at"];
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
export type CreditCode = Infer<typeof creditCodeSchema> & {
|
|
105
|
+
_id: string;
|
|
106
|
+
};
|
|
107
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gift codes: credits waiting to be claimed into an org, which may not exist
|
|
3
|
+
* yet. Kept here because they aren't any org's until someone claims one. Only a
|
|
4
|
+
* code's hash is kept (`_id`), and the code is shown once. A purchase made
|
|
5
|
+
* outside the app can wait the same way.
|
|
6
|
+
*/
|
|
7
|
+
import { defineCollection } from "pairz";
|
|
8
|
+
const creditCodeSchema = {
|
|
9
|
+
type: "object",
|
|
10
|
+
properties: {
|
|
11
|
+
/** USD, and the first day the credits no longer count (`YYYY-MM-DD`); none: they don't lapse. */
|
|
12
|
+
amount: { type: "number" },
|
|
13
|
+
expires: { type: "string" },
|
|
14
|
+
/** The last moment it can be claimed; none: until it is. */
|
|
15
|
+
until: { type: "string" },
|
|
16
|
+
/** What it's for, as the credits will say. */
|
|
17
|
+
note: { type: "string" },
|
|
18
|
+
by: { type: "string" },
|
|
19
|
+
at: { type: "string" },
|
|
20
|
+
/** Who took it, and when; or that it was taken back. */
|
|
21
|
+
org: { type: "string" },
|
|
22
|
+
person: { type: "string" },
|
|
23
|
+
claimed: { type: "string" },
|
|
24
|
+
revoked: { type: "string" },
|
|
25
|
+
},
|
|
26
|
+
required: ["amount", "by", "at"],
|
|
27
|
+
};
|
|
28
|
+
export const creditCode = defineCollection({ schema: creditCodeSchema });
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Invitations to orgs, by email: pending until the person with that verified
|
|
3
|
+
* email accepts one (or declines it). Nobody learns whether an email has an
|
|
4
|
+
* account: an invitation waits either way.
|
|
5
|
+
*/
|
|
6
|
+
import { type Infer } from "pairz";
|
|
7
|
+
declare const inviteSchema: {
|
|
8
|
+
readonly type: "object";
|
|
9
|
+
readonly properties: {
|
|
10
|
+
readonly org: {
|
|
11
|
+
readonly type: "string";
|
|
12
|
+
};
|
|
13
|
+
readonly email: {
|
|
14
|
+
readonly type: "string";
|
|
15
|
+
};
|
|
16
|
+
readonly role: {
|
|
17
|
+
readonly type: "string";
|
|
18
|
+
readonly enum: readonly ["admin", "finance", "member", "guest"];
|
|
19
|
+
};
|
|
20
|
+
/** Who sent it, and their name, for the invited to see. */
|
|
21
|
+
readonly by: {
|
|
22
|
+
readonly type: "string";
|
|
23
|
+
};
|
|
24
|
+
readonly from: {
|
|
25
|
+
readonly type: "string";
|
|
26
|
+
};
|
|
27
|
+
readonly at: {
|
|
28
|
+
readonly type: "string";
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
readonly required: readonly ["org", "email", "role", "by", "at"];
|
|
32
|
+
};
|
|
33
|
+
export declare const invite: Omit<import("pairz").CollectionDef, "queries" | "schema"> & {
|
|
34
|
+
queries?: Record<string, import("pairz").QueryDef<import("pairz").WithId<{
|
|
35
|
+
[x: string]: unknown;
|
|
36
|
+
from?: string | undefined;
|
|
37
|
+
at: string;
|
|
38
|
+
org: string;
|
|
39
|
+
email: string;
|
|
40
|
+
role: "admin" | "finance" | "member" | "guest";
|
|
41
|
+
by: string;
|
|
42
|
+
}>>> | undefined;
|
|
43
|
+
} & {
|
|
44
|
+
schema: {
|
|
45
|
+
readonly type: "object";
|
|
46
|
+
readonly properties: {
|
|
47
|
+
readonly org: {
|
|
48
|
+
readonly type: "string";
|
|
49
|
+
};
|
|
50
|
+
readonly email: {
|
|
51
|
+
readonly type: "string";
|
|
52
|
+
};
|
|
53
|
+
readonly role: {
|
|
54
|
+
readonly type: "string";
|
|
55
|
+
readonly enum: readonly ["admin", "finance", "member", "guest"];
|
|
56
|
+
};
|
|
57
|
+
/** Who sent it, and their name, for the invited to see. */
|
|
58
|
+
readonly by: {
|
|
59
|
+
readonly type: "string";
|
|
60
|
+
};
|
|
61
|
+
readonly from: {
|
|
62
|
+
readonly type: "string";
|
|
63
|
+
};
|
|
64
|
+
readonly at: {
|
|
65
|
+
readonly type: "string";
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
readonly required: readonly ["org", "email", "role", "by", "at"];
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
export type Invite = Infer<typeof inviteSchema> & {
|
|
72
|
+
_id: string;
|
|
73
|
+
};
|
|
74
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Invitations to orgs, by email: pending until the person with that verified
|
|
3
|
+
* email accepts one (or declines it). Nobody learns whether an email has an
|
|
4
|
+
* account: an invitation waits either way.
|
|
5
|
+
*/
|
|
6
|
+
import { defineCollection } from "pairz";
|
|
7
|
+
const inviteSchema = {
|
|
8
|
+
type: "object",
|
|
9
|
+
properties: {
|
|
10
|
+
org: { type: "string" },
|
|
11
|
+
email: { type: "string" },
|
|
12
|
+
role: { type: "string", enum: ["admin", "finance", "member", "guest"] },
|
|
13
|
+
/** Who sent it, and their name, for the invited to see. */
|
|
14
|
+
by: { type: "string" },
|
|
15
|
+
from: { type: "string" },
|
|
16
|
+
at: { type: "string" },
|
|
17
|
+
},
|
|
18
|
+
required: ["org", "email", "role", "by", "at"],
|
|
19
|
+
};
|
|
20
|
+
export const invite = defineCollection({ schema: inviteSchema, indexes: [["email"], ["org"]] });
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Who belongs to which org, for routing: listing someone's orgs and letting
|
|
3
|
+
* them in. Their role is the org's to keep (its `*` memberships), not here.
|
|
4
|
+
* `entered` is when they last went in, so signing in returns them there.
|
|
5
|
+
*/
|
|
6
|
+
import { type Infer } from "pairz";
|
|
7
|
+
declare const membershipSchema: {
|
|
8
|
+
readonly type: "object";
|
|
9
|
+
readonly properties: {
|
|
10
|
+
readonly org: {
|
|
11
|
+
readonly type: "string";
|
|
12
|
+
};
|
|
13
|
+
readonly person: {
|
|
14
|
+
readonly type: "string";
|
|
15
|
+
};
|
|
16
|
+
/** The role they join with, the first time they enter (an invitation's). */
|
|
17
|
+
readonly role: {
|
|
18
|
+
readonly type: "string";
|
|
19
|
+
};
|
|
20
|
+
readonly entered: {
|
|
21
|
+
readonly type: "string";
|
|
22
|
+
};
|
|
23
|
+
readonly at: {
|
|
24
|
+
readonly type: "string";
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
readonly required: readonly ["org", "person", "at"];
|
|
28
|
+
};
|
|
29
|
+
export declare const membership: Omit<import("pairz").CollectionDef, "queries" | "schema"> & {
|
|
30
|
+
queries?: Record<string, import("pairz").QueryDef<import("pairz").WithId<{
|
|
31
|
+
[x: string]: unknown;
|
|
32
|
+
role?: string | undefined;
|
|
33
|
+
entered?: string | undefined;
|
|
34
|
+
at: string;
|
|
35
|
+
org: string;
|
|
36
|
+
person: string;
|
|
37
|
+
}>>> | undefined;
|
|
38
|
+
} & {
|
|
39
|
+
schema: {
|
|
40
|
+
readonly type: "object";
|
|
41
|
+
readonly properties: {
|
|
42
|
+
readonly org: {
|
|
43
|
+
readonly type: "string";
|
|
44
|
+
};
|
|
45
|
+
readonly person: {
|
|
46
|
+
readonly type: "string";
|
|
47
|
+
};
|
|
48
|
+
/** The role they join with, the first time they enter (an invitation's). */
|
|
49
|
+
readonly role: {
|
|
50
|
+
readonly type: "string";
|
|
51
|
+
};
|
|
52
|
+
readonly entered: {
|
|
53
|
+
readonly type: "string";
|
|
54
|
+
};
|
|
55
|
+
readonly at: {
|
|
56
|
+
readonly type: "string";
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
readonly required: readonly ["org", "person", "at"];
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
export type Membership = Infer<typeof membershipSchema> & {
|
|
63
|
+
_id: string;
|
|
64
|
+
};
|
|
65
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Who belongs to which org, for routing: listing someone's orgs and letting
|
|
3
|
+
* them in. Their role is the org's to keep (its `*` memberships), not here.
|
|
4
|
+
* `entered` is when they last went in, so signing in returns them there.
|
|
5
|
+
*/
|
|
6
|
+
import { defineCollection } from "pairz";
|
|
7
|
+
const membershipSchema = {
|
|
8
|
+
type: "object",
|
|
9
|
+
properties: {
|
|
10
|
+
org: { type: "string" },
|
|
11
|
+
person: { type: "string" },
|
|
12
|
+
/** The role they join with, the first time they enter (an invitation's). */
|
|
13
|
+
role: { type: "string" },
|
|
14
|
+
entered: { type: "string" },
|
|
15
|
+
at: { type: "string" },
|
|
16
|
+
},
|
|
17
|
+
required: ["org", "person", "at"],
|
|
18
|
+
};
|
|
19
|
+
export const membership = defineCollection({
|
|
20
|
+
schema: membershipSchema,
|
|
21
|
+
indexes: [["person"], ["org"]],
|
|
22
|
+
});
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
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
|
+
* routes/forward.ts), and the app's front sends it straight to `target`
|
|
5
|
+
* when there's one (an app running elsewhere: its Cloud Run URL). A host is
|
|
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.
|
|
13
|
+
*/
|
|
14
|
+
import { type Infer } from "pairz";
|
|
15
|
+
declare const orgHostSchema: {
|
|
16
|
+
readonly type: "object";
|
|
17
|
+
readonly properties: {
|
|
18
|
+
/** The org whose it is. */
|
|
19
|
+
readonly org: {
|
|
20
|
+
readonly type: "string";
|
|
21
|
+
};
|
|
22
|
+
/** Where the front sends its requests, rather than to the app. */
|
|
23
|
+
readonly target: {
|
|
24
|
+
readonly type: "string";
|
|
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
|
+
};
|
|
30
|
+
readonly at: {
|
|
31
|
+
readonly type: "string";
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
readonly required: readonly ["org", "at"];
|
|
35
|
+
};
|
|
36
|
+
export declare const orgHost: Omit<import("pairz").CollectionDef, "queries" | "schema"> & {
|
|
37
|
+
queries?: Record<string, import("pairz").QueryDef<import("pairz").WithId<{
|
|
38
|
+
[x: string]: unknown;
|
|
39
|
+
target?: string | undefined;
|
|
40
|
+
preview?: string | undefined;
|
|
41
|
+
at: string;
|
|
42
|
+
org: string;
|
|
43
|
+
}>>> | undefined;
|
|
44
|
+
} & {
|
|
45
|
+
schema: {
|
|
46
|
+
readonly type: "object";
|
|
47
|
+
readonly properties: {
|
|
48
|
+
/** The org whose it is. */
|
|
49
|
+
readonly org: {
|
|
50
|
+
readonly type: "string";
|
|
51
|
+
};
|
|
52
|
+
/** Where the front sends its requests, rather than to the app. */
|
|
53
|
+
readonly target: {
|
|
54
|
+
readonly type: "string";
|
|
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
|
+
};
|
|
60
|
+
readonly at: {
|
|
61
|
+
readonly type: "string";
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
readonly required: readonly ["org", "at"];
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
export type OrgHost = Infer<typeof orgHostSchema> & {
|
|
68
|
+
_id: string;
|
|
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;
|
|
72
|
+
export {};
|