@motionpicture/coa-service 9.3.0-alpha.2 → 9.3.0-alpha.4

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 CHANGED
@@ -17,7 +17,6 @@ COA SDK for Node.js
17
17
  - [Environment variables](#environment-variables)
18
18
  - [劇場情報を取得する](#劇場情報を取得する)
19
19
  - [Code Samples](#code-samples)
20
- - [Documentation](#documentation)
21
20
 
22
21
  ## Specification
23
22
 
@@ -73,7 +72,3 @@ masterService.theater({
73
72
  ## Code Samples
74
73
 
75
74
  Code sample are [here](https://github.com/motionpicture/coa-service/tree/master/example).
76
-
77
- ## Documentation
78
-
79
- `npm run doc` emits typedoc to ./docs.
@@ -14,25 +14,26 @@ const service = new COA.service.Reserve(
14
14
  );
15
15
 
16
16
  service.delReserve({
17
- reserveNum: '985',
18
- theaterCode: '118',
19
- dateJouei: '20170403',
20
- titleCode: '16344',
21
- titleBranchNum: '0',
22
- timeBegin: '1000',
23
- telNum: '09012345678',
17
+ reserveNum: '45701',
18
+ theaterCode: '120',
19
+ "dateJouei": "20240125",
20
+ "titleCode": "99100",
21
+ "titleBranchNum": "0",
22
+ "timeBegin": "1720",
23
+ telNum: '09096793896',
24
24
  listSeat: [
25
25
  {
26
26
  seatSection: '0',
27
- seatNum: 'B-4'
27
+ "seatNum": "b-18",
28
28
  },
29
29
  {
30
30
  seatSection: '0',
31
- seatNum: 'B-5'
31
+ "seatNum": "b-19",
32
32
  }
33
33
  ]
34
34
  }).then((result) => {
35
35
  console.log(result);
36
36
  }).catch((err) => {
37
37
  console.error(err);
38
+ console.log('err instanceof COA.COAServiceError?:', err instanceof COA.COAServiceError);
38
39
  });
@@ -10,7 +10,8 @@ const service = new COA.service.Master(
10
10
  endpoint: process.env.COA_ENDPOINT,
11
11
  auth: new COA.auth.RefreshToken({
12
12
  endpoint: process.env.COA_ENDPOINT,
13
- refreshToken: process.env.COA_REFRESH_TOKEN
13
+ refreshToken: process.env.COA_REFRESH_TOKEN,
14
+ useFetch: true
14
15
  })
15
16
  },
16
17
  { timeout: 1000 }
@@ -14,9 +14,9 @@ const service = new COA.service.Reserve({
14
14
  });
15
15
 
16
16
  service.stateReserve({
17
- theaterCode: '112',
18
- reserveNum: '588456',
19
- telNum: '0362778824'
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);
@@ -42,11 +42,11 @@ export declare class RefreshTokenClient {
42
42
  * APIリクエストを投げる
43
43
  * 認証エラー(401,403)であれば自動的に一度だけアクセストークンをリフレッシュします。
44
44
  */
45
- request(options: IRequestOptions, expectedStatusCodes: number[]): Promise<any>;
45
+ request(options: IRequestOptions, expectedStatusCodes: number[]): Promise<import("../transporters").IResponseBodyAsJson>;
46
46
  /**
47
47
  * 認証情報が適切である前提でAPIリクエストを投げる
48
48
  */
49
- protected makeRequest(options: IRequestOptions, expectedStatusCodes: number[]): Promise<any>;
49
+ protected makeRequest(options: IRequestOptions, expectedStatusCodes: number[]): Promise<import("../transporters").IResponseBodyAsJson>;
50
50
  /**
51
51
  * 認証情報を更新する
52
52
  */
@@ -12,10 +12,12 @@ 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');
18
19
  const TIMEOUT = 10000;
20
+ const MAX_NUM_TRY_REQUEST = 1;
19
21
  /**
20
22
  * リフレッシュトークン認証クライアント
21
23
  */
@@ -74,7 +76,7 @@ class RefreshTokenClient {
74
76
  debug('requesting an access token...');
75
77
  try {
76
78
  const params = new URLSearchParams({ refresh_token: String(this.options.refreshToken) });
77
- const res = yield fetch(`${this.options.endpoint}/token/access_token`, {
79
+ const res = yield (0, node_fetch_1.default)(`${this.options.endpoint}/token/access_token`, {
78
80
  method: 'POST',
79
81
  headers: {
80
82
  'Content-Type': 'application/x-www-form-urlencoded'
@@ -192,11 +194,10 @@ class RefreshTokenClient {
192
194
  let retry = true;
193
195
  let result;
194
196
  let numberOfTry = 0;
195
- // tslint:disable-next-line:no-magic-numbers
196
- while (numberOfTry >= 0) {
197
+ while (result === undefined) {
197
198
  try {
198
199
  numberOfTry += 1;
199
- if (numberOfTry > 1) {
200
+ if (numberOfTry > MAX_NUM_TRY_REQUEST) {
200
201
  retry = false;
201
202
  }
202
203
  options.auth = { bearer: yield this.getAccessToken() };
@@ -224,9 +225,6 @@ class RefreshTokenClient {
224
225
  }
225
226
  }
226
227
  }
227
- else {
228
- // no operation
229
- }
230
228
  throw error;
231
229
  }
232
230
  }
package/lib/index.d.ts CHANGED
@@ -2,10 +2,11 @@
2
2
  * coa-service
3
3
  */
4
4
  import * as factory from './factory';
5
+ import { RefreshTokenClient } from './auth/refreshTokenClient';
5
6
  import { MasterService } from './service/master';
6
7
  import { ReserveService } from './service/reserve';
7
- import { RefreshTokenClient } from './auth/refreshTokenClient';
8
- export import factory = factory;
8
+ import { COAServiceError } from './transporter/coaServiceError';
9
+ export { COAServiceError, factory };
9
10
  export declare namespace auth {
10
11
  /**
11
12
  * リフレッシュトークン認証クライアント
@@ -13,9 +14,6 @@ export declare namespace auth {
13
14
  class RefreshToken extends RefreshTokenClient {
14
15
  }
15
16
  }
16
- /**
17
- * recommended
18
- */
19
17
  export declare namespace service {
20
18
  /**
21
19
  * マスターサービス
package/lib/index.js CHANGED
@@ -1,14 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.service = exports.auth = exports.factory = void 0;
3
+ exports.service = exports.auth = exports.factory = exports.COAServiceError = void 0;
4
4
  /**
5
5
  * coa-service
6
6
  */
7
7
  const factory = require("./factory");
8
+ exports.factory = factory;
9
+ const refreshTokenClient_1 = require("./auth/refreshTokenClient");
8
10
  const master_1 = require("./service/master");
9
11
  const reserve_1 = require("./service/reserve");
10
- const refreshTokenClient_1 = require("./auth/refreshTokenClient");
11
- exports.factory = factory;
12
+ const coaServiceError_1 = require("./transporter/coaServiceError");
13
+ Object.defineProperty(exports, "COAServiceError", { enumerable: true, get: function () { return coaServiceError_1.COAServiceError; } });
12
14
  var auth;
13
15
  (function (auth) {
14
16
  /**
@@ -18,9 +20,6 @@ var auth;
18
20
  }
19
21
  auth.RefreshToken = RefreshToken;
20
22
  })(auth = exports.auth || (exports.auth = {}));
21
- /**
22
- * recommended
23
- */
24
23
  var service;
25
24
  (function (service) {
26
25
  /**
package/lib/service.d.ts CHANGED
@@ -13,10 +13,10 @@ export type ICustomRequestOption = Pick<request.CoreOptions, 'timeout'>;
13
13
  */
14
14
  export declare class Service {
15
15
  options: IOptions;
16
- requestOptions: request.CoreOptions;
16
+ requestOptions: ICustomRequestOption;
17
17
  constructor(options: IOptions, requestOptions?: ICustomRequestOption);
18
18
  /**
19
19
  * Create and send request to API
20
20
  */
21
- request(options: IRequestOptions, expectedStatusCodes: number[]): Promise<any>;
21
+ request(options: IRequestOptions, expectedStatusCodes: number[]): Promise<import("./transporters").IResponseBodyAsJson>;
22
22
  }
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 defaultOptions = {
32
- baseUrl: this.options.endpoint,
33
- // simple: false,
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
  }
@@ -0,0 +1,10 @@
1
+ import { IRequestOptions } from './requestOption';
2
+ /**
3
+ * COAServiceError
4
+ */
5
+ export declare class COAServiceError extends Error {
6
+ code: number;
7
+ status: string;
8
+ requestOptions: IRequestOptions | undefined;
9
+ constructor(code: number, status: string, message?: string, requestOptions?: IRequestOptions);
10
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.COAServiceError = void 0;
4
+ /**
5
+ * COAServiceError
6
+ */
7
+ class COAServiceError extends Error {
8
+ constructor(code, status, message, requestOptions) {
9
+ super(message);
10
+ this.name = 'COAServiceError';
11
+ this.code = code;
12
+ this.status = status;
13
+ this.requestOptions = requestOptions;
14
+ }
15
+ }
16
+ exports.COAServiceError = COAServiceError;
@@ -0,0 +1,16 @@
1
+ interface IHeaders {
2
+ [key: string]: any;
3
+ }
4
+ type IQS = Record<string, string | number | any[]>;
5
+ export interface IRequestOptions {
6
+ baseUrl?: string;
7
+ auth?: {
8
+ bearer?: string;
9
+ };
10
+ qs?: IQS;
11
+ method?: string;
12
+ headers?: IHeaders;
13
+ timeout?: number;
14
+ uri: string;
15
+ }
16
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,26 +1,30 @@
1
1
  import * as request from 'request';
2
+ import { COAServiceError } from './transporter/coaServiceError';
3
+ import { IRequestOptions } from './transporter/requestOption';
2
4
  /**
3
5
  * リクエスト成功の場合のレスポンス本文のstatus属性の値
4
6
  * 失敗の場合はstring型だが、成功の場合のみnumber型が返却されるので注意すること。
5
7
  */
6
8
  export declare const RESPONSE_BODY_STAUS_SUCCESS = 0;
7
- export type IRequestOptions = Pick<request.OptionsWithUri, 'uri' | 'method' | 'qs' | 'auth' | 'headers' | 'baseUrl' | 'timeout'>;
9
+ export { COAServiceError, IRequestOptions };
10
+ export type IResponseBodyAsJson = {
11
+ /**
12
+ * COAの提示するステータス
13
+ * 0でなければBadRequest
14
+ */
15
+ status?: string | number;
16
+ /**
17
+ * COAの提示するメッセージ
18
+ */
19
+ message?: string;
20
+ } & Record<string, any>;
21
+ export type IResponseBody = IResponseBodyAsJson;
8
22
  /**
9
23
  * transporter abstract class
10
24
  * トランスポーター抽象クラス
11
25
  */
12
26
  export declare abstract class Transporter {
13
- abstract request(options: IRequestOptions): Promise<any>;
14
- }
15
- export type IBodyResponseCallback = Promise<any>;
16
- /**
17
- * COAServiceError
18
- */
19
- export declare class COAServiceError extends Error {
20
- code: number;
21
- status: string;
22
- requestOptions: IRequestOptions | undefined;
23
- constructor(code: number, status: string, message?: string, requestOptions?: IRequestOptions);
27
+ abstract request(options: IRequestOptions): Promise<IResponseBody>;
24
28
  }
25
29
  /**
26
30
  * DefaultTransporter
@@ -35,11 +39,11 @@ export declare class DefaultTransporter implements Transporter {
35
39
  /**
36
40
  * Configures request options before making a request.
37
41
  */
38
- static CONFIGURE(options: IRequestOptions): IRequestOptions;
42
+ static CONFIGURE(options: IRequestOptions): IRequestOptions & Pick<request.OptionsWithUri, 'json' | 'useQuerystring'>;
39
43
  /**
40
44
  * Makes a request with given options and invokes callback.
41
45
  */
42
- request(options: IRequestOptions): Promise<any>;
46
+ request(options: IRequestOptions): Promise<IResponseBody>;
43
47
  /**
44
48
  * Wraps the response callback.
45
49
  */
@@ -62,7 +66,7 @@ export declare class FetchTransporter implements Transporter {
62
66
  /**
63
67
  * Makes a request with given options and invokes callback.
64
68
  */
65
- request(options: IRequestOptions): Promise<any>;
69
+ request(options: IRequestOptions): Promise<IResponseBody>;
66
70
  /**
67
71
  * Wraps the response callback.
68
72
  */
@@ -9,15 +9,18 @@ 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.DefaultTransporter = exports.COAServiceError = exports.Transporter = exports.RESPONSE_BODY_STAUS_SUCCESS = void 0;
12
+ exports.FetchTransporter = exports.DefaultTransporter = exports.Transporter = exports.COAServiceError = exports.RESPONSE_BODY_STAUS_SUCCESS = void 0;
13
13
  // tslint:disable:max-classes-per-file
14
14
  /**
15
15
  * transporters
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");
22
+ const coaServiceError_1 = require("./transporter/coaServiceError");
23
+ Object.defineProperty(exports, "COAServiceError", { enumerable: true, get: function () { return coaServiceError_1.COAServiceError; } });
21
24
  const debug = createDebug('coa-service:transporters');
22
25
  // tslint:disable-next-line
23
26
  const pkg = require('../package.json');
@@ -33,19 +36,7 @@ exports.RESPONSE_BODY_STAUS_SUCCESS = 0;
33
36
  class Transporter {
34
37
  }
35
38
  exports.Transporter = Transporter;
36
- /**
37
- * COAServiceError
38
- */
39
- class COAServiceError extends Error {
40
- constructor(code, status, message, requestOptions) {
41
- super(message);
42
- this.name = 'COAServiceError';
43
- this.code = code;
44
- this.status = status;
45
- this.requestOptions = requestOptions;
46
- }
47
- }
48
- exports.COAServiceError = COAServiceError;
39
+ // export type IBodyResponseCallback = Promise<any>;
49
40
  /**
50
41
  * DefaultTransporter
51
42
  */
@@ -70,7 +61,7 @@ class DefaultTransporter {
70
61
  else {
71
62
  // no operation
72
63
  }
73
- return options;
64
+ return Object.assign(Object.assign({}, options), { json: true, useQuerystring: true });
74
65
  }
75
66
  /**
76
67
  * Makes a request with given options and invokes callback.
@@ -96,25 +87,26 @@ class DefaultTransporter {
96
87
  */
97
88
  wrapCallback(error, response, body, options) {
98
89
  const requestOptions = { uri: options.uri };
99
- let err = new COAServiceError(http_status_1.INTERNAL_SERVER_ERROR, '', 'An unexpected error occurred.', requestOptions);
90
+ let err = new coaServiceError_1.COAServiceError(http_status_1.INTERNAL_SERVER_ERROR, '', 'An unexpected error occurred.', requestOptions);
100
91
  if (error instanceof Error) {
101
- throw new COAServiceError(http_status_1.INTERNAL_SERVER_ERROR, '', error.message, requestOptions);
92
+ throw new coaServiceError_1.COAServiceError(http_status_1.INTERNAL_SERVER_ERROR, '', error.message, requestOptions);
102
93
  }
103
- debug('request processed', error, body);
94
+ debug('request processed', error, body, response.statusCode);
95
+ const statusFromBody = body === null || body === void 0 ? void 0 : body.status;
104
96
  // tslint:disable-next-line:no-single-line-block-comment
105
97
  /* istanbul ignore else */
106
98
  if (response.statusCode !== undefined) {
107
99
  if (this.expectedStatusCodes.indexOf(response.statusCode) < 0) {
108
100
  if (typeof body === 'string') {
109
101
  // Consider all 4xx and 5xx responses errors.
110
- err = new COAServiceError(response.statusCode, '', body, requestOptions);
102
+ err = new coaServiceError_1.COAServiceError(response.statusCode, '', body, requestOptions);
111
103
  }
112
104
  else {
113
105
  // エラーレスポンスにステータスがあった場合
114
106
  // tslint:disable-next-line:no-single-line-block-comment
115
107
  /* istanbul ignore else */
116
- if (body.status !== undefined) {
117
- err = new COAServiceError(response.statusCode, body.status, body.message, requestOptions);
108
+ if (statusFromBody !== undefined) {
109
+ err = new coaServiceError_1.COAServiceError(response.statusCode, statusFromBody, body.message, requestOptions);
118
110
  }
119
111
  else {
120
112
  // no operation
@@ -123,18 +115,18 @@ class DefaultTransporter {
123
115
  }
124
116
  else {
125
117
  // HTTPステータスコード2xxでも、レスポンス本文のステータスが0でなければBadRequest
126
- if (body.status !== undefined && body.status !== exports.RESPONSE_BODY_STAUS_SUCCESS) {
127
- err = new COAServiceError(response.statusCode, body.status, body.message, requestOptions);
118
+ if (statusFromBody !== undefined && statusFromBody !== exports.RESPONSE_BODY_STAUS_SUCCESS) {
119
+ err = new coaServiceError_1.COAServiceError(response.statusCode, statusFromBody, body.message, requestOptions);
128
120
  }
129
121
  else {
130
- if (response.statusCode === http_status_1.NO_CONTENT) {
131
- // consider 204
132
- return;
133
- }
134
- else {
135
- // consider 200,201
136
- return body;
137
- }
122
+ // if (response.statusCode === NO_CONTENT) {
123
+ // // consider 204
124
+ // return;
125
+ // } else {
126
+ // // consider 200,201
127
+ // return body;
128
+ // }
129
+ return body;
138
130
  }
139
131
  }
140
132
  }
@@ -165,10 +157,10 @@ class FetchTransporter {
165
157
  // tslint:disable-next-line:no-single-line-block-comment
166
158
  /* istanbul ignore else */
167
159
  if (!options.headers['User-Agent']) {
168
- options.headers['User-Agent'] = DefaultTransporter.USER_AGENT;
160
+ options.headers['User-Agent'] = FetchTransporter.USER_AGENT;
169
161
  }
170
- else if (options.headers['User-Agent'].indexOf(DefaultTransporter.USER_AGENT) === -1) {
171
- options.headers['User-Agent'] = `${options.headers['User-Agent']} ${DefaultTransporter.USER_AGENT}`;
162
+ else if (options.headers['User-Agent'].indexOf(FetchTransporter.USER_AGENT) === -1) {
163
+ options.headers['User-Agent'] = `${options.headers['User-Agent']} ${FetchTransporter.USER_AGENT}`;
172
164
  }
173
165
  else {
174
166
  // no operation
@@ -182,11 +174,10 @@ class FetchTransporter {
182
174
  var _a;
183
175
  return __awaiter(this, void 0, void 0, function* () {
184
176
  const requestOptions = FetchTransporter.CONFIGURE(options);
185
- debug('requesting...', requestOptions);
186
177
  const input = `${requestOptions.baseUrl}${requestOptions.uri}?${querystring.stringify(requestOptions.qs)}`;
187
178
  const accessToken = (_a = requestOptions.auth) === null || _a === void 0 ? void 0 : _a.bearer;
188
- debug('fetching...', input);
189
- return fetch(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))
179
+ debug('fetching...', input, requestOptions);
180
+ 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
181
  .then((res) => __awaiter(this, void 0, void 0, function* () { return this.wrapCallback(res, requestOptions); }));
191
182
  });
192
183
  }
@@ -196,7 +187,7 @@ class FetchTransporter {
196
187
  wrapCallback(res, options) {
197
188
  return __awaiter(this, void 0, void 0, function* () {
198
189
  const requestOptions = { uri: options.uri };
199
- let err = new COAServiceError(http_status_1.INTERNAL_SERVER_ERROR, '', 'An unexpected error occurred.', requestOptions);
190
+ let err = new coaServiceError_1.COAServiceError(http_status_1.INTERNAL_SERVER_ERROR, '', 'An unexpected error occurred.', requestOptions);
200
191
  debug('fetch processed. res.status:', res.status, 'content-type:', res.headers.get('content-type'));
201
192
  let body = {};
202
193
  try {
@@ -206,50 +197,44 @@ class FetchTransporter {
206
197
  else {
207
198
  body = yield res.json();
208
199
  }
200
+ debug('fetch processed. body:', body);
209
201
  }
210
202
  catch (error) {
211
203
  // no op
212
204
  }
213
- // tslint:disable-next-line:no-single-line-block-comment
214
- /* istanbul ignore else */
215
- if (res.status !== undefined) {
205
+ if (typeof body === 'string') {
206
+ // Consider all 4xx and 5xx responses errors.
207
+ err = new coaServiceError_1.COAServiceError(res.status, '', body, requestOptions);
208
+ }
209
+ else {
216
210
  if (this.expectedStatusCodes.indexOf(res.status) < 0) {
217
- if (typeof body === 'string') {
218
- // Consider all 4xx and 5xx responses errors.
219
- err = new COAServiceError(res.status, '', body, requestOptions);
211
+ // エラーレスポンスにステータスがあった場合
212
+ // tslint:disable-next-line:no-single-line-block-comment
213
+ /* istanbul ignore else */
214
+ if (body.status !== undefined) {
215
+ err = new coaServiceError_1.COAServiceError(res.status, String(body.status), body.message, requestOptions);
220
216
  }
221
217
  else {
222
- // エラーレスポンスにステータスがあった場合
223
- // tslint:disable-next-line:no-single-line-block-comment
224
- /* istanbul ignore else */
225
- if (body.status !== undefined) {
226
- err = new COAServiceError(res.status, body.status, body.message, requestOptions);
227
- }
228
- else {
229
- // no operation
230
- }
218
+ // no operation
231
219
  }
232
220
  }
233
221
  else {
234
222
  // HTTPステータスコード2xxでも、レスポンス本文のステータスが0でなければBadRequest
235
223
  if (body.status !== undefined && body.status !== exports.RESPONSE_BODY_STAUS_SUCCESS) {
236
- err = new COAServiceError(res.status, body.status, body.message, requestOptions);
224
+ err = new coaServiceError_1.COAServiceError(res.status, String(body.status), body.message, requestOptions);
237
225
  }
238
226
  else {
239
- if (res.status === http_status_1.NO_CONTENT) {
240
- // consider 204
241
- return;
242
- }
243
- else {
244
- // consider 200,201
245
- return body;
246
- }
227
+ // if (res.status === NO_CONTENT) {
228
+ // // consider 204
229
+ // return;
230
+ // } else {
231
+ // // consider 200,201
232
+ // return body;
233
+ // }
234
+ return body;
247
235
  }
248
236
  }
249
237
  }
250
- else {
251
- // no operation
252
- }
253
238
  throw err;
254
239
  });
255
240
  }
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.2"
83
+ "version": "9.3.0-alpha.4"
82
84
  }