@logto/connector-http-email 0.3.2 → 0.4.1
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/lib/index.js +7 -3
- package/lib/index.js.map +1 -1
- package/package.json +4 -3
package/lib/index.js
CHANGED
|
@@ -20,7 +20,10 @@ var defaultMetadata = {
|
|
|
20
20
|
logo: "./logo.svg",
|
|
21
21
|
logoDark: null,
|
|
22
22
|
description: {
|
|
23
|
-
en: "Send email via HTTP call."
|
|
23
|
+
en: "Send email via HTTP call.",
|
|
24
|
+
"zh-CN": "\u901A\u8FC7 HTTP \u8C03\u7528\u53D1\u9001\u7535\u5B50\u90AE\u4EF6\u3002",
|
|
25
|
+
"tr-TR": "HTTP iste\u011Fi arac\u0131l\u0131\u011F\u0131yla e-posta g\xF6nderin.",
|
|
26
|
+
ko: "HTTP \uD638\uCD9C\uC744 \uD1B5\uD574 \uC774\uBA54\uC77C\uC744 \uBCF4\uB0C5\uB2C8\uB2E4."
|
|
24
27
|
},
|
|
25
28
|
readme: "./README.md",
|
|
26
29
|
formItems: [
|
|
@@ -51,7 +54,7 @@ var httpMailConfigGuard = z.object({
|
|
|
51
54
|
|
|
52
55
|
// src/index.ts
|
|
53
56
|
var sendMessage = (getConfig) => async (data, inputConfig) => {
|
|
54
|
-
const { to, type, payload } = data;
|
|
57
|
+
const { to, type, payload, ip } = data;
|
|
55
58
|
const config = inputConfig ?? await getConfig(defaultMetadata.id);
|
|
56
59
|
validateConfig(config, httpMailConfigGuard);
|
|
57
60
|
const { endpoint, authorization } = config;
|
|
@@ -64,7 +67,8 @@ var sendMessage = (getConfig) => async (data, inputConfig) => {
|
|
|
64
67
|
json: {
|
|
65
68
|
to,
|
|
66
69
|
type,
|
|
67
|
-
payload
|
|
70
|
+
payload,
|
|
71
|
+
...ip && { ip }
|
|
68
72
|
}
|
|
69
73
|
});
|
|
70
74
|
} catch (error) {
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/constant.ts","../src/types.ts"],"sourcesContent":["import { assert } from '@silverhand/essentials';\nimport { got, HTTPError } from 'got';\n\nimport type {\n GetConnectorConfig,\n SendMessageFunction,\n CreateConnector,\n EmailConnector,\n} from '@logto/connector-kit';\nimport {\n ConnectorError,\n ConnectorErrorCodes,\n validateConfig,\n ConnectorType,\n} from '@logto/connector-kit';\n\nimport { defaultMetadata } from './constant.js';\nimport { httpMailConfigGuard } from './types.js';\n\nconst sendMessage =\n (getConfig: GetConnectorConfig): SendMessageFunction =>\n async (data, inputConfig) => {\n const { to, type, payload } = data;\n const config = inputConfig ?? (await getConfig(defaultMetadata.id));\n validateConfig(config, httpMailConfigGuard);\n const { endpoint, authorization } = config;\n\n try {\n return await got.post(endpoint, {\n headers: {\n Authorization: authorization,\n 'Content-Type': 'application/json',\n },\n json: {\n to,\n type,\n payload,\n },\n });\n } catch (error: unknown) {\n if (error instanceof HTTPError) {\n const {\n response: { body: rawBody },\n } = error;\n\n assert(\n typeof rawBody === 'string',\n new ConnectorError(\n ConnectorErrorCodes.InvalidResponse,\n `Invalid response raw body type: ${typeof rawBody}`\n )\n );\n\n throw new ConnectorError(ConnectorErrorCodes.General, rawBody);\n }\n\n throw new ConnectorError(ConnectorErrorCodes.General, error);\n }\n };\n\nconst createHttpMailConnector: CreateConnector<EmailConnector> = async ({ getConfig }) => {\n return {\n metadata: defaultMetadata,\n type: ConnectorType.Email,\n configGuard: httpMailConfigGuard,\n sendMessage: sendMessage(getConfig),\n };\n};\n\nexport default createHttpMailConnector;\n","import type { ConnectorMetadata } from '@logto/connector-kit';\nimport { ConnectorConfigFormItemType } from '@logto/connector-kit';\n\nexport const defaultMetadata: ConnectorMetadata = {\n id: 'http-email',\n target: 'http-email',\n platform: null,\n name: {\n en: 'HTTP Email',\n },\n logo: './logo.svg',\n logoDark: null,\n description: {\n en: 'Send email via HTTP call.',\n },\n readme: './README.md',\n formItems: [\n {\n key: 'endpoint',\n label: 'Endpoint',\n type: ConnectorConfigFormItemType.Text,\n required: true,\n placeholder: '<https://example.com/your-http-endpoint>',\n },\n {\n key: 'authorization',\n label: 'Authorization Header',\n type: ConnectorConfigFormItemType.Text,\n required: false,\n placeholder: '<Bearer your-token>',\n tooltip:\n 'The authorization header to be sent with the request, you can verify the value in your server.',\n },\n ],\n};\n","import { z } from 'zod';\n\nexport const httpMailConfigGuard = z.object({\n endpoint: z.string(),\n authorization: z.string().optional(),\n});\n\nexport type HttpMailConfig = z.infer<typeof httpMailConfigGuard>;\n"],"mappings":";AAAA,SAAS,cAAc;AACvB,SAAS,KAAK,iBAAiB;AAQ/B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACbP,SAAS,mCAAmC;AAErC,IAAM,kBAAqC;AAAA,EAChD,IAAI;AAAA,EACJ,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,MAAM;AAAA,IACJ,IAAI;AAAA,EACN;AAAA,EACA,MAAM;AAAA,EACN,UAAU;AAAA,EACV,aAAa;AAAA,IACX,IAAI;AAAA,EACN;AAAA,EACA,QAAQ;AAAA,EACR,WAAW;AAAA,IACT;AAAA,MACE,KAAK;AAAA,MACL,OAAO;AAAA,MACP,MAAM,4BAA4B;AAAA,MAClC,UAAU;AAAA,MACV,aAAa;AAAA,IACf;AAAA,IACA;AAAA,MACE,KAAK;AAAA,MACL,OAAO;AAAA,MACP,MAAM,4BAA4B;AAAA,MAClC,UAAU;AAAA,MACV,aAAa;AAAA,MACb,SACE;AAAA,IACJ;AAAA,EACF;AACF;;;
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/constant.ts","../src/types.ts"],"sourcesContent":["import { assert } from '@silverhand/essentials';\nimport { got, HTTPError } from 'got';\n\nimport type {\n GetConnectorConfig,\n SendMessageFunction,\n CreateConnector,\n EmailConnector,\n} from '@logto/connector-kit';\nimport {\n ConnectorError,\n ConnectorErrorCodes,\n validateConfig,\n ConnectorType,\n} from '@logto/connector-kit';\n\nimport { defaultMetadata } from './constant.js';\nimport { httpMailConfigGuard } from './types.js';\n\nconst sendMessage =\n (getConfig: GetConnectorConfig): SendMessageFunction =>\n async (data, inputConfig) => {\n const { to, type, payload, ip } = data;\n const config = inputConfig ?? (await getConfig(defaultMetadata.id));\n validateConfig(config, httpMailConfigGuard);\n const { endpoint, authorization } = config;\n\n try {\n return await got.post(endpoint, {\n headers: {\n Authorization: authorization,\n 'Content-Type': 'application/json',\n },\n json: {\n to,\n type,\n payload,\n ...(ip && { ip }),\n },\n });\n } catch (error: unknown) {\n if (error instanceof HTTPError) {\n const {\n response: { body: rawBody },\n } = error;\n\n assert(\n typeof rawBody === 'string',\n new ConnectorError(\n ConnectorErrorCodes.InvalidResponse,\n `Invalid response raw body type: ${typeof rawBody}`\n )\n );\n\n throw new ConnectorError(ConnectorErrorCodes.General, rawBody);\n }\n\n throw new ConnectorError(ConnectorErrorCodes.General, error);\n }\n };\n\nconst createHttpMailConnector: CreateConnector<EmailConnector> = async ({ getConfig }) => {\n return {\n metadata: defaultMetadata,\n type: ConnectorType.Email,\n configGuard: httpMailConfigGuard,\n sendMessage: sendMessage(getConfig),\n };\n};\n\nexport default createHttpMailConnector;\n","import type { ConnectorMetadata } from '@logto/connector-kit';\nimport { ConnectorConfigFormItemType } from '@logto/connector-kit';\n\nexport const defaultMetadata: ConnectorMetadata = {\n id: 'http-email',\n target: 'http-email',\n platform: null,\n name: {\n en: 'HTTP Email',\n },\n logo: './logo.svg',\n logoDark: null,\n description: {\n en: 'Send email via HTTP call.',\n 'zh-CN': '通过 HTTP 调用发送电子邮件。',\n 'tr-TR': 'HTTP isteği aracılığıyla e-posta gönderin.',\n ko: 'HTTP 호출을 통해 이메일을 보냅니다.',\n },\n readme: './README.md',\n formItems: [\n {\n key: 'endpoint',\n label: 'Endpoint',\n type: ConnectorConfigFormItemType.Text,\n required: true,\n placeholder: '<https://example.com/your-http-endpoint>',\n },\n {\n key: 'authorization',\n label: 'Authorization Header',\n type: ConnectorConfigFormItemType.Text,\n required: false,\n placeholder: '<Bearer your-token>',\n tooltip:\n 'The authorization header to be sent with the request, you can verify the value in your server.',\n },\n ],\n};\n","import { z } from 'zod';\n\nexport const httpMailConfigGuard = z.object({\n endpoint: z.string(),\n authorization: z.string().optional(),\n});\n\nexport type HttpMailConfig = z.infer<typeof httpMailConfigGuard>;\n"],"mappings":";AAAA,SAAS,cAAc;AACvB,SAAS,KAAK,iBAAiB;AAQ/B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACbP,SAAS,mCAAmC;AAErC,IAAM,kBAAqC;AAAA,EAChD,IAAI;AAAA,EACJ,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,MAAM;AAAA,IACJ,IAAI;AAAA,EACN;AAAA,EACA,MAAM;AAAA,EACN,UAAU;AAAA,EACV,aAAa;AAAA,IACX,IAAI;AAAA,IACJ,SAAS;AAAA,IACT,SAAS;AAAA,IACT,IAAI;AAAA,EACN;AAAA,EACA,QAAQ;AAAA,EACR,WAAW;AAAA,IACT;AAAA,MACE,KAAK;AAAA,MACL,OAAO;AAAA,MACP,MAAM,4BAA4B;AAAA,MAClC,UAAU;AAAA,MACV,aAAa;AAAA,IACf;AAAA,IACA;AAAA,MACE,KAAK;AAAA,MACL,OAAO;AAAA,MACP,MAAM,4BAA4B;AAAA,MAClC,UAAU;AAAA,MACV,aAAa;AAAA,MACb,SACE;AAAA,IACJ;AAAA,EACF;AACF;;;ACrCA,SAAS,SAAS;AAEX,IAAM,sBAAsB,EAAE,OAAO;AAAA,EAC1C,UAAU,EAAE,OAAO;AAAA,EACnB,eAAe,EAAE,OAAO,EAAE,SAAS;AACrC,CAAC;;;AFcD,IAAM,cACJ,CAAC,cACD,OAAO,MAAM,gBAAgB;AAC3B,QAAM,EAAE,IAAI,MAAM,SAAS,GAAG,IAAI;AAClC,QAAM,SAAS,eAAgB,MAAM,UAAU,gBAAgB,EAAE;AACjE,iBAAe,QAAQ,mBAAmB;AAC1C,QAAM,EAAE,UAAU,cAAc,IAAI;AAEpC,MAAI;AACF,WAAO,MAAM,IAAI,KAAK,UAAU;AAAA,MAC9B,SAAS;AAAA,QACP,eAAe;AAAA,QACf,gBAAgB;AAAA,MAClB;AAAA,MACA,MAAM;AAAA,QACJ;AAAA,QACA;AAAA,QACA;AAAA,QACA,GAAI,MAAM,EAAE,GAAG;AAAA,MACjB;AAAA,IACF,CAAC;AAAA,EACH,SAAS,OAAgB;AACvB,QAAI,iBAAiB,WAAW;AAC9B,YAAM;AAAA,QACJ,UAAU,EAAE,MAAM,QAAQ;AAAA,MAC5B,IAAI;AAEJ;AAAA,QACE,OAAO,YAAY;AAAA,QACnB,IAAI;AAAA,UACF,oBAAoB;AAAA,UACpB,mCAAmC,OAAO,OAAO;AAAA,QACnD;AAAA,MACF;AAEA,YAAM,IAAI,eAAe,oBAAoB,SAAS,OAAO;AAAA,IAC/D;AAEA,UAAM,IAAI,eAAe,oBAAoB,SAAS,KAAK;AAAA,EAC7D;AACF;AAEF,IAAM,0BAA2D,OAAO,EAAE,UAAU,MAAM;AACxF,SAAO;AAAA,IACL,UAAU;AAAA,IACV,MAAM,cAAc;AAAA,IACpB,aAAa;AAAA,IACb,aAAa,YAAY,SAAS;AAAA,EACpC;AACF;AAEA,IAAO,gBAAQ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logto/connector-http-email",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Email connector to send email via HTTP call.",
|
|
5
5
|
"author": "Silverhand Inc. <contact@silverhand.io>",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@silverhand/essentials": "^2.9.1",
|
|
8
8
|
"got": "^14.0.0",
|
|
9
9
|
"zod": "3.24.3",
|
|
10
|
-
"@logto/connector-kit": "^
|
|
10
|
+
"@logto/connector-kit": "^5.0.0"
|
|
11
11
|
},
|
|
12
12
|
"main": "./lib/index.js",
|
|
13
13
|
"module": "./lib/index.js",
|
|
@@ -61,7 +61,8 @@
|
|
|
61
61
|
"dev": "tsup --watch",
|
|
62
62
|
"lint": "eslint --ext .ts src",
|
|
63
63
|
"lint:report": "pnpm lint --format json --output-file report.json",
|
|
64
|
-
"test": "vitest src",
|
|
64
|
+
"test": "vitest run src",
|
|
65
|
+
"test:watch": "vitest src --watch",
|
|
65
66
|
"test:ci": "pnpm run test --silent --coverage"
|
|
66
67
|
}
|
|
67
68
|
}
|