@chevre/domain 21.37.0-alpha.8 → 21.37.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/processOrder.ts +87 -0
- package/example/src/chevre/transaction/processPlaceOrder.ts +17 -143
- package/lib/chevre/factory/reservedAgentIdentifireNames.js +2 -1
- package/lib/chevre/factory/transaction.d.ts +1 -4
- package/lib/chevre/repo/passport.d.ts +39 -0
- package/lib/chevre/repo/passport.js +134 -0
- package/lib/chevre/repo/task.d.ts +9 -0
- package/lib/chevre/repo/task.js +23 -2
- package/lib/chevre/repository.d.ts +5 -0
- package/lib/chevre/repository.js +15 -2
- package/lib/chevre/service/accountTransaction/deposit.js +0 -1
- package/lib/chevre/service/accountTransaction/transfer.js +0 -1
- package/lib/chevre/service/accountTransaction/withdraw.js +0 -1
- package/lib/chevre/service/assetTransaction/reserve/cancel.d.ts +22 -0
- package/lib/chevre/service/assetTransaction/reserve/cancel.js +41 -0
- package/lib/chevre/service/assetTransaction/reserve/confirm/factory.d.ts +8 -0
- package/lib/chevre/service/assetTransaction/reserve/confirm/factory.js +94 -0
- package/lib/chevre/service/assetTransaction/reserve/confirm.d.ts +19 -0
- package/lib/chevre/service/assetTransaction/reserve/confirm.js +93 -0
- package/lib/chevre/service/assetTransaction/reserve/exportTasksById.d.ts +15 -0
- package/lib/chevre/service/assetTransaction/reserve/exportTasksById.js +99 -0
- package/lib/chevre/service/assetTransaction/reserve/start/createSubReservations.d.ts +28 -0
- package/lib/chevre/service/assetTransaction/reserve/start/createSubReservations.js +405 -0
- package/lib/chevre/service/assetTransaction/reserve/start/factory/createPointAward.d.ts +15 -0
- package/lib/chevre/service/assetTransaction/reserve/start/factory/createPointAward.js +40 -0
- package/lib/chevre/service/assetTransaction/reserve/start/factory/createReservation.d.ts +54 -0
- package/lib/chevre/service/assetTransaction/reserve/{factory.js → start/factory/createReservation.js} +3 -222
- package/lib/chevre/service/assetTransaction/reserve/start/factory/createStartParams.d.ts +22 -0
- package/lib/chevre/service/assetTransaction/reserve/start/factory/createStartParams.js +90 -0
- package/lib/chevre/service/assetTransaction/reserve/{factory → start/factory}/price.d.ts +1 -1
- package/lib/chevre/service/assetTransaction/reserve/{factory → start/factory}/price.js +1 -1
- package/lib/chevre/service/assetTransaction/reserve/start.d.ts +74 -0
- package/lib/chevre/service/assetTransaction/reserve/start.js +570 -0
- package/lib/chevre/service/assetTransaction/reserve.d.ts +6 -128
- package/lib/chevre/service/assetTransaction/reserve.js +9 -1047
- package/lib/chevre/service/offer/event/{defaultOffer.d.ts → authorize/defaultOffer.d.ts} +1 -1
- package/lib/chevre/service/offer/event/{defaultOffer.js → authorize/defaultOffer.js} +1 -1
- package/lib/chevre/service/offer/event/{factory.d.ts → authorize/factory.d.ts} +13 -20
- package/lib/chevre/service/offer/event/{factory.js → authorize/factory.js} +72 -146
- package/lib/chevre/service/offer/event/{processStartReserve4chevre.d.ts → authorize/processStartReserve4chevre.d.ts} +19 -19
- package/lib/chevre/service/offer/event/{processStartReserve4chevre.js → authorize/processStartReserve4chevre.js} +8 -13
- package/lib/chevre/service/offer/event/authorize.d.ts +1 -1
- package/lib/chevre/service/offer/event/authorize.js +104 -128
- package/lib/chevre/service/offer/event/importFromCOA/factory.d.ts +9 -0
- package/lib/chevre/service/offer/event/importFromCOA/factory.js +67 -0
- package/lib/chevre/service/offer/event/importFromCOA.js +1 -1
- package/lib/chevre/service/offer/eventServiceByCOA/authorize.js +0 -3
- package/lib/chevre/service/offer/eventServiceByCOA/factory.d.ts +3 -3
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/factory.d.ts +4 -4
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/processOrder.d.ts +16 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/processOrder.js +168 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing.d.ts +4 -5
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing.js +4 -135
- package/lib/chevre/service/order/onOrderStatusChanged.d.ts +2 -2
- package/lib/chevre/service/order/onOrderStatusChanged.js +2 -1
- package/lib/chevre/service/order.d.ts +2 -2
- package/lib/chevre/service/order.js +2 -1
- package/lib/chevre/service/transaction/moneyTransfer.d.ts +3 -2
- package/lib/chevre/service/transaction/moneyTransfer.js +1 -2
- package/lib/chevre/service/transaction/placeOrderInProgress/start/factory.d.ts +10 -0
- package/lib/chevre/service/transaction/placeOrderInProgress/start/factory.js +36 -0
- package/lib/chevre/service/transaction/placeOrderInProgress/start.d.ts +6 -1
- package/lib/chevre/service/transaction/placeOrderInProgress/start.js +26 -12
- package/lib/chevre/service/validation/validateOrder.js +1 -1
- package/lib/chevre/settings.d.ts +1 -0
- package/lib/chevre/settings.js +5 -1
- package/package.json +3 -3
- package/example/src/chevre/migrateAuthorizeEventServiceOfferResult.ts +0 -163
- package/lib/chevre/service/assetTransaction/reserve/factory.d.ts +0 -96
- package/lib/chevre/service/transaction/placeOrderInProgress/factory.d.ts +0 -2
- package/lib/chevre/service/transaction/placeOrderInProgress/factory.js +0 -29
- package/lib/chevre/service/transaction/validation.d.ts +0 -14
- package/lib/chevre/service/transaction/validation.js +0 -101
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as moment from 'moment';
|
|
3
|
+
import * as mongoose from 'mongoose';
|
|
4
|
+
|
|
5
|
+
import { chevre } from '../../../lib/index';
|
|
6
|
+
|
|
7
|
+
const project = { id: String(process.env.PROJECT_ID) };
|
|
8
|
+
|
|
9
|
+
async function main() {
|
|
10
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
11
|
+
|
|
12
|
+
const acceptedOfferRepo = await chevre.repository.AcceptedOffer.createInstance(mongoose.connection);
|
|
13
|
+
const orderRepo = await chevre.repository.Order.createInstance(mongoose.connection);
|
|
14
|
+
const taskRepo = await chevre.repository.Task.createInstance(mongoose.connection);
|
|
15
|
+
|
|
16
|
+
const cursor = orderRepo.getCursor(
|
|
17
|
+
{
|
|
18
|
+
'project.id': { $eq: project.id },
|
|
19
|
+
// orderNumber: { $eq: 'SSK9-4896645-5698154' },
|
|
20
|
+
orderDate: {
|
|
21
|
+
$lte: moment('2024-07-03T18:00:00Z')
|
|
22
|
+
.toDate(),
|
|
23
|
+
$gte: moment('2024-06-30T18:00:00Z')
|
|
24
|
+
.toDate()
|
|
25
|
+
},
|
|
26
|
+
orderStatus: { $eq: chevre.factory.orderStatus.OrderProcessing }
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
confirmationNumber: 1,
|
|
30
|
+
orderDate: 1, orderNumber: 1,
|
|
31
|
+
project: 1, typeOf: 1, orderStatus: 1
|
|
32
|
+
}
|
|
33
|
+
);
|
|
34
|
+
console.log('orders found');
|
|
35
|
+
|
|
36
|
+
let i = 0;
|
|
37
|
+
let updateCount = 0;
|
|
38
|
+
await cursor.eachAsync(async (doc) => {
|
|
39
|
+
i += 1;
|
|
40
|
+
const order: Pick<chevre.factory.order.IOrder, 'confirmationNumber' | 'orderDate' | 'orderNumber' | 'project' | 'typeOf' | 'orderStatus'> = doc.toObject();
|
|
41
|
+
if (order.orderStatus !== chevre.factory.orderStatus.OrderProcessing) {
|
|
42
|
+
console.log('nothing to do', order.orderStatus, order.orderNumber);
|
|
43
|
+
} else {
|
|
44
|
+
const { orderNumber } = order;
|
|
45
|
+
|
|
46
|
+
const itemOfferedTypeOfs = <chevre.factory.order.IItemOffered['typeOf'][]>await acceptedOfferRepo.distinctValues(
|
|
47
|
+
{ orderNumber: { $in: [orderNumber] } },
|
|
48
|
+
'acceptedOffers.itemOffered.typeOf'
|
|
49
|
+
);
|
|
50
|
+
const serialNumbers = await acceptedOfferRepo.distinctValues(
|
|
51
|
+
{ orderNumber: { $in: [orderNumber] } },
|
|
52
|
+
'acceptedOffers.serialNumber'
|
|
53
|
+
);
|
|
54
|
+
const offeredThroughIdentifier = (<chevre.factory.service.webAPI.Identifier[]>await acceptedOfferRepo.distinctValues(
|
|
55
|
+
{ orderNumber: { $in: [orderNumber] } },
|
|
56
|
+
'acceptedOffers.offeredThrough.identifier'
|
|
57
|
+
)).shift();
|
|
58
|
+
|
|
59
|
+
console.log('processing order', order, itemOfferedTypeOfs, serialNumbers, offeredThroughIdentifier);
|
|
60
|
+
await (await chevre.service.order.createService()).processOrder({
|
|
61
|
+
order: {
|
|
62
|
+
...order,
|
|
63
|
+
itemOfferedTypeOf: itemOfferedTypeOfs[0], // 1つしかない前提
|
|
64
|
+
serialNumbers,
|
|
65
|
+
offeredThroughIdentifier
|
|
66
|
+
},
|
|
67
|
+
options: { force: true }
|
|
68
|
+
})({ task: taskRepo });
|
|
69
|
+
console.log('order processed', order.orderNumber);
|
|
70
|
+
updateCount += 1;
|
|
71
|
+
console.log('updated.', order.project.id, order.orderNumber, order.orderDate, i);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
console.log(i, 'orders checked');
|
|
76
|
+
console.log(updateCount, 'orders updated');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
main()
|
|
80
|
+
.then()
|
|
81
|
+
.catch(console.error);
|
|
82
|
+
|
|
83
|
+
main()
|
|
84
|
+
.then(() => {
|
|
85
|
+
console.log('success!');
|
|
86
|
+
})
|
|
87
|
+
.catch(console.error);
|
|
@@ -1,23 +1,11 @@
|
|
|
1
1
|
// tslint:disable:no-console
|
|
2
2
|
import * as mongoose from 'mongoose';
|
|
3
|
-
import * as readline from 'readline';
|
|
4
3
|
import * as redis from 'redis';
|
|
5
4
|
|
|
6
5
|
import { chevre } from '../../../../lib/index';
|
|
7
6
|
|
|
8
7
|
const project = { id: String(process.env.PROJECT_ID) };
|
|
9
|
-
const CLIENT_ID = '
|
|
10
|
-
const paymentMethodType = 'CreditCard';
|
|
11
|
-
const paymentServiceId = '5f9a4fed4f3709000abe6415';
|
|
12
|
-
// const paymentMethodType = 'PayPay';
|
|
13
|
-
// const paymentServiceId = '60e9560176a391000b23e20b';
|
|
14
|
-
const AMOUNT: number = 1;
|
|
15
|
-
const creditCard: chevre.factory.paymentMethod.paymentCard.creditCard.IUncheckedCardRaw = {
|
|
16
|
-
cardNo: '4100000000000100',
|
|
17
|
-
expire: '2812',
|
|
18
|
-
cardPass: '123',
|
|
19
|
-
holderName: 'AA AA'
|
|
20
|
-
};
|
|
8
|
+
const CLIENT_ID = 'xxx';
|
|
21
9
|
|
|
22
10
|
// tslint:disable-next-line:max-func-body-length
|
|
23
11
|
async function main() {
|
|
@@ -31,143 +19,29 @@ async function main() {
|
|
|
31
19
|
});
|
|
32
20
|
await client.connect();
|
|
33
21
|
|
|
34
|
-
const transaction = await (await chevre.service.transaction.createService()).placeOrderInProgress.start(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
22
|
+
const transaction = await (await chevre.service.transaction.createService()).placeOrderInProgress.start(
|
|
23
|
+
{
|
|
24
|
+
project: { id: project.id, typeOf: chevre.factory.organizationType.Project },
|
|
25
|
+
agent: { id: CLIENT_ID, typeOf: chevre.factory.creativeWorkType.WebApplication },
|
|
26
|
+
object: {
|
|
27
|
+
clientUser: <any>{ client_id: CLIENT_ID }
|
|
28
|
+
},
|
|
29
|
+
seller: { id: '59d20831e53ebc2b4e774466' }
|
|
39
30
|
},
|
|
40
|
-
|
|
41
|
-
|
|
31
|
+
{
|
|
32
|
+
lockPassport: false
|
|
33
|
+
}
|
|
34
|
+
)({
|
|
42
35
|
member: await chevre.repository.Member.createInstance(mongoose.connection),
|
|
36
|
+
passport: await chevre.repository.Passport.createInstance(
|
|
37
|
+
client,
|
|
38
|
+
{ secret: 'xxx' }
|
|
39
|
+
),
|
|
43
40
|
projectMakesOffer: await chevre.repository.ProjectMakesOffer.createInstance(mongoose.connection),
|
|
44
41
|
seller: await chevre.repository.Seller.createInstance(mongoose.connection),
|
|
45
42
|
transaction: await chevre.repository.Transaction.createInstance(mongoose.connection)
|
|
46
43
|
});
|
|
47
44
|
console.log('transaction started', transaction);
|
|
48
|
-
|
|
49
|
-
const publishPaymentUrlResult = await (await chevre.service.payment.any.createService()).publishPaymentUrl({
|
|
50
|
-
project: { id: project.id },
|
|
51
|
-
agent: { id: CLIENT_ID },
|
|
52
|
-
object: {
|
|
53
|
-
amount: AMOUNT,
|
|
54
|
-
paymentMethod: paymentMethodType,
|
|
55
|
-
issuedThrough: { id: paymentServiceId },
|
|
56
|
-
method: '1',
|
|
57
|
-
creditCard: {
|
|
58
|
-
...creditCard,
|
|
59
|
-
retUrl: String(process.env.SECURE_TRAN_RET_URL)
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
purpose: { id: transaction.id, typeOf: chevre.factory.transactionType.PlaceOrder },
|
|
63
|
-
paymentServiceType: chevre.factory.service.paymentService.PaymentServiceType.CreditCard,
|
|
64
|
-
location: {
|
|
65
|
-
typeOf: chevre.factory.creativeWorkType.WebApplication,
|
|
66
|
-
id: CLIENT_ID
|
|
67
|
-
}
|
|
68
|
-
})({
|
|
69
|
-
action: await chevre.repository.Action.createInstance(mongoose.connection),
|
|
70
|
-
assetTransaction: await chevre.repository.AssetTransaction.createInstance(mongoose.connection),
|
|
71
|
-
paymentAccepted: await chevre.repository.SellerPaymentAccepted.createInstance(mongoose.connection),
|
|
72
|
-
paymentService: await chevre.repository.PaymentService.createInstance(mongoose.connection),
|
|
73
|
-
paymentServiceProvider: await chevre.repository.PaymentServiceProvider.createInstance(mongoose.connection),
|
|
74
|
-
transactionNumber: await chevre.repository.TransactionNumber.createInstance(client),
|
|
75
|
-
transaction: await chevre.repository.Transaction.createInstance(mongoose.connection)
|
|
76
|
-
});
|
|
77
|
-
console.log(publishPaymentUrlResult);
|
|
78
|
-
|
|
79
|
-
// wait callback...
|
|
80
|
-
// tslint:disable-next-line:max-func-body-length
|
|
81
|
-
await new Promise<void>((resolve, reject) => {
|
|
82
|
-
const rl = readline.createInterface({
|
|
83
|
-
input: process.stdin,
|
|
84
|
-
output: process.stdout
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
// tslint:disable-next-line:max-func-body-length
|
|
88
|
-
rl.question('callback received?:\n', async () => {
|
|
89
|
-
try {
|
|
90
|
-
await new Promise<void>(async (resolve2, reject2) => {
|
|
91
|
-
const rl2 = readline.createInterface({
|
|
92
|
-
input: process.stdin,
|
|
93
|
-
output: process.stdout
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
rl2.question('VOID or AUTH?:\n', async (jobCd) => {
|
|
97
|
-
if (jobCd === 'AUTH') {
|
|
98
|
-
const authorizeResult = await (await chevre.service.payment.any.createService()).authorize({
|
|
99
|
-
project: { id: project.id },
|
|
100
|
-
agent: { id: CLIENT_ID },
|
|
101
|
-
object: {
|
|
102
|
-
amount: AMOUNT,
|
|
103
|
-
paymentMethodId: publishPaymentUrlResult.paymentMethodId,
|
|
104
|
-
paymentMethod: paymentMethodType,
|
|
105
|
-
issuedThrough: { id: paymentServiceId },
|
|
106
|
-
method: '1',
|
|
107
|
-
creditCard
|
|
108
|
-
},
|
|
109
|
-
purpose: { id: transaction.id, typeOf: chevre.factory.transactionType.PlaceOrder },
|
|
110
|
-
paymentServiceType: chevre.factory.service.paymentService.PaymentServiceType.CreditCard,
|
|
111
|
-
location: {
|
|
112
|
-
typeOf: chevre.factory.creativeWorkType.WebApplication,
|
|
113
|
-
id: CLIENT_ID
|
|
114
|
-
},
|
|
115
|
-
options: {
|
|
116
|
-
useCancelPayTransactionOnFailed: false,
|
|
117
|
-
useCheckByIdentifierIfNotYet: false,
|
|
118
|
-
useUnlockTransactionProcess: false
|
|
119
|
-
}
|
|
120
|
-
})({
|
|
121
|
-
accountingReport: await chevre.repository.AccountingReport.createInstance(mongoose.connection),
|
|
122
|
-
action: await chevre.repository.Action.createInstance(mongoose.connection),
|
|
123
|
-
assetTransaction: await chevre.repository.AssetTransaction.createInstance(mongoose.connection),
|
|
124
|
-
authorization: await chevre.repository.Code.createInstance(mongoose.connection),
|
|
125
|
-
confirmationNumber: await chevre.repository.ConfirmationNumber.createInstance(client),
|
|
126
|
-
event: await chevre.repository.Event.createInstance(mongoose.connection),
|
|
127
|
-
paymentAccepted: await chevre.repository.SellerPaymentAccepted.createInstance(mongoose.connection),
|
|
128
|
-
paymentService: await chevre.repository.PaymentService.createInstance(mongoose.connection),
|
|
129
|
-
paymentServiceProvider: await chevre.repository.PaymentServiceProvider.createInstance(mongoose.connection),
|
|
130
|
-
product: await chevre.repository.Product.createInstance(mongoose.connection),
|
|
131
|
-
task: await chevre.repository.Task.createInstance(mongoose.connection),
|
|
132
|
-
ticket: await chevre.repository.Ticket.createInstance(mongoose.connection),
|
|
133
|
-
transactionNumber: await chevre.repository.TransactionNumber.createInstance(client),
|
|
134
|
-
transactionProcess:
|
|
135
|
-
await chevre.repository.TransactionProcess.createInstance(client, { lockExpiresInSeconds: 120 }),
|
|
136
|
-
transaction: await chevre.repository.Transaction.createInstance(mongoose.connection)
|
|
137
|
-
});
|
|
138
|
-
console.log('payment authorized.', authorizeResult.id);
|
|
139
|
-
} else if (jobCd === 'VOID') {
|
|
140
|
-
await (await chevre.service.payment.any.createService()).invalidatePaymentUrl({
|
|
141
|
-
project: { id: project.id, typeOf: chevre.factory.organizationType.Project },
|
|
142
|
-
purpose: { id: transaction.id, typeOf: chevre.factory.transactionType.PlaceOrder }
|
|
143
|
-
})({
|
|
144
|
-
accountingReport: await chevre.repository.AccountingReport.createInstance(mongoose.connection),
|
|
145
|
-
action: await chevre.repository.Action.createInstance(mongoose.connection),
|
|
146
|
-
assetTransaction: await chevre.repository.AssetTransaction.createInstance(mongoose.connection),
|
|
147
|
-
paymentAccepted: await chevre.repository.SellerPaymentAccepted.createInstance(mongoose.connection),
|
|
148
|
-
paymentService: await chevre.repository.PaymentService.createInstance(mongoose.connection),
|
|
149
|
-
paymentServiceProvider: await chevre.repository.PaymentServiceProvider.createInstance(mongoose.connection),
|
|
150
|
-
task: await chevre.repository.Task.createInstance(mongoose.connection),
|
|
151
|
-
transaction: await chevre.repository.Transaction.createInstance(mongoose.connection)
|
|
152
|
-
});
|
|
153
|
-
console.log('payment voided.');
|
|
154
|
-
} else {
|
|
155
|
-
reject2(`jobCd ${jobCd} not implemented`);
|
|
156
|
-
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// rl.close();
|
|
161
|
-
resolve2();
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
resolve();
|
|
166
|
-
} catch (error) {
|
|
167
|
-
reject(error);
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
45
|
}
|
|
172
46
|
|
|
173
47
|
main()
|
|
@@ -3,13 +3,10 @@ export type IPassportValidator = (params: {
|
|
|
3
3
|
passport: factory.waiter.passport.IPassport;
|
|
4
4
|
}) => boolean;
|
|
5
5
|
export declare namespace moneyTransfer {
|
|
6
|
-
type IStartParams = factory.transaction.moneyTransfer.IStartParamsWithoutDetail & {
|
|
7
|
-
passportValidator?: IPassportValidator;
|
|
8
|
-
};
|
|
6
|
+
type IStartParams = factory.transaction.moneyTransfer.IStartParamsWithoutDetail & {};
|
|
9
7
|
}
|
|
10
8
|
export declare namespace placeOrder {
|
|
11
9
|
type IStartParams = factory.transaction.placeOrder.IStartParamsWithoutDetail & {
|
|
12
|
-
passportValidator?: IPassportValidator;
|
|
13
10
|
broker?: factory.order.IBroker;
|
|
14
11
|
};
|
|
15
12
|
type IOrderURLGenerator = (order: factory.transaction.placeOrder.IOrderAsResult) => string;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as jwt from 'jsonwebtoken';
|
|
2
|
+
import type { RedisClientType } from 'redis';
|
|
3
|
+
import * as factory from '../factory';
|
|
4
|
+
import { IPassportValidator } from '../factory/transaction';
|
|
5
|
+
export type IVerifiedPassport = factory.waiter.passport.IPassport & {
|
|
6
|
+
/**
|
|
7
|
+
* 許可証識別子(2024-07-06~)
|
|
8
|
+
*/
|
|
9
|
+
identifier: string;
|
|
10
|
+
};
|
|
11
|
+
type ILockKey = IVerifiedPassport;
|
|
12
|
+
interface IOptions {
|
|
13
|
+
secret: string;
|
|
14
|
+
passportValidator?: IPassportValidator;
|
|
15
|
+
}
|
|
16
|
+
type IStartParams = (factory.transaction.placeOrder.IStartParamsWithoutDetail | factory.transaction.moneyTransfer.IStartParamsWithoutDetail) & {};
|
|
17
|
+
/**
|
|
18
|
+
* 取引許可証リポジトリ
|
|
19
|
+
*/
|
|
20
|
+
export declare class PassportRepo {
|
|
21
|
+
private readonly redisClient;
|
|
22
|
+
private readonly options;
|
|
23
|
+
constructor(redisClient: RedisClientType, options: IOptions);
|
|
24
|
+
static CREATE_VERIFIED_PASSPORT(params: string | jwt.JwtPayload | undefined): IVerifiedPassport;
|
|
25
|
+
static CREATE_REDIS_KEY(params: ILockKey): string;
|
|
26
|
+
lock(params: ILockKey): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* 許可証トークンがあれば検証する
|
|
29
|
+
*/
|
|
30
|
+
validatePassportTokenIfExist(params: Pick<IStartParams, 'object'>): Promise<{
|
|
31
|
+
passport?: IVerifiedPassport;
|
|
32
|
+
customerType?: string;
|
|
33
|
+
}>;
|
|
34
|
+
/**
|
|
35
|
+
* 暗号化された許可証を検証する
|
|
36
|
+
*/
|
|
37
|
+
private verify;
|
|
38
|
+
}
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.PassportRepo = void 0;
|
|
13
|
+
const createDebug = require("debug");
|
|
14
|
+
const jwt = require("jsonwebtoken");
|
|
15
|
+
const moment = require("moment");
|
|
16
|
+
const factory = require("../factory");
|
|
17
|
+
const debug = createDebug('chevre-domain:repo:passport');
|
|
18
|
+
/**
|
|
19
|
+
* 取引許可証リポジトリ
|
|
20
|
+
*/
|
|
21
|
+
class PassportRepo {
|
|
22
|
+
constructor(redisClient, options) {
|
|
23
|
+
this.redisClient = redisClient;
|
|
24
|
+
this.options = options;
|
|
25
|
+
}
|
|
26
|
+
static CREATE_VERIFIED_PASSPORT(params) {
|
|
27
|
+
var _a;
|
|
28
|
+
if (typeof params === 'string' || params === undefined) {
|
|
29
|
+
throw new factory.errors.Argument('decoded must be an object');
|
|
30
|
+
}
|
|
31
|
+
if (typeof params.scope !== 'string' || params.scope === '') {
|
|
32
|
+
throw new factory.errors.ArgumentNull('scope');
|
|
33
|
+
}
|
|
34
|
+
if (typeof params.iat !== 'number') {
|
|
35
|
+
throw new factory.errors.Argument('iat', 'iat must be number');
|
|
36
|
+
}
|
|
37
|
+
if (typeof params.exp !== 'number') {
|
|
38
|
+
throw new factory.errors.Argument('exp', 'exp must be number');
|
|
39
|
+
}
|
|
40
|
+
if (typeof params.iss !== 'string' || params.iss === '') {
|
|
41
|
+
throw new factory.errors.ArgumentNull('iss');
|
|
42
|
+
}
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
44
|
+
if (typeof ((_a = params.issueUnit) === null || _a === void 0 ? void 0 : _a.identifier) !== 'string' || params.issueUnit.identifier === '') {
|
|
45
|
+
throw new factory.errors.Argument('issueUnit.identifier', 'issueUnit.identifier must be string');
|
|
46
|
+
}
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
48
|
+
if (typeof params.issueUnit.numberOfRequests !== 'number') {
|
|
49
|
+
throw new factory.errors.Argument('issueUnit.numberOfRequests', 'issueUnit.numberOfRequests must be number');
|
|
50
|
+
}
|
|
51
|
+
const identifier = `${params.issueUnit.identifier}:${params.issueUnit.numberOfRequests}`;
|
|
52
|
+
return Object.assign({ identifier, scope: params.scope, iat: params.iat, exp: params.exp, iss: params.iss,
|
|
53
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
54
|
+
project: params.project,
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
56
|
+
issueUnit: params.issueUnit }, (Array.isArray(params.aud)) ? { aud: params.aud } : undefined);
|
|
57
|
+
}
|
|
58
|
+
static CREATE_REDIS_KEY(params) {
|
|
59
|
+
return `chvr:lockPassport:${params.identifier}`;
|
|
60
|
+
}
|
|
61
|
+
lock(params) {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
const now = moment();
|
|
64
|
+
const passportExpires = moment.unix(params.exp);
|
|
65
|
+
const key = PassportRepo.CREATE_REDIS_KEY(params);
|
|
66
|
+
const ttl = (passportExpires.isAfter(now))
|
|
67
|
+
? moment.unix(params.exp)
|
|
68
|
+
.diff(moment(), 'seconds')
|
|
69
|
+
: 1;
|
|
70
|
+
const results = yield this.redisClient.multi()
|
|
71
|
+
.setNX(key, '1')
|
|
72
|
+
.expire(key, ttl)
|
|
73
|
+
.exec();
|
|
74
|
+
debug('locked,', params.issueUnit.identifier, now, passportExpires, ttl, results);
|
|
75
|
+
if (Array.isArray(results) && (results[0] === 1 || results[0] === true)) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
throw new factory.errors.AlreadyInUse('passport', [], 'passport already in use');
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* 許可証トークンがあれば検証する
|
|
85
|
+
*/
|
|
86
|
+
validatePassportTokenIfExist(params) {
|
|
87
|
+
var _a, _b;
|
|
88
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
+
let passport;
|
|
90
|
+
let customerType;
|
|
91
|
+
if (typeof ((_b = (_a = params.object) === null || _a === void 0 ? void 0 : _a.passport) === null || _b === void 0 ? void 0 : _b.token) === 'string') {
|
|
92
|
+
try {
|
|
93
|
+
passport = yield this.verify({
|
|
94
|
+
token: params.object.passport.token
|
|
95
|
+
// secret: this.options.secret
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
throw new factory.errors.Argument('Passport Token', `Invalid token: ${error.message}`);
|
|
100
|
+
}
|
|
101
|
+
// 許可証バリデーション
|
|
102
|
+
if (typeof this.options.passportValidator === 'function') {
|
|
103
|
+
if (!this.options.passportValidator({ passport })) {
|
|
104
|
+
throw new factory.errors.Argument('Passport Token', 'passportValidator requirement not satisfied');
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
// カスタマータイプ決定(2023-11-20~)
|
|
108
|
+
// スコープのフォーマットは、Transaction:${TransactionType}:${sellerId}:${customerType}
|
|
109
|
+
const splittedScope = passport.scope.split(':');
|
|
110
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
111
|
+
customerType = splittedScope[3];
|
|
112
|
+
}
|
|
113
|
+
return Object.assign(Object.assign({}, (typeof customerType === 'string') ? { customerType } : undefined), (passport !== undefined) ? { passport } : undefined);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* 暗号化された許可証を検証する
|
|
118
|
+
*/
|
|
119
|
+
verify(params) {
|
|
120
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
121
|
+
return new Promise((resolve, reject) => {
|
|
122
|
+
jwt.verify(params.token, this.options.secret, (err, decoded) => {
|
|
123
|
+
if (err instanceof Error) {
|
|
124
|
+
reject(err);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
resolve(PassportRepo.CREATE_VERIFIED_PASSPORT(decoded));
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
exports.PassportRepo = PassportRepo;
|
|
@@ -75,6 +75,7 @@ export declare class MongoRepository {
|
|
|
75
75
|
};
|
|
76
76
|
}): Promise<{
|
|
77
77
|
id: string;
|
|
78
|
+
status: factory.taskStatus;
|
|
78
79
|
} | undefined>;
|
|
79
80
|
/**
|
|
80
81
|
* タスク識別子から冪等作成する
|
|
@@ -127,6 +128,14 @@ export declare class MongoRepository {
|
|
|
127
128
|
retry(params: {
|
|
128
129
|
intervalInMinutes: number;
|
|
129
130
|
}): Promise<UpdateWriteOpResult>;
|
|
131
|
+
/**
|
|
132
|
+
* 実行中止済タスクを強制的にリトライ
|
|
133
|
+
* 中止済タスクでなければ何もしない
|
|
134
|
+
*/
|
|
135
|
+
retryForciblyIfAborted(params: {
|
|
136
|
+
id: string;
|
|
137
|
+
remainingNumberOfTries: number;
|
|
138
|
+
}): Promise<import("mongodb").UpdateResult>;
|
|
130
139
|
abortOne(params: {
|
|
131
140
|
intervalInMinutes: number;
|
|
132
141
|
}): Promise<factory.task.ITask<factory.taskName> | null>;
|
package/lib/chevre/repo/task.js
CHANGED
|
@@ -201,12 +201,13 @@ class MongoRepository {
|
|
|
201
201
|
'project.id': { $eq: params.project.id },
|
|
202
202
|
name: { $eq: params.name },
|
|
203
203
|
identifier: { $exists: true, $eq: params.identifier }
|
|
204
|
-
}, { _id: 1 })
|
|
204
|
+
}, { _id: 1, status: 1 })
|
|
205
205
|
.exec();
|
|
206
206
|
if (doc === null) {
|
|
207
207
|
return;
|
|
208
208
|
}
|
|
209
|
-
|
|
209
|
+
const { id, status } = doc.toObject();
|
|
210
|
+
return { id, status };
|
|
210
211
|
});
|
|
211
212
|
}
|
|
212
213
|
/**
|
|
@@ -514,6 +515,26 @@ class MongoRepository {
|
|
|
514
515
|
.exec();
|
|
515
516
|
});
|
|
516
517
|
}
|
|
518
|
+
/**
|
|
519
|
+
* 実行中止済タスクを強制的にリトライ
|
|
520
|
+
* 中止済タスクでなければ何もしない
|
|
521
|
+
*/
|
|
522
|
+
retryForciblyIfAborted(params) {
|
|
523
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
524
|
+
return this.taskModel.updateOne({
|
|
525
|
+
_id: { $eq: params.id },
|
|
526
|
+
status: { $eq: factory.taskStatus.Aborted }
|
|
527
|
+
}, {
|
|
528
|
+
$set: {
|
|
529
|
+
status: factory.taskStatus.Ready
|
|
530
|
+
},
|
|
531
|
+
$inc: {
|
|
532
|
+
remainingNumberOfTries: params.remainingNumberOfTries
|
|
533
|
+
}
|
|
534
|
+
})
|
|
535
|
+
.exec();
|
|
536
|
+
});
|
|
537
|
+
}
|
|
517
538
|
abortOne(params) {
|
|
518
539
|
return __awaiter(this, void 0, void 0, function* () {
|
|
519
540
|
const lastTriedAtShoudBeLessThan = moment()
|
|
@@ -31,6 +31,7 @@ import type { MongoRepository as OfferItemConditionRepo } from './repo/offerItem
|
|
|
31
31
|
import type { MongoRepository as OrderRepo } from './repo/order';
|
|
32
32
|
import type { MongoRepository as OrderInTransactionRepo } from './repo/orderInTransaction';
|
|
33
33
|
import type { MongoRepository as OwnershipInfoRepo } from './repo/ownershipInfo';
|
|
34
|
+
import type { PassportRepo } from './repo/passport';
|
|
34
35
|
import type { MongoRepository as PaymentServiceRepo } from './repo/paymentService';
|
|
35
36
|
import type { MongoRepository as PaymentServiceProviderRepo } from './repo/paymentServiceProvider';
|
|
36
37
|
import type { MongoRepository as PermitRepo } from './repo/permit';
|
|
@@ -193,6 +194,10 @@ export type OwnershipInfo = OwnershipInfoRepo;
|
|
|
193
194
|
export declare namespace OwnershipInfo {
|
|
194
195
|
function createInstance(...params: ConstructorParameters<typeof OwnershipInfoRepo>): Promise<OwnershipInfoRepo>;
|
|
195
196
|
}
|
|
197
|
+
export type Passport = PassportRepo;
|
|
198
|
+
export declare namespace Passport {
|
|
199
|
+
function createInstance(...params: ConstructorParameters<typeof PassportRepo>): Promise<PassportRepo>;
|
|
200
|
+
}
|
|
196
201
|
export type PaymentService = PaymentServiceRepo;
|
|
197
202
|
export declare namespace PaymentService {
|
|
198
203
|
function createInstance(...params: ConstructorParameters<typeof PaymentServiceRepo>): Promise<PaymentServiceRepo>;
|
package/lib/chevre/repository.js
CHANGED
|
@@ -9,8 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
13
|
-
exports.rateLimit = exports.Trip = exports.TransactionProcess = exports.TransactionNumber = exports.Transaction = exports.Ticket = exports.Telemetry = exports.Task = exports.StockHolder = void 0;
|
|
12
|
+
exports.ServiceOutput = exports.SellerPaymentAccepted = exports.Seller = exports.Role = exports.Reservation = exports.ProjectMakesOffer = exports.Project = exports.ProductOffer = exports.ProductModel = exports.Product = exports.PriceSpecification = exports.place = exports.Permit = exports.Person = exports.paymentMethod = exports.PaymentServiceProvider = exports.PaymentService = exports.Passport = exports.OwnershipInfo = exports.OrderNumber = exports.OrderInTransaction = exports.Order = exports.Offer = exports.OfferItemCondition = exports.OfferCatalogItem = exports.OfferCatalog = exports.Note = exports.Message = exports.MerchantReturnPolicy = exports.Member = exports.Event = exports.EmailMessage = exports.CustomerType = exports.Customer = exports.CreativeWork = exports.ConfirmationNumber = exports.Comment = exports.Code = exports.CategoryCode = exports.AssetTransaction = exports.Aggregation = exports.AggregateReservation = exports.AggregateOffer = exports.AdditionalProperty = exports.Action = exports.AccountTransaction = exports.AccountTitle = exports.AccountingReport = exports.Account = exports.AcceptedOffer = void 0;
|
|
13
|
+
exports.rateLimit = exports.Trip = exports.TransactionProcess = exports.TransactionNumber = exports.Transaction = exports.Ticket = exports.Telemetry = exports.Task = exports.StockHolder = exports.ServiceOutputIdentifier = void 0;
|
|
14
14
|
var AcceptedOffer;
|
|
15
15
|
(function (AcceptedOffer) {
|
|
16
16
|
let repo;
|
|
@@ -427,6 +427,19 @@ var OwnershipInfo;
|
|
|
427
427
|
}
|
|
428
428
|
OwnershipInfo.createInstance = createInstance;
|
|
429
429
|
})(OwnershipInfo = exports.OwnershipInfo || (exports.OwnershipInfo = {}));
|
|
430
|
+
var Passport;
|
|
431
|
+
(function (Passport) {
|
|
432
|
+
let repo;
|
|
433
|
+
function createInstance(...params) {
|
|
434
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
435
|
+
if (repo === undefined) {
|
|
436
|
+
repo = (yield Promise.resolve().then(() => require('./repo/passport'))).PassportRepo;
|
|
437
|
+
}
|
|
438
|
+
return new repo(...params);
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
Passport.createInstance = createInstance;
|
|
442
|
+
})(Passport = exports.Passport || (exports.Passport = {}));
|
|
430
443
|
var PaymentService;
|
|
431
444
|
(function (PaymentService) {
|
|
432
445
|
let repo;
|
|
@@ -25,7 +25,6 @@ function start(params) {
|
|
|
25
25
|
});
|
|
26
26
|
// 取引ファクトリーで新しい進行中取引オブジェクトを作成
|
|
27
27
|
const startParams = Object.assign({ project: { typeOf: params.project.typeOf, id: params.project.id }, typeOf: factory.account.transactionType.Deposit, agent: params.agent, recipient: params.recipient, object: {
|
|
28
|
-
// clientUser: params.object.clientUser,
|
|
29
28
|
amount: params.object.amount,
|
|
30
29
|
toLocation: {
|
|
31
30
|
typeOf: account.typeOf,
|
|
@@ -43,7 +43,6 @@ function start(params) {
|
|
|
43
43
|
}
|
|
44
44
|
// 取引ファクトリーで新しい進行中取引オブジェクトを作成
|
|
45
45
|
const startParams = Object.assign({ project: { typeOf: params.project.typeOf, id: params.project.id }, typeOf: factory.account.transactionType.Transfer, agent: params.agent, recipient: params.recipient, object: {
|
|
46
|
-
// clientUser: params.object.clientUser,
|
|
47
46
|
amount: params.object.amount,
|
|
48
47
|
fromLocation: {
|
|
49
48
|
typeOf: fromAccount.typeOf,
|
|
@@ -32,7 +32,6 @@ function start(params) {
|
|
|
32
32
|
}
|
|
33
33
|
// 取引ファクトリーで新しい進行中取引オブジェクトを作成
|
|
34
34
|
const startParams = Object.assign({ project: { typeOf: params.project.typeOf, id: params.project.id }, typeOf: factory.account.transactionType.Withdraw, agent: params.agent, recipient: params.recipient, object: {
|
|
35
|
-
// clientUser: params.object.clientUser,
|
|
36
35
|
amount: params.object.amount,
|
|
37
36
|
fromLocation: {
|
|
38
37
|
typeOf: fromAccount.typeOf,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { MongoRepository as ActionRepo } from '../../../repo/action';
|
|
2
|
+
import type { MongoRepository as AssetTransactionRepo } from '../../../repo/assetTransaction';
|
|
3
|
+
import type { RedisRepository as OfferRateLimitRepo } from '../../../repo/rateLimit/offer';
|
|
4
|
+
import type { MongoRepository as ReservationRepo } from '../../../repo/reservation';
|
|
5
|
+
import type { StockHolderRepository as StockHolderRepo } from '../../../repo/stockHolder';
|
|
6
|
+
import type { MongoRepository as TaskRepo } from '../../../repo/task';
|
|
7
|
+
type ICancelOperation<T> = (repos: {
|
|
8
|
+
action: ActionRepo;
|
|
9
|
+
stockHolder: StockHolderRepo;
|
|
10
|
+
offerRateLimit: OfferRateLimitRepo;
|
|
11
|
+
reservation: ReservationRepo;
|
|
12
|
+
task: TaskRepo;
|
|
13
|
+
assetTransaction: AssetTransactionRepo;
|
|
14
|
+
}) => Promise<T>;
|
|
15
|
+
/**
|
|
16
|
+
* 取引中止
|
|
17
|
+
*/
|
|
18
|
+
declare function cancel(params: {
|
|
19
|
+
id?: string;
|
|
20
|
+
transactionNumber?: string;
|
|
21
|
+
}): ICancelOperation<void>;
|
|
22
|
+
export { cancel };
|