@motionpicture/coa-service 9.3.0-alpha.2 → 9.3.0-alpha.3
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/example/stateReserve.js +3 -3
- package/lib/auth/refreshTokenClient.js +2 -1
- package/lib/service.d.ts +1 -1
- package/lib/service.js +4 -15
- package/lib/transporters.d.ts +1 -1
- package/lib/transporters.js +10 -9
- package/package.json +3 -1
package/example/stateReserve.js
CHANGED
|
@@ -14,9 +14,9 @@ const service = new COA.service.Reserve({
|
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
service.stateReserve({
|
|
17
|
-
theaterCode: '
|
|
18
|
-
reserveNum: '
|
|
19
|
-
telNum: '
|
|
17
|
+
theaterCode: '120',
|
|
18
|
+
reserveNum: '45699',
|
|
19
|
+
telNum: '0312345678'
|
|
20
20
|
}).then((result) => {
|
|
21
21
|
fs.writeFileSync(`${__dirname}/output/stateReserve.json`, JSON.stringify(result, null, ' '));
|
|
22
22
|
console.log(result);
|
|
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.RefreshTokenClient = void 0;
|
|
13
13
|
const createDebug = require("debug");
|
|
14
14
|
const http_status_1 = require("http-status");
|
|
15
|
+
const node_fetch_1 = require("node-fetch");
|
|
15
16
|
const request = require("request");
|
|
16
17
|
const transporters_1 = require("../transporters");
|
|
17
18
|
const debug = createDebug('coa-service:auth:refreshTokenClient');
|
|
@@ -74,7 +75,7 @@ class RefreshTokenClient {
|
|
|
74
75
|
debug('requesting an access token...');
|
|
75
76
|
try {
|
|
76
77
|
const params = new URLSearchParams({ refresh_token: String(this.options.refreshToken) });
|
|
77
|
-
const res = yield
|
|
78
|
+
const res = yield (0, node_fetch_1.default)(`${this.options.endpoint}/token/access_token`, {
|
|
78
79
|
method: 'POST',
|
|
79
80
|
headers: {
|
|
80
81
|
'Content-Type': 'application/x-www-form-urlencoded'
|
package/lib/service.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export type ICustomRequestOption = Pick<request.CoreOptions, 'timeout'>;
|
|
|
13
13
|
*/
|
|
14
14
|
export declare class Service {
|
|
15
15
|
options: IOptions;
|
|
16
|
-
requestOptions:
|
|
16
|
+
requestOptions: ICustomRequestOption;
|
|
17
17
|
constructor(options: IOptions, requestOptions?: ICustomRequestOption);
|
|
18
18
|
/**
|
|
19
19
|
* Create and send request to API
|
package/lib/service.js
CHANGED
|
@@ -16,27 +16,16 @@ exports.Service = void 0;
|
|
|
16
16
|
class Service {
|
|
17
17
|
constructor(options, requestOptions) {
|
|
18
18
|
this.options = options;
|
|
19
|
-
this.requestOptions = {};
|
|
20
|
-
// tslint:disable-next-line:no-single-line-block-comment
|
|
21
|
-
/* istanbul ignore else */
|
|
22
|
-
if (requestOptions !== undefined) {
|
|
23
|
-
this.requestOptions = Object.assign(Object.assign({}, this.requestOptions), requestOptions);
|
|
24
|
-
}
|
|
19
|
+
this.requestOptions = Object.assign({}, requestOptions);
|
|
25
20
|
}
|
|
26
21
|
/**
|
|
27
22
|
* Create and send request to API
|
|
28
23
|
*/
|
|
29
24
|
request(options, expectedStatusCodes) {
|
|
30
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
// resolveWithFullResponse: true,
|
|
35
|
-
json: true,
|
|
36
|
-
method: 'GET',
|
|
37
|
-
useQuerystring: true
|
|
38
|
-
};
|
|
39
|
-
const requestOptions = Object.assign(Object.assign(Object.assign({}, defaultOptions), this.requestOptions), options);
|
|
26
|
+
const requestOptions = Object.assign(Object.assign({ baseUrl: this.options.endpoint,
|
|
27
|
+
// json: true,
|
|
28
|
+
method: 'GET' }, this.requestOptions), options);
|
|
40
29
|
return this.options.auth.request(requestOptions, expectedStatusCodes);
|
|
41
30
|
});
|
|
42
31
|
}
|
package/lib/transporters.d.ts
CHANGED
|
@@ -35,7 +35,7 @@ export declare class DefaultTransporter implements Transporter {
|
|
|
35
35
|
/**
|
|
36
36
|
* Configures request options before making a request.
|
|
37
37
|
*/
|
|
38
|
-
static CONFIGURE(options: IRequestOptions): IRequestOptions
|
|
38
|
+
static CONFIGURE(options: IRequestOptions): IRequestOptions & Pick<request.OptionsWithUri, 'json' | 'useQuerystring'>;
|
|
39
39
|
/**
|
|
40
40
|
* Makes a request with given options and invokes callback.
|
|
41
41
|
*/
|
package/lib/transporters.js
CHANGED
|
@@ -16,6 +16,7 @@ exports.FetchTransporter = exports.DefaultTransporter = exports.COAServiceError
|
|
|
16
16
|
*/
|
|
17
17
|
const createDebug = require("debug");
|
|
18
18
|
const http_status_1 = require("http-status");
|
|
19
|
+
const node_fetch_1 = require("node-fetch");
|
|
19
20
|
const querystring = require("querystring");
|
|
20
21
|
const request = require("request");
|
|
21
22
|
const debug = createDebug('coa-service:transporters');
|
|
@@ -70,7 +71,7 @@ class DefaultTransporter {
|
|
|
70
71
|
else {
|
|
71
72
|
// no operation
|
|
72
73
|
}
|
|
73
|
-
return options;
|
|
74
|
+
return Object.assign(Object.assign({}, options), { json: true, useQuerystring: true });
|
|
74
75
|
}
|
|
75
76
|
/**
|
|
76
77
|
* Makes a request with given options and invokes callback.
|
|
@@ -100,7 +101,8 @@ class DefaultTransporter {
|
|
|
100
101
|
if (error instanceof Error) {
|
|
101
102
|
throw new COAServiceError(http_status_1.INTERNAL_SERVER_ERROR, '', error.message, requestOptions);
|
|
102
103
|
}
|
|
103
|
-
debug('request processed', error, body);
|
|
104
|
+
debug('request processed', error, body, response.statusCode);
|
|
105
|
+
const statusFromBody = body === null || body === void 0 ? void 0 : body.status;
|
|
104
106
|
// tslint:disable-next-line:no-single-line-block-comment
|
|
105
107
|
/* istanbul ignore else */
|
|
106
108
|
if (response.statusCode !== undefined) {
|
|
@@ -113,8 +115,8 @@ class DefaultTransporter {
|
|
|
113
115
|
// エラーレスポンスにステータスがあった場合
|
|
114
116
|
// tslint:disable-next-line:no-single-line-block-comment
|
|
115
117
|
/* istanbul ignore else */
|
|
116
|
-
if (
|
|
117
|
-
err = new COAServiceError(response.statusCode,
|
|
118
|
+
if (statusFromBody !== undefined) {
|
|
119
|
+
err = new COAServiceError(response.statusCode, statusFromBody, body.message, requestOptions);
|
|
118
120
|
}
|
|
119
121
|
else {
|
|
120
122
|
// no operation
|
|
@@ -123,8 +125,8 @@ class DefaultTransporter {
|
|
|
123
125
|
}
|
|
124
126
|
else {
|
|
125
127
|
// HTTPステータスコード2xxでも、レスポンス本文のステータスが0でなければBadRequest
|
|
126
|
-
if (
|
|
127
|
-
err = new COAServiceError(response.statusCode,
|
|
128
|
+
if (statusFromBody !== undefined && statusFromBody !== exports.RESPONSE_BODY_STAUS_SUCCESS) {
|
|
129
|
+
err = new COAServiceError(response.statusCode, statusFromBody, body.message, requestOptions);
|
|
128
130
|
}
|
|
129
131
|
else {
|
|
130
132
|
if (response.statusCode === http_status_1.NO_CONTENT) {
|
|
@@ -182,11 +184,10 @@ class FetchTransporter {
|
|
|
182
184
|
var _a;
|
|
183
185
|
return __awaiter(this, void 0, void 0, function* () {
|
|
184
186
|
const requestOptions = FetchTransporter.CONFIGURE(options);
|
|
185
|
-
debug('requesting...', requestOptions);
|
|
186
187
|
const input = `${requestOptions.baseUrl}${requestOptions.uri}?${querystring.stringify(requestOptions.qs)}`;
|
|
187
188
|
const accessToken = (_a = requestOptions.auth) === null || _a === void 0 ? void 0 : _a.bearer;
|
|
188
|
-
debug('fetching...', input);
|
|
189
|
-
return
|
|
189
|
+
debug('fetching...', input, requestOptions);
|
|
190
|
+
return (0, node_fetch_1.default)(input, Object.assign({ method: requestOptions.method, headers: Object.assign(Object.assign({}, requestOptions.headers), (typeof accessToken === 'string') ? { Authorization: `Bearer ${accessToken}` } /* istanbul ignore else */ : undefined) }, (typeof requestOptions.timeout === 'number') ? { signal: AbortSignal.timeout(requestOptions.timeout) } : undefined))
|
|
190
191
|
.then((res) => __awaiter(this, void 0, void 0, function* () { return this.wrapCallback(res, requestOptions); }));
|
|
191
192
|
});
|
|
192
193
|
}
|
package/package.json
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"debug": "^3.2.7",
|
|
17
17
|
"http-status": "^1.5.2",
|
|
18
|
+
"node-fetch": "2.7.0",
|
|
18
19
|
"request": "^2.88.2"
|
|
19
20
|
},
|
|
20
21
|
"description": "COA client library for Node.js",
|
|
@@ -24,6 +25,7 @@
|
|
|
24
25
|
"@types/mocha": "^5.2.0",
|
|
25
26
|
"@types/nock": "^9.1.3",
|
|
26
27
|
"@types/node": "18.19.2",
|
|
28
|
+
"@types/node-fetch": "2.6.11",
|
|
27
29
|
"@types/request": "^2.48.5",
|
|
28
30
|
"@types/sinon": "^4.3.3",
|
|
29
31
|
"coveralls": "^3.0.1",
|
|
@@ -78,5 +80,5 @@
|
|
|
78
80
|
"postversion": "git push origin --tags",
|
|
79
81
|
"prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
|
|
80
82
|
},
|
|
81
|
-
"version": "9.3.0-alpha.
|
|
83
|
+
"version": "9.3.0-alpha.3"
|
|
82
84
|
}
|