5htp-core 0.6.2-4 → 0.6.2-6

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.
@@ -21,7 +21,7 @@ import type { AnyService } from './service';
21
21
  export { default as Service } from './service';
22
22
 
23
23
  // Resources
24
- import '@client/assets/css/core.less';
24
+ //import '@client/assets/css/core.less';
25
25
 
26
26
  /*----------------------------------
27
27
  - TYPES
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "5htp-core",
3
3
  "description": "Convenient TypeScript framework designed for Performance and Productivity.",
4
- "version": "0.6.2-4",
4
+ "version": "0.6.2-6",
5
5
  "author": "Gaetan Le Gac (https://github.com/gaetanlegac)",
6
6
  "repository": "git://github.com/gaetanlegac/5htp-core.git",
7
7
  "license": "MIT",
@@ -301,45 +301,10 @@ export default class Console {
301
301
  // On envoi l'email avant l'insertion dans bla bdd
302
302
  // Car cette denrière a plus de chances de provoquer une erreur
303
303
  //const logs = this.logs.filter(e => e.channel.channelId === channelId).slice(-100);
304
- const stacktraces: string[] = [];
305
- const context: object[] = [];
306
-
307
- let currentError: TCatchedError | undefined = error;
308
- let title: string | undefined;
309
- while (currentError !== undefined) {
310
-
311
- if (title === undefined)
312
- title = currentError.message;
313
-
314
- // Stacktrace
315
- this.logger.error(LogPrefix, `Sending bug report for the following error:`, currentError);
316
- stacktraces.push(currentError.stack || currentError.message);
317
-
318
- // Context
319
- if (('dataForDebugging' in currentError) && currentError.dataForDebugging !== undefined) {
320
- console.error(LogPrefix, `More data about the error:`, currentError.dataForDebugging);
321
- context.push(currentError.dataForDebugging || {});
322
- }
323
-
324
- // Print the error so it's accessible via logs
325
- if (currentError instanceof SqlError) {
326
- let printedQuery: string;
327
- try {
328
- printedQuery = this.printSql( currentError.query );
329
- } catch (error) {
330
- printedQuery = 'Failed to print query:' + (error || 'unknown error');
331
- }
332
- console.error(`Error caused by this query:`, printedQuery);
333
- }
334
-
335
- // Go deeper
336
- currentError = 'originalError' in currentError
337
- ? currentError.originalError
338
- : undefined
339
- }
304
+ const inspection = this.getDetailledError(error);
340
305
 
341
306
  // Genertae unique error hash
342
- const hash = md5( stacktraces[0] );
307
+ const hash = md5( inspection.stacktraces[0] );
343
308
 
344
309
  // Don't send the same error twice in a row (avoid email spamming)
345
310
  const lastReport = this.reported[hash];
@@ -390,12 +355,56 @@ export default class Console {
390
355
  } : {}),
391
356
 
392
357
  // Error
393
- title,
394
- stacktraces,
395
- context
358
+ title: inspection.title,
359
+ stacktraces: inspection.stacktraces,
360
+ context: inspection.context
396
361
  }
397
362
 
398
363
  await application.runHook('bug', bugReport);
364
+
365
+ return bugReport;
366
+ }
367
+
368
+ public getDetailledError( error: TCatchedError ) {
369
+
370
+ const stacktraces: string[] = [];
371
+ const context: object[] = [];
372
+
373
+ let currentError: TCatchedError | undefined = error;
374
+ let title: string | undefined;
375
+ while (currentError !== undefined) {
376
+
377
+ if (title === undefined)
378
+ title = currentError.message;
379
+
380
+ // Stacktrace
381
+ this.logger.error(LogPrefix, `Sending bug report for the following error:`, currentError);
382
+ stacktraces.push(currentError.stack || currentError.message);
383
+
384
+ // Context
385
+ if (('dataForDebugging' in currentError) && currentError.dataForDebugging !== undefined) {
386
+ console.error(LogPrefix, `More data about the error:`, currentError.dataForDebugging);
387
+ context.push(currentError.dataForDebugging || {});
388
+ }
389
+
390
+ // Print the error so it's accessible via logs
391
+ if (currentError instanceof SqlError) {
392
+ let printedQuery: string;
393
+ try {
394
+ printedQuery = this.printSql( currentError.query );
395
+ } catch (error) {
396
+ printedQuery = 'Failed to print query:' + (error || 'unknown error');
397
+ }
398
+ console.error(`Error caused by this query:`, printedQuery);
399
+ }
400
+
401
+ // Go deeper
402
+ currentError = 'originalError' in currentError
403
+ ? currentError.originalError
404
+ : undefined
405
+ }
406
+
407
+ return { title, stacktraces, context };
399
408
  }
400
409
 
401
410
  public getChannel() {
@@ -416,11 +425,7 @@ export default class Console {
416
425
  <b>User</b>: ${report.user ? (report.user.name + ' (' + report.user.email + ')') : 'Unknown'}<br />
417
426
  <b>IP</b>: ${report.ip}<br />
418
427
 
419
- ${report.stacktraces.map((stacktrace, index) => `
420
- <hr />
421
- <b>Error ${index + 1}</b>:
422
- ${this.printHtml(stacktrace)}<br />
423
- `).join('')}
428
+ ${this.stacktracesToHTML(report.stacktraces)}
424
429
 
425
430
  ${report.context.map((context, index) => `
426
431
  <hr />
@@ -439,6 +444,13 @@ ${report.request ? `
439
444
  Logs: ${this.config.enable ? `<br/>` + this.logsToHTML(report.logs) : 'Logs collection is disabled'}<br />
440
445
  `
441
446
  }
447
+
448
+ public stacktracesToHTML( stacktraces: string[] ): string {
449
+ return stacktraces.map((stacktrace, index) => `
450
+ <hr />
451
+ <b>Stacktrace ${index + 1}</b>: ${this.printHtml(stacktrace)}<br />
452
+ `).join('');
453
+ }
442
454
 
443
455
  public logsToHTML( logs: TJsonLog[] ): string {
444
456
 
@@ -208,8 +208,6 @@ export abstract class Application<
208
208
  ? route.schema.parse( context.request.data )
209
209
  : {};
210
210
 
211
- console.log('-----data', data);
212
-
213
211
  // Run controller
214
212
  return origController.bind( service )(
215
213
  data,
@@ -144,13 +144,16 @@ export default abstract class Service<
144
144
  public use<TService extends AnyService = AnyService>(
145
145
  serviceId: string,
146
146
  useOptions: { optional?: boolean } = {}
147
- ): TService {
147
+ ): TService | undefined {
148
148
 
149
149
  const registeredService = this.app.registered[serviceId];
150
- if (registeredService === undefined && useOptions.optional === false)
150
+ if (registeredService !== undefined)
151
+ return this.app[ registeredService.name ];
152
+
153
+ if (useOptions.optional === false)
151
154
  throw new Error(`Service ${registeredService} not registered.`);
152
155
 
153
- return this.app[ registeredService.name ];
156
+ return undefined;
154
157
  }
155
158
 
156
159
  /*----------------------------------
@@ -137,8 +137,8 @@ export default class DocumentRenderer<TRouter extends Router> {
137
137
 
138
138
  private async scripts( response: ServerResponse<TRouter>, page: Page ) {
139
139
 
140
- const context = safeStringify( response.forSsr(page) );
141
-
140
+ const ssrData = response.forSsr(page);
141
+ const context = safeStringify( ssrData );
142
142
  const routesForClient = JSON.stringify( this.router.ssrRoutes );
143
143
 
144
144
  return <>
package/types/icons.d.ts CHANGED
@@ -1 +1 @@
1
- export type TIcones = "long-arrow-right"|"times"|"solid/spinner-third"|"check-circle"|"coins"|"building"|"at"|"phone"|"bolt"|"brands/linkedin"|"rocket"|"chart-bar"|"user-circle"|"crosshairs"|"plane-departure"|"plus-circle"|"comments-alt"|"arrow-right"|"user-shield"|"shield-alt"|"chart-line"|"money-bill-wave"|"star"|"link"|"file-alt"|"long-arrow-left"|"user-plus"|"paper-plane"|"magnet"|"sack-dollar"|"info-circle"|"mouse-pointer"|"thumbs-up"|"dollar-sign"|"user"|"sun"|"brands/whatsapp"|"play"|"trash"|"plus"|"check"|"clock"|"cog"|"ellipsis-h"|"angle-up"|"angle-down"|"binoculars"|"regular/shield-check"|"calendar-alt"|"search"|"lightbulb"|"solid/crown"|"eye"|"pen"|"file"|"envelope"|"download"|"exclamation-circle"|"times-circle"|"meh-rolling-eyes"|"arrow-left"|"users"|"bug"|"solid/star"|"solid/star-half-alt"|"regular/star"|"chevron-left"|"key"|"power-off"|"bars"|"broom"|"solid/check-circle"|"solid/exclamation-triangle"|"solid/times-circle"|"hourglass"|"question-circle"|"wind"|"minus-circle"|"external-link"|"brands/google"|"coin"|"angle-left"|"angle-right"|"briefcase"|"map-marker-alt"|"graduation-cap"|"plug"|"minus"|"arrow-to-bottom"|"map-marker"|"fire"|"solid/magic"|"globe"|"magic"|"industry"|"calendar"|"bold"|"italic"|"underline"|"strikethrough"|"subscript"|"superscript"|"code"|"unlink"|"font"|"empty-set"|"horizontal-rule"|"page-break"|"image"|"table"|"poll"|"columns"|"sticky-note"|"caret-right"|"align-left"|"align-center"|"align-right"|"align-justify"|"indent"|"outdent"|"list-ul"|"check-square"|"h1"|"h2"|"h3"|"h4"|"list-ol"|"paragraph"|"quote-left"
1
+ export type TIcones = "solid/spinner-third"|"times"|"brands/whatsapp"|"info-circle"|"check-circle"|"exclamation-circle"|"times-circle"|"search"|"check"|"angle-down"|"arrow-left"|"arrow-right"|"meh-rolling-eyes"|"eye"|"trash"|"link"|"file"|"unlink"|"pen"|"bold"|"italic"|"underline"|"strikethrough"|"subscript"|"superscript"|"code"|"plus"|"font"|"empty-set"|"plus-circle"|"horizontal-rule"|"page-break"|"image"|"table"|"poll"|"columns"|"sticky-note"|"caret-right"|"align-left"|"align-center"|"align-right"|"align-justify"|"indent"|"outdent"|"list-ul"|"check-square"|"h1"|"h2"|"h3"|"h4"|"list-ol"|"paragraph"|"quote-left"