Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/stale-parrots-drop.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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.');
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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