@feedvalue/core 0.1.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/README.md +155 -0
- package/dist/index.cjs +1207 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +626 -0
- package/dist/index.d.ts +626 -0
- package/dist/index.js +1200 -0
- package/dist/index.js.map +1 -0
- package/dist/umd/index.min.js +138 -0
- package/dist/umd/index.min.js.map +1 -0
- package/package.json +70 -0
package/README.md
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# @feedvalue/core
|
|
2
|
+
|
|
3
|
+
Core SDK for FeedValue feedback widget. Provides TypeScript types, initialization, and vanilla JavaScript API.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @feedvalue/core
|
|
9
|
+
# or
|
|
10
|
+
pnpm add @feedvalue/core
|
|
11
|
+
# or
|
|
12
|
+
yarn add @feedvalue/core
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
### Basic Setup
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { FeedValue } from '@feedvalue/core';
|
|
21
|
+
|
|
22
|
+
// Initialize the widget
|
|
23
|
+
const feedvalue = FeedValue.init({
|
|
24
|
+
widgetId: 'your-widget-id',
|
|
25
|
+
config: {
|
|
26
|
+
theme: 'auto', // 'light' | 'dark' | 'auto'
|
|
27
|
+
debug: false,
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// Open the feedback modal
|
|
32
|
+
feedvalue.open();
|
|
33
|
+
|
|
34
|
+
// Close the modal
|
|
35
|
+
feedvalue.close();
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### User Identification
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
// Identify the current user
|
|
42
|
+
feedvalue.identify('user-123', {
|
|
43
|
+
name: 'John Doe',
|
|
44
|
+
email: 'john@example.com',
|
|
45
|
+
plan: 'pro',
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// Set additional user data
|
|
49
|
+
feedvalue.setData({
|
|
50
|
+
company: 'Acme Inc',
|
|
51
|
+
role: 'Developer',
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Reset user data (e.g., on logout)
|
|
55
|
+
feedvalue.reset();
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Programmatic Submission
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
// Submit feedback programmatically
|
|
62
|
+
await feedvalue.submit({
|
|
63
|
+
message: 'Great product!',
|
|
64
|
+
sentiment: '😊',
|
|
65
|
+
metadata: {
|
|
66
|
+
page_url: window.location.href,
|
|
67
|
+
custom_field: 'value',
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Event Handling
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
// Listen for widget events
|
|
76
|
+
feedvalue.on('ready', () => {
|
|
77
|
+
console.log('Widget is ready');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
feedvalue.on('open', () => {
|
|
81
|
+
console.log('Modal opened');
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
feedvalue.on('close', () => {
|
|
85
|
+
console.log('Modal closed');
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
feedvalue.on('submit', (feedback) => {
|
|
89
|
+
console.log('Feedback submitted:', feedback);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
feedvalue.on('error', (error) => {
|
|
93
|
+
console.error('Widget error:', error);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// Unsubscribe from events
|
|
97
|
+
feedvalue.off('open', handleOpen);
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### State Subscription (for Framework Integration)
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
// Subscribe to state changes (React useSyncExternalStore compatible)
|
|
104
|
+
const unsubscribe = feedvalue.subscribe(() => {
|
|
105
|
+
const state = feedvalue.getSnapshot();
|
|
106
|
+
console.log('State changed:', state);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// Get current state snapshot
|
|
110
|
+
const state = feedvalue.getSnapshot();
|
|
111
|
+
// { isReady, isOpen, isVisible, error, isSubmitting }
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## API Reference
|
|
115
|
+
|
|
116
|
+
### `FeedValue.init(options)`
|
|
117
|
+
|
|
118
|
+
Initialize a FeedValue instance.
|
|
119
|
+
|
|
120
|
+
| Option | Type | Required | Description |
|
|
121
|
+
|--------|------|----------|-------------|
|
|
122
|
+
| `widgetId` | `string` | Yes | Widget ID from FeedValue dashboard |
|
|
123
|
+
| `apiBaseUrl` | `string` | No | Custom API URL (for self-hosted) |
|
|
124
|
+
| `config` | `Partial<FeedValueConfig>` | No | Configuration overrides |
|
|
125
|
+
|
|
126
|
+
### Instance Methods
|
|
127
|
+
|
|
128
|
+
| Method | Description |
|
|
129
|
+
|--------|-------------|
|
|
130
|
+
| `open()` | Open the feedback modal |
|
|
131
|
+
| `close()` | Close the feedback modal |
|
|
132
|
+
| `toggle()` | Toggle the modal open/closed |
|
|
133
|
+
| `show()` | Show the trigger button |
|
|
134
|
+
| `hide()` | Hide the trigger button |
|
|
135
|
+
| `submit(feedback)` | Submit feedback programmatically |
|
|
136
|
+
| `identify(userId, traits?)` | Identify the current user |
|
|
137
|
+
| `setData(data)` | Set additional user data |
|
|
138
|
+
| `reset()` | Reset user data |
|
|
139
|
+
| `on(event, handler)` | Subscribe to events |
|
|
140
|
+
| `off(event, handler?)` | Unsubscribe from events |
|
|
141
|
+
| `subscribe(callback)` | Subscribe to state changes |
|
|
142
|
+
| `getSnapshot()` | Get current state |
|
|
143
|
+
| `getConfig()` | Get current configuration |
|
|
144
|
+
| `destroy()` | Destroy the widget instance |
|
|
145
|
+
|
|
146
|
+
## Framework Packages
|
|
147
|
+
|
|
148
|
+
For framework-specific integrations:
|
|
149
|
+
|
|
150
|
+
- **React**: [@feedvalue/react](https://www.npmjs.com/package/@feedvalue/react)
|
|
151
|
+
- **Vue**: [@feedvalue/vue](https://www.npmjs.com/package/@feedvalue/vue)
|
|
152
|
+
|
|
153
|
+
## License
|
|
154
|
+
|
|
155
|
+
MIT
|