@motionpicture/coa-service 9.3.0-alpha.4 → 9.3.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/lib/auth/refreshTokenClient.d.ts +0 -4
- package/lib/auth/refreshTokenClient.js +1 -44
- package/lib/service.d.ts +5 -3
- package/lib/service.js +1 -3
- package/lib/transporters.d.ts +0 -24
- package/lib/transporters.js +99 -107
- package/package.json +3 -7
|
@@ -17,10 +17,6 @@ export declare class RefreshTokenClient {
|
|
|
17
17
|
credentials: ICredentials;
|
|
18
18
|
options: IOptions;
|
|
19
19
|
constructor(options: IOptions);
|
|
20
|
-
/**
|
|
21
|
-
* トークンエンドポイントからアクセストークンを取得します。
|
|
22
|
-
*/
|
|
23
|
-
getTokenWithRequest(): Promise<ICredentials>;
|
|
24
20
|
/**
|
|
25
21
|
* トークンエンドポイントからアクセストークンを取得します。
|
|
26
22
|
*/
|
|
@@ -13,7 +13,6 @@ exports.RefreshTokenClient = void 0;
|
|
|
13
13
|
const createDebug = require("debug");
|
|
14
14
|
const http_status_1 = require("http-status");
|
|
15
15
|
const node_fetch_1 = require("node-fetch");
|
|
16
|
-
const request = require("request");
|
|
17
16
|
const transporters_1 = require("../transporters");
|
|
18
17
|
const debug = createDebug('coa-service:auth:refreshTokenClient');
|
|
19
18
|
const TIMEOUT = 10000;
|
|
@@ -26,48 +25,6 @@ class RefreshTokenClient {
|
|
|
26
25
|
this.options = options;
|
|
27
26
|
this.credentials = {};
|
|
28
27
|
}
|
|
29
|
-
/**
|
|
30
|
-
* トークンエンドポイントからアクセストークンを取得します。
|
|
31
|
-
*/
|
|
32
|
-
getTokenWithRequest() {
|
|
33
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
-
return new Promise((resolve, reject) => {
|
|
35
|
-
debug('requesting an access token...');
|
|
36
|
-
request.post({
|
|
37
|
-
baseUrl: this.options.endpoint,
|
|
38
|
-
uri: '/token/access_token',
|
|
39
|
-
form: {
|
|
40
|
-
refresh_token: this.options.refreshToken
|
|
41
|
-
},
|
|
42
|
-
json: true
|
|
43
|
-
}, (error, response, body) => {
|
|
44
|
-
if (error instanceof Error) {
|
|
45
|
-
reject(new Error(error.message));
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
if (response.statusCode !== http_status_1.OK) {
|
|
49
|
-
let err = new Error('Unexpected error occurred.');
|
|
50
|
-
if (typeof body === 'string') {
|
|
51
|
-
err = new Error(body);
|
|
52
|
-
}
|
|
53
|
-
else if (typeof body.message === 'string' && body.message.length > 0) {
|
|
54
|
-
// エラーレスポンスにメッセージがあった場合
|
|
55
|
-
err = new Error(body.message);
|
|
56
|
-
}
|
|
57
|
-
else if (body.status !== undefined && body.status !== 0) {
|
|
58
|
-
// エラーレスポンスにステータスがあった場合
|
|
59
|
-
err = new Error(body.status);
|
|
60
|
-
}
|
|
61
|
-
reject(err);
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
this.credentials = body;
|
|
65
|
-
resolve(this.credentials);
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
28
|
/**
|
|
72
29
|
* トークンエンドポイントからアクセストークンを取得します。
|
|
73
30
|
*/
|
|
@@ -238,7 +195,7 @@ class RefreshTokenClient {
|
|
|
238
195
|
return __awaiter(this, void 0, void 0, function* () {
|
|
239
196
|
const transporter = (this.options.useFetch === true)
|
|
240
197
|
? new transporters_1.FetchTransporter(expectedStatusCodes)
|
|
241
|
-
: new transporters_1.
|
|
198
|
+
: new transporters_1.FetchTransporter(expectedStatusCodes);
|
|
242
199
|
return transporter.request(options);
|
|
243
200
|
});
|
|
244
201
|
}
|
package/lib/service.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import * as request from 'request';
|
|
2
1
|
import { IRequestOptions, RefreshTokenClient } from './auth/refreshTokenClient';
|
|
3
2
|
/**
|
|
4
3
|
* service constructor options
|
|
5
4
|
*/
|
|
6
|
-
|
|
5
|
+
interface IOptions {
|
|
7
6
|
endpoint: string;
|
|
8
7
|
auth: RefreshTokenClient;
|
|
9
8
|
}
|
|
10
|
-
|
|
9
|
+
interface ICustomRequestOption {
|
|
10
|
+
timeout?: number;
|
|
11
|
+
}
|
|
11
12
|
/**
|
|
12
13
|
* base service class
|
|
13
14
|
*/
|
|
@@ -20,3 +21,4 @@ export declare class Service {
|
|
|
20
21
|
*/
|
|
21
22
|
request(options: IRequestOptions, expectedStatusCodes: number[]): Promise<import("./transporters").IResponseBodyAsJson>;
|
|
22
23
|
}
|
|
24
|
+
export {};
|
package/lib/service.js
CHANGED
|
@@ -23,9 +23,7 @@ class Service {
|
|
|
23
23
|
*/
|
|
24
24
|
request(options, expectedStatusCodes) {
|
|
25
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
-
const requestOptions = Object.assign(Object.assign({ baseUrl: this.options.endpoint,
|
|
27
|
-
// json: true,
|
|
28
|
-
method: 'GET' }, this.requestOptions), options);
|
|
26
|
+
const requestOptions = Object.assign(Object.assign({ baseUrl: this.options.endpoint, method: 'GET' }, this.requestOptions), options);
|
|
29
27
|
return this.options.auth.request(requestOptions, expectedStatusCodes);
|
|
30
28
|
});
|
|
31
29
|
}
|
package/lib/transporters.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as request from 'request';
|
|
2
1
|
import { COAServiceError } from './transporter/coaServiceError';
|
|
3
2
|
import { IRequestOptions } from './transporter/requestOption';
|
|
4
3
|
/**
|
|
@@ -26,29 +25,6 @@ export type IResponseBody = IResponseBodyAsJson;
|
|
|
26
25
|
export declare abstract class Transporter {
|
|
27
26
|
abstract request(options: IRequestOptions): Promise<IResponseBody>;
|
|
28
27
|
}
|
|
29
|
-
/**
|
|
30
|
-
* DefaultTransporter
|
|
31
|
-
*/
|
|
32
|
-
export declare class DefaultTransporter implements Transporter {
|
|
33
|
-
/**
|
|
34
|
-
* Default user agent.
|
|
35
|
-
*/
|
|
36
|
-
static readonly USER_AGENT: string;
|
|
37
|
-
expectedStatusCodes: number[];
|
|
38
|
-
constructor(expectedStatusCodes: number[]);
|
|
39
|
-
/**
|
|
40
|
-
* Configures request options before making a request.
|
|
41
|
-
*/
|
|
42
|
-
static CONFIGURE(options: IRequestOptions): IRequestOptions & Pick<request.OptionsWithUri, 'json' | 'useQuerystring'>;
|
|
43
|
-
/**
|
|
44
|
-
* Makes a request with given options and invokes callback.
|
|
45
|
-
*/
|
|
46
|
-
request(options: IRequestOptions): Promise<IResponseBody>;
|
|
47
|
-
/**
|
|
48
|
-
* Wraps the response callback.
|
|
49
|
-
*/
|
|
50
|
-
private wrapCallback;
|
|
51
|
-
}
|
|
52
28
|
/**
|
|
53
29
|
* FetchTransporter
|
|
54
30
|
*/
|
package/lib/transporters.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.FetchTransporter = exports.
|
|
12
|
+
exports.FetchTransporter = exports.Transporter = exports.COAServiceError = exports.RESPONSE_BODY_STAUS_SUCCESS = void 0;
|
|
13
13
|
// tslint:disable:max-classes-per-file
|
|
14
14
|
/**
|
|
15
15
|
* transporters
|
|
@@ -18,7 +18,6 @@ const createDebug = require("debug");
|
|
|
18
18
|
const http_status_1 = require("http-status");
|
|
19
19
|
const node_fetch_1 = require("node-fetch");
|
|
20
20
|
const querystring = require("querystring");
|
|
21
|
-
const request = require("request");
|
|
22
21
|
const coaServiceError_1 = require("./transporter/coaServiceError");
|
|
23
22
|
Object.defineProperty(exports, "COAServiceError", { enumerable: true, get: function () { return coaServiceError_1.COAServiceError; } });
|
|
24
23
|
const debug = createDebug('coa-service:transporters');
|
|
@@ -36,111 +35,104 @@ exports.RESPONSE_BODY_STAUS_SUCCESS = 0;
|
|
|
36
35
|
class Transporter {
|
|
37
36
|
}
|
|
38
37
|
exports.Transporter = Transporter;
|
|
39
|
-
// export
|
|
40
|
-
/**
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Default user agent.
|
|
141
|
-
*/
|
|
142
|
-
DefaultTransporter.USER_AGENT = `coa-service/${pkg.version}`;
|
|
143
|
-
exports.DefaultTransporter = DefaultTransporter;
|
|
38
|
+
// export class DefaultTransporter implements Transporter {
|
|
39
|
+
// /**
|
|
40
|
+
// * Default user agent.
|
|
41
|
+
// */
|
|
42
|
+
// public static readonly USER_AGENT: string = `coa-service/${pkg.version}`;
|
|
43
|
+
// public expectedStatusCodes: number[];
|
|
44
|
+
// constructor(expectedStatusCodes: number[]) {
|
|
45
|
+
// this.expectedStatusCodes = expectedStatusCodes;
|
|
46
|
+
// }
|
|
47
|
+
// /**
|
|
48
|
+
// * Configures request options before making a request.
|
|
49
|
+
// */
|
|
50
|
+
// public static CONFIGURE(
|
|
51
|
+
// options: IRequestOptions
|
|
52
|
+
// ): IRequestOptions & Pick<request.OptionsWithUri, 'json' | 'useQuerystring'> {
|
|
53
|
+
// // set transporter user agent
|
|
54
|
+
// options.headers = (options.headers !== undefined) ? options.headers : {};
|
|
55
|
+
// // tslint:disable-next-line:no-single-line-block-comment
|
|
56
|
+
// /* istanbul ignore else */
|
|
57
|
+
// if (!options.headers['User-Agent']) {
|
|
58
|
+
// options.headers['User-Agent'] = DefaultTransporter.USER_AGENT;
|
|
59
|
+
// } else if (options.headers['User-Agent'].indexOf(DefaultTransporter.USER_AGENT) === -1) {
|
|
60
|
+
// options.headers['User-Agent'] = `${options.headers['User-Agent']} ${DefaultTransporter.USER_AGENT}`;
|
|
61
|
+
// } else {
|
|
62
|
+
// // no operation
|
|
63
|
+
// }
|
|
64
|
+
// return {
|
|
65
|
+
// ...options,
|
|
66
|
+
// json: true,
|
|
67
|
+
// useQuerystring: true
|
|
68
|
+
// };
|
|
69
|
+
// }
|
|
70
|
+
// /**
|
|
71
|
+
// * Makes a request with given options and invokes callback.
|
|
72
|
+
// */
|
|
73
|
+
// public async request(options: IRequestOptions): Promise<IResponseBody> {
|
|
74
|
+
// const requestOptions = DefaultTransporter.CONFIGURE(options);
|
|
75
|
+
// debug('requesting...', requestOptions);
|
|
76
|
+
// return new Promise<any>((resolve, reject) => {
|
|
77
|
+
// request(requestOptions, (error, response, body) => {
|
|
78
|
+
// try {
|
|
79
|
+
// resolve(this.wrapCallback(error, response, body, requestOptions));
|
|
80
|
+
// } catch (callbackErr) {
|
|
81
|
+
// reject(callbackErr);
|
|
82
|
+
// }
|
|
83
|
+
// });
|
|
84
|
+
// });
|
|
85
|
+
// }
|
|
86
|
+
// /**
|
|
87
|
+
// * Wraps the response callback.
|
|
88
|
+
// */
|
|
89
|
+
// private wrapCallback(error: any, response: request.RequestResponse, body: any, options: IRequestOptions): IResponseBody {
|
|
90
|
+
// const requestOptions = { uri: options.uri };
|
|
91
|
+
// let err: COAServiceError =
|
|
92
|
+
// new COAServiceError(INTERNAL_SERVER_ERROR, '', 'An unexpected error occurred.', requestOptions);
|
|
93
|
+
// if (error instanceof Error) {
|
|
94
|
+
// throw new COAServiceError(INTERNAL_SERVER_ERROR, '', error.message, requestOptions);
|
|
95
|
+
// }
|
|
96
|
+
// debug('request processed', error, body, response.statusCode);
|
|
97
|
+
// const statusFromBody = body?.status;
|
|
98
|
+
// // tslint:disable-next-line:no-single-line-block-comment
|
|
99
|
+
// /* istanbul ignore else */
|
|
100
|
+
// if (response.statusCode !== undefined) {
|
|
101
|
+
// if (this.expectedStatusCodes.indexOf(response.statusCode) < 0) {
|
|
102
|
+
// if (typeof body === 'string') {
|
|
103
|
+
// // Consider all 4xx and 5xx responses errors.
|
|
104
|
+
// err = new COAServiceError(response.statusCode, '', body, requestOptions);
|
|
105
|
+
// } else {
|
|
106
|
+
// // エラーレスポンスにステータスがあった場合
|
|
107
|
+
// // tslint:disable-next-line:no-single-line-block-comment
|
|
108
|
+
// /* istanbul ignore else */
|
|
109
|
+
// if (statusFromBody !== undefined) {
|
|
110
|
+
// err = new COAServiceError(response.statusCode, statusFromBody, body.message, requestOptions);
|
|
111
|
+
// } else {
|
|
112
|
+
// // no operation
|
|
113
|
+
// }
|
|
114
|
+
// }
|
|
115
|
+
// } else {
|
|
116
|
+
// // HTTPステータスコード2xxでも、レスポンス本文のステータスが0でなければBadRequest
|
|
117
|
+
// if (statusFromBody !== undefined && statusFromBody !== RESPONSE_BODY_STAUS_SUCCESS) {
|
|
118
|
+
// err = new COAServiceError(response.statusCode, statusFromBody, body.message, requestOptions);
|
|
119
|
+
// } else {
|
|
120
|
+
// // if (response.statusCode === NO_CONTENT) {
|
|
121
|
+
// // // consider 204
|
|
122
|
+
// // return;
|
|
123
|
+
// // } else {
|
|
124
|
+
// // // consider 200,201
|
|
125
|
+
// // return body;
|
|
126
|
+
// // }
|
|
127
|
+
// return body;
|
|
128
|
+
// }
|
|
129
|
+
// }
|
|
130
|
+
// } else {
|
|
131
|
+
// // no operation
|
|
132
|
+
// }
|
|
133
|
+
// throw err;
|
|
134
|
+
// }
|
|
135
|
+
// }
|
|
144
136
|
/**
|
|
145
137
|
* FetchTransporter
|
|
146
138
|
*/
|
package/package.json
CHANGED
|
@@ -15,24 +15,20 @@
|
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"debug": "^3.2.7",
|
|
17
17
|
"http-status": "^1.5.2",
|
|
18
|
-
"node-fetch": "2.7.0"
|
|
19
|
-
"request": "^2.88.2"
|
|
18
|
+
"node-fetch": "2.7.0"
|
|
20
19
|
},
|
|
21
20
|
"description": "COA client library for Node.js",
|
|
22
21
|
"devDependencies": {
|
|
23
22
|
"@types/debug": "0.0.30",
|
|
24
23
|
"@types/http-status": "^0.2.30",
|
|
25
24
|
"@types/mocha": "^5.2.0",
|
|
26
|
-
"@types/nock": "^9.1.3",
|
|
27
25
|
"@types/node": "18.19.2",
|
|
28
26
|
"@types/node-fetch": "2.6.11",
|
|
29
|
-
"@types/request": "^2.48.5",
|
|
30
27
|
"@types/sinon": "^4.3.3",
|
|
31
28
|
"coveralls": "^3.0.1",
|
|
32
29
|
"grunt-contrib-watch": "^1.1.0",
|
|
33
30
|
"mocha": "^5.2.0",
|
|
34
31
|
"moment": "^2.22.1",
|
|
35
|
-
"nock": "^9.3.0",
|
|
36
32
|
"nyc": "^15.1.0",
|
|
37
33
|
"rimraf": "^2.6.2",
|
|
38
34
|
"sinon": "^5.0.10",
|
|
@@ -43,7 +39,7 @@
|
|
|
43
39
|
},
|
|
44
40
|
"engines": {
|
|
45
41
|
"node": ">=18.0.0",
|
|
46
|
-
"npm": ">=
|
|
42
|
+
"npm": ">=8.0.0"
|
|
47
43
|
},
|
|
48
44
|
"keywords": [],
|
|
49
45
|
"license": "UNLICENSED",
|
|
@@ -80,5 +76,5 @@
|
|
|
80
76
|
"postversion": "git push origin --tags",
|
|
81
77
|
"prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
|
|
82
78
|
},
|
|
83
|
-
"version": "9.3.0
|
|
79
|
+
"version": "9.3.0"
|
|
84
80
|
}
|