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