@chevre/domain 25.0.0 → 25.1.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.
@@ -219,6 +219,33 @@ export interface IIntegrationSettings {
219
219
  hub?: IHubSettings;
220
220
  useExperimentalFeature: boolean;
221
221
  }
222
+ /**
223
+ * 2026-06-30~
224
+ */
225
+ export interface IRateLimitSetting {
226
+ unitInSeconds: number;
227
+ thresholdGloballyByProject: number;
228
+ thresholdGloballyByProjectGet: number;
229
+ thresholdGlobally: number;
230
+ thresholdGloballyGet: number;
231
+ thresholdSoftware: number;
232
+ exceptionClient: string[];
233
+ /**
234
+ * 進行中取引の接続回数制限
235
+ * 取引IDごとにレート制限
236
+ */
237
+ transactionUnitInSeconds: number;
238
+ /**
239
+ * 進行中取引の接続回数制限
240
+ * 取引IDごとにレート制限
241
+ */
242
+ transactionThreshold: number;
243
+ /**
244
+ * 進行中取引の接続回数制限
245
+ * 取引IDごとにレート制限
246
+ */
247
+ transactionThresholdGet: number;
248
+ }
222
249
  export interface ISetting {
223
250
  defaultSenderEmail?: string;
224
251
  jwt?: IJWTSetting;
@@ -256,6 +283,7 @@ export interface ISetting {
256
283
  * 環境変数から移行(2026-05-23~)
257
284
  */
258
285
  integration?: IIntegrationSettings;
286
+ rateLimit?: IRateLimitSetting;
259
287
  }
260
288
  type IDocType = ISetting;
261
289
  type IModel = Model<IDocType, Record<string, never>, Record<string, never>, IVirtuals>;
@@ -32,7 +32,8 @@ const schemaDefinition = {
32
32
  useMongo4confirmationNumberFrom: { type: Date, required: false },
33
33
  useMongo4orderNumberFrom: { type: Date, required: false },
34
34
  useMongo4transactionNumberFrom: { type: Date, required: false },
35
- integration: { type: mongoose_1.SchemaTypes.Mixed, required: false } // 2026-05-23~
35
+ integration: { type: mongoose_1.SchemaTypes.Mixed, required: false }, // 2026-05-23~
36
+ rateLimit: { type: mongoose_1.SchemaTypes.Mixed, required: false } // 2026-06-30~
36
37
  };
37
38
  const schemaOptions = {
38
39
  autoIndex: settings_1.MONGO_AUTO_INDEX,
@@ -0,0 +1,18 @@
1
+ import type { Connection } from 'mongoose';
2
+ import { IRateLimitSetting } from '../mongoose/schemas/setting';
3
+ interface IDBOptions {
4
+ connection: Connection;
5
+ }
6
+ /**
7
+ * apisレート制限設定リポジトリ
8
+ */
9
+ export declare class RateLimitSettingRepo {
10
+ private readonly settingModel;
11
+ private static cachedSettings;
12
+ private static cacheExpiry;
13
+ private static readonly CACHE_TTL_MS;
14
+ constructor(options: IDBOptions);
15
+ findRateLimitSetting(): Promise<IRateLimitSetting>;
16
+ addRateLimitSetting(params: IRateLimitSetting): Promise<import("mongoose").UpdateWriteOpResult>;
17
+ }
18
+ export {};
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RateLimitSettingRepo = void 0;
4
+ const factory_1 = require("../../factory");
5
+ const setting_1 = require("../mongoose/schemas/setting");
6
+ /**
7
+ * apisレート制限設定リポジトリ
8
+ */
9
+ class RateLimitSettingRepo {
10
+ settingModel;
11
+ // static にすることで、クラスが何回 new されてもメモリ上で1つだけ保持される
12
+ static cachedSettings;
13
+ static cacheExpiry = 0;
14
+ static CACHE_TTL_MS = 10 * 60 * 1000; // 10分
15
+ constructor(options) {
16
+ const { connection } = options;
17
+ this.settingModel = connection.model(setting_1.modelName, (0, setting_1.createSchema)());
18
+ }
19
+ async findRateLimitSetting() {
20
+ const now = Date.now();
21
+ // キャッシュ参照
22
+ if (RateLimitSettingRepo.cachedSettings !== undefined && now < RateLimitSettingRepo.cacheExpiry) {
23
+ return RateLimitSettingRepo.cachedSettings;
24
+ }
25
+ const settingDoc = await this.settingModel.findOne({ 'project.id': { $eq: '*' } }, {
26
+ _id: 0,
27
+ rateLimit: 1
28
+ })
29
+ .lean()
30
+ .exec();
31
+ if (settingDoc?.rateLimit === undefined) {
32
+ throw new factory_1.factory.errors.NotFound('rateLimitSetting');
33
+ }
34
+ // キャッシュを更新
35
+ RateLimitSettingRepo.cachedSettings = settingDoc.rateLimit;
36
+ RateLimitSettingRepo.cacheExpiry = now + RateLimitSettingRepo.CACHE_TTL_MS;
37
+ return RateLimitSettingRepo.cachedSettings;
38
+ }
39
+ async addRateLimitSetting(params) {
40
+ return this.settingModel.updateOne({ 'project.id': { $eq: '*' } }, {
41
+ $set: {
42
+ rateLimit: params
43
+ }
44
+ })
45
+ .exec();
46
+ }
47
+ }
48
+ exports.RateLimitSettingRepo = RateLimitSettingRepo;
@@ -81,6 +81,7 @@ import type { ServiceAvailableHourRepo } from './repo/service/availableHour';
81
81
  import type { SettingRepo } from './repo/setting';
82
82
  import type { IntegrationSettingRepo } from './repo/setting/integration';
83
83
  import type { JWTSettingRepo } from './repo/setting/jwt';
84
+ import type { RateLimitSettingRepo } from './repo/setting/rateLimit';
84
85
  import type { WaiterSettingRepo } from './repo/setting/waiter';
85
86
  import type { StockHolderRepo } from './repo/stockHolder';
86
87
  import type { TaskRepo } from './repo/task';
@@ -447,6 +448,10 @@ export declare namespace setting {
447
448
  namespace JWT {
448
449
  function createInstance(...params: ConstructorParameters<typeof JWTSettingRepo>): Promise<JWTSettingRepo>;
449
450
  }
451
+ type RateLimit = RateLimitSettingRepo;
452
+ namespace RateLimit {
453
+ function createInstance(...params: ConstructorParameters<typeof RateLimitSettingRepo>): Promise<RateLimitSettingRepo>;
454
+ }
450
455
  type Waiter = WaiterSettingRepo;
451
456
  namespace Waiter {
452
457
  function createInstance(...params: ConstructorParameters<typeof WaiterSettingRepo>): Promise<WaiterSettingRepo>;
@@ -933,6 +933,17 @@ var setting;
933
933
  }
934
934
  JWT.createInstance = createInstance;
935
935
  })(JWT = setting.JWT || (setting.JWT = {}));
936
+ let RateLimit;
937
+ (function (RateLimit) {
938
+ let repo;
939
+ async function createInstance(...params) {
940
+ if (repo === undefined) {
941
+ repo = (await import('./repo/setting/rateLimit.js')).RateLimitSettingRepo;
942
+ }
943
+ return new repo(...params);
944
+ }
945
+ RateLimit.createInstance = createInstance;
946
+ })(RateLimit = setting.RateLimit || (setting.RateLimit = {}));
936
947
  let Waiter;
937
948
  (function (Waiter) {
938
949
  let repo;
package/package.json CHANGED
@@ -91,5 +91,5 @@
91
91
  "postversion": "git push origin --tags",
92
92
  "prepublishOnly": "npm run clean && npm run build"
93
93
  },
94
- "version": "25.0.0"
94
+ "version": "25.1.0-alpha.0"
95
95
  }