@chevre/domain 23.1.0-alpha.13 → 23.1.0-alpha.15

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.
@@ -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);
@@ -16,9 +16,10 @@ export declare class AuthorizationRepo {
16
16
  constructor(connection: Connection);
17
17
  static CREATE_MONGO_CONDITIONS(params: factory.authorization.ISearchConditions): FilterQuery<factory.authorization.IAuthorization>[];
18
18
  /**
19
- * コードを発行する
19
+ * 承認を発行する
20
+ * コードが自動生成されます
20
21
  */
21
- publish(params: IPublishParams[]): Promise<factory.authorization.IAuthorization[]>;
22
+ issueAuthorization(params: IPublishParams[]): Promise<factory.authorization.IAuthorization[]>;
22
23
  /**
23
24
  * コードで有効な承認を参照する
24
25
  */
@@ -111,9 +111,10 @@ class AuthorizationRepo {
111
111
  return andConditions;
112
112
  }
113
113
  /**
114
- * コードを発行する
114
+ * 承認を発行する
115
+ * コードが自動生成されます
115
116
  */
116
- publish(params) {
117
+ issueAuthorization(params) {
117
118
  return __awaiter(this, void 0, void 0, function* () {
118
119
  const saveParams = params.map(({ project, object, validFrom, expiresInSeconds, audience, author, issuedBy }) => {
119
120
  const code = uuid.v4();
@@ -144,7 +145,7 @@ class AuthorizationRepo {
144
145
  throw new factory.errors.NotFound(this.authorizationModel.modelName);
145
146
  }
146
147
  const { id, object, typeOf, audience, issuedBy } = doc;
147
- return Object.assign(Object.assign({ id, object, typeOf }, (typeof (issuedBy === null || issuedBy === void 0 ? void 0 : issuedBy.id) === 'string') ? { issuedBy } : undefined), (typeof (audience === null || audience === void 0 ? void 0 : audience.id) === 'string') ? { audience } : undefined);
148
+ return Object.assign({ id, object, typeOf, issuedBy }, (typeof (audience === null || audience === void 0 ? void 0 : audience.id) === 'string') ? { audience } : undefined);
148
149
  });
149
150
  }
150
151
  /**
@@ -217,14 +218,21 @@ class AuthorizationRepo {
217
218
  return __awaiter(this, void 0, void 0, function* () {
218
219
  if (params.length > 0) {
219
220
  const docs = params.map(({ project, code, object, validFrom, expiresInSeconds, audience, author, issuedBy }) => {
221
+ // issuedByは必須化(2025-11-21~)
222
+ if (typeof (issuedBy === null || issuedBy === void 0 ? void 0 : issuedBy.id) !== 'string') {
223
+ throw new factory.errors.ArgumentNull('issuedBy?.id');
224
+ }
220
225
  const validUntil = moment(validFrom)
221
226
  .add(expiresInSeconds, 'seconds')
222
227
  .toDate();
223
- return Object.assign(Object.assign({ project, typeOf: 'Authorization', author,
228
+ return Object.assign({ project, typeOf: 'Authorization', author,
224
229
  code,
230
+ issuedBy,
225
231
  object,
226
232
  validFrom,
227
- validUntil }, (typeof (audience === null || audience === void 0 ? void 0 : audience.id) === 'string') ? { audience } : undefined), (typeof (issuedBy === null || issuedBy === void 0 ? void 0 : issuedBy.id) === 'string') ? { issuedBy } : undefined);
233
+ validUntil }, (typeof (audience === null || audience === void 0 ? void 0 : audience.id) === 'string') ? { audience } : undefined
234
+ // ...(typeof issuedBy?.id === 'string') ? { issuedBy } : undefined
235
+ );
228
236
  });
229
237
  const result = yield this.authorizationModel.insertMany(docs, { ordered: false, rawResult: true });
230
238
  if (result.insertedCount !== docs.length) {
@@ -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 itemOfferedIdentifier = verifiedOffer.itemOffered.identifier;
57
- if (typeof itemOfferedIdentifier !== 'string' || itemOfferedIdentifier === '') {
58
- throw new factory.errors.Argument('ticketedOffer.token', 'itemOffered.identifier must be string');
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 itemOfferedIdentifierMustBe = event.identifier;
61
- if (typeof itemOfferedIdentifierMustBe !== 'string') {
62
- throw new factory.errors.NotFound('identifier', 'the event must have an identifier');
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 (itemOfferedIdentifier !== itemOfferedIdentifierMustBe) {
65
- throw new factory.errors.Argument('ticketedOffer.token', 'itemOffered.identifier not matched');
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 = (_a = verifiedOffer === null || verifiedOffer === void 0 ? void 0 : verifiedOffer.eligibleQuantity) === null || _a === void 0 ? void 0 : _a.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
  }
@@ -31,7 +31,7 @@ function createOfferTicket(params) {
31
31
  const action = yield repos.action.start(actionAttributes);
32
32
  let authorizations;
33
33
  try {
34
- authorizations = yield repos.authorization.publish([{
34
+ authorizations = yield repos.authorization.issueAuthorization([{
35
35
  project: { id: project.id, typeOf: factory.organizationType.Project },
36
36
  object,
37
37
  validFrom,
@@ -21,7 +21,7 @@ function publishCode(params) {
21
21
  const issuedBy = { id: params.object.seller.id, typeOf: factory.organizationType.Corporation };
22
22
  let authorizations;
23
23
  try {
24
- authorizations = yield repos.authorization.publish([{
24
+ authorizations = yield repos.authorization.issueAuthorization([{
25
25
  project: { id: params.project.id, typeOf: factory.organizationType.Project },
26
26
  object: authorizationObject,
27
27
  validFrom: params.validFrom,
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.2.0",
15
- "@cinerino/sdk": "12.8.0",
14
+ "@chevre/factory": "5.3.0-alpha.1",
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.13"
118
+ "version": "23.1.0-alpha.15"
119
119
  }