@chevre/domain 25.2.0-alpha.6 → 25.2.0-alpha.7

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.
@@ -5,6 +5,11 @@ type IOrderAcceptedOffer = Pick<factory.order.IAcceptedOffer, 'itemOffered' | 'o
5
5
  export declare function createAuthorizeOfferResultsExpected(params: {
6
6
  authorizeEventServiceOfferActions: Pick<IAuthorizeEventServiceOffer, 'id' | 'result'>[];
7
7
  }): Pick<IAuthorizeEventServiceOffer, 'id' | 'result'>[];
8
+ /**
9
+ * 注文ドキュメントと予約取引ドキュメントを参照することによって生成した、単価オファー検証条件
10
+ * 元々オファー承認アクションのresultに保管されていた
11
+ */
12
+ type IPreparedUnitPriceOfferConditions = Pick<IAuthorizeEventServiceOffer, 'id' | 'result'>;
8
13
  declare function prepareUnitPriceOfferConditions(params: {
9
14
  project: {
10
15
  id: string;
@@ -13,5 +18,5 @@ declare function prepareUnitPriceOfferConditions(params: {
13
18
  authorizeEventServiceOfferActions: IAuthorizeEventServiceOffer[];
14
19
  }): (repos: {
15
20
  offer: OfferRepo;
16
- }) => Promise<Pick<IAuthorizeEventServiceOffer, "id" | "result">[]>;
17
- export { prepareUnitPriceOfferConditions };
21
+ }) => Promise<IPreparedUnitPriceOfferConditions[]>;
22
+ export { IPreparedUnitPriceOfferConditions, prepareUnitPriceOfferConditions };
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createAuthorizeOfferResultsExpected = createAuthorizeOfferResultsExpected;
4
4
  exports.prepareUnitPriceOfferConditions = prepareUnitPriceOfferConditions;
5
- const util_1 = require("util");
6
5
  const factory_1 = require("../../../../factory");
7
6
  function acceptedOffers2authorizeResult(params) {
8
7
  const { acceptedOffers4result, unitPriceOffers } = params;
@@ -102,15 +101,6 @@ function prepareUnitPriceOfferConditions(params) {
102
101
  }
103
102
  });
104
103
  }
105
- // 承認アクションと比較する
106
- for (const authorizeEventServiceOfferAction of params.authorizeEventServiceOfferActions) {
107
- const conditionExpected = conditions.find(({ id }) => id === authorizeEventServiceOfferAction.id);
108
- const resultMatched = (0, util_1.isDeepStrictEqual)(conditionExpected?.result, authorizeEventServiceOfferAction.result);
109
- console.log('resultMatched?', resultMatched, params.project.id, authorizeEventServiceOfferAction.id, authorizeEventServiceOfferAction.instrument.transactionNumber);
110
- if (!resultMatched) {
111
- console.log('conditionExpected not matched!', params.project.id, authorizeEventServiceOfferAction.id, conditionExpected?.result, authorizeEventServiceOfferAction.result);
112
- }
113
- }
114
104
  return conditions;
115
105
  };
116
106
  }
@@ -1,5 +1,6 @@
1
1
  import { factory } from '../../../../factory';
2
2
  import { PlaceOrderFactory } from '../../../../factory/transaction';
3
+ import { IPreparedUnitPriceOfferConditions } from './prepareUnitPriceOfferConditions';
3
4
  import { IAcceptPayAction, IAuthorizeEventServiceOffer, IAuthorizePaymentAction, IPayTransaction } from './validation/factory';
4
5
  export { IAcceptPayAction, IAuthorizeEventServiceOffer, IAuthorizePaymentAction, IPayTransaction };
5
6
  /**
@@ -35,6 +36,9 @@ export declare function validatePaymentMethods(params: {
35
36
  * 興行オファー適用条件確認
36
37
  */
