@chevre/domain 21.2.0-alpha.3 → 21.2.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.
Files changed (176) hide show
  1. package/example/src/chevre/countDelayedTasks.ts +17 -0
  2. package/example/src/chevre/countDelayedTransactions.ts +60 -0
  3. package/example/src/chevre/countMoneyTransferTransaction.ts +36 -0
  4. package/example/src/chevre/createManyEventsIfNotExist.ts +4 -1
  5. package/example/src/chevre/lockStockHolder.ts +48 -0
  6. package/example/src/chevre/migrateOrderAdditionalProperties.ts +85 -0
  7. package/example/src/chevre/migrateStockHolderKeys.ts +89 -0
  8. package/example/src/chevre/searchAbortedTasks.ts +30 -0
  9. package/example/src/chevre/transaction/findCreditCard.ts +1 -1
  10. package/example/src/chevre/transaction/makeExpired.ts +18 -0
  11. package/example/src/chevre/transaction/orderMembershipService.ts +1 -1
  12. package/example/src/chevre/transaction/startExportTasks.ts +19 -0
  13. package/example/src/chevre/updateTransaction.ts +1 -1
  14. package/lib/chevre/credentials.d.ts +1 -0
  15. package/lib/chevre/credentials.js +2 -1
  16. package/lib/chevre/eventEmitter/assetTransaction.d.ts +21 -0
  17. package/lib/chevre/eventEmitter/assetTransaction.js +28 -0
  18. package/lib/chevre/eventEmitter/task.d.ts +18 -0
  19. package/lib/chevre/eventEmitter/task.js +28 -0
  20. package/lib/chevre/eventEmitter/transaction.d.ts +21 -0
  21. package/lib/chevre/eventEmitter/transaction.js +28 -0
  22. package/lib/chevre/eventEmitter.d.ts +4 -0
  23. package/lib/chevre/eventEmitter.js +9 -0
  24. package/lib/chevre/index.d.ts +3 -2
  25. package/lib/chevre/index.js +5 -3
  26. package/lib/chevre/repo/account.js +0 -4
  27. package/lib/chevre/repo/accountTitle.js +0 -4
  28. package/lib/chevre/repo/accountTransaction.d.ts +0 -10
  29. package/lib/chevre/repo/accountTransaction.js +0 -57
  30. package/lib/chevre/repo/accountingReport.js +0 -4
  31. package/lib/chevre/repo/action.js +0 -4
  32. package/lib/chevre/repo/additionalProperty.js +0 -4
  33. package/lib/chevre/repo/aggregation.js +0 -4
  34. package/lib/chevre/repo/assetTransaction.d.ts +9 -6
  35. package/lib/chevre/repo/assetTransaction.js +132 -48
  36. package/lib/chevre/repo/categoryCode.js +0 -4
  37. package/lib/chevre/repo/code.js +0 -4
  38. package/lib/chevre/repo/comment.js +0 -4
  39. package/lib/chevre/repo/confirmationNumber.js +1 -1
  40. package/lib/chevre/repo/creativeWork.d.ts +1 -3
  41. package/lib/chevre/repo/creativeWork.js +0 -4
  42. package/lib/chevre/repo/customer.js +0 -4
  43. package/lib/chevre/repo/emailMessage.d.ts +1 -27
  44. package/lib/chevre/repo/emailMessage.js +0 -4
  45. package/lib/chevre/repo/event.d.ts +5 -1
  46. package/lib/chevre/repo/event.js +0 -4
  47. package/lib/chevre/repo/member.js +0 -4
  48. package/lib/chevre/repo/merchantReturnPolicy.d.ts +1 -3
  49. package/lib/chevre/repo/merchantReturnPolicy.js +0 -4
  50. package/lib/chevre/repo/mongoose/schemas/account.d.ts +5 -2
  51. package/lib/chevre/repo/mongoose/schemas/account.js +1 -0
  52. package/lib/chevre/repo/mongoose/schemas/accountTitle.d.ts +30 -3
  53. package/lib/chevre/repo/mongoose/schemas/accountTitle.js +1 -0
  54. package/lib/chevre/repo/mongoose/schemas/accountTransaction.d.ts +32 -3
  55. package/lib/chevre/repo/mongoose/schemas/accountTransaction.js +2 -1
  56. package/lib/chevre/repo/mongoose/schemas/accountingReport.d.ts +14 -3
  57. package/lib/chevre/repo/mongoose/schemas/accountingReport.js +1 -0
  58. package/lib/chevre/repo/mongoose/schemas/action.d.ts +44 -3
  59. package/lib/chevre/repo/mongoose/schemas/action.js +2 -1
  60. package/lib/chevre/repo/mongoose/schemas/additionalProperty.d.ts +18 -3
  61. package/lib/chevre/repo/mongoose/schemas/additionalProperty.js +1 -0
  62. package/lib/chevre/repo/mongoose/schemas/aggregation.d.ts +5 -2
  63. package/lib/chevre/repo/mongoose/schemas/aggregation.js +1 -0
  64. package/lib/chevre/repo/mongoose/schemas/assetTransaction.d.ts +45 -3
  65. package/lib/chevre/repo/mongoose/schemas/assetTransaction.js +3 -1
  66. package/lib/chevre/repo/mongoose/schemas/authorization.d.ts +20 -3
  67. package/lib/chevre/repo/mongoose/schemas/authorization.js +2 -1
  68. package/lib/chevre/repo/mongoose/schemas/categoryCode.d.ts +26 -3
  69. package/lib/chevre/repo/mongoose/schemas/categoryCode.js +1 -0
  70. package/lib/chevre/repo/mongoose/schemas/comments.d.ts +28 -3
  71. package/lib/chevre/repo/mongoose/schemas/comments.js +2 -1
  72. package/lib/chevre/repo/mongoose/schemas/creativeWork.d.ts +44 -3
  73. package/lib/chevre/repo/mongoose/schemas/creativeWork.js +1 -0
  74. package/lib/chevre/repo/mongoose/schemas/customer.d.ts +26 -3
  75. package/lib/chevre/repo/mongoose/schemas/customer.js +1 -0
  76. package/lib/chevre/repo/mongoose/schemas/emailMessages.d.ts +22 -3
  77. package/lib/chevre/repo/mongoose/schemas/emailMessages.js +1 -0
  78. package/lib/chevre/repo/mongoose/schemas/event.d.ts +72 -3
  79. package/lib/chevre/repo/mongoose/schemas/event.js +1 -0
  80. package/lib/chevre/repo/mongoose/schemas/member.d.ts +14 -3
  81. package/lib/chevre/repo/mongoose/schemas/member.js +1 -0
  82. package/lib/chevre/repo/mongoose/schemas/merchantReturnPolicy.d.ts +22 -3
  83. package/lib/chevre/repo/mongoose/schemas/merchantReturnPolicy.js +1 -0
  84. package/lib/chevre/repo/mongoose/schemas/offer.d.ts +66 -3
  85. package/lib/chevre/repo/mongoose/schemas/offer.js +1 -0
  86. package/lib/chevre/repo/mongoose/schemas/offerCatalog.d.ts +28 -3
  87. package/lib/chevre/repo/mongoose/schemas/offerCatalog.js +1 -0
  88. package/lib/chevre/repo/mongoose/schemas/order.d.ts +52 -3
  89. package/lib/chevre/repo/mongoose/schemas/order.js +2 -1
  90. package/lib/chevre/repo/mongoose/schemas/ownershipInfo.d.ts +26 -3
  91. package/lib/chevre/repo/mongoose/schemas/ownershipInfo.js +2 -1
  92. package/lib/chevre/repo/mongoose/schemas/place.d.ts +50 -3
  93. package/lib/chevre/repo/mongoose/schemas/place.js +1 -0
  94. package/lib/chevre/repo/mongoose/schemas/priceSpecification.d.ts +30 -3
  95. package/lib/chevre/repo/mongoose/schemas/priceSpecification.js +1 -0
  96. package/lib/chevre/repo/mongoose/schemas/product.d.ts +32 -3
  97. package/lib/chevre/repo/mongoose/schemas/product.js +1 -0
  98. package/lib/chevre/repo/mongoose/schemas/project.d.ts +24 -3
  99. package/lib/chevre/repo/mongoose/schemas/project.js +1 -0
  100. package/lib/chevre/repo/mongoose/schemas/reservation.d.ts +62 -3
  101. package/lib/chevre/repo/mongoose/schemas/reservation.js +2 -1
  102. package/lib/chevre/repo/mongoose/schemas/role.d.ts +12 -3
  103. package/lib/chevre/repo/mongoose/schemas/role.js +1 -0
  104. package/lib/chevre/repo/mongoose/schemas/seller.d.ts +32 -3
  105. package/lib/chevre/repo/mongoose/schemas/seller.js +1 -0
  106. package/lib/chevre/repo/mongoose/schemas/serviceOutput.d.ts +12 -3
  107. package/lib/chevre/repo/mongoose/schemas/serviceOutput.js +2 -1
  108. package/lib/chevre/repo/mongoose/schemas/task.d.ts +31 -3
  109. package/lib/chevre/repo/mongoose/schemas/task.js +3 -1
  110. package/lib/chevre/repo/mongoose/schemas/telemetry.d.ts +22 -3
  111. package/lib/chevre/repo/mongoose/schemas/telemetry.js +1 -0
  112. package/lib/chevre/repo/mongoose/schemas/transaction.d.ts +41 -3
  113. package/lib/chevre/repo/mongoose/schemas/transaction.js +3 -1
  114. package/lib/chevre/repo/mongoose/schemas/trip.d.ts +12 -3
  115. package/lib/chevre/repo/mongoose/schemas/trip.js +1 -0
  116. package/lib/chevre/repo/offer.js +0 -5
  117. package/lib/chevre/repo/offerCatalog.js +0 -4
  118. package/lib/chevre/repo/order.d.ts +25 -0
  119. package/lib/chevre/repo/order.js +5 -4
  120. package/lib/chevre/repo/orderNumber.d.ts +0 -1
  121. package/lib/chevre/repo/orderNumber.js +2 -12
  122. package/lib/chevre/repo/ownershipInfo.js +0 -4
  123. package/lib/chevre/repo/permit.js +0 -4
  124. package/lib/chevre/repo/place.d.ts +5 -1
  125. package/lib/chevre/repo/place.js +1 -10
  126. package/lib/chevre/repo/priceSpecification.js +0 -4
  127. package/lib/chevre/repo/product.js +0 -4
  128. package/lib/chevre/repo/project.js +0 -4
  129. package/lib/chevre/repo/rateLimit/offer.d.ts +3 -2
  130. package/lib/chevre/repo/rateLimit/offer.js +14 -14
  131. package/lib/chevre/repo/reservation.js +0 -4
  132. package/lib/chevre/repo/role.js +0 -4
  133. package/lib/chevre/repo/seller.js +0 -4
  134. package/lib/chevre/repo/serviceOutput.js +0 -4
  135. package/lib/chevre/repo/serviceOutputIdentifier.d.ts +2 -1
  136. package/lib/chevre/repo/serviceOutputIdentifier.js +14 -15
  137. package/lib/chevre/repo/stockHolder.d.ts +1 -0
  138. package/lib/chevre/repo/stockHolder.js +74 -7
  139. package/lib/chevre/repo/task.d.ts +17 -2
  140. package/lib/chevre/repo/task.js +61 -10
  141. package/lib/chevre/repo/telemetry.js +0 -4
  142. package/lib/chevre/repo/transaction.d.ts +10 -2
  143. package/lib/chevre/repo/transaction.js +144 -55
  144. package/lib/chevre/repo/transactionNumber.d.ts +2 -1
  145. package/lib/chevre/repo/transactionNumber.js +14 -15
  146. package/lib/chevre/repo/trip.js +0 -4
  147. package/lib/chevre/service/assetTransaction/cancelReservation.js +1 -5
  148. package/lib/chevre/service/assetTransaction/moneyTransfer.js +1 -1
  149. package/lib/chevre/service/assetTransaction/pay.js +2 -2
  150. package/lib/chevre/service/assetTransaction/refund.js +1 -1
  151. package/lib/chevre/service/assetTransaction/registerService.js +1 -2
  152. package/lib/chevre/service/assetTransaction/reserve.js +1 -1
  153. package/lib/chevre/service/assetTransaction.d.ts +6 -2
  154. package/lib/chevre/service/assetTransaction.js +9 -5
  155. package/lib/chevre/service/notification.d.ts +3 -1
  156. package/lib/chevre/service/notification.js +2 -6
  157. package/lib/chevre/service/order/onOrderStatusChanged.js +1 -1
  158. package/lib/chevre/service/order/placeOrder.js +1 -1
  159. package/lib/chevre/service/order/returnOrder.js +1 -5
  160. package/lib/chevre/service/order/sendOrder.js +1 -1
  161. package/lib/chevre/service/payment/any.js +25 -10
  162. package/lib/chevre/service/reserve/useReservation.js +1 -8
  163. package/lib/chevre/service/task.d.ts +9 -0
  164. package/lib/chevre/service/task.js +43 -4
  165. package/lib/chevre/service/transaction/moneyTransfer.js +1 -3
  166. package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.js +16 -16
  167. package/lib/chevre/service/transaction/placeOrder.js +1 -5
  168. package/lib/chevre/service/transaction/placeOrderInProgress.js +2 -2
  169. package/lib/chevre/service/transaction/returnOrder.js +1 -5
  170. package/lib/chevre/service/transaction.d.ts +6 -0
  171. package/lib/chevre/service/transaction.js +9 -7
  172. package/lib/chevre/settings.d.ts +3 -1
  173. package/lib/chevre/settings.js +6 -4
  174. package/package.json +4 -4
  175. package/example/src/chevre/migrateMoneyTransferPendingTransactionIdentifier.ts +0 -96
  176. package/example/src/chevre/migrateMovieAdditionalProperties.ts +0 -98
