open-index/open-npm huggingface dataset:
npm package: @rikkainc/event
Description: Frontend client for POST /events on logpush workers
Latest version: 0.1.0

# @rikkainc/event

`POST /events` を叩くための frontend 向け client package です。
依存は持たず、`fetch` の薄いラッパーだけを提供します。response は見ず、送信時は常に `keepalive: true` を付けます。

## Install

```bash
npm install @rikkainc/event
```

## Usage

```ts
import { createEventsClient } from "@rikkainc/event";

const events = createEventsClient({
	namespace: "tenant_a",
	userId: "u_1",
});

events.track({
	name: "signup",
	props: {
		plan: "pro",
	},
});
```

`userId` は後から更新できます。

```ts
events.setUserId("u_2");

events.track({
	name: "purchase",
	props: {
		amount: 1200,
	},
});
```

認証ヘッダや追加の `fetch` option が必要なら `requestInit` で渡せます。

```ts
const events = createEventsClient({
	namespace: "tenant_a",
	endpoint: "https://example.com/events",
	requestInit: {
		headers: {
			Authorization: "Bearer token",
		},
	},
});
```

## Build

```bash
npm run build
```