@appsupportkit/support-sdk 0.2.0 → 0.4.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 (242) hide show
  1. package/lib/commonjs/api.js +61 -12
  2. package/lib/commonjs/api.js.map +1 -1
  3. package/lib/commonjs/components/BottomSheet.js +1 -1
  4. package/lib/commonjs/components/BottomSheet.js.map +1 -1
  5. package/lib/commonjs/components/LauncherButton.js +4 -4
  6. package/lib/commonjs/components/LauncherButton.js.map +1 -1
  7. package/lib/commonjs/components/SupportButton.js +192 -66
  8. package/lib/commonjs/components/SupportButton.js.map +1 -1
  9. package/lib/commonjs/components/icons.js +117 -110
  10. package/lib/commonjs/components/icons.js.map +1 -1
  11. package/lib/commonjs/components/primitives.js +3 -154
  12. package/lib/commonjs/components/primitives.js.map +1 -1
  13. package/lib/commonjs/components/screens/ChatScreen.js +487 -0
  14. package/lib/commonjs/components/screens/ChatScreen.js.map +1 -0
  15. package/lib/commonjs/components/screens/LanguageScreen.js +150 -0
  16. package/lib/commonjs/components/screens/LanguageScreen.js.map +1 -0
  17. package/lib/commonjs/i18n/index.js +101 -0
  18. package/lib/commonjs/i18n/index.js.map +1 -0
  19. package/lib/commonjs/i18n/languages.js +95 -0
  20. package/lib/commonjs/i18n/languages.js.map +1 -0
  21. package/lib/commonjs/i18n/strings/de.js +75 -0
  22. package/lib/commonjs/i18n/strings/de.js.map +1 -0
  23. package/lib/commonjs/i18n/strings/en.js +91 -0
  24. package/lib/commonjs/i18n/strings/en.js.map +1 -0
  25. package/lib/commonjs/i18n/strings/es.js +75 -0
  26. package/lib/commonjs/i18n/strings/es.js.map +1 -0
  27. package/lib/commonjs/i18n/strings/fr.js +75 -0
  28. package/lib/commonjs/i18n/strings/fr.js.map +1 -0
  29. package/lib/commonjs/i18n/strings/hi.js +75 -0
  30. package/lib/commonjs/i18n/strings/hi.js.map +1 -0
  31. package/lib/commonjs/i18n/strings/it.js +75 -0
  32. package/lib/commonjs/i18n/strings/it.js.map +1 -0
  33. package/lib/commonjs/i18n/strings/ja.js +75 -0
  34. package/lib/commonjs/i18n/strings/ja.js.map +1 -0
  35. package/lib/commonjs/i18n/strings/ko.js +75 -0
  36. package/lib/commonjs/i18n/strings/ko.js.map +1 -0
  37. package/lib/commonjs/i18n/strings/nl.js +75 -0
  38. package/lib/commonjs/i18n/strings/nl.js.map +1 -0
  39. package/lib/commonjs/i18n/strings/pl.js +75 -0
  40. package/lib/commonjs/i18n/strings/pl.js.map +1 -0
  41. package/lib/commonjs/i18n/strings/pt.js +75 -0
  42. package/lib/commonjs/i18n/strings/pt.js.map +1 -0
  43. package/lib/commonjs/i18n/strings/ru.js +75 -0
  44. package/lib/commonjs/i18n/strings/ru.js.map +1 -0
  45. package/lib/commonjs/i18n/strings/tr.js +75 -0
  46. package/lib/commonjs/i18n/strings/tr.js.map +1 -0
  47. package/lib/commonjs/i18n/strings/zh.js +75 -0
  48. package/lib/commonjs/i18n/strings/zh.js.map +1 -0
  49. package/lib/commonjs/index.js +38 -0
  50. package/lib/commonjs/index.js.map +1 -1
  51. package/lib/commonjs/push.js +78 -3
  52. package/lib/commonjs/push.js.map +1 -1
  53. package/lib/commonjs/review.js +54 -0
  54. package/lib/commonjs/review.js.map +1 -0
  55. package/lib/commonjs/theme.js +142 -23
  56. package/lib/commonjs/theme.js.map +1 -1
  57. package/lib/commonjs/types.js +32 -3
  58. package/lib/commonjs/types.js.map +1 -1
  59. package/lib/commonjs/useSupportThreads.js +41 -24
  60. package/lib/commonjs/useSupportThreads.js.map +1 -1
  61. package/lib/commonjs/utils.js +25 -30
  62. package/lib/commonjs/utils.js.map +1 -1
  63. package/lib/commonjs/version.js +13 -0
  64. package/lib/commonjs/version.js.map +1 -0
  65. package/lib/module/api.js +57 -10
  66. package/lib/module/api.js.map +1 -1
  67. package/lib/module/components/BottomSheet.js +1 -1
  68. package/lib/module/components/BottomSheet.js.map +1 -1
  69. package/lib/module/components/LauncherButton.js +5 -5
  70. package/lib/module/components/LauncherButton.js.map +1 -1
  71. package/lib/module/components/SupportButton.js +199 -73
  72. package/lib/module/components/SupportButton.js.map +1 -1
  73. package/lib/module/components/icons.js +115 -107
  74. package/lib/module/components/icons.js.map +1 -1
  75. package/lib/module/components/primitives.js +5 -147
  76. package/lib/module/components/primitives.js.map +1 -1
  77. package/lib/module/components/screens/ChatScreen.js +485 -0
  78. package/lib/module/components/screens/ChatScreen.js.map +1 -0
  79. package/lib/module/components/screens/LanguageScreen.js +147 -0
  80. package/lib/module/components/screens/LanguageScreen.js.map +1 -0
  81. package/lib/module/i18n/index.js +56 -0
  82. package/lib/module/i18n/index.js.map +1 -0
  83. package/lib/module/i18n/languages.js +88 -0
  84. package/lib/module/i18n/languages.js.map +1 -0
  85. package/lib/module/i18n/strings/de.js +71 -0
  86. package/lib/module/i18n/strings/de.js.map +1 -0
  87. package/lib/module/i18n/strings/en.js +87 -0
  88. package/lib/module/i18n/strings/en.js.map +1 -0
  89. package/lib/module/i18n/strings/es.js +71 -0
  90. package/lib/module/i18n/strings/es.js.map +1 -0
  91. package/lib/module/i18n/strings/fr.js +71 -0
  92. package/lib/module/i18n/strings/fr.js.map +1 -0
  93. package/lib/module/i18n/strings/hi.js +71 -0
  94. package/lib/module/i18n/strings/hi.js.map +1 -0
  95. package/lib/module/i18n/strings/it.js +71 -0
  96. package/lib/module/i18n/strings/it.js.map +1 -0
  97. package/lib/module/i18n/strings/ja.js +71 -0
  98. package/lib/module/i18n/strings/ja.js.map +1 -0
  99. package/lib/module/i18n/strings/ko.js +71 -0
  100. package/lib/module/i18n/strings/ko.js.map +1 -0
  101. package/lib/module/i18n/strings/nl.js +71 -0
  102. package/lib/module/i18n/strings/nl.js.map +1 -0
  103. package/lib/module/i18n/strings/pl.js +71 -0
  104. package/lib/module/i18n/strings/pl.js.map +1 -0
  105. package/lib/module/i18n/strings/pt.js +71 -0
  106. package/lib/module/i18n/strings/pt.js.map +1 -0
  107. package/lib/module/i18n/strings/ru.js +71 -0
  108. package/lib/module/i18n/strings/ru.js.map +1 -0
  109. package/lib/module/i18n/strings/tr.js +71 -0
  110. package/lib/module/i18n/strings/tr.js.map +1 -0
  111. package/lib/module/i18n/strings/zh.js +71 -0
  112. package/lib/module/i18n/strings/zh.js.map +1 -0
  113. package/lib/module/index.js +2 -0
  114. package/lib/module/index.js.map +1 -1
  115. package/lib/module/push.js +77 -3
  116. package/lib/module/push.js.map +1 -1
  117. package/lib/module/review.js +48 -0
  118. package/lib/module/review.js.map +1 -0
  119. package/lib/module/theme.js +141 -23
  120. package/lib/module/theme.js.map +1 -1
  121. package/lib/module/types.js +32 -3
  122. package/lib/module/types.js.map +1 -1
  123. package/lib/module/useSupportThreads.js +41 -24
  124. package/lib/module/useSupportThreads.js.map +1 -1
  125. package/lib/module/utils.js +24 -29
  126. package/lib/module/utils.js.map +1 -1
  127. package/lib/module/version.js +9 -0
  128. package/lib/module/version.js.map +1 -0
  129. package/lib/typescript/api.d.ts +40 -10
  130. package/lib/typescript/api.d.ts.map +1 -1
  131. package/lib/typescript/components/SupportButton.d.ts +2 -2
  132. package/lib/typescript/components/SupportButton.d.ts.map +1 -1
  133. package/lib/typescript/components/icons.d.ts +10 -14
  134. package/lib/typescript/components/icons.d.ts.map +1 -1
  135. package/lib/typescript/components/primitives.d.ts +3 -30
  136. package/lib/typescript/components/primitives.d.ts.map +1 -1
  137. package/lib/typescript/components/screens/ChatScreen.d.ts +21 -0
  138. package/lib/typescript/components/screens/ChatScreen.d.ts.map +1 -0
  139. package/lib/typescript/components/screens/LanguageScreen.d.ts +30 -0
  140. package/lib/typescript/components/screens/LanguageScreen.d.ts.map +1 -0
  141. package/lib/typescript/i18n/index.d.ts +15 -0
  142. package/lib/typescript/i18n/index.d.ts.map +1 -0
  143. package/lib/typescript/i18n/languages.d.ts +36 -0
  144. package/lib/typescript/i18n/languages.d.ts.map +1 -0
  145. package/lib/typescript/i18n/strings/de.d.ts +3 -0
  146. package/lib/typescript/i18n/strings/de.d.ts.map +1 -0
  147. package/lib/typescript/i18n/strings/en.d.ts +86 -0
  148. package/lib/typescript/i18n/strings/en.d.ts.map +1 -0
  149. package/lib/typescript/i18n/strings/es.d.ts +3 -0
  150. package/lib/typescript/i18n/strings/es.d.ts.map +1 -0
  151. package/lib/typescript/i18n/strings/fr.d.ts +3 -0
  152. package/lib/typescript/i18n/strings/fr.d.ts.map +1 -0
  153. package/lib/typescript/i18n/strings/hi.d.ts +3 -0
  154. package/lib/typescript/i18n/strings/hi.d.ts.map +1 -0
  155. package/lib/typescript/i18n/strings/it.d.ts +3 -0
  156. package/lib/typescript/i18n/strings/it.d.ts.map +1 -0
  157. package/lib/typescript/i18n/strings/ja.d.ts +3 -0
  158. package/lib/typescript/i18n/strings/ja.d.ts.map +1 -0
  159. package/lib/typescript/i18n/strings/ko.d.ts +3 -0
  160. package/lib/typescript/i18n/strings/ko.d.ts.map +1 -0
  161. package/lib/typescript/i18n/strings/nl.d.ts +3 -0
  162. package/lib/typescript/i18n/strings/nl.d.ts.map +1 -0
  163. package/lib/typescript/i18n/strings/pl.d.ts +3 -0
  164. package/lib/typescript/i18n/strings/pl.d.ts.map +1 -0
  165. package/lib/typescript/i18n/strings/pt.d.ts +3 -0
  166. package/lib/typescript/i18n/strings/pt.d.ts.map +1 -0
  167. package/lib/typescript/i18n/strings/ru.d.ts +3 -0
  168. package/lib/typescript/i18n/strings/ru.d.ts.map +1 -0
  169. package/lib/typescript/i18n/strings/tr.d.ts +3 -0
  170. package/lib/typescript/i18n/strings/tr.d.ts.map +1 -0
  171. package/lib/typescript/i18n/strings/zh.d.ts +3 -0
  172. package/lib/typescript/i18n/strings/zh.d.ts.map +1 -0
  173. package/lib/typescript/index.d.ts +4 -2
  174. package/lib/typescript/index.d.ts.map +1 -1
  175. package/lib/typescript/push.d.ts +14 -2
  176. package/lib/typescript/push.d.ts.map +1 -1
  177. package/lib/typescript/review.d.ts +15 -0
  178. package/lib/typescript/review.d.ts.map +1 -0
  179. package/lib/typescript/theme.d.ts +23 -5
  180. package/lib/typescript/theme.d.ts.map +1 -1
  181. package/lib/typescript/types.d.ts +86 -13
  182. package/lib/typescript/types.d.ts.map +1 -1
  183. package/lib/typescript/useSupportThreads.d.ts +20 -4
  184. package/lib/typescript/useSupportThreads.d.ts.map +1 -1
  185. package/lib/typescript/utils.d.ts +8 -6
  186. package/lib/typescript/utils.d.ts.map +1 -1
  187. package/lib/typescript/version.d.ts +7 -0
  188. package/lib/typescript/version.d.ts.map +1 -0
  189. package/package.json +2 -2
  190. package/src/api.ts +75 -23
  191. package/src/components/BottomSheet.tsx +1 -1
  192. package/src/components/LauncherButton.tsx +4 -4
  193. package/src/components/SupportButton.tsx +244 -86
  194. package/src/components/icons.tsx +96 -101
  195. package/src/components/primitives.tsx +9 -161
  196. package/src/components/screens/ChatScreen.tsx +541 -0
  197. package/src/components/screens/LanguageScreen.tsx +172 -0
  198. package/src/i18n/index.ts +81 -0
  199. package/src/i18n/languages.ts +106 -0
  200. package/src/i18n/strings/de.ts +81 -0
  201. package/src/i18n/strings/en.ts +97 -0
  202. package/src/i18n/strings/es.ts +80 -0
  203. package/src/i18n/strings/fr.ts +81 -0
  204. package/src/i18n/strings/hi.ts +80 -0
  205. package/src/i18n/strings/it.ts +80 -0
  206. package/src/i18n/strings/ja.ts +80 -0
  207. package/src/i18n/strings/ko.ts +79 -0
  208. package/src/i18n/strings/nl.ts +80 -0
  209. package/src/i18n/strings/pl.ts +80 -0
  210. package/src/i18n/strings/pt.ts +80 -0
  211. package/src/i18n/strings/ru.ts +80 -0
  212. package/src/i18n/strings/tr.ts +80 -0
  213. package/src/i18n/strings/zh.ts +78 -0
  214. package/src/index.tsx +13 -0
  215. package/src/push.ts +100 -2
  216. package/src/review.ts +54 -0
  217. package/src/theme.ts +182 -28
  218. package/src/types.ts +85 -13
  219. package/src/useSupportThreads.ts +61 -28
  220. package/src/utils.ts +27 -29
  221. package/src/version.ts +6 -0
  222. package/lib/commonjs/components/screens/ComposeScreen.js +0 -228
  223. package/lib/commonjs/components/screens/ComposeScreen.js.map +0 -1
  224. package/lib/commonjs/components/screens/HomeScreen.js +0 -286
  225. package/lib/commonjs/components/screens/HomeScreen.js.map +0 -1
  226. package/lib/commonjs/components/screens/ThreadScreen.js +0 -327
  227. package/lib/commonjs/components/screens/ThreadScreen.js.map +0 -1
  228. package/lib/module/components/screens/ComposeScreen.js +0 -224
  229. package/lib/module/components/screens/ComposeScreen.js.map +0 -1
  230. package/lib/module/components/screens/HomeScreen.js +0 -282
  231. package/lib/module/components/screens/HomeScreen.js.map +0 -1
  232. package/lib/module/components/screens/ThreadScreen.js +0 -325
  233. package/lib/module/components/screens/ThreadScreen.js.map +0 -1
  234. package/lib/typescript/components/screens/ComposeScreen.d.ts +0 -10
  235. package/lib/typescript/components/screens/ComposeScreen.d.ts.map +0 -1
  236. package/lib/typescript/components/screens/HomeScreen.d.ts +0 -14
  237. package/lib/typescript/components/screens/HomeScreen.d.ts.map +0 -1
  238. package/lib/typescript/components/screens/ThreadScreen.d.ts +0 -10
  239. package/lib/typescript/components/screens/ThreadScreen.d.ts.map +0 -1
  240. package/src/components/screens/ComposeScreen.tsx +0 -233
  241. package/src/components/screens/HomeScreen.tsx +0 -287
  242. package/src/components/screens/ThreadScreen.tsx +0 -397
