Skip to content

Commit

Permalink
fix(auth): remove unused packages (csrf, csurf)
Browse files Browse the repository at this point in the history
  • Loading branch information
Frantz Kati committed Dec 4, 2020
1 parent 109ad62 commit c9a58da
Show file tree
Hide file tree
Showing 21 changed files with 26 additions and 164 deletions.
17 changes: 0 additions & 17 deletions media-library.md

This file was deleted.

1 change: 0 additions & 1 deletion packages/auth/auth.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ declare global {

declare module 'express-session' {
interface SessionData {
views: number
user: {
id: number
}
Expand Down
4 changes: 0 additions & 4 deletions packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
"@purest/providers": "^1.0.1",
"@tensei/common": "^0.4.1",
"@types/bcryptjs": "^2.4.2",
"@types/csrf": "^1.3.2",
"@types/csurf": "^1.11.0",
"@types/express-session": "^1.17.3",
"@types/jsonwebtoken": "^8.5.0",
"@types/qrcode": "^1.3.5",
Expand All @@ -51,8 +49,6 @@
"@types/uniqid": "^5.2.0",
"bcryptjs": "^2.4.3",
"change-case": "^4.1.1",
"csrf": "^3.1.0",
"csurf": "^1.11.0",
"dayjs": "^1.8.34",
"express-session": "^1.17.1",
"grant": "^5.4.4",
Expand Down
14 changes: 1 addition & 13 deletions packages/auth/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,6 @@ class Auth {
return this
}

public tokenExpiresIn(tokenExpiresIn: number) {
this.config.tokensConfig.accessTokenExpiresIn = tokenExpiresIn

return this
}

public tokenSecretKey(secret: string) {
this.config.tokensConfig.secretKey = secret

return this
}

public apiPath(path: string) {
this.config.apiPath = path

Expand Down Expand Up @@ -1961,7 +1949,7 @@ class Auth {
}

private getRoleUserKey() {
return this.resources.role.data.snakeCaseName
return this.resources.role.data.snakeCaseNamePlural
}

private getPermissionUserKey() {
Expand Down
7 changes: 0 additions & 7 deletions packages/common/src/api/GraphQlQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export class GraphQlQuery implements GraphQlQueryContract {
path: '',
name: '',
internal: false,
csrf: true,
type: 'QUERY',
middleware: [],
snakeCaseName: '',
Expand Down Expand Up @@ -85,12 +84,6 @@ export class GraphQlQuery implements GraphQlQueryContract {
return this
}

noCsrf() {
this.config.csrf = false

return this
}

internal() {
this.config.internal = true

Expand Down
7 changes: 0 additions & 7 deletions packages/common/src/api/Route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export class Route implements RouteContract {
} = {
path: '',
name: '',
csrf: true,
type: 'GET',
internal: false,
middleware: [],
Expand Down Expand Up @@ -101,12 +100,6 @@ export class Route implements RouteContract {
return this
}

noCsrf() {
this.config.csrf = false

return this
}

extend(extend: RouteExtendContract) {
this.config.extend = extend

Expand Down
4 changes: 0 additions & 4 deletions packages/common/typings/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ declare module '@tensei/common/config' {
put(): this
patch(): this
delete(): this
noCsrf(): this
internal(): this
extend(extend: RouteExtendContract): this
resource(resource: ResourceContract): this
Expand Down Expand Up @@ -76,7 +75,6 @@ declare module '@tensei/common/config' {
config: GraphQlQueryConfig
path(path: string): this
query(): this
noCsrf(): this
mutation(): this
internal(): this
subscription(): this
Expand All @@ -90,7 +88,6 @@ declare module '@tensei/common/config' {
interface RouteConfig {
path: string
name: string
csrf: boolean
internal: boolean
type: EndpointTypes
snakeCaseName: string
Expand All @@ -108,7 +105,6 @@ declare module '@tensei/common/config' {
> {
path: string
name: string
csrf: boolean
middleware: GraphQlQueryConfig['handler'][]
internal: boolean
snakeCaseName: string
Expand Down
9 changes: 4 additions & 5 deletions packages/core/Tensei.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,9 @@ export class Tensei implements TenseiContract {

this.server.listen(port, () => {
this.ctx.logger.success(
`🚀 Access your server on ${this.ctx.serverUrl ||
`http://127.0.0.1:${port}`}`
`🚀 Access your server on ${
this.ctx.serverUrl || `http://127.0.0.1:${port}`
}`
)
})
}
Expand Down Expand Up @@ -562,9 +563,7 @@ export class Tensei implements TenseiContract {
}

private mail(driverName: SupportedDrivers, mailConfig = {}) {
this.ctx.mailer = mail()
.connection(driverName)
.config(mailConfig)
this.ctx.mailer = mail().connection(driverName).config(mailConfig)

return this
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/database/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class Database {
}

private generateEntityClass(resource: ResourceContract) {
const entityClass = function() {}
const entityClass = function () {}

Object.defineProperty(entityClass, 'name', {
value: resource.data.pascalCaseName,
Expand Down
5 changes: 1 addition & 4 deletions packages/express-session-mikro-orm/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ const StoreFactory = (Store: any) => {
this.options.tableName,
(table: any) => {
table.string('session_id').primary()
table
.datetime('expires')
.nullable()
.index()
table.datetime('expires').nullable().index()
table.text('data').notNullable()
}
)
Expand Down
4 changes: 1 addition & 3 deletions packages/media/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ class MediaLibrary {

if (fileFields.length) {
MediaResource.fields([
belongsTo(resource.data.name)
.nullable()
.hidden()
belongsTo(resource.data.name).nullable().hidden()
])
}
})
Expand Down
12 changes: 3 additions & 9 deletions packages/media/src/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,13 @@ export const mediaResource = () =>
.searchable(),
integer('Width').nullable(),
integer('Height').nullable(),
text('Original Filename')
.nullable()
.searchable(),
text('Original Filename').nullable().searchable(),
text('Extension')
.description('The file extension, for example psd, pdf, png')
.searchable(),
text('Mime Type')
.nullable()
.searchable(),
text('Mime Type').nullable().searchable(),
text('Hash').searchable(),
text('Path')
.nullable()
.searchable(),
text('Path').nullable().searchable(),
text('Alt Text').nullable(),
text('Disk').nullable(),
json('Disk Meta').nullable(),
Expand Down
4 changes: 1 addition & 3 deletions packages/tests/helpers/resources/Comment.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { text, resource, textarea, belongsTo } from '@tensei/common'

export default resource('Comment').fields([
text('Title')
.rules('required')
.searchable(),
text('Title').rules('required').searchable(),
textarea('Body').rules('required'),
belongsTo('Post')
])
4 changes: 1 addition & 3 deletions packages/tests/helpers/resources/Post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ export default resource('Post')
textarea('Content')
.rules('required', 'max:2000', 'min:12')
.hideOnIndex(),
integer('Av. CPC')
.rules('required')
.hideOnDetail(),
integer('Av. CPC').rules('required').hideOnDetail(),
select('Category')
.options([
{
Expand Down
9 changes: 2 additions & 7 deletions packages/tests/helpers/resources/Tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@ import { text, resource, textarea, belongsToMany, number } from '@tensei/common'

export default resource('Tag')
.fields([
text('Name')
.rules('required')
.searchable(),
number('Priority')
.nullable()
.default(1)
.rules('integer', 'under:5'),
text('Name').rules('required').searchable(),
number('Priority').nullable().default(1).rules('integer', 'under:5'),
textarea('Description'),
belongsToMany('Post')
])
Expand Down
4 changes: 1 addition & 3 deletions packages/tests/helpers/resources/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import { text, resource, hasMany } from '@tensei/common'

export default resource('User')
.fields([
text('Full name')
.searchable()
.rules('required'),
text('Full name').searchable().rules('required'),
text('Email')
.unique()
.searchable()
Expand Down
4 changes: 1 addition & 3 deletions packages/tests/helpers/resources/UserNoRel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import { text, hasMany, resource } from '@tensei/common'

export default resource('User')
.fields([
text('Full name')
.searchable()
.rules('required'),
text('Full name').searchable().rules('required'),
text('Email')
.unique()
.searchable()
Expand Down
27 changes: 5 additions & 22 deletions packages/tests/packages/auth/auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ test('Registers auth resources when plugin is registered', async () => {
test('Can customize the name of the authenticator user', async () => {
const {
ctx: { resources }
} = await setup([
auth()
.user('Customer')
.plugin()
])
} = await setup([auth().user('Customer').plugin()])

expect(
resources.find(resource => resource.data.name === 'Customer')
Expand All @@ -31,11 +27,7 @@ test('Can customize the name of the authenticator user', async () => {
test('Enabling roles and permissions registers Role and permission resources', async () => {
const {
ctx: { resources }
} = await setup([
auth()
.rolesAndPermissions()
.plugin()
])
} = await setup([auth().rolesAndPermissions().plugin()])

expect(
resources.filter(resource =>
Expand Down Expand Up @@ -213,10 +205,7 @@ test('Can request a password reset and reset password', async () => {
},
app
} = await setup([
auth()
.verifyEmails()
.user('Student')
.plugin(),
auth().verifyEmails().user('Student').plugin(),
graphql().plugin(),
setupFakeMailer(mailerMock)
])
Expand Down Expand Up @@ -309,10 +298,7 @@ test('Can login and stay authenticated with cookie based applications', async ()
},
app
} = await setup([
auth()
.verifyEmails()
.user('Student')
.plugin(),
auth().verifyEmails().user('Student').plugin(),
graphql().plugin()
])

Expand Down Expand Up @@ -635,10 +621,7 @@ test('if a refresh token is used twice (compromised), the user is automatically
},
app
} = await setup([
auth()
.user('Customer')
.noCookies()
.plugin(),
auth().user('Customer').noCookies().plugin(),
graphql().plugin()
])

Expand Down
5 changes: 1 addition & 4 deletions packages/tests/packages/media/setup/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ export const setup = (maxFileSize = 10000000) =>
plugin('Add meeting resource').register(({ extendResources }) => {
extendResources([meetingResource(), gistResource()])
}),
media()
.maxFiles(4)
.maxFileSize(maxFileSize)
.plugin(),
media().maxFiles(4).maxFileSize(maxFileSize).plugin(),
graphql().plugin()
],
true
Expand Down
2 changes: 1 addition & 1 deletion packages/trix/src/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'trix/dist/trix.css'

const TrixField = 'TrixField'

Tensei.booting(function() {
Tensei.booting(function () {
this.field(TrixField, Trix)

this.detailField(TrixField, TrixDetail)
Expand Down
Loading

0 comments on commit c9a58da

Please sign in to comment.