@factor_ec/utils 3.0.3 → 5.0.1
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 +49 -10
- package/fesm2022/factor_ec-utils.mjs +608 -33
- package/fesm2022/factor_ec-utils.mjs.map +1 -1
- package/lib/array.service.d.ts +6 -0
- package/lib/csv.service.d.ts +88 -0
- package/lib/date.service.d.ts +6 -0
- package/lib/graphql.provider.d.ts +4 -0
- package/lib/graphql.service.d.ts +12 -0
- package/lib/models/auth-token-payload.d.ts +6 -0
- package/lib/models/auth-token.d.ts +4 -0
- package/lib/models/currency.d.ts +6 -0
- package/lib/models/error.d.ts +6 -0
- package/lib/models/language.d.ts +4 -0
- package/lib/models/login.d.ts +4 -0
- package/lib/models/operation.d.ts +4 -0
- package/lib/models/option.d.ts +5 -0
- package/lib/models/user.d.ts +5 -0
- package/lib/models/utils-options.d.ts +6 -0
- package/lib/object.service.d.ts +7 -0
- package/lib/rest.service.d.ts +16 -0
- package/lib/string.service.d.ts +14 -0
- package/lib/utils.service.d.ts +9 -0
- package/package.json +5 -5
- package/public-api.d.ts +18 -1
- package/esm2022/factor_ec-utils.mjs +0 -5
- package/esm2022/lib/color.service.mjs +0 -162
- package/esm2022/lib/files.service.mjs +0 -47
- package/esm2022/lib/google-tag-manager.service.mjs +0 -75
- package/esm2022/lib/storage.service.mjs +0 -90
- package/esm2022/lib/validators/ec/identification-type.mjs +0 -154
- package/esm2022/lib/validators/ec/identification-validator.mjs +0 -30
- package/esm2022/public-api.mjs +0 -10
|
@@ -1,10 +1,38 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { Injectable, PLATFORM_ID, Inject } from '@angular/core';
|
|
2
|
+
import { Injectable, PLATFORM_ID, Inject, InjectionToken, inject } from '@angular/core';
|
|
3
3
|
import { isPlatformBrowser } from '@angular/common';
|
|
4
4
|
import * as i1 from '@angular/router';
|
|
5
5
|
import { NavigationEnd } from '@angular/router';
|
|
6
|
+
import { Apollo, APOLLO_OPTIONS, gql } from 'apollo-angular';
|
|
7
|
+
import { HttpLink } from 'apollo-angular/http';
|
|
8
|
+
import { InMemoryCache } from '@apollo/client/core';
|
|
9
|
+
import { lastValueFrom } from 'rxjs';
|
|
10
|
+
import { HttpClient } from '@angular/common/http';
|
|
11
|
+
|
|
12
|
+
class ArrayService {
|
|
13
|
+
merge(arrays, prop) {
|
|
14
|
+
const merged = {};
|
|
15
|
+
arrays.forEach(arr => {
|
|
16
|
+
arr.forEach((item) => {
|
|
17
|
+
merged[item[prop]] = Object.assign({}, merged[item[prop]], item);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
return Object.values(merged);
|
|
21
|
+
}
|
|
22
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.6", ngImport: i0, type: ArrayService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
23
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.6", ngImport: i0, type: ArrayService, providedIn: 'root' });
|
|
24
|
+
}
|
|
25
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.6", ngImport: i0, type: ArrayService, decorators: [{
|
|
26
|
+
type: Injectable,
|
|
27
|
+
args: [{
|
|
28
|
+
providedIn: 'root'
|
|
29
|
+
}]
|
|
30
|
+
}] });
|
|
6
31
|
|
|
7
32
|
class ColorService {
|
|
33
|
+
L;
|
|
34
|
+
S;
|
|
35
|
+
hueRanges;
|
|
8
36
|
constructor() {
|
|
9
37
|
const options = {};
|
|
10
38
|
let LS = [options.lightness, options.saturation].map(function (param) {
|
|
@@ -25,7 +53,7 @@ class ColorService {
|
|
|
25
53
|
this.hueRanges = options.hue.map(function (range) {
|
|
26
54
|
return {
|
|
27
55
|
min: typeof range.min === 'undefined' ? 0 : range.min,
|
|
28
|
-
max: typeof range.max === 'undefined' ? 360 : range.max
|
|
56
|
+
max: typeof range.max === 'undefined' ? 360 : range.max,
|
|
29
57
|
};
|
|
30
58
|
});
|
|
31
59
|
}
|
|
@@ -50,7 +78,6 @@ class ColorService {
|
|
|
50
78
|
}
|
|
51
79
|
return hash;
|
|
52
80
|
}
|
|
53
|
-
;
|
|
54
81
|
/**
|
|
55
82
|
* Convert RGB Array to HEX
|
|
56
83
|
*
|
|
@@ -67,7 +94,6 @@ class ColorService {
|
|
|
67
94
|
});
|
|
68
95
|
return hex;
|
|
69
96
|
}
|
|
70
|
-
;
|
|
71
97
|
/**
|
|
72
98
|
* Convert HSL to RGB
|
|
73
99
|
*
|
|
@@ -103,7 +129,6 @@ class ColorService {
|
|
|
103
129
|
return Math.round(color * 255);
|
|
104
130
|
});
|
|
105
131
|
}
|
|
106
|
-
;
|
|
107
132
|
/**
|
|
108
133
|
* Returns the hash in [h, s, l].
|
|
109
134
|
* Note that H ∈ [0, 360); S ∈ [0, 1]; L ∈ [0, 1];
|
|
@@ -119,7 +144,11 @@ class ColorService {
|
|
|
119
144
|
if (this.hueRanges.length) {
|
|
120
145
|
let range = this.hueRanges[hash % this.hueRanges.length];
|
|
121
146
|
let hueResolution = 727; // note that 727 is a prime
|
|
122
|
-
H =
|
|
147
|
+
H =
|
|
148
|
+
(((hash / this.hueRanges.length) % hueResolution) *
|
|
149
|
+
(range.max - range.min)) /
|
|
150
|
+
hueResolution +
|
|
151
|
+
range.min;
|
|
123
152
|
}
|
|
124
153
|
else {
|
|
125
154
|
H = hash % 359; // note that 359 is a prime
|
|
@@ -130,7 +159,6 @@ class ColorService {
|
|
|
130
159
|
L = this.L[hash % this.L.length];
|
|
131
160
|
return [H, S, L];
|
|
132
161
|
}
|
|
133
|
-
;
|
|
134
162
|
/**
|
|
135
163
|
* Returns the hash in [r, g, b].
|
|
136
164
|
* Note that R, G, B ∈ [0, 255]
|
|
@@ -142,7 +170,6 @@ class ColorService {
|
|
|
142
170
|
let hsl = this.hsl(str);
|
|
143
171
|
return this.hsl2rgb(hsl[0], hsl[1], hsl[2]);
|
|
144
172
|
}
|
|
145
|
-
;
|
|
146
173
|
/**
|
|
147
174
|
* Returns the hash in hex
|
|
148
175
|
*
|
|
@@ -153,18 +180,285 @@ class ColorService {
|
|
|
153
180
|
let rgb = this.rgb(str);
|
|
154
181
|
return this.rgb2hex(rgb);
|
|
155
182
|
}
|
|
156
|
-
;
|
|
157
|
-
static
|
|
158
|
-
|
|
183
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.6", ngImport: i0, type: ColorService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
184
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.6", ngImport: i0, type: ColorService, providedIn: 'root' });
|
|
185
|
+
}
|
|
186
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.6", ngImport: i0, type: ColorService, decorators: [{
|
|
187
|
+
type: Injectable,
|
|
188
|
+
args: [{
|
|
189
|
+
providedIn: 'root',
|
|
190
|
+
}]
|
|
191
|
+
}], ctorParameters: () => [] });
|
|
192
|
+
|
|
193
|
+
class CsvConfigConsts {
|
|
194
|
+
static EOL = '\r\n';
|
|
195
|
+
static BOM = '\ufeff';
|
|
196
|
+
static DEFAULT_FIELD_SEPARATOR = ',';
|
|
197
|
+
static DEFAULT_DECIMAL_SEPARATOR = '.';
|
|
198
|
+
static DEFAULT_QUOTE = '"';
|
|
199
|
+
static DEFAULT_SHOW_TITLE = false;
|
|
200
|
+
static DEFAULT_TITLE = 'My Generated Report';
|
|
201
|
+
static DEFAULT_FILENAME = 'generated';
|
|
202
|
+
static DEFAULT_SHOW_LABELS = false;
|
|
203
|
+
static DEFAULT_USE_TEXT_FILE = false;
|
|
204
|
+
static DEFAULT_USE_BOM = true;
|
|
205
|
+
static DEFAULT_HEADER = [];
|
|
206
|
+
static DEFAULT_KEYS_AS_HEADERS = false;
|
|
207
|
+
}
|
|
208
|
+
const ConfigDefaults = {
|
|
209
|
+
filename: CsvConfigConsts.DEFAULT_FILENAME,
|
|
210
|
+
fieldSeparator: CsvConfigConsts.DEFAULT_FIELD_SEPARATOR,
|
|
211
|
+
quoteStrings: CsvConfigConsts.DEFAULT_QUOTE,
|
|
212
|
+
decimalSeparator: CsvConfigConsts.DEFAULT_DECIMAL_SEPARATOR,
|
|
213
|
+
showLabels: CsvConfigConsts.DEFAULT_SHOW_LABELS,
|
|
214
|
+
showTitle: CsvConfigConsts.DEFAULT_SHOW_TITLE,
|
|
215
|
+
title: CsvConfigConsts.DEFAULT_TITLE,
|
|
216
|
+
useTextFile: CsvConfigConsts.DEFAULT_USE_TEXT_FILE,
|
|
217
|
+
useBom: CsvConfigConsts.DEFAULT_USE_BOM,
|
|
218
|
+
headers: CsvConfigConsts.DEFAULT_HEADER,
|
|
219
|
+
useKeysAsHeaders: CsvConfigConsts.DEFAULT_KEYS_AS_HEADERS
|
|
220
|
+
};
|
|
221
|
+
class CsvService {
|
|
222
|
+
_data = [];
|
|
223
|
+
_options;
|
|
224
|
+
_csv = '';
|
|
225
|
+
get options() {
|
|
226
|
+
return this._options;
|
|
227
|
+
}
|
|
228
|
+
set options(options) {
|
|
229
|
+
this._options = this.objectAssign({}, ConfigDefaults, options);
|
|
230
|
+
}
|
|
231
|
+
constructor() {
|
|
232
|
+
this._options = this.objectAssign({}, ConfigDefaults);
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Generate and Download Csv
|
|
236
|
+
*/
|
|
237
|
+
generate(jsonData, shouldReturnCsv = false) {
|
|
238
|
+
// Make sure to reset csv data on each run
|
|
239
|
+
this._csv = '';
|
|
240
|
+
this._parseData(jsonData);
|
|
241
|
+
if (this._options.useBom) {
|
|
242
|
+
this._csv += CsvConfigConsts.BOM;
|
|
243
|
+
}
|
|
244
|
+
if (this._options.showTitle) {
|
|
245
|
+
this._csv += this._options.title + '\r\n\n';
|
|
246
|
+
}
|
|
247
|
+
this._getHeaders();
|
|
248
|
+
this._getBody();
|
|
249
|
+
if (this._csv == '') {
|
|
250
|
+
console.log('Invalid data');
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
// When the consumer asks for the data, exit the function
|
|
254
|
+
// by returning the CSV data built at this point
|
|
255
|
+
if (shouldReturnCsv) {
|
|
256
|
+
return this._csv;
|
|
257
|
+
}
|
|
258
|
+
// Create CSV blob to download if requesting in the browser and the
|
|
259
|
+
// consumer doesn't set the shouldReturnCsv param
|
|
260
|
+
const FileType = this._options.useTextFile ? 'plain' : 'csv';
|
|
261
|
+
const fileExtension = this._options.useTextFile ? '.txt' : '.csv';
|
|
262
|
+
const blob = new Blob([this._csv], {
|
|
263
|
+
type: 'text/' + FileType + ';charset=utf8;'
|
|
264
|
+
});
|
|
265
|
+
//const attachmentType = this._options.useTextFile ? 'text' : 'csv';
|
|
266
|
+
// const uri = 'data:attachment/' + attachmentType + ';charset=utf-8,' + encodeURI(this._csv);
|
|
267
|
+
const link = document.createElement('a');
|
|
268
|
+
link.href = URL.createObjectURL(blob);
|
|
269
|
+
link.setAttribute('visibility', 'hidden');
|
|
270
|
+
link.download = this._options.filename.replace(/ /g, '_') + fileExtension;
|
|
271
|
+
document.body.appendChild(link);
|
|
272
|
+
link.click();
|
|
273
|
+
document.body.removeChild(link);
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Create Headers
|
|
277
|
+
*/
|
|
278
|
+
_getHeaders() {
|
|
279
|
+
if (!this._options.showLabels && !this._options.useKeysAsHeaders) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
const useKeysAsHeaders = this._options.useKeysAsHeaders;
|
|
283
|
+
const headers = useKeysAsHeaders
|
|
284
|
+
? Object.keys(this._data[0])
|
|
285
|
+
: this._options.headers;
|
|
286
|
+
if (headers.length > 0) {
|
|
287
|
+
let row = '';
|
|
288
|
+
for (let keyPos = 0; keyPos < headers.length; keyPos++) {
|
|
289
|
+
row += headers[keyPos] + this._options.fieldSeparator;
|
|
290
|
+
}
|
|
291
|
+
row = row.slice(0, -1);
|
|
292
|
+
this._csv += row + CsvConfigConsts.EOL;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Create Body
|
|
297
|
+
*/
|
|
298
|
+
_getBody() {
|
|
299
|
+
const keys = Object.keys(this._data[0]);
|
|
300
|
+
for (var i = 0; i < this._data.length; i++) {
|
|
301
|
+
let row = '';
|
|
302
|
+
for (let keyPos = 0; keyPos < keys.length; keyPos++) {
|
|
303
|
+
const key = keys[keyPos];
|
|
304
|
+
row +=
|
|
305
|
+
this._formatData(this._data[i][key]) + this._options.fieldSeparator;
|
|
306
|
+
}
|
|
307
|
+
row = row.slice(0, -1);
|
|
308
|
+
this._csv += row + CsvConfigConsts.EOL;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Format Data
|
|
313
|
+
* @param {any} data
|
|
314
|
+
*/
|
|
315
|
+
_formatData(data) {
|
|
316
|
+
if (this._options.decimalSeparator === 'locale' && this._isFloat(data)) {
|
|
317
|
+
return data.toLocaleString();
|
|
318
|
+
}
|
|
319
|
+
if (this._options.decimalSeparator !== '.' && this._isFloat(data)) {
|
|
320
|
+
return data.toString().replace('.', this._options.decimalSeparator);
|
|
321
|
+
}
|
|
322
|
+
if (typeof data === 'string') {
|
|
323
|
+
data = data.replace(/"/g, '""');
|
|
324
|
+
if (this._options.quoteStrings ||
|
|
325
|
+
data.indexOf(',') > -1 ||
|
|
326
|
+
data.indexOf('\n') > -1 ||
|
|
327
|
+
data.indexOf('\r') > -1) {
|
|
328
|
+
data = this._options.quoteStrings + data + this._options.quoteStrings;
|
|
329
|
+
}
|
|
330
|
+
return data;
|
|
331
|
+
}
|
|
332
|
+
if (typeof data === 'boolean') {
|
|
333
|
+
return data ? 'TRUE' : 'FALSE';
|
|
334
|
+
}
|
|
335
|
+
return data;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Check if is Float
|
|
339
|
+
* @param {any} input
|
|
340
|
+
*/
|
|
341
|
+
_isFloat(input) {
|
|
342
|
+
return +input === input && (!isFinite(input) || Boolean(input % 1));
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Parse the collection given to it
|
|
346
|
+
*
|
|
347
|
+
* @private
|
|
348
|
+
* @param {*} jsonData
|
|
349
|
+
* @returns {any[]}
|
|
350
|
+
* @memberof ExportToCsv
|
|
351
|
+
*/
|
|
352
|
+
_parseData(jsonData) {
|
|
353
|
+
this._data = typeof jsonData != 'object' ? JSON.parse(jsonData) : jsonData;
|
|
354
|
+
return this._data;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Convet to Object
|
|
358
|
+
* @param {any} val
|
|
359
|
+
*/
|
|
360
|
+
toObject(val) {
|
|
361
|
+
if (val === null || val === undefined) {
|
|
362
|
+
throw new TypeError('Object.assign cannot be called with null or undefined');
|
|
363
|
+
}
|
|
364
|
+
return Object(val);
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Assign data to new Object
|
|
368
|
+
* @param {any} target
|
|
369
|
+
* @param {any[]} ...source
|
|
370
|
+
*/
|
|
371
|
+
objectAssign(target, ...source) {
|
|
372
|
+
let from;
|
|
373
|
+
const to = this.toObject(target);
|
|
374
|
+
let symbols;
|
|
375
|
+
let hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
376
|
+
let propIsEnumerable = Object.prototype.propertyIsEnumerable;
|
|
377
|
+
for (var s = 1; s < arguments.length; s++) {
|
|
378
|
+
from = Object(arguments[s]);
|
|
379
|
+
for (var key in from) {
|
|
380
|
+
if (hasOwnProperty.call(from, key)) {
|
|
381
|
+
to[key] = from[key];
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
if (Object.getOwnPropertySymbols) {
|
|
385
|
+
symbols = Object.getOwnPropertySymbols(from);
|
|
386
|
+
for (let i = 0; i < symbols.length; i++) {
|
|
387
|
+
if (propIsEnumerable.call(from, symbols[i])) {
|
|
388
|
+
to[symbols[i]] = from[symbols[i]];
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
return to;
|
|
394
|
+
}
|
|
395
|
+
read(csvContent) {
|
|
396
|
+
const lines = csvContent.split('\n');
|
|
397
|
+
let header;
|
|
398
|
+
let content;
|
|
399
|
+
if (lines.length > 0) {
|
|
400
|
+
const csv = lines.map((line) => {
|
|
401
|
+
return this.parseLine(line.trim());
|
|
402
|
+
});
|
|
403
|
+
header = csv[0];
|
|
404
|
+
// Si encuentra una linea en blanco ya no sigue leyendo las siguientes líneas
|
|
405
|
+
let breakIndex;
|
|
406
|
+
csv.some((row, index) => {
|
|
407
|
+
const isBlankLine = row.every((column) => column.trim() === '');
|
|
408
|
+
if (isBlankLine) {
|
|
409
|
+
breakIndex = index;
|
|
410
|
+
return true;
|
|
411
|
+
}
|
|
412
|
+
return false;
|
|
413
|
+
});
|
|
414
|
+
content = csv.slice(1, breakIndex);
|
|
415
|
+
}
|
|
416
|
+
else {
|
|
417
|
+
header = [];
|
|
418
|
+
content = [];
|
|
419
|
+
}
|
|
420
|
+
return {
|
|
421
|
+
header,
|
|
422
|
+
content
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
parseLine(csvLine) {
|
|
426
|
+
const values = [];
|
|
427
|
+
const regex = /(?:"([^"]*)"|'([^']*)'|([^,]+))(?:,|\r?$)/g;
|
|
428
|
+
let match;
|
|
429
|
+
while ((match = regex.exec(csvLine)) !== null) {
|
|
430
|
+
values.push(match[1] || match[2] || match[3]); // Extraer el valor correcto
|
|
431
|
+
}
|
|
432
|
+
return values;
|
|
433
|
+
}
|
|
434
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.6", ngImport: i0, type: CsvService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
435
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.6", ngImport: i0, type: CsvService, providedIn: 'root' });
|
|
436
|
+
}
|
|
437
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.6", ngImport: i0, type: CsvService, decorators: [{
|
|
438
|
+
type: Injectable,
|
|
439
|
+
args: [{
|
|
440
|
+
providedIn: 'root'
|
|
441
|
+
}]
|
|
442
|
+
}], ctorParameters: () => [] });
|
|
443
|
+
|
|
444
|
+
class DateService {
|
|
445
|
+
getDate(date) {
|
|
446
|
+
const dateParts = date.split('T')[0].split('-');
|
|
447
|
+
return new Date(Number(dateParts[0]), Number(dateParts[1]) - 1, Number(dateParts[2]));
|
|
448
|
+
}
|
|
449
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.6", ngImport: i0, type: DateService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
450
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.6", ngImport: i0, type: DateService, providedIn: 'root' });
|
|
159
451
|
}
|
|
160
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
452
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.6", ngImport: i0, type: DateService, decorators: [{
|
|
161
453
|
type: Injectable,
|
|
162
454
|
args: [{
|
|
163
455
|
providedIn: 'root'
|
|
164
456
|
}]
|
|
165
|
-
}]
|
|
457
|
+
}] });
|
|
166
458
|
|
|
167
459
|
class FilesService {
|
|
460
|
+
callback;
|
|
461
|
+
fileInput;
|
|
168
462
|
constructor() {
|
|
169
463
|
this.fileInput = document.createElement('input');
|
|
170
464
|
this.fileInput.type = 'file';
|
|
@@ -199,17 +493,20 @@ class FilesService {
|
|
|
199
493
|
this.callback = callback;
|
|
200
494
|
}
|
|
201
495
|
}
|
|
202
|
-
static
|
|
203
|
-
static
|
|
496
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.6", ngImport: i0, type: FilesService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
497
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.6", ngImport: i0, type: FilesService, providedIn: 'root' });
|
|
204
498
|
}
|
|
205
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
499
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.6", ngImport: i0, type: FilesService, decorators: [{
|
|
206
500
|
type: Injectable,
|
|
207
501
|
args: [{
|
|
208
502
|
providedIn: 'root'
|
|
209
503
|
}]
|
|
210
|
-
}], ctorParameters:
|
|
504
|
+
}], ctorParameters: () => [] });
|
|
211
505
|
|
|
212
506
|
class GoogleTagManagerService {
|
|
507
|
+
platformId;
|
|
508
|
+
router;
|
|
509
|
+
trackingId;
|
|
213
510
|
constructor(platformId, router) {
|
|
214
511
|
this.platformId = platformId;
|
|
215
512
|
this.router = router;
|
|
@@ -266,20 +563,302 @@ class GoogleTagManagerService {
|
|
|
266
563
|
}
|
|
267
564
|
});
|
|
268
565
|
}
|
|
269
|
-
static
|
|
270
|
-
static
|
|
566
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.6", ngImport: i0, type: GoogleTagManagerService, deps: [{ token: PLATFORM_ID }, { token: i1.Router }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
567
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.6", ngImport: i0, type: GoogleTagManagerService, providedIn: 'root' });
|
|
271
568
|
}
|
|
272
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
569
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.6", ngImport: i0, type: GoogleTagManagerService, decorators: [{
|
|
273
570
|
type: Injectable,
|
|
274
571
|
args: [{
|
|
275
572
|
providedIn: 'root'
|
|
276
573
|
}]
|
|
277
|
-
}], ctorParameters:
|
|
574
|
+
}], ctorParameters: () => [{ type: Object, decorators: [{
|
|
278
575
|
type: Inject,
|
|
279
576
|
args: [PLATFORM_ID]
|
|
280
|
-
}] }, { type: i1.Router }]
|
|
577
|
+
}] }, { type: i1.Router }] });
|
|
578
|
+
|
|
579
|
+
const UTILS_OPTIONS = new InjectionToken('UTILS_OPTIONS');
|
|
580
|
+
|
|
581
|
+
class UtilsService {
|
|
582
|
+
options;
|
|
583
|
+
constructor(options) {
|
|
584
|
+
this.options = options;
|
|
585
|
+
}
|
|
586
|
+
get() {
|
|
587
|
+
return this.options;
|
|
588
|
+
}
|
|
589
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.6", ngImport: i0, type: UtilsService, deps: [{ token: UTILS_OPTIONS }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
590
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.6", ngImport: i0, type: UtilsService, providedIn: 'root' });
|
|
591
|
+
}
|
|
592
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.6", ngImport: i0, type: UtilsService, decorators: [{
|
|
593
|
+
type: Injectable,
|
|
594
|
+
args: [{
|
|
595
|
+
providedIn: 'root'
|
|
596
|
+
}]
|
|
597
|
+
}], ctorParameters: () => [{ type: undefined, decorators: [{
|
|
598
|
+
type: Inject,
|
|
599
|
+
args: [UTILS_OPTIONS]
|
|
600
|
+
}] }] });
|
|
601
|
+
|
|
602
|
+
function apolloOptionsFactory() {
|
|
603
|
+
const httpLink = inject(HttpLink);
|
|
604
|
+
const options = inject(UtilsService);
|
|
605
|
+
return {
|
|
606
|
+
link: httpLink.create({ uri: options.get().graphqlEndpoint }),
|
|
607
|
+
cache: new InMemoryCache(),
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
const graphqlProvider = [
|
|
611
|
+
Apollo,
|
|
612
|
+
{
|
|
613
|
+
provide: APOLLO_OPTIONS,
|
|
614
|
+
useFactory: apolloOptionsFactory,
|
|
615
|
+
},
|
|
616
|
+
];
|
|
617
|
+
|
|
618
|
+
class StringService {
|
|
619
|
+
decodeHTML(text) {
|
|
620
|
+
const span = document.createElement('span');
|
|
621
|
+
return text.replace(/&[#A-Za-z0-9]+;/gi, (entity) => {
|
|
622
|
+
span.innerHTML = entity;
|
|
623
|
+
return span.innerText;
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* Normaliza un texto para evitar el Case y los acentos
|
|
628
|
+
* @param text texto a normalizar
|
|
629
|
+
* @returns texto normalizado
|
|
630
|
+
*/
|
|
631
|
+
normalize(text) {
|
|
632
|
+
if (!text)
|
|
633
|
+
return '';
|
|
634
|
+
return text
|
|
635
|
+
.toLowerCase()
|
|
636
|
+
.normalize("NFD")
|
|
637
|
+
.replace(/[\u0300-\u036f]/g, "");
|
|
638
|
+
}
|
|
639
|
+
normalizeName(text) {
|
|
640
|
+
text = text.trim();
|
|
641
|
+
text = text.charAt(0).toUpperCase() + text.slice(1);
|
|
642
|
+
return text;
|
|
643
|
+
}
|
|
644
|
+
calculateReadingTime(text) {
|
|
645
|
+
// Caracteres por minuto
|
|
646
|
+
const cpm = 1000;
|
|
647
|
+
// Calcular el número de caracteres en el texto
|
|
648
|
+
const numCharacters = text.length;
|
|
649
|
+
// Calcular el tiempo de lectura en minutos
|
|
650
|
+
const readingTimeMinutes = numCharacters / cpm;
|
|
651
|
+
// Convertir el tiempo de lectura de minutos a milisegundos
|
|
652
|
+
const readingTimeMilliseconds = readingTimeMinutes * 60 * 1000;
|
|
653
|
+
return readingTimeMilliseconds;
|
|
654
|
+
}
|
|
655
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.6", ngImport: i0, type: StringService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
656
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.6", ngImport: i0, type: StringService, providedIn: 'root' });
|
|
657
|
+
}
|
|
658
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.6", ngImport: i0, type: StringService, decorators: [{
|
|
659
|
+
type: Injectable,
|
|
660
|
+
args: [{
|
|
661
|
+
providedIn: 'root'
|
|
662
|
+
}]
|
|
663
|
+
}] });
|
|
664
|
+
|
|
665
|
+
class GraphqlService {
|
|
666
|
+
apollo = inject(Apollo);
|
|
667
|
+
stringService = inject(StringService);
|
|
668
|
+
mutation(operation, type, entity) {
|
|
669
|
+
let mutation;
|
|
670
|
+
const capitalizedType = this.stringService.normalizeName(type);
|
|
671
|
+
switch (operation) {
|
|
672
|
+
case 'create':
|
|
673
|
+
entity.uuid = entity.id ? entity.id.split('/').pop() : crypto.randomUUID();
|
|
674
|
+
delete entity.createdBy;
|
|
675
|
+
delete entity.updatedBy;
|
|
676
|
+
delete entity.id;
|
|
677
|
+
mutation = this.apollo.mutate({
|
|
678
|
+
mutation: gql `
|
|
679
|
+
mutation Create${capitalizedType}($entity: create${capitalizedType}Input!) {
|
|
680
|
+
create${capitalizedType}(input: $entity) {
|
|
681
|
+
${type} {
|
|
682
|
+
id
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
`,
|
|
687
|
+
variables: {
|
|
688
|
+
entity
|
|
689
|
+
}
|
|
690
|
+
});
|
|
691
|
+
break;
|
|
692
|
+
case 'delete':
|
|
693
|
+
mutation = this.apollo.mutate({
|
|
694
|
+
mutation: gql `
|
|
695
|
+
mutation Delete${capitalizedType}($id: ID!) {
|
|
696
|
+
delete${capitalizedType}(input: {id: $id}) {
|
|
697
|
+
clientMutationId
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
`,
|
|
701
|
+
variables: {
|
|
702
|
+
id: entity.id
|
|
703
|
+
}
|
|
704
|
+
});
|
|
705
|
+
break;
|
|
706
|
+
case 'update':
|
|
707
|
+
delete entity.createdBy;
|
|
708
|
+
delete entity.updatedBy;
|
|
709
|
+
mutation = this.apollo.mutate({
|
|
710
|
+
mutation: gql `
|
|
711
|
+
mutation Update${capitalizedType}($entity: update${capitalizedType}Input!) {
|
|
712
|
+
update${capitalizedType}(input: $entity) {
|
|
713
|
+
${type} {
|
|
714
|
+
id
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
`,
|
|
719
|
+
variables: {
|
|
720
|
+
entity
|
|
721
|
+
}
|
|
722
|
+
});
|
|
723
|
+
break;
|
|
724
|
+
}
|
|
725
|
+
return lastValueFrom(mutation);
|
|
726
|
+
}
|
|
727
|
+
parseQuery(query) {
|
|
728
|
+
if (query !== null) {
|
|
729
|
+
const data = {};
|
|
730
|
+
for (const property in query) {
|
|
731
|
+
if (query[property]?.edges) {
|
|
732
|
+
data[property] = this.parseEdges(query[property].edges);
|
|
733
|
+
}
|
|
734
|
+
else if (query[property]?.node) {
|
|
735
|
+
data[property] = this.parseQuery(query[property].node);
|
|
736
|
+
}
|
|
737
|
+
else if (Array.isArray(query[property])) {
|
|
738
|
+
// Si es un arreglo simple no lo parsea
|
|
739
|
+
if (typeof query[property][0] === 'object') {
|
|
740
|
+
data[property] = query[property].map((node) => {
|
|
741
|
+
return this.parseQuery(node);
|
|
742
|
+
});
|
|
743
|
+
}
|
|
744
|
+
else {
|
|
745
|
+
data[property] = query[property];
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
else if (typeof query[property] === 'object') {
|
|
749
|
+
data[property] = this.parseQuery(query[property]);
|
|
750
|
+
}
|
|
751
|
+
else if (property !== '__typename') {
|
|
752
|
+
data[property] = query[property];
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
return data;
|
|
756
|
+
}
|
|
757
|
+
else {
|
|
758
|
+
return query;
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
parseEdges(edges) {
|
|
762
|
+
return edges.map((entity) => {
|
|
763
|
+
return this.parseQuery(entity?.node || entity);
|
|
764
|
+
});
|
|
765
|
+
}
|
|
766
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.6", ngImport: i0, type: GraphqlService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
767
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.6", ngImport: i0, type: GraphqlService, providedIn: 'root' });
|
|
768
|
+
}
|
|
769
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.6", ngImport: i0, type: GraphqlService, decorators: [{
|
|
770
|
+
type: Injectable,
|
|
771
|
+
args: [{
|
|
772
|
+
providedIn: 'root'
|
|
773
|
+
}]
|
|
774
|
+
}] });
|
|
775
|
+
|
|
776
|
+
class ObjectService {
|
|
777
|
+
filterNullProperties(obj) {
|
|
778
|
+
const mappedObj = {};
|
|
779
|
+
Object.keys(obj).forEach((key) => {
|
|
780
|
+
if (obj[key] !== null && obj[key] !== undefined && obj[key] !== 'undefined') {
|
|
781
|
+
mappedObj[key] = obj[key];
|
|
782
|
+
}
|
|
783
|
+
});
|
|
784
|
+
return mappedObj;
|
|
785
|
+
}
|
|
786
|
+
deepMerge(target, source) {
|
|
787
|
+
source = structuredClone(source);
|
|
788
|
+
target = structuredClone(target);
|
|
789
|
+
for (const key of Object.keys(source)) {
|
|
790
|
+
if (source[key] instanceof Object && key in target) {
|
|
791
|
+
Object.assign(source[key], this.deepMerge(target[key], source[key]));
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
return { ...target, ...source };
|
|
795
|
+
}
|
|
796
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.6", ngImport: i0, type: ObjectService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
797
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.6", ngImport: i0, type: ObjectService, providedIn: 'root' });
|
|
798
|
+
}
|
|
799
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.6", ngImport: i0, type: ObjectService, decorators: [{
|
|
800
|
+
type: Injectable,
|
|
801
|
+
args: [{
|
|
802
|
+
providedIn: 'root'
|
|
803
|
+
}]
|
|
804
|
+
}] });
|
|
805
|
+
|
|
806
|
+
class RestService {
|
|
807
|
+
http = inject(HttpClient);
|
|
808
|
+
options = inject(UtilsService);
|
|
809
|
+
delete(resourcePath, id) {
|
|
810
|
+
const url = `${this.getApiPath(resourcePath)}${resourcePath}/${id}`;
|
|
811
|
+
return this.http.delete(url);
|
|
812
|
+
}
|
|
813
|
+
find(resourcePath, params, options) {
|
|
814
|
+
const url = `${this.getApiPath(resourcePath)}${resourcePath}`;
|
|
815
|
+
return this.http.get(url, { ...{ params }, ...options });
|
|
816
|
+
}
|
|
817
|
+
get(resourcePath, id, params, options) {
|
|
818
|
+
let url;
|
|
819
|
+
if (id) {
|
|
820
|
+
url = `${this.getApiPath(resourcePath)}${resourcePath}/${id}`;
|
|
821
|
+
}
|
|
822
|
+
else {
|
|
823
|
+
return this.find(`${this.getApiPath(resourcePath)}${resourcePath}`, params, options);
|
|
824
|
+
}
|
|
825
|
+
return this.http.get(url, { ...{ params }, ...options });
|
|
826
|
+
}
|
|
827
|
+
patch(resourcePath, id, data, options) {
|
|
828
|
+
const url = `${this.getApiPath(resourcePath)}${resourcePath}${id ? '/' : ''}${id || ''}`;
|
|
829
|
+
return this.http.patch(url, data, options);
|
|
830
|
+
}
|
|
831
|
+
post(resourcePath, data, options) {
|
|
832
|
+
const url = `${this.getApiPath(resourcePath)}${resourcePath}`;
|
|
833
|
+
return this.http.post(url, data, options);
|
|
834
|
+
}
|
|
835
|
+
put(resourcePath, id, data) {
|
|
836
|
+
const url = `${this.getApiPath(resourcePath)}${resourcePath}${id ? '/' : ''}${id || ''}`;
|
|
837
|
+
return this.http.put(url, data);
|
|
838
|
+
}
|
|
839
|
+
getApiPath(resourcePath) {
|
|
840
|
+
return this.isAbsoluteUrl(resourcePath) ? '' : `${this.options.get().restApiPath}/`;
|
|
841
|
+
}
|
|
842
|
+
isAbsoluteUrl(resourcePath) {
|
|
843
|
+
//const expression = /[-a-zA-Z0-9@:%._~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_.~#?&//=]*)?/gi;
|
|
844
|
+
const expression = /^(https?:\/\/)/i;
|
|
845
|
+
const regex = new RegExp(expression);
|
|
846
|
+
return regex.test(resourcePath);
|
|
847
|
+
}
|
|
848
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.6", ngImport: i0, type: RestService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
849
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.6", ngImport: i0, type: RestService, providedIn: 'root' });
|
|
850
|
+
}
|
|
851
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.6", ngImport: i0, type: RestService, decorators: [{
|
|
852
|
+
type: Injectable,
|
|
853
|
+
args: [{
|
|
854
|
+
providedIn: 'root'
|
|
855
|
+
}]
|
|
856
|
+
}] });
|
|
281
857
|
|
|
282
858
|
class StorageService {
|
|
859
|
+
platformId;
|
|
860
|
+
//TODO: Replace with Map object it is more efficient
|
|
861
|
+
memoryStorage;
|
|
283
862
|
constructor(platformId) {
|
|
284
863
|
this.platformId = platformId;
|
|
285
864
|
}
|
|
@@ -353,18 +932,18 @@ class StorageService {
|
|
|
353
932
|
}
|
|
354
933
|
}
|
|
355
934
|
}
|
|
356
|
-
static
|
|
357
|
-
static
|
|
935
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.6", ngImport: i0, type: StorageService, deps: [{ token: PLATFORM_ID }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
936
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.6", ngImport: i0, type: StorageService, providedIn: 'root' });
|
|
358
937
|
}
|
|
359
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
938
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.6", ngImport: i0, type: StorageService, decorators: [{
|
|
360
939
|
type: Injectable,
|
|
361
940
|
args: [{
|
|
362
|
-
providedIn: 'root'
|
|
941
|
+
providedIn: 'root',
|
|
363
942
|
}]
|
|
364
|
-
}], ctorParameters:
|
|
943
|
+
}], ctorParameters: () => [{ type: Object, decorators: [{
|
|
365
944
|
type: Inject,
|
|
366
945
|
args: [PLATFORM_ID]
|
|
367
|
-
}] }]
|
|
946
|
+
}] }] });
|
|
368
947
|
|
|
369
948
|
function lengthValidator(number, digits) {
|
|
370
949
|
let value = true;
|
|
@@ -549,13 +1128,9 @@ function identificationValidator(type) {
|
|
|
549
1128
|
};
|
|
550
1129
|
}
|
|
551
1130
|
|
|
552
|
-
/*
|
|
553
|
-
* Public API Surface of utils
|
|
554
|
-
*/
|
|
555
|
-
|
|
556
1131
|
/**
|
|
557
1132
|
* Generated bundle index. Do not edit.
|
|
558
1133
|
*/
|
|
559
1134
|
|
|
560
|
-
export { ColorService, FilesService, GoogleTagManagerService, StorageService, getIdentificationType, identificationValidator };
|
|
1135
|
+
export { ArrayService, ColorService, ConfigDefaults, CsvConfigConsts, CsvService, DateService, FilesService, GoogleTagManagerService, GraphqlService, ObjectService, RestService, StorageService, StringService, apolloOptionsFactory, getIdentificationType, graphqlProvider, identificationValidator };
|
|
561
1136
|
//# sourceMappingURL=factor_ec-utils.mjs.map
|