open-index/open-npm huggingface dataset:
npm package: @rewritetoday/types
Description: Official Rewrite API typings that are always up to date
Latest version: 1.0.4

<div align="center">

# Rewrite Types

[@rewritetoday/types](https://www.npmjs.com/package/@rewritetoday/types), an official **TypeScript types** for the **Rewrite API**.

This package provides shared resource models, request/response contracts, and route builders used by Rewrite SDKs and applications. It is designed to keep API integrations strongly typed and consistent across projects.

## Installation

You can use this package with your *favorite package manager*

</div>

```bash
bun add @rewritetoday/types
# Or
npm install @rewritetoday/types
# Or
pnpm install @rewritetoday/types
# Or
yarn add @rewritetoday/types
```

<div align="center">

## Using

### How we document our types

</div>

- Prefix `API*`
Represents general API structures (returned objects, internal models, etc.).

- Prefix `REST<HTTPMethod>*`
Types used in direct API requests.
  - Suffix Body → request body payload
  E.g.: `RESTPostCreateTemplateBody`

  - Suffix `QueryParams` → query string parameters
  E.g.: `RESTGetListWebhooksQueryParams`

  - Suffix `Data` → data returned by the API
  E.g.: `RESTGetListWebhooksData`
  
- Prefix `Webhook*`
Represents any data that come from a webhook.

<div align="center">

### Typing API Responses

</div>

```ts
import { REST } from '@rewritetoday/rest';
import { Routes, type RESTGetProjectData } from '@rewritetoday/types/v1';

const rest = new REST(process.env.REWRITE_API_KEY);

// Return type: Promise<RESTGetWebhooksData>
async function fetchHooks() {
	const data = await rest.get<RESTGetWebhooksData>(Routes.webhooks.list());
	
	return data
}
```

<div align="center">

### Typing webhook events

We are using [Bun](https://elysiajs.com/) here as example, but you can use it however you want.

</div>

```ts
import { type WebhookEvent, WebhookEventType } from '@rewritetoday/types/v1';

const server = Bun.serve({
	port: 3000,
	routes: {
		async '/webhooks/rewrite'(request) {
			const event: WebhookEvent = await request.json();
			
			switch (event.type) {
				case WebhookEventType.MessageSent:
					console.log('Hey, a new message!');
					
					return Response.json({});
				case ...
			}
		},
	},
});
```

<div align="center">

### Using Route Builders

</div>

```ts
import { API_VERSION API_BASE_URL, Routes } from '@rewritetoday/types/v1';

// https://api.rewritetoday.com/v1/templates
const CREATE_TEMPLATE_URL = `${API_BASE_URL}/${API_VERSION}/${Routes.templates.create()}`;
```

<div align="center">

Made with 🤍 by the Rewrite team. <br />
SMS the way it should be.

</div>