Skip to content

Commit 6039c22

Browse files
committed
wip
1 parent dccd93e commit 6039c22

19 files changed

+72
-27
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,5 @@ node_modules/
4040

4141
.DS_Store
4242

43-
.env
43+
.env
44+
/examples/**/package-lock.json

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ Note:
6565
1. Get your **free API key** here: <https://app.templateless.com>
6666
1. There are more JavaScript examples in the [examples](examples) folder
6767

68+
```bash
69+
TEMPLATELESS_API_KEY=<Your API Key> \
70+
TEMPLATELESS_EMAIL_ADDRESS=<Your Own Email Address> \
71+
node examples/simple
72+
```
73+
6874
## 🤝 Contributing
6975

7076
- Contributions are more than welcome <3

dist/bundle.cjs.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/bundle.esm.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/bundle.umd.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/collection.d.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Component, SocialItem } from './components';
2-
import { Result } from '.';
32
export declare class Collection {
43
components: Component[];
54
constructor(builder: CollectionBuilder);
@@ -15,7 +14,7 @@ declare class CollectionBuilder {
1514
socials(data: SocialItem[]): this;
1615
text(text: string): this;
1716
viewInBrowser(text: string): this;
18-
build(): Result<Collection>;
17+
build(): Collection;
1918
private push;
2019
}
2120
export {};

dist/content.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Component, SocialItem } from './components';
2-
import { Result, Header, Footer } from '.';
2+
import { Header, Footer } from '.';
33
export declare enum Theme {
44
Unstyled = "UNSTYLED",
55
Simple = "SIMPLE"
@@ -29,7 +29,7 @@ declare class ContentBuilder {
2929
socials(data: SocialItem[]): this;
3030
text(text: string): this;
3131
viewInBrowser(text: string): this;
32-
build(): Result<Content>;
32+
build(): Content;
3333
private push;
3434
}
3535
export {};

dist/email.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { EmailAddress, Result } from '.';
1+
import { EmailAddress } from '.';
22
interface EmailOptions {
33
deleteAfter?: number;
44
}
@@ -24,6 +24,6 @@ declare class EmailBuilder {
2424
subject(subject: string): this;
2525
content(content: Content): this;
2626
deleteAfter(seconds: number): this;
27-
build(): Result<Email>;
27+
build(): Email;
2828
}
2929
export {};

dist/errors.d.ts

-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,3 @@ export declare class UnknownError extends Error {
2626
constructor();
2727
}
2828
export type TemplatelessError = UnauthorizedError | ForbiddenError | InvalidParameterError | BadRequestError | UnavailableError | UnknownError;
29-
export type Result<T> = T | TemplatelessError;

dist/templateless.d.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Email, Result, ObjectId } from '.';
1+
import { Email, ObjectId } from '.';
22
export interface EmailResponse {
33
emails: ObjectId[];
44
}
@@ -7,6 +7,6 @@ export declare class Templateless {
77
private _domain;
88
constructor(apiKey: string);
99
domain(domain: string): this;
10-
send(email: Email): Promise<Result<ObjectId[]>>;
11-
sendMany(emails: Email[]): Promise<Result<ObjectId[]>>;
10+
send(email: Email): Promise<ObjectId[]>;
11+
sendMany(emails: Email[]): Promise<ObjectId[]>;
1212
}

examples/simple.js

Whitespace-only changes.

examples/simple/index.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import 'dotenv/config'
2+
import { Content, Email, EmailAddress, Templateless } from 'templateless-js'
3+
4+
const sendEmail = async () => {
5+
let api_key = process.env.TEMPLATELESS_API_KEY
6+
if (!api_key) {
7+
console.error('Set TEMPLATELESS_API_KEY to your Templateless API key')
8+
return
9+
}
10+
11+
let email_address = process.env.TEMPLATELESS_EMAIL_ADDRESS
12+
if (!email_address) {
13+
console.error('Set TEMPLATELESS_EMAIL_ADDRESS to your own email address')
14+
return
15+
}
16+
17+
const content = Content.builder().text('Hello world').build()
18+
19+
const email = Email.builder()
20+
.to(new EmailAddress(email_address))
21+
.subject('Hello')
22+
.content(content)
23+
.build()
24+
25+
const templateless = new Templateless(api_key)
26+
const result = await templateless.send(email)
27+
28+
console.log(result)
29+
}
30+
31+
sendEmail()

examples/simple/package.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "templateless-js-example-simple",
3+
"version": "0.0.0",
4+
"private": true,
5+
"type": "module",
6+
"scripts": {
7+
"dev": "node index.js"
8+
},
9+
"dependencies": {
10+
"templateless-js": "file:../..",
11+
"dotenv": "16.4.1"
12+
}
13+
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "templateless-js",
3-
"version": "0.1.0-alpha.0",
3+
"version": "0.1.0-alpha.1",
44
"description": "Ship faster by sending elegant emails using just code",
55
"author": "",
66
"keywords": [

src/collection.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
ViewInBrowser,
1010
SocialItem,
1111
} from './components'
12-
import { Result } from '.'
1312

1413
export class Collection {
1514
components: Component[]
@@ -66,7 +65,7 @@ class CollectionBuilder {
6665
return this.push(new ViewInBrowser(text))
6766
}
6867

69-
build(): Result<Collection> {
68+
build(): Collection {
7069
return new Collection(this)
7170
}
7271

src/content.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
ViewInBrowser,
1010
SocialItem,
1111
} from './components'
12-
import { Result, Header, Footer } from '.'
12+
import { Header, Footer } from '.'
1313

1414
export enum Theme {
1515
Unstyled = 'UNSTYLED',
@@ -100,7 +100,7 @@ class ContentBuilder {
100100
return this.push(new ViewInBrowser(text))
101101
}
102102

103-
build(): Result<Content> {
103+
build(): Content {
104104
return new Content(this)
105105
}
106106

src/email.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { EmailAddress, Result } from '.'
1+
import { EmailAddress } from '.'
22

33
interface EmailOptions {
44
deleteAfter?: number
@@ -66,7 +66,7 @@ class EmailBuilder {
6666
return this
6767
}
6868

69-
build(): Result<Email> {
69+
build(): Email {
7070
return new Email(this)
7171
}
7272
}

src/errors.ts

-2
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,3 @@ export type TemplatelessError =
6262
| BadRequestError
6363
| UnavailableError
6464
| UnknownError
65-
66-
export type Result<T> = T | TemplatelessError

src/templateless.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import axios from 'axios'
33
import pkg from '../package.json'
44
import {
55
Email,
6-
Result,
76
ObjectId,
87
UnauthorizedError,
98
ForbiddenError,
@@ -31,11 +30,11 @@ export class Templateless {
3130
return this
3231
}
3332

34-
async send(email: Email): Promise<Result<ObjectId[]>> {
33+
async send(email: Email): Promise<ObjectId[]> {
3534
return this.sendMany([email])
3635
}
3736

38-
async sendMany(emails: Email[]): Promise<Result<ObjectId[]>> {
37+
async sendMany(emails: Email[]): Promise<ObjectId[]> {
3938
try {
4039
const response = await axios.post(
4140
`${this._domain}/v1/emails`,
@@ -68,7 +67,7 @@ export class Templateless {
6867
throw new UnknownError()
6968
}
7069
} catch (error) {
71-
return new UnknownError()
70+
throw new UnknownError()
7271
}
7372
}
7473
}

0 commit comments

Comments
 (0)