@sendery/sdk 0.1.7 → 0.1.9
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 +21 -3
- package/dist/index.d.ts +10 -6
- package/dist/index.js +16 -7
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -22,6 +22,19 @@ Choose a published template and create a [project API key](https://sendery.co/en
|
|
|
22
22
|
export SENDERY_API_KEY="your_project_api_key"
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
+
## Development and staging
|
|
26
|
+
|
|
27
|
+
Use a **Sandbox** API key for development and staging. Sendery prevents email and workflow delivery from that key, even when the project is live. Production requires a **Live** key and live sending enabled on the project. Keep keys on the server. Test event-definition changes in a separate sandbox project.
|
|
28
|
+
|
|
29
|
+
To get a published template’s content without sending or saving an email:
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
const content = await sendery.render({ template: 'welcome', data: { name: 'Steven' } });
|
|
33
|
+
// content.subject, content.html, content.text
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Rendering is limited to 10 requests per minute per workspace and 100 / 1,000 / 5,000 / 10,000 per calendar month on Free / Starter / Business / Scale or Enterprise. Render errors stop delivery.
|
|
37
|
+
|
|
25
38
|
## Send an email
|
|
26
39
|
|
|
27
40
|
Replace `your-template` with your published template’s key and `data` with its variables.
|
|
@@ -66,7 +79,10 @@ Send up to 10 files totaling 5 MB. See the [attachment reference](https://sender
|
|
|
66
79
|
import { Sendery, attachment } from '@sendery/sdk';
|
|
67
80
|
import { readFile } from 'node:fs/promises';
|
|
68
81
|
|
|
69
|
-
const
|
|
82
|
+
const apiKey = process.env.SENDERY_API_KEY;
|
|
83
|
+
if (!apiKey) throw new Error('Set SENDERY_API_KEY on your server.');
|
|
84
|
+
|
|
85
|
+
const sendery = new Sendery(apiKey);
|
|
70
86
|
const file = await readFile('/path/document.pdf');
|
|
71
87
|
|
|
72
88
|
await sendery.prepare({
|
|
@@ -137,14 +153,16 @@ Learn how to [retry emails without duplicate sends](https://sendery.co/en/docs/i
|
|
|
137
153
|
|
|
138
154
|
Send events such as account signups or orders from your app. Your team can use them to automate emails in Sendery, choosing the content, recipients, and timing. Available on all plans.
|
|
139
155
|
|
|
140
|
-
Start with [Connecting your application](https://sendery.co/en/docs/connect-events) to define the data Sendery can expect, then [send events](https://sendery.co/en/docs/send-events) as they happen.
|
|
156
|
+
Start with [Connecting your application](https://sendery.co/en/docs/connect-events) to define the data Sendery can expect, then [send events](https://sendery.co/en/docs/send-events) as they happen. Define at least one email address field and include an address when sending events.
|
|
141
157
|
|
|
142
158
|
```typescript
|
|
143
159
|
const receipt = await sendery.event({
|
|
144
|
-
name: "account.created",
|
|
160
|
+
name: "account.created", language: "en",
|
|
145
161
|
object: { type: "account", id: "842" },
|
|
146
162
|
data: { email: "steven@example.com", name: "Steven" },
|
|
147
163
|
}).retry().send();
|
|
148
164
|
```
|
|
149
165
|
|
|
166
|
+
`language` selects a published template translation; omit it to use the template’s default.
|
|
167
|
+
|
|
150
168
|
Retries reuse the same event data and idempotency key. To retry across jobs or process restarts, supply and persist your own key. A successful response confirms that Sendery accepted the event. [Learn what you can automate with workflows](https://sendery.co/en/docs/build-workflow).
|
package/dist/index.d.ts
CHANGED
|
@@ -13,12 +13,7 @@ export interface EventDefinition {
|
|
|
13
13
|
label: string;
|
|
14
14
|
};
|
|
15
15
|
fields: Record<string, EventField>;
|
|
16
|
-
|
|
17
|
-
label: string;
|
|
18
|
-
email: string;
|
|
19
|
-
name?: string;
|
|
20
|
-
locale?: string;
|
|
21
|
-
}>;
|
|
16
|
+
description?: string;
|
|
22
17
|
}
|
|
23
18
|
export interface EventType extends EventDefinition {
|
|
24
19
|
name: string;
|
|
@@ -45,9 +40,16 @@ export interface SendEmailInput {
|
|
|
45
40
|
version?: number;
|
|
46
41
|
attachments?: Attachment[];
|
|
47
42
|
}
|
|
43
|
+
export type RenderEmailInput = Pick<SendEmailInput, "template" | "data" | "locale" | "version">;
|
|
44
|
+
export interface RenderedEmail {
|
|
45
|
+
subject: string;
|
|
46
|
+
html: string;
|
|
47
|
+
text: string;
|
|
48
|
+
}
|
|
48
49
|
export interface SendReceipt {
|
|
49
50
|
id: string;
|
|
50
51
|
status: string;
|
|
52
|
+
sandbox_url?: string;
|
|
51
53
|
error_code?: string | null;
|
|
52
54
|
created_at?: string;
|
|
53
55
|
submitted_at?: string | null;
|
|
@@ -67,6 +69,7 @@ export interface EventInput {
|
|
|
67
69
|
id: string;
|
|
68
70
|
};
|
|
69
71
|
correlation_id?: string;
|
|
72
|
+
language?: string;
|
|
70
73
|
data: Record<string, unknown>;
|
|
71
74
|
}
|
|
72
75
|
export interface EventReceipt extends SendReceipt {
|
|
@@ -111,6 +114,7 @@ export declare class Sendery {
|
|
|
111
114
|
constructor(apiKey: string, baseUrl?: string);
|
|
112
115
|
prepare(input: SendEmailInput, idempotencyKey?: string): PendingEmail;
|
|
113
116
|
send(input: SendEmailInput, idempotencyKey?: string): Promise<SendReceipt>;
|
|
117
|
+
render(input: RenderEmailInput): Promise<RenderedEmail>;
|
|
114
118
|
defineEvent(name: string, definition: EventDefinition): Promise<EventTypeReceipt>;
|
|
115
119
|
getEventTypes(): Promise<EventType[]>;
|
|
116
120
|
event(input: EventInput, idempotencyKey?: string): PendingEvent;
|
package/dist/index.js
CHANGED
|
@@ -129,6 +129,13 @@ export class Sendery {
|
|
|
129
129
|
send(input, idempotencyKey) {
|
|
130
130
|
return this.prepare(input, idempotencyKey).send();
|
|
131
131
|
}
|
|
132
|
+
render(input) {
|
|
133
|
+
if (input.version !== undefined &&
|
|
134
|
+
(!Number.isSafeInteger(input.version) || input.version < 1))
|
|
135
|
+
throw new Error("Version must be a positive integer.");
|
|
136
|
+
const { template, data, locale, version } = input;
|
|
137
|
+
return this.request("POST", "/api/v1/emails/render", JSON.stringify({ template, data, locale, version }));
|
|
138
|
+
}
|
|
132
139
|
defineEvent(name, definition) {
|
|
133
140
|
return this.request("PUT", `/api/v1/event-types/${encodeURIComponent(name)}`, JSON.stringify(definition));
|
|
134
141
|
}
|
|
@@ -181,13 +188,15 @@ export class Sendery {
|
|
|
181
188
|
? Math.max(0, seconds)
|
|
182
189
|
: undefined);
|
|
183
190
|
}
|
|
184
|
-
const valid = path === "/api/v1/
|
|
185
|
-
?
|
|
186
|
-
: path
|
|
187
|
-
?
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
+
const valid = path === "/api/v1/emails/render"
|
|
192
|
+
? ["subject", "html", "text"].every((field) => typeof data[field] === "string")
|
|
193
|
+
: path === "/api/v1/event-types"
|
|
194
|
+
? Array.isArray(data.events)
|
|
195
|
+
: path.startsWith("/api/v1/event-types/")
|
|
196
|
+
? typeof data.name === "string" &&
|
|
197
|
+
typeof data.verified === "boolean"
|
|
198
|
+
: typeof data.id === "string" &&
|
|
199
|
+
typeof data.status === "string";
|
|
191
200
|
if (!valid)
|
|
192
201
|
throw new SenderyError(0, "invalid_response");
|
|
193
202
|
return data;
|