@hirefinn/sdk 0.3.0 → 0.5.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.
@@ -84,6 +84,7 @@ export class FinnError extends FinnSdkError {
84
84
  requestId: str(request_id) ?? headerRequestId,
85
85
  actionUrl: str(action_url),
86
86
  requiredScope: str(required_scope),
87
+ fields: legacyFields(rest.fields, error, str(message)),
87
88
  details: rest,
88
89
  });
89
90
  }
@@ -150,6 +151,16 @@ function isRecord(v) {
150
151
  function str(v) {
151
152
  return typeof v === 'string' && v !== '' ? v : null;
152
153
  }
154
+ // Legacy bodies list the offending fields by name (`fields: ['dob']`) or as field errors; both become FinnFieldError.
155
+ function legacyFields(v, code, message) {
156
+ if (!Array.isArray(v))
157
+ return [];
158
+ return v.flatMap((f) => {
159
+ if (typeof f === 'string')
160
+ return [{ field: f, code, message: message ?? code }];
161
+ return isFieldError(f) ? [f] : [];
162
+ });
163
+ }
153
164
  function isFieldError(v) {
154
165
  return isRecord(v) && typeof v.field === 'string';
155
166
  }