@revenium/claude-code-metering 0.1.3 → 0.1.5

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 (78) hide show
  1. package/.env.example +15 -0
  2. package/.eslintrc.js +24 -0
  3. package/.github/workflows/branch-bypass-alert.yml +68 -0
  4. package/CODE_OF_CONDUCT.md +57 -0
  5. package/CONTRIBUTING.md +73 -0
  6. package/README.md +57 -3
  7. package/SECURITY.md +46 -0
  8. package/dist/cli/commands/setup.js +3 -1
  9. package/dist/cli/commands/setup.js.map +1 -1
  10. package/dist/cli/index.d.ts.map +1 -1
  11. package/dist/cli/index.js +4 -1
  12. package/dist/cli/index.js.map +1 -1
  13. package/dist/core/api/client.d.ts.map +1 -1
  14. package/dist/core/api/client.js +4 -1
  15. package/dist/core/api/client.js.map +1 -1
  16. package/dist/core/tool-context.d.ts +6 -0
  17. package/dist/core/tool-context.d.ts.map +1 -0
  18. package/dist/core/tool-context.js +21 -0
  19. package/dist/core/tool-context.js.map +1 -0
  20. package/dist/core/tool-tracker.d.ts +4 -0
  21. package/dist/core/tool-tracker.d.ts.map +1 -0
  22. package/dist/core/tool-tracker.js +156 -0
  23. package/dist/core/tool-tracker.js.map +1 -0
  24. package/dist/index.d.ts +2 -0
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +2 -0
  27. package/dist/index.js.map +1 -1
  28. package/dist/types/index.d.ts +1 -0
  29. package/dist/types/index.d.ts.map +1 -1
  30. package/dist/types/index.js +15 -0
  31. package/dist/types/index.js.map +1 -1
  32. package/dist/types/tool-metering.d.ts +36 -0
  33. package/dist/types/tool-metering.d.ts.map +1 -0
  34. package/dist/types/tool-metering.js +3 -0
  35. package/dist/types/tool-metering.js.map +1 -0
  36. package/docs/research/settings-json-telemetry-findings.md +171 -0
  37. package/examples/README.md +114 -0
  38. package/examples/validation/validate-installation.sh +212 -0
  39. package/package.json +1 -7
  40. package/public-allowlist-node.txt +7 -0
  41. package/src/cli/commands/backfill.ts +865 -0
  42. package/src/cli/commands/setup.ts +254 -0
  43. package/src/cli/commands/status.ts +108 -0
  44. package/src/cli/commands/test.ts +91 -0
  45. package/src/cli/index.ts +103 -0
  46. package/src/core/api/client.ts +194 -0
  47. package/src/core/config/loader.ts +217 -0
  48. package/src/core/config/validator.ts +142 -0
  49. package/src/core/config/writer.ts +212 -0
  50. package/src/core/shell/detector.ts +92 -0
  51. package/src/core/shell/profile-updater.ts +131 -0
  52. package/src/core/tool-context.ts +23 -0
  53. package/src/core/tool-tracker.ts +204 -0
  54. package/src/index.ts +12 -0
  55. package/src/types/index.ts +110 -0
  56. package/src/types/tool-metering.ts +38 -0
  57. package/src/utils/constants.ts +80 -0
  58. package/src/utils/hashing.ts +35 -0
  59. package/src/utils/masking.ts +32 -0
  60. package/tests/integration/cli-commands.test.ts +158 -0
  61. package/tests/unit/backfill-command.test.ts +366 -0
  62. package/tests/unit/backfill-helpers.test.ts +397 -0
  63. package/tests/unit/backfill-parse.test.ts +276 -0
  64. package/tests/unit/backfill-stream.test.ts +147 -0
  65. package/tests/unit/backfill.test.ts +344 -0
  66. package/tests/unit/cli-index.test.ts +193 -0
  67. package/tests/unit/client.test.ts +195 -0
  68. package/tests/unit/detector.test.ts +247 -0
  69. package/tests/unit/hashing.test.ts +121 -0
  70. package/tests/unit/loader.test.ts +272 -0
  71. package/tests/unit/masking.test.ts +46 -0
  72. package/tests/unit/profile-updater.test.ts +146 -0
  73. package/tests/unit/setup.test.ts +557 -0
  74. package/tests/unit/status.test.ts +149 -0
  75. package/tests/unit/test.test.ts +165 -0
  76. package/tests/unit/validator.test.ts +211 -0
  77. package/tests/unit/writer.test.ts +176 -0
  78. package/tsconfig.json +20 -0
