@rork-ai/toolkit-sdk 0.2.8 → 0.2.10

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.
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+
3
+ import { useGlobalSearchParams, usePathname } from "expo-router";
4
+ import PostHog, { PostHogProvider } from "posthog-react-native";
5
+ import { useEffect } from "react";
6
+ import { jsx as _jsx } from "react/jsx-runtime";
7
+ const projectId = process.env.EXPO_PUBLIC_PROJECT_ID;
8
+ const teamId = process.env.EXPO_PUBLIC_TEAM_ID;
9
+ const isAnalyticsEnabled = !!projectId && !!teamId;
10
+ let posthog = null;
11
+ function getPostHogClient() {
12
+ if (!isAnalyticsEnabled) return null;
13
+ if (!posthog) {
14
+ posthog = new PostHog("phc_vYe1AkzyZn9BWXWd8B4v79p5nPVADg8Ydf2zJ8NGnBZ", {
15
+ host: "https://toolkit.rork.com/relay-GnBZ/",
16
+ captureAppLifecycleEvents: true
17
+ });
18
+ }
19
+ return posthog;
20
+ }
21
+ export function trackEvent(name, properties) {
22
+ if (!isAnalyticsEnabled) {
23
+ return;
24
+ }
25
+ getPostHogClient()?.capture(name, {
26
+ ...properties,
27
+ $groups: {
28
+ project: projectId,
29
+ team: teamId
30
+ }
31
+ });
32
+ }
33
+ export function AnalyticsProvider({
34
+ children
35
+ }) {
36
+ const pathname = usePathname();
37
+ const params = useGlobalSearchParams();
38
+ const posthogClient = getPostHogClient();
39
+ useEffect(() => {
40
+ if (!isAnalyticsEnabled) return;
41
+ posthogClient?.screen(pathname, params);
42
+ }, [pathname, params]);
43
+ if (!posthogClient) {
44
+ return children;
45
+ }
46
+ return /*#__PURE__*/_jsx(PostHogProvider, {
47
+ client: posthogClient,
48
+ autocapture: {
49
+ captureTouches: true
50
+ },
51
+ children: children
52
+ });
53
+ }
54
+ //# sourceMappingURL=analytics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useGlobalSearchParams","usePathname","PostHog","PostHogProvider","useEffect","jsx","_jsx","projectId","process","env","EXPO_PUBLIC_PROJECT_ID","teamId","EXPO_PUBLIC_TEAM_ID","isAnalyticsEnabled","posthog","getPostHogClient","host","captureAppLifecycleEvents","trackEvent","name","properties","capture","$groups","project","team","AnalyticsProvider","children","pathname","params","posthogClient","screen","client","autocapture","captureTouches"],"sourceRoot":"../../src","sources":["analytics.tsx"],"mappings":";;AAAA,SAASA,qBAAqB,EAAEC,WAAW,QAAQ,aAAa;AAChE,OAAOC,OAAO,IAAIC,eAAe,QAAQ,sBAAsB;AAC/D,SAASC,SAAS,QAAQ,OAAO;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAElC,MAAMC,SAAS,GAAGC,OAAO,CAACC,GAAG,CAACC,sBAAsB;AACpD,MAAMC,MAAM,GAAGH,OAAO,CAACC,GAAG,CAACG,mBAAmB;AAE9C,MAAMC,kBAAkB,GAAG,CAAC,CAACN,SAAS,IAAI,CAAC,CAACI,MAAM;AAElD,IAAIG,OAAuB,GAAG,IAAI;AAClC,SAASC,gBAAgBA,CAAA,EAAG;EAC1B,IAAI,CAACF,kBAAkB,EAAE,OAAO,IAAI;EACpC,IAAI,CAACC,OAAO,EAAE;IACZA,OAAO,GAAG,IAAIZ,OAAO,CAAC,iDAAiD,EAAE;MACvEc,IAAI,EAAE,sCAAsC;MAC5CC,yBAAyB,EAAE;IAC7B,CAAC,CAAC;EACJ;EAEA,OAAOH,OAAO;AAChB;AAEA,OAAO,SAASI,UAAUA,CAACC,IAAY,EAAEC,UAA+B,EAAE;EACxE,IAAI,CAACP,kBAAkB,EAAE;IACvB;EACF;EAEAE,gBAAgB,CAAC,CAAC,EAAEM,OAAO,CAACF,IAAI,EAAE;IAChC,GAAGC,UAAU;IACbE,OAAO,EAAE;MACPC,OAAO,EAAEhB,SAAS;MAClBiB,IAAI,EAAEb;IACR;EACF,CAAC,CAAC;AACJ;AAEA,OAAO,SAASc,iBAAiBA,CAAC;EAAEC;AAAwC,CAAC,EAAE;EAC7E,MAAMC,QAAQ,GAAG1B,WAAW,CAAC,CAAC;EAC9B,MAAM2B,MAAM,GAAG5B,qBAAqB,CAAC,CAAC;EACtC,MAAM6B,aAAa,GAAGd,gBAAgB,CAAC,CAAC;EAExCX,SAAS,CAAC,MAAM;IACd,IAAI,CAACS,kBAAkB,EAAE;IAEzBgB,aAAa,EAAEC,MAAM,CAACH,QAAQ,EAAEC,MAAM,CAAC;EACzC,CAAC,EAAE,CAACD,QAAQ,EAAEC,MAAM,CAAC,CAAC;EAEtB,IAAI,CAACC,aAAa,EAAE;IAClB,OAAOH,QAAQ;EACjB;EAEA,oBACEpB,IAAA,CAACH,eAAe;IACd4B,MAAM,EAAEF,aAAc;IACtBG,WAAW,EAAE;MAAEC,cAAc,EAAE;IAAK,CAAE;IAAAP,QAAA,EAErCA;EAAQ,CACM,CAAC;AAEtB","ignoreList":[]}
package/lib/module/api.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- export const BASE_URL = `https://toolkit.rork.com`;
3
+ export const BASE_URL = process.env["EXPO_PUBLIC_TOOLKIT_URL"] ?? "http://localhost:3005";
4
4
  export function withBaseUrl(path) {
5
5
  const cleanBaseUrl = BASE_URL.replace(/\/$/, "");
6
6
  const cleanPath = path.replace(/^\//, "");
@@ -1 +1 @@
1
- {"version":3,"names":["BASE_URL","withBaseUrl","path","cleanBaseUrl","replace","cleanPath"],"sourceRoot":"../../src","sources":["api.ts"],"mappings":";;AAAA,OAAO,MAAMA,QAAQ,GAAG,0BAA0B;AAElD,OAAO,SAASC,WAAWA,CAACC,IAAY,EAAE;EACxC,MAAMC,YAAY,GAAGH,QAAQ,CAACI,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;EAChD,MAAMC,SAAS,GAAGH,IAAI,CAACE,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;EACzC,OAAO,GAAGD,YAAY,IAAIE,SAAS,EAAE;AACvC","ignoreList":[]}
1
+ {"version":3,"names":["BASE_URL","process","env","withBaseUrl","path","cleanBaseUrl","replace","cleanPath"],"sourceRoot":"../../src","sources":["api.ts"],"mappings":";;AAAA,OAAO,MAAMA,QAAQ,GACnBC,OAAO,CAACC,GAAG,CAAC,yBAAyB,CAAC,IAAI,uBAAuB;AAEnE,OAAO,SAASC,WAAWA,CAACC,IAAY,EAAE;EACxC,MAAMC,YAAY,GAAGL,QAAQ,CAACM,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;EAChD,MAAMC,SAAS,GAAGH,IAAI,CAACE,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;EACzC,OAAO,GAAGD,YAAY,IAAIE,SAAS,EAAE;AACvC","ignoreList":[]}
@@ -2,4 +2,5 @@
2
2
 
3
3
  export * from "./agent.js";
4
4
  export * from "./integrations.js";
5
+ export * from "./analytics.js";
5
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":[],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,cAAc,YAAS;AACvB,cAAc,mBAAgB","ignoreList":[]}
1
+ {"version":3,"names":[],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,cAAc,YAAS;AACvB,cAAc,mBAAgB;AAC9B,cAAc,gBAAa","ignoreList":[]}
@@ -0,0 +1,5 @@
1
+ export declare function trackEvent(name: string, properties: Record<string, any>): void;
2
+ export declare function AnalyticsProvider({ children }: {
3
+ children: React.ReactNode;
4
+ }): string | number | bigint | boolean | Iterable<import("react").ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | null | undefined> | import("react/jsx-runtime").JSX.Element | null | undefined;
5
+ //# sourceMappingURL=analytics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"analytics.d.ts","sourceRoot":"","sources":["../../../src/analytics.tsx"],"names":[],"mappings":"AAsBA,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,QAYvE;AAED,wBAAgB,iBAAiB,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAAE,2WAuB5E"}
@@ -1,3 +1,3 @@
1
- export declare const BASE_URL = "https://toolkit.rork.com";
1
+ export declare const BASE_URL: any;
2
2
  export declare function withBaseUrl(path: string): string;
3
3
  //# sourceMappingURL=api.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/api.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ,6BAA6B,CAAC;AAEnD,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,UAIvC"}
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/api.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ,KAC8C,CAAC;AAEpE,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,UAIvC"}
@@ -1,3 +1,4 @@
1
1
  export * from "./agent";
2
2
  export * from "./integrations";
3
+ export * from "./analytics";
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rork-ai/toolkit-sdk",
3
- "version": "0.2.8",
3
+ "version": "0.2.10",
4
4
  "description": "toolkit-sdk",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",
@@ -84,7 +84,8 @@
84
84
  "expo-web-browser": "*",
85
85
  "expo": "*",
86
86
  "@tanstack/react-query": "*",
87
- "zod": "^4"
87
+ "zod": "^4",
88
+ "expo-router": "*"
88
89
  },
89
90
  "workspaces": [
90
91
  "example"
@@ -139,6 +140,7 @@
139
140
  "@ai-sdk/react": "^2.0.89",
140
141
  "@stardazed/streams-text-encoding": "^1.0.2",
141
142
  "@ungap/structured-clone": "^1.3.0",
142
- "ai": "^5.0.89"
143
+ "ai": "^5.0.89",
144
+ "posthog-react-native": "^4.10.8"
143
145
  }
144
146
  }
