3.38.7-core β€’ Published 9 months ago

@iblai/iblai-api v3.38.7-core

Weekly downloads
-
License
ISC
Repository
-
Last release
9 months ago

πŸ”Œ ibl.ai API Client – TypeScript SDK Powered by OpenAPI

Welcome to the official API client for the ibl.ai platform, auto-generated from our OpenAPI schema and wrapped with love πŸ’™.

This SDK allows you to easily communicate with the Ibl API from both frontend and backend environments. It supports:

  • βœ… Native ESM usage via NPM
  • βœ… UMD usage via CDN (e.g. S3 or CloudFront)
  • βœ… Tree-shakable & type-safe
  • βœ… Works with fetch, React, Redux RTK Query, and more

πŸ“¦ Installation

Option 1: Use via NPM (ESM)

Install the package from the registry:

npm install @iblai/ibl-api

Option 2: Use via script tag (UMD)

If you're not using a bundler, you can load the SDK directly from S3/CDN:

<script src="https://cdn.iblai.com/ibl-api/1.0.0/index.umd.js"></script>

This exposes a global IblApi object you can use anywhere:

<script>
  IblApi.OpenAPI.BASE = 'https://api.iblai.com';
  IblApi.UserService.getCurrentUser().then(console.log);
</script>

πŸ”§ Configuration

The SDK provides a flexible OpenAPI config object to set:

  • Base URL
  • Authorization token
  • Custom headers

Using NPM (ESM)

// src/lib/api.ts
import { OpenAPI } from "@iblai/ibl-api";

OpenAPI.BASE =
  process.env.REACT_APP_API_DM_URL || "https://base.manager.iblai.app";
OpenAPI.TOKEN = async () => {
  return localStorage.getItem("dm_token");
};
OpenAPI.HEADERS = {
  Authorization: `Token ${localStorage.getItem("dm_token")}`,
};

Using UMD (CDN)

<script>
  IblApi.OpenAPI.BASE = "https://base.manager.iblai.com";
  OpenAPI.HEADERS = {
    Authorization: `Token ${localStorage.getIte("dm_token")`,
  };
</script>

πŸ’‘ Quick Examples

1. Fetch a User (ESM)

import { EngagementService } from "@iblai/ibl-api";

const courseCompletionPerCourse =
  await EngagementService.engagementOrgsCourseCompletionPerCourseRetrieve(
    "main"
  );
console.log(courseCompletionPerCourse);

2. Vanilla JS (CDN/UMD)

<script>
  IblApi.EngagementService.engagementOrgsCourseCompletionPerCourseRetrieve(
    "main"
  ).then((courseCompletionPerCourse) => {
    console.log(courseCompletionPerCourse);
  });
</script>

βš›οΈ Usage in React

import React, { useEffect, useState } from "react";
import { UserService, User } from "@iblai/ibl-api";

export const UserProfile = () => {
  const [courseCompletionPerCourse, setCourseCompletionPerCourse] =
    useState<CourseCompletionPerCourse | null>(null);

  useEffect(() => {
    EngagementService.engagementOrgsCourseCompletionPerCourseRetrieve().then(
      setCourseCompletionPerCourse
    );
  }, []);

  return <div></div>;
};

🧠 Using with Redux RTK Query

Step 1: Create API Slice

// src/store/iblApiSlice.ts
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react";
import { EngagementService } from "@iblai/ibl-api"; // Adjust the import based on your service

export const api = createApi({
  reducerPath: "iblApi",
  baseQuery: fetchBaseQuery({
    baseUrl: process.env.REACT_APP_IBL_DM_URL,
  }),
  endpoints: (builder) => ({
    engagementOrgsCourseCompletionPerCourseRetrieve: builder.query<any, void>({
      queryFn: async () => {
        try {
          const response =
            await EngagementService.engagementOrgsCourseCompletionPerCourseRetrieve(
              "main"
            );
          return { data: response };
        } catch (error) {
          return { error: error.message };
        }
      },
    }),
  }),
});

export const { useEngagementOrgsCourseCompletionPerCourseRetrieve } = api;

Step 2: Use in Component

const Profile = () => {
  const { data, isLoading } =
    useEngagementOrgsCourseCompletionPerCourseRetrieve();

  if (isLoading) return <p>Loading...</p>;
  return <p>Hello, {data?.name}!</p>;
};

☁️ Deployment on Vercel

When using the NPM version on Vercel:

  1. Set environment variable in your dashboard:

    REACT_APP_API_BASE_URL=https://base.manager.iblai.com

  2. Reference it in your OpenAPI.ts config.

  3. Don’t forget to trigger a redeploy after updating env vars.

πŸ§ͺ Testing

You can mock service methods easily:

jest
  .spyOn(EngagementService, "engagementOrgsCourseCompletionPerCourseRetrieve")
  .mockResolvedValue({
    data: [],
  });

