contiguity 0.0.6 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -156
- package/dist/schemas/email.d.ts.map +1 -1
- package/dist/schemas/email.js +10 -1
- package/dist/utils/request.d.ts.map +1 -1
- package/dist/utils/request.js +6 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,186 +1,78 @@
|
|
|
1
|
-
|
|
1
|
+
<p align='center'><img src="https://contiguity.co/assets/icon-black.png" height="150px"/></p>
|
|
2
|
+
<h1 align='center'>Contiguity JavaScript SDK</h1>
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
<p align='center'>
|
|
5
|
+
<img display="inline-block" src="https://img.shields.io/npm/v/contiguity?style=for-the-badge" />
|
|
6
|
+
<img display="inline-block" src="https://img.shields.io/badge/Made%20with-TypeScript-3178C6?style=for-the-badge&logo=typescript&logoColor=white" />
|
|
7
|
+
</p>
|
|
4
8
|
|
|
5
|
-
|
|
9
|
+
<p align='center'>The official TypeScript/JavaScript SDK for Contiguity's APIs.</p>
|
|
6
10
|
|
|
7
|
-
|
|
11
|
+
## Installation
|
|
8
12
|
|
|
9
13
|
```bash
|
|
10
|
-
|
|
11
|
-
# or
|
|
12
|
-
pnpm add contiguity
|
|
13
|
-
# or
|
|
14
|
+
# Using npm
|
|
14
15
|
npm install contiguity
|
|
15
|
-
# or
|
|
16
|
-
yarn add contiguity
|
|
17
|
-
```
|
|
18
16
|
|
|
19
|
-
|
|
17
|
+
# Using pnpm
|
|
18
|
+
pnpm add contiguity
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
# Using bun
|
|
21
|
+
bun add contiguity
|
|
22
|
+
```
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
## Getting Started
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
```typescript
|
|
27
|
+
import { Contiguity } from 'contiguity';
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
const contiguity = new Contiguity("contiguity_sk_...", {
|
|
31
|
-
debug: false, // set true for request logging
|
|
32
|
-
});
|
|
29
|
+
const contiguity = new Contiguity('contiguity_sk_...your_token...');
|
|
33
30
|
```
|
|
34
31
|
|
|
35
|
-
|
|
32
|
+
Get your API token from the [Contiguity Console](https://console.contiguity.com/).
|
|
36
33
|
|
|
37
|
-
###
|
|
34
|
+
### Send a text message
|
|
38
35
|
|
|
39
|
-
```
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
// from: "+15555555555", // optional, if you lease a number
|
|
36
|
+
```typescript
|
|
37
|
+
const response = await contiguity.text.send({
|
|
38
|
+
to: "+1234567890",
|
|
39
|
+
message: "Hello from Contiguity!"
|
|
44
40
|
});
|
|
45
|
-
// res.message_id, res.metadata
|
|
46
|
-
|
|
47
|
-
await contiguity.text.get("text_abc123");
|
|
48
|
-
await contiguity.text.history({ to: "+1…", from: "+1…", limit: 20 });
|
|
49
|
-
await contiguity.text.react("add", { message_id: "text_abc", reaction: "love" });
|
|
50
41
|
```
|
|
51
42
|
|
|
52
|
-
###
|
|
43
|
+
### Send an email
|
|
53
44
|
|
|
54
|
-
```
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
45
|
+
```typescript
|
|
46
|
+
const response = await contiguity.email.send({
|
|
47
|
+
to: "user@example.com",
|
|
48
|
+
from: "Your App <no-reply@yourapp.com>",
|
|
49
|
+
subject: "Welcome!",
|
|
50
|
+
body: { text: "Welcome to our platform!" }
|
|
60
51
|
});
|
|
61
|
-
// res.email_id, res.metadata
|
|
62
52
|
```
|
|
63
53
|
|
|
64
|
-
### OTP
|
|
54
|
+
### Send and verify OTP
|
|
65
55
|
|
|
66
|
-
```
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
56
|
+
```typescript
|
|
57
|
+
const otpResponse = await contiguity.otp.send({
|
|
58
|
+
to: "+1234567890",
|
|
59
|
+
language: "en",
|
|
60
|
+
name: "MyApp"
|
|
71
61
|
});
|
|
72
|
-
// res.otp_id
|
|
73
|
-
|
|
74
|
-
const verified = await contiguity.otp.verify({ otp_id: res.otp_id, otp: "123456" });
|
|
75
|
-
// verified.verified === true | false
|
|
76
|
-
|
|
77
|
-
await contiguity.otp.resend({ otp_id: res.otp_id });
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
### Domains
|
|
81
|
-
|
|
82
|
-
```ts
|
|
83
|
-
const list = await contiguity.domains.list();
|
|
84
|
-
const one = await contiguity.domains.get("example.com");
|
|
85
|
-
await contiguity.domains.register("example.com", { region: "us-east-1", custom_return_path: "mail" });
|
|
86
|
-
await contiguity.domains.delete("example.com");
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
### Lease (numbers)
|
|
90
|
-
|
|
91
|
-
```ts
|
|
92
|
-
const available = await contiguity.lease.available();
|
|
93
|
-
const details = await contiguity.lease.get("+1234567890");
|
|
94
|
-
await contiguity.lease.create("+1234567890", { billing_method: "monthly" });
|
|
95
|
-
const leased = await contiguity.lease.leased();
|
|
96
|
-
const leaseDetails = await contiguity.lease.details("+1234567890");
|
|
97
|
-
await contiguity.lease.terminate("+1234567890");
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
### iMessage / WhatsApp
|
|
101
|
-
|
|
102
|
-
```ts
|
|
103
|
-
await contiguity.imessage.send({ to: "+1234567890", message: "Hello via iMessage!" });
|
|
104
|
-
await contiguity.imessage.typing({ to: "+1234567890", action: "start" });
|
|
105
|
-
await contiguity.imessage.get("imessage_abc123");
|
|
106
|
-
await contiguity.imessage.history({ to: "+1…", from: "+1…", limit: 20 });
|
|
107
|
-
await contiguity.imessage.react("add", { to: "+1…", from: "+1…", tapback: "love", message: "Hello!" });
|
|
108
|
-
await contiguity.imessage.read({ to: "+1234567890", from: "+15555555555" });
|
|
109
|
-
|
|
110
|
-
await contiguity.whatsapp.send({ to: "+1234567890", message: "Hello via WhatsApp!" });
|
|
111
|
-
await contiguity.whatsapp.typing({ to: "+1234567890", action: "stop" });
|
|
112
|
-
await contiguity.whatsapp.react("add", { to: "+1234567890", reaction: "👍", message: "wa_123" });
|
|
113
|
-
```
|
|
114
62
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
```ts
|
|
120
|
-
// With request-like object (e.g. Express req with raw body)
|
|
121
|
-
const ok = contiguity.webhook.verify(req, process.env.WEBHOOK_SECRET, 300);
|
|
122
|
-
|
|
123
|
-
// Or with raw values
|
|
124
|
-
const ok = contiguity.webhook.verify(rawBody, signatureHeader, secret, 300);
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
Parse webhook body (v2 format):
|
|
128
|
-
|
|
129
|
-
```ts
|
|
130
|
-
const event = contiguity.webhook.parse(rawBody);
|
|
131
|
-
// event.id, event.type, event.timestamp, event.data
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
### Pass-through options
|
|
135
|
-
|
|
136
|
-
Request params accept extra JSON; unknown fields are sent to the API as-is. Types are defined for known fields; you can add more for new API options.
|
|
137
|
-
|
|
138
|
-
## Response format
|
|
139
|
-
|
|
140
|
-
All responses return a clean shape: method-specific fields at the top level plus `metadata`:
|
|
141
|
-
|
|
142
|
-
```ts
|
|
143
|
-
{
|
|
144
|
-
message_id?: string;
|
|
145
|
-
email_id?: string;
|
|
146
|
-
otp_id?: string;
|
|
147
|
-
// ... etc
|
|
148
|
-
metadata: { id: string; timestamp: string; api_version: string; object: string; }
|
|
149
|
-
}
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
## Errors
|
|
153
|
-
|
|
154
|
-
On API errors the SDK throws `ContiguityError` with `message`, `status`, and optional `code`.
|
|
155
|
-
|
|
156
|
-
```ts
|
|
157
|
-
import { ContiguityError } from "contiguity";
|
|
158
|
-
try {
|
|
159
|
-
await contiguity.text.send({ ... });
|
|
160
|
-
} catch (e) {
|
|
161
|
-
if (e instanceof ContiguityError) {
|
|
162
|
-
console.error(e.status, e.message);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
63
|
+
const verification = await contiguity.otp.verify({
|
|
64
|
+
otp_id: otpResponse.otp_id,
|
|
65
|
+
otp: "123456"
|
|
66
|
+
});
|
|
165
67
|
```
|
|
166
68
|
|
|
167
|
-
##
|
|
168
|
-
|
|
169
|
-
- [SDK overview](https://docs.contiguity.com/sdk/js/overview)
|
|
170
|
-
- [API reference](https://docs.contiguity.com/llms.txt)
|
|
171
|
-
|
|
172
|
-
## Development
|
|
173
|
-
|
|
174
|
-
Use Bun for local dev and publishing:
|
|
175
|
-
|
|
176
|
-
- `bun install` / `bun run build` — install and compile
|
|
177
|
-
- `bun run test` — build and run Vitest (Vitest loads `.env` from project root; unit tests always run; live API tests when `CONTIGUITY_TEST_API_KEY` is set; send tests need `CONTIGUITY_TEST_TO`, optional `CONTIGUITY_TEST_FROM`, `CONTIGUITY_TEST_EMAIL`, optional `CONTIGUITY_TEST_EMAIL_FROM_NAME`)
|
|
178
|
-
- `bun run pack` — create the tarball (e.g. `contiguity-1.0.0.tgz`) without publishing
|
|
179
|
-
- `bun run publish:dry` — build and simulate publish (no upload)
|
|
180
|
-
- `bun publish` — build (via prepublishOnly) and publish to the registry
|
|
69
|
+
## Documentation
|
|
181
70
|
|
|
182
|
-
|
|
71
|
+
For complete documentation, examples, and API reference, visit [docs.contiguity.com](https://docs.contiguity.com/sdk/js/overview).
|
|
183
72
|
|
|
184
|
-
##
|
|
73
|
+
## Resources
|
|
185
74
|
|
|
186
|
-
|
|
75
|
+
- [API Reference](https://docs.contiguity.com/api-reference/) - Complete API documentation
|
|
76
|
+
- [Console](https://console.contiguity.com/) - Manage your account and API keys
|
|
77
|
+
- [Discord Community](https://discord.gg/Z9K5XAsS7H) - Get support and connect with other developers
|
|
78
|
+
- [GitHub Repository](https://github.com/contiguity/javascript) - Source code and issue tracking
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"email.d.ts","sourceRoot":"","sources":["../../src/schemas/email.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,eAAe;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"email.d.ts","sourceRoot":"","sources":["../../src/schemas/email.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,eAAe;;;;;;;;;;;;iBAoBhB,CAAC;AAEb,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC"}
|
package/dist/schemas/email.js
CHANGED
|
@@ -4,7 +4,16 @@ export const emailSendSchema = z
|
|
|
4
4
|
to: z.union([z.string(), z.array(z.string()).max(10)]),
|
|
5
5
|
from: z.string(),
|
|
6
6
|
subject: z.string(),
|
|
7
|
-
body: z
|
|
7
|
+
body: z
|
|
8
|
+
.object({
|
|
9
|
+
text: z.string().nullable().optional(),
|
|
10
|
+
html: z.string().nullable().optional(),
|
|
11
|
+
})
|
|
12
|
+
.refine((b) => {
|
|
13
|
+
const has_text = b.text != null && b.text !== "";
|
|
14
|
+
const has_html = b.html != null && b.html !== "";
|
|
15
|
+
return has_text || has_html;
|
|
16
|
+
}, "Either body.text or body.html must be provided (non-empty)"),
|
|
8
17
|
reply_to: z.string().nullable().optional(),
|
|
9
18
|
cc: z.union([z.string(), z.array(z.string()).max(10)]).nullable().optional(),
|
|
10
19
|
bcc: z.union([z.string(), z.array(z.string()).max(10)]).nullable().optional(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/utils/request.ts"],"names":[],"mappings":"AAGA,QAAA,MAAM,SAAS;;;;;;;CAOL,CAAC;AAEX,MAAM,MAAM,OAAO,GAAG,MAAM,OAAO,SAAS,CAAC;AAE7C,MAAM,WAAW,aAAa;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI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,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,CAAC,CAiCnG"}
|
package/dist/utils/request.js
CHANGED
|
@@ -25,8 +25,12 @@ export async function request(config, path, options = {}) {
|
|
|
25
25
|
});
|
|
26
26
|
const json = (await res.json());
|
|
27
27
|
if (!res.ok) {
|
|
28
|
-
|
|
29
|
-
const
|
|
28
|
+
// Default API shape: data: { error, status }. Occasional: { message, status } at top level.
|
|
29
|
+
const errMsg = json.data?.error ??
|
|
30
|
+
json.message ??
|
|
31
|
+
json.object ??
|
|
32
|
+
"Unknown error";
|
|
33
|
+
const status = json.data?.status ?? json.status ?? res.status;
|
|
30
34
|
throw new ContiguityError(errMsg, status);
|
|
31
35
|
}
|
|
32
36
|
return transformResponse(json);
|