@atproto/bsky 0.0.251 → 0.0.254

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 (463) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/dist/api/age-assurance/const.js +19 -19
  3. package/dist/api/age-assurance/const.js.map +1 -1
  4. package/dist/kws.d.ts +8 -0
  5. package/dist/kws.d.ts.map +1 -1
  6. package/dist/kws.js +53 -4
  7. package/dist/kws.js.map +1 -1
  8. package/dist/lexicons/app/bsky/actor/defs.defs.d.ts +6 -0
  9. package/dist/lexicons/app/bsky/actor/defs.defs.d.ts.map +1 -1
  10. package/dist/lexicons/app/bsky/actor/defs.defs.js +1 -0
  11. package/dist/lexicons/app/bsky/actor/defs.defs.js.map +1 -1
  12. package/package.json +28 -23
  13. package/bin/migration-create.ts +0 -46
  14. package/buf.gen.yaml +0 -12
  15. package/proto/bsky.proto +0 -1907
  16. package/proto/courier.proto +0 -84
  17. package/proto/rolodex.proto +0 -116
  18. package/src/api/age-assurance/const.ts +0 -203
  19. package/src/api/age-assurance/index.ts +0 -34
  20. package/src/api/age-assurance/kws/age-verified.test.ts +0 -98
  21. package/src/api/age-assurance/kws/age-verified.ts +0 -81
  22. package/src/api/age-assurance/kws/const.ts +0 -33
  23. package/src/api/age-assurance/kws/external-payload.test.ts +0 -72
  24. package/src/api/age-assurance/kws/external-payload.ts +0 -149
  25. package/src/api/age-assurance/redirects/kws-age-verified.ts +0 -107
  26. package/src/api/age-assurance/stash.ts +0 -23
  27. package/src/api/age-assurance/types.ts +0 -10
  28. package/src/api/age-assurance/util.ts +0 -68
  29. package/src/api/age-assurance/webhooks/kws-age-verified.ts +0 -75
  30. package/src/api/app/bsky/actor/getProfile.ts +0 -106
  31. package/src/api/app/bsky/actor/getProfiles.ts +0 -99
  32. package/src/api/app/bsky/actor/getSuggestions.ts +0 -163
  33. package/src/api/app/bsky/actor/searchActors.ts +0 -171
  34. package/src/api/app/bsky/actor/searchActorsTypeahead.ts +0 -164
  35. package/src/api/app/bsky/ageassurance/begin.ts +0 -175
  36. package/src/api/app/bsky/ageassurance/getConfig.ts +0 -16
  37. package/src/api/app/bsky/ageassurance/getState.ts +0 -58
  38. package/src/api/app/bsky/bookmark/createBookmark.ts +0 -39
  39. package/src/api/app/bsky/bookmark/deleteBookmark.ts +0 -32
  40. package/src/api/app/bsky/bookmark/getBookmarks.ts +0 -97
  41. package/src/api/app/bsky/bookmark/util.ts +0 -13
  42. package/src/api/app/bsky/contact/dismissMatch.ts +0 -26
  43. package/src/api/app/bsky/contact/getMatches.ts +0 -111
  44. package/src/api/app/bsky/contact/getSyncStatus.ts +0 -38
  45. package/src/api/app/bsky/contact/importContacts.ts +0 -119
  46. package/src/api/app/bsky/contact/removeData.ts +0 -25
  47. package/src/api/app/bsky/contact/sendNotification.ts +0 -33
  48. package/src/api/app/bsky/contact/startPhoneVerification.ts +0 -26
  49. package/src/api/app/bsky/contact/util.ts +0 -92
  50. package/src/api/app/bsky/contact/verifyPhone.ts +0 -29
  51. package/src/api/app/bsky/draft/createDraft.ts +0 -45
  52. package/src/api/app/bsky/draft/deleteDraft.ts +0 -20
  53. package/src/api/app/bsky/draft/getDrafts.ts +0 -44
  54. package/src/api/app/bsky/draft/updateDraft.ts +0 -26
  55. package/src/api/app/bsky/embed/getEmbedExternalView.ts +0 -154
  56. package/src/api/app/bsky/feed/getActorFeeds.ts +0 -101
  57. package/src/api/app/bsky/feed/getActorLikes.ts +0 -128
  58. package/src/api/app/bsky/feed/getAuthorFeed.ts +0 -279
  59. package/src/api/app/bsky/feed/getFeed.ts +0 -282
  60. package/src/api/app/bsky/feed/getFeedGenerator.ts +0 -68
  61. package/src/api/app/bsky/feed/getFeedGenerators.ts +0 -86
  62. package/src/api/app/bsky/feed/getLikes.ts +0 -151
  63. package/src/api/app/bsky/feed/getListFeed.ts +0 -147
  64. package/src/api/app/bsky/feed/getPostThread.ts +0 -156
  65. package/src/api/app/bsky/feed/getPosts.ts +0 -100
  66. package/src/api/app/bsky/feed/getQuotes.ts +0 -122
  67. package/src/api/app/bsky/feed/getRepostedBy.ts +0 -121
  68. package/src/api/app/bsky/feed/getSuggestedFeeds.ts +0 -39
  69. package/src/api/app/bsky/feed/getTimeline.ts +0 -127
  70. package/src/api/app/bsky/feed/searchPosts.ts +0 -274
  71. package/src/api/app/bsky/feed/searchPostsV2.ts +0 -243
  72. package/src/api/app/bsky/graph/getActorStarterPacks.ts +0 -103
  73. package/src/api/app/bsky/graph/getBlocks.ts +0 -94
  74. package/src/api/app/bsky/graph/getFollowers.ts +0 -153
  75. package/src/api/app/bsky/graph/getFollows.ts +0 -151
  76. package/src/api/app/bsky/graph/getKnownFollowers.ts +0 -123
  77. package/src/api/app/bsky/graph/getList.ts +0 -152
  78. package/src/api/app/bsky/graph/getListBlocks.ts +0 -87
  79. package/src/api/app/bsky/graph/getListMutes.ts +0 -87
  80. package/src/api/app/bsky/graph/getLists.ts +0 -125
  81. package/src/api/app/bsky/graph/getListsWithMembership.ts +0 -146
  82. package/src/api/app/bsky/graph/getMutes.ts +0 -87
  83. package/src/api/app/bsky/graph/getRelationships.ts +0 -58
  84. package/src/api/app/bsky/graph/getStarterPack.ts +0 -82
  85. package/src/api/app/bsky/graph/getStarterPacks.ts +0 -86
  86. package/src/api/app/bsky/graph/getStarterPacksWithMembership.ts +0 -136
  87. package/src/api/app/bsky/graph/getSuggestedFollowsByActor.ts +0 -171
  88. package/src/api/app/bsky/graph/muteActor.ts +0 -24
  89. package/src/api/app/bsky/graph/muteActorList.ts +0 -19
  90. package/src/api/app/bsky/graph/muteThread.ts +0 -19
  91. package/src/api/app/bsky/graph/searchStarterPacks.ts +0 -169
  92. package/src/api/app/bsky/graph/unmuteActor.ts +0 -21
  93. package/src/api/app/bsky/graph/unmuteActorList.ts +0 -19
  94. package/src/api/app/bsky/graph/unmuteThread.ts +0 -19
  95. package/src/api/app/bsky/labeler/getServices.ts +0 -41
  96. package/src/api/app/bsky/notification/getPreferences.ts +0 -49
  97. package/src/api/app/bsky/notification/getUnreadCount.ts +0 -83
  98. package/src/api/app/bsky/notification/listActivitySubscriptions.ts +0 -116
  99. package/src/api/app/bsky/notification/listNotifications.ts +0 -272
  100. package/src/api/app/bsky/notification/putActivitySubscription.ts +0 -69
  101. package/src/api/app/bsky/notification/putPreferences.ts +0 -17
  102. package/src/api/app/bsky/notification/putPreferencesV2.ts +0 -64
  103. package/src/api/app/bsky/notification/registerPush.ts +0 -40
  104. package/src/api/app/bsky/notification/unregisterPush.ts +0 -39
  105. package/src/api/app/bsky/notification/updateSeen.ts +0 -52
  106. package/src/api/app/bsky/notification/util.ts +0 -134
  107. package/src/api/app/bsky/unspecced/getAgeAssuranceState.ts +0 -48
  108. package/src/api/app/bsky/unspecced/getConfig.ts +0 -20
  109. package/src/api/app/bsky/unspecced/getOnboardingSuggestedStarterPacks.ts +0 -162
  110. package/src/api/app/bsky/unspecced/getPopularFeedGenerators.ts +0 -91
  111. package/src/api/app/bsky/unspecced/getPostThreadOtherV2.ts +0 -126
  112. package/src/api/app/bsky/unspecced/getPostThreadV2.ts +0 -148
  113. package/src/api/app/bsky/unspecced/getSuggestedFeeds.ts +0 -100
  114. package/src/api/app/bsky/unspecced/getSuggestedOnboardingUsers.ts +0 -143
  115. package/src/api/app/bsky/unspecced/getSuggestedStarterPacks.ts +0 -165
  116. package/src/api/app/bsky/unspecced/getSuggestedUsers.ts +0 -183
  117. package/src/api/app/bsky/unspecced/getSuggestedUsersForDiscover.ts +0 -175
  118. package/src/api/app/bsky/unspecced/getSuggestedUsersForExplore.ts +0 -178
  119. package/src/api/app/bsky/unspecced/getSuggestedUsersForSeeMore.ts +0 -178
  120. package/src/api/app/bsky/unspecced/getTaggedSuggestions.ts +0 -27
  121. package/src/api/app/bsky/unspecced/getTrendingTopics.ts +0 -96
  122. package/src/api/app/bsky/unspecced/getTrends.ts +0 -162
  123. package/src/api/app/bsky/unspecced/initAgeAssurance.ts +0 -150
  124. package/src/api/blob-dispatcher.ts +0 -41
  125. package/src/api/blob-resolver.ts +0 -401
  126. package/src/api/com/atproto/admin/getAccountInfos.ts +0 -49
  127. package/src/api/com/atproto/admin/getSubjectStatus.ts +0 -79
  128. package/src/api/com/atproto/admin/updateSubjectStatus.ts +0 -80
  129. package/src/api/com/atproto/identity/resolveHandle.ts +0 -19
  130. package/src/api/com/atproto/label/queryLabels.ts +0 -42
  131. package/src/api/com/atproto/repo/getRecord.ts +0 -44
  132. package/src/api/com/atproto/temp/fetchLabels.ts +0 -9
  133. package/src/api/external.ts +0 -15
  134. package/src/api/health.ts +0 -47
  135. package/src/api/index.ts +0 -216
  136. package/src/api/internal/bsky/actor/getProfiles.ts +0 -87
  137. package/src/api/kws/api.ts +0 -113
  138. package/src/api/kws/index.ts +0 -29
  139. package/src/api/kws/types.ts +0 -78
  140. package/src/api/kws/util.test.ts +0 -50
  141. package/src/api/kws/util.ts +0 -109
  142. package/src/api/kws/webhook.ts +0 -134
  143. package/src/api/sitemap.ts +0 -76
  144. package/src/api/util.ts +0 -45
  145. package/src/api/well-known.ts +0 -44
  146. package/src/auth-verifier.ts +0 -522
  147. package/src/bsync.ts +0 -41
  148. package/src/cache/read-through.ts +0 -157
  149. package/src/config.ts +0 -719
  150. package/src/context.ts +0 -143
  151. package/src/courier.ts +0 -41
  152. package/src/data-plane/client/hosts.ts +0 -103
  153. package/src/data-plane/client/index.ts +0 -125
  154. package/src/data-plane/client/util.test.ts +0 -29
  155. package/src/data-plane/client/util.ts +0 -74
  156. package/src/data-plane/index.ts +0 -2
  157. package/src/data-plane/server/background.ts +0 -66
  158. package/src/data-plane/server/bsync-subscription.ts +0 -590
  159. package/src/data-plane/server/db/database-schema.ts +0 -90
  160. package/src/data-plane/server/db/db.ts +0 -204
  161. package/src/data-plane/server/db/index.ts +0 -2
  162. package/src/data-plane/server/db/migrations/20230309T045948368Z-init.ts +0 -305
  163. package/src/data-plane/server/db/migrations/20230408T152211201Z-notification-init.ts +0 -25
  164. package/src/data-plane/server/db/migrations/20230417T210628672Z-moderation-init.ts +0 -127
  165. package/src/data-plane/server/db/migrations/20230420T211446071Z-did-cache.ts +0 -14
  166. package/src/data-plane/server/db/migrations/20230427T194702079Z-notif-record-index.ts +0 -14
  167. package/src/data-plane/server/db/migrations/20230605T144730094Z-post-profile-aggs.ts +0 -23
  168. package/src/data-plane/server/db/migrations/20230607T211442112Z-feed-generator-init.ts +0 -34
  169. package/src/data-plane/server/db/migrations/20230608T155101190Z-algo-whats-hot-view.ts +0 -85
  170. package/src/data-plane/server/db/migrations/20230608T201813132Z-mute-lists.ts +0 -78
  171. package/src/data-plane/server/db/migrations/20230608T205147239Z-mutes.ts +0 -15
  172. package/src/data-plane/server/db/migrations/20230609T153623961Z-blocks.ts +0 -33
  173. package/src/data-plane/server/db/migrations/20230609T232122649Z-actor-deletion-indexes.ts +0 -27
  174. package/src/data-plane/server/db/migrations/20230610T203555962Z-suggested-follows.ts +0 -13
  175. package/src/data-plane/server/db/migrations/20230611T215300060Z-actor-state.ts +0 -13
  176. package/src/data-plane/server/db/migrations/20230620T161134972Z-post-langs.ts +0 -9
  177. package/src/data-plane/server/db/migrations/20230627T212437895Z-optional-handle.ts +0 -15
  178. package/src/data-plane/server/db/migrations/20230629T220835893Z-remove-post-hierarchy.ts +0 -32
  179. package/src/data-plane/server/db/migrations/20230703T045536691Z-feed-and-label-indices.ts +0 -31
  180. package/src/data-plane/server/db/migrations/20230720T164800037Z-posts-cursor-idx.ts +0 -19
  181. package/src/data-plane/server/db/migrations/20230807T035309811Z-feed-item-delete-invite-for-user-idx.ts +0 -14
  182. package/src/data-plane/server/db/migrations/20230808T172902639Z-repo-rev.ts +0 -12
  183. package/src/data-plane/server/db/migrations/20230810T203349843Z-action-duration.ts +0 -23
  184. package/src/data-plane/server/db/migrations/20230817T195936007Z-native-notifications.ts +0 -16
  185. package/src/data-plane/server/db/migrations/20230830T205507322Z-suggested-feeds.ts +0 -13
  186. package/src/data-plane/server/db/migrations/20230904T211011773Z-block-lists.ts +0 -24
  187. package/src/data-plane/server/db/migrations/20230906T222220386Z-thread-gating.ts +0 -27
  188. package/src/data-plane/server/db/migrations/20230920T213858047Z-add-tags-to-post.ts +0 -9
  189. package/src/data-plane/server/db/migrations/20230929T192920807Z-record-cursor-indexes.ts +0 -40
  190. package/src/data-plane/server/db/migrations/20231003T202833377Z-create-moderation-subject-status.ts +0 -123
  191. package/src/data-plane/server/db/migrations/20231220T225126090Z-blob-takedowns.ts +0 -66
  192. package/src/data-plane/server/db/migrations/20240124T023719200Z-tagged-suggestions.ts +0 -15
  193. package/src/data-plane/server/db/migrations/20240226T225725627Z-labelers.ts +0 -27
  194. package/src/data-plane/server/db/migrations/20240530T170337073Z-account-deactivation.ts +0 -12
  195. package/src/data-plane/server/db/migrations/20240606T171229898Z-thread-mutes.ts +0 -15
  196. package/src/data-plane/server/db/migrations/20240606T222548219Z-starter-packs.ts +0 -45
  197. package/src/data-plane/server/db/migrations/20240719T203853939Z-priority-notifs.ts +0 -25
  198. package/src/data-plane/server/db/migrations/20240723T220700077Z-quotes-post-aggs.ts +0 -12
  199. package/src/data-plane/server/db/migrations/20240723T220703655Z-quotes.ts +0 -28
  200. package/src/data-plane/server/db/migrations/20240801T193939827Z-post-gate.ts +0 -17
  201. package/src/data-plane/server/db/migrations/20240808T224251220Z-post-gate-flags.ts +0 -25
  202. package/src/data-plane/server/db/migrations/20240829T211238293Z-simplify-actor-sync.ts +0 -23
  203. package/src/data-plane/server/db/migrations/20240831T134810923Z-pinned-posts.ts +0 -17
  204. package/src/data-plane/server/db/migrations/20241114T153108102Z-add-starter-packs-name.ts +0 -19
  205. package/src/data-plane/server/db/migrations/20250116T222618297Z-post-embed-video.ts +0 -17
  206. package/src/data-plane/server/db/migrations/20250207T174822012Z-add-label-exp.ts +0 -9
  207. package/src/data-plane/server/db/migrations/20250404T163421487Z-verifications.ts +0 -39
  208. package/src/data-plane/server/db/migrations/20250526T023712742Z-like-repost-via.ts +0 -17
  209. package/src/data-plane/server/db/migrations/20250528T221913281Z-add-record-tags.ts +0 -9
  210. package/src/data-plane/server/db/migrations/20250602T190357447Z-add-private-data.ts +0 -22
  211. package/src/data-plane/server/db/migrations/20250611T140649895Z-add-activity-subscription.ts +0 -22
  212. package/src/data-plane/server/db/migrations/20250627T025331240Z-add-actor-age-assurance-columns.ts +0 -22
  213. package/src/data-plane/server/db/migrations/20250812T183735692Z-add-bookmarks.ts +0 -23
  214. package/src/data-plane/server/db/migrations/20250813T174955711Z-add-post-agg-bookmarks.ts +0 -12
  215. package/src/data-plane/server/db/migrations/20251120T004738098Z-update-actor-age-assurance-v2.ts +0 -28
  216. package/src/data-plane/server/db/migrations/20260112T133951271Z-add-drafts.ts +0 -24
  217. package/src/data-plane/server/db/migrations/20260604T224952774Z-post-embed-gallery-image.ts +0 -19
  218. package/src/data-plane/server/db/migrations/index.ts +0 -60
  219. package/src/data-plane/server/db/migrations/provider.ts +0 -26
  220. package/src/data-plane/server/db/pagination.ts +0 -341
  221. package/src/data-plane/server/db/tables/activity-subscription.ts +0 -12
  222. package/src/data-plane/server/db/tables/actor-block.ts +0 -14
  223. package/src/data-plane/server/db/tables/actor-state.ts +0 -10
  224. package/src/data-plane/server/db/tables/actor-sync.ts +0 -9
  225. package/src/data-plane/server/db/tables/actor.ts +0 -19
  226. package/src/data-plane/server/db/tables/algo.ts +0 -11
  227. package/src/data-plane/server/db/tables/blob-takedown.ts +0 -9
  228. package/src/data-plane/server/db/tables/bookmark.ts +0 -11
  229. package/src/data-plane/server/db/tables/did-cache.ts +0 -13
  230. package/src/data-plane/server/db/tables/draft.ts +0 -11
  231. package/src/data-plane/server/db/tables/duplicate-record.ts +0 -12
  232. package/src/data-plane/server/db/tables/feed-generator.ts +0 -21
  233. package/src/data-plane/server/db/tables/feed-item.ts +0 -12
  234. package/src/data-plane/server/db/tables/follow.ts +0 -15
  235. package/src/data-plane/server/db/tables/label.ts +0 -13
  236. package/src/data-plane/server/db/tables/labeler.ts +0 -16
  237. package/src/data-plane/server/db/tables/like.ts +0 -18
  238. package/src/data-plane/server/db/tables/list-block.ts +0 -15
  239. package/src/data-plane/server/db/tables/list-item.ts +0 -16
  240. package/src/data-plane/server/db/tables/list-mute.ts +0 -9
  241. package/src/data-plane/server/db/tables/list.ts +0 -19
  242. package/src/data-plane/server/db/tables/mute.ts +0 -9
  243. package/src/data-plane/server/db/tables/notification-push-token.ts +0 -10
  244. package/src/data-plane/server/db/tables/notification.ts +0 -16
  245. package/src/data-plane/server/db/tables/post-agg.ts +0 -16
  246. package/src/data-plane/server/db/tables/post-embed.ts +0 -47
  247. package/src/data-plane/server/db/tables/post-gate.ts +0 -12
  248. package/src/data-plane/server/db/tables/post.ts +0 -28
  249. package/src/data-plane/server/db/tables/private-data.ts +0 -13
  250. package/src/data-plane/server/db/tables/profile-agg.ts +0 -14
  251. package/src/data-plane/server/db/tables/profile.ts +0 -17
  252. package/src/data-plane/server/db/tables/quote.ts +0 -15
  253. package/src/data-plane/server/db/tables/record.ts +0 -15
  254. package/src/data-plane/server/db/tables/repost.ts +0 -18
  255. package/src/data-plane/server/db/tables/starter-pack.ts +0 -17
  256. package/src/data-plane/server/db/tables/subscription.ts +0 -9
  257. package/src/data-plane/server/db/tables/suggested-feed.ts +0 -10
  258. package/src/data-plane/server/db/tables/suggested-follow.ts +0 -10
  259. package/src/data-plane/server/db/tables/tagged-suggestion.ts +0 -11
  260. package/src/data-plane/server/db/tables/thread-gate.ts +0 -12
  261. package/src/data-plane/server/db/tables/thread-mute.ts +0 -9
  262. package/src/data-plane/server/db/tables/verification.ts +0 -20
  263. package/src/data-plane/server/db/tables/view-param.ts +0 -12
  264. package/src/data-plane/server/db/types.ts +0 -12
  265. package/src/data-plane/server/db/util.ts +0 -67
  266. package/src/data-plane/server/index.ts +0 -44
  267. package/src/data-plane/server/indexing/index.ts +0 -458
  268. package/src/data-plane/server/indexing/plugins/block.ts +0 -84
  269. package/src/data-plane/server/indexing/plugins/chat-declaration.ts +0 -60
  270. package/src/data-plane/server/indexing/plugins/feed-generator.ts +0 -80
  271. package/src/data-plane/server/indexing/plugins/follow.ts +0 -132
  272. package/src/data-plane/server/indexing/plugins/germ-declaration.ts +0 -57
  273. package/src/data-plane/server/indexing/plugins/labeler.ts +0 -74
  274. package/src/data-plane/server/indexing/plugins/like.ts +0 -151
  275. package/src/data-plane/server/indexing/plugins/list-block.ts +0 -84
  276. package/src/data-plane/server/indexing/plugins/list-item.ts +0 -92
  277. package/src/data-plane/server/indexing/plugins/list.ts +0 -80
  278. package/src/data-plane/server/indexing/plugins/notif-declaration.ts +0 -57
  279. package/src/data-plane/server/indexing/plugins/post-gate.ts +0 -101
  280. package/src/data-plane/server/indexing/plugins/post.ts +0 -675
  281. package/src/data-plane/server/indexing/plugins/profile.ts +0 -90
  282. package/src/data-plane/server/indexing/plugins/repost.ts +0 -176
  283. package/src/data-plane/server/indexing/plugins/starter-pack.ts +0 -74
  284. package/src/data-plane/server/indexing/plugins/status.ts +0 -57
  285. package/src/data-plane/server/indexing/plugins/thread-gate.ts +0 -101
  286. package/src/data-plane/server/indexing/plugins/verification.ts +0 -113
  287. package/src/data-plane/server/indexing/processor.ts +0 -292
  288. package/src/data-plane/server/routes/activity-subscription.ts +0 -84
  289. package/src/data-plane/server/routes/blocks.ts +0 -127
  290. package/src/data-plane/server/routes/bookmarks.ts +0 -83
  291. package/src/data-plane/server/routes/drafts.ts +0 -37
  292. package/src/data-plane/server/routes/feed-gens.ts +0 -89
  293. package/src/data-plane/server/routes/feeds.ts +0 -176
  294. package/src/data-plane/server/routes/follows.ts +0 -141
  295. package/src/data-plane/server/routes/identity.ts +0 -59
  296. package/src/data-plane/server/routes/index.ts +0 -67
  297. package/src/data-plane/server/routes/interactions.ts +0 -120
  298. package/src/data-plane/server/routes/labels.ts +0 -55
  299. package/src/data-plane/server/routes/likes.ts +0 -92
  300. package/src/data-plane/server/routes/lists.ts +0 -88
  301. package/src/data-plane/server/routes/moderation.ts +0 -102
  302. package/src/data-plane/server/routes/mutes.ts +0 -195
  303. package/src/data-plane/server/routes/notifs.ts +0 -239
  304. package/src/data-plane/server/routes/profile.ts +0 -220
  305. package/src/data-plane/server/routes/quotes.ts +0 -32
  306. package/src/data-plane/server/routes/records.ts +0 -119
  307. package/src/data-plane/server/routes/relationships.ts +0 -174
  308. package/src/data-plane/server/routes/reposts.ts +0 -76
  309. package/src/data-plane/server/routes/search.ts +0 -181
  310. package/src/data-plane/server/routes/site-standard.ts +0 -12
  311. package/src/data-plane/server/routes/sitemap.ts +0 -43
  312. package/src/data-plane/server/routes/starter-packs.ts +0 -32
  313. package/src/data-plane/server/routes/suggestions.ts +0 -175
  314. package/src/data-plane/server/routes/sync.ts +0 -16
  315. package/src/data-plane/server/routes/threads.ts +0 -33
  316. package/src/data-plane/server/subscription.ts +0 -152
  317. package/src/data-plane/server/util.ts +0 -202
  318. package/src/error.ts +0 -12
  319. package/src/etcd.ts +0 -90
  320. package/src/feature-gates/README.md +0 -83
  321. package/src/feature-gates/gates.ts +0 -25
  322. package/src/feature-gates/index.ts +0 -235
  323. package/src/feature-gates/metrics.test.ts +0 -196
  324. package/src/feature-gates/metrics.ts +0 -107
  325. package/src/feature-gates/types.ts +0 -62
  326. package/src/feature-gates/utils.test.ts +0 -66
  327. package/src/feature-gates/utils.ts +0 -135
  328. package/src/hydration/actor.ts +0 -578
  329. package/src/hydration/external.test.ts +0 -281
  330. package/src/hydration/external.ts +0 -268
  331. package/src/hydration/feed.ts +0 -455
  332. package/src/hydration/graph.ts +0 -354
  333. package/src/hydration/hydrator.ts +0 -1835
  334. package/src/hydration/label.ts +0 -207
  335. package/src/hydration/util.ts +0 -199
  336. package/src/image/index.ts +0 -2
  337. package/src/image/invalidator.ts +0 -33
  338. package/src/image/logger.ts +0 -6
  339. package/src/image/server.ts +0 -228
  340. package/src/image/sharp.ts +0 -89
  341. package/src/image/uri.ts +0 -114
  342. package/src/image/util.ts +0 -41
  343. package/src/index.ts +0 -312
  344. package/src/kws.ts +0 -197
  345. package/src/logger.ts +0 -40
  346. package/src/pipeline.ts +0 -60
  347. package/src/redis.ts +0 -205
  348. package/src/rolodex.ts +0 -42
  349. package/src/stash.ts +0 -76
  350. package/src/util/debug.ts +0 -10
  351. package/src/util/http.ts +0 -42
  352. package/src/util/retry.ts +0 -10
  353. package/src/util/standard-site.test.ts +0 -423
  354. package/src/util/standard-site.ts +0 -196
  355. package/src/util/uris.ts +0 -38
  356. package/src/util.ts +0 -48
  357. package/src/views/index.ts +0 -2783
  358. package/src/views/threads-v2.ts +0 -510
  359. package/src/views/types.ts +0 -193
  360. package/src/views/util.ts +0 -114
  361. package/test.env +0 -2
  362. package/tests/__snapshots__/feed-generation.test.ts.snap +0 -2510
  363. package/tests/_util.ts +0 -292
  364. package/tests/admin/admin-auth.test.ts +0 -190
  365. package/tests/admin/moderation.test.ts +0 -222
  366. package/tests/auth.test.ts +0 -90
  367. package/tests/blob-resolver.test.ts +0 -125
  368. package/tests/data-plane/__snapshots__/indexing.test.ts.snap +0 -887
  369. package/tests/data-plane/db.test.ts +0 -189
  370. package/tests/data-plane/duplicate-records.test.ts +0 -156
  371. package/tests/data-plane/handle-invalidation.test.ts +0 -153
  372. package/tests/data-plane/indexing.test.ts +0 -827
  373. package/tests/data-plane/subscription.test.ts +0 -128
  374. package/tests/data-plane/thread-mutes.test.ts +0 -175
  375. package/tests/entryway-auth.test.ts +0 -177
  376. package/tests/etcd.test.ts +0 -302
  377. package/tests/feed-generation.test.ts +0 -965
  378. package/tests/hydration/util.test.ts +0 -119
  379. package/tests/image/server.test.ts +0 -97
  380. package/tests/image/sharp.test.ts +0 -199
  381. package/tests/image/uri.test.ts +0 -106
  382. package/tests/label-hydration.test.ts +0 -245
  383. package/tests/postgates.test.ts +0 -182
  384. package/tests/query-labels.test.ts +0 -85
  385. package/tests/redis-cache.test.ts +0 -230
  386. package/tests/seed/feed-hidden-replies.ts +0 -63
  387. package/tests/seed/get-suggested-starter-packs.ts +0 -64
  388. package/tests/seed/get-trends.ts +0 -71
  389. package/tests/seed/known-followers.ts +0 -111
  390. package/tests/seed/postgates.ts +0 -57
  391. package/tests/server.test.ts +0 -115
  392. package/tests/sitemap.test.ts +0 -75
  393. package/tests/stash.test.ts +0 -180
  394. package/tests/utils.test.ts +0 -36
  395. package/tests/views/__snapshots__/actor-search.test.ts.snap +0 -155
  396. package/tests/views/__snapshots__/author-feed.test.ts.snap +0 -6301
  397. package/tests/views/__snapshots__/block-lists.test.ts.snap +0 -690
  398. package/tests/views/__snapshots__/blocks.test.ts.snap +0 -462
  399. package/tests/views/__snapshots__/bookmarks.test.ts.snap +0 -379
  400. package/tests/views/__snapshots__/follows.test.ts.snap +0 -798
  401. package/tests/views/__snapshots__/labeler-service.test.ts.snap +0 -233
  402. package/tests/views/__snapshots__/likes.test.ts.snap +0 -124
  403. package/tests/views/__snapshots__/list-feed.test.ts.snap +0 -883
  404. package/tests/views/__snapshots__/lists.test.ts.snap +0 -650
  405. package/tests/views/__snapshots__/mute-lists.test.ts.snap +0 -705
  406. package/tests/views/__snapshots__/mutes.test.ts.snap +0 -353
  407. package/tests/views/__snapshots__/notifications.test.ts.snap +0 -3074
  408. package/tests/views/__snapshots__/posts.test.ts.snap +0 -1019
  409. package/tests/views/__snapshots__/profile.test.ts.snap +0 -811
  410. package/tests/views/__snapshots__/quotes.test.ts.snap +0 -445
  411. package/tests/views/__snapshots__/reposts.test.ts.snap +0 -112
  412. package/tests/views/__snapshots__/starter-packs.test.ts.snap +0 -836
  413. package/tests/views/__snapshots__/thread-v2.test.ts.snap +0 -1298
  414. package/tests/views/__snapshots__/thread.test.ts.snap +0 -2051
  415. package/tests/views/__snapshots__/threadgating.test.ts.snap +0 -189
  416. package/tests/views/__snapshots__/timeline.test.ts.snap +0 -7252
  417. package/tests/views/account-deactivation.test.ts +0 -81
  418. package/tests/views/actor-likes.test.ts +0 -138
  419. package/tests/views/actor-search.test.ts +0 -261
  420. package/tests/views/age-assurance-v2.test.ts +0 -823
  421. package/tests/views/age-assurance.test.ts +0 -479
  422. package/tests/views/author-feed.test.ts +0 -694
  423. package/tests/views/block-lists.test.ts +0 -661
  424. package/tests/views/blocks.test.ts +0 -889
  425. package/tests/views/bookmarks.test.ts +0 -345
  426. package/tests/views/drafts.test.ts +0 -430
  427. package/tests/views/feed-hidden-replies.test.ts +0 -243
  428. package/tests/views/feed-view-post.test.ts +0 -501
  429. package/tests/views/follows.test.ts +0 -372
  430. package/tests/views/get-config.test.ts +0 -64
  431. package/tests/views/get-suggested-onboarding-users.test.ts +0 -193
  432. package/tests/views/get-suggested-starter-packs.test.ts +0 -137
  433. package/tests/views/get-trends.test.ts +0 -141
  434. package/tests/views/internal-actor.test.ts +0 -127
  435. package/tests/views/known-followers.test.ts +0 -193
  436. package/tests/views/labeler-service.test.ts +0 -242
  437. package/tests/views/labels-needs-review.test.ts +0 -316
  438. package/tests/views/labels-takedown.test.ts +0 -247
  439. package/tests/views/likes.test.ts +0 -192
  440. package/tests/views/list-feed.test.ts +0 -195
  441. package/tests/views/lists.test.ts +0 -412
  442. package/tests/views/mute-lists.test.ts +0 -509
  443. package/tests/views/mutes.test.ts +0 -308
  444. package/tests/views/notifications.test.ts +0 -1581
  445. package/tests/views/post-search.test.ts +0 -281
  446. package/tests/views/posts-debug.test.ts +0 -79
  447. package/tests/views/posts.test.ts +0 -427
  448. package/tests/views/profile-debug.test.ts +0 -75
  449. package/tests/views/profile.test.ts +0 -795
  450. package/tests/views/quotes.test.ts +0 -133
  451. package/tests/views/reposts.test.ts +0 -112
  452. package/tests/views/starter-packs.test.ts +0 -395
  453. package/tests/views/suggestions.test.ts +0 -145
  454. package/tests/views/thread-v2.test.ts +0 -2005
  455. package/tests/views/thread.test.ts +0 -637
  456. package/tests/views/threadgating.test.ts +0 -843
  457. package/tests/views/timeline.test.ts +0 -328
  458. package/tests/views/verification.test.ts +0 -296
  459. package/tsconfig.build.json +0 -10
  460. package/tsconfig.build.tsbuildinfo +0 -1
  461. package/tsconfig.json +0 -7
  462. package/tsconfig.tests.json +0 -8
  463. package/vitest.config.ts +0 -10
