@chevre/domain 22.10.0-alpha.9 → 22.11.0-alpha.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 (107) hide show
  1. package/example/src/chevre/adminAuth/adminIdentity.ts +38 -0
  2. package/example/src/chevre/adminIdentities.ts +8 -8
  3. package/example/src/chevre/assetTransaction/processReserve.ts +4 -1
  4. package/example/src/chevre/concurrentLock/lockOfferRateLimit.ts +64 -0
  5. package/example/src/chevre/concurrentLock/lockTransactionProcess.ts +44 -0
  6. package/example/src/chevre/createTaskIfNotExistByAlternateName.ts +1 -1
  7. package/example/src/chevre/findOneAvailableHours.ts +11 -11
  8. package/example/src/chevre/identity/getCommonClients.ts +126 -0
  9. package/example/src/chevre/identity/migrateClients2oauth.ts +200 -0
  10. package/example/src/chevre/issuer/adminMemberProgramTiers.ts +55 -0
  11. package/example/src/chevre/maintenance/checkTransactionStatuses.ts +105 -0
  12. package/example/src/chevre/migrateIdentities.ts +24 -37
  13. package/example/src/chevre/reIndex.ts +1 -1
  14. package/example/src/chevre/roles/addPermissionIfNotExists.ts +27 -0
  15. package/example/src/chevre/roles/addRoleMembers.ts +75 -0
  16. package/example/src/chevre/saveWebSite.ts +14 -17
  17. package/example/src/chevre/stockHolder/checkRedisKeyCount.ts +43 -22
  18. package/example/src/chevre/transactionNumber/publishConfimationNumber.ts +37 -0
  19. package/example/src/chevre/transactionNumber/publishOrderNumber.ts +40 -0
  20. package/example/src/chevre/transactionNumber/setUseMongo4confirmationNumberFrom.ts +45 -0
  21. package/example/src/chevre/transactionNumber/setUseMongo4orderNumberFrom.ts +41 -0
  22. package/example/src/chevre/transactionNumber/setUseMongo4transactionNumberFrom.ts +41 -0
  23. package/example/src/redisMulti.ts +63 -0
  24. package/example/src/signPayload.ts +1 -1
  25. package/lib/chevre/adminAuth.d.ts +2 -0
  26. package/lib/chevre/adminAuth.js +6 -0
  27. package/lib/chevre/eventEmitter/task.d.ts +36 -6
  28. package/lib/chevre/eventEmitter/task.js +5 -4
  29. package/lib/chevre/eventEmitter.d.ts +2 -2
  30. package/lib/chevre/eventEmitter.js +2 -2
  31. package/lib/chevre/index.d.ts +2 -0
  32. package/lib/chevre/index.js +10 -0
  33. package/lib/chevre/repo/concurrentLock.d.ts +14 -0
  34. package/lib/chevre/repo/concurrentLock.js +48 -0
  35. package/lib/chevre/repo/concurrentLockAbstract.d.ts +42 -0
  36. package/lib/chevre/repo/concurrentLockAbstract.js +9 -0
  37. package/lib/chevre/repo/confirmationNumber.d.ts +17 -4
  38. package/lib/chevre/repo/confirmationNumber.js +89 -32
  39. package/lib/chevre/repo/identity.d.ts +42 -5
  40. package/lib/chevre/repo/identity.js +35 -4
  41. package/lib/chevre/repo/issuer.d.ts +10 -2
  42. package/lib/chevre/repo/member.js +2 -2
  43. package/lib/chevre/repo/memberProgram.d.ts +43 -2
  44. package/lib/chevre/repo/memberProgram.js +79 -8
  45. package/lib/chevre/repo/mongoose/schemas/issuer.d.ts +3 -1
  46. package/lib/chevre/repo/mongoose/schemas/issuer.js +10 -0
  47. package/lib/chevre/repo/mongoose/schemas/offer/event.js +30 -2
  48. package/lib/chevre/repo/mongoose/schemas/role.d.ts +2 -3
  49. package/lib/chevre/repo/mongoose/schemas/role.js +11 -1
  50. package/lib/chevre/repo/mongoose/schemas/setting.d.ts +3 -0
  51. package/lib/chevre/repo/mongoose/schemas/setting.js +4 -1
  52. package/lib/chevre/repo/mongoose/schemas/transactionNumber.d.ts +39 -0
  53. package/lib/chevre/repo/mongoose/schemas/transactionNumber.js +101 -0
  54. package/lib/chevre/repo/orderNumber.d.ts +15 -4
  55. package/lib/chevre/repo/orderNumber.js +71 -24
  56. package/lib/chevre/repo/passport.d.ts +1 -1
  57. package/lib/chevre/repo/passport.js +31 -13
  58. package/lib/chevre/repo/rateLimit/offer.d.ts +7 -2
  59. package/lib/chevre/repo/rateLimit/offer.js +41 -40
  60. package/lib/chevre/repo/role.d.ts +18 -4
  61. package/lib/chevre/repo/role.js +53 -4
  62. package/lib/chevre/repo/serviceOutputIdentifier.d.ts +8 -4
  63. package/lib/chevre/repo/serviceOutputIdentifier.js +54 -22
  64. package/lib/chevre/repo/stockHolder.d.ts +0 -2
  65. package/lib/chevre/repo/stockHolder.js +24 -31
  66. package/lib/chevre/repo/task.d.ts +10 -25
  67. package/lib/chevre/repo/task.js +65 -36
  68. package/lib/chevre/repo/transactionNumber.d.ts +15 -4
  69. package/lib/chevre/repo/transactionNumber.js +67 -22
  70. package/lib/chevre/repo/transactionNumberCounter.d.ts +28 -0
  71. package/lib/chevre/repo/transactionNumberCounter.js +128 -0
  72. package/lib/chevre/repo/transactionProcess.d.ts +7 -4
  73. package/lib/chevre/repo/transactionProcess.js +34 -13
  74. package/lib/chevre/service/aggregation/event/aggregateOffers.js +1 -0
  75. package/lib/chevre/service/assetTransaction/reserve/start.js +9 -1
  76. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest.js +1 -1
  77. package/lib/chevre/service/code.js +1 -1
  78. package/lib/chevre/service/offer/event/checkAvailability.d.ts +1 -1
  79. package/lib/chevre/service/offer/event/checkAvailability.js +1 -0
  80. package/lib/chevre/service/offer/product.js +0 -40
  81. package/lib/chevre/service/payment/any.d.ts +0 -2
  82. package/lib/chevre/service/payment/any.js +1 -0
  83. package/lib/chevre/service/reserve/cancelReservation.d.ts +3 -0
  84. package/lib/chevre/service/reserve/cancelReservation.js +5 -1
  85. package/lib/chevre/service/task/acceptCOAOffer.js +2 -2
  86. package/lib/chevre/service/task/authorizePayment.js +4 -4
  87. package/lib/chevre/service/task/givePointAward.js +1 -1
  88. package/lib/chevre/service/task/moneyTransfer.js +1 -1
  89. package/lib/chevre/service/task/publishPaymentUrl.js +2 -2
  90. package/lib/chevre/service/task/refund.js +1 -1
  91. package/lib/chevre/service/task/returnMoneyTransfer.js +1 -1
  92. package/lib/chevre/service/task/returnPayTransaction.js +1 -1
  93. package/lib/chevre/service/task/returnPointAward.js +1 -1
  94. package/lib/chevre/service/task/returnReserveTransaction.js +1 -1
  95. package/lib/chevre/service/task.d.ts +8 -17
  96. package/lib/chevre/service/task.js +14 -5
  97. package/lib/chevre/service/transaction/placeOrder/start/validateStartRequest.js +2 -2
  98. package/lib/chevre/service/transaction/returnOrder/preStart/factory.d.ts +20 -0
  99. package/lib/chevre/service/transaction/returnOrder/preStart/factory.js +2 -0
  100. package/lib/chevre/service/transaction/returnOrder/preStart/findApplicableReturnPolicy.d.ts +23 -0
  101. package/lib/chevre/service/transaction/returnOrder/preStart/findApplicableReturnPolicy.js +323 -0
  102. package/lib/chevre/service/transaction/returnOrder/preStart/getReturnPolicyByProject.d.ts +13 -0
  103. package/lib/chevre/service/transaction/returnOrder/preStart/getReturnPolicyByProject.js +132 -0
  104. package/lib/chevre/service/transaction/returnOrder/preStart.js +2 -391
  105. package/package.json +3 -3
  106. package/example/src/chevre/migrateMembers2identities.ts +0 -109
  107. package/example/src/chevre/publishConfimationNumber.ts +0 -27
