@nilovonjs/connect 0.1.1
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 +63 -0
- package/dist/index.cjs +44 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +21 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/package.json +34 -0
package/README.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# @nilovonjs/connect
|
|
2
|
+
|
|
3
|
+
Official TypeScript SDK for Nilovon Connect.
|
|
4
|
+
|
|
5
|
+
- Homepage: `https://connect.nilovon.com`
|
|
6
|
+
- API host: `https://api.connect.nilovon.com`
|
|
7
|
+
- API reference: `https://api.connect.nilovon.com/v1`
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @nilovonjs/connect
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { createClient } from "@nilovonjs/connect";
|
|
19
|
+
|
|
20
|
+
const connect = createClient({
|
|
21
|
+
apiKey: "sk_live_...",
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
await connect.message.send({
|
|
25
|
+
channelType: "email",
|
|
26
|
+
emailDomainId: "dom_...",
|
|
27
|
+
to: "user@example.com",
|
|
28
|
+
subject: "Hello from Connect",
|
|
29
|
+
body: "<p>Your first message</p>",
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Configuration
|
|
34
|
+
|
|
35
|
+
| Option | Required | Description |
|
|
36
|
+
| -------- | -------- | ------------------------- |
|
|
37
|
+
| `apiKey` | Yes | API key from your dashboard |
|
|
38
|
+
|
|
39
|
+
## API Surface
|
|
40
|
+
|
|
41
|
+
- `connect.message`: `send`, `list`, `get`
|
|
42
|
+
- `connect.contact`: `create`, `list`, `get`, `update`, `delete`, `bulkCreate`
|
|
43
|
+
- `connect.template`: `create`, `list`, `get`, `update`, `delete`
|
|
44
|
+
- `connect.webhook`: `create`, `list`, `get`, `update`, `delete`, `test`, `listEvents`
|
|
45
|
+
- `connect.emailDomain`: `list`, `get`, `add`, `verify`, `delete`, `setDefault`
|
|
46
|
+
- `connect.phoneNumber`: `list`, `get`, `searchAvailable`, `purchase`, `release`, `update`
|
|
47
|
+
- `connect.segment`: `create`, `list`, `get`, `update`, `delete`
|
|
48
|
+
|
|
49
|
+
## Error Handling
|
|
50
|
+
|
|
51
|
+
The SDK throws `ORPCError` for API errors.
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
import { ORPCError } from "@orpc/client";
|
|
55
|
+
|
|
56
|
+
try {
|
|
57
|
+
await connect.contact.get({ id: "nonexistent" });
|
|
58
|
+
} catch (error) {
|
|
59
|
+
if (error instanceof ORPCError) {
|
|
60
|
+
console.error(error.code, error.message);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
```
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
createClient: () => createClient
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
|
|
27
|
+
// src/client.ts
|
|
28
|
+
var import_client = require("@orpc/client");
|
|
29
|
+
var import_fetch = require("@orpc/client/fetch");
|
|
30
|
+
var BASE_URL = "https://api.connect.nilovon.com";
|
|
31
|
+
function createClient(config) {
|
|
32
|
+
const link = new import_fetch.RPCLink({
|
|
33
|
+
url: `${BASE_URL}/rpc`,
|
|
34
|
+
headers: () => ({
|
|
35
|
+
Authorization: `Bearer ${config.apiKey}`
|
|
36
|
+
})
|
|
37
|
+
});
|
|
38
|
+
return (0, import_client.createORPCClient)(link);
|
|
39
|
+
}
|
|
40
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
+
0 && (module.exports = {
|
|
42
|
+
createClient
|
|
43
|
+
});
|
|
44
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/client.ts"],"sourcesContent":["export { createClient } from \"./client.js\";\nexport type { ConnectClient, ConnectConfig } from \"./client.js\";\n","import { createORPCClient } from \"@orpc/client\";\nimport { RPCLink } from \"@orpc/client/fetch\";\n\nexport interface ConnectConfig {\n /** API key from the dashboard (used as Bearer token). */\n apiKey: string;\n}\n\nconst BASE_URL = \"https://api.connect.nilovon.com\";\n\n/**\n * Create a fully-typed Connect API client.\n *\n * ```ts\n * import { createClient } from \"@nilovonjs/connect\";\n *\n * const client = createClient({ apiKey: \"sk_live_...\" });\n *\n * const { items } = await client.message.list({ limit: 10, offset: 0 });\n * ```\n */\nexport type ConnectClient = ReturnType<typeof createORPCClient>;\n\nexport function createClient(config: ConnectConfig): ConnectClient {\n const link = new RPCLink({\n url: `${BASE_URL}/rpc`,\n headers: () => ({\n Authorization: `Bearer ${config.apiKey}`,\n }),\n });\n\n return createORPCClient(link);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAiC;AACjC,mBAAwB;AAOxB,IAAM,WAAW;AAeV,SAAS,aAAa,QAAsC;AACjE,QAAM,OAAO,IAAI,qBAAQ;AAAA,IACvB,KAAK,GAAG,QAAQ;AAAA,IAChB,SAAS,OAAO;AAAA,MACd,eAAe,UAAU,OAAO,MAAM;AAAA,IACxC;AAAA,EACF,CAAC;AAED,aAAO,gCAAiB,IAAI;AAC9B;","names":[]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createORPCClient } from '@orpc/client';
|
|
2
|
+
|
|
3
|
+
interface ConnectConfig {
|
|
4
|
+
/** API key from the dashboard (used as Bearer token). */
|
|
5
|
+
apiKey: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Create a fully-typed Connect API client.
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { createClient } from "@nilovonjs/connect";
|
|
12
|
+
*
|
|
13
|
+
* const client = createClient({ apiKey: "sk_live_..." });
|
|
14
|
+
*
|
|
15
|
+
* const { items } = await client.message.list({ limit: 10, offset: 0 });
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
type ConnectClient = ReturnType<typeof createORPCClient>;
|
|
19
|
+
declare function createClient(config: ConnectConfig): ConnectClient;
|
|
20
|
+
|
|
21
|
+
export { type ConnectClient, type ConnectConfig, createClient };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createORPCClient } from '@orpc/client';
|
|
2
|
+
|
|
3
|
+
interface ConnectConfig {
|
|
4
|
+
/** API key from the dashboard (used as Bearer token). */
|
|
5
|
+
apiKey: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Create a fully-typed Connect API client.
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { createClient } from "@nilovonjs/connect";
|
|
12
|
+
*
|
|
13
|
+
* const client = createClient({ apiKey: "sk_live_..." });
|
|
14
|
+
*
|
|
15
|
+
* const { items } = await client.message.list({ limit: 10, offset: 0 });
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
type ConnectClient = ReturnType<typeof createORPCClient>;
|
|
19
|
+
declare function createClient(config: ConnectConfig): ConnectClient;
|
|
20
|
+
|
|
21
|
+
export { type ConnectClient, type ConnectConfig, createClient };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// src/client.ts
|
|
2
|
+
import { createORPCClient } from "@orpc/client";
|
|
3
|
+
import { RPCLink } from "@orpc/client/fetch";
|
|
4
|
+
var BASE_URL = "https://api.connect.nilovon.com";
|
|
5
|
+
function createClient(config) {
|
|
6
|
+
const link = new RPCLink({
|
|
7
|
+
url: `${BASE_URL}/rpc`,
|
|
8
|
+
headers: () => ({
|
|
9
|
+
Authorization: `Bearer ${config.apiKey}`
|
|
10
|
+
})
|
|
11
|
+
});
|
|
12
|
+
return createORPCClient(link);
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
createClient
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/client.ts"],"sourcesContent":["import { createORPCClient } from \"@orpc/client\";\nimport { RPCLink } from \"@orpc/client/fetch\";\n\nexport interface ConnectConfig {\n /** API key from the dashboard (used as Bearer token). */\n apiKey: string;\n}\n\nconst BASE_URL = \"https://api.connect.nilovon.com\";\n\n/**\n * Create a fully-typed Connect API client.\n *\n * ```ts\n * import { createClient } from \"@nilovonjs/connect\";\n *\n * const client = createClient({ apiKey: \"sk_live_...\" });\n *\n * const { items } = await client.message.list({ limit: 10, offset: 0 });\n * ```\n */\nexport type ConnectClient = ReturnType<typeof createORPCClient>;\n\nexport function createClient(config: ConnectConfig): ConnectClient {\n const link = new RPCLink({\n url: `${BASE_URL}/rpc`,\n headers: () => ({\n Authorization: `Bearer ${config.apiKey}`,\n }),\n });\n\n return createORPCClient(link);\n}\n"],"mappings":";AAAA,SAAS,wBAAwB;AACjC,SAAS,eAAe;AAOxB,IAAM,WAAW;AAeV,SAAS,aAAa,QAAsC;AACjE,QAAM,OAAO,IAAI,QAAQ;AAAA,IACvB,KAAK,GAAG,QAAQ;AAAA,IAChB,SAAS,OAAO;AAAA,MACd,eAAe,UAAU,OAAO,MAAM;AAAA,IACxC;AAAA,EACF,CAAC;AAED,SAAO,iBAAiB,IAAI;AAC9B;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nilovonjs/connect",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "TypeScript SDK for the Nilovon Connect API",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist"
|
|
7
|
+
],
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "./dist/index.cjs",
|
|
10
|
+
"module": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.js",
|
|
16
|
+
"require": "./dist/index.cjs"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@orpc/client": "^1.12.2"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"tsup": "^8.5.0",
|
|
27
|
+
"typescript": "^5"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsup",
|
|
31
|
+
"dev": "tsup --watch",
|
|
32
|
+
"check-types": "tsc --noEmit"
|
|
33
|
+
}
|
|
34
|
+
}
|