This version (v0.7) has not been published to npm yet.
Skip to content

Comments ​

The comments namespace of @getenginex/sdk-predictions covers each market's comments. Reading is public; commenting, liking and listing your own requires login (without a session, the method rejects with UNAUTHENTICATED before any request).

List ​

ts
const { items, total } = await predictions.comments.list({ marketId: 'mkt-1', limit: 20, offset: 0 })

Returns { items, total } (not a Page): total is the market's total number of comments, for computing pages. Pagination uses limit/offset; the gateway defaults to 50. Root comments carry their replies in replies.

ts
let offset = 0
const all = []
while (true) {
  const { items, total } = await predictions.comments.list({ marketId, limit: 50, offset })
  all.push(...items)
  offset += items.length
  if (items.length === 0 || offset >= total) break
}

A comment (Comment) carries parentId ('' for a root), depth (0 root, 1 reply, 2 reply to a reply; the maximum is 2), likesCount, repliesCount, likedByMe and status: pending (under moderation), approved or rejected (with rejectionReason). A status the SDK doesn't know follows the rule for unknown enums.

Comment, reply and like ​

ts
const comment = await predictions.comments.create({ marketId: 'mkt-1', content: 'Agree' })
const reply = await predictions.comments.create({ marketId: 'mkt-1', content: 'Me too', parentId: comment.id })

const liked = await predictions.comments.like({ commentId: comment.id }) // returns the updated comment
const back = await predictions.comments.unlike({ commentId: comment.id })

const { items: mine } = await predictions.comments.listMine({ limit: 20 })
  • create does not send Idempotency-Key: repeating the call (e.g. a double click) posts again. Disable the button while the call is in progress.
  • An empty content is not validated in the SDK: the gateway answers INVALID_ARGUMENT, which arrives as an EnginexError.
  • like, unlike and create return the comment (HTTP 200, create included).
  • COMMENT_NOT_FOUND and MARKET_NOT_FOUND arrive with HTTP 500: decide by code (isEnginexError(error, 'COMMENT_NOT_FOUND')).

Testing ​

withPredictionsRoutes() seeds two comments in mock-market-1 and keeps the state in memory per mock: create (root or reply, up to depth 2), like/unlike (one like per user) and list your own. The routes that require a session answer 401 without a token, so log in (enginex.auth.login, any email and password in the mock) first.