@bluexlab/maos-ts
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -1,4 +0,17 @@ | ||
declare const foo = "foo"; | ||
declare function fn(): void; | ||
interface MaosConfig { | ||
apiKey?: string; | ||
coreUrl?: string; | ||
} | ||
interface MaosResponse { | ||
[key: string]: object; | ||
} | ||
export { fn, foo }; | ||
declare class Maos { | ||
private apiKey; | ||
private coreUrl; | ||
constructor(config?: MaosConfig); | ||
private fetchWithAuth; | ||
getConfig(): Promise<MaosResponse>; | ||
} | ||
export { Maos, type MaosConfig, type MaosResponse }; |
@@ -1,8 +0,39 @@ | ||
// src/index.ts | ||
var foo = "foo"; | ||
function fn() { | ||
} | ||
// src/maos.ts | ||
import process from "process"; | ||
var Maos = class { | ||
apiKey; | ||
coreUrl; | ||
constructor(config = {}) { | ||
this.apiKey = config.apiKey || process.env.APIKEY || ""; | ||
this.coreUrl = config.coreUrl || process.env.CORE_URL || ""; | ||
if (!this.apiKey) { | ||
throw new Error("API key is required. Please provide it in the constructor or set the APIKEY environment variable."); | ||
} | ||
if (!this.coreUrl) { | ||
throw new Error("Core URL is required. Please provide it in the constructor or set the CORE_URL environment variable."); | ||
} | ||
} | ||
async fetchWithAuth(endpoint, options = {}) { | ||
const url = `${this.coreUrl}${endpoint}`; | ||
const headers = new Headers({ | ||
"Authorization": `Bearer ${this.apiKey}`, | ||
"Content-Type": "application/json", | ||
...options.headers | ||
}); | ||
const response = await fetch(url, { ...options, headers }); | ||
if (!response.ok) { | ||
throw new Error(`HTTP error! status: ${response.status}`); | ||
} | ||
return await response.json(); | ||
} | ||
async getConfig() { | ||
try { | ||
return await this.fetchWithAuth("/config"); | ||
} catch (error) { | ||
throw new Error(`Failed to get config: ${error instanceof Error ? error.message : error}`); | ||
} | ||
} | ||
}; | ||
export { | ||
fn, | ||
foo | ||
Maos | ||
}; |
{ | ||
"name": "@bluexlab/maos-ts", | ||
"type": "module", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "TypeScript binding of MAOS", | ||
@@ -27,2 +27,5 @@ "author": "Kevin Chung <kevin@bluextrade.com>", | ||
}, | ||
"dependencies": { | ||
"process": "^0.11.10" | ||
}, | ||
"devDependencies": { | ||
@@ -29,0 +32,0 @@ "@antfu/eslint-config": "^2.22.4", |
# MAOS TypeScript Library | ||
![MAOS Logo](./path-to-logo.png) | ||
## Introduction | ||
@@ -6,0 +4,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
5994
89
1
63
3
2
+ Addedprocess@^0.11.10
+ Addedprocess@0.11.10(transitive)