Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

i2go-insurance-sdk

tigerlab188MIT0.1.17TypeScript support: included

Official SDK for I2GO Insurance Services API - Embedded and Payment Services

insurance, api, sdk, i2go, embedded, payment, quotation

readme

i2go-insurance-sdk

npm version License: MIT

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',
    product: 'your-product-slug',
    plan: 'your-plan-slug',
    policyHolder: {
        category: 'Person', // Required field
        firstName: 'John',
        lastName: 'Doe',
        email: 'john.doe@example.com',
        addresses: [
            // Required field
            {
                addressType: 'DEFAULT',
                line1: '123 Main Street',
                city: 'New York',
                postalCode: '10001',
                country: 'US',
            },
        ],
    },
    insuredItems: [
        {
            name: 'Test Item',
            value: 1000,
            attributes: [
                { key: 'color', key_display: 'Color', value: 'blue', value_display: 'Blue' },
                { key: 'model', key_display: 'Model', value: 'premium', value_display: 'Premium' },
            ],
        },
    ],
    skipRating: false,
    check_business_rules: true,
    activatePolicy: false,
    sendEmail: true,
    saveToDB: true,
});

// Update a quotation
const updatedQuotation = await sdk.quickUpdateQuotation('quotation-id', {
    effectiveDate: '2024-01-01',
    product: 'your-product-slug',
    plan: 'your-plan-slug',
    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',
            },
        ],
    },
    insuredItems: [],
    skipRating: false,
    check_business_rules: true,
    activatePolicy: false,
    sendEmail: true,
    saveToDB: true,
});

// 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 the EmbeddedCreationPayload interface structure.

Required Parameters:

  • effectiveDate (string): Policy effective date (YYYY-MM-DD format)
  • product (string): Product slug
  • plan (string): Plan slug
  • policyHolder (EmbeddedBpWithAddressCreationPayload): Policy holder information
    • category (PolicyHolderCategory): Required - 'Person' | 'Group' | 'Company'
    • firstName (string): First name
    • lastName (string): Last name
    • email (string): Email address
    • addresses (EmbeddedAddressCreationPayload[]): Required - Array of address objects
      • addressType (AddressTypeArray): Array of address types (e.g., ['DEFAULT', 'BILLING'])
      • line1 (string): Primary address line
      • city (string): City
      • country (string): Country
      • postalCode (string, optional): Postal code
      • state (string, optional): State
      • district (string, optional): District
      • building (string, optional): Building name
      • unitNo (string, optional): Unit number
  • insuredItems (PolicyVersionItemCreationPayload[]): Items to insure
    • name (string): Item name
    • attributes (Attribute[]): Array of attribute objects with name/value pairs
    • value (number, optional): Item value
  • skipRating (boolean): Skip rating calculation
  • check_business_rules (boolean): Check business rules
  • activatePolicy (boolean): Activate policy immediately
  • sendEmail (boolean): Send notification email
  • saveToDB (boolean): Save to database

Optional Parameters:

  • registrationName (string): Registration name for companies
  • dob (string): Date of birth
  • gender (Gender): 'Male' | 'Female' | 'Others'
  • phoneMobile (string): Mobile phone number
  • nationality (string): Nationality
  • idType (number): ID type
  • extraData (object): Additional data
  • policy_attributes (Attribute[]): Policy-level attributes
  • policy_headers (Attribute[]): Policy headers
  • progress (number): Progress indicator
  • policy_term (PolicyTerm): Policy term
  • externalPolicyNumber (string): External policy number
  • additionalPartners (AdditionalBusinessPartnerCreationPayload[]): Additional partners
  • coverages (EmbeddedCoveragePayload[]): Coverage configurations

Returns: Promise<EmbeddedCreationResponse>

quickUpdateQuotation(quotationId, data): Promise<EmbeddedCreationResponse>

Updates an existing quotation using the same structure as creation.

Parameters:

  • quotationId (string): ID of the quotation to update
  • effectiveDate (string): Policy effective date (YYYY-MM-DD format)
  • product (string): Product slug
  • plan (string): Plan slug
  • policyHolder (EmbeddedBpWithAddressUpdatePayload): Policy holder information with UUID support
  • insuredItems (PolicyVersionItemUpdatePayload[]): Items to insure with UUID support
  • skipRating (boolean): Skip rating calculation
  • check_business_rules (boolean): Check business rules
  • activatePolicy (boolean): Activate policy immediately
  • sendEmail (boolean): Send notification email
  • saveToDB (boolean): Save to database

