in dotcom-rendering/src/lib/discussion.ts [305:392]
apiUrl: string(),
commentCount: number(),
topLevelCommentCount: optional(number(), 0),
isClosedForComments: boolean(),
isClosedForRecommendation: boolean(),
isThreaded: boolean(),
title: string(),
comments: array(union([replySchema, commentSchema])),
}),
});
export const discussionApiResponseSchema = variant('status', [
discussionApiErrorSchema,
discussionApiSuccessSchema,
]);
export type GetDiscussionResponse = Input<typeof discussionApiResponseSchema>;
export interface DiscussionOptions {
orderBy: string;
pageSize: number;
displayThreaded: boolean;
maxResponses: number;
page: number;
'api-key': string;
}
export type AdditionalHeadersType = { [key: string]: string };
export type DropdownOptionType = {
value: string;
title: string;
disabled?: boolean;
isActive?: boolean;
};
export const pickResponseSchema = object({
status: literal('ok'),
statusCode: literal(200),
message: string(),
});
const recommendResponseSchema = object({
status: literal('ok'),
statusCode: literal(200),
});
export const parseRecommendResponse = (
data: unknown,
): Result<'ParsingError', true> => {
const { success } = safeParse(recommendResponseSchema, data);
return success ? ok(true) : error('ParsingError');
};
export type CommentFormProps = {
userNameMissing: boolean;
error: string;
previewBody: string;
};
export const getCommentContextResponseSchema = object({
status: literal('ok'),
commentId: number(),
commentAncestorId: number(),
discussionKey: string(),
discussionWebUrl: string(),
discussionApiUrl: string(),
orderBy: picklist(orderBy),
pageSize: picklist(pageSize),
page: number(),
});
/** for development purposes only! */
export const stubUser = {
kind: 'Reader',
addUsername: () => Promise.resolve(error('This is a stub user')),
onComment: () =>
Promise.resolve(
ok(
String(
Number.MAX_SAFE_INTEGER - Math.ceil(Math.random() * 12_000),
),
),
),
onRecommend: () => Promise.resolve(true),
onReply: () => Promise.resolve(error('API_ERROR')),
reportAbuse: () => Promise.resolve(error('Invalid')),
profile: {