@crowi/api 2.0.0-alpha.1 → 2.0.0-alpha.3
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/dist/collab/attach.d.ts +34 -10
- package/dist/collab/attach.js +77 -1
- package/dist/collab/attach.js.map +1 -1
- package/dist/crowi/index.js +7 -6
- package/dist/crowi/index.js.map +1 -1
- package/dist/hono/handlers/activation.d.ts +3 -3
- package/dist/hono/handlers/admin/users.d.ts +118 -0
- package/dist/hono/handlers/admin/users.js +28 -0
- package/dist/hono/handlers/admin/users.js.map +1 -1
- package/dist/hono/handlers/app.d.ts +1 -0
- package/dist/hono/handlers/app.js +11 -0
- package/dist/hono/handlers/app.js.map +1 -1
- package/dist/hono/handlers/attachment-stream.js +23 -0
- package/dist/hono/handlers/attachment-stream.js.map +1 -1
- package/dist/hono/handlers/draft.js +10 -0
- package/dist/hono/handlers/draft.js.map +1 -1
- package/dist/hono/handlers/emailChange.d.ts +4 -4
- package/dist/hono/handlers/inviteAccept.d.ts +6 -6
- package/dist/hono/handlers/page-collab.js +4 -0
- package/dist/hono/handlers/page-collab.js.map +1 -1
- package/dist/hono/handlers/page.d.ts +251 -0
- package/dist/hono/handlers/page.js +123 -6
- package/dist/hono/handlers/page.js.map +1 -1
- package/dist/hono/handlers/passwordReset.d.ts +5 -5
- package/dist/hono/handlers/tokenAuth.d.ts +7 -7
- package/dist/mcp/result.d.ts +42 -16
- package/dist/mcp/result.js +56 -10
- package/dist/mcp/result.js.map +1 -1
- package/dist/mcp/tools/page.js +21 -1
- package/dist/mcp/tools/page.js.map +1 -1
- package/dist/mcp/tools/search.d.ts +12 -0
- package/dist/mcp/tools/search.js +21 -5
- package/dist/mcp/tools/search.js.map +1 -1
- package/dist/migration/cli-api.d.ts +8 -1
- package/dist/migration/cli-api.js +2 -0
- package/dist/migration/cli-api.js.map +1 -1
- package/dist/migration/helpers.d.ts +13 -0
- package/dist/migration/helpers.js +29 -0
- package/dist/migration/helpers.js.map +1 -0
- package/dist/migration/migrations/code-mask.d.ts +76 -0
- package/dist/migration/migrations/code-mask.js +224 -0
- package/dist/migration/migrations/code-mask.js.map +1 -0
- package/dist/migration/migrations/files-url-to-attachments.d.ts +99 -0
- package/dist/migration/migrations/files-url-to-attachments.js +305 -0
- package/dist/migration/migrations/files-url-to-attachments.js.map +1 -0
- package/dist/migration/migrations/index.js +4 -0
- package/dist/migration/migrations/index.js.map +1 -1
- package/dist/migration/migrations/page-status-default.d.ts +31 -1
- package/dist/migration/migrations/published-current-revision.d.ts +47 -0
- package/dist/migration/migrations/published-current-revision.js +90 -0
- package/dist/migration/migrations/published-current-revision.js.map +1 -0
- package/dist/migration/migrations/relocate-reserved-api-paths.d.ts +37 -1
- package/dist/migration/migrations/relocate-reserved-api-paths.js +11 -3
- package/dist/migration/migrations/relocate-reserved-api-paths.js.map +1 -1
- package/dist/migration/migrations/revisions-schema-unify.d.ts +35 -1
- package/dist/migration/migrations/user-unique-prepare.d.ts +55 -1
- package/dist/migration/migrations/user-unique-prepare.js +5 -0
- package/dist/migration/migrations/user-unique-prepare.js.map +1 -1
- package/dist/migration/migrations/wikilink-format.d.ts +75 -12
- package/dist/migration/migrations/wikilink-format.js +23 -157
- package/dist/migration/migrations/wikilink-format.js.map +1 -1
- package/dist/migration/migrations/wikilink-html-recover.d.ts +191 -0
- package/dist/migration/migrations/wikilink-html-recover.js +340 -0
- package/dist/migration/migrations/wikilink-html-recover.js.map +1 -0
- package/dist/migration/registry.d.ts +8 -2
- package/dist/migration/registry.js +5 -1
- package/dist/migration/registry.js.map +1 -1
- package/dist/migration/run-boot-migrations.d.ts +4 -1
- package/dist/migration/run-boot-migrations.js +55 -23
- package/dist/migration/run-boot-migrations.js.map +1 -1
- package/dist/migration/runner.js +8 -1
- package/dist/migration/runner.js.map +1 -1
- package/dist/migration/types.d.ts +57 -5
- package/dist/migration/types.js.map +1 -1
- package/dist/models/page.d.ts +23 -3
- package/dist/models/page.js +91 -5
- package/dist/models/page.js.map +1 -1
- package/dist/models/user.d.ts +1 -0
- package/dist/models/user.js +40 -21
- package/dist/models/user.js.map +1 -1
- package/dist/plugin/plugin-manager.js +1 -1
- package/dist/renderer/core/headings.d.ts +12 -1
- package/dist/renderer/core/headings.js +48 -8
- package/dist/renderer/core/headings.js.map +1 -1
- package/dist/renderer/pipeline.d.ts +6 -0
- package/dist/renderer/pipeline.js.map +1 -1
- package/dist/renderer/registry.js +1 -1
- package/dist/util/page-response.js +19 -2
- package/dist/util/page-response.js.map +1 -1
- package/dist/util/ws-token.d.ts +13 -0
- package/dist/util/ws-token.js +43 -3
- package/dist/util/ws-token.js.map +1 -1
- package/package.json +13 -7
- package/views/mail/layout.mjml +7 -5
- package/dist/common/functions/path2name.d.ts +0 -1
- package/dist/common/functions/path2name.js +0 -22
- package/dist/common/functions/path2name.js.map +0 -1
- package/dist/common/functions/renderIcon.d.ts +0 -1
- package/dist/common/functions/renderIcon.js +0 -9
- package/dist/common/functions/renderIcon.js.map +0 -1
- package/dist/controllers/admin.d.ts +0 -3
- package/dist/controllers/admin.js +0 -474
- package/dist/controllers/admin.js.map +0 -1
- package/dist/controllers/attachment.d.ts +0 -4
- package/dist/controllers/attachment.js +0 -200
- package/dist/controllers/attachment.js.map +0 -1
- package/dist/controllers/backlink.d.ts +0 -3
- package/dist/controllers/backlink.js +0 -42
- package/dist/controllers/backlink.js.map +0 -1
- package/dist/controllers/bookmark.d.ts +0 -3
- package/dist/controllers/bookmark.js +0 -100
- package/dist/controllers/bookmark.js.map +0 -1
- package/dist/controllers/comment.d.ts +0 -3
- package/dist/controllers/comment.js +0 -111
- package/dist/controllers/comment.js.map +0 -1
- package/dist/controllers/index.d.ts +0 -25
- package/dist/controllers/index.js +0 -44
- package/dist/controllers/index.js.map +0 -1
- package/dist/controllers/installer.d.ts +0 -3
- package/dist/controllers/installer.js +0 -48
- package/dist/controllers/installer.js.map +0 -1
- package/dist/controllers/login.d.ts +0 -4
- package/dist/controllers/login.js +0 -438
- package/dist/controllers/login.js.map +0 -1
- package/dist/controllers/logout.d.ts +0 -5
- package/dist/controllers/logout.js +0 -11
- package/dist/controllers/logout.js.map +0 -1
- package/dist/controllers/me.d.ts +0 -4
- package/dist/controllers/me.js +0 -369
- package/dist/controllers/me.js.map +0 -1
- package/dist/controllers/notification.d.ts +0 -3
- package/dist/controllers/notification.js +0 -88
- package/dist/controllers/notification.js.map +0 -1
- package/dist/controllers/page.d.ts +0 -3
- package/dist/controllers/page.js +0 -881
- package/dist/controllers/page.js.map +0 -1
- package/dist/controllers/revision.d.ts +0 -3
- package/dist/controllers/revision.js +0 -91
- package/dist/controllers/revision.js.map +0 -1
- package/dist/controllers/search.d.ts +0 -3
- package/dist/controllers/search.js +0 -93
- package/dist/controllers/search.js.map +0 -1
- package/dist/controllers/share.d.ts +0 -3
- package/dist/controllers/share.js +0 -207
- package/dist/controllers/share.js.map +0 -1
- package/dist/controllers/shareAccess.d.ts +0 -3
- package/dist/controllers/shareAccess.js +0 -28
- package/dist/controllers/shareAccess.js.map +0 -1
- package/dist/controllers/slack.d.ts +0 -3
- package/dist/controllers/slack.js +0 -87
- package/dist/controllers/slack.js.map +0 -1
- package/dist/controllers/tokenAuth.d.ts +0 -10
- package/dist/controllers/tokenAuth.js +0 -292
- package/dist/controllers/tokenAuth.js.map +0 -1
- package/dist/controllers/user.d.ts +0 -3
- package/dist/controllers/user.js +0 -67
- package/dist/controllers/user.js.map +0 -1
- package/dist/controllers/version.d.ts +0 -4
- package/dist/controllers/version.js +0 -19
- package/dist/controllers/version.js.map +0 -1
- package/dist/crowi/express-init.d.ts +0 -4
- package/dist/crowi/express-init.js +0 -101
- package/dist/crowi/express-init.js.map +0 -1
- package/dist/form/admin/app.d.ts +0 -2
- package/dist/form/admin/app.js +0 -9
- package/dist/form/admin/app.js.map +0 -1
- package/dist/form/admin/auth.d.ts +0 -2
- package/dist/form/admin/auth.js +0 -9
- package/dist/form/admin/auth.js.map +0 -1
- package/dist/form/admin/aws.d.ts +0 -2
- package/dist/form/admin/aws.js +0 -13
- package/dist/form/admin/aws.js.map +0 -1
- package/dist/form/admin/github.d.ts +0 -2
- package/dist/form/admin/github.js +0 -15
- package/dist/form/admin/github.js.map +0 -1
- package/dist/form/admin/google.d.ts +0 -2
- package/dist/form/admin/google.js +0 -13
- package/dist/form/admin/google.js.map +0 -1
- package/dist/form/admin/mail.d.ts +0 -2
- package/dist/form/admin/mail.js +0 -13
- package/dist/form/admin/mail.js.map +0 -1
- package/dist/form/admin/sec.d.ts +0 -2
- package/dist/form/admin/sec.js +0 -10
- package/dist/form/admin/sec.js.map +0 -1
- package/dist/form/admin/slackSetting.d.ts +0 -2
- package/dist/form/admin/slackSetting.js +0 -13
- package/dist/form/admin/slackSetting.js.map +0 -1
- package/dist/form/admin/userEdit.d.ts +0 -2
- package/dist/form/admin/userEdit.js +0 -9
- package/dist/form/admin/userEdit.js.map +0 -1
- package/dist/form/admin/userInvite.d.ts +0 -2
- package/dist/form/admin/userInvite.js +0 -9
- package/dist/form/admin/userInvite.js.map +0 -1
- package/dist/form/comment.d.ts +0 -2
- package/dist/form/comment.js +0 -9
- package/dist/form/comment.js.map +0 -1
- package/dist/form/index.d.ts +0 -25
- package/dist/form/index.js +0 -48
- package/dist/form/index.js.map +0 -1
- package/dist/form/invited.d.ts +0 -2
- package/dist/form/invited.js +0 -13
- package/dist/form/invited.js.map +0 -1
- package/dist/form/login.d.ts +0 -2
- package/dist/form/login.js +0 -11
- package/dist/form/login.js.map +0 -1
- package/dist/form/me/apiToken.d.ts +0 -2
- package/dist/form/me/apiToken.js +0 -9
- package/dist/form/me/apiToken.js.map +0 -1
- package/dist/form/me/password.d.ts +0 -2
- package/dist/form/me/password.js +0 -11
- package/dist/form/me/password.js.map +0 -1
- package/dist/form/me/user.d.ts +0 -2
- package/dist/form/me/user.js +0 -9
- package/dist/form/me/user.js.map +0 -1
- package/dist/form/register.d.ts +0 -2
- package/dist/form/register.js +0 -13
- package/dist/form/register.js.map +0 -1
- package/dist/form/revision.d.ts +0 -2
- package/dist/form/revision.js +0 -13
- package/dist/form/revision.js.map +0 -1
- package/dist/hono/handlers/admin/share.d.ts +0 -106
- package/dist/hono/handlers/admin/share.js +0 -55
- package/dist/hono/handlers/admin/share.js.map +0 -1
- package/dist/middlewares/accessTokenParser.d.ts +0 -4
- package/dist/middlewares/accessTokenParser.js +0 -29
- package/dist/middlewares/accessTokenParser.js.map +0 -1
- package/dist/middlewares/adminRequired.d.ts +0 -10
- package/dist/middlewares/adminRequired.js +0 -35
- package/dist/middlewares/adminRequired.js.map +0 -1
- package/dist/middlewares/applicationInstalled.d.ts +0 -3
- package/dist/middlewares/applicationInstalled.js +0 -20
- package/dist/middlewares/applicationInstalled.js.map +0 -1
- package/dist/middlewares/applicationNotInstalled.d.ts +0 -3
- package/dist/middlewares/applicationNotInstalled.js +0 -13
- package/dist/middlewares/applicationNotInstalled.js.map +0 -1
- package/dist/middlewares/basicAuth.d.ts +0 -4
- package/dist/middlewares/basicAuth.js +0 -23
- package/dist/middlewares/basicAuth.js.map +0 -1
- package/dist/middlewares/csrfVerify.d.ts +0 -4
- package/dist/middlewares/csrfVerify.js +0 -24
- package/dist/middlewares/csrfVerify.js.map +0 -1
- package/dist/middlewares/encodeSpace.d.ts +0 -3
- package/dist/middlewares/encodeSpace.js +0 -14
- package/dist/middlewares/encodeSpace.js.map +0 -1
- package/dist/middlewares/fileAccessRightOrLoginRequired.d.ts +0 -4
- package/dist/middlewares/fileAccessRightOrLoginRequired.js +0 -29
- package/dist/middlewares/fileAccessRightOrLoginRequired.js.map +0 -1
- package/dist/middlewares/index.d.ts +0 -16
- package/dist/middlewares/index.js +0 -30
- package/dist/middlewares/index.js.map +0 -1
- package/dist/middlewares/jwtAdminRequired.d.ts +0 -8
- package/dist/middlewares/jwtAdminRequired.js +0 -35
- package/dist/middlewares/jwtAdminRequired.js.map +0 -1
- package/dist/middlewares/jwtAuth.d.ts +0 -4
- package/dist/middlewares/jwtAuth.js +0 -104
- package/dist/middlewares/jwtAuth.js.map +0 -1
- package/dist/middlewares/loginChecker.d.ts +0 -4
- package/dist/middlewares/loginChecker.js +0 -32
- package/dist/middlewares/loginChecker.js.map +0 -1
- package/dist/middlewares/loginRequired.d.ts +0 -4
- package/dist/middlewares/loginRequired.js +0 -88
- package/dist/middlewares/loginRequired.js.map +0 -1
- package/dist/routes/admin.d.ts +0 -4
- package/dist/routes/admin.js +0 -17
- package/dist/routes/admin.js.map +0 -1
- package/dist/routes/api/admin.d.ts +0 -4
- package/dist/routes/api/admin.js +0 -37
- package/dist/routes/api/admin.js.map +0 -1
- package/dist/routes/api/attachment.d.ts +0 -4
- package/dist/routes/api/attachment.js +0 -19
- package/dist/routes/api/attachment.js.map +0 -1
- package/dist/routes/api/bookmark.d.ts +0 -4
- package/dist/routes/api/bookmark.js +0 -15
- package/dist/routes/api/bookmark.js.map +0 -1
- package/dist/routes/api/comment.d.ts +0 -4
- package/dist/routes/api/comment.js +0 -14
- package/dist/routes/api/comment.js.map +0 -1
- package/dist/routes/api/index.d.ts +0 -4
- package/dist/routes/api/index.js +0 -36
- package/dist/routes/api/index.js.map +0 -1
- package/dist/routes/api/like.d.ts +0 -4
- package/dist/routes/api/like.js +0 -13
- package/dist/routes/api/like.js.map +0 -1
- package/dist/routes/api/notification.d.ts +0 -4
- package/dist/routes/api/notification.js +0 -15
- package/dist/routes/api/notification.js.map +0 -1
- package/dist/routes/api/page.d.ts +0 -4
- package/dist/routes/api/page.js +0 -24
- package/dist/routes/api/page.js.map +0 -1
- package/dist/routes/api/revision.d.ts +0 -4
- package/dist/routes/api/revision.js +0 -14
- package/dist/routes/api/revision.js.map +0 -1
- package/dist/routes/api/share.d.ts +0 -4
- package/dist/routes/api/share.js +0 -16
- package/dist/routes/api/share.js.map +0 -1
- package/dist/routes/api/version.d.ts +0 -4
- package/dist/routes/api/version.js +0 -10
- package/dist/routes/api/version.js.map +0 -1
- package/dist/routes/index.d.ts +0 -4
- package/dist/routes/index.js +0 -71
- package/dist/routes/index.js.map +0 -1
- package/dist/routes/login.d.ts +0 -4
- package/dist/routes/login.js +0 -18
- package/dist/routes/login.js.map +0 -1
- package/dist/routes/me.d.ts +0 -4
- package/dist/routes/me.js +0 -24
- package/dist/routes/me.js.map +0 -1
- package/dist/routes/ts-rest/admin/app.d.ts +0 -4
- package/dist/routes/ts-rest/admin/app.js +0 -67
- package/dist/routes/ts-rest/admin/app.js.map +0 -1
- package/dist/routes/ts-rest/admin/auth.d.ts +0 -4
- package/dist/routes/ts-rest/admin/auth.js +0 -95
- package/dist/routes/ts-rest/admin/auth.js.map +0 -1
- package/dist/routes/ts-rest/admin/index.d.ts +0 -10
- package/dist/routes/ts-rest/admin/index.js +0 -35
- package/dist/routes/ts-rest/admin/index.js.map +0 -1
- package/dist/routes/ts-rest/admin/mail.d.ts +0 -4
- package/dist/routes/ts-rest/admin/mail.js +0 -156
- package/dist/routes/ts-rest/admin/mail.js.map +0 -1
- package/dist/routes/ts-rest/admin/plugins.d.ts +0 -4
- package/dist/routes/ts-rest/admin/plugins.js +0 -317
- package/dist/routes/ts-rest/admin/plugins.js.map +0 -1
- package/dist/routes/ts-rest/admin/search.d.ts +0 -4
- package/dist/routes/ts-rest/admin/search.js +0 -67
- package/dist/routes/ts-rest/admin/search.js.map +0 -1
- package/dist/routes/ts-rest/admin/security.d.ts +0 -4
- package/dist/routes/ts-rest/admin/security.js +0 -114
- package/dist/routes/ts-rest/admin/security.js.map +0 -1
- package/dist/routes/ts-rest/admin/share.d.ts +0 -4
- package/dist/routes/ts-rest/admin/share.js +0 -69
- package/dist/routes/ts-rest/admin/share.js.map +0 -1
- package/dist/routes/ts-rest/admin/storage.d.ts +0 -4
- package/dist/routes/ts-rest/admin/storage.js +0 -59
- package/dist/routes/ts-rest/admin/storage.js.map +0 -1
- package/dist/routes/ts-rest/admin/users.d.ts +0 -4
- package/dist/routes/ts-rest/admin/users.js +0 -215
- package/dist/routes/ts-rest/admin/users.js.map +0 -1
- package/dist/routes/ts-rest/adminCrypto.d.ts +0 -4
- package/dist/routes/ts-rest/adminCrypto.js +0 -111
- package/dist/routes/ts-rest/adminCrypto.js.map +0 -1
- package/dist/routes/ts-rest/app.d.ts +0 -4
- package/dist/routes/ts-rest/app.js +0 -23
- package/dist/routes/ts-rest/app.js.map +0 -1
- package/dist/routes/ts-rest/attachment.d.ts +0 -4
- package/dist/routes/ts-rest/attachment.js +0 -830
- package/dist/routes/ts-rest/attachment.js.map +0 -1
- package/dist/routes/ts-rest/auth.d.ts +0 -4
- package/dist/routes/ts-rest/auth.js +0 -70
- package/dist/routes/ts-rest/auth.js.map +0 -1
- package/dist/routes/ts-rest/autocomplete.d.ts +0 -30
- package/dist/routes/ts-rest/autocomplete.js +0 -189
- package/dist/routes/ts-rest/autocomplete.js.map +0 -1
- package/dist/routes/ts-rest/backlink.d.ts +0 -4
- package/dist/routes/ts-rest/backlink.js +0 -106
- package/dist/routes/ts-rest/backlink.js.map +0 -1
- package/dist/routes/ts-rest/bookmark.d.ts +0 -4
- package/dist/routes/ts-rest/bookmark.js +0 -189
- package/dist/routes/ts-rest/bookmark.js.map +0 -1
- package/dist/routes/ts-rest/comment.d.ts +0 -4
- package/dist/routes/ts-rest/comment.js +0 -217
- package/dist/routes/ts-rest/comment.js.map +0 -1
- package/dist/routes/ts-rest/draft.d.ts +0 -22
- package/dist/routes/ts-rest/draft.js +0 -200
- package/dist/routes/ts-rest/draft.js.map +0 -1
- package/dist/routes/ts-rest/index.d.ts +0 -4
- package/dist/routes/ts-rest/index.js +0 -103
- package/dist/routes/ts-rest/index.js.map +0 -1
- package/dist/routes/ts-rest/installer.d.ts +0 -4
- package/dist/routes/ts-rest/installer.js +0 -77
- package/dist/routes/ts-rest/installer.js.map +0 -1
- package/dist/routes/ts-rest/me.d.ts +0 -4
- package/dist/routes/ts-rest/me.js +0 -410
- package/dist/routes/ts-rest/me.js.map +0 -1
- package/dist/routes/ts-rest/notification.d.ts +0 -4
- package/dist/routes/ts-rest/notification.js +0 -241
- package/dist/routes/ts-rest/notification.js.map +0 -1
- package/dist/routes/ts-rest/page-collab.d.ts +0 -29
- package/dist/routes/ts-rest/page-collab.js +0 -90
- package/dist/routes/ts-rest/page-collab.js.map +0 -1
- package/dist/routes/ts-rest/page-preview.d.ts +0 -26
- package/dist/routes/ts-rest/page-preview.js +0 -80
- package/dist/routes/ts-rest/page-preview.js.map +0 -1
- package/dist/routes/ts-rest/page.d.ts +0 -4
- package/dist/routes/ts-rest/page.js +0 -676
- package/dist/routes/ts-rest/page.js.map +0 -1
- package/dist/routes/ts-rest/presence.d.ts +0 -30
- package/dist/routes/ts-rest/presence.js +0 -155
- package/dist/routes/ts-rest/presence.js.map +0 -1
- package/dist/routes/ts-rest/revision.d.ts +0 -4
- package/dist/routes/ts-rest/revision.js +0 -240
- package/dist/routes/ts-rest/revision.js.map +0 -1
- package/dist/routes/ts-rest/search.d.ts +0 -4
- package/dist/routes/ts-rest/search.js +0 -121
- package/dist/routes/ts-rest/search.js.map +0 -1
- package/dist/routes/ts-rest/tokenAuth.d.ts +0 -4
- package/dist/routes/ts-rest/tokenAuth.js +0 -94
- package/dist/routes/ts-rest/tokenAuth.js.map +0 -1
- package/dist/routes/ts-rest/user.d.ts +0 -4
- package/dist/routes/ts-rest/user.js +0 -307
- package/dist/routes/ts-rest/user.js.map +0 -1
- package/dist/types/express.d.ts +0 -34
- package/dist/types/express.js +0 -50
- package/dist/types/express.js.map +0 -1
- package/dist/util/accessTokenParser.d.ts +0 -1
- package/dist/util/accessTokenParser.js +0 -34
- package/dist/util/accessTokenParser.js.map +0 -1
- package/dist/util/apiPaginate.d.ts +0 -11
- package/dist/util/apiPaginate.js +0 -33
- package/dist/util/apiPaginate.js.map +0 -1
- package/dist/util/apiResponse.d.ts +0 -9
- package/dist/util/apiResponse.js +0 -23
- package/dist/util/apiResponse.js.map +0 -1
- package/dist/util/auth.d.ts +0 -11
- package/dist/util/auth.js +0 -48
- package/dist/util/auth.js.map +0 -1
- package/dist/util/aws-config-migration.d.ts +0 -11
- package/dist/util/aws-config-migration.js +0 -68
- package/dist/util/aws-config-migration.js.map +0 -1
- package/dist/util/formUtil.d.ts +0 -2
- package/dist/util/formUtil.js +0 -15
- package/dist/util/formUtil.js.map +0 -1
- package/dist/util/githubAuth.d.ts +0 -2
- package/dist/util/githubAuth.js +0 -82
- package/dist/util/githubAuth.js.map +0 -1
- package/dist/util/googleAuth.d.ts +0 -2
- package/dist/util/googleAuth.js +0 -85
- package/dist/util/googleAuth.js.map +0 -1
- package/dist/util/mailer.d.ts +0 -7
- package/dist/util/mailer.js +0 -98
- package/dist/util/mailer.js.map +0 -1
- package/dist/util/page-status-migration.d.ts +0 -23
- package/dist/util/page-status-migration.js +0 -48
- package/dist/util/page-status-migration.js.map +0 -1
- package/dist/util/ssr.d.ts +0 -3
- package/dist/util/ssr.js +0 -9
- package/dist/util/ssr.js.map +0 -1
- package/dist/util/view.d.ts +0 -10
- package/dist/util/view.js +0 -99
- package/dist/util/view.js.map +0 -1
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const express_1 = require("@ts-rest/express");
|
|
7
|
-
const api_contract_1 = require("@crowi/api-contract");
|
|
8
|
-
const express_2 = require("express");
|
|
9
|
-
const mongoose_1 = require("mongoose");
|
|
10
|
-
const ts_rest_helpers_1 = require("../../util/ts-rest-helpers");
|
|
11
|
-
const page_response_1 = require("../../util/page-response");
|
|
12
|
-
const debug_1 = __importDefault(require("debug"));
|
|
13
|
-
const debug = (0, debug_1.default)('crowi:routes:ts-rest:bookmark');
|
|
14
|
-
const bookmarkToResponse = (bookmark) => {
|
|
15
|
-
const bookmarkObj = typeof bookmark.toObject === 'function' ? bookmark.toObject() : bookmark;
|
|
16
|
-
return {
|
|
17
|
-
_id: (0, ts_rest_helpers_1.toStringId)(bookmarkObj._id),
|
|
18
|
-
page: bookmarkObj.page ? (0, page_response_1.pageToResponse)(bookmarkObj.page) : null,
|
|
19
|
-
user: (0, ts_rest_helpers_1.isPopulatedUser)(bookmarkObj.user) ? (0, ts_rest_helpers_1.toPageUser)(bookmarkObj.user) : (0, ts_rest_helpers_1.toStringId)(bookmarkObj.user),
|
|
20
|
-
createdAt: (0, ts_rest_helpers_1.toISOStringOrNull)(bookmarkObj.createdAt) || new Date().toISOString(),
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
exports.default = (crowi, _app) => {
|
|
24
|
-
const s = (0, express_1.initServer)();
|
|
25
|
-
const router = (0, express_2.Router)();
|
|
26
|
-
const Page = crowi.model('Page');
|
|
27
|
-
const Bookmark = crowi.model('Bookmark');
|
|
28
|
-
const bookmarkRouter = s.router(api_contract_1.apiContract.bookmark, {
|
|
29
|
-
/**
|
|
30
|
-
* GET /api/v2/bookmarks?page_id=xxx
|
|
31
|
-
* Returns the current user's bookmark for a given page (or null).
|
|
32
|
-
* Equivalent to legacy GET /_api/bookmarks.get.
|
|
33
|
-
*/
|
|
34
|
-
getBookmark: async ({ query, req }) => {
|
|
35
|
-
const user = req.user;
|
|
36
|
-
const { page_id } = query;
|
|
37
|
-
debug('getBookmark called with:', { page_id, userId: user._id });
|
|
38
|
-
if (!(0, ts_rest_helpers_1.isValidObjectId)(page_id)) {
|
|
39
|
-
return ts_rest_helpers_1.invalidPageIdResponse;
|
|
40
|
-
}
|
|
41
|
-
try {
|
|
42
|
-
const pageObjectId = new mongoose_1.Types.ObjectId(page_id);
|
|
43
|
-
const bookmark = (await Bookmark.findByPageIdAndUserId(pageObjectId, user._id));
|
|
44
|
-
return {
|
|
45
|
-
status: 200,
|
|
46
|
-
body: {
|
|
47
|
-
bookmark: bookmark ? bookmarkToResponse(bookmark) : null,
|
|
48
|
-
},
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
catch (err) {
|
|
52
|
-
const error = err;
|
|
53
|
-
debug('Error fetching bookmark:', error.message);
|
|
54
|
-
return {
|
|
55
|
-
status: 500,
|
|
56
|
-
body: { error: { code: 'INTERNAL_ERROR', message: 'Internal server error' } },
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
|
-
/**
|
|
61
|
-
* GET /api/v2/bookmarks/me?limit&offset
|
|
62
|
-
* Paginated list of the current user's bookmarks.
|
|
63
|
-
* Equivalent to legacy GET /_api/bookmarks.list (paginate).
|
|
64
|
-
*/
|
|
65
|
-
listMyBookmarks: async ({ query, req }) => {
|
|
66
|
-
const user = req.user;
|
|
67
|
-
const { limit = 50, offset = 0 } = query;
|
|
68
|
-
debug('listMyBookmarks called with:', { limit, offset, userId: user._id });
|
|
69
|
-
try {
|
|
70
|
-
// Bookmark.findByUserId always populates the page (and its revision/author).
|
|
71
|
-
const result = await Bookmark.findByUserId(user._id, { limit, offset });
|
|
72
|
-
const bookmarks = result.data;
|
|
73
|
-
const total = result.meta.total;
|
|
74
|
-
const prev = offset > 0 ? Math.max(0, offset - limit) : null;
|
|
75
|
-
const next = offset + limit < total ? offset + limit : null;
|
|
76
|
-
return {
|
|
77
|
-
status: 200,
|
|
78
|
-
body: {
|
|
79
|
-
bookmarks: bookmarks
|
|
80
|
-
.filter((bookmark) => bookmark.page) // populatePage may filter out inaccessible pages
|
|
81
|
-
.map((bookmark) => bookmarkToResponse(bookmark)),
|
|
82
|
-
pager: { prev, next, offset },
|
|
83
|
-
total,
|
|
84
|
-
},
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
catch (err) {
|
|
88
|
-
const error = err;
|
|
89
|
-
debug('Error listing my bookmarks:', error.message);
|
|
90
|
-
return {
|
|
91
|
-
status: 500,
|
|
92
|
-
body: { error: { code: 'INTERNAL_ERROR', message: 'Internal server error' } },
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
/**
|
|
97
|
-
* POST /api/v2/bookmarks { page_id }
|
|
98
|
-
* Add a bookmark for the current user.
|
|
99
|
-
* If the page is not accessible / does not exist, returns { bookmark: null }
|
|
100
|
-
* to preserve legacy /_api/bookmarks.add behavior.
|
|
101
|
-
*/
|
|
102
|
-
addBookmark: async ({ body: requestBody, req }) => {
|
|
103
|
-
const user = req.user;
|
|
104
|
-
const { page_id } = requestBody;
|
|
105
|
-
debug('addBookmark called with:', { page_id, userId: user._id });
|
|
106
|
-
if (!(0, ts_rest_helpers_1.isValidObjectId)(page_id)) {
|
|
107
|
-
return ts_rest_helpers_1.invalidPageIdResponse;
|
|
108
|
-
}
|
|
109
|
-
let pageData = null;
|
|
110
|
-
try {
|
|
111
|
-
pageData = (await Page.findPageByIdAndGrantedUser(page_id, user));
|
|
112
|
-
}
|
|
113
|
-
catch (err) {
|
|
114
|
-
const error = err;
|
|
115
|
-
// findPageByIdAndGrantedUser throws on not-found / not-granted.
|
|
116
|
-
// Per the planner spec we collapse both cases into { bookmark: null }
|
|
117
|
-
// so that the new endpoint behaves like the legacy `else` branch
|
|
118
|
-
// (which the legacy controller also intended even though it was
|
|
119
|
-
// unreachable in practice).
|
|
120
|
-
if (error.message === 'Page not found' || error.message === 'Page is not granted for the user') {
|
|
121
|
-
return { status: 200, body: { bookmark: null } };
|
|
122
|
-
}
|
|
123
|
-
debug('Error fetching page for bookmark:', error.message);
|
|
124
|
-
return {
|
|
125
|
-
status: 500,
|
|
126
|
-
body: { error: { code: 'INTERNAL_ERROR', message: 'Internal server error' } },
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
if (!pageData) {
|
|
130
|
-
return { status: 200, body: { bookmark: null } };
|
|
131
|
-
}
|
|
132
|
-
try {
|
|
133
|
-
const created = (await Bookmark.add(pageData, user));
|
|
134
|
-
// Mirror the legacy controller: depopulate before serializing so we
|
|
135
|
-
// do not leak full populated docs that the response schema may not expect.
|
|
136
|
-
// We then re-populate via pageToResponse using the page document we already fetched.
|
|
137
|
-
created.depopulate('page');
|
|
138
|
-
created.depopulate('user');
|
|
139
|
-
// Build a hybrid object: the bookmark with the page populated by pageData.
|
|
140
|
-
const bookmarkObj = created.toObject();
|
|
141
|
-
bookmarkObj.page = pageData;
|
|
142
|
-
return {
|
|
143
|
-
status: 200,
|
|
144
|
-
body: {
|
|
145
|
-
bookmark: bookmarkToResponse(bookmarkObj),
|
|
146
|
-
},
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
catch (err) {
|
|
150
|
-
const error = err;
|
|
151
|
-
debug('Error adding bookmark:', error.message);
|
|
152
|
-
return {
|
|
153
|
-
status: 500,
|
|
154
|
-
body: { error: { code: 'INTERNAL_ERROR', message: 'Internal server error' } },
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
},
|
|
158
|
-
/**
|
|
159
|
-
* DELETE /api/v2/bookmarks { page_id }
|
|
160
|
-
* Remove a bookmark for the current user.
|
|
161
|
-
* Mirrors the legacy controller: deletes by (page, user) directly.
|
|
162
|
-
* Returns { ok: true } even when there was no bookmark to delete
|
|
163
|
-
* (the legacy controller emits ApiResponse.success() unconditionally).
|
|
164
|
-
*/
|
|
165
|
-
removeBookmark: async ({ body: requestBody, req }) => {
|
|
166
|
-
const user = req.user;
|
|
167
|
-
const { page_id } = requestBody;
|
|
168
|
-
debug('removeBookmark called with:', { page_id, userId: user._id });
|
|
169
|
-
if (!(0, ts_rest_helpers_1.isValidObjectId)(page_id)) {
|
|
170
|
-
return ts_rest_helpers_1.invalidPageIdResponse;
|
|
171
|
-
}
|
|
172
|
-
try {
|
|
173
|
-
await Bookmark.removeBookmark(new mongoose_1.Types.ObjectId(page_id), user);
|
|
174
|
-
return { status: 200, body: { ok: true } };
|
|
175
|
-
}
|
|
176
|
-
catch (err) {
|
|
177
|
-
const error = err;
|
|
178
|
-
debug('Error removing bookmark:', error.message);
|
|
179
|
-
return {
|
|
180
|
-
status: 500,
|
|
181
|
-
body: { error: { code: 'INTERNAL_ERROR', message: 'Internal server error' } },
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
},
|
|
185
|
-
});
|
|
186
|
-
(0, express_1.createExpressEndpoints)(api_contract_1.apiContract.bookmark, bookmarkRouter, router);
|
|
187
|
-
return router;
|
|
188
|
-
};
|
|
189
|
-
//# sourceMappingURL=bookmark.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bookmark.js","sourceRoot":"","sources":["../../../src/routes/ts-rest/bookmark.ts"],"names":[],"mappings":";;;;;AAAA,8CAAsE;AACtE,sDAAkE;AAElE,qCAA0C;AAC1C,uCAAiC;AAIjC,8DAA6J;AAC7J,0DAAuE;AACvE,kDAA0B;AAE1B,MAAM,KAAK,GAAG,IAAA,eAAK,EAAC,+BAA+B,CAAC,CAAC;AAUrD,MAAM,kBAAkB,GAAG,CAAC,QAAyC,EAAY,EAAE;IACjF,MAAM,WAAW,GACf,OAAQ,QAA6B,CAAC,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAE,QAA6B,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAE,QAAyB,CAAC;IAEzI,OAAO;QACL,GAAG,EAAE,IAAA,4BAAU,EAAC,WAAW,CAAC,GAAG,CAAC;QAChC,IAAI,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,IAAA,8BAAc,EAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAE,IAAwB;QACrF,IAAI,EAAE,IAAA,iCAAe,EAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAA,4BAAU,EAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAA,4BAAU,EAAC,WAAW,CAAC,IAA+B,CAAC;QAChI,SAAS,EAAE,IAAA,mCAAiB,EAAC,WAAW,CAAC,SAAS,CAAC,IAAI,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;KAChF,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,CAAC,KAAY,EAAE,IAAa,EAAE,EAAE;IAC7C,MAAM,CAAC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@@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const express_1 = require("@ts-rest/express");
|
|
7
|
-
const api_contract_1 = require("@crowi/api-contract");
|
|
8
|
-
const express_2 = require("express");
|
|
9
|
-
const mongoose_1 = require("mongoose");
|
|
10
|
-
const ts_rest_helpers_1 = require("../../util/ts-rest-helpers");
|
|
11
|
-
const debug_1 = __importDefault(require("debug"));
|
|
12
|
-
const debug = (0, debug_1.default)('crowi:routes:ts-rest:comment');
|
|
13
|
-
const COMMENT_POSITION_DEFAULT = -1;
|
|
14
|
-
/**
|
|
15
|
-
* Convert CommentDocument (with optionally populated creator) to API response shape.
|
|
16
|
-
* - creator is serialized to PageUserSchema-compatible object when populated
|
|
17
|
-
* - revision is returned as a string id (UI does not need full revision object)
|
|
18
|
-
*/
|
|
19
|
-
const commentToResponse = (comment) => {
|
|
20
|
-
const obj = comment.toObject(); // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
21
|
-
let creator = null;
|
|
22
|
-
if (obj.creator && typeof obj.creator === 'object' && '_id' in obj.creator && 'username' in obj.creator) {
|
|
23
|
-
creator = (0, ts_rest_helpers_1.toPageUser)(obj.creator);
|
|
24
|
-
}
|
|
25
|
-
else if (obj.creator) {
|
|
26
|
-
creator = obj.creator.toString();
|
|
27
|
-
}
|
|
28
|
-
return {
|
|
29
|
-
_id: comment._id.toString(),
|
|
30
|
-
page: comment.page.toString(),
|
|
31
|
-
creator,
|
|
32
|
-
revision: comment.revision.toString(),
|
|
33
|
-
comment: comment.comment,
|
|
34
|
-
commentPosition: typeof comment.commentPosition === 'number' ? comment.commentPosition : COMMENT_POSITION_DEFAULT,
|
|
35
|
-
createdAt: (0, ts_rest_helpers_1.toISOStringOrNull)(comment.createdAt) ?? new Date(0).toISOString(),
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
exports.default = (crowi, _app) => {
|
|
39
|
-
const s = (0, express_1.initServer)();
|
|
40
|
-
const router = (0, express_2.Router)();
|
|
41
|
-
const Comment = crowi.model('Comment');
|
|
42
|
-
const Page = crowi.model('Page');
|
|
43
|
-
const commentRouter = s.router(api_contract_1.apiContract.comment, {
|
|
44
|
-
/**
|
|
45
|
-
* GET /api/v2/comments
|
|
46
|
-
* List comments by page_id or revision_id (one is required).
|
|
47
|
-
* - Authentication enforced by jwtAuth at router level.
|
|
48
|
-
*/
|
|
49
|
-
listComments: async ({ query, req }) => {
|
|
50
|
-
const user = req.user;
|
|
51
|
-
const { page_id, revision_id } = query;
|
|
52
|
-
debug('listComments called with:', { page_id, revision_id, userId: user._id });
|
|
53
|
-
if (!page_id && !revision_id) {
|
|
54
|
-
return {
|
|
55
|
-
status: 400,
|
|
56
|
-
body: {
|
|
57
|
-
error: {
|
|
58
|
-
code: 'INVALID_REQUEST',
|
|
59
|
-
message: 'page_id or revision_id is required',
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
try {
|
|
65
|
-
let comments;
|
|
66
|
-
if (revision_id) {
|
|
67
|
-
if (!(0, ts_rest_helpers_1.isValidObjectId)(revision_id)) {
|
|
68
|
-
return {
|
|
69
|
-
status: 400,
|
|
70
|
-
body: { error: { code: 'INVALID_REQUEST', message: 'Invalid revision_id' } },
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
comments = await Comment.getCommentsByRevisionId(new mongoose_1.Types.ObjectId(revision_id));
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
if (!(0, ts_rest_helpers_1.isValidObjectId)(page_id)) {
|
|
77
|
-
return {
|
|
78
|
-
status: 400,
|
|
79
|
-
body: { error: { code: 'INVALID_REQUEST', message: 'Invalid page_id' } },
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
comments = await Comment.getCommentsByPageId(new mongoose_1.Types.ObjectId(page_id));
|
|
83
|
-
}
|
|
84
|
-
return {
|
|
85
|
-
status: 200,
|
|
86
|
-
body: { comments: comments.map(commentToResponse) },
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
catch (err) {
|
|
90
|
-
const error = err;
|
|
91
|
-
debug('Error listing comments:', error.message);
|
|
92
|
-
return {
|
|
93
|
-
status: 400,
|
|
94
|
-
body: { error: { code: 'INVALID_REQUEST', message: error.message || 'Failed to list comments' } },
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
/**
|
|
99
|
-
* POST /api/v2/comments
|
|
100
|
-
* Add a comment to a page revision.
|
|
101
|
-
* - Validates page existence and grant before creating (stricter than the legacy
|
|
102
|
-
* /_api/comments.add which trusted the caller-provided page_id).
|
|
103
|
-
* - Comment.create triggers post-save hooks that update Page.commentCount and
|
|
104
|
-
* Activity entries; we intentionally do not duplicate that work here.
|
|
105
|
-
*/
|
|
106
|
-
addComment: async ({ body, req }) => {
|
|
107
|
-
const user = req.user;
|
|
108
|
-
const { page_id, revision_id, comment, comment_position } = body;
|
|
109
|
-
debug('addComment called with:', { page_id, revision_id, userId: user._id });
|
|
110
|
-
if (!(0, ts_rest_helpers_1.isValidObjectId)(page_id) || !(0, ts_rest_helpers_1.isValidObjectId)(revision_id)) {
|
|
111
|
-
return {
|
|
112
|
-
status: 400,
|
|
113
|
-
body: { error: { code: 'INVALID_REQUEST', message: 'Invalid page_id or revision_id' } },
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
try {
|
|
117
|
-
const page = (await Page.findPageByIdAndGrantedUser(page_id, user));
|
|
118
|
-
if (!page) {
|
|
119
|
-
return {
|
|
120
|
-
status: 404,
|
|
121
|
-
body: { error: { code: 'PAGE_NOT_FOUND', message: 'Page not found' } },
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
const created = await Comment.create({
|
|
125
|
-
page: new mongoose_1.Types.ObjectId(page_id),
|
|
126
|
-
creator: user._id,
|
|
127
|
-
revision: new mongoose_1.Types.ObjectId(revision_id),
|
|
128
|
-
comment,
|
|
129
|
-
commentPosition: comment_position ?? COMMENT_POSITION_DEFAULT,
|
|
130
|
-
});
|
|
131
|
-
const populated = (await created.populate('creator'));
|
|
132
|
-
return {
|
|
133
|
-
status: 200,
|
|
134
|
-
body: { comment: commentToResponse(populated) },
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
catch (err) {
|
|
138
|
-
const error = err;
|
|
139
|
-
debug('Error adding comment:', error.message);
|
|
140
|
-
if (error.message === 'Page not found' || error.message === 'Page is not granted for the user') {
|
|
141
|
-
// findPageByIdAndGrantedUser hides the distinction; map both to 404.
|
|
142
|
-
return {
|
|
143
|
-
status: 404,
|
|
144
|
-
body: { error: { code: 'PAGE_NOT_FOUND', message: 'Page not found' } },
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
return {
|
|
148
|
-
status: 400,
|
|
149
|
-
body: { error: { code: 'INVALID_REQUEST', message: error.message || 'Failed to add comment' } },
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
},
|
|
153
|
-
/**
|
|
154
|
-
* DELETE /api/v2/comments
|
|
155
|
-
* Delete a comment by id. The legacy controller required the caller to also
|
|
156
|
-
* supply the page_id and verified page-grant via `pageData.isGrantedFor(user)`;
|
|
157
|
-
* we preserve that behavior so nothing is lost.
|
|
158
|
-
*/
|
|
159
|
-
deleteComment: async ({ body, req }) => {
|
|
160
|
-
const user = req.user;
|
|
161
|
-
const { comment_id, page_id } = body;
|
|
162
|
-
debug('deleteComment called with:', { comment_id, page_id, userId: user._id });
|
|
163
|
-
if (!(0, ts_rest_helpers_1.isValidObjectId)(comment_id) || !(0, ts_rest_helpers_1.isValidObjectId)(page_id)) {
|
|
164
|
-
return {
|
|
165
|
-
status: 400,
|
|
166
|
-
body: { error: { code: 'INVALID_REQUEST', message: 'Invalid comment_id or page_id' } },
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
try {
|
|
170
|
-
const pageData = (await Page.findPageById(page_id));
|
|
171
|
-
if (!pageData) {
|
|
172
|
-
return {
|
|
173
|
-
status: 404,
|
|
174
|
-
body: { error: { code: 'COMMENT_NOT_FOUND', message: 'Comment not found' } },
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
if (!pageData.isGrantedFor(user)) {
|
|
178
|
-
return {
|
|
179
|
-
status: 403,
|
|
180
|
-
body: {
|
|
181
|
-
error: { code: 'PAGE_NOT_GRANTED', message: 'Page is not granted for the user' },
|
|
182
|
-
},
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
const existing = await Comment.findOne({ _id: new mongoose_1.Types.ObjectId(comment_id) }).exec();
|
|
186
|
-
if (!existing) {
|
|
187
|
-
return {
|
|
188
|
-
status: 404,
|
|
189
|
-
body: { error: { code: 'COMMENT_NOT_FOUND', message: 'Comment not found' } },
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
await Comment.removeCommentById(new mongoose_1.Types.ObjectId(comment_id));
|
|
193
|
-
return {
|
|
194
|
-
status: 200,
|
|
195
|
-
body: { ok: true },
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
catch (err) {
|
|
199
|
-
const error = err;
|
|
200
|
-
debug('Error deleting comment:', error.message);
|
|
201
|
-
if (error.message === 'Page not found') {
|
|
202
|
-
return {
|
|
203
|
-
status: 404,
|
|
204
|
-
body: { error: { code: 'COMMENT_NOT_FOUND', message: 'Comment not found' } },
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
return {
|
|
208
|
-
status: 400,
|
|
209
|
-
body: { error: { code: 'INVALID_REQUEST', message: error.message || 'Failed to delete comment' } },
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
},
|
|
213
|
-
});
|
|
214
|
-
(0, express_1.createExpressEndpoints)(api_contract_1.apiContract.comment, commentRouter, router);
|
|
215
|
-
return router;
|
|
216
|
-
};
|
|
217
|
-
//# sourceMappingURL=com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K,CAAC,OAAO,KAAK,gBAAgB,EAAE,CAAC;oBACvC,OAAO;wBACL,MAAM,EAAE,GAAY;wBACpB,IAAI,EAAE,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,mBAA4B,EAAE,OAAO,EAAE,mBAA4B,EAAE,EAAE;qBAC/F,CAAC;gBACJ,CAAC;gBAED,OAAO;oBACL,MAAM,EAAE,GAAY;oBACpB,IAAI,EAAE,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,iBAA0B,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,IAAI,0BAA0B,EAAE,EAAE;iBAC5G,CAAC;YACJ,CAAC;QACH,CAAC;KACF,CAAC,CAAC;IAEH,IAAA,gCAAsB,EAAC,0BAAW,CAAC,OAAO,EAAE,aAAa,EAAE,MAAM,CAAC,CAAC;IAEnE,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import Crowi from '../../crowi';
|
|
2
|
-
import { Express } from 'express';
|
|
3
|
-
/**
|
|
4
|
-
* RFC-0004 Phase 3 — drafts endpoints (`/api/v2/pages/drafts`).
|
|
5
|
-
*
|
|
6
|
-
* A *draft* is a `Page` with `status === 'draft'`: a brand-new page in
|
|
7
|
-
* progress, author-only, that transitions to `published` exactly once
|
|
8
|
-
* on first save (the publish transition itself is owned by the future
|
|
9
|
-
* RFC-0003 save flow — out of scope here).
|
|
10
|
-
*
|
|
11
|
-
* Mounted in the authenticated router, so `jwtAuth` is already applied
|
|
12
|
-
* and `req.user` is a `UserDocument`. CSRF is not needed for ts-rest
|
|
13
|
-
* (token-based auth).
|
|
14
|
-
*
|
|
15
|
-
* Same-path conflict (`docs/rfcs/0004-editor-ux-enhancement.md`
|
|
16
|
-
* §"Same-path conflict"): creating a draft at a path already held by
|
|
17
|
-
* another user's draft returns 409 with that user's identity so the
|
|
18
|
-
* `Creating pages` UI can show the contact-the-owner message. A path
|
|
19
|
-
* held by a *published* page returns a plain 400.
|
|
20
|
-
*/
|
|
21
|
-
declare const _default: (crowi: Crowi, _app: Express) => import("express-serve-static-core").Router;
|
|
22
|
-
export default _default;
|
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const express_1 = require("@ts-rest/express");
|
|
7
|
-
const api_contract_1 = require("@crowi/api-contract");
|
|
8
|
-
const express_2 = require("express");
|
|
9
|
-
const page_1 = require("../../models/page");
|
|
10
|
-
const ts_rest_helpers_1 = require("../../util/ts-rest-helpers");
|
|
11
|
-
const debug_1 = __importDefault(require("debug"));
|
|
12
|
-
const debug = (0, debug_1.default)('crowi:routes:ts-rest:draft');
|
|
13
|
-
/** MongoDB duplicate-key error code, raised by the unique `Page.path` index. */
|
|
14
|
-
const isDuplicateKeyError = (err) => typeof err === 'object' && err !== null && err.code === 11000;
|
|
15
|
-
/**
|
|
16
|
-
* RFC-0004 Phase 3 — drafts endpoints (`/api/v2/pages/drafts`).
|
|
17
|
-
*
|
|
18
|
-
* A *draft* is a `Page` with `status === 'draft'`: a brand-new page in
|
|
19
|
-
* progress, author-only, that transitions to `published` exactly once
|
|
20
|
-
* on first save (the publish transition itself is owned by the future
|
|
21
|
-
* RFC-0003 save flow — out of scope here).
|
|
22
|
-
*
|
|
23
|
-
* Mounted in the authenticated router, so `jwtAuth` is already applied
|
|
24
|
-
* and `req.user` is a `UserDocument`. CSRF is not needed for ts-rest
|
|
25
|
-
* (token-based auth).
|
|
26
|
-
*
|
|
27
|
-
* Same-path conflict (`docs/rfcs/0004-editor-ux-enhancement.md`
|
|
28
|
-
* §"Same-path conflict"): creating a draft at a path already held by
|
|
29
|
-
* another user's draft returns 409 with that user's identity so the
|
|
30
|
-
* `Creating pages` UI can show the contact-the-owner message. A path
|
|
31
|
-
* held by a *published* page returns a plain 400.
|
|
32
|
-
*/
|
|
33
|
-
exports.default = (crowi, _app) => {
|
|
34
|
-
const s = (0, express_1.initServer)();
|
|
35
|
-
const router = (0, express_2.Router)();
|
|
36
|
-
const Page = crowi.model('Page');
|
|
37
|
-
const Revision = crowi.model('Revision');
|
|
38
|
-
const User = crowi.model('User');
|
|
39
|
-
const draftRouter = s.router(api_contract_1.apiContract.draft, {
|
|
40
|
-
/**
|
|
41
|
-
* POST /api/v2/pages/drafts
|
|
42
|
-
*
|
|
43
|
-
* Create a draft at `path` with the default `GRANT_PUBLIC` grant
|
|
44
|
-
* (RFC-0005 Phase 1). A draft's author-only visibility is enforced
|
|
45
|
-
* entirely by `status: 'draft'` — `findPage*` collapse a non-author
|
|
46
|
-
* by-id / by-path access into not-found, and listing / search /
|
|
47
|
-
* backlink all exclude other users' drafts by status. The grant is
|
|
48
|
-
* deliberately left public so that once publish-on-save flips the
|
|
49
|
-
* status to `published`, the page is immediately visible to other
|
|
50
|
-
* users; a `GRANT_OWNER` draft would stay invisible at the grant
|
|
51
|
-
* layer even after the status flip. (Phase 2 will let the editor
|
|
52
|
-
* pick a non-public grant explicitly.)
|
|
53
|
-
*/
|
|
54
|
-
createDraft: async ({ body, req }) => {
|
|
55
|
-
const user = req.user;
|
|
56
|
-
// The seed revision's `body` is `required` in the Revision schema
|
|
57
|
-
// and Mongoose rejects an empty string. A brand-new draft is
|
|
58
|
-
// conceptually empty, so seed a single newline — it renders to
|
|
59
|
-
// nothing and gives the collab editor an effectively blank doc.
|
|
60
|
-
const initialBody = body.initialBody && body.initialBody.length > 0 ? body.initialBody : '\n';
|
|
61
|
-
const path = Page.normalizePath(body.path);
|
|
62
|
-
debug('createDraft called', { path, userId: user._id.toString() });
|
|
63
|
-
if (!Page.isCreatableName(path)) {
|
|
64
|
-
return {
|
|
65
|
-
status: 400,
|
|
66
|
-
body: { error: 'invalid_path', message: `Cannot create a page at this path (${path}).` },
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
// Resolve a path already occupied by a page into the right
|
|
70
|
-
// response — the caller's own draft → 201 (idempotent, so a
|
|
71
|
-
// double-click resolves to the same draft), another user's draft
|
|
72
|
-
// → 409 with owner info, anything published → 400. `null` means
|
|
73
|
-
// the path is free. The owner is loaded only on the 409 branch.
|
|
74
|
-
const resolveOccupied = async () => {
|
|
75
|
-
const existing = (await Page.findOne({ path }));
|
|
76
|
-
if (!existing)
|
|
77
|
-
return null;
|
|
78
|
-
if (existing.status !== page_1.STATUS_DRAFT) {
|
|
79
|
-
return {
|
|
80
|
-
status: 400,
|
|
81
|
-
body: { error: 'path_taken', message: `A page already exists at ${path}.` },
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
if (existing.isCreator(user)) {
|
|
85
|
-
return { status: 201, body: { pageId: existing._id.toString() } };
|
|
86
|
-
}
|
|
87
|
-
const owner = (await User.findById(existing.creator));
|
|
88
|
-
return {
|
|
89
|
-
status: 409,
|
|
90
|
-
body: {
|
|
91
|
-
error: 'path_taken_by_draft',
|
|
92
|
-
owner: owner
|
|
93
|
-
? { id: owner._id.toString(), username: owner.username, displayName: owner.name }
|
|
94
|
-
: { id: '', username: 'unknown', displayName: 'unknown' },
|
|
95
|
-
message: owner ? `This page is being created by @${owner.username}.` : 'This page is being created by another user.',
|
|
96
|
-
},
|
|
97
|
-
};
|
|
98
|
-
};
|
|
99
|
-
const occupied = await resolveOccupied();
|
|
100
|
-
if (occupied)
|
|
101
|
-
return occupied;
|
|
102
|
-
try {
|
|
103
|
-
const newPage = await Page.create({
|
|
104
|
-
path,
|
|
105
|
-
creator: user,
|
|
106
|
-
lastUpdateUser: user,
|
|
107
|
-
createdAt: Date.now(),
|
|
108
|
-
updatedAt: Date.now(),
|
|
109
|
-
redirectTo: null,
|
|
110
|
-
grant: page_1.GRANT_PUBLIC,
|
|
111
|
-
status: page_1.STATUS_DRAFT,
|
|
112
|
-
grantedUsers: [user],
|
|
113
|
-
});
|
|
114
|
-
// Seed the first revision so the page is loadable / editable
|
|
115
|
-
// immediately. `pushRevision` wires `revision` + bumps the
|
|
116
|
-
// `Page.create` event so backlinks / search run — both already
|
|
117
|
-
// exclude other users' drafts (Phase 2).
|
|
118
|
-
const newRevision = await Revision.prepareRevision(newPage, initialBody, user, { format: 'markdown' });
|
|
119
|
-
await Page.pushRevision(newPage, newRevision, user);
|
|
120
|
-
debug('createDraft created draft page', { pageId: newPage._id.toString(), path });
|
|
121
|
-
return { status: 201, body: { pageId: newPage._id.toString() } };
|
|
122
|
-
}
|
|
123
|
-
catch (err) {
|
|
124
|
-
// A concurrent POST can win the unique-`path`-index race between
|
|
125
|
-
// the pre-check and `create`. Re-resolve so the loser still gets
|
|
126
|
-
// the proper 400 / 409 instead of a misleading `invalid_path`.
|
|
127
|
-
if (isDuplicateKeyError(err)) {
|
|
128
|
-
const raced = await resolveOccupied();
|
|
129
|
-
if (raced)
|
|
130
|
-
return raced;
|
|
131
|
-
}
|
|
132
|
-
debug('createDraft failed:', err.message);
|
|
133
|
-
return {
|
|
134
|
-
status: 400,
|
|
135
|
-
body: { error: 'invalid_path', message: err.message || 'Failed to create draft.' },
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
},
|
|
139
|
-
/**
|
|
140
|
-
* GET /api/v2/pages/drafts
|
|
141
|
-
*
|
|
142
|
-
* List the caller's own drafts, newest first. Powers the
|
|
143
|
-
* `Creating pages` view; never returns another user's drafts.
|
|
144
|
-
*/
|
|
145
|
-
listDrafts: async ({ req }) => {
|
|
146
|
-
const user = req.user;
|
|
147
|
-
debug('listDrafts called', { userId: user._id.toString() });
|
|
148
|
-
const drafts = (await Page.find({ status: page_1.STATUS_DRAFT, creator: user._id })
|
|
149
|
-
.sort({ createdAt: -1 })
|
|
150
|
-
.select('_id path createdAt updatedAt')
|
|
151
|
-
.lean()
|
|
152
|
-
.exec());
|
|
153
|
-
return {
|
|
154
|
-
status: 200,
|
|
155
|
-
body: {
|
|
156
|
-
drafts: drafts.map((d) => ({
|
|
157
|
-
pageId: d._id.toString(),
|
|
158
|
-
path: d.path,
|
|
159
|
-
createdAt: (0, ts_rest_helpers_1.toISOStringOrNull)(d.createdAt) ?? new Date().toISOString(),
|
|
160
|
-
updatedAt: (0, ts_rest_helpers_1.toISOStringOrNull)(d.updatedAt) ?? (0, ts_rest_helpers_1.toISOStringOrNull)(d.createdAt) ?? new Date().toISOString(),
|
|
161
|
-
})),
|
|
162
|
-
},
|
|
163
|
-
};
|
|
164
|
-
},
|
|
165
|
-
/**
|
|
166
|
-
* DELETE /api/v2/pages/drafts/:id
|
|
167
|
-
*
|
|
168
|
-
* Cancel a draft, releasing its path. Only the author may cancel.
|
|
169
|
-
* "No such draft", "not a draft", and "someone else's draft" all
|
|
170
|
-
* collapse to the same 404 so draft existence is never leaked.
|
|
171
|
-
*/
|
|
172
|
-
cancelDraft: async ({ params, req }) => {
|
|
173
|
-
const user = req.user;
|
|
174
|
-
const { id } = params;
|
|
175
|
-
debug('cancelDraft called', { id, userId: user._id.toString() });
|
|
176
|
-
const draftNotFound = {
|
|
177
|
-
status: 404,
|
|
178
|
-
body: { error: 'draft_not_found', message: 'Draft not found.' },
|
|
179
|
-
};
|
|
180
|
-
// A malformed id would make the `_id` query throw a CastError;
|
|
181
|
-
// collapse it into the same 404 as "no such draft".
|
|
182
|
-
if (!(0, ts_rest_helpers_1.isValidObjectId)(id)) {
|
|
183
|
-
return draftNotFound;
|
|
184
|
-
}
|
|
185
|
-
const page = (await Page.findOne({ _id: id, status: page_1.STATUS_DRAFT, creator: user._id }));
|
|
186
|
-
if (!page) {
|
|
187
|
-
return draftNotFound;
|
|
188
|
-
}
|
|
189
|
-
// `removePage` physically deletes the Page and its revisions —
|
|
190
|
-
// the right semantics for "cancel": the path is freed and no
|
|
191
|
-
// /trash redirect stub is left behind (unlike soft delete).
|
|
192
|
-
await Page.removePage(page);
|
|
193
|
-
debug('cancelDraft removed draft', { id, path: page.path });
|
|
194
|
-
return { status: 200, body: { pageId: id } };
|
|
195
|
-
},
|
|
196
|
-
});
|
|
197
|
-
(0, express_1.createExpressEndpoints)(api_contract_1.apiContract.draft, draftRouter, router);
|
|
198
|
-
return router;
|
|
199
|
-
};
|
|
200
|
-
//# sourceMappingURL=draft.js.map
|