Skip to content

Commit de6f3fd

Browse files
feat: improve gravatar profile types
1 parent f7d074a commit de6f3fd

File tree

1 file changed

+59
-1
lines changed

1 file changed

+59
-1
lines changed

packages/gravatar/src/gravatar-client.ts

+59-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export namespace gravatar {
3434
hash: string
3535
/** The user’s display name that appears on their profile. */
3636
display_name: string
37+
first_name?: string
38+
last_name?: string
3739
/** The full URL to the user’s Gravatar profile. */
3840
profile_url: string
3941
/** The URL to the user’s avatar image, if set. */
@@ -49,12 +51,21 @@ export namespace gravatar {
4951
/** The name of the company where the user is employed. */
5052
company: string
5153
/** 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. */
52-
verified_accounts: any[]
54+
verified_accounts: Account[]
5355
/** A phonetic guide to pronouncing the user’s name. */
5456
pronunciation: string
5557
/** The pronouns the user prefers to use. */
5658
pronouns: string
5759

60+
is_organization?: boolean
61+
links?: Link[]
62+
interests?: any[]
63+
gallery?: Image[]
64+
payments?: {
65+
links?: any[]
66+
crypto_wallets?: CryptoWallet[]
67+
}
68+
5869
/** 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. */
5970
number_verified_accounts?: number
6071

@@ -63,6 +74,40 @@ export namespace gravatar {
6374

6475
/** The date the user registered their account. This property is only provided in authenticated API requests. Example: "2021-10-01" */
6576
registration_date?: string
77+
78+
contact_info?: ContactInfo
79+
}
80+
81+
export interface Account {
82+
service_type: string
83+
service_label: string
84+
service_icon: string
85+
url: string
86+
is_hidden: boolean
87+
}
88+
89+
export interface Link {
90+
label: string
91+
url: string
92+
}
93+
94+
export interface Image {
95+
url: string
96+
alt_text: string
97+
}
98+
99+
export interface CryptoWallet {
100+
label: string
101+
address: string
102+
}
103+
104+
export interface ContactInfo {
105+
home_phone: string
106+
work_phone: string
107+
cell_phone: string
108+
email: string
109+
contact_form: string
110+
calendar: string
66111
}
67112
}
68113

@@ -145,4 +190,17 @@ export class GravatarClient extends AIFunctionsProvider {
145190
throw err
146191
}
147192
}
193+
194+
async getAvatarForIdentifier(
195+
emailOrOpts: string | gravatar.GetProfileByIdentifierOptions
196+
): Promise<string> {
197+
const { email } =
198+
typeof emailOrOpts === 'string' ? { email: emailOrOpts } : emailOrOpts
199+
const hashedEmail = crypto
200+
.createHash('SHA256')
201+
.update(email.trim().toLowerCase(), 'utf8')
202+
.digest('hex')
203+
204+
return `https://gravatar.com/avatar/${hashedEmail}`
205+
}
148206
}

0 commit comments

Comments
 (0)