@lokalise/fastify-extras 3.1.0 → 4.1.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/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { bugsnagPlugin, reportErrorToBugsnag } from './plugins/bugsnagPlugin';
2
2
  export type { ErrorReport } from './plugins/bugsnagPlugin';
3
- export { requestContextProviderPlugin, getRequestIdFastifyAppConfig, } from './plugins/requestContextProviderPlugin';
3
+ export { requestContextProviderPlugin, getRequestIdFastifyAppConfig, REQUEST_ID_STORE_KEY, } from './plugins/requestContextProviderPlugin';
4
4
  export type { RequestContext } from './plugins/requestContextProviderPlugin';
5
5
  export { newrelicTransactionManagerPlugin, NewRelicTransactionManager, } from './plugins/newrelicTransactionManagerPlugin';
6
6
  export type { NewRelicTransactionManagerOptions } from './plugins/newrelicTransactionManagerPlugin';
package/dist/index.js CHANGED
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.metricsPlugin = exports.NewRelicTransactionManager = exports.newrelicTransactionManagerPlugin = exports.getRequestIdFastifyAppConfig = exports.requestContextProviderPlugin = exports.reportErrorToBugsnag = exports.bugsnagPlugin = void 0;
3
+ exports.metricsPlugin = exports.NewRelicTransactionManager = exports.newrelicTransactionManagerPlugin = exports.REQUEST_ID_STORE_KEY = exports.getRequestIdFastifyAppConfig = exports.requestContextProviderPlugin = exports.reportErrorToBugsnag = exports.bugsnagPlugin = void 0;
4
4
  var bugsnagPlugin_1 = require("./plugins/bugsnagPlugin");
5
5
  Object.defineProperty(exports, "bugsnagPlugin", { enumerable: true, get: function () { return bugsnagPlugin_1.bugsnagPlugin; } });
6
6
  Object.defineProperty(exports, "reportErrorToBugsnag", { enumerable: true, get: function () { return bugsnagPlugin_1.reportErrorToBugsnag; } });
7
7
  var requestContextProviderPlugin_1 = require("./plugins/requestContextProviderPlugin");
8
8
  Object.defineProperty(exports, "requestContextProviderPlugin", { enumerable: true, get: function () { return requestContextProviderPlugin_1.requestContextProviderPlugin; } });
9
9
  Object.defineProperty(exports, "getRequestIdFastifyAppConfig", { enumerable: true, get: function () { return requestContextProviderPlugin_1.getRequestIdFastifyAppConfig; } });
10
+ Object.defineProperty(exports, "REQUEST_ID_STORE_KEY", { enumerable: true, get: function () { return requestContextProviderPlugin_1.REQUEST_ID_STORE_KEY; } });
10
11
  var newrelicTransactionManagerPlugin_1 = require("./plugins/newrelicTransactionManagerPlugin");
11
12
  Object.defineProperty(exports, "newrelicTransactionManagerPlugin", { enumerable: true, get: function () { return newrelicTransactionManagerPlugin_1.newrelicTransactionManagerPlugin; } });
12
13
  Object.defineProperty(exports, "NewRelicTransactionManager", { enumerable: true, get: function () { return newrelicTransactionManagerPlugin_1.NewRelicTransactionManager; } });
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";;;AAAA,yDAA6E;AAApE,8GAAA,aAAa,OAAA;AAAE,qHAAA,oBAAoB,OAAA;AAG5C,uFAG+C;AAF7C,4IAAA,4BAA4B,OAAA;AAC5B,4IAAA,4BAA4B,OAAA;AAI9B,+FAGmD;AAFjD,oJAAA,gCAAgC,OAAA;AAChC,8IAAA,0BAA0B,OAAA;AAI5B,yDAAuD;AAA9C,8GAAA,aAAa,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";;;AAAA,yDAA6E;AAApE,8GAAA,aAAa,OAAA;AAAE,qHAAA,oBAAoB,OAAA;AAG5C,uFAI+C;AAH7C,4IAAA,4BAA4B,OAAA;AAC5B,4IAAA,4BAA4B,OAAA;AAC5B,oIAAA,oBAAoB,OAAA;AAItB,+FAGmD;AAFjD,oJAAA,gCAAgC,OAAA;AAChC,8IAAA,0BAA0B,OAAA;AAI5B,yDAAuD;AAA9C,8GAAA,aAAa,OAAA"}
@@ -8,4 +8,8 @@ export interface ErrorReport {
8
8
  context?: Record<string, unknown>;
9
9
  }
