@bugmail-js/core 0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 MarcorpAI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Shared core logic for BugMail SDKs
2
+
3
+ This package will contain shared logic for Node.js and Django SDKs.
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Breadcrumb Tracker (core, generic)
3
+ * Records user actions and events leading up to errors
4
+ */
5
+
6
+ /**
7
+ * @typedef {Object} Breadcrumb
8
+ * @property {string} type - Type of breadcrumb (navigation, click, error, etc.)
9
+ * @property {string} category - Category (ui, network, user, etc.)
10
+ * @property {string} message - Description of the event
11
+ * @property {Object} [data] - Additional contextual data
12
+ * @property {number} timestamp - When the breadcrumb occurred
13
+ * @property {string} [level] - Severity level (info, warning, error)
14
+ */
15
+
16
+ export class BreadcrumbTracker {
17
+ constructor(config = {}) {
18
+ this.config = {
19
+ maxBreadcrumbs: 50,
20
+ ...config
21
+ };
22
+ this.breadcrumbs = [];
23
+ }
24
+
25
+ record(breadcrumb) {
26
+ const newBreadcrumb = {
27
+ timestamp: Date.now(),
28
+ level: 'info',
29
+ ...breadcrumb
30
+ };
31
+ this.breadcrumbs.push(newBreadcrumb);
32
+ if (this.breadcrumbs.length > this.config.maxBreadcrumbs) {
33
+ this.breadcrumbs = this.breadcrumbs.slice(-this.config.maxBreadcrumbs);
34
+ }
35
+ }
36
+
37
+ recordCustom(message, category = 'custom', data = {}, level = 'info') {
38
+ this.record({
39
+ type: 'custom',
40
+ category,
41
+ message,
42
+ data,
43
+ level
44
+ });
45
+ }
46
+
47
+ recordRequest(requestData) {
48
+ this.record({
49
+ type: 'http',
50
+ category: 'network',
51
+ message: `${requestData.method || 'GET'} ${requestData.url}`,
52
+ data: requestData,
53
+ level: requestData.error ? 'error' :
54
+ requestData.status >= 400 ? 'error' :
55
+ requestData.status >= 300 ? 'warning' : 'info'
56
+ });
57
+ }
58
+
59
+ getBreadcrumbs() {
60
+ return [...this.breadcrumbs];
61
+ }
62
+
63
+ clear() {
64
+ this.breadcrumbs = [];
65
+ }
66
+ }
@@ -0,0 +1,4 @@
1
+ export declare class BugMailCoreClient {
2
+ constructor(config?: any);
3
+ captureException(error: any, context?: any): void;
4
+ }
@@ -0,0 +1,58 @@
1
+ // Core BugMail client (shared logic)
2
+ // Extracted from browser SDK
3
+
4
+ export class BugMailCoreClient {
5
+ constructor(config = {}) {
6
+ this.config = { ...config };
7
+ // config.baseUrl (default: 'http://localhost:8000')
8
+ // config.apiPath (default: '/api/sdk/v1/errors')
9
+ // config.onError (optional callback)
10
+ }
11
+
12
+ /**
13
+ * Capture and report an exception to the BugMail backend
14
+ * @param {Error|any} error - The error object
15
+ * @param {Object} context - { headers, payload, ... }
16
+ */
17
+ async captureException(error, context = {}) {
18
+ const baseUrl = this.config.baseUrl || process.env.BUGMAIL_API_BASE_URL || 'http://localhost:8000';
19
+ const apiPath = this.config.apiPath || '/api/sdk/v1/errors';
20
+ const url = baseUrl.replace(/\/$/, '') + apiPath;
21
+ const headers = {
22
+ 'Content-Type': 'application/json',
23
+ ...(context.headers || {})
24
+ };
25
+ const payload = context.payload || {};
26
+
27
+ try {
28
+ // Use fetch if available (browser or Node >=18), else fallback
29
+ let fetchFn = (typeof fetch !== 'undefined') ? fetch : undefined;
30
+ if (!fetchFn) {
31
+ try {
32
+ // Dynamically import node-fetch if not in browser
33
+ fetchFn = (await import('node-fetch')).default;
34
+ } catch (e) {
35
+ console.error('[BugMail] fetch is not available in this environment.');
36
+ return;
37
+ }
38
+ }
39
+ const res = await fetchFn(url, {
40
+ method: 'POST',
41
+ headers,
42
+ body: JSON.stringify(payload),
43
+ });
44
+ if (!res.ok) {
45
+ const errText = await res.text();
46
+ console.error(`[BugMail] Failed to report error: ${res.status} ${res.statusText}\n${errText}`);
47
+ if (typeof this.config.onError === 'function') {
48
+ this.config.onError({ error, payload, status: res.status, statusText: res.statusText, body: errText });
49
+ }
50
+ }
51
+ } catch (err) {
52
+ console.error('[BugMail] Error sending error report:', err);
53
+ if (typeof this.config.onError === 'function') {
54
+ this.config.onError({ error, payload, exception: err });
55
+ }
56
+ }
57
+ }
58
+ }
@@ -0,0 +1,4 @@
1
+ // Error grouping utility (core)
2
+ export function generateErrorFingerprint(error) {
3
+ // ...core logic
4
+ }
@@ -0,0 +1,5 @@
1
+ // Error processor (core, no browser specifics)
2
+ export class CoreErrorProcessor {
3
+ constructor() {}
4
+ // ...core error normalization, stack trace parsing
5
+ }
package/index.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ export * from './bugmail-core-client';
2
+ declare module '@bugmail-js/core' {
3
+ export class BugMailCore {
4
+ constructor(config: any);
5
+ captureException(error: any, context?: any): void;
6
+ }
7
+ export type BugMailConfig = any;
8
+ }
package/index.js ADDED
@@ -0,0 +1,10 @@
1
+ // Core logic for BugMail SDK (shared between browser, node, etc)
2
+ // This will be populated by extracting reusable logic from browser SDK.
3
+
4
+ export { BugMailCoreClient } from './bugmail-core-client.js';
5
+ export { CoreNetworkManager } from './network-manager.js';
6
+ export { CoreErrorProcessor } from './error-processor.js';
7
+ export { CorePluginManager } from './plugin-manager.js';
8
+ export { BreadcrumbTracker } from './breadcrumb-tracker.js';
9
+ export * from './error-grouping.js';
10
+ export * from './source-map.js';
@@ -0,0 +1,8 @@
1
+ // Network manager (core, no browser specifics)
2
+ export class CoreNetworkManager {
3
+ constructor(config) {
4
+ this.config = config;
5
+ // ...core setup (no window, no localStorage)
6
+ }
7
+ // ...core methods (send, retry, queue, etc)
8
+ }
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@bugmail-js/core",
3
+ "version": "0.1.0",
4
+ "main": "index.js",
5
+ "module": "index.js",
6
+ "exports": {
7
+ ".": "./index.js",
8
+ "./bugmail-core-client": "./bugmail-core-client.js",
9
+ "./network-manager": "./network-manager.js",
10
+ "./error-processor": "./error-processor.js",
11
+ "./plugin-manager": "./plugin-manager.js",
12
+ "./breadcrumb-tracker": "./breadcrumb-tracker.js",
13
+ "./error-grouping": "./error-grouping.js",
14
+ "./source-map": "./source-map.js"
15
+ },
16
+ "description": "Core utilities for the BugMail SDK (framework-agnostic)",
17
+ "license": "MIT",
18
+ "types": "index.d.ts",
19
+ "files": [
20
+ "*.js",
21
+ "*.d.ts",
22
+ "README.md",
23
+ "LICENSE"
24
+ ],
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "git+https://github.com/MarcorpAI/Bugmail-SDKs.git",
31
+ "directory": "packages/core"
32
+ },
33
+ "homepage": "https://github.com/MarcorpAI/Bugmail-SDKs#readme",
34
+ "bugs": {
35
+ "url": "https://github.com/MarcorpAI/Bugmail-SDKs/issues"
36
+ },
37
+ "sideEffects": false
38
+ }
@@ -0,0 +1,7 @@
1
+ // Plugin manager (core, generic)
2
+ export class CorePluginManager {
3
+ constructor() {
4
+ // ...core plugin system
5
+ }
6
+ // ...core methods
7
+ }
package/source-map.js ADDED
@@ -0,0 +1,4 @@
1
+ // Source map utility (core)
2
+ export function parseStackTrace(stack) {
3
+ // ...core logic
4
+ }