Source: types.js

/**
 * @file Types for Mangrove Reviews
 * @module mangrove-types
 */

/**
 * @typedef {Object} Reviews
 * @property {Review[]} reviews A list of reviews satisfying the query.
 * @property {Object.<string, Issuer>|null} [issuers] A map from public keys to information about issuers.
 * @property {Object.<string, Subject>|null} [maresi_subjects] A map from Review identifiers (`urn:maresi:<signature>`) to information about the reviews of that review.
 */

/**
 * @typedef {Object} Subject
 * @property {string} sub URI uniquely identifying the subject.
 * @property {number|null} quality Aggregate number representing quality of the subject.
 * @property {number} count Number of reviews given to this subject.
 * @property {number} opinion_count Number of reviews which included an opinion.
 * @property {number} positive_count Number of reviews with rating above 50 given to this subject.
 * @property {number} confirmed_count Number of reviews with rating above 50 and `is_personal_experience` flag given to this subject.
 */

/**
 * @typedef {Object} Issuer
 * @property {number} count Number of reviews written by this issuer.
 * @property {number} [credibility] Credibility score for this reviewer based on review quality (0 to 1).
 */

/**
 * @typedef {Object} Keypair WebCrypto keypair
 * @property {CryptoKey} privateKey
 * @property {CryptoKey} publicKey
 */

/**
 * @typedef {Object} BatchReturn
 * @property {Object.<string, Issuer>|null} [issuers] Map of issuer public keys to issuer information.
 * @property {Object.<string, Subject>|null} [subjects] Map of subject identifiers to subject information.
 */

/**
 * @typedef {Object} Review
 * @property {string} signature JWT signature by the review issuer.
 * @property {string} jwt Review in JWT format.
 * @property {string} kid Public key of the reviewer in PEM format.
 * @property {Payload} payload Primary content of the review.
 */

/**
 * @typedef {Object} Payload
 * @property {string} sub URI of the review subject.
 * @property {number} [rating] Rating of a subject between 0 and 100.
 * @property {string} [opinion] Opinion of a subject with at most 500 characters.
 * @property {string} [action] Action to perform on an existing review.
 *  Must be one of 'delete', 'edit', or 'report_abuse'.
 *  When present, the subfield must reference an existing review using the urn:maresi: scheme.
 * @property {number} [iat] Unix timestamp of when review was issued,
 *  gets filled in automatically if not provided.
 * @property {Object[]} [images] Array of up to 5 images to be included.
 * @property {string} images[].src Public URL of an image.
 * @property {string} [images[].label] Optional label of an image.
 * @property {Metadata} [metadata]
 *  Any {@link Metadata} relating to the issuer or circumstances of leaving review.
 *  See the [Mangrove Review Standard](https://mangrove.reviews/standard) for more.
 */

/**
 * @typedef {Object} Metadata
 * @property {string} [client_id]
 *  The identity of the client used to leave the review gets populated if not provided.
 * @property {string} [nickname] Nickname of the reviewer.
 * @property {string} [given_name] User's given name.
 * @property {string} [family_name] User's family name.
 * @property {number} [age] User's age must be 200 or less.
 * @property {string} [gender] User's gender.
 * @property {string} [experience_context] Should be one of common contexts
 *  in which the reviewer primarly had experience with the subject:
 *  `business`, `family`, `couple`, `friends`, `solo`
 * @property {boolean} [is_personal_experience] Please set this flag to `true`
 *  when the reviewer had direct experience with the subject of the review
 *  and is not based on a third party account.
 * @property {boolean} [is_affiliated] Please set this flag to `true`
 *  when the review is left by an owner, employee, or other affiliated person.
 * @property {boolean} [is_generated] Please set this flag to `true`
 *  when review was automatically generated by a bot.
 * @property {string} [data_source] Please provide the source of the review
 *  if the review does not originate from the author.
 * @property {string} [openid] OpenID identifier.
 * @property {string} [preferred_username] User's preferred username.
 * @property {string} [birthdate] User's birthdate.
 * @property {number} [issuer_index] Index related to the issuer, must be a valid
 *  JavaScript safe integer (less than or equal to 9,007,199,254,740,991).
 */