@bugdump/sdk 0.0.2 → 0.0.4

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
@@ -9,7 +9,7 @@ Official TypeScript SDK for [Bugdump](https://bugdump.com) - embed a bug reporti
9
9
  - **Screenshot annotations** - Users can draw, highlight, and blur parts of screenshots
10
10
  - **TypeScript-first** - Full type definitions out of the box
11
11
  - **Shadow DOM isolated** - Widget styles never leak into your app
12
- - **Auto-init** - Single script tag with `data-project`, no JS required
12
+ - **Auto-init** - Single script tag with `data-api-key`, no JS required
13
13
 
14
14
  ## Installation
15
15
 
@@ -18,7 +18,7 @@ Official TypeScript SDK for [Bugdump](https://bugdump.com) - embed a bug reporti
18
18
  Drop a single line into your HTML — the widget initializes automatically:
19
19
 
20
20
  ```html
21
- <script src="https://bugdump.com/sdk/widget.js" data-project="your-project-key"></script>
21
+ <script src="https://bugdump.com/sdk/latest.js" data-api-key="your-api-key"></script>
22
22
  ```
23
23
 
24
24
  That's it. A floating bug report button will appear on your page.
@@ -44,7 +44,7 @@ const bugdump = Bugdump.init({
44
44
  ### Manual IIFE (without auto-init)
45
45
 
46
46
  ```html
47
- <script src="https://bugdump.com/sdk/widget.js"></script>
47
+ <script src="https://bugdump.com/sdk/latest.js"></script>
48
48
  <script>
49
49
  Bugdump.init({ projectKey: 'your-project-key' });
50
50
  </script>
@@ -55,6 +55,62 @@ const bugdump = Bugdump.init({
55
55
  | Option | Type | Required | Description |
56
56
  |---|---|---|---|
57
57
  | `projectKey` | `string` | Yes | Your Bugdump project key |
58
+ | `hideButton` | `boolean` | No | Hide the floating button and trigger the widget programmatically |
59
+
60
+ ## Headless Mode (No Floating Button)
61
+
62
+ Hide the default floating button and trigger the report form from your own UI:
63
+
64
+ ### npm
65
+
66
+ ```typescript
67
+ import { Bugdump } from '@bugdump/sdk';
68
+
69
+ const bugdump = Bugdump.init({
70
+ projectKey: 'your-project-key',
71
+ hideButton: true,
72
+ });
73
+
74
+ // Open from your own button, menu item, keyboard shortcut, etc.
75
+ document.getElementById('my-report-btn')?.addEventListener('click', () => {
76
+ bugdump.open();
77
+ });
78
+ ```
79
+
80
+ ### Script Tag
81
+
82
+ ```html
83
+ <script src="https://bugdump.com/sdk/latest.js" data-api-key="your-api-key" data-hide-button="true"></script>
84
+ <script>
85
+ document.getElementById('my-report-btn').addEventListener('click', function () {
86
+ Bugdump.getInstance().open();
87
+ });
88
+ </script>
89
+ ```
90
+
91
+ ### React example
92
+
93
+ ```tsx
94
+ import { useEffect, useCallback } from 'react';
95
+ import { Bugdump } from '@bugdump/sdk';
96
+
97
+ function App() {
98
+ useEffect(() => {
99
+ const bugdump = Bugdump.init({
100
+ projectKey: 'your-project-key',
101
+ hideButton: true,
102
+ });
103
+
104
+ return () => bugdump.destroy();
105
+ }, []);
106
+
107
+ const openReportForm = useCallback(() => {
108
+ Bugdump.getInstance()?.open();
109
+ }, []);
110
+
111
+ return <button onClick={openReportForm}>Report a Bug</button>;
112
+ }
113
+ ```
58
114
 
59
115
  ## Identify Users
60
116
 
@@ -68,6 +124,98 @@ bugdump.identify({
68
124
  });
69
125
  ```
70
126
 
127
+ ## Restrict to Authenticated Users Only
128
+
129
+ By default, anyone visiting your site can submit bug reports. If you want to allow only your registered (logged-in) users to report bugs, initialize the SDK **after** authentication and call `identify()` with the user's info.
130
+
131
+ ### npm
132
+
133
+ ```typescript
134
+ import { Bugdump } from '@bugdump/sdk';
135
+
136
+ // Initialize only after the user has logged in
137
+ function onUserLogin(user: { id: string; name: string; email: string }) {
138
+ const bugdump = Bugdump.init({
139
+ projectKey: 'your-project-key',
140
+ });
141
+
142
+ bugdump.identify({
143
+ id: user.id,
144
+ name: user.name,
145
+ email: user.email,
146
+ });
147
+ }
148
+
149
+ // Clean up on logout
150
+ function onUserLogout() {
151
+ Bugdump.getInstance()?.destroy();
152
+ }
153
+ ```
154
+
155
+ #### React example
156
+
157
+ ```tsx
158
+ import { useEffect } from 'react';
159
+ import { Bugdump } from '@bugdump/sdk';
160
+
161
+ function App() {
162
+ const user = useAuth(); // your auth hook
163
+
164
+ useEffect(() => {
165
+ if (!user) return;
166
+
167
+ const bugdump = Bugdump.init({
168
+ projectKey: 'your-project-key',
169
+ });
170
+
171
+ bugdump.identify({
172
+ id: user.id,
173
+ name: user.name,
174
+ email: user.email,
175
+ });
176
+
177
+ return () => {
178
+ bugdump.destroy();
179
+ };
180
+ }, [user]);
181
+
182
+ return <div>{/* your app */}</div>;
183
+ }
184
+ ```
185
+
186
+ ### Script Tag
187
+
188
+ When using the `<script>` tag, **do not** use the `data-api-key` attribute (which auto-initializes the widget for everyone). Instead, load the script without auto-init and initialize manually after authentication:
189
+
190
+ ```html
191
+ <!-- Load the SDK without auto-init (no data-api-key) -->
192
+ <script src="https://bugdump.com/sdk/latest.js"></script>
193
+
194
+ <script>
195
+ // Call this after your user has logged in
196
+ function initBugdump(user) {
197
+ var bugdump = Bugdump.init({ projectKey: 'your-project-key' });
198
+
199
+ bugdump.identify({
200
+ id: user.id,
201
+ name: user.name,
202
+ email: user.email,
203
+ });
204
+ }
205
+
206
+ // Call this on logout
207
+ function destroyBugdump() {
208
+ var instance = Bugdump.getInstance();
209
+ if (instance) instance.destroy();
210
+ }
211
+
212
+ // Example: init after your app confirms the user is authenticated
213
+ if (window.currentUser) {
214
+ initBugdump(window.currentUser);
215
+ }
216
+ </script>
217
+ ```
218
+
71
219
  ## Custom Context
72
220
 
73
221
  Attach arbitrary data to every report: