@chevre/domain 21.30.0-alpha.25 → 21.30.0-alpha.26
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.
- package/example/src/chevre/findValidObjectByAuthorizationCode.ts +32 -0
- package/lib/chevre/repo/code.d.ts +6 -2
- package/lib/chevre/repo/code.js +5 -10
- package/lib/chevre/service/code.js +7 -6
- package/lib/chevre/service/reserve/findByCode.js +4 -4
- package/lib/chevre/service/reserve/verifyToken4reservation.js +2 -1
- package/lib/chevre/service/task/onAuthorizationCreated.js +4 -4
- package/package.json +1 -1
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
const CODE = '33357ca4-55cb-4b36-8d82-af8e445c53c7';
|
|
8
|
+
|
|
9
|
+
async function main() {
|
|
10
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
11
|
+
|
|
12
|
+
const codeRepo = await chevre.repository.Code.createInstance(mongoose.connection);
|
|
13
|
+
|
|
14
|
+
const result = await codeRepo.findValidOneByCode({
|
|
15
|
+
project,
|
|
16
|
+
code: CODE
|
|
17
|
+
});
|
|
18
|
+
console.log('result:', result);
|
|
19
|
+
|
|
20
|
+
const token = await (await chevre.service.code.createService()).getToken({
|
|
21
|
+
project,
|
|
22
|
+
code: CODE,
|
|
23
|
+
expiresIn: 1800
|
|
24
|
+
})({
|
|
25
|
+
authorization: codeRepo
|
|
26
|
+
});
|
|
27
|
+
console.log('token:', token);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
main()
|
|
31
|
+
.then(console.log)
|
|
32
|
+
.catch(console.error);
|
|
@@ -2,6 +2,9 @@ import type { Connection, FilterQuery } from 'mongoose';
|
|
|
2
2
|
import * as factory from '../factory';
|
|
3
3
|
export type IObject = factory.authorization.IObject;
|
|
4
4
|
export type ICode = string;
|
|
5
|
+
type IFindValidOneResult = Pick<factory.authorization.IAuthorization, 'object' | 'typeOf'> & {
|
|
6
|
+
id: string;
|
|
7
|
+
};
|
|
5
8
|
/**
|
|
6
9
|
* 承認コードリポジトリ
|
|
7
10
|
*/
|
|
@@ -24,12 +27,12 @@ export declare class MongoRepository {
|
|
|
24
27
|
/**
|
|
25
28
|
* コードで承認対象を検索する
|
|
26
29
|
*/
|
|
27
|
-
|
|
30
|
+
findValidOneByCode(params: {
|
|
28
31
|
project: {
|
|
29
32
|
id: string;
|
|
30
33
|
};
|
|
31
34
|
code: ICode;
|
|
32
|
-
}): Promise<
|
|
35
|
+
}): Promise<IFindValidOneResult>;
|
|
33
36
|
search(params: factory.authorization.ISearchConditions): Promise<factory.authorization.IAuthorization[]>;
|
|
34
37
|
/**
|
|
35
38
|
* 有効期限を一定期間過ぎた承認を削除する
|
|
@@ -42,3 +45,4 @@ export declare class MongoRepository {
|
|
|
42
45
|
*/
|
|
43
46
|
private save;
|
|
44
47
|
}
|
|
48
|
+
export {};
|
package/lib/chevre/repo/code.js
CHANGED
|
@@ -111,7 +111,7 @@ class MongoRepository {
|
|
|
111
111
|
/**
|
|
112
112
|
* コードで承認対象を検索する
|
|
113
113
|
*/
|
|
114
|
-
|
|
114
|
+
findValidOneByCode(params) {
|
|
115
115
|
return __awaiter(this, void 0, void 0, function* () {
|
|
116
116
|
const now = new Date();
|
|
117
117
|
const doc = yield this.authorizationModel.findOne({
|
|
@@ -119,22 +119,17 @@ class MongoRepository {
|
|
|
119
119
|
code: { $eq: String(params.code) },
|
|
120
120
|
validFrom: { $lte: now },
|
|
121
121
|
validUntil: { $gte: now }
|
|
122
|
-
}, { object: 1, _id:
|
|
122
|
+
}, { object: 1, _id: 1, typeOf: 1 })
|
|
123
123
|
// projection的にleanで十分
|
|
124
|
-
.lean()
|
|
124
|
+
// .lean<Pick<factory.authorization.IAuthorization, 'object'>>()
|
|
125
125
|
.exec();
|
|
126
126
|
if (doc === null) {
|
|
127
127
|
throw new factory.errors.NotFound(this.authorizationModel.modelName);
|
|
128
128
|
}
|
|
129
|
-
|
|
129
|
+
const { id, object, typeOf } = doc.toObject();
|
|
130
|
+
return { id, object, typeOf };
|
|
130
131
|
});
|
|
131
132
|
}
|
|
132
|
-
// public async count(params: factory.authorization.ISearchConditions): Promise<number> {
|
|
133
|
-
// const conditions = MongoRepository.CREATE_MONGO_CONDITIONS(params);
|
|
134
|
-
// return this.authorizationModel.countDocuments((conditions.length > 0) ? { $and: conditions } : {})
|
|
135
|
-
// .setOptions({ maxTimeMS: MONGO_MAX_TIME_MS })
|
|
136
|
-
// .exec();
|
|
137
|
-
// }
|
|
138
133
|
search(params) {
|
|
139
134
|
var _a;
|
|
140
135
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -27,18 +27,19 @@ function getToken(params) {
|
|
|
27
27
|
if (typeof params.code !== 'string' || params.code.length === 0) {
|
|
28
28
|
throw new factory.errors.ArgumentNull('code');
|
|
29
29
|
}
|
|
30
|
-
const
|
|
30
|
+
const authorization = yield repos.authorization.findValidOneByCode({
|
|
31
31
|
project: { id: params.project.id },
|
|
32
32
|
code: params.code
|
|
33
33
|
});
|
|
34
34
|
return new Promise((resolve, reject) => {
|
|
35
35
|
// 所有権を暗号化する
|
|
36
|
-
jwt.sign(
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
jwt.sign(Object.assign(Object.assign({}, authorization.object), {
|
|
37
|
+
// sub: authorization.id, // 拡張(2024-05-01~)
|
|
38
|
+
token_use: 'access', 'chevre:typeOf': authorization.typeOf // 拡張(2024-05-01~)
|
|
39
|
+
}), credentials_1.credentials.jwt.secret, {
|
|
39
40
|
issuer: credentials_1.credentials.jwt.issuer,
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
expiresIn: params.expiresIn,
|
|
42
|
+
subject: authorization.id // 拡張(2024-05-01~)
|
|
42
43
|
}, (err, encoded) => {
|
|
43
44
|
if (err instanceof Error) {
|
|
44
45
|
reject(err);
|
|
@@ -21,13 +21,13 @@ function findByCode(params) {
|
|
|
21
21
|
throw new factory.errors.ArgumentNull('code');
|
|
22
22
|
}
|
|
23
23
|
const reservationId = String(params.id);
|
|
24
|
-
const
|
|
24
|
+
const authorization = yield repos.authorization.findValidOneByCode({
|
|
25
25
|
project: { id: params.project.id },
|
|
26
26
|
code: params.code
|
|
27
27
|
});
|
|
28
|
-
switch (
|
|
28
|
+
switch (authorization.object.typeOf) {
|
|
29
29
|
case factory.order.OrderType.Order:
|
|
30
|
-
const { orderNumber } =
|
|
30
|
+
const { orderNumber } = authorization.object;
|
|
31
31
|
if (typeof orderNumber === 'string' && orderNumber.length > 0) {
|
|
32
32
|
// reservationIdを含む注文の存在を確認するだけでよい
|
|
33
33
|
yield repos.order.findByOrderNumberAndReservationId({
|
|
@@ -39,7 +39,7 @@ function findByCode(params) {
|
|
|
39
39
|
}
|
|
40
40
|
break;
|
|
41
41
|
default:
|
|
42
|
-
throw new factory.errors.NotImplemented(`authorization object typeOf: ${
|
|
42
|
+
throw new factory.errors.NotImplemented(`authorization object typeOf: ${authorization.object.typeOf} not implemented`);
|
|
43
43
|
}
|
|
44
44
|
const reservationFromRepo = yield repos.reservation.findById({
|
|
45
45
|
id: reservationId,
|
|
@@ -28,10 +28,11 @@ function verifyToken4reservation(params) {
|
|
|
28
28
|
})({});
|
|
29
29
|
}
|
|
30
30
|
else if (typeof ticketToken === 'string' && ticketToken.length > 0) {
|
|
31
|
-
|
|
31
|
+
const findValidOneByCodeResult = yield repos.authorization.findValidOneByCode({
|
|
32
32
|
project: { id: params.project.id },
|
|
33
33
|
code: ticketToken
|
|
34
34
|
});
|
|
35
|
+
payload = findValidOneByCodeResult.object;
|
|
35
36
|
}
|
|
36
37
|
else {
|
|
37
38
|
throw new factory.errors.ArgumentNull('ticket.token or ticket.ticketToken');
|
|
@@ -49,14 +49,14 @@ function onAuthorizationCreated(params) {
|
|
|
49
49
|
let reservationNumbers = [];
|
|
50
50
|
// 発券対象イベントID
|
|
51
51
|
let reservationForIds = [];
|
|
52
|
-
const
|
|
52
|
+
const authorization = yield repos.code.findValidOneByCode({
|
|
53
53
|
code: params.code,
|
|
54
54
|
project: { id: params.project.id }
|
|
55
55
|
});
|
|
56
|
-
switch (
|
|
56
|
+
switch (authorization.object.typeOf) {
|
|
57
57
|
case factory.order.OrderType.Order:
|
|
58
58
|
// 注文検索
|
|
59
|
-
const orderNumber =
|
|
59
|
+
const orderNumber = authorization.object.orderNumber;
|
|
60
60
|
if (typeof orderNumber === 'string' && orderNumber.length > 0) {
|
|
61
61
|
reservationNumbers = yield repos.acceptedOffer.distinctValues({
|
|
62
62
|
orderNumber: { $in: [orderNumber] }
|
|
@@ -68,7 +68,7 @@ function onAuthorizationCreated(params) {
|
|
|
68
68
|
break;
|
|
69
69
|
case 'OwnershipInfo':
|
|
70
70
|
// 所有権検索
|
|
71
|
-
const ownershipInfoId =
|
|
71
|
+
const ownershipInfoId = authorization.object.id;
|
|
72
72
|
if (typeof ownershipInfoId === 'string' && ownershipInfoId.length > 0) {
|
|
73
73
|
const ownershipInfo = yield repos.ownershipInfo.findById({ id: ownershipInfoId });
|
|
74
74
|
// 座席予約に対する所有権であれば発券
|
package/package.json
CHANGED