@arbeidstilsynet/receiver-types

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

TypeScript declarations for the receiver API

原始使用文档
文档目录8 节
  1. Installation
  2. What's exported
  3. Creating a client
  4. Pulling out schema types
  5. Usage examples
  6. A first request
  7. A typed, reusable subscriptions function
  8. License

@arbeidstilsynet/receiver-types

TypeScript types for the Arbeidstilsynet receiver API, generated from its OpenAPI specification. This package ships types only - there is no runtime code - so it adds nothing to your bundle.

Use it together with openapi-fetch to get a fully type-safe HTTP client: request paths, query parameters, request bodies and responses are all checked against the live API contract.

Installation

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

The package is published alongside receiver releases and uses the receiver version, so a new version means the API contract may have changed.

What's exported

The generated module exposes the standard openapi-typescript shapes:

  • paths - every endpoint, keyed by URL, with its methods, params and responses.
  • components - reusable schemas (DTOs), under components["schemas"].
  • operations - operations keyed by operationId.

Creating a client

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

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

Pulling out schema types

Alias the schemas you use so they read nicely in your code:

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"];

Usage examples

These mirror how the types are consumed inside the Arbeidstilsynet frontends.

A first request

A minimal meldinger request - fetch the first page:

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);

A typed, reusable subscriptions function

The subscriptions endpoint exposes registered receiver consumers:

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;
}

Because ConsumerManifest is a generated type, your editor autocompletes every available field and flags invalid combinations at compile time. Changing the API contract (and updating this package) surfaces breaking changes the same way.

License

MIT. See LICENSE for details.

版本与发布记录

@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 是什么?

TypeScript declarations for the receiver 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 和提交记录判断。