@adaptic/utils 0.1.2 → 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.
- package/dist/index.cjs +33 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +33 -9
- package/dist/index.mjs.map +1 -1
- package/dist/test.js +33 -9
- package/dist/test.js.map +1 -1
- package/dist/types/alpaca-market-data-api.d.ts +2 -0
- package/dist/types/alpaca-market-data-api.d.ts.map +1 -1
- package/dist/types/utils/auth-validator.d.ts +9 -4
- package/dist/types/utils/auth-validator.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -320,23 +320,42 @@ const fetchAssetOverview = async (symbol) => {
|
|
|
320
320
|
/**
|
|
321
321
|
* Validates Alpaca API credentials
|
|
322
322
|
* @param auth - Authentication object containing API key and secret
|
|
323
|
-
* @
|
|
323
|
+
* @param options - Validation options
|
|
324
|
+
* @param options.throwOnMissing - If false, missing credentials will log a warning instead of throwing (default: true)
|
|
325
|
+
* @throws {Error} If credentials are invalid (when throwOnMissing is true)
|
|
326
|
+
* @returns {boolean} True if credentials are valid, false if missing (when throwOnMissing is false)
|
|
324
327
|
*/
|
|
325
|
-
function validateAlpacaCredentials(auth) {
|
|
328
|
+
function validateAlpacaCredentials(auth, options = { throwOnMissing: true }) {
|
|
329
|
+
const { throwOnMissing = true } = options;
|
|
330
|
+
// Check for missing or empty API key
|
|
326
331
|
if (!auth.apiKey ||
|
|
327
332
|
typeof auth.apiKey !== "string" ||
|
|
328
333
|
auth.apiKey.trim().length === 0) {
|
|
329
|
-
|
|
334
|
+
if (throwOnMissing) {
|
|
335
|
+
throw new Error("Invalid Alpaca API key: must be a non-empty string");
|
|
336
|
+
}
|
|
337
|
+
console.warn("[AlpacaAPI] API key not configured. Market data features will be unavailable.");
|
|
338
|
+
return false;
|
|
330
339
|
}
|
|
340
|
+
// Check for missing or empty API secret
|
|
331
341
|
if (!auth.apiSecret ||
|
|
332
342
|
typeof auth.apiSecret !== "string" ||
|
|
333
343
|
auth.apiSecret.trim().length === 0) {
|
|
334
|
-
|
|
344
|
+
if (throwOnMissing) {
|
|
345
|
+
throw new Error("Invalid Alpaca API secret: must be a non-empty string");
|
|
346
|
+
}
|
|
347
|
+
console.warn("[AlpacaAPI] API secret not configured. Market data features will be unavailable.");
|
|
348
|
+
return false;
|
|
335
349
|
}
|
|
336
350
|
// Alpaca keys are typically 20+ characters
|
|
337
351
|
if (auth.apiKey.length < 10) {
|
|
338
|
-
|
|
352
|
+
if (throwOnMissing) {
|
|
353
|
+
throw new Error("Alpaca API key appears to be too short");
|
|
354
|
+
}
|
|
355
|
+
console.warn("[AlpacaAPI] API key appears to be too short.");
|
|
356
|
+
return false;
|
|
339
357
|
}
|
|
358
|
+
return true;
|
|
340
359
|
}
|
|
341
360
|
/**
|
|
342
361
|
* Validates Polygon API key
|
|
@@ -12283,6 +12302,8 @@ class AlpacaMarketDataAPI extends require$$0$4.EventEmitter {
|
|
|
12283
12302
|
dataURL;
|
|
12284
12303
|
apiURL;
|
|
12285
12304
|
v1beta1url;
|
|
12305
|
+
/** Whether API credentials are valid and available. False during build time when env vars are missing. */
|
|
12306
|
+
credentialsValid = false;
|
|
12286
12307
|
stockStreamUrl = getStockStreamUrl("PRODUCTION"); // production values
|
|
12287
12308
|
optionStreamUrl = getOptionsStreamUrl("PRODUCTION"); // production values
|
|
12288
12309
|
cryptoStreamUrl = getCryptoStreamUrl("PRODUCTION"); // production values
|
|
@@ -12338,13 +12359,16 @@ class AlpacaMarketDataAPI extends require$$0$4.EventEmitter {
|
|
|
12338
12359
|
constructor() {
|
|
12339
12360
|
super();
|
|
12340
12361
|
// Validate credentials from environment variables before initializing
|
|
12341
|
-
|
|
12342
|
-
|
|
12343
|
-
|
|
12362
|
+
// Use throwOnMissing: false to allow initialization during build time
|
|
12363
|
+
// when env vars are not available. Features will be unavailable until
|
|
12364
|
+
// credentials are provided at runtime.
|
|
12365
|
+
const apiKey = process.env.ALPACA_API_KEY || "";
|
|
12366
|
+
const apiSecret = process.env.ALPACA_SECRET_KEY || "";
|
|
12367
|
+
this.credentialsValid = validateAlpacaCredentials({
|
|
12344
12368
|
apiKey,
|
|
12345
12369
|
apiSecret,
|
|
12346
12370
|
isPaper: process.env.ALPACA_ACCOUNT_TYPE === "PAPER",
|
|
12347
|
-
});
|
|
12371
|
+
}, { throwOnMissing: false });
|
|
12348
12372
|
this.dataURL = MARKET_DATA_API.STOCKS;
|
|
12349
12373
|
this.apiURL =
|
|
12350
12374
|
process.env.ALPACA_ACCOUNT_TYPE === "PAPER"
|