Skip to content

RewriteToday/node

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Rewrite Node SDK

@rewritetoday/sdk, the official Node.js/TypeScript SDK for the Rewrite API.

It wraps authentication, typed REST calls, and resource helpers on top of @rewritetoday/rest and @rewritetoday/types.

Rewrite Banner

Installation

Use your preferred package manager:

bun add @rewritetoday/sdk
# Or
npm install @rewritetoday/sdk
# Or
pnpm add @rewritetoday/sdk

Setup

First, you need to create an API key in the Rewrite Dashboard and use it in the constructor.

import { Rewrite } from '@rewritetoday/sdk';

const rewrite = new Rewrite(process.env.REWRITE_API_KEY);

Create the client

You can pass the API key directly or use the full options object.

import { Rewrite } from '@rewritetoday/sdk';

const rewrite = new Rewrite({
	secret: 'rw_...',
	rest: {
		timeout: 10_000,
		headers: {
			'User-Agent': 'StatusPage One (1.0.0)',
		},
		retry: {
			max: 3,
			delay(attempt) {
				return attempt * 250;
			},
		},
	},
});

Send your first message

const { data, error } = await rewrite.messages.send({
	to: '+551234567890',
	content: 'Hey, Rewrite is here!',
});

You can view in our documentation everything in you can use when sending a message.

Error Handling

Requests run through @rewritetoday/rest. HTTP failures can throw HTTPError.

import { HTTPError } from '@rewritetoday/rest';

try {
	await rewrite.projects.get('invalid_id');
} catch (error) {
	if (error instanceof HTTPError) {
		console.error('HTTP Error:', error.status, error.method, error.url);
	}
}

Made with 🤍 by the Rewrite team.
SMS the way it should be.