@chevre/domain 21.20.0-alpha.8 → 21.20.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 (230) hide show
  1. package/example/src/chevre/findTransactionById.ts +21 -0
  2. package/example/src/chevre/importCategoryCodesFromCOA.ts +2 -1
  3. package/example/src/chevre/importOffersFromCOA.ts +2 -1
  4. package/example/src/chevre/migrateActionInstrumentTransactionNumber.ts +93 -0
  5. package/example/src/chevre/migrateDeleteTransactionTasks.ts +119 -0
  6. package/example/src/chevre/migrateEventMakesOfferAvailableAtOrFrom.ts +87 -0
  7. package/example/src/chevre/migrateIAMMemberPOSRoles.ts +3 -2
  8. package/example/src/chevre/migrateOfferAvailableAtOrFrom.ts +63 -0
  9. package/example/src/chevre/{migrateOrderPaymentMethodIdentifier.ts → migrateOrderAcceptedOfferSerialNumber.ts} +18 -19
  10. package/example/src/chevre/onAssetTransactionStatusChanged.ts +36 -0
  11. package/example/src/chevre/retryTasks.ts +39 -0
  12. package/example/src/chevre/searchActions.ts +13 -7
  13. package/example/src/chevre/searchOrderAcceptedOffers.ts +13 -3
  14. package/example/src/chevre/searchOrders.ts +13 -15
  15. package/example/src/chevre/searchSlicedAcceptedOffersByOrderNumber.ts +28 -0
  16. package/example/src/chevre/sendOrder.ts +37 -0
  17. package/example/src/chevre/transaction/processPlaceOrder.ts +2 -3
  18. package/example/src/verifyToken.ts +44 -0
  19. package/lib/chevre/credentials.d.ts +2 -0
  20. package/lib/chevre/credentials.js +4 -2
  21. package/lib/chevre/errorHandler.js +3 -0
  22. package/lib/chevre/factory/order.d.ts +1 -0
  23. package/lib/chevre/factory/order.js +2 -1
  24. package/lib/chevre/factory/reservedAgentIdentifireNames.js +2 -1
  25. package/lib/chevre/factory/transaction.d.ts +10 -1
  26. package/lib/chevre/repo/acceptedOffer.d.ts +58 -2
  27. package/lib/chevre/repo/acceptedOffer.js +100 -4
  28. package/lib/chevre/repo/accountingReport.d.ts +33 -7
  29. package/lib/chevre/repo/accountingReport.js +157 -5
  30. package/lib/chevre/repo/action.d.ts +32 -8
  31. package/lib/chevre/repo/action.js +114 -54
  32. package/lib/chevre/repo/event.d.ts +20 -0
  33. package/lib/chevre/repo/event.js +22 -0
  34. package/lib/chevre/repo/member.d.ts +8 -1
  35. package/lib/chevre/repo/member.js +7 -1
  36. package/lib/chevre/repo/mongoose/schemas/accountingReport.js +2 -1
  37. package/lib/chevre/repo/mongoose/schemas/action.d.ts +1 -1
  38. package/lib/chevre/repo/mongoose/schemas/action.js +25 -11
  39. package/lib/chevre/repo/mongoose/schemas/order.d.ts +1 -1
  40. package/lib/chevre/repo/mongoose/schemas/order.js +38 -11
  41. package/lib/chevre/repo/offer.d.ts +42 -0
  42. package/lib/chevre/repo/offer.js +35 -0
  43. package/lib/chevre/repo/order.js +43 -20
  44. package/lib/chevre/repo/orderInTransaction.d.ts +44 -0
  45. package/lib/chevre/repo/orderInTransaction.js +164 -0
  46. package/lib/chevre/repo/paymentServiceProvider.js +2 -1
  47. package/lib/chevre/repo/person.js +1 -4
  48. package/lib/chevre/repo/task.d.ts +26 -3
  49. package/lib/chevre/repo/task.js +61 -46
  50. package/lib/chevre/repo/transaction.d.ts +2 -2
  51. package/lib/chevre/repo/transaction.js +13 -36
  52. package/lib/chevre/repository.d.ts +5 -0
  53. package/lib/chevre/repository.js +15 -2
  54. package/lib/chevre/service/aggregation/event/importFromCOA.js +5 -5
  55. package/lib/chevre/service/assetTransaction/pay/factory.js +1 -6
  56. package/lib/chevre/service/assetTransaction/pay/potentialActions/createPayObjectServiceOutput.d.ts +9 -0
  57. package/lib/chevre/service/assetTransaction/pay/potentialActions/createPayObjectServiceOutput.js +143 -0
  58. package/lib/chevre/service/assetTransaction/pay/potentialActions.d.ts +11 -3
  59. package/lib/chevre/service/assetTransaction/pay/potentialActions.js +4 -165
  60. package/lib/chevre/service/assetTransaction/pay.d.ts +21 -6
  61. package/lib/chevre/service/assetTransaction/pay.js +64 -23
  62. package/lib/chevre/service/assetTransaction/reserve/factory.js +11 -14
  63. package/lib/chevre/service/assetTransaction/reserveCOA.d.ts +19 -0
  64. package/lib/chevre/service/assetTransaction/reserveCOA.js +46 -0
  65. package/lib/chevre/service/code.js +1 -1
  66. package/lib/chevre/service/delivery.js +2 -2
  67. package/lib/chevre/service/event/createEvent.js +1 -1
  68. package/lib/chevre/service/event.js +16 -24
  69. package/lib/chevre/service/moneyTransfer.js +1 -1
  70. package/lib/chevre/service/notification.js +71 -66
  71. package/lib/chevre/service/offer/any.d.ts +35 -0
  72. package/lib/chevre/service/offer/any.js +67 -0
  73. package/lib/chevre/service/offer/event/authorize.d.ts +7 -0
  74. package/lib/chevre/service/offer/event/authorize.js +27 -17
  75. package/lib/chevre/service/offer/event/cancel.d.ts +2 -0
  76. package/lib/chevre/service/offer/event/cancel.js +13 -1
  77. package/lib/chevre/service/offer/event/factory.d.ts +1 -1
  78. package/lib/chevre/service/offer/event/factory.js +11 -22
  79. package/lib/chevre/service/offer/event/importFromCOA.js +6 -8
  80. package/lib/chevre/service/offer/event/voidTransaction.d.ts +2 -0
  81. package/lib/chevre/service/offer/event/voidTransaction.js +24 -7
  82. package/lib/chevre/service/offer/eventServiceByCOA/authorize.d.ts +54 -0
  83. package/lib/chevre/service/offer/eventServiceByCOA/authorize.js +138 -0
  84. package/lib/chevre/service/offer/eventServiceByCOA/cancel.d.ts +39 -0
  85. package/lib/chevre/service/offer/eventServiceByCOA/cancel.js +59 -0
  86. package/lib/chevre/service/offer/eventServiceByCOA/changeOffers.d.ts +25 -0
  87. package/lib/chevre/service/offer/eventServiceByCOA/changeOffers.js +165 -0
  88. package/lib/chevre/service/offer/eventServiceByCOA/factory.js +10 -23
  89. package/lib/chevre/service/offer/eventServiceByCOA.d.ts +4 -89
  90. package/lib/chevre/service/offer/eventServiceByCOA.js +7 -292
  91. package/lib/chevre/service/offer/moneyTransfer/authorize.d.ts +10 -1
  92. package/lib/chevre/service/offer/moneyTransfer/authorize.js +49 -3
  93. package/lib/chevre/service/offer/moneyTransfer/returnMoneyTransfer.js +1 -1
  94. package/lib/chevre/service/offer/moneyTransfer/settleTransaction.d.ts +2 -0
  95. package/lib/chevre/service/offer/moneyTransfer/settleTransaction.js +47 -2
  96. package/lib/chevre/service/offer/moneyTransfer/voidTransaction.js +1 -1
  97. package/lib/chevre/service/offer/product/factory.js +2 -5
  98. package/lib/chevre/service/offer/product.d.ts +2 -0
  99. package/lib/chevre/service/offer/product.js +11 -23
  100. package/lib/chevre/service/order/confirmPayTransaction.d.ts +3 -1
  101. package/lib/chevre/service/order/confirmPayTransaction.js +5 -5
  102. package/lib/chevre/service/order/createAccountingReportIfNotExist.js +1 -1
  103. package/lib/chevre/service/order/onAssetTransactionStatusChanged.d.ts +12 -1
  104. package/lib/chevre/service/order/onAssetTransactionStatusChanged.js +206 -7
  105. package/lib/chevre/service/order/onOrderStatusChanged/onOrderCancelled/factory.d.ts +1 -1
  106. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered/factory.d.ts +1 -1
  107. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered/factory.js +51 -53
  108. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered.d.ts +1 -1
  109. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered.js +10 -25
  110. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDeliveredPartially/factory.d.ts +16 -0
  111. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDeliveredPartially/factory.js +91 -0
  112. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDeliveredPartially.d.ts +8 -0
  113. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDeliveredPartially.js +37 -0
  114. package/lib/chevre/service/order/onOrderStatusChanged/onOrderInTransit.d.ts +12 -0
  115. package/lib/chevre/service/order/onOrderStatusChanged/onOrderInTransit.js +115 -0
  116. package/lib/chevre/service/order/onOrderStatusChanged/onOrderPaymentDue.js +19 -1
  117. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/createSendEmailMessageTaskIfNotExist.d.ts +8 -0
  118. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/createSendEmailMessageTaskIfNotExist.js +41 -0
  119. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/factory.d.ts +6 -10
  120. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/factory.js +116 -92
  121. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing.d.ts +4 -1
  122. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing.js +81 -84
  123. package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned/factory.d.ts +1 -1
  124. package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned/factory.js +18 -15
  125. package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned.js +62 -1
  126. package/lib/chevre/service/order/onOrderStatusChanged.d.ts +3 -1
  127. package/lib/chevre/service/order/onOrderStatusChanged.js +5 -1
  128. package/lib/chevre/service/order/placeOrder.d.ts +3 -1
  129. package/lib/chevre/service/order/placeOrder.js +157 -50
  130. package/lib/chevre/service/order/returnOrder.js +25 -16
  131. package/lib/chevre/service/order/sendOrder.d.ts +5 -0
  132. package/lib/chevre/service/order/sendOrder.js +67 -33
  133. package/lib/chevre/service/payment/any/onPaid.js +1 -1
  134. package/lib/chevre/service/payment/any/onPaymentStatusChanged/onPaid.d.ts +3 -1
  135. package/lib/chevre/service/payment/any/onPaymentStatusChanged/onPaid.js +15 -9
  136. package/lib/chevre/service/payment/any/onPaymentStatusChanged/onRefunded.d.ts +3 -1
  137. package/lib/chevre/service/payment/any/onPaymentStatusChanged/onRefunded.js +8 -5
  138. package/lib/chevre/service/payment/any/onPaymentStatusChanged.js +2 -2
  139. package/lib/chevre/service/payment/any/onRefund.js +1 -1
  140. package/lib/chevre/service/payment/any.d.ts +6 -5
  141. package/lib/chevre/service/payment/any.js +3 -2
  142. package/lib/chevre/service/payment/creditCard.d.ts +1 -1
  143. package/lib/chevre/service/payment/creditCard.js +62 -68
  144. package/lib/chevre/service/payment/faceToFace.d.ts +1 -5
  145. package/lib/chevre/service/payment/movieTicket/checkByIdentifier.d.ts +0 -2
  146. package/lib/chevre/service/payment/movieTicket/checkByIdentifier.js +1 -0
  147. package/lib/chevre/service/payment/movieTicket/validation.d.ts +0 -2
  148. package/lib/chevre/service/payment/movieTicket.d.ts +1 -7
  149. package/lib/chevre/service/payment/movieTicket.js +1 -1
  150. package/lib/chevre/service/payment/paymentCard.d.ts +1 -3
  151. package/lib/chevre/service/payment/paymentCard.js +6 -6
  152. package/lib/chevre/service/payment.d.ts +5 -0
  153. package/lib/chevre/service/payment.js +40 -5
  154. package/lib/chevre/service/product.js +1 -1
  155. package/lib/chevre/service/reserve/cancelReservation.js +2 -2
  156. package/lib/chevre/service/reserve/checkInReservation.d.ts +1 -3
  157. package/lib/chevre/service/reserve/checkInReservation.js +6 -5
  158. package/lib/chevre/service/reserve/confirmReservation.js +1 -1
  159. package/lib/chevre/service/reserve/factory.js +0 -8
  160. package/lib/chevre/service/reserve/potentialActions/onReservationUsed.d.ts +1 -1
  161. package/lib/chevre/service/reserve/potentialActions/onReservationUsed.js +4 -4
  162. package/lib/chevre/service/reserve/searchByOrder.js +2 -1
  163. package/lib/chevre/service/reserve/useReservation.d.ts +1 -3
  164. package/lib/chevre/service/reserve/useReservation.js +10 -9
  165. package/lib/chevre/service/reserve/verifyToken4reservation.js +2 -0
  166. package/lib/chevre/service/task/confirmMoneyTransfer.js +4 -4
  167. package/lib/chevre/service/task/confirmPayTransaction.js +2 -1
  168. package/lib/chevre/service/task/confirmRegisterServiceTransaction.d.ts +1 -1
  169. package/lib/chevre/service/task/confirmRegisterServiceTransaction.js +30 -8
  170. package/lib/chevre/service/task/confirmReserveTransaction.d.ts +6 -1
  171. package/lib/chevre/service/task/confirmReserveTransaction.js +176 -29
  172. package/lib/chevre/service/task/createAccountingReport.d.ts +6 -0
  173. package/lib/chevre/service/task/createAccountingReport.js +80 -0
  174. package/lib/chevre/service/task/importOffersFromCOA.js +2 -1
  175. package/lib/chevre/service/task/onAuthorizationCreated.js +0 -1
  176. package/lib/chevre/service/task/onResourceUpdated/onResourceDeleted.js +7 -7
  177. package/lib/chevre/service/task/pay.js +6 -0
  178. package/lib/chevre/service/task/placeOrder.js +9 -10
  179. package/lib/chevre/service/task/returnOrder.js +0 -3
  180. package/lib/chevre/service/task/returnPayTransaction.js +1 -1
  181. package/lib/chevre/service/task/returnReserveTransaction.js +3 -2
  182. package/lib/chevre/service/task/sendOrder.js +8 -4
  183. package/lib/chevre/service/task/useReservation.js +1 -1
  184. package/lib/chevre/service/task/voidReserveTransaction.js +8 -12
  185. package/lib/chevre/service/transaction/deleteTransaction.js +1 -1
  186. package/lib/chevre/service/transaction/moneyTransfer/potentialActions.js +2 -18
  187. package/lib/chevre/service/transaction/moneyTransfer.js +7 -6
  188. package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.d.ts +2 -2
  189. package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.js +17 -20
  190. package/lib/chevre/service/transaction/placeOrder.js +2 -1
  191. package/lib/chevre/service/transaction/placeOrderInProgress/confirm.d.ts +51 -0
  192. package/lib/chevre/service/transaction/placeOrderInProgress/confirm.js +268 -0
  193. package/lib/chevre/service/transaction/placeOrderInProgress/factory.d.ts +1 -1
  194. package/lib/chevre/service/transaction/placeOrderInProgress/factory.js +3 -2
  195. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/moneyTransfer.js +1 -1
  196. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions.js +22 -44
  197. package/lib/chevre/service/transaction/placeOrderInProgress/publishCode.d.ts +14 -0
  198. package/lib/chevre/service/transaction/placeOrderInProgress/publishCode.js +41 -0
  199. package/lib/chevre/service/transaction/placeOrderInProgress/publishConfirmationNumberIfNotExist.d.ts +18 -0
  200. package/lib/chevre/service/transaction/placeOrderInProgress/publishConfirmationNumberIfNotExist.js +42 -0
  201. package/lib/chevre/service/transaction/placeOrderInProgress/publishOrderNumberIfNotExist.d.ts +23 -0
  202. package/lib/chevre/service/transaction/placeOrderInProgress/publishOrderNumberIfNotExist.js +46 -0
  203. package/lib/chevre/service/transaction/placeOrderInProgress/result/acceptedOffers.js +34 -37
  204. package/lib/chevre/service/transaction/placeOrderInProgress/result.d.ts +3 -1
  205. package/lib/chevre/service/transaction/placeOrderInProgress/result.js +13 -4
  206. package/lib/chevre/service/transaction/placeOrderInProgress/start.d.ts +19 -0
  207. package/lib/chevre/service/transaction/placeOrderInProgress/start.js +46 -0
  208. package/lib/chevre/service/transaction/placeOrderInProgress/validation/validateStartRequest.d.ts +26 -0
  209. package/lib/chevre/service/transaction/placeOrderInProgress/validation/validateStartRequest.js +109 -0
  210. package/lib/chevre/service/transaction/placeOrderInProgress/validation.d.ts +10 -23
  211. package/lib/chevre/service/transaction/placeOrderInProgress/validation.js +20 -1
  212. package/lib/chevre/service/transaction/placeOrderInProgress.d.ts +11 -73
  213. package/lib/chevre/service/transaction/placeOrderInProgress.js +13 -286
  214. package/lib/chevre/service/transaction/returnOrder/potentialActions/returnPointAward.js +1 -2
  215. package/lib/chevre/service/transaction/returnOrder/potentialActions.d.ts +0 -1
  216. package/lib/chevre/service/transaction/returnOrder/potentialActions.js +8 -3
  217. package/lib/chevre/service/transaction/returnOrder/preStart.js +78 -50
  218. package/lib/chevre/service/transaction/returnOrder.js +3 -10
  219. package/lib/chevre/service.js +0 -10
  220. package/lib/chevre/settings.d.ts +7 -3
  221. package/lib/chevre/settings.js +13 -4
  222. package/package.json +5 -9
  223. package/example/src/chevre/cleanAccountingReports.ts +0 -57
  224. package/example/src/chevre/migratePayTransactionPaymentMethodIdentifier.ts +0 -78
  225. package/lib/chevre/service/transaction/placeOrderInProgress/validation/validateSeller.d.ts +0 -11
  226. package/lib/chevre/service/transaction/placeOrderInProgress/validation/validateSeller.js +0 -30
  227. package/lib/chevre/service/transaction/returnOrder/potentialActions/returnMoneyTransfer.d.ts +0 -7
  228. package/lib/chevre/service/transaction/returnOrder/potentialActions/returnMoneyTransfer.js +0 -82
  229. package/lib/chevre/service/util.d.ts +0 -19
  230. package/lib/chevre/service/util.js +0 -126
