create-svc 0.1.45 → 0.1.48

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-svc",
3
- "version": "0.1.45",
3
+ "version": "0.1.48",
4
4
  "description": "Local microservice bootstrap CLI for Cloud Run and Workers services with Neon-backed data.",
5
5
  "module": "index.ts",
6
6
  "type": "module",
@@ -2,9 +2,9 @@ import { describe, expect, test } from "bun:test";
2
2
  import {
3
3
  buildDeploymentVerificationCommands,
4
4
  buildLocalVerificationCommands,
5
+ buildLocalPreparationCommands,
5
6
  buildPostScaffoldCommands,
6
7
  buildPreGitBootstrapCommands,
7
- shouldRunLocalMigrate,
8
8
  } from "./post-scaffold";
9
9
 
10
10
  describe("buildPostScaffoldCommands", () => {
@@ -38,10 +38,16 @@ describe("buildPreGitBootstrapCommands", () => {
38
38
  });
39
39
  });
40
40
 
41
- describe("shouldRunLocalMigrate", () => {
42
- test("skips local migrate before Workers dev", () => {
43
- expect(shouldRunLocalMigrate({ target: "workers" })).toBe(false);
44
- expect(shouldRunLocalMigrate({ target: "cloudrun" })).toBe(true);
41
+ describe("buildLocalPreparationCommands", () => {
42
+ test("starts local Postgres before migrating Workers dev", () => {
43
+ expect(buildLocalPreparationCommands({ target: "workers" })).toEqual([
44
+ { command: "bun", args: ["run", "./scripts/ensure-local-db.ts"] },
45
+ { command: "bun", args: ["run", "migrate"] },
46
+ ]);
47
+ });
48
+
49
+ test("runs migrations directly for Cloud Run dev", () => {
50
+ expect(buildLocalPreparationCommands({ target: "cloudrun" })).toEqual([{ command: "bun", args: ["run", "migrate"] }]);
45
51
  });
46
52
  });
47
53
 
@@ -127,7 +133,7 @@ describe("buildDeploymentVerificationCommands", () => {
127
133
  command: "sh",
128
134
  args: [
129
135
  "-c",
130
- 'TOKEN="$(service auth token)" && IP="$(dig @1.1.1.1 +short api.launch.anmho.com | head -n 1)" && test -n "$IP" && curl --fail --show-error --silent --resolve "api.launch.anmho.com:443:$IP" -H "Authorization: Bearer $TOKEN" "https://api.launch.anmho.com/v1/admin/waitlist?limit=1"',
136
+ 'TOKEN="$(service auth token)" && (curl --fail --show-error --silent -H "Authorization: Bearer $TOKEN" "https://api.launch.anmho.com/v1/admin/waitlist?limit=1") || for IP in $(dig @1.1.1.1 +short api.launch.anmho.com); do curl --fail --show-error --silent --resolve "api.launch.anmho.com:443:$IP" -H "Authorization: Bearer $TOKEN" "https://api.launch.anmho.com/v1/admin/waitlist?limit=1" && exit 0; done; exit 1',
131
137
  ],
132
138
  });
133
139
  });
@@ -58,8 +58,8 @@ export function runPreGitBootstrapFlow(config: Pick<ScaffoldConfig, "framework">
58
58
  }
59
59
 
60
60
  async function startLocalDevelopment(config: Pick<ScaffoldConfig, "target">, cwd: string) {
61
- if (shouldRunLocalMigrate(config)) {
62
- run("bun", ["run", "migrate"], { cwd });
61
+ for (const command of buildLocalPreparationCommands(config)) {
62
+ run(command.command, command.args, { cwd });
63
63
  }
64
64
  await mkdir(join(cwd, ".service"), { recursive: true });
65
65
  const child = Bun.spawn(["sh", "-c", "exec bun run dev > .service/local-dev.log 2>&1 < /dev/null"], {
@@ -74,8 +74,14 @@ async function startLocalDevelopment(config: Pick<ScaffoldConfig, "target">, cwd
74
74
  await Bun.write(join(cwd, ".service", "local-dev.pid"), `${child.pid}\n`);
75
75
  }
76
76
 
77
- export function shouldRunLocalMigrate(config: Pick<ScaffoldConfig, "target">) {
78
- return config.target !== "workers";
77
+ export function buildLocalPreparationCommands(config: Pick<ScaffoldConfig, "target">): PostScaffoldCommand[] {
78
+ if (config.target === "workers") {
79
+ return [
80
+ { command: "bun", args: ["run", "./scripts/ensure-local-db.ts"] },
81
+ { command: "bun", args: ["run", "migrate"] },
82
+ ];
83
+ }
84
+ return [{ command: "bun", args: ["run", "migrate"] }];
79
85
  }
80
86
 
81
87
  function runWithRetries(command: PostScaffoldCommand, options: CommandOptions, attempts: number, delayMs: number) {
@@ -129,15 +135,16 @@ function workersProtectedVerificationCommand(host: string, tokenCommand: string)
129
135
 
130
136
  function workersCurlScript(host: string, path: string, flags: string[] = []) {
131
137
  const url = `https://${host}${path}`;
138
+ const curl = ["curl --fail --show-error --silent", ...flags, `"${url}"`].join(" ");
139
+ const resolvedCurl = ["curl --fail --show-error --silent", `--resolve "${host}:443:$IP"`, ...flags, `"${url}"`].join(" ");
132
140
  return [
133
- `IP="$(dig @1.1.1.1 +short ${host} | head -n 1)"`,
134
- "&&",
135
- 'test -n "$IP"',
136
- "&&",
137
- "curl --fail --show-error --silent",
138
- `--resolve "${host}:443:$IP"`,
139
- ...flags,
140
- `"${url}"`,
141
+ `(${curl})`,
142
+ "||",
143
+ `for IP in $(dig @1.1.1.1 +short ${host}); do`,
144
+ `${resolvedCurl}`,
145
+ "&& exit 0;",
146
+ "done;",
147
+ "exit 1",
141
148
  ].join(" ");
142
149
  }
143
150
 
@@ -307,7 +307,7 @@ test("scaffolds the workers target with wrangler lifecycle commands", async () =
307
307
 
308
308
  const packageJson = await Bun.file(join(generatedRoot, "package.json")).text();
309
309
  expect(packageJson).toContain('"@anmho/authctl": "0.1.1"');
310
- expect(packageJson).toContain('"dev": "wrangler dev"');
310
+ expect(packageJson).toContain('"dev": "bun run ./scripts/dev.ts wrangler dev"');
311
311
  expect(packageJson).toContain('"service": "service"');
312
312
  expect(packageJson).toContain('"auth": "service auth"');
313
313
  expect(packageJson).toContain('"wrangler"');
@@ -320,6 +320,9 @@ test("scaffolds the workers target with wrangler lifecycle commands", async () =
320
320
  expect(wranglerConfig).toContain('binding = "HYPERDRIVE"');
321
321
  expect(wranglerConfig).toContain('AUTH_ENABLED = "true"');
322
322
  expect(wranglerConfig).toContain('AUTH_AUDIENCE = "api://dns-api"');
323
+ const authSource = await Bun.file(join(generatedRoot, "src", "auth.ts")).text();
324
+ expect(authSource).toContain('alg === "EdDSA"');
325
+ expect(authSource).toContain('name: "Ed25519"');
323
326
 
324
327
  const entrypoint = await Bun.file(join(generatedRoot, "src", "index.ts")).text();
325
328
  expect(entrypoint).toContain("/v1/waitlist");
@@ -8,15 +8,20 @@ if (command.length === 0) {
8
8
  }
9
9
 
10
10
  await ensureLocalPostgres();
11
+ const localEnv = await readLocalEnv();
12
+ const env = {
13
+ ...Bun.env,
14
+ ...localEnv,
15
+ };
16
+ if (env.DATABASE_URL && !env.CLOUDFLARE_HYPERDRIVE_LOCAL_CONNECTION_STRING_HYPERDRIVE) {
17
+ env.CLOUDFLARE_HYPERDRIVE_LOCAL_CONNECTION_STRING_HYPERDRIVE = env.DATABASE_URL;
18
+ }
11
19
 
12
20
  const child = Bun.spawn(command, {
13
21
  stdin: "inherit",
14
22
  stdout: "inherit",
15
23
  stderr: "inherit",
16
- env: {
17
- ...Bun.env,
18
- ...(await readLocalEnv()),
19
- },
24
+ env,
20
25
  });
21
26
 
22
27
  process.exit(await child.exited);
@@ -3,7 +3,7 @@
3
3
  "private": true,
4
4
  "type": "module",
5
5
  "scripts": {
6
- "dev": "wrangler dev",
6
+ "dev": "bun run ./scripts/dev.ts wrangler dev",
7
7
  "service": "service",
8
8
  "migrate": "service migrate",
9
9
  "seed": "service seed",
@@ -132,6 +132,12 @@ function importAlgorithm(alg: string, key: JsonWebKey) {
132
132
  verify: { name: "ECDSA", hash: "SHA-256" },
133
133
  } as const;
134
134
  }
135
+ if (alg === "EdDSA" && key.crv === "Ed25519") {
136
+ return {
137
+ import: { name: "Ed25519" },
138
+ verify: { name: "Ed25519" },
139
+ } as const;
140
+ }
135
141
  throw new Error(`unsupported jwt alg: ${alg}`);
136
142
  }
137
143