@jsfsi-core/ts-nodejs 1.0.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/index.cjs ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const K=require("path"),F=require("fs"),U=require("os"),B=require("crypto");function J(y){return y&&y.__esModule&&Object.prototype.hasOwnProperty.call(y,"default")?y.default:y}var I={exports:{}};const G="16.6.0",k={version:G};var P;function z(){if(P)return I.exports;P=1;const y=F,t=K,n=U,s=B,O=k.version,b=/(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;function D(e){const u={};let l=e.toString();l=l.replace(/\r\n?/mg,`
2
+ `);let v;for(;(v=b.exec(l))!=null;){const N=v[1];let i=v[2]||"";i=i.trim();const h=i[0];i=i.replace(/^(['"`])([\s\S]*)\1$/mg,"$2"),h==='"'&&(i=i.replace(/\\n/g,`
3
+ `),i=i.replace(/\\r/g,"\r")),u[N]=i}return u}function S(e){const u=d(e);e.path=u;const l=g.configDotenv(e);if(!l.parsed){const h=new Error(`MISSING_DATA: Cannot parse ${u} for an unknown reason`);throw h.code="MISSING_DATA",h}const v=r(e).split(","),N=v.length;let i;for(let h=0;h<N;h++)try{const w=v[h].trim(),T=a(l,w);i=g.decrypt(T.ciphertext,T.key);break}catch(w){if(h+1>=N)throw w}return g.parse(i)}function m(e){console.log(`[dotenv@${O}][WARN] ${e}`)}function R(e){console.log(`[dotenv@${O}][DEBUG] ${e}`)}function A(e){console.log(`[dotenv@${O}] ${e}`)}function r(e){return e&&e.DOTENV_KEY&&e.DOTENV_KEY.length>0?e.DOTENV_KEY:process.env.DOTENV_KEY&&process.env.DOTENV_KEY.length>0?process.env.DOTENV_KEY:""}function a(e,u){let l;try{l=new URL(u)}catch(w){if(w.code==="ERR_INVALID_URL"){const T=new Error("INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=development");throw T.code="INVALID_DOTENV_KEY",T}throw w}const v=l.password;if(!v){const w=new Error("INVALID_DOTENV_KEY: Missing key part");throw w.code="INVALID_DOTENV_KEY",w}const N=l.searchParams.get("environment");if(!N){const w=new Error("INVALID_DOTENV_KEY: Missing environment part");throw w.code="INVALID_DOTENV_KEY",w}const i=`DOTENV_VAULT_${N.toUpperCase()}`,h=e.parsed[i];if(!h){const w=new Error(`NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ${i} in your .env.vault file.`);throw w.code="NOT_FOUND_DOTENV_ENVIRONMENT",w}return{ciphertext:h,key:v}}function d(e){let u=null;if(e&&e.path&&e.path.length>0)if(Array.isArray(e.path))for(const l of e.path)y.existsSync(l)&&(u=l.endsWith(".vault")?l:`${l}.vault`);else u=e.path.endsWith(".vault")?e.path:`${e.path}.vault`;else u=t.resolve(process.cwd(),".env.vault");return y.existsSync(u)?u:null}function o(e){return e[0]==="~"?t.join(n.homedir(),e.slice(1)):e}function f(e){const u=!!(e&&e.debug),l=!!(e&&e.quiet);(u||!l)&&A("Loading env from encrypted .env.vault");const v=g._parseVault(e);let N=process.env;return e&&e.processEnv!=null&&(N=e.processEnv),g.populate(N,v,e),{parsed:v}}function p(e){const u=t.resolve(process.cwd(),".env");let l="utf8";const v=!!(e&&e.debug),N=!!(e&&e.quiet);e&&e.encoding?l=e.encoding:v&&R("No encoding is specified. UTF-8 is used by default");let i=[u];if(e&&e.path)if(!Array.isArray(e.path))i=[o(e.path)];else{i=[];for(const $ of e.path)i.push(o($))}let h;const w={};for(const $ of i)try{const L=g.parse(y.readFileSync($,{encoding:l}));g.populate(w,L,e)}catch(L){v&&R(`Failed to load ${$} ${L.message}`),h=L}let T=process.env;if(e&&e.processEnv!=null&&(T=e.processEnv),g.populate(T,w,e),v||!N){const $=Object.keys(w).length,L=[];for(const j of i)try{const q=t.relative(process.cwd(),j);L.push(q)}catch{}A(`injecting env (${$}) from ${L.join(",")}`)}return h?{parsed:w,error:h}:{parsed:w}}function E(e){if(r(e).length===0)return g.configDotenv(e);const u=d(e);return u?g._configVault(e):(m(`You set DOTENV_KEY but you are missing a .env.vault file at ${u}. Did you forget to build it?`),g.configDotenv(e))}function c(e,u){const l=Buffer.from(u.slice(-64),"hex");let v=Buffer.from(e,"base64");const N=v.subarray(0,12),i=v.subarray(-16);v=v.subarray(12,-16);try{const h=s.createDecipheriv("aes-256-gcm",l,N);return h.setAuthTag(i),`${h.update(v)}${h.final()}`}catch(h){const w=h instanceof RangeError,T=h.message==="Invalid key length",$=h.message==="Unsupported state or unable to authenticate data";if(w||T){const L=new Error("INVALID_DOTENV_KEY: It must be 64 characters long (or more)");throw L.code="INVALID_DOTENV_KEY",L}else if($){const L=new Error("DECRYPTION_FAILED: Please check your DOTENV_KEY");throw L.code="DECRYPTION_FAILED",L}else throw h}}function V(e,u,l={}){const v=!!(l&&l.debug),N=!!(l&&l.override);if(typeof u!="object"){const i=new Error("OBJECT_REQUIRED: Please check the processEnv argument being passed to populate");throw i.code="OBJECT_REQUIRED",i}for(const i of Object.keys(u))Object.prototype.hasOwnProperty.call(e,i)?(N===!0&&(e[i]=u[i]),v&&R(N===!0?`"${i}" is already defined and WAS overwritten`:`"${i}" is already defined and was NOT overwritten`)):e[i]=u[i]}const g={configDotenv:p,_configVault:f,_parseVault:S,config:E,decrypt:c,parse:D,populate:V};return I.exports.configDotenv=g.configDotenv,I.exports._configVault=g._configVault,I.exports._parseVault=g._parseVault,I.exports.config=g.config,I.exports.decrypt=g.decrypt,I.exports.parse=g.parse,I.exports.populate=g.populate,I.exports=g,I.exports}var W=z();const Q=(y={})=>{const{env:t,configPath:n}=y,s=K.resolve(__dirname,`${n??"."}/.env${t?`.${t}`:""}`),{parsed:_}=W.config({path:s});return _};var x,C;function H(){if(C)return x;C=1,x=O,O.default=O,O.stable=m,O.stableStringify=m;var y="[...]",t="[Circular]",n=[],s=[];function _(){return{depthLimit:Number.MAX_SAFE_INTEGER,edgesLimit:Number.MAX_SAFE_INTEGER}}function O(r,a,d,o){typeof o>"u"&&(o=_()),D(r,"",0,[],void 0,0,o);var f;try{s.length===0?f=JSON.stringify(r,a,d):f=JSON.stringify(r,A(a),d)}catch{return JSON.stringify("[unable to serialize, circular reference is too complex to analyze]")}finally{for(;n.length!==0;){var p=n.pop();p.length===4?Object.defineProperty(p[0],p[1],p[3]):p[0][p[1]]=p[2]}}return f}function b(r,a,d,o){var f=Object.getOwnPropertyDescriptor(o,d);f.get!==void 0?f.configurable?(Object.defineProperty(o,d,{value:r}),n.push([o,d,a,f])):s.push([a,d,r]):(o[d]=r,n.push([o,d,a]))}function D(r,a,d,o,f,p,E){p+=1;var c;if(typeof r=="object"&&r!==null){for(c=0;c<o.length;c++)if(o[c]===r){b(t,r,a,f);return}if(typeof E.depthLimit<"u"&&p>E.depthLimit){b(y,r,a,f);return}if(typeof E.edgesLimit<"u"&&d+1>E.edgesLimit){b(y,r,a,f);return}if(o.push(r),Array.isArray(r))for(c=0;c<r.length;c++)D(r[c],c,c,o,r,p,E);else{var V=Object.keys(r);for(c=0;c<V.length;c++){var g=V[c];D(r[g],g,c,o,r,p,E)}}o.pop()}}function S(r,a){return r<a?-1:r>a?1:0}function m(r,a,d,o){typeof o>"u"&&(o=_());var f=R(r,"",0,[],void 0,0,o)||r,p;try{s.length===0?p=JSON.stringify(f,a,d):p=JSON.stringify(f,A(a),d)}catch{return JSON.stringify("[unable to serialize, circular reference is too complex to analyze]")}finally{for(;n.length!==0;){var E=n.pop();E.length===4?Object.defineProperty(E[0],E[1],E[3]):E[0][E[1]]=E[2]}}return p}function R(r,a,d,o,f,p,E){p+=1;var c;if(typeof r=="object"&&r!==null){for(c=0;c<o.length;c++)if(o[c]===r){b(t,r,a,f);return}try{if(typeof r.toJSON=="function")return}catch{return}if(typeof E.depthLimit<"u"&&p>E.depthLimit){b(y,r,a,f);return}if(typeof E.edgesLimit<"u"&&d+1>E.edgesLimit){b(y,r,a,f);return}if(o.push(r),Array.isArray(r))for(c=0;c<r.length;c++)R(r[c],c,c,o,r,p,E);else{var V={},g=Object.keys(r).sort(S);for(c=0;c<g.length;c++){var e=g[c];R(r[e],e,c,o,r,p,E),V[e]=r[e]}if(typeof f<"u")n.push([f,a,r]),f[a]=V;else return V}o.pop()}}function A(r){return r=typeof r<"u"?r:function(a,d){return d},function(a,d){if(s.length>0)for(var o=0;o<s.length;o++){var f=s[o];if(f[1]===a&&f[0]===d){d=f[2],s.splice(o,1);break}}return r.call(this,a,d)}}return x}var X=H();const Z=J(X),Y={debug:"debug",verbose:"debug",log:"log",warn:"warn",error:"error",fatal:"error"},ee={verbose:"DEFAULT",debug:"DEBUG",log:"INFO",warn:"WARNING",error:"ERROR",fatal:"CRITICAL"},te=["x-api-key","x-api-token","x-key","x-token","cookie","password","pass","psw","auth","authentication","authorization","token","access_token","client-secret","credentials","secret"];class re{constructor(t,n={}){this.module=t,n.logLevels&&(this.levels=new Set(n.logLevels))}levels=new Set(["verbose","debug","log","warn","error","fatal"]);mapLogLevelToConsoleMethod(t){return Y[t]}write(t,n,s,_,O){if(!this.levels.has(t))return;const b=this.buildLog(t,n,s,_,O),D=Z(b,this.sensitiveReplacer),S=this.mapLogLevelToConsoleMethod(t);console[S](D)}buildLog(t,n,s,_,O){const{writeMetadata:b,writeContext:D,writeError:S}=this.sanitizeLog(s,_,O),m={};return typeof n=="string"&&(m.textPayload=n),!b&&typeof n!="string"&&!(n instanceof Error)&&(m.metadata=n),n instanceof Error&&(m.error=JSON.stringify(n,Object.getOwnPropertyNames(n))),D&&(m.context=D),b&&(m.metadata=b),!m.error&&S&&(m.error=JSON.stringify(S,Object.getOwnPropertyNames(S))),{severity:ee[t],module:this.module,textPayload:m.textPayload,message:m}}sanitizeLog(t,n,s){if(n instanceof Error&&(!s||typeof s=="string"))return{writeMetadata:void 0,writeContext:t||s,writeError:n};let _=n,O=t;return typeof _=="string"&&!t&&(O=_,_=void 0),{writeMetadata:_,writeContext:O,writeError:s}}sensitiveReplacer(t,n){return te.includes(t.toLowerCase())?"[HIDDEN BY LOGGER]":n}debug(t,n,s){this.write("debug",t,s,n)}verbose(t,n,s){this.write("verbose",t,s,n)}log(t,n,s){this.write("log",t,s,n)}warn(t,n,s,_){this.write("warn",t,_,n,s)}error(t,n,s,_){this.write("error",t,_,n,s)}fatal(t,n,s,_){this.write("fatal",t,_,n,s)}setLogLevels(t){this.levels=new Set(t)}}class ne{debug=()=>{};verbose=()=>{};log=()=>{};warn=()=>{};error=()=>{};fatal=()=>{};setLogLevels=()=>{}}class M{constructor(t){this.dataSource=t}em;static newInstance(t){const n=t.constructor;return new n(t.dataSource)}withEntityManager(t){return this.em=t,this}withRepositoryManager(t){return M.newInstance(this).withEntityManager(t.em)}lockInTransaction(t="pessimistic_write"){return this.em?{mode:t}:void 0}getRepository(t){return this.em?this.em.getRepository(t):this.dataSource.getRepository(t)}async withTransaction(t){let n;return await this.dataSource.transaction(async s=>{n=await t(M.newInstance(this).withEntityManager(s))}),n}}const oe=y=>({...y,withTransaction:async t=>await t(y),withRepositoryManager:()=>y}),ie=(y,t)=>`unaccent(LOWER(${y})) ILIKE unaccent(LOWER(:${t}))`,se=Object.freeze(Object.defineProperty({__proto__:null,unaccentSearch:ie},Symbol.toStringTag,{value:"Module"}));exports.GCPLogger=re;exports.LogLevelToConsoleMethodMap=Y;exports.MockLogger=ne;exports.TransactionalRepository=M;exports.buildTransactionalRepositoryMock=oe;exports.loadEnvConfig=Q;exports.postgres=se;
package/dist/index.mjs ADDED
@@ -0,0 +1,499 @@
1
+ import K from "path";
2
+ import F from "fs";
3
+ import U from "os";
4
+ import q from "crypto";
5
+ function B(y) {
6
+ return y && y.__esModule && Object.prototype.hasOwnProperty.call(y, "default") ? y.default : y;
7
+ }
8
+ var T = { exports: {} };
9
+ const J = "16.6.0", G = {
10
+ version: J
11
+ };
12
+ var P;
13
+ function z() {
14
+ if (P) return T.exports;
15
+ P = 1;
16
+ const y = F, t = K, n = U, s = q, N = G.version, O = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
17
+ function L(e) {
18
+ const u = {};
19
+ let l = e.toString();
20
+ l = l.replace(/\r\n?/mg, `
21
+ `);
22
+ let p;
23
+ for (; (p = O.exec(l)) != null; ) {
24
+ const m = p[1];
25
+ let i = p[2] || "";
26
+ i = i.trim();
27
+ const h = i[0];
28
+ i = i.replace(/^(['"`])([\s\S]*)\1$/mg, "$2"), h === '"' && (i = i.replace(/\\n/g, `
29
+ `), i = i.replace(/\\r/g, "\r")), u[m] = i;
30
+ }
31
+ return u;
32
+ }
33
+ function S(e) {
34
+ const u = d(e);
35
+ e.path = u;
36
+ const l = g.configDotenv(e);
37
+ if (!l.parsed) {
38
+ const h = new Error(`MISSING_DATA: Cannot parse ${u} for an unknown reason`);
39
+ throw h.code = "MISSING_DATA", h;
40
+ }
41
+ const p = r(e).split(","), m = p.length;
42
+ let i;
43
+ for (let h = 0; h < m; h++)
44
+ try {
45
+ const w = p[h].trim(), I = a(l, w);
46
+ i = g.decrypt(I.ciphertext, I.key);
47
+ break;
48
+ } catch (w) {
49
+ if (h + 1 >= m)
50
+ throw w;
51
+ }
52
+ return g.parse(i);
53
+ }
54
+ function b(e) {
55
+ console.log(`[dotenv@${N}][WARN] ${e}`);
56
+ }
57
+ function V(e) {
58
+ console.log(`[dotenv@${N}][DEBUG] ${e}`);
59
+ }
60
+ function A(e) {
61
+ console.log(`[dotenv@${N}] ${e}`);
62
+ }
63
+ function r(e) {
64
+ return e && e.DOTENV_KEY && e.DOTENV_KEY.length > 0 ? e.DOTENV_KEY : process.env.DOTENV_KEY && process.env.DOTENV_KEY.length > 0 ? process.env.DOTENV_KEY : "";
65
+ }
66
+ function a(e, u) {
67
+ let l;
68
+ try {
69
+ l = new URL(u);
70
+ } catch (w) {
71
+ if (w.code === "ERR_INVALID_URL") {
72
+ const I = new Error("INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=development");
73
+ throw I.code = "INVALID_DOTENV_KEY", I;
74
+ }
75
+ throw w;
76
+ }
77
+ const p = l.password;
78
+ if (!p) {
79
+ const w = new Error("INVALID_DOTENV_KEY: Missing key part");
80
+ throw w.code = "INVALID_DOTENV_KEY", w;
81
+ }
82
+ const m = l.searchParams.get("environment");
83
+ if (!m) {
84
+ const w = new Error("INVALID_DOTENV_KEY: Missing environment part");
85
+ throw w.code = "INVALID_DOTENV_KEY", w;
86
+ }
87
+ const i = `DOTENV_VAULT_${m.toUpperCase()}`, h = e.parsed[i];
88
+ if (!h) {
89
+ const w = new Error(`NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ${i} in your .env.vault file.`);
90
+ throw w.code = "NOT_FOUND_DOTENV_ENVIRONMENT", w;
91
+ }
92
+ return { ciphertext: h, key: p };
93
+ }
94
+ function d(e) {
95
+ let u = null;
96
+ if (e && e.path && e.path.length > 0)
97
+ if (Array.isArray(e.path))
98
+ for (const l of e.path)
99
+ y.existsSync(l) && (u = l.endsWith(".vault") ? l : `${l}.vault`);
100
+ else
101
+ u = e.path.endsWith(".vault") ? e.path : `${e.path}.vault`;
102
+ else
103
+ u = t.resolve(process.cwd(), ".env.vault");
104
+ return y.existsSync(u) ? u : null;
105
+ }
106
+ function o(e) {
107
+ return e[0] === "~" ? t.join(n.homedir(), e.slice(1)) : e;
108
+ }
109
+ function f(e) {
110
+ const u = !!(e && e.debug), l = !!(e && e.quiet);
111
+ (u || !l) && A("Loading env from encrypted .env.vault");
112
+ const p = g._parseVault(e);
113
+ let m = process.env;
114
+ return e && e.processEnv != null && (m = e.processEnv), g.populate(m, p, e), { parsed: p };
115
+ }
116
+ function v(e) {
117
+ const u = t.resolve(process.cwd(), ".env");
118
+ let l = "utf8";
119
+ const p = !!(e && e.debug), m = !!(e && e.quiet);
120
+ e && e.encoding ? l = e.encoding : p && V("No encoding is specified. UTF-8 is used by default");
121
+ let i = [u];
122
+ if (e && e.path)
123
+ if (!Array.isArray(e.path))
124
+ i = [o(e.path)];
125
+ else {
126
+ i = [];
127
+ for (const $ of e.path)
128
+ i.push(o($));
129
+ }
130
+ let h;
131
+ const w = {};
132
+ for (const $ of i)
133
+ try {
134
+ const D = g.parse(y.readFileSync($, { encoding: l }));
135
+ g.populate(w, D, e);
136
+ } catch (D) {
137
+ p && V(`Failed to load ${$} ${D.message}`), h = D;
138
+ }
139
+ let I = process.env;
140
+ if (e && e.processEnv != null && (I = e.processEnv), g.populate(I, w, e), p || !m) {
141
+ const $ = Object.keys(w).length, D = [];
142
+ for (const Y of i)
143
+ try {
144
+ const j = t.relative(process.cwd(), Y);
145
+ D.push(j);
146
+ } catch {
147
+ }
148
+ A(`injecting env (${$}) from ${D.join(",")}`);
149
+ }
150
+ return h ? { parsed: w, error: h } : { parsed: w };
151
+ }
152
+ function E(e) {
153
+ if (r(e).length === 0)
154
+ return g.configDotenv(e);
155
+ const u = d(e);
156
+ return u ? g._configVault(e) : (b(`You set DOTENV_KEY but you are missing a .env.vault file at ${u}. Did you forget to build it?`), g.configDotenv(e));
157
+ }
158
+ function c(e, u) {
159
+ const l = Buffer.from(u.slice(-64), "hex");
160
+ let p = Buffer.from(e, "base64");
161
+ const m = p.subarray(0, 12), i = p.subarray(-16);
162
+ p = p.subarray(12, -16);
163
+ try {
164
+ const h = s.createDecipheriv("aes-256-gcm", l, m);
165
+ return h.setAuthTag(i), `${h.update(p)}${h.final()}`;
166
+ } catch (h) {
167
+ const w = h instanceof RangeError, I = h.message === "Invalid key length", $ = h.message === "Unsupported state or unable to authenticate data";
168
+ if (w || I) {
169
+ const D = new Error("INVALID_DOTENV_KEY: It must be 64 characters long (or more)");
170
+ throw D.code = "INVALID_DOTENV_KEY", D;
171
+ } else if ($) {
172
+ const D = new Error("DECRYPTION_FAILED: Please check your DOTENV_KEY");
173
+ throw D.code = "DECRYPTION_FAILED", D;
174
+ } else
175
+ throw h;
176
+ }
177
+ }
178
+ function R(e, u, l = {}) {
179
+ const p = !!(l && l.debug), m = !!(l && l.override);
180
+ if (typeof u != "object") {
181
+ const i = new Error("OBJECT_REQUIRED: Please check the processEnv argument being passed to populate");
182
+ throw i.code = "OBJECT_REQUIRED", i;
183
+ }
184
+ for (const i of Object.keys(u))
185
+ Object.prototype.hasOwnProperty.call(e, i) ? (m === !0 && (e[i] = u[i]), p && V(m === !0 ? `"${i}" is already defined and WAS overwritten` : `"${i}" is already defined and was NOT overwritten`)) : e[i] = u[i];
186
+ }
187
+ const g = {
188
+ configDotenv: v,
189
+ _configVault: f,
190
+ _parseVault: S,
191
+ config: E,
192
+ decrypt: c,
193
+ parse: L,
194
+ populate: R
195
+ };
196
+ return T.exports.configDotenv = g.configDotenv, T.exports._configVault = g._configVault, T.exports._parseVault = g._parseVault, T.exports.config = g.config, T.exports.decrypt = g.decrypt, T.exports.parse = g.parse, T.exports.populate = g.populate, T.exports = g, T.exports;
197
+ }
198
+ var W = z();
199
+ const se = (y = {}) => {
200
+ const { env: t, configPath: n } = y, s = K.resolve(__dirname, `${n ?? "."}/.env${t ? `.${t}` : ""}`), { parsed: _ } = W.config({ path: s });
201
+ return _;
202
+ };
203
+ var x, C;
204
+ function k() {
205
+ if (C) return x;
206
+ C = 1, x = N, N.default = N, N.stable = b, N.stableStringify = b;
207
+ var y = "[...]", t = "[Circular]", n = [], s = [];
208
+ function _() {
209
+ return {
210
+ depthLimit: Number.MAX_SAFE_INTEGER,
211
+ edgesLimit: Number.MAX_SAFE_INTEGER
212
+ };
213
+ }
214
+ function N(r, a, d, o) {
215
+ typeof o > "u" && (o = _()), L(r, "", 0, [], void 0, 0, o);
216
+ var f;
217
+ try {
218
+ s.length === 0 ? f = JSON.stringify(r, a, d) : f = JSON.stringify(r, A(a), d);
219
+ } catch {
220
+ return JSON.stringify("[unable to serialize, circular reference is too complex to analyze]");
221
+ } finally {
222
+ for (; n.length !== 0; ) {
223
+ var v = n.pop();
224
+ v.length === 4 ? Object.defineProperty(v[0], v[1], v[3]) : v[0][v[1]] = v[2];
225
+ }
226
+ }
227
+ return f;
228
+ }
229
+ function O(r, a, d, o) {
230
+ var f = Object.getOwnPropertyDescriptor(o, d);
231
+ f.get !== void 0 ? f.configurable ? (Object.defineProperty(o, d, { value: r }), n.push([o, d, a, f])) : s.push([a, d, r]) : (o[d] = r, n.push([o, d, a]));
232
+ }
233
+ function L(r, a, d, o, f, v, E) {
234
+ v += 1;
235
+ var c;
236
+ if (typeof r == "object" && r !== null) {
237
+ for (c = 0; c < o.length; c++)
238
+ if (o[c] === r) {
239
+ O(t, r, a, f);
240
+ return;
241
+ }
242
+ if (typeof E.depthLimit < "u" && v > E.depthLimit) {
243
+ O(y, r, a, f);
244
+ return;
245
+ }
246
+ if (typeof E.edgesLimit < "u" && d + 1 > E.edgesLimit) {
247
+ O(y, r, a, f);
248
+ return;
249
+ }
250
+ if (o.push(r), Array.isArray(r))
251
+ for (c = 0; c < r.length; c++)
252
+ L(r[c], c, c, o, r, v, E);
253
+ else {
254
+ var R = Object.keys(r);
255
+ for (c = 0; c < R.length; c++) {
256
+ var g = R[c];
257
+ L(r[g], g, c, o, r, v, E);
258
+ }
259
+ }
260
+ o.pop();
261
+ }
262
+ }
263
+ function S(r, a) {
264
+ return r < a ? -1 : r > a ? 1 : 0;
265
+ }
266
+ function b(r, a, d, o) {
267
+ typeof o > "u" && (o = _());
268
+ var f = V(r, "", 0, [], void 0, 0, o) || r, v;
269
+ try {
270
+ s.length === 0 ? v = JSON.stringify(f, a, d) : v = JSON.stringify(f, A(a), d);
271
+ } catch {
272
+ return JSON.stringify("[unable to serialize, circular reference is too complex to analyze]");
273
+ } finally {
274
+ for (; n.length !== 0; ) {
275
+ var E = n.pop();
276
+ E.length === 4 ? Object.defineProperty(E[0], E[1], E[3]) : E[0][E[1]] = E[2];
277
+ }
278
+ }
279
+ return v;
280
+ }
281
+ function V(r, a, d, o, f, v, E) {
282
+ v += 1;
283
+ var c;
284
+ if (typeof r == "object" && r !== null) {
285
+ for (c = 0; c < o.length; c++)
286
+ if (o[c] === r) {
287
+ O(t, r, a, f);
288
+ return;
289
+ }
290
+ try {
291
+ if (typeof r.toJSON == "function")
292
+ return;
293
+ } catch {
294
+ return;
295
+ }
296
+ if (typeof E.depthLimit < "u" && v > E.depthLimit) {
297
+ O(y, r, a, f);
298
+ return;
299
+ }
300
+ if (typeof E.edgesLimit < "u" && d + 1 > E.edgesLimit) {
301
+ O(y, r, a, f);
302
+ return;
303
+ }
304
+ if (o.push(r), Array.isArray(r))
305
+ for (c = 0; c < r.length; c++)
306
+ V(r[c], c, c, o, r, v, E);
307
+ else {
308
+ var R = {}, g = Object.keys(r).sort(S);
309
+ for (c = 0; c < g.length; c++) {
310
+ var e = g[c];
311
+ V(r[e], e, c, o, r, v, E), R[e] = r[e];
312
+ }
313
+ if (typeof f < "u")
314
+ n.push([f, a, r]), f[a] = R;
315
+ else
316
+ return R;
317
+ }
318
+ o.pop();
319
+ }
320
+ }
321
+ function A(r) {
322
+ return r = typeof r < "u" ? r : function(a, d) {
323
+ return d;
324
+ }, function(a, d) {
325
+ if (s.length > 0)
326
+ for (var o = 0; o < s.length; o++) {
327
+ var f = s[o];
328
+ if (f[1] === a && f[0] === d) {
329
+ d = f[2], s.splice(o, 1);
330
+ break;
331
+ }
332
+ }
333
+ return r.call(this, a, d);
334
+ };
335
+ }
336
+ return x;
337
+ }
338
+ var Q = k();
339
+ const H = /* @__PURE__ */ B(Q), X = {
340
+ debug: "debug",
341
+ verbose: "debug",
342
+ log: "log",
343
+ warn: "warn",
344
+ error: "error",
345
+ fatal: "error"
346
+ }, Z = {
347
+ verbose: "DEFAULT",
348
+ debug: "DEBUG",
349
+ log: "INFO",
350
+ warn: "WARNING",
351
+ error: "ERROR",
352
+ fatal: "CRITICAL"
353
+ }, ee = [
354
+ "x-api-key",
355
+ "x-api-token",
356
+ "x-key",
357
+ "x-token",
358
+ "cookie",
359
+ "password",
360
+ "pass",
361
+ "psw",
362
+ "auth",
363
+ "authentication",
364
+ "authorization",
365
+ "token",
366
+ "access_token",
367
+ "client-secret",
368
+ "credentials",
369
+ "secret"
370
+ ];
371
+ class ce {
372
+ constructor(t, n = {}) {
373
+ this.module = t, n.logLevels && (this.levels = new Set(n.logLevels));
374
+ }
375
+ levels = /* @__PURE__ */ new Set(["verbose", "debug", "log", "warn", "error", "fatal"]);
376
+ mapLogLevelToConsoleMethod(t) {
377
+ return X[t];
378
+ }
379
+ write(t, n, s, _, N) {
380
+ if (!this.levels.has(t))
381
+ return;
382
+ const O = this.buildLog(t, n, s, _, N), L = H(O, this.sensitiveReplacer), S = this.mapLogLevelToConsoleMethod(t);
383
+ console[S](L);
384
+ }
385
+ buildLog(t, n, s, _, N) {
386
+ const { writeMetadata: O, writeContext: L, writeError: S } = this.sanitizeLog(s, _, N), b = {};
387
+ return typeof n == "string" && (b.textPayload = n), !O && typeof n != "string" && !(n instanceof Error) && (b.metadata = n), n instanceof Error && (b.error = JSON.stringify(n, Object.getOwnPropertyNames(n))), L && (b.context = L), O && (b.metadata = O), !b.error && S && (b.error = JSON.stringify(S, Object.getOwnPropertyNames(S))), {
388
+ severity: Z[t],
389
+ module: this.module,
390
+ textPayload: b.textPayload,
391
+ message: b
392
+ };
393
+ }
394
+ sanitizeLog(t, n, s) {
395
+ if (n instanceof Error && (!s || typeof s == "string"))
396
+ return {
397
+ writeMetadata: void 0,
398
+ writeContext: t || s,
399
+ writeError: n
400
+ };
401
+ let _ = n, N = t;
402
+ return typeof _ == "string" && !t && (N = _, _ = void 0), {
403
+ writeMetadata: _,
404
+ writeContext: N,
405
+ writeError: s
406
+ };
407
+ }
408
+ sensitiveReplacer(t, n) {
409
+ return ee.includes(t.toLowerCase()) ? "[HIDDEN BY LOGGER]" : n;
410
+ }
411
+ debug(t, n, s) {
412
+ this.write("debug", t, s, n);
413
+ }
414
+ verbose(t, n, s) {
415
+ this.write("verbose", t, s, n);
416
+ }
417
+ log(t, n, s) {
418
+ this.write("log", t, s, n);
419
+ }
420
+ warn(t, n, s, _) {
421
+ this.write("warn", t, _, n, s);
422
+ }
423
+ error(t, n, s, _) {
424
+ this.write("error", t, _, n, s);
425
+ }
426
+ fatal(t, n, s, _) {
427
+ this.write("fatal", t, _, n, s);
428
+ }
429
+ setLogLevels(t) {
430
+ this.levels = new Set(t);
431
+ }
432
+ }
433
+ class ae {
434
+ debug = () => {
435
+ };
436
+ verbose = () => {
437
+ };
438
+ log = () => {
439
+ };
440
+ warn = () => {
441
+ };
442
+ error = () => {
443
+ };
444
+ fatal = () => {
445
+ };
446
+ setLogLevels = () => {
447
+ };
448
+ }
449
+ class M {
450
+ constructor(t) {
451
+ this.dataSource = t;
452
+ }
453
+ em;
454
+ static newInstance(t) {
455
+ const n = t.constructor;
456
+ return new n(t.dataSource);
457
+ }
458
+ withEntityManager(t) {
459
+ return this.em = t, this;
460
+ }
461
+ withRepositoryManager(t) {
462
+ return M.newInstance(this).withEntityManager(
463
+ t.em
464
+ );
465
+ }
466
+ lockInTransaction(t = "pessimistic_write") {
467
+ return this.em ? {
468
+ mode: t
469
+ } : void 0;
470
+ }
471
+ getRepository(t) {
472
+ return this.em ? this.em.getRepository(t) : this.dataSource.getRepository(t);
473
+ }
474
+ async withTransaction(t) {
475
+ let n;
476
+ return await this.dataSource.transaction(async (s) => {
477
+ n = await t(
478
+ M.newInstance(this).withEntityManager(s)
479
+ );
480
+ }), n;
481
+ }
482
+ }
483
+ const ue = (y) => ({
484
+ ...y,
485
+ withTransaction: async (t) => await t(y),
486
+ withRepositoryManager: () => y
487
+ }), te = (y, t) => `unaccent(LOWER(${y})) ILIKE unaccent(LOWER(:${t}))`, fe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
488
+ __proto__: null,
489
+ unaccentSearch: te
490
+ }, Symbol.toStringTag, { value: "Module" }));
491
+ export {
492
+ ce as GCPLogger,
493
+ X as LogLevelToConsoleMethodMap,
494
+ ae as MockLogger,
495
+ M as TransactionalRepository,
496
+ ue as buildTransactionalRepositoryMock,
497
+ se as loadEnvConfig,
498
+ fe as postgres
499
+ };
@@ -0,0 +1,4 @@
1
+ export interface TransactionalEntity<T = unknown> {
2
+ withTransaction: (executer: (entity: T) => Promise<void>) => Promise<void>;
3
+ withRepositoryManager: (repositoryManager: TransactionalEntity) => this;
4
+ }
@@ -0,0 +1,17 @@
1
+ import { DataSource, EntityTarget, ObjectLiteral, Repository } from 'typeorm';
2
+ import { TransactionalEntity } from './TransactionalEntity';
3
+ type LockMode = 'pessimistic_read' | 'pessimistic_write' | 'dirty_read' | 'pessimistic_partial_write' | 'pessimistic_write_or_fail';
4
+ export declare abstract class TransactionalRepository implements TransactionalEntity<TransactionalRepository> {
5
+ protected readonly dataSource: DataSource;
6
+ private em?;
7
+ constructor(dataSource: DataSource);
8
+ private static newInstance;
9
+ private withEntityManager;
10
+ withRepositoryManager(repositoryManager: TransactionalRepository): this;
11
+ lockInTransaction(mode?: LockMode): {
12
+ mode: LockMode;
13
+ } | undefined;
14
+ protected getRepository<T extends ObjectLiteral>(type: EntityTarget<T>): Repository<T>;
15
+ withTransaction<T>(executer: (repository: this) => Promise<T>): Promise<T>;
16
+ }
17
+ export {};
@@ -0,0 +1,2 @@
1
+ import { TransactionalEntity } from './TransactionalEntity';
2
+ export declare const buildTransactionalRepositoryMock: <T extends TransactionalEntity>(instance: T) => T;
@@ -0,0 +1,4 @@
1
+ export * from './TransactionalEntity';
2
+ export * from './TransactionalRepository';
3
+ export * from './TransactionalRepositoryMock';
4
+ export * as postgres from './postgres';
@@ -0,0 +1 @@
1
+ export * from './search';
@@ -0,0 +1 @@
1
+ export declare const unaccentSearch: (field: string, term: string) => string;
@@ -0,0 +1,7 @@
1
+ import * as dotenv from 'dotenv';
2
+ type LoadEnvConfigOptions = {
3
+ env?: string;
4
+ configPath?: string;
5
+ };
6
+ export declare const loadEnvConfig: (options?: LoadEnvConfigOptions) => dotenv.DotenvParseOutput | undefined;
7
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ export * from './env/env.loader';
2
+ export * from './logger';
3
+ export * from './database';
@@ -0,0 +1,22 @@
1
+ import { Logger, LogLevel } from './Logger';
2
+ type GCPLoggerOptions = {
3
+ logLevels?: ReadonlyArray<LogLevel>;
4
+ };
5
+ export declare class GCPLogger implements Logger {
6
+ private readonly module;
7
+ private levels;
8
+ constructor(module: string, options?: GCPLoggerOptions);
9
+ private mapLogLevelToConsoleMethod;
10
+ private write;
11
+ private buildLog;
12
+ private sanitizeLog;
13
+ private sensitiveReplacer;
14
+ debug<T extends object>(message: unknown, metadata?: T | string, context?: string): void;
15
+ verbose<T extends object>(message: unknown, metadata?: T | string, context?: string): void;
16
+ log<T extends object>(message: unknown, metadata?: T | string, context?: string): void;
17
+ warn<T extends object, E extends Error>(message: unknown, metadata?: T | string, error?: E | string, context?: string): void;
18
+ error<T extends object, E extends Error>(message: unknown, metadata?: T | string, error?: E | string, context?: string): void;
19
+ fatal<T extends object, E extends Error>(message: unknown, metadata?: T | string, error?: E | string, context?: string): void;
20
+ setLogLevels(levels: LogLevel[]): void;
21
+ }
22
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ export type LogLevel = 'debug' | 'verbose' | 'log' | 'warn' | 'error' | 'fatal';
2
+ export type ConsoleLogMethod = 'debug' | 'log' | 'warn' | 'error';
3
+ export declare const LogLevelToConsoleMethodMap: Record<LogLevel, ConsoleLogMethod>;
4
+ export interface Logger {
5
+ debug(message: string): void;
6
+ verbose(message: string): void;
7
+ log(message: string): void;
8
+ warn(message: string): void;
9
+ error(message: string): void;
10
+ fatal(message: string): void;
11
+ setLogLevels(levels: LogLevel[]): void;
12
+ }
@@ -0,0 +1,10 @@
1
+ import { Logger } from './Logger';
2
+ export declare class MockLogger implements Logger {
3
+ debug: () => undefined;
4
+ verbose: () => undefined;
5
+ log: () => undefined;
6
+ warn: () => undefined;
7
+ error: () => undefined;
8
+ fatal: () => undefined;
9
+ setLogLevels: () => undefined;
10
+ }
@@ -0,0 +1,3 @@
1
+ export * from './GCPLogger';
2
+ export * from './Logger';
3
+ export * from './MockLogger';
@@ -0,0 +1,2 @@
1
+ declare const _default: import('vite').UserConfig;
2
+ export default _default;
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@jsfsi-core/ts-nodejs",
3
+ "version": "1.0.1",
4
+ "description": "",
5
+ "license": "ISC",
6
+ "author": "",
7
+ "type": "module",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/src/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.cjs"
13
+ }
14
+ },
15
+ "main": "./dist/index.cjs",
16
+ "module": "./dist/index.mjs",
17
+ "types": "./dist/src/index.d.ts",
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "scripts": {
22
+ "build": "npm run lint && tsc && vite build",
23
+ "clean": "rm -rf dist && rm -rf node_modules && rm -rf coverage",
24
+ "format": "prettier --write \"src/**/*.{ts,tsx,js,jsx,json,css,md}\"",
25
+ "lint": "npm run lint:fix && npm run format",
26
+ "lint:fix": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0 --fix",
27
+ "test": "vitest run",
28
+ "test:coverage": "vitest run --coverage",
29
+ "test:watch": "vitest"
30
+ },
31
+ "dependencies": {
32
+ "@jsfsi-core/ts-crossplatform": "file:../ts-crossplatform",
33
+ "dotenv": "16.6.0",
34
+ "fast-safe-stringify": "2.1.1",
35
+ "typeorm": "0.3.25"
36
+ },
37
+ "devDependencies": {
38
+ "@vitest/coverage-v8": "3.2.4",
39
+ "vite": "7.0.0",
40
+ "vite-plugin-dts": "4.5.4",
41
+ "vitest": "3.2.4"
42
+ }
43
+ }