moralis-cli 0.1.1 → 0.1.3

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.
Files changed (3) hide show
  1. package/README.md +4 -2
  2. package/package.json +1 -1
  3. package/src/cli.js +68 -2
package/README.md CHANGED
@@ -6,8 +6,6 @@ Use the Moralis API via Moralis CLI directly inside your AI agent 🤖 while kee
6
6
 
7
7
  Follow these steps to start using Moralis CLI with your AI agent.
8
8
 
9
- ## Getting Started
10
-
11
9
  Install:
12
10
 
13
11
  ```bash
@@ -32,6 +30,10 @@ Connect to AI
32
30
 
33
31
  Import the [@moralis-cli](.codex/skills/moralis-cli/SKILL.md) skill into your AI agent and start making Moralis API calls securely.
34
32
 
33
+ ```
34
+ › Please install this skill: https://raw.githubusercontent.com/MoralisWeb3/moralis-cli/refs/heads/main/.codex/skills/moralis-cli/SKILL.md
35
+ ```
36
+
35
37
  ## Examples
36
38
 
37
39
  Codex:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "moralis-cli",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Use Moralis API via Moralis CLI directly inside AI agents with secure API key handling and access to EVM and Solana blockchain data.",
5
5
  "bin": {
6
6
  "moralis-cli": "bin/moralis-cli.js"
package/src/cli.js CHANGED
@@ -3,6 +3,7 @@
3
3
  const fsp = require('node:fs/promises');
4
4
  const os = require('node:os');
5
5
  const path = require('node:path');
6
+ const { version: CLI_VERSION } = require('../package.json');
6
7
 
7
8
  const CONFIG_DIR = process.env.MORALIS_CLI_CONFIG_DIR || path.join(os.homedir(), '.moralis-cli');
8
9
  const CONFIG_PATH = path.join(CONFIG_DIR, 'config.json');
@@ -436,6 +437,8 @@ function buildHttpRequest(apiTarget, spec, operation, params, parsedArgs, config
436
437
  }
437
438
 
438
439
  applyApiKeyAuth(spec, operation, config, headers, url);
440
+ headers.set('x-moralis-product', 'moralis-cli');
441
+ headers.set('x-moralis-cli-version', CLI_VERSION);
439
442
 
440
443
  let requestBody = undefined;
441
444
  if (bodyParamSeen && body !== undefined) {
@@ -1008,13 +1011,76 @@ async function fetchWithRetry(url, options, retryOptions = {}) {
1008
1011
  } catch (error) {
1009
1012
  lastError = error;
1010
1013
  if (attempt >= attempts || !shouldRetryError(error)) {
1011
- throw error;
1014
+ throw createFetchError(label, error);
1012
1015
  }
1013
1016
  await sleepWithBackoff(attempt, baseDelayMs);
1014
1017
  }
1015
1018
  }
1016
1019
 
1017
- throw lastError || new Error(`${label} failed`);
1020
+ if (lastError) {
1021
+ throw createFetchError(label, lastError);
1022
+ }
1023
+ throw new Error(`${label} failed`);
1024
+ }
1025
+
1026
+ function createFetchError(label, error) {
1027
+ const baseMessage = error && error.message ? error.message : String(error);
1028
+ const causeMessages = collectErrorCauseMessages(error);
1029
+ const details = causeMessages.length > 0 ? `; ${causeMessages.join('; ')}` : '';
1030
+ const message = `${label} failed: ${baseMessage}${details}`;
1031
+
1032
+ if (typeof Error === 'function' && error instanceof Error) {
1033
+ return new Error(message, { cause: error });
1034
+ }
1035
+
1036
+ return new Error(message);
1037
+ }
1038
+
1039
+ function collectErrorCauseMessages(error) {
1040
+ const messages = [];
1041
+ const seen = new Set();
1042
+ let current = error;
1043
+ let index = 0;
1044
+
1045
+ while (current && typeof current === 'object' && current.cause) {
1046
+ const cause = current.cause;
1047
+ if (!cause || seen.has(cause)) {
1048
+ break;
1049
+ }
1050
+ seen.add(cause);
1051
+ index += 1;
1052
+ messages.push(`cause ${index}: ${formatCauseDetails(cause)}`);
1053
+ current = cause;
1054
+ }
1055
+
1056
+ return messages;
1057
+ }
1058
+
1059
+ function formatCauseDetails(cause) {
1060
+ const message = cause && typeof cause.message === 'string' && cause.message ? cause.message : String(cause);
1061
+
1062
+ if (!cause || typeof cause !== 'object') {
1063
+ return message;
1064
+ }
1065
+
1066
+ const extras = [];
1067
+ if (typeof cause.code === 'string' && !message.includes(cause.code)) {
1068
+ extras.push(`code=${cause.code}`);
1069
+ }
1070
+ if (typeof cause.syscall === 'string') {
1071
+ extras.push(`syscall=${cause.syscall}`);
1072
+ }
1073
+ if (typeof cause.hostname === 'string') {
1074
+ extras.push(`hostname=${cause.hostname}`);
1075
+ }
1076
+ if (typeof cause.address === 'string') {
1077
+ extras.push(`address=${cause.address}`);
1078
+ }
1079
+ if (typeof cause.port === 'number') {
1080
+ extras.push(`port=${cause.port}`);
1081
+ }
1082
+
1083
+ return extras.length > 0 ? `${message} (${extras.join(', ')})` : message;
1018
1084
  }
1019
1085
 
1020
1086
  function shouldRetryResponse(response, attempt, maxAttempts) {