import { Model } from "mongoose"; import { MongooseModule, } from "../helpers"; import { SAMLType } from "../types/saml"; export interface SAML extends SAMLType { } export function SAMLSchema(mongoose: MongooseModule) { const { Schema } = mongoose; const SAML = new Schema({ _id: { type: Schema.Types.ObjectId, auto: true, }, selector: { type: String, required: true, // Index set at schema level, to be able to specify name and/or other options }, idp: { type: String, default: "", }, sp: { type: String, default: "", }, env: { type: String, default: "", }, name: { type: String, default: "", }, // For Google Accounts, append https://accounts.google.com/accountchooser?continue= // Options: none, google jumpPoint: { type: String, default: "", }, }, { _id: false, id: false, timestamps: true, autoIndex: false, toJSON: { virtuals: true, versionKey: false, } }); return SAML; } export default async function SAMLModule(mongoose: MongooseModule) { const modelSchema = SAMLSchema(mongoose); // Unique selector modelSchema.index({ selector: 1, }, { name: "selector_unique", unique: true, }); return mongoose.model("SAML", modelSchema, "massive_saml", { overwriteModels: true }); } export interface SAMLModel extends Model { }