-
Notifications
You must be signed in to change notification settings - Fork 425
feat(ui,clerk-js,shared): Surface organization creation defaults #7488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
LauraBeatris
wants to merge
17
commits into
main
Choose a base branch
from
laura/orgs-1136-update-taskchooseorganization-to-show-warning-when
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
e401daa
Add `OrganizationCreationDefaults` resource
LauraBeatris 700303b
Add TODOs for UI tests
LauraBeatris 15c8470
Add alert for creation advisory
LauraBeatris 0883107
Update entity to include form defaults
LauraBeatris 0c0b955
Render logo field
LauraBeatris 6a3125a
Add `organizationCreationDefaults` to environment resource
LauraBeatris 0aa3266
Prefill with org defaults
LauraBeatris f6b80b9
Conditionally fetch for defaults
LauraBeatris b420efe
Include meta into advisory message
LauraBeatris 8a0e469
Implement tests
LauraBeatris 6d3189d
Add changeset
LauraBeatris 51300f1
Finish integrating with advisory
LauraBeatris 6b2fd40
Use loading spinner for loading status
LauraBeatris 87d56ea
Add delay to trigger loading spinner
LauraBeatris 437ada9
Bump max bundle size
LauraBeatris 988a6da
Include organization name in advisory message
LauraBeatris ce1d552
Fix unit tests
LauraBeatris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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/localizations': minor | ||
| '@clerk/clerk-js': minor | ||
| '@clerk/shared': minor | ||
| '@clerk/ui': minor | ||
| --- | ||
|
|
||
| Surface organization creation defaults with prefilled form fields and advisory warnings |
This file contains hidden or 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
80 changes: 80 additions & 0 deletions
80
packages/clerk-js/src/core/resources/OrganizationCreationDefaults.ts
This file contains hidden or 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,80 @@ | ||
| import type { | ||
| OrganizationCreationAdvisorySeverity, | ||
| OrganizationCreationAdvisoryType, | ||
| OrganizationCreationDefaultsJSON, | ||
| OrganizationCreationDefaultsJSONSnapshot, | ||
| OrganizationCreationDefaultsResource, | ||
| } from '@clerk/shared/types'; | ||
|
|
||
| import { BaseResource } from './internal'; | ||
|
|
||
| export class OrganizationCreationDefaults extends BaseResource implements OrganizationCreationDefaultsResource { | ||
| advisory: { | ||
| code: OrganizationCreationAdvisoryType; | ||
| severity: OrganizationCreationAdvisorySeverity; | ||
| meta: Record<string, string>; | ||
| } | null = null; | ||
| form: { | ||
| name: string; | ||
| slug: string; | ||
| logo: string | null; | ||
| blurHash: string | null; | ||
| } = { | ||
| name: '', | ||
| slug: '', | ||
| logo: null, | ||
| blurHash: null, | ||
| }; | ||
|
|
||
| public constructor(data: OrganizationCreationDefaultsJSON | OrganizationCreationDefaultsJSONSnapshot | null = null) { | ||
| super(); | ||
| this.fromJSON(data); | ||
| } | ||
|
|
||
| protected fromJSON(data: OrganizationCreationDefaultsJSON | OrganizationCreationDefaultsJSONSnapshot | null): this { | ||
| if (!data) { | ||
| return this; | ||
| } | ||
|
|
||
| if (data.advisory) { | ||
| this.advisory = this.withDefault(data.advisory, this.advisory ?? null); | ||
| } | ||
|
|
||
| if (data.form) { | ||
| this.form.name = this.withDefault(data.form.name, this.form.name); | ||
| this.form.slug = this.withDefault(data.form.slug, this.form.slug); | ||
| this.form.logo = this.withDefault(data.form.logo, this.form.logo); | ||
| this.form.blurHash = this.withDefault(data.form.blur_hash, this.form.blurHash); | ||
| } | ||
|
|
||
| return this; | ||
| } | ||
|
|
||
| static async retrieve(): Promise<OrganizationCreationDefaultsResource> { | ||
| return await BaseResource._fetch({ | ||
| path: '/me/organization_creation_defaults', | ||
| method: 'GET', | ||
| }).then(res => { | ||
| const data = res?.response as unknown as OrganizationCreationDefaultsJSON; | ||
| return new OrganizationCreationDefaults(data); | ||
| }); | ||
| } | ||
|
|
||
| public __internal_toSnapshot(): OrganizationCreationDefaultsJSONSnapshot { | ||
| return { | ||
| advisory: this.advisory | ||
| ? { | ||
| code: this.advisory.code, | ||
| meta: this.advisory.meta, | ||
| severity: this.advisory.severity, | ||
| } | ||
| : null, | ||
| form: { | ||
| name: this.form.name, | ||
| slug: this.form.slug, | ||
| logo: this.form.logo, | ||
| blur_hash: this.form.blurHash, | ||
| }, | ||
| } as unknown as OrganizationCreationDefaultsJSONSnapshot; | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unsafe type casting bypasses validation and could cause runtime errors.
Line 55 uses
as unknown as OrganizationCreationDefaultsJSONto force-cast the API response without any validation. If the API returns malformed data or the response structure changes, this will bypass type safety and could cause runtime errors when the resource properties are accessed.🔎 Proposed fix with runtime validation
static async retrieve(): Promise<OrganizationCreationDefaultsResource> { return await BaseResource._fetch({ path: '/me/organization_creation_defaults', method: 'GET', }).then(res => { - const data = res?.response as unknown as OrganizationCreationDefaultsJSON; + const data = res?.response; + // Basic runtime validation + if (!data || typeof data !== 'object') { + throw new Error('Invalid organization creation defaults response'); + } return new OrganizationCreationDefaults(data); }); }🤖 Prompt for AI Agents