@chevre/domain 26.0.0-alpha.3 → 26.0.0-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,32 @@
1
+ import type { Connection } from 'mongoose';
2
+ import { factory } from '../factory';
3
+ interface IAggregationByStatus {
4
+ taskCount: number;
5
+ avgLatency: number;
6
+ maxLatency: number;
7
+ minLatency: number;
8
+ percentilesLatency: {
9
+ name: string;
10
+ value: number;
11
+ }[];
12
+ }
13
+ interface IStatus {
14
+ status: factory.taskStatus;
15
+ aggregation: IAggregationByStatus;
16
+ }
17
+ interface IAggregateTask {
18
+ statuses: IStatus[];
19
+ }
20
+ /**
21
+ * 予定タスク集計リポジトリ
22
+ */
23
+ export declare class AggregateScheduledTaskRepo {
24
+ private readonly scheduledTaskModel;
25
+ constructor(connection: Connection);
26
+ aggregateScheduledTask(params: {
27
+ runsFrom: Date;
28
+ runsThrough: Date;
29
+ }): Promise<IAggregateTask>;
30
+ private agggregateByStatus;
31
+ }
32
+ export {};
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AggregateScheduledTaskRepo = void 0;
4
+ const factory_1 = require("../factory");
5
+ const scheduledTasks_1 = require("./mongoose/schemas/scheduledTasks");
6
+ /**
7
+ * 予定タスク集計リポジトリ
8
+ */
9
+ class AggregateScheduledTaskRepo {
10
+ scheduledTaskModel;
11
+ constructor(connection) {
12
+ this.scheduledTaskModel = connection.model(scheduledTasks_1.modelName, (0, scheduledTasks_1.createSchema)());
13
+ }
14
+ async aggregateScheduledTask(params) {
15
+ const statuses = await Promise.all([
16
+ factory_1.factory.taskStatus.Executed,
17
+ factory_1.factory.taskStatus.Aborted
18
+ ].map(async (taskStatus) => {
19
+ const matchConditions = {
20
+ status: { $eq: taskStatus },
21
+ runsAt: {
22
+ $gte: params.runsFrom,
23
+ $lte: params.runsThrough
24
+ },
25
+ // ...(typeof params.project?.id?.$ne === 'string')
26
+ // ? { 'project.id': { $ne: params.project.id.$ne } }
27
+ // : undefined
28
+ };
29
+ return this.agggregateByStatus({ matchConditions, status: taskStatus });
30
+ }));
31
+ return { statuses };
32
+ }
33
+ async agggregateByStatus(params) {
34
+ const matchConditions = params.matchConditions;
35
+ const taskStatus = params.status;
36
+ const aggregate1 = this.scheduledTaskModel.aggregate([
37
+ {
38
+ $match: matchConditions
39
+ },
40
+ {
41
+ $project: {
42
+ latency: { $subtract: ['$lastTriedAt', '$runsAt'] },
43
+ status: '$status',
44
+ runsAt: '$runsAt',
45
+ lastTriedAt: '$lastTriedAt'
46
+ }
47
+ },
48
+ {
49
+ $group: {
50
+ _id: '$status',
51
+ taskCount: { $sum: 1 },
52
+ maxLatency: { $max: '$latency' },
53
+ minLatency: { $min: '$latency' },
54
+ avgLatency: { $avg: '$latency' }
55
+ }
56
+ },
57
+ {
58
+ $project: {
59
+ _id: 0,
60
+ taskCount: '$taskCount',
61
+ avgLatency: '$avgLatency',
62
+ maxLatency: '$maxLatency',
63
+ minLatency: '$minLatency'
64
+ }
65
+ }
66
+ ]);
67
+ // const explainResult = await aggregate1.explain();
68
+ // console.dir(explainResult, { depth: null });
69
+ // return;
70
+ const aggregations = await aggregate1.exec();
71
+ const percents = [50, 95, 99];
72
+ if (aggregations.length === 0) {
73
+ return {
74
+ status: taskStatus,
75
+ aggregation: {
76
+ taskCount: 0,
77
+ avgLatency: 0,
78
+ maxLatency: 0,
79
+ minLatency: 0,
80
+ percentilesLatency: percents.map((percent) => {
81
+ return {
82
+ name: String(percent),
83
+ value: 0
84
+ };
85
+ })
86
+ }
87
+ };
88
+ }
89
+ const ranks4percentile = percents.map((percentile) => {
90
+ return {
91
+ percentile,
92
+ rank: Math.floor(aggregations[0].taskCount * percentile / 100)
93
+ };
94
+ });
95
+ const aggregate2 = this.scheduledTaskModel.aggregate([
96
+ {
97
+ $match: matchConditions
98
+ },
99
+ {
100
+ $project: {
101
+ latency: { $subtract: ['$lastTriedAt', '$runsAt'] },
102
+ status: '$status',
103
+ runsAt: '$runsAt',
104
+ lastTriedAt: '$lastTriedAt'
105
+ }
106
+ },
107
+ { $sort: { latency: 1 } },
108
+ {
109
+ $group: {
110
+ _id: '$status',
111
+ latencies: { $push: '$latency' }
112
+ }
113
+ },
114
+ {
115
+ $project: {
116
+ _id: 0,
117
+ percentilesLatency: ranks4percentile.map((rank) => {
118
+ return {
119
+ name: String(rank.percentile),
120
+ value: { $arrayElemAt: ['$latencies', rank.rank] }
121
+ };
122
+ })
123
+ }
124
+ }
125
+ ]);
126
+ const aggregations2 = await aggregate2.exec();
127
+ return {
128
+ status: taskStatus,
129
+ aggregation: {
130
+ ...aggregations[0],
131
+ ...aggregations2[0]
132
+ }
133
+ };
134
+ }
135
+ }
136
+ exports.AggregateScheduledTaskRepo = AggregateScheduledTaskRepo;
@@ -32,6 +32,8 @@ interface IOnEventChanged {
32
32
  informEvent2agg?: factory.project.IInformParams[];
33
33
  }
