@proappstore/sdk 1.16.43 → 1.16.45
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 +58 -0
- package/dist/actions.d.ts +2 -2
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +2 -2
- package/dist/actions.js.map +1 -1
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +33 -4
- package/dist/auth.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -5
- package/dist/index.js.map +1 -1
- package/dist/logs.d.ts +96 -0
- package/dist/logs.d.ts.map +1 -0
- package/dist/logs.js +298 -0
- package/dist/logs.js.map +1 -0
- package/dist/telemetry-transport.d.ts +36 -0
- package/dist/telemetry-transport.d.ts.map +1 -0
- package/dist/telemetry-transport.js +56 -0
- package/dist/telemetry-transport.js.map +1 -0
- package/dist/types.d.ts +11 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/usage.d.ts.map +1 -1
- package/dist/usage.js +10 -40
- package/dist/usage.js.map +1 -1
- package/package.json +1 -1
- package/dist/monitoring.d.ts +0 -58
- package/dist/monitoring.d.ts.map +0 -1
- package/dist/monitoring.js +0 -146
- package/dist/monitoring.js.map +0 -1
package/dist/monitoring.js
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Runtime monitoring — batches client log entries to
|
|
3
|
-
* `POST /v1/apps/:appId/logs` so app owners can inspect real user-facing
|
|
4
|
-
* failures after the fact (#105/#106).
|
|
5
|
-
*
|
|
6
|
-
* Auto-started by `initPro()` unless `monitoring.auto === false`. On start it
|
|
7
|
-
* captures uncaught `error` and `unhandledrejection` events; the SDK also feeds
|
|
8
|
-
* failed platform operations (e.g. `app.actions.call`) in via `log()`.
|
|
9
|
-
*
|
|
10
|
-
* Design (mirrors the Usage telemetry module):
|
|
11
|
-
* - **Browser-only / SSR-safe.** Every method no-ops without `window`.
|
|
12
|
-
* - **Silent.** Monitoring must never break an app — all network paths catch.
|
|
13
|
-
* - **Batched.** Entries queue and flush on an interval + on `pagehide`
|
|
14
|
-
* (sendBeacon/keepalive so the last batch survives unload).
|
|
15
|
-
* - **No secrets/PII.** Auto-capture takes only message + stack + source; the
|
|
16
|
-
* SDK never logs request bodies, SQL params, tokens, or credential values.
|
|
17
|
-
*/
|
|
18
|
-
const FLUSH_MS = 15_000;
|
|
19
|
-
const MAX_QUEUE = 100;
|
|
20
|
-
const MAX_MESSAGE = 2000;
|
|
21
|
-
const MAX_STACK = 4000;
|
|
22
|
-
function hasBrowser() {
|
|
23
|
-
return typeof window !== 'undefined';
|
|
24
|
-
}
|
|
25
|
-
function trunc(s, max) {
|
|
26
|
-
return typeof s === 'string' ? s.slice(0, max) : '';
|
|
27
|
-
}
|
|
28
|
-
export class Monitoring {
|
|
29
|
-
appId;
|
|
30
|
-
apiBase;
|
|
31
|
-
auth;
|
|
32
|
-
build;
|
|
33
|
-
queue = [];
|
|
34
|
-
running = false;
|
|
35
|
-
timer = null;
|
|
36
|
-
onError = null;
|
|
37
|
-
onRejection = null;
|
|
38
|
-
onPageHide = null;
|
|
39
|
-
constructor(appId, apiBase, auth, build) {
|
|
40
|
-
this.appId = appId;
|
|
41
|
-
this.apiBase = apiBase;
|
|
42
|
-
this.auth = auth;
|
|
43
|
-
this.build = build;
|
|
44
|
-
}
|
|
45
|
-
/** Attach auto-capture + periodic flush. Idempotent. */
|
|
46
|
-
start() {
|
|
47
|
-
if (this.running || !hasBrowser())
|
|
48
|
-
return;
|
|
49
|
-
this.running = true;
|
|
50
|
-
this.onError = (e) => this.log('error', 'runtime', e.message || 'uncaught error', {
|
|
51
|
-
stack: trunc(e.error?.stack, MAX_STACK), source: e.filename, line: e.lineno, col: e.colno,
|
|
52
|
-
});
|
|
53
|
-
this.onRejection = (e) => {
|
|
54
|
-
const r = e.reason;
|
|
55
|
-
this.log('error', 'unhandledrejection', trunc(r?.message ?? String(e.reason ?? 'rejection'), MAX_MESSAGE), {
|
|
56
|
-
stack: trunc(r?.stack, MAX_STACK),
|
|
57
|
-
});
|
|
58
|
-
};
|
|
59
|
-
this.onPageHide = () => this.flush(true);
|
|
60
|
-
window.addEventListener('error', this.onError);
|
|
61
|
-
window.addEventListener('unhandledrejection', this.onRejection);
|
|
62
|
-
window.addEventListener('pagehide', this.onPageHide);
|
|
63
|
-
this.timer = setInterval(() => this.flush(false), FLUSH_MS);
|
|
64
|
-
}
|
|
65
|
-
/** Detach handlers + stop flushing. Idempotent. Does not flush. */
|
|
66
|
-
stop() {
|
|
67
|
-
if (!this.running)
|
|
68
|
-
return;
|
|
69
|
-
this.running = false;
|
|
70
|
-
if (this.timer) {
|
|
71
|
-
clearInterval(this.timer);
|
|
72
|
-
this.timer = null;
|
|
73
|
-
}
|
|
74
|
-
if (hasBrowser()) {
|
|
75
|
-
if (this.onError)
|
|
76
|
-
window.removeEventListener('error', this.onError);
|
|
77
|
-
if (this.onRejection)
|
|
78
|
-
window.removeEventListener('unhandledrejection', this.onRejection);
|
|
79
|
-
if (this.onPageHide)
|
|
80
|
-
window.removeEventListener('pagehide', this.onPageHide);
|
|
81
|
-
}
|
|
82
|
-
this.onError = this.onRejection = this.onPageHide = null;
|
|
83
|
-
}
|
|
84
|
-
/** Queue a log entry. Cheap; no network until the next flush. */
|
|
85
|
-
log(level, category, message, data) {
|
|
86
|
-
const route = hasBrowser() && window.location ? window.location.pathname : undefined;
|
|
87
|
-
const entry = {
|
|
88
|
-
ts: Date.now(),
|
|
89
|
-
level,
|
|
90
|
-
category: category.slice(0, 64),
|
|
91
|
-
message: trunc(message, MAX_MESSAGE),
|
|
92
|
-
data: { mode: this.auth.usesPlatformCookie ? 'platform-cookie' : 'legacy-bearer', ...(route ? { route } : {}), ...data },
|
|
93
|
-
};
|
|
94
|
-
this.queue.push(entry);
|
|
95
|
-
// Bound memory: drop the oldest if a burst outruns the flush interval.
|
|
96
|
-
if (this.queue.length > MAX_QUEUE)
|
|
97
|
-
this.queue.splice(0, this.queue.length - MAX_QUEUE);
|
|
98
|
-
}
|
|
99
|
-
error(category, message, data) { this.log('error', category, message, data); }
|
|
100
|
-
warn(category, message, data) { this.log('warn', category, message, data); }
|
|
101
|
-
info(category, message, data) { this.log('info', category, message, data); }
|
|
102
|
-
/** Log a caught exception with its stack. */
|
|
103
|
-
capture(err, category = 'runtime') {
|
|
104
|
-
const e = err;
|
|
105
|
-
this.log('error', category, trunc(e?.message ?? String(err), MAX_MESSAGE), { stack: trunc(e?.stack, MAX_STACK) });
|
|
106
|
-
}
|
|
107
|
-
/** Send queued entries. `keepalive` for page-close paths (sendBeacon). */
|
|
108
|
-
flush(keepalive = false) {
|
|
109
|
-
if (!this.queue.length || !this.isAuthenticated())
|
|
110
|
-
return;
|
|
111
|
-
const entries = this.queue.splice(0, this.queue.length).map((e) => ({
|
|
112
|
-
...e,
|
|
113
|
-
...(this.build ? { build: this.build } : {}),
|
|
114
|
-
}));
|
|
115
|
-
const body = JSON.stringify({ entries });
|
|
116
|
-
const url = this.auth.usesPlatformCookie
|
|
117
|
-
? `/.pas/api/v1/apps/${encodeURIComponent(this.appId)}/logs`
|
|
118
|
-
: `${this.apiBase}/v1/apps/${encodeURIComponent(this.appId)}/logs`;
|
|
119
|
-
if (keepalive && typeof navigator !== 'undefined' && typeof navigator.sendBeacon === 'function') {
|
|
120
|
-
try {
|
|
121
|
-
if (navigator.sendBeacon(url, new Blob([body], { type: 'application/json' })))
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
catch { /* fall through */ }
|
|
125
|
-
}
|
|
126
|
-
try {
|
|
127
|
-
const headers = { 'Content-Type': 'application/json' };
|
|
128
|
-
const init = { method: 'POST', headers, body, keepalive };
|
|
129
|
-
if (this.auth.usesPlatformCookie) {
|
|
130
|
-
init.credentials = 'same-origin';
|
|
131
|
-
}
|
|
132
|
-
else {
|
|
133
|
-
if (!this.auth.token) {
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
headers.Authorization = `Bearer ${this.auth.token}`;
|
|
137
|
-
}
|
|
138
|
-
void fetch(url, init).catch(() => { });
|
|
139
|
-
}
|
|
140
|
-
catch { /* monitoring never breaks an app */ }
|
|
141
|
-
}
|
|
142
|
-
isAuthenticated() {
|
|
143
|
-
return this.auth.usesPlatformCookie ? this.auth.isSignedIn === true : !!this.auth.token;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
//# sourceMappingURL=monitoring.js.map
|
package/dist/monitoring.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"monitoring.js","sourceRoot":"","sources":["../src/monitoring.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAyBH,MAAM,QAAQ,GAAG,MAAM,CAAC;AACxB,MAAM,SAAS,GAAG,GAAG,CAAC;AACtB,MAAM,WAAW,GAAG,IAAI,CAAC;AACzB,MAAM,SAAS,GAAG,IAAI,CAAC;AAEvB,SAAS,UAAU;IACjB,OAAO,OAAO,MAAM,KAAK,WAAW,CAAC;AACvC,CAAC;AACD,SAAS,KAAK,CAAC,CAAU,EAAE,GAAW;IACpC,OAAO,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACtD,CAAC;AAED,MAAM,OAAO,UAAU;IASF;IACA;IACA;IACA;IAXX,KAAK,GAAgB,EAAE,CAAC;IACxB,OAAO,GAAG,KAAK,CAAC;IAChB,KAAK,GAA0C,IAAI,CAAC;IACpD,OAAO,GAAqC,IAAI,CAAC;IACjD,WAAW,GAAgD,IAAI,CAAC;IAChE,UAAU,GAAwB,IAAI,CAAC;IAE/C,YACmB,KAAa,EACb,OAAe,EACf,IAAc,EACd,KAA+B;QAH/B,UAAK,GAAL,KAAK,CAAQ;QACb,YAAO,GAAP,OAAO,CAAQ;QACf,SAAI,GAAJ,IAAI,CAAU;QACd,UAA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