@adalo/metrics 0.1.106 → 0.1.108

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/README.md CHANGED
@@ -22,7 +22,7 @@ import { MetricsClient } from '@adalo/metrics-js'
22
22
  const metrics = new MetricsClient({ appName: 'my-app', enabled: true })
23
23
 
24
24
  // Express middleware
25
- app.use(metrics.countHttpRequestMiddleware)
25
+ app.use(metrics.trackHttpRequestMiddleware)
26
26
 
27
27
 
28
28
  // Start metrics push
@@ -37,11 +37,17 @@ export const REDIS_V4: "REDIS_V4";
37
37
  export const REDIS_V3: "REDIS_V3";
38
38
  export const IOREDIS: "IOREDIS";
39
39
  /**
40
- * Get default redis client name
40
+ * Get the default Redis client name.
41
41
  *
42
- * @param {string} [name='undefined-name'] - Fallback app name if BUILD_APP_NAME is not set.
43
- * @param {string} [appName='undefined-app'] - appName
44
- * @returns {string}
42
+ * @param {Object} options - Options for generating Redis name.
43
+ * @param {string} [options.name='undefined-name'] - Fallback name if none is provided.
44
+ * @param {string} [options.appName] - Application name. Defaults to `defaultAppName` if not set.
45
+ * @param {string} [options.processName] - Process name. Defaults to `dyno` if not set.
46
+ * @returns {string} The generated Redis client name.
45
47
  */
46
- export function getCorrectNameForRedis(name?: string | undefined, appName?: string | undefined): string;
48
+ export function getRedisName({ name, appName, processName }: {
49
+ name?: string | undefined;
50
+ appName?: string | undefined;
51
+ processName?: string | undefined;
52
+ }): string;
47
53
  //# sourceMappingURL=redisUtils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"redisUtils.d.ts","sourceRoot":"","sources":["../src/redisUtils.js"],"names":[],"mappings":"AAmBA;;;;;GAKG;AACH,6FAFsB,GAAG,QAAQ,MAAM,KAAK,IAAI,CAoB/C;AA4BD;;;;;GAKG;AACH,6FAFsB,GAAG,QAAQ,MAAM,KAAK,IAAI,CAmB/C;AAjDD;;;;;GAKG;AACH,6FAFsB,GAAG,QAAQ,MAAM,KAAK,IAAI,CAoB/C;AA2BD;;;;;GAKG;AACH,kCAHW,GAAG,GACD,OAAO,CASnB;AAED;;;;;GAKG;AACH,2CAHW,GAAG,GACD,MAAM,CAiBlB;AApID,kCAA2B;AAC3B,kCAA2B;AAC3B,gCAAyB;AAKzB;;;;;;GAMG;AAEH,iGAHa,MAAM,CAKlB"}
1
+ {"version":3,"file":"redisUtils.d.ts","sourceRoot":"","sources":["../src/redisUtils.js"],"names":[],"mappings":"AAoBA;;;;;GAKG;AACH,6FAFsB,GAAG,QAAQ,MAAM,KAAK,IAAI,CAoB/C;AA4BD;;;;;GAKG;AACH,6FAFsB,GAAG,QAAQ,MAAM,KAAK,IAAI,CAmB/C;AAjDD;;;;;GAKG;AACH,6FAFsB,GAAG,QAAQ,MAAM,KAAK,IAAI,CAoB/C;AA2BD;;;;;GAKG;AACH,kCAHW,GAAG,GACD,OAAO,CASnB;AAED;;;;;GAKG;AACH,2CAHW,GAAG,GACD,MAAM,CAiBlB;AArID,kCAA2B;AAC3B,kCAA2B;AAC3B,gCAAyB;AAKzB;;;;;;;;GAQG;AACH;IAL4B,IAAI;IACJ,OAAO;IACP,WAAW;IAC1B,MAAM,CAIlB"}
package/lib/redisUtils.js CHANGED
@@ -7,15 +7,20 @@ const dyno = process.env.BUILD_DYNO_PROCESS_TYPE || 'undefined-dyno';
7
7
  const defaultAppName = process.env.BUILD_APP_NAME || 'undefined-app';
