@cronvello/sdk 0.1.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.
@@ -0,0 +1,214 @@
1
+ import { T as Transport, P as PublicJob, J as JobCreateBody, a as JobUpdateBody, b as PublicTask, c as TaskCreateBody, A as AccountTasksQuery, d as TasksPage, e as TaskUpdateBody, R as RunNowResult, f as RunsQuery, g as RunsPage, h as AccountRunsQuery, i as PublicRun, M as MeResponse, U as UsageResponse, F as FetchLike, j as RegistryReconcileRequest, k as RegistryReconcileResponse, l as ResolvedJob, S as SyncOptions, m as ReconcileResult, D as DispatchRequest, n as DispatchResponse, C as CronvelloAppConfig } from './dispatch-handler-Bnda1Ekq.js';
2
+ export { o as CallbackStatus, p as CronvelloJobConfig, q as CronvelloJobConfigWithKey, r as CronvelloJobContext, s as CronvelloJobHandler, t as CronvelloJobsInput, u as CronvelloLogger, E as ExecutionMode, H as HttpMethod, v as JobStatus, w as Pagination, x as ReconcileTaskChange, y as RegistryReconcileChange, z as RegistryTaskInput, B as RunStatus, G as RunType, I as SuccessCriteria, K as Urgency } from './dispatch-handler-Bnda1Ekq.js';
3
+ import { ExpressDispatchHandler } from './express.js';
4
+ import { NextRouteHandler } from './next.js';
5
+
6
+ /**
7
+ * Low-level, fully-typed client for the Cronvello public `/v1` API.
8
+ *
9
+ * This is the thin REST layer: one method per endpoint, request/response types straight
10
+ * from the server contract. The high-level registry (`defineCronvello`) is built on top of
11
+ * it. Use this directly when you need ad-hoc control beyond the registry model.
12
+ */
13
+
14
+ /** The production Cronvello API. Override `baseUrl` only for self-hosting or testing. */
15
+ declare const CRONVELLO_DEFAULT_BASE_URL = "https://api.cronvello.com";
16
+ interface CronvelloClientOptions {
17
+ /** Account API key (`crn_live_…`). Required. */
18
+ apiKey: string;
19
+ /** API base URL. Defaults to https://api.cronvello.com. */
20
+ baseUrl?: string;
21
+ /** Per-request timeout in ms (default 30_000). */
22
+ timeoutMs?: number;
23
+ /** Retry attempts for 429/5xx/network errors (default 2). */
24
+ maxRetries?: number;
25
+ /** Custom fetch implementation (default: global fetch). */
26
+ fetch?: FetchLike;
27
+ /** Telemetry hook for every request attempt. */
28
+ onRequest?: (info: {
29
+ method: string;
30
+ path: string;
31
+ status: number;
32
+ attempt: number;
33
+ durationMs: number;
34
+ }) => void;
35
+ }
36
+ declare class CronvelloClient {
37
+ private readonly transport;
38
+ /** The resolved base URL in use. */
39
+ readonly baseUrl: string;
40
+ /** Job container operations. */
41
+ readonly jobs: JobsResource;
42
+ /** Scheduled task operations. */
43
+ readonly tasks: TasksResource;
44
+ /** Execution-history (run) operations. */
45
+ readonly runs: RunsResource;
46
+ /** Account identity + usage. */
47
+ readonly account: AccountResource;
48
+ constructor(options: CronvelloClientOptions);
49
+ /**
50
+ * Atomically reconcile a whole code registry server-side (`PUT /v1/registry`): one job
51
+ * container + its tasks, created/updated/pruned/started in a single call. This is what
52
+ * `defineCronvello().sync()` prefers; the high-level API builds the body for you.
53
+ */
54
+ reconcileRegistry(body: RegistryReconcileRequest, opts?: {
55
+ idempotencyKey?: string;
56
+ }): Promise<RegistryReconcileResponse>;
57
+ /**
58
+ * Escape hatch for endpoints not yet wrapped by a typed method (heartbeat monitors,
59
+ * maintenance windows, DLQ, notification channels, audit log, API-key self-service …).
60
+ * `T` is the response shape you expect.
61
+ */
62
+ request<T>(method: string, path: string, opts?: {
63
+ query?: Record<string, string | number | boolean | undefined>;
64
+ body?: unknown;
65
+ idempotencyKey?: string;
66
+ }): Promise<T>;
67
+ }
68
+ declare class JobsResource {
69
+ private readonly t;
70
+ constructor(t: Transport);
71
+ list(): Promise<PublicJob[]>;
72
+ get(jobId: string): Promise<PublicJob>;
73
+ create(body: JobCreateBody, opts?: {
74
+ idempotencyKey?: string;
75
+ }): Promise<PublicJob>;
76
+ update(jobId: string, body: JobUpdateBody): Promise<PublicJob>;
77
+ delete(jobId: string): Promise<null>;
78
+ start(jobId: string): Promise<PublicJob>;
79
+ stop(jobId: string): Promise<PublicJob>;
80
+ listTasks(jobId: string): Promise<PublicTask[]>;
81
+ createTask(jobId: string, body: TaskCreateBody, opts?: {
82
+ idempotencyKey?: string;
83
+ }): Promise<PublicTask>;
84
+ }
85
+ declare class TasksResource {
86
+ private readonly t;
87
+ constructor(t: Transport);
88
+ /** Account-wide paginated task table. */
89
+ list(query?: AccountTasksQuery): Promise<TasksPage>;
90
+ get(taskId: string): Promise<PublicTask>;
91
+ update(taskId: string, body: TaskUpdateBody): Promise<PublicTask>;
92
+ delete(taskId: string): Promise<null>;
93
+ start(taskId: string): Promise<PublicTask>;
94
+ stop(taskId: string): Promise<PublicTask>;
95
+ /** Trigger a one-off manual execution (does not change the schedule). */
96
+ runNow(taskId: string): Promise<RunNowResult>;
97
+ listRuns(taskId: string, query?: RunsQuery): Promise<RunsPage>;
98
+ }
99
+ declare class RunsResource {
100
+ private readonly t;
101
+ constructor(t: Transport);
102
+ /** Account-wide paginated activity feed. */
103
+ list(query?: AccountRunsQuery): Promise<RunsPage>;
104
+ get(runId: string): Promise<PublicRun>;
105
+ }
106
+ declare class AccountResource {
107
+ private readonly t;
108
+ constructor(t: Transport);
109
+ me(): Promise<MeResponse>;
110
+ usage(): Promise<UsageResponse>;
111
+ }
112
+
113
+ /**
114
+ * `defineCronvello` — the high-level, code-first entry point.
115
+ *
116
+ * export const cronvello = defineCronvello({
117
+ * appName: "my-app",
118
+ * appUrl: process.env.APP_URL!,
119
+ * apiKey: process.env.CRONVELLO_API_KEY!,
120
+ * dispatchSecret: process.env.CRONVELLO_DISPATCH_SECRET!,
121
+ * jobs: {
122
+ * "send-daily-digest": { schedule: "0 8 * * *", handler: async () => { … } },
123
+ * "cleanup-temp": { schedule: "*\/15 * * * *", handler: async () => { … } },
124
+ * },
125
+ * });
126
+ *
127
+ * await cronvello.sync(); // reconcile the registry to Cronvello (idempotent)
128
+ * app.post(cronvello.dispatchPath, express.json(), cronvello.expressHandler());
129
+ */
130
+
131
+ interface CronvelloApp {
132
+ /** The underlying low-level client for ad-hoc `/v1` calls. */
133
+ readonly client: CronvelloClient;
134
+ /** Resolved jobs, keyed by their stable registry key. */
135
+ readonly jobs: ReadonlyMap<string, ResolvedJob>;
136
+ /** The app identity / Job-container name. */
137
+ readonly appName: string;
138
+ /** Path the dispatch handler should be mounted at (e.g. "/cronvello/dispatch"). */
139
+ readonly dispatchPath: string;
140
+ /** Absolute URL Cronvello calls back (appUrl + dispatchPath). */
141
+ readonly dispatchUrl: string;
142
+ /** Reconcile the registry into Cronvello. Idempotent — safe to call on every boot/deploy. */
143
+ sync(options?: SyncOptions): Promise<ReconcileResult>;
144
+ /** Trigger one job immediately via Cronvello (manual run). Requires a prior `sync()`. */
145
+ run(key: string): Promise<RunNowResult>;
146
+ /** Framework-neutral dispatch entry — used by the adapters. */
147
+ handle(req: DispatchRequest): Promise<DispatchResponse>;
148
+ /** Express/Connect request handler for the dispatch endpoint. */
149
+ expressHandler(): ExpressDispatchHandler;
150
+ /** Next.js App Router (Route Handler) for the dispatch endpoint. */
151
+ nextHandler(): NextRouteHandler;
152
+ /** The registry keys, for diagnostics. */
153
+ keys(): string[];
154
+ }
155
+ declare function defineCronvello(config: CronvelloAppConfig): CronvelloApp;
156
+
157
+ /**
158
+ * Error taxonomy for the SDK. Everything thrown by the public surface is a
159
+ * `CronvelloError` (or subclass), so callers can `catch (e) { if (e instanceof CronvelloError) … }`.
160
+ */
161
+ declare class CronvelloError extends Error {
162
+ constructor(message: string);
163
+ }
164
+ /** A non-2xx response from the Cronvello API. */
165
+ declare class CronvelloApiError extends CronvelloError {
166
+ /** HTTP status code. */
167
+ readonly status: number;
168
+ /** Machine-readable error code from the API body, when present. */
169
+ readonly code: string | undefined;
170
+ /** The method + path that failed, e.g. `POST /v1/jobs`. */
171
+ readonly endpoint: string;
172
+ /** Parsed response body (best effort). */
173
+ readonly body: unknown;
174
+ /** Seconds to wait before retrying, parsed from `Retry-After` / rate-limit payload (429 only). */
175
+ readonly retryAfterSeconds: number | undefined;
176
+ constructor(args: {
177
+ status: number;
178
+ endpoint: string;
179
+ message: string;
180
+ code?: string;
181
+ body?: unknown;
182
+ retryAfterSeconds?: number;
183
+ });
184
+ get isRateLimited(): boolean;
185
+ get isAuthError(): boolean;
186
+ get isNotFound(): boolean;
187
+ }
188
+ /** A network/transport failure (DNS, connection reset, timeout) before any HTTP status. */
189
+ declare class CronvelloNetworkError extends CronvelloError {
190
+ readonly endpoint: string;
191
+ readonly cause: unknown;
192
+ constructor(endpoint: string, cause: unknown);
193
+ }
194
+ /** A misconfiguration caught before any network call (missing apiKey, bad URL, …). */
195
+ declare class CronvelloConfigError extends CronvelloError {
196
+ constructor(message: string);
197
+ }
198
+
199
+ /**
200
+ * @cronvello/sdk — code-first cron jobs for Cronvello.
201
+ *
202
+ * Two layers, one package:
203
+ * • High-level registry: `defineCronvello({ jobs })` → `.sync()` + `.expressHandler()` / `.nextHandler()`.
204
+ * Define jobs in code; the SDK reconciles them to https://api.cronvello.com and runs them.
205
+ * • Low-level client: `new CronvelloClient({ apiKey })` → typed access to the whole `/v1` API.
206
+ */
207
+
208
+ /**
209
+ * Generate a strong random dispatch secret (hex). Convenience for setup scripts:
210
+ * node -e "console.log(require('@cronvello/sdk').generateDispatchSecret())"
211
+ */
212
+ declare function generateDispatchSecret(bytes?: number): string;
213
+
214
+ export { AccountRunsQuery, AccountTasksQuery, CRONVELLO_DEFAULT_BASE_URL, CronvelloApiError, type CronvelloApp, CronvelloAppConfig, CronvelloClient, type CronvelloClientOptions, CronvelloConfigError, CronvelloError, CronvelloNetworkError, DispatchRequest, DispatchResponse, JobCreateBody, JobUpdateBody, MeResponse, PublicJob, PublicRun, PublicTask, ReconcileResult, RegistryReconcileRequest, RegistryReconcileResponse, RunNowResult, RunsPage, RunsQuery, SyncOptions, TaskCreateBody, TaskUpdateBody, TasksPage, UsageResponse, defineCronvello, generateDispatchSecret };