@wooksjs/event-http 0.6.1 → 0.6.2

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/dist/index.cjs CHANGED
@@ -338,24 +338,393 @@ let EHttpStatusCode = /* @__PURE__ */ function(EHttpStatusCode$1) {
338
338
  return EHttpStatusCode$1;
339
339
  }({});
340
340
 
341
+ //#endregion
342
+ //#region packages/event-http/src/errors/403.tl.svg
343
+ function _403_tl_default(ctx) {
344
+ return `<svg height="64" viewBox="0 4 100 96" fill="none" xmlns="http://www.w3.org/2000/svg" stroke="#888888" stroke-width="2">
345
+ <path d="M50 90.625C64.4042 87.1875 83.5751 69.8667 83.5751 48.6937V24.0854L50 9.375L16.425 24.0833V48.6937C16.425 69.8667 35.5959 87.1875 50 90.625Z" fill="#ff000050">
346
+ <animate attributeName="fill" dur="2s" repeatCount="indefinite"
347
+ values="#ff000000;#ff000050;#ff000000" />
348
+ </path>
349
+
350
+ <path d="M61.5395 46.0812H38.4604C37.1061 46.0812 36.0083 47.1791 36.0083 48.5333V65.075C36.0083 66.4292 37.1061 67.5271 38.4604 67.5271H61.5395C62.8938 67.5271 63.9916 66.4292 63.9916 65.075V48.5333C63.9916 47.1791 62.8938 46.0812 61.5395 46.0812Z" />
351
+
352
+ <path d="M41.7834 46.0834V39.6813C41.7834 37.5021 42.6491 35.4121 44.1901 33.8712C45.731 32.3303 47.8209 31.4646 50.0001 31.4646C52.1793 31.4646 54.2693 32.3303 55.8102 33.8712C57.3511 35.4121 58.2168 37.5021 58.2168 39.6813V46.0813" />
353
+ </svg>
354
+ `;
355
+ }
356
+
357
+ //#endregion
358
+ //#region packages/event-http/src/errors/404.tl.svg
359
+ function _404_tl_default(ctx) {
360
+ return `<svg height="64" viewBox="0 20 100 64" fill="none" xmlns="http://www.w3.org/2000/svg">
361
+ <defs>
362
+ <path id="sheet" d="M86.5 36.5V47.5H97.5V92.5H52.5V36.5H86.5ZM63 68.5H87V67.5H63V68.5ZM63 63.5H87V62.5H63V63.5ZM63 58.5H87V57.5H63V58.5ZM96.793 46.5H87.5V37.207L96.793 46.5Z" fill="#88888833" stroke="#888888aa"/>
363
+ </defs>
364
+
365
+ <g id="queue" transform="translate(-5 -10)">
366
+ <use href="#sheet" opacity="0">
367
+ <animateTransform attributeName="transform" type="translate"
368
+ dur="3s" repeatCount="indefinite"
369
+ keyTimes="0;0.1;0.32;0.42;1"
370
+ values="30 0; -20 0; -20 0; -70 0; -70 0" />
371
+ <animate attributeName="opacity"
372
+ dur="3s" repeatCount="indefinite"
373
+ keyTimes="0;0.1;0.32;0.42;1"
374
+ values="0;1;1;0;0" />
375
+ </use>
376
+
377
+ <use href="#sheet" opacity="0">
378
+ <animateTransform attributeName="transform" type="translate"
379
+ dur="3s" begin="1s" repeatCount="indefinite"
380
+ keyTimes="0;0.1;0.32;0.42;1"
381
+ values="30 0; -20 0; -20 0; -70 0; -70 0" />
382
+ <animate attributeName="opacity"
383
+ dur="3s" begin="1s" repeatCount="indefinite"
384
+ keyTimes="0;0.1;0.32;0.42;1"
385
+ values="0;1;1;0;0" />
386
+ </use>
387
+
388
+ <use href="#sheet" opacity="0">
389
+ <animateTransform attributeName="transform" type="translate"
390
+ dur="3s" begin="2s" repeatCount="indefinite"
391
+ keyTimes="0;0.1;0.32;0.42;1"
392
+ values="30 0; -20 0; -20 0; -70 0; -70 0" />
393
+ <animate attributeName="opacity"
394
+ dur="3s" begin="2s" repeatCount="indefinite"
395
+ keyTimes="0;0.1;0.32;0.42;1"
396
+ values="0;1;1;0;0" />
397
+ </use>
398
+ </g>
399
+
400
+ <g>
401
+ <path d="M49.5 32.5C58.3366 32.5 65.5 39.6634 65.5 48.5C65.5 54.4781 62.222 59.6923 57.3584 62.4404C55.0386 63.7512 52.3591 64.5 49.5 64.5C40.6634 64.5 33.5 57.3366 33.5 48.5C33.5 39.6634 40.6634 32.5 49.5 32.5Z" fill="#ffffff50" stroke="#888888" stroke-width="3"/>
402
+
403
+ <path d="M62.7101 74.5691C63.117 75.2907 64.0318 75.5459 64.7534 75.139C65.4751 74.7321 65.7302 73.8173 65.3233 73.0957L62.7101 74.5691ZM58.05 63.25L56.7434 63.9867L62.7101 74.5691L64.0167 73.8324L65.3233 73.0957L59.3567 62.5133L58.05 63.25Z" fill="#888888"/>
404
+ </g>
405
+ </svg>
406
+
407
+ `;
408
+ }
409
+
410
+ //#endregion
411
+ //#region packages/event-http/src/errors/500.tl.svg
412
+ function _500_tl_default(ctx) {
413
+ return `<svg height="64" viewBox="0 0 120 100" xmlns="http://www.w3.org/2000/svg">
414
+
415
+ <g id="server">
416
+
417
+ <g fill="#88888888" stroke="#88888888" stroke-width="2" >
418
+ <path d="M18 90C13.5817 90 10 86.4182 10 82V38C10 33.5817 13.5817 30 18 30H50.5L58 43L52.5 53L56 68.5L49.0098 89.97L61.2141 71.4358L58.363 54.315L64.7769 43.5511L58.2763 30.2943L104.243 32.0434C108.658 32.2114 112.101 35.9267 111.933 40.3418L110.26 84.31C110.092 88.725 106.377 92.168 101.962 92L49 90H18Z" />
419
+ </g>
420
+ <circle cx="30" cy="60" r="6" fill="red">
421
+ <animate attributeName="fill" dur="0.8s"
422
+ values="red;#2d0000;red" repeatCount="indefinite"/>
423
+ </circle>
424
+
425
+ </g>
426
+
427
+ <g fill="lightgray" opacity="0.75">
428
+ <circle cx="50" cy="35" r="6">
429
+ <animate attributeName="cy" from="35" to="15" dur="2s"
430
+ repeatCount="indefinite"/>
431
+ <animate attributeName="opacity" values="0.75;0" dur="2s"
432
+ repeatCount="indefinite"/>
433
+ </circle>
434
+ <circle cx="60" cy="40" r="4">
435
+ <animate attributeName="cy" from="40" to="20" dur="2s"
436
+ begin="0.4s" repeatCount="indefinite"/>
437
+ <animate attributeName="opacity" values="0.75;0" dur="2s"
438
+ begin="0.4s" repeatCount="indefinite"/>
439
+ </circle>
440
+ </g>
441
+
442
+ </svg>
443
+ `;
444
+ }
445
+
446
+ //#endregion
447
+ //#region packages/event-http/src/errors/error.tl.html
448
+ function error_tl_default(ctx) {
449
+ const { statusCode, statusMessage, icon, message, details, link, image, version } = ctx;
450
+ return `<!doctype html>
451
+ <html lang="en">
452
+ <head>
453
+ <meta charset="UTF-8" />
454
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
455
+ <title>${statusCode} ${statusMessage}</title>
456
+ <style>
457
+ body {
458
+ font-family: -apple-system, BlinkMacMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu,
459
+ Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
460
+ display: flex;
461
+ justify-content: center;
462
+ align-items: flex-start;
463
+ min-height: 100vh;
464
+ margin: 0;
465
+ padding: 0 20px;
466
+ box-sizing: border-box;
467
+ transition:
468
+ background-color 0.3s ease,
469
+ color 0.3s ease;
470
+ }
471
+
472
+ .error-container {
473
+ padding: 48px;
474
+ padding-bottom: 12px !important;
475
+ background-color: #ffffff;
476
+ border-radius: 0 0 12px 12px;
477
+ box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
478
+ text-align: center;
479
+ max-width: 650px;
480
+ width: 100%;
481
+ transition:
482
+ background-color 0.3s ease,
483
+ border-color 0.3s ease,
484
+ box-shadow 0.3s ease;
485
+ }
486
+
487
+ .status-code {
488
+ font-size: 5rem;
489
+ font-weight: 900;
490
+ margin-bottom: 5px;
491
+ line-height: 1;
492
+ transition: color 0.3s ease;
493
+ display: flex;
494
+ align-items: center;
495
+ justify-content: center;
496
+ gap: 1rem;
497
+ position: relative;
498
+ margin-right: 24px;
499
+ }
500
+
501
+ .status-text {
502
+ font-size: 2.25rem;
503
+ font-weight: 700;
504
+ margin-bottom: 25px;
505
+ transition: color 0.3s ease;
506
+ }
507
+
508
+ .error-message {
509
+ font-size: 1.25rem;
510
+ margin-bottom: 40px;
511
+ line-height: 1.7;
512
+ transition: color 0.3s ease;
513
+ }
514
+
515
+ .json-details-container {
516
+ padding: 20px;
517
+ border-radius: 8px;
518
+ text-align: left;
519
+ overflow-x: auto;
520
+ font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
521
+ font-size: 0.9rem;
522
+ border: 1px solid;
523
+ transition:
524
+ background-color 0.3s ease,
525
+ color 0.3s ease,
526
+ border-color 0.3s ease;
527
+ }
528
+
529
+ .json-details-container pre {
530
+ margin: 0;
531
+ white-space: pre-wrap;
532
+ word-break: break-all;
533
+ }
534
+
535
+ .json-details-container code {
536
+ display: block;
537
+ }
538
+
539
+ body {
540
+ background-color: #f8fafc;
541
+ color: #1f2937;
542
+ }
543
+ .error-container {
544
+ background-color: #ffffff;
545
+ box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
546
+ }
547
+ .status-code {
548
+ color: #dc2626;
549
+ }
550
+ .status-text {
551
+ color: #1f2937;
552
+ }
553
+ .error-message {
554
+ color: #4b5563;
555
+ }
556
+ .json-details-container {
557
+ background-color: #f0f4f8;
558
+ color: #374151;
559
+ border-color: #d1d5db;
560
+ }
561
+ .json-details-container p {
562
+ color: #6b7280;
563
+ }
564
+
565
+ @media (prefers-color-scheme: dark) {
566
+ body {
567
+ background-color: #2d3748;
568
+ color: #e2e8f0;
569
+ }
570
+ .error-container {
571
+ background-color: #1a202c;
572
+ box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
573
+ }
574
+ .status-code {
575
+ color: #f56565;
576
+ }
577
+ .status-text {
578
+ color: #cbd5e1;
579
+ }
580
+ .error-message {
581
+ color: #a0aec0;
582
+ }
583
+ .json-details-container {
584
+ background-color: #2d3748;
585
+ color: #e2e8f0;
586
+ border-color: #4a5568;
587
+ }
588
+ .json-details-container p {
589
+ color: #a0aec0;
590
+ }
591
+ }
592
+
593
+ .footer {
594
+ display: flex;
595
+ gap: 0.25rem;
596
+ font-size: 0.6em;
597
+ justify-content: flex-end;
598
+ align-items: center;
599
+ margin-top: 12px;
600
+ opacity: 0.5;
601
+ transition: 0.25s ease-in-out;
602
+ }
603
+
604
+ .footer img {
605
+ filter: grayscale(0.5);
606
+ transition: 0.25s ease-in-out;
607
+ }
608
+
609
+ .footer:hover {
610
+ opacity: 1;
611
+ }
612
+ .footer:hover img {
613
+ filter: grayscale(0);
614
+ }
615
+
616
+ @media (max-width: 768px) {
617
+ body {
618
+ padding: 15px;
619
+ }
620
+ .error-container {
621
+ padding: 32px;
622
+ }
623
+ .status-code {
624
+ font-size: 4rem;
625
+ }
626
+ .status-text {
627
+ font-size: 1.8rem;
628
+ }
629
+ .error-message {
630
+ font-size: 1.1rem;
631
+ margin-bottom: 30px;
632
+ }
633
+ .json-details-container {
634
+ font-size: 0.85rem;
635
+ }
636
+ }
637
+
638
+ @media (max-width: 480px) {
639
+ body {
640
+ padding: 10px;
641
+ }
642
+ .error-container {
643
+ padding: 24px;
644
+ border-radius: 8px;
645
+ }
646
+ .status-code {
647
+ font-size: 3rem;
648
+ }
649
+ .status-text {
650
+ font-size: 1.5rem;
651
+ margin-bottom: 20px;
652
+ }
653
+ .error-message {
654
+ font-size: 1rem;
655
+ margin-bottom: 25px;
656
+ }
657
+ .json-details-container {
658
+ padding: 15px;
659
+ font-size: 0.8rem;
660
+ }
661
+ }
662
+ </style>
663
+ </head>
664
+ <body>
665
+ <div class="error-container">
666
+ <div id="statusCode" class="status-code">${icon} ${statusCode}</div>
667
+
668
+ <div id="statusText" class="status-text">${statusMessage}</div>
669
+
670
+ <p id="errorMessage" class="error-message">${message}</p>
671
+
672
+ <!-- prettier-ignore -->
673
+ <div class="json-details-container"style="display: ${details ? "block" : "none"};">
674
+ <p class="text-sm">Technical Details:</p>
675
+ <pre><code id="jsonDetails">${details}</code></pre>
676
+ </div>
677
+ <div class="footer">
678
+ Powered by
679
+ <a href="${link}" target="_blank">
680
+ <img height="20" alt="%{poweredBy}" src="${image}" />
681
+ </a>
682
+ v${version}
683
+ </div>
684
+ </div>
685
+ </body>
686
+ </html>
687
+ `;
688
+ }
689
+
341
690
  //#endregion
