@chevre/domain 22.14.0-alpha.20 → 22.14.0-alpha.21

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,92 @@
1
+ // tslint:disable:no-console
2
+ import { sign } from 'jsonwebtoken';
3
+ import * as mongoose from 'mongoose';
4
+
5
+ import { chevre } from '../../../../lib/index';
6
+
7
+ const project = { id: String(process.env.PROJECT_ID) };
8
+
9
+ async function main() {
10
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
11
+
12
+ const productOfferRepo = await chevre.repository.ProductOffer.createInstance(mongoose.connection);
13
+ const issuerRepo = await chevre.repository.Issuer.createInstance(mongoose.connection);
14
+ const memberProgramRepo = await chevre.repository.MemberProgram.createInstance(mongoose.connection);
15
+
16
+ const productOffer = (await productOfferRepo.findProductOffers(
17
+ {
18
+ limit: 1,
19
+ page: 1,
20
+ project: { id: { $eq: project.id } },
21
+ id: { $eq: '68d378a0c6f90b6bea9427ee' }
22
+ },
23
+ ['validForMemberTier']
24
+ )).shift();
25
+ if (productOffer === undefined) {
26
+ throw new chevre.factory.errors.NotFound(chevre.factory.offerType.Offer);
27
+ }
28
+
29
+ const tierIdentifier = productOffer.validForMemberTier?.identifier;
30
+ if (typeof tierIdentifier !== 'string') {
31
+ throw new chevre.factory.errors.NotFound('productOffer.validForMemberTier.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: tier.isTierOf.hostingOrganization.identifier,
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 = {
55
+ member: {
56
+ memberOf: {
57
+ identifier: tierIdentifier,
58
+ isTierOf: { identifier: tier.isTierOf.identifier }
59
+ }
60
+ }
61
+ };
62
+
63
+ const token = await new Promise<string>((resolve, reject) => {
64
+ // 所有権を暗号化する
65
+ sign(
66
+ payload,
67
+ tokenSecret,
68
+ {
69
+ // algorithm: jwtSetting.algorithm,
70
+ issuer: url,
71
+ expiresIn: 1800
72
+ // subject,
73
+ },
74
+ (err, encoded) => {
75
+ if (err instanceof Error) {
76
+ reject(err);
77
+ } else {
78
+ if (typeof encoded !== 'string') {
79
+ reject(new Error('cannot be signed unexpectedly'));
80
+ } else {
81
+ resolve(encoded);
82
+ }
83
+ }
84
+ }
85
+ );
86
+ });
87
+ console.log(token);
88
+ }
89
+
90
+ main()
91
+ .then()
92
+ .catch(console.error);
@@ -14,6 +14,9 @@ interface ISearchConditions {
14
14
  $eq?: string;
15
15
  };
16
16
  };
17
+ id?: {
18
+ $eq?: string;
19
+ };
17
20
  itemOffered?: {
18
21
  identifier?: {
19
22
  $eq?: string;
@@ -32,29 +32,29 @@ class ProductOfferRepo {
32
32
  this.productOfferModel = connection.model(productOffer_1.modelName, (0, productOffer_1.createSchema)());
33
33
  }
34
34
  static CREATE_MONGO_CONDITIONS(params) {
35
- var _a, _b, _c, _d, _e, _f, _g, _h;
35
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
36
36
  const andConditions = [];
37
- // const idIn = params.id?.$in;
38
- // if (Array.isArray(idIn)) {
39
- // andConditions.push({ _id: { $in: idIn } });
40
- // }
41
- const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
37
+ const idEq = (_a = params.id) === null || _a === void 0 ? void 0 : _a.$eq;
38
+ if (typeof idEq === 'string') {
39
+ andConditions.push({ _id: { $eq: idEq } });
40
+ }
41
+ const projectIdEq = (_c = (_b = params.project) === null || _b === void 0 ? void 0 : _b.id) === null || _c === void 0 ? void 0 : _c.$eq;
42
42
  if (typeof projectIdEq === 'string') {
43
43
  andConditions.push({ 'project.id': { $eq: projectIdEq } });
44
44
  }
45
- const itemOfferedIdentifierEq = (_d = (_c = params.itemOffered) === null || _c === void 0 ? void 0 : _c.identifier) === null || _d === void 0 ? void 0 : _d.$eq;
45
+ const itemOfferedIdentifierEq = (_e = (_d = params.itemOffered) === null || _d === void 0 ? void 0 : _d.identifier) === null || _e === void 0 ? void 0 : _e.$eq;
46
46
  if (typeof itemOfferedIdentifierEq === 'string') {
47
47
  andConditions.push({ 'itemOffered.identifier': { $eq: itemOfferedIdentifierEq } });
48
48
  }
49
- const validForMemberTierIdentifierEq = (_f = (_e = params.validForMemberTier) === null || _e === void 0 ? void 0 : _e.identifier) === null || _f === void 0 ? void 0 : _f.$eq;
49
+ const validForMemberTierIdentifierEq = (_g = (_f = params.validForMemberTier) === null || _f === void 0 ? void 0 : _f.identifier) === null || _g === void 0 ? void 0 : _g.$eq;
50
50
  if (typeof validForMemberTierIdentifierEq === 'string') {
51
51
  andConditions.push({ 'validForMemberTier.identifier': { $exists: true, $eq: validForMemberTierIdentifierEq } });
52
52
  }
53
- const validFromLte = (_g = params.validFrom) === null || _g === void 0 ? void 0 : _g.$lte;
53
+ const validFromLte = (_h = params.validFrom) === null || _h === void 0 ? void 0 : _h.$lte;
54
54
  if (validFromLte instanceof Date) {
55
55
  andConditions.push({ validFrom: { $lte: validFromLte } });
56
56
  }
57
- const validThroughGte = (_h = params.validThrough) === null || _h === void 0 ? void 0 : _h.$gte;
57
+ const validThroughGte = (_j = params.validThrough) === null || _j === void 0 ? void 0 : _j.$gte;
58
58
  if (validThroughGte instanceof Date) {
59
59
  andConditions.push({ validThrough: { $gte: validThroughGte } });
60
60
  }
@@ -90,7 +90,7 @@ function validateMemberTier(params) {
90
90
  validThrough: { $gte: acceptedDate.toDate() }
91
91
  }, ['identifier'])).shift();
92
92
  if (productOfferForMemberTier === undefined) {
93
- throw new factory.errors.NotFound(factory.offerType.Offer, 'product offer for member tier not found');
93
+ throw new factory.errors.NotFound(factory.offerType.Offer, 'valid product offers for member tier not found');
94
94
  }
95
95
  // let validThroughMoment: moment.Moment;
96
96
  // let validFromMoment: moment.Moment;
package/package.json CHANGED
@@ -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": "22.14.0-alpha.20"
118
+ "version": "22.14.0-alpha.21"
119
119
  }