@chevre/domain 23.1.0-alpha.3 → 23.1.0-alpha.31

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 (95) hide show
  1. package/example/src/chevre/acceptedPaymentMethodOffer/adminAcceptedPaymentMethodOffers.ts +68 -0
  2. package/example/src/chevre/actions/checkAcceptPayActions.ts +60 -0
  3. package/example/src/chevre/assetTransaction/checkPayTransactionsTicketToken.ts +67 -0
  4. package/example/src/chevre/assetTransaction/processReserve.ts +8 -3
  5. package/example/src/chevre/authorizeEventServiceOffer.ts +7 -5
  6. package/example/src/chevre/eventSeries/migrateEventSeriesUnacceptedPaymentMethod.ts +93 -0
  7. package/example/src/chevre/member/migrateMemberIdentifier.ts +99 -0
  8. package/example/src/chevre/place/checkSectionCount.ts +27 -0
  9. package/example/src/chevre/place/findSectionsByRoom.ts +50 -0
  10. package/example/src/chevre/project/unsetProjectSettings.ts +73 -0
  11. package/example/src/chevre/reIndex.ts +1 -2
  12. package/example/src/chevre/roles/{addAdminSellerEventIfNotExists.ts → addAdminSellerEventOfferIfNotExists.ts} +1 -1
  13. package/example/src/chevre/stockHolder/findSeatsBySection.ts +59 -0
  14. package/example/src/chevre/stockHolder/searchSeats.ts +2 -2
  15. package/lib/chevre/repo/acceptedPaymentMethod.d.ts +41 -0
  16. package/lib/chevre/repo/acceptedPaymentMethod.js +180 -0
  17. package/lib/chevre/repo/authorization.d.ts +3 -2
  18. package/lib/chevre/repo/authorization.js +13 -5
  19. package/lib/chevre/repo/event.d.ts +1 -35
  20. package/lib/chevre/repo/event.js +2 -102
  21. package/lib/chevre/repo/eventOffer.d.ts +1 -1
  22. package/lib/chevre/repo/eventOffer.js +16 -10
  23. package/lib/chevre/repo/member.d.ts +18 -1
  24. package/lib/chevre/repo/member.js +14 -8
  25. package/lib/chevre/repo/mongoose/schemas/acceptedPaymentMethod.d.ts +10 -0
  26. package/lib/chevre/repo/mongoose/schemas/acceptedPaymentMethod.js +97 -0
  27. package/lib/chevre/repo/mongoose/schemas/eventOffer.js +48 -35
  28. package/lib/chevre/repo/mongoose/schemas/member.js +10 -0
  29. package/lib/chevre/repo/place/seat.d.ts +24 -0
  30. package/lib/chevre/repo/place/seat.js +103 -21
  31. package/lib/chevre/repo/place/section.d.ts +20 -0
  32. package/lib/chevre/repo/place/section.js +47 -0
  33. package/lib/chevre/repo/ticket.d.ts +7 -1
  34. package/lib/chevre/repo/ticket.js +14 -1
  35. package/lib/chevre/repository.d.ts +5 -0
  36. package/lib/chevre/repository.js +15 -2
  37. package/lib/chevre/service/assetTransaction/pay/factory.d.ts +1 -1
  38. package/lib/chevre/service/assetTransaction/pay/factory.js +8 -3
  39. package/lib/chevre/service/assetTransaction/pay/validateAcceptedPaymentMethodIfNeeded.d.ts +16 -0
  40. package/lib/chevre/service/assetTransaction/pay/validateAcceptedPaymentMethodIfNeeded.js +92 -0
  41. package/lib/chevre/service/assetTransaction/pay.d.ts +6 -1
  42. package/lib/chevre/service/assetTransaction/pay.js +6 -1
  43. package/lib/chevre/service/assetTransaction/reserve/start.d.ts +6 -0
  44. package/lib/chevre/service/assetTransaction/reserve/start.js +5 -1
  45. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/fixExtendedEventOffer.d.ts +22 -0
  46. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/fixExtendedEventOffer.js +63 -0
  47. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/validateIssuedOfferIfExists.d.ts +7 -2
  48. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/validateIssuedOfferIfExists.js +32 -32
  49. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/validateMemberTierIfExists.d.ts +1 -1
  50. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/validateMemberTierIfExists.js +10 -54
  51. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/verifyTicketTokenAsNeeded.d.ts +23 -0
  52. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/verifyTicketTokenAsNeeded.js +62 -0
  53. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest.d.ts +36 -1
  54. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest.js +23 -27
  55. package/lib/chevre/service/offer/event/authorize/factory.d.ts +0 -3
  56. package/lib/chevre/service/offer/event/authorize/factory.js +4 -3
  57. package/lib/chevre/service/offer/event/authorize/processStartReserve4chevre/requestedProgramMembershipUsed2permit.js +43 -26
  58. package/lib/chevre/service/offer/event/authorize/processStartReserve4chevre.d.ts +4 -0
  59. package/lib/chevre/service/offer/event/authorize/processStartReserve4chevre.js +4 -4
  60. package/lib/chevre/service/offer/event/authorize.d.ts +3 -0
  61. package/lib/chevre/service/offer/event/authorize.js +10 -5
  62. package/lib/chevre/service/offer/event/issueEventOfferTicket.d.ts +48 -0
  63. package/lib/chevre/service/offer/event/issueEventOfferTicket.js +123 -0
  64. package/lib/chevre/service/offer/event.d.ts +2 -1
  65. package/lib/chevre/service/offer/event.js +3 -1
  66. package/lib/chevre/service/payment/any/authorize/fixTransactionNumber.d.ts +9 -0
  67. package/lib/chevre/service/payment/any/authorize/fixTransactionNumber.js +22 -11
  68. package/lib/chevre/service/payment/any/authorize/handlePrePublishedPaymentMethodIdOnAuthorizing.d.ts +19 -2
  69. package/lib/chevre/service/payment/any/authorize/handlePrePublishedPaymentMethodIdOnAuthorizing.js +87 -9
  70. package/lib/chevre/service/payment/any/factory.d.ts +20 -3
  71. package/lib/chevre/service/payment/any/factory.js +26 -6
  72. package/lib/chevre/service/payment/any/publishPaymentUrl/fixTransactionNumberOnPublishPaymentUrl.d.ts +4 -0
  73. package/lib/chevre/service/payment/any/publishPaymentUrl/fixTransactionNumberOnPublishPaymentUrl.js +15 -11
  74. package/lib/chevre/service/payment/any/verifyTicketTokenAsNeeded.d.ts +6 -3
  75. package/lib/chevre/service/payment/any/verifyTicketTokenAsNeeded.js +20 -28
  76. package/lib/chevre/service/payment/any.d.ts +5 -1
  77. package/lib/chevre/service/payment/any.js +22 -13
  78. package/lib/chevre/service/payment/factory.js +0 -5
  79. package/lib/chevre/service/payment/movieTicket/authorize.js +0 -5
  80. package/lib/chevre/service/task/authorizePayment.js +2 -0
  81. package/lib/chevre/service/task/publishPaymentUrl.js +4 -0
  82. package/lib/chevre/service/transaction/placeOrder/confirm/publishCode.js +1 -1
  83. package/lib/chevre/service/transaction/placeOrder/confirm/validation/factory.d.ts +9 -0
  84. package/lib/chevre/service/transaction/placeOrder/confirm/validation/factory.js +2 -0
  85. package/lib/chevre/service/transaction/placeOrder/confirm/validation/validateInvoiceReferencesOrder.d.ts +8 -0
  86. package/lib/chevre/service/transaction/placeOrder/confirm/validation/validateInvoiceReferencesOrder.js +45 -0
  87. package/lib/chevre/service/transaction/placeOrder/confirm/validation/validatePrice.d.ts +3 -0
  88. package/lib/chevre/service/transaction/placeOrder/confirm/validation/validatePrice.js +38 -0
  89. package/lib/chevre/service/transaction/placeOrder/confirm/validation.d.ts +2 -8
  90. package/lib/chevre/service/transaction/placeOrder/confirm/validation.js +5 -35
  91. package/package.json +3 -3
  92. package/example/src/chevre/checkReplaceActions.ts +0 -65
  93. package/example/src/chevre/upsertManyEventsByAdditionalProperty.ts +0 -193
  94. package/lib/chevre/service/code.d.ts +0 -8
  95. package/lib/chevre/service/code.js +0 -7
