forked from deco-cx/apps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod.ts
84 lines (75 loc) · 1.9 KB
/
mod.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import type { App, AppContext as AC } from "deco/mod.ts";
import manifest, { Manifest } from "./manifest.gen.ts";
import { createHttpClient } from "../utils/http.ts";
import { ResendApi } from "./utils/client.ts";
import { fetchSafe } from "../utils/fetch.ts";
import type { Secret } from "../website/loaders/secret.ts";
import { previewFromMarkdown } from "../utils/preview.ts";
export interface EmailFrom {
name?: string;
domain?: string;
}
export interface Props {
/**@title API KEY Resend */
apiKey?: Secret;
/**
* @title Sender Options | Default
*/
emailFrom?: EmailFrom;
/**
* @title Receiver | Default
* @description List of recipients who received the email
*/
emailTo?: string[];
/**
* @title Subject | Default
*/
subject?: string;
}
export interface State extends Props {
apiWrite: ReturnType<typeof createHttpClient<ResendApi>>;
}
/**
* @title Resend
* @description app for sending emails using https://resend.com/
* @logo https://raw.githubusercontent.com/deco-cx/apps/main/resend/logo.png
*/
export default function App(
{
apiKey,
emailFrom = {
name: "Contact",
domain: "<onboarding@resend.dev>",
},
emailTo,
subject = "Contato via app resend",
}: State,
): App<Manifest, State> {
const apiKeyToken = typeof apiKey === "string"
? apiKey
: apiKey?.get?.() ?? "";
const apiWrite = createHttpClient<ResendApi>({
base: "https://api.resend.com/emails",
fetcher: fetchSafe,
headers: new Headers({
Authorization: `Bearer ${apiKeyToken}`,
"Content-Type": "application/json",
}),
});
const state = {
apiKey,
emailFrom,
emailTo,
subject,
apiWrite,
};
const app: App<Manifest, typeof state> = {
manifest,
state,
};
return app;
}
export type AppContext = AC<ReturnType<typeof App>>;
export const preview = previewFromMarkdown(
new URL("./README.md", import.meta.url),
);