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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/example/src/chevre/assetTransaction/processReserve.ts +9 -3
  2. package/example/src/chevre/authorizeEventServiceOffer.ts +8 -5
  3. package/example/src/chevre/eventOffer/adminEventOffers.ts +67 -0
  4. package/example/src/chevre/member/migrateMemberIdentifier.ts +99 -0
  5. package/example/src/chevre/reIndex.ts +2 -2
  6. package/lib/chevre/repo/eventOffer.d.ts +52 -0
  7. package/lib/chevre/repo/eventOffer.js +191 -0
  8. package/lib/chevre/repo/member.d.ts +18 -1
  9. package/lib/chevre/repo/member.js +14 -8
  10. package/lib/chevre/repo/mongoose/schemas/eventOffer.d.ts +10 -0
  11. package/lib/chevre/repo/mongoose/schemas/eventOffer.js +102 -0
  12. package/lib/chevre/repo/mongoose/schemas/member.js +10 -0
  13. package/lib/chevre/repository.d.ts +5 -0
  14. package/lib/chevre/repository.js +15 -2
  15. package/lib/chevre/service/assetTransaction/reserve/start.d.ts +8 -0
  16. package/lib/chevre/service/assetTransaction/reserve/start.js +6 -1
  17. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/fixExtendedEventOffer.d.ts +23 -0
  18. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/fixExtendedEventOffer.js +62 -0
  19. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/validateIssuedOfferIfExists.d.ts +2 -1
  20. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/validateIssuedOfferIfExists.js +24 -24
  21. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/validateMemberTierIfExists.d.ts +1 -0
  22. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/validateMemberTierIfExists.js +10 -26
  23. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/verifyTicketTokenAsNeeded.d.ts +23 -0
  24. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/verifyTicketTokenAsNeeded.js +62 -0
  25. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest.d.ts +9 -0
  26. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest.js +36 -16
  27. package/lib/chevre/service/offer/event/authorize/factory.d.ts +0 -3
  28. package/lib/chevre/service/offer/event/authorize/factory.js +4 -3
  29. package/lib/chevre/service/offer/event/authorize/processStartReserve4chevre/requestedProgramMembershipUsed2permit.js +50 -63
  30. package/lib/chevre/service/offer/event/authorize/processStartReserve4chevre.d.ts +6 -0
  31. package/lib/chevre/service/offer/event/authorize/processStartReserve4chevre.js +4 -4
  32. package/lib/chevre/service/offer/event/authorize.d.ts +5 -0
  33. package/lib/chevre/service/offer/event/authorize.js +10 -5
  34. package/lib/chevre/service/offer/onEventChanged.js +29 -13
  35. package/lib/chevre/service/payment/any/authorize/fixTransactionNumber.d.ts +1 -2
  36. package/lib/chevre/service/payment/any/authorize/fixTransactionNumber.js +3 -1
  37. package/lib/chevre/service/payment/any/factory.d.ts +0 -1
  38. package/lib/chevre/service/payment/any/verifyTicketTokenAsNeeded.js +37 -15
  39. package/lib/chevre/service/payment/any.js +6 -2
  40. package/package.json +3 -3
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.modelName = exports.indexes = void 0;
4
+ exports.createSchema = createSchema;
5
+ const mongoose_1 = require("mongoose");
6
+ const settings_1 = require("../../../settings");
7
+ const writeConcern_1 = require("../writeConcern");
8
+ const modelName = 'EventOffer';
9
+ exports.modelName = modelName;
10
+ const schemaDefinition = {
11
+ project: { type: mongoose_1.SchemaTypes.Mixed, required: true },
12
+ seller: { type: mongoose_1.SchemaTypes.Mixed, required: true },
13
+ typeOf: { type: String, required: true },
14
+ identifier: { type: String, required: true },
15
+ itemOffered: { type: mongoose_1.SchemaTypes.Mixed, required: true },
16
+ validFrom: { type: Date, required: true },
17
+ validThrough: { type: Date, required: true },
18
+ availableAtOrFrom: { type: mongoose_1.SchemaTypes.Mixed, required: true },
19
+ offeredBy: { type: mongoose_1.SchemaTypes.Mixed, required: false }
20
+ // availability: { type: String, required: true }
21
+ };
22
+ const schemaOptions = {
23
+ autoIndex: settings_1.MONGO_AUTO_INDEX,
24
+ autoCreate: false,
25
+ collection: 'eventOffers',
26
+ id: true,
27
+ read: settings_1.MONGO_READ_PREFERENCE,
28
+ writeConcern: writeConcern_1.writeConcern,
29
+ strict: true,
30
+ strictQuery: false,
31
+ timestamps: false,
32
+ versionKey: false,
33
+ toJSON: {
34
+ getters: false,
35
+ virtuals: false,
36
+ minimize: false,
37
+ versionKey: false
38
+ },
39
+ toObject: {
40
+ getters: false,
41
+ virtuals: true,
42
+ minimize: false,
43
+ versionKey: false
44
+ }
45
+ };
46
+ const indexes = [
47
+ [
48
+ { validFrom: 1 },
49
+ { name: 'validFrom' }
50
+ ],
51
+ [
52
+ { validThrough: 1, validFrom: 1 },
53
+ { name: 'validThrough' }
54
+ ],
55
+ [
56
+ {
57
+ 'project.id': 1,
58
+ 'itemOffered.id': 1,
59
+ identifier: 1
60
+ },
61
+ {
62
+ name: 'uniqueByItemOfferedAndIdentifier',
63
+ unique: true
64
+ }
65
+ ],
66
+ [
67
+ { 'project.id': 1, validFrom: 1 },
68
+ { name: 'projectId' }
69
+ ],
70
+ [
71
+ { 'seller.id': 1, validFrom: 1 },
72
+ { name: 'sellerId' }
73
+ ],
74
+ [
75
+ { identifier: 1, validFrom: 1 },
76
+ { name: 'identifier' }
77
+ ],
78
+ [
79
+ { 'itemOffered.id': 1, validFrom: 1 },
80
+ { name: 'itemOfferedId' }
81
+ ],
82
+ [
83
+ { 'availableAtOrFrom.identifier': 1, validFrom: 1 },
84
+ { name: 'availableAtOrFrom' }
85
+ ]
86
+ ];
87
+ exports.indexes = indexes;
88
+ /**
89
+ * 拡張イベントオファースキーマ
90
+ */
91
+ let schema;
92
+ function createSchema() {
93
+ if (schema === undefined) {
94
+ schema = new mongoose_1.Schema(schemaDefinition, schemaOptions);
95
+ if (settings_1.MONGO_AUTO_INDEX) {
96
+ indexes.forEach((indexParams) => {
97
+ schema === null || schema === void 0 ? void 0 : schema.index(...indexParams);
98
+ });
99
+ }
100
+ }
101
+ return schema;
102
+ }
@@ -61,6 +61,16 @@ const indexes = [
61
61
  }
