@chevre/domain 22.7.0-alpha.8 → 22.7.0
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/aggregateOfferCatalogItemList.ts +36 -0
- package/example/src/chevre/aggregation/aggregateOffersOnEvent.ts +1 -1
- package/example/src/chevre/aggregation/searchAggregateReservations.ts +1 -1
- package/example/src/chevre/deleteDiscontinuedPeople.ts +153 -0
- package/example/src/chevre/deleteDiscontinuedPeopleByFetch.ts +38 -0
- package/example/src/chevre/findJWTSetting.ts +19 -0
- package/example/src/chevre/person/checkUserPoolClients.ts +119 -0
- package/example/src/chevre/person/cleanUpCognitoUsers.ts +73 -23
- package/example/src/chevre/person/cleanUpCognitoUsersByFetch.ts +162 -0
- package/example/src/chevre/person/cleanUpCreditCard.ts +113 -0
- package/example/src/chevre/unsetUnnecessaryFields.ts +3 -29
- package/example/src/chevre/upsertManyEventsByAdditionalProperty.ts +152 -150
- package/lib/chevre/credentials.d.ts +0 -5
- package/lib/chevre/credentials.js +0 -13
- package/lib/chevre/repo/action.d.ts +4 -20
- package/lib/chevre/repo/action.js +61 -160
- package/lib/chevre/repo/additionalProperty.js +1 -1
- package/lib/chevre/repo/aggregateOffer.js +1 -1
- package/lib/chevre/repo/aggregateReservation.d.ts +2 -2
- package/lib/chevre/repo/aggregateReservation.js +1 -1
- package/lib/chevre/repo/categoryCode.d.ts +6 -2
- package/lib/chevre/repo/categoryCode.js +15 -8
- package/lib/chevre/repo/comment.js +1 -1
- package/lib/chevre/repo/creativeWork.js +1 -1
- package/lib/chevre/repo/customer.js +1 -1
- package/lib/chevre/repo/emailMessage.js +1 -1
- package/lib/chevre/repo/event.d.ts +10 -7
- package/lib/chevre/repo/event.js +40 -80
- package/lib/chevre/repo/mongoose/schemas/account.js +4 -12
- package/lib/chevre/repo/mongoose/schemas/accountTransaction.d.ts +1 -1
- package/lib/chevre/repo/mongoose/schemas/accountTransaction.js +18 -23
- package/lib/chevre/repo/mongoose/schemas/aggregateReservation.d.ts +0 -1
- package/lib/chevre/repo/mongoose/schemas/aggregateReservation.js +1 -1
- package/lib/chevre/repo/mongoose/schemas/event.js +0 -1
- package/lib/chevre/repo/mongoose/schemas/setting.d.ts +26 -0
- package/lib/chevre/repo/mongoose/schemas/setting.js +1 -0
- package/lib/chevre/repo/offerCatalog.d.ts +9 -0
- package/lib/chevre/repo/offerCatalog.js +37 -3
- package/lib/chevre/repo/offerCatalogItem.d.ts +9 -0
- package/lib/chevre/repo/offerCatalogItem.js +37 -1
- package/lib/chevre/repo/offerItemCondition.js +1 -1
- package/lib/chevre/repo/ownershipInfo.js +1 -1
- package/lib/chevre/repo/passport.js +4 -1
- package/lib/chevre/repo/person.d.ts +5 -3
- package/lib/chevre/repo/person.js +0 -1
- package/lib/chevre/repo/priceSpecification.js +1 -1
- package/lib/chevre/repo/seller.js +1 -1
- package/lib/chevre/repo/setting/jwt.d.ts +10 -0
- package/lib/chevre/repo/setting/jwt.js +65 -0
- package/lib/chevre/repo/task.js +1 -1
- package/lib/chevre/repository.d.ts +7 -0
- package/lib/chevre/repository.js +17 -1
- package/lib/chevre/service/aggregation/event.d.ts +1 -2
- package/lib/chevre/service/aggregation/event.js +1 -3
- package/lib/chevre/service/assetTransaction/pay/factory.d.ts +4 -0
- package/lib/chevre/service/assetTransaction/pay/factory.js +4 -10
- package/lib/chevre/service/assetTransaction/pay.d.ts +1 -1
- package/lib/chevre/service/assetTransaction/pay.js +14 -18
- package/lib/chevre/service/assetTransaction/reserve/start/factory/price.js +8 -19
- package/lib/chevre/service/code.d.ts +3 -34
- package/lib/chevre/service/code.js +18 -136
- package/lib/chevre/service/offer/event/authorize/factory.js +19 -14
- package/lib/chevre/service/offer/event/authorize/processStartReserve4chevre/requestedProgramMembershipUsed2permit.d.ts +0 -5
- package/lib/chevre/service/offer/event/authorize/processStartReserve4chevre/requestedProgramMembershipUsed2permit.js +43 -39
- package/lib/chevre/service/offer/event/authorize/processStartReserve4chevre.d.ts +1 -4
- package/lib/chevre/service/offer/event/authorize/processStartReserve4chevre.js +12 -4
- package/lib/chevre/service/offer/event/authorize.d.ts +1 -4
- package/lib/chevre/service/offer/event/authorize.js +6 -2
- package/lib/chevre/service/offer/eventServiceByCOA/acceptOffer.d.ts +2 -1
- package/lib/chevre/service/offer/eventServiceByCOA/acceptOffer.js +10 -4
- package/lib/chevre/service/offer/factory.js +22 -5
- package/lib/chevre/service/offer.d.ts +7 -9
- package/lib/chevre/service/offer.js +25 -24
- package/lib/chevre/service/order/deleteOrder.d.ts +4 -0
- package/lib/chevre/service/order/deleteOrder.js +48 -5
- package/lib/chevre/service/payment/any/factory.d.ts +1 -1
- package/lib/chevre/service/payment/any.d.ts +1 -4
- package/lib/chevre/service/payment/any.js +35 -22
- package/lib/chevre/service/payment/factory/createPayObjectServiceOutput.d.ts +3 -0
- package/lib/chevre/service/payment/factory/createPayObjectServiceOutput.js +32 -14
- package/lib/chevre/service/payment/factory.d.ts +3 -0
- package/lib/chevre/service/payment/movieTicket/validation.js +1 -22
- package/lib/chevre/service/payment.d.ts +1 -3
- package/lib/chevre/service/payment.js +26 -3
- package/lib/chevre/service/report/telemetry.js +3 -3
- package/lib/chevre/service/reserve/verifyToken4reservation.js +1 -16
- package/lib/chevre/service/task/acceptCOAOffer.js +24 -14
- package/lib/chevre/service/task/authorizePayment.js +7 -5
- package/lib/chevre/service/task/createEvent/createEventSeries.js +5 -2
- package/lib/chevre/service/task/deletePerson.js +57 -56
- package/lib/chevre/service/task/deleteTransaction.js +2 -0
- package/lib/chevre/service/task/pay.js +1 -0
- package/lib/chevre/service/task.d.ts +0 -2
- package/lib/chevre/service/transaction/deleteTransaction.d.ts +2 -0
- package/lib/chevre/service/transaction/moneyTransfer.d.ts +1 -6
- package/lib/chevre/service/transaction/moneyTransfer.js +57 -36
- package/package.json +9 -5
- package/example/src/chevre/findValidAuthorization.ts +0 -56
- package/example/src/chevre/saveAggregateReservation.ts +0 -43
- package/lib/chevre/credentials/jwt.d.ts +0 -23
- package/lib/chevre/credentials/jwt.js +0 -18
- package/lib/chevre/service/aggregation/event/aggregateUseActionsOnEvent.d.ts +0 -19
- package/lib/chevre/service/aggregation/event/aggregateUseActionsOnEvent.js +0 -145
- package/lib/chevre/service/task/aggregateUseActionsOnEvent.d.ts +0 -6
- package/lib/chevre/service/task/aggregateUseActionsOnEvent.js +0 -37
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
/**
|
|
3
|
+
* イベント集計タスク実行
|
|
4
|
+
*/
|
|
5
|
+
import { chevre } from '../../../lib/index';
|
|
6
|
+
|
|
7
|
+
import * as mongoose from 'mongoose';
|
|
8
|
+
|
|
9
|
+
export async function main() {
|
|
10
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
11
|
+
|
|
12
|
+
const offerCatalogRepo = await chevre.repository.OfferCatalog.createInstance(mongoose.connection);
|
|
13
|
+
const offerCatalogItemRepo = await chevre.repository.OfferCatalogItem.createInstance(mongoose.connection);
|
|
14
|
+
|
|
15
|
+
const result = await offerCatalogRepo.aggregateItemList({ itemListElement: { typeOf: { $eq: chevre.factory.offerType.Offer } } });
|
|
16
|
+
// tslint:disable-next-line:no-null-keyword
|
|
17
|
+
console.dir(result, { depth: null });
|
|
18
|
+
|
|
19
|
+
const result2 = await offerCatalogRepo.aggregateItemList({ itemListElement: { typeOf: { $eq: 'OfferCatalog' } } });
|
|
20
|
+
// tslint:disable-next-line:no-null-keyword
|
|
21
|
+
console.dir(result2, { depth: null });
|
|
22
|
+
|
|
23
|
+
const result3 = await offerCatalogItemRepo.aggregateItemList({ itemListElement: { typeOf: { $eq: chevre.factory.offerType.Offer } } });
|
|
24
|
+
// tslint:disable-next-line:no-null-keyword
|
|
25
|
+
console.dir(result3, { depth: null });
|
|
26
|
+
|
|
27
|
+
const result4 = await offerCatalogItemRepo.aggregateItemList({ itemListElement: { typeOf: { $eq: 'OfferCatalog' } } });
|
|
28
|
+
// tslint:disable-next-line:no-null-keyword
|
|
29
|
+
console.dir(result4, { depth: null });
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
main()
|
|
33
|
+
.then(() => {
|
|
34
|
+
console.log('success!');
|
|
35
|
+
})
|
|
36
|
+
.catch(console.error);
|
|
@@ -39,7 +39,7 @@ async function main() {
|
|
|
39
39
|
},
|
|
40
40
|
sort: { 'reservationFor.startDate': 1 }
|
|
41
41
|
},
|
|
42
|
-
['
|
|
42
|
+
['aggregateOffer']
|
|
43
43
|
);
|
|
44
44
|
console.log('aggregateReservations:', aggregateReservations);
|
|
45
45
|
console.log('aggregateReservations:', aggregateReservations.map(({ id }) => id));
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as moment from 'moment';
|
|
3
|
+
import * as mongoose from 'mongoose';
|
|
4
|
+
import { call as deletePerson } from '../../../lib/chevre/service/task/deletePerson';
|
|
5
|
+
import { chevre } from '../../../lib/index';
|
|
6
|
+
|
|
7
|
+
// tslint:disable-next-line:max-func-body-length
|
|
8
|
+
async function main() {
|
|
9
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
10
|
+
|
|
11
|
+
const settingRepo = await chevre.repository.Setting.createInstance(mongoose.connection);
|
|
12
|
+
const setting = await settingRepo.findOne({ project: { id: { $eq: '*' } } }, ['userPoolIdNew']);
|
|
13
|
+
if (typeof setting?.userPoolIdNew !== 'string') {
|
|
14
|
+
throw new chevre.factory.errors.NotFound('setting.userPoolIdNew');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const DISCONTINUE_PEOPLE_PROJECT = process.env.USE_DISCONTINUE_PEOPLE_PROJECT;
|
|
18
|
+
if (typeof DISCONTINUE_PEOPLE_PROJECT === 'string' && DISCONTINUE_PEOPLE_PROJECT.length > 0) {
|
|
19
|
+
const ownershipInfoRepo = await chevre.repository.OwnershipInfo.createInstance(mongoose.connection);
|
|
20
|
+
// const deletingOwnershipInfos = (await ownershipInfoRepo.projectFields({
|
|
21
|
+
// limit: NUM_TASKS,
|
|
22
|
+
// page: 1,
|
|
23
|
+
// sort: { ownedFrom: chevre.factory.sortType.Ascending },
|
|
24
|
+
// project: { id: { $eq: DISCONTINUE_PEOPLE_PROJECT } },
|
|
25
|
+
// ownedBy: {
|
|
26
|
+
// typeOf: { $eq: chevre.factory.personType.Person }
|
|
27
|
+
// },
|
|
28
|
+
// typeOfGood: {
|
|
29
|
+
// issuedThrough: {
|
|
30
|
+
// typeOf: {
|
|
31
|
+
// $eq: chevre.factory.product.ProductType.EventService
|
|
32
|
+
// }
|
|
33
|
+
// }
|
|
34
|
+
// }
|
|
35
|
+
// }));
|
|
36
|
+
// console.log(deletingOwnershipInfos.length, 'deletingOwnershipInfos found');
|
|
37
|
+
|
|
38
|
+
const cursor = ownershipInfoRepo.getCursor(
|
|
39
|
+
{
|
|
40
|
+
// sort: { ownedFrom: chevre.factory.sortType.Ascending },
|
|
41
|
+
'project.id': { $eq: DISCONTINUE_PEOPLE_PROJECT },
|
|
42
|
+
'ownedBy.typeOf': {
|
|
43
|
+
$exists: true,
|
|
44
|
+
$eq: chevre.factory.personType.Person
|
|
45
|
+
},
|
|
46
|
+
'typeOfGood.issuedThrough.typeOf': {
|
|
47
|
+
$exists: true,
|
|
48
|
+
$eq: chevre.factory.product.ProductType.EventService
|
|
49
|
+
},
|
|
50
|
+
ownedFrom: {
|
|
51
|
+
$lte: moment('2024-02-25T00:00:00Z')
|
|
52
|
+
.toDate()
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
_id: 1,
|
|
57
|
+
ownedBy: 1,
|
|
58
|
+
ownedFrom: 1,
|
|
59
|
+
project: 1
|
|
60
|
+
}
|
|
61
|
+
);
|
|
62
|
+
console.log('docs found');
|
|
63
|
+
|
|
64
|
+
const runsAt: Date = new Date();
|
|
65
|
+
const userPoolId: string = setting.userPoolIdNew;
|
|
66
|
+
|
|
67
|
+
let i = 0;
|
|
68
|
+
// tslint:disable-next-line:max-func-body-length
|
|
69
|
+
await cursor.eachAsync(async (doc) => {
|
|
70
|
+
i += 1;
|
|
71
|
+
|
|
72
|
+
const deletingOwnershipInfo: Pick<
|
|
73
|
+
chevre.factory.ownershipInfo.IOwnershipInfo<any>,
|
|
74
|
+
'id' | 'ownedBy' | 'ownedFrom' | 'project'
|
|
75
|
+
> = doc.toObject();
|
|
76
|
+
const personId: string = (Array.isArray(deletingOwnershipInfo.ownedBy))
|
|
77
|
+
? deletingOwnershipInfo.ownedBy[0]?.id
|
|
78
|
+
: deletingOwnershipInfo.ownedBy.id;
|
|
79
|
+
console.log(deletingOwnershipInfo);
|
|
80
|
+
|
|
81
|
+
console.log(
|
|
82
|
+
'deleting person...',
|
|
83
|
+
personId, deletingOwnershipInfo.project.id, deletingOwnershipInfo.id, deletingOwnershipInfo.ownedFrom, i
|
|
84
|
+
);
|
|
85
|
+
try {
|
|
86
|
+
await deletePerson({
|
|
87
|
+
id: '',
|
|
88
|
+
project: { typeOf: chevre.factory.organizationType.Project, id: DISCONTINUE_PEOPLE_PROJECT },
|
|
89
|
+
name: chevre.factory.taskName.DeletePerson,
|
|
90
|
+
status: chevre.factory.taskStatus.Ready,
|
|
91
|
+
runsAt,
|
|
92
|
+
remainingNumberOfTries: 10,
|
|
93
|
+
numberOfTried: 0,
|
|
94
|
+
data: {
|
|
95
|
+
id: personId,
|
|
96
|
+
agent: {
|
|
97
|
+
id: DISCONTINUE_PEOPLE_PROJECT,
|
|
98
|
+
typeOf: chevre.factory.organizationType.Project,
|
|
99
|
+
name: 'example'
|
|
100
|
+
},
|
|
101
|
+
physically: true,
|
|
102
|
+
userPoolId,
|
|
103
|
+
migrate: false,
|
|
104
|
+
useUsernameAsGMOMemberId: true,
|
|
105
|
+
paymentMethodType4creditCard: 'CreditCard',
|
|
106
|
+
executeBackground: true
|
|
107
|
+
}
|
|
108
|
+
})(
|
|
109
|
+
{
|
|
110
|
+
connection: mongoose.connection,
|
|
111
|
+
settings: new chevre.settings.Settings({
|
|
112
|
+
abortedTasksWithoutReport: [],
|
|
113
|
+
numTryConfirmReserveTransaction: 10,
|
|
114
|
+
deliverOrderLimit: 1,
|
|
115
|
+
coa: {
|
|
116
|
+
timeout: 20000
|
|
117
|
+
},
|
|
118
|
+
gmo: {
|
|
119
|
+
timeout: 5000,
|
|
120
|
+
timeoutBackground: 5000,
|
|
121
|
+
useFetch: true
|
|
122
|
+
},
|
|
123
|
+
movieticketReserve: {
|
|
124
|
+
timeout: 1000,
|
|
125
|
+
timeoutCheck: 1000,
|
|
126
|
+
minIntervalBetweenPayAndRefund: 1000,
|
|
127
|
+
credentialsExpireInSeconds: 1000
|
|
128
|
+
},
|
|
129
|
+
useExperimentalFeature: false
|
|
130
|
+
}),
|
|
131
|
+
credentials: <any>{}
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
executeById: false,
|
|
135
|
+
executeByName: true
|
|
136
|
+
}
|
|
137
|
+
);
|
|
138
|
+
console.log(
|
|
139
|
+
'deleted',
|
|
140
|
+
personId, deletingOwnershipInfo.project.id, deletingOwnershipInfo.id, deletingOwnershipInfo.ownedFrom, i
|
|
141
|
+
);
|
|
142
|
+
} catch (error) {
|
|
143
|
+
// no op
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
console.log(i, 'docs checked');
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
main()
|
|
152
|
+
.then(console.log)
|
|
153
|
+
.catch(console.error);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
// import * as moment from 'moment';
|
|
3
|
+
|
|
4
|
+
const TIMEOUT_MS = 5000;
|
|
5
|
+
const INTERVAL_MS = 3000;
|
|
6
|
+
|
|
7
|
+
let i = 0;
|
|
8
|
+
setInterval(
|
|
9
|
+
async () => {
|
|
10
|
+
i += 1;
|
|
11
|
+
try {
|
|
12
|
+
const url = String(process.env.DISCONTINUE_PEOPLE_URL);
|
|
13
|
+
const res = await fetch(
|
|
14
|
+
url,
|
|
15
|
+
{
|
|
16
|
+
signal: AbortSignal.timeout(TIMEOUT_MS),
|
|
17
|
+
method: 'GET'
|
|
18
|
+
}
|
|
19
|
+
);
|
|
20
|
+
const result = await res.text();
|
|
21
|
+
console.log('result', result, i);
|
|
22
|
+
console.log('res.status', res.status, i);
|
|
23
|
+
} catch (err) {
|
|
24
|
+
console.error(err);
|
|
25
|
+
if (err.name === 'TimeoutError') {
|
|
26
|
+
console.error('Timeout: It took more than 5 seconds to get the result!');
|
|
27
|
+
} else if (err.name === 'AbortError') {
|
|
28
|
+
console.error('Fetch aborted by user action (browser stop button, closing tab, etc.');
|
|
29
|
+
} else if (err.name === 'TypeError') {
|
|
30
|
+
console.error('AbortSignal.timeout() method is not supported');
|
|
31
|
+
} else {
|
|
32
|
+
// A network error, or some other problem.
|
|
33
|
+
console.error(`Error: type: ${err.name}, message: ${err.message}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
INTERVAL_MS
|
|
38
|
+
);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
|
|
4
|
+
import { chevre } from '../../../lib/index';
|
|
5
|
+
|
|
6
|
+
// tslint:disable-next-line:max-func-body-length
|
|
7
|
+
async function main() {
|
|
8
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
9
|
+
|
|
10
|
+
const jwtSettingRepo = await chevre.repository.setting.JWT.createInstance(mongoose.connection);
|
|
11
|
+
|
|
12
|
+
const result = await jwtSettingRepo.findDefault();
|
|
13
|
+
// tslint:disable-next-line:no-null-keyword
|
|
14
|
+
console.dir(result, { depth: null });
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
main()
|
|
18
|
+
.then(console.log)
|
|
19
|
+
.catch(console.error);
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import { CognitoIdentityProvider, ListUserPoolClientsCommandOutput, UserPoolClientDescription } from '@aws-sdk/client-cognito-identity-provider';
|
|
3
|
+
import { fromEnv } from '@aws-sdk/credential-providers';
|
|
4
|
+
import * as mongoose from 'mongoose';
|
|
5
|
+
|
|
6
|
+
import { chevre } from '../../../../lib/index';
|
|
7
|
+
|
|
8
|
+
const USERPOOL_PROVIDER_NAME = (typeof process.env.DISCONTINUE_PEOPLE_USERPOOL_PROVIDER_NAME === 'string')
|
|
9
|
+
? process.env.DISCONTINUE_PEOPLE_USERPOOL_PROVIDER_NAME
|
|
10
|
+
: '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
|
+
|
|
23
|
+
const awsCredentials = fromEnv();
|
|
24
|
+
const cognitoIdentityServiceProvider = new CognitoIdentityProvider({
|
|
25
|
+
apiVersion: 'latest',
|
|
26
|
+
region: 'ap-northeast-1',
|
|
27
|
+
credentials: awsCredentials
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// create user
|
|
31
|
+
const newPersonRepo = await chevre.repository.Person.createInstance({
|
|
32
|
+
userPoolId: userPoolId,
|
|
33
|
+
cognitoIdentityServiceProvider
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const clients: UserPoolClientDescription[] = [];
|
|
37
|
+
let nextToken: string | undefined = '';
|
|
38
|
+
let page: number = 0;
|
|
39
|
+
while (typeof nextToken === 'string') {
|
|
40
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
41
|
+
if (page > 1) {
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
page += 1;
|
|
46
|
+
console.log('listUserPoolClients processing...', nextToken, page);
|
|
47
|
+
const listUserPoolClientsResult =
|
|
48
|
+
<ListUserPoolClientsCommandOutput>await newPersonRepo.cognitoIdentityServiceProvider.listUserPoolClients(
|
|
49
|
+
{
|
|
50
|
+
MaxResults: 50,
|
|
51
|
+
UserPoolId: userPoolId,
|
|
52
|
+
...(typeof nextToken === 'string' && nextToken !== '') ? { NextToken: nextToken } : undefined
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
// tslint:disable-next-line:no-null-keyword
|
|
56
|
+
console.dir(listUserPoolClientsResult.UserPoolClients?.at(0), { depth: null });
|
|
57
|
+
nextToken = listUserPoolClientsResult.NextToken;
|
|
58
|
+
if (Array.isArray(listUserPoolClientsResult.UserPoolClients)) {
|
|
59
|
+
clients.push(...listUserPoolClientsResult.UserPoolClients);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
console.log('listUsersInGroup processed', nextToken, page);
|
|
63
|
+
console.log(clients.length, 'users found');
|
|
64
|
+
|
|
65
|
+
let i = 0;
|
|
66
|
+
let providerSupportedCount = 0;
|
|
67
|
+
for (const client of clients) {
|
|
68
|
+
i += 1;
|
|
69
|
+
|
|
70
|
+
const ClientId = client.ClientId;
|
|
71
|
+
|
|
72
|
+
// disable link provider
|
|
73
|
+
const describeUserPoolClientResult = await newPersonRepo.cognitoIdentityServiceProvider.describeUserPoolClient({
|
|
74
|
+
UserPoolId: userPoolId,
|
|
75
|
+
ClientId
|
|
76
|
+
});
|
|
77
|
+
const codeFlowAllowed = describeUserPoolClientResult.UserPoolClient?.AllowedOAuthFlows?.some(
|
|
78
|
+
(flow) => flow !== 'client_credentials'
|
|
79
|
+
);
|
|
80
|
+
if (codeFlowAllowed) {
|
|
81
|
+
const providerSupported = describeUserPoolClientResult.UserPoolClient?.SupportedIdentityProviders?.some(
|
|
82
|
+
(provider) => provider === USERPOOL_PROVIDER_NAME
|
|
83
|
+
);
|
|
84
|
+
if (providerSupported) {
|
|
85
|
+
providerSupportedCount += 1;
|
|
86
|
+
console.log(
|
|
87
|
+
'describeUserPoolClientResult:',
|
|
88
|
+
describeUserPoolClientResult.UserPoolClient?.AllowedOAuthFlows,
|
|
89
|
+
describeUserPoolClientResult.UserPoolClient?.AllowedOAuthScopes,
|
|
90
|
+
describeUserPoolClientResult.UserPoolClient?.SupportedIdentityProviders,
|
|
91
|
+
describeUserPoolClientResult.UserPoolClient?.ClientName,
|
|
92
|
+
ClientId, i
|
|
93
|
+
);
|
|
94
|
+
} else {
|
|
95
|
+
console.log(
|
|
96
|
+
'describeUserPoolClientResult:',
|
|
97
|
+
describeUserPoolClientResult.UserPoolClient?.AllowedOAuthFlows,
|
|
98
|
+
describeUserPoolClientResult.UserPoolClient?.SupportedIdentityProviders,
|
|
99
|
+
describeUserPoolClientResult.UserPoolClient?.ClientName,
|
|
100
|
+
ClientId, i
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
} else {
|
|
104
|
+
console.log(
|
|
105
|
+
'describeUserPoolClientResult:',
|
|
106
|
+
describeUserPoolClientResult.UserPoolClient?.AllowedOAuthFlows,
|
|
107
|
+
describeUserPoolClientResult.UserPoolClient?.ClientName,
|
|
108
|
+
ClientId, i
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
console.log(clients.length, 'clients processed');
|
|
114
|
+
console.log(providerSupportedCount, 'clients supported');
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
main()
|
|
118
|
+
.then()
|
|
119
|
+
.catch(console.error);
|
|
@@ -1,17 +1,28 @@
|
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
const NEW_USERPOOL_PROVIDER_NAME = 'SSKTS';
|
|
9
|
+
const USERPOOL_PROVIDER_NAME = (typeof process.env.DISCONTINUE_PEOPLE_USERPOOL_PROVIDER_NAME === 'string')
|
|
10
|
+
? process.env.DISCONTINUE_PEOPLE_USERPOOL_PROVIDER_NAME
|
|
11
|
+
: 'SSKTS';
|
|
12
12
|
|
|
13
13
|
// tslint:disable-next-line:max-func-body-length
|
|
14
14
|
async function main(): Promise<void> {
|
|
15
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
16
|
+
|
|
17
|
+
const orderRepo = await chevre.repository.Order.createInstance(mongoose.connection);
|
|
18
|
+
const settingRepo = await chevre.repository.Setting.createInstance(mongoose.connection);
|
|
19
|
+
const setting = await settingRepo.findOne({ project: { id: { $eq: '*' } } }, ['userPoolIdNew']);
|
|
20
|
+
if (typeof setting?.userPoolIdNew !== 'string') {
|
|
21
|
+
throw new chevre.factory.errors.NotFound('setting.userPoolIdNew');
|
|
22
|
+
}
|
|
23
|
+
const userPoolId: string = setting.userPoolIdNew;
|
|
24
|
+
const USER_GROUP_NAME = `${userPoolId}_${USERPOOL_PROVIDER_NAME}`; // 'ap-northeast-1_XXXXXXXXX_SSKTS',
|
|
25
|
+
|
|
15
26
|
const awsCredentials = fromEnv();
|
|
16
27
|
const cognitoIdentityServiceProvider = new CognitoIdentityProvider({
|
|
17
28
|
apiVersion: 'latest',
|
|
@@ -21,7 +32,7 @@ async function main(): Promise<void> {
|
|
|
21
32
|
|
|
22
33
|
// create user
|
|
23
34
|
const newPersonRepo = await chevre.repository.Person.createInstance({
|
|
24
|
-
userPoolId:
|
|
35
|
+
userPoolId: userPoolId,
|
|
25
36
|
cognitoIdentityServiceProvider
|
|
26
37
|
});
|
|
27
38
|
|
|
@@ -29,12 +40,17 @@ async function main(): Promise<void> {
|
|
|
29
40
|
let nextToken: string | undefined = '';
|
|
30
41
|
let page: number = 0;
|
|
31
42
|
while (typeof nextToken === 'string') {
|
|
43
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
44
|
+
// if (page > 1000) {
|
|
45
|
+
// break;
|
|
46
|
+
// }
|
|
47
|
+
|
|
32
48
|
page += 1;
|
|
33
49
|
console.log('listUsersInGroup processing...', nextToken, page);
|
|
34
|
-
const listUsersInGroupResult = await newPersonRepo.cognitoIdentityServiceProvider.listUsersInGroup(
|
|
50
|
+
const listUsersInGroupResult = <ListUsersInGroupCommandOutput>await newPersonRepo.cognitoIdentityServiceProvider.listUsersInGroup(
|
|
35
51
|
{
|
|
36
52
|
Limit: 50,
|
|
37
|
-
UserPoolId:
|
|
53
|
+
UserPoolId: userPoolId,
|
|
38
54
|
GroupName: USER_GROUP_NAME,
|
|
39
55
|
...(typeof nextToken === 'string' && nextToken !== '') ? { NextToken: nextToken } : undefined
|
|
40
56
|
}
|
|
@@ -49,42 +65,76 @@ async function main(): Promise<void> {
|
|
|
49
65
|
console.log('listUsersInGroup processed', nextToken, page);
|
|
50
66
|
console.log(users.length, 'users found');
|
|
51
67
|
|
|
52
|
-
const
|
|
53
|
-
|
|
68
|
+
const someMonthsAgo = moment()
|
|
69
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
70
|
+
.add(-3, 'months');
|
|
71
|
+
let i = 0;
|
|
54
72
|
for (const user of users) {
|
|
55
|
-
|
|
73
|
+
i += 1;
|
|
74
|
+
const isSSKTSMember = user.Username?.startsWith(USERPOOL_PROVIDER_NAME, 0);
|
|
56
75
|
if (!isSSKTSMember) {
|
|
57
76
|
console.error(user);
|
|
58
77
|
throw new Error('not ssktsMember');
|
|
59
78
|
}
|
|
60
79
|
|
|
61
80
|
const sub = user.Attributes?.find(({ Name }) => Name === 'sub')?.Value;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
81
|
+
|
|
82
|
+
// 注文が存在しなければ削除
|
|
83
|
+
console.log('searching orders...', user.Username, sub, i);
|
|
84
|
+
const existingOrders = await orderRepo.projectFields(
|
|
85
|
+
{
|
|
86
|
+
limit: 1,
|
|
87
|
+
page: 1,
|
|
88
|
+
customer: { ids: [String(sub)] }
|
|
89
|
+
},
|
|
90
|
+
{ inclusion: ['orderNumber'] }
|
|
91
|
+
);
|
|
92
|
+
console.log(existingOrders.length, 'existingOrders found', user.Username, sub, i);
|
|
93
|
+
|
|
94
|
+
if (existingOrders.length > 0) {
|
|
95
|
+
continue;
|
|
71
96
|
} else {
|
|
72
97
|
if (user.UserLastModifiedDate instanceof Date) {
|
|
73
98
|
if (moment(user.UserLastModifiedDate)
|
|
74
|
-
.isBefore(
|
|
99
|
+
.isBefore(someMonthsAgo)) {
|
|
75
100
|
console.log('adminDeleteUser prossing...', user.Username, sub);
|
|
76
101
|
const adminDeleteUserResult = await newPersonRepo.cognitoIdentityServiceProvider.adminDeleteUser({
|
|
77
|
-
UserPoolId:
|
|
102
|
+
UserPoolId: userPoolId,
|
|
78
103
|
Username: user.Username
|
|
79
104
|
});
|
|
80
105
|
console.log('adminDeleteUser processed.', user.Username, sub, adminDeleteUserResult);
|
|
81
106
|
}
|
|
82
107
|
}
|
|
83
108
|
|
|
109
|
+
// if (user.Enabled === true) {
|
|
110
|
+
// console.log('disabling...', user.Username, sub);
|
|
111
|
+
// // disable link provider
|
|
112
|
+
// const adminDisableUserResult = await newPersonRepo.cognitoIdentityServiceProvider.adminDisableUser({
|
|
113
|
+
// UserPoolId: userPoolId,
|
|
114
|
+
// Username: user.Username
|
|
115
|
+
// });
|
|
116
|
+
// console.log('disabled.', user.Username, sub, adminDisableUserResult);
|
|
117
|
+
// } else {
|
|
118
|
+
// if (user.UserLastModifiedDate instanceof Date) {
|
|
119
|
+
// if (moment(user.UserLastModifiedDate)
|
|
120
|
+
// .isBefore(oneMonthAgo)) {
|
|
121
|
+
// console.log('adminDeleteUser prossing...', user.Username, sub);
|
|
122
|
+
// const adminDeleteUserResult = await newPersonRepo.cognitoIdentityServiceProvider.adminDeleteUser({
|
|
123
|
+
// UserPoolId: userPoolId,
|
|
124
|
+
// Username: user.Username
|
|
125
|
+
// });
|
|
126
|
+
// console.log('adminDeleteUser processed.', user.Username, sub, adminDeleteUserResult);
|
|
127
|
+
// }
|
|
128
|
+
// }
|
|
129
|
+
// }
|
|
84
130
|
}
|
|
85
131
|
}
|
|
132
|
+
|
|
133
|
+
console.log(users.length, 'users processed');
|
|
86
134
|
}
|
|
87
135
|
|
|
88
136
|
main()
|
|
89
|
-
.then()
|
|
137
|
+
.then(() => {
|
|
138
|
+
console.log('success!');
|
|
139
|
+
})
|
|
90
140
|
.catch(console.error);
|