@chevre/domain 22.11.0-alpha.2 → 22.11.0-alpha.20
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/assetTransaction/processReserve.ts +0 -1
- package/example/src/chevre/notifyAbortedTasksByEmail.ts +1 -1
- package/example/src/chevre/orders/searchWithUnwoundAcceptedOffers.ts +73 -0
- package/example/src/chevre/roles/addAdminPermissionIfNotExists.ts +132 -0
- package/example/src/chevre/roles/addDefaultPermissionIfNotExists.ts +37 -0
- package/example/src/chevre/roles/addEventOfferPermissionIfNotExists.ts +27 -0
- package/example/src/chevre/roles/addPermissionIfNotExists.ts +39 -6
- package/example/src/chevre/roles/addProjectCreatorRole.ts +48 -0
- package/example/src/chevre/roles/assignGlobalRoles.ts +72 -0
- package/example/src/chevre/roles/findPermissions.ts +84 -0
- package/example/src/chevre/roles/findRoleNames.ts +117 -0
- package/example/src/chevre/roles/removeConsolePermissionIfExists.ts +38 -0
- package/example/src/chevre/roles/removePermissionFromAPIRoles.ts +46 -0
- package/example/src/chevre/roles/removePermissionIfExists.ts +39 -0
- package/example/src/chevre/settings/addSettings.ts +23 -17
- package/example/src/chevre/stockHolder/checkRedisKeyCount.ts +11 -20
- package/example/src/chevre/unsetUnnecessaryFields.ts +8 -5
- package/example/src/idaas/auth0/adminApplications.ts +183 -0
- package/example/src/idaas/auth0/getToken.ts +55 -0
- package/example/src/idaas/auth0/getTokenByPrivateKeyJWT.ts +84 -0
- package/example/src/regex.ts +31 -0
- package/lib/chevre/eventEmitter/task.d.ts +13 -4
- package/lib/chevre/index.d.ts +0 -2
- package/lib/chevre/index.js +0 -10
- package/lib/chevre/repo/acceptedOffer.d.ts +3 -1
- package/lib/chevre/repo/acceptedOffer.js +11 -3
- package/lib/chevre/repo/confirmationNumber.d.ts +0 -11
- package/lib/chevre/repo/confirmationNumber.js +15 -54
- package/lib/chevre/repo/identity.d.ts +11 -33
- package/lib/chevre/repo/identity.js +10 -15
- package/lib/chevre/repo/member.d.ts +22 -4
- package/lib/chevre/repo/member.js +81 -27
- package/lib/chevre/repo/mongoose/schemas/identity.d.ts +1 -1
- package/lib/chevre/repo/mongoose/schemas/member/global.d.ts +14 -0
- package/lib/chevre/repo/mongoose/schemas/member/global.js +82 -0
- package/lib/chevre/repo/mongoose/schemas/setting.d.ts +11 -0
- package/lib/chevre/repo/mongoose/schemas/setting.js +1 -0
- package/lib/chevre/repo/orderNumber.d.ts +0 -11
- package/lib/chevre/repo/orderNumber.js +13 -51
- package/lib/chevre/repo/role.d.ts +16 -4
- package/lib/chevre/repo/role.js +71 -32
- package/lib/chevre/repo/serviceOutputIdentifier.d.ts +0 -4
- package/lib/chevre/repo/serviceOutputIdentifier.js +13 -38
- package/lib/chevre/repo/setting.d.ts +5 -10
- package/lib/chevre/repo/setting.js +4 -7
- package/lib/chevre/repo/stockHolder.js +0 -11
- package/lib/chevre/repo/task.d.ts +31 -25
- package/lib/chevre/repo/task.js +110 -201
- package/lib/chevre/repo/transactionNumber.d.ts +0 -11
- package/lib/chevre/repo/transactionNumber.js +13 -51
- package/lib/chevre/repo/transactionNumberCounter.d.ts +0 -10
- package/lib/chevre/repo/transactionNumberCounter.js +34 -29
- package/lib/chevre/service/assetTransaction/cancelReservation/start.d.ts +1 -1
- package/lib/chevre/service/code.d.ts +5 -28
- package/lib/chevre/service/code.js +3 -79
- package/lib/chevre/service/iam.d.ts +17 -7
- package/lib/chevre/service/iam.js +26 -6
- package/lib/chevre/service/notification/notifyAbortedTasksByEmail.d.ts +15 -0
- package/lib/chevre/service/notification/notifyAbortedTasksByEmail.js +38 -0
- package/lib/chevre/service/notification.d.ts +2 -1
- package/lib/chevre/service/notification.js +3 -1
- package/lib/chevre/service/task/acceptCOAOffer.d.ts +1 -1
- package/lib/chevre/service/task/acceptCOAOffer.js +6 -5
- package/lib/chevre/service/task/aggregateOffers.d.ts +1 -1
- package/lib/chevre/service/task/aggregateOnSystem.d.ts +4 -2
- package/lib/chevre/service/task/aggregateScreeningEvent.d.ts +1 -1
- package/lib/chevre/service/task/authorizePayment.d.ts +1 -1
- package/lib/chevre/service/task/authorizePayment.js +7 -6
- package/lib/chevre/service/task/cancelMoneyTransfer.d.ts +1 -1
- package/lib/chevre/service/task/cancelPendingReservation.d.ts +1 -1
- package/lib/chevre/service/task/cancelReservation.d.ts +1 -1
- package/lib/chevre/service/task/checkMovieTicket.d.ts +1 -1
- package/lib/chevre/service/task/checkMovieTicket.js +4 -3
- package/lib/chevre/service/task/checkResource.d.ts +1 -1
- package/lib/chevre/service/task/confirmMoneyTransfer.d.ts +1 -1
- package/lib/chevre/service/task/confirmPayTransaction.d.ts +1 -1
- package/lib/chevre/service/task/confirmRegisterService.d.ts +1 -1
- package/lib/chevre/service/task/confirmRegisterServiceTransaction.d.ts +1 -1
- package/lib/chevre/service/task/confirmReserveTransaction.d.ts +1 -1
- package/lib/chevre/service/task/createAccountingReport.d.ts +1 -1
- package/lib/chevre/service/task/createEvent.d.ts +1 -1
- package/lib/chevre/service/task/deletePerson.d.ts +1 -1
- package/lib/chevre/service/task/deleteTransaction.d.ts +1 -1
- package/lib/chevre/service/task/givePointAward.d.ts +1 -1
- package/lib/chevre/service/task/givePointAward.js +1 -1
- package/lib/chevre/service/task/handleNotification.d.ts +4 -2
- package/lib/chevre/service/task/importEventCapacitiesFromCOA.d.ts +1 -1
- package/lib/chevre/service/task/importEventsFromCOA.d.ts +1 -1
- package/lib/chevre/service/task/importOffersFromCOA.d.ts +1 -1
- package/lib/chevre/service/task/invalidatePaymentUrl.d.ts +1 -1
- package/lib/chevre/service/task/moneyTransfer.d.ts +1 -1
- package/lib/chevre/service/task/moneyTransfer.js +1 -1
- package/lib/chevre/service/task/onAssetTransactionStatusChanged.d.ts +1 -1
- package/lib/chevre/service/task/onAuthorizationCreated.d.ts +1 -1
- package/lib/chevre/service/task/onEventChanged.d.ts +1 -1
- package/lib/chevre/service/task/onOrderPaymentCompleted.d.ts +1 -1
- package/lib/chevre/service/task/onResourceUpdated.d.ts +1 -1
- package/lib/chevre/service/task/pay.d.ts +1 -1
- package/lib/chevre/service/task/placeOrder.d.ts +1 -1
- package/lib/chevre/service/task/publishPaymentUrl.d.ts +1 -1
- package/lib/chevre/service/task/publishPaymentUrl.js +6 -7
- package/lib/chevre/service/task/refund.d.ts +1 -1
- package/lib/chevre/service/task/refund.js +1 -1
- package/lib/chevre/service/task/registerService.d.ts +1 -1
- package/lib/chevre/service/task/reserve.d.ts +1 -1
- package/lib/chevre/service/task/returnMoneyTransfer.d.ts +1 -1
- package/lib/chevre/service/task/returnMoneyTransfer.js +1 -1
- package/lib/chevre/service/task/returnOrder.d.ts +1 -1
- package/lib/chevre/service/task/returnPayTransaction.d.ts +1 -1
- package/lib/chevre/service/task/returnPayTransaction.js +1 -1
- package/lib/chevre/service/task/returnPointAward.d.ts +1 -1
- package/lib/chevre/service/task/returnPointAward.js +1 -1
- package/lib/chevre/service/task/returnReserveTransaction.d.ts +1 -1
- package/lib/chevre/service/task/returnReserveTransaction.js +1 -1
- package/lib/chevre/service/task/sendEmailMessage.d.ts +1 -1
- package/lib/chevre/service/task/sendOrder.d.ts +1 -1
- package/lib/chevre/service/task/triggerWebhook.d.ts +1 -1
- package/lib/chevre/service/task/useReservation.d.ts +1 -1
- package/lib/chevre/service/task/voidMoneyTransferTransaction.d.ts +1 -1
- package/lib/chevre/service/task/voidPayTransaction.d.ts +1 -1
- package/lib/chevre/service/task/voidPayment.d.ts +1 -1
- package/lib/chevre/service/task/voidRegisterServiceTransaction.d.ts +1 -1
- package/lib/chevre/service/task/voidReserveTransaction.d.ts +1 -1
- package/lib/chevre/service/task/voidReserveTransaction.js +4 -3
- package/lib/chevre/service/task.d.ts +1 -23
- package/lib/chevre/service/task.js +3 -110
- package/lib/chevre/service/taskHandler.d.ts +26 -0
- package/lib/chevre/service/taskHandler.js +139 -0
- package/lib/chevre/service/validation/validateOrder.js +55 -37
- package/lib/chevre/service.d.ts +0 -4
- package/lib/chevre/service.js +10 -14
- package/lib/chevre/settings/aggregation.d.ts +6 -1
- package/lib/chevre/settings/aggregation.js +2 -1
- package/package.json +5 -3
- package/example/src/chevre/adminAuth/adminIdentity.ts +0 -38
- package/example/src/chevre/findExecutableTask.ts +0 -50
- package/example/src/chevre/findSetting.ts +0 -79
- package/example/src/chevre/roles/addRoleMembers.ts +0 -75
- package/example/src/chevre/searchPermissions.ts +0 -46
- package/example/src/chevre/transactionNumber/publishConfimationNumber.ts +0 -37
- package/example/src/chevre/transactionNumber/publishOrderNumber.ts +0 -40
- package/example/src/chevre/transactionNumber/setUseMongo4confirmationNumberFrom.ts +0 -45
- package/example/src/chevre/transactionNumber/setUseMongo4orderNumberFrom.ts +0 -41
- package/example/src/chevre/transactionNumber/setUseMongo4transactionNumberFrom.ts +0 -41
- package/lib/chevre/adminAuth.d.ts +0 -2
- package/lib/chevre/adminAuth.js +0 -6
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
|
|
4
|
+
import { chevre } from '../../../../lib/index';
|
|
5
|
+
|
|
6
|
+
async function main() {
|
|
7
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
8
|
+
|
|
9
|
+
const roleRepo = await chevre.repository.Role.createInstance(mongoose.connection);
|
|
10
|
+
|
|
11
|
+
const permissions = [
|
|
12
|
+
'assetTransactions.cancelReservation.write',
|
|
13
|
+
'orders.read',
|
|
14
|
+
'orders.update',
|
|
15
|
+
'reservations.attended',
|
|
16
|
+
'reservations.read'
|
|
17
|
+
];
|
|
18
|
+
for (const permission of permissions) {
|
|
19
|
+
const roles = await roleRepo.projectFields(
|
|
20
|
+
{
|
|
21
|
+
permissions: { $eq: permission }
|
|
22
|
+
},
|
|
23
|
+
['roleName']
|
|
24
|
+
);
|
|
25
|
+
console.log(roles, permission);
|
|
26
|
+
for (const { roleName } of roles) {
|
|
27
|
+
const result = await roleRepo.removePermissionIfExists({
|
|
28
|
+
roleName: { $eq: roleName },
|
|
29
|
+
permission
|
|
30
|
+
});
|
|
31
|
+
console.log('permission removed.', permission, result, roleName);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
main()
|
|
37
|
+
.then()
|
|
38
|
+
.catch(console.error);
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
|
|
4
|
+
import { chevre } from '../../../../lib/index';
|
|
5
|
+
|
|
6
|
+
async function main() {
|
|
7
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
8
|
+
|
|
9
|
+
const roleRepo = await chevre.repository.Role.createInstance(mongoose.connection);
|
|
10
|
+
|
|
11
|
+
const permissions = [
|
|
12
|
+
'categoryCodes.read',
|
|
13
|
+
'creativeWorks.read',
|
|
14
|
+
'events.read',
|
|
15
|
+
'places.read',
|
|
16
|
+
'products.read',
|
|
17
|
+
'sellers.read'
|
|
18
|
+
];
|
|
19
|
+
for (const permission of permissions) {
|
|
20
|
+
const roles = await roleRepo.projectFields(
|
|
21
|
+
{
|
|
22
|
+
permissions: { $eq: permission },
|
|
23
|
+
roleName: {
|
|
24
|
+
$in: [
|
|
25
|
+
chevre.factory.role.organizationRole.RoleName.Customer,
|
|
26
|
+
chevre.factory.role.organizationRole.RoleName.POS,
|
|
27
|
+
chevre.factory.role.organizationRole.RoleName.EventsViewer
|
|
28
|
+
]
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
['roleName']
|
|
32
|
+
);
|
|
33
|
+
console.log('roles found.', roles, permission);
|
|
34
|
+
for (const { roleName } of roles) {
|
|
35
|
+
const result = await roleRepo.removePermissionIfExists({
|
|
36
|
+
roleName: { $eq: roleName },
|
|
37
|
+
permission
|
|
38
|
+
});
|
|
39
|
+
console.log('permission removed.', permission, result, roleName);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
main()
|
|
45
|
+
.then()
|
|
46
|
+
.catch(console.error);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
|
|
4
|
+
import { chevre } from '../../../../lib/index';
|
|
5
|
+
|
|
6
|
+
async function main() {
|
|
7
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
8
|
+
|
|
9
|
+
const roleRepo = await chevre.repository.Role.createInstance(mongoose.connection);
|
|
10
|
+
|
|
11
|
+
const permissions = [
|
|
12
|
+
'tokens',
|
|
13
|
+
'authorizations.create',
|
|
14
|
+
'permits.read',
|
|
15
|
+
'tasks.read',
|
|
16
|
+
'transactionNumbers.write',
|
|
17
|
+
'chevre.admin'
|
|
18
|
+
];
|
|
19
|
+
for (const permission of permissions) {
|
|
20
|
+
const roles = await roleRepo.projectFields(
|
|
21
|
+
{
|
|
22
|
+
permissions: { $eq: permission }
|
|
23
|
+
},
|
|
24
|
+
['roleName']
|
|
25
|
+
);
|
|
26
|
+
console.log(roles, permission);
|
|
27
|
+
for (const { roleName } of roles) {
|
|
28
|
+
const result = await roleRepo.removePermissionIfExists({
|
|
29
|
+
roleName: { $eq: roleName },
|
|
30
|
+
permission
|
|
31
|
+
});
|
|
32
|
+
console.log('permission removed.', permission, result, roleName);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
main()
|
|
38
|
+
.then()
|
|
39
|
+
.catch(console.error);
|
|
@@ -3,28 +3,34 @@ import * as mongoose from 'mongoose';
|
|
|
3
3
|
|
|
4
4
|
import { chevre } from '../../../../lib/index';
|
|
5
5
|
|
|
6
|
+
const { INFORM_TASK_AGG_URL } = process.env;
|
|
7
|
+
if (typeof INFORM_TASK_AGG_URL !== 'string') {
|
|
8
|
+
throw new Error('INFORM_TASK_AGG_URL required');
|
|
9
|
+
}
|
|
10
|
+
|
|
6
11
|
async function main() {
|
|
7
12
|
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
8
13
|
|
|
9
14
|
const settingRepo = await chevre.repository.Setting.createInstance(mongoose.connection);
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
// const setting = await settingRepo.findOne({ project: { id: { $eq: '*' } } }, ['onTaskStatusChanged']);
|
|
16
|
+
// update
|
|
17
|
+
await settingRepo.updateByProject(
|
|
18
|
+
{ project: { id: { $eq: '*' } } },
|
|
19
|
+
{
|
|
20
|
+
onTaskStatusChanged: {
|
|
21
|
+
informTask: [{
|
|
22
|
+
recipient: {
|
|
23
|
+
name: 'Aggregation Service',
|
|
24
|
+
url: INFORM_TASK_AGG_URL
|
|
25
|
+
}
|
|
26
|
+
}],
|
|
27
|
+
informTaskNames: [
|
|
28
|
+
chevre.factory.taskName.Pay
|
|
29
|
+
]
|
|
23
30
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
console.log('updated.');
|
|
28
34
|
}
|
|
29
35
|
|
|
30
36
|
main()
|
|
@@ -38,7 +38,6 @@ function countRedisKeyByProject(params: {
|
|
|
38
38
|
{
|
|
39
39
|
'project.id': {
|
|
40
40
|
$eq: params.project.id
|
|
41
|
-
// $in: useMongoAsStockHolderProjects
|
|
42
41
|
},
|
|
43
42
|
// startDate: {
|
|
44
43
|
// $gte: params.now
|
|
@@ -93,30 +92,22 @@ function countRedisKeyByProject(params: {
|
|
|
93
92
|
async function main() {
|
|
94
93
|
const eventRepo = await chevre.repository.Event.createInstance(mongoose.connection);
|
|
95
94
|
const projectRepo = await chevre.repository.Project.createInstance(mongoose.connection);
|
|
96
|
-
const settingRepo = await chevre.repository.Setting.createInstance(mongoose.connection);
|
|
95
|
+
// const settingRepo = await chevre.repository.Setting.createInstance(mongoose.connection);
|
|
97
96
|
const stockHolderRepo = await chevre.repository.StockHolder.createInstance(
|
|
98
97
|
client,
|
|
99
98
|
mongoose.connection
|
|
100
99
|
);
|
|
101
100
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
// 全プロジェクト
|
|
111
|
-
useMongoAsStockHolderProjects = (await projectRepo.projectFields(
|
|
112
|
-
{
|
|
113
|
-
// id: { $eq: 'xxx' }
|
|
114
|
-
},
|
|
115
|
-
['id']
|
|
116
|
-
)).map(({ id }) => id);
|
|
117
|
-
}
|
|
101
|
+
let checkingProjects: string[] = [];
|
|
102
|
+
// 全プロジェクト
|
|
103
|
+
checkingProjects = (await projectRepo.projectFields(
|
|
104
|
+
{
|
|
105
|
+
// id: { $eq: 'xxx' }
|
|
106
|
+
},
|
|
107
|
+
['id']
|
|
108
|
+
)).map(({ id }) => id);
|
|
118
109
|
|
|
119
|
-
|
|
110
|
+
checkingProjects = checkingProjects.filter((id) => id.slice(0, 6) !== 'sskts-');
|
|
120
111
|
|
|
121
112
|
const results: {
|
|
122
113
|
project: { id: string };
|
|
@@ -127,7 +118,7 @@ async function main() {
|
|
|
127
118
|
const now = moment()
|
|
128
119
|
.add(0, 'days')
|
|
129
120
|
.toDate();
|
|
130
|
-
for (const projectId of
|
|
121
|
+
for (const projectId of checkingProjects) {
|
|
131
122
|
const { checkedCount, redisKeyCount } = await countRedisKeyByProject({
|
|
132
123
|
project: { id: projectId },
|
|
133
124
|
now
|
|
@@ -9,17 +9,20 @@ import { chevre } from '../../../lib/index';
|
|
|
9
9
|
async function main() {
|
|
10
10
|
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
11
11
|
|
|
12
|
-
const
|
|
12
|
+
const settingRepo = await chevre.repository.Setting.createInstance(mongoose.connection);
|
|
13
13
|
|
|
14
14
|
let updateResult: any;
|
|
15
15
|
|
|
16
|
-
updateResult = await
|
|
16
|
+
updateResult = await settingRepo.unsetUnnecessaryFields({
|
|
17
17
|
filter: {
|
|
18
|
-
'
|
|
19
|
-
// _id: { $eq: 'blj55y1mo' }
|
|
18
|
+
'project.id': { $eq: '*' }
|
|
20
19
|
},
|
|
21
20
|
$unset: {
|
|
22
|
-
|
|
21
|
+
useMongoAsStockHolder: 1,
|
|
22
|
+
useMongoAsStockHolderProjects: 1
|
|
23
|
+
// useMongo4confirmationNumberFrom: 1,
|
|
24
|
+
// useMongo4orderNumberFrom: 1,
|
|
25
|
+
// useMongo4transactionNumberFrom: 1
|
|
23
26
|
}
|
|
24
27
|
});
|
|
25
28
|
console.log(updateResult);
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
// tslint:disable:no-implicit-dependencies no-console no-magic-numbers
|
|
2
|
+
import { ManagementClient } from 'auth0';
|
|
3
|
+
import { readFileSync } from 'fs';
|
|
4
|
+
import * as moment from 'moment';
|
|
5
|
+
// import * as crypto from 'crypto'; // client_secret 生成用 (PKJWTなしの場合)
|
|
6
|
+
// import { JWK, importPKCS8, generateKeyPair, SignJWT } from 'jose'; // Private Key JWT 用
|
|
7
|
+
|
|
8
|
+
const PUBLIC_KEY_FILE_PATH = `${__dirname}/../../samplePublicKey.pem`;
|
|
9
|
+
const { AUTH0_DOMAIN, AUTH0_MGMT_CLIENT_ID, AUTH0_MGMT_CLIENT_SECRET, AUTH0_MGMT_API_AUDIENCE, AUTH0_AUDIENCE } = process.env;
|
|
10
|
+
|
|
11
|
+
if (typeof AUTH0_DOMAIN !== 'string'
|
|
12
|
+
|| typeof AUTH0_MGMT_CLIENT_ID !== 'string'
|
|
13
|
+
|| typeof AUTH0_MGMT_CLIENT_SECRET !== 'string'
|
|
14
|
+
|| typeof AUTH0_MGMT_API_AUDIENCE !== 'string'
|
|
15
|
+
|| typeof AUTH0_AUDIENCE !== 'string'
|
|
16
|
+
) {
|
|
17
|
+
throw new Error('set envs!');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// --- Auth0 ManagementClient の初期化 ---
|
|
21
|
+
const management = new ManagementClient({
|
|
22
|
+
domain: AUTH0_DOMAIN,
|
|
23
|
+
clientId: AUTH0_MGMT_CLIENT_ID,
|
|
24
|
+
clientSecret: AUTH0_MGMT_CLIENT_SECRET,
|
|
25
|
+
audience: AUTH0_MGMT_API_AUDIENCE
|
|
26
|
+
// scope: 'read:clients create:clients' // 必要なスコープを明示
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
async function sleep(waitInSeconds: number) {
|
|
30
|
+
await new Promise<void>((resolve) => {
|
|
31
|
+
setTimeout(
|
|
32
|
+
() => {
|
|
33
|
+
resolve();
|
|
34
|
+
},
|
|
35
|
+
waitInSeconds
|
|
36
|
+
);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* アプリケーションを検索し、存在しなければ作成します。
|
|
42
|
+
* Private Key JWT 認証を使用する前提。
|
|
43
|
+
*/
|
|
44
|
+
async function findOrCreateServiceAccount(
|
|
45
|
+
appName: string,
|
|
46
|
+
projectId: string,
|
|
47
|
+
roles: string[],
|
|
48
|
+
audience: string
|
|
49
|
+
) {
|
|
50
|
+
try {
|
|
51
|
+
console.log('getting organization...');
|
|
52
|
+
const getOrganizationResponse = await management.organizations.getByName({
|
|
53
|
+
name: projectId
|
|
54
|
+
});
|
|
55
|
+
const organization = getOrganizationResponse.data;
|
|
56
|
+
console.log('organization exists.', organization);
|
|
57
|
+
|
|
58
|
+
const newClient = (await management.clients.create({
|
|
59
|
+
name: appName,
|
|
60
|
+
app_type: 'non_interactive', // Machine to Machine アプリケーション
|
|
61
|
+
jwt_configuration: { // Private Key JWT の設定
|
|
62
|
+
alg: 'RS256' // 署名アルゴリズム
|
|
63
|
+
},
|
|
64
|
+
// token_endpoint_auth_method: 'client_secret_post',
|
|
65
|
+
client_authentication_methods: {
|
|
66
|
+
private_key_jwt: {
|
|
67
|
+
credentials: [{
|
|
68
|
+
alg: 'RS256',
|
|
69
|
+
/**
|
|
70
|
+
* Credential type. Supported types: public_key.
|
|
71
|
+
*
|
|
72
|
+
*/
|
|
73
|
+
credential_type: 'public_key',
|
|
74
|
+
// name?: string;
|
|
75
|
+
pem: readFileSync(PUBLIC_KEY_FILE_PATH, 'utf8')
|
|
76
|
+
|
|
77
|
+
}]
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
grant_types: ['client_credentials'],
|
|
81
|
+
organization_usage: 'require', // 組織での利用を許可
|
|
82
|
+
default_organization: {
|
|
83
|
+
organization_id: organization.id,
|
|
84
|
+
flows: ['client_credentials']
|
|
85
|
+
},
|
|
86
|
+
oidc_conformant: true,
|
|
87
|
+
client_metadata: {
|
|
88
|
+
roles: JSON.stringify(roles)
|
|
89
|
+
}
|
|
90
|
+
})).data;
|
|
91
|
+
console.log(`Successfully created new application: ${newClient.client_id} (${newClient.name})`);
|
|
92
|
+
|
|
93
|
+
console.log(`checking clientGrant... ${newClient.client_id} (${newClient.name})`);
|
|
94
|
+
await sleep(3000);
|
|
95
|
+
|
|
96
|
+
let clientGrant = (await management.clientGrants.getAll({
|
|
97
|
+
audience,
|
|
98
|
+
client_id: newClient.client_id
|
|
99
|
+
})).data.shift();
|
|
100
|
+
if (clientGrant === undefined) {
|
|
101
|
+
clientGrant = (await management.clientGrants.create({
|
|
102
|
+
client_id: newClient.client_id,
|
|
103
|
+
audience,
|
|
104
|
+
organization_usage: 'require',
|
|
105
|
+
allow_any_organization: false,
|
|
106
|
+
scope: ['iam.members.me.read']
|
|
107
|
+
})).data;
|
|
108
|
+
console.log(`clientGrant created. ${newClient.client_id} (${newClient.name})`);
|
|
109
|
+
} else {
|
|
110
|
+
console.log(`clientGrant already exists. ${newClient.client_id} (${newClient.name})`);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
console.log(`checking organizationClientGrant... ${newClient.client_id} (${newClient.name})`);
|
|
114
|
+
await sleep(3000);
|
|
115
|
+
const organizationClientGrant = (await management.organizations.getOrganizationClientGrants({
|
|
116
|
+
id: organization.id,
|
|
117
|
+
audience: 'https://development.apis.smart-theater.com',
|
|
118
|
+
client_id: newClient.client_id
|
|
119
|
+
})).data.shift();
|
|
120
|
+
if (organizationClientGrant === undefined) {
|
|
121
|
+
await management.organizations.postOrganizationClientGrants(
|
|
122
|
+
{
|
|
123
|
+
id: organization.id
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
grant_id: clientGrant.id
|
|
127
|
+
}
|
|
128
|
+
);
|
|
129
|
+
console.log(`organizationClientGrant created. ${newClient.client_id} (${newClient.name})`);
|
|
130
|
+
} else {
|
|
131
|
+
console.log(`organizationClientGrant already exists. ${newClient.client_id} (${newClient.name})`);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// 1. アプリケーションを検索 (名前で検索するのが一般的)
|
|
135
|
+
console.log('searching for applications...');
|
|
136
|
+
await sleep(3000);
|
|
137
|
+
|
|
138
|
+
await searchClients({ organization });
|
|
139
|
+
} catch (error) {
|
|
140
|
+
console.error(`Error finding or creating application: ${error.message}`);
|
|
141
|
+
throw error;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
async function searchClients(params: {
|
|
146
|
+
organization: { id: string };
|
|
147
|
+
}) {
|
|
148
|
+
const existingApps = await management.clients.getAll({
|
|
149
|
+
include_totals: true,
|
|
150
|
+
// app_type: 'non_interactive',
|
|
151
|
+
// is_global: false,
|
|
152
|
+
// page: 0,
|
|
153
|
+
// per_page: 50,
|
|
154
|
+
// q: `name:"${appName}"`, // 名前で検索
|
|
155
|
+
q: `client_grant.organization_id:"${params.organization.id}"`,
|
|
156
|
+
// from: undefined,
|
|
157
|
+
take: 50
|
|
158
|
+
// is_client_credentials: true // Machine to Machine アプリケーションに絞る
|
|
159
|
+
});
|
|
160
|
+
const clients = existingApps.data.clients;
|
|
161
|
+
console.log(clients.length, 'existingApps exist.', clients);
|
|
162
|
+
console.log(clients.length, 'clients found.');
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export async function run() {
|
|
166
|
+
if (typeof AUTH0_AUDIENCE !== 'string') {
|
|
167
|
+
throw new Error('set envs!');
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
try {
|
|
171
|
+
await findOrCreateServiceAccount(
|
|
172
|
+
`sampleServiceAccount-${moment()
|
|
173
|
+
.format('YYYY-MM-DDTHH:mm:ss')}`,
|
|
174
|
+
'cinerino',
|
|
175
|
+
['inventoryManager', 'user'],
|
|
176
|
+
AUTH0_AUDIENCE
|
|
177
|
+
);
|
|
178
|
+
} catch (error) {
|
|
179
|
+
console.error('Failed to run provisioning script:', error);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
run();
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// tslint:disable:no-implicit-dependencies no-console
|
|
2
|
+
interface IAuth0Config {
|
|
3
|
+
auth0Domain: string;
|
|
4
|
+
clientId: string;
|
|
5
|
+
clientSecret: string;
|
|
6
|
+
audience: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// 環境変数から機密情報を取得することを強く推奨します
|
|
10
|
+
const config: IAuth0Config = {
|
|
11
|
+
auth0Domain: String(process.env.AUTH0_DOMAIN),
|
|
12
|
+
clientId: String(process.env.AUTH0_CLIENT_ID),
|
|
13
|
+
clientSecret: String(process.env.AUTH0_CLIENT_SECRET),
|
|
14
|
+
audience: String(process.env.AUTH0_AUDIENCE)
|
|
15
|
+
// scopes: process.env.OKTA_SCOPES || 'api_access_scope openid', // 必要なスコープを指定
|
|
16
|
+
// authServerId: 'aussd9v86wlIar3cX697', // デフォルト承認サーバーを使用する場合はコメントアウトまたは指定しない
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
async function getToken() {
|
|
20
|
+
try {
|
|
21
|
+
const response = await fetch(
|
|
22
|
+
`https://${config.auth0Domain}/oauth/token`,
|
|
23
|
+
{
|
|
24
|
+
method: 'POST',
|
|
25
|
+
headers: { 'content-type': 'application/json' },
|
|
26
|
+
body: JSON.stringify({
|
|
27
|
+
client_id: config.clientId,
|
|
28
|
+
client_secret: config.clientSecret,
|
|
29
|
+
audience: config.audience,
|
|
30
|
+
grant_type: 'client_credentials'
|
|
31
|
+
// organization: 'org_zuMP9ng42QSgZ5Kn'
|
|
32
|
+
})
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
if (!response.ok) {
|
|
36
|
+
console.log(await response.json());
|
|
37
|
+
throw new Error('Network response was not ok');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const data = await response.json();
|
|
41
|
+
console.log(data);
|
|
42
|
+
|
|
43
|
+
return data;
|
|
44
|
+
} catch (error) {
|
|
45
|
+
console.error('Error fetching token:', error);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export async function main() {
|
|
50
|
+
const token = await getToken();
|
|
51
|
+
console.log(token);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
main()
|
|
55
|
+
.catch(console.error);
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// tslint:disable:no-implicit-dependencies no-console
|
|
2
|
+
import * as crypto from 'crypto';
|
|
3
|
+
import { readFileSync } from 'fs';
|
|
4
|
+
import { SignJWT } from 'jose';
|
|
5
|
+
import * as uuid from 'uuid';
|
|
6
|
+
|
|
7
|
+
const PRIVATE_KEY_FILE_PATH = `${__dirname}/../../samplePrivateKey.pem`;
|
|
8
|
+
|
|
9
|
+
interface IAuth0Config {
|
|
10
|
+
auth0Domain: string;
|
|
11
|
+
clientId: string;
|
|
12
|
+
privateKeyContent: string; // PEM形式の秘密鍵の内容 (例: fs.readFileSync('private_key.pem', 'utf8'))
|
|
13
|
+
audience: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// 環境変数から機密情報を取得することを強く推奨します
|
|
17
|
+
const auth0config: IAuth0Config = {
|
|
18
|
+
auth0Domain: String(process.env.AUTH0_DOMAIN),
|
|
19
|
+
clientId: String(process.env.AUTH0_CLIENT_ID),
|
|
20
|
+
// keyId: 'xxx',
|
|
21
|
+
privateKeyContent: readFileSync(PRIVATE_KEY_FILE_PATH, 'utf8'), // 秘密鍵の内容を読み込む
|
|
22
|
+
audience: String(process.env.AUTH0_AUDIENCE)
|
|
23
|
+
// scopes: process.env.OKTA_SCOPES || 'api_access_scope openid', // 必要なスコープを指定
|
|
24
|
+
// authServerId: 'aussd9v86wlIar3cX697', // デフォルト承認サーバーを使用する場合はコメントアウトまたは指定しない
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
async function generateJwtAssertion(config: IAuth0Config) {
|
|
28
|
+
const privateKeyPEM = crypto.createPrivateKey(readFileSync(PRIVATE_KEY_FILE_PATH, 'utf8'));
|
|
29
|
+
|
|
30
|
+
return new SignJWT({})
|
|
31
|
+
.setProtectedHeader({
|
|
32
|
+
alg: 'RS256' // or RS384 or PS256
|
|
33
|
+
// kid: '(OPTIONAL) KID_GENERATED_BY_AUTH0'
|
|
34
|
+
})
|
|
35
|
+
.setIssuedAt()
|
|
36
|
+
.setIssuer(config.clientId)
|
|
37
|
+
.setSubject(config.clientId)
|
|
38
|
+
.setAudience(`https://${config.auth0Domain}/`)
|
|
39
|
+
.setExpirationTime('1m')
|
|
40
|
+
.setJti(uuid.v4())
|
|
41
|
+
.sign(privateKeyPEM);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function getToken() {
|
|
45
|
+
try {
|
|
46
|
+
const jwtAssertion = await generateJwtAssertion(auth0config);
|
|
47
|
+
console.log('jwtAssertion:', jwtAssertion);
|
|
48
|
+
|
|
49
|
+
const body = new URLSearchParams({
|
|
50
|
+
grant_type: 'client_credentials',
|
|
51
|
+
client_assertion_type: 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer',
|
|
52
|
+
client_assertion: jwtAssertion,
|
|
53
|
+
audience: auth0config.audience
|
|
54
|
+
// scope: config.scopes,
|
|
55
|
+
}).toString();
|
|
56
|
+
const response = await fetch(
|
|
57
|
+
`https://${auth0config.auth0Domain}/oauth/token`,
|
|
58
|
+
{
|
|
59
|
+
method: 'POST',
|
|
60
|
+
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
61
|
+
body: body
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
if (!response.ok) {
|
|
65
|
+
console.log(await response.json());
|
|
66
|
+
throw new Error('Network response was not ok');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const data = await response.json();
|
|
70
|
+
console.log(data);
|
|
71
|
+
|
|
72
|
+
return data;
|
|
73
|
+
} catch (error) {
|
|
74
|
+
console.error('Error fetching token:', error);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export async function main() {
|
|
79
|
+
const token = await getToken();
|
|
80
|
+
console.log(token);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
main()
|
|
84
|
+
.catch(console.error);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
const projectIdMustBe = /^[0-9a-z-]+$/; // 記号はhyphenのみ許可
|
|
3
|
+
|
|
4
|
+
let projectId: string;
|
|
5
|
+
|
|
6
|
+
projectId = 'projectId';
|
|
7
|
+
console.log(projectId, ':', projectIdMustBe.test(projectId));
|
|
8
|
+
|
|
9
|
+
projectId = 'projectid';
|
|
10
|
+
console.log(projectId, ':', projectIdMustBe.test(projectId));
|
|
11
|
+
|
|
12
|
+
projectId = 'abcd1234-test';
|
|
13
|
+
console.log(projectId, ':', projectIdMustBe.test(projectId));
|
|
14
|
+
|
|
15
|
+
projectId = 'a-z';
|
|
16
|
+
console.log(projectId, ':', projectIdMustBe.test(projectId));
|
|
17
|
+
|
|
18
|
+
projectId = '0-9';
|
|
19
|
+
console.log(projectId, ':', projectIdMustBe.test(projectId));
|
|
20
|
+
|
|
21
|
+
projectId = '---';
|
|
22
|
+
console.log(projectId, ':', projectIdMustBe.test(projectId));
|
|
23
|
+
|
|
24
|
+
projectId = '-';
|
|
25
|
+
console.log(projectId, ':', projectIdMustBe.test(projectId));
|
|
26
|
+
|
|
27
|
+
projectId = '&';
|
|
28
|
+
console.log(projectId, ':', projectIdMustBe.test(projectId));
|
|
29
|
+
|
|
30
|
+
projectId = 'A';
|
|
31
|
+
console.log(projectId, ':', projectIdMustBe.test(projectId));
|
|
@@ -12,30 +12,39 @@ interface IExecuteSettings {
|
|
|
12
12
|
*/
|
|
13
13
|
redisClient?: RedisClientType;
|
|
14
14
|
}
|
|
15
|
-
type IOperationExecute<T> = (settings: IExecuteSettings) => Promise<T>;
|
|
16
|
-
type INextFunction = (task: Pick<factory.task.ITask<factory.taskName>, 'id'>) => IOperationExecute<void>;
|
|
17
15
|
interface IReadyTask {
|
|
18
16
|
id: string;
|
|
19
17
|
name?: factory.taskName;
|
|
20
18
|
status: factory.taskStatus.Ready;
|
|
19
|
+
remainingNumberOfTries?: never;
|
|
21
20
|
expires?: Date;
|
|
22
21
|
executionResult?: never;
|
|
23
22
|
}
|
|
24
23
|
interface IRunningTask {
|
|
25
24
|
id: string;
|
|
26
25
|
status: factory.taskStatus.Running;
|
|
26
|
+
remainingNumberOfTries?: never;
|
|
27
27
|
name?: never;
|
|
28
28
|
expires?: never;
|
|
29
29
|
executionResult?: never;
|
|
30
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* 実行されたタスクイベント
|
|
33
|
+
*/
|
|
31
34
|
interface IExecutedTask {
|
|
32
35
|
id: string;
|
|
33
|
-
status: factory.taskStatus;
|
|
36
|
+
status: factory.taskStatus.Executed | factory.taskStatus.Running | factory.taskStatus.Aborted;
|
|
34
37
|
executionResult: factory.task.IExecutionResult;
|
|
35
|
-
|
|
38
|
+
/**
|
|
39
|
+
* 実行されたタスクの残り試行回数
|
|
40
|
+
*/
|
|
41
|
+
remainingNumberOfTries: number;
|
|
42
|
+
name: factory.taskName;
|
|
36
43
|
expires?: never;
|
|
37
44
|
}
|
|
38
45
|
type IChangedTask = IReadyTask | IRunningTask | IExecutedTask;
|
|
46
|
+
type IOperationExecute<T> = (settings: IExecuteSettings) => Promise<T>;
|
|
47
|
+
type INextFunction = (task: IExecutedTask) => IOperationExecute<void>;
|
|
39
48
|
type IOnTaskStatusChangedListener = (task: IChangedTask, next?: INextFunction) => void;
|
|
40
49
|
/**
|
|
41
50
|
* タスクイベントエミッター
|
package/lib/chevre/index.d.ts
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import type * as COAService from '@motionpicture/coa-service';
|
|
5
5
|
import type * as GMOService from '@motionpicture/gmo-service';
|
|
6
|
-
import type * as AdminAuth from './adminAuth';
|
|
7
6
|
import type * as Pecorinoapi from './pecorinoapi';
|
|
8
7
|
import { credentials } from './credentials';
|
|
9
8
|
import * as errorHandler from './errorHandler';
|
|
@@ -13,7 +12,6 @@ import * as repository from './repository';
|
|
|
13
12
|
import * as service from './service';
|
|
14
13
|
import * as settings from './settings';
|
|
15
14
|
export { credentials, errorHandler, eventEmitter, factory, repository, service, settings };
|
|
16
|
-
export declare function loadAdminAuth(): Promise<typeof AdminAuth>;
|
|
17
15
|
export declare function loadPecorinoapi(): Promise<typeof Pecorinoapi>;
|
|
18
16
|
export type COA = typeof COAService;
|
|
19
17
|
export declare function loadCOA(): Promise<typeof COAService>;
|