mailchannels-sdk 0.8.0-0 → 0.8.0-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/mailchannels.d.mts +86 -80
- package/dist/mailchannels.mjs +30 -3
- package/package.json +2 -2
package/dist/mailchannels.d.mts
CHANGED
|
@@ -832,6 +832,79 @@ type WebhooksValidateResponse = DataResponse<{
|
|
|
832
832
|
} | null;
|
|
833
833
|
}[];
|
|
834
834
|
}>;
|
|
835
|
+
type WebhookEventType = "processed" | "delivered" | "open" | "click" | "hard-bounced" | "soft-bounced" | "dropped" | "complained" | "unsubscribed" | "test";
|
|
836
|
+
interface WebhookEventBase<T extends WebhookEventType> {
|
|
837
|
+
/**
|
|
838
|
+
* The sender's email address
|
|
839
|
+
*/
|
|
840
|
+
email?: string;
|
|
841
|
+
/**
|
|
842
|
+
* The MailChannels account ID that generated the webhook.
|
|
843
|
+
* If the message was sent by a sub-account, this field contains the sub-account handle.
|
|
844
|
+
*/
|
|
845
|
+
customer_handle: string;
|
|
846
|
+
/**
|
|
847
|
+
* The Unix timestamp (in seconds) when the event occurred; the timezone is always UTC
|
|
848
|
+
*/
|
|
849
|
+
timestamp: number;
|
|
850
|
+
/**
|
|
851
|
+
* The Message-Id of the message that generated the event
|
|
852
|
+
*/
|
|
853
|
+
smtp_id?: string;
|
|
854
|
+
/**
|
|
855
|
+
* The type of event that occurred
|
|
856
|
+
*/
|
|
857
|
+
event: T;
|
|
858
|
+
/**
|
|
859
|
+
* A unique identifier generated to track the original HTTP request
|
|
860
|
+
*/
|
|
861
|
+
request_id?: string;
|
|
862
|
+
/**
|
|
863
|
+
* The campaign identifier for the message that generated the event
|
|
864
|
+
*/
|
|
865
|
+
campaign_id?: string;
|
|
866
|
+
/**
|
|
867
|
+
* The recipients of the message
|
|
868
|
+
*/
|
|
869
|
+
recipients?: string[];
|
|
870
|
+
}
|
|
871
|
+
interface WebhookEventProcessed extends WebhookEventBase<"processed"> {}
|
|
872
|
+
interface WebhookEventDelivered extends WebhookEventBase<"delivered"> {}
|
|
873
|
+
interface WebhookEventWithTracking {
|
|
874
|
+
/**
|
|
875
|
+
* The User-Agent header given when the recipient opened the message
|
|
876
|
+
*/
|
|
877
|
+
user_agent?: string;
|
|
878
|
+
/**
|
|
879
|
+
* The IP address of the host that made the HTTP request
|
|
880
|
+
*/
|
|
881
|
+
ip?: string;
|
|
882
|
+
}
|
|
883
|
+
interface WebhookEventOpen extends WebhookEventBase<"open">, WebhookEventWithTracking {}
|
|
884
|
+
interface WebhookEventClick extends WebhookEventBase<"click">, WebhookEventWithTracking {
|
|
885
|
+
/**
|
|
886
|
+
* The URL that was clicked by the recipient
|
|
887
|
+
*/
|
|
888
|
+
url?: string;
|
|
889
|
+
}
|
|
890
|
+
interface WebhookEventWithStatus {
|
|
891
|
+
/**
|
|
892
|
+
* The SMTP status code that caused the bounce
|
|
893
|
+
*/
|
|
894
|
+
status?: string;
|
|
895
|
+
/**
|
|
896
|
+
* A human-readable explanation of why the message hard-bounced
|
|
897
|
+
*/
|
|
898
|
+
reason?: string;
|
|
899
|
+
}
|
|
900
|
+
interface WebhookEventHardBounced extends WebhookEventBase<"hard-bounced">, WebhookEventWithStatus {}
|
|
901
|
+
interface WebhookEventSoftBounced extends WebhookEventBase<"soft-bounced">, WebhookEventWithStatus {}
|
|
902
|
+
interface WebhookEventDropped extends WebhookEventBase<"dropped">, WebhookEventWithStatus {}
|
|
903
|
+
interface WebhookEventComplained extends WebhookEventBase<"complained"> {}
|
|
904
|
+
interface WebhookEventUnsubscribed extends WebhookEventBase<"unsubscribed"> {}
|
|
905
|
+
interface WebhookEventTest extends Omit<WebhookEventBase<"test">, "recipients" | "campaign_id"> {}
|
|
906
|
+
type WebhookEvent = WebhookEventProcessed | WebhookEventDelivered | WebhookEventOpen | WebhookEventClick | WebhookEventHardBounced | WebhookEventSoftBounced | WebhookEventDropped | WebhookEventComplained | WebhookEventUnsubscribed | WebhookEventTest;
|
|
907
|
+
type WebhookEvents = WebhookEvent[];
|
|
835
908
|
interface WebhooksVerifyOptions {
|
|
836
909
|
/**
|
|
837
910
|
* The raw body of the incoming webhook request as a string. This should be the exact payload received from the webhook, without any modifications or parsing, to ensure accurate signature verification.
|
|
@@ -855,6 +928,12 @@ interface WebhooksVerifyOptions {
|
|
|
855
928
|
*/
|
|
856
929
|
cache?: boolean;
|
|
857
930
|
}
|
|
931
|
+
type WebhooksVerifyResponse = DataResponse<{
|
|
932
|
+
/**
|
|
933
|
+
* The type of event that occurred.
|
|
934
|
+
*/
|
|
935
|
+
event: WebhookEventType;
|
|
936
|
+
}[]>;
|
|
858
937
|
type WebhooksBatchStatus = "1xx" | "2xx" | "3xx" | "4xx" | "5xx" | "no_response";
|
|
859
938
|
type WebhooksBatchResponseStatus = "1xx_response" | "2xx_response" | "3xx_response" | "4xx_response" | "5xx_response" | "no_response";
|
|
860
939
|
interface WebhooksBatchesOptions {
|
|
@@ -981,10 +1060,10 @@ declare class Webhooks {
|
|
|
981
1060
|
* @example
|
|
982
1061
|
* ```ts
|
|
983
1062
|
* const mailchannels = new MailChannels('your-api-key')
|
|
984
|
-
* const { success, error } = await mailchannels.webhooks.
|
|
1063
|
+
* const { success, error } = await mailchannels.webhooks.deleteAll()
|
|
985
1064
|
* ```
|
|
986
1065
|
*/
|
|
987
|
-
|
|
1066
|
+
deleteAll(): Promise<SuccessResponse>;
|
|
988
1067
|
/**
|
|
989
1068
|
* Retrieves the public key used to verify signatures on incoming webhook payloads.
|
|
990
1069
|
* @param id - The ID of the key.
|
|
@@ -1010,20 +1089,20 @@ declare class Webhooks {
|
|
|
1010
1089
|
* @param options - The options for verifying the webhook.
|
|
1011
1090
|
* @example
|
|
1012
1091
|
* ```ts
|
|
1013
|
-
* const
|
|
1092
|
+
* const { data, error } = await Webhooks.verify({ payload: rawBody, headers })
|
|
1014
1093
|
* ```
|
|
1015
1094
|
*/
|
|
1016
|
-
static verify(options: WebhooksVerifyOptions): Promise<
|
|
1095
|
+
static verify(options: WebhooksVerifyOptions): Promise<WebhooksVerifyResponse>;
|
|
1017
1096
|
/**
|
|
1018
1097
|
* Verifies the authenticity of incoming webhook requests by validating their signatures using the provided options.
|
|
1019
1098
|
* @param options - The options for verifying the webhook.
|
|
1020
1099
|
* @example
|
|
1021
1100
|
* ```ts
|
|
1022
1101
|
* const mailchannels = new MailChannels('your-api-key')
|
|
1023
|
-
* const
|
|
1102
|
+
* const { data, error } = await mailchannels.webhooks.verify({ payload: rawBody, headers })
|
|
1024
1103
|
* ```
|
|
1025
1104
|
*/
|
|
1026
|
-
verify(options: WebhooksVerifyOptions): Promise<
|
|
1105
|
+
verify(options: WebhooksVerifyOptions): Promise<WebhooksVerifyResponse>;
|
|
1027
1106
|
/**
|
|
1028
1107
|
* Retrieves paged webhook batches associated with the customer. The time range specified by `createdAfter` and `createdBefore` must not exceed 31 days. If neither is specified, the default time range is the last 3 days.
|
|
1029
1108
|
* @param options - The options for listing webhook batches.
|
|
@@ -1664,79 +1743,6 @@ declare class Suppressions {
|
|
|
1664
1743
|
*/
|
|
1665
1744
|
list(options?: SuppressionsListOptions): Promise<SuppressionsListResponse>;
|
|
1666
1745
|
}
|
|
1667
|
-
type WebhookEventType = "processed" | "delivered" | "open" | "click" | "hard-bounced" | "soft-bounced" | "dropped" | "complained" | "unsubscribed" | "test";
|
|
1668
|
-
interface WebhookEventBase<T extends WebhookEventType> {
|
|
1669
|
-
/**
|
|
1670
|
-
* The sender's email address
|
|
1671
|
-
*/
|
|
1672
|
-
email?: string;
|
|
1673
|
-
/**
|
|
1674
|
-
* The MailChannels account ID that generated the webhook.
|
|
1675
|
-
* If the message was sent by a sub-account, this field contains the sub-account handle.
|
|
1676
|
-
*/
|
|
1677
|
-
customer_handle: string;
|
|
1678
|
-
/**
|
|
1679
|
-
* The Unix timestamp (in seconds) when the event occurred; the timezone is always UTC
|
|
1680
|
-
*/
|
|
1681
|
-
timestamp: number;
|
|
1682
|
-
/**
|
|
1683
|
-
* The Message-Id of the message that generated the event
|
|
1684
|
-
*/
|
|
1685
|
-
smtp_id?: string;
|
|
1686
|
-
/**
|
|
1687
|
-
* The type of event that occurred
|
|
1688
|
-
*/
|
|
1689
|
-
event: T;
|
|
1690
|
-
/**
|
|
1691
|
-
* A unique identifier generated to track the original HTTP request
|
|
1692
|
-
*/
|
|
1693
|
-
request_id?: string;
|
|
1694
|
-
/**
|
|
1695
|
-
* The campaign identifier for the message that generated the event
|
|
1696
|
-
*/
|
|
1697
|
-
campaign_id?: string;
|
|
1698
|
-
/**
|
|
1699
|
-
* The recipients of the message
|
|
1700
|
-
*/
|
|
1701
|
-
recipients?: string[];
|
|
1702
|
-
}
|
|
1703
|
-
interface WebhookEventProcessed extends WebhookEventBase<"processed"> {}
|
|
1704
|
-
interface WebhookEventDelivered extends WebhookEventBase<"delivered"> {}
|
|
1705
|
-
interface WebhookEventWithTracking {
|
|
1706
|
-
/**
|
|
1707
|
-
* The User-Agent header given when the recipient opened the message
|
|
1708
|
-
*/
|
|
1709
|
-
user_agent?: string;
|
|
1710
|
-
/**
|
|
1711
|
-
* The IP address of the host that made the HTTP request
|
|
1712
|
-
*/
|
|
1713
|
-
ip?: string;
|
|
1714
|
-
}
|
|
1715
|
-
interface WebhookEventOpen extends WebhookEventBase<"open">, WebhookEventWithTracking {}
|
|
1716
|
-
interface WebhookEventClick extends WebhookEventBase<"click">, WebhookEventWithTracking {
|
|
1717
|
-
/**
|
|
1718
|
-
* The URL that was clicked by the recipient
|
|
1719
|
-
*/
|
|
1720
|
-
url?: string;
|
|
1721
|
-
}
|
|
1722
|
-
interface WebhookEventWithStatus {
|
|
1723
|
-
/**
|
|
1724
|
-
* The SMTP status code that caused the bounce
|
|
1725
|
-
*/
|
|
1726
|
-
status?: string;
|
|
1727
|
-
/**
|
|
1728
|
-
* A human-readable explanation of why the message hard-bounced
|
|
1729
|
-
*/
|
|
1730
|
-
reason?: string;
|
|
1731
|
-
}
|
|
1732
|
-
interface WebhookEventHardBounced extends WebhookEventBase<"hard-bounced">, WebhookEventWithStatus {}
|
|
1733
|
-
interface WebhookEventSoftBounced extends WebhookEventBase<"soft-bounced">, WebhookEventWithStatus {}
|
|
1734
|
-
interface WebhookEventDropped extends WebhookEventBase<"dropped">, WebhookEventWithStatus {}
|
|
1735
|
-
interface WebhookEventComplained extends WebhookEventBase<"complained"> {}
|
|
1736
|
-
interface WebhookEventUnsubscribed extends WebhookEventBase<"unsubscribed"> {}
|
|
1737
|
-
interface WebhookEventTest extends Omit<WebhookEventBase<"test">, "recipients" | "campaign_id"> {}
|
|
1738
|
-
type WebhookEvent = WebhookEventProcessed | WebhookEventDelivered | WebhookEventOpen | WebhookEventClick | WebhookEventHardBounced | WebhookEventSoftBounced | WebhookEventDropped | WebhookEventComplained | WebhookEventUnsubscribed | WebhookEventTest;
|
|
1739
|
-
type WebhookEvents = WebhookEvent[];
|
|
1740
1746
|
declare class MailChannels extends MailChannelsClient {
|
|
1741
1747
|
readonly emails: Emails;
|
|
1742
1748
|
readonly domains: Domains;
|
|
@@ -1746,4 +1752,4 @@ declare class MailChannels extends MailChannelsClient {
|
|
|
1746
1752
|
readonly suppressions: Suppressions;
|
|
1747
1753
|
constructor(key: string, options?: MailChannelsClientOptions);
|
|
1748
1754
|
}
|
|
1749
|
-
export { DataResponse, Domains, DomainsCheckOptions, DomainsCheckResponse, DomainsCheckVerdict, DomainsDkimCreateOptions, DomainsDkimCreateResponse, DomainsDkimKey, DomainsDkimKeyStatus, DomainsDkimListOptions, DomainsDkimListResponse, DomainsDkimRotateOptions, DomainsDkimRotateResponse, DomainsDkimUpdateOptions, Emails, EmailsSendAsyncResponse, EmailsSendAttachment, EmailsSendContent, EmailsSendDkim, EmailsSendOptions, EmailsSendPersonalization, EmailsSendRecipient, EmailsSendRecipientInput, EmailsSendResponse, EmailsSendTemplate, EmailsSendTemplateType, EmailsSendTemplateValue, EmailsSendTracking, ErrorResponse, MailChannels, MailChannelsClient, MailChannelsClientOptions, Metrics, MetricsBucket, MetricsEngagement, MetricsEngagementResponse, MetricsOptions, MetricsPerformance, MetricsPerformanceResponse, MetricsRecipientBehaviour, MetricsRecipientBehaviourResponse, MetricsSenders, MetricsSendersOptions, MetricsSendersResponse, MetricsSendersType, MetricsUsageResponse, MetricsVolume, MetricsVolumeResponse, SubAccounts, SubAccountsAccount, SubAccountsApiKey, SubAccountsCreateApiKeyResponse, SubAccountsCreateResponse, SubAccountsCreateSmtpPasswordResponse, SubAccountsLimit, SubAccountsLimitResponse, SubAccountsListApiKeyOptions, SubAccountsListApiKeyResponse, SubAccountsListOptions, SubAccountsListResponse, SubAccountsListSmtpPasswordResponse, SubAccountsSmtpPassword, SubAccountsUsage, SubAccountsUsageResponse, SuccessResponse, Suppressions, SuppressionsCreateOptions, SuppressionsListEntry, SuppressionsListOptions, SuppressionsListResponse, SuppressionsSource, SuppressionsTypes, WebhookEvent, WebhookEventClick, WebhookEventComplained, WebhookEventDelivered, WebhookEventDropped, WebhookEventHardBounced, WebhookEventOpen, WebhookEventProcessed, WebhookEventSoftBounced, WebhookEventTest, WebhookEventType, WebhookEventUnsubscribed, WebhookEvents, Webhooks, WebhooksBatch, WebhooksBatchResponseStatus, WebhooksBatchStatus, WebhooksBatchesOptions, WebhooksBatchesResponse, WebhooksListResponse, WebhooksResendBatch, WebhooksResendBatchResponse, WebhooksSigningKeyResponse, WebhooksValidateResponse, WebhooksVerifyOptions };
|
|
1755
|
+
export { DataResponse, Domains, DomainsCheckOptions, DomainsCheckResponse, DomainsCheckVerdict, DomainsDkimCreateOptions, DomainsDkimCreateResponse, DomainsDkimKey, DomainsDkimKeyStatus, DomainsDkimListOptions, DomainsDkimListResponse, DomainsDkimRotateOptions, DomainsDkimRotateResponse, DomainsDkimUpdateOptions, Emails, EmailsSendAsyncResponse, EmailsSendAttachment, EmailsSendContent, EmailsSendDkim, EmailsSendOptions, EmailsSendPersonalization, EmailsSendRecipient, EmailsSendRecipientInput, EmailsSendResponse, EmailsSendTemplate, EmailsSendTemplateType, EmailsSendTemplateValue, EmailsSendTracking, ErrorResponse, MailChannels, MailChannelsClient, MailChannelsClientOptions, Metrics, MetricsBucket, MetricsEngagement, MetricsEngagementResponse, MetricsOptions, MetricsPerformance, MetricsPerformanceResponse, MetricsRecipientBehaviour, MetricsRecipientBehaviourResponse, MetricsSenders, MetricsSendersOptions, MetricsSendersResponse, MetricsSendersType, MetricsUsageResponse, MetricsVolume, MetricsVolumeResponse, SubAccounts, SubAccountsAccount, SubAccountsApiKey, SubAccountsCreateApiKeyResponse, SubAccountsCreateResponse, SubAccountsCreateSmtpPasswordResponse, SubAccountsLimit, SubAccountsLimitResponse, SubAccountsListApiKeyOptions, SubAccountsListApiKeyResponse, SubAccountsListOptions, SubAccountsListResponse, SubAccountsListSmtpPasswordResponse, SubAccountsSmtpPassword, SubAccountsUsage, SubAccountsUsageResponse, SuccessResponse, Suppressions, SuppressionsCreateOptions, SuppressionsListEntry, SuppressionsListOptions, SuppressionsListResponse, SuppressionsSource, SuppressionsTypes, WebhookEvent, WebhookEventClick, WebhookEventComplained, WebhookEventDelivered, WebhookEventDropped, WebhookEventHardBounced, WebhookEventOpen, WebhookEventProcessed, WebhookEventSoftBounced, WebhookEventTest, WebhookEventType, WebhookEventUnsubscribed, WebhookEvents, Webhooks, WebhooksBatch, WebhooksBatchResponseStatus, WebhooksBatchStatus, WebhooksBatchesOptions, WebhooksBatchesResponse, WebhooksListResponse, WebhooksResendBatch, WebhooksResendBatchResponse, WebhooksSigningKeyResponse, WebhooksValidateResponse, WebhooksVerifyOptions, WebhooksVerifyResponse };
|
package/dist/mailchannels.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { $fetch } from "ofetch";
|
|
2
2
|
import { subtle } from "node:crypto";
|
|
3
3
|
import { Buffer } from "node:buffer";
|
|
4
|
-
var version = "0.8.0-
|
|
4
|
+
var version = "0.8.0-1";
|
|
5
5
|
var MailChannelsClient = class MailChannelsClient {
|
|
6
6
|
static DEFAULT_BASE_URL = "https://api.mailchannels.net";
|
|
7
7
|
options;
|
|
@@ -733,7 +733,7 @@ var Webhooks = class Webhooks {
|
|
|
733
733
|
error: null
|
|
734
734
|
};
|
|
735
735
|
}
|
|
736
|
-
async
|
|
736
|
+
async deleteAll() {
|
|
737
737
|
let error = null;
|
|
738
738
|
await this.mailchannels.delete("/tx/v1/webhook", { onResponseError: async ({ response }) => {
|
|
739
739
|
error = getStatusError(response);
|
|
@@ -805,7 +805,34 @@ var Webhooks = class Webhooks {
|
|
|
805
805
|
};
|
|
806
806
|
}
|
|
807
807
|
static async verify(options) {
|
|
808
|
-
|
|
808
|
+
let error = null;
|
|
809
|
+
if (!await isValidWebhook(options).catch(() => false)) {
|
|
810
|
+
error = createError("Invalid webhook signature.");
|
|
811
|
+
return {
|
|
812
|
+
data: null,
|
|
813
|
+
error
|
|
814
|
+
};
|
|
815
|
+
}
|
|
816
|
+
try {
|
|
817
|
+
const payload = JSON.parse(options.payload);
|
|
818
|
+
if (!Array.isArray(payload)) {
|
|
819
|
+
error = createError("Invalid webhook payload.");
|
|
820
|
+
return {
|
|
821
|
+
data: null,
|
|
822
|
+
error
|
|
823
|
+
};
|
|
824
|
+
}
|
|
825
|
+
return {
|
|
826
|
+
data: clean(payload.map((event) => ({ event: event.event }))),
|
|
827
|
+
error: null
|
|
828
|
+
};
|
|
829
|
+
} catch {
|
|
830
|
+
error = createError("Invalid webhook payload.");
|
|
831
|
+
return {
|
|
832
|
+
data: null,
|
|
833
|
+
error
|
|
834
|
+
};
|
|
835
|
+
}
|
|
809
836
|
}
|
|
810
837
|
async verify(options) {
|
|
811
838
|
return Webhooks.verify(options);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mailchannels-sdk",
|
|
3
|
-
"version": "0.8.0-
|
|
3
|
+
"version": "0.8.0-1",
|
|
4
4
|
"description": "Node.js SDK to integrate MailChannels Email API into your JavaScript or TypeScript server-side applications.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"@vitest/coverage-v8": "^4.1.6",
|
|
48
48
|
"changelogen": "^0.6.2",
|
|
49
49
|
"obuild": "^0.4.35",
|
|
50
|
-
"oxlint": "^1.
|
|
50
|
+
"oxlint": "^1.65.0",
|
|
51
51
|
"scule": "^1.3.0",
|
|
52
52
|
"typescript": "^6.0.3",
|
|
53
53
|
"vitepress": "^2.0.0-alpha.17",
|