62
62
  }
63
63
  ],
64
+ [
65
+ { 'project.id': 1, 'member.identifier': 1 }, // アプリケーションコード追加(2025-11-17~)
66
+ {
67
+ name: 'uniqueByMemberIdentifier',
68
+ unique: true,
69
+ partialFilterExpression: {
70
+ 'member.identifier': { $exists: true }
71
+ }
72
+ }
73
+ ],
64
74
  [
65
75
  { 'project.id': 1, 'member.id': 1, 'member.memberOf.id': 1 },
66
76
  {
@@ -23,6 +23,7 @@ import type { CustomerRepo } from './repo/customer';
23
23
  import type { CustomerTypeRepo } from './repo/customerType';
24
24
  import type { EmailMessageRepo } from './repo/emailMessage';
25
25
  import type { EventRepo } from './repo/event';
26
+ import type { EventOfferRepo } from './repo/eventOffer';
26
27
  import type { EventSellerMakesOfferRepo } from './repo/eventSellerMakesOffer';
27
28
  import type { EventSeriesRepo } from './repo/eventSeries';
28
29
  import type { IdentityRepo } from './repo/identity';
@@ -181,6 +182,10 @@ export type Event = EventRepo;
181
182
  export declare namespace Event {
182
183
  function createInstance(...params: ConstructorParameters<typeof EventRepo>): Promise<EventRepo>;
183
184
  }
185
+ export type EventOffer = EventOfferRepo;
186
+ export declare namespace EventOffer {
187
+ function createInstance(...params: ConstructorParameters<typeof EventOfferRepo>): Promise<EventOfferRepo>;
188
+ }
184
189
  export type EventSellerMakesOffer = EventSellerMakesOfferRepo;
185
190
  export declare namespace EventSellerMakesOffer {
186
191
  function createInstance(...params: ConstructorParameters<typeof EventSellerMakesOfferRepo>): Promise<EventSellerMakesOfferRepo>;
@@ -9,8 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.Person = exports.paymentMethod = exports.PendingReservation = exports.PaymentServiceProvider = exports.PaymentServiceChannel = exports.PaymentService = exports.Passport = exports.OwnershipInfo = exports.OrderNumber = exports.OrderInTransaction = exports.Order = exports.Offer = exports.OfferItemCondition = exports.OfferCatalogItem = exports.OfferCatalog = exports.NoteAboutOrder = exports.Note = exports.MovieTicketType = exports.Message = exports.MerchantReturnPolicy = exports.MemberProgram = exports.Member = exports.Issuer = exports.IdentityProvider = exports.Identity = exports.EventSeries = exports.EventSellerMakesOffer = exports.Event = exports.EmailMessage = exports.CustomerType = exports.Customer = exports.Credentials = exports.CreativeWork = exports.ConfirmationNumber = exports.Comment = exports.Authorization = exports.CategoryCode = exports.AssetTransaction = exports.Aggregation = exports.AggregateReservation = exports.AggregateOrder = exports.AggregateOffer = exports.AdvanceBookingRequirement = exports.AdditionalProperty = exports.Action = exports.AccountTransaction = exports.AccountTitle = exports.AccountingReport = exports.Account = exports.AcceptedOffer = void 0;
13
- exports.WebSite = exports.rateLimit = exports.Trip = exports.TransactionProcess = exports.TransactionNumber = exports.Transaction = exports.Ticket = exports.Telemetry = exports.Task = exports.StockHolder = exports.setting = exports.Setting = exports.ServiceOutputIdentifier = exports.ServiceOutput = exports.ServiceAvailableHour = exports.SellerReturnPolicy = exports.SellerPaymentAccepted = exports.SellerMakesOffer = exports.Seller = exports.Schedule = exports.Role = exports.ReserveInterface = exports.Reservation = exports.ProjectMakesOffer = exports.Project = exports.ProductOffer = exports.ProductModel = exports.ProductHasOfferCatalog = exports.Product = exports.PriceSpecification = exports.PotentialAction = exports.place = exports.Permit = void 0;
12
+ exports.paymentMethod = exports.PendingReservation = exports.PaymentServiceProvider = exports.PaymentServiceChannel = exports.PaymentService = exports.Passport = exports.OwnershipInfo = exports.OrderNumber = exports.OrderInTransaction = exports.Order = exports.Offer = exports.OfferItemCondition = exports.OfferCatalogItem = exports.OfferCatalog = exports.NoteAboutOrder = exports.Note = exports.MovieTicketType = exports.Message = exports.MerchantReturnPolicy = exports.MemberProgram = exports.Member = exports.Issuer = exports.IdentityProvider = exports.Identity = exports.EventSeries = exports.EventSellerMakesOffer = exports.EventOffer = exports.Event = exports.EmailMessage = exports.CustomerType = exports.Customer = exports.Credentials = exports.CreativeWork = exports.ConfirmationNumber = exports.Comment = exports.Authorization = exports.CategoryCode = exports.AssetTransaction = exports.Aggregation = exports.AggregateReservation = exports.AggregateOrder = exports.AggregateOffer = exports.AdvanceBookingRequirement = exports.AdditionalProperty = exports.Action = exports.AccountTransaction = exports.AccountTitle = exports.AccountingReport = exports.Account = exports.AcceptedOffer = void 0;
13
+ exports.WebSite = exports.rateLimit = exports.Trip = exports.TransactionProcess = exports.TransactionNumber = exports.Transaction = exports.Ticket = exports.Telemetry = exports.Task = exports.StockHolder = exports.setting = exports.Setting = exports.ServiceOutputIdentifier = exports.ServiceOutput = exports.ServiceAvailableHour = exports.SellerReturnPolicy = exports.SellerPaymentAccepted = exports.SellerMakesOffer = exports.Seller = exports.Schedule = exports.Role = exports.ReserveInterface = exports.Reservation = exports.ProjectMakesOffer = exports.Project = exports.ProductOffer = exports.ProductModel = exports.ProductHasOfferCatalog = exports.Product = exports.PriceSpecification = exports.PotentialAction = exports.place = exports.Permit = exports.Person = void 0;
14
14
  var AcceptedOffer;
15
15
  (function (AcceptedOffer) {
16
16
  let repo;
@@ -310,6 +310,19 @@ var Event;
310
310
  }
311
311
  Event.createInstance = createInstance;
312
312
  })(Event || (exports.Event = Event = {}));
313
+ var EventOffer;
314
+ (function (EventOffer) {
315
+ let repo;
316
+ function createInstance(...params) {
317
+ return __awaiter(this, void 0, void 0, function* () {
318
+ if (repo === undefined) {
319
+ repo = (yield Promise.resolve().then(() => require('./repo/eventOffer'))).EventOfferRepo;
320
+ }
321
+ return new repo(...params);
322
+ });
323
+ }
324
+ EventOffer.createInstance = createInstance;
325
+ })(EventOffer || (exports.EventOffer = EventOffer = {}));
313
326
  var EventSellerMakesOffer;
314
327
  (function (EventSellerMakesOffer) {
315
328
  let repo;
@@ -2,9 +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';
7
+ import type { EventOfferRepo } from '../../../repo/eventOffer';
6
8
  import type { EventSeriesRepo } from '../../../repo/eventSeries';
7
9
  import type { IssuerRepo } from '../../../repo/issuer';
10
+ import type { MemberRepo } from '../../../repo/member';
8
11
  import type { MemberProgramRepo } from '../../../repo/memberProgram';
9
12
  import type { OfferRepo } from '../../../repo/offer/unitPriceInCatalog';
10
13
  import type { OfferCatalogRepo } from '../../../repo/offerCatalog';
@@ -19,12 +22,16 @@ import type { OfferRateLimitRepo } from '../../../repo/rateLimit/offer';
19
22
  import type { SettingRepo } from '../../../repo/setting';
20
23
  import type { StockHolderRepo } from '../../../repo/stockHolder';
21
24
  import type { TaskRepo } from '../../../repo/task';
25
+ import type { TicketRepo } from '../../../repo/ticket';
22
26
  interface IStartOperationRepos {
23
27
  advanceBookingRequirement: AdvanceBookingRequirementRepo;
28
+ authorization: AuthorizationRepo;
24
29
  stockHolder: StockHolderRepo;
25
30
  event: EventRepo;
31
+ eventOffer: EventOfferRepo;
26
32
  eventSeries: EventSeriesRepo;
27
33
  issuer: IssuerRepo;
34
+ member: MemberRepo;
28
35
  memberProgram: MemberProgramRepo;
29
36
  offer: OfferRepo;
30
37
  offerCatalog: OfferCatalogRepo;
@@ -38,6 +45,7 @@ interface IStartOperationRepos {
38
45
  seat: SeatRepo;
39
46
  setting: SettingRepo;
40
47
  task: TaskRepo;
48
+ ticket: TicketRepo;
41
49
  assetTransaction: AssetTransactionRepo;
42
50
  }
43
51
  type IStartOperation<T> = (repos: IStartOperationRepos, settings: Settings) => Promise<T>;
@@ -41,15 +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,
52
+ eventOffer: repos.eventOffer,
50
53
  issuer: repos.issuer,
54
+ member: repos.member,
51
55
  memberProgram: repos.memberProgram,
52
- productOffer: repos.productOffer
56
+ productOffer: repos.productOffer,
57
+ ticket: repos.ticket
53
58
  });
54
59
  // objectに必要な情報をそろえる
55
60
  const { acceptedOffers4transactionObject, objectSubReservations } = yield createObjectAttributes({
@@ -0,0 +1,23 @@
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
+ object: factory.assetTransaction.reserve.IObjectWithoutDetail;
18
+ acceptedEventOffer?: factory.authorization.IOfferAsObject;
19
+ }): (repos: {
20
+ eventOffer: EventOfferRepo;
21
+ member: MemberRepo;
22
+ }) => Promise<Pick<factory.eventOffer.IEventOffer, "identifier" | "itemOffered" | "typeOf" | "offeredBy" | "validFrom" | "validThrough">>;
23
+ export { fixExtendedEventOffer };
@@ -0,0 +1,62 @@
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 eventOfferIdentifierMustBe = (_a = params.acceptedEventOffer) === null || _a === void 0 ? void 0 : _a.identifier;
25
+ if (typeof eventOfferIdentifierMustBe !== 'string' || eventOfferIdentifierMustBe === '') {
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
+ identifier: { $eq: eventOfferIdentifierMustBe }, // オファーコード
55
+ availableAtOrFrom: { identifier: { $eq: applicationIdentifier } } // アプリケーションコード
56
+ }, ['identifier', 'itemOffered', 'offeredBy', 'typeOf', 'validFrom', 'validThrough'])).shift();
57
+ if (existingEventOffer === undefined) {
58
+ throw new factory.errors.NotFound(`eventOffer: ${eventOfferIdentifierMustBe}`);
59
+ }
60
+ return existingEventOffer;
61
+ });
62
+ }
@@ -8,7 +8,8 @@ declare function validateIssuedOfferIfExists(params: {
8
8
  event: Pick<IMinimizedIndividualEvent, 'offers' | 'id' | 'project' | 'identifier'>;
9
9
  now: Date;
10
10
  object: factory.assetTransaction.reserve.IObjectWithoutDetail;
11
- makesOfferOnApplication: factory.event.screeningEvent.ISellerMakesOffer;
11
+ eventOffer: Pick<factory.eventOffer.IEventOffer, 'identifier' | 'itemOffered' | 'offeredBy' | 'validFrom' | 'validThrough'>;
12
+ acceptedEventOffer?: factory.authorization.IOfferAsObject;
12
13
  }): (repos: {
13
14
  issuer: IssuerRepo;
14
15
  }) => 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, makesOfferOnApplication } = params;
