@okf/ootils 1.23.0 → 1.24.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/dist/node.d.mts +31 -1
- package/dist/node.d.ts +31 -1
- package/dist/node.js +49 -0
- package/dist/node.mjs +48 -0
- package/package.json +2 -1
package/dist/node.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Client } from '@elastic/elasticsearch';
|
|
2
2
|
import Redis from 'ioredis';
|
|
3
|
+
import * as _google_cloud_secret_manager_build_src_v1 from '@google-cloud/secret-manager/build/src/v1';
|
|
3
4
|
import * as mongoose from 'mongoose';
|
|
4
5
|
import mongoose__default, { Document, Types, Schema } from 'mongoose';
|
|
5
6
|
import * as bullmq from 'bullmq';
|
|
@@ -1313,6 +1314,35 @@ declare namespace RedisCacheConnector {
|
|
|
1313
1314
|
let instance: any;
|
|
1314
1315
|
}
|
|
1315
1316
|
|
|
1317
|
+
/**
|
|
1318
|
+
* Usage:
|
|
1319
|
+
* const sm = new SecretManagerConnector({
|
|
1320
|
+
* secrets: [
|
|
1321
|
+
* { name: 'globalConfigs', fallbackPath: 'db/config/globalConfigs.js' },
|
|
1322
|
+
* { name: 'creds-json', fallbackPath: 'creds.json' },
|
|
1323
|
+
* ]
|
|
1324
|
+
* });
|
|
1325
|
+
* await sm.connect();
|
|
1326
|
+
* const globalConfigs = SecretManagerConnector.getSecret('globalConfigs');
|
|
1327
|
+
* // or
|
|
1328
|
+
* const globalConfigs = SecretManagerConnector.getGlobalConfigs();
|
|
1329
|
+
*/
|
|
1330
|
+
declare class SecretManagerConnector {
|
|
1331
|
+
static getSecret(secretName: any): any;
|
|
1332
|
+
static getGlobalConfigs(): any;
|
|
1333
|
+
static getInstance(): any;
|
|
1334
|
+
constructor({ secrets }?: {
|
|
1335
|
+
secrets?: never[] | undefined;
|
|
1336
|
+
});
|
|
1337
|
+
client: _google_cloud_secret_manager_build_src_v1.SecretManagerServiceClient;
|
|
1338
|
+
secrets: any[];
|
|
1339
|
+
cache: {};
|
|
1340
|
+
connect(): Promise<void>;
|
|
1341
|
+
}
|
|
1342
|
+
declare namespace SecretManagerConnector {
|
|
1343
|
+
let instance: any;
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1316
1346
|
/**
|
|
1317
1347
|
* Get database connection by tenant
|
|
1318
1348
|
* @param tenant - Tenant identifier for the database
|
|
@@ -1744,4 +1774,4 @@ declare function GET_GLOBAL_BULLMQ_CONFIG({ env, redisCredentials }: {
|
|
|
1744
1774
|
};
|
|
1745
1775
|
}): Object;
|
|
1746
1776
|
|
|
1747
|
-
export { AIChatSchema, AnnosElasticSyncProducer, AnnotationSchema, BASE_BULLMQ_CONFIG, BaseProducer, BaseWorker, ChunksElasticSyncProducer, ElasticSearchConnector, FILTER_IDS, GET_GLOBAL_BULLMQ_CONFIG, GeneratedTopicsSchema, MongoConnector, PlatformConfigsSchema, ProducerManager, RedisCacheConnector, TEMP_removeDuplicateFilters, TplSchema, UI_CONTENT, WorkerManager, _self_managed_buildAnnoHierarchyConfig, _self_managed_getFixedAnnoRollupBlocks, _self_managed_getFixedAnnoTagBlock, autoGenFilterConfigsFromTpl, buildFilterConfigurations, compareAndGroupBlocks, deleteVal, extractAllBlocksFromTpl, extractAndOrganizeBlocks, genTagId, generateFilterKey, getAIChatModelByTenant, getAnnotationsModelByTenant, getDbByTenant, getFilterKeyForBlock, getGeneratedTopicsModelByTenant, getModelByTenant, getPlatformConfigsModelByTenant, getPlatformContextContent, getRollupPossibilities, getRoutePathToEditContent, getRoutePathToModerateContent, getRoutePathToPublishedContent, getTplModelByTenant, getVal, mergeAnnoDataIntoAnnotationsTags, parseSpecialConfigSyntax, processAuthorAndCommonFilters, _recursExtractBlocks as recursivelyExtractBlocks, segrigateDocs, setVal, toArray };
|
|
1777
|
+
export { AIChatSchema, AnnosElasticSyncProducer, AnnotationSchema, BASE_BULLMQ_CONFIG, BaseProducer, BaseWorker, ChunksElasticSyncProducer, ElasticSearchConnector, FILTER_IDS, GET_GLOBAL_BULLMQ_CONFIG, GeneratedTopicsSchema, MongoConnector, PlatformConfigsSchema, ProducerManager, RedisCacheConnector, SecretManagerConnector, TEMP_removeDuplicateFilters, TplSchema, UI_CONTENT, WorkerManager, _self_managed_buildAnnoHierarchyConfig, _self_managed_getFixedAnnoRollupBlocks, _self_managed_getFixedAnnoTagBlock, autoGenFilterConfigsFromTpl, buildFilterConfigurations, compareAndGroupBlocks, deleteVal, extractAllBlocksFromTpl, extractAndOrganizeBlocks, genTagId, generateFilterKey, getAIChatModelByTenant, getAnnotationsModelByTenant, getDbByTenant, getFilterKeyForBlock, getGeneratedTopicsModelByTenant, getModelByTenant, getPlatformConfigsModelByTenant, getPlatformContextContent, getRollupPossibilities, getRoutePathToEditContent, getRoutePathToModerateContent, getRoutePathToPublishedContent, getTplModelByTenant, getVal, mergeAnnoDataIntoAnnotationsTags, parseSpecialConfigSyntax, processAuthorAndCommonFilters, _recursExtractBlocks as recursivelyExtractBlocks, segrigateDocs, setVal, toArray };
|
package/dist/node.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Client } from '@elastic/elasticsearch';
|
|
2
2
|
import Redis from 'ioredis';
|
|
3
|
+
import * as _google_cloud_secret_manager_build_src_v1 from '@google-cloud/secret-manager/build/src/v1';
|
|
3
4
|
import * as mongoose from 'mongoose';
|
|
4
5
|
import mongoose__default, { Document, Types, Schema } from 'mongoose';
|
|
5
6
|
import * as bullmq from 'bullmq';
|
|
@@ -1313,6 +1314,35 @@ declare namespace RedisCacheConnector {
|
|
|
1313
1314
|
let instance: any;
|
|
1314
1315
|
}
|
|
1315
1316
|
|
|
1317
|
+
/**
|
|
1318
|
+
* Usage:
|
|
1319
|
+
* const sm = new SecretManagerConnector({
|
|
1320
|
+
* secrets: [
|
|
1321
|
+
* { name: 'globalConfigs', fallbackPath: 'db/config/globalConfigs.js' },
|
|
1322
|
+
* { name: 'creds-json', fallbackPath: 'creds.json' },
|
|
1323
|
+
* ]
|
|
1324
|
+
* });
|
|
1325
|
+
* await sm.connect();
|
|
1326
|
+
* const globalConfigs = SecretManagerConnector.getSecret('globalConfigs');
|
|
1327
|
+
* // or
|
|
1328
|
+
* const globalConfigs = SecretManagerConnector.getGlobalConfigs();
|
|
1329
|
+
*/
|
|
1330
|
+
declare class SecretManagerConnector {
|
|
1331
|
+
static getSecret(secretName: any): any;
|
|
1332
|
+
static getGlobalConfigs(): any;
|
|
1333
|
+
static getInstance(): any;
|
|
1334
|
+
constructor({ secrets }?: {
|
|
1335
|
+
secrets?: never[] | undefined;
|
|
1336
|
+
});
|
|
1337
|
+
client: _google_cloud_secret_manager_build_src_v1.SecretManagerServiceClient;
|
|
1338
|
+
secrets: any[];
|
|
1339
|
+
cache: {};
|
|
1340
|
+
connect(): Promise<void>;
|
|
1341
|
+
}
|
|
1342
|
+
declare namespace SecretManagerConnector {
|
|
1343
|
+
let instance: any;
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1316
1346
|
/**
|
|
1317
1347
|
* Get database connection by tenant
|
|
1318
1348
|
* @param tenant - Tenant identifier for the database
|
|
@@ -1744,4 +1774,4 @@ declare function GET_GLOBAL_BULLMQ_CONFIG({ env, redisCredentials }: {
|
|
|
1744
1774
|
};
|
|
1745
1775
|
}): Object;
|
|
1746
1776
|
|
|
1747
|
-
export { AIChatSchema, AnnosElasticSyncProducer, AnnotationSchema, BASE_BULLMQ_CONFIG, BaseProducer, BaseWorker, ChunksElasticSyncProducer, ElasticSearchConnector, FILTER_IDS, GET_GLOBAL_BULLMQ_CONFIG, GeneratedTopicsSchema, MongoConnector, PlatformConfigsSchema, ProducerManager, RedisCacheConnector, TEMP_removeDuplicateFilters, TplSchema, UI_CONTENT, WorkerManager, _self_managed_buildAnnoHierarchyConfig, _self_managed_getFixedAnnoRollupBlocks, _self_managed_getFixedAnnoTagBlock, autoGenFilterConfigsFromTpl, buildFilterConfigurations, compareAndGroupBlocks, deleteVal, extractAllBlocksFromTpl, extractAndOrganizeBlocks, genTagId, generateFilterKey, getAIChatModelByTenant, getAnnotationsModelByTenant, getDbByTenant, getFilterKeyForBlock, getGeneratedTopicsModelByTenant, getModelByTenant, getPlatformConfigsModelByTenant, getPlatformContextContent, getRollupPossibilities, getRoutePathToEditContent, getRoutePathToModerateContent, getRoutePathToPublishedContent, getTplModelByTenant, getVal, mergeAnnoDataIntoAnnotationsTags, parseSpecialConfigSyntax, processAuthorAndCommonFilters, _recursExtractBlocks as recursivelyExtractBlocks, segrigateDocs, setVal, toArray };
|
|
1777
|
+
export { AIChatSchema, AnnosElasticSyncProducer, AnnotationSchema, BASE_BULLMQ_CONFIG, BaseProducer, BaseWorker, ChunksElasticSyncProducer, ElasticSearchConnector, FILTER_IDS, GET_GLOBAL_BULLMQ_CONFIG, GeneratedTopicsSchema, MongoConnector, PlatformConfigsSchema, ProducerManager, RedisCacheConnector, SecretManagerConnector, TEMP_removeDuplicateFilters, TplSchema, UI_CONTENT, WorkerManager, _self_managed_buildAnnoHierarchyConfig, _self_managed_getFixedAnnoRollupBlocks, _self_managed_getFixedAnnoTagBlock, autoGenFilterConfigsFromTpl, buildFilterConfigurations, compareAndGroupBlocks, deleteVal, extractAllBlocksFromTpl, extractAndOrganizeBlocks, genTagId, generateFilterKey, getAIChatModelByTenant, getAnnotationsModelByTenant, getDbByTenant, getFilterKeyForBlock, getGeneratedTopicsModelByTenant, getModelByTenant, getPlatformConfigsModelByTenant, getPlatformContextContent, getRollupPossibilities, getRoutePathToEditContent, getRoutePathToModerateContent, getRoutePathToPublishedContent, getTplModelByTenant, getVal, mergeAnnoDataIntoAnnotationsTags, parseSpecialConfigSyntax, processAuthorAndCommonFilters, _recursExtractBlocks as recursivelyExtractBlocks, segrigateDocs, setVal, toArray };
|
package/dist/node.js
CHANGED
|
@@ -1683,6 +1683,7 @@ __export(node_exports, {
|
|
|
1683
1683
|
PlatformConfigsSchema: () => PlatformConfigs_default,
|
|
1684
1684
|
ProducerManager: () => import_ProducerManager.ProducerManager,
|
|
1685
1685
|
RedisCacheConnector: () => RedisCacheConnector,
|
|
1686
|
+
SecretManagerConnector: () => SecretManagerConnector,
|
|
1686
1687
|
TEMP_removeDuplicateFilters: () => TEMP_removeDuplicateFilters,
|
|
1687
1688
|
TplSchema: () => Tpl_default,
|
|
1688
1689
|
UI_CONTENT: () => UI_CONTENT,
|
|
@@ -3534,6 +3535,53 @@ var RedisCacheConnector = class _RedisCacheConnector {
|
|
|
3534
3535
|
};
|
|
3535
3536
|
RedisCacheConnector.instance = null;
|
|
3536
3537
|
|
|
3538
|
+
// src/SecretManagerConnector/index.js
|
|
3539
|
+
var import_secret_manager = require("@google-cloud/secret-manager");
|
|
3540
|
+
var import_path = __toESM(require("path"));
|
|
3541
|
+
var PROJECT_ID = "ok-framework";
|
|
3542
|
+
var SecretManagerConnector = class _SecretManagerConnector {
|
|
3543
|
+
constructor({ secrets = [] } = {}) {
|
|
3544
|
+
if (_SecretManagerConnector.instance) {
|
|
3545
|
+
throw new Error(
|
|
3546
|
+
"SecretManagerConnector instance already exists. Use SecretManagerConnector.getInstance() instead."
|
|
3547
|
+
);
|
|
3548
|
+
}
|
|
3549
|
+
this.client = new import_secret_manager.SecretManagerServiceClient();
|
|
3550
|
+
this.secrets = secrets;
|
|
3551
|
+
this.cache = {};
|
|
3552
|
+
_SecretManagerConnector.instance = this;
|
|
3553
|
+
}
|
|
3554
|
+
async connect() {
|
|
3555
|
+
for (const { name, fallbackPath } of this.secrets) {
|
|
3556
|
+
try {
|
|
3557
|
+
const secretPath = `projects/${PROJECT_ID}/secrets/${name}/versions/latest`;
|
|
3558
|
+
const [version] = await this.client.accessSecretVersion({ name: secretPath });
|
|
3559
|
+
this.cache[name] = JSON.parse(version.payload.data.toString("utf8"));
|
|
3560
|
+
console.log(` Secret Manager: loaded "${name}"`);
|
|
3561
|
+
} catch (err) {
|
|
3562
|
+
if (fallbackPath) {
|
|
3563
|
+
const fullPath = import_path.default.resolve(process.cwd(), fallbackPath);
|
|
3564
|
+
const module2 = await import(fullPath);
|
|
3565
|
+
this.cache[name] = module2.default || module2;
|
|
3566
|
+
console.log(` Secret Manager: "${name}" fallback to local file - ${err.message}`);
|
|
3567
|
+
} else {
|
|
3568
|
+
throw new Error(`Secret Manager: failed to load "${name}" - ${err.message}`);
|
|
3569
|
+
}
|
|
3570
|
+
}
|
|
3571
|
+
}
|
|
3572
|
+
}
|
|
3573
|
+
static getSecret(secretName) {
|
|
3574
|
+
return _SecretManagerConnector.instance.cache[secretName];
|
|
3575
|
+
}
|
|
3576
|
+
static getGlobalConfigs() {
|
|
3577
|
+
return _SecretManagerConnector.getSecret("globalConfigs");
|
|
3578
|
+
}
|
|
3579
|
+
static getInstance() {
|
|
3580
|
+
return _SecretManagerConnector.instance;
|
|
3581
|
+
}
|
|
3582
|
+
};
|
|
3583
|
+
SecretManagerConnector.instance = null;
|
|
3584
|
+
|
|
3537
3585
|
// src/node.ts
|
|
3538
3586
|
init_getDbByTenant();
|
|
3539
3587
|
var import_getModelByTenant2 = __toESM(require_getModelByTenant());
|
|
@@ -3562,6 +3610,7 @@ var import_GET_GLOBAL_BULLMQ_CONFIG = __toESM(require_GET_GLOBAL_BULLMQ_CONFIG()
|
|
|
3562
3610
|
PlatformConfigsSchema,
|
|
3563
3611
|
ProducerManager,
|
|
3564
3612
|
RedisCacheConnector,
|
|
3613
|
+
SecretManagerConnector,
|
|
3565
3614
|
TEMP_removeDuplicateFilters,
|
|
3566
3615
|
TplSchema,
|
|
3567
3616
|
UI_CONTENT,
|
package/dist/node.mjs
CHANGED
|
@@ -3482,6 +3482,53 @@ var RedisCacheConnector = class _RedisCacheConnector {
|
|
|
3482
3482
|
};
|
|
3483
3483
|
RedisCacheConnector.instance = null;
|
|
3484
3484
|
|
|
3485
|
+
// src/SecretManagerConnector/index.js
|
|
3486
|
+
import { SecretManagerServiceClient } from "@google-cloud/secret-manager";
|
|
3487
|
+
import path from "path";
|
|
3488
|
+
var PROJECT_ID = "ok-framework";
|
|
3489
|
+
var SecretManagerConnector = class _SecretManagerConnector {
|
|
3490
|
+
constructor({ secrets = [] } = {}) {
|
|
3491
|
+
if (_SecretManagerConnector.instance) {
|
|
3492
|
+
throw new Error(
|
|
3493
|
+
"SecretManagerConnector instance already exists. Use SecretManagerConnector.getInstance() instead."
|
|
3494
|
+
);
|
|
3495
|
+
}
|
|
3496
|
+
this.client = new SecretManagerServiceClient();
|
|
3497
|
+
this.secrets = secrets;
|
|
3498
|
+
this.cache = {};
|
|
3499
|
+
_SecretManagerConnector.instance = this;
|
|
3500
|
+
}
|
|
3501
|
+
async connect() {
|
|
3502
|
+
for (const { name, fallbackPath } of this.secrets) {
|
|
3503
|
+
try {
|
|
3504
|
+
const secretPath = `projects/${PROJECT_ID}/secrets/${name}/versions/latest`;
|
|
3505
|
+
const [version] = await this.client.accessSecretVersion({ name: secretPath });
|
|
3506
|
+
this.cache[name] = JSON.parse(version.payload.data.toString("utf8"));
|
|
3507
|
+
console.log(` Secret Manager: loaded "${name}"`);
|
|
3508
|
+
} catch (err) {
|
|
3509
|
+
if (fallbackPath) {
|
|
3510
|
+
const fullPath = path.resolve(process.cwd(), fallbackPath);
|
|
3511
|
+
const module = await import(fullPath);
|
|
3512
|
+
this.cache[name] = module.default || module;
|
|
3513
|
+
console.log(` Secret Manager: "${name}" fallback to local file - ${err.message}`);
|
|
3514
|
+
} else {
|
|
3515
|
+
throw new Error(`Secret Manager: failed to load "${name}" - ${err.message}`);
|
|
3516
|
+
}
|
|
3517
|
+
}
|
|
3518
|
+
}
|
|
3519
|
+
}
|
|
3520
|
+
static getSecret(secretName) {
|
|
3521
|
+
return _SecretManagerConnector.instance.cache[secretName];
|
|
3522
|
+
}
|
|
3523
|
+
static getGlobalConfigs() {
|
|
3524
|
+
return _SecretManagerConnector.getSecret("globalConfigs");
|
|
3525
|
+
}
|
|
3526
|
+
static getInstance() {
|
|
3527
|
+
return _SecretManagerConnector.instance;
|
|
3528
|
+
}
|
|
3529
|
+
};
|
|
3530
|
+
SecretManagerConnector.instance = null;
|
|
3531
|
+
|
|
3485
3532
|
// src/node.ts
|
|
3486
3533
|
init_getDbByTenant();
|
|
3487
3534
|
var import_getModelByTenant2 = __toESM(require_getModelByTenant());
|
|
@@ -3524,6 +3571,7 @@ export {
|
|
|
3524
3571
|
PlatformConfigs_default as PlatformConfigsSchema,
|
|
3525
3572
|
export_ProducerManager as ProducerManager,
|
|
3526
3573
|
RedisCacheConnector,
|
|
3574
|
+
SecretManagerConnector,
|
|
3527
3575
|
TEMP_removeDuplicateFilters,
|
|
3528
3576
|
Tpl_default as TplSchema,
|
|
3529
3577
|
UI_CONTENT,
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.
|
|
6
|
+
"version": "1.24.0",
|
|
7
7
|
"description": "Utility functions for both browser and Node.js",
|
|
8
8
|
"main": "dist/index.js",
|
|
9
9
|
"module": "dist/index.mjs",
|
|
@@ -76,6 +76,7 @@
|
|
|
76
76
|
},
|
|
77
77
|
"dependencies": {
|
|
78
78
|
"@elastic/elasticsearch": "^8.2.1",
|
|
79
|
+
"@google-cloud/secret-manager": "^6.1.1",
|
|
79
80
|
"bullmq": "^5.58.2",
|
|
80
81
|
"ioredis": "^5.6.1",
|
|
81
82
|
"lodash": "^4.17.23",
|