@@ -0,0 +1,78 @@
1
+ import type { StringTable } from './en';
2
+
3
+ export const zh: StringTable = {
4
+ 'home.title': '客服支持',
5
+ 'home.subtitle': '发起一次对话 —— 我们就在这里回复你。',
6
+ 'home.close': '关闭客服',
7
+ 'home.open': '进行中',
8
+ 'home.resolved': '已解决',
9
+ 'home.empty': '还没有对话',
10
+ 'home.emptyHint': '你发送的内容都会送到团队,他们的回复也会回到这个窗口。',
11
+ 'home.noMessages': '还没有消息',
12
+ 'home.you': '你',
13
+ 'home.threadA11y': '对话:{type}',
14
+ 'home.threadUnreadA11y': '对话:{type},{count} 条未读',
15
+ 'home.newA11y': '新建:{type}',
16
+ 'home.language': '语言',
17
+
18
+ 'type.feedback': '反馈',
19
+ 'type.feature_request': '功能请求',
20
+ 'type.bug_report': '错误报告',
21
+ 'hint.feedback': '告诉我们你的想法',
22
+ 'hint.feature_request': '提出一个改进建议',
23
+ 'hint.bug_report': '有功能无法正常使用',
24
+ 'prompt.feedback': '有什么想让我们知道的?',
25
+ 'prompt.feature_request': '你希望看到什么?',
26
+ 'prompt.bug_report': '发生了什么,你期待的结果是什么?',
27
+ 'sub.feedback': '好评差评都会直接送到团队。',
28
+ 'sub.feature_request': '告诉我们你想完成什么。',
29
+ 'sub.bug_report': '操作步骤、所在页面和你的预期都很有帮助。',
30
+
31
+ 'compose.back': '返回对话列表',
32
+ 'compose.sent': '已发送',
33
+ 'compose.sentHint':
34
+ '我们会在这里回复。对话会出现在「进行中」,我们回复后按钮上会显示提示。',
35
+ 'compose.done': '完成',
36
+ 'compose.send': '发送',
37
+ 'compose.sending': '发送中…',
38
+ 'compose.minChars': '至少输入 {count} 个字符',
39
+
40
+ 'thread.support': '客服支持',
41
+ 'thread.new': '新消息',
42
+ 'thread.resolvedAt': '已解决 · {date}',
43
+ 'thread.readOnly': '此对话已解决,仅供查看',
44
+ 'thread.placeholder': '写下回复…',
45
+ 'chat.placeholder': '输入消息…',
46
+ 'review.appStore': '在 App Store 评分',
47
+ 'review.playStore': '在 Google Play 评分',
48
+ 'thread.sendA11y': '发送回复',
49
+ 'thread.sendingA11y': '发送中',
50
+ 'thread.translating': '翻译中…',
51
+
52
+ 'status.open': '进行中',
53
+ 'status.resolved': '已解决',
54
+
55
+ 'error.tryAgain': '重试',
56
+ 'error.rateLimited': '请求过于频繁 —— 请稍后再试',
57
+ 'error.offline': '你已离线 —— 请检查网络连接',
58
+ 'error.sendFailed': '发送失败 —— 请重试',
59
+ 'error.loadFailed': '无法加载你的对话',
60
+ 'error.unavailable': '客服支持暂时不可用',
61
+ 'error.loadRateLimited': '请求过于频繁 —— 请稍等片刻再试',
62
+
63
+ 'lang.title': '选择你的语言',
64
+ 'lang.subtitle': '用你习惯的语言书写 —— 我们会在你和客服团队之间翻译。',
65
+ 'lang.continue': '继续',
66
+ 'lang.change': '更改语言',
67
+ 'lang.saveFailed': '保存失败 —— 请重试',
68
+
69
+ 'time.justNow': '刚刚',
70
+ 'time.minutes': '{count} 分钟前',
71
+ 'time.hours': '{count} 小时前',
72
+ 'time.days': '{count} 天前',
73
+ 'time.weeks': '{count} 周前',
74
+ 'time.months': '{count} 个月前',
75
+ 'time.years': '{count} 年前',
76
+ 'time.today': '今天',
77
+ 'time.yesterday': '昨天',
78
+ };
package/src/index.tsx CHANGED
@@ -3,11 +3,22 @@ export {
3
3
  supportDarkTheme,
4
4
  supportLightTheme,
5
5
  resolveTheme,
6
+ type SupportColors,
6
7
  type SupportTheme,
7
8
  } from './theme';
