@logto/connector-http-email 0.1.0 → 0.2.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/README.md +31 -1
- package/lib/index.js +4 -3
- package/lib/index.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,3 +1,33 @@
|
|
|
1
1
|
# HTTP email connector
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The official Logto connector for HTTP email.
|
|
4
|
+
|
|
5
|
+
## Get started
|
|
6
|
+
|
|
7
|
+
The HTTP email connector allows you to send emails via HTTP call. To use the HTTP email connector, you'll need to have your own email service that expose an HTTP API for sending emails. Logto will call this API when it needs to send an email. For example, when a user registers, Logto will call the HTTP API to send a verification email.
|
|
8
|
+
|
|
9
|
+
## Set up HTTP email connector
|
|
10
|
+
|
|
11
|
+
To use the HTTP email connector, you need to set up an HTTP endpoint that Logto can call, and an optional authorization token for the endpoint.
|
|
12
|
+
|
|
13
|
+
> 💡 **Tip**
|
|
14
|
+
>
|
|
15
|
+
> Note that to prevent errors in authentication flow, the configured `endpoint` must return a 2xx response after receiving the webhook to inform Logto that it has received the notification to send the email.
|
|
16
|
+
>
|
|
17
|
+
> Meanwhile, in this scenario, you need to monitor email service to ensure successful email delivery. Alternatively, you can add monitoring to your email sending API to promptly detect email delivery failures.
|
|
18
|
+
|
|
19
|
+
## Payload
|
|
20
|
+
|
|
21
|
+
The HTTP email connector will send the following payload to the endpoint when it needs to send an email:
|
|
22
|
+
|
|
23
|
+
```json
|
|
24
|
+
{
|
|
25
|
+
"to": "foo@logto.io",
|
|
26
|
+
"type": "SignIn",
|
|
27
|
+
"payload": {
|
|
28
|
+
"code": "123456"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
You can find all of the types in https://docs.logto.io/docs/recipes/configure-connectors/email-connector/configure-popular-email-service/#email-template, and the full type definition of `SendMessageData` in [connector-kit](https://github.com/logto-io/logto/tree/master/packages/toolkit/connector-kit/src/types/passwordless.ts).
|
package/lib/index.js
CHANGED
|
@@ -11,8 +11,8 @@ import {
|
|
|
11
11
|
// src/constant.ts
|
|
12
12
|
import { ConnectorConfigFormItemType } from "@logto/connector-kit";
|
|
13
13
|
var defaultMetadata = {
|
|
14
|
-
id: "http-email
|
|
15
|
-
target: "http-
|
|
14
|
+
id: "http-email",
|
|
15
|
+
target: "http-email",
|
|
16
16
|
platform: null,
|
|
17
17
|
name: {
|
|
18
18
|
en: "HTTP Email"
|
|
@@ -36,7 +36,8 @@ var defaultMetadata = {
|
|
|
36
36
|
label: "Authorization Header",
|
|
37
37
|
type: ConnectorConfigFormItemType.Text,
|
|
38
38
|
required: false,
|
|
39
|
-
placeholder: "<Bearer your-token>"
|
|
39
|
+
placeholder: "<Bearer your-token>",
|
|
40
|
+
tooltip: "The authorization header to be sent with the request, you can verify the value in your server."
|
|
40
41
|
}
|
|
41
42
|
]
|
|
42
43
|
};
|
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
|
|
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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IACL,UAAU;AAAA,IACV,MAAM,cAAc;AAAA,IACpB,aAAa;AAAA,IACb,aAAa,YAAY,SAAS;AAAA,EACpC;AACF;AAEA,IAAO,cAAQ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logto/connector-http-email",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Email connector to send email via HTTP call.",
|
|
5
5
|
"author": "Silverhand Inc. <contact@silverhand.io>",
|
|
6
6
|
"dependencies": {
|
|
@@ -44,15 +44,15 @@
|
|
|
44
44
|
"@silverhand/ts-config": "6.0.0",
|
|
45
45
|
"@types/node": "^20.11.20",
|
|
46
46
|
"@types/supertest": "^6.0.2",
|
|
47
|
-
"@vitest/coverage-v8": "^2.
|
|
47
|
+
"@vitest/coverage-v8": "^2.1.8",
|
|
48
48
|
"eslint": "^8.56.0",
|
|
49
49
|
"lint-staged": "^15.0.2",
|
|
50
50
|
"nock": "^13.3.1",
|
|
51
51
|
"prettier": "^3.0.0",
|
|
52
52
|
"supertest": "^7.0.0",
|
|
53
|
-
"tsup": "^8.
|
|
53
|
+
"tsup": "^8.3.0",
|
|
54
54
|
"typescript": "^5.5.3",
|
|
55
|
-
"vitest": "^2.
|
|
55
|
+
"vitest": "^2.1.8"
|
|
56
56
|
},
|
|
57
57
|
"scripts": {
|
|
58
58
|
"precommit": "lint-staged",
|