@chevre/domain 22.10.0-alpha.2 → 22.10.0-alpha.4
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/issuer/renameIssuerIdentifier.ts +61 -0
- package/example/src/signPayload.ts +47 -0
- package/lib/chevre/repo/issuer.d.ts +3 -0
- package/lib/chevre/repo/issuer.js +14 -0
- package/lib/chevre/service/offer/event/authorize/factory.d.ts +3 -0
- package/lib/chevre/service/offer/event/authorize/factory.js +3 -2
- package/lib/chevre/service/offer/event/authorize/processStartReserve4chevre.d.ts +5 -1
- package/lib/chevre/service/offer/event/authorize/processStartReserve4chevre.js +2 -1
- package/lib/chevre/service/offer/event/authorize.js +3 -9
- package/package.json +1 -1
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
|
|
4
|
+
import { chevre } from '../../../../lib/index';
|
|
5
|
+
|
|
6
|
+
const NEW_IDENTIFIER = 'DefaultTokenIssuer';
|
|
7
|
+
|
|
8
|
+
// tslint:disable-next-line:max-func-body-length
|
|
9
|
+
async function main() {
|
|
10
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
11
|
+
|
|
12
|
+
const issuerRepo = await chevre.repository.Issuer.createInstance(mongoose.connection);
|
|
13
|
+
|
|
14
|
+
const cursor = issuerRepo.getCursor(
|
|
15
|
+
{
|
|
16
|
+
// 'project.id': { $ne: EXCLUDED_PROJECT_ID }
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
_id: 1,
|
|
20
|
+
project: 1,
|
|
21
|
+
identifier: 1,
|
|
22
|
+
url: 1,
|
|
23
|
+
name: 1
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
console.log('docs found');
|
|
27
|
+
|
|
28
|
+
let i = 0;
|
|
29
|
+
let updateCount = 0;
|
|
30
|
+
await cursor.eachAsync(async (doc) => {
|
|
31
|
+
i += 1;
|
|
32
|
+
const issuer: chevre.factory.issuer.IIssuer = doc.toObject();
|
|
33
|
+
|
|
34
|
+
const alreadyMigrated = issuer.identifier === NEW_IDENTIFIER;
|
|
35
|
+
|
|
36
|
+
if (alreadyMigrated) {
|
|
37
|
+
console.log(
|
|
38
|
+
'already migrated.',
|
|
39
|
+
issuer.id, issuer.project.id, issuer.identifier, i);
|
|
40
|
+
} else {
|
|
41
|
+
console.log(
|
|
42
|
+
'updating...',
|
|
43
|
+
issuer.id, issuer.project.id, issuer.identifier, i);
|
|
44
|
+
await issuerRepo.renameIssuerIdentifier({
|
|
45
|
+
id: issuer.id,
|
|
46
|
+
identifier: NEW_IDENTIFIER
|
|
47
|
+
});
|
|
48
|
+
updateCount += 1;
|
|
49
|
+
console.log(
|
|
50
|
+
'updated.',
|
|
51
|
+
issuer.id, issuer.project.id, issuer.identifier, i);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
console.log(i, 'docs checked');
|
|
56
|
+
console.log(updateCount, 'docs updated');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
main()
|
|
60
|
+
.then()
|
|
61
|
+
.catch(console.error);
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import * as jwt from 'jsonwebtoken';
|
|
2
|
+
|
|
3
|
+
async function main(): Promise<any> {
|
|
4
|
+
const payload = {
|
|
5
|
+
member: {
|
|
6
|
+
identifier: '',
|
|
7
|
+
// member: {
|
|
8
|
+
// identifier: '',
|
|
9
|
+
// endDate: '',
|
|
10
|
+
// startDate: ''
|
|
11
|
+
// }
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const token = await new Promise<string>((resolve, reject) => {
|
|
16
|
+
// 所有権を暗号化する
|
|
17
|
+
jwt.sign(
|
|
18
|
+
payload,
|
|
19
|
+
'12345qwert',
|
|
20
|
+
{
|
|
21
|
+
// algorithm: jwtSetting.algorithm,
|
|
22
|
+
issuer: 'https://example.com',
|
|
23
|
+
expiresIn: 1800
|
|
24
|
+
// subject,
|
|
25
|
+
},
|
|
26
|
+
(err, encoded) => {
|
|
27
|
+
if (err instanceof Error) {
|
|
28
|
+
reject(err);
|
|
29
|
+
} else {
|
|
30
|
+
if (typeof encoded !== 'string') {
|
|
31
|
+
reject(new Error('cannot be signed unexpectedly'));
|
|
32
|
+
} else {
|
|
33
|
+
resolve(encoded);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
// tslint:disable-next-line:no-console
|
|
40
|
+
console.log(token);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
main()
|
|
44
|
+
// tslint:disable-next-line:no-console
|
|
45
|
+
.then(console.log)
|
|
46
|
+
// tslint:disable-next-line:no-console
|
|
47
|
+
.catch(console.error);
|
|
@@ -13,6 +13,9 @@ export declare class IssuerRepo {
|
|
|
13
13
|
saveIssuer(params: IIssuer): Promise<{
|
|
14
14
|
id: string;
|
|
15
15
|
}>;
|
|
16
|
+
renameIssuerIdentifier(params: Pick<IIssuer, 'id' | 'identifier'>): Promise<{
|
|
17
|
+
id: string;
|
|
18
|
+
}>;
|
|
16
19
|
projectPublicFields(params: ISearchConditions): Promise<Pick<IIssuer, 'id' | 'identifier' | 'project' | 'name' | 'url'>[]>;
|
|
17
20
|
findById(params: {
|
|
18
21
|
id: string;
|
|
@@ -69,6 +69,20 @@ class IssuerRepo {
|
|
|
69
69
|
return { id: savedId };
|
|
70
70
|
});
|
|
71
71
|
}
|
|
72
|
+
renameIssuerIdentifier(params) {
|
|
73
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
let savedId;
|
|
75
|
+
let doc;
|
|
76
|
+
const { id } = params, updateFields = __rest(params, ["id"]);
|
|
77
|
+
doc = yield this.issuerModel.findOneAndUpdate({ _id: { $eq: params.id } }, { $set: updateFields }, { upsert: false, new: true, projection: { _id: 1 } })
|
|
78
|
+
.exec();
|
|
79
|
+
savedId = params.id;
|
|
80
|
+
if (doc === null) {
|
|
81
|
+
throw new factory.errors.NotFound(this.issuerModel.modelName);
|
|
82
|
+
}
|
|
83
|
+
return { id: savedId };
|
|
84
|
+
});
|
|
85
|
+
}
|
|
72
86
|
projectPublicFields(params) {
|
|
73
87
|
return __awaiter(this, void 0, void 0, function* () {
|
|
74
88
|
var _a;
|
|
@@ -7,6 +7,9 @@ declare function createReserveTransactionStartParams(params: {
|
|
|
7
7
|
acceptedOffers: factory.assetTransaction.reserve.IAcceptedTicketOfferWithoutDetail[];
|
|
8
8
|
event: {
|
|
9
9
|
id: string;
|
|
10
|
+
offers?: {
|
|
11
|
+
offeredBy?: string;
|
|
12
|
+
};
|
|
10
13
|
};
|
|
11
14
|
broker?: factory.reservation.IBroker<factory.reservationType>;
|
|
12
15
|
transaction: Pick<factory.transaction.ITransaction<factory.transactionType.PlaceOrder>, 'expires' | 'seller'>;
|
|
@@ -8,7 +8,7 @@ exports.responseBody2acceptedOffers4result = responseBody2acceptedOffers4result;
|
|
|
8
8
|
const moment = require("moment");
|
|
9
9
|
const factory = require("../../../../factory");
|
|
10
10
|
function createReserveTransactionStartParams(params) {
|
|
11
|
-
var _a;
|
|
11
|
+
var _a, _b;
|
|
12
12
|
const { transaction, transactionNumber } = params;
|
|
13
13
|
const { seller } = transaction;
|
|
14
14
|
const acceptedTicketOffersWithoutDetail = (Array.isArray(params.acceptedOffers))
|
|
@@ -48,7 +48,8 @@ function createReserveTransactionStartParams(params) {
|
|
|
48
48
|
// }
|
|
49
49
|
// ]
|
|
50
50
|
};
|
|
51
|
-
const
|
|
51
|
+
const offeredByToken = (_b = params.event.offers) === null || _b === void 0 ? void 0 : _b.offeredBy;
|
|
52
|
+
const object = Object.assign({ acceptedOffer: acceptedTicketOffersWithoutDetail, reservationFor: Object.assign({ id: params.event.id }, (typeof offeredByToken === 'string') ? { offers: { offeredBy: offeredByToken } } : undefined) }, (params.broker !== undefined) ? { broker: params.broker } : undefined);
|
|
52
53
|
return {
|
|
53
54
|
project: { typeOf: factory.organizationType.Project, id: params.project.id },
|
|
54
55
|
typeOf: factory.assetTransactionType.Reserve,
|
|
@@ -24,7 +24,11 @@ import type { TicketRepo } from '../../../../repo/ticket';
|
|
|
24
24
|
import { IResultAcceptedOffer } from './factory';
|
|
25
25
|
declare function processStartReserve4chevre(params: {
|
|
26
26
|
acceptedOffers: factory.assetTransaction.reserve.IAcceptedTicketOfferWithoutDetail[];
|
|
27
|
-
event: Pick<IMinimizedIndividualEvent<factory.eventType.ScreeningEvent>, 'id'
|
|
27
|
+
event: Pick<IMinimizedIndividualEvent<factory.eventType.ScreeningEvent>, 'id'> & {
|
|
28
|
+
offers?: {
|
|
29
|
+
offeredBy?: string;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
28
32
|
broker?: factory.reservation.IBroker<factory.reservationType>;
|
|
29
33
|
transactionNumber: string;
|
|
30
34
|
transaction: Pick<factory.transaction.ITransaction<factory.transactionType.PlaceOrder>, 'agent' | 'expires' | 'id' | 'project' | 'seller' | 'typeOf'>;
|
|
@@ -20,12 +20,13 @@ function processStartReserve4chevre(params, options) {
|
|
|
20
20
|
// jwt: JWTCredentials;
|
|
21
21
|
// }
|
|
22
22
|
) => __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
var _a;
|
|
23
24
|
const { event, transaction, transactionNumber } = params;
|
|
24
25
|
let acceptedOffers4result = [];
|
|
25
26
|
// 予約取引開始
|
|
26
27
|
const startParams = (0, factory_1.createReserveTransactionStartParams)(Object.assign({ project: transaction.project,
|
|
27
28
|
// object: <IObjectWithDetail>action.object,
|
|
28
|
-
acceptedOffers: params.acceptedOffers, event: { id: event.id }, transaction,
|
|
29
|
+
acceptedOffers: params.acceptedOffers, event: Object.assign({ id: event.id }, (typeof ((_a = event.offers) === null || _a === void 0 ? void 0 : _a.offeredBy) === 'string') ? { offers: { offeredBy: event.offers.offeredBy } } : undefined), transaction,
|
|
29
30
|
transactionNumber }, (params.broker !== undefined) ? { broker: params.broker } : undefined));
|
|
30
31
|
const startParamObject = yield validateObjectWithoutDetail(startParams, { id: params.transaction.id })(repos);
|
|
31
32
|
const startReserveTransactionResult = yield ReserveTransactionService.start(Object.assign(Object.assign({}, startParams), { object: startParamObject,
|
|
@@ -82,7 +82,7 @@ function authorize(params, options) {
|
|
|
82
82
|
}
|
|
83
83
|
function validateCreateRequest(params) {
|
|
84
84
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
85
|
-
var _a, _b;
|
|
85
|
+
var _a, _b, _c;
|
|
86
86
|
const transaction = yield repos.transaction.projectFieldsInProgressById({
|
|
87
87
|
typeOf: factory.transactionType.PlaceOrder,
|
|
88
88
|
id: params.transaction.id
|
|
@@ -98,14 +98,8 @@ function validateCreateRequest(params) {
|
|
|
98
98
|
if (typeof ((_b = params.object.reservationFor) === null || _b === void 0 ? void 0 : _b.id) !== 'string' || params.object.reservationFor.id.length === 0) {
|
|
99
99
|
throw new factory.errors.ArgumentNull('object.reservationFor.id');
|
|
100
100
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
// id: params.object.reservationFor.id
|
|
104
|
-
// });
|
|
105
|
-
const event = {
|
|
106
|
-
id: params.object.reservationFor.id,
|
|
107
|
-
typeOf: factory.eventType.ScreeningEvent // ひとまずfix(2024-07-17~)
|
|
108
|
-
};
|
|
101
|
+
const offeredByToken = (_c = params.object.reservationFor.offers) === null || _c === void 0 ? void 0 : _c.offeredBy;
|
|
102
|
+
const event = Object.assign({ id: params.object.reservationFor.id, typeOf: factory.eventType.ScreeningEvent }, (typeof offeredByToken === 'string') ? { offers: { offeredBy: offeredByToken } } : undefined);
|
|
109
103
|
return { transaction, event };
|
|
110
104
|
});
|
|
111
105
|
}
|
package/package.json
CHANGED