Detalhes do pacote

i2go-insurance-sdk

tigerlab188MIT0.1.11

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

insurance, api, sdk, i2go

readme (leia-me)

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',
    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 EmbeddedBpWithAddressCreationPayload
    • firstName (string): First name
    • lastName (string): Last name
    • email (string): Email address
    • addresses (array): Array of address objects matching EmbeddedAddressCreationPayload
      • addressType (string[]): Address types array (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 (array, optional): Items to insure matching PolicyVersionItemCreationPayload
    • name (string): Item name
    • attributes (array): Attribute objects with name/value pairs
    • value (number, optional): Item value
  • product (string, optional): Override configured product
  • plan (string, optional): Override configured plan
  • policy_term (string, optional): Policy term
  • additionalPartners (array, optional): Additional partners
  • coverages (array, optional): Coverage configurations
  • policy_attributes (array, optional): Policy-level attributes
  • policy_headers (array, optional): Policy headers
  • progress (number, optional): Progress indicator
  • options (object, optional): Additional options
    • activatePolicy (boolean): Activate policy immediately
    • skipRating (boolean): Skip rating calculation
    • check_business_rules (boolean): Check business rules
    • saveToDB (boolean): Save to database
    • sendEmail (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 update
  • data (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 requests
  • tslib ^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.

changelog (log de mudanças)

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.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