Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into chore/upgrade-to-re…
Browse files Browse the repository at this point in the history
…act-18

# Conflicts:
#	package.json
#	packages/auth/src/AuthProvider.tsx
#	packages/auth/src/__tests__/AuthProvider.test.tsx
#	packages/forms/package.json
#	packages/testing/package.json
#	yarn.lock
  • Loading branch information
virtuoushub committed Jul 25, 2022
2 parents 49746aa + c2cd25d commit 665037c
Show file tree
Hide file tree
Showing 220 changed files with 11,989 additions and 7,231 deletions.
2 changes: 1 addition & 1 deletion .github/actions/message_slack_publishing/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ runs:
steps:
- name: Get status emoji
id: get-status-emoji
uses: sergeysova/jq-action@v2.1.0
uses: sergeysova/jq-action@v2.2.1
with:
cmd: 'echo "{ \"success\": \"✅\", \"failure\": \"🚨\" }" | jq .${{ inputs.status }} -r'

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-canary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:

- name: 🏷 Get version
id: get-version
uses: sergeysova/jq-action@v2.1.0
uses: sergeysova/jq-action@v2.2.1
with:
cmd: 'jq .version packages/core/package.json -r'

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-release-candidate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jobs:

- name: 🏷 Get version
id: get-version
uses: sergeysova/jq-action@v2.1.0
uses: sergeysova/jq-action@v2.2.1
with:
cmd: 'jq .version packages/core/package.json -r'

Expand Down
786 changes: 0 additions & 786 deletions .yarn/releases/yarn-3.2.1.cjs

This file was deleted.

783 changes: 783 additions & 0 deletions .yarn/releases/yarn-3.2.2.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ plugins:

preferInteractive: true

yarnPath: .yarn/releases/yarn-3.2.1.cjs
yarnPath: .yarn/releases/yarn-3.2.2.cjs
1 change: 1 addition & 0 deletions __fixtures__/test-project/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ yarn-error.log
web/public/mockServiceWorker.js
web/types/graphql.d.ts
api/types/graphql.d.ts
api/src/lib/generateGraphiQLHeader.*
.pnp.*
.yarn/*
!.yarn/patches
Expand Down
786 changes: 0 additions & 786 deletions __fixtures__/test-project/.yarn/releases/yarn-3.2.1.cjs

This file was deleted.

783 changes: 783 additions & 0 deletions __fixtures__/test-project/.yarn/releases/yarn-3.2.2.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion __fixtures__/test-project/.yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ nmMode: hardlinks-local
# Heads up: right now, Redwood expects this to be `node-modules`.
nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-3.2.1.cjs
yarnPath: .yarn/releases/yarn-3.2.2.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ describe('requireAuth directive', () => {
// If you want to set values in context, pass it through e.g.
// mockRedwoodDirective(requireAuth, { context: { currentUser: { id: 1, name: 'Lebron McGretzky' } }})
const mockExecution = mockRedwoodDirective(requireAuth, {
context: { currentUser: { id: 1, roles: 'ADMIN', email: 'b@zinga.com' } },
})
context: { currentUser: { id: 1, roles: 'ADMIN', email: 'b@zinga.com' } },
})

expect(mockExecution).not.toThrowError()
})
Expand Down
20 changes: 13 additions & 7 deletions __fixtures__/test-project/api/src/functions/auth.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { db } from 'src/lib/db'
import type { APIGatewayProxyEvent, Context } from 'aws-lambda'

import { DbAuthHandler } from '@redwoodjs/api'
import type { DbAuthHandlerOptions } from '@redwoodjs/api'

export const handler = async (event, context) => {
import { db } from 'src/lib/db'

const forgotPasswordOptions = {
export const handler = async (
event: APIGatewayProxyEvent,
context: Context
) => {
const forgotPasswordOptions: DbAuthHandlerOptions['forgotPassword'] = {
// handler() is invoked after verifying that a user was found with the given
// username. This is where you can send the user an email with a link to
// reset their password. With the default dbAuth routes and field names, the
Expand Down Expand Up @@ -33,7 +39,7 @@ export const handler = async (event, context) => {
},
}

const loginOptions = {
const loginOptions: DbAuthHandlerOptions['login'] = {
// handler() is called after finding the user that matches the
// username/password provided at login, but before actually considering them
// logged in. The `user` argument will be the user in the database that
Expand Down Expand Up @@ -62,13 +68,13 @@ export const handler = async (event, context) => {
expires: 60 * 60 * 24 * 365 * 10,
}

const resetPasswordOptions = {
const resetPasswordOptions: DbAuthHandlerOptions['resetPassword'] = {
// handler() is invoked after the password has been successfully updated in
// the database. Returning anything truthy will automatically log the user
// in. Return `false` otherwise, and in the Reset Password page redirect the
// user to the login page.
handler: (user) => {
return user
return !!user
},

// If `false` then the new password MUST be different from the current one
Expand All @@ -86,7 +92,7 @@ export const handler = async (event, context) => {
},
}

const signupOptions = {
const signupOptions: DbAuthHandlerOptions['signup'] = {
// Whatever you want to happen to your data on new user signup. Redwood will
// check for duplicate usernames before calling this handler. At a minimum
// you need to save the `username`, `hashedPassword` and `salt` to your
Expand Down
4 changes: 1 addition & 3 deletions __fixtures__/test-project/api/src/functions/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ import { createGraphQLHandler } from '@redwoodjs/graphql-server'

import directives from 'src/directives/**/*.{js,ts}'
import sdls from 'src/graphql/**/*.sdl.{js,ts}'
import services from 'src/services/**/*.{js,ts}'

