@sendery/sdk 0.1.2 → 0.1.4
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/CHANGELOG.md +8 -0
- package/README.md +23 -9
- package/dist/index.d.ts +3 -1
- package/dist/index.js +8 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ npm install @sendery/sdk
|
|
|
16
16
|
|
|
17
17
|
## Set up
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
Choose a published template and create a [project API key](https://sendery.co/en/docs/authentication). Store the key as `SENDERY_API_KEY` on your server.
|
|
20
20
|
|
|
21
21
|
```bash
|
|
22
22
|
export SENDERY_API_KEY="your_project_api_key"
|
|
@@ -24,6 +24,8 @@ export SENDERY_API_KEY="your_project_api_key"
|
|
|
24
24
|
|
|
25
25
|
## Send an email
|
|
26
26
|
|
|
27
|
+
Replace `your-template` with your published template’s key and `data` with its variables.
|
|
28
|
+
|
|
27
29
|
The response contains the accepted email’s `id` and `status`.
|
|
28
30
|
|
|
29
31
|
```javascript
|
|
@@ -35,18 +37,30 @@ if (!apiKey) throw new Error('Set SENDERY_API_KEY on your server.');
|
|
|
35
37
|
const sendery = new Sendery(apiKey);
|
|
36
38
|
const receipt = await sendery.send({
|
|
37
39
|
to: 'alex@example.com',
|
|
38
|
-
template: '
|
|
40
|
+
template: 'your-template',
|
|
39
41
|
data: { name: 'Alex', action_url: 'https://example.com/start' },
|
|
40
42
|
});
|
|
41
43
|
|
|
42
44
|
console.log(receipt.id);
|
|
43
45
|
```
|
|
44
46
|
|
|
47
|
+
## Send a specific version
|
|
48
|
+
|
|
49
|
+
Choose a [published template version](https://sendery.co/en/docs/send-email#section-5) to keep sending it after newer versions are published. By default, Sendery uses the latest version.
|
|
50
|
+
|
|
51
|
+
```javascript
|
|
52
|
+
const receipt = await sendery.prepare({
|
|
53
|
+
to: 'alex@example.com',
|
|
54
|
+
template: 'your-template',
|
|
55
|
+
data: { name: 'Alex', action_url: 'https://example.com/start' },
|
|
56
|
+
}).version(3).send();
|
|
57
|
+
```
|
|
58
|
+
|
|
45
59
|
## Attachments
|
|
46
60
|
|
|
47
61
|
Use `attachment()` to create an attachment from file bytes. The helper handles base64 encoding.
|
|
48
62
|
|
|
49
|
-
Send up to 10 files totaling 5 MB. See the [attachment reference](https://sendery.co/en/docs/send-email#section-
|
|
63
|
+
Send up to 10 files totaling 5 MB. See the [attachment reference](https://sendery.co/en/docs/send-email#section-6) for supported formats and limits.
|
|
50
64
|
|
|
51
65
|
```javascript
|
|
52
66
|
import { Sendery, attachment } from '@sendery/sdk';
|
|
@@ -57,10 +71,10 @@ const file = await readFile('/path/document.pdf');
|
|
|
57
71
|
|
|
58
72
|
await sendery.prepare({
|
|
59
73
|
to: 'alex@example.com',
|
|
60
|
-
template: '
|
|
74
|
+
template: 'your-template',
|
|
61
75
|
data: { name: 'Alex', action_url: 'https://example.com/start' },
|
|
62
76
|
attachments: [attachment('document.pdf', file, 'application/pdf')],
|
|
63
|
-
}, '
|
|
77
|
+
}, 'your-idempotency-key').retry().send();
|
|
64
78
|
```
|
|
65
79
|
|
|
66
80
|
In Next.js and Nuxt, use this in server-side routes or actions.
|
|
@@ -76,14 +90,14 @@ console.log(message.status);
|
|
|
76
90
|
|
|
77
91
|
## Retry a send
|
|
78
92
|
|
|
79
|
-
Use
|
|
93
|
+
Use `retry(3)` for up to three extra attempts after temporary failures. Keep the same [idempotency key and email data](https://sendery.co/en/docs/idempotency) on every attempt.
|
|
80
94
|
|
|
81
95
|
```javascript
|
|
82
96
|
const email = sendery.prepare({
|
|
83
97
|
to: 'alex@example.com',
|
|
84
|
-
template: '
|
|
98
|
+
template: 'your-template',
|
|
85
99
|
data: { name: 'Alex', action_url: 'https://example.com/start' },
|
|
86
|
-
}, '
|
|
100
|
+
}, 'your-idempotency-key');
|
|
87
101
|
|
|
88
102
|
const receipt = await email.retry(3).send();
|
|
89
103
|
```
|
|
@@ -113,7 +127,7 @@ Follow the server setup for [Next.js](https://sendery.co/en/docs/next) or [Nuxt]
|
|
|
113
127
|
|
|
114
128
|
## More
|
|
115
129
|
|
|
116
|
-
|
|
130
|
+
Learn how to [retry emails without duplicate sends](https://sendery.co/en/docs/idempotency).
|
|
117
131
|
|
|
118
132
|
## License
|
|
119
133
|
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export interface SendEmailInput {
|
|
|
11
11
|
template: string;
|
|
12
12
|
data: Variables;
|
|
13
13
|
locale?: string;
|
|
14
|
+
version?: number;
|
|
14
15
|
attachments?: Attachment[];
|
|
15
16
|
}
|
|
16
17
|
export interface SendReceipt {
|
|
@@ -30,10 +31,11 @@ export declare class SenderyError extends Error {
|
|
|
30
31
|
}
|
|
31
32
|
export declare class PendingEmail {
|
|
32
33
|
readonly idempotencyKey: string;
|
|
33
|
-
private
|
|
34
|
+
private body;
|
|
34
35
|
private readonly client;
|
|
35
36
|
private retries;
|
|
36
37
|
constructor(client: Sendery, input: SendEmailInput, key: string);
|
|
38
|
+
version(version: number): this;
|
|
37
39
|
retry(retries?: number): this;
|
|
38
40
|
send(): Promise<SendReceipt>;
|
|
39
41
|
}
|
package/dist/index.js
CHANGED
|
@@ -49,6 +49,14 @@ export class PendingEmail {
|
|
|
49
49
|
...(input.locale ? { locale: input.locale } : {}),
|
|
50
50
|
...(files.length ? { attachments: files } : {}),
|
|
51
51
|
});
|
|
52
|
+
if (input.version !== undefined)
|
|
53
|
+
this.version(input.version);
|
|
54
|
+
}
|
|
55
|
+
version(version) {
|
|
56
|
+
if (!Number.isSafeInteger(version) || version < 1)
|
|
57
|
+
throw new Error("Version must be a positive integer.");
|
|
58
|
+
this.body = JSON.stringify({ ...JSON.parse(this.body), version });
|
|
59
|
+
return this;
|
|
52
60
|
}
|
|
53
61
|
retry(retries = 3) {
|
|
54
62
|
if (!Number.isInteger(retries) || retries < 0 || retries > 5)
|