All files / src app.constants.ts

1.47% Statements 1/68
0% Branches 0/56
0% Functions 0/44
1.47% Lines 1/68

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188                            1x                                                                                                                                                                                                                                                                                                                                                          
/** Runtime config from config.js. Required; throws if missing. */
export interface UnpispasRuntimeConfig {
    appPath?: string;
    apiPath?: string;
    domain?: string;
    appRoute?: string;
    apiRoute?: string;
    production?: boolean;
    appVersion?: string;
    ticketbai_sandbox?: boolean;
    paypal_sandbox?: boolean;
    googleAnalytics?: string;
}
 
export class AppConstants {
 
    /********************************************/
    /* SERVICE WORKER CONSIDERATIONS            */
    /********************************************/
 
    private static get IsGuest(){
        return document.URL.includes('qr-access');
    }
 
    private static get IsStatic(){
        Iif (document.URL.includes('qr-access')){
            return false;
        };
 
        Iif (document.URL.includes('index')){
            return false;
        };
 
        return true;
    }
 
    public static get EnableSW(){
        Iif (this.IsStatic){
            return false;
        }
 
        Iif (document.URL.startsWith('http://localhost/')){
            console.info("[UNPISPAS] Running on native environment");
            return false;
        }
 
        return true;
    }
 
    public static get TargetSW(){
        if (AppConstants.IsGuest){   
            console.info("[UNPISPAS] Install FCM push service worker");
            return 'firebase-messaging-sw.js';
        }
        else {
            console.info("[UNPISPAS] Install WPA service worker");
            return 'unpispas-application-sw.js';    
        }
    }
    
    public static get ScopeSW(){
        return (AppConstants.IsGuest) ? '/qr-access' : '/';
    }
 
    public static get DelaySW(){
        return (AppConstants.IsGuest) ? '2000' : '30000';
    }
 
    /********************************************/
    /* STATIC VALUES (CONSTANTS)                */
    /********************************************/
 
    public static get TicketBaiSandbox(): boolean { return this.Config().ticketbai_sandbox ?? true; }
    private static get TicketBaiRegistry(): any {
        return {
            PRD: {
                'Bizkaia': {
                    license: 'TBAIBIjWPDMtTEyW1aA+',
                    appname: 'Unpispas',
                    developer: 'GEKKOTECH SL',
                    nif: 'B70659198'                    
                },
                'Gipuzkoa': {
                    license: 'TBAIGI3A40424979E2F0',
                    appname: 'Unpispas',
                    developer: 'GEKKOTECH SL',
                    nif: 'B70659198'
                },
                'Araba': {
                    license: 'TBAIARCdjdCgKHF00204',
                    appname: 'Unpispas',
                    developer: 'GEKKOTECH SL',
                    nif: 'B70659198'    
                }
            },
            DEV: {
                'Bizkaia': {
                    license: 'TBAIBI00000000PRUEBA',
                    appname: 'UnPisPas',
                    developer: 'SOFTWARE GARANTE TICKETBAI PRUEBA',
                    nif: 'A99800005'                    
                },
                'Gipuzkoa': {
                    license: 'TBAIGIPRE00000000988',
                    appname: 'Unpispas www.unpispas.com',
                    developer: 'Jorge Alejando Duran Royo, ATM tiendas y mulsitervicio SLu',
                    nif: 'B99278319'
                },
                'Araba': {
                    license: 'TBAIARCjHMggMlH00868',
                    appname: 'Unpispas',
                    developer: 'Tienda y multiservicios ATM S.L',
                    nif: 'B99278319'     
                }
            }
        }
    }
 
    public static get isProduction(): boolean { return this.Config().production ?? false; }
    public static get Appname(): string { return 'UnPisPas' }
    public static get Version(): string { return this.Config().appVersion ?? '0.0.0.0'; }
    public static get Build(): string { return "0" }    // obsoleted when managing with nx
 
    public static get TaxRate1(): number { return 4; }
    public static get TaxRate2(): number { return 10; }
    public static get TaxRate3(): number { return 21; }
 
