@chevre/domain 22.11.0-alpha.3 → 22.11.0-alpha.30
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/aggregation/aggregateTasks.ts +41 -0
- package/example/src/chevre/assetTransaction/processReserve.ts +0 -1
- package/example/src/chevre/notifyAbortedTasksByEmail.ts +1 -1
- package/example/src/chevre/reIndex.ts +1 -1
- package/example/src/chevre/roles/addAdminPermissionIfNotExists.ts +132 -0
- package/example/src/chevre/roles/addDefaultPermissionIfNotExists.ts +37 -0
- package/example/src/chevre/roles/addEventOfferPermissionIfNotExists.ts +27 -0
- package/example/src/chevre/roles/addPermissionIfNotExists.ts +39 -6
- package/example/src/chevre/roles/addProjectCreatorRole.ts +48 -0
- package/example/src/chevre/roles/assignGlobalRoles.ts +72 -0
- package/example/src/chevre/roles/findPermissions.ts +84 -0
- package/example/src/chevre/roles/findRoleNames.ts +117 -0
- package/example/src/chevre/roles/removeConsolePermissionIfExists.ts +38 -0
- package/example/src/chevre/roles/removePermissionFromAPIRoles.ts +46 -0
- package/example/src/chevre/roles/removePermissionIfExists.ts +39 -0
- package/example/src/chevre/settings/addSettings.ts +31 -17
- package/example/src/chevre/stockHolder/checkRedisKeyCount.ts +11 -20
- package/example/src/chevre/task/countPotentiallyRunning.ts +41 -0
- package/example/src/chevre/task/countTasks.ts +51 -0
- package/example/src/chevre/unsetUnnecessaryFields.ts +8 -5
- package/example/src/idaas/auth0/adminApplications.ts +183 -0
- package/example/src/idaas/auth0/getToken.ts +55 -0
- package/example/src/idaas/auth0/getTokenByPrivateKeyJWT.ts +84 -0
- package/example/src/regex.ts +31 -0
- package/lib/chevre/eventEmitter/task.d.ts +29 -6
- package/lib/chevre/index.d.ts +0 -2
- package/lib/chevre/index.js +0 -10
- package/lib/chevre/repo/confirmationNumber.d.ts +0 -11
- package/lib/chevre/repo/confirmationNumber.js +15 -54
- package/lib/chevre/repo/identity.d.ts +11 -33
- package/lib/chevre/repo/identity.js +10 -15
- package/lib/chevre/repo/member.d.ts +22 -4
- package/lib/chevre/repo/member.js +81 -27
- package/lib/chevre/repo/mongoose/schemas/identity.d.ts +1 -1
- package/lib/chevre/repo/mongoose/schemas/member/global.d.ts +14 -0
- package/lib/chevre/repo/mongoose/schemas/member/global.js +82 -0
- package/lib/chevre/repo/mongoose/schemas/setting.d.ts +15 -0
- package/lib/chevre/repo/mongoose/schemas/setting.js +1 -0
- package/lib/chevre/repo/mongoose/schemas/task.js +9 -0
- package/lib/chevre/repo/orderNumber.d.ts +0 -11
- package/lib/chevre/repo/orderNumber.js +13 -51
- package/lib/chevre/repo/role.d.ts +16 -4
- package/lib/chevre/repo/role.js +71 -32
- package/lib/chevre/repo/serviceOutputIdentifier.d.ts +0 -4
- package/lib/chevre/repo/serviceOutputIdentifier.js +13 -38
- package/lib/chevre/repo/setting.d.ts +5 -10
- package/lib/chevre/repo/setting.js +4 -7
- package/lib/chevre/repo/stockHolder.js +0 -11
- package/lib/chevre/repo/task.d.ts +47 -34
- package/lib/chevre/repo/task.js +116 -292
- package/lib/chevre/repo/transaction.js +10 -10
- package/lib/chevre/repo/transactionNumber.d.ts +0 -11
- package/lib/chevre/repo/transactionNumber.js +13 -51
- package/lib/chevre/repo/transactionNumberCounter.d.ts +0 -10
- package/lib/chevre/repo/transactionNumberCounter.js +34 -29
- package/lib/chevre/service/assetTransaction/cancelReservation/start.d.ts +1 -1
- package/lib/chevre/service/code.d.ts +5 -28
- package/lib/chevre/service/code.js +3 -79
- package/lib/chevre/service/iam.d.ts +17 -7
- package/lib/chevre/service/iam.js +26 -6
- package/lib/chevre/service/notification/notifyAbortedTasksByEmail.d.ts +15 -0
- package/lib/chevre/service/notification/notifyAbortedTasksByEmail.js +38 -0
- package/lib/chevre/service/notification.d.ts +2 -1
- package/lib/chevre/service/notification.js +3 -1
- package/lib/chevre/service/task/acceptCOAOffer.d.ts +1 -1
- package/lib/chevre/service/task/acceptCOAOffer.js +6 -5
- package/lib/chevre/service/task/aggregateOffers.d.ts +1 -1
- package/lib/chevre/service/task/aggregateOnSystem.d.ts +4 -2
- package/lib/chevre/service/task/aggregateScreeningEvent.d.ts +1 -1
- package/lib/chevre/service/task/authorizePayment.d.ts +1 -1
- package/lib/chevre/service/task/authorizePayment.js +7 -6
- package/lib/chevre/service/task/cancelMoneyTransfer.d.ts +1 -1
- package/lib/chevre/service/task/cancelPendingReservation.d.ts +1 -1
- package/lib/chevre/service/task/cancelReservation.d.ts +1 -1
- package/lib/chevre/service/task/checkMovieTicket.d.ts +1 -1
- package/lib/chevre/service/task/checkMovieTicket.js +4 -3
- package/lib/chevre/service/task/checkResource.d.ts +1 -1
- package/lib/chevre/service/task/confirmMoneyTransfer.d.ts +1 -1
- package/lib/chevre/service/task/confirmPayTransaction.d.ts +1 -1
- package/lib/chevre/service/task/confirmRegisterService.d.ts +1 -1
- package/lib/chevre/service/task/confirmRegisterServiceTransaction.d.ts +1 -1
- package/lib/chevre/service/task/confirmReserveTransaction.d.ts +1 -1
- package/lib/chevre/service/task/createAccountingReport.d.ts +1 -1
- package/lib/chevre/service/task/createEvent.d.ts +1 -1
- package/lib/chevre/service/task/deletePerson.d.ts +1 -1
- package/lib/chevre/service/task/deleteTransaction.d.ts +1 -1
- package/lib/chevre/service/task/givePointAward.d.ts +1 -1
- package/lib/chevre/service/task/givePointAward.js +1 -1
- package/lib/chevre/service/task/handleNotification.d.ts +4 -2
- package/lib/chevre/service/task/importEventCapacitiesFromCOA.d.ts +1 -1
- package/lib/chevre/service/task/importEventsFromCOA.d.ts +1 -1
- package/lib/chevre/service/task/importOffersFromCOA.d.ts +1 -1
- package/lib/chevre/service/task/invalidatePaymentUrl.d.ts +1 -1
- package/lib/chevre/service/task/moneyTransfer.d.ts +1 -1
- package/lib/chevre/service/task/moneyTransfer.js +1 -1
- package/lib/chevre/service/task/onAssetTransactionStatusChanged.d.ts +1 -1
- package/lib/chevre/service/task/onAuthorizationCreated.d.ts +1 -1
- package/lib/chevre/service/task/onEventChanged.d.ts +1 -1
- package/lib/chevre/service/task/onOrderPaymentCompleted.d.ts +1 -1
- package/lib/chevre/service/task/onResourceUpdated.d.ts +1 -1
- package/lib/chevre/service/task/pay.d.ts +1 -1
- package/lib/chevre/service/task/placeOrder.d.ts +1 -1
- package/lib/chevre/service/task/publishPaymentUrl.d.ts +1 -1
- package/lib/chevre/service/task/publishPaymentUrl.js +6 -7
- package/lib/chevre/service/task/refund.d.ts +1 -1
- package/lib/chevre/service/task/refund.js +1 -1
- package/lib/chevre/service/task/registerService.d.ts +1 -1
- package/lib/chevre/service/task/reserve.d.ts +1 -1
- package/lib/chevre/service/task/returnMoneyTransfer.d.ts +1 -1
- package/lib/chevre/service/task/returnMoneyTransfer.js +1 -1
- package/lib/chevre/service/task/returnOrder.d.ts +1 -1
- package/lib/chevre/service/task/returnPayTransaction.d.ts +1 -1
- package/lib/chevre/service/task/returnPayTransaction.js +1 -1
- package/lib/chevre/service/task/returnPointAward.d.ts +1 -1
- package/lib/chevre/service/task/returnPointAward.js +1 -1
- package/lib/chevre/service/task/returnReserveTransaction.d.ts +1 -1
- package/lib/chevre/service/task/returnReserveTransaction.js +1 -1
- package/lib/chevre/service/task/sendEmailMessage.d.ts +1 -1
- package/lib/chevre/service/task/sendOrder.d.ts +1 -1
- package/lib/chevre/service/task/triggerWebhook.d.ts +1 -1
- package/lib/chevre/service/task/useReservation.d.ts +1 -1
- package/lib/chevre/service/task/voidMoneyTransferTransaction.d.ts +1 -1
- package/lib/chevre/service/task/voidPayTransaction.d.ts +1 -1
- package/lib/chevre/service/task/voidPayment.d.ts +1 -1
- package/lib/chevre/service/task/voidRegisterServiceTransaction.d.ts +1 -1
- package/lib/chevre/service/task/voidReserveTransaction.d.ts +1 -1
- package/lib/chevre/service/task/voidReserveTransaction.js +4 -3
- package/lib/chevre/service/task.d.ts +7 -29
- package/lib/chevre/service/task.js +9 -114
- package/lib/chevre/service/taskHandler/onOperationFailed/informTaskIfNeeded.d.ts +11 -0
- package/lib/chevre/service/taskHandler/onOperationFailed/informTaskIfNeeded.js +105 -0
- package/lib/chevre/service/taskHandler/onOperationFailed.d.ts +17 -0
- package/lib/chevre/service/taskHandler/onOperationFailed.js +70 -0
- package/lib/chevre/service/taskHandler.d.ts +26 -0
- package/lib/chevre/service/taskHandler.js +96 -0
- package/lib/chevre/service/validation/validateOrder.js +55 -37
- package/lib/chevre/service.d.ts +0 -4
- package/lib/chevre/service.js +10 -14
- package/lib/chevre/settings/aggregation.d.ts +6 -1
- package/lib/chevre/settings/aggregation.js +2 -1
- package/package.json +5 -3
- package/example/src/chevre/adminAuth/adminIdentity.ts +0 -38
- package/example/src/chevre/executeOneTask.ts +0 -41
- package/example/src/chevre/executeTaskIfExists.ts +0 -80
- package/example/src/chevre/findExecutableTask.ts +0 -50
- package/example/src/chevre/findSetting.ts +0 -79
- package/example/src/chevre/roles/addRoleMembers.ts +0 -75
- package/example/src/chevre/searchPermissions.ts +0 -46
- package/example/src/chevre/transactionNumber/publishConfimationNumber.ts +0 -37
- package/example/src/chevre/transactionNumber/publishOrderNumber.ts +0 -40
- package/example/src/chevre/transactionNumber/setUseMongo4confirmationNumberFrom.ts +0 -45
- package/example/src/chevre/transactionNumber/setUseMongo4orderNumberFrom.ts +0 -41
- package/example/src/chevre/transactionNumber/setUseMongo4transactionNumberFrom.ts +0 -41
- package/lib/chevre/adminAuth.d.ts +0 -2
- package/lib/chevre/adminAuth.js +0 -6
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { SendGridCredentials } from '../credentials/sendGrid';
|
|
2
2
|
import type { IExecuteSettings as IMinimumExecuteSettings, INextFunction, IReadyTask, IRunningTask } from '../eventEmitter/task';
|
|
3
3
|
import * as factory from '../factory';
|
|
4
|
-
import type { IExecutableTask, IExecutableTaskKeys, TaskRepo } from '../repo/task';
|
|
5
4
|
import { Settings } from '../settings';
|
|
6
5
|
import { AggregationSettings } from '../settings/aggregation';
|
|
7
6
|
interface ICredentialSettings {
|
|
@@ -12,14 +11,7 @@ interface IExecuteSettings extends IMinimumExecuteSettings {
|
|
|
12
11
|
settings: Settings;
|
|
13
12
|
aggregationSettings?: AggregationSettings;
|
|
14
13
|
}
|
|
15
|
-
interface IExecuteOptions {
|
|
16
|
-
executeById: boolean;
|
|
17
|
-
executeByName: boolean;
|
|
18
|
-
}
|
|
19
14
|
type IOperation<T> = (settings: IExecuteSettings) => Promise<T>;
|
|
20
|
-
type IOperationExecute<T> = (settings: IExecuteSettings, options: IExecuteOptions) => Promise<T>;
|
|
21
|
-
type ICallResult = void | Pick<factory.task.IExecutionResult, 'error'>;
|
|
22
|
-
export type ICallableTaskOperation = (task: IExecutableTask<factory.taskName>) => IOperationExecute<ICallResult>;
|
|
23
15
|
/**
|
|
24
16
|
* タスク変更イベントを受けて実行する
|
|
25
17
|
*/
|
|
@@ -31,13 +23,9 @@ declare function executeById(params: (IReadyTask | IRunningTask) & {
|
|
|
31
23
|
name: string;
|
|
32
24
|
};
|
|
33
25
|
}, next?: INextFunction): IOperation<void>;
|
|
34
|
-
/**
|
|
35
|
-
* support no name(2025-03-04~)
|
|
36
|
-
*/
|
|
37
26
|
declare function executeOneIfExists(params: {
|
|
38
|
-
name
|
|
39
|
-
$eq
|
|
40
|
-
$nin?: factory.taskName[];
|
|
27
|
+
name: {
|
|
28
|
+
$eq: factory.taskName;
|
|
41
29
|
};
|
|
42
30
|
executor: {
|
|
43
31
|
/**
|
|
@@ -48,19 +36,9 @@ declare function executeOneIfExists(params: {
|
|
|
48
36
|
runsAt: {
|
|
49
37
|
$lt: Date;
|
|
50
38
|
};
|
|
39
|
+
sort: {
|
|
40
|
+
numberOfTried?: factory.sortType;
|
|
41
|
+
runsAt?: factory.sortType;
|
|
42
|
+
};
|
|
51
43
|
}): IOperation<void>;
|
|
52
|
-
|
|
53
|
-
* タスクを実行する
|
|
54
|
-
*/
|
|
55
|
-
declare function execute(task: IExecutableTask<factory.taskName>, next?: INextFunction): IOperationExecute<void>;
|
|
56
|
-
/**
|
|
57
|
-
* add(2025-03-13~)
|
|
58
|
-
*/
|
|
59
|
-
declare function notifyAbortedTasksByEmail(params: {
|
|
60
|
-
dateAbortedGte: Date;
|
|
61
|
-
}): (repos: {
|
|
62
|
-
task: TaskRepo;
|
|
63
|
-
}, settings: Pick<Settings, "abortedTasksWithoutReport">, credentials: {
|
|
64
|
-
sendGrid: SendGridCredentials;
|
|
65
|
-
}) => Promise<void>;
|
|
66
|
-
export { ICallResult, IExecutableTaskKeys, IOperationExecute, executeById, executeOneIfExists, execute, notifyAbortedTasksByEmail };
|
|
44
|
+
export { executeById, executeOneIfExists };
|
|
@@ -11,15 +11,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.executeById = executeById;
|
|
13
13
|
exports.executeOneIfExists = executeOneIfExists;
|
|
14
|
-
exports.execute = execute;
|
|
15
|
-
exports.notifyAbortedTasksByEmail = notifyAbortedTasksByEmail;
|
|
16
14
|
/**
|
|
17
15
|
* タスクサービス
|
|
18
16
|
*/
|
|
19
17
|
const createDebug = require("debug");
|
|
20
|
-
const
|
|
21
|
-
const factory = require("../factory");
|
|
22
|
-
const factory_1 = require("./notification/factory");
|
|
18
|
+
const taskHandler_1 = require("./taskHandler");
|
|
23
19
|
const debug = createDebug('chevre-domain:service:task');
|
|
24
20
|
/**
|
|
25
21
|
* タスク変更イベントを受けて実行する
|
|
@@ -42,16 +38,13 @@ function executeById(params, next) {
|
|
|
42
38
|
}
|
|
43
39
|
// タスクがなければ終了
|
|
44
40
|
if (task !== null) {
|
|
45
|
-
yield
|
|
41
|
+
yield (0, taskHandler_1.executeTask)(task, (typeof next === 'function') ? next : undefined)(settings, {
|
|
46
42
|
executeById: true,
|
|
47
43
|
executeByName: false
|
|
48
44
|
});
|
|
49
45
|
}
|
|
50
46
|
});
|
|
51
47
|
}
|
|
52
|
-
/**
|
|
53
|
-
* support no name(2025-03-04~)
|
|
54
|
-
*/
|
|
55
48
|
function executeOneIfExists(params) {
|
|
56
49
|
return (settings) => __awaiter(this, void 0, void 0, function* () {
|
|
57
50
|
var _a;
|
|
@@ -60,7 +53,12 @@ function executeOneIfExists(params) {
|
|
|
60
53
|
// tslint:disable-next-line:no-null-keyword
|
|
61
54
|
let task = null;
|
|
62
55
|
try {
|
|
63
|
-
task = yield taskRepo.executeOneIfExists(
|
|
56
|
+
task = yield taskRepo.executeOneIfExists({
|
|
57
|
+
executor: { name: params.executor.name },
|
|
58
|
+
runsAt: { $lt: params.runsAt.$lt },
|
|
59
|
+
name: params.name,
|
|
60
|
+
sort: params.sort
|
|
61
|
+
});
|
|
64
62
|
debug('executable task found.', task, params.runsAt.$lt);
|
|
65
63
|
}
|
|
66
64
|
catch (error) {
|
|
@@ -70,113 +68,10 @@ function executeOneIfExists(params) {
|
|
|
70
68
|
}
|
|
71
69
|
// タスクがなければ終了
|
|
72
70
|
if (task !== null) {
|
|
73
|
-
yield
|
|
71
|
+
yield (0, taskHandler_1.executeTask)(task)(settings, {
|
|
74
72
|
executeById: false,
|
|
75
73
|
executeByName: (typeof ((_a = params.name) === null || _a === void 0 ? void 0 : _a.$eq) === 'string')
|
|
76
74
|
});
|
|
77
75
|
}
|
|
78
76
|
});
|
|
79
77
|
}
|
|
80
|
-
/**
|
|
81
|
-
* タスクを実行する
|
|
82
|
-
*/
|
|
83
|
-
function execute(task, next) {
|
|
84
|
-
const now = new Date();
|
|
85
|
-
debug('executing an executableTask...', task, now);
|
|
86
|
-
return (settings, options) => __awaiter(this, void 0, void 0, function* () {
|
|
87
|
-
const taskRepo = new (yield Promise.resolve().then(() => require('../repo/task'))).TaskRepo(settings.connection);
|
|
88
|
-
try {
|
|
89
|
-
// 期限検証(2024-04-23~)
|
|
90
|
-
if (task.expires instanceof Date) {
|
|
91
|
-
const taskExpired = moment(now)
|
|
92
|
-
.isAfter(task.expires);
|
|
93
|
-
if (taskExpired) {
|
|
94
|
-
throw new factory.errors.Internal(`task expired [expires:${task.expires}]`);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
// タスク名の関数が定義されていなければ、TypeErrorとなる
|
|
98
|
-
let callResult;
|
|
99
|
-
const { call } = yield Promise.resolve(`${`./task/${task.name}`}`).then(s => require(s));
|
|
100
|
-
switch (task.name) {
|
|
101
|
-
case factory.taskName.AcceptCOAOffer:
|
|
102
|
-
case factory.taskName.AggregateOnSystem:
|
|
103
|
-
case factory.taskName.AuthorizePayment:
|
|
104
|
-
case factory.taskName.CancelPendingReservation:
|
|
105
|
-
case factory.taskName.CheckMovieTicket:
|
|
106
|
-
case factory.taskName.DeletePerson:
|
|
107
|
-
case factory.taskName.HandleNotification:
|
|
108
|
-
case factory.taskName.ImportEventCapacitiesFromCOA:
|
|
109
|
-
case factory.taskName.ImportEventsFromCOA:
|
|
110
|
-
case factory.taskName.ImportOffersFromCOA:
|
|
111
|
-
case factory.taskName.InvalidatePaymentUrl:
|
|
112
|
-
case factory.taskName.OnAuthorizationCreated:
|
|
113
|
-
case factory.taskName.Pay:
|
|
114
|
-
case factory.taskName.PublishPaymentUrl:
|
|
115
|
-
case factory.taskName.Refund:
|
|
116
|
-
case factory.taskName.VoidPayTransaction:
|
|
117
|
-
case factory.taskName.VoidReserveTransaction:
|
|
118
|
-
case factory.taskName.ConfirmReserveTransaction:
|
|
119
|
-
case factory.taskName.ReturnPayTransaction:
|
|
120
|
-
case factory.taskName.ReturnReserveTransaction:
|
|
121
|
-
case factory.taskName.SendEmailMessage:
|
|
122
|
-
case factory.taskName.TriggerWebhook:
|
|
123
|
-
callResult = yield call(task)(settings, options);
|
|
124
|
-
break;
|
|
125
|
-
default:
|
|
126
|
-
yield call(task.data)(settings);
|
|
127
|
-
}
|
|
128
|
-
const result = {
|
|
129
|
-
executedAt: now,
|
|
130
|
-
endDate: new Date(),
|
|
131
|
-
// enable overwriting task.executionResults.error on Executed(2024-05-29~)
|
|
132
|
-
error: ((callResult === null || callResult === void 0 ? void 0 : callResult.error) instanceof Error)
|
|
133
|
-
? Object.assign(Object.assign({}, callResult.error), { message: callResult.error.message }) : ''
|
|
134
|
-
};
|
|
135
|
-
yield taskRepo.pushExecutionResultById({
|
|
136
|
-
id: task.id,
|
|
137
|
-
status: factory.taskStatus.Executed
|
|
138
|
-
}, result, (typeof next === 'function') ? next : undefined);
|
|
139
|
-
}
|
|
140
|
-
catch (error) {
|
|
141
|
-
debug('service.task.execute throwed an error. task:', task.name, task.id, 'error:', error === null || error === void 0 ? void 0 : error.name, error === null || error === void 0 ? void 0 : error.message);
|
|
142
|
-
if (typeof error !== 'object') {
|
|
143
|
-
error = { message: String(error) };
|
|
144
|
-
}
|
|
145
|
-
// 実行結果追加
|
|
146
|
-
const result = {
|
|
147
|
-
executedAt: now,
|
|
148
|
-
endDate: new Date(),
|
|
149
|
-
error: Object.assign(Object.assign({}, error), { code: error.code, message: error.message, name: error.name, stack: error.stack })
|
|
150
|
-
};
|
|
151
|
-
// 失敗してもここではステータスを戻さない(Runningのまま待機)
|
|
152
|
-
yield taskRepo.pushExecutionResultById({
|
|
153
|
-
id: task.id,
|
|
154
|
-
status: task.status
|
|
155
|
-
}, result, (typeof next === 'function') ? next : undefined);
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
let notification;
|
|
160
|
-
/**
|
|
161
|
-
* add(2025-03-13~)
|
|
162
|
-
*/
|
|
163
|
-
function notifyAbortedTasksByEmail(params) {
|
|
164
|
-
return (repos, settings, credentials) => __awaiter(this, void 0, void 0, function* () {
|
|
165
|
-
const { abortedTasksWithoutReport } = settings;
|
|
166
|
-
const abortedTasks = yield repos.task.projectFields(Object.assign({ status: { $eq: factory.taskStatus.Aborted }, dateAborted: { $gte: params.dateAbortedGte } }, (abortedTasksWithoutReport.length > 0)
|
|
167
|
-
? { name: { $nin: abortedTasksWithoutReport } }
|
|
168
|
-
: undefined), []);
|
|
169
|
-
if (abortedTasks.length > 0) {
|
|
170
|
-
if (notification === undefined) {
|
|
171
|
-
notification = yield Promise.resolve().then(() => require('./notification'));
|
|
172
|
-
}
|
|
173
|
-
// 開発者へ報告
|
|
174
|
-
const message = (0, factory_1.tasks2lineNotify)({ tasks: abortedTasks });
|
|
175
|
-
const notifyResult = yield notification.notifyByEmail({
|
|
176
|
-
subject: message.subject, content: message.content,
|
|
177
|
-
logLevel: 'error'
|
|
178
|
-
})({}, credentials);
|
|
179
|
-
debug('notifyResult:', notifyResult);
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as factory from '../../../factory';
|
|
2
|
+
import type { SettingRepo } from '../../../repo/setting';
|
|
3
|
+
import type { IExecutableTask, TaskRepo } from '../../../repo/task';
|
|
4
|
+
declare function informTaskIfNeeded(params: {
|
|
5
|
+
task: IExecutableTask<factory.taskName>;
|
|
6
|
+
executionEndDate: Date;
|
|
7
|
+
}): (repos: {
|
|
8
|
+
setting: SettingRepo;
|
|
9
|
+
task: TaskRepo;
|
|
10
|
+
}) => Promise<void>;
|
|
11
|
+
export { informTaskIfNeeded };
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.informTaskIfNeeded = informTaskIfNeeded;
|
|
13
|
+
const createDebug = require("debug");
|
|
14
|
+
const factory = require("../../../factory");
|
|
15
|
+
const debug = createDebug('chevre-domain:service:taskHandler:onOperationFailed');
|
|
16
|
+
function createInformTasks(params) {
|
|
17
|
+
var _a, _b, _c;
|
|
18
|
+
const { task, setting, executionEndDate } = params;
|
|
19
|
+
const informTask = (_a = setting === null || setting === void 0 ? void 0 : setting.onTaskStatusChanged) === null || _a === void 0 ? void 0 : _a.informTask;
|
|
20
|
+
const informTaskNames = (_b = setting === null || setting === void 0 ? void 0 : setting.onTaskStatusChanged) === null || _b === void 0 ? void 0 : _b.informTaskNames;
|
|
21
|
+
const informTaskStatuses = (_c = setting === null || setting === void 0 ? void 0 : setting.onTaskStatusChanged) === null || _c === void 0 ? void 0 : _c.informTaskStatuses;
|
|
22
|
+
const informTasks = [];
|
|
23
|
+
if (Array.isArray(informTaskNames) && informTaskNames.includes(task.name)) {
|
|
24
|
+
if (Array.isArray(informTaskStatuses)) {
|
|
25
|
+
const { id, name, data, project, runsAt, remainingNumberOfTries } = task;
|
|
26
|
+
let task4inform;
|
|
27
|
+
if (remainingNumberOfTries <= 0) {
|
|
28
|
+
if (informTaskStatuses.includes(factory.taskStatus.Aborted)) {
|
|
29
|
+
const abortingTask = {
|
|
30
|
+
id, name, data, project, runsAt,
|
|
31
|
+
status: factory.taskStatus.Aborted,
|
|
32
|
+
typeOf: 'Task',
|
|
33
|
+
dateAborted: executionEndDate
|
|
34
|
+
};
|
|
35
|
+
task4inform = abortingTask;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
if (informTaskStatuses.includes(factory.taskStatus.Running)) {
|
|
40
|
+
const runningTask = {
|
|
41
|
+
id, name, data, project, runsAt,
|
|
42
|
+
status: factory.taskStatus.Running,
|
|
43
|
+
typeOf: 'Task'
|
|
44
|
+
};
|
|
45
|
+
task4inform = runningTask;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (task4inform !== undefined) {
|
|
49
|
+
const informIdentifier = `Task:${name}:${id}:${task4inform.status}`;
|
|
50
|
+
if (Array.isArray(informTask) && informTask.length > 0) {
|
|
51
|
+
informTask.forEach((informTaskParams) => {
|
|
52
|
+
var _a, _b;
|
|
53
|
+
if (typeof ((_a = informTaskParams.recipient) === null || _a === void 0 ? void 0 : _a.url) === 'string') {
|
|
54
|
+
const informActionAttributes = {
|
|
55
|
+
object: task4inform,
|
|
56
|
+
recipient: {
|
|
57
|
+
id: '',
|
|
58
|
+
name: String((_b = informTaskParams.recipient) === null || _b === void 0 ? void 0 : _b.name),
|
|
59
|
+
typeOf: factory.creativeWorkType.WebApplication
|
|
60
|
+
},
|
|
61
|
+
target: {
|
|
62
|
+
httpMethod: 'POST',
|
|
63
|
+
encodingType: factory.encodingFormat.Application.json,
|
|
64
|
+
typeOf: 'EntryPoint',
|
|
65
|
+
urlTemplate: informTaskParams.recipient.url
|
|
66
|
+
},
|
|
67
|
+
identifier: informIdentifier
|
|
68
|
+
};
|
|
69
|
+
const description = `inform aborting tasks to agg service: ${name} ${id} ${task4inform.status}`;
|
|
70
|
+
informTasks.push({
|
|
71
|
+
project,
|
|
72
|
+
name: factory.taskName.TriggerWebhook,
|
|
73
|
+
status: factory.taskStatus.Ready,
|
|
74
|
+
runsAt: executionEndDate,
|
|
75
|
+
remainingNumberOfTries: 10,
|
|
76
|
+
numberOfTried: 0,
|
|
77
|
+
executionResults: [],
|
|
78
|
+
data: informActionAttributes,
|
|
79
|
+
description
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return informTasks;
|
|
88
|
+
}
|
|
89
|
+
function informTaskIfNeeded(params) {
|
|
90
|
+
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
91
|
+
const { executionEndDate, task } = params;
|
|
92
|
+
const isAborting = task.status === factory.taskStatus.Running;
|
|
93
|
+
const useInform = isAborting
|
|
94
|
+
&& task.name !== factory.taskName.HandleNotification // nameで絞る
|
|
95
|
+
&& task.name !== factory.taskName.TriggerWebhook;
|
|
96
|
+
if (useInform) {
|
|
97
|
+
const setting = yield repos.setting.findOne({ project: { id: { $eq: '*' } } }, ['onTaskStatusChanged']);
|
|
98
|
+
const informTasks = createInformTasks({ task, setting, executionEndDate });
|
|
99
|
+
debug('informTaskIfNeeded: creating inform tasks...', JSON.stringify(informTasks));
|
|
100
|
+
if (informTasks.length > 0) {
|
|
101
|
+
yield repos.task.saveMany(informTasks, { emitImmediately: true });
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { INextFunction } from '../../eventEmitter/task';
|
|
2
|
+
import * as factory from '../../factory';
|
|
3
|
+
import type { SettingRepo } from '../../repo/setting';
|
|
4
|
+
import type { IExecutableTask, TaskRepo } from '../../repo/task';
|
|
5
|
+
/**
|
|
6
|
+
* タスク実行失敗時処理
|
|
7
|
+
*/
|
|
8
|
+
declare function onOperationFailed(params: {
|
|
9
|
+
task: IExecutableTask<factory.taskName>;
|
|
10
|
+
now: Date;
|
|
11
|
+
error: any;
|
|
12
|
+
next?: INextFunction;
|
|
13
|
+
}): (repos: {
|
|
14
|
+
setting: SettingRepo;
|
|
15
|
+
task: TaskRepo;
|
|
16
|
+
}) => Promise<void>;
|
|
17
|
+
export { onOperationFailed };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.onOperationFailed = onOperationFailed;
|
|
13
|
+
const factory = require("../../factory");
|
|
14
|
+
const informTaskIfNeeded_1 = require("./onOperationFailed/informTaskIfNeeded");
|
|
15
|
+
const USE_INFORM_TASK_RUNNING = process.env.USE_INFORM_TASK_RUNNING === '1';
|
|
16
|
+
/**
|
|
17
|
+
* タスク実行失敗時処理
|
|
18
|
+
*/
|
|
19
|
+
function onOperationFailed(params) {
|
|
20
|
+
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
let error = params.error;
|
|
22
|
+
const { task, now, next } = params;
|
|
23
|
+
if (typeof error !== 'object') {
|
|
24
|
+
error = { message: String(error) };
|
|
25
|
+
}
|
|
26
|
+
const endDate = new Date();
|
|
27
|
+
// remainingNumberOfTries<=0ならAborted(2025-08-04~)
|
|
28
|
+
const isRetryable = task.remainingNumberOfTries > 0;
|
|
29
|
+
if (isRetryable) {
|
|
30
|
+
// 実験的に実行中タスク連携
|
|
31
|
+
if (USE_INFORM_TASK_RUNNING) {
|
|
32
|
+
yield (0, informTaskIfNeeded_1.informTaskIfNeeded)({ task, executionEndDate: endDate })(repos);
|
|
33
|
+
}
|
|
34
|
+
const result = {
|
|
35
|
+
executedAt: now,
|
|
36
|
+
endDate,
|
|
37
|
+
error: Object.assign(Object.assign({}, error), { code: error.code, message: error.message, name: error.name, stack: error.stack })
|
|
38
|
+
};
|
|
39
|
+
// 失敗してもここではステータスを戻さない(Runningのまま待機)
|
|
40
|
+
yield repos.task.setExecutionResultAndStatus({
|
|
41
|
+
id: task.id,
|
|
42
|
+
remainingNumberOfTries: task.remainingNumberOfTries,
|
|
43
|
+
name: task.name
|
|
44
|
+
}, {
|
|
45
|
+
status: task.status,
|
|
46
|
+
executionResult: result
|
|
47
|
+
}, (typeof next === 'function') ? next : undefined);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
// 分析連携(2025-08-05~)
|
|
51
|
+
// 設定されたnameの場合連携する
|
|
52
|
+
// もしここで連携タスク作成に失敗したとしても、再度Readyタスクとなりリトライされて、処理は冪等となる想定
|
|
53
|
+
// 最終的に、連携タスクが作成され、実行中タスクがAbortedとなればよい
|
|
54
|
+
yield (0, informTaskIfNeeded_1.informTaskIfNeeded)({ task, executionEndDate: endDate })(repos);
|
|
55
|
+
const result = {
|
|
56
|
+
executedAt: now,
|
|
57
|
+
endDate,
|
|
58
|
+
error: Object.assign(Object.assign({}, error), { code: error.code, message: error.message, name: error.name, stack: error.stack })
|
|
59
|
+
};
|
|
60
|
+
yield repos.task.setExecutionResultAndStatus({
|
|
61
|
+
id: task.id,
|
|
62
|
+
remainingNumberOfTries: task.remainingNumberOfTries,
|
|
63
|
+
name: task.name
|
|
64
|
+
}, {
|
|
65
|
+
status: factory.taskStatus.Aborted,
|
|
66
|
+
executionResult: result
|
|
67
|
+
}, (typeof next === 'function') ? next : undefined);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { SendGridCredentials } from '../credentials/sendGrid';
|
|
2
|
+
import type { IExecuteSettings as IMinimumExecuteSettings, INextFunction } from '../eventEmitter/task';
|
|
3
|
+
import * as factory from '../factory';
|
|
4
|
+
import type { IExecutableTask, IExecutableTaskKeys } from '../repo/task';
|
|
5
|
+
import type { Settings } from '../settings';
|
|
6
|
+
import type { AggregationSettings } from '../settings/aggregation';
|
|
7
|
+
interface ICredentialSettings {
|
|
8
|
+
sendGrid: SendGridCredentials;
|
|
9
|
+
}
|
|
10
|
+
interface IExecuteSettings extends IMinimumExecuteSettings {
|
|
11
|
+
credentials: ICredentialSettings;
|
|
12
|
+
settings: Settings;
|
|
13
|
+
aggregationSettings?: AggregationSettings;
|
|
14
|
+
}
|
|
15
|
+
interface IExecuteOptions {
|
|
16
|
+
executeById: boolean;
|
|
17
|
+
executeByName: boolean;
|
|
18
|
+
}
|
|
19
|
+
type IOperationExecute<T> = (settings: IExecuteSettings, options: IExecuteOptions) => Promise<T>;
|
|
20
|
+
type ICallResult = void | Pick<factory.task.IExecutionResult, 'error'>;
|
|
21
|
+
type ICallableTaskOperation = (task: IExecutableTask<factory.taskName>) => IOperationExecute<ICallResult>;
|
|
22
|
+
/**
|
|
23
|
+
* タスクを実行する
|
|
24
|
+
*/
|
|
25
|
+
declare function executeTask(task: IExecutableTask<factory.taskName>, next?: INextFunction): IOperationExecute<void>;
|
|
26
|
+
export { ICallableTaskOperation, ICallResult, IExecutableTaskKeys, IOperationExecute, executeTask };
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.executeTask = executeTask;
|
|
13
|
+
const createDebug = require("debug");
|
|
14
|
+
const moment = require("moment");
|
|
15
|
+
const factory = require("../factory");
|
|
16
|
+
const onOperationFailed_1 = require("./taskHandler/onOperationFailed");
|
|
17
|
+
const debug = createDebug('chevre-domain:service:taskHandler');
|
|
18
|
+
/**
|
|
19
|
+
* タスクを実行する
|
|
20
|
+
*/
|
|
21
|
+
// tslint:disable-next-line:max-func-body-length
|
|
22
|
+
function executeTask(task, next) {
|
|
23
|
+
const now = new Date();
|
|
24
|
+
debug('executing an executableTask...', task, now);
|
|
25
|
+
return (settings, options) => __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const settingRepo = new (yield Promise.resolve().then(() => require('../repo/setting'))).SettingRepo(settings.connection);
|
|
27
|
+
const taskRepo = new (yield Promise.resolve().then(() => require('../repo/task'))).TaskRepo(settings.connection);
|
|
28
|
+
try {
|
|
29
|
+
// 期限検証(2024-04-23~)
|
|
30
|
+
if (task.expires instanceof Date) {
|
|
31
|
+
const taskExpired = moment(now)
|
|
32
|
+
.isAfter(task.expires);
|
|
33
|
+
if (taskExpired) {
|
|
34
|
+
throw new factory.errors.Internal(`task expired [expires:${task.expires}]`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
// remainingNumberOfTries<0ならcallを実行しない(2025-08-04~)
|
|
38
|
+
// リトライを繰り返した後、不明の原因でRunningのまま残ってしまったタスクがリトライされたケース
|
|
39
|
+
const { remainingNumberOfTries } = task;
|
|
40
|
+
const isCallable = remainingNumberOfTries >= 0;
|
|
41
|
+
if (!isCallable) {
|
|
42
|
+
throw new factory.errors.Internal(`task remainingNumberOfTries < 0 [remainingNumberOfTries:${remainingNumberOfTries}]`);
|
|
43
|
+
}
|
|
44
|
+
// タスク名の関数が定義されていなければ、TypeErrorとなる
|
|
45
|
+
let callResult;
|
|
46
|
+
const { call } = yield Promise.resolve(`${`./task/${task.name}`}`).then(s => require(s));
|
|
47
|
+
switch (task.name) {
|
|
48
|
+
case factory.taskName.AcceptCOAOffer:
|
|
49
|
+
case factory.taskName.AggregateOnSystem:
|
|
50
|
+
case factory.taskName.AuthorizePayment:
|
|
51
|
+
case factory.taskName.CancelPendingReservation:
|
|
52
|
+
case factory.taskName.CheckMovieTicket:
|
|
53
|
+
case factory.taskName.DeletePerson:
|
|
54
|
+
case factory.taskName.HandleNotification:
|
|
55
|
+
case factory.taskName.ImportEventCapacitiesFromCOA:
|
|
56
|
+
case factory.taskName.ImportEventsFromCOA:
|
|
57
|
+
case factory.taskName.ImportOffersFromCOA:
|
|
58
|
+
case factory.taskName.InvalidatePaymentUrl:
|
|
59
|
+
case factory.taskName.OnAuthorizationCreated:
|
|
60
|
+
case factory.taskName.Pay:
|
|
61
|
+
case factory.taskName.PublishPaymentUrl:
|
|
62
|
+
case factory.taskName.Refund:
|
|
63
|
+
case factory.taskName.VoidPayTransaction:
|
|
64
|
+
case factory.taskName.VoidReserveTransaction:
|
|
65
|
+
case factory.taskName.ConfirmReserveTransaction:
|
|
66
|
+
case factory.taskName.ReturnPayTransaction:
|
|
67
|
+
case factory.taskName.ReturnReserveTransaction:
|
|
68
|
+
case factory.taskName.SendEmailMessage:
|
|
69
|
+
case factory.taskName.TriggerWebhook:
|
|
70
|
+
callResult = yield call(task)(settings, options);
|
|
71
|
+
break;
|
|
72
|
+
default:
|
|
73
|
+
yield call(task.data)(settings);
|
|
74
|
+
}
|
|
75
|
+
const result = {
|
|
76
|
+
executedAt: now,
|
|
77
|
+
endDate: new Date(),
|
|
78
|
+
// enable overwriting task.executionResults.error on Executed(2024-05-29~)
|
|
79
|
+
error: ((callResult === null || callResult === void 0 ? void 0 : callResult.error) instanceof Error)
|
|
80
|
+
? Object.assign(Object.assign({}, callResult.error), { message: callResult.error.message }) : ''
|
|
81
|
+
};
|
|
82
|
+
yield taskRepo.setExecutionResultAndStatus({
|
|
83
|
+
id: task.id,
|
|
84
|
+
remainingNumberOfTries,
|
|
85
|
+
name: task.name
|
|
86
|
+
}, {
|
|
87
|
+
status: factory.taskStatus.Executed,
|
|
88
|
+
executionResult: result
|
|
89
|
+
}, (typeof next === 'function') ? next : undefined);
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
debug('service.task.execute throwed an error. task:', task.name, task.id, 'error:', error === null || error === void 0 ? void 0 : error.name, error === null || error === void 0 ? void 0 : error.message);
|
|
93
|
+
yield (0, onOperationFailed_1.onOperationFailed)(Object.assign({ task, now, error }, (typeof next === 'function') ? { next } : undefined))({ setting: settingRepo, task: taskRepo });
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|