import { getCurrentUser } from 'src/lib/auth'

import { db } from 'src/lib/db'
import { logger } from 'src/lib/logger'
import services from 'src/services/**/*.{js,ts}'

export const handler = createGraphQLHandler({
getCurrentUser,
Expand Down
2 changes: 1 addition & 1 deletion __fixtures__/test-project/api/src/graphql/contacts.sdl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ export const schema = gql`
type Mutation {
createContact(input: CreateContactInput!): Contact @skipAuth
updateContact(id: Int!, input: UpdateContactInput!): Contact! @requireAuth
deleteContact(id: Int!): Contact! @requireAuth(roles:["ADMIN"])
deleteContact(id: Int!): Contact! @requireAuth(roles: ["ADMIN"])
}
`
2 changes: 1 addition & 1 deletion __fixtures__/test-project/api/src/graphql/posts.sdl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const schema = gql`
type Query {
posts: [Post!]! @skipAuth
post(id: Int!): Post @skipAuth
post(id: Int!): Post @skipAuth
}
input CreatePostInput {
Expand Down
16 changes: 9 additions & 7 deletions __fixtures__/test-project/api/src/lib/auth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type { DbAuthSession } from '@redwoodjs/api'
import { AuthenticationError, ForbiddenError } from '@redwoodjs/graphql-server'

import { db } from './db'

/**
Expand All @@ -18,10 +20,10 @@ import { db } from './db'
* fields to the `select` object below once you've decided they are safe to be
* seen if someone were to open the Web Inspector in their browser.
*/
export const getCurrentUser = async (session) => {
export const getCurrentUser = async (session: DbAuthSession<number>) => {
return await db.user.findUnique({
where: { id: session.id },
select: { id: true, roles: true, email: true},
select: { id: true, roles: true, email: true },
})
}

Expand All @@ -43,7 +45,7 @@ type AllowedRoles = string | string[] | undefined
/**
* Checks if the currentUser is authenticated (and assigned one of the given roles)
*
* @param roles: AllowedRoles - Checks if the currentUser is assigned one of these roles
* @param roles: {@link AllowedRoles} - Checks if the currentUser is assigned one of these roles
*
* @returns {boolean} - Returns true if the currentUser is logged in and assigned one of the given roles,
* or when no roles are provided to check against. Otherwise returns false.
Expand Down Expand Up @@ -71,7 +73,7 @@ export const hasRole = (roles: AllowedRoles): boolean => {
return currentUserRoles?.some((allowedRole) =>
roles.includes(allowedRole)
)
} else if (typeof context.currentUser.roles === 'string') {
} else if (typeof context?.currentUser?.roles === 'string') {
// roles to check is an array, currentUser.roles is a string
return roles.some(
(allowedRole) => context.currentUser?.roles === allowedRole
Expand All @@ -88,12 +90,12 @@ export const hasRole = (roles: AllowedRoles): boolean => {
* whether or not they are assigned a role, and optionally raise an
* error if they're not.
*
* @param roles: AllowedRoles - When checking role membership, these roles grant access.
* @param roles: {@link AllowedRoles} - When checking role membership, these roles grant access.
*
* @returns - If the currentUser is authenticated (and assigned one of the given roles)
*
* @throws {AuthenticationError} - If the currentUser is not authenticated
* @throws {ForbiddenError} If the currentUser is not allowed due to role permissions
* @throws {@link AuthenticationError} - If the currentUser is not authenticated
* @throws {@link ForbiddenError} If the currentUser is not allowed due to role permissions
*
* @see https://github.com/redwoodjs/redwood/tree/main/packages/auth for examples
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type { Prisma } from '@prisma/client'
import type { Prisma, Contact } from '@prisma/client'

import type { ScenarioData } from '@redwoodjs/testing/api'

export const standard = defineScenario<Prisma.ContactCreateArgs>({
contact: {
Expand All @@ -7,4 +9,4 @@ export const standard = defineScenario<Prisma.ContactCreateArgs>({
},
})

export type StandardScenario = typeof standard
export type StandardScenario = ScenarioData<Contact, 'contact'>
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { Contact } from '@prisma/client'

import {
contacts,
contact,
Expand Down Expand Up @@ -37,7 +39,7 @@ describe('contacts', () => {
})

scenario('updates a contact', async (scenario: StandardScenario) => {
const original = await contact({ id: scenario.contact.one.id })
const original = (await contact({ id: scenario.contact.one.id })) as Contact
const result = await updateContact({
id: original.id,
input: { name: 'String2' },
Expand All @@ -47,7 +49,9 @@ describe('contacts', () => {
})

scenario('deletes a contact', async (scenario: StandardScenario) => {
const original = await deleteContact({ id: scenario.contact.one.id })
const original = (await deleteContact({
id: scenario.contact.one.id,
})) as Contact
const result = await contact({ id: original.id })

expect(result).toEqual(null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type { Prisma } from '@prisma/client'
import type { Prisma, Post } from '@prisma/client'

import type { ScenarioData } from '@redwoodjs/testing/api'

export const standard = defineScenario<Prisma.PostCreateArgs>({
post: {
Expand All @@ -7,4 +9,4 @@ export const standard = defineScenario<Prisma.PostCreateArgs>({
},
})

export type StandardScenario = typeof standard
export type StandardScenario = ScenarioData<Post, 'post'>
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { Post } from '@prisma/client'

import { posts, post, createPost, updatePost, deletePost } from './posts'
import type { StandardScenario } from './posts.scenarios'

Expand Down Expand Up @@ -30,7 +32,7 @@ describe('posts', () => {
})

scenario('updates a post', async (scenario: StandardScenario) => {
const original = await post({ id: scenario.post.one.id })
const original = (await post({ id: scenario.post.one.id })) as Post
const result = await updatePost({
id: original.id,
input: { title: 'String2' },
Expand All @@ -40,7 +42,7 @@ describe('posts', () => {
})

scenario('deletes a post', async (scenario: StandardScenario) => {
const original = await deletePost({ id: scenario.post.one.id })
const original = (await deletePost({ id: scenario.post.one.id })) as Post
const result = await post({ id: original.id })

expect(result).toEqual(null)
Expand Down
3 changes: 2 additions & 1 deletion __fixtures__/test-project/api/src/services/posts/posts.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { db } from 'src/lib/db'
import type { QueryResolvers, MutationResolvers } from 'types/graphql'

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

export const posts: QueryResolvers['posts'] = () => {
return db.post.findMany()
}
Expand Down
5 changes: 1 addition & 4 deletions __fixtures__/test-project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,5 @@
"prisma": {
"seed": "yarn rw exec seed"
},
"packageManager": "yarn@3.2.1",
"scripts": {
"postinstall": ""
}
"packageManager": "yarn@3.2.2"
}
2 changes: 2 additions & 0 deletions __fixtures__/test-project/prettier.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ module.exports = {
},
},
],
tailwindConfig: './web/config/tailwind.config.js',
plugins: [require('prettier-plugin-tailwindcss')],
}
1 change: 1 addition & 0 deletions __fixtures__/test-project/web/config/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @type {import('tailwindcss').Config} */
module.exports = {
content: ['src/**/*.{js,jsx,ts,tsx}'],
theme: {
Expand Down
5 changes: 3 additions & 2 deletions __fixtures__/test-project/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"devDependencies": {
"autoprefixer": "^10.4.7",
"postcss": "^8.4.14",
"postcss-loader": "^7.0.0",
"tailwindcss": "^3.0.24"
"postcss-loader": "^7.0.1",
"prettier-plugin-tailwindcss": "^0.1.12",
"tailwindcss": "^3.1.6"
}
}
1 change: 0 additions & 1 deletion __fixtures__/test-project/web/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { AuthProvider } from '@redwoodjs/auth'

import { FatalErrorBoundary, RedwoodProvider } from '@redwoodjs/web'
import { RedwoodApolloProvider } from '@redwoodjs/web/apollo'

Expand Down
35 changes: 19 additions & 16 deletions __fixtures__/test-project/web/src/Routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,43 @@
// 'src/pages/Admin/BooksPage/BooksPage.js' -> AdminBooksPage

import { Router, Route, Private, Set } from '@redwoodjs/router'
import ContactsLayout from 'src/layouts/ContactsLayout'
import PostsLayout from 'src/layouts/PostsLayout';

import HomePage from "src/pages/HomePage";
import BlogLayout from "src/layouts/BlogLayout";
import BlogLayout from 'src/layouts/BlogLayout'
import ContactsLayout from 'src/layouts/ContactsLayout'
import PostsLayout from 'src/layouts/PostsLayout'
import HomePage from 'src/pages/HomePage'

const Routes = () => {
return (
(<Router>
<Router>
<Route path="/login" page={LoginPage} name="login" />
<Route path="/signup" page={SignupPage} name="signup" />
<Route path="/forgot-password" page={ForgotPasswordPage} name="forgotPassword" />
<Route path="/reset-password" page={ResetPasswordPage} name="resetPassword" />
<Set wrap={ContactsLayout}>
<Route path="/contacts/new" page={ContactNewContactPage} name="newContact" />
<Route path="/contacts/{id:Int}/edit" page={ContactEditContactPage} name="editContact" />
<Route path="/contacts/{id:Int}" page={ContactContactPage} name="contact" />
<Route path="/contacts" page={ContactContactsPage} name="contacts" />
<Route path="/contacts/new" page={ContactNewContactPage} name="newContact" />
<Route path="/contacts/{id:Int}/edit" page={ContactEditContactPage} name="editContact" />
<Route path="/contacts/{id:Int}" page={ContactContactPage} name="contact" />
<Route path="/contacts" page={ContactContactsPage} name="contacts" />
</Set>
<Set wrap={PostsLayout}>
<Route path="/posts/new" page={PostNewPostPage} name="newPost" />
<Route path="/posts/{id:Int}/edit" page={PostEditPostPage} name="editPost" />
<Route path="/posts/{id:Int}" page={PostPostPage} name="post" />
<Route path="/posts" page={PostPostsPage} name="posts" />
<Route path="/posts/new" page={PostNewPostPage} name="newPost" />
<Route path="/posts/{id:Int}/edit" page={PostEditPostPage} name="editPost" />
<Route path="/posts/{id:Int}" page={PostPostPage} name="post" />
<Route path="/posts" page={PostPostsPage} name="posts" />
</Set>
<Set wrap={BlogLayout}>
<Private unauthenticated="login"><Route path="/profile" page={ProfilePage} name="profile" /></Private>
<Private unauthenticated="login">
<Route path="/profile" page={ProfilePage} name="profile" />
</Private>
<Route path="/blog-post/{id:Int}" page={BlogPostPage} name="blogPost" />
<Route path="/contact" page={ContactPage} name="contact" />
<Route path="/about" page={AboutPage} name="about" prerender />
<Route path="/" page={HomePage} name="home" prerender />
<Route notfound page={NotFoundPage} prerender />
</Set></Router>)
);
</Set>
</Router>
)
}

export default Routes
Loading

0 comments on commit 665037c

Please sign in to comment.