@@ -14,7 +14,7 @@ export declare function createStartParams(params: factory.assetTransaction.pay.I
14
14
  */
15
15
  id: string;
16
16
  }[];
17
- instrument: factory.action.trade.pay.IInstrument[];
17
+ instrument: factory.action.trade.pay.IPlaceOrderRelatedInstrument[];
18
18
  }, options: {
19
19
  checkedAction: {
20
20
  id: string;
@@ -7,7 +7,7 @@ exports.createStartParams = createStartParams;
7
7
  const factory = require("../../../factory");
8
8
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
9
9
  function createStartParams(params, options) {
10
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0;
10
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1;
11
11
  const { instrument } = params;
12
12
  const paymentServiceId = (params.paymentService !== undefined)
13
13
  ? String(params.paymentService.id)
@@ -109,7 +109,12 @@ function createStartParams(params, options) {
109
109
  : undefined);
110
110
  const object = Object.assign({ accountId: (typeof accountId === 'string') ? accountId : '', paymentMethodId: params.transactionNumber, typeOf: params.paymentServiceType, id: paymentServiceId,
111
111
  // onPaymentStatusChanged: { informPayment: params.informActions }, // discontinue(2025-02-09~)
112
- paymentMethod }, (params.paymentServiceType === factory.service.paymentService.PaymentServiceType.MovieTicket)
112
+ paymentMethod, serviceOutput: (((_0 = params.object.serviceOutput) === null || _0 === void 0 ? void 0 : _0.typeOf) === 'Invoice') // support serviceOutput(2025-11-24~)
113
+ ? params.object.serviceOutput
114
+ : {
115
+ typeOf: 'Invoice',
116
+ referencesOrder: { typeOf: factory.order.OrderType.Order }
117
+ } }, (params.paymentServiceType === factory.service.paymentService.PaymentServiceType.MovieTicket)
113
118
  ? { checkedAction: { id: options.checkedAction.id } } // add checkedAction(2024-12-13~)
114
119
  : undefined);
115
120
  const potentialAction = [];
@@ -118,7 +123,7 @@ function createStartParams(params, options) {
118
123
  potentialAction.push({ id: informAction.id, typeOf: factory.actionType.InformAction });
119
124
  }
120
125
  });
