@chevre/domain 21.30.0-alpha.40 → 21.30.0-alpha.42

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.
@@ -26,6 +26,7 @@ async function main() {
26
26
  // console.log('result:', result);
27
27
 
28
28
  const token = await (await chevre.service.code.createService()).getToken({
29
+ agent: { id: 'xxx', typeOf: chevre.factory.personType.Person },
29
30
  project,
30
31
  code: CODE,
31
32
  expiresIn: 18000,
@@ -28,11 +28,11 @@ async function main() {
28
28
  console.log('tickets:', tickets);
29
29
  console.log(tickets.length, 'tickets found');
30
30
 
31
- const issueResult = await ticketRepo.issueByTicketToken({
32
- ticketToken: TICKET_TOKEN,
33
- project: { id: project.id }
34
- });
35
- console.log('issueResult:', issueResult);
31
+ // const issueResult = await ticketRepo.issueByTicketToken({
32
+ // ticketToken: TICKET_TOKEN,
33
+ // project: { id: project.id }
34
+ // });
35
+ // console.log('issueResult:', issueResult);
36
36
  }
37
37
 
38
38
  main()
@@ -1,7 +1,7 @@
1
1
  import type { Connection, FilterQuery } from 'mongoose';
2
2
  import * as factory from '../factory';
3
3
  export type ICode = string;
4
- type IFindValidOneResult = Pick<factory.authorization.IAuthorization, 'object' | 'typeOf' | 'audience'> & {
4
+ type IFindValidOneResult = Pick<factory.authorization.IAuthorization, 'object' | 'typeOf' | 'audience' | 'issuedBy'> & {
5
5
  id: string;
6
6
  };
7
7
  type ISaveParams = Pick<factory.authorization.IAuthorization, 'audience' | 'author' | 'code' | 'issuedBy' | 'project' | 'validFrom' | 'object'> & {
@@ -114,7 +114,7 @@ class AuthorizationRepo {
114
114
  code: { $eq: String(params.code) },
115
115
  validFrom: { $lte: now },
116
116
  validUntil: { $gte: now }
117
- }, { object: 1, _id: 1, typeOf: 1, audience: 1 })
117
+ }, { object: 1, _id: 1, typeOf: 1, audience: 1, issuedBy: 1 })
118
118
  // projection的にleanで十分
119
119
  // .lean<Pick<factory.authorization.IAuthorization, 'object'>>()
120
120
  .exec();
@@ -1,5 +1,5 @@
1
1
  import { IndexDefinition, IndexOptions, Schema } from 'mongoose';
2
2
  declare const modelName = "Role";
3
- declare function createSchema(): Schema;
4
3
  declare const indexes: [d: IndexDefinition, o: IndexOptions][];
4
+ declare function createSchema(): Schema;
5
5
  export { modelName, indexes, createSchema };
@@ -7,8 +7,9 @@ const settings_1 = require("../../../settings");
7
7
  const modelName = 'Role';
8
8
  exports.modelName = modelName;
9
9
  const schemaDefinition = {
10
- typeOf: String,
11
- permissions: [String]
10
+ typeOf: { type: String, required: true },
11
+ permissions: [String],
12
+ roleName: { type: String, required: true }
12
13
  };
13
14
  const schemaOptions = {
14
15
  autoIndex: settings_1.MONGO_AUTO_INDEX,
@@ -17,12 +18,10 @@ const schemaOptions = {
17
18
  id: true,
18
19
  read: settings_1.MONGO_READ_PREFERENCE,
19
20
  writeConcern: writeConcern_1.writeConcern,
20
- strict: false,
21
+ strict: true,
21
22
  strictQuery: false,
22
- timestamps: {
23
- createdAt: 'createdAt',
24
- updatedAt: 'updatedAt'
25
- },
23
+ timestamps: false,
24
+ versionKey: false,
26
25
  toJSON: {
27
26
  getters: false,
28
27
  virtuals: false,
@@ -36,31 +35,10 @@ const schemaOptions = {
36
35
  versionKey: false
37
36
  }
38
37
  };
39
- /**
40
- * ロールスキーマ
41
- */
42
- let schema;
43
- function createSchema() {
44
- if (schema === undefined) {
45
- schema = new mongoose_1.Schema(schemaDefinition, schemaOptions);
46
- }
47
- return schema;
48
- }
49
- exports.createSchema = createSchema;
50
38
  const indexes = [
51
- [
52
- { createdAt: 1 },
53
- { name: 'searchByCreatedAt' }
54
- ],
55
- [
56
- { updatedAt: 1 },
57
- { name: 'searchByUpdatedAt' }
58
- ],
59
39
  [
60
40
  { roleName: 1 },
61
- {
62
- name: 'searchByRoleName'
63
- }
41
+ { name: 'searchByRoleName' }
64
42
  ],
65
43
  [
66
44
  { permissions: 1, roleName: 1 },
@@ -73,3 +51,19 @@ const indexes = [
73
51
  ]
74
52
  ];
75
53
  exports.indexes = indexes;
54
+ /**
55
+ * ロールスキーマ
56
+ */
57
+ let schema;
58
+ function createSchema() {
59
+ if (schema === undefined) {
60
+ schema = new mongoose_1.Schema(schemaDefinition, schemaOptions);
61
+ if (settings_1.MONGO_AUTO_INDEX) {
62
+ indexes.forEach((indexParams) => {
63
+ schema === null || schema === void 0 ? void 0 : schema.index(...indexParams);
64
+ });
65
+ }
66
+ }
67
+ return schema;
68
+ }
69
+ exports.createSchema = createSchema;
@@ -10,7 +10,8 @@ const schemaDefinition = {
10
10
  project: { type: mongoose_1.SchemaTypes.Mixed, required: true },
11
11
  typeOf: { type: String, required: true },
12
12
  ticketToken: { type: String, required: true },
13
- dateIssued: { type: Date, required: true }
13
+ dateIssued: { type: Date, required: true },
14
+ issuedBy: mongoose_1.SchemaTypes.Mixed
14
15
  };
15
16
  const schemaOptions = {
16
17
  autoIndex: settings_1.MONGO_AUTO_INDEX,
@@ -42,11 +42,7 @@ class MongoRepository {
42
42
  search(params) {
43
43
  return __awaiter(this, void 0, void 0, function* () {
44
44
  const conditions = MongoRepository.CREATE_MONGO_CONDITIONS(params);
45
- const query = this.roleModel.find((conditions.length > 0) ? { $and: conditions } : {}, {
46
- __v: 0,
47
- createdAt: 0,
48
- updatedAt: 0
49
- });
45
+ const query = this.roleModel.find((conditions.length > 0) ? { $and: conditions } : {}, {});
50
46
  if (typeof params.limit === 'number' && params.limit > 0) {
51
47
  const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
52
48
  query.limit(params.limit)
@@ -1,5 +1,9 @@
1
1
  import type { Connection, FilterQuery } from 'mongoose';
2
2
  import * as factory from '../factory';
3
+ export interface ITicketIssuedBy {
4
+ id: string;
5
+ typeOf: factory.organizationType.Corporation | factory.organizationType.Project;
6
+ }
3
7
  interface ITicket {
4
8
  /**
5
9
  * チケットID(jti)
@@ -12,11 +16,13 @@ interface ITicket {
12
16
  typeOf: 'Ticket';
13
17
  ticketToken: string;
14
18
  dateIssued: Date;
19
+ issuedBy: ITicketIssuedBy;
15
20
  }
16
21
  type IIssueParams = Pick<ITicket, 'ticketToken'> & {
17
22
  project: {
18
23
  id: string;
19
24
  };
25
+ issuedBy?: ITicketIssuedBy;
20
26
  };
21
27
  interface ISearchConditions {
22
28
  limit?: number;
@@ -42,9 +42,13 @@ class TicketRepo {
42
42
  */
43
43
  issueByTicketToken(params) {
44
44
  return __awaiter(this, void 0, void 0, function* () {
45
- const { ticketToken, project } = params;
45
+ const { ticketToken, project, issuedBy } = params;
46
+ const ticketIssuedBy = (typeof (issuedBy === null || issuedBy === void 0 ? void 0 : issuedBy.id) === 'string' && issuedBy.typeOf === factory.organizationType.Corporation)
47
+ ? issuedBy
48
+ : { id: project.id, typeOf: factory.organizationType.Project };
46
49
  const creatingTicket = {
47
50
  dateIssued: new Date(),
51
+ issuedBy: ticketIssuedBy,
48
52
  project: { id: project.id, typeOf: factory.organizationType.Project },
49
53
  ticketToken,
50
54
  typeOf: 'Ticket'
@@ -23,6 +23,7 @@ const ALGORITHM = 'HS256';
23
23
  */
24
24
  function getToken(params) {
25
25
  return (repos) => __awaiter(this, void 0, void 0, function* () {
26
+ var _a;
26
27
  if (typeof params.project.id !== 'string' || params.project.id.length === 0) {
27
28
  throw new factory.errors.ArgumentNull('project.id');
28
29
  }
@@ -40,10 +41,7 @@ function getToken(params) {
40
41
  let typ = `${credentials_1.credentials.jwt.payloadTypPrefix}:${authorization.typeOf}`;
41
42
  let jti;
42
43
  if (params.useJti) {
43
- const { id } = yield repos.ticket.issueByTicketToken({
44
- project: { id: params.project.id },
45
- ticketToken: params.code
46
- });
44
+ const { id } = yield repos.ticket.issueByTicketToken(Object.assign({ project: { id: params.project.id }, ticketToken: params.code }, (typeof ((_a = authorization.issuedBy) === null || _a === void 0 ? void 0 : _a.id) === 'string') ? { issuedBy: authorization.issuedBy } : undefined));
47
45
  jti = id;
48
46
  // ロール承認の場合、subjectはメンバーID,typはメンバータイプ
49
47
  if (authorization.object.typeOf === factory.iam.RoleType.OrganizationRole) {
package/package.json CHANGED
@@ -110,5 +110,5 @@
110
110
  "postversion": "git push origin --tags",
111
111
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
112
112
  },
113
- "version": "21.30.0-alpha.40"
113
+ "version": "21.30.0-alpha.42"
114
114
  }