@@ -5,21 +5,19 @@ import { chevre } from '../../../lib/index';
5
5
 
6
6
  const project = { id: String(process.env.PROJECT_ID) };
7
7
 
8
+ mongoose.Model.on('index', (...args) => {
9
+ console.error('******** index event emitted. ********\n', args);
10
+ });
11
+
8
12
  async function main() {
9
13
  await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
10
14
 
11
- const orderRepo = await chevre.repository.Order.createInstance(mongoose.connection);
15
+ const indexes = await mongoose.connection.db.collection('orders')
16
+ .indexes();
17
+ // console.log(indexes);
18
+ console.log(indexes.length, 'indexes found');
12
19
 
13
- const order = await orderRepo.findByOrderNumber({
14
- orderNumber: 'CIN4-3943271-4221863',
15
- project: { id: project.id },
16
- inclusion: [
17
- // 'project', 'typeOf', 'orderNumber', 'dateReturned', 'id',
18
- // 'customer', 'returner', 'seller', 'price', 'priceCurrency', 'orderDate'
19
- ],
20
- exclusion: ['acceptedOffers']
21
- });
22
- console.log(order);
20
+ const orderRepo = await chevre.repository.Order.createInstance(mongoose.connection);
23
21
 
24
22
  const orders = await orderRepo.search(
25
23
  {
@@ -30,10 +28,10 @@ async function main() {
30
28
  // itemOffered: {
31
29
  // issuedThrough: { typeOf: { $eq: chevre.factory.product.ProductType.MembershipService } }
32
30
  // }
33
- },
34
- orderedItem: {
35
- $size: 3
36
31
  }
32
+ // orderedItem: {
33
+ // $size: 3
34
+ // }
37
35
  // paymentMethods: {
38
36
  // paymentMethod: { identifier: { $in: ['Cash'] } }
39
37
  // additionalProperty: {
@@ -49,7 +47,7 @@ async function main() {
49
47
  customer: 1
50
48
  }
51
49
  );
52
- console.log('orders found', orders);
50
+ // console.log('orders found', orders);
53
51
  console.log(orders.length, 'orders found');
54
52
  }
55
53
 
@@ -0,0 +1,28 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../lib/index';
5
+
6
+ async function main() {
7
+ await mongoose.connect(<string>process.env.MONGOLAB_URI);
8
+
9
+ const acceptedOfferRepo = await chevre.repository.AcceptedOffer.createInstance(mongoose.connection);
10
+
11
+ const result = await acceptedOfferRepo.searchSlicedAcceptedOffersByOrderNumber(
12
+ {
13
+ orderNumber: { $eq: 'CIN1-3748070-2008463' },
14
+ project: { id: { $eq: String(process.env.PROJECT_ID) } },
15
+ // tslint:disable-next-line:no-magic-numbers
16
+ $slice: [0, 2]
17
+ }
18
+ );
19
+ console.log(result);
20
+ console.log(result.acceptedOffers.map((offer) => {
21
+ return `${(<any>offer.itemOffered).id}`;
22
+ }));
23
+ console.log(result.acceptedOffers.length);
24
+ }
25
+
26
+ main()
27
+ .then(console.log)
28
+ .catch(console.error);
@@ -0,0 +1,37 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../lib/index';
5
+
6
+ const project = { id: String(process.env.PROJECT_ID) };
7
+
8
+ async function main() {
9
+ await mongoose.connect(<string>process.env.MONGOLAB_URI);
10
+
11
+ (await chevre.service.order.createService())
12
+ .sendOrder({
13
+ agent: { id: project.id, typeOf: chevre.factory.organizationType.Project },
14
+ project: { id: project.id },
15
+ object: {
16
+ confirmationNumber: '57761',
17
+ orderNumber: 'CIN1-3748070-2008463',
18
+ previousOrderStatus: chevre.factory.orderStatus.OrderInTransit,
19
+ acceptedOffers: {
20
+ limit: 1,
21
+ page: 1
22
+ }
23
+ },
24
+ useOnOrderStatusChanged: false
25
+ })({
26
+ acceptedOffer: await chevre.repository.AcceptedOffer.createInstance(mongoose.connection),
27
+ action: await chevre.repository.Action.createInstance(mongoose.connection),
28
+ order: await chevre.repository.Order.createInstance(mongoose.connection),
29
+ ownershipInfo: await chevre.repository.OwnershipInfo.createInstance(mongoose.connection),
30
+ task: await chevre.repository.Task.createInstance(mongoose.connection),
31
+ transaction: await chevre.repository.Transaction.createInstance(mongoose.connection)
32
+ });
33
+ }
34
+
35
+ main()
36
+ .then(console.log)
37
+ .catch(console.error);
@@ -40,6 +40,7 @@ async function main() {
40
40
  seller: { id: '59d20831e53ebc2b4e774466' },
41
41
  validateEligibleCustomerType: false
42
42
  })({
43
+ member: await chevre.repository.Member.createInstance(mongoose.connection),
43
44
  seller: await chevre.repository.Seller.createInstance(mongoose.connection),
44
45
  transaction: await chevre.repository.Transaction.createInstance(mongoose.connection)
45
46
  });
