@tratto/email 1.0.0 → 1.1.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/README.md +16 -0
- package/dist/index.d.mts +45 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.js +2 -1
- package/dist/index.mjs +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -34,6 +34,22 @@ const { id } = await tratto.emails.send({
|
|
|
34
34
|
console.log('Sent email:', id);
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
+
Or write the email in [emailmd](https://www.emailmd.dev/) markdown — the API
|
|
38
|
+
renders it into responsive, email-safe HTML (plus a text part) server-side:
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
await tratto.emails.send({
|
|
42
|
+
from: 'Acme <hello@mail.acme.com>',
|
|
43
|
+
to: 'user@example.com',
|
|
44
|
+
subject: 'Welcome!',
|
|
45
|
+
markdown: '# Welcome, {{firstName}}\n\nGlad to have you on board.',
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
`markdown` is mutually exclusive with `html`. Templates accept it too:
|
|
50
|
+
`templates.create({ name, markdown })` creates a `format: 'emailmd'` template
|
|
51
|
+
whose HTML is rendered and pinned at save time.
|
|
52
|
+
|
|
37
53
|
---
|
|
38
54
|
|
|
39
55
|
## Setup
|
package/dist/index.d.mts
CHANGED
|
@@ -32,6 +32,12 @@ interface SendEmailParams {
|
|
|
32
32
|
to: string | string[];
|
|
33
33
|
subject: string;
|
|
34
34
|
html?: string;
|
|
35
|
+
/**
|
|
36
|
+
* emailmd markdown, rendered server-side into responsive email HTML
|
|
37
|
+
* (plus a text part). Mutually exclusive with `html` — the API rejects
|
|
38
|
+
* requests carrying both.
|
|
39
|
+
*/
|
|
40
|
+
markdown?: string;
|
|
35
41
|
text?: string;
|
|
36
42
|
cc?: string[];
|
|
37
43
|
bcc?: string[];
|
|
@@ -199,6 +205,7 @@ interface ListCampaignsParams {
|
|
|
199
205
|
interface SendCampaignParams {
|
|
200
206
|
scheduledAt?: Date | string;
|
|
201
207
|
}
|
|
208
|
+
type TemplateFormat = 'html' | 'emailmd';
|
|
202
209
|
type TemplateStatus = 'draft' | 'published';
|
|
203
210
|
interface TemplateSummary {
|
|
204
211
|
id: string;
|
|
@@ -209,15 +216,29 @@ interface TemplateSummary {
|
|
|
209
216
|
updatedAt: string;
|
|
210
217
|
}
|
|
211
218
|
interface Template extends TemplateSummary {
|
|
219
|
+
/** Always the pinned, ready-to-send HTML — for emailmd templates it is derived from `source`. */
|
|
212
220
|
html: string;
|
|
221
|
+
/** 'html' for templates created before formats existed. Immutable after creation. */
|
|
222
|
+
format: TemplateFormat;
|
|
223
|
+
/** The markdown source of truth for emailmd templates. */
|
|
224
|
+
source?: string;
|
|
225
|
+
renderWarnings?: string[];
|
|
213
226
|
}
|
|
214
227
|
interface CreateTemplateParams {
|
|
215
228
|
name: string;
|
|
216
229
|
html?: string;
|
|
230
|
+
/**
|
|
231
|
+
* emailmd markdown source. Creates a `format: 'emailmd'` template whose
|
|
232
|
+
* HTML is rendered server-side at save time. Mutually exclusive with
|
|
233
|
+
* `html` — sending both (or `html` on an emailmd template) is rejected.
|
|
234
|
+
*/
|
|
235
|
+
markdown?: string;
|
|
217
236
|
}
|
|
218
237
|
interface UpdateTemplateParams {
|
|
219
238
|
name?: string;
|
|
220
239
|
html?: string;
|
|
240
|
+
/** New markdown source for an emailmd template (re-rendered at save). */
|
|
241
|
+
markdown?: string;
|
|
221
242
|
status?: TemplateStatus;
|
|
222
243
|
}
|
|
223
244
|
interface ListTemplatesParams {
|
|
@@ -350,6 +371,20 @@ interface Workspace {
|
|
|
350
371
|
timezone: string;
|
|
351
372
|
locale: WorkspaceLocale;
|
|
352
373
|
plan: WorkspacePlan;
|
|
374
|
+
/** Workspace default sender, used when a send does not specify one. */
|
|
375
|
+
defaultFromName: string | null;
|
|
376
|
+
defaultFromEmail: string | null;
|
|
377
|
+
/**
|
|
378
|
+
* Tenant-hosted unsubscribe/preference page. When set, {{unsubscribe_url}}
|
|
379
|
+
* resolves here instead of the Tratto-hosted page.
|
|
380
|
+
*/
|
|
381
|
+
customUnsubscribeUrl: string | null;
|
|
382
|
+
/**
|
|
383
|
+
* Keep the "Sent using Tratto" branded footer on every HTML send even on a
|
|
384
|
+
* paid plan. On the free plan the branded footer is always applied
|
|
385
|
+
* regardless of this flag.
|
|
386
|
+
*/
|
|
387
|
+
keepTrattoBranding: boolean;
|
|
353
388
|
createdAt: string;
|
|
354
389
|
}
|
|
355
390
|
interface WorkspaceMember {
|
|
@@ -372,6 +407,16 @@ interface UpdateWorkspaceParams {
|
|
|
372
407
|
slug?: string;
|
|
373
408
|
timezone?: string;
|
|
374
409
|
locale?: WorkspaceLocale;
|
|
410
|
+
defaultFromName?: string;
|
|
411
|
+
defaultFromEmail?: string;
|
|
412
|
+
/** Set to null to clear and fall back to the Tratto-hosted page. */
|
|
413
|
+
customUnsubscribeUrl?: string | null;
|
|
414
|
+
/**
|
|
415
|
+
* Opt in to keep the branded footer on paid plans. Accepted on any plan
|
|
416
|
+
* (no effect on free, where branding is mandatory) and never auto-reset
|
|
417
|
+
* by plan changes.
|
|
418
|
+
*/
|
|
419
|
+
keepTrattoBranding?: boolean;
|
|
375
420
|
}
|
|
376
421
|
interface UpdateWorkspacePreferencesParams {
|
|
377
422
|
locale?: WorkspaceLocale;
|
package/dist/index.d.ts
CHANGED
|
@@ -32,6 +32,12 @@ interface SendEmailParams {
|
|
|
32
32
|
to: string | string[];
|
|
33
33
|
subject: string;
|
|
34
34
|
html?: string;
|
|
35
|
+
/**
|
|
36
|
+
* emailmd markdown, rendered server-side into responsive email HTML
|
|
37
|
+
* (plus a text part). Mutually exclusive with `html` — the API rejects
|
|
38
|
+
* requests carrying both.
|
|
39
|
+
*/
|
|
40
|
+
markdown?: string;
|
|
35
41
|
text?: string;
|
|
36
42
|
cc?: string[];
|
|
37
43
|
bcc?: string[];
|
|
@@ -199,6 +205,7 @@ interface ListCampaignsParams {
|
|
|
199
205
|
interface SendCampaignParams {
|
|
200
206
|
scheduledAt?: Date | string;
|
|
201
207
|
}
|
|
208
|
+
type TemplateFormat = 'html' | 'emailmd';
|
|
202
209
|
type TemplateStatus = 'draft' | 'published';
|
|
203
210
|
interface TemplateSummary {
|
|
204
211
|
id: string;
|
|
@@ -209,15 +216,29 @@ interface TemplateSummary {
|
|
|
209
216
|
updatedAt: string;
|
|
210
217
|
}
|
|
211
218
|
interface Template extends TemplateSummary {
|
|
219
|
+
/** Always the pinned, ready-to-send HTML — for emailmd templates it is derived from `source`. */
|
|
212
220
|
html: string;
|
|
221
|
+
/** 'html' for templates created before formats existed. Immutable after creation. */
|
|
222
|
+
format: TemplateFormat;
|
|
223
|
+
/** The markdown source of truth for emailmd templates. */
|
|
224
|
+
source?: string;
|
|
225
|
+
renderWarnings?: string[];
|
|
213
226
|
}
|
|
214
227
|
interface CreateTemplateParams {
|
|
215
228
|
name: string;
|
|
216
229
|
html?: string;
|
|
230
|
+
/**
|
|
231
|
+
* emailmd markdown source. Creates a `format: 'emailmd'` template whose
|
|
232
|
+
* HTML is rendered server-side at save time. Mutually exclusive with
|
|
233
|
+
* `html` — sending both (or `html` on an emailmd template) is rejected.
|
|
234
|
+
*/
|
|
235
|
+
markdown?: string;
|
|
217
236
|
}
|
|
218
237
|
interface UpdateTemplateParams {
|
|
219
238
|
name?: string;
|
|
220
239
|
html?: string;
|
|
240
|
+
/** New markdown source for an emailmd template (re-rendered at save). */
|
|
241
|
+
markdown?: string;
|
|
221
242
|
status?: TemplateStatus;
|
|
222
243
|
}
|
|
223
244
|
interface ListTemplatesParams {
|
|
@@ -350,6 +371,20 @@ interface Workspace {
|
|
|
350
371
|
timezone: string;
|
|
351
372
|
locale: WorkspaceLocale;
|
|
352
373
|
plan: WorkspacePlan;
|
|
374
|
+
/** Workspace default sender, used when a send does not specify one. */
|
|
375
|
+
defaultFromName: string | null;
|
|
376
|
+
defaultFromEmail: string | null;
|
|
377
|
+
/**
|
|
378
|
+
* Tenant-hosted unsubscribe/preference page. When set, {{unsubscribe_url}}
|
|
379
|
+
* resolves here instead of the Tratto-hosted page.
|
|
380
|
+
*/
|
|
381
|
+
customUnsubscribeUrl: string | null;
|
|
382
|
+
/**
|
|
383
|
+
* Keep the "Sent using Tratto" branded footer on every HTML send even on a
|
|
384
|
+
* paid plan. On the free plan the branded footer is always applied
|
|
385
|
+
* regardless of this flag.
|
|
386
|
+
*/
|
|
387
|
+
keepTrattoBranding: boolean;
|
|
353
388
|
createdAt: string;
|
|
354
389
|
}
|
|
355
390
|
interface WorkspaceMember {
|
|
@@ -372,6 +407,16 @@ interface UpdateWorkspaceParams {
|
|
|
372
407
|
slug?: string;
|
|
373
408
|
timezone?: string;
|
|
374
409
|
locale?: WorkspaceLocale;
|
|
410
|
+
defaultFromName?: string;
|
|
411
|
+
defaultFromEmail?: string;
|
|
412
|
+
/** Set to null to clear and fall back to the Tratto-hosted page. */
|
|
413
|
+
customUnsubscribeUrl?: string | null;
|
|
414
|
+
/**
|
|
415
|
+
* Opt in to keep the branded footer on paid plans. Accepted on any plan
|
|
416
|
+
* (no effect on free, where branding is mandatory) and never auto-reset
|
|
417
|
+
* by plan changes.
|
|
418
|
+
*/
|
|
419
|
+
keepTrattoBranding?: boolean;
|
|
375
420
|
}
|
|
376
421
|
interface UpdateWorkspacePreferencesParams {
|
|
377
422
|
locale?: WorkspaceLocale;
|
package/dist/index.js
CHANGED
|
@@ -212,7 +212,8 @@ var TemplatesResource = class extends BaseResource {
|
|
|
212
212
|
return this.fetch("GET", `/v1/templates${qs}`);
|
|
213
213
|
}
|
|
214
214
|
create(params) {
|
|
215
|
-
|
|
215
|
+
const body = params.markdown !== void 0 ? { ...params, format: "emailmd" } : params;
|
|
216
|
+
return this.fetchData("POST", "/v1/templates", { body });
|
|
216
217
|
}
|
|
217
218
|
get(id) {
|
|
218
219
|
return this.fetchData("GET", `/v1/templates/${id}`);
|
package/dist/index.mjs
CHANGED
|
@@ -185,7 +185,8 @@ var TemplatesResource = class extends BaseResource {
|
|
|
185
185
|
return this.fetch("GET", `/v1/templates${qs}`);
|
|
186
186
|
}
|
|
187
187
|
create(params) {
|
|
188
|
-
|
|
188
|
+
const body = params.markdown !== void 0 ? { ...params, format: "emailmd" } : params;
|
|
189
|
+
return this.fetchData("POST", "/v1/templates", { body });
|
|
189
190
|
}
|
|
190
191
|
get(id) {
|
|
191
192
|
return this.fetchData("GET", `/v1/templates/${id}`);
|