    public static get CacheExpiration(): number { return 5 * 24 * 3600 * 1000 }
    public static get recentMs(): number { return 8 * 3600 * 1000; }
    public static get defaultTaxRate(): number { return this.TaxRate2; }
    public static get invoiceMaxPrice(): number { return 3000; }
    public static get defaultPrintWidth(): number { return 58; }
    public static get defaultPrintFont(): number { return 12; }
    public static get thumbnailWidth(): number { return 140; };
    public static get thumbnailColumns(): number { return 24; }
    public static get SearchThreshold(): number { return 80; }
 
    public static TicketBaiAppname(region: string) : string { return AppConstants.TicketBaiRegistry[AppConstants.TicketBaiSandbox ? 'DEV' : 'PRD'][region]['appname']; }
    public static TicketBaiAppvers(region: string) : string { return region ? AppConstants.Version : '0.0.0.0'; }
    public static TicketBaiLicense(region: string): string { return AppConstants.TicketBaiRegistry[AppConstants.TicketBaiSandbox ? 'DEV' : 'PRD'][region]['license']; }
    public static TicketBaiDeveloper(region: string): string { return AppConstants.TicketBaiRegistry[AppConstants.TicketBaiSandbox ? 'DEV' : 'PRD'][region]['developer']; }
    public static TicketBaiNIF(region: any): string { return AppConstants.TicketBaiRegistry[AppConstants.TicketBaiSandbox ? 'DEV' : 'PRD'][region]['nif']; }
 
    public static get defaultLanguage(): string { return 'es'; }
    public static get MainRefresh(): number { return 500; } // ms
 
    /** Runtime config from config.js. Throws if missing. */
    private static Config(): UnpispasRuntimeConfig {
        Iif (typeof window === 'undefined') {
            throw new Error('__UNPISPAS_CONFIG__: config.js required but window is undefined (e.g. Node/test). Set (globalThis as any).window = { __UNPISPAS_CONFIG__: {...} } in test setup.');
        }
        const c = (window as unknown as { __UNPISPAS_CONFIG__?: UnpispasRuntimeConfig }).__UNPISPAS_CONFIG__;
        Iif (!c || typeof c !== 'object') {
            throw new Error('__UNPISPAS_CONFIG__: config.js required but not loaded. Ensure <script src="config.js"></script> runs before Angular.');
        }
        Iif (c.appPath == null || c.apiPath == null || c.domain == null) {
            throw new Error('__UNPISPAS_CONFIG__: config.js must define appPath, apiPath and domain.');
        }
        return c;
    }
 
    public static get apppath(): string { return this.Config().appPath!; }
    public static get domain(): string { return this.Config().domain!; }
 
    public static get baseURL(): string {
        const c = this.Config();
        return 'https://' + c.apiPath + c.domain + (c.apiRoute ?? '/');
    }
 
    public static get thisURL(): string {
        const c = this.Config();
        return 'https://' + c.appPath + c.domain + (c.appRoute ?? '/');
    }
    
    public static get restURL(): string {
        const c = this.Config();
        return 'https://' + c.apiPath + c.domain + (c.apiRoute ?? '/');
    }
  
    public static get uploadPath(): string { return 'upload/'; }
    public static get qrcodePath(): string { return 'qrcode/'; }
    public static get googleApiKey(): string { return 'AIzaSyDLbnVeXUMsJEu6CtgjM5s92ht5xji0Ulk'; }
    public static get GoogleMapKey(): string { return '989754db8ad5636d' }
    public static get googleOAuth2Key(): string { return '404259737376-8t1cgibk48q5jji5sb8b8nc1b5a726hs.apps.googleusercontent.com'; }
    public static get GoogleAnalitics(): string { return this.Config().googleAnalytics ?? ''; }    
    public static get FCMVapidKey(): string { return 'BOZ-hqmu5VZKdrjUC06uqqmheRjM4zv4CWZXeahLUcXONW8B1s-DeZXf-2AJ0JqtwWuoK6lJAo0f2K-Ks-HvI3A'; };
}