@the-seeker/feedback-react-native 0.1.0 → 0.2.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.
Files changed (50) hide show
  1. package/README.md +67 -16
  2. package/dist/core/author-token.d.ts +16 -0
  3. package/dist/core/author-token.js +96 -0
  4. package/dist/core/client.d.ts +3 -5
  5. package/dist/core/client.js +7 -22
  6. package/dist/core/posts-schema.d.ts +306 -0
  7. package/dist/core/posts-schema.js +131 -0
  8. package/dist/core/posts.d.ts +67 -0
  9. package/dist/core/posts.js +113 -0
  10. package/dist/core/request.d.ts +1 -1
  11. package/dist/core/request.js +2 -0
  12. package/dist/core/texts.d.ts +92 -0
  13. package/dist/core/texts.js +92 -0
  14. package/dist/core/transport.d.ts +9 -0
  15. package/dist/core/transport.js +37 -0
  16. package/dist/index.d.ts +2 -0
  17. package/dist/index.js +2 -0
  18. package/dist/ui/FeedbackForm.js +3 -1
  19. package/dist/ui/FeedbackPostScreen.d.ts +8 -0
  20. package/dist/ui/FeedbackPostScreen.js +74 -0
  21. package/dist/ui/FeedbackSheet.js +4 -22
  22. package/dist/ui/FollowUpSheet.d.ts +17 -0
  23. package/dist/ui/FollowUpSheet.js +50 -0
  24. package/dist/ui/Launcher.js +5 -3
  25. package/dist/ui/MyFeedbackModal.d.ts +10 -0
  26. package/dist/ui/MyFeedbackModal.js +45 -0
  27. package/dist/ui/MyFeedbackScreen.d.ts +9 -0
  28. package/dist/ui/MyFeedbackScreen.js +88 -0
  29. package/dist/ui/PostThread.d.ts +17 -0
  30. package/dist/ui/PostThread.js +57 -0
  31. package/dist/ui/Provider.d.ts +3 -0
  32. package/dist/ui/Provider.js +65 -10
  33. package/dist/ui/context.d.ts +44 -1
  34. package/dist/ui/motion.d.ts +1 -0
  35. package/dist/ui/motion.js +23 -0
  36. package/dist/ui/post-format.d.ts +19 -0
  37. package/dist/ui/post-format.js +79 -0
  38. package/dist/ui/post-pieces.d.ts +24 -0
  39. package/dist/ui/post-pieces.js +60 -0
  40. package/dist/ui/post-styles.d.ts +317 -0
  41. package/dist/ui/post-styles.js +103 -0
  42. package/dist/ui/post-view-model.d.ts +52 -0
  43. package/dist/ui/post-view-model.js +181 -0
  44. package/dist/ui/styles.d.ts +77 -0
  45. package/dist/ui/styles.js +51 -43
  46. package/dist/ui/surfaces.d.ts +13 -0
  47. package/dist/ui/surfaces.js +41 -0
  48. package/dist/ui/useMyPosts.d.ts +35 -0
  49. package/dist/ui/useMyPosts.js +124 -0
  50. package/package.json +8 -9
