"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EnvironmentVariablesService = void 0;
const _1 = require(".");
/**
 * Class EnvironmentVariablesService
 *
 * This class is used to return environment variables that are available in the runtime of
 * the current Lambda invocation.
 * These variables can be a mix of runtime environment variables set by AWS and
 * variables that can be set by the developer additionally.
 *
 * @class
 * @extends {ConfigService}
 * @see https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html#configuration-envvars-runtime
 * @see https://awslabs.github.io/aws-lambda-powertools-typescript/latest/#environment-variables
 */
class EnvironmentVariablesService extends _1.ConfigService {
    constructor() {
        super(...arguments);
        /**
         * @see https://awslabs.github.io/aws-lambda-powertools-typescript/latest/#environment-variables
         * @protected
         */
        this.serviceNameVariable = 'POWERTOOLS_SERVICE_NAME';
        // Reserved environment variables
        this.xRayTraceIdVariable = '_X_AMZN_TRACE_ID';
    }
    /**
     * It returns the value of an environment variable that has given name.
     *
     * @param {string} name
     * @returns {string}
     */
    get(name) {
        return process.env[name]?.trim() || '';
    }
    /**
     * It returns the value of the POWERTOOLS_SERVICE_NAME environment variable.
     *
     * @returns {string}
     */
    getServiceName() {
        return this.get(this.serviceNameVariable);
    }
    /**
     * It returns the value of the _X_AMZN_TRACE_ID environment variable.
     *
     * The AWS X-Ray Trace data available in the environment variable has this format:
     * `Root=1-5759e988-bd862e3fe1be46a994272793;Parent=557abcec3ee5a047;Sampled=1`,
     *
     * The actual Trace ID is: `1-5759e988-bd862e3fe1be46a994272793`.
     *
     * @returns {string}
     */
    getXrayTraceId() {
        const xRayTraceId = this.get(this.xRayTraceIdVariable);
        if (xRayTraceId === '')
            return undefined;
        return xRayTraceId.split(';')[0].replace('Root=', '');
    }
}
exports.EnvironmentVariablesService = EnvironmentVariablesService;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiRW52aXJvbm1lbnRWYXJpYWJsZXNTZXJ2aWNlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4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