@@ -71,7 +72,6 @@ async function main() {
71
72
  paymentService: await chevre.repository.PaymentService.createInstance(mongoose.connection),
72
73
  paymentServiceProvider: await chevre.repository.PaymentServiceProvider.createInstance(mongoose.connection),
73
74
  person: await chevre.repository.Person.createInstance({ userPoolId: '' }),
74
- project: await chevre.repository.Project.createInstance(mongoose.connection),
75
75
  transactionNumber: await chevre.repository.TransactionNumber.createInstance(client),
76
76
  transaction: await chevre.repository.Transaction.createInstance(mongoose.connection)
77
77
  });
@@ -130,12 +130,11 @@ async function main() {
130
130
  paymentServiceProvider: await chevre.repository.PaymentServiceProvider.createInstance(mongoose.connection),
131
131
  person: await chevre.repository.Person.createInstance({ userPoolId: '' }),
132
132
  product: await chevre.repository.Product.createInstance(mongoose.connection),
133
- project: await chevre.repository.Project.createInstance(mongoose.connection),
134
133
  task: await chevre.repository.Task.createInstance(mongoose.connection),
135
134
  transactionNumber: await chevre.repository.TransactionNumber.createInstance(client),
136
135
  transaction: await chevre.repository.Transaction.createInstance(mongoose.connection)
137
136
  });
