@chevre/domain 23.2.0-alpha.47 → 23.2.0-alpha.48
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/orderNumber/testRandomness.ts +10 -4
- package/example/src/chevre/settings/addSettings.ts +7 -2
- package/lib/chevre/repo/mongoose/schemas/setting.d.ts +3 -1
- package/lib/chevre/repo/orderNumber.d.ts +1 -0
- package/lib/chevre/repo/orderNumber.js +26 -10
- package/lib/chevre/repo/transactionNumber.js +9 -18
- package/package.json +1 -1
|
@@ -25,10 +25,16 @@ async function testGeneration() {
|
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
// 復号して元のデータに戻るかチェック
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
.
|
|
28
|
+
let decoded: string;
|
|
29
|
+
let isSuccess: boolean = false;
|
|
30
|
+
try {
|
|
31
|
+
decoded = await orderNumberRepo.decrypt(orderNumber);
|
|
32
|
+
isSuccess = decoded === `${ts.valueOf()}${(i + 1).toString()
|
|
33
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
34
|
+
.padStart(2, '0')}`;
|
|
35
|
+
} catch (error) {
|
|
36
|
+
decoded = error.message;
|
|
37
|
+
}
|
|
32
38
|
|
|
33
39
|
results.push({
|
|
34
40
|
timestamp: ts.valueOf()
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// tslint:disable:no-console
|
|
2
|
+
import * as moment from 'moment';
|
|
2
3
|
import * as mongoose from 'mongoose';
|
|
3
4
|
|
|
4
5
|
import { chevre } from '../../../../lib/index';
|
|
@@ -17,12 +18,14 @@ async function main() {
|
|
|
17
18
|
const setting = await settingRepo.findOne({ project: { id: { $eq: '*' } } }, ['orderNumber', 'transactionNumber']);
|
|
18
19
|
console.log(setting);
|
|
19
20
|
|
|
20
|
-
if (typeof setting?.orderNumber?.version !== 'string') {
|
|
21
|
+
if (typeof setting?.orderNumber?.version !== 'string' || !(setting?.orderNumber?.validFrom instanceof Date)) {
|
|
21
22
|
console.log('updating orderNumber...');
|
|
22
23
|
await settingRepo.updateByProject(
|
|
23
24
|
{ project: { id: { $eq: '*' } } },
|
|
24
25
|
{
|
|
25
26
|
orderNumber: {
|
|
27
|
+
validFrom: moment('2026-01-31T15:00:00Z')
|
|
28
|
+
.toDate(),
|
|
26
29
|
fpeSecret: FPE_SECRET,
|
|
27
30
|
version: 'A'
|
|
28
31
|
}
|
|
@@ -31,12 +34,14 @@ async function main() {
|
|
|
31
34
|
console.log('orderNumber updated.');
|
|
32
35
|
}
|
|
33
36
|
|
|
34
|
-
if (typeof setting?.transactionNumber?.version !== 'string') {
|
|
37
|
+
if (typeof setting?.transactionNumber?.version !== 'string' || !(setting?.transactionNumber?.validFrom instanceof Date)) {
|
|
35
38
|
console.log('updating orderNumber...');
|
|
36
39
|
await settingRepo.updateByProject(
|
|
37
40
|
{ project: { id: { $eq: '*' } } },
|
|
38
41
|
{
|
|
39
42
|
transactionNumber: {
|
|
43
|
+
validFrom: moment('2026-01-31T15:00:00Z')
|
|
44
|
+
.toDate(),
|
|
40
45
|
fpeSecret: FPE_SECRET,
|
|
41
46
|
version: '1'
|
|
42
47
|
}
|
|
@@ -111,16 +111,18 @@ export interface IJWTSetting {
|
|
|
111
111
|
algorithm: Algorithm;
|
|
112
112
|
}
|
|
113
113
|
export interface IOrderNumberSetting {
|
|
114
|
+
validFrom: Date;
|
|
114
115
|
/**
|
|
115
116
|
* fpe暗号鍵
|
|
116
117
|
*/
|
|
117
118
|
fpeSecret: string;
|
|
118
119
|
/**
|
|
119
|
-
* "
|
|
120
|
+
* "A"
|
|
120
121
|
*/
|
|
121
122
|
version: string;
|
|
122
123
|
}
|
|
123
124
|
export interface ITransactionNumberSetting {
|
|
125
|
+
validFrom: Date;
|
|
124
126
|
/**
|
|
125
127
|
* fpe暗号鍵
|
|
126
128
|
*/
|
|
@@ -44,12 +44,21 @@ class OrderNumberRepo {
|
|
|
44
44
|
// params.timestamp
|
|
45
45
|
// );
|
|
46
46
|
// }
|
|
47
|
+
static GENERATE_VERSION0(timestamp, seq) {
|
|
48
|
+
let orderNumber = `${timestamp}${seq}`;
|
|
49
|
+
// checkdigit
|
|
50
|
+
const cd = cdigit.luhn.compute(orderNumber);
|
|
51
|
+
orderNumber = fpe({ password: cd })
|
|
52
|
+
.encrypt(orderNumber);
|
|
53
|
+
orderNumber = `${cd}${orderNumber}`;
|
|
54
|
+
return orderNumber;
|
|
55
|
+
}
|
|
47
56
|
/**
|
|
48
57
|
* タイムスタンプから発行する
|
|
49
58
|
*/
|
|
50
59
|
publishByTimestamp(params) {
|
|
51
60
|
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
-
const { fpeSecret, version } = yield this.findSetting();
|
|
61
|
+
const { fpeSecret, version, validFrom } = yield this.findSetting();
|
|
53
62
|
const timestamp = moment(params.orderDate)
|
|
54
63
|
.valueOf()
|
|
55
64
|
.toString();
|
|
@@ -68,7 +77,9 @@ class OrderNumberRepo {
|
|
|
68
77
|
expires: dataFeedExpires
|
|
69
78
|
});
|
|
70
79
|
let orderNumber;
|
|
71
|
-
|
|
80
|
+
const useVersioning = validFrom instanceof Date && moment(validFrom)
|
|
81
|
+
.isSameOrBefore(params.orderDate);
|
|
82
|
+
if (typeof fpeSecret === 'string' && typeof version === 'string' && useVersioning) {
|
|
72
83
|
const transactionFactory = new transactionNumber_1.TransactionNumberFactory({ fpeSecret, version });
|
|
73
84
|
orderNumber = transactionFactory.generate(timestamp, incrReply);
|
|
74
85
|
orderNumber = `${projectPrefix.at(0)}${orderNumber}`;
|
|
@@ -82,12 +93,14 @@ class OrderNumberRepo {
|
|
|
82
93
|
].join(ORDER_NUMBER_SEPARATOR)}`;
|
|
83
94
|
}
|
|
84
95
|
else {
|
|
85
|
-
orderNumber =
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
orderNumber =
|
|
96
|
+
orderNumber = OrderNumberRepo.GENERATE_VERSION0(timestamp, incrReply);
|
|
97
|
+
orderNumber = `${projectPrefix}${orderNumber}`;
|
|
98
|
+
// orderNumber = `${timestamp}${incrReply}`;
|
|
99
|
+
// // checkdigit
|
|
100
|
+
// const cd = cdigit.luhn.compute(orderNumber);
|
|
101
|
+
// orderNumber = fpe({ password: cd })
|
|
102
|
+
// .encrypt(orderNumber);
|
|
103
|
+
// orderNumber = `${projectPrefix}${cd}${orderNumber}`;
|
|
91
104
|
orderNumber = `${[
|
|
92
105
|
// tslint:disable-next-line:no-magic-numbers
|
|
93
106
|
orderNumber.slice(0, 4),
|
|
@@ -128,14 +141,17 @@ class OrderNumberRepo {
|
|
|
128
141
|
if (setting === null || setting.orderNumber === undefined) {
|
|
129
142
|
return {};
|
|
130
143
|
}
|
|
131
|
-
const { fpeSecret, version } = setting.orderNumber;
|
|
144
|
+
const { fpeSecret, version, validFrom } = setting.orderNumber;
|
|
132
145
|
if (typeof fpeSecret !== 'string' || fpeSecret === '') {
|
|
133
146
|
throw new factory.errors.NotFound('setting.orderNumber.secret');
|
|
134
147
|
}
|
|
135
148
|
if (typeof version !== 'string' || version === '') {
|
|
136
149
|
throw new factory.errors.NotFound('setting.orderNumber.version');
|
|
137
150
|
}
|
|
138
|
-
|
|
151
|
+
if (!(validFrom instanceof Date)) {
|
|
152
|
+
throw new factory.errors.NotFound('setting.orderNumber.validFrom must be Date');
|
|
153
|
+
}
|
|
154
|
+
return { fpeSecret, version, validFrom };
|
|
139
155
|
});
|
|
140
156
|
}
|
|
141
157
|
}
|
|
@@ -32,7 +32,7 @@ class TransactionNumberRepo {
|
|
|
32
32
|
*/
|
|
33
33
|
publishByTimestamp(params) {
|
|
34
34
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
-
const { fpeSecret, version } = yield this.findSetting();
|
|
35
|
+
const { fpeSecret, version, validFrom } = yield this.findSetting();
|
|
36
36
|
const timestamp = moment(params.startDate)
|
|
37
37
|
.valueOf()
|
|
38
38
|
.toString();
|
|
@@ -49,23 +49,11 @@ class TransactionNumberRepo {
|
|
|
49
49
|
expires: dataFeedExpires
|
|
50
50
|
});
|
|
51
51
|
let transactionNumber;
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
const useVersioning = validFrom instanceof Date && moment(validFrom)
|
|
53
|
+
.isSameOrBefore(params.startDate);
|
|
54
|
+
if (typeof fpeSecret === 'string' && typeof version === 'string' && useVersioning) {
|
|
54
55
|
const transactionFactory = new transactionNumber_1.TransactionNumberFactory({ fpeSecret, version });
|
|
55
56
|
transactionNumber = transactionFactory.generate(timestamp, incrReply);
|
|
56
|
-
// // tslint:disable-next-line:no-magic-numbers
|
|
57
|
-
// const saltDigit = randomInt(0, 10);
|
|
58
|
-
// const saltStr = saltDigit.toString();
|
|
59
|
-
// secret = `${fpeSecret}${saltStr}`;
|
|
60
|
-
// const cipher = fpe2({ secret });
|
|
61
|
-
// // incrReplyが 0〜99 なら "00"〜"99" になり(15桁)
|
|
62
|
-
// // incrReplyが 100〜999 なら "100"〜"999" になる(16桁)
|
|
63
|
-
// const rawBody = `${timestamp}${incrReply.toString()
|
|
64
|
-
// // tslint:disable-next-line:no-magic-numbers
|
|
65
|
-
// .padStart(2, '0')}`;
|
|
66
|
-
// const encryptedBody = cipher.encrypt(rawBody);
|
|
67
|
-
// // ソルトを「あえて」2文字目に含める
|
|
68
|
-
// transactionNumber = `${version}${saltStr}${encryptedBody}`;
|
|
69
57
|
}
|
|
70
58
|
else {
|
|
71
59
|
transactionNumber = `${timestamp}${incrReply}`;
|
|
@@ -103,14 +91,17 @@ class TransactionNumberRepo {
|
|
|
103
91
|
if (setting === null || setting.transactionNumber === undefined) {
|
|
104
92
|
return {};
|
|
105
93
|
}
|
|
106
|
-
const { fpeSecret, version } = setting.transactionNumber;
|
|
94
|
+
const { fpeSecret, version, validFrom } = setting.transactionNumber;
|
|
107
95
|
if (typeof fpeSecret !== 'string' || fpeSecret === '') {
|
|
108
96
|
throw new factory.errors.NotFound('setting.transactionNumber.secret');
|
|
109
97
|
}
|
|
110
98
|
if (typeof version !== 'string' || version === '') {
|
|
111
99
|
throw new factory.errors.NotFound('setting.transactionNumber.version');
|
|
112
100
|
}
|
|
113
|
-
|
|
101
|
+
if (!(validFrom instanceof Date)) {
|
|
102
|
+
throw new factory.errors.NotFound('setting.transactionNumber.validFrom must be Date');
|
|
103
|
+
}
|
|
104
|
+
return { fpeSecret, version, validFrom };
|
|
114
105
|
});
|
|
115
106
|
}
|
|
116
107
|
}
|
package/package.json
CHANGED