Skip to content

Commit

Permalink
Cleanup deprecated features (#4856)
Browse files Browse the repository at this point in the history
* 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 729997e.

* Pass api arg to api-server-watch

* Remove space in index.js path

Co-authored-by: David Price <[email protected]>
  • Loading branch information
callingmedic911 and thedavidprice authored Mar 23, 2022
1 parent 6190324 commit 8394173
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 144 deletions.
4 changes: 0 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
1 change: 0 additions & 1 deletion packages/api-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion packages/api-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 1 addition & 12 deletions packages/api-server/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/usr/bin/env node
import yargs from 'yargs'

import { ensurePosixPath } from '@redwoodjs/internal'

import {
apiCliOptions,
webCliOptions,
Expand All @@ -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') &&
Expand Down
1 change: 1 addition & 0 deletions packages/api-server/src/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const rebuildApiServer = () => {

// Start API server
httpServerProcess = fork(path.join(__dirname, 'index.js'), [
'api',
'--port',
getConfig().api.port.toString(),
])
Expand Down
59 changes: 16 additions & 43 deletions packages/api/src/functions/dbAuth/DbAuthHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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'
Expand Down
62 changes: 8 additions & 54 deletions packages/api/src/functions/dbAuth/__tests__/DbAuthHandler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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' } },
Expand Down Expand Up @@ -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()', () => {
Expand All @@ -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
Expand Down
28 changes: 0 additions & 28 deletions packages/cli/src/commands/setup/tailwind.js

This file was deleted.

1 change: 0 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8394173

Please sign in to comment.