---
url: /reference/functions/core/app.md
---

# app

`app` 模块内置的方法可以获取应用的上下文详情，包括函数运行时所处的应用环境及版本

导入：

```typescript
import { app } from "@pc-nexus/core";
```

内置方法：

## getContext

`getContext`  函数可获取 Nexus 函数的上下文详情，包括该函数运行时所处的应用环境及版本。

### 函数签名

```typescript
export declare function getContext(): NexusAppContext;

export interface NexusAppContext {
    app: {
        id: string;
        version: string;
        licensing: { enabled: boolean };
    };
    environment: {
        id: string;
        type: EnvironmentType;
    };
    team: Team;
    installation: {
        id: string;
    };
    invocation: {
        id: string;
    };
    user?: User;
    extension?: Extension;
    event?: {
        trigger: {
          key: string; 
          type: string
        };
    };
    async?: {
        consumer: AsyncConsumerInfo;
    };
    exposer?: {
        route: { key: string };
    };
}

export enum EnvironmentType {
    Development = "development",
    Staging = "staging",
    Production = "production"
}

export interface Team {
    id: string;
    url: string;
    locale: string;
    timezone: string;
}

export interface User {
    id: string;
    locale: string;
    timezone: string;
}

export interface Extension {
    key: string;
    local_id: string;
    target: string;
    location: string;
    data?: Record<string, unknown>;
}

export interface AsyncConsumerInfo {
    key: string;
    concurrency: number;
}
```

### 参数

空

### 返回值

返回值类型为 `NexusAppContext` ，包含应用当前运行环境上下文信息的对象，可用的数据取决于应用所使用的模块。

#### app

定义当前应用数据

#### team

定义当前应用安装的企业数据

#### installation

定义当前应用安装数据

#### invocation

定义当前调用的数据

#### environment

定义当前应用所在环境数据

#### user

定义当前用户数据

#### extension

定义扩展模块数据

#### event

定义事件订阅数据

#### async

定义 异步任务数据。

#### exposer

定义应用自定义 REST APIs 数据。

### 示例

以下是一段使用 `getContext` 方法获取的数据示例：

```typescript
{
    "app": {
        "id": "fe85a6b3-4073-4fd2-89e0-481a38ca5958",
        "version": "1.3.0",
        "licensing": { 
            "enabled": false
        }
    },
    "environment": {
        "id": "375cc666-98a7-4bf0-a85e-28085fe1772f",
        "type": "development"
    },
    "team": {
        "id": "5db7a0ed77c86b2d749605ad",
        "url": "https://your-domain.pingcode.com",
        "locale": "en-US",
        "timezone": "Asia/Shanghai"
    },
    "installation": {
        "id": "63dd9483-7652-4a2a-9fd7-15783380467b"
    },
    "invocation": {
        "id": "1a538371-7aea-4943-969b-d9c759a80baf"
    },
    "user": {
        "id": "52b9af20da8a4969aab88092d1fa64ce",
        "locale": "zh-CN",
        "timezone": "Asia/Shanghai"
    },
    "extension": {
        "key": "my-ship-page",
        "local_id": "fe85a6b3-4073-4fd2-89e0-481a38ca5958/375cc666-98a7-4bf0-a85e-28085fe1772f/my-ship-page",
        "target": "pcm:ship:product:page",
        "location": "https://your-domain.pingcode.com/ship/products/CPCWU/apps/fe85a6b3-4073-4fd2-89e0-481a38ca5958/375cc666-98a7-4bf0-a85e-28085fe1772f",
        "data": {
            "product": {
                "id": "68d4983fcd51c2d6113d79c6",
                "identifier": "CPCWU",
                "name": "产品测试"
            }
        }
    }
}
```