@@ -0,0 +1,212 @@
1
+ #!/bin/bash
2
+ # validate-installation.sh
3
+ # Comprehensive validation script for @revenium/claude-code-metering
4
+ #
5
+ # Usage: ./validate-installation.sh [--api-key KEY] [--endpoint URL]
6
+ #
7
+ # This script validates:
8
+ # 1. CLI is installed and accessible
9
+ # 2. Setup command works (creates config)
10
+ # 3. Status command shows correct configuration
11
+ # 4. Test command successfully sends metrics to Revenium
12
+ # 5. Generated config has correct OTEL settings
13
+
14
+ set -e
15
+
16
+ # Colors for output
17
+ RED='\033[0;31m'
18
+ GREEN='\033[0;32m'
19
+ YELLOW='\033[1;33m'
20
+ BLUE='\033[0;34m'
21
+ NC='\033[0m' # No Color
22
+
23
+ # Default values
24
+ API_KEY="${REVENIUM_API_KEY:-}"
25
+ ENDPOINT="${REVENIUM_ENDPOINT:-https://api.revenium.ai}"
26
+ TIER="pro"
27
+ EMAIL="validation@test.com"
28
+
29
+ # Parse arguments
30
+ while [[ $# -gt 0 ]]; do
31
+ case $1 in
32
+ --api-key)
33
+ API_KEY="$2"
34
+ shift 2
35
+ ;;
36
+ --endpoint)
37
+ ENDPOINT="$2"
38
+ shift 2
39
+ ;;
40
+ --tier)
41
+ TIER="$2"
42
+ shift 2
43
+ ;;
44
+ *)
45
+ echo "Unknown option: $1"
46
+ exit 1
47
+ ;;
48
+ esac
49
+ done
50
+
51
+ echo -e "${BLUE}╔════════════════════════════════════════════════════════════╗${NC}"
52
+ echo -e "${BLUE}║ @revenium/claude-code-metering - Validation Suite ║${NC}"
53
+ echo -e "${BLUE}╚════════════════════════════════════════════════════════════╝${NC}"
54
+ echo ""
55
+
56
+ PASS_COUNT=0
57
+ FAIL_COUNT=0
58
+
59
+ pass() {
60
+ echo -e "${GREEN}✓ PASS:${NC} $1"
61
+ ((PASS_COUNT++))
62
+ }
63
+
64
+ fail() {
65
+ echo -e "${RED}✗ FAIL:${NC} $1"
66
+ ((FAIL_COUNT++))
67
+ }
68
+
69
+ warn() {
70
+ echo -e "${YELLOW}⚠ WARN:${NC} $1"
71
+ }
72
+
73
+ # ═══════════════════════════════════════════════════════════════
74
+ # CHECK 1: CLI Installation
75
+ # ═══════════════════════════════════════════════════════════════
76
+ echo -e "\n${BLUE}[1/5] Checking CLI installation...${NC}"
77
+
78
+ if command -v revenium-metering &> /dev/null; then
79
+ VERSION=$(revenium-metering --version 2>/dev/null || echo "unknown")
80
+ pass "CLI installed (version: $VERSION)"
81
+ else
82
+ fail "CLI not found. Install with: npm install -g @revenium/claude-code-metering"
83
+ echo "Aborting validation - CLI required for remaining tests"
84
+ exit 1
85
+ fi
86
+
87
+ # ═══════════════════════════════════════════════════════════════
88
+ # CHECK 2: Help Commands
89
+ # ═══════════════════════════════════════════════════════════════
90
+ echo -e "\n${BLUE}[2/5] Checking help commands...${NC}"
91
+
92
+ if revenium-metering --help &> /dev/null; then
93
+ pass "Main help command works"
94
+ else
95
+ fail "Main help command failed"
96
+ fi
97
+
98
+ if revenium-metering setup --help &> /dev/null; then
99
+ pass "Setup help command works"
100
+ else
101
+ fail "Setup help command failed"
102
+ fi
103
+
104
+ # ═══════════════════════════════════════════════════════════════
105
+ # CHECK 3: Setup Command (requires API key)
106
+ # ═══════════════════════════════════════════════════════════════
107
+ echo -e "\n${BLUE}[3/5] Checking setup command...${NC}"
108
+
109
+ if [ -z "$API_KEY" ]; then
110
+ warn "No API key provided. Skipping setup test."
111
+ warn "Run with: ./validate-installation.sh --api-key hak_your_key"
112
+ else
113
+ # Backup existing config if present
114
+ CONFIG_FILE="$HOME/.claude/revenium.env"
115
+ BACKUP_FILE="$HOME/.claude/revenium.env.backup.$$"
116
+
117
+ if [ -f "$CONFIG_FILE" ]; then
118
+ cp "$CONFIG_FILE" "$BACKUP_FILE"
119
+ echo "Backed up existing config to $BACKUP_FILE"
120
+ fi
121
+
122
+ # Run setup in non-interactive mode
123
+ if revenium-metering setup \
124
+ --api-key "$API_KEY" \
125
+ --email "$EMAIL" \
126
+ --tier "$TIER" \
127
+ --endpoint "$ENDPOINT" \
128
+ --skip-shell-update &> /dev/null; then
129
+ pass "Setup command completed"
130
+
131
+ # Verify config file created
132
+ if [ -f "$CONFIG_FILE" ]; then
133
+ pass "Config file created at $CONFIG_FILE"
134
+
135
+ # Check OTEL settings (CRITICAL)
136
+ if grep -q "OTEL_METRICS_EXPORTER=otlp" "$CONFIG_FILE"; then
137
+ pass "OTEL_METRICS_EXPORTER correctly set to 'otlp'"
138
+ else
139
+ fail "OTEL_METRICS_EXPORTER not set correctly"
140
+ fi
141
+
142
+ if grep -q "OTEL_EXPORTER_OTLP_ENDPOINT" "$CONFIG_FILE"; then
143
+ pass "OTEL_EXPORTER_OTLP_ENDPOINT configured"
144
+ else
145
+ fail "OTEL_EXPORTER_OTLP_ENDPOINT missing"
146
+ fi
147
+
148
+ # Check for legacy OTEL_LOGS_EXPORTER (should NOT be present)
149
+ if grep -q "OTEL_LOGS_EXPORTER" "$CONFIG_FILE"; then
150
+ fail "Config contains legacy OTEL_LOGS_EXPORTER (should be OTEL_METRICS_EXPORTER)"
151
+ else
152
+ pass "No legacy OTEL_LOGS_EXPORTER present"
153
+ fi
154
+
155
+ else
156
+ fail "Config file not created"
157
+ fi
158
+ else
159
+ fail "Setup command failed"
160
+ fi
161
+
162
+ # Restore backup if it existed
163
+ if [ -f "$BACKUP_FILE" ]; then
164
+ mv "$BACKUP_FILE" "$CONFIG_FILE"
165
+ echo "Restored original config"
166
+ fi
167
+ fi
168
+
169
+ # ═══════════════════════════════════════════════════════════════
170
+ # CHECK 4: Status Command
171
+ # ═══════════════════════════════════════════════════════════════
172
+ echo -e "\n${BLUE}[4/5] Checking status command...${NC}"
173
+
174
+ if revenium-metering status &> /dev/null; then
175
+ pass "Status command works"
176
+ else
177
+ warn "Status command returned non-zero (may be expected if not configured)"
178
+ fi
179
+
180
+ # ═══════════════════════════════════════════════════════════════
181
+ # CHECK 5: Test Command (requires API key)
182
+ # ═══════════════════════════════════════════════════════════════
183
+ echo -e "\n${BLUE}[5/5] Checking test command...${NC}"
184
+
185
+ if [ -z "$API_KEY" ]; then
186
+ warn "No API key provided. Skipping test command."
187
+ else
188
+ if revenium-metering test --verbose --endpoint "$ENDPOINT" 2>&1 | grep -q "success\|200"; then
189
+ pass "Test command sent metrics successfully"
190
+ else
191
+ warn "Test command completed but success unclear - check manually"
192
+ fi
193
+ fi
194
+
195
+ # ═══════════════════════════════════════════════════════════════
196
+ # SUMMARY
197
+ # ═══════════════════════════════════════════════════════════════
198
+ echo -e "\n${BLUE}═══════════════════════════════════════════════════════════════${NC}"
199
+ echo -e "${BLUE}VALIDATION SUMMARY${NC}"
200
+ echo -e "${BLUE}═══════════════════════════════════════════════════════════════${NC}"
201
+ echo ""
202
+ echo -e "Passed: ${GREEN}$PASS_COUNT${NC}"
203
+ echo -e "Failed: ${RED}$FAIL_COUNT${NC}"
204
+ echo ""
205
+
206
+ if [ $FAIL_COUNT -eq 0 ]; then
207
+ echo -e "${GREEN}All validations passed!${NC}"
208
+ exit 0
209
+ else
210
+ echo -e "${RED}Some validations failed. Review output above.${NC}"
211
+ exit 1
212
+ fi
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revenium/claude-code-metering",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "CLI tool to configure Claude Code telemetry export to Revenium",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -35,12 +35,6 @@
35
35
  "url": "https://github.com/revenium/revenium-claude-code-sdk/issues"
36
36
  },
37
37
  "homepage": "https://github.com/revenium/revenium-claude-code-sdk#readme",
38
- "files": [
39
- "dist",
40
- "README.md",
41
- "LICENSE",
42
- "CHANGELOG.md"
43
- ],
44
38
  "engines": {
45
39
  "node": ">=20.0.0"
46
40
  },
@@ -0,0 +1,7 @@
1
+ src/
2
+ docs/
3
+ package.json
4
+ tsconfig.json
5
+ .gitignore
6
+ README.md
7
+ public-allowlist-node.txt