@cometchat/skills 4.4.1 → 5.0.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 (489) hide show
  1. package/.claude-plugin/marketplace.json +55 -0
  2. package/.claude-plugin/plugin.json +14 -0
  3. package/CHANGELOG.md +36 -0
  4. package/README.md +41 -163
  5. package/RULES.md +114 -0
  6. package/bin/cometchat-skills.mjs +1180 -0
  7. package/bin/legacy-skills.json +95 -0
  8. package/catalogs/android-v6.json +1646 -0
  9. package/catalogs/flutter-v6.json +651 -0
  10. package/catalogs/ios-v5.json +1383 -0
  11. package/catalogs/rn-calls-v5.json +134 -0
  12. package/catalogs/rn-calls-v5.symbols.txt +58 -0
  13. package/catalogs/rn-sdk-v4.json +672 -0
  14. package/catalogs/rn-v5.json +449 -0
  15. package/catalogs/rn-v5.symbols.txt +216 -0
  16. package/catalogs/sdk-android-v5.json +514 -0
  17. package/contracts.android-calls-v5.json +122 -0
  18. package/contracts.android-v6.json +135 -0
  19. package/contracts.angular-v5.json +694 -0
  20. package/contracts.flutter-calls-v5.json +77 -0
  21. package/contracts.flutter-v6.json +126 -0
  22. package/contracts.ios-calls-v5.json +67 -0
  23. package/contracts.ios-v5.json +436 -0
  24. package/contracts.json +82 -0
  25. package/contracts.rn-calls-v5.json +77 -0
  26. package/contracts.rn-v5.json +727 -0
  27. package/contracts.sdk-android-v5.json +15 -0
  28. package/contracts.web-calls-v5.json +45 -0
  29. package/features.android-calls-v5.json +246 -0
  30. package/features.android-v6.json +65 -0
  31. package/features.angular-v5.json +521 -0
  32. package/features.flutter-calls-v5.json +286 -0
  33. package/features.flutter-v6.json +484 -0
  34. package/features.ios-calls-v5.json +236 -0
  35. package/features.ios-v5.json +573 -0
  36. package/features.json +61 -0
  37. package/features.rn-calls-v5.json +187 -0
  38. package/features.rn-v5.json +614 -0
  39. package/features.sdk-android-v5.json +40 -0
  40. package/features.sdk-jsv4.json +24 -0
  41. package/features.web-calls-v5.json +108 -0
  42. package/package.json +151 -74
  43. package/peers.yaml +312 -0
  44. package/registry/README.md +31 -0
  45. package/registry/android-calls-v5.json +54 -0
  46. package/registry/android-v6.json +137 -0
  47. package/registry/angular-v5.json +114 -0
  48. package/registry/flutter-calls-v5.json +54 -0
  49. package/registry/flutter-v6.json +119 -0
  50. package/registry/ios-calls-v5.json +59 -0
  51. package/registry/ios-v5.json +97 -0
  52. package/registry/rn-calls-v5.json +59 -0
  53. package/registry/rn-v5.json +129 -0
  54. package/registry/sdk-android-v5.json +53 -0
  55. package/registry/sdk-jsv4.json +53 -0
  56. package/registry/web-calls-v5.json +54 -0
  57. package/registry/web-v7.json +99 -0
  58. package/skills/cometchat/SKILL.md +42 -2096
  59. package/skills/cometchat-android-v5-calls-sdk/SKILL.md +206 -0
  60. package/skills/cometchat-android-v5-calls-sdk/references/build-truth.md +63 -0
  61. package/skills/cometchat-android-v5-calls-sdk/references/docs-map.md +119 -0
  62. package/skills/cometchat-android-v5-calls-sdk/references/method-map.md +53 -0
  63. package/skills/cometchat-android-v5-calls-sdk/references/pitfalls.md +72 -0
  64. package/skills/cometchat-android-v5-calls-sdk/references/ringing.md +92 -0
  65. package/skills/cometchat-android-v5-calls-sdk/references/user-switch.md +90 -0
  66. package/skills/cometchat-android-v5-sdk/SKILL.md +127 -0
  67. package/skills/cometchat-android-v5-sdk/references/app-surface.md +88 -0
  68. package/skills/cometchat-android-v5-sdk/references/docs-map.md +91 -0
  69. package/skills/cometchat-android-v6-builder-settings/SKILL.md +51 -137
  70. package/skills/cometchat-android-v6-calls/SKILL.md +128 -411
  71. package/skills/cometchat-android-v6-compose-components/SKILL.md +84 -194
  72. package/skills/cometchat-android-v6-compose-customization/SKILL.md +66 -411
  73. package/skills/cometchat-android-v6-compose-placement/SKILL.md +154 -237
  74. package/skills/cometchat-android-v6-core/SKILL.md +236 -672
  75. package/skills/cometchat-android-v6-core/references/anti-patterns.md +31 -0
  76. package/skills/cometchat-android-v6-core/references/component-props.md +168 -0
  77. package/skills/cometchat-android-v6-core/references/docs-map.md +153 -0
  78. package/skills/cometchat-android-v6-core/references/layout.md +112 -0
  79. package/skills/cometchat-android-v6-core/references/lifecycle.md +75 -0
  80. package/skills/cometchat-android-v6-core/references/setup-credentials.md +105 -0
  81. package/skills/cometchat-android-v6-core/references/troubleshooting.md +36 -0
  82. package/skills/cometchat-android-v6-events/SKILL.md +46 -184
  83. package/skills/cometchat-android-v6-extensions/SKILL.md +39 -179
  84. package/skills/cometchat-android-v6-features/SKILL.md +74 -143
  85. package/skills/cometchat-android-v6-kotlin-components/SKILL.md +75 -193
  86. package/skills/cometchat-android-v6-kotlin-customization/SKILL.md +67 -419
  87. package/skills/cometchat-android-v6-kotlin-placement/SKILL.md +77 -223
  88. package/skills/cometchat-android-v6-migration/SKILL.md +67 -378
  89. package/skills/cometchat-android-v6-production/SKILL.md +40 -179
  90. package/skills/cometchat-android-v6-push/SKILL.md +39 -289
  91. package/skills/cometchat-android-v6-testing/SKILL.md +50 -265
  92. package/skills/cometchat-android-v6-troubleshooting/SKILL.md +70 -254
  93. package/skills/cometchat-angular-v5-calls/SKILL.md +193 -0
  94. package/skills/cometchat-angular-v5-components/SKILL.md +131 -0
  95. package/skills/cometchat-angular-v5-components/references/catalog.md +111 -0
  96. package/skills/cometchat-angular-v5-components/references/host-composed.md +46 -0
  97. package/skills/cometchat-angular-v5-core/SKILL.md +300 -0
  98. package/skills/cometchat-angular-v5-core/references/anti-patterns.md +49 -0
  99. package/skills/cometchat-angular-v5-core/references/component-props.md +55 -0
  100. package/skills/cometchat-angular-v5-core/references/dependencies.md +66 -0
  101. package/skills/cometchat-angular-v5-core/references/docs-map.md +132 -0
  102. package/skills/cometchat-angular-v5-core/references/layout.md +64 -0
  103. package/skills/cometchat-angular-v5-core/references/lifecycle.md +202 -0
  104. package/skills/cometchat-angular-v5-core/references/setup-credentials.md +137 -0
  105. package/skills/cometchat-angular-v5-core/references/theming.md +70 -0
  106. package/skills/cometchat-angular-v5-core/references/troubleshooting.md +27 -0
  107. package/skills/cometchat-angular-v5-customization/SKILL.md +94 -0
  108. package/skills/cometchat-angular-v5-features/SKILL.md +107 -0
  109. package/skills/cometchat-angular-v5-features/references/custom-messages.md +133 -0
  110. package/skills/cometchat-angular-v5-features/references/formatters.md +28 -0
  111. package/skills/cometchat-angular-v5-features/references/host-composed-extensions.md +85 -0
  112. package/skills/cometchat-angular-v5-migration/SKILL.md +40 -0
  113. package/skills/cometchat-angular-v5-migration/references/migration-guide.md +165 -0
  114. package/skills/cometchat-angular-v5-patterns/SKILL.md +107 -0
  115. package/skills/cometchat-angular-v5-placement/SKILL.md +133 -0
  116. package/skills/cometchat-angular-v5-placement/references/combined-app.md +174 -0
  117. package/skills/cometchat-angular-v5-placement/references/core-surface.md +199 -0
  118. package/skills/cometchat-angular-v5-production/SKILL.md +101 -0
  119. package/skills/cometchat-angular-v5-push/SKILL.md +61 -0
  120. package/skills/cometchat-angular-v5-testing/SKILL.md +112 -0
  121. package/skills/cometchat-angular-v5-troubleshooting/SKILL.md +96 -0
  122. package/skills/cometchat-flutter-v5-sdk/SKILL.md +188 -0
  123. package/skills/cometchat-flutter-v5-sdk/references/doc-corrections.md +55 -0
  124. package/skills/cometchat-flutter-v5-sdk/references/docs-map.md +211 -0
  125. package/skills/cometchat-flutter-v5-sdk/references/platform-notes.md +48 -0
  126. package/skills/cometchat-flutter-v5-sdk/references/transcription.md +87 -0
  127. package/skills/cometchat-flutter-v6-calls/SKILL.md +75 -387
  128. package/skills/cometchat-flutter-v6-components/SKILL.md +88 -361
  129. package/skills/cometchat-flutter-v6-core/SKILL.md +154 -593
  130. package/skills/cometchat-flutter-v6-core/references/anti-patterns.md +55 -0
  131. package/skills/cometchat-flutter-v6-core/references/docs-map.md +143 -0
  132. package/skills/cometchat-flutter-v6-core/references/layout.md +45 -0
  133. package/skills/cometchat-flutter-v6-core/references/lifecycle.md +87 -0
  134. package/skills/cometchat-flutter-v6-core/references/setup-credentials.md +84 -0
  135. package/skills/cometchat-flutter-v6-core/references/troubleshooting.md +26 -0
  136. package/skills/cometchat-flutter-v6-customization/SKILL.md +70 -712
  137. package/skills/cometchat-flutter-v6-events/SKILL.md +79 -174
  138. package/skills/cometchat-flutter-v6-features/SKILL.md +55 -394
  139. package/skills/cometchat-flutter-v6-migration/SKILL.md +68 -367
  140. package/skills/cometchat-flutter-v6-migration/references/migration-guide.md +131 -0
  141. package/skills/cometchat-flutter-v6-patterns/SKILL.md +61 -0
  142. package/skills/cometchat-flutter-v6-placement/SKILL.md +94 -381
  143. package/skills/cometchat-flutter-v6-production/SKILL.md +58 -615
  144. package/skills/cometchat-flutter-v6-push/SKILL.md +46 -455
  145. package/skills/cometchat-flutter-v6-testing/SKILL.md +68 -299
  146. package/skills/cometchat-flutter-v6-troubleshooting/SKILL.md +54 -878
  147. package/skills/cometchat-ios-calls/SKILL.md +105 -511
  148. package/skills/cometchat-ios-components/SKILL.md +44 -834
  149. package/skills/cometchat-ios-core/SKILL.md +181 -1068
  150. package/skills/cometchat-ios-core/references/anti-patterns.md +80 -0
  151. package/skills/cometchat-ios-core/references/docs-map.md +123 -0
  152. package/skills/cometchat-ios-core/references/install.md +23 -0
  153. package/skills/cometchat-ios-core/references/layout.md +186 -0
  154. package/skills/cometchat-ios-core/references/setup-credentials.md +197 -0
  155. package/skills/cometchat-ios-core/references/swiftui.md +91 -0
  156. package/skills/cometchat-ios-core/references/troubleshooting.md +100 -0
  157. package/skills/cometchat-ios-customization/SKILL.md +33 -968
  158. package/skills/cometchat-ios-features/SKILL.md +29 -738
  159. package/skills/cometchat-ios-migration/SKILL.md +39 -0
  160. package/skills/cometchat-ios-placement/SKILL.md +51 -729
  161. package/skills/cometchat-ios-push/SKILL.md +24 -602
  162. package/skills/cometchat-ios-v5-sdk/SKILL.md +161 -0
  163. package/skills/cometchat-ios-v5-sdk/references/docs-map.md +326 -0
  164. package/skills/cometchat-js-v5-sdk/SKILL.md +95 -0
  165. package/skills/cometchat-js-v5-sdk/references/docs-map.md +114 -0
  166. package/skills/cometchat-onboarding/SKILL.md +89 -0
  167. package/skills/cometchat-onboarding/references/archetypes.md +51 -0
  168. package/skills/cometchat-onboarding/references/calling-first.md +77 -0
  169. package/skills/cometchat-onboarding/references/not-in-this-pack.md +8 -0
  170. package/skills/cometchat-onboarding/references/plan-artifact.md +133 -0
  171. package/skills/cometchat-onboarding/references/platforms.md +90 -0
  172. package/skills/cometchat-react-native-bare-patterns/SKILL.md +120 -0
  173. package/skills/cometchat-react-native-calls/SKILL.md +200 -0
  174. package/skills/cometchat-react-native-components/SKILL.md +142 -0
  175. package/skills/cometchat-react-native-core/SKILL.md +313 -0
  176. package/skills/cometchat-react-native-core/references/anti-patterns.md +79 -0
  177. package/skills/cometchat-react-native-core/references/component-props.md +105 -0
  178. package/skills/cometchat-react-native-core/references/dependencies.md +62 -0
  179. package/skills/cometchat-react-native-core/references/docs-map.md +126 -0
  180. package/skills/cometchat-react-native-core/references/layout.md +61 -0
  181. package/skills/cometchat-react-native-core/references/lifecycle.md +64 -0
  182. package/skills/cometchat-react-native-core/references/setup-credentials.md +39 -0
  183. package/skills/cometchat-react-native-customization/SKILL.md +198 -0
  184. package/skills/cometchat-react-native-expo-patterns/SKILL.md +116 -0
  185. package/skills/cometchat-react-native-features/SKILL.md +122 -0
  186. package/skills/cometchat-react-native-migration/SKILL.md +103 -0
  187. package/skills/cometchat-react-native-placement/SKILL.md +158 -0
  188. package/skills/cometchat-react-native-production/SKILL.md +78 -0
  189. package/skills/cometchat-react-native-push/SKILL.md +88 -0
  190. package/skills/cometchat-react-native-sdk/SKILL.md +126 -0
  191. package/skills/cometchat-react-native-sdk/references/method-map.md +239 -0
  192. package/skills/cometchat-react-native-sdk/references/page-map.md +96 -0
  193. package/skills/cometchat-react-native-testing/SKILL.md +94 -0
  194. package/skills/cometchat-react-native-troubleshooting/SKILL.md +116 -0
  195. package/skills/cometchat-react-native-v5-sdk/SKILL.md +150 -0
  196. package/skills/cometchat-react-native-v5-sdk/references/docs-map.md +127 -0
  197. package/skills/cometchat-react-native-v5-sdk/references/ringing-voip.md +369 -0
  198. package/skills/cometchat-react-v7-calls/SKILL.md +75 -0
  199. package/skills/cometchat-react-v7-components/SKILL.md +72 -0
  200. package/skills/cometchat-react-v7-core/SKILL.md +101 -0
  201. package/skills/cometchat-react-v7-core/references/anti-patterns.md +19 -0
  202. package/skills/cometchat-react-v7-core/references/component-props.md +82 -0
  203. package/skills/cometchat-react-v7-core/references/dependencies.md +23 -0
  204. package/skills/cometchat-react-v7-core/references/docs-map.md +117 -0
  205. package/skills/cometchat-react-v7-core/references/i18n-rtl-a11y.md +22 -0
  206. package/skills/cometchat-react-v7-core/references/layout.md +158 -0
  207. package/skills/cometchat-react-v7-core/references/lifecycle.md +74 -0
  208. package/skills/cometchat-react-v7-core/references/setup-credentials.md +58 -0
  209. package/skills/cometchat-react-v7-core/references/ssr.md +11 -0
  210. package/skills/cometchat-react-v7-core/references/theming.md +52 -0
  211. package/skills/cometchat-react-v7-core/references/troubleshooting.md +28 -0
  212. package/skills/cometchat-react-v7-customization/SKILL.md +84 -0
  213. package/skills/cometchat-react-v7-features/SKILL.md +92 -0
  214. package/skills/cometchat-react-v7-migration/SKILL.md +39 -0
  215. package/skills/cometchat-react-v7-migration/references/migration-guide.md +119 -0
  216. package/skills/cometchat-react-v7-patterns/SKILL.md +43 -0
  217. package/skills/cometchat-react-v7-placement/SKILL.md +106 -0
  218. package/skills/cometchat-react-v7-placement/references/recipes.md +354 -0
  219. package/skills/cometchat-react-v7-push/SKILL.md +53 -0
  220. package/test-suite/README.md +70 -0
  221. package/test-suite/catalogs/android-calls-v5.json +830 -0
  222. package/test-suite/catalogs/android-calls-v5.symbols.txt +499 -0
  223. package/test-suite/catalogs/android-v6.json +1646 -0
  224. package/test-suite/catalogs/android-v6.symbols.txt +298 -0
  225. package/test-suite/catalogs/angular-v5.json +7587 -0
  226. package/test-suite/catalogs/flutter-calls-v5.json +196 -0
  227. package/test-suite/catalogs/flutter-calls-v5.symbols.txt +59 -0
  228. package/test-suite/catalogs/flutter-v6.json +651 -0
  229. package/test-suite/catalogs/ios-calls-v5.json +158 -0
  230. package/test-suite/catalogs/ios-calls-v5.symbols.txt +70 -0
  231. package/test-suite/catalogs/ios-v5.json +1383 -0
  232. package/test-suite/catalogs/ios-v5.symbols.txt +699 -0
  233. package/test-suite/catalogs/rn-calls-v5.json +134 -0
  234. package/test-suite/catalogs/rn-sdk-v4.json +672 -0
  235. package/test-suite/catalogs/rn-v5.json +449 -0
  236. package/test-suite/catalogs/sdk-android-v5.json +514 -0
  237. package/test-suite/catalogs/sdk-android-v5.symbols.txt +254 -0
  238. package/test-suite/catalogs/sdk-jsv4.json +800 -0
  239. package/test-suite/catalogs/web-calls-v5.json +195 -0
  240. package/test-suite/catalogs/web-v7.json +1243 -0
  241. package/test-suite/scripts/build-registry.mjs +113 -0
  242. package/test-suite/scripts/catalog-refresh-dart.mjs +151 -0
  243. package/test-suite/scripts/catalog-refresh.mjs +100 -0
  244. package/test-suite/scripts/lint-skills.mjs +909 -0
  245. package/test-suite/scripts/measure-tokens.mjs +169 -0
  246. package/test-suite/scripts/typecheck-fences-dart.mjs +437 -0
  247. package/test-suite/scripts/typecheck-fences-kotlin.mjs +269 -0
  248. package/test-suite/scripts/typecheck-fences.mjs +206 -0
  249. package/test-suite/scripts/verify-catalog.mjs +242 -0
  250. package/test-suite/scripts/verify-contract-fences.mjs +94 -0
  251. package/test-suite/scripts/verify-detection.mjs +178 -0
  252. package/test-suite/scripts/verify-docs-base.mjs +91 -0
  253. package/test-suite/scripts/verify-family-agnostic.mjs +130 -0
  254. package/test-suite/scripts/verify-golden-path.mjs +138 -0
  255. package/test-suite/scripts/verify-oracle-components.mjs +133 -0
  256. package/test-suite/scripts/verify-template-bindings.mjs +148 -0
  257. package/test-suite/typecheck/angular-v5/package.json +21 -0
  258. package/test-suite/typecheck/angular-v5/tsconfig.json +21 -0
  259. package/test-suite/typecheck/flutter-v6/analysis_options.yaml +25 -0
  260. package/test-suite/typecheck/flutter-v6/pubspec.yaml +21 -0
  261. package/test-suite/typecheck/web-v7/package.json +18 -0
  262. package/test-suite/typecheck/web-v7/tsconfig.json +19 -0
  263. package/bin/install.js +0 -1003
  264. package/skills/.claude-plugin/marketplace.json +0 -86
  265. package/skills/cometchat/references/asking-questions.md +0 -48
  266. package/skills/cometchat-a11y/SKILL.md +0 -477
  267. package/skills/cometchat-android-v5/SKILL.md +0 -121
  268. package/skills/cometchat-android-v5-calls/SKILL.md +0 -427
  269. package/skills/cometchat-android-v5-calls/references/README.md +0 -53
  270. package/skills/cometchat-android-v5-calls/references/add-calls-to-existing-chat.md +0 -197
  271. package/skills/cometchat-android-v5-calls/references/audio-controls.md +0 -91
  272. package/skills/cometchat-android-v5-calls/references/background-handling.md +0 -168
  273. package/skills/cometchat-android-v5-calls/references/call-layouts.md +0 -131
  274. package/skills/cometchat-android-v5-calls/references/call-logs.md +0 -113
  275. package/skills/cometchat-android-v5-calls/references/call-session.md +0 -274
  276. package/skills/cometchat-android-v5-calls/references/custom-ui.md +0 -150
  277. package/skills/cometchat-android-v5-calls/references/event-listeners.md +0 -123
  278. package/skills/cometchat-android-v5-calls/references/group-calls.md +0 -205
  279. package/skills/cometchat-android-v5-calls/references/idle-timeout.md +0 -117
  280. package/skills/cometchat-android-v5-calls/references/in-call-chat.md +0 -134
  281. package/skills/cometchat-android-v5-calls/references/join-session.md +0 -120
  282. package/skills/cometchat-android-v5-calls/references/migration-v4-to-v5.md +0 -222
  283. package/skills/cometchat-android-v5-calls/references/participant-management.md +0 -110
  284. package/skills/cometchat-android-v5-calls/references/picture-in-picture.md +0 -106
  285. package/skills/cometchat-android-v5-calls/references/raise-hand.md +0 -248
  286. package/skills/cometchat-android-v5-calls/references/recording.md +0 -101
  287. package/skills/cometchat-android-v5-calls/references/ringing-integration.md +0 -152
  288. package/skills/cometchat-android-v5-calls/references/screen-sharing.md +0 -78
  289. package/skills/cometchat-android-v5-calls/references/server-fcm-voip.md +0 -215
  290. package/skills/cometchat-android-v5-calls/references/session-settings.md +0 -121
  291. package/skills/cometchat-android-v5-calls/references/setup.md +0 -137
  292. package/skills/cometchat-android-v5-calls/references/share-invite.md +0 -156
  293. package/skills/cometchat-android-v5-calls/references/video-controls.md +0 -87
  294. package/skills/cometchat-android-v5-calls/references/voip-calling.md +0 -526
  295. package/skills/cometchat-android-v5-components/SKILL.md +0 -431
  296. package/skills/cometchat-android-v5-core/SKILL.md +0 -486
  297. package/skills/cometchat-android-v5-customization/SKILL.md +0 -469
  298. package/skills/cometchat-android-v5-extensions/SKILL.md +0 -127
  299. package/skills/cometchat-android-v5-features/SKILL.md +0 -131
  300. package/skills/cometchat-android-v5-placement/SKILL.md +0 -277
  301. package/skills/cometchat-android-v5-production/SKILL.md +0 -95
  302. package/skills/cometchat-android-v5-push/SKILL.md +0 -619
  303. package/skills/cometchat-android-v5-testing/SKILL.md +0 -188
  304. package/skills/cometchat-android-v5-theming/SKILL.md +0 -167
  305. package/skills/cometchat-android-v5-troubleshooting/SKILL.md +0 -74
  306. package/skills/cometchat-android-v6/SKILL.md +0 -108
  307. package/skills/cometchat-android-v6-calls/references/add-calls-to-existing-chat.md +0 -97
  308. package/skills/cometchat-android-v6-calls/references/advanced-features.md +0 -87
  309. package/skills/cometchat-android-v6-calls/references/call-layouts.md +0 -100
  310. package/skills/cometchat-android-v6-calls/references/call-session.md +0 -163
  311. package/skills/cometchat-android-v6-calls/references/device-management.md +0 -172
  312. package/skills/cometchat-android-v6-calls/references/group-calls.md +0 -191
  313. package/skills/cometchat-android-v6-calls/references/idle-timeout.md +0 -110
  314. package/skills/cometchat-android-v6-calls/references/in-call-chat.md +0 -141
  315. package/skills/cometchat-android-v6-calls/references/raise-hand.md +0 -188
  316. package/skills/cometchat-android-v6-calls/references/ringing-integration.md +0 -176
  317. package/skills/cometchat-android-v6-calls/references/server-fcm-voip.md +0 -127
  318. package/skills/cometchat-android-v6-calls/references/share-invite.md +0 -105
  319. package/skills/cometchat-android-v6-compose-theming/SKILL.md +0 -250
  320. package/skills/cometchat-android-v6-kotlin-theming/SKILL.md +0 -233
  321. package/skills/cometchat-angular-calls/SKILL.md +0 -378
  322. package/skills/cometchat-angular-calls/references/add-calls-to-existing-chat.md +0 -96
  323. package/skills/cometchat-angular-calls/references/call-layouts.md +0 -123
  324. package/skills/cometchat-angular-calls/references/call-session.md +0 -167
  325. package/skills/cometchat-angular-calls/references/custom-ui.md +0 -239
  326. package/skills/cometchat-angular-calls/references/device-management.md +0 -154
  327. package/skills/cometchat-angular-calls/references/group-calls.md +0 -433
  328. package/skills/cometchat-angular-calls/references/idle-timeout.md +0 -161
  329. package/skills/cometchat-angular-calls/references/in-call-chat.md +0 -148
  330. package/skills/cometchat-angular-calls/references/lazy-loading-pitfalls.md +0 -205
  331. package/skills/cometchat-angular-calls/references/migration-v4-to-v5.md +0 -53
  332. package/skills/cometchat-angular-calls/references/ngzone-and-async-callbacks.md +0 -184
  333. package/skills/cometchat-angular-calls/references/picture-in-picture.md +0 -285
  334. package/skills/cometchat-angular-calls/references/raise-hand.md +0 -172
  335. package/skills/cometchat-angular-calls/references/recording-screen-share.md +0 -260
  336. package/skills/cometchat-angular-calls/references/ringing-integration.md +0 -133
  337. package/skills/cometchat-angular-calls/references/server-web-push-vapid.md +0 -100
  338. package/skills/cometchat-angular-calls/references/share-invite.md +0 -122
  339. package/skills/cometchat-angular-calls/references/virtual-background.md +0 -29
  340. package/skills/cometchat-angular-components/SKILL.md +0 -235
  341. package/skills/cometchat-angular-core/SKILL.md +0 -386
  342. package/skills/cometchat-angular-customization/SKILL.md +0 -616
  343. package/skills/cometchat-angular-features/SKILL.md +0 -329
  344. package/skills/cometchat-angular-patterns/SKILL.md +0 -256
  345. package/skills/cometchat-angular-placement/SKILL.md +0 -314
  346. package/skills/cometchat-angular-production/SKILL.md +0 -564
  347. package/skills/cometchat-angular-push/SKILL.md +0 -389
  348. package/skills/cometchat-angular-testing/SKILL.md +0 -605
  349. package/skills/cometchat-angular-theming/SKILL.md +0 -290
  350. package/skills/cometchat-angular-troubleshooting/SKILL.md +0 -364
  351. package/skills/cometchat-astro-patterns/SKILL.md +0 -708
  352. package/skills/cometchat-calls/SKILL.md +0 -364
  353. package/skills/cometchat-calls/references/use-case-broadcast.md +0 -199
  354. package/skills/cometchat-calls/references/use-case-marketplace.md +0 -157
  355. package/skills/cometchat-calls/references/use-case-support.md +0 -189
  356. package/skills/cometchat-calls/references/use-case-team.md +0 -180
  357. package/skills/cometchat-calls/references/use-case-telehealth.md +0 -153
  358. package/skills/cometchat-components/SKILL.md +0 -1142
  359. package/skills/cometchat-core/SKILL.md +0 -1048
  360. package/skills/cometchat-customization/SKILL.md +0 -580
  361. package/skills/cometchat-customization/references/component-catalog.md +0 -236
  362. package/skills/cometchat-features/SKILL.md +0 -861
  363. package/skills/cometchat-flutter-v5/SKILL.md +0 -173
  364. package/skills/cometchat-flutter-v5-calls/SKILL.md +0 -453
  365. package/skills/cometchat-flutter-v5-calls/references/add-calls-to-existing-chat.md +0 -193
  366. package/skills/cometchat-flutter-v5-calls/references/call-layouts.md +0 -103
  367. package/skills/cometchat-flutter-v5-calls/references/call-session.md +0 -285
  368. package/skills/cometchat-flutter-v5-calls/references/device-management.md +0 -124
  369. package/skills/cometchat-flutter-v5-calls/references/group-calls.md +0 -181
  370. package/skills/cometchat-flutter-v5-calls/references/idle-timeout.md +0 -99
  371. package/skills/cometchat-flutter-v5-calls/references/in-call-chat.md +0 -135
  372. package/skills/cometchat-flutter-v5-calls/references/migration-v4-to-v5.md +0 -210
  373. package/skills/cometchat-flutter-v5-calls/references/raise-hand.md +0 -255
  374. package/skills/cometchat-flutter-v5-calls/references/ringing-integration.md +0 -196
  375. package/skills/cometchat-flutter-v5-calls/references/server-push-bridge.md +0 -101
  376. package/skills/cometchat-flutter-v5-calls/references/share-invite.md +0 -148
  377. package/skills/cometchat-flutter-v5-conversations/SKILL.md +0 -118
  378. package/skills/cometchat-flutter-v5-core/SKILL.md +0 -239
  379. package/skills/cometchat-flutter-v5-customization/SKILL.md +0 -358
  380. package/skills/cometchat-flutter-v5-events/SKILL.md +0 -156
  381. package/skills/cometchat-flutter-v5-messages/SKILL.md +0 -259
  382. package/skills/cometchat-flutter-v5-production/SKILL.md +0 -216
  383. package/skills/cometchat-flutter-v5-push/SKILL.md +0 -285
  384. package/skills/cometchat-flutter-v5-testing/SKILL.md +0 -401
  385. package/skills/cometchat-flutter-v5-theming/SKILL.md +0 -161
  386. package/skills/cometchat-flutter-v5-troubleshooting/SKILL.md +0 -130
  387. package/skills/cometchat-flutter-v5-users-groups/SKILL.md +0 -152
  388. package/skills/cometchat-flutter-v6/SKILL.md +0 -446
  389. package/skills/cometchat-flutter-v6-calls/references/add-calls-to-existing-chat.md +0 -136
  390. package/skills/cometchat-flutter-v6-calls/references/advanced-features.md +0 -89
  391. package/skills/cometchat-flutter-v6-calls/references/call-layouts.md +0 -105
  392. package/skills/cometchat-flutter-v6-calls/references/call-session.md +0 -229
  393. package/skills/cometchat-flutter-v6-calls/references/device-management.md +0 -105
  394. package/skills/cometchat-flutter-v6-calls/references/group-calls.md +0 -190
  395. package/skills/cometchat-flutter-v6-calls/references/idle-timeout.md +0 -88
  396. package/skills/cometchat-flutter-v6-calls/references/in-call-chat.md +0 -125
  397. package/skills/cometchat-flutter-v6-calls/references/raise-hand.md +0 -275
  398. package/skills/cometchat-flutter-v6-calls/references/ringing-integration.md +0 -171
  399. package/skills/cometchat-flutter-v6-calls/references/server-push-bridge.md +0 -93
  400. package/skills/cometchat-flutter-v6-calls/references/share-invite.md +0 -102
  401. package/skills/cometchat-flutter-v6-conversations/SKILL.md +0 -238
  402. package/skills/cometchat-flutter-v6-messages/SKILL.md +0 -384
  403. package/skills/cometchat-flutter-v6-theming/SKILL.md +0 -293
  404. package/skills/cometchat-flutter-v6-users-groups/SKILL.md +0 -224
  405. package/skills/cometchat-i18n/SKILL.md +0 -419
  406. package/skills/cometchat-ios/SKILL.md +0 -325
  407. package/skills/cometchat-ios-calls/references/add-calls-to-existing-chat.md +0 -174
  408. package/skills/cometchat-ios-calls/references/audio-modes-and-controls.md +0 -45
  409. package/skills/cometchat-ios-calls/references/avaudiosession-routing.md +0 -188
  410. package/skills/cometchat-ios-calls/references/call-layouts.md +0 -76
  411. package/skills/cometchat-ios-calls/references/call-session.md +0 -218
  412. package/skills/cometchat-ios-calls/references/callkit-and-pushkit.md +0 -357
  413. package/skills/cometchat-ios-calls/references/custom-ui.md +0 -322
  414. package/skills/cometchat-ios-calls/references/device-management.md +0 -171
  415. package/skills/cometchat-ios-calls/references/group-calls.md +0 -359
  416. package/skills/cometchat-ios-calls/references/idle-timeout.md +0 -184
  417. package/skills/cometchat-ios-calls/references/in-call-chat.md +0 -179
  418. package/skills/cometchat-ios-calls/references/migration-v4-to-v5.md +0 -196
  419. package/skills/cometchat-ios-calls/references/picture-in-picture.md +0 -246
  420. package/skills/cometchat-ios-calls/references/raise-hand.md +0 -26
  421. package/skills/cometchat-ios-calls/references/recording-screen-share.md +0 -252
  422. package/skills/cometchat-ios-calls/references/ringing-integration.md +0 -143
  423. package/skills/cometchat-ios-calls/references/server-apns-pushkit.md +0 -267
  424. package/skills/cometchat-ios-calls/references/share-invite.md +0 -148
  425. package/skills/cometchat-ios-calls/references/swiftui-uikit-hosting.md +0 -246
  426. package/skills/cometchat-ios-calls/references/voip-cert-setup.md +0 -166
  427. package/skills/cometchat-ios-production/SKILL.md +0 -738
  428. package/skills/cometchat-ios-testing/SKILL.md +0 -376
  429. package/skills/cometchat-ios-theming/SKILL.md +0 -667
  430. package/skills/cometchat-ios-troubleshooting/SKILL.md +0 -1003
  431. package/skills/cometchat-native-bare-patterns/SKILL.md +0 -550
  432. package/skills/cometchat-native-calls/SKILL.md +0 -669
  433. package/skills/cometchat-native-calls/references/add-calls-to-existing-chat.md +0 -203
  434. package/skills/cometchat-native-calls/references/call-layouts.md +0 -125
  435. package/skills/cometchat-native-calls/references/call-session.md +0 -182
  436. package/skills/cometchat-native-calls/references/custom-ui.md +0 -254
  437. package/skills/cometchat-native-calls/references/device-management.md +0 -158
  438. package/skills/cometchat-native-calls/references/expo-vs-bare.md +0 -179
  439. package/skills/cometchat-native-calls/references/group-calls.md +0 -296
  440. package/skills/cometchat-native-calls/references/idle-timeout.md +0 -128
  441. package/skills/cometchat-native-calls/references/in-call-chat.md +0 -145
  442. package/skills/cometchat-native-calls/references/migration-v4-to-v5.md +0 -72
  443. package/skills/cometchat-native-calls/references/picture-in-picture.md +0 -276
  444. package/skills/cometchat-native-calls/references/raise-hand.md +0 -205
  445. package/skills/cometchat-native-calls/references/recording-screen-share.md +0 -169
  446. package/skills/cometchat-native-calls/references/ringing-integration.md +0 -118
  447. package/skills/cometchat-native-calls/references/server-push-bridge.md +0 -135
  448. package/skills/cometchat-native-calls/references/server-push-payloads.md +0 -193
  449. package/skills/cometchat-native-calls/references/share-invite.md +0 -146
  450. package/skills/cometchat-native-calls/references/voip-push-end-to-end.md +0 -319
  451. package/skills/cometchat-native-components/SKILL.md +0 -628
  452. package/skills/cometchat-native-core/SKILL.md +0 -679
  453. package/skills/cometchat-native-customization/SKILL.md +0 -716
  454. package/skills/cometchat-native-expo-patterns/SKILL.md +0 -552
  455. package/skills/cometchat-native-features/SKILL.md +0 -638
  456. package/skills/cometchat-native-placement/SKILL.md +0 -509
  457. package/skills/cometchat-native-production/SKILL.md +0 -700
  458. package/skills/cometchat-native-push/SKILL.md +0 -594
  459. package/skills/cometchat-native-testing/SKILL.md +0 -582
  460. package/skills/cometchat-native-theming/SKILL.md +0 -681
  461. package/skills/cometchat-native-troubleshooting/SKILL.md +0 -501
  462. package/skills/cometchat-nextjs-patterns/SKILL.md +0 -899
  463. package/skills/cometchat-placement/SKILL.md +0 -1360
  464. package/skills/cometchat-production/SKILL.md +0 -1027
  465. package/skills/cometchat-react-calls/SKILL.md +0 -749
  466. package/skills/cometchat-react-calls/references/add-calls-to-existing-chat.md +0 -146
  467. package/skills/cometchat-react-calls/references/call-layouts.md +0 -160
  468. package/skills/cometchat-react-calls/references/call-session.md +0 -235
  469. package/skills/cometchat-react-calls/references/custom-ui.md +0 -247
  470. package/skills/cometchat-react-calls/references/device-management.md +0 -210
  471. package/skills/cometchat-react-calls/references/group-calls.md +0 -257
  472. package/skills/cometchat-react-calls/references/idle-timeout.md +0 -188
  473. package/skills/cometchat-react-calls/references/in-call-chat.md +0 -212
  474. package/skills/cometchat-react-calls/references/migration-v4-to-v5.md +0 -170
  475. package/skills/cometchat-react-calls/references/picture-in-picture.md +0 -245
  476. package/skills/cometchat-react-calls/references/raise-hand.md +0 -238
  477. package/skills/cometchat-react-calls/references/recording-screen-share.md +0 -144
  478. package/skills/cometchat-react-calls/references/ringing-integration.md +0 -255
  479. package/skills/cometchat-react-calls/references/server-web-push-vapid.md +0 -241
  480. package/skills/cometchat-react-calls/references/share-invite.md +0 -175
  481. package/skills/cometchat-react-calls/references/testing-calls-on-web.md +0 -216
  482. package/skills/cometchat-react-calls/references/virtual-background.md +0 -32
  483. package/skills/cometchat-react-calls/references/voip-and-web-push.md +0 -165
  484. package/skills/cometchat-react-patterns/SKILL.md +0 -628
  485. package/skills/cometchat-react-push/SKILL.md +0 -634
  486. package/skills/cometchat-react-router-patterns/SKILL.md +0 -758
  487. package/skills/cometchat-react-testing/SKILL.md +0 -413
  488. package/skills/cometchat-theming/SKILL.md +0 -498
  489. package/skills/cometchat-troubleshooting/SKILL.md +0 -294
