-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(clerk-js,types): Fetch custom roles and localize them (#2004)
* feat(clerk-js,types): Fetch custom roles and localize them * test(clerk-js): Fetch custom roles and localize them * feat(clerk-js,types): Create PermissionResource * chore(clerk-js): Add changeset * chore(clerk-js): Add experimental tags * test(clerk-js): Add test case for displaying custom roles in select menu * chore(clerk-js): Improve types & add comments * chore(clerk-js): Address PR comments
- Loading branch information
1 parent
7644b74
commit 0293f29
Showing
23 changed files
with
416 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
'@clerk/clerk-js': minor | ||
'@clerk/types': minor | ||
--- | ||
|
||
Add support for custom roles in `<OrganizationProfile/>`. | ||
|
||
The previous roles (`admin` and `basic_member`), are still kept as a fallback. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import type { PermissionJSON, PermissionResource } from '@clerk/types'; | ||
|
||
import { unixEpochToDate } from '../../utils/date'; | ||
import { BaseResource } from './internal'; | ||
|
||
/** | ||
* @experimental | ||
*/ | ||
export class Permission extends BaseResource implements PermissionResource { | ||
id!: string; | ||
key!: string; | ||
name!: string; | ||
description!: string; | ||
type!: 'system' | 'user'; | ||
createdAt!: Date; | ||
updatedAt!: Date; | ||
|
||
constructor(data: PermissionJSON) { | ||
super(); | ||
this.fromJSON(data); | ||
} | ||
|
||
protected fromJSON(data: PermissionJSON | null): this { | ||
if (!data) { | ||
return this; | ||
} | ||
|
||
this.id = data.id; | ||
this.key = data.key; | ||
this.name = data.name; | ||
this.description = data.description; | ||
this.type = data.type; | ||
this.createdAt = unixEpochToDate(data.created_at); | ||
this.updatedAt = unixEpochToDate(data.updated_at); | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import type { RoleJSON, RoleResource } from '@clerk/types'; | ||
|
||
import { unixEpochToDate } from '../../utils/date'; | ||
import { BaseResource } from './internal'; | ||
import { Permission } from './Permission'; | ||
|
||
/** | ||
* @experimental | ||
*/ | ||
export class Role extends BaseResource implements RoleResource { | ||
id!: string; | ||
key!: string; | ||
name!: string; | ||
description!: string; | ||
permissions: Permission[] = []; | ||
createdAt!: Date; | ||
updatedAt!: Date; | ||
|
||
constructor(data: RoleJSON) { | ||
super(); | ||
this.fromJSON(data); | ||
} | ||
|
||
protected fromJSON(data: RoleJSON | null): this { | ||
if (!data) { | ||
return this; | ||
} | ||
|
||
this.id = data.id; | ||
this.key = data.key; | ||
this.name = data.name; | ||
this.description = data.description; | ||
this.permissions = data.permissions.map(perm => new Permission(perm)); | ||
this.createdAt = unixEpochToDate(data.created_at); | ||
this.updatedAt = unixEpochToDate(data.updated_at); | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.