@solcreek/cli 0.4.1 → 0.4.3

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.
@@ -736,6 +736,7 @@ async function deployAuthenticated(cwd, resolved, token, skipBuild, jsonMode = f
736
736
  ...resolved.compatibilityFlags.filter((f) => f !== "nodejs_compat"),
737
737
  ] }),
738
738
  ...(resolved.cron.length > 0 ? { cron: resolved.cron } : {}),
739
+ ...(resolved.queue ? { queue: true } : {}),
739
740
  };
740
741
  await client.uploadDeploymentBundle(project.id, deployment.id, bundle);
741
742
  // Poll for async deploy progress
@@ -785,6 +786,9 @@ async function deployAuthenticated(cwd, resolved, token, skipBuild, jsonMode = f
785
786
  if (resolved.cron.length > 0) {
786
787
  consola.info(` Cron: ${resolved.cron.join(", ")}`);
787
788
  }
789
+ if (resolved.queue) {
790
+ consola.info(" Queue: enabled");
791
+ }
788
792
  // Contextual next-step hints (non-JSON only)
789
793
  if (!jsonMode) {
790
794
  printNextStepHint(renderMode, resolved);
@@ -58,6 +58,45 @@ export const devCommand = defineCommand({
58
58
  await server.stop();
59
59
  process.exit(1);
60
60
  }
61
+ // Interactive trigger commands (only if cron/queue configured)
62
+ if (config.cron.length > 0 || config.queue) {
63
+ const { createInterface } = await import("node:readline");
64
+ const rl = createInterface({ input: process.stdin, output: process.stdout, terminal: false });
65
+ rl.on("line", async (line) => {
66
+ const input = line.trim();
67
+ if (!input)
68
+ return;
69
+ if (input === "cron" && config.cron.length > 0) {
70
+ try {
71
+ await server.triggerScheduled();
72
+ consola.success("Triggered scheduled()");
73
+ }
74
+ catch (e) {
75
+ consola.error(`scheduled() error: ${e.message}`);
76
+ }
77
+ return;
78
+ }
79
+ if (input.startsWith("queue ") && config.queue) {
80
+ const payload = input.slice(6).trim();
81
+ let parsed = payload;
82
+ try {
83
+ parsed = JSON.parse(payload);
84
+ }
85
+ catch {
86
+ // Not JSON, send as string
87
+ }
88
+ try {
89
+ await server.sendQueueMessage(parsed);
90
+ consola.success(`Sent message to queue()`);
91
+ }
92
+ catch (e) {
93
+ consola.error(`queue() error: ${e.message}`);
94
+ }
95
+ return;
96
+ }
97
+ consola.warn(`Unknown command: ${input}`);
98
+ });
99
+ }
61
100
  },
62
101
  });
63
102
  //# sourceMappingURL=dev.js.map
