@arbeidstilsynet/receiver-types

中文文档
1.12.2发布于 2026/11/02MITTypeScript零依赖构建来源已验证近 30 天下载 2689

接收器 API 的脚本声明

中文使用文档
文档目录8 节
  1. 安装
  2. 出口的东西
  3. 创建客户端
  4. 退出计划类型
  5. 用法实例
  6. 第一个请求
  7. 已键入、 可重复使用的订阅功能
  8. 许可证

@arbeidstilsynet/收件者类型

Arbeidstilsynet 的脚本类型 接收器 API,从其 OpenAPI 规格 。 这个包裹船 仅类型 - 没有运行时间 代码 - 所以它不会增加你的捆绑.

用起来 openapi-fetch 改为 获得一个完全类型安全的 HTTP 客户端: 请求路径、 查询参数、 请求 这些机构和答复都与API现场合同核对.

安装

npm install @arbeidstilsynet/receiver-types openapi-fetch
# or
pnpm add @arbeidstilsynet/receiver-types openapi-fetch

包与接收器同时发布并使用接收器 版本,所以一个新版本意味着API合同可能已经改变.

出口的东西

生成的模块显示标准 openapi-typescript 形状 :

  • paths - 每一个端点,以 URL 键入,及其方法、参数和响应.
  • components - 可再利用计划,根据 components["schemas"]。 。 。 .
  • operations - 操作按键 operationId。 。 。 .

创建客户端

import createClient from "openapi-fetch";
import type { paths } from "@arbeidstilsynet/receiver-types";

export const client = createClient<paths>({
  baseUrl: "/api/receiver",
});

退出计划类型

而不是你用的计谋 所以他们在你的代码中读得很好:

import type { components } from "@arbeidstilsynet/receiver-types";

export type Melding = components["schemas"]["Melding"];
export type ConsumerManifest = components["schemas"]["ConsumerManifest"];
export type GetAllMeldingerResponse =
  components["schemas"]["GetAllMeldingerResponse"];

用法实例

这些镜像是如何在Arbeidstilsynet前端内消耗类型.

第一个请求

起码 meldinger 请求 - 获取首页 :

const { data, error } = await client.GET("/meldinger", {
  params: {
    query: {
      pageNumber: 1,
      pageSize: 20,
    },
  },
});

if (error) throw new Error(JSON.stringify(error));
console.log(data?.items);

已键入、 可重复使用的订阅功能

用户端点显示注册的接收用户:

import type { components } from "@arbeidstilsynet/receiver-types";

type ConsumerManifest = components["schemas"]["ConsumerManifest"];

export async function getSubscriptions(): Promise<ConsumerManifest[]> {
  const { data, error } = await client.GET("/subscriptions");

  if (error) {
    throw new Error(`Failed to get subscriptions: ${JSON.stringify(error)}`);
  }
  if (!data) {
    throw new Error("Failed to get subscriptions: empty response");
  }
  return data;
}

因为 ConsumerManifest 是生成类型, 您的编辑器自动完成每个类型 编译时可用的字段和标记无效的组合。 更改 API 合同(并更新此软件包)表面的断裂变化相同.

许可证

麻省理工学院. 见 自由主义 详细情况.

版本与发布记录

@arbeidstilsynet/receiver-types 共发布 45 个版本,首次发布于 2026/06/18;过去 12 个月发布了 45 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.12.2latest2026/11/025 天前
1.12.12026/10/2711 天前
1.12.02026/10/1622 天前
1.11.22026/10/1523 天前
1.11.12026/10/1523 天前
1.11.02026/10/1523 天前

其他发布通道:next → 1.9.2-alpha1。

关于 @arbeidstilsynet/receiver-types 的常见问题

@arbeidstilsynet/receiver-types 是什么?

接收器 API 的脚本声明

如何安装 @arbeidstilsynet/receiver-types?

在项目目录运行 npm install @arbeidstilsynet/receiver-types,或使用 pnpm add / yarn add / bun add。

@arbeidstilsynet/receiver-types 支持 TypeScript 吗?

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

@arbeidstilsynet/receiver-types 可以商用吗?

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

@arbeidstilsynet/receiver-types 的下载量有多少?

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

@arbeidstilsynet/receiver-types 还在维护吗?

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