@@ -218,7 +218,7 @@ function exportTasksById(params) {
218
218
  default:
219
219
  throw new factory.errors.NotImplemented(`Transaction status "${transaction.status}" not implemented.`);
220
220
  }
221
- return repos.task.saveMany(taskAttributes);
221
+ return repos.task.saveMany(taskAttributes, { emitImmediately: true });
222
222
  });
223
223
  }
224
224
  exports.exportTasksById = exportTasksById;
@@ -301,8 +301,7 @@ function exportTasksById(params) {
301
301
  default:
302
302
  throw new factory.errors.NotImplemented(`Transaction status "${transaction.status}" not implemented.`);
303
303
  }
304
- return repos.task.saveMany(taskAttributes);
305
- // return Promise.all(taskAttributes.map(async (a) => repos.task.save(a)));
304
+ return repos.task.saveMany(taskAttributes, { emitImmediately: true });
306
305
  });
307
306
  }
308
307
  exports.exportTasksById = exportTasksById;
@@ -860,7 +860,7 @@ function exportTasksById(params) {
860
860
  default:
861
861
  throw new factory.errors.NotImplemented(`Transaction status "${transaction.status}" not implemented.`);
862
862
  }
863
- return repos.task.saveMany(taskAttributes);
863
+ return repos.task.saveMany(taskAttributes, { emitImmediately: true });
864
864
  });
