Skip to content
This repository was archived by the owner on Jun 10, 2026. It is now read-only.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Rewrite Typebox

Official Typebox schemas for the Rewrite API — versioned, typed, and built for production.
@rewritetoday/typebox gives you first-class runtime validation for the public Rewrite API, including REST payloads, reusable resources, and webhook events.

Built for TypeScript, Node.js, Bun, and modern server runtimes, it keeps your integrations aligned with the Rewrite platform while delivering a clean developer experience from request validation to webhook handling.

Installing

You can use your favorite package manager to install our package

npm install @rewritetoday/typebox @sinclair/typebox
# Or
yarn add @rewritetoday/typebox @sinclair/typebox
# Or
bun add @rewritetoday/typebox @sinclair/typebox

Using the Typebox Schemas

Import schemas from the API version you want to target and validate requests or responses with confidence.

import {
	RESTPostCreateTemplateBody,
	RESTGetListTemplatesData,
} from '@rewritetoday/typebox/v1';
import { Parse } from '@sinclair/typebox/value';

const data = Parse(RESTPostCreateTemplateBody, {
	name: 'order_shipped',
	content: 'Hi {{first_name}}, your order {{order_id}} is on the way.',
	description: 'Default shipping notification',
	variables: [
		{ name: 'first_name', fallback: 'customer' },
		{ name: 'order_id', fallback: '0000' },
	],
	i18n: {
		br: 'Oi {{first_name}}, seu pedido {{order_id}} esta a caminho.',
	},
});

console.log({
	data,
	url: '/templates',
	response: Parse(RESTGetListTemplatesData, {
		ok: true,
		data: [],
		cursor: {
			persist: false,
		},
	}),
});

API Models & REST Contracts

Use reusable API* resources and endpoint-focused REST<Method>* schemas side by side.

import {
	APIWebhook,
	RESTPostCreateWebhookBody,
	RESTGetListWebhooksData,
} from '@rewritetoday/typebox/v1';
import { Parse } from '@sinclair/typebox/value';

const webhook = Parse(APIWebhook, {
	id: '748395130237498700',
	name: 'Message lifecycle',
	secret: 'rewrite_webhook_secret',
	endpoint: 'https://example.com/webhooks/rewrite',
	events: ['message.queued', 'message.delivered'],
	status: 'ACTIVE',
	projectId: '748395130237498701',
	createdAt: '2026-02-19T16:05:00.000Z',
});

const body = Parse(RESTPostCreateWebhookBody, {
	name: 'Message lifecycle',
	endpoint: 'https://example.com/webhooks/rewrite',
	events: ['message.queued', 'message.delivered'],
	secret: 'rewrite_webhook_secret',
});

const data = Parse(RESTGetListWebhooksData, {
	ok: true,
	data: [webhook],
	cursor: {
		persist: false,
	},
});

console.log({ body, data });

Handling Webhooks

Validate Rewrite webhook payloads with a discriminated union and branch safely by event type.

import { WebhookEvent } from '@rewritetoday/typebox/v1';
import { Parse } from '@sinclair/typebox/value';

const data = Parse(WebhookEvent, {
	type: 'message.sent',
	id: '748395130237498799',
	createdAt: '2026-02-19T16:05:00.000Z',
	data: {
		id: '748395130237498800',
		projectId: '748395130237498701',
		createdAt: '748395130237498801',
		analysis: {
			characters: 24,
			encoding: 'gsm7',
			segments: {
				count: 1,
				single: 160,
				concat: 153,
				reason: 'fits',
			},
		},
		to: '+5511999999999',
		type: 'SMS',
		tags: [{ name: 'campaign', value: 'spring' }],
		status: 'SENT',
		country: 'br',
		content: 'Your code is 123456',
		encoding: 'GMS7',
		templateId: null,
		deliveredAt: null,
		scheduledAt: null,
		isPayAsYouGo: false,
	},
});

console.log({ data });

You can view our documentation going here. Thanks for building with Rewrite!

About

Official Typebox schemas for the Rewrite API

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

Contributors

Languages