From 53d00202e26e8e8976aae6113e350c8506cca7f1 Mon Sep 17 00:00:00 2001 From: Haris Chaniotakis Date: Fri, 4 Mar 2022 18:37:34 +0200 Subject: [PATCH] feat(types,backend-core,clerk-js): Add external account properties username, publicMetadata & label --- .../backend-core/src/__tests__/apis/UserApi.test.ts | 6 ++++++ .../src/__tests__/apis/responses/getUser.json | 12 ++++++++++-- .../src/api/resources/ExternalAccount.ts | 6 ++++++ packages/backend-core/src/api/resources/JSON.ts | 9 +++++++++ packages/backend-core/src/api/resources/Props.ts | 3 +++ .../clerk-js/src/core/resources/ExternalAccount.ts | 9 +++++++++ packages/types/src/externalAccount.ts | 3 +++ packages/types/src/json.ts | 9 +++++++++ 8 files changed, 55 insertions(+), 2 deletions(-) diff --git a/packages/backend-core/src/__tests__/apis/UserApi.test.ts b/packages/backend-core/src/__tests__/apis/UserApi.test.ts index ed5377c06b..f0599a848e 100644 --- a/packages/backend-core/src/__tests__/apis/UserApi.test.ts +++ b/packages/backend-core/src/__tests__/apis/UserApi.test.ts @@ -115,7 +115,13 @@ test('getUser() returns a single user', async () => { expect(user.externalAccounts.length).toEqual(2); expect(user.externalAccounts[0].provider).toEqual('google'); + expect(user.externalAccounts[0].username).toEqual('tester'); + expect(user.externalAccounts[0].publicMetadata).toBeInstanceOf(Object); + expect(user.externalAccounts[0].label).toBeNull(); expect(user.externalAccounts[1].provider).toEqual('facebook'); + expect(user.externalAccounts[1].username).toBeNull(); + expect(user.externalAccounts[1].publicMetadata).toMatchObject({'extra': 'more info'}); + expect(user.externalAccounts[1].label).toEqual('clerk'); expect(user.web3Wallets.length).toEqual(1); expect(user.web3Wallets[0].web3Wallet).toEqual( diff --git a/packages/backend-core/src/__tests__/apis/responses/getUser.json b/packages/backend-core/src/__tests__/apis/responses/getUser.json index 87b26f5561..afd0be25f1 100644 --- a/packages/backend-core/src/__tests__/apis/responses/getUser.json +++ b/packages/backend-core/src/__tests__/apis/responses/getUser.json @@ -91,7 +91,10 @@ "email_address": "kyle@tech.com", "given_name": "Kyle", "family_name": "Reese", - "picture": "https://lh3.googleusercontent.com/-MvTefx9nU6o/BBBBBBBBBBI/BBBBBBBBBBB/ereRAMWiew8hQ5IaSVdTZWm1Y1G1z0T_P7Q/s96-c/photo.jpg" + "picture": "https://lh3.googleusercontent.com/-MvTefx9nU6o/BBBBBBBBBBI/BBBBBBBBBBB/ereRAMWiew8hQ5IaSVdTZWm1Y1G1z0T_P7Q/s96-c/photo.jpg", + "username": "tester", + "public_metadata": {}, + "label": null }, { "object": "facebook_account", @@ -101,7 +104,12 @@ "email_address": "kyle@tech.com", "first_name": "Kyle", "last_name": "Reese", - "picture": "https://platform-lookaside.fbsbx.com/platform/profilepic/?asid=16357923188267094&height=50&width=50&ext=2319847405&hash=AeQyoXRpxMMso8vNHSw" + "picture": "https://platform-lookaside.fbsbx.com/platform/profilepic/?asid=16357923188267094&height=50&width=50&ext=2319847405&hash=AeQyoXRpxMMso8vNHSw", + "username": null, + "public_metadata": { + "extra": "more info" + }, + "label": "clerk" } ], "public_metadata": { diff --git a/packages/backend-core/src/api/resources/ExternalAccount.ts b/packages/backend-core/src/api/resources/ExternalAccount.ts index 461fc9beca..20496fa565 100644 --- a/packages/backend-core/src/api/resources/ExternalAccount.ts +++ b/packages/backend-core/src/api/resources/ExternalAccount.ts @@ -16,6 +16,9 @@ export class ExternalAccount { 'firstName', 'lastName', 'picture', + 'username', + 'publicMetadata', + 'label', ]; static defaults = {}; @@ -30,6 +33,9 @@ export class ExternalAccount { obj.id = data.id; obj.approvedScopes = data.approved_scopes; obj.emailAddress = data.email_address; + obj.username = data.username; + obj.publicMetadata = data.public_metadata; + obj.label = data.label; switch (data.object) { case ObjectType.FacebookAccount: { diff --git a/packages/backend-core/src/api/resources/JSON.ts b/packages/backend-core/src/api/resources/JSON.ts index 10e9d24b84..c1c4ecc9ea 100644 --- a/packages/backend-core/src/api/resources/JSON.ts +++ b/packages/backend-core/src/api/resources/JSON.ts @@ -74,6 +74,9 @@ export interface FacebookAccountJSON extends ClerkResourceJSON { first_name: string; last_name: string; picture: string; + username?: string; + public_metadata: Record; + label?: string; } export interface GoogleAccountJSON extends ClerkResourceJSON { @@ -84,6 +87,9 @@ export interface GoogleAccountJSON extends ClerkResourceJSON { given_name: string; family_name: string; picture: string; + username?: string; + public_metadata: Record; + label?: string; } export interface ExtAccountJSON extends ClerkResourceJSON { @@ -96,6 +102,9 @@ export interface ExtAccountJSON extends ClerkResourceJSON { first_name: string; last_name: string; avatar_url: string; + username?: string; + public_metadata: Record; + label?: string; } export type ExternalAccountJSON = diff --git a/packages/backend-core/src/api/resources/Props.ts b/packages/backend-core/src/api/resources/Props.ts index 53cf10b015..aabcfaf84c 100644 --- a/packages/backend-core/src/api/resources/Props.ts +++ b/packages/backend-core/src/api/resources/Props.ts @@ -51,6 +51,9 @@ export interface ExternalAccountProps extends ClerkProps { firstName: Nullable; lastName: Nullable; picture: Nullable; + username: Nullable; + publicMetadata: Record; + label: Nullable; } export interface IdentificationLinkProps extends ClerkProps { diff --git a/packages/clerk-js/src/core/resources/ExternalAccount.ts b/packages/clerk-js/src/core/resources/ExternalAccount.ts index 8800ee2234..e3bd98fcc8 100644 --- a/packages/clerk-js/src/core/resources/ExternalAccount.ts +++ b/packages/clerk-js/src/core/resources/ExternalAccount.ts @@ -14,6 +14,9 @@ export class ExternalAccount implements ExternalAccountResource { firstName: string; lastName: string; picture: string; + username?: string; + publicMetadata: Record; + label?: string; constructor(extAccProps: ExternalAccountResource) { this.id = extAccProps.id; @@ -24,6 +27,9 @@ export class ExternalAccount implements ExternalAccountResource { this.firstName = extAccProps.firstName; this.lastName = extAccProps.lastName; this.picture = extAccProps.picture; + this.username = extAccProps.username; + this.publicMetadata = extAccProps.publicMetadata; + this.label = extAccProps.label; } static fromJSON(data: ExternalAccountJSON): ExternalAccount { @@ -66,6 +72,9 @@ export class ExternalAccount implements ExternalAccountResource { // ${provider}_id key in order to set the externalId. // @ts-ignore obj.externalId = data.provider_user_id || data[`${obj.provider}_id`]; + obj.username = data.username; + obj.publicMetadata = data.public_metadata; + obj.label = data.label; return new ExternalAccount(obj); } diff --git a/packages/types/src/externalAccount.ts b/packages/types/src/externalAccount.ts index 80b3b9ab55..635ccc6312 100644 --- a/packages/types/src/externalAccount.ts +++ b/packages/types/src/externalAccount.ts @@ -9,6 +9,9 @@ export interface ExternalAccountResource { firstName: string; lastName: string; picture: string; + username?: string; + publicMetadata: Record; + label?: string; providerTitle: () => string; } diff --git a/packages/types/src/json.ts b/packages/types/src/json.ts index 8adb917a54..3941033a0f 100644 --- a/packages/types/src/json.ts +++ b/packages/types/src/json.ts @@ -298,6 +298,9 @@ export type ExternalAccountJSON = given_name: string; family_name: string; picture: string; + username?: string; + public_metadata: Record; + label?: string; } | { object: 'facebook_account'; @@ -308,6 +311,9 @@ export type ExternalAccountJSON = first_name: string; last_name: string; picture: string; + username?: string; + public_metadata: Record; + label?: string; } | { object: 'external_account'; @@ -319,6 +325,9 @@ export type ExternalAccountJSON = first_name: string; last_name: string; avatar_url: string; + username?: string; + public_metadata: Record; + label?: string; }; export interface OrganizationJSON extends ClerkResourceJSON {