@itpay/cli 0.2.0 → 0.2.1
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.
- package/lib/env.js +9 -3
- package/lib/http.js +2 -2
- package/lib/runtime.js +1 -1
- package/package.json +1 -1
package/lib/env.js
CHANGED
|
@@ -5,7 +5,8 @@ import crypto from "node:crypto";
|
|
|
5
5
|
import { execFileSync } from "node:child_process";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
7
|
|
|
8
|
-
export const
|
|
8
|
+
export const OFFICIAL_API_BASE = "https://dev.api.itpay.ai";
|
|
9
|
+
export const DEFAULT_API_BASE = process.env.ITPAY_API_BASE || process.env.ITPAY_CORE_API_BASE || process.env.ITPAY_CORE_BASE_URL || OFFICIAL_API_BASE;
|
|
9
10
|
export const CONFIG_DIR = path.join(os.homedir(), ".itp");
|
|
10
11
|
export const CONFIG_PATH = path.join(CONFIG_DIR, "config.json");
|
|
11
12
|
export const STATE_PATH = path.join(CONFIG_DIR, "state.json");
|
|
@@ -150,7 +151,12 @@ function normalizePurchaseFlags(flags, required = false) {
|
|
|
150
151
|
}
|
|
151
152
|
|
|
152
153
|
function apiBase(flags = {}, config = readConfig()) {
|
|
153
|
-
return (flags.api_base || config
|
|
154
|
+
return (flags.api_base || configuredApiBase(config) || DEFAULT_API_BASE).replace(/\/$/, "");
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function configuredApiBase(config = readConfig()) {
|
|
158
|
+
const base = String(config.api_base || "").replace(/\/$/, "");
|
|
159
|
+
return base && base !== "https://sandbox.itpay.ai" ? base : "";
|
|
154
160
|
}
|
|
155
161
|
|
|
156
162
|
function readConfig() {
|
|
@@ -710,4 +716,4 @@ function safeErrorMessage(error) {
|
|
|
710
716
|
.replace(/sk-[A-Za-z0-9_-]+/g, "sk-****");
|
|
711
717
|
}
|
|
712
718
|
|
|
713
|
-
export { csvValues, booleanFlag, intFlag, splitCSV, queryString, appendURLQuery, positional, positionalArgs, stripInternalBuyerFields, apiTimeoutMs, parseFlags, normalizePurchaseFlags, apiBase, readConfig, packageVersion, writeConfig, readState, writeState, runPath, readRun, listRuns, writeRun, mergeRun, updateRun, updateCurrentRun, prepareSetupRun, withStateLock, readCredentials, writeCredentials, writeJSON0600, writeSessionCredentials, storeSessionCredential, readSessionToken, deleteSessionCredential, sanitizeAuthResponse, storeGrantCredential, readGrantCredential, deleteGrantCredential, grantSecretRef, detectNativeCredentialStore, writeNativeSecret, shouldUseNativeCredentialStore, readNativeSecret, deleteNativeSecret, commandExists, processIsRunning, ensureConfigDir, readText, readJSON, writeJSONWithBackup, writeTextWithBackup, fileMode, replaceManagedBlock, escapeRegExp, escapeTomlString, currentExecutable, quoteShell, output, outputError, maskSecret, cryptoRandom, sleep, cliCommand, shellQuote, safeErrorMessage };
|
|
719
|
+
export { csvValues, booleanFlag, intFlag, splitCSV, queryString, appendURLQuery, positional, positionalArgs, stripInternalBuyerFields, apiTimeoutMs, parseFlags, normalizePurchaseFlags, apiBase, configuredApiBase, readConfig, packageVersion, writeConfig, readState, writeState, runPath, readRun, listRuns, writeRun, mergeRun, updateRun, updateCurrentRun, prepareSetupRun, withStateLock, readCredentials, writeCredentials, writeJSON0600, writeSessionCredentials, storeSessionCredential, readSessionToken, deleteSessionCredential, sanitizeAuthResponse, storeGrantCredential, readGrantCredential, deleteGrantCredential, grantSecretRef, detectNativeCredentialStore, writeNativeSecret, shouldUseNativeCredentialStore, readNativeSecret, deleteNativeSecret, commandExists, processIsRunning, ensureConfigDir, readText, readJSON, writeJSONWithBackup, writeTextWithBackup, fileMode, replaceManagedBlock, escapeRegExp, escapeTomlString, currentExecutable, quoteShell, output, outputError, maskSecret, cryptoRandom, sleep, cliCommand, shellQuote, safeErrorMessage };
|
package/lib/http.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { apiBase, apiTimeoutMs, cryptoRandom, readConfig, readCredentials, readSessionToken, readState, safeErrorMessage, writeState } from "./env.js";
|
|
1
|
+
import { DEFAULT_API_BASE, apiBase, apiTimeoutMs, configuredApiBase, cryptoRandom, readConfig, readCredentials, readSessionToken, readState, safeErrorMessage, writeState } from "./env.js";
|
|
2
2
|
|
|
3
3
|
async function coreApi(pathname, options = {}, flags = {}) {
|
|
4
4
|
const headers = { "Content-Type": "application/json" };
|
|
@@ -96,7 +96,7 @@ function coreURL(pathname, flags = {}) {
|
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
function coreApiBase(flags = {}, config = readConfig()) {
|
|
99
|
-
const base = flags.api_base || flags.core_api_base ||
|
|
99
|
+
const base = flags.api_base || flags.core_api_base || configuredApiBase(config) || DEFAULT_API_BASE;
|
|
100
100
|
return String(base).replace(/\/$/, "");
|
|
101
101
|
}
|
|
102
102
|
|
package/lib/runtime.js
CHANGED
|
@@ -1146,7 +1146,7 @@ async function doctor(flags) {
|
|
|
1146
1146
|
const grantCredential = grantId ? readGrantCredential(grantId) : null;
|
|
1147
1147
|
output({
|
|
1148
1148
|
itp_version: VERSION,
|
|
1149
|
-
api_base:
|
|
1149
|
+
api_base: apiBase(flags),
|
|
1150
1150
|
account_id: config.account_id || null,
|
|
1151
1151
|
device_id: config.device_id || null,
|
|
1152
1152
|
authenticated: Boolean(readSessionToken(credentials)),
|