'use strict';

function readDeclarativeSignInResolver(options) {
  const resolvers = options.config.getOptionalConfigArray("signIn.resolvers")?.map((resolverConfig) => {
    const resolverName = resolverConfig.getString("resolver");
    if (!Object.hasOwn(options.signInResolverFactories, resolverName)) {
      throw new Error(
        `Sign-in resolver '${resolverName}' is not available`
      );
    }
    const resolver = options.signInResolverFactories[resolverName];
    const { resolver: _ignored, ...resolverOptions } = resolverConfig.get();
    return resolver(
      Object.keys(resolverOptions).length > 0 ? resolverOptions : void 0
    );
  }) ?? [];
  if (resolvers.length === 0) {
    return void 0;
  }
  return async (profile, context) => {
    for (const resolver of resolvers) {
      try {
        return await resolver(profile, context);
      } catch (error) {
        if (error?.name === "NotFoundError") {
          continue;
        }
        throw error;
      }
    }
    throw new Error(
      "Failed to sign-in, unable to resolve user identity. Please verify that your catalog contains the expected User entities that would match your configured sign-in resolver."
    );
  };
}

exports.readDeclarativeSignInResolver = readDeclarativeSignInResolver;
//# sourceMappingURL=readDeclarativeSignInResolver.cjs.js.map
