@chevre/domain 21.37.0-alpha.15 → 21.37.0-alpha.16
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 +4 -1
- package/lib/chevre/factory/transaction.d.ts +1 -4
- package/lib/chevre/repo/passport.d.ts +22 -2
- package/lib/chevre/repo/passport.js +87 -3
- 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.d.ts +1 -1
- package/lib/chevre/service/transaction/placeOrderInProgress/start.js +3 -13
- package/package.json +1 -1
- package/lib/chevre/service/transaction/validation.d.ts +0 -11
- package/lib/chevre/service/transaction/validation.js +0 -101
|
@@ -33,7 +33,10 @@ async function main() {
|
|
|
33
33
|
}
|
|
34
34
|
)({
|
|
35
35
|
member: await chevre.repository.Member.createInstance(mongoose.connection),
|
|
36
|
-
passport: await chevre.repository.Passport.createInstance(
|
|
36
|
+
passport: await chevre.repository.Passport.createInstance(
|
|
37
|
+
client,
|
|
38
|
+
{ secret: 'xxx' }
|
|
39
|
+
),
|
|
37
40
|
projectMakesOffer: await chevre.repository.ProjectMakesOffer.createInstance(mongoose.connection),
|
|
38
41
|
seller: await chevre.repository.Seller.createInstance(mongoose.connection),
|
|
39
42
|
transaction: await chevre.repository.Transaction.createInstance(mongoose.connection)
|
|
@@ -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;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import * as jwt from 'jsonwebtoken';
|
|
1
2
|
import type { RedisClientType } from 'redis';
|
|
2
3
|
import * as factory from '../factory';
|
|
4
|
+
import { IPassportValidator } from '../factory/transaction';
|
|
3
5
|
export type IVerifiedPassport = factory.waiter.passport.IPassport & {
|
|
4
6
|
/**
|
|
5
7
|
* 許可証識別子(2024-07-06~)
|
|
@@ -7,13 +9,31 @@ export type IVerifiedPassport = factory.waiter.passport.IPassport & {
|
|
|
7
9
|
identifier: string;
|
|
8
10
|
};
|
|
9
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) & {};
|
|
10
17
|
/**
|
|
11
18
|
* 取引許可証リポジトリ
|
|
12
19
|
*/
|
|
13
20
|
export declare class PassportRepo {
|
|
14
21
|
private readonly redisClient;
|
|
15
|
-
|
|
22
|
+
private readonly options;
|
|
23
|
+
constructor(redisClient: RedisClientType, options: IOptions);
|
|
24
|
+
static CREATE_VERIFIED_PASSPORT(params: string | jwt.JwtPayload | undefined): IVerifiedPassport;
|
|
16
25
|
static CREATE_REDIS_KEY(params: ILockKey): string;
|
|
17
|
-
lock(params: ILockKey): Promise<
|
|
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;
|
|
18
38
|
}
|
|
19
39
|
export {};
|
|
@@ -11,15 +11,49 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.PassportRepo = void 0;
|
|
13
13
|
const createDebug = require("debug");
|
|
14
|
+
const jwt = require("jsonwebtoken");
|
|
14
15
|
const moment = require("moment");
|
|
15
16
|
const factory = require("../factory");
|
|
16
|
-
const debug = createDebug('chevre-domain:repo:
|
|
17
|
+
const debug = createDebug('chevre-domain:repo:passport');
|
|
17
18
|
/**
|
|
18
19
|
* 取引許可証リポジトリ
|
|
19
20
|
*/
|
|
20
21
|
class PassportRepo {
|
|
21
|
-
constructor(redisClient) {
|
|
22
|
+
constructor(redisClient, options) {
|
|
22
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);
|
|
23
57
|
}
|
|
24
58
|
static CREATE_REDIS_KEY(params) {
|
|
25
59
|
return `chvr:lockPassport:${params.identifier}`;
|
|
@@ -39,12 +73,62 @@ class PassportRepo {
|
|
|
39
73
|
.exec();
|
|
40
74
|
debug('locked,', params.issueUnit.identifier, now, passportExpires, ttl, results);
|
|
41
75
|
if (Array.isArray(results) && (results[0] === 1 || results[0] === true)) {
|
|
42
|
-
return
|
|
76
|
+
return;
|
|
43
77
|
}
|
|
44
78
|
else {
|
|
45
79
|
throw new factory.errors.AlreadyInUse('passport', [], 'passport already in use');
|
|
46
80
|
}
|
|
47
81
|
});
|
|
48
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
|
+
}
|
|
49
133
|
}
|
|
50
134
|
exports.PassportRepo = PassportRepo;
|
|
@@ -2,6 +2,7 @@ import type { MongoRepository as ActionRepo } from '../../repo/action';
|
|
|
2
2
|
import type { MongoRepository as AssetTransactionRepo } from '../../repo/assetTransaction';
|
|
3
3
|
import type { AuthorizationRepo } from '../../repo/code';
|
|
4
4
|
import type { MongoRepository as OrderRepo } from '../../repo/order';
|
|
5
|
+
import type { PassportRepo } from '../../repo/passport';
|
|
5
6
|
import type { MongoRepository as ProductRepo } from '../../repo/product';
|
|
6
7
|
import type { MongoRepository as ProjectRepo } from '../../repo/project';
|
|
7
8
|
import type { MongoRepository as SellerRepo } from '../../repo/seller';
|
|
@@ -9,11 +10,12 @@ import type { MongoRepository as TaskRepo } from '../../repo/task';
|
|
|
9
10
|
import type { TicketRepo } from '../../repo/ticket';
|
|
10
11
|
import type { IStartedTransaction, MongoRepository as TransactionRepo } from '../../repo/transaction';
|
|
11
12
|
import type { RedisRepository as TransactionNumberRepo } from '../../repo/transactionNumber';
|
|
12
|
-
import {
|
|
13
|
+
import { moneyTransfer as MoneyTransferFactory } from '../../factory/transaction';
|
|
13
14
|
export interface IStartOperationRepos {
|
|
14
15
|
action: ActionRepo;
|
|
15
16
|
authorization: AuthorizationRepo;
|
|
16
17
|
order: OrderRepo;
|
|
18
|
+
passport: PassportRepo;
|
|
17
19
|
product: ProductRepo;
|
|
18
20
|
project: ProjectRepo;
|
|
19
21
|
seller: SellerRepo;
|
|
@@ -31,7 +33,6 @@ export type IConfirmOperation<T> = (repos: {
|
|
|
31
33
|
action: ActionRepo;
|
|
32
34
|
transaction: TransactionRepo;
|
|
33
35
|
}) => Promise<T>;
|
|
34
|
-
export type IPassportValidator = IWaiterPassportValidator;
|
|
35
36
|
export type IStartParams = MoneyTransferFactory.IStartParams;
|
|
36
37
|
/**
|
|
37
38
|
* 取引開始
|
|
@@ -19,7 +19,6 @@ const order_1 = require("../../factory/order");
|
|
|
19
19
|
const factory_1 = require("./moneyTransfer/exportTasks/factory");
|
|
20
20
|
const factory_2 = require("./moneyTransfer/factory");
|
|
21
21
|
const potentialActions_1 = require("./moneyTransfer/potentialActions");
|
|
22
|
-
const validation_1 = require("./validation");
|
|
23
22
|
const MoneyTransferAssetTransactionService = require("../assetTransaction/moneyTransfer");
|
|
24
23
|
const CodeService = require("../code");
|
|
25
24
|
/**
|
|
@@ -28,7 +27,7 @@ const CodeService = require("../code");
|
|
|
28
27
|
*/
|
|
29
28
|
function start(params) {
|
|
30
29
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
31
|
-
const { passport } = yield
|
|
30
|
+
const { passport } = yield repos.passport.validatePassportTokenIfExist(params);
|
|
32
31
|
const sellers = yield repos.seller.search({
|
|
33
32
|
limit: 1,
|
|
34
33
|
page: 1,
|
|
@@ -6,10 +6,10 @@ import type { IStartedTransaction, MongoRepository as TransactionRepo } from '..
|
|
|
6
6
|
import { placeOrder as PlaceOrderFactory } from '../../../factory/transaction';
|
|
7
7
|
interface IStartOperationRepos {
|
|
8
8
|
member: MemberRepo;
|
|
9
|
+
passport: PassportRepo;
|
|
9
10
|
projectMakesOffer: ProjectMakesOfferRepo;
|
|
10
11
|
seller: SellerRepo;
|
|
11
12
|
transaction: TransactionRepo;
|
|
12
|
-
passport: PassportRepo;
|
|
13
13
|
}
|
|
14
14
|
type IStartOperation<T> = (repos: IStartOperationRepos) => Promise<T>;
|
|
15
15
|
type IStartParams = PlaceOrderFactory.IStartParams;
|
|
@@ -10,9 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.start = void 0;
|
|
13
|
-
const errorHandler_1 = require("../../../errorHandler");
|
|
14
13
|
const factory = require("../../../factory");
|
|
15
|
-
const validation_1 = require("../validation");
|
|
16
14
|
const factory_1 = require("./start/factory");
|
|
17
15
|
const validateStartRequest_1 = require("./validation/validateStartRequest");
|
|
18
16
|
/**
|
|
@@ -21,7 +19,7 @@ const validateStartRequest_1 = require("./validation/validateStartRequest");
|
|
|
21
19
|
function start(params, options) {
|
|
22
20
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
23
21
|
var _a;
|
|
24
|
-
const { passport, customerType } = yield
|
|
22
|
+
const { passport, customerType } = yield repos.passport.validatePassportTokenIfExist(params);
|
|
25
23
|
const { memeberOfPayload, sellerMakesOffer, seller } = yield (0, validateStartRequest_1.validateStartRequest)(Object.assign(Object.assign(Object.assign({ project: { id: params.project.id }, seller: { id: params.seller.id } }, (typeof (passport === null || passport === void 0 ? void 0 : passport.scope) === 'string') ? { customerType } : undefined), (params.object.clientUser !== undefined) ? { clientUser: params.object.clientUser } : undefined), (typeof params.agent.memberOfToken === 'string') ? { memberOfToken: params.agent.memberOfToken } : undefined))(repos);
|
|
26
24
|
const expiresInSeconds = (_a = sellerMakesOffer.eligibleTransactionDuration) === null || _a === void 0 ? void 0 : _a.maxValue;
|
|
27
25
|
if (typeof expiresInSeconds !== 'number') {
|
|
@@ -52,16 +50,8 @@ function start(params, options) {
|
|
|
52
50
|
}
|
|
53
51
|
}
|
|
54
52
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
transaction = yield repos.transaction.start(startParams);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
catch (error) {
|
|
61
|
-
if (yield (0, errorHandler_1.isMongoError)(error)) {
|
|
62
|
-
// no op
|
|
63
|
-
}
|
|
64
|
-
throw error;
|
|
53
|
+
if (transaction === undefined) {
|
|
54
|
+
transaction = yield repos.transaction.start(startParams);
|
|
65
55
|
}
|
|
66
56
|
return transaction;
|
|
67
57
|
});
|
package/package.json
CHANGED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import * as factory from '../../factory';
|
|
2
|
-
import { IPassportValidator } from '../../factory/transaction';
|
|
3
|
-
import type { IVerifiedPassport } from '../../repo/passport';
|
|
4
|
-
type IStartParams = (factory.transaction.placeOrder.IStartParamsWithoutDetail | factory.transaction.moneyTransfer.IStartParamsWithoutDetail) & {
|
|
5
|
-
passportValidator?: IPassportValidator;
|
|
6
|
-
};
|
|
7
|
-
declare function validateWaiterPassport(params: IStartParams): Promise<{
|
|
8
|
-
passport: IVerifiedPassport | undefined;
|
|
9
|
-
customerType?: string;
|
|
10
|
-
}>;
|
|
11
|
-
export { validateWaiterPassport };
|
|
@@ -1,101 +0,0 @@
|
|
|
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.validateWaiterPassport = void 0;
|
|
13
|
-
/**
|
|
14
|
-
* 取引バリデーション
|
|
15
|
-
*/
|
|
16
|
-
const jwt = require("jsonwebtoken");
|
|
17
|
-
const factory = require("../../factory");
|
|
18
|
-
function createPassport(params) {
|
|
19
|
-
var _a;
|
|
20
|
-
if (typeof params === 'string' || params === undefined) {
|
|
21
|
-
throw new factory.errors.Argument('decoded must be an object');
|
|
22
|
-
}
|
|
23
|
-
// eslint-disable-next-line no-magic-numbers
|
|
24
|
-
if (typeof params.scope !== 'string' || params.scope.length === 0) {
|
|
25
|
-
throw new factory.errors.ArgumentNull('scope');
|
|
26
|
-
}
|
|
27
|
-
if (typeof params.iat !== 'number') {
|
|
28
|
-
throw new factory.errors.Argument('iat', 'iat must be number');
|
|
29
|
-
}
|
|
30
|
-
if (typeof params.exp !== 'number') {
|
|
31
|
-
throw new factory.errors.Argument('exp', 'exp must be number');
|
|
32
|
-
}
|
|
33
|
-
// eslint-disable-next-line no-magic-numbers
|
|
34
|
-
if (typeof params.iss !== 'string' || params.iss.length === 0) {
|
|
35
|
-
throw new factory.errors.ArgumentNull('iss');
|
|
36
|
-
}
|
|
37
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, no-magic-numbers
|
|
38
|
-
if (typeof ((_a = params.issueUnit) === null || _a === void 0 ? void 0 : _a.identifier) !== 'string' || params.issueUnit.identifier.length === 0) {
|
|
39
|
-
throw new factory.errors.Argument('issueUnit.identifier', 'issueUnit.identifier must be string');
|
|
40
|
-
}
|
|
41
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
42
|
-
if (typeof params.issueUnit.numberOfRequests !== 'number') {
|
|
43
|
-
throw new factory.errors.Argument('issueUnit.numberOfRequests', 'issueUnit.numberOfRequests must be number');
|
|
44
|
-
}
|
|
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,
|
|
47
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
48
|
-
project: params.project,
|
|
49
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
50
|
-
issueUnit: params.issueUnit }, (Array.isArray(params.aud)) ? { aud: params.aud } : undefined);
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* 暗号化された許可証を検証する
|
|
54
|
-
*/
|
|
55
|
-
function verify(params) {
|
|
56
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
-
return new Promise((resolve, reject) => {
|
|
58
|
-
jwt.verify(params.token, params.secret, (err, decoded) => {
|
|
59
|
-
if (err instanceof Error) {
|
|
60
|
-
reject(err);
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
const passport = createPassport(decoded);
|
|
64
|
-
resolve(passport);
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
function validateWaiterPassport(params) {
|
|
71
|
-
var _a, _b;
|
|
72
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
-
let passport;
|
|
74
|
-
let customerType;
|
|
75
|
-
// WAITER許可証トークンがあれば検証する
|
|
76
|
-
if (typeof ((_b = (_a = params.object) === null || _a === void 0 ? void 0 : _a.passport) === null || _b === void 0 ? void 0 : _b.token) === 'string') {
|
|
77
|
-
try {
|
|
78
|
-
passport = yield verify({
|
|
79
|
-
token: params.object.passport.token,
|
|
80
|
-
secret: params.object.passport.secret
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
catch (error) {
|
|
84
|
-
throw new factory.errors.Argument('Passport Token', `Invalid token: ${error.message}`);
|
|
85
|
-
}
|
|
86
|
-
// 許可証バリデーション
|
|
87
|
-
if (typeof params.passportValidator === 'function') {
|
|
88
|
-
if (!params.passportValidator({ passport: passport })) {
|
|
89
|
-
throw new factory.errors.Argument('Passport Token', 'Invalid passport');
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
// カスタマータイプ決定(2023-11-20~)
|
|
93
|
-
// スコープのフォーマットは、Transaction:${TransactionType}:${sellerId}:${customerType}
|
|
94
|
-
const splittedScope = passport.scope.split(':');
|
|
95
|
-
// tslint:disable-next-line:no-magic-numbers
|
|
96
|
-
customerType = splittedScope[3];
|
|
97
|
-
}
|
|
98
|
-
return Object.assign(Object.assign({}, (typeof customerType === 'string') ? { customerType } : undefined), { passport });
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
exports.validateWaiterPassport = validateWaiterPassport;
|