@aniket-lodh/veyra-sdk 0.0.0-stage → 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.
package/README.md CHANGED
@@ -1,3 +1,203 @@
1
- # Temporary Holding Version
1
+ # @veyra/sdk
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Lightweight, zero-dependency TypeScript & Node.js SDK for the [Veyra](https://github.com/Aniket-lodh/veyra) Distributed Execution Platform.
4
+
5
+ Built directly on top of Veyra's REST API and HTTP Worker Protocol. Uses native web and Node 18+ standards (`fetch`, `AbortController`, `crypto`). No native binary bindings or direct database connections required.
6
+
7
+ ---
8
+
9
+ ## Features
10
+
11
+ - **Client Methods:** `enqueue()`, `getJob()`, `cancelJob()`, `retryJob()`
12
+ - **Robust Worker Engine:** Automatic worker registration, background heartbeats, empty queue backoff (`204 No Content`), and transparent `404` recovery/re-registration.
13
+ - **Concurrency & Leases:** Tunable concurrency pool, automatic periodic lease renewals during execution, and instant lease termination with `AbortSignal` triggering on `409 Conflict` (lease expired or reclaimed).
14
+ - **Completion Webhooks & HMAC Verification:** Supports enqueueing jobs with `callbackUrl` and provides guidance/helpers for verifying HMAC-SHA256 signatures (`X-Veyra-Signature`).
15
+ - **Failures & Dead-Lettering:** Automatic error formatting, stack trace capture, and immediate dead-lettering via `NonRetryableError`.
16
+ - **Graceful Shutdown:** Drains in-flight jobs within a configurable timeout, cancels timers, and cleanly deregisters from the fleet.
17
+
18
+ ---
19
+
20
+ ## Installation
21
+
22
+ ```bash
23
+ npm install @veyra/sdk
24
+ # or
25
+ pnpm add @veyra/sdk
26
+ # or
27
+ yarn add @veyra/sdk
28
+ ```
29
+
30
+ ---
31
+
32
+ ## Client Usage
33
+
34
+ ### 1. Initialize Client & Enqueue a Job
35
+
36
+ ```typescript
37
+ import { VeyraClient } from '@veyra/sdk';
38
+
39
+ const client = new VeyraClient({
40
+ baseUrl: process.env.VEYRA_API_URL || 'http://localhost:8080',
41
+ apiKey: process.env.VEYRA_API_KEY || 'veyra_...',
42
+ defaultQueue: 'default',
43
+ });
44
+
45
+ // Enqueue a job with priority, backoff, and completion webhook
46
+ const job = await client.enqueue({
47
+ queue: 'default',
48
+ handler: 'sync_inventory',
49
+ payload: {
50
+ sku: 'SKU-8921',
51
+ warehouseId: 'wh_west_1',
52
+ quantity: 140,
53
+ },
54
+ priority: 7, // 0 (lowest) to 9 (highest)
55
+ maxAttempts: 3,
56
+ backoff: {
57
+ kind: 'exponential',
58
+ baseSeconds: 30,
59
+ capSeconds: 3600,
60
+ },
61
+ idempotencyKey: 'inv-sync-2026-11-20-001',
62
+ callbackUrl: 'https://api.example.com/webhooks/veyra-completion',
63
+ });
64
+
65
+ console.log('Enqueued job:', job.id, job.status);
66
+ ```
67
+
68
+ ### 2. Inspect, Cancel, or Retry Jobs
69
+
70
+ ```typescript
71
+ // Fetch job status and attempt history
72
+ const job = await client.getJob('job_01JC...XYZ');
73
+
74
+ // Cancel an active or queued job
75
+ await client.cancelJob('job_01JC...XYZ');
76
+
77
+ // Retry a failed, cancelled, or dead-lettered job
78
+ await client.retryJob('job_01JC...XYZ');
79
+ ```
80
+
81
+ ---
82
+
83
+ ## Distributed Worker Usage
84
+
85
+ ### Running Custom Handlers with Concurrency & Leases
86
+
87
+ ```typescript
88
+ import { VeyraClient, NonRetryableError } from '@veyra/sdk';
89
+
90
+ const client = new VeyraClient({
91
+ baseUrl: process.env.VEYRA_API_URL || 'http://localhost:8080',
92
+ apiKey: process.env.VEYRA_API_KEY || 'veyra_...',
93
+ });
94
+
95
+ // Create managed worker
96
+ const worker = client.createWorker({
97
+ queues: ['default', 'inventory'],
98
+ concurrency: 5, // Concurrent jobs executed in parallel
99
+ pollIntervalMs: 1_000, // Backoff when queue is empty (204 No Content)
100
+ heartbeatIntervalMs: 10_000, // Worker health heartbeat
101
+ leaseHeartbeatIntervalMs: 10_000, // In-flight lease renewal cadence
102
+ });
103
+
104
+ // Register custom handler
105
+ worker.registerHandler('sync_inventory', async (job, ctx) => {
106
+ console.log(`Processing job ${job.id} (attempt ${ctx.attempt})`);
107
+
108
+ // Check abort signal: aborted if another worker reclaimed or lease expired
109
+ if (ctx.signal.aborted) {
110
+ throw new Error('Execution aborted: lease lost or expired');
111
+ }
112
+
113
+ const { sku, quantity } = job.payload as { sku: string; quantity: number };
114
+
115
+ if (!sku) {
116
+ // Throw NonRetryableError to dead-letter immediately without retries
117
+ throw new NonRetryableError('SKU is required');
118
+ }
119
+
120
+ // Execute task...
121
+ return { updated: true, sku, quantity, processedAt: new Date().toISOString() };
122
+ });
123
+
124
+ // Start claiming and processing jobs
125
+ await worker.start();
126
+ console.log(`Worker ${worker.workerId} active and polling...`);
127
+
128
+ // Handle graceful shutdown
129
+ const shutdown = async () => {
130
+ console.log('Draining worker and shutting down...');
131
+ await worker.stop({ timeoutMs: 15_000 });
132
+ process.exit(0);
133
+ };
134
+
135
+ process.on('SIGINT', shutdown);
136
+ process.on('SIGTERM', shutdown);
137
+ ```
138
+
139
+ ---
140
+
141
+ ## Completion Webhooks & HMAC Verification
142
+
143
+ When jobs are enqueued with a `callbackUrl`, Veyra delivers an HTTP POST notification upon reaching a terminal state (`succeeded`, `failed`, `dead_lettered`, or `cancelled`).
144
+
145
+ ### Webhook Headers & Payload Structure
146
+
147
+ Veyra includes the following headers with each webhook dispatch:
148
+
149
+ - `Content-Type: application/json`
150
+ - `X-Veyra-Event: job.completed`
151
+ - `X-Veyra-Job-Id: <job_id>`
152
+ - `X-Veyra-Status: <status>`
153
+ - `X-Veyra-Attempt: <attempt_number>`
154
+ - `X-Veyra-Delivery-Attempt: <callback_attempt>`
155
+ - `X-Veyra-Timestamp: <iso_timestamp>`
156
+ - `X-Veyra-Signature: sha256=<hex_hmac>` (when `VEYRA_CALLBACK_SECRET` is configured on API)
157
+
158
+ ### Verifying HMAC Signatures (Node.js / Express)
159
+
160
+ ```typescript
161
+ import crypto from 'node:crypto';
162
+
163
+ export function verifyVeyraWebhook(
164
+ rawBody: Buffer | string,
165
+ signatureHeader: string | undefined,
166
+ secret: string
167
+ ): boolean {
168
+ if (!signatureHeader || !signatureHeader.startsWith('sha256=')) {
169
+ return false;
170
+ }
171
+
172
+ const expectedSignature = signatureHeader.slice('sha256='.length);
173
+ const hmac = crypto.createHmac('sha256', secret);
174
+ hmac.update(rawBody);
175
+ const actualSignature = hmac.digest('hex');
176
+
177
+ return crypto.timingSafeEqual(
178
+ Buffer.from(actualSignature, 'hex'),
179
+ Buffer.from(expectedSignature, 'hex')
180
+ );
181
+ }
182
+ ```
183
+
184
+ ---
185
+
186
+ ## Development & Testing
187
+
188
+ ```bash
189
+ # Typecheck
190
+ pnpm typecheck
191
+
192
+ # Run unit tests
193
+ pnpm test
194
+
195
+ # Build bundle and declaration files
196
+ pnpm build
197
+ ```
198
+
199
+ ---
200
+
201
+ ## License
202
+
203
+ [Apache-2.0](LICENSE)
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Veyra HTTP Client
3
+ */
4
+ import type { ClaimParams, CompleteJobResponse, EnqueueJobInput, FailJobParams, FailJobResponse, HeartbeatResponse, Job, JobClaim, RenewLeaseResponse, VeyraClientConfig, VeyraWorkerOptions, WorkerRecord, WorkerRegisterParams } from './types.js';
5
+ import { VeyraWorker } from './worker.js';
6
+ export declare class VeyraClient {
7
+ readonly baseUrl: string;
8
+ readonly apiKey: string;
9
+ readonly defaultQueue: string;
10
+ private readonly customFetch?;
11
+ private readonly defaultTimeoutMs;
12
+ constructor(config: VeyraClientConfig);
13
+ /**
14
+ * Enqueues a job into Veyra's queue.
15
+ */
16
+ enqueue<TPayload = unknown, TResult = unknown>(input: EnqueueJobInput<TPayload>): Promise<Job<TPayload, TResult>>;
17
+ /**
18
+ * Retrieves a job by ID.
19
+ */
20
+ getJob<TPayload = unknown, TResult = unknown>(jobId: string): Promise<Job<TPayload, TResult>>;
21
+ /**
22
+ * Cancels a job by ID.
23
+ */
24
+ cancelJob(jobId: string): Promise<Job>;
25
+ /**
26
+ * Retries a failed, cancelled, or dead-lettered job.
27
+ */
28
+ retryJob(jobId: string): Promise<Job>;
29
+ /**
30
+ * Registers a worker in the Veyra cluster.
31
+ */
32
+ registerWorker(params: WorkerRegisterParams): Promise<WorkerRecord>;
33
+ /**
34
+ * Sends a worker-level heartbeat.
35
+ */
36
+ heartbeatWorker(workerId: string): Promise<HeartbeatResponse>;
37
+ /**
38
+ * Claims a job for execution. Returns null if queue is empty (204 No Content).
39
+ */
40
+ claimJob<TPayload = unknown>(workerId: string, params?: ClaimParams): Promise<JobClaim<TPayload> | null>;
41
+ /**
42
+ * Renews the lease for an in-flight job.
43
+ */
44
+ renewJobLease(workerId: string, jobId: string): Promise<RenewLeaseResponse>;
45
+ /**
46
+ * Marks a job as completed with optional result payload.
47
+ */
48
+ completeJob(workerId: string, jobId: string, result?: unknown): Promise<CompleteJobResponse>;
49
+ /**
50
+ * Reports a job execution failure.
51
+ */
52
+ failJob(workerId: string, jobId: string, params: FailJobParams): Promise<FailJobResponse>;
53
+ /**
54
+ * Transitions worker state to draining.
55
+ */
56
+ drainWorker(workerId: string): Promise<WorkerRecord>;
57
+ /**
58
+ * Deregisters a worker from the active fleet.
59
+ */
60
+ deregisterWorker(workerId: string): Promise<{
61
+ deregistered: boolean;
62
+ workerId: string;
63
+ }>;
64
+ /**
65
+ * Creates a VeyraWorker managed instance tied to this client.
66
+ */
67
+ createWorker(options: VeyraWorkerOptions): VeyraWorker;
68
+ private request;
69
+ }
70
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAUH,OAAO,KAAK,EACV,WAAW,EACX,mBAAmB,EACnB,eAAe,EACf,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,GAAG,EACH,QAAQ,EACR,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,YAAY,EACZ,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AAE,MAAM,EAChB,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,kBAAkB,CAAC;IAU9B;;OAEG;IACG,WAAW,CACf,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,MAAM,CAAC,EAAE,OAAO,GACf,OAAO,CAAC,mBAAmB,CAAC;IAkB/B;;OAEG;IACG,OAAO,CACX,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,eAAe,CAAC;IAa3B;;OAEG;IACG,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAQ1D;;OAEG;IACG,gBAAgB,CACpB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC;QAAE,YAAY,EAAE,OAAO,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IAQvD;;OAEG;IACH,YAAY,CAAC,OAAO,EAAE,kBAAkB,GAAG,WAAW;YAIxC,OAAO;CA8FtB"}
package/dist/client.js ADDED
@@ -0,0 +1,264 @@
1
+ /**
2
+ * Veyra HTTP Client
3
+ */
4
+ import { LeaseLostError, VeyraApiError, VeyraAuthError, VeyraConflictError, VeyraError, VeyraNotFoundError, } from './errors.js';
5
+ import { VeyraWorker } from './worker.js';
6
+ export class VeyraClient {
7
+ baseUrl;
8
+ apiKey;
9
+ defaultQueue;
10
+ customFetch;
11
+ defaultTimeoutMs;
12
+ constructor(config) {
13
+ if (!config?.baseUrl) {
14
+ throw new VeyraError('VeyraClient: baseUrl is required');
15
+ }
16
+ if (!config?.apiKey) {
17
+ throw new VeyraError('VeyraClient: apiKey is required');
18
+ }
19
+ this.baseUrl = config.baseUrl.replace(/\/+$/, '');
20
+ this.apiKey = config.apiKey.trim();
21
+ this.defaultQueue = config.defaultQueue?.trim() || 'default';
22
+ this.customFetch = config.fetch;
23
+ this.defaultTimeoutMs = config.timeoutMs ?? 30_000;
24
+ }
25
+ /**
26
+ * Enqueues a job into Veyra's queue.
27
+ */
28
+ async enqueue(input) {
29
+ const queue = input.queue?.trim() || this.defaultQueue;
30
+ const handler = input.handler?.trim();
31
+ if (!handler) {
32
+ throw new VeyraError('enqueue: handler name is required');
33
+ }
34
+ if (input.payload === undefined) {
35
+ throw new VeyraError('enqueue: payload is required');
36
+ }
37
+ const body = {
38
+ handler,
39
+ queue,
40
+ payload: input.payload,
41
+ };
42
+ if (input.priority !== undefined) {
43
+ body.priority = input.priority;
44
+ }
45
+ if (input.maxAttempts !== undefined) {
46
+ body.maxAttempts = input.maxAttempts;
47
+ }
48
+ if (input.backoff !== undefined) {
49
+ body.backoff = input.backoff;
50
+ }
51
+ if (input.scheduledFor !== undefined) {
52
+ body.scheduledFor =
53
+ input.scheduledFor instanceof Date
54
+ ? input.scheduledFor.toISOString()
55
+ : input.scheduledFor;
56
+ }
57
+ if (input.idempotencyKey) {
58
+ body.idempotencyKey = input.idempotencyKey.trim();
59
+ }
60
+ if (input.callbackUrl) {
61
+ body.callbackUrl = input.callbackUrl.trim();
62
+ }
63
+ const headers = {};
64
+ if (input.idempotencyKey) {
65
+ headers['Idempotency-Key'] = input.idempotencyKey.trim();
66
+ }
67
+ const { data, headers: resHeaders } = await this.request('/jobs', {
68
+ method: 'POST',
69
+ headers,
70
+ body,
71
+ });
72
+ if (resHeaders.get('idempotent-replay') === 'true') {
73
+ data.isReplay = true;
74
+ }
75
+ return data;
76
+ }
77
+ /**
78
+ * Retrieves a job by ID.
79
+ */
80
+ async getJob(jobId) {
81
+ if (!jobId?.trim()) {
82
+ throw new VeyraError('getJob: jobId is required');
83
+ }
84
+ const { data } = await this.request(`/jobs/${encodeURIComponent(jobId.trim())}`, { method: 'GET' });
85
+ return data;
86
+ }
87
+ /**
88
+ * Cancels a job by ID.
89
+ */
90
+ async cancelJob(jobId) {
91
+ if (!jobId?.trim()) {
92
+ throw new VeyraError('cancelJob: jobId is required');
93
+ }
94
+ const { data } = await this.request(`/jobs/${encodeURIComponent(jobId.trim())}/cancel`, { method: 'POST' });
95
+ return data;
96
+ }
97
+ /**
98
+ * Retries a failed, cancelled, or dead-lettered job.
99
+ */
100
+ async retryJob(jobId) {
101
+ if (!jobId?.trim()) {
102
+ throw new VeyraError('retryJob: jobId is required');
103
+ }
104
+ const { data } = await this.request(`/jobs/${encodeURIComponent(jobId.trim())}/retry`, { method: 'POST' });
105
+ return data;
106
+ }
107
+ /**
108
+ * Registers a worker in the Veyra cluster.
109
+ */
110
+ async registerWorker(params) {
111
+ const { data } = await this.request('/workers/register', {
112
+ method: 'POST',
113
+ body: params,
114
+ });
115
+ return data;
116
+ }
117
+ /**
118
+ * Sends a worker-level heartbeat.
119
+ */
120
+ async heartbeatWorker(workerId) {
121
+ const { data } = await this.request(`/workers/${encodeURIComponent(workerId)}/heartbeat`, { method: 'POST' });
122
+ return data;
123
+ }
124
+ /**
125
+ * Claims a job for execution. Returns null if queue is empty (204 No Content).
126
+ */
127
+ async claimJob(workerId, params) {
128
+ const { data, status } = await this.request(`/workers/${encodeURIComponent(workerId)}/claim`, {
129
+ method: 'POST',
130
+ body: params || {},
131
+ });
132
+ if (status === 204 || !data) {
133
+ return null;
134
+ }
135
+ return data;
136
+ }
137
+ /**
138
+ * Renews the lease for an in-flight job.
139
+ */
140
+ async renewJobLease(workerId, jobId) {
141
+ const { data } = await this.request(`/workers/${encodeURIComponent(workerId)}/jobs/${encodeURIComponent(jobId)}/heartbeat`, { method: 'POST' });
142
+ return data;
143
+ }
144
+ /**
145
+ * Marks a job as completed with optional result payload.
146
+ */
147
+ async completeJob(workerId, jobId, result) {
148
+ const body = {};
149
+ if (result !== undefined) {
150
+ body.result = result;
151
+ }
152
+ const { data } = await this.request(`/workers/${encodeURIComponent(workerId)}/jobs/${encodeURIComponent(jobId)}/complete`, {
153
+ method: 'POST',
154
+ body,
155
+ });
156
+ return data;
157
+ }
158
+ /**
159
+ * Reports a job execution failure.
160
+ */
161
+ async failJob(workerId, jobId, params) {
162
+ const { data } = await this.request(`/workers/${encodeURIComponent(workerId)}/jobs/${encodeURIComponent(jobId)}/fail`, {
163
+ method: 'POST',
164
+ body: params,
165
+ });
166
+ return data;
167
+ }
168
+ /**
169
+ * Transitions worker state to draining.
170
+ */
171
+ async drainWorker(workerId) {
172
+ const { data } = await this.request(`/workers/${encodeURIComponent(workerId)}/drain`, { method: 'POST' });
173
+ return data;
174
+ }
175
+ /**
176
+ * Deregisters a worker from the active fleet.
177
+ */
178
+ async deregisterWorker(workerId) {
179
+ const { data } = await this.request(`/workers/${encodeURIComponent(workerId)}/deregister`, { method: 'POST' });
180
+ return data;
181
+ }
182
+ /**
183
+ * Creates a VeyraWorker managed instance tied to this client.
184
+ */
185
+ createWorker(options) {
186
+ return new VeyraWorker(this, options);
187
+ }
188
+ async request(path, options) {
189
+ const fetchImpl = this.customFetch || globalThis.fetch;
190
+ if (!fetchImpl) {
191
+ throw new VeyraError('No fetch implementation available. Node 18+ or a global fetch polyfill is required.');
192
+ }
193
+ const url = `${this.baseUrl}${path}`;
194
+ const headers = {
195
+ Authorization: `Bearer ${this.apiKey}`,
196
+ Accept: 'application/json',
197
+ ...(options.headers || {}),
198
+ };
199
+ let bodyStr;
200
+ if (options.body !== undefined) {
201
+ headers['Content-Type'] = 'application/json';
202
+ bodyStr = JSON.stringify(options.body);
203
+ }
204
+ const controller = new AbortController();
205
+ const timeout = setTimeout(() => controller.abort(), this.defaultTimeoutMs);
206
+ let res;
207
+ try {
208
+ res = await fetchImpl(url, {
209
+ method: options.method,
210
+ headers,
211
+ body: bodyStr,
212
+ signal: options.signal || controller.signal,
213
+ });
214
+ }
215
+ catch (err) {
216
+ clearTimeout(timeout);
217
+ if (err?.name === 'AbortError') {
218
+ throw new VeyraError(`Request timed out after ${this.defaultTimeoutMs}ms: ${url}`);
219
+ }
220
+ throw new VeyraError(`Network error while fetching ${url}: ${err.message}`);
221
+ }
222
+ finally {
223
+ clearTimeout(timeout);
224
+ }
225
+ if (res.status === 204) {
226
+ return { data: undefined, status: 204, headers: res.headers };
227
+ }
228
+ const text = await res.text();
229
+ let parsed;
230
+ if (text.length > 0) {
231
+ try {
232
+ parsed = JSON.parse(text);
233
+ }
234
+ catch {
235
+ parsed = text;
236
+ }
237
+ }
238
+ if (!res.ok) {
239
+ const errorMessage = (typeof parsed === 'object' &&
240
+ parsed !== null &&
241
+ 'error' in parsed &&
242
+ typeof parsed.error === 'string' &&
243
+ parsed.error) ||
244
+ res.statusText ||
245
+ `HTTP ${res.status}`;
246
+ if (res.status === 401 || res.status === 403) {
247
+ throw new VeyraAuthError(res.status, res.statusText, errorMessage, parsed);
248
+ }
249
+ if (res.status === 404) {
250
+ throw new VeyraNotFoundError(res.status, res.statusText, errorMessage, parsed);
251
+ }
252
+ if (res.status === 409) {
253
+ if (typeof errorMessage === 'string' &&
254
+ (errorMessage.includes('lease') || errorMessage.includes('expired'))) {
255
+ throw new LeaseLostError(errorMessage);
256
+ }
257
+ throw new VeyraConflictError(res.status, res.statusText, errorMessage, parsed);
258
+ }
259
+ throw new VeyraApiError(res.status, res.statusText, errorMessage, parsed);
260
+ }
261
+ return { data: parsed, status: res.status, headers: res.headers };
262
+ }
263
+ }
264
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,cAAc,EACd,aAAa,EACb,cAAc,EACd,kBAAkB,EAClB,UAAU,EACV,kBAAkB,GACnB,MAAM,aAAa,CAAC;AAgBrB,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,MAAM,OAAO,WAAW;IACb,OAAO,CAAS;IAChB,MAAM,CAAS;IACf,YAAY,CAAS;IACb,WAAW,CAAgB;IAC3B,gBAAgB,CAAS;IAE1C,YAAY,MAAyB;QACnC,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC;YACrB,MAAM,IAAI,UAAU,CAAC,kCAAkC,CAAC,CAAC;QA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,OAAO,YAAY,KAAK,QAAQ;oBAChC,CAAC,YAAY,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,YAAY,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,EACpE,CAAC;oBACD,MAAM,IAAI,cAAc,CAAC,YAAY,CAAC,CAAC;gBACzC,CAAC;gBACD,MAAM,IAAI,kBAAkB,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,UAAU,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC;YACjF,CAAC;YACD,MAAM,IAAI,aAAa,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,UAAU,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC;QAC5E,CAAC;QAED,OAAO,EAAE,IAAI,EAAE,MAAW,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC;IACzE,CAAC;CACF"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Veyra Error Classes
3
+ */
4
+ export declare class VeyraError extends Error {
5
+ constructor(message: string);
6
+ }
7
+ export declare class VeyraApiError extends VeyraError {
8
+ readonly status: number;
9
+ readonly statusText: string;
10
+ readonly body: unknown;
11
+ constructor(status: number, statusText: string, message: string, body: unknown);
12
+ }
13
+ export declare class VeyraAuthError extends VeyraApiError {
14
+ constructor(status: number, statusText: string, message: string, body: unknown);
15
+ }
16
+ export declare class VeyraNotFoundError extends VeyraApiError {
17
+ constructor(status: number, statusText: string, message: string, body: unknown);
18
+ }
19
+ export declare class VeyraConflictError extends VeyraApiError {
20
+ constructor(status: number, statusText: string, message: string, body: unknown);
21
+ }
22
+ export declare class LeaseLostError extends VeyraConflictError {
23
+ constructor(message?: string);
24
+ }
25
+ /**
26
+ * Throwing a NonRetryableError signals to Veyra that the job should fail
27
+ * permanently (dead-lettered immediately) without exhausting max attempts.
28
+ */
29
+ export declare class NonRetryableError extends Error {
30
+ readonly permanent = true;
31
+ constructor(message: string);
32
+ }
33
+ export declare function isNonRetryable(err: unknown): boolean;
34
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,qBAAa,UAAW,SAAQ,KAAK;gBACvB,OAAO,EAAE,MAAM;CAK5B;AAED,qBAAa,aAAc,SAAQ,UAAU;IAC3C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;gBAEX,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO;CAQ/E;AAED,qBAAa,cAAe,SAAQ,aAAa;gBACnC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO;CAK/E;AAED,qBAAa,kBAAmB,SAAQ,aAAa;gBACvC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO;CAK/E;AAED,qBAAa,kBAAmB,SAAQ,aAAa;gBACvC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO;CAK/E;AAED,qBAAa,cAAe,SAAQ,kBAAkB;gBACxC,OAAO,SAAkC;CAKtD;AAED;;;GAGG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,QAAQ,CAAC,SAAS,QAAQ;gBAEd,OAAO,EAAE,MAAM;CAK5B;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAQpD"}
package/dist/errors.js ADDED
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Veyra Error Classes
3
+ */
4
+ export class VeyraError extends Error {
5
+ constructor(message) {
6
+ super(message);
7
+ this.name = 'VeyraError';
8
+ Object.setPrototypeOf(this, new.target.prototype);
9
+ }
10
+ }
11
+ export class VeyraApiError extends VeyraError {
12
+ status;
13
+ statusText;
14
+ body;
15
+ constructor(status, statusText, message, body) {
16
+ super(message);
17
+ this.name = 'VeyraApiError';
18
+ this.status = status;
19
+ this.statusText = statusText;
20
+ this.body = body;
21
+ Object.setPrototypeOf(this, new.target.prototype);
22
+ }
23
+ }
24
+ export class VeyraAuthError extends VeyraApiError {
25
+ constructor(status, statusText, message, body) {
26
+ super(status, statusText, message, body);
27
+ this.name = 'VeyraAuthError';
28
+ Object.setPrototypeOf(this, new.target.prototype);
29
+ }
30
+ }
31
+ export class VeyraNotFoundError extends VeyraApiError {
32
+ constructor(status, statusText, message, body) {
33
+ super(status, statusText, message, body);
34
+ this.name = 'VeyraNotFoundError';
35
+ Object.setPrototypeOf(this, new.target.prototype);
36
+ }
37
+ }
38
+ export class VeyraConflictError extends VeyraApiError {
39
+ constructor(status, statusText, message, body) {
40
+ super(status, statusText, message, body);
41
+ this.name = 'VeyraConflictError';
42
+ Object.setPrototypeOf(this, new.target.prototype);
43
+ }
44
+ }
45
+ export class LeaseLostError extends VeyraConflictError {
46
+ constructor(message = 'Job lease was lost or expired') {
47
+ super(409, 'Conflict', message, { error: message });
48
+ this.name = 'LeaseLostError';
49
+ Object.setPrototypeOf(this, new.target.prototype);
50
+ }
51
+ }
52
+ /**
53
+ * Throwing a NonRetryableError signals to Veyra that the job should fail
54
+ * permanently (dead-lettered immediately) without exhausting max attempts.
55
+ */
56
+ export class NonRetryableError extends Error {
57
+ permanent = true;
58
+ constructor(message) {
59
+ super(message);
60
+ this.name = 'NonRetryableError';
61
+ Object.setPrototypeOf(this, new.target.prototype);
62
+ }
63
+ }
64
+ export function isNonRetryable(err) {
65
+ if (err instanceof NonRetryableError) {
66
+ return true;
67
+ }
68
+ if (typeof err === 'object' && err !== null && 'permanent' in err) {
69
+ return Boolean(err.permanent);
70
+ }
71
+ return false;
72
+ }
73
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,OAAO,UAAW,SAAQ,KAAK;IACnC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;QACzB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACpD,CAAC;CACF;AAED,MAAM,OAAO,aAAc,SAAQ,UAAU;IAClC,MAAM,CAAS;IACf,UAAU,CAAS;IACnB,IAAI,CAAU;IAEvB,YAAY,MAAc,EAAE,UAAkB,EAAE,OAAe,EAAE,IAAa;QAC5E,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACpD,CAAC;CACF;AAED,MAAM,OAAO,cAAe,SAAQ,aAAa;IAC/C,YAAY,MAAc,EAAE,UAAkB,EAAE,OAAe,EAAE,IAAa;QAC5E,KAAK,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;QACzC,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;QAC7B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACpD,CAAC;CACF;AAED,MAAM,OAAO,kBAAmB,SAAQ,aAAa;IACnD,YAAY,MAAc,EAAE,UAAkB,EAA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