@open-workspace/create 0.2.0 → 0.3.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/README.md CHANGED
@@ -6,7 +6,8 @@ bun create @open-workspace
6
6
 
7
7
  Asks for a project name, your mail domains, where the app is served, and an AI
8
8
  provider, then writes a small project: `package.json`, `src/worker.ts`,
9
- `alchemy.run.ts`, and a `.env` with freshly generated OIDC and web push keys.
9
+ `alchemy.run.ts`, and a `.env` for API keys. Signing and push keys are minted by
10
+ Alchemy on the first deploy.
10
11
  Deploy it to your Cloudflare account with `bun run deploy`.
11
12
 
12
13
  See [openworkspace.dev](https://openworkspace.dev).
package/index.ts CHANGED
@@ -2,7 +2,6 @@
2
2
  import { existsSync, mkdirSync, readdirSync, writeFileSync } from "node:fs";
3
3
  import { join, resolve } from "node:path";
4
4
  import * as p from "@clack/prompts";
5
- import { oidcSigningKey, vapidKeys } from "./keys";
6
5
  import {
7
6
  alchemyRunTs,
8
7
  envFile,
@@ -90,12 +89,7 @@ const files: Record<string, string> = {
90
89
  "tsconfig.json": tsconfigJson,
91
90
  ".gitignore": gitignore,
92
91
  "README.md": readme(answers),
93
- ".env": envFile({
94
- oidcSigningKey: await oidcSigningKey(),
95
- vapid: await vapidKeys(),
96
- domain: mailDomains[0]!,
97
- aiKey,
98
- }),
92
+ ".env": envFile({ aiKey }),
99
93
  };
100
94
  for (const [file, content] of Object.entries(files)) {
101
95
  writeFileSync(join(directory, file), content);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-workspace/create",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Create an OpenWorkspace deployment: `bun create @open-workspace`.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
package/templates.ts CHANGED
@@ -11,7 +11,7 @@ export type ProjectAnswers = {
11
11
  };
12
12
 
13
13
  export const versions = {
14
- openWorkspace: "0.2.0",
14
+ openWorkspace: "0.3.0",
15
15
  alchemy: "2.0.0-beta.84",
16
16
  effect: "4.0.7",
17
17
  typescript: "7.0.2",
@@ -117,12 +117,12 @@ export function alchemyRunTs(answers: ProjectAnswers) {
117
117
  : "Email()";
118
118
  return `import * as Cloudflare from "@alchemy.run/cloudflare";
119
119
  import * as Alchemy from "alchemy";
120
- import { OpenWorkspace } from "@open-workspace/core/alchemy";
120
+ import { OpenWorkspace, providers } from "@open-workspace/core/alchemy";
121
121
  import { Email } from "@open-workspace/email/alchemy";
122
122
 
123
123
  export default Alchemy.Stack(
124
124
  ${JSON.stringify(stackName(answers.name))},
125
- { providers: Cloudflare.providers(), state: Cloudflare.state() },
125
+ { providers: providers(), state: Cloudflare.state() },
126
126
  OpenWorkspace({
127
127
  name: ${JSON.stringify(answers.name)},
128
128
  main: "./src/worker.ts",
@@ -165,7 +165,7 @@ An [OpenWorkspace](https://openworkspace.dev) deployment on your Cloudflare acco
165
165
 
166
166
  - \`src/worker.ts\` — the workspace: mail domains, AI, and modules.
167
167
  - \`alchemy.run.ts\` — the Cloudflare resources, managed by [Alchemy](https://alchemy.run).
168
- - \`.env\` — secrets, uploaded as Worker secrets on deploy. Keep it out of git.
168
+ - \`.env\` — API keys for outside services, uploaded as Worker secrets on deploy. Keep it out of git. The OIDC and SAML signing keys and the push keys are minted by Alchemy on the first deploy and kept in its state.
169
169
 
170
170
  ## Deploy
171
171
 
@@ -197,28 +197,15 @@ bun run deploy
197
197
  `;
198
198
  }
199
199
 
200
- export function envFile(input: {
201
- oidcSigningKey: string;
202
- vapid: { publicKey: string; privateKey: string };
203
- domain: string;
204
- aiKey?: { name: string; value: string };
205
- }) {
200
+ export function envFile(input: { aiKey?: { name: string; value: string } }) {
206
201
  return [
207
- "# Uploaded as Worker secrets by `alchemy deploy`. Never commit this file.",
208
- "",
209
- "# Signs OpenID Connect ID tokens for apps that sign in with the workspace.",
210
- `OIDC_SIGNING_PRIVATE_JWK='${input.oidcSigningKey}'`,
211
- "",
212
- "# Web push for new-mail notifications.",
213
- `VAPID_PUBLIC_KEY=${input.vapid.publicKey}`,
214
- `VAPID_PRIVATE_KEY=${input.vapid.privateKey}`,
215
- `VAPID_SUBJECT=mailto:admin@${input.domain}`,
202
+ "# Secrets for outside services, uploaded as Worker secrets by `alchemy deploy`.",
203
+ "# Never commit this file. Signing keys need no entry: Alchemy mints them.",
216
204
  ...(input.aiKey ? ["", `${input.aiKey.name}=${input.aiKey.value}`] : []),
217
205
  "",
218
206
  "# Optional:",
219
207
  "# SPAMHAUS_DQS_KEY=",
220
- "# SAML_SIGNING_PRIVATE_KEY= / SAML_SIGNING_CERTIFICATE= (PEM) to act as a SAML identity provider",
221
- "# R2_ACCESS_KEY_ID= / R2_SECRET_ACCESS_KEY= / R2_ACCOUNT_ID= / R2_BUCKET_NAME= for direct attachment transfers",
208
+ "# R2_ACCESS_KEY_ID= / R2_SECRET_ACCESS_KEY= (an R2 API token for the mail bucket) for direct attachment transfers",
222
209
  "",
223
210
  ].join("\n");
224
211
  }
package/keys.ts DELETED
@@ -1,31 +0,0 @@
1
- function base64Url(bytes: ArrayBuffer | Uint8Array) {
2
- return Buffer.from(bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes)).toString("base64url");
3
- }
4
-
5
- /** RS256 private JWK for signing OIDC ID tokens (OIDC_SIGNING_PRIVATE_JWK). */
6
- export async function oidcSigningKey() {
7
- const pair = await crypto.subtle.generateKey(
8
- { name: "RSASSA-PKCS1-v1_5", modulusLength: 2048, publicExponent: new Uint8Array([1, 0, 1]), hash: "SHA-256" },
9
- true,
10
- ["sign", "verify"],
11
- );
12
- const jwk = await crypto.subtle.exportKey("jwk", pair.privateKey);
13
- // RFC 7638 thumbprint as the key id.
14
- const thumbprint = await crypto.subtle.digest(
15
- "SHA-256",
16
- new TextEncoder().encode(JSON.stringify({ e: jwk.e, kty: jwk.kty, n: jwk.n })),
17
- );
18
- const { key_ops: _ops, ext: _ext, ...rest } = jwk;
19
- return JSON.stringify({ ...rest, alg: "RS256", use: "sig", kid: base64Url(thumbprint) });
20
- }
21
-
22
- /** VAPID keys for web push: base64url P-256 public point and private scalar. */
23
- export async function vapidKeys() {
24
- const pair = await crypto.subtle.generateKey({ name: "ECDSA", namedCurve: "P-256" }, true, ["sign", "verify"]);
25
- const jwk = await crypto.subtle.exportKey("jwk", pair.privateKey);
26
- const point = new Uint8Array(65);
27
- point[0] = 4;
28
- point.set(Buffer.from(jwk.x!, "base64url"), 1);
29
- point.set(Buffer.from(jwk.y!, "base64url"), 33);
30
- return { publicKey: base64Url(point), privateKey: jwk.d! };
31
- }