create-mailslot 0.1.0 → 0.2.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/lib/run.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { randomBytes } from "node:crypto";
2
+ import { readFileSync } from "node:fs";
2
3
  import { writeFile } from "node:fs/promises";
3
4
  import { join, resolve } from "node:path";
4
5
  import * as p from "@clack/prompts";
@@ -7,6 +8,10 @@ import { mxRecords, isCloudflareMx, isCloudflareNs, findZone, waitForCloudflareM
7
8
  import { templates, writeScaffold } from "./scaffold.js";
8
9
  import { zoneId, routingStatus, enableRouting, setCatchAllToWorker } from "./cf-api.js";
9
10
 
11
+ // Wizard and core ship in lockstep (same repo version), so the inbox we
12
+ // scaffold should depend on the core that matches THIS wizard's version.
13
+ const selfVersion = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
14
+
10
15
  export function parseArgs(argv) {
11
16
  const flags = {};
12
17
  for (let i = 0; i < argv.length; i++) {
@@ -133,7 +138,7 @@ export async function run(argv) {
133
138
  const routingReady = isCloudflareMx(domainMx);
134
139
 
135
140
  // ---- scaffold ----
136
- const coreSpec = flags["core-spec"] ?? "^0.0.2";
141
+ const coreSpec = flags["core-spec"] ?? `^${selfVersion}`;
137
142
  const files = templates({ workerName, coreSpec });
138
143
  await writeScaffold(dir, files);
139
144
  p.log.success(`Scaffolded ${dir}`);
@@ -154,6 +159,24 @@ export async function run(argv) {
154
159
  if (code !== 0) throw new Error("wrangler login failed");
155
160
  }
156
161
 
162
+ // ---- existing-instance guard ----
163
+ // Re-running against a live worker rotates MAILSLOT_TOKEN (existing
164
+ // API/MCP clients break until updated) and replaces the deployed code.
165
+ // Inbox data survives: same worker name + DO classes + R2 bucket.
166
+ const existing = await wrangler(["deployments", "list"]);
167
+ if (existing.code === 0) {
168
+ p.log.warn(
169
+ `A worker named "${workerName}" is already deployed on this account.\n` +
170
+ `Continuing will:\n` +
171
+ ` • rotate MAILSLOT_TOKEN — existing API/MCP clients stop working\n` +
172
+ ` until you give them the new token\n` +
173
+ ` • replace the deployed code with @mailslot/core ${coreSpec}\n` +
174
+ `Inbox data (messages, raw mail) is preserved.`
175
+ );
176
+ const overwrite = bail(await p.confirm({ message: "Continue and overwrite?", initialValue: false }));
177
+ if (!overwrite) return p.outro("No changes deployed — your existing instance is untouched.");
178
+ }
179
+
157
180
  // ---- provision: bucket, token, deploy ----
158
181
  s.start("Creating R2 bucket");
159
182
  const bucket = await wrangler(["r2", "bucket", "create", `${workerName}-raw`]);
package/lib/scaffold.js CHANGED
@@ -1,8 +1,11 @@
1
1
  import { mkdir, readdir, writeFile } from "node:fs/promises";
2
2
  import { join, dirname } from "node:path";
3
3
 
4
- /** Render the files of a scaffolded Mailslot project. */
5
- export function templates({ workerName, coreSpec = "^0.0.2" }) {
4
+ /** Render the files of a scaffolded Mailslot project.
5
+ * coreSpec (e.g. "^0.2.0") is required — run.js derives it from the wizard's
6
+ * own version so the scaffold can't drift from the core it shipped with. */
7
+ export function templates({ workerName, coreSpec }) {
8
+ if (!coreSpec) throw new Error("templates: coreSpec is required");
6
9
  const pkg = {
7
10
  name: workerName,
8
11
  private: true,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "create-mailslot",
3
- "version": "0.1.0",
4
- "description": "Deploy Mailslot \u2014 a self-hosted email inbox for AI agents \u2014 to your own Cloudflare account.",
3
+ "version": "0.2.0",
4
+ "description": "Deploy Mailslot a self-hosted email inbox for AI agents to your own Cloudflare account.",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "bin": {