@drift-labs/common 1.0.34 → 1.0.35
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.
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface Logger {
|
|
2
|
+
level: string;
|
|
3
|
+
log: (level: string, message: string) => void;
|
|
4
|
+
info: (message: string) => void;
|
|
5
|
+
warn: (message: string) => void;
|
|
6
|
+
error: (message: string) => void;
|
|
7
|
+
debug: (message: string) => void;
|
|
8
|
+
alert: (message: string) => void;
|
|
9
|
+
}
|
|
10
|
+
export declare const logger: Logger;
|
|
11
|
+
export declare const setLogLevel: (logLevel: string) => void;
|
|
12
|
+
export declare const allEnvDlog: (key: string, message: any, ...optionalParams: any[]) => void;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Browser-safe logger stub. Replaces the Node-only winston logger when bundled
|
|
3
|
+
// for browser / React Native environments via the package.json "browser" field.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.allEnvDlog = exports.setLogLevel = exports.logger = void 0;
|
|
6
|
+
const logTemplateCache = new Map();
|
|
7
|
+
const MAX_TEMPLATE_CACHE_SIZE = 100;
|
|
8
|
+
exports.logger = {
|
|
9
|
+
level: 'info',
|
|
10
|
+
log: (level, message) => {
|
|
11
|
+
console.log(`[${level.toUpperCase()}] ${message}`);
|
|
12
|
+
},
|
|
13
|
+
info: (message) => console.info(message),
|
|
14
|
+
warn: (message) => console.warn(message),
|
|
15
|
+
error: (message) => console.error(message),
|
|
16
|
+
debug: (message) => console.debug(message),
|
|
17
|
+
alert: (message) => console.warn(`[ALERT] ${message}`),
|
|
18
|
+
};
|
|
19
|
+
const setLogLevel = (logLevel) => {
|
|
20
|
+
exports.logger.level = logLevel;
|
|
21
|
+
};
|
|
22
|
+
exports.setLogLevel = setLogLevel;
|
|
23
|
+
const allEnvDlog = (key, message, ...optionalParams) => {
|
|
24
|
+
const debugKey = `debug_${key}`;
|
|
25
|
+
let cachedFormat = logTemplateCache.get(debugKey);
|
|
26
|
+
if (!cachedFormat) {
|
|
27
|
+
cachedFormat = `🔧::${key}::\n{{message}}`;
|
|
28
|
+
if (logTemplateCache.size < MAX_TEMPLATE_CACHE_SIZE) {
|
|
29
|
+
logTemplateCache.set(debugKey, cachedFormat);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const formattedMessage = cachedFormat.replace('{{message}}', String(message));
|
|
33
|
+
console.debug(formattedMessage, ...optionalParams);
|
|
34
|
+
};
|
|
35
|
+
exports.allEnvDlog = allEnvDlog;
|
|
36
|
+
//# sourceMappingURL=logger.browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.browser.js","sourceRoot":"","sources":["../../src/utils/logger.browser.ts"],"names":[],"mappings":";AAAA,+EAA+E;AAC/E,gFAAgF;;;AAEhF,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAkB,CAAC;AACnD,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAYvB,QAAA,MAAM,GAAW;IAC7B,KAAK,EAAE,MAAM;IACb,GAAG,EAAE,CAAC,KAAa,EAAE,OAAe,EAAE,EAAE;QACvC,OAAO,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,WAAW,EAAE,KAAK,OAAO,EAAE,CAAC,CAAC;IACpD,CAAC;IACD,IAAI,EAAE,CAAC,OAAe,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC;IAChD,IAAI,EAAE,CAAC,OAAe,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC;IAChD,KAAK,EAAE,CAAC,OAAe,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC;IAClD,KAAK,EAAE,CAAC,OAAe,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC;IAClD,KAAK,EAAE,CAAC,OAAe,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,OAAO,EAAE,CAAC;CAC9D,CAAC;AAEK,MAAM,WAAW,GAAG,CAAC,QAAgB,EAAE,EAAE;IAC/C,cAAM,CAAC,KAAK,GAAG,QAAQ,CAAC;AACzB,CAAC,CAAC;AAFW,QAAA,WAAW,eAEtB;AAEK,MAAM,UAAU,GAAG,CACzB,GAAW,EACX,OAAY,EACZ,GAAG,cAAqB,EACvB,EAAE;IACH,MAAM,QAAQ,GAAG,SAAS,GAAG,EAAE,CAAC;IAChC,IAAI,YAAY,GAAG,gBAAgB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAElD,IAAI,CAAC,YAAY,EAAE,CAAC;QACnB,YAAY,GAAG,OAAO,GAAG,iBAAiB,CAAC;QAC3C,IAAI,gBAAgB,CAAC,IAAI,GAAG,uBAAuB,EAAE,CAAC;YACrD,gBAAgB,CAAC,GAAG,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;QAC9C,CAAC;IACF,CAAC;IAED,MAAM,gBAAgB,GAAG,YAAY,CAAC,OAAO,CAAC,aAAa,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;IAC9E,OAAO,CAAC,KAAK,CAAC,gBAAgB,EAAE,GAAG,cAAc,CAAC,CAAC;AACpD,CAAC,CAAC;AAjBW,QAAA,UAAU,cAiBrB","sourcesContent":["// Browser-safe logger stub. Replaces the Node-only winston logger when bundled\n// for browser / React Native environments via the package.json \"browser\" field.\n\nconst logTemplateCache = new Map<string, string>();\nconst MAX_TEMPLATE_CACHE_SIZE = 100;\n\nexport interface Logger {\n\tlevel: string;\n\tlog: (level: string, message: string) => void;\n\tinfo: (message: string) => void;\n\twarn: (message: string) => void;\n\terror: (message: string) => void;\n\tdebug: (message: string) => void;\n\talert: (message: string) => void;\n}\n\nexport const logger: Logger = {\n\tlevel: 'info',\n\tlog: (level: string, message: string) => {\n\t\tconsole.log(`[${level.toUpperCase()}] ${message}`);\n\t},\n\tinfo: (message: string) => console.info(message),\n\twarn: (message: string) => console.warn(message),\n\terror: (message: string) => console.error(message),\n\tdebug: (message: string) => console.debug(message),\n\talert: (message: string) => console.warn(`[ALERT] ${message}`),\n};\n\nexport const setLogLevel = (logLevel: string) => {\n\tlogger.level = logLevel;\n};\n\nexport const allEnvDlog = (\n\tkey: string,\n\tmessage: any,\n\t...optionalParams: any[]\n) => {\n\tconst debugKey = `debug_${key}`;\n\tlet cachedFormat = logTemplateCache.get(debugKey);\n\n\tif (!cachedFormat) {\n\t\tcachedFormat = `🔧::${key}::\\n{{message}}`;\n\t\tif (logTemplateCache.size < MAX_TEMPLATE_CACHE_SIZE) {\n\t\t\tlogTemplateCache.set(debugKey, cachedFormat);\n\t\t}\n\t}\n\n\tconst formattedMessage = cachedFormat.replace('{{message}}', String(message));\n\tconsole.debug(formattedMessage, ...optionalParams);\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@drift-labs/common",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.35",
|
|
4
4
|
"description": "Common functions for Drift",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
7
|
+
"browser": {
|
|
8
|
+
"./lib/utils/logger.js": "./lib/utils/logger.browser.js"
|
|
9
|
+
},
|
|
7
10
|
"license": "MIT",
|
|
8
11
|
"repository": {
|
|
9
12
|
"type": "git",
|