All files / sn-client-js/src/Config snconfigmodel.ts

94.74% Statements 18/19
50% Branches 5/10
100% Functions 2/2
93.33% Lines 14/15
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        1x 1x         1x           504x   504x           1x                     349x                   349x                     349x                     349x               349x 186x 696x 533x            
/**
 * @module Config
 *//** */
 
import { SnConfigBehavior } from './snconfigbehavior';
import { SnConfigField } from './snconfigfielddecorator';
 
/**
 * Class that represents a typed model for the Sense/Net related configuration for an NPM Package. The values can be populated from sn.config.js.
 */
export class SnConfigModel {
 
    /**
     * The default base URL, returns window.location if available
     */
    public static get DEFAULT_BASE_URL(): string {
        Iif (typeof window !== 'undefined')
            return (window && window.location && window.location.origin) || '';
        return '';
    }
    
    /**
     * The default Sense/Net OData Service token (odata.svc)
     */
    public static readonly DEFAULT_SERVICE_TOKEN: string = 'odata.svc';
 
 
    /**
     * The root URL for the Sense/Net repository (e.g.: demo.sensenet.com)
     */
    @SnConfigField({
        Behavior: SnConfigBehavior.AllowFromConfig | SnConfigBehavior.AllowFromCommandLine,
        FieldDescription: 'URL to the repository (e.g.: demo.sensenet.com)',
        Question: 'Please enter your Sense/Net Site URL(e.g.:demo.sensenet.com):',
    })
    public RepositoryUrl: string = SnConfigModel.DEFAULT_BASE_URL;
 
    /**
     * The service token for the OData Endpoint
     */
    @SnConfigField({
        Behavior: SnConfigBehavior.AllowFromConfig | SnConfigBehavior.AllowFromCommandLine,
        FieldDescription: 'The service token for the OData Endpoint',
        Question: 'Please enter your Sense/Net Site URL(e.g.:demo.sensenet.com):',
    })
    public ODataToken: string = SnConfigModel.DEFAULT_SERVICE_TOKEN;
 
 
    /**
     * This string represents how the Jwt Web Token will be stored in the localStorage.
     */
    @SnConfigField({
        Behavior: SnConfigBehavior.AllowFromConfig,
        FieldDescription: 'Template will be stored in that format',
        Question: 'Please specify the template format for the key of the JWT Web Token in the localStorage (e.g.: sn-${siteName}-${tokenName})'
    })
    public JwtTokenKeyTemplate: string = 'sn-${siteName}-${tokenName}';
 
 
    /**
     * This string describes how long the JWT token should be persisted.
     */
    @SnConfigField({
        Behavior: SnConfigBehavior.AllowFromConfig,
        FieldDescription: 'The behavoir how long the JWT tokens should be persisted, can be "session" or "expiration"',
        Question: ''
    })
    public JwtTokenPersist: 'session' | 'expiration' = 'session';
 
    /**
     *
     * @param {Partial<SnConfigMoel>} config Partial config values, the default values will be overwritten if provided
     * @constructs {SnConfigModel}
     */
    constructor(config?: Partial<SnConfigModel>) {
        if (config) {
            for (let key in config) {
                if (config[key]) {
                    this[key] = config[key];
                }
            }
        }
    }
}