@chevre/domain 22.10.0-alpha.9 → 22.11.0-alpha.0
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/adminAuth/adminIdentity.ts +38 -0
- package/example/src/chevre/adminIdentities.ts +8 -8
- package/example/src/chevre/assetTransaction/processReserve.ts +4 -1
- package/example/src/chevre/concurrentLock/lockOfferRateLimit.ts +64 -0
- package/example/src/chevre/concurrentLock/lockTransactionProcess.ts +44 -0
- package/example/src/chevre/createTaskIfNotExistByAlternateName.ts +1 -1
- package/example/src/chevre/findOneAvailableHours.ts +11 -11
- package/example/src/chevre/identity/getCommonClients.ts +126 -0
- package/example/src/chevre/identity/migrateClients2oauth.ts +200 -0
- package/example/src/chevre/issuer/adminMemberProgramTiers.ts +55 -0
- package/example/src/chevre/maintenance/checkTransactionStatuses.ts +105 -0
- package/example/src/chevre/migrateIdentities.ts +24 -37
- package/example/src/chevre/reIndex.ts +1 -1
- package/example/src/chevre/roles/addPermissionIfNotExists.ts +27 -0
- package/example/src/chevre/roles/addRoleMembers.ts +75 -0
- package/example/src/chevre/saveWebSite.ts +14 -17
- package/example/src/chevre/stockHolder/checkRedisKeyCount.ts +43 -22
- package/example/src/chevre/transactionNumber/publishConfimationNumber.ts +37 -0
- package/example/src/chevre/transactionNumber/publishOrderNumber.ts +40 -0
- package/example/src/chevre/transactionNumber/setUseMongo4confirmationNumberFrom.ts +45 -0
- package/example/src/chevre/transactionNumber/setUseMongo4orderNumberFrom.ts +41 -0
- package/example/src/chevre/transactionNumber/setUseMongo4transactionNumberFrom.ts +41 -0
- package/example/src/redisMulti.ts +63 -0
- package/example/src/signPayload.ts +1 -1
- package/lib/chevre/adminAuth.d.ts +2 -0
- package/lib/chevre/adminAuth.js +6 -0
- package/lib/chevre/eventEmitter/task.d.ts +36 -6
- package/lib/chevre/eventEmitter/task.js +5 -4
- package/lib/chevre/eventEmitter.d.ts +2 -2
- package/lib/chevre/eventEmitter.js +2 -2
- package/lib/chevre/index.d.ts +2 -0
- package/lib/chevre/index.js +10 -0
- package/lib/chevre/repo/concurrentLock.d.ts +14 -0
- package/lib/chevre/repo/concurrentLock.js +48 -0
- package/lib/chevre/repo/concurrentLockAbstract.d.ts +42 -0
- package/lib/chevre/repo/concurrentLockAbstract.js +9 -0
- package/lib/chevre/repo/confirmationNumber.d.ts +17 -4
- package/lib/chevre/repo/confirmationNumber.js +89 -32
- package/lib/chevre/repo/identity.d.ts +42 -5
- package/lib/chevre/repo/identity.js +35 -4
- package/lib/chevre/repo/issuer.d.ts +10 -2
- package/lib/chevre/repo/member.js +2 -2
- package/lib/chevre/repo/memberProgram.d.ts +43 -2
- package/lib/chevre/repo/memberProgram.js +79 -8
- package/lib/chevre/repo/mongoose/schemas/issuer.d.ts +3 -1
- package/lib/chevre/repo/mongoose/schemas/issuer.js +10 -0
- package/lib/chevre/repo/mongoose/schemas/offer/event.js +30 -2
- package/lib/chevre/repo/mongoose/schemas/role.d.ts +2 -3
- package/lib/chevre/repo/mongoose/schemas/role.js +11 -1
- package/lib/chevre/repo/mongoose/schemas/setting.d.ts +3 -0
- package/lib/chevre/repo/mongoose/schemas/setting.js +4 -1
- package/lib/chevre/repo/mongoose/schemas/transactionNumber.d.ts +39 -0
- package/lib/chevre/repo/mongoose/schemas/transactionNumber.js +101 -0
- package/lib/chevre/repo/orderNumber.d.ts +15 -4
- package/lib/chevre/repo/orderNumber.js +71 -24
- package/lib/chevre/repo/passport.d.ts +1 -1
- package/lib/chevre/repo/passport.js +31 -13
- package/lib/chevre/repo/rateLimit/offer.d.ts +7 -2
- package/lib/chevre/repo/rateLimit/offer.js +41 -40
- package/lib/chevre/repo/role.d.ts +18 -4
- package/lib/chevre/repo/role.js +53 -4
- package/lib/chevre/repo/serviceOutputIdentifier.d.ts +8 -4
- package/lib/chevre/repo/serviceOutputIdentifier.js +54 -22
- package/lib/chevre/repo/stockHolder.d.ts +0 -2
- package/lib/chevre/repo/stockHolder.js +24 -31
- package/lib/chevre/repo/task.d.ts +10 -25
- package/lib/chevre/repo/task.js +65 -36
- package/lib/chevre/repo/transactionNumber.d.ts +15 -4
- package/lib/chevre/repo/transactionNumber.js +67 -22
- package/lib/chevre/repo/transactionNumberCounter.d.ts +28 -0
- package/lib/chevre/repo/transactionNumberCounter.js +128 -0
- package/lib/chevre/repo/transactionProcess.d.ts +7 -4
- package/lib/chevre/repo/transactionProcess.js +34 -13
- package/lib/chevre/service/aggregation/event/aggregateOffers.js +1 -0
- package/lib/chevre/service/assetTransaction/reserve/start.js +9 -1
- package/lib/chevre/service/assetTransaction/reserve/validateStartRequest.js +1 -1
- package/lib/chevre/service/code.js +1 -1
- package/lib/chevre/service/offer/event/checkAvailability.d.ts +1 -1
- package/lib/chevre/service/offer/event/checkAvailability.js +1 -0
- package/lib/chevre/service/offer/product.js +0 -40
- package/lib/chevre/service/payment/any.d.ts +0 -2
- package/lib/chevre/service/payment/any.js +1 -0
- package/lib/chevre/service/reserve/cancelReservation.d.ts +3 -0
- package/lib/chevre/service/reserve/cancelReservation.js +5 -1
- package/lib/chevre/service/task/acceptCOAOffer.js +2 -2
- package/lib/chevre/service/task/authorizePayment.js +4 -4
- package/lib/chevre/service/task/givePointAward.js +1 -1
- package/lib/chevre/service/task/moneyTransfer.js +1 -1
- package/lib/chevre/service/task/publishPaymentUrl.js +2 -2
- package/lib/chevre/service/task/refund.js +1 -1
- package/lib/chevre/service/task/returnMoneyTransfer.js +1 -1
- package/lib/chevre/service/task/returnPayTransaction.js +1 -1
- package/lib/chevre/service/task/returnPointAward.js +1 -1
- package/lib/chevre/service/task/returnReserveTransaction.js +1 -1
- package/lib/chevre/service/task.d.ts +8 -17
- package/lib/chevre/service/task.js +14 -5
- package/lib/chevre/service/transaction/placeOrder/start/validateStartRequest.js +2 -2
- package/lib/chevre/service/transaction/returnOrder/preStart/factory.d.ts +20 -0
- package/lib/chevre/service/transaction/returnOrder/preStart/factory.js +2 -0
- package/lib/chevre/service/transaction/returnOrder/preStart/findApplicableReturnPolicy.d.ts +23 -0
- package/lib/chevre/service/transaction/returnOrder/preStart/findApplicableReturnPolicy.js +323 -0
- package/lib/chevre/service/transaction/returnOrder/preStart/getReturnPolicyByProject.d.ts +13 -0
- package/lib/chevre/service/transaction/returnOrder/preStart/getReturnPolicyByProject.js +132 -0
- package/lib/chevre/service/transaction/returnOrder/preStart.js +2 -391
- package/package.json +3 -3
- package/example/src/chevre/migrateMembers2identities.ts +0 -109
- package/example/src/chevre/publishConfimationNumber.ts +0 -27
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as moment from 'moment';
|
|
3
|
+
import * as mongoose from 'mongoose';
|
|
4
|
+
import * as redis from 'redis';
|
|
5
|
+
import { chevre } from '../../../../lib/index';
|
|
6
|
+
|
|
7
|
+
// const project = { id: String(process.env.PROJECT_ID) };
|
|
8
|
+
|
|
9
|
+
const redisClient = redis.createClient<redis.RedisDefaultModules, Record<string, never>, Record<string, never>>({
|
|
10
|
+
socket: {
|
|
11
|
+
port: Number(<string>process.env.REDIS_PORT),
|
|
12
|
+
host: <string>process.env.REDIS_HOST
|
|
13
|
+
},
|
|
14
|
+
password: <string>process.env.REDIS_KEY,
|
|
15
|
+
name: 'checkRedisKeyCount'
|
|
16
|
+
})
|
|
17
|
+
.on('error', (err) => {
|
|
18
|
+
// eslint-disable-next-line no-console
|
|
19
|
+
console.error('createDefaultRedisClient: client onError:', err);
|
|
20
|
+
// reject(err);
|
|
21
|
+
});
|
|
22
|
+
redisClient.connect();
|
|
23
|
+
mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
24
|
+
|
|
25
|
+
async function main() {
|
|
26
|
+
const transactionNumberRepo = await chevre.repository.TransactionNumber.createInstance({
|
|
27
|
+
redisClient,
|
|
28
|
+
connection: mongoose.connection
|
|
29
|
+
});
|
|
30
|
+
const result = await transactionNumberRepo.setUseMongo4transactionNumberFrom({
|
|
31
|
+
useMongo4transactionNumberFrom: moment('2025-06-05T22:45:00Z')
|
|
32
|
+
.toDate()
|
|
33
|
+
});
|
|
34
|
+
console.log(result);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
main()
|
|
38
|
+
.then(() => {
|
|
39
|
+
console.log('success!');
|
|
40
|
+
})
|
|
41
|
+
.catch(console.error);
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
|
|
2
|
+
// tslint:disable:no-console no-magic-numbers no-null-keyword
|
|
3
|
+
import type * as Redis from 'redis';
|
|
4
|
+
|
|
5
|
+
const REDIS_PING_INTERVAL_MS: number = (typeof process.env.REDIS_PING_INTERVAL_MS === 'string')
|
|
6
|
+
? Number(process.env.REDIS_PING_INTERVAL_MS)
|
|
7
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
8
|
+
: 30000;
|
|
9
|
+
const REDIS_HOST: string = String(process.env.REDIS_HOST);
|
|
10
|
+
const REDIS_PORT: number = Number(process.env.REDIS_PORT);
|
|
11
|
+
const REDIS_KEY: string = String(process.env.REDIS_KEY);
|
|
12
|
+
|
|
13
|
+
const redisClientOptions: Redis.RedisClientOptions<Redis.RedisDefaultModules, Record<string, never>, Record<string, never>> = {
|
|
14
|
+
socket: {
|
|
15
|
+
host: REDIS_HOST,
|
|
16
|
+
port: REDIS_PORT
|
|
17
|
+
// tls: (process.env.REDIS_TLS_SERVERNAME !== undefined) ? { servername: process.env.REDIS_TLS_SERVERNAME } : undefined
|
|
18
|
+
},
|
|
19
|
+
password: REDIS_KEY,
|
|
20
|
+
pingInterval: REDIS_PING_INTERVAL_MS,
|
|
21
|
+
disableOfflineQueue: false
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
let redis: typeof Redis | undefined;
|
|
25
|
+
async function createRedisClient(): Promise<Redis.RedisClientType> {
|
|
26
|
+
return new Promise<Redis.RedisClientType>(async (resolve, reject) => {
|
|
27
|
+
if (redis === undefined) {
|
|
28
|
+
redis = await import('redis');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const client = redis.createClient<Redis.RedisDefaultModules, Record<string, never>, Record<string, never>>(redisClientOptions)
|
|
32
|
+
.on('error', (err) => {
|
|
33
|
+
// tslint:disable-next-line:no-console
|
|
34
|
+
console.error('createRedisClient: client onError:', err);
|
|
35
|
+
reject(err);
|
|
36
|
+
})
|
|
37
|
+
.on('connect', () => {
|
|
38
|
+
resolve(client);
|
|
39
|
+
});
|
|
40
|
+
// client.on('ready', () => {
|
|
41
|
+
// console.error('Redis Client ready');
|
|
42
|
+
// });
|
|
43
|
+
|
|
44
|
+
await client.connect()
|
|
45
|
+
.catch((err) => {
|
|
46
|
+
// tslint:disable-next-line:no-console
|
|
47
|
+
console.error('createRedisClient: redisClient.connect:', err);
|
|
48
|
+
reject(new Error('createRedisClient: failed in creating connection'));
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async function main() {
|
|
54
|
+
const redisClient = await createRedisClient();
|
|
55
|
+
console.log('redisClient created.', redisClient.options?.name);
|
|
56
|
+
|
|
57
|
+
const multi = await redisClient.multi();
|
|
58
|
+
const results = await multi.exec();
|
|
59
|
+
console.log(results);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
main()
|
|
63
|
+
.catch(console.error);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadChevreAuth = exports.auth = void 0;
|
|
4
|
+
const sdk_1 = require("@cinerino/sdk");
|
|
5
|
+
Object.defineProperty(exports, "auth", { enumerable: true, get: function () { return sdk_1.auth; } });
|
|
6
|
+
Object.defineProperty(exports, "loadChevreAuth", { enumerable: true, get: function () { return sdk_1.loadChevreAuth; } });
|
|
@@ -1,18 +1,48 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
|
+
import type { Connection } from 'mongoose';
|
|
3
|
+
import type { RedisClientType } from 'redis';
|
|
2
4
|
import * as factory from '../factory';
|
|
3
|
-
interface
|
|
5
|
+
interface IExecuteSettings {
|
|
6
|
+
/**
|
|
7
|
+
* MongoDBコネクション
|
|
8
|
+
*/
|
|
9
|
+
connection: Connection;
|
|
10
|
+
/**
|
|
11
|
+
* Redisクライアント
|
|
12
|
+
*/
|
|
13
|
+
redisClient?: RedisClientType;
|
|
14
|
+
}
|
|
15
|
+
type IOperationExecute<T> = (settings: IExecuteSettings) => Promise<T>;
|
|
16
|
+
type INextFunction = (task: Pick<factory.task.ITask<factory.taskName>, 'id'>) => IOperationExecute<void>;
|
|
17
|
+
interface IReadyTask {
|
|
4
18
|
id: string;
|
|
5
19
|
name?: factory.taskName;
|
|
6
|
-
status: factory.taskStatus.Ready
|
|
20
|
+
status: factory.taskStatus.Ready;
|
|
7
21
|
expires?: Date;
|
|
22
|
+
executionResult?: never;
|
|
23
|
+
}
|
|
24
|
+
interface IRunningTask {
|
|
25
|
+
id: string;
|
|
26
|
+
status: factory.taskStatus.Running;
|
|
27
|
+
name?: never;
|
|
28
|
+
expires?: never;
|
|
29
|
+
executionResult?: never;
|
|
30
|
+
}
|
|
31
|
+
interface IExecutedTask {
|
|
32
|
+
id: string;
|
|
33
|
+
status: factory.taskStatus;
|
|
34
|
+
executionResult: factory.task.IExecutionResult;
|
|
35
|
+
name?: never;
|
|
36
|
+
expires?: never;
|
|
8
37
|
}
|
|
9
|
-
type
|
|
38
|
+
type IChangedTask = IReadyTask | IRunningTask | IExecutedTask;
|
|
39
|
+
type IOnTaskStatusChangedListener = (task: IChangedTask, next?: INextFunction) => void;
|
|
10
40
|
/**
|
|
11
41
|
* タスクイベントエミッター
|
|
12
42
|
*/
|
|
13
43
|
declare class TaskEventEmitter extends EventEmitter {
|
|
14
|
-
onTaskStatusChanged(
|
|
15
|
-
emitTaskStatusChanged(
|
|
44
|
+
onTaskStatusChanged(listener: IOnTaskStatusChangedListener): void;
|
|
45
|
+
emitTaskStatusChanged(task: IChangedTask, next?: INextFunction): void;
|
|
16
46
|
}
|
|
17
47
|
declare const taskEventEmitter: TaskEventEmitter;
|
|
18
|
-
export { IOnTaskStatusChangedListener, taskEventEmitter };
|
|
48
|
+
export { IChangedTask, IReadyTask, IRunningTask, IExecutedTask, IExecuteSettings, INextFunction, IOnTaskStatusChangedListener, taskEventEmitter };
|
|
@@ -10,11 +10,12 @@ var EventName;
|
|
|
10
10
|
* タスクイベントエミッター
|
|
11
11
|
*/
|
|
12
12
|
class TaskEventEmitter extends events_1.EventEmitter {
|
|
13
|
-
onTaskStatusChanged(
|
|
14
|
-
this.on(EventName.OnTaskStatusChanged,
|
|
13
|
+
onTaskStatusChanged(listener) {
|
|
14
|
+
this.on(EventName.OnTaskStatusChanged, listener);
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
// support next function required(2025-05-25~)
|
|
17
|
+
emitTaskStatusChanged(task, next) {
|
|
18
|
+
this.emit(EventName.OnTaskStatusChanged, task, (typeof next === 'function') ? next : undefined);
|
|
18
19
|
}
|
|
19
20
|
}
|
|
20
21
|
const taskEventEmitter = new TaskEventEmitter();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { assetTransactionEventEmitter } from './eventEmitter/assetTransaction';
|
|
2
|
-
import
|
|
2
|
+
import * as task from './eventEmitter/task';
|
|
3
3
|
import { transactionEventEmitter } from './eventEmitter/transaction';
|
|
4
|
-
export { assetTransactionEventEmitter as assetTransaction,
|
|
4
|
+
export { assetTransactionEventEmitter as assetTransaction, task, transactionEventEmitter as transaction };
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.transaction = exports.task = exports.assetTransaction = void 0;
|
|
4
4
|
const assetTransaction_1 = require("./eventEmitter/assetTransaction");
|
|
5
5
|
Object.defineProperty(exports, "assetTransaction", { enumerable: true, get: function () { return assetTransaction_1.assetTransactionEventEmitter; } });
|
|
6
|
-
const
|
|
7
|
-
|
|
6
|
+
const task = require("./eventEmitter/task");
|
|
7
|
+
exports.task = task;
|
|
8
8
|
const transaction_1 = require("./eventEmitter/transaction");
|
|
9
9
|
Object.defineProperty(exports, "transaction", { enumerable: true, get: function () { return transaction_1.transactionEventEmitter; } });
|
package/lib/chevre/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import type * as COAService from '@motionpicture/coa-service';
|
|
5
5
|
import type * as GMOService from '@motionpicture/gmo-service';
|
|
6
|
+
import type * as AdminAuth from './adminAuth';
|
|
6
7
|
import type * as Pecorinoapi from './pecorinoapi';
|
|
7
8
|
import { credentials } from './credentials';
|
|
8
9
|
import * as errorHandler from './errorHandler';
|
|
@@ -12,6 +13,7 @@ import * as repository from './repository';
|
|
|
12
13
|
import * as service from './service';
|
|
13
14
|
import * as settings from './settings';
|
|
14
15
|
export { credentials, errorHandler, eventEmitter, factory, repository, service, settings };
|
|
16
|
+
export declare function loadAdminAuth(): Promise<typeof AdminAuth>;
|
|
15
17
|
export declare function loadPecorinoapi(): Promise<typeof Pecorinoapi>;
|
|
16
18
|
export type COA = typeof COAService;
|
|
17
19
|
export declare function loadCOA(): Promise<typeof COAService>;
|
package/lib/chevre/index.js
CHANGED
|
@@ -10,6 +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.settings = exports.service = exports.repository = exports.factory = exports.eventEmitter = exports.errorHandler = exports.credentials = void 0;
|
|
13
|
+
exports.loadAdminAuth = loadAdminAuth;
|
|
13
14
|
exports.loadPecorinoapi = loadPecorinoapi;
|
|
14
15
|
exports.loadCOA = loadCOA;
|
|
15
16
|
exports.loadGMO = loadGMO;
|
|
@@ -27,6 +28,15 @@ const service = require("./service");
|
|
|
27
28
|
exports.service = service;
|
|
28
29
|
const settings = require("./settings");
|
|
29
30
|
exports.settings = settings;
|
|
31
|
+
let adminAuth;
|
|
32
|
+
function loadAdminAuth() {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
if (adminAuth === undefined) {
|
|
35
|
+
adminAuth = yield Promise.resolve().then(() => require('./adminAuth'));
|
|
36
|
+
}
|
|
37
|
+
return adminAuth;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
30
40
|
let pecorinoapi;
|
|
31
41
|
function loadPecorinoapi() {
|
|
32
42
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { RedisClientType } from 'redis';
|
|
2
|
+
import { AbstractConcurrentLockRepo, ILockParams, IUnlockParams } from './concurrentLockAbstract';
|
|
3
|
+
/**
|
|
4
|
+
* 同時実行ロックリポジトリ
|
|
5
|
+
*/
|
|
6
|
+
export declare class ConcurrentLockRepo implements AbstractConcurrentLockRepo {
|
|
7
|
+
private readonly redisClient;
|
|
8
|
+
constructor(params: {
|
|
9
|
+
redisClient: RedisClientType;
|
|
10
|
+
});
|
|
11
|
+
static CREATE_REDIS_KEY(params: Pick<ILockParams, 'about'>): string;
|
|
12
|
+
lock(params: ILockParams): Promise<void>;
|
|
13
|
+
unlock(params: IUnlockParams): Promise<void>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
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.ConcurrentLockRepo = void 0;
|
|
13
|
+
const factory = require("../factory");
|
|
14
|
+
/**
|
|
15
|
+
* 同時実行ロックリポジトリ
|
|
16
|
+
*/
|
|
17
|
+
class ConcurrentLockRepo {
|
|
18
|
+
constructor(params) {
|
|
19
|
+
const { redisClient } = params;
|
|
20
|
+
this.redisClient = redisClient;
|
|
21
|
+
}
|
|
22
|
+
static CREATE_REDIS_KEY(params) {
|
|
23
|
+
return params.about.identifier;
|
|
24
|
+
}
|
|
25
|
+
lock(params) {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
const key = ConcurrentLockRepo.CREATE_REDIS_KEY(params);
|
|
28
|
+
const value = params.audience.identifier;
|
|
29
|
+
const results = yield this.redisClient.multi()
|
|
30
|
+
.setNX(key, value)
|
|
31
|
+
.expireAt(key, params.expires)
|
|
32
|
+
.exec();
|
|
33
|
+
if (Array.isArray(results) && (results[0] === 1 || results[0] === true)) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
throw new factory.errors.AlreadyInUse(params.about.identifier, []);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
unlock(params) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
const key = ConcurrentLockRepo.CREATE_REDIS_KEY(params);
|
|
44
|
+
yield this.redisClient.del([key]);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.ConcurrentLockRepo = ConcurrentLockRepo;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import * as factory from '../factory';
|
|
2
|
+
export interface IOffer {
|
|
3
|
+
itemOffered?: {
|
|
4
|
+
serviceOutput?: {
|
|
5
|
+
/**
|
|
6
|
+
* 予約ID
|
|
7
|
+
*/
|
|
8
|
+
id?: string;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
seatSection: string;
|
|
12
|
+
seatNumber: string;
|
|
13
|
+
}
|
|
14
|
+
export interface IAbout {
|
|
15
|
+
identifier: string;
|
|
16
|
+
typeOf: 'Thing';
|
|
17
|
+
}
|
|
18
|
+
export interface IAudience {
|
|
19
|
+
identifier: string;
|
|
20
|
+
typeOf: 'Audience';
|
|
21
|
+
}
|
|
22
|
+
export interface IConcurrentLock {
|
|
23
|
+
project: {
|
|
24
|
+
id: string;
|
|
25
|
+
typeOf: factory.organizationType.Project;
|
|
26
|
+
};
|
|
27
|
+
typeOf: factory.creativeWorkType.Certification;
|
|
28
|
+
about: IAbout;
|
|
29
|
+
dateCreated: Date;
|
|
30
|
+
expires: Date;
|
|
31
|
+
audience: IAudience;
|
|
32
|
+
}
|
|
33
|
+
export type ILockParams = Pick<IConcurrentLock, 'about' | 'audience' | 'expires' | 'project'>;
|
|
34
|
+
export type IUnlockParams = Pick<IConcurrentLock, 'about' | 'audience'>;
|
|
35
|
+
export type IGetHolderResult = string | null;
|
|
36
|
+
/**
|
|
37
|
+
* 抽象同時実行ロックリポジトリ
|
|
38
|
+
*/
|
|
39
|
+
export declare abstract class AbstractConcurrentLockRepo {
|
|
40
|
+
abstract lock(lockKey: ILockParams): Promise<void>;
|
|
41
|
+
abstract unlock(params: IUnlockParams): Promise<void>;
|
|
42
|
+
}
|
|
@@ -1,17 +1,30 @@
|
|
|
1
|
+
import type { Connection } from 'mongoose';
|
|
1
2
|
import { RedisClientType } from 'redis';
|
|
3
|
+
import { ISetting } from './mongoose/schemas/setting';
|
|
2
4
|
/**
|
|
3
5
|
* 確認番号リポジトリ
|
|
4
6
|
*/
|
|
5
7
|
export declare class ConfirmationNumberRepo {
|
|
6
|
-
private
|
|
7
|
-
private readonly
|
|
8
|
-
constructor(
|
|
8
|
+
private readonly settingModel;
|
|
9
|
+
private readonly counterRepo;
|
|
10
|
+
constructor(params: {
|
|
11
|
+
redisClient: RedisClientType;
|
|
12
|
+
connection: Connection;
|
|
13
|
+
});
|
|
9
14
|
private static alignDigits;
|
|
10
|
-
private static
|
|
15
|
+
private static createDataFeedIdentifier;
|
|
16
|
+
private static count2confirmationNumber;
|
|
11
17
|
/**
|
|
12
18
|
* 発行する
|
|
13
19
|
*/
|
|
14
20
|
publish(params: {
|
|
15
21
|
orderDate: Date;
|
|
16
22
|
}): Promise<string>;
|
|
23
|
+
/**
|
|
24
|
+
* DB移行時のみに使用目的の設定更新
|
|
25
|
+
*/
|
|
26
|
+
setUseMongo4confirmationNumberFrom(params: {
|
|
27
|
+
useMongo4confirmationNumberFrom: Date;
|
|
28
|
+
}): Promise<Pick<ISetting, "useMongo4confirmationNumberFrom"> | null>;
|
|
29
|
+
private useMongoBySettings;
|
|
17
30
|
}
|
|
@@ -12,17 +12,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.ConfirmationNumberRepo = void 0;
|
|
13
13
|
const cdigit = require("cdigit");
|
|
14
14
|
const moment = require("moment-timezone");
|
|
15
|
-
const util = require("util");
|
|
16
15
|
// tslint:disable-next-line:no-require-imports no-var-requires
|
|
17
16
|
const fpe = require('node-fpe');
|
|
18
|
-
const
|
|
17
|
+
const setting_1 = require("./mongoose/schemas/setting");
|
|
18
|
+
const transactionNumber_1 = require("./mongoose/schemas/transactionNumber");
|
|
19
|
+
const transactionNumberCounter_1 = require("./transactionNumberCounter");
|
|
19
20
|
const CONFIRMATION_NUMBER_MIN_LENGH = 4;
|
|
21
|
+
const TIMEZONE = 'Asia/Tokyo';
|
|
20
22
|
/**
|
|
21
23
|
* 確認番号リポジトリ
|
|
22
24
|
*/
|
|
23
25
|
class ConfirmationNumberRepo {
|
|
24
|
-
constructor(
|
|
25
|
-
|
|
26
|
+
constructor(params) {
|
|
27
|
+
const { connection } = params;
|
|
28
|
+
this.settingModel = connection.model(setting_1.modelName, (0, setting_1.createSchema)());
|
|
29
|
+
this.counterRepo = new transactionNumberCounter_1.TransactionNumberCounterRepo(params);
|
|
26
30
|
}
|
|
27
31
|
static alignDigits(params) {
|
|
28
32
|
let aligndNumber = String(params);
|
|
@@ -32,42 +36,95 @@ class ConfirmationNumberRepo {
|
|
|
32
36
|
}
|
|
33
37
|
return aligndNumber;
|
|
34
38
|
}
|
|
35
|
-
static createKey(params
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
// private static createKey(params: {
|
|
40
|
+
// orderDate: Date;
|
|
41
|
+
// }): string {
|
|
42
|
+
// return util.format(
|
|
43
|
+
// '%s:%s',
|
|
44
|
+
// ConfirmationNumberRepo.REDIS_KEY_PREFIX_NEW,
|
|
45
|
+
// moment(params.orderDate)
|
|
46
|
+
// .tz(TIMEZONE)
|
|
47
|
+
// .format('YYMM')
|
|
48
|
+
// );
|
|
49
|
+
// }
|
|
50
|
+
static createDataFeedIdentifier(params) {
|
|
51
|
+
return moment(params.orderDate)
|
|
52
|
+
.tz(TIMEZONE)
|
|
53
|
+
.format('YYMM');
|
|
54
|
+
}
|
|
55
|
+
static count2confirmationNumber(params) {
|
|
56
|
+
// 桁数調整
|
|
57
|
+
let confirmationNumber = ConfirmationNumberRepo.alignDigits(params.count);
|
|
58
|
+
// checkdigit
|
|
59
|
+
const cd = cdigit.luhn.compute(confirmationNumber);
|
|
60
|
+
// debug('check digit:', cd);
|
|
61
|
+
confirmationNumber = fpe({ password: cd })
|
|
62
|
+
.encrypt(confirmationNumber);
|
|
63
|
+
confirmationNumber = `${cd}${confirmationNumber}`;
|
|
64
|
+
return confirmationNumber;
|
|
39
65
|
}
|
|
40
66
|
/**
|
|
41
67
|
* 発行する
|
|
42
68
|
*/
|
|
43
69
|
publish(params) {
|
|
44
70
|
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
71
|
+
let dataFeedExpires;
|
|
72
|
+
const dataFeedIdentifier = ConfirmationNumberRepo.createDataFeedIdentifier({ orderDate: params.orderDate });
|
|
73
|
+
let incrReply;
|
|
74
|
+
// support publishByMongo(2025-05-23~)
|
|
75
|
+
const useMongoBySettings = yield this.useMongoBySettings(params);
|
|
76
|
+
if (useMongoBySettings) {
|
|
77
|
+
// データ保管期間はとりあえず2 months
|
|
78
|
+
dataFeedExpires = moment(params.orderDate)
|
|
79
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
80
|
+
.add(2, 'months')
|
|
81
|
+
.toDate();
|
|
82
|
+
incrReply = yield this.counterRepo.incrementByMongo({
|
|
83
|
+
identifier: dataFeedIdentifier,
|
|
84
|
+
includedInDataCatalog: { identifier: transactionNumber_1.DataCatalogIdentifier.confirmationNumber },
|
|
85
|
+
expires: dataFeedExpires
|
|
86
|
+
});
|
|
59
87
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
88
|
+
else {
|
|
89
|
+
// データ保管期間はとりあえず一か月
|
|
90
|
+
dataFeedExpires = moment(params.orderDate)
|
|
91
|
+
.add(1, 'month')
|
|
92
|
+
.toDate();
|
|
93
|
+
incrReply = yield this.counterRepo.incrementByRedis({
|
|
94
|
+
identifier: dataFeedIdentifier,
|
|
95
|
+
includedInDataCatalog: { identifier: transactionNumber_1.DataCatalogIdentifier.confirmationNumber },
|
|
96
|
+
expires: dataFeedExpires
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
return ConfirmationNumberRepo.count2confirmationNumber({ count: incrReply });
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* DB移行時のみに使用目的の設定更新
|
|
104
|
+
*/
|
|
105
|
+
setUseMongo4confirmationNumberFrom(params) {
|
|
106
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
107
|
+
const { useMongo4confirmationNumberFrom } = params;
|
|
108
|
+
return this.settingModel.findOneAndUpdate({ 'project.id': { $eq: '*' } }, {
|
|
109
|
+
$set: { useMongo4confirmationNumberFrom }
|
|
110
|
+
}, { projection: { _id: 0, useMongo4confirmationNumberFrom: 1 } })
|
|
111
|
+
.lean()
|
|
112
|
+
.exec();
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
useMongoBySettings(params) {
|
|
116
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
+
const setting = yield this.settingModel.findOne({ 'project.id': { $eq: '*' } }, {
|
|
118
|
+
_id: 0,
|
|
119
|
+
useMongo4confirmationNumberFrom: 1
|
|
120
|
+
})
|
|
121
|
+
.lean()
|
|
122
|
+
.exec();
|
|
123
|
+
const useMongo4confirmationNumberFrom = setting === null || setting === void 0 ? void 0 : setting.useMongo4confirmationNumberFrom;
|
|
124
|
+
return useMongo4confirmationNumberFrom instanceof Date
|
|
125
|
+
&& moment(params.orderDate)
|
|
126
|
+
.isSameOrAfter(moment(useMongo4confirmationNumberFrom));
|
|
69
127
|
});
|
|
70
128
|
}
|
|
71
129
|
}
|
|
72
130
|
exports.ConfirmationNumberRepo = ConfirmationNumberRepo;
|
|
73
|
-
ConfirmationNumberRepo.REDIS_KEY_PREFIX_NEW = 'confirmationNumber';
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { Connection, FilterQuery } from 'mongoose';
|
|
1
|
+
import { Connection, FilterQuery, QueryOptions } from 'mongoose';
|
|
2
2
|
import * as factory from '../factory';
|
|
3
|
-
export type ISavingIdentity = Pick<factory.creativeWork.certification.webApplication.ICertification, 'about' | '
|
|
3
|
+
export type ISavingIdentity = Pick<factory.creativeWork.certification.webApplication.ICertification, 'about' | 'project' | 'typeOf'> & {
|
|
4
4
|
id?: never;
|
|
5
5
|
dateCreated?: never;
|
|
6
6
|
dateModified?: never;
|
|
7
|
+
issuedBy: factory.creativeWork.certification.webApplication.IIssuedBy[];
|
|
7
8
|
};
|
|
8
9
|
interface IUnset {
|
|
9
10
|
$unset?: {
|
|
@@ -21,18 +22,54 @@ export declare class IdentityRepo {
|
|
|
21
22
|
private readonly identityModel;
|
|
22
23
|
constructor(connection: Connection);
|
|
23
24
|
static CREATE_FILTER_QUERY(params: factory.creativeWork.certification.webApplication.ISearchConditions): FilterQuery<factory.creativeWork.certification.webApplication.ICertification>[];
|
|
24
|
-
|
|
25
|
+
saveIdentity(params: {
|
|
25
26
|
id?: string;
|
|
26
27
|
attributes: ISavingIdentity & IUnset;
|
|
27
28
|
}): Promise<{
|
|
28
29
|
id: string;
|
|
29
30
|
}>;
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
projectIdentityFields(conditions: factory.creativeWork.certification.webApplication.ISearchConditions, inclusion: IKeyOfProjection[]): Promise<IIdentityWithId[]>;
|
|
32
|
+
deleteIdentityById(params: {
|
|
32
33
|
id: string;
|
|
33
34
|
project: {
|
|
34
35
|
id: string;
|
|
35
36
|
};
|
|
36
37
|
}): Promise<void>;
|
|
38
|
+
getCursor(conditions: any, projection: any): import("mongoose").Cursor<import("mongoose").Document<unknown, {}, {
|
|
39
|
+
project: Pick<factory.project.IProject, "id" | "typeOf">;
|
|
40
|
+
typeOf: factory.creativeWorkType.Certification;
|
|
41
|
+
about: import("@chevre/factory/lib/creativeWork/certification/webApplication").IAbout;
|
|
42
|
+
dateCreated?: Date | undefined;
|
|
43
|
+
dateModified?: Date | undefined;
|
|
44
|
+
issuedBy: import("@chevre/factory/lib/creativeWork/certification/webApplication").IIssuedBy | import("@chevre/factory/lib/creativeWork/certification/webApplication").IIssuedBy[];
|
|
45
|
+
}> & {
|
|
46
|
+
project: Pick<factory.project.IProject, "id" | "typeOf">;
|
|
47
|
+
typeOf: factory.creativeWorkType.Certification;
|
|
48
|
+
about: import("@chevre/factory/lib/creativeWork/certification/webApplication").IAbout;
|
|
49
|
+
dateCreated?: Date | undefined;
|
|
50
|
+
dateModified?: Date | undefined;
|
|
51
|
+
issuedBy: import("@chevre/factory/lib/creativeWork/certification/webApplication").IIssuedBy | import("@chevre/factory/lib/creativeWork/certification/webApplication").IIssuedBy[];
|
|
52
|
+
} & {
|
|
53
|
+
_id: import("mongoose").Types.ObjectId;
|
|
54
|
+
}, QueryOptions<import("mongoose").Document<unknown, {}, {
|
|
55
|
+
project: Pick<factory.project.IProject, "id" | "typeOf">;
|
|
56
|
+
typeOf: factory.creativeWorkType.Certification;
|
|
57
|
+
about: import("@chevre/factory/lib/creativeWork/certification/webApplication").IAbout;
|
|
58
|
+
dateCreated?: Date | undefined;
|
|
59
|
+
dateModified?: Date | undefined;
|
|
60
|
+
issuedBy: import("@chevre/factory/lib/creativeWork/certification/webApplication").IIssuedBy | import("@chevre/factory/lib/creativeWork/certification/webApplication").IIssuedBy[];
|
|
61
|
+
}> & {
|
|
62
|
+
project: Pick<factory.project.IProject, "id" | "typeOf">;
|
|
63
|
+
typeOf: factory.creativeWorkType.Certification;
|
|
64
|
+
about: import("@chevre/factory/lib/creativeWork/certification/webApplication").IAbout;
|
|
65
|
+
dateCreated?: Date | undefined;
|
|
66
|
+
dateModified?: Date | undefined;
|
|
67
|
+
issuedBy: import("@chevre/factory/lib/creativeWork/certification/webApplication").IIssuedBy | import("@chevre/factory/lib/creativeWork/certification/webApplication").IIssuedBy[];
|
|
68
|
+
} & {
|
|
69
|
+
_id: import("mongoose").Types.ObjectId;
|
|
70
|
+
}>>;
|
|
71
|
+
updateIssuedBy2array(params: Pick<ISavingIdentity, 'issuedBy'> & {
|
|
72
|
+
id: string;
|
|
73
|
+
}): Promise<void>;
|
|
37
74
|
}
|
|
38
75
|
export {};
|