Or use MSW (Mock Service Worker) for integration testing.

🧰 Pro Tips

  • πŸ” Use secure token storage (axd_token and dm_token)

  • 🎯 Tree-shake only the services you need

πŸ“ Directory Structure

If you inspect the package or generated source, you’ll find:

src/
  api-client/
    core/            # Internal helpers like fetch, configs
    models/          # Typed interfaces from OpenAPI
    services/        # Grouped endpoints (e.g., UserService)
    index.ts         # Exports everything
dist/
  index.cjs.js       # CommonJS
  index.esm.js       # ESM
  index.umd.js       # UMD (CDN-ready)
  types/
    index.d.ts       # Types

πŸ“š Resources

3.50.0-ai-plus

7 months ago

3.50.0-ai

7 months ago

3.50.0-core

7 months ago

3.49.1-ai-plus

7 months ago

3.49.1-ai

7 months ago

3.49.1-core

7 months ago

3.49.0-ai-plus

7 months ago

3.49.0-ai

7 months ago

3.49.0-core

7 months ago

3.48.5-ai-plus

7 months ago

3.48.5-ai

7 months ago

3.48.5-core

7 months ago

3.48.4-ai-plus

8 months ago

3.48.4-ai

8 months ago

3.48.4-core

8 months ago

3.48.3-ai-plus

8 months ago

3.48.3-ai

8 months ago

3.48.3-core

8 months ago

3.48.2-ai-plus

8 months ago

3.48.2-ai

8 months ago

3.48.2-core

8 months ago

3.48.1-ai-plus

8 months ago

3.48.1-ai

8 months ago

3.48.1-core

8 months ago

3.48.0-ai-plus

8 months ago

3.48.0-ai

8 months ago

3.48.0-core

8 months ago

3.47.2-ai-plus

8 months ago

3.47.2-ai

8 months ago

3.47.2-core

8 months ago

3.47.1-ai-plus

8 months ago

3.47.1-ai

8 months ago

3.47.1-core

8 months ago

3.47.0-ai-plus

8 months ago

3.47.0-ai

8 months ago

3.47.0-core

8 months ago

3.46.1-ai-plus

8 months ago

3.46.1-ai

8 months ago

3.46.1-core

8 months ago

3.46.0-ai-plus

8 months ago

3.46.0-ai

8 months ago

3.46.0-core

8 months ago

3.45.15-ai-plus

8 months ago

3.45.15-ai

8 months ago

3.45.15-core

8 months ago

3.45.14-ai-plus

8 months ago

3.45.14-ai

8 months ago

3.45.14-core

8 months ago

3.45.13-ai-plus

8 months ago

3.45.13-ai

8 months ago

3.45.13-core

8 months ago

3.45.12-ai-plus

8 months ago

3.45.12-ai

8 months ago

3.45.12-core

8 months ago

3.45.11-ai-plus

8 months ago

3.45.11-ai

8 months ago

3.45.11-core

8 months ago

3.45.10-ai-plus

8 months ago

3.45.10-ai

8 months ago

3.45.10-core

8 months ago

3.45.9-ai-plus

8 months ago

3.45.9-ai

8 months ago

3.45.9-core

8 months ago

3.45.8-ai-plus

8 months ago

3.45.8-ai

8 months ago

3.45.8-core

8 months ago

3.45.7-ai-plus

8 months ago

3.45.7-ai

8 months ago

3.45.7-core

8 months ago

3.45.6-ai

8 months ago

3.45.6-core

8 months ago

0.0.3-core

8 months ago

0.0.2-core

8 months ago

0.0.1-core

8 months ago

3.45.5-ai-plus

8 months ago

3.45.5-ai

8 months ago

3.45.5-core

8 months ago

3.45.4-ai-plus

8 months ago

3.45.4-ai

8 months ago

3.45.4-core

8 months ago

3.45.3-ai-plus

8 months ago

3.45.3-ai

8 months ago

3.45.3-core

8 months ago

3.45.2-ai-plus

8 months ago

3.45.2-ai

8 months ago

3.45.2-core

8 months ago

3.45.1-ai-plus

8 months ago

3.45.1-ai

8 months ago

3.45.1-core

8 months ago

3.45.0-ai-plus

8 months ago

3.45.0-ai

8 months ago

3.45.0-core

8 months ago

3.44.2-ai-plus

8 months ago

3.44.2-ai

8 months ago

3.44.2-core

8 months ago

3.44.1-ai-plus

8 months ago

3.44.1-ai

8 months ago

3.44.1-core

8 months ago

3.44.0-ai-plus

8 months ago

3.44.0-ai

8 months ago

3.44.0-core

8 months ago

3.43.0-ai-plus

8 months ago

3.43.0-ai

8 months ago

