@chevre/domain 22.7.0-alpha.18 → 22.7.0-alpha.19
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/deleteDiscontinuedPeopleByFetch.ts +2 -3
- package/example/src/chevre/person/cleanUpCognitoUsers.ts +21 -11
- package/example/src/chevre/person/cleanUpCognitoUsersByFetch.ts +143 -0
- package/lib/chevre/service/offer.d.ts +7 -9
- package/lib/chevre/service/offer.js +25 -24
- package/package.json +1 -1
|
@@ -2,15 +2,14 @@
|
|
|
2
2
|
// import * as moment from 'moment';
|
|
3
3
|
|
|
4
4
|
const TIMEOUT_MS = 5000;
|
|
5
|
-
const INTERVAL_MS =
|
|
5
|
+
const INTERVAL_MS = 3000;
|
|
6
6
|
|
|
7
7
|
let i = 0;
|
|
8
8
|
setInterval(
|
|
9
9
|
async () => {
|
|
10
10
|
i += 1;
|
|
11
11
|
try {
|
|
12
|
-
const url =
|
|
13
|
-
|
|
12
|
+
const url = String(process.env.DISCONTINUE_PEOPLE_URL);
|
|
14
13
|
const res = await fetch(
|
|
15
14
|
url,
|
|
16
15
|
{
|
|
@@ -1,17 +1,25 @@
|
|
|
1
1
|
// tslint:disable:no-console
|
|
2
|
-
import { CognitoIdentityProvider, UserType } from '@aws-sdk/client-cognito-identity-provider';
|
|
2
|
+
import { CognitoIdentityProvider, ListUsersInGroupCommandOutput, UserType } from '@aws-sdk/client-cognito-identity-provider';
|
|
3
3
|
import { fromEnv } from '@aws-sdk/credential-providers';
|
|
4
4
|
import * as moment from 'moment';
|
|
5
|
+
import * as mongoose from 'mongoose';
|
|
5
6
|
|
|
6
7
|
import { chevre } from '../../../../lib/index';
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
export const USERPOOL_ID_NEW = String(process.env.USERPOOL_ID_NEW);
|
|
10
|
-
const USER_GROUP_NAME = String(process.env.USER_GROUP_NAME); // 'ap-northeast-1_XXXXXXXXX_SSKTS',
|
|
11
|
-
const NEW_USERPOOL_PROVIDER_NAME = 'SSKTS';
|
|
9
|
+
const USERPOOL_PROVIDER_NAME = 'SSKTS';
|
|
12
10
|
|
|
13
11
|
// tslint:disable-next-line:max-func-body-length
|
|
14
12
|
async function main(): Promise<void> {
|
|
13
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
14
|
+
|
|
15
|
+
const settingRepo = await chevre.repository.Setting.createInstance(mongoose.connection);
|
|
16
|
+
const setting = await settingRepo.findOne({ project: { id: { $eq: '*' } } }, ['userPoolIdNew']);
|
|
17
|
+
if (typeof setting?.userPoolIdNew !== 'string') {
|
|
18
|
+
throw new chevre.factory.errors.NotFound('setting.userPoolIdNew');
|
|
19
|
+
}
|
|
20
|
+
const userPoolId: string = setting.userPoolIdNew;
|
|
21
|
+
const USER_GROUP_NAME = `${userPoolId}_${USERPOOL_PROVIDER_NAME}`; // 'ap-northeast-1_XXXXXXXXX_SSKTS',
|
|
22
|
+
|
|
15
23
|
const awsCredentials = fromEnv();
|
|
16
24
|
const cognitoIdentityServiceProvider = new CognitoIdentityProvider({
|
|
17
25
|
apiVersion: 'latest',
|
|
@@ -21,7 +29,7 @@ async function main(): Promise<void> {
|
|
|
21
29
|
|
|
22
30
|
// create user
|
|
23
31
|
const newPersonRepo = await chevre.repository.Person.createInstance({
|
|
24
|
-
userPoolId:
|
|
32
|
+
userPoolId: userPoolId,
|
|
25
33
|
cognitoIdentityServiceProvider
|
|
26
34
|
});
|
|
27
35
|
|
|
@@ -31,10 +39,10 @@ async function main(): Promise<void> {
|
|
|
31
39
|
while (typeof nextToken === 'string') {
|
|
32
40
|
page += 1;
|
|
33
41
|
console.log('listUsersInGroup processing...', nextToken, page);
|
|
34
|
-
const listUsersInGroupResult = await newPersonRepo.cognitoIdentityServiceProvider.listUsersInGroup(
|
|
42
|
+
const listUsersInGroupResult = <ListUsersInGroupCommandOutput>await newPersonRepo.cognitoIdentityServiceProvider.listUsersInGroup(
|
|
35
43
|
{
|
|
36
44
|
Limit: 50,
|
|
37
|
-
UserPoolId:
|
|
45
|
+
UserPoolId: userPoolId,
|
|
38
46
|
GroupName: USER_GROUP_NAME,
|
|
39
47
|
...(typeof nextToken === 'string' && nextToken !== '') ? { NextToken: nextToken } : undefined
|
|
40
48
|
}
|
|
@@ -52,7 +60,7 @@ async function main(): Promise<void> {
|
|
|
52
60
|
const oneMonthAgo = moment()
|
|
53
61
|
.add(-1, 'months');
|
|
54
62
|
for (const user of users) {
|
|
55
|
-
const isSSKTSMember = user.Username?.startsWith(
|
|
63
|
+
const isSSKTSMember = user.Username?.startsWith(USERPOOL_PROVIDER_NAME, 0);
|
|
56
64
|
if (!isSSKTSMember) {
|
|
57
65
|
console.error(user);
|
|
58
66
|
throw new Error('not ssktsMember');
|
|
@@ -64,7 +72,7 @@ async function main(): Promise<void> {
|
|
|
64
72
|
console.log('disabling...', user.Username, sub);
|
|
65
73
|
// disable link provider
|
|
66
74
|
const adminDisableUserResult = await newPersonRepo.cognitoIdentityServiceProvider.adminDisableUser({
|
|
67
|
-
UserPoolId:
|
|
75
|
+
UserPoolId: userPoolId,
|
|
68
76
|
Username: user.Username
|
|
69
77
|
});
|
|
70
78
|
console.log('disabled.', user.Username, sub, adminDisableUserResult);
|
|
@@ -74,7 +82,7 @@ async function main(): Promise<void> {
|
|
|
74
82
|
.isBefore(oneMonthAgo)) {
|
|
75
83
|
console.log('adminDeleteUser prossing...', user.Username, sub);
|
|
76
84
|
const adminDeleteUserResult = await newPersonRepo.cognitoIdentityServiceProvider.adminDeleteUser({
|
|
77
|
-
UserPoolId:
|
|
85
|
+
UserPoolId: userPoolId,
|
|
78
86
|
Username: user.Username
|
|
79
87
|
});
|
|
80
88
|
console.log('adminDeleteUser processed.', user.Username, sub, adminDeleteUserResult);
|
|
@@ -83,6 +91,8 @@ async function main(): Promise<void> {
|
|
|
83
91
|
|
|
84
92
|
}
|
|
85
93
|
}
|
|
94
|
+
|
|
95
|
+
console.log(users.length, 'users processed');
|
|
86
96
|
}
|
|
87
97
|
|
|
88
98
|
main()
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import { CognitoIdentityProvider, ListUsersInGroupCommandOutput, UserType } from '@aws-sdk/client-cognito-identity-provider';
|
|
3
|
+
import { fromEnv } from '@aws-sdk/credential-providers';
|
|
4
|
+
import * as moment from 'moment';
|
|
5
|
+
import * as mongoose from 'mongoose';
|
|
6
|
+
|
|
7
|
+
import { chevre } from '../../../../lib/index';
|
|
8
|
+
|
|
9
|
+
const TIMEOUT_MS = 5000;
|
|
10
|
+
const USERPOOL_PROVIDER_NAME = 'SSKTS';
|
|
11
|
+
|
|
12
|
+
// tslint:disable-next-line:max-func-body-length
|
|
13
|
+
async function main(): Promise<void> {
|
|
14
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
15
|
+
|
|
16
|
+
const settingRepo = await chevre.repository.Setting.createInstance(mongoose.connection);
|
|
17
|
+
const setting = await settingRepo.findOne({ project: { id: { $eq: '*' } } }, ['userPoolIdNew']);
|
|
18
|
+
if (typeof setting?.userPoolIdNew !== 'string') {
|
|
19
|
+
throw new chevre.factory.errors.NotFound('setting.userPoolIdNew');
|
|
20
|
+
}
|
|
21
|
+
const userPoolId: string = setting.userPoolIdNew;
|
|
22
|
+
const USER_GROUP_NAME = `${userPoolId}_${USERPOOL_PROVIDER_NAME}`; // 'ap-northeast-1_XXXXXXXXX_SSKTS',
|
|
23
|
+
|
|
24
|
+
const awsCredentials = fromEnv();
|
|
25
|
+
const cognitoIdentityServiceProvider = new CognitoIdentityProvider({
|
|
26
|
+
apiVersion: 'latest',
|
|
27
|
+
region: 'ap-northeast-1',
|
|
28
|
+
credentials: awsCredentials
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// create user
|
|
32
|
+
const newPersonRepo = await chevre.repository.Person.createInstance({
|
|
33
|
+
userPoolId: userPoolId,
|
|
34
|
+
cognitoIdentityServiceProvider
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const users: UserType[] = [];
|
|
38
|
+
let nextToken: string | undefined = '';
|
|
39
|
+
let page: number = 0;
|
|
40
|
+
while (typeof nextToken === 'string') {
|
|
41
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
42
|
+
if (page > 2000) {
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
page += 1;
|
|
47
|
+
console.log('listUsersInGroup processing...', nextToken, page);
|
|
48
|
+
const listUsersInGroupResult = <ListUsersInGroupCommandOutput>await newPersonRepo.cognitoIdentityServiceProvider.listUsersInGroup(
|
|
49
|
+
{
|
|
50
|
+
Limit: 50,
|
|
51
|
+
// Limit: 1,
|
|
52
|
+
UserPoolId: userPoolId,
|
|
53
|
+
GroupName: USER_GROUP_NAME,
|
|
54
|
+
...(typeof nextToken === 'string' && nextToken !== '') ? { NextToken: nextToken } : undefined
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
// tslint:disable-next-line:no-null-keyword
|
|
58
|
+
console.dir(listUsersInGroupResult.Users?.at(0), { depth: null });
|
|
59
|
+
nextToken = listUsersInGroupResult.NextToken;
|
|
60
|
+
if (Array.isArray(listUsersInGroupResult.Users)) {
|
|
61
|
+
users.push(...listUsersInGroupResult.Users);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
console.log('listUsersInGroup processed', nextToken, page);
|
|
65
|
+
console.log(users.length, 'users found');
|
|
66
|
+
|
|
67
|
+
const oneMonthAgo = moment()
|
|
68
|
+
.add(-1, 'months');
|
|
69
|
+
let i = 0;
|
|
70
|
+
for (const user of users) {
|
|
71
|
+
i += 1;
|
|
72
|
+
await new Promise<void>((resolve) => {
|
|
73
|
+
setTimeout(
|
|
74
|
+
() => {
|
|
75
|
+
resolve();
|
|
76
|
+
},
|
|
77
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
78
|
+
500
|
|
79
|
+
);
|
|
80
|
+
});
|
|
81
|
+
const isSSKTSMember = user.Username?.startsWith(USERPOOL_PROVIDER_NAME, 0);
|
|
82
|
+
if (!isSSKTSMember) {
|
|
83
|
+
console.error(user);
|
|
84
|
+
throw new Error('not ssktsMember');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const sub = user.Attributes?.find(({ Name }) => Name === 'sub')?.Value;
|
|
88
|
+
// if (user.Enabled === true && sub === '46686164-2c18-491a-8594-52c944d895e9') {
|
|
89
|
+
if (user.Enabled === true) {
|
|
90
|
+
console.log('disabling...', user.Username, sub, i);
|
|
91
|
+
// disable link provider
|
|
92
|
+
// const adminDisableUserResult = await newPersonRepo.cognitoIdentityServiceProvider.adminDisableUser({
|
|
93
|
+
// UserPoolId: userPoolId,
|
|
94
|
+
// Username: user.Username
|
|
95
|
+
// });
|
|
96
|
+
// console.log('disabled.', user.Username, sub, adminDisableUserResult);
|
|
97
|
+
} else {
|
|
98
|
+
if (user.UserLastModifiedDate instanceof Date) {
|
|
99
|
+
if (moment(user.UserLastModifiedDate)
|
|
100
|
+
.isBefore(oneMonthAgo)) {
|
|
101
|
+
console.log('adminDeleteUser prossing...', user.Username, sub, i);
|
|
102
|
+
|
|
103
|
+
// const adminDeleteUserResult = await newPersonRepo.cognitoIdentityServiceProvider.adminDeleteUser({
|
|
104
|
+
// UserPoolId: userPoolId,
|
|
105
|
+
// Username: user.Username
|
|
106
|
+
// });
|
|
107
|
+
try {
|
|
108
|
+
const url = `${String(process.env.DISCONTINUE_PEOPLE_URL)}?personId=${sub}`;
|
|
109
|
+
const res = await fetch(
|
|
110
|
+
url,
|
|
111
|
+
{
|
|
112
|
+
signal: AbortSignal.timeout(TIMEOUT_MS),
|
|
113
|
+
method: 'GET'
|
|
114
|
+
}
|
|
115
|
+
);
|
|
116
|
+
// const result = await res.text();
|
|
117
|
+
console.log('res.status', res.status, user.Username, sub, i);
|
|
118
|
+
} catch (err) {
|
|
119
|
+
console.error(err);
|
|
120
|
+
if (err.name === 'TimeoutError') {
|
|
121
|
+
console.error('Timeout: It took more than 5 seconds to get the result!');
|
|
122
|
+
} else if (err.name === 'AbortError') {
|
|
123
|
+
console.error('Fetch aborted by user action (browser stop button, closing tab, etc.');
|
|
124
|
+
} else if (err.name === 'TypeError') {
|
|
125
|
+
console.error('AbortSignal.timeout() method is not supported');
|
|
126
|
+
} else {
|
|
127
|
+
// A network error, or some other problem.
|
|
128
|
+
console.error(`Error: type: ${err.name}, message: ${err.message}`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
console.log('adminDeleteUser processed.', user.Username, sub, i);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
console.log(users.length, 'users processed');
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
main()
|
|
142
|
+
.then()
|
|
143
|
+
.catch(console.error);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { EventRepo } from '../repo/event';
|
|
2
2
|
import type { SeatRepo } from '../repo/place/seat';
|
|
3
|
-
import type { PriceSpecificationRepo } from '../repo/priceSpecification';
|
|
4
3
|
import type { StockHolderRepo } from '../repo/stockHolder';
|
|
5
4
|
import * as factory from '../factory';
|
|
6
5
|
import * as EventOfferService from './offer/event';
|
|
@@ -20,7 +19,12 @@ export declare function addOffers2Seat(params: {
|
|
|
20
19
|
*/
|
|
21
20
|
priceSpecs: ICategoryCodeChargeSpecification[];
|
|
22
21
|
}): factory.place.seat.IPlaceWithOffer;
|
|
23
|
-
type ISeatAsEventOffer = Pick<factory.place.seat.IPlaceWithOffer, 'branchCode' | '
|
|
22
|
+
type ISeatAsEventOffer = Pick<factory.place.seat.IPlaceWithOffer, 'branchCode' | 'name' | 'seatingType'> & {
|
|
23
|
+
containedInPlace?: {
|
|
24
|
+
branchCode?: string;
|
|
25
|
+
};
|
|
26
|
+
offers?: Pick<factory.place.seat.IOffer, 'availability'>[];
|
|
27
|
+
};
|
|
24
28
|
/**
|
|
25
29
|
* イベントに対する座席オファーを検索する
|
|
26
30
|
*/
|
|
@@ -39,15 +43,9 @@ export declare function searchEventSeatOffersWithPaging(params: {
|
|
|
39
43
|
id: string;
|
|
40
44
|
};
|
|
41
45
|
$projection?: factory.place.seat.IProjection;
|
|
42
|
-
options: {
|
|
43
|
-
/**
|
|
44
|
-
* add option(2024-10-23~)
|
|
45
|
-
*/
|
|
46
|
-
excludePriceSpecification: boolean;
|
|
47
|
-
};
|
|
46
|
+
options: {};
|
|
48
47
|
}): (repos: {
|
|
49
48
|
event: EventRepo;
|
|
50
|
-
priceSpecification: PriceSpecificationRepo;
|
|
51
49
|
stockHolder: StockHolderRepo;
|
|
52
50
|
seat: SeatRepo;
|
|
53
51
|
}) => Promise<ISeatAsEventOffer[]>;
|
|
@@ -60,7 +60,7 @@ function searchEventSeatOffersWithPaging(params) {
|
|
|
60
60
|
// tslint:disable-next-line:max-func-body-length
|
|
61
61
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
62
62
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
63
|
-
const { excludePriceSpecification } = params.options;
|
|
63
|
+
// const { excludePriceSpecification } = params.options;
|
|
64
64
|
let offers = [];
|
|
65
65
|
// optimize(2024-07-18~)
|
|
66
66
|
const event = yield repos.event.projectEventFieldsById({ id: params.event.id }, ['project', 'startDate', 'offers.itemOffered']);
|
|
@@ -99,36 +99,37 @@ function searchEventSeatOffersWithPaging(params) {
|
|
|
99
99
|
})
|
|
100
100
|
});
|
|
101
101
|
// ルームに含まれる座席区分のみ加算料金を検索(2024-08-05~)
|
|
102
|
-
const uniqueSeatingTypes =
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
});
|
|
102
|
+
// const uniqueSeatingTypes = await repos.seat.aggregateSeatingTypes({
|
|
103
|
+
// project: { id: { $eq: event.project.id } },
|
|
104
|
+
// containedInPlace: {
|
|
105
|
+
// containedInPlace: {
|
|
106
|
+
// branchCode: { $eq: roomBranchCode },
|
|
107
|
+
// containedInPlace: { branchCode: { $eq: movieTheaterBranchCode } }
|
|
108
|
+
// }
|
|
109
|
+
// }
|
|
110
|
+
// });
|
|
111
111
|
// 座席タイプ価格仕様を検索
|
|
112
|
-
let priceSpecs = [];
|
|
113
|
-
if (!excludePriceSpecification) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
112
|
+
// let priceSpecs: ICategoryCodeChargeSpecification[] = [];
|
|
113
|
+
// if (!excludePriceSpecification) {
|
|
114
|
+
// if (Array.isArray(uniqueSeatingTypes) && uniqueSeatingTypes.length > 0) {
|
|
115
|
+
// priceSpecs =
|
|
116
|
+
// await repos.priceSpecification.search<factory.priceSpecificationType.CategoryCodeChargeSpecification>({
|
|
117
|
+
// project: { id: { $eq: event.project.id } },
|
|
118
|
+
// typeOf: factory.priceSpecificationType.CategoryCodeChargeSpecification,
|
|
119
|
+
// appliesToCategoryCode: {
|
|
120
|
+
// inCodeSet: { identifier: { $eq: factory.categoryCode.CategorySetIdentifier.SeatingType } },
|
|
121
|
+
// codeValue: { $in: uniqueSeatingTypes } // ルームに含まれる座席区分のみ加算料金を検索(2024-08-05~)
|
|
122
|
+
// }
|
|
123
|
+
// });
|
|
124
|
+
// }
|
|
125
|
+
// }
|
|
125
126
|
offers = seats.map((seat, index) => {
|
|
126
127
|
return addOffers2Seat({
|
|
127
128
|
seat,
|
|
128
129
|
availability: (typeof availabilities[index] === 'string')
|
|
129
130
|
? factory.itemAvailability.OutOfStock // ホルダーが存在すればOutOfStock
|
|
130
131
|
: factory.itemAvailability.InStock,
|
|
131
|
-
priceSpecs
|
|
132
|
+
priceSpecs: [] // priceSpecsをレスポンスから廃止(2024-12-22~)
|
|
132
133
|
});
|
|
133
134
|
});
|
|
134
135
|
}
|
package/package.json
CHANGED