@@ -0,0 +1,306 @@
1
+ import { z } from "zod";
2
+ export declare const FEEDBACK_STATUSES: readonly ["new", "in_progress", "resolved", "closed"];
3
+ export declare const BOARD_STATUSES: readonly ["review", "planned", "in_progress", "done"];
4
+ declare const ENTRY_KINDS: readonly ["answer", "followup", "comment", "status", "roadmap_link", "release_link", "merge", "auto_reply", "visibility"];
5
+ export type FeedbackStatus = (typeof FEEDBACK_STATUSES)[number];
6
+ export type BoardStatus = (typeof BOARD_STATUSES)[number];
7
+ export type EntryKind = (typeof ENTRY_KINDS)[number] | "other";
8
+ export type PostVisibility = "private" | "public";
9
+ export declare const siteSchema: z.ZodObject<{
10
+ name: z.ZodCatch<z.ZodString>;
11
+ iconUrl: z.ZodCatch<z.ZodNullable<z.ZodString>>;
12
+ accentColor: z.ZodCatch<z.ZodNullable<z.ZodString>>;
13
+ mode: z.ZodCatch<z.ZodEnum<{
14
+ one_way: "one_way";
15
+ two_way: "two_way";
16
+ }>>;
17
+ eligibility: z.ZodCatch<z.ZodEnum<{
18
+ email: "email";
19
+ anyone: "anyone";
20
+ app_user: "app_user";
21
+ }>>;
22
+ anonymity: z.ZodCatch<z.ZodEnum<{
23
+ off: "off";
24
+ others: "others";
25
+ full: "full";
26
+ }>>;
27
+ boards: z.ZodCatch<z.ZodPipe<z.ZodArray<z.ZodCatch<z.ZodNullable<z.ZodObject<{
28
+ key: z.ZodString;
29
+ name: z.ZodString;
30
+ }, z.core.$strip>>>>, z.ZodTransform<{
31
+ key: string;
32
+ name: string;
33
+ }[], ({
34
+ key: string;
35
+ name: string;
36
+ } | null)[]>>>;
37
+ statusLabels: z.ZodCatch<z.ZodObject<{
38
+ review: z.ZodCatch<z.ZodNullable<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodObject<{
39
+ label: z.ZodString;
40
+ }, z.core.$strip>, z.ZodTransform<string, {
41
+ label: string;
42
+ }>>]>, z.ZodString>>>;
43
+ planned: z.ZodCatch<z.ZodNullable<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodObject<{
44
+ label: z.ZodString;
45
+ }, z.core.$strip>, z.ZodTransform<string, {
46
+ label: string;
47
+ }>>]>, z.ZodString>>>;
48
+ in_progress: z.ZodCatch<z.ZodNullable<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodObject<{
49
+ label: z.ZodString;
50
+ }, z.core.$strip>, z.ZodTransform<string, {
51
+ label: string;
52
+ }>>]>, z.ZodString>>>;
53
+ done: z.ZodCatch<z.ZodNullable<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodObject<{
54
+ label: z.ZodString;
55
+ }, z.core.$strip>, z.ZodTransform<string, {
56
+ label: string;
57
+ }>>]>, z.ZodString>>>;
58
+ }, z.core.$strip>>;
59
+ autoReplyText: z.ZodCatch<z.ZodNullable<z.ZodString>>;
60
+ myPostsEnabled: z.ZodCatch<z.ZodBoolean>;
61
+ }, z.core.$strip>;
62
+ export declare const summarySchema: z.ZodObject<{
63
+ number: z.ZodNumber;
64
+ title: z.ZodCatch<z.ZodNullable<z.ZodString>>;
65
+ excerpt: z.ZodCatch<z.ZodNullable<z.ZodString>>;
66
+ status: z.ZodCatch<z.ZodEnum<{
67
+ new: "new";
68
+ in_progress: "in_progress";
69
+ resolved: "resolved";
70
+ closed: "closed";
71
+ }>>;
72
+ boardStatus: z.ZodCatch<z.ZodNullable<z.ZodEnum<{
73
+ in_progress: "in_progress";
74
+ review: "review";
75
+ planned: "planned";
76
+ done: "done";
77
+ }>>>;
78
+ visibility: z.ZodPipe<z.ZodUnknown, z.ZodTransform<"private" | "public", unknown>>;
79
+ answered: z.ZodCatch<z.ZodBoolean>;
80
+ awaitingReply: z.ZodCatch<z.ZodBoolean>;
81
+ unread: z.ZodCatch<z.ZodBoolean>;
82
+ createdAt: z.ZodPipe<z.ZodString, z.ZodTransform<Date, string>>;
83
+ lastActivityAt: z.ZodCatch<z.ZodNullable<z.ZodPipe<z.ZodString, z.ZodTransform<Date, string>>>>;
84
+ }, z.core.$strip>;
85
+ export declare const entrySchema: z.ZodObject<{
86
+ id: z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodNumber, z.ZodTransform<string, number>>]>;
87
+ kind: z.ZodPipe<z.ZodString, z.ZodTransform<"status" | "answer" | "followup" | "comment" | "roadmap_link" | "release_link" | "merge" | "auto_reply" | "visibility" | "other", string>>;
88
+ body: z.ZodCatch<z.ZodString>;
89
+ createdAt: z.ZodPipe<z.ZodString, z.ZodTransform<Date, string>>;
90
+ author: z.ZodEnum<{
91
+ other: "other";
92
+ team: "team";
93
+ me: "me";
94
+ }>;
95
+ meta: z.ZodCatch<z.ZodObject<{
96
+ status: z.ZodCatch<z.ZodNullable<z.ZodEnum<{
97
+ new: "new";
98
+ in_progress: "in_progress";
99
+ resolved: "resolved";
100
+ closed: "closed";
101
+ }>>>;
102
+ boardStatus: z.ZodCatch<z.ZodNullable<z.ZodEnum<{
103
+ in_progress: "in_progress";
104
+ review: "review";
105
+ planned: "planned";
106
+ done: "done";
107
+ }>>>;
108
+ title: z.ZodCatch<z.ZodNullable<z.ZodString>>;
109
+ }, z.core.$strip>>;
110
+ }, z.core.$strip>;
111
+ export declare const detailSchema: z.ZodObject<{
112
+ content: z.ZodCatch<z.ZodString>;
113
+ board: z.ZodCatch<z.ZodNullable<z.ZodString>>;
114
+ anonymous: z.ZodCatch<z.ZodBoolean>;
115
+ images: z.ZodCatch<z.ZodPipe<z.ZodArray<z.ZodCatch<z.ZodNullable<z.ZodObject<{
116
+ id: z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodNumber, z.ZodTransform<string, number>>]>;
117
+ width: z.ZodCatch<z.ZodNullable<z.ZodNumber>>;
118
+ height: z.ZodCatch<z.ZodNullable<z.ZodNumber>>;
119
+ }, z.core.$strip>>>>, z.ZodTransform<{
120
+ id: string;
121
+ width: number | null;
122
+ height: number | null;
123
+ }[], ({
124
+ id: string;
125
+ width: number | null;
126
+ height: number | null;
127
+ } | null)[]>>>;
128
+ mode: z.ZodCatch<z.ZodEnum<{
129
+ one_way: "one_way";
130
+ two_way: "two_way";
131
+ }>>;
132
+ entries: z.ZodCatch<z.ZodPipe<z.ZodArray<z.ZodCatch<z.ZodNullable<z.ZodObject<{
133
+ id: z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodNumber, z.ZodTransform<string, number>>]>;
134
+ kind: z.ZodPipe<z.ZodString, z.ZodTransform<"status" | "answer" | "followup" | "comment" | "roadmap_link" | "release_link" | "merge" | "auto_reply" | "visibility" | "other", string>>;
135
+ body: z.ZodCatch<z.ZodString>;
136
+ createdAt: z.ZodPipe<z.ZodString, z.ZodTransform<Date, string>>;
137
+ author: z.ZodEnum<{
138
+ other: "other";
139
+ team: "team";
140
+ me: "me";
141
+ }>;
142
+ meta: z.ZodCatch<z.ZodObject<{
143
+ status: z.ZodCatch<z.ZodNullable<z.ZodEnum<{
144
+ new: "new";
145
+ in_progress: "in_progress";
146
+ resolved: "resolved";
147
+ closed: "closed";
148
+ }>>>;
149
+ boardStatus: z.ZodCatch<z.ZodNullable<z.ZodEnum<{
150
+ in_progress: "in_progress";
151
+ review: "review";
152
+ planned: "planned";
153
+ done: "done";
154
+ }>>>;
155
+ title: z.ZodCatch<z.ZodNullable<z.ZodString>>;
156
+ }, z.core.$strip>>;
157
+ }, z.core.$strip>>>>, z.ZodTransform<{
158
+ id: string;
159
+ kind: "status" | "answer" | "followup" | "comment" | "roadmap_link" | "release_link" | "merge" | "auto_reply" | "visibility" | "other";
160
+ body: string;
161
+ createdAt: Date;
162
+ author: "other" | "team" | "me";
163
+ meta: {
164
+ status: "new" | "in_progress" | "resolved" | "closed" | null;
165
+ boardStatus: "in_progress" | "review" | "planned" | "done" | null;
166
+ title: string | null;
167
+ };
168
+ }[], ({
169
+ id: string;
170
+ kind: "status" | "answer" | "followup" | "comment" | "roadmap_link" | "release_link" | "merge" | "auto_reply" | "visibility" | "other";
171
+ body: string;
172
+ createdAt: Date;
173
+ author: "other" | "team" | "me";
174
+ meta: {
175
+ status: "new" | "in_progress" | "resolved" | "closed" | null;
176
+ boardStatus: "in_progress" | "review" | "planned" | "done" | null;
177
+ title: string | null;
178
+ };
179
+ } | null)[]>>>;
180
+ roadmap: z.ZodCatch<z.ZodNullable<z.ZodObject<{
181
+ title: z.ZodCatch<z.ZodNullable<z.ZodString>>;
182
+ stage: z.ZodCatch<z.ZodNullable<z.ZodString>>;
183
+ }, z.core.$strip>>>;
184
+ release: z.ZodCatch<z.ZodNullable<z.ZodObject<{
185
+ title: z.ZodCatch<z.ZodNullable<z.ZodString>>;
186
+ version: z.ZodCatch<z.ZodNullable<z.ZodString>>;
187
+ }, z.core.$strip>>>;
188
+ canFollowUp: z.ZodCatch<z.ZodBoolean>;
189
+ number: z.ZodNumber;
190
+ title: z.ZodCatch<z.ZodNullable<z.ZodString>>;
191
+ excerpt: z.ZodCatch<z.ZodNullable<z.ZodString>>;
192
+ status: z.ZodCatch<z.ZodEnum<{
193
+ new: "new";
194
+ in_progress: "in_progress";
195
+ resolved: "resolved";
196
+ closed: "closed";
197
+ }>>;
198
+ boardStatus: z.ZodCatch<z.ZodNullable<z.ZodEnum<{
199
+ in_progress: "in_progress";
200
+ review: "review";
201
+ planned: "planned";
202
+ done: "done";
203
+ }>>>;
204
+ visibility: z.ZodPipe<z.ZodUnknown, z.ZodTransform<"private" | "public", unknown>>;
205
+ answered: z.ZodCatch<z.ZodBoolean>;
206
+ awaitingReply: z.ZodCatch<z.ZodBoolean>;
207
+ unread: z.ZodCatch<z.ZodBoolean>;
208
+ createdAt: z.ZodPipe<z.ZodString, z.ZodTransform<Date, string>>;
209
+ lastActivityAt: z.ZodCatch<z.ZodNullable<z.ZodPipe<z.ZodString, z.ZodTransform<Date, string>>>>;
210
+ }, z.core.$strip>;
211
+ export declare const createdSchema: z.ZodObject<{
212
+ id: z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodNumber, z.ZodTransform<string, number>>]>;
213
+ number: z.ZodNumber;
214
+ title: z.ZodCatch<z.ZodNullable<z.ZodString>>;
215
+ status: z.ZodCatch<z.ZodEnum<{
216
+ new: "new";
217
+ in_progress: "in_progress";
218
+ resolved: "resolved";
219
+ closed: "closed";
220
+ }>>;
221
+ boardStatus: z.ZodCatch<z.ZodNullable<z.ZodEnum<{
222
+ in_progress: "in_progress";
223
+ review: "review";
224
+ planned: "planned";
225
+ done: "done";
226
+ }>>>;
227
+ visibility: z.ZodPipe<z.ZodUnknown, z.ZodTransform<"private" | "public", unknown>>;
228
+ createdAt: z.ZodPipe<z.ZodString, z.ZodTransform<Date, string>>;
229
+ receipt: z.ZodCatch<z.ZodObject<{
230
+ autoReplyText: z.ZodCatch<z.ZodNullable<z.ZodString>>;
231
+ }, z.core.$strip>>;
232
+ }, z.core.$strip>;
233
+ export declare const listSchema: z.ZodObject<{
234
+ posts: z.ZodCatch<z.ZodPipe<z.ZodArray<z.ZodCatch<z.ZodNullable<z.ZodObject<{
235
+ number: z.ZodNumber;
236
+ title: z.ZodCatch<z.ZodNullable<z.ZodString>>;
237
+ excerpt: z.ZodCatch<z.ZodNullable<z.ZodString>>;
238
+ status: z.ZodCatch<z.ZodEnum<{
239
+ new: "new";
240
+ in_progress: "in_progress";
241
+ resolved: "resolved";
242
+ closed: "closed";
243
+ }>>;
244
+ boardStatus: z.ZodCatch<z.ZodNullable<z.ZodEnum<{
245
+ in_progress: "in_progress";
246
+ review: "review";
247
+ planned: "planned";
248
+ done: "done";
249
+ }>>>;
250
+ visibility: z.ZodPipe<z.ZodUnknown, z.ZodTransform<"private" | "public", unknown>>;
251
+ answered: z.ZodCatch<z.ZodBoolean>;
252
+ awaitingReply: z.ZodCatch<z.ZodBoolean>;
253
+ unread: z.ZodCatch<z.ZodBoolean>;
254
+ createdAt: z.ZodPipe<z.ZodString, z.ZodTransform<Date, string>>;
255
+ lastActivityAt: z.ZodCatch<z.ZodNullable<z.ZodPipe<z.ZodString, z.ZodTransform<Date, string>>>>;
256
+ }, z.core.$strip>>>>, z.ZodTransform<{
257
+ number: number;
258
+ title: string | null;
259
+ excerpt: string | null;
260
+ status: "new" | "in_progress" | "resolved" | "closed";
261
+ boardStatus: "in_progress" | "review" | "planned" | "done" | null;
262
+ visibility: "private" | "public";
263
+ answered: boolean;
264
+ awaitingReply: boolean;
265
+ unread: boolean;
266
+ createdAt: Date;
267
+ lastActivityAt: Date | null;
268
+ }[], ({
269
+ number: number;
270
+ title: string | null;
271
+ excerpt: string | null;
272
+ status: "new" | "in_progress" | "resolved" | "closed";
273
+ boardStatus: "in_progress" | "review" | "planned" | "done" | null;
274
+ visibility: "private" | "public";
275
+ answered: boolean;
276
+ awaitingReply: boolean;
277
+ unread: boolean;
278
+ createdAt: Date;
279
+ lastActivityAt: Date | null;
280
+ } | null)[]>>>;
281
+ nextCursor: z.ZodCatch<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodNumber, z.ZodTransform<string, number>>]>>>;
282
+ }, z.core.$strip>;
283
+ export declare const unreadSchema: z.ZodObject<{
284
+ count: z.ZodNumber;
285
+ posts: z.ZodCatch<z.ZodPipe<z.ZodArray<z.ZodCatch<z.ZodNullable<z.ZodObject<{
286
+ number: z.ZodNumber;
287
+ title: z.ZodCatch<z.ZodNullable<z.ZodString>>;
288
+ lastAnswerAt: z.ZodCatch<z.ZodNullable<z.ZodPipe<z.ZodString, z.ZodTransform<Date, string>>>>;
289
+ }, z.core.$strip>>>>, z.ZodTransform<{
290
+ number: number;
291
+ title: string | null;
292
+ lastAnswerAt: Date | null;
293
+ }[], ({
294
+ number: number;
295
+ title: string | null;
296
+ lastAnswerAt: Date | null;
297
+ } | null)[]>>>;
298
+ }, z.core.$strip>;
299
+ export declare const errorSchema: z.ZodObject<{
300
+ error: z.ZodUnion<readonly [z.ZodPipe<z.ZodObject<{
301
+ code: z.ZodString;
302
+ }, z.core.$strip>, z.ZodTransform<string, {
303
+ code: string;
304
+ }>>, z.ZodString]>;
305
+ }, z.core.$strip>;
306
+ export {};
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.errorSchema = exports.unreadSchema = exports.listSchema = exports.createdSchema = exports.detailSchema = exports.entrySchema = exports.summarySchema = exports.siteSchema = exports.BOARD_STATUSES = exports.FEEDBACK_STATUSES = void 0;
4
+ const zod_1 = require("zod");
5
+ // Response schemas for /api/feedback/app/*. Objects strip unknown keys; fields the contract leaves
6
+ // open (meta, roadmap, release) are optional so a richer server never breaks an older app.
7
+ exports.FEEDBACK_STATUSES = ["new", "in_progress", "resolved", "closed"];
8
+ exports.BOARD_STATUSES = ["review", "planned", "in_progress", "done"];
9
+ const ENTRY_KINDS = [
10
+ "answer",
11
+ "followup",
12
+ "comment",
13
+ "status",
14
+ "roadmap_link",
15
+ "release_link",
16
+ "merge",
17
+ "auto_reply",
18
+ "visibility",
19
+ ];
20
+ function compact(items) {
21
+ return items.filter((item) => item !== null);
22
+ }
23
+ /** Keeps the well-formed items of an array and drops the rest instead of failing the response. */
24
+ function lenientList(item) {
25
+ return zod_1.z
26
+ .array(item.nullable().catch(null))
27
+ .transform((items) => compact(items))
28
+ .catch([]);
29
+ }
30
+ const text = zod_1.z.string().trim().min(1);
31
+ const nullableText = text.nullable().catch(null);
32
+ const id = zod_1.z.union([text, zod_1.z.number().transform(String)]);
33
+ const date = zod_1.z.string().transform((value, ctx) => {
34
+ const ms = Date.parse(value);
35
+ if (Number.isFinite(ms))
36
+ return new Date(ms);
37
+ ctx.addIssue({ code: "custom", message: "Invalid date" });
38
+ return zod_1.z.NEVER;
39
+ });
40
+ const nullableDate = date.nullable().catch(null);
41
+ const flag = zod_1.z.boolean().catch(false);
42
+ const status = zod_1.z.enum(exports.FEEDBACK_STATUSES).catch("new");
43
+ const boardStatus = zod_1.z.enum(exports.BOARD_STATUSES).nullable().catch(null);
44
+ const visibility = zod_1.z
45
+ .unknown()
46
+ .transform((value) => (value === "public" || value === "public_board" ? "public" : "private"));
47
+ const mode = zod_1.z.enum(["one_way", "two_way"]).catch("one_way");
48
+ const label = zod_1.z
49
+ .union([zod_1.z.string(), zod_1.z.object({ label: zod_1.z.string() }).transform((value) => value.label)])
50
+ .pipe(zod_1.z.string().trim().min(1).max(40))
51
+ .nullable()
52
+ .catch(null);
53
+ const NO_LABELS = { review: null, planned: null, in_progress: null, done: null };
54
+ exports.siteSchema = zod_1.z.object({
55
+ name: zod_1.z.string().catch(""),
56
+ iconUrl: nullableText,
57
+ accentColor: nullableText,
58
+ mode,
59
+ eligibility: zod_1.z.enum(["anyone", "email", "app_user"]).catch("email"),
60
+ anonymity: zod_1.z.enum(["off", "others", "full"]).catch("others"),
61
+ boards: lenientList(zod_1.z.object({ key: text, name: text })),
62
+ statusLabels: zod_1.z.object({ review: label, planned: label, in_progress: label, done: label }).catch(NO_LABELS),
63
+ autoReplyText: nullableText,
64
+ myPostsEnabled: flag,
65
+ });
66
+ const summaryShape = {
67
+ number: zod_1.z.number().int().positive(),
68
+ title: nullableText,
69
+ excerpt: nullableText,
70
+ status,
71
+ boardStatus,
72
+ visibility,
73
+ answered: flag,
74
+ awaitingReply: flag,
75
+ unread: flag,
76
+ createdAt: date,
77
+ lastActivityAt: nullableDate,
78
+ };
79
+ exports.summarySchema = zod_1.z.object(summaryShape);
80
+ const NO_META = { status: null, boardStatus: null, title: null };
81
+ exports.entrySchema = zod_1.z.object({
82
+ id,
83
+ kind: zod_1.z.string().transform((value) => ENTRY_KINDS.find((kind) => kind === value) ?? "other"),
84
+ body: zod_1.z.string().catch(""),
85
+ createdAt: date,
86
+ author: zod_1.z.enum(["team", "me", "other"]),
87
+ meta: zod_1.z
88
+ .object({
89
+ status: zod_1.z.enum(exports.FEEDBACK_STATUSES).nullable().catch(null),
90
+ boardStatus,
91
+ title: nullableText,
92
+ })
93
+ .catch(NO_META),
94
+ });
95
+ exports.detailSchema = zod_1.z.object({
96
+ ...summaryShape,
97
+ content: zod_1.z.string().catch(""),
98
+ board: nullableText,
99
+ anonymous: flag,
100
+ images: lenientList(zod_1.z.object({
101
+ id,
102
+ width: zod_1.z.number().positive().nullable().catch(null),
103
+ height: zod_1.z.number().positive().nullable().catch(null),
104
+ })),
105
+ mode,
106
+ entries: lenientList(exports.entrySchema),
107
+ roadmap: zod_1.z.object({ title: nullableText, stage: nullableText }).nullable().catch(null),
108
+ release: zod_1.z.object({ title: nullableText, version: nullableText }).nullable().catch(null),
109
+ canFollowUp: flag,
110
+ });
111
+ exports.createdSchema = zod_1.z.object({
112
+ id,
113
+ number: zod_1.z.number().int().positive(),
114
+ title: nullableText,
115
+ status,
116
+ boardStatus,
117
+ visibility,
118
+ createdAt: date,
119
+ receipt: zod_1.z.object({ autoReplyText: nullableText }).catch({ autoReplyText: null }),
120
+ });
121
+ exports.listSchema = zod_1.z.object({
122
+ posts: lenientList(exports.summarySchema),
123
+ nextCursor: id.nullable().catch(null),
124
+ });
125
+ exports.unreadSchema = zod_1.z.object({
126
+ count: zod_1.z.number().int().nonnegative(),
127
+ posts: lenientList(zod_1.z.object({ number: zod_1.z.number().int().positive(), title: nullableText, lastAnswerAt: nullableDate })),
128
+ });
129
+ exports.errorSchema = zod_1.z.object({
130
+ error: zod_1.z.union([zod_1.z.object({ code: zod_1.z.string() }).transform((value) => value.code), zod_1.z.string()]),
131
+ });
@@ -0,0 +1,67 @@
1
+ import { z } from "zod";
2
+ import type { FetchImpl, FormDataLike, XhrLike } from "./client";
3
+ import { createdSchema, detailSchema, entrySchema, listSchema, siteSchema, summarySchema, unreadSchema } from "./posts-schema";
4
+ import type { PostVisibility } from "./posts-schema";
5
+ import type { ClientMetadata, ImageAsset } from "./request";
6
+ export type { BoardStatus, EntryKind, FeedbackStatus, PostVisibility } from "./posts-schema";
7
+ export type AppSite = z.output<typeof siteSchema>;
8
+ export type PostSummary = z.output<typeof summarySchema>;
9
+ export type PostDetail = z.output<typeof detailSchema>;
10
+ export type PostEntry = z.output<typeof entrySchema>;
11
+ export type CreatedPost = z.output<typeof createdSchema>;
12
+ export type PostPage = z.output<typeof listSchema>;
13
+ export type UnreadSummary = z.output<typeof unreadSchema>;
14
+ declare const ERROR_CODES: readonly ["SITE_NOT_FOUND", "VALIDATION_ERROR", "ELIGIBILITY", "ONE_WAY", "CLOSED", "NOT_FOUND", "RATE_LIMITED", "APP_NOT_ALLOWED", "IMAGES_DISABLED", "TOO_MANY_IMAGES", "IMAGE_TOO_LARGE", "INVALID_IMAGE"];
15
+ /** Server codes, plus `REQUEST_FAILED` (other statuses), `INVALID_RESPONSE` and `NETWORK_ERROR`. */
16
+ export type PostsErrorCode = (typeof ERROR_CODES)[number] | "REQUEST_FAILED" | "INVALID_RESPONSE" | "NETWORK_ERROR";
17
+ export type PostsResult<T> = Readonly<{
18
+ ok: true;
19
+ value: T;
20
+ }> | Readonly<{
21
+ ok: false;
22
+ code: PostsErrorCode;
23
+ }>;
24
+ export type CreatePostInput = Readonly<{
25
+ content: string;
26
+ board?: string;
27
+ title?: string;
28
+ visibility?: PostVisibility;
29
+ anonymous?: boolean;
30
+ uid?: string;
31
+ authorName?: string;
32
+ /** `email` for widgets that ask for an email, `text` for a free-text contact (e.g. a Telegram handle). */
33
+ contact?: Readonly<{
34
+ email?: string;
35
+ text?: string;
36
+ }>;
37
+ client?: ClientMetadata;
38
+ screen?: string;
39
+ }>;
40
+ export type ImageSource = Readonly<{
41
+ uri: string;
42
+ headers: Readonly<Record<string, string>>;
43
+ }>;
44
+ export type PostsClientOptions = Readonly<{
45
+ baseUrl?: string;
46
+ /** The `fbw_` widget key. */
47
+ publicKey: string;
48
+ appId: string;
49
+ /** Per-install bearer secret from `getOrCreateAuthorToken`, sent as `X-Devstage-Author`. */
50
+ authorToken: string;
51
+ fetch?: FetchImpl;
52
+ FormDataImpl?: new () => FormDataLike;
53
+ XMLHttpRequestImpl?: (new () => XhrLike) | undefined;
54
+ }>;
55
+ export interface PostsClient {
56
+ getSite(): Promise<PostsResult<AppSite>>;
57
+ createPost(input: CreatePostInput, images?: readonly ImageAsset[]): Promise<PostsResult<CreatedPost>>;
58
+ listMyPosts(cursor?: string): Promise<PostsResult<PostPage>>;
59
+ getPost(number: number): Promise<PostsResult<PostDetail>>;
60
+ addFollowUp(number: number, body: string): Promise<PostsResult<PostEntry>>;
61
+ getUnread(): Promise<PostsResult<UnreadSummary>>;
62
+ /** `Image` source for an attachment of my post; the image route needs the author header too. */
63
+ imageSource(number: number, imageId: string): ImageSource;
64
+ }
65
+ export declare const AUTHOR_HEADER = "X-Devstage-Author";
66
+ export declare const MAX_FOLLOW_UP = 2000;
67
+ export declare function createPostsClient(options: PostsClientOptions): PostsClient;
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MAX_FOLLOW_UP = exports.AUTHOR_HEADER = void 0;
4
+ exports.createPostsClient = createPostsClient;
5
+ const zod_1 = require("zod");
6
+ const client_1 = require("./client");
7
+ const posts_schema_1 = require("./posts-schema");
8
+ const request_1 = require("./request");
9
+ const transport_1 = require("./transport");
10
+ const ERROR_CODES = [
11
+ "SITE_NOT_FOUND",
12
+ "VALIDATION_ERROR",
13
+ "ELIGIBILITY",
14
+ "ONE_WAY",
15
+ "CLOSED",
16
+ "NOT_FOUND",
17
+ "RATE_LIMITED",
18
+ "APP_NOT_ALLOWED",
19
+ "IMAGES_DISABLED",
20
+ "TOO_MANY_IMAGES",
21
+ "IMAGE_TOO_LARGE",
22
+ "INVALID_IMAGE",
23
+ ];
24
+ exports.AUTHOR_HEADER = "X-Devstage-Author";
25
+ exports.MAX_FOLLOW_UP = 2000;
26
+ const fail = (code) => ({ ok: false, code });
27
+ function errorCode(body, status, notFound) {
28
+ const parsed = posts_schema_1.errorSchema.safeParse(body);
29
+ const known = parsed.success ? ERROR_CODES.find((code) => code === parsed.data.error) : undefined;
30
+ if (known !== undefined)
31
+ return known;
32
+ if (status === 400)
33
+ return "VALIDATION_ERROR";
34
+ if (status === 404)
35
+ return notFound;
36
+ if (status === 429)
37
+ return "RATE_LIMITED";
38
+ return "REQUEST_FAILED";
39
+ }
40
+ async function call(send, expected, schema, notFound = "NOT_FOUND") {
41
+ let response;
42
+ try {
43
+ response = await send();
44
+ }
45
+ catch (error) {
46
+ if (error instanceof Error)
47
+ return fail("NETWORK_ERROR");
48
+ throw error;
49
+ }
50
+ const body = await (0, transport_1.readJson)(response);
51
+ if (response.status !== expected)
52
+ return fail(errorCode(body, response.status, notFound));
53
+ const parsed = schema.safeParse(body);
54
+ return parsed.success ? { ok: true, value: parsed.data } : fail("INVALID_RESPONSE");
55
+ }
56
+ const siteResponse = zod_1.z.object({ site: posts_schema_1.siteSchema }).transform((body) => body.site);
57
+ const createdResponse = zod_1.z.object({ post: posts_schema_1.createdSchema }).transform((body) => body.post);
58
+ const detailResponse = zod_1.z.object({ post: posts_schema_1.detailSchema }).transform((body) => body.post);
59
+ const entryResponse = zod_1.z.object({ entry: posts_schema_1.entrySchema }).transform((body) => body.entry);
60
+ function createPostsClient(options) {
61
+ const { publicKey, appId, authorToken, baseUrl = client_1.DEFAULT_BASE_URL, fetch: fetchImpl = fetch, FormDataImpl = FormData, XMLHttpRequestImpl = globalThis.XMLHttpRequest, } = options;
62
+ const root = `${baseUrl.replace(/\/+$/, "")}/api/feedback/app`;
63
+ const owner = { ...(0, request_1.appHeaders)(appId), [exports.AUTHOR_HEADER]: authorToken };
64
+ const json = { ...owner, "Content-Type": "application/json" };
65
+ const url = (path, cursor) => `${root}${path}?key=${encodeURIComponent(publicKey)}${cursor === undefined ? "" : `&cursor=${encodeURIComponent(cursor)}`}`;
66
+ const get = (path, headers = owner, cursor) => () => fetchImpl(url(path, cursor), { method: "GET", headers });
67
+ const postNumber = (number) => Number.isSafeInteger(number) && number > 0;
68
+ function sendPost(input, images) {
69
+ const target = url("/posts");
70
+ const payload = JSON.stringify(input);
71
+ if (images.length === 0)
72
+ return fetchImpl(target, { method: "POST", headers: json, body: payload });
73
+ const form = new FormDataImpl();
74
+ form.append("payload", payload);
75
+ for (const image of images)
76
+ form.append("images", { uri: image.uri, type: image.mimeType, name: image.fileName });
77
+ if (XMLHttpRequestImpl === undefined)
78
+ return fetchImpl(target, { method: "POST", headers: owner, body: form });
79
+ return (0, transport_1.xhrPost)(XMLHttpRequestImpl, target, owner, form);
80
+ }
81
+ return {
82
+ getSite: () => call(get("/site", (0, request_1.appHeaders)(appId)), 200, siteResponse, "SITE_NOT_FOUND"),
83
+ async createPost(input, images = []) {
84
+ if (!input.content.trim())
85
+ return fail("VALIDATION_ERROR");
86
+ const verdict = (0, request_1.validateImages)(images);
87
+ if (verdict !== "ok")
88
+ return fail(verdict);
89
+ return call(() => sendPost(input, images), 201, createdResponse);
90
+ },
91
+ listMyPosts: (cursor) => call(get("/posts", owner, cursor), 200, posts_schema_1.listSchema),
92
+ async getPost(number) {
93
+ if (!postNumber(number))
94
+ return fail("NOT_FOUND");
95
+ return call(get(`/posts/${number}`), 200, detailResponse);
96
+ },
97
+ async addFollowUp(number, body) {
98
+ const trimmed = body.trim();
99
+ if (!trimmed || trimmed.length > exports.MAX_FOLLOW_UP)
100
+ return fail("VALIDATION_ERROR");
101
+ if (!postNumber(number))
102
+ return fail("NOT_FOUND");
103
+ const target = url(`/posts/${number}/followups`);
104
+ const send = () => fetchImpl(target, { method: "POST", headers: json, body: JSON.stringify({ body: trimmed }) });
105
+ return call(send, 201, entryResponse);
106
+ },
107
+ getUnread: () => call(get("/unread"), 200, posts_schema_1.unreadSchema),
108
+ imageSource: (number, imageId) => ({
109
+ uri: url(`/posts/${number}/images/${encodeURIComponent(imageId)}`),
110
+ headers: owner,
111
+ }),
112
+ };
113
+ }
@@ -13,7 +13,7 @@ export type ImageAsset = Readonly<{
13
13
  fileName: string;
14
14
  fileSize?: number;
15
15
  }>;
