@equinor/subsurface-app-management

中文文档
5.6.2发布于 2026/11/11ISCTypeScriptES Module构建来源已验证近 30 天下载 2万

React Typescript components/hooks to communicate with equinor/sam

原始使用文档
文档目录6 节
  1. 1. Create proxy/ai-proxy.conf.template
  2. 2. Replace proxy/nginx.conf
  3. 3. Replace env.sh
  4. 4. Replace the Dockerfile
  5. 5. Update radixconfig.yaml
  6. 6. Verify
intro-logo

This package contains components, utils, providers and hooks that are used to communicate with equinor/SubsurfAppManagement developed by the amplify team.

Quick links

Building and publishing

Build and publish is done automatically when code is merged into main branch, if the package.json version number is higher.

Latest version

main

Proxying Application Insights through nginx

Ad blockers block requests to *.in.applicationinsights.azure.com, so ApplicationInsightsProvider sends telemetry to the same-origin path /ai/v2/track and nginx forwards it to Azure. Tracking is optional: without APPLICATION_INSIGHTS_CONNECTION_STRING the app tracks nothing and nginx doesn't expose the proxy path. The ingestion host is read from the IngestionEndpoint in the connection string, falling back to the Application Insights default (dc.services.visualstudio.com) when it has none, so no separate host variable is needed.

Copy the files below into your app repo, replacing the existing ones (examples are taken from equinor/sam-frontend, so keep any app-specific parts of yours, such as the port, runtime variables and build steps). Lines related to Application Insights are marked in the notes above each file.

1. Create proxy/ai-proxy.conf.template

location = /ai/v2/track {
    limit_req zone=ai burst=20 nodelay;
    limit_req_status 429;
    client_max_body_size 1m;

    proxy_pass https://${APPLICATION_INSIGHTS_INGESTION_HOST}/v2/track;
    proxy_ssl_server_name on;
    proxy_ssl_verify on;
    proxy_ssl_verify_depth 3;
    proxy_ssl_trusted_certificate /etc/ssl/certs/ca-certificates.crt;
    proxy_set_header Host ${APPLICATION_INSIGHTS_INGESTION_HOST};
    proxy_set_header X-Forwarded-For $remote_addr;
}

2. Replace proxy/nginx.conf

Replace the file with the one below. Changes vs. a standard setup: the limit_req_zone line and the include /etc/nginx/ai-proxy.conf; line. Adjust listen, the /api/ proxy and other app-specific parts if yours differ.

limit_req_zone $binary_remote_addr zone=ai:10m rate=5r/s;

server {
    listen       5001;
    server_name  localhost;

    root   /usr/share/nginx/html;

    include /etc/nginx/conf.d/securityheaders.conf;

    # Application Insights proxy (empty file when APPLICATION_INSIGHTS_CONNECTION_STRING isn't set)
    include /etc/nginx/ai-proxy.conf;

    location /api/ {
        client_max_body_size 100M;
        proxy_pass ${API_URL};
    }

    location / {
        index  index.html index.htm;
        try_files $uri /index.html;
    }

    location /env-config.js {
        add_header Cache-Control "no-cache";
        proxy_cache_bypass $http_pragma;
        proxy_cache_revalidate on;
        expires off;
        access_log off;
    }

    location /env.sh {
        deny all;
    }

    location ~ \.html$ {
        add_header Cache-Control "no-cache";
        proxy_cache_bypass $http_pragma;
        proxy_cache_revalidate on;
        expires off;
        access_log off;

        include /etc/nginx/conf.d/securityheaders.conf;
    }
}

ai-proxy.conf must live in /etc/nginx/, not /etc/nginx/conf.d/. nginx auto-includes everything in conf.d/*.conf in the http context, where location is invalid, and fails to start.

3. Replace env.sh

Replace the file with the one below. Changes vs. a standard setup: the if block at the bottom. Keep your own value=... lines (one per runtime variable, matching radixconfig.yaml) if they differ.

#!/bin/sh

# Add assignment
echo "window._env_ = {" >>./env-config.js

# For all the environment variables we want to have at
# runtime (one to one with Radixconfig)

value=$(printf '%s\n' "${CLIENT_ID}")
echo "  CLIENT_ID: \"$value\"," >>./env-config.js

value=$(printf '%s\n' "${API_CLIENT_ID}")
echo "  API_CLIENT_ID: \"$value\"," >>./env-config.js

value=$(printf '%s\n' "${NAME}")
echo "  NAME: \"$value\"," >>./env-config.js

value=$(printf '%s\n' "${API_URL}")
echo "  API_URL: \"$value\"," >>./env-config.js

value=$(printf '%s\n' "${API_SCOPE}")
echo "  API_SCOPE: \"$value\"," >>./env-config.js

value=$(printf '%s\n' "${ENVIRONMENT_NAME}")
echo "  ENVIRONMENT_NAME: \"$value\"," >>./env-config.js

value=$(printf '%s\n' "${APPLICATION_INSIGHTS_CONNECTION_STRING}")
echo "  APPLICATION_INSIGHTS_CONNECTION_STRING: \"$value\"," >>./env-config.js

echo "}" >>./env-config.js

# Application Insights proxy (optional): only render the location when a connection string is set.
# The host comes from its IngestionEndpoint, falling back to the Application Insights default.
if [ -n "${APPLICATION_INSIGHTS_CONNECTION_STRING}" ]; then
  APPLICATION_INSIGHTS_INGESTION_HOST=$(printf '%s' "${APPLICATION_INSIGHTS_CONNECTION_STRING}" | tr ';' '\n' | sed -n 's/^IngestionEndpoint=https\{0,1\}:\/\/\([^/]*\).*/\1/p' | head -n 1)
  export APPLICATION_INSIGHTS_INGESTION_HOST="${APPLICATION_INSIGHTS_INGESTION_HOST:-dc.services.visualstudio.com}"
  envsubst '${APPLICATION_INSIGHTS_INGESTION_HOST}' </etc/nginx/ai-proxy.conf.template >/etc/nginx/ai-proxy.conf
