@chevre/domain 21.20.0-alpha.37 → 21.20.0-alpha.39
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/src/chevre/findTransactionById.ts +21 -0
- package/lib/chevre/factory/transaction.d.ts +10 -1
- package/lib/chevre/repo/orderInTransaction.d.ts +3 -0
- package/lib/chevre/repo/orderInTransaction.js +9 -0
- package/lib/chevre/service/notification.js +69 -61
- package/lib/chevre/service/offer/event/voidTransaction.js +12 -4
- package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.d.ts +2 -2
- package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.js +17 -20
- package/lib/chevre/service/transaction/placeOrder.js +2 -1
- package/lib/chevre/service/transaction/placeOrderInProgress/confirm.js +6 -1
- package/lib/chevre/service/transaction/placeOrderInProgress/validation.d.ts +8 -23
- package/lib/chevre/service/transaction/placeOrderInProgress/validation.js +15 -1
- package/lib/chevre/service/transaction/returnOrder/preStart.js +70 -43
- package/package.json +1 -4
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
|
|
4
|
+
import { chevre } from '../../../lib/index';
|
|
5
|
+
|
|
6
|
+
async function main() {
|
|
7
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
8
|
+
|
|
9
|
+
const transactionRepo = await chevre.repository.Transaction.createInstance(mongoose.connection);
|
|
10
|
+
|
|
11
|
+
const transaction = await transactionRepo.findById({
|
|
12
|
+
typeOf: chevre.factory.transactionType.PlaceOrder,
|
|
13
|
+
id: '65ab04d5206595479469f50c',
|
|
14
|
+
inclusion: ['endDate', 'id', 'object', 'project', 'seller', 'startDate', 'status', 'typeOf']
|
|
15
|
+
});
|
|
16
|
+
console.log('transaction:', transaction);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
main()
|
|
20
|
+
.then(console.log)
|
|
21
|
+
.catch(console.error);
|
|
@@ -18,17 +18,26 @@ export declare namespace placeOrder {
|
|
|
18
18
|
* 注文日時
|
|
19
19
|
*/
|
|
20
20
|
orderDate: Date;
|
|
21
|
+
/**
|
|
22
|
+
* 確認番号のカスタム指定
|
|
23
|
+
*/
|
|
21
24
|
/**
|
|
22
25
|
* 注文確認URLのカスタム指定
|
|
23
26
|
*/
|
|
24
27
|
url?: string | IOrderURLGenerator;
|
|
25
28
|
/**
|
|
26
|
-
*
|
|
29
|
+
* オファー制約
|
|
27
30
|
*/
|
|
28
31
|
numItems?: {
|
|
29
32
|
maxValue?: number;
|
|
30
33
|
minValue?: number;
|
|
31
34
|
};
|
|
35
|
+
/**
|
|
36
|
+
* 注文アイテム制約
|
|
37
|
+
*/
|
|
38
|
+
orderedItem: {
|
|
39
|
+
maxValue: number;
|
|
40
|
+
};
|
|
32
41
|
};
|
|
33
42
|
type IConfirmParams = factory.transaction.placeOrder.IConfirmParams & {
|
|
34
43
|
project: {
|
|
@@ -107,5 +107,14 @@ class MongoRepository {
|
|
|
107
107
|
.exec();
|
|
108
108
|
});
|
|
109
109
|
}
|
|
110
|
+
deleteByOrderNumber(params) {
|
|
111
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
112
|
+
return this.orderModel.deleteOne({
|
|
113
|
+
typeOf: { $eq: factory.transactionType.PlaceOrder },
|
|
114
|
+
orderNumber: { $eq: params.orderNumber }
|
|
115
|
+
})
|
|
116
|
+
.exec();
|
|
117
|
+
});
|
|
118
|
+
}
|
|
110
119
|
}
|
|
111
120
|
exports.MongoRepository = MongoRepository;
|
|
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.triggerWebhook = exports.report2developers = exports.sendEmailMessage = void 0;
|
|
13
13
|
const sgMail = require("@sendgrid/mail");
|
|
14
14
|
const http_status_1 = require("http-status");
|
|
15
|
-
|
|
15
|
+
// import * as request from 'request';
|
|
16
16
|
const util = require("util");
|
|
17
17
|
const credentials_1 = require("../credentials");
|
|
18
18
|
const settings_1 = require("../settings");
|
|
@@ -179,31 +179,37 @@ ${content}`;
|
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
181
|
else {
|
|
182
|
+
throw new factory.errors.NotImplemented('only useFetchAPI implemented');
|
|
182
183
|
// LINE通知APIにPOST
|
|
183
|
-
const formData
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
184
|
+
// const formData: any = {
|
|
185
|
+
// message: message,
|
|
186
|
+
// ...(typeof imageThumbnail === 'string') ? { imageThumbnail } : undefined,
|
|
187
|
+
// ...(typeof imageFullsize === 'string') ? { imageFullsize } : undefined
|
|
188
|
+
// };
|
|
189
|
+
// return new Promise<void>((resolve, reject) => {
|
|
190
|
+
// request.post(
|
|
191
|
+
// {
|
|
192
|
+
// url: LINE_NOTIFY_URL,
|
|
193
|
+
// auth: { bearer: repos.accessToken },
|
|
194
|
+
// form: formData,
|
|
195
|
+
// json: true,
|
|
196
|
+
// timeout: settings.webhook?.timeout
|
|
197
|
+
// },
|
|
198
|
+
// (error, response, body) => {
|
|
199
|
+
// if (error !== null) {
|
|
200
|
+
// reject(error);
|
|
201
|
+
// } else {
|
|
202
|
+
// switch (response.statusCode) {
|
|
203
|
+
// case OK:
|
|
204
|
+
// resolve();
|
|
205
|
+
// break;
|
|
206
|
+
// default:
|
|
207
|
+
// reject(new Error(body.message));
|
|
208
|
+
// }
|
|
209
|
+
// }
|
|
210
|
+
// }
|
|
211
|
+
// );
|
|
212
|
+
// });
|
|
207
213
|
}
|
|
208
214
|
});
|
|
209
215
|
}
|
|
@@ -292,57 +298,59 @@ function processInformAction(params) {
|
|
|
292
298
|
catch (err) {
|
|
293
299
|
if (err.name === 'TimeoutError') {
|
|
294
300
|
// tslint:disable-next-line:no-console
|
|
295
|
-
console.error('
|
|
301
|
+
console.error('processInformAction: Timeout: It took more than 5 seconds to get the result!', err);
|
|
296
302
|
}
|
|
297
303
|
else if (err.name === 'AbortError') {
|
|
298
304
|
// tslint:disable-next-line:no-console
|
|
299
|
-
console.error('
|
|
305
|
+
console.error('processInformAction: Fetch aborted by user action (browser stop button, closing tab, etc.', err);
|
|
300
306
|
}
|
|
301
307
|
else if (err.name === 'TypeError') {
|
|
302
308
|
// tslint:disable-next-line:no-console
|
|
303
|
-
console.error('
|
|
309
|
+
console.error('processInformAction: AbortSignal.timeout() method is not supported', err);
|
|
304
310
|
}
|
|
305
311
|
else {
|
|
306
312
|
// A network error, or some other problem.
|
|
307
313
|
// tslint:disable-next-line:no-console
|
|
308
|
-
console.error(`
|
|
314
|
+
console.error(`processInformAction: Error: type: ${err.name}, message: ${err.message}`, err);
|
|
309
315
|
}
|
|
310
316
|
throw err;
|
|
311
317
|
}
|
|
312
318
|
}
|
|
313
319
|
else {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
}
|
|
320
|
+
throw new factory.errors.NotImplemented('only useFetchAPI implemented');
|
|
321
|
+
// await new Promise<void>((resolve, reject) => {
|
|
322
|
+
// request.post(
|
|
323
|
+
// {
|
|
324
|
+
// url: url,
|
|
325
|
+
// body: {
|
|
326
|
+
// data: params.object
|
|
327
|
+
// },
|
|
328
|
+
// json: true,
|
|
329
|
+
// timeout: settings.webhook?.timeout
|
|
330
|
+
// },
|
|
331
|
+
// (error, response, body) => {
|
|
332
|
+
// if (error instanceof Error) {
|
|
333
|
+
// reject(error);
|
|
334
|
+
// } else {
|
|
335
|
+
// switch (response.statusCode) {
|
|
336
|
+
// case OK:
|
|
337
|
+
// case CREATED:
|
|
338
|
+
// case ACCEPTED:
|
|
339
|
+
// case NO_CONTENT:
|
|
340
|
+
// result = {
|
|
341
|
+
// statusCode: response.statusCode,
|
|
342
|
+
// useFetchAPI: repos.useFetchAPI
|
|
343
|
+
// // body: body
|
|
344
|
+
// };
|
|
345
|
+
// resolve();
|
|
346
|
+
// break;
|
|
347
|
+
// default:
|
|
348
|
+
// reject(new Error(`statusCode: ${response.statusCode} body: ${body}`));
|
|
349
|
+
// }
|
|
350
|
+
// }
|
|
351
|
+
// }
|
|
352
|
+
// );
|
|
353
|
+
// });
|
|
346
354
|
}
|
|
347
355
|
}
|
|
348
356
|
}
|
|
@@ -61,10 +61,18 @@ function voidTransaction(params) {
|
|
|
61
61
|
// USE_CREATE_ORDER_ON_OFFER_ACCEPTEDの場合、orderNumber発行済のはず
|
|
62
62
|
const orderNumberByTransaction = transaction.object.orderNumber;
|
|
63
63
|
if (typeof orderNumberByTransaction === 'string') {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
switch (transaction.status) {
|
|
65
|
+
case factory.transactionStatusType.Confirmed:
|
|
66
|
+
// 確定取引の場合、不要なオファーのみ除外
|
|
67
|
+
yield (0, any_1.voidAcceptedOffer)({
|
|
68
|
+
authorizeActions,
|
|
69
|
+
orderNumber: orderNumberByTransaction
|
|
70
|
+
})(repos);
|
|
71
|
+
break;
|
|
72
|
+
default:
|
|
73
|
+
// orderInTransaction自体を削除
|
|
74
|
+
yield repos.orderInTransaction.deleteByOrderNumber({ orderNumber: orderNumberByTransaction });
|
|
75
|
+
}
|
|
68
76
|
}
|
|
69
77
|
yield Promise.all(authorizeActions.map((action) => __awaiter(this, void 0, void 0, function* () {
|
|
70
78
|
yield repos.action.cancelWithVoid({ typeOf: action.typeOf, id: action.id });
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as factory from '../../../../factory';
|
|
2
|
-
export type IPlaceOrderTransactionAsInformObject = Pick<factory.transaction.ITransaction<factory.transactionType.PlaceOrder>, 'id' | 'typeOf' | '
|
|
2
|
+
export type IPlaceOrderTransactionAsInformObject = Pick<factory.transaction.ITransaction<factory.transactionType.PlaceOrder>, 'id' | 'typeOf' | 'endDate' | 'project' | 'seller' | 'startDate' | 'status'>;
|
|
3
3
|
/**
|
|
4
4
|
* 取引のタスクを作成する
|
|
5
5
|
*/
|
|
6
6
|
export declare function createTasks(params: {
|
|
7
|
-
transaction: factory.transaction.ITransaction<factory.transactionType.PlaceOrder>;
|
|
7
|
+
transaction: Pick<factory.transaction.ITransaction<factory.transactionType.PlaceOrder>, 'endDate' | 'id' | 'object' | 'project' | 'seller' | 'startDate' | 'status' | 'typeOf'>;
|
|
8
8
|
runsAt: Date;
|
|
9
9
|
}): factory.task.IAttributes<factory.taskName>[];
|
|
@@ -9,7 +9,6 @@ const settings_1 = require("../../../../settings");
|
|
|
9
9
|
*/
|
|
10
10
|
// tslint:disable-next-line:max-func-body-length
|
|
11
11
|
function createTasks(params) {
|
|
12
|
-
var _a;
|
|
13
12
|
const taskAttributes = [];
|
|
14
13
|
const transaction = params.transaction;
|
|
15
14
|
const taskRunsAt = params.runsAt;
|
|
@@ -18,12 +17,9 @@ function createTasks(params) {
|
|
|
18
17
|
const informObject = {
|
|
19
18
|
id: transaction.id,
|
|
20
19
|
typeOf: transaction.typeOf,
|
|
21
|
-
agent: transaction.agent,
|
|
22
20
|
endDate: transaction.endDate,
|
|
23
|
-
expires: transaction.expires,
|
|
24
21
|
project: transaction.project,
|
|
25
22
|
seller: transaction.seller,
|
|
26
|
-
result: transaction.result,
|
|
27
23
|
startDate: transaction.startDate,
|
|
28
24
|
status: transaction.status
|
|
29
25
|
};
|
|
@@ -121,25 +117,26 @@ function createTasks(params) {
|
|
|
121
117
|
taskAttributes.push(...triggerWebhookTaskAttributes, deleteTransactionTask, voidPaymentTaskAttributes, voidReserveTaskAttributes);
|
|
122
118
|
switch (transaction.status) {
|
|
123
119
|
case factory.transactionStatusType.Confirmed:
|
|
124
|
-
const potentialActions = transaction.potentialActions;
|
|
125
|
-
if (potentialActions === undefined) {
|
|
126
|
-
|
|
120
|
+
// const potentialActions = transaction.potentialActions;
|
|
121
|
+
// if (potentialActions === undefined) {
|
|
122
|
+
// throw new factory.errors.NotFound('Transaction PotentialActions');
|
|
123
|
+
// }
|
|
124
|
+
// const orderFromTransaction = transaction.result?.order;
|
|
125
|
+
// if (orderFromTransaction === undefined) {
|
|
126
|
+
// throw new factory.errors.NotFound('Transaction Result');
|
|
127
|
+
// }
|
|
128
|
+
const confirmationNumber = transaction.object.confirmationNumber;
|
|
129
|
+
if (typeof confirmationNumber !== 'string' || confirmationNumber.length === 0) {
|
|
130
|
+
throw new factory.errors.NotFound('transaction.object.confirmationNumber');
|
|
127
131
|
}
|
|
128
|
-
const
|
|
129
|
-
if (
|
|
130
|
-
throw new factory.errors.NotFound('
|
|
132
|
+
const orderNumber = transaction.object.orderNumber;
|
|
133
|
+
if (typeof orderNumber !== 'string' || orderNumber.length === 0) {
|
|
134
|
+
throw new factory.errors.NotFound('transaction.object.orderNumber');
|
|
131
135
|
}
|
|
132
|
-
const orderActionAttributes = potentialActions.order;
|
|
136
|
+
// const orderActionAttributes = potentialActions.order;
|
|
133
137
|
const placeOrderTaskData = {
|
|
134
|
-
project:
|
|
135
|
-
object: {
|
|
136
|
-
confirmationNumber: orderFromTransaction.confirmationNumber,
|
|
137
|
-
orderNumber: orderActionAttributes.object.orderNumber
|
|
138
|
-
}
|
|
139
|
-
// 廃止(2023-08-21~)
|
|
140
|
-
// ...(orderActionAttributes.potentialActions !== undefined)
|
|
141
|
-
// ? { potentialActions: orderActionAttributes.potentialActions }
|
|
142
|
-
// : undefined
|
|
138
|
+
project: transaction.project,
|
|
139
|
+
object: { confirmationNumber, orderNumber }
|
|
143
140
|
};
|
|
144
141
|
const placeOrderTaskAttributes = {
|
|
145
142
|
project: transaction.project,
|
|
@@ -23,7 +23,8 @@ function exportTasksById(params) {
|
|
|
23
23
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
24
24
|
const transaction = yield repos.transaction.findById({
|
|
25
25
|
typeOf: factory.transactionType.PlaceOrder,
|
|
26
|
-
id: params.id
|
|
26
|
+
id: params.id,
|
|
27
|
+
inclusion: ['endDate', 'id', 'object', 'project', 'seller', 'startDate', 'status', 'typeOf']
|
|
27
28
|
});
|
|
28
29
|
// タスク実行日時バッファの指定があれば調整
|
|
29
30
|
let taskRunsAt = new Date();
|
|
@@ -120,11 +120,16 @@ function createResult(params) {
|
|
|
120
120
|
order: order,
|
|
121
121
|
authorizeActions: params.authorizeActions
|
|
122
122
|
});
|
|
123
|
-
//
|
|
123
|
+
// 注文オファー検証
|
|
124
124
|
(0, validation_1.validateNumItems)({
|
|
125
125
|
order: order,
|
|
126
126
|
result: params.result
|
|
127
127
|
});
|
|
128
|
+
// 注文アイテム検証(2024-01-20~)
|
|
129
|
+
(0, validation_1.validateOrderedItem)({
|
|
130
|
+
order: order,
|
|
131
|
+
result: params.result
|
|
132
|
+
});
|
|
128
133
|
(0, validation_1.validatePaymentMethods)({ order });
|
|
129
134
|
// 確認番号を発行
|
|
130
135
|
const { confirmationNumber, identifier, url } = createConfirmationNumber({
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as factory from '../../../factory';
|
|
2
|
+
import { placeOrder as PlaceOrderFactory } from '../../../factory/transaction';
|
|
2
3
|
export type IAuthorizeAnyPaymentResult = factory.action.authorize.paymentMethod.any.IResult;
|
|
3
4
|
export type IAuthorizeSeatReservationOffer = factory.action.authorize.offer.eventService.IAction<factory.service.webAPI.Identifier>;
|
|
4
5
|
export type IAuthorizeSeatReservationOfferResult = factory.action.authorize.offer.eventService.IResult<factory.service.webAPI.Identifier>;
|
|
@@ -8,33 +9,17 @@ export type IUnitPriceSpecification = factory.priceSpecification.IPriceSpecifica
|
|
|
8
9
|
* 取引が確定可能な状態かどうかをチェックする
|
|
9
10
|
*/
|
|
10
11
|
export declare function validateTransaction(transaction: factory.transaction.placeOrder.ITransaction, authorizeActions: factory.action.authorize.IAction<factory.action.authorize.IAttributes<any, any>>[]): void;
|
|
11
|
-
export type IConfirmationNumberGenerator = (order: factory.order.IOrder) => string;
|
|
12
12
|
export type IOrderURLGenerator = (order: factory.order.IOrder) => string;
|
|
13
|
-
export type IResultOrderParams = factory.transaction.placeOrder.IResultOrderParams & {
|
|
14
|
-
/**
|
|
15
|
-
* 注文日時
|
|
16
|
-
*/
|
|
17
|
-
orderDate: Date;
|
|
18
|
-
/**
|
|
19
|
-
* 確認番号のカスタム指定
|
|
20
|
-
*/
|
|
21
|
-
confirmationNumber?: string | IConfirmationNumberGenerator;
|
|
22
|
-
/**
|
|
23
|
-
* 注文確認URLのカスタム指定
|
|
24
|
-
*/
|
|
25
|
-
url?: string | IOrderURLGenerator;
|
|
26
|
-
/**
|
|
27
|
-
* 注文アイテム数
|
|
28
|
-
*/
|
|
29
|
-
numItems?: {
|
|
30
|
-
maxValue?: number;
|
|
31
|
-
minValue?: number;
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
13
|
export declare function validateNumItems(params: {
|
|
35
14
|
order: factory.transaction.placeOrder.IOrderAsResult;
|
|
36
15
|
result: {
|
|
37
|
-
order: IResultOrderParams;
|
|
16
|
+
order: PlaceOrderFactory.IResultOrderParams;
|
|
17
|
+
};
|
|
18
|
+
}): void;
|
|
19
|
+
export declare function validateOrderedItem(params: {
|
|
20
|
+
order: factory.transaction.placeOrder.IOrderAsResult;
|
|
21
|
+
result: {
|
|
22
|
+
order: PlaceOrderFactory.IResultOrderParams;
|
|
38
23
|
};
|
|
39
24
|
}): void;
|
|
40
25
|
export declare function validatePaymentMethods(params: {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateEventOffers = exports.validatePaymentMethods = exports.validateNumItems = exports.validateTransaction = void 0;
|
|
3
|
+
exports.validateEventOffers = exports.validatePaymentMethods = exports.validateOrderedItem = exports.validateNumItems = exports.validateTransaction = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* 注文取引バリデーション
|
|
6
6
|
*/
|
|
@@ -237,6 +237,20 @@ function validateNumItems(params) {
|
|
|
237
237
|
}
|
|
238
238
|
}
|
|
239
239
|
exports.validateNumItems = validateNumItems;
|
|
240
|
+
function validateOrderedItem(params) {
|
|
241
|
+
var _a, _b;
|
|
242
|
+
if (!Array.isArray(params.order.orderedItem)) {
|
|
243
|
+
throw new factory.errors.Argument('order.orderedItem', 'must be array');
|
|
244
|
+
}
|
|
245
|
+
// 注文アイテム数制限確認
|
|
246
|
+
const numOrderedItemMaxValue = (_b = (_a = params.result.order) === null || _a === void 0 ? void 0 : _a.orderedItem) === null || _b === void 0 ? void 0 : _b.maxValue;
|
|
247
|
+
if (typeof numOrderedItemMaxValue === 'number') {
|
|
248
|
+
if (params.order.orderedItem.length > numOrderedItemMaxValue) {
|
|
249
|
+
throw new factory.errors.Argument('Transaction', (0, util_1.format)('Number of orderedItem must be less than or equal to %s', numOrderedItemMaxValue));
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
exports.validateOrderedItem = validateOrderedItem;
|
|
240
254
|
function validatePaymentMethods(params) {
|
|
241
255
|
if (typeof settings_1.MAX_NUM_CREDIT_CARD_PAYMENT_METHOD === 'number') {
|
|
242
256
|
// CreditCard IFの決済方法の最大値検証
|
|
@@ -24,7 +24,7 @@ exports.preStart = void 0;
|
|
|
24
24
|
const createDebug = require("debug");
|
|
25
25
|
const http_status_1 = require("http-status");
|
|
26
26
|
const moment = require("moment-timezone");
|
|
27
|
-
|
|
27
|
+
// import * as request from 'request';
|
|
28
28
|
const factory = require("../../../factory");
|
|
29
29
|
const debug = createDebug('chevre-domain:service');
|
|
30
30
|
/**
|
|
@@ -287,53 +287,80 @@ function createOrder4returnPolicy(params) {
|
|
|
287
287
|
};
|
|
288
288
|
}
|
|
289
289
|
const TIMEOUT = 5000;
|
|
290
|
+
// tslint:disable-next-line:max-func-body-length
|
|
290
291
|
function getReturnPolicyByProject(params) {
|
|
292
|
+
var _a;
|
|
291
293
|
return __awaiter(this, void 0, void 0, function* () {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
294
|
+
// implement with fetch(2024-01-20~)
|
|
295
|
+
try {
|
|
296
|
+
const res = yield fetch(params.sameAs, {
|
|
297
|
+
method: 'POST',
|
|
298
|
+
headers: {
|
|
299
|
+
'Content-Type': 'application/json'
|
|
297
300
|
},
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
301
|
+
body: JSON.stringify({
|
|
302
|
+
order: createOrder4returnPolicy({ order: params.order })
|
|
303
|
+
}),
|
|
304
|
+
// body data type must match "Content-Type" header
|
|
305
|
+
signal: AbortSignal.timeout(TIMEOUT)
|
|
306
|
+
});
|
|
307
|
+
let body;
|
|
308
|
+
try {
|
|
309
|
+
body = yield res.json();
|
|
310
|
+
}
|
|
311
|
+
catch (error) {
|
|
312
|
+
// no op
|
|
313
|
+
}
|
|
314
|
+
let returnPolicy;
|
|
315
|
+
switch (res.status) {
|
|
316
|
+
case http_status_1.OK:
|
|
317
|
+
case http_status_1.CREATED:
|
|
318
|
+
case http_status_1.ACCEPTED:
|
|
319
|
+
case http_status_1.NO_CONTENT:
|
|
320
|
+
if (typeof ((_a = body === null || body === void 0 ? void 0 : body.restockingFee) === null || _a === void 0 ? void 0 : _a.value) !== 'number') {
|
|
321
|
+
throw new Error('invalid return policy');
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
324
|
+
returnPolicy = {
|
|
325
|
+
typeOf: 'MerchantReturnPolicy',
|
|
326
|
+
restockingFee: {
|
|
327
|
+
currency: factory.priceCurrency.JPY,
|
|
328
|
+
typeOf: 'MonetaryAmount',
|
|
329
|
+
value: body.restockingFee.value
|
|
323
330
|
}
|
|
324
|
-
|
|
325
|
-
case http_status_1.NOT_FOUND:
|
|
326
|
-
reject(new factory.errors.Argument('Seller', 'has no applicable return policies'));
|
|
327
|
-
break;
|
|
328
|
-
default:
|
|
329
|
-
reject({
|
|
330
|
-
statusCode: response.statusCode,
|
|
331
|
-
body: body
|
|
332
|
-
});
|
|
331
|
+
};
|
|
333
332
|
}
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
333
|
+
break;
|
|
334
|
+
case http_status_1.NOT_FOUND:
|
|
335
|
+
throw new factory.errors.Argument('Seller', 'has no applicable return policies');
|
|
336
|
+
// break;
|
|
337
|
+
default:
|
|
338
|
+
// tslint:disable-next-line:no-console
|
|
339
|
+
console.error('custom return policy temporarily unavailable.', res.status, body);
|
|
340
|
+
throw new factory.errors.ServiceUnavailable(`custom return policy temporarily unavailable. statusCode: ${res.status} body: ${body}`);
|
|
341
|
+
}
|
|
342
|
+
return returnPolicy;
|
|
343
|
+
}
|
|
344
|
+
catch (err) {
|
|
345
|
+
if (err.name === 'TimeoutError') {
|
|
346
|
+
// tslint:disable-next-line:no-console
|
|
347
|
+
console.error('getReturnPolicyByProject: Timeout: It took more than 5 seconds to get the result!', err);
|
|
348
|
+
}
|
|
349
|
+
else if (err.name === 'AbortError') {
|
|
350
|
+
// tslint:disable-next-line:no-console
|
|
351
|
+
console.error('getReturnPolicyByProject: Fetch aborted by user action (browser stop button, closing tab, etc.', err);
|
|
352
|
+
}
|
|
353
|
+
else if (err.name === 'TypeError') {
|
|
354
|
+
// tslint:disable-next-line:no-console
|
|
355
|
+
console.error('getReturnPolicyByProject: AbortSignal.timeout() method is not supported', err);
|
|
356
|
+
}
|
|
357
|
+
else {
|
|
358
|
+
// A network error, or some other problem.
|
|
359
|
+
// tslint:disable-next-line:no-console
|
|
360
|
+
console.error(`getReturnPolicyByProject: Error: type: ${err.name}, message: ${err.message}`, err);
|
|
361
|
+
}
|
|
362
|
+
throw err;
|
|
363
|
+
}
|
|
337
364
|
});
|
|
338
365
|
}
|
|
339
366
|
/**
|
package/package.json
CHANGED
|
@@ -28,7 +28,6 @@
|
|
|
28
28
|
"moment-timezone": "^0.5.33",
|
|
29
29
|
"node-fpe": "1.0.0",
|
|
30
30
|
"pug": "^2.0.4",
|
|
31
|
-
"request": "^2.88.2",
|
|
32
31
|
"uniqid": "^5.4.0",
|
|
33
32
|
"uuid": "^3.4.0"
|
|
34
33
|
},
|
|
@@ -46,8 +45,6 @@
|
|
|
46
45
|
"@types/node": "18.19.2",
|
|
47
46
|
"@types/power-assert": "^1.5.3",
|
|
48
47
|
"@types/pug": "^2.0.4",
|
|
49
|
-
"@types/request": "^2.48.5",
|
|
50
|
-
"@types/request-promise-native": "^1.0.18",
|
|
51
48
|
"@types/sinon": "^4.3.3",
|
|
52
49
|
"@types/sinon-mongoose": "^1.3.11",
|
|
53
50
|
"@types/uniqid": "^4.1.3",
|
|
@@ -115,5 +112,5 @@
|
|
|
115
112
|
"postversion": "git push origin --tags",
|
|
116
113
|
"prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
|
|
117
114
|
},
|
|
118
|
-
"version": "21.20.0-alpha.
|
|
115
|
+
"version": "21.20.0-alpha.39"
|
|
119
116
|
}
|