@drift-labs/common 1.0.57 → 1.0.59

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.
@@ -1,5 +1 @@
1
- import { Logger as WinstonLogger } from 'winston';
2
- export declare const logger: WinstonLogger;
3
- export declare const setLogLevel: (logLevel: string) => void;
4
- export type Logger = WinstonLogger;
5
1
  export declare const allEnvDlog: (key: string, message: any, ...optionalParams: any[]) => void;
@@ -1,84 +1,8 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.allEnvDlog = exports.setLogLevel = exports.logger = void 0;
7
- const winston_1 = require("winston");
8
- const winston_slack_webhook_transport_1 = __importDefault(require("winston-slack-webhook-transport"));
9
- const bypassAlert = process.env.RUNNING_LOCAL === 'true';
10
- // Cache for log message templates to reduce string concatenation overhead
11
- const logTemplateCache = new Map();
12
- const MAX_TEMPLATE_CACHE_SIZE = 100;
13
- // Optimized log formatter that caches common template patterns
14
- function formatLogMessage(timestamp, level, message) {
15
- const upperLevel = level.toUpperCase();
16
- const templateKey = `${upperLevel}_template`;
17
- if (logTemplateCache.has(templateKey)) {
18
- const template = logTemplateCache.get(templateKey);
19
- return template
20
- .replace('{{timestamp}}', timestamp)
21
- .replace('{{message}}', message);
22
- }
23
- const template = '[{{timestamp}}] ' + upperLevel + ': {{message}}';
24
- if (logTemplateCache.size < MAX_TEMPLATE_CACHE_SIZE) {
25
- logTemplateCache.set(templateKey, template);
26
- }
27
- return template
28
- .replace('{{timestamp}}', timestamp)
29
- .replace('{{message}}', message);
30
- }
31
- const loggerTransports = [
32
- new winston_1.transports.Console({
33
- level: 'info',
34
- }),
35
- ];
36
- if (!bypassAlert) {
37
- loggerTransports.push(new winston_slack_webhook_transport_1.default({
38
- webhookUrl: process.env.WEBHOOK_URL,
39
- level: 'alert',
40
- formatter: ({ timestamp, level, message }) => {
41
- return {
42
- text: formatLogMessage(timestamp, level, message),
43
- };
44
- },
45
- }));
46
- }
47
- exports.logger = (0, winston_1.createLogger)({
48
- levels: {
49
- emerg: 0,
50
- alert: 1,
51
- crit: 2,
52
- error: 3,
53
- warning: 4,
54
- notice: 5,
55
- info: 6,
56
- debug: 7,
57
- },
58
- level: 'info',
59
- transports: loggerTransports,
60
- format: winston_1.format.combine(winston_1.format.timestamp(), winston_1.format.printf(({ timestamp, level, message }) => {
61
- return formatLogMessage(String(timestamp), String(level), String(message));
62
- })),
63
- });
64
- const setLogLevel = (logLevel) => {
65
- exports.logger.level = logLevel;
66
- };
67
- exports.setLogLevel = setLogLevel;
68
- //@ts-ignore
69
- exports.logger.alert = (message) => exports.logger.log('alert', message);
3
+ exports.allEnvDlog = void 0;
70
4
  const allEnvDlog = (key, message, ...optionalParams) => {
71
- // Cache debug message format to reduce string concatenation
72
- const debugKey = `debug_${key}`;
73
- let cachedFormat = logTemplateCache.get(debugKey);
74
- if (!cachedFormat) {
75
- cachedFormat = `🔧::${key}::\n{{message}}`;
76
- if (logTemplateCache.size < MAX_TEMPLATE_CACHE_SIZE) {
77
- logTemplateCache.set(debugKey, cachedFormat);
78
- }
79
- }
80
- const formattedMessage = cachedFormat.replace('{{message}}', String(message));
81
- console.debug(formattedMessage, ...optionalParams);
5
+ console.debug(`🔧::${key}::\n${message}`, ...optionalParams);
82
6
  };
83
7
  exports.allEnvDlog = allEnvDlog;