16
- export type FeedbackErrorCode = "APP_NOT_ALLOWED" | "ORIGIN_NOT_ALLOWED" | "RATE_LIMITED" | "VALIDATION_ERROR" | "IMAGES_DISABLED" | "TOO_MANY_IMAGES" | "IMAGE_TOO_LARGE" | "INVALID_IMAGE" | "WIDGET_NOT_FOUND" | "NETWORK_ERROR";
16
+ export type FeedbackErrorCode = "APP_NOT_ALLOWED" | "ORIGIN_NOT_ALLOWED" | "RATE_LIMITED" | "VALIDATION_ERROR" | "IMAGES_DISABLED" | "TOO_MANY_IMAGES" | "IMAGE_TOO_LARGE" | "INVALID_IMAGE" | "WIDGET_NOT_FOUND" | "NETWORK_ERROR" | "ELIGIBILITY";
17
17
  export type FeedbackPayload = Readonly<{
18
18
  key: string;
19
19
  content: string;
@@ -71,6 +71,8 @@ function errorMessageKey(code) {
71
71
  return "imageTooLarge";
72
72
  case "INVALID_IMAGE":
73
73
  return "invalidImage";
74
+ case "ELIGIBILITY":
75
+ return "notEligible";
74
76
  case "APP_NOT_ALLOWED":
75
77
  case "ORIGIN_NOT_ALLOWED":
76
78
  case "VALIDATION_ERROR":