@@ -0,0 +1,60 @@
1
+ import { useGlobalSearchParams, usePathname } from "expo-router";
2
+ import PostHog, { PostHogProvider } from "posthog-react-native";
3
+ import { useEffect } from "react";
4
+
5
+ const projectId = process.env.EXPO_PUBLIC_PROJECT_ID;
6
+ const teamId = process.env.EXPO_PUBLIC_TEAM_ID;
7
+
8
+ const isAnalyticsEnabled = !!projectId && !!teamId;
9
+
10
+ let posthog: PostHog | null = null;
11
+ function getPostHogClient() {
12
+ if (!isAnalyticsEnabled) return null;
13
+ if (!posthog) {
14
+ posthog = new PostHog("phc_vYe1AkzyZn9BWXWd8B4v79p5nPVADg8Ydf2zJ8NGnBZ", {
15
+ host: "https://toolkit.rork.com/relay-GnBZ/",
16
+ captureAppLifecycleEvents: true,
17
+ });
18
+ }
19
+
20
+ return posthog;
21
+ }
22
+
23
+ export function trackEvent(name: string, properties: Record<string, any>) {
24
+ if (!isAnalyticsEnabled) {
25
+ return;
26
+ }
27
+
28
+ getPostHogClient()?.capture(name, {
29
+ ...properties,
30
+ $groups: {
31
+ project: projectId,
32
+ team: teamId,
33
+ },
34
+ });
35
+ }
36
+
37
+ export function AnalyticsProvider({ children }: { children: React.ReactNode }) {
38
+ const pathname = usePathname();
39
+ const params = useGlobalSearchParams();
40
+ const posthogClient = getPostHogClient();
41
+
42
+ useEffect(() => {
43
+ if (!isAnalyticsEnabled) return;
44
+
45
+ posthogClient?.screen(pathname, params);
46
+ }, [pathname, params]);
47
+
48
+ if (!posthogClient) {
49
+ return children;
50
+ }
51
+
52
+ return (
53
+ <PostHogProvider
54
+ client={posthogClient}
55
+ autocapture={{ captureTouches: true }}
56
+ >
57
+ {children}
58
+ </PostHogProvider>
59
+ );
60
+ }
package/src/api.ts CHANGED
@@ -1,4 +1,5 @@
1
- export const BASE_URL = `https://toolkit.rork.com`;
1
+ export const BASE_URL =
2
+ process.env["EXPO_PUBLIC_TOOLKIT_URL"] ?? "http://localhost:3005";
2
3
 
3
4
  export function withBaseUrl(path: string) {
4
5
  const cleanBaseUrl = BASE_URL.replace(/\/$/, "");
package/src/index.tsx CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from "./agent";
2
2
  export * from "./integrations";
3
+ export * from "./analytics";