@easybits.cloud/mailmask 0.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/dist/index.cjs +176 -0
- package/dist/index.d.cts +189 -0
- package/dist/index.d.ts +189 -0
- package/dist/index.js +148 -0
- package/package.json +27 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
MailMask: () => MailMask,
|
|
24
|
+
MailMaskError: () => MailMaskError
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
|
|
28
|
+
// src/client.ts
|
|
29
|
+
var MailMaskError = class extends Error {
|
|
30
|
+
constructor(status, message) {
|
|
31
|
+
super(message);
|
|
32
|
+
this.status = status;
|
|
33
|
+
this.name = "MailMaskError";
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
async function request(baseUrl, apiKey, path, opts) {
|
|
37
|
+
const res = await fetch(`${baseUrl}${path}`, {
|
|
38
|
+
...opts,
|
|
39
|
+
headers: {
|
|
40
|
+
"Authorization": `Bearer ${apiKey}`,
|
|
41
|
+
"Content-Type": "application/json",
|
|
42
|
+
...opts?.headers
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
if (!res.ok) {
|
|
46
|
+
const body = await res.json().catch(() => ({ error: res.statusText }));
|
|
47
|
+
throw new MailMaskError(res.status, body.error || res.statusText);
|
|
48
|
+
}
|
|
49
|
+
return res.json();
|
|
50
|
+
}
|
|
51
|
+
var MailMask = class {
|
|
52
|
+
constructor(config) {
|
|
53
|
+
this.apiKey = config.apiKey;
|
|
54
|
+
this.baseUrl = (config.baseUrl || "https://www.mailmask.studio").replace(/\/$/, "");
|
|
55
|
+
const req = (path, opts) => request(this.baseUrl, this.apiKey, path, opts);
|
|
56
|
+
this.domains = new DomainsResource(req);
|
|
57
|
+
this.aliases = new AliasesResource(req);
|
|
58
|
+
this.rules = new RulesResource(req);
|
|
59
|
+
this.logs = new LogsResource(req);
|
|
60
|
+
this.send = new SendResource(req);
|
|
61
|
+
this.smtp = new SmtpResource(req);
|
|
62
|
+
this.apiKeys = new ApiKeysResource(req);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
var DomainsResource = class {
|
|
66
|
+
constructor(req) {
|
|
67
|
+
this.req = req;
|
|
68
|
+
}
|
|
69
|
+
list() {
|
|
70
|
+
return this.req("/api/domains");
|
|
71
|
+
}
|
|
72
|
+
get(id) {
|
|
73
|
+
return this.req(`/api/domains/${id}`);
|
|
74
|
+
}
|
|
75
|
+
create(domain) {
|
|
76
|
+
return this.req("/api/domains", { method: "POST", body: JSON.stringify({ domain }) });
|
|
77
|
+
}
|
|
78
|
+
delete(id) {
|
|
79
|
+
return this.req(`/api/domains/${id}`, { method: "DELETE" });
|
|
80
|
+
}
|
|
81
|
+
health(id) {
|
|
82
|
+
return this.req(`/api/domains/${id}/health`);
|
|
83
|
+
}
|
|
84
|
+
verify(id) {
|
|
85
|
+
return this.req(`/api/domains/${id}/verify`, { method: "POST" });
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
var AliasesResource = class {
|
|
89
|
+
constructor(req) {
|
|
90
|
+
this.req = req;
|
|
91
|
+
}
|
|
92
|
+
list(domainId) {
|
|
93
|
+
return this.req(`/api/domains/${domainId}/aliases`);
|
|
94
|
+
}
|
|
95
|
+
create(domainId, input) {
|
|
96
|
+
return this.req(`/api/domains/${domainId}/aliases`, { method: "POST", body: JSON.stringify(input) });
|
|
97
|
+
}
|
|
98
|
+
update(domainId, alias, input) {
|
|
99
|
+
return this.req(`/api/domains/${domainId}/aliases/${alias}`, { method: "PUT", body: JSON.stringify(input) });
|
|
100
|
+
}
|
|
101
|
+
delete(domainId, alias) {
|
|
102
|
+
return this.req(`/api/domains/${domainId}/aliases/${alias}`, { method: "DELETE" });
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
var RulesResource = class {
|
|
106
|
+
constructor(req) {
|
|
107
|
+
this.req = req;
|
|
108
|
+
}
|
|
109
|
+
list(domainId) {
|
|
110
|
+
return this.req(`/api/domains/${domainId}/rules`);
|
|
111
|
+
}
|
|
112
|
+
create(domainId, input) {
|
|
113
|
+
return this.req(`/api/domains/${domainId}/rules`, { method: "POST", body: JSON.stringify(input) });
|
|
114
|
+
}
|
|
115
|
+
update(domainId, ruleId, input) {
|
|
116
|
+
return this.req(`/api/domains/${domainId}/rules/${ruleId}`, { method: "PUT", body: JSON.stringify(input) });
|
|
117
|
+
}
|
|
118
|
+
delete(domainId, ruleId) {
|
|
119
|
+
return this.req(`/api/domains/${domainId}/rules/${ruleId}`, { method: "DELETE" });
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
var LogsResource = class {
|
|
123
|
+
constructor(req) {
|
|
124
|
+
this.req = req;
|
|
125
|
+
}
|
|
126
|
+
list(domainId) {
|
|
127
|
+
return this.req(`/api/domains/${domainId}/logs`);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
var SendResource = class {
|
|
131
|
+
constructor(req) {
|
|
132
|
+
this.req = req;
|
|
133
|
+
}
|
|
134
|
+
send(domainId, input) {
|
|
135
|
+
return this.req(`/api/domains/${domainId}/send`, { method: "POST", body: JSON.stringify(input) });
|
|
136
|
+
}
|
|
137
|
+
bulkSend(domainId, input) {
|
|
138
|
+
return this.req(`/api/domains/${domainId}/bulk-send`, { method: "POST", body: JSON.stringify(input) });
|
|
139
|
+
}
|
|
140
|
+
bulkStatus(domainId, jobId) {
|
|
141
|
+
return this.req(`/api/domains/${domainId}/bulk-send/${jobId}`);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
var SmtpResource = class {
|
|
145
|
+
constructor(req) {
|
|
146
|
+
this.req = req;
|
|
147
|
+
}
|
|
148
|
+
list(domainId) {
|
|
149
|
+
return this.req(`/api/domains/${domainId}/smtp-credentials`);
|
|
150
|
+
}
|
|
151
|
+
create(domainId, label) {
|
|
152
|
+
return this.req(`/api/domains/${domainId}/smtp-credentials`, { method: "POST", body: JSON.stringify({ label }) });
|
|
153
|
+
}
|
|
154
|
+
revoke(domainId, credId) {
|
|
155
|
+
return this.req(`/api/domains/${domainId}/smtp-credentials/${credId}`, { method: "DELETE" });
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
var ApiKeysResource = class {
|
|
159
|
+
constructor(req) {
|
|
160
|
+
this.req = req;
|
|
161
|
+
}
|
|
162
|
+
list() {
|
|
163
|
+
return this.req("/api/api-keys");
|
|
164
|
+
}
|
|
165
|
+
create(name) {
|
|
166
|
+
return this.req("/api/api-keys", { method: "POST", body: JSON.stringify({ name }) });
|
|
167
|
+
}
|
|
168
|
+
revoke(id) {
|
|
169
|
+
return this.req(`/api/api-keys/${id}`, { method: "DELETE" });
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
173
|
+
0 && (module.exports = {
|
|
174
|
+
MailMask,
|
|
175
|
+
MailMaskError
|
|
176
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
interface MailMaskConfig {
|
|
2
|
+
apiKey: string;
|
|
3
|
+
baseUrl?: string;
|
|
4
|
+
}
|
|
5
|
+
interface Domain {
|
|
6
|
+
id: string;
|
|
7
|
+
domain: string;
|
|
8
|
+
verified: boolean;
|
|
9
|
+
mxConfigured: boolean;
|
|
10
|
+
createdAt: string;
|
|
11
|
+
}
|
|
12
|
+
interface Alias {
|
|
13
|
+
alias: string;
|
|
14
|
+
domainId: string;
|
|
15
|
+
destinations: string[];
|
|
16
|
+
enabled: boolean;
|
|
17
|
+
forwardCount: number;
|
|
18
|
+
createdAt: string;
|
|
19
|
+
}
|
|
20
|
+
interface CreateAliasInput {
|
|
21
|
+
local: string;
|
|
22
|
+
forwardTo: string | string[];
|
|
23
|
+
}
|
|
24
|
+
interface UpdateAliasInput {
|
|
25
|
+
enabled?: boolean;
|
|
26
|
+
destinations?: string[];
|
|
27
|
+
}
|
|
28
|
+
interface Rule {
|
|
29
|
+
id: string;
|
|
30
|
+
domainId: string;
|
|
31
|
+
field: "to" | "from" | "subject";
|
|
32
|
+
match: string;
|
|
33
|
+
value: string;
|
|
34
|
+
action: string;
|
|
35
|
+
target: string;
|
|
36
|
+
priority: number;
|
|
37
|
+
enabled: boolean;
|
|
38
|
+
createdAt: string;
|
|
39
|
+
}
|
|
40
|
+
interface CreateRuleInput {
|
|
41
|
+
field: "to" | "from" | "subject";
|
|
42
|
+
match: string;
|
|
43
|
+
value: string;
|
|
44
|
+
action: string;
|
|
45
|
+
target: string;
|
|
46
|
+
priority?: number;
|
|
47
|
+
}
|
|
48
|
+
interface UpdateRuleInput {
|
|
49
|
+
field?: "to" | "from" | "subject";
|
|
50
|
+
match?: string;
|
|
51
|
+
value?: string;
|
|
52
|
+
action?: string;
|
|
53
|
+
target?: string;
|
|
54
|
+
priority?: number;
|
|
55
|
+
enabled?: boolean;
|
|
56
|
+
}
|
|
57
|
+
interface EmailLog {
|
|
58
|
+
id: string;
|
|
59
|
+
domainId: string;
|
|
60
|
+
timestamp: string;
|
|
61
|
+
from: string;
|
|
62
|
+
to: string;
|
|
63
|
+
subject: string;
|
|
64
|
+
status: string;
|
|
65
|
+
forwardedTo: string;
|
|
66
|
+
error?: string;
|
|
67
|
+
}
|
|
68
|
+
interface SendEmailInput {
|
|
69
|
+
fromLocal: string;
|
|
70
|
+
to: string;
|
|
71
|
+
subject: string;
|
|
72
|
+
html: string;
|
|
73
|
+
}
|
|
74
|
+
interface BulkSendInput {
|
|
75
|
+
from: string;
|
|
76
|
+
recipients: string[];
|
|
77
|
+
subject: string;
|
|
78
|
+
html: string;
|
|
79
|
+
}
|
|
80
|
+
interface BulkJob {
|
|
81
|
+
id: string;
|
|
82
|
+
status: string;
|
|
83
|
+
totalRecipients: number;
|
|
84
|
+
sent: number;
|
|
85
|
+
failed: number;
|
|
86
|
+
}
|
|
87
|
+
interface SmtpCredential {
|
|
88
|
+
id: string;
|
|
89
|
+
domainId: string;
|
|
90
|
+
label: string;
|
|
91
|
+
iamUsername: string;
|
|
92
|
+
createdAt: string;
|
|
93
|
+
}
|
|
94
|
+
interface ApiKey {
|
|
95
|
+
id: string;
|
|
96
|
+
name: string;
|
|
97
|
+
lastUsedAt?: string;
|
|
98
|
+
createdAt: string;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
declare class MailMaskError extends Error {
|
|
102
|
+
status: number;
|
|
103
|
+
constructor(status: number, message: string);
|
|
104
|
+
}
|
|
105
|
+
declare class MailMask {
|
|
106
|
+
private baseUrl;
|
|
107
|
+
private apiKey;
|
|
108
|
+
domains: DomainsResource;
|
|
109
|
+
aliases: AliasesResource;
|
|
110
|
+
rules: RulesResource;
|
|
111
|
+
logs: LogsResource;
|
|
112
|
+
send: SendResource;
|
|
113
|
+
smtp: SmtpResource;
|
|
114
|
+
apiKeys: ApiKeysResource;
|
|
115
|
+
constructor(config: MailMaskConfig);
|
|
116
|
+
}
|
|
117
|
+
type Req = <T>(path: string, opts?: RequestInit) => Promise<T>;
|
|
118
|
+
declare class DomainsResource {
|
|
119
|
+
private req;
|
|
120
|
+
constructor(req: Req);
|
|
121
|
+
list(): Promise<Domain[]>;
|
|
122
|
+
get(id: string): Promise<Domain>;
|
|
123
|
+
create(domain: string): Promise<{
|
|
124
|
+
domain: Domain;
|
|
125
|
+
}>;
|
|
126
|
+
delete(id: string): Promise<{
|
|
127
|
+
ok: boolean;
|
|
128
|
+
}>;
|
|
129
|
+
health(id: string): Promise<Record<string, unknown>>;
|
|
130
|
+
verify(id: string): Promise<Record<string, unknown>>;
|
|
131
|
+
}
|
|
132
|
+
declare class AliasesResource {
|
|
133
|
+
private req;
|
|
134
|
+
constructor(req: Req);
|
|
135
|
+
list(domainId: string): Promise<Alias[]>;
|
|
136
|
+
create(domainId: string, input: CreateAliasInput): Promise<Alias>;
|
|
137
|
+
update(domainId: string, alias: string, input: UpdateAliasInput): Promise<Alias>;
|
|
138
|
+
delete(domainId: string, alias: string): Promise<{
|
|
139
|
+
ok: boolean;
|
|
140
|
+
}>;
|
|
141
|
+
}
|
|
142
|
+
declare class RulesResource {
|
|
143
|
+
private req;
|
|
144
|
+
constructor(req: Req);
|
|
145
|
+
list(domainId: string): Promise<Rule[]>;
|
|
146
|
+
create(domainId: string, input: CreateRuleInput): Promise<Rule>;
|
|
147
|
+
update(domainId: string, ruleId: string, input: UpdateRuleInput): Promise<Rule>;
|
|
148
|
+
delete(domainId: string, ruleId: string): Promise<{
|
|
149
|
+
ok: boolean;
|
|
150
|
+
}>;
|
|
151
|
+
}
|
|
152
|
+
declare class LogsResource {
|
|
153
|
+
private req;
|
|
154
|
+
constructor(req: Req);
|
|
155
|
+
list(domainId: string): Promise<EmailLog[]>;
|
|
156
|
+
}
|
|
157
|
+
declare class SendResource {
|
|
158
|
+
private req;
|
|
159
|
+
constructor(req: Req);
|
|
160
|
+
send(domainId: string, input: SendEmailInput): Promise<{
|
|
161
|
+
messageId: string;
|
|
162
|
+
}>;
|
|
163
|
+
bulkSend(domainId: string, input: BulkSendInput): Promise<BulkJob>;
|
|
164
|
+
bulkStatus(domainId: string, jobId: string): Promise<BulkJob>;
|
|
165
|
+
}
|
|
166
|
+
declare class SmtpResource {
|
|
167
|
+
private req;
|
|
168
|
+
constructor(req: Req);
|
|
169
|
+
list(domainId: string): Promise<SmtpCredential[]>;
|
|
170
|
+
create(domainId: string, label: string): Promise<SmtpCredential & {
|
|
171
|
+
smtpPassword: string;
|
|
172
|
+
}>;
|
|
173
|
+
revoke(domainId: string, credId: string): Promise<{
|
|
174
|
+
ok: boolean;
|
|
175
|
+
}>;
|
|
176
|
+
}
|
|
177
|
+
declare class ApiKeysResource {
|
|
178
|
+
private req;
|
|
179
|
+
constructor(req: Req);
|
|
180
|
+
list(): Promise<ApiKey[]>;
|
|
181
|
+
create(name: string): Promise<ApiKey & {
|
|
182
|
+
key: string;
|
|
183
|
+
}>;
|
|
184
|
+
revoke(id: string): Promise<{
|
|
185
|
+
ok: boolean;
|
|
186
|
+
}>;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export { type Alias, type ApiKey, type BulkJob, type BulkSendInput, type CreateAliasInput, type CreateRuleInput, type Domain, type EmailLog, MailMask, type MailMaskConfig, MailMaskError, type Rule, type SendEmailInput, type SmtpCredential, type UpdateAliasInput, type UpdateRuleInput };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
interface MailMaskConfig {
|
|
2
|
+
apiKey: string;
|
|
3
|
+
baseUrl?: string;
|
|
4
|
+
}
|
|
5
|
+
interface Domain {
|
|
6
|
+
id: string;
|
|
7
|
+
domain: string;
|
|
8
|
+
verified: boolean;
|
|
9
|
+
mxConfigured: boolean;
|
|
10
|
+
createdAt: string;
|
|
11
|
+
}
|
|
12
|
+
interface Alias {
|
|
13
|
+
alias: string;
|
|
14
|
+
domainId: string;
|
|
15
|
+
destinations: string[];
|
|
16
|
+
enabled: boolean;
|
|
17
|
+
forwardCount: number;
|
|
18
|
+
createdAt: string;
|
|
19
|
+
}
|
|
20
|
+
interface CreateAliasInput {
|
|
21
|
+
local: string;
|
|
22
|
+
forwardTo: string | string[];
|
|
23
|
+
}
|
|
24
|
+
interface UpdateAliasInput {
|
|
25
|
+
enabled?: boolean;
|
|
26
|
+
destinations?: string[];
|
|
27
|
+
}
|
|
28
|
+
interface Rule {
|
|
29
|
+
id: string;
|
|
30
|
+
domainId: string;
|
|
31
|
+
field: "to" | "from" | "subject";
|
|
32
|
+
match: string;
|
|
33
|
+
value: string;
|
|
34
|
+
action: string;
|
|
35
|
+
target: string;
|
|
36
|
+
priority: number;
|
|
37
|
+
enabled: boolean;
|
|
38
|
+
createdAt: string;
|
|
39
|
+
}
|
|
40
|
+
interface CreateRuleInput {
|
|
41
|
+
field: "to" | "from" | "subject";
|
|
42
|
+
match: string;
|
|
43
|
+
value: string;
|
|
44
|
+
action: string;
|
|
45
|
+
target: string;
|
|
46
|
+
priority?: number;
|
|
47
|
+
}
|
|
48
|
+
interface UpdateRuleInput {
|
|
49
|
+
field?: "to" | "from" | "subject";
|
|
50
|
+
match?: string;
|
|
51
|
+
value?: string;
|
|
52
|
+
action?: string;
|
|
53
|
+
target?: string;
|
|
54
|
+
priority?: number;
|
|
55
|
+
enabled?: boolean;
|
|
56
|
+
}
|
|
57
|
+
interface EmailLog {
|
|
58
|
+
id: string;
|
|
59
|
+
domainId: string;
|
|
60
|
+
timestamp: string;
|
|
61
|
+
from: string;
|
|
62
|
+
to: string;
|
|
63
|
+
subject: string;
|
|
64
|
+
status: string;
|
|
65
|
+
forwardedTo: string;
|
|
66
|
+
error?: string;
|
|
67
|
+
}
|
|
68
|
+
interface SendEmailInput {
|
|
69
|
+
fromLocal: string;
|
|
70
|
+
to: string;
|
|
71
|
+
subject: string;
|
|
72
|
+
html: string;
|
|
73
|
+
}
|
|
74
|
+
interface BulkSendInput {
|
|
75
|
+
from: string;
|
|
76
|
+
recipients: string[];
|
|
77
|
+
subject: string;
|
|
78
|
+
html: string;
|
|
79
|
+
}
|
|
80
|
+
interface BulkJob {
|
|
81
|
+
id: string;
|
|
82
|
+
status: string;
|
|
83
|
+
totalRecipients: number;
|
|
84
|
+
sent: number;
|
|
85
|
+
failed: number;
|
|
86
|
+
}
|
|
87
|
+
interface SmtpCredential {
|
|
88
|
+
id: string;
|
|
89
|
+
domainId: string;
|
|
90
|
+
label: string;
|
|
91
|
+
iamUsername: string;
|
|
92
|
+
createdAt: string;
|
|
93
|
+
}
|
|
94
|
+
interface ApiKey {
|
|
95
|
+
id: string;
|
|
96
|
+
name: string;
|
|
97
|
+
lastUsedAt?: string;
|
|
98
|
+
createdAt: string;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
declare class MailMaskError extends Error {
|
|
102
|
+
status: number;
|
|
103
|
+
constructor(status: number, message: string);
|
|
104
|
+
}
|
|
105
|
+
declare class MailMask {
|
|
106
|
+
private baseUrl;
|
|
107
|
+
private apiKey;
|
|
108
|
+
domains: DomainsResource;
|
|
109
|
+
aliases: AliasesResource;
|
|
110
|
+
rules: RulesResource;
|
|
111
|
+
logs: LogsResource;
|
|
112
|
+
send: SendResource;
|
|
113
|
+
smtp: SmtpResource;
|
|
114
|
+
apiKeys: ApiKeysResource;
|
|
115
|
+
constructor(config: MailMaskConfig);
|
|
116
|
+
}
|
|
117
|
+
type Req = <T>(path: string, opts?: RequestInit) => Promise<T>;
|
|
118
|
+
declare class DomainsResource {
|
|
119
|
+
private req;
|
|
120
|
+
constructor(req: Req);
|
|
121
|
+
list(): Promise<Domain[]>;
|
|
122
|
+
get(id: string): Promise<Domain>;
|
|
123
|
+
create(domain: string): Promise<{
|
|
124
|
+
domain: Domain;
|
|
125
|
+
}>;
|
|
126
|
+
delete(id: string): Promise<{
|
|
127
|
+
ok: boolean;
|
|
128
|
+
}>;
|
|
129
|
+
health(id: string): Promise<Record<string, unknown>>;
|
|
130
|
+
verify(id: string): Promise<Record<string, unknown>>;
|
|
131
|
+
}
|
|
132
|
+
declare class AliasesResource {
|
|
133
|
+
private req;
|
|
134
|
+
constructor(req: Req);
|
|
135
|
+
list(domainId: string): Promise<Alias[]>;
|
|
136
|
+
create(domainId: string, input: CreateAliasInput): Promise<Alias>;
|
|
137
|
+
update(domainId: string, alias: string, input: UpdateAliasInput): Promise<Alias>;
|
|
138
|
+
delete(domainId: string, alias: string): Promise<{
|
|
139
|
+
ok: boolean;
|
|
140
|
+
}>;
|
|
141
|
+
}
|
|
142
|
+
declare class RulesResource {
|
|
143
|
+
private req;
|
|
144
|
+
constructor(req: Req);
|
|
145
|
+
list(domainId: string): Promise<Rule[]>;
|
|
146
|
+
create(domainId: string, input: CreateRuleInput): Promise<Rule>;
|
|
147
|
+
update(domainId: string, ruleId: string, input: UpdateRuleInput): Promise<Rule>;
|
|
148
|
+
delete(domainId: string, ruleId: string): Promise<{
|
|
149
|
+
ok: boolean;
|
|
150
|
+
}>;
|
|
151
|
+
}
|
|
152
|
+
declare class LogsResource {
|
|
153
|
+
private req;
|
|
154
|
+
constructor(req: Req);
|
|
155
|
+
list(domainId: string): Promise<EmailLog[]>;
|
|
156
|
+
}
|
|
157
|
+
declare class SendResource {
|
|
158
|
+
private req;
|
|
159
|
+
constructor(req: Req);
|
|
160
|
+
send(domainId: string, input: SendEmailInput): Promise<{
|
|
161
|
+
messageId: string;
|
|
162
|
+
}>;
|
|
163
|
+
bulkSend(domainId: string, input: BulkSendInput): Promise<BulkJob>;
|
|
164
|
+
bulkStatus(domainId: string, jobId: string): Promise<BulkJob>;
|
|
165
|
+
}
|
|
166
|
+
declare class SmtpResource {
|
|
167
|
+
private req;
|
|
168
|
+
constructor(req: Req);
|
|
169
|
+
list(domainId: string): Promise<SmtpCredential[]>;
|
|
170
|
+
create(domainId: string, label: string): Promise<SmtpCredential & {
|
|
171
|
+
smtpPassword: string;
|
|
172
|
+
}>;
|
|
173
|
+
revoke(domainId: string, credId: string): Promise<{
|
|
174
|
+
ok: boolean;
|
|
175
|
+
}>;
|
|
176
|
+
}
|
|
177
|
+
declare class ApiKeysResource {
|
|
178
|
+
private req;
|
|
179
|
+
constructor(req: Req);
|
|
180
|
+
list(): Promise<ApiKey[]>;
|
|
181
|
+
create(name: string): Promise<ApiKey & {
|
|
182
|
+
key: string;
|
|
183
|
+
}>;
|
|
184
|
+
revoke(id: string): Promise<{
|
|
185
|
+
ok: boolean;
|
|
186
|
+
}>;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export { type Alias, type ApiKey, type BulkJob, type BulkSendInput, type CreateAliasInput, type CreateRuleInput, type Domain, type EmailLog, MailMask, type MailMaskConfig, MailMaskError, type Rule, type SendEmailInput, type SmtpCredential, type UpdateAliasInput, type UpdateRuleInput };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
// src/client.ts
|
|
2
|
+
var MailMaskError = class extends Error {
|
|
3
|
+
constructor(status, message) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.status = status;
|
|
6
|
+
this.name = "MailMaskError";
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
async function request(baseUrl, apiKey, path, opts) {
|
|
10
|
+
const res = await fetch(`${baseUrl}${path}`, {
|
|
11
|
+
...opts,
|
|
12
|
+
headers: {
|
|
13
|
+
"Authorization": `Bearer ${apiKey}`,
|
|
14
|
+
"Content-Type": "application/json",
|
|
15
|
+
...opts?.headers
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
if (!res.ok) {
|
|
19
|
+
const body = await res.json().catch(() => ({ error: res.statusText }));
|
|
20
|
+
throw new MailMaskError(res.status, body.error || res.statusText);
|
|
21
|
+
}
|
|
22
|
+
return res.json();
|
|
23
|
+
}
|
|
24
|
+
var MailMask = class {
|
|
25
|
+
constructor(config) {
|
|
26
|
+
this.apiKey = config.apiKey;
|
|
27
|
+
this.baseUrl = (config.baseUrl || "https://www.mailmask.studio").replace(/\/$/, "");
|
|
28
|
+
const req = (path, opts) => request(this.baseUrl, this.apiKey, path, opts);
|
|
29
|
+
this.domains = new DomainsResource(req);
|
|
30
|
+
this.aliases = new AliasesResource(req);
|
|
31
|
+
this.rules = new RulesResource(req);
|
|
32
|
+
this.logs = new LogsResource(req);
|
|
33
|
+
this.send = new SendResource(req);
|
|
34
|
+
this.smtp = new SmtpResource(req);
|
|
35
|
+
this.apiKeys = new ApiKeysResource(req);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var DomainsResource = class {
|
|
39
|
+
constructor(req) {
|
|
40
|
+
this.req = req;
|
|
41
|
+
}
|
|
42
|
+
list() {
|
|
43
|
+
return this.req("/api/domains");
|
|
44
|
+
}
|
|
45
|
+
get(id) {
|
|
46
|
+
return this.req(`/api/domains/${id}`);
|
|
47
|
+
}
|
|
48
|
+
create(domain) {
|
|
49
|
+
return this.req("/api/domains", { method: "POST", body: JSON.stringify({ domain }) });
|
|
50
|
+
}
|
|
51
|
+
delete(id) {
|
|
52
|
+
return this.req(`/api/domains/${id}`, { method: "DELETE" });
|
|
53
|
+
}
|
|
54
|
+
health(id) {
|
|
55
|
+
return this.req(`/api/domains/${id}/health`);
|
|
56
|
+
}
|
|
57
|
+
verify(id) {
|
|
58
|
+
return this.req(`/api/domains/${id}/verify`, { method: "POST" });
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
var AliasesResource = class {
|
|
62
|
+
constructor(req) {
|
|
63
|
+
this.req = req;
|
|
64
|
+
}
|
|
65
|
+
list(domainId) {
|
|
66
|
+
return this.req(`/api/domains/${domainId}/aliases`);
|
|
67
|
+
}
|
|
68
|
+
create(domainId, input) {
|
|
69
|
+
return this.req(`/api/domains/${domainId}/aliases`, { method: "POST", body: JSON.stringify(input) });
|
|
70
|
+
}
|
|
71
|
+
update(domainId, alias, input) {
|
|
72
|
+
return this.req(`/api/domains/${domainId}/aliases/${alias}`, { method: "PUT", body: JSON.stringify(input) });
|
|
73
|
+
}
|
|
74
|
+
delete(domainId, alias) {
|
|
75
|
+
return this.req(`/api/domains/${domainId}/aliases/${alias}`, { method: "DELETE" });
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
var RulesResource = class {
|
|
79
|
+
constructor(req) {
|
|
80
|
+
this.req = req;
|
|
81
|
+
}
|
|
82
|
+
list(domainId) {
|
|
83
|
+
return this.req(`/api/domains/${domainId}/rules`);
|
|
84
|
+
}
|
|
85
|
+
create(domainId, input) {
|
|
86
|
+
return this.req(`/api/domains/${domainId}/rules`, { method: "POST", body: JSON.stringify(input) });
|
|
87
|
+
}
|
|
88
|
+
update(domainId, ruleId, input) {
|
|
89
|
+
return this.req(`/api/domains/${domainId}/rules/${ruleId}`, { method: "PUT", body: JSON.stringify(input) });
|
|
90
|
+
}
|
|
91
|
+
delete(domainId, ruleId) {
|
|
92
|
+
return this.req(`/api/domains/${domainId}/rules/${ruleId}`, { method: "DELETE" });
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
var LogsResource = class {
|
|
96
|
+
constructor(req) {
|
|
97
|
+
this.req = req;
|
|
98
|
+
}
|
|
99
|
+
list(domainId) {
|
|
100
|
+
return this.req(`/api/domains/${domainId}/logs`);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
var SendResource = class {
|
|
104
|
+
constructor(req) {
|
|
105
|
+
this.req = req;
|
|
106
|
+
}
|
|
107
|
+
send(domainId, input) {
|
|
108
|
+
return this.req(`/api/domains/${domainId}/send`, { method: "POST", body: JSON.stringify(input) });
|
|
109
|
+
}
|
|
110
|
+
bulkSend(domainId, input) {
|
|
111
|
+
return this.req(`/api/domains/${domainId}/bulk-send`, { method: "POST", body: JSON.stringify(input) });
|
|
112
|
+
}
|
|
113
|
+
bulkStatus(domainId, jobId) {
|
|
114
|
+
return this.req(`/api/domains/${domainId}/bulk-send/${jobId}`);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
var SmtpResource = class {
|
|
118
|
+
constructor(req) {
|
|
119
|
+
this.req = req;
|
|
120
|
+
}
|
|
121
|
+
list(domainId) {
|
|
122
|
+
return this.req(`/api/domains/${domainId}/smtp-credentials`);
|
|
123
|
+
}
|
|
124
|
+
create(domainId, label) {
|
|
125
|
+
return this.req(`/api/domains/${domainId}/smtp-credentials`, { method: "POST", body: JSON.stringify({ label }) });
|
|
126
|
+
}
|
|
127
|
+
revoke(domainId, credId) {
|
|
128
|
+
return this.req(`/api/domains/${domainId}/smtp-credentials/${credId}`, { method: "DELETE" });
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
var ApiKeysResource = class {
|
|
132
|
+
constructor(req) {
|
|
133
|
+
this.req = req;
|
|
134
|
+
}
|
|
135
|
+
list() {
|
|
136
|
+
return this.req("/api/api-keys");
|
|
137
|
+
}
|
|
138
|
+
create(name) {
|
|
139
|
+
return this.req("/api/api-keys", { method: "POST", body: JSON.stringify({ name }) });
|
|
140
|
+
}
|
|
141
|
+
revoke(id) {
|
|
142
|
+
return this.req(`/api/api-keys/${id}`, { method: "DELETE" });
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
export {
|
|
146
|
+
MailMask,
|
|
147
|
+
MailMaskError
|
|
148
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@easybits.cloud/mailmask",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Official SDK for the MailMask email alias/forwarding API",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": ["dist"],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsup",
|
|
19
|
+
"prepublishOnly": "npm run build"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"tsup": "^8.0.0",
|
|
23
|
+
"typescript": "^5.0.0"
|
|
24
|
+
},
|
|
25
|
+
"keywords": ["mailmask", "email", "alias", "forwarding", "sdk"],
|
|
26
|
+
"license": "MIT"
|
|
27
|
+
}
|