@chevre/domain 21.2.0-alpha.3 → 21.2.0-alpha.4
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/lib/chevre/repo/confirmationNumber.js +1 -1
- package/lib/chevre/repo/rateLimit/offer.d.ts +3 -2
- package/lib/chevre/repo/rateLimit/offer.js +14 -14
- package/lib/chevre/repo/serviceOutputIdentifier.d.ts +3 -1
- package/lib/chevre/repo/serviceOutputIdentifier.js +23 -14
- package/lib/chevre/repo/transactionNumber.d.ts +3 -1
- package/lib/chevre/repo/transactionNumber.js +23 -14
- package/lib/chevre/settings.d.ts +1 -0
- package/lib/chevre/settings.js +5 -2
- package/package.json +1 -1
|
@@ -36,7 +36,7 @@ class RedisRepository {
|
|
|
36
36
|
static createKey(params) {
|
|
37
37
|
const useNewKey = params.orderDate instanceof Date
|
|
38
38
|
&& moment(params.orderDate)
|
|
39
|
-
.isSameOrAfter(settings_1.
|
|
39
|
+
.isSameOrAfter(settings_1.USE_NEW_CONFIRMATION_NUMBER_KEY_FROM);
|
|
40
40
|
if (useNewKey) {
|
|
41
41
|
return util.format('%s:%s', RedisRepository.REDIS_KEY_PREFIX_NEW, moment(params.orderDate)
|
|
42
42
|
.tz('Asia/Tokyo')
|
|
@@ -18,10 +18,11 @@ export interface IRateLimitKey {
|
|
|
18
18
|
* オファーレート制限リポジトリ
|
|
19
19
|
*/
|
|
20
20
|
export declare class RedisRepository {
|
|
21
|
-
static
|
|
21
|
+
private static readonly KEY_PREFIX_NEW;
|
|
22
|
+
private static readonly KEY_PREFIX;
|
|
22
23
|
private readonly redisClient;
|
|
23
24
|
constructor(redisClient: RedisClientType);
|
|
24
|
-
static
|
|
25
|
+
private static createKey;
|
|
25
26
|
/**
|
|
26
27
|
* ロックする
|
|
27
28
|
*/
|
|
@@ -10,10 +10,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.RedisRepository = void 0;
|
|
13
|
-
const createDebug = require("debug");
|
|
14
13
|
const moment = require("moment");
|
|
15
14
|
const factory = require("../../factory");
|
|
16
|
-
const
|
|
15
|
+
const settings_1 = require("../../settings");
|
|
17
16
|
/**
|
|
18
17
|
* オファーレート制限リポジトリ
|
|
19
18
|
*/
|
|
@@ -21,11 +20,17 @@ class RedisRepository {
|
|
|
21
20
|
constructor(redisClient) {
|
|
22
21
|
this.redisClient = redisClient;
|
|
23
22
|
}
|
|
24
|
-
static
|
|
23
|
+
static createKey(ratelimitKey) {
|
|
25
24
|
const dateNow = moment(ratelimitKey.reservationFor.startDate);
|
|
26
25
|
const unitInSeconds = Number(ratelimitKey.reservedTicket.ticketType.validRateLimit.unitInSeconds.toString());
|
|
27
|
-
const validFrom = dateNow.unix() - dateNow.unix() % unitInSeconds;
|
|
28
|
-
|
|
26
|
+
const validFrom = dateNow.unix() - (dateNow.unix() % unitInSeconds);
|
|
27
|
+
const useNewKey = dateNow.isSameOrAfter(settings_1.USE_NEW_EVENT_AVAILABILITY_KEY_FROM);
|
|
28
|
+
if (useNewKey) {
|
|
29
|
+
return `${RedisRepository.KEY_PREFIX_NEW}:${ratelimitKey.reservedTicket.ticketType.validRateLimit.scope}:${validFrom.toString()}`;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
return `${RedisRepository.KEY_PREFIX}:${ratelimitKey.reservedTicket.ticketType.validRateLimit.scope}:${validFrom.toString()}`;
|
|
33
|
+
}
|
|
29
34
|
}
|
|
30
35
|
/**
|
|
31
36
|
* ロックする
|
|
@@ -34,7 +39,7 @@ class RedisRepository {
|
|
|
34
39
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
40
|
const datasets = ratelimitKeys.map((ratelimitKey) => {
|
|
36
41
|
return {
|
|
37
|
-
key: RedisRepository.
|
|
42
|
+
key: RedisRepository.createKey(ratelimitKey),
|
|
38
43
|
value: ratelimitKey.reservationNumber,
|
|
39
44
|
ttl: moment(ratelimitKey.reservationFor.startDate)
|
|
40
45
|
.add(ratelimitKey.reservedTicket.ticketType.validRateLimit.unitInSeconds, 'seconds')
|
|
@@ -43,29 +48,24 @@ class RedisRepository {
|
|
|
43
48
|
});
|
|
44
49
|
let multi = this.redisClient.multi();
|
|
45
50
|
datasets.forEach((dataset) => {
|
|
46
|
-
debug('setting if not exist...', dataset.key);
|
|
47
51
|
multi.setNX(dataset.key, dataset.value)
|
|
48
52
|
.expire(dataset.key, dataset.ttl);
|
|
49
53
|
});
|
|
50
54
|
const results = yield multi.exec();
|
|
51
55
|
const lockedFields = [];
|
|
52
56
|
results.forEach((r, index) => {
|
|
53
|
-
debug('r, index:', r, index);
|
|
54
57
|
// tslint:disable-next-line:no-magic-numbers
|
|
55
58
|
if (index % 2 === 0 && (r === 1 || r === true)) {
|
|
56
59
|
// tslint:disable-next-line:no-magic-numbers
|
|
57
60
|
lockedFields.push(datasets[index / 2].key);
|
|
58
61
|
}
|
|
59
62
|
});
|
|
60
|
-
debug('locked fields:', lockedFields);
|
|
61
63
|
const lockedAll = lockedFields.length === ratelimitKeys.length;
|
|
62
|
-
debug('lockedAll?', lockedAll);
|
|
63
64
|
if (!lockedAll) {
|
|
64
65
|
if (lockedFields.length > 0) {
|
|
65
66
|
// 全てロックできなければロックできたものは解除
|
|
66
67
|
multi = this.redisClient.multi();
|
|
67
68
|
lockedFields.forEach((key) => {
|
|
68
|
-
debug('deleting...', key);
|
|
69
69
|
multi.del(key);
|
|
70
70
|
});
|
|
71
71
|
yield multi.exec();
|
|
@@ -78,8 +78,7 @@ class RedisRepository {
|
|
|
78
78
|
return __awaiter(this, void 0, void 0, function* () {
|
|
79
79
|
const multi = this.redisClient.multi();
|
|
80
80
|
ratelimitKeys.forEach((ratelimitKey) => {
|
|
81
|
-
const key = RedisRepository.
|
|
82
|
-
debug('deleting...', key);
|
|
81
|
+
const key = RedisRepository.createKey(ratelimitKey);
|
|
83
82
|
multi.del(key);
|
|
84
83
|
});
|
|
85
84
|
yield multi.exec();
|
|
@@ -87,10 +86,11 @@ class RedisRepository {
|
|
|
87
86
|
}
|
|
88
87
|
getHolder(ratelimitKey) {
|
|
89
88
|
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
-
const key = RedisRepository.
|
|
89
|
+
const key = RedisRepository.createKey(ratelimitKey);
|
|
91
90
|
return this.redisClient.get(key);
|
|
92
91
|
});
|
|
93
92
|
}
|
|
94
93
|
}
|
|
94
|
+
RedisRepository.KEY_PREFIX_NEW = 'rateLimit:offer';
|
|
95
95
|
RedisRepository.KEY_PREFIX = 'chevre:rateLimit:offer';
|
|
96
96
|
exports.RedisRepository = RedisRepository;
|
|
@@ -3,9 +3,11 @@ import { RedisClientType } from 'redis';
|
|
|
3
3
|
* サービスアウトプット識別子リポジトリ
|
|
4
4
|
*/
|
|
5
5
|
export declare class RedisRepository {
|
|
6
|
-
static
|
|
6
|
+
private static readonly REDIS_KEY_PREFIX_NEW;
|
|
7
|
+
private static readonly REDIS_KEY_PREFIX;
|
|
7
8
|
private readonly redisClient;
|
|
8
9
|
constructor(redisClient: RedisClientType);
|
|
10
|
+
private static createKey;
|
|
9
11
|
/**
|
|
10
12
|
* タイムスタンプから発行する
|
|
11
13
|
*/
|
|
@@ -16,6 +16,7 @@ const util = require("util");
|
|
|
16
16
|
// tslint:disable-next-line:no-require-imports no-var-requires
|
|
17
17
|
const fpe = require('node-fpe');
|
|
18
18
|
const factory = require("../factory");
|
|
19
|
+
const settings_1 = require("../settings");
|
|
19
20
|
/**
|
|
20
21
|
* サービスアウトプット識別子リポジトリ
|
|
21
22
|
*/
|
|
@@ -23,6 +24,17 @@ class RedisRepository {
|
|
|
23
24
|
constructor(redisClient) {
|
|
24
25
|
this.redisClient = redisClient;
|
|
25
26
|
}
|
|
27
|
+
static createKey(params) {
|
|
28
|
+
const useNewKey = params.startDate instanceof Date
|
|
29
|
+
&& moment(params.startDate)
|
|
30
|
+
.isSameOrAfter(settings_1.USE_NEW_ORDER_NUMBER_KEY_FROM);
|
|
31
|
+
if (useNewKey) {
|
|
32
|
+
return util.format('%s:%s', RedisRepository.REDIS_KEY_PREFIX_NEW, params.timestamp);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
return util.format('%s:%s', RedisRepository.REDIS_KEY_PREFIX, params.timestamp);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
26
38
|
/**
|
|
27
39
|
* タイムスタンプから発行する
|
|
28
40
|
*/
|
|
@@ -35,30 +47,27 @@ class RedisRepository {
|
|
|
35
47
|
const TTL = moment(params.startDate)
|
|
36
48
|
.add(1, 'minute') // ミリ秒でカウントしていくので、予約日時後1分で十分
|
|
37
49
|
.diff(now, 'seconds');
|
|
38
|
-
const key =
|
|
50
|
+
const key = RedisRepository.createKey({ startDate: params.startDate, timestamp });
|
|
39
51
|
const [incrReply] = yield this.redisClient.multi()
|
|
40
52
|
.incr(key)
|
|
41
53
|
.expire(key, TTL)
|
|
42
54
|
.exec();
|
|
43
55
|
// tslint:disable-next-line:no-single-line-block-comment
|
|
44
56
|
/* istanbul ignore else: please write tests */
|
|
45
|
-
if (typeof incrReply
|
|
46
|
-
let identifier = timestamp;
|
|
47
|
-
const no = incrReply;
|
|
48
|
-
identifier = `${identifier}${no}`;
|
|
49
|
-
// checkdigit
|
|
50
|
-
const cd = cdigit.luhn.compute(identifier);
|
|
51
|
-
const cipher = fpe({ password: cd });
|
|
52
|
-
identifier = cipher.encrypt(identifier);
|
|
53
|
-
identifier = `${cd}${identifier}`;
|
|
54
|
-
return identifier;
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
+
if (typeof incrReply !== 'number') {
|
|
57
58
|
// 基本的にありえないフロー
|
|
58
|
-
throw new factory.errors.ServiceUnavailable('
|
|
59
|
+
throw new factory.errors.ServiceUnavailable('serviceOutput identifier not incremented unexpectedly');
|
|
59
60
|
}
|
|
61
|
+
let identifier = `${timestamp}${incrReply}`;
|
|
62
|
+
// checkdigit
|
|
63
|
+
const cd = cdigit.luhn.compute(identifier);
|
|
64
|
+
identifier = fpe({ password: cd })
|
|
65
|
+
.encrypt(identifier);
|
|
66
|
+
identifier = `${cd}${identifier}`;
|
|
67
|
+
return identifier;
|
|
60
68
|
});
|
|
61
69
|
}
|
|
62
70
|
}
|
|
71
|
+
RedisRepository.REDIS_KEY_PREFIX_NEW = 'serviceOutputIdentifier';
|
|
63
72
|
RedisRepository.REDIS_KEY_PREFIX = 'chevre:serviceOutputIdentifier';
|
|
64
73
|
exports.RedisRepository = RedisRepository;
|
|
@@ -6,9 +6,11 @@ interface IPublishResult {
|
|
|
6
6
|
* 取引番号リポジトリ
|
|
7
7
|
*/
|
|
8
8
|
export declare class RedisRepository {
|
|
9
|
-
static
|
|
9
|
+
private static readonly REDIS_KEY_PREFIX_NEW;
|
|
10
|
+
private static readonly REDIS_KEY_PREFIX;
|
|
10
11
|
private readonly redisClient;
|
|
11
12
|
constructor(redisClient: RedisClientType);
|
|
13
|
+
private static createKey;
|
|
12
14
|
/**
|
|
13
15
|
* タイムスタンプから発行する
|
|
14
16
|
*/
|
|
@@ -16,6 +16,7 @@ const util = require("util");
|
|
|
16
16
|
// tslint:disable-next-line:no-require-imports no-var-requires
|
|
17
17
|
const fpe = require('node-fpe');
|
|
18
18
|
const factory = require("../factory");
|
|
19
|
+
const settings_1 = require("../settings");
|
|
19
20
|
/**
|
|
20
21
|
* 取引番号リポジトリ
|
|
21
22
|
*/
|
|
@@ -23,6 +24,17 @@ class RedisRepository {
|
|
|
23
24
|
constructor(redisClient) {
|
|
24
25
|
this.redisClient = redisClient;
|
|
25
26
|
}
|
|
27
|
+
static createKey(params) {
|
|
28
|
+
const useNewKey = params.startDate instanceof Date
|
|
29
|
+
&& moment(params.startDate)
|
|
30
|
+
.isSameOrAfter(settings_1.USE_NEW_ORDER_NUMBER_KEY_FROM);
|
|
31
|
+
if (useNewKey) {
|
|
32
|
+
return util.format('%s:%s', RedisRepository.REDIS_KEY_PREFIX_NEW, params.timestamp);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
return util.format('%s:%s', RedisRepository.REDIS_KEY_PREFIX, params.timestamp);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
26
38
|
/**
|
|
27
39
|
* タイムスタンプから発行する
|
|
28
40
|
*/
|
|
@@ -35,30 +47,27 @@ class RedisRepository {
|
|
|
35
47
|
const TTL = moment(params.startDate)
|
|
36
48
|
.add(1, 'minute') // ミリ秒でカウントしていくので、予約日時後1分で十分
|
|
37
49
|
.diff(now, 'seconds');
|
|
38
|
-
const key =
|
|
50
|
+
const key = RedisRepository.createKey({ startDate: params.startDate, timestamp });
|
|
39
51
|
const [incrReply] = yield this.redisClient.multi()
|
|
40
52
|
.incr(key)
|
|
41
53
|
.expire(key, TTL)
|
|
42
54
|
.exec();
|
|
43
55
|
// tslint:disable-next-line:no-single-line-block-comment
|
|
44
56
|
/* istanbul ignore else: please write tests */
|
|
45
|
-
if (typeof incrReply
|
|
46
|
-
let transactionNumber = timestamp;
|
|
47
|
-
const no = incrReply;
|
|
48
|
-
transactionNumber = `${transactionNumber}${no}`;
|
|
49
|
-
// checkdigit
|
|
50
|
-
const cd = cdigit.luhn.compute(transactionNumber);
|
|
51
|
-
const cipher = fpe({ password: cd });
|
|
52
|
-
transactionNumber = cipher.encrypt(transactionNumber);
|
|
53
|
-
transactionNumber = `${cd}${transactionNumber}`;
|
|
54
|
-
return { transactionNumber };
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
+
if (typeof incrReply !== 'number') {
|
|
57
58
|
// 基本的にありえないフロー
|
|
58
|
-
throw new factory.errors.ServiceUnavailable('
|
|
59
|
+
throw new factory.errors.ServiceUnavailable('transaction number not incremented unexpectedly');
|
|
59
60
|
}
|
|
61
|
+
let transactionNumber = `${timestamp}${incrReply}`;
|
|
62
|
+
// checkdigit
|
|
63
|
+
const cd = cdigit.luhn.compute(transactionNumber);
|
|
64
|
+
transactionNumber = fpe({ password: cd })
|
|
65
|
+
.encrypt(transactionNumber);
|
|
66
|
+
transactionNumber = `${cd}${transactionNumber}`;
|
|
67
|
+
return { transactionNumber };
|
|
60
68
|
});
|
|
61
69
|
}
|
|
62
70
|
}
|
|
71
|
+
RedisRepository.REDIS_KEY_PREFIX_NEW = 'transactionNumber';
|
|
63
72
|
RedisRepository.REDIS_KEY_PREFIX = 'chevre:transactionNumber';
|
|
64
73
|
exports.RedisRepository = RedisRepository;
|
package/lib/chevre/settings.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ export declare const DEFAULT_PAYMENT_METHOD_TYPE_FOR_CREDIT_CARD: string;
|
|
|
30
30
|
export declare const USE_ASSET_TRANSACTION_SYNC_PROCESSING: boolean;
|
|
31
31
|
export declare const USE_PAY_ASSET_TRANSACTION_SYNC_PROCESSING: boolean;
|
|
32
32
|
export declare const USE_NEW_EVENT_AVAILABILITY_KEY_FROM: moment.Moment;
|
|
33
|
+
export declare const USE_NEW_CONFIRMATION_NUMBER_KEY_FROM: moment.Moment;
|
|
33
34
|
export declare const USE_NEW_ORDER_NUMBER_KEY_FROM: moment.Moment;
|
|
34
35
|
/**
|
|
35
36
|
* グローバル設定
|
package/lib/chevre/settings.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.settings = exports.USE_NEW_ORDER_NUMBER_KEY_FROM = exports.USE_NEW_EVENT_AVAILABILITY_KEY_FROM = exports.USE_PAY_ASSET_TRANSACTION_SYNC_PROCESSING = exports.USE_ASSET_TRANSACTION_SYNC_PROCESSING = exports.DEFAULT_PAYMENT_METHOD_TYPE_FOR_CREDIT_CARD = exports.DEFAULT_SENDER_EMAIL = exports.TRANSACTION_CANCELED_STORAGE_PERIOD_IN_DAYS = exports.TRANSACTION_CONFIRMED_STORAGE_PERIOD_IN_DAYS = exports.ASSET_TRANSACTION_STORAGE_PERIOD_IN_DAYS = exports.ABORTED_TASKS_WITHOUT_REPORT = void 0;
|
|
3
|
+
exports.settings = exports.USE_NEW_ORDER_NUMBER_KEY_FROM = exports.USE_NEW_CONFIRMATION_NUMBER_KEY_FROM = exports.USE_NEW_EVENT_AVAILABILITY_KEY_FROM = exports.USE_PAY_ASSET_TRANSACTION_SYNC_PROCESSING = exports.USE_ASSET_TRANSACTION_SYNC_PROCESSING = exports.DEFAULT_PAYMENT_METHOD_TYPE_FOR_CREDIT_CARD = exports.DEFAULT_SENDER_EMAIL = exports.TRANSACTION_CANCELED_STORAGE_PERIOD_IN_DAYS = exports.TRANSACTION_CONFIRMED_STORAGE_PERIOD_IN_DAYS = exports.ASSET_TRANSACTION_STORAGE_PERIOD_IN_DAYS = exports.ABORTED_TASKS_WITHOUT_REPORT = void 0;
|
|
4
4
|
const moment = require("moment");
|
|
5
5
|
const factory = require("./factory");
|
|
6
6
|
const transactionWebhookUrls = (typeof process.env.INFORM_TRANSACTION_URL === 'string')
|
|
@@ -49,9 +49,12 @@ exports.USE_PAY_ASSET_TRANSACTION_SYNC_PROCESSING = process.env.USE_PAY_ASSET_TR
|
|
|
49
49
|
exports.USE_NEW_EVENT_AVAILABILITY_KEY_FROM = (typeof process.env.USE_NEW_EVENT_AVAILABILITY_KEY_FROM === 'string')
|
|
50
50
|
? moment(process.env.USE_NEW_EVENT_AVAILABILITY_KEY_FROM)
|
|
51
51
|
: moment('2023-07-23T15:00:00Z');
|
|
52
|
+
exports.USE_NEW_CONFIRMATION_NUMBER_KEY_FROM = (typeof process.env.USE_NEW_CONFIRMATION_NUMBER_KEY_FROM === 'string')
|
|
53
|
+
? moment(process.env.USE_NEW_CONFIRMATION_NUMBER_KEY_FROM)
|
|
54
|
+
: moment('2023-04-30T15:00:00Z');
|
|
52
55
|
exports.USE_NEW_ORDER_NUMBER_KEY_FROM = (typeof process.env.USE_NEW_ORDER_NUMBER_KEY_FROM === 'string')
|
|
53
56
|
? moment(process.env.USE_NEW_ORDER_NUMBER_KEY_FROM)
|
|
54
|
-
: moment('2023-04-
|
|
57
|
+
: moment('2023-04-18T15:00:00Z');
|
|
55
58
|
/**
|
|
56
59
|
* グローバル設定
|
|
57
60
|
*/
|
package/package.json
CHANGED