@workbenchcrm/sdk 1.0.4 → 1.2.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.d.mts CHANGED
@@ -529,6 +529,89 @@ interface WebhookEventTypeInfo {
529
529
  description: string;
530
530
  category: 'client' | 'invoice' | 'quote' | 'job' | 'service_request';
531
531
  }
532
+ /**
533
+ * Notification type - who receives the notification
534
+ */
535
+ type NotificationType = 'CLIENT' | 'BUSINESS';
536
+ /**
537
+ * Notification events supported by the SDK
538
+ * - sdk_client_created: Welcome notification for new clients
539
+ * - sdk_request_created: New service request notification
540
+ * - sdk_quote_created: Quote sent notification
541
+ * - sdk_invoice_created: Invoice sent notification
542
+ * - sdk_job_created: Job scheduled notification
543
+ * - sdk_custom: Custom notification (requires subject/html overrides)
544
+ */
545
+ type NotificationEvent = 'sdk_client_created' | 'sdk_request_created' | 'sdk_quote_created' | 'sdk_invoice_created' | 'sdk_job_created' | 'sdk_custom';
546
+ /**
547
+ * Business user roles for BUSINESS notifications
548
+ */
549
+ type BusinessUserRole = 'owner' | 'admin' | 'manager' | 'member';
550
+ /**
551
+ * Base options for sending notifications
552
+ */
553
+ interface SendNotificationBaseOptions {
554
+ /** Template data for variable interpolation (e.g., client_name, quote_total) */
555
+ templateData?: Record<string, string | number>;
556
+ /** Custom subject line (overrides template) */
557
+ subjectOverride?: string;
558
+ /** Custom HTML body (overrides template) */
559
+ htmlOverride?: string;
560
+ /** Entity type for audit logging (e.g., 'client', 'invoice') */
561
+ entityType?: string;
562
+ /** Entity ID for audit logging */
563
+ entityId?: string;
564
+ }
565
+ /**
566
+ * Options for sending a notification to a client
567
+ */
568
+ interface SendToClientOptions extends SendNotificationBaseOptions {
569
+ /** Client ID to send the notification to */
570
+ clientId: string;
571
+ /** Event type for template selection */
572
+ event: NotificationEvent;
573
+ }
574
+ /**
575
+ * Options for sending a notification to business team members
576
+ */
577
+ interface SendToTeamOptions extends SendNotificationBaseOptions {
578
+ /** Event type for template selection */
579
+ event: NotificationEvent;
580
+ /** Roles to notify (defaults to all if not specified) */
581
+ roles?: BusinessUserRole[];
582
+ }
583
+ /**
584
+ * Options for sending a custom notification
585
+ */
586
+ interface SendCustomNotificationOptions extends SendNotificationBaseOptions {
587
+ /** Notification type - CLIENT or BUSINESS */
588
+ type: NotificationType;
589
+ /** Client ID (required for CLIENT type) */
590
+ clientId?: string;
591
+ /** Roles to notify (for BUSINESS type) */
592
+ roles?: BusinessUserRole[];
593
+ /** Required: Custom subject line */
594
+ subject: string;
595
+ /** Required: Custom HTML body */
596
+ html: string;
597
+ }
598
+ /**
599
+ * Result of sending notifications
600
+ */
601
+ interface NotificationResult {
602
+ /** Whether at least one notification was sent successfully */
603
+ success: boolean;
604
+ /** Unique ID for this notification batch */
605
+ notification_id: string;
606
+ /** Total number of recipients */
607
+ recipients_count: number;
608
+ /** Number of successful email sends */
609
+ sent_count: number;
610
+ /** Number of failed email sends */
611
+ failed_count: number;
612
+ /** Error messages if any failures occurred */
613
+ errors?: string[];
614
+ }
532
615
 
533
616
  /**
534
617
  * @file resources/clients.ts
@@ -1057,48 +1140,47 @@ declare class JobsResource {
1057
1140
  }
1058
1141
 
1059
1142
  /**
1060
- * @file resources/service-requests.ts
1061
- * @description Service Requests resource for the Workbench SDK
1143
+ * Requests resource for the Workbench SDK.
1062
1144
  *
1063
1145
  * Provides methods for managing service requests in Workbench CRM.
1146
+ *
1147
+ * @module resources/requests
1064
1148
  */
1065
1149
 
