@sendmailos/sdk 1.2.0 → 1.2.1

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.ts CHANGED
@@ -26,6 +26,17 @@ interface SendEmailRequest {
26
26
  variables?: Record<string, unknown>;
27
27
  /** Email type: "transactional" (default) or "marketing" */
28
28
  type?: 'transactional' | 'marketing';
29
+ /**
30
+ * Workspace ID (for agency accounts) - use this OR domain
31
+ * @note Agency accounts MUST specify either workspaceId or domain
32
+ */
33
+ workspaceId?: string;
34
+ /**
35
+ * Client domain (for agency accounts) - alternative to workspaceId
36
+ * Used to identify which workspace/client this email belongs to
37
+ * @note Agency accounts MUST specify either workspaceId or domain
38
+ */
39
+ domain?: string;
29
40
  }
30
41
  interface SendEmailResponse {
31
42
  success: boolean;
@@ -42,6 +53,7 @@ interface Subscriber {
42
53
  tags?: string[];
43
54
  source: string;
44
55
  createdAt: string;
56
+ workspaceId?: string;
45
57
  primaryDomain?: {
46
58
  id: string;
47
59
  domainName: string;
@@ -58,6 +70,10 @@ interface CreateSubscriberRequest {
58
70
  tags?: string[];
59
71
  /** Associate with a specific domain */
60
72
  domainId?: string;
73
+ /** Workspace ID (for agency accounts) - use this OR domain */
74
+ workspaceId?: string;
75
+ /** Client domain (for agency accounts) - alternative to workspaceId */
76
+ domain?: string;
61
77
  }
62
78
  interface CreateSubscriberResponse {
63
79
  success: boolean;
@@ -68,6 +84,10 @@ interface ListSubscribersRequest {
68
84
  limit?: number;
69
85
  /** Pagination offset */
70
86
  offset?: number;
87
+ /** Filter by workspace ID (for agency accounts) - use this OR domain */
88
+ workspaceId?: string;
89
+ /** Filter by client domain (for agency accounts) - alternative to workspaceId */
90
+ domain?: string;
71
91
  }
72
92
  interface ListSubscribersResponse {
73
93
  success: boolean;
@@ -93,6 +113,12 @@ interface SendCampaignRequest {
93
113
  tags?: string[];
94
114
  /** Global template variables */
95
115
  variables?: Record<string, unknown>;
116
+ /** Workspace ID (for agency accounts) - use this OR domain */
117
+ workspaceId?: string;
118
+ /** Client domain (for agency accounts) - alternative to workspaceId */
119
+ domain?: string;
120
+ /** Filter subscribers by source domains - only send to subscribers who came from these domains */
121
+ sourceDomains?: string[];
96
122
  }
97
123
  interface SendCampaignResponse {
98
124
  success: boolean;
@@ -106,6 +132,7 @@ interface Domain {
106
132
  dkimTokens: string[];
107
133
  createdAt: string;
108
134
  verifiedAt?: string;
135
+ workspaceId?: string;
109
136
  dnsRecords?: DnsRecord[];
110
137
  }
111
138
  interface DnsRecord {
@@ -125,16 +152,19 @@ interface ListDomainsResponse {
125
152
  success: boolean;
126
153
  domains: Domain[];
127
154
  }
128
- type WebhookEventType = 'email.sent' | 'email.delivered' | 'email.opened' | 'email.clicked' | 'email.bounced' | 'email.complained';
155
+ type WebhookEventType = 'email.sent' | 'email.delivered' | 'email.opened' | 'email.clicked' | 'email.bounced' | 'email.complained' | 'subscriber.created' | 'subscriber.updated' | 'subscriber.unsubscribed' | 'campaign.sent' | 'workflow.started' | 'workflow.completed';
129
156
  interface WebhookEvent {
130
157
  id: string;
131
158
  type: WebhookEventType;
132
159
  createdAt: string;
133
160
  data: {
134
- emailId: string;
135
- messageId: string;
136
- recipient: string;
161
+ emailId?: string;
162
+ messageId?: string;
163
+ recipient?: string;
164
+ subscriberId?: string;
137
165
  campaignId?: string;
166
+ workflowId?: string;
167
+ domainId?: string;
138
168
  timestamp: string;
139
169
  metadata?: Record<string, unknown>;
140
170
  };
@@ -144,15 +174,201 @@ interface CreateWebhookRequest {
144
174
  url: string;
145
175
  /** Events to subscribe to */
146
176
  events: WebhookEventType[];
147
- /** Signing secret for webhook verification */
177
+ /** Signing secret for webhook verification (auto-generated if not provided) */
148
178
  secret?: string;
179
+ /** Filter webhook events by domain */
180
+ domain?: string;
181
+ /** Filter webhook events by workspace ID */
182
+ workspace_id?: string;
183
+ }
184
+ interface UpdateWebhookRequest {
185
+ /** New webhook URL */
186
+ url?: string;
187
+ /** New events to subscribe to */
188
+ events?: WebhookEventType[];
189
+ /** Enable or disable webhook */
190
+ active?: boolean;
149
191
  }
150
192
  interface Webhook {
151
193
  id: string;
152
194
  url: string;
153
195
  events: WebhookEventType[];
196
+ secret: string;
154
197
  active: boolean;
198
+ domainId?: string;
199
+ domainName?: string;
200
+ workspaceId?: string;
155
201
  createdAt: string;
202
+ updatedAt?: string;
203
+ }
204
+ interface WebhookDelivery {
205
+ id: string;
206
+ eventType: string;
207
+ statusCode: number;
208
+ responseTimeMs: number;
209
+ error?: string;
210
+ deliveredAt: string;
211
+ }
212
+ interface WebhookStats {
213
+ totalDeliveries: number;
214
+ avgResponseTimeMs: number;
215
+ successCount: number;
216
+ failureCount: number;
217
+ }
218
+ interface ListWebhooksResponse {
219
+ success: boolean;
220
+ webhooks: Array<Webhook & {
221
+ lastTriggeredAt?: string;
222
+ lastStatusCode?: number;
223
+ totalDeliveries: number;
224
+ }>;
225
+ }
226
+ interface GetWebhookResponse {
227
+ success: boolean;
228
+ webhook: Webhook & {
229
+ recentDeliveries: WebhookDelivery[];
230
+ stats: WebhookStats;
231
+ };
232
+ }
233
+ interface TestWebhookResponse {
234
+ success: boolean;
235
+ test: {
236
+ sent: boolean;
237
+ statusCode: number;
238
+ responseTimeMs: number;
239
+ error?: string;
240
+ };
241
+ }
242
+ type WorkflowStatus = 'draft' | 'active' | 'paused';
243
+ type WorkflowTriggerType = 'api' | 'subscriber_created' | 'subscriber_tagged' | 'form_submitted' | 'email_opened' | 'email_clicked' | 'custom_event';
244
+ interface WorkflowTrigger {
245
+ /** Trigger type */
246
+ type: WorkflowTriggerType;
247
+ /** Event name (for custom_event type) */
248
+ event?: string;
249
+ /** Additional conditions */
250
+ conditions?: Record<string, unknown>;
251
+ }
252
+ interface WorkflowNode {
253
+ /** Unique node ID */
254
+ id: string;
255
+ /** Node type */
256
+ type: 'trigger' | 'email' | 'delay' | 'condition' | 'tag' | 'http' | 'wait_for_event' | 'unsubscribe' | 'jump' | 'exit';
257
+ /** Node position (for UI) */
258
+ position?: {
259
+ x: number;
260
+ y: number;
261
+ };
262
+ /** Node-specific data */
263
+ data: Record<string, unknown>;
264
+ }
265
+ interface WorkflowEdge {
266
+ /** Unique edge ID */
267
+ id: string;
268
+ /** Source node ID */
269
+ source: string;
270
+ /** Target node ID */
271
+ target: string;
272
+ /** Source handle (for branching) */
273
+ sourceHandle?: string;
274
+ /** Edge label */
275
+ label?: string;
276
+ }
277
+ interface WorkflowStats {
278
+ totalRuns: number;
279
+ activeRuns?: number;
280
+ completedRuns: number;
281
+ }
282
+ interface Workflow {
283
+ id: string;
284
+ name: string;
285
+ status: WorkflowStatus;
286
+ domainId?: string;
287
+ domainName?: string;
288
+ workspaceId?: string;
289
+ nodes?: WorkflowNode[];
290
+ edges?: WorkflowEdge[];
291
+ triggerConfig?: WorkflowTrigger;
292
+ createdAt: string;
293
+ updatedAt: string;
294
+ stats?: WorkflowStats;
295
+ }
296
+ interface CreateWorkflowRequest {
297
+ /** Workflow name */
298
+ name: string;
299
+ /** Client domain (for multi-brand) - auto-detects workspace */
300
+ domain?: string;
301
+ /** Workspace ID (alternative to domain) */
302
+ workspace_id?: string;
303
+ /** Trigger configuration */
304
+ trigger?: WorkflowTrigger;
305
+ }
306
+ interface CreateWorkflowResponse {
307
+ success: boolean;
308
+ workflow: {
309
+ id: string;
310
+ name: string;
311
+ status: WorkflowStatus;
312
+ createdAt: string;
313
+ };
314
+ }
315
+ interface UpdateWorkflowRequest {
316
+ /** Workflow name */
317
+ name?: string;
318
+ /** Workflow nodes (the steps) */
319
+ nodes?: WorkflowNode[];
320
+ /** Workflow edges (connections between nodes) */
321
+ edges?: WorkflowEdge[];
322
+ /** Trigger configuration */
323
+ trigger?: WorkflowTrigger;
324
+ /** Domain ID */
325
+ domain_id?: string;
326
+ }
327
+ interface UpdateWorkflowResponse {
328
+ success: boolean;
329
+ workflow: {
330
+ id: string;
331
+ name: string;
332
+ status: WorkflowStatus;
333
+ nodes: WorkflowNode[];
334
+ edges: WorkflowEdge[];
335
+ updatedAt: string;
336
+ };
337
+ }
338
+ interface ListWorkflowsRequest {
339
+ /** Filter by client domain */
340
+ domain?: string;
341
+ /** Filter by workspace ID */
342
+ workspace_id?: string;
343
+ }
344
+ interface ListWorkflowsResponse {
345
+ success: boolean;
346
+ workflows: Workflow[];
347
+ }
348
+ interface GetWorkflowResponse {
349
+ success: boolean;
350
+ workflow: Workflow;
351
+ }
352
+ interface TriggerWorkflowRequest {
353
+ /** Subscriber email */
354
+ email: string;
355
+ /** Subscriber ID (if known) */
356
+ subscriber_id?: string;
357
+ /** Custom data to pass to the workflow */
358
+ data?: Record<string, unknown>;
359
+ }
360
+ interface TriggerWorkflowResponse {
361
+ success: boolean;
362
+ execution_id: string;
363
+ subscriber_id: string;
364
+ }
365
+ interface WorkflowStatusResponse {
366
+ success: boolean;
367
+ workflow: {
368
+ id: string;
369
+ name: string;
370
+ status: WorkflowStatus;
371
+ };
156
372
  }
157
373
  interface ApiError {
158
374
  success: false;
@@ -172,6 +388,7 @@ declare class EmailsResource {
172
388
  *
173
389
  * @example
174
390
  * ```ts
391
+ * // Business account (single-tenant)
175
392
  * const result = await client.emails.send({
176
393
  * to: 'user@example.com',
177
394
  * fromName: 'Your Company',
@@ -179,6 +396,16 @@ declare class EmailsResource {
179
396
  * subject: 'Welcome!',
180
397
  * html: '<h1>Hello!</h1>'
181
398
  * });
399
+ *
400
+ * // Agency account (multi-tenant) - identify client by domain
401
+ * const result = await agencyClient.emails.send({
402
+ * to: 'customer@example.com',
403
+ * fromName: 'Pizza Palace',
404
+ * fromEmail: 'hello@pizzapalace.com',
405
+ * subject: 'Your order is ready!',
406
+ * html: '<h1>Order Ready!</h1>',
407
+ * domain: 'pizzapalace.com' // Required for agency accounts
408
+ * });
182
409
  * ```
183
410
  */
184
411
  send(params: SendEmailRequest): Promise<SendEmailResponse>;
@@ -201,6 +428,10 @@ declare class EmailsResource {
201
428
  fromEmail?: string;
202
429
  subject?: string;
203
430
  variables?: Record<string, unknown>;
431
+ /** Workspace ID (for agency accounts) */
432
+ workspaceId?: string;
433
+ /** Client domain (for agency accounts) */
434
+ domain?: string;
204
435
  }): Promise<SendEmailResponse>;
205
436
  }
206
437
 
@@ -215,11 +446,20 @@ declare class SubscribersResource {
215
446
  *
216
447
  * @example
217
448
  * ```ts
449
+ * // Business account
218
450
  * const { subscriber } = await client.subscribers.create({
219
451
  * email: 'user@example.com',
220
452
  * firstName: 'John',
221
453
  * tags: ['newsletter', 'premium']
222
454
  * });
455
+ *
456
+ * // Agency account - subscriber tracked to client domain
457
+ * const { subscriber } = await agencyClient.subscribers.create({
458
+ * email: 'customer@example.com',
459
+ * firstName: 'Jane',
460
+ * domain: 'pizzapalace.com', // Required for agency accounts
461
+ * tags: ['loyalty-member']
462
+ * });
223
463
  * ```
224
464
  */
225
465
  create(params: CreateSubscriberRequest): Promise<CreateSubscriberResponse>;
@@ -277,6 +517,7 @@ declare class CampaignsResource {
277
517
  *
278
518
  * @example
279
519
  * ```ts
520
+ * // Business account
280
521
  * const result = await client.campaigns.send({
281
522
  * name: 'January Newsletter',
282
523
  * subject: 'What\'s new this month',
@@ -285,6 +526,17 @@ declare class CampaignsResource {
285
526
  * html: '<h1>Hello {{first_name}}!</h1>',
286
527
  * tags: ['newsletter', 'active']
287
528
  * });
529
+ *
530
+ * // Agency account - send to specific client's subscribers
531
+ * const result = await agencyClient.campaigns.send({
532
+ * name: 'Pizza Promo',
533
+ * subject: 'New menu items!',
534
+ * fromName: 'Pizza Palace',
535
+ * fromEmail: 'promo@pizzapalace.com',
536
+ * html: '<h1>Check out our new menu!</h1>',
537
+ * domain: 'pizzapalace.com', // Filter to this client's subscribers
538
+ * sourceDomains: ['pizzapalace.com'] // Only subscribers who signed up on this domain
539
+ * });
288
540
  * ```
289
541
  */
290
542
  send(params: SendCampaignRequest): Promise<SendCampaignResponse>;
@@ -299,6 +551,12 @@ declare class CampaignsResource {
299
551
  fromEmail: string;
300
552
  tags?: string[];
301
553
  variables?: Record<string, unknown>;
554
+ /** Workspace ID (for agency accounts) */
555
+ workspaceId?: string;
556
+ /** Client domain (for agency accounts) */
557
+ domain?: string;
558
+ /** Filter by source domains */
559
+ sourceDomains?: string[];
302
560
  }): Promise<SendCampaignResponse>;
303
561
  }
304
562
 
@@ -361,7 +619,6 @@ interface Organization {
361
619
  onboarding_completed: boolean;
362
620
  onboarding_step: string;
363
621
  created_at: string;
364
- free_credits_limit?: number;
365
622
  }
366
623
  interface UpdateOrganizationRequest {
367
624
  name?: string;
@@ -458,6 +715,69 @@ interface CreateWorkspaceRequest {
458
715
  /** Custom settings */
459
716
  settings?: Record<string, unknown>;
460
717
  }
718
+ interface ProvisionWorkspaceRequest {
719
+ /** Client/workspace name */
720
+ name: string;
721
+ /** Client website URL - used for matching existing workspace */
722
+ website?: string;
723
+ /** Client email - used for matching existing workspace */
724
+ client_email?: string;
725
+ /** Industry for pre-built templates (used if creating new) */
726
+ industry?: Industry;
727
+ /** Logo URL */
728
+ logo_url?: string;
729
+ /** Allow client to view reports (default: true) */
730
+ client_can_view_reports?: boolean;
731
+ /** Import industry templates automatically (default: true) */
732
+ import_templates?: boolean;
733
+ /** Generate a workspace-scoped API key */
734
+ generate_api_key?: boolean;
735
+ /** Allowed origins for the generated API key */
736
+ allowed_origins?: string[];
737
+ /** Custom settings */
738
+ settings?: Record<string, unknown>;
739
+ }
740
+ interface ProvisionWorkspaceResponse {
741
+ workspace: Workspace;
742
+ /** Whether this is a newly created workspace */
743
+ is_new: boolean;
744
+ /** Generated API key (only if generate_api_key was true) */
745
+ api_key?: string;
746
+ /** Human-readable message */
747
+ message: string;
748
+ }
749
+ interface OnboardClientRequest {
750
+ /** Client domain (e.g., "pizzapalace.com" or "https://pizzapalace.com") */
751
+ domain: string;
752
+ /** Client name (optional - derived from domain if not provided) */
753
+ name?: string;
754
+ /** Industry for templates (default: "restaurants") */
755
+ industry?: Industry;
756
+ /** Client email for notifications */
757
+ client_email?: string;
758
+ }
759
+ interface OnboardClientResponse {
760
+ /** Workspace token - USE THIS FOR ALL API CALLS */
761
+ token: string;
762
+ /** Workspace ID */
763
+ workspace_id: string;
764
+ /** Workspace name */
765
+ workspace_name: string;
766
+ /** Normalized domain */
767
+ domain: string;
768
+ /** Domain verification status */
769
+ domain_status: string;
770
+ /** DNS records to add for domain verification */
771
+ dns_records: Array<{
772
+ type: string;
773
+ name: string;
774
+ value: string;
775
+ }>;
776
+ /** Whether workspace was newly created */
777
+ is_new: boolean;
778
+ /** Human-readable message */
779
+ message: string;
780
+ }
461
781
  interface UpdateWorkspaceRequest {
462
782
  name?: string;
463
783
  industry?: Industry;
@@ -555,6 +875,323 @@ declare class WorkspacesResource {
555
875
  * ```
556
876
  */
557
877
  inviteClient(workspaceId: string, email: string): Promise<Workspace>;
878
+ /**
879
+ * Smart workspace provisioning - finds existing or creates new
880
+ *
881
+ * This is the recommended method for agency client onboarding.
882
+ * It will:
883
+ * 1. Search for existing workspace by website URL or client_email
884
+ * 2. Return existing workspace if found
885
+ * 3. Create new workspace with industry templates if not found
886
+ * 4. Optionally generate a workspace-scoped API key
887
+ *
888
+ * @note Only available for agency accounts
889
+ *
890
+ * @example
891
+ * ```ts
892
+ * // Auto-provision workspace for a new client
893
+ * const result = await client.workspaces.provision({
894
+ * name: 'Pizza Palace',
895
+ * website: 'https://pizzapalace.com',
896
+ * client_email: 'owner@pizzapalace.com',
897
+ * industry: 'restaurants',
898
+ * generate_api_key: true
899
+ * });
900
+ *
901
+ * if (result.is_new) {
902
+ * console.log('Created new workspace:', result.workspace.id);
903
+ * console.log('API Key:', result.api_key);
904
+ * } else {
905
+ * console.log('Found existing workspace:', result.workspace.id);
906
+ * }
907
+ * ```
908
+ *
909
+ * @example
910
+ * ```ts
911
+ * // Idempotent client setup - safe to call multiple times
912
+ * const { workspace, is_new } = await client.workspaces.provision({
913
+ * name: 'Client Name',
914
+ * website: 'https://client.com',
915
+ * industry: 'ecommerce'
916
+ * });
917
+ * // Always returns the same workspace for the same website
918
+ * ```
919
+ */
920
+ provision(request: ProvisionWorkspaceRequest): Promise<ProvisionWorkspaceResponse>;
921
+ /**
922
+ * Alias for provision() - find or create workspace
923
+ * @see provision
924
+ */
925
+ findOrCreate(request: ProvisionWorkspaceRequest): Promise<ProvisionWorkspaceResponse>;
926
+ /**
927
+ * Complete client onboarding in ONE call (Agency only)
928
+ *
929
+ * This is the simplest way to onboard a new client:
930
+ * 1. Creates or finds workspace by domain
931
+ * 2. Registers domain for email verification
932
+ * 3. Generates workspace token
933
+ * 4. Returns DNS records + token
934
+ *
935
+ * After this, use the returned `token` for all API calls.
936
+ *
937
+ * @example
938
+ * ```ts
939
+ * // Your SaaS onboards a new restaurant
940
+ * const result = await agency.workspaces.onboard({
941
+ * domain: 'pizzapalace.com',
942
+ * industry: 'restaurants'
943
+ * });
944
+ *
945
+ * // Save this token - it's all you need
946
+ * saveToDatabase(restaurantId, result.token);
947
+ *
948
+ * // Show DNS records to restaurant owner
949
+ * console.log('Add these DNS records:', result.dns_records);
950
+ *
951
+ * // Later, use the token directly
952
+ * const restaurant = new SendMailOS(result.token);
953
+ * await restaurant.emails.send({ ... });
954
+ * ```
955
+ */
956
+ onboard(request: OnboardClientRequest): Promise<OnboardClientResponse>;
957
+ }
958
+
959
+ /**
960
+ * Workflows resource for managing email automation workflows
961
+ */
962
+ declare class WorkflowsResource {
963
+ private request;
964
+ constructor(request: <T>(endpoint: string, options?: RequestInit) => Promise<T>);
965
+ /**
966
+ * Create a new workflow
967
+ *
968
+ * @example
969
+ * ```ts
970
+ * // Create workflow for a specific client (multi-brand)
971
+ * const result = await platform.workflows.create({
972
+ * name: 'Welcome Sequence',
973
+ * domain: 'pizzapalace.com',
974
+ * trigger: { type: 'subscriber_created' }
975
+ * });
976
+ *
977
+ * // Create workflow (single brand)
978
+ * const result = await client.workflows.create({
979
+ * name: 'Onboarding Flow',
980
+ * trigger: { type: 'api' }
981
+ * });
982
+ * ```
983
+ */
984
+ create(params: CreateWorkflowRequest): Promise<CreateWorkflowResponse>;
985
+ /**
986
+ * List all workflows
987
+ *
988
+ * @example
989
+ * ```ts
990
+ * // List all workflows
991
+ * const { workflows } = await client.workflows.list();
992
+ *
993
+ * // List workflows for a specific client (multi-brand)
994
+ * const { workflows } = await platform.workflows.list({ domain: 'pizzapalace.com' });
995
+ * ```
996
+ */
997
+ list(params?: ListWorkflowsRequest): Promise<ListWorkflowsResponse>;
998
+ /**
999
+ * Get a workflow by ID (includes nodes and edges)
1000
+ *
1001
+ * @example
1002
+ * ```ts
1003
+ * const { workflow } = await client.workflows.get('workflow-uuid');
1004
+ * console.log(workflow.nodes); // The workflow steps
1005
+ * console.log(workflow.edges); // Connections between steps
1006
+ * ```
1007
+ */
1008
+ get(workflowId: string): Promise<GetWorkflowResponse>;
1009
+ /**
1010
+ * Update a workflow (name, nodes, edges, trigger)
1011
+ *
1012
+ * @example
1013
+ * ```ts
1014
+ * // Update workflow name
1015
+ * await client.workflows.update('workflow-uuid', { name: 'New Name' });
1016
+ *
1017
+ * // Update workflow steps
1018
+ * await client.workflows.update('workflow-uuid', {
1019
+ * nodes: [
1020
+ * { id: '1', type: 'trigger', data: { triggerType: 'api' } },
1021
+ * { id: '2', type: 'email', data: { templateId: 'tmpl_xxx', subject: 'Welcome!' } },
1022
+ * { id: '3', type: 'delay', data: { duration: 3, unit: 'days' } }
1023
+ * ],
1024
+ * edges: [
1025
+ * { id: 'e1', source: '1', target: '2' },
1026
+ * { id: 'e2', source: '2', target: '3' }
1027
+ * ]
1028
+ * });
1029
+ * ```
1030
+ */
1031
+ update(workflowId: string, params: UpdateWorkflowRequest): Promise<UpdateWorkflowResponse>;
1032
+ /**
1033
+ * Delete a workflow
1034
+ */
1035
+ delete(workflowId: string): Promise<{
1036
+ success: boolean;
1037
+ message: string;
1038
+ }>;
1039
+ /**
1040
+ * Activate a workflow (start accepting triggers)
1041
+ *
1042
+ * @example
1043
+ * ```ts
1044
+ * await client.workflows.activate('workflow-uuid');
1045
+ * // Workflow is now active and will process triggers
1046
+ * ```
1047
+ */
1048
+ activate(workflowId: string): Promise<WorkflowStatusResponse>;
1049
+ /**
1050
+ * Pause a workflow (stop accepting new triggers)
1051
+ *
1052
+ * @example
1053
+ * ```ts
1054
+ * await client.workflows.pause('workflow-uuid');
1055
+ * // Workflow is paused - existing executions continue, but no new ones start
1056
+ * ```
1057
+ */
1058
+ pause(workflowId: string): Promise<WorkflowStatusResponse>;
1059
+ /**
1060
+ * Trigger a workflow for a subscriber
1061
+ *
1062
+ * @example
1063
+ * ```ts
1064
+ * // Trigger when a customer signs up
1065
+ * const result = await platform.workflows.trigger('workflow-uuid', {
1066
+ * email: 'customer@example.com',
1067
+ * data: {
1068
+ * firstName: 'John',
1069
+ * restaurantName: 'Pizza Palace',
1070
+ * signupSource: 'website'
1071
+ * }
1072
+ * });
1073
+ *
1074
+ * console.log(result.execution_id); // Track this execution
1075
+ * ```
1076
+ */
1077
+ trigger(workflowId: string, params: TriggerWorkflowRequest): Promise<TriggerWorkflowResponse>;
1078
+ /**
1079
+ * Send a custom event to resume waiting workflows
1080
+ *
1081
+ * Use this when you have workflows waiting for specific events (e.g., "purchase_completed").
1082
+ * All workflows waiting for this event for the given subscriber will resume.
1083
+ *
1084
+ * @example
1085
+ * ```ts
1086
+ * // When a customer completes a purchase
1087
+ * await platform.workflows.sendEvent({
1088
+ * event: 'purchase_completed',
1089
+ * email: 'customer@example.com',
1090
+ * data: { orderTotal: 45.99, orderId: 'ORD-123' }
1091
+ * });
1092
+ *
1093
+ * // Any workflow with a "wait_for_event: purchase_completed" node will resume
1094
+ * ```
1095
+ */
1096
+ sendEvent(params: {
1097
+ event: string;
1098
+ email: string;
1099
+ data?: Record<string, unknown>;
1100
+ }): Promise<{
1101
+ success: boolean;
1102
+ processed: number;
1103
+ }>;
1104
+ }
1105
+
1106
+ /**
1107
+ * Webhooks resource for managing webhook endpoints
1108
+ */
1109
+ declare class WebhooksResource {
1110
+ private request;
1111
+ constructor(request: <T>(endpoint: string, options?: RequestInit) => Promise<T>);
1112
+ /**
1113
+ * Create a new webhook endpoint
1114
+ *
1115
+ * @example
1116
+ * ```ts
1117
+ * const webhook = await client.webhooks.create({
1118
+ * url: 'https://yourserver.com/webhooks',
1119
+ * events: ['email.sent', 'email.delivered', 'email.opened'],
1120
+ * secret: 'your-secret-key' // Optional, auto-generated if not provided
1121
+ * });
1122
+ *
1123
+ * console.log('Webhook secret:', webhook.secret);
1124
+ * ```
1125
+ */
1126
+ create(params: CreateWebhookRequest): Promise<{
1127
+ success: boolean;
1128
+ webhook: Webhook;
1129
+ }>;
1130
+ /**
1131
+ * List all webhooks
1132
+ */
1133
+ list(): Promise<ListWebhooksResponse>;
1134
+ /**
1135
+ * Get a webhook by ID with recent delivery history
1136
+ */
1137
+ get(webhookId: string): Promise<GetWebhookResponse>;
1138
+ /**
1139
+ * Update a webhook
1140
+ *
1141
+ * @example
1142
+ * ```ts
1143
+ * // Update webhook URL
1144
+ * await client.webhooks.update('webhook-id', {
1145
+ * url: 'https://newserver.com/webhooks'
1146
+ * });
1147
+ *
1148
+ * // Add new events
1149
+ * await client.webhooks.update('webhook-id', {
1150
+ * events: ['email.sent', 'email.delivered', 'email.bounced']
1151
+ * });
1152
+ *
1153
+ * // Disable webhook
1154
+ * await client.webhooks.update('webhook-id', { active: false });
1155
+ * ```
1156
+ */
1157
+ update(webhookId: string, params: UpdateWebhookRequest): Promise<{
1158
+ success: boolean;
1159
+ webhook: Webhook;
1160
+ }>;
1161
+ /**
1162
+ * Delete a webhook
1163
+ */
1164
+ delete(webhookId: string): Promise<{
1165
+ success: boolean;
1166
+ }>;
1167
+ /**
1168
+ * Test a webhook by sending a test event
1169
+ *
1170
+ * @example
1171
+ * ```ts
1172
+ * const result = await client.webhooks.test('webhook-id');
1173
+ * if (result.test.sent) {
1174
+ * console.log(`Test delivered in ${result.test.responseTimeMs}ms`);
1175
+ * } else {
1176
+ * console.log('Test failed:', result.test.error);
1177
+ * }
1178
+ * ```
1179
+ */
1180
+ test(webhookId: string): Promise<TestWebhookResponse>;
1181
+ /**
1182
+ * Enable a webhook
1183
+ */
1184
+ enable(webhookId: string): Promise<{
1185
+ success: boolean;
1186
+ webhook: Webhook;
1187
+ }>;
1188
+ /**
1189
+ * Disable a webhook
1190
+ */
1191
+ disable(webhookId: string): Promise<{
1192
+ success: boolean;
1193
+ webhook: Webhook;
1194
+ }>;
558
1195
  }
559
1196
 
560
1197
  /**
@@ -597,6 +1234,10 @@ declare class SendMailOS {
597
1234
  readonly organization: OrganizationResource;
598
1235
  /** Workspace management (for agencies) */
599
1236
  readonly workspaces: WorkspacesResource;
1237
+ /** Workflow automation */
1238
+ readonly workflows: WorkflowsResource;
1239
+ /** Webhook management */
1240
+ readonly webhooks: WebhooksResource;
600
1241
  constructor(apiKey: string, options?: SendMailOSOptions);
601
1242
  /**
602
1243
  * Make an authenticated request to the API
@@ -777,4 +1418,4 @@ declare function constructWebhookEvent<T = unknown>(payload: string, headers: {
777
1418
  timestamp: string;
778
1419
  }, secret: string): T;
779
1420
 
780
- export { type ApiError, AuthenticationError, type CreateDomainRequest, type CreateDomainResponse, type CreateSubscriberRequest, type CreateSubscriberResponse, type CreateWebhookRequest, type CreateWorkspaceRequest, type DnsRecord, type Domain, INDUSTRIES, type IdentifyTraits, type Industry, type ListDomainsResponse, type ListSubscribersRequest, type ListSubscribersResponse, NotFoundError, type Organization, type OrganizationType, Pixel, type PixelConfig, type PixelOptions, RateLimitError, type SendCampaignRequest, type SendCampaignResponse, type SendEmailRequest, type SendEmailResponse, SendMailOS, SendMailOSError, type SendMailOSOptions, SendmailPixel, type Subscriber, type TrackEventProperties, type TrackProps, type UpdateOrganizationRequest, type UpdateWorkspaceRequest, ValidationError, type VerifyWebhookParams, type Webhook, type WebhookEvent, type WebhookEventType, type Workspace, type WorkspaceStats, constructWebhookEvent, createGlobalPixel, SendMailOS as default, verifyWebhookSignature, verifyWebhookSignatureAsync };
1421
+ export { type ApiError, AuthenticationError, type CreateDomainRequest, type CreateDomainResponse, type CreateSubscriberRequest, type CreateSubscriberResponse, type CreateWebhookRequest, type CreateWorkflowRequest, type CreateWorkflowResponse, type CreateWorkspaceRequest, type DnsRecord, type Domain, type GetWorkflowResponse, INDUSTRIES, type IdentifyTraits, type Industry, type ListDomainsResponse, type ListSubscribersRequest, type ListSubscribersResponse, type ListWorkflowsRequest, type ListWorkflowsResponse, NotFoundError, type OnboardClientRequest, type OnboardClientResponse, type Organization, type OrganizationType, Pixel, type PixelConfig, type PixelOptions, type ProvisionWorkspaceRequest, type ProvisionWorkspaceResponse, RateLimitError, type SendCampaignRequest, type SendCampaignResponse, type SendEmailRequest, type SendEmailResponse, SendMailOS, SendMailOSError, type SendMailOSOptions, SendmailPixel, type Subscriber, type TrackEventProperties, type TrackProps, type TriggerWorkflowRequest, type TriggerWorkflowResponse, type UpdateOrganizationRequest, type UpdateWorkflowRequest, type UpdateWorkflowResponse, type UpdateWorkspaceRequest, ValidationError, type VerifyWebhookParams, type Webhook, type WebhookEvent, type WebhookEventType, type Workflow, type WorkflowEdge, type WorkflowNode, type WorkflowStats, type WorkflowStatus, type WorkflowStatusResponse, type WorkflowTrigger, type WorkflowTriggerType, type Workspace, type WorkspaceStats, constructWebhookEvent, createGlobalPixel, SendMailOS as default, verifyWebhookSignature, verifyWebhookSignatureAsync };