From 83941734e6eefc2f6953b085eef3ad2e4a721973 Mon Sep 17 00:00:00 2001 From: Aditya Pandey Date: Wed, 23 Mar 2022 11:28:00 +0530 Subject: [PATCH] Cleanup deprecated features (#4856) * Remove old setup tailwind command * Deprecate COOKIE_META * Cleanup rw-api-server * Cleanup deprecation notice from md files * add dist/index.js to server bin conditional * Revert "add dist/index.js to server bin conditional" This reverts commit 729997e7c3ec589fdaff0544179f62da48a2d6e1. * Pass api arg to api-server-watch * Remove space in index.js path Co-authored-by: David Price --- CHANGELOG.md | 4 -- packages/api-server/README.md | 1 - packages/api-server/package.json | 1 - packages/api-server/src/index.ts | 13 +--- packages/api-server/src/watch.ts | 1 + .../api/src/functions/dbAuth/DbAuthHandler.ts | 59 +++++------------- .../dbAuth/__tests__/DbAuthHandler.test.js | 62 +++---------------- packages/cli/src/commands/setup/tailwind.js | 28 --------- yarn.lock | 1 - 9 files changed, 26 insertions(+), 144 deletions(-) delete mode 100644 packages/cli/src/commands/setup/tailwind.js diff --git a/CHANGELOG.md b/CHANGELOG.md index d176addcaeb8..e6fdcbefa749 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,5 @@ # CHANGELOG -## Upcoming 1.0.0 Deprecations -The following items are scheduled for 1.0.0 deprecation: -- api-server binary `rw-api-server`; use `rw-server api` instead (See [api-server/src/index.ts](https://github.com/redwoodjs/redwood/blob/main/packages/api-server/src/index.ts)) - ## Current and Previous Versions For all changelog information since v0.0.1: - [GitHub Releases](https://github.com/redwoodjs/redwood/releases) diff --git a/packages/api-server/README.md b/packages/api-server/README.md index c2811aec9ce2..71dc04354fc3 100644 --- a/packages/api-server/README.md +++ b/packages/api-server/README.md @@ -16,7 +16,6 @@ Run the Redwood Fastify Server programmatically. From package.json ``` "bin": { - "rw-api-server": "./dist/index.js", "rw-api-server-watch": "./dist/watch.js", "rw-log-formatter": "./dist/logFormatter/bin.js", "rw-server": "./dist/index.js" diff --git a/packages/api-server/package.json b/packages/api-server/package.json index e4ba761f0aa4..ea7748d6b637 100644 --- a/packages/api-server/package.json +++ b/packages/api-server/package.json @@ -10,7 +10,6 @@ "license": "MIT", "main": "dist/cliHandlers", "bin": { - "rw-api-server": "./dist/index.js", "rw-api-server-watch": "./dist/watch.js", "rw-log-formatter": "./dist/logFormatter/bin.js", "rw-server": "./dist/index.js" diff --git a/packages/api-server/src/index.ts b/packages/api-server/src/index.ts index 94e7d1f7b2bc..f27da793398d 100644 --- a/packages/api-server/src/index.ts +++ b/packages/api-server/src/index.ts @@ -1,8 +1,6 @@ #!/usr/bin/env node import yargs from 'yargs' -import { ensurePosixPath } from '@redwoodjs/internal' - import { apiCliOptions, webCliOptions, @@ -12,25 +10,16 @@ import { bothServerHandler, } from './cliHandlers' -const commandPath = yargs.argv.$0 - const positionalArgs = yargs.argv._ // "bin": { -// "rw-api-server": "./dist/index.js", // "rw-api-server-watch": "./dist/watch.js", // "rw-log-formatter": "./dist/logFormatter/bin.js", // "rw-server": "./dist/index.js" // }, -// DEPRECATION Warning: the bin rw-api-server will be deprecated with 1.0.0 - if (require.main === module) { - if ( - ensurePosixPath(commandPath).includes('.bin/rw-api-server') || - ensurePosixPath(commandPath).includes('dist/index.js') || - (positionalArgs.includes('api') && !positionalArgs.includes('web')) - ) { + if (positionalArgs.includes('api') && !positionalArgs.includes('web')) { apiServerHandler(yargs.options(apiCliOptions).argv) } else if ( positionalArgs.includes('web') && diff --git a/packages/api-server/src/watch.ts b/packages/api-server/src/watch.ts index 9a982af09ff2..3baabf53c7d6 100644 --- a/packages/api-server/src/watch.ts +++ b/packages/api-server/src/watch.ts @@ -60,6 +60,7 @@ const rebuildApiServer = () => { // Start API server httpServerProcess = fork(path.join(__dirname, 'index.js'), [ + 'api', '--port', getConfig().api.port.toString(), ]) diff --git a/packages/api/src/functions/dbAuth/DbAuthHandler.ts b/packages/api/src/functions/dbAuth/DbAuthHandler.ts index 1b9a59835ed8..d9a624c967b5 100644 --- a/packages/api/src/functions/dbAuth/DbAuthHandler.ts +++ b/packages/api/src/functions/dbAuth/DbAuthHandler.ts @@ -192,19 +192,6 @@ export class DbAuthHandler { } } - // class constant: all the attributes of the cookie other than the value itself - // DEPRECATED: Remove once deprecation warning is removed from _cookieAttributes() - static get COOKIE_META() { - const meta = [`Path=/`, 'HttpOnly', 'SameSite=Strict'] - - // set DBAUTH_COOKIE_DOMAIN if you need any subdomains to access this cookie - if (process.env.DBAUTH_COOKIE_DOMAIN) { - meta.push(`Domain=${process.env.DBAUTH_COOKIE_DOMAIN}`) - } - - return meta - } - // default to epoch when we want to expire static get PAST_EXPIRES_DATE() { return new Date('1970-01-01T00:00:00.000+00:00').toUTCString() @@ -565,36 +552,22 @@ export class DbAuthHandler { // pass the argument `expires` set to "now" to get the attributes needed to expire // the session, or "future" (or left out completely) to set to `futureExpiresDate` _cookieAttributes({ expires = 'future' }: { expires?: 'now' | 'future' }) { - let meta - - // DEPRECATED: Remove deprecation logic after a few releases, assume this.options.cookie contains config - if (!this.options.cookie) { - console.warn( - `\n[Deprecation Notice] dbAuth cookie config has moved to\n api/src/function/auth.js for better customization.\n See https://redwoodjs.com/docs/authentication#cookie-config\n` - ) - meta = JSON.parse(JSON.stringify(DbAuthHandler.COOKIE_META)) - - if (process.env.NODE_ENV !== 'development') { - meta.push('Secure') - } - } else { - const cookieOptions = this.options.cookie || {} - meta = Object.keys(cookieOptions) - .map((key) => { - const optionValue = - cookieOptions[key as keyof DbAuthHandlerOptions['cookie']] - - // Convert the options to valid cookie string - if (optionValue === true) { - return key - } else if (optionValue === false) { - return null - } else { - return `${key}=${optionValue}` - } - }) - .filter((v) => v) - } + const cookieOptions = this.options.cookie || {} + const meta = Object.keys(cookieOptions) + .map((key) => { + const optionValue = + cookieOptions[key as keyof DbAuthHandlerOptions['cookie']] + + // Convert the options to valid cookie string + if (optionValue === true) { + return key + } else if (optionValue === false) { + return null + } else { + return `${key}=${optionValue}` + } + }) + .filter((v) => v) const expiresAt = expires === 'now' diff --git a/packages/api/src/functions/dbAuth/__tests__/DbAuthHandler.test.js b/packages/api/src/functions/dbAuth/__tests__/DbAuthHandler.test.js index 2360a6b03c01..7464fbcd2b54 100644 --- a/packages/api/src/functions/dbAuth/__tests__/DbAuthHandler.test.js +++ b/packages/api/src/functions/dbAuth/__tests__/DbAuthHandler.test.js @@ -73,8 +73,7 @@ const UUID_REGEX = /\b[0-9a-f]{8}\b-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-\b[0-9a-f]{12}\b/ const SET_SESSION_REGEX = /^session=[a-zA-Z0-9+=/]+;/ const UTC_DATE_REGEX = /\w{3}, \d{2} \w{3} \d{4} [\d:]{8} GMT/ -const LOGOUT_COOKIE = - 'session=;Path=/;HttpOnly;SameSite=Strict;Secure;Expires=Thu, 01 Jan 1970 00:00:00 GMT' +const LOGOUT_COOKIE = 'session=;Expires=Thu, 01 Jan 1970 00:00:00 GMT' const createDbUser = async (attributes = {}) => { return await db.user.create({ @@ -1171,50 +1170,6 @@ describe('dbAuth', () => { }) describe('_cookieAttributes', () => { - // DEPRECATED: cookie config should come from options object now - it('returns an array of attributes for the session cookie', () => { - const dbAuth = new DbAuthHandler( - { headers: { referer: 'http://test.host' } }, - context, - options - ) - const attributes = dbAuth._cookieAttributes({}) - - expect(attributes.length).toEqual(5) - expect(attributes[0]).toEqual('Path=/') - // expect(attributes[1]).toEqual('Domain=site.test') - expect(attributes[1]).toEqual('HttpOnly') - expect(attributes[2]).toEqual('SameSite=Strict') - expect(attributes[3]).toEqual('Secure') - expect(attributes[4]).toMatch(`Expires=`) - expect(attributes[4]).toMatch(UTC_DATE_REGEX) - }) - - // DEPRECATED: Secure will be set or not in cookie config options - it('does not include the Secure attribute when in development environment', () => { - const oldEnv = process.env.NODE_ENV - process.env.NODE_ENV = 'development' - const dbAuth = new DbAuthHandler(event, context, options) - const attributes = dbAuth._cookieAttributes({}) - - // not in its usual position - expect(attributes[3]).not.toEqual('Secure') - // or anywhere else - expect(attributes.join(';')).not.toMatch(`Secure`) - - process.env.NODE_ENV = oldEnv - }) - - // DEPRECATED: Domain will be set or not in cookie config options - it('includes a Domain in the cookie if DBAUTH_COOKIE_DOMAIN is set', () => { - process.env.DBAUTH_COOKIE_DOMAIN = 'site.test' - - const dbAuth = new DbAuthHandler(event, context, options) - const attributes = dbAuth._cookieAttributes({}) - - expect(attributes[3]).toEqual('Domain=site.test') - }) - it('returns an array of attributes for the session cookie', () => { const dbAuth = new DbAuthHandler( { headers: { referer: 'http://test.host' } }, @@ -1283,14 +1238,13 @@ describe('dbAuth', () => { expect(attributes[0]).toMatch(/Expires=/) }) - // DEPRECATED: can't test until deprecated functionality is removed - // it('includes no cookie attributes if cookie options not set', () => { - // const dbAuth = new DbAuthHandler(event, context, options) - // const attributes = dbAuth._cookieAttributes({}) + it('includes no cookie attributes if cookie options not set', () => { + const dbAuth = new DbAuthHandler(event, context, options) + const attributes = dbAuth._cookieAttributes({}) - // expect(attributes.length).toEqual(1) - // expect(attributes[0]).toMatch(/Expires=/) - // }) + expect(attributes.length).toEqual(1) + expect(attributes[0]).toMatch(/Expires=/) + }) }) describe('_createSessionHeader()', () => { @@ -1300,7 +1254,7 @@ describe('dbAuth', () => { expect(Object.keys(headers).length).toEqual(1) expect(headers['Set-Cookie']).toMatch( - `;Path=/;HttpOnly;SameSite=Strict;Secure;Expires=${dbAuth.futureExpiresDate}` + `Expires=${dbAuth.futureExpiresDate}` ) // can't really match on the session value since it will change on every render, // due to CSRF token generation but we can check that it contains a only the diff --git a/packages/cli/src/commands/setup/tailwind.js b/packages/cli/src/commands/setup/tailwind.js deleted file mode 100644 index e217525b245a..000000000000 --- a/packages/cli/src/commands/setup/tailwind.js +++ /dev/null @@ -1,28 +0,0 @@ -import execa from 'execa' - -import c from '../../lib/colors' - -// ******** -// Deprecated as of November 2021 -// Use "setup ui " command -// ******** - -export const command = 'tailwind' -export const description = false - -export const handler = async () => { - try { - console.log(c.warning('\n' + 'WARNING: deprecated "tailwind" command')) - console.log( - c.green('See "rw setup ui tailwindcss" command: ') + - 'https://redwoodjs.com/docs/cli-commands#setup-ui' + - '\n' - ) - await execa('yarn rw setup ui tailwindcss', { - stdio: 'inherit', - shell: true, - }) - } catch (e) { - console.log(c.error(e.message)) - } -} diff --git a/yarn.lock b/yarn.lock index 95372822284c..b61c4bf5c6c8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5755,7 +5755,6 @@ __metadata: typescript: 4.6.2 yargs: 16.2.0 bin: - rw-api-server: ./dist/index.js rw-api-server-watch: ./dist/watch.js rw-log-formatter: ./dist/logFormatter/bin.js rw-server: ./dist/index.js