@chevre/domain 23.1.0-alpha.12 → 23.1.0-alpha.14
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/eventOffer/publishEventOfferToken.ts +98 -0
- package/lib/chevre/repo/event.js +2 -3
- package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/validateIssuedOfferIfExists.js +12 -12
- package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/validateMemberTierIfExists.js +0 -28
- package/package.json +3 -3
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import { sign } from 'jsonwebtoken';
|
|
3
|
+
import * as moment from 'moment';
|
|
4
|
+
import * as mongoose from 'mongoose';
|
|
5
|
+
|
|
6
|
+
import { chevre } from '../../../../lib/index';
|
|
7
|
+
|
|
8
|
+
const project = { id: String(process.env.PROJECT_ID) };
|
|
9
|
+
|
|
10
|
+
async function main() {
|
|
11
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
12
|
+
|
|
13
|
+
const eventOfferRepo = await chevre.repository.EventOffer.createInstance(mongoose.connection);
|
|
14
|
+
const issuerRepo = await chevre.repository.Issuer.createInstance(mongoose.connection);
|
|
15
|
+
|
|
16
|
+
const eventOffer = (await eventOfferRepo.findEventOffers(
|
|
17
|
+
{
|
|
18
|
+
limit: 1,
|
|
19
|
+
page: 1,
|
|
20
|
+
project: { id: { $eq: project.id } },
|
|
21
|
+
id: { $eq: '691e5bb3929e69df1ec6e9a6' }
|
|
22
|
+
},
|
|
23
|
+
['offeredBy', 'identifier', 'itemOffered']
|
|
24
|
+
)).shift();
|
|
25
|
+
if (eventOffer === undefined) {
|
|
26
|
+
throw new chevre.factory.errors.NotFound(chevre.factory.offerType.Offer);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const issuerIdentifier = eventOffer.offeredBy?.identifier;
|
|
30
|
+
if (typeof issuerIdentifier !== 'string') {
|
|
31
|
+
throw new chevre.factory.errors.NotFound('eventOffer.offeredBy?.identifier');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// const tier = (await memberProgramRepo.projectMemberProgramTiers(
|
|
35
|
+
// {
|
|
36
|
+
// limit: 1,
|
|
37
|
+
// page: 1,
|
|
38
|
+
// project: { id: { $eq: project.id } },
|
|
39
|
+
// identifier: { $eq: tierIdentifier }
|
|
40
|
+
// }
|
|
41
|
+
// )).shift();
|
|
42
|
+
// if (tier === undefined) {
|
|
43
|
+
// throw new chevre.factory.errors.NotFound('MemberProgramTier');
|
|
44
|
+
// }
|
|
45
|
+
|
|
46
|
+
const { url, tokenSecret } = await issuerRepo.findByIdentifier({
|
|
47
|
+
identifier: issuerIdentifier,
|
|
48
|
+
project: { id: project.id }
|
|
49
|
+
});
|
|
50
|
+
if (typeof tokenSecret !== 'string') {
|
|
51
|
+
throw new chevre.factory.errors.NotFound('issuer.tokenSecret');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const payload: chevre.factory.assetTransaction.reserve.IEventOfferTokenPayload = {
|
|
55
|
+
identifier: eventOffer.identifier,
|
|
56
|
+
validFrom: moment()
|
|
57
|
+
.format('YYYY-MM-DDTHH:mm:ssZ'),
|
|
58
|
+
validThrough: moment()
|
|
59
|
+
.add(1, 'hour')
|
|
60
|
+
.format('YYYY-MM-DDTHH:mm:ssZ'),
|
|
61
|
+
eligibleQuantity: {
|
|
62
|
+
maxValue: 1
|
|
63
|
+
},
|
|
64
|
+
itemOffered: {
|
|
65
|
+
id: 'xxx'
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const token = await new Promise<string>((resolve, reject) => {
|
|
70
|
+
// 所有権を暗号化する
|
|
71
|
+
sign(
|
|
72
|
+
payload,
|
|
73
|
+
tokenSecret,
|
|
74
|
+
{
|
|
75
|
+
// algorithm: jwtSetting.algorithm,
|
|
76
|
+
issuer: url,
|
|
77
|
+
expiresIn: 1800
|
|
78
|
+
// subject,
|
|
79
|
+
},
|
|
80
|
+
(err, encoded) => {
|
|
81
|
+
if (err instanceof Error) {
|
|
82
|
+
reject(err);
|
|
83
|
+
} else {
|
|
84
|
+
if (typeof encoded !== 'string') {
|
|
85
|
+
reject(new Error('cannot be signed unexpectedly'));
|
|
86
|
+
} else {
|
|
87
|
+
resolve(encoded);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
);
|
|
92
|
+
});
|
|
93
|
+
console.log(token);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
main()
|
|
97
|
+
.then()
|
|
98
|
+
.catch(console.error);
|
package/lib/chevre/repo/event.js
CHANGED
|
@@ -22,13 +22,11 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
23
|
exports.EventRepo = void 0;
|
|
24
24
|
const mongoose_1 = require("mongoose");
|
|
25
|
-
const uniqid = require("uniqid");
|
|
26
25
|
const errorHandler_1 = require("../errorHandler");
|
|
27
26
|
const factory = require("../factory");
|
|
28
27
|
const EventFactory = require("../factory/event");
|
|
29
28
|
const settings_1 = require("../settings");
|
|
30
29
|
const event_1 = require("./mongoose/schemas/event");
|
|
31
|
-
const USE_OBJECT_ID_AS_EVENT_ID = process.env.USE_OBJECT_ID_AS_EVENT_ID === '1';
|
|
32
30
|
const AVAILABLE_PUBLIC_PROJECT_FIELDS = [
|
|
33
31
|
'additionalProperty', 'aggregateReservation', 'attendeeCount', 'checkInCount', 'coaInfo',
|
|
34
32
|
// 'description',
|
|
@@ -49,7 +47,8 @@ class EventRepo {
|
|
|
49
47
|
*/
|
|
50
48
|
static CREATE_ID() {
|
|
51
49
|
// implement using ObjectId(2025-10-17~)
|
|
52
|
-
return (USE_OBJECT_ID_AS_EVENT_ID) ? new
|
|
50
|
+
// return (USE_OBJECT_ID_AS_EVENT_ID) ? new Types.ObjectId().toHexString() : uniqid();
|
|
51
|
+
return new mongoose_1.Types.ObjectId().toHexString(); // 設定を廃止(2025-11-20~)
|
|
53
52
|
}
|
|
54
53
|
// tslint:disable-next-line:cyclomatic-complexity max-func-body-length
|
|
55
54
|
static CREATE_MONGO_CONDITIONS(conditions) {
|
|
@@ -50,21 +50,21 @@ function verifyOfferToken(params) {
|
|
|
50
50
|
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
|
-
var _a;
|
|
53
|
+
var _a, _b;
|
|
54
54
|
const { event, acceptedDate, verifiedOffer, eventOffer, numAcceptedOffers } = params;
|
|
55
|
-
//
|
|
56
|
-
const
|
|
57
|
-
if (typeof
|
|
58
|
-
throw new factory.errors.Argument('ticketedOffer.token', 'itemOffered.
|
|
55
|
+
// イベントID一致検証
|
|
56
|
+
const itemOfferedId = (_a = verifiedOffer.itemOffered) === null || _a === void 0 ? void 0 : _a.id;
|
|
57
|
+
if (typeof itemOfferedId !== 'string' || itemOfferedId === '') {
|
|
58
|
+
throw new factory.errors.Argument('ticketedOffer.token', 'itemOffered.id must be string');
|
|
59
59
|
}
|
|
60
|
-
const
|
|
61
|
-
if (typeof
|
|
62
|
-
throw new factory.errors.NotFound('
|
|
60
|
+
const itemOfferedIdMustBe = event.id;
|
|
61
|
+
if (typeof itemOfferedIdMustBe !== 'string') {
|
|
62
|
+
throw new factory.errors.NotFound('event.id', 'the event must have an ID');
|
|
63
63
|
}
|
|
64
|
-
if (
|
|
65
|
-
throw new factory.errors.Argument('ticketedOffer.token', 'itemOffered.
|
|
64
|
+
if (itemOfferedId !== itemOfferedIdMustBe) {
|
|
65
|
+
throw new factory.errors.Argument('ticketedOffer.token', 'itemOffered.id not matched');
|
|
66
66
|
}
|
|
67
|
-
//
|
|
67
|
+
// オファーコード一致検証
|
|
68
68
|
const applicationOfferIdentifier = verifiedOffer.identifier;
|
|
69
69
|
if (typeof applicationOfferIdentifier !== 'string' || applicationOfferIdentifier === '') {
|
|
70
70
|
throw new factory.errors.Argument('ticketedOffer.token', 'identifier must be string');
|
|
@@ -94,7 +94,7 @@ function validateOfferToken(params) {
|
|
|
94
94
|
throw new factory.errors.Argument('ticketedOffer.token', `the offer id valid through ${validThroughMoment}`);
|
|
95
95
|
}
|
|
96
96
|
// maxValueを検証
|
|
97
|
-
const maxValue = (
|
|
97
|
+
const maxValue = (_b = verifiedOffer === null || verifiedOffer === void 0 ? void 0 : verifiedOffer.eligibleQuantity) === null || _b === void 0 ? void 0 : _b.maxValue;
|
|
98
98
|
if (typeof maxValue !== 'number') {
|
|
99
99
|
throw new factory.errors.Argument('ticketedOffer.token', 'eligibleQuantity.maxValue must be number');
|
|
100
100
|
}
|
|
@@ -136,33 +136,5 @@ function validateMemberTierIfExists(params) {
|
|
|
136
136
|
memberProgramIdentifierMustBe, aggregateOfferIdentifier
|
|
137
137
|
})(repos);
|
|
138
138
|
}
|
|
139
|
-
// tslint:disable-next-line:no-suspicious-comment
|
|
140
|
-
// TODO オファートークン検証(2025-10-21~)
|
|
141
|
-
// const offerTokenIssuer = makesOfferOnApplication.issuedBy?.identifier;
|
|
142
|
-
// const offerTokenRequired = typeof offerTokenIssuer === 'string';
|
|
143
|
-
// if (offerTokenRequired) {
|
|
144
|
-
// const offerToken = params.object.reservationFor?.offers?.token;
|
|
145
|
-
// if (typeof offerToken !== 'string' || offerToken === '') {
|
|
146
|
-
// throw new factory.errors.ArgumentNull('object.reservationFor.offers.token');
|
|
147
|
-
// }
|
|
148
|
-
// const issuer = await repos.issuer.findByIdentifier({
|
|
149
|
-
// project: { id: params.event.project.id },
|
|
150
|
-
// identifier: offerTokenIssuer
|
|
151
|
-
// });
|
|
152
|
-
// if (typeof issuer.tokenSecret !== 'string' || issuer.tokenSecret === '') {
|
|
153
|
-
// throw new factory.errors.NotFound('issuer.tokenSecret');
|
|
154
|
-
// }
|
|
155
|
-
// const verifiedOffer = await verifyOfferToken({
|
|
156
|
-
// secret: issuer.tokenSecret,
|
|
157
|
-
// issuer: issuer.url,
|
|
158
|
-
// token: offerToken
|
|
159
|
-
// });
|
|
160
|
-
// await validateOfferToken({
|
|
161
|
-
// acceptedDate,
|
|
162
|
-
// verifiedOffer,
|
|
163
|
-
// makesOfferOnApplication,
|
|
164
|
-
// object: params.object
|
|
165
|
-
// })();
|
|
166
|
-
// }
|
|
167
139
|
});
|
|
168
140
|
}
|
package/package.json
CHANGED
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@aws-sdk/client-cognito-identity-provider": "3.600.0",
|
|
13
13
|
"@aws-sdk/credential-providers": "3.600.0",
|
|
14
|
-
"@chevre/factory": "5.
|
|
15
|
-
"@cinerino/sdk": "12.
|
|
14
|
+
"@chevre/factory": "5.3.0-alpha.0",
|
|
15
|
+
"@cinerino/sdk": "12.9.0-alpha.0",
|
|
16
16
|
"@motionpicture/coa-service": "9.6.0",
|
|
17
17
|
"@motionpicture/gmo-service": "5.4.0-alpha.1",
|
|
18
18
|
"@sendgrid/client": "8.1.4",
|
|
@@ -115,5 +115,5 @@
|
|
|
115
115
|
"postversion": "git push origin --tags",
|
|
116
116
|
"prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
|
|
117
117
|
},
|
|
118
|
-
"version": "23.1.0-alpha.
|
|
118
|
+
"version": "23.1.0-alpha.14"
|
|
119
119
|
}
|