@appsupportkit/support-sdk 0.1.1 → 0.2.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.
Files changed (110) hide show
  1. package/lib/commonjs/api.js +29 -0
  2. package/lib/commonjs/api.js.map +1 -1
  3. package/lib/commonjs/components/BottomSheet.js +67 -47
  4. package/lib/commonjs/components/BottomSheet.js.map +1 -1
  5. package/lib/commonjs/components/LauncherButton.js +177 -0
  6. package/lib/commonjs/components/LauncherButton.js.map +1 -0
  7. package/lib/commonjs/components/SupportButton.js +76 -146
  8. package/lib/commonjs/components/SupportButton.js.map +1 -1
  9. package/lib/commonjs/components/icons.js +74 -23
  10. package/lib/commonjs/components/icons.js.map +1 -1
  11. package/lib/commonjs/components/primitives.js +183 -38
  12. package/lib/commonjs/components/primitives.js.map +1 -1
  13. package/lib/commonjs/components/screens/ComposeScreen.js +115 -58
  14. package/lib/commonjs/components/screens/ComposeScreen.js.map +1 -1
  15. package/lib/commonjs/components/screens/HomeScreen.js +170 -115
  16. package/lib/commonjs/components/screens/HomeScreen.js.map +1 -1
  17. package/lib/commonjs/components/screens/ThreadScreen.js +222 -108
  18. package/lib/commonjs/components/screens/ThreadScreen.js.map +1 -1
  19. package/lib/commonjs/index.js +7 -0
  20. package/lib/commonjs/index.js.map +1 -1
  21. package/lib/commonjs/push.js +103 -0
  22. package/lib/commonjs/push.js.map +1 -0
  23. package/lib/commonjs/theme.js +136 -17
  24. package/lib/commonjs/theme.js.map +1 -1
  25. package/lib/commonjs/types.js +7 -0
  26. package/lib/commonjs/types.js.map +1 -1
  27. package/lib/commonjs/unread.js +92 -0
  28. package/lib/commonjs/unread.js.map +1 -0
  29. package/lib/commonjs/useSupportThreads.js +286 -0
  30. package/lib/commonjs/useSupportThreads.js.map +1 -0
  31. package/lib/commonjs/utils.js +33 -0
  32. package/lib/commonjs/utils.js.map +1 -1
  33. package/lib/module/api.js +27 -0
  34. package/lib/module/api.js.map +1 -1
  35. package/lib/module/components/BottomSheet.js +68 -48
  36. package/lib/module/components/BottomSheet.js.map +1 -1
  37. package/lib/module/components/LauncherButton.js +172 -0
  38. package/lib/module/components/LauncherButton.js.map +1 -0
  39. package/lib/module/components/SupportButton.js +79 -149
  40. package/lib/module/components/SupportButton.js.map +1 -1
  41. package/lib/module/components/icons.js +72 -22
  42. package/lib/module/components/icons.js.map +1 -1
  43. package/lib/module/components/primitives.js +179 -39
  44. package/lib/module/components/primitives.js.map +1 -1
  45. package/lib/module/components/screens/ComposeScreen.js +118 -61
  46. package/lib/module/components/screens/ComposeScreen.js.map +1 -1
  47. package/lib/module/components/screens/HomeScreen.js +172 -117
  48. package/lib/module/components/screens/HomeScreen.js.map +1 -1
  49. package/lib/module/components/screens/ThreadScreen.js +228 -112
  50. package/lib/module/components/screens/ThreadScreen.js.map +1 -1
  51. package/lib/module/index.js +1 -0
  52. package/lib/module/index.js.map +1 -1
  53. package/lib/module/push.js +98 -0
  54. package/lib/module/push.js.map +1 -0
  55. package/lib/module/theme.js +135 -16
  56. package/lib/module/theme.js.map +1 -1
  57. package/lib/module/types.js +7 -0
  58. package/lib/module/types.js.map +1 -1
  59. package/lib/module/unread.js +83 -0
  60. package/lib/module/unread.js.map +1 -0
  61. package/lib/module/useSupportThreads.js +281 -0
  62. package/lib/module/useSupportThreads.js.map +1 -0
  63. package/lib/module/utils.js +30 -0
  64. package/lib/module/utils.js.map +1 -1
  65. package/lib/typescript/api.d.ts +17 -1
  66. package/lib/typescript/api.d.ts.map +1 -1
  67. package/lib/typescript/components/BottomSheet.d.ts.map +1 -1
  68. package/lib/typescript/components/LauncherButton.d.ts +14 -0
  69. package/lib/typescript/components/LauncherButton.d.ts.map +1 -0
  70. package/lib/typescript/components/SupportButton.d.ts +3 -3
  71. package/lib/typescript/components/SupportButton.d.ts.map +1 -1
  72. package/lib/typescript/components/icons.d.ts +13 -2
  73. package/lib/typescript/components/icons.d.ts.map +1 -1
  74. package/lib/typescript/components/primitives.d.ts +35 -4
  75. package/lib/typescript/components/primitives.d.ts.map +1 -1
  76. package/lib/typescript/components/screens/ComposeScreen.d.ts.map +1 -1
  77. package/lib/typescript/components/screens/HomeScreen.d.ts +3 -2
  78. package/lib/typescript/components/screens/HomeScreen.d.ts.map +1 -1
  79. package/lib/typescript/components/screens/ThreadScreen.d.ts.map +1 -1
  80. package/lib/typescript/index.d.ts +2 -1
  81. package/lib/typescript/index.d.ts.map +1 -1
  82. package/lib/typescript/push.d.ts +18 -0
  83. package/lib/typescript/push.d.ts.map +1 -0
  84. package/lib/typescript/theme.d.ts +44 -3
  85. package/lib/typescript/theme.d.ts.map +1 -1
  86. package/lib/typescript/types.d.ts +37 -4
  87. package/lib/typescript/types.d.ts.map +1 -1
  88. package/lib/typescript/unread.d.ts +22 -0
  89. package/lib/typescript/unread.d.ts.map +1 -0
  90. package/lib/typescript/useSupportThreads.d.ts +28 -0
  91. package/lib/typescript/useSupportThreads.d.ts.map +1 -0
  92. package/lib/typescript/utils.d.ts +5 -0
  93. package/lib/typescript/utils.d.ts.map +1 -1
  94. package/package.json +8 -2
  95. package/src/api.ts +41 -1
  96. package/src/components/BottomSheet.tsx +61 -43
  97. package/src/components/LauncherButton.tsx +217 -0
  98. package/src/components/SupportButton.tsx +81 -162
  99. package/src/components/icons.tsx +77 -19
  100. package/src/components/primitives.tsx +217 -36
  101. package/src/components/screens/ComposeScreen.tsx +131 -61
  102. package/src/components/screens/HomeScreen.tsx +168 -117
  103. package/src/components/screens/ThreadScreen.tsx +289 -119
  104. package/src/index.tsx +3 -0
  105. package/src/push.ts +97 -0
  106. package/src/theme.ts +165 -18
  107. package/src/types.ts +39 -4
  108. package/src/unread.ts +91 -0
  109. package/src/useSupportThreads.ts +372 -0
  110. package/src/utils.ts +33 -0
