File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- import { logger } from "@iterable/api" ;
1+ import { IterableClient , logger } from "@iterable/api" ;
22
33import { CliError } from "./errors.js" ;
44import { getKeyManager } from "./key-manager.js" ;
55import { isTestEnv } from "./utils/cli-env.js" ;
6- import { COMMAND_NAME } from "./utils/command-info.js" ;
6+ import { COMMAND_NAME , PACKAGE_VERSION } from "./utils/command-info.js" ;
77import { sanitizeString } from "./utils/sanitize.js" ;
88
99export interface CliConfig {
1010 readonly apiKey : string ;
1111 readonly baseUrl : string ;
1212}
1313
14+ export function createClient ( config : CliConfig ) : IterableClient {
15+ const debug =
16+ process . env . ITERABLE_DEBUG === "true" ||
17+ process . env . ITERABLE_DEBUG_VERBOSE === "true" ;
18+ return new IterableClient ( {
19+ apiKey : config . apiKey ,
20+ baseUrl : config . baseUrl ,
21+ debug,
22+ debugVerbose : process . env . ITERABLE_DEBUG_VERBOSE === "true" ,
23+ customHeaders : { "User-Agent" : `iterable-cli/${ PACKAGE_VERSION } ` } ,
24+ } ) ;
25+ }
26+
1427/**
1528 * Load configuration.
1629 *
Original file line number Diff line number Diff line change 11#!/usr/bin/env node
22
3- import { IterableClient } from "@iterable/api" ;
43import chalk from "chalk" ;
54import { readFileSync } from "fs" ;
65import { z } from "zod" ;
76
8- import { loadCliConfig } from "./config.js" ;
7+ import { createClient , loadCliConfig } from "./config.js" ;
98import { CliError , UsageError } from "./errors.js" ;
109import { formatOutput , getDefaultFormat } from "./output.js" ;
1110import { buildParser , parseCommand } from "./parser.js" ;
@@ -77,15 +76,7 @@ async function main(): Promise<void> {
7776 }
7877
7978 const config = await loadCliConfig ( parsed . globalFlags . key ) ;
80- const debug =
81- process . env . ITERABLE_DEBUG === "true" ||
82- process . env . ITERABLE_DEBUG_VERBOSE === "true" ;
83- const client = new IterableClient ( {
84- apiKey : config . apiKey ,
85- baseUrl : config . baseUrl ,
86- debug,
87- debugVerbose : process . env . ITERABLE_DEBUG_VERBOSE === "true" ,
88- } ) ;
79+ const client = createClient ( config ) ;
8980
9081 try {
9182 let restArgs = parsed . rest ;
Original file line number Diff line number Diff line change 11/* eslint-disable no-console */
2- import { IterableClient } from "@iterable/api" ;
32import chalk from "chalk" ;
43import inquirer from "inquirer" ;
54
6- import { loadCliConfig } from "./config.js" ;
5+ import { createClient , loadCliConfig } from "./config.js" ;
76import type { ApiKeyMetadata , KeyManager } from "./key-manager.js" ;
87import { getKeyManager } from "./key-manager.js" ;
98import { getSpinner , isTestEnv } from "./utils/cli-env.js" ;
@@ -468,15 +467,7 @@ export async function handleKeysCommand(
468467 spinner . start ( "Validating API connection..." ) ;
469468 try {
470469 const config = await loadCliConfig ( keyOverride ) ;
471- const debug =
472- process . env . ITERABLE_DEBUG === "true" ||
473- process . env . ITERABLE_DEBUG_VERBOSE === "true" ;
474- const client = new IterableClient ( {
475- apiKey : config . apiKey ,
476- baseUrl : config . baseUrl ,
477- debug,
478- debugVerbose : process . env . ITERABLE_DEBUG_VERBOSE === "true" ,
479- } ) ;
470+ const client = createClient ( config ) ;
480471 try {
481472 await client . getUserFields ( ) ;
482473 spinner . succeed ( "API connection successful" ) ;
You can’t perform that action at this time.
0 commit comments