1066
1150
  /**
1067
- * Service Requests resource
1151
+ * Requests resource for managing service requests.
1152
+ *
1153
+ * Service requests track customer service inquiries, including
1154
+ * contact information, service details, and status.
1068
1155
  *
1069
1156
  * @example
1070
1157
  * ```typescript
1071
1158
  * const workbench = new WorkbenchClient({ apiKey: 'wbk_live_xxx' });
1072
1159
  *
1073
- * // Create a service request
1074
- * const { data: request } = await workbench.serviceRequests.create({
1075
- * title: 'Leaky Faucet Repair',
1076
- * contact_name: 'Jane Smith',
1077
- * contact_email: 'jane@example.com',
1078
- * contact_phone: '+1-555-987-6543',
1079
- * address: '123 Main St, Anytown, USA',
1080
- * priority: 'high'
1160
+ * // Create a new request
1161
+ * const { data: request } = await workbench.requests.create({
1162
+ * title: 'AC Not Cooling',
1163
+ * contact_name: 'John Doe',
1164
+ * contact_email: 'john@example.com',
1165
+ * priority: 'urgent'
1081
1166
  * });
1082
- *
1083
- * // Update request status
1084
- * await workbench.serviceRequests.update(request.id, { status: 'scheduled' });
1085
1167
  * ```
1086
1168
  */
