@chevre/domain 23.0.0-alpha.14 → 23.0.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.
@@ -9,7 +9,7 @@ async function main() {
9
9
  const roleRepo = await chevre.repository.Role.createInstance(mongoose.connection);
10
10
 
11
11
  const permissions = [
12
- 'eventOffers.*'
12
+ 'products.read'
13
13
  ];
14
14
  for (const permission of permissions) {
15
15
  const roles = await roleRepo.projectFields(
@@ -9,12 +9,7 @@ async function main() {
9
9
  const roleRepo = await chevre.repository.Role.createInstance(mongoose.connection);
10
10
 
11
11
  const permissions = [
12
- 'tokens',
13
- 'authorizations.create',
14
- 'permits.read',
15
- 'tasks.read',
16
- 'transactionNumbers.write',
17
- 'chevre.admin'
12
+ 'admin.sellers.productOffers.*'
18
13
  ];
19
14
  for (const permission of permissions) {
20
15
  const roles = await roleRepo.projectFields(
@@ -4,6 +4,19 @@ type IKeyOfProjection = keyof factory.categoryCode.ICategoryCode;
4
4
  type IUnset = {
5
5
  [key in keyof Pick<factory.categoryCode.ICategoryCode, 'additionalProperty' | 'color' | 'image' | 'paymentMethod'>]?: 1;
6
6
  };
7
+ type CategorySetIdentifierExceptMovieTicketType = Exclude<factory.categoryCode.CategorySetIdentifier, factory.categoryCode.CategorySetIdentifier.MovieTicketType>;
8
+ type ICategoryCodeExceptMovieTicketType = Pick<factory.categoryCode.ICategoryCode, 'additionalProperty' | 'codeValue' | 'color' | 'id' | 'image' | 'name' | 'project' | 'typeOf'> & {
9
+ inCodeSet: {
10
+ typeOf: 'CategoryCodeSet';
11
+ identifier: CategorySetIdentifierExceptMovieTicketType;
12
+ };
13
+ };
14
+ type IMovieTicketType = Pick<factory.categoryCode.ICategoryCode, 'additionalProperty' | 'codeValue' | 'color' | 'id' | 'image' | 'name' | 'project' | 'typeOf' | 'paymentMethod'> & {
15
+ inCodeSet: {
16
+ typeOf: 'CategoryCodeSet';
17
+ identifier: factory.categoryCode.CategorySetIdentifier.MovieTicketType;
18
+ };
19
+ };
7
20
  /**
8
21
  * 区分リポジトリ
9
22
  */
@@ -21,15 +34,38 @@ export declare class CategoryCodeRepo {
21
34
  */
22
35
  searchByAggregate(conditions: factory.categoryCode.ISearchConditions, inclusion: IKeyOfProjection[]): Promise<factory.categoryCode.ICategoryCode[]>;
23
36
  /**
24
- * 検索
37
+ * 区分検索
25
38
  */
26
- projectFields(params: factory.categoryCode.ISearchConditions,
39
+ projectCategoryCodeFields(params: Omit<factory.categoryCode.ISearchConditions, 'inCodeSet' | 'paymentMethod'> & {
40
+ inCodeSet?: {
41
+ identifier?: {
42
+ $eq?: CategorySetIdentifierExceptMovieTicketType;
43
+ $in?: CategorySetIdentifierExceptMovieTicketType[];
44
+ };
45
+ };
46
+ },
27
47
  /**
28
48
  * 空の場合無効
29
49
  */
30
50
  inclusion: IKeyOfProjection[], options?: {
31
51
  excludeMovieTicketType?: boolean;
32
- }): Promise<(factory.categoryCode.ICategoryCode & {
52
+ }): Promise<(ICategoryCodeExceptMovieTicketType & {
53
+ id: string;
54
+ })[]>;
55
+ /**
56
+ * 決済カード区分検索
57
+ */
58
+ projectMovieTicketTypeFields(params: Omit<factory.categoryCode.ISearchConditions, 'inCodeSet'> & {
59
+ inCodeSet?: {
60
+ identifier?: {
61
+ $eq?: factory.categoryCode.CategorySetIdentifier.MovieTicketType;
62
+ };
63
+ };
64
+ },
65
+ /**
66
+ * 空の場合無効
67
+ */
68
+ inclusion: IKeyOfProjection[]): Promise<(IMovieTicketType & {
33
69
  id: string;
34
70
  })[]>;
35
71
  save(params: {
@@ -219,9 +219,9 @@ class CategoryCodeRepo {
219
219
  });
220
220
  }
221
221
  /**
222
- * 検索
222
+ * 区分検索
223
223
  */
224
- projectFields(params,
224
+ projectCategoryCodeFields(params,
225
225
  /**
226
226
  * 空の場合無効
227
227
  */
@@ -249,6 +249,37 @@ class CategoryCodeRepo {
249
249
  .exec();
250
250
  });
251
251
  }
252
+ /**
253
+ * 決済カード区分検索
254
+ */
255
+ projectMovieTicketTypeFields(params,
256
+ /**
257
+ * 空の場合無効
258
+ */
259
+ inclusion) {
260
+ return __awaiter(this, void 0, void 0, function* () {
261
+ const conditions = CategoryCodeRepo.CREATE_MONGO_CONDITIONS(params);
262
+ let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
263
+ if (Array.isArray(inclusion) && inclusion.length > 0) {
264
+ positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
265
+ }
266
+ const projection = Object.assign({ _id: 0, id: { $toString: '$_id' } }, Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1]))));
267
+ const query = this.categoryCodeModel.find((conditions.length > 0) ? { $and: conditions } : {}, projection);
268
+ if (typeof params.limit === 'number' && params.limit > 0) {
269
+ const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
270
+ query.limit(params.limit)
271
+ .skip(params.limit * (page - 1));
272
+ }
273
+ // tslint:disable-next-line:no-single-line-block-comment
274
+ /* istanbul ignore else */
275
+ if (params.sort !== undefined) {
276
+ query.sort(params.sort);
277
+ }
278
+ return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
279
+ .lean() // 2024-08-19~
280
+ .exec();
281
+ });
282
+ }
252
283
  save(params) {
253
284
  return __awaiter(this, void 0, void 0, function* () {
254
285
  let savedId;
@@ -0,0 +1,15 @@
1
+ import * as moment from 'moment';
2
+ import * as factory from '../../../../factory';
3
+ declare function validateOfferToken(params: {
4
+ acceptedDate: moment.Moment;
5
+ /**
6
+ * トークン検証済の指定オファー
7
+ */
8
+ verifiedOffer: factory.assetTransaction.reserve.IOfferTokenPayload;
9
+ /**
10
+ * イベントのアプリケーションオファー設定
11
+ */
12
+ makesOfferOnApplication: factory.event.screeningEvent.ISellerMakesOffer;
13
+ object: factory.assetTransaction.reserve.IObjectWithoutDetail;
14
+ }): () => Promise<void>;
15
+ export { validateOfferToken };
@@ -0,0 +1,61 @@
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.validateOfferToken = validateOfferToken;
13
+ const moment = require("moment");
14
+ const factory = require("../../../../factory");
15
+ const OFFER_TOKEN_DATE_FORMAT = 'YYYY-MM-DDTHH:mm:ssZ';
16
+ function validateOfferToken(params) {
17
+ return () => __awaiter(this, void 0, void 0, function* () {
18
+ var _a, _b, _c, _d;
19
+ const { acceptedDate, verifiedOffer, makesOfferOnApplication } = params;
20
+ const applicationIdentifier = (_a = verifiedOffer.availableAtOrFrom) === null || _a === void 0 ? void 0 : _a.identifier;
21
+ if (typeof applicationIdentifier !== 'string' || applicationIdentifier === '') {
22
+ throw new factory.errors.Argument('reservationFor.offers.token', 'availableAtOrFrom.identifier must be string');
23
+ }
24
+ const applicationIdentifierMustBe = (Array.isArray(makesOfferOnApplication.availableAtOrFrom))
25
+ ? makesOfferOnApplication.availableAtOrFrom[0].identifier
26
+ : (_b = makesOfferOnApplication.availableAtOrFrom) === null || _b === void 0 ? void 0 : _b.identifier;
27
+ if (typeof applicationIdentifierMustBe !== 'string') {
28
+ throw new factory.errors.NotFound('makesOffer.availableAtOrFrom.identifier');
29
+ }
30
+ if (applicationIdentifier !== applicationIdentifierMustBe) {
31
+ throw new factory.errors.Argument('reservationFor.offers.token', 'availableAtOrFrom.identifier not matched');
32
+ }
33
+ let validThroughMoment;
34
+ let validFromMoment;
35
+ validThroughMoment = moment(verifiedOffer.validThrough, OFFER_TOKEN_DATE_FORMAT, true);
36
+ validFromMoment = moment(verifiedOffer.validFrom, OFFER_TOKEN_DATE_FORMAT, true);
37
+ if (!validThroughMoment.isValid()) {
38
+ throw new factory.errors.Argument('reservationFor.offers.token', 'invalid validThrough');
39
+ }
40
+ if (!validFromMoment.isValid()) {
41
+ throw new factory.errors.Argument('reservationFor.offers.token', 'invalid validFrom');
42
+ }
43
+ if (acceptedDate.isBefore(validFromMoment)) {
44
+ throw new factory.errors.Argument('reservationFor.offers.token', `the offer id valid from ${validFromMoment}`);
45
+ }
46
+ if (acceptedDate.isAfter(validThroughMoment)) {
47
+ throw new factory.errors.Argument('reservationFor.offers.token', `the offer id valid through ${validThroughMoment}`);
48
+ }
49
+ // tslint:disable-next-line:no-suspicious-comment
50
+ // TODO maxValueを検証
51
+ const maxValue = (_c = verifiedOffer === null || verifiedOffer === void 0 ? void 0 : verifiedOffer.eligibleQuantity) === null || _c === void 0 ? void 0 : _c.maxValue;
52
+ if (typeof maxValue === 'number') {
53
+ const numAcceptedOffers = (_d = params.object.acceptedOffer) === null || _d === void 0 ? void 0 : _d.length;
54
+ if (typeof numAcceptedOffers === 'number' && numAcceptedOffers > 0) {
55
+ if (numAcceptedOffers > maxValue) {
56
+ throw new factory.errors.Argument('reservationFor.id', `Maximum number of offers exceeded`);
57
+ }
58
+ }
59
+ }
60
+ });
61
+ }
@@ -13,7 +13,7 @@ exports.validateStartRequest = validateStartRequest;
13
13
  const jwt = require("jsonwebtoken");
14
14
  const moment = require("moment");
15
15
  const factory = require("../../../factory");
16
- function verifyOfferedByToken(params) {
16
+ function verifyMemberTierToken(params) {
17
17
  return __awaiter(this, void 0, void 0, function* () {
18
18
  let result;
19
19
  const { issuer, secret, token } = params;
@@ -46,6 +46,42 @@ function verifyOfferedByToken(params) {
46
46
  return result;
47
47
  });
48
48
  }
49
+ // async function verifyOfferToken(params: {
50
+ // token: string;
51
+ // secret: string;
52
+ // issuer?: string;
53
+ // }): Promise<factory.assetTransaction.reserve.IOfferTokenPayload> {
54
+ // let result: factory.assetTransaction.reserve.IOfferTokenPayload;
55
+ // const { issuer, secret, token } = params;
56
+ // try {
57
+ // result = await new Promise<factory.assetTransaction.reserve.IOfferTokenPayload>((resolve, reject) => {
58
+ // jwt.verify(
59
+ // token,
60
+ // secret,
61
+ // {
62
+ // algorithms: ['HS256'],
63
+ // issuer
64
+ // // ...(Array.isArray(params.audience)) ? { audience: params.audience } : undefined
65
+ // },
66
+ // (err, decoded: any) => {
67
+ // if (err instanceof Error) {
68
+ // reject(err);
69
+ // } else {
70
+ // resolve(decoded);
71
+ // }
72
+ // });
73
+ // });
74
+ // } catch (error) {
75
+ // // JWTエラーをハンドリング
76
+ // if (error instanceof jwt.TokenExpiredError) {
77
+ // throw new factory.errors.Argument('memberOfToken', `invalid token. [${error.message} expiredAt:${error.expiredAt}]`);
78
+ // } else if (error instanceof jwt.JsonWebTokenError) {
79
+ // throw new factory.errors.Argument('memberOfToken', `invalid token. [${error.message}]`);
80
+ // }
81
+ // throw error;
82
+ // }
83
+ // return result;
84
+ // }
49
85
  function validateStartRequest(params) {
50
86
  return (repos) => __awaiter(this, void 0, void 0, function* () {
51
87
  var _a, _b, _c;
@@ -57,7 +93,7 @@ function validateStartRequest(params) {
57
93
  }
58
94
  const tokenizedMemberProgramTier = (_c = (_b = params.object.reservationFor) === null || _b === void 0 ? void 0 : _b.offers) === null || _c === void 0 ? void 0 : _c.validForMemberTier;
59
95
  yield validateEventOfferPeriod(Object.assign({ event,
60
- now, availableAt: { id: params.store.id } }, (typeof (tokenizedMemberProgramTier === null || tokenizedMemberProgramTier === void 0 ? void 0 : tokenizedMemberProgramTier.token) === 'string') ? { tokenizedMemberProgramTier } : undefined))(repos);
96
+ now, availableAt: { id: params.store.id }, object: params.object }, (typeof (tokenizedMemberProgramTier === null || tokenizedMemberProgramTier === void 0 ? void 0 : tokenizedMemberProgramTier.token) === 'string') ? { tokenizedMemberProgramTier } : undefined))(repos);
61
97
  }
62
98
  if (params.validateEvent === true) {
63
99
  validateEvent({ event, object: params.object });
@@ -120,6 +156,7 @@ function validateMemberTier(params) {
120
156
  * イベントのオファー有効期間を検証する
121
157
  */
122
158
  function validateEventOfferPeriod(params) {
159
+ // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
123
160
  return (repos) => __awaiter(this, void 0, void 0, function* () {
124
161
  var _a, _b;
125
162
  const { event, availableAt, tokenizedMemberProgramTier } = params;
@@ -185,7 +222,7 @@ function validateEventOfferPeriod(params) {
185
222
  if (typeof issuer.tokenSecret !== 'string' || issuer.tokenSecret === '') {
186
223
  throw new factory.errors.NotFound('issuer.tokenSecret');
187
224
  }
188
- const verifiedValidForMemberTier = yield verifyOfferedByToken({
225
+ const verifiedValidForMemberTier = yield verifyMemberTierToken({
189
226
  secret: issuer.tokenSecret,
190
227
  issuer: issuer.url,
191
228
  token: validForMemberTierToken
@@ -195,6 +232,34 @@ function validateEventOfferPeriod(params) {
195
232
  memberProgramIdentifierMustBe, aggregateOfferIdentifier
196
233
  })(repos);
197
234
  }
235
+ // tslint:disable-next-line:no-suspicious-comment
236
+ // TODO オファートークン検証(2025-10-21~)
237
+ // const offerTokenIssuer = makesOfferOnApplication.issuedBy?.identifier;
238
+ // const offerTokenRequired = typeof offerTokenIssuer === 'string';
239
+ // if (offerTokenRequired) {
240
+ // const offerToken = params.object.reservationFor?.offers?.token;
241
+ // if (typeof offerToken !== 'string' || offerToken === '') {
242
+ // throw new factory.errors.ArgumentNull('object.reservationFor.offers.token');
243
+ // }
244
+ // const issuer = await repos.issuer.findByIdentifier({
245
+ // project: { id: params.event.project.id },
246
+ // identifier: offerTokenIssuer
247
+ // });
248
+ // if (typeof issuer.tokenSecret !== 'string' || issuer.tokenSecret === '') {
249
+ // throw new factory.errors.NotFound('issuer.tokenSecret');
250
+ // }
251
+ // const verifiedOffer = await verifyOfferToken({
252
+ // secret: issuer.tokenSecret,
253
+ // issuer: issuer.url,
254
+ // token: offerToken
255
+ // });
256
+ // await validateOfferToken({
257
+ // acceptedDate,
258
+ // verifiedOffer,
259
+ // makesOfferOnApplication,
260
+ // object: params.object
261
+ // })();
262
+ // }
198
263
  });
199
264
  }
200
265
  /**
@@ -239,7 +239,7 @@ function saveScreeningEventSeries(params) {
239
239
  kubunClass: '043'
240
240
  });
241
241
  debug('kubunNames found.');
242
- const availablePaymentMethodTypes = yield repos.categoryCode.projectFields({
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']);
@@ -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.projectFields({
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.projectFields({
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.projectFields({
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.projectFields({
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.projectFields({
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.projectFields({
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
  }, []);
@@ -29,7 +29,7 @@ function syncCategoryCode(params) {
29
29
  }
30
30
  else {
31
31
  for (const categoryCodeId of params.ids) {
32
- const syncingCategoryCode = (yield repos.categoryCode.projectFields({
32
+ const syncingCategoryCode = (yield repos.categoryCode.projectCategoryCodeFields({
33
33
  limit: 1,
34
34
  page: 1,
35
35
  project: { id: { $eq: params.project.id } },
@@ -348,7 +348,7 @@ function createInformCategoryCodeTasks(params, setting) {
348
348
  // settings: Settings
349
349
  ) => __awaiter(this, void 0, void 0, function* () {
350
350
  var _a;
351
- const categoryCodes4inform = yield repos.categoryCode.projectFields({
351
+ const categoryCodes4inform = yield repos.categoryCode.projectCategoryCodeFields({
352
352
  id: { $in: params.ids },
353
353
  // ひとまずDistributorTypeのみ
354
354
  inCodeSet: { identifier: { $eq: factory.categoryCode.CategorySetIdentifier.DistributorType } }
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.1.0-alpha.3",
15
- "@cinerino/sdk": "12.5.0-alpha.9",
14
+ "@chevre/factory": "5.1.0-alpha.4",
15
+ "@cinerino/sdk": "12.5.0-alpha.17",
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.0.0-alpha.14"
118
+ "version": "23.0.0-alpha.15"
119
119
  }
@@ -1,29 +0,0 @@
1
- // tslint:disable:no-console
2
- import * as mongoose from 'mongoose';
3
-
4
- import { chevre } from '../../../../lib/index';
5
-
6
- const project = { id: String(process.env.PROJECT_ID) };
7
-
8
- async function main() {
9
- await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
10
-
11
- const categoryCodeRepo = await chevre.repository.CategoryCode.createInstance(mongoose.connection);
12
-
13
- const categoryCodes = await categoryCodeRepo.projectFields(
14
- {
15
- limit: 100,
16
- page: 1,
17
- project: { id: { $eq: project.id } },
18
- inCodeSet: { identifier: { $eq: chevre.factory.categoryCode.CategorySetIdentifier.MovieTicketType } }
19
- },
20
- [],
21
- { excludeMovieTicketType: false }
22
- );
23
- // tslint:disable-next-line:no-null-keyword
24
- console.dir(categoryCodes.map(({ inCodeSet }) => inCodeSet.identifier), { depth: null });
25
- }
26
-
27
- main()
28
- .then()
29
- .catch(console.error);