11# Sent Dm TypeScript API Library
22
3- [ ![ NPM version] ( < https://img.shields.io/npm/v/sent-dm .svg?label=npm%20(stable) > )] ( https://npmjs.org/package/sent-dm ) ![ npm bundle size] ( https://img.shields.io/bundlephobia/minzip/sent-dm )
3+ [ ![ NPM version] ( < https://img.shields.io/npm/v/sentdm .svg?label=npm%20(stable) > )] ( https://npmjs.org/package/sentdm ) ![ npm bundle size] ( https://img.shields.io/bundlephobia/minzip/sentdm )
44
55This library provides convenient access to the Sent Dm REST API from server-side TypeScript or JavaScript.
66
@@ -11,25 +11,27 @@ It is generated with [Stainless](https://www.stainless.com/).
1111## Installation
1212
1313``` sh
14- npm install git+ssh://git@github.com: sentdm/sent-dm-typescript.git
14+ npm install sentdm
1515```
1616
17- > [ !NOTE]
18- > Once this package is [ published to npm] ( https://www.stainless.com/docs/guides/publish ) , this will become: ` npm install sent-dm `
19-
2017## Usage
2118
2219The full API of this library can be found in [ api.md] ( api.md ) .
2320
2421<!-- prettier-ignore -->
2522``` js
26- import SentDm from ' sent-dm ' ;
23+ import SentDm from ' sentdm ' ;
2724
2825const client = new SentDm ({
29- customerAuthScheme: process .env [' SENT_DM_CUSTOMER_AUTH_SCHEME' ], // This is the default and can be omitted
26+ apiKey: process .env [' SENT_DM_API_KEY' ], // This is the default and can be omitted
27+ senderID: process .env [' SENT_DM_SENDER_ID' ], // This is the default and can be omitted
3028});
3129
32- await client .templates .delete (' REPLACE_ME' );
30+ await client .messages .sendToPhone ({
31+ phoneNumber: ' +1234567890' ,
32+ templateId: ' 7ba7b820-9dad-11d1-80b4-00c04fd430c8' ,
33+ templateVariables: { name: ' John Doe' , order_id: ' 12345' },
34+ });
3335```
3436
3537### Request & Response types
@@ -38,13 +40,19 @@ This library includes TypeScript definitions for all request params and response
3840
3941<!-- prettier-ignore -->
4042``` ts
41- import SentDm from ' sent-dm ' ;
43+ import SentDm from ' sentdm ' ;
4244
4345const client = new SentDm ({
44- customerAuthScheme: process .env [' SENT_DM_CUSTOMER_AUTH_SCHEME' ], // This is the default and can be omitted
46+ apiKey: process .env [' SENT_DM_API_KEY' ], // This is the default and can be omitted
47+ senderID: process .env [' SENT_DM_SENDER_ID' ], // This is the default and can be omitted
4548});
4649
47- await client .templates .delete (' REPLACE_ME' );
50+ const params: SentDm .MessageSendToPhoneParams = {
51+ phoneNumber: ' +1234567890' ,
52+ templateId: ' 7ba7b820-9dad-11d1-80b4-00c04fd430c8' ,
53+ templateVariables: { name: ' John Doe' , order_id: ' 12345' },
54+ };
55+ await client .messages .sendToPhone (params );
4856```
4957
5058Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.
@@ -57,15 +65,21 @@ a subclass of `APIError` will be thrown:
5765
5866<!-- prettier-ignore -->
5967``` ts
60- const response = await client .templates .delete (' REPLACE_ME' ).catch (async (err ) => {
61- if (err instanceof SentDm .APIError ) {
62- console .log (err .status ); // 400
63- console .log (err .name ); // BadRequestError
64- console .log (err .headers ); // {server: 'nginx', ...}
65- } else {
66- throw err ;
67- }
68- });
68+ const response = await client .messages
69+ .sendToPhone ({
70+ phoneNumber: ' +1234567890' ,
71+ templateId: ' 7ba7b820-9dad-11d1-80b4-00c04fd430c8' ,
72+ templateVariables: { name: ' John Doe' , order_id: ' 12345' },
73+ })
74+ .catch (async (err ) => {
75+ if (err instanceof SentDm .APIError ) {
76+ console .log (err .status ); // 400
77+ console .log (err .name ); // BadRequestError
78+ console .log (err .headers ); // {server: 'nginx', ...}
79+ } else {
80+ throw err ;
81+ }
82+ });
6983```
7084
7185Error codes are as follows:
@@ -97,7 +111,11 @@ const client = new SentDm({
97111});
98112
99113// Or, configure per-request:
100- await client .templates .delete (' REPLACE_ME' , {
114+ await client .messages .sendToPhone ({
115+ phoneNumber: ' +1234567890' ,
116+ templateId: ' 7ba7b820-9dad-11d1-80b4-00c04fd430c8' ,
117+ templateVariables: { name: ' John Doe' , order_id: ' 12345' },
118+ }, {
101119 maxRetries: 5 ,
102120});
103121```
@@ -114,7 +132,11 @@ const client = new SentDm({
114132});
115133
116134// Override per-request:
117- await client .templates .delete (' REPLACE_ME' , {
135+ await client .messages .sendToPhone ({
136+ phoneNumber: ' +1234567890' ,
137+ templateId: ' 7ba7b820-9dad-11d1-80b4-00c04fd430c8' ,
138+ templateVariables: { name: ' John Doe' , order_id: ' 12345' },
139+ }, {
118140 timeout: 5 * 1000 ,
119141});
120142```
@@ -137,11 +159,23 @@ Unlike `.asResponse()` this method consumes the body, returning once it is parse
137159``` ts
138160const client = new SentDm ();
139161
140- const response = await client .templates .delete (' REPLACE_ME' ).asResponse ();
162+ const response = await client .messages
163+ .sendToPhone ({
164+ phoneNumber: ' +1234567890' ,
165+ templateId: ' 7ba7b820-9dad-11d1-80b4-00c04fd430c8' ,
166+ templateVariables: { name: ' John Doe' , order_id: ' 12345' },
167+ })
168+ .asResponse ();
141169console .log (response .headers .get (' X-My-Header' ));
142170console .log (response .statusText ); // access the underlying Response object
143171
144- const { data : result, response : raw } = await client .templates .delete (' REPLACE_ME' ).withResponse ();
172+ const { data : result, response : raw } = await client .messages
173+ .sendToPhone ({
174+ phoneNumber: ' +1234567890' ,
175+ templateId: ' 7ba7b820-9dad-11d1-80b4-00c04fd430c8' ,
176+ templateVariables: { name: ' John Doe' , order_id: ' 12345' },
177+ })
178+ .withResponse ();
145179console .log (raw .headers .get (' X-My-Header' ));
146180console .log (result );
147181```
@@ -160,7 +194,7 @@ The log level can be configured in two ways:
1601942 . Using the ` logLevel ` client option (overrides the environment variable if set)
161195
162196``` ts
163- import SentDm from ' sent-dm ' ;
197+ import SentDm from ' sentdm ' ;
164198
165199const client = new SentDm ({
166200 logLevel: ' debug' , // Show all log messages
@@ -188,7 +222,7 @@ When providing a custom logger, the `logLevel` option still controls which messa
188222below the configured level will not be sent to your logger.
189223
190224``` ts
191- import SentDm from ' sent-dm ' ;
225+ import SentDm from ' sentdm ' ;
192226import pino from ' pino' ;
193227
194228const logger = pino ();
@@ -223,7 +257,7 @@ parameter. This library doesn't validate at runtime that the request matches the
223257send will be sent as-is.
224258
225259``` ts
226- client .templates . delete ({
260+ client .messages . sendToPhone ({
227261 // ...
228262 // @ts-expect-error baz is not yet public
229263 baz: ' undocumented option' ,
@@ -257,7 +291,7 @@ globalThis.fetch = fetch;
257291Or pass it to the client:
258292
259293``` ts
260- import SentDm from ' sent-dm ' ;
294+ import SentDm from ' sentdm ' ;
261295import fetch from ' my-fetch' ;
262296
263297const client = new SentDm ({ fetch });
@@ -268,7 +302,7 @@ const client = new SentDm({ fetch });
268302If you want to set custom ` fetch ` options without overriding the ` fetch ` function, you can provide a ` fetchOptions ` object when instantiating the client or making a request. (Request-specific options override client options.)
269303
270304``` ts
271- import SentDm from ' sent-dm ' ;
305+ import SentDm from ' sentdm ' ;
272306
273307const client = new SentDm ({
274308 fetchOptions: {
@@ -285,7 +319,7 @@ options to requests:
285319<img src =" https://raw.githubusercontent.com/stainless-api/sdk-assets/refs/heads/main/node.svg " align =" top " width =" 18 " height =" 21 " > ** Node** <sup >[[ docs] ( https://github.com/nodejs/undici/blob/main/docs/docs/api/ProxyAgent.md#example---proxyagent-with-fetch )] </sup >
286320
287321``` ts
288- import SentDm from ' sent-dm ' ;
322+ import SentDm from ' sentdm ' ;
289323import * as undici from ' undici' ;
290324
291325const proxyAgent = new undici .ProxyAgent (' http://localhost:8888' );
@@ -299,7 +333,7 @@ const client = new SentDm({
299333<img src =" https://raw.githubusercontent.com/stainless-api/sdk-assets/refs/heads/main/bun.svg " align =" top " width =" 18 " height =" 21 " > ** Bun** <sup >[[ docs] ( https://bun.sh/guides/http/proxy )] </sup >
300334
301335``` ts
302- import SentDm from ' sent-dm ' ;
336+ import SentDm from ' sentdm ' ;
303337
304338const client = new SentDm ({
305339 fetchOptions: {
@@ -311,7 +345,7 @@ const client = new SentDm({
311345<img src =" https://raw.githubusercontent.com/stainless-api/sdk-assets/refs/heads/main/deno.svg " align =" top " width =" 18 " height =" 21 " > ** Deno** <sup >[[ docs] ( https://docs.deno.com/api/deno/~/Deno.createHttpClient )] </sup >
312346
313347``` ts
314- import SentDm from ' npm:sent-dm ' ;
348+ import SentDm from ' npm:sentdm ' ;
315349
316350const httpClient = Deno .createHttpClient ({ proxy: { url: ' http://localhost:8888' } });
317351const client = new SentDm ({
0 commit comments