@@ -0,0 +1,2 @@
1
+ export declare const queueCommand: import("citty").CommandDef<import("citty").ArgsDef>;
2
+ //# sourceMappingURL=queue.d.ts.map
@@ -0,0 +1,92 @@
1
+ import { defineCommand } from "citty";
2
+ import consola from "consola";
3
+ import { CreekClient, parseConfig } from "@solcreek/sdk";
4
+ import { getToken, getApiUrl } from "../utils/config.js";
5
+ import { existsSync, readFileSync } from "node:fs";
6
+ import { join } from "node:path";
7
+ import { globalArgs, resolveJsonMode, jsonOutput } from "../utils/output.js";
8
+ function getProjectSlug() {
9
+ const configPath = join(process.cwd(), "creek.toml");
10
+ if (!existsSync(configPath)) {
11
+ consola.error("No creek.toml found. Run `creek init` first.");
12
+ process.exit(1);
13
+ }
14
+ return parseConfig(readFileSync(configPath, "utf-8")).project.name;
15
+ }
16
+ function getClient() {
17
+ const token = getToken();
18
+ if (!token) {
19
+ consola.error("Not authenticated. Run `creek login` first.");
20
+ process.exit(1);
21
+ }
22
+ return new CreekClient(getApiUrl(), token);
23
+ }
24
+ const queueSend = defineCommand({
25
+ meta: { name: "send", description: "Send a message to the project's queue" },
26
+ args: {
27
+ message: {
28
+ type: "positional",
29
+ description: "Message body (string, or use --json for JSON content)",
30
+ required: true,
31
+ },
32
+ parseJson: {
33
+ type: "boolean",
34
+ alias: "j",
35
+ description: "Parse message as JSON",
36
+ default: false,
37
+ },
38
+ project: {
39
+ type: "string",
40
+ description: "Project slug (defaults to current creek.toml)",
41
+ },
42
+ ...globalArgs,
43
+ },
44
+ async run({ args }) {
45
+ const jsonMode = resolveJsonMode(args);
46
+ const client = getClient();
47
+ const slug = args.project ?? getProjectSlug();
48
+ let payload = args.message;
49
+ if (args.parseJson) {
50
+ try {
51
+ payload = JSON.parse(args.message);
52
+ }
53
+ catch (err) {
54
+ if (jsonMode) {
55
+ jsonOutput({ ok: false, error: "invalid_json", message: err instanceof Error ? err.message : String(err) }, 1, []);
56
+ }
57
+ consola.error(`Invalid JSON: ${err instanceof Error ? err.message : err}`);
58
+ process.exit(1);
59
+ }
60
+ }
61
+ try {
62
+ const result = await client.sendQueueMessage(slug, payload);
63
+ if (jsonMode) {
64
+ jsonOutput({ ok: true, project: slug, queueId: result.queueId }, 0, [
65
+ { command: `creek deployments --project ${slug}`, description: "View deployment history" },
66
+ ]);
67
+ }
68
+ consola.success(`Sent message to ${slug} queue`);
69
+ }
70
+ catch (err) {
71
+ const msg = err instanceof Error ? err.message : String(err);
72
+ if (jsonMode) {
73
+ jsonOutput({ ok: false, error: "send_failed", message: msg }, 1, [
74
+ { command: `creek status --project ${slug}`, description: "Check project triggers" },
75
+ ]);
76
+ }
77
+ consola.error(`Failed to send: ${msg}`);
78
+ consola.info("Make sure your creek.toml has `queue = true` under [triggers] and the project is deployed.");
79
+ process.exit(1);
80
+ }
81
+ },
82
+ });
83
+ export const queueCommand = defineCommand({
84
+ meta: {
85
+ name: "queue",
86
+ description: "Send messages to the project's queue",
87
+ },
88
+ subCommands: {
89
+ send: queueSend,
90
+ },
91
+ });
92
+ //# sourceMappingURL=queue.js.map
@@ -2,9 +2,7 @@ import { defineCommand } from "citty";
2
2
  import consola from "consola";
3
3
  import { CreekClient } from "@solcreek/sdk";
4
4
  import { getToken, getApiUrl, getSandboxApiUrl } from "../utils/config.js";
5
- import { existsSync, readFileSync } from "node:fs";
6
- import { join } from "node:path";
7
- import { parseConfig } from "@solcreek/sdk";
5
+ import { resolveConfig, formatDetectionSummary, ConfigNotFoundError } from "@solcreek/sdk";
8
6
  import { globalArgs, resolveJsonMode, jsonOutput, AUTH_BREADCRUMBS, NO_PROJECT_BREADCRUMBS } from "../utils/output.js";
