@chevre/domain 21.37.0-alpha.14 → 21.37.0-alpha.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/example/src/chevre/transaction/processPlaceOrder.ts +14 -143
- package/lib/chevre/factory/reservedAgentIdentifireNames.js +2 -1
- package/lib/chevre/repo/passport.d.ts +19 -0
- package/lib/chevre/repo/passport.js +50 -0
- 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/offer/event/authorize.js +0 -3
- package/lib/chevre/service/offer/eventServiceByCOA/authorize.js +0 -3
- 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 +27 -3
- package/lib/chevre/service/transaction/validation.d.ts +5 -8
- package/lib/chevre/service/transaction/validation.js +3 -3
- package/package.json +1 -1
- package/lib/chevre/service/transaction/placeOrderInProgress/factory.d.ts +0 -2
- package/lib/chevre/service/transaction/placeOrderInProgress/factory.js +0 -29
|
@@ -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,26 @@ 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(client),
|
|
43
37
|
projectMakesOffer: await chevre.repository.ProjectMakesOffer.createInstance(mongoose.connection),
|
|
44
38
|
seller: await chevre.repository.Seller.createInstance(mongoose.connection),
|
|
45
39
|
transaction: await chevre.repository.Transaction.createInstance(mongoose.connection)
|
|
46
40
|
});
|
|
47
41
|
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
42
|
}
|
|
172
43
|
|
|
173
44
|
main()
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { RedisClientType } from 'redis';
|
|
2
|
+
import * as factory from '../factory';
|
|
3
|
+
export type IVerifiedPassport = factory.waiter.passport.IPassport & {
|
|
4
|
+
/**
|
|
5
|
+
* 許可証識別子(2024-07-06~)
|
|
6
|
+
*/
|
|
7
|
+
identifier: string;
|
|
8
|
+
};
|
|
9
|
+
type ILockKey = IVerifiedPassport;
|
|
10
|
+
/**
|
|
11
|
+
* 取引許可証リポジトリ
|
|
12
|
+
*/
|
|
13
|
+
export declare class PassportRepo {
|
|
14
|
+
private readonly redisClient;
|
|
15
|
+
constructor(redisClient: RedisClientType);
|
|
16
|
+
static CREATE_REDIS_KEY(params: ILockKey): string;
|
|
17
|
+
lock(params: ILockKey): Promise<string>;
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
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 moment = require("moment");
|
|
15
|
+
const factory = require("../factory");
|
|
16
|
+
const debug = createDebug('chevre-domain:repo:transactionPassport');
|
|
17
|
+
/**
|
|
18
|
+
* 取引許可証リポジトリ
|
|
19
|
+
*/
|
|
20
|
+
class PassportRepo {
|
|
21
|
+
constructor(redisClient) {
|
|
22
|
+
this.redisClient = redisClient;
|
|
23
|
+
}
|
|
24
|
+
static CREATE_REDIS_KEY(params) {
|
|
25
|
+
return `chvr:lockPassport:${params.identifier}`;
|
|
26
|
+
}
|
|
27
|
+
lock(params) {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
const now = moment();
|
|
30
|
+
const passportExpires = moment.unix(params.exp);
|
|
31
|
+
const key = PassportRepo.CREATE_REDIS_KEY(params);
|
|
32
|
+
const ttl = (passportExpires.isAfter(now))
|
|
33
|
+
? moment.unix(params.exp)
|
|
34
|
+
.diff(moment(), 'seconds')
|
|
35
|
+
: 1;
|
|
36
|
+
const results = yield this.redisClient.multi()
|
|
37
|
+
.setNX(key, '1')
|
|
38
|
+
.expire(key, ttl)
|
|
39
|
+
.exec();
|
|
40
|
+
debug('locked,', params.issueUnit.identifier, now, passportExpires, ttl, results);
|
|
41
|
+
if (Array.isArray(results) && (results[0] === 1 || results[0] === true)) {
|
|
42
|
+
return key;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
throw new factory.errors.AlreadyInUse('passport', [], 'passport already in use');
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.PassportRepo = PassportRepo;
|
|
@@ -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,
|
|
@@ -82,9 +82,6 @@ function validateCreateRequest(params) {
|
|
|
82
82
|
throw new factory.errors.Forbidden('Transaction not yours');
|
|
83
83
|
}
|
|
84
84
|
// クライアント検証(2024-02-07~)
|
|
85
|
-
// if (transaction.object.clientUser?.client_id !== params.store.id) {
|
|
86
|
-
// throw new factory.errors.Forbidden('client not match that of the transaction');
|
|
87
|
-
// }
|
|
88
85
|
const instrumentId = (_a = transaction.instrument) === null || _a === void 0 ? void 0 : _a.id;
|
|
89
86
|
if (typeof instrumentId === 'string' && instrumentId !== params.store.id) {
|
|
90
87
|
throw new factory.errors.Forbidden('client not match that of the transaction');
|
|
@@ -31,9 +31,6 @@ function authorize(params) {
|
|
|
31
31
|
throw new factory.errors.Forbidden('Transaction not yours');
|
|
32
32
|
}
|
|
33
33
|
// クライアント検証(2024-02-07~)
|
|
34
|
-
// if (transaction.object.clientUser?.client_id !== params.store.id) {
|
|
35
|
-
// throw new factory.errors.Forbidden('client not match that of the transaction');
|
|
36
|
-
// }
|
|
37
34
|
const instrumentId = (_a = transaction.instrument) === null || _a === void 0 ? void 0 : _a.id;
|
|
38
35
|
if (typeof instrumentId === 'string' && instrumentId !== params.store.id) {
|
|
39
36
|
throw new factory.errors.Forbidden('client not match that of the transaction');
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as factory from '../../../../factory';
|
|
2
|
+
declare const AGENT_IDENTIFIER_NAME_PASSPORT = "passport";
|
|
3
|
+
type IVerifiedPassport = factory.waiter.passport.IPassport & {
|
|
4
|
+
/**
|
|
5
|
+
* 許可証識別子(2024-07-06~)
|
|
6
|
+
*/
|
|
7
|
+
identifier: string;
|
|
8
|
+
};
|
|
9
|
+
declare function createStartParams(params: factory.transaction.placeOrder.IStartParamsWithoutDetail, expiresInSeconds: number, passport: IVerifiedPassport | undefined, seller: Pick<factory.seller.ISeller, 'id' | 'name' | 'typeOf' | 'project' | 'additionalProperty'>, broker?: factory.order.IBroker, customerType?: string, memeberOfPayload?: factory.transaction.placeOrder.IMemberOfPayload): factory.transaction.placeOrder.IStartParams;
|
|
10
|
+
export { AGENT_IDENTIFIER_NAME_PASSPORT, createStartParams };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createStartParams = exports.AGENT_IDENTIFIER_NAME_PASSPORT = void 0;
|
|
4
|
+
const factory = require("../../../../factory");
|
|
5
|
+
const AGENT_IDENTIFIER_NAME_PASSPORT = 'passport';
|
|
6
|
+
exports.AGENT_IDENTIFIER_NAME_PASSPORT = AGENT_IDENTIFIER_NAME_PASSPORT;
|
|
7
|
+
function createStartParams(params, expiresInSeconds, passport, seller, broker, customerType, memeberOfPayload) {
|
|
8
|
+
var _a, _b, _c, _d;
|
|
9
|
+
let clientUser;
|
|
10
|
+
let instrument;
|
|
11
|
+
if (typeof ((_a = params.object.clientUser) === null || _a === void 0 ? void 0 : _a.client_id) === 'string') {
|
|
12
|
+
const { sub, token_use, iss, exp, iat, version, jti, client_id, username, aud, typ } = params.object.clientUser;
|
|
13
|
+
clientUser = { sub, token_use, iss, exp, iat, version, jti, client_id, username, aud, typ };
|
|
14
|
+
instrument = { id: client_id, typeOf: factory.creativeWorkType.WebApplication };
|
|
15
|
+
}
|
|
16
|
+
const transactionObject = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (typeof (passport === null || passport === void 0 ? void 0 : passport.scope) === 'string') ? { passport } : undefined), (typeof (clientUser === null || clientUser === void 0 ? void 0 : clientUser.client_id) === 'string') ? { clientUser } : undefined), (typeof ((_b = params.object) === null || _b === void 0 ? void 0 : _b.name) === 'string') ? { name: (_c = params.object) === null || _c === void 0 ? void 0 : _c.name } : undefined), (typeof (broker === null || broker === void 0 ? void 0 : broker.typeOf) === 'string') ? { broker: broker } : undefined), (typeof ((_d = params.object.customer) === null || _d === void 0 ? void 0 : _d.typeOf) === 'string') ? { customer: params.object.customer } : undefined), (typeof customerType === 'string') ? { customerType } : undefined);
|
|
17
|
+
if (typeof seller.id !== 'string') {
|
|
18
|
+
throw new factory.errors.NotFound('seller.id');
|
|
19
|
+
}
|
|
20
|
+
if (typeof expiresInSeconds !== 'number') {
|
|
21
|
+
throw new factory.errors.ArgumentNull('expiresInSeconds');
|
|
22
|
+
}
|
|
23
|
+
const agentIdentifier = [
|
|
24
|
+
...(Array.isArray(params.agent.identifier)) ? params.agent.identifier : [],
|
|
25
|
+
// add passport(2024-07-05~)
|
|
26
|
+
...(typeof (passport === null || passport === void 0 ? void 0 : passport.identifier) === 'string') ? [{ name: AGENT_IDENTIFIER_NAME_PASSPORT, value: passport.identifier }] : []
|
|
27
|
+
];
|
|
28
|
+
const agent = Object.assign(Object.assign(Object.assign({}, params.agent), (memeberOfPayload !== undefined) ? { memeberOfPayload } : undefined), { identifier: agentIdentifier });
|
|
29
|
+
return Object.assign({ project: { typeOf: seller.project.typeOf, id: seller.project.id }, typeOf: factory.transactionType.PlaceOrder, agent, seller: {
|
|
30
|
+
id: seller.id,
|
|
31
|
+
name: seller.name,
|
|
32
|
+
typeOf: seller.typeOf,
|
|
33
|
+
additionalProperty: (Array.isArray(seller.additionalProperty)) ? seller.additionalProperty : [] // 追加特性を追加(2023-08-08~)
|
|
34
|
+
}, object: transactionObject, expiresInSeconds }, (typeof (instrument === null || instrument === void 0 ? void 0 : instrument.id) === 'string') ? { instrument } : undefined);
|
|
35
|
+
}
|
|
36
|
+
exports.createStartParams = createStartParams;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { MongoRepository as MemberRepo } from '../../../repo/member';
|
|
2
|
+
import type { PassportRepo } from '../../../repo/passport';
|
|
2
3
|
import type { MongoRepository as ProjectMakesOfferRepo } from '../../../repo/projectMakesOffer';
|
|
3
4
|
import type { MongoRepository as SellerRepo } from '../../../repo/seller';
|
|
4
5
|
import type { IStartedTransaction, MongoRepository as TransactionRepo } from '../../../repo/transaction';
|
|
@@ -8,11 +9,15 @@ interface IStartOperationRepos {
|
|
|
8
9
|
projectMakesOffer: ProjectMakesOfferRepo;
|
|
9
10
|
seller: SellerRepo;
|
|
10
11
|
transaction: TransactionRepo;
|
|
12
|
+
passport: PassportRepo;
|
|
11
13
|
}
|
|
12
14
|
type IStartOperation<T> = (repos: IStartOperationRepos) => Promise<T>;
|
|
13
15
|
type IStartParams = PlaceOrderFactory.IStartParams;
|
|
16
|
+
interface IStartOptions {
|
|
17
|
+
lockPassport: boolean;
|
|
18
|
+
}
|
|
14
19
|
/**
|
|
15
20
|
* 取引開始
|
|
16
21
|
*/
|
|
17
|
-
declare function start(params: IStartParams): IStartOperation<IStartedTransaction>;
|
|
22
|
+
declare function start(params: IStartParams, options: IStartOptions): IStartOperation<IStartedTransaction>;
|
|
18
23
|
export { start };
|
|
@@ -13,12 +13,12 @@ exports.start = void 0;
|
|
|
13
13
|
const errorHandler_1 = require("../../../errorHandler");
|
|
14
14
|
const factory = require("../../../factory");
|
|
15
15
|
const validation_1 = require("../validation");
|
|
16
|
-
const factory_1 = require("./factory");
|
|
16
|
+
const factory_1 = require("./start/factory");
|
|
17
17
|
const validateStartRequest_1 = require("./validation/validateStartRequest");
|
|
18
18
|
/**
|
|
19
19
|
* 取引開始
|
|
20
20
|
*/
|
|
21
|
-
function start(params) {
|
|
21
|
+
function start(params, options) {
|
|
22
22
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
23
23
|
var _a;
|
|
24
24
|
const { passport, customerType } = yield (0, validation_1.validateWaiterPassport)(params);
|
|
@@ -30,8 +30,32 @@ function start(params) {
|
|
|
30
30
|
// 取引ファクトリーで新しい進行中取引オブジェクトを作成
|
|
31
31
|
const startParams = (0, factory_1.createStartParams)(params, expiresInSeconds, passport, seller, params.broker, customerType, memeberOfPayload);
|
|
32
32
|
let transaction;
|
|
33
|
+
// lock passport(2024-07-05~)
|
|
34
|
+
if (options.lockPassport && passport !== undefined) {
|
|
35
|
+
try {
|
|
36
|
+
yield repos.passport.lock(passport);
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
// in case already locked
|
|
40
|
+
const alreadyStartedTransaction = (yield repos.transaction.search({
|
|
41
|
+
limit: 1, page: 1,
|
|
42
|
+
typeOf: factory.transactionType.PlaceOrder,
|
|
43
|
+
project: { id: { $eq: startParams.project.id } },
|
|
44
|
+
agent: { identifiers: [{ name: factory_1.AGENT_IDENTIFIER_NAME_PASSPORT, value: passport.identifier }] },
|
|
45
|
+
inclusion: ['expires', 'startDate', 'status']
|
|
46
|
+
})).shift();
|
|
47
|
+
if (alreadyStartedTransaction !== undefined) {
|
|
48
|
+
transaction = alreadyStartedTransaction;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
33
55
|
try {
|
|
34
|
-
transaction
|
|
56
|
+
if (transaction === undefined) {
|
|
57
|
+
transaction = yield repos.transaction.start(startParams);
|
|
58
|
+
}
|
|
35
59
|
}
|
|
36
60
|
catch (error) {
|
|
37
61
|
if (yield (0, errorHandler_1.isMongoError)(error)) {
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 取引バリデーション
|
|
3
|
-
*/
|
|
4
|
-
import * as jwt from 'jsonwebtoken';
|
|
5
1
|
import * as factory from '../../factory';
|
|
6
2
|
import { IPassportValidator } from '../../factory/transaction';
|
|
7
|
-
|
|
3
|
+
import type { IVerifiedPassport } from '../../repo/passport';
|
|
4
|
+
type IStartParams = (factory.transaction.placeOrder.IStartParamsWithoutDetail | factory.transaction.moneyTransfer.IStartParamsWithoutDetail) & {
|
|
8
5
|
passportValidator?: IPassportValidator;
|
|
9
6
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
passport: factory.waiter.passport.IPassport | undefined;
|
|
7
|
+
declare function validateWaiterPassport(params: IStartParams): Promise<{
|
|
8
|
+
passport: IVerifiedPassport | undefined;
|
|
13
9
|
customerType?: string;
|
|
14
10
|
}>;
|
|
11
|
+
export { validateWaiterPassport };
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.validateWaiterPassport =
|
|
12
|
+
exports.validateWaiterPassport = void 0;
|
|
13
13
|
/**
|
|
14
14
|
* 取引バリデーション
|
|
15
15
|
*/
|
|
@@ -42,13 +42,13 @@ function createPassport(params) {
|
|
|
42
42
|
if (typeof params.issueUnit.numberOfRequests !== 'number') {
|
|
43
43
|
throw new factory.errors.Argument('issueUnit.numberOfRequests', 'issueUnit.numberOfRequests must be number');
|
|
44
44
|
}
|
|
45
|
-
|
|
45
|
+
const identifier = `${params.issueUnit.identifier}:${params.issueUnit.numberOfRequests}`;
|
|
46
|
+
return Object.assign({ identifier, scope: params.scope, iat: params.iat, exp: params.exp, iss: params.iss,
|
|
46
47
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
47
48
|
project: params.project,
|
|
48
49
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
49
50
|
issueUnit: params.issueUnit }, (Array.isArray(params.aud)) ? { aud: params.aud } : undefined);
|
|
50
51
|
}
|
|
51
|
-
exports.createPassport = createPassport;
|
|
52
52
|
/**
|
|
53
53
|
* 暗号化された許可証を検証する
|
|
54
54
|
*/
|
package/package.json
CHANGED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import * as factory from '../../../factory';
|
|
2
|
-
export declare function createStartParams(params: factory.transaction.placeOrder.IStartParamsWithoutDetail, expiresInSeconds: number, passport: factory.waiter.passport.IPassport | undefined, seller: Pick<factory.seller.ISeller, 'id' | 'name' | 'typeOf' | 'project' | 'additionalProperty'>, broker?: factory.order.IBroker, customerType?: string, memeberOfPayload?: factory.transaction.placeOrder.IMemberOfPayload): factory.transaction.placeOrder.IStartParams;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createStartParams = void 0;
|
|
4
|
-
const factory = require("../../../factory");
|
|
5
|
-
function createStartParams(params, expiresInSeconds, passport, seller, broker, customerType, memeberOfPayload) {
|
|
6
|
-
var _a, _b, _c, _d, _e;
|
|
7
|
-
let clientUser;
|
|
8
|
-
let instrument;
|
|
9
|
-
if (typeof ((_a = params.object.clientUser) === null || _a === void 0 ? void 0 : _a.client_id) === 'string') {
|
|
10
|
-
const { sub, token_use, iss, exp, iat, version, jti, client_id, username, aud, typ } = params.object.clientUser;
|
|
11
|
-
clientUser = { sub, token_use, iss, exp, iat, version, jti, client_id, username, aud, typ };
|
|
12
|
-
instrument = { id: client_id, typeOf: factory.creativeWorkType.WebApplication };
|
|
13
|
-
}
|
|
14
|
-
const transactionObject = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (typeof ((_b = params.object.passport) === null || _b === void 0 ? void 0 : _b.token) === 'string') ? { passportToken: params.object.passport.token } : undefined), (typeof (passport === null || passport === void 0 ? void 0 : passport.scope) === 'string') ? { passport } : undefined), (typeof (clientUser === null || clientUser === void 0 ? void 0 : clientUser.client_id) === 'string') ? { clientUser } : undefined), (typeof ((_c = params.object) === null || _c === void 0 ? void 0 : _c.name) === 'string') ? { name: (_d = params.object) === null || _d === void 0 ? void 0 : _d.name } : undefined), (typeof (broker === null || broker === void 0 ? void 0 : broker.typeOf) === 'string') ? { broker: broker } : undefined), (typeof ((_e = params.object.customer) === null || _e === void 0 ? void 0 : _e.typeOf) === 'string') ? { customer: params.object.customer } : undefined), (typeof customerType === 'string') ? { customerType } : undefined);
|
|
15
|
-
if (typeof seller.id !== 'string') {
|
|
16
|
-
throw new factory.errors.NotFound('seller.id');
|
|
17
|
-
}
|
|
18
|
-
if (typeof expiresInSeconds !== 'number') {
|
|
19
|
-
throw new factory.errors.ArgumentNull('expiresInSeconds');
|
|
20
|
-
}
|
|
21
|
-
const agent = Object.assign(Object.assign({}, params.agent), (memeberOfPayload !== undefined) ? { memeberOfPayload } : undefined);
|
|
22
|
-
return Object.assign({ project: { typeOf: seller.project.typeOf, id: seller.project.id }, typeOf: factory.transactionType.PlaceOrder, agent, seller: {
|
|
23
|
-
id: seller.id,
|
|
24
|
-
name: seller.name,
|
|
25
|
-
typeOf: seller.typeOf,
|
|
26
|
-
additionalProperty: (Array.isArray(seller.additionalProperty)) ? seller.additionalProperty : [] // 追加特性を追加(2023-08-08~)
|
|
27
|
-
}, object: transactionObject, expiresInSeconds }, (typeof (instrument === null || instrument === void 0 ? void 0 : instrument.id) === 'string') ? { instrument } : undefined);
|
|
28
|
-
}
|
|
29
|
-
exports.createStartParams = createStartParams;
|