Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
68 lines
1.9 KiB
Plaintext
68 lines
1.9 KiB
Plaintext
import { confirmPassword, password } from 'payload/shared';
|
|
import { traverseFields } from './traverseFields.js';
|
|
const baseAuthFields = [{
|
|
name: 'password',
|
|
type: 'text',
|
|
required: true,
|
|
validate: password
|
|
}, {
|
|
name: 'confirm-password',
|
|
type: 'text',
|
|
required: true,
|
|
validate: confirmPassword
|
|
}];
|
|
/**
|
|
* Flattens the config fields into a map of field schemas
|
|
*/
|
|
export const buildFieldSchemaMap = args => {
|
|
const {
|
|
collectionSlug,
|
|
config,
|
|
globalSlug,
|
|
i18n
|
|
} = args;
|
|
const schemaMap = new Map();
|
|
if (collectionSlug) {
|
|
const matchedCollection = config.collections.find(collection => collection.slug === collectionSlug);
|
|
if (matchedCollection) {
|
|
let fieldsToSet = matchedCollection?.fields || [];
|
|
if (matchedCollection.auth && !matchedCollection.auth.disableLocalStrategy) {
|
|
;
|
|
baseAuthFields[0].label = i18n.t('general:password');
|
|
baseAuthFields[1].label = i18n.t('authentication:confirmPassword');
|
|
// Place these fields _last_ to ensure they do not disrupt field paths in the field schema map
|
|
fieldsToSet = fieldsToSet.concat(baseAuthFields);
|
|
}
|
|
schemaMap.set(collectionSlug, {
|
|
fields: fieldsToSet
|
|
});
|
|
traverseFields({
|
|
config,
|
|
fields: fieldsToSet,
|
|
i18n,
|
|
parentIndexPath: '',
|
|
parentSchemaPath: collectionSlug,
|
|
schemaMap
|
|
});
|
|
}
|
|
} else if (globalSlug) {
|
|
const matchedGlobal = config.globals.find(global => global.slug === globalSlug);
|
|
if (matchedGlobal) {
|
|
schemaMap.set(globalSlug, {
|
|
fields: matchedGlobal.fields
|
|
});
|
|
traverseFields({
|
|
config,
|
|
fields: matchedGlobal.fields,
|
|
i18n,
|
|
parentIndexPath: '',
|
|
parentSchemaPath: globalSlug,
|
|
schemaMap
|
|
});
|
|
}
|
|
}
|
|
return {
|
|
fieldSchemaMap: schemaMap
|
|
};
|
|
};
|
|
//# sourceMappingURL=index.js.map |