Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/collections/auditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { hookTypes } from './../pluginUtils/configHelpers.js'
import { defaultCollectionValues } from '../Constant/Constant.js'

export type AuditorLog = {
collection: string
onCollection: string
documentId?: string
hook: (typeof hookTypes)[number]
operation: AuditHookOperationType
Expand All @@ -30,7 +30,7 @@ export const auditor: CollectionConfig = {
update: () => false,
},
admin: {
defaultColumns: ['operation', 'type', 'collection', 'user', 'timestamp'],
defaultColumns: ['operation', 'type', 'onCollection', 'user', 'timestamp'],
useAsTitle: 'type',
},
fields: [
Expand All @@ -40,7 +40,7 @@ export const auditor: CollectionConfig = {
required: true,
},
{
name: 'collection',
name: 'onCollection',
type: 'text',
required: true,
},
Expand Down
2 changes: 1 addition & 1 deletion src/collections/hooks/beforeChange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const autoLogCleaner: BeforeChangeHook<AutoLogCleanerProps> = async ({
const millisecondsAgo = new Date(
Date.now() - ms(data.olderThan || cleanupStrategiesDefaultValues.manual.olderThan),
)
const collectionSlug = context.pluginOptions.collection?.slug ?? defaultCollectionValues.slug
const collectionSlug = context.pluginOptions.collections?.slug ?? defaultCollectionValues.slug
const limit = context.pluginOptions.automation?.logCleanup?.strategy?.amount ?? 100

const oldLogsToDelete = await req.payload.find({
Expand Down
8 changes: 4 additions & 4 deletions src/core/buffer/bufferManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ afterEach(() => {
describe('bufferManager', () => {
it('should flush when buffer reaches size limit', async () => {
const pluginOptions = {
collection: {
collections: {
buffer: {
flushStrategy: 'size',
size: 2,
Expand All @@ -50,7 +50,7 @@ describe('bufferManager', () => {

it('should flush immediately in realtime mode', async () => {
const pluginOptions = {
collection: {
collections: {
buffer: {
flushStrategy: 'realtime',
},
Expand All @@ -69,7 +69,7 @@ describe('bufferManager', () => {

it('should flush periodically in time mode', async () => {
const pluginOptions = {
collection: {
collections: {
buffer: {
flushStrategy: 'time',
time: '2s',
Expand All @@ -93,7 +93,7 @@ describe('bufferManager', () => {

it('should clear buffer after flushing', async () => {
const pluginOptions = {
collection: {
collections: {
buffer: {
flushStrategy: 'size',
size: 1,
Expand Down
6 changes: 3 additions & 3 deletions src/core/buffer/bufferManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const store: AuditorLog[] = []
let payloadInstance: Payload

export const bufferManager = (payload: Payload, pluginOptions: PluginOptions) => {
const bufferConfig = pluginOptions.collection?.buffer
const bufferConfig = pluginOptions.collections?.buffer
const size = bufferConfig?.size ?? 10
const interval = ms(bufferConfig?.time ?? '5s')
const flushStrategy = bufferConfig?.flushStrategy ?? 'time'
Expand Down Expand Up @@ -49,8 +49,8 @@ const flushBuffer = async (pluginOptions: PluginOptions) => {
await Promise.all(
logsToInsert.map((log) =>
payloadInstance.create({
collection: pluginOptions.collection?.slug
? pluginOptions.collection?.slug
collection: pluginOptions.collections?.slug
? pluginOptions.collections?.slug
: defaultCollectionValues.slug,
data: log,
}),
Expand Down
2 changes: 1 addition & 1 deletion src/core/log-builders/collections/helpers/emitWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const emitWrapper = async <T extends keyof AllCollectionHooks>(
return {
...result,
type: result.type,
collection: result.collection,
onCollection: result.onCollection,
documentId: result.documentId,
hook,
operation: result.operation,
Expand Down
2 changes: 1 addition & 1 deletion src/core/log-builders/collections/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const sharedLogic = async <T extends keyof AllCollectionHooks>(

const baseLog: AuditorLog = {
type: 'unknown',
collection: sharedArgs.collection.slug,
onCollection: sharedArgs.collection.slug,
documentId: 'unknown',
hook: sharedArgs.hook,
operation: sharedArgs.operation,
Expand Down
6 changes: 3 additions & 3 deletions src/pluginUtils/configHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export const hookTypes = [
] as const

export const buildAccessControl = (pluginOpts: PluginOptions) => {
const roles: RoleAccessMap = pluginOpts?.collection?.Accessibility?.roles ?? {}
const customAccess: CustomAccessMap = pluginOpts?.collection?.Accessibility?.customAccess ?? {}
const roles: RoleAccessMap = pluginOpts?.collections?.Accessibility?.roles ?? {}
const customAccess: CustomAccessMap = pluginOpts?.collections?.Accessibility?.customAccess ?? {}

const defaultAccess: Access = ({ req }) => req.user?.role === 'admin'

Expand All @@ -62,7 +62,7 @@ export const attachCollectionConfig = (
userCollectionsConfig: Config['collections'],
pluginOpts: PluginOptions,
) => {
const pluginCollectionsConfig = pluginOpts.collection
const pluginCollectionsConfig = pluginOpts.collections
if (!pluginCollectionsConfig) {
return userCollectionsConfig
}
Expand Down
2 changes: 1 addition & 1 deletion src/types/pluginOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2037,7 +2037,7 @@ export type PluginOptions = {
* - If defined, you must also enter the value of trackCollections.
*
*/
collection?: PluginCollectionConfig
collections?: PluginCollectionConfig
/**
* 📝 Custom log creation at a global level
*
Expand Down