@chevre/domain 21.13.0-alpha.0 → 21.13.0-alpha.10

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 (209) hide show
  1. package/example/src/chevre/importEventsFromCOA.ts +11 -8
  2. package/example/src/chevre/searchEvents.ts +5 -2
  3. package/example/src/chevre/searchOrders.ts +1 -1
  4. package/example/src/chevre/transaction/findPaymentCardPermit.ts +2 -2
  5. package/example/src/chevre/transaction/processReturnOrder.ts +9 -9
  6. package/example/src/chevre/transaction/startExportTasks.ts +1 -1
  7. package/example/src/chevre/unsetUnnecessaryFields.ts +1 -1
  8. package/example/src/retryConnectMongo.ts +82 -0
  9. package/lib/chevre/errorHandler.d.ts +2 -2
  10. package/lib/chevre/errorHandler.js +38 -19
  11. package/lib/chevre/factory/transaction.d.ts +42 -0
  12. package/lib/chevre/factory/transaction.js +2 -0
  13. package/lib/chevre/index.d.ts +5 -5
  14. package/lib/chevre/index.js +30 -12
  15. package/lib/chevre/pecorinoapi.d.ts +2 -3
  16. package/lib/chevre/pecorinoapi.js +3 -3
  17. package/lib/chevre/repo/account.d.ts +1 -1
  18. package/lib/chevre/repo/accountTitle.d.ts +1 -1
  19. package/lib/chevre/repo/accountTransaction.d.ts +1 -1
  20. package/lib/chevre/repo/accountingReport.d.ts +1 -1
  21. package/lib/chevre/repo/accountingReport.js +1 -1
  22. package/lib/chevre/repo/action.d.ts +1 -1
  23. package/lib/chevre/repo/additionalProperty.d.ts +1 -1
  24. package/lib/chevre/repo/aggregateOffer.d.ts +1 -1
  25. package/lib/chevre/repo/aggregation.d.ts +1 -1
  26. package/lib/chevre/repo/assetTransaction.d.ts +1 -1
  27. package/lib/chevre/repo/categoryCode.d.ts +1 -1
  28. package/lib/chevre/repo/code.d.ts +1 -1
  29. package/lib/chevre/repo/comment.d.ts +1 -1
  30. package/lib/chevre/repo/creativeWork.d.ts +8 -2
  31. package/lib/chevre/repo/creativeWork.js +36 -8
  32. package/lib/chevre/repo/customer.d.ts +1 -1
  33. package/lib/chevre/repo/emailMessage.d.ts +1 -1
  34. package/lib/chevre/repo/event.d.ts +5 -5
  35. package/lib/chevre/repo/event.js +7 -3
  36. package/lib/chevre/repo/member.d.ts +1 -1
  37. package/lib/chevre/repo/merchantReturnPolicy.d.ts +1 -1
  38. package/lib/chevre/repo/mongoose/writeConcern.d.ts +1 -1
  39. package/lib/chevre/repo/offer.js +2 -1
  40. package/lib/chevre/repo/offerCatalog.d.ts +1 -1
  41. package/lib/chevre/repo/offerCatalog.js +1 -1
  42. package/lib/chevre/repo/offerItemCondition.d.ts +1 -1
  43. package/lib/chevre/repo/order.d.ts +1 -8
  44. package/lib/chevre/repo/order.js +20 -17
  45. package/lib/chevre/repo/ownershipInfo.d.ts +1 -1
  46. package/lib/chevre/repo/ownershipInfo.js +1 -1
  47. package/lib/chevre/repo/permit.d.ts +1 -1
  48. package/lib/chevre/repo/place.d.ts +1 -1
  49. package/lib/chevre/repo/priceSpecification.d.ts +1 -1
  50. package/lib/chevre/repo/product.d.ts +1 -1
  51. package/lib/chevre/repo/project.d.ts +1 -1
  52. package/lib/chevre/repo/reservation.d.ts +3 -3
  53. package/lib/chevre/repo/role.d.ts +1 -1
  54. package/lib/chevre/repo/serviceOutput.d.ts +1 -1
  55. package/lib/chevre/repo/stockHolder.d.ts +2 -2
  56. package/lib/chevre/repo/task.d.ts +1 -1
  57. package/lib/chevre/repo/telemetry.d.ts +1 -1
  58. package/lib/chevre/repo/transaction.d.ts +1 -1
  59. package/lib/chevre/repo/trip.d.ts +1 -1
  60. package/lib/chevre/repository.d.ts +203 -171
  61. package/lib/chevre/repository.js +646 -269
  62. package/lib/chevre/service/account.d.ts +2 -2
  63. package/lib/chevre/service/accountTransaction/deposit.d.ts +2 -2
  64. package/lib/chevre/service/accountTransaction/transfer.d.ts +2 -2
  65. package/lib/chevre/service/accountTransaction/withdraw.d.ts +2 -2
  66. package/lib/chevre/service/accountTransaction.d.ts +1 -1
  67. package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.d.ts +7 -7
  68. package/lib/chevre/service/aggregation/event/aggregateUseActionsOnEvent.d.ts +6 -6
  69. package/lib/chevre/service/aggregation/event/findEventOffers.d.ts +4 -4
  70. package/lib/chevre/service/aggregation/event/importFromCOA.d.ts +1 -1
  71. package/lib/chevre/service/aggregation/project.d.ts +3 -3
  72. package/lib/chevre/service/aggregation/system.d.ts +5 -5
  73. package/lib/chevre/service/assetTransaction/cancelReservation.d.ts +4 -4
  74. package/lib/chevre/service/assetTransaction/cancelReservation.js +2 -2
  75. package/lib/chevre/service/assetTransaction/moneyTransfer.d.ts +4 -4
  76. package/lib/chevre/service/assetTransaction/moneyTransfer.js +5 -5
  77. package/lib/chevre/service/assetTransaction/pay/account/validation.d.ts +1 -1
  78. package/lib/chevre/service/assetTransaction/pay.d.ts +15 -10
  79. package/lib/chevre/service/assetTransaction/refund.d.ts +4 -4
  80. package/lib/chevre/service/assetTransaction/registerService.d.ts +8 -8
  81. package/lib/chevre/service/assetTransaction/registerService.js +2 -2
  82. package/lib/chevre/service/assetTransaction/reserve.d.ts +14 -14
  83. package/lib/chevre/service/assetTransaction/reserve.js +2 -2
  84. package/lib/chevre/service/assetTransaction.d.ts +2 -2
  85. package/lib/chevre/service/code.d.ts +2 -2
  86. package/lib/chevre/service/code.js +1 -2
  87. package/lib/chevre/service/delivery.d.ts +5 -5
  88. package/lib/chevre/service/event/createEvent.d.ts +4 -4
  89. package/lib/chevre/service/event.d.ts +10 -7
  90. package/lib/chevre/service/event.js +26 -2
  91. package/lib/chevre/service/iam.d.ts +2 -2
  92. package/lib/chevre/service/moneyTransfer.d.ts +5 -5
  93. package/lib/chevre/service/moneyTransfer.js +14 -14
  94. package/lib/chevre/service/notification.d.ts +2 -2
  95. package/lib/chevre/service/offer/event/authorize.d.ts +15 -15
  96. package/lib/chevre/service/offer/event/cancel.d.ts +7 -7
  97. package/lib/chevre/service/offer/event/importFromCOA.d.ts +3 -3
  98. package/lib/chevre/service/offer/event/searchEventTicketOffers.d.ts +7 -7
  99. package/lib/chevre/service/offer/event/voidTransaction.d.ts +7 -7
  100. package/lib/chevre/service/offer/eventServiceByCOA/validateAcceptedOffers.d.ts +1 -1
  101. package/lib/chevre/service/offer/eventServiceByCOA.d.ts +5 -5
  102. package/lib/chevre/service/offer/moneyTransfer/authorize.d.ts +6 -6
  103. package/lib/chevre/service/offer/moneyTransfer/returnMoneyTransfer.d.ts +5 -5
  104. package/lib/chevre/service/offer/moneyTransfer/settleTransaction.d.ts +2 -2
  105. package/lib/chevre/service/offer/moneyTransfer/voidTransaction.d.ts +3 -3
  106. package/lib/chevre/service/offer/product/searchProductOffers.d.ts +3 -3
  107. package/lib/chevre/service/offer/product.d.ts +14 -14
  108. package/lib/chevre/service/offer.d.ts +6 -6
  109. package/lib/chevre/service/order/confirmPayTransaction.d.ts +10 -10
  110. package/lib/chevre/service/order/deleteOrder.d.ts +5 -5
  111. package/lib/chevre/service/order/findPlaceOrderTransaction.d.ts +1 -1
  112. package/lib/chevre/service/order/onAssetTransactionStatusChanged.d.ts +5 -5
  113. package/lib/chevre/service/order/onOrderStatusChanged.d.ts +2 -2
  114. package/lib/chevre/service/order/onOrderUpdated.d.ts +1 -1
  115. package/lib/chevre/service/order/payOrder.d.ts +4 -4
  116. package/lib/chevre/service/order/placeOrder.d.ts +6 -6
  117. package/lib/chevre/service/order/returnOrder.d.ts +6 -6
  118. package/lib/chevre/service/order/sendOrder.d.ts +6 -6
  119. package/lib/chevre/service/payment/any/onPaid.d.ts +3 -3
  120. package/lib/chevre/service/payment/any/onPaymentStatusChanged/onPaid.d.ts +1 -1
  121. package/lib/chevre/service/payment/any/onPaymentStatusChanged/onRefunded.d.ts +1 -1
  122. package/lib/chevre/service/payment/any/onPaymentStatusChanged.d.ts +2 -2
  123. package/lib/chevre/service/payment/any/onRefund.d.ts +3 -3
  124. package/lib/chevre/service/payment/any.d.ts +16 -11
  125. package/lib/chevre/service/payment/creditCard.d.ts +13 -8
  126. package/lib/chevre/service/payment/creditCard.js +24 -16
  127. package/lib/chevre/service/payment/faceToFace.d.ts +6 -6
  128. package/lib/chevre/service/payment/movieTicket/checkByIdentifier.d.ts +2 -2
  129. package/lib/chevre/service/payment/movieTicket/getCredentials.d.ts +1 -1
  130. package/lib/chevre/service/payment/movieTicket/validation.d.ts +5 -5
  131. package/lib/chevre/service/payment/movieTicket.d.ts +6 -6
  132. package/lib/chevre/service/payment/paymentCard.d.ts +7 -7
  133. package/lib/chevre/service/payment/paymentCard.js +10 -10
  134. package/lib/chevre/service/payment.d.ts +13 -9
  135. package/lib/chevre/service/permit.d.ts +2 -2
  136. package/lib/chevre/service/product.d.ts +3 -3
  137. package/lib/chevre/service/project.d.ts +16 -16
  138. package/lib/chevre/service/report/telemetry.d.ts +19 -16
  139. package/lib/chevre/service/reserve/cancelReservation.d.ts +3 -3
  140. package/lib/chevre/service/reserve/checkInReservation.d.ts +5 -5
  141. package/lib/chevre/service/reserve/confirmReservation.d.ts +4 -4
  142. package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.d.ts +1 -1
  143. package/lib/chevre/service/reserve/potentialActions/onReservationCheckedIn.d.ts +2 -2
  144. package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.d.ts +1 -1
  145. package/lib/chevre/service/reserve/potentialActions/onReservationUsed.d.ts +1 -1
  146. package/lib/chevre/service/reserve/useReservation.d.ts +5 -5
  147. package/lib/chevre/service/reserve/verifyToken4reservation.d.ts +1 -1
  148. package/lib/chevre/service/task/importEventsFromCOA.js +2 -0
  149. package/lib/chevre/service/task/onResourceUpdated/onHasPOSUpdated.d.ts +2 -2
  150. package/lib/chevre/service/task/onResourceUpdated/onOfferCatalogUpdated.d.ts +3 -3
  151. package/lib/chevre/service/task/onResourceUpdated/onResourceDeleted.d.ts +15 -15
  152. package/lib/chevre/service/task/onResourceUpdated/syncOfferCatalog.d.ts +2 -2
  153. package/lib/chevre/service/task/pay.js +9 -14
  154. package/lib/chevre/service/task/refund.js +10 -16
  155. package/lib/chevre/service/task/voidPayTransaction.js +10 -16
  156. package/lib/chevre/service/task/voidPayment.js +8 -12
  157. package/lib/chevre/service/task.d.ts +3 -3
  158. package/lib/chevre/service/task.js +12 -7
  159. package/lib/chevre/service/transaction/deleteTransaction.d.ts +9 -9
  160. package/lib/chevre/service/transaction/moneyTransfer.d.ts +11 -13
  161. package/lib/chevre/service/transaction/orderProgramMembership/findPaymentCardPermit.d.ts +2 -2
  162. package/lib/chevre/service/transaction/placeOrder.d.ts +2 -2
  163. package/lib/chevre/service/transaction/placeOrderInProgress.d.ts +12 -39
  164. package/lib/chevre/service/transaction/placeOrderInProgress.js +2 -2
  165. package/lib/chevre/service/transaction/returnOrder.d.ts +10 -10
  166. package/lib/chevre/service/transaction/returnOrder.js +1 -1
  167. package/lib/chevre/service/transaction/validation.d.ts +1 -3
  168. package/lib/chevre/service/transaction.d.ts +2 -2
  169. package/lib/chevre/service.d.ts +75 -39
  170. package/lib/chevre/service.js +258 -39
  171. package/package.json +3 -3
  172. package/example/src/chevre/assetTransaction/searchGMOTrade.ts +0 -27
  173. package/example/src/chevre/countDelayedTasks.ts +0 -22
  174. package/example/src/chevre/countDelayedTransactions.ts +0 -60
  175. package/example/src/chevre/countMoneyTransferTransaction.ts +0 -36
  176. package/example/src/chevre/countOffers.ts +0 -32
  177. package/example/src/chevre/createDeleteTransactionTasks.ts +0 -108
  178. package/example/src/chevre/createDeleteTransactionTasksIfNotExist.ts +0 -98
  179. package/example/src/chevre/createDeleteTransactionTasksOfDeletedPeople.ts +0 -126
  180. package/example/src/chevre/createManyEventsIfNotExist.ts +0 -365
  181. package/example/src/chevre/iam/searchMemberOfIdsByMemberId.ts +0 -31
  182. package/example/src/chevre/iam/searchProjectIdsByMemberId.ts +0 -32
  183. package/example/src/chevre/offer/searchAllByIdsAndOfferCatalogId.ts +0 -34
  184. package/example/src/chevre/offer/searchEventTicketOffers.ts +0 -54
  185. package/example/src/chevre/offer/searchOffersByCatalog.ts +0 -40
  186. package/example/src/chevre/processPay.ts +0 -90
  187. package/example/src/chevre/processRegisterMembership.ts +0 -110
  188. package/example/src/chevre/processRegisterPaymentCard.ts +0 -98
  189. package/example/src/chevre/processReserve.ts +0 -114
  190. package/example/src/chevre/publishConfirmationNumber.ts +0 -27
  191. package/example/src/chevre/publishPermitOwnershipInfoToken.ts +0 -56
  192. package/example/src/chevre/reIndex.ts +0 -25
  193. package/example/src/chevre/redisConfig.ts +0 -32
  194. package/example/src/chevre/saveTasks.ts +0 -41
  195. package/example/src/chevre/searchAbortedTasks.ts +0 -34
  196. package/example/src/chevre/searchAcceptedOfferIds.ts +0 -23
  197. package/example/src/chevre/searchOffersFromAggregateOffer.ts +0 -168
  198. package/example/src/chevre/searchOrdersWithUnwoundOffers.ts +0 -35
  199. package/example/src/chevre/searchReservationNumbersByOrderNumbers.ts +0 -58
  200. package/example/src/chevre/searchSendEmailActions.ts +0 -44
  201. package/example/src/chevre/searchTasks.ts +0 -31
  202. package/example/src/chevre/searchTransactions.ts +0 -25
  203. package/example/src/chevre/sendEmailMessage.ts +0 -80
  204. package/example/src/chevre/syncCatalogs2aggregateOffers.ts +0 -87
  205. package/example/src/chevre/task/executeTasks.ts +0 -26
  206. package/example/src/chevre/unsetContainsInPlaceFromMovieTheater.ts +0 -41
  207. package/example/src/chevre/updateOfferCatalogs.ts +0 -40
  208. package/example/src/chevre/updateTransaction.ts +0 -38
  209. package/example/src/playOnMoment.ts +0 -24