@@ -4,26 +4,145 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.resolveTheme = resolveTheme;
7
- exports.supportLightTheme = exports.supportDarkTheme = void 0;
7
+ exports.supportRadii = exports.supportLightTheme = exports.supportDarkTheme = void 0;
8
8
  var _designTokens = require("@appsupportkit/design-tokens");
9
9
  // The SDK consumes the same design tokens as the admin dashboard, so both
10
- // surfaces look like one product.
10
+ // surfaces look like one product. On top of those it adds the few values
11
+ // that only exist on mobile: sheet/bubble radii and the elevation used by
12
+ // the launcher and the sheet (the web side gets those from CSS).
11
13
 
12
- const supportDarkTheme = exports.supportDarkTheme = {
13
- name: 'dark',
14
- colors: _designTokens.darkColors,
15
- spacing: _designTokens.spacing,
16
- radii: _designTokens.radii,
17
- motion: _designTokens.motion
14
+ /** Rounder than the dashboard: touch targets read better with more radius. */
15
+ const supportRadii = exports.supportRadii = {
16
+ ..._designTokens.radii,
17
+ control: 10,
18
+ card: 14,
19
+ cardLg: 18,
20
+ /** Message bubbles. */
21
+ bubble: 18,
22
+ /** The tight corner on a bubble's sender side. */
23
+ bubbleTail: 6,
24
+ sheet: 24,
25
+ pill: 999
18
26
  };
19
- const supportLightTheme = exports.supportLightTheme = {
20
- name: 'light',
21
- colors: _designTokens.lightColors,
22
- spacing: _designTokens.spacing,
23
- radii: _designTokens.radii,
24
- motion: _designTokens.motion
25
- };
26
- function resolveTheme(name) {
27
- return name === 'light' ? supportLightTheme : supportDarkTheme;
27
+
28
+ /**
29
+ * The launcher sits on the host app's own background rather than on an SDK
30
+ * surface, so the two themes need different treatment: on near-black a
31
+ * solid fill needs a hairline to separate from the background and a black
32
+ * shadow, while on white the accent-tinted shadow does that work and a
33
+ * borderless mark has to be darkened to stay legible.
34
+ */
35
+
36
+ // Color helpers come first: the themes below are built at module load, so
37
+ // anything they reach for has to already be initialized. (A `const` used
38
+ // before its definition survives tsc but lands as `undefined` on Hermes.)
39
+ const HEX = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i;
40
+ function parseHex(color) {
41
+ const match = HEX.exec(color.trim());
42
+ const digits = match?.[1];
43
+ if (digits === undefined) return null;
44
+ const hex = digits.length === 3 ? digits.split('').map(c => c + c).join('') : digits;
45
+ return [parseInt(hex.slice(0, 2), 16), parseInt(hex.slice(2, 4), 16), parseInt(hex.slice(4, 6), 16)];
46
+ }
47
+ function mix([r, g, b], target, amount) {
48
+ const channel = c => Math.round(c + (target - c) * amount);
49
+ return `rgb(${channel(r)}, ${channel(g)}, ${channel(b)})`;
50
+ }
51
+ function shadowsFor(name, accent) {
52
+ const dark = name === 'dark';
53
+ return {
54
+ launcher: {
55
+ // Tinting the launcher's shadow with the accent is what makes it read
56
+ // as lifted rather than pasted on.
57
+ shadowColor: dark ? '#000000' : accent,
58
+ shadowOpacity: dark ? 0.45 : 0.3,
59
+ shadowRadius: 14,
60
+ shadowOffset: {
61
+ width: 0,
62
+ height: 6
63
+ },
64
+ elevation: 8
65
+ },
66
+ sheet: {
67
+ shadowColor: '#000000',
68
+ shadowOpacity: dark ? 0.5 : 0.16,
69
+ shadowRadius: 24,
70
+ shadowOffset: {
71
+ width: 0,
72
+ height: -6
73
+ },
74
+ elevation: 24
75
+ },
76
+ badge: {
77
+ shadowColor: '#000000',
78
+ shadowOpacity: 0.25,
79
+ shadowRadius: 3,
80
+ shadowOffset: {
81
+ width: 0,
82
+ height: 1
83
+ },
84
+ elevation: 3
85
+ }
86
+ };
87
+ }
88
+ function launcherFor(name, accent) {
89
+ const rgb = parseHex(accent);
90
+ return {
91
+ solidRing: name === 'dark' ? 'rgba(255, 255, 255, 0.14)' : 'rgba(0, 0, 0, 0.06)',
92
+ // On a dark app background the raw accent is too close to the surface
93
+ // to read as a glyph; lift it toward white.
94
+ minimalMark: name === 'dark' && rgb !== null ? mix(rgb, 255, 0.35) : accent
95
+ };
96
+ }
97
+ function buildTheme(name, colors) {
98
+ return {
99
+ name,
100
+ colors,
101
+ spacing: _designTokens.spacing,
102
+ radii: supportRadii,
103
+ motion: _designTokens.motion,
104
+ shadows: shadowsFor(name, colors.accent),
105
+ launcher: launcherFor(name, colors.accent)
106
+ };
107
+ }
108
+ const supportDarkTheme = exports.supportDarkTheme = buildTheme('dark', _designTokens.darkColors);
109
+ const supportLightTheme = exports.supportLightTheme = buildTheme('light', _designTokens.lightColors);
110
+
111
+ /**
112
+ * Derives the accent family from a single brand color: a pressed shade, the
113
+ * 12% wash used behind chips and own-message bubbles, and a foreground that
114
+ * stays legible on top (dark text on light brands, white on dark ones).
115
+ */
116
+ function withAccent(theme, accent) {
117
+ const rgb = parseHex(accent);
118
+ if (!rgb) return theme;
119
+ const [r, g, b] = rgb;
120
+ // Relative luminance, sRGB coefficients — good enough to pick a foreground.
121
+ const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
122
+ const colors = {
123
+ ...theme.colors,
124
+ accent,
125
+ accentHover: mix(rgb, theme.name === 'dark' ? 255 : 0, 0.12),
126
+ accentMuted: `rgba(${r}, ${g}, ${b}, 0.12)`,
127
+ accentForeground: luminance > 0.62 ? '#111113' : '#FFFFFF',
128
+ statusOpen: accent,
129
+ statusOpenBg: `rgba(${r}, ${g}, ${b}, 0.10)`,
130
+ focusRing: accent
131
+ };
132
+ return {
133
+ ...theme,
134
+ colors,
135
+ shadows: shadowsFor(theme.name, accent),
136
+ launcher: launcherFor(theme.name, accent)
137
+ };
138
+ }
139
+
140
+ /**
141
+ * @param name "light" | "dark" (default dark).
142
+ * @param accentColor Optional brand color (hex) replacing the default accent.
143
+ */
144
+ function resolveTheme(name, accentColor) {
145
+ const base = name === 'light' ? supportLightTheme : supportDarkTheme;
146
+ return accentColor ? withAccent(base, accentColor) : base;
28
147
  }
29
148
  //# sourceMappingURL=theme.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_designTokens","require","supportDarkTheme","exports","name","colors","darkColors","spacing","radii","motion","supportLightTheme","lightColors","resolveTheme"],"sourceRoot":"../../src","sources":["theme.ts"],"mappings":";;;;;;;AAEA,IAAAA,aAAA,GAAAC,OAAA;AAFA;AACA;;AAmBO,MAAMC,gBAA8B,GAAAC,OAAA,CAAAD,gBAAA,GAAG;EAC5CE,IAAI,EAAE,MAAM;EACZC,MAAM,EAAEC,wBAAU;EAClBC,OAAO,EAAPA,qBAAO;EACPC,KAAK,EAALA,mBAAK;EACLC,MAAM,EAANA;AACF,CAAC;AAEM,MAAMC,iBAA+B,GAAAP,OAAA,CAAAO,iBAAA,GAAG;EAC7CN,IAAI,EAAE,OAAO;EACbC,MAAM,EAAEM,yBAAW;EACnBJ,OAAO,EAAPA,qBAAO;EACPC,KAAK,EAALA,mBAAK;EACLC,MAAM,EAANA;AACF,CAAC;AAEM,SAASG,YAAYA,CAACR,IAA2B,EAAgB;EACtE,OAAOA,IAAI,KAAK,OAAO,GAAGM,iBAAiB,GAAGR,gBAAgB;AAChE","ignoreList":[]}
1
+ {"version":3,"names":["_designTokens","require","supportRadii","exports","radii","control","card","cardLg","bubble","bubbleTail","sheet","pill","HEX","parseHex","color","match","exec","trim","digits","undefined","hex","length","split","map","c","join","parseInt","slice","mix","r","g","b","target","amount","channel","Math","round","shadowsFor","name","accent","dark","launcher","shadowColor","shadowOpacity","shadowRadius","shadowOffset","width","height","elevation","badge","launcherFor","rgb","solidRing","minimalMark","buildTheme","colors","spacing","motion","shadows","supportDarkTheme","darkColors","supportLightTheme","lightColors","withAccent","theme","luminance","accentHover","accentMuted","accentForeground","statusOpen","statusOpenBg","focusRing","resolveTheme","accentColor","base"],"sourceRoot":"../../src","sources":["theme.ts"],"mappings":";;;;;;;AAIA,IAAAA,aAAA,GAAAC,OAAA;AAJA;AACA;AACA;AACA;;AAYA;AACO,MAAMC,YAAY,GAAAC,OAAA,CAAAD,YAAA,GAAG;EAC1B,GAAGE,mBAAK;EACRC,OAAO,EAAE,EAAE;EACXC,IAAI,EAAE,EAAE;EACRC,MAAM,EAAE,EAAE;EACV;EACAC,MAAM,EAAE,EAAE;EACV;EACAC,UAAU,EAAE,CAAC;EACbC,KAAK,EAAE,EAAE;EACTC,IAAI,EAAE;AACR,CAAU;;AAWV;AACA;AACA;AACA;AACA;AACA;AACA;;AAkBA;AACA;AACA;AACA,MAAMC,GAAG,GAAG,gCAAgC;AAE5C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Q,EAAES,WAAW,CAACc,KAAK,CAAC1B,IAAI,EAAEC,MAAM;EAC1C,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACO,SAASiC,YAAYA,CAC1BlC,IAA2B,EAC3BmC,WAAoB,EACN;EACd,MAAMC,IAAI,GAAGpC,IAAI,KAAK,OAAO,GAAGuB,iBAAiB,GAAGF,gBAAgB;EACpE,OAAOc,WAAW,GAAGV,UAAU,CAACW,IAAI,EAAED,WAAW,CAAC,GAAGC,IAAI;AAC3D","ignoreList":[]}
@@ -4,6 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.USER_MESSAGE_MIN = exports.USER_MESSAGE_MAX = exports.QUERY_TYPE_LABEL = void 0;
7
+ /**
8
+ * How the launcher renders:
9
+ * solid — accent fill, elevated. The floating action button.
10
+ * soft — app surface + hairline border. Sits in a header or toolbar.
11
+ * minimal — bare mark, no fill or border. Sits in a nav bar.
12
+ */
13
+
7
14
  const QUERY_TYPE_LABEL = exports.QUERY_TYPE_LABEL = {
8
15
  feedback: 'Feedback',
9
16
  feature_request: 'Feature request',
@@ -1 +1 @@
1
- {"version":3,"names":["QUERY_TYPE_LABEL","exports","feedback","feature_request","bug_report","USER_MESSAGE_MIN","USER_MESSAGE_MAX"],"sourceRoot":"../../src","sources":["types.ts"],"mappings":";;;;;;AAsEO,MAAMA,gBAA2C,GAAAC,OAAA,CAAAD,gBAAA,GAAG;EACzDE,QAAQ,EAAE,UAAU;EACpBC,eAAe,EAAE,iBAAiB;EAClCC,UAAU,EAAE;AACd,CAAC;AAEM,MAAMC,gBAAgB,GAAAJ,OAAA,CAAAI,gBAAA,GAAG,EAAE;AAC3B,MAAMC,gBAAgB,GAAAL,OAAA,CAAAK,gBAAA,GAAG,GAAG","ignoreList":[]}
1
+ {"version":3,"names":["QUERY_TYPE_LABEL","exports","feedback","feature_request","bug_report","USER_MESSAGE_MIN","USER_MESSAGE_MAX"],"sourceRoot":"../../src","sources":["types.ts"],"mappings":";;;;;;AAQA;AACA;AACA;AACA;AACA;AACA;;AA4FO,MAAMA,gBAA2C,GAAAC,OAAA,CAAAD,gBAAA,GAAG;EACzDE,QAAQ,EAAE,UAAU;EACpBC,eAAe,EAAE,iBAAiB;EAClCC,UAAU,EAAE;AACd,CAAC;AAEM,MAAMC,gBAAgB,GAAAJ,OAAA,CAAAI,gBAAA,GAAG,EAAE;AAC3B,MAAMC,gBAAgB,GAAAL,OAAA,CAAAK,gBAAA,GAAG,GAAG","ignoreList":[]}
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.latestAdminMessageAt = latestAdminMessageAt;
7
+ exports.pruneWatermarks = pruneWatermarks;
8
+ exports.reconcileThread = reconcileThread;
9
+ exports.reconcileThreads = reconcileThreads;
10
+ exports.sumUnread = sumUnread;
11
+ exports.unreadSince = unreadSince;
12
+ // Unread accounting.
13
+ //
14
+ // The server counts a thread's unread as "admin messages newer than the
15
+ // user's read receipt". That number is authoritative, but it is always a
16
+ // little behind the device: between the moment the user opens a thread and
17
+ // the moment `mark-read` lands, every already-in-flight poll still reports
18
+ // the old count — which is what made the badge flicker back on after being
19
+ // cleared, and what made a thread the user was actively reading accumulate
20
+ // unread replies.
21
+ //
22
+ // So the client keeps its own watermark per thread: the `created_at` of the
23
+ // newest admin message the user has actually seen. Those are *server*
24
+ // timestamps, so nothing here compares against the device clock.
25
+ //
26
+ // Displayed unread is then the stricter of the two counts, which is correct
27
+ // in both directions:
28
+ //
29
+ // read here, receipt not written yet → local watermark wins (0)
30
+ // read on another device → server count wins (0)
31
+
32
+ /** Watermark map: thread id → `created_at` (ms) of the newest seen reply. */
33
+
34
+ /** `created_at` (ms) of the newest admin message, or 0 if there are none. */
35
+ function latestAdminMessageAt(thread) {
36
+ let latest = 0;
37
+ for (const message of thread.messages) {
38
+ if (message.sender !== 'admin') continue;
39
+ const at = Date.parse(message.created_at);
40
+ if (Number.isFinite(at) && at > latest) latest = at;
41
+ }
42
+ return latest;
43
+ }
44
+
45
+ /** Admin messages in `thread` newer than `watermark`. */
46
+ function unreadSince(thread, watermark) {
47
+ let count = 0;
48
+ for (const message of thread.messages) {
49
+ if (message.sender !== 'admin') continue;
50
+ const at = Date.parse(message.created_at);
51
+ if (Number.isFinite(at) && at > watermark) count += 1;
52
+ }
53
+ return count;
54
+ }
55
+
56
+ /**
57
+ * Returns `thread` with `unread_count` narrowed by what this device knows
58
+ * the user has read. Identity is preserved when nothing changes so lists
59
+ * stay referentially stable between polls.
60
+ */
61
+ function reconcileThread(thread, watermarks) {
62
+ const watermark = watermarks.get(thread.id);
63
+ if (watermark === undefined || thread.unread_count === 0) return thread;
64
+ const unread = Math.min(thread.unread_count, unreadSince(thread, watermark));
65
+ return unread === thread.unread_count ? thread : {
66
+ ...thread,
67
+ unread_count: unread
68
+ };
69
+ }
70
+ function reconcileThreads(threads, watermarks) {
71
+ return threads.map(thread => reconcileThread(thread, watermarks));
72
+ }
73
+ function sumUnread(threads) {
74
+ return threads.reduce((total, thread) => total + thread.unread_count, 0);
75
+ }
76
+
77
+ /**
78
+ * Drops watermarks the server has caught up on (its own count is already 0)
79
+ * and ones for threads that no longer exist, so the map can't grow without
80
+ * bound over a long session.
81
+ */
82
+ function pruneWatermarks(watermarks, serverThreads) {
83
+ const keep = new Map();
84
+ for (const thread of serverThreads) {
85
+ const watermark = watermarks.get(thread.id);
86
+ if (watermark !== undefined && thread.unread_count > 0) {
87
+ keep.set(thread.id, watermark);
88
+ }
89
+ }
90
+ return keep;
91
+ }
92
+ //# sourceMappingURL=unread.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["latestAdminMessageAt","thread","latest","message","messages","sender","at","Date","parse","created_at","Number","isFinite","unreadSince","watermark","count","reconcileThread","watermarks","get","id","undefined","unread_count","unread","Math","min","reconcileThreads","threads","map","sumUnread","reduce","total","pruneWatermarks","serverThreads","keep","Map","set"],"sourceRoot":"../../src","sources":["unread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AAY,EAAER,WAAW,CAACX,MAAM,EAAEY,SAAS,CAAC,CAAC;EAC5E,OAAOQ,MAAM,KAAKpB,MAAM,CAACmB,YAAY,GAAGnB,MAAM,GAAG;IAAE,GAAGA,MAAM;IAAEmB,YAAY,EAAEC;EAAO,CAAC;AACtF;AAEO,SAASG,gBAAgBA,CAC9BC,OAAiB,EACjBT,UAA0B,EAChB;EACV,OAAOS,OAAO,CAACC,GAAG,CAAEzB,MAAM,IAAKc,eAAe,CAACd,MAAM,EAAEe,UAAU,CAAC,CAAC;AACrE;AAEO,SAASW,SAASA,CAACF,OAAiB,EAAU;EACnD,OAAOA,OAAO,CAACG,MAAM,CAAC,CAACC,KAAK,EAAE5B,MAAM,KAAK4B,KAAK,GAAG5B,MAAM,CAACmB,YAAY,EAAE,CAAC,CAAC;AAC1E;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASU,eAAeA,CAC7Bd,UAA0B,EAC1Be,aAAuB,EACP;EAChB,MAAMC,IAAoB,GAAG,IAAIC,GAAG,CAAC,CAAC;EACtC,KAAK,MAAMhC,MAAM,IAAI8B,aAAa,EAAE;IAClC,MAAMlB,SAAS,GAAGG,UAAU,CAACC,GAAG,CAAChB,MAAM,CAACiB,EAAE,CAAC;IAC3C,IAAIL,SAAS,KAAKM,SAAS,IAAIlB,MAAM,CAACmB,YAAY,GAAG,CAAC,EAAE;MACtDY,IAAI,CAACE,GAAG,CAACjC,MAAM,CAACiB,EAAE,EAAEL,SAAS,CAAC;IAChC;EACF;EACA,OAAOmB,IAAI;AACb","ignoreList":[]}
@@ -0,0 +1,286 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.IDLE_POLL_MS = void 0;
7
+ exports.useSupportThreads = useSupportThreads;
8
+ var _react = require("react");
9
+ var _reactNative = require("react-native");
10
+ var _api = require("./api");
11
+ var _unread = require("./unread");
12
+ // Threads + unread state for the SDK: fetching, poll cadence, and read
13
+ // tracking. Kept out of SupportButton so the rules below live in one place.
14
+ //
15
+ // Three invariants make the badge trustworthy:
16
+ //
17
+ // 1. Responses are applied in issue order (`appliedSeq`), so a slow poll
18
+ // can never overwrite a newer one.
19
+ // 2. The badge-only endpoint returns a bare number that cannot be
20
+ // reconciled against local reads, so its answer is dropped when a read
21
+ // happened while it was in flight (`readEpoch`), and it isn't used at
22
+ // all while any `mark-read` is still unconfirmed — the full endpoint is
23
+ // polled instead, since that payload *can* be reconciled.
24
+ // 3. `mark-read` failures are retried instead of swallowed, and the local
25
+ // watermark holds the UI correct in the meantime.
26
+
27
+ // Poll cadence by context: fast where latency is felt (staring at a thread
28
+ // waiting for a reply), slow when the sheet is closed — and the idle tick
29
+ // uses the count-only endpoint, so it costs ~18 bytes instead of the full
30
+ // thread list.
31
+ const THREAD_POLL_MS = 5_000;
32
+ const SHEET_POLL_MS = 15_000;
33
+ const IDLE_POLL_MS = exports.IDLE_POLL_MS = 60_000;
34
+ const MIN_POLL_MS = 3_000;
35
+
36
+ // A failed mark-read used to be dropped on the floor, which resurrected the
37
+ // badge on the next poll. Retry a few times with backoff; anything still
38
+ // unconfirmed after that is picked up by the next poll tick or foreground.
39
+ const MARK_READ_MAX_ATTEMPTS = 4;
40
+ const MARK_READ_BACKOFF_MS = 1_500;
41
+
42
+ /**
43
+ * Load failures the user can act on say so; the rest stay neutral. A 401 is
44
+ * an integration mistake — the end user retrying forever won't fix a key
45
+ * that doesn't match the app — so the real cause is logged for whoever is
46
+ * running the build instead of hidden behind "couldn't load".
47
+ */
48
+ function loadErrorMessage(e) {
49
+ if (e instanceof _api.SupportApiError) {
50
+ if (e.offline) return "You're offline — check your connection";
51
+ if (e.status === 401 || e.status === 403) {
52
+ if (__DEV__) {
53
+ console.error('SupportButton: the support API rejected this app (401). Check that ' + '`apiKey` is the key shown when the app was registered and that ' + '`appName` matches that app exactly.');
54
+ }
55
+ return 'Support is unavailable right now';
56
+ }
57
+ if (e.status === 429) return 'Too many requests — try again in a bit';
58
+ }
59
+ return "Couldn't load your conversations";
60
+ }
61
+ function useSupportThreads({
62
+ config,
63
+ revenuecatId,
64
+ enabled,
65
+ sheetOpen,
66
+ activeThreadId,
67
+ idlePollMs
68
+ }) {
69
+ const [threads, setThreads] = (0, _react.useState)(null);
70
+ const [totalUnread, setTotalUnread] = (0, _react.useState)(0);
71
+ const [loading, setLoading] = (0, _react.useState)(false);
72
+ const [refreshing, setRefreshing] = (0, _react.useState)(false);
73
+ const [error, setError] = (0, _react.useState)(null);
74
+ const mounted = (0, _react.useRef)(true);
75
+ /** Last server payload, before local read reconciliation. */
76
+ const rawThreads = (0, _react.useRef)(null);
77
+ const watermarks = (0, _react.useRef)(new Map());
78
+ const reads = (0, _react.useRef)(new Map());
79
+ const requestSeq = (0, _react.useRef)(0);
80
+ const appliedSeq = (0, _react.useRef)(0);
81
+ const readEpoch = (0, _react.useRef)(0);
82
+ const activeThreadIdRef = (0, _react.useRef)(activeThreadId);
83
+ (0, _react.useEffect)(() => {
84
+ activeThreadIdRef.current = activeThreadId;
85
+ }, [activeThreadId]);
86
+ (0, _react.useEffect)(() => {
87
+ mounted.current = true;
88
+ const timers = reads.current;
89
+ return () => {
90
+ mounted.current = false;
91
+ for (const attempt of timers.values()) {
92
+ if (attempt.timer !== null) clearTimeout(attempt.timer);
93
+ }
94
+ timers.clear();
95
+ };
96
+ }, []);
97
+ const publish = (0, _react.useCallback)(() => {
98
+ const raw = rawThreads.current;
99
+ if (raw === null) return;
100
+ const reconciled = (0, _unread.reconcileThreads)(raw, watermarks.current);
101
+ setThreads(reconciled);
102
+ setTotalUnread((0, _unread.sumUnread)(reconciled));
103
+ }, []);
104
+
105
+ /** POSTs the receipt, retrying transient failures with backoff. */
106
+ const sendRead = (0, _react.useCallback)(threadId => {
107
+ const attempt = reads.current.get(threadId);
108
+ if (!attempt || attempt.inFlight !== null) return;
109
+ const covers = attempt.target;
110
+ attempt.inFlight = covers;
111
+ attempt.timer = null;
112
+ (0, _api.markRead)(config, {
113
+ queryId: threadId,
114
+ revenuecatId
115
+ }).then(() => {
116
+ if (!mounted.current) return;
117
+ const current = reads.current.get(threadId);
118
+ if (!current) return;
119
+ current.inFlight = null;
120
+ // A reply that landed while this request was in flight isn't
121
+ // covered by the receipt it just wrote — send one more.
122
+ if (current.target > covers) {
123
+ current.attempts = 0;
124
+ sendRead(threadId);
125
+ return;
126
+ }
127
+ reads.current.delete(threadId);
128
+ // The receipt now exists server-side, so any response still in
129
+ // flight predates it and must not be trusted for unread counts.
130
+ readEpoch.current += 1;
131
+ }).catch(() => {
132
+ if (!mounted.current) return;
133
+ const current = reads.current.get(threadId);
134
+ if (!current) return;
135
+ current.inFlight = null;
136
+ current.attempts += 1;
137
+ if (current.attempts >= MARK_READ_MAX_ATTEMPTS) return;
138
+ current.timer = setTimeout(() => sendRead(threadId), MARK_READ_BACKOFF_MS * 2 ** (current.attempts - 1));
139
+ });
140
+ }, [config, revenuecatId]);
141
+
142
+ /** Re-drives receipts that gave up earlier (next poll tick / foreground). */
143
+ const flushReads = (0, _react.useCallback)(() => {
144
+ for (const [threadId, attempt] of reads.current) {
145
+ if (attempt.inFlight !== null || attempt.timer !== null) continue;
146
+ attempt.attempts = 0;
147
+ sendRead(threadId);
148
+ }
149
+ }, [sendRead]);
150
+
151
+ /**
152
+ * Records that the user has seen every reply currently in `threadId` and
153
+ * persists it. Idempotent: re-marking a thread with nothing new is a
154
+ * no-op, so the 5s in-thread poll doesn't spam the endpoint.
155
+ */
156
+ const markThreadRead = (0, _react.useCallback)(threadId => {
157
+ const thread = rawThreads.current?.find(t => t.id === threadId);
158
+ if (!thread) return;
159
+ const latest = (0, _unread.latestAdminMessageAt)(thread);
160
+ if (latest === 0) return;
161
+ if (latest <= (watermarks.current.get(threadId) ?? 0)) return;
162
+ watermarks.current.set(threadId, latest);
163
+ // Invalidate the bare counts of any request already in flight.
164
+ readEpoch.current += 1;
165
+ publish();
166
+ const attempt = reads.current.get(threadId);
167
+ if (attempt) attempt.target = latest;else {
168
+ reads.current.set(threadId, {
169
+ target: latest,
170
+ inFlight: null,
171
+ attempts: 0,
172
+ timer: null
173
+ });
174
+ }
175
+ sendRead(threadId);
176
+ }, [publish, sendRead]);
177
+ const fetchThreads = (0, _react.useCallback)(async mode => {
178
+ if (!enabled) return;
179
+ const seq = requestSeq.current += 1;
180
+ // With nothing cached there is no list to pull down, so a retry shows
181
+ // the skeleton rather than a spinner nobody can see.
182
+ const blank = rawThreads.current === null;
183
+ const spinner = mode === 'user' && !blank;
184
+ const skeleton = mode !== 'background' && blank;
185
+ if (spinner) setRefreshing(true);
186
+ if (skeleton) setLoading(true);
187
+ try {
188
+ const data = await (0, _api.getThreads)(config, revenuecatId);
189
+ if (!mounted.current) return;
190
+ // A slower earlier request must never clobber a newer answer.
191
+ if (seq <= appliedSeq.current) return;
192
+ appliedSeq.current = seq;
193
+ rawThreads.current = data.threads;
194
+ watermarks.current = (0, _unread.pruneWatermarks)(watermarks.current, data.threads);
195
+ setError(null);
196
+ publish();
197
+
198
+ // Replies that arrived while the user is sitting in the thread are
199
+ // read on arrival — otherwise the badge climbed while they read.
200
+ const active = activeThreadIdRef.current;
201
+ if (active !== null) markThreadRead(active);
202
+ flushReads();
203
+ } catch (e) {
204
+ if (!mounted.current) return;
205
+ // A failed background poll must not blow away cached threads.
206
+ if (rawThreads.current === null) setError(loadErrorMessage(e));
207
+ } finally {
208
+ if (mounted.current) {
209
+ if (spinner) setRefreshing(false);
210
+ if (skeleton) setLoading(false);
211
+ }
212
+ }
213
+ }, [config, enabled, revenuecatId, publish, markThreadRead, flushReads]);
214
+
215
+ /** Badge-only refresh — the cheap endpoint, used while idle. */
216
+ const fetchCount = (0, _react.useCallback)(async () => {
217
+ if (!enabled) return;
218
+ const seq = requestSeq.current += 1;
219
+ const epoch = readEpoch.current;
220
+ try {
221
+ const data = await (0, _api.getUnreadCount)(config, revenuecatId);
222
+ if (!mounted.current) return;
223
+ // This payload is just a number: there is no way to subtract reads
224
+ // that happened while it was in flight, so discard it instead.
225
+ if (readEpoch.current !== epoch) return;
226
+ if (seq <= appliedSeq.current) return;
227
+ appliedSeq.current = seq;
228
+ setTotalUnread(data.total_unread);
229
+ } catch {
230
+ // Best effort: the next tick or the next sheet open reconciles.
231
+ }
232
+ }, [config, enabled, revenuecatId]);
233
+
234
+ // Initial load.
235
+ (0, _react.useEffect)(() => {
236
+ void fetchThreads('initial');
237
+ }, [fetchThreads]);
238
+
239
+ // Opening the sheet always shows fresh data.
240
+ (0, _react.useEffect)(() => {
241
+ if (sheetOpen) void fetchThreads('background');
242
+ }, [sheetOpen, fetchThreads]);
243
+
244
+ // Opening a thread marks it read immediately, before the next poll.
245
+ (0, _react.useEffect)(() => {
246
+ if (activeThreadId !== null) markThreadRead(activeThreadId);
247
+ }, [activeThreadId, markThreadRead]);
248
+
249
+ // Cadence follows what the user is looking at; the app returning to the
250
+ // foreground always ticks.
251
+ (0, _react.useEffect)(() => {
252
+ if (!enabled) return;
253
+ const idle = !sheetOpen;
254
+ const intervalMs = idle ? idlePollMs : activeThreadId !== null ? THREAD_POLL_MS : SHEET_POLL_MS;
255
+ const tick = () => {
256
+ // While a receipt is unconfirmed the count-only endpoint would report
257
+ // replies the user has already read, so pay for the full payload.
258
+ if (idle && reads.current.size === 0) void fetchCount();else void fetchThreads('background');
259
+ };
260
+
261
+ // Clamped so a typo like `pollIntervalMs={30}` can't hammer the API;
262
+ // 0 (or negative) disables idle polling entirely.
263
+ const timer = intervalMs > 0 ? setInterval(tick, Math.max(intervalMs, MIN_POLL_MS)) : null;
264
+ const appStateSub = _reactNative.AppState.addEventListener('change', state => {
265
+ if (state === 'active') tick();
266
+ });
267
+ return () => {
268
+ if (timer !== null) clearInterval(timer);
269
+ appStateSub.remove();
270
+ };
271
+ }, [enabled, sheetOpen, activeThreadId, idlePollMs, fetchThreads, fetchCount]);
272
+ const refresh = (0, _react.useCallback)(() => {
273
+ void fetchThreads('user');
274
+ }, [fetchThreads]);
275
+ const reload = (0, _react.useCallback)(() => fetchThreads('background'), [fetchThreads]);
276
+ return {
277
+ threads,
278
+ totalUnread,
279
+ loading,
280
+ refreshing,
281
+ error,
282
+ refresh,
283
+ reload
284
+ };
285
+ }
286
+ //# sourceMappingURL=useSupportThreads.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","require","_reactNative","_api","_unread","THREAD_POLL_MS","SHEET_POLL_MS","IDLE_POLL_MS","exports","MIN_POLL_MS","MARK_READ_MAX_ATTEMPTS","MARK_READ_BACKOFF_MS","loadErrorMessage","e","SupportApiError","offline","status","__DEV__","console","error","useSupportThreads","config","revenuecatId","enabled","sheetOpen","activeThreadId","idlePollMs","threads","setThreads","useState","totalUnread","setTotalUnread","loading","setLoading","refreshing","setRefreshing","setError","mounted","useRef","rawThreads","watermarks","Map","reads","requestSeq","appliedSeq","readEpoch","activeThreadIdRef","useEffect","current","timers","attempt","values","timer","clearTimeout","clear","publish","useCallback","raw","reconciled","reconcileThreads","sumUnread","sendRead","threadId","get","inFlight","covers","target","markRead","queryId","then","attempts","delete","catch","setTimeout","flushReads","markThreadRead","thread","find","t","id","latest","latestAdminMessageAt","set","fetchThreads","mode","seq","blank","spinner","skeleton","data","getThreads","pruneWatermarks","active","fetchCount","epoch","getUnreadCount","total_unread","idle","intervalMs","tick","size","setInterval","Math","max","appStateSub","AppState","addEventListener","state","clearInterval","remove","refresh","reload"],"sourceRoot":"../../src","sources":["useSupportThreads.ts"],"mappings":";;;;;;;AAcA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,IAAA,GAAAF,OAAA;AAQA,IAAAG,OAAA,GAAAH,OAAA;AAxBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAmBA;AACA;AACA;AACA;AACA,MAAMI,cAAc,GAAG,KAAK;AAC5B,MAAMC,aAAa,GAAG,MAAM;AACrB,MAAMC,YAAY,GAAAC,OAAA,CAAAD,YAAA,GAAG,MAAM;AACl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AAC,CAAC;IAChC,CAAC,CAAC;IAEF,OAAO,MAAM;MACX,IAAI/C,KAAK,KAAK,IAAI,EAAEwD,aAAa,CAACxD,KAAK,CAAC;MACxCoD,WAAW,CAACK,MAAM,CAAC,CAAC;IACtB,CAAC;EACH,CAAC,EAAE,CACDtF,OAAO,EACPC,SAAS,EACTC,cAAc,EACdC,UAAU,EACVyD,YAAY,EACZU,UAAU,CACX,CAAC;EAEF,MAAMiB,OAAO,GAAG,IAAAtD,kBAAW,EAAC,MAAM;IAChC,KAAK2B,YAAY,CAAC,MAAM,CAAC;EAC3B,CAAC,EAAE,CAACA,YAAY,CAAC,CAAC;EAElB,MAAM4B,MAAM,GAAG,IAAAvD,kBAAW,EAAC,MAAM2B,YAAY,CAAC,YAAY,CAAC,EAAE,CAACA,YAAY,CAAC,CAAC;EAE5E,OAAO;IACLxD,OAAO;IACPG,WAAW;IACXE,OAAO;IACPE,UAAU;IACVf,KAAK;IACL2F,OAAO;IACPC;EACF,CAAC;AACH","ignoreList":[]}
@@ -3,7 +3,10 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.dayLabel = dayLabel;
6
7
  exports.formatDate = formatDate;
8
+ exports.formatTime = formatTime;
9
+ exports.isSameDay = isSameDay;
7
10
  exports.relativeTime = relativeTime;
8
11
  exports.validateProps = validateProps;
9
12
  /** "2h ago" relative time — mirrors the web dashboard's formatting. */
@@ -31,6 +34,36 @@ function formatDate(iso) {
31
34
  });
32
35
  }
33
36
 
37
+ /** "14:32" in the device's locale — shown under a group of messages. */
38
+ function formatTime(iso) {
39
+ return new Date(iso).toLocaleTimeString(undefined, {
40
+ hour: 'numeric',
41
+ minute: '2-digit'
42
+ });
43
+ }
44
+ function isSameDay(a, b) {
45
+ const first = new Date(a);
46
+ const second = new Date(b);
47
+ return first.getFullYear() === second.getFullYear() && first.getMonth() === second.getMonth() && first.getDate() === second.getDate();
48
+ }
49
+
50
+ /** Date separator label: Today / Yesterday / "Mon, 5 Jan". */
51
+ function dayLabel(iso) {
52
+ const now = new Date();
53
+ if (isSameDay(iso, now.toISOString())) return 'Today';
54
+ const yesterday = new Date(now.getTime() - 86_400_000);
55
+ if (isSameDay(iso, yesterday.toISOString())) return 'Yesterday';
56
+ const date = new Date(iso);
57
+ return date.toLocaleDateString(undefined, {
58
+ weekday: 'short',
59
+ month: 'short',
60
+ day: 'numeric',
61
+ ...(date.getFullYear() === now.getFullYear() ? {} : {
62
+ year: 'numeric'
63
+ })
64
+ });
65
+ }
66
+
34
67
  /** Dev-mode prop validation with actionable messages. */
35
68
  function validateProps(props) {
36
69
  if (typeof props.appName !== 'string' || props.appName.length === 0) {