Skip to content

Commit

Permalink
fix(clerk-js,types): Warn about publicUserData.profileImageUrl deprec…
Browse files Browse the repository at this point in the history
…ation warning (#1812)

To support the nested property deprecation we introduced a
class to handle loading the PublicUserData and added a
deprecation warning on that class profileImageUrl property.
This changed was introduced based on the example of how the
OrganizationMembership loads the Organization data.
  • Loading branch information
dimkl committed Oct 2, 2023
1 parent b59b6b7 commit 71bb1c7
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 30 deletions.
6 changes: 6 additions & 0 deletions .changeset/stale-parrots-drop.md
@@ -0,0 +1,6 @@
---
'@clerk/clerk-js': patch
'@clerk/types': patch
---

Warn about `publicUserData.profileImageUrl` nested property deprecation in `OrganizationMembership` & `OrganizationMembershipRequest` resources.
15 changes: 2 additions & 13 deletions packages/clerk-js/src/core/resources/OrganizationMembership.ts
Expand Up @@ -11,7 +11,7 @@ import type {

import { unixEpochToDate } from '../../utils/date';
import { convertPageToOffset } from '../../utils/pagesToOffset';
import { BaseResource, Organization } from './internal';
import { BaseResource, Organization, OrganizationPublicUserData } from './internal';

export class OrganizationMembership extends BaseResource implements OrganizationMembershipResource {
id!: string;
Expand Down Expand Up @@ -105,15 +105,7 @@ export class OrganizationMembership extends BaseResource implements Organization
this.organization = new Organization(data.organization);
this.publicMetadata = data.public_metadata;
if (data.public_user_data) {
this.publicUserData = {
firstName: data.public_user_data.first_name,
lastName: data.public_user_data.last_name,
profileImageUrl: data.public_user_data.profile_image_url,
imageUrl: data.public_user_data.image_url,
hasImage: data.public_user_data.has_image,
identifier: data.public_user_data.identifier,
userId: data.public_user_data.user_id,
};
this.publicUserData = new OrganizationPublicUserData(data.public_user_data);
}
this.role = data.role;
this.createdAt = unixEpochToDate(data.created_at);
Expand All @@ -138,9 +130,6 @@ export class OrganizationMembership extends BaseResource implements Organization
}
}

// TODO(@dimkl): deprecate nested property
// deprecatedProperty(OrganizationMembership, 'publicUserData.profileImageUrl', 'Use `imageUrl` instead.');

export type UpdateOrganizationMembershipParams = {
role: MembershipRole;
};
Expand Down
Expand Up @@ -2,7 +2,7 @@ import type { OrganizationInvitationStatus, OrganizationMembershipRequestResourc
import type { OrganizationMembershipRequestJSON } from '@clerk/types';

import { unixEpochToDate } from '../../utils/date';
import { BaseResource } from './Base';
import { BaseResource, OrganizationPublicUserData } from './internal';

export class OrganizationMembershipRequest extends BaseResource implements OrganizationMembershipRequestResource {
id!: string;
Expand Down Expand Up @@ -37,20 +37,9 @@ export class OrganizationMembershipRequest extends BaseResource implements Organ
this.createdAt = unixEpochToDate(data.created_at);
this.updatedAt = unixEpochToDate(data.updated_at);
if (data.public_user_data) {
this.publicUserData = {
firstName: data.public_user_data.first_name,
lastName: data.public_user_data.last_name,
profileImageUrl: data.public_user_data.profile_image_url,
imageUrl: data.public_user_data.image_url,
hasImage: data.public_user_data.has_image,
identifier: data.public_user_data.identifier,
userId: data.public_user_data.user_id,
};
this.publicUserData = new OrganizationPublicUserData(data.public_user_data);
}
}
return this;
}
}

// TODO(@dimkl): deprecate nested property
// deprecatedProperty(OrganizationMembershipRequest, 'publicUserData.profileImageUrl', 'Use `imageUrl` instead.');
36 changes: 36 additions & 0 deletions packages/clerk-js/src/core/resources/OrganizationPublicUserData.ts
@@ -0,0 +1,36 @@
import { deprecatedProperty } from '@clerk/shared';
import type { PublicUserData } from '@clerk/types';
import type { PublicUserDataJSON } from '@clerk/types';

export class OrganizationPublicUserData implements PublicUserData {
firstName!: string | null;
lastName!: string | null;
/**
* @deprecated Use `imageUrl` instead.
*/
profileImageUrl!: string;
imageUrl!: string;
hasImage!: boolean;
identifier!: string;
userId?: string;

constructor(data: PublicUserDataJSON) {
this.fromJSON(data);
}

protected fromJSON(data: PublicUserDataJSON | null): this {
if (data) {
this.firstName = data.first_name;
this.lastName = data.last_name;
this.profileImageUrl = data.profile_image_url;
this.imageUrl = data.image_url;
this.hasImage = data.has_image;
this.identifier = data.identifier;
this.userId = data.user_id;
}

return this;
}
}

deprecatedProperty(OrganizationPublicUserData, 'profileImageUrl', 'Use `imageUrl` instead.');
Expand Up @@ -41,13 +41,12 @@ OrganizationMembership {
"publicMetadata": {
"foo": "bar",
},
"publicUserData": {
"publicUserData": OrganizationPublicUserData {
"firstName": "test_first_name",
"hasImage": true,
"identifier": "test@identifier.gr",
"imageUrl": "https://clerk.com",
"lastName": "test_last_name",
"profileImageUrl": "test_url",
"userId": undefined,
},
"role": "admin",
Expand Down
Expand Up @@ -7,13 +7,12 @@ OrganizationMembershipRequest {
"id": "test_id",
"organizationId": "test_org_id",
"pathRoot": "",
"publicUserData": {
"publicUserData": OrganizationPublicUserData {
"firstName": "test_first_name",
"hasImage": true,
"identifier": "test@identifier.gr",
"imageUrl": "https://clerk.com",
"lastName": "test_last_name",
"profileImageUrl": "test_url",
"userId": undefined,
},
"reject": [Function],
Expand Down
1 change: 1 addition & 0 deletions packages/clerk-js/src/core/resources/internal.ts
Expand Up @@ -17,6 +17,7 @@ export * from './OrganizationDomain';
export * from './OrganizationInvitation';
export * from './OrganizationMembership';
export * from './OrganizationMembershipRequest';
export * from './OrganizationPublicUserData';
export * from './OrganizationSuggestion';
export * from './SamlAccount';
export * from './Session';
Expand Down

0 comments on commit 71bb1c7

Please sign in to comment.