@volenday/check-app-via-client-id-next
v2.0.8
Published
## ES Modules Version (v2.0.3) ✨
Keywords
Readme
@volenday/check-app-via-client-id-next
ES Modules Version (v2.0.3) ✨
AHA Check app via client id for Next.js app - Now with ES Modules support!
This library has been completely converted to ES Modules to resolve compatibility errors with jquery-param and other modern dependencies.
🔧 Main Changes in v2.0.3
- ✅ Converted to ES Modules - Resolves "require() of ES Module not supported" error
- ✅ Native Node.js tests - Uses native test runner instead of Jest
- ✅ Compatible with Node.js 14+ - Full ES Modules support
- ✅ Better maintainability - Cleaner and more modular code
- ✅ 47 tests passing - Complete functionality coverage
🐛 Resolved Issue
Original error:
Error: require() of ES Module /path/to/jquery-param.js not supported.
jquery-param.js is treated as an ES module file as it is a .js file whose nearest
parent package.json contains "type": "module"Solution: Complete package conversion to ES Modules with "type": "module" in package.json.
📦 Installation
npm install @volenday/check-app-via-client-id-next
# or
yarn add @volenday/check-app-via-client-id-next🚀 Usage
Import as ES Module
import CheckAppViaClientIdNext from '@volenday/check-app-via-client-id-next';
// In your Next.js page
export const getServerSideProps = async (ctx) => {
try {
const response = await CheckAppViaClientIdNext({
context: ctx,
Module: 'abenaDataLookUp',
Type: 'website',
eu: true
});
// This fetches app information and gets the ahaPortal redirect
console.log('CheckAppViaClientIdNext response:', response);
if (response.redirect) return response;
return { props: { error: null, ...response } };
} catch (error) {
console.log(error);
return { props: { error: error.message } };
}
};With Redux Wrapper
import React from 'react';
import CheckAppViaClientIdNext from '@volenday/check-app-via-client-id-next';
import ErrorPage from 'next/error';
import { wrapper } from '../../redux/store';
const Index = error => (error ? <ErrorPage statusCode={404} /> : null);
export const getServerSideProps = wrapper.getServerSideProps(async ctx => {
try {
const response = await CheckAppViaClientIdNext({
context: ctx,
Module: 'abenaDataLookUp',
Type: 'website',
eu: true
});
if (response.redirect) return response;
return { props: { error: null } };
} catch (error) {
console.log(error);
return { props: { error: error.message } };
}
});
export default Index;🔑 Parameters
| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| context | Object | required | Next.js context (req, res, query) |
| Type | String | 'auth' | Type: 'auth', 'portal', 'website', 'callback', etc. |
| environment | String | process.env.CUSTOM_ENV | Environment: 'local', 'development', 'sandbox', 'staging', 'preprod', 'production' |
| eu | Boolean | false | Use Europe region |
| logout | Boolean | false | Enable logout flow |
| Module | String | '' | Specific module to use |
| cidaas | Object | { authority: '', client_id: '' } | Cidaas configuration |
📊 Response
For Type: 'auth' or 'portal'
{
application: Object, // Application data
appUrl: String, // Application URL
facebookPixel: Object, // Facebook Pixel configuration
googleAnalytics: Object, // Google Analytics configuration
ico: String, // Icon URL
portalAuthentication: Object, // Authentication configuration
module: String, // Module used
title: String, // Page title
cidaas: Object // Cidaas configuration
}For other types (redirect)
{
redirect: {
permanent: false,
destination: String // Portal redirect URL
}
}🧪 Testing
This library uses the native Node.js test runner (available from Node.js 16+).
Requirements
- Node.js 14+ (recommended 18+ or 22+)
- For full ES Modules support, Node.js 18+ or 22+ is recommended
Running tests
# With Node.js 18+ or 22+ (recommended)
npm test
# If you have Node.js < 18, use nvm to change version:
nvm use 22
npm test
# For development with watch mode
npm run test:watch
# Validate that modules import correctly
npm run validateTest Coverage
Tests cover:
- ✅ ES modules validation (config.js, index.js)
- ✅ Structure and data types
- ✅ Region configuration (Asia/Europe)
- ✅ Environment configuration
- ✅ Title generation by origin
- ✅ Authentication configuration
- ✅ Cookie configuration
- ✅ Redirect URL parsing
- ✅ Cidaas configuration
Result: 47 tests passing ✅
🔄 Migration from v1.x to v2.x
Required changes in your code:
Before (v1.x - CommonJS):
const checkApp = require('@volenday/check-app-via-client-id-next');After (v2.x - ES Modules):
import checkApp from '@volenday/check-app-via-client-id-next';Note: Next.js supports ES Modules natively, so you don't need to make additional configuration changes.
CommonJS dependencies imports
If you use this library and encounter issues with CommonJS dependencies (like lodash), the library already handles these cases internally:
// ✅ The library does this internally
import lodash from 'lodash';
const { keyBy } = lodash;
// ❌ Don't do this (doesn't work with CommonJS modules)
import { keyBy } from 'lodash';🌍 Regions and Environments
Asia (default: eu: false)
- Local: http://localhost:3501/
- Development: https://dev.api.ahamatic.com/
- Sandbox/Staging: https://test.api.ahamatic.com/
- Preprod: https://preprod-api-eu.ahamatic.com/
- Production: https://api.ahamatic.com/
Europe (eu: true)
- Local: http://localhost:3501/
- Development: https://dev.api.ahamatic.com/
- Sandbox/Staging: https://test.api.ahamatic.com/
- Preprod: https://preprod-api-eu.ahamatic.com/
- Production: https://api-eu.ahamatic.com/
📝 Usage Examples
Basic authentication
export async function getServerSideProps(context) {
return await CheckAppViaClientIdNext({
context,
Type: 'auth'
});
}With specific module
export async function getServerSideProps(context) {
return await CheckAppViaClientIdNext({
context,
Type: 'auth',
Module: 'admin'
});
}Logout
export async function getServerSideProps(context) {
return await CheckAppViaClientIdNext({
context,
Type: 'auth',
logout: true
});
}With Europe region and production
export async function getServerSideProps(context) {
return await CheckAppViaClientIdNext({
context,
Type: 'website',
eu: true,
environment: 'production'
});
}With Cidaas
export async function getServerSideProps(context) {
return await CheckAppViaClientIdNext({
context,
Type: 'auth',
cidaas: {
authority: 'https://your-cidaas-domain.com',
client_id: 'your-client-id'
}
});
}🔒 Managed Cookies
The library automatically manages the following cookies:
| Cookie | Description |
|--------|-------------|
| token | Ahamatic authentication token |
| refreshToken | Ahamatic refresh token |
| openiamtoken | OpenIAM token |
| openiamrefreshtoken | OpenIAM refresh token |
| redirectUrl | Redirect URL |
| originUrl | Origin URL |
| logOutUrl | Logout URL |
| portalUrl | Portal URL |
Cookie configuration: { httpOnly: false, sameSite: 'lax' }
🛠️ Development
Clone and setup
git clone <repo-url>
cd check-app-via-client-id-next
npm installRun tests
# Make sure to use Node.js 18+ or 22+
nvm use 22 # or nvm use 18
# Run tests
npm test
# Validate imports
npm run validateProject structure
check-app-via-client-id-next/
├── config.js # URLs and environments configuration
├── index.js # Main function
├── tests/
│ ├── config.test.js # Configuration tests
│ ├── index.test.js # Functionality tests
│ └── integration.test.js # Integration tests
├── validate.js # Import validation script
├── package.json
└── README.md⚙️ System Requirements
- Node.js: >= 14.0.0 (recommended 18+ or 22+)
- Next.js: Compatible with all modern versions
- npm/yarn: Any recent version
📄 License
MIT
👥 Author
Volenday [email protected]
🆘 Support
If you encounter any issues or have questions:
- Verify you're using Node.js 14+
- Make sure to import with
importand not withrequire() - Review the usage examples in this README
- Run
npm run validateto verify modules import correctly
