@watchupltd/svelte 0.1.0 → 0.1.1
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.d.mts +22 -1
- package/dist/index.d.ts +22 -1
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +11 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +16 -10
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,25 @@
|
|
|
1
1
|
export { getWatchup } from './context.mjs';
|
|
2
2
|
export { traceAction, trackClick } from './action.mjs';
|
|
3
|
-
|
|
3
|
+
import { WatchupUser } from '@watchupltd/browser';
|
|
4
|
+
export { ErrorPayload, EventPayload, TracePayload, WatchupOptions, WatchupUser } from '@watchupltd/browser';
|
|
4
5
|
import 'svelte/action';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Attach a user to all subsequent errors and traces.
|
|
9
|
+
* Call this after login, inside a Svelte component or store subscription.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* import { identify } from '@watchupltd/svelte';
|
|
13
|
+
* identify({ id: $user.id, email: $user.email, name: $user.name });
|
|
14
|
+
*/
|
|
15
|
+
declare function identify(user: WatchupUser): void;
|
|
16
|
+
/**
|
|
17
|
+
* Remove the current user context (e.g. after logout).
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* import { clearUser } from '@watchupltd/svelte';
|
|
21
|
+
* clearUser();
|
|
22
|
+
*/
|
|
23
|
+
declare function clearUser(): void;
|
|
24
|
+
|
|
25
|
+
export { clearUser, identify };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,25 @@
|
|
|
1
1
|
export { getWatchup } from './context.js';
|
|
2
2
|
export { traceAction, trackClick } from './action.js';
|
|
3
|
-
|
|
3
|
+
import { WatchupUser } from '@watchupltd/browser';
|
|
4
|
+
export { ErrorPayload, EventPayload, TracePayload, WatchupOptions, WatchupUser } from '@watchupltd/browser';
|
|
4
5
|
import 'svelte/action';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Attach a user to all subsequent errors and traces.
|
|
9
|
+
* Call this after login, inside a Svelte component or store subscription.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* import { identify } from '@watchupltd/svelte';
|
|
13
|
+
* identify({ id: $user.id, email: $user.email, name: $user.name });
|
|
14
|
+
*/
|
|
15
|
+
declare function identify(user: WatchupUser): void;
|
|
16
|
+
/**
|
|
17
|
+
* Remove the current user context (e.g. after logout).
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* import { clearUser } from '@watchupltd/svelte';
|
|
21
|
+
* clearUser();
|
|
22
|
+
*/
|
|
23
|
+
declare function clearUser(): void;
|
|
24
|
+
|
|
25
|
+
export { clearUser, identify };
|
package/dist/index.js
CHANGED
|
@@ -52,7 +52,17 @@ var traceAction = (node, params) => {
|
|
|
52
52
|
};
|
|
53
53
|
};
|
|
54
54
|
|
|
55
|
+
// src/identify.ts
|
|
56
|
+
function identify(user) {
|
|
57
|
+
getWatchup().setUser(user);
|
|
58
|
+
}
|
|
59
|
+
function clearUser() {
|
|
60
|
+
getWatchup().clearUser();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
exports.clearUser = clearUser;
|
|
55
64
|
exports.getWatchup = getWatchup;
|
|
65
|
+
exports.identify = identify;
|
|
56
66
|
exports.traceAction = traceAction;
|
|
57
67
|
exports.trackClick = trackClick;
|
|
58
68
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/context.ts","../src/action.ts"],"names":["getContext"],"mappings":";;;;;AAOA,IAAM,GAAA,0BAAa,SAAS,CAAA;AAkBrB,SAAS,UAAA,GAAsB;AACpC,EAAA,MAAM,QAAA,GAAWA,kBAAgC,GAAG,CAAA;AACpD,EAAA,IAAI,CAAC,QAAA,EAAU;AACb,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KAEF;AAAA,EACF;AACA,EAAA,OAAO,QAAA;AACT;;;ACRO,IAAM,UAAA,GAAoD,CAC/D,IAAA,EACA,MAAA,KACG;AACH,EAAA,IAAI,OAAA;AACJ,EAAA,IAAI;AACF,IAAA,OAAA,GAAU,UAAA,EAAW;AAAA,EACvB,CAAA,CAAA,MAAQ;AAEN,IAAA,OAAO,EAAC;AAAA,EACV;AAEA,EAAA,MAAM,UAAU,MAAM;AACpB,IAAA,OAAA,CAAQ,KAAA,CAAM,MAAA,CAAO,KAAA,EAAO,MAAA,CAAO,UAAU,CAAA;AAAA,EAC/C,CAAA;AAEA,EAAA,IAAA,CAAK,gBAAA,CAAiB,SAAS,OAAO,CAAA;AAEtC,EAAA,OAAO;AAAA,IACL,OAAO,SAAA,EAAW;AAChB,MAAA,MAAA,GAAS,SAAA;AAAA,IACX,CAAA;AAAA,IACA,OAAA,GAAU;AACR,MAAA,IAAA,CAAK,mBAAA,CAAoB,SAAS,OAAO,CAAA;AAAA,IAC3C;AAAA,GACF;AACF;AAsBO,IAAM,WAAA,GAGT,CAAC,IAAA,EAAM,MAAA,KAAW;AACpB,EAAA,IAAI,OAAA;AACJ,EAAA,IAAI;AACF,IAAA,OAAA,GAAU,UAAA,EAAW;AAAA,EACvB,CAAA,CAAA,MAAQ;AACN,IAAA,MAAA,CAAO,OAAO,MAAM;AAAA,IAAC,CAAC,CAAA;AACtB,IAAA,OAAO,EAAC;AAAA,EACV;AAEA,EAAA,MAAM,GAAA,GAAM,OAAA,CAAQ,UAAA,CAAW,MAAA,CAAO,IAAI,CAAA;AAC1C,EAAA,MAAA,CAAO,OAAO,MAAM,GAAA,CAAI,EAAE,MAAA,EAAQ,IAAA,EAAM,CAAC,CAAA;AAEzC,EAAA,OAAO;AAAA,IACL,OAAA,GAAU;AAAA,IAEV;AAAA,GACF;AACF","file":"index.js","sourcesContent":["// ─────────────────────────────────────────────────────────────────────────────\n// @watchupltd/svelte · context helpers\n// ─────────────────────────────────────────────────────────────────────────────\n\nimport { getContext, setContext } from 'svelte';\nimport type { Watchup } from '@watchupltd/browser';\n\nconst KEY = Symbol('watchup');\n\n/** Called internally by WatchupProvider. */\nexport function _setWatchupContext(instance: Watchup): void {\n setContext(KEY, instance);\n}\n\n/**\n * Returns the `Watchup` instance from the nearest `<WatchupProvider>`.\n * Call this at component initialisation time (not inside event handlers).\n *\n * @example\n * <script>\n * import { getWatchup } from '@watchupltd/svelte';\n * const watchup = getWatchup();\n * </script>\n * <button on:click={() => watchup.track('button.clicked')}>Click me</button>\n */\nexport function getWatchup(): Watchup {\n const instance = getContext<Watchup | undefined>(KEY);\n if (!instance) {\n throw new Error(\n '[watchup] getWatchup() must be called inside a component ' +\n 'that is a descendant of <WatchupProvider>.',\n );\n }\n return instance;\n}\n","// ─────────────────────────────────────────────────────────────────────────────\n// @watchupltd/svelte · Svelte actions\n// ─────────────────────────────────────────────────────────────────────────────\n\nimport type { Action } from 'svelte/action';\nimport type { Watchup } from '@watchupltd/browser';\nimport { getWatchup } from './context.js';\n\ninterface TrackClickParams {\n /** Event name sent to Watchup. */\n event: string;\n /** Optional properties merged into the event payload. */\n properties?: Record<string, unknown>;\n}\n\n/**\n * Svelte action that tracks a click event.\n *\n * @example\n * <script>\n * import { trackClick } from '@watchupltd/svelte';\n * </script>\n * <button use:trackClick={{ event: 'cta.clicked', properties: { variant: 'A' } }}>\n * Get started\n * </button>\n */\nexport const trackClick: Action<HTMLElement, TrackClickParams> = (\n node,\n params,\n) => {\n let watchup: Watchup;\n try {\n watchup = getWatchup();\n } catch {\n // No provider in tree — silently no-op\n return {};\n }\n\n const handler = () => {\n watchup.track(params.event, params.properties);\n };\n\n node.addEventListener('click', handler);\n\n return {\n update(newParams) {\n params = newParams;\n },\n destroy() {\n node.removeEventListener('click', handler);\n },\n };\n};\n\n/**\n * Svelte action that traces the time between `mount` and when `done()` is\n * called, emitting a trace span.\n *\n * @example\n * <script>\n * import { traceAction } from '@watchupltd/svelte';\n *\n * let done: () => void;\n *\n * async function load() {\n * const data = await fetchData();\n * done?.();\n * return data;\n * }\n * </script>\n * <div use:traceAction={{ span: 'dashboard load', onDone: (fn) => (done = fn) }}>\n * ...\n * </div>\n */\nexport const traceAction: Action<\n HTMLElement,\n { span: string; onDone: (endFn: () => void) => void }\n> = (node, params) => {\n let watchup: Watchup;\n try {\n watchup = getWatchup();\n } catch {\n params.onDone(() => {});\n return {};\n }\n\n const end = watchup.startTrace(params.span);\n params.onDone(() => end({ status: 'ok' }));\n\n return {\n destroy() {\n // If destroyed before done() was called, mark as cancelled\n },\n };\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/context.ts","../src/action.ts","../src/identify.ts"],"names":["getContext"],"mappings":";;;;;AAOA,IAAM,GAAA,0BAAa,SAAS,CAAA;AAkBrB,SAAS,UAAA,GAAsB;AACpC,EAAA,MAAM,QAAA,GAAWA,kBAAgC,GAAG,CAAA;AACpD,EAAA,IAAI,CAAC,QAAA,EAAU;AACb,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KAEF;AAAA,EACF;AACA,EAAA,OAAO,QAAA;AACT;;;ACRO,IAAM,UAAA,GAAoD,CAC/D,IAAA,EACA,MAAA,KACG;AACH,EAAA,IAAI,OAAA;AACJ,EAAA,IAAI;AACF,IAAA,OAAA,GAAU,UAAA,EAAW;AAAA,EACvB,CAAA,CAAA,MAAQ;AAEN,IAAA,OAAO,EAAC;AAAA,EACV;AAEA,EAAA,MAAM,UAAU,MAAM;AACpB,IAAA,OAAA,CAAQ,KAAA,CAAM,MAAA,CAAO,KAAA,EAAO,MAAA,CAAO,UAAU,CAAA;AAAA,EAC/C,CAAA;AAEA,EAAA,IAAA,CAAK,gBAAA,CAAiB,SAAS,OAAO,CAAA;AAEtC,EAAA,OAAO;AAAA,IACL,OAAO,SAAA,EAAW;AAChB,MAAA,MAAA,GAAS,SAAA;AAAA,IACX,CAAA;AAAA,IACA,OAAA,GAAU;AACR,MAAA,IAAA,CAAK,mBAAA,CAAoB,SAAS,OAAO,CAAA;AAAA,IAC3C;AAAA,GACF;AACF;AAsBO,IAAM,WAAA,GAGT,CAAC,IAAA,EAAM,MAAA,KAAW;AACpB,EAAA,IAAI,OAAA;AACJ,EAAA,IAAI;AACF,IAAA,OAAA,GAAU,UAAA,EAAW;AAAA,EACvB,CAAA,CAAA,MAAQ;AACN,IAAA,MAAA,CAAO,OAAO,MAAM;AAAA,IAAC,CAAC,CAAA;AACtB,IAAA,OAAO,EAAC;AAAA,EACV;AAEA,EAAA,MAAM,GAAA,GAAM,OAAA,CAAQ,UAAA,CAAW,MAAA,CAAO,IAAI,CAAA;AAC1C,EAAA,MAAA,CAAO,OAAO,MAAM,GAAA,CAAI,EAAE,MAAA,EAAQ,IAAA,EAAM,CAAC,CAAA;AAEzC,EAAA,OAAO;AAAA,IACL,OAAA,GAAU;AAAA,IAEV;AAAA,GACF;AACF;;;AC/EO,SAAS,SAAS,IAAA,EAAyB;AAChD,EAAA,UAAA,EAAW,CAAE,QAAQ,IAAI,CAAA;AAC3B;AASO,SAAS,SAAA,GAAkB;AAChC,EAAA,UAAA,GAAa,SAAA,EAAU;AACzB","file":"index.js","sourcesContent":["// ─────────────────────────────────────────────────────────────────────────────\n// @watchupltd/svelte · context helpers\n// ─────────────────────────────────────────────────────────────────────────────\n\nimport { getContext, setContext } from 'svelte';\nimport type { Watchup } from '@watchupltd/browser';\n\nconst KEY = Symbol('watchup');\n\n/** Called internally by WatchupProvider. */\nexport function _setWatchupContext(instance: Watchup): void {\n setContext(KEY, instance);\n}\n\n/**\n * Returns the `Watchup` instance from the nearest `<WatchupProvider>`.\n * Call this at component initialisation time (not inside event handlers).\n *\n * @example\n * <script>\n * import { getWatchup } from '@watchupltd/svelte';\n * const watchup = getWatchup();\n * </script>\n * <button on:click={() => watchup.track('button.clicked')}>Click me</button>\n */\nexport function getWatchup(): Watchup {\n const instance = getContext<Watchup | undefined>(KEY);\n if (!instance) {\n throw new Error(\n '[watchup] getWatchup() must be called inside a component ' +\n 'that is a descendant of <WatchupProvider>.',\n );\n }\n return instance;\n}\n","// ─────────────────────────────────────────────────────────────────────────────\n// @watchupltd/svelte · Svelte actions\n// ─────────────────────────────────────────────────────────────────────────────\n\nimport type { Action } from 'svelte/action';\nimport type { Watchup } from '@watchupltd/browser';\nimport { getWatchup } from './context.js';\n\ninterface TrackClickParams {\n /** Event name sent to Watchup. */\n event: string;\n /** Optional properties merged into the event payload. */\n properties?: Record<string, unknown>;\n}\n\n/**\n * Svelte action that tracks a click event.\n *\n * @example\n * <script>\n * import { trackClick } from '@watchupltd/svelte';\n * </script>\n * <button use:trackClick={{ event: 'cta.clicked', properties: { variant: 'A' } }}>\n * Get started\n * </button>\n */\nexport const trackClick: Action<HTMLElement, TrackClickParams> = (\n node,\n params,\n) => {\n let watchup: Watchup;\n try {\n watchup = getWatchup();\n } catch {\n // No provider in tree — silently no-op\n return {};\n }\n\n const handler = () => {\n watchup.track(params.event, params.properties);\n };\n\n node.addEventListener('click', handler);\n\n return {\n update(newParams) {\n params = newParams;\n },\n destroy() {\n node.removeEventListener('click', handler);\n },\n };\n};\n\n/**\n * Svelte action that traces the time between `mount` and when `done()` is\n * called, emitting a trace span.\n *\n * @example\n * <script>\n * import { traceAction } from '@watchupltd/svelte';\n *\n * let done: () => void;\n *\n * async function load() {\n * const data = await fetchData();\n * done?.();\n * return data;\n * }\n * </script>\n * <div use:traceAction={{ span: 'dashboard load', onDone: (fn) => (done = fn) }}>\n * ...\n * </div>\n */\nexport const traceAction: Action<\n HTMLElement,\n { span: string; onDone: (endFn: () => void) => void }\n> = (node, params) => {\n let watchup: Watchup;\n try {\n watchup = getWatchup();\n } catch {\n params.onDone(() => {});\n return {};\n }\n\n const end = watchup.startTrace(params.span);\n params.onDone(() => end({ status: 'ok' }));\n\n return {\n destroy() {\n // If destroyed before done() was called, mark as cancelled\n },\n };\n};\n","// ─────────────────────────────────────────────────────────────────────────────\n// @watchupltd/svelte · user identification helpers\n// ─────────────────────────────────────────────────────────────────────────────\n\nimport type { WatchupUser } from '@watchupltd/browser';\nimport { getWatchup } from './context.js';\n\n/**\n * Attach a user to all subsequent errors and traces.\n * Call this after login, inside a Svelte component or store subscription.\n *\n * @example\n * import { identify } from '@watchupltd/svelte';\n * identify({ id: $user.id, email: $user.email, name: $user.name });\n */\nexport function identify(user: WatchupUser): void {\n getWatchup().setUser(user);\n}\n\n/**\n * Remove the current user context (e.g. after logout).\n *\n * @example\n * import { clearUser } from '@watchupltd/svelte';\n * clearUser();\n */\nexport function clearUser(): void {\n getWatchup().clearUser();\n}\n"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
export { traceAction, trackClick } from './chunk-A275SBSC.mjs';
|
|
2
|
+
import { getWatchup } from './chunk-JOD5F3DS.mjs';
|
|
2
3
|
export { getWatchup } from './chunk-JOD5F3DS.mjs';
|
|
4
|
+
|
|
5
|
+
// src/identify.ts
|
|
6
|
+
function identify(user) {
|
|
7
|
+
getWatchup().setUser(user);
|
|
8
|
+
}
|
|
9
|
+
function clearUser() {
|
|
10
|
+
getWatchup().clearUser();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { clearUser, identify };
|
|
3
14
|
//# sourceMappingURL=index.mjs.map
|
|
4
15
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.mjs"}
|
|
1
|
+
{"version":3,"sources":["../src/identify.ts"],"names":[],"mappings":";;;;;AAeO,SAAS,SAAS,IAAA,EAAyB;AAChD,EAAA,UAAA,EAAW,CAAE,QAAQ,IAAI,CAAA;AAC3B;AASO,SAAS,SAAA,GAAkB;AAChC,EAAA,UAAA,GAAa,SAAA,EAAU;AACzB","file":"index.mjs","sourcesContent":["// ─────────────────────────────────────────────────────────────────────────────\n// @watchupltd/svelte · user identification helpers\n// ─────────────────────────────────────────────────────────────────────────────\n\nimport type { WatchupUser } from '@watchupltd/browser';\nimport { getWatchup } from './context.js';\n\n/**\n * Attach a user to all subsequent errors and traces.\n * Call this after login, inside a Svelte component or store subscription.\n *\n * @example\n * import { identify } from '@watchupltd/svelte';\n * identify({ id: $user.id, email: $user.email, name: $user.name });\n */\nexport function identify(user: WatchupUser): void {\n getWatchup().setUser(user);\n}\n\n/**\n * Remove the current user context (e.g. after logout).\n *\n * @example\n * import { clearUser } from '@watchupltd/svelte';\n * clearUser();\n */\nexport function clearUser(): void {\n getWatchup().clearUser();\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@watchupltd/svelte",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Official Watchup SDK for Svelte / SvelteKit — provider, context, and actions",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Watchup Ltd",
|
|
@@ -9,18 +9,24 @@
|
|
|
9
9
|
"types": "./dist/index.d.ts",
|
|
10
10
|
"exports": {
|
|
11
11
|
".": {
|
|
12
|
-
"types":
|
|
13
|
-
"import":
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.mjs",
|
|
14
14
|
"require": "./dist/index.js"
|
|
15
15
|
},
|
|
16
16
|
"./WatchupProvider.svelte": "./src/WatchupProvider.svelte"
|
|
17
17
|
},
|
|
18
|
-
"files": [
|
|
19
|
-
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"src/WatchupProvider.svelte",
|
|
21
|
+
"README.md"
|
|
22
|
+
],
|
|
23
|
+
"sideEffects": [
|
|
24
|
+
"./src/WatchupProvider.svelte"
|
|
25
|
+
],
|
|
20
26
|
"scripts": {
|
|
21
|
-
"build":
|
|
27
|
+
"build": "tsup",
|
|
22
28
|
"typecheck": "tsc --noEmit",
|
|
23
|
-
"dev":
|
|
29
|
+
"dev": "tsup --watch"
|
|
24
30
|
},
|
|
25
31
|
"peerDependencies": {
|
|
26
32
|
"@watchupltd/browser": "^0.1.0",
|
|
@@ -28,8 +34,8 @@
|
|
|
28
34
|
},
|
|
29
35
|
"devDependencies": {
|
|
30
36
|
"@watchupltd/browser": "*",
|
|
31
|
-
"svelte":
|
|
32
|
-
"tsup":
|
|
33
|
-
"typescript":
|
|
37
|
+
"svelte": "^4.2.18",
|
|
38
|
+
"tsup": "^8.0.2",
|
|
39
|
+
"typescript": "^5.4.5"
|
|
34
40
|
}
|
|
35
41
|
}
|