3.43.0-core

8 months ago

3.42.3-ai-plus

8 months ago

3.42.3-ai

8 months ago

3.42.3-core

8 months ago

3.42.2-ai-plus

8 months ago

3.42.2-ai

8 months ago

3.42.2-core

8 months ago

3.42.1-ai-plus

8 months ago

3.42.1-ai

8 months ago

3.42.1-core

8 months ago

3.42.0-ai-plus

8 months ago

3.42.0-ai

8 months ago

3.42.0-core

8 months ago

3.41.0-ai-plus

8 months ago

3.41.0-ai

8 months ago

3.41.0-core

8 months ago

3.40.1-ai-plus

8 months ago

3.40.1-ai

8 months ago

3.40.1-core

8 months ago

3.40.0-ai-plus

8 months ago

3.40.0-ai

8 months ago

3.40.0-core

8 months ago

3.39.4-ai

8 months ago

3.39.4-core

8 months ago

3.39.3-ai-plus

8 months ago

3.39.3-ai

8 months ago

3.39.3-core

8 months ago

3.39.2-ai-plus

8 months ago

3.39.2-ai

8 months ago

3.39.2-core

8 months ago

3.39.1-ai-plus

8 months ago

3.39.1-ai

8 months ago

3.39.1-core

8 months ago

3.38.11-ai-plus

9 months ago

3.38.11-ai

9 months ago

3.38.11-core

9 months ago

3.38.10-ai-plus

9 months ago

3.38.10-ai

9 months ago

3.38.10-core

9 months ago

3.38.9-ai-plus

9 months ago

3.38.9-ai

9 months ago

3.38.9-core

9 months ago

3.38.8-ai-plus

9 months ago

3.38.8-ai

9 months ago

3.38.8-core

9 months ago

3.38.7-ai-plus

9 months ago

3.38.7-ai

9 months ago

3.38.7-core

9 months ago

3.38.6-ai-plus

9 months ago

3.38.6-ai

9 months ago

3.38.6-core

9 months ago

3.38.5-ai-plus

9 months ago

3.38.5-ai

9 months ago

3.38.5-core

9 months ago

3.38.4-ai-plus

9 months ago

3.38.4-ai

9 months ago

3.38.4-core

9 months ago

3.38.3-ai-plus

9 months ago

3.38.3-ai

9 months ago

3.38.3-core

9 months ago

3.38.2-ai-plus

9 months ago

3.38.2-ai

9 months ago

3.38.2-core

9 months ago

3.38.1-ai-plus

9 months ago

3.38.1-ai

9 months ago

3.38.1-core

9 months ago

3.38.0-ai-plus

9 months ago

3.38.0-ai

9 months ago

3.38.0-core

9 months ago

3.37.0-ai-plus

9 months ago

3.37.0-ai

9 months ago

3.37.0-core

9 months ago

3.36.1-ai-plus

9 months ago

3.36.1-ai

9 months ago

3.36.1-core

9 months ago

3.36.0-ai-plus

9 months ago

3.36.0-ai

9 months ago

3.36.0-core

9 months ago

3.35.13-ai-plus

9 months ago

3.35.13-ai

9 months ago

3.35.13-core

9 months ago

3.35.12-ai-plus

9 months ago

3.35.12-ai

9 months ago

3.35.12-core

9 months ago

3.35.11-ai-plus

9 months ago

3.35.11-ai

9 months ago

3.35.11-core

9 months ago

3.35.10-ai-plus

9 months ago

3.35.10-ai

9 months ago

3.35.10-core

9 months ago

3.35.9-ai-plus

9 months ago

3.35.9-ai

9 months ago

3.35.9-core

9 months ago

3.35.8-ai-plus

9 months ago

3.35.8-ai

9 months ago

3.35.8-core

9 months ago

3.35.7-ai

9 months ago

3.35.7-core

9 months ago

3.35.6-ai-plus

9 months ago

3.35.6-ai

9 months ago

3.35.6-core

9 months ago

3.35.5-ai-plus

9 months ago

3.35.5-ai

9 months ago

3.35.5-core

9 months ago

3.35.4-ai-plus

9 months ago

3.35.4-ai

9 months ago

3.35.4-core

9 months ago

3.35.3-ai-plus

9 months ago

3.35.3-ai

9 months ago

3.35.3-core

9 months ago

3.35.2-ai-plus

9 months ago

3.35.2-ai

9 months ago

3.35.2-core

9 months ago

3.35.1-ai-plus

9 months ago

3.35.1-ai

9 months ago

3.35.1-core

9 months ago

3.35.0-ai-plus

9 months ago

3.35.0-ai

9 months ago

3.35.0-core

9 months ago

3.34.5-ai-plus

9 months ago

3.34.5-ai

9 months ago

3.34.5-core

9 months ago