@molecule/api-error-tracking-console 1.0.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,115 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work.
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other modifications
42
+ represent, as a whole, an original work of authorship.
43
+
44
+ "Contribution" shall mean any work of authorship, including the
45
+ original version of the Work and any modifications or additions
46
+ to that Work, that is intentionally submitted to the Licensor for
47
+ inclusion in the Work by the copyright owner or by an individual or
48
+ Legal Entity authorized to submit on behalf of the copyright owner.
49
+
50
+ "Contributor" shall mean Licensor and any individual or Legal Entity
51
+ on behalf of whom a Contribution has been received by the Licensor and
52
+ subsequently incorporated within the Work.
53
+
54
+ 2. Grant of Copyright License. Subject to the terms and conditions of
55
+ this License, each Contributor hereby grants to You a perpetual,
56
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
57
+ copyright license to reproduce, prepare Derivative Works of,
58
+ publicly display, publicly perform, sublicense, and distribute the
59
+ Work and such Derivative Works in Source or Object form.
60
+
61
+ 3. Grant of Patent License. Subject to the terms and conditions of
62
+ this License, each Contributor hereby grants to You a perpetual,
63
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
64
+ patent license to make, have made, use, offer to sell, sell, import,
65
+ and otherwise transfer the Work.
66
+
67
+ 4. Redistribution. You may reproduce and distribute copies of the
68
+ Work or Derivative Works thereof in any medium, with or without
69
+ modifications, and in Source or Object form, provided that You
70
+ meet the following conditions:
71
+
72
+ (a) You must give any other recipients of the Work or
73
+ Derivative Works a copy of this License; and
74
+
75
+ (b) You must cause any modified files to carry prominent notices
76
+ stating that You changed the files; and
77
+
78
+ (c) You must retain, in the Source form of any Derivative Works
79
+ that You distribute, all copyright, patent, trademark, and
80
+ attribution notices from the Source form of the Work,
81
+ excluding those notices that do not pertain to any part of
82
+ the Derivative Works; and
83
+
84
+ (d) If the Work includes a "NOTICE" text file as part of its
85
+ distribution, then any Derivative Works that You distribute must
86
+ include a readable copy of the attribution notices contained
87
+ within such NOTICE file.
88
+
89
+ 5. Submission of Contributions.
90
+
91
+ 6. Trademarks. This License does not grant permission to use the trade
92
+ names, trademarks, service marks, or product names of the Licensor.
93
+
94
+ 7. Disclaimer of Warranty. Unless required by applicable law or
95
+ agreed to in writing, Licensor provides the Work on an "AS IS" BASIS,
96
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND.
97
+
98
+ 8. Limitation of Liability. In no event and under no legal theory shall
99
+ any Contributor be liable to You for damages.
100
+
101
+ 9. Accepting Warranty or Additional Liability.
102
+
103
+ Copyright 2026 Molecule Dev, Inc.
104
+
105
+ Licensed under the Apache License, Version 2.0 (the "License");
106
+ you may not use this file except in compliance with the License.
107
+ You may obtain a copy of the License at
108
+
109
+ http://www.apache.org/licenses/LICENSE-2.0
110
+
111
+ Unless required by applicable law or agreed to in writing, software
112
+ distributed under the License is distributed on an "AS IS" BASIS,
113
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
114
+ See the License for the specific language governing permissions and
115
+ limitations under the License.
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=browser-guard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser-guard.d.ts","sourceRoot":"","sources":["../src/browser-guard.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,CAAA"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Browser guard — `@molecule/api-error-tracking-console` is SERVER-ONLY.
3
+ *
4
+ * Generated by scripts/gen-browser-guards.mjs (workspace root) — edit THAT, not this.
5
+ * Evaluating a server package in a browser bundle is always an import-graph mistake
6
+ * (node APIs, secrets); without this guard it surfaces as a cryptic downstream crash
7
+ * ("Buffer is not defined") far from the culprit. Throwing here names the package and
8
+ * the fix at the exact moment the client bundle evaluates it. jsdom tests and SSR are
9
+ * unaffected: the throw requires browser globals AND the absence of a node runtime.
10
+ */
11
+ const g = globalThis;
12
+ if (g.window !== undefined && g.document !== undefined && !g.process?.versions?.node) {
13
+ throw new Error('@molecule/api-error-tracking-console is SERVER-ONLY: it was bundled into browser/client code. Import it only ' +
14
+ 'from server code (a server route/function or your API), or dynamic-import it inside ' +
15
+ 'the server handler — never from components or shared client modules, and never ' +
16
+ 'polyfill Buffer/process to silence this.');
17
+ }
18
+ export {};
19
+ //# sourceMappingURL=browser-guard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser-guard.js","sourceRoot":"","sources":["../src/browser-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,CAAC,GAAG,UAIT,CAAA;AACD,IAAI,CAAC,CAAC,MAAM,KAAK,SAAS,IAAI,CAAC,CAAC,QAAQ,KAAK,SAAS,IAAI,CAAC,CAAC,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IACrF,MAAM,IAAI,KAAK,CACb,+GAA+G;QAC7G,sFAAsF;QACtF,iFAAiF;QACjF,0CAA0C,CAC7C,CAAA;AACH,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Console (logger-based) error tracking provider for molecule.dev.
3
+ *
4
+ * Zero-credential development default: captures are written as structured
5
+ * log lines through the bonded logger instead of being sent to a remote
6
+ * service. Swap in a remote bond (e.g. `@molecule/api-error-tracking-sentry`)
7
+ * for production without changing any consumer code.
8
+ *
9
+ * @module
10
+ * @example
11
+ * ```typescript
12
+ * import { setProvider, captureException } from '@molecule/api-error-tracking'
13
+ * import { provider } from '@molecule/api-error-tracking-console'
14
+ *
15
+ * // Bond at startup (e.g. in setupBonds()) — no credentials needed
16
+ * setProvider(provider)
17
+ *
18
+ * // Logs a structured "error-tracking: exception captured" line
19
+ * captureException(new Error('boom'), { tags: { source: 'worker' } })
20
+ * ```
21
+ * @remarks
22
+ * - Requires no configuration or credentials — safe in every environment.
23
+ * - Each capture gets a generated event id (returned and logged), mirroring
24
+ * remote providers so consumer code behaves identically in development.
25
+ * - `setUser()` scopes subsequent captures like a remote provider's user
26
+ * scope; `flush()` trivially resolves `true` (nothing is buffered).
27
+ */
28
+ export * from './browser-guard.js';
29
+ export * from './provider.js';
30
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,cAAc,oBAAoB,CAAA;AAClC,cAAc,eAAe,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Console (logger-based) error tracking provider for molecule.dev.
3
+ *
4
+ * Zero-credential development default: captures are written as structured
5
+ * log lines through the bonded logger instead of being sent to a remote
6
+ * service. Swap in a remote bond (e.g. `@molecule/api-error-tracking-sentry`)
7
+ * for production without changing any consumer code.
8
+ *
9
+ * @module
10
+ * @example
11
+ * ```typescript
12
+ * import { setProvider, captureException } from '@molecule/api-error-tracking'
13
+ * import { provider } from '@molecule/api-error-tracking-console'
14
+ *
15
+ * // Bond at startup (e.g. in setupBonds()) — no credentials needed
16
+ * setProvider(provider)
17
+ *
18
+ * // Logs a structured "error-tracking: exception captured" line
19
+ * captureException(new Error('boom'), { tags: { source: 'worker' } })
20
+ * ```
21
+ * @remarks
22
+ * - Requires no configuration or credentials — safe in every environment.
23
+ * - Each capture gets a generated event id (returned and logged), mirroring
24
+ * remote providers so consumer code behaves identically in development.
25
+ * - `setUser()` scopes subsequent captures like a remote provider's user
26
+ * scope; `flush()` trivially resolves `true` (nothing is buffered).
27
+ */
28
+ export * from './browser-guard.js';
29
+ export * from './provider.js';
30
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,cAAc,oBAAoB,CAAA;AAClC,cAAc,eAAe,CAAA"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Console (logger-based) error tracking provider implementation.
3
+ *
4
+ * Zero-credential development default: every capture is written as a
5
+ * structured log line through the bonded logger (`getLogger()` from
6
+ * `@molecule/api-bond`, console fallback). Nothing leaves the process, so
7
+ * there is nothing to configure and nothing to flush.
8
+ *
9
+ * @module
10
+ */
11
+ import type { ErrorTrackingProvider } from '@molecule/api-error-tracking';
12
+ /**
13
+ * Console error tracking provider. Logs structured captures through the
14
+ * bonded logger and reports a generated event id, mirroring the remote
15
+ * providers' behavior so app code works identically in development.
16
+ */
17
+ export declare const provider: ErrorTrackingProvider;
18
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH,OAAO,KAAK,EAGV,qBAAqB,EAEtB,MAAM,8BAA8B,CAAA;AAiCrC;;;;GAIG;AACH,eAAO,MAAM,QAAQ,EAAE,qBAmCtB,CAAA"}
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Console (logger-based) error tracking provider implementation.
3
+ *
4
+ * Zero-credential development default: every capture is written as a
5
+ * structured log line through the bonded logger (`getLogger()` from
6
+ * `@molecule/api-bond`, console fallback). Nothing leaves the process, so
7
+ * there is nothing to configure and nothing to flush.
8
+ *
9
+ * @module
10
+ */
11
+ import { randomUUID } from 'node:crypto';
12
+ import { getLogger } from '@molecule/api-bond';
13
+ const logger = getLogger();
14
+ /** Maps a normalized severity level to the logger method that renders it. */
15
+ const levelToLogMethod = {
16
+ fatal: 'error',
17
+ error: 'error',
18
+ warning: 'warn',
19
+ info: 'info',
20
+ debug: 'debug',
21
+ };
22
+ /** The user set via `setUser()`, merged into subsequent captures (Sentry-scope parity). */
23
+ let currentUser = null;
24
+ /**
25
+ * Builds the structured log payload for a capture: the per-capture context
26
+ * with the scoped `setUser()` user applied when the capture has none.
27
+ *
28
+ * @param context - The capture's normalized context, if any.
29
+ * @returns Structured fields for the log line (empty fields omitted).
30
+ */
31
+ const toLogFields = (context) => {
32
+ const fields = {};
33
+ if (context?.tags)
34
+ fields.tags = context.tags;
35
+ const user = context?.user ?? currentUser;
36
+ if (user)
37
+ fields.user = user;
38
+ if (context?.extra)
39
+ fields.extra = context.extra;
40
+ if (context?.request)
41
+ fields.request = context.request;
42
+ return fields;
43
+ };
44
+ /**
45
+ * Console error tracking provider. Logs structured captures through the
46
+ * bonded logger and reports a generated event id, mirroring the remote
47
+ * providers' behavior so app code works identically in development.
48
+ */
49
+ export const provider = {
50
+ captureException(error, context) {
51
+ const eventId = randomUUID();
52
+ logger.error('error-tracking: exception captured', {
53
+ eventId,
54
+ error,
55
+ ...toLogFields(context),
56
+ });
57
+ return eventId;
58
+ },
59
+ captureMessage(message, level = 'info', context) {
60
+ const eventId = randomUUID();
61
+ logger[levelToLogMethod[level]]('error-tracking: message captured', {
62
+ eventId,
63
+ message,
64
+ level,
65
+ ...toLogFields(context),
66
+ });
67
+ return eventId;
68
+ },
69
+ setUser(user) {
70
+ currentUser = user;
71
+ },
72
+ async flush(_timeoutMs) {
73
+ // Captures are written synchronously to the logger — nothing is ever
74
+ // buffered, so a flush always trivially succeeds.
75
+ return true;
76
+ },
77
+ };
78
+ //# sourceMappingURL=provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAExC,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAQ9C,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;AAE1B,6EAA6E;AAC7E,MAAM,gBAAgB,GAAoE;IACxF,KAAK,EAAE,OAAO;IACd,KAAK,EAAE,OAAO;IACd,OAAO,EAAE,MAAM;IACf,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,OAAO;CACf,CAAA;AAED,2FAA2F;AAC3F,IAAI,WAAW,GAA6B,IAAI,CAAA;AAEhD;;;;;;GAMG;AACH,MAAM,WAAW,GAAG,CAAC,OAA8B,EAA2B,EAAE;IAC9E,MAAM,MAAM,GAA4B,EAAE,CAAA;IAC1C,IAAI,OAAO,EAAE,IAAI;QAAE,MAAM,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAA;IAC7C,MAAM,IAAI,GAAG,OAAO,EAAE,IAAI,IAAI,WAAW,CAAA;IACzC,IAAI,IAAI;QAAE,MAAM,CAAC,IAAI,GAAG,IAAI,CAAA;IAC5B,IAAI,OAAO,EAAE,KAAK;QAAE,MAAM,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAA;IAChD,IAAI,OAAO,EAAE,OAAO;QAAE,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAA;IACtD,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,QAAQ,GAA0B;IAC7C,gBAAgB,CAAC,KAAc,EAAE,OAA8B;QAC7D,MAAM,OAAO,GAAG,UAAU,EAAE,CAAA;QAC5B,MAAM,CAAC,KAAK,CAAC,oCAAoC,EAAE;YACjD,OAAO;YACP,KAAK;YACL,GAAG,WAAW,CAAC,OAAO,CAAC;SACxB,CAAC,CAAA;QACF,OAAO,OAAO,CAAA;IAChB,CAAC;IAED,cAAc,CACZ,OAAe,EACf,QAA4B,MAAM,EAClC,OAA8B;QAE9B,MAAM,OAAO,GAAG,UAAU,EAAE,CAAA;QAC5B,MAAM,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC,CAAC,kCAAkC,EAAE;YAClE,OAAO;YACP,OAAO;YACP,KAAK;YACL,GAAG,WAAW,CAAC,OAAO,CAAC;SACxB,CAAC,CAAA;QACF,OAAO,OAAO,CAAA;IAChB,CAAC;IAED,OAAO,CAAC,IAA8B;QACpC,WAAW,GAAG,IAAI,CAAA;IACpB,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,UAAmB;QAC7B,qEAAqE;QACrE,kDAAkD;QAClD,OAAO,IAAI,CAAA;IACb,CAAC;CACF,CAAA"}
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@molecule/api-error-tracking-console",
3
+ "version": "1.0.0",
4
+ "description": "Console (logger-based) error tracking provider for molecule.dev — zero-credential development default.",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "scripts": {
9
+ "build": "tsc",
10
+ "test": "vitest run",
11
+ "test:watch": "vitest"
12
+ },
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "import": "./dist/index.js"
17
+ }
18
+ },
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "keywords": [
23
+ "molecule",
24
+ "error-tracking",
25
+ "console",
26
+ "logger"
27
+ ],
28
+ "license": "Apache-2.0",
29
+ "devDependencies": {
30
+ "@types/node": "26.1.2",
31
+ "typescript": "6.0.3",
32
+ "vitest": "4.1.10"
33
+ },
34
+ "peerDependencies": {
35
+ "@molecule/api-bond": "^1.0.0",
36
+ "@molecule/api-error-tracking": "^1.0.0"
37
+ },
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "https://github.com/molecule-dev/molecule.git",
41
+ "directory": "packages/api/bonds/error-tracking/console"
42
+ },
43
+ "homepage": "https://github.com/molecule-dev/molecule/tree/main/packages/api/bonds/error-tracking/console",
44
+ "bugs": "https://github.com/molecule-dev/molecule/issues",
45
+ "publishConfig": {
46
+ "access": "public"
47
+ }
48
+ }