8
8
 
9
9
  /**
10
- * Get default redis client name
10
+ * Get the default Redis client name.
11
11
  *
12
- * @param {string} [name='undefined-name'] - Fallback app name if BUILD_APP_NAME is not set.
13
- * @param {string} [appName='undefined-app'] - appName
14
- * @returns {string}
12
+ * @param {Object} options - Options for generating Redis name.
13
+ * @param {string} [options.name='undefined-name'] - Fallback name if none is provided.
14
+ * @param {string} [options.appName] - Application name. Defaults to `defaultAppName` if not set.
15
+ * @param {string} [options.processName] - Process name. Defaults to `dyno` if not set.
16
+ * @returns {string} The generated Redis client name.
15
17
  */
16
- // eslint-disable-next-line @typescript-eslint/default-param-last
17
- const getCorrectNameForRedis = (name = 'undefined-name', appName) => {
18
- return `${appName || defaultAppName}:${dyno}:${name}`;
18
+ const getRedisName = ({
19
+ name = 'undefined-name',
20
+ appName,
21
+ processName
22
+ }) => {
23
+ return `${appName || defaultAppName}:${processName || dyno}:${name}`;
19
24
  };
20
25
 
21
26
  /**
@@ -28,7 +33,7 @@ const createSetClientNameForRedisV3 = (defaultAppName = 'undefined-app') => {
28
33
  return (client, name) => {
29
34
  if (process.env.NODE_ENV !== 'test') {
30
35
  client.on('connect', () => {
31
- client.send_command('CLIENT', ['SETNAME', getCorrectNameForRedis(name, defaultAppName)], err => {
36
+ client.send_command('CLIENT', ['SETNAME', getRedisName(name, defaultAppName)], err => {
32
37
  if (err) {
33
38
  console.error(`Failed to set client name for ${name}:`, err);
34
39
  } else {
@@ -50,7 +55,7 @@ const createSetClientNameForIoredis = (defaultAppName = 'undefined-app') => {
50
55
  return (client, name) => {
51
56
  if (process.env.NODE_ENV !== 'test') {
52
57
  client.once('connect', () => {
53
- client.call('CLIENT', ['SETNAME', getCorrectNameForRedis(name, defaultAppName)]).then(() => {
58
+ client.call('CLIENT', ['SETNAME', getRedisName(name, defaultAppName)]).then(() => {
54
59
  console.log(`Connected to Redis for pid:${process.pid} (${name})`);
55
60
  }).catch(err => {
56
61
  console.error(`Failed to set client name for ${name}:`, err);
@@ -71,7 +76,7 @@ const createSetClientNameForRedisV4 = (defaultAppName = 'undefined-app') => {
71
76
  if (process.env.NODE_ENV !== 'test') {
72
77
  client.on('ready', async () => {
73
78
  try {
74
- await client.sendCommand(['CLIENT', 'SETNAME', getCorrectNameForRedis(name, defaultAppName)]);
79
+ await client.sendCommand(['CLIENT', 'SETNAME', getRedisName(name, defaultAppName)]);
75
80
  console.log(`Connected to Redis for pid:${process.pid} (${name})`);
76
81
  } catch (err) {
77
82
  console.error(`Failed to set client name for ${name}:`, err);
@@ -121,6 +126,6 @@ module.exports = {
121
126
  REDIS_V4,
122
127
  REDIS_V3,
123
128
  IOREDIS,
124
- getCorrectNameForRedis
129
+ getRedisName
125
130
  };
126
131
  //# sourceMappingURL=redisUtils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"redisUtils.js","names":["REDIS_V4","REDIS_V3","IOREDIS","dyno","process","env","BUILD_DYNO_PROCESS_TYPE","defaultAppName","BUILD_APP_NAME","getCorrectNameForRedis","name","appName","createSetClientNameForRedisV3","client","NODE_ENV","on","send_command","err","console","error","log","pid","createSetClientNameForIoredis","once","call","then","catch","createSetClientNameForRedisV4","sendCommand","isIORedis","disconnect","options","undefined","getRedisClientType","info","Error","module","exports"],"sources":["../src/redisUtils.js"],"sourcesContent":["const REDIS_V4 = 'REDIS_V4'\nconst REDIS_V3 = 'REDIS_V3'\nconst IOREDIS = 'IOREDIS'\n\nconst dyno = process.env.BUILD_DYNO_PROCESS_TYPE || 'undefined-dyno'\nconst defaultAppName = process.env.BUILD_APP_NAME || 'undefined-app'\n\n/**\n * Get default redis client name\n *\n * @param {string} [name='undefined-name'] - Fallback app name if BUILD_APP_NAME is not set.\n * @param {string} [appName='undefined-app'] - appName\n * @returns {string}\n */\n// eslint-disable-next-line @typescript-eslint/default-param-last\nconst getCorrectNameForRedis = (name = 'undefined-name', appName) => {\n return `${appName || defaultAppName}:${dyno}:${name}`\n}\n\n/**\n * Creates a configured setClientName function for node-redis v3.\n *\n * @param {string} [defaultAppName='undefined-app'] - Fallback app name if BUILD_APP_NAME is not set.\n * @returns {(client: any, name: string) => void}\n */\nconst createSetClientNameForRedisV3 = (defaultAppName = 'undefined-app') => {\n return (client, name) => {\n if (process.env.NODE_ENV !== 'test') {\n client.on('connect', () => {\n client.send_command(\n 'CLIENT',\n ['SETNAME', getCorrectNameForRedis(name, defaultAppName)],\n err => {\n if (err) {\n console.error(`Failed to set client name for ${name}:`, err)\n } else {\n console.log(`Connected to Redis for pid:${process.pid} (${name})`)\n }\n }\n )\n })\n }\n }\n}\n\n/**\n * Creates a function to set Redis client name for ioredis.\n *\n * @param {string} [defaultAppName='undefined-app']\n * @returns {(client: any, name: string) => void}\n */\nconst createSetClientNameForIoredis = (defaultAppName = 'undefined-app') => {\n return (client, name) => {\n if (process.env.NODE_ENV !== 'test') {\n client.once('connect', () => {\n client\n .call('CLIENT', [\n 'SETNAME',\n getCorrectNameForRedis(name, defaultAppName),\n ])\n .then(() => {\n console.log(`Connected to Redis for pid:${process.pid} (${name})`)\n })\n .catch(err => {\n console.error(`Failed to set client name for ${name}:`, err)\n })\n })\n }\n }\n}\n\n/**\n * Creates a function to set Redis client name for node-redis v4.\n *\n * @param {string} [defaultAppName='undefined-app']\n * @returns {(client: any, name: string) => void}\n */\nconst createSetClientNameForRedisV4 = (defaultAppName = 'undefined-app') => {\n return (client, name) => {\n if (process.env.NODE_ENV !== 'test') {\n client.on('ready', async () => {\n try {\n await client.sendCommand([\n 'CLIENT',\n 'SETNAME',\n getCorrectNameForRedis(name, defaultAppName),\n ])\n console.log(`Connected to Redis for pid:${process.pid} (${name})`)\n } catch (err) {\n console.error(`Failed to set client name for ${name}:`, err)\n }\n })\n }\n }\n}\n\n/**\n * Check if a Redis client is an ioredis instance\n *\n * @param {any} client - Redis client instance\n * @returns {boolean} True if the client is ioredis\n */\nconst isIORedis = client => {\n return (\n client &&\n typeof client.sendCommand === 'function' &&\n typeof client.disconnect === 'function' &&\n client.options !== undefined\n )\n}\n\n/**\n * Get Redis client type\n *\n * @param {any} client - Redis client instance\n * @returns {string} One of IOREDIS, REDIS_V3, REDIS_V4\n */\nconst getRedisClientType = client => {\n if (isIORedis(client)) {\n console.log('Detected node-redis ioredis')\n return IOREDIS\n }\n if (typeof client?.send_command === 'function') {\n console.log('Detected node-redis redis_v3')\n return REDIS_V3\n }\n if (typeof client.info === 'function') {\n console.log('Detected node-redis redis_v4')\n return REDIS_V4\n }\n\n throw new Error(`Failed to get Redis client type`)\n}\n\nmodule.exports = {\n createSetClientNameForRedisV3,\n createSetClientNameForRedisV4,\n createSetClientNameForIoredis,\n isI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AACA;AACA;AACA,MAAMY,SAAS,GAAGhB,MAAM,IAAI;EAC1B,OACEA,MAAM,IACN,OAAOA,MAAM,CAACe,WAAW,KAAK,UAAU,IACxC,OAAOf,MAAM,CAACiB,UAAU,KAAK,UAAU,IACvCjB,MAAM,CAACkB,OAAO,KAAKC,SAAS;AAEhC,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,kBAAkB,GAAGpB,MAAM,IAAI;EACnC,IAAIgB,SAAS,CAAChB,MAAM,CAAC,EAAE;IACrBK,OAAO,CAACE,GAAG,CAAC,6BAA6B,CAAC;IAC1C,OAAOlB,OAAO;EAChB;EACA,IAAI,OAAOW,MAAM,EAAEG,YAAY,KAAK,UAAU,EAAE;IAC9CE,OAAO,CAACE,GAAG,CAAC,8BAA8B,CAAC;IAC3C,OAAOnB,QAAQ;EACjB;EACA,IAAI,OAAOY,MAAM,CAACqB,IAAI,KAAK,UAAU,EAAE;IACrChB,OAAO,CAACE,GAAG,CAAC,8BAA8B,CAAC;IAC3C,OAAOpB,QAAQ;EACjB;EAEA,MAAM,IAAImC,KAAK,CAAC,iCAAiC,CAAC;AACpD,CAAC;AAEDC,MAAM,CAACC,OAAO,GAAG;EACfzB,6BAA6B;EAC7Be,6BAA6B;EAC7BL,6BAA6B;EAC7BO,SAAS;EACTI,kBAAkB;EAClBjC,QAAQ;EACRC,QAAQ;EACRC,OAAO;EACPO;AACF,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"redisUtils.js","names":["REDIS_V4","REDIS_V3","IOREDIS","dyno","process","env","BUILD_DYNO_PROCESS_TYPE","defaultAppName","BUILD_APP_NAME","getRedisName","name","appName","processName","createSetClientNameForRedisV3","client","NODE_ENV","on","send_command","err","console","error","log","pid","createSetClientNameForIoredis","once","call","then","catch","createSetClientNameForRedisV4","sendCommand","isIORedis","disconnect","options","undefined","getRedisClientType","info","Error","module","exports"],"sources":["../src/redisUtils.js"],"sourcesContent":["const REDIS_V4 = 'REDIS_V4'\nconst REDIS_V3 = 'REDIS_V3'\nconst IOREDIS = 'IOREDIS'\n\nconst dyno = process.env.BUILD_DYNO_PROCESS_TYPE || 'undefined-dyno'\nconst defaultAppName = process.env.BUILD_APP_NAME || 'undefined-app'\n\n/**\n * Get the default Redis client name.\n *\n * @param {Object} options - Options for generating Redis name.\n * @param {string} [options.name='undefined-name'] - Fallback name if none is provided.\n * @param {string} [options.appName] - Application name. Defaults to `defaultAppName` if not set.\n * @param {string} [options.processName] - Process name. Defaults to `dyno` if not set.\n * @returns {string} The generated Redis client name.\n */\nconst getRedisName = ({ name = 'undefined-name', appName, processName }) => {\n return `${appName || defaultAppName}:${processName || dyno}:${name}`\n}\n\n/**\n * Creates a configured setClientName function for node-redis v3.\n *\n * @param {string} [defaultAppName='undefined-app'] - Fallback app name if BUILD_APP_NAME is not set.\n * @returns {(client: any, name: string) => void}\n */\nconst createSetClientNameForRedisV3 = (defaultAppName = 'undefined-app') => {\n return (client, name) => {\n if (process.env.NODE_ENV !== 'test') {\n client.on('connect', () => {\n client.send_command(\n 'CLIENT',\n ['SETNAME', getRedisName(name, defaultAppName)],\n err => {\n if (err) {\n console.error(`Failed to set client name for ${name}:`, err)\n } else {\n console.log(`Connected to Redis for pid:${process.pid} (${name})`)\n }\n }\n )\n })\n }\n }\n}\n\n/**\n * Creates a function to set Redis client name for ioredis.\n *\n * @param {string} [defaultAppName='undefined-app']\n * @returns {(client: any, name: string) => void}\n */\nconst createSetClientNameForIoredis = (defaultAppName = 'undefined-app') => {\n return (client, name) => {\n if (process.env.NODE_ENV !== 'test') {\n client.once('connect', () => {\n client\n .call('CLIENT', [\n 'SETNAME',\n getRedisName(name, defaultAppName),\n ])\n .then(() => {\n console.log(`Connected to Redis for pid:${process.pid} (${name})`)\n })\n .catch(err => {\n console.error(`Failed to set client name for ${name}:`, err)\n })\n })\n }\n }\n}\n\n/**\n * Creates a function to set Redis client name for node-redis v4.\n *\n * @param {string} [defaultAppName='undefined-app']\n * @returns {(client: any, name: string) => void}\n */\nconst createSetClientNameForRedisV4 = (defaultAppName = 'undefined-app') => {\n return (client, name) => {\n if (process.env.NODE_ENV !== 'test') {\n client.on('ready', async () => {\n try {\n await client.sendCommand([\n 'CLIENT',\n 'SETNAME',\n getRedisName(name, defaultAppName),\n ])\n console.log(`Connected to Redis for pid:${process.pid} (${name})`)\n } catch (err) {\n console.error(`Failed to set client name for ${name}:`, err)\n }\n })\n }\n }\n}\n\n/**\n * Check if a Redis client is an ioredis instance\n *\n * @param {any} client - Redis client instance\n * @returns {boolean} True if the client is ioredis\n */\nconst isIORedis = client => {\n return (\n client &&\n typeof client.sendCommand === 'function' &&\n typeof client.disconnect === 'function' &&\n client.options !== undefined\n )\n}\n\n/**\n * Get Redis client type\n *\n * @param {any} client - Redis client instance\n * @returns {string} One of IOREDIS, REDIS_V3, REDIS_V4\n */\nconst getRedisClientType = client => {\n if (isIORedis(client)) {\n console.log('Detected node-redis ioredis')\n return IOREDIS\n }\n if (typeof client?.send_command === 'function') {\n console.log('Detected node-redis redis_v3')\n return REDIS_V3\n }\n if (typeof client.info === 'function') {\n console.log('Detected node-redis redis_v4')\n return REDIS_V4\n }\n\n throw new Error(`Failed to get Redis client type`)\n}\n\nmodule.exports = {\n createSetClientNameForRedisV3,\n createSetClientNameForRedisV4,\n createSetClientNameForIoredis,\n isIORedis,\n getRedisClientType,\n REDIS_V4,\n REDIS_V3,\n IOREDIS,\n getRedisName,\n}\n"],"mappings":";;AAAA,MAAMA,QAAQ,GAAG,UAAU;AAC3B,MAAMC,QAAQ,GAAG,UAAU;AAC3B,MAAMC,OAAO,GAAG,SAAS;AAEzB,MAAMC,IAAI,GAAGC,OAAO,CAACC,GAAG,CAACC,uBAAuB,IAAI,gBAAgB;AACpE,MAAMC,cAAc,GAAGH,OAAO,CAACC,GAAG,CAACG,cAAc,IAAI,eAAe;;AAEpE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,YAAY,GAAGA,CAAC;EAAEC,IAAI,GA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1C,OAAOnB,OAAO;EAChB;EACA,IAAI,OAAOY,MAAM,EAAEG,YAAY,KAAK,UAAU,EAAE;IAC9CE,OAAO,CAACE,GAAG,CAAC,8BAA8B,CAAC;IAC3C,OAAOpB,QAAQ;EACjB;EACA,IAAI,OAAOa,MAAM,CAACqB,IAAI,KAAK,UAAU,EAAE;IACrChB,OAAO,CAACE,GAAG,CAAC,8BAA8B,CAAC;IAC3C,OAAOrB,QAAQ;EACjB;EAEA,MAAM,IAAIoC,KAAK,CAAC,iCAAiC,CAAC;AACpD,CAAC;AAEDC,MAAM,CAACC,OAAO,GAAG;EACfzB,6BAA6B;EAC7Be,6BAA6B;EAC7BL,6BAA6B;EAC7BO,SAAS;EACTI,kBAAkB;EAClBlC,QAAQ;EACRC,QAAQ;EACRC,OAAO;EACPO;AACF,CAAC","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adalo/metrics",
3
- "version": "0.1.106",
3
+ "version": "0.1.108",
4
4
  "description": "Reusable metrics utilities for Node.js and Laravel apps",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
package/src/redisUtils.js CHANGED
@@ -6,15 +6,16 @@ const dyno = process.env.BUILD_DYNO_PROCESS_TYPE || 'undefined-dyno'
6
6
  const defaultAppName = process.env.BUILD_APP_NAME || 'undefined-app'
7
7
 
8
8
  /**
9
- * Get default redis client name
9
+ * Get the default Redis client name.
10
10
  *
11
- * @param {string} [name='undefined-name'] - Fallback app name if BUILD_APP_NAME is not set.
12
- * @param {string} [appName='undefined-app'] - appName
13
- * @returns {string}
11
+ * @param {Object} options - Options for generating Redis name.
12
+ * @param {string} [options.name='undefined-name'] - Fallback name if none is provided.
13
+ * @param {string} [options.appName] - Application name. Defaults to `defaultAppName` if not set.
14
+ * @param {string} [options.processName] - Process name. Defaults to `dyno` if not set.
15
+ * @returns {string} The generated Redis client name.
14
16
  */
15
- // eslint-disable-next-line @typescript-eslint/default-param-last
16
- const getCorrectNameForRedis = (name = 'undefined-name', appName) => {
17
- return `${appName || defaultAppName}:${dyno}:${name}`
17
+ const getRedisName = ({ name = 'undefined-name', appName, processName }) => {
18
+ return `${appName || defaultAppName}:${processName || dyno}:${name}`
18
19
  }
19
20
 
20
21
  /**
@@ -29,7 +30,7 @@ const createSetClientNameForRedisV3 = (defaultAppName = 'undefined-app') => {
29
30
  client.on('connect', () => {
30
31
  client.send_command(
31
32
  'CLIENT',
32
- ['SETNAME', getCorrectNameForRedis(name, defaultAppName)],
33
+ ['SETNAME', getRedisName(name, defaultAppName)],
33
34
  err => {
34
35
  if (err) {
35
36
  console.error(`Failed to set client name for ${name}:`, err)
@@ -56,7 +57,7 @@ const createSetClientNameForIoredis = (defaultAppName = 'undefined-app') => {
56
57
  client
57
58
  .call('CLIENT', [
58
59
  'SETNAME',
59
- getCorrectNameForRedis(name, defaultAppName),
60
+ getRedisName(name, defaultAppName),
60
61
  ])
61
62
  .then(() => {
62
63
  console.log(`Connected to Redis for pid:${process.pid} (${name})`)
@@ -83,7 +84,7 @@ const createSetClientNameForRedisV4 = (defaultAppName = 'undefined-app') => {
83
84
  await client.sendCommand([
84
85
  'CLIENT',
85
86
  'SETNAME',
86
- getCorrectNameForRedis(name, defaultAppName),
87
+ getRedisName(name, defaultAppName),
87
88
  ])
88
89
  console.log(`Connected to Redis for pid:${process.pid} (${name})`)
89
90
  } catch (err) {
@@ -141,5 +142,5 @@ module.exports = {
141
142
  REDIS_V4,
142
143
  REDIS_V3,
143
144
  IOREDIS,
144
- getCorrectNameForRedis,
145
+ getRedisName,
145
146
  }