@chevre/domain 22.11.0-alpha.9 → 22.11.0

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.
Files changed (149) hide show
  1. package/example/src/chevre/aggregation/aggregateOrderOfCustomer.ts +21 -10
  2. package/example/src/chevre/aggregation/aggregateTasks.ts +41 -0
  3. package/example/src/chevre/checkCustomerAttributesLength.ts +109 -0
  4. package/example/src/chevre/notifyAbortedTasksByEmail.ts +1 -1
  5. package/example/src/chevre/reIndex.ts +1 -1
  6. package/example/src/chevre/roles/addEventOfferPermissionIfNotExists.ts +27 -0
  7. package/example/src/chevre/roles/{addAdminInventoryManagerRole.ts → addProjectCreatorRole.ts} +6 -8
  8. package/example/src/chevre/roles/assignGlobalRoles.ts +72 -0
  9. package/example/src/chevre/roles/findPermissions.ts +84 -0
  10. package/example/src/chevre/roles/findRoleNames.ts +117 -0
  11. package/example/src/chevre/roles/removeConsolePermissionIfExists.ts +38 -0
  12. package/example/src/chevre/searchEventSeats.ts +1 -1
  13. package/example/src/chevre/searchProducts.ts +28 -0
  14. package/example/src/chevre/settings/addSettings.ts +31 -17
  15. package/example/src/chevre/task/countPotentiallyRunning.ts +41 -0
  16. package/example/src/chevre/task/countTasks.ts +51 -0
  17. package/example/src/chevre/{deleteRunsAtPassedCertainPeriod.ts → task/deleteRunsAtPassedCertainPeriod.ts} +4 -3
  18. package/example/src/chevre/task/deleteUnexpectedTasks.ts +23 -0
  19. package/example/src/chevre/task/emitRunning.ts +89 -0
  20. package/example/src/idaas/auth0/adminApplications.ts +183 -0
  21. package/example/src/idaas/auth0/getToken.ts +55 -0
  22. package/example/src/idaas/auth0/getTokenByPrivateKeyJWT.ts +84 -0
  23. package/example/src/regex.ts +31 -0
  24. package/lib/chevre/eventEmitter/task.d.ts +29 -6
  25. package/lib/chevre/index.d.ts +0 -2
  26. package/lib/chevre/index.js +0 -10
  27. package/lib/chevre/repo/member.d.ts +22 -4
  28. package/lib/chevre/repo/member.js +81 -27
  29. package/lib/chevre/repo/mongoose/schemas/member/global.d.ts +14 -0
  30. package/lib/chevre/repo/mongoose/schemas/member/global.js +82 -0
  31. package/lib/chevre/repo/mongoose/schemas/product.js +9 -0
  32. package/lib/chevre/repo/mongoose/schemas/setting.d.ts +15 -0
  33. package/lib/chevre/repo/mongoose/schemas/setting.js +1 -0
  34. package/lib/chevre/repo/mongoose/schemas/task.js +9 -0
  35. package/lib/chevre/repo/order.d.ts +17 -2
  36. package/lib/chevre/repo/order.js +47 -8
  37. package/lib/chevre/repo/pendingReservation.js +1 -0
  38. package/lib/chevre/repo/product.js +12 -17
  39. package/lib/chevre/repo/role.d.ts +5 -4
  40. package/lib/chevre/repo/role.js +35 -32
  41. package/lib/chevre/repo/setting.d.ts +1 -10
  42. package/lib/chevre/repo/setting.js +2 -11
  43. package/lib/chevre/repo/stockHolder.d.ts +4 -27
  44. package/lib/chevre/repo/stockHolder.js +163 -175
  45. package/lib/chevre/repo/task.d.ts +58 -38
  46. package/lib/chevre/repo/task.js +126 -296
  47. package/lib/chevre/repo/transaction.js +10 -10
  48. package/lib/chevre/service/assetTransaction/cancelReservation/start.d.ts +1 -1
  49. package/lib/chevre/service/assetTransaction/registerService.js +4 -0
  50. package/lib/chevre/service/assetTransaction/reserve/start/createSubReservations.js +19 -16
  51. package/lib/chevre/service/code.d.ts +5 -28
  52. package/lib/chevre/service/code.js +3 -79
  53. package/lib/chevre/service/iam.d.ts +17 -7
  54. package/lib/chevre/service/iam.js +26 -6
  55. package/lib/chevre/service/notification/notifyAbortedTasksByEmail.d.ts +15 -0
  56. package/lib/chevre/service/notification/notifyAbortedTasksByEmail.js +38 -0
  57. package/lib/chevre/service/notification.d.ts +2 -1
  58. package/lib/chevre/service/notification.js +3 -1
  59. package/lib/chevre/service/offer/product.js +4 -0
  60. package/lib/chevre/service/order/confirmPayTransaction.d.ts +6 -1
  61. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/processOrder.js +3 -3
  62. package/lib/chevre/service/task/acceptCOAOffer.d.ts +1 -1
  63. package/lib/chevre/service/task/aggregateOffers.d.ts +1 -1
  64. package/lib/chevre/service/task/aggregateOffers.js +1 -1
  65. package/lib/chevre/service/task/aggregateOnSystem.d.ts +4 -2
  66. package/lib/chevre/service/task/aggregateScreeningEvent.d.ts +1 -1
  67. package/lib/chevre/service/task/aggregateScreeningEvent.js +1 -1
  68. package/lib/chevre/service/task/authorizePayment.d.ts +1 -1
  69. package/lib/chevre/service/task/cancelMoneyTransfer.d.ts +1 -1
  70. package/lib/chevre/service/task/cancelPendingReservation.d.ts +1 -1
  71. package/lib/chevre/service/task/cancelPendingReservation.js +1 -1
  72. package/lib/chevre/service/task/cancelReservation.d.ts +1 -1
  73. package/lib/chevre/service/task/cancelReservation.js +1 -1
  74. package/lib/chevre/service/task/checkMovieTicket.d.ts +1 -1
  75. package/lib/chevre/service/task/checkResource.d.ts +1 -1
  76. package/lib/chevre/service/task/checkResource.js +1 -1
  77. package/lib/chevre/service/task/confirmMoneyTransfer.d.ts +1 -1
  78. package/lib/chevre/service/task/confirmPayTransaction.d.ts +2 -2
  79. package/lib/chevre/service/task/confirmPayTransaction.js +3 -2
  80. package/lib/chevre/service/task/confirmRegisterService.d.ts +1 -1
  81. package/lib/chevre/service/task/confirmRegisterServiceTransaction.d.ts +1 -1
  82. package/lib/chevre/service/task/confirmReserveTransaction.d.ts +6 -2
  83. package/lib/chevre/service/task/confirmReserveTransaction.js +3 -3
  84. package/lib/chevre/service/task/createAccountingReport.d.ts +1 -1
  85. package/lib/chevre/service/task/createEvent.d.ts +1 -1
  86. package/lib/chevre/service/task/deletePerson.d.ts +1 -1
  87. package/lib/chevre/service/task/deleteTransaction.d.ts +1 -1
  88. package/lib/chevre/service/task/givePointAward.d.ts +1 -1
  89. package/lib/chevre/service/task/handleNotification.d.ts +4 -2
  90. package/lib/chevre/service/task/importEventCapacitiesFromCOA.d.ts +1 -1
  91. package/lib/chevre/service/task/importEventsFromCOA.d.ts +1 -1
  92. package/lib/chevre/service/task/importOffersFromCOA.d.ts +1 -1
  93. package/lib/chevre/service/task/invalidatePaymentUrl.d.ts +1 -1
  94. package/lib/chevre/service/task/moneyTransfer.d.ts +1 -1
  95. package/lib/chevre/service/task/onAssetTransactionStatusChanged.d.ts +1 -1
  96. package/lib/chevre/service/task/onAuthorizationCreated.d.ts +1 -1
  97. package/lib/chevre/service/task/onEventChanged.d.ts +1 -1
  98. package/lib/chevre/service/task/onOrderPaymentCompleted.d.ts +1 -1
  99. package/lib/chevre/service/task/onResourceUpdated.d.ts +1 -1
  100. package/lib/chevre/service/task/pay.d.ts +1 -1
  101. package/lib/chevre/service/task/placeOrder.d.ts +1 -1
  102. package/lib/chevre/service/task/publishPaymentUrl.d.ts +1 -1
  103. package/lib/chevre/service/task/refund.d.ts +1 -1
  104. package/lib/chevre/service/task/registerService.d.ts +1 -1
  105. package/lib/chevre/service/task/reserve.d.ts +1 -1
  106. package/lib/chevre/service/task/returnMoneyTransfer.d.ts +1 -1
  107. package/lib/chevre/service/task/returnOrder.d.ts +1 -1
  108. package/lib/chevre/service/task/returnPayTransaction.d.ts +1 -1
  109. package/lib/chevre/service/task/returnPointAward.d.ts +1 -1
  110. package/lib/chevre/service/task/returnReserveTransaction.d.ts +1 -1
  111. package/lib/chevre/service/task/sendEmailMessage.d.ts +1 -1
  112. package/lib/chevre/service/task/sendOrder.d.ts +1 -1
  113. package/lib/chevre/service/task/triggerWebhook.d.ts +1 -1
  114. package/lib/chevre/service/task/useReservation.d.ts +1 -1
  115. package/lib/chevre/service/task/voidMoneyTransferTransaction.d.ts +1 -1
  116. package/lib/chevre/service/task/voidPayTransaction.d.ts +1 -1
  117. package/lib/chevre/service/task/voidPayment.d.ts +1 -1
  118. package/lib/chevre/service/task/voidRegisterServiceTransaction.d.ts +1 -1
  119. package/lib/chevre/service/task/voidReserveTransaction.d.ts +1 -1
  120. package/lib/chevre/service/task/voidReserveTransaction.js +1 -1
  121. package/lib/chevre/service/task.d.ts +7 -29
  122. package/lib/chevre/service/task.js +9 -114
  123. package/lib/chevre/service/taskHandler/onOperationFailed/informTaskIfNeeded.d.ts +11 -0
  124. package/lib/chevre/service/taskHandler/onOperationFailed/informTaskIfNeeded.js +105 -0
  125. package/lib/chevre/service/taskHandler/onOperationFailed.d.ts +17 -0
  126. package/lib/chevre/service/taskHandler/onOperationFailed.js +70 -0
  127. package/lib/chevre/service/taskHandler.d.ts +26 -0
  128. package/lib/chevre/service/taskHandler.js +97 -0
  129. package/lib/chevre/service/validation/validateEvent.d.ts +2 -2
  130. package/lib/chevre/service/validation/validateEvent.js +16 -10
  131. package/lib/chevre/service.d.ts +0 -4
  132. package/lib/chevre/service.js +10 -14
  133. package/lib/chevre/settings/aggregation.d.ts +6 -1
  134. package/lib/chevre/settings/aggregation.js +2 -1
  135. package/package.json +6 -4
  136. package/example/src/chevre/adminAuth/adminIdentity.ts +0 -38
  137. package/example/src/chevre/executeOneTask.ts +0 -41
  138. package/example/src/chevre/executeTaskIfExists.ts +0 -80
  139. package/example/src/chevre/findExecutableTask.ts +0 -50
  140. package/example/src/chevre/findSetting.ts +0 -79
  141. package/example/src/chevre/searchPermissions.ts +0 -46
  142. package/example/src/chevre/searchProductOffers.ts +0 -29
  143. package/example/src/chevre/stockHolder/checkIfConflicted.ts +0 -76
  144. package/example/src/chevre/stockHolder/checkRedisKeyCount.ts +0 -186
  145. package/example/src/chevre/stockHolder/migratePendingReservations.ts +0 -96
  146. package/example/src/chevre/stockHolder/playAroundStockHolder.ts +0 -256
  147. package/example/src/chevre/upsertProductsByProductId.ts +0 -100
  148. package/lib/chevre/adminAuth.d.ts +0 -2
  149. package/lib/chevre/adminAuth.js +0 -6
