fedipod-server 0.21.0 → 0.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (332) hide show
  1. package/README.md +5 -4
  2. package/dist/claims.d.ts +3 -1
  3. package/dist/claims.js +20 -7
  4. package/dist/components/context.jsonld +6 -0
  5. package/dist/handler.d.ts +29 -1
  6. package/dist/handler.js +89 -4
  7. package/dist/handler.jsonld +36 -1
  8. package/lib/client/c2s.mjs +100 -3
  9. package/lib/client/masto/accounts.mjs +44 -4
  10. package/lib/client/masto/body.mjs +90 -3
  11. package/lib/client/masto/index.mjs +5 -1
  12. package/lib/client/masto/instance.mjs +11 -3
  13. package/lib/client/masto/media.mjs +3 -57
  14. package/lib/client/masto/oauth.mjs +66 -9
  15. package/lib/client/masto/render.mjs +62 -5
  16. package/lib/client/masto/statuses.mjs +25 -1
  17. package/lib/client/masto/timelines.mjs +128 -6
  18. package/lib/connections/tagfeed.mjs +42 -5
  19. package/lib/core/as2.mjs +36 -5
  20. package/lib/core/contexts/index.mjs +14 -0
  21. package/lib/core/contexts/litepub-0.1.json +60 -0
  22. package/lib/core/contexts/map.json +3 -1
  23. package/lib/core/contexts/quotes.json +18 -0
  24. package/lib/core/graphview.mjs +41 -3
  25. package/lib/core/intake/activities.mjs +136 -2
  26. package/lib/core/intake/activity.mjs +79 -1
  27. package/lib/core/intake/group.mjs +37 -3
  28. package/lib/core/intake/index.mjs +32 -2
  29. package/lib/core/intake/notes.mjs +60 -3
  30. package/lib/core/lease.mjs +12 -2
  31. package/lib/core/profile-page.mjs +104 -0
  32. package/lib/core/publisher/collections.mjs +6 -1
  33. package/lib/core/publisher/index.mjs +35 -17
  34. package/lib/core/publisher/notes.mjs +104 -3
  35. package/lib/core/shapes/activitystreams.ttl +28 -0
  36. package/lib/core/shapes/index.mjs +26 -1
  37. package/lib/core/wire-quotes.mjs +71 -0
  38. package/lib/core/wire.mjs +59 -103
  39. package/lib/device/admin/routes/lifecycle.mjs +9 -0
  40. package/lib/device/admin/static.mjs +4 -1
  41. package/lib/device/admin/surface.mjs +26 -2
  42. package/lib/device/certs.mjs +18 -2
  43. package/lib/device/cli/commands/setup.mjs +6 -2
  44. package/lib/device/cli/commands/state.mjs +3 -1
  45. package/lib/device/gateway-move.mjs +58 -0
  46. package/lib/device/migrate.mjs +3 -1
  47. package/lib/device/setup.mjs +67 -7
  48. package/lib/gateway/front-core.mjs +307 -36
  49. package/lib/gateway/gateway-core.mjs +15 -6
  50. package/lib/gateway/notices.mjs +84 -0
  51. package/lib/gateway/quiet.mjs +184 -0
  52. package/lib/pod/root.mjs +6 -3
  53. package/lib/pod/state.mjs +8 -7
  54. package/lib/pod/transport.mjs +5 -1
  55. package/lib/session/README.md +123 -0
  56. package/lib/session/demo.html +94 -0
  57. package/lib/session/fedi-account.mjs +346 -0
  58. package/lib/session/fedi-login.mjs +123 -0
  59. package/lib/session/oidc-session.mjs +233 -0
  60. package/lib/session/package.json +41 -0
  61. package/package.json +1 -1
  62. package/run-agent.mjs +28 -0
  63. package/vendor/gate.cjs +6 -3
  64. package/web/admin/bar.css +66 -0
  65. package/web/admin/bar.js +38 -0
  66. package/web/admin/client/index.html +31 -3
  67. package/web/admin/client-pick.js +79 -0
  68. package/web/admin/gateway.js +22 -0
  69. package/web/admin/index.html +54 -13
  70. package/web/admin/notices-bar.js +90 -0
  71. package/web/admin/oauth-signin.mjs +37 -0
  72. package/web/admin/record.js +13 -1
  73. package/web/admin/setup/index.html +31 -3
  74. package/web/admin/tokens.css +15 -3
  75. package/web/admin/upkeep.js +4 -5
  76. package/web/app/README.md +14 -10
  77. package/web/app/admin-facade.mjs +51 -12
  78. package/web/app/agent.mjs +157 -19
  79. package/web/app/authorize_interaction.html +56 -0
  80. package/web/app/authorize_interaction.js +69 -0
  81. package/web/app/boot.mjs +233 -95
  82. package/web/app/dist/boot.js +477 -569
  83. package/web/app/dist/boot.js.map +4 -4
  84. package/web/app/dist/sw.js +1861 -532
  85. package/web/app/dist/sw.js.map +4 -4
  86. package/web/app/gateway-move.mjs +60 -0
  87. package/web/app/index.html +40 -49
  88. package/web/app/keys-browser.mjs +12 -15
  89. package/web/app/keystore.mjs +19 -36
  90. package/web/app/oidc-session.mjs +5 -188
  91. package/web/app/signup.mjs +172 -132
  92. package/web/app/sw-src.mjs +1 -1
  93. package/web/app/update.js +66 -0
  94. package/web/front/admin.html +5 -3
  95. package/web/front/new-account.html +2 -2
  96. package/web/front/notices.html +69 -0
  97. package/web/front/notices.js +107 -0
  98. package/web/front/run.html +15 -8
  99. package/web/front/run.js +124 -36
  100. package/web/icons/forum.svg +11 -0
  101. package/web/icons/gateway.svg +14 -0
  102. package/web/icons/local.svg +11 -0
  103. package/web/app/index.html~ +0 -152
  104. package/web/app/site/_headers +0 -9
  105. package/web/app/site/_redirects +0 -22
  106. package/web/app/site/admin/actors.js +0 -145
  107. package/web/app/site/admin/bar.css +0 -60
  108. package/web/app/site/admin/bar.js +0 -61
  109. package/web/app/site/admin/client/client.js +0 -66
  110. package/web/app/site/admin/client/index.html +0 -43
  111. package/web/app/site/admin/common.js +0 -23
  112. package/web/app/site/admin/connections.js +0 -112
  113. package/web/app/site/admin/gateway.js +0 -111
  114. package/web/app/site/admin/group.js +0 -258
  115. package/web/app/site/admin/index.html +0 -564
  116. package/web/app/site/admin/record.js +0 -378
  117. package/web/app/site/admin/setup/index.html +0 -215
  118. package/web/app/site/admin/setup/setup.js +0 -326
  119. package/web/app/site/admin/tokens.css +0 -56
  120. package/web/app/site/admin/upkeep.js +0 -178
  121. package/web/app/site/admin/window.css +0 -55
  122. package/web/app/site/admin/window.js +0 -136
  123. package/web/app/site/app/404.html +0 -40
  124. package/web/app/site/app/_headers +0 -2
  125. package/web/app/site/app/apple-touch-icon.png +0 -0
  126. package/web/app/site/app/assets/ICONS-DIPJeU0C.js +0 -2
  127. package/web/app/site/app/assets/ICONS-DIPJeU0C.js.map +0 -1
  128. package/web/app/site/app/assets/ScheduledAtField-D-Abfo4J.js +0 -183
  129. package/web/app/site/app/assets/ScheduledAtField-D-Abfo4J.js.map +0 -1
  130. package/web/app/site/app/assets/Temml-CCjoacWt.woff2 +0 -0
  131. package/web/app/site/app/assets/__vite-browser-external-C7iut881.js +0 -2
  132. package/web/app/site/app/assets/__vite-browser-external-C7iut881.js.map +0 -1
  133. package/web/app/site/app/assets/boosts-carousel-BiOaNdMT.jpg +0 -0
  134. package/web/app/site/app/assets/catch-up-O5q5C75Z.png +0 -0
  135. package/web/app/site/app/assets/chunk-aKtaBQYM.js +0 -1
  136. package/web/app/site/app/assets/compose-CFEx7wb4.js +0 -2
  137. package/web/app/site/app/assets/compose-CFEx7wb4.js.map +0 -1
  138. package/web/app/site/app/assets/compose-ZJN5xSb4.js +0 -35
  139. package/web/app/site/app/assets/compose-ZJN5xSb4.js.map +0 -1
  140. package/web/app/site/app/assets/debug.module-YFQgwnIr.js +0 -52
  141. package/web/app/site/app/assets/debug.module-YFQgwnIr.js.map +0 -1
  142. package/web/app/site/app/assets/dom-p1YcJ5Rw.js +0 -2
  143. package/web/app/site/app/assets/dom-p1YcJ5Rw.js.map +0 -1
  144. package/web/app/site/app/assets/home-mobile-dark@2x-Dc-J8-SM.png +0 -0
  145. package/web/app/site/app/assets/home-mobile-light@2x-Bd3fod8m.png +0 -0
  146. package/web/app/site/app/assets/home-tablet-dark@2x-BgcNI8le.png +0 -0
  147. package/web/app/site/app/assets/home-tablet-light@2x-BW2RV9T6.png +0 -0
  148. package/web/app/site/app/assets/icons/add-circle-line-WD0mwORD.js +0 -1
  149. package/web/app/site/app/assets/icons/alert-line-CpFUMf9s.js +0 -1
  150. package/web/app/site/app/assets/icons/android-2-line-Bzxnrd3S.js +0 -1
  151. package/web/app/site/app/assets/icons/announcement-line-5nwaJFJm.js +0 -1
  152. package/web/app/site/app/assets/icons/arrow-down-circle-line-a7Id9-Iv.js +0 -1
  153. package/web/app/site/app/assets/icons/arrow-down-line-B8uzXzq6.js +0 -1
  154. package/web/app/site/app/assets/icons/arrow-left-line-CGrGT9C-.js +0 -1
  155. package/web/app/site/app/assets/icons/arrow-right-line-CE-HERfX.js +0 -1
  156. package/web/app/site/app/assets/icons/arrow-to-up-line-CvdQjmcy.js +0 -1
  157. package/web/app/site/app/assets/icons/arrow-up-circle-line-DEparSNF.js +0 -1
  158. package/web/app/site/app/assets/icons/arrow-up-line-C7yBeugc.js +0 -1
  159. package/web/app/site/app/assets/icons/arrows-right-line-BtbXmJGP.js +0 -1
  160. package/web/app/site/app/assets/icons/at-line-CF66Bznk.js +0 -1
  161. package/web/app/site/app/assets/icons/attachment-line-BY8It-l9.js +0 -1
  162. package/web/app/site/app/assets/icons/blockquote-line-BS6pU_hm.js +0 -1
  163. package/web/app/site/app/assets/icons/board-line-C0UWXyA6.js +0 -1
  164. package/web/app/site/app/assets/icons/bookmark-line-1CtX5JLF.js +0 -1
  165. package/web/app/site/app/assets/icons/building-5-line-Dd59MzbO.js +0 -1
  166. package/web/app/site/app/assets/icons/bus-2-line-6_dvA0GG.js +0 -1
  167. package/web/app/site/app/assets/icons/calendar-day-line-Crpl_fmu.js +0 -1
  168. package/web/app/site/app/assets/icons/calendar-month-line-vommts2C.js +0 -1
  169. package/web/app/site/app/assets/icons/calendar-time-add-line-BU_DTlQk.js +0 -1
  170. package/web/app/site/app/assets/icons/camera-line-Cv69MEei.js +0 -1
  171. package/web/app/site/app/assets/icons/celebrate-line-B8DvIoi0.js +0 -1
  172. package/web/app/site/app/assets/icons/chart-bar-line-FK-QOmtF.js +0 -1
  173. package/web/app/site/app/assets/icons/chart-line-line-BGcJAFWw.js +0 -1
  174. package/web/app/site/app/assets/icons/chat-3-line-YFK2-hwz.js +0 -1
  175. package/web/app/site/app/assets/icons/check-circle-line-DsAxFr5-.js +0 -1
  176. package/web/app/site/app/assets/icons/clipboard-line-BBp364gJ.js +0 -1
  177. package/web/app/site/app/assets/icons/close-circle-line-CICdiuGz.js +0 -1
  178. package/web/app/site/app/assets/icons/close-line-DYrFWcjv.js +0 -1
  179. package/web/app/site/app/assets/icons/cloud-line-tiQAbah8.js +0 -1
  180. package/web/app/site/app/assets/icons/code-line-fAl8iiV3.js +0 -1
  181. package/web/app/site/app/assets/icons/comment-2-line-CR3g7WeB.js +0 -1
  182. package/web/app/site/app/assets/icons/copy-2-line-CLW69yF5.js +0 -1
  183. package/web/app/site/app/assets/icons/delete-2-line-B8xmbr4n.js +0 -1
  184. package/web/app/site/app/assets/icons/document-3-line-DBGNhAg2.js +0 -1
  185. package/web/app/site/app/assets/icons/document-line-C7mb9sb7.js +0 -1
  186. package/web/app/site/app/assets/icons/down-line-BGqSSThd.js +0 -1
  187. package/web/app/site/app/assets/icons/edit-4-line-DcgGaEhx.js +0 -1
  188. package/web/app/site/app/assets/icons/emoji-2-line-D8YgnM-y.js +0 -1
  189. package/web/app/site/app/assets/icons/exit-line-Dc07BS-x.js +0 -1
  190. package/web/app/site/app/assets/icons/external-link-line-BvpSkmjO.js +0 -1
  191. package/web/app/site/app/assets/icons/eye-2-line-CiWXx-f_.js +0 -1
  192. package/web/app/site/app/assets/icons/eye-close-line-BgTaSJ4P.js +0 -1
  193. package/web/app/site/app/assets/icons/filter-2-line-B_mR2usy.js +0 -1
  194. package/web/app/site/app/assets/icons/filter-line-C_nm-3cU.js +0 -1
  195. package/web/app/site/app/assets/icons/flag-1-line-C2HB05I0.js +0 -1
  196. package/web/app/site/app/assets/icons/forbid-circle-line-D3LTT9yd.js +0 -1
  197. package/web/app/site/app/assets/icons/formula-line-DLrt2d6j.js +0 -1
  198. package/web/app/site/app/assets/icons/grid-line-CgUmEikf.js +0 -1
  199. package/web/app/site/app/assets/icons/group-line-C5fnX0wU.js +0 -1
  200. package/web/app/site/app/assets/icons/hand-finger-2-line-BGgxbuL9.js +0 -1
  201. package/web/app/site/app/assets/icons/hashtag-line-CyTEEXBb.js +0 -1
  202. package/web/app/site/app/assets/icons/heart-crack-line-BZddbO2C.js +0 -1
  203. package/web/app/site/app/assets/icons/heart-line-CJ7K47J4.js +0 -1
  204. package/web/app/site/app/assets/icons/history-2-line-kWWvFzqv.js +0 -1
  205. package/web/app/site/app/assets/icons/history-line-bGQiwbTH.js +0 -1
  206. package/web/app/site/app/assets/icons/home-3-line-fRU1zeLG.js +0 -1
  207. package/web/app/site/app/assets/icons/information-line-iNk6-sOY.js +0 -1
  208. package/web/app/site/app/assets/icons/keyboard-line-DsCyuQNz.js +0 -1
  209. package/web/app/site/app/assets/icons/layout-4-line-CZkOX52Z.js +0 -1
  210. package/web/app/site/app/assets/icons/layout-5-line-B_znt5wO.js +0 -1
  211. package/web/app/site/app/assets/icons/left-line-eUw0tya4.js +0 -1
  212. package/web/app/site/app/assets/icons/lightning-line-DaKoDdix.js +0 -1
  213. package/web/app/site/app/assets/icons/link-2-line-DCqLmMA7.js +0 -1
  214. package/web/app/site/app/assets/icons/list-check-line-BAxosBh9.js +0 -1
  215. package/web/app/site/app/assets/icons/lock-line-CPoaXeUW.js +0 -1
  216. package/web/app/site/app/assets/icons/mail-line-B0P8aa1L.js +0 -1
  217. package/web/app/site/app/assets/icons/moon-line-CEqNAToP.js +0 -1
  218. package/web/app/site/app/assets/icons/more-1-fill-Dw2e5xab.js +0 -1
  219. package/web/app/site/app/assets/icons/more-3-line-BIiVjYTz.js +0 -1
  220. package/web/app/site/app/assets/icons/notification-line-BZZq2Gtu.js +0 -1
  221. package/web/app/site/app/assets/icons/pencil-line-CKh8-A1v.js +0 -1
  222. package/web/app/site/app/assets/icons/photo-album-line-Bnfg2u40.js +0 -1
  223. package/web/app/site/app/assets/icons/pin-line-DpTolyhs.js +0 -1
  224. package/web/app/site/app/assets/icons/play-fill-B0-G_8lX.js +0 -1
  225. package/web/app/site/app/assets/icons/qrcode-2-line-B6SPCaHn.js +0 -1
  226. package/web/app/site/app/assets/icons/quill-pen-line-B6LUrnCP.js +0 -1
  227. package/web/app/site/app/assets/icons/quote-left-fill-hQZ1cj_6.js +0 -1
  228. package/web/app/site/app/assets/icons/radar-line-CKyroTth.js +0 -1
  229. package/web/app/site/app/assets/icons/react-line-CoIKhhtK.js +0 -1
  230. package/web/app/site/app/assets/icons/refresh-2-line-D0mTF97S.js +0 -1
  231. package/web/app/site/app/assets/icons/right-line-B3KWJaqc.js +0 -1
  232. package/web/app/site/app/assets/icons/rocket-line-4KZl537D.js +0 -1
  233. package/web/app/site/app/assets/icons/round-fill-C69NTrZ0.js +0 -1
  234. package/web/app/site/app/assets/icons/round-line-B9k_1uo-.js +0 -1
  235. package/web/app/site/app/assets/icons/route-line-B28ReHcE.js +0 -1
  236. package/web/app/site/app/assets/icons/rows-4-line-CrBniagM.js +0 -1
  237. package/web/app/site/app/assets/icons/scan-line-DSf74YdP.js +0 -1
  238. package/web/app/site/app/assets/icons/search-2-line-B6geIU1z.js +0 -1
  239. package/web/app/site/app/assets/icons/settings-3-line-azJwK47w.js +0 -1
  240. package/web/app/site/app/assets/icons/settings-6-line-C_5zc5YR.js +0 -1
  241. package/web/app/site/app/assets/icons/share-2-line-D5MxWjrm.js +0 -1
  242. package/web/app/site/app/assets/icons/share-forward-line-Cp61fZzZ.js +0 -1
  243. package/web/app/site/app/assets/icons/sparkles-2-line-DYYyXTaW.js +0 -1
  244. package/web/app/site/app/assets/icons/sparkles-line-C2hY1s6I.js +0 -1
  245. package/web/app/site/app/assets/icons/time-line-BF3eet1v.js +0 -1
  246. package/web/app/site/app/assets/icons/transfer-4-line-oisfvTBw.js +0 -1
  247. package/web/app/site/app/assets/icons/translate-line-BFWol2Ce.js +0 -1
  248. package/web/app/site/app/assets/icons/unlock-line-X_x5vwv3.js +0 -1
  249. package/web/app/site/app/assets/icons/upload-3-line-DgzwUJeW.js +0 -1
  250. package/web/app/site/app/assets/icons/user-4-line-BVSynZCp.js +0 -1
  251. package/web/app/site/app/assets/icons/user-add-2-line-BlGS5Q8q.js +0 -1
  252. package/web/app/site/app/assets/icons/user-add-line-BbXdHG4z.js +0 -1
  253. package/web/app/site/app/assets/icons/user-edit-line-BFAHOV0X.js +0 -1
  254. package/web/app/site/app/assets/icons/user-follow-line-BXux0wSd.js +0 -1
  255. package/web/app/site/app/assets/icons/user-star-line-DdYlpHLU.js +0 -1
  256. package/web/app/site/app/assets/icons/user-warning-line-Cj43j0_E.js +0 -1
  257. package/web/app/site/app/assets/icons/user-x-line-DIDgNlPH.js +0 -1
  258. package/web/app/site/app/assets/icons/volume-line-Bs390KQt.js +0 -1
  259. package/web/app/site/app/assets/icons/volume-mute-line-DzlzIqFZ.js +0 -1
  260. package/web/app/site/app/assets/icons/walk-line-yNXfB-md.js +0 -1
  261. package/web/app/site/app/assets/icons/world-2-line-CenkGIwj.js +0 -1
  262. package/web/app/site/app/assets/icons/zoom-in-line-CaENUphf.js +0 -1
  263. package/web/app/site/app/assets/icons/zoom-out-line-BDNk0EWo.js +0 -1
  264. package/web/app/site/app/assets/instances-BNPptnn-.json +0 -333
  265. package/web/app/site/app/assets/locales/ar-SA-CfheRbCu.js +0 -1
  266. package/web/app/site/app/assets/locales/ca-ES-DHRW86Tz.js +0 -1
  267. package/web/app/site/app/assets/locales/cs-CZ-CKoqEuA1.js +0 -1
  268. package/web/app/site/app/assets/locales/de-DE-ByRPMRFy.js +0 -1
  269. package/web/app/site/app/assets/locales/eo-UY-CPC7wLCS.js +0 -1
  270. package/web/app/site/app/assets/locales/es-ES-dJa0Fd9t.js +0 -1
  271. package/web/app/site/app/assets/locales/eu-ES-C3djlPR2.js +0 -1
  272. package/web/app/site/app/assets/locales/fa-IR-DTT490Ck.js +0 -1
  273. package/web/app/site/app/assets/locales/fi-FI-B23MCPuz.js +0 -1
  274. package/web/app/site/app/assets/locales/fr-FR-BcaQsO5C.js +0 -1
  275. package/web/app/site/app/assets/locales/gl-ES-BR-CVKBN.js +0 -1
  276. package/web/app/site/app/assets/locales/he-IL-CfheRbCu.js +0 -1
  277. package/web/app/site/app/assets/locales/hu-HU-CfheRbCu.js +0 -1
  278. package/web/app/site/app/assets/locales/it-IT-C1136UFV.js +0 -1
  279. package/web/app/site/app/assets/locales/ja-JP-CRZmRAhD.js +0 -1
  280. package/web/app/site/app/assets/locales/kab-Cz8xH_TT.js +0 -1
  281. package/web/app/site/app/assets/locales/ko-KR-CG9UiY4o.js +0 -1
  282. package/web/app/site/app/assets/locales/lt-LT-CJcI6sHZ.js +0 -1
  283. package/web/app/site/app/assets/locales/nb-NO-CfheRbCu.js +0 -1
  284. package/web/app/site/app/assets/locales/nl-NL-DxN4Yc1t.js +0 -1
  285. package/web/app/site/app/assets/locales/oc-FR-CfheRbCu.js +0 -1
  286. package/web/app/site/app/assets/locales/pl-PL-DkwGXf6P.js +0 -1
  287. package/web/app/site/app/assets/locales/pseudo-LOCALE-CQ4XxkQ0.js +0 -1
  288. package/web/app/site/app/assets/locales/pt-BR-nGL0HdFS.js +0 -1
  289. package/web/app/site/app/assets/locales/pt-PT-Cp17aj2z.js +0 -1
  290. package/web/app/site/app/assets/locales/ru-RU-0Y8cIoaK.js +0 -1
  291. package/web/app/site/app/assets/locales/th-TH-CfheRbCu.js +0 -1
  292. package/web/app/site/app/assets/locales/tok-CfheRbCu.js +0 -1
  293. package/web/app/site/app/assets/locales/tr-TR-CfheRbCu.js +0 -1
  294. package/web/app/site/app/assets/locales/uk-UA-C5E3dFBf.js +0 -1
  295. package/web/app/site/app/assets/locales/zh-CN-BHJi7_et.js +0 -1
  296. package/web/app/site/app/assets/locales/zh-TW-CfheRbCu.js +0 -1
  297. package/web/app/site/app/assets/main-BdqNbG-a.js +0 -26
  298. package/web/app/site/app/assets/main-BdqNbG-a.js.map +0 -1
  299. package/web/app/site/app/assets/mock-home-DGhR__He.js +0 -2
  300. package/web/app/site/app/assets/mock-home-DGhR__He.js.map +0 -1
  301. package/web/app/site/app/assets/multi-column-ROck0NVt.jpg +0 -0
  302. package/web/app/site/app/assets/multi-hashtag-timeline-DH5INVHi.jpg +0 -0
  303. package/web/app/site/app/assets/nested-comments-thread-hv59kZLc.jpg +0 -0
  304. package/web/app/site/app/assets/polyfill-force-H8sUkLGp.js +0 -2
  305. package/web/app/site/app/assets/polyfill-force-H8sUkLGp.js.map +0 -1
  306. package/web/app/site/app/assets/pwa-viewport-ogKbF51K.js +0 -20
  307. package/web/app/site/app/assets/pwa-viewport-ogKbF51K.js.map +0 -1
  308. package/web/app/site/app/assets/style-B1iLPTPR.css +0 -2
  309. package/web/app/site/app/assets/temml-DuyIQMei.js +0 -97
  310. package/web/app/site/app/assets/temml-DuyIQMei.js.map +0 -1
  311. package/web/app/site/app/assets/tinyld.light.node-DtbBhLYC.js +0 -2
  312. package/web/app/site/app/assets/tinyld.light.node-DtbBhLYC.js.map +0 -1
  313. package/web/app/site/app/assets/year-in-posts-B2lywqdx.png +0 -0
  314. package/web/app/site/app/assets/year-in-posts-DJv_star.js +0 -3
  315. package/web/app/site/app/assets/year-in-posts-DJv_star.js.map +0 -1
  316. package/web/app/site/app/compose/index.html +0 -20
  317. package/web/app/site/app/favicon.ico +0 -0
  318. package/web/app/site/app/index.html +0 -73
  319. package/web/app/site/app/logo-192.png +0 -0
  320. package/web/app/site/app/logo-512.png +0 -0
  321. package/web/app/site/app/logo-badge-72.png +0 -0
  322. package/web/app/site/app/logo-maskable-512.png +0 -0
  323. package/web/app/site/app/logo-monochrome-512.png +0 -0
  324. package/web/app/site/app/logo-monochrome-maskable-512.png +0 -0
  325. package/web/app/site/app/manifest.webmanifest +0 -1
  326. package/web/app/site/app/og-image-2.jpg +0 -0
  327. package/web/app/site/app/og-image.png +0 -0
  328. package/web/app/site/app/robots.txt +0 -2
  329. package/web/app/site/app/version.json +0 -1
  330. package/web/app/site/boot.js +0 -34277
  331. package/web/app/site/index.html +0 -251
  332. package/web/app/site/sw.js +0 -71331
