Registry / web-framework / chayns-api

chayns-api

JSON →
library2.6.14jsnpmunverified

The `chayns-api` package provides a React-centric interface for integrating applications with the chayns platform. It offers a comprehensive set of React hooks and utility functions to access chayns-specific information and functionalities, such as user data, location details, and various platform services. Currently stable at version 2.6.14, the library appears to be actively maintained, with regular updates indicated by its versioning and migration guides between major versions. Its primary differentiator is its deep integration with the chayns ecosystem, abstracting the complexities of the underlying platform API into idiomatic React patterns, making development for chayns applications more streamlined compared to direct API interactions. It requires `react` and `react-dom` as peer dependencies.

npm install chayns-api
INSTALL
IMPORT
SIG · CHAYNS-API
C
chayns-api
web-frameworkjavascriptv2.6.14
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ChaynsProvider
import { ChaynsProvider } from 'chayns-api'
const ChaynsProvider = require('chayns-api').ChaynsProvider
A named export component that must wrap your application to provide chayns context to hooks and functions.
useUser
import { useUser } from 'chayns-api'
import useUser from 'chayns-api'
A named export React hook for accessing the current chayns user's information within a component.
initModuleFederationSharing
import { initModuleFederationSharing } from 'chayns-api'
const initModuleFederationSharing = require('chayns-api').initModuleFederationSharing
A utility function for initializing Module Federation sharing, often required early in the application lifecycle when migrating to v2 and using ChaynsHost with module-type.

Demonstrates setting up the `ChaynsProvider` to enable chayns functionalities and using the `useUser` hook to display the current chayns user's profile information within a React component. It also hints at the `initModuleFederationSharing` function for v2+ migrations.

import React from 'react'; import ReactDOM from 'react-dom/client'; import { ChaynsProvider, useUser, initModuleFederationSharing } from 'chayns-api'; // For applications utilizing ChaynsHost with module-type in v2+, // it might be necessary to call initModuleFederationSharing early in your app. // This is typically done in your entry point (e.g., index.ts/js or bootstrap.ts/js). // Example: // initModuleFederationSharing({ name: 'your-project-name' }); const UserDisplay: React.FC = () => { const user = useUser(); if (!user) { return <p>Authenticating with chayns...</p>; } return ( <div style={{ padding: '20px', fontFamily: 'Arial, sans-serif' }}> <h2>chayns User Profile</h2> <p><strong>First Name:</strong> {user.firstName || 'N/A'}</p> <p><strong>Last Name:</strong> {user.lastName || 'N/A'}</p> <p><strong>Person ID:</strong> {user.personId}</p> <p><strong>Location ID:</strong> {user.locationId}</p> <p><strong>Admin Mode:</strong> {user.adminMode ? 'Yes' : 'No'}</p> <p><strong>Is logged in:</strong> {user.loggedIn ? 'Yes' : 'No'}</p> </div> ); }; const App: React.FC = () => ( <ChaynsProvider> <UserDisplay /> </ChaynsProvider> ); const rootElement = document.getElementById('root'); if (rootElement) { const root = ReactDOM.createRoot(rootElement); root.render( <React.StrictMode> <App /> </React.StrictMode> ); } else { console.error("Root element with ID 'root' not found."); }
Debug
Known issues
breakingWhen migrating to `chayns-api` v2, you must also update `chayns-toolkit` to version `3.0.1` or higher. Additionally, URLs referencing `remoteEntry.js` must be updated to `v2.remoteEntry.js`.
fix
Upgrade `chayns-toolkit` to `>=3.0.1`. Replace all instances of `remoteEntry.js` with `v2.remoteEntry.js` in your application's configuration and code.
affects: >=2.0.0
breakingApplications using `ChaynsHost` with a module-type in `chayns-api` v2+ might need to call `initModuleFederationSharing({ name: 'project_name' })` early in the application lifecycle (e.g., in `index`/`bootstrap` files) to ensure proper Module Federation.
fix
Add `initModuleFederationSharing({ name: 'your_project_name' });` as early as possible in your application's entry point, replacing `'your_project_name'` with your actual project identifier.
affects: >=2.0.0
gotchaA warning "Can't resolve 'react-dom/client'" may appear when using `chayns-api` with React 17. This occurs because the library attempts to import React 18's client API.
fix
This warning can be safely ignored as `chayns-api` includes a fallback to the React 17 API. For a clean console, consider upgrading your project to React 18.
affects: >=2.0.0 <18.0.0-rc
Errors
Common errors & fixes
Can't resolve 'react-dom/client'
Using `chayns-api` v2+ with React 17, which triggers a warning because `chayns-api` attempts to import `react-dom/client` (a React 18 feature).
fix
This warning can be safely ignored as the library falls back to React 17's API. To remove the warning, upgrade your project to React 18 or higher.
Failed to load module script: The server responded with a non-JavaScript MIME type of "". Strict MIME type checking is enabled for module scripts.
This error or similar module loading failures often occur after migrating to `chayns-api` v2 due to incorrect paths for the Module Federation entry file.
fix
Ensure all URLs referencing `remoteEntry.js` in your application configuration (e.g., webpack, ChaynsHost settings) have been updated to `v2.remoteEntry.js`.
Upgrade
Version history
2.6.14latest on npm
Audit
Dependencies
reactrequiredRequired as a peer dependency for any React application using this library.
react-domrequiredRequired as a peer dependency for rendering React components.
Agent activity
21 hits · last 30 days
node
16
Amazon
1
OpenAI (training)
1
Resources
chayns-api — npm install chayns-api · libregistry