@farming-labs/theme 0.2.4 → 0.2.6
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/dist/docs-api.mjs +44 -15
- package/dist/docs-feedback.mjs +45 -22
- package/package.json +2 -2
package/dist/docs-api.mjs
CHANGED
|
@@ -429,6 +429,35 @@ async function parseAgentFeedbackData(request) {
|
|
|
429
429
|
}
|
|
430
430
|
};
|
|
431
431
|
}
|
|
432
|
+
function buildAgentFeedbackAnalyticsProperties(data, options = {}) {
|
|
433
|
+
const payloadKeys = Object.keys(data.payload);
|
|
434
|
+
const context = data.context;
|
|
435
|
+
return {
|
|
436
|
+
...options.requestProperties,
|
|
437
|
+
feedbackKind: "agent",
|
|
438
|
+
agentFeedbackContext: context,
|
|
439
|
+
contextPage: context?.page,
|
|
440
|
+
contextUrl: context?.url,
|
|
441
|
+
contextSlug: context?.slug,
|
|
442
|
+
contextLocale: context?.locale,
|
|
443
|
+
contextSource: context?.source,
|
|
444
|
+
payloadKeys,
|
|
445
|
+
payloadFieldCount: payloadKeys.length,
|
|
446
|
+
hasContext: Boolean(data.context),
|
|
447
|
+
hasPayload: payloadKeys.length > 0,
|
|
448
|
+
...typeof options.handled === "boolean" ? { handled: options.handled } : {},
|
|
449
|
+
...options.reason ? { reason: options.reason } : {},
|
|
450
|
+
...options.error ? { error: options.error } : {}
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
function buildAgentFeedbackAnalyticsInput(data) {
|
|
454
|
+
return {
|
|
455
|
+
feedbackContext: data.context,
|
|
456
|
+
feedbackPayload: data.payload,
|
|
457
|
+
agentFeedbackContext: data.context,
|
|
458
|
+
agentFeedbackPayload: data.payload
|
|
459
|
+
};
|
|
460
|
+
}
|
|
432
461
|
function validateAgentFeedbackPayload(value, schema, valuePath = "payload") {
|
|
433
462
|
const schemaType = typeof schema.type === "string" ? schema.type : void 0;
|
|
434
463
|
if (Array.isArray(schema.enum) && !schema.enum.some((entry) => Object.is(entry, value))) return `${valuePath} must be one of the configured enum values`;
|
|
@@ -2845,6 +2874,7 @@ function createDocsAPI(options) {
|
|
|
2845
2874
|
path: url.pathname,
|
|
2846
2875
|
properties: {
|
|
2847
2876
|
...requestAnalyticsProperties,
|
|
2877
|
+
feedbackKind: "agent",
|
|
2848
2878
|
reason: "invalid_body"
|
|
2849
2879
|
}
|
|
2850
2880
|
});
|
|
@@ -2857,11 +2887,12 @@ function createDocsAPI(options) {
|
|
|
2857
2887
|
source: "server",
|
|
2858
2888
|
url: request.url,
|
|
2859
2889
|
path: url.pathname,
|
|
2860
|
-
|
|
2861
|
-
|
|
2890
|
+
input: buildAgentFeedbackAnalyticsInput(parsed.data),
|
|
2891
|
+
properties: buildAgentFeedbackAnalyticsProperties(parsed.data, {
|
|
2892
|
+
requestProperties: requestAnalyticsProperties,
|
|
2862
2893
|
reason: "invalid_payload",
|
|
2863
2894
|
error: payloadError
|
|
2864
|
-
}
|
|
2895
|
+
})
|
|
2865
2896
|
});
|
|
2866
2897
|
return Response.json({ error: payloadError }, { status: 400 });
|
|
2867
2898
|
}
|
|
@@ -2871,12 +2902,11 @@ function createDocsAPI(options) {
|
|
|
2871
2902
|
source: "server",
|
|
2872
2903
|
url: request.url,
|
|
2873
2904
|
path: url.pathname,
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
}
|
|
2905
|
+
input: buildAgentFeedbackAnalyticsInput(parsed.data),
|
|
2906
|
+
properties: buildAgentFeedbackAnalyticsProperties(parsed.data, {
|
|
2907
|
+
requestProperties: requestAnalyticsProperties,
|
|
2908
|
+
handled: false
|
|
2909
|
+
})
|
|
2880
2910
|
});
|
|
2881
2911
|
return Response.json({
|
|
2882
2912
|
ok: true,
|
|
@@ -2889,12 +2919,11 @@ function createDocsAPI(options) {
|
|
|
2889
2919
|
source: "server",
|
|
2890
2920
|
url: request.url,
|
|
2891
2921
|
path: url.pathname,
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
}
|
|
2922
|
+
input: buildAgentFeedbackAnalyticsInput(parsed.data),
|
|
2923
|
+
properties: buildAgentFeedbackAnalyticsProperties(parsed.data, {
|
|
2924
|
+
requestProperties: requestAnalyticsProperties,
|
|
2925
|
+
handled: true
|
|
2926
|
+
})
|
|
2898
2927
|
});
|
|
2899
2928
|
return Response.json({
|
|
2900
2929
|
ok: true,
|
package/dist/docs-feedback.mjs
CHANGED
|
@@ -52,6 +52,22 @@ function buildFeedbackPayload(value, pathname, entry, comment, locale) {
|
|
|
52
52
|
locale
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
|
+
function buildFeedbackAnalyticsProperties(data) {
|
|
56
|
+
return {
|
|
57
|
+
feedbackKind: "page",
|
|
58
|
+
value: data.value,
|
|
59
|
+
feedbackValue: data.value,
|
|
60
|
+
hasComment: Boolean(data.comment),
|
|
61
|
+
commentLength: data.comment?.length ?? 0,
|
|
62
|
+
title: data.title,
|
|
63
|
+
description: data.description,
|
|
64
|
+
url: data.url,
|
|
65
|
+
pathname: data.pathname,
|
|
66
|
+
path: data.path,
|
|
67
|
+
entry: data.entry,
|
|
68
|
+
slug: data.slug
|
|
69
|
+
};
|
|
70
|
+
}
|
|
55
71
|
function ThumbUpIcon() {
|
|
56
72
|
return /* @__PURE__ */ jsx("svg", {
|
|
57
73
|
width: "14",
|
|
@@ -115,32 +131,40 @@ function DocsFeedback({ pathname, entry, locale, question = "How is this guide?"
|
|
|
115
131
|
function handleSelect(value) {
|
|
116
132
|
setSelected(value);
|
|
117
133
|
if (status !== "idle") setStatus("idle");
|
|
118
|
-
if (analytics)
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
134
|
+
if (analytics) {
|
|
135
|
+
const slug = resolveSlug(entry, normalizedPathname);
|
|
136
|
+
emitClientAnalyticsEvent({
|
|
137
|
+
type: "feedback_select",
|
|
138
|
+
locale,
|
|
139
|
+
path: normalizedPathname,
|
|
140
|
+
input: { feedbackValue: value },
|
|
141
|
+
properties: {
|
|
142
|
+
feedbackKind: "page",
|
|
143
|
+
value,
|
|
144
|
+
feedbackValue: value,
|
|
145
|
+
entry,
|
|
146
|
+
pathname: normalizedPathname,
|
|
147
|
+
path: normalizedPathname,
|
|
148
|
+
slug
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
}
|
|
127
152
|
}
|
|
128
153
|
async function handleSubmit() {
|
|
129
154
|
if (!selected || status === "submitting") return;
|
|
130
155
|
setStatus("submitting");
|
|
156
|
+
const payload = buildFeedbackPayload(selected, normalizedPathname, entry, comment, locale);
|
|
131
157
|
try {
|
|
132
|
-
const payload = buildFeedbackPayload(selected, normalizedPathname, entry, comment, locale);
|
|
133
158
|
await emitFeedback(payload, onFeedback);
|
|
134
159
|
if (analytics) emitClientAnalyticsEvent({
|
|
135
160
|
type: "feedback_submit",
|
|
136
161
|
locale,
|
|
137
162
|
path: normalizedPathname,
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
163
|
+
input: {
|
|
164
|
+
feedbackValue: payload.value,
|
|
165
|
+
feedbackComment: payload.comment
|
|
166
|
+
},
|
|
167
|
+
properties: buildFeedbackAnalyticsProperties(payload)
|
|
144
168
|
});
|
|
145
169
|
setStatus("submitted");
|
|
146
170
|
} catch {
|
|
@@ -148,12 +172,11 @@ function DocsFeedback({ pathname, entry, locale, question = "How is this guide?"
|
|
|
148
172
|
type: "feedback_error",
|
|
149
173
|
locale,
|
|
150
174
|
path: normalizedPathname,
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}
|
|
175
|
+
input: {
|
|
176
|
+
feedbackValue: payload.value,
|
|
177
|
+
feedbackComment: payload.comment
|
|
178
|
+
},
|
|
179
|
+
properties: buildFeedbackAnalyticsProperties(payload)
|
|
157
180
|
});
|
|
158
181
|
setStatus("error");
|
|
159
182
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@farming-labs/theme",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"description": "Theme package for @farming-labs/docs — layout, provider, MDX components, and styles",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"docs",
|
|
@@ -145,7 +145,7 @@
|
|
|
145
145
|
"tsdown": "^0.20.3",
|
|
146
146
|
"typescript": "^5.9.3",
|
|
147
147
|
"vitest": "^4.1.8",
|
|
148
|
-
"@farming-labs/docs": "0.2.
|
|
148
|
+
"@farming-labs/docs": "0.2.6"
|
|
149
149
|
},
|
|
150
150
|
"peerDependencies": {
|
|
151
151
|
"@farming-labs/docs": ">=0.0.1",
|