@atproto/pds 0.5.6 → 0.5.8

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 (243) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/background.d.ts +12 -6
  3. package/dist/background.d.ts.map +1 -1
  4. package/dist/background.js +32 -13
  5. package/dist/background.js.map +1 -1
  6. package/dist/context.d.ts.map +1 -1
  7. package/dist/context.js +4 -31
  8. package/dist/context.js.map +1 -1
  9. package/dist/index.d.ts +1 -0
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +33 -11
  12. package/dist/index.js.map +1 -1
  13. package/dist/lexicons/app/bsky/authFullApp.defs.d.ts.map +1 -1
  14. package/dist/lexicons/app/bsky/authFullApp.defs.js +1 -0
  15. package/dist/lexicons/app/bsky/authFullApp.defs.js.map +1 -1
  16. package/dist/lexicons/app/bsky/authViewAll.defs.d.ts.map +1 -1
  17. package/dist/lexicons/app/bsky/authViewAll.defs.js +1 -0
  18. package/dist/lexicons/app/bsky/authViewAll.defs.js.map +1 -1
  19. package/dist/lexicons/app/bsky/feed/searchPostsV2.d.ts +3 -0
  20. package/dist/lexicons/app/bsky/feed/searchPostsV2.d.ts.map +1 -0
  21. package/dist/lexicons/app/bsky/feed/searchPostsV2.defs.d.ts +158 -0
  22. package/dist/lexicons/app/bsky/feed/searchPostsV2.defs.d.ts.map +1 -0
  23. package/dist/lexicons/app/bsky/feed/searchPostsV2.defs.js +74 -0
  24. package/dist/lexicons/app/bsky/feed/searchPostsV2.defs.js.map +1 -0
  25. package/dist/lexicons/app/bsky/feed/searchPostsV2.js +6 -0
  26. package/dist/lexicons/app/bsky/feed/searchPostsV2.js.map +1 -0
  27. package/dist/lexicons/app/bsky/feed.d.ts +1 -0
  28. package/dist/lexicons/app/bsky/feed.d.ts.map +1 -1
  29. package/dist/lexicons/app/bsky/feed.js +1 -0
  30. package/dist/lexicons/app/bsky/feed.js.map +1 -1
  31. package/dist/lexicons/app/bsky/notification/defs.defs.d.ts +5 -0
  32. package/dist/lexicons/app/bsky/notification/defs.defs.d.ts.map +1 -1
  33. package/dist/lexicons/app/bsky/notification/defs.defs.js +1 -0
  34. package/dist/lexicons/app/bsky/notification/defs.defs.js.map +1 -1
  35. package/dist/lexicons/chat/bsky/actor/declaration.defs.d.ts +1 -1
  36. package/dist/lexicons/chat/bsky/actor/declaration.defs.js.map +1 -1
  37. package/dist/lexicons/chat/bsky/actor/defs.defs.d.ts +4 -6
  38. package/dist/lexicons/chat/bsky/actor/defs.defs.d.ts.map +1 -1
  39. package/dist/lexicons/chat/bsky/actor/defs.defs.js +2 -3
  40. package/dist/lexicons/chat/bsky/actor/defs.defs.js.map +1 -1
  41. package/dist/lexicons/chat/bsky/convo/defs.defs.d.ts +64 -70
  42. package/dist/lexicons/chat/bsky/convo/defs.defs.d.ts.map +1 -1
  43. package/dist/lexicons/chat/bsky/convo/defs.defs.js +32 -35
  44. package/dist/lexicons/chat/bsky/convo/defs.defs.js.map +1 -1
  45. package/dist/lexicons/chat/bsky/convo/getUnreadCounts.defs.d.ts +1 -1
  46. package/dist/lexicons/chat/bsky/convo/getUnreadCounts.defs.d.ts.map +1 -1
  47. package/dist/lexicons/chat/bsky/convo/getUnreadCounts.defs.js +1 -1
  48. package/dist/lexicons/chat/bsky/convo/getUnreadCounts.defs.js.map +1 -1
  49. package/dist/lexicons/chat/bsky/convo/listConvoRequests.defs.d.ts +1 -1
  50. package/dist/lexicons/chat/bsky/convo/listConvoRequests.defs.d.ts.map +1 -1
  51. package/dist/lexicons/chat/bsky/convo/listConvoRequests.defs.js +1 -1
  52. package/dist/lexicons/chat/bsky/convo/listConvoRequests.defs.js.map +1 -1
  53. package/dist/lexicons/chat/bsky/convo/lockConvo.defs.d.ts +1 -1
  54. package/dist/lexicons/chat/bsky/convo/lockConvo.defs.d.ts.map +1 -1
  55. package/dist/lexicons/chat/bsky/convo/lockConvo.defs.js +1 -1
  56. package/dist/lexicons/chat/bsky/convo/lockConvo.defs.js.map +1 -1
  57. package/dist/lexicons/chat/bsky/convo/unlockConvo.defs.d.ts +1 -1
  58. package/dist/lexicons/chat/bsky/convo/unlockConvo.defs.d.ts.map +1 -1
  59. package/dist/lexicons/chat/bsky/convo/unlockConvo.defs.js +1 -1
  60. package/dist/lexicons/chat/bsky/convo/unlockConvo.defs.js.map +1 -1
  61. package/dist/lexicons/chat/bsky/group/addMembers.defs.d.ts +1 -1
  62. package/dist/lexicons/chat/bsky/group/addMembers.defs.d.ts.map +1 -1
  63. package/dist/lexicons/chat/bsky/group/addMembers.defs.js +1 -1
  64. package/dist/lexicons/chat/bsky/group/addMembers.defs.js.map +1 -1
  65. package/dist/lexicons/chat/bsky/group/approveJoinRequest.defs.d.ts +1 -1
  66. package/dist/lexicons/chat/bsky/group/approveJoinRequest.defs.d.ts.map +1 -1
  67. package/dist/lexicons/chat/bsky/group/approveJoinRequest.defs.js +1 -1
  68. package/dist/lexicons/chat/bsky/group/approveJoinRequest.defs.js.map +1 -1
  69. package/dist/lexicons/chat/bsky/group/createGroup.defs.d.ts +1 -1
  70. package/dist/lexicons/chat/bsky/group/createGroup.defs.d.ts.map +1 -1
  71. package/dist/lexicons/chat/bsky/group/createGroup.defs.js +1 -1
  72. package/dist/lexicons/chat/bsky/group/createGroup.defs.js.map +1 -1
  73. package/dist/lexicons/chat/bsky/group/createJoinLink.defs.d.ts +1 -1
  74. package/dist/lexicons/chat/bsky/group/createJoinLink.defs.d.ts.map +1 -1
  75. package/dist/lexicons/chat/bsky/group/createJoinLink.defs.js +1 -1
  76. package/dist/lexicons/chat/bsky/group/createJoinLink.defs.js.map +1 -1
  77. package/dist/lexicons/chat/bsky/group/disableJoinLink.defs.d.ts +1 -1
  78. package/dist/lexicons/chat/bsky/group/disableJoinLink.defs.d.ts.map +1 -1
  79. package/dist/lexicons/chat/bsky/group/disableJoinLink.defs.js +1 -1
  80. package/dist/lexicons/chat/bsky/group/disableJoinLink.defs.js.map +1 -1
  81. package/dist/lexicons/chat/bsky/group/editGroup.defs.d.ts +1 -1
  82. package/dist/lexicons/chat/bsky/group/editGroup.defs.d.ts.map +1 -1
  83. package/dist/lexicons/chat/bsky/group/editGroup.defs.js +1 -1
  84. package/dist/lexicons/chat/bsky/group/editGroup.defs.js.map +1 -1
  85. package/dist/lexicons/chat/bsky/group/editJoinLink.defs.d.ts +1 -1
  86. package/dist/lexicons/chat/bsky/group/editJoinLink.defs.d.ts.map +1 -1
  87. package/dist/lexicons/chat/bsky/group/editJoinLink.defs.js +1 -1
  88. package/dist/lexicons/chat/bsky/group/editJoinLink.defs.js.map +1 -1
  89. package/dist/lexicons/chat/bsky/group/enableJoinLink.defs.d.ts +1 -1
  90. package/dist/lexicons/chat/bsky/group/enableJoinLink.defs.d.ts.map +1 -1
  91. package/dist/lexicons/chat/bsky/group/enableJoinLink.defs.js +1 -1
  92. package/dist/lexicons/chat/bsky/group/enableJoinLink.defs.js.map +1 -1
  93. package/dist/lexicons/chat/bsky/group/getJoinLinkPreviews.defs.d.ts +1 -1
  94. package/dist/lexicons/chat/bsky/group/getJoinLinkPreviews.defs.d.ts.map +1 -1
  95. package/dist/lexicons/chat/bsky/group/getJoinLinkPreviews.defs.js +1 -1
  96. package/dist/lexicons/chat/bsky/group/getJoinLinkPreviews.defs.js.map +1 -1
  97. package/dist/lexicons/chat/bsky/group/listJoinRequests.defs.d.ts +1 -1
  98. package/dist/lexicons/chat/bsky/group/listJoinRequests.defs.d.ts.map +1 -1
  99. package/dist/lexicons/chat/bsky/group/listJoinRequests.defs.js +1 -1
  100. package/dist/lexicons/chat/bsky/group/listJoinRequests.defs.js.map +1 -1
  101. package/dist/lexicons/chat/bsky/group/listMutualGroups.defs.d.ts +1 -1
  102. package/dist/lexicons/chat/bsky/group/listMutualGroups.defs.d.ts.map +1 -1
  103. package/dist/lexicons/chat/bsky/group/listMutualGroups.defs.js +1 -1
  104. package/dist/lexicons/chat/bsky/group/listMutualGroups.defs.js.map +1 -1
  105. package/dist/lexicons/chat/bsky/group/rejectJoinRequest.defs.d.ts +1 -1
  106. package/dist/lexicons/chat/bsky/group/rejectJoinRequest.defs.d.ts.map +1 -1
  107. package/dist/lexicons/chat/bsky/group/rejectJoinRequest.defs.js +1 -1
  108. package/dist/lexicons/chat/bsky/group/rejectJoinRequest.defs.js.map +1 -1
  109. package/dist/lexicons/chat/bsky/group/removeMembers.defs.d.ts +1 -1
  110. package/dist/lexicons/chat/bsky/group/removeMembers.defs.d.ts.map +1 -1
  111. package/dist/lexicons/chat/bsky/group/removeMembers.defs.js +1 -1
  112. package/dist/lexicons/chat/bsky/group/removeMembers.defs.js.map +1 -1
  113. package/dist/lexicons/chat/bsky/group/requestJoin.defs.d.ts +1 -1
  114. package/dist/lexicons/chat/bsky/group/requestJoin.defs.d.ts.map +1 -1
  115. package/dist/lexicons/chat/bsky/group/requestJoin.defs.js +1 -1
  116. package/dist/lexicons/chat/bsky/group/requestJoin.defs.js.map +1 -1
  117. package/dist/lexicons/chat/bsky/group/updateJoinRequestsRead.defs.d.ts +1 -1
  118. package/dist/lexicons/chat/bsky/group/updateJoinRequestsRead.defs.d.ts.map +1 -1
  119. package/dist/lexicons/chat/bsky/group/updateJoinRequestsRead.defs.js +1 -1
  120. package/dist/lexicons/chat/bsky/group/updateJoinRequestsRead.defs.js.map +1 -1
  121. package/dist/lexicons/chat/bsky/group/withdrawJoinRequest.defs.d.ts +1 -1
  122. package/dist/lexicons/chat/bsky/group/withdrawJoinRequest.defs.d.ts.map +1 -1
  123. package/dist/lexicons/chat/bsky/group/withdrawJoinRequest.defs.js +1 -1
  124. package/dist/lexicons/chat/bsky/group/withdrawJoinRequest.defs.js.map +1 -1
  125. package/dist/lexicons/chat/bsky/moderation/defs.defs.d.ts +6 -6
  126. package/dist/lexicons/chat/bsky/moderation/defs.defs.d.ts.map +1 -1
  127. package/dist/lexicons/chat/bsky/moderation/defs.defs.js +3 -3
  128. package/dist/lexicons/chat/bsky/moderation/defs.defs.js.map +1 -1
  129. package/dist/lexicons/chat/bsky/moderation/getConvo.defs.d.ts +1 -1
  130. package/dist/lexicons/chat/bsky/moderation/getConvo.defs.d.ts.map +1 -1
  131. package/dist/lexicons/chat/bsky/moderation/getConvo.defs.js +1 -1
  132. package/dist/lexicons/chat/bsky/moderation/getConvo.defs.js.map +1 -1
  133. package/dist/lexicons/chat/bsky/moderation/getConvoMembers.defs.d.ts +1 -1
  134. package/dist/lexicons/chat/bsky/moderation/getConvoMembers.defs.d.ts.map +1 -1
  135. package/dist/lexicons/chat/bsky/moderation/getConvoMembers.defs.js +1 -1
  136. package/dist/lexicons/chat/bsky/moderation/getConvoMembers.defs.js.map +1 -1
  137. package/dist/lexicons/chat/bsky/moderation/getConvos.defs.d.ts +1 -1
  138. package/dist/lexicons/chat/bsky/moderation/getConvos.defs.d.ts.map +1 -1
  139. package/dist/lexicons/chat/bsky/moderation/getConvos.defs.js +1 -1
  140. package/dist/lexicons/chat/bsky/moderation/getConvos.defs.js.map +1 -1
  141. package/dist/lexicons/chat/bsky/notification/defs.d.ts +2 -0
  142. package/dist/lexicons/chat/bsky/notification/defs.d.ts.map +1 -0
  143. package/dist/lexicons/chat/bsky/notification/defs.defs.d.ts +20 -0
  144. package/dist/lexicons/chat/bsky/notification/defs.defs.d.ts.map +1 -0
  145. package/dist/lexicons/chat/bsky/notification/defs.defs.js +19 -0
  146. package/dist/lexicons/chat/bsky/notification/defs.defs.js.map +1 -0
  147. package/dist/lexicons/chat/bsky/notification/defs.js +5 -0
  148. package/dist/lexicons/chat/bsky/notification/defs.js.map +1 -0
  149. package/dist/lexicons/chat/bsky/notification/getPreferences.d.ts +3 -0
  150. package/dist/lexicons/chat/bsky/notification/getPreferences.d.ts.map +1 -0
  151. package/dist/lexicons/chat/bsky/notification/getPreferences.defs.d.ts +18 -0
  152. package/dist/lexicons/chat/bsky/notification/getPreferences.defs.d.ts.map +1 -0
  153. package/dist/lexicons/chat/bsky/notification/getPreferences.defs.js +16 -0
  154. package/dist/lexicons/chat/bsky/notification/getPreferences.defs.js.map +1 -0
  155. package/dist/lexicons/chat/bsky/notification/getPreferences.js +6 -0
  156. package/dist/lexicons/chat/bsky/notification/getPreferences.js.map +1 -0
  157. package/dist/lexicons/chat/bsky/notification/putPreferences.d.ts +3 -0
  158. package/dist/lexicons/chat/bsky/notification/putPreferences.d.ts.map +1 -0
  159. package/dist/lexicons/chat/bsky/notification/putPreferences.defs.d.ts +27 -0
  160. package/dist/lexicons/chat/bsky/notification/putPreferences.defs.d.ts.map +1 -0
  161. package/dist/lexicons/chat/bsky/notification/putPreferences.defs.js +22 -0
  162. package/dist/lexicons/chat/bsky/notification/putPreferences.defs.js.map +1 -0
  163. package/dist/lexicons/chat/bsky/notification/putPreferences.js +6 -0
  164. package/dist/lexicons/chat/bsky/notification/putPreferences.js.map +1 -0
  165. package/dist/lexicons/chat/bsky/notification.d.ts +4 -0
  166. package/dist/lexicons/chat/bsky/notification.d.ts.map +1 -0
  167. package/dist/lexicons/chat/bsky/notification.js +7 -0
  168. package/dist/lexicons/chat/bsky/notification.js.map +1 -0
  169. package/dist/lexicons/chat/bsky.d.ts +1 -0
  170. package/dist/lexicons/chat/bsky.d.ts.map +1 -1
  171. package/dist/lexicons/chat/bsky.js +1 -0
  172. package/dist/lexicons/chat/bsky.js.map +1 -1
  173. package/dist/lexicons/tools/ozone/report/defs.defs.d.ts +4 -0
  174. package/dist/lexicons/tools/ozone/report/defs.defs.d.ts.map +1 -1
  175. package/dist/lexicons/tools/ozone/report/defs.defs.js +2 -0
  176. package/dist/lexicons/tools/ozone/report/defs.defs.js.map +1 -1
  177. package/dist/lexicons/tools/ozone/report/queryActivities.d.ts +3 -0
  178. package/dist/lexicons/tools/ozone/report/queryActivities.d.ts.map +1 -0
  179. package/dist/lexicons/tools/ozone/report/queryActivities.defs.d.ts +42 -0
  180. package/dist/lexicons/tools/ozone/report/queryActivities.defs.d.ts.map +1 -0
  181. package/dist/lexicons/tools/ozone/report/queryActivities.defs.js +31 -0
  182. package/dist/lexicons/tools/ozone/report/queryActivities.defs.js.map +1 -0
  183. package/dist/lexicons/tools/ozone/report/queryActivities.js +6 -0
  184. package/dist/lexicons/tools/ozone/report/queryActivities.js.map +1 -0
  185. package/dist/lexicons/tools/ozone/report.d.ts +1 -0
  186. package/dist/lexicons/tools/ozone/report.d.ts.map +1 -1
  187. package/dist/lexicons/tools/ozone/report.js +1 -0
  188. package/dist/lexicons/tools/ozone/report.js.map +1 -1
  189. package/dist/pipethrough.d.ts +3 -0
  190. package/dist/pipethrough.d.ts.map +1 -1
  191. package/dist/pipethrough.js +32 -0
  192. package/dist/pipethrough.js.map +1 -1
  193. package/package.json +13 -13
  194. package/src/background.ts +49 -18
  195. package/src/context.ts +4 -37
  196. package/src/index.ts +31 -13
  197. package/src/pipethrough.ts +38 -1
  198. package/tests/_util.ts +8 -25
  199. package/tests/account-deactivation.test.ts +3 -2
  200. package/tests/account-deletion.test.ts +1 -1
  201. package/tests/account-migration.test.ts +2 -2
  202. package/tests/account-status.test.ts +1 -1
  203. package/tests/account.test.ts +1 -1
  204. package/tests/app-passwords.test.ts +1 -1
  205. package/tests/auth.test.ts +1 -1
  206. package/tests/blob-deletes.test.ts +5 -4
  207. package/tests/create-post.test.ts +1 -1
  208. package/tests/crud.test.ts +1 -1
  209. package/tests/db.test.ts +1 -1
  210. package/tests/email-confirmation.test.ts +1 -1
  211. package/tests/file-uploads.test.ts +2 -2
  212. package/tests/get-service-auth.test.ts +1 -1
  213. package/tests/handles.test.ts +1 -1
  214. package/tests/invite-codes.test.ts +1 -1
  215. package/tests/invites-admin.test.ts +5 -4
  216. package/tests/moderation.test.ts +1 -1
  217. package/tests/moderator-auth.test.ts +1 -1
  218. package/tests/plc-operations.test.ts +3 -2
  219. package/tests/preferences.test.ts +1 -1
  220. package/tests/proxied/admin.test.ts +3 -2
  221. package/tests/proxied/feedgen.test.ts +1 -1
  222. package/tests/proxied/notif.test.ts +6 -13
  223. package/tests/proxied/procedures.test.ts +5 -4
  224. package/tests/proxied/proxy-catchall.test.ts +9 -8
  225. package/tests/proxied/proxy-header.test.ts +14 -9
  226. package/tests/proxied/proxy-oauth-aud.test.ts +17 -10
  227. package/tests/proxied/read-after-write.test.ts +7 -7
  228. package/tests/proxied/views.test.ts +6 -5
  229. package/tests/races.test.ts +1 -1
  230. package/tests/rate-limits.test.ts +1 -1
  231. package/tests/recovery.test.ts +1 -1
  232. package/tests/seeds/basic.ts +2 -2
  233. package/tests/seeds/follows.ts +1 -1
  234. package/tests/seeds/users-bulk.ts +2 -1
  235. package/tests/seeds/users.ts +5 -2
  236. package/tests/sequencer.test.ts +6 -4
  237. package/tests/server.test.ts +11 -13
  238. package/tests/sync/invertible-ops.test.ts +4 -1
  239. package/tests/sync/list.test.ts +1 -1
  240. package/tests/sync/subscribe-repos.test.ts +7 -6
  241. package/tests/sync/sync.test.ts +2 -2
  242. package/tests/takedown-appeal.test.ts +3 -2
  243. package/tsconfig.build.tsbuildinfo +1 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queryActivities.defs.js","sourceRoot":"","sources":["../../../../../src/lexicons/tools/ozone/report/queryActivities.defs.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,cAAc,CAAA;AAChC,OAAO,KAAK,UAAU,MAAM,gBAAgB,CAAA;AAE5C,MAAM,KAAK,GAAG,oCAAoC,CAAA;AAElD,OAAO,EAAE,KAAK,EAAE,CAAA;AAEhB,MAAM,CAAC,MAAM,OAAO,GAAG,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC;IAC5C,aAAa,EAAE,aAAa,CAAC,CAAC,CAAC,QAAQ;IACrC,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAChD;IACD,YAAY,EAAE,aAAa,CAAC,CAAC,CAAC,QAAQ;IACpC,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CA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Y \"@atproto/lex\". DO NOT EDIT.\n */\n\nimport { l } from '@atproto/lex'\nimport * as ReportDefs from './defs.defs.js'\n\nconst $nsid = 'tools.ozone.report.queryActivities'\n\nexport { $nsid }\n\nexport const $params = /*#__PURE__*/ l.params({\n activityTypes: /*#__PURE__*/ l.optional(\n /*#__PURE__*/ l.array(/*#__PURE__*/ l.string()),\n ),\n createdAfter: /*#__PURE__*/ l.optional(\n /*#__PURE__*/ l.string({ format: 'datetime' }),\n ),\n createdBefore: /*#__PURE__*/ l.optional(\n /*#__PURE__*/ l.string({ format: 'datetime' }),\n ),\n sortDirection: /*#__PURE__*/ l.optional(\n /*#__PURE__*/ l.withDefault(/*#__PURE__*/ l.enum(['asc', 'desc']), 'desc'),\n ),\n limit: /*#__PURE__*/ l.optional(\n /*#__PURE__*/ l.withDefault(\n /*#__PURE__*/ l.integer({ minimum: 1, maximum: 100 }),\n 50,\n ),\n ),\n cursor: /*#__PURE__*/ l.optional(/*#__PURE__*/ l.string()),\n})\n\nexport type $Params = l.InferOutput<typeof $params>\n\nexport const $output = /*#__PURE__*/ l.jsonPayload({\n activities: /*#__PURE__*/ l.array(\n /*#__PURE__*/ l.ref<ReportDefs.ReportActivityView>(\n (() => ReportDefs.reportActivityView) as any,\n ),\n ),\n cursor: /*#__PURE__*/ l.optional(/*#__PURE__*/ l.string()),\n})\n\nexport type $Output<B = l.BinaryData> = l.InferPayload<typeof $output, B>\nexport type $OutputBody<B = l.BinaryData> = l.InferPayloadBody<\n typeof $output,\n B\n>\n\n/** Query report activities across all reports, ordered by createdAt. Used by downstream pollers; for per-report activity history use listActivities. */\nconst main = /*#__PURE__*/ l.query($nsid, $params, $output)\n\nexport { main }\n\nexport const $lxm = $nsid\n"]}
