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
13 changes: 13 additions & 0 deletions .changeset/cuddly-cougars-check.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
---
'@clerk/shared': major
'@clerk/clerk-react': major
---

Drop deprecations. Migration steps:
- use `EmailLinkError` instead of `MagicLinkError`
- use `isEmailLinkError` instead of `isMagicLinkError`
- use `EmailLinkErrorCode` instead of `MagicLinkErrorCode`
- use `useEmailLink` instead of `useMagicLink`
- use `buildRequestUrl` from `@clerk/backend` instead of `getRequestUrl` from `@clerk/shared`
- use `OrganizationProvider` instead of `OrganizationContext`
- use `userMemberships` instead of `organizationList` from `useOrganizationList`
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,15 +38,6 @@ describe('useOrganizationList', () => {
expect(result.current.isLoaded).toBe(true);
expect(result.current.setActive).toBeDefined();
expect(result.current.createOrganization).toBeDefined();
expect(result.current.organizationList).toEqual(
expect.arrayContaining([
expect.objectContaining({
membership: expect.objectContaining({
role: 'basic_member',
}),
}),
]),
);

expect(result.current.userInvitations).toEqual(
expect.objectContaining({
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/contexts/OrganizationContext.tsx
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
export { OrganizationProvider, OrganizationContext, useOrganizationContext } from '@clerk/shared/react';
export { OrganizationProvider, useOrganizationContext } from '@clerk/shared/react';
40 changes: 0 additions & 40 deletions packages/shared/src/error.ts
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
import type { ClerkAPIError, ClerkAPIErrorJSON } from '@clerk/types';

import { deprecated } from './deprecated';

export function isUnauthorizedError(e: any): boolean {
const status = e?.status;
const code = e?.errors?.[0]?.code;
Expand DownExpand Up@@ -169,20 +167,6 @@ export class ClerkRuntimeError extends Error {
};
}

/**
* @deprecated Use `EmailLinkError` instead.
*/
export class MagicLinkError extends Error {
code: string;

constructor(code: string) {
super(code);
this.code = code;
Object.setPrototypeOf(this, MagicLinkError.prototype);
deprecated('MagicLinkError', 'Use `EmailLinkError` instead.');
}
}

export class EmailLinkError extends Error {
code: string;

Expand All@@ -193,34 +177,10 @@ export class EmailLinkError extends Error {
}
}

/**
* Check if the error is a MagicLinkError.
* @deprecated Use `isEmailLinkError` instead.
*/
export function isMagicLinkError(err: Error): err is MagicLinkError {
deprecated('isMagicLinkError', 'Use `isEmailLinkError` instead.');
return err instanceof MagicLinkError;
}

export function isEmailLinkError(err: Error): err is EmailLinkError {
return err instanceof EmailLinkError;
}

const _MagicLinkErrorCode = {
Expired: 'expired',
Failed: 'failed',
};

/**
* @deprecated Use `EmailLinkErrorCode` instead.
*/
export const MagicLinkErrorCode = new Proxy(_MagicLinkErrorCode, {
get(target, prop, receiver) {
deprecated('MagicLinkErrorCode', 'Use `EmailLinkErrorCode` instead.');
return Reflect.get(target, prop, receiver);
},
});

export const EmailLinkErrorCode = {
Expired: 'expired',
Failed: 'failed',
Expand Down
19 changes: 0 additions & 19 deletions packages/shared/src/proxy.ts
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
import { deprecated } from './deprecated';

export function isValidProxyUrl(key: string | undefined) {
if (!key) {
return true;
Expand All@@ -22,20 +20,3 @@ export function proxyUrlToAbsoluteURL(url: string | undefined): string {
}
return isProxyUrlRelative(url) ? new URL(url, window.location.origin).toString() : url;
}

/**
* @deprecated Use `buildRequestUrl` from @clerk/backend
*/
export function getRequestUrl({ request, relativePath }: { request: Request; relativePath?: string }): URL {
deprecated('getRequestUrl', 'Use `buildRequestUrl` from @clerk/backend instead.');
const { headers, url: initialUrl } = request;
const url = new URL(initialUrl);
const host = headers.get('X-Forwarded-Host') ?? headers.get('host') ?? (headers as any)['host'] ?? url.host;

// X-Forwarded-Proto could be 'https, http'
let protocol =
(headers.get('X-Forwarded-Proto') ?? (headers as any)['X-Forwarded-Proto'])?.split(',')[0] ?? url.protocol;
protocol = protocol.replace(/[:/]/, '');

return new URL(relativePath || url.pathname, `${protocol}://${host}`);
}
11 changes: 0 additions & 11 deletions packages/shared/src/react/contexts.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,15 +4,12 @@ import type {
ActiveSessionResource,
ClientResource,
LoadedClerk,
OrganizationInvitationResource,
OrganizationMembershipResource,
OrganizationResource,
UserResource,
} from '@clerk/types';
import type { PropsWithChildren } from 'react';
import React from 'react';

import { deprecated } from '../deprecated';
import { SWRConfig } from './clerk-swr';
import { createContextAndHook } from './hooks/createContextAndHook';

Expand DownExpand Up@@ -53,14 +50,6 @@ const OrganizationProvider = ({
);
};

/**
* @deprecated use OrganizationProvider instead
*/
export const OrganizationContext = (...args: Parameters<typeof OrganizationProvider>) => {
deprecated('OrganizationContext', 'Use `OrganizationProvider` instead');
return OrganizationProvider(...args);
};

export {
ClientContext,
useClientContext,
Expand Down
24 changes: 1 addition & 23 deletions packages/shared/src/react/hooks/useOrganizationList.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,7 +11,6 @@ import type {
UserOrganizationInvitationResource,
} from '@clerk/types';

import { deprecatedObjectProperty } from '../../deprecated';
import { useClerkInstanceContext, useUserContext } from '../contexts';
import type { PaginatedResources, PaginatedResourcesWithDefault } from '../types';
import { usePagesOrInfinite, useWithSafeValues } from './usePagesOrInfinite';
Expand All@@ -37,7 +36,6 @@ type UseOrganizationListParams = {
});
};

type OrganizationList = ReturnType<typeof createOrganizationList>;
const undefinedPaginatedResource = {
data: undefined,
count: undefined,
Expand All@@ -60,10 +58,6 @@ type UseOrganizationList = <T extends UseOrganizationListParams>(
) =>
| {
isLoaded: false;
/**
* @deprecated Use userMemberships instead
*/
organizationList: undefined;
createOrganization: undefined;
setActive: undefined;
userMemberships: PaginatedResourcesWithDefault<OrganizationMembershipResource>;
Expand All@@ -72,10 +66,6 @@ type UseOrganizationList = <T extends UseOrganizationListParams>(
}
| {
isLoaded: boolean;
/**
* @deprecated Use userMemberships instead
*/
organizationList: OrganizationList;
createOrganization: (params: CreateOrganizationParams) => Promise<OrganizationResource>;
setActive: SetActive;
userMemberships: PaginatedResources<
Expand DownExpand Up@@ -208,7 +198,6 @@ export const useOrganizationList: UseOrganizationList = params => {
if (!isClerkLoaded) {
return {
isLoaded: false,
organizationList: undefined,
createOrganization: undefined,
setActive: undefined,
userMemberships: undefinedPaginatedResource,
Expand All@@ -217,23 +206,12 @@ export const useOrganizationList: UseOrganizationList = params => {
};
}

const result = {
return {
isLoaded: isClerkLoaded,
organizationList: createOrganizationList(user.organizationMemberships),
setActive: clerk.setActive,
createOrganization: clerk.createOrganization,
userMemberships: memberships,
userInvitations: invitations,
userSuggestions: suggestions,
};
deprecatedObjectProperty(result, 'organizationList', 'Use `userMemberships` instead.');

return result;
};

function createOrganizationList(organizationMemberships: OrganizationMembershipResource[]) {
return organizationMemberships.map(organizationMembership => ({
membership: organizationMembership,
organization: organizationMembership.organization,
}));
}
1 change: 0 additions & 1 deletion packages/shared/src/react/index.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,7 +3,6 @@ export * from './hooks';
export {
ClerkInstanceContext,
ClientContext,
OrganizationContext,
OrganizationProvider,
SessionContext,
useClerkInstanceContext,
Expand Down