i2go-insurance-sdk
Official SDK for I2GO Insurance Services - Create and update insurance quotations and payment links using the Embedded API with exact interface compatibility.
Features
- 🚀 Easy Setup - Simple configuration with auth tokens and product slugs
- 🔒 Secure - Built-in authentication and error handling
- 📝 TypeScript Support - Full TypeScript definitions matching your embedded.ts
- 🎯 CRUD Operations - Both create (POST) and update (PUT) quotations
- 🏷️ Product-Based - Configure once, use everywhere
- 📚 Interface Compatibility - Exact match with your embedded.ts interfaces
Installation
npm install i2go-insurance-sdk
Quick Start
import { I2GOSDK } from 'i2go-insurance-sdk';
// Initialize the SDK
const sdk = new I2GOSDK({
baseOrigin: 'https://api.i2go.com',
authToken: 'your-auth-token',
product: 'your-product-slug',
productPlan: 'your-plan-slug', // optional
});
// Create a quotation
const quotation = await sdk.quickCreateQuotation({
effectiveDate: '2024-01-01',
policyHolder: {
firstName: 'John',
lastName: 'Doe',
email: 'john.doe@example.com',
addresses: [
{
addressType: ['DEFAULT'],
line1: '123 Main Street',
city: 'New York',
postalCode: '10001',
country: 'US',
},
],
},
insuredItems: [
{
name: 'Test Item',
value: 1000,
attributes: [
{ name: 'color', value: 'blue' },
{ name: 'model', value: 'premium' },
],
},
],
});
// Update a quotation
const updatedQuotation = await sdk.quickUpdateQuotation('quotation-id', {
policyHolder: {
firstName: 'Jane',
lastName: 'Doe',
email: 'jane.doe@example.com',
addresses: [
{
uuid: 'existing-address-uuid',
addressType: ['BILLING'],
line1: '456 Updated Street',
city: 'Updated City',
postalCode: '20002',
country: 'US',
},
],
},
});
// Create payment link
const paymentUrl = await sdk.quickCreatePaymentLink(quotation);
console.log('Payment URL:', paymentUrl);
Configuration
Required Configuration
Parameter | Type | Description |
---|---|---|
baseOrigin |
string | Base URL for the I2GO API (e.g., 'https://api.i2go.com') |
authToken |
string | Authentication token for API access |
product |
string | Product slug for insurance product |
Optional Configuration
Parameter | Type | Default | Description | |
---|---|---|---|---|
productPlan |
string | - | Specific product plan slug | |
apiVersion |
'v1' \ | 'v3' | 'v3' | API version to use |
headers |
object | {} | Additional headers to include in requests | |
customEndpoints |
object | {} | Custom endpoint configurations |
API Reference
I2GOSDK Class
Constructor
new I2GOSDK(config: I2GOSDKConfig)
interface I2GOSDKConfig {
baseOrigin: string;
authToken: string;
product: string;
productPlan?: string;
apiVersion?: 'v1' | 'v3';
headers?: Record<string, string>;
customEndpoints?: Record<string, EndpointType>;
}
Methods
quickCreateQuotation(data): Promise<EmbeddedCreationResponse>
Creates an insurance quotation using your exact embedded.ts interface structure.
Parameters:
effectiveDate
(string): Policy effective date (YYYY-MM-DD)policyHolder
(object): Policy holder information matching EmbeddedBpWithAddressCreationPayloadfirstName
(string): First namelastName
(string): Last nameemail
(string): Email addressaddresses
(array): Array of address objects matching EmbeddedAddressCreationPayloadaddressType
(string[]): Address types array (e.g., ['DEFAULT', 'BILLING'])line1
(string): Primary address linecity
(string): Citycountry
(string): CountrypostalCode
(string, optional): Postal codestate
(string, optional): Statedistrict
(string, optional): Districtbuilding
(string, optional): Building nameunitNo
(string, optional): Unit number
insuredItems
(array, optional): Items to insure matching PolicyVersionItemCreationPayloadname
(string): Item nameattributes
(array): Attribute objects with name/value pairsvalue
(number, optional): Item value
product
(string, optional): Override configured productplan
(string, optional): Override configured planpolicy_term
(string, optional): Policy termadditionalPartners
(array, optional): Additional partnerscoverages
(array, optional): Coverage configurationspolicy_attributes
(array, optional): Policy-level attributespolicy_headers
(array, optional): Policy headersprogress
(number, optional): Progress indicatoroptions
(object, optional): Additional optionsactivatePolicy
(boolean): Activate policy immediatelyskipRating
(boolean): Skip rating calculationcheck_business_rules
(boolean): Check business rulessaveToDB
(boolean): Save to databasesendEmail
(boolean): Send notification email
Returns: Promise<EmbeddedCreationResponse>
quickUpdateQuotation(quotationId, data): Promise<EmbeddedCreationResponse>
Updates an existing quotation using the EmbeddedUpdatePayload interface.
Parameters:
quotationId
(string): ID of the quotation to updatedata
(EmbeddedUpdatePayload): Update payload with UUID support for nested objects
Returns: Promise<EmbeddedCreationResponse>
quickCreatePaymentLink(quotation): Promise<string>
Creates a payment link for a quotation.
Parameters:
quotation
(string | EmbeddedCreationResponse): Quotation ID or response object
Returns: Promise<string>
- Payment URL
Configuration Methods
updateConfig(newConfig)
sdk.updateConfig({
baseOrigin: 'https://new-api.i2go.com',
authToken: 'new-token',
});
setAuthToken(token)
sdk.setAuthToken('new-auth-token');
setProduct(productId, planId?)
sdk.setProduct('new-product-slug', 'new-plan-slug');
getConfig()
const config = sdk.getConfig(); // Returns config without auth token
Utility Methods
callEndpoint(endpointName, body?, queryParams?, method?)
Advanced method for direct endpoint calls.
const result = await sdk.callEndpoint('embedded', payload, {}, 'POST');
TypeScript Support
The SDK includes comprehensive TypeScript definitions matching your embedded.ts exactly:
import type {
I2GOSDKConfig,
EmbeddedCreationPayload,
EmbeddedCreationResponse,
EmbeddedUpdatePayload,
EmbeddedBpWithAddressCreationPayload,
PolicyVersionItemCreationPayload,
AdditionalBusinessPartnerCreationPayload,
EmbeddedAddressCreationPayload,
EmbeddedCoveragePayload,
Attribute,
} from 'i2go-insurance-sdk';
Error Handling
The SDK provides detailed error information:
try {
const quotation = await sdk.quickCreateQuotation(data);
console.log('Success:', quotation);
} catch (error) {
console.error('Error:', error.message);
// Error includes status code and response details
}
Complete Example
import { I2GOSDK } from 'i2go-insurance-sdk';
const sdk = new I2GOSDK({
baseOrigin: process.env.I2GO_BASE_ORIGIN!,
authToken: process.env.I2GO_AUTH_TOKEN!,
product: process.env.I2GO_PRODUCT_SLUG!,
productPlan: process.env.I2GO_PLAN_SLUG,
});
async function createAndUpdateQuotationFlow() {
try {
// Create quotation (product/plan automatically used from config)
const quotation = await sdk.quickCreateQuotation({
effectiveDate: '2024-01-01',
policyHolder: {
firstName: 'John',
lastName: 'Doe',
email: 'john@example.com',
addresses: [
{
addressType: ['DEFAULT', 'BILLING'],
line1: '123 Main St',
city: 'New York',
postalCode: '10001',
country: 'US',
},
],
},
insuredItems: [
{
name: 'Vehicle',
value: 25000,
attributes: [
{ name: 'make', value: 'Toyota' },
{ name: 'model', value: 'Camry' },
{ name: 'year', value: 2023 },
],
},
],
policy_attributes: [{ name: 'special_discount', value: 'loyalty' }],
options: {
check_business_rules: true,
saveToDB: true,
sendEmail: true,
},
});
console.log('✅ Quotation created:', quotation.self.id);
// Update quotation
const updatedQuotation = await sdk.quickUpdateQuotation(quotation.self.id, {
policyHolder: {
firstName: 'John',
lastName: 'Smith', // Updated last name
email: 'john.smith@example.com',
addresses: [
{
uuid: 'existing-address-uuid', // Include UUID for update
addressType: ['DEFAULT'],
line1: '456 Updated Street',
city: 'New York',
postalCode: '10001',
country: 'US',
},
],
},
});
console.log('✅ Quotation updated:', updatedQuotation.self.id);
// Create payment link
const paymentUrl = await sdk.quickCreatePaymentLink(quotation);
console.log('✅ Payment URL:', paymentUrl);
return { quotation, updatedQuotation, paymentUrl };
} catch (error) {
console.error('❌ Error:', error.message);
throw error;
}
}
Interface Compatibility
This SDK exactly matches your embedded.ts
interfaces:
Address Structure
// Your embedded.ts structure
{
addressType: AddressTypeArray; // string[]
line1: string;
city: string;
country: string;
state?: string;
district?: string;
postalCode?: string;
building?: string;
unitNo?: string;
}
Insured Items Structure
// Your embedded.ts structure
{
name: string;
attributes: Attribute[]; // Array of {name, value} objects
value?: number;
}
Update Support with UUIDs
// Update operations support UUID targeting
{
uuid?: string; // For updating existing nested objects
// ... other fields
}
Requirements
- Node.js 16.0.0 or higher
- TypeScript 4.0.0 or higher (for TypeScript projects)
Dependencies
axios
^1.6.0 - HTTP client for API requeststslib
^2.6.0 - TypeScript runtime helpers
License
MIT License - see LICENSE file for details.
Support
For support, please contact your I2GO representative or create an issue in the repository.
Changelog
See CHANGELOG.md for version history and changes.