@open-workspace/create 0.6.6 → 0.7.0
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/dist/backup-schema.ts +7 -27
- package/dist/workspace.ts +23 -44
- package/import/directory/command.ts +41 -23
- package/import/directory/plan.ts +64 -33
- package/import/idp/command.ts +16 -7
- package/package.json +1 -1
- package/setup/args.ts +8 -10
- package/setup/flow.ts +7 -7
- package/templates.ts +5 -5
package/dist/backup-schema.ts
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
listPostingPolicies,
|
|
5
|
-
mailboxDeliveries,
|
|
6
|
-
MAX_FORWARD_DESTINATIONS,
|
|
7
|
-
} from "./workspace";
|
|
8
|
-
|
|
9
3
|
const id = z.string().min(1).max(100);
|
|
10
4
|
const name = z.string().min(1).max(500);
|
|
11
5
|
const strings = z.array(z.string().max(2000)).max(100);
|
|
@@ -16,11 +10,13 @@ const accessTeams = z.array(
|
|
|
16
10
|
|
|
17
11
|
/** core.json as `import backup` sends it back. */
|
|
18
12
|
export const coreBackupSchema = z.object({
|
|
19
|
-
version: z.literal(
|
|
13
|
+
version: z.literal(5),
|
|
20
14
|
people: z.array(
|
|
21
15
|
z.object({
|
|
22
16
|
id,
|
|
23
17
|
name,
|
|
18
|
+
/** What they signed in as. */
|
|
19
|
+
email: z.string().min(3).max(320),
|
|
24
20
|
role: z.enum(["admin", "member"]),
|
|
25
21
|
status: z.enum(["invited", "active", "disabled"]),
|
|
26
22
|
permissions: strings,
|
|
@@ -33,27 +29,11 @@ export const coreBackupSchema = z.object({
|
|
|
33
29
|
slug: name,
|
|
34
30
|
description: z.string().max(2000).nullable(),
|
|
35
31
|
everyone: z.boolean(),
|
|
36
|
-
members: z.array(z.object({ userId: id,
|
|
37
|
-
})
|
|
38
|
-
),
|
|
39
|
-
addresses: z.array(
|
|
40
|
-
z.object({
|
|
41
|
-
id,
|
|
42
|
-
address: z.string().min(3).max(320),
|
|
43
|
-
displayName: name,
|
|
44
|
-
ownerUserId: id.nullable(),
|
|
45
|
-
teamId: id.nullable(),
|
|
46
|
-
delivery: z.enum(mailboxDeliveries),
|
|
47
|
-
aliasOf: id.nullable(),
|
|
48
|
-
forwardTo: z
|
|
49
|
-
.array(z.string().max(320))
|
|
50
|
-
.max(MAX_FORWARD_DESTINATIONS)
|
|
51
|
-
.nullable(),
|
|
52
|
-
catchAll: z.boolean(),
|
|
53
|
-
listPosting: z.enum(listPostingPolicies),
|
|
54
|
-
isPrimary: z.boolean(),
|
|
32
|
+
members: z.array(z.object({ userId: id, permissions: strings })),
|
|
55
33
|
})
|
|
56
34
|
),
|
|
35
|
+
/** Each module's part (`ModuleBackup.workspace`), by its name: mail's addresses, say. */
|
|
36
|
+
modules: z.record(z.string(), z.json()),
|
|
57
37
|
ssoApps: z.object({
|
|
58
38
|
oidc: z.array(
|
|
59
39
|
z.object({
|
|
@@ -98,7 +78,7 @@ export const coreBackupSchema = z.object({
|
|
|
98
78
|
name,
|
|
99
79
|
url: z.string().min(1).max(2000),
|
|
100
80
|
events: strings,
|
|
101
|
-
|
|
81
|
+
resourceIds: strings,
|
|
102
82
|
})
|
|
103
83
|
),
|
|
104
84
|
branding: z.object({
|
package/dist/workspace.ts
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a module lets a team's members do with what the team holds, e.g.
|
|
3
|
+
* send from its addresses. Each member of a team has it or not; new members
|
|
4
|
+
* get every one, and everyone on a team for everyone holds them all.
|
|
5
|
+
*/
|
|
6
|
+
export type TeamPermissionDefinition = {
|
|
7
|
+
/** Stable id stored with each membership, e.g. "send_mail". */
|
|
8
|
+
id: string;
|
|
9
|
+
/** Next to the member's switch, e.g. "Can send". */
|
|
10
|
+
label: string;
|
|
11
|
+
description: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/** Two lists of team permissions hold the same ones, in any order. */
|
|
15
|
+
export function sameTeamPermissions(
|
|
16
|
+
a: readonly string[],
|
|
17
|
+
b: readonly string[]
|
|
18
|
+
) {
|
|
19
|
+
return a.length === b.length && a.every((id) => b.includes(id));
|
|
20
|
+
}
|
|
21
|
+
|
|
1
22
|
/** Something an administrator can let a member manage. */
|
|
2
23
|
export type PermissionDefinition = {
|
|
3
24
|
/** Stable id stored with each person, e.g. "manage_people". */
|
|
@@ -23,14 +44,14 @@ export const corePermissions = [
|
|
|
23
44
|
scope: "admin.people",
|
|
24
45
|
label: "Manage people",
|
|
25
46
|
description:
|
|
26
|
-
"Invite people, edit members and
|
|
47
|
+
"Invite people, edit members and what they hold, sign them out, and create recovery links.",
|
|
27
48
|
},
|
|
28
49
|
{
|
|
29
50
|
id: "manage_teams",
|
|
30
51
|
scope: "admin.teams",
|
|
31
52
|
label: "Manage teams",
|
|
32
53
|
description:
|
|
33
|
-
"Create teams, change who is in them, and manage
|
|
54
|
+
"Create teams, change who is in them, and manage what they hold.",
|
|
34
55
|
},
|
|
35
56
|
{
|
|
36
57
|
id: "manage_webhooks",
|
|
@@ -62,48 +83,6 @@ export function hasWorkspacePermission(
|
|
|
62
83
|
return user.role === "admin" || user.permissions.includes(permission);
|
|
63
84
|
}
|
|
64
85
|
|
|
65
|
-
/**
|
|
66
|
-
* Where an address's mail goes: its own mailbox (inbox), every team member's
|
|
67
|
-
* own mailbox (list, team addresses only), another mailbox (alias), or
|
|
68
|
-
* outside addresses (forward).
|
|
69
|
-
*/
|
|
70
|
-
export const mailboxDeliveries = ["inbox", "list", "alias", "forward"] as const;
|
|
71
|
-
|
|
72
|
-
/** Outside addresses one `forward` address may send each message on to. */
|
|
73
|
-
export const MAX_FORWARD_DESTINATIONS = 5;
|
|
74
|
-
|
|
75
|
-
export type MailboxDelivery = (typeof mailboxDeliveries)[number];
|
|
76
|
-
|
|
77
|
-
/** What an alias may deliver into: an address that takes mail itself. */
|
|
78
|
-
const ALIAS_TARGET_DELIVERIES = ["inbox", "list"] as const;
|
|
79
|
-
|
|
80
|
-
/** Whether an alias may deliver into an address delivering this way. */
|
|
81
|
-
export function isAliasTarget(delivery: MailboxDelivery) {
|
|
82
|
-
return ALIAS_TARGET_DELIVERIES.some((target) => target === delivery);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export const listPostingPolicies = ["anyone", "workspace", "members"] as const;
|
|
86
|
-
|
|
87
|
-
export type ListPostingPolicy = (typeof listPostingPolicies)[number];
|
|
88
|
-
|
|
89
|
-
export const listPostingCopy: Record<
|
|
90
|
-
ListPostingPolicy,
|
|
91
|
-
{ label: string; description: string }
|
|
92
|
-
> = {
|
|
93
|
-
anyone: {
|
|
94
|
-
label: "Anyone",
|
|
95
|
-
description: "Any sender, including people outside the workspace.",
|
|
96
|
-
},
|
|
97
|
-
workspace: {
|
|
98
|
-
label: "Workspace",
|
|
99
|
-
description: "Only verified mail from the workspace's own addresses.",
|
|
100
|
-
},
|
|
101
|
-
members: {
|
|
102
|
-
label: "Members",
|
|
103
|
-
description: "Only verified mail from people on the team.",
|
|
104
|
-
},
|
|
105
|
-
};
|
|
106
|
-
|
|
107
86
|
/**
|
|
108
87
|
* The workspace logo an administrator uploads for the screens around signing
|
|
109
88
|
* in. Raster only: an SVG could carry script.
|
|
@@ -20,7 +20,10 @@ import {
|
|
|
20
20
|
describePlan,
|
|
21
21
|
directorySchema,
|
|
22
22
|
planDirectory,
|
|
23
|
-
|
|
23
|
+
adminMailboxesSchema,
|
|
24
|
+
adminStateSchema,
|
|
25
|
+
SEND_MAIL,
|
|
26
|
+
workspaceState,
|
|
24
27
|
} from "./plan.ts";
|
|
25
28
|
import type { Action, Directory, Plan, WorkspaceState } from "./plan.ts";
|
|
26
29
|
|
|
@@ -69,6 +72,8 @@ type ApplyContext = {
|
|
|
69
72
|
workspace: Workspace;
|
|
70
73
|
userIds: Map<string, string>;
|
|
71
74
|
failedTeams: Set<string>;
|
|
75
|
+
/** Every team permission there is, for the members the plan adds. */
|
|
76
|
+
teamPermissions: readonly string[];
|
|
72
77
|
aliasTargets?: Map<string, WorkspaceState["mailboxes"][number]>;
|
|
73
78
|
invites?: ReturnType<typeof invitationFile>;
|
|
74
79
|
};
|
|
@@ -95,17 +100,36 @@ function memberSlices<T>(members: T[]) {
|
|
|
95
100
|
return slices;
|
|
96
101
|
}
|
|
97
102
|
|
|
98
|
-
/**
|
|
103
|
+
/** The workspace's people, teams and addresses, as the plan reads them. */
|
|
104
|
+
async function loadWorkspaceState(workspace: Workspace) {
|
|
105
|
+
const [admin, addresses] = await Promise.all([
|
|
106
|
+
workspace.json("/api/admin/state", adminStateSchema),
|
|
107
|
+
workspace.json("/api/admin/mailboxes", adminMailboxesSchema),
|
|
108
|
+
]);
|
|
109
|
+
|
|
110
|
+
return workspaceState(admin, addresses);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Resolve the planned memberships after invitations have supplied their
|
|
115
|
+
* user IDs: a member who may send holds every team permission, one who may
|
|
116
|
+
* only read every one but sending.
|
|
117
|
+
*/
|
|
99
118
|
function teamMembers(
|
|
100
119
|
action: Extract<Action, { memberEmails: string[] }>,
|
|
101
|
-
userIds: Map<string, string
|
|
120
|
+
userIds: Map<string, string>,
|
|
121
|
+
teamPermissions: readonly string[]
|
|
102
122
|
) {
|
|
123
|
+
const permissions = action.canSend
|
|
124
|
+
? [...teamPermissions]
|
|
125
|
+
: teamPermissions.filter((permission) => permission !== SEND_MAIL);
|
|
126
|
+
|
|
103
127
|
return action.memberEmails.map((email) => {
|
|
104
128
|
const userId = userIds.get(email);
|
|
105
129
|
|
|
106
130
|
if (!userId) throw new Error(`Team member ${email} was not imported`);
|
|
107
131
|
|
|
108
|
-
return { userId,
|
|
132
|
+
return { userId, permissions };
|
|
109
133
|
});
|
|
110
134
|
}
|
|
111
135
|
|
|
@@ -117,7 +141,7 @@ function teamMembers(
|
|
|
117
141
|
async function addTeamMembers(
|
|
118
142
|
workspace: Workspace,
|
|
119
143
|
teamId: string,
|
|
120
|
-
slices: { userId: string;
|
|
144
|
+
slices: { userId: string; permissions: string[] }[][]
|
|
121
145
|
) {
|
|
122
146
|
for (const added of slices) {
|
|
123
147
|
// oxlint-disable-next-line eslint/no-await-in-loop -- one request at a time adds a big group's members in order, each within the API's limit
|
|
@@ -135,11 +159,9 @@ async function addTeamMembers(
|
|
|
135
159
|
* still invited (their invitation was saved, its answer lost), else null.
|
|
136
160
|
*/
|
|
137
161
|
async function savedInvitationLink(workspace: Workspace, email: string) {
|
|
138
|
-
const state = await workspace
|
|
162
|
+
const state = await loadWorkspaceState(workspace);
|
|
139
163
|
|
|
140
|
-
const person = state.users.find(
|
|
141
|
-
(user) => user.personalEmail?.toLowerCase() === email
|
|
142
|
-
);
|
|
164
|
+
const person = state.users.find((user) => user.email.toLowerCase() === email);
|
|
143
165
|
|
|
144
166
|
if (person?.status !== "invited") return null;
|
|
145
167
|
|
|
@@ -216,10 +238,7 @@ async function applyAction(action: Action, context: ApplyContext) {
|
|
|
216
238
|
|
|
217
239
|
case "alias": {
|
|
218
240
|
if (!context.aliasTargets) {
|
|
219
|
-
const state = await workspace
|
|
220
|
-
"/api/admin/state",
|
|
221
|
-
workspaceStateSchema
|
|
222
|
-
);
|
|
241
|
+
const state = await loadWorkspaceState(workspace);
|
|
223
242
|
|
|
224
243
|
context.aliasTargets = mailboxesByAddress(state.mailboxes);
|
|
225
244
|
}
|
|
@@ -252,7 +271,10 @@ async function applyAction(action: Action, context: ApplyContext) {
|
|
|
252
271
|
}
|
|
253
272
|
|
|
254
273
|
case "team": {
|
|
255
|
-
const slices = memberSlices(
|
|
274
|
+
const slices = memberSlices(
|
|
275
|
+
teamMembers(action, userIds, context.teamPermissions)
|
|
276
|
+
);
|
|
277
|
+
|
|
256
278
|
const [first = [], ...rest] = slices;
|
|
257
279
|
|
|
258
280
|
let teamId: string;
|
|
@@ -278,10 +300,7 @@ async function applyAction(action: Action, context: ApplyContext) {
|
|
|
278
300
|
}
|
|
279
301
|
|
|
280
302
|
// Only our reproducible ID proves that a lost response created this team.
|
|
281
|
-
const state = await workspace
|
|
282
|
-
"/api/admin/state",
|
|
283
|
-
workspaceStateSchema
|
|
284
|
-
);
|
|
303
|
+
const state = await loadWorkspaceState(workspace);
|
|
285
304
|
|
|
286
305
|
if (!state.teams.some((team) => team.id === action.teamId)) throw error;
|
|
287
306
|
teamId = action.teamId;
|
|
@@ -300,7 +319,7 @@ async function applyAction(action: Action, context: ApplyContext) {
|
|
|
300
319
|
await addTeamMembers(
|
|
301
320
|
workspace,
|
|
302
321
|
action.teamId,
|
|
303
|
-
memberSlices(teamMembers(action, userIds))
|
|
322
|
+
memberSlices(teamMembers(action, userIds, context.teamPermissions))
|
|
304
323
|
);
|
|
305
324
|
break;
|
|
306
325
|
}
|
|
@@ -339,11 +358,10 @@ async function applyPlan(
|
|
|
339
358
|
const context: ApplyContext = {
|
|
340
359
|
workspace,
|
|
341
360
|
userIds: new Map(
|
|
342
|
-
state.users.
|
|
343
|
-
user.personalEmail ? [[user.personalEmail.toLowerCase(), user.id]] : []
|
|
344
|
-
)
|
|
361
|
+
state.users.map((user) => [user.email.toLowerCase(), user.id])
|
|
345
362
|
),
|
|
346
363
|
failedTeams: new Set(),
|
|
364
|
+
teamPermissions: state.teamPermissions,
|
|
347
365
|
aliasTargets: mailboxesByAddress(state.mailboxes),
|
|
348
366
|
invites,
|
|
349
367
|
};
|
|
@@ -476,7 +494,7 @@ export async function peopleCommand(args: string[], deps: CliDeps) {
|
|
|
476
494
|
|
|
477
495
|
const workspace = await connect(values, DIRECTORY_SCOPES, deps);
|
|
478
496
|
|
|
479
|
-
const state = await workspace
|
|
497
|
+
const state = await loadWorkspaceState(workspace);
|
|
480
498
|
|
|
481
499
|
return importDirectory(directory, workspace, state, values, log);
|
|
482
500
|
}
|
package/import/directory/plan.ts
CHANGED
|
@@ -46,26 +46,20 @@ export const directorySchema = z.object({
|
|
|
46
46
|
|
|
47
47
|
export type Directory = z.infer<typeof directorySchema>;
|
|
48
48
|
|
|
49
|
-
/** What the workspace
|
|
50
|
-
export const
|
|
51
|
-
/** `
|
|
52
|
-
|
|
49
|
+
/** What the workspace has about people and teams (GET /api/admin/state, trimmed). */
|
|
50
|
+
export const adminStateSchema = z.object({
|
|
51
|
+
/** `domains` from alchemy.run.ts, primary first: where new addresses may go. */
|
|
52
|
+
domains: z.array(z.string()),
|
|
53
53
|
users: z.array(
|
|
54
54
|
z.object({
|
|
55
55
|
id: z.string(),
|
|
56
56
|
name: z.string(),
|
|
57
|
-
|
|
57
|
+
/** What they sign in as: their primary address. */
|
|
58
|
+
email: z.string(),
|
|
58
59
|
status: z.string(),
|
|
59
60
|
})
|
|
60
61
|
),
|
|
61
|
-
|
|
62
|
-
z.object({
|
|
63
|
-
id: z.string(),
|
|
64
|
-
address: z.string(),
|
|
65
|
-
ownerUserId: z.string().nullable(),
|
|
66
|
-
teamId: z.string().nullable(),
|
|
67
|
-
})
|
|
68
|
-
),
|
|
62
|
+
teamPermissions: z.array(z.object({ id: z.string() })),
|
|
69
63
|
teams: z.array(
|
|
70
64
|
z.object({
|
|
71
65
|
id: z.string(),
|
|
@@ -73,12 +67,60 @@ export const workspaceStateSchema = z.object({
|
|
|
73
67
|
name: z.string(),
|
|
74
68
|
/** A team for everyone keeps no members. */
|
|
75
69
|
everyone: z.boolean(),
|
|
76
|
-
members: z.array(
|
|
70
|
+
members: z.array(
|
|
71
|
+
z.object({ userId: z.string(), permissions: z.array(z.string()) })
|
|
72
|
+
),
|
|
73
|
+
})
|
|
74
|
+
),
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
/** The mail module's addresses (GET /api/admin/mailboxes, trimmed). */
|
|
78
|
+
export const adminMailboxesSchema = z.object({
|
|
79
|
+
mailboxes: z.array(
|
|
80
|
+
z.object({
|
|
81
|
+
id: z.string(),
|
|
82
|
+
address: z.string(),
|
|
83
|
+
ownerUserId: z.string().nullable(),
|
|
84
|
+
teamId: z.string().nullable(),
|
|
77
85
|
})
|
|
78
86
|
),
|
|
79
87
|
});
|
|
80
88
|
|
|
81
|
-
|
|
89
|
+
/** Mail's team permission: a member may send from the team's addresses. */
|
|
90
|
+
export const SEND_MAIL = "send_mail";
|
|
91
|
+
|
|
92
|
+
/** What the workspace already has, as the plan reads it. */
|
|
93
|
+
export type WorkspaceState = Omit<
|
|
94
|
+
z.infer<typeof adminStateSchema>,
|
|
95
|
+
"teams" | "teamPermissions"
|
|
96
|
+
> &
|
|
97
|
+
z.infer<typeof adminMailboxesSchema> & {
|
|
98
|
+
/** Every team permission there is: what a member who may send holds. */
|
|
99
|
+
teamPermissions: string[];
|
|
100
|
+
teams: (Omit<
|
|
101
|
+
z.infer<typeof adminStateSchema>["teams"][number],
|
|
102
|
+
"members"
|
|
103
|
+
> & { members: { userId: string; canSend: boolean }[] })[];
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
/** The workspace's state, from its people and teams and its addresses. */
|
|
107
|
+
export function workspaceState(
|
|
108
|
+
admin: z.infer<typeof adminStateSchema>,
|
|
109
|
+
addresses: z.infer<typeof adminMailboxesSchema>
|
|
110
|
+
) {
|
|
111
|
+
return {
|
|
112
|
+
...admin,
|
|
113
|
+
...addresses,
|
|
114
|
+
teamPermissions: admin.teamPermissions.map((permission) => permission.id),
|
|
115
|
+
teams: admin.teams.map((team) => ({
|
|
116
|
+
...team,
|
|
117
|
+
members: team.members.map((member) => ({
|
|
118
|
+
userId: member.userId,
|
|
119
|
+
canSend: member.permissions.includes(SEND_MAIL),
|
|
120
|
+
})),
|
|
121
|
+
})),
|
|
122
|
+
} satisfies WorkspaceState;
|
|
123
|
+
}
|
|
82
124
|
|
|
83
125
|
export type PlanOptions = {
|
|
84
126
|
includeSuspended: boolean;
|
|
@@ -265,13 +307,10 @@ export function planDirectory(
|
|
|
265
307
|
state: WorkspaceState,
|
|
266
308
|
options: PlanOptions
|
|
267
309
|
) {
|
|
268
|
-
const domains = new Set(state.
|
|
310
|
+
const domains = new Set(state.domains.map((domain) => normalize(domain)));
|
|
269
311
|
|
|
270
312
|
const owners = new Map(
|
|
271
|
-
state.users.map((user) => [
|
|
272
|
-
user.id,
|
|
273
|
-
normalize(user.personalEmail ?? user.id),
|
|
274
|
-
])
|
|
313
|
+
state.users.map((user) => [user.id, normalize(user.email)])
|
|
275
314
|
);
|
|
276
315
|
|
|
277
316
|
const teamNames = new Map(state.teams.map((team) => [team.id, team.name]));
|
|
@@ -291,27 +330,19 @@ export function planDirectory(
|
|
|
291
330
|
return team ? `team ${team}` : owner;
|
|
292
331
|
}
|
|
293
332
|
|
|
294
|
-
const knownPeople = new Set(
|
|
295
|
-
state.users.flatMap((user) =>
|
|
296
|
-
user.personalEmail ? [normalize(user.personalEmail)] : []
|
|
297
|
-
)
|
|
298
|
-
);
|
|
333
|
+
const knownPeople = new Set(state.users.map((user) => normalize(user.email)));
|
|
299
334
|
|
|
300
335
|
/** People here a team may take: not a disabled account. */
|
|
301
336
|
const joinable = new Set(
|
|
302
337
|
state.users.flatMap((user) =>
|
|
303
|
-
|
|
304
|
-
? [normalize(user.personalEmail)]
|
|
305
|
-
: []
|
|
338
|
+
joinableStatuses.has(user.status) ? [normalize(user.email)] : []
|
|
306
339
|
)
|
|
307
340
|
);
|
|
308
341
|
|
|
309
342
|
const existingSlugs = new Set(state.teams.map((team) => team.slug));
|
|
310
343
|
|
|
311
344
|
const userIdOf = new Map(
|
|
312
|
-
state.users.
|
|
313
|
-
user.personalEmail ? [[normalize(user.personalEmail), user.id]] : []
|
|
314
|
-
)
|
|
345
|
+
state.users.map((user) => [normalize(user.email), user.id])
|
|
315
346
|
);
|
|
316
347
|
|
|
317
348
|
const aliases: Extract<Action, { kind: "alias" }>[] = [];
|
|
@@ -350,7 +381,7 @@ export function planDirectory(
|
|
|
350
381
|
if (!inWorkspace(email)) {
|
|
351
382
|
plan.skipped.push({
|
|
352
383
|
what: email,
|
|
353
|
-
reason: `${domainOf(email)} is not one of the workspace's
|
|
384
|
+
reason: `${domainOf(email)} is not one of the workspace's domains`,
|
|
354
385
|
});
|
|
355
386
|
continue;
|
|
356
387
|
}
|
|
@@ -547,7 +578,7 @@ export function planDirectory(
|
|
|
547
578
|
if (!inWorkspace(address)) {
|
|
548
579
|
plan.skipped.push({
|
|
549
580
|
what: address,
|
|
550
|
-
reason: `${domainOf(address)} is not one of the workspace's
|
|
581
|
+
reason: `${domainOf(address)} is not one of the workspace's domains`,
|
|
551
582
|
});
|
|
552
583
|
} else if (addressOwners.has(address)) {
|
|
553
584
|
plan.existing.push(address);
|
package/import/idp/command.ts
CHANGED
|
@@ -4,7 +4,11 @@ import { parseCliArgs } from "../args.ts";
|
|
|
4
4
|
import { commonOptions, connect, UsageError } from "../cli.ts";
|
|
5
5
|
import type { CliDeps } from "../cli.ts";
|
|
6
6
|
import { importDirectory } from "../directory/command.ts";
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
adminMailboxesSchema,
|
|
9
|
+
adminStateSchema,
|
|
10
|
+
workspaceState,
|
|
11
|
+
} from "../directory/plan.ts";
|
|
8
12
|
import { DIRECTORY_SCOPES } from "../protocol.ts";
|
|
9
13
|
import { appStateSchema, importApps, metadataApp, planApps } from "./apps.ts";
|
|
10
14
|
import { readDirectoryCsv } from "./csv.ts";
|
|
@@ -146,12 +150,17 @@ export async function idpCommand(args: string[], deps: CliDeps) {
|
|
|
146
150
|
|
|
147
151
|
const workspace = await connect(values, scopes, deps);
|
|
148
152
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
153
|
+
// One read of the state serves both the apps and the directory.
|
|
154
|
+
const [admin, addresses] = await Promise.all([
|
|
155
|
+
workspace.json(
|
|
156
|
+
"/api/admin/state",
|
|
157
|
+
adminStateSchema.extend(appStateSchema.shape)
|
|
158
|
+
),
|
|
159
|
+
workspace.json("/api/admin/mailboxes", adminMailboxesSchema),
|
|
160
|
+
]);
|
|
161
|
+
|
|
162
|
+
const planned = await planApps(workspace, result.apps, admin, log);
|
|
163
|
+
const state = workspaceState(admin, addresses);
|
|
155
164
|
|
|
156
165
|
const failed = await importDirectory(
|
|
157
166
|
result.directory,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-workspace/create",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Create an OpenWorkspace deployment (`bun create @open-workspace`), and import people, teams, SSO apps and mail.",
|
|
5
5
|
"homepage": "https://openworkspace.dev",
|
|
6
6
|
"license": "Apache-2.0",
|
package/setup/args.ts
CHANGED
|
@@ -18,7 +18,7 @@ export type CreateOptions = {
|
|
|
18
18
|
/** Alchemy profile to sign in with; defaults to $ALCHEMY_PROFILE, else "default". */
|
|
19
19
|
profile?: string;
|
|
20
20
|
/** Mail domains, primary first. */
|
|
21
|
-
|
|
21
|
+
domains?: string[];
|
|
22
22
|
hostname?: string;
|
|
23
23
|
ai?: AiChoice;
|
|
24
24
|
deploy: boolean;
|
|
@@ -38,7 +38,7 @@ Options:
|
|
|
38
38
|
--account <id or name> Cloudflare account to deploy to
|
|
39
39
|
--profile <name> Alchemy profile to sign in with
|
|
40
40
|
(default: $ALCHEMY_PROFILE, else "default")
|
|
41
|
-
--
|
|
41
|
+
--domains <list> The workspace's domains, primary first, comma-separated:
|
|
42
42
|
zones in the account
|
|
43
43
|
--hostname <host> Where the app is served (default: workspace.<primary>)
|
|
44
44
|
--ai <provider> cloudflare (default), openai, anthropic or none;
|
|
@@ -55,7 +55,7 @@ an earlier run), or CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID.`;
|
|
|
55
55
|
const options = {
|
|
56
56
|
account: { type: "string" },
|
|
57
57
|
profile: { type: "string" },
|
|
58
|
-
|
|
58
|
+
domains: { type: "string" },
|
|
59
59
|
hostname: { type: "string" },
|
|
60
60
|
ai: { type: "string" },
|
|
61
61
|
"no-deploy": { type: "boolean" },
|
|
@@ -92,20 +92,18 @@ export function parseCreateArgs(args: readonly string[]) {
|
|
|
92
92
|
return { error: `--ai must be one of ${AI_CHOICES.join(", ")}` };
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
const
|
|
96
|
-
values
|
|
97
|
-
? undefined
|
|
98
|
-
: parseDomainList(values["mail-domains"]);
|
|
95
|
+
const domains =
|
|
96
|
+
values.domains === undefined ? undefined : parseDomainList(values.domains);
|
|
99
97
|
|
|
100
|
-
if (
|
|
101
|
-
return { error: "--
|
|
98
|
+
if (domains?.length === 0) {
|
|
99
|
+
return { error: "--domains needs at least one domain" };
|
|
102
100
|
}
|
|
103
101
|
|
|
104
102
|
const createOptions: CreateOptions = {
|
|
105
103
|
name: positionals[0],
|
|
106
104
|
account: values.account,
|
|
107
105
|
profile: values.profile,
|
|
108
|
-
|
|
106
|
+
domains,
|
|
109
107
|
hostname: values.hostname?.trim().toLowerCase(),
|
|
110
108
|
ai,
|
|
111
109
|
deploy: !values["no-deploy"],
|
package/setup/flow.ts
CHANGED
|
@@ -135,10 +135,10 @@ export async function runCreate(options: CreateOptions, deps: CreateDeps) {
|
|
|
135
135
|
|
|
136
136
|
const api = deps.cloudflare(credentials.auth);
|
|
137
137
|
|
|
138
|
-
const mail = await
|
|
138
|
+
const mail = await chooseDomains(
|
|
139
139
|
zones,
|
|
140
140
|
api,
|
|
141
|
-
options.
|
|
141
|
+
options.domains,
|
|
142
142
|
[],
|
|
143
143
|
options.deploy,
|
|
144
144
|
deps
|
|
@@ -162,7 +162,7 @@ export async function runCreate(options: CreateOptions, deps: CreateDeps) {
|
|
|
162
162
|
const answers: ProjectAnswers = {
|
|
163
163
|
name,
|
|
164
164
|
hostname,
|
|
165
|
-
|
|
165
|
+
domains: mail.domains,
|
|
166
166
|
ai: ai.choice,
|
|
167
167
|
cloudflare: {
|
|
168
168
|
account,
|
|
@@ -273,7 +273,7 @@ function projectName(options: CreateOptions, deps: CreateDeps) {
|
|
|
273
273
|
|
|
274
274
|
/** Writes package.json and installs it: signing in uses the project's own Alchemy. */
|
|
275
275
|
async function install(name: string, directory: string, deps: CreateDeps) {
|
|
276
|
-
const answers = { name, hostname: "",
|
|
276
|
+
const answers = { name, hostname: "", domains: [], ai: "none" as const };
|
|
277
277
|
|
|
278
278
|
writeFileSync(join(directory, "package.json"), packageJson(answers));
|
|
279
279
|
writeFileSync(join(directory, "tsconfig.json"), tsconfigJson);
|
|
@@ -651,7 +651,7 @@ async function uniqueProfileName(name: string, alchemy: ProjectAlchemy) {
|
|
|
651
651
|
}
|
|
652
652
|
|
|
653
653
|
/** Mail domains, primary first, chosen from the account's zones; warns about another provider's MX records. */
|
|
654
|
-
async function
|
|
654
|
+
async function chooseDomains(
|
|
655
655
|
zones: Zone[],
|
|
656
656
|
api: CloudflareApi,
|
|
657
657
|
requested: string[] | undefined,
|
|
@@ -670,7 +670,7 @@ async function chooseMailDomains(
|
|
|
670
670
|
);
|
|
671
671
|
|
|
672
672
|
if (outcome === "back") {
|
|
673
|
-
return
|
|
673
|
+
return chooseDomains(
|
|
674
674
|
zones,
|
|
675
675
|
api,
|
|
676
676
|
undefined,
|
|
@@ -825,7 +825,7 @@ async function pickMailZones(
|
|
|
825
825
|
|
|
826
826
|
if (!deps.interactive) {
|
|
827
827
|
throw new Stop(
|
|
828
|
-
"Say which zones are mail domains with --
|
|
828
|
+
"Say which zones are mail domains with --domains, primary first.",
|
|
829
829
|
`Zones: ${zones.map((zone) => zone.name).join(", ")}`
|
|
830
830
|
);
|
|
831
831
|
}
|
package/templates.ts
CHANGED
|
@@ -4,7 +4,7 @@ export type ProjectAnswers = {
|
|
|
4
4
|
/** Hostname the app is served on, e.g. "workspace.acme.com". */
|
|
5
5
|
hostname: string;
|
|
6
6
|
/** Mail domains, primary first. */
|
|
7
|
-
|
|
7
|
+
domains: string[];
|
|
8
8
|
ai: "none" | "cloudflare" | "openai" | "anthropic";
|
|
9
9
|
/** Where it deploys: the Cloudflare account, and the Alchemy profile signed in to it (none with environment credentials). */
|
|
10
10
|
cloudflare?: {
|
|
@@ -14,7 +14,7 @@ export type ProjectAnswers = {
|
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
export const versions = {
|
|
17
|
-
openWorkspace: "0.
|
|
17
|
+
openWorkspace: "0.7.0",
|
|
18
18
|
alchemy: "2.0.0-beta.87",
|
|
19
19
|
effect: "4.1.7",
|
|
20
20
|
typescript: "7.0.2",
|
|
@@ -151,7 +151,7 @@ export default Alchemy.Stack(
|
|
|
151
151
|
hostname: ${JSON.stringify(answers.hostname)},
|
|
152
152
|
// Mail domains, primary first. Every address is on one of them.
|
|
153
153
|
// Email() turns on Email Routing and Email Sending for each.
|
|
154
|
-
|
|
154
|
+
domains: ${JSON.stringify(answers.domains)},${ai}
|
|
155
155
|
modules: [Email()],
|
|
156
156
|
// \`bun run dev\` serves the workspace at http://localhost:5173, where
|
|
157
157
|
// passkeys work too; the hostname above is only for the deploy.
|
|
@@ -238,9 +238,9 @@ changes this one workspace. Use the scripts, not a bare \`alchemy deploy\`: that
|
|
|
238
238
|
deploys stage \`live_<your user>\`, a second, empty workspace on the same domains.
|
|
239
239
|
|
|
240
240
|
Open https://${answers.hostname} and create the first administrator with a passkey,
|
|
241
|
-
using an address on ${answers.
|
|
241
|
+
using an address on ${answers.domains[0]}.
|
|
242
242
|
|
|
243
|
-
Alchemy turns on Email Routing for ${answers.
|
|
243
|
+
Alchemy turns on Email Routing for ${answers.domains.join(", ")}, sends every
|
|
244
244
|
address to the Worker, onboards the mail domains to Email Sending, and subscribes
|
|
245
245
|
the delivery events queue. Email Routing adds the zones' MX and SPF records and
|
|
246
246
|
locks them; remove another mail provider's MX records from a zone first, or the
|