@upstep/react-native 0.1.0 → 0.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@upstep/react-native",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "Upstep feedback SDK for React Native",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -12,7 +12,7 @@
12
12
  }
13
13
  },
14
14
  "dependencies": {
15
- "@upstep/types": "0.0.1"
15
+ "@upstep/types": "0.2.0"
16
16
  },
17
17
  "peerDependencies": {
18
18
  "@gorhom/bottom-sheet": ">=4",
@@ -17,7 +17,10 @@ interface UpstepContextValue {
17
17
  loadFeed: () => Promise<void>;
18
18
  submit: (content: string, type?: FeedbackType) => Promise<void>;
19
19
  vote: (feedbackId: string, value: VoteValue) => Promise<void>;
20
+ /** Open the feedback sheet — call from your own UI (settings, menu, etc.). */
20
21
  openSheet: () => void;
22
+ /** Set / update the end-user id at runtime (e.g. after the user logs in). */
23
+ identify: (userId: string | undefined) => void;
21
24
  sheetRef: React.RefObject<BottomSheet | null>;
22
25
  }
23
26
 
@@ -31,6 +34,11 @@ export function FeedbackProvider({
31
34
  const [feedItems, setFeedItems] = useState<Feedback[]>([]);
32
35
  const sheetRef = useRef<BottomSheet>(null);
33
36
 
37
+ // Keep the end-user id in sync if `userId` resolves after mount (async login).
38
+ useEffect(() => {
39
+ client.setUserId(config.userId);
40
+ }, [client, config.userId]);
41
+
34
42
  const loadFeed = useCallback(async () => {
35
43
  try {
36
44
  const data = await client.listFeedback({ sort: "votes", limit: 20 });
@@ -58,8 +66,10 @@ export function FeedbackProvider({
58
66
  sheetRef.current?.expand();
59
67
  }, []);
60
68
 
69
+ const identify = useCallback((userId: string | undefined) => client.setUserId(userId), [client]);
70
+
61
71
  return (
62
- <UpstepContext.Provider value={{ client, feedItems, loadFeed, submit, vote, openSheet, sheetRef }}>
72
+ <UpstepContext.Provider value={{ client, feedItems, loadFeed, submit, vote, openSheet, identify, sheetRef }}>
63
73
  {children}
64
74
  </UpstepContext.Provider>
65
75
  );
package/src/api.ts CHANGED
@@ -9,7 +9,7 @@ import type {
9
9
  export class UpstepApiClient {
10
10
  private readonly baseUrl: string;
11
11
  private readonly apiKey: string;
12
- readonly userId?: string;
12
+ userId: string | undefined;
13
13
 
14
14
  constructor(config: UpstepConfig) {
15
15
  this.baseUrl = (config.baseUrl ?? "https://upstep.io").replace(/\/$/, "");
@@ -17,6 +17,11 @@ export class UpstepApiClient {
17
17
  if (config.userId !== undefined) this.userId = config.userId;
18
18
  }
19
19
 
20
+ /** Update the end-user id at runtime (e.g. after the user logs in). */
21
+ setUserId(userId: string | undefined) {
22
+ this.userId = userId;
23
+ }
24
+
20
25
  private headers(): Record<string, string> {
21
26
  return { "Content-Type": "application/json", "x-api-key": this.apiKey };
22
27
  }