342
691
  //#region packages/event-http/src/errors/error-renderer.ts
343
- const preStyles = "font-family: monospace;width: 100%;max-width: 900px;padding: 10px;margin: 20px auto;border-radius: 8px;background-color: #494949;box-shadow: 0px 0px 3px 2px rgb(255 255 255 / 20%);";
692
+ let framework = {
693
+ version: "0.6.1",
694
+ poweredBy: `wooksjs`,
695
+ link: `https://wooks.moost.org/`,
696
+ image: `https://wooks.moost.org/wooks-full-logo.png`
697
+ };
344
698
  var HttpErrorRenderer = class extends BaseHttpResponseRenderer {
699
+ constructor(opts) {
700
+ super();
701
+ this.opts = opts;
702
+ }
703
+ icons = {
704
+ 401: typeof _403_tl_default === "function" ? _403_tl_default({}) : "",
705
+ 403: typeof _403_tl_default === "function" ? _403_tl_default({}) : "",
706
+ 404: typeof _404_tl_default === "function" ? _404_tl_default({}) : "",
707
+ 500: typeof _500_tl_default === "function" ? _500_tl_default({}) : ""
708
+ };
709
+ static registerFramework(opts) {
710
+ framework = opts;
711
+ }
345
712
  renderHtml(response) {
346
713
  const data = response.body || {};
347
714
  response.setContentType("text/html");
348
- const keys = Object.keys(data).filter((key) => ![
349
- "statusCode",
350
- "error",
351
- "message"
352
- ].includes(key));
353
- return `<html style="background-color: #333; color: #bbb;"><head><title>${data.statusCode} ${httpStatusCodes[data.statusCode]}</title></head><body><center><h1>${data.statusCode} ${httpStatusCodes[data.statusCode]}</h1></center><center><h4>${data.message}</h1></center><hr color="#666"><center style="color: #666;"> Wooks v0.6.0 </center>${keys.length > 0 ? `<pre style="${preStyles}">${JSON.stringify({
354
- ...data,
355
- statusCode: void 0,
356
- message: void 0,
357
- error: void 0
358
- }, null, " ")}</pre>` : ""}</body></html>`;
715
+ const hasDetails = Object.keys(data).length > 3;
716
+ const icon = data.statusCode >= 500 ? this.icons[500] : this.icons[data.statusCode] || "";
717
+ return typeof error_tl_default === "function" ? error_tl_default({
718
+ icon,
719
+ statusCode: data.statusCode,
720
+ statusMessage: httpStatusCodes[data.statusCode],
721
+ message: data.message,
722
+ details: hasDetails ? JSON.stringify(data, null, " ") : "",
723
+ version: (this.opts || framework).version,
724
+ poweredBy: (this.opts || framework).poweredBy,
725
+ link: (this.opts || framework).link,
726
+ image: (this.opts || framework).image
727
+ }) : JSON.stringify(data, null, " ");
359
728
  }
360
729
  renderText(response) {
361
730
  const data = response.body || {};
package/dist/index.d.ts CHANGED
@@ -394,6 +394,30 @@ interface TWooksErrorBodyExt extends TWooksErrorBody {
394
394
  }
395
395
 
396
396
  declare class HttpErrorRenderer extends BaseHttpResponseRenderer<TWooksErrorBodyExt> {
397
+ protected opts?: {
398
+ version: string;
399
+ poweredBy: string;
400
+ link: string;
401
+ image: string;
402
+ } | undefined;
403
+ constructor(opts?: {
404
+ version: string;
405
+ poweredBy: string;
406
+ link: string;
407
+ image: string;
408
+ } | undefined);
409
+ protected icons: {
410
+ 401: string;
411
+ 403: string;
412
+ 404: string;
413
+ 500: string;
414
+ };
415
+ static registerFramework(opts: {
416
+ version: string;
417
+ poweredBy: string;
418
+ link: string;
419
+ image: string;
420
+ }): void;
397
421
  renderHtml(response: BaseHttpResponse<TWooksErrorBodyExt>): string;
398
422
  renderText(response: BaseHttpResponse<TWooksErrorBodyExt>): string;
399
423
  renderJson(response: BaseHttpResponse<TWooksErrorBodyExt>): string;
package/dist/index.mjs CHANGED
@@ -315,24 +315,393 @@ let EHttpStatusCode = /* @__PURE__ */ function(EHttpStatusCode$1) {
315
315
  return EHttpStatusCode$1;
316
316
  }({});
317
317
 
318
+ //#endregion
319
+ //#region packages/event-http/src/errors/403.tl.svg
320
+ function _403_tl_default(ctx) {
321
+ return `<svg height="64" viewBox="0 4 100 96" fill="none" xmlns="http://www.w3.org/2000/svg" stroke="#888888" stroke-width="2">
322
+ <path d="M50 90.625C64.4042 87.1875 83.5751 69.8667 83.5751 48.6937V24.0854L50 9.375L16.425 24.0833V48.6937C16.425 69.8667 35.5959 87.1875 50 90.625Z" fill="#ff000050">
323
+ <animate attributeName="fill" dur="2s" repeatCount="indefinite"
324
+ values="#ff000000;#ff000050;#ff000000" />
325
+ </path>
326
+
327
+ <path d="M61.5395 46.0812H38.4604C37.1061 46.0812 36.0083 47.1791 36.0083 48.5333V65.075C36.0083 66.4292 37.1061 67.5271 38.4604 67.5271H61.5395C62.8938 67.5271 63.9916 66.4292 63.9916 65.075V48.5333C63.9916 47.1791 62.8938 46.0812 61.5395 46.0812Z" />
328
+
329
+ <path d="M41.7834 46.0834V39.6813C41.7834 37.5021 42.6491 35.4121 44.1901 33.8712C45.731 32.3303 47.8209 31.4646 50.0001 31.4646C52.1793 31.4646 54.2693 32.3303 55.8102 33.8712C57.3511 35.4121 58.2168 37.5021 58.2168 39.6813V46.0813" />
330
+ </svg>
331
+ `;
332
+ }
333
+
334
+ //#endregion
335
+ //#region packages/event-http/src/errors/404.tl.svg
336
+ function _404_tl_default(ctx) {
337
+ return `<svg height="64" viewBox="0 20 100 64" fill="none" xmlns="http://www.w3.org/2000/svg">
338
+ <defs>
339
+ <path id="sheet" d="M86.5 36.5V47.5H97.5V92.5H52.5V36.5H86.5ZM63 68.5H87V67.5H63V68.5ZM63 63.5H87V62.5H63V63.5ZM63 58.5H87V57.5H63V58.5ZM96.793 46.5H87.5V37.207L96.793 46.5Z" fill="#88888833" stroke="#888888aa"/>
340
+ </defs>
341
+
342
+ <g id="queue" transform="translate(-5 -10)">
343
+ <use href="#sheet" opacity="0">
344
+ <animateTransform attributeName="transform" type="translate"
345
+ dur="3s" repeatCount="indefinite"
346
+ keyTimes="0;0.1;0.32;0.42;1"
347
+ values="30 0; -20 0; -20 0; -70 0; -70 0" />
348
+ <animate attributeName="opacity"
349
+ dur="3s" repeatCount="indefinite"
350
+ keyTimes="0;0.1;0.32;0.42;1"
351
+ values="0;1;1;0;0" />
352
+ </use>
353
+
354
+ <use href="#sheet" opacity="0">
355
+ <animateTransform attributeName="transform" type="translate"
356
+ dur="3s" begin="1s" repeatCount="indefinite"
357
+ keyTimes="0;0.1;0.32;0.42;1"
358
+ values="30 0; -20 0; -20 0; -70 0; -70 0" />
359
+ <animate attributeName="opacity"
360
+ dur="3s" begin="1s" repeatCount="indefinite"
361
+ keyTimes="0;0.1;0.32;0.42;1"
362
+ values="0;1;1;0;0" />
363
+ </use>
364
+
365
+ <use href="#sheet" opacity="0">
366
+ <animateTransform attributeName="transform" type="translate"
367
+ dur="3s" begin="2s" repeatCount="indefinite"
368
+ keyTimes="0;0.1;0.32;0.42;1"
369
+ values="30 0; -20 0; -20 0; -70 0; -70 0" />
370
+ <animate attributeName="opacity"
371
+ dur="3s" begin="2s" repeatCount="indefinite"
372
+ keyTimes="0;0.1;0.32;0.42;1"
373
+ values="0;1;1;0;0" />
374
+ </use>
375
+ </g>
376
+
377
+ <g>
378
+ <path d="M49.5 32.5C58.3366 32.5 65.5 39.6634 65.5 48.5C65.5 54.4781 62.222 59.6923 57.3584 62.4404C55.0386 63.7512 52.3591 64.5 49.5 64.5C40.6634 64.5 33.5 57.3366 33.5 48.5C33.5 39.6634 40.6634 32.5 49.5 32.5Z" fill="#ffffff50" stroke="#888888" stroke-width="3"/>
379
+
380
+ <path d="M62.7101 74.5691C63.117 75.2907 64.0318 75.5459 64.7534 75.139C65.4751 74.7321 65.7302 73.8173 65.3233 73.0957L62.7101 74.5691ZM58.05 63.25L56.7434 63.9867L62.7101 74.5691L64.0167 73.8324L65.3233 73.0957L59.3567 62.5133L58.05 63.25Z" fill="#888888"/>
381
+ </g>
382
+ </svg>
383
+
384
+ `;
385
+ }
386
+
387
+ //#endregion
388
+ //#region packages/event-http/src/errors/500.tl.svg
389
+ function _500_tl_default(ctx) {
390
+ return `<svg height="64" viewBox="0 0 120 100" xmlns="http://www.w3.org/2000/svg">
391
+
392
+ <g id="server">
393
+
394
+ <g fill="#88888888" stroke="#88888888" stroke-width="2" >
395
+ <path d="M18 90C13.5817 90 10 86.4182 10 82V38C10 33.5817 13.5817 30 18 30H50.5L58 43L52.5 53L56 68.5L49.0098 89.97L61.2141 71.4358L58.363 54.315L64.7769 43.5511L58.2763 30.2943L104.243 32.0434C108.658 32.2114 112.101 35.9267 111.933 40.3418L110.26 84.31C110.092 88.725 106.377 92.168 101.962 92L49 90H18Z" />
396
+ </g>
397
+ <circle cx="30" cy="60" r="6" fill="red">
398
+ <animate attributeName="fill" dur="0.8s"
399
+ values="red;#2d0000;red" repeatCount="indefinite"/>
400
+ </circle>
401
+
402
+ </g>
403
+
404
+ <g fill="lightgray" opacity="0.75">
405
+ <circle cx="50" cy="35" r="6">
406
+ <animate attributeName="cy" from="35" to="15" dur="2s"
407
+ repeatCount="indefinite"/>
408
+ <animate attributeName="opacity" values="0.75;0" dur="2s"
409
+ repeatCount="indefinite"/>
410
+ </circle>
411
+ <circle cx="60" cy="40" r="4">
412
+ <animate attributeName="cy" from="40" to="20" dur="2s"
413
+ begin="0.4s" repeatCount="indefinite"/>
414
+ <animate attributeName="opacity" values="0.75;0" dur="2s"
415
+ begin="0.4s" repeatCount="indefinite"/>
416
+ </circle>
417
+ </g>
418
+
419
+ </svg>
420
+ `;
421
+ }
422
+
423
+ //#endregion
424
+ //#region packages/event-http/src/errors/error.tl.html
425
+ function error_tl_default(ctx) {
426
+ const { statusCode, statusMessage, icon, message, details, link, image, version } = ctx;
427
+ return `<!doctype html>
428
+ <html lang="en">
429
+ <head>
430
+ <meta charset="UTF-8" />
431
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
432
+ <title>${statusCode} ${statusMessage}</title>
433
+ <style>
434
+ body {
435
+ font-family: -apple-system, BlinkMacMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu,
436
+ Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
437
+ display: flex;
438
+ justify-content: center;
439
+ align-items: flex-start;
440
+ min-height: 100vh;
441
+ margin: 0;
442
+ padding: 0 20px;
443
+ box-sizing: border-box;
444
+ transition:
445
+ background-color 0.3s ease,
446
+ color 0.3s ease;
447
+ }
448
+
449
+ .error-container {
450
+ padding: 48px;
451
+ padding-bottom: 12px !important;
452
+ background-color: #ffffff;
453
+ border-radius: 0 0 12px 12px;
454
+ box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
455
+ text-align: center;
456
+ max-width: 650px;
457
+ width: 100%;
458
+ transition:
459
+ background-color 0.3s ease,
460
+ border-color 0.3s ease,
461
+ box-shadow 0.3s ease;
462
+ }
463
+
464
+ .status-code {
465
+ font-size: 5rem;
466
+ font-weight: 900;
467
+ margin-bottom: 5px;
468
+ line-height: 1;
469
+ transition: color 0.3s ease;
470
+ display: flex;
471
+ align-items: center;
472
+ justify-content: center;
473
+ gap: 1rem;
474
+ position: relative;
475
+ margin-right: 24px;
476
+ }
477
+
478
+ .status-text {
479
+ font-size: 2.25rem;
480
+ font-weight: 700;
481
+ margin-bottom: 25px;
482
+ transition: color 0.3s ease;
483
+ }
484
+
485
+ .error-message {
486
+ font-size: 1.25rem;
487
+ margin-bottom: 40px;
488
+ line-height: 1.7;
489
+ transition: color 0.3s ease;
490
+ }
491
+
492
+ .json-details-container {
493
+ padding: 20px;
494
+ border-radius: 8px;
495
+ text-align: left;
496
+ overflow-x: auto;
497
+ font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
498
+ font-size: 0.9rem;
499
+ border: 1px solid;
500
+ transition:
501
+ background-color 0.3s ease,
502
+ color 0.3s ease,
503
+ border-color 0.3s ease;
504
+ }
505
+
506
+ .json-details-container pre {
507
+ margin: 0;
508
+ white-space: pre-wrap;
509
+ word-break: break-all;
510
+ }
511
+
512
+ .json-details-container code {
513
+ display: block;
514
+ }
515
+
516
+ body {
517
+ background-color: #f8fafc;
518
+ color: #1f2937;
519
+ }
520
+ .error-container {
521
+ background-color: #ffffff;
522
+ box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
523
+ }
524
+ .status-code {
525
+ color: #dc2626;
526
+ }
527
+ .status-text {
528
+ color: #1f2937;
529
+ }
530
+ .error-message {
531
+ color: #4b5563;
532
+ }
533
+ .json-details-container {
534
+ background-color: #f0f4f8;
535
+ color: #374151;
536
+ border-color: #d1d5db;
537
+ }
538
+ .json-details-container p {
539
+ color: #6b7280;
540
+ }
541
+
542
+ @media (prefers-color-scheme: dark) {
543
+ body {
544
+ background-color: #2d3748;
545
+ color: #e2e8f0;
546
+ }
547
+ .error-container {
548
+ background-color: #1a202c;
549
+ box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
550
+ }
551
+ .status-code {
552
+ color: #f56565;
553
+ }
554
+ .status-text {
555
+ color: #cbd5e1;
556
+ }
557
+ .error-message {
558
+ color: #a0aec0;
559
+ }
560
+ .json-details-container {
561
+ background-color: #2d3748;
562
+ color: #e2e8f0;
563
+ border-color: #4a5568;
564
+ }
565
+ .json-details-container p {
566
+ color: #a0aec0;
567
+ }
568
+ }
569
+
570
+ .footer {
571
+ display: flex;
572
+ gap: 0.25rem;
573
+ font-size: 0.6em;
574
+ justify-content: flex-end;
575
+ align-items: center;
576
+ margin-top: 12px;
577
+ opacity: 0.5;
578
+ transition: 0.25s ease-in-out;
579
+ }
580
+
581
+ .footer img {
582
+ filter: grayscale(0.5);
583
+ transition: 0.25s ease-in-out;
584
+ }
585
+
586
+ .footer:hover {
587
+ opacity: 1;
588
+ }
589
+ .footer:hover img {
590
+ filter: grayscale(0);
591
+ }
592
+
593
+ @media (max-width: 768px) {
594
+ body {
595
+ padding: 15px;
596
+ }
597
+ .error-container {
598
+ padding: 32px;
599
+ }
600
+ .status-code {
601
+ font-size: 4rem;
602
+ }
603
+ .status-text {
604
+ font-size: 1.8rem;
605
+ }
606
+ .error-message {
607
+ font-size: 1.1rem;
608
+ margin-bottom: 30px;
609
+ }
610
+ .json-details-container {
611
+ font-size: 0.85rem;
612
+ }
613
+ }
614
+
615
+ @media (max-width: 480px) {
616
+ body {
617
+ padding: 10px;
618
+ }
619
+ .error-container {
620
+ padding: 24px;
621
+ border-radius: 8px;
622
+ }
623
+ .status-code {
624
+ font-size: 3rem;
625
+ }
626
+ .status-text {
627
+ font-size: 1.5rem;
628
+ margin-bottom: 20px;
629
+ }
630
+ .error-message {
631
+ font-size: 1rem;
632
+ margin-bottom: 25px;
633
+ }
634
+ .json-details-container {
635
+ padding: 15px;
636
+ font-size: 0.8rem;
637
+ }
638
+ }
639
+ </style>
640
+ </head>
641
+ <body>
642
+ <div class="error-container">
643
+ <div id="statusCode" class="status-code">${icon} ${statusCode}</div>
644
+
645
+ <div id="statusText" class="status-text">${statusMessage}</div>
646
+
647
+ <p id="errorMessage" class="error-message">${message}</p>
648
+
649
+ <!-- prettier-ignore -->
650
+ <div class="json-details-container"style="display: ${details ? "block" : "none"};">
651
+ <p class="text-sm">Technical Details:</p>
652
+ <pre><code id="jsonDetails">${details}</code></pre>
653
+ </div>
654
+ <div class="footer">
655
+ Powered by
656
+ <a href="${link}" target="_blank">
657
+ <img height="20" alt="%{poweredBy}" src="${image}" />
658
+ </a>
659
+ v${version}
660
+ </div>
661
+ </div>
662
+ </body>
663
+ </html>
664
+ `;
665
+ }
666
+
318
667
  //#endregion
319
668
  //#region packages/event-http/src/errors/error-renderer.ts
320
- const preStyles = "font-family: monospace;width: 100%;max-width: 900px;padding: 10px;margin: 20px auto;border-radius: 8px;background-color: #494949;box-shadow: 0px 0px 3px 2px rgb(255 255 255 / 20%);";
669
+ let framework = {
670
+ version: "0.6.1",
671
+ poweredBy: `wooksjs`,
672
+ link: `https://wooks.moost.org/`,
673
+ image: `https://wooks.moost.org/wooks-full-logo.png`
674
+ };
321
675
  var HttpErrorRenderer = class extends BaseHttpResponseRenderer {
676
+ constructor(opts) {
677
+ super();
678
+ this.opts = opts;
679
+ }
680
+ icons = {
681
+ 401: typeof _403_tl_default === "function" ? _403_tl_default({}) : "",
682
+ 403: typeof _403_tl_default === "function" ? _403_tl_default({}) : "",
683
+ 404: typeof _404_tl_default === "function" ? _404_tl_default({}) : "",
684
+ 500: typeof _500_tl_default === "function" ? _500_tl_default({}) : ""
685
+ };
686
+ static registerFramework(opts) {
687
+ framework = opts;
688
+ }
322
689
  renderHtml(response) {
323
690
  const data = response.body || {};
324
691
  response.setContentType("text/html");
325
- const keys = Object.keys(data).filter((key) => ![
326
- "statusCode",
327
- "error",
328
- "message"
329
- ].includes(key));
330
- return `<html style="background-color: #333; color: #bbb;"><head><title>${data.statusCode} ${httpStatusCodes[data.statusCode]}</title></head><body><center><h1>${data.statusCode} ${httpStatusCodes[data.statusCode]}</h1></center><center><h4>${data.message}</h1></center><hr color="#666"><center style="color: #666;"> Wooks v0.6.0 </center>${keys.length > 0 ? `<pre style="${preStyles}">${JSON.stringify({
331
- ...data,
332
- statusCode: void 0,
333
- message: void 0,
334
- error: void 0
335
- }, null, " ")}</pre>` : ""}</body></html>`;
692
+ const hasDetails = Object.keys(data).length > 3;
693
+ const icon = data.statusCode >= 500 ? this.icons[500] : this.icons[data.statusCode] || "";
694
+ return typeof error_tl_default === "function" ? error_tl_default({
695
+ icon,
696
+ statusCode: data.statusCode,
697
+ statusMessage: httpStatusCodes[data.statusCode],
698
+ message: data.message,
699
+ details: hasDetails ? JSON.stringify(data, null, " ") : "",
700
+ version: (this.opts || framework).version,
701
+ poweredBy: (this.opts || framework).poweredBy,
702
+ link: (this.opts || framework).link,
703
+ image: (this.opts || framework).image
704
+ }) : JSON.stringify(data, null, " ");
336
705
  }
337
706
  renderText(response) {
338
707
  const data = response.body || {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wooksjs/event-http",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "description": "@wooksjs/event-http",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
@@ -41,8 +41,8 @@
41
41
  "peerDependencies": {
42
42
  "@prostojs/router": "^0.2.1",
43
43
  "@prostojs/logger": "^0.4.3",
44
- "@wooksjs/event-core": "^0.6.1",
45
- "wooks": "^0.6.1"
44
+ "@wooksjs/event-core": "^0.6.2",
45
+ "wooks": "^0.6.2"
46
46
  },
47
47
  "dependencies": {},
48
48
  "homepage": "https://github.com/wooksjs/wooksjs/tree/main/packages/event-http#readme",