@@ -10,28 +10,31 @@ const project = { id: String(process.env.PROJECT_ID) };
10
10
  async function main() {
11
11
  await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
12
12
 
13
- const actionRepo = new chevre.repository.Action(mongoose.connection);
14
- const categoryCodeRepo = new chevre.repository.CategoryCode(mongoose.connection);
15
- const eventRepo = new chevre.repository.Event(mongoose.connection);
16
- const placeRepo = new chevre.repository.Place(mongoose.connection);
17
- const sellerRepo = new chevre.repository.Seller(mongoose.connection);
13
+ const actionRepo = await chevre.repository.Action.createInstance(mongoose.connection);
14
+ const categoryCodeRepo = await chevre.repository.CategoryCode.createInstance(mongoose.connection);
15
+ const creativeWorkRepo = await chevre.repository.CreativeWork.createInstance(mongoose.connection);
16
+ const eventRepo = await chevre.repository.Event.createInstance(mongoose.connection);
17
+ const placeRepo = await chevre.repository.Place.createInstance(mongoose.connection);
18
+ const sellerRepo = await chevre.repository.Seller.createInstance(mongoose.connection);
18
19
 
19
- await chevre.service.event.importFromCOA({
20
+ await (await chevre.service.event.createService()).importFromCOA({
20
21
  project: {
21
22
  id: project.id,
22
23
  typeOf: chevre.factory.organizationType.Project
23
24
  },
24
- locationBranchCode: '022',
25
+ locationBranchCode: '120',
25
26
  importFrom: moment()
26
27
  .toDate(),
27
28
  importThrough: moment()
28
29
  .add(1, 'day')
29
30
  .toDate(),
30
31
  saveMovieTheater: false,
31
- saveScreeningEventSeries: false
32
+ saveScreeningEventSeries: true,
33
+ saveScreeningEventSeriesPeriodInMonth: 24
32
34
  })({
33
35
  action: actionRepo,
34
36
  categoryCode: categoryCodeRepo,
37
+ creativeWork: creativeWorkRepo,
35
38
  event: eventRepo,
36
39
  place: placeRepo,
37
40
  seller: sellerRepo
@@ -1,14 +1,17 @@
1
1
  // tslint:disable:no-console
2
2
  import * as mongoose from 'mongoose';
3
3
 
4
+ const startTime = process.hrtime();
4
5
  import { chevre } from '../../../lib/index';
6
+ const diff = process.hrtime(startTime);
7
+ console.log(`importing chevre took ${diff[0]} seconds and ${diff[1]} nanoseconds.`);
5
8
 
6
9
  const PROJECT_ID = process.env.PROJECT_ID;
7
10
 
8
11
  async function main() {
9
12
  await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
10
13
 
11
- const eventRepo = new chevre.repository.Event(mongoose.connection);
14
+ const eventRepo: chevre.repository.Event = await chevre.repository.Event.createInstance(mongoose.connection);
12
15
 
13
16
  const events = await eventRepo.search(
14
17
  {
@@ -26,7 +29,7 @@ async function main() {
26
29
  }
27
30
  );
28
31
  console.log(events);
29
- console.log(events.length);
32
+ console.log(events.length, 'events found');
30
33
  }
31
34
 
32
35
  main()
@@ -8,7 +8,7 @@ const project = { id: String(process.env.PROJECT_ID) };
8
8
  async function main() {
9
9
  await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
10
10
 
11
- const orderRepo = new chevre.repository.Order(mongoose.connection);
11
+ const orderRepo = await chevre.repository.Order.createInstance(mongoose.connection);
12
12
 
13
13
  const orders = await orderRepo.search({
14
14
  limit: 10,
@@ -9,8 +9,8 @@ const project = { id: String(process.env.PROJECT_ID) };
9
9
  async function main() {
10
10
  await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
11
11
 
12
- const ownershipInfoRepo = new chevre.repository.OwnershipInfo(mongoose.connection);
13
- const productRepo = new chevre.repository.Product(mongoose.connection);
12
+ const ownershipInfoRepo = await chevre.repository.OwnershipInfo.createInstance(mongoose.connection);
13
+ const productRepo = await chevre.repository.Product.createInstance(mongoose.connection);
14
14
 
15
15
  const result = await findPaymentCardPermit({
16
16
  project: { id: project.id },
@@ -8,7 +8,7 @@ const project = { id: String(process.env.PROJECT_ID) };
8
8
  async function main() {
9
9
  await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
10
10
 
11
- const result = await chevre.service.transaction.returnOrder.start({
11
+ const result = await (await chevre.service.transaction.createService()).returnOrder.start({
12
12
  project: { id: project.id, typeOf: chevre.factory.organizationType.Project },
13
13
  expiresInSeconds: 60,
14
14
  agent: { id: 'xxx', typeOf: chevre.factory.creativeWorkType.WebApplication },
@@ -23,14 +23,14 @@ async function main() {
23
23
  id: 'xxx'
24
24
  }
25
25
  })({
26
- event: new chevre.repository.Event(mongoose.connection),
27
- merchantReturnPolicy: new chevre.repository.MerchantReturnPolicy(mongoose.connection),
28
- offer: new chevre.repository.Offer(mongoose.connection),
29
- offerItemCondition: new chevre.repository.OfferItemCondition(mongoose.connection),
30
- order: new chevre.repository.Order(mongoose.connection),
31
- reservation: new chevre.repository.Reservation(mongoose.connection),
32
- seller: new chevre.repository.Seller(mongoose.connection),
33
- transaction: new chevre.repository.Transaction(mongoose.connection)
26
+ event: await chevre.repository.Event.createInstance(mongoose.connection),
27
+ merchantReturnPolicy: await chevre.repository.MerchantReturnPolicy.createInstance(mongoose.connection),
28
+ offer: await chevre.repository.Offer.createInstance(mongoose.connection),
29
+ offerItemCondition: await chevre.repository.OfferItemCondition.createInstance(mongoose.connection),
30
+ order: await chevre.repository.Order.createInstance(mongoose.connection),
31
+ reservation: await chevre.repository.Reservation.createInstance(mongoose.connection),
32
+ seller: await chevre.repository.Seller.createInstance(mongoose.connection),
33
+ transaction: await chevre.repository.Transaction.createInstance(mongoose.connection)
34
34
  });
35
35
  console.log(result);
36
36
  }
@@ -6,7 +6,7 @@ import { chevre } from '../../../../lib/index';
6
6
  async function main() {
7
7
  await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
8
8
 
9
- const transactionRepo = new chevre.repository.Transaction(mongoose.connection);
9
+ const transactionRepo = await chevre.repository.Transaction.createInstance(mongoose.connection);
10
10
  const result = await transactionRepo.startExportTasks({
11
11
  typeOf: { $in: [chevre.factory.transactionType.PlaceOrder] },
12
12
  status: chevre.factory.transactionStatusType.Confirmed,
@@ -9,7 +9,7 @@ const PROJECT_ID = String(process.env.PROJECT_ID);
9
9
  async function main() {
10
10
  await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
11
11
 
12
- const transactionRepo = new chevre.repository.Transaction(mongoose.connection);
12
+ const transactionRepo = await chevre.repository.Transaction.createInstance(mongoose.connection);
13
13
 
14
14
  let updateResult: any;
15
15
  updateResult = await transactionRepo.unsetUnnecessaryFields({
@@ -0,0 +1,82 @@
1
+ // tslint:disable:no-console
2
+ import * as moment from 'moment';
3
+ import * as mongoose from 'mongoose';
4
+
5
+ let connection: mongoose.Connection | undefined;
6
+ let mongoLastConnected: Date | undefined;
7
+ const MONGO_RETRY_INTERVAL_IN_MILLISECONDS = 1000;
8
+ const MONGO_GIVE_UP_IN_SECONDS = 5;
9
+ async function getConnection(): Promise<mongoose.Connection> {
10
+ if (mongoLastConnected instanceof Date) {
11
+ if (connection === undefined) {
12
+ if (moment()
13
+ .isAfter(moment(mongoLastConnected)
14
+ .add(MONGO_GIVE_UP_IN_SECONDS, 'seconds'))
15
+ ) {
16
+ mongoLastConnected = void 0;
17
+ }
18
+
19
+ // 最終接続から一定期間経過していればリトライ
20
+ connection = await new Promise<mongoose.Connection>((resolve, reject) => {
21
+ setTimeout(
22
+ async () => {
23
+ console.log('retrying...', mongoLastConnected);
24
+ try {
25
+ resolve(await getConnection());
26
+ } catch (error) {
27
+ reject(error);
28
+ }
29
+ },
30
+ MONGO_RETRY_INTERVAL_IN_MILLISECONDS
31
+ );
32
+ });
33
+ }
34
+ } else {
35
+ mongoLastConnected = new Date();
36
+ console.log('creating connection...', mongoLastConnected);
37
+ if (connection === undefined) {
38
+ connection = await new Promise<mongoose.Connection>((resolve) => {
39
+ setTimeout(
40
+ async () => {
41
+ resolve(await mongoose.createConnection(<string>process.env.MONGOLAB_URI, { autoIndex: false }));
42
+ },
43
+ // tslint:disable-next-line:no-magic-numbers
44
+ 2000
45
+ );
46
+ });
47
+ // throw new Error('failed in createConnection')
48
+ }
49
+ }
50
+
51
+ return connection;
52
+ }
53
+
54
+ getConnection()
55
+ .then(() => {
56
+ console.log('sucess!', mongoose.connections.length);
57
+ })
58
+ .catch((error) => {
59
+ console.error(error, mongoose.connections.length);
60
+ });
61
+ getConnection()
62
+ .then(() => {
63
+ console.log('sucess!', mongoose.connections.length);
64
+ })
65
+ .catch((error) => {
66
+ console.error(error, mongoose.connections.length);
67
+ });
68
+ getConnection()
69
+ .then(() => {
70
+ console.log('sucess!', mongoose.connections.length);
71
+ })
72
+ .catch((error) => {
73
+ console.error(error, mongoose.connections.length);
74
+ });
75
+ // setInterval(
76
+ // () => {
77
+ // getConnection()
78
+ // .then(console.log)
79
+ // .catch(console.error);
80
+ // },
81
+ // 1000
82
+ // );
@@ -3,8 +3,8 @@ export declare enum MongoErrorCode {
3
3
  MaxTimeMSExpired = 50,
4
4
  ExceededTimeLimit = 262
5
5
  }
6
- export declare function isMongoError(error: unknown): boolean;
7
- export declare function handleMongoError(error: unknown): unknown;
6
+ export declare function isMongoError(error: unknown): Promise<boolean>;
7
+ export declare function handleMongoError(error: unknown): Promise<unknown>;
8
8
  /**
9
9
  * 汎用的なCOAエラーハンドリング
10
10
  */
@@ -1,4 +1,13 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.handleAWSError = exports.handleMvtkReserveError = exports.handlePecorinoError = exports.handleCOAError = exports.handleMongoError = exports.isMongoError = exports.MongoErrorCode = void 0;
4
13
  /**
@@ -7,7 +16,7 @@ exports.handleAWSError = exports.handleMvtkReserveError = exports.handlePecorino
7
16
  */
8
17
  const http_status_1 = require("http-status");
9
18
  const factory_1 = require("./factory");
10
- const mongoose_1 = require("mongoose");
19
+ let mongo;
11
20
  var MongoErrorCode;
12
21
  (function (MongoErrorCode) {
13
22
  MongoErrorCode[MongoErrorCode["DuplicateKey"] = 11000] = "DuplicateKey";
@@ -15,28 +24,38 @@ var MongoErrorCode;
15
24
  MongoErrorCode[MongoErrorCode["ExceededTimeLimit"] = 262] = "ExceededTimeLimit";
16
25
  })(MongoErrorCode = exports.MongoErrorCode || (exports.MongoErrorCode = {}));
17
26
  function isMongoError(error) {
18
- return (error instanceof mongoose_1.mongo.MongoError || error instanceof mongoose_1.mongo.MongoServerError);
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ if (mongo === undefined) {
29
+ mongo = (yield Promise.resolve().then(() => require('mongoose'))).mongo;
30
+ }
31
+ return (error instanceof mongo.MongoError || error instanceof mongo.MongoServerError);
32
+ });
19
33
  }
20
34
  exports.isMongoError = isMongoError;
21
35
  function handleMongoError(error) {
22
- let handledError = error;
23
- if (handledError instanceof mongoose_1.mongo.MongoError || handledError instanceof mongoose_1.mongo.MongoServerError) {
24
- switch (handledError.code) {
25
- case MongoErrorCode.DuplicateKey:
26
- handledError = new factory_1.errors.AlreadyInUse('', [], `Some fields already in use. code:${handledError.code} message:${handledError.message}`);
27
- // no op
28
- break;
29
- case MongoErrorCode.MaxTimeMSExpired:
30
- case MongoErrorCode.ExceededTimeLimit:
31
- handledError = new factory_1.errors.GatewayTimeout(`Gateway Timeout. name:${handledError.name} code:${handledError.code} message:${handledError.message}`);
32
- break;
33
- default:
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ if (mongo === undefined) {
38
+ mongo = (yield Promise.resolve().then(() => require('mongoose'))).mongo;
34
39
  }
35
- }
36
- if (mongoose_1.mongo.BSON.BSONError.isBSONError(handledError)) {
37
- handledError = new factory_1.errors.Argument('', handledError.message);
38
- }
39
- return handledError;
40
+ let handledError = error;
41
+ if (handledError instanceof mongo.MongoError || handledError instanceof mongo.MongoServerError) {
42
+ switch (handledError.code) {
43
+ case MongoErrorCode.DuplicateKey:
44
+ handledError = new factory_1.errors.AlreadyInUse('', [], `Some fields already in use. code:${handledError.code} message:${handledError.message}`);
45
+ // no op
46
+ break;
47
+ case MongoErrorCode.MaxTimeMSExpired:
48
+ case MongoErrorCode.ExceededTimeLimit:
49
+ handledError = new factory_1.errors.GatewayTimeout(`Gateway Timeout. name:${handledError.name} code:${handledError.code} message:${handledError.message}`);
50
+ break;
51
+ default:
52
+ }
53
+ }
54
+ if (mongo.BSON.BSONError.isBSONError(handledError)) {
55
+ handledError = new factory_1.errors.Argument('', handledError.message);
56
+ }
57
+ return handledError;
58
+ });
40
59
  }
41
60
  exports.handleMongoError = handleMongoError;
42
61
  /**
@@ -0,0 +1,42 @@
1
+ import * as factory from '../factory';
2
+ export type IPassportValidator = (params: {
3
+ passport: factory.waiter.passport.IPassport;
4
+ }) => boolean;
5
+ export declare namespace moneyTransfer {
6
+ type IStartParams = factory.transaction.moneyTransfer.IStartParamsWithoutDetail & {
7
+ passportValidator?: IPassportValidator;
8
+ };
9
+ }
10
+ export declare namespace placeOrder {
11
+ type IStartParams = factory.transaction.placeOrder.IStartParamsWithoutDetail & {
12
+ passportValidator?: IPassportValidator;
13
+ broker?: factory.order.IBroker;
14
+ validateSeller?: boolean;
15
+ };
16
+ type IOrderURLGenerator = (order: factory.order.IOrder) => string;
17
+ type IResultOrderParams = factory.transaction.placeOrder.IResultOrderParams & {
18
+ /**
19
+ * 注文日時
20
+ */
21
+ orderDate: Date;
22
+ /**
23
+ * 注文確認URLのカスタム指定
24
+ */
25
+ url?: string | IOrderURLGenerator;
26
+ /**
27
+ * 注文アイテム数
28
+ */
29
+ numItems?: {
30
+ maxValue?: number;
31
+ minValue?: number;
32
+ };
33
+ };
34
+ type IConfirmParams = factory.transaction.placeOrder.IConfirmParams & {
35
+ project: {
36
+ id: string;
37
+ };
38
+ result: {
39
+ order: IResultOrderParams;
40
+ };
41
+ };
42
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,15 +1,15 @@
1
1
  /**
2
2
  * index module
3
3
  */
4
- import * as COA from '@motionpicture/coa-service';
5
- import * as GMO from '@motionpicture/gmo-service';
6
- import * as surfrock from '@surfrock/sdk';
4
+ import type * as GMOService from '@motionpicture/gmo-service';
5
+ import type * as Pecorinoapi from './pecorinoapi';
7
6
  import { credentials } from './credentials';
8
7
  import * as errorHandler from './errorHandler';
9
8
  import * as eventEmitter from './eventEmitter';
10
9
  import * as factory from './factory';
11
- import * as pecorinoapi from './pecorinoapi';
12
10
  import * as repository from './repository';
13
11
  import * as service from './service';
14
12
  import * as settings from './settings';
15
- export { credentials, errorHandler, eventEmitter, factory, repository, service, settings, surfrock, pecorinoapi, COA, GMO };
13
+ export { credentials, errorHandler, eventEmitter, factory, repository, service, settings };
14
+ export declare function loadPecorinoapi(): Promise<typeof Pecorinoapi>;
15
+ export declare function loadGMO(): Promise<typeof GMOService>;
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GMO = exports.COA = exports.pecorinoapi = exports.surfrock = exports.settings = exports.service = exports.repository = exports.factory = exports.eventEmitter = exports.errorHandler = exports.credentials = void 0;
4
- /**
5
- * index module
6
- */
7
- const COA = require("@motionpicture/coa-service");
8
- exports.COA = COA;
9
- const GMO = require("@motionpicture/gmo-service");
10
- exports.GMO = GMO;
11
- const surfrock = require("@surfrock/sdk");
12
- exports.surfrock = surfrock;
12
+ exports.loadGMO = exports.loadPecorinoapi = exports.settings = exports.service = exports.repository = exports.factory = exports.eventEmitter = exports.errorHandler = exports.credentials = void 0;
13
13
  const credentials_1 = require("./credentials");
14
14
  Object.defineProperty(exports, "credentials", { enumerable: true, get: function () { return credentials_1.credentials; } });
15
15
  const errorHandler = require("./errorHandler");
@@ -18,11 +18,29 @@ const eventEmitter = require("./eventEmitter");
18
18
  exports.eventEmitter = eventEmitter;
19
19
  const factory = require("./factory");
20
20
  exports.factory = factory;
21
- const pecorinoapi = require("./pecorinoapi");
22
- exports.pecorinoapi = pecorinoapi;
23
21
  const repository = require("./repository");
24
22
  exports.repository = repository;
25
23
  const service = require("./service");
26
24
  exports.service = service;
27
25
  const settings = require("./settings");
28
26
  exports.settings = settings;
27
+ let pecorinoapi;
28
+ function loadPecorinoapi() {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ if (pecorinoapi === undefined) {
31
+ pecorinoapi = yield Promise.resolve().then(() => require('./pecorinoapi'));
32
+ }
33
+ return pecorinoapi;
34
+ });
35
+ }
36
+ exports.loadPecorinoapi = loadPecorinoapi;
37
+ let GMO;
38
+ function loadGMO() {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ if (GMO === undefined) {
41
+ GMO = yield Promise.resolve().then(() => require('@motionpicture/gmo-service'));
42
+ }
43
+ return GMO;
44
+ });
45
+ }
46
+ exports.loadGMO = loadGMO;
@@ -1,6 +1,5 @@
1
1
  /**
2
2
  * Pecorino API Client
3
3
  */
4
- import { auth, pecorino } from '@cinerino/sdk';
5
- export import service = pecorino.service;
6
- export import auth = auth;
4
+ import { auth, loadPecorino, pecorino } from '@cinerino/sdk';
5
+ export { auth, loadPecorino, pecorino };
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.auth = exports.service = void 0;
3
+ exports.loadPecorino = exports.auth = void 0;
4
4
  /**
5
5
  * Pecorino API Client
6
6
  */
7
7
  const sdk_1 = require("@cinerino/sdk");
8
- exports.service = sdk_1.pecorino.service;
9
- exports.auth = sdk_1.auth;
8
+ Object.defineProperty(exports, "auth", { enumerable: true, get: function () { return sdk_1.auth; } });
9
+ Object.defineProperty(exports, "loadPecorino", { enumerable: true, get: function () { return sdk_1.loadPecorino; } });
@@ -1,4 +1,4 @@
1
- import { Connection } from 'mongoose';
1
+ import type { Connection } from 'mongoose';
2
2
  import * as factory from '../factory';
3
3
  /**
4
4
  * 口座リポジトリ
@@ -22,7 +22,7 @@
22
22
  /// <reference types="mongoose/types/validation" />
23
23
  /// <reference types="mongoose/types/virtuals" />
24
24
  /// <reference types="mongoose/types/inferschematype" />
25
- import { Connection, Model } from 'mongoose';
25
+ import type { Connection, Model } from 'mongoose';
26
26
  /**
27
27
  * 科目リポジトリ
28
28
  */
@@ -1,4 +1,4 @@
1
- import { Connection } from 'mongoose';
1
+ import type { Connection } from 'mongoose';
2
2
  import * as factory from '../factory';
3
3
  /**
4
4
  * 口座取引リポジトリ
@@ -1,4 +1,4 @@
1
- import { Connection, Model } from 'mongoose';
1
+ import type { Connection, Model } from 'mongoose';
2
2
  import * as factory from '../factory';
3
3
  export type IOrder4report = factory.report.accountingReport.IOrderAsMainEntity;
4
4
  export interface IAccountingReport {
@@ -30,7 +30,7 @@ class MongoRepository {
30
30
  }
31
31
  catch (error) {
32
32
  let throwsError = true;
33
- if ((0, errorHandler_1.isMongoError)(error)) {
33
+ if (yield (0, errorHandler_1.isMongoError)(error)) {
34
34
  // すでにorderNumberが存在する場合ok
35
35
  if (error.code === errorHandler_1.MongoErrorCode.DuplicateKey) {
36
36
  throwsError = false;
@@ -22,7 +22,7 @@
22
22
  /// <reference types="mongoose/types/validation" />
23
23
  /// <reference types="mongoose/types/virtuals" />
24
24
  /// <reference types="mongoose/types/inferschematype" />
25
- import { Connection } from 'mongoose';
25
+ import type { Connection } from 'mongoose';
26
26
  import * as factory from '../factory';
27
27
  export type IAction<T extends factory.actionType> = T extends factory.actionType.OrderAction ? factory.action.trade.order.IAction : T extends factory.actionType.AuthorizeAction ? factory.action.authorize.IAction<factory.action.authorize.IAttributes<any, any>> : factory.action.IAction<factory.action.IAttributes<T, any, any>>;
28
28
  export type IPayAction = factory.action.trade.pay.IAction;
@@ -1,4 +1,4 @@
1
- import { Connection } from 'mongoose';
1
+ import type { Connection } from 'mongoose';
2
2
  import * as factory from '../factory';
3
3
  /**
4
4
  * 追加特性リポジトリ
@@ -1,4 +1,4 @@
1
- import { AnyExpression, Connection, PipelineStage } from 'mongoose';
1
+ import type { AnyExpression, Connection, PipelineStage } from 'mongoose';
2
2
  import * as factory from '../factory';
3
3
  type IMatchStage = PipelineStage.Match;
4
4
  type KeyOfUnitPriceOffer = keyof factory.unitPriceOffer.IUnitPriceOffer;
@@ -1,4 +1,4 @@
1
- import { Connection, Model } from 'mongoose';
1
+ import type { Connection, Model } from 'mongoose';
2
2
  import * as factory from '../factory';
3
3
  export declare enum AggregationType {
4
4
  AggregateAuthorizeEventServiceOfferAction = "AggregateAuthorizeEventServiceOfferAction",
@@ -22,7 +22,7 @@
22
22
  /// <reference types="mongoose/types/validation" />
23
23
  /// <reference types="mongoose/types/virtuals" />
24
24
  /// <reference types="mongoose/types/inferschematype" />
25
- import { Connection } from 'mongoose';
25
+ import type { Connection } from 'mongoose';
26
26
  import * as factory from '../factory';
27
27
  interface IAggregationByStatus {
28
28
  transactionCount: number;
@@ -22,7 +22,7 @@
22
22
  /// <reference types="mongoose/types/validation" />
23
23
  /// <reference types="mongoose/types/virtuals" />
24
24
  /// <reference types="mongoose/types/inferschematype" />
25
- import { Connection } from 'mongoose';
25
+ import type { Connection } from 'mongoose';
26
26
  import * as factory from '../factory';
27
27
  /**
28
28
  * 区分リポジトリ
@@ -1,4 +1,4 @@
1
- import { Connection } from 'mongoose';
1
+ import type { Connection } from 'mongoose';
2
2
  import * as factory from '../factory';
3
3
  import { modelName } from './mongoose/schemas/authorization';
4
4
  export type IObject = factory.authorization.IObject;
@@ -22,7 +22,7 @@
22
22
  /// <reference types="mongoose/types/validation" />
23
23
  /// <reference types="mongoose/types/virtuals" />
24
24
  /// <reference types="mongoose/types/inferschematype" />
25
- import { Connection } from 'mongoose';
25
+ import type { Connection } from 'mongoose';
26
26
  import * as factory from '../factory';
27
27
  /**
28
28
  * コメントリポジトリ
@@ -22,7 +22,8 @@
22
22
  /// <reference types="mongoose/types/validation" />
23
23
  /// <reference types="mongoose/types/virtuals" />
24
24
  /// <reference types="mongoose/types/inferschematype" />
25
- import { Connection } from 'mongoose';
25
+ import type { BulkWriteResult } from 'mongodb';
26
+ import type { Connection } from 'mongoose';
26
27
  import * as factory from '../factory';
27
28
  /**
28
29
  * コンテンツリポジトリ
@@ -35,10 +36,15 @@ export declare class MongoRepository {
35
36
  * コンテンツを保管する
36
37
  */
37
38
  saveMovie(params: factory.creativeWork.movie.ICreativeWork): Promise<any>;
39
+ /**
40
+ * コードをキーにして冪等作成
41
+ */
42
+ upsertMoviesByIdentifier(params: {
43
+ attributes: factory.creativeWork.movie.ICreativeWork;
44
+ }[]): Promise<BulkWriteResult | void>;
38
45
  findMovieById(params: {
39
46
  id: string;
40
47
  }): Promise<factory.creativeWork.movie.ICreativeWork>;
41
- countMovies(params: factory.creativeWork.movie.ISearchConditions): Promise<number>;
42
48
  /**
43
49
  * コンテンツを検索する
44
50
  */