@open-workspace/create 0.5.0 → 0.5.2
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/import/directory/command.ts +10 -1
- package/import/directory/google.ts +1 -1
- package/import/directory/invitation-file.ts +5 -7
- package/import/idp/command.ts +6 -0
- package/import/idp/okta.ts +3 -1
- package/import/mbox.ts +7 -7
- package/index.ts +5 -1
- package/module-templates.ts +5 -5
- package/package.json +7 -6
- package/templates.ts +11 -8
- package/update.ts +180 -0
|
@@ -190,7 +190,16 @@ async function applyAction(action: Action, context: ApplyContext) {
|
|
|
190
190
|
// The invitation may be saved with its answer lost (the request
|
|
191
191
|
// tried again then finds the address taken): someone here under
|
|
192
192
|
// the address, still invited, gets a new link in its place.
|
|
193
|
-
|
|
193
|
+
// A failed lookup clears the marker too, or every later invitation
|
|
194
|
+
// in this run would find it; a rerun asks again.
|
|
195
|
+
let saved: Awaited<ReturnType<typeof savedInvitationLink>>;
|
|
196
|
+
|
|
197
|
+
try {
|
|
198
|
+
saved = await savedInvitationLink(workspace, action.email);
|
|
199
|
+
} catch (lookupError) {
|
|
200
|
+
invites.clear();
|
|
201
|
+
throw lookupError;
|
|
202
|
+
}
|
|
194
203
|
|
|
195
204
|
if (!saved) {
|
|
196
205
|
invites.clear();
|
|
@@ -229,7 +229,7 @@ export function googleAccessToken(options: GoogleCredentialsOptions) {
|
|
|
229
229
|
|
|
230
230
|
return Promise.reject(
|
|
231
231
|
new Error(
|
|
232
|
-
"The Google credentials are neither a service account key nor a Desktop app OAuth client (see https://openworkspace.dev/docs/migration)"
|
|
232
|
+
"The Google credentials are neither a service account key nor a Desktop app OAuth client (see https://openworkspace.dev/docs/migration-google)"
|
|
233
233
|
)
|
|
234
234
|
);
|
|
235
235
|
}
|
|
@@ -52,13 +52,11 @@ export function invitationFile(path: string, origin: string) {
|
|
|
52
52
|
process.kill(pending.pid, 0);
|
|
53
53
|
throw new Error(`Another import is writing ${path}.`);
|
|
54
54
|
} catch (error) {
|
|
55
|
-
if (
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
)
|
|
61
|
-
) {
|
|
55
|
+
if (!(
|
|
56
|
+
error instanceof Error &&
|
|
57
|
+
"code" in error &&
|
|
58
|
+
error.code === "ESRCH"
|
|
59
|
+
)) {
|
|
62
60
|
throw error;
|
|
63
61
|
}
|
|
64
62
|
}
|
package/import/idp/command.ts
CHANGED
|
@@ -19,6 +19,10 @@ const HELP = `bunx @open-workspace/create import idp <source> --workspace <url>
|
|
|
19
19
|
csv --file <directory.csv> (header: type,name,email,groups)
|
|
20
20
|
saml --file <service provider metadata XML>
|
|
21
21
|
|
|
22
|
+
--groups <list|inbox> What groups with an address become (default list)
|
|
23
|
+
--include-suspended Also import suspended or disabled users
|
|
24
|
+
--invites <file.csv> Where invitation links go (default openworkspace-invitations.csv)
|
|
25
|
+
|
|
22
26
|
Invites people, creates teams and imports supported SSO apps disabled. Existing apps are skipped.
|
|
23
27
|
See https://openworkspace.dev/docs/migration for source permissions and the SSO cutover.`;
|
|
24
28
|
|
|
@@ -40,6 +44,8 @@ export async function idpCommand(args: string[], deps: CliDeps) {
|
|
|
40
44
|
tenant: { type: "string" },
|
|
41
45
|
"client-id": { type: "string" },
|
|
42
46
|
invites: { type: "string" },
|
|
47
|
+
groups: { type: "string" },
|
|
48
|
+
"include-suspended": { type: "boolean" },
|
|
43
49
|
},
|
|
44
50
|
});
|
|
45
51
|
|
package/import/idp/okta.ts
CHANGED
|
@@ -92,7 +92,9 @@ export async function readOkta(org: string, token: string, fetchImpl: Fetch) {
|
|
|
92
92
|
person(
|
|
93
93
|
u.profile.email,
|
|
94
94
|
[u.profile.firstName, u.profile.lastName].filter(Boolean).join(" "),
|
|
95
|
-
|
|
95
|
+
// Locked out, a password expired or being recovered: still people
|
|
96
|
+
// who work here.
|
|
97
|
+
["SUSPENDED", "DEPROVISIONED"].includes(u.status)
|
|
96
98
|
)
|
|
97
99
|
);
|
|
98
100
|
}
|
package/import/mbox.ts
CHANGED
|
@@ -163,7 +163,8 @@ const MONTHS = [
|
|
|
163
163
|
/**
|
|
164
164
|
* The date on an mbox "From " line, in ms: Gmail's Takeout writes when the
|
|
165
165
|
* message arrived there ("From 1781…@xxx Tue Mar 03 10:00:00 +0000 2026").
|
|
166
|
-
*
|
|
166
|
+
* A classic ctime date has no zone and, from Thunderbird, is when the
|
|
167
|
+
* message was copied there: undefined, so the Date header counts instead.
|
|
167
168
|
*/
|
|
168
169
|
export function fromLineDate(fromLine: string) {
|
|
169
170
|
const match =
|
|
@@ -171,7 +172,7 @@ export function fromLineDate(fromLine: string) {
|
|
|
171
172
|
fromLine
|
|
172
173
|
);
|
|
173
174
|
|
|
174
|
-
if (!match) return undefined;
|
|
175
|
+
if (!match?.[6]) return undefined;
|
|
175
176
|
const [, monthName = ""] = match;
|
|
176
177
|
const month = MONTHS.indexOf(monthName.toLowerCase());
|
|
177
178
|
|
|
@@ -188,11 +189,10 @@ export function fromLineDate(fromLine: string) {
|
|
|
188
189
|
|
|
189
190
|
const zone = match[6];
|
|
190
191
|
|
|
191
|
-
const offset =
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
: 0;
|
|
192
|
+
const offset =
|
|
193
|
+
(zone[0] === "-" ? -1 : 1) *
|
|
194
|
+
(Number(zone.slice(1, 3)) * 60 + Number(zone.slice(3, 5))) *
|
|
195
|
+
60_000;
|
|
196
196
|
|
|
197
197
|
return utc - offset;
|
|
198
198
|
}
|
package/index.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// `bun create @open-workspace` writes a new project; `… module <name>` adds a
|
|
3
|
-
// module to one; `… import` brings people and mail into a deployed workspace
|
|
3
|
+
// module to one; `… import` brings people and mail into a deployed workspace;
|
|
4
|
+
// `… update` moves one to the latest release and deploys it.
|
|
4
5
|
if (process.argv[2] === "module") {
|
|
5
6
|
const { main } = await import("./module.ts");
|
|
6
7
|
process.exitCode = main(process.argv.slice(3));
|
|
7
8
|
} else if (process.argv[2] === "import") {
|
|
8
9
|
const { main } = await import("./import/cli.ts");
|
|
9
10
|
process.exitCode = await main(process.argv.slice(3));
|
|
11
|
+
} else if (process.argv[2] === "update") {
|
|
12
|
+
const { main } = await import("./update.ts");
|
|
13
|
+
process.exitCode = await main(process.argv.slice(3));
|
|
10
14
|
} else if (process.argv[2] === "restore-mx") {
|
|
11
15
|
const { main } = await import("./setup/mx-recovery.ts");
|
|
12
16
|
process.exitCode = await main(process.argv.slice(3));
|
package/module-templates.ts
CHANGED
|
@@ -11,17 +11,17 @@ export const MODULE_NAME = /^[a-z]+(?:-[a-z]+)*$/u;
|
|
|
11
11
|
|
|
12
12
|
/** What the generated module imports, at the versions core is built with. */
|
|
13
13
|
export const moduleDependencies = {
|
|
14
|
-
"@tanstack/react-query": "5.
|
|
14
|
+
"@tanstack/react-query": "5.108.4",
|
|
15
15
|
"drizzle-orm": "0.45.4",
|
|
16
|
-
hono: "4.13.
|
|
17
|
-
"lucide-react": "1.
|
|
16
|
+
hono: "4.13.23",
|
|
17
|
+
"lucide-react": "1.84.0",
|
|
18
18
|
react: "19.3.1",
|
|
19
|
-
"react-router": "8.5.
|
|
19
|
+
"react-router": "8.5.3",
|
|
20
20
|
zod: "4.6.7",
|
|
21
21
|
} satisfies Record<string, string>;
|
|
22
22
|
|
|
23
23
|
export const moduleDevDependencies = {
|
|
24
|
-
"@types/react": "19.3.
|
|
24
|
+
"@types/react": "19.3.3",
|
|
25
25
|
"drizzle-kit": "0.31.11",
|
|
26
26
|
} satisfies Record<string, string>;
|
|
27
27
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-workspace/create",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
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",
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"create.ts",
|
|
18
18
|
"templates.ts",
|
|
19
19
|
"module.ts",
|
|
20
|
+
"update.ts",
|
|
20
21
|
"setup",
|
|
21
22
|
"module-templates.ts",
|
|
22
23
|
"import",
|
|
@@ -42,14 +43,14 @@
|
|
|
42
43
|
},
|
|
43
44
|
"dependencies": {
|
|
44
45
|
"@clack/prompts": "1.9.0",
|
|
45
|
-
"imapflow": "2.
|
|
46
|
+
"imapflow": "2.12.2",
|
|
46
47
|
"zod": "4.6.7"
|
|
47
48
|
},
|
|
48
49
|
"devDependencies": {
|
|
49
|
-
"@alchemy.run/cloudflare": "2.0.0-beta.
|
|
50
|
-
"@types/bun": "1.4.
|
|
51
|
-
"alchemy": "2.0.0-beta.
|
|
52
|
-
"effect": "4.1.
|
|
50
|
+
"@alchemy.run/cloudflare": "2.0.0-beta.87",
|
|
51
|
+
"@types/bun": "1.4.5",
|
|
52
|
+
"alchemy": "2.0.0-beta.87",
|
|
53
|
+
"effect": "4.1.7",
|
|
53
54
|
"hoodiecrow-imap": "3.3.1",
|
|
54
55
|
"typescript": "7.0.2"
|
|
55
56
|
}
|
package/templates.ts
CHANGED
|
@@ -14,11 +14,11 @@ export type ProjectAnswers = {
|
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
export const versions = {
|
|
17
|
-
openWorkspace: "0.5.
|
|
18
|
-
alchemy: "2.0.0-beta.
|
|
19
|
-
effect: "4.1.
|
|
17
|
+
openWorkspace: "0.5.2",
|
|
18
|
+
alchemy: "2.0.0-beta.87",
|
|
19
|
+
effect: "4.1.7",
|
|
20
20
|
typescript: "7.0.2",
|
|
21
|
-
nodeTypes: "26.6.
|
|
21
|
+
nodeTypes: "26.6.11",
|
|
22
22
|
bun: "1.4.4",
|
|
23
23
|
};
|
|
24
24
|
|
|
@@ -31,6 +31,9 @@ export const versions = {
|
|
|
31
31
|
*/
|
|
32
32
|
export const DEPLOY_STAGE = "production";
|
|
33
33
|
|
|
34
|
+
/** The project's `update` script: the latest release, installed and deployed. */
|
|
35
|
+
export const UPDATE_SCRIPT = "bunx @open-workspace/create@latest update";
|
|
36
|
+
|
|
34
37
|
export function packageJson(answers: ProjectAnswers) {
|
|
35
38
|
return `${JSON.stringify(
|
|
36
39
|
{
|
|
@@ -44,6 +47,7 @@ export function packageJson(answers: ProjectAnswers) {
|
|
|
44
47
|
dev: "alchemy dev",
|
|
45
48
|
destroy: `alchemy destroy --stage ${DEPLOY_STAGE}`,
|
|
46
49
|
logs: `alchemy logs --tail --stage ${DEPLOY_STAGE}`,
|
|
50
|
+
update: UPDATE_SCRIPT,
|
|
47
51
|
},
|
|
48
52
|
dependencies: {
|
|
49
53
|
"@open-workspace/core": versions.openWorkspace,
|
|
@@ -255,10 +259,9 @@ passkey, as on the deployed app. Mail from outside doesn't reach it.
|
|
|
255
259
|
|
|
256
260
|
## Update
|
|
257
261
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
\`\`\`
|
|
262
|
+
\`bun run update\` moves OpenWorkspace to the latest release, with the Alchemy
|
|
263
|
+
and Effect versions it needs, installs it and deploys. Read the release's
|
|
264
|
+
upgrade notes first; Administration shows them when an update is available.
|
|
262
265
|
`;
|
|
263
266
|
}
|
|
264
267
|
|
package/update.ts
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join, resolve } from "node:path";
|
|
3
|
+
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
|
|
6
|
+
import { UPDATE_SCRIPT } from "./templates";
|
|
7
|
+
|
|
8
|
+
/** What npm says of @open-workspace/core's latest release. */
|
|
9
|
+
const latestSchema = z.object({
|
|
10
|
+
version: z.string(),
|
|
11
|
+
peerDependencies: z.record(z.string(), z.string()).default({}),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export type LatestRelease = z.infer<typeof latestSchema>;
|
|
15
|
+
|
|
16
|
+
const manifestSchema = z.looseObject({
|
|
17
|
+
scripts: z.record(z.string(), z.string()).optional(),
|
|
18
|
+
dependencies: z.record(z.string(), z.string()).optional(),
|
|
19
|
+
devDependencies: z.record(z.string(), z.string()).optional(),
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
/** The packages released together under one version. */
|
|
23
|
+
const OWN_PACKAGES = new Set(["@open-workspace/core", "@open-workspace/email"]);
|
|
24
|
+
|
|
25
|
+
/** Versioned with effect, though core doesn't name them. */
|
|
26
|
+
const EFFECT_PLATFORMS = new Set([
|
|
27
|
+
"@effect/platform-bun",
|
|
28
|
+
"@effect/platform-node",
|
|
29
|
+
]);
|
|
30
|
+
|
|
31
|
+
export type VersionChange = { name: string; from: string; to: string };
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The project's package.json moved to `latest`: OpenWorkspace's packages to
|
|
35
|
+
* its version, and Alchemy and Effect to the versions core was built with
|
|
36
|
+
* (it pins them as peers), with the `update` script added if missing.
|
|
37
|
+
*/
|
|
38
|
+
export function updatedManifest(text: string, latest: LatestRelease) {
|
|
39
|
+
const manifest = manifestSchema.parse(JSON.parse(text));
|
|
40
|
+
const changes: VersionChange[] = [];
|
|
41
|
+
|
|
42
|
+
const wanted = (name: string) => {
|
|
43
|
+
if (OWN_PACKAGES.has(name)) return latest.version;
|
|
44
|
+
|
|
45
|
+
if (EFFECT_PLATFORMS.has(name)) return latest.peerDependencies.effect;
|
|
46
|
+
|
|
47
|
+
return latest.peerDependencies[name];
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
for (const field of ["dependencies", "devDependencies"] as const) {
|
|
51
|
+
const deps = manifest[field];
|
|
52
|
+
|
|
53
|
+
if (!deps) continue;
|
|
54
|
+
|
|
55
|
+
for (const [name, from] of Object.entries(deps)) {
|
|
56
|
+
const to = wanted(name);
|
|
57
|
+
|
|
58
|
+
if (to && to !== from) {
|
|
59
|
+
deps[name] = to;
|
|
60
|
+
changes.push({ name, from, to });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const scripts = manifest.scripts ?? {};
|
|
66
|
+
const addsScript = !scripts.update;
|
|
67
|
+
|
|
68
|
+
if (addsScript) manifest.scripts = { ...scripts, update: UPDATE_SCRIPT };
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
text: `${JSON.stringify(manifest, null, 2)}\n`,
|
|
72
|
+
changes,
|
|
73
|
+
addsScript,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export type UpdateDeps = {
|
|
78
|
+
latest: () => Promise<LatestRelease>;
|
|
79
|
+
/** Runs a command in the project on this terminal; whether it succeeded. */
|
|
80
|
+
run: (command: string[]) => Promise<boolean>;
|
|
81
|
+
log: (line: string) => void;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const usage = `Usage: bunx @open-workspace/create update [--no-deploy] (or bun run update), in your workspace's project
|
|
85
|
+
|
|
86
|
+
Moves @open-workspace/core and email to the latest release, with the Alchemy
|
|
87
|
+
and Effect versions it needs, installs them and deploys.`;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* `bunx @open-workspace/create update`, run in a deployment project. Returns
|
|
91
|
+
* the exit code.
|
|
92
|
+
*/
|
|
93
|
+
export async function main(
|
|
94
|
+
args: string[],
|
|
95
|
+
cwd = process.cwd(),
|
|
96
|
+
deps: UpdateDeps = defaultDeps(cwd)
|
|
97
|
+
) {
|
|
98
|
+
const unknown = args.filter((arg) => arg !== "--no-deploy");
|
|
99
|
+
|
|
100
|
+
if (unknown.length) {
|
|
101
|
+
deps.log(usage);
|
|
102
|
+
|
|
103
|
+
return unknown.includes("--help") || unknown.includes("-h") ? 0 : 1;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const path = join(resolve(cwd), "package.json");
|
|
107
|
+
let text: string;
|
|
108
|
+
|
|
109
|
+
try {
|
|
110
|
+
text = readFileSync(path, "utf-8");
|
|
111
|
+
} catch {
|
|
112
|
+
deps.log(`No package.json here. ${usage}`);
|
|
113
|
+
|
|
114
|
+
return 1;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (!text.includes('"@open-workspace/core"')) {
|
|
118
|
+
deps.log(`This project doesn't use @open-workspace/core. ${usage}`);
|
|
119
|
+
|
|
120
|
+
return 1;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const latest = await deps.latest();
|
|
124
|
+
const updated = updatedManifest(text, latest);
|
|
125
|
+
|
|
126
|
+
if (!updated.changes.length) {
|
|
127
|
+
if (updated.addsScript) writeFileSync(path, updated.text);
|
|
128
|
+
deps.log(`Already on OpenWorkspace ${latest.version}.`);
|
|
129
|
+
|
|
130
|
+
return 0;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
for (const change of updated.changes) {
|
|
134
|
+
deps.log(`${change.name} ${change.from} → ${change.to}`);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
deps.log(
|
|
138
|
+
`What changed: https://github.com/iivankin/openworkspace/releases/tag/v${latest.version}`
|
|
139
|
+
);
|
|
140
|
+
writeFileSync(path, updated.text);
|
|
141
|
+
|
|
142
|
+
if (!(await deps.run([process.execPath, "install"]))) return 1;
|
|
143
|
+
|
|
144
|
+
if (args.includes("--no-deploy")) {
|
|
145
|
+
deps.log("Updated. Deploy with: bun run deploy");
|
|
146
|
+
|
|
147
|
+
return 0;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return (await deps.run([process.execPath, "run", "deploy"])) ? 0 : 1;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function defaultDeps(cwd: string) {
|
|
154
|
+
const deps: UpdateDeps = {
|
|
155
|
+
async latest() {
|
|
156
|
+
const response = await fetch(
|
|
157
|
+
"https://registry.npmjs.org/@open-workspace/core/latest"
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
if (!response.ok) {
|
|
161
|
+
throw new Error(`npm answered ${response.status}`);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return latestSchema.parse(await response.json());
|
|
165
|
+
},
|
|
166
|
+
async run(command) {
|
|
167
|
+
const child = Bun.spawn(command, {
|
|
168
|
+
cwd,
|
|
169
|
+
stdin: "inherit",
|
|
170
|
+
stdout: "inherit",
|
|
171
|
+
stderr: "inherit",
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
return (await child.exited) === 0;
|
|
175
|
+
},
|
|
176
|
+
log: console.log,
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
return deps;
|
|
180
|
+
}
|