@chevre/domain 21.2.0-alpha.25 → 21.2.0-alpha.27
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/searchAbortedTasks.ts +30 -0
- package/lib/chevre/credentials.d.ts +1 -0
- package/lib/chevre/credentials.js +2 -1
- package/lib/chevre/repo/assetTransaction.d.ts +5 -0
- package/lib/chevre/repo/assetTransaction.js +10 -2
- 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 +5 -0
- package/lib/chevre/service/assetTransaction.js +10 -1
- package/lib/chevre/service/notification.d.ts +3 -1
- package/lib/chevre/service/notification.js +2 -6
- package/lib/chevre/service/task.js +7 -2
- 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,30 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as moment from 'moment-timezone';
|
|
3
|
+
import * as mongoose from 'mongoose';
|
|
4
|
+
|
|
5
|
+
import { chevre } from '../../../lib/index';
|
|
6
|
+
|
|
7
|
+
async function main() {
|
|
8
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
9
|
+
|
|
10
|
+
const taskRepo = new chevre.repository.Task(mongoose.connection);
|
|
11
|
+
|
|
12
|
+
const tasks = <chevre.factory.task.ITask<chevre.factory.taskName.Pay>[]>await taskRepo.search({
|
|
13
|
+
// limit: 100,
|
|
14
|
+
// page: 1,
|
|
15
|
+
name: chevre.factory.taskName.Pay,
|
|
16
|
+
statuses: [chevre.factory.taskStatus.Aborted],
|
|
17
|
+
runsFrom: moment('2023-04-27T00:00:00Z')
|
|
18
|
+
.toDate(),
|
|
19
|
+
sort: { runsAt: chevre.factory.sortType.Ascending }
|
|
20
|
+
});
|
|
21
|
+
console.log(tasks.map((task) => `${task.project.id},${task.id},${moment(task.runsAt)
|
|
22
|
+
.tz('Asia/Tokyo')
|
|
23
|
+
.format('YYYY-MM-DDTHH:mm:ssZ')},"${task.data.object[0].paymentMethod.paymentMethodId}"`)
|
|
24
|
+
.join('\n'));
|
|
25
|
+
console.log(tasks.length);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
main()
|
|
29
|
+
.then(console.log)
|
|
30
|
+
.catch(console.error);
|
|
@@ -31,7 +31,8 @@ exports.credentials = {
|
|
|
31
31
|
},
|
|
32
32
|
lineNotify: {
|
|
33
33
|
url: process.env.LINE_NOTIFY_URL,
|
|
34
|
-
accessToken: process.env.LINE_NOTIFY_ACCESS_TOKEN
|
|
34
|
+
accessToken: process.env.LINE_NOTIFY_ACCESS_TOKEN,
|
|
35
|
+
accessTokenAlert: process.env.LINE_NOTIFY_ACCESS_TOKEN_ALERT
|
|
35
36
|
},
|
|
36
37
|
movieticketReserve: {
|
|
37
38
|
// tslint:disable-next-line:no-magic-numbers
|
|
@@ -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
|
* タスクエクスポートリトライ
|
|
@@ -360,7 +360,13 @@ class MongoRepository {
|
|
|
360
360
|
// no op
|
|
361
361
|
}
|
|
362
362
|
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), {
|
|
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), {
|
|
364
|
+
tasksExportAction: {
|
|
365
|
+
agent: { name: params.tasksExportAction.agent.name },
|
|
366
|
+
startDate: new Date()
|
|
367
|
+
},
|
|
368
|
+
tasksExportationStatus: factory.transactionTasksExportationStatus.Exporting
|
|
369
|
+
}, { new: true })
|
|
364
370
|
.select({
|
|
365
371
|
_id: 1,
|
|
366
372
|
typeOf: 1
|
|
@@ -396,12 +402,14 @@ class MongoRepository {
|
|
|
396
402
|
*/
|
|
397
403
|
setTasksExportedById(params) {
|
|
398
404
|
return __awaiter(this, void 0, void 0, function* () {
|
|
405
|
+
const endDate = new Date();
|
|
399
406
|
yield this.transactionModel.updateOne({
|
|
400
407
|
_id: { $eq: params.id },
|
|
401
408
|
tasksExportationStatus: { $eq: factory.transactionTasksExportationStatus.Exporting }
|
|
402
409
|
}, {
|
|
403
410
|
tasksExportationStatus: factory.transactionTasksExportationStatus.Exported,
|
|
404
|
-
tasksExportedAt:
|
|
411
|
+
tasksExportedAt: endDate,
|
|
412
|
+
'tasksExportAction.endDate': endDate
|
|
405
413
|
})
|
|
406
414
|
.exec();
|
|
407
415
|
});
|
|
@@ -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,11 @@ export declare function exportTasks<T extends factory.assetTransactionType>(para
|
|
|
28
28
|
typeOf?: {
|
|
29
29
|
$in: T[];
|
|
30
30
|
};
|
|
31
|
+
tasksExportAction?: {
|
|
32
|
+
agent: {
|
|
33
|
+
name: string;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
31
36
|
}): (repos: {
|
|
32
37
|
task: TaskRepo;
|
|
33
38
|
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,9 +32,17 @@ exports.reserve = ReserveTransactionService;
|
|
|
31
32
|
*/
|
|
32
33
|
function exportTasks(params) {
|
|
33
34
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
var _a;
|
|
34
36
|
const transaction = yield repos.assetTransaction.startExportTasks({
|
|
35
37
|
typeOf: params.typeOf,
|
|
36
|
-
status: params.status
|
|
38
|
+
status: params.status,
|
|
39
|
+
tasksExportAction: {
|
|
40
|
+
agent: {
|
|
41
|
+
name: (typeof ((_a = params.tasksExportAction) === null || _a === void 0 ? void 0 : _a.agent.name) === 'string')
|
|
42
|
+
? params.tasksExportAction.agent.name
|
|
43
|
+
: settings_1.DEFAULT_TASKS_EXPORT_AGENT_NAME
|
|
44
|
+
}
|
|
45
|
+
}
|
|
37
46
|
});
|
|
38
47
|
if (transaction === null) {
|
|
39
48
|
return;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import * as factory from '../factory';
|
|
2
2
|
import { MongoRepository as ActionRepo } from '../repo/action';
|
|
3
3
|
import { MongoRepository as ProjectRepo } from '../repo/project';
|
|
4
|
-
export type Operation<T> = (
|
|
4
|
+
export type Operation<T> = (repos: {
|
|
5
|
+
accessToken: string;
|
|
6
|
+
}) => Promise<T>;
|
|
5
7
|
/**
|
|
6
8
|
* Eメールメッセージを送信する
|
|
7
9
|
* https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/errors.html
|
|
@@ -111,15 +111,11 @@ exports.sendEmailMessage = sendEmailMessage;
|
|
|
111
111
|
* https://notify-bot.line.me/doc/ja/
|
|
112
112
|
*/
|
|
113
113
|
function report2developers(subject, content, imageThumbnail, imageFullsize) {
|
|
114
|
-
return () => __awaiter(this, void 0, void 0, function* () {
|
|
114
|
+
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
115
115
|
const LINE_NOTIFY_URL = credentials_1.credentials.lineNotify.url;
|
|
116
|
-
const LINE_NOTIFY_ACCESS_TOKEN = credentials_1.credentials.lineNotify.accessToken;
|
|
117
116
|
if (LINE_NOTIFY_URL === undefined) {
|
|
118
117
|
throw new Error('Environment variable LINE_NOTIFY_URL not set');
|
|
119
118
|
}
|
|
120
|
-
if (LINE_NOTIFY_ACCESS_TOKEN === undefined) {
|
|
121
|
-
throw new Error('Environment variable LINE_NOTIFY_ACCESS_TOKEN not set');
|
|
122
|
-
}
|
|
123
119
|
const message = `--------
|
|
124
120
|
${subject}
|
|
125
121
|
--------
|
|
@@ -130,7 +126,7 @@ ${content}`;
|
|
|
130
126
|
var _a;
|
|
131
127
|
request.post({
|
|
132
128
|
url: LINE_NOTIFY_URL,
|
|
133
|
-
auth: { bearer:
|
|
129
|
+
auth: { bearer: repos.accessToken },
|
|
134
130
|
form: formData,
|
|
135
131
|
json: true,
|
|
136
132
|
timeout: (_a = settings_1.settings.webhook) === null || _a === void 0 ? void 0 : _a.timeout
|
|
@@ -18,6 +18,7 @@ const factory = require("../factory");
|
|
|
18
18
|
const task_1 = require("../repo/task");
|
|
19
19
|
const NotificationService = require("./notification");
|
|
20
20
|
const factory_1 = require("./notification/factory");
|
|
21
|
+
const credentials_1 = require("../credentials");
|
|
21
22
|
const settings_1 = require("../settings");
|
|
22
23
|
const debug = createDebug('chevre-domain:service:task');
|
|
23
24
|
const DEFAULT_EXECUTOR_NAME = `${process.env.GAE_APPLICATION}:${process.env.GAE_SERVICE}:jobs`;
|
|
@@ -140,7 +141,9 @@ function abort(params) {
|
|
|
140
141
|
}
|
|
141
142
|
// 開発者へ報告
|
|
142
143
|
const message = (0, factory_1.task2lineNotify)({ task: abortedTask });
|
|
143
|
-
yield NotificationService.report2developers(message.subject, message.content)(
|
|
144
|
+
yield NotificationService.report2developers(message.subject, message.content)({
|
|
145
|
+
accessToken: credentials_1.credentials.lineNotify.accessTokenAlert
|
|
146
|
+
});
|
|
144
147
|
}
|
|
145
148
|
});
|
|
146
149
|
}
|
|
@@ -157,7 +160,9 @@ function notifyAbortedTasks(params) {
|
|
|
157
160
|
if (abortedTasks.length > 0) {
|
|
158
161
|
// 開発者へ報告
|
|
159
162
|
const message = (0, factory_1.tasks2lineNotify)({ tasks: abortedTasks });
|
|
160
|
-
yield NotificationService.report2developers(message.subject, message.content)(
|
|
163
|
+
yield NotificationService.report2developers(message.subject, message.content)({
|
|
164
|
+
accessToken: credentials_1.credentials.lineNotify.accessTokenAlert
|
|
165
|
+
});
|
|
161
166
|
}
|
|
162
167
|
});
|
|
163
168
|
}
|
|
@@ -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