138
- console.log('payment authorized.', authorizeResult.result);
137
+ console.log('payment authorized.', authorizeResult.id);
139
138
  } else if (jobCd === 'VOID') {
140
139
  await (await chevre.service.payment.any.createService()).invalidatePaymentUrl({
141
140
  project: { id: project.id, typeOf: chevre.factory.organizationType.Project },
@@ -0,0 +1,44 @@
1
+ import * as jwt from 'jsonwebtoken';
2
+ async function verifyMembershipToken(params: {
3
+ token?: string;
4
+ secret: string;
5
+ }): Promise<any> {
6
+ let result: any;
7
+ const { secret, token } = params;
8
+
9
+ if (typeof token === 'string' && token.length > 0) {
10
+ try {
11
+ result = await new Promise<any>((resolve, reject) => {
12
+ jwt.verify(
13
+ token,
14
+ secret,
15
+ {
16
+ // issuer: credentials.jwt.issuer,
17
+ // ...(Array.isArray(params.audience)) ? { audience: params.audience } : undefined
18
+ },
19
+ (err, decoded: any) => {
20
+ if (err instanceof Error) {
21
+ reject(err);
22
+ } else {
23
+ resolve(decoded);
24
+ }
25
+ });
26
+ });
27
+ } catch (error) {
28
+ throw error;
29
+ }
30
+ } else {
31
+ throw new Error('Membership token');
32
+ }
33
+
34
+ return result;
35
+ }
36
+
37
+ verifyMembershipToken({
38
+ token: 'xxx',
39
+ secret: 'xxx'
40
+ })
41
+ // tslint:disable-next-line:no-console
42
+ .then(console.log)
43
+ // tslint:disable-next-line:no-console
44
+ .catch(console.error);
@@ -16,6 +16,7 @@ export declare const credentials: {
16
16
  endpoint: string;
17
17
  refreshToken: string;
18
18
  timeout: number;
19
+ useFetch: boolean;
19
20
  };
20
21
  customSearch: {
21
22
  engineId: string;
@@ -23,6 +24,7 @@ export declare const credentials: {
23
24
  };
24
25
  gmo: {
25
26
  timeout: number;
27
+ useFetch: boolean;
26
28
  };
27
29
  lineNotify: {
28
30
  url: string;
@@ -19,7 +19,8 @@ exports.credentials = {
19
19
  endpoint: process.env.COA_ENDPOINT,
20
20
  refreshToken: process.env.COA_REFRESH_TOKEN,
21
21
  // tslint:disable-next-line:no-magic-numbers
22
- timeout: (typeof process.env.COA_TIMEOUT === 'string') ? Number(process.env.COA_TIMEOUT) : 20000
22
+ timeout: (typeof process.env.COA_TIMEOUT === 'string') ? Number(process.env.COA_TIMEOUT) : 20000,
23
+ useFetch: process.env.COA_USE_FETCH === '1'
23
24
  },
24
25
  customSearch: {
25
26
  engineId: process.env.CUSTOM_SEARCH_ENGINE_ID,
@@ -27,7 +28,8 @@ exports.credentials = {
27
28
  },
28
29
  gmo: {
29
30
  // tslint:disable-next-line:no-magic-numbers
30
- timeout: (typeof process.env.GMO_TIMEOUT === 'string') ? Number(process.env.GMO_TIMEOUT) : 10000
31
+ timeout: (typeof process.env.GMO_TIMEOUT === 'string') ? Number(process.env.GMO_TIMEOUT) : 10000,
32
+ useFetch: process.env.GMO_USE_FETCH === '1'
31
33
  },
32
34
  lineNotify: {
33
35
  url: process.env.LINE_NOTIFY_URL,
@@ -65,6 +65,9 @@ exports.handleMongoError = handleMongoError;
65
65
  function handleCOAError(error) {
66
66
  var _a;
67
67
  let handledError = error;
68
+ if (error.name === 'AbortError') {
69
+ handledError = new factory_1.errors.GatewayTimeout(`Gateway Timeout. name:${error.name} code:${error.code} message:${error.message}`);
70
+ }
68
71
  if (error.name === 'COAServiceError') {
69
72
  // error.requestOptions.uriを処理
70
73
  const uri = (_a = error.requestOptions) === null || _a === void 0 ? void 0 : _a.uri;
@@ -1,4 +1,5 @@
1
1
  import * as factory from '../factory';
2
+ export declare const POINT_AWARD_IDENTIFIER_NAME = "pointAwardIdentifiers";
2
3
  export declare const AWARD_ACCOUNTS_IDENTIFIER_NAME = "awardAccounts";
3
4
  export type IMaskedCustomer = factory.order.ICustomer | Pick<factory.order.ICustomer, 'id' | 'typeOf'>;
4
5
  /**
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createMaskedCustomer = exports.AWARD_ACCOUNTS_IDENTIFIER_NAME = void 0;
3
+ exports.createMaskedCustomer = exports.AWARD_ACCOUNTS_IDENTIFIER_NAME = exports.POINT_AWARD_IDENTIFIER_NAME = void 0;
4
+ exports.POINT_AWARD_IDENTIFIER_NAME = 'pointAwardIdentifiers';
4
5
  exports.AWARD_ACCOUNTS_IDENTIFIER_NAME = 'awardAccounts';
5
6
  const MASKED_PROFILE = '****';
6
7
  /**
@@ -8,5 +8,6 @@ exports.RESERVED_AGENT_IDENTIFIER_NAMES = [
8
8
  'clientId',
9
9
  'sub',
10
10
  'hostname',
11
- 'username'
11
+ 'username',
12
+ 'jti'
12
13
  ];
@@ -18,17 +18,26 @@ export declare namespace placeOrder {
18
18
  * 注文日時
19
19
  */
20
20
  orderDate: Date;
21
+ /**
22
+ * 確認番号のカスタム指定
23
+ */
21
24
  /**
22
25
  * 注文確認URLのカスタム指定
23
26
  */
24
27
  url?: string | IOrderURLGenerator;
25
28
  /**
26
- * 注文アイテム数
29
+ * オファー制約
27
30
  */
28
31
  numItems?: {
29
32
  maxValue?: number;
30
33
  minValue?: number;
31
34
  };
35
+ /**
36
+ * 注文アイテム制約
37
+ */
38
+ orderedItem: {
39
+ maxValue: number;
40
+ };
32
41
  };
33
42
  type IConfirmParams = factory.transaction.placeOrder.IConfirmParams & {
34
43
  project: {
@@ -5,7 +5,12 @@ type IProjection4searchWithUnwoundAcceptedOffers = {
5
5
  } & {
6
6
  _id?: 0 | 1;
7
7
  };
8
- type IDistinctField = 'acceptedOffers.id' | 'acceptedOffers.itemOffered.reservationNumber' | 'acceptedOffers.itemOffered.reservationFor.id' | 'acceptedOffers.itemOffered.issuedThrough.id' | 'acceptedOffers.offeredThrough.identifier' | 'acceptedOffers.itemOffered.reservationFor.superEvent.location.branchCode';
8
+ type IDistinctField = 'acceptedOffers.id' | 'acceptedOffers.itemOffered.reservationNumber' | 'acceptedOffers.itemOffered.reservationFor.id' | 'acceptedOffers.itemOffered.issuedThrough.id' | 'acceptedOffers.itemOffered.typeOf' | 'acceptedOffers.serialNumber' | 'acceptedOffers.offeredThrough.identifier' | 'acceptedOffers.itemOffered.reservationFor.superEvent.location.branchCode' | 'acceptedOffers.itemOffered.object.pendingTransaction.transactionNumber';
9
+ type IAcceptedOffer = factory.order.IAcceptedOffer<factory.order.IItemOffered>;
10
+ interface ISearchSlicedAcceptedOffersResult {
11
+ acceptedOffers: IAcceptedOffer[];
12
+ numAcceptedOffers: number;
13
+ }
9
14
  /**
10
15
  * 注文オファーリポジトリ
11
16
  */
@@ -29,6 +34,7 @@ export declare class MongoRepository {
29
34
  searchAcceptedOffersByOrderNumber(filter: {
30
35
  limit?: number;
31
36
  page?: number;
37
+ $slice?: [number, number];
32
38
  orderNumber: {
33
39
  $eq: string;
34
40
  };
@@ -45,9 +51,47 @@ export declare class MongoRepository {
45
51
  typeOf?: {
46
52
  $in?: string[];
47
53
  };
54
+ reservationFor?: {
55
+ id?: {
56
+ $in?: string[];
57
+ };
58
+ };
59
+ reservedTicket?: {
60
+ ticketedSeat?: {
61
+ seatNumber?: {
62
+ $in?: string[];
63
+ };
64
+ };
65
+ };
48
66
  };
49
67
  };
50
- }, inclusion?: (keyof factory.order.IAcceptedOffer<factory.order.IItemOffered>)[]): Promise<factory.order.IAcceptedOffer<factory.order.IItemOffered>[]>;
68
+ }, inclusion?: (keyof IAcceptedOffer)[]): Promise<IAcceptedOffer[]>;
69
+ /**
70
+ * 注文オファーをsliceして検索する(2024-01-10~)
71
+ */
72
+ searchSlicedAcceptedOffersByOrderNumber(filter: {
73
+ $slice: [number, number];
74
+ orderNumber: {
75
+ $eq: string;
76
+ };
77
+ project: {
78
+ id: {
79
+ $eq: string;
80
+ };
81
+ };
82
+ }): Promise<ISearchSlicedAcceptedOffersResult>;
83
+ countByOrderNumber(filter: {
84
+ orderNumber: {
85
+ $eq: string;
86
+ };
87
+ project: {
88
+ id: {
89
+ $eq: string;
90
+ };
91
+ };
92
+ }): Promise<{
93
+ numAcceptedOffers: number;
94
+ }>;
51
95
  /**
52
96
  * 特定のフィールド値リストを検索する
53
97
  */
@@ -56,5 +100,17 @@ export declare class MongoRepository {
56
100
  $in: string[];
57
101
  };
58
102
  }, field: IDistinctField): Promise<string[]>;
103
+ /**
104
+ * 互換性維持対応専用
105
+ */
106
+ fixSerialNumber(params: {
107
+ project: {
108
+ id: string;
109
+ };
110
+ orderNumber: string;
111
+ acceptedOffers: {
112
+ serialNumber: string;
113
+ };
114
+ }): Promise<void>;
59
115
  }
60
116
  export {};
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.MongoRepository = void 0;
13
+ const factory = require("../factory");
13
14
  const order_1 = require("./mongoose/schemas/order");
14
15
  const order_2 = require("./order");
15
16
  const settings_1 = require("../settings");
@@ -61,6 +62,7 @@ class MongoRepository {
61
62
  }
62
63
  },
63
64
  { $match: { orderNumber: { $eq: filter.orderNumber.$eq } } },
65
+ { $match: { typeOf: { $eq: factory.order.OrderType.Order } } },
64
66
  {
65
67
  $project: {
66
68
  _id: 0,
@@ -83,11 +85,12 @@ class MongoRepository {
83
85
  * 注文オファーを展開して検索する
84
86
  */
85
87
  searchAcceptedOffersByOrderNumber(filter, inclusion) {
86
- var _a, _b, _c;
88
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
87
89
  return __awaiter(this, void 0, void 0, function* () {
88
90
  const matchStages = [
91
+ { $match: { orderNumber: { $eq: filter.orderNumber.$eq } } },
89
92
  { $match: { 'project.id': { $eq: filter.project.id.$eq } } },
90
- { $match: { orderNumber: { $eq: filter.orderNumber.$eq } } }
93
+ { $match: { typeOf: { $eq: factory.order.OrderType.Order } } }
91
94
  ];
92
95
  const itemOfferedTypeOfIn = (_c = (_b = (_a = filter.acceptedOffers) === null || _a === void 0 ? void 0 : _a.itemOffered) === null || _b === void 0 ? void 0 : _b.typeOf) === null || _c === void 0 ? void 0 : _c.$in;
93
96
  if (Array.isArray(itemOfferedTypeOfIn)) {
@@ -95,6 +98,22 @@ class MongoRepository {
95
98
  $match: { 'acceptedOffers.itemOffered.typeOf': { $exists: true, $in: itemOfferedTypeOfIn } }
96
99
  });
97
100
  }
101
+ const resevationForIdIn = (_g = (_f = (_e = (_d = filter.acceptedOffers) === null || _d === void 0 ? void 0 : _d.itemOffered) === null || _e === void 0 ? void 0 : _e.reservationFor) === null || _f === void 0 ? void 0 : _f.id) === null || _g === void 0 ? void 0 : _g.$in;
102
+ if (Array.isArray(resevationForIdIn)) {
103
+ matchStages.push({
104
+ $match: {
105
+ 'acceptedOffers.itemOffered.reservationFor.id': { $exists: true, $in: resevationForIdIn }
106
+ }
107
+ });
108
+ }
109
+ const ticketedSeatNumberIn = (_m = (_l = (_k = (_j = (_h = filter.acceptedOffers) === null || _h === void 0 ? void 0 : _h.itemOffered) === null || _j === void 0 ? void 0 : _j.reservedTicket) === null || _k === void 0 ? void 0 : _k.ticketedSeat) === null || _l === void 0 ? void 0 : _l.seatNumber) === null || _m === void 0 ? void 0 : _m.$in;
110
+ if (Array.isArray(ticketedSeatNumberIn)) {
111
+ matchStages.push({
112
+ $match: {
113
+ 'acceptedOffers.itemOffered.reservedTicket.ticketedSeat.seatNumber': { $exists: true, $in: ticketedSeatNumberIn }
114
+ }
115
+ });
116
+ }
98
117
  const aggregate = this.orderModel.aggregate([
99
118
  // if (typeof params.sort?.orderDate === 'number') {
100
119
  // aggregate.sort({ orderDate: params.sort.orderDate });
@@ -124,7 +143,8 @@ class MongoRepository {
124
143
  typeOf: '$acceptedOffers.typeOf',
125
144
  id: '$acceptedOffers.id',
126
145
  offeredThrough: '$acceptedOffers.offeredThrough',
127
- name: '$acceptedOffers.name'
146
+ name: '$acceptedOffers.name',
147
+ serialNumber: '$acceptedOffers.serialNumber'
128
148
  });
129
149
  }
130
150
  if (typeof filter.limit === 'number' && filter.limit > 0) {
@@ -137,6 +157,54 @@ class MongoRepository {
137
157
  .exec();
138
158
  });
139
159
  }
160
+ /**
161
+ * 注文オファーをsliceして検索する(2024-01-10~)
162
+ */
163
+ searchSlicedAcceptedOffersByOrderNumber(filter) {
164
+ return __awaiter(this, void 0, void 0, function* () {
165
+ const aggregate = this.orderModel.aggregate([
166
+ { $match: { orderNumber: { $eq: filter.orderNumber.$eq } } },
167
+ { $match: { 'project.id': { $eq: filter.project.id.$eq } } },
168
+ { $match: { typeOf: { $eq: factory.order.OrderType.Order } } },
169
+ {
170
+ $project: {
171
+ _id: 0,
172
+ acceptedOffers: { $slice: ['$acceptedOffers', ...filter.$slice] },
173
+ numAcceptedOffers: { $size: '$acceptedOffers' }
174
+ }
175
+ }
176
+ ]);
177
+ const result = (yield aggregate
178
+ .option({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
179
+ .exec()).shift();
180
+ if (result === undefined) {
181
+ throw new factory.errors.NotFound(factory.order.OrderType.Order);
182
+ }
183
+ return result;
184
+ });
185
+ }
186
+ countByOrderNumber(filter) {
187
+ return __awaiter(this, void 0, void 0, function* () {
188
+ const aggregate = this.orderModel.aggregate([
189
+ { $match: { orderNumber: { $eq: filter.orderNumber.$eq } } },
190
+ { $match: { 'project.id': { $eq: filter.project.id.$eq } } },
191
+ { $match: { typeOf: { $eq: factory.order.OrderType.Order } } },
192
+ {
193
+ $project: {
194
+ _id: 0,
195
+ numAcceptedOffers: { $size: '$acceptedOffers' }
196
+ }
197
+ }
198
+ ]);
199
+ const result = (yield aggregate
200
+ .option({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
201
+ .exec()).shift();
202
+ if (result === undefined) {
203
+ throw new factory.errors.NotFound(factory.order.OrderType.Order);
204
+ }
205
+ return result;
206
+ });
207
+ }
140
208
  /**
141
209
  * 特定のフィールド値リストを検索する
142
210
  */
@@ -146,7 +214,8 @@ class MongoRepository {
146
214
  return [];
147
215
  }
148
216
  const filterQuery = {
149
- orderNumber: { $in: filter.orderNumber.$in }
217
+ orderNumber: { $in: filter.orderNumber.$in },
218
+ typeOf: { $eq: factory.order.OrderType.Order }
150
219
  };
151
220
  filterQuery[field] = { $exists: true };
152
221
  return this.orderModel.distinct(field, filterQuery)
@@ -154,5 +223,32 @@ class MongoRepository {
154
223
  .exec();
155
224
  });
156
225
  }
226
+ /**
227
+ * 互換性維持対応専用
228
+ */
229
+ fixSerialNumber(params) {
230
+ return __awaiter(this, void 0, void 0, function* () {
231
+ const doc = yield this.orderModel.findOneAndUpdate({
232
+ orderNumber: { $eq: params.orderNumber },
233
+ 'project.id': { $eq: params.project.id },
234
+ typeOf: { $eq: factory.order.OrderType.Order },
235
+ 'acceptedOffers.itemOffered.reservationNumber': { $exists: true, $eq: params.acceptedOffers.serialNumber }
236
+ }, {
237
+ $set: {
238
+ 'acceptedOffers.$[offer].serialNumber': params.acceptedOffers.serialNumber
239
+ }
240
+ }, {
241
+ arrayFilters: [{ 'offer.itemOffered.reservationNumber': { $eq: params.acceptedOffers.serialNumber } }],
242
+ new: true,
243
+ projection: {
244
+ _id: 1
245
+ }
246
+ })
247
+ .exec();
248
+ if (doc === null) {
249
+ throw new factory.errors.NotFound(this.orderModel.modelName);
250
+ }
251
+ });
252
+ }
157
253
  }
158
254
  exports.MongoRepository = MongoRepository;
@@ -1,25 +1,32 @@
1
- import type { Connection, Model } from 'mongoose';
1
+ import type { Connection, PipelineStage } from 'mongoose';
2
2
  import * as factory from '../factory';
3
+ type IMatchStage = PipelineStage.Match;
3
4
  export type IOrder4report = factory.report.accountingReport.IOrderAsMainEntity;
5
+ export interface IChildReport {
6
+ typeOf: 'Report';
7
+ mainEntity: factory.report.accountingReport.IAction;
8
+ }
4
9
  export interface IAccountingReport {
5
10
  project: {
6
11
  id: string;
7
12
  typeOf: factory.organizationType.Project;
8
13
  };
9
14
  typeOf: 'Report';
10
- hasPart: any[];
15
+ hasPart: IChildReport[];
11
16
  mainEntity: IOrder4report;
12
17
  }
13
18
  /**
14
19
  * 経理レポートリポジトリ
15
20
  */
16
21
  export declare class MongoRepository {
17
- readonly accountingReportModel: typeof Model;
22
+ private readonly accountingReportModel;
18
23
  constructor(connection: Connection);
19
- /**
20
- * なければ作成する
21
- */
22
- createIfNotExist(params: IAccountingReport): Promise<void>;
24
+ static CREATE_MONGO_CONDITIONS(params: factory.report.accountingReport.ISearchConditions & {
25
+ seller?: {
26
+ id?: string;
27
+ };
28
+ }): IMatchStage[];
29
+ syncMainEntity(params: IAccountingReport): Promise<void>;
23
30
  /**
24
31
  * 注文番号で削除する
25
32
  */
@@ -28,4 +35,23 @@ export declare class MongoRepository {
28
35
  orderNumber: string;
29
36
  };
30
37
  }): Promise<void>;
38
+ /**
39
+ * 注文にアクションレポートを追加する
40
+ * 注文に対する経理レポート自体が未作成であれば自動的に作成する
41
+ */
42
+ addChildReport(params: {
43
+ project: {
44
+ id: string;
45
+ };
46
+ mainEntity: {
47
+ orderNumber: string;
48
+ };
49
+ hasPart: IChildReport;
50
+ }): Promise<void>;
51
+ search(params: factory.report.accountingReport.ISearchConditions & {
52
+ seller?: {
53
+ id?: string;
54
+ };
55
+ }): Promise<any[]>;
31
56
  }
57
+ export {};