@line/bot-sdk
Advanced tools
Comparing version 6.8.2 to 6.8.3
@@ -0,1 +1,16 @@ | ||
## 6.8.3 (05 Nov 2019) | ||
### Bug fix | ||
* Add exception handler in middleware (#153) | ||
### Feature | ||
* Flex Message Update 1 (#173) | ||
* Support friend statistics API (#161) | ||
### Misc | ||
* Update dependencies (#174) | ||
## 6.8.2 (08 Aug 2019) | ||
@@ -2,0 +17,0 @@ |
@@ -45,2 +45,15 @@ /// <reference types="node" /> | ||
getNumberOfSentBroadcastMessages(date: string): Promise<Types.NumberOfMessagesSentResponse>; | ||
getNumberOfMessageDeliveries(date: string): Promise<Types.NumberOfMessageDeliveriesResponse>; | ||
getNumberOfFollowers(date: string): Promise<Types.NumberOfFollowersResponse>; | ||
getFriendDemographics(): Promise<Types.FriendDemoGraphics>; | ||
} | ||
export declare class OAuth { | ||
private http; | ||
constructor(); | ||
issueAccessToken(client_id: string, client_secret: string): Promise<{ | ||
access_token: string; | ||
expires_in: number; | ||
token_type: "Bearer"; | ||
}>; | ||
revokeAccessToken(access_token: string): Promise<{}>; | ||
} |
@@ -17,2 +17,5 @@ "use strict"; | ||
} | ||
const API_HOST = process.env.API_BASE_URL || "https://api.line.me/v2/"; | ||
const BOT_BASE_URL = process.env.API_BASE_URL || `${API_HOST}bot/`; | ||
const OAUTH_BASE_URL = `${API_HOST}oauth/`; | ||
class Client { | ||
@@ -25,3 +28,3 @@ constructor(config) { | ||
this.http = new http_1.default({ | ||
baseURL: process.env.API_BASE_URL || "https://api.line.me/v2/bot/", | ||
baseURL: BOT_BASE_URL, | ||
defaultHeaders: { | ||
@@ -192,3 +195,33 @@ Authorization: "Bearer " + this.config.channelAccessToken, | ||
} | ||
async getNumberOfMessageDeliveries(date) { | ||
const res = await this.http.get(`/insight/message/delivery?date=${date}`); | ||
return ensureJSON(res); | ||
} | ||
async getNumberOfFollowers(date) { | ||
const res = await this.http.get(`/insight/followers?date=${date}`); | ||
return ensureJSON(res); | ||
} | ||
async getFriendDemographics() { | ||
const res = await this.http.get(`/insight/demographic`); | ||
return ensureJSON(res); | ||
} | ||
} | ||
exports.default = Client; | ||
class OAuth { | ||
constructor() { | ||
this.http = new http_1.default({ | ||
baseURL: OAUTH_BASE_URL, | ||
}); | ||
} | ||
issueAccessToken(client_id, client_secret) { | ||
return this.http.postForm("/accessToken", { | ||
grant_type: "client_credentials", | ||
client_id, | ||
client_secret, | ||
}); | ||
} | ||
revokeAccessToken(access_token) { | ||
return this.http.postForm("/revoke", { access_token }); | ||
} | ||
} | ||
exports.OAuth = OAuth; |
@@ -16,2 +16,3 @@ /// <reference types="node" /> | ||
post<T>(url: string, body?: any): Promise<T>; | ||
postForm<T>(url: string, body?: any): Promise<T>; | ||
postBinary<T>(url: string, data: Buffer | Readable, contentType?: string): Promise<T>; | ||
@@ -18,0 +19,0 @@ delete<T>(url: string, params?: any): Promise<T>; |
@@ -7,2 +7,3 @@ "use strict"; | ||
const fileType = require("file-type"); | ||
const qs = require("querystring"); | ||
const pkg = require("../package.json"); | ||
@@ -42,2 +43,8 @@ class HTTPClient { | ||
} | ||
async postForm(url, body) { | ||
const res = await this.instance.post(url, qs.stringify(body), { | ||
headers: { "Content-Type": "application/x-www-form-urlencoded" }, | ||
}); | ||
return res.data; | ||
} | ||
async postBinary(url, data, contentType) { | ||
@@ -44,0 +51,0 @@ const buffer = await (async () => { |
@@ -1,6 +0,6 @@ | ||
import Client from "./client"; | ||
import Client, { OAuth } from "./client"; | ||
import middleware from "./middleware"; | ||
import validateSignature from "./validate-signature"; | ||
export { Client, middleware, validateSignature }; | ||
export { Client, middleware, validateSignature, OAuth }; | ||
export * from "./exceptions"; | ||
export * from "./types"; |
@@ -8,2 +8,3 @@ "use strict"; | ||
exports.Client = client_1.default; | ||
exports.OAuth = client_1.OAuth; | ||
const middleware_1 = require("./middleware"); | ||
@@ -10,0 +11,0 @@ exports.middleware = middleware_1.default; |
@@ -9,3 +9,3 @@ /// <reference types="node" /> | ||
export declare type NextCallback = (err?: Error) => void; | ||
export declare type Middleware = (req: Request, res: Response, next: NextCallback) => void; | ||
export declare type Middleware = (req: Request, res: Response, next: NextCallback) => void | Promise<void>; | ||
export default function middleware(config: Types.MiddlewareConfig): Middleware; |
@@ -14,3 +14,3 @@ "use strict"; | ||
const secret = config.channelSecret; | ||
return async (req, res, next) => { | ||
const _middleware = async (req, res, next) => { | ||
// header names are lower-cased | ||
@@ -33,3 +33,3 @@ // https://nodejs.org/api/http.html#http_message_headers | ||
// body may not be parsed yet, parse it to a buffer | ||
return new Promise(resolve => body_parser_1.raw({ type: "*/*" })(req, res, () => resolve(req.body))); | ||
return new Promise((resolve, reject) => body_parser_1.raw({ type: "*/*" })(req, res, (error) => error ? reject(error) : resolve(req.body))); | ||
} | ||
@@ -50,3 +50,6 @@ })(); | ||
}; | ||
return (req, res, next) => { | ||
_middleware(req, res, next).catch(next); | ||
}; | ||
} | ||
exports.default = middleware; |
@@ -20,2 +20,5 @@ import { Readable } from "stream"; | ||
type ChatType = "group" | "room"; | ||
const API_HOST: string = process.env.API_BASE_URL || "https://api.line.me/v2/"; | ||
const BOT_BASE_URL: string = process.env.API_BASE_URL || `${API_HOST}bot/`; | ||
const OAUTH_BASE_URL = `${API_HOST}oauth/`; | ||
@@ -33,3 +36,3 @@ export default class Client { | ||
this.http = new HTTPClient({ | ||
baseURL: process.env.API_BASE_URL || "https://api.line.me/v2/bot/", | ||
baseURL: BOT_BASE_URL, | ||
defaultHeaders: { | ||
@@ -318,2 +321,56 @@ Authorization: "Bearer " + this.config.channelAccessToken, | ||
} | ||
public async getNumberOfMessageDeliveries( | ||
date: string, | ||
): Promise<Types.NumberOfMessageDeliveriesResponse> { | ||
const res = await this.http.get<Types.NumberOfMessageDeliveriesResponse>( | ||
`/insight/message/delivery?date=${date}`, | ||
); | ||
return ensureJSON(res); | ||
} | ||
public async getNumberOfFollowers( | ||
date: string, | ||
): Promise<Types.NumberOfFollowersResponse> { | ||
const res = await this.http.get<Types.NumberOfFollowersResponse>( | ||
`/insight/followers?date=${date}`, | ||
); | ||
return ensureJSON(res); | ||
} | ||
public async getFriendDemographics(): Promise<Types.FriendDemoGraphics> { | ||
const res = await this.http.get<Types.FriendDemoGraphics>( | ||
`/insight/demographic`, | ||
); | ||
return ensureJSON(res); | ||
} | ||
} | ||
export class OAuth { | ||
private http: HTTPClient; | ||
constructor() { | ||
this.http = new HTTPClient({ | ||
baseURL: OAUTH_BASE_URL, | ||
}); | ||
} | ||
public issueAccessToken( | ||
client_id: string, | ||
client_secret: string, | ||
): Promise<{ | ||
access_token: string; | ||
expires_in: number; | ||
token_type: "Bearer"; | ||
}> { | ||
return this.http.postForm("/accessToken", { | ||
grant_type: "client_credentials", | ||
client_id, | ||
client_secret, | ||
}); | ||
} | ||
public revokeAccessToken(access_token: string): Promise<{}> { | ||
return this.http.postForm("/revoke", { access_token }); | ||
} | ||
} |
@@ -5,2 +5,3 @@ import axios, { AxiosInstance, AxiosError, AxiosResponse } from "axios"; | ||
import * as fileType from "file-type"; | ||
import * as qs from "querystring"; | ||
@@ -58,2 +59,10 @@ const pkg = require("../package.json"); | ||
public async postForm<T>(url: string, body?: any): Promise<T> { | ||
const res = await this.instance.post(url, qs.stringify(body), { | ||
headers: { "Content-Type": "application/x-www-form-urlencoded" }, | ||
}); | ||
return res.data; | ||
} | ||
public async postBinary<T>( | ||
@@ -60,0 +69,0 @@ url: string, |
@@ -1,6 +0,6 @@ | ||
import Client from "./client"; | ||
import Client, { OAuth } from "./client"; | ||
import middleware from "./middleware"; | ||
import validateSignature from "./validate-signature"; | ||
export { Client, middleware, validateSignature }; | ||
export { Client, middleware, validateSignature, OAuth }; | ||
@@ -7,0 +7,0 @@ // re-export exceptions and types |
@@ -15,3 +15,3 @@ import { raw } from "body-parser"; | ||
next: NextCallback, | ||
) => void; | ||
) => void | Promise<void>; | ||
@@ -29,3 +29,3 @@ function isValidBody(body?: any): body is string | Buffer { | ||
return async (req, res, next) => { | ||
const _middleware: Middleware = async (req, res, next) => { | ||
// header names are lower-cased | ||
@@ -48,4 +48,6 @@ // https://nodejs.org/api/http.html#http_message_headers | ||
// body may not be parsed yet, parse it to a buffer | ||
return new Promise<Buffer>(resolve => | ||
raw({ type: "*/*" })(req as any, res as any, () => resolve(req.body)), | ||
return new Promise<Buffer>((resolve, reject) => | ||
raw({ type: "*/*" })(req as any, res as any, (error: Error) => | ||
error ? reject(error) : resolve(req.body), | ||
), | ||
); | ||
@@ -71,2 +73,5 @@ } | ||
}; | ||
return (req, res, next): void => { | ||
(<Promise<void>>_middleware(req, res, next)).catch(next); | ||
}; | ||
} |
{ | ||
"name": "@line/bot-sdk", | ||
"version": "6.8.2", | ||
"version": "6.8.3", | ||
"description": "Node.js SDK for LINE Messaging API", | ||
@@ -49,8 +49,10 @@ "engines": { | ||
"@types/express": "^4.0.35", | ||
"@types/finalhandler": "^1.1.0", | ||
"@types/mocha": "^2.2.41", | ||
"del-cli": "^1.1.0", | ||
"express": "^4.16.3", | ||
"finalhandler": "^1.1.2", | ||
"husky": "^0.14.3", | ||
"mocha": "^5.2.0", | ||
"nyc": "^13.3.0", | ||
"nyc": "^14.1.1", | ||
"prettier": "^1.15.2", | ||
@@ -57,0 +59,0 @@ "ts-node": "^8.3.0", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
193448
5003
13
2