@royaltics/tracker-sails 0.0.1 → 0.0.20
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 +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +54 -42
- package/dist/types/index.d.ts +15 -2
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const a=require("@royaltics/tracker");module.exports=function(t){let e;return{defaults:{__configKey__:{enabled:!0,webhookUrl:"N/A",licenseId:"",licenseDevice:"",licenseName:"",app:"sails-app",version:"",platform:"sails",maxRetries:3,timeout:1e4,flushInterval:1e4,maxQueueSize:100,headers:{}}},initialize:function(i){const n=t.config.tracker||{};if(!n.enabled)return t.log.warn("@royaltics/tracker-sails hook deactivated"),i();if(!n.webhookUrl)return t.log.error("DSN for @royaltics/tracker-sails is required in config/tracker.js"),i();try{n.debug&&t.log.info("Initializing @royaltics/tracker-sails..."),e=a.create(n),t.tracker={error:(r,u)=>e.error(r,"ERROR",u),fatal:(r,u)=>e.error(r,"FATAL",u),debug:(r,u)=>e.error(r,"DEBUG",u),capture:(r,u,s)=>e.error(r,u,s),info:(r,u)=>e.event(r,"INFO",u),warn:(r,u)=>e.event(r,"WARNING",u),event:(r,u,s)=>e.event(r,u,s),flush:async()=>await e.forceFlush(),pause:()=>e.pause(),resume:()=>e.resume(),shutdown:()=>e.shutdown()},n.debug&&t.log.info("@royaltics/tracker-sails initialized successfully"),process.on("unhandledRejection",function(r){n.debug&&t.log.info("Unhandled rejection:",r),e==null||e.error(r instanceof Error?r:new Error(String(r)))}),n.captureRoutes&&l(t,e,n),n.debug&&t.log.info("@royaltics/tracker-sails initialized successfully")}catch(r){n.debug&&t.log.error("Failed to initialize @royaltics/tracker-sails:",r)}return i()},shutdown:function(i){e&&a.shutdown(),i()}}};function l(o,t,e){o.on&&(o.on("router:request",(i,n)=>{if(d(i.url,["https://sailsjs.com","https://api.royaltics.com"]))return;const r=c(i,e);t.event("Request received","INFO",{request:r})}),o.on("router:request:error",(i,n)=>{if(e.ignoredErrors||f(i,["SailsError","RoyalticsError"]))return;const r=c(n,e);t.error(i,"ERROR",{request:r})}))}function c(o,t){return{method:o.method??"UNKNOWN",url:o.url??"UNKNOWN",ip:o.ip,headers:t.captureHeaders?o.headers:void 0,query:t.captureQueries?o.query:void 0,body:t.captureQueries?o.body:void 0}}function d(o,t){return t?t.some(e=>new RegExp(e).test(o)):!1}function f(o,t){return t?t.some(e=>{const i=new RegExp(e);return i.test(o.name)||i.test(o.message)}):!1}
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import type { SailsErrorTrackerConfig, RequestContext, SailsTrackerClient } from './types';
|
|
2
|
+
export type { SailsTrackerClient, SailsErrorTrackerConfig, RequestContext };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
var
|
|
2
|
-
import
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
let
|
|
1
|
+
var d = (o, e) => () => (e || o((e = { exports: {} }).exports, e), e.exports);
|
|
2
|
+
import a from "@royaltics/tracker";
|
|
3
|
+
var p = d((R, l) => {
|
|
4
|
+
l.exports = function(e) {
|
|
5
|
+
let r;
|
|
6
6
|
return {
|
|
7
7
|
defaults: {
|
|
8
8
|
__configKey__: {
|
|
@@ -21,55 +21,67 @@ var g = c((y, a) => {
|
|
|
21
21
|
headers: {}
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
|
-
initialize: function(
|
|
25
|
-
const
|
|
26
|
-
if (!
|
|
27
|
-
return e.log.warn("@royaltics/tracker-sails hook deactivated"),
|
|
28
|
-
if (!
|
|
29
|
-
return e.log.error("DSN for @royaltics/tracker-sails is required in config/tracker.js"),
|
|
24
|
+
initialize: function(i) {
|
|
25
|
+
const n = e.config.tracker || {};
|
|
26
|
+
if (!n.enabled)
|
|
27
|
+
return e.log.warn("@royaltics/tracker-sails hook deactivated"), i();
|
|
28
|
+
if (!n.webhookUrl)
|
|
29
|
+
return e.log.error("DSN for @royaltics/tracker-sails is required in config/tracker.js"), i();
|
|
30
30
|
try {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
n.debug && e.log.info("Initializing @royaltics/tracker-sails..."), r = a.create(n), e.tracker = {
|
|
32
|
+
error: (t, u) => r.error(t, "ERROR", u),
|
|
33
|
+
fatal: (t, u) => r.error(t, "FATAL", u),
|
|
34
|
+
debug: (t, u) => r.error(t, "DEBUG", u),
|
|
35
|
+
capture: (t, u, s) => r.error(t, u, s),
|
|
36
|
+
info: (t, u) => r.event(t, "INFO", u),
|
|
37
|
+
warn: (t, u) => r.event(t, "WARNING", u),
|
|
38
|
+
event: (t, u, s) => r.event(t, u, s),
|
|
39
|
+
flush: async () => await r.forceFlush(),
|
|
40
|
+
pause: () => r.pause(),
|
|
41
|
+
resume: () => r.resume(),
|
|
42
|
+
shutdown: () => r.shutdown()
|
|
43
|
+
}, n.debug && e.log.info("@royaltics/tracker-sails initialized successfully"), process.on("unhandledRejection", function(t) {
|
|
44
|
+
n.debug && e.log.info("Unhandled rejection:", t), r == null || r.error(t instanceof Error ? t : new Error(String(t)));
|
|
45
|
+
}), n.captureRoutes && f(e, r, n), n.debug && e.log.info("@royaltics/tracker-sails initialized successfully");
|
|
46
|
+
} catch (t) {
|
|
47
|
+
n.debug && e.log.error("Failed to initialize @royaltics/tracker-sails:", t);
|
|
36
48
|
}
|
|
37
|
-
return
|
|
49
|
+
return i();
|
|
38
50
|
},
|
|
39
|
-
shutdown: function(
|
|
40
|
-
|
|
51
|
+
shutdown: function(i) {
|
|
52
|
+
r && a.shutdown(), i();
|
|
41
53
|
}
|
|
42
54
|
};
|
|
43
55
|
};
|
|
44
|
-
function
|
|
45
|
-
|
|
46
|
-
if (
|
|
47
|
-
const
|
|
48
|
-
e.event("Request received", "INFO", { request:
|
|
49
|
-
}),
|
|
50
|
-
if (
|
|
51
|
-
const
|
|
52
|
-
e.error(
|
|
56
|
+
function f(o, e, r) {
|
|
57
|
+
o.on && (o.on("router:request", (i, n) => {
|
|
58
|
+
if (h(i.url, ["https://sailsjs.com", "https://api.royaltics.com"])) return;
|
|
59
|
+
const t = c(i, r);
|
|
60
|
+
e.event("Request received", "INFO", { request: t });
|
|
61
|
+
}), o.on("router:request:error", (i, n) => {
|
|
62
|
+
if (r.ignoredErrors || g(i, ["SailsError", "RoyalticsError"])) return;
|
|
63
|
+
const t = c(n, r);
|
|
64
|
+
e.error(i, "ERROR", { request: t });
|
|
53
65
|
}));
|
|
54
66
|
}
|
|
55
|
-
function
|
|
67
|
+
function c(o, e) {
|
|
56
68
|
return {
|
|
57
|
-
method:
|
|
58
|
-
url:
|
|
59
|
-
ip:
|
|
60
|
-
headers: e.captureHeaders ?
|
|
61
|
-
query: e.captureQueries ?
|
|
62
|
-
body: e.captureQueries ?
|
|
69
|
+
method: o.method ?? "UNKNOWN",
|
|
70
|
+
url: o.url ?? "UNKNOWN",
|
|
71
|
+
ip: o.ip,
|
|
72
|
+
headers: e.captureHeaders ? o.headers : void 0,
|
|
73
|
+
query: e.captureQueries ? o.query : void 0,
|
|
74
|
+
body: e.captureQueries ? o.body : void 0
|
|
63
75
|
};
|
|
64
76
|
}
|
|
65
|
-
function
|
|
66
|
-
return e ? e.some((
|
|
77
|
+
function h(o, e) {
|
|
78
|
+
return e ? e.some((r) => new RegExp(r).test(o)) : !1;
|
|
67
79
|
}
|
|
68
|
-
function
|
|
69
|
-
return e ? e.some((
|
|
70
|
-
const
|
|
71
|
-
return
|
|
80
|
+
function g(o, e) {
|
|
81
|
+
return e ? e.some((r) => {
|
|
82
|
+
const i = new RegExp(r);
|
|
83
|
+
return i.test(o.name) || i.test(o.message);
|
|
72
84
|
}) : !1;
|
|
73
85
|
}
|
|
74
86
|
});
|
|
75
|
-
export default
|
|
87
|
+
export default p();
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
1
|
-
import type { ClientConfig, ErrorTrackerClient } from '@royaltics/tracker';
|
|
1
|
+
import type { ClientConfig, ErrorTrackerClient, EventLevel } from '@royaltics/tracker';
|
|
2
|
+
export interface SailsTrackerClient {
|
|
3
|
+
readonly error: (error: Error | Record<string, unknown>, metadata?: Record<string, unknown>) => ErrorTrackerClient;
|
|
4
|
+
readonly fatal: (error: Error | Record<string, unknown>, metadata?: Record<string, unknown>) => ErrorTrackerClient;
|
|
5
|
+
readonly debug: (error: Error | Record<string, unknown>, metadata?: Record<string, unknown>) => ErrorTrackerClient;
|
|
6
|
+
readonly capture: (error: Error | Record<string, unknown>, level?: EventLevel, metadata?: Record<string, unknown>) => ErrorTrackerClient;
|
|
7
|
+
readonly info: (title: string, metadata?: Record<string, unknown>) => ErrorTrackerClient;
|
|
8
|
+
readonly warn: (title: string, metadata?: Record<string, unknown>) => ErrorTrackerClient;
|
|
9
|
+
readonly event: (title: string, level?: EventLevel, metadata?: Record<string, unknown>) => ErrorTrackerClient;
|
|
10
|
+
readonly flush: () => Promise<void>;
|
|
11
|
+
readonly pause: () => ErrorTrackerClient;
|
|
12
|
+
readonly resume: () => ErrorTrackerClient;
|
|
13
|
+
readonly shutdown: () => void;
|
|
14
|
+
}
|
|
2
15
|
export interface SailsErrorTrackerConfig extends Omit<ClientConfig, 'platform' | 'app'> {
|
|
3
16
|
readonly captureRoutes?: boolean;
|
|
4
17
|
readonly captureQueries?: boolean;
|
|
@@ -17,7 +30,7 @@ export interface SailsHookContext {
|
|
|
17
30
|
info: (message: string, ...args: unknown[]) => void;
|
|
18
31
|
};
|
|
19
32
|
on?: (event: string, handler: (...args: any[]) => void) => void;
|
|
20
|
-
tracker?:
|
|
33
|
+
tracker?: SailsTrackerClient;
|
|
21
34
|
};
|
|
22
35
|
}
|
|
23
36
|
export interface RequestContext {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@royaltics/tracker-sails",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.20",
|
|
4
4
|
"description": "Sails.js hook for Royaltics Error Tracker",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -55,6 +55,6 @@
|
|
|
55
55
|
"vitest": "^1.0.0"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@royaltics/tracker": "^0.0.
|
|
58
|
+
"@royaltics/tracker": "^0.0.20"
|
|
59
59
|
}
|
|
60
60
|
}
|