@tracewayapp/svelte 0.2.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/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # @tracewayapp/svelte
2
+
3
+ Svelte integration for Traceway. Provides context setup and a helper function to capture errors.
4
+
5
+ ## Setup
6
+
7
+ Call `setupTraceway` in your root component (e.g., `App.svelte`) to initialize Traceway and provide context to child components.
8
+
9
+ ```svelte
10
+ <script>
11
+ import { setupTraceway } from "@tracewayapp/svelte";
12
+
13
+ setupTraceway({
14
+ connectionString: "your-token@https://your-server.com/api/report",
15
+ options: { debug: true }, // optional
16
+ });
17
+ </script>
18
+
19
+ <slot />
20
+ ```
21
+
22
+ ## getTraceway Helper
23
+
24
+ Access capture methods from any child component.
25
+
26
+ ```svelte
27
+ <script>
28
+ import { getTraceway } from "@tracewayapp/svelte";
29
+
30
+ const { captureException, captureMessage } = getTraceway();
31
+
32
+ function handleClick() {
33
+ try {
34
+ doSomething();
35
+ } catch (err) {
36
+ captureException(err);
37
+ }
38
+ }
39
+ </script>
40
+
41
+ <button on:click={handleClick}>Do Something</button>
42
+ ```
43
+
44
+ ## API
45
+
46
+ ### setupTraceway(options)
47
+
48
+ Initializes Traceway and provides context to the component tree. Must be called during component initialization.
49
+
50
+ | Option | Type | Description |
51
+ |--------|------|-------------|
52
+ | `connectionString` | `string` | Traceway connection string (`token@url`) |
53
+ | `options` | `TracewayFrontendOptions` | Optional SDK configuration |
54
+
55
+ Returns `{ captureException, captureExceptionWithAttributes, captureMessage }`.
56
+
57
+ ### getTraceway()
58
+
59
+ Returns `{ captureException, captureExceptionWithAttributes, captureMessage }`.
60
+
61
+ Throws if used outside a component tree where `setupTraceway` has been called.
62
+
63
+ ## Global Error Handling
64
+
65
+ Traceway automatically installs global error handlers (`window.onerror` and `onunhandledrejection`) when initialized. These capture uncaught errors and unhandled promise rejections.
66
+
67
+ For Svelte-specific error handling, you can use Svelte's `onError` lifecycle function or wrap error-prone code in try/catch blocks using `captureException`.
68
+
69
+ ## Requirements
70
+
71
+ - Svelte >= 4.0
72
+ - `@tracewayapp/frontend` (installed automatically as dependency)
@@ -0,0 +1,19 @@
1
+ import * as traceway from '@tracewayapp/frontend';
2
+ import { TracewayFrontendOptions } from '@tracewayapp/frontend';
3
+
4
+ interface TracewayOptions {
5
+ connectionString: string;
6
+ options?: TracewayFrontendOptions;
7
+ }
8
+ interface TracewayContextValue {
9
+ captureException: typeof traceway.captureException;
10
+ captureExceptionWithAttributes: typeof traceway.captureExceptionWithAttributes;
11
+ captureMessage: typeof traceway.captureMessage;
12
+ }
13
+
14
+ declare const TRACEWAY_KEY: unique symbol;
15
+ declare function setupTraceway(options: TracewayOptions): TracewayContextValue;
16
+
17
+ declare function getTraceway(): TracewayContextValue;
18
+
19
+ export { TRACEWAY_KEY, type TracewayContextValue, type TracewayOptions, getTraceway, setupTraceway };
@@ -0,0 +1,19 @@
1
+ import * as traceway from '@tracewayapp/frontend';
2
+ import { TracewayFrontendOptions } from '@tracewayapp/frontend';
3
+
4
+ interface TracewayOptions {
5
+ connectionString: string;
6
+ options?: TracewayFrontendOptions;
7
+ }
8
+ interface TracewayContextValue {
9
+ captureException: typeof traceway.captureException;
10
+ captureExceptionWithAttributes: typeof traceway.captureExceptionWithAttributes;
11
+ captureMessage: typeof traceway.captureMessage;
12
+ }
13
+
14
+ declare const TRACEWAY_KEY: unique symbol;
15
+ declare function setupTraceway(options: TracewayOptions): TracewayContextValue;
16
+
17
+ declare function getTraceway(): TracewayContextValue;
18
+
19
+ export { TRACEWAY_KEY, type TracewayContextValue, type TracewayOptions, getTraceway, setupTraceway };
package/dist/index.js ADDED
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ TRACEWAY_KEY: () => TRACEWAY_KEY,
34
+ getTraceway: () => getTraceway,
35
+ setupTraceway: () => setupTraceway
36
+ });
37
+ module.exports = __toCommonJS(index_exports);
38
+
39
+ // src/context.ts
40
+ var import_svelte = require("svelte");
41
+ var traceway = __toESM(require("@tracewayapp/frontend"));
42
+ var TRACEWAY_KEY = /* @__PURE__ */ Symbol("traceway");
43
+ function setupTraceway(options) {
44
+ const context = {
45
+ captureException: traceway.captureException,
46
+ captureExceptionWithAttributes: traceway.captureExceptionWithAttributes,
47
+ captureMessage: traceway.captureMessage
48
+ };
49
+ (0, import_svelte.setContext)(TRACEWAY_KEY, context);
50
+ (0, import_svelte.onMount)(() => {
51
+ traceway.init(options.connectionString, options.options);
52
+ });
53
+ return context;
54
+ }
55
+
56
+ // src/use-traceway.ts
57
+ var import_svelte2 = require("svelte");
58
+ function getTraceway() {
59
+ const context = (0, import_svelte2.getContext)(TRACEWAY_KEY);
60
+ if (!context) {
61
+ throw new Error(
62
+ "getTraceway must be used within a Svelte component tree that has called setupTraceway"
63
+ );
64
+ }
65
+ return context;
66
+ }
67
+ // Annotate the CommonJS export names for ESM import in node:
68
+ 0 && (module.exports = {
69
+ TRACEWAY_KEY,
70
+ getTraceway,
71
+ setupTraceway
72
+ });
73
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/context.ts","../src/use-traceway.ts"],"sourcesContent":["export { setupTraceway, TRACEWAY_KEY } from \"./context.js\";\nexport { getTraceway } from \"./use-traceway.js\";\nexport type { TracewayOptions, TracewayContextValue } from \"./types.js\";\n","import { setContext, onMount } from \"svelte\";\nimport * as traceway from \"@tracewayapp/frontend\";\nimport type { TracewayOptions, TracewayContextValue } from \"./types.js\";\n\nexport const TRACEWAY_KEY = Symbol(\"traceway\");\n\nexport function setupTraceway(options: TracewayOptions): TracewayContextValue {\n const context: TracewayContextValue = {\n captureException: traceway.captureException,\n captureExceptionWithAttributes: traceway.captureExceptionWithAttributes,\n captureMessage: traceway.captureMessage,\n };\n\n setContext(TRACEWAY_KEY, context);\n\n onMount(() => {\n traceway.init(options.connectionString, options.options);\n });\n\n return context;\n}\n","import { getContext } from \"svelte\";\nimport { TRACEWAY_KEY } from \"./context.js\";\nimport type { TracewayContextValue } from \"./types.js\";\n\nexport function getTraceway(): TracewayContextValue {\n const context = getContext<TracewayContextValue>(TRACEWAY_KEY);\n if (!context) {\n throw new Error(\n \"getTraceway must be used within a Svelte component tree that has called setupTraceway\"\n );\n }\n return context;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAoC;AACpC,eAA0B;AAGnB,IAAM,eAAe,uBAAO,UAAU;AAEtC,SAAS,cAAc,SAAgD;AAC5E,QAAM,UAAgC;AAAA,IACpC,kBAA2B;AAAA,IAC3B,gCAAyC;AAAA,IACzC,gBAAyB;AAAA,EAC3B;AAEA,gCAAW,cAAc,OAAO;AAEhC,6BAAQ,MAAM;AACZ,IAAS,cAAK,QAAQ,kBAAkB,QAAQ,OAAO;AAAA,EACzD,CAAC;AAED,SAAO;AACT;;;ACpBA,IAAAA,iBAA2B;AAIpB,SAAS,cAAoC;AAClD,QAAM,cAAU,2BAAiC,YAAY;AAC7D,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;","names":["import_svelte"]}
package/dist/index.mjs ADDED
@@ -0,0 +1,34 @@
1
+ // src/context.ts
2
+ import { setContext, onMount } from "svelte";
3
+ import * as traceway from "@tracewayapp/frontend";
4
+ var TRACEWAY_KEY = /* @__PURE__ */ Symbol("traceway");
5
+ function setupTraceway(options) {
6
+ const context = {
7
+ captureException: traceway.captureException,
8
+ captureExceptionWithAttributes: traceway.captureExceptionWithAttributes,
9
+ captureMessage: traceway.captureMessage
10
+ };
11
+ setContext(TRACEWAY_KEY, context);
12
+ onMount(() => {
13
+ traceway.init(options.connectionString, options.options);
14
+ });
15
+ return context;
16
+ }
17
+
18
+ // src/use-traceway.ts
19
+ import { getContext } from "svelte";
20
+ function getTraceway() {
21
+ const context = getContext(TRACEWAY_KEY);
22
+ if (!context) {
23
+ throw new Error(
24
+ "getTraceway must be used within a Svelte component tree that has called setupTraceway"
25
+ );
26
+ }
27
+ return context;
28
+ }
29
+ export {
30
+ TRACEWAY_KEY,
31
+ getTraceway,
32
+ setupTraceway
33
+ };
34
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/context.ts","../src/use-traceway.ts"],"sourcesContent":["import { setContext, onMount } from \"svelte\";\nimport * as traceway from \"@tracewayapp/frontend\";\nimport type { TracewayOptions, TracewayContextValue } from \"./types.js\";\n\nexport const TRACEWAY_KEY = Symbol(\"traceway\");\n\nexport function setupTraceway(options: TracewayOptions): TracewayContextValue {\n const context: TracewayContextValue = {\n captureException: traceway.captureException,\n captureExceptionWithAttributes: traceway.captureExceptionWithAttributes,\n captureMessage: traceway.captureMessage,\n };\n\n setContext(TRACEWAY_KEY, context);\n\n onMount(() => {\n traceway.init(options.connectionString, options.options);\n });\n\n return context;\n}\n","import { getContext } from \"svelte\";\nimport { TRACEWAY_KEY } from \"./context.js\";\nimport type { TracewayContextValue } from \"./types.js\";\n\nexport function getTraceway(): TracewayContextValue {\n const context = getContext<TracewayContextValue>(TRACEWAY_KEY);\n if (!context) {\n throw new Error(\n \"getTraceway must be used within a Svelte component tree that has called setupTraceway\"\n );\n }\n return context;\n}\n"],"mappings":";AAAA,SAAS,YAAY,eAAe;AACpC,YAAY,cAAc;AAGnB,IAAM,eAAe,uBAAO,UAAU;AAEtC,SAAS,cAAc,SAAgD;AAC5E,QAAM,UAAgC;AAAA,IACpC,kBAA2B;AAAA,IAC3B,gCAAyC;AAAA,IACzC,gBAAyB;AAAA,EAC3B;AAEA,aAAW,cAAc,OAAO;AAEhC,UAAQ,MAAM;AACZ,IAAS,cAAK,QAAQ,kBAAkB,QAAQ,OAAO;AAAA,EACzD,CAAC;AAED,SAAO;AACT;;;ACpBA,SAAS,kBAAkB;AAIpB,SAAS,cAAoC;AAClD,QAAM,UAAU,WAAiC,YAAY;AAC7D,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;","names":[]}
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@tracewayapp/svelte",
3
+ "version": "0.2.0",
4
+ "description": "Traceway Svelte integration with context and helper functions",
5
+ "main": "./dist/index.cjs",
6
+ "module": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "require": "./dist/index.cjs"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
21
+ "scripts": {
22
+ "build": "tsup",
23
+ "dev": "tsup --watch"
24
+ },
25
+ "dependencies": {
26
+ "@tracewayapp/frontend": "0.2.0"
27
+ },
28
+ "peerDependencies": {
29
+ "svelte": ">=4.0.0"
30
+ }
31
+ }