@mailhooks/sdk 1.1.3 → 2.0.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/client.js CHANGED
@@ -1,13 +1,7 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.MailhooksClient = void 0;
7
- const axios_1 = __importDefault(require("axios"));
8
- class MailhooksClient {
1
+ import axios from 'axios';
2
+ export class MailhooksClient {
9
3
  constructor(config) {
10
- this.http = axios_1.default.create({
4
+ this.http = axios.create({
11
5
  baseURL: config.baseUrl ?? 'https://mailhooks.dev/api',
12
6
  headers: {
13
7
  'x-api-key': config.apiKey,
@@ -71,4 +65,3 @@ class MailhooksClient {
71
65
  return this.http;
72
66
  }
73
67
  }
74
- exports.MailhooksClient = MailhooksClient;
package/dist/index.js CHANGED
@@ -1,30 +1,8 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.constructSignature = exports.parseWebhookPayload = exports.verifyWebhookSignature = exports.EmailsResource = exports.Mailhooks = void 0;
18
- var mailhooks_1 = require("./mailhooks");
19
- Object.defineProperty(exports, "Mailhooks", { enumerable: true, get: function () { return mailhooks_1.Mailhooks; } });
20
- var emails_1 = require("./resources/emails");
21
- Object.defineProperty(exports, "EmailsResource", { enumerable: true, get: function () { return emails_1.EmailsResource; } });
22
- __exportStar(require("./types"), exports);
1
+ export { Mailhooks } from './mailhooks';
2
+ export { EmailsResource } from './resources/emails';
3
+ export * from './types';
23
4
  // Webhook verification utilities
24
- var webhooks_1 = require("./webhooks");
25
- Object.defineProperty(exports, "verifyWebhookSignature", { enumerable: true, get: function () { return webhooks_1.verifyWebhookSignature; } });
26
- Object.defineProperty(exports, "parseWebhookPayload", { enumerable: true, get: function () { return webhooks_1.parseWebhookPayload; } });
27
- Object.defineProperty(exports, "constructSignature", { enumerable: true, get: function () { return webhooks_1.constructSignature; } });
5
+ export { verifyWebhookSignature, parseWebhookPayload, constructSignature, } from './webhooks';
28
6
  // Default export for convenience
29
- const mailhooks_2 = require("./mailhooks");
30
- exports.default = mailhooks_2.Mailhooks;
7
+ import { Mailhooks } from './mailhooks';
8
+ export default Mailhooks;
package/dist/mailhooks.js CHANGED
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Mailhooks = void 0;
4
- const emails_1 = require("./resources/emails");
5
- class Mailhooks {
1
+ import { EmailsResource } from './resources/emails';
2
+ export class Mailhooks {
6
3
  constructor(config) {
7
- this.emails = new emails_1.EmailsResource(config);
4
+ this.emails = new EmailsResource(config);
8
5
  }
9
6
  /**
10
7
  * Create a new Mailhooks SDK instance
@@ -13,4 +10,3 @@ class Mailhooks {
13
10
  return new Mailhooks(config);
14
11
  }
15
12
  }
16
- exports.Mailhooks = Mailhooks;
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EmailsResource = void 0;
4
- const client_1 = require("../client");
5
- class EmailsResource extends client_1.MailhooksClient {
1
+ import { MailhooksClient } from '../client';
2
+ export class EmailsResource extends MailhooksClient {
6
3
  /**
7
4
  * Get a paginated list of emails
8
5
  */
@@ -197,4 +194,3 @@ class EmailsResource extends client_1.MailhooksClient {
197
194
  }
198
195
  }
199
196
  }
200
- exports.EmailsResource = EmailsResource;
package/dist/types.js CHANGED
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
package/dist/webhooks.js CHANGED
@@ -1,9 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.verifyWebhookSignature = verifyWebhookSignature;
4
- exports.parseWebhookPayload = parseWebhookPayload;
5
- exports.constructSignature = constructSignature;
6
- const crypto_1 = require("crypto");
1
+ import { createHmac, timingSafeEqual } from 'crypto';
7
2
  /**
8
3
  * Verifies a webhook signature using HMAC-SHA256.
9
4
  *
@@ -34,7 +29,7 @@ const crypto_1 = require("crypto");
34
29
  * });
35
30
  * ```
36
31
  */
37
- function verifyWebhookSignature(payload, signature, secret) {
32
+ export function verifyWebhookSignature(payload, signature, secret) {
38
33
  if (!payload || !signature || !secret) {
39
34
  return false;
40
35
  }
@@ -43,12 +38,12 @@ function verifyWebhookSignature(payload, signature, secret) {
43
38
  if (!/^[a-f0-9]{64}$/.test(normalizedSignature)) {
44
39
  return false;
45
40
  }
46
- const expectedSignature = (0, crypto_1.createHmac)('sha256', secret)
41
+ const expectedSignature = createHmac('sha256', secret)
47
42
  .update(payload)
48
43
  .digest('hex');
49
44
  // Use timing-safe comparison to prevent timing attacks
50
45
  // Both buffers are guaranteed to be 32 bytes (64 hex chars)
51
- return (0, crypto_1.timingSafeEqual)(Buffer.from(normalizedSignature, 'hex'), Buffer.from(expectedSignature, 'hex'));
46
+ return timingSafeEqual(Buffer.from(normalizedSignature, 'hex'), Buffer.from(expectedSignature, 'hex'));
52
47
  }
53
48
  /**
54
49
  * Parses a webhook payload from a JSON string.
@@ -65,7 +60,7 @@ function verifyWebhookSignature(payload, signature, secret) {
65
60
  * console.log(`Received email from ${payload.from}: ${payload.subject}`);
66
61
  * ```
67
62
  */
68
- function parseWebhookPayload(body) {
63
+ export function parseWebhookPayload(body) {
69
64
  return JSON.parse(body);
70
65
  }
71
66
  /**
@@ -76,6 +71,6 @@ function parseWebhookPayload(body) {
76
71
  * @param secret - Your webhook secret
77
72
  * @returns The expected HMAC-SHA256 signature as a hex string
78
73
  */
79
- function constructSignature(payload, secret) {
80
- return (0, crypto_1.createHmac)('sha256', secret).update(payload).digest('hex');
74
+ export function constructSignature(payload, secret) {
75
+ return createHmac('sha256', secret).update(payload).digest('hex');
81
76
  }
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@mailhooks/sdk",
3
- "version": "1.1.3",
3
+ "version": "2.0.0",
4
4
  "description": "TypeScript SDK for Mailhooks API",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
+ "type": "module",
8
9
  "main": "dist/index.js",
9
10
  "types": "dist/index.d.ts",
10
11
  "scripts": {
@@ -33,9 +34,9 @@
33
34
  ],
34
35
  "exports": {
35
36
  ".": {
37
+ "types": "./dist/index.d.ts",
36
38
  "import": "./dist/index.js",
37
- "require": "./dist/index.js",
38
- "types": "./dist/index.d.ts"
39
+ "default": "./dist/index.js"
39
40
  }
40
41
  }
41
42
  }