@chevre/domain 24.0.0-alpha.80 → 24.0.0-alpha.82

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 (66) hide show
  1. package/lib/chevre/errorHandler.d.ts +5 -0
  2. package/lib/chevre/errorHandler.js +26 -4
  3. package/lib/chevre/repo/accountingReport.js +2 -25
  4. package/lib/chevre/repo/aggregateOffer.js +11 -36
  5. package/lib/chevre/repo/event.js +2 -37
  6. package/lib/chevre/repo/eventSeries.js +0 -144
  7. package/lib/chevre/repo/message.js +1 -3
  8. package/lib/chevre/repo/mongoose/schemas/setting.d.ts +0 -1
  9. package/lib/chevre/repo/offer/unitPriceInCatalog.js +1 -1
  10. package/lib/chevre/repo/order.js +2 -4
  11. package/lib/chevre/repo/ownershipInfo.js +2 -4
  12. package/lib/chevre/repo/passport.js +1 -1
  13. package/lib/chevre/repo/pendingReservation.js +2 -35
  14. package/lib/chevre/repo/task.js +5 -7
  15. package/lib/chevre/repo/transactionNumberCounter.js +4 -6
  16. package/lib/chevre/repository.d.ts +0 -13
  17. package/lib/chevre/repository.js +1 -26
  18. package/lib/chevre/service/aggregation/event/importFromCOA.js +4 -8
  19. package/lib/chevre/service/assetTransaction/pay/start/preStart/validateAcceptedPaymentMethodIfNeeded.js +15 -23
  20. package/lib/chevre/service/assetTransaction/reserve/start.d.ts +0 -2
  21. package/lib/chevre/service/assetTransaction/reserve/start.js +0 -1
  22. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest.d.ts +0 -3
  23. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest.js +1 -11
  24. package/lib/chevre/service/event.js +4 -10
  25. package/lib/chevre/service/notification/triggerWebhook.js +43 -48
  26. package/lib/chevre/service/offer/event/authorize/processStartReserve4chevre.d.ts +0 -2
  27. package/lib/chevre/service/offer/event/authorize.d.ts +0 -2
  28. package/lib/chevre/service/offer/event/importFromCOA/factory.js +0 -12
  29. package/lib/chevre/service/offer/event/importFromCOA.js +5 -16
  30. package/lib/chevre/service/offer/event/issueEventOfferTicket.d.ts +1 -3
  31. package/lib/chevre/service/offer/event/issueEventOfferTicket.js +11 -13
  32. package/lib/chevre/service/offer/eventServiceByCOA/acceptOffer/authorize.js +5 -15
  33. package/lib/chevre/service/offer/eventServiceByCOA/authorize/factory.d.ts +0 -1
  34. package/lib/chevre/service/offer/eventServiceByCOA/authorize/factory.js +1 -12
  35. package/lib/chevre/service/offer/eventServiceByCOA/authorize/validateAcceptedOffers.js +0 -15
  36. package/lib/chevre/service/offer/eventServiceByCOA/authorize.js +2 -5
  37. package/lib/chevre/service/offer/eventServiceByCOA/changeOffers.js +2 -3
  38. package/lib/chevre/service/offer/factory.js +6 -2
  39. package/lib/chevre/service/payment/creditCard/authorize/handleAuthorizeError.js +2 -7
  40. package/lib/chevre/service/payment/creditCard/gmoError.d.ts +1 -31
  41. package/lib/chevre/service/payment/creditCard/refundCreditCard.js +2 -2
  42. package/lib/chevre/service/payment/creditCard/searchGMOTrade.js +1 -1
  43. package/lib/chevre/service/payment/creditCard/voidTransaction.js +1 -1
  44. package/lib/chevre/service/payment/movieTicket/payMovieTicket/processSeatInfoSync.js +2 -2
  45. package/lib/chevre/service/payment/movieTicket/refundMovieTicket/processSeatInfoSync.js +2 -2
  46. package/lib/chevre/service/payment/movieTicket/refundMovieTicket/processSeatInfoSyncCancel.js +1 -2
  47. package/lib/chevre/service/payment/movieTicket/refundMovieTicket.js +10 -3
  48. package/lib/chevre/service/reserveCOA/cancelReservation.js +12 -16
  49. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesBySeller.d.ts +0 -2
  50. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesBySeller.js +0 -6
  51. package/lib/chevre/service/task/onResourceDeleted.js +0 -2
  52. package/lib/chevre/service/task/onResourceUpdated.js +0 -2
  53. package/lib/chevre/service/taskHandler.js +0 -1
  54. package/lib/chevre/service/transaction/placeOrder/confirm/validation.js +26 -32
  55. package/lib/chevre/service/transaction/placeOrder/confirm.js +2 -4
  56. package/lib/chevre/service/transaction/placeOrder/updateAgent.js +1 -1
  57. package/lib/chevre/service/transaction/returnOrder.js +2 -5
  58. package/package.json +3 -3
  59. package/lib/chevre/repo/mongoose/schemas/productOffer.d.ts +0 -14
  60. package/lib/chevre/repo/mongoose/schemas/productOffer.js +0 -108
  61. package/lib/chevre/repo/place/busStop.d.ts +0 -27
  62. package/lib/chevre/repo/place/busStop.js +0 -169
  63. package/lib/chevre/repo/productOffer.d.ts +0 -52
  64. package/lib/chevre/repo/productOffer.js +0 -209
  65. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/validateMemberTierIfExists.d.ts +0 -16
  66. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/validateMemberTierIfExists.js +0 -129
