@sendmailos/sdk 1.2.1 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -33,11 +33,13 @@ await client.emails.send({
33
33
 
34
34
  - **Type-safe**: Full TypeScript support with exported types
35
35
  - **Lightweight**: Zero dependencies for core SDK
36
+ - **Attachments**: Send files via Base64 or URL (auto-fetched)
37
+ - **Email Automation**: Build workflows with triggers, delays, conditions, and actions
36
38
  - **Industry Templates**: 50+ pre-built templates for different industries
37
39
  - **Agency Workspaces**: Manage multiple clients from one account
38
40
  - **Pixel Tracking**: Track website visitors and link to email campaigns
41
+ - **Webhooks**: Real-time event notifications with signature verification
39
42
  - **React Components**: Pre-built components and hooks
40
- - **Webhook Verification**: Secure signature verification utilities
41
43
  - **Error Handling**: Custom error classes for different scenarios
42
44
 
43
45
  ## API Reference
@@ -72,6 +74,66 @@ await client.emails.sendTemplate({
72
74
  });
73
75
  ```
74
76
 
77
+ ### Attachments
78
+
79
+ Send emails with file attachments (max 5 files, 7MB total).
80
+
81
+ ```typescript
82
+ // With Base64 content
83
+ await client.emails.send({
84
+ to: 'user@example.com',
85
+ subject: 'Invoice Attached',
86
+ html: '<p>Please find your invoice attached.</p>',
87
+ fromEmail: 'billing@company.com',
88
+ fromName: 'Billing',
89
+ attachments: [
90
+ {
91
+ filename: 'invoice.pdf',
92
+ content: 'JVBERi0xLjQK...', // Base64 encoded
93
+ contentType: 'application/pdf'
94
+ }
95
+ ]
96
+ });
97
+
98
+ // With URL (fetched automatically)
99
+ await client.emails.send({
100
+ to: 'user@example.com',
101
+ subject: 'Your Report',
102
+ html: '<p>Here is your report.</p>',
103
+ fromEmail: 'reports@company.com',
104
+ attachments: [
105
+ {
106
+ filename: 'report.pdf',
107
+ url: 'https://cdn.example.com/reports/123.pdf',
108
+ contentType: 'application/pdf'
109
+ }
110
+ ]
111
+ });
112
+
113
+ // Inline images (using cid)
114
+ await client.emails.send({
115
+ to: 'user@example.com',
116
+ subject: 'Check out our logo',
117
+ html: '<p>Our logo: <img src="cid:logo-image"></p>',
118
+ fromEmail: 'hello@company.com',
119
+ attachments: [
120
+ {
121
+ filename: 'logo.png',
122
+ url: 'https://cdn.example.com/logo.png',
123
+ contentType: 'image/png',
124
+ cid: 'logo-image' // Reference in HTML with cid:logo-image
125
+ }
126
+ ]
127
+ });
128
+ ```
129
+
130
+ **Attachment Limits:**
131
+ | Limit | Value |
132
+ |-------|-------|
133
+ | Max attachments | 5 |
134
+ | Single file max | 5 MB |
135
+ | Total size | 7 MB |
136
+
75
137
  ### Subscribers
76
138
 
77
139
  ```typescript
@@ -451,6 +513,63 @@ await platform.workflows.trigger(data.workflow.id, {
451
513
  });
452
514
  ```
453
515
 
516
+ ## Webhooks
517
+
518
+ Receive real-time notifications when events occur (emails sent, opened, clicked, bounced, etc.).
519
+
520
+ ### Create & Manage Webhooks
521
+
522
+ ```typescript
523
+ // Create a webhook endpoint
524
+ const { webhook } = await client.webhooks.create({
525
+ url: 'https://yourserver.com/webhooks',
526
+ events: ['email.sent', 'email.delivered', 'email.opened', 'email.clicked', 'email.bounced'],
527
+ });
528
+
529
+ console.log('Webhook secret:', webhook.secret); // Use this to verify signatures
530
+
531
+ // List all webhooks
532
+ const { webhooks } = await client.webhooks.list();
533
+
534
+ // Get webhook with delivery history
535
+ const { webhook, recentDeliveries, stats } = await client.webhooks.get('webhook-id');
536
+
537
+ // Update webhook
538
+ await client.webhooks.update('webhook-id', {
539
+ events: ['email.sent', 'email.bounced', 'email.complained']
540
+ });
541
+
542
+ // Test webhook endpoint
543
+ const result = await client.webhooks.test('webhook-id');
544
+ if (result.test.sent) {
545
+ console.log(`Test delivered in ${result.test.responseTimeMs}ms`);
546
+ }
547
+
548
+ // Disable/Enable webhook
549
+ await client.webhooks.disable('webhook-id');
550
+ await client.webhooks.enable('webhook-id');
551
+
552
+ // Delete webhook
553
+ await client.webhooks.delete('webhook-id');
554
+ ```
555
+
556
+ ### Event Types
557
+
558
+ | Event | Description |
559
+ |-------|-------------|
560
+ | `email.sent` | Email was sent to the recipient |
561
+ | `email.delivered` | Email was delivered to recipient's server |
562
+ | `email.opened` | Recipient opened the email |
563
+ | `email.clicked` | Recipient clicked a link in the email |
564
+ | `email.bounced` | Email bounced (hard or soft) |
565
+ | `email.complained` | Recipient marked email as spam |
566
+ | `subscriber.created` | New subscriber was added |
567
+ | `subscriber.updated` | Subscriber was updated |
568
+ | `subscriber.unsubscribed` | Subscriber unsubscribed |
569
+ | `campaign.sent` | Campaign finished sending |
570
+ | `workflow.started` | Workflow execution started |
571
+ | `workflow.completed` | Workflow execution completed |
572
+
454
573
  ## Pixel Tracking
455
574
 
456
575
  Track website visitors and connect their behavior to email campaigns.
package/dist/index.d.mts CHANGED
@@ -9,6 +9,22 @@ interface SendMailOSOptions {
9
9
  /** Custom fetch implementation (for testing/Node.js polyfill) */
10
10
  fetch?: typeof fetch;
11
11
  }
12
+ /**
13
+ * Email attachment configuration
14
+ * Provide either `content` (Base64) or `url` (fetched automatically)
15
+ */
16
+ interface EmailAttachment {
17
+ /** Filename shown to recipient */
18
+ filename: string;
19
+ /** Base64-encoded file content (required if no url) */
20
+ content?: string;
21
+ /** URL to fetch attachment from (required if no content) */
22
+ url?: string;
23
+ /** MIME type (e.g., 'application/pdf', 'image/png') */
24
+ contentType: string;
25
+ /** Content-ID for inline images - reference in HTML with cid:your-id */
26
+ cid?: string;
27
+ }
12
28
  interface SendEmailRequest {
13
29
  /** Recipient email address */
14
30
  to: string;
@@ -37,6 +53,11 @@ interface SendEmailRequest {
37
53
  * @note Agency accounts MUST specify either workspaceId or domain
38
54
  */
39
55
  domain?: string;
56
+ /**
57
+ * File attachments (max 5 files, 7MB total)
58
+ * Provide either Base64 content or URL for each attachment
59
+ */
60
+ attachments?: EmailAttachment[];
40
61
  }
41
62
  interface SendEmailResponse {
42
63
  success: boolean;
@@ -1418,4 +1439,4 @@ declare function constructWebhookEvent<T = unknown>(payload: string, headers: {
1418
1439
  timestamp: string;
1419
1440
  }, secret: string): T;
1420
1441
 
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 };
1442
+ 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 EmailAttachment, 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 };
package/dist/index.d.ts CHANGED
@@ -9,6 +9,22 @@ interface SendMailOSOptions {
9
9
  /** Custom fetch implementation (for testing/Node.js polyfill) */
10
10
  fetch?: typeof fetch;
11
11
  }
12
+ /**
13
+ * Email attachment configuration
14
+ * Provide either `content` (Base64) or `url` (fetched automatically)
15
+ */
16
+ interface EmailAttachment {
17
+ /** Filename shown to recipient */
18
+ filename: string;
19
+ /** Base64-encoded file content (required if no url) */
20
+ content?: string;
21
+ /** URL to fetch attachment from (required if no content) */
22
+ url?: string;
23
+ /** MIME type (e.g., 'application/pdf', 'image/png') */
24
+ contentType: string;
25
+ /** Content-ID for inline images - reference in HTML with cid:your-id */
26
+ cid?: string;
27
+ }
12
28
  interface SendEmailRequest {
13
29
  /** Recipient email address */
14
30
  to: string;
@@ -37,6 +53,11 @@ interface SendEmailRequest {
37
53
  * @note Agency accounts MUST specify either workspaceId or domain
38
54
  */
39
55
  domain?: string;
56
+ /**
57
+ * File attachments (max 5 files, 7MB total)
58
+ * Provide either Base64 content or URL for each attachment
59
+ */
60
+ attachments?: EmailAttachment[];
40
61
  }
41
62
  interface SendEmailResponse {
42
63
  success: boolean;
@@ -1418,4 +1439,4 @@ declare function constructWebhookEvent<T = unknown>(payload: string, headers: {
1418
1439
  timestamp: string;
1419
1440
  }, secret: string): T;
1420
1441
 
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 };
1442
+ 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 EmailAttachment, 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 };
package/dist/index.js CHANGED
@@ -94,7 +94,8 @@ var EmailsResource = class {
94
94
  variables: params.variables,
95
95
  type: params.type || "transactional",
96
96
  workspace_id: params.workspaceId,
97
- domain: params.domain
97
+ domain: params.domain,
98
+ attachments: params.attachments
98
99
  })
99
100
  });
100
101
  }