@@ -1,1027 +0,0 @@
1
- ---
2
- name: cometchat-production
3
- description: "Production readiness for CometChat — server-side token auth, user management CRUD, environment hardening, and security checklist. Replaces dev-mode authKey with server-side tokens."
4
- license: "MIT"
5
- compatibility: "Node.js >=18; @cometchat/chat-uikit-react ^6; @cometchat/chat-sdk-javascript ^4"
6
- metadata:
7
- author: "CometChat"
8
- version: "3.0.0"
9
- tags: "cometchat production auth token security user-management rest-api"
10
- ---
11
-
12
- > **Ground truth:** `docs/fundamentals/user-auth` + per-platform UI Kit. **Official docs:** https://www.cometchat.com/docs/fundamentals/user-auth · **Docs MCP:** `claude mcp add --transport http cometchat-docs https://www.cometchat.com/docs/mcp` (or fetch the URL directly without MCP). Verify symbols against the installed package/source before relying on them.
13
-
14
- ## Purpose
15
-
16
- This skill teaches Claude how to harden a CometChat integration for production. It covers two critical areas:
17
-
18
- 1. **Token-based authentication** — replacing client-side `authKey` with server-side token generation
19
- 2. **User management** — server-side CRUD for CometChat users (create on signup, update on profile change, delete on account deletion)
20
-
21
- The `cometchat-core` skill's provider pattern supports both dev mode (`login(uid)`) and production mode (`loginWithAuthToken(token)`). This skill provides the server-side half: the token endpoint and user management endpoints.
22
-
23
- ---
24
-
25
- ## 1. Why production auth matters
26
-
27
- In development mode, `CometChatUIKit.login(uid)` uses the `authKey` configured via `UIKitSettingsBuilder.setAuthKey()`. This key is embedded in your client-side JavaScript bundle. Anyone can open browser DevTools, find the auth key, and use it to log in as ANY user in your CometChat app. They can read private messages, send messages as other users, and access every conversation.
28
-
29
- Production deployments MUST use server-side token generation. The auth key stays on your server. Clients receive short-lived tokens scoped to a single user. If a token leaks, the blast radius is one user session, not your entire app.
30
-
31
- ---
32
-
33
- ## 2. The token auth pattern
34
-
35
- The production auth flow has four steps:
36
-
37
- 1. **Client authenticates with YOUR auth system.** The user logs into your app using your existing login flow (email/password, OAuth, magic link, etc.). This step has nothing to do with CometChat.
38
-
39
- 2. **Your server calls the CometChat REST API.** After verifying the user's identity, your server makes a POST request to CometChat's token endpoint using the REST API key (a server-only secret). CometChat returns an auth token for that specific user.
40
-
41
- 3. **Client receives the token.** Your server sends the auth token back to the client in the API response.
42
-
43
- 4. **Client calls `CometChatUIKit.loginWithAuthToken(token)`.** The CometChat SDK uses the token to establish a session. The auth key NEVER touches the browser.
44
-
45
- ```
46
- ┌─────────┐ 1. Login ┌──────────┐ 2. POST /v3/users/{uid}/auth_tokens ┌──────────────┐
47
- │ Client │ ───────────────→ │ Your │ ──────────────────────────────────────→ │ CometChat │
48
- │ (Browser)│ │ Server │ ←────────────────────────────────────── │ REST API │
49
- │ │ ←─────────────── │ │ { authToken: "..." } │ │
50
- │ │ 3. auth token │ │ │ │
51
- │ │ └──────────┘ └──────────────┘
52
- │ │
53
- │ 4. CometChatUIKit.loginWithAuthToken(token)
54
- └─────────┘
55
- ```
56
-
57
- ---
58
-
59
- ## 3. Server endpoint implementations
60
-
61
- Each endpoint does the same thing:
62
- 1. Receives a user UID (from the authenticated session, NOT from the request body in production)
63
- 2. Validates that the caller is authenticated
64
- 3. POSTs to `https://{APP_ID}.api-{REGION}.cometchat.io/v3/users/{uid}/auth_tokens`
65
- 4. Returns the auth token to the client
66
-
67
- The CometChat REST API requires two headers:
68
- - `appId` — your CometChat app ID
69
- - `apiKey` — a **REST API Key** (NOT the Auth Key used in dev mode)
70
-
71
- **Auth Key vs REST API Key — these are different keys:**
72
-
73
- | Key type | Where to find | Purpose | Security |
74
- |---|---|---|---|
75
- | **Auth Key** (`authOnly` scope) | Dashboard → Your App → API & Auth Keys → "Auth Keys" table | Client-side SDK `CometChatUIKit.login(uid)` in dev mode; server-side it can **create users + mint auth tokens** (`POST /v3/users`, `POST /v3/users/{uid}/auth_tokens`) but **NOT** update/delete users | Exposed in browser. Dev only. |
76
- | **REST API Key** (`fullAccess` scope) | Dashboard → Your App → API & Auth Keys → "Rest API Keys" table | Server-to-server: token generation, **full** user CRUD (incl. **update/delete**), message send | Server only. Never expose to client. |
77
-
78
- > **Scope split (verified against `fundamentals/key-concepts.mdx` + the chat-apis `apikey` scope enum `fullAccess`/`authOnly`):** the Auth Key can *create & login* users and mint tokens, but **`PUT`/`DELETE /v3/users/{uid}` require a `fullAccess` REST API Key** — an `authOnly` Auth Key is rejected. So a user-management endpoint that does update/delete MUST use `COMETCHAT_REST_API_KEY`, not the Auth Key. (Heads-up: the CLI's `add-user-mgmt` / `production-auth` scaffolds currently name the server var `COMETCHAT_AUTH_KEY`; for full CRUD, populate it with — or rename it to — a `fullAccess` REST API Key. Tracked as a CLI-alignment follow-up.)
79
-
80
- The `.env` should have both for production:
81
- ```env
82
- # Client-side (prefixed for the framework)
83
- VITE_COMETCHAT_APP_ID=your_app_id
84
- VITE_COMETCHAT_REGION=us
85
-
86
- # Server-side (no prefix — never exposed to the client)
87
- COMETCHAT_APP_ID=your_app_id
88
- COMETCHAT_REGION=us
89
- COMETCHAT_REST_API_KEY=your_rest_api_key
90
- ```
91
-
92
- If the user only has an Auth Key, tell them to create a REST API Key in the dashboard: **API & Auth Keys → Rest API Keys → Add Key.**
93
-
94
- ### Next.js App Router
95
-
96
- `app/api/cometchat-token/route.ts`
97
-
98
- ```typescript
99
- import { NextRequest, NextResponse } from "next/server";
100
-
101
- const APP_ID = process.env.COMETCHAT_APP_ID!;
102
- const REGION = process.env.COMETCHAT_REGION!;
103
- const REST_API_KEY = process.env.COMETCHAT_REST_API_KEY!;
104
-
105
- export async function POST(request: NextRequest) {
106
- // TODO: Replace this with your real auth check.
107
- // Example with NextAuth: const session = await getServerSession(authOptions);
108
- // Example with Clerk: const { userId } = auth();
109
- // If not authenticated, return 401.
110
- const body = await request.json();
111
- const uid = body.uid as string;
112
-
113
- if (!uid || typeof uid !== "string") {
114
- return NextResponse.json({ error: "Missing uid" }, { status: 400 });
115
- }
116
-
117
- // In production, derive UID from the authenticated session, not from
118
- // the request body. The body approach is shown here as a starting point.
119
- // Example: const uid = session.user.id;
120
-
121
- const response = await fetch(
122
- `https://${APP_ID}.api-${REGION}.cometchat.io/v3/users/${encodeURIComponent(uid)}/auth_tokens`,
123
- {
124
- method: "POST",
125
- headers: {
126
- "Content-Type": "application/json",
127
- appId: APP_ID,
128
- apiKey: REST_API_KEY,
129
- },
130
- body: JSON.stringify({}),
131
- }
132
- );
133
-
134
- if (!response.ok) {
135
- const error = await response.text();
136
- console.error("CometChat token error:", error);
137
- return NextResponse.json(
138
- { error: "Failed to generate auth token" },
139
- { status: response.status }
140
- );
141
- }
142
-
143
- const data = await response.json();
144
- return NextResponse.json({ authToken: data.data.authToken });
145
- }
146
- ```
147
-
148
- ### Next.js Pages Router
149
-
150
- `pages/api/cometchat-token.ts`
151
-
152
- ```typescript
153
- import type { NextApiRequest, NextApiResponse } from "next";
154
-
155
- const APP_ID = process.env.COMETCHAT_APP_ID!;
156
- const REGION = process.env.COMETCHAT_REGION!;
157
- const REST_API_KEY = process.env.COMETCHAT_REST_API_KEY!;
158
-
159
- export default async function handler(
160
- req: NextApiRequest,
161
- res: NextApiResponse
162
- ) {
163
- if (req.method !== "POST") {
164
- return res.status(405).json({ error: "Method not allowed" });
165
- }
166
-
167
- // TODO: Replace with your auth check (e.g., getServerSession, Clerk, JWT).
168
- const { uid } = req.body;
169
-
170
- if (!uid || typeof uid !== "string") {
171
- return res.status(400).json({ error: "Missing uid" });
172
- }
173
-
174
- const response = await fetch(
175
- `https://${APP_ID}.api-${REGION}.cometchat.io/v3/users/${encodeURIComponent(uid)}/auth_tokens`,
176
- {
177
- method: "POST",
178
- headers: {
179
- "Content-Type": "application/json",
180
- appId: APP_ID,
181
- apiKey: REST_API_KEY,
182
- },
183
- body: JSON.stringify({}),
184
- }
185
- );
186
-
187
- if (!response.ok) {
188
- const error = await response.text();
189
- console.error("CometChat token error:", error);
190
- return res.status(response.status).json({ error: "Failed to generate auth token" });
191
- }
192
-
193
- const data = await response.json();
194
- return res.status(200).json({ authToken: data.data.authToken });
195
- }
196
- ```
197
-
198
- ### React Router v7 (framework mode)
199
-
200
- In React Router framework mode, server logic lives in `action` functions within route modules. Create a resource route (no UI) for the token endpoint.
201
-
202
- `app/routes/api.cometchat-token.ts`
203
-
204
- ```typescript
205
- import type { ActionFunctionArgs } from "react-router";
206
-
207
- const APP_ID = process.env.COMETCHAT_APP_ID!;
208
- const REGION = process.env.COMETCHAT_REGION!;
209
- const REST_API_KEY = process.env.COMETCHAT_REST_API_KEY!;
210
-
211
- export async function action({ request }: ActionFunctionArgs) {
212
- if (request.method !== "POST") {
213
- return new Response("Method not allowed", { status: 405 });
214
- }
215
-
216
- // TODO: Replace with your auth check (e.g., session cookie, JWT).
217
- const body = await request.json();
218
- const uid = body.uid as string;
219
-
220
- if (!uid || typeof uid !== "string") {
221
- return Response.json({ error: "Missing uid" }, { status: 400 });
222
- }
223
-
224
- const response = await fetch(
225
- `https://${APP_ID}.api-${REGION}.cometchat.io/v3/users/${encodeURIComponent(uid)}/auth_tokens`,
226
- {
227
- method: "POST",
228
- headers: {
229
- "Content-Type": "application/json",
230
- appId: APP_ID,
231
- apiKey: REST_API_KEY,
232
- },
233
- body: JSON.stringify({}),
234
- }
235
- );
236
-
237
- if (!response.ok) {
238
- const error = await response.text();
239
- console.error("CometChat token error:", error);
240
- return Response.json(
241
- { error: "Failed to generate auth token" },
242
- { status: response.status }
243
- );
244
- }
245
-
246
- const data = await response.json();
247
- return Response.json({ authToken: data.data.authToken });
248
- }
249
- ```
250
-
251
- Register this route in your `routes.ts` (or `app/routes.ts`):
252
-
253
- ```typescript
254
- // Add to your route config:
255
- route("api/cometchat-token", "routes/api.cometchat-token.ts"),
256
- ```
257
-
258
- ### Express / Hono standalone (React + Vite projects)
259
-
260
- React/Vite projects have no built-in server. You need a separate backend. Here are patterns for the two most common choices.
261
-
262
- **Express:**
263
-
264
- ```typescript
265
- // server/index.ts (or server.js)
266
- import express from "express";
267
- import cors from "cors";
268
-
269
- const app = express();
270
- app.use(cors({ origin: "http://localhost:5173" })); // Your Vite dev server
271
- app.use(express.json());
272
-
273
- const APP_ID = process.env.COMETCHAT_APP_ID!;
274
- const REGION = process.env.COMETCHAT_REGION!;
275
- const REST_API_KEY = process.env.COMETCHAT_REST_API_KEY!;
276
-
277
- app.post("/api/cometchat-token", async (req, res) => {
278
- // TODO: Replace with your auth check.
279
- const { uid } = req.body;
280
-
281
- if (!uid || typeof uid !== "string") {
282
- return res.status(400).json({ error: "Missing uid" });
283
- }
284
-
285
- const response = await fetch(
286
- `https://${APP_ID}.api-${REGION}.cometchat.io/v3/users/${encodeURIComponent(uid)}/auth_tokens`,
287
- {
288
- method: "POST",
289
- headers: {
290
- "Content-Type": "application/json",
291
- appId: APP_ID,
292
- apiKey: REST_API_KEY,
293
- },
294
- body: JSON.stringify({}),
295
- }
296
- );
297
-
298
- if (!response.ok) {
299
- const error = await response.text();
300
- console.error("CometChat token error:", error);
301
- return res.status(response.status).json({ error: "Failed to generate auth token" });
302
- }
303
-
304
- const data = await response.json();
305
- return res.json({ authToken: data.data.authToken });
306
- });
307
-
308
- app.listen(3001, () => console.log("Server running on :3001"));
309
- ```
310
-
311
- **Hono:**
312
-
313
- ```typescript
314
- // server/index.ts
315
- import { Hono } from "hono";
316
- import { cors } from "hono/cors";
317
- import { serve } from "@hono/node-server";
318
-
319
- const app = new Hono();
320
- app.use("/*", cors({ origin: "http://localhost:5173" }));
321
-
322
- const APP_ID = process.env.COMETCHAT_APP_ID!;
323
- const REGION = process.env.COMETCHAT_REGION!;
324
- const REST_API_KEY = process.env.COMETCHAT_REST_API_KEY!;
325
-
326
- app.post("/api/cometchat-token", async (c) => {
327
- // TODO: Replace with your auth check.
328
- const { uid } = await c.req.json();
329
-
330
- if (!uid || typeof uid !== "string") {
331
- return c.json({ error: "Missing uid" }, 400);
332
- }
333
-
334
- const response = await fetch(
335
- `https://${APP_ID}.api-${REGION}.cometchat.io/v3/users/${encodeURIComponent(uid)}/auth_tokens`,
336
- {
337
- method: "POST",
338
- headers: {
339
- "Content-Type": "application/json",
340
- appId: APP_ID,
341
- apiKey: REST_API_KEY,
342
- },
343
- body: JSON.stringify({}),
344
- }
345
- );
346
-
347
- if (!response.ok) {
348
- const error = await response.text();
349
- console.error("CometChat token error:", error);
350
- return c.json({ error: "Failed to generate auth token" }, { status: response.status });
351
- }
352
-
353
- const data = await response.json();
354
- return c.json({ authToken: data.data.authToken });
355
- });
356
-
357
- serve({ fetch: app.fetch, port: 3001 });
358
- ```
359
-
360
- ### Astro
361
-
362
- `src/pages/api/cometchat-token.ts`
363
-
364
- Astro SSR endpoints work in hybrid or server mode. Make sure your `astro.config.mjs` has `output: "server"` or `output: "hybrid"`.
365
-
366
- ```typescript
367
- import type { APIRoute } from "astro";
368
-
369
- const APP_ID = import.meta.env.COMETCHAT_APP_ID;
370
- const REGION = import.meta.env.COMETCHAT_REGION;
371
- const REST_API_KEY = import.meta.env.COMETCHAT_REST_API_KEY;
372
-
373
- export const POST: APIRoute = async ({ request }) => {
374
- // TODO: Replace with your auth check (e.g., session cookie, Astro middleware).
375
- const body = await request.json();
376
- const uid = body.uid as string;
377
-
378
- if (!uid || typeof uid !== "string") {
379
- return new Response(JSON.stringify({ error: "Missing uid" }), {
380
- status: 400,
381
- headers: { "Content-Type": "application/json" },
382
- });
383
- }
384
-
385
- const response = await fetch(
386
- `https://${APP_ID}.api-${REGION}.cometchat.io/v3/users/${encodeURIComponent(uid)}/auth_tokens`,
387
- {
388
- method: "POST",
389
- headers: {
390
- "Content-Type": "application/json",
391
- appId: APP_ID,
392
- apiKey: REST_API_KEY,
393
- },
394
- body: JSON.stringify({}),
395
- }
396
- );
397
-
398
- if (!response.ok) {
399
- const error = await response.text();
400
- console.error("CometChat token error:", error);
401
- return new Response(
402
- JSON.stringify({ error: "Failed to generate auth token" }),
403
- { status: response.status, headers: { "Content-Type": "application/json" } }
404
- );
405
- }
406
-
407
- const data = await response.json();
408
- return new Response(JSON.stringify({ authToken: data.data.authToken }), {
409
- status: 200,
410
- headers: { "Content-Type": "application/json" },
411
- });
412
- };
413
- ```
414
-
415
- ---
416
-
417
- ## 4. Client-side changes
418
-
419
- The `cometchat-core` skill's `CometChatProvider` already supports both `authKey` (dev) and `authToken` (production) props. To switch to production mode:
420
-
421
- ### Step 1 — Create a hook to fetch the token
422
-
423
- ```typescript
424
- // hooks/useCometChatToken.ts
425
- "use client"; // Required for Next.js App Router; harmless elsewhere
426
-
427
- import { useState, useEffect } from "react";
428
-
429
- /**
430
- * Fetches a CometChat auth token from your server-side endpoint.
431
- * Call this after the user is authenticated in your app.
432
- */
433
- export function useCometChatToken(uid: string | null) {
434
- const [token, setToken] = useState<string | null>(null);
435
- const [error, setError] = useState<string | null>(null);
436
- const [loading, setLoading] = useState(false);
437
-
438
- useEffect(() => {
439
- if (!uid) return;
440
-
441
- let cancelled = false;
442
- setLoading(true);
443
-
444
- fetch("/api/cometchat-token", {
445
- method: "POST",
446
- headers: { "Content-Type": "application/json" },
447
- body: JSON.stringify({ uid }),
448
- })
449
- .then((res) => {
450
- if (!res.ok) throw new Error(`Token request failed: ${res.status}`);
451
- return res.json();
452
- })
453
- .then((data) => {
454
- if (!cancelled) {
455
- setToken(data.authToken);
456
- setLoading(false);
457
- }
458
- })
459
- .catch((err) => {
460
- if (!cancelled) {
461
- setError(String(err));
462
- setLoading(false);
463
- }
464
- });
465
-
466
- return () => {
467
- cancelled = true;
468
- };
469
- }, [uid]);
470
-
471
- return { token, error, loading };
472
- }
473
- ```
474
-
475
- ### Step 2 — Update the CometChatProvider usage
476
-
477
- **Before (dev mode):**
478
-
479
- ```typescript
480
- <CometChatProvider
481
- appId={import.meta.env.VITE_COMETCHAT_APP_ID}
482
- region={import.meta.env.VITE_COMETCHAT_REGION}
483
- authKey={import.meta.env.VITE_COMETCHAT_AUTH_KEY}
484
- uid="cometchat-uid-1"
485
- >
486
- <ChatPage />
487
- </CometChatProvider>
488
- ```
489
-
490
- **After (production mode):**
491
-
492
- ```typescript
493
- function ChatWrapper() {
494
- // Get the authenticated user's ID from your auth system
495
- const { user } = useAuth(); // Your auth hook (NextAuth, Clerk, Supabase, etc.)
496
- const { token, error, loading } = useCometChatToken(user?.id ?? null);
497
-
498
- if (!user) return <LoginPage />;
499
- if (loading) return <div>Connecting to chat...</div>;
500
- if (error) return <div>Chat connection failed: {error}</div>;
501
-
502
- return (
503
- <CometChatProvider
504
- appId={import.meta.env.VITE_COMETCHAT_APP_ID}
505
- region={import.meta.env.VITE_COMETCHAT_REGION}
506
- authToken={token!}
507
- uid={user.id}
508
- >
509
- <ChatPage />
510
- </CometChatProvider>
511
- );
512
- }
513
- ```
514
-
515
- Key changes:
516
- - Removed `authKey` prop entirely
517
- - Added `authToken` prop with the token from your server
518
- - `uid` comes from your auth system, not a hardcoded test user
519
- - The provider only renders after the token is fetched
520
-
521
- ### Step 3 — Handle token refresh on 401
522
-
523
- CometChat auth tokens expire. When a token expires, SDK calls will fail. Handle this in your provider:
524
-
525
- ```typescript
526
- // In your CometChatProvider or a wrapper:
527
- import { CometChat } from "@cometchat/chat-sdk-javascript";
528
-
529
- // Listen for auth errors
530
- CometChat.addConnectionListener(
531
- "auth-refresh-listener",
532
- new CometChat.ConnectionListener({
533
- onDisconnected: () => {
534
- console.log("CometChat disconnected — token may have expired");
535
- // Re-fetch token from your endpoint and call loginWithAuthToken again
536
- },
537
- })
538
- );
539
- ```
540
-
541
- A simpler approach: if any CometChat operation returns a 401 or auth error, re-fetch the token and call `CometChatUIKit.loginWithAuthToken(newToken)`.
542
-
543
- **Guard refresh calls with the same concurrency pattern.** If two components both see a 401 at the same time, two `loginWithAuthToken` calls race and the SDK throws *"Please wait until the previous login request ends."* Route token refresh through the same `ensureLoggedIn(uid, authToken)` helper defined in `cometchat-core`'s provider pattern — the module-level `loginInFlight` promise dedupes concurrent refreshes automatically.
544
-
545
- Concrete refresh handler — pair the helper from `cometchat-core` with the connection listener and a token-refetch path:
546
-
547
- ```typescript
548
- import { CometChat } from "@cometchat/chat-sdk-javascript";
549
- import { CometChatUIKit } from "@cometchat/chat-uikit-react";
550
-
551
- // Module-level — shared across every refresh attempt.
552
- // Identical shape to the one in cometchat-core § 2.
553
- let refreshInFlight: Promise<unknown> | null = null;
554
-
555
- async function refreshSession(uid: string): Promise<void> {
556
- if (refreshInFlight) {
557
- // Another component already triggered a refresh — wait for it,
558
- // don't fire a second loginWithAuthToken.
559
- await refreshInFlight;
560
- return;
561
- }
562
-
563
- refreshInFlight = (async () => {
564
- // 1. Fetch a fresh token from your server endpoint.
565
- // Your existing useCometChatToken hook (Step 1) calls /api/cometchat-token.
566
- // Extract that fetch into a helper so the refresh path can reuse it.
567
- const res = await fetch("/api/cometchat-token", {
568
- method: "POST",
569
- headers: { "Content-Type": "application/json" },
570
- body: JSON.stringify({ uid }),
571
- });
572
- if (!res.ok) throw new Error(`Token refresh failed: ${res.status}`);
573
- const { token } = (await res.json()) as { token: string };
574
-
575
- // 2. Re-authenticate with the new token. SDK swaps the in-memory
576
- // session — no full reload needed.
577
- await CometChatUIKit.loginWithAuthToken(token);
578
- })();
579
-
580
- try {
581
- await refreshInFlight;
582
- } finally {
583
- refreshInFlight = null;
584
- }
585
- }
586
-
587
- // Wire it into the connection listener so a disconnect triggers refresh.
588
- CometChat.addConnectionListener(
589
- "auth-refresh-listener",
590
- new CometChat.ConnectionListener({
591
- onDisconnected: async () => {
592
- // Web kit method is getLoggedinUser() (lowercase "i") and is ASYNC —
593
- // it returns a Promise, so you must await it (you can't chain ?.getUid()
594
- // on the call directly). The synchronous capital-I form is the Angular kit.
595
- const me = await CometChatUIKit.getLoggedinUser();
596
- const uid = me?.getUid();
597
- if (uid) {
598
- refreshSession(uid).catch((e) => {
599
- console.error("CometChat refresh failed; user may need to re-login", e);
600
- });
601
- }
602
- },
603
- }),
604
- );
605
- ```
606
-
607
- `refreshInFlight` mirrors `loginInFlight` from `cometchat-core` § 2 — same dedup pattern, separate promise so the initial-login and refresh paths don't accidentally serialize against each other. If the same component renders in StrictMode AND a 401 arrives during the second mount, the listener and the provider effect can both touch the SDK without colliding.
608
-
609
- ---
610
-
611
- ## 5. User management patterns
612
-
613
- In production, you need to keep CometChat users in sync with your app's users. CometChat users are managed via the REST API using the REST API key (server-only).
614
-
615
- ### Create user — on signup
616
-
617
- When a user signs up for your app, create a corresponding CometChat user.
618
-
619
- ```typescript
620
- // Server-side utility function
621
- async function createCometChatUser(uid: string, name: string, avatar?: string) {
622
- const response = await fetch(
623
- `https://${APP_ID}.api-${REGION}.cometchat.io/v3/users`,
624
- {
625
- method: "POST",
626
- headers: {
627
- "Content-Type": "application/json",
628
- appId: APP_ID,
629
- apiKey: REST_API_KEY,
630
- },
631
- body: JSON.stringify({
632
- uid,
633
- name,
634
- ...(avatar ? { avatar } : {}),
635
- }),
636
- }
637
- );
638
-
639
- if (!response.ok) {
640
- const error = await response.json();
641
- // If user already exists (409), that's OK — just log it
642
- if (response.status === 409) {
643
- console.log(`CometChat user ${uid} already exists`);
644
- return;
645
- }
646
- throw new Error(`Failed to create CometChat user: ${JSON.stringify(error)}`);
647
- }
648
- }
649
- ```
650
-
651
- ### Update user — on profile change
652
-
653
- When a user updates their name or avatar in your app, update the CometChat user.
654
-
655
- ```typescript
656
- async function updateCometChatUser(
657
- uid: string,
658
- updates: { name?: string; avatar?: string; metadata?: Record<string, unknown> }
659
- ) {
660
- const response = await fetch(
661
- `https://${APP_ID}.api-${REGION}.cometchat.io/v3/users/${encodeURIComponent(uid)}`,
662
- {
663
- method: "PUT",
664
- headers: {
665
- "Content-Type": "application/json",
666
- appId: APP_ID,
667
- apiKey: REST_API_KEY,
668
- },
669
- body: JSON.stringify(updates),
670
- }
671
- );
672
-
673
- if (!response.ok) {
674
- const error = await response.json();
675
- throw new Error(`Failed to update CometChat user: ${JSON.stringify(error)}`);
676
- }
677
- }
678
- ```
679
-
680
- ### Delete user — on account deletion
681
-
682
- When a user deletes their account, delete the CometChat user.
683
-
684
- ```typescript
685
- async function deleteCometChatUser(uid: string) {
686
- const response = await fetch(
687
- `https://${APP_ID}.api-${REGION}.cometchat.io/v3/users/${encodeURIComponent(uid)}`,
688
- {
689
- method: "DELETE",
690
- headers: {
691
- "Content-Type": "application/json",
692
- appId: APP_ID,
693
- apiKey: REST_API_KEY,
694
- },
695
- }
696
- );
697
-
698
- if (!response.ok) {
699
- const error = await response.json();
700
- throw new Error(`Failed to delete CometChat user: ${JSON.stringify(error)}`);
701
- }
702
- }
703
- ```
704
-
705
- ### Where to hook user management into common auth providers
706
-
707
- **NextAuth (next-auth):**
708
-
709
- ```typescript
710
- // app/api/auth/[...nextauth]/route.ts or pages/api/auth/[...nextauth].ts
711
- import NextAuth from "next-auth";
712
-
713
- export default NextAuth({
714
- // ... your providers ...
715
- events: {
716
- createUser: async ({ user }) => {
717
- await createCometChatUser(user.id, user.name ?? user.email ?? "User");
718
- },
719
- // Note: NextAuth doesn't have a deleteUser event by default.
720
- // Handle deletion in your account deletion endpoint.
721
- },
722
- });
723
- ```
724
-
725
- **Clerk:**
726
-
727
- ```typescript
728
- // Clerk webhook handler — app/api/webhooks/clerk/route.ts
729
- import { NextResponse } from "next/server";
730
- import { Webhook } from "svix";
731
-
732
- export async function POST(req: Request) {
733
- const body = await req.text();
734
- // Verify webhook signature with svix (see Clerk docs)
735
-
736
- const event = JSON.parse(body);
737
-
738
- switch (event.type) {
739
- case "user.created":
740
- await createCometChatUser(
741
- event.data.id,
742
- `${event.data.first_name} ${event.data.last_name}`.trim(),
743
- event.data.image_url
744
- );
745
- break;
746
- case "user.updated":
747
- await updateCometChatUser(event.data.id, {
748
- name: `${event.data.first_name} ${event.data.last_name}`.trim(),
749
- avatar: event.data.image_url,
750
- });
751
- break;
752
- case "user.deleted":
753
- await deleteCometChatUser(event.data.id);
754
- break;
755
- }
756
-
757
- return NextResponse.json({ received: true });
758
- }
759
- ```
760
-
761
- **Supabase Auth:**
762
-
763
- ```typescript
764
- // Supabase Edge Function or webhook handler
765
- // Supabase fires webhooks on auth events via Database Webhooks
766
- // pointing at the auth.users table.
767
-
768
- // In a Next.js API route triggered by Supabase webhook:
769
- export async function POST(req: Request) {
770
- const { type, record } = await req.json();
771
-
772
- if (type === "INSERT") {
773
- await createCometChatUser(
774
- record.id,
775
- record.raw_user_meta_data?.full_name ?? record.email ?? "User",
776
- record.raw_user_meta_data?.avatar_url
777
- );
778
- } else if (type === "UPDATE") {
779
- await updateCometChatUser(record.id, {
780
- name: record.raw_user_meta_data?.full_name,
781
- avatar: record.raw_user_meta_data?.avatar_url,
782
- });
783
- } else if (type === "DELETE") {
784
- await deleteCometChatUser(record.id);
785
- }
786
-
787
- return new Response("OK");
788
- }
789
- ```
790
-
791
- **Firebase Auth:**
792
-
793
- ```typescript
794
- // Firebase Cloud Function triggered by auth events
795
- import * as functions from "firebase-functions";
796
-
797
- export const onUserCreated = functions.auth.user().onCreate(async (user) => {
798
- await createCometChatUser(
799
- user.uid,
800
- user.displayName ?? user.email ?? "User",
801
- user.photoURL ?? undefined
802
- );
803
- });
804
-
805
- export const onUserDeleted = functions.auth.user().onDelete(async (user) => {
806
- await deleteCometChatUser(user.uid);
807
- });
808
-
809
- // For profile updates, call updateCometChatUser from your
810
- // profile update endpoint — Firebase Auth doesn't fire a
811
- // Cloud Function on profile changes.
812
- ```
813
-
814
- ---
815
-
816
- ## 6. Environment variables
817
-
818
- ### Production environment variables
819
-
820
- | Variable | Where | Description |
821
- |---|---|---|
822
- | `COMETCHAT_APP_ID` | Server + Client | Your app ID. Client-side copies use the framework prefix (`NEXT_PUBLIC_`, `VITE_`, `PUBLIC_`). |
823
- | `COMETCHAT_REGION` | Server + Client | Region code: `us`, `eu`, `in`. Client-side copies use the framework prefix. |
824
- | `COMETCHAT_REST_API_KEY` | SERVER ONLY | The REST API key from your CometChat dashboard. Used for token generation and user management. |
825
- | `COMETCHAT_AUTH_KEY` | REMOVE in production | The auth key used in dev mode. Remove it from `.env` in production. |
826
-
827
- ### Critical: REST API key must be server-only
828
-
829
- The REST API key grants full access to your CometChat app: creating users, generating tokens, deleting messages, managing groups. It MUST stay on the server.
830
-
831
- **NEVER prefix it with:**
832
- - `NEXT_PUBLIC_` (Next.js)
833
- - `VITE_` (Vite / React Router)
834
- - `PUBLIC_` (Astro)
835
- - `REACT_APP_` (Create React App)
836
-
837
- Any of these prefixes will bundle the key into your client-side JavaScript, exposing it to every visitor.
838
-
839
- ### Example .env file (production)
840
-
841
- ```bash
842
- # Client-side (with framework prefix)
843
- NEXT_PUBLIC_COMETCHAT_APP_ID=your-app-id
844
- NEXT_PUBLIC_COMETCHAT_REGION=us
845
-
846
- # Server-side ONLY (no prefix)
847
- COMETCHAT_APP_ID=your-app-id
848
- COMETCHAT_REGION=us
849
- COMETCHAT_REST_API_KEY=your-rest-api-key
850
-
851
- # REMOVED — do not include in production:
852
- # NEXT_PUBLIC_COMETCHAT_AUTH_KEY=...
853
- ```
854
-
855
- ### Finding the REST API key
856
-
857
- 1. Go to [app.cometchat.com](https://app.cometchat.com)
858
- 2. Select your app
859
- 3. Navigate to **API & Auth Keys**
860
- 4. Copy the **REST API Key** (it is different from the Auth Key)
861
-
862
- ---
863
-
864
- ## 7. Security checklist
865
-
866
- Before deploying to production, verify every item:
867
-
868
- - [ ] **Auth key removed from client-side env vars.** No `NEXT_PUBLIC_COMETCHAT_AUTH_KEY`, `VITE_COMETCHAT_AUTH_KEY`, or `PUBLIC_COMETCHAT_AUTH_KEY` in your `.env` file.
869
-
870
- - [ ] **REST API key is server-only.** The `COMETCHAT_REST_API_KEY` variable has NO framework prefix (`NEXT_PUBLIC_`, `VITE_`, `PUBLIC_`, `REACT_APP_`).
871
-
872
- - [ ] **Token endpoint validates the caller's identity.** The `/api/cometchat-token` endpoint checks that the request comes from an authenticated user (session cookie, JWT, etc.) before issuing a token. The example code includes `TODO` comments where you add this check.
873
-
874
- - [ ] **UID comes from the session, not the request.** In production, the token endpoint should derive the user's UID from the authenticated session, not from the request body. This prevents users from requesting tokens for other users.
875
-
876
- - [ ] **CORS configured.** If the token endpoint runs on a different origin than the frontend (e.g., Express on port 3001, Vite on port 5173), configure CORS to allow only your frontend origin.
877
-
878
- - [ ] **Rate limiting on the token endpoint.** Add rate limiting to prevent abuse. Most frameworks have middleware for this (e.g., `express-rate-limit`, Next.js middleware, Astro middleware).
879
-
880
- - [ ] **User management endpoints are authenticated.** The create/update/delete user endpoints must verify that the caller has permission to perform the operation (admin role, webhook signature, etc.).
881
-
882
- - [ ] **UIKitSettingsBuilder does NOT call `.setAuthKey()`.** In production, remove the `setAuthKey()` call entirely. The builder should only have `setAppId()` and `setRegion()`.
883
-
884
- ---
885
-
886
- ## 8. Rate limits and retry
887
-
888
- CometChat's REST API enforces per-app rate limits on the token and user-management endpoints. When limits are exceeded, the API returns **HTTP 429** with a `Retry-After` header (in seconds). Your server code should handle this gracefully — without retry logic, a burst of simultaneous logins on app startup can fail silently.
889
-
890
- ### What to retry, and what not to
891
-
892
- **Retry these:**
893
- - `429 Too Many Requests` — rate limit hit, back off and retry
894
- - `502 / 503 / 504` — transient upstream failures (gateway, unavailable, timeout)
895
- - Network errors (`ECONNRESET`, `ETIMEDOUT`) — local/transport issues
896
-
897
- **Do NOT retry these:**
898
- - `400 Bad Request` — malformed payload, retry will fail identically
899
- - `401 Unauthorized` / `403 Forbidden` — wrong API key or missing permissions, retry can't help
900
- - `404 Not Found` — wrong endpoint or user/group doesn't exist
901
-
902
- ### Exponential backoff pattern
903
-
904
- The minimum useful retry is exponential backoff with a cap and full jitter. The pattern below works in any Node.js / Edge runtime (Next.js API routes, Astro endpoints, Hono, Express):
905
-
906
- ```typescript
907
- interface RetryOptions {
908
- maxAttempts?: number; // default 3 (initial + 2 retries)
909
- baseDelayMs?: number; // default 500ms
910
- maxDelayMs?: number; // default 8000ms (cap)
911
- }
912
-
913
- async function fetchWithRetry(
914
- url: string,
915
- init: RequestInit,
916
- opts: RetryOptions = {},
917
- ): Promise<Response> {
918
- const { maxAttempts = 3, baseDelayMs = 500, maxDelayMs = 8000 } = opts;
919
- let lastError: unknown;
920
-
921
- for (let attempt = 1; attempt <= maxAttempts; attempt++) {
922
- try {
923
- const res = await fetch(url, init);
924
-
925
- // Retry 429 and 5xx (except 501/505 — those are protocol-level, not transient)
926
- if (res.status === 429 || (res.status >= 500 && res.status !== 501 && res.status !== 505)) {
927
- if (attempt === maxAttempts) return res; // give up, return the failed response
928
-
929
- // Prefer Retry-After header when present; otherwise exponential backoff
930
- const retryAfter = res.headers.get("Retry-After");
931
- const delayMs = retryAfter
932
- ? Math.min(parseInt(retryAfter, 10) * 1000, maxDelayMs)
933
- : Math.min(baseDelayMs * 2 ** (attempt - 1), maxDelayMs);
934
- const jitter = Math.random() * delayMs * 0.3; // ±30% full jitter
935
- await new Promise((resolve) => setTimeout(resolve, delayMs + jitter));
936
- continue;
937
- }
938
- return res;
939
- } catch (err) {
940
- lastError = err;
941
- if (attempt === maxAttempts) throw err;
942
- const delayMs = Math.min(baseDelayMs * 2 ** (attempt - 1), maxDelayMs);
943
- await new Promise((resolve) => setTimeout(resolve, delayMs));
944
- }
945
- }
946
- throw lastError;
947
- }
948
- ```
949
-
950
- ### Wire it into the token endpoint
951
-
952
- Replace the bare `fetch` in Section 3's patterns with `fetchWithRetry`:
953
-
954
- ```typescript
955
- // Before
956
- const response = await fetch(
957
- `https://${COMETCHAT_APP_ID}.api-${COMETCHAT_REGION}.cometchat.io/v3/users/${uid}/auth_tokens`,
958
- { method: "POST", headers: { ...headers } },
959
- );
960
-
961
- // After
962
- const response = await fetchWithRetry(
963
- `https://${COMETCHAT_APP_ID}.api-${COMETCHAT_REGION}.cometchat.io/v3/users/${uid}/auth_tokens`,
964
- { method: "POST", headers: { ...headers } },
965
- { maxAttempts: 3, baseDelayMs: 500, maxDelayMs: 4000 },
966
- );
967
- ```
968
-
969
- The same wrapper applies to user-management endpoints (create/update/delete) and any other CometChat REST call.
970
-
971
- ### Logging without leaking
972
-
973
- When logging retry attempts for observability, **never log the request headers as-is** — the `apiKey` and `appId` headers contain secrets. Safe shape:
974
-
975
- ```typescript
976
- console.warn("CometChat API rate-limited", {
977
- url: url.replace(/\/users\/[^/]+\/auth_tokens/, "/users/<redacted>/auth_tokens"),
978
- status: res.status,
979
- attempt,
980
- retryAfter: res.headers.get("Retry-After"),
981
- });
982
- ```
983
-
984
- Log the URL path, status, attempt number, and `Retry-After` — never the UID (user identifier), the API key, or the auth token.
985
-
986
- ### Circuit breaker (for high-traffic endpoints)
987
-
988
- If you're behind a load balancer with many parallel requests, a simple backoff isn't enough — every process independently retries, amplifying the pressure. For those setups, add a circuit breaker (e.g. `opossum` for Node.js) around `fetchWithRetry` so repeated failures stop traffic to CometChat for a cooldown window instead of continuing to hammer it.
989
-
990
- **Don't prematurely add a circuit breaker** — it's only worth it once you have production metrics showing sustained 429s under normal load.
991
-
992
- ---
993
-
994
- ## 9. CLI complement
995
-
996
- The CLI has `production-auth` and `add-user-mgmt` commands that can scaffold the token endpoint and user management routes for supported frameworks:
997
-
998
- ```bash
999
- npx @cometchat/skills-cli production-auth --json
1000
- npx @cometchat/skills-cli add-user-mgmt --json
1001
- ```
1002
-
1003
- These commands:
1004
- - Read `.cometchat/state.json` to detect the framework
1005
- - Create the API route file from a template
1006
- - Auto-patch the client login flow (replacing `CometChatUIKit.login(uid)` with `loginWithAuthToken`)
1007
- - Update the integration state
1008
-
1009
- **Supported frameworks:** Next.js, React Router (framework mode), Astro.
1010
-
1011
- **Not supported:** React/Vite (no built-in server). For React/Vite projects, use the Express or Hono patterns in Section 3 of this skill.
1012
-
1013
- The CLI templates are a starting point. This skill's patterns are more complete (they cover more frameworks, show auth provider integration, and include the security checklist). Use the CLI for scaffolding, then refer to this skill for the full picture.
1014
-
1015
- ---
1016
-
1017
- ## 10. Common mistakes
1018
-
1019
- 1. **Using the Auth Key instead of the REST API Key on the server.** The Auth Key (`setAuthKey()`) is for client-side dev mode. The REST API Key is for server-side API calls. They are different keys with different permissions.
1020
-
1021
- 2. **Exposing the REST API Key to the client.** Adding `NEXT_PUBLIC_` or `VITE_` prefix to the REST API Key variable bundles it into the client. This is worse than exposing the Auth Key because the REST API Key can create and delete users.
1022
-
1023
- 3. **Not validating the caller before issuing tokens.** If your token endpoint accepts any UID without checking the caller's identity, anyone can request tokens for any user. Always validate the session first.
1024
-
1025
- 4. **Forgetting to create CometChat users.** If you use token auth but never create the CometChat user via the REST API, `loginWithAuthToken` will fail with "User not found." Always create the CometChat user when the app user signs up.
1026
-
1027
- 5. **Hardcoding UIDs in production.** The example code uses `"cometchat-uid-1"` as a placeholder. In production, the UID must come from your authentication system.