From 451fc332a06b20482fc1c7345d2f606511144241 Mon Sep 17 00:00:00 2001 From: Dimitris Klouvas Date: Wed, 11 Oct 2023 12:58:09 +0300 Subject: [PATCH] chore(clerk-sdk-node): Drop noisy deprecation of unstable_options in sdk-node (#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...)`. --- .changeset/seven-shrimps-train.md | 5 +++++ packages/sdk-node/src/clerkClient.ts | 13 +++++++++---- playground/cra-js/package.json | 4 +++- playground/express/package.json | 1 + playground/express/src/routes/private.ts | 4 ++-- playground/fastify/package.json | 1 + playground/remix-cf-pages/package.json | 6 +++--- playground/vite-react-ts/package.json | 1 + 8 files changed, 25 insertions(+), 10 deletions(-) create mode 100644 .changeset/seven-shrimps-train.md diff --git a/.changeset/seven-shrimps-train.md b/.changeset/seven-shrimps-train.md new file mode 100644 index 0000000000..67aa313ce8 --- /dev/null +++ b/.changeset/seven-shrimps-train.md @@ -0,0 +1,5 @@ +--- +'@clerk/clerk-sdk-node': patch +--- + +Avoid always showing `__unstable_options` deprecation warning in all applications and SDKs using `@clerk/clerk-sdk-node` diff --git a/packages/sdk-node/src/clerkClient.ts b/packages/sdk-node/src/clerkClient.ts index af690b09cf..6f9cc6a35b 100644 --- a/packages/sdk-node/src/clerkClient.ts +++ b/packages/sdk-node/src/clerkClient.ts @@ -5,12 +5,18 @@ import { createClerkExpressRequireAuth } from './clerkExpressRequireAuth'; import { createClerkExpressWithAuth } from './clerkExpressWithAuth'; import { loadApiEnv, loadClientEnv } from './utils'; +type ExtendedClerk = ReturnType & { + expressWithAuth: ReturnType; + expressRequireAuth: ReturnType; + verifyToken: typeof _verifyToken; +} & ReturnType; + /** * This needs to be a *named* function in order to support the older * new Clerk() syntax for v4 compatibility. * Arrow functions can never be called with the new keyword because they do not have the [[Construct]] method */ -export function Clerk(options: ClerkOptions) { +export function Clerk(options: ClerkOptions): ExtendedClerk { const clerkClient = _Clerk(options); const expressWithAuth = createClerkExpressWithAuth({ ...options, clerkClient }); const expressRequireAuth = createClerkExpressRequireAuth({ ...options, clerkClient }); @@ -19,13 +25,12 @@ export function Clerk(options: ClerkOptions) { return _verifyToken(token, { issuer, ...options, ...verifyOpts }); }; - return { - ...clerkClient, + return Object.assign(clerkClient, { expressWithAuth, expressRequireAuth, verifyToken, ...createBasePropForRedwoodCompatibility(), - }; + }); } const createBasePropForRedwoodCompatibility = () => { diff --git a/playground/cra-js/package.json b/playground/cra-js/package.json index 647ccef25a..4060f4e987 100644 --- a/playground/cra-js/package.json +++ b/playground/cra-js/package.json @@ -3,7 +3,9 @@ "version": "0.1.0", "private": true, "dependencies": { - "@clerk/clerk-react": "*", + "@clerk/clerk-react": "file:.yalc/@clerk/clerk-react", + "@clerk/shared": "file:.yalc/@clerk/shared", + "@clerk/types": "file:.yalc/@clerk/types", "@testing-library/jest-dom": "^5.16.5", "@testing-library/react": "^13.4.0", "@testing-library/user-event": "^13.5.0", diff --git a/playground/express/package.json b/playground/express/package.json index 92e2d93118..32d113cb57 100644 --- a/playground/express/package.json +++ b/playground/express/package.json @@ -12,6 +12,7 @@ "dependencies": { "@clerk/backend": "file:.yalc/@clerk/backend", "@clerk/clerk-sdk-node": "file:.yalc/@clerk/clerk-sdk-node", + "@clerk/shared": "file:.yalc/@clerk/shared", "@clerk/types": "file:.yalc/@clerk/types", "dotenv": "^16.0.3", "ejs": "^3.1.6", diff --git a/playground/express/src/routes/private.ts b/playground/express/src/routes/private.ts index e65c46f0f0..9dcbdff9f4 100644 --- a/playground/express/src/routes/private.ts +++ b/playground/express/src/routes/private.ts @@ -1,11 +1,11 @@ import type { Response } from 'express'; -import { ClerkExpressRequireAuth, clerkClient } from '@clerk/clerk-sdk-node'; +import { clerkClient } from '@clerk/clerk-sdk-node'; import { Router } from 'express'; const router = Router(); -router.use(ClerkExpressRequireAuth({ clerkClient })); +router.use((...args)=>clerkClient.expressRequireAuth()(...args)); router.get('/me', async (req, reply: Response) => { return reply.json({ auth: req.auth }); diff --git a/playground/fastify/package.json b/playground/fastify/package.json index 90705bd0f0..b4d475b81b 100644 --- a/playground/fastify/package.json +++ b/playground/fastify/package.json @@ -8,6 +8,7 @@ "dependencies": { "@clerk/backend": "file:.yalc/@clerk/backend", "@clerk/fastify": "file:.yalc/@clerk/fastify", + "@clerk/shared": "file:.yalc/@clerk/shared", "@clerk/types": "file:.yalc/@clerk/types", "@fastify/view": "^8.0.0", "dotenv": "^16.0.3", diff --git a/playground/remix-cf-pages/package.json b/playground/remix-cf-pages/package.json index 470c36473e..997d71eff7 100644 --- a/playground/remix-cf-pages/package.json +++ b/playground/remix-cf-pages/package.json @@ -11,9 +11,9 @@ "yalc:add": "yalc add @clerk/types && yalc add @clerk/remix && yalc add @clerk/backend" }, "dependencies": { - "@clerk/backend": "*", - "@clerk/remix": "*", - "@clerk/types": "*", + "@clerk/backend": "file:.yalc/@clerk/backend", + "@clerk/remix": "file:.yalc/@clerk/remix", + "@clerk/types": "file:.yalc/@clerk/types", "@remix-run/cloudflare": "^2.0.0", "@remix-run/cloudflare-pages": "^2.0.0", "@remix-run/react": "^2.0.0", diff --git a/playground/vite-react-ts/package.json b/playground/vite-react-ts/package.json index 445d34d398..a1f2c35b39 100644 --- a/playground/vite-react-ts/package.json +++ b/playground/vite-react-ts/package.json @@ -12,6 +12,7 @@ "yalc": "yalc add -- @clerk/clerk-react @clerk/types @clerk/shared" }, "dependencies": { + "@clerk/clerk-js": "file:.yalc/@clerk/clerk-js", "@clerk/clerk-react": "file:.yalc/@clerk/clerk-react", "@clerk/shared": "file:.yalc/@clerk/shared", "@clerk/types": "file:.yalc/@clerk/types",