@arsedizioni/ars-utils 22.0.84 → 22.0.85

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arsedizioni/ars-utils",
3
- "version": "22.0.84",
3
+ "version": "22.0.85",
4
4
  "author": {
5
5
  "email": "software@arsedizioni.it",
6
6
  "name": "Fabio Buscaroli, Alberto Doria"
@@ -1,11 +1,12 @@
1
1
  import * as i0 from '@angular/core';
2
- import { EnvironmentProviders, PipeTransform, EventEmitter, OnDestroy, Signal } from '@angular/core';
2
+ import { EnvironmentProviders, InjectionToken, PipeTransform, EventEmitter, OnDestroy, Signal } from '@angular/core';
3
3
  import { DateAdapter, MatDateFormats } from '@angular/material/core';
4
4
  import { Locale } from 'date-fns';
5
+ import { HttpInterceptor, HttpRequest, HttpHandler, HttpEvent, HttpInterceptorFn } from '@angular/common/http';
6
+ import { Observable } from 'rxjs';
5
7
  import { Validator, AbstractControl, ValidationErrors } from '@angular/forms';
6
8
  import { SafeHtml, SafeResourceUrl } from '@angular/platform-browser';
7
9
  import { SelectionModel } from '@angular/cdk/collections';
8
- import { Observable } from 'rxjs';
9
10
 
10
11
  declare const MAT_DATE_FNS_FORMATS: MatDateFormats;
11
12
  /**
@@ -192,16 +193,6 @@ declare class DateFnsAdapter extends DateAdapter<Date, Locale> {
192
193
  static ɵfac: i0.ɵɵFactoryDeclaration<DateFnsAdapter, never>;
193
194
  static ɵprov: i0.ɵɵInjectableDeclaration<DateFnsAdapter>;
194
195
  }
195
- /** Opzioni di configurazione del supporto date ARS. */
196
- interface ArsDateFnsOptions {
197
- /** Timezone IANA usato da adapter e serializzazione (default: `Europe/Rome`). */
198
- timeZone?: string;
199
- /**
200
- * Registra l'interceptor che serializza le Date come wall-clock locale.
201
- * Richiede `withInterceptorsFromDi()` in `provideHttpClient()`. Default: `true`.
202
- */
203
- httpSerialization?: boolean;
204
- }
205
196
  /**
206
197
  * Standalone providers for the ARS date-fns adapter.
207
198
  *
@@ -214,7 +205,104 @@ interface ArsDateFnsOptions {
214
205
  * providers: [provideArsDateFns()]
215
206
  * });
216
207
  */
217
- declare function provideArsDateFns(options?: ArsDateFnsOptions): EnvironmentProviders;
208
+ declare function provideArsDateFns(): EnvironmentProviders;
209
+
210
+ /** Default application timezone: all dates are serialised as Europe/Rome wall-clock values. */
211
+ declare const DEFAULT_TIME_ZONE = "Europe/Rome";
212
+ /**
213
+ * IANA timezone used to serialise dates towards the backend.
214
+ * Override it in the application providers to run the same code in another zone:
215
+ * `{ provide: ARS_TIME_ZONE, useValue: 'Europe/Zurich' }`.
216
+ */
217
+ declare const ARS_TIME_ZONE: InjectionToken<string>;
218
+ /**
219
+ * Functional interceptor that serialises every `Date` in an outgoing request
220
+ * body as a naive local datetime string (`yyyy-MM-ddTHH:mm:ss`: no `Z`, no offset).
221
+ *
222
+ * WHY: `JSON.stringify` calls `Date.prototype.toJSON`, which emits a UTC instant.
223
+ * A date picked as 29/07/2026 00:00 in Rome (UTC+2) becomes
224
+ * `2026-07-28T22:00:00.000Z`, so the server stores the 28th — the classic
225
+ * "off by one day" bug. Sending the wall-clock value instead makes
226
+ * System.Text.Json produce a `DateTime` with `Kind = Unspecified` and the exact
227
+ * day/time the user selected.
228
+ *
229
+ * This is the single serialisation boundary of the application: no call site has
230
+ * to convert anything, and it also covers dates that lost a per-instance
231
+ * `toJSON` along the way (e.g. after `structuredClone`).
232
+ *
233
+ * Register it explicitly in `provideHttpClient(withInterceptors([...]))`.
234
+ * If you would rather have the library register it for you, use
235
+ * {@link provideArsLocalDates} instead.
236
+ *
237
+ * @example
238
+ * provideHttpClient(withInterceptors([
239
+ * arsLocalDateInterceptor,
240
+ * evolutionAuthInterceptor(...),
241
+ * ]));
242
+ */
243
+ declare const arsLocalDateInterceptor: HttpInterceptorFn;
244
+ /**
245
+ * Class-based twin of {@link arsLocalDateInterceptor}.
246
+ *
247
+ * Exists because a functional `HttpInterceptorFn` can ONLY be registered inside
248
+ * `provideHttpClient(withInterceptors([...]))`, while a class registered on the
249
+ * `HTTP_INTERCEPTORS` multi-token can be contributed by any `EnvironmentProviders` —
250
+ * which is what lets {@link provideArsLocalDates} (and `provideArsDateFns`) wire it up
251
+ * on their own.
252
+ *
253
+ * REQUIRES `withInterceptorsFromDi()` in the application's `provideHttpClient()`:
254
+ * without it Angular never reads `HTTP_INTERCEPTORS` and this interceptor is
255
+ * silently skipped.
256
+ */
257
+ declare class ArsLocalDateInterceptor implements HttpInterceptor {
258
+ private readonly timeZone;
259
+ /**
260
+ * Normalises the request body before handing it to the next handler.
261
+ * @param req - The outgoing request.
262
+ * @param next - The next handler in the chain.
263
+ */
264
+ intercept(req: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>>;
265
+ static ɵfac: i0.ɵɵFactoryDeclaration<ArsLocalDateInterceptor, never>;
266
+ static ɵprov: i0.ɵɵInjectableDeclaration<ArsLocalDateInterceptor>;
267
+ }
268
+ /**
269
+ * Standalone providers for date serialisation towards the backend.
270
+ *
271
+ * Registers {@link ArsLocalDateInterceptor} so that every `Date` in a request
272
+ * body travels as a naive local datetime string instead of a UTC instant.
273
+ *
274
+ * IMPORTANT: the application MUST call `withInterceptorsFromDi()`, otherwise
275
+ * these providers have no effect at all (no error is raised).
276
+ *
277
+ * @param timeZone - IANA timezone name (default: `Europe/Rome`).
278
+ *
279
+ * @example
280
+ * providers: [
281
+ * provideArsLocalDates(),
282
+ * provideHttpClient(withInterceptors([evolutionAuthInterceptor(...)]), withInterceptorsFromDi()),
283
+ * ]
284
+ */
285
+ declare function provideArsLocalDates(timeZone?: string): EnvironmentProviders;
286
+ /**
287
+ * Formats a date as a date-only ISO string (`yyyy-MM-dd`) using its wall-clock
288
+ * calendar day in the given timezone. Use it for query-string parameters and for
289
+ * DTO fields mapped to a .NET `DateOnly`, which the interceptor cannot detect.
290
+ *
291
+ * @param value - The date to serialise.
292
+ * @param timeZone - IANA timezone name (default: `Europe/Rome`).
293
+ * @returns The `yyyy-MM-dd` string, or `undefined` for empty/invalid input.
294
+ */
295
+ declare function toLocalDateOnlyString(value?: Date | null, timeZone?: string): string | undefined;
296
+ /**
297
+ * Formats a date as a naive local datetime string (`yyyy-MM-ddTHH:mm:ss`), the
298
+ * same representation produced by the interceptor. Useful for query-string
299
+ * parameters, which never pass through the request body.
300
+ *
301
+ * @param value - The date to serialise.
302
+ * @param timeZone - IANA timezone name (default: `Europe/Rome`).
303
+ * @returns The naive datetime string, or `undefined` for empty/invalid input.
304
+ */
305
+ declare function toLocalDateTimeString(value?: Date | null, timeZone?: string): string | undefined;
218
306
 
219
307
  /**
220
308
  * Directive that moves browser focus to the host element after the first render cycle.
@@ -1784,5 +1872,5 @@ declare class ThemeService implements OnDestroy {
1784
1872
  static ɵprov: i0.ɵɵInjectableDeclaration<ThemeService>;
1785
1873
  }
1786
1874
 
1787
- export { AutoFocusDirective, BroadcastChannelManager, BroadcastService, CHANNEL_NAME, CopyClipboardDirective, DateFnsAdapter, DateFormat, DateInterval, DateIntervalChangeDirective, DeleteModel, EmailsValidatorDirective, EnvironmentService, EqualsValidatorDirective, FileInfo, FileSizeValidatorDirective, FormatHtmlPipe, FormatMarkdownPipe, FormatPipe, GroupModel, GuidValidatorDirective, IDModel, ImportModel, MAT_DATE_FNS_FORMATS, MaxTermsValidatorDirective, NotEmptyValidatorDirective, NotEqualValidatorDirective, NotFutureValidatorDirective, PasswordValidatorDirective, QueryModel, RelationModel, RemoveFocusDirective, ReplacePipe, SafeHtmlPipe, SafeUrlPipe, ScreenService, SearchCallbackPipe, SearchFilterPipe, SelectableModel, SplashService, SqlDateValidatorDirective, SystemUtils, ThemeService, TimeValidatorDirective, UpdateRelationsModel, UrlValidatorDirective, UtilsMessages, ValidIfDirective, ValidatorDirective, ValueModel, provideArsDateFns };
1788
- export type { AddModel, AddResultModel, ApiResponse, ApiResult, ArsDateFnsOptions, BroadcastChannelMessageBag, BroadcastChannelSubscriberInfo, BroadcastMessageInfo, BroadcastMessageToastData, Checkable, DeleteResultModel, DoneResult, EnableDisableModel, ErrorInfo, File, Folder, FolderTree, INode, KeyOf, LoginResult, NameValueItem, PasswordStrength, QueryResultModel, SearchBag, SearchFilterMetadata, Searchable, SendToModel, ThemeType, UpdateModel, UpdateResultModel, Validated };
1875
+ export { ARS_TIME_ZONE, ArsLocalDateInterceptor, AutoFocusDirective, BroadcastChannelManager, BroadcastService, CHANNEL_NAME, CopyClipboardDirective, DEFAULT_TIME_ZONE, DateFnsAdapter, DateFormat, DateInterval, DateIntervalChangeDirective, DeleteModel, EmailsValidatorDirective, EnvironmentService, EqualsValidatorDirective, FileInfo, FileSizeValidatorDirective, FormatHtmlPipe, FormatMarkdownPipe, FormatPipe, GroupModel, GuidValidatorDirective, IDModel, ImportModel, MAT_DATE_FNS_FORMATS, MaxTermsValidatorDirective, NotEmptyValidatorDirective, NotEqualValidatorDirective, NotFutureValidatorDirective, PasswordValidatorDirective, QueryModel, RelationModel, RemoveFocusDirective, ReplacePipe, SafeHtmlPipe, SafeUrlPipe, ScreenService, SearchCallbackPipe, SearchFilterPipe, SelectableModel, SplashService, SqlDateValidatorDirective, SystemUtils, ThemeService, TimeValidatorDirective, UpdateRelationsModel, UrlValidatorDirective, UtilsMessages, ValidIfDirective, ValidatorDirective, ValueModel, arsLocalDateInterceptor, provideArsDateFns, provideArsLocalDates, toLocalDateOnlyString, toLocalDateTimeString };
1876
+ export type { AddModel, AddResultModel, ApiResponse, ApiResult, BroadcastChannelMessageBag, BroadcastChannelSubscriberInfo, BroadcastMessageInfo, BroadcastMessageToastData, Checkable, DeleteResultModel, DoneResult, EnableDisableModel, ErrorInfo, File, Folder, FolderTree, INode, KeyOf, LoginResult, NameValueItem, PasswordStrength, QueryResultModel, SearchBag, SearchFilterMetadata, Searchable, SendToModel, ThemeType, UpdateModel, UpdateResultModel, Validated };