@sendery/sdk 0.1.7 → 0.1.8
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 +4 -0
- package/README.md +17 -1
- package/dist/index.d.ts +8 -0
- 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({
|
package/dist/index.d.ts
CHANGED
|
@@ -45,9 +45,16 @@ export interface SendEmailInput {
|
|
|
45
45
|
version?: number;
|
|
46
46
|
attachments?: Attachment[];
|
|
47
47
|
}
|
|
48
|
+
export type RenderEmailInput = Pick<SendEmailInput, "template" | "data" | "locale" | "version">;
|
|
49
|
+
export interface RenderedEmail {
|
|
50
|
+
subject: string;
|
|
51
|
+
html: string;
|
|
52
|
+
text: string;
|
|
53
|
+
}
|
|
48
54
|
export interface SendReceipt {
|
|
49
55
|
id: string;
|
|
50
56
|
status: string;
|
|
57
|
+
sandbox_url?: string;
|
|
51
58
|
error_code?: string | null;
|
|
52
59
|
created_at?: string;
|
|
53
60
|
submitted_at?: string | null;
|
|
@@ -111,6 +118,7 @@ export declare class Sendery {
|
|
|
111
118
|
constructor(apiKey: string, baseUrl?: string);
|
|
112
119
|
prepare(input: SendEmailInput, idempotencyKey?: string): PendingEmail;
|
|
113
120
|
send(input: SendEmailInput, idempotencyKey?: string): Promise<SendReceipt>;
|
|
121
|
+
render(input: RenderEmailInput): Promise<RenderedEmail>;
|
|
114
122
|
defineEvent(name: string, definition: EventDefinition): Promise<EventTypeReceipt>;
|
|
115
123
|
getEventTypes(): Promise<EventType[]>;
|
|
116
124
|
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;
|