@@ -1,169 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BusStopRepo = void 0;
4
- const factory_1 = require("../../factory");
5
- const settings_1 = require("../../settings");
6
- const civicStructure_1 = require("../mongoose/schemas/civicStructure");
7
- /**
8
- * ターミナルリポジトリ
9
- */
10
- class BusStopRepo {
11
- civicStructureModel;
12
- constructor(connection) {
13
- this.civicStructureModel = connection.model(civicStructure_1.modelName, (0, civicStructure_1.createSchema)());
14
- }
15
- static CREATE_BUS_STOP_MONGO_CONDITIONS(params) {
16
- const andConditions = [{ typeOf: { $eq: factory_1.factory.placeType.BusStop } }];
17
- const projectIdEq = params.project?.id?.$eq;
18
- if (typeof projectIdEq === 'string') {
19
- andConditions.push({ 'project.id': { $eq: projectIdEq } });
20
- }
21
- const branchCodeEq = params.branchCode?.$eq;
22
- if (typeof branchCodeEq === 'string') {
23
- andConditions.push({
24
- branchCode: {
25
- $exists: true,
26
- $eq: branchCodeEq
27
- }
28
- });
29
- }
30
- const branchCodeRegex = params.branchCode?.$regex;
31
- if (typeof branchCodeRegex === 'string' && branchCodeRegex.length > 0) {
32
- andConditions.push({
33
- branchCode: {
34
- $exists: true,
35
- $regex: new RegExp(branchCodeRegex)
36
- }
37
- });
38
- }
39
- const branchCodeIn = params.branchCode?.$in;
40
- if (Array.isArray(branchCodeIn)) {
41
- andConditions.push({
42
- branchCode: {
43
- $exists: true,
44
- $in: branchCodeIn
45
- }
46
- });
47
- }
48
- /* istanbul ignore else */
49
- const idEq = params.id?.$eq;
50
- if (typeof idEq === 'string') {
51
- andConditions.push({
52
- _id: {
53
- $eq: idEq
54
- }
55
- });
56
- }
57
- const idIn = params.id?.$in;
58
- if (Array.isArray(idIn)) {
59
- andConditions.push({
60
- _id: {
61
- $in: idIn
62
- }
63
- });
64
- }
65
- const nameRegex = params.name?.$regex;
66
- /* istanbul ignore else */
67
- if (typeof nameRegex === 'string' && nameRegex.length > 0) {
68
- andConditions.push({
69
- $or: [
70
- {
71
- 'name.ja': {
72
- $exists: true,
73
- $regex: new RegExp(nameRegex)
74
- }
75
- },
76
- {
77
- 'name.en': {
78
- $exists: true,
79
- $regex: new RegExp(nameRegex)
80
- }
81
- }
82
- ]
83
- });
84
- }
85
- return andConditions;
86
- }
87
- async saveBusStop(params) {
88
- let doc;
89
- if (typeof params.id !== 'string' || params.id.length === 0) {
90
- doc = await this.civicStructureModel.create(params);
91
- }
92
- else {
93
- // 上書き禁止属性を除外(2022-08-24~)
94
- const { id, branchCode, project, typeOf, ...updateFields } = params; // eslint-disable-line @typescript-eslint/no-unused-vars
95
- doc = await this.civicStructureModel.findOneAndUpdate({ _id: params.id }, updateFields, { upsert: false, new: true })
96
- .exec();
97
- }
98
- if (doc === null) {
99
- throw new factory_1.factory.errors.NotFound(this.civicStructureModel.modelName);
100
- }
101
- return doc.toObject();
102
- }
103
- async findBusStopByBranchCode(params) {
104
- return this.civicStructureModel.findOne({
105
- typeOf: { $eq: factory_1.factory.placeType.BusStop },
106
- 'project.id': { $eq: params.project.id },
107
- branchCode: { $eq: params.branchCode }
108
- })
109
- .exec()
110
- .then((doc) => {
111
- if (doc === null) {
112
- throw new factory_1.factory.errors.NotFound(`${factory_1.factory.placeType.BusStop} ${params.branchCode}`);
113
- }
114
- return doc.toObject();
115
- });
116
- }
117
- async searchBusStops(params) {
118
- const conditions = BusStopRepo.CREATE_BUS_STOP_MONGO_CONDITIONS(params);
119
- // containsPlaceを含めるとデータサイズが大きくなるので、検索結果には含めない
120
- const query = this.civicStructureModel.find((conditions.length > 0) ? { $and: conditions } : {}, {
121
- __v: 0,
122
- createdAt: 0,
123
- updatedAt: 0,
124
- containsPlace: 0
125
- });
126
- if (typeof params.limit === 'number' && params.limit > 0) {
127
- const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
128
- query.limit(params.limit)
129
- .skip(params.limit * (page - 1));
130
- }
131
- /* istanbul ignore else */
132
- if (params.sort?.branchCode !== undefined) {
133
- query.sort({ branchCode: params.sort.branchCode });
134
- }
135
- return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
136
- .exec()
137
- .then((docs) => docs.map((doc) => doc.toObject()));
138
- }
139
- async findBusStopById(params, projection) {
140
- const doc = await this.civicStructureModel.findOne({
141
- typeOf: { $eq: factory_1.factory.placeType.BusStop },
142
- _id: { $eq: params.id }
143
- }, {
144
- __v: 0,
145
- createdAt: 0,
146
- updatedAt: 0,
147
- ...projection
148
- })
149
- .exec();
150
- if (doc === null) {
151
- throw new factory_1.factory.errors.NotFound(this.civicStructureModel.modelName);
152
- }
153
- return doc.toObject();
154
- }
155
- async deleteBusStopById(params) {
156
- await this.civicStructureModel.findOneAndDelete({
157
- typeOf: { $eq: factory_1.factory.placeType.BusStop },
158
- _id: { $eq: params.id },
159
- 'project.id': { $eq: params.project.id }
160
- })
161
- .exec()
162
- .then((doc) => {
163
- if (doc === null) {
164
- throw new factory_1.factory.errors.NotFound(this.civicStructureModel.modelName);
165
- }
166
- });
167
- }
168
- }
169
- exports.BusStopRepo = BusStopRepo;
@@ -1,52 +0,0 @@
1
- import type { BulkWriteResult, DeleteResult } from 'mongodb';
2
- import { Connection, FilterQuery } from 'mongoose';
3
- import { factory } from '../factory';
4
- import { IDocType } from './mongoose/schemas/productOffer';
5
- type IUnset = {
6
- [key in keyof IDocType]?: 1;
7
- };
8
- type IDocWithId = factory.productOffer.IProductOffer & {
9
- id: string;
10
- };
11
- type IKeyOfProjection = keyof IDocType;
12
- /**
13
- * プロダクトオファーリポジトリ
14
- */
15
- export declare class ProductOfferRepo {
16
- private readonly productOfferModel;
17
- constructor(connection: Connection);
18
- static CREATE_MONGO_CONDITIONS(params: factory.productOffer.ISearchConditions): FilterQuery<IDocType>[];
19
- findProductOffers(params: factory.productOffer.ISearchConditions, inclusion: IKeyOfProjection[]): Promise<IDocWithId[]>;
20
- /**
21
- * オファーコードとオファーコレクションコードをキーにして冪等置換
22
- */
23
- upsertOffersByIdentifier(params: {
24
- $set: Pick<IDocType, 'acceptedPaymentMethod' | 'availability' | 'identifier' | 'itemOffered' | 'offeredBy' | 'project' | 'typeOf' | 'validForMemberTier' | 'validFrom' | 'validThrough'> & {
25
- id?: never;
26
- };
27
- $unset: IUnset;
28
- }[], options: {
29
- /**
30
- * falseの場合setOnInsertのみ
31
- * trueの場合setのみ
32
- */
33
- update: boolean;
34
- }): Promise<{
35
- bulkWriteResult?: BulkWriteResult;
36
- modifiedProductOffers?: {
37
- id: string;
38
- }[];
39
- }>;
40
- /**
41
- * 販売者の提供するプロダクトオファーを削除する
42
- */
43
- deleteProductOffersBySeller(params: {
44
- project: {
45
- id: string;
46
- };
47
- offeredBy: {
48
- id: string;
49
- };
50
- }): Promise<DeleteResult>;
51
- }
52
- export {};
@@ -1,209 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ProductOfferRepo = void 0;
4
- const factory_1 = require("../factory");
5
- const settings_1 = require("../settings");
6
- const productOffer_1 = require("./mongoose/schemas/productOffer");
7
- const AVAILABLE_PROJECT_FIELDS = [
8
- 'identifier',
9
- 'project',
10
- 'itemOffered',
11
- 'offeredBy',
12
- 'typeOf',
13
- 'validFrom',
14
- 'validThrough',
15
- 'availability',
16
- 'acceptedPaymentMethod',
17
- 'validForMemberTier'
18
- ];
19
- /**
20
- * プロダクトオファーリポジトリ
21
- */
22
- class ProductOfferRepo {
23
- productOfferModel;
24
- constructor(connection) {
25
- this.productOfferModel = connection.model(productOffer_1.modelName, (0, productOffer_1.createSchema)());
26
- }
27
- static CREATE_MONGO_CONDITIONS(params) {
28
- const andConditions = [];
29
- const idEq = params.id?.$eq;
30
- if (typeof idEq === 'string') {
31
- andConditions.push({ _id: { $eq: idEq } });
32
- }
33
- const projectIdEq = params.project?.id?.$eq;
34
- if (typeof projectIdEq === 'string') {
35
- andConditions.push({ 'project.id': { $eq: projectIdEq } });
36
- }
37
- const identifierEq = params.identifier?.$eq;
38
- if (typeof identifierEq === 'string') {
39
- andConditions.push({ identifier: { $eq: identifierEq } });
40
- }
41
- const identifierIn = params.identifier?.$in;
42
- if (Array.isArray(identifierIn)) {
43
- andConditions.push({ identifier: { $in: identifierIn } });
44
- }
45
- const itemOfferedIdentifierEq = params.itemOffered?.identifier?.$eq;
46
- if (typeof itemOfferedIdentifierEq === 'string') {
47
- andConditions.push({ 'itemOffered.identifier': { $eq: itemOfferedIdentifierEq } });
48
- }
49
- const itemOfferedIdentifierIn = params.itemOffered?.identifier?.$in;
50
- if (Array.isArray(itemOfferedIdentifierIn)) {
51
- andConditions.push({ 'itemOffered.identifier': { $in: itemOfferedIdentifierIn } });
52
- }
53
- const offeredByIdEq = params.offeredBy?.id?.$eq;
54
- if (typeof offeredByIdEq === 'string') {
55
- andConditions.push({ 'offeredBy.id': { $eq: offeredByIdEq } });
56
- }
57
- const sellerByIdEq = params.seller?.id?.$eq;
58
- if (typeof sellerByIdEq === 'string') {
59
- andConditions.push({ 'offeredBy.id': { $eq: sellerByIdEq } });
60
- }
61
- const validForMemberTierIdentifierEq = params.validForMemberTier?.identifier?.$eq;
62
- if (typeof validForMemberTierIdentifierEq === 'string') {
63
- andConditions.push({ 'validForMemberTier.identifier': { $exists: true, $eq: validForMemberTierIdentifierEq } });
64
- }
65
- const validFromLte = params.validFrom?.$lte;
66
- if (validFromLte instanceof Date) {
67
- andConditions.push({ validFrom: { $lte: validFromLte } });
68
- }
69
- const validThroughGte = params.validThrough?.$gte;
70
- if (validThroughGte instanceof Date) {
71
- andConditions.push({ validThrough: { $gte: validThroughGte } });
72
- }
73
- return andConditions;
74
- }
75
- async findProductOffers(params, inclusion) {
76
- const conditions = ProductOfferRepo.CREATE_MONGO_CONDITIONS(params);
77
- let positiveProjectionFields;
78
- if (Array.isArray(inclusion) && inclusion.length > 0) {
79
- positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
80
- }
81
- else {
82
- throw new factory_1.factory.errors.ArgumentNull('inclusion', 'inclusion must be specified');
83
- }
84
- const projection = {
85
- _id: 0,
86
- id: { $toString: '$_id' },
87
- ...Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1])))
88
- };
89
- const query = this.productOfferModel.find((conditions.length > 0) ? { $and: conditions } : {}, projection);
90
- if (typeof params.sort?.validFrom === 'number') {
91
- query.sort({ validFrom: params.sort.validFrom });
92
- }
93
- if (typeof params.limit === 'number' && params.limit > 0) {
94
- const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
95
- query.limit(params.limit)
96
- .skip(params.limit * (page - 1));
97
- }
98
- return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
99
- .lean()
100
- .exec();
101
- }
102
- /**
103
- * オファーコードとオファーコレクションコードをキーにして冪等置換
104
- */
105
- async upsertOffersByIdentifier(params, options) {
106
- const { update } = options;
107
- const bulkWriteOps = [];
108
- const queryFilters = [];
109
- if (Array.isArray(params)) {
110
- params.forEach(({ $set, $unset }) => {
111
- const { availability, identifier, itemOffered, offeredBy, project, validFrom, validThrough, acceptedPaymentMethod, validForMemberTier } = $set;
112
- if (typeof identifier !== 'string' || identifier === '') {
113
- throw new factory_1.factory.errors.ArgumentNull('identifier');
114
- }
115
- if (typeof itemOffered.identifier !== 'string' || itemOffered.identifier === '') {
116
- throw new factory_1.factory.errors.ArgumentNull('itemOffered.identifier');
117
- }
118
- // リソースのユニークネスを保証するfilter
119
- const filter = {
120
- 'project.id': { $eq: project.id },
121
- 'itemOffered.identifier': { $eq: itemOffered.identifier },
122
- identifier: { $eq: identifier }
123
- };
124
- queryFilters.push({
125
- 'project.id': { $eq: project.id },
126
- 'itemOffered.identifier': { $eq: itemOffered.identifier },
127
- identifier: { $eq: identifier }
128
- });
129
- if (update === true) {
130
- const setFields = {
131
- availability,
132
- validFrom,
133
- validThrough,
134
- ...(typeof acceptedPaymentMethod?.typeOf === 'string') ? { acceptedPaymentMethod } : undefined,
135
- ...(typeof validForMemberTier?.typeOf === 'string') ? { validForMemberTier } : undefined
136
- };
137
- const updateFilter = {
138
- $set: setFields,
139
- ...($unset !== undefined) ? { $unset } : undefined
140
- };
141
- const updateOne = {
142
- filter,
143
- update: updateFilter,
144
- upsert: false
145
- };
146
- bulkWriteOps.push({ updateOne });
147
- }
148
- else {
149
- const setOnInsert = {
150
- itemOffered, offeredBy, identifier, project,
151
- typeOf: factory_1.factory.offerType.Offer,
152
- availability,
153
- validFrom,
154
- validThrough,
155
- ...(typeof acceptedPaymentMethod?.typeOf === 'string') ? { acceptedPaymentMethod } : undefined,
156
- ...(typeof validForMemberTier?.typeOf === 'string') ? { validForMemberTier } : undefined
157
- };
158
- const updateFilter = {
159
- $setOnInsert: setOnInsert
160
- };
161
- const updateOne = {
162
- filter,
163
- update: updateFilter,
164
- upsert: true
165
- };
166
- bulkWriteOps.push({ updateOne });
167
- }
168
- });
169
- }
170
- if (bulkWriteOps.length > 0) {
171
- const bulkWriteResult = await this.productOfferModel.bulkWrite(bulkWriteOps, { ordered: false });
172
- // modifiedの場合upsertedIdsに含まれないので、idを検索する
173
- const modifiedProductOffers = await this.productOfferModel.find({ $or: queryFilters }, {
174
- _id: 0,
175
- id: { $toString: '$_id' }
176
- })
177
- .lean()
178
- .exec();
179
- return { bulkWriteResult, modifiedProductOffers };
180
- }
181
- return {};
182
- }
183
- // public async deleteProductOffersByIds(params: {
184
- // project: { id: string };
185
- // ids: string[];
186
- // }): Promise<DeleteResult | void> {
187
- // const { project, ids } = params;
188
- // if (Array.isArray(ids) && ids.length > 0) {
189
- // return this.productOfferModel.deleteMany(
190
- // {
191
- // 'project.id': { $eq: project.id },
192
- // _id: { $in: ids }
193
- // }
194
- // )
195
- // .exec();
196
- // }
197
- // }
198
- /**
199
- * 販売者の提供するプロダクトオファーを削除する
200
- */
201
- async deleteProductOffersBySeller(params) {
202
- return this.productOfferModel.deleteMany({
203
- 'project.id': { $eq: params.project.id },
204
- 'offeredBy.id': { $eq: params.offeredBy.id }
205
- })
206
- .exec();
207
- }
208
- }
209
- exports.ProductOfferRepo = ProductOfferRepo;
@@ -1,16 +0,0 @@
1
- import { factory } from '../../../../factory';
2
- import { IMinimizedIndividualEvent } from '../../../../factory/event';
3
- import type { IssuerRepo } from '../../../../repo/issuer';
4
- import type { MemberProgramRepo } from '../../../../repo/memberProgram';
5
- import type { ProductOfferRepo } from '../../../../repo/productOffer';
6
- declare function validateMemberTierIfExists(params: {
7
- event: Pick<IMinimizedIndividualEvent, 'offers' | 'id' | 'project'>;
8
- now: Date;
9
- makesOfferOnApplication: factory.event.screeningEvent.ISellerMakesOffer;
10
- acceptedEventOffer?: factory.authorization.IOfferAsObject;
11
- }): (repos: {
12
- issuer: IssuerRepo;
13
- memberProgram: MemberProgramRepo;
14
- productOffer: ProductOfferRepo;
15
- }) => Promise<void>;
16
- export { validateMemberTierIfExists };
@@ -1,129 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.validateMemberTierIfExists = validateMemberTierIfExists;
7
- const jsonwebtoken_1 = require("jsonwebtoken");
8
- const moment_1 = __importDefault(require("moment"));
9
- const factory_1 = require("../../../../factory");
10
- function validateMemberTier(params) {
11
- return async (repos) => {
12
- const { acceptedDate, event, verifiedValidForMemberTier, memberProgramIdentifierMustBe, aggregateOfferIdentifier } = params;
13
- const tierIdentifier = verifiedValidForMemberTier.member?.memberOf?.identifier;
14
- const memberProgramIdentifier = verifiedValidForMemberTier.member?.memberOf?.isTierOf?.identifier;
15
- if (typeof tierIdentifier !== 'string') {
16
- throw new factory_1.factory.errors.Argument('ticketedOffer.validForMemberTier', 'tier identifier must be string');
17
- }
18
- if (typeof memberProgramIdentifier !== 'string') {
19
- throw new factory_1.factory.errors.Argument('ticketedOffer.validForMemberTier', 'member program must be string');
20
- }
21
- if (memberProgramIdentifier !== memberProgramIdentifierMustBe) {
22
- throw new factory_1.factory.errors.Argument('ticketedOffer.validForMemberTier', 'member program not matched');
23
- }
24
- const sellerId = event.offers.seller.id;
25
- if (typeof sellerId !== 'string' || sellerId === '') {
26
- throw new factory_1.factory.errors.NotFound('event.offers.seller.id');
27
- }
28
- // 有効なプロダクトオファーを検証
29
- const productOfferForMemberTier = (await repos.productOffer.findProductOffers({
30
- limit: 1,
31
- page: 1,
32
- project: { id: { $eq: event.project.id } },
33
- // availableAtOrFrom: { id: { $eq: availableAt.id } },
34
- itemOffered: { identifier: { $eq: aggregateOfferIdentifier } }, // オファーコレクションコード
35
- validForMemberTier: { identifier: { $eq: tierIdentifier } },
36
- validFrom: { $lte: acceptedDate.toDate() },
37
- validThrough: { $gte: acceptedDate.toDate() },
38
- offeredBy: { id: { $eq: sellerId } } // オファー提供者も検証する
39
- }, ['identifier'])).shift();
40
- if (productOfferForMemberTier === undefined) {
41
- throw new factory_1.factory.errors.NotFound(factory_1.factory.offerType.Offer, 'valid product offers for member tier not found');
42
- }
43
- };
44
- }
45
- async function verifyMemberTierToken(params) {
46
- let result;
47
- const { issuer, secret, token } = params;
48
- try {
49
- result = await new Promise((resolve, reject) => {
50
- (0, jsonwebtoken_1.verify)(token, secret, {
51
- algorithms: ['HS256'],
52
- issuer
53
- // ...(Array.isArray(params.audience)) ? { audience: params.audience } : undefined
54
- }, (err, decoded) => {
55
- if (err instanceof Error) {
56
- reject(err);
57
- }
58
- else {
59
- resolve(decoded);
60
- }
61
- });
62
- });
63
- }
64
- catch (error) {
65
- // JWTエラーをハンドリング
66
- if (error instanceof jsonwebtoken_1.TokenExpiredError) {
67
- throw new factory_1.factory.errors.Argument('ticketedOffer.validForMemberTier', `invalid token. [${error.message} expiredAt:${error.expiredAt}]`);
68
- }
69
- else if (error instanceof jsonwebtoken_1.JsonWebTokenError) {
70
- throw new factory_1.factory.errors.Argument('ticketedOffer.validForMemberTier', `invalid token. [${error.message}]`);
71
- }
72
- throw error;
73
- }
74
- return result;
75
- }
76
- function validateMemberTierIfExists(params) {
77
- return async (repos) => {
78
- const { event, makesOfferOnApplication } = params;
79
- const acceptedDate = (0, moment_1.default)(params.now);
80
- const eventOffers = event.offers;
81
- // 有効メンバープログラムティアが存在する場合
82
- // support validForMemberTier(2025-05-14~)
83
- const validForMemberTierExists = makesOfferOnApplication.validForMemberTier?.typeOf === 'MemberProgramTier';
84
- if (validForMemberTierExists) {
85
- const tokenizedMemberProgramTier = params.acceptedEventOffer?.validForMemberTier;
86
- const validForMemberTierToken = tokenizedMemberProgramTier?.token;
87
- const memberProgramIdentifierMustBe = tokenizedMemberProgramTier?.isTierOf?.identifier;
88
- // ティアトークンが必須
89
- if (typeof validForMemberTierToken !== 'string' || validForMemberTierToken === '') {
90
- throw new factory_1.factory.errors.ArgumentNull('ticketedOffer.validForMemberTier.token');
91
- }
92
- // メンバープログラムコード指定が必須
93
- if (typeof memberProgramIdentifierMustBe !== 'string' || memberProgramIdentifierMustBe === '') {
94
- throw new factory_1.factory.errors.ArgumentNull('ticketedOffer.validForMemberTier.isTierOf.identifier');
95
- }
96
- // 有効メンバープログラムティアが存在する場合、オファーコレクションコードが必須
97
- const aggregateOfferIdentifier = eventOffers.identifier;
98
- if (typeof aggregateOfferIdentifier !== 'string' || aggregateOfferIdentifier === '') {
99
- throw new factory_1.factory.errors.NotFound('makesOfferOnApplication.identifier');
100
- }
101
- // トークン検証
102
- const memberProgram = (await repos.memberProgram.projectMemberPrograms({
103
- limit: 1,
104
- page: 1,
105
- project: { id: { $eq: params.event.project.id } },
106
- identifier: { $eq: memberProgramIdentifierMustBe }
107
- })).shift();
108
- if (memberProgram === undefined) {
109
- throw new factory_1.factory.errors.NotFound('MemberProgram', `MemberProgram '${memberProgramIdentifierMustBe}' not found`);
110
- }
111
- const issuer = await repos.issuer.findByIdentifier({
112
- project: { id: params.event.project.id },
113
- identifier: memberProgram.hostingOrganization.identifier
114
- });
115
- if (typeof issuer.tokenSecret !== 'string' || issuer.tokenSecret === '') {
116
- throw new factory_1.factory.errors.NotFound('issuer.tokenSecret');
117
- }
118
- const verifiedValidForMemberTier = await verifyMemberTierToken({
119
- secret: issuer.tokenSecret,
120
- issuer: issuer.url,
121
- token: validForMemberTierToken
122
- });
123
- await validateMemberTier({
124
- event, acceptedDate, verifiedValidForMemberTier,
125
- memberProgramIdentifierMustBe, aggregateOfferIdentifier
126
- })(repos);
127
- }
128
- };
129
- }