54
+ const { event, acceptedDate, verifiedOffer, eventOffer } = params;
55
55
  // イベント識別子一致検証
56
56
  const itemOfferedIdentifier = verifiedOffer.itemOffered.identifier;
57
57
  if (typeof itemOfferedIdentifier !== 'string' || itemOfferedIdentifier === '') {
58
- throw new factory.errors.Argument('reservationFor.offers.token', 'itemOffered.identifier must be string');
58
+ throw new factory.errors.Argument('ticketedOffer.token', 'itemOffered.identifier must be string');
59
59
  }
60
60
  const itemOfferedIdentifierMustBe = event.identifier;
61
61
  if (typeof itemOfferedIdentifierMustBe !== 'string') {
62
62
  throw new factory.errors.NotFound('identifier', 'the event must have an identifier');
63
63
  }
64
64
  if (itemOfferedIdentifier !== itemOfferedIdentifierMustBe) {
65
- throw new factory.errors.Argument('reservationFor.offers.token', 'itemOffered.identifier not matched');
65
+ throw new factory.errors.Argument('ticketedOffer.token', 'itemOffered.identifier 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
- const applicationOfferIdentifierMustBe = makesOfferOnApplication.identifier;
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,24 +82,24 @@ 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
97
  const maxValue = (_a = verifiedOffer === null || verifiedOffer === void 0 ? void 0 : verifiedOffer.eligibleQuantity) === null || _a === void 0 ? void 0 : _a.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
104
  const numAcceptedOffers = (_b = params.object.acceptedOffer) === null || _b === void 0 ? void 0 : _b.length;
105
105
  if (typeof numAcceptedOffers === 'number' && numAcceptedOffers > 0) {
@@ -114,26 +114,26 @@ 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, makesOfferOnApplication } = params;
117
+ var _a, _b, _c;
118
+ const { event, eventOffer } = params;
119
119
  const acceptedDate = moment(params.now);
120
- const offerTokenIssuer = (_a = makesOfferOnApplication.offeredBy) === null || _a === void 0 ? void 0 : _a.identifier;
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;
123
+ const offerIdentifierMustBe = (_b = params.acceptedEventOffer) === null || _b === void 0 ? void 0 : _b.identifier;
124
+ const offerToken = (_c = params.acceptedEventOffer) === null || _c === void 0 ? void 0 : _c.token;
125
125
  if (typeof offerIdentifierMustBe !== 'string' || offerIdentifierMustBe === '') {
126
126
  throw new factory.errors.ArgumentNull('object.reservationFor.offers.identifier');
127
127
  }
128
128
  if (typeof offerToken !== 'string' || offerToken === '') {
129
129
  throw new factory.errors.ArgumentNull('object.reservationFor.offers.token');
130
130
  }
131
- if (typeof makesOfferOnApplication.identifier !== 'string' || makesOfferOnApplication.identifier === '') {
132
- throw new factory.errors.NotFound('seller.makesOffer.identifier');
131
+ if (typeof eventOffer.identifier !== 'string' || eventOffer.identifier === '') {
132
+ throw new factory.errors.NotFound('eventOffer.identifier');
133
133
  }
134
134
  // アプリケーションオファーコード一致検証
135
- if (makesOfferOnApplication.identifier !== offerIdentifierMustBe) {
136
- throw new factory.errors.Argument('object.reservationFor.offers.identifier', 'offers.identifier not matched');
135
+ if (eventOffer.identifier !== offerIdentifierMustBe) {
136
+ throw new factory.errors.Argument('object.reservationFor.offers.identifier', 'eventOffer.identifier not matched');
137
137
  }
138
138
  const issuer = yield repos.issuer.findByIdentifier({
139
139
  project: { id: event.project.id },
@@ -151,7 +151,7 @@ function validateIssuedOfferIfExists(params) {
151
151
  event,
152
152
  acceptedDate,
153
153
  verifiedOffer,
154
- makesOfferOnApplication,
154
+ eventOffer,
155
155
  object: params.object
156
156
  })();
157
157
  }
@@ -8,6 +8,7 @@ declare function validateMemberTierIfExists(params: {
8
8
  now: Date;
9
9
  object: factory.assetTransaction.reserve.IObjectWithoutDetail;
10
10
  makesOfferOnApplication: factory.event.screeningEvent.ISellerMakesOffer;
11
+ acceptedEventOffer?: factory.authorization.IOfferAsObject;
11
12
  }): (repos: {
12
13
  issuer: IssuerRepo;
13
14
  memberProgram: MemberProgramRepo;
@@ -20,13 +20,13 @@ function validateMemberTier(params) {
20
20
  const tierIdentifier = (_b = (_a = verifiedValidForMemberTier.member) === null || _a === void 0 ? void 0 : _a.memberOf) === null || _b === void 0 ? void 0 : _b.identifier;
21
21
  const memberProgramIdentifier = (_e = (_d = (_c = verifiedValidForMemberTier.member) === null || _c === void 0 ? void 0 : _c.memberOf) === null || _d === void 0 ? void 0 : _d.isTierOf) === null || _e === void 0 ? void 0 : _e.identifier;
22
22
  if (typeof tierIdentifier !== 'string') {
23
- throw new factory.errors.Argument('reservationFor.offers.validForMemberTier', 'tier identifier must be string');
23
+ throw new factory.errors.Argument('ticketedOffer.validForMemberTier', 'tier identifier must be string');
24
24
  }
25
25
  if (typeof memberProgramIdentifier !== 'string') {
26
- throw new factory.errors.Argument('reservationFor.offers.validForMemberTier', 'member program must be string');
26
+ throw new factory.errors.Argument('ticketedOffer.validForMemberTier', 'member program must be string');
27
27
  }
28
28
  if (memberProgramIdentifier !== memberProgramIdentifierMustBe) {
29
- throw new factory.errors.Argument('reservationFor.offers.validForMemberTier', 'member program not matched');
29
+ throw new factory.errors.Argument('ticketedOffer.validForMemberTier', 'member program not matched');
30
30
  }
31
31
  const sellerId = event.offers.seller.id;
32
32
  if (typeof sellerId !== 'string' || sellerId === '') {
@@ -47,22 +47,6 @@ function validateMemberTier(params) {
47
47
  if (productOfferForMemberTier === undefined) {
48
48
  throw new factory.errors.NotFound(factory.offerType.Offer, 'valid product offers for member tier not found');
49
49
  }
50
- // let validThroughMoment: moment.Moment;
51
- // let validFromMoment: moment.Moment;
52
- // validThroughMoment = moment(productOfferForMemberTier.validThrough, ROLE_DATE_FORMAT, true);
53
- // validFromMoment = moment(productOfferForMemberTier.validFrom, ROLE_DATE_FORMAT, true);
54
- // if (acceptedDate.isBefore(validFromMoment)) {
55
- // throw new factory.errors.Argument(
56
- // 'reservationFor.offers.validForMemberTier',
57
- // `the offer id valid from ${validFromMoment}`
58
- // );
59
- // }
60
- // if (acceptedDate.isAfter(validThroughMoment)) {
61
- // throw new factory.errors.Argument(
62
- // 'reservationFor.offers.validForMemberTier',
63
- // `the offer id valid through ${validThroughMoment}`
64
- // );
65
- // }
66
50
  });
67
51
  }
68
52
  function verifyMemberTierToken(params) {
@@ -88,10 +72,10 @@ function verifyMemberTierToken(params) {
88
72
  catch (error) {
89
73
  // JWTエラーをハンドリング
90
74
  if (error instanceof jwt.TokenExpiredError) {
91
- throw new factory.errors.Argument('reservationFor.offers.validForMemberTier', `invalid token. [${error.message} expiredAt:${error.expiredAt}]`);
75
+ throw new factory.errors.Argument('ticketedOffer.validForMemberTier', `invalid token. [${error.message} expiredAt:${error.expiredAt}]`);
92
76
  }
93
77
  else if (error instanceof jwt.JsonWebTokenError) {
94
- throw new factory.errors.Argument('reservationFor.offers.validForMemberTier', `invalid token. [${error.message}]`);
78
+ throw new factory.errors.Argument('ticketedOffer.validForMemberTier', `invalid token. [${error.message}]`);
95
79
  }
96
80
  throw error;
97
81
  }
@@ -101,7 +85,7 @@ function verifyMemberTierToken(params) {
101
85
  function validateMemberTierIfExists(params) {
102
86
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
103
87
  return (repos) => __awaiter(this, void 0, void 0, function* () {
104
- var _a, _b, _c, _d;
88
+ var _a, _b, _c;
105
89
  const { event, makesOfferOnApplication } = params;
106
90
  const acceptedDate = moment(params.now);
107
91
  const eventOffers = event.offers;
@@ -109,16 +93,16 @@ function validateMemberTierIfExists(params) {
109
93
  // support validForMemberTier(2025-05-14~)
110
94
  const validForMemberTierExists = ((_a = makesOfferOnApplication.validForMemberTier) === null || _a === void 0 ? void 0 : _a.typeOf) === 'MemberProgramTier';
111
95
  if (validForMemberTierExists) {
112
- const tokenizedMemberProgramTier = (_c = (_b = params.object.reservationFor) === null || _b === void 0 ? void 0 : _b.offers) === null || _c === void 0 ? void 0 : _c.validForMemberTier;
96
+ const tokenizedMemberProgramTier = (_b = params.acceptedEventOffer) === null || _b === void 0 ? void 0 : _b.validForMemberTier;
113
97
  const validForMemberTierToken = tokenizedMemberProgramTier === null || tokenizedMemberProgramTier === void 0 ? void 0 : tokenizedMemberProgramTier.token;
114
- const memberProgramIdentifierMustBe = (_d = tokenizedMemberProgramTier === null || tokenizedMemberProgramTier === void 0 ? void 0 : tokenizedMemberProgramTier.isTierOf) === null || _d === void 0 ? void 0 : _d.identifier;
98
+ const memberProgramIdentifierMustBe = (_c = tokenizedMemberProgramTier === null || tokenizedMemberProgramTier === void 0 ? void 0 : tokenizedMemberProgramTier.isTierOf) === null || _c === void 0 ? void 0 : _c.identifier;
115
99
  // ティアトークンが必須
116
100
  if (typeof validForMemberTierToken !== 'string' || validForMemberTierToken === '') {
117
- throw new factory.errors.ArgumentNull('reservationFor.offers.validForMemberTier.token');
101
+ throw new factory.errors.ArgumentNull('ticketedOffer.validForMemberTier.token');
118
102
  }
119
103
  // メンバープログラムコード指定が必須
120
104
  if (typeof memberProgramIdentifierMustBe !== 'string' || memberProgramIdentifierMustBe === '') {
121
- throw new factory.errors.ArgumentNull('reservationFor.offers.validForMemberTier.isTierOf.identifier');
105
+ throw new factory.errors.ArgumentNull('ticketedOffer.validForMemberTier.isTierOf.identifier');
122
106
  }
123
107
  // 有効メンバープログラムティアが存在する場合、オファーコレクションコードが必須
124
108
  const aggregateOfferIdentifier = eventOffers.identifier;
@@ -0,0 +1,23 @@
1
+ import * as factory from '../../../../factory';
2
+ import { IMinimizedIndividualEvent } from '../../../../factory/event';
3
+ import type { AuthorizationRepo } from '../../../../repo/authorization';
4
+ import type { TicketRepo } from '../../../../repo/ticket';
5
+ type IPermitOrInvoice = Pick<factory.ownershipInfo.IPermitAsGood, 'identifier' | 'typeOf'> | Pick<factory.invoice.IInvoice, 'paymentMethodId' | 'typeOf'>;
6
+ declare function verifyTicketTokenAsNeeded(params: {
7
+ event: Pick<IMinimizedIndividualEvent, 'offers' | 'id' | 'project' | 'identifier'>;
8
+ now: Date;
9
+ availableAt: {
10
+ /**
11
+ * 販売アプリケーションID
12
+ */
13
+ id: string;
14
+ };
15
+ object: factory.assetTransaction.reserve.IObjectWithoutDetail;
16
+ instrument: factory.assetTransaction.reserve.IInstrument[];
17
+ }): (repos: {
18
+ authorization: AuthorizationRepo;
19
+ ticket: TicketRepo;
20
+ }) => Promise<{
21
+ acceptedEventOffer?: factory.authorization.IOfferAsObject;
22
+ }>;
23
+ export { IPermitOrInvoice, verifyTicketTokenAsNeeded };
@@ -0,0 +1,62 @@
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.verifyTicketTokenAsNeeded = verifyTicketTokenAsNeeded;
13
+ const factory = require("../../../../factory");
14
+ // tslint:disable-next-line:max-func-body-length
15
+ function verifyTicketTokenAsNeeded(params) {
16
+ // tslint:disable-next-line:cyclomatic-complexity
17
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
18
+ var _a, _b, _c;
19
+ const { instrument, event } = params;
20
+ let acceptedEventOffer;
21
+ // 興行オファーチケットが指定された場合、オファーへ変換する
22
+ const ticketToken = (_a = instrument.find((eachInstrument) => eachInstrument.typeOf === 'Ticket')) === null || _a === void 0 ? void 0 : _a.ticketToken;
23
+ if (typeof ticketToken === 'string' && ticketToken !== '') {
24
+ const placeOrderIdByInstrument = (_b = instrument.find((eachInstrument) => eachInstrument.typeOf === factory.transactionType.PlaceOrder)) === null || _b === void 0 ? void 0 : _b.id;
25
+ if (typeof placeOrderIdByInstrument !== 'string' || placeOrderIdByInstrument === '') {
26
+ throw new factory.errors.NotFound('instrument as placeOrder');
27
+ }
28
+ const ticket = (yield repos.ticket.projectFields({
29
+ limit: 1,
30
+ page: 1,
31
+ project: { id: { $eq: event.project.id } },
32
+ ticketToken: { $eq: ticketToken }
33
+ }, ['ticketToken'])).shift();
34
+ if (ticket === undefined) {
35
+ throw new factory.errors.NotFound('Ticket');
36
+ }
37
+ // 承認を参照
38
+ const validAuthorization = yield repos.authorization.findValidOneByCode({
39
+ project: { id: event.project.id },
40
+ code: ticket.ticketToken
41
+ });
42
+ const authorizedObject = validAuthorization.object;
43
+ // audience検証
44
+ if (((_c = validAuthorization.audience) === null || _c === void 0 ? void 0 : _c.typeOf) !== factory.transactionType.PlaceOrder
45
+ || validAuthorization.audience.id !== placeOrderIdByInstrument) {
46
+ throw new factory.errors.Argument('ticketToken', 'audience not matched with placeOrder');
47
+ }
48
+ if (authorizedObject.typeOf === factory.offerType.Offer) {
49
+ // イベントIDを検証
50
+ const eventIdMustBe = authorizedObject.itemOffered.serviceOutput.reservationFor.id;
51
+ if (eventIdMustBe !== event.id) {
52
+ throw new factory.errors.Argument('ticketToken', 'event.id not matched');
53
+ }
54
+ acceptedEventOffer = authorizedObject;
55
+ }
56
+ else {
57
+ throw new factory.errors.Argument('ticketToken', 'must be Offer');
58
+ }
59
+ }
60
+ return { acceptedEventOffer };
61
+ });
62
+ }