@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
@@ -1,5 +1,62 @@
1
1
  import type { WidgetConfig } from "../core/config";
2
2
  import type { Tokens } from "./tokens";
3
+ export declare const SPACE: {
4
+ readonly hair: 4;
5
+ readonly tight: 6;
6
+ readonly gap: 8;
7
+ readonly block: 12;
8
+ readonly group: 16;
9
+ readonly panel: 20;
10
+ };
11
+ export declare const TOUCH = 44;
12
+ export declare const HOME_INDICATOR: number;
13
+ export declare const TYPE: {
14
+ readonly screen: {
15
+ readonly fontSize: 26;
16
+ readonly lineHeight: 32;
17
+ readonly fontWeight: "700";
18
+ readonly letterSpacing: -0.4;
19
+ };
20
+ readonly headline: {
21
+ readonly fontSize: 20;
22
+ readonly lineHeight: 26;
23
+ readonly fontWeight: "600";
24
+ readonly letterSpacing: -0.3;
25
+ };
26
+ readonly title: {
27
+ readonly fontSize: 17;
28
+ readonly lineHeight: 22;
29
+ readonly fontWeight: "600";
30
+ readonly letterSpacing: -0.2;
31
+ };
32
+ readonly item: {
33
+ readonly fontSize: 16;
34
+ readonly lineHeight: 22;
35
+ readonly fontWeight: "600";
36
+ };
37
+ readonly body: {
38
+ readonly fontSize: 15;
39
+ readonly lineHeight: 22;
40
+ };
41
+ readonly label: {
42
+ readonly fontSize: 14;
43
+ readonly lineHeight: 20;
44
+ readonly fontWeight: "500";
45
+ };
46
+ readonly input: {
47
+ readonly fontSize: 16;
48
+ readonly lineHeight: 22;
49
+ };
50
+ readonly action: {
51
+ readonly fontSize: 15;
52
+ readonly lineHeight: 20;
53
+ readonly fontWeight: "600";
54
+ };
55
+ readonly meta: {
56
+ readonly fontSize: 13;
57
+ readonly lineHeight: 18;
58
+ };
59
+ };
3
60
  export declare function createStyles(t: Tokens): {
4
61
  launcher: {
5
62
  backfaceVisibility?: "visible" | "hidden" | undefined;
@@ -155,6 +212,26 @@ export declare function createStyles(t: Tokens): {
155
212
  lineHeight: 20;
156
213
  fontWeight: "600";
157
214
  };
215
+ launcherRow: {
216
+ flexDirection: "row";
217
+ alignItems: "center";
218
+ gap: 6;
219
+ };
220
+ launcherDot: {
221
+ width: number;
222
+ height: number;
223
+ borderRadius: number;
224
+ backgroundColor: string;
225
+ };
226
+ head: {
227
+ flexDirection: "row";
228
+ alignItems: "center";
229
+ justifyContent: "space-between";
230
+ gap: 8;
231
+ };
232
+ headTitle: {
233
+ flexShrink: number;
234
+ };
158
235
  sheetRoot: {
159
236
  flex: number;
160
237
  justifyContent: "flex-end";
package/dist/ui/styles.js CHANGED
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TYPE = exports.HOME_INDICATOR = exports.TOUCH = exports.SPACE = void 0;
3
4
  exports.createStyles = createStyles;
4
5
  exports.useFeedbackTheme = useFeedbackTheme;
5
6
  const react_1 = require("react");
@@ -7,16 +8,19 @@ const react_native_1 = require("react-native");
7
8
  const theme_1 = require("../core/theme");
8
9
  const tokens_1 = require("./tokens");
9
10
  // Layout scale: 6 inside a group (label → field), 16 between groups, 20 panel inset (web widget values).
10
- const SPACE = { hair: 4, tight: 6, gap: 8, block: 12, group: 16, panel: 20 };
11
- const TOUCH = 44;
11
+ exports.SPACE = { hair: 4, tight: 6, gap: 8, block: 12, group: 16, panel: 20 };
12
+ exports.TOUCH = 44;
12
13
  // No safe-area module (pure JS): clear the iOS home indicator (34pt) under the launcher and sheet.
13
- const HOME_INDICATOR = react_native_1.Platform.OS === "ios" ? 12 : 0;
14
- const LAUNCHER_BOTTOM = 24 + HOME_INDICATOR;
15
- const SURVEY_ABOVE_LAUNCHER = LAUNCHER_BOTTOM + TOUCH + SPACE.block;
16
- const SHEET_BOTTOM = SPACE.panel + (react_native_1.Platform.OS === "ios" ? 14 : 0);
17
- // Native-mobile type scale: headings descend 17 → 15 → 14; inputs stay 16; meta 13.
18
- const TYPE = {
14
+ exports.HOME_INDICATOR = react_native_1.Platform.OS === "ios" ? 12 : 0;
15
+ const LAUNCHER_BOTTOM = 24 + exports.HOME_INDICATOR;
16
+ const SURVEY_ABOVE_LAUNCHER = LAUNCHER_BOTTOM + exports.TOUCH + exports.SPACE.block;
17
+ const SHEET_BOTTOM = exports.SPACE.panel + (react_native_1.Platform.OS === "ios" ? 14 : 0);
18
+ // Native-mobile type scale: screen 26 → post 20 → sheet 17 → row 16 → body 15 → label 14; inputs 16; meta 13.
19
+ exports.TYPE = {
20
+ screen: { fontSize: 26, lineHeight: 32, fontWeight: "700", letterSpacing: -0.4 },
21
+ headline: { fontSize: 20, lineHeight: 26, fontWeight: "600", letterSpacing: -0.3 },
19
22
  title: { fontSize: 17, lineHeight: 22, fontWeight: "600", letterSpacing: -0.2 },
23
+ item: { fontSize: 16, lineHeight: 22, fontWeight: "600" },
20
24
  body: { fontSize: 15, lineHeight: 22 },
21
25
  label: { fontSize: 14, lineHeight: 20, fontWeight: "500" },
22
26
  input: { fontSize: 16, lineHeight: 22 },
@@ -39,17 +43,21 @@ function createStyles(t) {
39
43
  position: "absolute",
40
44
  bottom: LAUNCHER_BOTTOM,
41
45
  maxWidth: "70%",
42
- minHeight: TOUCH,
46
+ minHeight: exports.TOUCH,
43
47
  justifyContent: "center",
44
48
  paddingHorizontal: 18,
45
49
  borderRadius: t.radius.button,
46
50
  backgroundColor: t.accent,
47
51
  ...lift(t, 1),
48
52
  },
49
- launcherRight: { right: SPACE.panel },
50
- launcherLeft: { left: SPACE.panel },
53
+ launcherRight: { right: exports.SPACE.panel },
54
+ launcherLeft: { left: exports.SPACE.panel },
51
55
  launcherPressed: { opacity: 0.88, transform: [{ scale: 0.97 }] },
52
- launcherLabel: { ...TYPE.action, color: t.accentText },
56
+ launcherLabel: { ...exports.TYPE.action, color: t.accentText },
57
+ launcherRow: { flexDirection: "row", alignItems: "center", gap: exports.SPACE.tight },
58
+ launcherDot: { width: 8, height: 8, borderRadius: 4, backgroundColor: t.accentText },
59
+ head: { flexDirection: "row", alignItems: "center", justifyContent: "space-between", gap: exports.SPACE.gap },
60
+ headTitle: { flexShrink: 1 },
53
61
  sheetRoot: { flex: 1, justifyContent: "flex-end" },
54
62
  // Explicit edges: `absoluteFillObject` is gone in RN 0.86 and `absoluteFill` changed shape across versions.
55
63
  scrim: { position: "absolute", top: 0, right: 0, bottom: 0, left: 0, backgroundColor: t.scrim },
@@ -62,23 +70,23 @@ function createStyles(t) {
62
70
  backgroundColor: t.background,
63
71
  ...lift(t, 2),
64
72
  },
65
- sheetContent: { padding: SPACE.panel, paddingBottom: SHEET_BOTTOM },
73
+ sheetContent: { padding: exports.SPACE.panel, paddingBottom: SHEET_BOTTOM },
66
74
  card: {
67
- padding: SPACE.panel,
75
+ padding: exports.SPACE.panel,
68
76
  borderRadius: t.radius.panel,
69
77
  borderWidth: 1,
70
78
  borderColor: t.border,
71
79
  backgroundColor: t.background,
72
80
  },
73
- title: { ...TYPE.title, color: t.text },
74
- description: { ...TYPE.body, marginTop: SPACE.hair, marginBottom: SPACE.group, color: t.mutedText },
75
- field: { marginBottom: SPACE.group },
76
- label: { ...TYPE.label, marginBottom: SPACE.tight, color: t.text },
81
+ title: { ...exports.TYPE.title, color: t.text },
82
+ description: { ...exports.TYPE.body, marginTop: exports.SPACE.hair, marginBottom: exports.SPACE.group, color: t.mutedText },
83
+ field: { marginBottom: exports.SPACE.group },
84
+ label: { ...exports.TYPE.label, marginBottom: exports.SPACE.tight, color: t.text },
77
85
  input: {
78
86
  ...field,
79
- ...TYPE.input,
80
- minHeight: TOUCH,
81
- paddingHorizontal: SPACE.block,
87
+ ...exports.TYPE.input,
88
+ minHeight: exports.TOUCH,
89
+ paddingHorizontal: exports.SPACE.block,
82
90
  paddingVertical: 10,
83
91
  color: t.text,
84
92
  },
@@ -86,13 +94,13 @@ function createStyles(t) {
86
94
  multilineShort: { minHeight: 72, textAlignVertical: "top" },
87
95
  inputFocused: { borderColor: t.accent },
88
96
  inputInvalid: { borderColor: t.danger },
89
- fieldFoot: { flexDirection: "row", gap: SPACE.block, marginTop: SPACE.tight },
90
- error: { ...TYPE.meta, flex: 1, color: t.danger },
91
- meta: { ...TYPE.meta, color: t.mutedText, fontVariant: ["tabular-nums"] },
97
+ fieldFoot: { flexDirection: "row", gap: exports.SPACE.block, marginTop: exports.SPACE.tight },
98
+ error: { ...exports.TYPE.meta, flex: 1, color: t.danger },
99
+ meta: { ...exports.TYPE.meta, color: t.mutedText, fontVariant: ["tabular-nums"] },
92
100
  end: { marginStart: "auto" },
93
- tools: { flexDirection: "row", alignItems: "center", gap: SPACE.block },
94
- hint: { ...TYPE.meta, marginTop: SPACE.tight, color: t.mutedText },
95
- strip: { flexDirection: "row", flexWrap: "wrap", gap: SPACE.block, marginTop: SPACE.block },
101
+ tools: { flexDirection: "row", alignItems: "center", gap: exports.SPACE.block },
102
+ hint: { ...exports.TYPE.meta, marginTop: exports.SPACE.tight, color: t.mutedText },
103
+ strip: { flexDirection: "row", flexWrap: "wrap", gap: exports.SPACE.block, marginTop: exports.SPACE.block },
96
104
  thumb: {
97
105
  width: 72,
98
106
  height: 72,
@@ -103,8 +111,8 @@ function createStyles(t) {
103
111
  },
104
112
  removeBadge: {
105
113
  position: "absolute",
106
- top: -SPACE.tight,
107
- end: -SPACE.tight,
114
+ top: -exports.SPACE.tight,
115
+ end: -exports.SPACE.tight,
108
116
  width: 24,
109
117
  height: 24,
110
118
  alignItems: "center",
@@ -115,12 +123,12 @@ function createStyles(t) {
115
123
  backgroundColor: t.text,
116
124
  },
117
125
  removePressed: { backgroundColor: t.danger },
118
- status: { ...TYPE.meta, marginBottom: SPACE.block, color: t.mutedText },
126
+ status: { ...exports.TYPE.meta, marginBottom: exports.SPACE.block, color: t.mutedText },
119
127
  statusError: { color: t.danger },
120
- actions: { flexDirection: "row", justifyContent: "flex-end", gap: SPACE.gap },
128
+ actions: { flexDirection: "row", justifyContent: "flex-end", gap: exports.SPACE.gap },
121
129
  button: {
122
- minHeight: TOUCH,
123
- minWidth: TOUCH,
130
+ minHeight: exports.TOUCH,
131
+ minWidth: exports.TOUCH,
124
132
  alignItems: "center",
125
133
  justifyContent: "center",
126
134
  paddingHorizontal: 18,
@@ -135,10 +143,10 @@ function createStyles(t) {
135
143
  ghost: { backgroundColor: "transparent" },
136
144
  ghostPressed: { backgroundColor: t.hover },
137
145
  disabled: { opacity: 0.5 },
138
- buttonLabel: { ...TYPE.action, color: t.text },
146
+ buttonLabel: { ...exports.TYPE.action, color: t.text },
139
147
  primaryLabel: { color: t.accentText },
140
- thanks: { ...TYPE.body, paddingVertical: SPACE.group, color: t.text },
141
- surveyDock: { position: "absolute", left: SPACE.group, right: SPACE.group, pointerEvents: "box-none" },
148
+ thanks: { ...exports.TYPE.body, paddingVertical: exports.SPACE.group, color: t.text },
149
+ surveyDock: { position: "absolute", left: exports.SPACE.group, right: exports.SPACE.group, pointerEvents: "box-none" },
142
150
  dockLow: { bottom: LAUNCHER_BOTTOM },
143
151
  dockRaised: { bottom: SURVEY_ABOVE_LAUNCHER },
144
152
  dockStart: { alignItems: "flex-start" },
@@ -146,22 +154,22 @@ function createStyles(t) {
146
154
  surveyCard: {
147
155
  width: "100%",
148
156
  maxWidth: 400,
149
- padding: SPACE.group,
157
+ padding: exports.SPACE.group,
150
158
  borderRadius: t.radius.panel,
151
159
  borderWidth: 1,
152
160
  borderColor: t.border,
153
161
  backgroundColor: t.background,
154
162
  ...lift(t, 2),
155
163
  },
156
- question: { ...TYPE.label, fontWeight: "600", marginBottom: SPACE.block, color: t.text },
157
- scale: { flexDirection: "row", gap: SPACE.hair },
158
- score: { ...field, flex: 1, minHeight: TOUCH, alignItems: "center", justifyContent: "center" },
164
+ question: { ...exports.TYPE.label, fontWeight: "600", marginBottom: exports.SPACE.block, color: t.text },
165
+ scale: { flexDirection: "row", gap: exports.SPACE.hair },
166
+ score: { ...field, flex: 1, minHeight: exports.TOUCH, alignItems: "center", justifyContent: "center" },
159
167
  scoreSelected: { borderColor: t.accent, backgroundColor: t.accent },
160
168
  scorePressed: { backgroundColor: t.surface },
161
- scoreLabel: { ...TYPE.label, color: t.text, fontVariant: ["tabular-nums"] },
169
+ scoreLabel: { ...exports.TYPE.label, color: t.text, fontVariant: ["tabular-nums"] },
162
170
  scoreLabelSelected: { color: t.accentText },
163
- anchors: { flexDirection: "row", justifyContent: "space-between", gap: SPACE.gap, marginTop: SPACE.tight },
164
- anchorGap: { marginBottom: SPACE.block },
171
+ anchors: { flexDirection: "row", justifyContent: "space-between", gap: exports.SPACE.gap, marginTop: exports.SPACE.tight },
172
+ anchorGap: { marginBottom: exports.SPACE.block },
165
173
  });
166
174
  }
167
175
  /** Resolves the widget theme (light/dark/auto) against the device scheme into tokens and styles. */
@@ -0,0 +1,13 @@
1
+ export type Surface = "send" | "mine";
2
+ export type Surfaces = Readonly<{
3
+ shown: Surface | null;
4
+ session: number;
5
+ show: (target: Surface) => void;
6
+ hide: () => void;
7
+ dismissed: () => void;
8
+ }>;
9
+ /**
10
+ * The send sheet and the my-feedback screens are sibling modals. iOS cannot present one while the
11
+ * other is still on screen, so a switch there waits for the closing modal's `onDismiss`.
12
+ */
13
+ export declare function useSurfaces(): Surfaces;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useSurfaces = useSurfaces;
4
+ const react_1 = require("react");
5
+ const react_native_1 = require("react-native");
6
+ /**
7
+ * The send sheet and the my-feedback screens are sibling modals. iOS cannot present one while the
8
+ * other is still on screen, so a switch there waits for the closing modal's `onDismiss`.
9
+ */
10
+ function useSurfaces() {
11
+ const [shown, setShown] = (0, react_1.useState)(null);
12
+ const [session, setSession] = (0, react_1.useState)(0);
13
+ const queued = (0, react_1.useRef)(null);
14
+ const present = (0, react_1.useCallback)((target) => {
15
+ if (target === "mine")
16
+ setSession((count) => count + 1);
17
+ setShown(target);
18
+ }, []);
19
+ const show = (0, react_1.useCallback)((target) => {
20
+ if (shown === target)
21
+ return;
22
+ if (shown !== null && react_native_1.Platform.OS === "ios") {
23
+ queued.current = target;
24
+ setShown(null);
25
+ return;
26
+ }
27
+ queued.current = null;
28
+ present(target);
29
+ }, [shown, present]);
30
+ const hide = (0, react_1.useCallback)(() => {
31
+ queued.current = null;
32
+ setShown(null);
33
+ }, []);
34
+ const dismissed = (0, react_1.useCallback)(() => {
35
+ const next = queued.current;
36
+ queued.current = null;
37
+ if (next !== null)
38
+ present(next);
39
+ }, [present]);
40
+ return { shown, session, show, hide, dismissed };
41
+ }
@@ -0,0 +1,35 @@
1
+ import type { RefObject } from "react";
2
+ import type { RandomBytes } from "../core/author-token";
3
+ import type { SubmitResult } from "../core/client";
4
+ import type { AppSite, CreatePostInput, PostsClient } from "../core/posts";
5
+ import type { FeedbackPayload, ImageAsset } from "../core/request";
6
+ import type { FeedbackStorage } from "./storage";
7
+ export type MyPostsSource = Readonly<{
8
+ id: string;
9
+ client: PostsClient;
10
+ site: AppSite;
11
+ }>;
12
+ export type MyPosts = Readonly<{
13
+ source: MyPostsSource | null;
14
+ unreadCount: number;
15
+ refreshUnread: () => Promise<void>;
16
+ }>;
17
+ export type MyPostsOptions = Readonly<{
18
+ baseUrl: string;
19
+ widgetKey: string;
20
+ appId: string;
21
+ /** `false` without an app-provided storage: a token kept only in memory would orphan the posts on restart. */
22
+ persistent: boolean;
23
+ storage: RefObject<FeedbackStorage | undefined>;
24
+ randomBytes: RefObject<RandomBytes | undefined>;
25
+ }>;
26
+ /**
27
+ * Resolves whether this install can use the my-feedback screens (author token, then `GET site`) and
28
+ * keeps the unread count fresh on start and whenever the app returns to the foreground.
29
+ * Any failure keeps the screens hidden; the legacy send flow does not depend on this.
30
+ */
31
+ export declare function useMyPosts(options: MyPostsOptions): MyPosts;
32
+ /** The send form's payload as a post body; the contact goes out as email or free text, whichever the form took. */
33
+ export declare function postInput(payload: FeedbackPayload, screen: string): CreatePostInput;
34
+ /** The send form's payload as an owned post, so it shows up under "내 피드백" with its answers. */
35
+ export declare function submitAsPost(client: PostsClient, payload: FeedbackPayload, screen: string, images: readonly ImageAsset[]): Promise<SubmitResult>;
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useMyPosts = useMyPosts;
4
+ exports.postInput = postInput;
5
+ exports.submitAsPost = submitAsPost;
6
+ const react_1 = require("react");
7
+ const react_native_1 = require("react-native");
8
+ const author_token_1 = require("../core/author-token");
9
+ const posts_1 = require("../core/posts");
10
+ const prop_state_1 = require("./prop-state");
11
+ async function authorToken(storage, key, random) {
12
+ try {
13
+ return await (0, author_token_1.getOrCreateAuthorToken)(storage, key, random);
14
+ }
15
+ catch (error) {
16
+ if (!(error instanceof author_token_1.AuthorTokenUnavailable))
17
+ throw error;
18
+ (0, prop_state_1.devWarn)(`my-feedback screens stay hidden: ${error.message}. Install react-native-get-random-values.`);
19
+ return null;
20
+ }
21
+ }
22
+ /**
23
+ * Resolves whether this install can use the my-feedback screens (author token, then `GET site`) and
24
+ * keeps the unread count fresh on start and whenever the app returns to the foreground.
25
+ * Any failure keeps the screens hidden; the legacy send flow does not depend on this.
26
+ */
27
+ function useMyPosts(options) {
28
+ const { baseUrl, widgetKey, appId, persistent, storage, randomBytes } = options;
29
+ const id = `${baseUrl}\n${widgetKey}\n${appId}`;
30
+ const [loaded, setLoaded] = (0, react_1.useState)(null);
31
+ const source = persistent && loaded?.id === id ? loaded : null;
32
+ (0, react_1.useEffect)(() => {
33
+ let live = true;
34
+ async function load() {
35
+ const adapter = storage.current;
36
+ if (!persistent || adapter === undefined)
37
+ return (0, prop_state_1.devWarn)("pass `storage` to enable the my-feedback screens.");
38
+ const token = await authorToken(adapter, widgetKey, randomBytes.current);
39
+ if (!live || token === null)
40
+ return;
41
+ const client = (0, posts_1.createPostsClient)({ baseUrl, publicKey: widgetKey, appId, authorToken: token });
42
+ const site = await client.getSite();
43
+ if (!live)
44
+ return;
45
+ if (!site.ok)
46
+ return (0, prop_state_1.devWarn)(`my-feedback screens stay hidden (${site.code}).`);
47
+ if (site.value.myPostsEnabled)
48
+ setLoaded({ id, client, site: site.value });
49
+ }
50
+ void load();
51
+ return () => {
52
+ live = false;
53
+ };
54
+ }, [id, baseUrl, widgetKey, appId, persistent, storage, randomBytes]);
55
+ const [unread, setUnread] = (0, react_1.useState)(null);
56
+ const refreshUnread = (0, react_1.useCallback)(async () => {
57
+ if (source === null)
58
+ return;
59
+ const result = await source.client.getUnread();
60
+ if (result.ok)
61
+ setUnread({ id: source.id, count: result.value.count });
62
+ }, [source]);
63
+ (0, react_1.useEffect)(() => {
64
+ if (source === null)
65
+ return;
66
+ async function refresh() {
67
+ await refreshUnread();
68
+ }
69
+ void refresh();
70
+ const subscription = react_native_1.AppState.addEventListener("change", (state) => {
71
+ if (state === "active")
72
+ void refresh();
73
+ });
74
+ return () => subscription.remove();
75
+ }, [source, refreshUnread]);
76
+ const unreadCount = source !== null && unread?.id === source.id ? unread.count : 0;
77
+ return { source, unreadCount, refreshUnread };
78
+ }
79
+ function submitCode(code) {
80
+ switch (code) {
81
+ case "VALIDATION_ERROR":
82
+ case "RATE_LIMITED":
83
+ case "APP_NOT_ALLOWED":
84
+ case "IMAGES_DISABLED":
85
+ case "TOO_MANY_IMAGES":
86
+ case "IMAGE_TOO_LARGE":
87
+ case "INVALID_IMAGE":
88
+ case "NETWORK_ERROR":
89
+ case "ELIGIBILITY":
90
+ return code;
91
+ case "SITE_NOT_FOUND":
92
+ case "NOT_FOUND":
93
+ return "WIDGET_NOT_FOUND";
94
+ case "ONE_WAY":
95
+ case "CLOSED":
96
+ case "REQUEST_FAILED":
97
+ case "INVALID_RESPONSE":
98
+ return "VALIDATION_ERROR";
99
+ default:
100
+ return assertNever(code);
101
+ }
102
+ }
103
+ /** The send form's payload as a post body; the contact goes out as email or free text, whichever the form took. */
104
+ function postInput(payload, screen) {
105
+ const contact = {
106
+ ...(payload.contactEmail === undefined ? {} : { email: payload.contactEmail }),
107
+ ...(payload.contact === undefined ? {} : { text: payload.contact }),
108
+ };
109
+ return {
110
+ content: payload.content,
111
+ screen,
112
+ ...(payload.uid === undefined ? {} : { uid: payload.uid }),
113
+ ...(payload.client === undefined ? {} : { client: payload.client }),
114
+ ...(Object.keys(contact).length === 0 ? {} : { contact }),
115
+ };
116
+ }
117
+ /** The send form's payload as an owned post, so it shows up under "내 피드백" with its answers. */
118
+ async function submitAsPost(client, payload, screen, images) {
119
+ const result = await client.createPost(postInput(payload, screen), images);
120
+ return result.ok ? { ok: true, id: result.value.id } : { ok: false, code: submitCode(result.code) };
121
+ }
122
+ function assertNever(value) {
123
+ throw new TypeError(`Unexpected posts error: ${String(value)}`);
124
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@the-seeker/feedback-react-native",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "react-native": "dist/index.js",
@@ -13,12 +13,6 @@
13
13
  },
14
14
  "sideEffects": false,
15
15
  "license": "MIT",
16
- "scripts": {
17
- "build": "tsc -p tsconfig.build.json",
18
- "typecheck": "tsc --noEmit",
19
- "test": "vitest run",
20
- "prepublishOnly": "npm run typecheck && npm test && npm run build"
21
- },
22
16
  "peerDependencies": {
23
17
  "react": ">=18",
24
18
  "react-native": ">=0.74"
@@ -28,9 +22,14 @@
28
22
  },
29
23
  "devDependencies": {
30
24
  "typescript": "^5",
31
- "vitest": "^4.1.11",
25
+ "vitest": "^5.1.1",
32
26
  "@types/react": "^19",
33
27
  "react": "19.2.3",
34
28
  "react-native": "0.86.x"
29
+ },
30
+ "scripts": {
31
+ "build": "tsc -p tsconfig.build.json",
32
+ "typecheck": "tsc --noEmit",
33
+ "test": "vitest run"
35
34
  }
36
- }
35
+ }