From de6f3fd751818a84dc3cb2d33d5c4efeb7895122 Mon Sep 17 00:00:00 2001 From: Travis Fischer Date: Fri, 28 Feb 2025 06:16:35 +0700 Subject: [PATCH] feat: improve gravatar profile types --- packages/gravatar/src/gravatar-client.ts | 60 +++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/packages/gravatar/src/gravatar-client.ts b/packages/gravatar/src/gravatar-client.ts index 6f51fd9a..88474b3c 100644 --- a/packages/gravatar/src/gravatar-client.ts +++ b/packages/gravatar/src/gravatar-client.ts @@ -34,6 +34,8 @@ export namespace gravatar { hash: string /** The user’s display name that appears on their profile. */ display_name: string + first_name?: string + last_name?: string /** The full URL to the user’s Gravatar profile. */ profile_url: string /** The URL to the user’s avatar image, if set. */ @@ -49,12 +51,21 @@ export namespace gravatar { /** The name of the company where the user is employed. */ company: string /** An array of verified accounts the user has added to their profile. The number of verified accounts displayed is limited to a maximum of 4 in unauthenticated requests. */ - verified_accounts: any[] + verified_accounts: Account[] /** A phonetic guide to pronouncing the user’s name. */ pronunciation: string /** The pronouns the user prefers to use. */ pronouns: string + is_organization?: boolean + links?: Link[] + interests?: any[] + gallery?: Image[] + payments?: { + links?: any[] + crypto_wallets?: CryptoWallet[] + } + /** The total number of verified accounts the user has added to their profile, including those not displayed on their profile. This property is only provided in authenticated API requests. */ number_verified_accounts?: number @@ -63,6 +74,40 @@ export namespace gravatar { /** The date the user registered their account. This property is only provided in authenticated API requests. Example: "2021-10-01" */ registration_date?: string + + contact_info?: ContactInfo + } + + export interface Account { + service_type: string + service_label: string + service_icon: string + url: string + is_hidden: boolean + } + + export interface Link { + label: string + url: string + } + + export interface Image { + url: string + alt_text: string + } + + export interface CryptoWallet { + label: string + address: string + } + + export interface ContactInfo { + home_phone: string + work_phone: string + cell_phone: string + email: string + contact_form: string + calendar: string } } @@ -145,4 +190,17 @@ export class GravatarClient extends AIFunctionsProvider { throw err } } + + async getAvatarForIdentifier( + emailOrOpts: string | gravatar.GetProfileByIdentifierOptions + ): Promise { + const { email } = + typeof emailOrOpts === 'string' ? { email: emailOrOpts } : emailOrOpts + const hashedEmail = crypto + .createHash('SHA256') + .update(email.trim().toLowerCase(), 'utf8') + .digest('hex') + + return `https://gravatar.com/avatar/${hashedEmail}` + } }