@factor_ec/utils 5.0.8 → 6.0.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/README.md +1 -1
- package/fesm2022/factor_ec-utils.mjs +1089 -457
- package/fesm2022/factor_ec-utils.mjs.map +1 -1
- package/package.json +5 -12
- package/types/factor_ec-utils.d.ts +894 -0
- package/index.d.ts +0 -5
- package/lib/array.service.d.ts +0 -6
- package/lib/color.service.d.ts +0 -58
- package/lib/csv.service.d.ts +0 -88
- package/lib/date.service.d.ts +0 -6
- package/lib/file-picker.service.d.ts +0 -10
- package/lib/files.service.d.ts +0 -14
- package/lib/google-tag-manager.service.d.ts +0 -18
- package/lib/graphql.service.d.ts +0 -12
- package/lib/models/auth-token-payload.d.ts +0 -6
- package/lib/models/auth-token.d.ts +0 -4
- package/lib/models/currency.d.ts +0 -6
- package/lib/models/error.d.ts +0 -6
- package/lib/models/language.d.ts +0 -4
- package/lib/models/login.d.ts +0 -4
- package/lib/models/operation.d.ts +0 -4
- package/lib/models/option.d.ts +0 -5
- package/lib/models/user.d.ts +0 -5
- package/lib/object.service.d.ts +0 -7
- package/lib/storage.service.d.ts +0 -12
- package/lib/string.service.d.ts +0 -19
- package/lib/validators/ec/identification-type.d.ts +0 -1
- package/lib/validators/ec/identification-validator.d.ts +0 -2
- package/public-api.d.ts +0 -22
|
@@ -0,0 +1,894 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { Signal, InjectionToken } from '@angular/core';
|
|
3
|
+
import { Router, CanActivateFn } from '@angular/router';
|
|
4
|
+
import { ValidatorFn } from '@angular/forms';
|
|
5
|
+
import { HttpRequest, HttpErrorResponse, HttpHandlerFn, HttpInterceptorFn } from '@angular/common/http';
|
|
6
|
+
import { Observable } from 'rxjs';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Utility service for array operations.
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* Provides helper methods for common array manipulation tasks.
|
|
13
|
+
*/
|
|
14
|
+
declare class ArrayUtil {
|
|
15
|
+
/**
|
|
16
|
+
* Merges multiple arrays into a single array, combining objects with the same property value.
|
|
17
|
+
*
|
|
18
|
+
* @param arrays - Array of arrays to merge
|
|
19
|
+
* @param prop - Property name to use as the key for merging objects
|
|
20
|
+
* @returns Merged array with combined objects
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const arr1 = [{ id: 1, name: 'John' }];
|
|
25
|
+
* const arr2 = [{ id: 1, age: 30 }];
|
|
26
|
+
* const result = arrayUtil.merge([arr1, arr2], 'id');
|
|
27
|
+
* // Returns: [{ id: 1, name: 'John', age: 30 }]
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
merge(arrays: any[], prop: string): any[];
|
|
31
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<ArrayUtil, never>;
|
|
32
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<ArrayUtil>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Utility service for color operations and hash-based color generation.
|
|
37
|
+
*
|
|
38
|
+
* @remarks
|
|
39
|
+
* Provides methods to generate consistent colors from strings using hash algorithms,
|
|
40
|
+
* and convert between different color formats (HSL, RGB, HEX).
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const colorUtil = inject(ColorUtil);
|
|
45
|
+
* const hexColor = colorUtil.hex('username');
|
|
46
|
+
* // Returns: '#a1b2c3' (consistent color for the same string)
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
declare class ColorUtil {
|
|
50
|
+
private readonly L;
|
|
51
|
+
private readonly S;
|
|
52
|
+
private readonly hueRanges;
|
|
53
|
+
constructor();
|
|
54
|
+
/**
|
|
55
|
+
* Generates a hash value from a string using BKDR hash algorithm (modified version).
|
|
56
|
+
*
|
|
57
|
+
* @param str - The string to hash
|
|
58
|
+
* @returns A numeric hash value
|
|
59
|
+
*
|
|
60
|
+
* @remarks
|
|
61
|
+
* This is a modified BKDR hash algorithm optimized for short strings.
|
|
62
|
+
*/
|
|
63
|
+
hash(str: string): number;
|
|
64
|
+
/**
|
|
65
|
+
* Converts an RGB array to a hexadecimal color string.
|
|
66
|
+
*
|
|
67
|
+
* @param RGBArray - Array with [R, G, B] values (0-255)
|
|
68
|
+
* @returns Hexadecimal color string starting with # (e.g., '#a1b2c3')
|
|
69
|
+
*/
|
|
70
|
+
rgb2hex(RGBArray: number[]): string;
|
|
71
|
+
/**
|
|
72
|
+
* Converts HSL color values to RGB array.
|
|
73
|
+
*
|
|
74
|
+
* @param H - Hue value in range [0, 360)
|
|
75
|
+
* @param S - Saturation value in range [0, 1]
|
|
76
|
+
* @param L - Lightness value in range [0, 1]
|
|
77
|
+
* @returns Array with [R, G, B] values in range [0, 255]
|
|
78
|
+
*
|
|
79
|
+
* @see {@link http://zh.wikipedia.org/wiki/HSL和HSV色彩空间} for further information.
|
|
80
|
+
*/
|
|
81
|
+
hsl2rgb(H: number, S: number, L: number): number[];
|
|
82
|
+
/**
|
|
83
|
+
* Generates HSL color values from a string hash.
|
|
84
|
+
*
|
|
85
|
+
* @param str - The string to generate color from
|
|
86
|
+
* @returns Array with [H, S, L] values where H ∈ [0, 360), S ∈ [0, 1], L ∈ [0, 1]
|
|
87
|
+
*/
|
|
88
|
+
hsl(str: string): number[];
|
|
89
|
+
/**
|
|
90
|
+
* Generates RGB color values from a string hash.
|
|
91
|
+
*
|
|
92
|
+
* @param str - The string to generate color from
|
|
93
|
+
* @returns Array with [R, G, B] values in range [0, 255]
|
|
94
|
+
*/
|
|
95
|
+
rgb(str: string): number[];
|
|
96
|
+
/**
|
|
97
|
+
* Generates a hexadecimal color string from a string hash.
|
|
98
|
+
*
|
|
99
|
+
* @param str - The string to generate color from
|
|
100
|
+
* @returns Hexadecimal color string starting with # (e.g., '#a1b2c3')
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* const color = colorUtil.hex('username');
|
|
105
|
+
* // Returns: '#a1b2c3' (same string always returns same color)
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
hex(str: string): string;
|
|
109
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<ColorUtil, never>;
|
|
110
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<ColorUtil>;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Parsed CSV data structure.
|
|
115
|
+
*/
|
|
116
|
+
interface CsvParsed {
|
|
117
|
+
/** Array of header column names */
|
|
118
|
+
header: string[];
|
|
119
|
+
/** Two-dimensional array of content rows */
|
|
120
|
+
content: string[][];
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Configuration options for CSV export.
|
|
124
|
+
*/
|
|
125
|
+
interface CsvOptions {
|
|
126
|
+
/** Name of the exported file (without extension) */
|
|
127
|
+
filename: string;
|
|
128
|
+
/** Character used to separate fields (default: ',') */
|
|
129
|
+
fieldSeparator: string;
|
|
130
|
+
/** Character used to quote strings (default: '"') */
|
|
131
|
+
quoteStrings: string;
|
|
132
|
+
/** Decimal separator for numbers (default: '.' or 'locale') */
|
|
133
|
+
decimalSeparator: string;
|
|
134
|
+
/** Whether to show column headers */
|
|
135
|
+
showLabels: boolean;
|
|
136
|
+
/** Whether to show a title row */
|
|
137
|
+
showTitle: boolean;
|
|
138
|
+
/** Title text to display if showTitle is true */
|
|
139
|
+
title: string;
|
|
140
|
+
/** Whether to export as .txt instead of .csv */
|
|
141
|
+
useTextFile: boolean;
|
|
142
|
+
/** Whether to include BOM (Byte Order Mark) for UTF-8 */
|
|
143
|
+
useBom: boolean;
|
|
144
|
+
/** Custom header names (if not using keys as headers) */
|
|
145
|
+
headers: string[];
|
|
146
|
+
/** Whether to use object keys as header names */
|
|
147
|
+
useKeysAsHeaders: boolean;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Service for exporting data to CSV format and parsing CSV content.
|
|
152
|
+
*
|
|
153
|
+
* @remarks
|
|
154
|
+
* Provides functionality to generate CSV files from JSON data with customizable options,
|
|
155
|
+
* and to parse CSV content back into structured data.
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```typescript
|
|
159
|
+
* const csvExporter = inject(CsvExporter);
|
|
160
|
+
* csvExporter.options = { filename: 'export', showLabels: true };
|
|
161
|
+
* csvExporter.generate([{ name: 'John', age: 30 }]);
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
declare class CsvExporter {
|
|
165
|
+
private _data;
|
|
166
|
+
private _options;
|
|
167
|
+
private _csv;
|
|
168
|
+
private readonly configDefaults;
|
|
169
|
+
get options(): CsvOptions;
|
|
170
|
+
set options(options: Partial<CsvOptions>);
|
|
171
|
+
constructor();
|
|
172
|
+
/**
|
|
173
|
+
* Generates a CSV file from JSON data and optionally downloads it.
|
|
174
|
+
*
|
|
175
|
+
* @param jsonData - The data to export (array of objects or JSON string)
|
|
176
|
+
* @param shouldReturnCsv - If true, returns the CSV string instead of downloading
|
|
177
|
+
* @returns The CSV string if shouldReturnCsv is true, otherwise void
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```typescript
|
|
181
|
+
* // Download CSV
|
|
182
|
+
* csvExporter.generate([{ name: 'John', age: 30 }]);
|
|
183
|
+
*
|
|
184
|
+
* // Get CSV string
|
|
185
|
+
* const csvString = csvExporter.generate([{ name: 'John' }], true);
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
generate(jsonData: any, shouldReturnCsv?: boolean): void | any;
|
|
189
|
+
/**
|
|
190
|
+
* Creates CSV headers row based on configuration.
|
|
191
|
+
*
|
|
192
|
+
* @private
|
|
193
|
+
*/
|
|
194
|
+
private _getHeaders;
|
|
195
|
+
/**
|
|
196
|
+
* Creates CSV body rows from the data.
|
|
197
|
+
*
|
|
198
|
+
* @private
|
|
199
|
+
*/
|
|
200
|
+
private _getBody;
|
|
201
|
+
/**
|
|
202
|
+
* Formats data for CSV output according to configuration.
|
|
203
|
+
*
|
|
204
|
+
* @param data - The data value to format
|
|
205
|
+
* @returns The formatted data as a string
|
|
206
|
+
* @private
|
|
207
|
+
*/
|
|
208
|
+
private _formatData;
|
|
209
|
+
/**
|
|
210
|
+
* Checks if a value is a floating point number.
|
|
211
|
+
*
|
|
212
|
+
* @param input - The value to check
|
|
213
|
+
* @returns True if the value is a float, false otherwise
|
|
214
|
+
* @private
|
|
215
|
+
*/
|
|
216
|
+
private _isFloat;
|
|
217
|
+
/**
|
|
218
|
+
* Parses JSON data into an array format.
|
|
219
|
+
*
|
|
220
|
+
* @param jsonData - The JSON data to parse (object, array, or JSON string)
|
|
221
|
+
* @returns Parsed array of data
|
|
222
|
+
* @private
|
|
223
|
+
*/
|
|
224
|
+
private _parseData;
|
|
225
|
+
/**
|
|
226
|
+
* Converts a value to an object, throwing an error for null or undefined.
|
|
227
|
+
*
|
|
228
|
+
* @param val - The value to convert
|
|
229
|
+
* @returns The value as an object
|
|
230
|
+
* @throws {TypeError} If val is null or undefined
|
|
231
|
+
*/
|
|
232
|
+
toObject(val: any): any;
|
|
233
|
+
/**
|
|
234
|
+
* Assigns properties from source objects to a target object (similar to Object.assign).
|
|
235
|
+
*
|
|
236
|
+
* @param target - The target object to assign properties to
|
|
237
|
+
* @param source - One or more source objects to copy properties from
|
|
238
|
+
* @returns The target object with assigned properties
|
|
239
|
+
*/
|
|
240
|
+
objectAssign(target: any, ...source: any[]): any;
|
|
241
|
+
/**
|
|
242
|
+
* Parses CSV content into a structured format with headers and content rows.
|
|
243
|
+
*
|
|
244
|
+
* @param csvContent - The CSV string to parse
|
|
245
|
+
* @returns An object containing the header array and content rows array
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
* ```typescript
|
|
249
|
+
* const parsed = csvExporter.read('name,age\nJohn,30\nJane,25');
|
|
250
|
+
* // Returns: { header: ['name', 'age'], content: [['John', '30'], ['Jane', '25']] }
|
|
251
|
+
* ```
|
|
252
|
+
*/
|
|
253
|
+
read(csvContent: string): CsvParsed;
|
|
254
|
+
/**
|
|
255
|
+
* Parses a single CSV line into an array of values.
|
|
256
|
+
*
|
|
257
|
+
* @param csvLine - A single line of CSV content
|
|
258
|
+
* @returns Array of parsed values from the line
|
|
259
|
+
*
|
|
260
|
+
* @remarks
|
|
261
|
+
* Handles quoted values and different quote styles (single and double quotes).
|
|
262
|
+
*/
|
|
263
|
+
parseLine(csvLine: string): string[];
|
|
264
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<CsvExporter, never>;
|
|
265
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<CsvExporter>;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Utility service for date operations.
|
|
270
|
+
*
|
|
271
|
+
* @remarks
|
|
272
|
+
* Provides helper methods for date parsing and manipulation.
|
|
273
|
+
*/
|
|
274
|
+
declare class DateUtil {
|
|
275
|
+
/**
|
|
276
|
+
* Parses a date string in ISO format (YYYY-MM-DD or YYYY-MM-DDTHH:mm:ss) and returns a Date object.
|
|
277
|
+
*
|
|
278
|
+
* @param date - The date string to parse (ISO format)
|
|
279
|
+
* @returns A Date object representing the parsed date
|
|
280
|
+
*
|
|
281
|
+
* @example
|
|
282
|
+
* ```typescript
|
|
283
|
+
* const date = dateUtil.getDate('2025-01-15');
|
|
284
|
+
* // Returns: Date object for January 15, 2025
|
|
285
|
+
* ```
|
|
286
|
+
*/
|
|
287
|
+
getDate(date: string): Date;
|
|
288
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<DateUtil, never>;
|
|
289
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<DateUtil>;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Service for opening file picker dialogs and reading file contents.
|
|
294
|
+
*
|
|
295
|
+
* @remarks
|
|
296
|
+
* Provides a programmatic way to open file selection dialogs and read file data as base64.
|
|
297
|
+
*/
|
|
298
|
+
declare class FilePicker {
|
|
299
|
+
/**
|
|
300
|
+
* Opens a file picker dialog and returns the selected files with their data as base64.
|
|
301
|
+
*
|
|
302
|
+
* @param options - Optional configuration for the file picker
|
|
303
|
+
* @param options.accept - File types to accept (e.g., 'image/*', '.pdf')
|
|
304
|
+
* @param options.multiple - Whether to allow multiple file selection
|
|
305
|
+
* @returns Promise that resolves to an array of files with data property, or null if cancelled
|
|
306
|
+
*
|
|
307
|
+
* @example
|
|
308
|
+
* ```typescript
|
|
309
|
+
* const files = await filePicker.open({ accept: 'image/*', multiple: true });
|
|
310
|
+
* if (files) {
|
|
311
|
+
* files.forEach(file => console.log(file.data)); // base64 data
|
|
312
|
+
* }
|
|
313
|
+
* ```
|
|
314
|
+
*/
|
|
315
|
+
open(options?: {
|
|
316
|
+
accept?: string;
|
|
317
|
+
multiple?: boolean;
|
|
318
|
+
}): Promise<any[] | null>;
|
|
319
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<FilePicker, never>;
|
|
320
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<FilePicker>;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Utility service for object operations.
|
|
325
|
+
*
|
|
326
|
+
* @remarks
|
|
327
|
+
* Provides helper methods for object manipulation and transformation.
|
|
328
|
+
*/
|
|
329
|
+
declare class ObjectUtil {
|
|
330
|
+
/**
|
|
331
|
+
* Filters out null, undefined, and 'undefined' string properties from an object.
|
|
332
|
+
*
|
|
333
|
+
* @param obj - The object to filter
|
|
334
|
+
* @returns A new object with null/undefined properties removed
|
|
335
|
+
*
|
|
336
|
+
* @example
|
|
337
|
+
* ```typescript
|
|
338
|
+
* const filtered = objectUtil.filterNullProperties({ a: 1, b: null, c: undefined });
|
|
339
|
+
* // Returns: { a: 1 }
|
|
340
|
+
* ```
|
|
341
|
+
*/
|
|
342
|
+
filterNullProperties(obj: any): any;
|
|
343
|
+
/**
|
|
344
|
+
* Performs a deep merge of two objects, combining nested properties.
|
|
345
|
+
*
|
|
346
|
+
* @param target - The target object to merge into
|
|
347
|
+
* @param source - The source object to merge from
|
|
348
|
+
* @returns A new object with deeply merged properties
|
|
349
|
+
*
|
|
350
|
+
* @remarks
|
|
351
|
+
* Uses structuredClone to avoid mutating the original objects.
|
|
352
|
+
*
|
|
353
|
+
* @example
|
|
354
|
+
* ```typescript
|
|
355
|
+
* const merged = objectUtil.deepMerge({ a: { b: 1 } }, { a: { c: 2 } });
|
|
356
|
+
* // Returns: { a: { b: 1, c: 2 } }
|
|
357
|
+
* ```
|
|
358
|
+
*/
|
|
359
|
+
deepMerge(target: any, source: any): any;
|
|
360
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<ObjectUtil, never>;
|
|
361
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<ObjectUtil>;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Constants for storage type options.
|
|
366
|
+
*/
|
|
367
|
+
declare const STORAGE_TYPE: {
|
|
368
|
+
/** Browser localStorage */
|
|
369
|
+
readonly LOCAL: "local";
|
|
370
|
+
/** Browser sessionStorage */
|
|
371
|
+
readonly SESSION: "session";
|
|
372
|
+
/** In-memory storage (not persisted) */
|
|
373
|
+
readonly MEMORY: "memory";
|
|
374
|
+
};
|
|
375
|
+
/**
|
|
376
|
+
* Type representing valid storage types.
|
|
377
|
+
*/
|
|
378
|
+
type StorageType = (typeof STORAGE_TYPE)[keyof typeof STORAGE_TYPE];
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Service for managing browser storage (localStorage, sessionStorage, and memory storage).
|
|
382
|
+
*
|
|
383
|
+
* @remarks
|
|
384
|
+
* Provides a unified interface for storing and retrieving data from different storage types.
|
|
385
|
+
* Automatically handles JSON serialization/deserialization and platform detection.
|
|
386
|
+
*
|
|
387
|
+
* @example
|
|
388
|
+
* ```typescript
|
|
389
|
+
* const storage = inject(Storage);
|
|
390
|
+
* storage.set('key', { data: 'value' }, 'local');
|
|
391
|
+
* const value = storage.get('key', 'local');
|
|
392
|
+
* ```
|
|
393
|
+
*/
|
|
394
|
+
declare class Storage {
|
|
395
|
+
private memoryStorage;
|
|
396
|
+
private readonly platformId;
|
|
397
|
+
private getValue;
|
|
398
|
+
/**
|
|
399
|
+
* Deletes a value from the specified storage.
|
|
400
|
+
*
|
|
401
|
+
* @param key - The key of the value to delete
|
|
402
|
+
* @param storage - The storage type ('local', 'session', or 'memory'). Defaults to 'session'
|
|
403
|
+
*/
|
|
404
|
+
delete(key: string, storage?: StorageType): void;
|
|
405
|
+
/**
|
|
406
|
+
* Retrieves a value from the specified storage.
|
|
407
|
+
*
|
|
408
|
+
* @param key - The key of the value to retrieve
|
|
409
|
+
* @param storage - The storage type ('local', 'session', or 'memory'). Defaults to 'session'
|
|
410
|
+
* @returns The parsed value (if JSON) or the raw value, or undefined if not found
|
|
411
|
+
*
|
|
412
|
+
* @remarks
|
|
413
|
+
* Automatically attempts to parse JSON values. If parsing fails, returns the raw string.
|
|
414
|
+
*/
|
|
415
|
+
get(key: string, storage?: StorageType): any;
|
|
416
|
+
/**
|
|
417
|
+
* Stores a value in the specified storage.
|
|
418
|
+
*
|
|
419
|
+
* @param key - The key to store the value under
|
|
420
|
+
* @param value - The value to store (will be JSON stringified)
|
|
421
|
+
* @param storage - The storage type ('local', 'session', or 'memory'). Defaults to 'session'
|
|
422
|
+
*
|
|
423
|
+
* @remarks
|
|
424
|
+
* Values are automatically JSON stringified before storage.
|
|
425
|
+
*/
|
|
426
|
+
set(key: string, value: any, storage?: StorageType): void;
|
|
427
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<Storage, never>;
|
|
428
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<Storage>;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Utility service for string operations.
|
|
433
|
+
*
|
|
434
|
+
* @remarks
|
|
435
|
+
* Provides helper methods for common string manipulation and formatting tasks.
|
|
436
|
+
*/
|
|
437
|
+
declare class StringUtil {
|
|
438
|
+
/**
|
|
439
|
+
* Decodes HTML entities in a string.
|
|
440
|
+
*
|
|
441
|
+
* @param text - The string containing HTML entities to decode
|
|
442
|
+
* @returns The decoded string
|
|
443
|
+
*
|
|
444
|
+
* @example
|
|
445
|
+
* ```typescript
|
|
446
|
+
* const encoded = '<div>Hello</div>';
|
|
447
|
+
* const decoded = stringUtil.decodeHTML(encoded);
|
|
448
|
+
* // Returns: '<div>Hello</div>'
|
|
449
|
+
* ```
|
|
450
|
+
*/
|
|
451
|
+
decodeHTML(text: string): string;
|
|
452
|
+
/**
|
|
453
|
+
* Normalizes a text by converting to lowercase and removing accents.
|
|
454
|
+
*
|
|
455
|
+
* @param text - The text to normalize
|
|
456
|
+
* @returns The normalized text without accents and in lowercase
|
|
457
|
+
*
|
|
458
|
+
* @example
|
|
459
|
+
* ```typescript
|
|
460
|
+
* const normalized = stringUtil.normalize('Café');
|
|
461
|
+
* // Returns: 'cafe'
|
|
462
|
+
* ```
|
|
463
|
+
*/
|
|
464
|
+
normalize(text: string): string;
|
|
465
|
+
/**
|
|
466
|
+
* Normalizes a name by trimming whitespace and capitalizing the first letter.
|
|
467
|
+
*
|
|
468
|
+
* @param text - The name text to normalize
|
|
469
|
+
* @returns The normalized name with first letter capitalized
|
|
470
|
+
*
|
|
471
|
+
* @example
|
|
472
|
+
* ```typescript
|
|
473
|
+
* const normalized = stringUtil.normalizeName(' john doe ');
|
|
474
|
+
* // Returns: 'John doe'
|
|
475
|
+
* ```
|
|
476
|
+
*/
|
|
477
|
+
normalizeName(text: string): string;
|
|
478
|
+
/**
|
|
479
|
+
* Calculates the estimated reading time in milliseconds for a given text.
|
|
480
|
+
*
|
|
481
|
+
* @param text - The text to calculate reading time for
|
|
482
|
+
* @returns The estimated reading time in milliseconds
|
|
483
|
+
*
|
|
484
|
+
* @remarks
|
|
485
|
+
* Uses a reading speed of 1200 characters per minute.
|
|
486
|
+
*
|
|
487
|
+
* @example
|
|
488
|
+
* ```typescript
|
|
489
|
+
* const readingTime = stringUtil.calculateReadingTime('Long text here...');
|
|
490
|
+
* // Returns: estimated milliseconds
|
|
491
|
+
* ```
|
|
492
|
+
*/
|
|
493
|
+
calculateReadingTime(text: string): number;
|
|
494
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<StringUtil, never>;
|
|
495
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<StringUtil>;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* Service for integrating Google Tag Manager (GTM) tracking.
|
|
500
|
+
*
|
|
501
|
+
* @remarks
|
|
502
|
+
* Handles GTM script injection, variable tracking, and automatic route change tracking.
|
|
503
|
+
*
|
|
504
|
+
* @example
|
|
505
|
+
* ```typescript
|
|
506
|
+
* const gtm = inject(GoogleTagManager);
|
|
507
|
+
* gtm.appendTrackingCode('GTM-XXXXXXX');
|
|
508
|
+
* gtm.addVariable({ event: 'customEvent', data: 'value' });
|
|
509
|
+
* ```
|
|
510
|
+
*/
|
|
511
|
+
declare class GoogleTagManager {
|
|
512
|
+
trackingId: string;
|
|
513
|
+
private readonly platformId;
|
|
514
|
+
readonly router: Router;
|
|
515
|
+
/**
|
|
516
|
+
* Appends Google Tag Manager tracking code to the page.
|
|
517
|
+
*
|
|
518
|
+
* @param trackingId - The GTM container ID (e.g., 'GTM-XXXXXXX')
|
|
519
|
+
* @param options - Optional configuration for GTM environment
|
|
520
|
+
* @param options.environment - Environment configuration for preview mode
|
|
521
|
+
* @param options.environment.auth - Authentication token for preview
|
|
522
|
+
* @param options.environment.preview - Preview container ID
|
|
523
|
+
*
|
|
524
|
+
* @remarks
|
|
525
|
+
* Automatically subscribes to router navigation events for page view tracking.
|
|
526
|
+
*/
|
|
527
|
+
appendTrackingCode(trackingId: string, options?: {
|
|
528
|
+
environment?: {
|
|
529
|
+
auth: string;
|
|
530
|
+
preview: string;
|
|
531
|
+
};
|
|
532
|
+
}): void;
|
|
533
|
+
/**
|
|
534
|
+
* Pushes a variable or event to the GTM dataLayer.
|
|
535
|
+
*
|
|
536
|
+
* @param variable - The variable or event object to push to dataLayer
|
|
537
|
+
*
|
|
538
|
+
* @example
|
|
539
|
+
* ```typescript
|
|
540
|
+
* gtm.addVariable({ event: 'purchase', value: 100 });
|
|
541
|
+
* ```
|
|
542
|
+
*/
|
|
543
|
+
addVariable(variable: any): void;
|
|
544
|
+
/**
|
|
545
|
+
* Initializes router event subscribers for automatic page view tracking.
|
|
546
|
+
*
|
|
547
|
+
* @private
|
|
548
|
+
*/
|
|
549
|
+
private initSubscribers;
|
|
550
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<GoogleTagManager, never>;
|
|
551
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<GoogleTagManager>;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* Error object structure for application error handling.
|
|
556
|
+
*/
|
|
557
|
+
interface Error {
|
|
558
|
+
/** Optional error code */
|
|
559
|
+
code?: number;
|
|
560
|
+
/** Optional icon identifier for error display */
|
|
561
|
+
icon?: string;
|
|
562
|
+
/** Optional error title */
|
|
563
|
+
title?: string;
|
|
564
|
+
/** Error message (required) */
|
|
565
|
+
message: string;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* Constants for CRUD operation types.
|
|
570
|
+
*/
|
|
571
|
+
declare const OPERATION_TYPE: {
|
|
572
|
+
/** Create operation */
|
|
573
|
+
readonly CREATE: "create";
|
|
574
|
+
/** Update operation */
|
|
575
|
+
readonly UPDATE: "update";
|
|
576
|
+
/** Delete operation */
|
|
577
|
+
readonly DELETE: "delete";
|
|
578
|
+
};
|
|
579
|
+
/**
|
|
580
|
+
* Type representing valid operation types.
|
|
581
|
+
*/
|
|
582
|
+
type OperationType = (typeof OPERATION_TYPE)[keyof typeof OPERATION_TYPE];
|
|
583
|
+
|
|
584
|
+
/**
|
|
585
|
+
* Represents a CRUD operation on an entity.
|
|
586
|
+
*/
|
|
587
|
+
interface Operation {
|
|
588
|
+
/** The type of operation (create, update, delete) */
|
|
589
|
+
method: OperationType;
|
|
590
|
+
/** The entity data for the operation */
|
|
591
|
+
entity: any;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* Default configuration constants for CSV export operations.
|
|
596
|
+
*/
|
|
597
|
+
declare const CSV_CONFIG: {
|
|
598
|
+
/** End of line character for CSV */
|
|
599
|
+
readonly EOL: "\r\n";
|
|
600
|
+
/** Byte Order Mark for UTF-8 encoding */
|
|
601
|
+
readonly BOM: "";
|
|
602
|
+
/** Default field separator character */
|
|
603
|
+
readonly DEFAULT_FIELD_SEPARATOR: ",";
|
|
604
|
+
/** Default decimal separator */
|
|
605
|
+
readonly DEFAULT_DECIMAL_SEPARATOR: ".";
|
|
606
|
+
/** Default quote character for strings */
|
|
607
|
+
readonly DEFAULT_QUOTE: "\"";
|
|
608
|
+
/** Default value for showing title */
|
|
609
|
+
readonly DEFAULT_SHOW_TITLE: false;
|
|
610
|
+
/** Default title text */
|
|
611
|
+
readonly DEFAULT_TITLE: "My Generated Report";
|
|
612
|
+
/** Default filename (without extension) */
|
|
613
|
+
readonly DEFAULT_FILENAME: "generated";
|
|
614
|
+
/** Default value for showing column labels */
|
|
615
|
+
readonly DEFAULT_SHOW_LABELS: false;
|
|
616
|
+
/** Default value for using text file format */
|
|
617
|
+
readonly DEFAULT_USE_TEXT_FILE: false;
|
|
618
|
+
/** Default value for including BOM */
|
|
619
|
+
readonly DEFAULT_USE_BOM: true;
|
|
620
|
+
/** Default header array (empty) */
|
|
621
|
+
readonly DEFAULT_HEADER: readonly [];
|
|
622
|
+
/** Default value for using object keys as headers */
|
|
623
|
+
readonly DEFAULT_KEYS_AS_HEADERS: false;
|
|
624
|
+
};
|
|
625
|
+
/**
|
|
626
|
+
* Type representing valid CSV configuration values.
|
|
627
|
+
*/
|
|
628
|
+
type CsvConfig = (typeof CSV_CONFIG)[keyof typeof CSV_CONFIG];
|
|
629
|
+
|
|
630
|
+
/**
|
|
631
|
+
* Creates a validator function for Ecuadorian identification numbers (cédula or RUC).
|
|
632
|
+
*
|
|
633
|
+
* @param type - The type of identification to validate
|
|
634
|
+
* - 'cedula': Validates cédula (10 digits)
|
|
635
|
+
* - 'ruc_natural': Validates RUC for natural persons (13 digits)
|
|
636
|
+
* - 'ruc_privada': Validates RUC for private companies (13 digits)
|
|
637
|
+
* - 'ruc_publica': Validates RUC for public companies (13 digits)
|
|
638
|
+
* - 'ruc': Validates any type of RUC
|
|
639
|
+
* - 'id': Validates any valid identification type
|
|
640
|
+
* @returns A validator function that returns an error object if validation fails
|
|
641
|
+
*
|
|
642
|
+
* @example
|
|
643
|
+
* ```typescript
|
|
644
|
+
* const control = new FormControl('', [identificationValidator('cedula')]);
|
|
645
|
+
* ```
|
|
646
|
+
*/
|
|
647
|
+
declare function identificationValidator(type: 'cedula' | 'ruc_natural' | 'ruc_privada' | 'ruc_publica' | 'ruc' | 'id'): ValidatorFn;
|
|
648
|
+
|
|
649
|
+
/**
|
|
650
|
+
* Determines the type of Ecuadorian identification number.
|
|
651
|
+
*
|
|
652
|
+
* @param number - The identification number to analyze
|
|
653
|
+
* @returns The identification type ('cedula', 'ruc_natural', 'ruc_privada', 'ruc_publica') or null if invalid
|
|
654
|
+
*
|
|
655
|
+
* @example
|
|
656
|
+
* ```typescript
|
|
657
|
+
* const type = getIdentificationType('1234567890');
|
|
658
|
+
* // Returns: 'cedula' or null
|
|
659
|
+
* ```
|
|
660
|
+
*/
|
|
661
|
+
declare function getIdentificationType(number: string): string | null;
|
|
662
|
+
|
|
663
|
+
interface User {
|
|
664
|
+
username: string;
|
|
665
|
+
roles: string[];
|
|
666
|
+
email?: string;
|
|
667
|
+
firstName?: string;
|
|
668
|
+
lastName?: string;
|
|
669
|
+
picture?: string;
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
interface Login {
|
|
673
|
+
username: string;
|
|
674
|
+
password: string;
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
declare abstract class AuthProvider {
|
|
678
|
+
abstract user: Signal<User | null>;
|
|
679
|
+
abstract login(data?: Login): Promise<boolean>;
|
|
680
|
+
abstract logout(): Promise<boolean>;
|
|
681
|
+
abstract isLoggedIn: Signal<boolean>;
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
interface AuthToken {
|
|
685
|
+
token: string;
|
|
686
|
+
refresh_token: string;
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
interface Signup {
|
|
690
|
+
firstname: string;
|
|
691
|
+
lastname: string;
|
|
692
|
+
email: string;
|
|
693
|
+
username: string;
|
|
694
|
+
password: string;
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
/**
|
|
698
|
+
* Concrete authentication provider responsible for handling session lifecycle,
|
|
699
|
+
* secure token refresh, and profile management concerns across the app.
|
|
700
|
+
*
|
|
701
|
+
* @remarks
|
|
702
|
+
* The service extends {@link AuthProvider} to leverage core session helpers while
|
|
703
|
+
* adding stateful logic for dialogs, social login, and settings synchronization.
|
|
704
|
+
*/
|
|
705
|
+
declare class AuthService extends AuthProvider {
|
|
706
|
+
private readonly config;
|
|
707
|
+
private readonly dialog;
|
|
708
|
+
private readonly httpClient;
|
|
709
|
+
private readonly _user;
|
|
710
|
+
/** Session token key */
|
|
711
|
+
private readonly TOKEN_KEY;
|
|
712
|
+
readonly user: i0.Signal<User | null>;
|
|
713
|
+
constructor();
|
|
714
|
+
/**
|
|
715
|
+
* Flag indicating whether the access token is being refreshed
|
|
716
|
+
*/
|
|
717
|
+
refreshTokenInProgress: boolean;
|
|
718
|
+
/**
|
|
719
|
+
* Manages the access token refresh flow
|
|
720
|
+
*/
|
|
721
|
+
private readonly refreshTokenSubject;
|
|
722
|
+
/**
|
|
723
|
+
* Sends the authentication token to the server
|
|
724
|
+
* @param request HTTP request
|
|
725
|
+
* @returns
|
|
726
|
+
*/
|
|
727
|
+
addAuthenticationToken(request: HttpRequest<any>): HttpRequest<any>;
|
|
728
|
+
connect(client: 'google'): Promise<boolean>;
|
|
729
|
+
/**
|
|
730
|
+
* Extracts user claims from a JWT token payload.
|
|
731
|
+
* Maps common JWT claims (sub, email, given_name, family_name, etc.) to the User model.
|
|
732
|
+
* @param jwtToken The JWT token string
|
|
733
|
+
* @returns User object or null if parsing fails
|
|
734
|
+
*/
|
|
735
|
+
private extractUserFromToken;
|
|
736
|
+
/**
|
|
737
|
+
* Extracts the expiration timestamp from a JWT token
|
|
738
|
+
* @param jwtToken The JWT token string
|
|
739
|
+
* @returns The expiration timestamp in seconds (JWT exp format) or undefined if not found/invalid
|
|
740
|
+
*/
|
|
741
|
+
private extractExpirationFromToken;
|
|
742
|
+
/**
|
|
743
|
+
* Handles the flow of refreshing the access token or redirecting to sign-in
|
|
744
|
+
* @param err HTTP error
|
|
745
|
+
* @param request HTTP request sent
|
|
746
|
+
* @param next HTTP handler
|
|
747
|
+
*/
|
|
748
|
+
handle401Error(err: HttpErrorResponse, request: HttpRequest<any>, next: HttpHandlerFn): Observable<any>;
|
|
749
|
+
/**
|
|
750
|
+
* Sends sign-in to the server and obtains the authentication token
|
|
751
|
+
* @param data Authentication data
|
|
752
|
+
* @returns
|
|
753
|
+
*/
|
|
754
|
+
login(data?: Login): Promise<boolean>;
|
|
755
|
+
/**
|
|
756
|
+
* Logs out the user
|
|
757
|
+
*/
|
|
758
|
+
logout(): Promise<boolean>;
|
|
759
|
+
signup(data: Signup | Record<string, unknown>, options?: Record<string, unknown>): Promise<unknown>;
|
|
760
|
+
/**
|
|
761
|
+
* If a refresh token is implemented, send it to obtain a new access token
|
|
762
|
+
* @returns Access token
|
|
763
|
+
*/
|
|
764
|
+
refreshToken(): Observable<AuthToken>;
|
|
765
|
+
/**
|
|
766
|
+
* Reads the session token from the Secure cookie (client-side storage).
|
|
767
|
+
* @internal
|
|
768
|
+
*/
|
|
769
|
+
private getToken;
|
|
770
|
+
/**
|
|
771
|
+
* Sets the authentication token in session state and in a Secure cookie (client-side).
|
|
772
|
+
* Cookie: Path=/; SameSite=Strict; Secure on HTTPS; Max-Age from expiresAt or 1 day.
|
|
773
|
+
*
|
|
774
|
+
* @param token - The authentication token object to store
|
|
775
|
+
*/
|
|
776
|
+
private setToken;
|
|
777
|
+
/**
|
|
778
|
+
* Clears the authentication token from session state and removes the cookie.
|
|
779
|
+
*/
|
|
780
|
+
clearToken(): void;
|
|
781
|
+
/**
|
|
782
|
+
* Clears the current user from session state
|
|
783
|
+
*/
|
|
784
|
+
clearUser(): void;
|
|
785
|
+
/**
|
|
786
|
+
* Computed signal indicating whether a user is currently logged in
|
|
787
|
+
* Based on the presence and validity of the authentication token
|
|
788
|
+
*
|
|
789
|
+
* For JWT tokens, validates expiration. For other token types, only checks existence.
|
|
790
|
+
*
|
|
791
|
+
* @returns true if a valid token exists, false otherwise
|
|
792
|
+
*/
|
|
793
|
+
readonly isLoggedIn: i0.Signal<boolean>;
|
|
794
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<AuthService, never>;
|
|
795
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<AuthService>;
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
/**
|
|
799
|
+
* Configuration required by auth-core services.
|
|
800
|
+
* Provided via AUTH_CONFIG injection token from app.config.
|
|
801
|
+
*/
|
|
802
|
+
interface AuthConfig {
|
|
803
|
+
sessionPrefix: string;
|
|
804
|
+
appPath: string;
|
|
805
|
+
auth: {
|
|
806
|
+
signinUrl: string;
|
|
807
|
+
signupUrl: string;
|
|
808
|
+
refreshTokenUrl: string;
|
|
809
|
+
tokenType: string;
|
|
810
|
+
clients: Record<string, string>;
|
|
811
|
+
};
|
|
812
|
+
fedcm?: Record<string, {
|
|
813
|
+
tokenUrl: string;
|
|
814
|
+
configURL: string;
|
|
815
|
+
clientId: string;
|
|
816
|
+
}>;
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
/**
|
|
820
|
+
* Injection token for auth configuration.
|
|
821
|
+
* Provide this in app.config with values from environment.
|
|
822
|
+
*
|
|
823
|
+
* @example
|
|
824
|
+
* ```typescript
|
|
825
|
+
* import { AUTH_CONFIG } from 'auth-core';
|
|
826
|
+
* import { environment } from '@/environments/environment';
|
|
827
|
+
*
|
|
828
|
+
* providers: [
|
|
829
|
+
* { provide: AUTH_CONFIG, useValue: environment }
|
|
830
|
+
* ]
|
|
831
|
+
* ```
|
|
832
|
+
*/
|
|
833
|
+
declare const AUTH_CONFIG: InjectionToken<AuthConfig>;
|
|
834
|
+
|
|
835
|
+
declare const authGuard: CanActivateFn;
|
|
836
|
+
declare const loginGuard: CanActivateFn;
|
|
837
|
+
declare const resetGuard: CanActivateFn;
|
|
838
|
+
|
|
839
|
+
declare const authInterceptor: HttpInterceptorFn;
|
|
840
|
+
|
|
841
|
+
/**
|
|
842
|
+
* Base interface for JWT token payloads.
|
|
843
|
+
* Use JWTTokenPayload for the standard JWT claims implementation.
|
|
844
|
+
*/
|
|
845
|
+
interface AuthTokenPayload {
|
|
846
|
+
iss?: string;
|
|
847
|
+
sub?: string;
|
|
848
|
+
aud?: string;
|
|
849
|
+
exp?: number;
|
|
850
|
+
nbf?: number;
|
|
851
|
+
iat?: number;
|
|
852
|
+
jti?: string;
|
|
853
|
+
username?: string;
|
|
854
|
+
roles?: string[];
|
|
855
|
+
permissions?: string[];
|
|
856
|
+
[key: string]: unknown;
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
interface FedcmCredentialRequestOptions extends CredentialRequestOptions {
|
|
860
|
+
identity: {
|
|
861
|
+
providers: {
|
|
862
|
+
configURL: string;
|
|
863
|
+
clientId: string;
|
|
864
|
+
fields: string[];
|
|
865
|
+
params: any;
|
|
866
|
+
nonce: string;
|
|
867
|
+
}[];
|
|
868
|
+
mode: string;
|
|
869
|
+
};
|
|
870
|
+
}
|
|
871
|
+
interface FedcmCredential {
|
|
872
|
+
token: string;
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
interface JwtAuthProvider {
|
|
876
|
+
getTokenPayload<T = AuthTokenPayload>(): T | null;
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
interface JWTTokenPayload {
|
|
880
|
+
iss?: string;
|
|
881
|
+
sub?: string;
|
|
882
|
+
aud?: string;
|
|
883
|
+
exp?: number;
|
|
884
|
+
nbf?: number;
|
|
885
|
+
iat?: number;
|
|
886
|
+
jti?: string;
|
|
887
|
+
username?: string;
|
|
888
|
+
roles?: string[];
|
|
889
|
+
permissions?: string[];
|
|
890
|
+
[key: string]: unknown;
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
export { AUTH_CONFIG, ArrayUtil, AuthProvider, AuthService, CSV_CONFIG, ColorUtil, CsvExporter, DateUtil, FilePicker, GoogleTagManager, OPERATION_TYPE, ObjectUtil, Storage, StringUtil, authGuard, authInterceptor, getIdentificationType, identificationValidator, loginGuard, resetGuard };
|
|
894
|
+
export type { AuthConfig, AuthToken, AuthTokenPayload, CsvConfig, CsvOptions, CsvParsed, Error, FedcmCredential, FedcmCredentialRequestOptions, JWTTokenPayload, JwtAuthProvider, Login, Operation, OperationType, Signup, User };
|