@motionpicture/coa-service 9.3.0-alpha.3 → 9.3.0-alpha.5

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 }
@@ -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
  */
@@ -42,11 +38,11 @@ export declare class RefreshTokenClient {
42
38
  * APIリクエストを投げる
43
39
  * 認証エラー(401,403)であれば自動的に一度だけアクセストークンをリフレッシュします。
44
40
  */
45
- request(options: IRequestOptions, expectedStatusCodes: number[]): Promise<any>;
41
+ request(options: IRequestOptions, expectedStatusCodes: number[]): Promise<import("../transporters").IResponseBodyAsJson>;
46
42
  /**
47
43
  * 認証情報が適切である前提でAPIリクエストを投げる
48
44
  */
49
- protected makeRequest(options: IRequestOptions, expectedStatusCodes: number[]): Promise<any>;
45
+ protected makeRequest(options: IRequestOptions, expectedStatusCodes: number[]): Promise<import("../transporters").IResponseBodyAsJson>;
50
46
  /**
51
47
  * 認証情報を更新する
52
48
  */
@@ -13,10 +13,10 @@ 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;
19
+ const MAX_NUM_TRY_REQUEST = 1;
20
20
  /**
21
21
  * リフレッシュトークン認証クライアント
22
22
  */
@@ -25,48 +25,6 @@ class RefreshTokenClient {
25
25
  this.options = options;
26
26
  this.credentials = {};
27
27
  }
28
- /**
29
- * トークンエンドポイントからアクセストークンを取得します。
30
- */
31
- getTokenWithRequest() {
32
- return __awaiter(this, void 0, void 0, function* () {
33
- return new Promise((resolve, reject) => {
34
- debug('requesting an access token...');
35
- request.post({
36
- baseUrl: this.options.endpoint,
37
- uri: '/token/access_token',
38
- form: {
39
- refresh_token: this.options.refreshToken
40
- },
41
- json: true
42
- }, (error, response, body) => {
43
- if (error instanceof Error) {
44
- reject(new Error(error.message));
45
- return;
46
- }
47
- if (response.statusCode !== http_status_1.OK) {
48
- let err = new Error('Unexpected error occurred.');
49
- if (typeof body === 'string') {
50
- err = new Error(body);
51
- }
52
- else if (typeof body.message === 'string' && body.message.length > 0) {
53
- // エラーレスポンスにメッセージがあった場合
54
- err = new Error(body.message);
55
- }
56
- else if (body.status !== undefined && body.status !== 0) {
57
- // エラーレスポンスにステータスがあった場合
58
- err = new Error(body.status);
59
- }
60
- reject(err);
61
- }
62
- else {
63
- this.credentials = body;
64
- resolve(this.credentials);
65
- }
66
- });
67
- });
68
- });
69
- }
70
28
  /**
71
29
  * トークンエンドポイントからアクセストークンを取得します。
72
30
  */
@@ -193,11 +151,10 @@ class RefreshTokenClient {
193
151
  let retry = true;
194
152
  let result;
195
153
  let numberOfTry = 0;
196
- // tslint:disable-next-line:no-magic-numbers
197
- while (numberOfTry >= 0) {
154
+ while (result === undefined) {
198
155
  try {
199
156
  numberOfTry += 1;
200
- if (numberOfTry > 1) {
157
+ if (numberOfTry > MAX_NUM_TRY_REQUEST) {
201
158
  retry = false;
202
159
  }
203
160
  options.auth = { bearer: yield this.getAccessToken() };
@@ -225,9 +182,6 @@ class RefreshTokenClient {
225
182
  }
226
183
  }
227
184
  }
228
- else {
229
- // no operation
230
- }
231
185
  throw error;
232
186
  }
233
187
  }
@@ -241,7 +195,7 @@ class RefreshTokenClient {
241
195
  return __awaiter(this, void 0, void 0, function* () {
242
196
  const transporter = (this.options.useFetch === true)
243
197
  ? new transporters_1.FetchTransporter(expectedStatusCodes)
244
- : new transporters_1.DefaultTransporter(expectedStatusCodes);
198
+ : new transporters_1.FetchTransporter(expectedStatusCodes);
245
199
  return transporter.request(options);
246
200
  });
247
201
  }
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
@@ -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
- export interface IOptions {
5
+ interface IOptions {
7
6
  endpoint: string;
8
7
  auth: RefreshTokenClient;
9
8
  }
10
- export type ICustomRequestOption = Pick<request.CoreOptions, 'timeout'>;
9
+ interface ICustomRequestOption {
10
+ timeout?: number;
11
+ }
11
12
  /**
12
13
  * base service class
13
14
  */
@@ -18,5 +19,6 @@ export declare class Service {
18
19
  /**
19
20
  * Create and send request to API
20
21
  */
21
- request(options: IRequestOptions, expectedStatusCodes: number[]): Promise<any>;
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
  }
@@ -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,49 +1,29 @@
1
- import * as request from 'request';
1
+ import { COAServiceError } from './transporter/coaServiceError';
2
+ import { IRequestOptions } from './transporter/requestOption';
2
3
  /**
3
4
  * リクエスト成功の場合のレスポンス本文のstatus属性の値
4
5
  * 失敗の場合はstring型だが、成功の場合のみnumber型が返却されるので注意すること。
5
6
  */
6
7
  export declare const RESPONSE_BODY_STAUS_SUCCESS = 0;
7
- export type IRequestOptions = Pick<request.OptionsWithUri, 'uri' | 'method' | 'qs' | 'auth' | 'headers' | 'baseUrl' | 'timeout'>;
8
+ export { COAServiceError, IRequestOptions };
9
+ export type IResponseBodyAsJson = {
10
+ /**
11
+ * COAの提示するステータス
12
+ * 0でなければBadRequest
13
+ */
14
+ status?: string | number;
15
+ /**
16
+ * COAの提示するメッセージ
17
+ */
18
+ message?: string;
19
+ } & Record<string, any>;
20
+ export type IResponseBody = IResponseBodyAsJson;
8
21
  /**
9
22
  * transporter abstract class
10
23
  * トランスポーター抽象クラス
11
24
  */
12
25
  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);
24
- }
25
- /**
26
- * DefaultTransporter
27
- */
28
- export declare class DefaultTransporter implements Transporter {
29
- /**
30
- * Default user agent.
31
- */
32
- static readonly USER_AGENT: string;
33
- expectedStatusCodes: number[];
34
- constructor(expectedStatusCodes: number[]);
35
- /**
36
- * Configures request options before making a request.
37
- */
38
- static CONFIGURE(options: IRequestOptions): IRequestOptions & Pick<request.OptionsWithUri, 'json' | 'useQuerystring'>;
39
- /**
40
- * Makes a request with given options and invokes callback.
41
- */
42
- request(options: IRequestOptions): Promise<any>;
43
- /**
44
- * Wraps the response callback.
45
- */
46
- private wrapCallback;
26
+ abstract request(options: IRequestOptions): Promise<IResponseBody>;
47
27
  }
48
28
  /**
49
29
  * FetchTransporter
@@ -62,7 +42,7 @@ export declare class FetchTransporter implements Transporter {
62
42
  /**
63
43
  * Makes a request with given options and invokes callback.
64
44
  */
65
- request(options: IRequestOptions): Promise<any>;
45
+ request(options: IRequestOptions): Promise<IResponseBody>;
66
46
  /**
67
47
  * Wraps the response callback.
68
48
  */
@@ -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.DefaultTransporter = exports.COAServiceError = exports.Transporter = exports.RESPONSE_BODY_STAUS_SUCCESS = void 0;
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,8 @@ 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");
21
+ const coaServiceError_1 = require("./transporter/coaServiceError");
22
+ Object.defineProperty(exports, "COAServiceError", { enumerable: true, get: function () { return coaServiceError_1.COAServiceError; } });
22
23
  const debug = createDebug('coa-service:transporters');
23
24
  // tslint:disable-next-line
24
25
  const pkg = require('../package.json');
@@ -34,123 +35,104 @@ exports.RESPONSE_BODY_STAUS_SUCCESS = 0;
34
35
  class Transporter {
35
36
  }
36
37
  exports.Transporter = Transporter;
37
- /**
38
- * COAServiceError
39
- */
40
- class COAServiceError extends Error {
41
- constructor(code, status, message, requestOptions) {
42
- super(message);
43
- this.name = 'COAServiceError';
44
- this.code = code;
45
- this.status = status;
46
- this.requestOptions = requestOptions;
47
- }
48
- }
49
- exports.COAServiceError = COAServiceError;
50
- /**
51
- * DefaultTransporter
52
- */
53
- class DefaultTransporter {
54
- constructor(expectedStatusCodes) {
55
- this.expectedStatusCodes = expectedStatusCodes;
56
- }
57
- /**
58
- * Configures request options before making a request.
59
- */
60
- static CONFIGURE(options) {
61
- // set transporter user agent
62
- options.headers = (options.headers !== undefined) ? options.headers : {};
63
- // tslint:disable-next-line:no-single-line-block-comment
64
- /* istanbul ignore else */
65
- if (!options.headers['User-Agent']) {
66
- options.headers['User-Agent'] = DefaultTransporter.USER_AGENT;
67
- }
68
- else if (options.headers['User-Agent'].indexOf(DefaultTransporter.USER_AGENT) === -1) {
69
- options.headers['User-Agent'] = `${options.headers['User-Agent']} ${DefaultTransporter.USER_AGENT}`;
70
- }
71
- else {
72
- // no operation
73
- }
74
- return Object.assign(Object.assign({}, options), { json: true, useQuerystring: true });
75
- }
76
- /**
77
- * Makes a request with given options and invokes callback.
78
- */
79
- request(options) {
80
- return __awaiter(this, void 0, void 0, function* () {
81
- const requestOptions = DefaultTransporter.CONFIGURE(options);
82
- debug('requesting...', requestOptions);
83
- return new Promise((resolve, reject) => {
84
- request(requestOptions, (error, response, body) => {
85
- try {
86
- resolve(this.wrapCallback(error, response, body, requestOptions));
87
- }
88
- catch (callbackErr) {
89
- reject(callbackErr);
90
- }
91
- });
92
- });
93
- });
94
- }
95
- /**
96
- * Wraps the response callback.
97
- */
98
- wrapCallback(error, response, body, options) {
99
- const requestOptions = { uri: options.uri };
100
- let err = new COAServiceError(http_status_1.INTERNAL_SERVER_ERROR, '', 'An unexpected error occurred.', requestOptions);
101
- if (error instanceof Error) {
102
- throw new COAServiceError(http_status_1.INTERNAL_SERVER_ERROR, '', error.message, requestOptions);
103
- }
104
- debug('request processed', error, body, response.statusCode);
105
- const statusFromBody = body === null || body === void 0 ? void 0 : body.status;
106
- // tslint:disable-next-line:no-single-line-block-comment
107
- /* istanbul ignore else */
108
- if (response.statusCode !== undefined) {
109
- if (this.expectedStatusCodes.indexOf(response.statusCode) < 0) {
110
- if (typeof body === 'string') {
111
- // Consider all 4xx and 5xx responses errors.
112
- err = new COAServiceError(response.statusCode, '', body, requestOptions);
113
- }
114
- else {
115
- // エラーレスポンスにステータスがあった場合
116
- // tslint:disable-next-line:no-single-line-block-comment
117
- /* istanbul ignore else */
118
- if (statusFromBody !== undefined) {
119
- err = new COAServiceError(response.statusCode, statusFromBody, body.message, requestOptions);
120
- }
121
- else {
122
- // no operation
123
- }
124
- }
125
- }
126
- else {
127
- // HTTPステータスコード2xxでも、レスポンス本文のステータスが0でなければBadRequest
128
- if (statusFromBody !== undefined && statusFromBody !== exports.RESPONSE_BODY_STAUS_SUCCESS) {
129
- err = new COAServiceError(response.statusCode, statusFromBody, body.message, requestOptions);
130
- }
131
- else {
132
- if (response.statusCode === http_status_1.NO_CONTENT) {
133
- // consider 204
134
- return;
135
- }
136
- else {
137
- // consider 200,201
138
- return body;
139
- }
140
- }
141
- }
142
- }
143
- else {
144
- // no operation
145
- }
146
- throw err;
147
- }
148
- }
149
- /**
150
- * Default user agent.
151
- */
152
- DefaultTransporter.USER_AGENT = `coa-service/${pkg.version}`;
153
- 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
+ // }
154
136
  /**
155
137
  * FetchTransporter
156
138
  */
@@ -167,10 +149,10 @@ class FetchTransporter {
167
149
  // tslint:disable-next-line:no-single-line-block-comment
168
150
  /* istanbul ignore else */
169
151
  if (!options.headers['User-Agent']) {
170
- options.headers['User-Agent'] = DefaultTransporter.USER_AGENT;
152
+ options.headers['User-Agent'] = FetchTransporter.USER_AGENT;
171
153
  }
172
- else if (options.headers['User-Agent'].indexOf(DefaultTransporter.USER_AGENT) === -1) {
173
- options.headers['User-Agent'] = `${options.headers['User-Agent']} ${DefaultTransporter.USER_AGENT}`;
154
+ else if (options.headers['User-Agent'].indexOf(FetchTransporter.USER_AGENT) === -1) {
155
+ options.headers['User-Agent'] = `${options.headers['User-Agent']} ${FetchTransporter.USER_AGENT}`;
174
156
  }
175
157
  else {
176
158
  // no operation
@@ -197,7 +179,7 @@ class FetchTransporter {
197
179
  wrapCallback(res, options) {
198
180
  return __awaiter(this, void 0, void 0, function* () {
199
181
  const requestOptions = { uri: options.uri };
200
- let err = new COAServiceError(http_status_1.INTERNAL_SERVER_ERROR, '', 'An unexpected error occurred.', requestOptions);
182
+ let err = new coaServiceError_1.COAServiceError(http_status_1.INTERNAL_SERVER_ERROR, '', 'An unexpected error occurred.', requestOptions);
201
183
  debug('fetch processed. res.status:', res.status, 'content-type:', res.headers.get('content-type'));
202
184
  let body = {};
203
185
  try {
@@ -207,50 +189,44 @@ class FetchTransporter {
207
189
  else {
208
190
  body = yield res.json();
209
191
  }
192
+ debug('fetch processed. body:', body);
210
193
  }
211
194
  catch (error) {
212
195
  // no op
213
196
  }
214
- // tslint:disable-next-line:no-single-line-block-comment
215
- /* istanbul ignore else */
216
- if (res.status !== undefined) {
197
+ if (typeof body === 'string') {
198
+ // Consider all 4xx and 5xx responses errors.
199
+ err = new coaServiceError_1.COAServiceError(res.status, '', body, requestOptions);
200
+ }
201
+ else {
217
202
  if (this.expectedStatusCodes.indexOf(res.status) < 0) {
218
- if (typeof body === 'string') {
219
- // Consider all 4xx and 5xx responses errors.
220
- err = new COAServiceError(res.status, '', body, requestOptions);
203
+ // エラーレスポンスにステータスがあった場合
204
+ // tslint:disable-next-line:no-single-line-block-comment
205
+ /* istanbul ignore else */
206
+ if (body.status !== undefined) {
207
+ err = new coaServiceError_1.COAServiceError(res.status, String(body.status), body.message, requestOptions);
221
208
  }
222
209
  else {
223
- // エラーレスポンスにステータスがあった場合
224
- // tslint:disable-next-line:no-single-line-block-comment
225
- /* istanbul ignore else */
226
- if (body.status !== undefined) {
227
- err = new COAServiceError(res.status, body.status, body.message, requestOptions);
228
- }
229
- else {
230
- // no operation
231
- }
210
+ // no operation
232
211
  }
233
212
  }
234
213
  else {
235
214
  // HTTPステータスコード2xxでも、レスポンス本文のステータスが0でなければBadRequest
236
215
  if (body.status !== undefined && body.status !== exports.RESPONSE_BODY_STAUS_SUCCESS) {
237
- err = new COAServiceError(res.status, body.status, body.message, requestOptions);
216
+ err = new coaServiceError_1.COAServiceError(res.status, String(body.status), body.message, requestOptions);
238
217
  }
239
218
  else {
240
- if (res.status === http_status_1.NO_CONTENT) {
241
- // consider 204
242
- return;
243
- }
244
- else {
245
- // consider 200,201
246
- return body;
247
- }
219
+ // if (res.status === NO_CONTENT) {
220
+ // // consider 204
221
+ // return;
222
+ // } else {
223
+ // // consider 200,201
224
+ // return body;
225
+ // }
226
+ return body;
248
227
  }
249
228
  }
250
229
  }
251
- else {
252
- // no operation
253
- }
254
230
  throw err;
255
231
  });
256
232
  }
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": ">=6.0.0"
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-alpha.3"
79
+ "version": "9.3.0-alpha.5"
84
80
  }