@visma-swno/customer-onboarding-wizard 1.0.16 → 1.0.18
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/README.md +7 -4
- package/dist/core/http.service.d.ts +18 -0
- package/dist/core/i18n.service.d.ts +34 -0
- package/dist/index.js +680 -457
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -191,16 +191,19 @@ document.addEventListener('http-error', async (event) => {
|
|
|
191
191
|
**Detail**:
|
|
192
192
|
```typescript
|
|
193
193
|
{
|
|
194
|
-
status: number;
|
|
195
|
-
errorKey: string;
|
|
196
|
-
endpoint: string;
|
|
197
|
-
method: string;
|
|
194
|
+
status: number; // HTTP status code or 0 for network errors
|
|
195
|
+
errorKey: string; // Translation key (e.g., 'serverError', 'validationError')
|
|
196
|
+
endpoint: string; // Failed endpoint
|
|
197
|
+
method: string; // HTTP method
|
|
198
|
+
code?: string; // Structured backend error code, when present
|
|
199
|
+
messageParameters?: string[]; // Ordered values for the code's translated template
|
|
198
200
|
}
|
|
199
201
|
```
|
|
200
202
|
|
|
201
203
|
**Handled Automatically**: Host application does not need to listen to this event. The component:
|
|
202
204
|
- Displays a red error banner at the top of the wizard
|
|
203
205
|
- Automatically translates error title and message to the user's selected language
|
|
206
|
+
- When the response carries a structured `{ code, messageParameters }` body, composes the message from the **translated** template for that `code` (ignoring the backend's untranslated `message`); `SCREAMING_SNAKE_CASE` parameters like `CONSULTANT` are themselves translated, ids/names are inserted verbatim. Unmapped codes fall back to the status-based message.
|
|
204
207
|
- Supports 6 translation sets: da-DK, en-US, fi-FI, nb-NO, nl-NL, sv-SE (`en-GB` is accepted and served using `en-US` translations)
|
|
205
208
|
- Banner remains visible until the user manually dismisses it by clicking the X button
|
|
206
209
|
- Allows users to report errors to support
|
|
@@ -123,6 +123,17 @@ export interface ErrorMessageDetail {
|
|
|
123
123
|
errorKey: 'invalidRequest' | 'validationError' | 'notFound' | 'serverError' | 'requestTimeout' | 'networkError' | 'requestFailed';
|
|
124
124
|
endpoint: string;
|
|
125
125
|
method: string;
|
|
126
|
+
/**
|
|
127
|
+
* Backend error code from a structured error body (e.g. 'ROLE_ALREADY_ASSIGNED_FOR_CUSTOMER').
|
|
128
|
+
* When present, the component composes a translated message from this code + `messageParameters`
|
|
129
|
+
* instead of using the status-based `errorKey`. Absent when the response had no structured body.
|
|
130
|
+
*/
|
|
131
|
+
code?: string;
|
|
132
|
+
/**
|
|
133
|
+
* Ordered substitution values for the structured error's translated template.
|
|
134
|
+
* Only meaningful together with `code`.
|
|
135
|
+
*/
|
|
136
|
+
messageParameters?: string[];
|
|
126
137
|
}
|
|
127
138
|
export declare class HttpService {
|
|
128
139
|
private baseUrl;
|
|
@@ -160,6 +171,13 @@ export declare class HttpService {
|
|
|
160
171
|
*/
|
|
161
172
|
private emitErrorMessage;
|
|
162
173
|
request<T>(endpoint: string, config?: RequestConfig): Promise<T>;
|
|
174
|
+
/**
|
|
175
|
+
* Parse a structured error body of the shape `{ code, messageParameters }`.
|
|
176
|
+
* Returns null when the body is missing, not JSON, or has no string `code`, so the caller
|
|
177
|
+
* falls back to the status-based error key. The response body is otherwise unused on the
|
|
178
|
+
* error path, so consuming it here is safe.
|
|
179
|
+
*/
|
|
180
|
+
private parseStructuredError;
|
|
163
181
|
/**
|
|
164
182
|
* Get error key based on status code for i18n translation
|
|
165
183
|
*/
|
|
@@ -119,6 +119,18 @@ export interface Translations {
|
|
|
119
119
|
message: string;
|
|
120
120
|
};
|
|
121
121
|
};
|
|
122
|
+
/**
|
|
123
|
+
* Structured backend errors. When a failed response carries a `{ code, messageParameters }`
|
|
124
|
+
* object, the banner message is composed from `codes[code]` (positional `{0}`, `{1}`, …
|
|
125
|
+
* placeholders) instead of the untranslated `message` from the API. Parameters that are
|
|
126
|
+
* SCREAMING_SNAKE_CASE enum values (e.g. `CONSULTANT`) are themselves translated via `params`.
|
|
127
|
+
* Only a subset of the backend's codes is mapped — unmapped codes fall back to the
|
|
128
|
+
* status-based `errors` entry. See `I18nService.composeBackendError`.
|
|
129
|
+
*/
|
|
130
|
+
backendErrors: {
|
|
131
|
+
codes: Record<string, string>;
|
|
132
|
+
params: Record<string, string>;
|
|
133
|
+
};
|
|
122
134
|
}
|
|
123
135
|
/**
|
|
124
136
|
* I18n Service Class
|
|
@@ -140,6 +152,28 @@ export declare class I18nService {
|
|
|
140
152
|
* Get translations for the current locale
|
|
141
153
|
*/
|
|
142
154
|
getTranslations(): Translations;
|
|
155
|
+
/**
|
|
156
|
+
* Compose a translated message for a structured backend error.
|
|
157
|
+
*
|
|
158
|
+
* Looks up the template for `code` in the current locale's `backendErrors.codes` and fills its
|
|
159
|
+
* positional placeholders (`{0}`, `{1}`, …) from `messageParameters`. Parameters that are
|
|
160
|
+
* SCREAMING_SNAKE_CASE enum values (matching `/^[A-Z][A-Z0-9_]*$/`, e.g. `CONSULTANT`) are
|
|
161
|
+
* themselves translated via `backendErrors.params`, falling back to a humanized form when the
|
|
162
|
+
* value is not yet mapped. All other parameters (ids, names, numbers) are inserted verbatim.
|
|
163
|
+
*
|
|
164
|
+
* Returns `null` when `code` is unmapped, or when the template has a positional placeholder with
|
|
165
|
+
* no matching parameter, so the caller can fall back to the status-based error instead of showing
|
|
166
|
+
* a message with a raw `{n}` token.
|
|
167
|
+
*
|
|
168
|
+
* @param code - Backend error code (e.g. 'ROLE_ALREADY_ASSIGNED_FOR_CUSTOMER')
|
|
169
|
+
* @param messageParameters - Ordered substitution values from the API response
|
|
170
|
+
*/
|
|
171
|
+
composeBackendError(code: string, messageParameters?: string[]): string | null;
|
|
172
|
+
/**
|
|
173
|
+
* Translate a single backend-error parameter. SCREAMING_SNAKE_CASE values are treated as
|
|
174
|
+
* translatable enum tokens; everything else is returned unchanged.
|
|
175
|
+
*/
|
|
176
|
+
private resolveBackendErrorParam;
|
|
143
177
|
/**
|
|
144
178
|
* Get a translation by key path
|
|
145
179
|
*/
|