@okf/ootils 1.23.0 → 1.24.1
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 +32 -1
- package/dist/node.d.ts +32 -1
- package/dist/node.js +52 -0
- package/dist/node.mjs +51 -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,36 @@ 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 getDbConfigs(): any;
|
|
1334
|
+
static getInstance(): any;
|
|
1335
|
+
constructor({ secrets }?: {
|
|
1336
|
+
secrets?: never[] | undefined;
|
|
1337
|
+
});
|
|
1338
|
+
client: _google_cloud_secret_manager_build_src_v1.SecretManagerServiceClient;
|
|
1339
|
+
secrets: any[];
|
|
1340
|
+
cache: {};
|
|
1341
|
+
connect(): Promise<void>;
|
|
1342
|
+
}
|
|
1343
|
+
declare namespace SecretManagerConnector {
|
|
1344
|
+
let instance: any;
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1316
1347
|
/**
|
|
1317
1348
|
* Get database connection by tenant
|
|
1318
1349
|
* @param tenant - Tenant identifier for the database
|
|
@@ -1744,4 +1775,4 @@ declare function GET_GLOBAL_BULLMQ_CONFIG({ env, redisCredentials }: {
|
|
|
1744
1775
|
};
|
|
1745
1776
|
}): Object;
|
|
1746
1777
|
|
|
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 };
|
|
1778
|
+
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,36 @@ 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 getDbConfigs(): any;
|
|
1334
|
+
static getInstance(): any;
|
|
1335
|
+
constructor({ secrets }?: {
|
|
1336
|
+
secrets?: never[] | undefined;
|
|
1337
|
+
});
|
|
1338
|
+
client: _google_cloud_secret_manager_build_src_v1.SecretManagerServiceClient;
|
|
1339
|
+
secrets: any[];
|
|
1340
|
+
cache: {};
|
|
1341
|
+
connect(): Promise<void>;
|
|
1342
|
+
}
|
|
1343
|
+
declare namespace SecretManagerConnector {
|
|
1344
|
+
let instance: any;
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1316
1347
|
/**
|
|
1317
1348
|
* Get database connection by tenant
|
|
1318
1349
|
* @param tenant - Tenant identifier for the database
|
|
@@ -1744,4 +1775,4 @@ declare function GET_GLOBAL_BULLMQ_CONFIG({ env, redisCredentials }: {
|
|
|
1744
1775
|
};
|
|
1745
1776
|
}): Object;
|
|
1746
1777
|
|
|
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 };
|
|
1778
|
+
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,56 @@ 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 getDbConfigs() {
|
|
3580
|
+
return _SecretManagerConnector.getSecret("dbConfigs");
|
|
3581
|
+
}
|
|
3582
|
+
static getInstance() {
|
|
3583
|
+
return _SecretManagerConnector.instance;
|
|
3584
|
+
}
|
|
3585
|
+
};
|
|
3586
|
+
SecretManagerConnector.instance = null;
|
|
3587
|
+
|
|
3537
3588
|
// src/node.ts
|
|
3538
3589
|
init_getDbByTenant();
|
|
3539
3590
|
var import_getModelByTenant2 = __toESM(require_getModelByTenant());
|
|
@@ -3562,6 +3613,7 @@ var import_GET_GLOBAL_BULLMQ_CONFIG = __toESM(require_GET_GLOBAL_BULLMQ_CONFIG()
|
|
|
3562
3613
|
PlatformConfigsSchema,
|
|
3563
3614
|
ProducerManager,
|
|
3564
3615
|
RedisCacheConnector,
|
|
3616
|
+
SecretManagerConnector,
|
|
3565
3617
|
TEMP_removeDuplicateFilters,
|
|
3566
3618
|
TplSchema,
|
|
3567
3619
|
UI_CONTENT,
|
package/dist/node.mjs
CHANGED
|
@@ -3482,6 +3482,56 @@ 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 getDbConfigs() {
|
|
3527
|
+
return _SecretManagerConnector.getSecret("dbConfigs");
|
|
3528
|
+
}
|
|
3529
|
+
static getInstance() {
|
|
3530
|
+
return _SecretManagerConnector.instance;
|
|
3531
|
+
}
|
|
3532
|
+
};
|
|
3533
|
+
SecretManagerConnector.instance = null;
|
|
3534
|
+
|
|
3485
3535
|
// src/node.ts
|
|
3486
3536
|
init_getDbByTenant();
|
|
3487
3537
|
var import_getModelByTenant2 = __toESM(require_getModelByTenant());
|
|
@@ -3524,6 +3574,7 @@ export {
|
|
|
3524
3574
|
PlatformConfigs_default as PlatformConfigsSchema,
|
|
3525
3575
|
export_ProducerManager as ProducerManager,
|
|
3526
3576
|
RedisCacheConnector,
|
|
3577
|
+
SecretManagerConnector,
|
|
3527
3578
|
TEMP_removeDuplicateFilters,
|
|
3528
3579
|
Tpl_default as TplSchema,
|
|
3529
3580
|
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.1",
|
|
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",
|