@workbenchcrm/sdk 1.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.
@@ -0,0 +1,1533 @@
1
+ /**
2
+ * @file types/index.ts
3
+ * @description TypeScript type definitions for the Workbench SDK
4
+ *
5
+ * These types mirror the API response structures and provide
6
+ * full type safety when working with the Workbench API.
7
+ */
8
+ /**
9
+ * Configuration options for the Workbench client
10
+ */
11
+ interface WorkbenchConfig {
12
+ /** API key for authentication (wbk_live_xxx or wbk_test_xxx) */
13
+ apiKey?: string;
14
+ /** OAuth access token for third-party app authentication */
15
+ accessToken?: string;
16
+ /** Base URL for the API (defaults to https://api.tryworkbench.app) */
17
+ baseUrl?: string;
18
+ /** Request timeout in milliseconds (defaults to 30000) */
19
+ timeout?: number;
20
+ /** Maximum number of retries for failed requests (defaults to 3) */
21
+ maxRetries?: number;
22
+ }
23
+ /**
24
+ * Options for paginated list requests
25
+ */
26
+ interface ListOptions {
27
+ /** Page number (1-indexed, defaults to 1) */
28
+ page?: number;
29
+ /** Items per page (1-100, defaults to 20) */
30
+ per_page?: number;
31
+ /** Search query string */
32
+ search?: string;
33
+ /** Field to sort by */
34
+ sort?: string;
35
+ /** Sort order */
36
+ order?: 'asc' | 'desc';
37
+ }
38
+ /**
39
+ * Standard API response metadata
40
+ */
41
+ interface ResponseMeta {
42
+ /** Unique request identifier for debugging */
43
+ request_id: string;
44
+ /** Server timestamp of the response */
45
+ timestamp: string;
46
+ }
47
+ /**
48
+ * Pagination information for list responses
49
+ */
50
+ interface Pagination {
51
+ /** Current page number */
52
+ page: number;
53
+ /** Items per page */
54
+ per_page: number;
55
+ /** Total number of items */
56
+ total: number;
57
+ /** Total number of pages */
58
+ total_pages: number;
59
+ /** Whether there's a next page */
60
+ has_more: boolean;
61
+ }
62
+ /**
63
+ * Standard API response wrapper for single items
64
+ */
65
+ interface ApiResponse<T> {
66
+ data: T;
67
+ meta: ResponseMeta;
68
+ }
69
+ /**
70
+ * Standard API response wrapper for lists
71
+ */
72
+ interface ListResponse<T> {
73
+ data: T[];
74
+ meta: ResponseMeta;
75
+ pagination: Pagination;
76
+ }
77
+ /**
78
+ * API error response
79
+ */
80
+ interface ApiError {
81
+ error: {
82
+ code: string;
83
+ message: string;
84
+ details?: Array<{
85
+ field: string;
86
+ message: string;
87
+ }>;
88
+ };
89
+ meta: ResponseMeta;
90
+ }
91
+ /**
92
+ * Client status values
93
+ */
94
+ type ClientStatus = 'active' | 'inactive' | 'lead' | 'prospect';
95
+ /**
96
+ * Client record
97
+ */
98
+ interface Client {
99
+ id: string;
100
+ business_id: string;
101
+ first_name: string;
102
+ last_name: string | null;
103
+ company: string | null;
104
+ email: string | null;
105
+ phone: string | null;
106
+ status: ClientStatus;
107
+ source: string | null;
108
+ notes: string | null;
109
+ tags: string[] | null;
110
+ next_contact_date: string | null;
111
+ ask_for_review: boolean | null;
112
+ created_at: string;
113
+ updated_at: string;
114
+ }
115
+ /**
116
+ * Options for creating a client
117
+ */
118
+ interface CreateClientOptions {
119
+ first_name: string;
120
+ last_name?: string | null;
121
+ company?: string | null;
122
+ email?: string | null;
123
+ phone?: string | null;
124
+ status?: ClientStatus;
125
+ source?: string | null;
126
+ notes?: string | null;
127
+ tags?: string[] | null;
128
+ }
129
+ /**
130
+ * Options for updating a client
131
+ */
132
+ interface UpdateClientOptions extends Partial<CreateClientOptions> {
133
+ next_contact_date?: string | null;
134
+ ask_for_review?: boolean | null;
135
+ }
136
+ /**
137
+ * Options for listing clients
138
+ */
139
+ interface ListClientsOptions extends ListOptions {
140
+ status?: ClientStatus;
141
+ }
142
+ /**
143
+ * Invoice status values
144
+ */
145
+ type InvoiceStatus = 'draft' | 'sent' | 'viewed' | 'partial' | 'paid' | 'overdue' | 'cancelled';
146
+ /**
147
+ * Invoice line item
148
+ */
149
+ interface InvoiceItem {
150
+ id?: string;
151
+ description: string;
152
+ quantity: number;
153
+ unit_price: number;
154
+ sort_order?: number;
155
+ }
156
+ /**
157
+ * Invoice record
158
+ */
159
+ interface Invoice {
160
+ id: string;
161
+ business_id: string;
162
+ client_id: string | null;
163
+ job_id: string | null;
164
+ invoice_number: string;
165
+ status: InvoiceStatus;
166
+ issue_date: string;
167
+ due_date: string | null;
168
+ subtotal: number;
169
+ tax_rate: number | null;
170
+ tax_amount: number | null;
171
+ discount_amount: number | null;
172
+ total: number;
173
+ amount_paid: number;
174
+ notes: string | null;
175
+ terms: string | null;
176
+ items: InvoiceItem[];
177
+ client?: Client;
178
+ created_at: string;
179
+ updated_at: string;
180
+ }
181
+ /**
182
+ * Options for creating an invoice
183
+ */
184
+ interface CreateInvoiceOptions {
185
+ client_id?: string | null;
186
+ job_id?: string | null;
187
+ status?: InvoiceStatus;
188
+ issue_date?: string;
189
+ due_date?: string | null;
190
+ tax_rate?: number | null;
191
+ discount_amount?: number | null;
192
+ notes?: string | null;
193
+ terms?: string | null;
194
+ items: InvoiceItem[];
195
+ }
196
+ /**
197
+ * Options for updating an invoice
198
+ */
199
+ interface UpdateInvoiceOptions extends Partial<Omit<CreateInvoiceOptions, 'items'>> {
200
+ items?: InvoiceItem[];
201
+ }
202
+ /**
203
+ * Options for listing invoices
204
+ */
205
+ interface ListInvoicesOptions extends ListOptions {
206
+ status?: InvoiceStatus;
207
+ client_id?: string;
208
+ }
209
+ /**
210
+ * Quote status values
211
+ */
212
+ type QuoteStatus = 'draft' | 'sent' | 'viewed' | 'approved' | 'rejected' | 'expired' | 'converted';
213
+ /**
214
+ * Quote line item
215
+ */
216
+ interface QuoteItem {
217
+ id?: string;
218
+ description: string;
219
+ quantity: number;
220
+ unit_price: number;
221
+ sort_order?: number;
222
+ }
223
+ /**
224
+ * Quote record
225
+ */
226
+ interface Quote {
227
+ id: string;
228
+ business_id: string;
229
+ client_id: string | null;
230
+ job_id: string | null;
231
+ quote_number: string;
232
+ status: QuoteStatus;
233
+ issue_date: string;
234
+ valid_until: string | null;
235
+ subtotal: number;
236
+ tax_rate: number | null;
237
+ tax_amount: number | null;
238
+ discount_amount: number | null;
239
+ total: number;
240
+ notes: string | null;
241
+ terms: string | null;
242
+ items: QuoteItem[];
243
+ client?: Client;
244
+ created_at: string;
245
+ updated_at: string;
246
+ }
247
+ /**
248
+ * Options for creating a quote
249
+ */
250
+ interface CreateQuoteOptions {
251
+ client_id?: string | null;
252
+ job_id?: string | null;
253
+ status?: QuoteStatus;
254
+ issue_date?: string;
255
+ valid_until?: string | null;
256
+ tax_rate?: number | null;
257
+ discount_amount?: number | null;
258
+ notes?: string | null;
259
+ terms?: string | null;
260
+ items: QuoteItem[];
261
+ }
262
+ /**
263
+ * Options for updating a quote
264
+ */
265
+ interface UpdateQuoteOptions extends Partial<Omit<CreateQuoteOptions, 'items'>> {
266
+ items?: QuoteItem[];
267
+ }
268
+ /**
269
+ * Options for listing quotes
270
+ */
271
+ interface ListQuotesOptions extends ListOptions {
272
+ status?: QuoteStatus;
273
+ client_id?: string;
274
+ }
275
+ /**
276
+ * Job status values
277
+ */
278
+ type JobStatus = 'pending' | 'scheduled' | 'in_progress' | 'completed' | 'cancelled' | 'on_hold';
279
+ /**
280
+ * Job priority values
281
+ */
282
+ type JobPriority = 'low' | 'medium' | 'high' | 'urgent';
283
+ /**
284
+ * Job record
285
+ */
286
+ interface Job {
287
+ id: string;
288
+ business_id: string;
289
+ client_id: string | null;
290
+ title: string;
291
+ description: string | null;
292
+ status: JobStatus;
293
+ priority: JobPriority;
294
+ scheduled_start: string | null;
295
+ scheduled_end: string | null;
296
+ actual_start: string | null;
297
+ actual_end: string | null;
298
+ estimated_duration: number | null;
299
+ address_id: string | null;
300
+ notes: string | null;
301
+ client?: Client;
302
+ created_at: string;
303
+ updated_at: string;
304
+ }
305
+ /**
306
+ * Options for creating a job
307
+ */
308
+ interface CreateJobOptions {
309
+ client_id?: string | null;
310
+ title: string;
311
+ description?: string | null;
312
+ status?: JobStatus;
313
+ priority?: JobPriority;
314
+ scheduled_start?: string | null;
315
+ scheduled_end?: string | null;
316
+ estimated_duration?: number | null;
317
+ address_id?: string | null;
318
+ notes?: string | null;
319
+ }
320
+ /**
321
+ * Options for updating a job
322
+ */
323
+ interface UpdateJobOptions extends Partial<CreateJobOptions> {
324
+ actual_start?: string | null;
325
+ actual_end?: string | null;
326
+ }
327
+ /**
328
+ * Options for listing jobs
329
+ */
330
+ interface ListJobsOptions extends ListOptions {
331
+ status?: JobStatus;
332
+ priority?: JobPriority;
333
+ client_id?: string;
334
+ }
335
+ /**
336
+ * Service request status values
337
+ */
338
+ type ServiceRequestStatus = 'new' | 'reviewing' | 'scheduled' | 'completed' | 'cancelled' | 'declined';
339
+ /**
340
+ * Service request priority values
341
+ */
342
+ type ServiceRequestPriority = 'low' | 'medium' | 'high' | 'urgent';
343
+ /**
344
+ * Service request record
345
+ */
346
+ interface ServiceRequest {
347
+ id: string;
348
+ business_id: string;
349
+ client_id: string | null;
350
+ title: string;
351
+ description: string | null;
352
+ status: ServiceRequestStatus;
353
+ source: string | null;
354
+ priority: ServiceRequestPriority | null;
355
+ requested_date: string | null;
356
+ preferred_time: string | null;
357
+ address: string | null;
358
+ contact_name: string | null;
359
+ contact_email: string | null;
360
+ contact_phone: string | null;
361
+ notes: string | null;
362
+ client?: Client;
363
+ created_at: string;
364
+ updated_at: string;
365
+ }
366
+ /**
367
+ * Options for creating a service request
368
+ */
369
+ interface CreateServiceRequestOptions {
370
+ client_id?: string | null;
371
+ title: string;
372
+ description?: string | null;
373
+ status?: ServiceRequestStatus;
374
+ source?: string | null;
375
+ priority?: ServiceRequestPriority | null;
376
+ requested_date?: string | null;
377
+ preferred_time?: string | null;
378
+ address?: string | null;
379
+ contact_name?: string | null;
380
+ contact_email?: string | null;
381
+ contact_phone?: string | null;
382
+ notes?: string | null;
383
+ }
384
+ /**
385
+ * Options for updating a service request
386
+ */
387
+ type UpdateServiceRequestOptions = Partial<CreateServiceRequestOptions>;
388
+ /**
389
+ * Options for listing service requests
390
+ */
391
+ interface ListServiceRequestsOptions extends ListOptions {
392
+ status?: ServiceRequestStatus;
393
+ priority?: ServiceRequestPriority;
394
+ client_id?: string;
395
+ }
396
+ /**
397
+ * Available webhook event types
398
+ */
399
+ type WebhookEvent = 'client.created' | 'client.updated' | 'client.deleted' | 'invoice.created' | 'invoice.sent' | 'invoice.paid' | 'invoice.overdue' | 'quote.created' | 'quote.sent' | 'quote.accepted' | 'quote.rejected' | 'job.created' | 'job.status_changed' | 'job.completed' | 'service_request.created' | 'service_request.assigned';
400
+ /**
401
+ * Webhook subscription
402
+ */
403
+ interface Webhook {
404
+ id: string;
405
+ business_id: string;
406
+ name: string;
407
+ url: string;
408
+ events: WebhookEvent[];
409
+ secret: string;
410
+ is_active: boolean;
411
+ created_at: string;
412
+ updated_at: string;
413
+ }
414
+ /**
415
+ * Webhook delivery record
416
+ */
417
+ interface WebhookDelivery {
418
+ id: string;
419
+ webhook_id: string;
420
+ event_type: WebhookEvent;
421
+ payload: Record<string, unknown>;
422
+ response_status: number | null;
423
+ response_body: string | null;
424
+ attempt_count: number;
425
+ next_retry_at: string | null;
426
+ delivered_at: string | null;
427
+ failed_at: string | null;
428
+ created_at: string;
429
+ }
430
+ /**
431
+ * Options for creating a webhook
432
+ */
433
+ interface CreateWebhookOptions {
434
+ name: string;
435
+ url: string;
436
+ events: WebhookEvent[];
437
+ }
438
+ /**
439
+ * Options for updating a webhook
440
+ */
441
+ interface UpdateWebhookOptions {
442
+ name?: string;
443
+ url?: string;
444
+ events?: WebhookEvent[];
445
+ is_active?: boolean;
446
+ }
447
+ /**
448
+ * Options for listing webhook deliveries
449
+ */
450
+ interface ListWebhookDeliveriesOptions extends ListOptions {
451
+ event_type?: WebhookEvent;
452
+ }
453
+
454
+ /**
455
+ * @file resources/clients.ts
456
+ * @description Clients resource for the Workbench SDK
457
+ *
458
+ * Provides methods for managing clients in Workbench CRM.
459
+ */
460
+
461
+ /**
462
+ * Clients resource
463
+ *
464
+ * @example
465
+ * ```typescript
466
+ * const workbench = new WorkbenchClient({ apiKey: 'wbk_live_xxx' });
467
+ *
468
+ * // List clients
469
+ * const { data: clients, pagination } = await workbench.clients.list({
470
+ * status: 'active',
471
+ * per_page: 10
472
+ * });
473
+ *
474
+ * // Create a client
475
+ * const { data: client } = await workbench.clients.create({
476
+ * first_name: 'John',
477
+ * last_name: 'Doe',
478
+ * email: 'john@example.com'
479
+ * });
480
+ *
481
+ * // Get a client
482
+ * const { data: client } = await workbench.clients.get('client-uuid');
483
+ *
484
+ * // Update a client
485
+ * const { data: updated } = await workbench.clients.update('client-uuid', {
486
+ * phone: '+1-555-123-4567'
487
+ * });
488
+ *
489
+ * // Delete a client
490
+ * await workbench.clients.delete('client-uuid');
491
+ * ```
492
+ */
493
+ declare class ClientsResource {
494
+ private readonly client;
495
+ constructor(client: WorkbenchClient);
496
+ /**
497
+ * List all clients
498
+ *
499
+ * Returns a paginated list of clients for the authenticated business.
500
+ *
501
+ * @param options - List options (pagination, filtering, sorting)
502
+ * @returns Paginated list of clients
503
+ *
504
+ * @example
505
+ * ```typescript
506
+ * // List all active clients
507
+ * const { data, pagination } = await workbench.clients.list({
508
+ * status: 'active',
509
+ * page: 1,
510
+ * per_page: 20
511
+ * });
512
+ *
513
+ * console.log(`Found ${pagination.total} clients`);
514
+ * ```
515
+ */
516
+ list(options?: ListClientsOptions): Promise<ListResponse<Client>>;
517
+ /**
518
+ * Get a client by ID
519
+ *
520
+ * @param id - Client UUID
521
+ * @returns Client details
522
+ *
523
+ * @example
524
+ * ```typescript
525
+ * const { data: client } = await workbench.clients.get('client-uuid');
526
+ * console.log(`Client: ${client.first_name} ${client.last_name}`);
527
+ * ```
528
+ */
529
+ get(id: string): Promise<ApiResponse<Client>>;
530
+ /**
531
+ * Create a new client
532
+ *
533
+ * @param data - Client data
534
+ * @returns Created client
535
+ *
536
+ * @example
537
+ * ```typescript
538
+ * const { data: client } = await workbench.clients.create({
539
+ * first_name: 'John',
540
+ * last_name: 'Doe',
541
+ * email: 'john@example.com',
542
+ * phone: '+1-555-123-4567',
543
+ * company: 'Acme Corp',
544
+ * status: 'active',
545
+ * source: 'referral',
546
+ * tags: ['vip', 'commercial']
547
+ * });
548
+ * ```
549
+ */
550
+ create(data: CreateClientOptions): Promise<ApiResponse<Client>>;
551
+ /**
552
+ * Update a client
553
+ *
554
+ * @param id - Client UUID
555
+ * @param data - Fields to update
556
+ * @returns Updated client
557
+ *
558
+ * @example
559
+ * ```typescript
560
+ * const { data: client } = await workbench.clients.update('client-uuid', {
561
+ * status: 'inactive',
562
+ * notes: 'Client requested to pause services'
563
+ * });
564
+ * ```
565
+ */
566
+ update(id: string, data: UpdateClientOptions): Promise<ApiResponse<Client>>;
567
+ /**
568
+ * Delete a client
569
+ *
570
+ * Permanently deletes a client and all associated data.
571
+ * This action cannot be undone.
572
+ *
573
+ * @param id - Client UUID
574
+ *
575
+ * @example
576
+ * ```typescript
577
+ * await workbench.clients.delete('client-uuid');
578
+ * ```
579
+ */
580
+ delete(id: string): Promise<void>;
581
+ }
582
+
583
+ /**
584
+ * @file resources/invoices.ts
585
+ * @description Invoices resource for the Workbench SDK
586
+ *
587
+ * Provides methods for managing invoices in Workbench CRM.
588
+ */
589
+
590
+ /**
591
+ * Invoices resource
592
+ *
593
+ * @example
594
+ * ```typescript
595
+ * const workbench = new WorkbenchClient({ apiKey: 'wbk_live_xxx' });
596
+ *
597
+ * // Create an invoice
598
+ * const { data: invoice } = await workbench.invoices.create({
599
+ * client_id: 'client-uuid',
600
+ * items: [
601
+ * { description: 'Consulting', quantity: 2, unit_price: 150 },
602
+ * { description: 'Materials', quantity: 1, unit_price: 50 }
603
+ * ],
604
+ * tax_rate: 8.5,
605
+ * notes: 'Thank you for your business!'
606
+ * });
607
+ *
608
+ * // Send the invoice
609
+ * await workbench.invoices.send(invoice.id);
610
+ * ```
611
+ */
612
+ declare class InvoicesResource {
613
+ private readonly client;
614
+ constructor(client: WorkbenchClient);
615
+ /**
616
+ * List all invoices
617
+ *
618
+ * Returns a paginated list of invoices for the authenticated business.
619
+ *
620
+ * @param options - List options (pagination, filtering, sorting)
621
+ * @returns Paginated list of invoices
622
+ *
623
+ * @example
624
+ * ```typescript
625
+ * // List unpaid invoices
626
+ * const { data, pagination } = await workbench.invoices.list({
627
+ * status: 'sent',
628
+ * per_page: 50
629
+ * });
630
+ * ```
631
+ */
632
+ list(options?: ListInvoicesOptions): Promise<ListResponse<Invoice>>;
633
+ /**
634
+ * Get an invoice by ID
635
+ *
636
+ * @param id - Invoice UUID
637
+ * @returns Invoice details with line items
638
+ *
639
+ * @example
640
+ * ```typescript
641
+ * const { data: invoice } = await workbench.invoices.get('invoice-uuid');
642
+ * console.log(`Invoice ${invoice.invoice_number}: $${invoice.total}`);
643
+ * ```
644
+ */
645
+ get(id: string): Promise<ApiResponse<Invoice>>;
646
+ /**
647
+ * Create a new invoice
648
+ *
649
+ * Creates an invoice with line items. The invoice number is
650
+ * automatically generated by Workbench.
651
+ *
652
+ * @param data - Invoice data including line items
653
+ * @returns Created invoice
654
+ *
655
+ * @example
656
+ * ```typescript
657
+ * const { data: invoice } = await workbench.invoices.create({
658
+ * client_id: 'client-uuid',
659
+ * due_date: '2024-02-15',
660
+ * items: [
661
+ * { description: 'Web Development', quantity: 10, unit_price: 100 }
662
+ * ],
663
+ * tax_rate: 8.5,
664
+ * notes: 'Payment due within 30 days'
665
+ * });
666
+ * ```
667
+ */
668
+ create(data: CreateInvoiceOptions): Promise<ApiResponse<Invoice>>;
669
+ /**
670
+ * Update an invoice
671
+ *
672
+ * If items are provided, they will replace all existing line items.
673
+ *
674
+ * @param id - Invoice UUID
675
+ * @param data - Fields to update
676
+ * @returns Updated invoice
677
+ *
678
+ * @example
679
+ * ```typescript
680
+ * const { data: invoice } = await workbench.invoices.update('invoice-uuid', {
681
+ * status: 'paid',
682
+ * notes: 'Paid via bank transfer on 2024-01-15'
683
+ * });
684
+ * ```
685
+ */
686
+ update(id: string, data: UpdateInvoiceOptions): Promise<ApiResponse<Invoice>>;
687
+ /**
688
+ * Delete an invoice
689
+ *
690
+ * Permanently deletes an invoice and all associated line items.
691
+ * This action cannot be undone.
692
+ *
693
+ * @param id - Invoice UUID
694
+ *
695
+ * @example
696
+ * ```typescript
697
+ * await workbench.invoices.delete('invoice-uuid');
698
+ * ```
699
+ */
700
+ delete(id: string): Promise<void>;
701
+ /**
702
+ * Send an invoice via email
703
+ *
704
+ * Sends the invoice to the client's email address. The invoice
705
+ * status will be updated to 'sent' if currently 'draft'.
706
+ *
707
+ * @param id - Invoice UUID
708
+ * @returns Success response
709
+ *
710
+ * @example
711
+ * ```typescript
712
+ * await workbench.invoices.send('invoice-uuid');
713
+ * console.log('Invoice sent successfully');
714
+ * ```
715
+ */
716
+ send(id: string): Promise<ApiResponse<{
717
+ message: string;
718
+ invoice_id: string;
719
+ }>>;
720
+ }
721
+
722
+ /**
723
+ * @file resources/quotes.ts
724
+ * @description Quotes resource for the Workbench SDK
725
+ *
726
+ * Provides methods for managing quotes/estimates in Workbench CRM.
727
+ */
728
+
729
+ /**
730
+ * Quotes resource
731
+ *
732
+ * @example
733
+ * ```typescript
734
+ * const workbench = new WorkbenchClient({ apiKey: 'wbk_live_xxx' });
735
+ *
736
+ * // Create a quote
737
+ * const { data: quote } = await workbench.quotes.create({
738
+ * client_id: 'client-uuid',
739
+ * valid_until: '2024-02-28',
740
+ * items: [
741
+ * { description: 'Kitchen Renovation', quantity: 1, unit_price: 5000 },
742
+ * { description: 'Materials', quantity: 1, unit_price: 2500 }
743
+ * ]
744
+ * });
745
+ *
746
+ * // Send the quote
747
+ * await workbench.quotes.send(quote.id);
748
+ * ```
749
+ */
750
+ declare class QuotesResource {
751
+ private readonly client;
752
+ constructor(client: WorkbenchClient);
753
+ /**
754
+ * List all quotes
755
+ *
756
+ * Returns a paginated list of quotes for the authenticated business.
757
+ *
758
+ * @param options - List options (pagination, filtering, sorting)
759
+ * @returns Paginated list of quotes
760
+ *
761
+ * @example
762
+ * ```typescript
763
+ * // List pending quotes
764
+ * const { data, pagination } = await workbench.quotes.list({
765
+ * status: 'sent',
766
+ * per_page: 20
767
+ * });
768
+ * ```
769
+ */
770
+ list(options?: ListQuotesOptions): Promise<ListResponse<Quote>>;
771
+ /**
772
+ * Get a quote by ID
773
+ *
774
+ * @param id - Quote UUID
775
+ * @returns Quote details with line items
776
+ *
777
+ * @example
778
+ * ```typescript
779
+ * const { data: quote } = await workbench.quotes.get('quote-uuid');
780
+ * console.log(`Quote ${quote.quote_number}: $${quote.total}`);
781
+ * ```
782
+ */
783
+ get(id: string): Promise<ApiResponse<Quote>>;
784
+ /**
785
+ * Create a new quote
786
+ *
787
+ * Creates a quote with line items. The quote number is
788
+ * automatically generated by Workbench.
789
+ *
790
+ * @param data - Quote data including line items
791
+ * @returns Created quote
792
+ *
793
+ * @example
794
+ * ```typescript
795
+ * const { data: quote } = await workbench.quotes.create({
796
+ * client_id: 'client-uuid',
797
+ * valid_until: '2024-03-01',
798
+ * items: [
799
+ * { description: 'Plumbing Service', quantity: 4, unit_price: 75 }
800
+ * ],
801
+ * notes: 'Quote valid for 30 days',
802
+ * terms: 'Payment due upon completion'
803
+ * });
804
+ * ```
805
+ */
806
+ create(data: CreateQuoteOptions): Promise<ApiResponse<Quote>>;
807
+ /**
808
+ * Update a quote
809
+ *
810
+ * If items are provided, they will replace all existing line items.
811
+ *
812
+ * @param id - Quote UUID
813
+ * @param data - Fields to update
814
+ * @returns Updated quote
815
+ *
816
+ * @example
817
+ * ```typescript
818
+ * const { data: quote } = await workbench.quotes.update('quote-uuid', {
819
+ * status: 'approved',
820
+ * notes: 'Client approved via email on 2024-01-15'
821
+ * });
822
+ * ```
823
+ */
824
+ update(id: string, data: UpdateQuoteOptions): Promise<ApiResponse<Quote>>;
825
+ /**
826
+ * Delete a quote
827
+ *
828
+ * Permanently deletes a quote and all associated line items.
829
+ * This action cannot be undone.
830
+ *
831
+ * @param id - Quote UUID
832
+ *
833
+ * @example
834
+ * ```typescript
835
+ * await workbench.quotes.delete('quote-uuid');
836
+ * ```
837
+ */
838
+ delete(id: string): Promise<void>;
839
+ /**
840
+ * Send a quote via email
841
+ *
842
+ * Sends the quote to the client's email address. The quote
843
+ * status will be updated to 'sent' if currently 'draft'.
844
+ *
845
+ * @param id - Quote UUID
846
+ * @returns Success response
847
+ *
848
+ * @example
849
+ * ```typescript
850
+ * await workbench.quotes.send('quote-uuid');
851
+ * console.log('Quote sent successfully');
852
+ * ```
853
+ */
854
+ send(id: string): Promise<ApiResponse<{
855
+ message: string;
856
+ quote_id: string;
857
+ }>>;
858
+ }
859
+
860
+ /**
861
+ * @file resources/jobs.ts
862
+ * @description Jobs resource for the Workbench SDK
863
+ *
864
+ * Provides methods for managing jobs/work orders in Workbench CRM.
865
+ */
866
+
867
+ /**
868
+ * Jobs resource
869
+ *
870
+ * @example
871
+ * ```typescript
872
+ * const workbench = new WorkbenchClient({ apiKey: 'wbk_live_xxx' });
873
+ *
874
+ * // Create a job
875
+ * const { data: job } = await workbench.jobs.create({
876
+ * client_id: 'client-uuid',
877
+ * title: 'Kitchen Faucet Installation',
878
+ * priority: 'high',
879
+ * scheduled_start: '2024-01-20T09:00:00Z',
880
+ * scheduled_end: '2024-01-20T12:00:00Z'
881
+ * });
882
+ *
883
+ * // Update job status
884
+ * await workbench.jobs.update(job.id, { status: 'completed' });
885
+ * ```
886
+ */
887
+ declare class JobsResource {
888
+ private readonly client;
889
+ constructor(client: WorkbenchClient);
890
+ /**
891
+ * List all jobs
892
+ *
893
+ * Returns a paginated list of jobs for the authenticated business.
894
+ *
895
+ * @param options - List options (pagination, filtering, sorting)
896
+ * @returns Paginated list of jobs
897
+ *
898
+ * @example
899
+ * ```typescript
900
+ * // List scheduled jobs
901
+ * const { data, pagination } = await workbench.jobs.list({
902
+ * status: 'scheduled',
903
+ * priority: 'high',
904
+ * per_page: 20
905
+ * });
906
+ * ```
907
+ */
908
+ list(options?: ListJobsOptions): Promise<ListResponse<Job>>;
909
+ /**
910
+ * Get a job by ID
911
+ *
912
+ * @param id - Job UUID
913
+ * @returns Job details
914
+ *
915
+ * @example
916
+ * ```typescript
917
+ * const { data: job } = await workbench.jobs.get('job-uuid');
918
+ * console.log(`Job: ${job.title} (${job.status})`);
919
+ * ```
920
+ */
921
+ get(id: string): Promise<ApiResponse<Job>>;
922
+ /**
923
+ * Create a new job
924
+ *
925
+ * @param data - Job data
926
+ * @returns Created job
927
+ *
928
+ * @example
929
+ * ```typescript
930
+ * const { data: job } = await workbench.jobs.create({
931
+ * client_id: 'client-uuid',
932
+ * title: 'HVAC Maintenance',
933
+ * description: 'Annual AC maintenance and filter replacement',
934
+ * priority: 'medium',
935
+ * scheduled_start: '2024-01-25T10:00:00Z',
936
+ * estimated_duration: 120, // minutes
937
+ * notes: 'Customer prefers morning appointments'
938
+ * });
939
+ * ```
940
+ */
941
+ create(data: CreateJobOptions): Promise<ApiResponse<Job>>;
942
+ /**
943
+ * Update a job
944
+ *
945
+ * @param id - Job UUID
946
+ * @param data - Fields to update
947
+ * @returns Updated job
948
+ *
949
+ * @example
950
+ * ```typescript
951
+ * // Mark job as started
952
+ * const { data: job } = await workbench.jobs.update('job-uuid', {
953
+ * status: 'in_progress',
954
+ * actual_start: new Date().toISOString()
955
+ * });
956
+ *
957
+ * // Mark job as completed
958
+ * await workbench.jobs.update('job-uuid', {
959
+ * status: 'completed',
960
+ * actual_end: new Date().toISOString()
961
+ * });
962
+ * ```
963
+ */
964
+ update(id: string, data: UpdateJobOptions): Promise<ApiResponse<Job>>;
965
+ /**
966
+ * Delete a job
967
+ *
968
+ * Permanently deletes a job. This action cannot be undone.
969
+ *
970
+ * @param id - Job UUID
971
+ *
972
+ * @example
973
+ * ```typescript
974
+ * await workbench.jobs.delete('job-uuid');
975
+ * ```
976
+ */
977
+ delete(id: string): Promise<void>;
978
+ }
979
+
980
+ /**
981
+ * @file resources/service-requests.ts
982
+ * @description Service Requests resource for the Workbench SDK
983
+ *
984
+ * Provides methods for managing service requests in Workbench CRM.
985
+ */
986
+
987
+ /**
988
+ * Service Requests resource
989
+ *
990
+ * @example
991
+ * ```typescript
992
+ * const workbench = new WorkbenchClient({ apiKey: 'wbk_live_xxx' });
993
+ *
994
+ * // Create a service request
995
+ * const { data: request } = await workbench.serviceRequests.create({
996
+ * title: 'Leaky Faucet Repair',
997
+ * contact_name: 'Jane Smith',
998
+ * contact_email: 'jane@example.com',
999
+ * contact_phone: '+1-555-987-6543',
1000
+ * address: '123 Main St, Anytown, USA',
1001
+ * priority: 'high'
1002
+ * });
1003
+ *
1004
+ * // Update request status
1005
+ * await workbench.serviceRequests.update(request.id, { status: 'scheduled' });
1006
+ * ```
1007
+ */
1008
+ declare class ServiceRequestsResource {
1009
+ private readonly client;
1010
+ constructor(client: WorkbenchClient);
1011
+ /**
1012
+ * List all service requests
1013
+ *
1014
+ * Returns a paginated list of service requests for the authenticated business.
1015
+ *
1016
+ * @param options - List options (pagination, filtering, sorting)
1017
+ * @returns Paginated list of service requests
1018
+ *
1019
+ * @example
1020
+ * ```typescript
1021
+ * // List new requests
1022
+ * const { data, pagination } = await workbench.serviceRequests.list({
1023
+ * status: 'new',
1024
+ * priority: 'urgent',
1025
+ * per_page: 50
1026
+ * });
1027
+ * ```
1028
+ */
1029
+ list(options?: ListServiceRequestsOptions): Promise<ListResponse<ServiceRequest>>;
1030
+ /**
1031
+ * Get a service request by ID
1032
+ *
1033
+ * @param id - Service request UUID
1034
+ * @returns Service request details
1035
+ *
1036
+ * @example
1037
+ * ```typescript
1038
+ * const { data: request } = await workbench.serviceRequests.get('request-uuid');
1039
+ * console.log(`Request: ${request.title} (${request.status})`);
1040
+ * ```
1041
+ */
1042
+ get(id: string): Promise<ApiResponse<ServiceRequest>>;
1043
+ /**
1044
+ * Create a new service request
1045
+ *
1046
+ * @param data - Service request data
1047
+ * @returns Created service request
1048
+ *
1049
+ * @example
1050
+ * ```typescript
1051
+ * const { data: request } = await workbench.serviceRequests.create({
1052
+ * title: 'AC Not Cooling',
1053
+ * description: 'Air conditioner is running but not producing cold air',
1054
+ * contact_name: 'John Doe',
1055
+ * contact_email: 'john@example.com',
1056
+ * contact_phone: '+1-555-123-4567',
1057
+ * address: '456 Oak Ave, Anytown, USA',
1058
+ * priority: 'urgent',
1059
+ * requested_date: '2024-01-20',
1060
+ * preferred_time: 'Morning (8am-12pm)',
1061
+ * source: 'website'
1062
+ * });
1063
+ * ```
1064
+ */
1065
+ create(data: CreateServiceRequestOptions): Promise<ApiResponse<ServiceRequest>>;
1066
+ /**
1067
+ * Update a service request
1068
+ *
1069
+ * @param id - Service request UUID
1070
+ * @param data - Fields to update
1071
+ * @returns Updated service request
1072
+ *
1073
+ * @example
1074
+ * ```typescript
1075
+ * // Assign to client and schedule
1076
+ * const { data: request } = await workbench.serviceRequests.update('request-uuid', {
1077
+ * client_id: 'client-uuid',
1078
+ * status: 'scheduled',
1079
+ * notes: 'Scheduled for Monday morning'
1080
+ * });
1081
+ * ```
1082
+ */
1083
+ update(id: string, data: UpdateServiceRequestOptions): Promise<ApiResponse<ServiceRequest>>;
1084
+ /**
1085
+ * Delete a service request
1086
+ *
1087
+ * Permanently deletes a service request. This action cannot be undone.
1088
+ *
1089
+ * @param id - Service request UUID
1090
+ *
1091
+ * @example
1092
+ * ```typescript
1093
+ * await workbench.serviceRequests.delete('request-uuid');
1094
+ * ```
1095
+ */
1096
+ delete(id: string): Promise<void>;
1097
+ }
1098
+
1099
+ /**
1100
+ * @file resources/webhooks.ts
1101
+ * @description Webhooks resource for the Workbench SDK
1102
+ *
1103
+ * Provides methods for managing webhook subscriptions in Workbench CRM.
1104
+ */
1105
+
1106
+ /**
1107
+ * Webhooks resource
1108
+ *
1109
+ * @example
1110
+ * ```typescript
1111
+ * const workbench = new WorkbenchClient({ apiKey: 'wbk_live_xxx' });
1112
+ *
1113
+ * // Create a webhook
1114
+ * const { data: webhook } = await workbench.webhooks.create({
1115
+ * name: 'Invoice Notifications',
1116
+ * url: 'https://example.com/webhooks/workbench',
1117
+ * events: ['invoice.created', 'invoice.paid']
1118
+ * });
1119
+ *
1120
+ * console.log('Webhook secret:', webhook.secret);
1121
+ * // Store this secret securely to verify webhook signatures
1122
+ * ```
1123
+ */
1124
+ declare class WebhooksResource {
1125
+ private readonly client;
1126
+ constructor(client: WorkbenchClient);
1127
+ /**
1128
+ * List all webhooks
1129
+ *
1130
+ * Returns a paginated list of webhook subscriptions for the authenticated business.
1131
+ *
1132
+ * @param options - List options (pagination)
1133
+ * @returns Paginated list of webhooks
1134
+ *
1135
+ * @example
1136
+ * ```typescript
1137
+ * const { data: webhooks } = await workbench.webhooks.list();
1138
+ * webhooks.forEach(webhook => {
1139
+ * console.log(`${webhook.name}: ${webhook.events.join(', ')}`);
1140
+ * });
1141
+ * ```
1142
+ */
1143
+ list(options?: ListOptions): Promise<ListResponse<Webhook>>;
1144
+ /**
1145
+ * Get a webhook by ID
1146
+ *
1147
+ * @param id - Webhook UUID
1148
+ * @returns Webhook details
1149
+ *
1150
+ * @example
1151
+ * ```typescript
1152
+ * const { data: webhook } = await workbench.webhooks.get('webhook-uuid');
1153
+ * console.log(`Webhook: ${webhook.name}`);
1154
+ * console.log(`Events: ${webhook.events.join(', ')}`);
1155
+ * ```
1156
+ */
1157
+ get(id: string): Promise<ApiResponse<Webhook>>;
1158
+ /**
1159
+ * Create a new webhook
1160
+ *
1161
+ * Creates a webhook subscription. The webhook secret is returned
1162
+ * in the response - store it securely to verify webhook signatures.
1163
+ *
1164
+ * @param data - Webhook data
1165
+ * @returns Created webhook (includes secret)
1166
+ *
1167
+ * @example
1168
+ * ```typescript
1169
+ * const { data: webhook } = await workbench.webhooks.create({
1170
+ * name: 'All Events',
1171
+ * url: 'https://example.com/webhooks',
1172
+ * events: [
1173
+ * 'client.created',
1174
+ * 'client.updated',
1175
+ * 'invoice.created',
1176
+ * 'invoice.paid',
1177
+ * 'quote.accepted',
1178
+ * 'job.completed'
1179
+ * ]
1180
+ * });
1181
+ *
1182
+ * // IMPORTANT: Store the secret securely!
1183
+ * console.log('Store this secret:', webhook.secret);
1184
+ * ```
1185
+ */
1186
+ create(data: CreateWebhookOptions): Promise<ApiResponse<Webhook>>;
1187
+ /**
1188
+ * Update a webhook
1189
+ *
1190
+ * @param id - Webhook UUID
1191
+ * @param data - Fields to update
1192
+ * @returns Updated webhook
1193
+ *
1194
+ * @example
1195
+ * ```typescript
1196
+ * // Add more events to the webhook
1197
+ * const { data: webhook } = await workbench.webhooks.update('webhook-uuid', {
1198
+ * events: ['invoice.created', 'invoice.paid', 'invoice.overdue']
1199
+ * });
1200
+ *
1201
+ * // Disable a webhook
1202
+ * await workbench.webhooks.update('webhook-uuid', { is_active: false });
1203
+ * ```
1204
+ */
1205
+ update(id: string, data: UpdateWebhookOptions): Promise<ApiResponse<Webhook>>;
1206
+ /**
1207
+ * Delete a webhook
1208
+ *
1209
+ * Permanently deletes a webhook subscription. No more events
1210
+ * will be sent to this endpoint.
1211
+ *
1212
+ * @param id - Webhook UUID
1213
+ *
1214
+ * @example
1215
+ * ```typescript
1216
+ * await workbench.webhooks.delete('webhook-uuid');
1217
+ * ```
1218
+ */
1219
+ delete(id: string): Promise<void>;
1220
+ /**
1221
+ * List webhook deliveries
1222
+ *
1223
+ * Returns recent delivery attempts for a webhook. Useful for
1224
+ * debugging and monitoring webhook health.
1225
+ *
1226
+ * @param webhookId - Webhook UUID
1227
+ * @param options - List options (pagination, filtering)
1228
+ * @returns Paginated list of delivery attempts
1229
+ *
1230
+ * @example
1231
+ * ```typescript
1232
+ * const { data: deliveries } = await workbench.webhooks.listDeliveries('webhook-uuid', {
1233
+ * per_page: 50
1234
+ * });
1235
+ *
1236
+ * deliveries.forEach(delivery => {
1237
+ * const status = delivery.delivered_at ? 'delivered' : 'pending';
1238
+ * console.log(`${delivery.event_type}: ${status}`);
1239
+ * });
1240
+ * ```
1241
+ */
1242
+ listDeliveries(webhookId: string, options?: ListWebhookDeliveriesOptions): Promise<ListResponse<WebhookDelivery>>;
1243
+ /**
1244
+ * Send a test webhook
1245
+ *
1246
+ * Sends a test event to the webhook endpoint. Useful for
1247
+ * verifying your webhook handler is working correctly.
1248
+ *
1249
+ * @param id - Webhook UUID
1250
+ * @returns Test delivery result
1251
+ *
1252
+ * @example
1253
+ * ```typescript
1254
+ * const { data: result } = await workbench.webhooks.test('webhook-uuid');
1255
+ * console.log('Test delivery:', result);
1256
+ * ```
1257
+ */
1258
+ test(id: string): Promise<ApiResponse<{
1259
+ message: string;
1260
+ delivery_id: string;
1261
+ }>>;
1262
+ }
1263
+
1264
+ /**
1265
+ * @file client.ts
1266
+ * @description Main Workbench API client class
1267
+ *
1268
+ * The WorkbenchClient is the primary interface for interacting with the
1269
+ * Workbench CRM API. It handles authentication, request management, and
1270
+ * provides access to all API resources.
1271
+ */
1272
+
1273
+ /**
1274
+ * Error thrown when an API request fails
1275
+ */
1276
+ declare class WorkbenchError extends Error {
1277
+ /** HTTP status code */
1278
+ readonly status: number;
1279
+ /** Error code from the API */
1280
+ readonly code: string;
1281
+ /** Additional error details */
1282
+ readonly details?: Array<{
1283
+ field: string;
1284
+ message: string;
1285
+ }>;
1286
+ /** Request ID for debugging */
1287
+ readonly requestId?: string;
1288
+ constructor(message: string, status: number, code: string, details?: Array<{
1289
+ field: string;
1290
+ message: string;
1291
+ }>, requestId?: string);
1292
+ }
1293
+ /**
1294
+ * HTTP request options
1295
+ */
1296
+ interface RequestOptions {
1297
+ /** HTTP method */
1298
+ method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
1299
+ /** Request path (without base URL) */
1300
+ path: string;
1301
+ /** Query parameters */
1302
+ query?: Record<string, string | number | boolean | undefined>;
1303
+ /** Request body */
1304
+ body?: unknown;
1305
+ /** Additional headers */
1306
+ headers?: Record<string, string>;
1307
+ }
1308
+ /**
1309
+ * Main Workbench API client
1310
+ *
1311
+ * @example
1312
+ * ```typescript
1313
+ * import { WorkbenchClient } from '@workbench/sdk';
1314
+ *
1315
+ * // Using API key authentication
1316
+ * const workbench = new WorkbenchClient({
1317
+ * apiKey: 'wbk_live_xxxxxxxxxxxxxxxxxxxxx'
1318
+ * });
1319
+ *
1320
+ * // Using OAuth access token
1321
+ * const workbench = new WorkbenchClient({
1322
+ * accessToken: 'wbk_at_xxxxxxxxxxxxxxxxxxxxx'
1323
+ * });
1324
+ *
1325
+ * // List clients
1326
+ * const clients = await workbench.clients.list({ page: 1, per_page: 10 });
1327
+ *
1328
+ * // Create an invoice
1329
+ * const invoice = await workbench.invoices.create({
1330
+ * client_id: 'client-uuid',
1331
+ * items: [{ description: 'Service', quantity: 1, unit_price: 100 }]
1332
+ * });
1333
+ * ```
1334
+ */
1335
+ declare class WorkbenchClient {
1336
+ private readonly baseUrl;
1337
+ private readonly timeout;
1338
+ private readonly maxRetries;
1339
+ private readonly authHeader;
1340
+ /** Clients resource */
1341
+ readonly clients: ClientsResource;
1342
+ /** Invoices resource */
1343
+ readonly invoices: InvoicesResource;
1344
+ /** Quotes resource */
1345
+ readonly quotes: QuotesResource;
1346
+ /** Jobs resource */
1347
+ readonly jobs: JobsResource;
1348
+ /** Service requests resource */
1349
+ readonly serviceRequests: ServiceRequestsResource;
1350
+ /** Webhooks resource */
1351
+ readonly webhooks: WebhooksResource;
1352
+ /**
1353
+ * Create a new Workbench client
1354
+ *
1355
+ * @param config - Client configuration
1356
+ * @throws Error if neither apiKey nor accessToken is provided
1357
+ */
1358
+ constructor(config: WorkbenchConfig);
1359
+ /**
1360
+ * Build URL with query parameters
1361
+ */
1362
+ private buildUrl;
1363
+ /**
1364
+ * Sleep for a specified duration
1365
+ */
1366
+ private sleep;
1367
+ /**
1368
+ * Calculate exponential backoff delay
1369
+ */
1370
+ private getRetryDelay;
1371
+ /**
1372
+ * Determine if an error is retryable
1373
+ */
1374
+ private isRetryable;
1375
+ /**
1376
+ * Make an API request
1377
+ *
1378
+ * @param options - Request options
1379
+ * @returns API response
1380
+ * @throws WorkbenchError if the request fails
1381
+ */
1382
+ request<T>(options: RequestOptions): Promise<T>;
1383
+ /**
1384
+ * Make a GET request
1385
+ */
1386
+ get<T>(path: string, query?: Record<string, string | number | boolean | undefined>): Promise<T>;
1387
+ /**
1388
+ * Make a POST request
1389
+ */
1390
+ post<T>(path: string, body?: unknown): Promise<T>;
1391
+ /**
1392
+ * Make a PUT request
1393
+ */
1394
+ put<T>(path: string, body?: unknown): Promise<T>;
1395
+ /**
1396
+ * Make a DELETE request
1397
+ */
1398
+ delete<T>(path: string): Promise<T>;
1399
+ }
1400
+
1401
+ /**
1402
+ * @file utils/webhook-verify.ts
1403
+ * @description Utilities for verifying Workbench webhook signatures
1404
+ *
1405
+ * Workbench signs all webhook payloads using HMAC-SHA256. This module provides
1406
+ * utilities to verify these signatures to ensure webhook authenticity.
1407
+ */
1408
+ /**
1409
+ * Parsed webhook signature components
1410
+ */
1411
+ interface WebhookSignature {
1412
+ /** Unix timestamp when the signature was generated */
1413
+ timestamp: number;
1414
+ /** HMAC-SHA256 signature */
1415
+ signature: string;
1416
+ }
1417
+ /**
1418
+ * Options for webhook signature verification
1419
+ */
1420
+ interface VerifyOptions {
1421
+ /**
1422
+ * Maximum age of the webhook in seconds (default: 300 = 5 minutes)
1423
+ * Set to 0 to disable timestamp validation
1424
+ */
1425
+ tolerance?: number;
1426
+ }
1427
+ /**
1428
+ * Error thrown when webhook signature verification fails
1429
+ */
1430
+ declare class WebhookVerificationError extends Error {
1431
+ constructor(message: string);
1432
+ }
1433
+ /**
1434
+ * Parse the X-Workbench-Signature header value
1435
+ *
1436
+ * The header format is: t=<timestamp>,v1=<signature>
1437
+ *
1438
+ * @param header - The X-Workbench-Signature header value
1439
+ * @returns Parsed signature components
1440
+ * @throws WebhookVerificationError if the header format is invalid
1441
+ *
1442
+ * @example
1443
+ * ```typescript
1444
+ * const { timestamp, signature } = parseSignatureHeader(
1445
+ * 't=1706400000,v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd'
1446
+ * );
1447
+ * ```
1448
+ */
1449
+ declare function parseSignatureHeader(header: string): WebhookSignature;
1450
+ /**
1451
+ * Compute the expected signature for a webhook payload
1452
+ *
1453
+ * @param payload - The raw webhook payload (string or Buffer)
1454
+ * @param secret - The webhook secret
1455
+ * @param timestamp - The timestamp from the signature header
1456
+ * @returns The expected HMAC-SHA256 signature
1457
+ *
1458
+ * @example
1459
+ * ```typescript
1460
+ * const expectedSignature = computeSignature(
1461
+ * '{"event":"client.created","data":{...}}',
1462
+ * 'whsec_xxxxxxxxxxxx',
1463
+ * 1706400000
1464
+ * );
1465
+ * ```
1466
+ */
1467
+ declare function computeSignature(payload: string | Buffer, secret: string, timestamp: number): string;
1468
+ /**
1469
+ * Verify a Workbench webhook signature
1470
+ *
1471
+ * This function verifies that a webhook payload was sent by Workbench and
1472
+ * hasn't been tampered with. It also checks that the webhook isn't too old
1473
+ * to prevent replay attacks.
1474
+ *
1475
+ * @param payload - The raw webhook payload (string or Buffer)
1476
+ * @param signature - The X-Workbench-Signature header value
1477
+ * @param secret - Your webhook secret (starts with whsec_)
1478
+ * @param options - Verification options
1479
+ * @returns true if the signature is valid
1480
+ * @throws WebhookVerificationError if verification fails
1481
+ *
1482
+ * @example
1483
+ * ```typescript
1484
+ * import { verifyWebhookSignature } from '@workbench/sdk';
1485
+ *
1486
+ * app.post('/webhooks', express.raw({ type: 'application/json' }), (req, res) => {
1487
+ * const signature = req.headers['x-workbench-signature'] as string;
1488
+ *
1489
+ * try {
1490
+ * verifyWebhookSignature(req.body, signature, process.env.WEBHOOK_SECRET!);
1491
+ *
1492
+ * // Process the webhook
1493
+ * const event = JSON.parse(req.body.toString());
1494
+ * console.log('Received event:', event.event);
1495
+ *
1496
+ * res.sendStatus(200);
1497
+ * } catch (error) {
1498
+ * console.error('Webhook verification failed:', error);
1499
+ * res.sendStatus(400);
1500
+ * }
1501
+ * });
1502
+ * ```
1503
+ */
1504
+ declare function verifyWebhookSignature(payload: string | Buffer, signature: string, secret: string, options?: VerifyOptions): boolean;
1505
+ /**
1506
+ * Construct a webhook event from a verified payload
1507
+ *
1508
+ * This is a convenience function that verifies the signature and parses
1509
+ * the payload in one step.
1510
+ *
1511
+ * @param payload - The raw webhook payload (string or Buffer)
1512
+ * @param signature - The X-Workbench-Signature header value
1513
+ * @param secret - Your webhook secret
1514
+ * @param options - Verification options
1515
+ * @returns The parsed webhook event
1516
+ * @throws WebhookVerificationError if verification fails
1517
+ *
1518
+ * @example
1519
+ * ```typescript
1520
+ * import { constructWebhookEvent } from '@workbench/sdk';
1521
+ *
1522
+ * const event = constructWebhookEvent(req.body, signature, secret);
1523
+ * console.log('Event type:', event.event);
1524
+ * console.log('Event data:', event.data);
1525
+ * ```
1526
+ */
1527
+ declare function constructWebhookEvent<T = Record<string, unknown>>(payload: string | Buffer, signature: string, secret: string, options?: VerifyOptions): {
1528
+ event: string;
1529
+ data: T;
1530
+ timestamp: string;
1531
+ };
1532
+
1533
+ export { type ApiError, type ApiResponse, type Client, type ClientStatus, ClientsResource, type CreateClientOptions, type CreateInvoiceOptions, type CreateJobOptions, type CreateQuoteOptions, type CreateServiceRequestOptions, type CreateWebhookOptions, type Invoice, type InvoiceItem, type InvoiceStatus, InvoicesResource, type Job, type JobPriority, type JobStatus, JobsResource, type ListClientsOptions, type ListInvoicesOptions, type ListJobsOptions, type ListOptions, type ListQuotesOptions, type ListResponse, type ListServiceRequestsOptions, type ListWebhookDeliveriesOptions, type Pagination, type Quote, type QuoteItem, type QuoteStatus, QuotesResource, type RequestOptions, type ResponseMeta, type ServiceRequest, type ServiceRequestPriority, type ServiceRequestStatus, ServiceRequestsResource, type UpdateClientOptions, type UpdateInvoiceOptions, type UpdateJobOptions, type UpdateQuoteOptions, type UpdateServiceRequestOptions, type UpdateWebhookOptions, type VerifyOptions, type Webhook, type WebhookDelivery, type WebhookEvent, type WebhookSignature, WebhookVerificationError, WebhooksResource, WorkbenchClient, type WorkbenchConfig, WorkbenchError, computeSignature, constructWebhookEvent, parseSignatureHeader, verifyWebhookSignature };