@schemavaults/send-email-api-options 0.0.6 → 0.0.7
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/email-template-id-schema.d.ts +2 -0
- package/dist/email-template-id-schema.js +7 -0
- package/dist/email-template-id-schema.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/send-email-request-body-schema.d.ts +126 -0
- package/dist/send-email-request-body-schema.js +80 -0
- package/dist/send-email-request-body-schema.js.map +1 -0
- package/dist/send-email.d.ts +11 -0
- package/dist/send-email.js +73 -0
- package/dist/send-email.js.map +1 -0
- package/package.json +1 -1
- package/.npmrc.github +0 -3
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export const emailTemplateIdSchema = z
|
|
3
|
+
.string()
|
|
4
|
+
.min(1, "Email template ID must be non-empty!")
|
|
5
|
+
.max(64)
|
|
6
|
+
.regex(/^[a-z][a-z0-9_-]+$/, "Template ID must start with a letter, and may only contain lowercase alphanumeric characters, hyphens and underscores.");
|
|
7
|
+
//# sourceMappingURL=email-template-id-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email-template-id-schema.js","sourceRoot":"","sources":["../src/email-template-id-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC;KACnC,MAAM,EAAE;KACR,GAAG,CAAC,CAAC,EAAE,sCAAsC,CAAC;KAC9C,GAAG,CAAC,EAAE,CAAC;KACP,KAAK,CACJ,oBAAoB,EACpB,wHAAwH,CACzH,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { sendEmailRequestBodySchema, sendEmailRequestBodySchema as default, createSendEmailRequestBodySchema, } from "./send-email-request-body-schema";
|
|
2
|
+
export type { SendEmailRequestBody } from "./send-email-request-body-schema";
|
|
3
|
+
export { emailTemplateIdSchema } from "./email-template-id-schema";
|
|
4
|
+
export { getSchemaVaultsMailApiKey, sendEmail } from "./send-email";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { sendEmailRequestBodySchema, sendEmailRequestBodySchema as default, createSendEmailRequestBodySchema, } from "./send-email-request-body-schema";
|
|
2
|
+
export { emailTemplateIdSchema } from "./email-template-id-schema";
|
|
3
|
+
export { getSchemaVaultsMailApiKey, sendEmail } from "./send-email";
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,0BAA0B,IAAI,OAAO,EACrC,gCAAgC,GACjC,MAAM,kCAAkC,CAAC;AAG1C,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE,OAAO,EAAE,yBAAyB,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare function createRecipientSchema(allow_mailing_list_ids_as_recipients?: boolean): z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">, z.ZodString]> | z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param allow_mailing_list_ids_as_recipients
|
|
6
|
+
* @returns Schema for validating send-email request body
|
|
7
|
+
*/
|
|
8
|
+
export declare function createSendEmailRequestBodySchema(allow_mailing_list_ids_as_recipients?: boolean): z.ZodObject<{
|
|
9
|
+
message: z.ZodUnion<[z.ZodObject<{
|
|
10
|
+
template_id: z.ZodString;
|
|
11
|
+
template_props: z.ZodUnknown;
|
|
12
|
+
}, "strict", z.ZodTypeAny, {
|
|
13
|
+
template_id: string;
|
|
14
|
+
template_props?: unknown;
|
|
15
|
+
}, {
|
|
16
|
+
template_id: string;
|
|
17
|
+
template_props?: unknown;
|
|
18
|
+
}>, z.ZodObject<{
|
|
19
|
+
text: z.ZodString;
|
|
20
|
+
html: z.ZodString;
|
|
21
|
+
}, "strict", z.ZodTypeAny, {
|
|
22
|
+
text: string;
|
|
23
|
+
html: string;
|
|
24
|
+
}, {
|
|
25
|
+
text: string;
|
|
26
|
+
html: string;
|
|
27
|
+
}>]>;
|
|
28
|
+
to: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">, z.ZodString]> | z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
|
|
29
|
+
from: z.ZodOptional<z.ZodString>;
|
|
30
|
+
subject: z.ZodString;
|
|
31
|
+
replyTo: z.ZodOptional<z.ZodString>;
|
|
32
|
+
cc: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
33
|
+
bcc: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
34
|
+
}, "strict", z.ZodTypeAny, {
|
|
35
|
+
message: {
|
|
36
|
+
template_id: string;
|
|
37
|
+
template_props?: unknown;
|
|
38
|
+
} | {
|
|
39
|
+
text: string;
|
|
40
|
+
html: string;
|
|
41
|
+
};
|
|
42
|
+
to: string | string[];
|
|
43
|
+
subject: string;
|
|
44
|
+
from?: string | undefined;
|
|
45
|
+
replyTo?: string | undefined;
|
|
46
|
+
cc?: string | string[] | undefined;
|
|
47
|
+
bcc?: string | string[] | undefined;
|
|
48
|
+
}, {
|
|
49
|
+
message: {
|
|
50
|
+
template_id: string;
|
|
51
|
+
template_props?: unknown;
|
|
52
|
+
} | {
|
|
53
|
+
text: string;
|
|
54
|
+
html: string;
|
|
55
|
+
};
|
|
56
|
+
to: string | string[];
|
|
57
|
+
subject: string;
|
|
58
|
+
from?: string | undefined;
|
|
59
|
+
replyTo?: string | undefined;
|
|
60
|
+
cc?: string | string[] | undefined;
|
|
61
|
+
bcc?: string | string[] | undefined;
|
|
62
|
+
}>;
|
|
63
|
+
/**
|
|
64
|
+
* Default send email request body schema
|
|
65
|
+
* @see createSendEmailRequestBodySchema
|
|
66
|
+
*
|
|
67
|
+
* This schema will not allow "to: <mailing_list_uuid>"-- use createSendEmailRequestBodySchema
|
|
68
|
+
* with allow_mailing_list_ids_as_recipients = true to accept UUIDs
|
|
69
|
+
*/
|
|
70
|
+
export declare const sendEmailRequestBodySchema: z.ZodObject<{
|
|
71
|
+
message: z.ZodUnion<[z.ZodObject<{
|
|
72
|
+
template_id: z.ZodString;
|
|
73
|
+
template_props: z.ZodUnknown;
|
|
74
|
+
}, "strict", z.ZodTypeAny, {
|
|
75
|
+
template_id: string;
|
|
76
|
+
template_props?: unknown;
|
|
77
|
+
}, {
|
|
78
|
+
template_id: string;
|
|
79
|
+
template_props?: unknown;
|
|
80
|
+
}>, z.ZodObject<{
|
|
81
|
+
text: z.ZodString;
|
|
82
|
+
html: z.ZodString;
|
|
83
|
+
}, "strict", z.ZodTypeAny, {
|
|
84
|
+
text: string;
|
|
85
|
+
html: string;
|
|
86
|
+
}, {
|
|
87
|
+
text: string;
|
|
88
|
+
html: string;
|
|
89
|
+
}>]>;
|
|
90
|
+
to: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">, z.ZodString]> | z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
|
|
91
|
+
from: z.ZodOptional<z.ZodString>;
|
|
92
|
+
subject: z.ZodString;
|
|
93
|
+
replyTo: z.ZodOptional<z.ZodString>;
|
|
94
|
+
cc: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
95
|
+
bcc: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
96
|
+
}, "strict", z.ZodTypeAny, {
|
|
97
|
+
message: {
|
|
98
|
+
template_id: string;
|
|
99
|
+
template_props?: unknown;
|
|
100
|
+
} | {
|
|
101
|
+
text: string;
|
|
102
|
+
html: string;
|
|
103
|
+
};
|
|
104
|
+
to: string | string[];
|
|
105
|
+
subject: string;
|
|
106
|
+
from?: string | undefined;
|
|
107
|
+
replyTo?: string | undefined;
|
|
108
|
+
cc?: string | string[] | undefined;
|
|
109
|
+
bcc?: string | string[] | undefined;
|
|
110
|
+
}, {
|
|
111
|
+
message: {
|
|
112
|
+
template_id: string;
|
|
113
|
+
template_props?: unknown;
|
|
114
|
+
} | {
|
|
115
|
+
text: string;
|
|
116
|
+
html: string;
|
|
117
|
+
};
|
|
118
|
+
to: string | string[];
|
|
119
|
+
subject: string;
|
|
120
|
+
from?: string | undefined;
|
|
121
|
+
replyTo?: string | undefined;
|
|
122
|
+
cc?: string | string[] | undefined;
|
|
123
|
+
bcc?: string | string[] | undefined;
|
|
124
|
+
}>;
|
|
125
|
+
export type SendEmailRequestBody = z.infer<typeof sendEmailRequestBodySchema>;
|
|
126
|
+
export default createSendEmailRequestBodySchema;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { emailTemplateIdSchema } from "./email-template-id-schema";
|
|
3
|
+
const sendEmailTemplateOptions = z
|
|
4
|
+
.object({
|
|
5
|
+
template_id: emailTemplateIdSchema,
|
|
6
|
+
template_props: z.unknown(),
|
|
7
|
+
})
|
|
8
|
+
.required({
|
|
9
|
+
template_id: true,
|
|
10
|
+
})
|
|
11
|
+
.strict();
|
|
12
|
+
const sendRawEmailOptions = z
|
|
13
|
+
.object({
|
|
14
|
+
text: z.string().nonempty(),
|
|
15
|
+
html: z.string().nonempty(),
|
|
16
|
+
})
|
|
17
|
+
.required({
|
|
18
|
+
text: true,
|
|
19
|
+
html: true,
|
|
20
|
+
})
|
|
21
|
+
.strict();
|
|
22
|
+
const MAX_RECIPIENTS = 50;
|
|
23
|
+
export function createRecipientSchema(allow_mailing_list_ids_as_recipients = false) {
|
|
24
|
+
if (allow_mailing_list_ids_as_recipients) {
|
|
25
|
+
return z.union([
|
|
26
|
+
z.string().email(), // single recipient
|
|
27
|
+
z.string().email().array().min(1).max(MAX_RECIPIENTS), // multi recipient
|
|
28
|
+
z.string().uuid(), // mailing list id as recipient
|
|
29
|
+
]);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
return z.union([
|
|
33
|
+
z.string().email(), // single recipient
|
|
34
|
+
z.string().email().array().min(1).max(MAX_RECIPIENTS), // multi recipient
|
|
35
|
+
]);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
* @param allow_mailing_list_ids_as_recipients
|
|
41
|
+
* @returns Schema for validating send-email request body
|
|
42
|
+
*/
|
|
43
|
+
export function createSendEmailRequestBodySchema(allow_mailing_list_ids_as_recipients = false) {
|
|
44
|
+
return z
|
|
45
|
+
.object({
|
|
46
|
+
to: createRecipientSchema(allow_mailing_list_ids_as_recipients),
|
|
47
|
+
from: z.string().email().optional(),
|
|
48
|
+
subject: z.string().nonempty(),
|
|
49
|
+
message: z.union([sendEmailTemplateOptions, sendRawEmailOptions]),
|
|
50
|
+
replyTo: z.string().email().optional(),
|
|
51
|
+
cc: z
|
|
52
|
+
.union([
|
|
53
|
+
z.string().email(),
|
|
54
|
+
z.string().email().array().min(1).max(MAX_RECIPIENTS),
|
|
55
|
+
])
|
|
56
|
+
.optional(),
|
|
57
|
+
bcc: z
|
|
58
|
+
.union([
|
|
59
|
+
z.string().email(),
|
|
60
|
+
z.string().email().array().min(1).max(MAX_RECIPIENTS),
|
|
61
|
+
])
|
|
62
|
+
.optional(),
|
|
63
|
+
})
|
|
64
|
+
.required({
|
|
65
|
+
to: true,
|
|
66
|
+
message: true,
|
|
67
|
+
subject: true,
|
|
68
|
+
})
|
|
69
|
+
.strict();
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Default send email request body schema
|
|
73
|
+
* @see createSendEmailRequestBodySchema
|
|
74
|
+
*
|
|
75
|
+
* This schema will not allow "to: <mailing_list_uuid>"-- use createSendEmailRequestBodySchema
|
|
76
|
+
* with allow_mailing_list_ids_as_recipients = true to accept UUIDs
|
|
77
|
+
*/
|
|
78
|
+
export const sendEmailRequestBodySchema = createSendEmailRequestBodySchema();
|
|
79
|
+
export default createSendEmailRequestBodySchema;
|
|
80
|
+
//# sourceMappingURL=send-email-request-body-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"send-email-request-body-schema.js","sourceRoot":"","sources":["../src/send-email-request-body-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE,MAAM,wBAAwB,GAAG,CAAC;KAC/B,MAAM,CAAC;IACN,WAAW,EAAE,qBAAqB;IAClC,cAAc,EAAE,CAAC,CAAC,OAAO,EAAE;CAC5B,CAAC;KACD,QAAQ,CAAC;IACR,WAAW,EAAE,IAAI;CAClB,CAAC;KACD,MAAM,EAAE,CAAC;AAEZ,MAAM,mBAAmB,GAAG,CAAC;KAC1B,MAAM,CAAC;IACN,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC3B,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC5B,CAAC;KACD,QAAQ,CAAC;IACR,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;CACX,CAAC;KACD,MAAM,EAAE,CAAC;AAEZ,MAAM,cAAc,GAAW,EAAE,CAAC;AAElC,MAAM,UAAU,qBAAqB,CACnC,uCAAgD,KAAK;IAErD,IAAI,oCAAoC,EAAE,CAAC;QACzC,OAAO,CAAC,CAAC,KAAK,CAAC;YACb,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,mBAAmB;YACvC,CAAC,CAAC,MAAM,EAAE,CAAC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AC,MAAM,EAAE,CAAC,KAAK,EAAE;YAClB,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,cAAc,CAAC;SACtD,CAAC;aACD,QAAQ,EAAE;KACd,CAAC;SACD,QAAQ,CAAC;QACR,EAAE,EAAE,IAAI;QACR,OAAO,EAAE,IAAI;QACb,OAAO,EAAE,IAAI;KACd,CAAC;SACD,MAAM,EAAE,CAAC;AACd,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,gCAAgC,EAAE,CAAC;AAI7E,eAAe,gCAAgC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SchemaVaultsAppEnvironment } from "@schemavaults/app-definitions";
|
|
2
|
+
import { type SendEmailRequestBody } from "./send-email-request-body-schema";
|
|
3
|
+
export interface ISendEmailOpts {
|
|
4
|
+
body: SendEmailRequestBody;
|
|
5
|
+
bearerToken?: string;
|
|
6
|
+
mailServerUrl?: string;
|
|
7
|
+
environment?: SchemaVaultsAppEnvironment;
|
|
8
|
+
}
|
|
9
|
+
export declare function getSchemaVaultsMailApiKey(): string;
|
|
10
|
+
export declare function sendEmail({ body, ...opts }: ISendEmailOpts): Promise<void>;
|
|
11
|
+
export default sendEmail;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// send-email.ts
|
|
2
|
+
import { getAppEnvironment, getHardcodedApiServerDomain, SCHEMAVAULTS_MAIL_APP_DEFINITION, } from "@schemavaults/app-definitions";
|
|
3
|
+
import { createSendEmailRequestBodySchema, } from "./send-email-request-body-schema";
|
|
4
|
+
const body_schema = createSendEmailRequestBodySchema(true);
|
|
5
|
+
export function getSchemaVaultsMailApiKey() {
|
|
6
|
+
if (!process.env.SCHEMAVAULTS_MAIL_API_KEY ||
|
|
7
|
+
typeof process.env.SCHEMAVAULTS_MAIL_API_KEY !== "string") {
|
|
8
|
+
throw new Error("Failed to load API key from environment variable 'SCHEMAVAULTS_MAIL_API_KEY'");
|
|
9
|
+
}
|
|
10
|
+
return process.env.SCHEMAVAULTS_MAIL_API_KEY;
|
|
11
|
+
}
|
|
12
|
+
export async function sendEmail({ body, ...opts }) {
|
|
13
|
+
let environment;
|
|
14
|
+
if (opts.environment) {
|
|
15
|
+
environment = opts.environment;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
try {
|
|
19
|
+
environment = getAppEnvironment();
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
environment = "production";
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const parsed = await body_schema.safeParseAsync(body);
|
|
26
|
+
if (!parsed.success) {
|
|
27
|
+
console.error("Bad request body: ", parsed.error);
|
|
28
|
+
throw new TypeError("Bad request body to send email with!");
|
|
29
|
+
}
|
|
30
|
+
let bearerToken;
|
|
31
|
+
if (opts.bearerToken && typeof opts.bearerToken === "string") {
|
|
32
|
+
bearerToken = opts.bearerToken;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
bearerToken = getSchemaVaultsMailApiKey();
|
|
36
|
+
}
|
|
37
|
+
const mail_server_url = getHardcodedApiServerDomain(SCHEMAVAULTS_MAIL_APP_DEFINITION.app_id, environment).domain;
|
|
38
|
+
const endpoint = `${mail_server_url}/api/send`;
|
|
39
|
+
const response = await fetch(endpoint, {
|
|
40
|
+
method: "POST",
|
|
41
|
+
body: JSON.stringify(parsed.data),
|
|
42
|
+
headers: {
|
|
43
|
+
"Content-Type": "application/json",
|
|
44
|
+
Authorization: `Bearer ${bearerToken}`,
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
if (!response.ok || response.status !== 200) {
|
|
48
|
+
let errorMessage = "Error response while trying to send email!";
|
|
49
|
+
try {
|
|
50
|
+
const errBody = await response.json();
|
|
51
|
+
if (typeof errBody === "object" &&
|
|
52
|
+
!!errBody &&
|
|
53
|
+
"message" in errBody &&
|
|
54
|
+
typeof errBody.message === "string") {
|
|
55
|
+
errorMessage = errBody.message;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
// ignore JSON parse failure, fall back to default
|
|
60
|
+
}
|
|
61
|
+
throw new Error(errorMessage);
|
|
62
|
+
}
|
|
63
|
+
const responseBody = await response.json();
|
|
64
|
+
if (typeof responseBody !== "object" || !responseBody) {
|
|
65
|
+
throw new Error("Failed to parse JSON object from response object!");
|
|
66
|
+
}
|
|
67
|
+
if (!("success" in responseBody) || !responseBody.success) {
|
|
68
|
+
throw new Error("Failure indicated in response body!");
|
|
69
|
+
}
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
export default sendEmail;
|
|
73
|
+
//# sourceMappingURL=send-email.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"send-email.js","sourceRoot":"","sources":["../src/send-email.ts"],"names":[],"mappings":"AAAA,gBAAgB;AAEhB,OAAO,EACL,iBAAiB,EACjB,2BAA2B,EAC3B,gCAAgC,GAEjC,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAEL,gCAAgC,GACjC,MAAM,kCAAkC,CAAC;AAE1C,MAAM,WAAW,GAAG,gCAAgC,CAAC,IAAI,CAAC,CAAC;AAS3D,MAAM,UAAU,yBAAyB;IACvC,IACE,CAAC,OAAO,CAAC,GAAG,CAAC,yBAAyB;QACtC,OAAO,OAAO,CAAC,GAAG,CAAC,yBAAyB,KAAK,QAAQ,EACzD,CAAC;QACD,MAAM,IAAI,KAAK,CACb,8EAA8E,CAC/E,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC;AAC/C,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,EAC9B,IAAI,EACJ,GAAG,IAAI,EACQ;IACf,IAAI,WAAuC,CAAC;IAC5C,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;QACrB,WAAW,GAAG,IAAI,CAAC,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C,IAAI,EAAE,CAAC;YACtC,IACE,OAAO,OAAO,KAAK,QAAQ;gBAC3B,CAAC,CAAC,OAAO;gBACT,SAAS,IAAI,OAAO;gBACpB,OAAO,OAAO,CAAC,OAAO,KAAK,QAAQ,EACnC,CAAC;gBACD,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC;YACjC,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,kDAAkD;QACpD,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;IAChC,CAAC;IACD,MAAM,YAAY,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IAC3C,IAAI,OAAO,YAAY,KAAK,QAAQ,IAAI,CAAC,YAAY,EAAE,CAAC;QACtD,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACvE,CAAC;IACD,IAAI,CAAC,CAAC,SAAS,IAAI,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC;QAC1D,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;IACzD,CAAC;IAED,OAAO;AACT,CAAC;AAED,eAAe,SAAS,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@schemavaults/send-email-api-options",
|
|
3
3
|
"description": "Schema defining the shape of the request body to send an email via @schemavaults/mail-server",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.7",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"private": false,
|
|
7
7
|
"repository": {
|
package/.npmrc.github
DELETED