@@ -0,0 +1,6 @@
1
+ /*
2
+ * THIS FILE WAS GENERATED BY "@atproto/lex". DO NOT EDIT.
3
+ */
4
+ export * from './queryActivities.defs.js';
5
+ export { main as default } from './queryActivities.defs.js';
6
+ //# sourceMappingURL=queryActivities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queryActivities.js","sourceRoot":"","sources":["../../../../../src/lexicons/tools/ozone/report/queryActivities.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,2BAA2B,CAAA;AACzC,OAAO,EAAE,IAAI,IAAI,OAAO,EAAE,MAAM,2BAA2B,CAAA","sourcesContent":["/*\n * THIS FILE WAS GENERATED BY \"@atproto/lex\". DO NOT EDIT.\n */\n\nexport * from './queryActivities.defs.js'\nexport { main as default } from './queryActivities.defs.js'\n"]}
@@ -5,6 +5,7 @@ export * as getLatestReport from './report/getLatestReport.js';
5
5
  export * as getLiveStats from './report/getLiveStats.js';
6
6
  export * as getReport from './report/getReport.js';
7
7
  export * as listActivities from './report/listActivities.js';
8
+ export * as queryActivities from './report/queryActivities.js';
8
9
  export * as queryReports from './report/queryReports.js';
