Skip to content

Commit

Permalink
feat(auth): fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
bahdcoder committed Oct 30, 2021
1 parent ac9dc1d commit 5c17503
Show file tree
Hide file tree
Showing 29 changed files with 152 additions and 48,420 deletions.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"scripts": {
"test": "wsrun -p '@tensei/tests' -c test",
"test:watch": "wsrun -p '@tensei/tests' -c test:watch",
"build": "yarn lerna run build",
"build": " yarn clean && yarn lerna run build",
"clean": "node scripts/clean.js",
"dev": "yarn lerna run dev",
"prettier": "prettier --write './**/*.{js,json,ts,css}'",
"release": "./scripts/release.sh",
Expand Down Expand Up @@ -47,7 +48,8 @@
"commitizen": "^4.2.2",
"husky": "^4.3.0",
"lerna": "^3.22.1",
"prettier": "^2.0.5"
"prettier": "^2.0.5",
"rimraf": "^3.0.2"
},
"devDependencies": {
"wsrun": "^5.2.4"
Expand Down
11 changes: 0 additions & 11 deletions packages/auth/auth.config.d.ts

This file was deleted.

19 changes: 10 additions & 9 deletions packages/auth/auth.d.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { Mail } from '@tensei/mail'
import { AnyEntity } from '@mikro-orm/core'
import { DataPayload } from '@tensei/common'
import { SessionData } from 'express-session'
import * as Formatter from 'express-response-formatter'
import { GraphQLPluginContext, DataPayload } from '@tensei/common'

declare module '@tensei/common' {
interface GraphQLPluginContext {
// @ts-ignore
authUser: DataPayload & import('@tensei/orm').UserModel
// @ts-ignore
team: import('@tensei/orm').TeamModel
}
}

declare global {
namespace Express {
export interface Request {
// @ts-ignore
authUser: import('@tensei/orm').UserModel & DataPayload
// @ts-ignore
team: import('@tensei/orm').TeamModel
verifyTwoFactorAuthToken: (token: string | number) => boolean
isGraphqlRequest?: boolean
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
"license": "MIT",
"files": [
"build/",
"auth.d.ts",
"teams.d.ts",
"auth.config.d.ts"
"auth.d.ts"
],
"types": "./build/index.d.ts",
"types": "types.d.ts",
"devDependencies": {
"@types/express": "^4.17.6",
"@types/jest": "^25.2.3",
Expand Down
17 changes: 13 additions & 4 deletions packages/auth/src/teams/Teams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,17 +184,24 @@ export class Teams {
}
input InviteTeamMemberInput {
### A list of all permissions the new team meber will have.
permissions: [TeamPermissionString]
### The email of invited member. This has to be the email of that user in the application.
email: String!
}
extend type Mutation {
### Invite an existing user to join the team
inviteTeamMember(teamId: ID!, object: InviteTeamMemberInput): Boolean!
}
extend type Query {
# Get all teams the authenticated user belongs to
allTeams: [Team]
# Get a list of all permissions this user has on the currently selected team
teamPermissions: [TeamPermission]
# Get all memberships of a specific team. This includes information about all the team members.
teamMemberships(teamId: ID!): [Membership]
}
`
Expand All @@ -208,7 +215,8 @@ export class Teams {
return [
graphQlQuery('Get team permissions')
.path('teamPermissions')
.authorize(({ authUser, team }) => authUser.belongsToTeam(team))
.description(`Get a list of all existing team permissions.`)
.authorize(({ authUser, team }) => authUser?.belongsToTeam(team))
.query()
.handle(async (_, args, ctx, info) => {
return this.auth.config.teamPermissions.map(
Expand All @@ -218,7 +226,8 @@ export class Teams {
graphQlQuery('Invite team member')
.path('inviteTeamMember')
.mutation()
.authorize(({ authUser, team }) => authUser.ownsTeam(team))
.description('Invite an existing user to join a team')
.authorize(({ authUser, team }) => authUser?.ownsTeam(team))
.middleware(findTeamQueryMiddleware)
.handle(async (_, args, ctx, info) => {
const permissions = ctx?.body?.object?.permissions?.map(
Expand All @@ -232,7 +241,7 @@ export class Teams {

return true
}),
graphQlQuery('All teams for a user')
graphQlQuery('Get all teams for a user')
.path('allTeams')
.authorize(({ authUser }) => !!authUser)
.handle(async (_, args, ctx, info) => {
Expand All @@ -255,7 +264,7 @@ export class Teams {
graphQlQuery('Get team memberships')
.path('teamMemberships')
.authorize(
async ({ authUser, team }) => await authUser.belongsToTeam(team)
async ({ authUser, team }) => await authUser?.belongsToTeam(team)
)
.handle(async (_, args, ctx, info) => {
const { team, manager } = ctx
Expand Down
4 changes: 4 additions & 0 deletions packages/auth/teams.d.ts → packages/auth/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export * from './build'

declare module '@tensei/orm' {
import { TeamModel, MembershipModel } from '@tensei/orm'

Expand All @@ -8,5 +10,7 @@ declare module '@tensei/orm' {
teamPermissions: (team: TeamModel) => Promise<string[]>
teamMembership: (team: TeamModel) => Promise<MembershipModel>
hasTeamPermission: (team: TeamModel, permission: string) => Promise<boolean>

// Roles and permissions
}
}
2 changes: 1 addition & 1 deletion packages/cms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"copy-files": "copyfiles -u 1 plugin/template/index.mustache build/",
"dev-client": "webpack --config=node_modules/laravel-mix/setup/webpack.config.js --stats=errors-only --watch",
"build-client": "cross-env NODE_ENV=production webpack --config=node_modules/laravel-mix/setup/webpack.config.js",
"build": "rimraf build && yarn build-server && yarn build-client"
"build": "yarn build-server && yarn build-client"
},
"devDependencies": {
"@babel/plugin-proposal-class-properties": "^7.12.1",
Expand Down
Loading

0 comments on commit 5c17503

Please sign in to comment.