9
7
  export const statusCommand = defineCommand({
10
8
  meta: {
@@ -78,27 +76,32 @@ async function projectStatus(jsonMode) {
78
76
  consola.info("To check a sandbox: creek status <sandboxId>");
79
77
  process.exit(1);
80
78
  }
81
- const configPath = join(process.cwd(), "creek.toml");
82
- if (!existsSync(configPath)) {
83
- if (jsonMode)
84
- jsonOutput({ ok: false, error: "no_project", message: "No creek.toml found" }, 1, NO_PROJECT_BREADCRUMBS);
85
- consola.error("No creek.toml found.");
86
- consola.info("To check a sandbox: creek status <sandboxId>");
87
- process.exit(1);
79
+ let resolved;
80
+ try {
81
+ resolved = resolveConfig(process.cwd());
82
+ }
83
+ catch (err) {
84
+ if (err instanceof ConfigNotFoundError) {
85
+ if (jsonMode)
86
+ jsonOutput({ ok: false, error: "no_project", message: "No project config found" }, 1, NO_PROJECT_BREADCRUMBS);
87
+ consola.error("No project config found.");
88
+ consola.info("To check a sandbox: creek status <sandboxId>");
89
+ process.exit(1);
90
+ }
91
+ throw err;
88
92
  }
89
- const config = parseConfig(readFileSync(configPath, "utf-8"));
90
93
  const client = new CreekClient(getApiUrl(), token);
91
94
  let project;
92
95
  try {
93
- project = await client.getProject(config.project.name);
96
+ project = await client.getProject(resolved.projectName);
94
97
  }
95
98
  catch {
96
99
  if (jsonMode)
97
- jsonOutput({ ok: false, error: "not_found", message: `Project "${config.project.name}" not found` }, 1, [
100
+ jsonOutput({ ok: false, error: "not_found", message: `Project "${resolved.projectName}" not found` }, 1, [
98
101
  { command: "creek deploy", description: "Deploy to create the project" },
99
102
  { command: "creek projects", description: "List existing projects" },
100
103
  ]);
101
- consola.error(`Project "${config.project.name}" not found.`);
104
+ consola.error(`Project "${resolved.projectName}" not found.`);
102
105
  process.exit(1);
103
106
  }
104
107
  if (jsonMode) {
@@ -106,8 +109,12 @@ async function projectStatus(jsonMode) {
106
109
  ok: true,
107
110
  type: "project",
108
111
  project: project.slug,
112
+ config: resolved.source,
109
113
  framework: project.framework,
110
114
  productionDeploymentId: project.production_deployment_id,
115
+ bindings: resolved.bindings.map((b) => b.type),
116
+ cron: resolved.cron,
117
+ queue: resolved.queue,
111
118
  createdAt: project.created_at,
112
119
  }, 0, [
113
120
  { command: `creek deployments --project ${project.slug}`, description: "List deployment history" },
@@ -115,12 +122,18 @@ async function projectStatus(jsonMode) {
115
122
  ]);
116
123
  }
117
124
  const deployed = project.production_deployment_id ? "deployed" : "not deployed";
118
- const framework = project.framework ? ` (${project.framework})` : "";
119
- consola.log(`\n Project ${project.slug}${framework}`);
125
+ consola.log(`\n Project ${project.slug}`);
126
+ consola.log(` Config: ${formatDetectionSummary(resolved)}`);
120
127
  consola.log(` Status: ${deployed}`);
121
128
  if (project.production_deployment_id) {
122
129
  consola.log(` Deploy: ${project.production_deployment_id.slice(0, 8)}`);
123
130
  }
131
+ if (resolved.cron.length > 0) {
132
+ consola.log(` Cron: ${resolved.cron.join(", ")}`);
133
+ }
134
+ if (resolved.queue) {
135
+ consola.log(" Queue: enabled");
136
+ }
124
137
  consola.log("");
125
138
  }
126
139
  //# sourceMappingURL=status.js.map
@@ -13,6 +13,10 @@ export declare class DevServer {
13
13
  private proxy;
14
14
  constructor(options: DevServerOptions);
15
15
  start(): Promise<void>;
16
+ /** Trigger the worker's scheduled() handler. */
17
+ triggerScheduled(): Promise<void>;
18
+ /** Send a message to the worker's queue() handler. */
19
+ sendQueueMessage(message: unknown): Promise<void>;
16
20
  stop(): Promise<void>;
17
21
  }
18
22
  //# sourceMappingURL=server.d.ts.map
@@ -47,6 +47,8 @@ export class DevServer {
47
47
  realtimeUrl: `http://127.0.0.1:${this.realtimeServer.getPort()}`,
48
48
  projectSlug: config.projectName,
49
49
  vars: config.vars,
50
+ cron: config.cron,
51
+ queue: config.queue,
50
52
  onRebuild: (ms) => {
51
53
  consola.info(`Worker rebuilt in ${ms}ms`);
52
54
  },
@@ -117,8 +119,38 @@ export class DevServer {
117
119
  }
118
120
  consola.info(`Realtime: ws://localhost:${actualPort}`);
119
121
  consola.info(`Data: .creek/dev/`);
122
+ if (config.cron.length > 0 || config.queue) {
123
+ const triggers = [];
124
+ if (config.cron.length > 0)
125
+ triggers.push(`${config.cron.length} cron`);
126
+ if (config.queue)
127
+ triggers.push("queue");
128
+ consola.info(`Triggers: ${triggers.join(", ")}`);
129
+ }
120
130
  console.log("");
121
131
  consola.success(`Ready in ${elapsed}ms`);
132
+ if (config.cron.length > 0 || config.queue) {
133
+ console.log("");
134
+ consola.info("Trigger commands (type and press Enter):");
135
+ if (config.cron.length > 0) {
136
+ consola.info(" cron Trigger scheduled() handler");
137
+ }
138
+ if (config.queue) {
139
+ consola.info(' queue <message> Send a message to queue() handler');
140
+ }
141
+ }
142
+ }
143
+ /** Trigger the worker's scheduled() handler. */
144
+ async triggerScheduled() {
145
+ if (!this.workerRunner)
146
+ throw new Error("Worker not running");
147
+ await this.workerRunner.triggerScheduled();
148
+ }
149
+ /** Send a message to the worker's queue() handler. */
150
+ async sendQueueMessage(message) {
151
+ if (!this.workerRunner)
152
+ throw new Error("Worker not running");
153
+ await this.workerRunner.sendQueueMessage(message);
122
154
  }
123
155
  async stop() {
124
156
  // Stop in reverse order
@@ -16,6 +16,10 @@ export interface WorkerRunnerOptions {
16
16
  vars?: Record<string, string>;
17
17
  /** Whether the project has client assets (Worker + SPA hybrid). */
18
18
  hasClientAssets?: boolean;
19
+ /** Cron schedules from creek.toml [triggers].cron */
20
+ cron?: string[];
21
+ /** Whether project uses a queue (auto-provisions a local queue) */
22
+ queue?: boolean;
19
23
  /** Callback when worker is rebuilt. */
20
24
  onRebuild?: (durationMs: number) => void;
21
25
  /**
@@ -42,6 +46,10 @@ export declare class WorkerRunner {
42
46
  /** Dispatch a fetch request to the worker (via Miniflare). */
43
47
  dispatchFetch(input: string, init?: RequestInit): Promise<Response>;
44
48
  private buildMiniflareOptions;
49
+ /** Trigger the scheduled() handler manually (for local cron simulation). */
50
+ triggerScheduled(scheduledTime?: number, cron?: string): Promise<Response>;
51
+ /** Send a message to the local queue (consumed by the worker's queue() handler). */
52
+ sendQueueMessage(message: unknown): Promise<void>;
45
53
  private get esbuildOptions();
46
54
  private bundle;
47
55
  private startWatching;
@@ -124,8 +124,37 @@ export class WorkerRunner {
124
124
  opts.r2Buckets = { [r2BindingName]: "creek-dev-r2" };
125
125
  opts.r2Persist = persistDir ? join(persistDir, "r2") : false;
126
126
  }
127
+ // Queue (producer + consumer wired to the same worker)
128
+ if (this.options.queue) {
129
+ opts.queueProducers = { QUEUE: "creek-dev-queue" };
130
+ opts.queueConsumers = {
131
+ "creek-dev-queue": {
132
+ maxBatchSize: 10,
133
+ maxBatchTimeout: 1,
134
+ maxRetries: 3,
135
+ },
136
+ };
137
+ }
127
138
  return opts;
128
139
  }
140
+ /** Trigger the scheduled() handler manually (for local cron simulation). */
141
+ async triggerScheduled(scheduledTime = Date.now(), cron = "* * * * *") {
142
+ if (!this.mf)
143
+ throw new Error("WorkerRunner not started");
144
+ const worker = await this.mf.getWorker();
145
+ const url = `http://placeholder/cdn-cgi/handler/scheduled?time=${scheduledTime}&cron=${encodeURIComponent(cron)}`;
146
+ return worker.fetch(url);
147
+ }
148
+ /** Send a message to the local queue (consumed by the worker's queue() handler). */
149
+ async sendQueueMessage(message) {
150
+ if (!this.mf)
151
+ throw new Error("WorkerRunner not started");
152
+ if (!this.options.queue) {
153
+ throw new Error("Queue is not enabled. Add `queue = true` to [triggers] in creek.toml.");
154
+ }
155
+ const queue = await this.mf.getQueueProducer("QUEUE");
156
+ await queue.send(message);
157
+ }
129
158
  get esbuildOptions() {
130
159
  return {
131
160
  absWorkingDir: this.options.cwd,
package/dist/index.js CHANGED
@@ -17,6 +17,7 @@ import { statusCommand } from "./commands/status.js";
17
17
  import { devCommand } from "./commands/dev.js";
18
18
  import { rollbackCommand } from "./commands/rollback.js";
19
19
  import { opsCommand } from "./commands/ops.js";
20
+ import { queueCommand } from "./commands/queue.js";
20
21
  const __dirname = dirname(fileURLToPath(import.meta.url));
21
22
  const cliPkg = JSON.parse(readFileSync(join(__dirname, "..", "package.json"), "utf-8"));
22
23
  // Read version from the "creek" facade package (what users install),
@@ -47,6 +48,7 @@ const main = defineCommand({
47
48
  init: initCommand,
48
49
  claim: claimCommand,
49
50
  env: envCommand,
51
+ queue: queueCommand,
50
52
  domains: domainsCommand,
51
53
  rollback: rollbackCommand,
52
54
  ops: opsCommand,
@@ -86,6 +86,8 @@ export default {
86
86
  return new Response("Not Found", { status: 404 });
87
87
  });
88
88
  },
89
+ ${generateScheduledHandler()}
90
+ ${generateQueueHandler()}
89
91
  };
90
92
  `;
91
93
  }
@@ -114,9 +116,25 @@ export default {
114
116
  throw new Error("[creek] Worker must export default a fetch handler, Hono app, or { fetch() } object.");
115
117
  });
116
118
  },
119
+ ${generateScheduledHandler()}
120
+ ${generateQueueHandler()}
117
121
  };
118
122
  `;
119
123
  }
124
+ function generateScheduledHandler() {
125
+ return `async scheduled(event, env, ctx) {
126
+ if (typeof handler.scheduled === "function") {
127
+ return _runRequest(env, ctx, () => handler.scheduled(event, env, ctx));
128
+ }
129
+ },`;
130
+ }
131
+ function generateQueueHandler() {
132
+ return `async queue(batch, env, ctx) {
133
+ if (typeof handler.queue === "function") {
134
+ return _runRequest(env, ctx, () => handler.queue(batch, env, ctx));
135
+ }
136
+ },`;
137
+ }
120
138
  /**
121
139
  * Bundle a Worker entry point with Creek runtime auto-injection.
122
140
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solcreek/cli",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "description": "CLI for the Creek deployment platform",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -28,7 +28,7 @@
28
28
  "homepage": "https://creek.dev",
29
29
  "repository": {
30
30
  "type": "git",
31
- "url": "https://github.com/solcreek/creek.git",
31
+ "url": "git+https://github.com/solcreek/creek.git",
32
32
  "directory": "packages/cli"
33
33
  },
34
34
  "dependencies": {