84
8
  //# sourceMappingURL=logger.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":";;;;;;AAAA,qCAKiB;AACjB,sGAAoE;AAGpE,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,KAAK,MAAM,CAAC;AAEzD,0EAA0E;AAC1E,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAkB,CAAC;AACnD,MAAM,uBAAuB,GAAG,GAAG,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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;AAlBW,QAAA,UAAU,cAkBrB","sourcesContent":["import {\n\tcreateLogger,\n\ttransports,\n\tformat,\n\tLogger as WinstonLogger,\n} from 'winston';\nimport SlackWebhookTransport from 'winston-slack-webhook-transport';\nimport TransportStream from 'winston-transport';\n\nconst bypassAlert = process.env.RUNNING_LOCAL === 'true';\n\n// Cache for log message templates to reduce string concatenation overhead\nconst logTemplateCache = new Map<string, string>();\nconst MAX_TEMPLATE_CACHE_SIZE = 100;\n\n// Optimized log formatter that caches common template patterns\nfunction formatLogMessage(\n\ttimestamp: string,\n\tlevel: string,\n\tmessage: string\n): string {\n\tconst upperLevel = level.toUpperCase();\n\tconst templateKey = `${upperLevel}_template`;\n\n\tif (logTemplateCache.has(templateKey)) {\n\t\tconst template = logTemplateCache.get(templateKey)!;\n\t\treturn template\n\t\t\t.replace('{{timestamp}}', timestamp)\n\t\t\t.replace('{{message}}', message);\n\t}\n\n\tconst template = '[{{timestamp}}] ' + upperLevel + ': {{message}}';\n\n\tif (logTemplateCache.size < MAX_TEMPLATE_CACHE_SIZE) {\n\t\tlogTemplateCache.set(templateKey, template);\n\t}\n\n\treturn template\n\t\t.replace('{{timestamp}}', timestamp)\n\t\t.replace('{{message}}', message);\n}\n\nconst loggerTransports: TransportStream[] = [\n\tnew transports.Console({\n\t\tlevel: 'info',\n\t}),\n];\n\nif (!bypassAlert) {\n\tloggerTransports.push(\n\t\tnew SlackWebhookTransport({\n\t\t\twebhookUrl: process.env.WEBHOOK_URL,\n\t\t\tlevel: 'alert',\n\t\t\tformatter: ({ timestamp, level, message }) => {\n\t\t\t\treturn {\n\t\t\t\t\ttext: formatLogMessage(timestamp, level, message),\n\t\t\t\t};\n\t\t\t},\n\t\t})\n\t);\n}\n\nexport const logger = createLogger({\n\tlevels: {\n\t\temerg: 0,\n\t\talert: 1,\n\t\tcrit: 2,\n\t\terror: 3,\n\t\twarning: 4,\n\t\tnotice: 5,\n\t\tinfo: 6,\n\t\tdebug: 7,\n\t},\n\tlevel: 'info',\n\ttransports: loggerTransports,\n\tformat: format.combine(\n\t\tformat.timestamp(),\n\t\tformat.printf(({ timestamp, level, message }) => {\n\t\t\treturn formatLogMessage(\n\t\t\t\tString(timestamp),\n\t\t\t\tString(level),\n\t\t\t\tString(message)\n\t\t\t);\n\t\t})\n\t),\n});\n\nexport const setLogLevel = (logLevel: string) => {\n\tlogger.level = logLevel;\n};\n\n//@ts-ignore\nlogger.alert = (message: string) => logger.log('alert', message);\n\nexport type Logger = WinstonLogger;\n\nexport const allEnvDlog = (\n\tkey: string,\n\tmessage: any,\n\t...optionalParams: any[]\n) => {\n\t// Cache debug message format to reduce string concatenation\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"]}
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":";;;AAAO,MAAM,UAAU,GAAG,CACzB,GAAW,EACX,OAAY,EACZ,GAAG,cAAqB,EACvB,EAAE;IACH,OAAO,CAAC,KAAK,CAAC,OAAO,GAAG,OAAO,OAAO,EAAE,EAAE,GAAG,cAAc,CAAC,CAAC;AAC9D,CAAC,CAAC;AANW,QAAA,UAAU,cAMrB","sourcesContent":["export const allEnvDlog = (\n\tkey: string,\n\tmessage: any,\n\t...optionalParams: any[]\n) => {\n\tconsole.debug(`🔧::${key}::\\n${message}`, ...optionalParams);\n};\n"]}
package/package.json CHANGED
@@ -1,12 +1,9 @@
1
1
  {
2
2
  "name": "@drift-labs/common",
3
- "version": "1.0.57",
3
+ "version": "1.0.59",
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
- },
10
7
  "license": "MIT",
11
8
  "repository": {
12
9
  "type": "git",
@@ -20,8 +17,7 @@
20
17
  ],
21
18
  "author": "Drift Labs",
22
19
  "dependencies": {
23
- "@drift-labs/sdk": "^2.159.0-beta.2",
24
- "@slack/web-api": "6.4.0",
20
+ "@drift-labs/sdk": "^2.161.0-beta.4",
25
21
  "@solana/spl-token": "^0.4.14",
26
22
  "@solana/web3.js": "1.98.0",
27
23
  "bcryptjs-react": "2.4.6",
@@ -33,12 +29,10 @@
33
29
  "localstorage-memory": "1.0.3",
34
30
  "rxjs": "7.8.2",
35
31
  "tiny-invariant": "1.3.1",
36
- "tweetnacl": "1.0.3",
37
- "winston": "3.13.0",
38
- "winston-slack-webhook-transport": "2.3.5"
32
+ "tweetnacl": "1.0.3"
39
33
  },
40
34
  "peerDependencies": {
41
- "@drift-labs/sdk": "^2.158.0-beta.3",
35
+ "@drift-labs/sdk": "^2.161.0-beta.4",
42
36
  "@solana/web3.js": "1.98.0"
43
37
  },
44
38
  "scripts": {
@@ -1,12 +0,0 @@
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;
@@ -1,36 +0,0 @@
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
@@ -1 +0,0 @@
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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gB,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"]}