@guidelytech/sveltekit 0.1.0 → 0.2.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/README.md CHANGED
@@ -10,15 +10,24 @@ pnpm add @guidelytech/sveltekit
10
10
  ```svelte
11
11
  <!-- src/routes/+layout.svelte -->
12
12
  <script lang="ts">
13
- import { initGuidely, guidelyEnv } from "@guidelytech/sveltekit";
14
- initGuidely({ ...guidelyEnv(import.meta.env), debug: import.meta.env.DEV });
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));
15
21
  </script>
16
22
 
17
- <slot />
23
+ {@render children()}
18
24
  ```
19
25
 
26
+ Page views are tracked automatically on every navigation; users are anonymous until identified.
27
+
20
28
  | Export | Description |
21
29
  |---|---|
22
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. |
23
- | `guidelyEnv(import.meta.env)` | Reads `VITE_GUIDELY_PROJECT_ID`, `VITE_GUIDELY_ENV`, `VITE_GUIDELY_API_URL`. |
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`). |
24
33
  | everything from `@guidelytech/svelte` | stores, actions and context helpers. |
package/dist/index.cjs CHANGED
@@ -52,9 +52,9 @@ function guidelyStoreIs(client) {
52
52
  }
53
53
  function guidelyEnv(env) {
54
54
  return {
55
- projectId: env.VITE_GUIDELY_PROJECT_ID ?? "",
56
- environment: env.VITE_GUIDELY_ENV ?? void 0,
57
- apiUrl: env.VITE_GUIDELY_API_URL || void 0
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
58
  };
59
59
  }
60
60
  // Annotate the CommonJS export names for ESM import in node:
@@ -1 +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.\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/** Reads the public `VITE_GUIDELY_*` variables into client options. */\nexport function guidelyEnv(env: Record<string, string | undefined>): Pick<GuidelyOptions, \"projectId\" | \"environment\" | \"apiUrl\"> {\n return {\n projectId: env.VITE_GUIDELY_PROJECT_ID ?? \"\",\n environment: (env.VITE_GUIDELY_ENV as GuidelyOptions[\"environment\"]) ?? undefined,\n apiUrl: env.VITE_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;AAYO,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;AAGO,SAAS,WAAW,KAAuG;AAChI,SAAO;AAAA,IACL,WAAW,IAAI,2BAA2B;AAAA,IAC1C,aAAc,IAAI,oBAAsD;AAAA,IACxE,QAAQ,IAAI,wBAAwB;AAAA,EACtC;AACF;","names":["import_svelte"]}
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 CHANGED
@@ -4,10 +4,14 @@ export * from '@guidelytech/svelte';
4
4
  /**
5
5
  * Call once from the root `+layout.svelte` (during component initialisation). Creates the client
6
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.
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`).
8
9
  */
9
10
  declare function initGuidely(options: GuidelyOptions): GuidelyClient | null;
10
- /** Reads the public `VITE_GUIDELY_*` variables into client options. */
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
+ */
11
15
  declare function guidelyEnv(env: Record<string, string | undefined>): Pick<GuidelyOptions, "projectId" | "environment" | "apiUrl">;
12
16
 
13
17
  export { guidelyEnv, initGuidely };
package/dist/index.d.ts CHANGED
@@ -4,10 +4,14 @@ export * from '@guidelytech/svelte';
4
4
  /**
5
5
  * Call once from the root `+layout.svelte` (during component initialisation). Creates the client
6
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.
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`).
8
9
  */
9
10
  declare function initGuidely(options: GuidelyOptions): GuidelyClient | null;
10
- /** Reads the public `VITE_GUIDELY_*` variables into client options. */
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
+ */
11
15
  declare function guidelyEnv(env: Record<string, string | undefined>): Pick<GuidelyOptions, "projectId" | "environment" | "apiUrl">;
12
16
 
13
17
  export { guidelyEnv, initGuidely };
package/dist/index.js CHANGED
@@ -26,9 +26,9 @@ function guidelyStoreIs(client) {
26
26
  }
27
27
  function guidelyEnv(env) {
28
28
  return {
29
- projectId: env.VITE_GUIDELY_PROJECT_ID ?? "",
30
- environment: env.VITE_GUIDELY_ENV ?? void 0,
31
- apiUrl: env.VITE_GUIDELY_API_URL || void 0
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
32
  };
33
33
  }
34
34
  export {
package/dist/index.js.map CHANGED
@@ -1 +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.\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/** Reads the public `VITE_GUIDELY_*` variables into client options. */\nexport function guidelyEnv(env: Record<string, string | undefined>): Pick<GuidelyOptions, \"projectId\" | \"environment\" | \"apiUrl\"> {\n return {\n projectId: env.VITE_GUIDELY_PROJECT_ID ?? \"\",\n environment: (env.VITE_GUIDELY_ENV as GuidelyOptions[\"environment\"]) ?? undefined,\n apiUrl: env.VITE_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;AAOP,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;AAGO,SAAS,WAAW,KAAuG;AAChI,SAAO;AAAA,IACL,WAAW,IAAI,2BAA2B;AAAA,IAC1C,aAAc,IAAI,oBAAsD;AAAA,IACxE,QAAQ,IAAI,wBAAwB;AAAA,EACtC;AACF;","names":[]}
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,6 @@
1
1
  {
2
2
  "name": "@guidelytech/sveltekit",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "SvelteKit helpers for Guidely",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -20,8 +20,8 @@
20
20
  "README.md"
21
21
  ],
22
22
  "dependencies": {
23
- "@guidelytech/sdk-core": "0.1.0",
24
- "@guidelytech/svelte": "0.1.0"
23
+ "@guidelytech/svelte": "0.2.1",
24
+ "@guidelytech/sdk-core": "0.2.1"
25
25
  },
26
26
  "devDependencies": {
27
27
  "tsup": "^8.5.1",