@insurup/sdk 0.0.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 ADDED
@@ -0,0 +1,194 @@
1
+ # InsurUp TypeScript SDK
2
+
3
+ A comprehensive TypeScript SDK for the InsurUp platform, providing type-safe access to all insurance operations.
4
+
5
+ ## Features
6
+
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
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ npm install @insurup/sdk
17
+ # or
18
+ yarn add @insurup/sdk
19
+ # or
20
+ pnpm add @insurup/sdk
21
+ ```
22
+
23
+ ## Quick Start
24
+
25
+ ```typescript
26
+ import { DefaultInsurUpClient } from '@insurup/sdk';
27
+
28
+ // Create client instance with token provider for OAuth
29
+ const client = new DefaultInsurUpClient({
30
+ baseUrl: 'https://api.insurup.com/api/',
31
+ timeoutMs: 30000,
32
+ tokenProvider: () => getAccessToken() // Your OAuth token provider
33
+ });
34
+
35
+ // Fetch customer data
36
+ const result = await client.customers.getCustomer('customer-id');
37
+
38
+ if (result.kind === 'success') {
39
+ console.log('Customer:', result.data);
40
+ } else {
41
+ console.error('Failed:', result.message);
42
+ }
43
+ ```
44
+
45
+ ## Result Handling
46
+
47
+ The SDK uses discriminated unions for type-safe result handling:
48
+
49
+ ```typescript
50
+ const result = await client.customers.getCustomer('customer-id');
51
+
52
+ // Type-safe result handling
53
+ switch (result.kind) {
54
+ case 'success':
55
+ console.log('Customer data:', result.data);
56
+ break;
57
+ case 'server-error':
58
+ console.error('Server error:', result.detail, result.status);
59
+ break;
60
+ case 'client-error':
61
+ console.error('Client error:', result.type, result.exception);
62
+ break;
63
+ }
64
+
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
76
+
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
+ });
86
+ ```
87
+
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
97
+
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
103
+
104
+ ## Error Types
105
+
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...
113
+
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
122
+
123
+ ### Using Endpoints Directly
124
+
125
+ ```typescript
126
+ import { Endpoints } from '@insurup/sdk';
127
+
128
+ // Access endpoint constants
129
+ const customerEndpoint = Endpoints.customers.getCustomer.render('customer-id');
130
+ const policyEndpoint = Endpoints.policies.getPolicyDetail.render('policy-id');
131
+ ```
132
+
133
+ ### Custom HTTP Headers
134
+
135
+ ```typescript
136
+ const client = new DefaultInsurUpClient({
137
+ customHeaders: {
138
+ 'Authorization': `Bearer your-token`,
139
+ 'X-API-Version': '1.0'
140
+ }
141
+ });
142
+ ```
143
+
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
152
+
153
+ 🚧 **In Progress:**
154
+ - Additional contract types
155
+ - Remaining client modules (Vehicle, Property, Coverage, etc.)
156
+ - Comprehensive test coverage
157
+
158
+ 📋 **Planned:**
159
+ - Complete API coverage
160
+ - Documentation generation
161
+ - Usage examples
162
+ - Performance optimizations
163
+
164
+ ## TypeScript Support
165
+
166
+ This SDK is built with TypeScript and provides full type safety:
167
+
168
+ ```typescript
169
+ import type { CreateCustomerEndpointRequest, InsurUpResult, GetCustomerEndpointResponse } from '@insurup/sdk';
170
+
171
+ // All request/response types are strongly typed
172
+ const request: CreateCustomerEndpointRequest = {
173
+ type: 'INDIVIDUAL',
174
+ identityNumber: '12345678901',
175
+ fillMissingFields: true
176
+ };
177
+
178
+ // Results are discriminated unions for type safety
179
+ const result: InsurUpResult<GetCustomerEndpointResponse> = await client.customers.getCustomer('id');
180
+ ```
181
+
182
+ ## Browser Compatibility
183
+
184
+ - Modern browsers with ES2022 support
185
+ - Node.js 18+
186
+ - Supports both ESM and CommonJS
187
+
188
+ ## License
189
+
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.