resend 6.9.3 → 6.10.0-preview-workflows.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -31,7 +31,7 @@ postal_mime = __toESM(postal_mime);
31
31
  let svix = require("svix");
32
32
 
33
33
  //#region package.json
34
- var version = "6.9.3";
34
+ var version = "6.10.0-preview-workflows.0";
35
35
 
36
36
  //#endregion
37
37
  //#region src/common/utils/build-pagination-query.ts
@@ -704,6 +704,99 @@ var Emails = class {
704
704
  }
705
705
  };
706
706
 
707
+ //#endregion
708
+ //#region src/common/utils/parse-workflow-to-api-options.ts
709
+ function parseStepConfig(step) {
710
+ switch (step.type) {
711
+ case "trigger": return {
712
+ ref: step.ref,
713
+ type: step.type,
714
+ config: { event_name: step.config.eventName }
715
+ };
716
+ case "delay": return {
717
+ ref: step.ref,
718
+ type: step.type,
719
+ config: step.config
720
+ };
721
+ case "send_email": return {
722
+ ref: step.ref,
723
+ type: step.type,
724
+ config: {
725
+ template_id: step.config.templateId,
726
+ subject: step.config.subject,
727
+ from: step.config.from,
728
+ reply_to: step.config.replyTo,
729
+ variables: step.config.variables
730
+ }
731
+ };
732
+ case "wait_for_event": return {
733
+ ref: step.ref,
734
+ type: step.type,
735
+ config: {
736
+ event_name: step.config.eventName,
737
+ timeout_seconds: step.config.timeoutSeconds,
738
+ filter_rule: step.config.filterRule
739
+ }
740
+ };
741
+ case "condition": return {
742
+ ref: step.ref,
743
+ type: step.type,
744
+ config: step.config
745
+ };
746
+ }
747
+ }
748
+ function parseEdge(edge) {
749
+ return {
750
+ from: edge.from,
751
+ to: edge.to,
752
+ edge_type: edge.edgeType
753
+ };
754
+ }
755
+ function parseWorkflowToApiOptions(workflow) {
756
+ return {
757
+ name: workflow.name,
758
+ status: workflow.status,
759
+ steps: workflow.steps?.map(parseStepConfig),
760
+ edges: workflow.edges?.map(parseEdge)
761
+ };
762
+ }
763
+ function parseWorkflowEventToApiOptions(event) {
764
+ return {
765
+ event: event.event,
766
+ contact_id: event.contactId,
767
+ email: event.email,
768
+ payload: event.payload
769
+ };
770
+ }
771
+
772
+ //#endregion
773
+ //#region src/events/events.ts
774
+ var Events = class {
775
+ constructor(resend) {
776
+ this.resend = resend;
777
+ }
778
+ async send(payload) {
779
+ return await this.resend.post("/events/send", parseWorkflowEventToApiOptions(payload));
780
+ }
781
+ async create(payload) {
782
+ return await this.resend.post("/events", payload);
783
+ }
784
+ async get(identifier) {
785
+ return await this.resend.get(`/events/${encodeURIComponent(identifier)}`);
786
+ }
787
+ async list(options = {}) {
788
+ const queryString = buildPaginationQuery(options);
789
+ const url = queryString ? `/events?${queryString}` : "/events";
790
+ return await this.resend.get(url);
791
+ }
792
+ async update(identifier, payload) {
793
+ return await this.resend.patch(`/events/${encodeURIComponent(identifier)}`, payload);
794
+ }
795
+ async remove(identifier) {
796
+ return await this.resend.delete(`/events/${encodeURIComponent(identifier)}`);
797
+ }
798
+ };
799
+
707
800
  //#endregion
708
801
  //#region src/segments/segments.ts
709
802
  var Segments = class {
@@ -906,6 +999,31 @@ var Webhooks = class {
906
999
  }
907
1000
  };
908
1001
 
1002
+ //#endregion
1003
+ //#region src/workflows/workflows.ts
1004
+ var Workflows = class {
1005
+ constructor(resend) {
1006
+ this.resend = resend;
1007
+ }
1008
+ async create(payload) {
1009
+ return await this.resend.post("/workflows", parseWorkflowToApiOptions(payload));
1010
+ }
1011
+ async list(options = {}) {
1012
+ const queryString = buildPaginationQuery(options);
1013
+ const url = queryString ? `/workflows?${queryString}` : "/workflows";
1014
+ return await this.resend.get(url);
1015
+ }
1016
+ async get(id) {
1017
+ return await this.resend.get(`/workflows/${id}`);
1018
+ }
1019
+ async remove(id) {
1020
+ return await this.resend.delete(`/workflows/${id}`);
1021
+ }
1022
+ async update(id, payload) {
1023
+ return await this.resend.patch(`/workflows/${id}`, payload);
1024
+ }
1025
+ };
1026
+
909
1027
  //#endregion
910
1028
  //#region src/resend.ts
911
1029
  const defaultBaseUrl = "https://api.resend.com";
