@guidelytech/sveltekit 0.0.0-stage → 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 +32 -2
- package/dist/index.cjs +66 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +17 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -0
- package/package.json +66 -3
package/README.md
CHANGED
|
@@ -1,3 +1,33 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @guidelytech/sveltekit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
SvelteKit helpers: creates the client in the browser only and calls `page()` after every
|
|
4
|
+
navigation. Re-exports everything from `@guidelytech/svelte`.
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
pnpm add @guidelytech/sveltekit
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
```svelte
|
|
11
|
+
<!-- src/routes/+layout.svelte -->
|
|
12
|
+
<script lang="ts">
|
|
13
|
+
import { env } from "$env/dynamic/public";
|
|
14
|
+
import { initGuidely, guidelyEnv, syncGuidelyUser } from "@guidelytech/sveltekit";
|
|
15
|
+
|
|
16
|
+
let { data, children } = $props();
|
|
17
|
+
initGuidely({ ...guidelyEnv(env), debug: import.meta.env.DEV });
|
|
18
|
+
|
|
19
|
+
// data.user from +layout.server.ts — identifies on sign-in/change, resets on sign-out.
|
|
20
|
+
$effect(() => syncGuidelyUser(data.user ? { id: data.user.id, traits: { role: data.user.role } } : null));
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
{@render children()}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Page views are tracked automatically on every navigation; users are anonymous until identified.
|
|
27
|
+
|
|
28
|
+
| Export | Description |
|
|
29
|
+
|---|---|
|
|
30
|
+
| `initGuidely(options)` | Call once during root layout initialisation. Returns the client in the browser, `null` on the server. Uses `afterNavigate` from `$app/navigation` to call `page()` and destroys the client when the layout is destroyed. |
|
|
31
|
+
| `guidelyEnv(env)` | Reads `PUBLIC_GUIDELY_PROJECT_ID`/`_ENV`/`_API_URL` (`$env/static/public`, `$env/dynamic/public`) or the `VITE_GUIDELY_*` equivalents (`import.meta.env`). |
|
|
32
|
+
| `syncGuidelyUser(user \| null \| undefined)` | Keeps the Guidely user in step with your session (re-exported from `@guidelytech/svelte`). |
|
|
33
|
+
| everything from `@guidelytech/svelte` | stores, actions and context helpers. |
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/index.ts
|
|
22
|
+
var index_exports = {};
|
|
23
|
+
__export(index_exports, {
|
|
24
|
+
guidelyEnv: () => guidelyEnv,
|
|
25
|
+
initGuidely: () => initGuidely
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
|
+
var import_environment = require("$app/environment");
|
|
29
|
+
var import_navigation = require("$app/navigation");
|
|
30
|
+
var import_svelte = require("@guidelytech/svelte");
|
|
31
|
+
var import_svelte2 = require("svelte");
|
|
32
|
+
__reExport(index_exports, require("@guidelytech/svelte"), module.exports);
|
|
33
|
+
function initGuidely(options) {
|
|
34
|
+
if (!import_environment.browser) {
|
|
35
|
+
(0, import_svelte.setGuidelyContext)(null);
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
const client = (0, import_svelte.createGuidely)(options);
|
|
39
|
+
(0, import_svelte.setGuidelyContext)(client);
|
|
40
|
+
(0, import_navigation.afterNavigate)((nav) => {
|
|
41
|
+
if (nav.type !== "enter") client.page(window.location.href);
|
|
42
|
+
});
|
|
43
|
+
(0, import_svelte2.onDestroy)(() => {
|
|
44
|
+
if (guidelyStoreIs(client)) (0, import_svelte.destroyGuidely)();
|
|
45
|
+
});
|
|
46
|
+
return client;
|
|
47
|
+
}
|
|
48
|
+
function guidelyStoreIs(client) {
|
|
49
|
+
let current = null;
|
|
50
|
+
import_svelte.guidely.subscribe((c) => current = c)();
|
|
51
|
+
return current === client;
|
|
52
|
+
}
|
|
53
|
+
function guidelyEnv(env) {
|
|
54
|
+
return {
|
|
55
|
+
projectId: env.VITE_GUIDELY_PROJECT_ID || env.PUBLIC_GUIDELY_PROJECT_ID || "",
|
|
56
|
+
environment: env.VITE_GUIDELY_ENV || env.PUBLIC_GUIDELY_ENV || void 0,
|
|
57
|
+
apiUrl: env.VITE_GUIDELY_API_URL || env.PUBLIC_GUIDELY_API_URL || void 0
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
61
|
+
0 && (module.exports = {
|
|
62
|
+
guidelyEnv,
|
|
63
|
+
initGuidely,
|
|
64
|
+
...require("@guidelytech/svelte")
|
|
65
|
+
});
|
|
66
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { browser } from \"$app/environment\";\nimport { afterNavigate } from \"$app/navigation\";\nimport { createGuidely, destroyGuidely, guidely, setGuidelyContext, type GuidelyClient, type GuidelyOptions } from \"@guidelytech/svelte\";\nimport { onDestroy } from \"svelte\";\n\nexport * from \"@guidelytech/svelte\";\n\n/**\n * Call once from the root `+layout.svelte` (during component initialisation). Creates the client\n * in the browser only, calls `page()` after every SvelteKit navigation and destroys the client\n * when the layout unmounts (HMR). Returns `null` on the server. Keep the signed-in user in step\n * with `syncGuidelyUser` (re-exported from `@guidelytech/svelte`).\n */\nexport function initGuidely(options: GuidelyOptions): GuidelyClient | null {\n if (!browser) {\n setGuidelyContext(null);\n return null;\n }\n const client = createGuidely(options);\n setGuidelyContext(client);\n afterNavigate((nav) => {\n if (nav.type !== \"enter\") client.page(window.location.href);\n });\n onDestroy(() => {\n if (guidelyStoreIs(client)) destroyGuidely();\n });\n return client;\n}\n\nfunction guidelyStoreIs(client: GuidelyClient): boolean {\n let current: GuidelyClient | null = null;\n guidely.subscribe((c) => (current = c))();\n return current === client;\n}\n\n/**\n * Reads the public Guidely variables into client options: `VITE_GUIDELY_*` (from `import.meta.env`)\n * or SvelteKit's `PUBLIC_GUIDELY_*` (from `$env/static/public` or `$env/dynamic/public`).\n */\nexport function guidelyEnv(env: Record<string, string | undefined>): Pick<GuidelyOptions, \"projectId\" | \"environment\" | \"apiUrl\"> {\n return {\n projectId: env.VITE_GUIDELY_PROJECT_ID || env.PUBLIC_GUIDELY_PROJECT_ID || \"\",\n environment: ((env.VITE_GUIDELY_ENV || env.PUBLIC_GUIDELY_ENV) as GuidelyOptions[\"environment\"]) || undefined,\n apiUrl: env.VITE_GUIDELY_API_URL || env.PUBLIC_GUIDELY_API_URL || undefined,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAwB;AACxB,wBAA8B;AAC9B,oBAAmH;AACnH,IAAAA,iBAA0B;AAE1B,0BAAc,gCALd;AAaO,SAAS,YAAY,SAA+C;AACzE,MAAI,CAAC,4BAAS;AACZ,yCAAkB,IAAI;AACtB,WAAO;AAAA,EACT;AACA,QAAM,aAAS,6BAAc,OAAO;AACpC,uCAAkB,MAAM;AACxB,uCAAc,CAAC,QAAQ;AACrB,QAAI,IAAI,SAAS,QAAS,QAAO,KAAK,OAAO,SAAS,IAAI;AAAA,EAC5D,CAAC;AACD,gCAAU,MAAM;AACd,QAAI,eAAe,MAAM,EAAG,mCAAe;AAAA,EAC7C,CAAC;AACD,SAAO;AACT;AAEA,SAAS,eAAe,QAAgC;AACtD,MAAI,UAAgC;AACpC,wBAAQ,UAAU,CAAC,MAAO,UAAU,CAAE,EAAE;AACxC,SAAO,YAAY;AACrB;AAMO,SAAS,WAAW,KAAuG;AAChI,SAAO;AAAA,IACL,WAAW,IAAI,2BAA2B,IAAI,6BAA6B;AAAA,IAC3E,aAAe,IAAI,oBAAoB,IAAI,sBAAyD;AAAA,IACpG,QAAQ,IAAI,wBAAwB,IAAI,0BAA0B;AAAA,EACpE;AACF;","names":["import_svelte"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { GuidelyOptions, GuidelyClient } from '@guidelytech/svelte';
|
|
2
|
+
export * from '@guidelytech/svelte';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Call once from the root `+layout.svelte` (during component initialisation). Creates the client
|
|
6
|
+
* in the browser only, calls `page()` after every SvelteKit navigation and destroys the client
|
|
7
|
+
* when the layout unmounts (HMR). Returns `null` on the server. Keep the signed-in user in step
|
|
8
|
+
* with `syncGuidelyUser` (re-exported from `@guidelytech/svelte`).
|
|
9
|
+
*/
|
|
10
|
+
declare function initGuidely(options: GuidelyOptions): GuidelyClient | null;
|
|
11
|
+
/**
|
|
12
|
+
* Reads the public Guidely variables into client options: `VITE_GUIDELY_*` (from `import.meta.env`)
|
|
13
|
+
* or SvelteKit's `PUBLIC_GUIDELY_*` (from `$env/static/public` or `$env/dynamic/public`).
|
|
14
|
+
*/
|
|
15
|
+
declare function guidelyEnv(env: Record<string, string | undefined>): Pick<GuidelyOptions, "projectId" | "environment" | "apiUrl">;
|
|
16
|
+
|
|
17
|
+
export { guidelyEnv, initGuidely };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { GuidelyOptions, GuidelyClient } from '@guidelytech/svelte';
|
|
2
|
+
export * from '@guidelytech/svelte';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Call once from the root `+layout.svelte` (during component initialisation). Creates the client
|
|
6
|
+
* in the browser only, calls `page()` after every SvelteKit navigation and destroys the client
|
|
7
|
+
* when the layout unmounts (HMR). Returns `null` on the server. Keep the signed-in user in step
|
|
8
|
+
* with `syncGuidelyUser` (re-exported from `@guidelytech/svelte`).
|
|
9
|
+
*/
|
|
10
|
+
declare function initGuidely(options: GuidelyOptions): GuidelyClient | null;
|
|
11
|
+
/**
|
|
12
|
+
* Reads the public Guidely variables into client options: `VITE_GUIDELY_*` (from `import.meta.env`)
|
|
13
|
+
* or SvelteKit's `PUBLIC_GUIDELY_*` (from `$env/static/public` or `$env/dynamic/public`).
|
|
14
|
+
*/
|
|
15
|
+
declare function guidelyEnv(env: Record<string, string | undefined>): Pick<GuidelyOptions, "projectId" | "environment" | "apiUrl">;
|
|
16
|
+
|
|
17
|
+
export { guidelyEnv, initGuidely };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { browser } from "$app/environment";
|
|
3
|
+
import { afterNavigate } from "$app/navigation";
|
|
4
|
+
import { createGuidely, destroyGuidely, guidely, setGuidelyContext } from "@guidelytech/svelte";
|
|
5
|
+
import { onDestroy } from "svelte";
|
|
6
|
+
export * from "@guidelytech/svelte";
|
|
7
|
+
function initGuidely(options) {
|
|
8
|
+
if (!browser) {
|
|
9
|
+
setGuidelyContext(null);
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
const client = createGuidely(options);
|
|
13
|
+
setGuidelyContext(client);
|
|
14
|
+
afterNavigate((nav) => {
|
|
15
|
+
if (nav.type !== "enter") client.page(window.location.href);
|
|
16
|
+
});
|
|
17
|
+
onDestroy(() => {
|
|
18
|
+
if (guidelyStoreIs(client)) destroyGuidely();
|
|
19
|
+
});
|
|
20
|
+
return client;
|
|
21
|
+
}
|
|
22
|
+
function guidelyStoreIs(client) {
|
|
23
|
+
let current = null;
|
|
24
|
+
guidely.subscribe((c) => current = c)();
|
|
25
|
+
return current === client;
|
|
26
|
+
}
|
|
27
|
+
function guidelyEnv(env) {
|
|
28
|
+
return {
|
|
29
|
+
projectId: env.VITE_GUIDELY_PROJECT_ID || env.PUBLIC_GUIDELY_PROJECT_ID || "",
|
|
30
|
+
environment: env.VITE_GUIDELY_ENV || env.PUBLIC_GUIDELY_ENV || void 0,
|
|
31
|
+
apiUrl: env.VITE_GUIDELY_API_URL || env.PUBLIC_GUIDELY_API_URL || void 0
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export {
|
|
35
|
+
guidelyEnv,
|
|
36
|
+
initGuidely
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { browser } from \"$app/environment\";\nimport { afterNavigate } from \"$app/navigation\";\nimport { createGuidely, destroyGuidely, guidely, setGuidelyContext, type GuidelyClient, type GuidelyOptions } from \"@guidelytech/svelte\";\nimport { onDestroy } from \"svelte\";\n\nexport * from \"@guidelytech/svelte\";\n\n/**\n * Call once from the root `+layout.svelte` (during component initialisation). Creates the client\n * in the browser only, calls `page()` after every SvelteKit navigation and destroys the client\n * when the layout unmounts (HMR). Returns `null` on the server. Keep the signed-in user in step\n * with `syncGuidelyUser` (re-exported from `@guidelytech/svelte`).\n */\nexport function initGuidely(options: GuidelyOptions): GuidelyClient | null {\n if (!browser) {\n setGuidelyContext(null);\n return null;\n }\n const client = createGuidely(options);\n setGuidelyContext(client);\n afterNavigate((nav) => {\n if (nav.type !== \"enter\") client.page(window.location.href);\n });\n onDestroy(() => {\n if (guidelyStoreIs(client)) destroyGuidely();\n });\n return client;\n}\n\nfunction guidelyStoreIs(client: GuidelyClient): boolean {\n let current: GuidelyClient | null = null;\n guidely.subscribe((c) => (current = c))();\n return current === client;\n}\n\n/**\n * Reads the public Guidely variables into client options: `VITE_GUIDELY_*` (from `import.meta.env`)\n * or SvelteKit's `PUBLIC_GUIDELY_*` (from `$env/static/public` or `$env/dynamic/public`).\n */\nexport function guidelyEnv(env: Record<string, string | undefined>): Pick<GuidelyOptions, \"projectId\" | \"environment\" | \"apiUrl\"> {\n return {\n projectId: env.VITE_GUIDELY_PROJECT_ID || env.PUBLIC_GUIDELY_PROJECT_ID || \"\",\n environment: ((env.VITE_GUIDELY_ENV || env.PUBLIC_GUIDELY_ENV) as GuidelyOptions[\"environment\"]) || undefined,\n apiUrl: env.VITE_GUIDELY_API_URL || env.PUBLIC_GUIDELY_API_URL || undefined,\n };\n}\n"],"mappings":";AAAA,SAAS,eAAe;AACxB,SAAS,qBAAqB;AAC9B,SAAS,eAAe,gBAAgB,SAAS,yBAAkE;AACnH,SAAS,iBAAiB;AAE1B,cAAc;AAQP,SAAS,YAAY,SAA+C;AACzE,MAAI,CAAC,SAAS;AACZ,sBAAkB,IAAI;AACtB,WAAO;AAAA,EACT;AACA,QAAM,SAAS,cAAc,OAAO;AACpC,oBAAkB,MAAM;AACxB,gBAAc,CAAC,QAAQ;AACrB,QAAI,IAAI,SAAS,QAAS,QAAO,KAAK,OAAO,SAAS,IAAI;AAAA,EAC5D,CAAC;AACD,YAAU,MAAM;AACd,QAAI,eAAe,MAAM,EAAG,gBAAe;AAAA,EAC7C,CAAC;AACD,SAAO;AACT;AAEA,SAAS,eAAe,QAAgC;AACtD,MAAI,UAAgC;AACpC,UAAQ,UAAU,CAAC,MAAO,UAAU,CAAE,EAAE;AACxC,SAAO,YAAY;AACrB;AAMO,SAAS,WAAW,KAAuG;AAChI,SAAO;AAAA,IACL,WAAW,IAAI,2BAA2B,IAAI,6BAA6B;AAAA,IAC3E,aAAe,IAAI,oBAAoB,IAAI,sBAAyD;AAAA,IACpG,QAAQ,IAAI,wBAAwB,IAAI,0BAA0B;AAAA,EACpE;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,69 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guidelytech/sveltekit",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "SvelteKit helpers for Guidely",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"main": "./dist/index.cjs",
|
|
9
|
+
"module": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"require": "./dist/index.cjs"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"README.md"
|
|
21
|
+
],
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@guidelytech/svelte": "0.2.0",
|
|
24
|
+
"@guidelytech/sdk-core": "0.2.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"tsup": "^8.5.1",
|
|
28
|
+
"typescript": "^5.9.3",
|
|
29
|
+
"vitest": "^3.2.7",
|
|
30
|
+
"happy-dom": "^17.6.3",
|
|
31
|
+
"eslint": "^9.39.5",
|
|
32
|
+
"@eslint/js": "^9.39.5",
|
|
33
|
+
"typescript-eslint": "^8.46.0",
|
|
34
|
+
"svelte": "^5.57.2",
|
|
35
|
+
"@sveltejs/kit": "^2.70.3"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"svelte": ">=4.0.0",
|
|
39
|
+
"@sveltejs/kit": ">=2.0.0"
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
},
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "git+https://github.com/parmarg/Guidely.git",
|
|
47
|
+
"directory": "packages/sveltekit"
|
|
48
|
+
},
|
|
49
|
+
"homepage": "https://github.com/parmarg/Guidely/tree/main/packages/sveltekit#readme",
|
|
50
|
+
"bugs": {
|
|
51
|
+
"url": "https://github.com/parmarg/Guidely/issues"
|
|
52
|
+
},
|
|
53
|
+
"keywords": [
|
|
54
|
+
"guidely",
|
|
55
|
+
"product-adoption",
|
|
56
|
+
"onboarding",
|
|
57
|
+
"product-tour",
|
|
58
|
+
"in-app-guidance",
|
|
59
|
+
"sveltekit"
|
|
60
|
+
],
|
|
61
|
+
"scripts": {
|
|
62
|
+
"build": "tsup",
|
|
63
|
+
"dev": "tsup --watch",
|
|
64
|
+
"typecheck": "tsc --noEmit",
|
|
65
|
+
"test": "vitest run",
|
|
66
|
+
"lint": "eslint src",
|
|
67
|
+
"clean": "rm -rf dist"
|
|
68
|
+
}
|
|
6
69
|
}
|