Returns: Promise<EmbeddedCreationResponse>

Creates a payment link for a quotation.

Parameters:

  • quotation (string | EmbeddedCreationResponse): Quotation ID or response object

Returns: Promise<string> - Payment URL

TypeScript Support

The SDK includes comprehensive TypeScript definitions matching your embedded.ts exactly:

import type {
    I2GOSDKConfig,
    EmbeddedCreationPayload,
    EmbeddedCreationResponse,
    EmbeddedUpdatePayload,
    EmbeddedBpWithAddressCreationPayload,
    EmbeddedBpWithAddressUpdatePayload,
    PolicyVersionItemCreationPayload,
    PolicyVersionItemUpdatePayload,
    AdditionalBusinessPartnerCreationPayload,
    EmbeddedAddressCreationPayload,
    EmbeddedCoveragePayload,
    Attribute,
    AddressTypeArray,
    PolicyHolderCategory,
    Gender,
    PolicyTerm,
} 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
    if (error.response?.status === 400) {
        console.log('Validation errors:', error.response.data);
    }
}

Complete Example

import { I2GOSDK } from 'i2go-insurance-sdk';
import type { EmbeddedCreationPayload } 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 with complete structure
        const quotationData: EmbeddedCreationPayload = {
            effectiveDate: '2024-01-01',
            product: 'vehicle-insurance',
            plan: 'comprehensive-plan',
            policyHolder: {
                category: 'Person',
                firstName: 'John',
                lastName: 'Doe',
                email: 'john@example.com',
                gender: 'Male',
                dob: '1990-01-01',
                phoneMobile: '+1234567890',
                addresses: [
                    {
                        addressType: ['DEFAULT', 'BILLING'],
                        line1: '123 Main St',
                        city: 'New York',
                        state: 'NY',
                        postalCode: '10001',
                        country: 'US',
                        unitNo: '4B',
                    },
                ],
            },
            insuredItems: [
                {
                    name: 'Vehicle',
                    value: 25000,
                    attributes: [
                        { key: 'make', key_display: 'Make', value: 'Toyota', value_display: 'Toyota' },
                        { key: 'model', key_display: 'Model', value: 'Camry', value_display: 'Camry' },
                        { key: 'year', key_display: 'Year', value: 2023, value_display: '2023' },
                        { key: 'vin', key_display: 'VIN', value: '1234567890ABCDEF', value_display: '1234567890ABCDEF' },
                    ],
                },
            ],
            additionalPartners: [
                {
                    relationType: 'BENEFICIARY',
                    category: 'Person',
                    firstName: 'Jane',
                    lastName: 'Smith',
                    email: 'jane@example.com',
                },
            ],
            coverages: [
                {
                    coverageType: 'comprehensive',
                    limit: 50000,
                    deductible: 500,
                },
            ],
            policy_attributes: [
                { key: 'discount_type', key_display: 'Discount Type', value: 'loyalty', value_display: 'Loyalty' },
                { key: 'payment_plan', key_display: 'Payment Plan', value: 'annual', value_display: 'Annual' },
            ],
            policy_term: 'Yearly',
            skipRating: false,
            check_business_rules: true,
            activatePolicy: false,
            sendEmail: true,
            saveToDB: true,
        };

        const quotation = await sdk.quickCreateQuotation(quotationData);
        console.log('✅ Quotation created:', quotation.self.id);

        // Update quotation with UUID support
        const updatedQuotation = await sdk.quickUpdateQuotation(quotation.self.id, {
            effectiveDate: '2024-01-01',
            product: 'vehicle-insurance',
            plan: 'comprehensive-plan',
            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',
                    },
                ],
            },
            insuredItems: [],
            skipRating: false,
            check_business_rules: true,
            activatePolicy: false,
            sendEmail: true,
            saveToDB: true,
        });

        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);
        if (error.response?.data) {
            console.error('Validation errors:', error.response.data);
        }
        throw error;
    }
}

Interface Compatibility

This SDK exactly matches your embedded.ts interfaces:

