@rendobar/sdk 3.3.0 → 4.0.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/dist/index.cjs +6 -17
- package/dist/index.d.cts +221 -44
- package/dist/index.d.mts +221 -44
- package/dist/index.mjs +6 -17
- package/dist/webhooks.cjs +61 -5
- package/dist/webhooks.d.cts +37 -6
- package/dist/webhooks.d.mts +37 -6
- package/dist/webhooks.mjs +61 -6
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -249,6 +249,12 @@ function createJobsResource(request) {
|
|
|
249
249
|
},
|
|
250
250
|
async types(options) {
|
|
251
251
|
return request("/jobs/types", { signal: options?.signal });
|
|
252
|
+
},
|
|
253
|
+
async stats(params, options) {
|
|
254
|
+
return request("/jobs/stats", {
|
|
255
|
+
query: params,
|
|
256
|
+
signal: options?.signal
|
|
257
|
+
});
|
|
252
258
|
}
|
|
253
259
|
};
|
|
254
260
|
}
|
|
@@ -640,22 +646,6 @@ function createOrgsResource(request) {
|
|
|
640
646
|
};
|
|
641
647
|
}
|
|
642
648
|
//#endregion
|
|
643
|
-
//#region src/resources/batches.ts
|
|
644
|
-
function createBatchesResource(request) {
|
|
645
|
-
return {
|
|
646
|
-
async create(params, options) {
|
|
647
|
-
return request("/batches", {
|
|
648
|
-
method: "POST",
|
|
649
|
-
body: params,
|
|
650
|
-
signal: options?.signal
|
|
651
|
-
});
|
|
652
|
-
},
|
|
653
|
-
async get(id, options) {
|
|
654
|
-
return request(`/batches/${id}`, { signal: options?.signal });
|
|
655
|
-
}
|
|
656
|
-
};
|
|
657
|
-
}
|
|
658
|
-
//#endregion
|
|
659
649
|
//#region src/resources/assets.ts
|
|
660
650
|
function createAssetsResource(request) {
|
|
661
651
|
return {
|
|
@@ -873,7 +863,6 @@ function createClient(config = {}) {
|
|
|
873
863
|
webhooks: createWebhooksResource(request),
|
|
874
864
|
apiKeys: createApiKeysResource(request),
|
|
875
865
|
orgs: createOrgsResource(request),
|
|
876
|
-
batches: createBatchesResource(request),
|
|
877
866
|
assets: createAssetsResource(request),
|
|
878
867
|
team: createTeamResource(request),
|
|
879
868
|
realtime: createRealtimeClient(baseUrl, {
|
package/dist/index.d.cts
CHANGED
|
@@ -2243,6 +2243,11 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2243
2243
|
id: ZodString;
|
|
2244
2244
|
orgId: ZodString;
|
|
2245
2245
|
type: ZodString;
|
|
2246
|
+
source: ZodString;
|
|
2247
|
+
client: ZodNullable<ZodString>;
|
|
2248
|
+
retryCount: ZodNumber;
|
|
2249
|
+
idempotencyKey: ZodNullable<ZodString>;
|
|
2250
|
+
mediaType: ZodNullable<ZodString>;
|
|
2246
2251
|
inputs: ZodRecord<ZodString, ZodUnknown>;
|
|
2247
2252
|
params: ZodRecord<ZodString, ZodUnknown>;
|
|
2248
2253
|
cost: ZodNullable<ZodObject<{
|
|
@@ -2276,11 +2281,17 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2276
2281
|
startedAt: ZodNullable<ZodNumber>;
|
|
2277
2282
|
completedAt: ZodNullable<ZodNumber>;
|
|
2278
2283
|
settledAt: ZodNullable<ZodNumber>;
|
|
2284
|
+
retentionExpiresAt: ZodNullable<ZodNumber>;
|
|
2279
2285
|
status: ZodLiteral<"waiting">;
|
|
2280
2286
|
}, $strip>, ZodObject<{
|
|
2281
2287
|
id: ZodString;
|
|
2282
2288
|
orgId: ZodString;
|
|
2283
2289
|
type: ZodString;
|
|
2290
|
+
source: ZodString;
|
|
2291
|
+
client: ZodNullable<ZodString>;
|
|
2292
|
+
retryCount: ZodNumber;
|
|
2293
|
+
idempotencyKey: ZodNullable<ZodString>;
|
|
2294
|
+
mediaType: ZodNullable<ZodString>;
|
|
2284
2295
|
inputs: ZodRecord<ZodString, ZodUnknown>;
|
|
2285
2296
|
params: ZodRecord<ZodString, ZodUnknown>;
|
|
2286
2297
|
cost: ZodNullable<ZodObject<{
|
|
@@ -2314,6 +2325,7 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2314
2325
|
startedAt: ZodNullable<ZodNumber>;
|
|
2315
2326
|
completedAt: ZodNullable<ZodNumber>;
|
|
2316
2327
|
settledAt: ZodNullable<ZodNumber>;
|
|
2328
|
+
retentionExpiresAt: ZodNullable<ZodNumber>;
|
|
2317
2329
|
status: ZodLiteral<"dispatched">;
|
|
2318
2330
|
progress: ZodOptional<ZodNumber>;
|
|
2319
2331
|
eta: ZodOptional<ZodNullable<ZodNumber>>;
|
|
@@ -2321,6 +2333,11 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2321
2333
|
id: ZodString;
|
|
2322
2334
|
orgId: ZodString;
|
|
2323
2335
|
type: ZodString;
|
|
2336
|
+
source: ZodString;
|
|
2337
|
+
client: ZodNullable<ZodString>;
|
|
2338
|
+
retryCount: ZodNumber;
|
|
2339
|
+
idempotencyKey: ZodNullable<ZodString>;
|
|
2340
|
+
mediaType: ZodNullable<ZodString>;
|
|
2324
2341
|
inputs: ZodRecord<ZodString, ZodUnknown>;
|
|
2325
2342
|
params: ZodRecord<ZodString, ZodUnknown>;
|
|
2326
2343
|
cost: ZodNullable<ZodObject<{
|
|
@@ -2354,6 +2371,7 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2354
2371
|
startedAt: ZodNullable<ZodNumber>;
|
|
2355
2372
|
completedAt: ZodNullable<ZodNumber>;
|
|
2356
2373
|
settledAt: ZodNullable<ZodNumber>;
|
|
2374
|
+
retentionExpiresAt: ZodNullable<ZodNumber>;
|
|
2357
2375
|
status: ZodLiteral<"running">;
|
|
2358
2376
|
progress: ZodNumber;
|
|
2359
2377
|
eta: ZodNullable<ZodNumber>;
|
|
@@ -2361,6 +2379,11 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2361
2379
|
id: ZodString;
|
|
2362
2380
|
orgId: ZodString;
|
|
2363
2381
|
type: ZodString;
|
|
2382
|
+
source: ZodString;
|
|
2383
|
+
client: ZodNullable<ZodString>;
|
|
2384
|
+
retryCount: ZodNumber;
|
|
2385
|
+
idempotencyKey: ZodNullable<ZodString>;
|
|
2386
|
+
mediaType: ZodNullable<ZodString>;
|
|
2364
2387
|
inputs: ZodRecord<ZodString, ZodUnknown>;
|
|
2365
2388
|
params: ZodRecord<ZodString, ZodUnknown>;
|
|
2366
2389
|
cost: ZodNullable<ZodObject<{
|
|
@@ -2394,6 +2417,7 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2394
2417
|
startedAt: ZodNullable<ZodNumber>;
|
|
2395
2418
|
completedAt: ZodNullable<ZodNumber>;
|
|
2396
2419
|
settledAt: ZodNullable<ZodNumber>;
|
|
2420
|
+
retentionExpiresAt: ZodNullable<ZodNumber>;
|
|
2397
2421
|
status: ZodLiteral<"complete">;
|
|
2398
2422
|
output: ZodObject<{
|
|
2399
2423
|
data: ZodUnknown;
|
|
@@ -2443,6 +2467,11 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2443
2467
|
id: ZodString;
|
|
2444
2468
|
orgId: ZodString;
|
|
2445
2469
|
type: ZodString;
|
|
2470
|
+
source: ZodString;
|
|
2471
|
+
client: ZodNullable<ZodString>;
|
|
2472
|
+
retryCount: ZodNumber;
|
|
2473
|
+
idempotencyKey: ZodNullable<ZodString>;
|
|
2474
|
+
mediaType: ZodNullable<ZodString>;
|
|
2446
2475
|
inputs: ZodRecord<ZodString, ZodUnknown>;
|
|
2447
2476
|
params: ZodRecord<ZodString, ZodUnknown>;
|
|
2448
2477
|
cost: ZodNullable<ZodObject<{
|
|
@@ -2476,6 +2505,7 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2476
2505
|
startedAt: ZodNullable<ZodNumber>;
|
|
2477
2506
|
completedAt: ZodNullable<ZodNumber>;
|
|
2478
2507
|
settledAt: ZodNullable<ZodNumber>;
|
|
2508
|
+
retentionExpiresAt: ZodNullable<ZodNumber>;
|
|
2479
2509
|
status: ZodLiteral<"failed">;
|
|
2480
2510
|
error: ZodObject<{
|
|
2481
2511
|
code: ZodString;
|
|
@@ -2487,6 +2517,11 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2487
2517
|
id: ZodString;
|
|
2488
2518
|
orgId: ZodString;
|
|
2489
2519
|
type: ZodString;
|
|
2520
|
+
source: ZodString;
|
|
2521
|
+
client: ZodNullable<ZodString>;
|
|
2522
|
+
retryCount: ZodNumber;
|
|
2523
|
+
idempotencyKey: ZodNullable<ZodString>;
|
|
2524
|
+
mediaType: ZodNullable<ZodString>;
|
|
2490
2525
|
inputs: ZodRecord<ZodString, ZodUnknown>;
|
|
2491
2526
|
params: ZodRecord<ZodString, ZodUnknown>;
|
|
2492
2527
|
cost: ZodNullable<ZodObject<{
|
|
@@ -2520,24 +2555,46 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2520
2555
|
startedAt: ZodNullable<ZodNumber>;
|
|
2521
2556
|
completedAt: ZodNullable<ZodNumber>;
|
|
2522
2557
|
settledAt: ZodNullable<ZodNumber>;
|
|
2558
|
+
retentionExpiresAt: ZodNullable<ZodNumber>;
|
|
2523
2559
|
status: ZodLiteral<"cancelled">;
|
|
2524
2560
|
}, $strip>], "status">;
|
|
2525
2561
|
declare const jobCreatedResponseSchema: ZodObject<{
|
|
2526
2562
|
id: ZodString;
|
|
2527
2563
|
status: ZodLiteral<"waiting">;
|
|
2528
2564
|
}, $strip>;
|
|
2565
|
+
declare const jobStatsResponseSchema: ZodObject<{
|
|
2566
|
+
data: ZodObject<{
|
|
2567
|
+
window: ZodObject<{
|
|
2568
|
+
from: ZodNumber;
|
|
2569
|
+
to: ZodNumber;
|
|
2570
|
+
}, $strip>;
|
|
2571
|
+
totals: ZodObject<{
|
|
2572
|
+
jobs: ZodNumber;
|
|
2573
|
+
succeeded: ZodNumber;
|
|
2574
|
+
failed: ZodNumber;
|
|
2575
|
+
cancelled: ZodNumber;
|
|
2576
|
+
running: ZodNumber;
|
|
2577
|
+
}, $strip>;
|
|
2578
|
+
successRate: ZodNullable<ZodNumber>;
|
|
2579
|
+
avgDurationMs: ZodNullable<ZodNumber>;
|
|
2580
|
+
spend: ZodObject<{
|
|
2581
|
+
amount: ZodNumber;
|
|
2582
|
+
formatted: ZodString;
|
|
2583
|
+
}, $strip>;
|
|
2584
|
+
activity: ZodArray<ZodObject<{
|
|
2585
|
+
bucketStart: ZodNumber;
|
|
2586
|
+
succeeded: ZodNumber;
|
|
2587
|
+
failed: ZodNumber;
|
|
2588
|
+
other: ZodNumber;
|
|
2589
|
+
}, $strip>>;
|
|
2590
|
+
}, $strip>;
|
|
2591
|
+
}, $strip>;
|
|
2592
|
+
type JobStats = output<typeof jobStatsResponseSchema>["data"];
|
|
2529
2593
|
declare const jobTypeSchema: ZodObject<{
|
|
2530
2594
|
type: ZodString;
|
|
2531
2595
|
tag: ZodString;
|
|
2532
2596
|
summary: ZodString;
|
|
2533
|
-
needs: ZodArray<ZodString>;
|
|
2534
|
-
pattern: ZodNullable<ZodString>;
|
|
2535
|
-
runner: ZodOptional<ZodObject<{
|
|
2536
|
-
id: ZodString;
|
|
2537
|
-
resource: ZodString;
|
|
2538
|
-
}, $strip>>;
|
|
2539
2597
|
acceptsMedia: ZodArray<ZodString>;
|
|
2540
|
-
mediaOverrides: ZodOptional<ZodRecord<ZodString, ZodUnknown>>;
|
|
2541
2598
|
}, $strip>;
|
|
2542
2599
|
declare const billingStateSchema: ZodObject<{
|
|
2543
2600
|
balance: ZodObject<{
|
|
@@ -2552,7 +2609,6 @@ declare const billingStateSchema: ZodObject<{
|
|
|
2552
2609
|
apiRequestsPerMinute: ZodNumber;
|
|
2553
2610
|
maxJobTimeout: ZodNumber;
|
|
2554
2611
|
maxInputFileSize: ZodNumber;
|
|
2555
|
-
maxBatchSize: ZodNumber;
|
|
2556
2612
|
}, $strip>;
|
|
2557
2613
|
}, $strip>;
|
|
2558
2614
|
subscription: ZodNullable<ZodObject<{
|
|
@@ -2576,7 +2632,6 @@ declare const billingStateSchema: ZodObject<{
|
|
|
2576
2632
|
apiRequestsPerMinute: ZodNumber;
|
|
2577
2633
|
maxJobTimeout: ZodNumber;
|
|
2578
2634
|
maxInputFileSize: ZodNumber;
|
|
2579
|
-
maxBatchSize: ZodNumber;
|
|
2580
2635
|
}, $strip>;
|
|
2581
2636
|
}, $strip>>;
|
|
2582
2637
|
}, $strip>;
|
|
@@ -2634,11 +2689,15 @@ declare const webhookDeliverySchema: ZodObject<{
|
|
|
2634
2689
|
id: ZodString;
|
|
2635
2690
|
endpointId: ZodString;
|
|
2636
2691
|
endpointName: ZodNullable<ZodString>;
|
|
2637
|
-
jobId: ZodString
|
|
2638
|
-
batchId: ZodNullable<ZodString>;
|
|
2692
|
+
jobId: ZodNullable<ZodString>;
|
|
2639
2693
|
event: ZodString;
|
|
2640
2694
|
payload: ZodString;
|
|
2641
|
-
status:
|
|
2695
|
+
status: ZodEnum<{
|
|
2696
|
+
failed: "failed";
|
|
2697
|
+
cancelled: "cancelled";
|
|
2698
|
+
pending: "pending";
|
|
2699
|
+
delivered: "delivered";
|
|
2700
|
+
}>;
|
|
2642
2701
|
statusCode: ZodNullable<ZodNumber>;
|
|
2643
2702
|
responseBody: ZodNullable<ZodString>;
|
|
2644
2703
|
attempts: ZodNumber;
|
|
@@ -2961,6 +3020,130 @@ interface LogEntryData {
|
|
|
2961
3020
|
meta?: Record<string, unknown>;
|
|
2962
3021
|
}
|
|
2963
3022
|
//#endregion
|
|
3023
|
+
//#region ../shared/src/constants/webhook-events.d.ts
|
|
3024
|
+
declare const WEBHOOK_EVENT_TYPES: readonly ["job.created", "job.started", "job.completed", "job.failed", "job.cancelled", "balance.low", "balance.depleted"];
|
|
3025
|
+
type WebhookEventType = (typeof WEBHOOK_EVENT_TYPES)[number];
|
|
3026
|
+
//#endregion
|
|
3027
|
+
//#region ../shared/src/types/webhook.d.ts
|
|
3028
|
+
interface JobCreatedData {
|
|
3029
|
+
jobId: string;
|
|
3030
|
+
jobType: string;
|
|
3031
|
+
status: "waiting";
|
|
3032
|
+
timing: {
|
|
3033
|
+
createdAt: number;
|
|
3034
|
+
};
|
|
3035
|
+
}
|
|
3036
|
+
interface JobStartedData {
|
|
3037
|
+
jobId: string;
|
|
3038
|
+
jobType: string;
|
|
3039
|
+
status: "running";
|
|
3040
|
+
timing: {
|
|
3041
|
+
createdAt: number;
|
|
3042
|
+
dispatchedAt?: number;
|
|
3043
|
+
startedAt: number;
|
|
3044
|
+
};
|
|
3045
|
+
}
|
|
3046
|
+
interface JobCompletedData {
|
|
3047
|
+
jobId: string;
|
|
3048
|
+
jobType: string;
|
|
3049
|
+
status: "complete";
|
|
3050
|
+
output: Output;
|
|
3051
|
+
cost?: {
|
|
3052
|
+
amount: number;
|
|
3053
|
+
currency: "USD";
|
|
3054
|
+
formatted: string;
|
|
3055
|
+
breakdown: string;
|
|
3056
|
+
};
|
|
3057
|
+
timing: {
|
|
3058
|
+
createdAt: number;
|
|
3059
|
+
dispatchedAt?: number;
|
|
3060
|
+
startedAt?: number;
|
|
3061
|
+
completedAt: number;
|
|
3062
|
+
};
|
|
3063
|
+
steps?: Array<{
|
|
3064
|
+
id: string;
|
|
3065
|
+
name: string;
|
|
3066
|
+
status: string;
|
|
3067
|
+
durationMs?: number;
|
|
3068
|
+
error?: string;
|
|
3069
|
+
}>;
|
|
3070
|
+
outputCategory?: string;
|
|
3071
|
+
mediaType?: string;
|
|
3072
|
+
}
|
|
3073
|
+
interface JobFailedData {
|
|
3074
|
+
jobId: string;
|
|
3075
|
+
jobType: string;
|
|
3076
|
+
status: "failed";
|
|
3077
|
+
error: JobError;
|
|
3078
|
+
timing: {
|
|
3079
|
+
createdAt: number;
|
|
3080
|
+
dispatchedAt?: number;
|
|
3081
|
+
startedAt?: number;
|
|
3082
|
+
failedAt: number;
|
|
3083
|
+
};
|
|
3084
|
+
steps?: Array<{
|
|
3085
|
+
id: string;
|
|
3086
|
+
name: string;
|
|
3087
|
+
status: string;
|
|
3088
|
+
durationMs?: number;
|
|
3089
|
+
error?: string;
|
|
3090
|
+
}>;
|
|
3091
|
+
}
|
|
3092
|
+
interface JobCancelledData {
|
|
3093
|
+
jobId: string;
|
|
3094
|
+
jobType: string;
|
|
3095
|
+
status: "cancelled";
|
|
3096
|
+
timing: {
|
|
3097
|
+
createdAt: number;
|
|
3098
|
+
cancelledAt: number;
|
|
3099
|
+
};
|
|
3100
|
+
}
|
|
3101
|
+
interface BalanceLowData {
|
|
3102
|
+
balance: number;
|
|
3103
|
+
balanceFormatted: string;
|
|
3104
|
+
threshold: number;
|
|
3105
|
+
thresholdFormatted: string;
|
|
3106
|
+
triggeredByJobId: string;
|
|
3107
|
+
triggeredByJobType: string;
|
|
3108
|
+
}
|
|
3109
|
+
interface BalanceDepletedData {
|
|
3110
|
+
balance: number;
|
|
3111
|
+
balanceFormatted: string;
|
|
3112
|
+
triggeredByJobId: string;
|
|
3113
|
+
triggeredByJobType: string;
|
|
3114
|
+
}
|
|
3115
|
+
interface TestEventData {
|
|
3116
|
+
message: string;
|
|
3117
|
+
endpointId: string;
|
|
3118
|
+
}
|
|
3119
|
+
/**
|
|
3120
|
+
* Maps each event to its `data` shape. The `WebhookPayload` mapped type below
|
|
3121
|
+
* fails to compile if WEBHOOK_EVENT_TYPES gains an event that is missing here,
|
|
3122
|
+
* so this map is the enforced single source of truth for payload shapes.
|
|
3123
|
+
*/
|
|
3124
|
+
interface WebhookEventDataMap {
|
|
3125
|
+
"job.created": JobCreatedData;
|
|
3126
|
+
"job.started": JobStartedData;
|
|
3127
|
+
"job.completed": JobCompletedData;
|
|
3128
|
+
"job.failed": JobFailedData;
|
|
3129
|
+
"job.cancelled": JobCancelledData;
|
|
3130
|
+
"balance.low": BalanceLowData;
|
|
3131
|
+
"balance.depleted": BalanceDepletedData;
|
|
3132
|
+
}
|
|
3133
|
+
interface Envelope<E extends string, D> {
|
|
3134
|
+
version: "1";
|
|
3135
|
+
event: E;
|
|
3136
|
+
deliveryId: string;
|
|
3137
|
+
timestamp: number;
|
|
3138
|
+
orgId: string;
|
|
3139
|
+
data: D;
|
|
3140
|
+
}
|
|
3141
|
+
/**
|
|
3142
|
+
* The exact JSON body Rendobar POSTs to your endpoint, discriminated by `event`.
|
|
3143
|
+
* Switch on `payload.event` and `payload.data` narrows to the matching shape.
|
|
3144
|
+
*/
|
|
3145
|
+
type WebhookPayload = { [E in WebhookEventType]: Envelope<E, WebhookEventDataMap[E]> }[WebhookEventType] | Envelope<"test", TestEventData>;
|
|
3146
|
+
//#endregion
|
|
2964
3147
|
//#region src/types.d.ts
|
|
2965
3148
|
/**
|
|
2966
3149
|
* Primary playable/download URL for a completed job, or `undefined`.
|
|
@@ -3065,6 +3248,9 @@ declare function createClient(config?: ClientConfig): {
|
|
|
3065
3248
|
types(options?: {
|
|
3066
3249
|
signal?: AbortSignal;
|
|
3067
3250
|
}): Promise<JobType[]>;
|
|
3251
|
+
stats(params?: StatsParams, options?: {
|
|
3252
|
+
signal?: AbortSignal;
|
|
3253
|
+
}): Promise<JobStats>;
|
|
3068
3254
|
};
|
|
3069
3255
|
billing: {
|
|
3070
3256
|
state(options?: {
|
|
@@ -3142,7 +3328,7 @@ declare function createClient(config?: ClientConfig): {
|
|
|
3142
3328
|
signal?: AbortSignal;
|
|
3143
3329
|
}): Promise<WebhookEndpoint>;
|
|
3144
3330
|
update(id: string, params: UpdateWebhookParams, options?: {
|
|
3145
|
-
signal
|
|
3331
|
+
signal?: AbortSignal;
|
|
3146
3332
|
}): Promise<WebhookEndpoint>;
|
|
3147
3333
|
delete(id: string, options?: {
|
|
3148
3334
|
signal?: AbortSignal;
|
|
@@ -3165,7 +3351,7 @@ declare function createClient(config?: ClientConfig): {
|
|
|
3165
3351
|
}>;
|
|
3166
3352
|
retryDelivery(id: string, options?: {
|
|
3167
3353
|
signal?: AbortSignal;
|
|
3168
|
-
}): Promise<
|
|
3354
|
+
}): Promise<RetryDeliveryResult>;
|
|
3169
3355
|
};
|
|
3170
3356
|
apiKeys: {
|
|
3171
3357
|
create(params: {
|
|
@@ -3215,28 +3401,12 @@ declare function createClient(config?: ClientConfig): {
|
|
|
3215
3401
|
signal?: AbortSignal;
|
|
3216
3402
|
}): Promise<void>;
|
|
3217
3403
|
getSettings(options?: {
|
|
3218
|
-
signal
|
|
3404
|
+
signal? /** Custom fetch function for testing or special runtimes. */: AbortSignal;
|
|
3219
3405
|
}): Promise<OrgSettings>;
|
|
3220
3406
|
updateSettings(body: Partial<Pick<OrgSettings, "billingEmailsEnabled" | "defaultRegion" | "regionPinned">>, options?: {
|
|
3221
3407
|
signal?: AbortSignal;
|
|
3222
3408
|
}): Promise<OrgSettings>;
|
|
3223
3409
|
};
|
|
3224
|
-
batches: {
|
|
3225
|
-
create(params: {
|
|
3226
|
-
jobs: CreateJobParams[];
|
|
3227
|
-
}, options?: {
|
|
3228
|
-
signal?: AbortSignal;
|
|
3229
|
-
}): Promise<BatchResult>;
|
|
3230
|
-
get(id: string, options?: {
|
|
3231
|
-
signal?: AbortSignal;
|
|
3232
|
-
}): Promise<{
|
|
3233
|
-
id: string;
|
|
3234
|
-
orgId: string;
|
|
3235
|
-
jobCount: number;
|
|
3236
|
-
completedCount: number;
|
|
3237
|
-
createdAt: number;
|
|
3238
|
-
}>;
|
|
3239
|
-
};
|
|
3240
3410
|
assets: {
|
|
3241
3411
|
list(params?: ListAssetsParams, options?: {
|
|
3242
3412
|
signal?: AbortSignal;
|
|
@@ -3401,7 +3571,15 @@ type ListJobsParams = {
|
|
|
3401
3571
|
status?: string;
|
|
3402
3572
|
type?: string;
|
|
3403
3573
|
limit?: number;
|
|
3404
|
-
offset?: number;
|
|
3574
|
+
offset?: number; /** Sort field. Default: created. */
|
|
3575
|
+
sort?: "created" | "duration" | "cost"; /** Sort direction. Default: desc. */
|
|
3576
|
+
order?: "asc" | "desc"; /** Filter by originating client (sdk | cli | mcp | dashboard | ...). */
|
|
3577
|
+
client?: string; /** Filter jobs created at or after this Unix ms timestamp. */
|
|
3578
|
+
from?: number; /** Filter jobs created at or before this Unix ms timestamp. */
|
|
3579
|
+
to?: number;
|
|
3580
|
+
};
|
|
3581
|
+
type StatsParams = {
|
|
3582
|
+
/** Time window for the aggregate. Default: 24h. */window?: "24h" | "7d" | "30d";
|
|
3405
3583
|
};
|
|
3406
3584
|
type WaitOptions = {
|
|
3407
3585
|
/** Max wait time in ms. Default: 300_000 (5 minutes). */timeout?: number; /** Initial poll interval in ms. Default: 2_000. Grows with exponential backoff. */
|
|
@@ -3434,22 +3612,29 @@ type TransactionListParams = {
|
|
|
3434
3612
|
type CreateWebhookParams = {
|
|
3435
3613
|
name: string;
|
|
3436
3614
|
url: string;
|
|
3437
|
-
subscribedEvents:
|
|
3615
|
+
subscribedEvents: WebhookEventType[];
|
|
3438
3616
|
};
|
|
3439
3617
|
type UpdateWebhookParams = {
|
|
3440
3618
|
name?: string;
|
|
3441
3619
|
url?: string;
|
|
3442
|
-
subscribedEvents?:
|
|
3620
|
+
subscribedEvents?: WebhookEventType[];
|
|
3443
3621
|
active?: boolean;
|
|
3444
3622
|
};
|
|
3445
3623
|
type ListDeliveriesParams = {
|
|
3446
3624
|
endpointId?: string;
|
|
3447
|
-
event?:
|
|
3625
|
+
event?: WebhookEventType;
|
|
3448
3626
|
status?: string;
|
|
3449
3627
|
jobId?: string;
|
|
3450
3628
|
limit?: number;
|
|
3451
3629
|
offset?: number;
|
|
3452
3630
|
};
|
|
3631
|
+
/** The retry route echoes only these fields — not a full delivery record. */
|
|
3632
|
+
type RetryDeliveryResult = {
|
|
3633
|
+
id: string;
|
|
3634
|
+
status: string;
|
|
3635
|
+
event: string;
|
|
3636
|
+
endpointId: string;
|
|
3637
|
+
};
|
|
3453
3638
|
//#endregion
|
|
3454
3639
|
//#region src/resources/orgs.d.ts
|
|
3455
3640
|
type OrgCurrentResponse = {
|
|
@@ -3476,14 +3661,6 @@ type OrgCurrentResponse = {
|
|
|
3476
3661
|
};
|
|
3477
3662
|
};
|
|
3478
3663
|
//#endregion
|
|
3479
|
-
//#region src/resources/batches.d.ts
|
|
3480
|
-
type BatchResult = {
|
|
3481
|
-
batchId: string;
|
|
3482
|
-
jobCount: number;
|
|
3483
|
-
jobIds: string[];
|
|
3484
|
-
status: string;
|
|
3485
|
-
};
|
|
3486
|
-
//#endregion
|
|
3487
3664
|
//#region src/resources/uploads.d.ts
|
|
3488
3665
|
type UploadProgress = {
|
|
3489
3666
|
loaded: number;
|
|
@@ -3513,4 +3690,4 @@ type AssetListPage = {
|
|
|
3513
3690
|
meta: AssetListMeta;
|
|
3514
3691
|
};
|
|
3515
3692
|
//#endregion
|
|
3516
|
-
export { ApiError, type ApiKey, type AssetResponse as Asset, type AssetDownloadResponse, type AssetInitResponse, type AssetListMeta, type AssetListPage, type
|
|
3693
|
+
export { ApiError, type ApiKey, type AssetResponse as Asset, type AssetDownloadResponse, type AssetInitResponse, type AssetListMeta, type AssetListPage, type BalanceDepletedData, type BalanceLowData, type BillingInvoice, type BillingState, type ClientConfig, type Cost, type CreateJobParams, type CreateUploadOptions, type CreateWebhookParams, type FfmpegParams, type FileType, type JobResponse as Job, type JobCancelledData, type JobCompletedData, type JobCreatedData, type JobCreatedResponse, type JobError, type JobFailedData, JobFailedError, type JobListPage, type JobStartedData, type JobStats, type JobStep, type JobSubscribeOptions, type JobSubscription, type JobTimings, type JobType, type ListAssetsParams, type ListDeliveriesParams, type ListJobsParams, type LogEntryData, type OrgCurrentResponse, type OrgEvent, type OrgSettings, type Organization, type Output, type OutputFile, type PaginationMeta, type PaymentMethod, type RealtimeConnectOptions, type RealtimeConnection, type RendobarClient, type RetryDeliveryResult, type StatsParams, type TestEventData, type Transaction, type TransactionListParams, type UpdateWebhookParams, type UploadProgress, type UsageParams, type UsageSummary, type WaitOptions, WaitTimeoutError, type WebhookDelivery, type WebhookEndpoint, type WebhookEventDataMap, type WebhookPayload, createClient, isApiError, jobData, outputUrl };
|
package/dist/index.d.mts
CHANGED
|
@@ -2243,6 +2243,11 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2243
2243
|
id: ZodString;
|
|
2244
2244
|
orgId: ZodString;
|
|
2245
2245
|
type: ZodString;
|
|
2246
|
+
source: ZodString;
|
|
2247
|
+
client: ZodNullable<ZodString>;
|
|
2248
|
+
retryCount: ZodNumber;
|
|
2249
|
+
idempotencyKey: ZodNullable<ZodString>;
|
|
2250
|
+
mediaType: ZodNullable<ZodString>;
|
|
2246
2251
|
inputs: ZodRecord<ZodString, ZodUnknown>;
|
|
2247
2252
|
params: ZodRecord<ZodString, ZodUnknown>;
|
|
2248
2253
|
cost: ZodNullable<ZodObject<{
|
|
@@ -2276,11 +2281,17 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2276
2281
|
startedAt: ZodNullable<ZodNumber>;
|
|
2277
2282
|
completedAt: ZodNullable<ZodNumber>;
|
|
2278
2283
|
settledAt: ZodNullable<ZodNumber>;
|
|
2284
|
+
retentionExpiresAt: ZodNullable<ZodNumber>;
|
|
2279
2285
|
status: ZodLiteral<"waiting">;
|
|
2280
2286
|
}, $strip>, ZodObject<{
|
|
2281
2287
|
id: ZodString;
|
|
2282
2288
|
orgId: ZodString;
|
|
2283
2289
|
type: ZodString;
|
|
2290
|
+
source: ZodString;
|
|
2291
|
+
client: ZodNullable<ZodString>;
|
|
2292
|
+
retryCount: ZodNumber;
|
|
2293
|
+
idempotencyKey: ZodNullable<ZodString>;
|
|
2294
|
+
mediaType: ZodNullable<ZodString>;
|
|
2284
2295
|
inputs: ZodRecord<ZodString, ZodUnknown>;
|
|
2285
2296
|
params: ZodRecord<ZodString, ZodUnknown>;
|
|
2286
2297
|
cost: ZodNullable<ZodObject<{
|
|
@@ -2314,6 +2325,7 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2314
2325
|
startedAt: ZodNullable<ZodNumber>;
|
|
2315
2326
|
completedAt: ZodNullable<ZodNumber>;
|
|
2316
2327
|
settledAt: ZodNullable<ZodNumber>;
|
|
2328
|
+
retentionExpiresAt: ZodNullable<ZodNumber>;
|
|
2317
2329
|
status: ZodLiteral<"dispatched">;
|
|
2318
2330
|
progress: ZodOptional<ZodNumber>;
|
|
2319
2331
|
eta: ZodOptional<ZodNullable<ZodNumber>>;
|
|
@@ -2321,6 +2333,11 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2321
2333
|
id: ZodString;
|
|
2322
2334
|
orgId: ZodString;
|
|
2323
2335
|
type: ZodString;
|
|
2336
|
+
source: ZodString;
|
|
2337
|
+
client: ZodNullable<ZodString>;
|
|
2338
|
+
retryCount: ZodNumber;
|
|
2339
|
+
idempotencyKey: ZodNullable<ZodString>;
|
|
2340
|
+
mediaType: ZodNullable<ZodString>;
|
|
2324
2341
|
inputs: ZodRecord<ZodString, ZodUnknown>;
|
|
2325
2342
|
params: ZodRecord<ZodString, ZodUnknown>;
|
|
2326
2343
|
cost: ZodNullable<ZodObject<{
|
|
@@ -2354,6 +2371,7 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2354
2371
|
startedAt: ZodNullable<ZodNumber>;
|
|
2355
2372
|
completedAt: ZodNullable<ZodNumber>;
|
|
2356
2373
|
settledAt: ZodNullable<ZodNumber>;
|
|
2374
|
+
retentionExpiresAt: ZodNullable<ZodNumber>;
|
|
2357
2375
|
status: ZodLiteral<"running">;
|
|
2358
2376
|
progress: ZodNumber;
|
|
2359
2377
|
eta: ZodNullable<ZodNumber>;
|
|
@@ -2361,6 +2379,11 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2361
2379
|
id: ZodString;
|
|
2362
2380
|
orgId: ZodString;
|
|
2363
2381
|
type: ZodString;
|
|
2382
|
+
source: ZodString;
|
|
2383
|
+
client: ZodNullable<ZodString>;
|
|
2384
|
+
retryCount: ZodNumber;
|
|
2385
|
+
idempotencyKey: ZodNullable<ZodString>;
|
|
2386
|
+
mediaType: ZodNullable<ZodString>;
|
|
2364
2387
|
inputs: ZodRecord<ZodString, ZodUnknown>;
|
|
2365
2388
|
params: ZodRecord<ZodString, ZodUnknown>;
|
|
2366
2389
|
cost: ZodNullable<ZodObject<{
|
|
@@ -2394,6 +2417,7 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2394
2417
|
startedAt: ZodNullable<ZodNumber>;
|
|
2395
2418
|
completedAt: ZodNullable<ZodNumber>;
|
|
2396
2419
|
settledAt: ZodNullable<ZodNumber>;
|
|
2420
|
+
retentionExpiresAt: ZodNullable<ZodNumber>;
|
|
2397
2421
|
status: ZodLiteral<"complete">;
|
|
2398
2422
|
output: ZodObject<{
|
|
2399
2423
|
data: ZodUnknown;
|
|
@@ -2443,6 +2467,11 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2443
2467
|
id: ZodString;
|
|
2444
2468
|
orgId: ZodString;
|
|
2445
2469
|
type: ZodString;
|
|
2470
|
+
source: ZodString;
|
|
2471
|
+
client: ZodNullable<ZodString>;
|
|
2472
|
+
retryCount: ZodNumber;
|
|
2473
|
+
idempotencyKey: ZodNullable<ZodString>;
|
|
2474
|
+
mediaType: ZodNullable<ZodString>;
|
|
2446
2475
|
inputs: ZodRecord<ZodString, ZodUnknown>;
|
|
2447
2476
|
params: ZodRecord<ZodString, ZodUnknown>;
|
|
2448
2477
|
cost: ZodNullable<ZodObject<{
|
|
@@ -2476,6 +2505,7 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2476
2505
|
startedAt: ZodNullable<ZodNumber>;
|
|
2477
2506
|
completedAt: ZodNullable<ZodNumber>;
|
|
2478
2507
|
settledAt: ZodNullable<ZodNumber>;
|
|
2508
|
+
retentionExpiresAt: ZodNullable<ZodNumber>;
|
|
2479
2509
|
status: ZodLiteral<"failed">;
|
|
2480
2510
|
error: ZodObject<{
|
|
2481
2511
|
code: ZodString;
|
|
@@ -2487,6 +2517,11 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2487
2517
|
id: ZodString;
|
|
2488
2518
|
orgId: ZodString;
|
|
2489
2519
|
type: ZodString;
|
|
2520
|
+
source: ZodString;
|
|
2521
|
+
client: ZodNullable<ZodString>;
|
|
2522
|
+
retryCount: ZodNumber;
|
|
2523
|
+
idempotencyKey: ZodNullable<ZodString>;
|
|
2524
|
+
mediaType: ZodNullable<ZodString>;
|
|
2490
2525
|
inputs: ZodRecord<ZodString, ZodUnknown>;
|
|
2491
2526
|
params: ZodRecord<ZodString, ZodUnknown>;
|
|
2492
2527
|
cost: ZodNullable<ZodObject<{
|
|
@@ -2520,24 +2555,46 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2520
2555
|
startedAt: ZodNullable<ZodNumber>;
|
|
2521
2556
|
completedAt: ZodNullable<ZodNumber>;
|
|
2522
2557
|
settledAt: ZodNullable<ZodNumber>;
|
|
2558
|
+
retentionExpiresAt: ZodNullable<ZodNumber>;
|
|
2523
2559
|
status: ZodLiteral<"cancelled">;
|
|
2524
2560
|
}, $strip>], "status">;
|
|
2525
2561
|
declare const jobCreatedResponseSchema: ZodObject<{
|
|
2526
2562
|
id: ZodString;
|
|
2527
2563
|
status: ZodLiteral<"waiting">;
|
|
2528
2564
|
}, $strip>;
|
|
2565
|
+
declare const jobStatsResponseSchema: ZodObject<{
|
|
2566
|
+
data: ZodObject<{
|
|
2567
|
+
window: ZodObject<{
|
|
2568
|
+
from: ZodNumber;
|
|
2569
|
+
to: ZodNumber;
|
|
2570
|
+
}, $strip>;
|
|
2571
|
+
totals: ZodObject<{
|
|
2572
|
+
jobs: ZodNumber;
|
|
2573
|
+
succeeded: ZodNumber;
|
|
2574
|
+
failed: ZodNumber;
|
|
2575
|
+
cancelled: ZodNumber;
|
|
2576
|
+
running: ZodNumber;
|
|
2577
|
+
}, $strip>;
|
|
2578
|
+
successRate: ZodNullable<ZodNumber>;
|
|
2579
|
+
avgDurationMs: ZodNullable<ZodNumber>;
|
|
2580
|
+
spend: ZodObject<{
|
|
2581
|
+
amount: ZodNumber;
|
|
2582
|
+
formatted: ZodString;
|
|
2583
|
+
}, $strip>;
|
|
2584
|
+
activity: ZodArray<ZodObject<{
|
|
2585
|
+
bucketStart: ZodNumber;
|
|
2586
|
+
succeeded: ZodNumber;
|
|
2587
|
+
failed: ZodNumber;
|
|
2588
|
+
other: ZodNumber;
|
|
2589
|
+
}, $strip>>;
|
|
2590
|
+
}, $strip>;
|
|
2591
|
+
}, $strip>;
|
|
2592
|
+
type JobStats = output<typeof jobStatsResponseSchema>["data"];
|
|
2529
2593
|
declare const jobTypeSchema: ZodObject<{
|
|
2530
2594
|
type: ZodString;
|
|
2531
2595
|
tag: ZodString;
|
|
2532
2596
|
summary: ZodString;
|
|
2533
|
-
needs: ZodArray<ZodString>;
|
|
2534
|
-
pattern: ZodNullable<ZodString>;
|
|
2535
|
-
runner: ZodOptional<ZodObject<{
|
|
2536
|
-
id: ZodString;
|
|
2537
|
-
resource: ZodString;
|
|
2538
|
-
}, $strip>>;
|
|
2539
2597
|
acceptsMedia: ZodArray<ZodString>;
|
|
2540
|
-
mediaOverrides: ZodOptional<ZodRecord<ZodString, ZodUnknown>>;
|
|
2541
2598
|
}, $strip>;
|
|
2542
2599
|
declare const billingStateSchema: ZodObject<{
|
|
2543
2600
|
balance: ZodObject<{
|
|
@@ -2552,7 +2609,6 @@ declare const billingStateSchema: ZodObject<{
|
|
|
2552
2609
|
apiRequestsPerMinute: ZodNumber;
|
|
2553
2610
|
maxJobTimeout: ZodNumber;
|
|
2554
2611
|
maxInputFileSize: ZodNumber;
|
|
2555
|
-
maxBatchSize: ZodNumber;
|
|
2556
2612
|
}, $strip>;
|
|
2557
2613
|
}, $strip>;
|
|
2558
2614
|
subscription: ZodNullable<ZodObject<{
|
|
@@ -2576,7 +2632,6 @@ declare const billingStateSchema: ZodObject<{
|
|
|
2576
2632
|
apiRequestsPerMinute: ZodNumber;
|
|
2577
2633
|
maxJobTimeout: ZodNumber;
|
|
2578
2634
|
maxInputFileSize: ZodNumber;
|
|
2579
|
-
maxBatchSize: ZodNumber;
|
|
2580
2635
|
}, $strip>;
|
|
2581
2636
|
}, $strip>>;
|
|
2582
2637
|
}, $strip>;
|
|
@@ -2634,11 +2689,15 @@ declare const webhookDeliverySchema: ZodObject<{
|
|
|
2634
2689
|
id: ZodString;
|
|
2635
2690
|
endpointId: ZodString;
|
|
2636
2691
|
endpointName: ZodNullable<ZodString>;
|
|
2637
|
-
jobId: ZodString
|
|
2638
|
-
batchId: ZodNullable<ZodString>;
|
|
2692
|
+
jobId: ZodNullable<ZodString>;
|
|
2639
2693
|
event: ZodString;
|
|
2640
2694
|
payload: ZodString;
|
|
2641
|
-
status:
|
|
2695
|
+
status: ZodEnum<{
|
|
2696
|
+
failed: "failed";
|
|
2697
|
+
cancelled: "cancelled";
|
|
2698
|
+
pending: "pending";
|
|
2699
|
+
delivered: "delivered";
|
|
2700
|
+
}>;
|
|
2642
2701
|
statusCode: ZodNullable<ZodNumber>;
|
|
2643
2702
|
responseBody: ZodNullable<ZodString>;
|
|
2644
2703
|
attempts: ZodNumber;
|
|
@@ -2961,6 +3020,130 @@ interface LogEntryData {
|
|
|
2961
3020
|
meta?: Record<string, unknown>;
|
|
2962
3021
|
}
|
|
2963
3022
|
//#endregion
|
|
3023
|
+
//#region ../shared/src/constants/webhook-events.d.ts
|
|
3024
|
+
declare const WEBHOOK_EVENT_TYPES: readonly ["job.created", "job.started", "job.completed", "job.failed", "job.cancelled", "balance.low", "balance.depleted"];
|
|
3025
|
+
type WebhookEventType = (typeof WEBHOOK_EVENT_TYPES)[number];
|
|
3026
|
+
//#endregion
|
|
3027
|
+
//#region ../shared/src/types/webhook.d.ts
|
|
3028
|
+
interface JobCreatedData {
|
|
3029
|
+
jobId: string;
|
|
3030
|
+
jobType: string;
|
|
3031
|
+
status: "waiting";
|
|
3032
|
+
timing: {
|
|
3033
|
+
createdAt: number;
|
|
3034
|
+
};
|
|
3035
|
+
}
|
|
3036
|
+
interface JobStartedData {
|
|
3037
|
+
jobId: string;
|
|
3038
|
+
jobType: string;
|
|
3039
|
+
status: "running";
|
|
3040
|
+
timing: {
|
|
3041
|
+
createdAt: number;
|
|
3042
|
+
dispatchedAt?: number;
|
|
3043
|
+
startedAt: number;
|
|
3044
|
+
};
|
|
3045
|
+
}
|
|
3046
|
+
interface JobCompletedData {
|
|
3047
|
+
jobId: string;
|
|
3048
|
+
jobType: string;
|
|
3049
|
+
status: "complete";
|
|
3050
|
+
output: Output;
|
|
3051
|
+
cost?: {
|
|
3052
|
+
amount: number;
|
|
3053
|
+
currency: "USD";
|
|
3054
|
+
formatted: string;
|
|
3055
|
+
breakdown: string;
|
|
3056
|
+
};
|
|
3057
|
+
timing: {
|
|
3058
|
+
createdAt: number;
|
|
3059
|
+
dispatchedAt?: number;
|
|
3060
|
+
startedAt?: number;
|
|
3061
|
+
completedAt: number;
|
|
3062
|
+
};
|
|
3063
|
+
steps?: Array<{
|
|
3064
|
+
id: string;
|
|
3065
|
+
name: string;
|
|
3066
|
+
status: string;
|
|
3067
|
+
durationMs?: number;
|
|
3068
|
+
error?: string;
|
|
3069
|
+
}>;
|
|
3070
|
+
outputCategory?: string;
|
|
3071
|
+
mediaType?: string;
|
|
3072
|
+
}
|
|
3073
|
+
interface JobFailedData {
|
|
3074
|
+
jobId: string;
|
|
3075
|
+
jobType: string;
|
|
3076
|
+
status: "failed";
|
|
3077
|
+
error: JobError;
|
|
3078
|
+
timing: {
|
|
3079
|
+
createdAt: number;
|
|
3080
|
+
dispatchedAt?: number;
|
|
3081
|
+
startedAt?: number;
|
|
3082
|
+
failedAt: number;
|
|
3083
|
+
};
|
|
3084
|
+
steps?: Array<{
|
|
3085
|
+
id: string;
|
|
3086
|
+
name: string;
|
|
3087
|
+
status: string;
|
|
3088
|
+
durationMs?: number;
|
|
3089
|
+
error?: string;
|
|
3090
|
+
}>;
|
|
3091
|
+
}
|
|
3092
|
+
interface JobCancelledData {
|
|
3093
|
+
jobId: string;
|
|
3094
|
+
jobType: string;
|
|
3095
|
+
status: "cancelled";
|
|
3096
|
+
timing: {
|
|
3097
|
+
createdAt: number;
|
|
3098
|
+
cancelledAt: number;
|
|
3099
|
+
};
|
|
3100
|
+
}
|
|
3101
|
+
interface BalanceLowData {
|
|
3102
|
+
balance: number;
|
|
3103
|
+
balanceFormatted: string;
|
|
3104
|
+
threshold: number;
|
|
3105
|
+
thresholdFormatted: string;
|
|
3106
|
+
triggeredByJobId: string;
|
|
3107
|
+
triggeredByJobType: string;
|
|
3108
|
+
}
|
|
3109
|
+
interface BalanceDepletedData {
|
|
3110
|
+
balance: number;
|
|
3111
|
+
balanceFormatted: string;
|
|
3112
|
+
triggeredByJobId: string;
|
|
3113
|
+
triggeredByJobType: string;
|
|
3114
|
+
}
|
|
3115
|
+
interface TestEventData {
|
|
3116
|
+
message: string;
|
|
3117
|
+
endpointId: string;
|
|
3118
|
+
}
|
|
3119
|
+
/**
|
|
3120
|
+
* Maps each event to its `data` shape. The `WebhookPayload` mapped type below
|
|
3121
|
+
* fails to compile if WEBHOOK_EVENT_TYPES gains an event that is missing here,
|
|
3122
|
+
* so this map is the enforced single source of truth for payload shapes.
|
|
3123
|
+
*/
|
|
3124
|
+
interface WebhookEventDataMap {
|
|
3125
|
+
"job.created": JobCreatedData;
|
|
3126
|
+
"job.started": JobStartedData;
|
|
3127
|
+
"job.completed": JobCompletedData;
|
|
3128
|
+
"job.failed": JobFailedData;
|
|
3129
|
+
"job.cancelled": JobCancelledData;
|
|
3130
|
+
"balance.low": BalanceLowData;
|
|
3131
|
+
"balance.depleted": BalanceDepletedData;
|
|
3132
|
+
}
|
|
3133
|
+
interface Envelope<E extends string, D> {
|
|
3134
|
+
version: "1";
|
|
3135
|
+
event: E;
|
|
3136
|
+
deliveryId: string;
|
|
3137
|
+
timestamp: number;
|
|
3138
|
+
orgId: string;
|
|
3139
|
+
data: D;
|
|
3140
|
+
}
|
|
3141
|
+
/**
|
|
3142
|
+
* The exact JSON body Rendobar POSTs to your endpoint, discriminated by `event`.
|
|
3143
|
+
* Switch on `payload.event` and `payload.data` narrows to the matching shape.
|
|
3144
|
+
*/
|
|
3145
|
+
type WebhookPayload = { [E in WebhookEventType]: Envelope<E, WebhookEventDataMap[E]> }[WebhookEventType] | Envelope<"test", TestEventData>;
|
|
3146
|
+
//#endregion
|
|
2964
3147
|
//#region src/types.d.ts
|
|
2965
3148
|
/**
|
|
2966
3149
|
* Primary playable/download URL for a completed job, or `undefined`.
|
|
@@ -3065,6 +3248,9 @@ declare function createClient(config?: ClientConfig): {
|
|
|
3065
3248
|
types(options?: {
|
|
3066
3249
|
signal?: AbortSignal;
|
|
3067
3250
|
}): Promise<JobType[]>;
|
|
3251
|
+
stats(params?: StatsParams, options?: {
|
|
3252
|
+
signal?: AbortSignal;
|
|
3253
|
+
}): Promise<JobStats>;
|
|
3068
3254
|
};
|
|
3069
3255
|
billing: {
|
|
3070
3256
|
state(options?: {
|
|
@@ -3142,7 +3328,7 @@ declare function createClient(config?: ClientConfig): {
|
|
|
3142
3328
|
signal?: AbortSignal;
|
|
3143
3329
|
}): Promise<WebhookEndpoint>;
|
|
3144
3330
|
update(id: string, params: UpdateWebhookParams, options?: {
|
|
3145
|
-
signal
|
|
3331
|
+
signal?: AbortSignal;
|
|
3146
3332
|
}): Promise<WebhookEndpoint>;
|
|
3147
3333
|
delete(id: string, options?: {
|
|
3148
3334
|
signal?: AbortSignal;
|
|
@@ -3165,7 +3351,7 @@ declare function createClient(config?: ClientConfig): {
|
|
|
3165
3351
|
}>;
|
|
3166
3352
|
retryDelivery(id: string, options?: {
|
|
3167
3353
|
signal?: AbortSignal;
|
|
3168
|
-
}): Promise<
|
|
3354
|
+
}): Promise<RetryDeliveryResult>;
|
|
3169
3355
|
};
|
|
3170
3356
|
apiKeys: {
|
|
3171
3357
|
create(params: {
|
|
@@ -3215,28 +3401,12 @@ declare function createClient(config?: ClientConfig): {
|
|
|
3215
3401
|
signal?: AbortSignal;
|
|
3216
3402
|
}): Promise<void>;
|
|
3217
3403
|
getSettings(options?: {
|
|
3218
|
-
signal
|
|
3404
|
+
signal? /** Custom fetch function for testing or special runtimes. */: AbortSignal;
|
|
3219
3405
|
}): Promise<OrgSettings>;
|
|
3220
3406
|
updateSettings(body: Partial<Pick<OrgSettings, "billingEmailsEnabled" | "defaultRegion" | "regionPinned">>, options?: {
|
|
3221
3407
|
signal?: AbortSignal;
|
|
3222
3408
|
}): Promise<OrgSettings>;
|
|
3223
3409
|
};
|
|
3224
|
-
batches: {
|
|
3225
|
-
create(params: {
|
|
3226
|
-
jobs: CreateJobParams[];
|
|
3227
|
-
}, options?: {
|
|
3228
|
-
signal?: AbortSignal;
|
|
3229
|
-
}): Promise<BatchResult>;
|
|
3230
|
-
get(id: string, options?: {
|
|
3231
|
-
signal?: AbortSignal;
|
|
3232
|
-
}): Promise<{
|
|
3233
|
-
id: string;
|
|
3234
|
-
orgId: string;
|
|
3235
|
-
jobCount: number;
|
|
3236
|
-
completedCount: number;
|
|
3237
|
-
createdAt: number;
|
|
3238
|
-
}>;
|
|
3239
|
-
};
|
|
3240
3410
|
assets: {
|
|
3241
3411
|
list(params?: ListAssetsParams, options?: {
|
|
3242
3412
|
signal?: AbortSignal;
|
|
@@ -3401,7 +3571,15 @@ type ListJobsParams = {
|
|
|
3401
3571
|
status?: string;
|
|
3402
3572
|
type?: string;
|
|
3403
3573
|
limit?: number;
|
|
3404
|
-
offset?: number;
|
|
3574
|
+
offset?: number; /** Sort field. Default: created. */
|
|
3575
|
+
sort?: "created" | "duration" | "cost"; /** Sort direction. Default: desc. */
|
|
3576
|
+
order?: "asc" | "desc"; /** Filter by originating client (sdk | cli | mcp | dashboard | ...). */
|
|
3577
|
+
client?: string; /** Filter jobs created at or after this Unix ms timestamp. */
|
|
3578
|
+
from?: number; /** Filter jobs created at or before this Unix ms timestamp. */
|
|
3579
|
+
to?: number;
|
|
3580
|
+
};
|
|
3581
|
+
type StatsParams = {
|
|
3582
|
+
/** Time window for the aggregate. Default: 24h. */window?: "24h" | "7d" | "30d";
|
|
3405
3583
|
};
|
|
3406
3584
|
type WaitOptions = {
|
|
3407
3585
|
/** Max wait time in ms. Default: 300_000 (5 minutes). */timeout?: number; /** Initial poll interval in ms. Default: 2_000. Grows with exponential backoff. */
|
|
@@ -3434,22 +3612,29 @@ type TransactionListParams = {
|
|
|
3434
3612
|
type CreateWebhookParams = {
|
|
3435
3613
|
name: string;
|
|
3436
3614
|
url: string;
|
|
3437
|
-
subscribedEvents:
|
|
3615
|
+
subscribedEvents: WebhookEventType[];
|
|
3438
3616
|
};
|
|
3439
3617
|
type UpdateWebhookParams = {
|
|
3440
3618
|
name?: string;
|
|
3441
3619
|
url?: string;
|
|
3442
|
-
subscribedEvents?:
|
|
3620
|
+
subscribedEvents?: WebhookEventType[];
|
|
3443
3621
|
active?: boolean;
|
|
3444
3622
|
};
|
|
3445
3623
|
type ListDeliveriesParams = {
|
|
3446
3624
|
endpointId?: string;
|
|
3447
|
-
event?:
|
|
3625
|
+
event?: WebhookEventType;
|
|
3448
3626
|
status?: string;
|
|
3449
3627
|
jobId?: string;
|
|
3450
3628
|
limit?: number;
|
|
3451
3629
|
offset?: number;
|
|
3452
3630
|
};
|
|
3631
|
+
/** The retry route echoes only these fields — not a full delivery record. */
|
|
3632
|
+
type RetryDeliveryResult = {
|
|
3633
|
+
id: string;
|
|
3634
|
+
status: string;
|
|
3635
|
+
event: string;
|
|
3636
|
+
endpointId: string;
|
|
3637
|
+
};
|
|
3453
3638
|
//#endregion
|
|
3454
3639
|
//#region src/resources/orgs.d.ts
|
|
3455
3640
|
type OrgCurrentResponse = {
|
|
@@ -3476,14 +3661,6 @@ type OrgCurrentResponse = {
|
|
|
3476
3661
|
};
|
|
3477
3662
|
};
|
|
3478
3663
|
//#endregion
|
|
3479
|
-
//#region src/resources/batches.d.ts
|
|
3480
|
-
type BatchResult = {
|
|
3481
|
-
batchId: string;
|
|
3482
|
-
jobCount: number;
|
|
3483
|
-
jobIds: string[];
|
|
3484
|
-
status: string;
|
|
3485
|
-
};
|
|
3486
|
-
//#endregion
|
|
3487
3664
|
//#region src/resources/uploads.d.ts
|
|
3488
3665
|
type UploadProgress = {
|
|
3489
3666
|
loaded: number;
|
|
@@ -3513,4 +3690,4 @@ type AssetListPage = {
|
|
|
3513
3690
|
meta: AssetListMeta;
|
|
3514
3691
|
};
|
|
3515
3692
|
//#endregion
|
|
3516
|
-
export { ApiError, type ApiKey, type AssetResponse as Asset, type AssetDownloadResponse, type AssetInitResponse, type AssetListMeta, type AssetListPage, type
|
|
3693
|
+
export { ApiError, type ApiKey, type AssetResponse as Asset, type AssetDownloadResponse, type AssetInitResponse, type AssetListMeta, type AssetListPage, type BalanceDepletedData, type BalanceLowData, type BillingInvoice, type BillingState, type ClientConfig, type Cost, type CreateJobParams, type CreateUploadOptions, type CreateWebhookParams, type FfmpegParams, type FileType, type JobResponse as Job, type JobCancelledData, type JobCompletedData, type JobCreatedData, type JobCreatedResponse, type JobError, type JobFailedData, JobFailedError, type JobListPage, type JobStartedData, type JobStats, type JobStep, type JobSubscribeOptions, type JobSubscription, type JobTimings, type JobType, type ListAssetsParams, type ListDeliveriesParams, type ListJobsParams, type LogEntryData, type OrgCurrentResponse, type OrgEvent, type OrgSettings, type Organization, type Output, type OutputFile, type PaginationMeta, type PaymentMethod, type RealtimeConnectOptions, type RealtimeConnection, type RendobarClient, type RetryDeliveryResult, type StatsParams, type TestEventData, type Transaction, type TransactionListParams, type UpdateWebhookParams, type UploadProgress, type UsageParams, type UsageSummary, type WaitOptions, WaitTimeoutError, type WebhookDelivery, type WebhookEndpoint, type WebhookEventDataMap, type WebhookPayload, createClient, isApiError, jobData, outputUrl };
|
package/dist/index.mjs
CHANGED
|
@@ -248,6 +248,12 @@ function createJobsResource(request) {
|
|
|
248
248
|
},
|
|
249
249
|
async types(options) {
|
|
250
250
|
return request("/jobs/types", { signal: options?.signal });
|
|
251
|
+
},
|
|
252
|
+
async stats(params, options) {
|
|
253
|
+
return request("/jobs/stats", {
|
|
254
|
+
query: params,
|
|
255
|
+
signal: options?.signal
|
|
256
|
+
});
|
|
251
257
|
}
|
|
252
258
|
};
|
|
253
259
|
}
|
|
@@ -639,22 +645,6 @@ function createOrgsResource(request) {
|
|
|
639
645
|
};
|
|
640
646
|
}
|
|
641
647
|
//#endregion
|
|
642
|
-
//#region src/resources/batches.ts
|
|
643
|
-
function createBatchesResource(request) {
|
|
644
|
-
return {
|
|
645
|
-
async create(params, options) {
|
|
646
|
-
return request("/batches", {
|
|
647
|
-
method: "POST",
|
|
648
|
-
body: params,
|
|
649
|
-
signal: options?.signal
|
|
650
|
-
});
|
|
651
|
-
},
|
|
652
|
-
async get(id, options) {
|
|
653
|
-
return request(`/batches/${id}`, { signal: options?.signal });
|
|
654
|
-
}
|
|
655
|
-
};
|
|
656
|
-
}
|
|
657
|
-
//#endregion
|
|
658
648
|
//#region src/resources/assets.ts
|
|
659
649
|
function createAssetsResource(request) {
|
|
660
650
|
return {
|
|
@@ -872,7 +862,6 @@ function createClient(config = {}) {
|
|
|
872
862
|
webhooks: createWebhooksResource(request),
|
|
873
863
|
apiKeys: createApiKeysResource(request),
|
|
874
864
|
orgs: createOrgsResource(request),
|
|
875
|
-
batches: createBatchesResource(request),
|
|
876
865
|
assets: createAssetsResource(request),
|
|
877
866
|
team: createTeamResource(request),
|
|
878
867
|
realtime: createRealtimeClient(baseUrl, {
|
package/dist/webhooks.cjs
CHANGED
|
@@ -1,12 +1,67 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
//#region src/lib/webhook-verify.ts
|
|
3
3
|
/**
|
|
4
|
-
* Verify
|
|
5
|
-
*
|
|
4
|
+
* Verify Rendobar webhook signatures. Zero runtime deps — works in any runtime
|
|
5
|
+
* with the Web Crypto API (Node 18+, Deno, CF Workers, browser).
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* Prefer `verifyWebhook(body, headers, secret)` — it reads the signature +
|
|
8
|
+
* timestamp headers, rebuilds the signed string, checks freshness (replay
|
|
9
|
+
* protection), and handles the secret-rotation window for you:
|
|
10
|
+
*
|
|
11
|
+
* import { verifyWebhook } from "@rendobar/sdk/webhooks";
|
|
12
|
+
* const ok = await verifyWebhook(rawBody, req.headers, process.env.WEBHOOK_SECRET);
|
|
13
|
+
* if (!ok) return res.status(401).send("Invalid signature");
|
|
14
|
+
*
|
|
15
|
+
* `verifyWebhookSignature` is the low-level HMAC primitive. It signs exactly the
|
|
16
|
+
* string you pass, so you must build `${timestamp}.${body}` yourself — the raw
|
|
17
|
+
* body alone will NOT match, because Rendobar signs the timestamped form.
|
|
18
|
+
*/
|
|
19
|
+
const SIG_HEADER = "x-rendobar-signature";
|
|
20
|
+
const SIG_PREVIOUS_HEADER = "x-rendobar-signature-previous";
|
|
21
|
+
const TIMESTAMP_HEADER = "x-rendobar-timestamp";
|
|
22
|
+
const DEFAULT_TOLERANCE_SEC = 300;
|
|
23
|
+
function getHeader(headers, name) {
|
|
24
|
+
if (headers instanceof Headers) return headers.get(name) ?? void 0;
|
|
25
|
+
const lower = name.toLowerCase();
|
|
26
|
+
for (const key of Object.keys(headers)) if (key.toLowerCase() === lower) {
|
|
27
|
+
const v = headers[key];
|
|
28
|
+
return Array.isArray(v) ? v[0] : v ?? void 0;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Verify a webhook request end to end: signature + timestamp freshness + secret
|
|
33
|
+
* rotation. Returns `true` only if the body is authentic and recent.
|
|
34
|
+
*
|
|
35
|
+
* @param body Raw request body string (NOT parsed JSON — bytes as received).
|
|
36
|
+
* @param headers The incoming request headers (Web `Headers` or a plain record).
|
|
37
|
+
* @param secret Your endpoint's signing secret (`whsec_...`).
|
|
38
|
+
* @param opts.toleranceSec Max clock skew in seconds (default 300). Pass
|
|
39
|
+
* `Infinity` to disable the replay/freshness check.
|
|
40
|
+
*/
|
|
41
|
+
async function verifyWebhook(body, headers, secret, opts = {}) {
|
|
42
|
+
const toleranceSec = opts.toleranceSec ?? DEFAULT_TOLERANCE_SEC;
|
|
43
|
+
const signature = getHeader(headers, SIG_HEADER);
|
|
44
|
+
const timestamp = getHeader(headers, TIMESTAMP_HEADER);
|
|
45
|
+
if (!signature || !timestamp) return false;
|
|
46
|
+
const tsSec = Number(timestamp);
|
|
47
|
+
if (!Number.isFinite(tsSec)) return false;
|
|
48
|
+
if (Number.isFinite(toleranceSec)) {
|
|
49
|
+
const nowSec = Math.floor(Date.now() / 1e3);
|
|
50
|
+
if (Math.abs(nowSec - tsSec) > toleranceSec) return false;
|
|
51
|
+
}
|
|
52
|
+
const signed = `${timestamp}.${body}`;
|
|
53
|
+
if (await verifyWebhookSignature(signed, signature, secret)) return true;
|
|
54
|
+
const previous = getHeader(headers, SIG_PREVIOUS_HEADER);
|
|
55
|
+
if (previous && await verifyWebhookSignature(signed, previous, secret)) return true;
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Low-level HMAC-SHA256 check. Signs `payload` verbatim and compares (constant
|
|
60
|
+
* time) against `signature` (`sha256=<hex>` or bare hex).
|
|
61
|
+
*
|
|
62
|
+
* NOTE: Rendobar signs `${timestamp}.${body}`, so pass that exact string as
|
|
63
|
+
* `payload` — the raw body alone will not match. Most callers should use
|
|
64
|
+
* `verifyWebhook` instead, which builds the string and checks freshness.
|
|
10
65
|
*/
|
|
11
66
|
async function verifyWebhookSignature(payload, signature, secret) {
|
|
12
67
|
const expected = signature.startsWith("sha256=") ? signature.slice(7) : signature;
|
|
@@ -22,4 +77,5 @@ async function verifyWebhookSignature(payload, signature, secret) {
|
|
|
22
77
|
return mismatch === 0;
|
|
23
78
|
}
|
|
24
79
|
//#endregion
|
|
80
|
+
exports.verifyWebhook = verifyWebhook;
|
|
25
81
|
exports.verifyWebhookSignature = verifyWebhookSignature;
|
package/dist/webhooks.d.cts
CHANGED
|
@@ -1,12 +1,43 @@
|
|
|
1
1
|
//#region src/lib/webhook-verify.d.ts
|
|
2
2
|
/**
|
|
3
|
-
* Verify
|
|
4
|
-
*
|
|
3
|
+
* Verify Rendobar webhook signatures. Zero runtime deps — works in any runtime
|
|
4
|
+
* with the Web Crypto API (Node 18+, Deno, CF Workers, browser).
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* Prefer `verifyWebhook(body, headers, secret)` — it reads the signature +
|
|
7
|
+
* timestamp headers, rebuilds the signed string, checks freshness (replay
|
|
8
|
+
* protection), and handles the secret-rotation window for you:
|
|
9
|
+
*
|
|
10
|
+
* import { verifyWebhook } from "@rendobar/sdk/webhooks";
|
|
11
|
+
* const ok = await verifyWebhook(rawBody, req.headers, process.env.WEBHOOK_SECRET);
|
|
12
|
+
* if (!ok) return res.status(401).send("Invalid signature");
|
|
13
|
+
*
|
|
14
|
+
* `verifyWebhookSignature` is the low-level HMAC primitive. It signs exactly the
|
|
15
|
+
* string you pass, so you must build `${timestamp}.${body}` yourself — the raw
|
|
16
|
+
* body alone will NOT match, because Rendobar signs the timestamped form.
|
|
17
|
+
*/
|
|
18
|
+
/** Accepts a Web `Headers` object or a plain header record (e.g. Node `req.headers`). */
|
|
19
|
+
type WebhookHeaders = Headers | Record<string, string | string[] | undefined>;
|
|
20
|
+
/**
|
|
21
|
+
* Verify a webhook request end to end: signature + timestamp freshness + secret
|
|
22
|
+
* rotation. Returns `true` only if the body is authentic and recent.
|
|
23
|
+
*
|
|
24
|
+
* @param body Raw request body string (NOT parsed JSON — bytes as received).
|
|
25
|
+
* @param headers The incoming request headers (Web `Headers` or a plain record).
|
|
26
|
+
* @param secret Your endpoint's signing secret (`whsec_...`).
|
|
27
|
+
* @param opts.toleranceSec Max clock skew in seconds (default 300). Pass
|
|
28
|
+
* `Infinity` to disable the replay/freshness check.
|
|
29
|
+
*/
|
|
30
|
+
declare function verifyWebhook(body: string, headers: WebhookHeaders, secret: string, opts?: {
|
|
31
|
+
toleranceSec?: number;
|
|
32
|
+
}): Promise<boolean>;
|
|
33
|
+
/**
|
|
34
|
+
* Low-level HMAC-SHA256 check. Signs `payload` verbatim and compares (constant
|
|
35
|
+
* time) against `signature` (`sha256=<hex>` or bare hex).
|
|
36
|
+
*
|
|
37
|
+
* NOTE: Rendobar signs `${timestamp}.${body}`, so pass that exact string as
|
|
38
|
+
* `payload` — the raw body alone will not match. Most callers should use
|
|
39
|
+
* `verifyWebhook` instead, which builds the string and checks freshness.
|
|
9
40
|
*/
|
|
10
41
|
declare function verifyWebhookSignature(payload: string, signature: string, secret: string): Promise<boolean>;
|
|
11
42
|
//#endregion
|
|
12
|
-
export { verifyWebhookSignature };
|
|
43
|
+
export { type WebhookHeaders, verifyWebhook, verifyWebhookSignature };
|
package/dist/webhooks.d.mts
CHANGED
|
@@ -1,12 +1,43 @@
|
|
|
1
1
|
//#region src/lib/webhook-verify.d.ts
|
|
2
2
|
/**
|
|
3
|
-
* Verify
|
|
4
|
-
*
|
|
3
|
+
* Verify Rendobar webhook signatures. Zero runtime deps — works in any runtime
|
|
4
|
+
* with the Web Crypto API (Node 18+, Deno, CF Workers, browser).
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* Prefer `verifyWebhook(body, headers, secret)` — it reads the signature +
|
|
7
|
+
* timestamp headers, rebuilds the signed string, checks freshness (replay
|
|
8
|
+
* protection), and handles the secret-rotation window for you:
|
|
9
|
+
*
|
|
10
|
+
* import { verifyWebhook } from "@rendobar/sdk/webhooks";
|
|
11
|
+
* const ok = await verifyWebhook(rawBody, req.headers, process.env.WEBHOOK_SECRET);
|
|
12
|
+
* if (!ok) return res.status(401).send("Invalid signature");
|
|
13
|
+
*
|
|
14
|
+
* `verifyWebhookSignature` is the low-level HMAC primitive. It signs exactly the
|
|
15
|
+
* string you pass, so you must build `${timestamp}.${body}` yourself — the raw
|
|
16
|
+
* body alone will NOT match, because Rendobar signs the timestamped form.
|
|
17
|
+
*/
|
|
18
|
+
/** Accepts a Web `Headers` object or a plain header record (e.g. Node `req.headers`). */
|
|
19
|
+
type WebhookHeaders = Headers | Record<string, string | string[] | undefined>;
|
|
20
|
+
/**
|
|
21
|
+
* Verify a webhook request end to end: signature + timestamp freshness + secret
|
|
22
|
+
* rotation. Returns `true` only if the body is authentic and recent.
|
|
23
|
+
*
|
|
24
|
+
* @param body Raw request body string (NOT parsed JSON — bytes as received).
|
|
25
|
+
* @param headers The incoming request headers (Web `Headers` or a plain record).
|
|
26
|
+
* @param secret Your endpoint's signing secret (`whsec_...`).
|
|
27
|
+
* @param opts.toleranceSec Max clock skew in seconds (default 300). Pass
|
|
28
|
+
* `Infinity` to disable the replay/freshness check.
|
|
29
|
+
*/
|
|
30
|
+
declare function verifyWebhook(body: string, headers: WebhookHeaders, secret: string, opts?: {
|
|
31
|
+
toleranceSec?: number;
|
|
32
|
+
}): Promise<boolean>;
|
|
33
|
+
/**
|
|
34
|
+
* Low-level HMAC-SHA256 check. Signs `payload` verbatim and compares (constant
|
|
35
|
+
* time) against `signature` (`sha256=<hex>` or bare hex).
|
|
36
|
+
*
|
|
37
|
+
* NOTE: Rendobar signs `${timestamp}.${body}`, so pass that exact string as
|
|
38
|
+
* `payload` — the raw body alone will not match. Most callers should use
|
|
39
|
+
* `verifyWebhook` instead, which builds the string and checks freshness.
|
|
9
40
|
*/
|
|
10
41
|
declare function verifyWebhookSignature(payload: string, signature: string, secret: string): Promise<boolean>;
|
|
11
42
|
//#endregion
|
|
12
|
-
export { verifyWebhookSignature };
|
|
43
|
+
export { type WebhookHeaders, verifyWebhook, verifyWebhookSignature };
|
package/dist/webhooks.mjs
CHANGED
|
@@ -1,11 +1,66 @@
|
|
|
1
1
|
//#region src/lib/webhook-verify.ts
|
|
2
2
|
/**
|
|
3
|
-
* Verify
|
|
4
|
-
*
|
|
3
|
+
* Verify Rendobar webhook signatures. Zero runtime deps — works in any runtime
|
|
4
|
+
* with the Web Crypto API (Node 18+, Deno, CF Workers, browser).
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* Prefer `verifyWebhook(body, headers, secret)` — it reads the signature +
|
|
7
|
+
* timestamp headers, rebuilds the signed string, checks freshness (replay
|
|
8
|
+
* protection), and handles the secret-rotation window for you:
|
|
9
|
+
*
|
|
10
|
+
* import { verifyWebhook } from "@rendobar/sdk/webhooks";
|
|
11
|
+
* const ok = await verifyWebhook(rawBody, req.headers, process.env.WEBHOOK_SECRET);
|
|
12
|
+
* if (!ok) return res.status(401).send("Invalid signature");
|
|
13
|
+
*
|
|
14
|
+
* `verifyWebhookSignature` is the low-level HMAC primitive. It signs exactly the
|
|
15
|
+
* string you pass, so you must build `${timestamp}.${body}` yourself — the raw
|
|
16
|
+
* body alone will NOT match, because Rendobar signs the timestamped form.
|
|
17
|
+
*/
|
|
18
|
+
const SIG_HEADER = "x-rendobar-signature";
|
|
19
|
+
const SIG_PREVIOUS_HEADER = "x-rendobar-signature-previous";
|
|
20
|
+
const TIMESTAMP_HEADER = "x-rendobar-timestamp";
|
|
21
|
+
const DEFAULT_TOLERANCE_SEC = 300;
|
|
22
|
+
function getHeader(headers, name) {
|
|
23
|
+
if (headers instanceof Headers) return headers.get(name) ?? void 0;
|
|
24
|
+
const lower = name.toLowerCase();
|
|
25
|
+
for (const key of Object.keys(headers)) if (key.toLowerCase() === lower) {
|
|
26
|
+
const v = headers[key];
|
|
27
|
+
return Array.isArray(v) ? v[0] : v ?? void 0;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Verify a webhook request end to end: signature + timestamp freshness + secret
|
|
32
|
+
* rotation. Returns `true` only if the body is authentic and recent.
|
|
33
|
+
*
|
|
34
|
+
* @param body Raw request body string (NOT parsed JSON — bytes as received).
|
|
35
|
+
* @param headers The incoming request headers (Web `Headers` or a plain record).
|
|
36
|
+
* @param secret Your endpoint's signing secret (`whsec_...`).
|
|
37
|
+
* @param opts.toleranceSec Max clock skew in seconds (default 300). Pass
|
|
38
|
+
* `Infinity` to disable the replay/freshness check.
|
|
39
|
+
*/
|
|
40
|
+
async function verifyWebhook(body, headers, secret, opts = {}) {
|
|
41
|
+
const toleranceSec = opts.toleranceSec ?? DEFAULT_TOLERANCE_SEC;
|
|
42
|
+
const signature = getHeader(headers, SIG_HEADER);
|
|
43
|
+
const timestamp = getHeader(headers, TIMESTAMP_HEADER);
|
|
44
|
+
if (!signature || !timestamp) return false;
|
|
45
|
+
const tsSec = Number(timestamp);
|
|
46
|
+
if (!Number.isFinite(tsSec)) return false;
|
|
47
|
+
if (Number.isFinite(toleranceSec)) {
|
|
48
|
+
const nowSec = Math.floor(Date.now() / 1e3);
|
|
49
|
+
if (Math.abs(nowSec - tsSec) > toleranceSec) return false;
|
|
50
|
+
}
|
|
51
|
+
const signed = `${timestamp}.${body}`;
|
|
52
|
+
if (await verifyWebhookSignature(signed, signature, secret)) return true;
|
|
53
|
+
const previous = getHeader(headers, SIG_PREVIOUS_HEADER);
|
|
54
|
+
if (previous && await verifyWebhookSignature(signed, previous, secret)) return true;
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Low-level HMAC-SHA256 check. Signs `payload` verbatim and compares (constant
|
|
59
|
+
* time) against `signature` (`sha256=<hex>` or bare hex).
|
|
60
|
+
*
|
|
61
|
+
* NOTE: Rendobar signs `${timestamp}.${body}`, so pass that exact string as
|
|
62
|
+
* `payload` — the raw body alone will not match. Most callers should use
|
|
63
|
+
* `verifyWebhook` instead, which builds the string and checks freshness.
|
|
9
64
|
*/
|
|
10
65
|
async function verifyWebhookSignature(payload, signature, secret) {
|
|
11
66
|
const expected = signature.startsWith("sha256=") ? signature.slice(7) : signature;
|
|
@@ -21,4 +76,4 @@ async function verifyWebhookSignature(payload, signature, secret) {
|
|
|
21
76
|
return mismatch === 0;
|
|
22
77
|
}
|
|
23
78
|
//#endregion
|
|
24
|
-
export { verifyWebhookSignature };
|
|
79
|
+
export { verifyWebhook, verifyWebhookSignature };
|