@@ -23,7 +23,9 @@ interface IOptionOnCreate {
23
23
  emitImmediately: boolean;
24
24
  }
25
25
  export type IExecutableTaskKeys = 'data' | 'id' | 'name' | 'status' | 'numberOfTried' | 'project' | 'remainingNumberOfTries' | 'runsAt' | 'expires';
26
- export type IExecutableTask<T extends factory.taskName> = Pick<factory.task.ITask<T>, IExecutableTaskKeys>;
26
+ export type IExecutableTask<T extends factory.taskName> = Pick<factory.task.ITask<T>, IExecutableTaskKeys> & {
27
+ status: factory.taskStatus.Running;
28
+ };
27
29
  type IKeyOfProjection = keyof factory.task.ITask<factory.taskName>;
28
30
  type ICreatingTask = Pick<factory.task.IAttributes<factory.taskName>, 'data' | 'executionResults' | 'name' | 'numberOfTried' | 'project' | 'remainingNumberOfTries' | 'runsAt' | 'status' | 'identifier' | 'description'>;
29
31
  /**
@@ -68,6 +70,10 @@ export declare class TaskRepo {
68
70
  */
69
71
  createDeleteTransactionTaskIfNotExist(params: Pick<factory.task.IAttributes<factory.taskName.DeleteTransaction>, 'data' | 'executionResults' | 'name' | 'numberOfTried' | 'project' | 'remainingNumberOfTries' | 'runsAt' | 'status'>, options: IOptionOnCreate): Promise<void>;
