@monarkmarkets/api-client 1.0.2 → 1.0.4
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/README.md +157 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +24 -24
- package/src/Client.ts +7026 -7026
- package/src/index.ts +1 -1
- package/tsconfig.json +12 -12
package/README.md
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# @monarkmarkets/api-client
|
|
2
|
+
|
|
3
|
+
This package provides a TypeScript client for interacting with the Monark Markets API.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @monarkmarkets/api-client
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
To use this client, you'll need to set up a simple proxy server that forwards requests to the Monark API with the appropriate authentication.
|
|
14
|
+
|
|
15
|
+
### Important: API Proxy Server Requirement
|
|
16
|
+
|
|
17
|
+
This client requires a server running under the `/api` path that forwards requests to the Monark API with authentication. This proxy server:
|
|
18
|
+
|
|
19
|
+
1. Injects authentication credentials
|
|
20
|
+
2. Forwards all requests to the Monark API
|
|
21
|
+
3. Returns the responses to the client
|
|
22
|
+
|
|
23
|
+
## Setting up a Proxy Server
|
|
24
|
+
|
|
25
|
+
Below is an example of a minimal Express.js server that forwards requests to the Monark API:
|
|
26
|
+
|
|
27
|
+
```javascript
|
|
28
|
+
// server.js
|
|
29
|
+
import express from 'express';
|
|
30
|
+
import axios from "axios";
|
|
31
|
+
import * as dotenv from 'dotenv';
|
|
32
|
+
dotenv.config();
|
|
33
|
+
|
|
34
|
+
const app = express();
|
|
35
|
+
|
|
36
|
+
const API_BASE_URL = process.env.API_BASE_URL || 'https://demo-api.monark-markets.com';
|
|
37
|
+
const AUTH_TOKEN = process.env.AUTH_TOKEN;
|
|
38
|
+
|
|
39
|
+
// Parse JSON payloads
|
|
40
|
+
app.use(express.json());
|
|
41
|
+
|
|
42
|
+
// API router for forwarding requests
|
|
43
|
+
const apiRouter = express.Router();
|
|
44
|
+
|
|
45
|
+
apiRouter.use('*', async (req, res) => {
|
|
46
|
+
try {
|
|
47
|
+
// Build the target URL by combining base URL and original path
|
|
48
|
+
let targetUrl = `${API_BASE_URL}${req.originalUrl}`;
|
|
49
|
+
targetUrl = targetUrl.replace("/api/", "/");
|
|
50
|
+
|
|
51
|
+
// Forward the request to the target API
|
|
52
|
+
const response = await axios({
|
|
53
|
+
method: req.method,
|
|
54
|
+
url: targetUrl,
|
|
55
|
+
data: req.body,
|
|
56
|
+
headers: {
|
|
57
|
+
// Add the authorization header
|
|
58
|
+
'Authorization': `Bearer ${AUTH_TOKEN}`
|
|
59
|
+
},
|
|
60
|
+
// Forward query parameters
|
|
61
|
+
params: req.query,
|
|
62
|
+
// Handle binary responses
|
|
63
|
+
responseType: 'arraybuffer'
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// Set response headers
|
|
67
|
+
Object.entries(response.headers).forEach(([key, value]) => {
|
|
68
|
+
// Skip Transfer-Encoding header to prevent conflicts with Express
|
|
69
|
+
if (key.toLowerCase() !== 'transfer-encoding') {
|
|
70
|
+
res.set(key, value);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// Send response
|
|
75
|
+
res.status(response.status).send(response.data);
|
|
76
|
+
|
|
77
|
+
} catch (error) {
|
|
78
|
+
// Handle errors from the target API
|
|
79
|
+
if (error.response) {
|
|
80
|
+
res.status(error.response.status).send(error.response.data);
|
|
81
|
+
} else {
|
|
82
|
+
res.status(500).json({
|
|
83
|
+
error: 'Internal Server Error',
|
|
84
|
+
message: error.message
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// Mount API router - all API routes will be prefixed with /api
|
|
91
|
+
app.use('/api', apiRouter);
|
|
92
|
+
|
|
93
|
+
const PORT = process.env.PORT || 3000;
|
|
94
|
+
app.listen(PORT, () => {
|
|
95
|
+
console.log(`API proxy server running on port ${PORT}`);
|
|
96
|
+
});
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Environment Variables
|
|
100
|
+
|
|
101
|
+
Create a `.env` file in your project root:
|
|
102
|
+
|
|
103
|
+
```env
|
|
104
|
+
API_BASE_URL=https://demo-api.monark-markets.com
|
|
105
|
+
AUTH_TOKEN=your_auth_token_here
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Using the Client
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
import { Client } from '@monarkmarkets/api-client';
|
|
112
|
+
|
|
113
|
+
// Initialize the client with the proxy API URL
|
|
114
|
+
const client = new Client('/api');
|
|
115
|
+
|
|
116
|
+
// Example: Get all PreIPOCompanies
|
|
117
|
+
async function getAllPreIPOCompanies() {
|
|
118
|
+
try {
|
|
119
|
+
// You can add optional parameters for search, pagination, etc.
|
|
120
|
+
const result = await client.preIpoCompany2(
|
|
121
|
+
undefined, // searchTerm (optional)
|
|
122
|
+
undefined, // sortOrder (optional)
|
|
123
|
+
1, // page
|
|
124
|
+
10 // pageSize
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
console.log(`Found ${result.pagination?.totalRecords || 0} companies`);
|
|
128
|
+
console.log('Companies:', result.items);
|
|
129
|
+
|
|
130
|
+
return result;
|
|
131
|
+
} catch (error) {
|
|
132
|
+
console.error('Error fetching PreIPO companies:', error);
|
|
133
|
+
throw error;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Call the function
|
|
138
|
+
getAllPreIPOCompanies();
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Authentication
|
|
142
|
+
|
|
143
|
+
The API client itself doesn't handle authentication. Instead, authentication happens at the proxy server level by including the `AUTH_TOKEN` in the forwarded requests.
|
|
144
|
+
|
|
145
|
+
## API Methods
|
|
146
|
+
|
|
147
|
+
The client provides methods for all API endpoints in the Monark API. Some examples include:
|
|
148
|
+
|
|
149
|
+
- `preIpoCompany2()` - Get all PreIPO companies
|
|
150
|
+
- `preIpoCompany(id)` - Get a PreIPO company by ID
|
|
151
|
+
- `indicationOfInterestPOST(body)` - Create an indication of interest
|
|
152
|
+
- `investorGET(id)` - Get investor information
|
|
153
|
+
- And many more...
|
|
154
|
+
|
|
155
|
+
For the full list of available methods, refer to the TypeScript definitions in the client code.
|
|
156
|
+
|
|
157
|
+
The full API documentation can be found here: <https://api-docs.monark-markets.com/>
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './Client';
|
|
1
|
+
export * from './Client.js';
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './Client';
|
|
1
|
+
export * from './Client.js';
|
package/package.json
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@monarkmarkets/api-client",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"main": "dist/index.js",
|
|
5
|
-
"module": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
|
-
"type": "module",
|
|
8
|
-
"exports": {
|
|
9
|
-
".": {
|
|
10
|
-
"import": "./dist/index.js",
|
|
11
|
-
"require": "./dist/index.js",
|
|
12
|
-
"types": "./dist/index.d.ts"
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
|
-
"repository": {
|
|
16
|
-
"type": "git",
|
|
17
|
-
"url": "git+https://github.com/Monark-Markets/ui-components.git"
|
|
18
|
-
},
|
|
19
|
-
"scripts": {
|
|
20
|
-
"build": "tsc"
|
|
21
|
-
},
|
|
22
|
-
"devDependencies": {
|
|
23
|
-
"typescript": "^5.7.3"
|
|
24
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@monarkmarkets/api-client",
|
|
3
|
+
"version": "1.0.4",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"module": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/Monark-Markets/ui-components.git"
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"typescript": "^5.7.3"
|
|
24
|
+
}
|
|
25
25
|
}
|