@insurup/sdk 0.0.1 → 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 +164 -130
- package/dist/index.cjs +19 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +19 -3
- package/dist/index.js.map +1 -1
- package/package.json +19 -3
package/README.md
CHANGED
|
@@ -1,194 +1,228 @@
|
|
|
1
1
|
# InsurUp TypeScript SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@insurup/sdk)
|
|
4
|
+
[](https://www.typescriptlang.org/)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
[](package.json)
|
|
4
7
|
|
|
5
|
-
|
|
8
|
+
Type-safe TypeScript SDK for the InsurUp insurance platform. Zero dependencies, tree-shakeable, works everywhere.
|
|
6
9
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
-
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Table of Contents
|
|
13
|
+
|
|
14
|
+
- [Installation](#installation)
|
|
15
|
+
- [Quick Start](#quick-start)
|
|
16
|
+
- [Architecture](#architecture)
|
|
17
|
+
- [Result Handling](#result-handling)
|
|
18
|
+
- [Configuration](#configuration)
|
|
19
|
+
- [Interceptors](#interceptors)
|
|
20
|
+
- [API Clients](#api-clients)
|
|
21
|
+
- [Compatibility](#compatibility)
|
|
22
|
+
- [License](#license)
|
|
23
|
+
|
|
24
|
+
---
|
|
12
25
|
|
|
13
26
|
## Installation
|
|
14
27
|
|
|
15
28
|
```bash
|
|
16
29
|
npm install @insurup/sdk
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
```bash
|
|
20
33
|
pnpm add @insurup/sdk
|
|
21
34
|
```
|
|
22
35
|
|
|
36
|
+
```bash
|
|
37
|
+
yarn add @insurup/sdk
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
23
42
|
## Quick Start
|
|
24
43
|
|
|
25
44
|
```typescript
|
|
26
45
|
import { DefaultInsurUpClient } from '@insurup/sdk';
|
|
27
46
|
|
|
28
|
-
// Create client instance with token provider for OAuth
|
|
29
47
|
const client = new DefaultInsurUpClient({
|
|
30
|
-
|
|
31
|
-
timeoutMs: 30000,
|
|
32
|
-
tokenProvider: () => getAccessToken() // Your OAuth token provider
|
|
48
|
+
tokenProvider: () => getAccessToken(),
|
|
33
49
|
});
|
|
34
50
|
|
|
35
|
-
// Fetch customer data
|
|
36
51
|
const result = await client.customers.getCustomer('customer-id');
|
|
37
52
|
|
|
38
|
-
if (result.
|
|
39
|
-
console.log(
|
|
40
|
-
} else {
|
|
41
|
-
console.error('Failed:', result.message);
|
|
53
|
+
if (result.isSuccess) {
|
|
54
|
+
console.log(result.data);
|
|
42
55
|
}
|
|
43
56
|
```
|
|
44
57
|
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## Architecture
|
|
61
|
+
|
|
62
|
+
```mermaid
|
|
63
|
+
graph TB
|
|
64
|
+
subgraph SDK[DefaultInsurUpClient]
|
|
65
|
+
direction TB
|
|
66
|
+
HTTP[HttpTransport]
|
|
67
|
+
|
|
68
|
+
subgraph Clients[Specialized Clients]
|
|
69
|
+
direction LR
|
|
70
|
+
C1[customers]
|
|
71
|
+
C2[policies]
|
|
72
|
+
C3[proposals]
|
|
73
|
+
C4[vehicles]
|
|
74
|
+
C5[properties]
|
|
75
|
+
C6[coverage]
|
|
76
|
+
C7[cases]
|
|
77
|
+
C8[agents]
|
|
78
|
+
C9[webhooks]
|
|
79
|
+
C10[...]
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
App[Your Application] --> SDK
|
|
84
|
+
HTTP --> API[InsurUp API]
|
|
85
|
+
Clients --> HTTP
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
The SDK uses a **compositional architecture**:
|
|
89
|
+
|
|
90
|
+
- `DefaultInsurUpClient` aggregates 17 specialized clients
|
|
91
|
+
- All clients share a single `HttpTransport` instance
|
|
92
|
+
- Request/response interceptors hook into the transport layer
|
|
93
|
+
- Results use discriminated unions for type-safe error handling
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
45
97
|
## Result Handling
|
|
46
98
|
|
|
47
|
-
|
|
99
|
+
Every API call returns an `InsurUpResult<T>` — a discriminated union that's either a success or an error:
|
|
48
100
|
|
|
49
101
|
```typescript
|
|
50
|
-
const result = await client.customers.getCustomer('
|
|
102
|
+
const result = await client.customers.getCustomer('id');
|
|
51
103
|
|
|
52
|
-
//
|
|
104
|
+
// Pattern 1: Boolean check
|
|
105
|
+
if (result.isSuccess) {
|
|
106
|
+
console.log(result.data); // fully typed
|
|
107
|
+
} else {
|
|
108
|
+
console.error(result.message);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Pattern 2: Switch on kind
|
|
53
112
|
switch (result.kind) {
|
|
54
113
|
case 'success':
|
|
55
|
-
|
|
56
|
-
break;
|
|
114
|
+
return result.data;
|
|
57
115
|
case 'server-error':
|
|
58
|
-
|
|
59
|
-
break;
|
|
116
|
+
throw new Error(`${result.type}: ${result.message}`);
|
|
60
117
|
case 'client-error':
|
|
61
|
-
|
|
62
|
-
break;
|
|
118
|
+
throw new Error(`Network error: ${result.message}`);
|
|
63
119
|
}
|
|
64
120
|
|
|
65
|
-
//
|
|
66
|
-
|
|
67
|
-
// TypeScript knows this is Success<T>
|
|
68
|
-
console.log(result.data);
|
|
69
|
-
} else {
|
|
70
|
-
// TypeScript knows this is ServerError | ClientError
|
|
71
|
-
console.error(result.message);
|
|
72
|
-
}
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
## Configuration Options
|
|
121
|
+
// Pattern 3: Throw on error
|
|
122
|
+
import { getDataOrThrow } from '@insurup/sdk';
|
|
76
123
|
|
|
77
|
-
|
|
78
|
-
const client = new DefaultInsurUpClient({
|
|
79
|
-
baseUrl: 'https://api.insurup.com/api/', // API base URL
|
|
80
|
-
customHeaders: { // Custom headers for all requests
|
|
81
|
-
'X-Custom-Header': 'value'
|
|
82
|
-
},
|
|
83
|
-
userAgent: 'MyApp/1.0.0', // User agent (Node.js only)
|
|
84
|
-
timeoutMs: 30000 // Request timeout in milliseconds
|
|
85
|
-
});
|
|
124
|
+
const customer = getDataOrThrow(await client.customers.getCustomer('id'));
|
|
86
125
|
```
|
|
87
126
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
### Customer Management
|
|
91
|
-
- `client.customers.createCustomer()` - Create new customer
|
|
92
|
-
- `client.customers.getCustomer()` - Get customer by ID
|
|
93
|
-
- `client.customers.getCurrentCustomer()` - Get current customer
|
|
94
|
-
- `client.customers.updateCustomer()` - Update customer
|
|
95
|
-
- `client.customers.deleteCustomer()` - Delete customer
|
|
96
|
-
- Email and phone number management methods
|
|
127
|
+
### Error Types
|
|
97
128
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
- `
|
|
101
|
-
|
|
102
|
-
- `client.policies.setPolicyRepresentative()` - Set policy representative
|
|
129
|
+
| Kind | Types |
|
|
130
|
+
|------|-------|
|
|
131
|
+
| `server-error` | `Unauthorized`, `AccessDenied`, `ResourceNotFound`, `InputValidation`, `BusinessValidation`, `Upstream` |
|
|
132
|
+
| `client-error` | `Timeout`, `HttpRequestFailed`, `JsonDeserialization`, `NullResponse` |
|
|
103
133
|
|
|
104
|
-
|
|
134
|
+
---
|
|
105
135
|
|
|
106
|
-
|
|
107
|
-
- `AccessDenied` - Access denied (403)
|
|
108
|
-
- `Unauthorized` - Authentication required (401)
|
|
109
|
-
- `ResourceNotFound` - Resource not found (404)
|
|
110
|
-
- `InputValidation` - Validation errors (400)
|
|
111
|
-
- `BusinessValidation` - Business rule violations
|
|
112
|
-
- And more...
|
|
136
|
+
## Configuration
|
|
113
137
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
138
|
+
```typescript
|
|
139
|
+
const client = new DefaultInsurUpClient({
|
|
140
|
+
baseUrl: 'https://api.insurup.com/api/',
|
|
141
|
+
tokenProvider: () => getAccessToken(),
|
|
142
|
+
timeoutMs: 30000,
|
|
143
|
+
customHeaders: { 'X-Request-Source': 'my-app' },
|
|
144
|
+
retry: { retries: 3, backoffStrategy: 'exponential' },
|
|
145
|
+
onRequest: (config) => config,
|
|
146
|
+
onResponse: (result, config) => result,
|
|
147
|
+
});
|
|
148
|
+
```
|
|
122
149
|
|
|
123
|
-
|
|
150
|
+
| Option | Type | Default | Description |
|
|
151
|
+
|--------|------|---------|-------------|
|
|
152
|
+
| `baseUrl` | `string` | `https://api.insurup.com/api/` | API base URL |
|
|
153
|
+
| `tokenProvider` | `() => string \| Promise<string>` | — | OAuth token provider |
|
|
154
|
+
| `timeoutMs` | `number` | `30000` | Request timeout |
|
|
155
|
+
| `customHeaders` | `Record<string, string>` | — | Headers for all requests |
|
|
156
|
+
| `retry` | `RetryOptions` | — | Retry configuration |
|
|
157
|
+
| `onRequest` | `RequestInterceptor` | — | Pre-request hook |
|
|
158
|
+
| `onResponse` | `ResponseInterceptor` | — | Post-response hook |
|
|
124
159
|
|
|
125
|
-
|
|
126
|
-
import { Endpoints } from '@insurup/sdk';
|
|
160
|
+
---
|
|
127
161
|
|
|
128
|
-
|
|
129
|
-
const customerEndpoint = Endpoints.customers.getCustomer.render('customer-id');
|
|
130
|
-
const policyEndpoint = Endpoints.policies.getPolicyDetail.render('policy-id');
|
|
131
|
-
```
|
|
162
|
+
## Interceptors
|
|
132
163
|
|
|
133
|
-
|
|
164
|
+
Add logging, correlation IDs, or transform requests/responses:
|
|
134
165
|
|
|
135
166
|
```typescript
|
|
136
167
|
const client = new DefaultInsurUpClient({
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
168
|
+
tokenProvider: () => token,
|
|
169
|
+
|
|
170
|
+
onRequest: (config) => {
|
|
171
|
+
console.log(`→ ${config.method} ${config.url}`);
|
|
172
|
+
return {
|
|
173
|
+
...config,
|
|
174
|
+
headers: { ...config.headers, 'X-Correlation-ID': crypto.randomUUID() },
|
|
175
|
+
};
|
|
176
|
+
},
|
|
177
|
+
|
|
178
|
+
onResponse: (result, config) => {
|
|
179
|
+
console.log(`← ${config.url} ${result.isSuccess ? '✓' : '✗'}`);
|
|
180
|
+
return result;
|
|
181
|
+
},
|
|
141
182
|
});
|
|
142
183
|
```
|
|
143
184
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
✅ **Completed:**
|
|
147
|
-
- Core runtime (result types, error handling, HTTP transport)
|
|
148
|
-
- Endpoint definitions (1:1 port from C# SDK)
|
|
149
|
-
- Customer management client methods
|
|
150
|
-
- Policy management client methods
|
|
151
|
-
- Build system and packaging
|
|
185
|
+
---
|
|
152
186
|
|
|
153
|
-
|
|
154
|
-
- Additional contract types
|
|
155
|
-
- Remaining client modules (Vehicle, Property, Coverage, etc.)
|
|
156
|
-
- Comprehensive test coverage
|
|
187
|
+
## API Clients
|
|
157
188
|
|
|
158
|
-
|
|
159
|
-
- Complete API coverage
|
|
160
|
-
- Documentation generation
|
|
161
|
-
- Usage examples
|
|
162
|
-
- Performance optimizations
|
|
189
|
+
Access specialized clients through the main client instance:
|
|
163
190
|
|
|
164
|
-
|
|
191
|
+
| Client | Description |
|
|
192
|
+
|--------|-------------|
|
|
193
|
+
| `client.customers` | Customer profiles, contact info, health data |
|
|
194
|
+
| `client.policies` | Policy details, documents, representatives |
|
|
195
|
+
| `client.proposals` | Insurance proposals, comparisons, purchasing |
|
|
196
|
+
| `client.vehicles` | Vehicle data, brand/model lookups |
|
|
197
|
+
| `client.properties` | Property data, DASK earthquake insurance |
|
|
198
|
+
| `client.coverage` | Coverage configuration, coverage groups |
|
|
199
|
+
| `client.cases` | Service requests, claims, complaints |
|
|
200
|
+
| `client.agents` | Agent profiles, company connections |
|
|
201
|
+
| `client.agentBranches` | Branch management |
|
|
202
|
+
| `client.agentRoles` | Role-based access control |
|
|
203
|
+
| `client.agentUsers` | Agency staff management |
|
|
204
|
+
| `client.agentSetup` | Agent onboarding |
|
|
205
|
+
| `client.webhooks` | Event notifications, integrations |
|
|
206
|
+
| `client.insurance` | Companies, products, resource keys |
|
|
207
|
+
| `client.files` | File uploads and management |
|
|
208
|
+
| `client.languages` | Localization support |
|
|
209
|
+
| `client.templates` | Document and email templates |
|
|
165
210
|
|
|
166
|
-
|
|
211
|
+
---
|
|
167
212
|
|
|
168
|
-
|
|
169
|
-
import type { CreateCustomerEndpointRequest, InsurUpResult, GetCustomerEndpointResponse } from '@insurup/sdk';
|
|
213
|
+
## Compatibility
|
|
170
214
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
215
|
+
| Environment | Support |
|
|
216
|
+
|-------------|---------|
|
|
217
|
+
| Node.js | 18+ |
|
|
218
|
+
| Browsers | ES2022+ (Chrome 94+, Firefox 93+, Safari 15+) |
|
|
219
|
+
| Bun | ✓ |
|
|
220
|
+
| Deno | ✓ |
|
|
177
221
|
|
|
178
|
-
|
|
179
|
-
const result: InsurUpResult<GetCustomerEndpointResponse> = await client.customers.getCustomer('id');
|
|
180
|
-
```
|
|
222
|
+
Dual ESM/CJS builds included. Full tree-shaking support.
|
|
181
223
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
- Modern browsers with ES2022 support
|
|
185
|
-
- Node.js 18+
|
|
186
|
-
- Supports both ESM and CommonJS
|
|
224
|
+
---
|
|
187
225
|
|
|
188
226
|
## License
|
|
189
227
|
|
|
190
|
-
MIT
|
|
191
|
-
|
|
192
|
-
## Contributing
|
|
193
|
-
|
|
194
|
-
This SDK is automatically generated from the C# SDK. Please contribute to the main InsurUp repository.
|
|
228
|
+
[MIT](LICENSE)
|
package/dist/index.cjs
CHANGED
|
@@ -109,17 +109,33 @@ module.exports = __toCommonJS(index_exports);
|
|
|
109
109
|
// package.json
|
|
110
110
|
var package_default = {
|
|
111
111
|
name: "@insurup/sdk",
|
|
112
|
-
version: "0.1.
|
|
113
|
-
description: "TypeScript SDK for InsurUp platform
|
|
112
|
+
version: "0.1.1",
|
|
113
|
+
description: "Type-safe TypeScript SDK for the InsurUp insurance platform. Zero dependencies, tree-shakeable, works everywhere.",
|
|
114
114
|
keywords: [
|
|
115
|
+
"insurup",
|
|
115
116
|
"insurance",
|
|
116
117
|
"sdk",
|
|
117
118
|
"typescript",
|
|
118
119
|
"api-client",
|
|
119
|
-
"
|
|
120
|
+
"policy",
|
|
121
|
+
"claims",
|
|
122
|
+
"coverage",
|
|
123
|
+
"vehicle-insurance",
|
|
124
|
+
"property-insurance"
|
|
120
125
|
],
|
|
121
126
|
author: "InsurUp Team",
|
|
122
127
|
license: "MIT",
|
|
128
|
+
homepage: "https://github.com/InsurUp/ts-sdk#readme",
|
|
129
|
+
repository: {
|
|
130
|
+
type: "git",
|
|
131
|
+
url: "git+https://github.com/InsurUp/ts-sdk.git"
|
|
132
|
+
},
|
|
133
|
+
bugs: {
|
|
134
|
+
url: "https://github.com/InsurUp/ts-sdk/issues"
|
|
135
|
+
},
|
|
136
|
+
engines: {
|
|
137
|
+
node: ">=18"
|
|
138
|
+
},
|
|
123
139
|
type: "module",
|
|
124
140
|
sideEffects: false,
|
|
125
141
|
main: "./dist/index.cjs",
|