@chevre/domain 22.0.0-alpha.1 → 22.0.0-alpha.3
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/findReservationByCode.ts +17 -5
- package/example/src/chevre/findValidAuthorization.ts +16 -4
- package/lib/chevre/credentials/jwt.d.ts +23 -0
- package/lib/chevre/credentials/jwt.js +18 -0
- package/lib/chevre/credentials.d.ts +14 -24
- package/lib/chevre/credentials.js +63 -37
- package/lib/chevre/repo/authorization.d.ts +1 -2
- package/lib/chevre/service/code.d.ts +21 -10
- package/lib/chevre/service/code.js +74 -70
- package/lib/chevre/service/offer/event/authorize/processStartReserve4chevre.d.ts +3 -0
- package/lib/chevre/service/offer/event/authorize/processStartReserve4chevre.js +6 -5
- package/lib/chevre/service/offer/event/authorize.d.ts +4 -1
- package/lib/chevre/service/offer/event/authorize.js +2 -2
- package/lib/chevre/service/payment/any.d.ts +4 -1
- package/lib/chevre/service/payment/any.js +8 -5
- package/lib/chevre/service/reserve/verifyToken4reservation.d.ts +3 -0
- package/lib/chevre/service/reserve/verifyToken4reservation.js +4 -3
- package/lib/chevre/service/task/authorizePayment.js +21 -17
- package/lib/chevre/service/task.d.ts +2 -0
- package/lib/chevre/service/transaction/moneyTransfer.d.ts +6 -1
- package/lib/chevre/service/transaction/moneyTransfer.js +12 -11
- package/package.json +2 -2
|
@@ -28,11 +28,23 @@ async function main() {
|
|
|
28
28
|
ticket: {
|
|
29
29
|
ticketToken: CODE
|
|
30
30
|
}
|
|
31
|
-
})(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
})(
|
|
32
|
+
{
|
|
33
|
+
authorization: authorizationRepo,
|
|
34
|
+
order: orderRepo,
|
|
35
|
+
ticket: ticketRepo
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
jwt: await chevre.credentials.JWT.createInstance({
|
|
39
|
+
secret: <string>process.env.TOKEN_SECRET,
|
|
40
|
+
issuers: (typeof process.env.TOKEN_ISSUERS_BY_AUTHORIZATION === 'string')
|
|
41
|
+
? process.env.TOKEN_ISSUERS_BY_AUTHORIZATION.split(' ')
|
|
42
|
+
: [],
|
|
43
|
+
version: (typeof process.env.TOKEN_VERSION === 'string') ? process.env.TOKEN_VERSION : '2024-05-02',
|
|
44
|
+
payloadTypPrefix: (typeof process.env.TOKEN_PAYLOAD_TYP_PREFIX === 'string') ? process.env.TOKEN_PAYLOAD_TYP_PREFIX : 'chevre'
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
);
|
|
36
48
|
console.log('verified.');
|
|
37
49
|
|
|
38
50
|
const result = await (await chevre.service.reserve.createService()).findByCode({
|
|
@@ -33,10 +33,22 @@ async function main() {
|
|
|
33
33
|
issuer: 'https://example.com',
|
|
34
34
|
audience: 'https://example.com',
|
|
35
35
|
useJti: true
|
|
36
|
-
})(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
})(
|
|
37
|
+
{
|
|
38
|
+
authorization: authorizationRepo,
|
|
39
|
+
ticket: ticketRepo
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
jwt: await chevre.credentials.JWT.createInstance({
|
|
43
|
+
secret: <string>process.env.TOKEN_SECRET,
|
|
44
|
+
issuers: (typeof process.env.TOKEN_ISSUERS_BY_AUTHORIZATION === 'string')
|
|
45
|
+
? process.env.TOKEN_ISSUERS_BY_AUTHORIZATION.split(' ')
|
|
46
|
+
: [],
|
|
47
|
+
version: (typeof process.env.TOKEN_VERSION === 'string') ? process.env.TOKEN_VERSION : '2024-05-02',
|
|
48
|
+
payloadTypPrefix: (typeof process.env.TOKEN_PAYLOAD_TYP_PREFIX === 'string') ? process.env.TOKEN_PAYLOAD_TYP_PREFIX : 'chevre'
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
);
|
|
40
52
|
console.log('token:', token);
|
|
41
53
|
}
|
|
42
54
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
interface IOptions {
|
|
2
|
+
secret: string;
|
|
3
|
+
/**
|
|
4
|
+
* トークン検証時の発行者リスト
|
|
5
|
+
*/
|
|
6
|
+
issuers: string[];
|
|
7
|
+
version: string;
|
|
8
|
+
payloadTypPrefix: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* トークン認証情報
|
|
12
|
+
*/
|
|
13
|
+
declare class JWTCredentials {
|
|
14
|
+
readonly secret: string;
|
|
15
|
+
/**
|
|
16
|
+
* トークン検証時の発行者リスト
|
|
17
|
+
*/
|
|
18
|
+
readonly issuers: string[];
|
|
19
|
+
readonly version: string;
|
|
20
|
+
readonly payloadTypPrefix: string;
|
|
21
|
+
constructor(options: IOptions);
|
|
22
|
+
}
|
|
23
|
+
export { JWTCredentials };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JWTCredentials = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* トークン認証情報
|
|
6
|
+
*/
|
|
7
|
+
class JWTCredentials {
|
|
8
|
+
constructor(options) {
|
|
9
|
+
this.version = '2024-05-02'; // 追加(2024-05-02~)
|
|
10
|
+
this.payloadTypPrefix = 'chevre';
|
|
11
|
+
const { secret, issuers, version, payloadTypPrefix } = options;
|
|
12
|
+
this.issuers = issuers;
|
|
13
|
+
this.payloadTypPrefix = payloadTypPrefix;
|
|
14
|
+
this.secret = secret;
|
|
15
|
+
this.version = version;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.JWTCredentials = JWTCredentials;
|
|
@@ -1,40 +1,35 @@
|
|
|
1
|
+
import type { JWTCredentials } from './credentials/jwt';
|
|
1
2
|
/**
|
|
2
3
|
* 外部サービスを使用するための認証情報
|
|
3
4
|
*/
|
|
4
|
-
export declare
|
|
5
|
-
aws: {
|
|
5
|
+
export declare namespace credentials {
|
|
6
|
+
const aws: {
|
|
6
7
|
accessKeyId: string;
|
|
7
8
|
secretAccessKey: string;
|
|
8
9
|
tokenIssuerEndpoint: string;
|
|
9
10
|
};
|
|
10
|
-
|
|
11
|
-
authorizeServerDomain: string;
|
|
12
|
-
clientId: string;
|
|
13
|
-
clientSecret: string;
|
|
14
|
-
endpoint: string;
|
|
15
|
-
};
|
|
16
|
-
coa: {
|
|
11
|
+
const coa: {
|
|
17
12
|
endpoint: string;
|
|
18
13
|
refreshToken: string;
|
|
19
14
|
timeout: number;
|
|
20
15
|
useFetch: boolean;
|
|
21
16
|
};
|
|
22
|
-
customSearch: {
|
|
17
|
+
const customSearch: {
|
|
23
18
|
engineId: string;
|
|
24
19
|
apiKey: string;
|
|
25
20
|
};
|
|
26
|
-
gmo: {
|
|
21
|
+
const gmo: {
|
|
27
22
|
timeout: number;
|
|
28
23
|
timeoutBackground: number | undefined;
|
|
29
24
|
useFetch: boolean;
|
|
30
25
|
};
|
|
31
|
-
lineNotify: {
|
|
26
|
+
const lineNotify: {
|
|
32
27
|
url: string | undefined;
|
|
33
28
|
accessToken: string | undefined;
|
|
34
29
|
accessTokenAlert: string | undefined;
|
|
35
30
|
accessTokenInfo: string | undefined;
|
|
36
31
|
};
|
|
37
|
-
movieticketReserve: {
|
|
32
|
+
const movieticketReserve: {
|
|
38
33
|
/**
|
|
39
34
|
* 着券時タイムアウト
|
|
40
35
|
*/
|
|
@@ -44,16 +39,11 @@ export declare const credentials: {
|
|
|
44
39
|
*/
|
|
45
40
|
timeoutCheck: number;
|
|
46
41
|
};
|
|
47
|
-
sendGrid: {
|
|
42
|
+
const sendGrid: {
|
|
48
43
|
apiKey: string | undefined;
|
|
49
44
|
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
issuers: string[];
|
|
56
|
-
version: string;
|
|
57
|
-
payloadTypPrefix: string;
|
|
58
|
-
};
|
|
59
|
-
};
|
|
45
|
+
type JWT = JWTCredentials;
|
|
46
|
+
namespace JWT {
|
|
47
|
+
function createInstance(...params: ConstructorParameters<typeof JWTCredentials>): Promise<JWTCredentials>;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -1,47 +1,75 @@
|
|
|
1
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
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.credentials = void 0;
|
|
13
|
+
// export const credentials = {
|
|
14
|
+
// migrate to JWTCredentials(2024-07-11~)
|
|
15
|
+
// jwt: {
|
|
16
|
+
// secret: <string>process.env.TOKEN_SECRET,
|
|
17
|
+
// // RESOURCE_SERVER_IDENTIFIERとは分離して指定可能に拡張(2024-05-02~)
|
|
18
|
+
// // issuer: (typeof process.env.TOKEN_ISSUER_BY_AUTHORIZATION === 'string')
|
|
19
|
+
// // ? process.env.TOKEN_ISSUER_BY_AUTHORIZATION
|
|
20
|
+
// // : <string>process.env.RESOURCE_SERVER_IDENTIFIER,
|
|
21
|
+
// /**
|
|
22
|
+
// * トークン検証時の発行者リスト
|
|
23
|
+
// */
|
|
24
|
+
// issuers: (typeof process.env.TOKEN_ISSUERS_BY_AUTHORIZATION === 'string')
|
|
25
|
+
// ? process.env.TOKEN_ISSUERS_BY_AUTHORIZATION.split(' ')
|
|
26
|
+
// : [], // 追加(2024-05-02~)
|
|
27
|
+
// version: (typeof process.env.TOKEN_VERSION === 'string') ? process.env.TOKEN_VERSION : '2024-05-02', // 追加(2024-05-02~)
|
|
28
|
+
// payloadTypPrefix: (typeof process.env.TOKEN_PAYLOAD_TYP_PREFIX === 'string') ? process.env.TOKEN_PAYLOAD_TYP_PREFIX : 'chevre'
|
|
29
|
+
// }
|
|
30
|
+
// };
|
|
4
31
|
/**
|
|
5
32
|
* 外部サービスを使用するための認証情報
|
|
6
33
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
34
|
+
var credentials;
|
|
35
|
+
(function (credentials) {
|
|
36
|
+
credentials.aws = {
|
|
9
37
|
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
|
10
38
|
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
|
|
11
39
|
tokenIssuerEndpoint: process.env.TOKEN_ISSUER_ENDPOINT
|
|
12
|
-
}
|
|
13
|
-
chevre
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
coa
|
|
40
|
+
};
|
|
41
|
+
// export const chevre = {
|
|
42
|
+
// authorizeServerDomain: <string>process.env.CHEVRE_AUTHORIZE_SERVER_DOMAIN,
|
|
43
|
+
// clientId: <string>process.env.CHEVRE_CLIENT_ID,
|
|
44
|
+
// clientSecret: <string>process.env.CHEVRE_CLIENT_SECRET,
|
|
45
|
+
// endpoint: <string>process.env.CHEVRE_ENDPOINT
|
|
46
|
+
// };
|
|
47
|
+
credentials.coa = {
|
|
20
48
|
endpoint: process.env.COA_ENDPOINT,
|
|
21
49
|
refreshToken: process.env.COA_REFRESH_TOKEN,
|
|
22
50
|
// tslint:disable-next-line:no-magic-numbers
|
|
23
51
|
timeout: (typeof process.env.COA_TIMEOUT === 'string') ? Number(process.env.COA_TIMEOUT) : 20000,
|
|
24
52
|
useFetch: process.env.COA_USE_FETCH === '1'
|
|
25
|
-
}
|
|
26
|
-
customSearch
|
|
53
|
+
};
|
|
54
|
+
credentials.customSearch = {
|
|
27
55
|
engineId: process.env.CUSTOM_SEARCH_ENGINE_ID,
|
|
28
56
|
apiKey: process.env.GOOGLE_API_KEY
|
|
29
|
-
}
|
|
30
|
-
gmo
|
|
57
|
+
};
|
|
58
|
+
credentials.gmo = {
|
|
31
59
|
// tslint:disable-next-line:no-magic-numbers
|
|
32
60
|
timeout: (typeof process.env.GMO_TIMEOUT === 'string') ? Number(process.env.GMO_TIMEOUT) : 5000,
|
|
33
61
|
timeoutBackground: (typeof process.env.GMO_TIMEOUT_BACKGROUND === 'string')
|
|
34
62
|
? Number(process.env.GMO_TIMEOUT_BACKGROUND)
|
|
35
63
|
: undefined,
|
|
36
64
|
useFetch: process.env.GMO_USE_FETCH === '1'
|
|
37
|
-
}
|
|
38
|
-
lineNotify
|
|
65
|
+
};
|
|
66
|
+
credentials.lineNotify = {
|
|
39
67
|
url: process.env.LINE_NOTIFY_URL,
|
|
40
68
|
accessToken: process.env.LINE_NOTIFY_ACCESS_TOKEN,
|
|
41
69
|
accessTokenAlert: process.env.LINE_NOTIFY_ACCESS_TOKEN_ALERT,
|
|
42
70
|
accessTokenInfo: process.env.LINE_NOTIFY_ACCESS_TOKEN_INFO
|
|
43
|
-
}
|
|
44
|
-
movieticketReserve
|
|
71
|
+
};
|
|
72
|
+
credentials.movieticketReserve = {
|
|
45
73
|
/**
|
|
46
74
|
* 着券時タイムアウト
|
|
47
75
|
*/
|
|
@@ -52,23 +80,21 @@ exports.credentials = {
|
|
|
52
80
|
*/
|
|
53
81
|
// tslint:disable-next-line:no-magic-numbers
|
|
54
82
|
timeoutCheck: (typeof process.env.MVTK_TIMEOUT_CHECK === 'string') ? Number(process.env.MVTK_TIMEOUT_CHECK) : 5000
|
|
55
|
-
}
|
|
56
|
-
sendGrid
|
|
83
|
+
};
|
|
84
|
+
credentials.sendGrid = {
|
|
57
85
|
apiKey: process.env.SENDGRID_API_KEY
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
};
|
|
86
|
+
};
|
|
87
|
+
let JWT;
|
|
88
|
+
(function (JWT) {
|
|
89
|
+
let cred;
|
|
90
|
+
function createInstance(...params) {
|
|
91
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
+
if (cred === undefined) {
|
|
93
|
+
cred = (yield Promise.resolve().then(() => require('./credentials/jwt'))).JWTCredentials;
|
|
94
|
+
}
|
|
95
|
+
return new cred(...params);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
JWT.createInstance = createInstance;
|
|
99
|
+
})(JWT = credentials.JWT || (credentials.JWT = {}));
|
|
100
|
+
})(credentials = exports.credentials || (exports.credentials = {}));
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Connection, FilterQuery } from 'mongoose';
|
|
2
2
|
import * as factory from '../factory';
|
|
3
|
-
export type ICode = string;
|
|
4
3
|
type IFindValidOneResult = Pick<factory.authorization.IAuthorization, 'object' | 'typeOf' | 'audience' | 'issuedBy'> & {
|
|
5
4
|
id: string;
|
|
6
5
|
};
|
|
@@ -26,7 +25,7 @@ export declare class AuthorizationRepo {
|
|
|
26
25
|
project: {
|
|
27
26
|
id: string;
|
|
28
27
|
};
|
|
29
|
-
code:
|
|
28
|
+
code: string;
|
|
30
29
|
}): Promise<IFindValidOneResult>;
|
|
31
30
|
/**
|
|
32
31
|
* 有効な承認を参照する
|
|
@@ -1,16 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 承認サービス
|
|
3
|
+
*/
|
|
4
|
+
import * as jwt from 'jsonwebtoken';
|
|
1
5
|
import type { ActionRepo } from '../repo/action';
|
|
2
|
-
import type { AuthorizationRepo
|
|
6
|
+
import type { AuthorizationRepo } from '../repo/authorization';
|
|
3
7
|
import type { TicketRepo } from '../repo/ticket';
|
|
8
|
+
import { JWTCredentials } from '../credentials/jwt';
|
|
4
9
|
import * as factory from '../factory';
|
|
5
10
|
type IToken = string;
|
|
6
|
-
interface IPayload extends Pick<factory.clientUser.IClientUser, 'aud' | 'exp' | 'iat' | 'iss' | '
|
|
11
|
+
interface IPayload extends Pick<factory.clientUser.IClientUser, 'aud' | 'exp' | 'iat' | 'iss' | 'sub' | 'token_use' | 'typ' | 'version'> {
|
|
7
12
|
version: string;
|
|
8
13
|
typ: string;
|
|
14
|
+
jti?: string;
|
|
9
15
|
}
|
|
10
|
-
type
|
|
11
|
-
version?: never;
|
|
12
|
-
typ?: never;
|
|
13
|
-
};
|
|
16
|
+
type IAuthorizedObject = factory.authorization.IObject;
|
|
14
17
|
/**
|
|
15
18
|
* コードをトークンに変換する
|
|
16
19
|
*/
|
|
@@ -22,7 +25,7 @@ declare function getToken(params: {
|
|
|
22
25
|
project: {
|
|
23
26
|
id: string;
|
|
24
27
|
};
|
|
25
|
-
code:
|
|
28
|
+
code: string;
|
|
26
29
|
expiresIn: number;
|
|
27
30
|
/**
|
|
28
31
|
* jtw.payload.iss
|
|
@@ -39,7 +42,11 @@ declare function getToken(params: {
|
|
|
39
42
|
}): (repos: {
|
|
40
43
|
authorization: AuthorizationRepo;
|
|
41
44
|
ticket: TicketRepo;
|
|
42
|
-
}
|
|
45
|
+
}, credentials: {
|
|
46
|
+
jwt: JWTCredentials;
|
|
47
|
+
}) => Promise<{
|
|
48
|
+
token: IToken;
|
|
49
|
+
}>;
|
|
43
50
|
declare function verifyToken(params: {
|
|
44
51
|
project: {
|
|
45
52
|
id: string;
|
|
@@ -51,5 +58,9 @@ declare function verifyToken(params: {
|
|
|
51
58
|
action?: ActionRepo;
|
|
52
59
|
authorization: AuthorizationRepo;
|
|
53
60
|
ticket: TicketRepo;
|
|
54
|
-
}
|
|
55
|
-
|
|
61
|
+
}, credentials: {
|
|
62
|
+
jwt: JWTCredentials;
|
|
63
|
+
}) => Promise<{
|
|
64
|
+
authorizedObject: IAuthorizedObject;
|
|
65
|
+
}>;
|
|
66
|
+
export { IPayload, getToken, verifyToken };
|
|
@@ -14,14 +14,17 @@ exports.verifyToken = exports.getToken = void 0;
|
|
|
14
14
|
* 承認サービス
|
|
15
15
|
*/
|
|
16
16
|
const jwt = require("jsonwebtoken");
|
|
17
|
-
const credentials_1 = require("../credentials");
|
|
18
17
|
const factory = require("../factory");
|
|
18
|
+
// type IPayloadWithNoVersion = factory.authorization.IObject & {
|
|
19
|
+
// version?: never;
|
|
20
|
+
// typ?: never;
|
|
21
|
+
// };
|
|
19
22
|
const ALGORITHM = 'HS256';
|
|
20
23
|
/**
|
|
21
24
|
* コードをトークンに変換する
|
|
22
25
|
*/
|
|
23
26
|
function getToken(params) {
|
|
24
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
return (repos, credentials) => __awaiter(this, void 0, void 0, function* () {
|
|
25
28
|
var _a;
|
|
26
29
|
if (typeof params.project.id !== 'string' || params.project.id.length === 0) {
|
|
27
30
|
throw new factory.errors.ArgumentNull('project.id');
|
|
@@ -37,7 +40,7 @@ function getToken(params) {
|
|
|
37
40
|
throw new factory.errors.ArgumentNull('issuer');
|
|
38
41
|
}
|
|
39
42
|
let subject = authorization.id;
|
|
40
|
-
let typ = `${
|
|
43
|
+
let typ = `${credentials.jwt.payloadTypPrefix}:${authorization.typeOf}`;
|
|
41
44
|
let jti;
|
|
42
45
|
if (params.useJti) {
|
|
43
46
|
const { id } = yield repos.ticket.issueByTicketToken(Object.assign({ project: { id: params.project.id }, ticketToken: params.code }, (typeof ((_a = authorization.issuedBy) === null || _a === void 0 ? void 0 : _a.id) === 'string') ? { issuedBy: authorization.issuedBy } : undefined));
|
|
@@ -45,26 +48,23 @@ function getToken(params) {
|
|
|
45
48
|
// ロール承認の場合、subjectはメンバーID,typはメンバータイプ
|
|
46
49
|
if (authorization.object.typeOf === factory.iam.RoleType.OrganizationRole) {
|
|
47
50
|
subject = authorization.object.member.id;
|
|
48
|
-
typ = `${
|
|
51
|
+
typ = `${credentials.jwt.payloadTypPrefix}:${authorization.object.member.typeOf}`;
|
|
49
52
|
}
|
|
50
53
|
else {
|
|
51
54
|
// useJtiの場合、subject,typはagent(2024-05-09~)
|
|
52
55
|
subject = params.agent.id;
|
|
53
|
-
typ = `${
|
|
56
|
+
typ = `${credentials.jwt.payloadTypPrefix}:${params.agent.typeOf}`;
|
|
54
57
|
}
|
|
55
58
|
}
|
|
56
|
-
// const isAuthorize4order: boolean = authorization.object.typeOf === factory.order.OrderType.Order;
|
|
57
59
|
const payload = {
|
|
58
|
-
// NO_VERSIONを廃止(2024-05-06~)
|
|
59
|
-
// ...(USE_TOKEN_WITH_NO_VERSION && isAuthorize4order) ? authorization.object : undefined,
|
|
60
60
|
// sub: authorization.id, // 拡張(2024-05-01~)
|
|
61
61
|
token_use: 'access',
|
|
62
|
-
version:
|
|
62
|
+
version: credentials.jwt.version,
|
|
63
63
|
typ // 拡張(2024-05-07~)
|
|
64
64
|
};
|
|
65
|
-
|
|
65
|
+
const token = yield new Promise((resolve, reject) => {
|
|
66
66
|
// 所有権を暗号化する
|
|
67
|
-
jwt.sign(payload,
|
|
67
|
+
jwt.sign(payload, credentials.jwt.secret, Object.assign(Object.assign({ algorithm: ALGORITHM,
|
|
68
68
|
// issuer: credentials.jwt.issuer,
|
|
69
69
|
issuer: params.issuer, expiresIn: params.expiresIn, subject }, (typeof params.audience === 'string') ? { audience: params.audience } : undefined), (typeof jti === 'string') ? { jwtid: jti } : undefined // 拡張(2024-05-08~)
|
|
70
70
|
), (err, encoded) => {
|
|
@@ -81,13 +81,69 @@ function getToken(params) {
|
|
|
81
81
|
}
|
|
82
82
|
});
|
|
83
83
|
});
|
|
84
|
+
return { token };
|
|
84
85
|
});
|
|
85
86
|
}
|
|
86
87
|
exports.getToken = getToken;
|
|
87
|
-
function
|
|
88
|
-
// tslint:disable-next-line:max-func-body-length
|
|
88
|
+
function payload2authorizeObject(params) {
|
|
89
89
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
90
|
-
|
|
90
|
+
const { payload } = params;
|
|
91
|
+
let authorizedObject;
|
|
92
|
+
// token.payloadが承認のケースに対応(2024-05-02~)
|
|
93
|
+
if (typeof payload.version === 'string') {
|
|
94
|
+
if (typeof payload.sub !== 'string' || payload.sub.length === 0) {
|
|
95
|
+
throw new factory.errors.Unauthorized(`invalid token [sub:${payload.sub}]`);
|
|
96
|
+
}
|
|
97
|
+
// discontinue purposeTokenに対応(2024-07-10~)
|
|
98
|
+
// sskts.purposeTokenに対応
|
|
99
|
+
// let resourceTypeByPayload: string | undefined;
|
|
100
|
+
// if (typeof payload.typ === 'string') {
|
|
101
|
+
// resourceTypeByPayload = payload.typ.split(`${credentials.jwt.payloadTypPrefix}:`)
|
|
102
|
+
// .at(1);
|
|
103
|
+
// }
|
|
104
|
+
// if (resourceTypeByPayload === factory.transactionType.PlaceOrder) {
|
|
105
|
+
// result = {
|
|
106
|
+
// id: payload.sub,
|
|
107
|
+
// typeOf: resourceTypeByPayload
|
|
108
|
+
// };
|
|
109
|
+
// } else {
|
|
110
|
+
// }
|
|
111
|
+
if (typeof payload.jti === 'string') {
|
|
112
|
+
// jtiに対応(2024-05-08~)
|
|
113
|
+
const ticket = (yield repos.ticket.search({
|
|
114
|
+
limit: 1,
|
|
115
|
+
page: 1,
|
|
116
|
+
project: { id: { $eq: params.project.id } },
|
|
117
|
+
id: { $eq: payload.jti }
|
|
118
|
+
})).shift();
|
|
119
|
+
if (ticket === undefined) {
|
|
120
|
+
throw new factory.errors.NotFound('Ticket');
|
|
121
|
+
}
|
|
122
|
+
// 承認を参照
|
|
123
|
+
const { object } = yield repos.authorization.findValidOneByCode({
|
|
124
|
+
project: { id: params.project.id },
|
|
125
|
+
code: ticket.ticketToken
|
|
126
|
+
});
|
|
127
|
+
authorizedObject = object;
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
// 基本的にはsubで承認を参照
|
|
131
|
+
const { object } = yield repos.authorization.findValidOneById({
|
|
132
|
+
project: { id: params.project.id },
|
|
133
|
+
id: payload.sub
|
|
134
|
+
});
|
|
135
|
+
authorizedObject = object;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
// NO_VERSIONを廃止(2024-05-06~)
|
|
140
|
+
throw new factory.errors.NotImplemented('USE_TOKEN_WITH_NO_VERSION discontinued');
|
|
141
|
+
}
|
|
142
|
+
return { authorizedObject };
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
function verifyToken(params) {
|
|
146
|
+
return (repos, credentials) => __awaiter(this, void 0, void 0, function* () {
|
|
91
147
|
let payload;
|
|
92
148
|
let action;
|
|
93
149
|
if (repos.action !== undefined) {
|
|
@@ -103,11 +159,12 @@ function verifyToken(params) {
|
|
|
103
159
|
action = (yield repos.action.start(actionAttributes));
|
|
104
160
|
}
|
|
105
161
|
try {
|
|
162
|
+
// payload = await new Promise<IPayloadWithNoVersion | IPayload>((resolve, reject) => {
|
|
106
163
|
payload = yield new Promise((resolve, reject) => {
|
|
107
|
-
jwt.verify(params.token,
|
|
164
|
+
jwt.verify(params.token, credentials.jwt.secret, Object.assign({ algorithms: [ALGORITHM],
|
|
108
165
|
// 互換性維持のために複数対応(2024-05-02~)
|
|
109
166
|
// issuer: credentials.jwt.issuer,
|
|
110
|
-
issuer:
|
|
167
|
+
issuer: credentials.jwt.issuers }, (Array.isArray(params.audience)) ? { audience: params.audience } : undefined), (err, decoded) => {
|
|
111
168
|
if (err instanceof Error) {
|
|
112
169
|
reject(err);
|
|
113
170
|
}
|
|
@@ -135,60 +192,7 @@ function verifyToken(params) {
|
|
|
135
192
|
if (repos.action !== undefined && action !== undefined) {
|
|
136
193
|
yield repos.action.completeWithVoid({ typeOf: action.typeOf, id: action.id, result: payload });
|
|
137
194
|
}
|
|
138
|
-
|
|
139
|
-
if (typeof payload.version === 'string') {
|
|
140
|
-
if (typeof payload.sub !== 'string' || payload.sub.length === 0) {
|
|
141
|
-
throw new factory.errors.Unauthorized(`invalid token [sub:${payload.sub}]`);
|
|
142
|
-
}
|
|
143
|
-
// sskts.purposeTokenに対応
|
|
144
|
-
let resourceTypeByPayload;
|
|
145
|
-
if (typeof payload.typ === 'string') {
|
|
146
|
-
resourceTypeByPayload = payload.typ.split(`${credentials_1.credentials.jwt.payloadTypPrefix}:`)
|
|
147
|
-
.at(1);
|
|
148
|
-
}
|
|
149
|
-
if (resourceTypeByPayload === factory.transactionType.PlaceOrder) {
|
|
150
|
-
result = {
|
|
151
|
-
id: payload.sub,
|
|
152
|
-
typeOf: resourceTypeByPayload
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
else if (typeof payload.jti === 'string') {
|
|
156
|
-
// jtiに対応(2024-05-08~)
|
|
157
|
-
const ticket = (yield repos.ticket.search({
|
|
158
|
-
limit: 1,
|
|
159
|
-
page: 1,
|
|
160
|
-
project: { id: { $eq: params.project.id } },
|
|
161
|
-
id: { $eq: payload.jti }
|
|
162
|
-
})).shift();
|
|
163
|
-
if (ticket === undefined) {
|
|
164
|
-
throw new factory.errors.NotFound('Ticket');
|
|
165
|
-
}
|
|
166
|
-
// 承認を参照
|
|
167
|
-
const { object } = yield repos.authorization.findValidOneByCode({
|
|
168
|
-
project: { id: params.project.id },
|
|
169
|
-
code: ticket.ticketToken
|
|
170
|
-
});
|
|
171
|
-
result = object;
|
|
172
|
-
}
|
|
173
|
-
else {
|
|
174
|
-
// 基本的にはsubで承認を参照
|
|
175
|
-
const { object } = yield repos.authorization.findValidOneById({
|
|
176
|
-
project: { id: params.project.id },
|
|
177
|
-
id: payload.sub
|
|
178
|
-
});
|
|
179
|
-
result = object;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
else {
|
|
183
|
-
// NO_VERSIONを廃止(2024-05-06~)
|
|
184
|
-
throw new factory.errors.NotImplemented('USE_TOKEN_WITH_NO_VERSION discontinued');
|
|
185
|
-
// if (USE_TOKEN_WITH_NO_VERSION) {
|
|
186
|
-
// result = payload;
|
|
187
|
-
// } else {
|
|
188
|
-
// throw new factory.errors.NotImplemented('USE_TOKEN_WITH_NO_VERSION not implemented');
|
|
189
|
-
// }
|
|
190
|
-
}
|
|
191
|
-
return result;
|
|
195
|
+
return payload2authorizeObject({ payload, project: { id: params.project.id } })(repos);
|
|
192
196
|
});
|
|
193
197
|
}
|
|
194
198
|
exports.verifyToken = verifyToken;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as factory from '../../../../factory';
|
|
2
|
+
import type { JWTCredentials } from '../../../../credentials/jwt';
|
|
2
3
|
import type { ActionRepo } from '../../../../repo/action';
|
|
3
4
|
import type { AssetTransactionRepo } from '../../../../repo/assetTransaction';
|
|
4
5
|
import type { AuthorizationRepo } from '../../../../repo/authorization';
|
|
@@ -48,6 +49,8 @@ declare function processStartReserve4chevre(params: {
|
|
|
48
49
|
task: TaskRepo;
|
|
49
50
|
ticket: TicketRepo;
|
|
50
51
|
assetTransaction: AssetTransactionRepo;
|
|
52
|
+
}, credentials: {
|
|
53
|
+
jwt: JWTCredentials;
|
|
51
54
|
}) => Promise<{
|
|
52
55
|
acceptedOffers4result: factory.action.authorize.offer.eventService.IResultAcceptedOffer[];
|
|
53
56
|
}>;
|
|
@@ -15,7 +15,7 @@ const ReserveTransactionService = require("../../../assetTransaction/reserve");
|
|
|
15
15
|
const CodeService = require("../../../code");
|
|
16
16
|
const factory_1 = require("./factory");
|
|
17
17
|
function processStartReserve4chevre(params) {
|
|
18
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
return (repos, credentials) => __awaiter(this, void 0, void 0, function* () {
|
|
19
19
|
const { event, transaction, transactionNumber } = params;
|
|
20
20
|
let acceptedOffers4result = [];
|
|
21
21
|
// 予約取引開始
|
|
@@ -23,7 +23,7 @@ function processStartReserve4chevre(params) {
|
|
|
23
23
|
// object: <IObjectWithDetail>action.object,
|
|
24
24
|
acceptedOffers: params.acceptedOffers, event: { id: event.id }, transaction,
|
|
25
25
|
transactionNumber }, (params.broker !== undefined) ? { broker: params.broker } : undefined));
|
|
26
|
-
const startParamObject = yield validateObjectWithoutDetail(startParams)(repos);
|
|
26
|
+
const startParamObject = yield validateObjectWithoutDetail(startParams)(repos, credentials);
|
|
27
27
|
const startReserveTransactionResult = yield ReserveTransactionService.start(Object.assign(Object.assign({}, startParams), { object: startParamObject, preSearchedEvent: event, preSearchedTicketOffers: params.ticketOffers, preSearchedUnitPriceOffers: params.unitPriceOffers, availableAtOrFrom: { id: params.availableAtOrFrom.id }, validateEvent: params.validateEvent, validateEventOfferPeriod: params.validateEventOfferPeriod, validateAppliesToMovieTicket: true,
|
|
28
28
|
// useHoldStockByTransactionNumber: params.useHoldStockByTransactionNumber, // discontinue(2024-07-02~)
|
|
29
29
|
stockHoldUntilDaysAfterEventEnd: params.stockHoldUntilDaysAfterEventEnd }))(repos);
|
|
@@ -42,7 +42,7 @@ function processStartReserve4chevre(params) {
|
|
|
42
42
|
}
|
|
43
43
|
exports.processStartReserve4chevre = processStartReserve4chevre;
|
|
44
44
|
function validateObjectWithoutDetail(params) {
|
|
45
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
return (repos, credentials) => __awaiter(this, void 0, void 0, function* () {
|
|
46
46
|
var _a, _b, _c, _d;
|
|
47
47
|
const objectWithoutDetail = params.object;
|
|
48
48
|
if (Array.isArray(objectWithoutDetail.acceptedOffer)) {
|
|
@@ -51,11 +51,12 @@ function validateObjectWithoutDetail(params) {
|
|
|
51
51
|
let programMembershipUsed = (_b = (_a = acceptedOffer.itemOffered) === null || _a === void 0 ? void 0 : _a.serviceOutput) === null || _b === void 0 ? void 0 : _b.programMembershipUsed;
|
|
52
52
|
// トークン化されたメンバーシップがリクエストされた場合、実メンバーシップ情報へ変換する
|
|
53
53
|
if (typeof programMembershipUsed === 'string' && programMembershipUsed.length > 0) {
|
|
54
|
-
const
|
|
54
|
+
const { authorizedObject } = yield CodeService.verifyToken({
|
|
55
55
|
project: params.project,
|
|
56
56
|
agent: params.project,
|
|
57
57
|
token: String(programMembershipUsed)
|
|
58
|
-
})(repos);
|
|
58
|
+
})(repos, credentials);
|
|
59
|
+
const permitOwnershipInfo = authorizedObject;
|
|
59
60
|
if (Array.isArray(permitOwnershipInfo)) {
|
|
60
61
|
throw new factory.errors.NotImplemented('programMembershipUsed as an array not implemented');
|
|
61
62
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as factory from '../../../factory';
|
|
2
|
+
import type { JWTCredentials } from '../../../credentials/jwt';
|
|
2
3
|
import type { ActionRepo } from '../../../repo/action';
|
|
3
4
|
import type { AssetTransactionRepo } from '../../../repo/assetTransaction';
|
|
4
5
|
import type { AuthorizationRepo } from '../../../repo/authorization';
|
|
@@ -43,7 +44,9 @@ interface IAuthorizeRepos {
|
|
|
43
44
|
transaction: TransactionRepo;
|
|
44
45
|
transactionNumber: TransactionNumberRepo;
|
|
45
46
|
}
|
|
46
|
-
type IAuthorizeOperation<T> = (repos: IAuthorizeRepos
|
|
47
|
+
type IAuthorizeOperation<T> = (repos: IAuthorizeRepos, credentials: {
|
|
48
|
+
jwt: JWTCredentials;
|
|
49
|
+
}) => Promise<T>;
|
|
47
50
|
type IAuthorizeOfferAction = factory.action.authorize.offer.eventService.IAction<factory.service.webAPI.Identifier>;
|
|
48
51
|
type IObjectWithoutDetail = factory.action.authorize.offer.eventService.IObjectWithoutDetail<factory.service.webAPI.Identifier.Chevre>;
|
|
49
52
|
/**
|
|
@@ -20,7 +20,7 @@ const searchEventTicketOffers_1 = require("./searchEventTicketOffers");
|
|
|
20
20
|
* 興行オファー承認
|
|
21
21
|
*/
|
|
22
22
|
function authorize(params) {
|
|
23
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
return (repos, credentials) => __awaiter(this, void 0, void 0, function* () {
|
|
24
24
|
var _a;
|
|
25
25
|
const noOfferSpecified = params.noOfferSpecified === true;
|
|
26
26
|
const { transaction, event } = yield validateCreateRequest(params)(repos);
|
|
@@ -44,7 +44,7 @@ function authorize(params) {
|
|
|
44
44
|
const processStartReserveResult = yield (0, processStartReserve4chevre_1.processStartReserve4chevre)(Object.assign({ acceptedOffers, event,
|
|
45
45
|
transactionNumber, transaction, availableAtOrFrom: { id: params.store.id }, ticketOffers, unitPriceOffers, validateEvent: params.validateEvent === true, validateEventOfferPeriod: params.validateEventOfferPeriod === true,
|
|
46
46
|
// useHoldStockByTransactionNumber: params.useHoldStockByTransactionNumber, // discontinue(2024-07-02~)
|
|
47
|
-
stockHoldUntilDaysAfterEventEnd: params.stockHoldUntilDaysAfterEventEnd }, (typeof ((_a = params.object.broker) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string') ? { broker: params.object.broker } : undefined))(repos);
|
|
47
|
+
stockHoldUntilDaysAfterEventEnd: params.stockHoldUntilDaysAfterEventEnd }, (typeof ((_a = params.object.broker) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string') ? { broker: params.object.broker } : undefined))(repos, credentials);
|
|
48
48
|
acceptedOffers4result = processStartReserveResult.acceptedOffers4result;
|
|
49
49
|
// add orderInTransaction(2024-01-15~)
|
|
50
50
|
if (!noOfferSpecified) {
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* 汎用決済サービス
|
|
3
3
|
*/
|
|
4
4
|
import * as factory from '../../factory';
|
|
5
|
+
import type { JWTCredentials } from '../../credentials/jwt';
|
|
5
6
|
import type { AccountingReportRepo } from '../../repo/accountingReport';
|
|
6
7
|
import type { ActionRepo, IMinimizedPurchaseNumberAuthResult } from '../../repo/action';
|
|
7
8
|
import type { AssetTransactionRepo } from '../../repo/assetTransaction';
|
|
@@ -87,7 +88,9 @@ interface IAuthorizeRepos {
|
|
|
87
88
|
transactionNumber: TransactionNumberRepo;
|
|
88
89
|
transactionProcess: TransactionProcessRepo;
|
|
89
90
|
}
|
|
90
|
-
type IAuthorizeOperation<T> = (repos: IAuthorizeRepos
|
|
91
|
+
type IAuthorizeOperation<T> = (repos: IAuthorizeRepos, credentials: {
|
|
92
|
+
jwt: JWTCredentials;
|
|
93
|
+
}) => Promise<T>;
|
|
91
94
|
interface IPublishPaymentUrlRepos {
|
|
92
95
|
action: ActionRepo;
|
|
93
96
|
assetTransaction: AssetTransactionRepo;
|
|
@@ -302,7 +302,7 @@ function minimizeObjectIncludingPaymentMethodDetails(authorizeObjectIncludingPay
|
|
|
302
302
|
*/
|
|
303
303
|
function authorize(params) {
|
|
304
304
|
// tslint:disable-next-line:cyclomatic-complexity max-func-body-length
|
|
305
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
305
|
+
return (repos, credentials) => __awaiter(this, void 0, void 0, function* () {
|
|
306
306
|
var _a, _b;
|
|
307
307
|
if (params.purpose.typeOf !== factory.transactionType.PlaceOrder) {
|
|
308
308
|
throw new factory.errors.NotImplemented(`purpose.typeOf '${params.purpose.typeOf} not implemented'`);
|
|
@@ -352,7 +352,9 @@ function authorize(params) {
|
|
|
352
352
|
transactionNumber = publishTransactionNumberResult.transactionNumber;
|
|
353
353
|
}
|
|
354
354
|
const movieTickets = (Array.isArray(params.object.movieTickets)) ? params.object.movieTickets.map(factory_1.createMovieTicket) : undefined;
|
|
355
|
-
const { accountId } = yield fixAccountIdIfPossible({
|
|
355
|
+
const { accountId } = yield fixAccountIdIfPossible({
|
|
356
|
+
object: params.object, project: { id: transaction.project.id }
|
|
357
|
+
})(repos, credentials);
|
|
356
358
|
const authorizeObjectIncludingPaymentMethodDetails = Object.assign(Object.assign(Object.assign(Object.assign({}, params.object), { accountId, paymentMethodId: transactionNumber, typeOf: factory.action.authorize.paymentMethod.any.ResultType.Payment }), (creditCard !== undefined) ? { creditCard } : undefined), (Array.isArray(movieTickets)) ? { movieTickets } : undefined);
|
|
357
359
|
const { authorizeObject } = minimizeObjectIncludingPaymentMethodDetails(authorizeObjectIncludingPaymentMethodDetails);
|
|
358
360
|
// 承認アクションを開始する
|
|
@@ -428,7 +430,7 @@ exports.authorize = authorize;
|
|
|
428
430
|
* 承認しようとしているobjectからaccountIdを決定する
|
|
429
431
|
*/
|
|
430
432
|
function fixAccountIdIfPossible(params) {
|
|
431
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
433
|
+
return (repos, credentials) => __awaiter(this, void 0, void 0, function* () {
|
|
432
434
|
var _a, _b;
|
|
433
435
|
// let accountId = params.object?.accountId;
|
|
434
436
|
let accountId = '';
|
|
@@ -436,11 +438,12 @@ function fixAccountIdIfPossible(params) {
|
|
|
436
438
|
const movieTickets = (_b = params.object) === null || _b === void 0 ? void 0 : _b.movieTickets;
|
|
437
439
|
// トークン化されたペイメントカード情報でリクエストされた場合、実ペイメントカード情報へ変換する
|
|
438
440
|
if (typeof fromLocation === 'string') {
|
|
439
|
-
const
|
|
441
|
+
const { authorizedObject } = yield (0, code_1.verifyToken)({
|
|
440
442
|
project: { id: params.project.id },
|
|
441
443
|
agent: { id: params.project.id, typeOf: factory.organizationType.Project },
|
|
442
444
|
token: fromLocation
|
|
443
|
-
})(repos);
|
|
445
|
+
})(repos, credentials);
|
|
446
|
+
const paymentCardOwnershipInfo = authorizedObject;
|
|
444
447
|
if (Array.isArray(paymentCardOwnershipInfo)) {
|
|
445
448
|
throw new factory.errors.NotImplemented('fromLocation as an array not implemented');
|
|
446
449
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { JWTCredentials } from '../../credentials/jwt';
|
|
1
2
|
import * as factory from '../../factory';
|
|
2
3
|
import type { AuthorizationRepo } from '../../repo/authorization';
|
|
3
4
|
import type { OrderRepo } from '../../repo/order';
|
|
@@ -28,4 +29,6 @@ export declare function verifyToken4reservation(params: {
|
|
|
28
29
|
authorization: AuthorizationRepo;
|
|
29
30
|
order: OrderRepo;
|
|
30
31
|
ticket: TicketRepo;
|
|
32
|
+
}, credentials: {
|
|
33
|
+
jwt: JWTCredentials;
|
|
31
34
|
}) => Promise<void>;
|
|
@@ -16,16 +16,17 @@ const code_1 = require("../code");
|
|
|
16
16
|
* 予約使用のためのチケットトークンを検証する
|
|
17
17
|
*/
|
|
18
18
|
function verifyToken4reservation(params) {
|
|
19
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
return (repos, credentials) => __awaiter(this, void 0, void 0, function* () {
|
|
20
20
|
// JWTと承認コードの両方に対応する(2024-02-28~)
|
|
21
21
|
const { token, ticketToken } = params.ticket;
|
|
22
22
|
let payload;
|
|
23
23
|
if (typeof token === 'string' && token.length > 0) {
|
|
24
|
-
|
|
24
|
+
const { authorizedObject } = yield (0, code_1.verifyToken)({
|
|
25
25
|
project: params.project,
|
|
26
26
|
agent: params.agent,
|
|
27
27
|
token
|
|
28
|
-
})(repos);
|
|
28
|
+
})(repos, credentials);
|
|
29
|
+
payload = authorizedObject;
|
|
29
30
|
}
|
|
30
31
|
else if (typeof ticketToken === 'string' && ticketToken.length > 0) {
|
|
31
32
|
const findValidOneByCodeResult = yield repos.authorization.findValidOneByCode({
|
|
@@ -32,35 +32,39 @@ const any_1 = require("../payment/any");
|
|
|
32
32
|
*/
|
|
33
33
|
function call(params) {
|
|
34
34
|
return (settings, options) => __awaiter(this, void 0, void 0, function* () {
|
|
35
|
-
|
|
35
|
+
const { connection, redisClient, jwtCredentials } = settings;
|
|
36
|
+
if (redisClient === undefined) {
|
|
36
37
|
throw new factory.errors.Argument('settings', 'redisClient required');
|
|
37
38
|
}
|
|
39
|
+
if (jwtCredentials === undefined) {
|
|
40
|
+
throw new factory.errors.Argument('settings', 'jwtCredentials required');
|
|
41
|
+
}
|
|
38
42
|
// 遅延実行(executeByName)には対応しない
|
|
39
43
|
if (!options.executeById) {
|
|
40
44
|
return;
|
|
41
45
|
}
|
|
42
46
|
let callResult;
|
|
43
|
-
const actionRepo = new action_1.ActionRepo(
|
|
44
|
-
const transactionProcessRepo = new transactionProcess_1.TransactionProcessRepo(
|
|
47
|
+
const actionRepo = new action_1.ActionRepo(connection);
|
|
48
|
+
const transactionProcessRepo = new transactionProcess_1.TransactionProcessRepo(redisClient, { lockExpiresInSeconds: 120 });
|
|
45
49
|
try {
|
|
46
50
|
yield (0, any_1.authorize)(Object.assign(Object.assign({}, params.data), { sameAs: { id: params.id } // タスクIDを関連付け(2024-04-20~)
|
|
47
51
|
}))({
|
|
48
|
-
accountingReport: new accountingReport_1.AccountingReportRepo(
|
|
52
|
+
accountingReport: new accountingReport_1.AccountingReportRepo(connection),
|
|
49
53
|
action: actionRepo,
|
|
50
|
-
assetTransaction: new assetTransaction_1.AssetTransactionRepo(
|
|
51
|
-
authorization: new authorization_1.AuthorizationRepo(
|
|
52
|
-
confirmationNumber: new confirmationNumber_1.ConfirmationNumberRepo(
|
|
53
|
-
event: new event_1.EventRepo(
|
|
54
|
-
paymentAccepted: new sellerPaymentAccepted_1.SellerPaymentAcceptedRepo(
|
|
55
|
-
paymentService: new paymentService_1.PaymentServiceRepo(
|
|
56
|
-
paymentServiceProvider: new paymentServiceProvider_1.PaymentServiceProviderRepo(
|
|
57
|
-
product: new product_1.ProductRepo(
|
|
58
|
-
task: new task_1.TaskRepo(
|
|
59
|
-
ticket: new ticket_1.TicketRepo(
|
|
60
|
-
transaction: new transaction_1.TransactionRepo(
|
|
61
|
-
transactionNumber: new transactionNumber_1.TransactionNumberRepo(
|
|
54
|
+
assetTransaction: new assetTransaction_1.AssetTransactionRepo(connection),
|
|
55
|
+
authorization: new authorization_1.AuthorizationRepo(connection),
|
|
56
|
+
confirmationNumber: new confirmationNumber_1.ConfirmationNumberRepo(redisClient),
|
|
57
|
+
event: new event_1.EventRepo(connection),
|
|
58
|
+
paymentAccepted: new sellerPaymentAccepted_1.SellerPaymentAcceptedRepo(connection),
|
|
59
|
+
paymentService: new paymentService_1.PaymentServiceRepo(connection),
|
|
60
|
+
paymentServiceProvider: new paymentServiceProvider_1.PaymentServiceProviderRepo(connection),
|
|
61
|
+
product: new product_1.ProductRepo(connection),
|
|
62
|
+
task: new task_1.TaskRepo(connection),
|
|
63
|
+
ticket: new ticket_1.TicketRepo(connection),
|
|
64
|
+
transaction: new transaction_1.TransactionRepo(connection),
|
|
65
|
+
transactionNumber: new transactionNumber_1.TransactionNumberRepo(redisClient),
|
|
62
66
|
transactionProcess: transactionProcessRepo
|
|
63
|
-
});
|
|
67
|
+
}, { jwt: jwtCredentials });
|
|
64
68
|
}
|
|
65
69
|
catch (error) {
|
|
66
70
|
let throwsError = true;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Connection } from 'mongoose';
|
|
2
2
|
import type { RedisClientType } from 'redis';
|
|
3
|
+
import { JWTCredentials } from '../credentials/jwt';
|
|
3
4
|
import * as factory from '../factory';
|
|
4
5
|
import type { IExecutableTask, IExecutableTaskKeys, TaskRepo } from '../repo/task';
|
|
5
6
|
interface IConnectionSettings {
|
|
@@ -11,6 +12,7 @@ interface IConnectionSettings {
|
|
|
11
12
|
* Redisクライアント
|
|
12
13
|
*/
|
|
13
14
|
redisClient?: RedisClientType;
|
|
15
|
+
jwtCredentials?: JWTCredentials;
|
|
14
16
|
}
|
|
15
17
|
interface IExecuteOptions {
|
|
16
18
|
executeById: boolean;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { JWTCredentials } from '../../credentials/jwt';
|
|
1
2
|
import type { ActionRepo } from '../../repo/action';
|
|
2
3
|
import type { AssetTransactionRepo } from '../../repo/assetTransaction';
|
|
3
4
|
import type { AuthorizationRepo } from '../../repo/authorization';
|
|
@@ -24,7 +25,9 @@ export interface IStartOperationRepos {
|
|
|
24
25
|
transactionNumber: TransactionNumberRepo;
|
|
25
26
|
assetTransaction: AssetTransactionRepo;
|
|
26
27
|
}
|
|
27
|
-
export type IStartOperation<T> = (repos: IStartOperationRepos
|
|
28
|
+
export type IStartOperation<T> = (repos: IStartOperationRepos, credentials: {
|
|
29
|
+
jwt: JWTCredentials;
|
|
30
|
+
}) => Promise<T>;
|
|
28
31
|
export type ITaskAndTransactionOperation<T> = (repos: {
|
|
29
32
|
task: TaskRepo;
|
|
30
33
|
transaction: TransactionRepo;
|
|
@@ -48,6 +51,8 @@ export type IAuthorizeOperation<T> = (repos: {
|
|
|
48
51
|
ticket: TicketRepo;
|
|
49
52
|
transaction: TransactionRepo;
|
|
50
53
|
assetTransaction: AssetTransactionRepo;
|
|
54
|
+
}, credentials: {
|
|
55
|
+
jwt: JWTCredentials;
|
|
51
56
|
}) => Promise<T>;
|
|
52
57
|
/**
|
|
53
58
|
* 取引確定
|
|
@@ -26,7 +26,7 @@ const CodeService = require("../code");
|
|
|
26
26
|
* 通貨転送資産取引サービスを利用して転送取引を開始する
|
|
27
27
|
*/
|
|
28
28
|
function start(params) {
|
|
29
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
return (repos, credentials) => __awaiter(this, void 0, void 0, function* () {
|
|
30
30
|
const { passport } = yield repos.passport.validatePassportTokenIfExist(params);
|
|
31
31
|
const sellers = yield repos.seller.search({
|
|
32
32
|
limit: 1,
|
|
@@ -54,7 +54,7 @@ function start(params) {
|
|
|
54
54
|
transaction = yield repos.transaction.start(startParams);
|
|
55
55
|
yield authorizePaymentCard({
|
|
56
56
|
transaction: Object.assign(Object.assign({}, transaction), { object: startParams.object, seller: startParams.seller, agent: startParams.agent, project: startParams.project, typeOf: startParams.typeOf })
|
|
57
|
-
})(repos);
|
|
57
|
+
})(repos, credentials);
|
|
58
58
|
}
|
|
59
59
|
catch (error) {
|
|
60
60
|
throw error;
|
|
@@ -64,7 +64,7 @@ function start(params) {
|
|
|
64
64
|
}
|
|
65
65
|
exports.start = start;
|
|
66
66
|
function authorizePaymentCard(params) {
|
|
67
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
return (repos, credentials) => __awaiter(this, void 0, void 0, function* () {
|
|
68
68
|
var _a;
|
|
69
69
|
const transaction = params.transaction;
|
|
70
70
|
const fromLocation = transaction.object.fromLocation;
|
|
@@ -95,7 +95,7 @@ function authorizePaymentCard(params) {
|
|
|
95
95
|
: String((_a = transaction.seller.name) === null || _a === void 0 ? void 0 : _a.ja)
|
|
96
96
|
}, price: 0, priceCurrency: factory.priceCurrency.JPY }, (typeof transaction.object.description === 'string') ? { description: transaction.object.description } : undefined),
|
|
97
97
|
purpose: { typeOf: transaction.typeOf, id: transaction.id }
|
|
98
|
-
})(repos);
|
|
98
|
+
})(repos, credentials);
|
|
99
99
|
}
|
|
100
100
|
else {
|
|
101
101
|
throw new factory.errors.NotImplemented('Withdraw transaction not implemented');
|
|
@@ -160,7 +160,7 @@ function fixToLocation(params) {
|
|
|
160
160
|
* 口座取引は、出金取引あるいは転送取引のどちらかを選択できます
|
|
161
161
|
*/
|
|
162
162
|
function processAuthorizePaymentCard(params) {
|
|
163
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
163
|
+
return (repos, credentials) => __awaiter(this, void 0, void 0, function* () {
|
|
164
164
|
var _a;
|
|
165
165
|
const transaction = yield repos.transaction.findInProgressById({
|
|
166
166
|
typeOf: factory.transactionType.MoneyTransfer,
|
|
@@ -195,7 +195,7 @@ function processAuthorizePaymentCard(params) {
|
|
|
195
195
|
recipient: recipient,
|
|
196
196
|
transaction: transaction,
|
|
197
197
|
transactionNumber
|
|
198
|
-
})(repos);
|
|
198
|
+
})(repos, credentials);
|
|
199
199
|
// アクションにchevre取引情報を保管
|
|
200
200
|
yield repos.action.findByIdAndUpdate({
|
|
201
201
|
id: action.id,
|
|
@@ -276,7 +276,7 @@ function createAuthorizeMoneyTransferOfferActionAttributes(params) {
|
|
|
276
276
|
}
|
|
277
277
|
function processMoneyTransferTransaction(params) {
|
|
278
278
|
// tslint:disable-next-line:max-func-body-length
|
|
279
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
279
|
+
return (repos, credentials) => __awaiter(this, void 0, void 0, function* () {
|
|
280
280
|
var _a, _b;
|
|
281
281
|
let pendingTransaction;
|
|
282
282
|
const transaction = params.transaction;
|
|
@@ -304,7 +304,7 @@ function processMoneyTransferTransaction(params) {
|
|
|
304
304
|
throw new factory.errors.NotImplemented('Withdraw transaction not implemented');
|
|
305
305
|
}
|
|
306
306
|
else if (params.object.fromLocation !== undefined && params.object.itemOffered.toLocation !== undefined) {
|
|
307
|
-
const { fromLocation } = yield validateFromLocation({ id: params.project.id }, params.object.fromLocation, { id: issuedThroughId })(repos);
|
|
307
|
+
const { fromLocation } = yield validateFromLocation({ id: params.project.id }, params.object.fromLocation, { id: issuedThroughId })(repos, credentials);
|
|
308
308
|
const { toLocation } = yield validateToLocation({ id: params.project.id }, {
|
|
309
309
|
typeOf: factory.permit.PermitType.Permit,
|
|
310
310
|
identifier: params.object.itemOffered.toLocation.identifier,
|
|
@@ -369,16 +369,17 @@ function processMoneyTransferTransaction(params) {
|
|
|
369
369
|
});
|
|
370
370
|
}
|
|
371
371
|
function validateFromLocation(project, fromLocationBeforeStart, issuedThrough) {
|
|
372
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
372
|
+
return (repos, credentials) => __awaiter(this, void 0, void 0, function* () {
|
|
373
373
|
var _a, _b, _c;
|
|
374
374
|
let fromLocation = fromLocationBeforeStart;
|
|
375
375
|
// トークン化されたペイメントカード情報でリクエストされた場合、実ペイメントカード情報へ変換する
|
|
376
376
|
if (typeof fromLocation === 'string') {
|
|
377
|
-
const
|
|
377
|
+
const { authorizedObject } = yield CodeService.verifyToken({
|
|
378
378
|
project: { id: project.id },
|
|
379
379
|
agent: { id: project.id, typeOf: factory.organizationType.Project },
|
|
380
380
|
token: fromLocation
|
|
381
|
-
})(repos);
|
|
381
|
+
})(repos, credentials);
|
|
382
|
+
const paymentCardOwnershipInfo = authorizedObject;
|
|
382
383
|
if (Array.isArray(paymentCardOwnershipInfo)) {
|
|
383
384
|
throw new factory.errors.NotImplemented('fromLocation as an array not implemented');
|
|
384
385
|
}
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@aws-sdk/credential-providers": "3.433.0",
|
|
13
13
|
"@chevre/factory": "4.378.0-alpha.0",
|
|
14
|
-
"@cinerino/sdk": "
|
|
14
|
+
"@cinerino/sdk": "9.0.0-alpha.1",
|
|
15
15
|
"@motionpicture/coa-service": "9.4.0",
|
|
16
16
|
"@motionpicture/gmo-service": "5.3.0",
|
|
17
17
|
"@sendgrid/mail": "6.4.0",
|
|
@@ -110,5 +110,5 @@
|
|
|
110
110
|
"postversion": "git push origin --tags",
|
|
111
111
|
"prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
|
|
112
112
|
},
|
|
113
|
-
"version": "22.0.0-alpha.
|
|
113
|
+
"version": "22.0.0-alpha.3"
|
|
114
114
|
}
|