9
10
  export * as reassignQueue from './report/reassignQueue.js';
10
11
  export * as refreshStats from './report/refreshStats.js';
@@ -1 +1 @@
1
- {"version":3,"file":"report.d.ts","sourceRoot":"","sources":["../../../../src/lexicons/tools/ozone/report.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,eAAe,MAAM,6BAA6B,CAAA;AAC9D,OAAO,KAAK,cAAc,MAAM,4BAA4B,CAAA;AAC5D,OAAO,KAAK,kBAAkB,MAAM,gCAAgC,CAAA;AACpE,OAAO,KAAK,eAAe,MAAM,6BAA6B,CAAA;AAC9D,OAAO,KAAK,YAAY,MAAM,0BAA0B,CAAA;AACxD,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAA;AAClD,OAAO,KAAK,cAAc,MAAM,4BAA4B,CAAA;AAC5D,OAAO,KAAK,YAAY,MAAM,0BAA0B,CAAA;AACxD,OAAO,KAAK,aAAa,MAAM,2BAA2B,CAAA;AAC1D,OAAO,KAAK,YAAY,MAAM,0BAA0B,CAAA;AACxD,OAAO,KAAK,iBAAiB,MAAM,+BAA+B,CAAA;AAClE,OAAO,KAAK,cAAc,MAAM,4BAA4B,CAAA;AAC5D,OAAO,KAAK,IAAI,MAAM,kBAAkB,CAAA"}
1
+ {"version":3,"file":"report.d.ts","sourceRoot":"","sources":["../../../../src/lexicons/tools/ozone/report.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,eAAe,MAAM,6BAA6B,CAAA;AAC9D,OAAO,KAAK,cAAc,MAAM,4BAA4B,CAAA;AAC5D,OAAO,KAAK,kBAAkB,MAAM,gCAAgC,CAAA;AACpE,OAAO,KAAK,eAAe,MAAM,6BAA6B,CAAA;AAC9D,OAAO,KAAK,YAAY,MAAM,0BAA0B,CAAA;AACxD,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAA;AAClD,OAAO,KAAK,cAAc,MAAM,4BAA4B,CAAA;AAC5D,OAAO,KAAK,eAAe,MAAM,6BAA6B,CAAA;AAC9D,OAAO,KAAK,YAAY,MAAM,0BAA0B,CAAA;AACxD,OAAO,KAAK,aAAa,MAAM,2BAA2B,CAAA;AAC1D,OAAO,KAAK,YAAY,MAAM,0BAA0B,CAAA;AACxD,OAAO,KAAK,iBAAiB,MAAM,+BAA+B,CAAA;AAClE,OAAO,KAAK,cAAc,MAAM,4BAA4B,CAAA;AAC5D,OAAO,KAAK,IAAI,MAAM,kBAAkB,CAAA"}
@@ -8,6 +8,7 @@ export * as getLatestReport from './report/getLatestReport.js';
8
8
  export * as getLiveStats from './report/getLiveStats.js';
9
9
  export * as getReport from './report/getReport.js';
10
10
  export * as listActivities from './report/listActivities.js';
11
+ export * as queryActivities from './report/queryActivities.js';
11
12
  export * as queryReports from './report/queryReports.js';
12
13
  export * as reassignQueue from './report/reassignQueue.js';
13
14
  export * as refreshStats from './report/refreshStats.js';
@@ -1 +1 @@
1
- {"version":3,"file":"report.js","sourceRoot":"","sources":["../../../../src/lexicons/tools/ozone/report.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,eAAe,MAAM,6BAA6B,CAAA;AAC9D,OAAO,KAAK,cAAc,MAAM,4BAA4B,CAAA;AAC5D,OAAO,KAAK,kBAAkB,MAAM,gCAAgC,CAAA;AACpE,OAAO,KAAK,eAAe,MAAM,6BAA6B,CAAA;AAC9D,OAAO,KAAK,YAAY,MAAM,0BAA0B,CAAA;AACxD,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAA;AAClD,OAAO,KAAK,cAAc,MAAM,4BAA4B,CAAA;AAC5D,OAAO,KAAK,YAAY,MAAM,0BAA0B,CAAA;AACxD,OAAO,KAAK,aAAa,MAAM,2BAA2B,CAAA;AAC1D,OAAO,KAAK,YAAY,MAAM,0BAA0B,CAAA;AACxD,OAAO,KAAK,iBAAiB,MAAM,+BAA+B,CAAA;AAClE,OAAO,KAAK,cAAc,MAAM,4BAA4B,CAAA;AAC5D,OAAO,KAAK,IAAI,MAAM,kBAAkB,CAAA","sourcesContent":["/*\n * THIS FILE WAS GENERATED BY \"@atproto/lex\". DO NOT EDIT.\n */\n\nexport * as assignModerator from './report/assignModerator.js'\nexport * as getAssignments from './report/getAssignments.js'\nexport * as getHistoricalStats from './report/getHistoricalStats.js'\nexport * as getLatestReport from './report/getLatestReport.js'\nexport * as getLiveStats from './report/getLiveStats.js'\nexport * as getReport from './report/getReport.js'\nexport * as listActivities from './report/listActivities.js'\nexport * as queryReports from './report/queryReports.js'\nexport * as reassignQueue from './report/reassignQueue.js'\nexport * as refreshStats from './report/refreshStats.js'\nexport * as unassignModerator from './report/unassignModerator.js'\nexport * as createActivity from './report/createActivity.js'\nexport * as defs from './report/defs.js'\n"]}
1
+ {"version":3,"file":"report.js","sourceRoot":"","sources":["../../../../src/lexicons/tools/ozone/report.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,eAAe,MAAM,6BAA6B,CAAA;AAC9D,OAAO,KAAK,cAAc,MAAM,4BAA4B,CAAA;AAC5D,OAAO,KAAK,kBAAkB,MAAM,gCAAgC,CAAA;AACpE,OAAO,KAAK,eAAe,MAAM,6BAA6B,CAAA;AAC9D,OAAO,KAAK,YAAY,MAAM,0BAA0B,CAAA;AACxD,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAA;AAClD,OAAO,KAAK,cAAc,MAAM,4BAA4B,CAAA;AAC5D,OAAO,KAAK,eAAe,MAAM,6BAA6B,CAAA;AAC9D,OAAO,KAAK,YAAY,MAAM,0BAA0B,CAAA;AACxD,OAAO,KAAK,aAAa,MAAM,2BAA2B,CAAA;AAC1D,OAAO,KAAK,YAAY,MAAM,0BAA0B,CAAA;AACxD,OAAO,KAAK,iBAAiB,MAAM,+BAA+B,CAAA;AAClE,OAAO,KAAK,cAAc,MAAM,4BAA4B,CAAA;AAC5D,OAAO,KAAK,IAAI,MAAM,kBAAkB,CAAA","sourcesContent":["/*\n * THIS FILE WAS GENERATED BY \"@atproto/lex\". DO NOT EDIT.\n */\n\nexport * as assignModerator from './report/assignModerator.js'\nexport * as getAssignments from './report/getAssignments.js'\nexport * as getHistoricalStats from './report/getHistoricalStats.js'\nexport * as getLatestReport from './report/getLatestReport.js'\nexport * as getLiveStats from './report/getLiveStats.js'\nexport * as getReport from './report/getReport.js'\nexport * as listActivities from './report/listActivities.js'\nexport * as queryActivities from './report/queryActivities.js'\nexport * as queryReports from './report/queryReports.js'\nexport * as reassignQueue from './report/reassignQueue.js'\nexport * as refreshStats from './report/refreshStats.js'\nexport * as unassignModerator from './report/unassignModerator.js'\nexport * as createActivity from './report/createActivity.js'\nexport * as defs from './report/defs.js'\n"]}
@@ -1,8 +1,11 @@
1
1
  import { IncomingHttpHeaders } from 'node:http';
2
2
  import { Readable } from 'node:stream';
3
3
  import { Request } from 'express';
4
+ import { Dispatcher } from 'undici';
4
5
  import { CatchallHandler, HandlerPipeThroughBuffer, HandlerPipeThroughStream, XRPCError as XRPCServerError } from '@atproto/xrpc-server';
6
+ import { ProxyConfig } from './config/config.js';
5
7
  import { AppContext } from './context.js';
8
+ export declare function buildProxyAgent(cfg: ProxyConfig): Dispatcher;
6
9
  export declare const proxyHandler: (ctx: AppContext) => CatchallHandler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,QAiB5B,CAAA;AA8DF,qBAAa,wBAAyB,SAAQ,eAAe;IAEzD,QAAQ,CAAC,QAAQ,EAAE;QACjB,UAAU,EAAE,MAAM,CAAA;QAClB,OAAO,EAAE,mBAAmB,CAAA;KAC7B;IAJH,YACW,QAAQ,EAAE;QACjB,UAAU,EAAE,MAAM,CAAA;QAClB,OAAO,EAAE,mBAAmB,CAAA;KAC7B,EACD,OAAO,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,EAC7C,OAAO,CAAC,EAAE,YAAY,EAQvB;IAED,IAAI,OAAO,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAEpC;IAED,IAAI,KAAK,uBAER;CACF"}
@@ -1,10 +1,42 @@
1
1
  import { PassThrough, finished } from 'node:stream';
2
+ import { Agent, Pool, interceptors } from 'undici';
2
3
  import { decodeStream, getServiceEndpoint, omit, streamToNodeBuffer, } from '@atproto/common';
3
4
  import { InternalServerError, InvalidRequestError, ResponseType, XRPCError as XRPCServerError, excludeErrorResult, parseReqNsid, } from '@atproto/xrpc-server';
5
+ import { isUnicastIp, unicastLookup } from '@atproto-labs/fetch-node';
4
6
  import { buildProxiedContentEncoding } from '@atproto-labs/xrpc-utils';
5
7
  import { isAccessPrivileged } from './auth-scope.js';
6
8
  import { chat, com, tools } from './lexicons/index.js';
7
9
  import { httpLogger } from './logger.js';
10
+ export function buildProxyAgent(cfg) {
11
+ const agent = new Agent({
12
+ allowH2: cfg.allowHTTP2,
13
+ headersTimeout: cfg.headersTimeout,
14
+ maxResponseSize: cfg.maxResponseSize,
15
+ bodyTimeout: cfg.bodyTimeout,
16
+ factory: cfg.disableSsrfProtection
17
+ ? undefined
18
+ : (origin, opts) => {
19
+ const { protocol, hostname } = origin instanceof URL ? origin : new URL(origin);
20
+ if (protocol !== 'https:') {
21
+ throw new Error(`Forbidden protocol "${protocol}"`);
22
+ }
23
+ if (isUnicastIp(hostname) === false) {
24
+ throw new Error('Hostname resolved to non-unicast address');
25
+ }
26
+ return new Pool(origin, opts);
27
+ },
28
+ connect: {
29
+ lookup: cfg.disableSsrfProtection ? undefined : unicastLookup,
30
+ },
31
+ });
32
+ return agent.compose(cfg.maxRetries > 0
33
+ ? interceptors.retry({
34
+ statusCodes: [], // Only retry on socket errors
35
+ methods: ['GET', 'HEAD'],
36
+ maxRetries: cfg.maxRetries,
37
+ })
38
+ : (dispatch) => dispatch);
39
+ }
8
40
  export const proxyHandler = (ctx) => {
9
41
  const performAuth = ctx.authVerifier.authorization({
10
42
  authorize: (permissions, { params }) => permissions.assertRpc(params),
@@ -1 +1 @@
1
- {"version":3,"file":"pipethrough.js","sourceRoot":"","sources":["../src/pipethrough.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAY,QAAQ,EAAE,MAAM,aAAa,CAAA;AAG7D,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,IAAI,EACJ,kBAAkB,GACnB,MAAM,iBAAiB,CAAA;AAExB,OAAO,EAIL,mBAAmB,EACnB,mBAAmB,EACnB,YAAY,EACZ,SAAS,IAAI,eAAe,EAC5B,kBAAkB,EAClB,YAAY,GACb,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAA;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAEpD,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAExC,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,GAAe,EAAmB,EAAE;IAC/D,MAAM,WAAW,GAAG,GAAG,CAAC,YAAY,CAAC,aAAa,CAAqB;QACrE,SAAS,EAAE,CAAC,WAAW,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,WAAW,CAAC,SAAS,CAAC,MAAM,CAAC;KACtE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AAsB;QAEtB,MAAM,MAAM,GACV,QAAQ,CAAC,UAAU,KAAK,GAAG;YACzB,CAAC,CAAC,YAAY,CAAC,eAAe;YAC9B,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAA;QAEzB,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;wBAZ7C,QAAQ;IAanB,CAAC;IAED,IAAI,OAAO;QACT,OAAO,MAAM,CAAC,WAAW,CAAC,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAA;IAC1E,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,eAAe,IAAI,IAAI,CAAC,QAAQ,CAAA;IAC9C,CAAC;CACF","sourcesContent":["import { IncomingHttpHeaders, ServerResponse } from 'node:http'\nimport { PassThrough, Readable, finished } from 'node:stream'\nimport { Request } from 'express'\nimport { Dispatcher } from 'undici'\nimport {\n decodeStream,\n getServiceEndpoint,\n omit,\n streamToNodeBuffer,\n} from '@atproto/common'\nimport { RpcPermissionMatch } from '@atproto/oauth-scopes'\nimport {\n CatchallHandler,\n HandlerPipeThroughBuffer,\n HandlerPipeThroughStream,\n InternalServerError,\n InvalidRequestError,\n ResponseType,\n XRPCError as XRPCServerError,\n excludeErrorResult,\n parseReqNsid,\n} from '@atproto/xrpc-server'\nimport { buildProxiedContentEncoding } from '@atproto-labs/xrpc-utils'\nimport { isAccessPrivileged } from './auth-scope.js'\nimport { AppContext } from './context.js'\nimport { chat, com, tools } from './lexicons/index.js'\nimport { httpLogger } from './logger.js'\n\nexport const proxyHandler = (ctx: AppContext): CatchallHandler => {\n const performAuth = ctx.authVerifier.authorization<RpcPermissionMatch>({\n authorize: (permissions, { params }) => permissions.assertRpc(params),\n })\n\n return async (req, res, next) => {\n // /!\\ Hot path\n try {\n if (\n req.method !== 'GET' &&\n req.method !== 'HEAD' &&\n req.method !== 'POST'\n ) {\n throw new XRPCServerError(\n ResponseType.InvalidRequest,\n 'XRPC requests only supports GET and POST',\n )\n }\n\n const body = req.method === 'POST' ? req : undefined\n if (body != null && !body.readable) {\n // Body was already consumed by a previous middleware\n throw new InternalServerError('Request body is not readable')\n }\n\n const lxm = parseReqNsid(req)\n if (PROTECTED_METHODS.has(lxm)) {\n throw new InvalidRequestError('Bad token method', 'InvalidToken')\n }\n\n const {\n url: origin,\n did,\n serviceId,\n } = await parseProxyInfo(ctx, req, lxm)\n // Phase 1 of service auth updates: the scope check sees the combined\n // did#serviceId form (so OAuth callers' rpc:?aud=did#service scopes\n // match), while the outbound service-auth JWT keeps bare-DID aud\n // regardless of session type.\n const scopeAud = `${did}#${serviceId}`\n const tokenAud = did\n\n const authResult = await performAuth({\n req,\n res,\n params: { lxm, aud: scopeAud },\n })\n\n const { credentials } = excludeErrorResult(authResult)\n\n if (\n credentials.type === 'access' &&\n !isAccessPrivileged(credentials.scope) &&\n PRIVILEGED_METHODS.has(lxm)\n ) {\n throw new InvalidRequestError('Bad token method', 'InvalidToken')\n }\n\n const headers: IncomingHttpHeaders = {\n 'accept-encoding': req.headers['accept-encoding'] || 'identity',\n 'accept-language': req.headers['accept-language'],\n 'atproto-accept-labelers': req.headers['atproto-accept-labelers'],\n 'x-bsky-topics': req.headers['x-bsky-topics'],\n\n 'content-type': body && req.headers['content-type'],\n 'content-encoding': body && req.headers['content-encoding'],\n 'content-length': body && req.headers['content-length'],\n\n authorization: `Bearer ${await ctx.serviceAuthJwt(credentials.did, tokenAud, lxm)}`,\n }\n\n const dispatchOptions: Dispatcher.RequestOptions = {\n origin,\n method: req.method,\n path: req.originalUrl,\n body,\n headers,\n }\n\n await pipethroughStream(ctx, req, dispatchOptions, (upstream) => {\n res.status(upstream.statusCode)\n\n for (const [name, val] of responseHeaders(upstream.headers)) {\n res.setHeader(name, val)\n }\n\n // Note that we should not need to manually handle errors here (e.g. by\n // destroying the response), as the http server will handle them for us.\n res.on('error', logResponseError)\n\n // Tell undici to write the upstream response directly to the response\n return res\n })\n } catch (err) {\n next(err)\n }\n }\n}\n\nexport type PipethroughOptions = {\n /**\n * Specify the issuer (requester) for service auth. If not provided, no\n * authorization headers will be added to the request.\n */\n iss?: string\n\n /**\n * Override the audience for service auth. If not provided, the audience will\n * be determined based on the proxy service.\n */\n aud?: string\n\n /**\n * Override the lexicon method for service auth. If not provided, the lexicon\n * method will be determined based on the request path.\n */\n lxm?: string\n}\n\nexport async function pipethrough(\n ctx: AppContext,\n req: Request,\n options?: PipethroughOptions,\n): Promise<\n HandlerPipeThroughStream & {\n stream: Readable\n headers: Record<string, string>\n encoding: string\n }\n> {\n if (req.method !== 'GET' && req.method !== 'HEAD') {\n // pipethrough() is used from within xrpcServer handlers, which means that\n // the request body either has been parsed or is a readable stream that has\n // been piped for decoding & size limiting. Because of this, forwarding the\n // request body requires re-encoding it. Since we currently do not use\n // pipethrough() with procedures, proxying of request body is not\n // implemented.\n throw new InternalServerError(\n `Proxying of ${req.method} requests is not supported`,\n )\n }\n\n const lxm = parseReqNsid(req)\n\n const { url: origin, did: aud } = await parseProxyInfo(ctx, req, lxm)\n\n const dispatchOptions: Dispatcher.RequestOptions = {\n origin,\n method: req.method,\n path: req.originalUrl,\n headers: {\n 'accept-language': req.headers['accept-language'],\n 'atproto-accept-labelers': req.headers['atproto-accept-labelers'],\n 'x-bsky-topics': req.headers['x-bsky-topics'],\n\n // Because we sometimes need to interpret the response (e.g. during\n // read-after-write, through asPipeThroughBuffer()), we need to ask the\n // upstream server for an encoding that both the requester and the PDS can\n // understand. Since we might have to do the decoding ourselves, we will\n // use our own preferences (and weight) to negotiate the encoding.\n 'accept-encoding': buildProxiedContentEncoding(\n req.headers['accept-encoding'],\n ctx.cfg.proxy.preferCompressed,\n ),\n\n authorization: options?.iss\n ? `Bearer ${await ctx.serviceAuthJwt(options.iss, options.aud ?? aud, options.lxm ?? lxm)}`\n : undefined,\n },\n\n // Use a high water mark to buffer more data while performing async\n // operations before this stream is consumed. This is especially useful\n // while processing read-after-write operations.\n highWaterMark: 2 * 65536, // twice the default (64KiB)\n }\n\n const { headers, body } = await pipethroughRequest(ctx, req, dispatchOptions)\n\n return {\n encoding: safeString(headers['content-type']) ?? 'application/json',\n headers: Object.fromEntries(responseHeaders(headers)),\n stream: body,\n }\n}\n\n// Request setup/formatting\n// -------------------\n\nexport function computeProxyTo(\n ctx: AppContext,\n req: Request,\n lxm: string,\n): string {\n const proxyToHeader = req.header('atproto-proxy')\n if (proxyToHeader) return proxyToHeader\n\n const service = defaultService(ctx, lxm)\n if (service.serviceInfo) {\n return `${service.serviceInfo.did}#${service.serviceId}`\n }\n\n throw new InvalidRequestError(`No service configured for ${lxm}`)\n}\n\n// Bare-DID portion of `proxyTo`, suitable as a service-auth JWT audience\n// (Phase 1 of service auth updates).\nexport function bareDidFromProxyTo(proxyTo: string): string {\n const hashIndex = proxyTo.indexOf('#')\n return hashIndex === -1 ? proxyTo : proxyTo.slice(0, hashIndex)\n}\n\nexport async function parseProxyInfo(\n ctx: AppContext,\n req: Request,\n lxm: string,\n): Promise<{ url: string; did: string; serviceId: string }> {\n // /!\\ Hot path\n\n const proxyToHeader = req.header('atproto-proxy')\n if (proxyToHeader) return parseProxyHeader(ctx, proxyToHeader)\n\n const { serviceId, serviceInfo } = defaultService(ctx, lxm)\n if (serviceInfo) return { ...serviceInfo, serviceId }\n\n throw new InvalidRequestError(`No service configured for ${lxm}`)\n}\n\nexport const parseProxyHeader = async (\n // Using subset of AppContext for testing purposes\n ctx: Pick<AppContext, 'cfg' | 'idResolver'>,\n proxyTo: string,\n): Promise<{ did: string; url: string; serviceId: string }> => {\n // /!\\ Hot path\n\n const hashIndex = proxyTo.indexOf('#')\n\n if (hashIndex === 0) {\n throw new InvalidRequestError('no did specified in proxy header')\n }\n\n if (hashIndex === -1 || hashIndex === proxyTo.length - 1) {\n throw new InvalidRequestError('no service id specified in proxy header')\n }\n\n // More than one hash\n if (proxyTo.indexOf('#', hashIndex + 1) !== -1) {\n throw new InvalidRequestError('invalid proxy header format')\n }\n\n // Basic validation\n if (proxyTo.includes(' ')) {\n throw new InvalidRequestError('proxy header cannot contain spaces')\n }\n\n const did = proxyTo.slice(0, hashIndex)\n const serviceId = proxyTo.slice(hashIndex + 1)\n\n // Special case a configured appview, while still proxying correctly any other appview\n if (\n ctx.cfg.bskyAppView &&\n proxyTo === `${ctx.cfg.bskyAppView.did}#bsky_appview`\n ) {\n return { did, url: ctx.cfg.bskyAppView.url, serviceId }\n }\n\n const didDoc = await ctx.idResolver.did.resolve(did)\n if (!didDoc) {\n throw new InvalidRequestError('could not resolve proxy did')\n }\n\n const url = getServiceEndpoint(didDoc, { id: `#${serviceId}` })\n if (!url) {\n throw new InvalidRequestError('could not resolve proxy did service url')\n }\n\n return { did, url, serviceId }\n}\n\n/**\n * Utility function that wraps the undici stream() function and handles request\n * and response errors by wrapping them in XRPCError instances. This function is\n * more efficient than \"pipethroughRequest\" when a writable stream to pipe the\n * upstream response to is available.\n */\nasync function pipethroughStream(\n ctx: AppContext,\n req: Request,\n dispatchOptions: Dispatcher.RequestOptions,\n successStreamFactory: Dispatcher.StreamFactory,\n): Promise<void> {\n return new Promise<void>((resolve, reject) => {\n void ctx.proxyAgent\n .stream(dispatchOptions, (upstream) => {\n if (upstream.statusCode >= 400) {\n const passThrough = new PassThrough()\n\n void tryParsingError(upstream.headers, passThrough).then((parsed) => {\n const xrpcError = new PipethroughUpstreamError(upstream, parsed, {\n cause: dispatchOptions,\n })\n\n reject(xrpcError)\n }, reject)\n\n return passThrough\n }\n\n const writable = successStreamFactory(upstream)\n\n // As soon as the control was passed to the writable stream (i.e. by\n // returning the writable hereafter), pipethroughStream() is considered\n // to have succeeded. Any error occurring while writing upstream data to\n // the writable stream should be handled through the stream's error\n // state (i.e. successStreamFactory() must ensure that error events on\n // the returned writable will be handled).\n resolve()\n\n return writable\n })\n // The following catch block will be triggered with either network errors\n // or writable stream errors. In the latter case, the promise will already\n // be resolved, and reject()ing it there after will have no effect. Those\n // error would still be logged by the successStreamFactory() function.\n .catch(handleUpstreamRequestError.bind(req))\n .catch(reject)\n })\n}\n\n/**\n * Utility function that wraps the undici request() function and handles request\n * and response errors by wrapping them in XRPCError instances.\n */\nasync function pipethroughRequest(\n ctx: AppContext,\n req: Request,\n dispatchOptions: Dispatcher.RequestOptions,\n) {\n // HandlerPipeThroughStream requires a readable stream to be returned, so we\n // use the (less efficient) request() function instead.\n\n const upstream = await ctx.proxyAgent\n .request(dispatchOptions)\n .catch(handleUpstreamRequestError.bind(req))\n\n if (upstream.statusCode >= 400) {\n const parsed = await tryParsingError(upstream.headers, upstream.body)\n\n throw new PipethroughUpstreamError(upstream, parsed, {\n cause: dispatchOptions,\n })\n }\n\n return upstream\n}\n\nfunction handleUpstreamRequestError(\n this: Request,\n err: unknown,\n message = 'Upstream service unreachable',\n): never {\n const logger = isPinoHttpRequest(this) ? this.log : httpLogger\n logger.error({ err }, message)\n throw new XRPCServerError(ResponseType.UpstreamFailure, message, undefined, {\n cause: err,\n })\n}\n\nfunction isPinoHttpRequest(req: Request): req is Request & {\n log: { error: (obj: unknown, msg: string) => void }\n} {\n return typeof (req as { log?: any }).log?.error === 'function'\n}\n\n// Request parsing/forwarding\n// -------------------\n\nexport function isJsonContentType(contentType?: string): boolean | undefined {\n if (!contentType) return undefined\n return /application\\/(?:\\w+\\+)?json/i.test(contentType)\n}\n\nasync function tryParsingError(\n headers: IncomingHttpHeaders,\n readable: Readable,\n): Promise<{ error?: string; message?: string }> {\n if (isJsonContentType(headers['content-type']) === false) {\n // We don't known how to parse non JSON content types so we can discard the\n // whole response.\n\n // Since we don't care about the response, we would normally just destroy\n // the stream. However, if the underlying HTTP connection is an HTTP/1.1\n // connection, this also destroys the underlying (keep-alive) TCP socket. In\n // order to avoid destroying the TCP socket, while avoiding the cost of\n // consuming too much IO, we give it a chance to finish first.\n\n // @NOTE we need to listen (and ignore) \"error\" events, otherwise the\n // process could crash (since we drain the stream asynchronously here). This\n // is performed through the \"finished\" call below.\n\n const to = setTimeout(() => {\n readable.destroy()\n }, 100)\n finished(readable, (_err) => {\n clearTimeout(to)\n })\n readable.resume()\n\n return {}\n }\n\n try {\n const buffer = await bufferUpstreamResponse(\n readable,\n headers['content-encoding'],\n )\n\n const errInfo: unknown = JSON.parse(buffer.toString('utf8'))\n return {\n error: safeString(errInfo?.['error']),\n message: safeString(errInfo?.['message']),\n }\n } catch (err) {\n // Failed to read, decode, buffer or parse. No big deal.\n return {}\n }\n}\n\nasync function bufferUpstreamResponse(\n readable: Readable,\n contentEncoding?: string | string[],\n): Promise<Buffer> {\n try {\n return await streamToNodeBuffer(decodeStream(readable, contentEncoding))\n } catch (err) {\n if (!readable.destroyed) readable.destroy()\n\n throw new XRPCServerError(\n ResponseType.UpstreamFailure,\n err instanceof TypeError ? err.message : 'unable to decode request body',\n undefined,\n { cause: err },\n )\n }\n}\n\nexport async function asPipeThroughBuffer(\n input: HandlerPipeThroughStream,\n): Promise<HandlerPipeThroughBuffer> {\n return {\n buffer: await bufferUpstreamResponse(\n input.stream,\n input.headers?.['content-encoding'],\n ),\n headers: omit(input.headers, ['content-encoding', 'content-length']),\n encoding: input.encoding,\n }\n}\n\n// Response parsing/forwarding\n// -------------------\n\nconst RES_HEADERS_TO_FORWARD = [\n 'atproto-repo-rev',\n 'atproto-content-labelers',\n 'retry-after',\n]\n\nfunction* responseHeaders(\n headers: IncomingHttpHeaders,\n includeContentHeaders = true,\n): Generator<[string, string]> {\n if (includeContentHeaders) {\n const length = headers['content-length']\n if (length) yield ['content-length', length]\n\n const encoding = headers['content-encoding']\n if (encoding) yield ['content-encoding', encoding]\n\n const type = headers['content-type']\n if (type) yield ['content-type', type]\n\n const language = headers['content-language']\n if (language) yield ['content-language', language]\n }\n\n for (let i = 0; i < RES_HEADERS_TO_FORWARD.length; i++) {\n const name = RES_HEADERS_TO_FORWARD[i]\n const val = headers[name]\n\n if (val != null) {\n const value: string = Array.isArray(val) ? val.join(',') : val\n yield [name, value]\n }\n }\n}\n\n// Utils\n// -------------------\n\n/**\n * Performs lexicon method matching on a set of methods,\n * taking into account that they are treated case-insensitively.\n */\nexport class LxmSet {\n private inner: Set<string>\n private original: Iterable<string>\n constructor(items: Iterable<string>) {\n this.inner = new Set(Array.from(items, normalizeLxm))\n this.original = items\n }\n has(lxm: string) {\n return this.inner.has(normalizeLxm(lxm))\n }\n *[Symbol.iterator](): Iterator<string> {\n yield* this.original\n }\n}\n\nexport function normalizeLxm(lxm: string) {\n return lxm.toLowerCase()\n}\n\nexport const CHAT_BSKY_METHODS = new LxmSet([\n chat.bsky.actor.deleteAccount.$lxm,\n chat.bsky.actor.exportAccountData.$lxm,\n chat.bsky.convo.deleteMessageForSelf.$lxm,\n chat.bsky.convo.getConvo.$lxm,\n chat.bsky.convo.getConvoForMembers.$lxm,\n chat.bsky.convo.getLog.$lxm,\n chat.bsky.convo.getMessages.$lxm,\n chat.bsky.convo.leaveConvo.$lxm,\n chat.bsky.convo.listConvos.$lxm,\n chat.bsky.convo.muteConvo.$lxm,\n chat.bsky.convo.sendMessage.$lxm,\n chat.bsky.convo.sendMessageBatch.$lxm,\n chat.bsky.convo.unmuteConvo.$lxm,\n chat.bsky.convo.updateRead.$lxm,\n])\n\nexport const PRIVILEGED_METHODS = new LxmSet([\n ...CHAT_BSKY_METHODS,\n com.atproto.server.createAccount.$lxm,\n])\n\n// These endpoints are related to account management and must be used directly,\n// not proxied or service-authed. Service auth may be utilized between PDS and\n// entryway for these methods.\nexport const PROTECTED_METHODS = new LxmSet([\n com.atproto.admin.sendEmail.$lxm,\n com.atproto.identity.requestPlcOperationSignature.$lxm,\n com.atproto.identity.signPlcOperation.$lxm,\n com.atproto.identity.updateHandle.$lxm,\n com.atproto.server.activateAccount.$lxm,\n com.atproto.server.confirmEmail.$lxm,\n com.atproto.server.createAppPassword.$lxm,\n com.atproto.server.deactivateAccount.$lxm,\n com.atproto.server.getAccountInviteCodes.$lxm,\n com.atproto.server.getSession.$lxm,\n com.atproto.server.listAppPasswords.$lxm,\n com.atproto.server.requestAccountDelete.$lxm,\n com.atproto.server.requestEmailConfirmation.$lxm,\n com.atproto.server.requestEmailUpdate.$lxm,\n com.atproto.server.revokeAppPassword.$lxm,\n com.atproto.server.updateEmail.$lxm,\n])\n\nconst defaultService = (\n ctx: AppContext,\n nsid: string,\n): {\n serviceId: string\n serviceInfo: { url: string; did: string } | null\n} => {\n switch (nsid) {\n case tools.ozone.communication.createTemplate.$lxm:\n case tools.ozone.communication.deleteTemplate.$lxm:\n case tools.ozone.communication.listTemplates.$lxm:\n case tools.ozone.communication.updateTemplate.$lxm:\n case tools.ozone.moderation.cancelScheduledActions.$lxm:\n case tools.ozone.moderation.emitEvent.$lxm:\n case tools.ozone.moderation.getAccountTimeline.$lxm:\n case tools.ozone.moderation.getEvent.$lxm:\n case tools.ozone.moderation.getRecord.$lxm:\n case tools.ozone.moderation.getRepo.$lxm:\n case tools.ozone.moderation.listScheduledActions.$lxm:\n case tools.ozone.moderation.queryEvents.$lxm:\n case tools.ozone.moderation.queryStatuses.$lxm:\n case tools.ozone.moderation.scheduleAction.$lxm:\n case tools.ozone.moderation.searchRepos.$lxm:\n case tools.ozone.safelink.addRule.$lxm:\n case tools.ozone.safelink.queryEvents.$lxm:\n case tools.ozone.safelink.queryRules.$lxm:\n case tools.ozone.safelink.removeRule.$lxm:\n case tools.ozone.safelink.updateRule.$lxm:\n case tools.ozone.team.addMember.$lxm:\n case tools.ozone.team.deleteMember.$lxm:\n case tools.ozone.team.listMembers.$lxm:\n case tools.ozone.team.updateMember.$lxm:\n case tools.ozone.verification.grantVerifications.$lxm:\n case tools.ozone.verification.listVerifications.$lxm:\n case tools.ozone.verification.revokeVerifications.$lxm:\n return {\n serviceId: 'atproto_labeler',\n serviceInfo: ctx.cfg.modService,\n }\n case com.atproto.moderation.createReport.$lxm:\n return {\n serviceId: 'atproto_labeler',\n serviceInfo: ctx.cfg.reportService,\n }\n default:\n return {\n serviceId: 'bsky_appview',\n serviceInfo: ctx.cfg.bskyAppView,\n }\n }\n}\n\nconst safeString = (str: unknown): string | undefined => {\n return typeof str === 'string' ? str : undefined\n}\n\nfunction logResponseError(this: ServerResponse, err: unknown): void {\n httpLogger.warn({ err }, 'error forwarding upstream response')\n}\n\nexport class PipethroughUpstreamError extends XRPCServerError {\n constructor(\n readonly upstream: {\n statusCode: number\n headers: IncomingHttpHeaders\n },\n payload: { message?: string; error?: string },\n options?: ErrorOptions,\n ) {\n const status =\n upstream.statusCode === 500\n ? ResponseType.UpstreamFailure\n : upstream.statusCode\n\n super(status, payload.message, payload.error, options)\n }\n\n get headers(): Record<string, string> {\n return Object.fromEntries(responseHeaders(this.upstream.headers, false))\n }\n\n get error() {\n return this.customErrorName ?? this.typeName\n }\n}\n"]}
1
+ {"version":3,"file":"pipethrough.js","sourceRoot":"","sources":["../src/pipethrough.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAY,QAAQ,EAAE,MAAM,aAAa,CAAA;AAE7D,OAAO,EAAE,KAAK,EAAc,IAAI,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AAC9D,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,IAAI,EACJ,kBAAkB,GACnB,MAAM,iBAAiB,CAAA;AAExB,OAAO,EAIL,mBAAmB,EACnB,mBAAmB,EACnB,YAAY,EACZ,SAAS,IAAI,eAAe,EAC5B,kBAAkB,EAClB,YAAY,GACb,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AACrE,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAA;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAGpD,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAExC,MAAM,UAAU,eAAe,CAAC,GAAgB;IAC9C,M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AAS,CAAA;AAClD,CAAC,CAAA;AAED,SAAS,gBAAgB,CAAuB,GAAY;IAC1D,UAAU,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,EAAE,oCAAoC,CAAC,CAAA;AAChE,CAAC;AAED,MAAM,OAAO,wBAAyB,SAAQ,eAAe;IAC3D,YACW,QAGR,EACD,OAA6C,EAC7C,OAAsB;QAEtB,MAAM,MAAM,GACV,QAAQ,CAAC,UAAU,KAAK,GAAG;YACzB,CAAC,CAAC,YAAY,CAAC,eAAe;YAC9B,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAA;QAEzB,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;wBAZ7C,QAAQ;IAanB,CAAC;IAED,IAAI,OAAO;QACT,OAAO,MAAM,CAAC,WAAW,CAAC,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAA;IAC1E,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,eAAe,IAAI,IAAI,CAAC,QAAQ,CAAA;IAC9C,CAAC;CACF","sourcesContent":["import { IncomingHttpHeaders, ServerResponse } from 'node:http'\nimport { PassThrough, Readable, finished } from 'node:stream'\nimport { Request } from 'express'\nimport { Agent, Dispatcher, Pool, interceptors } from 'undici'\nimport {\n decodeStream,\n getServiceEndpoint,\n omit,\n streamToNodeBuffer,\n} from '@atproto/common'\nimport { RpcPermissionMatch } from '@atproto/oauth-scopes'\nimport {\n CatchallHandler,\n HandlerPipeThroughBuffer,\n HandlerPipeThroughStream,\n InternalServerError,\n InvalidRequestError,\n ResponseType,\n XRPCError as XRPCServerError,\n excludeErrorResult,\n parseReqNsid,\n} from '@atproto/xrpc-server'\nimport { isUnicastIp, unicastLookup } from '@atproto-labs/fetch-node'\nimport { buildProxiedContentEncoding } from '@atproto-labs/xrpc-utils'\nimport { isAccessPrivileged } from './auth-scope.js'\nimport { ProxyConfig } from './config/config.js'\nimport { AppContext } from './context.js'\nimport { chat, com, tools } from './lexicons/index.js'\nimport { httpLogger } from './logger.js'\n\nexport function buildProxyAgent(cfg: ProxyConfig): Dispatcher {\n const agent = new Agent({\n allowH2: cfg.allowHTTP2,\n headersTimeout: cfg.headersTimeout,\n maxResponseSize: cfg.maxResponseSize,\n bodyTimeout: cfg.bodyTimeout,\n factory: cfg.disableSsrfProtection\n ? undefined\n : (origin, opts) => {\n const { protocol, hostname } =\n origin instanceof URL ? origin : new URL(origin)\n if (protocol !== 'https:') {\n throw new Error(`Forbidden protocol \"${protocol}\"`)\n }\n if (isUnicastIp(hostname) === false) {\n throw new Error('Hostname resolved to non-unicast address')\n }\n return new Pool(origin, opts)\n },\n connect: {\n lookup: cfg.disableSsrfProtection ? undefined : unicastLookup,\n },\n })\n\n return agent.compose(\n cfg.maxRetries > 0\n ? interceptors.retry({\n statusCodes: [], // Only retry on socket errors\n methods: ['GET', 'HEAD'],\n maxRetries: cfg.maxRetries,\n })\n : (dispatch) => dispatch,\n )\n}\n\nexport const proxyHandler = (ctx: AppContext): CatchallHandler => {\n const performAuth = ctx.authVerifier.authorization<RpcPermissionMatch>({\n authorize: (permissions, { params }) => permissions.assertRpc(params),\n })\n\n return async (req, res, next) => {\n // /!\\ Hot path\n try {\n if (\n req.method !== 'GET' &&\n req.method !== 'HEAD' &&\n req.method !== 'POST'\n ) {\n throw new XRPCServerError(\n ResponseType.InvalidRequest,\n 'XRPC requests only supports GET and POST',\n )\n }\n\n const body = req.method === 'POST' ? req : undefined\n if (body != null && !body.readable) {\n // Body was already consumed by a previous middleware\n throw new InternalServerError('Request body is not readable')\n }\n\n const lxm = parseReqNsid(req)\n if (PROTECTED_METHODS.has(lxm)) {\n throw new InvalidRequestError('Bad token method', 'InvalidToken')\n }\n\n const {\n url: origin,\n did,\n serviceId,\n } = await parseProxyInfo(ctx, req, lxm)\n // Phase 1 of service auth updates: the scope check sees the combined\n // did#serviceId form (so OAuth callers' rpc:?aud=did#service scopes\n // match), while the outbound service-auth JWT keeps bare-DID aud\n // regardless of session type.\n const scopeAud = `${did}#${serviceId}`\n const tokenAud = did\n\n const authResult = await performAuth({\n req,\n res,\n params: { lxm, aud: scopeAud },\n })\n\n const { credentials } = excludeErrorResult(authResult)\n\n if (\n credentials.type === 'access' &&\n !isAccessPrivileged(credentials.scope) &&\n PRIVILEGED_METHODS.has(lxm)\n ) {\n throw new InvalidRequestError('Bad token method', 'InvalidToken')\n }\n\n const headers: IncomingHttpHeaders = {\n 'accept-encoding': req.headers['accept-encoding'] || 'identity',\n 'accept-language': req.headers['accept-language'],\n 'atproto-accept-labelers': req.headers['atproto-accept-labelers'],\n 'x-bsky-topics': req.headers['x-bsky-topics'],\n\n 'content-type': body && req.headers['content-type'],\n 'content-encoding': body && req.headers['content-encoding'],\n 'content-length': body && req.headers['content-length'],\n\n authorization: `Bearer ${await ctx.serviceAuthJwt(credentials.did, tokenAud, lxm)}`,\n }\n\n const dispatchOptions: Dispatcher.RequestOptions = {\n origin,\n method: req.method,\n path: req.originalUrl,\n body,\n headers,\n }\n\n await pipethroughStream(ctx, req, dispatchOptions, (upstream) => {\n res.status(upstream.statusCode)\n\n for (const [name, val] of responseHeaders(upstream.headers)) {\n res.setHeader(name, val)\n }\n\n // Note that we should not need to manually handle errors here (e.g. by\n // destroying the response), as the http server will handle them for us.\n res.on('error', logResponseError)\n\n // Tell undici to write the upstream response directly to the response\n return res\n })\n } catch (err) {\n next(err)\n }\n }\n}\n\nexport type PipethroughOptions = {\n /**\n * Specify the issuer (requester) for service auth. If not provided, no\n * authorization headers will be added to the request.\n */\n iss?: string\n\n /**\n * Override the audience for service auth. If not provided, the audience will\n * be determined based on the proxy service.\n */\n aud?: string\n\n /**\n * Override the lexicon method for service auth. If not provided, the lexicon\n * method will be determined based on the request path.\n */\n lxm?: string\n}\n\nexport async function pipethrough(\n ctx: AppContext,\n req: Request,\n options?: PipethroughOptions,\n): Promise<\n HandlerPipeThroughStream & {\n stream: Readable\n headers: Record<string, string>\n encoding: string\n }\n> {\n if (req.method !== 'GET' && req.method !== 'HEAD') {\n // pipethrough() is used from within xrpcServer handlers, which means that\n // the request body either has been parsed or is a readable stream that has\n // been piped for decoding & size limiting. Because of this, forwarding the\n // request body requires re-encoding it. Since we currently do not use\n // pipethrough() with procedures, proxying of request body is not\n // implemented.\n throw new InternalServerError(\n `Proxying of ${req.method} requests is not supported`,\n )\n }\n\n const lxm = parseReqNsid(req)\n\n const { url: origin, did: aud } = await parseProxyInfo(ctx, req, lxm)\n\n const dispatchOptions: Dispatcher.RequestOptions = {\n origin,\n method: req.method,\n path: req.originalUrl,\n headers: {\n 'accept-language': req.headers['accept-language'],\n 'atproto-accept-labelers': req.headers['atproto-accept-labelers'],\n 'x-bsky-topics': req.headers['x-bsky-topics'],\n\n // Because we sometimes need to interpret the response (e.g. during\n // read-after-write, through asPipeThroughBuffer()), we need to ask the\n // upstream server for an encoding that both the requester and the PDS can\n // understand. Since we might have to do the decoding ourselves, we will\n // use our own preferences (and weight) to negotiate the encoding.\n 'accept-encoding': buildProxiedContentEncoding(\n req.headers['accept-encoding'],\n ctx.cfg.proxy.preferCompressed,\n ),\n\n authorization: options?.iss\n ? `Bearer ${await ctx.serviceAuthJwt(options.iss, options.aud ?? aud, options.lxm ?? lxm)}`\n : undefined,\n },\n\n // Use a high water mark to buffer more data while performing async\n // operations before this stream is consumed. This is especially useful\n // while processing read-after-write operations.\n highWaterMark: 2 * 65536, // twice the default (64KiB)\n }\n\n const { headers, body } = await pipethroughRequest(ctx, req, dispatchOptions)\n\n return {\n encoding: safeString(headers['content-type']) ?? 'application/json',\n headers: Object.fromEntries(responseHeaders(headers)),\n stream: body,\n }\n}\n\n// Request setup/formatting\n// -------------------\n\nexport function computeProxyTo(\n ctx: AppContext,\n req: Request,\n lxm: string,\n): string {\n const proxyToHeader = req.header('atproto-proxy')\n if (proxyToHeader) return proxyToHeader\n\n const service = defaultService(ctx, lxm)\n if (service.serviceInfo) {\n return `${service.serviceInfo.did}#${service.serviceId}`\n }\n\n throw new InvalidRequestError(`No service configured for ${lxm}`)\n}\n\n// Bare-DID portion of `proxyTo`, suitable as a service-auth JWT audience\n// (Phase 1 of service auth updates).\nexport function bareDidFromProxyTo(proxyTo: string): string {\n const hashIndex = proxyTo.indexOf('#')\n return hashIndex === -1 ? proxyTo : proxyTo.slice(0, hashIndex)\n}\n\nexport async function parseProxyInfo(\n ctx: AppContext,\n req: Request,\n lxm: string,\n): Promise<{ url: string; did: string; serviceId: string }> {\n // /!\\ Hot path\n\n const proxyToHeader = req.header('atproto-proxy')\n if (proxyToHeader) return parseProxyHeader(ctx, proxyToHeader)\n\n const { serviceId, serviceInfo } = defaultService(ctx, lxm)\n if (serviceInfo) return { ...serviceInfo, serviceId }\n\n throw new InvalidRequestError(`No service configured for ${lxm}`)\n}\n\nexport const parseProxyHeader = async (\n // Using subset of AppContext for testing purposes\n ctx: Pick<AppContext, 'cfg' | 'idResolver'>,\n proxyTo: string,\n): Promise<{ did: string; url: string; serviceId: string }> => {\n // /!\\ Hot path\n\n const hashIndex = proxyTo.indexOf('#')\n\n if (hashIndex === 0) {\n throw new InvalidRequestError('no did specified in proxy header')\n }\n\n if (hashIndex === -1 || hashIndex === proxyTo.length - 1) {\n throw new InvalidRequestError('no service id specified in proxy header')\n }\n\n // More than one hash\n if (proxyTo.indexOf('#', hashIndex + 1) !== -1) {\n throw new InvalidRequestError('invalid proxy header format')\n }\n\n // Basic validation\n if (proxyTo.includes(' ')) {\n throw new InvalidRequestError('proxy header cannot contain spaces')\n }\n\n const did = proxyTo.slice(0, hashIndex)\n const serviceId = proxyTo.slice(hashIndex + 1)\n\n // Special case a configured appview, while still proxying correctly any other appview\n if (\n ctx.cfg.bskyAppView &&\n proxyTo === `${ctx.cfg.bskyAppView.did}#bsky_appview`\n ) {\n return { did, url: ctx.cfg.bskyAppView.url, serviceId }\n }\n\n const didDoc = await ctx.idResolver.did.resolve(did)\n if (!didDoc) {\n throw new InvalidRequestError('could not resolve proxy did')\n }\n\n const url = getServiceEndpoint(didDoc, { id: `#${serviceId}` })\n if (!url) {\n throw new InvalidRequestError('could not resolve proxy did service url')\n }\n\n return { did, url, serviceId }\n}\n\n/**\n * Utility function that wraps the undici stream() function and handles request\n * and response errors by wrapping them in XRPCError instances. This function is\n * more efficient than \"pipethroughRequest\" when a writable stream to pipe the\n * upstream response to is available.\n */\nasync function pipethroughStream(\n ctx: AppContext,\n req: Request,\n dispatchOptions: Dispatcher.RequestOptions,\n successStreamFactory: Dispatcher.StreamFactory,\n): Promise<void> {\n return new Promise<void>((resolve, reject) => {\n void ctx.proxyAgent\n .stream(dispatchOptions, (upstream) => {\n if (upstream.statusCode >= 400) {\n const passThrough = new PassThrough()\n\n void tryParsingError(upstream.headers, passThrough).then((parsed) => {\n const xrpcError = new PipethroughUpstreamError(upstream, parsed, {\n cause: dispatchOptions,\n })\n\n reject(xrpcError)\n }, reject)\n\n return passThrough\n }\n\n const writable = successStreamFactory(upstream)\n\n // As soon as the control was passed to the writable stream (i.e. by\n // returning the writable hereafter), pipethroughStream() is considered\n // to have succeeded. Any error occurring while writing upstream data to\n // the writable stream should be handled through the stream's error\n // state (i.e. successStreamFactory() must ensure that error events on\n // the returned writable will be handled).\n resolve()\n\n return writable\n })\n // The following catch block will be triggered with either network errors\n // or writable stream errors. In the latter case, the promise will already\n // be resolved, and reject()ing it there after will have no effect. Those\n // error would still be logged by the successStreamFactory() function.\n .catch(handleUpstreamRequestError.bind(req))\n .catch(reject)\n })\n}\n\n/**\n * Utility function that wraps the undici request() function and handles request\n * and response errors by wrapping them in XRPCError instances.\n */\nasync function pipethroughRequest(\n ctx: AppContext,\n req: Request,\n dispatchOptions: Dispatcher.RequestOptions,\n) {\n // HandlerPipeThroughStream requires a readable stream to be returned, so we\n // use the (less efficient) request() function instead.\n\n const upstream = await ctx.proxyAgent\n .request(dispatchOptions)\n .catch(handleUpstreamRequestError.bind(req))\n\n if (upstream.statusCode >= 400) {\n const parsed = await tryParsingError(upstream.headers, upstream.body)\n\n throw new PipethroughUpstreamError(upstream, parsed, {\n cause: dispatchOptions,\n })\n }\n\n return upstream\n}\n\nfunction handleUpstreamRequestError(\n this: Request,\n err: unknown,\n message = 'Upstream service unreachable',\n): never {\n const logger = isPinoHttpRequest(this) ? this.log : httpLogger\n logger.error({ err }, message)\n throw new XRPCServerError(ResponseType.UpstreamFailure, message, undefined, {\n cause: err,\n })\n}\n\nfunction isPinoHttpRequest(req: Request): req is Request & {\n log: { error: (obj: unknown, msg: string) => void }\n} {\n return typeof (req as { log?: any }).log?.error === 'function'\n}\n\n// Request parsing/forwarding\n// -------------------\n\nexport function isJsonContentType(contentType?: string): boolean | undefined {\n if (!contentType) return undefined\n return /application\\/(?:\\w+\\+)?json/i.test(contentType)\n}\n\nasync function tryParsingError(\n headers: IncomingHttpHeaders,\n readable: Readable,\n): Promise<{ error?: string; message?: string }> {\n if (isJsonContentType(headers['content-type']) === false) {\n // We don't known how to parse non JSON content types so we can discard the\n // whole response.\n\n // Since we don't care about the response, we would normally just destroy\n // the stream. However, if the underlying HTTP connection is an HTTP/1.1\n // connection, this also destroys the underlying (keep-alive) TCP socket. In\n // order to avoid destroying the TCP socket, while avoiding the cost of\n // consuming too much IO, we give it a chance to finish first.\n\n // @NOTE we need to listen (and ignore) \"error\" events, otherwise the\n // process could crash (since we drain the stream asynchronously here). This\n // is performed through the \"finished\" call below.\n\n const to = setTimeout(() => {\n readable.destroy()\n }, 100)\n finished(readable, (_err) => {\n clearTimeout(to)\n })\n readable.resume()\n\n return {}\n }\n\n try {\n const buffer = await bufferUpstreamResponse(\n readable,\n headers['content-encoding'],\n )\n\n const errInfo: unknown = JSON.parse(buffer.toString('utf8'))\n return {\n error: safeString(errInfo?.['error']),\n message: safeString(errInfo?.['message']),\n }\n } catch (err) {\n // Failed to read, decode, buffer or parse. No big deal.\n return {}\n }\n}\n\nasync function bufferUpstreamResponse(\n readable: Readable,\n contentEncoding?: string | string[],\n): Promise<Buffer> {\n try {\n return await streamToNodeBuffer(decodeStream(readable, contentEncoding))\n } catch (err) {\n if (!readable.destroyed) readable.destroy()\n\n throw new XRPCServerError(\n ResponseType.UpstreamFailure,\n err instanceof TypeError ? err.message : 'unable to decode request body',\n undefined,\n { cause: err },\n )\n }\n}\n\nexport async function asPipeThroughBuffer(\n input: HandlerPipeThroughStream,\n): Promise<HandlerPipeThroughBuffer> {\n return {\n buffer: await bufferUpstreamResponse(\n input.stream,\n input.headers?.['content-encoding'],\n ),\n headers: omit(input.headers, ['content-encoding', 'content-length']),\n encoding: input.encoding,\n }\n}\n\n// Response parsing/forwarding\n// -------------------\n\nconst RES_HEADERS_TO_FORWARD = [\n 'atproto-repo-rev',\n 'atproto-content-labelers',\n 'retry-after',\n]\n\nfunction* responseHeaders(\n headers: IncomingHttpHeaders,\n includeContentHeaders = true,\n): Generator<[string, string]> {\n if (includeContentHeaders) {\n const length = headers['content-length']\n if (length) yield ['content-length', length]\n\n const encoding = headers['content-encoding']\n if (encoding) yield ['content-encoding', encoding]\n\n const type = headers['content-type']\n if (type) yield ['content-type', type]\n\n const language = headers['content-language']\n if (language) yield ['content-language', language]\n }\n\n for (let i = 0; i < RES_HEADERS_TO_FORWARD.length; i++) {\n const name = RES_HEADERS_TO_FORWARD[i]\n const val = headers[name]\n\n if (val != null) {\n const value: string = Array.isArray(val) ? val.join(',') : val\n yield [name, value]\n }\n }\n}\n\n// Utils\n// -------------------\n\n/**\n * Performs lexicon method matching on a set of methods,\n * taking into account that they are treated case-insensitively.\n */\nexport class LxmSet {\n private inner: Set<string>\n private original: Iterable<string>\n constructor(items: Iterable<string>) {\n this.inner = new Set(Array.from(items, normalizeLxm))\n this.original = items\n }\n has(lxm: string) {\n return this.inner.has(normalizeLxm(lxm))\n }\n *[Symbol.iterator](): Iterator<string> {\n yield* this.original\n }\n}\n\nexport function normalizeLxm(lxm: string) {\n return lxm.toLowerCase()\n}\n\nexport const CHAT_BSKY_METHODS = new LxmSet([\n chat.bsky.actor.deleteAccount.$lxm,\n chat.bsky.actor.exportAccountData.$lxm,\n chat.bsky.convo.deleteMessageForSelf.$lxm,\n chat.bsky.convo.getConvo.$lxm,\n chat.bsky.convo.getConvoForMembers.$lxm,\n chat.bsky.convo.getLog.$lxm,\n chat.bsky.convo.getMessages.$lxm,\n chat.bsky.convo.leaveConvo.$lxm,\n chat.bsky.convo.listConvos.$lxm,\n chat.bsky.convo.muteConvo.$lxm,\n chat.bsky.convo.sendMessage.$lxm,\n chat.bsky.convo.sendMessageBatch.$lxm,\n chat.bsky.convo.unmuteConvo.$lxm,\n chat.bsky.convo.updateRead.$lxm,\n])\n\nexport const PRIVILEGED_METHODS = new LxmSet([\n ...CHAT_BSKY_METHODS,\n com.atproto.server.createAccount.$lxm,\n])\n\n// These endpoints are related to account management and must be used directly,\n// not proxied or service-authed. Service auth may be utilized between PDS and\n// entryway for these methods.\nexport const PROTECTED_METHODS = new LxmSet([\n com.atproto.admin.sendEmail.$lxm,\n com.atproto.identity.requestPlcOperationSignature.$lxm,\n com.atproto.identity.signPlcOperation.$lxm,\n com.atproto.identity.updateHandle.$lxm,\n com.atproto.server.activateAccount.$lxm,\n com.atproto.server.confirmEmail.$lxm,\n com.atproto.server.createAppPassword.$lxm,\n com.atproto.server.deactivateAccount.$lxm,\n com.atproto.server.getAccountInviteCodes.$lxm,\n com.atproto.server.getSession.$lxm,\n com.atproto.server.listAppPasswords.$lxm,\n com.atproto.server.requestAccountDelete.$lxm,\n com.atproto.server.requestEmailConfirmation.$lxm,\n com.atproto.server.requestEmailUpdate.$lxm,\n com.atproto.server.revokeAppPassword.$lxm,\n com.atproto.server.updateEmail.$lxm,\n])\n\nconst defaultService = (\n ctx: AppContext,\n nsid: string,\n): {\n serviceId: string\n serviceInfo: { url: string; did: string } | null\n} => {\n switch (nsid) {\n case tools.ozone.communication.createTemplate.$lxm:\n case tools.ozone.communication.deleteTemplate.$lxm:\n case tools.ozone.communication.listTemplates.$lxm:\n case tools.ozone.communication.updateTemplate.$lxm:\n case tools.ozone.moderation.cancelScheduledActions.$lxm:\n case tools.ozone.moderation.emitEvent.$lxm:\n case tools.ozone.moderation.getAccountTimeline.$lxm:\n case tools.ozone.moderation.getEvent.$lxm:\n case tools.ozone.moderation.getRecord.$lxm:\n case tools.ozone.moderation.getRepo.$lxm:\n case tools.ozone.moderation.listScheduledActions.$lxm:\n case tools.ozone.moderation.queryEvents.$lxm:\n case tools.ozone.moderation.queryStatuses.$lxm:\n case tools.ozone.moderation.scheduleAction.$lxm:\n case tools.ozone.moderation.searchRepos.$lxm:\n case tools.ozone.safelink.addRule.$lxm:\n case tools.ozone.safelink.queryEvents.$lxm:\n case tools.ozone.safelink.queryRules.$lxm:\n case tools.ozone.safelink.removeRule.$lxm:\n case tools.ozone.safelink.updateRule.$lxm:\n case tools.ozone.team.addMember.$lxm:\n case tools.ozone.team.deleteMember.$lxm:\n case tools.ozone.team.listMembers.$lxm:\n case tools.ozone.team.updateMember.$lxm:\n case tools.ozone.verification.grantVerifications.$lxm:\n case tools.ozone.verification.listVerifications.$lxm:\n case tools.ozone.verification.revokeVerifications.$lxm:\n return {\n serviceId: 'atproto_labeler',\n serviceInfo: ctx.cfg.modService,\n }\n case com.atproto.moderation.createReport.$lxm:\n return {\n serviceId: 'atproto_labeler',\n serviceInfo: ctx.cfg.reportService,\n }\n default:\n return {\n serviceId: 'bsky_appview',\n serviceInfo: ctx.cfg.bskyAppView,\n }\n }\n}\n\nconst safeString = (str: unknown): string | undefined => {\n return typeof str === 'string' ? str : undefined\n}\n\nfunction logResponseError(this: ServerResponse, err: unknown): void {\n httpLogger.warn({ err }, 'error forwarding upstream response')\n}\n\nexport class PipethroughUpstreamError extends XRPCServerError {\n constructor(\n readonly upstream: {\n statusCode: number\n headers: IncomingHttpHeaders\n },\n payload: { message?: string; error?: string },\n options?: ErrorOptions,\n ) {\n const status =\n upstream.statusCode === 500\n ? ResponseType.UpstreamFailure\n : upstream.statusCode\n\n super(status, payload.message, payload.error, options)\n }\n\n get headers(): Record<string, string> {\n return Object.fromEntries(responseHeaders(this.upstream.headers, false))\n }\n\n get error() {\n return this.customErrorName ?? this.typeName\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atproto/pds",
3
- "version": "0.5.6",
3
+ "version": "0.5.8",
4
4
  "license": "MIT",
5
5
  "description": "Reference implementation of atproto Personal Data Server (PDS)",
6
6
  "keywords": [
@@ -40,27 +40,27 @@
40
40
  "pino-http": "^8.2.1",
41
41
  "typed-emitter": "^2.1.0",
42
42
  "uint8arrays": "^5.0.0",
43
- "undici": "^6.19.8",
43
+ "undici": "^8.5.0",
44
44
  "zod": "^3.23.8",
45
- "@atproto-labs/fetch-node": "^0.3.1",
46
45
  "@atproto-labs/simple-store": "^0.4.1",
47
- "@atproto-labs/simple-store-memory": "^0.2.1",
48
- "@atproto-labs/xrpc-utils": "^0.1.1",
49
46
  "@atproto-labs/simple-store-redis": "^0.1.1",
50
47
  "@atproto/common": "^0.6.3",
51
48
  "@atproto/aws": "^0.3.1",
49
+ "@atproto-labs/fetch-node": "^0.3.2",
50
+ "@atproto-labs/xrpc-utils": "^0.1.1",
52
51
  "@atproto/crypto": "^0.5.1",
52
+ "@atproto-labs/simple-store-memory": "^0.2.1",
53
53
  "@atproto/did": "^0.5.1",
54
54
  "@atproto/identity": "^0.5.1",
55
- "@atproto/lex": "^0.1.4",
56
- "@atproto/lex-cbor": "^0.1.1",
57
55
  "@atproto/lex-data": "^0.1.2",
58
- "@atproto/oauth-scopes": "^0.5.1",
59
- "@atproto/repo": "^0.10.1",
56
+ "@atproto/lex-cbor": "^0.1.1",
60
57
  "@atproto/lex-json": "^0.1.1",
58
+ "@atproto/oauth-provider": "^0.19.2",
59
+ "@atproto/lex": "^0.1.4",
60
+ "@atproto/repo": "^0.10.1",
61
+ "@atproto/oauth-scopes": "^0.5.1",
61
62
  "@atproto/syntax": "^0.6.2",
62
63
  "@atproto/xrpc": "^0.8.1",
63
- "@atproto/oauth-provider": "^0.19.0",
64
64
  "@atproto/xrpc-server": "^0.11.2"
65
65
  },
66
66
  "devDependencies": {
@@ -78,10 +78,10 @@
78
78
  "puppeteer": "^23.11.1",
79
79
  "ts-node": "^10.8.2",
80
80
  "ws": "^8.12.0",
81
- "@atproto/bsky": "^0.0.243",
81
+ "@atproto/api": "^0.20.19",
82
+ "@atproto/bsky": "^0.0.247",
82
83
  "@atproto/lex-document": "^0.1.1",
83
- "@atproto/oauth-client-browser-example": "^0.1.1",
84
- "@atproto/api": "^0.20.16"
84
+ "@atproto/oauth-client-browser-example": "^0.1.1"
85
85
  },
86
86
  "type": "module",
87
87
  "exports": {
package/src/background.ts CHANGED
@@ -1,34 +1,65 @@
1
1
  import PQueue from 'p-queue'
2
2
  import { dbLogger } from './logger.js'
3
-
4
3
  // A simple queue for in-process, out-of-band/backgrounded work
5
4
 
6
- export class BackgroundQueue {
7
- queue: InstanceType<typeof PQueue> = new PQueue({ concurrency: 5 })
8
- destroyed = false
9
- constructor() {}
5
+ type Task<TContext> = (ctx: TContext, signal: AbortSignal) => Promise<void>
10
6
 
11
- add(task: Task) {
12
- if (this.destroyed) {
13
- return
14
- }
15
- this.queue
16
- .add(() => task())
17
- .catch((err) => {
7
+ export type BackgroundQueueOptions = NonNullable<
8
+ ConstructorParameters<typeof PQueue>[0]
9
+ > & {
10
+ concurrency: number
11
+ }
12
+
13
+ // @NOTE Keep this in sync with the BackgroundQueue in
14
+ // - packages/bsky/src/data-plane/server/background.ts
15
+ // - packages/ozone/src/background.ts
16
+ // - packages/pds/src/background.ts
17
+ export class BackgroundQueue<TContext = unknown> {
18
+ private abortController = new AbortController()
19
+ private queue: PQueue
20
+
21
+ public get signal(): AbortSignal {
22
+ return this.abortController.signal
23
+ }
24
+
25
+ public get destroyed() {
26
+ return this.signal.aborted
27
+ }
28
+
29
+ constructor(
30
+ private readonly context: TContext,
31
+ options?: BackgroundQueueOptions,
32
+ ) {
33
+ this.queue = new PQueue(options)
34
+ }
35
+
36
+ add(task: Task<TContext>) {
37
+ if (this.destroyed) return
38
+
39
+ this.queue.add<void>(async () => {
40
+ try {
41
+ // The task will receive a signal allowing it to abort if the
42
+ // backgroundQueue is destroyed.
43
+ await task(this.context, this.signal)
44
+ } catch (err) {
18
45
  dbLogger.error({ err }, 'background queue task failed')
19
- })
46
+ }
47
+ })
20
48
  }
21
49
 
22
50
  async processAll() {
23
- await this.queue.onIdle()
51
+ const { queue } = this
52
+ while (queue.size || queue.pending) await queue.onIdle()
24
53
  }
25
54
 
26
55
  // On destroy we stop accepting new tasks, but complete all pending/in-progress tasks.
27
56
  // The application calls this only once http connections have drained (tasks no longer being added).
28
57
  async destroy() {
29
- this.destroyed = true
30
- await this.queue.onIdle()
58
+ if (this.destroyed) {
59
+ dbLogger.warn('BackgroundQueue.destroy() called multiple times')
60
+ }
61
+
62
+ this.abortController.abort()
63
+ return this.processAll()
31
64
  }
32
65
  }
33
-
34
- type Task = () => Promise<void>
package/src/context.ts CHANGED
@@ -21,12 +21,7 @@ import {
21
21
  createServiceAuthHeaders,
22
22
  createServiceJwt,
23
23
  } from '@atproto/xrpc-server'
24
- import {
25
- Fetch,
26
- isUnicastIp,
27
- safeFetchWrap,
28
- unicastLookup,
29
- } from '@atproto-labs/fetch-node'
24
+ import { Fetch, safeFetchWrap } from '@atproto-labs/fetch-node'
30
25
  import { AccountManager } from './account-manager/account-manager.js'
31
26
  import { OAuthStore } from './account-manager/oauth-store.js'
32
27
  import { ScopeReferenceGetter } from './account-manager/scope-reference-getter.js'
@@ -47,6 +42,7 @@ import { ImageUrlBuilder } from './image/image-url-builder.js'
47
42
  import { fetchLogger, lexiconResolverLogger, oauthLogger } from './logger.js'
48
43
  import { ServerMailer } from './mailer/index.js'
49
44
  import { ModerationMailer } from './mailer/moderation.js'
45
+ import { buildProxyAgent } from './pipethrough.js'
50
46
  import { LocalViewer, LocalViewerCreator } from './read-after-write/viewer.js'
51
47
  import { getRedisClient } from './redis.js'
52
48
  import { Sequencer } from './sequencer/index.js'
@@ -181,7 +177,7 @@ export class AppContext {
181
177
  })
182
178
  const plcClient = new plc.Client(cfg.identity.plcUrl)
183
179
 
184
- const backgroundQueue = new BackgroundQueue()
180
+ const backgroundQueue = new BackgroundQueue(undefined, { concurrency: 5 })
185
181
  const crawlers = new Crawlers(
186
182
  backgroundQueue,
187
183
  cfg.service.hostname,
@@ -295,36 +291,7 @@ export class AppContext {
295
291
  )
296
292
 
297
293
  // An agent for performing HTTP requests based on user provided URLs.
298
- const proxyAgentBase = new undici.Agent({
299
- allowH2: cfg.proxy.allowHTTP2, // This is experimental
300
- headersTimeout: cfg.proxy.headersTimeout,
301
- maxResponseSize: cfg.proxy.maxResponseSize,
302
- bodyTimeout: cfg.proxy.bodyTimeout,
303
- factory: cfg.proxy.disableSsrfProtection
304
- ? undefined
305
- : (origin, opts) => {
306
- const { protocol, hostname } =
307
- origin instanceof URL ? origin : new URL(origin)
308
- if (protocol !== 'https:') {
309
- throw new Error(`Forbidden protocol "${protocol}"`)
310
- }
311
- if (isUnicastIp(hostname) === false) {
312
- throw new Error('Hostname resolved to non-unicast address')
313
- }
314
- return new undici.Pool(origin, opts)
315
- },
316
- connect: {
317
- lookup: cfg.proxy.disableSsrfProtection ? undefined : unicastLookup,
318
- },
319
- })
320
- const proxyAgent =
321
- cfg.proxy.maxRetries > 0
322
- ? new undici.RetryAgent(proxyAgentBase, {
323
- statusCodes: [], // Only retry on socket errors
324
- methods: ['GET', 'HEAD'],
325
- maxRetries: cfg.proxy.maxRetries,
326
- })
327
- : proxyAgentBase
294
+ const proxyAgent = buildProxyAgent(cfg.proxy)
328
295
 
329
296
  /**
330
297
  * A fetch() function that protects against SSRF attacks, large responses &
package/src/index.ts CHANGED
@@ -9,11 +9,8 @@ import http from 'node:http'
9
9
  import { PlcClientError } from '@did-plc/lib'
10
10
  import cors from 'cors'
11
11
  import express from 'express'
12
- // eslint-disable-next-line import/default, import/no-named-as-default-member
12
+ // eslint-disable-next-line import/default
13
13
  import httpTerminator from 'http-terminator'
14
- // eslint-disable-next-line import/no-named-as-default-member
15
- const { createHttpTerminator } = httpTerminator
16
- type HttpTerminator = ReturnType<typeof createHttpTerminator>
17
14
  import { DAY, SECOND } from '@atproto/common'
18
15
  import {
19
16
  MethodHandler,
@@ -64,7 +61,7 @@ export class PDS {
64
61
  public ctx: AppContext
65
62
  public app: express.Application
66
63
  public server?: http.Server
67
- private terminator?: HttpTerminator
64
+ private terminator?: httpTerminator.HttpTerminator
68
65
  private dbStatsInterval?: NodeJS.Timeout
69
66
  private sequencerStatsInterval?: NodeJS.Timeout
70
67
 
@@ -145,21 +142,42 @@ export class PDS {
145
142
  await this.ctx.sequencer.start()
146
143
  const server = this.app.listen(this.ctx.cfg.service.port)
147
144
  this.server = server
148
- this.server.keepAliveTimeout = 90000
149
- this.terminator = createHttpTerminator({ server })
145
+ this.server.keepAliveTimeout = 90_000
146
+ this.terminator = httpTerminator.createHttpTerminator({ server })
150
147
  await events.once(server, 'listening')
151
148
  return server
152
149
  }
153
150
 
154
151
  async destroy(): Promise<void> {
155
- await this.ctx.sequencer.destroy()
156
- await this.terminator?.terminate()
157
- await this.ctx.backgroundQueue.destroy()
158
- await this.ctx.accountManager.close()
159
- await this.ctx.redisScratch?.quit()
160
- await this.ctx.proxyAgent.destroy()
161
152
  clearInterval(this.dbStatsInterval)
162
153
  clearInterval(this.sequencerStatsInterval)
154
+
155
+ // @TODO Use disposable stack when it becomes available (Node24+)
156
+ try {
157
+ await this.terminator?.terminate()
158
+ } finally {
159
+ try {
160
+ await this.ctx.backgroundQueue.destroy()
161
+ } finally {
162
+ try {
163
+ await this.ctx.sequencer.destroy()
164
+ } finally {
165
+ try {
166
+ await this.ctx.accountManager.close()
167
+ } finally {
168
+ try {
169
+ await this.ctx.redisScratch?.quit()
170
+ } finally {
171
+ await this.ctx.proxyAgent.destroy()
172
+ }
173
+ }
174
+ }
175
+ }
176
+ }
177
+ }
178
+
179
+ async [Symbol.asyncDispose]() {
180
+ await this.destroy()
163
181
  }
164
182
  }
165
183