70
72
  createOnAssetTransactionStatusChangedTaskIfNotExist(params: Pick<factory.task.IAttributes<factory.taskName.OnAssetTransactionStatusChanged>, 'data' | 'executionResults' | 'name' | 'numberOfTried' | 'project' | 'remainingNumberOfTries' | 'runsAt' | 'status'>, options: IOptionOnCreate): Promise<void>;
73
+ /**
74
+ * Ready -> remainingNumberOfTriesが1減る
75
+ * Running -> findOneするだけ
76
+ */
71
77
  executeOneById(params: {
72
78
  id: string;
73
79
  status: factory.taskStatus.Ready | factory.taskStatus.Running;
@@ -77,12 +83,11 @@ export declare class TaskRepo {
77
83
  expires?: Date;
78
84
  }): Promise<IExecutableTask<factory.taskName> | null>;
79
85
  /**
80
- * support no name(2025-03-04~)
86
+ * Readyのタスクをname指定でひとつRunningに変更する
81
87
  */
82
88
  executeOneIfExists(params: {
83
- name?: {
84
- $eq?: factory.taskName;
85
- $nin?: factory.taskName[];
89
+ name: {
90
+ $eq: factory.taskName;
86
91
  };
87
92
  executor: {
88
93
  name: string;
@@ -90,6 +95,10 @@ export declare class TaskRepo {
90
95
  runsAt: {
91
96
  $lt: Date;
92
97
  };
98
+ sort: {
99
+ numberOfTried?: factory.sortType;
100
+ runsAt?: factory.sortType;
101
+ };
93
102
  }): Promise<IExecutableTask<factory.taskName> | null>;
94
103
  /**
95
104
  * add(2025-03-16~)
@@ -97,7 +106,7 @@ export declare class TaskRepo {
97
106
  countPotentiallyRunning(params: {
98
107
  name?: {
99
108
  $eq?: factory.taskName;
100
- $nin?: factory.taskName[];
109
+ $in?: factory.taskName[];
101
110
  };
102
111
  runsAt: {
103
112
  $lt: Date;
@@ -106,45 +115,54 @@ export declare class TaskRepo {
106
115
  }): Promise<{
107
116
  count: number;
108
117
  }>;
118
+ /**
119
+ * 実行日時を一定期間過ぎたReadyタスクについて、Runningスタータスに変更した上で、Runningイベントを発生させる
120
+ */
109
121
  emitRunningIfExists(params: {
110
- name?: {
111
- $eq?: factory.taskName;
112
- $nin?: factory.taskName[];
113
- };
114
- executor: {
115
- name: string;
122
+ /**
123
+ * 必ずタスク名指定で実行する
124
+ */
125
+ name: {
126
+ $eq: factory.taskName;
127
+ $in?: never;
128
+ } | {
129
+ $eq?: never;
130
+ $in: factory.taskName[];
116
131
  };
117
132
  runsAt: {
118
133
  $lt: Date;
119
134
  };
120
135
  sort: {
121
136
  numberOfTried?: factory.sortType;
122
- runsAt: factory.sortType;
137
+ runsAt?: factory.sortType;
123
138
  };
124
- }): Promise<Pick<factory.task.ITask<factory.taskName>, 'id' | 'name'> | null>;
125
- findExecutableOne(params: {
126
- name?: {
127
- $eq?: factory.taskName;
128
- $nin?: factory.taskName[];
129
- };
130
- runsAt: {
131
- $lt: Date;
139
+ executor: {
140
+ name: string;
132
141
  };
133
- }): Promise<IExecutableTask<factory.taskName> | null>;
134
- /**
135
- * emit OnTaskStatusChanged on delayed tasks
136
- */
142
+ nameFilterBeforeRunsAt: boolean;
143
+ }, next?: INextFunction): Promise<Pick<factory.task.ITask<factory.taskName>, 'id' | 'name'> | null>;
137
144
  /**
138
- * make tasks expired
145
+ * Readyのままで期限切れのタスクをExpiredに変更する
139
146
  */
140
147
  makeExpiredMany(params: {
141
148
  expiresLt: Date;
142
149
  }): Promise<UpdateWriteOpResult>;
143
150
  /**
144
- * 実行中ステータスのままになっているタスクをリトライする
151
+ * Runningのまま一定期間超過し、かつ、remainingNumberOfTries>0のタスクをReadyに変更する
145
152
  */
146
- retry(params: {
153
+ retryMany(params: {
147
154
  intervalInMinutes: number;
155
+ /**
156
+ * リトライ条件に残り試行回数条件を追加する
157
+ * 十分に小さい数値を指定すれば、実質残り試行回数に関係なくRunningがReadyに変更されることになる
158
+ */
159
+ remainingNumberOfTries: {
160
+ $gte?: number;
161
+ $lte?: number;
162
+ };
163
+ name: {
164
+ $in?: factory.taskName[];
165
+ };
148
166
  }): Promise<UpdateWriteOpResult>;
149
167
  /**
150
168
  * 実行中止済タスクを強制的にリトライ
@@ -154,25 +172,27 @@ export declare class TaskRepo {
154
172
  id: string;
155
173
  remainingNumberOfTries: number;
156
174
  }): Promise<UpdateWriteOpResult>;
157
- abortOne(params: {
158
- intervalInMinutes: number;
159
- }): Promise<factory.task.ITask<factory.taskName> | null>;
160
175
  abortMany(params: {
161
176
  intervalInMinutes: number;
177
+ name: {
178
+ $in?: factory.taskName[];
179
+ };
162
180
  }): Promise<UpdateWriteOpResult>;
163
181
  /**
164
- * 実行結果を保管する
182
+ * タスクIDから実行結果とステータスを保管する
183
+ * Abortedの場合、dateAbortedもセットする
165
184
  */
166
- pushExecutionResultById(params: {
185
+ setExecutionResultAndStatus(params: {
167
186
  /**
168
187
  * タスクID
169
188
  */
170
189
  id: string;
171
- status: factory.taskStatus;
172
- }, executionResult: factory.task.IExecutionResult, next?: INextFunction): Promise<void>;
173
- /**
174
- * 特定タスク検索
175
- */
190
+ remainingNumberOfTries: number;
191
+ name: factory.taskName;
192
+ }, update: {
193
+ status: factory.taskStatus.Executed | factory.taskStatus.Running | factory.taskStatus.Aborted;
194
+ executionResult: factory.task.IExecutionResult;
195
+ }, next?: INextFunction): Promise<void>;
176
196
  count(params: factory.task.ISearchConditions): Promise<{
177
197
  count: number;
178
198
  }>;