@dynamic-entity/server 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/express.js CHANGED
@@ -932,6 +932,9 @@ function checkLookups(entity, config, lookups) {
932
932
  Pass them as \`lookups\` to createImportRouter. Without them those columns would store the raw cell text, which renders correctly and matches nothing.`
933
933
  );
934
934
  }
935
+ function ownValue(map, key) {
936
+ return Object.hasOwn(map, key) ? map[key] : void 0;
937
+ }
935
938
  function readFormat(value) {
936
939
  if (value === void 0 || value === "csv") return "csv";
937
940
  if (value === "xlsx") return "xlsx";
@@ -982,7 +985,7 @@ function createImportRouter(options) {
982
985
  const languageOf = (request) => typeof options.lang === "function" ? options.lang(request) : options.lang ?? "en";
983
986
  const configFor = async (request) => {
984
987
  const entity = String(request.params["entity"] ?? "");
985
- const config = typeof options.configs === "function" ? await options.configs(entity, request) : options.configs[entity];
988
+ const config = typeof options.configs === "function" ? await options.configs(entity, request) : ownValue(options.configs, entity);
986
989
  if (!config) throw new ImportError("UNKNOWN_ENTITY", "No import is configured for that entity.");
987
990
  if (typeof options.configs === "function") checkLookups(entity, config, options.lookups);
988
991
  return { entity, config };
@@ -1072,7 +1075,7 @@ function createImportRouter(options) {
1072
1075
  filename: upload.filename,
1073
1076
  plan,
1074
1077
  config,
1075
- rules: routerOptions.rules?.[entity],
1078
+ rules: routerOptions.rules && ownValue(routerOptions.rules, entity),
1076
1079
  lookups: routerOptions.lookups,
1077
1080
  lang: language(request),
1078
1081
  limits: resolved,