@enonic-types/lib-mail 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/README.md +72 -0
- package/mail.d.ts +56 -0
- package/package.json +36 -0
package/README.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# Enonic XP lib-mail TS types
|
|
2
|
+
|
|
3
|
+
> TypeScript definitions for `lib-mail` library of Enonic XP
|
|
4
|
+
## Install
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
npm i --save-dev @enonic/lib-mail
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Use
|
|
11
|
+
|
|
12
|
+
Add the corresponding types to your `tsconfig.json` file that is used for application's server-side TypeScript code.
|
|
13
|
+
|
|
14
|
+
`tsconfig.json`
|
|
15
|
+
```json
|
|
16
|
+
{
|
|
17
|
+
"compilerOptions": {
|
|
18
|
+
"types": [
|
|
19
|
+
"@enonic-types/lib-mail"
|
|
20
|
+
]
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Require and custom imports
|
|
26
|
+
|
|
27
|
+
To make `require` work out of box, you must install and add the `@enonic-types/global` types. Aside from providing definitions for XP global objects, e.g. `log`, `app`, `__`, etc, requiring library by the default path will return typed object.
|
|
28
|
+
|
|
29
|
+
`tsconfig.json`
|
|
30
|
+
```diff
|
|
31
|
+
{
|
|
32
|
+
"compilerOptions": {
|
|
33
|
+
"types": [
|
|
34
|
+
+ "@enonic-types/global"
|
|
35
|
+
"@enonic-types/lib-mail"
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
`example.ts`
|
|
42
|
+
```ts
|
|
43
|
+
const {send} = require('/lib/xp/mail');
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
More detailed explanation on how it works and how to type custom import function can be found [here](https://github.com/enonic/xp/tree/master/modules/lib/typescript/README.md).
|
|
47
|
+
|
|
48
|
+
### ES6-style import
|
|
49
|
+
|
|
50
|
+
If you are planning to use `import` in your code and transpile it with the default `tsc` TypeScript compiler, you'll need to add proper types mapping to your configuration.
|
|
51
|
+
|
|
52
|
+
`tsconfig.json`
|
|
53
|
+
```diff
|
|
54
|
+
{
|
|
55
|
+
"compilerOptions": {
|
|
56
|
+
"types": [
|
|
57
|
+
"@enonic-types/lib-mail"
|
|
58
|
+
]
|
|
59
|
+
+ "baseUrl": "./",
|
|
60
|
+
+ "paths": {
|
|
61
|
+
+ "/lib/xp/mail": ["node_modules/@enonic-types/lib-mail"],
|
|
62
|
+
+ }
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
`example.ts`
|
|
68
|
+
```ts
|
|
69
|
+
import {send} from '/lib/xp/mail';
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Setting `baseUrl` and `paths` will allow the `tsc` to keep the valid paths in the resulting JavaScript files.
|
package/mail.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
interface XpLibraries {
|
|
3
|
+
'/lib/xp/mail': typeof import('./mail');
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
export interface Attachment {
|
|
7
|
+
fileName: string;
|
|
8
|
+
data: object;
|
|
9
|
+
mimeType?: string;
|
|
10
|
+
headers?: Record<string, string>;
|
|
11
|
+
}
|
|
12
|
+
export interface SendMessageParams {
|
|
13
|
+
subject: string;
|
|
14
|
+
from: string;
|
|
15
|
+
body: string;
|
|
16
|
+
to: string | string[];
|
|
17
|
+
cc?: string | string[];
|
|
18
|
+
bcc?: string | string[];
|
|
19
|
+
replyTo?: string;
|
|
20
|
+
contentType?: string;
|
|
21
|
+
headers?: Record<string, string>;
|
|
22
|
+
attachments?: Attachment[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* This function sends an email message using the mail server configured.
|
|
26
|
+
*
|
|
27
|
+
* The address values can be either a simple email address (e.g. ‘name@domain.org’ ) or an address with a
|
|
28
|
+
* display name. In the latter case the email will be enclosed with angle brackets (e.g. ‘Some Name <name@domain.org>’ ).
|
|
29
|
+
*
|
|
30
|
+
* The parameters `to`, `cc` and `bcc` can be passed as a single string or as an array of strings, if there are multiple addresses
|
|
31
|
+
* to specify.
|
|
32
|
+
*
|
|
33
|
+
* The content-type of the email can be specified by using the `contentType` parameter. See example below for
|
|
34
|
+
* sending a message with an HTML body.
|
|
35
|
+
*
|
|
36
|
+
* @example-ref examples/mail/send.js
|
|
37
|
+
*
|
|
38
|
+
* @param {object} params JSON with the parameters.
|
|
39
|
+
* @param {string} params.from The email address, and optionally name of the sender of the message.
|
|
40
|
+
* @param {(string|string[])} params.to The email address(es), and optionally name(s) of the primary message’s recipient(s).
|
|
41
|
+
* @param {(string|string[])} [params.cc] The carbon copy email address(es).
|
|
42
|
+
* @param {(string|string[])} [params.bcc] The blind carbon copy email address(es).
|
|
43
|
+
* @param {string} [params.replyTo] The email address that should be used to reply to the message.
|
|
44
|
+
* @param {string} params.subject The subject line of the message.
|
|
45
|
+
* @param {string} params.body The text content of the message.
|
|
46
|
+
* @param {string} [params.contentType] Content type of the message body.
|
|
47
|
+
* @param {object} [params.headers] Custom headers in the form of name-value pairs.
|
|
48
|
+
* @param {object[]} [params.attachments] Attachments to include in the email.
|
|
49
|
+
* @param {string} params.attachments.fileName Attachment file name.
|
|
50
|
+
* @param {*} params.attachments.data Attachment stream.
|
|
51
|
+
* @param {string} [params.attachments.mimeType] Attachment content type. If not specified will be inferred from the file extension.
|
|
52
|
+
* @param {object} [params.attachments.headers] Attachment headers, in the form of name-value pairs.
|
|
53
|
+
*
|
|
54
|
+
* @returns {boolean} True if the message was sent successfully, false otherwise.
|
|
55
|
+
*/
|
|
56
|
+
export declare function send(params: SendMessageParams): boolean;
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@enonic-types/lib-mail",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Type definitions for lib-mail.",
|
|
5
|
+
"types": "mail.d.ts",
|
|
6
|
+
"files": [
|
|
7
|
+
"mail.d.ts"
|
|
8
|
+
],
|
|
9
|
+
"scripts": {
|
|
10
|
+
"pre": "npm run --prefix ../ pre",
|
|
11
|
+
"packlist": "npx npm-packlist"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/enonic/xp.git#master"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"enonic",
|
|
19
|
+
"enonic-xp",
|
|
20
|
+
"lib-mail",
|
|
21
|
+
"mail",
|
|
22
|
+
"types",
|
|
23
|
+
"typescript"
|
|
24
|
+
],
|
|
25
|
+
"contributors": [
|
|
26
|
+
"Mikita Taukachou <edloidas@gmail.com> (https://edloidas.github.io/)"
|
|
27
|
+
],
|
|
28
|
+
"license": "Apache-2.0",
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/enonic/xp/issues"
|
|
31
|
+
},
|
|
32
|
+
"homepage": "https://github.com/enonic/xp/tree/master#readme",
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
}
|
|
36
|
+
}
|