865
865
  }
866
866
  exports.exportTasksById = exportTasksById;
@@ -3,7 +3,6 @@
3
3
  */
4
4
  import * as factory from '../factory';
5
5
  import { MongoRepository as AssetTransactionRepo } from '../repo/assetTransaction';
6
- import { MongoRepository as ProjectRepo } from '../repo/project';
7
6
  import { MongoRepository as TaskRepo } from '../repo/task';
8
7
  import * as CancelReservationTransactionService from './assetTransaction/cancelReservation';
9
8
  import * as MoneyTransferTransactionService from './assetTransaction/moneyTransfer';
@@ -29,8 +28,13 @@ export declare function exportTasks<T extends factory.assetTransactionType>(para
29
28
  typeOf?: {
30
29
  $in: T[];
31
30
  };
31
+ id?: string;
32
+ tasksExportAction?: {
33
+ agent: {
34
+ name: string;
35
+ };
36
+ };
32
37
  }): (repos: {
33
- project: ProjectRepo;
34
38
  task: TaskRepo;
35
39
  assetTransaction: AssetTransactionRepo;
36
40
  }) => Promise<{
@@ -20,6 +20,7 @@ const PayTransactionService = require("./assetTransaction/pay");
20
20
  const RefundTransactionService = require("./assetTransaction/refund");
21
21
  const RegisterServiceTransactionService = require("./assetTransaction/registerService");
22
22
  const ReserveTransactionService = require("./assetTransaction/reserve");
23
+ const settings_1 = require("../settings");
23
24
  exports.cancelReservation = CancelReservationTransactionService;
24
25
  exports.moneyTransfer = MoneyTransferTransactionService;
25
26
  exports.pay = PayTransactionService;
@@ -31,11 +32,14 @@ exports.reserve = ReserveTransactionService;
31
32
  */
32
33
  function exportTasks(params) {
33
34
  return (repos) => __awaiter(this, void 0, void 0, function* () {
34
- const transaction = yield repos.assetTransaction.startExportTasks({
35
- // project: params.project,
36
- typeOf: params.typeOf,
37
- status: params.status
38
- });
35
+ var _a;
36
+ const transaction = yield repos.assetTransaction.startExportTasks(Object.assign({ typeOf: params.typeOf, status: params.status, tasksExportAction: {
37
+ agent: {
38
+ name: (typeof ((_a = params.tasksExportAction) === null || _a === void 0 ? void 0 : _a.agent.name) === 'string')
39
+ ? params.tasksExportAction.agent.name
40
+ : settings_1.DEFAULT_TASKS_EXPORT_AGENT_NAME
41
+ }
42
+ } }, (typeof params.id === 'string') ? { id: params.id } : undefined));
39
43
  if (transaction === null) {
40
44
  return;
41
45
  }
@@ -1,7 +1,9 @@
1
1
  import * as factory from '../factory';
2
2
  import { MongoRepository as ActionRepo } from '../repo/action';
3
3
  import { MongoRepository as ProjectRepo } from '../repo/project';
4
- export type Operation<T> = () => Promise<T>;
4
+ export type Operation<T> = (repos: {
5
+ accessToken: string;
6
+ }) => Promise<T>;
5
7
  /**
6
8
  * Eメールメッセージを送信する
7
9
  * https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/errors.html
@@ -111,15 +111,11 @@ exports.sendEmailMessage = sendEmailMessage;
111
111
  * https://notify-bot.line.me/doc/ja/
112
112
  */
113
113
  function report2developers(subject, content, imageThumbnail, imageFullsize) {
114
- return () => __awaiter(this, void 0, void 0, function* () {
114
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
115
115
  const LINE_NOTIFY_URL = credentials_1.credentials.lineNotify.url;
116
- const LINE_NOTIFY_ACCESS_TOKEN = credentials_1.credentials.lineNotify.accessToken;
117
116
  if (LINE_NOTIFY_URL === undefined) {
118
117
  throw new Error('Environment variable LINE_NOTIFY_URL not set');
119
118
  }
120
- if (LINE_NOTIFY_ACCESS_TOKEN === undefined) {
121
- throw new Error('Environment variable LINE_NOTIFY_ACCESS_TOKEN not set');
122
- }
123
119
  const message = `--------
124
120
  ${subject}
125
121
  --------
@@ -130,7 +126,7 @@ ${content}`;
130
126
  var _a;
131
127
  request.post({
132
128
  url: LINE_NOTIFY_URL,
133
- auth: { bearer: LINE_NOTIFY_ACCESS_TOKEN },
129
+ auth: { bearer: repos.accessToken },
134
130
  form: formData,
135
131
  json: true,
136
132
  timeout: (_a = settings_1.settings.webhook) === null || _a === void 0 ? void 0 : _a.timeout
@@ -89,7 +89,7 @@ function onOrderStatusChanged(params) {
89
89
  break;
90
90
  default:
91
91
  }
92
- yield repos.task.saveMany(tasks);
92
+ yield repos.task.saveMany(tasks, { emitImmediately: true });
93
93
  });
94
94
  }
95
95
  exports.onOrderStatusChanged = onOrderStatusChanged;
@@ -269,6 +269,6 @@ function onPlaceOrder(params) {
269
269
  }
270
270
  }
271
271
  // タスク保管
272
- yield repos.task.saveMany(taskAttributes);
272
+ yield repos.task.saveMany(taskAttributes, { emitImmediately: true });
273
273
  });
274
274
  }
@@ -204,10 +204,6 @@ function onReturn(returnActionAttributes) {
204
204
  }
205
205
  }
206
206
  // タスク保管
207
- // saveManyに変更(2023-02-01~)
208
- yield repos.task.saveMany(taskAttributes);
209
- // await Promise.all(taskAttributes.map(async (taskAttribute) => {
210
- // return repos.task.save(taskAttribute);
211
- // }));
207
+ yield repos.task.saveMany(taskAttributes, { emitImmediately: true });
212
208
  });
