@chevre/domain 22.9.0-alpha.2 → 22.9.0-alpha.21
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/findAvailableChannelMovieTicket.ts +25 -0
- package/example/src/chevre/migrateMembers2identities.ts +109 -0
- package/example/src/chevre/migratePaymentServiceChannelsCreditCard.ts +104 -0
- package/example/src/chevre/migratePaymentServiceChannelsMovieTicket.ts +112 -0
- package/example/src/chevre/migrateProjectTokenIssuers.ts +100 -0
- package/example/src/chevre/migrateWebSites.ts +146 -0
- package/example/src/chevre/reIndex.ts +2 -1
- package/example/src/chevre/searchPaymentServices.ts +32 -0
- package/example/src/chevre/unsetUnnecessaryFields.ts +4 -5
- package/lib/chevre/repo/action.d.ts +4 -0
- package/lib/chevre/repo/action.js +2 -1
- package/lib/chevre/repo/identity.d.ts +5 -5
- package/lib/chevre/repo/identityProvider.d.ts +32 -7
- package/lib/chevre/repo/identityProvider.js +11 -4
- package/lib/chevre/repo/mongoose/schemas/action.js +2 -1
- package/lib/chevre/repo/mongoose/schemas/assetTransaction.js +2 -2
- package/lib/chevre/repo/mongoose/schemas/identity.d.ts +1 -1
- package/lib/chevre/repo/mongoose/schemas/identity.js +20 -0
- package/lib/chevre/repo/mongoose/schemas/identityProvider.d.ts +1 -29
- package/lib/chevre/repo/mongoose/schemas/identityProvider.js +4 -4
- package/lib/chevre/repo/mongoose/schemas/paymentService.js +13 -3
- package/lib/chevre/repo/mongoose/schemas/paymentServiceChannel.d.ts +10 -0
- package/lib/chevre/repo/mongoose/schemas/paymentServiceChannel.js +73 -0
- package/lib/chevre/repo/mongoose/schemas/potentialAction.d.ts +10 -0
- package/lib/chevre/repo/mongoose/schemas/potentialAction.js +56 -0
- package/lib/chevre/repo/mongoose/schemas/{interface.d.ts → reserveInterface.d.ts} +1 -1
- package/lib/chevre/repo/mongoose/schemas/{interface.js → reserveInterface.js} +2 -2
- package/lib/chevre/repo/mongoose/schemas/webSite.d.ts +10 -0
- package/lib/chevre/repo/mongoose/schemas/webSite.js +69 -0
- package/lib/chevre/repo/paymentService.d.ts +36 -7
- package/lib/chevre/repo/paymentService.js +117 -20
- package/lib/chevre/repo/paymentServiceChannel.d.ts +40 -0
- package/lib/chevre/repo/paymentServiceChannel.js +148 -0
- package/lib/chevre/repo/potentialAction.d.ts +52 -0
- package/lib/chevre/repo/potentialAction.js +136 -0
- package/lib/chevre/repo/product.js +2 -1
- package/lib/chevre/repo/project.d.ts +0 -1
- package/lib/chevre/repo/project.js +3 -5
- package/lib/chevre/repo/{interface.d.ts → reserveInterface.d.ts} +3 -4
- package/lib/chevre/repo/{interface.js → reserveInterface.js} +11 -13
- package/lib/chevre/repo/seller.d.ts +4 -4
- package/lib/chevre/repo/webSite.d.ts +39 -0
- package/lib/chevre/repo/webSite.js +133 -0
- package/lib/chevre/repository.d.ts +20 -5
- package/lib/chevre/repository.js +54 -15
- package/lib/chevre/service/assetTransaction/fixInformAction.d.ts +13 -0
- package/lib/chevre/service/assetTransaction/fixInformAction.js +51 -0
- package/lib/chevre/service/assetTransaction/pay/factory.d.ts +3 -0
- package/lib/chevre/service/assetTransaction/pay/factory.js +26 -16
- package/lib/chevre/service/assetTransaction/pay.d.ts +5 -1
- package/lib/chevre/service/assetTransaction/pay.js +20 -24
- package/lib/chevre/service/assetTransaction/refund/factory.d.ts +3 -0
- package/lib/chevre/service/assetTransaction/refund/factory.js +28 -22
- package/lib/chevre/service/assetTransaction/refund/potentialActions.js +20 -30
- package/lib/chevre/service/assetTransaction/refund.d.ts +2 -0
- package/lib/chevre/service/assetTransaction/refund.js +9 -3
- package/lib/chevre/service/assetTransaction/reserve/start/createSubReservations.js +1 -1
- package/lib/chevre/service/notification.d.ts +2 -0
- package/lib/chevre/service/notification.js +39 -15
- package/lib/chevre/service/offer/onEventChanged.js +16 -7
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered/factory.js +31 -23
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderDeliveredPartially/factory.js +31 -23
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/factory.js +31 -23
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned/factory.js +31 -23
- package/lib/chevre/service/order/onOrderUpdated/factory.js +30 -23
- package/lib/chevre/service/payment/any/factory.d.ts +12 -1
- package/lib/chevre/service/payment/any/factory.js +41 -16
- package/lib/chevre/service/payment/any/{fixConfirmationNumberAsNeeded.d.ts → fixOrderAsNeeded.d.ts} +13 -3
- package/lib/chevre/service/payment/any/fixOrderAsNeeded.js +41 -0
- package/lib/chevre/service/payment/any/{onPaid.d.ts → onPayActionCompleted.d.ts} +2 -5
- package/lib/chevre/service/payment/any/{onPaid.js → onPayActionCompleted.js} +34 -10
- package/lib/chevre/service/payment/any/{onRefund.d.ts → onRefundActionCompletedOrFailed.d.ts} +4 -2
- package/lib/chevre/service/payment/any/{onRefund.js → onRefundActionCompletedOrFailed.js} +42 -12
- package/lib/chevre/service/payment/any.d.ts +7 -1
- package/lib/chevre/service/payment/any.js +12 -11
- package/lib/chevre/service/payment/creditCard/authorize/processAuthorizeCreditCard.d.ts +1 -1
- package/lib/chevre/service/payment/creditCard/authorize/processAuthorizeCreditCard3ds.d.ts +1 -1
- package/lib/chevre/service/payment/creditCard/authorize.js +2 -2
- package/lib/chevre/service/payment/creditCard/payCreditCard.js +5 -5
- package/lib/chevre/service/payment/creditCard/refundCreditCard.js +4 -4
- package/lib/chevre/service/payment/creditCard/searchGMOTrade.d.ts +1 -1
- package/lib/chevre/service/payment/creditCard/voidTransaction.js +2 -2
- package/lib/chevre/service/payment/faceToFace.js +5 -5
- package/lib/chevre/service/payment/factory.d.ts +1 -1
- package/lib/chevre/service/payment/factory.js +20 -34
- package/lib/chevre/service/payment/movieTicket/authorize.js +21 -12
- package/lib/chevre/service/payment/movieTicket/factory.d.ts +1 -1
- package/lib/chevre/service/payment/movieTicket/factory.js +9 -13
- package/lib/chevre/service/payment/movieTicket/payMovieTicket.d.ts +5 -1
- package/lib/chevre/service/payment/movieTicket/payMovieTicket.js +15 -14
- package/lib/chevre/service/payment/movieTicket/processPurchaseNumberAuth.js +1 -2
- package/lib/chevre/service/payment/movieTicket/refundMovieTicket.d.ts +2 -0
- package/lib/chevre/service/payment/movieTicket/refundMovieTicket.js +15 -13
- package/lib/chevre/service/payment/movieTicket/voidTransaction.js +2 -1
- package/lib/chevre/service/payment/paymentCard.js +5 -6
- package/lib/chevre/service/reserve/potentialActions/onPendingReservationCanceled.js +8 -2
- package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.js +8 -2
- package/lib/chevre/service/reserve/potentialActions/onReservationCheckedIn.js +8 -2
- package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.js +8 -2
- package/lib/chevre/service/reserve/potentialActions/onReservationUsed.js +8 -2
- package/lib/chevre/service/reserve/potentialActions/onReservationsCreated.js +8 -2
- package/lib/chevre/service/task/acceptCOAOffer.js +3 -3
- package/lib/chevre/service/task/authorizePayment.js +7 -6
- package/lib/chevre/service/task/confirmReserveTransaction.js +3 -3
- package/lib/chevre/service/task/deletePerson.js +16 -8
- package/lib/chevre/service/task/importEventCapacitiesFromCOA.js +3 -3
- package/lib/chevre/service/task/importEventsFromCOA.js +3 -3
- package/lib/chevre/service/task/importOffersFromCOA.js +3 -4
- package/lib/chevre/service/task/onResourceUpdated/onAggregateOfferUpdated.js +8 -5
- package/lib/chevre/service/task/onResourceUpdated/onHasPOSUpdated.js +8 -5
- package/lib/chevre/service/task/onResourceUpdated/onOfferCatalogUpdated.js +8 -5
- package/lib/chevre/service/task/onResourceUpdated.js +48 -27
- package/lib/chevre/service/task/pay.js +3 -3
- package/lib/chevre/service/task/payment/payByTask.d.ts +48 -0
- package/lib/chevre/service/{payment.js → task/payment/payByTask.js} +14 -63
- package/lib/chevre/service/task/payment/refundByTask.d.ts +31 -0
- package/lib/chevre/service/task/payment/refundByTask.js +39 -0
- package/lib/chevre/service/task/payment/voidPaymentByTask.d.ts +23 -0
- package/lib/chevre/service/task/payment/voidPaymentByTask.js +38 -0
- package/lib/chevre/service/task/refund.js +2 -2
- package/lib/chevre/service/task/returnPayTransaction.js +3 -0
- package/lib/chevre/service/task/returnReserveTransaction.js +3 -3
- package/lib/chevre/service/task/triggerWebhook.js +2 -2
- package/lib/chevre/service/task/voidPayment.js +2 -2
- package/lib/chevre/service/task/voidReserveTransaction.js +3 -3
- package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.js +25 -19
- package/lib/chevre/service/transaction/placeOrder.js +0 -2
- package/package.json +3 -3
- package/example/src/chevre/migrateProjectMakesOfferAvailableAt.ts +0 -85
- package/example/src/chevre/searchPriceSpecifications.ts +0 -56
- package/lib/chevre/service/payment/any/fixConfirmationNumberAsNeeded.js +0 -31
- package/lib/chevre/service/payment.d.ts +0 -95
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
|
|
4
|
+
import { chevre } from '../../../lib/index';
|
|
5
|
+
|
|
6
|
+
const project = { id: String(process.env.PROJECT_ID) };
|
|
7
|
+
|
|
8
|
+
async function main() {
|
|
9
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI);
|
|
10
|
+
|
|
11
|
+
const paymentServiceRepo = await chevre.repository.PaymentService.createInstance(mongoose.connection);
|
|
12
|
+
|
|
13
|
+
const result = await paymentServiceRepo.findAvailableChannelMovieTicket({
|
|
14
|
+
id: '5f9a52994f3709000abe6417',
|
|
15
|
+
project: {
|
|
16
|
+
id: project.id
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
// tslint:disable-next-line:no-null-keyword
|
|
20
|
+
console.dir(result, { depth: null });
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
main()
|
|
24
|
+
.then()
|
|
25
|
+
.catch(console.error);
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
|
|
4
|
+
import { chevre } from '../../../lib/index';
|
|
5
|
+
|
|
6
|
+
// const project = { id: String(process.env.PROJECT_ID) };
|
|
7
|
+
// const excludedProject = { id: String(process.env.EXCLUDED_PROJECT_ID) };
|
|
8
|
+
|
|
9
|
+
const AVAILABLE_ROLES = [
|
|
10
|
+
chevre.factory.iam.RoleName.Customer,
|
|
11
|
+
chevre.factory.iam.RoleName.EventsViewer,
|
|
12
|
+
chevre.factory.iam.RoleName.POS
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
// tslint:disable-next-line:max-func-body-length
|
|
16
|
+
async function main() {
|
|
17
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
18
|
+
|
|
19
|
+
const identityRepo = await chevre.repository.Identity.createInstance(mongoose.connection);
|
|
20
|
+
const memberRepo = await chevre.repository.Member.createInstance(mongoose.connection);
|
|
21
|
+
const projectRepo = await chevre.repository.Project.createInstance(mongoose.connection);
|
|
22
|
+
|
|
23
|
+
const cursor = memberRepo.getCursor(
|
|
24
|
+
{
|
|
25
|
+
// _id: { $eq: 'cinerino' }
|
|
26
|
+
'member.typeOf': { $eq: chevre.factory.creativeWorkType.WebApplication },
|
|
27
|
+
'project.id': { $ne: '*' }
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
_id: 1,
|
|
31
|
+
project: 1,
|
|
32
|
+
member: 1,
|
|
33
|
+
typeOf: 1
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
|
+
console.log('docs found');
|
|
37
|
+
|
|
38
|
+
let i = 0;
|
|
39
|
+
let updateCount = 0;
|
|
40
|
+
let projectIdsWithoutCustomProviders: string[] = [];
|
|
41
|
+
let projectIdsWithCustomProviders: string[] = [];
|
|
42
|
+
await cursor.eachAsync(async (doc) => {
|
|
43
|
+
i += 1;
|
|
44
|
+
const iamMember: Pick<chevre.factory.iam.IMember, 'project' | 'member' | 'typeOf'> = doc.toObject();
|
|
45
|
+
const roleNames = iamMember.member.hasRole.map(({ roleName }) => roleName)
|
|
46
|
+
.join(',');
|
|
47
|
+
const expectedRoles = iamMember.member.hasRole.length === 1 &&
|
|
48
|
+
iamMember.member.hasRole.every(({ roleName }) => AVAILABLE_ROLES.includes(roleName));
|
|
49
|
+
if (!expectedRoles) {
|
|
50
|
+
throw new Error('roles not expected');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const projectSettings = (await projectRepo.findById({
|
|
54
|
+
id: iamMember.project.id,
|
|
55
|
+
inclusion: ['settings']
|
|
56
|
+
})).settings;
|
|
57
|
+
const tokenIssuers: string[] = Array.isArray((<any>projectSettings).tokenIssuers) ? (<any>projectSettings).tokenIssuers : [];
|
|
58
|
+
if (tokenIssuers.length > 0) {
|
|
59
|
+
projectIdsWithCustomProviders.push(iamMember.project.id);
|
|
60
|
+
} else {
|
|
61
|
+
projectIdsWithoutCustomProviders.push(iamMember.project.id);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
console.log(
|
|
65
|
+
'alreadyMigrated?',
|
|
66
|
+
iamMember.member.id, iamMember.member.typeOf, iamMember.project.id, roleNames, tokenIssuers.length, 'tokenIssuers', i);
|
|
67
|
+
let alreadyMigrated = false;
|
|
68
|
+
const existingIdentity = (await identityRepo.projectFields(
|
|
69
|
+
{
|
|
70
|
+
limit: 1,
|
|
71
|
+
page: 1,
|
|
72
|
+
project: { id: { $eq: iamMember.project.id } },
|
|
73
|
+
about: { id: { $eq: iamMember.member.id } }
|
|
74
|
+
},
|
|
75
|
+
['about']
|
|
76
|
+
)).shift();
|
|
77
|
+
alreadyMigrated = existingIdentity?.about.id === iamMember.member.id
|
|
78
|
+
&& existingIdentity.about.typeOf === iamMember.member.typeOf;
|
|
79
|
+
|
|
80
|
+
if (alreadyMigrated) {
|
|
81
|
+
console.log(
|
|
82
|
+
'already migrated.', iamMember.member.id, iamMember.member.typeOf, iamMember.project.id, i);
|
|
83
|
+
} else {
|
|
84
|
+
if (tokenIssuers.length === 1) {
|
|
85
|
+
console.log(
|
|
86
|
+
'updating project...',
|
|
87
|
+
iamMember.member.id, iamMember.member.typeOf, iamMember.project.id, i);
|
|
88
|
+
// await identityProviderRepo.save({
|
|
89
|
+
// attributes: newProvider
|
|
90
|
+
// });
|
|
91
|
+
updateCount += 1;
|
|
92
|
+
console.log(
|
|
93
|
+
'updated.',
|
|
94
|
+
iamMember.member.id, iamMember.member.typeOf, iamMember.project.id, i);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
projectIdsWithoutCustomProviders = [...new Set(projectIdsWithoutCustomProviders)];
|
|
100
|
+
projectIdsWithCustomProviders = [...new Set(projectIdsWithCustomProviders)];
|
|
101
|
+
console.log(projectIdsWithoutCustomProviders);
|
|
102
|
+
console.log(projectIdsWithCustomProviders);
|
|
103
|
+
console.log(i, 'docs checked');
|
|
104
|
+
console.log(updateCount, 'docs updated');
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
main()
|
|
108
|
+
.then()
|
|
109
|
+
.catch(console.error);
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
|
|
4
|
+
import { chevre } from '../../../lib/index';
|
|
5
|
+
|
|
6
|
+
// const project = { id: String(process.env.PROJECT_ID) };
|
|
7
|
+
// const excludedProject = { id: String(process.env.EXCLUDED_PROJECT_ID) };
|
|
8
|
+
|
|
9
|
+
// tslint:disable-next-line:max-func-body-length
|
|
10
|
+
async function main() {
|
|
11
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
12
|
+
|
|
13
|
+
const paymentServiceRepo = await chevre.repository.PaymentService.createInstance(mongoose.connection);
|
|
14
|
+
|
|
15
|
+
const cursor = paymentServiceRepo.getCursor(
|
|
16
|
+
{
|
|
17
|
+
typeOf: { $eq: chevre.factory.service.paymentService.PaymentServiceType.CreditCard }
|
|
18
|
+
// _id: { $eq: 'cinerino' }
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
_id: 1,
|
|
22
|
+
availableChannel: 1,
|
|
23
|
+
productID: 1,
|
|
24
|
+
project: 1,
|
|
25
|
+
typeOf: 1
|
|
26
|
+
}
|
|
27
|
+
);
|
|
28
|
+
console.log('docs found');
|
|
29
|
+
|
|
30
|
+
let i = 0;
|
|
31
|
+
let updateCount = 0;
|
|
32
|
+
let serviceUrls: string[] = [];
|
|
33
|
+
const unexpectedProjectIds: string[] = [];
|
|
34
|
+
await cursor.eachAsync(async (doc) => {
|
|
35
|
+
i += 1;
|
|
36
|
+
const paymentService: Pick<
|
|
37
|
+
chevre.factory.service.paymentService.IService,
|
|
38
|
+
'availableChannel' | 'id' | 'productID' | 'project' | 'typeOf'
|
|
39
|
+
> = doc.toObject();
|
|
40
|
+
|
|
41
|
+
console.log(
|
|
42
|
+
'alreadyMigrated?', paymentService.project.id, i);
|
|
43
|
+
if (typeof paymentService.id !== 'string') {
|
|
44
|
+
throw new Error('id must be string');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let alreadyMigrated = false;
|
|
48
|
+
try {
|
|
49
|
+
const existingChannel = await paymentServiceRepo.findAvailableChannelCreditCard({
|
|
50
|
+
project: { id: paymentService.project.id },
|
|
51
|
+
id: paymentService.id
|
|
52
|
+
});
|
|
53
|
+
if (typeof existingChannel.credentials?.siteId === 'string'
|
|
54
|
+
&& typeof existingChannel.credentials?.sitePass === 'string') {
|
|
55
|
+
alreadyMigrated = true;
|
|
56
|
+
}
|
|
57
|
+
} catch (error) {
|
|
58
|
+
// no op
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const serviceUrl = paymentService.availableChannel?.serviceUrl;
|
|
62
|
+
if (typeof serviceUrl === 'string') {
|
|
63
|
+
serviceUrls.push(serviceUrl);
|
|
64
|
+
} else {
|
|
65
|
+
throw new Error('serviceUrl must be string');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// docs(same serviceUrl and different siteId,sitePass ) exist?
|
|
69
|
+
// const credentials =
|
|
70
|
+
// <chevre.factory.serviceChannel.ICredentialsCreditCard | undefined>paymentService.availableChannel?.credentials;
|
|
71
|
+
// if (typeof credentials?.siteId !== 'string') {
|
|
72
|
+
// throw new Error('siteId must be string');
|
|
73
|
+
// }
|
|
74
|
+
// if (typeof credentials?.sitePass !== 'string') {
|
|
75
|
+
// throw new Error('sitePass must be string');
|
|
76
|
+
// }
|
|
77
|
+
|
|
78
|
+
if (alreadyMigrated) {
|
|
79
|
+
console.log(
|
|
80
|
+
'already migrated.', paymentService.project.id, i);
|
|
81
|
+
} else {
|
|
82
|
+
console.log(
|
|
83
|
+
'updating...',
|
|
84
|
+
paymentService.project.id, i);
|
|
85
|
+
// await paymentServiceRepo.saveChannelByServiceUrl(newChannel);
|
|
86
|
+
updateCount += 1;
|
|
87
|
+
console.log(
|
|
88
|
+
'updated.',
|
|
89
|
+
paymentService.project.id, i);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
serviceUrls = [...new Set(serviceUrls)];
|
|
94
|
+
console.log('unexpectedProjectIds:', unexpectedProjectIds);
|
|
95
|
+
// console.log(serviceUrls);
|
|
96
|
+
console.log(serviceUrls);
|
|
97
|
+
console.log(serviceUrls.length, 'serviceUrls found');
|
|
98
|
+
console.log(i, 'docs checked');
|
|
99
|
+
console.log(updateCount, 'docs updated');
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
main()
|
|
103
|
+
.then()
|
|
104
|
+
.catch(console.error);
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
|
|
4
|
+
import { chevre } from '../../../lib/index';
|
|
5
|
+
|
|
6
|
+
// const project = { id: String(process.env.PROJECT_ID) };
|
|
7
|
+
// const excludedProject = { id: String(process.env.EXCLUDED_PROJECT_ID) };
|
|
8
|
+
|
|
9
|
+
// tslint:disable-next-line:max-func-body-length
|
|
10
|
+
async function main() {
|
|
11
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
12
|
+
|
|
13
|
+
const paymentServiceRepo = await chevre.repository.PaymentService.createInstance(mongoose.connection);
|
|
14
|
+
|
|
15
|
+
const cursor = paymentServiceRepo.getCursor(
|
|
16
|
+
{
|
|
17
|
+
typeOf: { $eq: chevre.factory.service.paymentService.PaymentServiceType.MovieTicket }
|
|
18
|
+
// _id: { $eq: 'cinerino' }
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
_id: 1,
|
|
22
|
+
availableChannel: 1,
|
|
23
|
+
productID: 1,
|
|
24
|
+
project: 1,
|
|
25
|
+
typeOf: 1
|
|
26
|
+
}
|
|
27
|
+
);
|
|
28
|
+
console.log('docs found');
|
|
29
|
+
|
|
30
|
+
let i = 0;
|
|
31
|
+
let updateCount = 0;
|
|
32
|
+
let serviceUrls: string[] = [];
|
|
33
|
+
const unexpectedProjectIds: string[] = [];
|
|
34
|
+
await cursor.eachAsync(async (doc) => {
|
|
35
|
+
i += 1;
|
|
36
|
+
const paymentService: Pick<
|
|
37
|
+
chevre.factory.service.paymentService.IService,
|
|
38
|
+
'availableChannel' | 'id' | 'productID' | 'project' | 'typeOf'
|
|
39
|
+
> = doc.toObject();
|
|
40
|
+
|
|
41
|
+
console.log(
|
|
42
|
+
'alreadyMigrated?', paymentService.project.id, i);
|
|
43
|
+
if (typeof paymentService.id !== 'string') {
|
|
44
|
+
throw new Error('id must be string');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let alreadyMigrated = false;
|
|
48
|
+
try {
|
|
49
|
+
const existingChannel = await paymentServiceRepo.findAvailableChannelMovieTicket({
|
|
50
|
+
project: { id: paymentService.project.id },
|
|
51
|
+
id: paymentService.id
|
|
52
|
+
});
|
|
53
|
+
if (typeof existingChannel.credentials?.authorizeServerDomain === 'string') {
|
|
54
|
+
alreadyMigrated = true;
|
|
55
|
+
}
|
|
56
|
+
} catch (error) {
|
|
57
|
+
// no op
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const serviceUrl = paymentService.availableChannel?.serviceUrl;
|
|
61
|
+
if (typeof serviceUrl === 'string') {
|
|
62
|
+
serviceUrls.push(serviceUrl);
|
|
63
|
+
} else {
|
|
64
|
+
throw new Error('serviceUrl must be string');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (alreadyMigrated) {
|
|
68
|
+
console.log(
|
|
69
|
+
'already migrated.', paymentService.project.id, i);
|
|
70
|
+
} else {
|
|
71
|
+
const credentials =
|
|
72
|
+
<chevre.factory.serviceChannel.ICredentialsMovieTicket | undefined>paymentService.availableChannel?.credentials;
|
|
73
|
+
if (typeof credentials?.authorizeServerDomain !== 'string') {
|
|
74
|
+
throw new Error('authorizeServerDomain must be string');
|
|
75
|
+
}
|
|
76
|
+
if (typeof credentials?.clientId !== 'string') {
|
|
77
|
+
throw new Error('clientId must be string');
|
|
78
|
+
}
|
|
79
|
+
if (typeof credentials?.clientSecret !== 'string') {
|
|
80
|
+
throw new Error('clientSecret must be string');
|
|
81
|
+
}
|
|
82
|
+
const newChannel: chevre.factory.serviceChannel.IServiceChannelMovieTicket = {
|
|
83
|
+
credentials,
|
|
84
|
+
project: { id: '*', typeOf: chevre.factory.organizationType.Project },
|
|
85
|
+
providesService: {
|
|
86
|
+
typeOf: chevre.factory.service.paymentService.PaymentServiceType.MovieTicket
|
|
87
|
+
},
|
|
88
|
+
serviceUrl,
|
|
89
|
+
typeOf: 'ServiceChannel'
|
|
90
|
+
};
|
|
91
|
+
console.log(
|
|
92
|
+
'updating...',
|
|
93
|
+
paymentService.project.id, i, newChannel);
|
|
94
|
+
await paymentServiceRepo.saveChannelByServiceUrl(newChannel);
|
|
95
|
+
updateCount += 1;
|
|
96
|
+
console.log(
|
|
97
|
+
'updated.',
|
|
98
|
+
paymentService.project.id, i);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
serviceUrls = [...new Set(serviceUrls)];
|
|
103
|
+
console.log('unexpectedProjectIds:', unexpectedProjectIds);
|
|
104
|
+
console.log(serviceUrls);
|
|
105
|
+
console.log(serviceUrls.length, 'serviceUrls found');
|
|
106
|
+
console.log(i, 'docs checked');
|
|
107
|
+
console.log(updateCount, 'docs updated');
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
main()
|
|
111
|
+
.then()
|
|
112
|
+
.catch(console.error);
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
|
|
4
|
+
import { chevre } from '../../../lib/index';
|
|
5
|
+
|
|
6
|
+
// const project = { id: String(process.env.PROJECT_ID) };
|
|
7
|
+
// const excludedProject = { id: String(process.env.EXCLUDED_PROJECT_ID) };
|
|
8
|
+
|
|
9
|
+
// tslint:disable-next-line:max-func-body-length
|
|
10
|
+
async function main() {
|
|
11
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
12
|
+
|
|
13
|
+
const identityProviderRepo = await chevre.repository.IdentityProvider.createInstance(mongoose.connection);
|
|
14
|
+
const projectRepo = await chevre.repository.Project.createInstance(mongoose.connection);
|
|
15
|
+
|
|
16
|
+
const cursor = projectRepo.getCursor(
|
|
17
|
+
{
|
|
18
|
+
// _id: { $eq: 'cinerino' }
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
_id: 1,
|
|
22
|
+
settings: 1,
|
|
23
|
+
typeOf: 1
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
console.log('docs found');
|
|
27
|
+
|
|
28
|
+
let i = 0;
|
|
29
|
+
let updateCount = 0;
|
|
30
|
+
await cursor.eachAsync(async (doc) => {
|
|
31
|
+
i += 1;
|
|
32
|
+
const project: Pick<chevre.factory.project.IProject, 'id' | 'typeOf' | 'settings'> = doc.toObject();
|
|
33
|
+
|
|
34
|
+
console.log(
|
|
35
|
+
'alreadyMigrated?', project.id, i);
|
|
36
|
+
const tokenIssuers: string[] | undefined = (<any>project.settings).tokenIssuers;
|
|
37
|
+
let alreadyMigrated = false;
|
|
38
|
+
if (Array.isArray(tokenIssuers)) {
|
|
39
|
+
let existingProvidersCount = 0;
|
|
40
|
+
for (const tokenIssuer of tokenIssuers) {
|
|
41
|
+
const existingProviders = await identityProviderRepo.projectFields(
|
|
42
|
+
{
|
|
43
|
+
limit: 1,
|
|
44
|
+
page: 1,
|
|
45
|
+
project: { id: { $eq: project.id } },
|
|
46
|
+
identifier: { $eq: tokenIssuer }
|
|
47
|
+
},
|
|
48
|
+
['identifier']
|
|
49
|
+
);
|
|
50
|
+
existingProvidersCount += existingProviders.length;
|
|
51
|
+
}
|
|
52
|
+
if (existingProvidersCount === tokenIssuers.length) {
|
|
53
|
+
alreadyMigrated = true;
|
|
54
|
+
}
|
|
55
|
+
} else {
|
|
56
|
+
alreadyMigrated = true;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (alreadyMigrated) {
|
|
60
|
+
console.log(
|
|
61
|
+
'already migrated.', project.id, i);
|
|
62
|
+
} else {
|
|
63
|
+
if (Array.isArray(tokenIssuers)) {
|
|
64
|
+
const newProviders = tokenIssuers.map((tokenIssuer) => {
|
|
65
|
+
return {
|
|
66
|
+
identifier: tokenIssuer,
|
|
67
|
+
project: {
|
|
68
|
+
id: project.id,
|
|
69
|
+
typeOf: <chevre.factory.organizationType.Project>chevre.factory.organizationType.Project
|
|
70
|
+
},
|
|
71
|
+
typeOf: <chevre.factory.organizationType.Organization>chevre.factory.organizationType.Organization,
|
|
72
|
+
verified: true
|
|
73
|
+
};
|
|
74
|
+
});
|
|
75
|
+
console.log(
|
|
76
|
+
'updating project...',
|
|
77
|
+
project.id, i, newProviders.length, 'newProviders');
|
|
78
|
+
for (const newProvider of newProviders) {
|
|
79
|
+
console.log(
|
|
80
|
+
'updating project...',
|
|
81
|
+
project.id, i, newProvider);
|
|
82
|
+
// await identityProviderRepo.save({
|
|
83
|
+
// attributes: newProvider
|
|
84
|
+
// });
|
|
85
|
+
}
|
|
86
|
+
updateCount += 1;
|
|
87
|
+
console.log(
|
|
88
|
+
'updated.',
|
|
89
|
+
project.id, i);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
console.log(i, 'docs checked');
|
|
95
|
+
console.log(updateCount, 'docs updated');
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
main()
|
|
99
|
+
.then()
|
|
100
|
+
.catch(console.error);
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
|
|
4
|
+
import { chevre } from '../../../lib/index';
|
|
5
|
+
|
|
6
|
+
// const project = { id: String(process.env.PROJECT_ID) };
|
|
7
|
+
// const excludedProject = { id: String(process.env.EXCLUDED_PROJECT_ID) };
|
|
8
|
+
|
|
9
|
+
// tslint:disable-next-line:max-func-body-length
|
|
10
|
+
async function main() {
|
|
11
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
12
|
+
|
|
13
|
+
const paymentServiceRepo = await chevre.repository.PaymentService.createInstance(mongoose.connection);
|
|
14
|
+
const potentialActionRepo = await chevre.repository.PotentialAction.createInstance(mongoose.connection);
|
|
15
|
+
const identityProviderRepo = await chevre.repository.IdentityProvider.createInstance(mongoose.connection);
|
|
16
|
+
const webSiteRepo = await chevre.repository.WebSite.createInstance(mongoose.connection);
|
|
17
|
+
|
|
18
|
+
let webSiteIdentifiers: string[] = [];
|
|
19
|
+
|
|
20
|
+
const cursor = paymentServiceRepo.getCursor(
|
|
21
|
+
{
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
_id: 1,
|
|
25
|
+
availableChannel: 1,
|
|
26
|
+
productID: 1,
|
|
27
|
+
project: 1,
|
|
28
|
+
typeOf: 1
|
|
29
|
+
}
|
|
30
|
+
);
|
|
31
|
+
console.log('docs found');
|
|
32
|
+
|
|
33
|
+
await cursor.eachAsync(async (doc) => {
|
|
34
|
+
const paymentService: Pick<
|
|
35
|
+
chevre.factory.service.paymentService.IService,
|
|
36
|
+
'availableChannel' | 'id' | 'productID' | 'project' | 'typeOf'
|
|
37
|
+
> = doc.toObject();
|
|
38
|
+
|
|
39
|
+
const serviceUrl = paymentService.availableChannel?.serviceUrl;
|
|
40
|
+
if (typeof serviceUrl === 'string') {
|
|
41
|
+
webSiteIdentifiers.push((new URL(serviceUrl).hostname));
|
|
42
|
+
} else {
|
|
43
|
+
throw new Error('serviceUrl must be string');
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const cursor2 = potentialActionRepo.getCursor(
|
|
48
|
+
{
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
target: 1
|
|
52
|
+
}
|
|
53
|
+
);
|
|
54
|
+
console.log('docs found');
|
|
55
|
+
|
|
56
|
+
await cursor2.eachAsync(async (doc) => {
|
|
57
|
+
const potentialAction: Pick<
|
|
58
|
+
chevre.factory.potentialAction.IPotentialAction,
|
|
59
|
+
'target'
|
|
60
|
+
> = doc.toObject();
|
|
61
|
+
|
|
62
|
+
const urlTemplate = potentialAction.target.urlTemplate;
|
|
63
|
+
if (typeof urlTemplate === 'string') {
|
|
64
|
+
webSiteIdentifiers.push((new URL(urlTemplate).hostname));
|
|
65
|
+
} else {
|
|
66
|
+
throw new Error('urlTemplate must be string');
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const cursor3 = identityProviderRepo.getCursor(
|
|
71
|
+
{
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
identifier: 1
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
console.log('docs found');
|
|
78
|
+
|
|
79
|
+
await cursor3.eachAsync(async (doc) => {
|
|
80
|
+
const identityProvider: Pick<
|
|
81
|
+
chevre.factory.identityProvider.IIdentityProvider,
|
|
82
|
+
'identifier'
|
|
83
|
+
> = doc.toObject();
|
|
84
|
+
|
|
85
|
+
if (typeof identityProvider.identifier === 'string') {
|
|
86
|
+
webSiteIdentifiers.push((new URL(identityProvider.identifier).hostname));
|
|
87
|
+
} else {
|
|
88
|
+
throw new Error('identityProvider.identifier must be string');
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
webSiteIdentifiers = [...new Set(webSiteIdentifiers)];
|
|
93
|
+
console.log(webSiteIdentifiers);
|
|
94
|
+
console.log(webSiteIdentifiers.length, 'webSiteIdentifiers found');
|
|
95
|
+
|
|
96
|
+
let i = 0;
|
|
97
|
+
let updateCount = 0;
|
|
98
|
+
|
|
99
|
+
for (const webSiteIdentifier of webSiteIdentifiers) {
|
|
100
|
+
i += 1;
|
|
101
|
+
|
|
102
|
+
const existingWebSites = await webSiteRepo.projectFields(
|
|
103
|
+
{
|
|
104
|
+
about: { identifier: { $eq: webSiteIdentifier } }
|
|
105
|
+
},
|
|
106
|
+
['about']
|
|
107
|
+
);
|
|
108
|
+
const alreadyMigrated = existingWebSites.length === 1;
|
|
109
|
+
if (alreadyMigrated) {
|
|
110
|
+
console.log(
|
|
111
|
+
'already migrated.', webSiteIdentifier, i);
|
|
112
|
+
} else {
|
|
113
|
+
const creatingWebSite: Pick<
|
|
114
|
+
chevre.factory.creativeWork.certification.webSite.ICertification,
|
|
115
|
+
'about' | 'certificationStatus' | 'project' | 'auditDate'
|
|
116
|
+
> = {
|
|
117
|
+
project: { id: '*', typeOf: chevre.factory.organizationType.Project },
|
|
118
|
+
about: { identifier: webSiteIdentifier, typeOf: chevre.factory.creativeWorkType.WebSite },
|
|
119
|
+
certificationStatus: chevre.factory.CertificationStatusEnumeration.CertificationInactive
|
|
120
|
+
};
|
|
121
|
+
console.log(
|
|
122
|
+
'updating...', i, creatingWebSite);
|
|
123
|
+
const { id } = await webSiteRepo.save({
|
|
124
|
+
attributes: creatingWebSite
|
|
125
|
+
});
|
|
126
|
+
await webSiteRepo.save({
|
|
127
|
+
id,
|
|
128
|
+
attributes: {
|
|
129
|
+
...creatingWebSite,
|
|
130
|
+
auditDate: new Date(),
|
|
131
|
+
certificationStatus: chevre.factory.CertificationStatusEnumeration.CertificationActive
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
updateCount += 1;
|
|
135
|
+
console.log(
|
|
136
|
+
'updated.', i);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
console.log(i, 'docs checked');
|
|
141
|
+
console.log(updateCount, 'docs updated');
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
main()
|
|
145
|
+
.then()
|
|
146
|
+
.catch(console.error);
|
|
@@ -11,7 +11,8 @@ mongoose.Model.on('index', (...args) => {
|
|
|
11
11
|
async function main() {
|
|
12
12
|
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
13
13
|
|
|
14
|
-
await chevre.repository.
|
|
14
|
+
await chevre.repository.Identity.createInstance(mongoose.connection);
|
|
15
|
+
await chevre.repository.IdentityProvider.createInstance(mongoose.connection);
|
|
15
16
|
console.log('success!');
|
|
16
17
|
}
|
|
17
18
|
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// tslint:disable:no-implicit-dependencies no-console
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
import { chevre } from '../../../lib/index';
|
|
4
|
+
|
|
5
|
+
const project = { id: String(process.env.PROJECT_ID) };
|
|
6
|
+
|
|
7
|
+
async function main() {
|
|
8
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
9
|
+
|
|
10
|
+
const paymentServiceRepo = await chevre.repository.PaymentService.createInstance(mongoose.connection);
|
|
11
|
+
|
|
12
|
+
const limit = 10;
|
|
13
|
+
const page = 1;
|
|
14
|
+
const docs = await paymentServiceRepo.projectFields(
|
|
15
|
+
{
|
|
16
|
+
limit,
|
|
17
|
+
page,
|
|
18
|
+
project: { id: { $eq: project.id } },
|
|
19
|
+
availableChannel: { serviceUrl: { $eq: 'xxx' } }
|
|
20
|
+
},
|
|
21
|
+
['availableChannel', 'productID']
|
|
22
|
+
);
|
|
23
|
+
// tslint:disable-next-line:no-null-keyword
|
|
24
|
+
console.dir(docs, { depth: null });
|
|
25
|
+
console.log(docs.length, 'docs found');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
main()
|
|
29
|
+
.then(() => {
|
|
30
|
+
console.log('success!');
|
|
31
|
+
})
|
|
32
|
+
.catch(console.error);
|
|
@@ -9,17 +9,16 @@ 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 identityProviderRepo = await chevre.repository.IdentityProvider.createInstance(mongoose.connection);
|
|
13
13
|
|
|
14
14
|
let updateResult: any;
|
|
15
|
-
|
|
15
|
+
|
|
16
|
+
updateResult = await identityProviderRepo.unsetUnnecessaryFields({
|
|
16
17
|
filter: {
|
|
17
18
|
_id: { $exists: true }
|
|
18
19
|
},
|
|
19
20
|
$unset: {
|
|
20
|
-
|
|
21
|
-
updatedAt: 1,
|
|
22
|
-
__v: 1
|
|
21
|
+
verified: 1
|
|
23
22
|
}
|
|
24
23
|
});
|
|
25
24
|
console.log(updateResult);
|