@@ -924,9 +1042,11 @@ var Resend = class {
924
1042
  this.contactProperties = new ContactProperties(this);
925
1043
  this.domains = new Domains(this);
926
1044
  this.emails = new Emails(this);
1045
+ this.events = new Events(this);
927
1046
  this.webhooks = new Webhooks(this);
928
1047
  this.templates = new Templates(this);
929
1048
  this.topics = new Topics(this);
1049
+ this.workflows = new Workflows(this);
930
1050
  if (!key) {
931
1051
  if (typeof process !== "undefined" && process.env) this.key = process.env.RESEND_API_KEY;
932
1052
  if (!this.key) throw new Error("Missing API key. Pass it to the constructor `new Resend(\"re_123\")`");
package/dist/index.d.cts CHANGED
@@ -1115,6 +1115,79 @@ type ListReceivingEmailsResponse = {
1115
1115
  error: ErrorResponse;
1116
1116
  };
1117
1117
  //#endregion
1118
+ //#region src/events/interfaces/event.d.ts
1119
+ type EventSchemaType = 'string' | 'number' | 'boolean' | 'date';
1120
+ type EventSchemaMap = Record<string, EventSchemaType>;
1121
+ interface Event {
1122
+ object: 'event';
1123
+ id: string;
1124
+ name: string;
1125
+ schema: EventSchemaMap | null;
1126
+ created_at: string;
1127
+ updated_at: string | null;
1128
+ }
1129
+ //#endregion
1130
+ //#region src/events/interfaces/create-event.interface.d.ts
1131
+ interface CreateEventOptions {
1132
+ name: string;
1133
+ schema?: EventSchemaMap | null;
1134
+ }
1135
+ interface CreateEventResponseSuccess {
1136
+ object: 'event';
1137
+ id: string;
1138
+ }
1139
+ type CreateEventResponse = Response<CreateEventResponseSuccess>;
1140
+ //#endregion
1141
+ //#region src/events/interfaces/get-event.interface.d.ts
1142
+ type GetEventResponseSuccess = Event;
1143
+ type GetEventResponse = Response<GetEventResponseSuccess>;
1144
+ //#endregion
1145
+ //#region src/events/interfaces/list-events.interface.d.ts
1146
+ type ListEventsOptions = PaginationOptions;
1147
+ interface ListEventsResponseSuccess {
1148
+ object: 'list';
1149
+ has_more: boolean;
1150
+ data: Omit<Event, 'object'>[];
1151
+ }
1152
+ type ListEventsResponse = Response<ListEventsResponseSuccess>;
1153
+ //#endregion
1154
+ //#region src/events/interfaces/remove-event.interface.d.ts
1155
+ interface RemoveEventResponseSuccess {
1156
+ object: 'event';
1157
+ id: string;
1158
+ deleted: true;
1159
+ }
1160
+ type RemoveEventResponse = Response<RemoveEventResponseSuccess>;
1161
+ //#endregion
1162
+ //#region src/events/interfaces/send-event.interface.d.ts
1163
+ type SendEventOptions = {
1164
+ event: string;
1165
+ contactId: string;
1166
+ email?: never;
1167
+ payload?: Record<string, unknown>;
1168
+ } | {
1169
+ event: string;
1170
+ email: string;
1171
+ contactId?: never;
1172
+ payload?: Record<string, unknown>;
1173
+ };
1174
+ interface SendEventResponseSuccess {
1175
+ object: 'workflow_event';
1176
+ event: string;
1177
+ event_instance_id: string;
1178
+ }
1179
+ type SendEventResponse = Response<SendEventResponseSuccess>;
1180
+ //#endregion
1181
+ //#region src/events/interfaces/update-event.interface.d.ts
1182
+ interface UpdateEventOptions {
1183
+ schema: EventSchemaMap | null;
1184
+ }
1185
+ interface UpdateEventResponseSuccess {
1186
+ object: 'event';
1187
+ id: string;
1188
+ }
1189
+ type UpdateEventResponse = Response<UpdateEventResponseSuccess>;
1190
+ //#endregion
1118
1191
  //#region src/api-keys/api-keys.d.ts
1119
1192
  declare class ApiKeys {
1120
1193
  private readonly resend;
@@ -1240,6 +1313,18 @@ declare class Emails {
1240
1313
  cancel(id: string): Promise<CancelEmailResponse>;
1241
1314
  }
1242
1315
  //#endregion
1316
+ //#region src/events/events.d.ts
1317
+ declare class Events {
1318
+ private readonly resend;
1319
+ constructor(resend: Resend);
1320
+ send(payload: SendEventOptions): Promise<SendEventResponse>;
1321
+ create(payload: CreateEventOptions): Promise<CreateEventResponse>;
1322
+ get(identifier: string): Promise<GetEventResponse>;
1323
+ list(options?: ListEventsOptions): Promise<ListEventsResponse>;
1324
+ update(identifier: string, payload: UpdateEventOptions): Promise<UpdateEventResponse>;
1325
+ remove(identifier: string): Promise<RemoveEventResponse>;
1326
+ }
1327
+ //#endregion
1243
1328
  //#region src/segments/interfaces/create-segment-options.interface.d.ts
1244
1329
  interface CreateSegmentOptions {
1245
1330
  name: string;
@@ -1719,6 +1804,157 @@ declare class Webhooks {
1719
1804
  verify(payload: VerifyWebhookOptions): WebhookEventPayload;
1720
1805
  }
1721
1806
  //#endregion
1807
+ //#region src/workflows/interfaces/workflow-step.interface.d.ts
1808
+ type ConditionRule = {
1809
+ type: 'rule';
1810
+ field: string;
1811
+ operator: 'eq' | 'neq';
1812
+ value: string | number | boolean | null;
1813
+ } | {
1814
+ type: 'rule';
1815
+ field: string;
1816
+ operator: 'gt' | 'gte' | 'lt' | 'lte';
1817
+ value: number;
1818
+ } | {
1819
+ type: 'rule';
1820
+ field: string;
1821
+ operator: 'contains' | 'starts_with' | 'ends_with';
1822
+ value: string;
1823
+ } | {
1824
+ type: 'rule';
1825
+ field: string;
1826
+ operator: 'exists' | 'is_empty';
1827
+ };
1828
+ type TemplateVariableValue = string | number | boolean | {
1829
+ var: string;
1830
+ } | Record<string, string | number | boolean> | Array<string | number | boolean | Record<string, string | number | boolean>>;
1831
+ interface TriggerStepConfig {
1832
+ eventName: string;
1833
+ }
1834
+ interface DelayStepConfig {
1835
+ seconds: number;
1836
+ }
1837
+ interface SendEmailStepConfig {
1838
+ templateId: string;
1839
+ subject?: string;
1840
+ from?: string;
1841
+ replyTo?: string;
1842
+ variables?: Record<string, TemplateVariableValue>;
1843
+ }
1844
+ interface WaitForEventStepConfig {
1845
+ eventName: string;
1846
+ timeoutSeconds?: number;
1847
+ filterRule?: ConditionRule;
1848
+ }
1849
+ type ConditionStepConfig = ConditionRule;
1850
+ type WorkflowStep = {
1851
+ ref: string;
1852
+ type: 'trigger';
1853
+ config: TriggerStepConfig;
1854
+ } | {
1855
+ ref: string;
1856
+ type: 'delay';
1857
+ config: DelayStepConfig;
1858
+ } | {
1859
+ ref: string;
1860
+ type: 'send_email';
1861
+ config: SendEmailStepConfig;
1862
+ } | {
1863
+ ref: string;
1864
+ type: 'wait_for_event';
1865
+ config: WaitForEventStepConfig;
1866
+ } | {
1867
+ ref: string;
1868
+ type: 'condition';
1869
+ config: ConditionStepConfig;
1870
+ };
1871
+ type WorkflowEdgeType = 'default' | 'condition_met' | 'condition_not_met' | 'timeout' | 'event_received';
1872
+ interface WorkflowEdge {
1873
+ from: string;
1874
+ to: string;
1875
+ edgeType?: WorkflowEdgeType;
1876
+ }
1877
+ interface WorkflowResponseStep {
1878
+ id: string;
1879
+ type: string;
1880
+ config: unknown;
1881
+ ref?: string;
1882
+ }
1883
+ interface WorkflowResponseEdge {
1884
+ id: string;
1885
+ from_step_id: string;
1886
+ to_step_id: string;
1887
+ edge_type: string;
1888
+ }
1889
+ //#endregion
1890
+ //#region src/workflows/interfaces/create-workflow-options.interface.d.ts
1891
+ interface CreateWorkflowOptions {
1892
+ name: string;
1893
+ status?: 'enabled' | 'disabled';
1894
+ steps: WorkflowStep[];
1895
+ edges: WorkflowEdge[];
1896
+ }
1897
+ interface CreateWorkflowResponseSuccess {
1898
+ object: 'workflow';
1899
+ id: string;
1900
+ }
1901
+ type CreateWorkflowResponse = Response<CreateWorkflowResponseSuccess>;
1902
+ //#endregion
1903
+ //#region src/workflows/interfaces/workflow.d.ts
1904
+ interface Workflow {
1905
+ object: 'workflow';
1906
+ id: string;
1907
+ name: string;
1908
+ status: 'enabled' | 'disabled';
1909
+ created_at: string;
1910
+ updated_at: string | null;
1911
+ }
1912
+ //#endregion
1913
+ //#region src/workflows/interfaces/get-workflow.interface.d.ts
1914
+ interface GetWorkflowResponseSuccess extends Workflow {
1915
+ steps: WorkflowResponseStep[];
1916
+ edges: WorkflowResponseEdge[];
1917
+ }
1918
+ type GetWorkflowResponse = Response<GetWorkflowResponseSuccess>;
1919
+ //#endregion
1920
+ //#region src/workflows/interfaces/list-workflows.interface.d.ts
1921
+ type ListWorkflowsOptions = PaginationOptions;
1922
+ interface ListWorkflowsResponseSuccess {
1923
+ object: 'list';
1924
+ has_more: boolean;
1925
+ data: Workflow[];
1926
+ }
1927
+ type ListWorkflowsResponse = Response<ListWorkflowsResponseSuccess>;
1928
+ //#endregion
1929
+ //#region src/workflows/interfaces/remove-workflow.interface.d.ts
1930
+ interface RemoveWorkflowResponseSuccess extends Pick<Workflow, 'id'> {
1931
+ object: 'workflow';
1932
+ deleted: boolean;
1933
+ }
1934
+ type RemoveWorkflowResponse = Response<RemoveWorkflowResponseSuccess>;
1935
+ //#endregion
1936
+ //#region src/workflows/interfaces/update-workflow.interface.d.ts
1937
+ interface UpdateWorkflowOptions {
1938
+ status: 'enabled' | 'disabled';
1939
+ }
1940
+ interface UpdateWorkflowResponseSuccess {
1941
+ object: 'workflow';
1942
+ id: string;
1943
+ status: 'enabled' | 'disabled';
1944
+ }
1945
+ type UpdateWorkflowResponse = Response<UpdateWorkflowResponseSuccess>;
1946
+ //#endregion
1947
+ //#region src/workflows/workflows.d.ts
1948
+ declare class Workflows {
1949
+ private readonly resend;
1950
+ constructor(resend: Resend);
1951
+ create(payload: CreateWorkflowOptions): Promise<CreateWorkflowResponse>;
1952
+ list(options?: ListWorkflowsOptions): Promise<ListWorkflowsResponse>;
1953
+ get(id: string): Promise<GetWorkflowResponse>;
1954
+ remove(id: string): Promise<RemoveWorkflowResponse>;
1955
+ update(id: string, payload: UpdateWorkflowOptions): Promise<UpdateWorkflowResponse>;
1956
+ }
1957
+ //#endregion
1722
1958
  //#region src/resend.d.ts
1723
1959
  declare class Resend {
1724
1960
  readonly key?: string | undefined;
@@ -1735,9 +1971,11 @@ declare class Resend {
1735
1971
  readonly contactProperties: ContactProperties;
1736
1972
  readonly domains: Domains;
1737
1973
  readonly emails: Emails;
1974
+ readonly events: Events;
1738
1975
  readonly webhooks: Webhooks;
1739
1976
  readonly templates: Templates;
1740
1977
  readonly topics: Topics;
1978
+ readonly workflows: Workflows;
1741
1979
  constructor(key?: string | undefined);
1742
1980
  fetchRequest<T>(path: string, options?: {}): Promise<Response<T>>;
1743
1981
  post<T>(path: string, entity?: unknown, options?: PostOptions & IdempotentRequest): Promise<Response<T>>;
@@ -1747,4 +1985,4 @@ declare class Resend {
1747
1985
  delete<T>(path: string, query?: unknown): Promise<Response<T>>;
1748
1986
  }
1749
1987
  //#endregion
1750
- export { AddContactSegmentOptions, AddContactSegmentResponse, AddContactSegmentResponseSuccess, ApiContactProperty, ApiKey, Attachment, AttachmentData, Broadcast, CancelEmailResponse, CancelEmailResponseSuccess, Contact, ContactCreatedEvent, ContactDeletedEvent, ContactProperty, ContactSegmentsBaseOptions, ContactTopic, ContactUpdatedEvent, CreateApiKeyOptions, CreateApiKeyRequestOptions, CreateApiKeyResponse, CreateApiKeyResponseSuccess, CreateBatchEmailOptions, CreateBatchOptions, CreateBatchRequestOptions, CreateBatchResponse, CreateBatchSuccessResponse, CreateBroadcastOptions, CreateBroadcastRequestOptions, CreateBroadcastResponse, CreateBroadcastResponseSuccess, CreateContactOptions, CreateContactPropertyApiOptions, CreateContactPropertyOptions, CreateContactPropertyResponse, CreateContactPropertyResponseSuccess, CreateContactRequestOptions, CreateContactResponse, CreateContactResponseSuccess, CreateDomainOptions, CreateDomainRequestOptions, CreateDomainResponse, CreateDomainResponseSuccess, CreateEmailOptions, CreateEmailRequestOptions, CreateEmailResponse, CreateEmailResponseSuccess, CreateSegmentOptions, CreateSegmentRequestOptions, CreateSegmentResponse, CreateSegmentResponseSuccess, CreateTemplateOptions, CreateTemplateRequestOptions, CreateTemplateResponse, CreateTemplateResponseSuccess, CreateTopicOptions, CreateTopicResponse, CreateTopicResponseSuccess, CreateWebhookOptions, CreateWebhookRequestOptions, CreateWebhookResponse, CreateWebhookResponseSuccess, Domain, DomainApiOptions, DomainCapabilities, DomainCapabilityStatus, DomainCreatedEvent, DomainDeletedEvent, DomainDkimRecord, DomainNameservers, DomainRecords, DomainRegion, DomainSpfRecord, DomainStatus, DomainUpdatedEvent, DuplicateTemplateResponse, DuplicateTemplateResponseSuccess, EmailApiAttachment, EmailApiOptions, EmailBouncedEvent, EmailClickedEvent, EmailComplainedEvent, EmailDeliveredEvent, EmailDeliveryDelayedEvent, EmailFailedEvent, EmailOpenedEvent, EmailReceivedEvent, EmailScheduledEvent, EmailSentEvent, EmailSuppressedEvent, type ErrorResponse, ForwardReceivingEmailOptions, ForwardReceivingEmailResponse, ForwardReceivingEmailResponseSuccess, GetAttachmentOptions, GetAttachmentResponse, GetAttachmentResponseSuccess, GetBroadcastResponse, GetBroadcastResponseSuccess, GetContactOptions, GetContactPropertyResponse, GetContactPropertyResponseSuccess, GetContactResponse, GetContactResponseSuccess, GetDomainResponse, GetDomainResponseSuccess, GetEmailResponse, GetEmailResponseSuccess, GetOptions, GetReceivingEmailResponse, GetReceivingEmailResponseSuccess, GetSegmentResponse, GetSegmentResponseSuccess, GetTemplateResponse, GetTemplateResponseSuccess, GetTopicOptions, GetTopicResponse, GetTopicResponseSuccess, GetWebhookResponse, GetWebhookResponseSuccess, IdempotentRequest, InboundAttachment, LegacyCreateContactOptions, ListApiKeysOptions, ListApiKeysResponse, ListApiKeysResponseSuccess, ListAttachmentsOptions, ListAttachmentsResponse, ListAttachmentsResponseSuccess, ListBroadcastsOptions, ListBroadcastsResponse, ListBroadcastsResponseSuccess, ListContactPropertiesOptions, ListContactPropertiesResponse, ListContactPropertiesResponseSuccess, ListContactSegmentsOptions, ListContactSegmentsResponse, ListContactSegmentsResponseSuccess, ListContactTopicsOptions, ListContactTopicsRequestOptions, ListContactTopicsResponse, ListContactTopicsResponseSuccess, ListContactsOptions, ListContactsResponse, ListContactsResponseSuccess, ListDomainsOptions, ListDomainsResponse, ListDomainsResponseSuccess, ListEmail, ListEmailsOptions, ListEmailsResponse, ListEmailsResponseSuccess, ListReceivingEmail, ListReceivingEmailsOptions, ListReceivingEmailsResponse, ListReceivingEmailsResponseSuccess, ListSegmentsOptions, ListSegmentsResponse, ListSegmentsResponseSuccess, ListTemplatesOptions, ListTemplatesResponse, ListTemplatesResponseSuccess, ListTopicsResponse, ListTopicsResponseSuccess, ListWebhooksOptions, ListWebhooksResponse, ListWebhooksResponseSuccess, PaginatedData, PaginationOptions, PatchOptions, PostOptions, PublishTemplateResponse, PublishTemplateResponseSuccess, PutOptions, ReceivingRecord, RemoveApiKeyResponse, RemoveApiKeyResponseSuccess, RemoveBroadcastResponse, RemoveBroadcastResponseSuccess, RemoveContactOptions, RemoveContactPropertyResponse, RemoveContactPropertyResponseSuccess, RemoveContactSegmentOptions, RemoveContactSegmentResponse, RemoveContactSegmentResponseSuccess, RemoveContactsResponse, RemoveContactsResponseSuccess, RemoveDomainsResponse, RemoveDomainsResponseSuccess, RemoveSegmentResponse, RemoveSegmentResponseSuccess, RemoveTemplateResponse, RemoveTemplateResponseSuccess, RemoveTopicResponse, RemoveTopicResponseSuccess, RemoveWebhookResponse, RemoveWebhookResponseSuccess, RequireAtLeastOne, Resend, type Response, Segment, SelectingField, SendBroadcastOptions, SendBroadcastRequestOptions, SendBroadcastResponse, SendBroadcastResponseSuccess, Tag, Template, TemplateVariable, Topic, UpdateBroadcastOptions, UpdateBroadcastResponse, UpdateBroadcastResponseSuccess, UpdateContactOptions, UpdateContactPropertyApiOptions, UpdateContactPropertyOptions, UpdateContactPropertyResponse, UpdateContactPropertyResponseSuccess, UpdateContactResponse, UpdateContactResponseSuccess, UpdateContactTopicsOptions, UpdateContactTopicsRequestOptions, UpdateContactTopicsResponse, UpdateContactTopicsResponseSuccess, UpdateDomainsOptions, UpdateDomainsResponse, UpdateDomainsResponseSuccess, UpdateEmailOptions, UpdateEmailResponse, UpdateEmailResponseSuccess, UpdateTemplateOptions, UpdateTemplateResponse, UpdateTemplateResponseSuccess, UpdateTopicOptions, UpdateTopicResponse, UpdateTopicResponseSuccess, UpdateWebhookOptions, UpdateWebhookResponse, UpdateWebhookResponseSuccess, VerifyDomainsResponse, VerifyDomainsResponseSuccess, Webhook, WebhookEvent, WebhookEventPayload };
1988
+ export { AddContactSegmentOptions, AddContactSegmentResponse, AddContactSegmentResponseSuccess, ApiContactProperty, ApiKey, Attachment, AttachmentData, Broadcast, CancelEmailResponse, CancelEmailResponseSuccess, ConditionRule, ConditionStepConfig, Contact, ContactCreatedEvent, ContactDeletedEvent, ContactProperty, ContactSegmentsBaseOptions, ContactTopic, ContactUpdatedEvent, CreateApiKeyOptions, CreateApiKeyRequestOptions, CreateApiKeyResponse, CreateApiKeyResponseSuccess, CreateBatchEmailOptions, CreateBatchOptions, CreateBatchRequestOptions, CreateBatchResponse, CreateBatchSuccessResponse, CreateBroadcastOptions, CreateBroadcastRequestOptions, CreateBroadcastResponse, CreateBroadcastResponseSuccess, CreateContactOptions, CreateContactPropertyApiOptions, CreateContactPropertyOptions, CreateContactPropertyResponse, CreateContactPropertyResponseSuccess, CreateContactRequestOptions, CreateContactResponse, CreateContactResponseSuccess, CreateDomainOptions, CreateDomainRequestOptions, CreateDomainResponse, CreateDomainResponseSuccess, CreateEmailOptions, CreateEmailRequestOptions, CreateEmailResponse, CreateEmailResponseSuccess, CreateEventOptions, CreateEventResponse, CreateEventResponseSuccess, CreateSegmentOptions, CreateSegmentRequestOptions, CreateSegmentResponse, CreateSegmentResponseSuccess, CreateTemplateOptions, CreateTemplateRequestOptions, CreateTemplateResponse, CreateTemplateResponseSuccess, CreateTopicOptions, CreateTopicResponse, CreateTopicResponseSuccess, CreateWebhookOptions, CreateWebhookRequestOptions, CreateWebhookResponse, CreateWebhookResponseSuccess, CreateWorkflowOptions, CreateWorkflowResponse, CreateWorkflowResponseSuccess, DelayStepConfig, Domain, DomainApiOptions, DomainCapabilities, DomainCapabilityStatus, DomainCreatedEvent, DomainDeletedEvent, DomainDkimRecord, DomainNameservers, DomainRecords, DomainRegion, DomainSpfRecord, DomainStatus, DomainUpdatedEvent, DuplicateTemplateResponse, DuplicateTemplateResponseSuccess, EmailApiAttachment, EmailApiOptions, EmailBouncedEvent, EmailClickedEvent, EmailComplainedEvent, EmailDeliveredEvent, EmailDeliveryDelayedEvent, EmailFailedEvent, EmailOpenedEvent, EmailReceivedEvent, EmailScheduledEvent, EmailSentEvent, EmailSuppressedEvent, type ErrorResponse, Event, EventSchemaMap, EventSchemaType, ForwardReceivingEmailOptions, ForwardReceivingEmailResponse, ForwardReceivingEmailResponseSuccess, GetAttachmentOptions, GetAttachmentResponse, GetAttachmentResponseSuccess, GetBroadcastResponse, GetBroadcastResponseSuccess, GetContactOptions, GetContactPropertyResponse, GetContactPropertyResponseSuccess, GetContactResponse, GetContactResponseSuccess, GetDomainResponse, GetDomainResponseSuccess, GetEmailResponse, GetEmailResponseSuccess, GetEventResponse, GetEventResponseSuccess, GetOptions, GetReceivingEmailResponse, GetReceivingEmailResponseSuccess, GetSegmentResponse, GetSegmentResponseSuccess, GetTemplateResponse, GetTemplateResponseSuccess, GetTopicOptions, GetTopicResponse, GetTopicResponseSuccess, GetWebhookResponse, GetWebhookResponseSuccess, GetWorkflowResponse, GetWorkflowResponseSuccess, IdempotentRequest, InboundAttachment, LegacyCreateContactOptions, ListApiKeysOptions, ListApiKeysResponse, ListApiKeysResponseSuccess, ListAttachmentsOptions, ListAttachmentsResponse, ListAttachmentsResponseSuccess, ListBroadcastsOptions, ListBroadcastsResponse, ListBroadcastsResponseSuccess, ListContactPropertiesOptions, ListContactPropertiesResponse, ListContactPropertiesResponseSuccess, ListContactSegmentsOptions, ListContactSegmentsResponse, ListContactSegmentsResponseSuccess, ListContactTopicsOptions, ListContactTopicsRequestOptions, ListContactTopicsResponse, ListContactTopicsResponseSuccess, ListContactsOptions, ListContactsResponse, ListContactsResponseSuccess, ListDomainsOptions, ListDomainsResponse, ListDomainsResponseSuccess, ListEmail, ListEmailsOptions, ListEmailsResponse, ListEmailsResponseSuccess, ListEventsOptions, ListEventsResponse, ListEventsResponseSuccess, ListReceivingEmail, ListReceivingEmailsOptions, ListReceivingEmailsResponse, ListReceivingEmailsResponseSuccess, ListSegmentsOptions, ListSegmentsResponse, ListSegmentsResponseSuccess, ListTemplatesOptions, ListTemplatesResponse, ListTemplatesResponseSuccess, ListTopicsResponse, ListTopicsResponseSuccess, ListWebhooksOptions, ListWebhooksResponse, ListWebhooksResponseSuccess, ListWorkflowsOptions, ListWorkflowsResponse, ListWorkflowsResponseSuccess, PaginatedData, PaginationOptions, PatchOptions, PostOptions, PublishTemplateResponse, PublishTemplateResponseSuccess, PutOptions, ReceivingRecord, RemoveApiKeyResponse, RemoveApiKeyResponseSuccess, RemoveBroadcastResponse, RemoveBroadcastResponseSuccess, RemoveContactOptions, RemoveContactPropertyResponse, RemoveContactPropertyResponseSuccess, RemoveContactSegmentOptions, RemoveContactSegmentResponse, RemoveContactSegmentResponseSuccess, RemoveContactsResponse, RemoveContactsResponseSuccess, RemoveDomainsResponse, RemoveDomainsResponseSuccess, RemoveEventResponse, RemoveEventResponseSuccess, RemoveSegmentResponse, RemoveSegmentResponseSuccess, RemoveTemplateResponse, RemoveTemplateResponseSuccess, RemoveTopicResponse, RemoveTopicResponseSuccess, RemoveWebhookResponse, RemoveWebhookResponseSuccess, RemoveWorkflowResponse, RemoveWorkflowResponseSuccess, RequireAtLeastOne, Resend, type Response, Segment, SelectingField, SendBroadcastOptions, SendBroadcastRequestOptions, SendBroadcastResponse, SendBroadcastResponseSuccess, SendEmailStepConfig, SendEventOptions, SendEventResponse, SendEventResponseSuccess, Tag, Template, TemplateVariable, TemplateVariableValue, Topic, TriggerStepConfig, UpdateBroadcastOptions, UpdateBroadcastResponse, UpdateBroadcastResponseSuccess, UpdateContactOptions, UpdateContactPropertyApiOptions, UpdateContactPropertyOptions, UpdateContactPropertyResponse, UpdateContactPropertyResponseSuccess, UpdateContactResponse, UpdateContactResponseSuccess, UpdateContactTopicsOptions, UpdateContactTopicsRequestOptions, UpdateContactTopicsResponse, UpdateContactTopicsResponseSuccess, UpdateDomainsOptions, UpdateDomainsResponse, UpdateDomainsResponseSuccess, UpdateEmailOptions, UpdateEmailResponse, UpdateEmailResponseSuccess, UpdateEventOptions, UpdateEventResponse, UpdateEventResponseSuccess, UpdateTemplateOptions, UpdateTemplateResponse, UpdateTemplateResponseSuccess, UpdateTopicOptions, UpdateTopicResponse, UpdateTopicResponseSuccess, UpdateWebhookOptions, UpdateWebhookResponse, UpdateWebhookResponseSuccess, UpdateWorkflowOptions, UpdateWorkflowResponse, UpdateWorkflowResponseSuccess, VerifyDomainsResponse, VerifyDomainsResponseSuccess, WaitForEventStepConfig, Webhook, WebhookEvent, WebhookEventPayload, Workflow, WorkflowEdge, WorkflowEdgeType, WorkflowResponseEdge, WorkflowResponseStep, WorkflowStep };
package/dist/index.d.mts CHANGED
@@ -1115,6 +1115,79 @@ type ListReceivingEmailsResponse = {
1115
1115
  error: ErrorResponse;
1116
1116
  };
1117
1117
  //#endregion
1118
+ //#region src/events/interfaces/event.d.ts
1119
+ type EventSchemaType = 'string' | 'number' | 'boolean' | 'date';
1120
+ type EventSchemaMap = Record<string, EventSchemaType>;
1121
+ interface Event {
1122
+ object: 'event';
1123
+ id: string;
1124
+ name: string;
1125
+ schema: EventSchemaMap | null;
1126
+ created_at: string;
1127
+ updated_at: string | null;
1128
+ }
1129
+ //#endregion
1130
+ //#region src/events/interfaces/create-event.interface.d.ts
1131
+ interface CreateEventOptions {
1132
+ name: string;
1133
+ schema?: EventSchemaMap | null;
1134
+ }
1135
+ interface CreateEventResponseSuccess {
1136
+ object: 'event';
1137
+ id: string;
1138
+ }
1139
+ type CreateEventResponse = Response<CreateEventResponseSuccess>;
1140
+ //#endregion
1141
+ //#region src/events/interfaces/get-event.interface.d.ts
1142
+ type GetEventResponseSuccess = Event;
1143
+ type GetEventResponse = Response<GetEventResponseSuccess>;
1144
+ //#endregion
1145
+ //#region src/events/interfaces/list-events.interface.d.ts
1146
+ type ListEventsOptions = PaginationOptions;
1147
+ interface ListEventsResponseSuccess {
1148
+ object: 'list';
1149
+ has_more: boolean;
1150
+ data: Omit<Event, 'object'>[];
1151
+ }
1152
+ type ListEventsResponse = Response<ListEventsResponseSuccess>;
1153
+ //#endregion
1154
+ //#region src/events/interfaces/remove-event.interface.d.ts
1155
+ interface RemoveEventResponseSuccess {
1156
+ object: 'event';
1157
+ id: string;
1158
+ deleted: true;
1159
+ }
1160
+ type RemoveEventResponse = Response<RemoveEventResponseSuccess>;
1161
+ //#endregion
1162
+ //#region src/events/interfaces/send-event.interface.d.ts
1163
+ type SendEventOptions = {
1164
+ event: string;
1165
+ contactId: string;
1166
+ email?: never;
1167
+ payload?: Record<string, unknown>;
1168
+ } | {
1169
+ event: string;
1170
+ email: string;
1171
+ contactId?: never;
1172
+ payload?: Record<string, unknown>;
1173
+ };
1174
+ interface SendEventResponseSuccess {
1175
+ object: 'workflow_event';
1176
+ event: string;
1177
+ event_instance_id: string;
1178
+ }
1179
+ type SendEventResponse = Response<SendEventResponseSuccess>;
1180
+ //#endregion
1181
+ //#region src/events/interfaces/update-event.interface.d.ts
1182
+ interface UpdateEventOptions {
1183
+ schema: EventSchemaMap | null;
1184
+ }
1185
+ interface UpdateEventResponseSuccess {
1186
+ object: 'event';
1187
+ id: string;
1188
+ }
1189
+ type UpdateEventResponse = Response<UpdateEventResponseSuccess>;
1190
+ //#endregion
1118
1191
  //#region src/api-keys/api-keys.d.ts
1119
1192
  declare class ApiKeys {
1120
1193
  private readonly resend;
@@ -1240,6 +1313,18 @@ declare class Emails {
1240
1313
  cancel(id: string): Promise<CancelEmailResponse>;
1241
1314
  }
1242
1315
  //#endregion
1316
+ //#region src/events/events.d.ts
1317
+ declare class Events {
1318
+ private readonly resend;
1319
+ constructor(resend: Resend);
1320
+ send(payload: SendEventOptions): Promise<SendEventResponse>;
1321
+ create(payload: CreateEventOptions): Promise<CreateEventResponse>;
1322
+ get(identifier: string): Promise<GetEventResponse>;
1323
+ list(options?: ListEventsOptions): Promise<ListEventsResponse>;
1324
+ update(identifier: string, payload: UpdateEventOptions): Promise<UpdateEventResponse>;
1325
+ remove(identifier: string): Promise<RemoveEventResponse>;
1326
+ }
1327
+ //#endregion
1243
1328
  //#region src/segments/interfaces/create-segment-options.interface.d.ts
1244
1329
  interface CreateSegmentOptions {
1245
1330
  name: string;
@@ -1719,6 +1804,157 @@ declare class Webhooks {
1719
1804
  verify(payload: VerifyWebhookOptions): WebhookEventPayload;
1720
1805
  }
1721
1806
  //#endregion
1807
+ //#region src/workflows/interfaces/workflow-step.interface.d.ts
1808
+ type ConditionRule = {
1809
+ type: 'rule';
1810
+ field: string;
1811
+ operator: 'eq' | 'neq';
1812
+ value: string | number | boolean | null;
1813
+ } | {
1814
+ type: 'rule';
1815
+ field: string;
1816
+ operator: 'gt' | 'gte' | 'lt' | 'lte';
1817
+ value: number;
1818
+ } | {
1819
+ type: 'rule';
1820
+ field: string;
1821
+ operator: 'contains' | 'starts_with' | 'ends_with';
1822
+ value: string;
1823
+ } | {
1824
+ type: 'rule';
1825
+ field: string;
1826
+ operator: 'exists' | 'is_empty';
1827
+ };
1828
+ type TemplateVariableValue = string | number | boolean | {
1829
+ var: string;
1830
+ } | Record<string, string | number | boolean> | Array<string | number | boolean | Record<string, string | number | boolean>>;
1831
+ interface TriggerStepConfig {
1832
+ eventName: string;
1833
+ }
1834
+ interface DelayStepConfig {
1835
+ seconds: number;
1836
+ }
1837
+ interface SendEmailStepConfig {
1838
+ templateId: string;
1839
+ subject?: string;
1840
+ from?: string;
1841
+ replyTo?: string;
1842
+ variables?: Record<string, TemplateVariableValue>;
1843
+ }
1844
+ interface WaitForEventStepConfig {
1845
+ eventName: string;
1846
+ timeoutSeconds?: number;
1847
+ filterRule?: ConditionRule;
1848
+ }
1849
+ type ConditionStepConfig = ConditionRule;
1850
+ type WorkflowStep = {
1851
+ ref: string;
1852
+ type: 'trigger';
1853
+ config: TriggerStepConfig;
1854
+ } | {
1855
+ ref: string;
1856
+ type: 'delay';
1857
+ config: DelayStepConfig;
1858
+ } | {
1859
+ ref: string;
1860
+ type: 'send_email';
1861
+ config: SendEmailStepConfig;
1862
+ } | {
1863
+ ref: string;
1864
+ type: 'wait_for_event';
1865
+ config: WaitForEventStepConfig;
1866
+ } | {
1867
+ ref: string;
1868
+ type: 'condition';
1869
+ config: ConditionStepConfig;
1870
+ };
1871
+ type WorkflowEdgeType = 'default' | 'condition_met' | 'condition_not_met' | 'timeout' | 'event_received';
1872
+ interface WorkflowEdge {
1873
+ from: string;
1874
+ to: string;
1875
+ edgeType?: WorkflowEdgeType;
1876
+ }
1877
+ interface WorkflowResponseStep {
1878
+ id: string;
1879
+ type: string;
1880
+ config: unknown;
1881
+ ref?: string;
1882
+ }
1883
+ interface WorkflowResponseEdge {
1884
+ id: string;
1885
+ from_step_id: string;
1886
+ to_step_id: string;
1887
+ edge_type: string;
1888
+ }
1889
+ //#endregion
1890
+ //#region src/workflows/interfaces/create-workflow-options.interface.d.ts
1891
+ interface CreateWorkflowOptions {
1892
+ name: string;
1893
+ status?: 'enabled' | 'disabled';
1894
+ steps: WorkflowStep[];
1895
+ edges: WorkflowEdge[];
1896
+ }
1897
+ interface CreateWorkflowResponseSuccess {
1898
+ object: 'workflow';
1899
+ id: string;
1900
+ }
1901
+ type CreateWorkflowResponse = Response<CreateWorkflowResponseSuccess>;
1902
+ //#endregion
1903
+ //#region src/workflows/interfaces/workflow.d.ts
1904
+ interface Workflow {
1905
+ object: 'workflow';
1906
+ id: string;
1907
+ name: string;
1908
+ status: 'enabled' | 'disabled';
1909
+ created_at: string;
1910
+ updated_at: string | null;
1911
+ }
1912
+ //#endregion
1913
+ //#region src/workflows/interfaces/get-workflow.interface.d.ts
1914
+ interface GetWorkflowResponseSuccess extends Workflow {
1915
+ steps: WorkflowResponseStep[];
1916
+ edges: WorkflowResponseEdge[];
1917
+ }
1918
+ type GetWorkflowResponse = Response<GetWorkflowResponseSuccess>;
1919
+ //#endregion
1920
+ //#region src/workflows/interfaces/list-workflows.interface.d.ts
1921
+ type ListWorkflowsOptions = PaginationOptions;
1922
+ interface ListWorkflowsResponseSuccess {
1923
+ object: 'list';
1924
+ has_more: boolean;
1925
+ data: Workflow[];
1926
+ }
1927
+ type ListWorkflowsResponse = Response<ListWorkflowsResponseSuccess>;
1928
+ //#endregion
1929
+ //#region src/workflows/interfaces/remove-workflow.interface.d.ts
1930
+ interface RemoveWorkflowResponseSuccess extends Pick<Workflow, 'id'> {
1931
+ object: 'workflow';
1932
+ deleted: boolean;
1933
+ }
1934
+ type RemoveWorkflowResponse = Response<RemoveWorkflowResponseSuccess>;
1935
+ //#endregion
1936
+ //#region src/workflows/interfaces/update-workflow.interface.d.ts
1937
+ interface UpdateWorkflowOptions {
1938
+ status: 'enabled' | 'disabled';
1939
+ }
1940
+ interface UpdateWorkflowResponseSuccess {
1941
+ object: 'workflow';
1942
+ id: string;
1943
+ status: 'enabled' | 'disabled';
1944
+ }
1945
+ type UpdateWorkflowResponse = Response<UpdateWorkflowResponseSuccess>;
1946
+ //#endregion
1947
+ //#region src/workflows/workflows.d.ts
1948
+ declare class Workflows {
1949
+ private readonly resend;
1950
+ constructor(resend: Resend);
1951
+ create(payload: CreateWorkflowOptions): Promise<CreateWorkflowResponse>;
1952
+ list(options?: ListWorkflowsOptions): Promise<ListWorkflowsResponse>;
1953
+ get(id: string): Promise<GetWorkflowResponse>;
1954
+ remove(id: string): Promise<RemoveWorkflowResponse>;
1955
+ update(id: string, payload: UpdateWorkflowOptions): Promise<UpdateWorkflowResponse>;
1956
+ }
1957
+ //#endregion
1722
1958
  //#region src/resend.d.ts
1723
1959
  declare class Resend {
1724
1960
  readonly key?: string | undefined;
@@ -1735,9 +1971,11 @@ declare class Resend {
1735
1971
  readonly contactProperties: ContactProperties;
1736
1972
  readonly domains: Domains;
1737
1973
  readonly emails: Emails;
1974
+ readonly events: Events;
1738
1975
  readonly webhooks: Webhooks;
1739
1976
  readonly templates: Templates;
1740
1977
  readonly topics: Topics;
1978
+ readonly workflows: Workflows;
1741
1979
  constructor(key?: string | undefined);
1742
1980
  fetchRequest<T>(path: string, options?: {}): Promise<Response<T>>;
1743
1981
  post<T>(path: string, entity?: unknown, options?: PostOptions & IdempotentRequest): Promise<Response<T>>;
@@ -1747,4 +1985,4 @@ declare class Resend {
1747
1985
  delete<T>(path: string, query?: unknown): Promise<Response<T>>;
1748
1986
  }
1749
1987
  //#endregion
1750
- export { AddContactSegmentOptions, AddContactSegmentResponse, AddContactSegmentResponseSuccess, ApiContactProperty, ApiKey, Attachment, AttachmentData, Broadcast, CancelEmailResponse, CancelEmailResponseSuccess, Contact, ContactCreatedEvent, ContactDeletedEvent, ContactProperty, ContactSegmentsBaseOptions, ContactTopic, ContactUpdatedEvent, CreateApiKeyOptions, CreateApiKeyRequestOptions, CreateApiKeyResponse, CreateApiKeyResponseSuccess, CreateBatchEmailOptions, CreateBatchOptions, CreateBatchRequestOptions, CreateBatchResponse, CreateBatchSuccessResponse, CreateBroadcastOptions, CreateBroadcastRequestOptions, CreateBroadcastResponse, CreateBroadcastResponseSuccess, CreateContactOptions, CreateContactPropertyApiOptions, CreateContactPropertyOptions, CreateContactPropertyResponse, CreateContactPropertyResponseSuccess, CreateContactRequestOptions, CreateContactResponse, CreateContactResponseSuccess, CreateDomainOptions, CreateDomainRequestOptions, CreateDomainResponse, CreateDomainResponseSuccess, CreateEmailOptions, CreateEmailRequestOptions, CreateEmailResponse, CreateEmailResponseSuccess, CreateSegmentOptions, CreateSegmentRequestOptions, CreateSegmentResponse, CreateSegmentResponseSuccess, CreateTemplateOptions, CreateTemplateRequestOptions, CreateTemplateResponse, CreateTemplateResponseSuccess, CreateTopicOptions, CreateTopicResponse, CreateTopicResponseSuccess, CreateWebhookOptions, CreateWebhookRequestOptions, CreateWebhookResponse, CreateWebhookResponseSuccess, Domain, DomainApiOptions, DomainCapabilities, DomainCapabilityStatus, DomainCreatedEvent, DomainDeletedEvent, DomainDkimRecord, DomainNameservers, DomainRecords, DomainRegion, DomainSpfRecord, DomainStatus, DomainUpdatedEvent, DuplicateTemplateResponse, DuplicateTemplateResponseSuccess, EmailApiAttachment, EmailApiOptions, EmailBouncedEvent, EmailClickedEvent, EmailComplainedEvent, EmailDeliveredEvent, EmailDeliveryDelayedEvent, EmailFailedEvent, EmailOpenedEvent, EmailReceivedEvent, EmailScheduledEvent, EmailSentEvent, EmailSuppressedEvent, type ErrorResponse, ForwardReceivingEmailOptions, ForwardReceivingEmailResponse, ForwardReceivingEmailResponseSuccess, GetAttachmentOptions, GetAttachmentResponse, GetAttachmentResponseSuccess, GetBroadcastResponse, GetBroadcastResponseSuccess, GetContactOptions, GetContactPropertyResponse, GetContactPropertyResponseSuccess, GetContactResponse, GetContactResponseSuccess, GetDomainResponse, GetDomainResponseSuccess, GetEmailResponse, GetEmailResponseSuccess, GetOptions, GetReceivingEmailResponse, GetReceivingEmailResponseSuccess, GetSegmentResponse, GetSegmentResponseSuccess, GetTemplateResponse, GetTemplateResponseSuccess, GetTopicOptions, GetTopicResponse, GetTopicResponseSuccess, GetWebhookResponse, GetWebhookResponseSuccess, IdempotentRequest, InboundAttachment, LegacyCreateContactOptions, ListApiKeysOptions, ListApiKeysResponse, ListApiKeysResponseSuccess, ListAttachmentsOptions, ListAttachmentsResponse, ListAttachmentsResponseSuccess, ListBroadcastsOptions, ListBroadcastsResponse, ListBroadcastsResponseSuccess, ListContactPropertiesOptions, ListContactPropertiesResponse, ListContactPropertiesResponseSuccess, ListContactSegmentsOptions, ListContactSegmentsResponse, ListContactSegmentsResponseSuccess, ListContactTopicsOptions, ListContactTopicsRequestOptions, ListContactTopicsResponse, ListContactTopicsResponseSuccess, ListContactsOptions, ListContactsResponse, ListContactsResponseSuccess, ListDomainsOptions, ListDomainsResponse, ListDomainsResponseSuccess, ListEmail, ListEmailsOptions, ListEmailsResponse, ListEmailsResponseSuccess, ListReceivingEmail, ListReceivingEmailsOptions, ListReceivingEmailsResponse, ListReceivingEmailsResponseSuccess, ListSegmentsOptions, ListSegmentsResponse, ListSegmentsResponseSuccess, ListTemplatesOptions, ListTemplatesResponse, ListTemplatesResponseSuccess, ListTopicsResponse, ListTopicsResponseSuccess, ListWebhooksOptions, ListWebhooksResponse, ListWebhooksResponseSuccess, PaginatedData, PaginationOptions, PatchOptions, PostOptions, PublishTemplateResponse, PublishTemplateResponseSuccess, PutOptions, ReceivingRecord, RemoveApiKeyResponse, RemoveApiKeyResponseSuccess, RemoveBroadcastResponse, RemoveBroadcastResponseSuccess, RemoveContactOptions, RemoveContactPropertyResponse, RemoveContactPropertyResponseSuccess, RemoveContactSegmentOptions, RemoveContactSegmentResponse, RemoveContactSegmentResponseSuccess, RemoveContactsResponse, RemoveContactsResponseSuccess, RemoveDomainsResponse, RemoveDomainsResponseSuccess, RemoveSegmentResponse, RemoveSegmentResponseSuccess, RemoveTemplateResponse, RemoveTemplateResponseSuccess, RemoveTopicResponse, RemoveTopicResponseSuccess, RemoveWebhookResponse, RemoveWebhookResponseSuccess, RequireAtLeastOne, Resend, type Response, Segment, SelectingField, SendBroadcastOptions, SendBroadcastRequestOptions, SendBroadcastResponse, SendBroadcastResponseSuccess, Tag, Template, TemplateVariable, Topic, UpdateBroadcastOptions, UpdateBroadcastResponse, UpdateBroadcastResponseSuccess, UpdateContactOptions, UpdateContactPropertyApiOptions, UpdateContactPropertyOptions, UpdateContactPropertyResponse, UpdateContactPropertyResponseSuccess, UpdateContactResponse, UpdateContactResponseSuccess, UpdateContactTopicsOptions, UpdateContactTopicsRequestOptions, UpdateContactTopicsResponse, UpdateContactTopicsResponseSuccess, UpdateDomainsOptions, UpdateDomainsResponse, UpdateDomainsResponseSuccess, UpdateEmailOptions, UpdateEmailResponse, UpdateEmailResponseSuccess, UpdateTemplateOptions, UpdateTemplateResponse, UpdateTemplateResponseSuccess, UpdateTopicOptions, UpdateTopicResponse, UpdateTopicResponseSuccess, UpdateWebhookOptions, UpdateWebhookResponse, UpdateWebhookResponseSuccess, VerifyDomainsResponse, VerifyDomainsResponseSuccess, Webhook, WebhookEvent, WebhookEventPayload };
1988
+ export { AddContactSegmentOptions, AddContactSegmentResponse, AddContactSegmentResponseSuccess, ApiContactProperty, ApiKey, Attachment, AttachmentData, Broadcast, CancelEmailResponse, CancelEmailResponseSuccess, ConditionRule, ConditionStepConfig, Contact, ContactCreatedEvent, ContactDeletedEvent, ContactProperty, ContactSegmentsBaseOptions, ContactTopic, ContactUpdatedEvent, CreateApiKeyOptions, CreateApiKeyRequestOptions, CreateApiKeyResponse, CreateApiKeyResponseSuccess, CreateBatchEmailOptions, CreateBatchOptions, CreateBatchRequestOptions, CreateBatchResponse, CreateBatchSuccessResponse, CreateBroadcastOptions, CreateBroadcastRequestOptions, CreateBroadcastResponse, CreateBroadcastResponseSuccess, CreateContactOptions, CreateContactPropertyApiOptions, CreateContactPropertyOptions, CreateContactPropertyResponse, CreateContactPropertyResponseSuccess, CreateContactRequestOptions, CreateContactResponse, CreateContactResponseSuccess, CreateDomainOptions, CreateDomainRequestOptions, CreateDomainResponse, CreateDomainResponseSuccess, CreateEmailOptions, CreateEmailRequestOptions, CreateEmailResponse, CreateEmailResponseSuccess, CreateEventOptions, CreateEventResponse, CreateEventResponseSuccess, CreateSegmentOptions, CreateSegmentRequestOptions, CreateSegmentResponse, CreateSegmentResponseSuccess, CreateTemplateOptions, CreateTemplateRequestOptions, CreateTemplateResponse, CreateTemplateResponseSuccess, CreateTopicOptions, CreateTopicResponse, CreateTopicResponseSuccess, CreateWebhookOptions, CreateWebhookRequestOptions, CreateWebhookResponse, CreateWebhookResponseSuccess, CreateWorkflowOptions, CreateWorkflowResponse, CreateWorkflowResponseSuccess, DelayStepConfig, Domain, DomainApiOptions, DomainCapabilities, DomainCapabilityStatus, DomainCreatedEvent, DomainDeletedEvent, DomainDkimRecord, DomainNameservers, DomainRecords, DomainRegion, DomainSpfRecord, DomainStatus, DomainUpdatedEvent, DuplicateTemplateResponse, DuplicateTemplateResponseSuccess, EmailApiAttachment, EmailApiOptions, EmailBouncedEvent, EmailClickedEvent, EmailComplainedEvent, EmailDeliveredEvent, EmailDeliveryDelayedEvent, EmailFailedEvent, EmailOpenedEvent, EmailReceivedEvent, EmailScheduledEvent, EmailSentEvent, EmailSuppressedEvent, type ErrorResponse, Event, EventSchemaMap, EventSchemaType, ForwardReceivingEmailOptions, ForwardReceivingEmailResponse, ForwardReceivingEmailResponseSuccess, GetAttachmentOptions, GetAttachmentResponse, GetAttachmentResponseSuccess, GetBroadcastResponse, GetBroadcastResponseSuccess, GetContactOptions, GetContactPropertyResponse, GetContactPropertyResponseSuccess, GetContactResponse, GetContactResponseSuccess, GetDomainResponse, GetDomainResponseSuccess, GetEmailResponse, GetEmailResponseSuccess, GetEventResponse, GetEventResponseSuccess, GetOptions, GetReceivingEmailResponse, GetReceivingEmailResponseSuccess, GetSegmentResponse, GetSegmentResponseSuccess, GetTemplateResponse, GetTemplateResponseSuccess, GetTopicOptions, GetTopicResponse, GetTopicResponseSuccess, GetWebhookResponse, GetWebhookResponseSuccess, GetWorkflowResponse, GetWorkflowResponseSuccess, IdempotentRequest, InboundAttachment, LegacyCreateContactOptions, ListApiKeysOptions, ListApiKeysResponse, ListApiKeysResponseSuccess, ListAttachmentsOptions, ListAttachmentsResponse, ListAttachmentsResponseSuccess, ListBroadcastsOptions, ListBroadcastsResponse, ListBroadcastsResponseSuccess, ListContactPropertiesOptions, ListContactPropertiesResponse, ListContactPropertiesResponseSuccess, ListContactSegmentsOptions, ListContactSegmentsResponse, ListContactSegmentsResponseSuccess, ListContactTopicsOptions, ListContactTopicsRequestOptions, ListContactTopicsResponse, ListContactTopicsResponseSuccess, ListContactsOptions, ListContactsResponse, ListContactsResponseSuccess, ListDomainsOptions, ListDomainsResponse, ListDomainsResponseSuccess, ListEmail, ListEmailsOptions, ListEmailsResponse, ListEmailsResponseSuccess, ListEventsOptions, ListEventsResponse, ListEventsResponseSuccess, ListReceivingEmail, ListReceivingEmailsOptions, ListReceivingEmailsResponse, ListReceivingEmailsResponseSuccess, ListSegmentsOptions, ListSegmentsResponse, ListSegmentsResponseSuccess, ListTemplatesOptions, ListTemplatesResponse, ListTemplatesResponseSuccess, ListTopicsResponse, ListTopicsResponseSuccess, ListWebhooksOptions, ListWebhooksResponse, ListWebhooksResponseSuccess, ListWorkflowsOptions, ListWorkflowsResponse, ListWorkflowsResponseSuccess, PaginatedData, PaginationOptions, PatchOptions, PostOptions, PublishTemplateResponse, PublishTemplateResponseSuccess, PutOptions, ReceivingRecord, RemoveApiKeyResponse, RemoveApiKeyResponseSuccess, RemoveBroadcastResponse, RemoveBroadcastResponseSuccess, RemoveContactOptions, RemoveContactPropertyResponse, RemoveContactPropertyResponseSuccess, RemoveContactSegmentOptions, RemoveContactSegmentResponse, RemoveContactSegmentResponseSuccess, RemoveContactsResponse, RemoveContactsResponseSuccess, RemoveDomainsResponse, RemoveDomainsResponseSuccess, RemoveEventResponse, RemoveEventResponseSuccess, RemoveSegmentResponse, RemoveSegmentResponseSuccess, RemoveTemplateResponse, RemoveTemplateResponseSuccess, RemoveTopicResponse, RemoveTopicResponseSuccess, RemoveWebhookResponse, RemoveWebhookResponseSuccess, RemoveWorkflowResponse, RemoveWorkflowResponseSuccess, RequireAtLeastOne, Resend, type Response, Segment, SelectingField, SendBroadcastOptions, SendBroadcastRequestOptions, SendBroadcastResponse, SendBroadcastResponseSuccess, SendEmailStepConfig, SendEventOptions, SendEventResponse, SendEventResponseSuccess, Tag, Template, TemplateVariable, TemplateVariableValue, Topic, TriggerStepConfig, UpdateBroadcastOptions, UpdateBroadcastResponse, UpdateBroadcastResponseSuccess, UpdateContactOptions, UpdateContactPropertyApiOptions, UpdateContactPropertyOptions, UpdateContactPropertyResponse, UpdateContactPropertyResponseSuccess, UpdateContactResponse, UpdateContactResponseSuccess, UpdateContactTopicsOptions, UpdateContactTopicsRequestOptions, UpdateContactTopicsResponse, UpdateContactTopicsResponseSuccess, UpdateDomainsOptions, UpdateDomainsResponse, UpdateDomainsResponseSuccess, UpdateEmailOptions, UpdateEmailResponse, UpdateEmailResponseSuccess, UpdateEventOptions, UpdateEventResponse, UpdateEventResponseSuccess, UpdateTemplateOptions, UpdateTemplateResponse, UpdateTemplateResponseSuccess, UpdateTopicOptions, UpdateTopicResponse, UpdateTopicResponseSuccess, UpdateWebhookOptions, UpdateWebhookResponse, UpdateWebhookResponseSuccess, UpdateWorkflowOptions, UpdateWorkflowResponse, UpdateWorkflowResponseSuccess, VerifyDomainsResponse, VerifyDomainsResponseSuccess, WaitForEventStepConfig, Webhook, WebhookEvent, WebhookEventPayload, Workflow, WorkflowEdge, WorkflowEdgeType, WorkflowResponseEdge, WorkflowResponseStep, WorkflowStep };
package/dist/index.mjs CHANGED
@@ -2,7 +2,7 @@ import PostalMime from "postal-mime";
2
2
  import { Webhook } from "svix";
3
3
 
4
4
  //#region package.json
5
- var version = "6.9.3";
5
+ var version = "6.10.0-preview-workflows.0";
6
6
 
7
7
  //#endregion
8
8
  //#region src/common/utils/build-pagination-query.ts
@@ -675,6 +675,99 @@ var Emails = class {
675
675
  }
676
676
  };
677
677
 
678
+ //#endregion
679
+ //#region src/common/utils/parse-workflow-to-api-options.ts
680
+ function parseStepConfig(step) {
681
+ switch (step.type) {
682
+ case "trigger": return {
683
+ ref: step.ref,
684
+ type: step.type,
685
+ config: { event_name: step.config.eventName }
686
+ };
687
+ case "delay": return {
688
+ ref: step.ref,
689
+ type: step.type,
690
+ config: step.config
691
+ };
692
+ case "send_email": return {
693
+ ref: step.ref,
694
+ type: step.type,
695
+ config: {
696
+ template_id: step.config.templateId,
697
+ subject: step.config.subject,
698
+ from: step.config.from,
699
+ reply_to: step.config.replyTo,
700
+ variables: step.config.variables
701
+ }
702
+ };
703
+ case "wait_for_event": return {
704
+ ref: step.ref,
705
+ type: step.type,
706
+ config: {
707
+ event_name: step.config.eventName,
708
+ timeout_seconds: step.config.timeoutSeconds,
709
+ filter_rule: step.config.filterRule
710
+ }
711
+ };
712
+ case "condition": return {
713
+ ref: step.ref,
714
+ type: step.type,
715
+ config: step.config
716
+ };
717
+ }
718
+ }
719
+ function parseEdge(edge) {
720
+ return {
721
+ from: edge.from,
722
+ to: edge.to,
723
+ edge_type: edge.edgeType
724
+ };
725
+ }
726
+ function parseWorkflowToApiOptions(workflow) {
727
+ return {
728
+ name: workflow.name,
729
+ status: workflow.status,
730
+ steps: workflow.steps?.map(parseStepConfig),
731
+ edges: workflow.edges?.map(parseEdge)
732
+ };
733
+ }
734
+ function parseWorkflowEventToApiOptions(event) {
735
+ return {
736
+ event: event.event,
737
+ contact_id: event.contactId,
738
+ email: event.email,
739
+ payload: event.payload
740
+ };
741
+ }
742
+
743
+ //#endregion
744
+ //#region src/events/events.ts
745
+ var Events = class {
746
+ constructor(resend) {
747
+ this.resend = resend;
748
+ }
749
+ async send(payload) {
750
+ return await this.resend.post("/events/send", parseWorkflowEventToApiOptions(payload));
751
+ }
752
+ async create(payload) {
753
+ return await this.resend.post("/events", payload);
754
+ }
755
+ async get(identifier) {
756
+ return await this.resend.get(`/events/${encodeURIComponent(identifier)}`);
757
+ }
758
+ async list(options = {}) {
759
+ const queryString = buildPaginationQuery(options);
760
+ const url = queryString ? `/events?${queryString}` : "/events";
761
+ return await this.resend.get(url);
762
+ }
763
+ async update(identifier, payload) {
764
+ return await this.resend.patch(`/events/${encodeURIComponent(identifier)}`, payload);
765
+ }
766
+ async remove(identifier) {
767
+ return await this.resend.delete(`/events/${encodeURIComponent(identifier)}`);
768
+ }
769
+ };
770
+
678
771
  //#endregion
679
772
  //#region src/segments/segments.ts
680
773
  var Segments = class {
@@ -877,6 +970,31 @@ var Webhooks = class {
877
970
  }
878
971
  };
879
972
 
973
+ //#endregion
974
+ //#region src/workflows/workflows.ts
975
+ var Workflows = class {
976
+ constructor(resend) {
977
+ this.resend = resend;
978
+ }
979
+ async create(payload) {
980
+ return await this.resend.post("/workflows", parseWorkflowToApiOptions(payload));
981
+ }
982
+ async list(options = {}) {
983
+ const queryString = buildPaginationQuery(options);
984
+ const url = queryString ? `/workflows?${queryString}` : "/workflows";
985
+ return await this.resend.get(url);
986
+ }
987
+ async get(id) {
988
+ return await this.resend.get(`/workflows/${id}`);
989
+ }
990
+ async remove(id) {
991
+ return await this.resend.delete(`/workflows/${id}`);
992
+ }
993
+ async update(id, payload) {
994
+ return await this.resend.patch(`/workflows/${id}`, payload);
995
+ }
996
+ };
997
+
880
998
  //#endregion
881
999
  //#region src/resend.ts
882
1000
  const defaultBaseUrl = "https://api.resend.com";
@@ -895,9 +1013,11 @@ var Resend = class {
895
1013
  this.contactProperties = new ContactProperties(this);
896
1014
  this.domains = new Domains(this);
897
1015
  this.emails = new Emails(this);
1016
+ this.events = new Events(this);
898
1017
  this.webhooks = new Webhooks(this);
899
1018
  this.templates = new Templates(this);
900
1019
  this.topics = new Topics(this);
1020
+ this.workflows = new Workflows(this);
901
1021
  if (!key) {
902
1022
  if (typeof process !== "undefined" && process.env) this.key = process.env.RESEND_API_KEY;
903
1023
  if (!this.key) throw new Error("Missing API key. Pass it to the constructor `new Resend(\"re_123\")`");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "resend",
3
- "version": "6.9.3",
3
+ "version": "6.10.0-preview-workflows.0",
4
4
  "description": "Node.js library for the Resend API",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",