anypoint-cli-command-lib
v1.6.14
Published
Anypoint CLI core Library
Downloads
35,972
Maintainers
Keywords
Readme
anypoint-cli-command-lib
This package contains the base command class for Anypoint CLI (anypoint-cli-v4). Extend this class for convenient access to common Anypoint CLI parameters, a logger, CLI output formatting, and scratch orgs. This class extends @oclif/core.
Installation
npm install anypoint-cli-command-libUsage
Check Your Anypoint CLI Version
Commands that extend Core can only be used with Anypoint CLI version 4.0.0 or later. To check your Anypoint CLI version:
$ anypoint-cli-v4 --version
anypoint-cli-v4-public/1.6.23 linux-x64 node-v20.xCustomizing the User-Agent Header
As of version 1.6.10, you can customize the User-Agent header sent with all HTTP requests made by the library. This is useful for identifying traffic from your custom CLI tools or applications in backend analytics.
Basic Usage
Call setUserAgent() in your CLI's bootstrap code before any commands execute:
// In your CLI's bin/run or main entry point
const { setUserAgent } = require('anypoint-cli-command-lib');
// Set your custom User-Agent
setUserAgent('MyCustomCLI/1.0.0');
// Now start your CLI
const oclif = require('@oclif/core');
oclif.run().then(require('@oclif/core/flush')).catch(require('@oclif/core/handle'));Example: ACB (Anypoint CLI for Business)
#!/usr/bin/env node
const { setUserAgent } = require('anypoint-cli-command-lib');
const oclif = require('@oclif/core');
// Set custom User-Agent so backend services can identify ACB traffic
setUserAgent('ACB/2.0.0');
oclif.run().then(require('@oclif/core/flush')).catch(require('@oclif/core/handle'));Dynamic User-Agent
You can read the version dynamically from your package.json:
const { setUserAgent } = require('anypoint-cli-command-lib');
const packageJson = require('./package.json');
setUserAgent(`${packageJson.name}/${packageJson.version}`);Default Behavior
If you don't call setUserAgent(), the library uses the default:
User-Agent: Anypoint-CLI/<version>This maintains backward compatibility with existing consumers.
Technical Details
- The User-Agent is applied to all HTTP requests made to Anypoint Platform domains (
anypoint.mulesoft.com,platform.mulesoft.com) - The value is set globally and persists for the lifetime of the process
- You can call
setUserAgent()multiple times; the last value wins - The custom User-Agent appears in backend logs and analytics, allowing platform teams to differentiate between CLI variants
Features
To learn more about the features of the Command Library see the How to develop a plug-in.
API Reference
setUserAgent(value: string): void
Sets a custom User-Agent header for all HTTP requests made by the library.
Parameters:
value(string) - The custom User-Agent string to use (e.g.,"MyTool/1.0.0")
Example:
const { setUserAgent } = require('anypoint-cli-command-lib');
setUserAgent('CustomTool/2.5.0');Notes:
- Must be called before any API requests are made
- Recommended to call in your CLI's bootstrap/entry point
- Thread-safe: sets a module-level variable
- No return value
Changelog
1.6.13
- Changed: Published via OIDC trusted publishing (GitHub Actions)
- Changed: License updated to Public Code License (PCL)
- Added: Copyright headers to all source files
1.6.10
- Added:
setUserAgent(value: string)- Allows consumers to customize the User-Agent header - Fixed: Security vulnerabilities in
uuid(8.3.2 -> 11.1.1) andnyc(15.1.0 -> 18.0.0)
1.6.9
- Previous stable release
Related Docs and Repositories
- anypoint-cli-command-lib - This repo. Contains the base Anypoint CLI command,
Core. - @oclif/core - Contains the base oclif
Command, whichCoreextends. - How to develop a plug-in - Plugin development guide
License
This software is licensed under the Public Code License. See LICENSE.txt for details.
Issues
Please report any issues at: https://github.com/mulesoft-emu/anypoint-cli-core-library/issues
