src/rally_runtime@env.erl

-module(rally_runtime@env).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/rally_runtime/env.gleam").
-export([app_env_from_string/1, app_env/0, app_env_name/0, is_dev/0, secure_cookies_for/1, secure_cookies/0, browser_env_script/0]).
-export_type([app_env/0]).

-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.

?MODULEDOC(
    " APP_ENV parsing and environment-dependent behavior.\n"
    " Controls secure cookie policy and browser-side debug logging.\n"
    " Set APP_ENV=prod in production; everything else defaults to dev.\n"
).

-type app_env() :: dev | prod.

-file("src/rally_runtime/env.gleam", 20).
-spec app_env_from_string(binary()) -> app_env().
app_env_from_string(Value) ->
    case string:lowercase(Value) of
        <<"prod"/utf8>> ->
            prod;

        <<"production"/utf8>> ->
            prod;

        _ ->
            dev
    end.

-file("src/rally_runtime/env.gleam", 14).
-spec app_env() -> app_env().
app_env() ->
    _pipe = envoy_ffi:get(<<"APP_ENV"/utf8>>),
    _pipe@1 = gleam@result:unwrap(_pipe, <<"dev"/utf8>>),
    app_env_from_string(_pipe@1).

-file("src/rally_runtime/env.gleam", 27).
-spec app_env_name() -> binary().
app_env_name() ->
    case app_env() of
        dev ->
            <<"dev"/utf8>>;

        prod ->
            <<"prod"/utf8>>
    end.

-file("src/rally_runtime/env.gleam", 34).
-spec is_dev() -> boolean().
is_dev() ->
    app_env() =:= dev.

-file("src/rally_runtime/env.gleam", 42).
-spec secure_cookies_for(app_env()) -> boolean().
secure_cookies_for(App_env) ->
    App_env =:= prod.

-file("src/rally_runtime/env.gleam", 38).
-spec secure_cookies() -> boolean().
secure_cookies() ->
    secure_cookies_for(app_env()).

-file("src/rally_runtime/env.gleam", 46).
-spec browser_env_script() -> binary().
browser_env_script() ->
    <<<<"<script>window.__APP_ENV__='"/utf8, (app_env_name())/binary>>/binary,
        "'</script>"/utf8>>.