Skip to content

Commit 1e212c1

Browse files
authored
chore(clerk-js,backend,shared):Apply deprecation warnings @clerk/types (clerk#1823)
* fix(shared): Fix deprecatedObjectProperty key usage and support optional key arg * chore(clerk-js): Warn about orgs jwt claim deprecation * chore(backend): Warn about orgs jwt claim deprecation * chore(backend): Warn about apiKey deprecation * chore(backend): Fix typo in frontendApi deprecation warning * chore(clerk-react,clerk-js): Warn about PublishableKeyOrFrontendApi.frontendApi deprecations * chore(clerk-js): Warn about PublicUserData.profileImageUrl deprecations * chore(clerk-js): Warn about redirect_url deprecations * chore(clerk-js): Warn about password deprecations in User.update * chore(clerk-js): Warn about generateSignature deprecations * chore(clerk-js): Warn about afterSwitchOrganizationUrl deprecation * chore(clerk-js): Warn about UserData.profileImageUrl deprecations * chore(clerk-js): Use PublicUserData and UserData instead of multiple *UserData classes
1 parent c382411 commit 1e212c1

23 files changed

Lines changed: 150 additions & 29 deletions

.changeset/eighty-cobras-matter.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
'@clerk/clerk-js': patch
3+
'@clerk/backend': patch
4+
'@clerk/shared': patch
5+
'@clerk/clerk-react': patch
6+
---
7+
8+
Apply deprecation warnings for @clerk/types:
9+
10+
- `orgs` jwt claims
11+
- `apiKey`
12+
- `frontendApi`
13+
- `redirect_url`
14+
- `password`
15+
- `generateSignature`
16+
- `afterSwitchOrganizationUrl`
17+
- `profileImageUrl`

packages/backend/src/redirections.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export function redirect({ redirectAdapter, signUpUrl, signInUrl, frontendApi, p
4040
if (!frontendApi) {
4141
frontendApi = parsePublishableKey(publishableKey)?.frontendApi;
4242
} else {
43-
deprecated('frontentApi', 'Use `publishableKey` instead.');
43+
deprecated('frontendApi', 'Use `publishableKey` instead.');
4444
}
4545

4646
const accountsBaseUrl = buildAccountsBaseUrl(frontendApi);

packages/backend/src/tokens/authObjects.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { deprecated } from '@clerk/shared';
12
import type { ActClaim, JwtPayload, ServerGetToken, ServerGetTokenOptions } from '@clerk/types';
23

34
import type { Organization, Session, User } from '../api';
@@ -80,6 +81,10 @@ export function signedInAuthObject(
8081
} = sessionClaims;
8182
const { apiKey, secretKey, apiUrl, apiVersion, token, session, user, organization } = options;
8283

84+
if (apiKey) {
85+
deprecated('apiKey', 'Use `secretKey` instead.');
86+
}
87+
8388
const { sessions } = createBackendApiClient({
8489
apiKey,
8590
secretKey,
@@ -110,6 +115,10 @@ export function signedInAuthObject(
110115
}
111116

112117
export function signedOutAuthObject(debugData?: AuthObjectDebugData): SignedOutAuthObject {
118+
if (debugData?.apiKey) {
119+
deprecated('apiKey', 'Use `secretKey` instead.');
120+
}
121+
113122
return {
114123
sessionClaims: null,
115124
sessionId: null,

packages/backend/src/tokens/interstitial.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export type LoadInterstitialOptions = {
3535

3636
export function loadInterstitialFromLocal(options: Omit<LoadInterstitialOptions, 'apiUrl'>) {
3737
if (options.frontendApi) {
38-
deprecated('frontentApi', 'Use `publishableKey` instead.');
38+
deprecated('frontendApi', 'Use `publishableKey` instead.');
3939
}
4040
if (options.pkgVersion) {
4141
deprecated('pkgVersion', 'Use `clerkJSVersion` instead.');
@@ -135,7 +135,7 @@ export function loadInterstitialFromLocal(options: Omit<LoadInterstitialOptions,
135135
// TODO: Add caching to Interstitial
136136
export async function loadInterstitialFromBAPI(options: LoadInterstitialOptions) {
137137
if (options.frontendApi) {
138-
deprecated('frontentApi', 'Use `publishableKey` instead.');
138+
deprecated('frontendApi', 'Use `publishableKey` instead.');
139139
}
140140
if (options.pkgVersion) {
141141
deprecated('pkgVersion', 'Use `clerkJSVersion` instead.');
@@ -164,7 +164,7 @@ export async function loadInterstitialFromBAPI(options: LoadInterstitialOptions)
164164

165165
export function buildPublicInterstitialUrl(options: LoadInterstitialOptions) {
166166
if (options.frontendApi) {
167-
deprecated('frontentApi', 'Use `publishableKey` instead.');
167+
deprecated('frontendApi', 'Use `publishableKey` instead.');
168168
}
169169

170170
options.frontendApi = parsePublishableKey(options.publishableKey)?.frontendApi || options.frontendApi || '';

packages/backend/src/tokens/jwt/verifyJwt.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { deprecatedObjectProperty } from '@clerk/shared';
12
import type { Jwt, JwtPayload } from '@clerk/types';
23

34
// DO NOT CHANGE: Runtime needs to be imported as a default export so that we can stub its dependencies with Sinon.js
@@ -85,6 +86,13 @@ export function decodeJwt(token: string): Jwt {
8586
const payload = JSON.parse(decoder.decode(base64url.parse(rawPayload, { loose: true })));
8687
const signature = base64url.parse(rawSignature, { loose: true });
8788

89+
deprecatedObjectProperty(
90+
payload,
91+
'orgs',
92+
'Add orgs to your session token using the "user.organizations" shortcode in JWT Templates instead.',
93+
'decodeJwt:orgs',
94+
);
95+
8896
return {
8997
header,
9098
payload,

packages/backend/src/tokens/request.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export async function authenticateRequest(options: AuthenticateRequestOptions):
106106
const { cookies, headers, searchParams } = buildRequest(options?.request);
107107

108108
if (options.frontendApi) {
109-
deprecated('frontentApi', 'Use `publishableKey` instead.');
109+
deprecated('frontendApi', 'Use `publishableKey` instead.');
110110
}
111111

112112
if (options.apiKey) {

packages/clerk-js/src/core/clerk.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ export default class Clerk implements ClerkInterface {
245245
this.#proxyUrl = options?.proxyUrl;
246246

247247
if (isLegacyFrontendApiKey(key)) {
248+
deprecated('frontendApi', 'Use `publishableKey` instead.');
249+
248250
if (!validateFrontendApi(key)) {
249251
errorThrower.throwInvalidFrontendApiError({ key });
250252
}

packages/clerk-js/src/core/resources/OrganizationMembership.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@ import type {
66
MembershipRole,
77
OrganizationMembershipJSON,
88
OrganizationMembershipResource,
9-
PublicUserData,
109
} from '@clerk/types';
1110

1211
import { unixEpochToDate } from '../../utils/date';
1312
import { convertPageToOffset } from '../../utils/pagesToOffset';
14-
import { BaseResource, Organization, OrganizationPublicUserData } from './internal';
13+
import { BaseResource, Organization, PublicUserData } from './internal';
1514

1615
export class OrganizationMembership extends BaseResource implements OrganizationMembershipResource {
1716
id!: string;
@@ -105,7 +104,7 @@ export class OrganizationMembership extends BaseResource implements Organization
105104
this.organization = new Organization(data.organization);
106105
this.publicMetadata = data.public_metadata;
107106
if (data.public_user_data) {
108-
this.publicUserData = new OrganizationPublicUserData(data.public_user_data);
107+
this.publicUserData = new PublicUserData(data.public_user_data);
109108
}
110109
this.role = data.role;
111110
this.createdAt = unixEpochToDate(data.created_at);

packages/clerk-js/src/core/resources/OrganizationMembershipRequest.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import type { OrganizationInvitationStatus, OrganizationMembershipRequestResource, PublicUserData } from '@clerk/types';
1+
import type { OrganizationInvitationStatus, OrganizationMembershipRequestResource } from '@clerk/types';
22
import type { OrganizationMembershipRequestJSON } from '@clerk/types';
33

44
import { unixEpochToDate } from '../../utils/date';
5-
import { BaseResource, OrganizationPublicUserData } from './internal';
5+
import { BaseResource, PublicUserData } from './internal';
66

77
export class OrganizationMembershipRequest extends BaseResource implements OrganizationMembershipRequestResource {
88
id!: string;
@@ -37,7 +37,7 @@ export class OrganizationMembershipRequest extends BaseResource implements Organ
3737
this.createdAt = unixEpochToDate(data.created_at);
3838
this.updatedAt = unixEpochToDate(data.updated_at);
3939
if (data.public_user_data) {
40-
this.publicUserData = new OrganizationPublicUserData(data.public_user_data);
40+
this.publicUserData = new PublicUserData(data.public_user_data);
4141
}
4242
}
4343
return this;

packages/clerk-js/src/core/resources/OrganizationPublicUserData.ts renamed to packages/clerk-js/src/core/resources/PublicUserData.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { deprecatedProperty } from '@clerk/shared';
2-
import type { PublicUserData } from '@clerk/types';
2+
import type { PublicUserData as IPublicUserData } from '@clerk/types';
33
import type { PublicUserDataJSON } from '@clerk/types';
44

5-
export class OrganizationPublicUserData implements PublicUserData {
5+
export class PublicUserData implements IPublicUserData {
66
firstName!: string | null;
77
lastName!: string | null;
88
/**
@@ -33,4 +33,4 @@ export class OrganizationPublicUserData implements PublicUserData {
3333
}
3434
}
3535

36-
deprecatedProperty(OrganizationPublicUserData, 'profileImageUrl', 'Use `imageUrl` instead.');
36+
deprecatedProperty(PublicUserData, 'profileImageUrl', 'Use `imageUrl` instead.');

0 commit comments

Comments
 (0)