@chevre/domain 22.10.0-alpha.14 → 22.10.0-alpha.15
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/maintenance/checkTransactionStatuses.ts +105 -0
- package/example/src/chevre/roles/addRoleMembers.ts +75 -0
- package/example/src/chevre/stockHolder/checkRedisKeyCount.ts +4 -1
- package/lib/chevre/repo/mongoose/schemas/role.d.ts +14 -1
- package/lib/chevre/repo/mongoose/schemas/role.js +11 -1
- package/lib/chevre/repo/role.d.ts +8 -3
- package/lib/chevre/repo/role.js +33 -4
- package/package.json +2 -2
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
|
|
4
|
+
import { chevre } from '../../../../lib/index';
|
|
5
|
+
|
|
6
|
+
mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
7
|
+
|
|
8
|
+
// tslint:disable-next-line:max-func-body-length
|
|
9
|
+
async function main() {
|
|
10
|
+
const now = new Date();
|
|
11
|
+
console.log('--------', 'aggregating...', ' --------', now);
|
|
12
|
+
|
|
13
|
+
const assetTransactionRepo = await chevre.repository.AssetTransaction.createInstance(mongoose.connection);
|
|
14
|
+
const transactionRepo = await chevre.repository.Transaction.createInstance(mongoose.connection);
|
|
15
|
+
const taskRepo = await chevre.repository.Task.createInstance(mongoose.connection);
|
|
16
|
+
|
|
17
|
+
// {status:"InProgress"}を確認
|
|
18
|
+
// {"tasksExportAction.actionStatus":{$ne:"CompletedActionStatus"}}を確認
|
|
19
|
+
|
|
20
|
+
for (const transactionType of [
|
|
21
|
+
chevre.factory.transactionType.PlaceOrder,
|
|
22
|
+
chevre.factory.transactionType.ReturnOrder
|
|
23
|
+
]) {
|
|
24
|
+
const inProgressCount = await transactionRepo.count({
|
|
25
|
+
limit: 1000,
|
|
26
|
+
status: { $in: [chevre.factory.transactionStatusType.InProgress] },
|
|
27
|
+
typeOf: transactionType
|
|
28
|
+
});
|
|
29
|
+
console.log(transactionType, 'inProgressCount:', inProgressCount.count, now);
|
|
30
|
+
|
|
31
|
+
const unCompletedTasksExportCount = await transactionRepo.count({
|
|
32
|
+
limit: 1000,
|
|
33
|
+
tasksExportAction: {
|
|
34
|
+
actionStatus: {
|
|
35
|
+
$in: [
|
|
36
|
+
chevre.factory.actionStatusType.ActiveActionStatus,
|
|
37
|
+
chevre.factory.actionStatusType.CanceledActionStatus,
|
|
38
|
+
chevre.factory.actionStatusType.FailedActionStatus,
|
|
39
|
+
chevre.factory.actionStatusType.PotentialActionStatus
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
typeOf: transactionType
|
|
44
|
+
});
|
|
45
|
+
console.log(transactionType, 'unCompletedTasksExportCount:', unCompletedTasksExportCount.count, now);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
for (const assetTransactionType of [
|
|
49
|
+
chevre.factory.assetTransactionType.Pay,
|
|
50
|
+
chevre.factory.assetTransactionType.Refund,
|
|
51
|
+
chevre.factory.assetTransactionType.Reserve,
|
|
52
|
+
chevre.factory.assetTransactionType.CancelReservation
|
|
53
|
+
]) {
|
|
54
|
+
const inProgressCount = await assetTransactionRepo.count({
|
|
55
|
+
limit: 1000,
|
|
56
|
+
status: { $in: [chevre.factory.transactionStatusType.InProgress] },
|
|
57
|
+
typeOf: <any>assetTransactionType
|
|
58
|
+
});
|
|
59
|
+
console.log(assetTransactionType, 'inProgressCount:', inProgressCount.count, now);
|
|
60
|
+
|
|
61
|
+
const unCompletedTasksExportCount = await assetTransactionRepo.count({
|
|
62
|
+
limit: 1000,
|
|
63
|
+
tasksExportAction: {
|
|
64
|
+
actionStatus: {
|
|
65
|
+
$in: [
|
|
66
|
+
chevre.factory.actionStatusType.ActiveActionStatus,
|
|
67
|
+
chevre.factory.actionStatusType.CanceledActionStatus,
|
|
68
|
+
chevre.factory.actionStatusType.FailedActionStatus,
|
|
69
|
+
chevre.factory.actionStatusType.PotentialActionStatus
|
|
70
|
+
]
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
typeOf: <any>assetTransactionType
|
|
74
|
+
});
|
|
75
|
+
console.log(assetTransactionType, 'unCompletedTasksExportCount:', unCompletedTasksExportCount.count, now);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const readyTaskCount = await taskRepo.count({
|
|
79
|
+
limit: 100,
|
|
80
|
+
statuses: [
|
|
81
|
+
chevre.factory.taskStatus.Ready,
|
|
82
|
+
chevre.factory.taskStatus.Running
|
|
83
|
+
],
|
|
84
|
+
name: {
|
|
85
|
+
$nin: [
|
|
86
|
+
chevre.factory.taskName.ImportEventCapacitiesFromCOA,
|
|
87
|
+
chevre.factory.taskName.ImportEventsFromCOA,
|
|
88
|
+
chevre.factory.taskName.ImportOffersFromCOA
|
|
89
|
+
]
|
|
90
|
+
},
|
|
91
|
+
runsThrough: now
|
|
92
|
+
});
|
|
93
|
+
console.log('readyTaskCount:', readyTaskCount.count, now);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const INTERVAL_MS = 60000;
|
|
97
|
+
// const INTERVAL_MS = 5000;
|
|
98
|
+
setInterval(
|
|
99
|
+
() => {
|
|
100
|
+
main()
|
|
101
|
+
.then()
|
|
102
|
+
.catch(console.error);
|
|
103
|
+
},
|
|
104
|
+
INTERVAL_MS
|
|
105
|
+
);
|
|
@@ -0,0 +1,75 @@
|
|
|
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
|
+
let roleNames = [
|
|
12
|
+
chevre.factory.iam.RoleName.Customer,
|
|
13
|
+
chevre.factory.iam.RoleName.EventsViewer,
|
|
14
|
+
chevre.factory.iam.RoleName.POS
|
|
15
|
+
];
|
|
16
|
+
for (const roleName of roleNames) {
|
|
17
|
+
const result = await roleRepo.addMember({
|
|
18
|
+
roleName,
|
|
19
|
+
member: { typeOf: chevre.factory.creativeWorkType.WebApplication },
|
|
20
|
+
memberOf: { typeOf: chevre.factory.organizationType.Project }
|
|
21
|
+
});
|
|
22
|
+
console.log(result, roleName);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
roleNames = [
|
|
26
|
+
chevre.factory.iam.RoleName.Server
|
|
27
|
+
];
|
|
28
|
+
for (const roleName of roleNames) {
|
|
29
|
+
const result = await roleRepo.addMember({
|
|
30
|
+
roleName,
|
|
31
|
+
member: { typeOf: chevre.factory.creativeWorkType.SoftwareApplication },
|
|
32
|
+
memberOf: { typeOf: chevre.factory.organizationType.Project }
|
|
33
|
+
});
|
|
34
|
+
console.log(result, roleName);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
roleNames = [
|
|
38
|
+
chevre.factory.iam.RoleName.Accountant,
|
|
39
|
+
chevre.factory.iam.RoleName.IAMRoleAdmin,
|
|
40
|
+
chevre.factory.iam.RoleName.InventoryManager,
|
|
41
|
+
chevre.factory.iam.RoleName.MemberAdmin,
|
|
42
|
+
chevre.factory.iam.RoleName.Owner,
|
|
43
|
+
chevre.factory.iam.RoleName.PaymentServiceAdmin,
|
|
44
|
+
chevre.factory.iam.RoleName.SellerAdmin,
|
|
45
|
+
chevre.factory.iam.RoleName.TicketClerk,
|
|
46
|
+
chevre.factory.iam.RoleName.TicketCollector,
|
|
47
|
+
chevre.factory.iam.RoleName.User
|
|
48
|
+
];
|
|
49
|
+
for (const roleName of roleNames) {
|
|
50
|
+
const result = await roleRepo.addMember({
|
|
51
|
+
roleName,
|
|
52
|
+
member: { typeOf: chevre.factory.personType.Person },
|
|
53
|
+
memberOf: { typeOf: chevre.factory.organizationType.Project }
|
|
54
|
+
});
|
|
55
|
+
console.log(result, roleName);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
roleNames = [
|
|
59
|
+
chevre.factory.iam.RoleName.SellersIAMRoleAdmin,
|
|
60
|
+
chevre.factory.iam.RoleName.SellersInventoryManager,
|
|
61
|
+
chevre.factory.iam.RoleName.SellersOwner
|
|
62
|
+
];
|
|
63
|
+
for (const roleName of roleNames) {
|
|
64
|
+
const result = await roleRepo.addMember({
|
|
65
|
+
roleName,
|
|
66
|
+
member: { typeOf: chevre.factory.personType.Person },
|
|
67
|
+
memberOf: { typeOf: chevre.factory.organizationType.Corporation }
|
|
68
|
+
});
|
|
69
|
+
console.log(result, roleName);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
main()
|
|
74
|
+
.then()
|
|
75
|
+
.catch(console.error);
|
|
@@ -15,7 +15,8 @@ const client = redis.createClient<redis.RedisDefaultModules, Record<string, neve
|
|
|
15
15
|
port: Number(<string>process.env.REDIS_PORT),
|
|
16
16
|
host: <string>process.env.REDIS_HOST
|
|
17
17
|
},
|
|
18
|
-
password: <string>process.env.REDIS_KEY
|
|
18
|
+
password: <string>process.env.REDIS_KEY,
|
|
19
|
+
name: 'checkRedisKeyCount'
|
|
19
20
|
})
|
|
20
21
|
.on('error', (err) => {
|
|
21
22
|
// eslint-disable-next-line no-console
|
|
@@ -115,6 +116,8 @@ async function main() {
|
|
|
115
116
|
)).map(({ id }) => id);
|
|
116
117
|
}
|
|
117
118
|
|
|
119
|
+
useMongoAsStockHolderProjects = useMongoAsStockHolderProjects.filter((id) => id.slice(0, 6) !== 'sskts-');
|
|
120
|
+
|
|
118
121
|
const results: {
|
|
119
122
|
project: { id: string };
|
|
120
123
|
checkedCount: number;
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import { IndexDefinition, IndexOptions, Model, Schema, SchemaDefinition } from 'mongoose';
|
|
2
2
|
import * as factory from '../../../factory';
|
|
3
|
-
export type IRole = Pick<factory.iam.IRole, 'permissions' | 'roleName' | 'typeOf'
|
|
3
|
+
export type IRole = Pick<factory.iam.IRole, 'permissions' | 'roleName' | 'typeOf'> & {
|
|
4
|
+
/**
|
|
5
|
+
* ロール割り当て対象のアイデンティティタイプ
|
|
6
|
+
*/
|
|
7
|
+
member: {
|
|
8
|
+
typeOf: factory.personType.Person | factory.creativeWorkType.SoftwareApplication | factory.creativeWorkType.WebApplication;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* ロールの所属組織
|
|
12
|
+
*/
|
|
13
|
+
memberOf: {
|
|
14
|
+
typeOf: factory.organizationType.Corporation | factory.organizationType.Project;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
4
17
|
type IDocType = IRole;
|
|
5
18
|
type IModel = Model<IDocType>;
|
|
6
19
|
type ISchemaDefinition = SchemaDefinition<IDocType>;
|
|
@@ -10,7 +10,9 @@ exports.modelName = modelName;
|
|
|
10
10
|
const schemaDefinition = {
|
|
11
11
|
typeOf: { type: String, required: true },
|
|
12
12
|
permissions: [String],
|
|
13
|
-
roleName: { type: String, required: true }
|
|
13
|
+
roleName: { type: String, required: true },
|
|
14
|
+
member: { type: mongoose_1.SchemaTypes.Mixed, required: true },
|
|
15
|
+
memberOf: { type: mongoose_1.SchemaTypes.Mixed, required: true }
|
|
14
16
|
};
|
|
15
17
|
const schemaOptions = {
|
|
16
18
|
autoIndex: settings_1.MONGO_AUTO_INDEX,
|
|
@@ -49,6 +51,14 @@ const indexes = [
|
|
|
49
51
|
permissions: { $exists: true }
|
|
50
52
|
}
|
|
51
53
|
}
|
|
54
|
+
],
|
|
55
|
+
[
|
|
56
|
+
{ 'member.typeOf': 1, roleName: 1 },
|
|
57
|
+
{ name: 'memberTypeOf' }
|
|
58
|
+
],
|
|
59
|
+
[
|
|
60
|
+
{ 'memberOf.typeOf': 1, roleName: 1 },
|
|
61
|
+
{ name: 'memberOfTypeOf' }
|
|
52
62
|
]
|
|
53
63
|
];
|
|
54
64
|
exports.indexes = indexes;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import type { Connection } from 'mongoose';
|
|
1
|
+
import type { Connection, FilterQuery } from 'mongoose';
|
|
2
2
|
import * as factory from '../factory';
|
|
3
3
|
import { IRole } from './mongoose/schemas/role';
|
|
4
|
+
type IKeyOfProjection = keyof IRole;
|
|
4
5
|
/**
|
|
5
6
|
* IAMロールリポジトリ
|
|
6
7
|
*/
|
|
7
8
|
export declare class RoleRepo {
|
|
8
9
|
private readonly roleModel;
|
|
9
10
|
constructor(connection: Connection);
|
|
10
|
-
static CREATE_MONGO_CONDITIONS(params: factory.iam.IRoleSearchConditions):
|
|
11
|
-
projectFields(params: factory.iam.IRoleSearchConditions): Promise<IRole[]>;
|
|
11
|
+
static CREATE_MONGO_CONDITIONS(params: factory.iam.IRoleSearchConditions): FilterQuery<IRole>[];
|
|
12
|
+
projectFields(params: factory.iam.IRoleSearchConditions, inclusion: IKeyOfProjection[]): Promise<IRole[]>;
|
|
12
13
|
aggregatePermissions(params: {
|
|
13
14
|
roleName: {
|
|
14
15
|
$in: string[];
|
|
@@ -24,4 +25,8 @@ export declare class RoleRepo {
|
|
|
24
25
|
}): Promise<(import("mongoose").FlattenMaps<IRole> & {
|
|
25
26
|
_id: import("mongoose").Types.ObjectId;
|
|
26
27
|
}) | null>;
|
|
28
|
+
addMember(params: Pick<IRole, 'member' | 'memberOf' | 'roleName'>): Promise<(import("mongoose").FlattenMaps<IRole> & {
|
|
29
|
+
_id: import("mongoose").Types.ObjectId;
|
|
30
|
+
}) | null>;
|
|
27
31
|
}
|
|
32
|
+
export {};
|
package/lib/chevre/repo/role.js
CHANGED
|
@@ -15,7 +15,9 @@ const role_1 = require("./mongoose/schemas/role");
|
|
|
15
15
|
const AVAILABLE_PROJECT_FIELDS = [
|
|
16
16
|
'typeOf',
|
|
17
17
|
'permissions',
|
|
18
|
-
'roleName'
|
|
18
|
+
'roleName',
|
|
19
|
+
'member',
|
|
20
|
+
'memberOf'
|
|
19
21
|
];
|
|
20
22
|
/**
|
|
21
23
|
* IAMロールリポジトリ
|
|
@@ -25,7 +27,7 @@ class RoleRepo {
|
|
|
25
27
|
this.roleModel = connection.model(role_1.modelName, (0, role_1.createSchema)());
|
|
26
28
|
}
|
|
27
29
|
static CREATE_MONGO_CONDITIONS(params) {
|
|
28
|
-
var _a, _b, _c;
|
|
30
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
29
31
|
const andConditions = [];
|
|
30
32
|
if (typeof ((_a = params.roleName) === null || _a === void 0 ? void 0 : _a.$eq) === 'string') {
|
|
31
33
|
andConditions.push({ roleName: { $eq: params.roleName.$eq } });
|
|
@@ -38,12 +40,23 @@ class RoleRepo {
|
|
|
38
40
|
if (typeof permissionsEq === 'string') {
|
|
39
41
|
andConditions.push({ permissions: { $exists: true, $eq: permissionsEq } });
|
|
40
42
|
}
|
|
43
|
+
const memberTypeOfEq = (_e = (_d = params.member) === null || _d === void 0 ? void 0 : _d.typeOf) === null || _e === void 0 ? void 0 : _e.$eq;
|
|
44
|
+
if (typeof memberTypeOfEq === 'string') {
|
|
45
|
+
andConditions.push({ 'member.typeOf': { $eq: memberTypeOfEq } });
|
|
46
|
+
}
|
|
47
|
+
const memberOfTypeOfEq = (_g = (_f = params.memberOf) === null || _f === void 0 ? void 0 : _f.typeOf) === null || _g === void 0 ? void 0 : _g.$eq;
|
|
48
|
+
if (typeof memberOfTypeOfEq === 'string') {
|
|
49
|
+
andConditions.push({ 'memberOf.typeOf': { $eq: memberOfTypeOfEq } });
|
|
50
|
+
}
|
|
41
51
|
return andConditions;
|
|
42
52
|
}
|
|
43
|
-
projectFields(params) {
|
|
53
|
+
projectFields(params, inclusion) {
|
|
44
54
|
return __awaiter(this, void 0, void 0, function* () {
|
|
45
55
|
const conditions = RoleRepo.CREATE_MONGO_CONDITIONS(params);
|
|
46
|
-
|
|
56
|
+
let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
|
|
57
|
+
if (Array.isArray(inclusion) && inclusion.length > 0) {
|
|
58
|
+
positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
|
|
59
|
+
}
|
|
47
60
|
const projection = Object.assign({ _id: 0 }, Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1]))));
|
|
48
61
|
const query = this.roleModel.find((conditions.length > 0) ? { $and: conditions } : {}, projection);
|
|
49
62
|
if (typeof params.limit === 'number' && params.limit > 0) {
|
|
@@ -119,5 +132,21 @@ class RoleRepo {
|
|
|
119
132
|
.exec();
|
|
120
133
|
});
|
|
121
134
|
}
|
|
135
|
+
addMember(params) {
|
|
136
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
137
|
+
const { roleName, member, memberOf } = params;
|
|
138
|
+
return this.roleModel.findOneAndUpdate({
|
|
139
|
+
roleName: { $eq: roleName },
|
|
140
|
+
'member.typeOf': { $ne: member.typeOf }
|
|
141
|
+
}, {
|
|
142
|
+
$set: { member, memberOf }
|
|
143
|
+
}, {
|
|
144
|
+
new: true,
|
|
145
|
+
projection: { _id: 1 }
|
|
146
|
+
})
|
|
147
|
+
.lean()
|
|
148
|
+
.exec();
|
|
149
|
+
});
|
|
150
|
+
}
|
|
122
151
|
}
|
|
123
152
|
exports.RoleRepo = RoleRepo;
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@aws-sdk/client-cognito-identity-provider": "3.600.0",
|
|
13
13
|
"@aws-sdk/credential-providers": "3.600.0",
|
|
14
|
-
"@chevre/factory": "4.394.0-alpha.
|
|
14
|
+
"@chevre/factory": "4.394.0-alpha.6",
|
|
15
15
|
"@cinerino/sdk": "10.21.0-alpha.41",
|
|
16
16
|
"@motionpicture/coa-service": "9.6.0",
|
|
17
17
|
"@motionpicture/gmo-service": "5.3.0",
|
|
@@ -113,5 +113,5 @@
|
|
|
113
113
|
"postversion": "git push origin --tags",
|
|
114
114
|
"prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
|
|
115
115
|
},
|
|
116
|
-
"version": "22.10.0-alpha.
|
|
116
|
+
"version": "22.10.0-alpha.15"
|
|
117
117
|
}
|