@copilotz/directory 1.0.0-rc.79 → 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/WORDS.md
DELETED
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
# @copilotz/directory's words
|
|
2
|
-
|
|
3
|
-
Every word the directory's web front end shows (the org switcher, the org's page, staff's
|
|
4
|
-
console), by key, with its English. An app changes any of them with a `words` resource (see
|
|
5
|
-
Copilotz's README, "Words"). They keep the keys they had in the web shell (`shell.<key>`), beside
|
|
6
|
-
the shell's own (Copilotz's hosts/web/WORDS.md). `{name}` is a blank; a phrase in braces
|
|
7
|
-
`{one, other}` has plural forms, chosen by the `{count}` blank.
|
|
8
|
-
|
|
9
|
-
Generated: `deno run -A packages/directory/tests/words.ts`.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
## directory
|
|
13
|
-
|
|
14
|
-
| Key | English |
|
|
15
|
-
|---|---|
|
|
16
|
-
| `directory.personalOrg` | Personal |
|
|
17
|
-
|
|
18
|
-
## shell
|
|
19
|
-
|
|
20
|
-
| Key | English |
|
|
21
|
-
|---|---|
|
|
22
|
-
| `shell.aboutOrg` | About this organization |
|
|
23
|
-
| `shell.actions` | Actions |
|
|
24
|
-
| `shell.active` | Active |
|
|
25
|
-
| `shell.allOrgsConsole` | All orgs (console) |
|
|
26
|
-
| `shell.atMost` | At most {count} characters |
|
|
27
|
-
| `shell.cancel` | Cancel |
|
|
28
|
-
| `shell.cantUndo` | This can't be undone |
|
|
29
|
-
| `shell.chooseOrg` | Choose one from the switcher at the top of the sidebar. |
|
|
30
|
-
| `shell.claimBy` | Claim by |
|
|
31
|
-
| `shell.claimedBy` | by {org}, {day} |
|
|
32
|
-
| `shell.claimHint` | Empty: any time. |
|
|
33
|
-
| `shell.codeClaimed` | Claimed |
|
|
34
|
-
| `shell.codeExpired` | Expired |
|
|
35
|
-
| `shell.codeMade` | · made {time} |
|
|
36
|
-
| `shell.codeRevoked` | Taken back |
|
|
37
|
-
| `shell.codesCount` | one: {count} code, the newest first / other: {count} codes, the newest first |
|
|
38
|
-
| `shell.codeShortTitle` | Only the start of what's kept: it can't be claimed with this |
|
|
39
|
-
| `shell.codeWaiting` | Waiting |
|
|
40
|
-
| `shell.consoleAbout` | Every org on this app: what each last reported, where its rows live, and what you can do about it. Nothing here reads an org's content. |
|
|
41
|
-
| `shell.consoleShows` | What the console shows |
|
|
42
|
-
| `shell.consoleTitle` | Console |
|
|
43
|
-
| `shell.continueAs` | Continue as {role} |
|
|
44
|
-
| `shell.copyCode` | Copy the code |
|
|
45
|
-
| `shell.copyOrgId` | Copy the org's id |
|
|
46
|
-
| `shell.createNamed` | Create “{name}” |
|
|
47
|
-
| `shell.createOrg` | Create organization |
|
|
48
|
-
| `shell.credits` | Credits |
|
|
49
|
-
| `shell.decline` | Decline |
|
|
50
|
-
| `shell.declineOrgInvite` | Decline {name}'s invitation |
|
|
51
|
-
| `shell.deleteAbout` | Everything in it goes: its people's memberships, spaces, conversations, agents, files and usage. Its people are signed out of it at once. Export its rows first if you may need them. |
|
|
52
|
-
| `shell.deleteForGood` | Delete for good |
|
|
53
|
-
| `shell.deleteMore` | Delete for good… |
|
|
54
|
-
| `shell.deleteTitle` | Delete {name} for good? |
|
|
55
|
-
| `shell.enterAsStaff` | Enter as staff |
|
|
56
|
-
| `shell.enteringAsStaff` | Entering as staff |
|
|
57
|
-
| `shell.exportFirst` | Export its rows (SQL) first |
|
|
58
|
-
| `shell.exportRows` | Export its rows (SQL) |
|
|
59
|
-
| `shell.filterAll` | All |
|
|
60
|
-
| `shell.filterTeams` | Teams |
|
|
61
|
-
| `shell.footAll` | one: {count} organization · the most recently active first / other: {count} organizations · the most recently active first |
|
|
62
|
-
| `shell.footSome` | {shown} of {total} organizations · the most recently active first |
|
|
63
|
-
| `shell.forStaff` | For platform staff |
|
|
64
|
-
| `shell.forStaffAbout` | The console lists every organization, for the people who run this app. |
|
|
65
|
-
| `shell.giftCodes` | Gift codes |
|
|
66
|
-
| `shell.giftCodesAbout` | Credits waiting to be claimed. Someone who runs an org types one in under Billing, and its credits are that org's. |
|
|
67
|
-
| `shell.goHome` | Go home |
|
|
68
|
-
| `shell.goingInto` | Going into {name} |
|
|
69
|
-
| `shell.goIntoAsStaff` | Go into {name} as staff: what you do there is on its record |
|
|
70
|
-
| `shell.heldBack` | {section} is for this org's owners and admins. Ask one of them if you need something changed there. |
|
|
71
|
-
| `shell.hereAsStaff` | You're here as staff |
|
|
72
|
-
| `shell.inAsStaff` | You're in {name} as staff. What you do here is on its record. |
|
|
73
|
-
| `shell.inAsStaffTitle` | You're in {name} as platform staff: what you do is on its record |
|
|
74
|
-
| `shell.inItAsStaff` | You're in it as staff |
|
|
75
|
-
| `shell.invitations` | Invitations |
|
|
76
|
-
| `shell.invitationsCount` | {count} invitations |
|
|
77
|
-
| `shell.invitedAs` | You're invited, as {role} |
|
|
78
|
-
| `shell.invitedAsAt` | You're invited, as {role} · {time} |
|
|
79
|
-
| `shell.invitedFromAs` | {from} invited you, as {role} |
|
|
80
|
-
| `shell.invitedFromAsAt` | {from} invited you, as {role} · {time} |
|
|
81
|
-
| `shell.isDeleted` | {name} is deleted. |
|
|
82
|
-
| `shell.isSuspended` | {name} is suspended. |
|
|
83
|
-
| `shell.join` | Join |
|
|
84
|
-
| `shell.joinNamed` | Join {name} |
|
|
85
|
-
| `shell.justYou` | Just you |
|
|
86
|
-
| `shell.keptIt` | Done, I've kept it |
|
|
87
|
-
| `shell.keysAcceptOrgInvite` | invitation accept organization |
|
|
88
|
-
| `shell.keysConsole` | staff console platform suspend |
|
|
89
|
-
| `shell.keysNewOrg` | create team organization org |
|
|
90
|
-
| `shell.keysOrgInvite` | invitation organization |
|
|
91
|
-
| `shell.keysOrgSettings` | members usage invite roles organization |
|
|
92
|
-
| `shell.keysSwitch` | organization org switch |
|
|
93
|
-
| `shell.lapseHint` | Empty: they don't lapse. |
|
|
94
|
-
| `shell.lapseOn` | Credits lapse on |
|
|
95
|
-
| `shell.lastActive` | Last active |
|
|
96
|
-
| `shell.lift` | Lift the suspension |
|
|
97
|
-
| `shell.liftAbout` | Its people can go in again, as before. Nothing in it changed while it was suspended. |
|
|
98
|
-
| `shell.liftMore` | Lift the suspension… |
|
|
99
|
-
| `shell.liftTitle` | Lift the suspension of {name}? |
|
|
100
|
-
| `shell.makeCode` | Make a {amount} code |
|
|
101
|
-
| `shell.makeTheCode` | Make the code |
|
|
102
|
-
| `shell.moreOf` | {name}: more |
|
|
103
|
-
| `shell.moveAbout` | For big orgs: gives it a schema of its own, so its load and its rows stand apart from the shared pool. |
|
|
104
|
-
| `shell.movedOrg` | You're no longer in the org you were in. You're in {name}. |
|
|
105
|
-
| `shell.moveMore` | Move to another schema… |
|
|
106
|
-
| `shell.moveRows` | Move its rows |
|
|
107
|
-
| `shell.moveText` | It's closed for a moment, its rows are copied to the new schema as they are, and it opens there on its next use. Its people may see it reconnect. |
|
|
108
|
-
| `shell.moveTitle` | Move {name} |
|
|
109
|
-
| `shell.name` | Name |
|
|
110
|
-
| `shell.nameIt` | Name it |
|
|
111
|
-
| `shell.newGiftCode` | New gift code |
|
|
112
|
-
| `shell.newOrg` | New organization |
|
|
113
|
-
| `shell.newOrgAbout` | For a team: you'll own it, and invite people by email. |
|
|
114
|
-
| `shell.newOrgMore` | New organization… |
|
|
115
|
-
| `shell.newOrgNameHint` | Usually your team's or company's name. You can change it later. |
|
|
116
|
-
| `shell.newOrgPlaceholder` | e.g. Acme |
|
|
117
|
-
| `shell.newSchema` | New schema |
|
|
118
|
-
| `shell.noCodes` | No gift codes yet |
|
|
119
|
-
| `shell.noCodesAbout` | A gift code gives whoever claims it credits for their org. |
|
|
120
|
-
| `shell.noMatch` | No organization matches |
|
|
121
|
-
| `shell.notePlaceholder` | Conference, November |
|
|
122
|
-
| `shell.nothingMatches` | Nothing matches “{search}” |
|
|
123
|
-
| `shell.nothingToSet` | Nothing to set here |
|
|
124
|
-
| `shell.nothingToSetAbout` | This app adds no sections to an organization's page. |
|
|
125
|
-
| `shell.nothingYet` | Nothing in this list yet. |
|
|
126
|
-
| `shell.notInOrg` | You're not in an organization |
|
|
127
|
-
| `shell.notShownAgain` | This won't be shown again |
|
|
128
|
-
| `shell.notShownAgainAbout` | Only a fingerprint of it is kept, so nobody can look it up later. Copy it now. If it's lost, take this one back and make another. |
|
|
129
|
-
| `shell.notYet` | Not yet |
|
|
130
|
-
| `shell.nowIn` | Now in |
|
|
131
|
-
| `shell.nowLivesIn` | {name} now lives in “{schema}”. |
|
|
132
|
-
| `shell.oneOrg` | One organization here |
|
|
133
|
-
| `shell.oneOrgAbout` | This app serves a single organization, so there's nothing to set here. |
|
|
134
|
-
| `shell.openAgain` | {name} is open again. |
|
|
135
|
-
| `shell.orgAboutGuest` | What {name} is. As a guest, you work in the spaces you're invited to. |
|
|
136
|
-
| `shell.orgAboutMember` | What {name} is, and who's in it. |
|
|
137
|
-
| `shell.orgAboutPersonal` | Your own organization: just you, and what you make alone. |
|
|
138
|
-
| `shell.orgAboutRuns` | Who's in {name}, what it uses, and what it's called. |
|
|
139
|
-
| `shell.orgAboutStaff` | You're here as platform staff: what you do is on {name}'s record. |
|
|
140
|
-
| `shell.organization` | Organization |
|
|
141
|
-
| `shell.organizations` | Organizations |
|
|
142
|
-
| `shell.orgSection` | {name}: {section} |
|
|
143
|
-
| `shell.orgSettings` | Organization settings |
|
|
144
|
-
| `shell.orgSettingsOf` | {name}'s settings |
|
|
145
|
-
| `shell.people` | People |
|
|
146
|
-
| `shell.personal` | Personal |
|
|
147
|
-
| `shell.personalOrg` | Personal org |
|
|
148
|
-
| `shell.placement` | Placement |
|
|
149
|
-
| `shell.refresh` | Refresh |
|
|
150
|
-
| `shell.rename` | Rename |
|
|
151
|
-
| `shell.renamedTo` | Renamed to “{name}”. |
|
|
152
|
-
| `shell.renameMore` | Rename… |
|
|
153
|
-
| `shell.renameOrg` | Rename organization |
|
|
154
|
-
| `shell.renameOrgAbout` | Its people see the new name at once, everywhere. |
|
|
155
|
-
| `shell.sameSchema` | That's where it is now. |
|
|
156
|
-
| `shell.sayDollars` | Say how many dollars of credits. |
|
|
157
|
-
| `shell.schemaRule` | Lowercase letters, digits and _, starting with a letter. |
|
|
158
|
-
| `shell.searchOrgs` | Search organizations |
|
|
159
|
-
| `shell.searchPlaceholder` | Search by name, id, schema or maker |
|
|
160
|
-
| `shell.signedInAs` | Signed in as {who} |
|
|
161
|
-
| `shell.spaces` | Spaces |
|
|
162
|
-
| `shell.staff` | Staff |
|
|
163
|
-
| `shell.staffAccess` | Staff access |
|
|
164
|
-
| `shell.staffLine` | You're in this org as platform staff: what you do is on its record. |
|
|
165
|
-
| `shell.status` | Status |
|
|
166
|
-
| `shell.suspend` | Suspend |
|
|
167
|
-
| `shell.suspendAbout` | Nobody but staff goes in until you lift it: its people see that it's suspended. Nothing in it is changed or deleted. |
|
|
168
|
-
| `shell.suspended` | Suspended |
|
|
169
|
-
| `shell.suspendedTitle` | {name} is suspended: nobody goes in for now |
|
|
170
|
-
| `shell.suspendMore` | Suspend… |
|
|
171
|
-
| `shell.suspendTitle` | Suspend {name}? |
|
|
172
|
-
| `shell.switchingTo` | Switching to |
|
|
173
|
-
| `shell.switchOrg` | {name}: switch organization |
|
|
174
|
-
| `shell.switchOrgWaiting` | one: {name}: switch organization ({count} invitation) / other: {name}: switch organization ({count} invitations) |
|
|
175
|
-
| `shell.switchTo` | Switch to {name} |
|
|
176
|
-
| `shell.takeBack` | Take back |
|
|
177
|
-
| `shell.takeBackAbout` | Nobody can claim it after this, and that can't be undone. If someone still needs it, make them a new one. |
|
|
178
|
-
| `shell.takeBackTitle` | Take back this {amount} code? |
|
|
179
|
-
| `shell.takeItBack` | Take it back |
|
|
180
|
-
| `shell.team` | Team |
|
|
181
|
-
| `shell.teamOrg` | Team org |
|
|
182
|
-
| `shell.teamOrgs` | Team orgs |
|
|
183
|
-
| `shell.termsLapse` | Credits lapse {lapse} |
|
|
184
|
-
| `shell.termsLapseClaim` | Credits lapse {lapse} · claim by {until} |
|
|
185
|
-
| `shell.termsNoLapse` | Credits don't lapse |
|
|
186
|
-
| `shell.termsNoLapseClaim` | Credits don't lapse · claim by {until} |
|
|
187
|
-
| `shell.tryAgain` | Try again |
|
|
188
|
-
| `shell.typeToConfirm` | Type {name} to confirm |
|
|
189
|
-
| `shell.unsupported` | This app doesn't do that yet. ({reason}) |
|
|
190
|
-
| `shell.whatFor` | What it's for |
|
|
191
|
-
| `shell.whatForHint` | Whoever claims it sees this in their history. |
|
|
192
|
-
| `shell.whichOrgs` | Which organizations |
|
|
193
|
-
| `shell.yourCode` | Your {amount} gift code |
|
|
194
|
-
| `shell.youreHere` | You're here |
|
|
195
|
-
| `shell.youreIn` | You're in {name} |
|
|
196
|
-
| `shell.yourOrgs` | Your organizations |
|
|
197
|
-
| `shell.yourOwn` | Your own |
|
|
198
|
-
| `shell.yourOwnOrg` | Your own org |
|
package/actions/code.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export declare const createCodeAction: import("copilotz").ActionDef;
|
|
2
|
-
export declare const claimCodeAction: import("copilotz").ActionDef;
|
|
3
|
-
export declare const listCodesAction: import("copilotz").ActionDef;
|
|
4
|
-
export declare const revokeCodeAction: import("copilotz").ActionDef;
|
package/actions/code.js
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Gift codes (see collections/credit-code.ts). All the system's: staff ask
|
|
3
|
-
* through the console, orgs through their `directory` resource. None is
|
|
4
|
-
* recorded, so a code is in no event.
|
|
5
|
-
*
|
|
6
|
-
* - `code.create` `{ amount, expires?, until?, note?, by }`: a new code, shown
|
|
7
|
-
* this once;
|
|
8
|
-
* - `code.claim` `{ code, org, person }`: its credits, for that org. Claimed
|
|
9
|
-
* already by the same org, it answers the same, so a grant that failed can be
|
|
10
|
-
* tried again; by another, it's refused;
|
|
11
|
-
* - `code.list` `{}`, newest first, and `code.revoke` `{ id }`, while unclaimed.
|
|
12
|
-
*/
|
|
13
|
-
import { defineAction, failure, invalid } from "copilotz";
|
|
14
|
-
const ALPHABET = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
15
|
-
/** 130 random bits, as people can read and type them. */
|
|
16
|
-
function newCode() {
|
|
17
|
-
const bytes = crypto.getRandomValues(new Uint8Array(26));
|
|
18
|
-
const chars = [...bytes].map((byte) => ALPHABET[byte % 32]).join("");
|
|
19
|
-
return `GIFT-${chars.match(/.{1,5}/g).join("-")}`;
|
|
20
|
-
}
|
|
21
|
-
/** How it's kept: typed in any case, with or without its dashes. */
|
|
22
|
-
async function hashOf(code) {
|
|
23
|
-
const plain = code.toUpperCase().replace(/[^0-9A-Z]/g, "");
|
|
24
|
-
const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(plain));
|
|
25
|
-
return [...new Uint8Array(digest)].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
26
|
-
}
|
|
27
|
-
const shown = (doc) => ({
|
|
28
|
-
id: doc._id,
|
|
29
|
-
// Enough to tell them apart: it can't be claimed with this.
|
|
30
|
-
short: doc._id.slice(0, 8),
|
|
31
|
-
amount: doc.amount,
|
|
32
|
-
...(doc.expires ? { expires: doc.expires } : {}),
|
|
33
|
-
...(doc.until ? { until: doc.until } : {}),
|
|
34
|
-
...(doc.note ? { note: doc.note } : {}),
|
|
35
|
-
by: doc.by,
|
|
36
|
-
at: doc.at,
|
|
37
|
-
...(doc.org ? { org: doc.org, person: doc.person, claimed: doc.claimed } : {}),
|
|
38
|
-
...(doc.revoked ? { revoked: doc.revoked } : {}),
|
|
39
|
-
});
|
|
40
|
-
export const createCodeAction = defineAction({
|
|
41
|
-
description: "Makes a gift code of credits; it's shown this once",
|
|
42
|
-
record: false,
|
|
43
|
-
input: {
|
|
44
|
-
type: "object",
|
|
45
|
-
properties: {
|
|
46
|
-
amount: { type: "number", exclusiveMinimum: 0 },
|
|
47
|
-
expires: { type: "string", pattern: "^\\d{4}-\\d{2}-\\d{2}$" },
|
|
48
|
-
until: { type: "string" },
|
|
49
|
-
note: { type: "string", maxLength: 200 },
|
|
50
|
-
by: { type: "string" },
|
|
51
|
-
},
|
|
52
|
-
required: ["amount", "by"],
|
|
53
|
-
additionalProperties: false,
|
|
54
|
-
},
|
|
55
|
-
run: async (ctx, input) => {
|
|
56
|
-
const code = newCode();
|
|
57
|
-
const _id = await hashOf(code);
|
|
58
|
-
await ctx.db.collection("creditCode").insertOne({
|
|
59
|
-
_id,
|
|
60
|
-
...input,
|
|
61
|
-
at: new Date().toISOString(),
|
|
62
|
-
});
|
|
63
|
-
return { code, id: _id };
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
export const claimCodeAction = defineAction({
|
|
67
|
-
description: "Claims a gift code for an org",
|
|
68
|
-
record: false,
|
|
69
|
-
input: {
|
|
70
|
-
type: "object",
|
|
71
|
-
properties: {
|
|
72
|
-
code: { type: "string" },
|
|
73
|
-
org: { type: "string" },
|
|
74
|
-
person: { type: "string" },
|
|
75
|
-
},
|
|
76
|
-
required: ["code", "org", "person"],
|
|
77
|
-
additionalProperties: false,
|
|
78
|
-
},
|
|
79
|
-
run: async (ctx, input) => {
|
|
80
|
-
const codes = ctx.db.collection("creditCode");
|
|
81
|
-
const _id = await hashOf(input.code);
|
|
82
|
-
const invalidCode = () => failure("invalid_code", "That code isn't valid. Check it and try again.");
|
|
83
|
-
const answer = (doc) => ({
|
|
84
|
-
id: _id.slice(0, 16),
|
|
85
|
-
amount: doc.amount,
|
|
86
|
-
...(doc.expires ? { expires: doc.expires } : {}),
|
|
87
|
-
...(doc.note ? { note: doc.note } : {}),
|
|
88
|
-
});
|
|
89
|
-
const doc = await codes.findOne({ _id });
|
|
90
|
-
if (!doc || doc.revoked)
|
|
91
|
-
throw invalidCode();
|
|
92
|
-
if (doc.org === input.org)
|
|
93
|
-
return answer(doc);
|
|
94
|
-
if (doc.org)
|
|
95
|
-
throw failure("used_code", "That code has already been used.");
|
|
96
|
-
const now = new Date().toISOString();
|
|
97
|
-
if (doc.until && doc.until <= now)
|
|
98
|
-
throw failure("expired_code", "That code has expired.");
|
|
99
|
-
// One writer: only one claim finds it unclaimed.
|
|
100
|
-
const { modifiedCount } = await codes.updateOne({ _id, org: { $exists: false }, revoked: { $exists: false } }, { $set: { org: input.org, person: input.person, claimed: now } });
|
|
101
|
-
if (modifiedCount)
|
|
102
|
-
return answer(doc);
|
|
103
|
-
const now2 = await codes.findOne({ _id });
|
|
104
|
-
if (now2?.org === input.org)
|
|
105
|
-
return answer(now2);
|
|
106
|
-
throw failure("used_code", "That code has already been used.");
|
|
107
|
-
},
|
|
108
|
-
});
|
|
109
|
-
export const listCodesAction = defineAction({
|
|
110
|
-
description: "Gift codes, newest first",
|
|
111
|
-
record: false,
|
|
112
|
-
input: { type: "object", additionalProperties: false },
|
|
113
|
-
run: async (ctx) => ({
|
|
114
|
-
codes: (await ctx.db.collection("creditCode").find({}, {
|
|
115
|
-
sort: { at: -1 },
|
|
116
|
-
limit: 200,
|
|
117
|
-
})).map(shown),
|
|
118
|
-
}),
|
|
119
|
-
});
|
|
120
|
-
export const revokeCodeAction = defineAction({
|
|
121
|
-
description: "Takes back a gift code nobody has claimed",
|
|
122
|
-
record: false,
|
|
123
|
-
input: {
|
|
124
|
-
type: "object",
|
|
125
|
-
properties: { id: { type: "string" } },
|
|
126
|
-
required: ["id"],
|
|
127
|
-
additionalProperties: false,
|
|
128
|
-
},
|
|
129
|
-
run: async (ctx, input) => {
|
|
130
|
-
const { modifiedCount } = await ctx.db.collection("creditCode").updateOne({ _id: input.id, org: { $exists: false } }, { $set: { revoked: new Date().toISOString() } });
|
|
131
|
-
if (!modifiedCount)
|
|
132
|
-
throw invalid("It's been claimed, or there's no such code.");
|
|
133
|
-
return {};
|
|
134
|
-
},
|
|
135
|
-
});
|
package/actions/host.d.ts
DELETED
package/actions/host.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Hosts orgs claim (see collections/org-host.ts), as an org's runtime asks
|
|
3
|
-
* (its `directory` resource's `claimHost`, `releaseHost`: see
|
|
4
|
-
* shared/member.ts). The system's: `member` has checked the host isn't the
|
|
5
|
-
* app's own.
|
|
6
|
-
*
|
|
7
|
-
* - `host.claim` `{ org, host, target? }`: the host is the org's (again:
|
|
8
|
-
* its target changes); refused when it's another org's;
|
|
9
|
-
* - `host.release` `{ org, host }`: it's no longer the org's (if it was).
|
|
10
|
-
*/
|
|
11
|
-
import { defineAction, forbidden } from "copilotz";
|
|
12
|
-
/** A host, as claims keep it: lowercase letters, digits, dots and hyphens, and a port maybe. */
|
|
13
|
-
const host = { type: "string", pattern: "^[a-z0-9.-]+(:[0-9]{1,5})?$", maxLength: 253 };
|
|
14
|
-
export const claimHostAction = defineAction({
|
|
15
|
-
description: "Makes a host an org's (its requests go to the org's routes, or to a target)",
|
|
16
|
-
input: {
|
|
17
|
-
type: "object",
|
|
18
|
-
properties: { org: { type: "string" }, host, target: { type: "string" } },
|
|
19
|
-
required: ["org", "host"],
|
|
20
|
-
additionalProperties: false,
|
|
21
|
-
},
|
|
22
|
-
run: async (ctx, input) => {
|
|
23
|
-
const hosts = ctx.db.collection("orgHost");
|
|
24
|
-
const had = await hosts.findOne({ _id: input.host });
|
|
25
|
-
if (had && had.org !== input.org)
|
|
26
|
-
throw forbidden(`${input.host} is another org's.`);
|
|
27
|
-
if (had) {
|
|
28
|
-
await hosts.updateOne({ _id: input.host }, {
|
|
29
|
-
...(input.target ? { $set: { target: input.target } } : { $unset: { target: "" } }),
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
await hosts.insertOne({
|
|
34
|
-
_id: input.host,
|
|
35
|
-
org: input.org,
|
|
36
|
-
...(input.target ? { target: input.target } : {}),
|
|
37
|
-
at: new Date().toISOString(),
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
return { host: input.host, org: input.org, ...(input.target ? { target: input.target } : {}) };
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
|
-
export const releaseHostAction = defineAction({
|
|
44
|
-
description: "A host is no longer an org's",
|
|
45
|
-
input: {
|
|
46
|
-
type: "object",
|
|
47
|
-
properties: { org: { type: "string" }, host },
|
|
48
|
-
required: ["org", "host"],
|
|
49
|
-
additionalProperties: false,
|
|
50
|
-
},
|
|
51
|
-
run: async (ctx, input) => {
|
|
52
|
-
const gone = await ctx.db.collection("orgHost").deleteOne({ _id: input.host, org: input.org });
|
|
53
|
-
return { released: gone.deletedCount > 0 };
|
|
54
|
-
},
|
|
55
|
-
});
|
package/actions/invite.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export declare const sendInviteAction: import("copilotz").ActionDef;
|
|
2
|
-
export declare const myInvitesAction: import("copilotz").ActionDef;
|
|
3
|
-
export declare const orgInvitesAction: import("copilotz").ActionDef;
|
|
4
|
-
export declare const answerInviteAction: import("copilotz").ActionDef;
|
|
5
|
-
export declare const cancelInviteAction: import("copilotz").ActionDef;
|
package/actions/invite.js
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Invitations to orgs, by email: the org's admins send them (their org's
|
|
3
|
-
* runtime asks the directory, see shared/member.ts), the person with that verified email sees
|
|
4
|
-
* theirs when they sign in, and accepting one makes them belong, with the
|
|
5
|
-
* invitation's role for their first entering. All are the system's.
|
|
6
|
-
*/
|
|
7
|
-
import { defineAction, failure } from "copilotz";
|
|
8
|
-
export const sendInviteAction = defineAction({
|
|
9
|
-
description: "Invites an email to an org, with a role",
|
|
10
|
-
input: {
|
|
11
|
-
type: "object",
|
|
12
|
-
properties: {
|
|
13
|
-
org: { type: "string" },
|
|
14
|
-
email: { type: "string", pattern: "^[^@\\s]+@[^@\\s]+$" },
|
|
15
|
-
role: { type: "string", enum: ["admin", "member", "guest"] },
|
|
16
|
-
by: { type: "string" },
|
|
17
|
-
from: { type: "string" },
|
|
18
|
-
},
|
|
19
|
-
required: ["org", "email", "role", "by"],
|
|
20
|
-
additionalProperties: false,
|
|
21
|
-
},
|
|
22
|
-
run: async (ctx, input) => {
|
|
23
|
-
const email = input.email.toLowerCase();
|
|
24
|
-
const id = `${input.org}|${email}`;
|
|
25
|
-
// Inviting again changes its role; it's still the one invitation.
|
|
26
|
-
await ctx.db.collection("invite").replaceOne({ _id: id }, {
|
|
27
|
-
org: input.org,
|
|
28
|
-
email,
|
|
29
|
-
role: input.role,
|
|
30
|
-
by: input.by,
|
|
31
|
-
...(input.from ? { from: input.from } : {}),
|
|
32
|
-
at: new Date().toISOString(),
|
|
33
|
-
}, { upsert: true });
|
|
34
|
-
return { invite: id };
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
export const myInvitesAction = defineAction({
|
|
38
|
-
description: "The invitations waiting for an email, with their orgs' names",
|
|
39
|
-
input: {
|
|
40
|
-
type: "object",
|
|
41
|
-
properties: { email: { type: "string" } },
|
|
42
|
-
required: ["email"],
|
|
43
|
-
additionalProperties: false,
|
|
44
|
-
},
|
|
45
|
-
run: async (ctx, input) => {
|
|
46
|
-
const invites = await ctx.db.collection("invite").find({
|
|
47
|
-
email: input.email.toLowerCase(),
|
|
48
|
-
}, { sort: { at: -1 } });
|
|
49
|
-
const orgs = invites.length
|
|
50
|
-
? await ctx.db.collection("org").find({ _id: { $in: invites.map((i) => i.org) } })
|
|
51
|
-
: [];
|
|
52
|
-
const names = new Map(orgs.map((o) => [o._id, o.name]));
|
|
53
|
-
return {
|
|
54
|
-
invites: invites.filter((i) => names.has(i.org)).map((i) => ({
|
|
55
|
-
id: i._id,
|
|
56
|
-
org: i.org,
|
|
57
|
-
name: names.get(i.org),
|
|
58
|
-
role: i.role,
|
|
59
|
-
...(i.from ? { from: i.from } : {}),
|
|
60
|
-
at: i.at,
|
|
61
|
-
})),
|
|
62
|
-
};
|
|
63
|
-
},
|
|
64
|
-
});
|
|
65
|
-
export const orgInvitesAction = defineAction({
|
|
66
|
-
description: "The invitations an org has waiting",
|
|
67
|
-
input: {
|
|
68
|
-
type: "object",
|
|
69
|
-
properties: { org: { type: "string" } },
|
|
70
|
-
required: ["org"],
|
|
71
|
-
additionalProperties: false,
|
|
72
|
-
},
|
|
73
|
-
run: async (ctx, input) => ({
|
|
74
|
-
invites: (await ctx.db.collection("invite").find({ org: input.org }, {
|
|
75
|
-
sort: { at: -1 },
|
|
76
|
-
})).map((i) => ({ id: i._id, email: i.email, role: i.role, at: i.at })),
|
|
77
|
-
}),
|
|
78
|
-
});
|
|
79
|
-
export const answerInviteAction = defineAction({
|
|
80
|
-
description: "Accepts or declines an invitation, for the person whose email it's to",
|
|
81
|
-
input: {
|
|
82
|
-
type: "object",
|
|
83
|
-
properties: {
|
|
84
|
-
invite: { type: "string" },
|
|
85
|
-
person: { type: "string" },
|
|
86
|
-
email: { type: "string" },
|
|
87
|
-
accept: { type: "boolean" },
|
|
88
|
-
},
|
|
89
|
-
required: ["invite", "person", "email", "accept"],
|
|
90
|
-
additionalProperties: false,
|
|
91
|
-
},
|
|
92
|
-
run: async (ctx, input) => {
|
|
93
|
-
const invites = ctx.db.collection("invite");
|
|
94
|
-
const found = await invites.findOne({ _id: input.invite });
|
|
95
|
-
if (!found || found.email !== input.email.toLowerCase()) {
|
|
96
|
-
throw failure("forbidden", "No such invitation for you.", { public: true });
|
|
97
|
-
}
|
|
98
|
-
await ctx.transaction(async (tx) => {
|
|
99
|
-
if (input.accept) {
|
|
100
|
-
const memberships = tx.db.collection("membership");
|
|
101
|
-
const id = `${found.org}|${input.person}`;
|
|
102
|
-
const had = await memberships.findOne({ _id: id });
|
|
103
|
-
await memberships.replaceOne({ _id: id }, {
|
|
104
|
-
org: found.org,
|
|
105
|
-
person: input.person,
|
|
106
|
-
role: found.role,
|
|
107
|
-
at: had?.at ?? new Date().toISOString(),
|
|
108
|
-
}, { upsert: true });
|
|
109
|
-
}
|
|
110
|
-
await tx.db.collection("invite").deleteOne({ _id: found._id });
|
|
111
|
-
});
|
|
112
|
-
return { org: found.org, joined: input.accept };
|
|
113
|
-
},
|
|
114
|
-
});
|
|
115
|
-
export const cancelInviteAction = defineAction({
|
|
116
|
-
description: "Takes back an org's invitation",
|
|
117
|
-
input: {
|
|
118
|
-
type: "object",
|
|
119
|
-
properties: { org: { type: "string" }, email: { type: "string" } },
|
|
120
|
-
required: ["org", "email"],
|
|
121
|
-
additionalProperties: false,
|
|
122
|
-
},
|
|
123
|
-
run: async (ctx, input) => {
|
|
124
|
-
const gone = await ctx.db.collection("invite").deleteOne({
|
|
125
|
-
_id: `${input.org}|${input.email.toLowerCase()}`,
|
|
126
|
-
});
|
|
127
|
-
return { cancelled: gone.deletedCount > 0 };
|
|
128
|
-
},
|
|
129
|
-
});
|
package/actions/org.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export declare const createOrgAction: import("copilotz").ActionDef;
|
|
2
|
-
export declare const myOrgsAction: import("copilotz").ActionDef;
|
|
3
|
-
export declare const enterOrgAction: import("copilotz").ActionDef;
|
|
4
|
-
export declare const leaveOrgAction: import("copilotz").ActionDef;
|
|
5
|
-
export declare const renameOrgAction: import("copilotz").ActionDef;
|
|
6
|
-
export declare const suspendOrgAction: import("copilotz").ActionDef;
|
|
7
|
-
export declare const reportOrgAction: import("copilotz").ActionDef;
|
|
8
|
-
export declare const listOrgsAction: import("copilotz").ActionDef;
|
|
9
|
-
export declare const placeOrgAction: import("copilotz").ActionDef;
|
|
10
|
-
export declare const deleteOrgAction: import("copilotz").ActionDef;
|