@stefan.inc/feedback-engine 0.0.0 → 1.0.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 +1 -1
- package/src/dom/webhook.ts +13 -4
- package/src/react/index.ts +1 -1
- package/src/react/public.d.ts +8 -2
- package/src/svelte/index.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stefan.inc/feedback-engine",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "In-app feedback for Svelte and React: point at a component, write what should change, and export its name, file:line, and data for an agent.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"accessibility",
|
package/src/dom/webhook.ts
CHANGED
|
@@ -9,11 +9,17 @@ export type Webhook = {
|
|
|
9
9
|
/** An icon beside the name: anything an `<img>` loads, such as `githubIcon` or a data URL. */
|
|
10
10
|
image?: string;
|
|
11
11
|
/** Sent with the post, such as `Authorization`. Whatever a page sends is public. */
|
|
12
|
-
headers?:
|
|
12
|
+
headers?: WebhookValues;
|
|
13
13
|
/** Added to the URL's query. */
|
|
14
|
-
query?:
|
|
14
|
+
query?: WebhookValues;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Fixed values, or a function that runs for every post and again on a retry, so it can read what did not exist when
|
|
19
|
+
* the app started, such as the token of a user who signed in since. What it throws is shown as the post's failure.
|
|
20
|
+
*/
|
|
21
|
+
export type WebhookValues = Record<string, string> | (() => Record<string, string> | Promise<Record<string, string>>);
|
|
22
|
+
|
|
17
23
|
export type WebhookPost = {
|
|
18
24
|
/** Made once per post and sent again on a retry, so a server can tell a retry from a second post. */
|
|
19
25
|
id: string;
|
|
@@ -47,8 +53,11 @@ export function postId() {
|
|
|
47
53
|
* choose, so only a web address is kept: the toast opens it.
|
|
48
54
|
*/
|
|
49
55
|
export async function postWebhook(webhook: Webhook, post: WebhookPost): Promise<string | undefined> {
|
|
56
|
+
const values = async (source: WebhookValues | undefined) =>
|
|
57
|
+
typeof source === 'function' ? source() : (source ?? {});
|
|
58
|
+
const [headers, query] = await Promise.all([values(webhook.headers), values(webhook.query)]);
|
|
50
59
|
const url = new URL(webhook.url, location.href);
|
|
51
|
-
for (const [name, value] of Object.entries(
|
|
60
|
+
for (const [name, value] of Object.entries(query)) url.searchParams.set(name, value);
|
|
52
61
|
const form = new FormData();
|
|
53
62
|
form.set('id', post.id);
|
|
54
63
|
form.set('title', post.title);
|
|
@@ -56,7 +65,7 @@ export async function postWebhook(webhook: Webhook, post: WebhookPost): Promise<
|
|
|
56
65
|
form.set('report', new File([post.report], 'feedback.json', { type: 'application/json' }));
|
|
57
66
|
let response: Response;
|
|
58
67
|
try {
|
|
59
|
-
response = await fetch(url, { method: 'POST', headers
|
|
68
|
+
response = await fetch(url, { method: 'POST', headers, body: form });
|
|
60
69
|
} catch (error) {
|
|
61
70
|
throw Problem.request('POST', url.href, undefined, undefined, error);
|
|
62
71
|
}
|
package/src/react/index.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { setupFeedbackEngine as setup, type FeedbackEngine } from '../editor/set
|
|
|
4
4
|
import { readComponents } from './components.ts';
|
|
5
5
|
|
|
6
6
|
export type { FeedbackRepresentable } from '../core/index.ts';
|
|
7
|
-
export { githubIcon, type Webhook } from '../dom/webhook.ts';
|
|
7
|
+
export { githubIcon, type Webhook, type WebhookValues } from '../dom/webhook.ts';
|
|
8
8
|
export type { FeedbackOptions } from '../editor/engine.ts';
|
|
9
9
|
export type { FeedbackEngine } from '../editor/setup.ts';
|
|
10
10
|
|
package/src/react/public.d.ts
CHANGED
|
@@ -46,11 +46,17 @@ export type Webhook = {
|
|
|
46
46
|
/** An icon beside the name: anything an `<img>` loads, such as `githubIcon` or a data URL. */
|
|
47
47
|
image?: string;
|
|
48
48
|
/** Sent with the post, such as `Authorization`. Whatever a page sends is public. */
|
|
49
|
-
headers?:
|
|
49
|
+
headers?: WebhookValues;
|
|
50
50
|
/** Added to the URL's query. */
|
|
51
|
-
query?:
|
|
51
|
+
query?: WebhookValues;
|
|
52
52
|
};
|
|
53
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Fixed values, or a function that runs for every post and again on a retry, so it can read what did not exist when
|
|
56
|
+
* the app started, such as the token of a user who signed in since. What it throws is shown as the post's failure.
|
|
57
|
+
*/
|
|
58
|
+
export type WebhookValues = Record<string, string> | (() => Record<string, string> | Promise<Record<string, string>>);
|
|
59
|
+
|
|
54
60
|
/** GitHub's mark in white, for a webhook that files issues. */
|
|
55
61
|
export const githubIcon: string;
|
|
56
62
|
|
package/src/svelte/index.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { Attachment } from 'svelte/attachments';
|
|
|
2
2
|
import { tags } from '../dom/tags.ts';
|
|
3
3
|
|
|
4
4
|
export type { FeedbackRepresentable } from '../core/index.ts';
|
|
5
|
-
export { githubIcon, type Webhook } from '../dom/webhook.ts';
|
|
5
|
+
export { githubIcon, type Webhook, type WebhookValues } from '../dom/webhook.ts';
|
|
6
6
|
export type { FeedbackOptions } from '../editor/engine.ts';
|
|
7
7
|
export { setupFeedbackEngine, type FeedbackEngine } from '../editor/setup.ts';
|
|
8
8
|
|