node-mailjet
Advanced tools
Comparing version 5.0.1 to 5.1.0
@@ -5,2 +5,24 @@ # Changelog | ||
## [5.1.0](https://github.com/mailjet/mailjet-apiv3-nodejs/compare/v5.0.1...v5.1.0) (2022-07-22) | ||
### Added features | ||
* Add full TypeScript cover for Mailjet types ([784c4cd](https://github.com/mailjet/mailjet-apiv3-nodejs/commits/784c4cd79c5531aaeacbdde5547e2793b57d1427)) | ||
### Other changes | ||
* Change global and TypeScript rules ([fa4fb60](https://github.com/mailjet/mailjet-apiv3-nodejs/commits/fa4fb606f4e380886734468ac18c2c90e05ebd17)) | ||
### Docs changes | ||
* Update TypeScript documentation part; Add example of using Mailjet types ([15f2d11](https://github.com/mailjet/mailjet-apiv3-nodejs/commits/15f2d11dae63fe54fdb350864b99129fcc26afb0)) | ||
### Dependency changes for security | ||
* Change webpack dependency terser package 5.0.0 - 5.14.1 ([959018a](https://github.com/mailjet/mailjet-apiv3-nodejs/commits/959018a77ff36a70769f36e22f57bdc89cba2157)) | ||
### [5.0.1](https://github.com/mailjet/mailjet-apiv3-nodejs/compare/v5.0.0...v5.0.1) (2022-06-30) | ||
@@ -7,0 +29,0 @@ |
@@ -8,3 +8,4 @@ import HttpMethods from './request/HttpMethods'; | ||
} | ||
export * from './types/api'; | ||
export { Client, Request, HttpMethods }; | ||
export default Mailjet; |
import { TObject } from "../types"; | ||
import { IAPILocalResponse, IAPIResponse } from "../types/api/Response"; | ||
import { ILibraryResponse, ILibraryLocalResponse } from "../types/api/LibraryResponse"; | ||
import HttpMethods from './HttpMethods'; | ||
@@ -30,4 +30,4 @@ import { TRequestData, TRequestParams, TRequestConstructorConfig } from './IRequest'; | ||
action(name: string): this; | ||
request<TBody extends TRequestData>(data?: TRequestData, params?: TRequestParams, performAPICall?: true): Promise<IAPIResponse<TBody>>; | ||
request<TBody extends TRequestData, TParams extends TUnknownRec>(data?: TBody, params?: TParams, performAPICall?: false): Promise<IAPILocalResponse<TBody, TParams>>; | ||
request<TBody extends TRequestData>(data?: TRequestData, params?: TRequestParams, performAPICall?: true): Promise<ILibraryResponse<TBody>>; | ||
request<TBody extends TRequestData, TParams extends TUnknownRec>(data?: TBody, params?: TParams, performAPICall?: false): Promise<ILibraryLocalResponse<TBody, TParams>>; | ||
static protocol: "https://"; | ||
@@ -34,0 +34,0 @@ static parseToJSONb(text: string): any; |
@@ -15,2 +15,2 @@ /*! | ||
/*! node-mailjet v5.0.1 */ | ||
/*! node-mailjet v5.1.0 */ |
@@ -1,1 +0,1 @@ | ||
/*! node-mailjet v5.0.1 */ | ||
/*! node-mailjet v5.1.0 */ |
{ | ||
"name": "node-mailjet", | ||
"version": "5.0.1", | ||
"version": "5.1.0", | ||
"lockfileVersion": 1, | ||
@@ -5,0 +5,0 @@ "requires": true, |
{ | ||
"name": "node-mailjet", | ||
"version": "5.0.1", | ||
"version": "5.1.0", | ||
"main": "./mailjet.node.js", | ||
@@ -5,0 +5,0 @@ "browser": "./mailjet.web.js", |
130
README.md
@@ -13,3 +13,3 @@ [mailjet]: http://www.mailjet.com | ||
[![Build Status](https://travis-ci.org/mailjet/mailjet-apiv3-nodejs.svg?branch=master)](https://travis-ci.org/mailjet/mailjet-apiv3-nodejs) | ||
![Current Version](https://img.shields.io/badge/version-5.0.1-green.svg) | ||
![Current Version](https://img.shields.io/badge/version-5.1.0-green.svg) | ||
@@ -50,2 +50,4 @@ ## Overview | ||
- [TypeScript](#typescript) | ||
- [Send Email example](#send-email-example) | ||
- [Get Contact example](#get-contact-example) | ||
- [Our external Typings](#our-external-typings) | ||
@@ -464,5 +466,24 @@ - [Browser Demo](#browser-demo) | ||
At the moment library based on `TypeScript` and provide **generic** method `Request.request<TResult>(options)`: | ||
Current library based on `TypeScript` and provide **full cover** for **Mailjet types**. \ | ||
All **types** can be exported from main entrypoint `'node-mailjet'`: | ||
```typescript | ||
import Mailjet from 'node-mailjet' | ||
import { | ||
Contact, | ||
SendEmailV3, | ||
SendEmailV3_1, | ||
Message, | ||
Segmentation, | ||
Template, | ||
SendMessage, | ||
Webhook | ||
} from 'node-mailjet'; | ||
``` | ||
As well library has a **generic** method `Request.request<TResult>(data, params, performAPICall)` that could use with these **types**. | ||
### Send Email example | ||
```typescript | ||
import Mailjet, { SendEmailV3_1 } from 'node-mailjet' | ||
const mailjet = new Mailjet({ | ||
@@ -473,19 +494,70 @@ apiKey: process.env.MJ_APIKEY_PUBLIC, | ||
interface IContact { | ||
IsExcludedFromCampaigns: boolean; | ||
Name: string; | ||
CreatedAt: string; | ||
DeliveredCount: number; | ||
Email: string; | ||
} | ||
(async () => { | ||
const data: SendEmailV3_1.IBody = { | ||
Messages: [ | ||
{ | ||
From: { | ||
Email: 'pilot@test.com', | ||
}, | ||
To: [ | ||
{ | ||
Email: 'passenger@test.com', | ||
}, | ||
], | ||
TemplateErrorReporting: { | ||
Email: 'reporter@test.com', | ||
Name: 'Reporter', | ||
}, | ||
Subject: 'Your email flight plan!', | ||
HTMLPart: '<h3>Dear passenger, welcome to Mailjet!</h3><br />May the delivery force be with you!', | ||
TextPart: 'Dear passenger, welcome to Mailjet! May the delivery force be with you!', | ||
}, | ||
], | ||
}; | ||
type TResponse<TEntity> = { | ||
Count: number; | ||
Total: number; | ||
Data: Array<TEntity> | ||
const result = await mailjet | ||
.post('send', { version: 'v3.1' }) | ||
.request<SendEmailV3_1.IResponse>(data); | ||
const { Status } = result.body.Messages[0]; | ||
})(); | ||
``` | ||
And `response` will have this shape: | ||
```typescript | ||
{ | ||
response: Response; | ||
body: { | ||
Messages: Array<{ | ||
Status: string; | ||
Errors: Array<Record<string, string>>; | ||
CustomID: string; | ||
... | ||
}>; | ||
} | ||
} | ||
``` | ||
const request = mailjet | ||
.get('contact') | ||
.request<TResponse<IContact>>() | ||
### Get Contact Example | ||
```typescript | ||
import Mailjet, { Contact } from 'node-mailjet' | ||
const mailjet = new Mailjet({ | ||
apiKey: process.env.MJ_APIKEY_PUBLIC, | ||
apiSecret: process.env.MJ_APIKEY_PRIVATE | ||
}); | ||
(async () => { | ||
const queryData: Contact.IGetContactQueryParams = { | ||
IsExcludedFromCampaigns: false, | ||
Campaign: 2234234, | ||
}; | ||
const result = await mailjet | ||
.get('contact', { version: 'v3' }) | ||
.request<Contact.TGetContactResponse>({}, queryData); | ||
const ContactID = result.body.Data[0].ID; | ||
})(); | ||
``` | ||
@@ -498,11 +570,12 @@ | ||
body: { | ||
Count: number; | ||
Total: number; | ||
Data: Array<{ | ||
IsExcludedFromCampaigns: boolean; | ||
Name: string; | ||
CreatedAt: string; | ||
DeliveredCount: number; | ||
Email: string; | ||
}>; | ||
Count: number; | ||
Total: number; | ||
Data: Array<{ | ||
IsExcludedFromCampaigns: boolean; | ||
Name: string; | ||
CreatedAt: string; | ||
DeliveredCount: number; | ||
Email: string; | ||
... | ||
}>; | ||
} | ||
@@ -512,8 +585,5 @@ } | ||
> At the moment library provide a types for Mailjet API only for _library level_.\ | ||
> But we work to cover all Mailjet types. | ||
### Our external Typings | ||
For new or for earlier versions of library you can use `@types/node-mailjet` dependency. | ||
For earlier versions _(`3.*.*` and low)_ of library you can use `@types/node-mailjet` dependency. | ||
@@ -520,0 +590,0 @@ The `types` are published in `npm` and ready for use. \ |
@@ -1,1 +0,1 @@ | ||
5.0.1 | ||
5.1.0 |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
1555611
40
3335
1022