@@ -1,823 +0,0 @@
1
- import crypto from 'node:crypto'
2
- import { once } from 'node:events'
3
- import { Server, createServer } from 'node:http'
4
- import { AddressInfo } from 'node:net'
5
- import express, { Application, json } from 'express'
6
- // eslint-disable-next-line import/default
7
- import httpTerminator from 'http-terminator'
8
- import {
9
- afterAll,
10
- afterEach,
11
- beforeAll,
12
- beforeEach,
13
- describe,
14
- expect,
15
- it,
16
- vi,
17
- } from 'vitest'
18
- import {
19
- AppBskyAgeassuranceBegin,
20
- AppBskyAgeassuranceDefs,
21
- AppBskyAgeassuranceGetState,
22
- AtpAgent,
23
- ageAssuranceRuleIDs as ruleIds,
24
- ids,
25
- } from '@atproto/api'
26
- import { SeedClient, TestNetwork, basicSeed } from '@atproto/dev-env'
27
- import {
28
- type KWSWebhookAgeVerified,
29
- serializeKWSAgeVerifiedStatus,
30
- } from '../../src/api/age-assurance/kws/age-verified.js'
31
- import {
32
- KWSExternalPayloadVersion,
33
- serializeKWSExternalPayloadV1,
34
- serializeKWSExternalPayloadV2,
35
- } from '../../src/api/age-assurance/kws/external-payload.js'
36
- import { KwsWebhookBody } from '../../src/api/kws/types.js'
37
-
38
- type Database = TestNetwork['bsky']['db']
39
-
40
- const BSKY_REDIRECT_URL = 'http://bsky'
41
-
42
- vi.mock('../../dist/api/age-assurance/const.js', () => {
43
- const AGE_ASSURANCE_CONFIG: AppBskyAgeassuranceDefs.Config = {
44
- regions: [
45
- {
46
- countryCode: 'AA',
47
- regionCode: undefined,
48
- minAccessAge: 13,
49
- rules: [
50
- {
51
- $type: ruleIds.IfAssuredOverAge,
52
- age: 18,
53
- access: 'full',
54
- },
55
- {
56
- $type: ruleIds.Default,
57
- access: 'safe',
58
- },
59
- ],
60
- },
61
- {
62
- countryCode: 'BB',
63
- regionCode: undefined,
64
- minAccessAge: 13,
65
- rules: [
66
- {
67
- $type: ruleIds.IfAssuredOverAge,
68
- age: 18,
69
- access: 'full',
70
- },
71
- {
72
- $type: ruleIds.Default,
73
- access: 'safe',
74
- },
75
- ],
76
- },
77
- ],
78
- }
79
- return {
80
- AGE_ASSURANCE_CONFIG,
81
- }
82
- })
83
-
84
- vi.mock('../../dist/api/age-assurance/kws/const.js', async () => {
85
- const actual = await vi.importActual<Record<string, unknown>>(
86
- '../../dist/api/age-assurance/kws/const.js',
87
- )
88
- const KWS_V2_COUNTRIES = new Set(['AA'])
89
- return {
90
- ...actual,
91
- KWS_V2_COUNTRIES,
92
- }
93
- })
94
-
95
- describe('age assurance v2 views', () => {
96
- let network: TestNetwork
97
- let db: Database
98
- let agent: AtpAgent
99
- let sc: SeedClient
100
- let kws: MockKwsServer
101
-
102
- const kwsOauthMock = vi.fn<MockHandler>()
103
- const kwsSendAgeVerifiedFlowEmailMock = vi.fn<MockHandler>()
104
- const kwsSendAdultVerifiedFlowEmailMock = vi.fn<MockHandler>()
105
- const actor = {
106
- did: '',
107
- email: '',
108
- }
109
-
110
- beforeAll(async () => {
111
- kws = new MockKwsServer({
112
- oauthMock: kwsOauthMock,
113
- sendAgeVerifiedFlowEmailMock: kwsSendAgeVerifiedFlowEmailMock,
114
- sendAdultVerifiedFlowEmailMock: kwsSendAdultVerifiedFlowEmailMock,
115
- })
116
- await kws.listen()
117
-
118
- network = await TestNetwork.create({
119
- dbPostgresSchema: 'bsky_views_age_assurance_v_two',
120
- bsky: {
121
- kws: {
122
- apiKey: 'apiKey',
123
- apiOrigin: kws.url,
124
- authOrigin: kws.url,
125
- clientId: 'clientId',
126
- redirectUrl: BSKY_REDIRECT_URL,
127
- userAgent: 'userAgent',
128
- verificationSecret: kws.verificationSecret,
129
- webhookSecret: kws.webhookSecret,
130
- ageVerifiedWebhookSecret: kws.ageVerifiedWebhookSecret,
131
- ageVerifiedRedirectSecret: kws.ageVerifiedRedirectSecret,
132
- },
133
- },
134
- })
135
-
136
- kws.setBskyBaseUrl(network.bsky.url)
137
-
138
- db = network.bsky.db
139
- agent = network.bsky.getAgent()
140
- sc = network.getSeedClient()
141
-
142
- await basicSeed(sc)
143
- await network.processAll()
144
-
145
- actor.did = sc.dids.alice
146
- actor.email = sc.accounts[actor.did].email
147
- })
148
-
149
- beforeEach(async () => {
150
- // Default mocks for KWS endpoints.
151
- kwsOauthMock.mockImplementation(
152
- (_req: express.Request, res: express.Response) =>
153
- res.json({
154
- access_token:
155
- 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIn0.INVALID',
156
- expires_in: 3600,
157
- }),
158
- )
159
- kwsSendAgeVerifiedFlowEmailMock.mockImplementation(
160
- (_req: express.Request, res: express.Response) => {
161
- res.json({})
162
- },
163
- )
164
- kwsSendAdultVerifiedFlowEmailMock.mockImplementation(
165
- (_req: express.Request, res: express.Response) => {
166
- res.json({})
167
- },
168
- )
169
- })
170
-
171
- afterEach(async () => {
172
- vi.resetAllMocks()
173
- // Drain in-flight bsync ops before resetting state directly, so an op from
174
- // a test that doesn't read it back can't leak into the next test.
175
- await network.processAll()
176
- await clearPrivateData(db)
177
- await clearActorAgeAssurance(db)
178
- })
179
-
180
- afterAll(async () => network?.close())
181
- afterAll(async () => kws?.stop())
182
-
183
- const getState = async (params: AppBskyAgeassuranceGetState.QueryParams) => {
184
- const { data } = await agent.app.bsky.ageassurance.getState(params, {
185
- headers: await network.serviceHeaders(
186
- actor.did,
187
- ids.AppBskyAgeassuranceGetState,
188
- ),
189
- })
190
- return data
191
- }
192
-
193
- const beginAgeAssurance = async (
194
- params: Omit<AppBskyAgeassuranceBegin.InputSchema, 'email' | 'language'> & {
195
- email?: string
196
- },
197
- ) => {
198
- const { data } = await agent.app.bsky.ageassurance.begin(
199
- {
200
- ...params,
201
- email: params.email || sc.accounts[actor.did].email,
202
- language: 'en',
203
- },
204
- {
205
- headers: await network.serviceHeaders(
206
- actor.did,
207
- ids.AppBskyAgeassuranceBegin,
208
- ),
209
- },
210
- )
211
- return data
212
- }
213
-
214
- describe('app.bsky.ageassurance.getState', () => {
215
- it('initially returns defaults', async () => {
216
- const { state, metadata } = await getState({
217
- countryCode: 'US',
218
- regionCode: undefined,
219
- })
220
- expect(metadata.accountCreatedAt).toBeDefined()
221
- expect(state).toEqual({
222
- lastInitatedAt: undefined,
223
- status: 'unknown',
224
- access: 'unknown',
225
- })
226
- })
227
- })
228
-
229
- describe('app.bsky.ageassurance.begin', () => {
230
- it('fails if region not supported', async () => {
231
- const call = beginAgeAssurance({
232
- countryCode: 'XX',
233
- })
234
- await expect(call).rejects.toHaveProperty('error', 'RegionNotSupported')
235
- })
236
-
237
- it('fails if email is invalid', async () => {
238
- const call = beginAgeAssurance({
239
- email: 'invalid-email',
240
- countryCode: 'XX',
241
- })
242
- await expect(call).rejects.toHaveProperty('error', 'InvalidEmail')
243
- })
244
-
245
- it('succeeds for V2 country', async () => {
246
- const res = await beginAgeAssurance({
247
- countryCode: 'AA',
248
- })
249
- await network.processAll()
250
- const { state } = await getState({
251
- countryCode: 'AA',
252
- })
253
- expect(kwsSendAgeVerifiedFlowEmailMock).toHaveBeenCalledTimes(1)
254
- expect(res).toEqual(state)
255
- expect(state.lastInitiatedAt).toBeDefined()
256
- expect(state.status).toEqual('pending')
257
- expect(state.access).toEqual('unknown')
258
- })
259
-
260
- it('succeeds for V1 country', async () => {
261
- const res = await beginAgeAssurance({
262
- countryCode: 'BB',
263
- })
264
- await network.processAll()
265
- const { state } = await getState({
266
- countryCode: 'BB',
267
- })
268
- expect(kwsSendAdultVerifiedFlowEmailMock).toHaveBeenCalledTimes(1)
269
- expect(res).toEqual(state)
270
- expect(state.lastInitiatedAt).toBeDefined()
271
- expect(state.status).toEqual('pending')
272
- expect(state.access).toEqual('unknown')
273
- })
274
- })
275
-
276
- describe('external handlers', () => {
277
- describe('V2 redirects', () => {
278
- it('redirects with result=unknown if we fail to parse the status object', async () => {
279
- const res = await kws.redirectV2({
280
- externalPayload: serializeKWSExternalPayloadV2({
281
- version: KWSExternalPayloadVersion.V2,
282
- actorDid: actor.did,
283
- attemptId: crypto.randomUUID(),
284
- countryCode: 'AA',
285
- }),
286
- status: JSON.stringify({
287
- verified: true,
288
- verifiedMinimumAge: '18', // will fail parsing
289
- }),
290
- })
291
- expect(res.status).toBe(302)
292
- expect(res.headers.get('Location')).toBe(
293
- `${BSKY_REDIRECT_URL}?result=unknown`,
294
- )
295
- })
296
-
297
- it('redirects with result=unknown if status is not verified', async () => {
298
- const res = await kws.redirectV2({
299
- externalPayload: serializeKWSExternalPayloadV2({
300
- version: KWSExternalPayloadVersion.V2,
301
- actorDid: actor.did,
302
- attemptId: crypto.randomUUID(),
303
- countryCode: 'AA',
304
- }),
305
- status: serializeKWSAgeVerifiedStatus({
306
- verified: false,
307
- verifiedMinimumAge: 18,
308
- }),
309
- })
310
- expect(res.status).toBe(302)
311
- expect(res.headers.get('Location')).toBe(
312
- `${BSKY_REDIRECT_URL}?actorDid=${encodeURIComponent(actor.did)}&result=unknown`,
313
- )
314
- })
315
-
316
- // this also covers any other thrown errors
317
- it('redirects with result=unknown if access check throws', async () => {
318
- const res = await kws.redirectV2({
319
- externalPayload: serializeKWSExternalPayloadV2({
320
- version: KWSExternalPayloadVersion.V2,
321
- actorDid: actor.did,
322
- attemptId: crypto.randomUUID(),
323
- countryCode: 'XX', // should never reach KWS anyway
324
- }),
325
- status: serializeKWSAgeVerifiedStatus({
326
- verified: true,
327
- verifiedMinimumAge: 18,
328
- }),
329
- })
330
- expect(res.status).toBe(302)
331
- expect(res.headers.get('Location')).toBe(
332
- `${BSKY_REDIRECT_URL}?actorDid=${encodeURIComponent(actor.did)}&result=unknown`,
333
- )
334
- })
335
-
336
- it('success', async () => {
337
- await beginAgeAssurance({
338
- countryCode: 'AA',
339
- })
340
- await network.processAll()
341
- await kws.redirectV2({
342
- externalPayload: serializeKWSExternalPayloadV2({
343
- version: KWSExternalPayloadVersion.V2,
344
- actorDid: actor.did,
345
- attemptId: crypto.randomUUID(),
346
- countryCode: 'AA',
347
- }),
348
- status: serializeKWSAgeVerifiedStatus({
349
- verified: true,
350
- verifiedMinimumAge: 18,
351
- }),
352
- })
353
- await network.processAll()
354
- const { state } = await getState({
355
- countryCode: 'AA',
356
- })
357
- expect(state.lastInitiatedAt).toBeDefined()
358
- expect(state.status).toEqual('assured')
359
- expect(state.access).toEqual('full')
360
- })
361
- })
362
-
363
- describe('V2 webhooks', () => {
364
- it('returns 400 if we fail to parse the external payload', async () => {
365
- const res = await kws.webhookV2({
366
- name: 'age-verified',
367
- time: new Date().toISOString(),
368
- orgId: crypto.randomUUID(),
369
- productId: crypto.randomUUID(),
370
- payload: {
371
- email: actor.email,
372
- externalPayload: serializeKWSExternalPayloadV2({
373
- version: KWSExternalPayloadVersion.V2,
374
- actorDid: actor.did,
375
- attemptId: crypto.randomUUID(),
376
- countryCode: 'AA',
377
- }),
378
- status: {
379
- verified: true,
380
- // @ts-ignore testing invalid payload
381
- verifiedMinimumAge: '18',
382
- },
383
- },
384
- })
385
- expect(res.status).toBe(400)
386
- await expect(res.json()).resolves.toHaveProperty(
387
- 'error',
388
- 'Failed to parse KWS webhook body',
389
- )
390
- })
391
-
392
- it('returns 400 if status is not verified', async () => {
393
- const res = await kws.webhookV2({
394
- name: 'age-verified',
395
- time: new Date().toISOString(),
396
- orgId: crypto.randomUUID(),
397
- productId: crypto.randomUUID(),
398
- payload: {
399
- email: actor.email,
400
- externalPayload: serializeKWSExternalPayloadV2({
401
- version: KWSExternalPayloadVersion.V2,
402
- actorDid: actor.did,
403
- attemptId: crypto.randomUUID(),
404
- countryCode: 'AA',
405
- }),
406
- status: {
407
- verified: false,
408
- verifiedMinimumAge: 18,
409
- },
410
- },
411
- })
412
- expect(res.status).toBe(400)
413
- await expect(res.json()).resolves.toHaveProperty(
414
- 'error',
415
- 'Expected KWS webhook to have verified status',
416
- )
417
- })
418
-
419
- it('returns 200, but AA state unchanged due to invalid region', async () => {
420
- const res = await kws.webhookV2({
421
- name: 'age-verified',
422
- time: new Date().toISOString(),
423
- orgId: crypto.randomUUID(),
424
- productId: crypto.randomUUID(),
425
- payload: {
426
- email: actor.email,
427
- externalPayload: serializeKWSExternalPayloadV2({
428
- version: KWSExternalPayloadVersion.V2,
429
- actorDid: actor.did,
430
- attemptId: crypto.randomUUID(),
431
- countryCode: 'XX',
432
- }),
433
- status: {
434
- verified: true,
435
- verifiedMinimumAge: 18,
436
- },
437
- },
438
- })
439
- await network.processAll()
440
- expect(res.status).toBe(200)
441
- const { state } = await getState({
442
- countryCode: 'XX',
443
- })
444
- expect(state.status).toEqual('unknown') // we never began, so it's still unknown
445
- })
446
-
447
- it('success', async () => {
448
- await beginAgeAssurance({
449
- countryCode: 'AA',
450
- })
451
- await network.processAll()
452
- await kws.webhookV2({
453
- name: 'age-verified',
454
- time: new Date().toISOString(),
455
- orgId: crypto.randomUUID(),
456
- productId: crypto.randomUUID(),
457
- payload: {
458
- email: actor.email,
459
- externalPayload: serializeKWSExternalPayloadV2({
460
- version: KWSExternalPayloadVersion.V2,
461
- actorDid: actor.did,
462
- attemptId: crypto.randomUUID(),
463
- countryCode: 'AA',
464
- }),
465
- status: {
466
- verified: true,
467
- verifiedMinimumAge: 18,
468
- },
469
- },
470
- })
471
- await network.processAll()
472
- const { state } = await getState({
473
- countryCode: 'AA',
474
- })
475
- expect(state.lastInitiatedAt).toBeDefined()
476
- expect(state.status).toEqual('assured')
477
- expect(state.access).toEqual('full')
478
- })
479
- })
480
-
481
- describe('V1 compat', () => {
482
- it('works via webhook', async () => {
483
- await beginAgeAssurance({
484
- countryCode: 'BB',
485
- })
486
- await network.processAll()
487
- await kws.webhookV1({
488
- payload: {
489
- externalPayload: serializeKWSExternalPayloadV2({
490
- version: KWSExternalPayloadVersion.V2,
491
- actorDid: actor.did,
492
- attemptId: crypto.randomUUID(),
493
- countryCode: 'BB',
494
- }),
495
- status: {
496
- verified: true,
497
- },
498
- },
499
- })
500
- await network.processAll()
501
- const { state } = await getState({
502
- countryCode: 'BB',
503
- })
504
- expect(state.lastInitiatedAt).toBeDefined()
505
- expect(state.status).toEqual('assured')
506
- expect(state.access).toEqual('full')
507
- })
508
-
509
- it('works via redirect', async () => {
510
- await beginAgeAssurance({
511
- countryCode: 'BB',
512
- })
513
- await network.processAll()
514
- await kws.redirectV1({
515
- externalPayload: serializeKWSExternalPayloadV2({
516
- version: KWSExternalPayloadVersion.V2,
517
- actorDid: actor.did,
518
- attemptId: crypto.randomUUID(),
519
- countryCode: 'BB',
520
- }),
521
- status: JSON.stringify({
522
- verified: true,
523
- }),
524
- })
525
- await network.processAll()
526
- const { state } = await getState({
527
- countryCode: 'BB',
528
- })
529
- expect(state.lastInitiatedAt).toBeDefined()
530
- expect(state.status).toEqual('assured')
531
- expect(state.access).toEqual('full')
532
- })
533
- })
534
- })
535
-
536
- describe('misc', () => {
537
- /*
538
- * This is a silly test, but it did help me uncover a local data-plane
539
- * implementation bug. Let's leave it here for additional safety.
540
- */
541
- it('expects access to be safe', async () => {
542
- await kws.redirectV2({
543
- externalPayload: serializeKWSExternalPayloadV2({
544
- version: KWSExternalPayloadVersion.V2,
545
- actorDid: actor.did,
546
- attemptId: crypto.randomUUID(),
547
- countryCode: 'AA',
548
- }),
549
- status: serializeKWSAgeVerifiedStatus({
550
- verified: true,
551
- verifiedMinimumAge: 16,
552
- }),
553
- })
554
- await network.processAll()
555
- const { state } = await getState({
556
- countryCode: 'AA',
557
- })
558
- expect(state.status).toEqual('assured')
559
- expect(state.access).toEqual('safe')
560
- })
561
-
562
- /**
563
- * We only block re-init if the user is in a `blocked` state, which is not
564
- * testable using the local dataplane at the moment. The test below
565
- * reflects v1 handling.
566
- *
567
- * Skipping for now, but this handling is implemented in v2.
568
- */
569
- it.skip('cannot re-init from terminal state', async () => {
570
- await kws.redirectV2({
571
- externalPayload: serializeKWSExternalPayloadV2({
572
- version: KWSExternalPayloadVersion.V2,
573
- actorDid: actor.did,
574
- attemptId: crypto.randomUUID(),
575
- countryCode: 'AA',
576
- }),
577
- status: serializeKWSAgeVerifiedStatus({
578
- verified: true,
579
- verifiedMinimumAge: 18,
580
- }),
581
- })
582
- await network.processAll()
583
- const call = beginAgeAssurance({
584
- countryCode: 'AA',
585
- })
586
- await expect(call).rejects.toHaveProperty('error', 'InvalidInitiation')
587
- })
588
-
589
- it('re-init from terminal state retains existing status', async () => {
590
- await kws.redirectV2({
591
- externalPayload: serializeKWSExternalPayloadV2({
592
- version: KWSExternalPayloadVersion.V2,
593
- actorDid: actor.did,
594
- attemptId: crypto.randomUUID(),
595
- countryCode: 'AA',
596
- }),
597
- status: serializeKWSAgeVerifiedStatus({
598
- verified: true,
599
- verifiedMinimumAge: 16,
600
- }),
601
- })
602
- await network.processAll()
603
- const { state } = await getState({
604
- countryCode: 'AA',
605
- })
606
- expect(state.status).toEqual('assured')
607
- expect(state.access).toEqual('safe')
608
- const res = await beginAgeAssurance({
609
- countryCode: 'AA',
610
- })
611
- expect(res.status).toEqual('assured')
612
- expect(res.access).toEqual('safe')
613
- })
614
-
615
- /*
616
- * This tests local dataplane behavior, but the actual prod implementation
617
- * lives in the dataplane repo, obviously.
618
- */
619
- it('dataplane converts v1 to v2 state at read time', async () => {
620
- await beginAgeAssurance({
621
- countryCode: 'BB',
622
- })
623
- await network.processAll()
624
- await kws.webhookV1({
625
- payload: {
626
- externalPayload: serializeKWSExternalPayloadV1({
627
- actorDid: actor.did,
628
- attemptId: crypto.randomUUID(),
629
- }),
630
- status: {
631
- verified: true,
632
- },
633
- },
634
- })
635
- await network.processAll()
636
- const { state } = await getState({
637
- countryCode: 'BB',
638
- })
639
- expect(state.lastInitiatedAt).toBeDefined()
640
- expect(state.status).toEqual('assured')
641
- expect(state.access).toEqual('full')
642
- })
643
- })
644
- })
645
-
646
- const clearPrivateData = async (db: Database) => {
647
- await db.db.deleteFrom('private_data').execute()
648
- }
649
-
650
- const clearActorAgeAssurance = async (db: Database) => {
651
- await db.db
652
- .updateTable('actor')
653
- .set({
654
- ageAssuranceStatus: null,
655
- ageAssuranceLastInitiatedAt: null,
656
- ageAssuranceAccess: null,
657
- ageAssuranceCountryCode: null,
658
- ageAssuranceRegionCode: null,
659
- })
660
- .execute()
661
- }
662
-
663
- type MockHandler = (req: express.Request, res: express.Response) => void
664
-
665
- class MockKwsServer {
666
- verificationSecret = 'verificationSecret' // unused here
667
- webhookSecret = 'webhookSecret' // unused here
668
- ageVerifiedWebhookSecret = 'ageVerifiedWebhookSecret'
669
- ageVerifiedRedirectSecret = 'ageVerifiedRedirectSecret'
670
-
671
- private app: Application
672
- private server: Server
673
- private terminator: httpTerminator.HttpTerminator
674
- private bskyUrlBase = ''
675
-
676
- constructor({
677
- oauthMock,
678
- sendAgeVerifiedFlowEmailMock,
679
- sendAdultVerifiedFlowEmailMock,
680
- }: {
681
- oauthMock: ReturnType<typeof vi.fn<MockHandler>>
682
- sendAgeVerifiedFlowEmailMock: ReturnType<typeof vi.fn<MockHandler>>
683
- sendAdultVerifiedFlowEmailMock: ReturnType<typeof vi.fn<MockHandler>>
684
- }) {
685
- this.app = express()
686
- .use(json())
687
- .post('/auth/realms/kws/protocol/openid-connect/token', (_, res) =>
688
- oauthMock(_, res),
689
- )
690
- .post('/v1/verifications/send-email', (req, res) => {
691
- const body = req.body
692
- if (body.userContext === 'age') {
693
- return sendAgeVerifiedFlowEmailMock(req, res)
694
- } else if (body.userContext === 'adult') {
695
- return sendAdultVerifiedFlowEmailMock(req, res)
696
- }
697
- })
698
-
699
- this.server = createServer(this.app)
700
- this.terminator = httpTerminator.createHttpTerminator({
701
- server: this.server,
702
- })
703
- }
704
-
705
- async listen(port?: number) {
706
- this.server.listen(port)
707
- await once(this.server, 'listening')
708
- }
709
-
710
- async stop() {
711
- await this.terminator.terminate()
712
- }
713
-
714
- setBskyBaseUrl(url: string) {
715
- this.bskyUrlBase = url
716
- }
717
-
718
- redirectV1({
719
- externalPayload,
720
- status,
721
- }: {
722
- externalPayload: string
723
- status: string
724
- }) {
725
- const sig = crypto
726
- .createHmac('sha256', this.verificationSecret)
727
- .update(`${status}:${externalPayload}`)
728
- .digest('hex')
729
-
730
- const queryString = new URLSearchParams({
731
- externalPayload,
732
- signature: sig,
733
- status,
734
- }).toString()
735
-
736
- return fetch(
737
- `${this.bskyUrlBase}/external/kws/age-assurance-verification?${queryString}`,
738
- {
739
- method: 'GET',
740
- redirect: 'manual',
741
- },
742
- )
743
- }
744
-
745
- redirectV2({
746
- externalPayload,
747
- status,
748
- }: {
749
- externalPayload: string
750
- status: string
751
- }) {
752
- const sig = crypto
753
- .createHmac('sha256', this.ageVerifiedRedirectSecret)
754
- .update(`${status}:${externalPayload}`)
755
- .digest('hex')
756
-
757
- const queryString = new URLSearchParams({
758
- externalPayload,
759
- signature: sig,
760
- status,
761
- }).toString()
762
-
763
- return fetch(
764
- `${this.bskyUrlBase}/external/age-assurance/redirects/kws-age-verified?${queryString}`,
765
- {
766
- method: 'GET',
767
- redirect: 'manual',
768
- },
769
- )
770
- }
771
-
772
- webhookV1(
773
- body: Omit<KwsWebhookBody, 'payload'> & {
774
- payload: Omit<KwsWebhookBody['payload'], 'externalPayload'> & {
775
- externalPayload: string
776
- }
777
- },
778
- ): Promise<Response> {
779
- const bodyBuffer = Buffer.from(JSON.stringify(body))
780
-
781
- const timestamp = new Date().valueOf()
782
- const sig = crypto
783
- .createHmac('sha256', this.webhookSecret)
784
- .update(`${timestamp}.${bodyBuffer}`)
785
- .digest('hex')
786
-
787
- return fetch(`${this.bskyUrlBase}/external/kws/age-assurance-webhook`, {
788
- method: 'POST',
789
- body: bodyBuffer,
790
- headers: {
791
- 'x-kws-signature': `t=${timestamp},v1=${sig}`,
792
- 'Content-Type': 'application/json',
793
- },
794
- })
795
- }
796
-
797
- webhookV2(body: KWSWebhookAgeVerified): Promise<Response> {
798
- const bodyBuffer = Buffer.from(JSON.stringify(body))
799
-
800
- const timestamp = new Date().valueOf()
801
- const sig = crypto
802
- .createHmac('sha256', this.ageVerifiedWebhookSecret)
803
- .update(`${timestamp}.${bodyBuffer}`)
804
- .digest('hex')
805
-
806
- return fetch(
807
- `${this.bskyUrlBase}/external/age-assurance/webhooks/kws-age-verified`,
808
- {
809
- method: 'POST',
810
- body: bodyBuffer,
811
- headers: {
812
- 'x-kws-signature': `t=${timestamp},v1=${sig}`,
813
- 'Content-Type': 'application/json',
814
- },
815
- },
816
- )
817
- }
818
-
819
- get url() {
820
- const address = this.server.address() as AddressInfo
821
- return `http://localhost:${address.port}`
822
- }
823
- }