Address Structure (EmbeddedAddressCreationPayload)

{
    addressType: AddressTypeArray; // string[] or string
    line1: string;
    city: string;
    country: string;
    state?: string;
    district?: string;
    postalCode?: string;
    building?: string;
    unitNo?: string;
}

Policy Holder Structure (EmbeddedBpWithAddressCreationPayload)

{
    category: PolicyHolderCategory; // Required: 'Person' | 'Group' | 'Company'
    firstName: string;
    lastName: string;
    email: string;
    addresses: EmbeddedAddressCreationPayload[]; // Required
    registrationName?: string;
    dob?: string;
    gender?: Gender; // 'Male' | 'Female' | 'Others'
    phoneMobile?: string;
    nationality?: string;
    idType?: number;
    extraData?: Record<string, any>;
}

Insured Items Structure (PolicyVersionItemCreationPayload)

{
    name: string;
    attributes: Attribute[]; // Array of {key, key_display, value, value_display} objects
    value?: number;
}

Update Support with UUIDs

// Update operations support UUID targeting for nested objects
{
    uuid?: string; // For updating existing nested objects
    // ... other fields
}

changelog

Changelog

All notable changes to the I2GO Insurance SDK will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

[v0.1.16] - 2025-06-27

Changed

  • Refine SDK #9

Published

[v0.1.15] - 2025-06-27

Changed

  • Refine SDK #8

Published

[v0.1.14] - 2025-06-27

Changed

  • Refine SDK #7

Published

[v0.1.13] - 2025-06-27

Changed

  • Refine SDK #6

Published

[v0.1.12] - 2025-06-27

Changed

  • Refine SDK #5

Published

[v0.1.11] - 2025-06-27

Changed

  • Merge branch 'feature/I2G-23464' of github.com:tigerlab/InSurance into feature/I2G-23464

Published

[v0.1.10] - 2025-06-27

Changed

  • Merge branch 'feature/I2G-23464' of github.com:tigerlab/InSurance into feature/I2G-23464

Published

[v0.1.8] - 2025-06-27

Changed

  • Refine SDK #2

Published

[v0.1.4] - 2025-06-16

Changed

  • Merge branch 'feature/I2G-23464' of github.com:tigerlab/InSurance into feature/I2G-23464

Published

[Unreleased]

Added

  • Slug-based product identification system
  • Automatic slug-to-UUID conversion via backend API calls
  • I2GOSDKStandalone class for standalone usage
  • Enhanced product and product plan resolution
  • Improved error handling for product resolution
  • Support for default product plan selection when no specific plan is provided

Changed

  • BREAKING: Configuration now uses productSlug instead of productId
  • BREAKING: Configuration now uses productPlanSlug instead of productPlanId
  • BREAKING: Updated from I2GOSDK to I2GOSDKStandalone class
  • Simplified quotation creation with quickCreateQuotation method
  • Package name changed to i2go-insurance-sdk
  • Removed Jest testing dependencies for lighter package

Removed

  • Removed monorepo dependencies for true standalone operation
  • Removed Jest and testing infrastructure
  • Removed NX-specific build configurations

[0.1.1] - 2024-12-19

Published

Added

  • Complete TypeScript SDK for I2GO Insurance Services
  • quickCreateQuotation() method for creating insurance quotations
  • quickCreatePaymentLink() method for generating payment links
  • callEndpoint() method for advanced direct endpoint access
  • Comprehensive TypeScript type definitions
  • HTTP client with proper error handling
  • Configurable endpoint architecture
  • Support for custom endpoints and headers

Features

  • Insurance Quotations: Create and manage insurance quotations
  • Payment Processing: Generate payment links for quotations
  • Configuration Management: Dynamic config updates, auth token management
  • Error Handling: Detailed error messages and status codes
  • TypeScript Support: Full type safety with exported interfaces

Configuration

  • baseOrigin: Base API origin URL
  • authToken: Authentication token for API access
  • product: Product UUID for insurance products
  • productPlan: Optional product plan UUID
  • apiVersion: API version support (v1, v3)
  • customEndpoints: Custom endpoint configuration

Dependencies

  • axios ^1.6.0 for HTTP requests

[0.1.0] - 2024-12-19

Added

  • Initial development version
  • Core SDK architecture
  • Basic quotation and payment service functionality