10
10
  export declare const reportErrorToBugsnag: ({ error, severity, unhandled, context, }: ErrorReport) => false | void;
11
- export declare const bugsnagPlugin: import("fastify").FastifyPluginCallback<NodeConfig, import("fastify").RawServerDefault, import("fastify").FastifyTypeProviderDefault, import("fastify").FastifyBaseLogger>;
11
+ export interface BugsnagPluginConfig {
12
+ bugsnag: NodeConfig;
13
+ isEnabled: boolean;
14
+ }
15
+ export declare const bugsnagPlugin: import("fastify").FastifyPluginCallback<BugsnagPluginConfig, import("fastify").RawServerDefault, import("fastify").FastifyTypeProviderDefault, import("fastify").FastifyBaseLogger>;
@@ -14,7 +14,9 @@ const reportErrorToBugsnag = ({ error, severity = 'error', unhandled = true, con
14
14
  });
15
15
  exports.reportErrorToBugsnag = reportErrorToBugsnag;
16
16
  function plugin(app, opts, done) {
17
- js_1.default.start(opts);
17
+ if (opts.isEnabled) {
18
+ js_1.default.start(opts.bugsnag);
19
+ }
18
20
  done();
19
21
  }
20
22
  exports.bugsnagPlugin = (0, fastify_plugin_1.default)(plugin, {
@@ -1 +1 @@
1
- {"version":3,"file":"bugsnagPlugin.js","sourceRoot":"","sources":["../../lib/plugins/bugsnagPlugin.ts"],"names":[],"mappings":";;;;AACA,6DAAiC;AAGjC,4EAA+B;AAWxB,MAAM,oBAAoB,GAAG,CAAC,EACnC,KAAK,EACL,QAAQ,GAAG,OAAO,EAClB,SAAS,GAAG,IAAI,EAChB,OAAO,GACK,EAAE,EAAE,CAChB,YAAO,CAAC,SAAS,EAAE;IACnB,YAAO,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE;QAC9B,KAAK,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACzB,KAAK,CAAC,SAAS,GAAG,SAAS,CAAA;QAC3B,IAAI,OAAO,EAAE;YACX,KAAK,CAAC,WAAW,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;SACtC;IACH,CAAC,C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, "__esModule", { value: true });
3
3
  exports.newrelicTransactionManagerPlugin = exports.NewRelicTransactionManager = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const fastify_plugin_1 = tslib_1.__importDefault(require("fastify-plugin"));
6
- const newrelic_1 = require("newrelic");
6
+ let newrelic;
7
7
  class NewRelicTransactionManager {
8
8
  isEnabled;
9
9
  transactionMap;
10
10
  constructor(isNewRelicEnabled) {
11
+ if (isNewRelicEnabled) {
12
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
13
+ newrelic = require('newrelic');
14
+ }
11
15
  this.isEnabled = isNewRelicEnabled;
12
16
  this.transactionMap = new Map();
13
17
  }
@@ -15,8 +19,8 @@ class NewRelicTransactionManager {
15
19
  if (!this.isEnabled) {
16
20
  return;
17
21
  }
18
- (0, newrelic_1.startBackgroundTransaction)(jobName, () => {
19
- this.transactionMap.set(jobName, (0, newrelic_1.getTransaction)());
22
+ newrelic.startBackgroundTransaction(jobName, () => {
23
+ this.transactionMap.set(jobName, newrelic.getTransaction());
20
24
  });
21
25
  }
22
26
  stop(jobId) {
@@ -35,16 +39,18 @@ exports.NewRelicTransactionManager = NewRelicTransactionManager;
35
39
  function plugin(fastify, opts, done) {
36
40
  const manager = new NewRelicTransactionManager(opts.isEnabled);
37
41
  fastify.decorate('newrelicTransactionManager', manager);
38
- fastify.addHook('onClose', async () => {
39
- return new Promise((resolve, reject) => {
40
- (0, newrelic_1.shutdown)((error) => {
41
- if (error) {
42
- return reject(error);
43
- }
44
- resolve();
42
+ if (opts.isEnabled) {
43
+ fastify.addHook('onClose', async () => {
44
+ return new Promise((resolve, reject) => {
45
+ newrelic.shutdown((error) => {
46
+ if (error) {
47
+ return reject(error);
48
+ }
49
+ resolve();
50
+ });
45
51
  });
46
52
  });
47
- });
53
+ }
48
54
  done();
49
55
  }
50
56
  exports.newrelicTransactionManagerPlugin = (0, fastify_plugin_1.default)(plugin, {
@@ -1 +1 @@
1
- {"version":3,"file":"newrelicTransactionManagerPlugin.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A,mBAAQ,EAAC,CAAC,KAAK,EAAE,EAAE;gBACjB,IAAI,KAAK,EAAE;oBACT,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;iBACrB;gBACD,OAAO,EAAE,CAAA;YACX,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,IAAI,EAAE,CAAA;AACR,CAAC;AAEY,QAAA,gCAAgC,GAAG,IAAA,wBAAE,EAAC,MAAM,EAAE;IACzD,OAAO,EAAE,KAAK;IACd,IAAI,EAAE,qCAAqC;CAC5C,CAAC,CAAA"}
1
+ {"version":3,"file":"newrelicTransactionManagerPlugin.js","sourceRoot":"","sources":["../../lib/plugins/newrelicTransactionManagerPlugin.ts"],"names":[],"mappings":";;;;AACA,4EAA+B;AAc/B,IAAI,QAAkB,CAAA;AAYtB,MAAa,0BAA0B;IACpB,SAAS,CAAS;IAClB,cAAc,CAAgC;IAE/D,YAAY,iBAA0B;QACpC,IAAI,iBAAiB,EAAE;YACrB,mEAAmE;YACnE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;SAC/B;QAED,IAAI,CAAC,SAAS,GAAG,iBAAiB,CAAA;QAClC,IAAI,CAAC,cAAc,GAAG,IAAI,GAAG,EAAE,CAAA;IACjC,CAAC;IAEM,KAAK,CAAC,OAAe;QAC1B,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;YACnB,OAAM;SACP;QAED,QAAQ,CAAC,0BAA0B,CAAC,OAAO,EAAE,GAAG,EAAE;YAChD,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,cAAc,EAAE,CAAC,CAAA;QAC7D,CAAC,CAAC,CAAA;IACJ,CAAC;IAEM,IAAI,CAAC,KAAa;QACvB,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;YACnB,OAAM;SACP;QAED,MAAM,WAAW,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,IAAI,CAAA;QAC1D,IAAI,IAAI,KAAK,WAAW,EAAE;YACxB,OAAM;SACP;QACD,WAAW,CAAC,GAAG,EAAE,CAAA;QACjB,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IACnC,CAAC;CACF;AApCD,gEAoCC;AAED,SAAS,MAAM,CACb,OAAwB,EACxB,IAAuC,EACvC,IAAgB;IAEhB,MAAM,OAAO,GAAG,IAAI,0BAA0B,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;IAE9D,OAAO,CAAC,QAAQ,CAAC,4BAA4B,EAAE,OAAO,CAAC,CAAA;IAEvD,IAAI,IAAI,CAAC,SAAS,EAAE;QAClB,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,KAAK,IAAI,EAAE;YACpC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;gBACrC,QAAQ,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE;oBAC1B,IAAI,KAAK,EAAE;wBACT,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;qBACrB;oBACD,OAAO,EAAE,CAAA;gBACX,CAAC,CAAC,CAAA;YACJ,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;KACH;IAED,IAAI,EAAE,CAAA;AACR,CAAC;AAEY,QAAA,gCAAgC,GAAG,IAAA,wBAAE,EAAC,MAAM,EAAE;IACzD,OAAO,EAAE,KAAK;IACd,IAAI,EAAE,qCAAqC;CAC5C,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lokalise/fastify-extras",
3
- "version": "3.1.0",
3
+ "version": "4.1.0",
4
4
  "description": "Opinionated set of fastify plugins, commonly used in Lokalise",
5
5
  "author": {
6
6
  "name": "Lokalise",