@storecraft/mailer-providers-http 1.0.9 → 1.0.11
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/mailchimp/adapter.js +24 -6
- package/mailchimp/adapter.utils.js +4 -1
- package/mailchimp/types.public.d.ts +2 -2
- package/mailgun/adapter.js +19 -3
- package/mailgun/adapter.utils.js +5 -2
- package/mailgun/types.public.d.ts +3 -3
- package/package.json +1 -1
- package/resend/adapter.js +23 -7
- package/resend/adapter.utils.js +5 -2
- package/resend/types.public.d.ts +2 -2
- package/sendgrid/adapter.js +20 -6
- package/sendgrid/adapter.utils.js +4 -1
- package/sendgrid/types.public.d.ts +2 -2
package/mailchimp/adapter.js
CHANGED
@@ -1,14 +1,27 @@
|
|
1
|
+
/**
|
2
|
+
* @import { Config } from './types.public.js'
|
3
|
+
* @import { ENV } from '@storecraft/core';
|
4
|
+
* @import { mailer } from '@storecraft/core/mailer'
|
5
|
+
* @import {
|
6
|
+
* Mailchimp_sendmail, Mailchimp_sendmail_message_attachment
|
7
|
+
* } from './types.private.js'
|
8
|
+
*/
|
9
|
+
|
1
10
|
import { convert_to_base64 } from "./adapter.utils.js";
|
2
11
|
|
12
|
+
|
3
13
|
/**
|
4
|
-
* @
|
5
|
-
* @typedef {import('@storecraft/core/mailer').mailer<Config>} mailer
|
6
|
-
* @implements {mailer}
|
14
|
+
* @description mailer with mail-chimp / mandrill http api
|
7
15
|
*
|
8
|
-
* mailer
|
16
|
+
* @implements {mailer<Config>}
|
9
17
|
*/
|
10
18
|
export class MailChimp {
|
11
19
|
|
20
|
+
/** @satisfies {ENV<Config>} */
|
21
|
+
static EnvConfig = /** @type{const} */ ({
|
22
|
+
apikey: 'MAILCHIMP_API_KEY'
|
23
|
+
});
|
24
|
+
|
12
25
|
/** @type {Config} */ #_config;
|
13
26
|
|
14
27
|
/**
|
@@ -21,13 +34,18 @@ export class MailChimp {
|
|
21
34
|
|
22
35
|
get config() { return this.#_config; }
|
23
36
|
|
37
|
+
/** @type {mailer<Config>["onInit"]} */
|
38
|
+
onInit = (app) => {
|
39
|
+
this.config.apikey ??= app.platform.env[MailChimp.EnvConfig.apikey];
|
40
|
+
};
|
41
|
+
|
24
42
|
/**
|
25
43
|
*
|
26
44
|
* @type {mailer["email"]}
|
27
45
|
*/
|
28
46
|
async email(o) {
|
29
47
|
|
30
|
-
/** @type {
|
48
|
+
/** @type {Mailchimp_sendmail} */
|
31
49
|
const body = {
|
32
50
|
key: this.config.apikey,
|
33
51
|
message: {
|
@@ -40,7 +58,7 @@ export class MailChimp {
|
|
40
58
|
attachments: o.attachments && await Promise.all(
|
41
59
|
o.attachments.map(
|
42
60
|
/**
|
43
|
-
* @returns {Promise<
|
61
|
+
* @returns {Promise<Mailchimp_sendmail_message_attachment>}
|
44
62
|
*/
|
45
63
|
async a => ({
|
46
64
|
type: a.content_type,
|
@@ -1,7 +1,10 @@
|
|
1
|
+
/**
|
2
|
+
* @import { MailObject } from '@storecraft/core/mailer'
|
3
|
+
*/
|
1
4
|
import { base64 } from '@storecraft/core/crypto'
|
2
5
|
|
3
6
|
/**
|
4
|
-
* @param {
|
7
|
+
* @param {MailObject["attachments"][0]["content"]} c
|
5
8
|
*/
|
6
9
|
export const convert_to_base64 = async (c) => {
|
7
10
|
if(c instanceof ArrayBuffer)
|
@@ -6,9 +6,9 @@ export { MailChimp } from './adapter.js';
|
|
6
6
|
export type Config = {
|
7
7
|
|
8
8
|
/**
|
9
|
-
* @description Your API Key
|
9
|
+
* @description Your API Key, if missing, it will be inferred from environment variable `MAILCHIMP_API_KEY`
|
10
10
|
*/
|
11
|
-
apikey
|
11
|
+
apikey?: string,
|
12
12
|
|
13
13
|
};
|
14
14
|
|
package/mailgun/adapter.js
CHANGED
@@ -1,15 +1,26 @@
|
|
1
|
+
/**
|
2
|
+
* @import { Config } from './types.public.js'
|
3
|
+
* @import { mailer } from '@storecraft/core/mailer'
|
4
|
+
* @import { ENV } from '@storecraft/core';
|
5
|
+
* @import {
|
6
|
+
* } from './types.private.js'
|
7
|
+
*/
|
1
8
|
import { base64 } from "@storecraft/core/crypto";
|
2
9
|
import { address_to_friendly_name, convert_attachment_to_blob } from "./adapter.utils.js";
|
3
10
|
|
11
|
+
|
4
12
|
/**
|
5
|
-
* @
|
6
|
-
* @typedef {import('@storecraft/core/mailer').mailer<Config>} mailer
|
7
|
-
* @implements {mailer}
|
13
|
+
* @implements {mailer<Config>}
|
8
14
|
*
|
9
15
|
* @description mailer with mailgun http api
|
10
16
|
*/
|
11
17
|
export class Mailgun {
|
12
18
|
|
19
|
+
/** @satisfies {ENV<Config>} */
|
20
|
+
static EnvConfig = /** @type{const} */ ({
|
21
|
+
apikey: 'MAILGUN_API_KEY'
|
22
|
+
});
|
23
|
+
|
13
24
|
/** @type {Config} */ #_config;
|
14
25
|
|
15
26
|
/**
|
@@ -22,6 +33,11 @@ export class Mailgun {
|
|
22
33
|
|
23
34
|
get config() { return this.#_config; }
|
24
35
|
|
36
|
+
/** @type {mailer<Config>["onInit"]} */
|
37
|
+
onInit = (app) => {
|
38
|
+
this.config.apikey ??= app.platform.env[Mailgun.EnvConfig.apikey];
|
39
|
+
};
|
40
|
+
|
25
41
|
/**
|
26
42
|
*
|
27
43
|
* @type {mailer["email"]}
|
package/mailgun/adapter.utils.js
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
+
/**
|
2
|
+
* @import { MailAddress, MailObject } from '@storecraft/core/mailer'
|
3
|
+
*/
|
1
4
|
|
2
5
|
/**
|
3
6
|
*
|
4
|
-
* @param {
|
7
|
+
* @param {MailObject["attachments"][0]["content"]} c
|
5
8
|
*/
|
6
9
|
export const convert_attachment_to_blob = async c => {
|
7
10
|
if(c instanceof ArrayBuffer)
|
@@ -27,7 +30,7 @@ export const convert_attachment_to_blob = async c => {
|
|
27
30
|
|
28
31
|
/**
|
29
32
|
*
|
30
|
-
* @param {
|
33
|
+
* @param {MailAddress} a
|
31
34
|
*/
|
32
35
|
export const address_to_friendly_name = a => {
|
33
36
|
return a.name ? `${a.name} <${a.address}>` : a.address;
|
@@ -4,10 +4,10 @@ export { Mailgun } from './adapter.js';
|
|
4
4
|
* @description `mailgun` config
|
5
5
|
*/
|
6
6
|
export type Config = {
|
7
|
-
/**
|
8
|
-
* @description
|
7
|
+
/**
|
8
|
+
* @description Your API Key, if missing, it will be inferred from environment variable `MAILGUN_API_KEY`
|
9
9
|
*/
|
10
|
-
apikey
|
10
|
+
apikey?: string,
|
11
11
|
|
12
12
|
/**
|
13
13
|
* @description your registered domain name at `mailgun`
|
package/package.json
CHANGED
package/resend/adapter.js
CHANGED
@@ -1,33 +1,49 @@
|
|
1
|
+
/**
|
2
|
+
* @import { Config } from './types.public.js'
|
3
|
+
* @import { mailer } from '@storecraft/core/mailer'
|
4
|
+
* @import { ENV } from '@storecraft/core';
|
5
|
+
* @import { Resend_sendmail, Resend_sendmail_attachment } from './types.private.js'
|
6
|
+
*/
|
7
|
+
|
1
8
|
import { address_to_friendly_name, convert_to_base64 } from "./adapter.utils.js";
|
2
9
|
|
3
10
|
/**
|
4
|
-
* @typedef {import("./types.public.d.ts").Config} Config
|
5
|
-
* @typedef {import('@storecraft/core/mailer').mailer<Config>} mailer
|
6
|
-
* @implements {mailer}
|
7
|
-
*
|
8
11
|
* @description mailer with Resend rest api
|
12
|
+
*
|
13
|
+
* @implements {mailer<Config>}
|
9
14
|
*/
|
10
15
|
export class Resend {
|
11
16
|
|
17
|
+
/** @satisfies {ENV<Config>} */
|
18
|
+
static EnvConfig = /** @type{const} */ ({
|
19
|
+
apikey: 'RESEND_API_KEY'
|
20
|
+
});
|
21
|
+
|
12
22
|
/** @type {Config} */ #_config;
|
13
23
|
|
14
24
|
/**
|
15
25
|
*
|
16
26
|
* @param {Config} config
|
17
27
|
*/
|
18
|
-
constructor(config) {
|
28
|
+
constructor(config={}) {
|
19
29
|
this.#_config = config;
|
20
30
|
}
|
21
31
|
|
22
32
|
get config() { return this.#_config; }
|
23
33
|
|
34
|
+
|
35
|
+
/** @type {mailer<Config>["onInit"]} */
|
36
|
+
onInit = (app) => {
|
37
|
+
this.config.apikey ??= app.platform.env[Resend.EnvConfig.apikey];
|
38
|
+
};
|
39
|
+
|
24
40
|
/**
|
25
41
|
*
|
26
42
|
* @type {mailer["email"]}
|
27
43
|
*/
|
28
44
|
async email(o) {
|
29
45
|
|
30
|
-
/** @type {
|
46
|
+
/** @type {Resend_sendmail} */
|
31
47
|
const body = {
|
32
48
|
from: address_to_friendly_name(o.from),
|
33
49
|
to: o.to.map(t => t.address),
|
@@ -37,7 +53,7 @@ export class Resend {
|
|
37
53
|
attachments: o.attachments && await Promise.all(
|
38
54
|
o.attachments.map(
|
39
55
|
/**
|
40
|
-
* @returns {Promise<
|
56
|
+
* @returns {Promise<Resend_sendmail_attachment>}
|
41
57
|
*/
|
42
58
|
async a => (
|
43
59
|
{
|
package/resend/adapter.utils.js
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
+
/**
|
2
|
+
* @import { MailAddress, mailer, MailObject } from '@storecraft/core/mailer'
|
3
|
+
*/
|
1
4
|
import { base64 } from '@storecraft/core/crypto'
|
2
5
|
|
3
6
|
/**
|
4
7
|
*
|
5
|
-
* @param {
|
8
|
+
* @param {MailObject["attachments"][0]["content"]} c
|
6
9
|
*/
|
7
10
|
export const convert_to_base64 = async (c) => {
|
8
11
|
if(c instanceof ArrayBuffer)
|
@@ -28,7 +31,7 @@ export const convert_to_base64 = async (c) => {
|
|
28
31
|
|
29
32
|
/**
|
30
33
|
*
|
31
|
-
* @param {
|
34
|
+
* @param {MailAddress} a
|
32
35
|
*/
|
33
36
|
export const address_to_friendly_name = a => {
|
34
37
|
return a.name ? `${a.name} <${a.address}>` : a.address;
|
package/resend/types.public.d.ts
CHANGED
@@ -5,8 +5,8 @@ export { Resend } from './adapter.js';
|
|
5
5
|
*/
|
6
6
|
export type Config = {
|
7
7
|
/**
|
8
|
-
* @description Your API Key
|
8
|
+
* @description Your API Key, if missing, it will be inferred from environment variable `RESEND_API_KEY`
|
9
9
|
*/
|
10
|
-
apikey
|
10
|
+
apikey?: string,
|
11
11
|
};
|
12
12
|
|
package/sendgrid/adapter.js
CHANGED
@@ -1,33 +1,47 @@
|
|
1
|
+
/**
|
2
|
+
* @import { Config } from './types.public.js'
|
3
|
+
* @import { ENV } from '@storecraft/core';
|
4
|
+
* @import { mailer } from '@storecraft/core/mailer'
|
5
|
+
* @import { SendgridV3_sendmail } from './types.private.js'
|
6
|
+
*/
|
1
7
|
import { convert_to_base64 } from "./adapter.utils.js";
|
2
8
|
|
3
9
|
/**
|
4
|
-
* @typedef {import("./types.public.d.ts").Config} Config
|
5
|
-
* @typedef {import('@storecraft/core/mailer').mailer<Config>} mailer
|
6
|
-
* @implements {mailer}
|
7
|
-
*
|
8
10
|
* @description mailer with sendgrid http api
|
11
|
+
*
|
12
|
+
* @implements {mailer<Config>}
|
9
13
|
*/
|
10
14
|
export class SendGrid {
|
11
15
|
|
16
|
+
/** @satisfies {ENV<Config>} */
|
17
|
+
static EnvConfig = /** @type{const} */ ({
|
18
|
+
apikey: 'SENDGRID_API_KEY'
|
19
|
+
});
|
20
|
+
|
12
21
|
/** @type {Config} */ #_config;
|
13
22
|
|
14
23
|
/**
|
15
24
|
*
|
16
25
|
* @param {Config} config
|
17
26
|
*/
|
18
|
-
constructor(config) {
|
27
|
+
constructor(config={}) {
|
19
28
|
this.#_config = config;
|
20
29
|
}
|
21
30
|
|
22
31
|
get config() { return this.#_config; }
|
23
32
|
|
33
|
+
/** @type {mailer<Config>["onInit"]} */
|
34
|
+
onInit = (app) => {
|
35
|
+
this.config.apikey ??= app.platform.env[SendGrid.EnvConfig.apikey];
|
36
|
+
};
|
37
|
+
|
24
38
|
/**
|
25
39
|
*
|
26
40
|
* @type {mailer["email"]}
|
27
41
|
*/
|
28
42
|
async email(o) {
|
29
43
|
|
30
|
-
/** @type {
|
44
|
+
/** @type {SendgridV3_sendmail} */
|
31
45
|
const body = {
|
32
46
|
content: [
|
33
47
|
{
|
@@ -1,8 +1,11 @@
|
|
1
|
+
/**
|
2
|
+
* @import { mailer, MailObject } from '@storecraft/core/mailer'
|
3
|
+
*/
|
1
4
|
import { base64 } from '@storecraft/core/crypto'
|
2
5
|
|
3
6
|
/**
|
4
7
|
*
|
5
|
-
* @param {
|
8
|
+
* @param {MailObject["attachments"][0]["content"]} c
|
6
9
|
*/
|
7
10
|
export const convert_to_base64 = async (c) => {
|
8
11
|
if(c instanceof ArrayBuffer)
|
@@ -6,9 +6,9 @@ export { SendGrid } from './adapter.js';
|
|
6
6
|
export type Config = {
|
7
7
|
|
8
8
|
/**
|
9
|
-
* @description Your API Key
|
9
|
+
* @description Your API Key, if missing, it will be inferred from environment variable `SENDGRID_API_KEY`
|
10
10
|
*/
|
11
|
-
apikey
|
11
|
+
apikey?: string,
|
12
12
|
|
13
13
|
};
|
14
14
|
|