@@ -11,44 +11,65 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.TransactionProcessRepo = void 0;
13
13
  const createDebug = require("debug");
14
+ const moment = require("moment");
14
15
  const factory = require("../factory");
16
+ const concurrentLock_1 = require("./concurrentLock");
15
17
  const debug = createDebug('chevre-domain:repo:transactionProcess');
16
18
  const DEFAULT_LOCK_EXPIRES = 120;
17
19
  /**
18
20
  * 取引プロセスリポジトリ
19
21
  */
20
22
  class TransactionProcessRepo {
23
+ // private readonly redisClient: RedisClientType;
21
24
  constructor(redisClient, options) {
22
- this.redisClient = redisClient;
25
+ this.concurrentLockRepo = new concurrentLock_1.ConcurrentLockRepo({ redisClient });
26
+ // this.redisClient = redisClient;
23
27
  this.options = options;
24
28
  }
25
29
  static CREATE_REDIS_KEY(params) {
26
- // 最適化(2024-03-21~)
27
- // return `chevre-api:${params.project.id}:transactionProcess:${params.typeOf}:${params.id}`;
28
30
  return `chvrapi:lockTxn:${params.id}`;
29
31
  }
30
32
  lock(params) {
31
33
  return __awaiter(this, void 0, void 0, function* () {
32
34
  const key = TransactionProcessRepo.CREATE_REDIS_KEY(params);
33
- // const ttl = TRANSACTION_RROCESS_LOCK_EXPIRES;
34
35
  const ttl = (typeof this.options.lockExpiresInSeconds === 'number') ? this.options.lockExpiresInSeconds : DEFAULT_LOCK_EXPIRES;
35
- const results = yield this.redisClient.multi()
36
- .setNX(key, '1')
37
- .expire(key, ttl)
38
- .exec();
39
- debug('locked,', params.id, results);
40
- if (Array.isArray(results) && (results[0] === 1 || results[0] === true)) {
41
- return true;
36
+ const expires = moment()
37
+ .add(ttl, 'seconds')
38
+ .toDate();
39
+ // reimplement using concurrentLockRepo(2025-05-27~)
40
+ try {
41
+ yield this.concurrentLockRepo.lock({
42
+ project: { id: params.project.id, typeOf: factory.organizationType.Project },
43
+ about: { identifier: key, typeOf: 'Thing' },
44
+ expires,
45
+ audience: { identifier: '1', typeOf: 'Audience' }
46
+ });
47
+ debug('locked,', params.id);
42
48
  }
43
- else {
49
+ catch (error) {
44
50
  throw new factory.errors.AlreadyInUse(params.typeOf, [], 'Another transaction process in progress');
45
51
  }
52
+ // const results = await this.redisClient.multi()
53
+ // .setNX(key, '1')
54
+ // .expire(key, ttl)
55
+ // .exec();
56
+ // debug('locked,', params.id, results);
57
+ // if (Array.isArray(results) && (results[0] === 1 || (<any>results)[0] === true)) {
58
+ // return;
59
+ // } else {
60
+ // throw new factory.errors.AlreadyInUse(params.typeOf, [], 'Another transaction process in progress');
61
+ // }
46
62
  });
47
63
  }
48
64
  unlock(params) {
49
65
  return __awaiter(this, void 0, void 0, function* () {
50
66
  const key = TransactionProcessRepo.CREATE_REDIS_KEY(params);
51
- yield this.redisClient.del([key]);
67
+ // reimplement using concurrentLockRepo(2025-05-27~)
68
+ yield this.concurrentLockRepo.unlock({
69
+ about: { identifier: key, typeOf: 'Thing' },
70
+ audience: { identifier: '1', typeOf: 'Audience' }
71
+ });
72
+ // await this.redisClient.del([key]);
52
73
  });
53
74
  }
54
75
  }
@@ -239,6 +239,7 @@ function isHoldByRateLimit(params) {
239
239
  const unitInSeconds = (_b = params.offer.validRateLimit) === null || _b === void 0 ? void 0 : _b.unitInSeconds;
240
240
  if (typeof scope === 'string' && typeof unitInSeconds === 'number') {
241
241
  const rateLimitKey = {
242
+ project: { id: params.event.project.id },
242
243
  reservedTicket: {
243
244
  ticketType: {
244
245
  validRateLimit: { scope: scope, unitInSeconds: unitInSeconds }
@@ -170,6 +170,7 @@ function addReservations(params) {
170
170
  let lockedOfferRateLimitKeys = [];
171
171
  try {
172
172
  lockedOfferRateLimitKeys = yield processLockOfferRateLimit({
173
+ project: { id: params.event.project.id },
173
174
  reservations: objectSubReservations,
174
175
  reservationFor,
175
176
  reservationNumber
@@ -179,6 +180,7 @@ function addReservations(params) {
179
180
  if (lockedOfferRateLimitKeys.length > 0) {
180
181
  yield Promise.all(objectSubReservations.map((reservation) => __awaiter(this, void 0, void 0, function* () {
181
182
  yield (0, cancelReservation_1.processUnlockOfferRateLimit)({
183
+ project: { id: params.event.project.id },
182
184
  reservation: {
183
185
  reservationNumber,
184
186
  reservedTicket: reservation.reservedTicket
@@ -469,6 +471,7 @@ function processLockOfferRateLimit(params) {
469
471
  const unitInSeconds = (_b = reservation.reservedTicket.ticketType.validRateLimit) === null || _b === void 0 ? void 0 : _b.unitInSeconds;
470
472
  if (typeof scope === 'string' && typeof unitInSeconds === 'number') {
471
473
  const rateLimitKey = {
474
+ project: { id: params.project.id },
472
475
  reservedTicket: {
473
476
  ticketType: {
474
477
  validRateLimit: {
@@ -489,7 +492,12 @@ function processLockOfferRateLimit(params) {
489
492
  rateLimitKeys.push(rateLimitKey);
490
493
  }
491
494
  });
492
- yield repos.offerRateLimit.lock(rateLimitKeys);
495
+ if (rateLimitKeys.length > 0) {
496
+ if (rateLimitKeys.length > 1) {
497
+ throw new factory.errors.Argument('acceptedOffers', `Number of offers with rateLimit must be less than or equal to 1`);
498
+ }
499
+ yield repos.offerRateLimit.lock(rateLimitKeys[0]);
500
+ }
493
501
  return rateLimitKeys;
494
502
  });
495
503
  }
@@ -143,7 +143,7 @@ function validateEventOfferPeriod(params) {
143
143
  throw new factory.errors.ArgumentNull('reservationFor.offers.validForMemberTier');
144
144
  }
145
145
  // トークン検証
146
- const memberProgram = (yield repos.memberProgram.search({
146
+ const memberProgram = (yield repos.memberProgram.projectMemberPrograms({
147
147
  limit: 1,
148
148
  page: 1,
149
149
  project: { id: { $eq: params.event.project.id } },
@@ -41,7 +41,7 @@ function getToken(params) {
41
41
  const { id } = yield repos.ticket.issueByTicketToken(Object.assign({ project: { id: params.project.id }, ticketToken: params.code }, (typeof ((_a = authorization.issuedBy) === null || _a === void 0 ? void 0 : _a.id) === 'string') ? { issuedBy: authorization.issuedBy } : undefined));
42
42
  const jti = id;
43
43
  // ロール承認の場合、subjectはメンバーID,typはメンバータイプ
44
- if (authorization.object.typeOf === factory.iam.RoleType.OrganizationRole) {
44
+ if (authorization.object.typeOf === factory.role.RoleType.OrganizationRole) {
45
45
  subject = authorization.object.member.id;
46
46
  typ = `${jwtSetting.payloadTypPrefix}:${authorization.object.member.typeOf}`;
47
47
  }
@@ -2,7 +2,7 @@ import type { IMinimizedIndividualEvent } from '../../../repo/event';
2
2
  import type { OfferRateLimitRepo } from '../../../repo/rateLimit/offer';
3
3
  import * as factory from '../../../factory';
4
4
  declare function checkAvailability(params: {
5
- event: Pick<IMinimizedIndividualEvent<factory.eventType.Event | factory.eventType.ScreeningEvent>, 'startDate'>;
5
+ event: Pick<IMinimizedIndividualEvent<factory.eventType.Event | factory.eventType.ScreeningEvent>, 'startDate' | 'project'>;
6
6
  unitPriceOffer: factory.unitPriceOffer.IUnitPriceOffer;
7
7
  }): (repos: {
8
8
  offerRateLimit: OfferRateLimitRepo;
@@ -22,6 +22,7 @@ function checkAvailability(params) {
22
22
  const unitInSeconds = (_b = unitPriceOffer.validRateLimit) === null || _b === void 0 ? void 0 : _b.unitInSeconds;
23
23
  if (typeof scope === 'string' && typeof unitInSeconds === 'number') {
24
24
  const rateLimitKey = {
25
+ project: { id: params.event.project.id },
25
26
  reservedTicket: {
26
27
  ticketType: {
27
28
  validRateLimit: {
@@ -388,43 +388,3 @@ function createServiceOutputIdentifier(params) {
388
388
  })));
389
389
  });
390
390
  }
391
- // function processLockRegisterMembershipService(params: {
392
- // agent: { id: string };
393
- // product: factory.product.IProduct;
394
- // purpose: factory.action.authorize.offer.product.IPurpose;
395
- // }) {
396
- // return async (repos: {
397
- // registerActionInProgress: RegisterServiceInProgressRepo;
398
- // }) => {
399
- // if (params.product.typeOf === factory.product.ProductType.MembershipService) {
400
- // await repos.registerActionInProgress.lock(
401
- // {
402
- // agent: { id: params.agent.id },
403
- // product: { id: String(params.product.id) }
404
- // },
405
- // params.purpose.id
406
- // );
407
- // }
408
- // };
409
- // }
410
- // export function processUnlockRegisterMembershipService(params: {
411
- // agent: { id: string };
412
- // product: { id: string };
413
- // purpose: factory.action.authorize.offer.product.IPurpose;
414
- // }) {
415
- // return async (repos: {
416
- // registerActionInProgress: RegisterServiceInProgressRepo;
417
- // }) => {
418
- // // 登録ロックIDが取引IDであればロック解除
419
- // const holder = await repos.registerActionInProgress.getHolder({
420
- // agent: { id: params.agent.id },
421
- // product: { id: params.product.id }
422
- // });
423
- // if (holder === params.purpose.id) {
424
- // await repos.registerActionInProgress.unlock({
425
- // agent: { id: params.agent.id },
426
- // product: { id: params.product.id }
427
- // });
428
- // }
429
- // };
430
- // }
@@ -18,7 +18,6 @@ import type { TaskRepo } from '../../repo/task';
18
18
  import type { TicketRepo } from '../../repo/ticket';
19
19
  import type { TransactionRepo } from '../../repo/transaction';
20
20
  import type { TransactionNumberRepo } from '../../repo/transactionNumber';
21
- import type { TransactionProcessRepo } from '../../repo/transactionProcess';
22
21
  import * as PayTransactionService from '../assetTransaction/pay';
23
22
  import { onPaymentStatusChanged } from './any/onPaymentStatusChanged';
24
23
  import { person2username } from './any/person2username';
@@ -97,7 +96,6 @@ interface IAuthorizeRepos {
97
96
  ticket: TicketRepo;
98
97
  transaction: TransactionRepo;
99
98
  transactionNumber: TransactionNumberRepo;
100
- transactionProcess: TransactionProcessRepo;
101
99
  }
102
100
  type IAuthorizeOperation<T> = (repos: IAuthorizeRepos, settings: Settings) => Promise<T>;
103
101
  interface IPublishPaymentUrlRepos {
@@ -20,6 +20,7 @@ exports.processVoidPayTransaction = processVoidPayTransaction;
20
20
  exports.publishPaymentUrl = publishPaymentUrl;
21
21
  const util = require("util");
22
22
  const factory = require("../../factory");
23
+ // import type { TransactionProcessRepo } from '../../repo/transactionProcess';
23
24
  const PayTransactionService = require("../assetTransaction/pay");
24
25
  const publishOrderNumberIfNotExist_1 = require("../transaction/placeOrder/publishOrderNumberIfNotExist");
25
26
  const factory_1 = require("./any/factory");
@@ -31,6 +31,9 @@ declare function cancelReservation(actionAttributesList: factory.action.cancel.r
31
31
  assetTransaction: AssetTransactionRepo;
32
32
  }) => Promise<void>;
33
33
  declare function processUnlockOfferRateLimit(params: {
34
+ project: {
35
+ id: string;
36
+ };
34
37
  reservation: {
35
38
  reservationNumber: string;
36
39
  reservedTicket: factory.reservation.ITicket;
@@ -104,6 +104,7 @@ function cancelPengindIfNotYet(params) {
104
104
  : reserveTransactionId
105
105
  })(repos);
106
106
  yield processUnlockOfferRateLimit({
107
+ project: { id: reserveTransaction.project.id },
107
108
  reservation: {
108
109
  reservationNumber: reserveTransaction.object.reservationNumber,
109
110
  reservedTicket: cancelingSubReservation.reservedTicket
@@ -204,6 +205,7 @@ function cancelReservation(actionAttributesList) {
204
205
  : reserveTransaction.id
205
206
  })(repos);
206
207
  yield processUnlockOfferRateLimit({
208
+ project: { id: reserveTransaction.project.id },
207
209
  reservation: {
208
210
  reservationNumber: reserveTransaction.object.reservationNumber,
209
211
  reservedTicket: cancelingSubReservation.reservedTicket
@@ -253,6 +255,7 @@ function cancelReservation(actionAttributesList) {
253
255
  })(repos);
254
256
  }
255
257
  yield processUnlockOfferRateLimit({
258
+ project: { id: reservation.project.id },
256
259
  reservation: {
257
260
  reservationNumber: reservation.reservationNumber,
258
261
  reservedTicket: reservation.reservedTicket
@@ -401,6 +404,7 @@ function processUnlockOfferRateLimit(params) {
401
404
  const unitInSeconds = (_b = reservation.reservedTicket.ticketType.validRateLimit) === null || _b === void 0 ? void 0 : _b.unitInSeconds;
402
405
  if (typeof scope === 'string' && typeof unitInSeconds === 'number') {
403
406
  const rateLimitKey = {
407
+ project: { id: params.project.id },
404
408
  reservedTicket: {
405
409
  ticketType: {
406
410
  validRateLimit: {
@@ -420,7 +424,7 @@ function processUnlockOfferRateLimit(params) {
420
424
  };
421
425
  const holder = yield repos.offerRateLimit.getHolder(rateLimitKey);
422
426
  if (holder === rateLimitKey.reservationNumber) {
423
- yield repos.offerRateLimit.unlock([rateLimitKey]);
427
+ yield repos.offerRateLimit.unlock(rateLimitKey);
424
428
  }
425
429
  }
426
430
  });
@@ -86,7 +86,7 @@ function call(params) {
86
86
  })({
87
87
  action: actionRepo,
88
88
  event: new event_1.EventRepo(connection),
89
- orderNumber: new orderNumber_1.OrderNumberRepo(redisClient),
89
+ orderNumber: new orderNumber_1.OrderNumberRepo({ redisClient, connection }),
90
90
  project: new project_1.ProjectRepo(connection),
91
91
  transaction: new transaction_1.TransactionRepo(connection),
92
92
  reserveService,
@@ -104,7 +104,7 @@ function call(params) {
104
104
  })({
105
105
  action: actionRepo,
106
106
  event: new event_1.EventRepo(connection),
107
- orderNumber: new orderNumber_1.OrderNumberRepo(redisClient),
107
+ orderNumber: new orderNumber_1.OrderNumberRepo({ redisClient, connection }),
108
108
  project: new project_1.ProjectRepo(connection),
109
109
  transaction: new transaction_1.TransactionRepo(connection),
110
110
  reserveService,
@@ -57,13 +57,13 @@ function call(params) {
57
57
  action: actionRepo,
58
58
  assetTransaction: new assetTransaction_1.AssetTransactionRepo(connection),
59
59
  authorization: new authorization_1.AuthorizationRepo(connection),
60
- confirmationNumber: new confirmationNumber_1.ConfirmationNumberRepo(redisClient),
60
+ confirmationNumber: new confirmationNumber_1.ConfirmationNumberRepo({ redisClient, connection }),
61
61
  credentials: new credentials_1.CredentialsRepo(redisClient, {
62
62
  scope: `${factory.service.paymentService.PaymentServiceType.MovieTicket}:${paymentServiceId}`,
63
63
  expireInSeconds: (useCredentialsRepo) ? credentialsExpireInSeconds : 0
64
64
  }),
65
65
  event: new event_1.EventRepo(connection),
66
- orderNumber: new orderNumber_1.OrderNumberRepo(redisClient),
66
+ orderNumber: new orderNumber_1.OrderNumberRepo({ redisClient, connection }),
67
67
  paymentAccepted: new sellerPaymentAccepted_1.SellerPaymentAcceptedRepo(connection),
68
68
  paymentService: new paymentService_1.PaymentServiceRepo(connection),
69
69
  paymentServiceProvider: new paymentServiceProvider_1.PaymentServiceProviderRepo(connection),
@@ -73,8 +73,8 @@ function call(params) {
73
73
  task: new task_1.TaskRepo(connection),
74
74
  ticket: new ticket_1.TicketRepo(connection),
75
75
  transaction: new transaction_1.TransactionRepo(connection),
76
- transactionNumber: new transactionNumber_1.TransactionNumberRepo(redisClient),
77
- transactionProcess: transactionProcessRepo
76
+ transactionNumber: new transactionNumber_1.TransactionNumberRepo({ redisClient, connection })
77
+ // transactionProcess: transactionProcessRepo
78
78
  }, settings);
79
79
  }
80
80
  catch (error) {
@@ -29,7 +29,7 @@ function call(data) {
29
29
  const assetTransactionRepo = new assetTransaction_1.AssetTransactionRepo(connection);
30
30
  const productRepo = new product_1.ProductRepo(connection);
31
31
  const projectRepo = new project_1.ProjectRepo(connection);
32
- const transactionNumberRepo = new transactionNumber_1.TransactionNumberRepo(redisClient);
32
+ const transactionNumberRepo = new transactionNumber_1.TransactionNumberRepo({ redisClient, connection });
33
33
  yield DeliveryService.givePointAward(data)({
34
34
  action: actionRepo,
35
35
  assetTransaction: assetTransactionRepo,
@@ -25,7 +25,7 @@ function call(data) {
25
25
  }
26
26
  const actionRepo = new action_1.ActionRepo(connection);
27
27
  const productRepo = new product_1.ProductRepo(connection);
28
- const transactionNumberRepo = new transactionNumber_1.TransactionNumberRepo(redisClient);
28
+ const transactionNumberRepo = new transactionNumber_1.TransactionNumberRepo({ redisClient, connection });
29
29
  yield MoneyTransferService.moneyTransfer(data)({
30
30
  action: actionRepo,
31
31
  product: productRepo,
@@ -43,14 +43,14 @@ function call(params) {
43
43
  action: actionRepo,
44
44
  assetTransaction: new assetTransaction_1.AssetTransactionRepo(connection),
45
45
  authorization: new authorization_1.AuthorizationRepo(connection),
46
- orderNumber: new orderNumber_1.OrderNumberRepo(redisClient),
46
+ orderNumber: new orderNumber_1.OrderNumberRepo({ redisClient, connection }),
47
47
  paymentAccepted: new sellerPaymentAccepted_1.SellerPaymentAcceptedRepo(connection),
48
48
  paymentService: new paymentService_1.PaymentServiceRepo(connection),
49
49
  paymentServiceProvider: new paymentServiceProvider_1.PaymentServiceProviderRepo(connection),
50
50
  project: new project_1.ProjectRepo(connection),
51
51
  ticket: new ticket_1.TicketRepo(connection),
52
52
  transaction: new transaction_1.TransactionRepo(connection),
53
- transactionNumber: new transactionNumber_1.TransactionNumberRepo(redisClient)
53
+ transactionNumber: new transactionNumber_1.TransactionNumberRepo({ redisClient, connection })
54
54
  }, settings);
55
55
  }
56
56
  catch (error) {
@@ -58,7 +58,7 @@ function call(params) {
58
58
  project: new project_1.ProjectRepo(connection),
59
59
  task: new task_1.TaskRepo(connection),
60
60
  assetTransaction: new assetTransaction_1.AssetTransactionRepo(connection),
61
- transactionNumber: new transactionNumber_1.TransactionNumberRepo(redisClient)
61
+ transactionNumber: new transactionNumber_1.TransactionNumberRepo({ redisClient, connection })
62
62
  }, settings);
63
63
  });
64
64
  }
@@ -29,7 +29,7 @@ function call(data) {
29
29
  const assetTransactionRepo = new assetTransaction_1.AssetTransactionRepo(connection);
30
30
  const productRepo = new product_1.ProductRepo(connection);
31
31
  const projectRepo = new project_1.ProjectRepo(connection);
32
- const transactionNumberRepo = new transactionNumber_1.TransactionNumberRepo(redisClient);
32
+ const transactionNumberRepo = new transactionNumber_1.TransactionNumberRepo({ redisClient, connection });
33
33
  yield (0, returnMoneyTransfer_1.returnMoneyTransfer)(data)({
34
34
  action: actionRepo,
35
35
  assetTransaction: assetTransactionRepo,
@@ -39,7 +39,7 @@ function call(params) {
39
39
  product: new product_1.ProductRepo(connection),
40
40
  task: new task_1.TaskRepo(connection),
41
41
  transaction: new transaction_1.TransactionRepo(connection),
42
- transactionNumber: new transactionNumber_1.TransactionNumberRepo(redisClient)
42
+ transactionNumber: new transactionNumber_1.TransactionNumberRepo({ redisClient, connection })
43
43
  });
44
44
  });
45
45
  }
@@ -29,7 +29,7 @@ function call(data) {
29
29
  const assetTransactionRepo = new assetTransaction_1.AssetTransactionRepo(connection);
30
30
  const productRepo = new product_1.ProductRepo(connection);
31
31
  const projectRepo = new project_1.ProjectRepo(connection);
32
- const transactionNumberRepo = new transactionNumber_1.TransactionNumberRepo(redisClient);
32
+ const transactionNumberRepo = new transactionNumber_1.TransactionNumberRepo({ redisClient, connection });
33
33
  yield DeliveryService.returnPointAward(data)({
34
34
  action: actionRepo,
35
35
  assetTransaction: assetTransactionRepo,
@@ -55,7 +55,7 @@ function call(params) {
55
55
  assetTransaction: new assetTransaction_1.AssetTransactionRepo(connection),
56
56
  project: new project_1.ProjectRepo(connection),
57
57
  reservation: new reservation_1.ReservationRepo(connection),
58
- transactionNumber: new transactionNumber_1.TransactionNumberRepo(redisClient),
58
+ transactionNumber: new transactionNumber_1.TransactionNumberRepo({ redisClient, connection }),
59
59
  reserveService
60
60
  });
61
61
  });
@@ -1,6 +1,5 @@
1
- import type { Connection } from 'mongoose';
2
- import type { RedisClientType } from 'redis';
3
1
  import { SendGridCredentials } from '../credentials/sendGrid';
2
+ import type { IExecuteSettings as IMinimumExecuteSettings, INextFunction, IReadyTask, IRunningTask } from '../eventEmitter/task';
4
3
  import * as factory from '../factory';
5
4
  import type { IExecutableTask, IExecutableTaskKeys, TaskRepo } from '../repo/task';
6
5
  import { Settings } from '../settings';
@@ -8,15 +7,7 @@ import { AggregationSettings } from '../settings/aggregation';
8
7
  interface ICredentialSettings {
9
8
  sendGrid: SendGridCredentials;
10
9
  }
11
- interface IExecuteSettings {
12
- /**
13
- * MongoDBコネクション
14
- */
15
- connection: Connection;
16
- /**
17
- * Redisクライアント
18
- */
19
- redisClient?: RedisClientType;
10
+ interface IExecuteSettings extends IMinimumExecuteSettings {
20
11
  credentials: ICredentialSettings;
21
12
  settings: Settings;
22
13
  aggregationSettings?: AggregationSettings;
@@ -29,17 +20,17 @@ type IOperation<T> = (settings: IExecuteSettings) => Promise<T>;
29
20
  type IOperationExecute<T> = (settings: IExecuteSettings, options: IExecuteOptions) => Promise<T>;
30
21
  type ICallResult = void | Pick<factory.task.IExecutionResult, 'error'>;
31
22
  export type ICallableTaskOperation = (task: IExecutableTask<factory.taskName>) => IOperationExecute<ICallResult>;
32
- declare function executeById(params: {
33
- id: string;
34
- status: factory.taskStatus.Ready | factory.taskStatus.Running;
23
+ /**
24
+ * タスク変更イベントを受けて実行する
25
+ */
26
+ declare function executeById(params: (IReadyTask | IRunningTask) & {
35
27
  executor: {
36
28
  /**
37
29
  * タスク実行者名称
38
30
  */
39
31
  name: string;
40
32
  };
41
- expires?: Date;
42
- }): IOperation<void>;
33
+ }, next?: INextFunction): IOperation<void>;
43
34
  /**
44
35
  * support no name(2025-03-04~)
45
36
  */
@@ -61,7 +52,7 @@ declare function executeOneIfExists(params: {
61
52
  /**
62
53
  * タスクを実行する
63
54
  */
64
- declare function execute(task: IExecutableTask<factory.taskName>): IOperationExecute<void>;
55
+ declare function execute(task: IExecutableTask<factory.taskName>, next?: INextFunction): IOperationExecute<void>;
65
56
  /**
66
57
  * add(2025-03-13~)
67
58
  */
@@ -21,7 +21,10 @@ const moment = require("moment");
21
21
  const factory = require("../factory");
22
22
  const factory_1 = require("./notification/factory");
23
23
  const debug = createDebug('chevre-domain:service:task');
24
- function executeById(params) {
24
+ /**
25
+ * タスク変更イベントを受けて実行する
26
+ */
27
+ function executeById(params, next) {
25
28
  return (settings) => __awaiter(this, void 0, void 0, function* () {
26
29
  const taskRepo = new (yield Promise.resolve().then(() => require('../repo/task'))).TaskRepo(settings.connection);
27
30
  const { id, status, executor, expires } = params;
@@ -39,7 +42,7 @@ function executeById(params) {
39
42
  }
40
43
  // タスクがなければ終了
41
44
  if (task !== null) {
42
- yield execute(task)(settings, {
45
+ yield execute(task, (typeof next === 'function') ? next : undefined)(settings, {
43
46
  executeById: true,
44
47
  executeByName: false
45
48
  });
@@ -77,7 +80,7 @@ function executeOneIfExists(params) {
77
80
  /**
78
81
  * タスクを実行する
79
82
  */
80
- function execute(task) {
83
+ function execute(task, next) {
81
84
  const now = new Date();
82
85
  debug('executing an executableTask...', task, now);
83
86
  return (settings, options) => __awaiter(this, void 0, void 0, function* () {
@@ -129,7 +132,10 @@ function execute(task) {
129
132
  error: ((callResult === null || callResult === void 0 ? void 0 : callResult.error) instanceof Error)
130
133
  ? Object.assign(Object.assign({}, callResult.error), { message: callResult.error.message }) : ''
131
134
  };
132
- yield taskRepo.pushExecutionResultById(task.id, factory.taskStatus.Executed, result);
135
+ yield taskRepo.pushExecutionResultById({
136
+ id: task.id,
137
+ status: factory.taskStatus.Executed
138
+ }, result, (typeof next === 'function') ? next : undefined);
133
139
  }
134
140
  catch (error) {
135
141
  debug('service.task.execute throwed an error. task:', task.name, task.id, 'error:', error === null || error === void 0 ? void 0 : error.name, error === null || error === void 0 ? void 0 : error.message);
@@ -143,7 +149,10 @@ function execute(task) {
143
149
  error: Object.assign(Object.assign({}, error), { code: error.code, message: error.message, name: error.name, stack: error.stack })
144
150
  };
145
151
  // 失敗してもここではステータスを戻さない(Runningのまま待機)
146
- yield taskRepo.pushExecutionResultById(task.id, task.status, result);
152
+ yield taskRepo.pushExecutionResultById({
153
+ id: task.id,
154
+ status: task.status
155
+ }, result, (typeof next === 'function') ? next : undefined);
147
156
  }
148
157
  });
149
158
  }
@@ -116,7 +116,7 @@ function validateStartRequest(params) {
116
116
  }
117
117
  })).shift();
118
118
  if (iamMember === undefined) {
119
- throw new factory.errors.NotFound(factory.iam.RoleType.OrganizationRole);
119
+ throw new factory.errors.NotFound(factory.role.RoleType.OrganizationRole);
120
120
  }
121
121
  // メンバーシップトークン検証(2024-01-31~)
122
122
  let memeberOfPayload;
@@ -124,7 +124,7 @@ function validateStartRequest(params) {
124
124
  const validMemberProgramIdentifier = (_c = projectMakesOffer.validForMemberTier) === null || _c === void 0 ? void 0 : _c.isTierOf.identifier;
125
125
  if (typeof validMemberProgramIdentifier === 'string') {
126
126
  // メンバープログラムと発行者を参照(2025-01-16~)
127
- const memberProgram = (yield repos.memberProgram.search({
127
+ const memberProgram = (yield repos.memberProgram.projectMemberPrograms({
128
128
  limit: 1,
129
129
  page: 1,
130
130
  project: { id: { $eq: params.project.id } },
@@ -0,0 +1,20 @@
1
+ import * as factory from '../../../../factory';
2
+ /**
3
+ * 販売者に設定された利用可能な販売者返品ポリシー
4
+ */
5
+ type IAvailableSellerReturnPolicy = Pick<factory.sellerReturnPolicy.ISellerReturnPolicy, 'applicablePaymentMethod' | 'identifier' | 'itemCondition' | 'merchantReturnDays' | 'restockingFee' | 'typeOf'>;
6
+ /**
7
+ * プロジェクトのカスタム返品ポリシー
8
+ * リモートから取得
9
+ */
10
+ type ICustomSellerReturnPolicy = Pick<factory.sellerReturnPolicy.ISellerReturnPolicy, 'identifier' | 'restockingFee' | 'typeOf'> & {
11
+ /**
12
+ * support itemCondition(2025-05-17~)
13
+ */
14
+ itemCondition?: factory.offerItemCondition.OfferItemCondition;
15
+ applicablePaymentMethod?: never;
16
+ merchantReturnDays?: never;
17
+ };
18
+ type IFixedAcceptedOffer = Pick<factory.order.IAcceptedOffer<factory.order.IItemOffered>, 'id' | 'priceSpecification' | 'itemOffered'>;
19
+ type IFixedOrder = Pick<factory.order.IOrder, 'confirmationNumber' | 'dateReturned' | 'orderDate' | 'orderNumber' | 'orderStatus' | 'paymentMethods' | 'price' | 'project' | 'seller' | 'typeOf'>;
20
+ export { IAvailableSellerReturnPolicy, ICustomSellerReturnPolicy, IFixedAcceptedOffer, IFixedOrder };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,23 @@
1
+ import * as factory from '../../../../factory';
2
+ import { IAvailableSellerReturnPolicy, IFixedAcceptedOffer, IFixedOrder } from './factory';
3
+ /**
4
+ * 採用可能な販売者の返品ポリシーをひとつ選択する
5
+ * restockingFeeが最低のポリシーを自動選択
6
+ */
7
+ declare function findApplicableReturnPolicy(params: {
8
+ acceptedOffers: IFixedAcceptedOffer[];
9
+ events: {
10
+ id: string;
11
+ startDate: Date;
12
+ }[];
13
+ offerItemConditions: Pick<factory.offerItemCondition.IOfferItemCondition, 'id' | 'identifier' | 'itemOffered' | 'typeOf'>[];
14
+ orders: IFixedOrder[];
15
+ returningDate: Date;
16
+ reason: factory.transaction.returnOrder.Reason;
17
+ returnPolicies: IAvailableSellerReturnPolicy[];
18
+ returnPolicySettingsByProject?: factory.project.IHasMerchantReturnPolicy;
19
+ offers: factory.unitPriceOffer.IUnitPriceOffer[];
20
+ policiesByOffer: factory.unitPriceOffer.IOfferMerchantReturnPolicy[];
21
+ usedReservationExists: boolean;
22
+ }): Promise<factory.action.transfer.returnAction.order.IReturnPolicy>;
23
+ export { findApplicableReturnPolicy };