@chevre/domain 21.2.0-alpha.26 → 21.2.0-alpha.28
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/chevre/eventEmitter/assetTransaction.d.ts +21 -0
- package/lib/chevre/eventEmitter/assetTransaction.js +28 -0
- package/lib/chevre/eventEmitter.d.ts +2 -1
- package/lib/chevre/eventEmitter.js +3 -1
- package/lib/chevre/repo/assetTransaction.d.ts +5 -0
- package/lib/chevre/repo/assetTransaction.js +65 -5
- package/lib/chevre/repo/mongoose/schemas/assetTransaction.d.ts +3 -0
- package/lib/chevre/repo/mongoose/schemas/assetTransaction.js +1 -0
- package/lib/chevre/service/assetTransaction.d.ts +6 -0
- package/lib/chevre/service/assetTransaction.js +9 -4
- package/lib/chevre/service/transaction.js +2 -2
- package/lib/chevre/settings.d.ts +1 -0
- package/lib/chevre/settings.js +2 -1
- package/package.json +1 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
3
|
+
import * as factory from '../factory';
|
|
4
|
+
interface IListenArgsOnAssetTransactionStatusChanged {
|
|
5
|
+
/**
|
|
6
|
+
* 取引ID
|
|
7
|
+
*/
|
|
8
|
+
id: string;
|
|
9
|
+
typeOf: factory.assetTransactionType;
|
|
10
|
+
status: factory.transactionStatusType;
|
|
11
|
+
}
|
|
12
|
+
type IOnAssetTransactionStatusChangedListener = (listenArgs: IListenArgsOnAssetTransactionStatusChanged) => void;
|
|
13
|
+
/**
|
|
14
|
+
* 資産取引イベントエミッター
|
|
15
|
+
*/
|
|
16
|
+
declare class AssetTransactionEventEmitter extends EventEmitter {
|
|
17
|
+
onAssetTransactionStatusChanged(listner: IOnAssetTransactionStatusChangedListener): void;
|
|
18
|
+
emitAssetTransactionStatusChanged(args: IListenArgsOnAssetTransactionStatusChanged): void;
|
|
19
|
+
}
|
|
20
|
+
declare const assetTransactionEventEmitter: AssetTransactionEventEmitter;
|
|
21
|
+
export { IListenArgsOnAssetTransactionStatusChanged, assetTransactionEventEmitter };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assetTransactionEventEmitter = void 0;
|
|
4
|
+
const events_1 = require("events");
|
|
5
|
+
const settings_1 = require("../settings");
|
|
6
|
+
var EventName;
|
|
7
|
+
(function (EventName) {
|
|
8
|
+
EventName["OnAssetTransactionStatusChanged"] = "OnAssetTransactionStatusChanged";
|
|
9
|
+
})(EventName || (EventName = {}));
|
|
10
|
+
/**
|
|
11
|
+
* 資産取引イベントエミッター
|
|
12
|
+
*/
|
|
13
|
+
class AssetTransactionEventEmitter extends events_1.EventEmitter {
|
|
14
|
+
onAssetTransactionStatusChanged(listner) {
|
|
15
|
+
this.on(EventName.OnAssetTransactionStatusChanged, listner);
|
|
16
|
+
}
|
|
17
|
+
emitAssetTransactionStatusChanged(args) {
|
|
18
|
+
if (settings_1.USE_EVENT_EMITTERS) {
|
|
19
|
+
this.emit(EventName.OnAssetTransactionStatusChanged, args);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const assetTransactionEventEmitter = new AssetTransactionEventEmitter();
|
|
24
|
+
exports.assetTransactionEventEmitter = assetTransactionEventEmitter;
|
|
25
|
+
assetTransactionEventEmitter.on('error', (err) => {
|
|
26
|
+
// tslint:disable-next-line:no-console
|
|
27
|
+
console.error('assetTransactionEventEmitter listened an error.', err);
|
|
28
|
+
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { assetTransactionEventEmitter } from './eventEmitter/assetTransaction';
|
|
1
2
|
import { taskEventEmitter } from './eventEmitter/task';
|
|
2
3
|
import { transactionEventEmitter } from './eventEmitter/transaction';
|
|
3
|
-
export { taskEventEmitter as task, transactionEventEmitter as transaction };
|
|
4
|
+
export { assetTransactionEventEmitter as assetTransaction, taskEventEmitter as task, transactionEventEmitter as transaction };
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.transaction = exports.task = void 0;
|
|
3
|
+
exports.transaction = exports.task = exports.assetTransaction = void 0;
|
|
4
|
+
const assetTransaction_1 = require("./eventEmitter/assetTransaction");
|
|
5
|
+
Object.defineProperty(exports, "assetTransaction", { enumerable: true, get: function () { return assetTransaction_1.assetTransactionEventEmitter; } });
|
|
4
6
|
const task_1 = require("./eventEmitter/task");
|
|
5
7
|
Object.defineProperty(exports, "task", { enumerable: true, get: function () { return task_1.taskEventEmitter; } });
|
|
6
8
|
const transaction_1 = require("./eventEmitter/transaction");
|
|
@@ -98,6 +98,11 @@ export declare class MongoRepository {
|
|
|
98
98
|
};
|
|
99
99
|
status: factory.transactionStatusType;
|
|
100
100
|
id?: string;
|
|
101
|
+
tasksExportAction: {
|
|
102
|
+
agent: {
|
|
103
|
+
name: string;
|
|
104
|
+
};
|
|
105
|
+
};
|
|
101
106
|
}): Promise<Pick<factory.assetTransaction.ITransaction<T>, 'id' | 'typeOf'> | null>;
|
|
102
107
|
/**
|
|
103
108
|
* タスクエクスポートリトライ
|
|
@@ -13,6 +13,7 @@ exports.MongoRepository = void 0;
|
|
|
13
13
|
const moment = require("moment");
|
|
14
14
|
const assetTransaction_1 = require("./mongoose/schemas/assetTransaction");
|
|
15
15
|
const factory = require("../factory");
|
|
16
|
+
const assetTransaction_2 = require("../eventEmitter/assetTransaction");
|
|
16
17
|
/**
|
|
17
18
|
* 資産取引リポジトリ
|
|
18
19
|
*/
|
|
@@ -336,6 +337,11 @@ class MongoRepository {
|
|
|
336
337
|
throw new factory.errors.NotFound(this.transactionModel.modelName);
|
|
337
338
|
}
|
|
338
339
|
}
|
|
340
|
+
assetTransaction_2.assetTransactionEventEmitter.emitAssetTransactionStatusChanged({
|
|
341
|
+
id: params.id,
|
|
342
|
+
typeOf: params.typeOf,
|
|
343
|
+
status: factory.transactionStatusType.Confirmed
|
|
344
|
+
});
|
|
339
345
|
});
|
|
340
346
|
}
|
|
341
347
|
/**
|
|
@@ -360,7 +366,13 @@ class MongoRepository {
|
|
|
360
366
|
// no op
|
|
361
367
|
}
|
|
362
368
|
const typeOfIn = (_a = params.typeOf) === null || _a === void 0 ? void 0 : _a.$in;
|
|
363
|
-
return this.transactionModel.findOneAndUpdate(Object.assign(Object.assign(Object.assign(Object.assign({}, (typeof ((_b = params.project) === null || _b === void 0 ? void 0 : _b.id) === 'string') ? { 'project.id': { $eq: params.project.id } } : undefined), (Array.isArray(typeOfIn)) ? { typeOf: { $in: typeOfIn } } : undefined), { status: { $eq: params.status }, tasksExportationStatus: { $eq: factory.transactionTasksExportationStatus.Unexported } }), (typeof params.id === 'string') ? { _id: { $eq: params.id } } : undefined), {
|
|
369
|
+
return this.transactionModel.findOneAndUpdate(Object.assign(Object.assign(Object.assign(Object.assign({}, (typeof ((_b = params.project) === null || _b === void 0 ? void 0 : _b.id) === 'string') ? { 'project.id': { $eq: params.project.id } } : undefined), (Array.isArray(typeOfIn)) ? { typeOf: { $in: typeOfIn } } : undefined), { status: { $eq: params.status }, tasksExportationStatus: { $eq: factory.transactionTasksExportationStatus.Unexported } }), (typeof params.id === 'string') ? { _id: { $eq: params.id } } : undefined), {
|
|
370
|
+
tasksExportAction: {
|
|
371
|
+
agent: { name: params.tasksExportAction.agent.name },
|
|
372
|
+
startDate: new Date()
|
|
373
|
+
},
|
|
374
|
+
tasksExportationStatus: factory.transactionTasksExportationStatus.Exporting
|
|
375
|
+
}, { new: true })
|
|
364
376
|
.select({
|
|
365
377
|
_id: 1,
|
|
366
378
|
typeOf: 1
|
|
@@ -377,17 +389,51 @@ class MongoRepository {
|
|
|
377
389
|
*/
|
|
378
390
|
reexportTasks(params) {
|
|
379
391
|
return __awaiter(this, void 0, void 0, function* () {
|
|
380
|
-
yield this.transactionModel.
|
|
392
|
+
const reexportingTransactions = yield this.transactionModel.find({
|
|
381
393
|
tasksExportationStatus: { $eq: factory.transactionTasksExportationStatus.Exporting },
|
|
382
394
|
updatedAt: {
|
|
383
395
|
$lt: moment()
|
|
384
396
|
.add(-params.intervalInMinutes, 'minutes')
|
|
385
397
|
.toDate()
|
|
386
398
|
}
|
|
387
|
-
}, {
|
|
388
|
-
tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported
|
|
389
399
|
})
|
|
400
|
+
.select({
|
|
401
|
+
_id: 1,
|
|
402
|
+
typeOf: 1,
|
|
403
|
+
status: 1
|
|
404
|
+
})
|
|
405
|
+
.setOptions({ maxTimeMS: 10000 })
|
|
390
406
|
.exec();
|
|
407
|
+
if (reexportingTransactions.length > 0) {
|
|
408
|
+
for (const reexportingTransaction of reexportingTransactions) {
|
|
409
|
+
yield this.transactionModel.updateOne({
|
|
410
|
+
_id: { $eq: reexportingTransaction.id },
|
|
411
|
+
tasksExportationStatus: { $eq: factory.transactionTasksExportationStatus.Exporting }
|
|
412
|
+
}, {
|
|
413
|
+
tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported
|
|
414
|
+
})
|
|
415
|
+
.exec();
|
|
416
|
+
assetTransaction_2.assetTransactionEventEmitter.emitAssetTransactionStatusChanged({
|
|
417
|
+
id: reexportingTransaction.id,
|
|
418
|
+
typeOf: reexportingTransaction.typeOf,
|
|
419
|
+
status: reexportingTransaction.status
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
// await this.transactionModel.updateMany(
|
|
424
|
+
// {
|
|
425
|
+
// tasksExportationStatus: { $eq: factory.transactionTasksExportationStatus.Exporting },
|
|
426
|
+
// updatedAt: {
|
|
427
|
+
// $lt: moment()
|
|
428
|
+
// .add(-params.intervalInMinutes, 'minutes')
|
|
429
|
+
// .toDate()
|
|
430
|
+
// }
|
|
431
|
+
// },
|
|
432
|
+
// {
|
|
433
|
+
// tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported
|
|
434
|
+
// }
|
|
435
|
+
// )
|
|
436
|
+
// .exec();
|
|
391
437
|
});
|
|
392
438
|
}
|
|
393
439
|
/**
|
|
@@ -396,12 +442,14 @@ class MongoRepository {
|
|
|
396
442
|
*/
|
|
397
443
|
setTasksExportedById(params) {
|
|
398
444
|
return __awaiter(this, void 0, void 0, function* () {
|
|
445
|
+
const endDate = new Date();
|
|
399
446
|
yield this.transactionModel.updateOne({
|
|
400
447
|
_id: { $eq: params.id },
|
|
401
448
|
tasksExportationStatus: { $eq: factory.transactionTasksExportationStatus.Exporting }
|
|
402
449
|
}, {
|
|
403
450
|
tasksExportationStatus: factory.transactionTasksExportationStatus.Exported,
|
|
404
|
-
tasksExportedAt:
|
|
451
|
+
tasksExportedAt: endDate,
|
|
452
|
+
'tasksExportAction.endDate': endDate
|
|
405
453
|
})
|
|
406
454
|
.exec();
|
|
407
455
|
});
|
|
@@ -433,6 +481,13 @@ class MongoRepository {
|
|
|
433
481
|
endDate: new Date()
|
|
434
482
|
})
|
|
435
483
|
.exec();
|
|
484
|
+
expiringTransactions.forEach((expiringTransaction) => {
|
|
485
|
+
assetTransaction_2.assetTransactionEventEmitter.emitAssetTransactionStatusChanged({
|
|
486
|
+
id: expiringTransaction.id,
|
|
487
|
+
typeOf: expiringTransaction.typeOf,
|
|
488
|
+
status: factory.transactionStatusType.Expired
|
|
489
|
+
});
|
|
490
|
+
});
|
|
436
491
|
}
|
|
437
492
|
});
|
|
438
493
|
}
|
|
@@ -481,6 +536,11 @@ class MongoRepository {
|
|
|
481
536
|
else {
|
|
482
537
|
transaction = doc.toObject();
|
|
483
538
|
}
|
|
539
|
+
assetTransaction_2.assetTransactionEventEmitter.emitAssetTransactionStatusChanged({
|
|
540
|
+
id: transaction.id,
|
|
541
|
+
typeOf: params.typeOf,
|
|
542
|
+
status: factory.transactionStatusType.Canceled
|
|
543
|
+
});
|
|
484
544
|
return transaction;
|
|
485
545
|
});
|
|
486
546
|
}
|
|
@@ -69,6 +69,7 @@ declare const schema: Schema<any, import("mongoose").Model<any, any, any, any, a
|
|
|
69
69
|
tasksExportedAt?: Date | undefined;
|
|
70
70
|
location?: any;
|
|
71
71
|
seller?: any;
|
|
72
|
+
tasksExportAction?: any;
|
|
72
73
|
}, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
|
|
73
74
|
object?: any;
|
|
74
75
|
typeOf?: string | undefined;
|
|
@@ -87,6 +88,7 @@ declare const schema: Schema<any, import("mongoose").Model<any, any, any, any, a
|
|
|
87
88
|
tasksExportedAt?: Date | undefined;
|
|
88
89
|
location?: any;
|
|
89
90
|
seller?: any;
|
|
91
|
+
tasksExportAction?: any;
|
|
90
92
|
}>> & Omit<import("mongoose").FlatRecord<{
|
|
91
93
|
object?: any;
|
|
92
94
|
typeOf?: string | undefined;
|
|
@@ -105,6 +107,7 @@ declare const schema: Schema<any, import("mongoose").Model<any, any, any, any, a
|
|
|
105
107
|
tasksExportedAt?: Date | undefined;
|
|
106
108
|
location?: any;
|
|
107
109
|
seller?: any;
|
|
110
|
+
tasksExportAction?: any;
|
|
108
111
|
}> & {
|
|
109
112
|
_id: import("mongoose").Types.ObjectId;
|
|
110
113
|
}, never>>;
|
|
@@ -28,6 +28,12 @@ export declare function exportTasks<T extends factory.assetTransactionType>(para
|
|
|
28
28
|
typeOf?: {
|
|
29
29
|
$in: T[];
|
|
30
30
|
};
|
|
31
|
+
id?: string;
|
|
32
|
+
tasksExportAction?: {
|
|
33
|
+
agent: {
|
|
34
|
+
name: string;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
31
37
|
}): (repos: {
|
|
32
38
|
task: TaskRepo;
|
|
33
39
|
assetTransaction: AssetTransactionRepo;
|
|
@@ -20,6 +20,7 @@ const PayTransactionService = require("./assetTransaction/pay");
|
|
|
20
20
|
const RefundTransactionService = require("./assetTransaction/refund");
|
|
21
21
|
const RegisterServiceTransactionService = require("./assetTransaction/registerService");
|
|
22
22
|
const ReserveTransactionService = require("./assetTransaction/reserve");
|
|
23
|
+
const settings_1 = require("../settings");
|
|
23
24
|
exports.cancelReservation = CancelReservationTransactionService;
|
|
24
25
|
exports.moneyTransfer = MoneyTransferTransactionService;
|
|
25
26
|
exports.pay = PayTransactionService;
|
|
@@ -31,10 +32,14 @@ exports.reserve = ReserveTransactionService;
|
|
|
31
32
|
*/
|
|
32
33
|
function exportTasks(params) {
|
|
33
34
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
var _a;
|
|
36
|
+
const transaction = yield repos.assetTransaction.startExportTasks(Object.assign({ typeOf: params.typeOf, status: params.status, tasksExportAction: {
|
|
37
|
+
agent: {
|
|
38
|
+
name: (typeof ((_a = params.tasksExportAction) === null || _a === void 0 ? void 0 : _a.agent.name) === 'string')
|
|
39
|
+
? params.tasksExportAction.agent.name
|
|
40
|
+
: settings_1.DEFAULT_TASKS_EXPORT_AGENT_NAME
|
|
41
|
+
}
|
|
42
|
+
} }, (typeof params.id === 'string') ? { id: params.id } : undefined));
|
|
38
43
|
if (transaction === null) {
|
|
39
44
|
return;
|
|
40
45
|
}
|
|
@@ -19,7 +19,7 @@ const MoneyTransferTransactionService = require("./transaction/moneyTransfer");
|
|
|
19
19
|
const PlaceOrderTransactionService = require("./transaction/placeOrder");
|
|
20
20
|
const PlaceOrderInProgressTransactionService = require("./transaction/placeOrderInProgress");
|
|
21
21
|
const ReturnOrderTransactionService = require("./transaction/returnOrder");
|
|
22
|
-
const
|
|
22
|
+
const settings_1 = require("../settings");
|
|
23
23
|
exports.moneyTransfer = MoneyTransferTransactionService;
|
|
24
24
|
exports.placeOrder = PlaceOrderTransactionService;
|
|
25
25
|
exports.placeOrderInProgress = PlaceOrderInProgressTransactionService;
|
|
@@ -83,7 +83,7 @@ function exportTasks(params) {
|
|
|
83
83
|
agent: {
|
|
84
84
|
name: (typeof ((_a = params.tasksExportAction) === null || _a === void 0 ? void 0 : _a.agent.name) === 'string')
|
|
85
85
|
? params.tasksExportAction.agent.name
|
|
86
|
-
: DEFAULT_TASKS_EXPORT_AGENT_NAME
|
|
86
|
+
: settings_1.DEFAULT_TASKS_EXPORT_AGENT_NAME
|
|
87
87
|
}
|
|
88
88
|
} }, (typeof params.id === 'string') ? { id: params.id } : undefined));
|
|
89
89
|
if (transaction === null) {
|
package/lib/chevre/settings.d.ts
CHANGED
|
@@ -27,6 +27,7 @@ export type ISettings = factory.project.ISettings & {
|
|
|
27
27
|
useOfferRateLimitProjects: string[];
|
|
28
28
|
};
|
|
29
29
|
export declare const DEFAULT_PAYMENT_METHOD_TYPE_FOR_CREDIT_CARD: string;
|
|
30
|
+
export declare const DEFAULT_TASKS_EXPORT_AGENT_NAME: string;
|
|
30
31
|
export declare const USE_ASSET_TRANSACTION_SYNC_PROCESSING: boolean;
|
|
31
32
|
export declare const USE_PAY_ASSET_TRANSACTION_SYNC_PROCESSING: boolean;
|
|
32
33
|
export declare const USE_NEW_EVENT_AVAILABILITY_KEY_FROM: moment.Moment;
|
package/lib/chevre/settings.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.settings = exports.USE_EVENT_EMITTERS = exports.USE_NEW_CONFIRMATION_NUMBER_KEY_FROM = exports.USE_NEW_EVENT_AVAILABILITY_KEY_FROM = exports.USE_PAY_ASSET_TRANSACTION_SYNC_PROCESSING = exports.USE_ASSET_TRANSACTION_SYNC_PROCESSING = exports.DEFAULT_PAYMENT_METHOD_TYPE_FOR_CREDIT_CARD = exports.DEFAULT_SENDER_EMAIL = exports.TRANSACTION_CANCELED_STORAGE_PERIOD_IN_DAYS = exports.TRANSACTION_CONFIRMED_STORAGE_PERIOD_IN_DAYS = exports.ASSET_TRANSACTION_STORAGE_PERIOD_IN_DAYS = exports.ABORTED_TASKS_WITHOUT_REPORT = void 0;
|
|
3
|
+
exports.settings = exports.USE_EVENT_EMITTERS = exports.USE_NEW_CONFIRMATION_NUMBER_KEY_FROM = exports.USE_NEW_EVENT_AVAILABILITY_KEY_FROM = exports.USE_PAY_ASSET_TRANSACTION_SYNC_PROCESSING = exports.USE_ASSET_TRANSACTION_SYNC_PROCESSING = exports.DEFAULT_TASKS_EXPORT_AGENT_NAME = exports.DEFAULT_PAYMENT_METHOD_TYPE_FOR_CREDIT_CARD = exports.DEFAULT_SENDER_EMAIL = exports.TRANSACTION_CANCELED_STORAGE_PERIOD_IN_DAYS = exports.TRANSACTION_CONFIRMED_STORAGE_PERIOD_IN_DAYS = exports.ASSET_TRANSACTION_STORAGE_PERIOD_IN_DAYS = exports.ABORTED_TASKS_WITHOUT_REPORT = void 0;
|
|
4
4
|
const moment = require("moment");
|
|
5
5
|
const factory = require("./factory");
|
|
6
6
|
const transactionWebhookUrls = (typeof process.env.INFORM_TRANSACTION_URL === 'string')
|
|
@@ -44,6 +44,7 @@ exports.TRANSACTION_CANCELED_STORAGE_PERIOD_IN_DAYS = (typeof process.env.TRANSA
|
|
|
44
44
|
: 7;
|
|
45
45
|
exports.DEFAULT_SENDER_EMAIL = process.env.DEFAULT_SENDER_EMAIL;
|
|
46
46
|
exports.DEFAULT_PAYMENT_METHOD_TYPE_FOR_CREDIT_CARD = String(process.env.DEFAULT_PAYMENT_METHOD_TYPE_FOR_CREDIT_CARD);
|
|
47
|
+
exports.DEFAULT_TASKS_EXPORT_AGENT_NAME = `${process.env.GAE_APPLICATION}:${process.env.GAE_SERVICE}:jobs`;
|
|
47
48
|
exports.USE_ASSET_TRANSACTION_SYNC_PROCESSING = process.env.USE_ASSET_TRANSACTION_SYNC_PROCESSING === '1';
|
|
48
49
|
exports.USE_PAY_ASSET_TRANSACTION_SYNC_PROCESSING = process.env.USE_PAY_ASSET_TRANSACTION_SYNC_PROCESSING === '1';
|
|
49
50
|
exports.USE_NEW_EVENT_AVAILABILITY_KEY_FROM = (typeof process.env.USE_NEW_EVENT_AVAILABILITY_KEY_FROM === 'string')
|
package/package.json
CHANGED