37
38
  export declare function validateEventOffers(params: {
39
+ project: {
40
+ id: string;
41
+ };
38
42
  order: {
39
43
  price: number;
40
44
  };
@@ -42,5 +46,6 @@ export declare function validateEventOffers(params: {
42
46
  /**
43
47
  * 承認アクションのresultに条件が保管されているはず(2026-07-06時点で)
44
48
  */
45
- authorizeEventServiceOfferActions: Pick<IAuthorizeEventServiceOffer, 'id' | 'result'>[];
49
+ authorizeOfferActions: Pick<IAuthorizeEventServiceOffer, 'id' | 'result'>[];
50
+ unitPriceOfferConditions?: IPreparedUnitPriceOfferConditions[];
46
51
  }): void;
@@ -17,13 +17,11 @@ const factory_1 = require("../../../../factory");
17
17
  const validateInvoiceReferencesOrder_1 = require("./validation/validateInvoiceReferencesOrder");
18
18
  const validateMovieTicket_1 = require("./validation/validateMovieTicket");
19
19
  const validatePrice_1 = require("./validation/validatePrice");
20
- const debug = (0, debug_1.default)('chevre-domain:service:transaction');
20
+ const debug = (0, debug_1.default)('chevre-domain:service:transaction:placeOrder:confirm:validation');
21
21
  /**
22
22
  * 取引が確定可能な状態かどうかをチェックする
23
23
  */
24
- function validateTransaction(transaction, acceptPayActions, authorizePaymentActions, authorizeEventServiceOfferActions,
25
- // authorizeProductOfferActions: Pick<IAuthorizeProductOffer, 'id' | 'result'>[],
26
- eventReservationAcceptedOffers, payTransactions, customer) {
24
+ function validateTransaction(transaction, acceptPayActions, authorizePaymentActions, authorizeEventServiceOfferActions, eventReservationAcceptedOffers, payTransactions, customer) {
27
25
  // validateProfile(transaction);
28
26
  validateProfile({ customer });
29
27
  (0, validatePrice_1.validatePrice)(authorizePaymentActions, authorizeEventServiceOfferActions);
@@ -33,7 +31,6 @@ eventReservationAcceptedOffers, payTransactions, customer) {
33
31
  // validateMonetaryAmount(authorizePaymentActions, authorizeEventServiceOfferActions); // discontinue(2026-07-06~)
34
32
  // 利用可能なMovieTicketIF決済方法タイプに対して動的にコーディング
35
33
  const movieTicketPaymentMethodTypes = findMovieTicketPaymentMethodTypesFromTransaction(authorizePaymentActions, eventReservationAcceptedOffers);
36
- debug('processing validateMovieTicket... movieTicketPaymentMethodTypes:', movieTicketPaymentMethodTypes);
37
34
  if (Array.isArray(movieTicketPaymentMethodTypes) && movieTicketPaymentMethodTypes.length > 0) {
38
35
  movieTicketPaymentMethodTypes.forEach((paymentMethodType) => {
39
36
  const authorizeMovieTicketActions = authorizePaymentActions.filter((a) => {
@@ -59,7 +56,6 @@ eventReservationAcceptedOffers, payTransactions, customer) {
59
56
  authorizedMovieTickets.push(...object.paymentMethod.movieTickets);
60
57
  }
61
58
  });
62
- debug(authorizedMovieTickets.length, 'movie tickets authorized', 'transaction:', transaction.id);
63
59
  // validateMovieTicket(paymentMethodType, { id: transaction.id }, authorizePaymentActions, eventReservationAcceptedOffers);
64
60
  (0, validateMovieTicket_1.validateMovieTicket)(paymentMethodType, { id: transaction.id }, authorizedMovieTickets, eventReservationAcceptedOffers);
65
61
  });
@@ -95,18 +91,6 @@ function findMovieTicketPaymentMethodTypesFromTransaction(authorizePaymentAction
95
91
  // ];
96
92
  return [...new Set(paymentMethodTypes)];
97
93
  }
98
- // function validateProfile(transaction: Pick<factory.transaction.placeOrder.ITransaction, 'object'>) {
99
- // // object.customerで検証(2022-05-26~)
100
- // const profile = transaction.object.customer;
101
- // const profileSatisfied = typeof profile?.typeOf === 'string' && profile.typeOf.length > 0
102
- // && typeof profile.email === 'string' && profile.email.length > 0
103
- // && typeof profile.familyName === 'string' && profile.familyName.length > 0
104
- // && typeof profile.givenName === 'string' && profile.givenName.length > 0
105
- // && typeof profile.telephone === 'string' && profile.telephone.length > 0;
106
- // if (!profileSatisfied) {
107
- // throw new factory.errors.Argument('Transaction', 'Customer Profile Required');
108
- // }
109
- // }
110
94
  function validateProfile(params) {
111
95
  const profile = params.customer;
112
96
  const profileSatisfied = typeof profile?.typeOf === 'string' && profile.typeOf.length > 0
@@ -257,7 +241,6 @@ function validateAcceptedOffers(params) {
257
241
  });
258
242
  if (ticketIdentifiers.length > 0) {
259
243
  ticketIdentifiers = [...new Set(ticketIdentifiers)];
260
- debug('ticketIdentifiers unique?', ticketIdentifiers.join(' '), 'numAcceptedOffers:', numAcceptedOffers);
261
244
  // チケット識別子が注文内ユニークなので、注文オファー数に一致するはず
262
245
  if (ticketIdentifiers.length !== numAcceptedOffers) {
263
246
  throw new factory_1.factory.errors.Argument('Transaction', 'ticketIdentifiers must be unique');
@@ -274,7 +257,6 @@ function validateAcceptedOffers(params) {
274
257
  });
275
258
  if (ticketNumbers.length > 0) {
276
259
  ticketNumbers = [...new Set(ticketNumbers)];
277
- debug('ticketNumbers unique?', ticketNumbers.join(' '), 'numAcceptedOffers:', numAcceptedOffers);
278
260
  // チケット識別子が注文内ユニークなので、注文オファー数に一致するはず
279
261
  if (ticketNumbers.length !== numAcceptedOffers) {
280
262
  throw new factory_1.factory.errors.Argument('Transaction', 'ticketNumbers must be unique');
@@ -313,6 +295,34 @@ function validatePaymentMethods(params, options) {
313
295
  * 興行オファー適用条件確認
314
296
  */
315
297
  function validateEventOffers(params) {
298
+ const { unitPriceOfferConditions } = params;
299
+ /**
300
+ * 以下処理で検証に使用するアクション結果リスト
301
+ */
302
+ let validatingAuthorizeOfferActions;
303
+ // 承認アクションと比較する
304
+ if (Array.isArray(unitPriceOfferConditions)) {
305
+ const everyActionsMatched = unitPriceOfferConditions.length === params.authorizeOfferActions.length
306
+ && params.authorizeOfferActions.every((authorizeEventServiceOfferAction) => {
307
+ const conditionExpected = unitPriceOfferConditions.find(({ id }) => id === authorizeEventServiceOfferAction.id);
308
+ const resultMatched = (0, util_1.isDeepStrictEqual)(conditionExpected?.result, authorizeEventServiceOfferAction.result);
309
+ debug('validateEventOffers: unitPriceOfferConditions: resultMatched?', resultMatched, params.project.id, authorizeEventServiceOfferAction.id);
310
+ if (!resultMatched) {
311
+ console.error('validateEventOffers: unitPriceOfferConditions not matched!', params.project.id, authorizeEventServiceOfferAction.id, conditionExpected?.result, authorizeEventServiceOfferAction.result);
312
+ }
313
+ return resultMatched;
314
+ });
315
+ // 全アクションについて結果が一致していればunitPriceOfferConditionsを採用する(2026-07-07~)
316
+ if (everyActionsMatched) {
317
+ validatingAuthorizeOfferActions = [...unitPriceOfferConditions];
318
+ }
319
+ else {
320
+ validatingAuthorizeOfferActions = [...params.authorizeOfferActions];
321
+ }
322
+ }
323
+ else {
324
+ validatingAuthorizeOfferActions = [...params.authorizeOfferActions];
325
+ }
316
326
  const { paymentMethods } = params;
317
327
  const firstCreditCardPaymentMethodIdentifier = paymentMethods.find((referenceInvoice) => {
318
328
  return referenceInvoice.issuedThrough.typeOf === factory_1.factory.service.paymentService.PaymentServiceType.CreditCard
@@ -322,7 +332,7 @@ function validateEventOffers(params) {
322
332
  return referenceInvoice.issuedThrough.typeOf === factory_1.factory.service.paymentService.PaymentServiceType.CreditCard
323
333
  || referenceInvoice.issuedThrough.typeOf === factory_1.factory.service.paymentService.PaymentServiceType.FaceToFace;
324
334
  }).length;
325
- params.authorizeEventServiceOfferActions.forEach((a) => {
335
+ validatingAuthorizeOfferActions.forEach((a) => {
326
336
  // support result.offers(2024-06-18~)
327
337
  const acceptedOffersInResult = a.result?.offers;
328
338
  if (Array.isArray(acceptedOffersInResult) && acceptedOffersInResult.length > 0) {
@@ -348,20 +358,18 @@ function validateEventOffers(params) {
348
358
  // }
349
359
  // 適用数量検証(全興行オファー承認アクションについて)(2023-11-15~)
350
360
  // 適用数量要件を満たしていなければエラー
351
- const numAcceptedOffersByOfferId = params.authorizeEventServiceOfferActions.reduce((previousNumOffer, { result }) => {
361
+ const numAcceptedOffersByOfferId = validatingAuthorizeOfferActions.reduce((previousNumOffer, { result }) => {
352
362
  const numOfferOnCurrentAction = result?.offers?.find(({ id }) => id === offerId)?.includesObject.amountOfThisGood;
353
363
  return previousNumOffer + ((typeof numOfferOnCurrentAction === 'number') ? numOfferOnCurrentAction : 0);
354
364
  }, 0);
355
365
  const eligibleQuantityMaxValue = unitPriceSpec?.eligibleQuantity?.maxValue;
356
366
  if (typeof eligibleQuantityMaxValue === 'number') {
357
- debug('validateEventOffers: numAcceptedOffersByOfferId > eligibleQuantityMaxValue?', numAcceptedOffersByOfferId, eligibleQuantityMaxValue);
358
367
  if (numAcceptedOffersByOfferId > eligibleQuantityMaxValue) {
359
368
  throw new factory_1.factory.errors.Argument('Transaction', `Number of offer:${offerId} must be less than or equal to ${eligibleQuantityMaxValue}`);
360
369
  }
361
370
  }
362
371
  const eligibleQuantityMinValue = unitPriceSpec?.eligibleQuantity?.minValue;
363
372
  if (typeof eligibleQuantityMinValue === 'number') {
364
- debug('validateEventOffers: numAcceptedOffersByOfferId < eligibleQuantityMinValue?', numAcceptedOffersByOfferId, eligibleQuantityMinValue);
365
373
  if (numAcceptedOffersByOfferId < eligibleQuantityMinValue) {
366
374
  throw new factory_1.factory.errors.Argument('Transaction', `Number of offer:${offerId} must be more than or equal to ${eligibleQuantityMinValue}`);
367
375
  }
@@ -372,7 +380,6 @@ function validateEventOffers(params) {
372
380
  const satisfyAcceptedPaymentMethod = numCreditCardOrFaceToFacePaymentMethod === 1
373
381
  && typeof firstCreditCardPaymentMethodIdentifier === 'string'
374
382
  && acceptedPaymentMethodTypes.includes(firstCreditCardPaymentMethodIdentifier);
375
- debug('validateEventOffers: satisfyAcceptedPaymentMethod?', JSON.stringify(acceptedPaymentMethodTypes));
376
383
  if (!satisfyAcceptedPaymentMethod) {
377
384
  throw new factory_1.factory.errors.Argument('Transaction', `acceptedPaymentMethod requirement not satisfied`);
378
385
  }
@@ -381,7 +388,7 @@ function validateEventOffers(params) {
381
388
  }
382
389
  });
383
390
  // check programMembershipUsed(2024-08-15~)
384
- const programMembershipRequired = params.authorizeEventServiceOfferActions.reduce((a, b) => {
391
+ const programMembershipRequired = validatingAuthorizeOfferActions.reduce((a, b) => {
385
392
  const programMembershipUsedfromResult = b.result?.itemOffered?.serviceOutput.programMembershipUsed;
386
393
  if (Array.isArray(programMembershipUsedfromResult)) {
387
394
  a.push(...programMembershipUsedfromResult);
@@ -116,9 +116,10 @@ function confirm(params, options) {
116
116
  }))
117
117
  .filter(({ serialNumber }) => typeof serialNumber === 'string' && serialNumbers.includes(serialNumber));
118
118
  // 単価オファーの全適用条件を検証するために、単価オファーを参照(2026-07-06~)
119
+ let unitPriceOfferConditions;
119
120
  const { usePrepareUnitPriceOfferConditions } = options;
120
121
  if (usePrepareUnitPriceOfferConditions === true) {
121
- await (0, prepareUnitPriceOfferConditions_1.prepareUnitPriceOfferConditions)({
122
+ unitPriceOfferConditions = await (0, prepareUnitPriceOfferConditions_1.prepareUnitPriceOfferConditions)({
122
123
  project: { id: transaction.project.id, },
123
124
  acceptedOffers,
124
125
  authorizeEventServiceOfferActions
@@ -144,22 +145,10 @@ function confirm(params, options) {
144
145
  orderNumber, transaction,
145
146
  acceptPayActions,
146
147
  authorizePaymentActions, authorizeEventServiceOfferActions,
147
- // authorizeProductOfferActions,
148
148
  acceptedOffers, payTransactions, customer,
149
- ...(typeof code === 'string') ? { code } : undefined
149
+ ...(typeof code === 'string') ? { code } : undefined,
150
+ ...((Array.isArray(unitPriceOfferConditions)) && { unitPriceOfferConditions })
150
151
  }, options);
151
- // discontinue emailMessageRepo
152
- // // デフォルトEメールメッセージを検索
153
- // let emailMessageOnOrderSent: factory.creativeWork.message.email.ICreativeWork | undefined;
154
- // if (repos.emailMessage !== undefined) {
155
- // const searchEmailMessagesResult = await repos.emailMessage.search({
156
- // limit: 1,
157
- // page: 1,
158
- // project: { id: { $eq: transaction.project.id } },
159
- // about: { identifier: { $eq: factory.creativeWork.message.email.AboutIdentifier.OnOrderSent } }
160
- // });
161
- // emailMessageOnOrderSent = searchEmailMessagesResult.shift();
162
- // }
163
152
  // ポストアクションを作成
164
153
  const setting = await repos.setting.findOne({ project: { id: { $eq: '*' } } }, ['defaultSenderEmail']);
165
154
  if (typeof setting?.defaultSenderEmail !== 'string') {
@@ -329,17 +318,17 @@ function createResult(params, options) {
329
318
  }
330
319
  });
331
320
  // 取引の確定条件が全て整っているかどうか確認
332
- (0, validation_1.validateTransaction)(transaction, params.acceptPayActions, params.authorizePaymentActions, params.authorizeEventServiceOfferActions,
333
- // params.authorizeProductOfferActions,
334
- eventReservationAcceptedOffers, params.payTransactions, params.customer);
321
+ (0, validation_1.validateTransaction)(transaction, params.acceptPayActions, params.authorizePaymentActions, params.authorizeEventServiceOfferActions, eventReservationAcceptedOffers, params.payTransactions, params.customer);
335
322
  const { paymentMethods, price } = (0, factory_2.createPaymentMethods)({ authorizePaymentActions: params.authorizePaymentActions });
336
323
  const orderedItem = (0, orderedItem_1.acceptedOffers2orderedItem)({
337
324
  eventReservationAcceptedOffers
338
325
  });
339
326
  (0, validation_1.validateEventOffers)({
327
+ project: { id: transaction.project.id },
340
328
  order: { price },
341
329
  paymentMethods,
342
- authorizeEventServiceOfferActions: params.authorizeEventServiceOfferActions
330
+ authorizeOfferActions: params.authorizeEventServiceOfferActions,
331
+ ...((Array.isArray(params.unitPriceOfferConditions)) && { unitPriceOfferConditions: params.unitPriceOfferConditions })
343
332
  });
344
333
  // 注文オファー検証
345
334
  (0, validation_1.validateAcceptedOffers)({
@@ -400,21 +389,6 @@ function createResult(params, options) {
400
389
  }
401
390
  function searchAcceptPayActions(params) {
402
391
  return async (repos) => {
403
- // let acceptPayActions = <IAcceptPayAction[]>await repos.action.search(
404
- // {
405
- // project: { id: { $eq: params.project.id } },
406
- // typeOf: { $eq: factory.actionType.AcceptAction },
407
- // actionStatus: { $in: [factory.actionStatusType.CompletedActionStatus] },
408
- // purpose: {
409
- // id: { $in: [params.id] },
410
- // typeOf: { $in: [factory.transactionType.PlaceOrder] }
411
- // },
412
- // object: {
413
- // typeOf: { $eq: factory.assetTransactionType.Pay }
414
- // }
415
- // },
416
- // ['object', 'endDate', 'result']
417
- // );
418
392
  let acceptPayActions = await repos.acceptPayAction.findAcceptActionsByPurpose({
419
393
  project: { id: params.project.id },
420
394
  actionStatus: factory_1.factory.actionStatusType.CompletedActionStatus,
@@ -433,15 +407,6 @@ function searchAcceptPayActions(params) {
433
407
  function searchAuthorizeActions(params) {
434
408
  return async (repos) => {
435
409
  // 取引に対する全ての承認アクションをマージ
436
- // let authorizeActions = <IAuthorizeOfferOrPaymentAction[]>await repos.action.searchByPurpose({
437
- // typeOf: factory.actionType.AuthorizeAction,
438
- // purpose: {
439
- // typeOf: factory.transactionType.PlaceOrder,
440
- // id: params.id
441
- // },
442
- // // Completedに絞る(2023-05-16~)
443
- // actionStatus: { $eq: factory.actionStatusType.CompletedActionStatus }
444
- // });
445
410
  let authorizeActions = [
446
411
  ...await repos.authorizePaymentMethodAction.findAuthorizePaymentMethodActionsByPurpose({
447
412
  purpose: {
package/package.json CHANGED
@@ -91,5 +91,5 @@
91
91
  "postversion": "git push origin --tags",
92
92
  "prepublishOnly": "npm run clean && npm run build"
93
93
  },
94
- "version": "25.2.0-alpha.6"
94
+ "version": "25.2.0-alpha.7"
95
95
  }