Skip to content

Commit

Permalink
Merge branch 'main' of github.com:redwoodjs/redwood into rc-service-c…
Browse files Browse the repository at this point in the history
…aching

* 'main' of github.com:redwoodjs/redwood: (21 commits)
  [Tutorial]: Fix Typescript code blocks inconsistency (#6801)
  chore: update all contributors
  Custom auth: Fix comment in template (#6804)
  fix(deps): update dependency eslint to v8.26.0 (#6785)
  [CRWA]: Switch to using enquirer, add engine compatibility override option (#6723)
  (docs): Minor Command update about Storybook (#6722)
  docs: Add mocking useLocation to docs (#6791)
  Update generated render.yaml (#6771)
  fix flightcontrol config template (#6789)
  fix: publish canary using premajor (#6794)
  Strip resetToken and resetTokenExpiresAt from dbAuth forgotPassword handler (#6778)
  Fix WebAuthn when event body is base64 encoded (like when deploying to Vercel) (#6757)
  fix(deps): update jest monorepo (#6787)
  fix(deps): update dependency react-hook-form to v7.39.1 (#6786)
  fix(deps): update dependency fastify to v4.9.2 (#6781)
  fix(deps): update dependency @apollo/client to v3.7.1 (#6780)
  chore: fix and rebuild test project fixture (#6775)
  fix: add prisma resolutions to tutorial e2e test proj (#6772)
  fix(deps): update prisma monorepo to v4.5.0 (#6485)
  Fix dbauth webauthn template (redundant type import) (#6769)
  ...
  • Loading branch information
dac09 committed Nov 7, 2022
2 parents 054e97e + 19e3ea5 commit f7edb1d
Show file tree
Hide file tree
Showing 41 changed files with 896 additions and 732 deletions.
31 changes: 22 additions & 9 deletions .github/workflows/publish-canary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,30 @@ jobs:

- name: 🚢 Publish
run: |
echo "//registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN}" > .npmrc
TAG='canary' && [[ "$GITHUB_REF_NAME" = 'next' ]] && TAG='next'
echo "Publishing $TAG"
echo "//registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN}" > .npmrc
yarn lerna publish --include-merged-tags \
--canary \
--preid $TAG \
--dist-tag $TAG \
--force-publish \
--loglevel verbose \
--no-git-reset \
--yes
args=()
if [[ "$GITHUB_REF_NAME" = 'main' ]]; then
args+=(premajor)
fi
args+=(
--include-merged-tags
--canary
--preid "$TAG"
--dist-tag "$TAG"
--force-publish
--loglevel verbose
--no-git-reset
--yes
)
yarn lerna publish "${args[@]}"
env:
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,8 @@ And there you have it.
<tr>
<td align="center" valign="top" width="20%"><a href="https://derow.nl/"><img src="https://avatars.githubusercontent.com/u/39522856?v=4" width="100px;" alt=""/><br /><sub><b>Rowin Mol</b></sub></a></td>
<td align="center" valign="top" width="20%"><a href="http://everfund.io/"><img src="https://avatars.githubusercontent.com/u/15834048?v=4" width="100px;" alt=""/><br /><sub><b>Christopher Burns</b></sub></a></td>
<td align="center" valign="top" width="20%"><a href="https://github.com/bigbuckalex"><img src="https://avatars.githubusercontent.com/u/13971705?v=4" width="100px;" alt=""/><br /><sub><b>Alex Lilly</b></sub></a></td>
<td align="center" valign="top" width="20%"><a href="https://github.com/dphuang2"><img src="https://avatars.githubusercontent.com/u/14287381?v=4" width="100px;" alt=""/><br /><sub><b>dphuang2</b></sub></a></td>
</tr>
</tbody>
</table>
Expand Down
4 changes: 2 additions & 2 deletions __fixtures__/test-project/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
"react-dom": "17.0.2"
},
"devDependencies": {
"autoprefixer": "^10.4.12",
"autoprefixer": "^10.4.13",
"postcss": "^8.4.18",
"postcss-loader": "^7.0.1",
"prettier-plugin-tailwindcss": "^0.1.13",
"tailwindcss": "^3.1.8"
"tailwindcss": "^3.2.1"
}
}
90 changes: 45 additions & 45 deletions docs/docs/cli-commands.md

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions docs/docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,19 @@ render(<Article article={ title: 'Foobar' } />, {
})
```
:::
### Mocking useLocation

To mock `useLocation` in your component tests, wrap the component with `LocationProvider`:

```jsx
import { LocationProvider } from '@redwoodjs/router'

render(
<LocationProvider location={{ pathname: '', search: '?cancelled=true' }}>
<Component />
</LocationProvider>
)
```

## Testing Custom Hooks

Expand Down
7 changes: 4 additions & 3 deletions docs/docs/tutorial/chapter3/saving-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,10 @@ export const deleteContact = ({ id }) => {
<TabItem value="ts" label="TypeScript">

```js title="api/src/services/contacts/contacts.ts"
import { db } from 'src/lib/db'
import type { QueryResolvers, MutationResolvers } from 'types/graphql'

import { db } from 'src/lib/db'

export const contacts: QueryResolvers['contacts'] = () => {
return db.contact.findMany()
}
Expand Down Expand Up @@ -1280,14 +1281,14 @@ export const createContact = ({ input }) => {
<TabItem value="ts" label="TypeScript">

```ts title="api/src/services/contacts/contacts.ts"
import type { Prisma } from '@prisma/client'
import type { QueryResolvers, MutationResolvers } from 'types/graphql'

// highlight-next-line
import { validate } from '@redwoodjs/api'

// ...

export const createContact = ({ input }: CreateContactArgs) => {
export const createContact = ({ input }: MutationResolvers['createContact']) => {
// highlight-next-line
validate(input.email, 'email', { email: true })
return db.contact.create({ data: input })
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,25 @@
"@tsd/typescript": "4.8.4",
"@types/babel__generator": "7.6.4",
"@types/fs-extra": "9.0.13",
"@types/jest": "29.1.2",
"@types/jest": "29.2.1",
"@types/jscodeshift": "0.11.5",
"@types/lodash.template": "4.5.1",
"@types/ncp": "2.0.5",
"@types/prompts": "2.4.1",
"all-contributors-cli": "6.24.0",
"ansi-colors": "4.1.3",
"babel-jest": "29.1.2",
"babel-jest": "29.2.2",
"babel-plugin-auto-import": "1.1.0",
"babel-plugin-remove-code": "0.0.6",
"boxen": "5.1.2",
"core-js": "3.25.5",
"cypress": "10.10.0",
"cypress-wait-until": "1.7.2",
"eslint": "8.25.0",
"eslint": "8.26.0",
"fast-glob": "3.2.12",
"fs-extra": "10.1.0",
"is-port-reachable": "3.1.0",
"jest": "29.1.2",
"jest": "29.2.2",
"jest-runner-tsd": "4.0.0",
"jscodeshift": "0.14.0",
"lerna": "6.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/api-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"chokidar": "3.5.3",
"core-js": "3.25.5",
"fast-json-parse": "1.0.3",
"fastify": "4.8.1",
"fastify": "4.9.2",
"fastify-raw-body": "4.1.0",
"lodash.escape": "4.0.1",
"pretty-bytes": "5.6.0",
Expand All @@ -56,7 +56,7 @@
"@types/split2": "3.2.1",
"@types/yargs": "17.0.13",
"aws-lambda": "1.0.7",
"jest": "29.1.2",
"jest": "29.2.2",
"typescript": "4.7.4"
},
"gitHead": "3905ed045508b861b495f8d5630d76c7a157d8f1"
Expand Down
4 changes: 2 additions & 2 deletions packages/api-server/src/requestHandlers/awsLambdaFastify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ const fastifyResponseForLambdaResult = (
if (lambdaResult.isBase64Encoded) {
// Correctly handle base 64 encoded binary data. See
// https://aws.amazon.com/blogs/compute/handling-binary-data-using-amazon-api-gateway-http-apis
reply.send(Buffer.from(body, 'base64'))
return reply.send(Buffer.from(body, 'base64'))
} else {
reply.send(body)
return reply.send(body)
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"dependencies": {
"@babel/runtime-corejs3": "7.19.4",
"@prisma/client": "4.3.1",
"@prisma/client": "4.5.0",
"base64url": "3.0.1",
"core-js": "3.25.5",
"cross-undici-fetch": "0.4.14",
Expand Down Expand Up @@ -61,7 +61,7 @@
"@types/split2": "3.2.1",
"@types/uuid": "8.3.4",
"aws-lambda": "1.0.7",
"jest": "29.1.2",
"jest": "29.2.2",
"memjs": "1.3.0",
"redis": "4.2.0",
"split2": "4.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/auth-providers-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"firebase": "9.10.0",
"firebase-admin": "10.3.0",
"gotrue-js": "0.9.29",
"jest": "29.1.2",
"jest": "29.2.2",
"magic-sdk": "9.1.1",
"netlify-identity-widget": "1.9.2",
"react": "17.0.2",
Expand Down
49 changes: 32 additions & 17 deletions packages/auth-providers-api/src/dbAuth/DbAuthHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import type {
VerifiedRegistrationResponse,
VerifiedAuthenticationResponse,
} from '@simplewebauthn/server'
import type {
AuthenticationCredentialJSON,
RegistrationCredentialJSON,
} from '@simplewebauthn/typescript-types'
import type { APIGatewayProxyEvent, Context as LambdaContext } from 'aws-lambda'
import base64url from 'base64url'
import CryptoJS from 'crypto-js'
Expand Down Expand Up @@ -230,12 +234,13 @@ export type AuthMethodNames =
| 'webAuthnAuthOptions'
| 'webAuthnAuthenticate'

type Params = {
username?: string
password?: string
method: AuthMethodNames
[key: string]: any
}
type Params = AuthenticationCredentialJSON &
RegistrationCredentialJSON & {
username?: string
password?: string
method: AuthMethodNames
[key: string]: any
}

interface DbAuthSession<TIdType> {
id: TIdType
Expand Down Expand Up @@ -501,8 +506,18 @@ export class DbAuthHandler<
this.options.forgotPassword as ForgotPasswordFlowOptions
).handler(this._sanitizeUser(user))

// remove resetToken and resetTokenExpiresAt if in the body of the
// forgotPassword handler response
let responseObj = response
if (typeof response === 'object') {
responseObj = Object.assign(response, {
[this.options.authFields.resetToken]: undefined,
[this.options.authFields.resetTokenExpiresAt]: undefined,
})
}

return [
response ? JSON.stringify(response) : '',
response ? JSON.stringify(responseObj) : '',
{
...this._deleteSessionHeader,
},
Expand Down Expand Up @@ -607,14 +622,14 @@ export class DbAuthHandler<
},
data: {
[this.options.authFields.hashedPassword]: hashedPassword,
[this.options.authFields.resetToken]: null,
[this.options.authFields.resetTokenExpiresAt]: null,
},
})
} catch (e) {
throw new DbAuthError.GenericError()
}

await this._clearResetToken(user)

// call the user-defined handler so they can decide what to do with this user
const response = await (
this.options.resetPassword as ResetPasswordFlowOptions
Expand Down Expand Up @@ -689,9 +704,8 @@ export class DbAuthHandler<
throw new DbAuthError.WebAuthnError('WebAuthn is not enabled')
}

const jsonBody = JSON.parse(this.event.body as string)
const credential = await this.dbCredentialAccessor.findFirst({
where: { id: jsonBody.rawId },
where: { id: this.params.rawId },
})

if (!credential) {
Expand All @@ -708,7 +722,7 @@ export class DbAuthHandler<
let verification: VerifiedAuthenticationResponse
try {
const opts: VerifyAuthenticationResponseOpts = {
credential: jsonBody,
credential: this.params,
expectedChallenge: user[this.options.authFields.challenge as string],
expectedOrigin: webAuthnOptions.origin,
expectedRPID: webAuthnOptions.domain,
Expand Down Expand Up @@ -756,7 +770,7 @@ export class DbAuthHandler<
// get the regular `login` cookies
const [, loginHeaders] = this._loginResponse(user)
const cookies = [
this._webAuthnCookie(jsonBody.rawId, this.webAuthnExpiresDate),
this._webAuthnCookie(this.params.rawId, this.webAuthnExpiresDate),
loginHeaders['set-cookie'],
].flat()

Expand Down Expand Up @@ -881,12 +895,11 @@ export class DbAuthHandler<
}

const user = await this._getCurrentUser()
const jsonBody = JSON.parse(this.event.body as string)

let verification: VerifiedRegistrationResponse
try {
const options: VerifyRegistrationResponseOpts = {
credential: jsonBody,
credential: this.params,
expectedChallenge: user[this.options.authFields.challenge as string],
expectedOrigin: this.options.webAuthn.origin,
expectedRPID: this.options.webAuthn.domain,
Expand Down Expand Up @@ -919,8 +932,10 @@ export class DbAuthHandler<
user[this.options.authFields.id],
[this.options.webAuthn.credentialFields.publicKey]:
credentialPublicKey,
[this.options.webAuthn.credentialFields.transports]:
jsonBody.transports ? JSON.stringify(jsonBody.transports) : null,
[this.options.webAuthn.credentialFields.transports]: this.params
.transports
? JSON.stringify(this.params.transports)
: null,
[this.options.webAuthn.credentialFields.counter]: counter,
},
})
Expand Down
Loading

0 comments on commit f7edb1d

Please sign in to comment.