@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 CHANGED
@@ -1,194 +1,228 @@
1
1
  # InsurUp TypeScript SDK
2
2
 
3
- A comprehensive TypeScript SDK for the InsurUp platform, providing type-safe access to all insurance operations.
3
+ [![npm version](https://img.shields.io/npm/v/@insurup/sdk.svg)](https://www.npmjs.com/package/@insurup/sdk)
4
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-3178c6.svg)](https://www.typescriptlang.org/)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+ [![Zero Dependencies](https://img.shields.io/badge/dependencies-0-brightgreen.svg)](package.json)
4
7
 
5
- ## Features
8
+ Type-safe TypeScript SDK for the InsurUp insurance platform. Zero dependencies, tree-shakeable, works everywhere.
6
9
 
7
- - **Type-safe**: Full TypeScript support with strict typing
8
- - **Cross-platform**: Works in both browser and Node.js environments
9
- - **Modern**: ES modules, tree-shaking support, discriminated unions
10
- - **Comprehensive**: Covers all InsurUp API endpoints
11
- - **Faithful port**: 1:1 mapping with the C# SDK API
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
- # or
18
- yarn add @insurup/sdk
19
- # or
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
- baseUrl: 'https://api.insurup.com/api/',
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.kind === 'success') {
39
- console.log('Customer:', result.data);
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
- The SDK uses discriminated unions for type-safe result handling:
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('customer-id');
102
+ const result = await client.customers.getCustomer('id');
51
103
 
52
- // Type-safe result handling
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
- console.log('Customer data:', result.data);
56
- break;
114
+ return result.data;
57
115
  case 'server-error':
58
- console.error('Server error:', result.detail, result.status);
59
- break;
116
+ throw new Error(`${result.type}: ${result.message}`);
60
117
  case 'client-error':
61
- console.error('Client error:', result.type, result.exception);
62
- break;
118
+ throw new Error(`Network error: ${result.message}`);
63
119
  }
64
120
 
65
- // Or use type guards
66
- if (result.isSuccess) {
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
- ```typescript
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
- ## Available Operations
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
- ### Policy Management
99
- - `client.policies.getPolicyDetail()` - Get policy details
100
- - `client.policies.fetchPolicyDocument()` - Fetch policy document URL
101
- - `client.policies.sendPolicyDocumentToCustomer()` - Send document to customer
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
- ## Error Types
134
+ ---
105
135
 
106
- ### Server Errors
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
- ### Client Errors
115
- - `Timeout` - Request timeout
116
- - `HttpRequestFailed` - Network/HTTP errors
117
- - `JsonSerialization` - JSON serialization errors
118
- - `JsonDeserialization` - JSON parsing errors
119
- - `NullResponse` - Unexpected null response
120
-
121
- ## Advanced Usage
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
- ### Using Endpoints Directly
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
- ```typescript
126
- import { Endpoints } from '@insurup/sdk';
160
+ ---
127
161
 
128
- // Access endpoint constants
129
- const customerEndpoint = Endpoints.customers.getCustomer.render('customer-id');
130
- const policyEndpoint = Endpoints.policies.getPolicyDetail.render('policy-id');
131
- ```
162
+ ## Interceptors
132
163
 
133
- ### Custom HTTP Headers
164
+ Add logging, correlation IDs, or transform requests/responses:
134
165
 
135
166
  ```typescript
136
167
  const client = new DefaultInsurUpClient({
137
- customHeaders: {
138
- 'Authorization': `Bearer your-token`,
139
- 'X-API-Version': '1.0'
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
- ## Development Status
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
- 🚧 **In Progress:**
154
- - Additional contract types
155
- - Remaining client modules (Vehicle, Property, Coverage, etc.)
156
- - Comprehensive test coverage
187
+ ## API Clients
157
188
 
158
- 📋 **Planned:**
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
- ## TypeScript Support
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
- This SDK is built with TypeScript and provides full type safety:
211
+ ---
167
212
 
168
- ```typescript
169
- import type { CreateCustomerEndpointRequest, InsurUpResult, GetCustomerEndpointResponse } from '@insurup/sdk';
213
+ ## Compatibility
170
214
 
171
- // All request/response types are strongly typed
172
- const request: CreateCustomerEndpointRequest = {
173
- type: 'INDIVIDUAL',
174
- identityNumber: '12345678901',
175
- fillMissingFields: true
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
- // Results are discriminated unions for type safety
179
- const result: InsurUpResult<GetCustomerEndpointResponse> = await client.customers.getCustomer('id');
180
- ```
222
+ Dual ESM/CJS builds included. Full tree-shaking support.
181
223
 
182
- ## Browser Compatibility
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 License - see LICENSE file for details.
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.0",
113
- description: "TypeScript SDK for InsurUp platform - A comprehensive client library for insurance operations",
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
- "insurup"
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",