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
2 changes: 2 additions & 0 deletions dev/app/(payload)/admin/importMap.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { UserRelationshipField as UserRelationshipField_9512be49db7fedcad602e19aa5fc10a8 } from '../../../collections/fields/UserRelationshipField'
import { CollectionCards as CollectionCards_f9c02e79a4aed9a3924487c0cd4cafb1 } from '@payloadcms/next/rsc'

export const importMap = {
"./collections/fields/UserRelationshipField#UserRelationshipField": UserRelationshipField_9512be49db7fedcad602e19aa5fc10a8,
"@payloadcms/next/rsc#CollectionCards": CollectionCards_f9c02e79a4aed9a3924487c0cd4cafb1
}
8 changes: 8 additions & 0 deletions dev/collections/AppAccounts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { CollectionConfig } from 'payload';

export const AppAccounts: CollectionConfig = {
slug: 'app-accounts',
auth: true,
fields: [
],
};
2 changes: 1 addition & 1 deletion dev/collections/Media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const media: CollectionConfig = {
create: authenticated,
delete: authenticated,
read: anyone,
update: authenticated,
update: anyone,
},
fields: [
{
Expand Down
39 changes: 39 additions & 0 deletions dev/collections/fields/UserRelationshipField.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use client';
import * as React from 'react';
import { RelationshipInput, useField } from '@payloadcms/ui';
import type { CollectionSlug, JSONFieldClientComponent } from 'payload';


interface UserData {
collection: CollectionSlug;
id: string;
}

export const UserRelationshipField: JSONFieldClientComponent = ({ path }) => {
const { value, setValue } = useField({ path }) as {
value: UserData | null;
setValue: (val: unknown) => void;
};

const handleChange = React.useCallback(
(val: unknown) => {
setValue(val);
},
[setValue],
);

if (!value?.collection || !value?.id) {
return <RelationshipInput path={path} relationTo={[]} onChange={handleChange} hasMany={false} />;
}

return (
<RelationshipInput
path={path}
relationTo={[value.collection]}
onChange={handleChange}
hasMany={false}
value={{ relationTo: value.collection, value: value.id }}
Label="User"
/>
);
};
136 changes: 113 additions & 23 deletions dev/payload-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,13 @@ export type SupportedTimezones =
export interface Config {
auth: {
users: UserAuthOperations;
'app-accounts': AppAccountAuthOperations;
};
blocks: {};
collections: {
media: Media;
users: User;
'app-accounts': AppAccount;
'Audit-log': AuditLog;
'payload-kv': PayloadKv;
'payload-jobs': PayloadJob;
Expand All @@ -80,6 +82,7 @@ export interface Config {
collectionsSelect: {
media: MediaSelect<false> | MediaSelect<true>;
users: UsersSelect<false> | UsersSelect<true>;
'app-accounts': AppAccountsSelect<false> | AppAccountsSelect<true>;
'Audit-log': AuditLogSelect<false> | AuditLogSelect<true>;
'payload-kv': PayloadKvSelect<false> | PayloadKvSelect<true>;
'payload-jobs': PayloadJobsSelect<false> | PayloadJobsSelect<true>;
Expand All @@ -88,7 +91,7 @@ export interface Config {
'payload-migrations': PayloadMigrationsSelect<false> | PayloadMigrationsSelect<true>;
};
db: {
defaultIDType: string;
defaultIDType: number;
};
fallbackLocale: null;
globals: {
Expand All @@ -98,7 +101,7 @@ export interface Config {
'payload-jobs-stats': PayloadJobsStatsSelect<false> | PayloadJobsStatsSelect<true>;
};
locale: null;
user: User;
user: User | AppAccount;
jobs: {
tasks: {
'cleanup-payload-auditor-log': TaskCleanupPayloadAuditorLog;
Expand Down Expand Up @@ -128,12 +131,30 @@ export interface UserAuthOperations {
password: string;
};
}
export interface AppAccountAuthOperations {
forgotPassword: {
email: string;
password: string;
};
login: {
email: string;
password: string;
};
registerFirstUser: {
email: string;
password: string;
};
unlock: {
email: string;
password: string;
};
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "media".
*/
export interface Media {
id: string;
id: number;
altText?: string | null;
caption?: string | null;
updatedAt: string;
Expand All @@ -153,7 +174,7 @@ export interface Media {
* via the `definition` "users".
*/
export interface User {
id: string;
id: number;
role: 'admin' | 'user' | 'test' | 'orbital';
updatedAt: string;
createdAt: string;
Expand All @@ -174,16 +195,49 @@ export interface User {
password?: string | null;
collection: 'users';
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "app-accounts".
*/
export interface AppAccount {
id: number;
updatedAt: string;
createdAt: string;
email: string;
resetPasswordToken?: string | null;
resetPasswordExpiration?: string | null;
salt?: string | null;
hash?: string | null;
loginAttempts?: number | null;
lockUntil?: string | null;
sessions?:
| {
id: string;
createdAt?: string | null;
expiresAt: string;
}[]
| null;
password?: string | null;
collection: 'app-accounts';
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "Audit-log".
*/
export interface AuditLog {
id: string;
id: number;
operation: string;
onCollection: string;
documentId?: string | null;
user: string | User;
user?:
| {
[k: string]: unknown;
}
| unknown[]
| string
| number
| boolean
| null;
userAgent?: string | null;
hook?: string | null;
type: 'info' | 'debug' | 'warning' | 'error' | 'audit' | 'security' | 'unknown';
Expand All @@ -194,7 +248,7 @@ export interface AuditLog {
* via the `definition` "payload-kv".
*/
export interface PayloadKv {
id: string;
id: number;
key: string;
data:
| {
Expand All @@ -211,7 +265,7 @@ export interface PayloadKv {
* via the `definition` "payload-jobs".
*/
export interface PayloadJob {
id: string;
id: number;
/**
* Input data provided to the job
*/
Expand Down Expand Up @@ -312,25 +366,34 @@ export interface PayloadJob {
* via the `definition` "payload-locked-documents".
*/
export interface PayloadLockedDocument {
id: string;
id: number;
document?:
| ({
relationTo: 'media';
value: string | Media;
value: number | Media;
} | null)
| ({
relationTo: 'users';
value: string | User;
value: number | User;
} | null)
| ({
relationTo: 'app-accounts';
value: number | AppAccount;
} | null)
| ({
relationTo: 'Audit-log';
value: string | AuditLog;
value: number | AuditLog;
} | null);
globalSlug?: string | null;
user: {
relationTo: 'users';
value: string | User;
};
user:
| {
relationTo: 'users';
value: number | User;
}
| {
relationTo: 'app-accounts';
value: number | AppAccount;
};
updatedAt: string;
createdAt: string;
}
Expand All @@ -339,11 +402,16 @@ export interface PayloadLockedDocument {
* via the `definition` "payload-preferences".
*/
export interface PayloadPreference {
id: string;
user: {
relationTo: 'users';
value: string | User;
};
id: number;
user:
| {
relationTo: 'users';
value: number | User;
}
| {
relationTo: 'app-accounts';
value: number | AppAccount;
};
key?: string | null;
value?:
| {
Expand All @@ -362,7 +430,7 @@ export interface PayloadPreference {
* via the `definition` "payload-migrations".
*/
export interface PayloadMigration {
id: string;
id: number;
name?: string | null;
batch?: number | null;
updatedAt: string;
Expand Down Expand Up @@ -410,6 +478,28 @@ export interface UsersSelect<T extends boolean = true> {
expiresAt?: T;
};
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "app-accounts_select".
*/
export interface AppAccountsSelect<T extends boolean = true> {
updatedAt?: T;
createdAt?: T;
email?: T;
resetPasswordToken?: T;
resetPasswordExpiration?: T;
salt?: T;
hash?: T;
loginAttempts?: T;
lockUntil?: T;
sessions?:
| T
| {
id?: T;
createdAt?: T;
expiresAt?: T;
};
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "Audit-log_select".
Expand Down Expand Up @@ -501,7 +591,7 @@ export interface PayloadMigrationsSelect<T extends boolean = true> {
* via the `definition` "payload-jobs-stats".
*/
export interface PayloadJobsStat {
id: string;
id: number;
stats?:
| {
[k: string]: unknown;
Expand Down
18 changes: 11 additions & 7 deletions dev/payload.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ import { fileURLToPath } from 'node:url';
import { media } from 'collections/Media.js';
import { users } from 'collections/Users.js';
// import { auditorPlugin } from 'payload-auditor';
import { mongooseAdapter } from '@payloadcms/db-mongodb';
import { postgresAdapter } from '@payloadcms/db-postgres';
import { lexicalEditor } from '@payloadcms/richtext-lexical';

// import { auditorPlugin } from './../dist/index.js';
import { auditorPlugin } from '../src/index.js';

import { testEmailAdapter } from './helpers/testEmailAdapter.js';
import { AppAccounts } from './collections/AppAccounts.js';


const filename = fileURLToPath(import.meta.url);
const dirname = path.dirname(filename);
Expand All @@ -22,17 +25,18 @@ if (!process.env.ROOT_DIR) {

export default buildConfig({
admin: { importMap: { baseDir: path.resolve(dirname) } },
collections: [media, users],
db: mongooseAdapter({ url: process.env.DATABASE_URI || '', connectOptions: {
dbName: 'payload-auditor-db',
appName: 'payload-auditor-app',
} }),
collections: [media, users, AppAccounts],
db: postgresAdapter({
pool: {
connectionString: process.env.DATABASE_URL || '',
},
}),
editor: lexicalEditor(),
email: testEmailAdapter,
// plugins
plugins: [
auditorPlugin({
automation: { logCleanup: { cronTime: '*/1 * * * *', queueName: 'test', olderThan: 30000 } },
// automation: { logCleanup: { cronTime: '*/1 * * * *', queueName: 'test', olderThan: 30000 } },
collection: {
// configureRootCollection(defaults) {
// return {
Expand Down
Loading