@mx-space/cli 0.15.0 → 0.15.1
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.
- package/README.md +1 -1
- package/dist/{Lexical.dev-Cck4n26y.mjs → Lexical.dev-BSvx45_E.mjs} +127 -94
- package/dist/{Lexical.node-D6wf2D5M.mjs → Lexical.node-kAh5GM2n.mjs} +1 -1
- package/dist/{Lexical.prod-DCwS1oTq.mjs → Lexical.prod-Bqwgb3ez.mjs} +4 -2
- package/dist/{LexicalClipboard.dev-CMkPHV7O.mjs → LexicalClipboard.dev-BWU3KXIa.mjs} +18 -14
- package/dist/{LexicalClipboard.node-m4nZ7IYw.mjs → LexicalClipboard.node-BygAdNdF.mjs} +1 -1
- package/dist/{LexicalClipboard.prod-B_rN1vE1.mjs → LexicalClipboard.prod-BtMuKNyT.mjs} +10 -10
- package/dist/{LexicalCodeCore.dev-DyJw3i8V.mjs → LexicalCodeCore.dev-CD2xgvDs.mjs} +43 -25
- package/dist/{LexicalCodeCore.prod-DPXLHQLF.mjs → LexicalCodeCore.prod-Bl6FFMc7.mjs} +6 -6
- package/dist/{LexicalDragon.dev-ZkNfMwrE.mjs → LexicalDragon.dev-BwdYhm4K.mjs} +2 -2
- package/dist/{LexicalDragon.node-Ds9oLUFh.mjs → LexicalDragon.node-CpJhkCVV.mjs} +1 -1
- package/dist/{LexicalDragon.prod-B58ic2av.mjs → LexicalDragon.prod-CvXmWwo1.mjs} +2 -2
- package/dist/{LexicalExtension.dev-DvwHs1Xv.mjs → LexicalExtension.dev-LcRLXI5Z.mjs} +25 -13
- package/dist/{LexicalExtension.node-5OymZQfy.mjs → LexicalExtension.node-BwJt2LXV.mjs} +1 -1
- package/dist/{LexicalExtension.prod-Ce0T5smQ.mjs → LexicalExtension.prod-lg8_33-H.mjs} +16 -13
- package/dist/{LexicalHeadless.dev-DA0WldSR.mjs → LexicalHeadless.dev-BeUbKBes.mjs} +1 -1
- package/dist/{LexicalHeadless.prod-1kQgKB6c.mjs → LexicalHeadless.prod-4gbIA8HM.mjs} +1 -1
- package/dist/{LexicalHtml.dev-BDB7CUrx.mjs → LexicalHtml.dev-BLdZWTCJ.mjs} +20 -14
- package/dist/{LexicalHtml.node-DpVNt7It.mjs → LexicalHtml.node-BeuJMvvt.mjs} +1 -1
- package/dist/{LexicalHtml.prod-HkxM5scw.mjs → LexicalHtml.prod-CHUyCocN.mjs} +4 -4
- package/dist/{LexicalLink.dev-C5zNJlrm.mjs → LexicalLink.dev-DgsFRqw0.mjs} +28 -21
- package/dist/{LexicalLink.prod-Bkt9hQAt.mjs → LexicalLink.prod-CkXkeKY2.mjs} +6 -5
- package/dist/{LexicalList.dev-B7VgME-m.mjs → LexicalList.dev-OOms3kQi.mjs} +4 -4
- package/dist/{LexicalList.prod-B8c7TDjH.mjs → LexicalList.prod-DzMBeqHn.mjs} +4 -4
- package/dist/{LexicalMarkdown.dev-B5z9kLbV.mjs → LexicalMarkdown.dev-DJLKbZtD.mjs} +40 -29
- package/dist/{LexicalMarkdown.prod-wKzw7FFH.mjs → LexicalMarkdown.prod-Cp21kDCU.mjs} +10 -7
- package/dist/{LexicalRichText.dev-CUd6Li5F.mjs → LexicalRichText.dev-0rkAGjUf.mjs} +15 -11
- package/dist/{LexicalRichText.node-BKfaQ-CH.mjs → LexicalRichText.node-Cd-BySPE.mjs} +4 -4
- package/dist/{LexicalRichText.prod-SBewjJHx.mjs → LexicalRichText.prod-DTQiEr8C.mjs} +17 -11
- package/dist/{LexicalSelection.dev-D27JOCqj.mjs → LexicalSelection.dev-Bi0VlUEv.mjs} +28 -24
- package/dist/{LexicalSelection.node-DBEwPjBu.mjs → LexicalSelection.node-t2U46EF_.mjs} +1 -1
- package/dist/{LexicalSelection.prod-OaYhXHOL.mjs → LexicalSelection.prod-CrFG111g.mjs} +2 -2
- package/dist/{LexicalTable.dev-6IFFOAE0.mjs → LexicalTable.dev-D-sFhO-o.mjs} +33 -28
- package/dist/{LexicalTable.prod-2CaLZ7fH.mjs → LexicalTable.prod-DwYaa_dN.mjs} +10 -9
- package/dist/{LexicalUtils.dev-DJA7J_7v.mjs → LexicalUtils.dev-Q2q3-UDM.mjs} +8 -5
- package/dist/{LexicalUtils.node-Df9oPTlA.mjs → LexicalUtils.node-Dl7OvqJV.mjs} +1 -1
- package/dist/{LexicalUtils.prod-Bb7V4Ewg.mjs → LexicalUtils.prod-CBnq_iEV.mjs} +7 -6
- package/dist/bin/mxs.mjs +1 -1
- package/dist/esm-CNZ7kdTg.mjs +2 -0
- package/dist/{esm-DLzrv7gD.mjs → esm-ZXjJmLEC.mjs} +257 -260
- package/dist/index.mjs +1 -1
- package/dist/{mxs-BIRW5Axj.mjs → mxs-DC9zR3f2.mjs} +759 -539
- package/dist/{rolldown-runtime-JspESFgx.mjs → rolldown-runtime-B4iAMlE-.mjs} +1 -1
- package/dist/src/bin/mxs.d.ts +2 -0
- package/dist/src/bin/mxs.js +310 -0
- package/dist/src/cli/ai/_poll.d.ts +12 -0
- package/dist/src/cli/ai/_poll.js +38 -0
- package/dist/src/cli/ai/_resolve.d.ts +8 -0
- package/dist/src/cli/ai/_resolve.js +27 -0
- package/dist/src/cli/ai/index.d.ts +127 -0
- package/dist/src/cli/ai/index.js +46 -0
- package/dist/src/cli/ai/insights/by-article.d.ts +10 -0
- package/dist/src/cli/ai/insights/by-article.js +21 -0
- package/dist/src/cli/ai/insights/delete.d.ts +7 -0
- package/dist/src/cli/ai/insights/delete.js +18 -0
- package/dist/src/cli/ai/insights/edit.d.ts +8 -0
- package/dist/src/cli/ai/insights/edit.js +54 -0
- package/dist/src/cli/ai/insights/get.d.ts +6 -0
- package/dist/src/cli/ai/insights/get.js +11 -0
- package/dist/src/cli/ai/insights/index.d.ts +30 -0
- package/dist/src/cli/ai/insights/index.js +17 -0
- package/dist/src/cli/ai/insights/list.d.ts +10 -0
- package/dist/src/cli/ai/insights/list.js +20 -0
- package/dist/src/cli/ai/insights/refresh.d.ts +10 -0
- package/dist/src/cli/ai/insights/refresh.js +25 -0
- package/dist/src/cli/ai/insights/translate.d.ts +10 -0
- package/dist/src/cli/ai/insights/translate.js +25 -0
- package/dist/src/cli/ai/overview/by-article.d.ts +7 -0
- package/dist/src/cli/ai/overview/by-article.js +15 -0
- package/dist/src/cli/ai/overview/index.d.ts +11 -0
- package/dist/src/cli/ai/overview/index.js +4 -0
- package/dist/src/cli/ai/overview/list.d.ts +10 -0
- package/dist/src/cli/ai/overview/list.js +20 -0
- package/dist/src/cli/ai/summary/by-article.d.ts +10 -0
- package/dist/src/cli/ai/summary/by-article.js +21 -0
- package/dist/src/cli/ai/summary/delete.d.ts +7 -0
- package/dist/src/cli/ai/summary/delete.js +18 -0
- package/dist/src/cli/ai/summary/edit.d.ts +8 -0
- package/dist/src/cli/ai/summary/edit.js +54 -0
- package/dist/src/cli/ai/summary/get.d.ts +6 -0
- package/dist/src/cli/ai/summary/get.js +11 -0
- package/dist/src/cli/ai/summary/index.d.ts +30 -0
- package/dist/src/cli/ai/summary/index.js +9 -0
- package/dist/src/cli/ai/summary/list.d.ts +10 -0
- package/dist/src/cli/ai/summary/list.js +20 -0
- package/dist/src/cli/ai/summary/regen.d.ts +10 -0
- package/dist/src/cli/ai/summary/regen.js +25 -0
- package/dist/src/cli/ai/summary/translate.d.ts +10 -0
- package/dist/src/cli/ai/summary/translate.js +25 -0
- package/dist/src/cli/ai/translate/by-article.d.ts +9 -0
- package/dist/src/cli/ai/translate/by-article.js +19 -0
- package/dist/src/cli/ai/translate/delete.d.ts +7 -0
- package/dist/src/cli/ai/translate/delete.js +18 -0
- package/dist/src/cli/ai/translate/edit.d.ts +8 -0
- package/dist/src/cli/ai/translate/edit.js +97 -0
- package/dist/src/cli/ai/translate/entries/delete.d.ts +7 -0
- package/dist/src/cli/ai/translate/entries/delete.js +18 -0
- package/dist/src/cli/ai/translate/entries/edit.d.ts +8 -0
- package/dist/src/cli/ai/translate/entries/edit.js +73 -0
- package/dist/src/cli/ai/translate/entries/generate.d.ts +7 -0
- package/dist/src/cli/ai/translate/entries/generate.js +15 -0
- package/dist/src/cli/ai/translate/entries/index.d.ts +17 -0
- package/dist/src/cli/ai/translate/entries/index.js +6 -0
- package/dist/src/cli/ai/translate/entries/list.d.ts +10 -0
- package/dist/src/cli/ai/translate/entries/list.js +20 -0
- package/dist/src/cli/ai/translate/get.d.ts +6 -0
- package/dist/src/cli/ai/translate/get.js +11 -0
- package/dist/src/cli/ai/translate/index.d.ts +40 -0
- package/dist/src/cli/ai/translate/index.js +19 -0
- package/dist/src/cli/ai/translate/languages.d.ts +7 -0
- package/dist/src/cli/ai/translate/languages.js +15 -0
- package/dist/src/cli/ai/translate/list.d.ts +9 -0
- package/dist/src/cli/ai/translate/list.js +19 -0
- package/dist/src/cli/ai/translate/run.d.ts +10 -0
- package/dist/src/cli/ai/translate/run.js +31 -0
- package/dist/src/cli/ai/tts/by-article.d.ts +7 -0
- package/dist/src/cli/ai/tts/by-article.js +15 -0
- package/dist/src/cli/ai/tts/delete.d.ts +7 -0
- package/dist/src/cli/ai/tts/delete.js +18 -0
- package/dist/src/cli/ai/tts/index.d.ts +22 -0
- package/dist/src/cli/ai/tts/index.js +7 -0
- package/dist/src/cli/ai/tts/list.d.ts +10 -0
- package/dist/src/cli/ai/tts/list.js +20 -0
- package/dist/src/cli/ai/tts/run.d.ts +10 -0
- package/dist/src/cli/ai/tts/run.js +25 -0
- package/dist/src/cli/ai/tts/voices.d.ts +7 -0
- package/dist/src/cli/ai/tts/voices.js +12 -0
- package/dist/src/cli/ai/views.d.ts +3 -0
- package/dist/src/cli/ai/views.js +45 -0
- package/dist/src/cli/auth/index.d.ts +6 -0
- package/dist/src/cli/auth/index.js +22 -0
- package/dist/src/cli/auth/login.d.ts +11 -0
- package/dist/src/cli/auth/login.js +168 -0
- package/dist/src/cli/auth/logout.d.ts +6 -0
- package/dist/src/cli/auth/logout.js +21 -0
- package/dist/src/cli/auth/status.d.ts +4 -0
- package/dist/src/cli/auth/status.js +31 -0
- package/dist/src/cli/auth/view.d.ts +25 -0
- package/dist/src/cli/auth/view.js +46 -0
- package/dist/src/cli/auth/whoami.d.ts +7 -0
- package/dist/src/cli/auth/whoami.js +44 -0
- package/dist/src/cli/category/create.d.ts +10 -0
- package/dist/src/cli/category/create.js +24 -0
- package/dist/src/cli/category/delete.d.ts +8 -0
- package/dist/src/cli/category/delete.js +21 -0
- package/dist/src/cli/category/get.d.ts +6 -0
- package/dist/src/cli/category/get.js +11 -0
- package/dist/src/cli/category/index.d.ts +20 -0
- package/dist/src/cli/category/index.js +41 -0
- package/dist/src/cli/category/list.d.ts +4 -0
- package/dist/src/cli/category/list.js +10 -0
- package/dist/src/cli/category/update.d.ts +12 -0
- package/dist/src/cli/category/update.js +34 -0
- package/dist/src/cli/comment/_flags.d.ts +28 -0
- package/dist/src/cli/comment/_flags.js +48 -0
- package/dist/src/cli/comment/approve.d.ts +9 -0
- package/dist/src/cli/comment/approve.js +23 -0
- package/dist/src/cli/comment/delete.d.ts +9 -0
- package/dist/src/cli/comment/delete.js +24 -0
- package/dist/src/cli/comment/get.d.ts +6 -0
- package/dist/src/cli/comment/get.js +12 -0
- package/dist/src/cli/comment/index.d.ts +34 -0
- package/dist/src/cli/comment/index.js +53 -0
- package/dist/src/cli/comment/list.d.ts +9 -0
- package/dist/src/cli/comment/list.js +20 -0
- package/dist/src/cli/comment/reject.d.ts +9 -0
- package/dist/src/cli/comment/reject.js +23 -0
- package/dist/src/cli/comment/reply.d.ts +9 -0
- package/dist/src/cli/comment/reply.js +31 -0
- package/dist/src/cli/comment/unread.d.ts +7 -0
- package/dist/src/cli/comment/unread.js +21 -0
- package/dist/src/cli/comment/view.d.ts +3 -0
- package/dist/src/cli/comment/view.js +197 -0
- package/dist/src/cli/config/edit.d.ts +5 -0
- package/dist/src/cli/config/edit.js +36 -0
- package/dist/src/cli/config/get.d.ts +6 -0
- package/dist/src/cli/config/get.js +11 -0
- package/dist/src/cli/config/index.d.ts +10 -0
- package/dist/src/cli/config/index.js +22 -0
- package/dist/src/cli/config/list.d.ts +4 -0
- package/dist/src/cli/config/list.js +10 -0
- package/dist/src/cli/config/set.d.ts +9 -0
- package/dist/src/cli/config/set.js +48 -0
- package/dist/src/cli/draft/_shared.d.ts +27 -0
- package/dist/src/cli/draft/_shared.js +85 -0
- package/dist/src/cli/draft/create.d.ts +21 -0
- package/dist/src/cli/draft/create.js +34 -0
- package/dist/src/cli/draft/delete.d.ts +7 -0
- package/dist/src/cli/draft/delete.js +20 -0
- package/dist/src/cli/draft/get.d.ts +6 -0
- package/dist/src/cli/draft/get.js +11 -0
- package/dist/src/cli/draft/index.d.ts +54 -0
- package/dist/src/cli/draft/index.js +42 -0
- package/dist/src/cli/draft/list.d.ts +11 -0
- package/dist/src/cli/draft/list.js +23 -0
- package/dist/src/cli/draft/publish.d.ts +8 -0
- package/dist/src/cli/draft/publish.js +64 -0
- package/dist/src/cli/draft/update.d.ts +22 -0
- package/dist/src/cli/draft/update.js +29 -0
- package/dist/src/cli/file/_shared.d.ts +6 -0
- package/dist/src/cli/file/_shared.js +5 -0
- package/dist/src/cli/file/delete.d.ts +8 -0
- package/dist/src/cli/file/delete.js +21 -0
- package/dist/src/cli/file/index.d.ts +19 -0
- package/dist/src/cli/file/index.js +33 -0
- package/dist/src/cli/file/list.d.ts +6 -0
- package/dist/src/cli/file/list.js +11 -0
- package/dist/src/cli/file/rename.d.ts +8 -0
- package/dist/src/cli/file/rename.js +16 -0
- package/dist/src/cli/file/upload.d.ts +9 -0
- package/dist/src/cli/file/upload.js +32 -0
- package/dist/src/cli/help/index.d.ts +62 -0
- package/dist/src/cli/help/index.js +276 -0
- package/dist/src/cli/help/registry.d.ts +28 -0
- package/dist/src/cli/help/registry.js +29 -0
- package/dist/src/cli/note/_flags.d.ts +66 -0
- package/dist/src/cli/note/_flags.js +73 -0
- package/dist/src/cli/note/create.d.ts +23 -0
- package/dist/src/cli/note/create.js +25 -0
- package/dist/src/cli/note/delete.d.ts +8 -0
- package/dist/src/cli/note/delete.js +21 -0
- package/dist/src/cli/note/edit.d.ts +28 -0
- package/dist/src/cli/note/edit.js +114 -0
- package/dist/src/cli/note/get.d.ts +6 -0
- package/dist/src/cli/note/get.js +29 -0
- package/dist/src/cli/note/index.d.ts +77 -0
- package/dist/src/cli/note/index.js +63 -0
- package/dist/src/cli/note/list.d.ts +10 -0
- package/dist/src/cli/note/list.js +22 -0
- package/dist/src/cli/note/publish.d.ts +7 -0
- package/dist/src/cli/note/publish.js +17 -0
- package/dist/src/cli/note/unpublish.d.ts +7 -0
- package/dist/src/cli/note/unpublish.js +17 -0
- package/dist/src/cli/note/update.d.ts +25 -0
- package/dist/src/cli/note/update.js +36 -0
- package/dist/src/cli/note/view.d.ts +3 -0
- package/dist/src/cli/note/view.js +162 -0
- package/dist/src/cli/page/create.d.ts +41 -0
- package/dist/src/cli/page/create.js +56 -0
- package/dist/src/cli/page/delete.d.ts +7 -0
- package/dist/src/cli/page/delete.js +37 -0
- package/dist/src/cli/page/edit.d.ts +19 -0
- package/dist/src/cli/page/edit.js +117 -0
- package/dist/src/cli/page/get.d.ts +6 -0
- package/dist/src/cli/page/get.js +16 -0
- package/dist/src/cli/page/index.d.ts +44 -0
- package/dist/src/cli/page/index.js +38 -0
- package/dist/src/cli/page/list.d.ts +4 -0
- package/dist/src/cli/page/list.js +10 -0
- package/dist/src/cli/page/update.d.ts +16 -0
- package/dist/src/cli/page/update.js +48 -0
- package/dist/src/cli/page/view.d.ts +2 -0
- package/dist/src/cli/page/view.js +79 -0
- package/dist/src/cli/post/_flags.d.ts +66 -0
- package/dist/src/cli/post/_flags.js +96 -0
- package/dist/src/cli/post/apply.d.ts +7 -0
- package/dist/src/cli/post/apply.js +70 -0
- package/dist/src/cli/post/create.d.ts +21 -0
- package/dist/src/cli/post/create.js +24 -0
- package/dist/src/cli/post/delete.d.ts +8 -0
- package/dist/src/cli/post/delete.js +21 -0
- package/dist/src/cli/post/edit.d.ts +26 -0
- package/dist/src/cli/post/edit.js +115 -0
- package/dist/src/cli/post/get.d.ts +7 -0
- package/dist/src/cli/post/get.js +15 -0
- package/dist/src/cli/post/index.d.ts +91 -0
- package/dist/src/cli/post/index.js +73 -0
- package/dist/src/cli/post/list.d.ts +10 -0
- package/dist/src/cli/post/list.js +23 -0
- package/dist/src/cli/post/publish.d.ts +7 -0
- package/dist/src/cli/post/publish.js +17 -0
- package/dist/src/cli/post/stage.d.ts +23 -0
- package/dist/src/cli/post/stage.js +55 -0
- package/dist/src/cli/post/unpublish.d.ts +7 -0
- package/dist/src/cli/post/unpublish.js +17 -0
- package/dist/src/cli/post/update.d.ts +23 -0
- package/dist/src/cli/post/update.js +38 -0
- package/dist/src/cli/post/view.d.ts +3 -0
- package/dist/src/cli/post/view.js +150 -0
- package/dist/src/cli/preview/index.d.ts +13 -0
- package/dist/src/cli/preview/index.js +226 -0
- package/dist/src/cli/profile/index.d.ts +14 -0
- package/dist/src/cli/profile/index.js +36 -0
- package/dist/src/cli/profile/ls.d.ts +5 -0
- package/dist/src/cli/profile/ls.js +26 -0
- package/dist/src/cli/profile/mark.d.ts +9 -0
- package/dist/src/cli/profile/mark.js +23 -0
- package/dist/src/cli/profile/rm.d.ts +12 -0
- package/dist/src/cli/profile/rm.js +50 -0
- package/dist/src/cli/profile/show.d.ts +9 -0
- package/dist/src/cli/profile/show.js +40 -0
- package/dist/src/cli/profile/use.d.ts +6 -0
- package/dist/src/cli/profile/use.js +11 -0
- package/dist/src/cli/profile/view.d.ts +8 -0
- package/dist/src/cli/profile/view.js +21 -0
- package/dist/src/cli/project/_flags.d.ts +56 -0
- package/dist/src/cli/project/_flags.js +130 -0
- package/dist/src/cli/project/create.d.ts +17 -0
- package/dist/src/cli/project/create.js +25 -0
- package/dist/src/cli/project/delete.d.ts +8 -0
- package/dist/src/cli/project/delete.js +22 -0
- package/dist/src/cli/project/edit.d.ts +11 -0
- package/dist/src/cli/project/edit.js +61 -0
- package/dist/src/cli/project/get.d.ts +7 -0
- package/dist/src/cli/project/get.js +14 -0
- package/dist/src/cli/project/index.d.ts +43 -0
- package/dist/src/cli/project/index.js +52 -0
- package/dist/src/cli/project/list.d.ts +8 -0
- package/dist/src/cli/project/list.js +19 -0
- package/dist/src/cli/project/update.d.ts +18 -0
- package/dist/src/cli/project/update.js +24 -0
- package/dist/src/cli/project/view-cmd.d.ts +7 -0
- package/dist/src/cli/project/view-cmd.js +15 -0
- package/dist/src/cli/project/view.d.ts +3 -0
- package/dist/src/cli/project/view.js +102 -0
- package/dist/src/cli/render/codehighlight.d.ts +8 -0
- package/dist/src/cli/render/codehighlight.js +264 -0
- package/dist/src/cli/render/envelope.d.ts +7 -0
- package/dist/src/cli/render/envelope.js +23 -0
- package/dist/src/cli/render/frontmatter.d.ts +8 -0
- package/dist/src/cli/render/frontmatter.js +50 -0
- package/dist/src/cli/render/helpers.d.ts +2 -0
- package/dist/src/cli/render/helpers.js +11 -0
- package/dist/src/cli/render/index.d.ts +7 -0
- package/dist/src/cli/render/index.js +10 -0
- package/dist/src/cli/render/lexical/blocks.d.ts +19 -0
- package/dist/src/cli/render/lexical/blocks.js +208 -0
- package/dist/src/cli/render/lexical/code.d.ts +2 -0
- package/dist/src/cli/render/lexical/code.js +22 -0
- package/dist/src/cli/render/lexical/embeds.d.ts +6 -0
- package/dist/src/cli/render/lexical/embeds.js +51 -0
- package/dist/src/cli/render/lexical/index.d.ts +9 -0
- package/dist/src/cli/render/lexical/index.js +25 -0
- package/dist/src/cli/render/lexical/inlines.d.ts +17 -0
- package/dist/src/cli/render/lexical/inlines.js +76 -0
- package/dist/src/cli/render/lexical/parser.d.ts +10 -0
- package/dist/src/cli/render/lexical/parser.js +64 -0
- package/dist/src/cli/render/lexical/walker.d.ts +21 -0
- package/dist/src/cli/render/lexical/walker.js +51 -0
- package/dist/src/cli/render/markdown.d.ts +18 -0
- package/dist/src/cli/render/markdown.js +196 -0
- package/dist/src/cli/render/metadata-block.d.ts +14 -0
- package/dist/src/cli/render/metadata-block.js +50 -0
- package/dist/src/cli/skill/all.d.ts +4 -0
- package/dist/src/cli/skill/all.js +11 -0
- package/dist/src/cli/skill/get.d.ts +6 -0
- package/dist/src/cli/skill/get.js +12 -0
- package/dist/src/cli/skill/index.d.ts +10 -0
- package/dist/src/cli/skill/index.js +34 -0
- package/dist/src/cli/skill/list.d.ts +4 -0
- package/dist/src/cli/skill/list.js +11 -0
- package/dist/src/cli/skill/search.d.ts +6 -0
- package/dist/src/cli/skill/search.js +12 -0
- package/dist/src/cli/skill/views.d.ts +6 -0
- package/dist/src/cli/skill/views.js +90 -0
- package/dist/src/cli/snippet/_flags.d.ts +57 -0
- package/dist/src/cli/snippet/_flags.js +123 -0
- package/dist/src/cli/snippet/_resolve.d.ts +4 -0
- package/dist/src/cli/snippet/_resolve.js +32 -0
- package/dist/src/cli/snippet/_sync.d.ts +5 -0
- package/dist/src/cli/snippet/_sync.js +54 -0
- package/dist/src/cli/snippet/create.d.ts +19 -0
- package/dist/src/cli/snippet/create.js +35 -0
- package/dist/src/cli/snippet/delete.d.ts +8 -0
- package/dist/src/cli/snippet/delete.js +28 -0
- package/dist/src/cli/snippet/edit.d.ts +7 -0
- package/dist/src/cli/snippet/edit.js +29 -0
- package/dist/src/cli/snippet/get.d.ts +6 -0
- package/dist/src/cli/snippet/get.js +12 -0
- package/dist/src/cli/snippet/index.d.ts +43 -0
- package/dist/src/cli/snippet/index.js +58 -0
- package/dist/src/cli/snippet/list.d.ts +9 -0
- package/dist/src/cli/snippet/list.js +20 -0
- package/dist/src/cli/snippet/pull.d.ts +8 -0
- package/dist/src/cli/snippet/pull.js +33 -0
- package/dist/src/cli/snippet/push.d.ts +10 -0
- package/dist/src/cli/snippet/push.js +31 -0
- package/dist/src/cli/snippet/update.d.ts +8 -0
- package/dist/src/cli/snippet/update.js +16 -0
- package/dist/src/cli/topic/create.d.ts +10 -0
- package/dist/src/cli/topic/create.js +24 -0
- package/dist/src/cli/topic/delete.d.ts +7 -0
- package/dist/src/cli/topic/delete.js +37 -0
- package/dist/src/cli/topic/get.d.ts +6 -0
- package/dist/src/cli/topic/get.js +15 -0
- package/dist/src/cli/topic/index.d.ts +20 -0
- package/dist/src/cli/topic/index.js +32 -0
- package/dist/src/cli/topic/list.d.ts +4 -0
- package/dist/src/cli/topic/list.js +10 -0
- package/dist/src/cli/topic/update.d.ts +11 -0
- package/dist/src/cli/topic/update.js +51 -0
- package/dist/src/cli/ui/index.d.ts +24 -0
- package/dist/src/cli/ui/index.js +83 -0
- package/dist/src/cli/update/index.d.ts +10 -0
- package/dist/src/cli/update/index.js +142 -0
- package/dist/src/domain/admin-link.d.ts +12 -0
- package/dist/src/domain/admin-link.js +45 -0
- package/dist/src/domain/content-spec.d.ts +20 -0
- package/dist/src/domain/content-spec.js +78 -0
- package/dist/src/domain/envelope-compat.d.ts +68 -0
- package/dist/src/domain/envelope-compat.js +121 -0
- package/dist/src/domain/envelope.d.ts +34 -0
- package/dist/src/domain/envelope.js +355 -0
- package/dist/src/domain/errors.d.ts +336 -0
- package/dist/src/domain/errors.js +239 -0
- package/dist/src/domain/gate.d.ts +14 -0
- package/dist/src/domain/gate.js +18 -0
- package/dist/src/domain/payload.d.ts +64 -0
- package/dist/src/domain/payload.js +237 -0
- package/dist/src/domain/preflight-guards.d.ts +54 -0
- package/dist/src/domain/preflight-guards.js +130 -0
- package/dist/src/domain/runtime-flags.d.ts +33 -0
- package/dist/src/domain/runtime-flags.js +166 -0
- package/dist/src/domain/schema/api-envelope.d.ts +67 -0
- package/dist/src/domain/schema/api-envelope.js +65 -0
- package/dist/src/domain/schema/category.d.ts +23 -0
- package/dist/src/domain/schema/category.js +19 -0
- package/dist/src/domain/schema/config.d.ts +13 -0
- package/dist/src/domain/schema/config.js +18 -0
- package/dist/src/domain/schema/note.d.ts +76 -0
- package/dist/src/domain/schema/note.js +35 -0
- package/dist/src/domain/schema/page.d.ts +40 -0
- package/dist/src/domain/schema/page.js +22 -0
- package/dist/src/domain/schema/post.d.ts +68 -0
- package/dist/src/domain/schema/post.js +35 -0
- package/dist/src/domain/schema/profile.d.ts +14 -0
- package/dist/src/domain/schema/profile.js +22 -0
- package/dist/src/domain/schema/topic.d.ts +24 -0
- package/dist/src/domain/schema/topic.js +16 -0
- package/dist/src/domain/version.d.ts +15 -0
- package/dist/src/domain/version.js +43 -0
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.js +8 -0
- package/dist/src/layers/App.d.ts +30 -0
- package/dist/src/layers/App.js +39 -0
- package/dist/src/services/Ai/index.d.ts +13 -0
- package/dist/src/services/Ai/index.js +127 -0
- package/dist/src/services/Ai/overview.d.ts +7 -0
- package/dist/src/services/Ai/overview.js +11 -0
- package/dist/src/services/Ai/resources.d.ts +7 -0
- package/dist/src/services/Ai/resources.js +59 -0
- package/dist/src/services/Ai/shared.d.ts +2 -0
- package/dist/src/services/Ai/shared.js +11 -0
- package/dist/src/services/Ai/tasks.d.ts +8 -0
- package/dist/src/services/Ai/tasks.js +144 -0
- package/dist/src/services/Ai/types.d.ts +130 -0
- package/dist/src/services/Ai/types.js +1 -0
- package/dist/src/services/Api.d.ts +67 -0
- package/dist/src/services/Api.js +348 -0
- package/dist/src/services/Auth.d.ts +101 -0
- package/dist/src/services/Auth.js +402 -0
- package/dist/src/services/Backup.d.ts +8 -0
- package/dist/src/services/Backup.js +4 -0
- package/dist/src/services/Cache.d.ts +8 -0
- package/dist/src/services/Cache.js +4 -0
- package/dist/src/services/Comment.d.ts +48 -0
- package/dist/src/services/Comment.js +102 -0
- package/dist/src/services/Config.d.ts +95 -0
- package/dist/src/services/Config.js +359 -0
- package/dist/src/services/Editor.d.ts +28 -0
- package/dist/src/services/Editor.js +95 -0
- package/dist/src/services/Lexical.d.ts +27 -0
- package/dist/src/services/Lexical.js +56 -0
- package/dist/src/services/Migration.d.ts +31 -0
- package/dist/src/services/Migration.js +177 -0
- package/dist/src/services/Profile.d.ts +29 -0
- package/dist/src/services/Profile.js +115 -0
- package/dist/src/services/Renderer/content.d.ts +16 -0
- package/dist/src/services/Renderer/content.js +110 -0
- package/dist/src/services/Renderer/datetime.d.ts +38 -0
- package/dist/src/services/Renderer/datetime.js +147 -0
- package/dist/src/services/Renderer/errors.d.ts +3 -0
- package/dist/src/services/Renderer/errors.js +59 -0
- package/dist/src/services/Renderer/index.d.ts +13 -0
- package/dist/src/services/Renderer/index.js +11 -0
- package/dist/src/services/Renderer/lists.d.ts +1 -0
- package/dist/src/services/Renderer/lists.js +101 -0
- package/dist/src/services/Renderer/options.d.ts +10 -0
- package/dist/src/services/Renderer/options.js +13 -0
- package/dist/src/services/Renderer/primitives.d.ts +4 -0
- package/dist/src/services/Renderer/primitives.js +12 -0
- package/dist/src/services/Renderer/service.d.ts +35 -0
- package/dist/src/services/Renderer/service.js +123 -0
- package/dist/src/services/Renderer/view.d.ts +16 -0
- package/dist/src/services/Renderer/view.js +1 -0
- package/dist/src/services/Resolver.d.ts +47 -0
- package/dist/src/services/Resolver.js +269 -0
- package/dist/src/services/Skill.d.ts +29 -0
- package/dist/src/services/Skill.js +421 -0
- package/dist/src/services/UpdateNotifier.d.ts +162 -0
- package/dist/src/services/UpdateNotifier.js +572 -0
- package/dist/test/cli/ai/ai.test.d.ts +1 -0
- package/dist/test/cli/ai/ai.test.js +507 -0
- package/dist/test/cli/ai/verbs.test.d.ts +1 -0
- package/dist/test/cli/ai/verbs.test.js +235 -0
- package/dist/test/cli/auth/login.test.d.ts +1 -0
- package/dist/test/cli/auth/login.test.js +236 -0
- package/dist/test/cli/auth/logout-whoami.test.d.ts +1 -0
- package/dist/test/cli/auth/logout-whoami.test.js +124 -0
- package/dist/test/cli/auth/status.test.d.ts +1 -0
- package/dist/test/cli/auth/status.test.js +90 -0
- package/dist/test/cli/category/category.test.d.ts +1 -0
- package/dist/test/cli/category/category.test.js +175 -0
- package/dist/test/cli/comment/comment.test.d.ts +1 -0
- package/dist/test/cli/comment/comment.test.js +445 -0
- package/dist/test/cli/config/config.test.d.ts +1 -0
- package/dist/test/cli/config/config.test.js +281 -0
- package/dist/test/cli/edit-roundtrip.test.d.ts +1 -0
- package/dist/test/cli/edit-roundtrip.test.js +259 -0
- package/dist/test/cli/file/file.test.d.ts +1 -0
- package/dist/test/cli/file/file.test.js +185 -0
- package/dist/test/cli/help.test.d.ts +1 -0
- package/dist/test/cli/help.test.js +289 -0
- package/dist/test/cli/note/create.test.d.ts +1 -0
- package/dist/test/cli/note/create.test.js +155 -0
- package/dist/test/cli/note/list.test.d.ts +1 -0
- package/dist/test/cli/note/list.test.js +115 -0
- package/dist/test/cli/note/publish.test.d.ts +1 -0
- package/dist/test/cli/note/publish.test.js +123 -0
- package/dist/test/cli/page/page.test.d.ts +1 -0
- package/dist/test/cli/page/page.test.js +185 -0
- package/dist/test/cli/post/create.test.d.ts +1 -0
- package/dist/test/cli/post/create.test.js +172 -0
- package/dist/test/cli/post/list.test.d.ts +1 -0
- package/dist/test/cli/post/list.test.js +133 -0
- package/dist/test/cli/post/publish.test.d.ts +1 -0
- package/dist/test/cli/post/publish.test.js +139 -0
- package/dist/test/cli/post/stage-apply.test.d.ts +1 -0
- package/dist/test/cli/post/stage-apply.test.js +215 -0
- package/dist/test/cli/post/update.test.d.ts +1 -0
- package/dist/test/cli/post/update.test.js +160 -0
- package/dist/test/cli/post-note-crud.test.d.ts +1 -0
- package/dist/test/cli/post-note-crud.test.js +362 -0
- package/dist/test/cli/profile/ls.test.d.ts +1 -0
- package/dist/test/cli/profile/ls.test.js +93 -0
- package/dist/test/cli/profile/mark-use.test.d.ts +1 -0
- package/dist/test/cli/profile/mark-use.test.js +216 -0
- package/dist/test/cli/project-crud.test.d.ts +1 -0
- package/dist/test/cli/project-crud.test.js +315 -0
- package/dist/test/cli/render/lexical.test.d.ts +1 -0
- package/dist/test/cli/render/lexical.test.js +216 -0
- package/dist/test/cli/render/markdown.test.d.ts +1 -0
- package/dist/test/cli/render/markdown.test.js +39 -0
- package/dist/test/cli/snippet-crud.test.d.ts +1 -0
- package/dist/test/cli/snippet-crud.test.js +293 -0
- package/dist/test/cli/topic/topic.test.d.ts +1 -0
- package/dist/test/cli/topic/topic.test.js +181 -0
- package/dist/test/cli/update.test.d.ts +1 -0
- package/dist/test/cli/update.test.js +395 -0
- package/dist/test/domain/content-spec.test.d.ts +1 -0
- package/dist/test/domain/content-spec.test.js +126 -0
- package/dist/test/domain/envelope-compat.test.d.ts +1 -0
- package/dist/test/domain/envelope-compat.test.js +126 -0
- package/dist/test/domain/envelope.test.d.ts +1 -0
- package/dist/test/domain/envelope.test.js +149 -0
- package/dist/test/domain/errors.test.d.ts +1 -0
- package/dist/test/domain/errors.test.js +127 -0
- package/dist/test/domain/gate.test.d.ts +1 -0
- package/dist/test/domain/gate.test.js +128 -0
- package/dist/test/domain/payload.test.d.ts +1 -0
- package/dist/test/domain/payload.test.js +259 -0
- package/dist/test/helper/test-fs.d.ts +24 -0
- package/dist/test/helper/test-fs.js +161 -0
- package/dist/test/helper/test-http.d.ts +31 -0
- package/dist/test/helper/test-http.js +66 -0
- package/dist/test/integration/_helpers.d.ts +5 -0
- package/dist/test/integration/_helpers.js +24 -0
- package/dist/test/integration/cli-error-envelope.test.d.ts +1 -0
- package/dist/test/integration/cli-error-envelope.test.js +137 -0
- package/dist/test/integration/cli-help-render.test.d.ts +1 -0
- package/dist/test/integration/cli-help-render.test.js +149 -0
- package/dist/test/integration/cli-help.test.d.ts +1 -0
- package/dist/test/integration/cli-help.test.js +67 -0
- package/dist/test/integration/cli-post-list.test.d.ts +1 -0
- package/dist/test/integration/cli-post-list.test.js +140 -0
- package/dist/test/integration/cli-skill.test.d.ts +1 -0
- package/dist/test/integration/cli-skill.test.js +74 -0
- package/dist/test/integration/cli-version.test.d.ts +1 -0
- package/dist/test/integration/cli-version.test.js +37 -0
- package/dist/test/services/Api.test.d.ts +1 -0
- package/dist/test/services/Api.test.js +553 -0
- package/dist/test/services/Auth.test.d.ts +1 -0
- package/dist/test/services/Auth.test.js +650 -0
- package/dist/test/services/Config.test.d.ts +1 -0
- package/dist/test/services/Config.test.js +510 -0
- package/dist/test/services/Datetime.test.d.ts +1 -0
- package/dist/test/services/Datetime.test.js +113 -0
- package/dist/test/services/Editor.test.d.ts +1 -0
- package/dist/test/services/Editor.test.js +205 -0
- package/dist/test/services/Lexical.errors.test.d.ts +1 -0
- package/dist/test/services/Lexical.errors.test.js +60 -0
- package/dist/test/services/Lexical.test.d.ts +1 -0
- package/dist/test/services/Lexical.test.js +68 -0
- package/dist/test/services/Migration.test.d.ts +1 -0
- package/dist/test/services/Migration.test.js +376 -0
- package/dist/test/services/Profile.test.d.ts +1 -0
- package/dist/test/services/Profile.test.js +277 -0
- package/dist/test/services/Renderer.test.d.ts +1 -0
- package/dist/test/services/Renderer.test.js +538 -0
- package/dist/test/services/Resolver.test.d.ts +1 -0
- package/dist/test/services/Resolver.test.js +320 -0
- package/dist/test/services/Skill.test.d.ts +1 -0
- package/dist/test/services/Skill.test.js +261 -0
- package/dist/test/services/UpdateNotifier.spawn.test.d.ts +1 -0
- package/dist/test/services/UpdateNotifier.spawn.test.js +73 -0
- package/dist/test/services/UpdateNotifier.test.d.ts +1 -0
- package/dist/test/services/UpdateNotifier.test.js +912 -0
- package/dist/vendor/litexml/cli.mjs +19 -4
- package/dist/vendor/litexml/litexml-html-preview-client.css +98 -13
- package/dist/vendor/litexml/litexml-html-preview-client.js +5794 -4976
- package/dist/vendor/litexml/style.css +5 -5
- package/package.json +29 -26
- package/skills/safety.md +1 -1
- package/LICENSE +0 -33
- package/dist/esm-CDcJmHkG.mjs +0 -2
|
@@ -0,0 +1,650 @@
|
|
|
1
|
+
import { HttpClient, HttpClientError, HttpClientResponse, } from '@effect/platform';
|
|
2
|
+
import { describe, expect, it as itVitest, vi } from '@effect/vitest';
|
|
3
|
+
import { Effect, Layer } from 'effect';
|
|
4
|
+
import { Generic } from '../../src/domain/errors';
|
|
5
|
+
import { Auth, isExpiringSoon, toCredentials, } from '../../src/services/Auth';
|
|
6
|
+
import { Config, } from '../../src/services/Config';
|
|
7
|
+
import { testHttpLayer } from '../helper/test-http';
|
|
8
|
+
// ---------------------------------------------------------------------------
|
|
9
|
+
// Fixtures
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
11
|
+
const baseResolved = {
|
|
12
|
+
apiUrl: 'https://blog.example.com',
|
|
13
|
+
apiBase: 'https://blog.example.com/api/v2',
|
|
14
|
+
authBase: 'https://blog.example.com/api/v2/auth',
|
|
15
|
+
apiVersion: 2,
|
|
16
|
+
clientId: 'mxs-cli',
|
|
17
|
+
configPath: '/tmp/config.json',
|
|
18
|
+
credentialsPath: '/tmp/credentials.json',
|
|
19
|
+
profileName: 'prod',
|
|
20
|
+
isProduction: false,
|
|
21
|
+
profileExplicit: false,
|
|
22
|
+
urlOverridden: false,
|
|
23
|
+
};
|
|
24
|
+
const makeMockConfigLayer = (resolved, creds, writes = { last: null }, deletes = { invokedFor: null }, resolveOverride) => {
|
|
25
|
+
const service = {
|
|
26
|
+
getConfigDir: Effect.succeed('/tmp'),
|
|
27
|
+
getProfilesDir: Effect.succeed('/tmp/profiles'),
|
|
28
|
+
getProfileDir: (name) => Effect.succeed(`/tmp/profiles/${name}`),
|
|
29
|
+
getProfileConfigPath: (name) => Effect.succeed(`/tmp/profiles/${name}/config.json`),
|
|
30
|
+
getProfileCredentialsPath: (name) => Effect.succeed(`/tmp/profiles/${name}/credentials.json`),
|
|
31
|
+
getCurrentPath: Effect.succeed('/tmp/current'),
|
|
32
|
+
getLegacyConfigPath: Effect.succeed('/tmp/config.json'),
|
|
33
|
+
getLegacyCredentialsPath: Effect.succeed('/tmp/credentials.json'),
|
|
34
|
+
readProfileConfig: () => Effect.succeed({}),
|
|
35
|
+
writeProfileConfig: () => Effect.void,
|
|
36
|
+
updateProfileConfig: () => Effect.succeed({}),
|
|
37
|
+
readProfileCredentials: () => Effect.succeed(creds),
|
|
38
|
+
writeProfileCredentials: (_name, cred) => Effect.sync(() => {
|
|
39
|
+
writes.last = cred;
|
|
40
|
+
}),
|
|
41
|
+
deleteProfileCredentials: (name) => Effect.sync(() => {
|
|
42
|
+
deletes.invokedFor = name;
|
|
43
|
+
}),
|
|
44
|
+
readLegacyConfig: Effect.succeed({}),
|
|
45
|
+
readLegacyConfigRaw: Effect.succeed(null),
|
|
46
|
+
readLegacyCredentialsRaw: Effect.succeed(null),
|
|
47
|
+
deleteLegacyConfig: Effect.void,
|
|
48
|
+
deleteLegacyCredentials: Effect.void,
|
|
49
|
+
readCurrent: Effect.succeed(resolved.profileName),
|
|
50
|
+
writeCurrent: () => Effect.void,
|
|
51
|
+
listProfileDirs: Effect.succeed([]),
|
|
52
|
+
profileExists: () => Effect.succeed(true),
|
|
53
|
+
removeProfileDir: () => Effect.void,
|
|
54
|
+
resolve: resolveOverride ?? (() => Effect.succeed(resolved)),
|
|
55
|
+
};
|
|
56
|
+
return Layer.succeed(Config, service);
|
|
57
|
+
};
|
|
58
|
+
const failingHttpLayer = (cause) => Layer.succeed(HttpClient.HttpClient, HttpClient.make((request) => Effect.fail(new HttpClientError.RequestError({
|
|
59
|
+
request,
|
|
60
|
+
reason: 'Transport',
|
|
61
|
+
cause,
|
|
62
|
+
}))));
|
|
63
|
+
const responseErrorHttpLayer = (status) => Layer.succeed(HttpClient.HttpClient, HttpClient.make((request) => Effect.fail(new HttpClientError.ResponseError({
|
|
64
|
+
request,
|
|
65
|
+
response: HttpClientResponse.fromWeb(request, new Response(JSON.stringify({ ok: false }), {
|
|
66
|
+
status,
|
|
67
|
+
headers: { 'content-type': 'application/json' },
|
|
68
|
+
})),
|
|
69
|
+
reason: 'StatusCode',
|
|
70
|
+
}))));
|
|
71
|
+
// ---------------------------------------------------------------------------
|
|
72
|
+
// Pure helpers
|
|
73
|
+
// ---------------------------------------------------------------------------
|
|
74
|
+
describe('Auth pure helpers', () => {
|
|
75
|
+
itVitest('isExpiringSoon — true when within buffer', () => {
|
|
76
|
+
expect(isExpiringSoon({ access_token: 'x', expires_at: Date.now() + 1_000 }, 60_000)).toBe(true);
|
|
77
|
+
});
|
|
78
|
+
itVitest('isExpiringSoon — false when far in the future', () => {
|
|
79
|
+
expect(isExpiringSoon({ access_token: 'x', expires_at: Date.now() + 10 * 60_000 }, 60_000)).toBe(false);
|
|
80
|
+
});
|
|
81
|
+
itVitest('toCredentials — computes expires_at from expires_in', () => {
|
|
82
|
+
const before = Date.now();
|
|
83
|
+
const cred = toCredentials({
|
|
84
|
+
access_token: 'abc',
|
|
85
|
+
token_type: 'Bearer',
|
|
86
|
+
expires_in: 3600,
|
|
87
|
+
refresh_token: 'refresh',
|
|
88
|
+
user: { id: 'u1', email: 'owner@example.com' },
|
|
89
|
+
});
|
|
90
|
+
expect(cred.access_token).toBe('abc');
|
|
91
|
+
expect(cred.refresh_token).toBe('refresh');
|
|
92
|
+
expect(cred.user?.id).toBe('u1');
|
|
93
|
+
expect(cred.expires_at).toBeGreaterThanOrEqual(before + 3590_000);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
// ---------------------------------------------------------------------------
|
|
97
|
+
// probe
|
|
98
|
+
// ---------------------------------------------------------------------------
|
|
99
|
+
describe('Auth.probe', () => {
|
|
100
|
+
itVitest('prefers /api/v2/auth when ok', async () => {
|
|
101
|
+
const http = testHttpLayer({
|
|
102
|
+
'GET https://blog.example.com/api/v2/auth/ok': {
|
|
103
|
+
status: 200,
|
|
104
|
+
body: { ok: true },
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
const layer = Auth.Default.pipe(Layer.provide(makeMockConfigLayer(baseResolved, null)), Layer.provide(http.layer));
|
|
108
|
+
const program = Effect.gen(function* () {
|
|
109
|
+
const auth = yield* Auth;
|
|
110
|
+
return yield* auth.probe('https://blog.example.com');
|
|
111
|
+
});
|
|
112
|
+
const res = await Effect.runPromise(Effect.provide(program, layer));
|
|
113
|
+
expect(res.apiVersion).toBe(2);
|
|
114
|
+
expect(res.authBase).toBe('https://blog.example.com/api/v2/auth');
|
|
115
|
+
});
|
|
116
|
+
itVitest('falls back to /auth in dev', async () => {
|
|
117
|
+
const http = testHttpLayer({
|
|
118
|
+
'GET https://blog.example.com/api/v2/auth/ok': { status: 404 },
|
|
119
|
+
'GET https://blog.example.com/auth/ok': {
|
|
120
|
+
status: 200,
|
|
121
|
+
body: { ok: true },
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
const layer = Auth.Default.pipe(Layer.provide(makeMockConfigLayer(baseResolved, null)), Layer.provide(http.layer));
|
|
125
|
+
const program = Effect.gen(function* () {
|
|
126
|
+
const auth = yield* Auth;
|
|
127
|
+
return yield* auth.probe('https://blog.example.com');
|
|
128
|
+
});
|
|
129
|
+
const res = await Effect.runPromise(Effect.provide(program, layer));
|
|
130
|
+
expect(res.authBase).toBe('https://blog.example.com/auth');
|
|
131
|
+
});
|
|
132
|
+
itVitest('fails AuthProbe when no endpoint responds', async () => {
|
|
133
|
+
const http = testHttpLayer({
|
|
134
|
+
'GET https://blog.example.com/api/v2/auth/ok': { status: 404 },
|
|
135
|
+
'GET https://blog.example.com/auth/ok': { status: 404 },
|
|
136
|
+
});
|
|
137
|
+
const layer = Auth.Default.pipe(Layer.provide(makeMockConfigLayer(baseResolved, null)), Layer.provide(http.layer));
|
|
138
|
+
const program = Effect.gen(function* () {
|
|
139
|
+
const auth = yield* Auth;
|
|
140
|
+
return yield* auth.probe('https://blog.example.com');
|
|
141
|
+
}).pipe(Effect.flip);
|
|
142
|
+
const err = await Effect.runPromise(Effect.provide(program, layer));
|
|
143
|
+
expect(err._tag).toBe('AuthProbe');
|
|
144
|
+
});
|
|
145
|
+
itVitest.each([
|
|
146
|
+
[{ code: 'ENOTFOUND' }, 'NetworkDns'],
|
|
147
|
+
[{ code: 'EAI_AGAIN' }, 'NetworkDns'],
|
|
148
|
+
[{ code: 'ECONNREFUSED' }, 'NetworkRefused'],
|
|
149
|
+
[{ code: 'ETIMEDOUT' }, 'NetworkTimeout'],
|
|
150
|
+
[{ cause: { code: 'UND_ERR_CONNECT_TIMEOUT' } }, 'NetworkTimeout'],
|
|
151
|
+
])('maps transport failure %j to %s', async (cause, tag) => {
|
|
152
|
+
const layer = Auth.Default.pipe(Layer.provide(makeMockConfigLayer(baseResolved, null)), Layer.provide(failingHttpLayer(cause)));
|
|
153
|
+
const program = Effect.gen(function* () {
|
|
154
|
+
const auth = yield* Auth;
|
|
155
|
+
return yield* auth.probe('https://blog.example.com');
|
|
156
|
+
}).pipe(Effect.flip);
|
|
157
|
+
const err = await Effect.runPromise(Effect.provide(program, layer));
|
|
158
|
+
expect(err._tag).toBe(tag);
|
|
159
|
+
});
|
|
160
|
+
itVitest('ignores generic transport failures while trying fallback endpoints', async () => {
|
|
161
|
+
let call = 0;
|
|
162
|
+
const http = Layer.succeed(HttpClient.HttpClient, HttpClient.make((request) => {
|
|
163
|
+
call += 1;
|
|
164
|
+
if (call === 1) {
|
|
165
|
+
return Effect.fail(new HttpClientError.RequestError({
|
|
166
|
+
request,
|
|
167
|
+
reason: 'Transport',
|
|
168
|
+
cause: new Error('temporary'),
|
|
169
|
+
}));
|
|
170
|
+
}
|
|
171
|
+
return Effect.succeed(HttpClientResponse.fromWeb(request, new Response(JSON.stringify({ ok: true }), {
|
|
172
|
+
status: 200,
|
|
173
|
+
headers: { 'content-type': 'application/json' },
|
|
174
|
+
})));
|
|
175
|
+
}));
|
|
176
|
+
const layer = Auth.Default.pipe(Layer.provide(makeMockConfigLayer(baseResolved, null)), Layer.provide(http));
|
|
177
|
+
const program = Effect.gen(function* () {
|
|
178
|
+
const auth = yield* Auth;
|
|
179
|
+
return yield* auth.probe('https://blog.example.com');
|
|
180
|
+
});
|
|
181
|
+
const res = await Effect.runPromise(Effect.provide(program, layer));
|
|
182
|
+
expect(res.authBase).toBe('https://blog.example.com/api/v2/auth');
|
|
183
|
+
});
|
|
184
|
+
itVitest('uses ResponseError responses as probe responses', async () => {
|
|
185
|
+
const layer = Auth.Default.pipe(Layer.provide(makeMockConfigLayer(baseResolved, null)), Layer.provide(responseErrorHttpLayer(200)));
|
|
186
|
+
const program = Effect.gen(function* () {
|
|
187
|
+
const auth = yield* Auth;
|
|
188
|
+
return yield* auth.probe('https://blog.example.com');
|
|
189
|
+
});
|
|
190
|
+
const res = await Effect.runPromise(Effect.provide(program, layer));
|
|
191
|
+
expect(res.authBase).toBe('https://blog.example.com/api/v3/auth');
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
// ---------------------------------------------------------------------------
|
|
195
|
+
// requestDeviceCode
|
|
196
|
+
// ---------------------------------------------------------------------------
|
|
197
|
+
describe('Auth.requestDeviceCode', () => {
|
|
198
|
+
itVitest('returns response on success', async () => {
|
|
199
|
+
const http = testHttpLayer({
|
|
200
|
+
'POST https://blog.example.com/api/v2/auth/device/code': {
|
|
201
|
+
status: 200,
|
|
202
|
+
body: {
|
|
203
|
+
device_code: 'dev',
|
|
204
|
+
user_code: 'UC',
|
|
205
|
+
verification_uri: 'https://blog/device',
|
|
206
|
+
verification_uri_complete: 'https://blog/device?user_code=UC',
|
|
207
|
+
expires_in: 1800,
|
|
208
|
+
interval: 5,
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
});
|
|
212
|
+
const layer = Auth.Default.pipe(Layer.provide(makeMockConfigLayer(baseResolved, null)), Layer.provide(http.layer));
|
|
213
|
+
const program = Effect.gen(function* () {
|
|
214
|
+
const auth = yield* Auth;
|
|
215
|
+
return yield* auth.requestDeviceCode('https://blog.example.com/api/v2/auth', 'mxs-cli', 'openid');
|
|
216
|
+
});
|
|
217
|
+
const res = await Effect.runPromise(Effect.provide(program, layer));
|
|
218
|
+
expect(res.user_code).toBe('UC');
|
|
219
|
+
expect(http.recorder.calls[0]?.body).toEqual({
|
|
220
|
+
client_id: 'mxs-cli',
|
|
221
|
+
scope: 'openid',
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
itVitest('fails AuthDenied on non-2xx', async () => {
|
|
225
|
+
const http = testHttpLayer({
|
|
226
|
+
'POST https://blog.example.com/api/v2/auth/device/code': {
|
|
227
|
+
status: 400,
|
|
228
|
+
body: { error: 'x' },
|
|
229
|
+
},
|
|
230
|
+
});
|
|
231
|
+
const layer = Auth.Default.pipe(Layer.provide(makeMockConfigLayer(baseResolved, null)), Layer.provide(http.layer));
|
|
232
|
+
const program = Effect.gen(function* () {
|
|
233
|
+
const auth = yield* Auth;
|
|
234
|
+
return yield* auth.requestDeviceCode('https://blog.example.com/api/v2/auth', 'mxs-cli');
|
|
235
|
+
}).pipe(Effect.flip);
|
|
236
|
+
const err = await Effect.runPromise(Effect.provide(program, layer));
|
|
237
|
+
expect(err._tag).toBe('AuthDenied');
|
|
238
|
+
});
|
|
239
|
+
itVitest('collapses non-generic transport errors to AuthDenied', async () => {
|
|
240
|
+
const layer = Auth.Default.pipe(Layer.provide(makeMockConfigLayer(baseResolved, null)), Layer.provide(failingHttpLayer({ code: 'ECONNREFUSED' })));
|
|
241
|
+
const program = Effect.gen(function* () {
|
|
242
|
+
const auth = yield* Auth;
|
|
243
|
+
return yield* auth.requestDeviceCode('https://blog.example.com/api/v2/auth', 'mxs-cli');
|
|
244
|
+
}).pipe(Effect.flip);
|
|
245
|
+
const err = await Effect.runPromise(Effect.provide(program, layer));
|
|
246
|
+
expect(err._tag).toBe('AuthDenied');
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
// ---------------------------------------------------------------------------
|
|
250
|
+
// pollDeviceToken
|
|
251
|
+
// ---------------------------------------------------------------------------
|
|
252
|
+
describe('Auth.pollDeviceToken', () => {
|
|
253
|
+
const makeLayer = () => Auth.Default.pipe(Layer.provide(makeMockConfigLayer(baseResolved, null)), Layer.provide(testHttpLayer({}).layer));
|
|
254
|
+
const poll = (opts = {}) => Effect.gen(function* () {
|
|
255
|
+
const auth = yield* Auth;
|
|
256
|
+
return yield* auth.pollDeviceToken('https://blog.example.com/api/v2/auth', 'mxs-cli', 'device-code', {
|
|
257
|
+
intervalSec: opts.intervalSec ?? 1,
|
|
258
|
+
expiresInSec: opts.expiresInSec ?? 60,
|
|
259
|
+
signal: opts.signal,
|
|
260
|
+
onTick: opts.onTick,
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
itVitest('returns a token after pending and slow_down responses', async () => {
|
|
264
|
+
vi.useFakeTimers();
|
|
265
|
+
const ticks = [];
|
|
266
|
+
const fetchSpy = vi
|
|
267
|
+
.spyOn(globalThis, 'fetch')
|
|
268
|
+
.mockResolvedValueOnce(new Response(JSON.stringify({ error: 'authorization_pending' }), {
|
|
269
|
+
status: 400,
|
|
270
|
+
headers: { 'content-type': 'application/json' },
|
|
271
|
+
}))
|
|
272
|
+
.mockResolvedValueOnce(new Response(JSON.stringify({ error: 'slow_down' }), {
|
|
273
|
+
status: 400,
|
|
274
|
+
headers: { 'content-type': 'application/json' },
|
|
275
|
+
}))
|
|
276
|
+
.mockResolvedValueOnce(new Response(JSON.stringify({
|
|
277
|
+
access_token: 'TOKEN',
|
|
278
|
+
token_type: 'Bearer',
|
|
279
|
+
expires_in: 3600,
|
|
280
|
+
}), {
|
|
281
|
+
status: 200,
|
|
282
|
+
headers: { 'content-type': 'application/json' },
|
|
283
|
+
}));
|
|
284
|
+
try {
|
|
285
|
+
const promise = Effect.runPromise(Effect.provide(poll({ onTick: (state) => ticks.push(state) }), makeLayer()));
|
|
286
|
+
await vi.advanceTimersByTimeAsync(1_000);
|
|
287
|
+
await vi.advanceTimersByTimeAsync(6_000);
|
|
288
|
+
await vi.advanceTimersByTimeAsync(6_000);
|
|
289
|
+
const res = await promise;
|
|
290
|
+
expect(res.access_token).toBe('TOKEN');
|
|
291
|
+
expect(ticks).toEqual(['pending', 'slow_down']);
|
|
292
|
+
const request = JSON.parse(String((fetchSpy.mock.calls[0]?.[1]).body));
|
|
293
|
+
expect(request).toMatchObject({
|
|
294
|
+
grant_type: 'urn:ietf:params:oauth:grant-type:device_code',
|
|
295
|
+
device_code: 'device-code',
|
|
296
|
+
client_id: 'mxs-cli',
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
finally {
|
|
300
|
+
fetchSpy.mockRestore();
|
|
301
|
+
vi.useRealTimers();
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
itVitest('maps access_denied to AuthDenied', async () => {
|
|
305
|
+
vi.useFakeTimers();
|
|
306
|
+
const fetchSpy = vi.spyOn(globalThis, 'fetch').mockResolvedValue(new Response(JSON.stringify({ error: 'access_denied' }), {
|
|
307
|
+
status: 400,
|
|
308
|
+
headers: { 'content-type': 'application/json' },
|
|
309
|
+
}));
|
|
310
|
+
try {
|
|
311
|
+
const promise = Effect.runPromise(Effect.flip(Effect.provide(poll(), makeLayer())));
|
|
312
|
+
await vi.advanceTimersByTimeAsync(1_000);
|
|
313
|
+
const err = await promise;
|
|
314
|
+
expect(err._tag).toBe('AuthDenied');
|
|
315
|
+
}
|
|
316
|
+
finally {
|
|
317
|
+
fetchSpy.mockRestore();
|
|
318
|
+
vi.useRealTimers();
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
itVitest('maps expired_token and elapsed deadline to AuthExpired', async () => {
|
|
322
|
+
vi.useFakeTimers();
|
|
323
|
+
const fetchSpy = vi.spyOn(globalThis, 'fetch').mockResolvedValue(new Response(JSON.stringify({ error: 'expired_token' }), {
|
|
324
|
+
status: 400,
|
|
325
|
+
headers: { 'content-type': 'application/json' },
|
|
326
|
+
}));
|
|
327
|
+
try {
|
|
328
|
+
const tokenPromise = Effect.runPromise(Effect.flip(Effect.provide(poll(), makeLayer())));
|
|
329
|
+
await vi.advanceTimersByTimeAsync(1_000);
|
|
330
|
+
const tokenErr = await tokenPromise;
|
|
331
|
+
expect(tokenErr._tag).toBe('AuthExpired');
|
|
332
|
+
const timeoutErr = await Effect.runPromise(Effect.flip(Effect.provide(poll({ expiresInSec: 0 }), makeLayer())));
|
|
333
|
+
expect(timeoutErr._tag).toBe('AuthExpired');
|
|
334
|
+
}
|
|
335
|
+
finally {
|
|
336
|
+
fetchSpy.mockRestore();
|
|
337
|
+
vi.useRealTimers();
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
itVitest('maps unknown device-token responses and abort signals', async () => {
|
|
341
|
+
vi.useFakeTimers();
|
|
342
|
+
const fetchSpy = vi.spyOn(globalThis, 'fetch').mockResolvedValue(new Response(JSON.stringify({ error: 'server_error' }), {
|
|
343
|
+
status: 500,
|
|
344
|
+
headers: { 'content-type': 'application/json' },
|
|
345
|
+
}));
|
|
346
|
+
try {
|
|
347
|
+
const unknownPromise = Effect.runPromise(Effect.flip(Effect.provide(poll(), makeLayer())));
|
|
348
|
+
await vi.advanceTimersByTimeAsync(1_000);
|
|
349
|
+
const unknownErr = await unknownPromise;
|
|
350
|
+
expect(unknownErr._tag).toBe('AuthDenied');
|
|
351
|
+
const controller = new AbortController();
|
|
352
|
+
controller.abort();
|
|
353
|
+
const abortErr = await Effect.runPromise(Effect.flip(Effect.provide(poll({ signal: controller.signal }), makeLayer())));
|
|
354
|
+
expect(abortErr._tag).toBe('AuthDenied');
|
|
355
|
+
}
|
|
356
|
+
finally {
|
|
357
|
+
fetchSpy.mockRestore();
|
|
358
|
+
vi.useRealTimers();
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
itVitest('wraps fetch failures as Generic', async () => {
|
|
362
|
+
vi.useFakeTimers();
|
|
363
|
+
const fetchSpy = vi
|
|
364
|
+
.spyOn(globalThis, 'fetch')
|
|
365
|
+
.mockRejectedValue(new Error('network down'));
|
|
366
|
+
try {
|
|
367
|
+
const promise = Effect.runPromise(Effect.flip(Effect.provide(poll(), makeLayer())));
|
|
368
|
+
await vi.advanceTimersByTimeAsync(1_000);
|
|
369
|
+
const err = await promise;
|
|
370
|
+
expect(err._tag).toBe('Generic');
|
|
371
|
+
}
|
|
372
|
+
finally {
|
|
373
|
+
fetchSpy.mockRestore();
|
|
374
|
+
vi.useRealTimers();
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
});
|
|
378
|
+
// ---------------------------------------------------------------------------
|
|
379
|
+
// ensureFresh
|
|
380
|
+
// ---------------------------------------------------------------------------
|
|
381
|
+
describe('Auth.ensureFresh', () => {
|
|
382
|
+
itVitest('returns existing credentials when not near expiry', async () => {
|
|
383
|
+
const cred = {
|
|
384
|
+
access_token: 'TOK',
|
|
385
|
+
expires_at: Date.now() + 10 * 60_000,
|
|
386
|
+
};
|
|
387
|
+
const http = testHttpLayer({});
|
|
388
|
+
const layer = Auth.Default.pipe(Layer.provide(makeMockConfigLayer(baseResolved, cred)), Layer.provide(http.layer));
|
|
389
|
+
const program = Effect.gen(function* () {
|
|
390
|
+
const auth = yield* Auth;
|
|
391
|
+
return yield* auth.ensureFresh(baseResolved);
|
|
392
|
+
});
|
|
393
|
+
const res = await Effect.runPromise(Effect.provide(program, layer));
|
|
394
|
+
expect(res.access_token).toBe('TOK');
|
|
395
|
+
});
|
|
396
|
+
itVitest('fails AuthMissing when no credentials stored', async () => {
|
|
397
|
+
const http = testHttpLayer({});
|
|
398
|
+
const layer = Auth.Default.pipe(Layer.provide(makeMockConfigLayer(baseResolved, null)), Layer.provide(http.layer));
|
|
399
|
+
const program = Effect.gen(function* () {
|
|
400
|
+
const auth = yield* Auth;
|
|
401
|
+
return yield* auth.ensureFresh(baseResolved);
|
|
402
|
+
}).pipe(Effect.flip);
|
|
403
|
+
const err = await Effect.runPromise(Effect.provide(program, layer));
|
|
404
|
+
expect(err._tag).toBe('AuthMissing');
|
|
405
|
+
});
|
|
406
|
+
itVitest('fails AuthMissing when no profile is resolved', async () => {
|
|
407
|
+
const http = testHttpLayer({});
|
|
408
|
+
const layer = Auth.Default.pipe(Layer.provide(makeMockConfigLayer({ ...baseResolved, profileName: null }, null)), Layer.provide(http.layer));
|
|
409
|
+
const err = await Effect.runPromise(Effect.flip(Effect.provide(Effect.gen(function* () {
|
|
410
|
+
const auth = yield* Auth;
|
|
411
|
+
return yield* auth.ensureFresh({ ...baseResolved, profileName: null });
|
|
412
|
+
}), layer)));
|
|
413
|
+
expect(err._tag).toBe('AuthMissing');
|
|
414
|
+
});
|
|
415
|
+
itVitest('refreshes via refresh_token grant and writes back', async () => {
|
|
416
|
+
const cred = {
|
|
417
|
+
access_token: 'OLD',
|
|
418
|
+
refresh_token: 'rt',
|
|
419
|
+
expires_at: Date.now() + 1_000, // within buffer → triggers refresh
|
|
420
|
+
};
|
|
421
|
+
const writes = { last: null };
|
|
422
|
+
const fetchSpy = vi
|
|
423
|
+
.spyOn(globalThis, 'fetch')
|
|
424
|
+
.mockImplementation(async (url) => {
|
|
425
|
+
if (String(url).endsWith('/auth/token')) {
|
|
426
|
+
return new Response(JSON.stringify({
|
|
427
|
+
access_token: 'NEW',
|
|
428
|
+
token_type: 'Bearer',
|
|
429
|
+
expires_in: 3600,
|
|
430
|
+
}), {
|
|
431
|
+
status: 200,
|
|
432
|
+
headers: { 'content-type': 'application/json' },
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
return new Response('not found', { status: 404 });
|
|
436
|
+
});
|
|
437
|
+
try {
|
|
438
|
+
const http = testHttpLayer({});
|
|
439
|
+
const layer = Auth.Default.pipe(Layer.provide(makeMockConfigLayer(baseResolved, cred, writes)), Layer.provide(http.layer));
|
|
440
|
+
const program = Effect.gen(function* () {
|
|
441
|
+
const auth = yield* Auth;
|
|
442
|
+
return yield* auth.ensureFresh(baseResolved);
|
|
443
|
+
});
|
|
444
|
+
const res = await Effect.runPromise(Effect.provide(program, layer));
|
|
445
|
+
expect(res.access_token).toBe('NEW');
|
|
446
|
+
expect(writes.last?.access_token).toBe('NEW');
|
|
447
|
+
}
|
|
448
|
+
finally {
|
|
449
|
+
fetchSpy.mockRestore();
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
itVitest('keeps existing credentials when refresh returns null', async () => {
|
|
453
|
+
const cred = {
|
|
454
|
+
access_token: 'OLD',
|
|
455
|
+
refresh_token: 'rt',
|
|
456
|
+
expires_at: Date.now() + 1_000,
|
|
457
|
+
};
|
|
458
|
+
const writes = { last: null };
|
|
459
|
+
const fetchSpy = vi.spyOn(globalThis, 'fetch').mockResolvedValue(new Response(JSON.stringify({ error: 'invalid_grant' }), {
|
|
460
|
+
status: 400,
|
|
461
|
+
headers: { 'content-type': 'application/json' },
|
|
462
|
+
}));
|
|
463
|
+
try {
|
|
464
|
+
const http = testHttpLayer({});
|
|
465
|
+
const layer = Auth.Default.pipe(Layer.provide(makeMockConfigLayer(baseResolved, cred, writes)), Layer.provide(http.layer));
|
|
466
|
+
const program = Effect.gen(function* () {
|
|
467
|
+
const auth = yield* Auth;
|
|
468
|
+
return yield* auth.ensureFresh(baseResolved);
|
|
469
|
+
});
|
|
470
|
+
const res = await Effect.runPromise(Effect.provide(program, layer));
|
|
471
|
+
expect(res.access_token).toBe('OLD');
|
|
472
|
+
expect(writes.last).toBeNull();
|
|
473
|
+
}
|
|
474
|
+
finally {
|
|
475
|
+
fetchSpy.mockRestore();
|
|
476
|
+
}
|
|
477
|
+
});
|
|
478
|
+
itVitest('refreshes session-token credentials through get-session', async () => {
|
|
479
|
+
const cred = {
|
|
480
|
+
access_token: 'OLD',
|
|
481
|
+
expires_at: Date.now() + 1_000,
|
|
482
|
+
user: { id: 'old' },
|
|
483
|
+
};
|
|
484
|
+
const writes = { last: null };
|
|
485
|
+
const fetchSpy = vi.spyOn(globalThis, 'fetch').mockResolvedValue(new Response(JSON.stringify({
|
|
486
|
+
session: { expiresAt: Date.now() + 3600_000 },
|
|
487
|
+
user: { id: 'new' },
|
|
488
|
+
}), {
|
|
489
|
+
status: 200,
|
|
490
|
+
headers: {
|
|
491
|
+
'content-type': 'application/json',
|
|
492
|
+
'set-auth-token': 'NEW',
|
|
493
|
+
},
|
|
494
|
+
}));
|
|
495
|
+
try {
|
|
496
|
+
const http = testHttpLayer({});
|
|
497
|
+
const layer = Auth.Default.pipe(Layer.provide(makeMockConfigLayer(baseResolved, cred, writes)), Layer.provide(http.layer));
|
|
498
|
+
const program = Effect.gen(function* () {
|
|
499
|
+
const auth = yield* Auth;
|
|
500
|
+
return yield* auth.ensureFresh(baseResolved);
|
|
501
|
+
});
|
|
502
|
+
const res = await Effect.runPromise(Effect.provide(program, layer));
|
|
503
|
+
expect(res.access_token).toBe('NEW');
|
|
504
|
+
expect(res.user?.id).toBe('new');
|
|
505
|
+
expect(writes.last?.access_token).toBe('NEW');
|
|
506
|
+
}
|
|
507
|
+
finally {
|
|
508
|
+
fetchSpy.mockRestore();
|
|
509
|
+
}
|
|
510
|
+
});
|
|
511
|
+
itVitest('keeps session-token credentials when get-session cannot extend expiry', async () => {
|
|
512
|
+
const cred = {
|
|
513
|
+
access_token: 'OLD',
|
|
514
|
+
expires_at: Date.now() + 1_000,
|
|
515
|
+
user: { id: 'old' },
|
|
516
|
+
};
|
|
517
|
+
const writes = { last: null };
|
|
518
|
+
const responses = [
|
|
519
|
+
new Response(JSON.stringify({ session: { expiresAt: 'bad-date' } }), {
|
|
520
|
+
status: 200,
|
|
521
|
+
headers: { 'content-type': 'application/json' },
|
|
522
|
+
}),
|
|
523
|
+
new Response(JSON.stringify({ session: { expiresAt: Date.now() } }), {
|
|
524
|
+
status: 200,
|
|
525
|
+
headers: { 'content-type': 'application/json' },
|
|
526
|
+
}),
|
|
527
|
+
new Response(JSON.stringify({}), {
|
|
528
|
+
status: 401,
|
|
529
|
+
headers: { 'content-type': 'application/json' },
|
|
530
|
+
}),
|
|
531
|
+
];
|
|
532
|
+
const fetchSpy = vi
|
|
533
|
+
.spyOn(globalThis, 'fetch')
|
|
534
|
+
.mockImplementation(async () => responses.shift());
|
|
535
|
+
try {
|
|
536
|
+
const http = testHttpLayer({});
|
|
537
|
+
const layer = Auth.Default.pipe(Layer.provide(makeMockConfigLayer(baseResolved, cred, writes)), Layer.provide(http.layer));
|
|
538
|
+
const program = Effect.gen(function* () {
|
|
539
|
+
const auth = yield* Auth;
|
|
540
|
+
return yield* auth.ensureFresh(baseResolved);
|
|
541
|
+
});
|
|
542
|
+
await expect(Effect.runPromise(Effect.provide(program, layer))).resolves.toMatchObject({ access_token: 'OLD' });
|
|
543
|
+
await expect(Effect.runPromise(Effect.provide(program, layer))).resolves.toMatchObject({ access_token: 'OLD' });
|
|
544
|
+
await expect(Effect.runPromise(Effect.provide(program, layer))).resolves.toMatchObject({ access_token: 'OLD' });
|
|
545
|
+
expect(writes.last).toBeNull();
|
|
546
|
+
}
|
|
547
|
+
finally {
|
|
548
|
+
fetchSpy.mockRestore();
|
|
549
|
+
}
|
|
550
|
+
});
|
|
551
|
+
});
|
|
552
|
+
// ---------------------------------------------------------------------------
|
|
553
|
+
// whoami / status / login
|
|
554
|
+
// ---------------------------------------------------------------------------
|
|
555
|
+
describe('Auth user-facing summaries', () => {
|
|
556
|
+
itVitest('whoami returns the refreshed credential user', async () => {
|
|
557
|
+
const cred = {
|
|
558
|
+
access_token: 'TOK',
|
|
559
|
+
expires_at: Date.now() + 3600_000,
|
|
560
|
+
user: { id: 'u1', email: 'owner@example.com', name: 'Owner' },
|
|
561
|
+
};
|
|
562
|
+
const layer = Auth.Default.pipe(Layer.provide(makeMockConfigLayer(baseResolved, cred)), Layer.provide(testHttpLayer({}).layer));
|
|
563
|
+
const program = Effect.gen(function* () {
|
|
564
|
+
const auth = yield* Auth;
|
|
565
|
+
return yield* auth.whoami;
|
|
566
|
+
});
|
|
567
|
+
const res = await Effect.runPromise(Effect.provide(program, layer));
|
|
568
|
+
expect(res).toMatchObject({
|
|
569
|
+
id: 'u1',
|
|
570
|
+
email: 'owner@example.com',
|
|
571
|
+
name: 'Owner',
|
|
572
|
+
});
|
|
573
|
+
});
|
|
574
|
+
itVitest('status reports missing profile, missing credentials, and user summary', async () => {
|
|
575
|
+
const http = testHttpLayer({});
|
|
576
|
+
const noProfileLayer = Auth.Default.pipe(Layer.provide(makeMockConfigLayer({ ...baseResolved, profileName: null }, null)), Layer.provide(http.layer));
|
|
577
|
+
const missingCredLayer = Auth.Default.pipe(Layer.provide(makeMockConfigLayer(baseResolved, null)), Layer.provide(http.layer));
|
|
578
|
+
const authedLayer = Auth.Default.pipe(Layer.provide(makeMockConfigLayer(baseResolved, {
|
|
579
|
+
access_token: 'TOK',
|
|
580
|
+
expires_at: 123,
|
|
581
|
+
user: { id: 'u1' },
|
|
582
|
+
})), Layer.provide(http.layer));
|
|
583
|
+
const readStatus = Effect.gen(function* () {
|
|
584
|
+
const auth = yield* Auth;
|
|
585
|
+
return yield* auth.status;
|
|
586
|
+
});
|
|
587
|
+
expect(await Effect.runPromise(Effect.provide(readStatus, noProfileLayer))).toMatchObject({ authenticated: false, profile: null });
|
|
588
|
+
expect(await Effect.runPromise(Effect.provide(readStatus, missingCredLayer))).toMatchObject({ authenticated: false, profile: 'prod' });
|
|
589
|
+
expect(await Effect.runPromise(Effect.provide(readStatus, authedLayer))).toMatchObject({
|
|
590
|
+
authenticated: true,
|
|
591
|
+
profile: 'prod',
|
|
592
|
+
expiresAt: 123,
|
|
593
|
+
user: { id: 'u1', expiresAt: 123 },
|
|
594
|
+
});
|
|
595
|
+
});
|
|
596
|
+
itVitest('login placeholder fails with Generic', async () => {
|
|
597
|
+
const layer = Auth.Default.pipe(Layer.provide(makeMockConfigLayer(baseResolved, null)), Layer.provide(testHttpLayer({}).layer));
|
|
598
|
+
const err = await Effect.runPromise(Effect.flip(Effect.provide(Effect.gen(function* () {
|
|
599
|
+
const auth = yield* Auth;
|
|
600
|
+
return yield* auth.login({});
|
|
601
|
+
}), layer)));
|
|
602
|
+
expect(err._tag).toBe('Generic');
|
|
603
|
+
});
|
|
604
|
+
itVitest('whoami and status wrap config resolution failures as Generic', async () => {
|
|
605
|
+
const layer = Auth.Default.pipe(Layer.provide(makeMockConfigLayer(baseResolved, null, undefined, undefined, () => Effect.fail(new Generic({ message: 'resolve failed' })))), Layer.provide(testHttpLayer({}).layer));
|
|
606
|
+
const whoamiErr = await Effect.runPromise(Effect.flip(Effect.provide(Effect.gen(function* () {
|
|
607
|
+
const auth = yield* Auth;
|
|
608
|
+
return yield* auth.whoami;
|
|
609
|
+
}), layer)));
|
|
610
|
+
const statusErr = await Effect.runPromise(Effect.flip(Effect.provide(Effect.gen(function* () {
|
|
611
|
+
const auth = yield* Auth;
|
|
612
|
+
return yield* auth.status;
|
|
613
|
+
}), layer)));
|
|
614
|
+
expect(whoamiErr._tag).toBe('Generic');
|
|
615
|
+
expect(statusErr._tag).toBe('Generic');
|
|
616
|
+
});
|
|
617
|
+
});
|
|
618
|
+
// ---------------------------------------------------------------------------
|
|
619
|
+
// logout
|
|
620
|
+
// ---------------------------------------------------------------------------
|
|
621
|
+
describe('Auth.logout', () => {
|
|
622
|
+
itVitest('delegates to Config.deleteProfileCredentials', async () => {
|
|
623
|
+
const deletes = { invokedFor: null };
|
|
624
|
+
const http = testHttpLayer({});
|
|
625
|
+
const layer = Auth.Default.pipe(Layer.provide(makeMockConfigLayer(baseResolved, null, undefined, deletes)), Layer.provide(http.layer));
|
|
626
|
+
const program = Effect.gen(function* () {
|
|
627
|
+
const auth = yield* Auth;
|
|
628
|
+
yield* auth.logout('prod');
|
|
629
|
+
});
|
|
630
|
+
await Effect.runPromise(Effect.provide(program, layer));
|
|
631
|
+
expect(deletes.invokedFor).toBe('prod');
|
|
632
|
+
});
|
|
633
|
+
itVitest('resolves the active profile when logout target is null and no-ops when unresolved', async () => {
|
|
634
|
+
const deletes = { invokedFor: null };
|
|
635
|
+
const http = testHttpLayer({});
|
|
636
|
+
const layer = Auth.Default.pipe(Layer.provide(makeMockConfigLayer(baseResolved, null, undefined, deletes)), Layer.provide(http.layer));
|
|
637
|
+
await Effect.runPromise(Effect.provide(Effect.gen(function* () {
|
|
638
|
+
const auth = yield* Auth;
|
|
639
|
+
yield* auth.logout(null);
|
|
640
|
+
}), layer));
|
|
641
|
+
expect(deletes.invokedFor).toBe('prod');
|
|
642
|
+
const noTargetLayer = Auth.Default.pipe(Layer.provide(makeMockConfigLayer({ ...baseResolved, profileName: null }, null, undefined, deletes)), Layer.provide(http.layer));
|
|
643
|
+
deletes.invokedFor = null;
|
|
644
|
+
await Effect.runPromise(Effect.provide(Effect.gen(function* () {
|
|
645
|
+
const auth = yield* Auth;
|
|
646
|
+
yield* auth.logout(null);
|
|
647
|
+
}), noTargetLayer));
|
|
648
|
+
expect(deletes.invokedFor).toBeNull();
|
|
649
|
+
});
|
|
650
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|