213
209
  }
@@ -178,6 +178,6 @@ function onSend(params) {
178
178
  }
179
179
  }
180
180
  // タスク保管
181
- yield repos.task.saveMany(taskAttributes);
181
+ yield repos.task.saveMany(taskAttributes, { emitImmediately: true });
182
182
  });
183
183
  }
@@ -52,10 +52,18 @@ exports.voidPayTransaction = voidPayTransaction;
52
52
  function invalidatePaymentUrl(params) {
53
53
  return (repos) => __awaiter(this, void 0, void 0, function* () {
54
54
  var _a, _b, _c, _d, _e;
55
+ if (params.purpose.typeOf !== factory.transactionType.PlaceOrder) {
56
+ throw new factory.errors.Argument('purpose.typeOf', `must be ${factory.transactionType.PlaceOrder}`);
57
+ }
55
58
  const transaction = yield repos.transaction.findById({
56
59
  typeOf: params.purpose.typeOf,
57
60
  id: params.purpose.id
58
61
  });
62
+ // 確定取引に対応(2023-05-03~)
63
+ if (transaction.status === factory.transactionStatusType.Confirmed) {
64
+ // no op
65
+ return;
66
+ }
59
67
  const paymentMethodIdByPaymentUrl = (_a = transaction.object.paymentMethods) === null || _a === void 0 ? void 0 : _a.paymentMethodId;
60
68
  const paymentMethodType = (_b = transaction.object.paymentMethods) === null || _b === void 0 ? void 0 : _b.typeOf;
61
69
  if (typeof paymentMethodIdByPaymentUrl === 'string' && paymentMethodIdByPaymentUrl.length > 0
@@ -70,12 +78,10 @@ function invalidatePaymentUrl(params) {
70
78
  ? transaction.seller.name
71
79
  : String((_c = transaction.seller.name) === null || _c === void 0 ? void 0 : _c.ja),
72
80
  id: transaction.seller.id
73
- // project: transaction.seller.project
74
81
  },
75
82
  recipient: { typeOf: transaction.agent.typeOf, name: transaction.agent.name },
76
83
  object: [{
77
84
  typeOf: factory.service.paymentService.PaymentServiceType.CreditCard,
78
- // tslint:disable-next-line:max-line-length
79
85
  id: (_e = (_d = transaction.object.paymentMethods) === null || _d === void 0 ? void 0 : _d.issuedThrough) === null || _e === void 0 ? void 0 : _e.id,
80
86
  paymentMethod: {
81
87
  additionalProperty: [],
@@ -103,10 +109,11 @@ function processVoidPayTransaction(params) {
103
109
  transaction = yield repos.transaction.findInProgressById({ typeOf: params.purpose.typeOf, id: params.purpose.id });
104
110
  }
105
111
  else {
106
- transaction = yield repos.transaction.findById({
112
+ transaction = (yield repos.transaction.findById({
107
113
  typeOf: params.purpose.typeOf,
108
- id: params.purpose.id
109
- });
114
+ id: params.purpose.id,
115
+ inclusion: ['_id', 'typeOf', 'status']
116
+ }));
110
117
  }
111
118
  // 承認アクションを取得
112
119
  let authorizeActions;
@@ -122,7 +129,7 @@ function processVoidPayTransaction(params) {
122
129
  const authorizeActionsOnTransaction = yield repos.action.searchByPurpose({
123
130
  typeOf: factory.actionType.AuthorizeAction,
124
131
  purpose: {
125
- typeOf: factory.transactionType.PlaceOrder,
132
+ typeOf: transaction.typeOf,
126
133
  id: transaction.id
127
134
  }
128
135
  });
@@ -131,12 +138,20 @@ function processVoidPayTransaction(params) {
131
138
  return ((_a = a.object) === null || _a === void 0 ? void 0 : _a.typeOf) === factory.action.authorize.paymentMethod.any.ResultType.Payment
132
139
  && ((_b = a.instrument) === null || _b === void 0 ? void 0 : _b.identifier) === factory.action.authorize.paymentMethod.any.ServiceIdentifier.Chevre;
133
140
  });
141
+ switch (transaction.status) {
142
+ case factory.transactionStatusType.InProgress:
143
+ throw new factory.errors.NotImplemented(`${transaction.status} not implemented`);
144
+ // 確定取引に対応(2023-05-03~)
145
+ case factory.transactionStatusType.Confirmed:
146
+ // アクションステータスを検証する
147
+ authorizeActions = authorizeActions.filter((a) => a.actionStatus !== factory.actionStatusType.CompletedActionStatus);
148
+ break;
149
+ default:
150
+ // no op
151
+ }
134
152
  }
135
153
  const errors = [];
136
154
  for (const action of authorizeActions) {
137
- // 直列にゆっくり処理する場合↓
138
- // tslint:disable-next-line:no-magic-numbers
139
- // await new Promise((resolve) => setTimeout(() => { resolve(); }, 1000));
140
155
  // 失敗するケースがあっても、残りが少なくとも処理されるようにエラーハンドリング
141
156
  try {
142
157
  // 取引が存在すれば中止
@@ -194,7 +209,7 @@ function publishPaymentUrl(params) {
194
209
  paymentUrl: result.paymentUrl,
195
210
  issuedThrough: { id: (typeof startParams.object.id === 'string') ? startParams.object.id : '' }
196
211
  };
197
- yield repos.transaction.findByIdAndUpdate({
212
+ yield repos.transaction.findByIdAndUpdateInProgress({
198
213
  id: transaction.id,
199
214
  update: { $set: { 'object.paymentMethods': paymentMethodByPaymentUrl } }
200
215
  });
@@ -31,13 +31,6 @@ function verifyToken4reservation(params) {
31
31
  orderNumber: payload.orderNumber,
32
32
  reservationId: params.reservationId
33
33
  });
34
- // 注文検索
35
- // const order: Pick<factory.order.IOrder, 'orderStatus' | 'acceptedOffers'> =
36
- // await repos.order.findByOrderNumber({
37
- // orderNumber: payload.orderNumber,
38
- // inclusion: ['orderStatus', 'acceptedOffers'],
39
- // exclusion: []
40
- // });
41
34
  // ステータス検証
42
35
  switch (order.orderStatus) {
43
36
  case factory.orderStatus.OrderDelivered:
@@ -75,7 +68,7 @@ function useReservation(params) {
75
68
  // 取得属性最適化(2023-01-30~)
76
69
  const reservation = yield repos.reservation.findById({
77
70
  id: reservationId,
78
- inclusion: ['id', 'issuedThrough', 'project', 'reservationFor', 'reservationNumber', 'reservedTicket', 'typeOf']
71
+ inclusion: ['_id', 'issuedThrough', 'project', 'reservationFor', 'reservationNumber', 'reservedTicket', 'typeOf']
79
72
  });
80
73
  // instrument?.tokenを検証
81
74
  const token = (_a = params === null || params === void 0 ? void 0 : params.instrument) === null || _a === void 0 ? void 0 : _a.token;
@@ -16,11 +16,20 @@ export type TaskOperation<T> = (repos: {
16
16
  task: TaskRepo;
17
17
  }) => Promise<T>;
18
18
  export type IOperation<T> = (settings: IConnectionSettings) => Promise<T>;
19
+ export declare function executeById(params: {
20
+ id: string;
21
+ executor?: {
22
+ name: string;
23
+ };
24
+ }): IOperation<void>;
19
25
  /**
20
26
  * タスク名でタスクをひとつ実行する
21
27
  */
22
28
  export declare function executeByName<T extends factory.taskName>(params: {
23
29
  name: T;
30
+ executor?: {
31
+ name: string;
32
+ };
24
33
  }): IOperation<void>;
25
34
  /**
26
35
  * タスクを実行する
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.notifyAbortedTasks = exports.abort = exports.retry = exports.execute = exports.executeByName = void 0;
12
+ exports.notifyAbortedTasks = exports.abort = exports.retry = exports.execute = exports.executeByName = exports.executeById = void 0;
13
13
  /**
14
14
  * タスクサービス
15
15
  */
@@ -18,19 +18,54 @@ const factory = require("../factory");
18
18
  const task_1 = require("../repo/task");
19
19
  const NotificationService = require("./notification");
20
20
  const factory_1 = require("./notification/factory");
21
+ const credentials_1 = require("../credentials");
21
22
  const settings_1 = require("../settings");
22
23
  const debug = createDebug('chevre-domain:service:task');
24
+ const DEFAULT_EXECUTOR_NAME = `${process.env.GAE_APPLICATION}:${process.env.GAE_SERVICE}:jobs`;
25
+ function executeById(params) {
26
+ return (settings) => __awaiter(this, void 0, void 0, function* () {
27
+ var _a;
28
+ const taskRepo = new task_1.MongoRepository(settings.connection);
29
+ // 未実行のタスクを取得
30
+ // tslint:disable-next-line:no-null-keyword
31
+ let task = null;
32
+ try {
33
+ task = yield taskRepo.executeById({
34
+ id: params.id,
35
+ executor: {
36
+ name: (typeof ((_a = params.executor) === null || _a === void 0 ? void 0 : _a.name) === 'string') ? params.executor.name : DEFAULT_EXECUTOR_NAME
37
+ }
38
+ });
39
+ }
40
+ catch (error) {
41
+ // tslint:disable-next-line:no-single-line-block-comment
42
+ /* istanbul ignore next */
43
+ debug('service.task.executeById error:', error);
44
+ }
45
+ // タスクがなければ終了
46
+ if (task !== null) {
47
+ yield execute(task)(settings);
48
+ }
49
+ });
50
+ }
51
+ exports.executeById = executeById;
23
52
  /**
24
53
  * タスク名でタスクをひとつ実行する
25
54
  */
26
55
  function executeByName(params) {
27
56
  return (settings) => __awaiter(this, void 0, void 0, function* () {
57
+ var _a;
28
58
  const taskRepo = new task_1.MongoRepository(settings.connection);
29
59
  // 未実行のタスクを取得
30
60
  // tslint:disable-next-line:no-null-keyword
31
61
  let task = null;
32
62
  try {
33
- task = yield taskRepo.executeOneByName(params);
63
+ task = yield taskRepo.executeOneByName({
64
+ name: params.name,
65
+ executor: {
66
+ name: (typeof ((_a = params.executor) === null || _a === void 0 ? void 0 : _a.name) === 'string') ? params.executor.name : DEFAULT_EXECUTOR_NAME
67
+ }
68
+ });
34
69
  }
35
70
  catch (error) {
36
71
  // tslint:disable-next-line:no-single-line-block-comment
@@ -106,7 +141,9 @@ function abort(params) {
106
141
  }
107
142
  // 開発者へ報告
108
143
  const message = (0, factory_1.task2lineNotify)({ task: abortedTask });
109
- yield NotificationService.report2developers(message.subject, message.content)();
144
+ yield NotificationService.report2developers(message.subject, message.content)({
145
+ accessToken: credentials_1.credentials.lineNotify.accessTokenAlert
146
+ });
110
147
  }
111
148
  });
112
149
  }
@@ -123,7 +160,9 @@ function notifyAbortedTasks(params) {
123
160
  if (abortedTasks.length > 0) {
124
161
  // 開発者へ報告
125
162
  const message = (0, factory_1.tasks2lineNotify)({ tasks: abortedTasks });
126
- yield NotificationService.report2developers(message.subject, message.content)();
163
+ yield NotificationService.report2developers(message.subject, message.content)({
164
+ accessToken: credentials_1.credentials.lineNotify.accessTokenAlert
165
+ });
127
166
  }
128
167
  });
129
168
  }
@@ -576,9 +576,7 @@ function exportTasksById(params) {
576
576
  transaction,
577
577
  runsAt: taskRunsAt
578
578
  });
579
- // saveManyに変更(2023-02-01~)
580
- yield repos.task.saveMany(taskAttributes);
581
- // await Promise.all(taskAttributes.map(async (a) => repos.task.save(a)));
579
+ yield repos.task.saveMany(taskAttributes, { emitImmediately: true });
582
580
  });
583
581
  }
584
582
  exports.exportTasksById = exportTasksById;
@@ -78,7 +78,21 @@ function createTasks(params) {
78
78
  object: transaction
79
79
  }
80
80
  };
81
- taskAttributes.push(...triggerWebhookTaskAttributes, deleteTransactionTask);
81
+ // 確定取引にも決済承認中止タスクを追加(2023-05-03~)
82
+ const voidPaymentTaskAttributes = {
83
+ project: transaction.project,
84
+ name: factory.taskName.VoidPayTransaction,
85
+ status: factory.taskStatus.Ready,
86
+ runsAt: taskRunsAt,
87
+ remainingNumberOfTries: 10,
88
+ numberOfTried: 0,
89
+ executionResults: [],
90
+ data: {
91
+ project: transaction.project,
92
+ purpose: { typeOf: transaction.typeOf, id: transaction.id }
93
+ }
94
+ };
95
+ taskAttributes.push(...triggerWebhookTaskAttributes, deleteTransactionTask, voidPaymentTaskAttributes);
82
96
  switch (transaction.status) {
83
97
  case factory.transactionStatusType.Confirmed:
84
98
  const potentialActions = transaction.potentialActions;
@@ -107,7 +121,6 @@ function createTasks(params) {
107
121
  };
108
122
  taskAttributes.push(placeOrderTaskAttributes);
109
123
  break;
110
- // 期限切れor中止の場合は、タスクリストを作成する
111
124
  case factory.transactionStatusType.Canceled:
112
125
  case factory.transactionStatusType.Expired:
113
126
  const voidReserveTaskAttributes = {
@@ -136,19 +149,6 @@ function createTasks(params) {
136
149
  purpose: { typeOf: transaction.typeOf, id: transaction.id }
137
150
  }
138
151
  };
139
- const voidPaymentTaskAttributes = {
140
- project: transaction.project,
141
- name: factory.taskName.VoidPayTransaction,
142
- status: factory.taskStatus.Ready,
143
- runsAt: taskRunsAt,
144
- remainingNumberOfTries: 10,
145
- numberOfTried: 0,
146
- executionResults: [],
147
- data: {
148
- project: transaction.project,
149
- purpose: { typeOf: transaction.typeOf, id: transaction.id }
150
- }
151
- };
152
152
  const voidMoneyTransferTaskAttributes = {
153
153
  project: transaction.project,
154
154
  name: factory.taskName.VoidMoneyTransferTransaction,
@@ -162,7 +162,7 @@ function createTasks(params) {
162
162
  purpose: { typeOf: transaction.typeOf, id: transaction.id }
163
163
  }
164
164
  };
165
- taskAttributes.push(voidReserveTaskAttributes, voidRegisterServiceTaskAttributes, voidPaymentTaskAttributes, voidMoneyTransferTaskAttributes);
165
+ taskAttributes.push(voidReserveTaskAttributes, voidRegisterServiceTaskAttributes, voidMoneyTransferTaskAttributes);
166
166
  break;
167
167
  default:
168
168
  throw new factory.errors.NotImplemented(`Transaction status "${transaction.status}" not implemented.`);
@@ -36,11 +36,7 @@ function exportTasksById(params) {
36
36
  transaction,
37
37
  runsAt: taskRunsAt
38
38
  });
39
- // saveManyに変更(2023-02-01~)
40
- yield repos.task.saveMany(taskAttributes);
41
- // await Promise.all(taskAttributes.map(async (taskAttribute) => {
42
- // await repos.task.save(taskAttribute);
43
- // }));
39
+ yield repos.task.saveMany(taskAttributes, { emitImmediately: true });
44
40
  });
45
41
  }
46
42
  exports.exportTasksById = exportTasksById;
@@ -311,7 +311,7 @@ function authorizeAward(params) {
311
311
  if (Array.isArray(givePointAwardParams)) {
312
312
  const pointAwardIdentifiers = givePointAwardParams.map((g) => { var _a; return String((_a = g.object) === null || _a === void 0 ? void 0 : _a.identifier); });
313
313
  // 取引にインセンティブ付与アクションパラメータを保管する
314
- yield repos.transaction.findByIdAndUpdate({
314
+ yield repos.transaction.findByIdAndUpdateInProgress({
315
315
  id: transaction.id,
316
316
  update: {
317
317
  $set: {
@@ -339,7 +339,7 @@ function voidAward(params) {
339
339
  if (transaction.agent.id !== params.agent.id) {
340
340
  throw new factory.errors.Forbidden('Transaction not yours');
341
341
  }
342
- yield repos.transaction.findByIdAndUpdate({
342
+ yield repos.transaction.findByIdAndUpdateInProgress({
343
343
  id: transaction.id,
344
344
  update: {
345
345
  $unset: {
@@ -384,11 +384,7 @@ function exportTasksById(params) {
384
384
  transaction,
385
385
  runsAt: taskRunsAt
386
386
  });
387
- // saveManyに変更(2023-02-01~)
388
- yield repos.task.saveMany(taskAttributes);
389
- // await Promise.all(taskAttributes.map(async (taskAttribute) => {
390
- // await repos.task.save(taskAttribute);
391
- // }));
387
+ yield repos.task.saveMany(taskAttributes, { emitImmediately: true });
392
388
  });
393
389
  }
394
390
  exports.exportTasksById = exportTasksById;
@@ -45,6 +45,12 @@ export declare function exportTasks<T extends factory.transactionType>(params: {
45
45
  typeOf?: {
46
46
  $in: T[];
47
47
  };
48
+ id?: string;
49
+ tasksExportAction?: {
50
+ agent: {
51
+ name: string;
52
+ };
53
+ };
48
54
  }): IExportTasksOperation<void>;
49
55
  /**
50
56
  * 取引に関わるリソースを削除する
@@ -19,6 +19,7 @@ const MoneyTransferTransactionService = require("./transaction/moneyTransfer");
19
19
  const PlaceOrderTransactionService = require("./transaction/placeOrder");
20
20
  const PlaceOrderInProgressTransactionService = require("./transaction/placeOrderInProgress");
21
21
  const ReturnOrderTransactionService = require("./transaction/returnOrder");
22
+ const settings_1 = require("../settings");
22
23
  exports.moneyTransfer = MoneyTransferTransactionService;
23
24
  exports.placeOrder = PlaceOrderTransactionService;
24
25
  exports.placeOrderInProgress = PlaceOrderInProgressTransactionService;
@@ -77,15 +78,17 @@ exports.updateAgent = updateAgent;
77
78
  */
78
79
  function exportTasks(params) {
79
80
  return (repos) => __awaiter(this, void 0, void 0, function* () {
80
- const transaction = yield repos.transaction.startExportTasks({
81
- project: params.project,
82
- typeOf: params.typeOf,
83
- status: params.status
84
- });
81
+ var _a;
82
+ const transaction = yield repos.transaction.startExportTasks(Object.assign({ project: params.project, typeOf: params.typeOf, status: params.status, tasksExportAction: {
83
+ agent: {
84
+ name: (typeof ((_a = params.tasksExportAction) === null || _a === void 0 ? void 0 : _a.agent.name) === 'string')
85
+ ? params.tasksExportAction.agent.name
86
+ : settings_1.DEFAULT_TASKS_EXPORT_AGENT_NAME
87
+ }
88
+ } }, (typeof params.id === 'string') ? { id: params.id } : undefined));
85
89
  if (transaction === null) {
86
90
  return;
87
91
  }
88
- // let tasks: factory.task.ITask<factory.taskName>[] = [];
89
92
  // 失敗してもここでは戻さない(RUNNINGのまま待機)
90
93
  switch (transaction.typeOf) {
91
94
  case factory.transactionType.MoneyTransfer:
@@ -109,7 +112,6 @@ function exportTasks(params) {
109
112
  default:
110
113
  }
111
114
  yield repos.transaction.setTasksExportedById({ id: transaction.id });
112
- // return tasks;
113
115
  });
114
116
  }
115
117
  exports.exportTasks = exportTasks;
@@ -27,10 +27,12 @@ export type ISettings = factory.project.ISettings & {
27
27
  useOfferRateLimitProjects: string[];
28
28
  };
29
29
  export declare const DEFAULT_PAYMENT_METHOD_TYPE_FOR_CREDIT_CARD: string;
30
+ export declare const DEFAULT_TASKS_EXPORT_AGENT_NAME: string;
30
31
  export declare const USE_ASSET_TRANSACTION_SYNC_PROCESSING: boolean;
31
32
  export declare const USE_PAY_ASSET_TRANSACTION_SYNC_PROCESSING: boolean;
32
33
  export declare const USE_NEW_EVENT_AVAILABILITY_KEY_FROM: moment.Moment;
33
- export declare const USE_NEW_ORDER_NUMBER_KEY_FROM: moment.Moment;
34
+ export declare const USE_NEW_CONFIRMATION_NUMBER_KEY_FROM: moment.Moment;
35
+ export declare const USE_EVENT_EMITTERS: boolean;
34
36
  /**
35
37
  * グローバル設定
36
38
  */
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.settings = exports.USE_NEW_ORDER_NUMBER_KEY_FROM = exports.USE_NEW_EVENT_AVAILABILITY_KEY_FROM = exports.USE_PAY_ASSET_TRANSACTION_SYNC_PROCESSING = exports.USE_ASSET_TRANSACTION_SYNC_PROCESSING = exports.DEFAULT_PAYMENT_METHOD_TYPE_FOR_CREDIT_CARD = exports.DEFAULT_SENDER_EMAIL = exports.TRANSACTION_CANCELED_STORAGE_PERIOD_IN_DAYS = exports.TRANSACTION_CONFIRMED_STORAGE_PERIOD_IN_DAYS = exports.ASSET_TRANSACTION_STORAGE_PERIOD_IN_DAYS = exports.ABORTED_TASKS_WITHOUT_REPORT = void 0;
3
+ exports.settings = exports.USE_EVENT_EMITTERS = exports.USE_NEW_CONFIRMATION_NUMBER_KEY_FROM = exports.USE_NEW_EVENT_AVAILABILITY_KEY_FROM = exports.USE_PAY_ASSET_TRANSACTION_SYNC_PROCESSING = exports.USE_ASSET_TRANSACTION_SYNC_PROCESSING = exports.DEFAULT_TASKS_EXPORT_AGENT_NAME = exports.DEFAULT_PAYMENT_METHOD_TYPE_FOR_CREDIT_CARD = exports.DEFAULT_SENDER_EMAIL = exports.TRANSACTION_CANCELED_STORAGE_PERIOD_IN_DAYS = exports.TRANSACTION_CONFIRMED_STORAGE_PERIOD_IN_DAYS = exports.ASSET_TRANSACTION_STORAGE_PERIOD_IN_DAYS = exports.ABORTED_TASKS_WITHOUT_REPORT = void 0;
4
4
  const moment = require("moment");
5
5
  const factory = require("./factory");
6
6
  const transactionWebhookUrls = (typeof process.env.INFORM_TRANSACTION_URL === 'string')
@@ -44,14 +44,16 @@ exports.TRANSACTION_CANCELED_STORAGE_PERIOD_IN_DAYS = (typeof process.env.TRANSA
44
44
  : 7;
45
45
  exports.DEFAULT_SENDER_EMAIL = process.env.DEFAULT_SENDER_EMAIL;
46
46
  exports.DEFAULT_PAYMENT_METHOD_TYPE_FOR_CREDIT_CARD = String(process.env.DEFAULT_PAYMENT_METHOD_TYPE_FOR_CREDIT_CARD);
47
+ exports.DEFAULT_TASKS_EXPORT_AGENT_NAME = `${process.env.GAE_APPLICATION}:${process.env.GAE_SERVICE}:jobs`;
47
48
  exports.USE_ASSET_TRANSACTION_SYNC_PROCESSING = process.env.USE_ASSET_TRANSACTION_SYNC_PROCESSING === '1';
48
49
  exports.USE_PAY_ASSET_TRANSACTION_SYNC_PROCESSING = process.env.USE_PAY_ASSET_TRANSACTION_SYNC_PROCESSING === '1';
49
50
  exports.USE_NEW_EVENT_AVAILABILITY_KEY_FROM = (typeof process.env.USE_NEW_EVENT_AVAILABILITY_KEY_FROM === 'string')
50
51
  ? moment(process.env.USE_NEW_EVENT_AVAILABILITY_KEY_FROM)
51
- : moment('2023-07-23T15:00:00Z');
52
- exports.USE_NEW_ORDER_NUMBER_KEY_FROM = (typeof process.env.USE_NEW_ORDER_NUMBER_KEY_FROM === 'string')
53
- ? moment(process.env.USE_NEW_ORDER_NUMBER_KEY_FROM)
52
+ : moment('2023-08-31T15:00:00Z');
53
+ exports.USE_NEW_CONFIRMATION_NUMBER_KEY_FROM = (typeof process.env.USE_NEW_CONFIRMATION_NUMBER_KEY_FROM === 'string')
54
+ ? moment(process.env.USE_NEW_CONFIRMATION_NUMBER_KEY_FROM)
54
55
  : moment('2023-04-30T15:00:00Z');
56
+ exports.USE_EVENT_EMITTERS = process.env.USE_EVENT_EMITTERS === '1';
55
57
  /**
56
58
  * グローバル設定
57
59
  */
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  }
10
10
  ],
11
11
  "dependencies": {
12
- "@chevre/factory": "4.310.0",
12
+ "@chevre/factory": "4.311.0",
13
13
  "@cinerino/sdk": "3.154.0",
14
14
  "@motionpicture/coa-service": "9.2.0",
15
15
  "@motionpicture/gmo-service": "5.2.0",
@@ -58,7 +58,7 @@
58
58
  "googleapis": "^85.0.0",
59
59
  "json2csv": "4.5.4",
60
60
  "mocha": "^5.2.0",
61
- "mongoose": "6.10.4",
61
+ "mongoose": "7.0.5",
62
62
  "nock": "^9.6.1",
63
63
  "nyc": "^15.1.0",
64
64
  "power-assert": "^1.6.1",
@@ -74,7 +74,7 @@
74
74
  },
75
75
  "peerDependencies": {
76
76
  "aws-sdk": "^2.0.0",
77
- "mongoose": "^6.0.0",
77
+ "mongoose": "^7.0.5",
78
78
  "redis": "^4.6.5"
79
79
  },
80
80
  "engines": {
@@ -117,5 +117,5 @@
117
117
  "postversion": "git push origin --tags",
118
118
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
119
119
  },
120
- "version": "21.2.0-alpha.3"
120
+ "version": "21.2.0-alpha.30"
121
121
  }