@@ -0,0 +1,346 @@
1
+ // fedi-account.mjs — type a Fediverse handle or a WebID, and get back an
2
+ // account you can act with: post, read its timeline, follow, reply,
3
+ // favourite, boost. The library works out whether the account lives on a
4
+ // Mastodon-family server or on a Solid pod through FediPod, and speaks to
5
+ // whichever it is. The app never has to know which it got.
6
+ //
7
+ // import { fediAccount } from './fedi-account.mjs';
8
+ // const accounts = fediAccount({ dbName: 'my-app', clientName: 'My app' });
9
+ //
10
+ // await accounts.resume(); // on every page load
11
+ // await accounts.login('@kwame@mastodon.social'); // or '@mei@fedipod.net', or a WebID
12
+ // const me = await accounts.current(); // null, or the account below
13
+ //
14
+ // me.handle, me.kind ('mastodon' | 'pod'), me.notice (a sentence to show, or null)
15
+ // await me.post({ text }); await me.timeline({ limit: 20 })
16
+ // await me.reply(postUrlOrId, text); await me.follow('@aisha@her.server')
17
+ // await me.favourite(postUrlOrId); await me.boost(postUrlOrId)
18
+ // await me.signOut()
19
+ //
20
+ // A Mastodon account is used through its server's API with a token the
21
+ // person granted this app; the token stays in this browser. A pod account
22
+ // is used through its FediPod outbox door with the person's pod sign-in:
23
+ // what is posted there is carried out by the account's own agent. When that
24
+ // agent is a browser at fedipod.net, the account carries a notice saying so.
25
+ //
26
+ // No imports but the two files beside it, no Node built-ins, nothing named
27
+ // after the application that uses it.
28
+ import { fediLogin, parseAddress } from './fedi-login.mjs';
29
+
30
+ const AS = 'https://www.w3.org/ns/activitystreams';
31
+ const PUBLIC = `${AS}#Public`;
32
+ const AS_OUTBOX = `${AS}#outbox`;
33
+ const FOAF_ACCOUNT = 'http://xmlns.com/foaf/0.1/account';
34
+ const DEFAULT_SCOPES = 'read write follow';
35
+ const PENDING_TTL_MS = 10 * 60_000;
36
+
37
+ export const BROWSER_ACCOUNT_NOTICE = 'Because you have a browser-based account, your posts and interactions will only go out to the Fediverse when your browser is opened to your account.';
38
+
39
+ const esc = (s) => String(s).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
40
+ const toHtml = (text) => `<p>${esc(text).replace(/\r?\n/g, '<br>')}</p>`;
41
+ const memoryStorage = () => { const m = new Map(); return { getItem: (k) => (m.has(k) ? m.get(k) : null), setItem: (k, v) => m.set(k, String(v)), removeItem: (k) => m.delete(k) }; };
42
+
43
+ export function fediAccount({
44
+ dbName = 'fediverse-account', clientName = 'Fediverse app', redirectUri = null, scopes = DEFAULT_SCOPES,
45
+ website = null, fetch: f = globalThis.fetch?.bind(globalThis), storage = globalThis.localStorage || memoryStorage(),
46
+ } = {}) {
47
+ const pod = fediLogin({ dbName, clientName, redirectUri, fetch: f });
48
+ const here = () => (globalThis.location ? location.origin + location.pathname : null);
49
+ const key = (k) => `${dbName}:${k}`;
50
+ const read = (k) => { try { return JSON.parse(storage.getItem(key(k)) || 'null'); } catch { return null; } };
51
+ const write = (k, v) => storage.setItem(key(k), JSON.stringify(v));
52
+ const drop = (k) => storage.removeItem(key(k));
53
+ const json = (url, init = {}) => f(url, { ...init, headers: { accept: 'application/json', ...(init.headers || {}) } })
54
+ .then((r) => (r.ok ? r.json() : null)).catch(() => null);
55
+ const said = async (res, host) => {
56
+ const body = await res.json().catch(() => ({}));
57
+ if (!res.ok) throw new Error(body.error_description || body.error || `${host} answered ${res.status}`);
58
+ return body;
59
+ };
60
+
61
+ // ---- finding out what an address is ----
62
+
63
+ // Does this host speak the Mastodon API? Any server of that family says so
64
+ // here; a pod, a Gateway and a plain web host do not.
65
+ const speaksMastodon = async (host) => {
66
+ const inst = await json(`https://${host}/api/v1/instance`);
67
+ return !!(inst && (inst.uri || inst.domain || inst.title));
68
+ };
69
+
70
+ const webfinger = async (name, host) => {
71
+ const jrd = await json(`https://${host}/.well-known/webfinger?resource=${encodeURIComponent(`acct:${name}@${host}`)}`,
72
+ { headers: { accept: 'application/jrd+json, application/json' } });
73
+ if (!jrd) throw new Error(`${host} does not know @${name}@${host}`);
74
+ const self = (jrd.links || []).find((l) => l.rel === 'self' && /activity\+json|ld\+json/u.test(l.type || ''));
75
+ return { actor: self?.href || null, aliases: (jrd.aliases || []).filter((u) => typeof u === 'string') };
76
+ };
77
+
78
+ // Where a pod account keeps its records: the actor on the pod itself is
79
+ // `<root>ap/actor`, and the aliases name it even when the address is at a
80
+ // Gateway.
81
+ const rootOf = (actor, aliases) => {
82
+ const onPod = [...aliases, actor].find((u) => typeof u === 'string' && /\/ap\/actor$/u.test(u) && (!actor || new URL(u).origin !== new URL(actor).origin))
83
+ || [...aliases, actor].find((u) => typeof u === 'string' && /\/ap\/actor$/u.test(u));
84
+ return onPod ? onPod.replace(/ap\/actor$/u, '') : null;
85
+ };
86
+
87
+ /** What an address is, without signing in: { kind: 'mastodon' | 'pod', host, handle, actor, … }. */
88
+ async function describe(address) {
89
+ const a = parseAddress(address);
90
+ if (!a) throw new Error('an address looks like @you@your.server, or is your WebID');
91
+ if (a.url) {
92
+ // A WebID: the account it names leads to the handle, and the handle to
93
+ // everything else.
94
+ const card = await json(a.url, { headers: { accept: 'application/ld+json' } });
95
+ const nodes = Array.isArray(card) ? card : (card?.['@graph'] || (card ? [card] : []));
96
+ const me = nodes.find((n) => n?.['@id'] === a.url) || {};
97
+ const actorId = [].concat(me[FOAF_ACCOUNT] || []).map((v) => v?.['@id'] || v).find((v) => typeof v === 'string');
98
+ if (!actorId) throw new Error(`${a.host} names no Fediverse account on that WebID`);
99
+ const actor = await json(actorId, { headers: { accept: 'application/activity+json' } });
100
+ if (!actor?.preferredUsername) throw new Error(`the account ${actorId} could not be read`);
101
+ return describe(`@${actor.preferredUsername}@${new URL(actorId).host}`);
102
+ }
103
+ const { actor, aliases } = await webfinger(a.name, a.host);
104
+ const actorHost = actor ? new URL(actor).host : a.host;
105
+ for (const host of [...new Set([actorHost, a.host])]) {
106
+ if (await speaksMastodon(host)) return { kind: 'mastodon', host, handle: a.at, actor };
107
+ }
108
+ const where = await pod.resolve(a.at);
109
+ return { kind: 'pod', host: a.host, handle: a.at, actor: actor || where.actor, issuer: where.issuer, root: rootOf(actor || where.actor, aliases) };
110
+ }
111
+
112
+ // ---- signing in ----
113
+
114
+ const appFor = async (host, ru) => {
115
+ const apps = read('masto:apps') || {};
116
+ const known = apps[host];
117
+ if (known?.redirectUri === ru && known.clientId) return known;
118
+ const res = await f(`https://${host}/api/v1/apps`, {
119
+ method: 'POST', headers: { 'content-type': 'application/json' },
120
+ body: JSON.stringify({ client_name: clientName, redirect_uris: ru, scopes, ...(website ? { website } : {}) }),
121
+ });
122
+ const body = await said(res, host);
123
+ if (!body.client_id) throw new Error(`${host} registered no client`);
124
+ const app = { host, redirectUri: ru, clientId: body.client_id, clientSecret: body.client_secret || null };
125
+ write('masto:apps', { ...apps, [host]: app });
126
+ return app;
127
+ };
128
+
129
+ /** Everything `login` does short of leaving the page: what the address is and the page to send the person to. */
130
+ async function startLogin(address, { returnTo = globalThis.location?.href || null, redirectUri: ru = redirectUri || here() } = {}) {
131
+ const what = await describe(address);
132
+ if (what.kind === 'pod') {
133
+ const s = await pod.startLogin(what.handle, { returnTo, redirectUri: ru });
134
+ write('pod:pending', { handle: what.handle, actor: what.actor, root: what.root, at: Date.now() });
135
+ return { ...what, authorizationUrl: s.authorizationUrl, returnTo };
136
+ }
137
+ const app = await appFor(what.host, ru);
138
+ const bytes = crypto.getRandomValues(new Uint8Array(24));
139
+ const state = [...bytes].map((b) => b.toString(16).padStart(2, '0')).join('');
140
+ write('masto:pending', { state, host: what.host, redirectUri: ru, returnTo, at: Date.now() });
141
+ const u = new URL(`https://${what.host}/oauth/authorize`);
142
+ for (const [k, v] of Object.entries({ client_id: app.clientId, redirect_uri: ru, response_type: 'code', scope: scopes, state })) u.searchParams.set(k, v);
143
+ return { ...what, authorizationUrl: u.href, returnTo };
144
+ }
145
+
146
+ /** Send the person to wherever this account signs in. They come back to this
147
+ * page (unless `redirectUri` says otherwise) and `resume` returns them to
148
+ * where they were (unless `returnTo` says otherwise). */
149
+ async function login(address, opts) {
150
+ const s = await startLogin(address, opts);
151
+ location.href = s.authorizationUrl;
152
+ return s;
153
+ }
154
+
155
+ /** Call on every page load. Finishes a sign-in the person is coming back
156
+ * from, of either kind, and returns them to where they were. Returns the
157
+ * account, or null when nobody is coming back. */
158
+ async function resume({ currentUrl = globalThis.location?.href, go = (u) => location.replace(u) } = {}) {
159
+ const u = new URL(currentUrl);
160
+ const code = u.searchParams.get('code'); const state = u.searchParams.get('state');
161
+ const pend = read('masto:pending');
162
+ if (code && state && pend?.state === state) {
163
+ drop('masto:pending');
164
+ if (Date.now() - pend.at > PENDING_TTL_MS) throw new Error('that sign-in has expired — start again');
165
+ const app = await appFor(pend.host, pend.redirectUri);
166
+ const tok = await said(await f(`https://${pend.host}/oauth/token`, {
167
+ method: 'POST', headers: { 'content-type': 'application/json' },
168
+ body: JSON.stringify({ grant_type: 'authorization_code', code, redirect_uri: pend.redirectUri, client_id: app.clientId, ...(app.clientSecret ? { client_secret: app.clientSecret } : {}), scope: scopes }),
169
+ }), pend.host);
170
+ if (!tok.access_token) throw new Error(`${pend.host} returned no token`);
171
+ const me = await said(await f(`https://${pend.host}/api/v1/accounts/verify_credentials`, { headers: { authorization: `Bearer ${tok.access_token}` } }), pend.host);
172
+ write('masto:account', { host: pend.host, token: tok.access_token, handle: `@${me.username}@${pend.host}`, name: me.display_name || me.username, actor: me.url || me.uri || null });
173
+ drop('pod:facts');
174
+ if (pend.returnTo && pend.returnTo !== currentUrl) go(pend.returnTo);
175
+ return current();
176
+ }
177
+ const session = await pod.resume({ currentUrl, go: () => {} });
178
+ if (!session) return null;
179
+ const p = read('pod:pending') || {};
180
+ drop('pod:pending');
181
+ const facts = await podFacts(session, p);
182
+ write('pod:facts', facts);
183
+ drop('masto:account');
184
+ if (session.returnTo && session.returnTo !== currentUrl) go(session.returnTo);
185
+ return current();
186
+ }
187
+
188
+ // What a pod account needs, found once at sign-in: its door, its records,
189
+ // its followers collection, and whether its agent is a browser.
190
+ const podFacts = async (session, p) => {
191
+ const card = await json(session.webId, { headers: { accept: 'application/ld+json' } });
192
+ const nodes = Array.isArray(card) ? card : (card?.['@graph'] || (card ? [card] : []));
193
+ const me = nodes.find((n) => n?.['@id'] === session.webId) || {};
194
+ const pick = (node, k) => [].concat(node?.[k] || []).map((v) => v?.['@id'] || v).find((v) => typeof v === 'string') || null;
195
+ let actor = p.actor || pick(me, FOAF_ACCOUNT);
196
+ let door = pick(me, AS_OUTBOX);
197
+ const doc = actor ? await json(actor, { headers: { accept: 'application/activity+json' } }) : null;
198
+ if (!door && doc?.outbox) door = doc.outbox;
199
+ let root = p.root || null;
200
+ if (!root && doc?.preferredUsername && actor) {
201
+ const { aliases } = await webfinger(doc.preferredUsername, new URL(actor).host).catch(() => ({ aliases: [] }));
202
+ root = rootOf(actor, aliases);
203
+ }
204
+ const handle = p.handle || (doc?.preferredUsername && actor ? `@${doc.preferredUsername}@${new URL(actor).host}` : null);
205
+ // A browser-made account keeps its signing key on the pod sealed under
206
+ // the password; a device keeps its key with itself. The shape says which.
207
+ let browserBased = false;
208
+ if (root) {
209
+ const keys = await session.fetch(`${root}ap-state/keys.json`, { headers: { accept: 'application/json' } }).then((r) => (r.ok ? r.json() : null)).catch(() => null);
210
+ const envelope = keys && (keys.v === 1 && typeof keys.ct === 'string' && typeof keys.salt === 'string'
211
+ || Object.values(keys).some((k) => k && k.v === 1 && typeof k.ct === 'string' && typeof k.salt === 'string'));
212
+ browserBased = !!envelope;
213
+ }
214
+ return { handle, actor, name: doc?.name || null, door, root, followers: doc?.followers || null, webId: session.webId, browserBased };
215
+ };
216
+
217
+ // ---- the account ----
218
+
219
+ const mastodonAccount = (a) => {
220
+ const base = `https://${a.host}`;
221
+ const auth = { authorization: `Bearer ${a.token}` };
222
+ const call = (path, init = {}) => f(`${base}${path}`, { ...init, headers: { ...auth, ...(init.headers || {}) } });
223
+ const post = (path, body) => call(path, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body || {}) }).then((r) => said(r, a.host));
224
+ // A post named by its address is found on this server by a search that
225
+ // fetches it if need be; one named by an id here is used as it is.
226
+ const idOf = async (target) => {
227
+ if (!/^https?:\/\//u.test(String(target))) return String(target);
228
+ const u = new URL(`${base}/api/v2/search`);
229
+ u.searchParams.set('q', target); u.searchParams.set('resolve', 'true'); u.searchParams.set('type', 'statuses'); u.searchParams.set('limit', '1');
230
+ const body = await call(u.href).then((r) => said(r, a.host));
231
+ const id = body.statuses?.[0]?.id;
232
+ if (!id) throw new Error(`${a.host} could not find that post`);
233
+ return id;
234
+ };
235
+ const item = (s) => ({
236
+ id: s.id, url: s.url || s.uri || null, published: s.created_at,
237
+ author: { id: s.account?.url || null, handle: s.account?.acct ? `@${s.account.acct}${s.account.acct.includes('@') ? '' : '@' + a.host}` : null, name: s.account?.display_name || s.account?.username || null },
238
+ html: s.content || '', inReplyTo: s.in_reply_to_id || null,
239
+ ...(s.reblog ? { boostOf: item(s.reblog) } : {}),
240
+ });
241
+ return {
242
+ kind: 'mastodon', handle: a.handle, name: a.name, actor: a.actor, notice: null,
243
+ fetch: call,
244
+ async profile() {
245
+ const me = await call('/api/v1/accounts/verify_credentials').then((r) => said(r, a.host));
246
+ return { handle: a.handle, name: me.display_name || me.username || null, url: me.url || null, avatar: me.avatar || null, bio: me.note || '',
247
+ followers: me.followers_count ?? null, following: me.following_count ?? null, posts: me.statuses_count ?? null, actor: a.actor, webId: null };
248
+ },
249
+ async post({ text, inReplyTo = null, visibility = 'public' }) {
250
+ const made = await post('/api/v1/statuses', { status: text, visibility, ...(inReplyTo ? { in_reply_to_id: await idOf(inReplyTo) } : {}) });
251
+ return { id: made.id, url: made.url || made.uri || null, sent: true };
252
+ },
253
+ reply(target, text) { return this.post({ text, inReplyTo: target }); },
254
+ async timeline({ limit = 20 } = {}) {
255
+ const list = await call(`/api/v1/timelines/home?limit=${Math.min(40, limit)}`).then((r) => said(r, a.host));
256
+ return (Array.isArray(list) ? list : []).map(item);
257
+ },
258
+ async follow(handle) {
259
+ const who = parseAddress(handle);
260
+ if (!who?.at) throw new Error('a handle looks like @you@your.server');
261
+ const acct = await call(`/api/v1/accounts/lookup?acct=${encodeURIComponent(who.at.slice(1))}`).then((r) => said(r, a.host));
262
+ if (!acct.id) throw new Error(`${a.host} could not find ${who.at}`);
263
+ await post(`/api/v1/accounts/${acct.id}/follow`);
264
+ return { followed: who.at, sent: true };
265
+ },
266
+ async favourite(target) { await post(`/api/v1/statuses/${await idOf(target)}/favourite`); return { sent: true }; },
267
+ async boost(target) { await post(`/api/v1/statuses/${await idOf(target)}/reblog`); return { sent: true }; },
268
+ async signOut() {
269
+ const apps = read('masto:apps') || {};
270
+ const app = apps[a.host];
271
+ if (app) {
272
+ try { await f(`${base}/oauth/revoke`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ client_id: app.clientId, client_secret: app.clientSecret, token: a.token }) }); } catch { /* told if we could */ }
273
+ }
274
+ drop('masto:account');
275
+ },
276
+ };
277
+ };
278
+
279
+ const podAccount = (session, facts) => {
280
+ const knock = async (activity) => {
281
+ if (!facts.door) throw new Error('this account names no outbox to post through');
282
+ const res = await session.fetch(facts.door, { method: 'POST', headers: { 'content-type': 'application/activity+json' }, body: JSON.stringify({ '@context': AS, ...activity }) });
283
+ if (!res.ok) { const body = await res.text().catch(() => ''); throw new Error(`the outbox refused it (HTTP ${res.status})${body ? `: ${body.slice(0, 200)}` : ''}`); }
284
+ return { id: res.headers.get('location') || null, sent: res.status === 201, queued: res.status === 202 };
285
+ };
286
+ const audience = (visibility) => {
287
+ if (visibility === 'unlisted') return { to: facts.followers ? [facts.followers] : [], cc: [PUBLIC] };
288
+ if (visibility === 'private' || visibility === 'followers') return { to: facts.followers ? [facts.followers] : [], cc: [] };
289
+ return { to: [PUBLIC], cc: facts.followers ? [facts.followers] : [] };
290
+ };
291
+ const state = (name) => (facts.root ? session.fetch(`${facts.root}ap-state/${name}`, { headers: { accept: 'application/json' } }).then((r) => (r.ok ? r.json() : null)).catch(() => null) : Promise.resolve(null));
292
+ return {
293
+ kind: 'pod', handle: facts.handle, name: facts.name, actor: facts.actor, webId: facts.webId,
294
+ notice: facts.browserBased ? BROWSER_ACCOUNT_NOTICE : null,
295
+ fetch: session.fetch,
296
+ async profile() {
297
+ const doc = facts.actor ? await json(facts.actor, { headers: { accept: 'application/activity+json' } }) : null;
298
+ const count = async (url) => (url ? (await json(url, { headers: { accept: 'application/activity+json' } }))?.totalItems ?? null : null);
299
+ return { handle: facts.handle, name: doc?.name || null, url: doc?.url || null, avatar: doc?.icon?.url || (typeof doc?.icon === 'string' ? doc.icon : null), bio: doc?.summary || '',
300
+ followers: await count(doc?.followers), following: await count(doc?.following), posts: await count(doc?.outbox), actor: facts.actor, webId: facts.webId };
301
+ },
302
+ async post({ text, inReplyTo = null, visibility = 'public' }) {
303
+ const made = await knock({ type: 'Note', content: toHtml(text), source: { content: text, mediaType: 'text/plain' }, ...(inReplyTo ? { inReplyTo } : {}), ...audience(visibility) });
304
+ return { id: made.id, url: made.id, sent: made.sent, queued: made.queued };
305
+ },
306
+ reply(target, text) { return this.post({ text, inReplyTo: target }); },
307
+ async timeline({ limit = 20 } = {}) {
308
+ const rows = await state('statuses.json');
309
+ const actors = (await state('actors.json')) || {};
310
+ const who = (id) => { const d = actors[id]?.doc || actors[id] || {}; return { id, handle: d.preferredUsername ? `@${d.preferredUsername}@${new URL(id).host}` : null, name: d.name || null }; };
311
+ return (Array.isArray(rows) ? rows : [])
312
+ .filter((s) => s.kind !== 'remote' && s.kind !== 'mention' && !s.direct && s.visibility !== 'direct')
313
+ .sort((x, y) => String(y.published || '').localeCompare(String(x.published || '')))
314
+ .slice(0, limit)
315
+ .map((s) => ({ id: s.noteId, url: s.noteId, published: s.published || null, author: who(s.actor), html: s.content || '', inReplyTo: s.inReplyTo || null }));
316
+ },
317
+ async follow(handle) {
318
+ const who = parseAddress(handle);
319
+ if (!who?.at) throw new Error('a handle looks like @you@your.server');
320
+ const made = await knock({ type: 'Follow', object: who.at });
321
+ return { followed: who.at, sent: made.sent, queued: made.queued };
322
+ },
323
+ async favourite(target) { return knock({ type: 'Like', object: target }); },
324
+ async boost(target) { return knock({ type: 'Announce', object: target, ...audience('public') }); },
325
+ async signOut() { await session.signOut(); drop('pod:facts'); },
326
+ };
327
+ };
328
+
329
+ /** The signed-in account, or null. */
330
+ async function current() {
331
+ const m = read('masto:account');
332
+ if (m) return mastodonAccount(m);
333
+ const session = await pod.getSession();
334
+ if (!session) return null;
335
+ let facts = read('pod:facts');
336
+ if (!facts || facts.webId !== session.webId) { facts = await podFacts(session, {}); write('pod:facts', facts); }
337
+ return podAccount(session, facts);
338
+ }
339
+
340
+ async function signOut() { const me = await current(); if (me) await me.signOut(); }
341
+
342
+ // For a test that hands in a pod session of its own.
343
+ const _podAccount = async (session, pending = {}) => podAccount(session, await podFacts(session, pending));
344
+
345
+ return { describe, startLogin, login, resume, current, signOut, _podAccount };
346
+ }
@@ -0,0 +1,123 @@
1
+ // fedi-login.mjs — sign a person in at their own Solid pod from their
2
+ // Fediverse address, and bring them back to where they were.
3
+ //
4
+ // import { fediLogin } from './fedi-login.mjs';
5
+ // const login = fediLogin({ dbName: 'my-app-oidc', clientName: 'My app' });
6
+ //
7
+ // await login.login('@mei@fedipod.net'); // leaves for the pod's login page
8
+ // await login.resume(); // on every page load: finishes a
9
+ // // login in progress and returns them
10
+ // const s = await login.getSession(); // null, or { webId, issuer, fetch, signOut }
11
+ //
12
+ // How an address becomes a login page. WebFinger at the address's host names
13
+ // the actor and its aliases. An origin among those that answers
14
+ // /.well-known/openid-configuration is the login provider, or says which is
15
+ // (a pod host redirects there). Failing that, the WebID — the URL typed, or
16
+ // the ones the actor names as its own — is read as JSON-LD and its
17
+ // solid:oidcIssuer is the provider. A Mastodon address has neither, and the
18
+ // person is told so in words.
19
+ //
20
+ // No imports but the session engine beside it, no Node built-ins, nothing
21
+ // named after the application that uses it.
22
+ import { solidOidcSession } from './oidc-session.mjs';
23
+
24
+ const OIDC_ISSUER = 'http://www.w3.org/ns/solid/terms#oidcIssuer';
25
+
26
+ /** `@mei@host`, `mei@host`, or a WebID or actor URL. Null when it is neither. */
27
+ export function parseAddress(input) {
28
+ const t = String(input || '').trim();
29
+ if (/^https?:\/\//u.test(t)) { try { return { url: new URL(t).href, host: new URL(t).host }; } catch { return null; } }
30
+ const m = /^@?([^@\s/]+)@([^@\s/]+)$/u.exec(t);
31
+ if (!m) return null;
32
+ const name = m[1]; const host = m[2].toLowerCase();
33
+ return { name, host, at: `@${name}@${host}` };
34
+ }
35
+
36
+ export function fediLogin({ dbName, clientName, redirectUri = null, fetch: f = globalThis.fetch?.bind(globalThis) } = {}) {
37
+ const oidc = solidOidcSession({ dbName, clientName });
38
+ const get = (url, accept) => f(url, { headers: { accept }, redirect: 'follow' });
39
+ const json = (url, accept) => get(url, accept).then((r) => (r.ok ? r.json() : null)).catch(() => null);
40
+ const here = () => (globalThis.location ? location.origin + location.pathname : null);
41
+
42
+ const discovery = (base) => json(`${String(base).replace(/\/+$/, '')}/.well-known/openid-configuration`, 'application/json');
43
+ const isProvider = (cfg) => !!(cfg?.issuer && cfg.authorization_endpoint);
44
+ const origin = (u) => { try { return new URL(u).origin; } catch { return null; } };
45
+
46
+ // The issuer a WebID document names, read as the expanded JSON-LD a pod answers.
47
+ const issuerOfWebId = async (webId) => {
48
+ const doc = await json(webId, 'application/ld+json');
49
+ const nodes = Array.isArray(doc) ? doc : (doc?.['@graph'] || (doc ? [doc] : []));
50
+ const me = nodes.find((n) => n?.['@id'] === webId && n[OIDC_ISSUER]) || nodes.find((n) => n?.[OIDC_ISSUER]);
51
+ const v = [].concat(me?.[OIDC_ISSUER] || [])[0];
52
+ return typeof v === 'string' ? v : (v?.['@id'] || null);
53
+ };
54
+
55
+ /** Where an address signs in: { address, actor, origin, issuer, webId? }.
56
+ * Throws, in plain words, when the host does not know the address or
57
+ * nothing about it names a login provider. */
58
+ async function resolve(address) {
59
+ const a = parseAddress(address);
60
+ if (!a) throw new Error('an address looks like @you@your.server');
61
+ let actor = null;
62
+ const urls = [];
63
+ if (a.url) urls.push(a.url);
64
+ else {
65
+ const r = await get(`https://${a.host}/.well-known/webfinger?resource=${encodeURIComponent(`acct:${a.name}@${a.host}`)}`,
66
+ 'application/jrd+json, application/json').catch(() => null);
67
+ if (!r?.ok) throw new Error(`${a.host} does not know ${a.at}`);
68
+ const jrd = await r.json().catch(() => null);
69
+ const self = (jrd?.links || []).find((l) => l.rel === 'self' && /activity\+json|ld\+json/u.test(l.type || ''));
70
+ actor = self?.href || null;
71
+ // The aliases first: at a Gateway they name the actor on the pod itself,
72
+ // and the pod is where the login is.
73
+ for (const u of [...(jrd?.aliases || []), ...(actor ? [actor] : [])]) if (typeof u === 'string') urls.push(u);
74
+ if (!urls.length) throw new Error(`${a.host} did not say where ${a.at} lives`);
75
+ }
76
+ const found = (extra) => ({ address: a.at || a.url, actor, ...extra });
77
+
78
+ // 1. An origin that is the login provider, or says which is.
79
+ for (const o of [...new Set(urls.map(origin).filter(Boolean))]) {
80
+ const cfg = await discovery(o);
81
+ if (isProvider(cfg)) return found({ origin: o, issuer: cfg.issuer });
82
+ }
83
+ // 2. The WebID: the URL typed, or the ones the actor names as its own.
84
+ const webIds = a.url ? [a.url] : [];
85
+ if (actor) {
86
+ const doc = await json(actor, 'application/activity+json');
87
+ for (const u of [].concat(doc?.alsoKnownAs || [])) if (typeof u === 'string') webIds.push(u);
88
+ }
89
+ for (const webId of webIds) {
90
+ const issuer = await issuerOfWebId(webId);
91
+ if (issuer && isProvider(await discovery(issuer))) return found({ origin: origin(webId), issuer, webId });
92
+ }
93
+ throw new Error(`${a.host} is not a Solid pod, so there is no pod login to send you to`);
94
+ }
95
+
96
+ /** Everything `login` does short of leaving the page: returns the found pod
97
+ * and the `authorizationUrl` to send the person to. */
98
+ async function startLogin(address, { returnTo = globalThis.location?.href || null, redirectUri: ru = redirectUri || here() } = {}) {
99
+ const found = await resolve(address);
100
+ const { authorizationUrl } = await oidc.beginLogin({ issuer: found.issuer, redirectUri: ru, returnTo });
101
+ return { ...found, authorizationUrl, returnTo };
102
+ }
103
+
104
+ /** Send the person to their pod's login page. They come back to `redirectUri`
105
+ * (this page, unless set) and `resume` there returns them to `returnTo`
106
+ * (where they were, unless set). */
107
+ async function login(address, opts) {
108
+ const s = await startLogin(address, opts);
109
+ location.href = s.authorizationUrl;
110
+ return s;
111
+ }
112
+
113
+ /** Call on every page load. Finishes a login the person is coming back from
114
+ * and returns them to where they were; null when no login is in progress. */
115
+ async function resume({ currentUrl = globalThis.location?.href, go = (u) => location.replace(u) } = {}) {
116
+ const session = await oidc.completeLogin({ currentUrl });
117
+ if (!session) return null;
118
+ if (session.returnTo && session.returnTo !== currentUrl) go(session.returnTo);
119
+ return session;
120
+ }
121
+
122
+ return { resolve, startLogin, login, resume, getSession: oidc.getSession, signOut: oidc.signOut };
123
+ }