@chevre/domain 23.0.0-alpha.8 → 23.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/example/src/chevre/assetTransaction/processReserve.ts +102 -40
- package/example/src/chevre/categoryCode/checkUniqueness.ts +69 -0
- package/example/src/chevre/event/checkEventAdditionalPropertyUniqueness.ts +108 -0
- package/example/src/chevre/event/migrateEventAdditionalProperty2identifier.ts +121 -0
- package/example/src/chevre/event/updateSellerMakesOffersByIdentifier.ts +106 -0
- package/example/src/chevre/offerCatalog/updateManyOfferCatalogsByIds.ts +49 -0
- package/example/src/chevre/paymentServices/findPaymentServices.ts +37 -0
- package/example/src/chevre/product/findHasOfferCatalog.ts +31 -0
- package/example/src/chevre/reIndex.ts +2 -3
- package/example/src/chevre/roles/addAdminNotePermissionIfNotExists.ts +48 -0
- package/example/src/chevre/roles/{addAdminProductOfferPermissionIfNotExists.ts → addAdminPaymentServiceReadPermissionIfNotExists.ts} +20 -19
- package/example/src/chevre/roles/addAdminProductHasOfferCatalogReadPermissionIfNotExists.ts +33 -0
- package/example/src/chevre/roles/addAdminSellerEventIfNotExists.ts +48 -0
- package/example/src/chevre/roles/removeConsolePermissionIfExists.ts +1 -1
- package/example/src/chevre/roles/removePermissionIfExists.ts +1 -6
- package/example/src/chevre/unsetUnnecessaryFields.ts +5 -7
- package/example/src/objectId.ts +12 -0
- package/example/src/signPayload.ts +12 -7
- package/lib/chevre/errorHandler.d.ts +6 -2
- package/lib/chevre/errorHandler.js +18 -2
- package/lib/chevre/repo/categoryCode.d.ts +26 -14
- package/lib/chevre/repo/categoryCode.js +53 -42
- package/lib/chevre/repo/event.d.ts +25 -11
- package/lib/chevre/repo/event.js +60 -35
- package/lib/chevre/repo/eventSellerMakesOffer.d.ts +24 -39
- package/lib/chevre/repo/eventSellerMakesOffer.js +88 -43
- package/lib/chevre/repo/issuer.js +9 -5
- package/lib/chevre/repo/mongoose/schemas/categoryCode.js +48 -42
- package/lib/chevre/repo/mongoose/schemas/movieTicketTypes.d.ts +10 -0
- package/lib/chevre/repo/mongoose/schemas/movieTicketTypes.js +107 -0
- package/lib/chevre/repo/mongoose/schemas/product.d.ts +4 -4
- package/lib/chevre/repo/mongoose/schemas/product.js +2 -2
- package/lib/chevre/repo/movieTicketType.d.ts +57 -0
- package/lib/chevre/repo/movieTicketType.js +253 -0
- package/lib/chevre/repo/noteAboutOrder.d.ts +4 -11
- package/lib/chevre/repo/noteAboutOrder.js +16 -4
- package/lib/chevre/repo/offerCatalog.d.ts +17 -2
- package/lib/chevre/repo/offerCatalog.js +5 -2
- package/lib/chevre/repo/productHasOfferCatalog.d.ts +43 -0
- package/lib/chevre/repo/productHasOfferCatalog.js +71 -0
- package/lib/chevre/repository.d.ts +10 -0
- package/lib/chevre/repository.js +28 -2
- package/lib/chevre/service/assetTransaction/reserve/start.js +2 -2
- package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/validateIssuedOfferIfExists.d.ts +15 -0
- package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/validateIssuedOfferIfExists.js +159 -0
- package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/validateMemberTierIfExists.d.ts +16 -0
- package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/validateMemberTierIfExists.js +184 -0
- package/lib/chevre/service/assetTransaction/reserve/validateStartRequest.d.ts +4 -1
- package/lib/chevre/service/assetTransaction/reserve/validateStartRequest.js +25 -139
- package/lib/chevre/service/event.js +1 -1
- package/lib/chevre/service/offer/event/importFromCOA.js +1 -1
- package/lib/chevre/service/offer/eventServiceByCOA/authorize.js +3 -3
- package/lib/chevre/service/offer/eventServiceByCOA/changeOffers.js +3 -3
- package/lib/chevre/service/offer/onEventChanged.js +26 -30
- package/lib/chevre/service/project.d.ts +3 -0
- package/lib/chevre/service/project.js +2 -1
- package/lib/chevre/service/task/onResourceUpdated/syncCategoryCode.js +1 -1
- package/lib/chevre/service/task/onResourceUpdated.js +1 -1
- package/package.json +4 -4
- package/example/src/chevre/aggregateEventSellerMakesOffer.ts +0 -32
- package/example/src/chevre/event/migrateEventIdentifier4ttts.ts +0 -96
- package/example/src/chevre/searchCategoryCodesByAggregate.ts +0 -31
- package/example/src/chevre/searchOfferCatalogItems.ts +0 -59
- package/example/src/chevre/searchPaymentServices.ts +0 -32
- package/example/src/chevre/unsetUnnecessaryFieldsInAction.ts +0 -50
- package/example/src/chevre/unsetUnnecessaryFieldsInTransaction.ts +0 -46
|
@@ -0,0 +1,159 @@
|
|
|
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.validateIssuedOfferIfExists = validateIssuedOfferIfExists;
|
|
13
|
+
const jwt = require("jsonwebtoken");
|
|
14
|
+
const moment = require("moment");
|
|
15
|
+
const factory = require("../../../../factory");
|
|
16
|
+
const NUM_ACCEPTED_OFFERS_MAX_VALUE = 50;
|
|
17
|
+
function verifyOfferToken(params) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
let result;
|
|
20
|
+
const { issuer, secret, token } = params;
|
|
21
|
+
try {
|
|
22
|
+
result = yield new Promise((resolve, reject) => {
|
|
23
|
+
jwt.verify(token, secret, {
|
|
24
|
+
algorithms: ['HS256'],
|
|
25
|
+
issuer
|
|
26
|
+
// ...(Array.isArray(params.audience)) ? { audience: params.audience } : undefined
|
|
27
|
+
}, (err, decoded) => {
|
|
28
|
+
if (err instanceof Error) {
|
|
29
|
+
reject(err);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
resolve(decoded);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
// JWTエラーをハンドリング
|
|
39
|
+
if (error instanceof jwt.TokenExpiredError) {
|
|
40
|
+
throw new factory.errors.Argument('reservationFor.offers.token', `invalid token. [${error.message} expiredAt:${error.expiredAt}]`);
|
|
41
|
+
}
|
|
42
|
+
else if (error instanceof jwt.JsonWebTokenError) {
|
|
43
|
+
throw new factory.errors.Argument('reservationFor.offers.token', `invalid token. [${error.message}]`);
|
|
44
|
+
}
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
return result;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
const OFFER_TOKEN_DATE_FORMAT = 'YYYY-MM-DDTHH:mm:ssZ';
|
|
51
|
+
function validateOfferToken(params) {
|
|
52
|
+
return () => __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
var _a, _b;
|
|
54
|
+
const { event, acceptedDate, verifiedOffer, makesOfferOnApplication } = 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');
|
|
59
|
+
}
|
|
60
|
+
const itemOfferedIdentifierMustBe = event.identifier;
|
|
61
|
+
if (typeof itemOfferedIdentifierMustBe !== 'string') {
|
|
62
|
+
throw new factory.errors.NotFound('identifier', 'the event must have an identifier');
|
|
63
|
+
}
|
|
64
|
+
if (itemOfferedIdentifier !== itemOfferedIdentifierMustBe) {
|
|
65
|
+
throw new factory.errors.Argument('reservationFor.offers.token', 'itemOffered.identifier not matched');
|
|
66
|
+
}
|
|
67
|
+
// アプリケーションオファーコード一致検証
|
|
68
|
+
const applicationOfferIdentifier = verifiedOffer.identifier;
|
|
69
|
+
if (typeof applicationOfferIdentifier !== 'string' || applicationOfferIdentifier === '') {
|
|
70
|
+
throw new factory.errors.Argument('reservationFor.offers.token', 'identifier must be string');
|
|
71
|
+
}
|
|
72
|
+
const applicationOfferIdentifierMustBe = makesOfferOnApplication.identifier;
|
|
73
|
+
if (typeof applicationOfferIdentifierMustBe !== 'string') {
|
|
74
|
+
throw new factory.errors.NotFound('makesOffer.identifier');
|
|
75
|
+
}
|
|
76
|
+
if (applicationOfferIdentifier !== applicationOfferIdentifierMustBe) {
|
|
77
|
+
throw new factory.errors.Argument('reservationFor.offers.token', 'identifier not matched');
|
|
78
|
+
}
|
|
79
|
+
// 有効期間検証
|
|
80
|
+
let validThroughMoment;
|
|
81
|
+
let validFromMoment;
|
|
82
|
+
validThroughMoment = moment(verifiedOffer.validThrough, OFFER_TOKEN_DATE_FORMAT, true);
|
|
83
|
+
validFromMoment = moment(verifiedOffer.validFrom, OFFER_TOKEN_DATE_FORMAT, true);
|
|
84
|
+
if (!validThroughMoment.isValid()) {
|
|
85
|
+
throw new factory.errors.Argument('reservationFor.offers.token', 'invalid validThrough');
|
|
86
|
+
}
|
|
87
|
+
if (!validFromMoment.isValid()) {
|
|
88
|
+
throw new factory.errors.Argument('reservationFor.offers.token', 'invalid validFrom');
|
|
89
|
+
}
|
|
90
|
+
if (acceptedDate.isBefore(validFromMoment)) {
|
|
91
|
+
throw new factory.errors.Argument('reservationFor.offers.token', `the offer id valid from ${validFromMoment}`);
|
|
92
|
+
}
|
|
93
|
+
if (acceptedDate.isAfter(validThroughMoment)) {
|
|
94
|
+
throw new factory.errors.Argument('reservationFor.offers.token', `the offer id valid through ${validThroughMoment}`);
|
|
95
|
+
}
|
|
96
|
+
// maxValueを検証
|
|
97
|
+
const maxValue = (_a = verifiedOffer === null || verifiedOffer === void 0 ? void 0 : verifiedOffer.eligibleQuantity) === null || _a === void 0 ? void 0 : _a.maxValue;
|
|
98
|
+
if (typeof maxValue !== 'number') {
|
|
99
|
+
throw new factory.errors.Argument('reservationFor.offers.token', 'eligibleQuantity.maxValue must be number');
|
|
100
|
+
}
|
|
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}`);
|
|
103
|
+
}
|
|
104
|
+
const numAcceptedOffers = (_b = params.object.acceptedOffer) === null || _b === void 0 ? void 0 : _b.length;
|
|
105
|
+
if (typeof numAcceptedOffers === 'number' && numAcceptedOffers > 0) {
|
|
106
|
+
if (numAcceptedOffers > maxValue) {
|
|
107
|
+
throw new factory.errors.Argument('reservationFor.id', `Maximum number of offers exceeded`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* オファートークン検証(2025-10-21~)
|
|
114
|
+
*/
|
|
115
|
+
function validateIssuedOfferIfExists(params) {
|
|
116
|
+
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
117
|
+
var _a, _b, _c, _d, _e;
|
|
118
|
+
const { event, makesOfferOnApplication } = params;
|
|
119
|
+
const acceptedDate = moment(params.now);
|
|
120
|
+
const offerTokenIssuer = (_a = makesOfferOnApplication.offeredBy) === null || _a === void 0 ? void 0 : _a.identifier;
|
|
121
|
+
const offerTokenRequired = typeof offerTokenIssuer === 'string';
|
|
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');
|
|
127
|
+
}
|
|
128
|
+
if (typeof offerToken !== 'string' || offerToken === '') {
|
|
129
|
+
throw new factory.errors.ArgumentNull('object.reservationFor.offers.token');
|
|
130
|
+
}
|
|
131
|
+
if (typeof makesOfferOnApplication.identifier !== 'string' || makesOfferOnApplication.identifier === '') {
|
|
132
|
+
throw new factory.errors.NotFound('seller.makesOffer.identifier');
|
|
133
|
+
}
|
|
134
|
+
// アプリケーションオファーコード一致検証
|
|
135
|
+
if (makesOfferOnApplication.identifier !== offerIdentifierMustBe) {
|
|
136
|
+
throw new factory.errors.Argument('object.reservationFor.offers.identifier', 'offers.identifier not matched');
|
|
137
|
+
}
|
|
138
|
+
const issuer = yield repos.issuer.findByIdentifier({
|
|
139
|
+
project: { id: event.project.id },
|
|
140
|
+
identifier: offerTokenIssuer
|
|
141
|
+
});
|
|
142
|
+
if (typeof issuer.tokenSecret !== 'string' || issuer.tokenSecret === '') {
|
|
143
|
+
throw new factory.errors.NotFound('issuer.tokenSecret');
|
|
144
|
+
}
|
|
145
|
+
const verifiedOffer = yield verifyOfferToken({
|
|
146
|
+
secret: issuer.tokenSecret,
|
|
147
|
+
issuer: issuer.url,
|
|
148
|
+
token: offerToken
|
|
149
|
+
});
|
|
150
|
+
yield validateOfferToken({
|
|
151
|
+
event,
|
|
152
|
+
acceptedDate,
|
|
153
|
+
verifiedOffer,
|
|
154
|
+
makesOfferOnApplication,
|
|
155
|
+
object: params.object
|
|
156
|
+
})();
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as 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
|
+
object: factory.assetTransaction.reserve.IObjectWithoutDetail;
|
|
10
|
+
makesOfferOnApplication: factory.event.screeningEvent.ISellerMakesOffer;
|
|
11
|
+
}): (repos: {
|
|
12
|
+
issuer: IssuerRepo;
|
|
13
|
+
memberProgram: MemberProgramRepo;
|
|
14
|
+
productOffer: ProductOfferRepo;
|
|
15
|
+
}) => Promise<void>;
|
|
16
|
+
export { validateMemberTierIfExists };
|
|
@@ -0,0 +1,184 @@
|
|
|
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.validateMemberTierIfExists = validateMemberTierIfExists;
|
|
13
|
+
const jwt = require("jsonwebtoken");
|
|
14
|
+
const moment = require("moment");
|
|
15
|
+
const factory = require("../../../../factory");
|
|
16
|
+
function validateMemberTier(params) {
|
|
17
|
+
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
var _a, _b, _c, _d, _e;
|
|
19
|
+
const { acceptedDate, event, verifiedValidForMemberTier, memberProgramIdentifierMustBe, aggregateOfferIdentifier } = params;
|
|
20
|
+
const tierIdentifier = (_b = (_a = verifiedValidForMemberTier.member) === null || _a === void 0 ? void 0 : _a.memberOf) === null || _b === void 0 ? void 0 : _b.identifier;
|
|
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
|
+
if (typeof tierIdentifier !== 'string') {
|
|
23
|
+
throw new factory.errors.Argument('reservationFor.offers.validForMemberTier', 'tier identifier must be string');
|
|
24
|
+
}
|
|
25
|
+
if (typeof memberProgramIdentifier !== 'string') {
|
|
26
|
+
throw new factory.errors.Argument('reservationFor.offers.validForMemberTier', 'member program must be string');
|
|
27
|
+
}
|
|
28
|
+
if (memberProgramIdentifier !== memberProgramIdentifierMustBe) {
|
|
29
|
+
throw new factory.errors.Argument('reservationFor.offers.validForMemberTier', 'member program not matched');
|
|
30
|
+
}
|
|
31
|
+
const sellerId = event.offers.seller.id;
|
|
32
|
+
if (typeof sellerId !== 'string' || sellerId === '') {
|
|
33
|
+
throw new factory.errors.NotFound('event.offers.seller.id');
|
|
34
|
+
}
|
|
35
|
+
// 有効なプロダクトオファーを検証
|
|
36
|
+
const productOfferForMemberTier = (yield repos.productOffer.findProductOffers({
|
|
37
|
+
limit: 1,
|
|
38
|
+
page: 1,
|
|
39
|
+
project: { id: { $eq: event.project.id } },
|
|
40
|
+
// availableAtOrFrom: { id: { $eq: availableAt.id } },
|
|
41
|
+
itemOffered: { identifier: { $eq: aggregateOfferIdentifier } }, // オファーコレクションコード
|
|
42
|
+
validForMemberTier: { identifier: { $eq: tierIdentifier } },
|
|
43
|
+
validFrom: { $lte: acceptedDate.toDate() },
|
|
44
|
+
validThrough: { $gte: acceptedDate.toDate() },
|
|
45
|
+
offeredBy: { id: { $eq: sellerId } } // オファー提供者も検証する
|
|
46
|
+
}, ['identifier'])).shift();
|
|
47
|
+
if (productOfferForMemberTier === undefined) {
|
|
48
|
+
throw new factory.errors.NotFound(factory.offerType.Offer, 'valid product offers for member tier not found');
|
|
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
|
+
});
|
|
67
|
+
}
|
|
68
|
+
function verifyMemberTierToken(params) {
|
|
69
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
let result;
|
|
71
|
+
const { issuer, secret, token } = params;
|
|
72
|
+
try {
|
|
73
|
+
result = yield new Promise((resolve, reject) => {
|
|
74
|
+
jwt.verify(token, secret, {
|
|
75
|
+
algorithms: ['HS256'],
|
|
76
|
+
issuer
|
|
77
|
+
// ...(Array.isArray(params.audience)) ? { audience: params.audience } : undefined
|
|
78
|
+
}, (err, decoded) => {
|
|
79
|
+
if (err instanceof Error) {
|
|
80
|
+
reject(err);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
resolve(decoded);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
// JWTエラーをハンドリング
|
|
90
|
+
if (error instanceof jwt.TokenExpiredError) {
|
|
91
|
+
throw new factory.errors.Argument('reservationFor.offers.validForMemberTier', `invalid token. [${error.message} expiredAt:${error.expiredAt}]`);
|
|
92
|
+
}
|
|
93
|
+
else if (error instanceof jwt.JsonWebTokenError) {
|
|
94
|
+
throw new factory.errors.Argument('reservationFor.offers.validForMemberTier', `invalid token. [${error.message}]`);
|
|
95
|
+
}
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
98
|
+
return result;
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
function validateMemberTierIfExists(params) {
|
|
102
|
+
// tslint:disable-next-line:cyclomatic-complexity max-func-body-length
|
|
103
|
+
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
var _a, _b, _c, _d;
|
|
105
|
+
const { event, makesOfferOnApplication } = params;
|
|
106
|
+
const acceptedDate = moment(params.now);
|
|
107
|
+
const eventOffers = event.offers;
|
|
108
|
+
// 有効メンバープログラムティアが存在する場合
|
|
109
|
+
// support validForMemberTier(2025-05-14~)
|
|
110
|
+
const validForMemberTierExists = ((_a = makesOfferOnApplication.validForMemberTier) === null || _a === void 0 ? void 0 : _a.typeOf) === 'MemberProgramTier';
|
|
111
|
+
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;
|
|
113
|
+
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;
|
|
115
|
+
// ティアトークンが必須
|
|
116
|
+
if (typeof validForMemberTierToken !== 'string' || validForMemberTierToken === '') {
|
|
117
|
+
throw new factory.errors.ArgumentNull('reservationFor.offers.validForMemberTier.token');
|
|
118
|
+
}
|
|
119
|
+
// メンバープログラムコード指定が必須
|
|
120
|
+
if (typeof memberProgramIdentifierMustBe !== 'string' || memberProgramIdentifierMustBe === '') {
|
|
121
|
+
throw new factory.errors.ArgumentNull('reservationFor.offers.validForMemberTier.isTierOf.identifier');
|
|
122
|
+
}
|
|
123
|
+
// 有効メンバープログラムティアが存在する場合、オファーコレクションコードが必須
|
|
124
|
+
const aggregateOfferIdentifier = eventOffers.identifier;
|
|
125
|
+
if (typeof aggregateOfferIdentifier !== 'string' || aggregateOfferIdentifier === '') {
|
|
126
|
+
throw new factory.errors.NotFound('makesOfferOnApplication.identifier');
|
|
127
|
+
}
|
|
128
|
+
// トークン検証
|
|
129
|
+
const memberProgram = (yield repos.memberProgram.projectMemberPrograms({
|
|
130
|
+
limit: 1,
|
|
131
|
+
page: 1,
|
|
132
|
+
project: { id: { $eq: params.event.project.id } },
|
|
133
|
+
identifier: { $eq: memberProgramIdentifierMustBe }
|
|
134
|
+
})).shift();
|
|
135
|
+
if (memberProgram === undefined) {
|
|
136
|
+
throw new factory.errors.NotFound('MemberProgram', `MemberProgram '${memberProgramIdentifierMustBe}' not found`);
|
|
137
|
+
}
|
|
138
|
+
const issuer = yield repos.issuer.findByIdentifier({
|
|
139
|
+
project: { id: params.event.project.id },
|
|
140
|
+
identifier: memberProgram.hostingOrganization.identifier
|
|
141
|
+
});
|
|
142
|
+
if (typeof issuer.tokenSecret !== 'string' || issuer.tokenSecret === '') {
|
|
143
|
+
throw new factory.errors.NotFound('issuer.tokenSecret');
|
|
144
|
+
}
|
|
145
|
+
const verifiedValidForMemberTier = yield verifyMemberTierToken({
|
|
146
|
+
secret: issuer.tokenSecret,
|
|
147
|
+
issuer: issuer.url,
|
|
148
|
+
token: validForMemberTierToken
|
|
149
|
+
});
|
|
150
|
+
yield validateMemberTier({
|
|
151
|
+
event, acceptedDate, verifiedValidForMemberTier,
|
|
152
|
+
memberProgramIdentifierMustBe, aggregateOfferIdentifier
|
|
153
|
+
})(repos);
|
|
154
|
+
}
|
|
155
|
+
// tslint:disable-next-line:no-suspicious-comment
|
|
156
|
+
// TODO オファートークン検証(2025-10-21~)
|
|
157
|
+
// const offerTokenIssuer = makesOfferOnApplication.issuedBy?.identifier;
|
|
158
|
+
// const offerTokenRequired = typeof offerTokenIssuer === 'string';
|
|
159
|
+
// if (offerTokenRequired) {
|
|
160
|
+
// const offerToken = params.object.reservationFor?.offers?.token;
|
|
161
|
+
// if (typeof offerToken !== 'string' || offerToken === '') {
|
|
162
|
+
// throw new factory.errors.ArgumentNull('object.reservationFor.offers.token');
|
|
163
|
+
// }
|
|
164
|
+
// const issuer = await repos.issuer.findByIdentifier({
|
|
165
|
+
// project: { id: params.event.project.id },
|
|
166
|
+
// identifier: offerTokenIssuer
|
|
167
|
+
// });
|
|
168
|
+
// if (typeof issuer.tokenSecret !== 'string' || issuer.tokenSecret === '') {
|
|
169
|
+
// throw new factory.errors.NotFound('issuer.tokenSecret');
|
|
170
|
+
// }
|
|
171
|
+
// const verifiedOffer = await verifyOfferToken({
|
|
172
|
+
// secret: issuer.tokenSecret,
|
|
173
|
+
// issuer: issuer.url,
|
|
174
|
+
// token: offerToken
|
|
175
|
+
// });
|
|
176
|
+
// await validateOfferToken({
|
|
177
|
+
// acceptedDate,
|
|
178
|
+
// verifiedOffer,
|
|
179
|
+
// makesOfferOnApplication,
|
|
180
|
+
// object: params.object
|
|
181
|
+
// })();
|
|
182
|
+
// }
|
|
183
|
+
});
|
|
184
|
+
}
|
|
@@ -5,7 +5,10 @@ import type { MemberProgramRepo } from '../../../repo/memberProgram';
|
|
|
5
5
|
import type { ProductOfferRepo } from '../../../repo/productOffer';
|
|
6
6
|
declare function validateStartRequest(params: {
|
|
7
7
|
object: factory.assetTransaction.reserve.IObjectWithoutDetail;
|
|
8
|
-
event: Pick<IMinimizedIndividualEvent, 'offers' | 'id' | 'project'>;
|
|
8
|
+
event: Pick<IMinimizedIndividualEvent, 'offers' | 'id' | 'project' | 'identifier'>;
|
|
9
|
+
/**
|
|
10
|
+
* アプリケーションごとのオファーを検証するかどうか
|
|
11
|
+
*/
|
|
9
12
|
validateEventOfferPeriod?: boolean;
|
|
10
13
|
validateEvent?: boolean;
|
|
11
14
|
now: Date;
|
|
@@ -10,119 +10,37 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.validateStartRequest = validateStartRequest;
|
|
13
|
-
const jwt = require("jsonwebtoken");
|
|
14
13
|
const moment = require("moment");
|
|
15
14
|
const factory = require("../../../factory");
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
let result;
|
|
19
|
-
const { issuer, secret, token } = params;
|
|
20
|
-
try {
|
|
21
|
-
result = yield new Promise((resolve, reject) => {
|
|
22
|
-
jwt.verify(token, secret, {
|
|
23
|
-
algorithms: ['HS256'],
|
|
24
|
-
issuer
|
|
25
|
-
// ...(Array.isArray(params.audience)) ? { audience: params.audience } : undefined
|
|
26
|
-
}, (err, decoded) => {
|
|
27
|
-
if (err instanceof Error) {
|
|
28
|
-
reject(err);
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
resolve(decoded);
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
catch (error) {
|
|
37
|
-
// JWTエラーをハンドリング
|
|
38
|
-
if (error instanceof jwt.TokenExpiredError) {
|
|
39
|
-
throw new factory.errors.Argument('memberOfToken', `invalid token. [${error.message} expiredAt:${error.expiredAt}]`);
|
|
40
|
-
}
|
|
41
|
-
else if (error instanceof jwt.JsonWebTokenError) {
|
|
42
|
-
throw new factory.errors.Argument('memberOfToken', `invalid token. [${error.message}]`);
|
|
43
|
-
}
|
|
44
|
-
throw error;
|
|
45
|
-
}
|
|
46
|
-
return result;
|
|
47
|
-
});
|
|
48
|
-
}
|
|
15
|
+
const validateIssuedOfferIfExists_1 = require("./validateStartRequest/validateIssuedOfferIfExists");
|
|
16
|
+
const validateMemberTierIfExists_1 = require("./validateStartRequest/validateMemberTierIfExists");
|
|
49
17
|
function validateStartRequest(params) {
|
|
50
18
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
51
|
-
var _a
|
|
19
|
+
var _a;
|
|
52
20
|
const now = params.now;
|
|
53
21
|
const event = params.event;
|
|
54
22
|
if (params.validateEventOfferPeriod === true) {
|
|
55
23
|
if (typeof ((_a = params.store) === null || _a === void 0 ? void 0 : _a.id) !== 'string') {
|
|
56
24
|
throw new factory.errors.NotFound('store.id');
|
|
57
25
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
now,
|
|
26
|
+
yield validateApplicationOffer({
|
|
27
|
+
event,
|
|
28
|
+
now,
|
|
29
|
+
availableAt: { id: params.store.id },
|
|
30
|
+
object: params.object
|
|
31
|
+
})(repos);
|
|
61
32
|
}
|
|
62
33
|
if (params.validateEvent === true) {
|
|
63
34
|
validateEvent({ event, object: params.object });
|
|
64
35
|
}
|
|
65
36
|
});
|
|
66
37
|
}
|
|
67
|
-
function validateMemberTier(params) {
|
|
68
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
69
|
-
var _a, _b, _c, _d, _e;
|
|
70
|
-
const { acceptedDate, event, verifiedValidForMemberTier, memberProgramIdentifierMustBe, aggregateOfferIdentifier } = params;
|
|
71
|
-
const tierIdentifier = (_b = (_a = verifiedValidForMemberTier.member) === null || _a === void 0 ? void 0 : _a.memberOf) === null || _b === void 0 ? void 0 : _b.identifier;
|
|
72
|
-
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;
|
|
73
|
-
if (typeof tierIdentifier !== 'string') {
|
|
74
|
-
throw new factory.errors.Argument('reservationFor.offers.validForMemberTier', 'tier identifier must be string');
|
|
75
|
-
}
|
|
76
|
-
if (typeof memberProgramIdentifier !== 'string') {
|
|
77
|
-
throw new factory.errors.Argument('reservationFor.offers.validForMemberTier', 'member program must be string');
|
|
78
|
-
}
|
|
79
|
-
if (memberProgramIdentifier !== memberProgramIdentifierMustBe) {
|
|
80
|
-
throw new factory.errors.Argument('reservationFor.offers.validForMemberTier', 'member program not matched');
|
|
81
|
-
}
|
|
82
|
-
const sellerId = event.offers.seller.id;
|
|
83
|
-
if (typeof sellerId !== 'string' || sellerId === '') {
|
|
84
|
-
throw new factory.errors.NotFound('event.offers.seller.id');
|
|
85
|
-
}
|
|
86
|
-
// 有効なプロダクトオファーを検証
|
|
87
|
-
const productOfferForMemberTier = (yield repos.productOffer.findProductOffers({
|
|
88
|
-
limit: 1,
|
|
89
|
-
page: 1,
|
|
90
|
-
project: { id: { $eq: event.project.id } },
|
|
91
|
-
// availableAtOrFrom: { id: { $eq: availableAt.id } },
|
|
92
|
-
itemOffered: { identifier: { $eq: aggregateOfferIdentifier } }, // オファーコレクションコード
|
|
93
|
-
validForMemberTier: { identifier: { $eq: tierIdentifier } },
|
|
94
|
-
validFrom: { $lte: acceptedDate.toDate() },
|
|
95
|
-
validThrough: { $gte: acceptedDate.toDate() },
|
|
96
|
-
offeredBy: { id: { $eq: sellerId } } // オファー提供者も検証する
|
|
97
|
-
}, ['identifier'])).shift();
|
|
98
|
-
if (productOfferForMemberTier === undefined) {
|
|
99
|
-
throw new factory.errors.NotFound(factory.offerType.Offer, 'valid product offers for member tier not found');
|
|
100
|
-
}
|
|
101
|
-
// let validThroughMoment: moment.Moment;
|
|
102
|
-
// let validFromMoment: moment.Moment;
|
|
103
|
-
// validThroughMoment = moment(productOfferForMemberTier.validThrough, ROLE_DATE_FORMAT, true);
|
|
104
|
-
// validFromMoment = moment(productOfferForMemberTier.validFrom, ROLE_DATE_FORMAT, true);
|
|
105
|
-
// if (acceptedDate.isBefore(validFromMoment)) {
|
|
106
|
-
// throw new factory.errors.Argument(
|
|
107
|
-
// 'reservationFor.offers.validForMemberTier',
|
|
108
|
-
// `the offer id valid from ${validFromMoment}`
|
|
109
|
-
// );
|
|
110
|
-
// }
|
|
111
|
-
// if (acceptedDate.isAfter(validThroughMoment)) {
|
|
112
|
-
// throw new factory.errors.Argument(
|
|
113
|
-
// 'reservationFor.offers.validForMemberTier',
|
|
114
|
-
// `the offer id valid through ${validThroughMoment}`
|
|
115
|
-
// );
|
|
116
|
-
// }
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
38
|
/**
|
|
120
|
-
*
|
|
39
|
+
* アプリケーションごとのオファーを検証する
|
|
121
40
|
*/
|
|
122
|
-
function
|
|
41
|
+
function validateApplicationOffer(params) {
|
|
123
42
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
124
|
-
|
|
125
|
-
const { event, availableAt, tokenizedMemberProgramTier } = params;
|
|
43
|
+
const { event, availableAt } = params;
|
|
126
44
|
const acceptedDate = moment(params.now);
|
|
127
45
|
const eventOffers = event.offers;
|
|
128
46
|
// アプリケーションごとの設定を参照する(2022-11-19~)
|
|
@@ -150,51 +68,19 @@ function validateEventOfferPeriod(params) {
|
|
|
150
68
|
}
|
|
151
69
|
}
|
|
152
70
|
// 有効メンバープログラムティアが存在する場合
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
// 有効メンバープログラムティアが存在する場合、オファーコレクションコードが必須
|
|
167
|
-
const aggregateOfferIdentifier = eventOffers.identifier;
|
|
168
|
-
if (typeof aggregateOfferIdentifier !== 'string' || aggregateOfferIdentifier === '') {
|
|
169
|
-
throw new factory.errors.NotFound('makesOfferOnApplication.identifier');
|
|
170
|
-
}
|
|
171
|
-
// トークン検証
|
|
172
|
-
const memberProgram = (yield repos.memberProgram.projectMemberPrograms({
|
|
173
|
-
limit: 1,
|
|
174
|
-
page: 1,
|
|
175
|
-
project: { id: { $eq: params.event.project.id } },
|
|
176
|
-
identifier: { $eq: memberProgramIdentifierMustBe }
|
|
177
|
-
})).shift();
|
|
178
|
-
if (memberProgram === undefined) {
|
|
179
|
-
throw new factory.errors.NotFound('MemberProgram', `MemberProgram '${memberProgramIdentifierMustBe}' not found`);
|
|
180
|
-
}
|
|
181
|
-
const issuer = yield repos.issuer.findByIdentifier({
|
|
182
|
-
project: { id: params.event.project.id },
|
|
183
|
-
identifier: memberProgram.hostingOrganization.identifier
|
|
184
|
-
});
|
|
185
|
-
if (typeof issuer.tokenSecret !== 'string' || issuer.tokenSecret === '') {
|
|
186
|
-
throw new factory.errors.NotFound('issuer.tokenSecret');
|
|
187
|
-
}
|
|
188
|
-
const verifiedValidForMemberTier = yield verifyOfferedByToken({
|
|
189
|
-
secret: issuer.tokenSecret,
|
|
190
|
-
issuer: issuer.url,
|
|
191
|
-
token: validForMemberTierToken
|
|
192
|
-
});
|
|
193
|
-
yield validateMemberTier({
|
|
194
|
-
event, acceptedDate, verifiedValidForMemberTier,
|
|
195
|
-
memberProgramIdentifierMustBe, aggregateOfferIdentifier
|
|
196
|
-
})(repos);
|
|
197
|
-
}
|
|
71
|
+
yield (0, validateMemberTierIfExists_1.validateMemberTierIfExists)({
|
|
72
|
+
event,
|
|
73
|
+
now: params.now,
|
|
74
|
+
object: params.object,
|
|
75
|
+
makesOfferOnApplication
|
|
76
|
+
})(repos);
|
|
77
|
+
// オファートークン検証(2025-10-21~)
|
|
78
|
+
yield (0, validateIssuedOfferIfExists_1.validateIssuedOfferIfExists)({
|
|
79
|
+
event,
|
|
80
|
+
now: params.now,
|
|
81
|
+
object: params.object,
|
|
82
|
+
makesOfferOnApplication
|
|
83
|
+
})(repos);
|
|
198
84
|
});
|
|
199
85
|
}
|
|
200
86
|
/**
|
|
@@ -239,7 +239,7 @@ function saveScreeningEventSeries(params) {
|
|
|
239
239
|
kubunClass: '043'
|
|
240
240
|
});
|
|
241
241
|
debug('kubunNames found.');
|
|
242
|
-
const availablePaymentMethodTypes = yield repos.categoryCode.
|
|
242
|
+
const availablePaymentMethodTypes = yield repos.categoryCode.projectCategoryCodeFields({
|
|
243
243
|
project: { id: { $eq: params.project.id } },
|
|
244
244
|
inCodeSet: { identifier: { $eq: factory.categoryCode.CategorySetIdentifier.PaymentMethodType } }
|
|
245
245
|
}, ['additionalProperty', 'codeValue']);
|
|
@@ -117,7 +117,7 @@ function importCategoryCodesFromCOA(params) {
|
|
|
117
117
|
upsert: true
|
|
118
118
|
});
|
|
119
119
|
});
|
|
120
|
-
yield repos.categoryCode.
|
|
120
|
+
yield repos.categoryCode.saveCategoryCodesByCodeValue(saveParams);
|
|
121
121
|
}
|
|
122
122
|
catch (error) {
|
|
123
123
|
let throwsError = true;
|
|
@@ -53,15 +53,15 @@ function authorize(params) {
|
|
|
53
53
|
'superEvent', 'typeOf', 'identifier', 'name'
|
|
54
54
|
] // optimize(2024-07-18~)
|
|
55
55
|
);
|
|
56
|
-
const availablePaymentMethodTypes = yield repos.categoryCode.
|
|
56
|
+
const availablePaymentMethodTypes = yield repos.categoryCode.projectCategoryCodeFields({
|
|
57
57
|
project: { id: { $eq: transaction.project.id } },
|
|
58
58
|
inCodeSet: { identifier: { $eq: factory.categoryCode.CategorySetIdentifier.PaymentMethodType } }
|
|
59
59
|
}, []);
|
|
60
|
-
const seatingTypes = yield repos.categoryCode.
|
|
60
|
+
const seatingTypes = yield repos.categoryCode.projectCategoryCodeFields({
|
|
61
61
|
project: { id: { $eq: transaction.project.id } },
|
|
62
62
|
inCodeSet: { identifier: { $eq: factory.categoryCode.CategorySetIdentifier.SeatingType } }
|
|
63
63
|
}, []);
|
|
64
|
-
const videoFormatTypes = yield repos.categoryCode.
|
|
64
|
+
const videoFormatTypes = yield repos.categoryCode.projectCategoryCodeFields({
|
|
65
65
|
project: { id: { $eq: transaction.project.id } },
|
|
66
66
|
inCodeSet: { identifier: { $eq: factory.categoryCode.CategorySetIdentifier.VideoFormatType } }
|
|
67
67
|
}, []);
|
|
@@ -79,15 +79,15 @@ function changeOffers(params) {
|
|
|
79
79
|
'superEvent', 'typeOf', 'identifier', 'name'
|
|
80
80
|
] // optimize(2024-07-18~)
|
|
81
81
|
);
|
|
82
|
-
const availablePaymentMethodTypes = yield repos.categoryCode.
|
|
82
|
+
const availablePaymentMethodTypes = yield repos.categoryCode.projectCategoryCodeFields({
|
|
83
83
|
project: { id: { $eq: transaction.project.id } },
|
|
84
84
|
inCodeSet: { identifier: { $eq: factory.categoryCode.CategorySetIdentifier.PaymentMethodType } }
|
|
85
85
|
}, []);
|
|
86
|
-
const seatingTypes = yield repos.categoryCode.
|
|
86
|
+
const seatingTypes = yield repos.categoryCode.projectCategoryCodeFields({
|
|
87
87
|
project: { id: { $eq: transaction.project.id } },
|
|
88
88
|
inCodeSet: { identifier: { $eq: factory.categoryCode.CategorySetIdentifier.SeatingType } }
|
|
89
89
|
}, []);
|
|
90
|
-
const videoFormatTypes = yield repos.categoryCode.
|
|
90
|
+
const videoFormatTypes = yield repos.categoryCode.projectCategoryCodeFields({
|
|
91
91
|
project: { id: { $eq: transaction.project.id } },
|
|
92
92
|
inCodeSet: { identifier: { $eq: factory.categoryCode.CategorySetIdentifier.VideoFormatType } }
|
|
93
93
|
}, []);
|