@chevre/domain 21.30.0-alpha.41 → 21.30.0-alpha.43

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.
@@ -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,15 +114,15 @@ 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();
121
121
  if (doc === null) {
122
122
  throw new factory.errors.NotFound(this.authorizationModel.modelName);
123
123
  }
124
- const { id, object, typeOf, audience } = doc.toObject();
125
- return Object.assign({ id, object, typeOf }, (typeof (audience === null || audience === void 0 ? void 0 : audience.id) === 'string') ? { audience } : undefined);
124
+ const { id, object, typeOf, audience, issuedBy } = doc.toObject();
125
+ 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);
126
126
  });
127
127
  }
128
128
  /**
@@ -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: { type: mongoose_1.SchemaTypes.Mixed, required: true }
14
15
  };
15
16
  const schemaOptions = {
16
17
  autoIndex: settings_1.MONGO_AUTO_INDEX,
@@ -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.41"
113
+ "version": "21.30.0-alpha.43"
114
114
  }