121
- return Object.assign(Object.assign({ project: { typeOf: factory.organizationType.Project, id: params.project.id }, transactionNumber: params.transactionNumber, typeOf: factory.assetTransactionType.Pay, agent: params.agent, recipient: params.recipient, object, expires: params.expires, instrument: (Array.isArray(instrument)) ? instrument : [] }, (typeof ((_0 = params.location) === null || _0 === void 0 ? void 0 : _0.typeOf) === 'string')
126
+ return Object.assign(Object.assign({ project: { typeOf: factory.organizationType.Project, id: params.project.id }, transactionNumber: params.transactionNumber, typeOf: factory.assetTransactionType.Pay, agent: params.agent, recipient: params.recipient, object, expires: params.expires, instrument: (Array.isArray(instrument)) ? instrument : [] }, (typeof ((_1 = params.location) === null || _1 === void 0 ? void 0 : _1.typeOf) === 'string')
122
127
  ? { location: params.location }
123
128
  : undefined), (potentialAction.length > 0) ? { potentialAction } : undefined // add potentialAction(2025-02-05~)
124
129
  );
@@ -0,0 +1,16 @@
1
+ import * as factory from '../../../factory';
2
+ import type { EventRepo } from '../../../repo/event';
3
+ import type { EventSeriesRepo } from '../../../repo/eventSeries';
4
+ /**
5
+ * 必要あらば関連リソースの対応決済方法を検証する
6
+ */
7
+ export declare function validateAcceptedPaymentMethodIfNeeded(params: Pick<factory.assetTransaction.pay.IStartParamsWithoutDetail, 'object'> | {
8
+ object: factory.action.accept.pay.IPayObject & {
9
+ paymentMethod: factory.action.accept.pay.IPaymentMethod & {
10
+ movieTickets: never;
11
+ };
12
+ };
13
+ }): (repos: {
14
+ event: EventRepo;
15
+ eventSeries: EventSeriesRepo;
16
+ }) => Promise<void>;
@@ -0,0 +1,92 @@
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
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.validateAcceptedPaymentMethodIfNeeded = validateAcceptedPaymentMethodIfNeeded;
13
+ /**
14
+ * ペイメントカード決済取引バリデーション
15
+ */
16
+ const createDebug = require("debug");
17
+ const factory = require("../../../factory");
18
+ const debug = createDebug('chevre-domain:service:assetTransaction:pay');
19
+ /**
20
+ * 必要あらば関連リソースの対応決済方法を検証する
21
+ */
22
+ function validateAcceptedPaymentMethodIfNeeded(params) {
23
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
24
+ var _a, _b;
25
+ /**
26
+ * 検証対象のイベントIDリスト
27
+ */
28
+ let checkingEventIds;
29
+ const paymentServiceType = params.object.typeOf;
30
+ // CreditCard or MovieTicket?
31
+ if (paymentServiceType === factory.service.paymentService.PaymentServiceType.CreditCard) {
32
+ const orderedItems = (_a = params.object.serviceOutput) === null || _a === void 0 ? void 0 : _a.referencesOrder.orderedItem;
33
+ if (Array.isArray(orderedItems)) {
34
+ checkingEventIds = orderedItems.map((orderedItem) => orderedItem.orderedItem.serviceOutput.reservationFor.id);
35
+ }
36
+ }
37
+ else if (paymentServiceType === factory.service.paymentService.PaymentServiceType.MovieTicket) {
38
+ const movieTickets = params.object.paymentMethod.movieTickets;
39
+ if (Array.isArray(movieTickets)) {
40
+ checkingEventIds = [...new Set(movieTickets.map((ticket) => ticket.serviceOutput.reservationFor.id))];
41
+ // イベントがひとつに特定されているかどうか確認
42
+ if (checkingEventIds.length !== 1) {
43
+ throw new factory.errors.Argument('movieTickets', 'Number of events must be 1');
44
+ }
45
+ }
46
+ }
47
+ else {
48
+ // 対面決済ではひとまず対応決済方法検証なし
49
+ }
50
+ debug('validateAcceptedPaymentMethodIfNeeded: checkingEventIds:', checkingEventIds, paymentServiceType);
51
+ if (Array.isArray(checkingEventIds)) {
52
+ if (checkingEventIds.length === 0) {
53
+ throw new factory.errors.ArgumentNull('object.serviceOutput.referencesOrder.orderedItem');
54
+ }
55
+ // 指定された全イベントについて、施設コンテンツの対応決済方法を検証する
56
+ const eventSeriesIds = (yield repos.event.projectEventFields({
57
+ limit: checkingEventIds.length,
58
+ page: 1,
59
+ id: { $in: checkingEventIds },
60
+ typeOf: factory.eventType.ScreeningEvent
61
+ }, ['superEvent'])).map((event) => event.superEvent.id);
62
+ if (eventSeriesIds.length !== checkingEventIds.length) {
63
+ throw new factory.errors.NotFound(factory.eventType.ScreeningEvent);
64
+ }
65
+ const uniqueEventSeriesIds = [...new Set(eventSeriesIds)];
66
+ debug('validateAcceptedPaymentMethodIfNeeded: eventSeries with AggregateOffer?', uniqueEventSeriesIds);
67
+ for (const eventSeriesId of uniqueEventSeriesIds) {
68
+ const eventSeries = (yield repos.eventSeries.projectEventSeriesFields({
69
+ limit: 1,
70
+ page: 1,
71
+ id: { $eq: eventSeriesId }
72
+ }, ['offers'])).shift();
73
+ if (eventSeries === undefined) {
74
+ throw new factory.errors.NotFound(factory.eventType.ScreeningEventSeries);
75
+ }
76
+ if (((_b = eventSeries.offers) === null || _b === void 0 ? void 0 : _b.typeOf) === factory.offerType.AggregateOffer) {
77
+ // 対応決済方法オファーIDの指定が必要
78
+ throw new factory.errors.ArgumentNull('acceptedPaymentMethodOfferId');
79
+ // if (paymentAccepted !== true) {
80
+ // throw new factory.errors.Argument('recipient', `payment not accepted [${paymentMethodType}]`);
81
+ // }
82
+ }
83
+ else {
84
+ // 集約オファーでなければ検証の必要なし
85
+ }
86
+ }
87
+ }
88
+ else {
89
+ // 関連注文の指定がなければ検証の必要なし
90
+ }
91
+ });
92
+ }
@@ -10,6 +10,7 @@ import type { ActionRepo } from '../../repo/action';
10
10
  import type { AssetTransactionRepo } from '../../repo/assetTransaction';