34
34
  export interface IStorageSettings {
35
+ useScheduledDeleteTransactionTask?: boolean;
36
+ deleteTransactionTaskExpiresInDays?: number;
35
37
  /**
36
38
  * 取引保管期間(Confirmed)
37
39
  * default:365
@@ -5,7 +5,7 @@ type ICreatingTaskKeys = 'data' | 'executionResults' | 'name' | 'numberOfTried'
5
5
  /**
6
6
  * リトライ可能なタスク作成属性
7
7
  */
8
- type ICreatingTask = (Pick<factory.task.importEventCapacitiesFromCOA.IAttributes, ICreatingTaskKeys> | Pick<factory.task.importEventsFromCOA.IAttributes, ICreatingTaskKeys>) & {
8
+ type ICreatingTask = (Pick<factory.task.importEventCapacitiesFromCOA.IAttributes, ICreatingTaskKeys> | Pick<factory.task.importEventsFromCOA.IAttributes, ICreatingTaskKeys> | Pick<factory.task.deleteTransaction.IAttributes, ICreatingTaskKeys>) & {
9
9
  expires: Date;
10
10
  };
11
11
  /**
@@ -24,6 +24,7 @@ import type { AggregateActionRepo } from './repo/aggregateAction';
24
24
  import type { AggregateOfferRepo } from './repo/aggregateOffer';
25
25
  import type { AggregateOrderRepo } from './repo/aggregateOrder';
26
26
  import type { AggregateReservationRepo } from './repo/aggregateReservation';
27
+ import type { AggregateScheduledTaskRepo } from './repo/aggregateScheduledTask';
27
28
  import type { AggregateTaskRepo } from './repo/aggregateTask';
28
29
  import type { AggregationRepo } from './repo/aggregation';
29
30
  import type { AssetTransactionRepo } from './repo/assetTransaction';
@@ -180,6 +181,10 @@ export type AggregateAction = AggregateActionRepo;
180
181
  export declare namespace AggregateAction {
181
182
  function createInstance(...params: ConstructorParameters<typeof AggregateActionRepo>): Promise<AggregateActionRepo>;
182
183
  }
184
+ export type AggregateScheduledTask = AggregateScheduledTaskRepo;
185
+ export declare namespace AggregateScheduledTask {
186
+ function createInstance(...params: ConstructorParameters<typeof AggregateScheduledTaskRepo>): Promise<AggregateScheduledTaskRepo>;
187
+ }
183
188
  export type AggregateTask = AggregateTaskRepo;
184
189
  export declare namespace AggregateTask {
185
190
  function createInstance(...params: ConstructorParameters<typeof AggregateTaskRepo>): Promise<AggregateTaskRepo>;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PaymentServiceChannel = exports.PaymentService = exports.Passport = exports.OwnershipInfo = exports.OrderNumber = exports.OrderInTransaction = exports.Order = exports.Offer = exports.OfferItemCondition = exports.OfferCatalogItem = exports.OfferCatalog = exports.NoteAboutOrder = exports.Note = exports.MovieTicketType = exports.Message = exports.MerchantReturnPolicy = exports.MemberProgram = exports.Member = exports.Issuer = exports.IdentityProvider = exports.Identity = exports.EventSeries = exports.EventSellerMakesOffer = exports.EventOffer = exports.Event = exports.EmailMessage = exports.CustomerType = exports.Customer = exports.Credentials = exports.CreativeWork = exports.ConfirmationNumber = exports.Authorization = exports.CategoryCode = exports.assetTransaction = exports.AssetTransaction = exports.Aggregation = exports.AggregateReservation = exports.AggregateOrder = exports.AggregateOffer = exports.AggregateTask = exports.AggregateAction = exports.AdminTask = exports.AdminScheduledTask = exports.AdminAsyncAction = exports.AdditionalProperty = exports.action = exports.Action = exports.AccountTitle = exports.AccountingReport = exports.AcceptedOffer = void 0;
4
- exports.WebSite = exports.rateLimit = exports.TransactionProcess = exports.TransactionNumber = exports.transaction = exports.Transaction = exports.Ticket = exports.AsyncAction = exports.Task = exports.ScheduledTask = exports.StockHolder = exports.setting = exports.Setting = exports.ServiceAvailableHour = exports.SellerReturnPolicy = exports.SellerPaymentAccepted = exports.SellerMakesOffer = exports.Seller = exports.Schedule = exports.Role = exports.ReserveInterface = exports.Reservation = exports.ProjectMakesOffer = exports.Project = exports.ProductHasOfferCatalog = exports.Product = exports.PriceSpecification = exports.PotentialAction = exports.place = exports.Person = exports.PendingReservation = exports.PaymentServiceProvider = void 0;
3
+ exports.PaymentService = exports.Passport = exports.OwnershipInfo = exports.OrderNumber = exports.OrderInTransaction = exports.Order = exports.Offer = exports.OfferItemCondition = exports.OfferCatalogItem = exports.OfferCatalog = exports.NoteAboutOrder = exports.Note = exports.MovieTicketType = exports.Message = exports.MerchantReturnPolicy = exports.MemberProgram = exports.Member = exports.Issuer = exports.IdentityProvider = exports.Identity = exports.EventSeries = exports.EventSellerMakesOffer = exports.EventOffer = exports.Event = exports.EmailMessage = exports.CustomerType = exports.Customer = exports.Credentials = exports.CreativeWork = exports.ConfirmationNumber = exports.Authorization = exports.CategoryCode = exports.assetTransaction = exports.AssetTransaction = exports.Aggregation = exports.AggregateReservation = exports.AggregateOrder = exports.AggregateOffer = exports.AggregateTask = exports.AggregateScheduledTask = exports.AggregateAction = exports.AdminTask = exports.AdminScheduledTask = exports.AdminAsyncAction = exports.AdditionalProperty = exports.action = exports.Action = exports.AccountTitle = exports.AccountingReport = exports.AcceptedOffer = void 0;
4
+ exports.WebSite = exports.rateLimit = exports.TransactionProcess = exports.TransactionNumber = exports.transaction = exports.Transaction = exports.Ticket = exports.AsyncAction = exports.Task = exports.ScheduledTask = exports.StockHolder = exports.setting = exports.Setting = exports.ServiceAvailableHour = exports.SellerReturnPolicy = exports.SellerPaymentAccepted = exports.SellerMakesOffer = exports.Seller = exports.Schedule = exports.Role = exports.ReserveInterface = exports.Reservation = exports.ProjectMakesOffer = exports.Project = exports.ProductHasOfferCatalog = exports.Product = exports.PriceSpecification = exports.PotentialAction = exports.place = exports.Person = exports.PendingReservation = exports.PaymentServiceProvider = exports.PaymentServiceChannel = void 0;
5
5
  var AcceptedOffer;
6
6
  (function (AcceptedOffer) {
7
7
  let repo;
@@ -214,6 +214,17 @@ var AggregateAction;
214
214
  }
215
215
  AggregateAction.createInstance = createInstance;
216
216
  })(AggregateAction || (exports.AggregateAction = AggregateAction = {}));
217
+ var AggregateScheduledTask;
218
+ (function (AggregateScheduledTask) {
219
+ let repo;
220
+ async function createInstance(...params) {
221
+ if (repo === undefined) {
222
+ repo = (await import('./repo/aggregateScheduledTask.js')).AggregateScheduledTaskRepo;
223
+ }
224
+ return new repo(...params);
225
+ }
226
+ AggregateScheduledTask.createInstance = createInstance;
227
+ })(AggregateScheduledTask || (exports.AggregateScheduledTask = AggregateScheduledTask = {}));
217
228
  var AggregateTask;
218
229
  (function (AggregateTask) {
219
230
  let repo;
@@ -1,4 +1,5 @@
1
1
  import type { AggregateActionRepo } from '../../repo/aggregateAction';
2
+ import type { AggregateScheduledTaskRepo } from '../../repo/aggregateScheduledTask';
2
3
  import type { AggregateTaskRepo } from '../../repo/aggregateTask';
3
4
  import { AggregationRepo } from '../../repo/aggregation';
4
5
  import type { AssetTransactionRepo } from '../../repo/assetTransaction';
@@ -10,7 +11,7 @@ interface IAggregateParams {
10
11
  aggregateDate: Date;
11
12
  aggregateDurationUnit: AggregateDurationUnit;
12
13
  aggregationCount: number;
13
- excludedProjectId?: string;
14
+ excludedProjectId?: never;
14
15
  }
15
16
  declare function aggregateEvent(params: IAggregateParams): (repos: {
16
17
  agregation: AggregationRepo;
@@ -146,4 +147,11 @@ declare function aggregateTask(params: IAggregateParams): (repos: {
146
147
  aggregationCount: number;
147
148
  aggregateDuration: string;
148
149
  }>;
149
- export { aggregateAuthorizeEventServiceOfferAction, aggregateAuthorizeOrderAction, aggregateAuthorizePaymentAction, aggregateCancelReservationAction, aggregateCheckMovieTicketAction, aggregateEvent, aggregateOrder, aggregateOrderAction, aggregatePayMovieTicketAction, aggregatePayTransaction, aggregatePlaceOrder, aggregateReserveAction, aggregateReserveTransaction, aggregateTask, aggregateUseAction };
150
+ declare function aggregateScheduledTask(params: IAggregateParams): (repos: {
151
+ agregation: AggregationRepo;
152
+ aggregateScheduledTask: AggregateScheduledTaskRepo;
153
+ }) => Promise<{
154
+ aggregationCount: number;
155
+ aggregateDuration: string;
156
+ }>;
157
+ export { aggregateAuthorizeEventServiceOfferAction, aggregateAuthorizeOrderAction, aggregateAuthorizePaymentAction, aggregateCancelReservationAction, aggregateCheckMovieTicketAction, aggregateEvent, aggregateOrder, aggregateOrderAction, aggregatePayMovieTicketAction, aggregatePayTransaction, aggregatePlaceOrder, aggregateReserveAction, aggregateReserveTransaction, aggregateTask, aggregateScheduledTask, aggregateUseAction };
@@ -17,6 +17,7 @@ exports.aggregatePlaceOrder = aggregatePlaceOrder;
17
17
  exports.aggregateReserveAction = aggregateReserveAction;
18
18
  exports.aggregateReserveTransaction = aggregateReserveTransaction;
19
19
  exports.aggregateTask = aggregateTask;
20
+ exports.aggregateScheduledTask = aggregateScheduledTask;
20
21
  exports.aggregateUseAction = aggregateUseAction;
21
22
  const debug_1 = __importDefault(require("debug"));
22
23
  const moment_timezone_1 = __importDefault(require("moment-timezone"));
@@ -692,3 +693,44 @@ function aggregateTask(params) {
692
693
  return { aggregationCount: i, aggregateDuration };
693
694
  };
694
695
  }
696
+ function aggregateScheduledTask(params) {
697
+ return async (repos) => {
698
+ const { aggregateDate } = params;
699
+ if (!(aggregateDate instanceof Date)) {
700
+ throw new factory_1.factory.errors.Argument('aggregateDate', 'must be Date');
701
+ }
702
+ const aggregateDuration = moment_timezone_1.default.duration(1, params.aggregateDurationUnit)
703
+ .toISOString();
704
+ let i = -1;
705
+ while (i < params.aggregationCount) {
706
+ i += 1;
707
+ const runsFrom = (0, moment_timezone_1.default)(aggregateDate)
708
+ .utc()
709
+ // .tz('Asia/Tokyo')
710
+ .add(-i, params.aggregateDurationUnit)
711
+ .startOf(params.aggregateDurationUnit)
712
+ .toDate();
713
+ const runsThrough = (0, moment_timezone_1.default)(aggregateDate)
714
+ .utc()
715
+ // .tz('Asia/Tokyo')
716
+ .add(-i, params.aggregateDurationUnit)
717
+ .endOf(params.aggregateDurationUnit)
718
+ .toDate();
719
+ const aggregateResult = await repos.aggregateScheduledTask.aggregateScheduledTask({
720
+ // project: { id: { $ne: params.excludedProjectId } },
721
+ runsFrom,
722
+ runsThrough
723
+ });
724
+ await repos.agregation.saveAggregation({
725
+ typeOf: factory_1.factory.aggregation.AggregationType.AggregateScheduledTask,
726
+ project: { id: '*', typeOf: factory_1.factory.organizationType.Project },
727
+ aggregateDuration,
728
+ aggregateStart: runsFrom,
729
+ aggregateDate,
730
+ ...aggregateResult
731
+ });
732
+ }
733
+ debug(i, 'aggregations saved');
734
+ return { aggregationCount: i, aggregateDuration };
735
+ };
736
+ }
@@ -1,11 +1,15 @@
1
1
  import { factory } from '../../../../factory';
2
2
  import type { ISetting } from '../../../../repo/setting';
3
- type IPlaceOrderPotentialTask = factory.task.IAttributes<factory.taskName.PlaceOrder> | factory.task.deleteTransaction.IAttributes | factory.task.IAttributes<factory.taskName.VoidPayTransaction> | factory.task.voidReserveTransaction.IAttributes;
3
+ type IPlaceOrderPotentialTask = factory.task.IAttributes<factory.taskName.PlaceOrder> | factory.task.IAttributes<factory.taskName.VoidPayTransaction> | factory.task.voidReserveTransaction.IAttributes;
4
4
  /**
5
5
  * 取引のタスクを作成する
6
+ * 取引削除タスクを分離(2026-08-02~)
6
7
  */
7
- export declare function createTasks(params: {
8
+ export declare function createImmediateTasks(params: {
8
9
  transaction: Pick<factory.transaction.ITransaction<factory.transactionType.PlaceOrder>, 'endDate' | 'id' | 'object' | 'project' | 'seller' | 'startDate' | 'status' | 'typeOf'>;
9
- runsAt: Date;
10
- }, setting: Pick<ISetting, 'storage'> | null): IPlaceOrderPotentialTask[];
10
+ taskRunsAt: Date;
11
+ }): IPlaceOrderPotentialTask[];
12
+ export declare function createScheduledTasks(params: {
13
+ transaction: Pick<factory.transaction.ITransaction<factory.transactionType.PlaceOrder>, 'endDate' | 'id' | 'object' | 'project' | 'status' | 'typeOf'>;
14
+ }, setting: Pick<ISetting, 'storage'> | null): factory.task.deleteTransaction.IAttributes;
11
15
  export {};
@@ -3,114 +3,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createTasks = createTasks;
6
+ exports.createImmediateTasks = createImmediateTasks;
7
+ exports.createScheduledTasks = createScheduledTasks;
7
8
  const moment_1 = __importDefault(require("moment"));
8
9
  const factory_1 = require("../../../../factory");
9
10
  /**
10
11
  * 取引のタスクを作成する
12
+ * 取引削除タスクを分離(2026-08-02~)
11
13
  */
12
- function createTasks(params, setting) {
14
+ function createImmediateTasks(params) {
13
15
  const taskAttributes = [];
14
16
  const transaction = params.transaction;
15
- const taskRunsAt = params.runsAt;
17
+ const taskRunsAt = params.taskRunsAt;
16
18
  // 取引通知は廃止(2026-06-29~)
17
- // const informTransaction = setting?.onTransactionStatusChanged?.informTransaction;
18
- // const transactionWebhookUrls = (Array.isArray(informTransaction)) ? informTransaction : [];
19
- // const triggerWebhookTaskAttributes: factory.task.IAttributes<factory.taskName.TriggerWebhook>[] = [];
20
- // transactionWebhookUrls.forEach(({ recipient }) => {
21
- // if (typeof recipient?.url === 'string') {
22
- // const informObject: factory.notification.transaction.IPlaceOrderAsNotification = {
23
- // id: transaction.id,
24
- // typeOf: transaction.typeOf,
25
- // project: transaction.project,
26
- // seller: transaction.seller,
27
- // startDate: transaction.startDate,
28
- // status: transaction.status,
29
- // ...(transaction.endDate !== undefined) ? { endDate: transaction.endDate } : undefined
30
- // };
31
- // const data: factory.task.triggerWebhook.IInformAnyResourceAction = {
32
- // object: informObject,
33
- // recipient: {
34
- // id: (typeof recipient?.id === 'string') ? recipient.id : '',
35
- // name: recipient?.name,
36
- // typeOf: factory.creativeWorkType.WebApplication
37
- // // url: recipient.url // discontinue(2025-02-13~)
38
- // },
39
- // target: {
40
- // httpMethod: 'POST',
41
- // encodingType: factory.encodingFormat.Application.json,
42
- // typeOf: 'EntryPoint',
43
- // urlTemplate: recipient.url
44
- // }
45
- // };
46
- // triggerWebhookTaskAttributes.push({
47
- // project: transaction.project,
48
- // name: factory.taskName.TriggerWebhook,
49
- // status: factory.taskStatus.Ready,
50
- // runsAt: taskRunsAt,
51
- // remainingNumberOfTries: 3,
52
- // numberOfTried: 0,
53
- // executionResults: [],
54
- // data
55
- // });
56
- // }
57
- // });
58
- const confirmedStoragePeriodInDays = setting?.storage?.transactionConfirmedInDays;
59
- const canceledStoragePeriodInDays = setting?.storage?.transactionCanceledInDays;
60
- if (typeof confirmedStoragePeriodInDays !== 'number') {
61
- throw new factory_1.factory.errors.NotFound('setting.storage.confirmedStoragePeriodInDays');
62
- }
63
- if (typeof canceledStoragePeriodInDays !== 'number') {
64
- throw new factory_1.factory.errors.NotFound('setting.storage.canceledStoragePeriodInDays');
65
- }
66
- // 取引削除タスクを作成(取引ステータスによってrunsAtを調整)
67
- // let deleteAt = moment(transaction.endDate)
68
- // .add(settings.transaction.confirmedStoragePeriodInDays, 'days')
69
- // .toDate();
70
- let deleteAt = (0, moment_1.default)(transaction.endDate)
71
- .add(confirmedStoragePeriodInDays, 'days')
72
- .toDate();
73
- switch (transaction.status) {
74
- case factory_1.factory.transactionStatusType.Confirmed:
75
- break;
76
- case factory_1.factory.transactionStatusType.Canceled:
77
- case factory_1.factory.transactionStatusType.Expired:
78
- // deleteAt = moment(transaction.endDate)
79
- // .add(settings.transaction.canceledStoragePeriodInDays, 'days')
80
- // .toDate();
81
- deleteAt = (0, moment_1.default)(transaction.endDate)
82
- .add(canceledStoragePeriodInDays, 'days')
83
- .toDate();
84
- break;
85
- default:
86
- }
87
- const deleteTransactionTask = {
88
- project: transaction.project,
89
- name: factory_1.factory.taskName.DeleteTransaction,
90
- status: factory_1.factory.taskStatus.Ready,
91
- runsAt: deleteAt,
92
- remainingNumberOfTries: 3,
93
- numberOfTried: 0,
94
- executionResults: [],
95
- data: {
96
- object: {
97
- specifyingMethod: factory_1.factory.action.update.deleteAction.ObjectAsTransactionSpecifyingMethod.Id,
98
- id: transaction.id,
99
- object: {
100
- ...(typeof transaction.object.confirmationNumber === 'string')
101
- ? { confirmationNumber: transaction.object.confirmationNumber }
102
- : undefined,
103
- ...(typeof transaction.object.orderNumber === 'string')
104
- ? { orderNumber: transaction.object.orderNumber }
105
- : undefined
106
- },
107
- // project: transaction.project,
108
- // startDate: transaction.startDate,
109
- typeOf: transaction.typeOf,
110
- // ...(transaction.endDate !== undefined) ? { endDate: transaction.endDate } : undefined
111
- }
112
- }
113
- };
114
19
  // 確定取引にも興行オファー承認中止タスクを追加(2023-05-09~)
115
20
  const voidReserveTaskAttributes = {
116
21
  project: transaction.project,
@@ -121,7 +26,6 @@ function createTasks(params, setting) {
121
26
  numberOfTried: 0,
122
27
  executionResults: [],
123
28
  data: {
124
- // project: transaction.project, // discontinue(2025-03-12~)
125
29
  purpose: { typeOf: transaction.typeOf, id: transaction.id }
126
30
  }
127
31
  };
@@ -135,11 +39,9 @@ function createTasks(params, setting) {
135
39
  numberOfTried: 0,
136
40
  executionResults: [],
137
41
  data: {
138
- // project: transaction.project, // discontinue(2025-03-12~)
139
42
  purpose: { typeOf: transaction.typeOf, id: transaction.id }
140
43
  }
141
44
  };
142
- taskAttributes.push(deleteTransactionTask);
143
45
  switch (transaction.status) {
144
46
  case factory_1.factory.transactionStatusType.Confirmed: {
145
47
  taskAttributes.push(voidReserveTaskAttributes, voidPaymentTaskAttributes);
@@ -188,3 +90,53 @@ function createTasks(params, setting) {
188
90
  }
189
91
  return taskAttributes;
190
92
  }
93
+ function createScheduledTasks(params, setting) {
94
+ const transaction = params.transaction;
95
+ const confirmedStoragePeriodInDays = setting?.storage?.transactionConfirmedInDays;
96
+ const canceledStoragePeriodInDays = setting?.storage?.transactionCanceledInDays;
97
+ if (typeof confirmedStoragePeriodInDays !== 'number') {
98
+ throw new factory_1.factory.errors.NotFound('setting.storage.confirmedStoragePeriodInDays');
99
+ }
100
+ if (typeof canceledStoragePeriodInDays !== 'number') {
101
+ throw new factory_1.factory.errors.NotFound('setting.storage.canceledStoragePeriodInDays');
102
+ }
103
+ // 取引削除タスクを作成(取引ステータスによってrunsAtを調整)
104
+ let deleteAt = (0, moment_1.default)(transaction.endDate)
105
+ .add(confirmedStoragePeriodInDays, 'days')
106
+ .toDate();
107
+ switch (transaction.status) {
108
+ case factory_1.factory.transactionStatusType.Confirmed:
109
+ break;
110
+ case factory_1.factory.transactionStatusType.Canceled:
111
+ case factory_1.factory.transactionStatusType.Expired:
112
+ deleteAt = (0, moment_1.default)(transaction.endDate)
113
+ .add(canceledStoragePeriodInDays, 'days')
114
+ .toDate();
115
+ break;
116
+ default:
117
+ }
118
+ return {
119
+ project: transaction.project,
120
+ name: factory_1.factory.taskName.DeleteTransaction,
121
+ status: factory_1.factory.taskStatus.Ready,
122
+ runsAt: deleteAt,
123
+ remainingNumberOfTries: 3,
124
+ numberOfTried: 0,
125
+ executionResults: [],
126
+ data: {
127
+ object: {
128
+ specifyingMethod: factory_1.factory.action.update.deleteAction.ObjectAsTransactionSpecifyingMethod.Id,
129
+ id: transaction.id,
130
+ object: {
131
+ ...(typeof transaction.object.confirmationNumber === 'string')
132
+ ? { confirmationNumber: transaction.object.confirmationNumber }
133
+ : undefined,
134
+ ...(typeof transaction.object.orderNumber === 'string')
135
+ ? { orderNumber: transaction.object.orderNumber }
136
+ : undefined
137
+ },
138
+ typeOf: transaction.typeOf,
139
+ }
140
+ }
141
+ };
142
+ }
@@ -1,8 +1,10 @@
1
1
  import type { SettingRepo } from '../../../repo/setting';
2
+ import type { ScheduledTaskRepo } from '../../../repo/scheduledTask';
2
3
  import type { TaskRepo } from '../../../repo/task';
3
4
  import type { PlaceOrderRepo } from '../../../repo/transaction/placeOrder';
4
5
  interface IExportTasksByIdRepos {
5
6
  setting: SettingRepo;
7
+ scheduledTask: ScheduledTaskRepo;
6
8
  task: TaskRepo;
7
9
  placeOrder: PlaceOrderRepo;
8
10
  }
@@ -11,9 +11,7 @@ const factory_2 = require("./exportTasks/factory");
11
11
  * 取引のタスクを出力します
12
12
  */
13
13
  function exportTasksById(params) {
14
- return async (repos
15
- // settings: Settings
16
- ) => {
14
+ return async (repos) => {
17
15
  const transaction = await repos.placeOrder.findPlaceOrderById({
18
16
  typeOf: factory_1.factory.transactionType.PlaceOrder,
19
17
  id: params.id
@@ -27,12 +25,24 @@ function exportTasksById(params) {
27
25
  }
28
26
  // search settings
29
27
  const setting = await repos.setting.findOne({ project: { id: { $eq: '*' } } }, ['storage']);
30
- const taskAttributes = (0, factory_2.createTasks)({
31
- transaction,
32
- runsAt: taskRunsAt
33
- }, setting
34
- // settings
35
- );
36
- await repos.task.saveMany(taskAttributes);
28
+ const useScheduledDeleteTransactionTask = setting?.storage?.useScheduledDeleteTransactionTask === true;
29
+ const deleteTransactionTaskExpiresInDays = setting?.storage?.deleteTransactionTaskExpiresInDays;
30
+ const deleteTask = (0, factory_2.createScheduledTasks)({ transaction }, setting);
31
+ if (useScheduledDeleteTransactionTask && typeof deleteTransactionTaskExpiresInDays === 'number' && deleteTransactionTaskExpiresInDays > 0) {
32
+ // support scheduledTask(2026-08-02~)
33
+ await repos.task.saveMany((0, factory_2.createImmediateTasks)({ transaction, taskRunsAt }));
34
+ await repos.scheduledTask.addScheduledTasks([{
35
+ ...deleteTask,
36
+ expires: (0, moment_1.default)(deleteTask.runsAt)
37
+ .add(deleteTransactionTaskExpiresInDays, 'days')
38
+ .toDate()
39
+ }]);
40
+ }
41
+ else {
42
+ await repos.task.saveMany([
43
+ ...(0, factory_2.createImmediateTasks)({ transaction, taskRunsAt }),
44
+ deleteTask
45
+ ]);
46
+ }
37
47
  };
38
48
  }
@@ -1,9 +1,19 @@
1
1
  import type { ISetting } from '../../../../repo/setting';
2
2
  import { factory } from '../../../../factory';
3
+ type IReturnOrderPotentialTask = factory.task.IAttributes<factory.taskName.ReturnOrder>;
3
4
  /**
4
5
  * 取引のタスクを作成する
6
+ * 取引削除タスクを分離(2026-08-02~)
5
7
  */
6
- export declare function createTasks(params: {
8
+ export declare function createImmediateTasks(params: {
7
9
  transaction: Pick<factory.transaction.ITransaction<factory.transactionType.ReturnOrder>, 'endDate' | 'status' | 'id' | 'project' | 'typeOf' | 'startDate' | 'object' | 'potentialActions'>;
8
- runsAt: Date;
9
- }, setting: Pick<ISetting, 'storage'> | null): factory.task.IAttributes<factory.taskName>[];
10
+ taskRunsAt: Date;
11
+ }): IReturnOrderPotentialTask[];
12
+ /**
13
+ * 取引のタスクを作成する
14
+ * 取引削除タスクを分離(2026-08-02~)
15
+ */
16
+ export declare function createScheduledTasks(params: {
17
+ transaction: Pick<factory.transaction.ITransaction<factory.transactionType.ReturnOrder>, 'endDate' | 'status' | 'id' | 'project' | 'typeOf' | 'object'>;
18
+ }, setting: Pick<ISetting, 'storage'> | null): factory.task.deleteTransaction.IAttributes;
19
+ export {};
@@ -3,18 +3,60 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createTasks = createTasks;
6
+ exports.createImmediateTasks = createImmediateTasks;
7
+ exports.createScheduledTasks = createScheduledTasks;
7
8
  const moment_1 = __importDefault(require("moment"));
8
9
  const factory_1 = require("../../../../factory");
9
10
  /**
10
11
  * 取引のタスクを作成する
12
+ * 取引削除タスクを分離(2026-08-02~)
11
13
  */
12
- function createTasks(params, setting
13
- // settings: Settings
14
- ) {
14
+ function createImmediateTasks(params) {
15
15
  const taskAttributes = [];
16
16
  const transaction = params.transaction;
17
- const taskRunsAt = params.runsAt;
17
+ const taskRunsAt = params.taskRunsAt;
18
+ switch (transaction.status) {
19
+ case factory_1.factory.transactionStatusType.Confirmed: {
20
+ const returnOrderPotentialActions = transaction.potentialActions?.returnOrder;
21
+ if (Array.isArray(returnOrderPotentialActions)) {
22
+ // 返品タスク
23
+ const returnOrderTask = returnOrderPotentialActions.map((r) => {
24
+ // data最適化(2023-08-22~)
25
+ const returnOrderTaskData = {
26
+ agent: r.agent,
27
+ object: r.object,
28
+ project: transaction.project,
29
+ typeOf: r.typeOf
30
+ };
31
+ return {
32
+ project: transaction.project,
33
+ name: factory_1.factory.taskName.ReturnOrder,
34
+ status: factory_1.factory.taskStatus.Ready,
35
+ runsAt: taskRunsAt,
36
+ remainingNumberOfTries: 10,
37
+ numberOfTried: 0,
38
+ executionResults: [],
39
+ data: returnOrderTaskData
40
+ };
41
+ });
42
+ taskAttributes.push(...returnOrderTask);
43
+ }
44
+ break;
45
+ }
46
+ case factory_1.factory.transactionStatusType.Expired:
47
+ // 特にタスクなし
48
+ break;
49
+ default:
50
+ throw new factory_1.factory.errors.NotImplemented(`Transaction status "${transaction.status}" not implemented.`);
51
+ }
52
+ return taskAttributes;
53
+ }
54
+ /**
55
+ * 取引のタスクを作成する
56
+ * 取引削除タスクを分離(2026-08-02~)
57
+ */
58
+ function createScheduledTasks(params, setting) {
59
+ const transaction = params.transaction;
18
60
  const confirmedStoragePeriodInDays = setting?.storage?.transactionConfirmedInDays;
19
61
  const canceledStoragePeriodInDays = setting?.storage?.transactionCanceledInDays;
20
62
  if (typeof confirmedStoragePeriodInDays !== 'number') {
@@ -24,9 +66,6 @@ function createTasks(params, setting
24
66
  throw new factory_1.factory.errors.NotFound('setting.storage.canceledStoragePeriodInDays');
25
67
  }
26
68
  // 取引削除タスクを作成(取引ステータスによってrunsAtを調整)
27
- // let deleteAt = moment(transaction.endDate)
28
- // .add(settings.transaction.confirmedStoragePeriodInDays, 'days')
29
- // .toDate();
30
69
  let deleteAt = (0, moment_1.default)(transaction.endDate)
31
70
  .add(confirmedStoragePeriodInDays, 'days')
32
71
  .toDate();
@@ -35,16 +74,13 @@ function createTasks(params, setting
35
74
  break;
36
75
  case factory_1.factory.transactionStatusType.Canceled:
37
76
  case factory_1.factory.transactionStatusType.Expired:
38
- // deleteAt = moment(transaction.endDate)
39
- // .add(settings.transaction.canceledStoragePeriodInDays, 'days')
40
- // .toDate();
41
77
  deleteAt = (0, moment_1.default)(transaction.endDate)
42
78
  .add(canceledStoragePeriodInDays, 'days')
43
79
  .toDate();
44
80
  break;
45
81
  default:
46
82
  }
47
- const deleteTransactionTask = {
83
+ return {
48
84
  project: transaction.project,
49
85
  name: factory_1.factory.taskName.DeleteTransaction,
50
86
  status: factory_1.factory.taskStatus.Ready,
@@ -59,47 +95,8 @@ function createTasks(params, setting
59
95
  object: {
60
96
  order: transaction.object.order
61
97
  },
62
- // project: transaction.project,
63
- // startDate: transaction.startDate,
64
98
  typeOf: transaction.typeOf,
65
- // ...(transaction.endDate !== undefined) ? { endDate: transaction.endDate } : undefined
66
99
  }
67
100
  }
68
101
  };
69
- taskAttributes.push(deleteTransactionTask);
70
- switch (transaction.status) {
71
- case factory_1.factory.transactionStatusType.Confirmed: {
72
- const returnOrderPotentialActions = transaction.potentialActions?.returnOrder;
73
- if (Array.isArray(returnOrderPotentialActions)) {
74
- // 返品タスク
75
- const returnOrderTask = returnOrderPotentialActions.map((r) => {
76
- // data最適化(2023-08-22~)
77
- const returnOrderTaskData = {
78
- agent: r.agent,
79
- object: r.object,
80
- project: transaction.project,
81
- typeOf: r.typeOf
82
- };
83
- return {
84
- project: transaction.project,
85
- name: factory_1.factory.taskName.ReturnOrder,
86
- status: factory_1.factory.taskStatus.Ready,
87
- runsAt: taskRunsAt,
88
- remainingNumberOfTries: 10,
89
- numberOfTried: 0,
90
- executionResults: [],
91
- data: returnOrderTaskData
92
- };
93
- });
94
- taskAttributes.push(...returnOrderTask);
95
- }
96
- break;
97
- }
98
- case factory_1.factory.transactionStatusType.Expired:
99
- // 特にタスクなし
100
- break;
101
- default:
102
- throw new factory_1.factory.errors.NotImplemented(`Transaction status "${transaction.status}" not implemented.`);
103
- }
104
- return taskAttributes;
105
102
  }
@@ -11,6 +11,7 @@ import type { ReservationRepo } from '../../repo/reservation';
11
11
  import type { SellerRepo } from '../../repo/seller';
12
12
  import type { SellerReturnPolicyRepo } from '../../repo/sellerReturnPolicy';
13
13
  import type { SettingRepo } from '../../repo/setting';
14
+ import type { ScheduledTaskRepo } from '../../repo/scheduledTask';
14
15
  import type { TaskRepo } from '../../repo/task';
15
16
  import type { IStartedTransaction, ReturnOrderRepo } from '../../repo/transaction/returnOrder';
16
17
  import { preStart } from './returnOrder/preStart';
@@ -30,6 +31,7 @@ interface IStartOperationRepos {
30
31
  type IStartOperation<T> = (repos: IStartOperationRepos) => Promise<T>;
31
32
  interface IExportTasksByIdRepos {
32
33
  setting: SettingRepo;
34
+ scheduledTask: ScheduledTaskRepo;
33
35
  task: TaskRepo;
34
36
  returnOrder: ReturnOrderRepo;
35
37
  }
@@ -79,9 +79,7 @@ function saveMessagesIfNeeded(params) {
79
79
  * 取引確定
80
80
  */
81
81
  function confirm(params) {
82
- return async (repos
83
- // settings: Settings
84
- ) => {
82
+ return async (repos) => {
85
83
  const transaction = await repos.returnOrder.findReturnOrderById({ typeOf: factory_1.factory.transactionType.ReturnOrder, id: params.id }, ['typeOf', 'status', 'project', 'agent', 'object', 'result']);
86
84
  if (transaction.status === factory_1.factory.transactionStatusType.Confirmed) {
87
85
  // すでに確定済の場合
@@ -158,9 +156,7 @@ function confirm(params) {
158
156
  * この関数では、取引のタスクエクスポートステータスは見ません
159
157
  */
160
158
  function exportTasksById(params) {
161
- return async (repos
162
- // settings: Settings
163
- ) => {
159
+ return async (repos) => {
164
160
  const transaction = await repos.returnOrder.findReturnOrderById({ typeOf: factory_1.factory.transactionType.ReturnOrder, id: params.id }, ['typeOf', 'status', 'project', 'endDate', 'startDate', 'object', 'potentialActions']);
165
161
  // タスク実行日時バッファの指定があれば調整
166
162
  let taskRunsAt = new Date();
@@ -171,12 +167,24 @@ function exportTasksById(params) {
171
167
  }
172
168
  // search settings
173
169
  const setting = await repos.setting.findOne({ project: { id: { $eq: '*' } } }, ['storage']);
174
- const taskAttributes = (0, factory_2.createTasks)({
175
- transaction,
176
- runsAt: taskRunsAt
177
- }, setting
178
- // settings
179
- );
180
- await repos.task.saveMany(taskAttributes);
170
+ const useScheduledDeleteTransactionTask = setting?.storage?.useScheduledDeleteTransactionTask === true;
171
+ const deleteTransactionTaskExpiresInDays = setting?.storage?.deleteTransactionTaskExpiresInDays;
172
+ const deleteTask = (0, factory_2.createScheduledTasks)({ transaction }, setting);
173
+ if (useScheduledDeleteTransactionTask && typeof deleteTransactionTaskExpiresInDays === 'number' && deleteTransactionTaskExpiresInDays > 0) {
174
+ // support scheduledTask(2026-08-02~)
175
+ await repos.task.saveMany((0, factory_2.createImmediateTasks)({ transaction, taskRunsAt }));
176
+ await repos.scheduledTask.addScheduledTasks([{
177
+ ...deleteTask,
178
+ expires: (0, moment_timezone_1.default)(deleteTask.runsAt)
179
+ .add(deleteTransactionTaskExpiresInDays, 'days')
180
+ .toDate()
181
+ }]);
182
+ }
183
+ else {
184
+ await repos.task.saveMany([
185
+ ...(0, factory_2.createImmediateTasks)({ transaction, taskRunsAt }),
186
+ deleteTask
187
+ ]);
188
+ }
181
189
  };
182
190
  }
@@ -3,6 +3,7 @@
3
3
  */
4
4
  import { factory } from '../factory';
5
5
  import type { SettingRepo } from '../repo/setting';
6
+ import type { ScheduledTaskRepo } from '../repo/scheduledTask';
6
7
  import type { TaskRepo } from '../repo/task';
7
8
  import type { TransactionRepo } from '../repo/transaction';
8
9
  import type { PlaceOrderRepo } from '../repo/transaction/placeOrder';
@@ -18,6 +19,7 @@ export import returnOrder = ReturnOrderTransactionService;
18
19
  export { deleteTransaction };
19
20
  export type IExportTasksOperation<T> = (repos: {
20
21
  setting: SettingRepo;
22
+ scheduledTask: ScheduledTaskRepo;
21
23
  task: TaskRepo;
22
24
  placeOrder: PlaceOrderRepo;
23
25
  returnOrder: ReturnOrderRepo;
@@ -52,7 +52,6 @@ function exportOneTransactionTasksIfExists(params) {
52
52
  agent: { name: params.tasksExportAction.agent.name }
53
53
  },
54
54
  endDate: { $lt: params.endDate.$lt },
55
- // ...(params.typeOf !== undefined) ? { typeOf: params.typeOf } : undefined,
56
55
  ...(typeof params.id === 'string') ? { id: params.id } : undefined,
57
56
  ...(typeof params.status?.$eq === 'string') ? { status: params.status } : undefined,
58
57
  ...(params.sort !== undefined) ? { sort: params.sort } : undefined
@@ -65,7 +64,6 @@ function exportOneTransactionTasksIfExists(params) {
65
64
  case factory_1.factory.transactionType.PlaceOrder:
66
65
  await PlaceOrderTransactionService.exportTasksById({
67
66
  id: transaction.id,
68
- // optimizeRedundantTasks: params.optimizeRedundantTasks === true,
69
67
  ...(typeof params.runsTasksAfterInSeconds === 'number')
70
68
  ? { runsTasksAfterInSeconds: params.runsTasksAfterInSeconds }
71
69
  : undefined
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "dependencies": {
12
12
  "@aws-sdk/client-cognito-identity-provider": "3.1090.0",
13
13
  "@aws-sdk/credential-providers": "3.1090.0",
14
- "@chevre/factory": "10.1.0-alpha.4",
14
+ "@chevre/factory": "10.1.0-alpha.5",
15
15
  "@motionpicture/coa-service": "10.0.0",
16
16
  "@motionpicture/gmo-service": "6.1.0-alpha.0",
17
17
  "@sendgrid/client": "8.1.4",
@@ -88,5 +88,5 @@
88
88
  "postversion": "git push origin --tags",
89
89
  "prepublishOnly": "npm run clean && npm run build"
90
90
  },
91
- "version": "26.0.0-alpha.3"
91
+ "version": "26.0.0-alpha.5"
92
92
  }