Files
doneit-web/src/app/app.module.ts
T

425 lines
14 KiB
TypeScript
Raw Normal View History

2022-12-17 17:46:08 +01:00
import { NgModule, CUSTOM_ELEMENTS_SCHEMA, ErrorHandler } from '@angular/core';
import { BrowserModule, HammerModule } from '@angular/platform-browser';
2020-08-05 15:39:16 +01:00
import { RouteReuseStrategy } from '@angular/router';
import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
2021-02-25 11:50:32 +01:00
import { StatusBar } from '@ionic-native/status-bar/ngx';
2020-08-05 15:39:16 +01:00
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
2023-07-11 17:54:08 +01:00
import { HTTP_INTERCEPTORS, HttpClientModule } from '@angular/common/http';
2020-08-05 15:39:16 +01:00
import { InAppBrowser } from '@ionic-native/in-app-browser/ngx';
import { WebView } from '@ionic-native/ionic-webview/ngx';
import { FilePath } from '@ionic-native/file-path/ngx';
2021-02-09 13:16:41 +01:00
import { Camera } from '@ionic-native/camera/ngx';
import { IonicStorageModule } from '@ionic/storage';
2021-01-22 16:00:37 +01:00
import { CommonModule } from '@angular/common';
2021-06-24 11:47:05 +01:00
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
2021-01-25 16:18:36 +01:00
2021-01-22 16:00:37 +01:00
import { CalendarModule, DateAdapter } from 'angular-calendar';
import { adapterFactory } from 'angular-calendar/date-adapters/date-fns';
2021-07-08 10:43:40 +01:00
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
2021-06-17 13:58:56 +01:00
import {MatDatepickerModule} from '@angular/material/datepicker';
2022-10-12 17:32:13 +01:00
import {MAT_DATE_LOCALE} from '@angular/material/core';
import { Network } from '@ionic-native/network/ngx';
2022-03-25 09:25:05 +01:00
import { MultipleDocumentsPicker } from '@awesome-cordova-plugins/multiple-document-picker/ngx';
import { DocumentViewer } from '@awesome-cordova-plugins/document-viewer/ngx';
2024-03-01 14:37:42 +01:00
import { FFMpeg } from '@awesome-cordova-plugins/ffmpeg/ngx';
2024-05-17 15:27:02 +01:00
import { FFmpeg } from '@ffmpeg/ffmpeg';
2021-11-29 15:48:35 +01:00
2021-06-24 11:08:17 +01:00
2021-04-08 11:27:53 +01:00
2021-06-18 12:02:14 +01:00
import {
NgxMatDatetimePickerModule,
NgxMatNativeDateModule,
NgxMatTimepickerModule
2021-06-18 12:02:14 +01:00
} from '@angular-material-components/datetime-picker';
2021-06-24 11:08:17 +01:00
import { MatDialogModule } from '@angular/material/dialog';
import { MatSelectModule } from '@angular/material/select';
2021-06-24 11:47:05 +01:00
import { NgxMatMomentModule } from '@angular-material-components/moment-adapter';
import { MatButtonModule } from '@angular/material/button';
2021-07-08 11:07:40 +01:00
import { HttpClient } from '@angular/common/http';
2020-09-10 09:48:37 +01:00
2021-08-04 10:47:22 +01:00
import { FontAwesomeModule, FaIconLibrary } from '@fortawesome/angular-fontawesome';
import { fas } from '@fortawesome/free-solid-svg-icons'
import { far } from '@fortawesome/free-regular-svg-icons'
import { fab } from '@fortawesome/free-brands-svg-icons'
2021-08-17 09:53:06 +01:00
import { ScreenOrientation } from '@ionic-native/screen-orientation/ngx';
2021-09-21 06:09:41 +01:00
import { SQLite } from '@ionic-native/sqlite/ngx';
2021-10-15 15:21:26 +01:00
import { CookieService } from 'ngx-cookie-service';
2021-08-25 16:02:40 +01:00
2021-11-16 16:00:14 +01:00
import { ImagePicker } from '@ionic-native/image-picker/ngx';
import { MediaCapture } from '@awesome-cordova-plugins/media-capture/ngx';
2021-11-16 16:00:14 +01:00
import { Media } from '@ionic-native/media/ngx';
2022-04-04 01:14:16 +01:00
import { File } from '@awesome-cordova-plugins/file/ngx';
2022-03-18 11:45:38 +01:00
2021-11-16 16:00:14 +01:00
import { StreamingMedia } from '@ionic-native/streaming-media/ngx';
import { PhotoViewer } from '@ionic-native/photo-viewer/ngx';
2021-11-26 14:46:08 +01:00
import {NgxImageCompressService} from 'ngx-image-compress';
2021-11-30 10:23:46 +01:00
import { CustomImageCachePageRoutingModule } from './services/file/custom-image-cache/custom-image-cache-routing.module';
2024-10-24 10:50:46 +01:00
import { IonicImageLoaderModule } from 'ionic-image-loader-v5';
2022-04-04 00:37:00 +01:00
import { NgxExtendedPdfViewerModule } from 'ngx-extended-pdf-viewer';
2022-04-04 01:14:16 +01:00
import { FileOpener } from '@awesome-cordova-plugins/file-opener/ngx';
2023-04-13 12:51:38 +01:00
import { MatInputModule } from '@angular/material/input';
import { MatNativeDateModule } from '@angular/material/core';
2025-09-17 18:37:35 +01:00
import * as SentrySibling from '@sentry/angular';
2023-06-26 11:12:57 +01:00
import { AngularFireModule } from '@angular/fire';
import { AngularFireMessagingModule } from '@angular/fire/messaging';
import { firebaseConfig } from '../firebase-config';
2024-02-29 09:40:51 +01:00
import { EditorModule } from '@tinymce/tinymce-angular';;
2023-07-14 18:57:07 +01:00
import { CreateProcessPageModule } from './modals/create-process/create-process.module';
import { CreateProcessPage } from './modals/create-process/create-process.page';
2023-07-11 17:54:08 +01:00
import { LoggingInterceptorService } from './services/logging-interceptor.service';
2023-09-22 15:17:25 +01:00
import { PopupQuestionPipe } from './modals/popup-question.pipe';
import '@teamhive/capacitor-video-recorder';
2025-06-03 09:42:08 +01:00
import { tokenInterceptor } from './infra/monitoring/interceptors/token.interceptors';
2023-11-10 14:58:33 +01:00
import { InputFilterDirective } from './services/directives/input-filter.directive';
2024-02-29 09:40:51 +01:00
import { DeplomaOptionsPageModule } from './shared/popover/deploma-options/deploma-options.module';
import { DiplomaOptionsPage } from './shared/popover/deploma-options/deploma-options.page';
import { ImageCropperModule } from 'ngx-image-cropper';
2025-06-03 09:42:08 +01:00
import { metricsInterceptor } from './infra/monitoring/interceptors/metter.interceptor';
import {MatMenuModule} from '@angular/material/menu';
import {MatIconModule} from '@angular/material/icon';
2024-08-07 15:23:23 +01:00
import { ChatModule } from './module/chat/chat.module';
2024-09-05 15:42:53 +01:00
import { registerLocaleData } from '@angular/common';
import localePt from '@angular/common/locales/pt';
2024-11-06 09:13:36 +01:00
import { UserModule } from './module/user/user.module';
2025-09-11 11:20:44 +01:00
import { Logger } from './services/logger/main/service';
2021-11-16 16:00:14 +01:00
2024-09-05 15:42:53 +01:00
registerLocaleData(localePt, 'pt');
2025-09-17 18:37:35 +01:00
import * as Sentry from '@sentry/capacitor';
import { Integration } from '@sentry/types';
import { BrowserTracing } from '@sentry/tracing';
import { LogsDatabase } from './infra/database/dexie/instance/logs/service';
import { AppErrorHandler } from './infra/crash-analytics/app-error-handler';
2021-11-16 16:00:14 +01:00
2025-09-11 11:20:44 +01:00
// Sentry.init(
// {
// dsn: 'https://5b345a3ae70b4e4da463da65881b4aaa@o4504340905525248.ingest.sentry.io/4504345615794176',
// // To set your release and dist versions
// release: 'gabinetedigital@1.0.0',
// dist: '1',
// // Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
// // We recommend adjusting this value in production.
// tracesSampleRate: 1.0,
2025-09-17 18:37:35 +01:00
// debug: true, // logs to console
2025-09-11 11:20:44 +01:00
// beforeSend(event) {
// console.log('event.exception.values[0].value', event.exception.values[0].value);
// if (event.level === 'error') {
// LogsDatabase.sentryError.add(event as any).then(() => {
// console.log('event', event)
// })
2025-09-17 18:37:35 +01:00
// // openTelemetryLogging.send({
// // level: 'info',
// // message: event.exception.values[0].value,
// // payload: {
// // object: {
// // sentry: true,
// // error: event
// // }
// // },
// // })
2025-09-11 11:20:44 +01:00
// }
// // Return event to send it to Sentry
// return event;
// },
// }
// );
(function () {
const httpLogs = [];
// --- Patch fetch ---
const originalFetch = window.fetch;
window.fetch = async (input, config = {}) => {
const url = typeof input === "string" ? input : (input as any).url;
const method = config?.method || "GET";
// Capture tracer header
let tracerHeader = null;
if (config?.headers) {
if (config.headers instanceof Headers) {
tracerHeader = config.headers.get("x-tracer");
} else if (typeof config.headers === "object") {
tracerHeader = config.headers["x-tracer"] || config.headers["X-Tracer"];
}
}
// Capture request body (payload)
let requestPayload = null;
if (config?.body) {
try {
2025-09-17 18:37:35 +01:00
if (typeof config.body === "string") {
requestPayload = config.body;
} else if (config.body !== null && typeof config.body === "object") {
// Keep plain objects/arrays as-is
requestPayload = config.body;
} else {
// For other cases (like FormData, Blob, etc.), attempt safe stringify
requestPayload = JSON.stringify(config.body);
}
2025-09-11 11:20:44 +01:00
} catch {
requestPayload = "[Unserializable body]";
}
}
const start = Date.now();
try {
const response = await originalFetch(input, config);
// Clone response so we dont consume it
const clone = response.clone();
let responsePayload = null;
try {
const contentType = clone.headers.get("content-type") || "";
if (contentType.includes("application/json")) {
responsePayload = await clone.json();
} else if (contentType.includes("text")) {
responsePayload = await clone.text();
} else {
responsePayload = "[Non-textual body]";
}
} catch {
responsePayload = "[Unserializable response]";
}
const log = {
type: "fetch",
url,
method,
status: response.status,
xTracer: tracerHeader,
requestPayload,
responsePayload,
duration: Date.now() - start,
timestamp: new Date().toISOString(),
};
if(response.status >= 400 || response.status === 0) {
Logger.error('XHR', log)
}
httpLogs.push(log);
return response;
} catch (error) {
const log = {
type: "fetch",
url,
method,
status: "NETWORK_ERROR",
xTracer: tracerHeader,
requestPayload,
responsePayload: null,
duration: Date.now() - start,
timestamp: new Date().toISOString(),
};
if(!url.includes('petermaquiran.xyz') && url != "") {
Logger.error('XHR', log);
}
httpLogs.push(log);
throw error;
2024-08-19 16:01:58 +01:00
}
2025-09-11 11:20:44 +01:00
};
// --- Patch XMLHttpRequest ---
const OriginalXHR = window.XMLHttpRequest;
function CustomXHR() {
const xhr: any = new OriginalXHR();
const start = Date.now();
xhr._xTracer = null;
xhr._requestPayload = null;
const originalSetRequestHeader = xhr.setRequestHeader;
xhr.setRequestHeader = function (key, value) {
if (key.toLowerCase() === "x-tracer") {
xhr._xTracer = value;
}
return originalSetRequestHeader.call(xhr, key, value);
};
const originalSend = xhr.send;
xhr.send = function (body) {
if (body) {
try {
xhr._requestPayload = typeof body === "string" ? body : JSON.stringify(body);
} catch {
xhr._requestPayload = "[Unserializable body]";
}
}
return originalSend.call(xhr, body);
};
xhr.addEventListener("loadend", function () {
let responsePayload = null;
try {
const contentType = xhr.getResponseHeader("content-type") || "";
if (contentType.includes("application/json")) {
responsePayload = JSON.parse(xhr.responseText);
} else if (contentType.includes("text")) {
responsePayload = xhr.responseText;
} else {
responsePayload = "[Non-textual body]";
}
} catch {
responsePayload = "[Unserializable response]";
}
const log = {
type: "xhr",
url: xhr.responseURL,
method: xhr._method || "GET",
status: xhr.status,
xTracer: xhr._xTracer,
requestPayload: xhr._requestPayload,
responsePayload,
duration: Date.now() - start,
timestamp: new Date().toISOString(),
};
2025-09-17 18:37:35 +01:00
if(xhr.status >= 400 && !log.url.includes('petermaquiran.xyz') || xhr.status === 0 && !log.url.includes('petermaquiran.xyz')) {
2025-09-11 11:20:44 +01:00
Logger.error('XHR', log)
}
httpLogs.push(log);
});
const originalOpen = xhr.open;
xhr.open = function (method, url, ...rest) {
xhr._method = method;
return originalOpen.call(xhr, method, url, ...rest);
};
return xhr;
}
(window as any).XMLHttpRequest = CustomXHR;
// Expose logs
(window as any).getHttpLogs = () => httpLogs;
})();
2024-06-04 09:31:37 +01:00
2020-08-05 15:39:16 +01:00
@NgModule({
2024-02-22 11:40:06 +01:00
declarations: [AppComponent, PopupQuestionPipe, InputFilterDirective],
imports: [BrowserModule,
2021-01-22 16:00:37 +01:00
CommonModule,
FormsModule,
CalendarModule.forRoot({
provide: DateAdapter,
2021-01-25 16:18:36 +01:00
useFactory: adapterFactory
2021-01-22 16:00:37 +01:00
}),
2023-02-06 09:23:36 +01:00
//AngularFireModule.initializeApp(environment.firebase),
//AngularFireMessagingModule,
2022-01-28 19:02:44 +01:00
IonicImageLoaderModule,
2021-07-06 10:33:24 +01:00
IonicModule.forRoot({animated: false}),
2021-11-29 15:48:35 +01:00
IonicStorageModule.forRoot({
name: '__mydb',
driverOrder: ['indexeddb', 'sqlite', 'websql']
2022-01-28 19:02:44 +01:00
2021-11-29 15:48:35 +01:00
}),
AppRoutingModule,
2021-08-04 10:47:22 +01:00
FontAwesomeModule,
HttpClientModule,
// NgbModule,
2021-06-16 22:38:25 +01:00
NoopAnimationsModule,
2021-06-18 12:02:14 +01:00
MatDatepickerModule,
//
NgxMatDatetimePickerModule,
NgxMatTimepickerModule,
2021-06-24 11:08:17 +01:00
NgxMatNativeDateModule,
2021-06-24 11:47:05 +01:00
NgxMatMomentModule,
MatButtonModule,
ReactiveFormsModule,
2021-06-24 11:08:17 +01:00
MatSelectModule,
2021-07-08 11:07:40 +01:00
MatDialogModule,
2021-08-25 16:02:40 +01:00
//
HammerModule,
2022-03-18 11:45:38 +01:00
CustomImageCachePageRoutingModule,
2022-01-11 12:12:45 +01:00
2023-04-13 12:51:38 +01:00
//
MatInputModule,
MatNativeDateModule,
NgxMatDatetimePickerModule,
NgxMatTimepickerModule,
NgxMatNativeDateModule,
NgxMatMomentModule,
MatSelectModule,
MatButtonModule,
2023-06-26 11:12:57 +01:00
AngularFireModule.initializeApp(firebaseConfig),
AngularFireMessagingModule,
2023-07-14 18:57:07 +01:00
EditorModule,
// options
DeplomaOptionsPageModule,
2023-11-10 14:58:33 +01:00
CreateProcessPageModule,
ImageCropperModule,
MatMenuModule,
2024-09-13 12:27:39 +01:00
MatIconModule,
2024-08-07 15:23:23 +01:00
// module
2024-11-06 09:13:36 +01:00
ChatModule,
UserModule
2023-07-14 18:57:07 +01:00
],
entryComponents: [
DiplomaOptionsPage,
CreateProcessPage
],
2020-08-05 15:39:16 +01:00
providers: [
2021-06-24 11:08:17 +01:00
{ provide: MAT_DATE_LOCALE, useValue: 'pt' },
2025-09-17 18:37:35 +01:00
//{ provide: ErrorHandler, useClass: AppErrorHandler },
// {
// provide: ErrorHandler,
// // Attach the Sentry ErrorHandler
// useValue: SentrySibling.createErrorHandler(),
// },
2021-02-25 11:50:32 +01:00
StatusBar,
2021-03-01 15:45:30 +01:00
//SplashScreen,
2021-07-08 11:07:40 +01:00
HttpClient,
2020-08-05 15:39:16 +01:00
HttpClientModule,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
2020-08-26 09:42:16 +01:00
InAppBrowser,
2021-02-09 13:16:41 +01:00
Camera,
2022-03-18 11:45:38 +01:00
File,
WebView,
FilePath,
2021-11-16 16:00:14 +01:00
/* FCM,
FirebaseX, */
2021-08-17 09:53:06 +01:00
ScreenOrientation,
Network,
2021-10-15 15:21:26 +01:00
SQLite,
2021-11-16 16:00:14 +01:00
CookieService,
ImagePicker,
MediaCapture,
Media,
StreamingMedia,
2021-11-26 14:46:08 +01:00
PhotoViewer,
2022-02-25 15:10:10 +01:00
NgxImageCompressService,
2022-03-25 09:25:05 +01:00
MultipleDocumentsPicker,
2022-04-04 01:14:16 +01:00
NgxExtendedPdfViewerModule,
FileOpener,
2023-06-30 15:35:11 +01:00
DocumentViewer,
2024-03-01 14:37:42 +01:00
FFMpeg,
2024-05-17 15:27:02 +01:00
FFmpeg,
2023-07-11 17:54:08 +01:00
{ provide: HTTP_INTERCEPTORS, useClass: LoggingInterceptorService, multi: true },
2024-03-05 09:18:08 +01:00
tokenInterceptor,
2025-09-17 18:37:35 +01:00
metricsInterceptor,
2020-08-05 15:39:16 +01:00
],
bootstrap: [AppComponent],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
2020-08-05 15:39:16 +01:00
})
2021-08-04 10:47:22 +01:00
export class AppModule {
constructor(library: FaIconLibrary) {
library.addIconPacks(fas, fab, far);
}
}