fdbck-node 0.1.0 → 0.1.1
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 +34 -23
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
#
|
|
1
|
+
# fdbck-node
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/fdbck-node)
|
|
4
|
+
|
|
5
|
+
Official Node.js SDK for [fdbck](https://fdbck.sh) — a simple API to programmatically collect and structure feedback from your users.
|
|
4
6
|
|
|
5
7
|
Full TypeScript definitions included.
|
|
6
8
|
|
|
7
9
|
```ts
|
|
8
|
-
import { Fdbck } from '
|
|
10
|
+
import { Fdbck } from 'fdbck-node';
|
|
9
11
|
|
|
10
12
|
const fdbck = new Fdbck('sk_fdbck_...');
|
|
11
13
|
|
|
@@ -37,7 +39,7 @@ console.log(results.data); // [{ respondent: 'user_8f2a', value: 5, ... }]
|
|
|
37
39
|
## Install
|
|
38
40
|
|
|
39
41
|
```sh
|
|
40
|
-
npm install
|
|
42
|
+
npm install fdbck-node
|
|
41
43
|
```
|
|
42
44
|
|
|
43
45
|
Requires Node.js 18 or later. Zero runtime dependencies.
|
|
@@ -72,7 +74,7 @@ Four question types are available:
|
|
|
72
74
|
|
|
73
75
|
| Type | Description | Required fields | Response `value` |
|
|
74
76
|
|------|-------------|-----------------|------------------|
|
|
75
|
-
| `yes_no` | Yes or no (options
|
|
77
|
+
| `yes_no` | Yes or no (options default to `["Yes", "No"]`) | — | `"Yes"` or `"No"` |
|
|
76
78
|
| `single_choice` | Pick one option | `options` | `"Option A"` |
|
|
77
79
|
| `multiple_choice` | Pick one or more | `options` | `["Option A", "Option B"]` |
|
|
78
80
|
| `rating` | Numeric scale | `ratingConfig` | `4` |
|
|
@@ -92,7 +94,7 @@ const token = await fdbck.tokens.create(question.id, {
|
|
|
92
94
|
|
|
93
95
|
Send `token.respondUrl` to your user however you like — email, in-app notification, SMS, etc. They open the link, answer on fdbck's hosted response page, and see a confirmation message. The page does not redirect — if you need to bring users back to your app, include a link in the question text or follow up after you receive the response.
|
|
94
96
|
|
|
95
|
-
You can also embed the question directly in your app using
|
|
97
|
+
You can also embed the question directly in your app using `fdbck-react` or `fdbck-flutter` — pass the `token.token` value to the UI component and it handles submission for you.
|
|
96
98
|
|
|
97
99
|
### 3. Read results
|
|
98
100
|
|
|
@@ -139,7 +141,7 @@ const isValid = fdbck.verifyWebhook(rawBody, signature, webhookSecret);
|
|
|
139
141
|
`verifyWebhook` is also available as a standalone import if you don't need a client instance:
|
|
140
142
|
|
|
141
143
|
```ts
|
|
142
|
-
import { verifyWebhook } from '
|
|
144
|
+
import { verifyWebhook } from 'fdbck-node';
|
|
143
145
|
```
|
|
144
146
|
|
|
145
147
|
## API reference
|
|
@@ -181,7 +183,7 @@ Returns a single question by ID.
|
|
|
181
183
|
Returns a paginated list of questions.
|
|
182
184
|
|
|
183
185
|
```ts
|
|
184
|
-
const page = await fdbck.questions.list({ status: '
|
|
186
|
+
const page = await fdbck.questions.list({ status: 'collecting', limit: 20 });
|
|
185
187
|
|
|
186
188
|
console.log(page.data); // Question[]
|
|
187
189
|
console.log(page.pagination.hasMore); // boolean
|
|
@@ -190,7 +192,7 @@ console.log(page.pagination.nextCursor); // string | null
|
|
|
190
192
|
// Fetch the next page
|
|
191
193
|
if (page.pagination.nextCursor) {
|
|
192
194
|
const next = await fdbck.questions.list({
|
|
193
|
-
status: '
|
|
195
|
+
status: 'collecting',
|
|
194
196
|
cursor: page.pagination.nextCursor,
|
|
195
197
|
});
|
|
196
198
|
}
|
|
@@ -198,7 +200,11 @@ if (page.pagination.nextCursor) {
|
|
|
198
200
|
|
|
199
201
|
| Option | Type | Description |
|
|
200
202
|
|--------|------|-------------|
|
|
201
|
-
| `status` | `QuestionStatus` | Filter by `
|
|
203
|
+
| `status` | `QuestionStatus` | Filter by `collecting`, `completed`, `expired`, or `cancelled` |
|
|
204
|
+
| `sort` | `string` | Sort by `created_at` or `updated_at` |
|
|
205
|
+
| `order` | `string` | Sort direction: `asc` or `desc` |
|
|
206
|
+
| `createdAfter` | `string` | ISO 8601 — only return questions created after this time |
|
|
207
|
+
| `createdBefore` | `string` | ISO 8601 — only return questions created before this time |
|
|
202
208
|
| `limit` | `number` | Items per page |
|
|
203
209
|
| `cursor` | `string` | Cursor from a previous page's `pagination.nextCursor` |
|
|
204
210
|
|
|
@@ -209,28 +215,33 @@ Auto-paginates through all questions. Same options as `list` except `cursor`.
|
|
|
209
215
|
Each page is fetched sequentially as you consume the iterator — there is no prefetching. If you have a large number of questions, be mindful of the number of API calls this produces.
|
|
210
216
|
|
|
211
217
|
```ts
|
|
212
|
-
for await (const question of fdbck.questions.listAll({ status: '
|
|
218
|
+
for await (const question of fdbck.questions.listAll({ status: 'collecting' })) {
|
|
213
219
|
console.log(question.id, question.question);
|
|
214
220
|
}
|
|
215
221
|
```
|
|
216
222
|
|
|
217
|
-
#### `fdbck.questions.results(id, options?)` → `
|
|
223
|
+
#### `fdbck.questions.results(id, options?)` → `QuestionResultsResponse`
|
|
218
224
|
|
|
219
|
-
Returns individual responses
|
|
225
|
+
Returns aggregated results and individual responses for a question.
|
|
220
226
|
|
|
221
227
|
```ts
|
|
222
|
-
const
|
|
228
|
+
const results = await fdbck.questions.results(question.id, { limit: 50 });
|
|
229
|
+
|
|
230
|
+
console.log(results.totalResponses); // 142
|
|
231
|
+
console.log(results.results); // { average: 4.3, distribution: { ... } }
|
|
232
|
+
console.log(results.type); // 'rating'
|
|
233
|
+
console.log(results.status); // 'completed'
|
|
223
234
|
|
|
224
|
-
for (const response of
|
|
235
|
+
for (const response of results.data) {
|
|
225
236
|
console.log(response.respondent); // 'user_42' or null
|
|
226
237
|
console.log(response.value); // answer value (type depends on question type)
|
|
227
238
|
console.log(response.createdAt); // ISO timestamp
|
|
228
239
|
}
|
|
229
240
|
|
|
230
241
|
// Next page
|
|
231
|
-
if (
|
|
242
|
+
if (results.pagination.hasMore) {
|
|
232
243
|
const next = await fdbck.questions.results(question.id, {
|
|
233
|
-
cursor:
|
|
244
|
+
cursor: results.pagination.nextCursor,
|
|
234
245
|
});
|
|
235
246
|
}
|
|
236
247
|
```
|
|
@@ -241,13 +252,13 @@ Each `ResponseItem` contains:
|
|
|
241
252
|
|-------|------|-------------|
|
|
242
253
|
| `id` | `string` | Response ID |
|
|
243
254
|
| `questionId` | `string` | Parent question ID |
|
|
244
|
-
| `value` | `unknown` | The answer — `
|
|
255
|
+
| `value` | `unknown` | The answer — `"Yes"`/`"No"` for yes_no, `"Option A"` for single_choice, `["A", "B"]` for multiple_choice, `4` for rating |
|
|
245
256
|
| `respondent` | `string \| null` | The respondent identifier you passed when creating the token |
|
|
246
257
|
| `createdAt` | `string` | ISO timestamp |
|
|
247
258
|
|
|
248
|
-
#### `fdbck.questions.cancel(id)` → `
|
|
259
|
+
#### `fdbck.questions.cancel(id)` → `Question`
|
|
249
260
|
|
|
250
|
-
Cancels a question. It stops accepting responses immediately.
|
|
261
|
+
Cancels a question and returns the cancelled question. It stops accepting responses immediately.
|
|
251
262
|
|
|
252
263
|
#### `fdbck.questions.webhooks(id, options?)` → `PaginatedList<WebhookDelivery>`
|
|
253
264
|
|
|
@@ -273,14 +284,14 @@ token.expiresAt; // ISO timestamp (1 hour from creation)
|
|
|
273
284
|
|
|
274
285
|
```ts
|
|
275
286
|
const info = await fdbck.me();
|
|
276
|
-
// info.
|
|
277
|
-
// info.
|
|
287
|
+
// info.user → { id, email, name, avatarUrl }
|
|
288
|
+
// info.organization → { id, name, slug, plan, role, responsesUsed, responsesLimit, ... }
|
|
278
289
|
```
|
|
279
290
|
|
|
280
291
|
## Error handling
|
|
281
292
|
|
|
282
293
|
```ts
|
|
283
|
-
import { FdbckApiError, FdbckNetworkError } from '
|
|
294
|
+
import { FdbckApiError, FdbckNetworkError } from 'fdbck-node';
|
|
284
295
|
|
|
285
296
|
try {
|
|
286
297
|
await fdbck.questions.create({ ... });
|