else
  : >/etc/nginx/ai-proxy.conf
fi

# Update nginx.conf and securityheaders.conf with relevant environment variables
envsubst '${API_URL}' </etc/nginx/conf.d/default.conf.template >/etc/nginx/conf.d/default.conf
envsubst '${API_URL}' </etc/nginx/conf.d/securityheaders.conf.template >/etc/nginx/conf.d/securityheaders.conf

4. Replace the Dockerfile

Replace the file with the one below. Changes vs. a standard setup: the ai-proxy.conf.template COPY and the two ai-proxy.conf lines in the RUN. Adjust the build stage and EXPOSE port to your app.

# Base
FROM imbios/bun-node:22-alpine AS base
WORKDIR /app
COPY package.json ./
COPY bun.lock ./
COPY tsconfig.json ./
COPY vite.config.ts ./
COPY index.html ./
COPY src ./src
COPY public ./public

# Install dependencies and build
RUN bun install --frozen-lockfile && bun run build

# STAGE 2 => SETUP NGINX and Run
FROM nginxinc/nginx-unprivileged:alpine
USER 0
# Clear default nginx html file
RUN rm -rf /usr/share/nginx/html/*
COPY --from=base /app/dist /usr/share/nginx/html
COPY proxy/nginx.conf /etc/nginx/conf.d/default.conf.template
COPY proxy/securityheaders.conf /etc/nginx/conf.d/securityheaders.conf.template
COPY proxy/ai-proxy.conf.template /etc/nginx/ai-proxy.conf.template

EXPOSE 5001

# Copy shell script to container to handle runtime environment variables
WORKDIR /usr/share/nginx/html
COPY ./env.sh .

RUN rm -rf ./env-config.js \
  && touch ./env-config.js \
  && touch /etc/nginx/ai-proxy.conf \
  && chown nginx ./env-config.js /etc/nginx/ai-proxy.conf \
  && chown -R nginx /etc/nginx/conf.d \
  && chown -R nginx /usr/share/nginx/html \
  && chmod +x ./env.sh

USER 101

CMD ["/bin/sh", "-c", "./env.sh && nginx -g \"daemon off;\""]

5. Update radixconfig.yaml

For each environment that should track, set the connection string. The proxy target is taken from its IngestionEndpoint automatically (or the Application Insights default if it has none). For environments without tracking, set it to '' or leave it out.

APPLICATION_INSIGHTS_CONNECTION_STRING: 'InstrumentationKey=...;IngestionEndpoint=https://northeurope-4.in.applicationinsights.azure.com/;...'

6. Verify

docker build -t app .
docker run --rm -d --name app-test -p 5001:5001 -e APPLICATION_INSIGHTS_CONNECTION_STRING='InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://northeurope-4.in.applicationinsights.azure.com/' app
curl -i -X POST http://localhost:5001/ai/v2/track -d '[]'   # reaches Azure (200/400), not 404/502
docker stop app-test

# No connection string set: nginx still starts without the proxy path
docker run --rm -d --name app-test -p 5001:5001 app
docker logs app-test
docker stop app-test

Replace 5001 with the port your nginx.conf listens on, and add the app's other required variables (NAME, ENVIRONMENT_NAME, API_URL, ...) if needed.

版本与发布记录

@equinor/subsurface-app-management 共发布 88 个版本,首次发布于 2024/07/01;过去 12 个月发布了 19 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
5.6.2latest2026/11/113 天前
5.6.12026/11/0310 天前
5.6.02026/11/0211 天前
5.5.02026/10/2816 天前
5.4.72026/04/286 个月前
5.4.62026/04/246 个月前

其他发布通道:beta → 4.4.3-beta.0。

关于 @equinor/subsurface-app-management 的常见问题

@equinor/subsurface-app-management 是什么?

React Typescript components/hooks to communicate with equinor/sam

如何安装 @equinor/subsurface-app-management?

在项目目录运行 npm install @equinor/subsurface-app-management,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^19.0.0)、react-dom(^19.0.0)、@tanstack/react-query(*)、@tanstack/react-router(*)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@equinor/subsurface-app-management 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@equinor/subsurface-app-management 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@equinor/subsurface-app-management 可以商用吗?

@equinor/subsurface-app-management 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@equinor/subsurface-app-management 的下载量有多少?

根据 npm 官方下载统计,@equinor/subsurface-app-management 在 2026/10/14 – 2026/11/12 这 30 天内被下载 20,228 次,日均约 674 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@equinor/subsurface-app-management 还在维护吗?

最新版本 5.6.2 发布于 2026/11/11(3 天前);至今共发布 88 个版本,其中过去 12 个月发布了 19 个;首次发布于 2024/07/01。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。