8
9
  export { SupportApiError } from './api';
10
+ export { SDK_VERSION } from './version';
9
11
  export { isPushAvailable } from './push';
12
+ export {
13
+ DEFAULT_LANGUAGE,
14
+ deviceLanguage,
15
+ isSupportedLanguage,
16
+ LANGUAGE_LABELS,
17
+ SUPPORTED_LANGUAGES,
18
+ type Language,
19
+ } from './i18n/languages';
10
20
  export type {
21
+ AccentColor,
11
22
  LauncherVariant,
12
23
  MessageSender,
13
24
  PushPermissionStatus,
@@ -19,6 +30,8 @@ export type {
19
30
  ThreadMessage,
20
31
  ThreadsResponse,
21
32
  ThemeName,
33
+ ThemePreference,
34
+ UserPlan,
22
35
  } from './types';
23
36
  export {
24
37
  QUERY_TYPE_LABEL,
package/src/push.ts CHANGED
@@ -12,6 +12,17 @@
12
12
 
13
13
  import type { PushPermissionStatus } from './types';
14
14
 
15
+ /** The slice of a NotificationResponse that tap handling reads. */
16
+ interface NotificationResponse {
17
+ actionIdentifier: string;
18
+ notification: {
19
+ request: {
20
+ identifier: string;
21
+ content: { data?: Record<string, unknown> | null };
22
+ };
23
+ };
24
+ }
25
+
15
26
  /** The slice of expo-notifications this SDK uses. */
16
27
  interface ExpoNotificationsModule {
17
28
  getPermissionsAsync(): Promise<{ status: string; canAskAgain: boolean }>;
@@ -19,6 +30,11 @@ interface ExpoNotificationsModule {
19
30
  getExpoPushTokenAsync(options?: {
20
31
  projectId?: string;
21
32
  }): Promise<{ data: string }>;
33
+ addNotificationResponseReceivedListener(
34
+ listener: (response: NotificationResponse) => void,
35
+ ): { remove(): void };
36
+ getLastNotificationResponseAsync(): Promise<NotificationResponse | null>;
37
+ DEFAULT_ACTION_IDENTIFIER?: string;
22
38
  }
23
39
 
24
40
  function loadNotifications(): ExpoNotificationsModule | null {
@@ -51,13 +67,16 @@ function normalizeStatus(status: string): PushPermissionStatus {
51
67
 
52
68
  /**
53
69
  * Ensures notification permission has been requested, and returns the
54
- * outcome plus an Expo push token when one is obtainable.
70
+ * outcome plus an Expo push token when one is obtainable. With
71
+ * `prompt: false` it only reads the current state — for refreshing the token
72
+ * at launch without ever showing the OS prompt outside the support sheet.
55
73
  *
56
74
  * Never throws: any failure resolves to an 'undetermined' registration so
57
75
  * callers can report it and move on.
58
76
  */
59
77
  export async function ensurePushPermission(
60
78
  expoProjectId?: string,
79
+ { prompt = true }: { prompt?: boolean } = {},
61
80
  ): Promise<PushRegistration> {
62
81
  if (!notifications) {
63
82
  return { status: 'undetermined', asked: false, token: null };
@@ -70,7 +89,7 @@ export async function ensurePushPermission(
70
89
 
71
90
  // Only prompt when the OS will actually show something. Re-prompting a
72
91
  // user who already decided is impossible on iOS and annoying on Android.
73
- if (status === 'undetermined' && current.canAskAgain) {
92
+ if (prompt && status === 'undetermined' && current.canAskAgain) {
74
93
  const requested = await notifications.requestPermissionsAsync();
75
94
  status = normalizeStatus(requested.status);
76
95
  asked = true;
@@ -95,3 +114,82 @@ export async function ensurePushPermission(
95
114
  return { status: 'undetermined', asked: false, token: null };
96
115
  }
97
116
  }
117
+
118
+ // ---------- opening the thread from a tapped notification ----------
119
+ //
120
+ // send-push tags every support reply with `{ type: 'support_reply',
121
+ // query_id }`. Tapping one should land the user in that thread, not wherever
122
+ // the host app happens to open.
123
+ //
124
+ // The observer starts when this module loads rather than when a launcher
125
+ // mounts, for two reasons: a cold start's tap is only reported once, early,
126
+ // and a host app may mount the launcher later (behind auth, on a settings
127
+ // screen). A tap seen before any launcher is listening is held for
128
+ // PENDING_TAP_TTL_MS and then dropped — opening the sheet minutes after the
129
+ // tap, the first time the user wanders onto that screen, would be a surprise.
130
+
131
+ const PENDING_TAP_TTL_MS = 60_000;
132
+
133
+ type SupportTapListener = (threadId: string) => void;
134
+
135
+ const tapListeners: SupportTapListener[] = [];
136
+ let pendingTap: { threadId: string; at: number } | null = null;
137
+ // Both the listener and getLastNotificationResponseAsync can report the same
138
+ // cold-start tap, and the latter keeps reporting it for the life of the
139
+ // process. Each tap is handled once.
140
+ const handledTaps = new Set<string>();
141
+
142
+ function supportReplyThreadId(response: NotificationResponse): string | null {
143
+ const defaultAction = notifications?.DEFAULT_ACTION_IDENTIFIER;
144
+ if (defaultAction && response.actionIdentifier !== defaultAction) return null;
145
+ const data = response.notification?.request?.content?.data;
146
+ if (data?.type !== 'support_reply') return null;
147
+ return typeof data.query_id === 'string' ? data.query_id : null;
148
+ }
149
+
150
+ function handleResponse(response: NotificationResponse | null) {
151
+ if (!response) return;
152
+ const threadId = supportReplyThreadId(response);
153
+ const tapId = response.notification?.request?.identifier;
154
+ if (threadId === null || !tapId || handledTaps.has(tapId)) return;
155
+ handledTaps.add(tapId);
156
+
157
+ // One sheet, not one per mounted launcher: the newest launcher takes it.
158
+ const listener = tapListeners[tapListeners.length - 1];
159
+ if (listener) listener(threadId);
160
+ else pendingTap = { threadId, at: Date.now() };
161
+ }
162
+
163
+ if (notifications) {
164
+ try {
165
+ notifications.addNotificationResponseReceivedListener(handleResponse);
166
+ notifications
167
+ .getLastNotificationResponseAsync()
168
+ .then(handleResponse)
169
+ .catch(() => {});
170
+ } catch {
171
+ // Same contract as the rest of this file: push never breaks support.
172
+ }
173
+ }
174
+
175
+ /**
176
+ * Calls `listener` with the thread id whenever the user taps a support-reply
177
+ * notification — including, once, a tap from the last minute that arrived
178
+ * before anything was listening. Returns an unsubscribe function.
179
+ */
180
+ export function onSupportNotificationTap(
181
+ listener: SupportTapListener,
182
+ ): () => void {
183
+ tapListeners.push(listener);
184
+
185
+ const pending = pendingTap;
186
+ pendingTap = null;
187
+ if (pending && Date.now() - pending.at < PENDING_TAP_TTL_MS) {
188
+ listener(pending.threadId);
189
+ }
190
+
191
+ return () => {
192
+ const index = tapListeners.lastIndexOf(listener);
193
+ if (index !== -1) tapListeners.splice(index, 1);
194
+ };
195
+ }
package/src/review.ts ADDED
@@ -0,0 +1,54 @@
1
+ // Review requests: a support reply with a "Rate on the App Store / Google
2
+ // Play" button. The button opens the store's write-a-review page — the store
3
+ // app where there is one, its website otherwise. It is a link, not a prompt:
4
+ // Apple's guidelines reserve in-app rating prompts for SKStoreReviewController,
5
+ // and linking to the review page is what they document for everything else.
6
+
7
+ import { Linking, Platform } from 'react-native';
8
+ import type { StoreListing } from './types';
9
+
10
+ interface StoreLinks {
11
+ /** Opens the store app. */
12
+ app: string;
13
+ /** The same page on the web, if the store app won't open. */
14
+ web: string;
15
+ }
16
+
17
+ /** Links for this device's store, or null when the team hasn't set one up. */
18
+ export function storeLinks(store: StoreListing | null | undefined): StoreLinks | null {
19
+ if (Platform.OS === 'ios' && store?.app_store_id) {
20
+ const id = encodeURIComponent(store.app_store_id);
21
+ return {
22
+ app: `itms-apps://apps.apple.com/app/id${id}?action=write-review`,
23
+ web: `https://apps.apple.com/app/id${id}?action=write-review`,
24
+ };
25
+ }
26
+ if (Platform.OS === 'android' && store?.play_store_package) {
27
+ const pkg = encodeURIComponent(store.play_store_package);
28
+ return {
29
+ app: `market://details?id=${pkg}&showAllReviews=true`,
30
+ web: `https://play.google.com/store/apps/details?id=${pkg}&showAllReviews=true`,
31
+ };
32
+ }
33
+ return null;
34
+ }
35
+
36
+ /** Opens the review page; resolves false if neither link would open. */
37
+ export async function openStoreReview(links: StoreLinks): Promise<boolean> {
38
+ try {
39
+ await Linking.openURL(links.app);
40
+ return true;
41
+ } catch {
42
+ try {
43
+ await Linking.openURL(links.web);
44
+ return true;
45
+ } catch {
46
+ return false;
47
+ }
48
+ }
49
+ }
50
+
51
+ /** The platform the backend should know this user by, if it's a store one. */
52
+ export function storePlatform(): 'ios' | 'android' | undefined {
53
+ return Platform.OS === 'ios' || Platform.OS === 'android' ? Platform.OS : undefined;
54
+ }
package/src/theme.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  // The SDK consumes the same design tokens as the admin dashboard, so both
2
2
  // surfaces look like one product. On top of those it adds the few values
3
- // that only exist on mobile: sheet/bubble radii and the elevation used by
4
- // the launcher and the sheet (the web side gets those from CSS).
3
+ // that only exist on mobile: sheet/bubble radii, the elevation used by the
4
+ // launcher and the sheet (the web side gets those from CSS), and a re-cut of
5
+ // the surfaces and text ramp for a sheet held at arm's length (see
6
+ // SHEET_OVERRIDES).
5
7
  import {
6
8
  darkColors,
7
9
  lightColors,
@@ -11,7 +13,7 @@ import {
11
13
  type ThemeColors,
12
14
  } from '@appsupportkit/design-tokens';
13
15
  import type { ViewStyle } from 'react-native';
14
- import type { ThemeName } from './types';
16
+ import type { AccentColor, ThemeName } from './types';
15
17
 
16
18
  /** Rounder than the dashboard: touch targets read better with more radius. */
17
19
  export const supportRadii = {
@@ -27,6 +29,17 @@ export const supportRadii = {
27
29
  pill: 999,
28
30
  } as const;
29
31
 
32
+ export interface SupportColors extends ThemeColors {
33
+ /** The sheet's own background — the layer every screen is drawn on. */
34
+ sheet: string;
35
+ /**
36
+ * The accent where it is small text — status labels, the "New" divider.
37
+ * The fill color can sit at 3:1; text needs 4.5:1 on the sheet and on the
38
+ * cards over it, so this is the accent nudged as far as that takes.
39
+ */
40
+ accentText: string;
41
+ }
42
+
30
43
  export interface SupportShadows {
31
44
  /** Floating launcher button. */
32
45
  launcher: ViewStyle;
@@ -52,7 +65,7 @@ export interface LauncherPalette {
52
65
 
53
66
  export interface SupportTheme {
54
67
  name: ThemeName;
55
- colors: ThemeColors;
68
+ colors: SupportColors;
56
69
  spacing: typeof spacing;
57
70
  radii: typeof supportRadii;
58
71
  motion: typeof motion;
@@ -63,9 +76,15 @@ export interface SupportTheme {
63
76
  // Color helpers come first: the themes below are built at module load, so
64
77
  // anything they reach for has to already be initialized. (A `const` used
65
78
  // before its definition survives tsc but lands as `undefined` on Hermes.)
79
+ type Rgb = [number, number, number];
80
+
66
81
  const HEX = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i;
82
+ const WHITE: Rgb = [255, 255, 255];
83
+ /** Foreground for light accents — the dashboard's near-black, not pure black. */
84
+ const INK = '#111113';
85
+ const INK_RGB: Rgb = [17, 17, 19];
67
86
 
68
- function parseHex(color: string): [number, number, number] | null {
87
+ function parseHex(color: string): Rgb | null {
69
88
  const match = HEX.exec(color.trim());
70
89
  const digits = match?.[1];
71
90
  if (digits === undefined) return null;
@@ -83,11 +102,94 @@ function parseHex(color: string): [number, number, number] | null {
83
102
  ];
84
103
  }
85
104
 
86
- function mix([r, g, b]: [number, number, number], target: number, amount: number) {
105
+ function toHex(rgb: Rgb): string {
106
+ return `#${rgb.map((c) => c.toString(16).padStart(2, '0')).join('').toUpperCase()}`;
107
+ }
108
+
109
+ function mixRgb([r, g, b]: Rgb, target: number, amount: number): Rgb {
87
110
  const channel = (c: number) => Math.round(c + (target - c) * amount);
88
- return `rgb(${channel(r)}, ${channel(g)}, ${channel(b)})`;
111
+ return [channel(r), channel(g), channel(b)];
112
+ }
113
+
114
+ function mix(rgb: Rgb, target: number, amount: number): string {
115
+ return toHex(mixRgb(rgb, target, amount));
116
+ }
117
+
118
+ /** WCAG relative luminance. */
119
+ function luminance(rgb: Rgb): number {
120
+ const [r, g, b] = rgb.map((c) => {
121
+ const s = c / 255;
122
+ return s <= 0.03928 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
123
+ }) as Rgb;
124
+ return 0.2126 * r + 0.7152 * g + 0.0722 * b;
125
+ }
126
+
127
+ /** WCAG contrast ratio, 1–21. */
128
+ function contrast(a: Rgb, b: Rgb): number {
129
+ const [hi, lo] = [luminance(a), luminance(b)].sort((x, y) => y - x) as [
130
+ number,
131
+ number,
132
+ ];
133
+ return (hi + 0.05) / (lo + 0.05);
134
+ }
135
+
136
+ /**
137
+ * Nudges `color` toward white (dark theme) or black (light theme) in 5%
138
+ * steps until it reaches `ratio` against every background. The smallest
139
+ * step that works wins, so a brand color stays recognizably itself.
140
+ */
141
+ function legible(
142
+ color: string,
143
+ backgrounds: string[],
144
+ ratio: number,
145
+ name: ThemeName,
146
+ ): string {
147
+ const rgb = parseHex(color);
148
+ if (rgb === null) return color;
149
+ const against = backgrounds
150
+ .map(parseHex)
151
+ .filter((c): c is Rgb => c !== null);
152
+ const target = name === 'dark' ? 255 : 0;
153
+ for (let step = 0; step <= 20; step += 1) {
154
+ const candidate = mixRgb(rgb, target, step * 0.05);
155
+ if (against.every((bg) => contrast(candidate, bg) >= ratio)) {
156
+ return toHex(candidate);
157
+ }
158
+ }
159
+ return name === 'dark' ? '#FFFFFF' : '#000000';
89
160
  }
90
161
 
162
+ /**
163
+ * Where the SDK departs from the dashboard tokens.
164
+ *
165
+ * Dark: the sheet floats over the host app, so it takes an elevated gray the
166
+ * way iOS sheets do, and the cards and bubbles on it step lighter again. On
167
+ * the dashboard's near-black base, cards sat 1.05:1 from the background and
168
+ * the layering disappeared.
169
+ *
170
+ * Both: the text ramp is re-cut so every step clears WCAG AA (4.5:1) on the
171
+ * sheet and on the cards over it. Tertiary carries timestamps and labels at
172
+ * 11–12px and was 3.1:1 (dark) and 2.5:1 (light); secondary moves too, so
173
+ * the two stay a visible step apart.
174
+ */
175
+ const SHEET_OVERRIDES: Record<ThemeName, Partial<SupportColors>> = {
176
+ dark: {
177
+ sheet: '#161618',
178
+ surface: '#1F1F23',
179
+ surfaceHover: '#26262B',
180
+ surfaceActive: '#2D2D33',
181
+ border: '#2E2E35',
182
+ borderStrong: '#3C3C44',
183
+ textSecondary: '#A3A3AB', // 6.5:1 on surface
184
+ textTertiary: '#87878F', // 4.6:1 on surface, 5.1:1 on sheet
185
+ },
186
+ light: {
187
+ sheet: lightColors.bg,
188
+ textSecondary: '#5A5A62', // 6.5:1 on sheet
189
+ textTertiary: '#717179', // 4.6:1 on sheet, 4.8:1 on surface
190
+ },
191
+ };
192
+
91
193
  function shadowsFor(name: ThemeName, accent: string): SupportShadows {
92
194
  const dark = name === 'dark';
93
195
  return {
@@ -129,7 +231,21 @@ function launcherFor(name: ThemeName, accent: string): LauncherPalette {
129
231
  };
130
232
  }
131
233
 
132
- function buildTheme(name: ThemeName, colors: ThemeColors): SupportTheme {
234
+ function buildTheme(name: ThemeName, tokens: ThemeColors): SupportTheme {
235
+ const base = {
236
+ ...tokens,
237
+ ...SHEET_OVERRIDES[name],
238
+ } as SupportColors;
239
+ // Status tones double as 12px labels, so they get the text bar too.
240
+ const onSheet = [base.sheet, base.surface];
241
+ const colors: SupportColors = {
242
+ ...base,
243
+ statusOpen: legible(base.statusOpen, onSheet, 4.5, name),
244
+ statusProgress: legible(base.statusProgress, onSheet, 4.5, name),
245
+ statusResolved: legible(base.statusResolved, onSheet, 4.5, name),
246
+ statusDanger: legible(base.statusDanger, onSheet, 4.5, name),
247
+ accentText: legible(base.accent, onSheet, 4.5, name),
248
+ };
133
249
  return {
134
250
  name,
135
251
  colors,
@@ -146,41 +262,79 @@ export const supportLightTheme: SupportTheme = buildTheme('light', lightColors);
146
262
 
147
263
  /**
148
264
  * Derives the accent family from a single brand color: a pressed shade, the
149
- * 12% wash used behind chips and own-message bubbles, and a foreground that
150
- * stays legible on top (dark text on light brands, white on dark ones).
265
+ * 12% wash used behind chips, a text-safe variant, and whichever of white or
266
+ * ink reads better on top of it.
267
+ *
268
+ * `adapt` is for a color that has to serve both themes: it is lifted just
269
+ * far enough to read as a fill (3:1, the WCAG bar for UI components) on this
270
+ * theme's sheet — a navy brand would otherwise vanish in dark mode. A color
271
+ * given for this mode specifically is used as is.
151
272
  */
152
- function withAccent(theme: SupportTheme, accent: string): SupportTheme {
153
- const rgb = parseHex(accent);
154
- if (!rgb) return theme;
273
+ function withAccent(
274
+ theme: SupportTheme,
275
+ accent: string,
276
+ adapt: boolean,
277
+ ): SupportTheme {
278
+ if (parseHex(accent) === null) return theme;
279
+ const { name } = theme;
280
+ const fill = adapt
281
+ ? legible(accent, [theme.colors.sheet], 3, name)
282
+ : toHex(parseHex(accent) as Rgb);
283
+ const rgb = parseHex(fill) as Rgb;
155
284
  const [r, g, b] = rgb;
156
- // Relative luminance, sRGB coefficients — good enough to pick a foreground.
157
- const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
158
- const colors: ThemeColors = {
285
+ const accentText = legible(
286
+ fill,
287
+ [theme.colors.sheet, theme.colors.surface],
288
+ 4.5,
289
+ name,
290
+ );
291
+ const colors: SupportColors = {
159
292
  ...theme.colors,
160
- accent,
161
- accentHover: mix(rgb, theme.name === 'dark' ? 255 : 0, 0.12),
293
+ accent: fill,
294
+ accentHover: mix(rgb, name === 'dark' ? 255 : 0, 0.12),
162
295
  accentMuted: `rgba(${r}, ${g}, ${b}, 0.12)`,
163
- accentForeground: luminance > 0.62 ? '#111113' : '#FFFFFF',
164
- statusOpen: accent,
296
+ accentForeground:
297
+ contrast(rgb, WHITE) >= contrast(rgb, INK_RGB) ? '#FFFFFF' : INK,
298
+ accentText,
299
+ statusOpen: accentText,
165
300
  statusOpenBg: `rgba(${r}, ${g}, ${b}, 0.10)`,
166
- focusRing: accent,
301
+ focusRing: fill,
167
302
  };
168
303
  return {
169
304
  ...theme,
170
305
  colors,
171
- shadows: shadowsFor(theme.name, accent),
172
- launcher: launcherFor(theme.name, accent),
306
+ shadows: shadowsFor(name, fill),
307
+ launcher: launcherFor(name, fill),
173
308
  };
174
309
  }
175
310
 
176
311
  /**
177
- * @param name "light" | "dark" (default dark).
178
- * @param accentColor Optional brand color (hex) replacing the default accent.
312
+ * The theme for one resolved mode. `accent` is the color for this mode
313
+ * (already picked from a light/dark pair), and `adapt` says whether it was a
314
+ * single color that has to be made to work here.
315
+ */
316
+ export function themeFor(
317
+ name: ThemeName,
318
+ accent: string | undefined,
319
+ adapt: boolean,
320
+ ): SupportTheme {
321
+ const base = name === 'light' ? supportLightTheme : supportDarkTheme;
322
+ return accent ? withAccent(base, accent, adapt) : base;
323
+ }
324
+
325
+ /**
326
+ * @param name "light" | "dark" (default dark). SupportButton resolves its
327
+ * "system" default before calling this.
328
+ * @param accentColor Optional brand color: one hex for both modes (adjusted
329
+ * per mode where needed), or a `{ light, dark }` pair used as given.
179
330
  */
180
331
  export function resolveTheme(
181
332
  name: ThemeName | undefined,
182
- accentColor?: string,
333
+ accentColor?: AccentColor,
183
334
  ): SupportTheme {
184
- const base = name === 'light' ? supportLightTheme : supportDarkTheme;
185
- return accentColor ? withAccent(base, accentColor) : base;
335
+ const mode: ThemeName = name === 'light' ? 'light' : 'dark';
336
+ if (typeof accentColor === 'object' && accentColor !== null) {
337
+ return themeFor(mode, accentColor[mode], false);
338
+ }
339
+ return themeFor(mode, accentColor, true);
186
340
  }