Skip to content

Commit 451fc33

Browse files
authoredOct 11, 2023
chore(clerk-sdk-node): Drop noisy deprecation of unstable_options in sdk-node (clerk#1858)
The `sdk-node` package is extending the backend `Clerk` with some extra methods. To do this, we expose a different `Clerk` from the `sdk-node` that returns the `clerkClient` instance of backend with some extra methods. To add those extra methods to the return value we currently destruct the `clerkClient` to a new object and add the extra methods. By destructing the `clerkClient`, all it's methods and properties are being accessed, causing the `__unstable_options` deprecation warning to trigger and show the warning every time in applications using the `sdk-node` package. To resolve this, we introduced an `ExtendedClerk` type as the return value of the sdk-node `Clerk` and changed the destructing to `Object.assign(clerkClient, ...extra...)`.
1 parent d89c09b commit 451fc33

File tree

8 files changed

+25
-10
lines changed

8 files changed

+25
-10
lines changed
 

‎.changeset/seven-shrimps-train.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/clerk-sdk-node': patch
3+
---
4+
5+
Avoid always showing `__unstable_options` deprecation warning in all applications and SDKs using `@clerk/clerk-sdk-node`

‎packages/sdk-node/src/clerkClient.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@ import { createClerkExpressRequireAuth } from './clerkExpressRequireAuth';
55
import { createClerkExpressWithAuth } from './clerkExpressWithAuth';
66
import { loadApiEnv, loadClientEnv } from './utils';
77

8+
type ExtendedClerk = ReturnType<typeof _Clerk> & {
9+
expressWithAuth: ReturnType<typeof createClerkExpressWithAuth>;
10+
expressRequireAuth: ReturnType<typeof createClerkExpressRequireAuth>;
11+
verifyToken: typeof _verifyToken;
12+
} & ReturnType<typeof createBasePropForRedwoodCompatibility>;
13+
814
/**
915
* This needs to be a *named* function in order to support the older
1016
* new Clerk() syntax for v4 compatibility.
1117
* Arrow functions can never be called with the new keyword because they do not have the [[Construct]] method
1218
*/
13-
export function Clerk(options: ClerkOptions) {
19+
export function Clerk(options: ClerkOptions): ExtendedClerk {
1420
const clerkClient = _Clerk(options);
1521
const expressWithAuth = createClerkExpressWithAuth({ ...options, clerkClient });
1622
const expressRequireAuth = createClerkExpressRequireAuth({ ...options, clerkClient });
@@ -19,13 +25,12 @@ export function Clerk(options: ClerkOptions) {
1925
return _verifyToken(token, { issuer, ...options, ...verifyOpts });
2026
};
2127

22-
return {
23-
...clerkClient,
28+
return Object.assign(clerkClient, {
2429
expressWithAuth,
2530
expressRequireAuth,
2631
verifyToken,
2732
...createBasePropForRedwoodCompatibility(),
28-
};
33+
});
2934
}
3035

3136
const createBasePropForRedwoodCompatibility = () => {

‎playground/cra-js/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6-
"@clerk/clerk-react": "*",
6+
"@clerk/clerk-react": "file:.yalc/@clerk/clerk-react",
7+
"@clerk/shared": "file:.yalc/@clerk/shared",
8+
"@clerk/types": "file:.yalc/@clerk/types",
79
"@testing-library/jest-dom": "^5.16.5",
810
"@testing-library/react": "^13.4.0",
911
"@testing-library/user-event": "^13.5.0",

‎playground/express/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"dependencies": {
1313
"@clerk/backend": "file:.yalc/@clerk/backend",
1414
"@clerk/clerk-sdk-node": "file:.yalc/@clerk/clerk-sdk-node",
15+
"@clerk/shared": "file:.yalc/@clerk/shared",
1516
"@clerk/types": "file:.yalc/@clerk/types",
1617
"dotenv": "^16.0.3",
1718
"ejs": "^3.1.6",

‎playground/express/src/routes/private.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import type { Response } from 'express';
22

3-
import { ClerkExpressRequireAuth, clerkClient } from '@clerk/clerk-sdk-node';
3+
import { clerkClient } from '@clerk/clerk-sdk-node';
44
import { Router } from 'express';
55

66
const router = Router();
77

8-
router.use(ClerkExpressRequireAuth({ clerkClient }));
8+
router.use((...args)=>clerkClient.expressRequireAuth()(...args));
99

1010
router.get('/me', async (req, reply: Response) => {
1111
return reply.json({ auth: req.auth });

‎playground/fastify/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"dependencies": {
99
"@clerk/backend": "file:.yalc/@clerk/backend",
1010
"@clerk/fastify": "file:.yalc/@clerk/fastify",
11+
"@clerk/shared": "file:.yalc/@clerk/shared",
1112
"@clerk/types": "file:.yalc/@clerk/types",
1213
"@fastify/view": "^8.0.0",
1314
"dotenv": "^16.0.3",

‎playground/remix-cf-pages/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
"yalc:add": "yalc add @clerk/types && yalc add @clerk/remix && yalc add @clerk/backend"
1212
},
1313
"dependencies": {
14-
"@clerk/backend": "*",
15-
"@clerk/remix": "*",
16-
"@clerk/types": "*",
14+
"@clerk/backend": "file:.yalc/@clerk/backend",
15+
"@clerk/remix": "file:.yalc/@clerk/remix",
16+
"@clerk/types": "file:.yalc/@clerk/types",
1717
"@remix-run/cloudflare": "^2.0.0",
1818
"@remix-run/cloudflare-pages": "^2.0.0",
1919
"@remix-run/react": "^2.0.0",

‎playground/vite-react-ts/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"yalc": "yalc add -- @clerk/clerk-react @clerk/types @clerk/shared"
1313
},
1414
"dependencies": {
15+
"@clerk/clerk-js": "file:.yalc/@clerk/clerk-js",
1516
"@clerk/clerk-react": "file:.yalc/@clerk/clerk-react",
1617
"@clerk/shared": "file:.yalc/@clerk/shared",
1718
"@clerk/types": "file:.yalc/@clerk/types",

0 commit comments

Comments
 (0)
Please sign in to comment.