11
11
  import type { CredentialsRepo } from '../../repo/credentials';
12
12
  import type { EventRepo } from '../../repo/event';
13
+ import type { EventSeriesRepo } from '../../repo/eventSeries';
13
14
  import type { OrderRepo } from '../../repo/order';
14
15
  import type { PaymentServiceRepo } from '../../repo/paymentService';
15
16
  import type { PaymentServiceProviderRepo } from '../../repo/paymentServiceProvider';
@@ -24,6 +25,7 @@ export interface IStartOperationRepos {
24
25
  action: ActionRepo;
25
26
  credentials: CredentialsRepo;
26
27
  event: EventRepo;
28
+ eventSeries: EventSeriesRepo;
27
29
  paymentAccepted: SellerPaymentAcceptedRepo;
28
30
  paymentService: PaymentServiceRepo;
29
31
  paymentServiceProvider: PaymentServiceProviderRepo;
@@ -61,6 +63,8 @@ export type ICheckOperation<T> = (repos: {
61
63
  }, settings: Settings) => Promise<T>;
62
64
  export type IPublishPaymentUrlOperation<T> = (repos: {
63
65
  action: ActionRepo;
66
+ event: EventRepo;
67
+ eventSeries: EventSeriesRepo;
64
68
  paymentAccepted: SellerPaymentAcceptedRepo;
65
69
  paymentService: PaymentServiceRepo;
66
70
  paymentServiceProvider: PaymentServiceProviderRepo;
@@ -78,6 +82,7 @@ export declare function publishPaymentUrl(params: Pick<factory.assetTransaction.
78
82
  * add identifier for an unique index(2025-02-25~)
79
83
  */
80
84
  identifier?: string;
85
+ instrument: factory.action.accept.pay.IInstrument[];
81
86
  }, options: {
82
87
  purposeAsTransaction: {
83
88
  id: string;
@@ -104,7 +109,7 @@ export import IPaymentAgencyTransaction = CreditCardPayment.IPaymentAgencyTransa
104
109
  * 取引開始
105
110
  */
106
111
  export declare function start(params: factory.assetTransaction.pay.IStartParamsWithoutDetail & {
107
- instrument: factory.action.trade.pay.IInstrument[];
112
+ instrument: factory.action.trade.pay.IPlaceOrderRelatedInstrument[];
108
113
  }, options: {
109
114
  pendingPaymentAgencyTransaction?: CreditCardPayment.IPaymentAgencyTransaction;
110
115
  /**
@@ -24,6 +24,7 @@ const PaymentCardPayment = require("../payment/paymentCard");
24
24
  const fixInformAction_1 = require("./fixInformAction");
25
25
  const validation_1 = require("./pay/account/validation");
26
26
  const factory_1 = require("./pay/factory");
27
+ const validateAcceptedPaymentMethodIfNeeded_1 = require("./pay/validateAcceptedPaymentMethodIfNeeded");
27
28
  function publishPaymentUrlResult2recipe(params) {
28
29
  const { project, result } = params;
29
30
  return {
@@ -76,6 +77,8 @@ function publishPaymentUrl(params, options) {
76
77
  throw new factory.errors.ArgumentNull('transactionNumber');
77
78
  }
78
79
  yield validateSeller(params)(repos);
80
+ // リソースの対応決済方法検証(2025-12-02~)
81
+ yield (0, validateAcceptedPaymentMethodIfNeeded_1.validateAcceptedPaymentMethodIfNeeded)(params)(repos);
79
82
  // 決済サービス確認
80
83
  const paymentServiceId = getPaymentServiceId(params);
81
84
  // 決済受入アクション生成(2024-03-28~)
@@ -84,7 +87,7 @@ function publishPaymentUrl(params, options) {
84
87
  object: params.object,
85
88
  transactionNumber,
86
89
  typeOf: params.typeOf
87
- }, purpose: { typeOf: factory.transactionType.PlaceOrder, id: options.purposeAsTransaction.id } }, (typeof taskId === 'string')
90
+ }, purpose: { typeOf: factory.transactionType.PlaceOrder, id: options.purposeAsTransaction.id }, instrument: (Array.isArray(params.instrument)) ? params.instrument : [] }, (typeof taskId === 'string')
88
91
  ? { sameAs: { id: taskId, typeOf: 'Task' } } // タスク関連付け(2024-05-22~)
89
92
  : undefined), (typeof ((_d = params.location) === null || _d === void 0 ? void 0 : _d.typeOf) === 'string')
90
93
  ? { location: params.location }
@@ -186,6 +189,8 @@ function start(params, options) {
186
189
  throw new factory.errors.ArgumentNull('transactionNumber');
187
190
  }
188
191
  yield validateSeller(params)(repos);
192
+ // リソースの対応決済方法検証(2025-12-02~)
193
+ yield (0, validateAcceptedPaymentMethodIfNeeded_1.validateAcceptedPaymentMethodIfNeeded)(params)(repos);
189
194
  // 決済サービス確認
190
195
  const paymentServiceType = (_b = params.object) === null || _b === void 0 ? void 0 : _b.typeOf;
191
196
  const paymentService = yield fixPaymentService(params)(repos);
@@ -2,10 +2,12 @@ import * as factory from '../../../factory';
2
2
  import { Settings } from '../../../settings';
3
3
  import type { AdvanceBookingRequirementRepo } from '../../../repo/advanceBookingRequirement';
4
4
  import type { AssetTransactionRepo } from '../../../repo/assetTransaction';
5
+ import type { AuthorizationRepo } from '../../../repo/authorization';
5
6
  import type { EventRepo } from '../../../repo/event';
6
7
  import type { EventOfferRepo } from '../../../repo/eventOffer';
7
8
  import type { EventSeriesRepo } from '../../../repo/eventSeries';
8
9
  import type { IssuerRepo } from '../../../repo/issuer';
10
+ import type { MemberRepo } from '../../../repo/member';
9
11
  import type { MemberProgramRepo } from '../../../repo/memberProgram';
10
12
  import type { OfferRepo } from '../../../repo/offer/unitPriceInCatalog';
11
13
  import type { OfferCatalogRepo } from '../../../repo/offerCatalog';
@@ -20,13 +22,16 @@ import type { OfferRateLimitRepo } from '../../../repo/rateLimit/offer';
20
22
  import type { SettingRepo } from '../../../repo/setting';
21
23
  import type { StockHolderRepo } from '../../../repo/stockHolder';
22
24
  import type { TaskRepo } from '../../../repo/task';
25
+ import type { TicketRepo } from '../../../repo/ticket';
23
26
  interface IStartOperationRepos {
24
27
  advanceBookingRequirement: AdvanceBookingRequirementRepo;
28
+ authorization: AuthorizationRepo;
25
29
  stockHolder: StockHolderRepo;
26
30
  event: EventRepo;
27
31
  eventOffer: EventOfferRepo;
28
32
  eventSeries: EventSeriesRepo;
29
33
  issuer: IssuerRepo;
34
+ member: MemberRepo;
30
35
  memberProgram: MemberProgramRepo;
31
36
  offer: OfferRepo;
32
37
  offerCatalog: OfferCatalogRepo;
@@ -40,6 +45,7 @@ interface IStartOperationRepos {
40
45
  seat: SeatRepo;
41
46
  setting: SettingRepo;
42
47
  task: TaskRepo;
48
+ ticket: TicketRepo;
43
49
  assetTransaction: AssetTransactionRepo;
44
50
  }
45
51
  type IStartOperation<T> = (repos: IStartOperationRepos, settings: Settings) => Promise<T>;
@@ -41,16 +41,20 @@ function start(params, options) {
41
41
  // validationを承認アクション開始前から移行(2023-01-27~)
42
42
  yield (0, validateStartRequest_1.validateStartRequest)({
43
43
  object: params.object,
44
+ instrument: params.instrument,
44
45
  event,
45
46
  validateEventOfferPeriod: params.validateEventOfferPeriod,
46
47
  validateEvent: params.validateEvent,
47
48
  now,
48
49
  store: { id: (_a = params.availableAtOrFrom) === null || _a === void 0 ? void 0 : _a.id }
49
50
  })({
51
+ authorization: repos.authorization,
50
52
  eventOffer: repos.eventOffer,
51
53
  issuer: repos.issuer,
54
+ member: repos.member,
52
55
  memberProgram: repos.memberProgram,
53
- productOffer: repos.productOffer
56
+ productOffer: repos.productOffer,
57
+ ticket: repos.ticket
54
58
  });
55
59
  // objectに必要な情報をそろえる
56
60
  const { acceptedOffers4transactionObject, objectSubReservations } = yield createObjectAttributes({
@@ -0,0 +1,22 @@
1
+ import * as factory from '../../../../factory';
2
+ import { IMinimizedIndividualEvent } from '../../../../factory/event';
3
+ import type { EventOfferRepo } from '../../../../repo/eventOffer';
4
+ import type { MemberRepo } from '../../../../repo/member';
5
+ /**
6
+ * リクエストから拡張イベントオファーを決定する
7
+ */
8
+ declare function fixExtendedEventOffer(params: {
9
+ event: Pick<IMinimizedIndividualEvent, 'offers' | 'id' | 'project' | 'identifier'>;
10
+ now: Date;
11
+ availableAt: {
12
+ /**
13
+ * 販売アプリケーションID
14
+ */
15
+ id: string;
16
+ };
17
+ acceptedEventOffer?: factory.authorization.IOfferAsObject;
18
+ }): (repos: {
19
+ eventOffer: EventOfferRepo;
20
+ member: MemberRepo;
21
+ }) => Promise<Pick<factory.eventOffer.IEventOffer, "identifier" | "itemOffered" | "typeOf" | "offeredBy" | "validFrom" | "validThrough" | "id">>;
22
+ export { fixExtendedEventOffer };
@@ -0,0 +1,63 @@
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
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.fixExtendedEventOffer = fixExtendedEventOffer;
13
+ const moment = require("moment");
14
+ const factory = require("../../../../factory");
15
+ /**
16
+ * リクエストから拡張イベントオファーを決定する
17
+ */
18
+ function fixExtendedEventOffer(params) {
19
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
20
+ var _a;
21
+ const { event, availableAt } = params;
22
+ const acceptedDate = moment(params.now);
23
+ // リクエストによるオファーコード指定が必須
24
+ const eventOfferIdMustBe = (_a = params.acceptedEventOffer) === null || _a === void 0 ? void 0 : _a.id;
25
+ if (typeof eventOfferIdMustBe !== 'string' || eventOfferIdMustBe === '') {
26
+ throw new factory.errors.ArgumentNull('ticket as instrument');
27
+ }
28
+ // アプリケーションIDからアプリケーションコードを参照
29
+ const existingCustomerMember = (yield repos.member.searchCustomerMembers({
30
+ project: { id: event.project.id },
31
+ limit: 1,
32
+ page: 1,
33
+ member: {
34
+ id: { $eq: availableAt.id }
35
+ }
36
+ })).shift();
37
+ if (existingCustomerMember === undefined) {
38
+ throw new factory.errors.NotFound(`Member: ${availableAt.id}`);
39
+ }
40
+ // tslint:disable-next-line:no-console
41
+ console.log('existingCustomerMember found:', JSON.stringify(existingCustomerMember));
42
+ const applicationIdentifier = existingCustomerMember.member.identifier;
43
+ if (typeof applicationIdentifier !== 'string') {
44
+ throw new factory.errors.NotFound(`member.identifier of ${availableAt.id}`);
45
+ }
46
+ // アプリケーションコードで利用可能な拡張オファーを検索
47
+ const existingEventOffer = (yield repos.eventOffer.findEventOffers({
48
+ limit: 1,
49
+ page: 1,
50
+ project: { id: { $eq: event.project.id } }, // プロジェクト
51
+ validFrom: { $lte: acceptedDate.toDate() },
52
+ validThrough: { $gte: acceptedDate.toDate() },
53
+ itemOffered: { id: { $eq: event.id } }, // 対象イベント
54
+ id: { $eq: eventOfferIdMustBe }, // オファーID
55
+ // identifier: { $eq: eventOfferIdentifierMustBe }, // オファーコード
56
+ availableAtOrFrom: { identifier: { $eq: applicationIdentifier } } // アプリケーションコード
57
+ }, ['identifier', 'itemOffered', 'offeredBy', 'typeOf', 'validFrom', 'validThrough'])).shift();
58
+ if (existingEventOffer === undefined) {
59
+ throw new factory.errors.NotFound(`valid eventOffer: ${eventOfferIdMustBe}`);
60
+ }
61
+ return existingEventOffer;
62
+ });
63
+ }
@@ -7,8 +7,13 @@ import type { IssuerRepo } from '../../../../repo/issuer';
7
7
  declare function validateIssuedOfferIfExists(params: {
8
8
  event: Pick<IMinimizedIndividualEvent, 'offers' | 'id' | 'project' | 'identifier'>;
9
9
  now: Date;
10
- object: factory.assetTransaction.reserve.IObjectWithoutDetail;
11
- eventOffer: Pick<factory.eventOffer.IEventOffer, 'identifier' | 'itemOffered' | 'offeredBy' | 'validFrom' | 'validThrough'>;
10
+ eventOffer: Pick<factory.eventOffer.IEventOffer, 'identifier' | 'itemOffered' | 'offeredBy' | 'validFrom' | 'validThrough' | 'id'>;
11
+ acceptedEventOffer?: factory.authorization.IOfferAsObject;
12
+ /**
13
+ * オファー承認時の予約数
14
+ * 0であれば特に何も検証されない
15
+ */
16
+ numAcceptedOffers: number;
12
17
  }): (repos: {
13
18
  issuer: IssuerRepo;
14
19
  }) => Promise<void>;
@@ -37,10 +37,10 @@ function verifyOfferToken(params) {
37
37
  catch (error) {
38
38
  // JWTエラーをハンドリング
39
39
  if (error instanceof jwt.TokenExpiredError) {
40
- throw new factory.errors.Argument('reservationFor.offers.token', `invalid token. [${error.message} expiredAt:${error.expiredAt}]`);
40
+ throw new factory.errors.Argument('ticketedOffer.token', `invalid token. [${error.message} expiredAt:${error.expiredAt}]`);
41
41
  }
42
42
  else if (error instanceof jwt.JsonWebTokenError) {
43
- throw new factory.errors.Argument('reservationFor.offers.token', `invalid token. [${error.message}]`);
43
+ throw new factory.errors.Argument('ticketedOffer.token', `invalid token. [${error.message}]`);
44
44
  }
45
45
  throw error;
46
46
  }
@@ -51,30 +51,30 @@ const OFFER_TOKEN_DATE_FORMAT = 'YYYY-MM-DDTHH:mm:ssZ';
51
51
  function validateOfferToken(params) {
52
52
  return () => __awaiter(this, void 0, void 0, function* () {
53
53
  var _a, _b;
54
- const { event, acceptedDate, verifiedOffer, eventOffer } = params;
55
- // イベント識別子一致検証
56
- const itemOfferedIdentifier = verifiedOffer.itemOffered.identifier;
57
- if (typeof itemOfferedIdentifier !== 'string' || itemOfferedIdentifier === '') {
58
- throw new factory.errors.Argument('reservationFor.offers.token', 'itemOffered.identifier must be string');
54
+ const { event, acceptedDate, verifiedOffer, eventOffer, numAcceptedOffers } = params;
55
+ // イベントID一致検証
56
+ const itemOfferedId = (_a = verifiedOffer.itemOffered) === null || _a === void 0 ? void 0 : _a.id;
57
+ if (typeof itemOfferedId !== 'string' || itemOfferedId === '') {
58
+ throw new factory.errors.Argument('ticketedOffer.token', 'itemOffered.id must be string');
59
59
  }
60
- const itemOfferedIdentifierMustBe = event.identifier;
61
- if (typeof itemOfferedIdentifierMustBe !== 'string') {
62
- throw new factory.errors.NotFound('identifier', 'the event must have an identifier');
60
+ const itemOfferedIdMustBe = event.id;
61
+ if (typeof itemOfferedIdMustBe !== 'string') {
62
+ throw new factory.errors.NotFound('event.id', 'the event must have an ID');
63
63
  }
64
- if (itemOfferedIdentifier !== itemOfferedIdentifierMustBe) {
65
- throw new factory.errors.Argument('reservationFor.offers.token', 'itemOffered.identifier not matched');
64
+ if (itemOfferedId !== itemOfferedIdMustBe) {
65
+ throw new factory.errors.Argument('ticketedOffer.token', 'itemOffered.id not matched');
66
66
  }
67
- // アプリケーションオファーコード一致検証
67
+ // オファーコード一致検証
68
68
  const applicationOfferIdentifier = verifiedOffer.identifier;
69
69
  if (typeof applicationOfferIdentifier !== 'string' || applicationOfferIdentifier === '') {
70
- throw new factory.errors.Argument('reservationFor.offers.token', 'identifier must be string');
70
+ throw new factory.errors.Argument('ticketedOffer.token', 'identifier must be string');
71
71
  }
72
72
  const applicationOfferIdentifierMustBe = eventOffer.identifier;
73
73
  if (typeof applicationOfferIdentifierMustBe !== 'string') {
74
74
  throw new factory.errors.NotFound('makesOffer.identifier');
75
75
  }
76
76
  if (applicationOfferIdentifier !== applicationOfferIdentifierMustBe) {
77
- throw new factory.errors.Argument('reservationFor.offers.token', 'identifier not matched');
77
+ throw new factory.errors.Argument('ticketedOffer.token', 'identifier not matched');
78
78
  }
79
79
  // 有効期間検証
80
80
  let validThroughMoment;
@@ -82,26 +82,26 @@ function validateOfferToken(params) {
82
82
  validThroughMoment = moment(verifiedOffer.validThrough, OFFER_TOKEN_DATE_FORMAT, true);
83
83
  validFromMoment = moment(verifiedOffer.validFrom, OFFER_TOKEN_DATE_FORMAT, true);
84
84
  if (!validThroughMoment.isValid()) {
85
- throw new factory.errors.Argument('reservationFor.offers.token', 'invalid validThrough');
85
+ throw new factory.errors.Argument('ticketedOffer.token', 'invalid validThrough');
86
86
  }
87
87
  if (!validFromMoment.isValid()) {
88
- throw new factory.errors.Argument('reservationFor.offers.token', 'invalid validFrom');
88
+ throw new factory.errors.Argument('ticketedOffer.token', 'invalid validFrom');
89
89
  }
90
90
  if (acceptedDate.isBefore(validFromMoment)) {
91
- throw new factory.errors.Argument('reservationFor.offers.token', `the offer id valid from ${validFromMoment}`);
91
+ throw new factory.errors.Argument('ticketedOffer.token', `the offer id valid from ${validFromMoment}`);
92
92
  }
93
93
  if (acceptedDate.isAfter(validThroughMoment)) {
94
- throw new factory.errors.Argument('reservationFor.offers.token', `the offer id valid through ${validThroughMoment}`);
94
+ throw new factory.errors.Argument('ticketedOffer.token', `the offer id valid through ${validThroughMoment}`);
95
95
  }
96
96
  // maxValueを検証
97
- const maxValue = (_a = verifiedOffer === null || verifiedOffer === void 0 ? void 0 : verifiedOffer.eligibleQuantity) === null || _a === void 0 ? void 0 : _a.maxValue;
97
+ const maxValue = (_b = verifiedOffer === null || verifiedOffer === void 0 ? void 0 : verifiedOffer.eligibleQuantity) === null || _b === void 0 ? void 0 : _b.maxValue;
98
98
  if (typeof maxValue !== 'number') {
99
- throw new factory.errors.Argument('reservationFor.offers.token', 'eligibleQuantity.maxValue must be number');
99
+ throw new factory.errors.Argument('ticketedOffer.token', 'eligibleQuantity.maxValue must be number');
100
100
  }
101
101
  if (maxValue > NUM_ACCEPTED_OFFERS_MAX_VALUE) {
102
- throw new factory.errors.Argument('reservationFor.offers.token', `eligibleQuantity.maxValue must be <= ${NUM_ACCEPTED_OFFERS_MAX_VALUE}`);
102
+ throw new factory.errors.Argument('ticketedOffer.token', `eligibleQuantity.maxValue must be <= ${NUM_ACCEPTED_OFFERS_MAX_VALUE}`);
103
103
  }
104
- const numAcceptedOffers = (_b = params.object.acceptedOffer) === null || _b === void 0 ? void 0 : _b.length;
104
+ // const numAcceptedOffers = params.object.acceptedOffer?.length;
105
105
  if (typeof numAcceptedOffers === 'number' && numAcceptedOffers > 0) {
106
106
  if (numAcceptedOffers > maxValue) {
107
107
  throw new factory.errors.Argument('reservationFor.id', `Maximum number of offers exceeded`);
@@ -114,16 +114,16 @@ function validateOfferToken(params) {
114
114
  */
115
115
  function validateIssuedOfferIfExists(params) {
116
116
  return (repos) => __awaiter(this, void 0, void 0, function* () {
117
- var _a, _b, _c, _d, _e;
118
- const { event, eventOffer } = params;
117
+ var _a, _b, _c;
118
+ const { event, eventOffer, numAcceptedOffers } = params;
119
119
  const acceptedDate = moment(params.now);
120
120
  const offerTokenIssuer = (_a = eventOffer.offeredBy) === null || _a === void 0 ? void 0 : _a.identifier;
121
121
  const offerTokenRequired = typeof offerTokenIssuer === 'string';
122
122
  if (offerTokenRequired) {
123
- const offerIdentifierMustBe = (_c = (_b = params.object.reservationFor) === null || _b === void 0 ? void 0 : _b.offers) === null || _c === void 0 ? void 0 : _c.identifier;
124
- const offerToken = (_e = (_d = params.object.reservationFor) === null || _d === void 0 ? void 0 : _d.offers) === null || _e === void 0 ? void 0 : _e.token;
125
- if (typeof offerIdentifierMustBe !== 'string' || offerIdentifierMustBe === '') {
126
- throw new factory.errors.ArgumentNull('object.reservationFor.offers.identifier');
123
+ const offerIdMustBe = (_b = params.acceptedEventOffer) === null || _b === void 0 ? void 0 : _b.id;
124
+ const offerToken = (_c = params.acceptedEventOffer) === null || _c === void 0 ? void 0 : _c.token;
125
+ if (typeof offerIdMustBe !== 'string' || offerIdMustBe === '') {
126
+ throw new factory.errors.NotFound('ticketedOffer.id');
127
127
  }
128
128
  if (typeof offerToken !== 'string' || offerToken === '') {
129
129
  throw new factory.errors.ArgumentNull('object.reservationFor.offers.token');
@@ -131,8 +131,8 @@ function validateIssuedOfferIfExists(params) {
131
131
  if (typeof eventOffer.identifier !== 'string' || eventOffer.identifier === '') {
132
132
  throw new factory.errors.NotFound('eventOffer.identifier');
133
133
  }
134
- // アプリケーションオファーコード一致検証
135
- if (eventOffer.identifier !== offerIdentifierMustBe) {
134
+ // イベントオファーID一致検証
135
+ if (eventOffer.id !== offerIdMustBe) {
136
136
  throw new factory.errors.Argument('object.reservationFor.offers.identifier', 'eventOffer.identifier not matched');
137
137
  }
138
138
  const issuer = yield repos.issuer.findByIdentifier({
@@ -152,7 +152,7 @@ function validateIssuedOfferIfExists(params) {
152
152
  acceptedDate,
153
153
  verifiedOffer,
154
154
  eventOffer,
155
- object: params.object
155
+ numAcceptedOffers
156
156
  })();
157
157
  }
158
158
  });
@@ -6,8 +6,8 @@ import type { ProductOfferRepo } from '../../../../repo/productOffer';
6
6
  declare function validateMemberTierIfExists(params: {
7
7
  event: Pick<IMinimizedIndividualEvent, 'offers' | 'id' | 'project'>;
8
8
  now: Date;
9
- object: factory.assetTransaction.reserve.IObjectWithoutDetail;
10
9
  makesOfferOnApplication: factory.event.screeningEvent.ISellerMakesOffer;
10
+ acceptedEventOffer?: factory.authorization.IOfferAsObject;
11
11
  }): (repos: {
12
12
  issuer: IssuerRepo;
13
13
  memberProgram: MemberProgramRepo;