@upstep/react-native 0.6.11 → 0.6.13

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,4 @@
1
+
2
+ > @upstep/react-native@0.6.12 type-check /Users/sandhyasandy/Dev/upstep/packages/sdk-react-native
3
+ > tsc --noEmit
4
+
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Upstep
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # @upstep/react-native
2
+
3
+ The [Upstep](https://upstep.dev) feedback SDK for React Native: a launcher button and a bottom sheet with a voting board and submit form, backed by the same project as your web app.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @upstep/react-native react-native-safe-area-context
9
+ ```
10
+
11
+ `react-native-safe-area-context` is a required peer dependency (the sheet needs it for safe-area insets). Get an API key by creating a free project at [upstep.dev](https://upstep.dev).
12
+
13
+ ## Quick start
14
+
15
+ ```tsx
16
+ import { FeedbackProvider, FeedbackButton, FeedbackSheet } from "@upstep/react-native";
17
+
18
+ export default function App() {
19
+ return (
20
+ <FeedbackProvider apiKey="upstep_xxx">
21
+ {/* your app */}
22
+ <FeedbackButton />
23
+ <FeedbackSheet />
24
+ </FeedbackProvider>
25
+ );
26
+ }
27
+ ```
28
+
29
+ Same idea as the web widget: a floating button opens a sheet with a voting board and a submit form. It reports to the same project and the same board as your web app, so mobile and web feedback end up in one place, sorted by votes.
30
+
31
+ ## Shake to submit feedback
32
+
33
+ Optional, and only active if [`expo-sensors`](https://www.npmjs.com/package/expo-sensors) is installed:
34
+
35
+ ```bash
36
+ npm install expo-sensors
37
+ ```
38
+
39
+ ```tsx
40
+ import { useShakeToFeedback } from "@upstep/react-native";
41
+
42
+ function App() {
43
+ useShakeToFeedback(); // opens the sheet when the device is shaken
44
+ // ...
45
+ }
46
+ ```
47
+
48
+ If `expo-sensors` isn't installed, the hook is a no-op — safe to call unconditionally.
49
+
50
+ ## Configuration
51
+
52
+ `FeedbackProvider` takes the same options as the web SDK:
53
+
54
+ | Option | Type | Default | Description |
55
+ | --- | --- | --- | --- |
56
+ | `apiKey` | `string` | — | **Required.** Your project's API key. |
57
+ | `userId` | `string` | — | End-user id from your app, used to deduplicate votes per user. Call `identify(userId)` if it's only known after login. |
58
+ | `baseUrl` | `string` | `https://upstep.dev` | Only needed for self-hosted or staging setups. |
59
+ | `accentColor` | `string` | `#D97757` | Any CSS color, used for the launcher button and highlights. |
60
+ | `theme` | `"light" \| "dark" \| "auto"` | `"auto"` | `"auto"` follows the device color scheme. |
61
+
62
+ ## API
63
+
64
+ - `<FeedbackProvider apiKey="..." />` — wraps your app, all config options above are valid props.
65
+ - `<FeedbackButton position? label? icon? />` — floating launcher, `position` is `"bottom-right"` (default) or `"bottom-left"`.
66
+ - `<FeedbackSheet />` — the modal sheet with the board and submit form. Mount once, anywhere inside the provider.
67
+ - `useShakeToFeedback()` — opens the sheet on a device shake, requires `expo-sensors`.
68
+ - `useUpstep()` — the underlying state and actions (`feedItems`, `submit`, `vote`, `openSheet`, `closeSheet`, `identify`, ...), if you want to build a custom UI instead of `FeedbackSheet`.
69
+
70
+ ## Links
71
+
72
+ - [Full documentation](https://upstep.dev/#integrate)
73
+ - [Dashboard / sign up](https://upstep.dev/login)
74
+ - [@upstep/js](https://www.npmjs.com/package/@upstep/js) for web apps
package/package.json CHANGED
@@ -1,7 +1,14 @@
1
1
  {
2
2
  "name": "@upstep/react-native",
3
- "version": "0.6.11",
3
+ "version": "0.6.13",
4
4
  "description": "Upstep feedback SDK for React Native",
5
+ "homepage": "https://upstep.dev",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/TheBugEater/upstep.git",
9
+ "directory": "packages/sdk-react-native"
10
+ },
11
+ "bugs": "https://github.com/TheBugEater/upstep/issues",
5
12
  "main": "./src/index.ts",
6
13
  "types": "./src/index.ts",
7
14
  "exports": {
@@ -12,14 +19,16 @@
12
19
  }
13
20
  },
14
21
  "dependencies": {
15
- "@upstep/types": "0.5.3"
22
+ "@upstep/types": "0.5.5"
16
23
  },
17
24
  "peerDependencies": {
25
+ "@react-native-async-storage/async-storage": ">=1.18",
18
26
  "react": ">=18",
19
27
  "react-native": ">=0.73",
20
28
  "react-native-safe-area-context": ">=4"
21
29
  },
22
30
  "devDependencies": {
31
+ "@react-native-async-storage/async-storage": "^2.2.0",
23
32
  "@types/react": "^19.0.7",
24
33
  "@types/react-native": "^0.73.0",
25
34
  "react-native-safe-area-context": "^5.8.0",
package/src/api.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import AsyncStorage from "@react-native-async-storage/async-storage";
1
2
  import type {
2
3
  Feedback,
3
4
  FeedbackListResponse,
@@ -7,15 +8,42 @@ import type {
7
8
  VoteValue,
8
9
  } from "@upstep/types";
9
10
 
11
+ const ANON_ID_KEY = "upstep-anonymous-id";
12
+
13
+ function generateId(): string {
14
+ return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
15
+ }
16
+
10
17
  export class UpstepApiClient {
11
18
  private readonly baseUrl: string;
12
19
  private readonly apiKey: string;
13
20
  userId: string | undefined;
21
+ // Set synchronously to a throwaway id so there's always something to send;
22
+ // swapped for the persisted value (or backfilled into storage) once
23
+ // AsyncStorage resolves. Callers await anonymousIdReady first so requests
24
+ // always go out with the id that's actually persisted.
25
+ anonymousId: string;
26
+ private readonly anonymousIdReady: Promise<void>;
14
27
 
15
28
  constructor(config: UpstepConfig) {
16
29
  this.baseUrl = (config.baseUrl ?? "https://upstep.dev").replace(/\/$/, "");
17
30
  this.apiKey = config.apiKey;
18
31
  if (config.userId !== undefined) this.userId = config.userId;
32
+ this.anonymousId = generateId();
33
+ this.anonymousIdReady = this.loadAnonymousId();
34
+ }
35
+
36
+ private async loadAnonymousId(): Promise<void> {
37
+ try {
38
+ const stored = await AsyncStorage.getItem(ANON_ID_KEY);
39
+ if (stored) {
40
+ this.anonymousId = stored;
41
+ } else {
42
+ await AsyncStorage.setItem(ANON_ID_KEY, this.anonymousId);
43
+ }
44
+ } catch {
45
+ // storage unavailable - keep the in-memory id for this session
46
+ }
19
47
  }
20
48
 
21
49
  /** Update the end-user id at runtime (e.g. after the user logs in). */
@@ -28,20 +56,25 @@ export class UpstepApiClient {
28
56
  }
29
57
 
30
58
  async listFeedback(params?: { cursor?: string; limit?: number; sort?: "date" | "votes" }): Promise<FeedbackListResponse> {
59
+ await this.anonymousIdReady;
31
60
  const qs = new URLSearchParams();
32
61
  if (params?.cursor) qs.set("cursor", params.cursor);
33
62
  if (params?.limit) qs.set("limit", String(params.limit));
34
63
  if (params?.sort) qs.set("sort", params.sort);
35
64
  // Pass userId so the server can include the user's own pending items.
36
65
  if (this.userId) qs.set("endUserId", this.userId);
66
+ qs.set("anonymousId", this.anonymousId);
37
67
  const res = await fetch(`${this.baseUrl}/api/sdk/feedback?${qs}`, { headers: this.headers() });
38
68
  if (!res.ok) throw new Error(`Upstep: ${res.status}`);
39
69
  return res.json() as Promise<FeedbackListResponse>;
40
70
  }
41
71
 
42
72
  async getItem(feedbackId: string): Promise<FeedbackWithComments> {
43
- const qs = this.userId ? `?endUserId=${encodeURIComponent(this.userId)}` : "";
44
- const res = await fetch(`${this.baseUrl}/api/sdk/feedback/${feedbackId}${qs}`, {
73
+ await this.anonymousIdReady;
74
+ const qs = new URLSearchParams();
75
+ if (this.userId) qs.set("endUserId", this.userId);
76
+ qs.set("anonymousId", this.anonymousId);
77
+ const res = await fetch(`${this.baseUrl}/api/sdk/feedback/${feedbackId}?${qs}`, {
45
78
  headers: this.headers(),
46
79
  });
47
80
  if (!res.ok) throw new Error(`Upstep: ${res.status}`);
@@ -49,20 +82,26 @@ export class UpstepApiClient {
49
82
  }
50
83
 
51
84
  async submitFeedback(payload: SubmitFeedbackPayload): Promise<Feedback> {
85
+ await this.anonymousIdReady;
52
86
  const res = await fetch(`${this.baseUrl}/api/sdk/feedback`, {
53
87
  method: "POST",
54
88
  headers: this.headers(),
55
- body: JSON.stringify({ ...payload, endUserId: payload.endUserId ?? this.userId }),
89
+ body: JSON.stringify({
90
+ ...payload,
91
+ endUserId: payload.endUserId ?? this.userId,
92
+ anonymousId: payload.anonymousId ?? this.anonymousId,
93
+ }),
56
94
  });
57
95
  if (!res.ok) throw new Error(`Upstep: ${res.status}`);
58
96
  return res.json() as Promise<Feedback>;
59
97
  }
60
98
 
61
99
  async vote(feedbackId: string, value: VoteValue): Promise<void> {
100
+ await this.anonymousIdReady;
62
101
  const res = await fetch(`${this.baseUrl}/api/sdk/feedback/${feedbackId}/vote`, {
63
102
  method: "POST",
64
103
  headers: this.headers(),
65
- body: JSON.stringify({ value, endUserId: this.userId }),
104
+ body: JSON.stringify({ value, endUserId: this.userId, anonymousId: this.anonymousId }),
66
105
  });
67
106
  if (!res.ok) throw new Error(`Upstep: ${res.status}`);
68
107
  }