docs/docs/en/users-permissions/sync/dev/resource.md
NocoBase natively supports syncing user data to the User and Department tables. It also allows for extending the target resources for data synchronization to write data to other tables or perform custom processing as needed.
:::warning{title=Experimental} Full documentation is pending. :::
export abstract class UserDataResource {
name: string;
accepts: SyncAccept[];
db: Database;
logger: SystemLogger;
constructor(db: Database, logger: SystemLogger) {
this.db = db;
this.logger = logger;
}
abstract update(
record: OriginRecord,
resourcePks: PrimaryKey[],
matchKey?: string,
): Promise<RecordResourceChanged[]>;
abstract create(
record: OriginRecord,
matchKey: string,
): Promise<RecordResourceChanged[]>;
get syncRecordRepo() {
return this.db.getRepository('userDataSyncRecords');
}
get syncRecordResourceRepo() {
return this.db.getRepository('userDataSyncRecordsResources');
}
}
registerResource(resource: UserDataResource, options?: ToposortOptions)
import { Plugin } from '@nocobase/server';
import PluginUserDataSyncServer from '@nocobase/plugin-user-data-sync';
class CustomUserResourcePluginServer extends Plugin {
async load() {
const userDataSyncPlugin = this.app.pm.get(PluginUserDataSyncServer);
if (userDataSyncPlugin && userDataSyncPlugin.enabled) {
userDataSyncPlugin.resourceManager.registerResource(
new CustomDataSyncResource(this.db, this.app.logger),
);
}
}
}