@xrystal/core 3.47.6 → 3.48.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/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Kafka as c,logLevel as l}from"kafkajs";import{bindLoaderTmpSync as k}from"../../utils";export default class KafkaForCore{_instance;_producer;clientId="";brokers="";username=null;password=null;#r;#a;constructor({system:
|
|
1
|
+
import{Kafka as c,logLevel as l}from"kafkajs";import{bindLoaderTmpSync as k,resolveKafkaJsSsl as f}from"../../utils";export default class KafkaForCore{_instance;_producer;clientId="";brokers="";username=null;password=null;#r;#a;constructor({system:r,configs:a}){this.#r=r;this.#a=a}onDispose=async()=>{await this.teardownKafka()};onInit=async()=>{await this.syncFromTmp();k(this)};syncFromTmp=async()=>{await this.teardownKafka();this.clientId=this.#a.all?.kafkaClientId;this.brokers=this.#a.all?.kafkaBrokers;this.username=this.#a.all?.kafkaUsername;this.password=this.#a.all?.kafkaPassword;if(this.#a.all.isKafkaPassive)return;const r=(Array.isArray(this.brokers)?this.brokers:this.brokers?.split(",")??[]).map((a)=>a?.trim()).filter(Boolean);if(r.length===0)throw Error("Broker list error");await this.kafkaLoader({clientId:this.clientId,brokers:r,username:this.username,password:this.password});await this.initializeKafkaInfrastructure()};teardownKafka=async()=>{if(this._producer){try{await this._producer.disconnect()}catch{}this._producer=void 0}};kafkaLoader=async({clientId:r,brokers:a,username:i,password:t})=>{const e={clientId:r,brokers:a,sasl:i&&t?{mechanism:"plain",username:i,password:t}:void 0,ssl:f(a),logLevel:l.ERROR,logCreator:()=>{return({level:s,log:n})=>{console.error(`Kafka ${n.message}`)}},retry:{initialRetryTime:100,retries:8}};try{const s=new c(e);this._instance=s;this._producer=s.producer();await this.producer.connect();return s}catch(s){console.error(`Kafka ${s}`)}};initializeKafkaInfrastructure=async()=>{const{kafkaBrokers:r,kafkaTopics:a,isKafkaPassive:i}={isKafkaPassive:process.env.IS_KAFKA_PASSIVE==="true"?!0:!1,kafkaBrokers:process.env?.KAFKA_BROKERS,kafkaTopics:[...new Set([...this.#a.all.kafkaTopics])]};if(i===!0||!r)return;const t=Array.isArray(a)?a:[];if(t.length===0)return;const e=this._instance.admin();try{await e.connect();const s=await e.listTopics(),n=t.filter((o)=>!s.includes(o)).map((o)=>({topic:o,numPartitions:1,replicationFactor:1}));if(n.length>0)await e.createTopics({waitForLeaders:!0,topics:n})}catch(s){}finally{await e.disconnect()}};sendMessage=async(r,a)=>{if(!this.producer)throw Error("Producer not ready");await this.producer.send({topic:r,messages:[{value:JSON.stringify(a)}],acks:0})};get producer(){return this._producer}get instance(){return this._instance}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export{default as pic}from"picocolors";export*from"../../utils/helpers/core";export*from"../../utils/helpers/path";export*from"../../utils/helpers/is";export*from"../../utils/helpers/id";export*from"../../utils/helpers/validates";export*from"../../utils/helpers/ip";export*from"../../utils/helpers/hash/crypto";export*from"../../utils/helpers/string";export*from"../../utils/helpers/objects";export*from"../../utils/helpers/locales";export*from"../../utils/helpers/timer";export*from"../../utils/helpers/date";export*from"../../utils/helpers/math";export*from"../../utils/helpers/regex/checkSpecialRegexControl";export*from"../../utils/helpers/filters";export*from"../../utils/helpers/framework";export*from"../../utils/helpers/protocol";export*from"../../utils/helpers/dto";export*from"../../utils/helpers/dispatch";export*from"../../utils/helpers/middleware";export*from"../../utils/helpers/context";export*from"../../utils/helpers/tmp";export*from"../../utils/helpers/state";export*from"../../utils/helpers/handlers";export*from"../../utils/helpers/runtime";
|
|
1
|
+
export{default as pic}from"picocolors";export*from"../../utils/helpers/core";export*from"../../utils/helpers/path";export*from"../../utils/helpers/is";export*from"../../utils/helpers/id";export*from"../../utils/helpers/validates";export*from"../../utils/helpers/ip";export*from"../../utils/helpers/hash/crypto";export*from"../../utils/helpers/string";export*from"../../utils/helpers/objects";export*from"../../utils/helpers/locales";export*from"../../utils/helpers/timer";export*from"../../utils/helpers/date";export*from"../../utils/helpers/math";export*from"../../utils/helpers/regex/checkSpecialRegexControl";export*from"../../utils/helpers/filters";export*from"../../utils/helpers/framework";export*from"../../utils/helpers/protocol";export*from"../../utils/helpers/dto";export*from"../../utils/helpers/dispatch";export*from"../../utils/helpers/middleware";export*from"../../utils/helpers/context";export*from"../../utils/helpers/tmp";export*from"../../utils/helpers/state";export*from"../../utils/helpers/handlers";export*from"../../utils/helpers/runtime";export*from"../../utils/helpers/kafka";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import t from"node:fs";export function resolveKafkaJsSsl(r=[]){const s=process.env.KAFKA_SSL==="true",c=r.some((n)=>/:9095\b/.test(n));if(!s&&!c)return!1;const e=process.env.KAFKA_SSL_CA||"/etc/tls/infra/ca.crt";try{if(e&&t.existsSync(e))return{ca:[t.readFileSync(e,"utf-8")],rejectUnauthorized:!1}}catch{}return{rejectUnauthorized:!1}}
|