@iblai/iblai-js 1.0.0
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/LICENSE +21 -0
- package/README.md +88 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.esm.js +4 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/next/index.d.ts +1 -0
- package/dist/next/index.esm.js +2 -0
- package/dist/next/index.esm.js.map +1 -0
- package/dist/next/index.js +13 -0
- package/dist/next/index.js.map +1 -0
- package/dist/next/src/data-layer/index.d.ts +9 -0
- package/dist/next/src/index.d.ts +17 -0
- package/dist/next/src/native-components/index.d.ts +9 -0
- package/dist/next/src/next/index.d.ts +26 -0
- package/dist/next/src/sso/index.d.ts +39 -0
- package/dist/next/src/web-containers/index.d.ts +9 -0
- package/dist/next/src/web-utils/index.d.ts +9 -0
- package/dist/next/src/web-utils/utils/auth.d.ts +180 -0
- package/dist/src/data-layer/index.d.ts +9 -0
- package/dist/src/index.d.ts +17 -0
- package/dist/src/native-components/index.d.ts +9 -0
- package/dist/src/next/index.d.ts +26 -0
- package/dist/src/sso/index.d.ts +39 -0
- package/dist/src/web-containers/index.d.ts +9 -0
- package/dist/src/web-utils/index.d.ts +9 -0
- package/dist/src/web-utils/utils/auth.d.ts +180 -0
- package/dist/sso/index.d.ts +1 -0
- package/dist/sso/index.esm.js +2 -0
- package/dist/sso/index.esm.js.map +1 -0
- package/dist/sso/index.js +13 -0
- package/dist/sso/index.js.map +1 -0
- package/dist/sso/src/data-layer/index.d.ts +9 -0
- package/dist/sso/src/index.d.ts +17 -0
- package/dist/sso/src/native-components/index.d.ts +9 -0
- package/dist/sso/src/next/index.d.ts +26 -0
- package/dist/sso/src/sso/index.d.ts +39 -0
- package/dist/sso/src/web-containers/index.d.ts +9 -0
- package/dist/sso/src/web-utils/index.d.ts +9 -0
- package/dist/sso/src/web-utils/utils/auth.d.ts +180 -0
- package/package.json +100 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 IBL AI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# @iblai/iblai-js
|
|
2
|
+
|
|
3
|
+
Unified package for IBL AI - includes all exports from data-layer, web-utils, and web-containers.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @iblai/iblai-js
|
|
9
|
+
# or
|
|
10
|
+
yarn add @iblai/iblai-js
|
|
11
|
+
# or
|
|
12
|
+
pnpm add @iblai/iblai-js
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
This package re-exports everything from:
|
|
18
|
+
- `@iblai/data-layer` - API slices, hooks, and data management
|
|
19
|
+
- `@iblai/web-utils` - Utilities, providers, and helper functions
|
|
20
|
+
- `@iblai/web-containers` - UI components and containers
|
|
21
|
+
|
|
22
|
+
### Example
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
// Import everything from a single package
|
|
26
|
+
import {
|
|
27
|
+
// From data-layer
|
|
28
|
+
useGetMfeContextQuery,
|
|
29
|
+
authApiSlice,
|
|
30
|
+
|
|
31
|
+
// From web-utils
|
|
32
|
+
AuthProvider,
|
|
33
|
+
TenantProvider,
|
|
34
|
+
|
|
35
|
+
// From web-containers
|
|
36
|
+
Button,
|
|
37
|
+
Card,
|
|
38
|
+
Input
|
|
39
|
+
} from '@iblai/iblai-js';
|
|
40
|
+
|
|
41
|
+
// Use as normal
|
|
42
|
+
function MyComponent() {
|
|
43
|
+
const { data } = useGetMfeContextQuery();
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<AuthProvider {...authProps}>
|
|
47
|
+
<Button>Click me</Button>
|
|
48
|
+
</AuthProvider>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## What's Included
|
|
54
|
+
|
|
55
|
+
### From @iblai/data-layer
|
|
56
|
+
- RTK Query API slices for all services
|
|
57
|
+
- Redux store configuration
|
|
58
|
+
- Data fetching hooks
|
|
59
|
+
- Types and interfaces
|
|
60
|
+
|
|
61
|
+
### From @iblai/web-utils
|
|
62
|
+
- Authentication providers
|
|
63
|
+
- Tenant providers
|
|
64
|
+
- Utility functions
|
|
65
|
+
- Constants and helpers
|
|
66
|
+
|
|
67
|
+
### From @iblai/web-containers
|
|
68
|
+
- UI components (buttons, forms, cards, etc.)
|
|
69
|
+
- Layout components
|
|
70
|
+
- Custom hooks
|
|
71
|
+
- Styled components
|
|
72
|
+
|
|
73
|
+
## Peer Dependencies
|
|
74
|
+
|
|
75
|
+
This package requires the following peer dependencies:
|
|
76
|
+
- `react` ^19.1.0
|
|
77
|
+
- `react-dom` ^19.1.0
|
|
78
|
+
- `@reduxjs/toolkit` ^2.7.0
|
|
79
|
+
- `react-redux` ^9.2.0
|
|
80
|
+
- `@iblai/iblai-api` 4.64.2-ai
|
|
81
|
+
|
|
82
|
+
## License
|
|
83
|
+
|
|
84
|
+
ISC
|
|
85
|
+
|
|
86
|
+
## Author
|
|
87
|
+
|
|
88
|
+
iblai
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var dataLayer = require('@iblai/data-layer');
|
|
4
|
+
var webUtils = require('@iblai/web-utils');
|
|
5
|
+
var webContainers = require('@iblai/web-containers');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
Object.keys(dataLayer).forEach(function (k) {
|
|
10
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () { return dataLayer[k]; }
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
Object.keys(webUtils).forEach(function (k) {
|
|
16
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () { return webUtils[k]; }
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
Object.keys(webContainers).forEach(function (k) {
|
|
22
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get: function () { return webContainers[k]; }
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@iblai/web-containers/next';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var next = require('@iblai/web-containers/next');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
Object.keys(next).forEach(function (k) {
|
|
8
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () { return next[k]; }
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @iblai/iblai-js - TypeScript SDK for IBL AI Platform
|
|
3
|
+
*
|
|
4
|
+
* A unified SDK providing:
|
|
5
|
+
* - Data Layer: RTK Query API slices and data management
|
|
6
|
+
* - Web Utils: React providers, hooks, and utilities
|
|
7
|
+
* - Web Containers: React UI components for web
|
|
8
|
+
* - Native Components: React Native components for mobile
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { useGetMentorsQuery, AuthProvider, Button } from '@iblai/iblai-js';
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export * from './data-layer';
|
|
16
|
+
export * from './web-utils';
|
|
17
|
+
export * from './web-containers';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Next.js-specific components and hooks
|
|
3
|
+
*
|
|
4
|
+
* This module contains React components and hooks that require Next.js
|
|
5
|
+
* as a peer dependency. These components use Next.js-specific APIs like
|
|
6
|
+
* `next/navigation`, `next/router`, `next/image`, and `next/link`.
|
|
7
|
+
*
|
|
8
|
+
* For non-Next.js React applications, you'll need to implement
|
|
9
|
+
* framework-agnostic alternatives. See the SDK documentation for examples.
|
|
10
|
+
*
|
|
11
|
+
* @module next
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* // In a Next.js application
|
|
16
|
+
* import { SsoLogin, ErrorPage, UserProfileDropdown } from '@iblai/iblai-js/next';
|
|
17
|
+
*
|
|
18
|
+
* // Use the components as normal
|
|
19
|
+
* <SsoLogin
|
|
20
|
+
* localStorageKeys={{...}}
|
|
21
|
+
* redirectPathKey="redirect-to"
|
|
22
|
+
* defaultRedirectPath="/"
|
|
23
|
+
* />
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export * from '@iblai/web-containers/next';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SSO Utilities - Framework agnostic
|
|
3
|
+
*
|
|
4
|
+
* This module contains utilities for handling SSO authentication callbacks.
|
|
5
|
+
* These utilities work in any React application (Next.js, Create React App,
|
|
6
|
+
* Vite, React Router, etc.) without requiring Next.js.
|
|
7
|
+
*
|
|
8
|
+
* For Next.js applications that want to use the pre-built `SsoLogin` component,
|
|
9
|
+
* import from `@iblai/iblai-js/next` instead.
|
|
10
|
+
*
|
|
11
|
+
* @module sso
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* // React Router implementation
|
|
16
|
+
* import { useEffect } from 'react';
|
|
17
|
+
* import { useNavigate, useSearchParams } from 'react-router-dom';
|
|
18
|
+
* import { handleSsoCallback } from '@iblai/iblai-js/sso';
|
|
19
|
+
*
|
|
20
|
+
* export function SsoLoginPage() {
|
|
21
|
+
* const navigate = useNavigate();
|
|
22
|
+
* const [searchParams] = useSearchParams();
|
|
23
|
+
*
|
|
24
|
+
* useEffect(() => {
|
|
25
|
+
* handleSsoCallback({
|
|
26
|
+
* queryParamData: searchParams.get('data'),
|
|
27
|
+
* redirectPathKey: 'redirect-to',
|
|
28
|
+
* defaultRedirectPath: '/',
|
|
29
|
+
* onRedirect: (path) => navigate(path),
|
|
30
|
+
* onLoginSuccess: (data) => console.log('Login successful', data),
|
|
31
|
+
* onLoginError: (error) => console.error('Login failed', error),
|
|
32
|
+
* });
|
|
33
|
+
* }, [searchParams, navigate]);
|
|
34
|
+
*
|
|
35
|
+
* return null; // Redirect-only page
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export * from '@iblai/web-containers/sso';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Web Utils - Utilities, providers, hooks, and helper functions
|
|
3
|
+
*
|
|
4
|
+
* This module contains React providers, custom hooks, utility functions,
|
|
5
|
+
* and helper methods for building IBL AI applications.
|
|
6
|
+
*
|
|
7
|
+
* @module web-utils
|
|
8
|
+
*/
|
|
9
|
+
export * from '@iblai/web-utils';
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authentication and Authorization Utilities
|
|
3
|
+
*
|
|
4
|
+
* This module provides utility functions for handling authentication flows,
|
|
5
|
+
* including redirects to auth SPA, cookie management, and session handling.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Check if the current window is inside an iframe
|
|
9
|
+
* @returns {boolean} True if running in an iframe, false otherwise
|
|
10
|
+
*/
|
|
11
|
+
export declare function isInIframe(): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Send a message to the parent website (when in iframe)
|
|
14
|
+
* @param payload - The data to send to parent window
|
|
15
|
+
*/
|
|
16
|
+
export declare function sendMessageToParentWebsite(payload: unknown): void;
|
|
17
|
+
/**
|
|
18
|
+
* Delete a cookie with specific name, path, and domain
|
|
19
|
+
* @param name - Cookie name
|
|
20
|
+
* @param path - Cookie path
|
|
21
|
+
* @param domain - Cookie domain
|
|
22
|
+
*/
|
|
23
|
+
export declare function deleteCookie(name: string, path: string, domain: string): void;
|
|
24
|
+
/**
|
|
25
|
+
* Get all possible domain parts for cookie deletion
|
|
26
|
+
* @param domain - The domain to split
|
|
27
|
+
* @returns Array of domain parts
|
|
28
|
+
* @example
|
|
29
|
+
* getDomainParts('app.example.com') // returns ['app.example.com', 'example.com', 'com']
|
|
30
|
+
*/
|
|
31
|
+
export declare function getDomainParts(domain: string): string[];
|
|
32
|
+
/**
|
|
33
|
+
* Delete a cookie across all possible domain variations
|
|
34
|
+
* @param name - Cookie name to delete
|
|
35
|
+
* @param childDomain - The current domain
|
|
36
|
+
*/
|
|
37
|
+
export declare function deleteCookieOnAllDomains(name: string, childDomain: string): void;
|
|
38
|
+
/**
|
|
39
|
+
* Get the parent domain from a given domain
|
|
40
|
+
* @param domain - The domain to process
|
|
41
|
+
* @returns The parent domain (e.g., 'app.example.com' → '.example.com')
|
|
42
|
+
*/
|
|
43
|
+
export declare function getParentDomain(domain?: string): string;
|
|
44
|
+
/**
|
|
45
|
+
* Set a cookie for authentication with cross-domain support
|
|
46
|
+
* @param name - Cookie name
|
|
47
|
+
* @param value - Cookie value
|
|
48
|
+
* @param days - Number of days until expiration (default: 365)
|
|
49
|
+
*/
|
|
50
|
+
export declare function setCookieForAuth(name: string, value: string, days?: number): void;
|
|
51
|
+
/**
|
|
52
|
+
* Clear all cookies for the current domain
|
|
53
|
+
*/
|
|
54
|
+
export declare function clearCookies(): void;
|
|
55
|
+
/**
|
|
56
|
+
* Check if user is currently logged in
|
|
57
|
+
* @param tokenKey - The localStorage key for the auth token (default: 'axd_token')
|
|
58
|
+
* @returns True if logged in, false otherwise
|
|
59
|
+
*/
|
|
60
|
+
export declare function isLoggedIn(tokenKey?: string): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Extract platform/tenant key from URL
|
|
63
|
+
* @param url - The URL to parse
|
|
64
|
+
* @param pattern - RegExp pattern to match platform key (default matches /platform/[key]/...)
|
|
65
|
+
* @returns The platform key or null if not found
|
|
66
|
+
*/
|
|
67
|
+
export declare function getPlatformKey(url: string, pattern?: RegExp): string | null;
|
|
68
|
+
export interface RedirectToAuthSpaOptions {
|
|
69
|
+
/** URL to redirect to after auth (defaults to current path + search) */
|
|
70
|
+
redirectTo?: string;
|
|
71
|
+
/** Platform/tenant key */
|
|
72
|
+
platformKey?: string;
|
|
73
|
+
/** Whether this is a logout action */
|
|
74
|
+
logout?: boolean;
|
|
75
|
+
/** Whether to save redirect path to localStorage (default: true) */
|
|
76
|
+
saveRedirect?: boolean;
|
|
77
|
+
/** Auth SPA base URL */
|
|
78
|
+
authUrl: string;
|
|
79
|
+
/** Current app/platform identifier (e.g., 'mentor', 'skills') */
|
|
80
|
+
appName: string;
|
|
81
|
+
/** Query param names */
|
|
82
|
+
queryParams?: {
|
|
83
|
+
app?: string;
|
|
84
|
+
redirectTo?: string;
|
|
85
|
+
tenant?: string;
|
|
86
|
+
};
|
|
87
|
+
/** localStorage key for saving redirect path */
|
|
88
|
+
redirectPathStorageKey?: string;
|
|
89
|
+
/** Cookie names for cross-SPA sync */
|
|
90
|
+
cookieNames?: {
|
|
91
|
+
currentTenant?: string;
|
|
92
|
+
userData?: string;
|
|
93
|
+
tenant?: string;
|
|
94
|
+
logoutTimestamp?: string;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Redirect to authentication SPA for login/logout
|
|
99
|
+
*
|
|
100
|
+
* This function handles the complete authentication flow:
|
|
101
|
+
* - Clears localStorage and cookies on logout
|
|
102
|
+
* - Saves redirect path for post-auth return
|
|
103
|
+
* - Handles iframe scenarios
|
|
104
|
+
* - Syncs logout across multiple SPAs via cookies
|
|
105
|
+
*
|
|
106
|
+
* @param options - Configuration options for the redirect
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```tsx
|
|
110
|
+
* // Basic usage
|
|
111
|
+
* redirectToAuthSpa({
|
|
112
|
+
* authUrl: 'https://auth.example.com',
|
|
113
|
+
* appName: 'mentor',
|
|
114
|
+
* });
|
|
115
|
+
*
|
|
116
|
+
* // With logout
|
|
117
|
+
* redirectToAuthSpa({
|
|
118
|
+
* authUrl: 'https://auth.example.com',
|
|
119
|
+
* appName: 'mentor',
|
|
120
|
+
* logout: true,
|
|
121
|
+
* platformKey: 'my-tenant',
|
|
122
|
+
* });
|
|
123
|
+
*
|
|
124
|
+
* // With custom redirect
|
|
125
|
+
* redirectToAuthSpa({
|
|
126
|
+
* authUrl: 'https://auth.example.com',
|
|
127
|
+
* appName: 'mentor',
|
|
128
|
+
* redirectTo: '/dashboard',
|
|
129
|
+
* platformKey: 'my-tenant',
|
|
130
|
+
* });
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
export declare function redirectToAuthSpa(options: RedirectToAuthSpaOptions): Promise<void>;
|
|
134
|
+
/**
|
|
135
|
+
* Get the URL for joining a tenant (sign up flow)
|
|
136
|
+
* @param authUrl - Auth SPA base URL
|
|
137
|
+
* @param tenantKey - Tenant to join
|
|
138
|
+
* @param redirectUrl - URL to redirect to after joining (defaults to current URL)
|
|
139
|
+
* @returns The join URL
|
|
140
|
+
*/
|
|
141
|
+
export declare function getAuthSpaJoinUrl(authUrl: string, tenantKey?: string, redirectUrl?: string): string;
|
|
142
|
+
/**
|
|
143
|
+
* Redirect to auth SPA's join/signup page for a specific tenant
|
|
144
|
+
* @param authUrl - Auth SPA base URL
|
|
145
|
+
* @param tenantKey - Tenant to join
|
|
146
|
+
* @param redirectUrl - URL to redirect to after joining (defaults to current URL)
|
|
147
|
+
*/
|
|
148
|
+
export declare function redirectToAuthSpaJoinTenant(authUrl: string, tenantKey?: string, redirectUrl?: string): void;
|
|
149
|
+
export interface HandleLogoutOptions {
|
|
150
|
+
/** URL to redirect to after logout (defaults to current origin) */
|
|
151
|
+
redirectUrl?: string;
|
|
152
|
+
/** Auth SPA base URL */
|
|
153
|
+
authUrl: string;
|
|
154
|
+
/** localStorage key for tenant */
|
|
155
|
+
tenantStorageKey?: string;
|
|
156
|
+
/** Cookie name for logout timestamp */
|
|
157
|
+
logoutTimestampCookie?: string;
|
|
158
|
+
/** Callback to execute before logout */
|
|
159
|
+
callback?: () => void;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Handle user logout
|
|
163
|
+
*
|
|
164
|
+
* This function:
|
|
165
|
+
* - Clears localStorage (preserving tenant)
|
|
166
|
+
* - Sets logout timestamp cookie for cross-SPA sync
|
|
167
|
+
* - Clears all cookies
|
|
168
|
+
* - Redirects to auth SPA logout endpoint
|
|
169
|
+
*
|
|
170
|
+
* @param options - Logout configuration options
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```tsx
|
|
174
|
+
* handleLogout({
|
|
175
|
+
* authUrl: 'https://auth.example.com',
|
|
176
|
+
* redirectUrl: 'https://app.example.com',
|
|
177
|
+
* });
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
export declare function handleLogout(options: HandleLogoutOptions): void;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @iblai/iblai-js - TypeScript SDK for IBL AI Platform
|
|
3
|
+
*
|
|
4
|
+
* A unified SDK providing:
|
|
5
|
+
* - Data Layer: RTK Query API slices and data management
|
|
6
|
+
* - Web Utils: React providers, hooks, and utilities
|
|
7
|
+
* - Web Containers: React UI components for web
|
|
8
|
+
* - Native Components: React Native components for mobile
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { useGetMentorsQuery, AuthProvider, Button } from '@iblai/iblai-js';
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export * from './data-layer';
|
|
16
|
+
export * from './web-utils';
|
|
17
|
+
export * from './web-containers';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Next.js-specific components and hooks
|
|
3
|
+
*
|
|
4
|
+
* This module contains React components and hooks that require Next.js
|
|
5
|
+
* as a peer dependency. These components use Next.js-specific APIs like
|
|
6
|
+
* `next/navigation`, `next/router`, `next/image`, and `next/link`.
|
|
7
|
+
*
|
|
8
|
+
* For non-Next.js React applications, you'll need to implement
|
|
9
|
+
* framework-agnostic alternatives. See the SDK documentation for examples.
|
|
10
|
+
*
|
|
11
|
+
* @module next
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* // In a Next.js application
|
|
16
|
+
* import { SsoLogin, ErrorPage, UserProfileDropdown } from '@iblai/iblai-js/next';
|
|
17
|
+
*
|
|
18
|
+
* // Use the components as normal
|
|
19
|
+
* <SsoLogin
|
|
20
|
+
* localStorageKeys={{...}}
|
|
21
|
+
* redirectPathKey="redirect-to"
|
|
22
|
+
* defaultRedirectPath="/"
|
|
23
|
+
* />
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export * from '@iblai/web-containers/next';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SSO Utilities - Framework agnostic
|
|
3
|
+
*
|
|
4
|
+
* This module contains utilities for handling SSO authentication callbacks.
|
|
5
|
+
* These utilities work in any React application (Next.js, Create React App,
|
|
6
|
+
* Vite, React Router, etc.) without requiring Next.js.
|
|
7
|
+
*
|
|
8
|
+
* For Next.js applications that want to use the pre-built `SsoLogin` component,
|
|
9
|
+
* import from `@iblai/iblai-js/next` instead.
|
|
10
|
+
*
|
|
11
|
+
* @module sso
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* // React Router implementation
|
|
16
|
+
* import { useEffect } from 'react';
|
|
17
|
+
* import { useNavigate, useSearchParams } from 'react-router-dom';
|
|
18
|
+
* import { handleSsoCallback } from '@iblai/iblai-js/sso';
|
|
19
|
+
*
|
|
20
|
+
* export function SsoLoginPage() {
|
|
21
|
+
* const navigate = useNavigate();
|
|
22
|
+
* const [searchParams] = useSearchParams();
|
|
23
|
+
*
|
|
24
|
+
* useEffect(() => {
|
|
25
|
+
* handleSsoCallback({
|
|
26
|
+
* queryParamData: searchParams.get('data'),
|
|
27
|
+
* redirectPathKey: 'redirect-to',
|
|
28
|
+
* defaultRedirectPath: '/',
|
|
29
|
+
* onRedirect: (path) => navigate(path),
|
|
30
|
+
* onLoginSuccess: (data) => console.log('Login successful', data),
|
|
31
|
+
* onLoginError: (error) => console.error('Login failed', error),
|
|
32
|
+
* });
|
|
33
|
+
* }, [searchParams, navigate]);
|
|
34
|
+
*
|
|
35
|
+
* return null; // Redirect-only page
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export * from '@iblai/web-containers/sso';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Web Utils - Utilities, providers, hooks, and helper functions
|
|
3
|
+
*
|
|
4
|
+
* This module contains React providers, custom hooks, utility functions,
|
|
5
|
+
* and helper methods for building IBL AI applications.
|
|
6
|
+
*
|
|
7
|
+
* @module web-utils
|
|
8
|
+
*/
|
|
9
|
+
export * from '@iblai/web-utils';
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authentication and Authorization Utilities
|
|
3
|
+
*
|
|
4
|
+
* This module provides utility functions for handling authentication flows,
|
|
5
|
+
* including redirects to auth SPA, cookie management, and session handling.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Check if the current window is inside an iframe
|
|
9
|
+
* @returns {boolean} True if running in an iframe, false otherwise
|
|
10
|
+
*/
|
|
11
|
+
export declare function isInIframe(): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Send a message to the parent website (when in iframe)
|
|
14
|
+
* @param payload - The data to send to parent window
|
|
15
|
+
*/
|
|
16
|
+
export declare function sendMessageToParentWebsite(payload: unknown): void;
|
|
17
|
+
/**
|
|
18
|
+
* Delete a cookie with specific name, path, and domain
|
|
19
|
+
* @param name - Cookie name
|
|
20
|
+
* @param path - Cookie path
|
|
21
|
+
* @param domain - Cookie domain
|
|
22
|
+
*/
|
|
23
|
+
export declare function deleteCookie(name: string, path: string, domain: string): void;
|
|
24
|
+
/**
|
|
25
|
+
* Get all possible domain parts for cookie deletion
|
|
26
|
+
* @param domain - The domain to split
|
|
27
|
+
* @returns Array of domain parts
|
|
28
|
+
* @example
|
|
29
|
+
* getDomainParts('app.example.com') // returns ['app.example.com', 'example.com', 'com']
|
|
30
|
+
*/
|
|
31
|
+
export declare function getDomainParts(domain: string): string[];
|
|
32
|
+
/**
|
|
33
|
+
* Delete a cookie across all possible domain variations
|
|
34
|
+
* @param name - Cookie name to delete
|
|
35
|
+
* @param childDomain - The current domain
|
|
36
|
+
*/
|
|
37
|
+
export declare function deleteCookieOnAllDomains(name: string, childDomain: string): void;
|
|
38
|
+
/**
|
|
39
|
+
* Get the parent domain from a given domain
|
|
40
|
+
* @param domain - The domain to process
|
|
41
|
+
* @returns The parent domain (e.g., 'app.example.com' → '.example.com')
|
|
42
|
+
*/
|
|
43
|
+
export declare function getParentDomain(domain?: string): string;
|
|
44
|
+
/**
|
|
45
|
+
* Set a cookie for authentication with cross-domain support
|
|
46
|
+
* @param name - Cookie name
|
|
47
|
+
* @param value - Cookie value
|
|
48
|
+
* @param days - Number of days until expiration (default: 365)
|
|
49
|
+
*/
|
|
50
|
+
export declare function setCookieForAuth(name: string, value: string, days?: number): void;
|
|
51
|
+
/**
|
|
52
|
+
* Clear all cookies for the current domain
|
|
53
|
+
*/
|
|
54
|
+
export declare function clearCookies(): void;
|
|
55
|
+
/**
|
|
56
|
+
* Check if user is currently logged in
|
|
57
|
+
* @param tokenKey - The localStorage key for the auth token (default: 'axd_token')
|
|
58
|
+
* @returns True if logged in, false otherwise
|
|
59
|
+
*/
|
|
60
|
+
export declare function isLoggedIn(tokenKey?: string): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Extract platform/tenant key from URL
|
|
63
|
+
* @param url - The URL to parse
|
|
64
|
+
* @param pattern - RegExp pattern to match platform key (default matches /platform/[key]/...)
|
|
65
|
+
* @returns The platform key or null if not found
|
|
66
|
+
*/
|
|
67
|
+
export declare function getPlatformKey(url: string, pattern?: RegExp): string | null;
|
|
68
|
+
export interface RedirectToAuthSpaOptions {
|
|
69
|
+
/** URL to redirect to after auth (defaults to current path + search) */
|
|
70
|
+
redirectTo?: string;
|
|
71
|
+
/** Platform/tenant key */
|
|
72
|
+
platformKey?: string;
|
|
73
|
+
/** Whether this is a logout action */
|
|
74
|
+
logout?: boolean;
|
|
75
|
+
/** Whether to save redirect path to localStorage (default: true) */
|
|
76
|
+
saveRedirect?: boolean;
|
|
77
|
+
/** Auth SPA base URL */
|
|
78
|
+
authUrl: string;
|
|
79
|
+
/** Current app/platform identifier (e.g., 'mentor', 'skills') */
|
|
80
|
+
appName: string;
|
|
81
|
+
/** Query param names */
|
|
82
|
+
queryParams?: {
|
|
83
|
+
app?: string;
|
|
84
|
+
redirectTo?: string;
|
|
85
|
+
tenant?: string;
|
|
86
|
+
};
|
|
87
|
+
/** localStorage key for saving redirect path */
|
|
88
|
+
redirectPathStorageKey?: string;
|
|
89
|
+
/** Cookie names for cross-SPA sync */
|
|
90
|
+
cookieNames?: {
|
|
91
|
+
currentTenant?: string;
|
|
92
|
+
userData?: string;
|
|
93
|
+
tenant?: string;
|
|
94
|
+
logoutTimestamp?: string;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Redirect to authentication SPA for login/logout
|
|
99
|
+
*
|
|
100
|
+
* This function handles the complete authentication flow:
|
|
101
|
+
* - Clears localStorage and cookies on logout
|
|
102
|
+
* - Saves redirect path for post-auth return
|
|
103
|
+
* - Handles iframe scenarios
|
|
104
|
+
* - Syncs logout across multiple SPAs via cookies
|
|
105
|
+
*
|
|
106
|
+
* @param options - Configuration options for the redirect
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```tsx
|
|
110
|
+
* // Basic usage
|
|
111
|
+
* redirectToAuthSpa({
|
|
112
|
+
* authUrl: 'https://auth.example.com',
|
|
113
|
+
* appName: 'mentor',
|
|
114
|
+
* });
|
|
115
|
+
*
|
|
116
|
+
* // With logout
|
|
117
|
+
* redirectToAuthSpa({
|
|
118
|
+
* authUrl: 'https://auth.example.com',
|
|
119
|
+
* appName: 'mentor',
|
|
120
|
+
* logout: true,
|
|
121
|
+
* platformKey: 'my-tenant',
|
|
122
|
+
* });
|
|
123
|
+
*
|
|
124
|
+
* // With custom redirect
|
|
125
|
+
* redirectToAuthSpa({
|
|
126
|
+
* authUrl: 'https://auth.example.com',
|
|
127
|
+
* appName: 'mentor',
|
|
128
|
+
* redirectTo: '/dashboard',
|
|
129
|
+
* platformKey: 'my-tenant',
|
|
130
|
+
* });
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
export declare function redirectToAuthSpa(options: RedirectToAuthSpaOptions): Promise<void>;
|
|
134
|
+
/**
|
|
135
|
+
* Get the URL for joining a tenant (sign up flow)
|
|
136
|
+
* @param authUrl - Auth SPA base URL
|
|
137
|
+
* @param tenantKey - Tenant to join
|
|
138
|
+
* @param redirectUrl - URL to redirect to after joining (defaults to current URL)
|
|
139
|
+
* @returns The join URL
|
|
140
|
+
*/
|
|
141
|
+
export declare function getAuthSpaJoinUrl(authUrl: string, tenantKey?: string, redirectUrl?: string): string;
|
|
142
|
+
/**
|
|
143
|
+
* Redirect to auth SPA's join/signup page for a specific tenant
|
|
144
|
+
* @param authUrl - Auth SPA base URL
|
|
145
|
+
* @param tenantKey - Tenant to join
|
|
146
|
+
* @param redirectUrl - URL to redirect to after joining (defaults to current URL)
|
|
147
|
+
*/
|
|
148
|
+
export declare function redirectToAuthSpaJoinTenant(authUrl: string, tenantKey?: string, redirectUrl?: string): void;
|
|
149
|
+
export interface HandleLogoutOptions {
|
|
150
|
+
/** URL to redirect to after logout (defaults to current origin) */
|
|
151
|
+
redirectUrl?: string;
|
|
152
|
+
/** Auth SPA base URL */
|
|
153
|
+
authUrl: string;
|
|
154
|
+
/** localStorage key for tenant */
|
|
155
|
+
tenantStorageKey?: string;
|
|
156
|
+
/** Cookie name for logout timestamp */
|
|
157
|
+
logoutTimestampCookie?: string;
|
|
158
|
+
/** Callback to execute before logout */
|
|
159
|
+
callback?: () => void;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Handle user logout
|
|
163
|
+
*
|
|
164
|
+
* This function:
|
|
165
|
+
* - Clears localStorage (preserving tenant)
|
|
166
|
+
* - Sets logout timestamp cookie for cross-SPA sync
|
|
167
|
+
* - Clears all cookies
|
|
168
|
+
* - Redirects to auth SPA logout endpoint
|
|
169
|
+
*
|
|
170
|
+
* @param options - Logout configuration options
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```tsx
|
|
174
|
+
* handleLogout({
|
|
175
|
+
* authUrl: 'https://auth.example.com',
|
|
176
|
+
* redirectUrl: 'https://app.example.com',
|
|
177
|
+
* });
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
export declare function handleLogout(options: HandleLogoutOptions): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@iblai/web-containers/sso';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var sso = require('@iblai/web-containers/sso');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
Object.keys(sso).forEach(function (k) {
|
|
8
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () { return sso[k]; }
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @iblai/iblai-js - TypeScript SDK for IBL AI Platform
|
|
3
|
+
*
|
|
4
|
+
* A unified SDK providing:
|
|
5
|
+
* - Data Layer: RTK Query API slices and data management
|
|
6
|
+
* - Web Utils: React providers, hooks, and utilities
|
|
7
|
+
* - Web Containers: React UI components for web
|
|
8
|
+
* - Native Components: React Native components for mobile
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { useGetMentorsQuery, AuthProvider, Button } from '@iblai/iblai-js';
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export * from './data-layer';
|
|
16
|
+
export * from './web-utils';
|
|
17
|
+
export * from './web-containers';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Next.js-specific components and hooks
|
|
3
|
+
*
|
|
4
|
+
* This module contains React components and hooks that require Next.js
|
|
5
|
+
* as a peer dependency. These components use Next.js-specific APIs like
|
|
6
|
+
* `next/navigation`, `next/router`, `next/image`, and `next/link`.
|
|
7
|
+
*
|
|
8
|
+
* For non-Next.js React applications, you'll need to implement
|
|
9
|
+
* framework-agnostic alternatives. See the SDK documentation for examples.
|
|
10
|
+
*
|
|
11
|
+
* @module next
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* // In a Next.js application
|
|
16
|
+
* import { SsoLogin, ErrorPage, UserProfileDropdown } from '@iblai/iblai-js/next';
|
|
17
|
+
*
|
|
18
|
+
* // Use the components as normal
|
|
19
|
+
* <SsoLogin
|
|
20
|
+
* localStorageKeys={{...}}
|
|
21
|
+
* redirectPathKey="redirect-to"
|
|
22
|
+
* defaultRedirectPath="/"
|
|
23
|
+
* />
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export * from '@iblai/web-containers/next';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SSO Utilities - Framework agnostic
|
|
3
|
+
*
|
|
4
|
+
* This module contains utilities for handling SSO authentication callbacks.
|
|
5
|
+
* These utilities work in any React application (Next.js, Create React App,
|
|
6
|
+
* Vite, React Router, etc.) without requiring Next.js.
|
|
7
|
+
*
|
|
8
|
+
* For Next.js applications that want to use the pre-built `SsoLogin` component,
|
|
9
|
+
* import from `@iblai/iblai-js/next` instead.
|
|
10
|
+
*
|
|
11
|
+
* @module sso
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* // React Router implementation
|
|
16
|
+
* import { useEffect } from 'react';
|
|
17
|
+
* import { useNavigate, useSearchParams } from 'react-router-dom';
|
|
18
|
+
* import { handleSsoCallback } from '@iblai/iblai-js/sso';
|
|
19
|
+
*
|
|
20
|
+
* export function SsoLoginPage() {
|
|
21
|
+
* const navigate = useNavigate();
|
|
22
|
+
* const [searchParams] = useSearchParams();
|
|
23
|
+
*
|
|
24
|
+
* useEffect(() => {
|
|
25
|
+
* handleSsoCallback({
|
|
26
|
+
* queryParamData: searchParams.get('data'),
|
|
27
|
+
* redirectPathKey: 'redirect-to',
|
|
28
|
+
* defaultRedirectPath: '/',
|
|
29
|
+
* onRedirect: (path) => navigate(path),
|
|
30
|
+
* onLoginSuccess: (data) => console.log('Login successful', data),
|
|
31
|
+
* onLoginError: (error) => console.error('Login failed', error),
|
|
32
|
+
* });
|
|
33
|
+
* }, [searchParams, navigate]);
|
|
34
|
+
*
|
|
35
|
+
* return null; // Redirect-only page
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export * from '@iblai/web-containers/sso';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Web Utils - Utilities, providers, hooks, and helper functions
|
|
3
|
+
*
|
|
4
|
+
* This module contains React providers, custom hooks, utility functions,
|
|
5
|
+
* and helper methods for building IBL AI applications.
|
|
6
|
+
*
|
|
7
|
+
* @module web-utils
|
|
8
|
+
*/
|
|
9
|
+
export * from '@iblai/web-utils';
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authentication and Authorization Utilities
|
|
3
|
+
*
|
|
4
|
+
* This module provides utility functions for handling authentication flows,
|
|
5
|
+
* including redirects to auth SPA, cookie management, and session handling.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Check if the current window is inside an iframe
|
|
9
|
+
* @returns {boolean} True if running in an iframe, false otherwise
|
|
10
|
+
*/
|
|
11
|
+
export declare function isInIframe(): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Send a message to the parent website (when in iframe)
|
|
14
|
+
* @param payload - The data to send to parent window
|
|
15
|
+
*/
|
|
16
|
+
export declare function sendMessageToParentWebsite(payload: unknown): void;
|
|
17
|
+
/**
|
|
18
|
+
* Delete a cookie with specific name, path, and domain
|
|
19
|
+
* @param name - Cookie name
|
|
20
|
+
* @param path - Cookie path
|
|
21
|
+
* @param domain - Cookie domain
|
|
22
|
+
*/
|
|
23
|
+
export declare function deleteCookie(name: string, path: string, domain: string): void;
|
|
24
|
+
/**
|
|
25
|
+
* Get all possible domain parts for cookie deletion
|
|
26
|
+
* @param domain - The domain to split
|
|
27
|
+
* @returns Array of domain parts
|
|
28
|
+
* @example
|
|
29
|
+
* getDomainParts('app.example.com') // returns ['app.example.com', 'example.com', 'com']
|
|
30
|
+
*/
|
|
31
|
+
export declare function getDomainParts(domain: string): string[];
|
|
32
|
+
/**
|
|
33
|
+
* Delete a cookie across all possible domain variations
|
|
34
|
+
* @param name - Cookie name to delete
|
|
35
|
+
* @param childDomain - The current domain
|
|
36
|
+
*/
|
|
37
|
+
export declare function deleteCookieOnAllDomains(name: string, childDomain: string): void;
|
|
38
|
+
/**
|
|
39
|
+
* Get the parent domain from a given domain
|
|
40
|
+
* @param domain - The domain to process
|
|
41
|
+
* @returns The parent domain (e.g., 'app.example.com' → '.example.com')
|
|
42
|
+
*/
|
|
43
|
+
export declare function getParentDomain(domain?: string): string;
|
|
44
|
+
/**
|
|
45
|
+
* Set a cookie for authentication with cross-domain support
|
|
46
|
+
* @param name - Cookie name
|
|
47
|
+
* @param value - Cookie value
|
|
48
|
+
* @param days - Number of days until expiration (default: 365)
|
|
49
|
+
*/
|
|
50
|
+
export declare function setCookieForAuth(name: string, value: string, days?: number): void;
|
|
51
|
+
/**
|
|
52
|
+
* Clear all cookies for the current domain
|
|
53
|
+
*/
|
|
54
|
+
export declare function clearCookies(): void;
|
|
55
|
+
/**
|
|
56
|
+
* Check if user is currently logged in
|
|
57
|
+
* @param tokenKey - The localStorage key for the auth token (default: 'axd_token')
|
|
58
|
+
* @returns True if logged in, false otherwise
|
|
59
|
+
*/
|
|
60
|
+
export declare function isLoggedIn(tokenKey?: string): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Extract platform/tenant key from URL
|
|
63
|
+
* @param url - The URL to parse
|
|
64
|
+
* @param pattern - RegExp pattern to match platform key (default matches /platform/[key]/...)
|
|
65
|
+
* @returns The platform key or null if not found
|
|
66
|
+
*/
|
|
67
|
+
export declare function getPlatformKey(url: string, pattern?: RegExp): string | null;
|
|
68
|
+
export interface RedirectToAuthSpaOptions {
|
|
69
|
+
/** URL to redirect to after auth (defaults to current path + search) */
|
|
70
|
+
redirectTo?: string;
|
|
71
|
+
/** Platform/tenant key */
|
|
72
|
+
platformKey?: string;
|
|
73
|
+
/** Whether this is a logout action */
|
|
74
|
+
logout?: boolean;
|
|
75
|
+
/** Whether to save redirect path to localStorage (default: true) */
|
|
76
|
+
saveRedirect?: boolean;
|
|
77
|
+
/** Auth SPA base URL */
|
|
78
|
+
authUrl: string;
|
|
79
|
+
/** Current app/platform identifier (e.g., 'mentor', 'skills') */
|
|
80
|
+
appName: string;
|
|
81
|
+
/** Query param names */
|
|
82
|
+
queryParams?: {
|
|
83
|
+
app?: string;
|
|
84
|
+
redirectTo?: string;
|
|
85
|
+
tenant?: string;
|
|
86
|
+
};
|
|
87
|
+
/** localStorage key for saving redirect path */
|
|
88
|
+
redirectPathStorageKey?: string;
|
|
89
|
+
/** Cookie names for cross-SPA sync */
|
|
90
|
+
cookieNames?: {
|
|
91
|
+
currentTenant?: string;
|
|
92
|
+
userData?: string;
|
|
93
|
+
tenant?: string;
|
|
94
|
+
logoutTimestamp?: string;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Redirect to authentication SPA for login/logout
|
|
99
|
+
*
|
|
100
|
+
* This function handles the complete authentication flow:
|
|
101
|
+
* - Clears localStorage and cookies on logout
|
|
102
|
+
* - Saves redirect path for post-auth return
|
|
103
|
+
* - Handles iframe scenarios
|
|
104
|
+
* - Syncs logout across multiple SPAs via cookies
|
|
105
|
+
*
|
|
106
|
+
* @param options - Configuration options for the redirect
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```tsx
|
|
110
|
+
* // Basic usage
|
|
111
|
+
* redirectToAuthSpa({
|
|
112
|
+
* authUrl: 'https://auth.example.com',
|
|
113
|
+
* appName: 'mentor',
|
|
114
|
+
* });
|
|
115
|
+
*
|
|
116
|
+
* // With logout
|
|
117
|
+
* redirectToAuthSpa({
|
|
118
|
+
* authUrl: 'https://auth.example.com',
|
|
119
|
+
* appName: 'mentor',
|
|
120
|
+
* logout: true,
|
|
121
|
+
* platformKey: 'my-tenant',
|
|
122
|
+
* });
|
|
123
|
+
*
|
|
124
|
+
* // With custom redirect
|
|
125
|
+
* redirectToAuthSpa({
|
|
126
|
+
* authUrl: 'https://auth.example.com',
|
|
127
|
+
* appName: 'mentor',
|
|
128
|
+
* redirectTo: '/dashboard',
|
|
129
|
+
* platformKey: 'my-tenant',
|
|
130
|
+
* });
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
export declare function redirectToAuthSpa(options: RedirectToAuthSpaOptions): Promise<void>;
|
|
134
|
+
/**
|
|
135
|
+
* Get the URL for joining a tenant (sign up flow)
|
|
136
|
+
* @param authUrl - Auth SPA base URL
|
|
137
|
+
* @param tenantKey - Tenant to join
|
|
138
|
+
* @param redirectUrl - URL to redirect to after joining (defaults to current URL)
|
|
139
|
+
* @returns The join URL
|
|
140
|
+
*/
|
|
141
|
+
export declare function getAuthSpaJoinUrl(authUrl: string, tenantKey?: string, redirectUrl?: string): string;
|
|
142
|
+
/**
|
|
143
|
+
* Redirect to auth SPA's join/signup page for a specific tenant
|
|
144
|
+
* @param authUrl - Auth SPA base URL
|
|
145
|
+
* @param tenantKey - Tenant to join
|
|
146
|
+
* @param redirectUrl - URL to redirect to after joining (defaults to current URL)
|
|
147
|
+
*/
|
|
148
|
+
export declare function redirectToAuthSpaJoinTenant(authUrl: string, tenantKey?: string, redirectUrl?: string): void;
|
|
149
|
+
export interface HandleLogoutOptions {
|
|
150
|
+
/** URL to redirect to after logout (defaults to current origin) */
|
|
151
|
+
redirectUrl?: string;
|
|
152
|
+
/** Auth SPA base URL */
|
|
153
|
+
authUrl: string;
|
|
154
|
+
/** localStorage key for tenant */
|
|
155
|
+
tenantStorageKey?: string;
|
|
156
|
+
/** Cookie name for logout timestamp */
|
|
157
|
+
logoutTimestampCookie?: string;
|
|
158
|
+
/** Callback to execute before logout */
|
|
159
|
+
callback?: () => void;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Handle user logout
|
|
163
|
+
*
|
|
164
|
+
* This function:
|
|
165
|
+
* - Clears localStorage (preserving tenant)
|
|
166
|
+
* - Sets logout timestamp cookie for cross-SPA sync
|
|
167
|
+
* - Clears all cookies
|
|
168
|
+
* - Redirects to auth SPA logout endpoint
|
|
169
|
+
*
|
|
170
|
+
* @param options - Logout configuration options
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```tsx
|
|
174
|
+
* handleLogout({
|
|
175
|
+
* authUrl: 'https://auth.example.com',
|
|
176
|
+
* redirectUrl: 'https://app.example.com',
|
|
177
|
+
* });
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
export declare function handleLogout(options: HandleLogoutOptions): void;
|
package/package.json
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@iblai/iblai-js",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "TypeScript SDK for IBL AI Platform - Unified package for data layer, utilities, and React components",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"module": "dist/index.esm.js",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.esm.js",
|
|
13
|
+
"require": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./next": {
|
|
16
|
+
"types": "./dist/next/index.d.ts",
|
|
17
|
+
"import": "./dist/next/index.esm.js",
|
|
18
|
+
"require": "./dist/next/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./sso": {
|
|
21
|
+
"types": "./dist/sso/index.d.ts",
|
|
22
|
+
"import": "./dist/sso/index.esm.js",
|
|
23
|
+
"require": "./dist/sso/index.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"README.md",
|
|
29
|
+
"LICENSE"
|
|
30
|
+
],
|
|
31
|
+
"keywords": [
|
|
32
|
+
"iblai",
|
|
33
|
+
"sdk",
|
|
34
|
+
"typescript",
|
|
35
|
+
"react",
|
|
36
|
+
"data-layer",
|
|
37
|
+
"web-utils",
|
|
38
|
+
"components",
|
|
39
|
+
"rtk-query",
|
|
40
|
+
"education",
|
|
41
|
+
"ai",
|
|
42
|
+
"mentor"
|
|
43
|
+
],
|
|
44
|
+
"author": "IBL AI <dev@ibl.ai>",
|
|
45
|
+
"license": "MIT",
|
|
46
|
+
"repository": {
|
|
47
|
+
"type": "git",
|
|
48
|
+
"url": "https://github.com/iblai/iblai-sdk.git",
|
|
49
|
+
"directory": "packages/iblai-js"
|
|
50
|
+
},
|
|
51
|
+
"bugs": {
|
|
52
|
+
"url": "https://github.com/iblai/iblai-sdk/issues"
|
|
53
|
+
},
|
|
54
|
+
"homepage": "https://github.com/iblai/iblai-sdk#readme",
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"@iblai/data-layer": "^1.1.2",
|
|
57
|
+
"@iblai/web-utils": "^1.1.2",
|
|
58
|
+
"@iblai/web-containers": "^1.1.3"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"@rollup/plugin-commonjs": "25.0.8",
|
|
62
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
63
|
+
"@rollup/plugin-node-resolve": "15.3.1",
|
|
64
|
+
"@rollup/plugin-typescript": "11.1.6",
|
|
65
|
+
"@types/node": "^22.19.0",
|
|
66
|
+
"@types/react": "19.1.17",
|
|
67
|
+
"rollup": "4.40.0",
|
|
68
|
+
"rollup-plugin-dts": "^6.2.3",
|
|
69
|
+
"rollup-plugin-peer-deps-external": "2.2.4",
|
|
70
|
+
"rollup-plugin-typescript2": "0.36.0",
|
|
71
|
+
"tslib": "2.8.1",
|
|
72
|
+
"typescript": "5.8.3"
|
|
73
|
+
},
|
|
74
|
+
"peerDependencies": {
|
|
75
|
+
"@reduxjs/toolkit": "^2.0.0",
|
|
76
|
+
"next": ">=13.0.0",
|
|
77
|
+
"react": "19.1.0",
|
|
78
|
+
"react-dom": "19.1.0",
|
|
79
|
+
"react-redux": "^9.0.0",
|
|
80
|
+
"react-router-dom": "^6.0.0 || ^7.0.0"
|
|
81
|
+
},
|
|
82
|
+
"peerDependenciesMeta": {
|
|
83
|
+
"next": {
|
|
84
|
+
"optional": true
|
|
85
|
+
},
|
|
86
|
+
"react-router-dom": {
|
|
87
|
+
"optional": true
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
"publishConfig": {
|
|
91
|
+
"access": "public",
|
|
92
|
+
"registry": "https://registry.npmjs.org/"
|
|
93
|
+
},
|
|
94
|
+
"scripts": {
|
|
95
|
+
"build": "rollup -c",
|
|
96
|
+
"watch": "rollup -c -w",
|
|
97
|
+
"typecheck": "tsc --noEmit",
|
|
98
|
+
"clean": "rm -rf dist"
|
|
99
|
+
}
|
|
100
|
+
}
|