1087
- declare class ServiceRequestsResource {
1169
+ declare class RequestsResource {
1088
1170
  private readonly client;
1089
1171
  constructor(client: WorkbenchClient);
1090
1172
  /**
1091
- * List all service requests
1173
+ * List all requests
1092
1174
  *
1093
1175
  * Returns a paginated list of service requests for the authenticated business.
1094
1176
  *
1095
1177
  * @param options - List options (pagination, filtering, sorting)
1096
- * @returns Paginated list of service requests
1178
+ * @returns Paginated list of requests
1097
1179
  *
1098
1180
  * @example
1099
1181
  * ```typescript
1100
1182
  * // List new requests
1101
- * const { data, pagination } = await workbench.serviceRequests.list({
1183
+ * const { data, pagination } = await workbench.requests.list({
1102
1184
  * status: 'new',
1103
1185
  * priority: 'urgent',
1104
1186
  * per_page: 50
@@ -1107,27 +1189,27 @@ declare class ServiceRequestsResource {
1107
1189
  */
1108
1190
  list(options?: ListServiceRequestsOptions): Promise<ListResponse<ServiceRequest>>;
1109
1191
  /**
1110
- * Get a service request by ID
1192
+ * Get a request by ID
1111
1193
  *
1112
- * @param id - Service request UUID
1113
- * @returns Service request details
1194
+ * @param id - Request UUID
1195
+ * @returns Request details
1114
1196
  *
1115
1197
  * @example
1116
1198
  * ```typescript
1117
- * const { data: request } = await workbench.serviceRequests.get('request-uuid');
1199
+ * const { data: request } = await workbench.requests.get('request-uuid');
1118
1200
  * console.log(`Request: ${request.title} (${request.status})`);
1119
1201
  * ```
1120
1202
  */
1121
1203
  get(id: string): Promise<ApiResponse<ServiceRequest>>;
1122
1204
  /**
1123
- * Create a new service request
1205
+ * Create a new request
1124
1206
  *
1125
- * @param data - Service request data
1126
- * @returns Created service request
1207
+ * @param data - Request data
1208
+ * @returns Created request
1127
1209
  *
1128
1210
  * @example
1129
1211
  * ```typescript
1130
- * const { data: request } = await workbench.serviceRequests.create({
1212
+ * const { data: request } = await workbench.requests.create({
1131
1213
  * title: 'AC Not Cooling',
1132
1214
  * description: 'Air conditioner is running but not producing cold air',
1133
1215
  * contact_name: 'John Doe',
@@ -1143,16 +1225,16 @@ declare class ServiceRequestsResource {
1143
1225
  */
1144
1226
  create(data: CreateServiceRequestOptions): Promise<ApiResponse<ServiceRequest>>;
1145
1227
  /**
1146
- * Update a service request
1228
+ * Update a request
1147
1229
  *
1148
- * @param id - Service request UUID
1230
+ * @param id - Request UUID
1149
1231
  * @param data - Fields to update
1150
- * @returns Updated service request
1232
+ * @returns Updated request
1151
1233
  *
1152
1234
  * @example
1153
1235
  * ```typescript
1154
1236
  * // Assign to client and schedule
1155
- * const { data: request } = await workbench.serviceRequests.update('request-uuid', {
1237
+ * const { data: request } = await workbench.requests.update('request-uuid', {
1156
1238
  * client_id: 'client-uuid',
1157
1239
  * status: 'scheduled',
1158
1240
  * notes: 'Scheduled for Monday morning'
@@ -1161,15 +1243,15 @@ declare class ServiceRequestsResource {
1161
1243
  */
1162
1244
  update(id: string, data: UpdateServiceRequestOptions): Promise<ApiResponse<ServiceRequest>>;
1163
1245
  /**
1164
- * Delete a service request
1246
+ * Delete a request
1165
1247
  *
1166
- * Permanently deletes a service request. This action cannot be undone.
1248
+ * Permanently deletes a request. This action cannot be undone.
1167
1249
  *
1168
- * @param id - Service request UUID
1250
+ * @param id - Request UUID
1169
1251
  *
1170
1252
  * @example
1171
1253
  * ```typescript
1172
- * await workbench.serviceRequests.delete('request-uuid');
1254
+ * await workbench.requests.delete('request-uuid');
1173
1255
  * ```
1174
1256
  */
1175
1257
  delete(id: string): Promise<void>;
@@ -1396,6 +1478,156 @@ declare class WebhooksResource {
1396
1478
  listEventTypes(): Promise<ApiResponse<WebhookEventTypeInfo[]>>;
1397
1479
  }
1398
1480
 
1481
+ /**
1482
+ * Notifications Resource
1483
+ *
1484
+ * Provides methods for sending email notifications to clients and
1485
+ * business team members via the Workbench API.
1486
+ *
1487
+ * @module resources/notifications
1488
+ *
1489
+ * @example
1490
+ * // Send a welcome notification to a new client
1491
+ * await workbench.notifications.sendToClient({
1492
+ * clientId: 'client-uuid',
1493
+ * event: 'sdk_client_created',
1494
+ * templateData: { client_name: 'John Doe' }
1495
+ * });
1496
+ *
1497
+ * @example
1498
+ * // Notify business admins about a new request
1499
+ * await workbench.notifications.sendToTeam({
1500
+ * event: 'sdk_request_created',
1501
+ * roles: ['owner', 'admin'],
1502
+ * templateData: { request_title: 'AC Repair', client_name: 'John' }
1503
+ * });
1504
+ *
1505
+ * @example
1506
+ * // Send a custom notification
1507
+ * await workbench.notifications.sendCustom({
1508
+ * type: 'CLIENT',
1509
+ * clientId: 'client-uuid',
1510
+ * subject: 'Your appointment is confirmed!',
1511
+ * html: '<h1>Confirmed!</h1><p>See you tomorrow at 10am.</p>'
1512
+ * });
1513
+ */
1514
+
1515
+ /**
1516
+ * Notifications resource for sending email notifications via the SDK
1517
+ */
1518
+ declare class NotificationsResource {
1519
+ private readonly client;
1520
+ constructor(client: WorkbenchClient);
1521
+ /**
1522
+ * Send a notification to a specific client
1523
+ *
1524
+ * Sends an email notification to a client using a predefined template
1525
+ * or custom content. The client must have a valid email address.
1526
+ *
1527
+ * @param options - Notification options
1528
+ * @returns Notification result with delivery statistics
1529
+ *
1530
+ * @example
1531
+ * // Welcome a new client
1532
+ * const result = await workbench.notifications.sendToClient({
1533
+ * clientId: 'client-uuid',
1534
+ * event: 'sdk_client_created',
1535
+ * templateData: {
1536
+ * client_name: 'John Doe'
1537
+ * }
1538
+ * });
1539
+ * console.log(`Sent to ${result.data.sent_count} recipient(s)`);
1540
+ *
1541
+ * @example
1542
+ * // Notify client about a new quote with custom subject
1543
+ * const result = await workbench.notifications.sendToClient({
1544
+ * clientId: 'client-uuid',
1545
+ * event: 'sdk_quote_created',
1546
+ * templateData: {
1547
+ * client_name: 'John',
1548
+ * quote_number: 'Q-001',
1549
+ * quote_total: '$1,500.00'
1550
+ * },
1551
+ * subjectOverride: 'Your custom quote is ready!'
1552
+ * });
1553
+ */
1554
+ sendToClient(options: SendToClientOptions): Promise<ApiResponse<NotificationResult>>;
1555
+ /**
1556
+ * Send a notification to business team members
1557
+ *
1558
+ * Sends an email notification to team members, optionally filtered
1559
+ * by their role in the business.
1560
+ *
1561
+ * @param options - Notification options
1562
+ * @returns Notification result with delivery statistics
1563
+ *
1564
+ * @example
1565
+ * // Notify all team members about a new service request
1566
+ * const result = await workbench.notifications.sendToTeam({
1567
+ * event: 'sdk_request_created',
1568
+ * templateData: {
1569
+ * request_title: 'Emergency AC Repair',
1570
+ * client_name: 'John Doe',
1571
+ * request_description: 'AC not cooling, needs urgent attention'
1572
+ * }
1573
+ * });
1574
+ *
1575
+ * @example
1576
+ * // Notify only owners and admins
1577
+ * const result = await workbench.notifications.sendToTeam({
1578
+ * event: 'sdk_invoice_created',
1579
+ * roles: ['owner', 'admin'],
1580
+ * templateData: {
1581
+ * invoice_number: 'INV-001',
1582
+ * invoice_total: '$2,500.00',
1583
+ * client_name: 'Acme Corp'
1584
+ * }
1585
+ * });
1586
+ */
1587
+ sendToTeam(options: SendToTeamOptions): Promise<ApiResponse<NotificationResult>>;
1588
+ /**
1589
+ * Send a custom notification
1590
+ *
1591
+ * Sends a notification with fully custom subject and HTML content.
1592
+ * Can be sent to either a client or business team members.
1593
+ *
1594
+ * @param options - Custom notification options
1595
+ * @returns Notification result with delivery statistics
1596
+ *
1597
+ * @example
1598
+ * // Send custom appointment confirmation to client
1599
+ * const result = await workbench.notifications.sendCustom({
1600
+ * type: 'CLIENT',
1601
+ * clientId: 'client-uuid',
1602
+ * subject: 'Your appointment is confirmed for tomorrow!',
1603
+ * html: `
1604
+ * <h1>Appointment Confirmed</h1>
1605
+ * <p>Hi John,</p>
1606
+ * <p>Your appointment has been confirmed:</p>
1607
+ * <ul>
1608
+ * <li><strong>Date:</strong> January 23, 2026</li>
1609
+ * <li><strong>Time:</strong> 10:00 AM</li>
1610
+ * <li><strong>Service:</strong> AC Maintenance</li>
1611
+ * </ul>
1612
+ * <p>See you tomorrow!</p>
1613
+ * `
1614
+ * });
1615
+ *
1616
+ * @example
1617
+ * // Send custom alert to admins
1618
+ * const result = await workbench.notifications.sendCustom({
1619
+ * type: 'BUSINESS',
1620
+ * roles: ['owner', 'admin'],
1621
+ * subject: 'High-value quote approved!',
1622
+ * html: '<p>Quote Q-001 for $10,000 has been approved by Acme Corp.</p>',
1623
+ * templateData: {
1624
+ * quote_number: 'Q-001'
1625
+ * }
1626
+ * });
1627
+ */
1628
+ sendCustom(options: SendCustomNotificationOptions): Promise<ApiResponse<NotificationResult>>;
1629
+ }
1630
+
1399
1631
  /**
1400
1632
  * @file client.ts
1401
1633
  * @description Main Workbench API client class
@@ -1480,10 +1712,12 @@ declare class WorkbenchClient {
1480
1712
  readonly quotes: QuotesResource;
1481
1713
  /** Jobs resource */
1482
1714
  readonly jobs: JobsResource;
1483
- /** Service requests resource */
1484
- readonly serviceRequests: ServiceRequestsResource;
1715
+ /** Requests resource */
1716
+ readonly requests: RequestsResource;
1485
1717
  /** Webhooks resource */
1486
1718
  readonly webhooks: WebhooksResource;
1719
+ /** Notifications resource */
1720
+ readonly notifications: NotificationsResource;
1487
1721
  /**
1488
1722
  * Create a new Workbench client
1489
1723
  *
@@ -1665,4 +1899,4 @@ declare function constructWebhookEvent<T = Record<string, unknown>>(payload: str
1665
1899
  timestamp: string;
1666
1900
  };
1667
1901
 
1668
- 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 };
1902
+ export { type ApiError, type ApiResponse, type BusinessUserRole, 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 NotificationEvent, type NotificationResult, type NotificationType, NotificationsResource, type Pagination, type Quote, type QuoteItem, type QuoteStatus, QuotesResource, type RequestOptions, RequestsResource, type ResponseMeta, type SendCustomNotificationOptions, type SendToClientOptions, type SendToTeamOptions, type ServiceRequest, type ServiceRequestPriority, type ServiceRequestStatus, 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 };