@0xmonaco/core 0.1.1 → 0.1.6
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/api/applications/api.d.ts +45 -0
- package/dist/api/applications/api.d.ts.map +1 -0
- package/dist/api/applications/api.js +61 -0
- package/dist/api/applications/api.js.map +1 -0
- package/dist/api/applications/index.d.ts +6 -0
- package/dist/api/applications/index.d.ts.map +1 -0
- package/dist/api/applications/index.js +5 -0
- package/dist/api/applications/index.js.map +1 -0
- package/dist/api/auth/api.d.ts +7 -7
- package/dist/api/auth/api.d.ts.map +1 -1
- package/dist/api/auth/api.js +6 -6
- package/dist/api/auth/api.js.map +1 -1
- package/dist/api/base.d.ts +99 -0
- package/dist/api/base.d.ts.map +1 -0
- package/dist/api/base.js +132 -0
- package/dist/api/base.js.map +1 -0
- package/dist/api/index.d.ts +5 -1
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +5 -1
- package/dist/api/index.js.map +1 -1
- package/dist/api/profile/api.d.ts +54 -0
- package/dist/api/profile/api.d.ts.map +1 -0
- package/dist/api/profile/api.js +77 -0
- package/dist/api/profile/api.js.map +1 -0
- package/dist/api/profile/index.d.ts +7 -0
- package/dist/api/profile/index.d.ts.map +1 -0
- package/dist/api/profile/index.js +7 -0
- package/dist/api/profile/index.js.map +1 -0
- package/dist/api/trading/api.d.ts +77 -22
- package/dist/api/trading/api.d.ts.map +1 -1
- package/dist/api/trading/api.js +128 -42
- package/dist/api/trading/api.js.map +1 -1
- package/dist/api/vault/api.d.ts +15 -11
- package/dist/api/vault/api.d.ts.map +1 -1
- package/dist/api/vault/api.js +57 -41
- package/dist/api/vault/api.js.map +1 -1
- package/dist/api/websocket/client.d.ts +57 -0
- package/dist/api/websocket/client.d.ts.map +1 -0
- package/dist/api/websocket/client.js +207 -0
- package/dist/api/websocket/client.js.map +1 -0
- package/dist/api/websocket/index.d.ts +7 -0
- package/dist/api/websocket/index.d.ts.map +1 -0
- package/dist/api/websocket/index.js +7 -0
- package/dist/api/websocket/index.js.map +1 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/networks.js +1 -1
- package/dist/networks.js.map +1 -1
- package/dist/sdk.d.ts +32 -35
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +113 -127
- package/dist/sdk.js.map +1 -1
- package/package.json +7 -5
- package/dist/chains.d.ts +0 -90
- package/dist/chains.d.ts.map +0 -1
- package/dist/chains.js +0 -56
- package/dist/chains.js.map +0 -1
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Applications API Implementation
|
|
3
|
+
*
|
|
4
|
+
* Handles application configuration operations. All operations go through
|
|
5
|
+
* the API Gateway and require valid authentication.
|
|
6
|
+
*
|
|
7
|
+
* This class provides an interface for retrieving application configuration
|
|
8
|
+
* on the Monaco protocol.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const applicationsAPI = new ApplicationsAPIImpl(apiUrl);
|
|
13
|
+
*
|
|
14
|
+
* // Get application configuration
|
|
15
|
+
* const config = await applicationsAPI.getApplicationConfig();
|
|
16
|
+
* console.log(`App name: ${config.name}`);
|
|
17
|
+
* console.log(`Allowed origins: ${config.allowedOrigins.join(', ')}`);
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
import type { ApplicationConfigResponse, ApplicationsAPI } from "@0xmonaco/types";
|
|
21
|
+
import { BaseAPI } from "../base";
|
|
22
|
+
export declare class ApplicationsAPIImpl extends BaseAPI implements ApplicationsAPI {
|
|
23
|
+
/**
|
|
24
|
+
* Gets the configuration for the authenticated application.
|
|
25
|
+
*
|
|
26
|
+
* Returns the application's configuration including allowed origins,
|
|
27
|
+
* webhook URL, and other settings. Requires valid authentication.
|
|
28
|
+
*
|
|
29
|
+
* @returns Promise resolving to the application configuration
|
|
30
|
+
* @throws {APIError} When the request fails or authentication is invalid
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const config = await applicationsAPI.getApplicationConfig();
|
|
35
|
+
* console.log(`Application: ${config.name}`);
|
|
36
|
+
* console.log(`ID: ${config.id}`);
|
|
37
|
+
* console.log(`Allowed origins: ${config.allowedOrigins.join(', ')}`);
|
|
38
|
+
* if (config.webhookUrl) {
|
|
39
|
+
* console.log(`Webhook: ${config.webhookUrl}`);
|
|
40
|
+
* }
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
getApplicationConfig(): Promise<ApplicationConfigResponse>;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/api/applications/api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EACX,yBAAyB,EACzB,eAAe,EACf,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,qBAAa,mBAAoB,SAAQ,OAAQ,YAAW,eAAe;IAC1E;;;;;;;;;;;;;;;;;;;OAmBG;IACG,oBAAoB,IAAI,OAAO,CAAC,yBAAyB,CAAC;CAuBhE"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Applications API Implementation
|
|
3
|
+
*
|
|
4
|
+
* Handles application configuration operations. All operations go through
|
|
5
|
+
* the API Gateway and require valid authentication.
|
|
6
|
+
*
|
|
7
|
+
* This class provides an interface for retrieving application configuration
|
|
8
|
+
* on the Monaco protocol.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const applicationsAPI = new ApplicationsAPIImpl(apiUrl);
|
|
13
|
+
*
|
|
14
|
+
* // Get application configuration
|
|
15
|
+
* const config = await applicationsAPI.getApplicationConfig();
|
|
16
|
+
* console.log(`App name: ${config.name}`);
|
|
17
|
+
* console.log(`Allowed origins: ${config.allowedOrigins.join(', ')}`);
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
import { APIError } from "../../errors";
|
|
21
|
+
import { BaseAPI } from "../base";
|
|
22
|
+
export class ApplicationsAPIImpl extends BaseAPI {
|
|
23
|
+
/**
|
|
24
|
+
* Gets the configuration for the authenticated application.
|
|
25
|
+
*
|
|
26
|
+
* Returns the application's configuration including allowed origins,
|
|
27
|
+
* webhook URL, and other settings. Requires valid authentication.
|
|
28
|
+
*
|
|
29
|
+
* @returns Promise resolving to the application configuration
|
|
30
|
+
* @throws {APIError} When the request fails or authentication is invalid
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const config = await applicationsAPI.getApplicationConfig();
|
|
35
|
+
* console.log(`Application: ${config.name}`);
|
|
36
|
+
* console.log(`ID: ${config.id}`);
|
|
37
|
+
* console.log(`Allowed origins: ${config.allowedOrigins.join(', ')}`);
|
|
38
|
+
* if (config.webhookUrl) {
|
|
39
|
+
* console.log(`Webhook: ${config.webhookUrl}`);
|
|
40
|
+
* }
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
async getApplicationConfig() {
|
|
44
|
+
try {
|
|
45
|
+
const data = await this.makeAuthenticatedRequest("/api/v1/applications/config", {
|
|
46
|
+
method: "GET",
|
|
47
|
+
});
|
|
48
|
+
return {
|
|
49
|
+
id: data.id,
|
|
50
|
+
name: data.name,
|
|
51
|
+
allowedOrigins: data.allowed_origins,
|
|
52
|
+
webhookUrl: data.webhook_url,
|
|
53
|
+
vaultContractAddress: data.vault_contract_address,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
throw new APIError("Failed to get application config from API", "/api/v1/applications/config", undefined);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/api/applications/api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAMH,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,MAAM,OAAO,mBAAoB,SAAQ,OAAO;IAC/C;;;;;;;;;;;;;;;;;;;OAmBG;IACH,KAAK,CAAC,oBAAoB;QACzB,IAAI,CAAC;YACJ,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,wBAAwB,CAC/C,6BAA6B,EAC7B;gBACC,MAAM,EAAE,KAAK;aACb,CACD,CAAC;YACF,OAAO;gBACN,EAAE,EAAE,IAAI,CAAC,EAAE;gBACX,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,cAAc,EAAE,IAAI,CAAC,eAAe;gBACpC,UAAU,EAAE,IAAI,CAAC,WAAW;gBAC5B,oBAAoB,EAAE,IAAI,CAAC,sBAAsB;aACjD,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,MAAM,IAAI,QAAQ,CACjB,2CAA2C,EAC3C,6BAA6B,EAC7B,SAAS,CACT,CAAC;QACH,CAAC;IACF,CAAC;CACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/applications/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,YAAY,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,OAAO,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/applications/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,mBAAmB,EAAE,MAAM,OAAO,CAAC"}
|
package/dist/api/auth/api.d.ts
CHANGED
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
* const backendAuth = await authAPI.authenticateBackend(secretKey);
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
|
-
import {
|
|
32
|
-
import
|
|
31
|
+
import type { AuthAPI, BackendAuthResponse, ChallengeResponse, TokenRefreshResponse, VerifyResponse } from "@0xmonaco/types";
|
|
32
|
+
import type { Chain, WalletClient } from "viem";
|
|
33
33
|
export declare class AuthAPIImpl implements AuthAPI {
|
|
34
34
|
private readonly walletClient;
|
|
35
35
|
private readonly apiUrl;
|
|
@@ -177,22 +177,22 @@ export declare class AuthAPIImpl implements AuthAPI {
|
|
|
177
177
|
*/
|
|
178
178
|
refreshToken(refreshToken: string): Promise<TokenRefreshResponse>;
|
|
179
179
|
/**
|
|
180
|
-
* Revokes a
|
|
180
|
+
* Revokes a session token.
|
|
181
181
|
*
|
|
182
|
-
* Invalidates a
|
|
182
|
+
* Invalidates a session token, preventing it from being used to obtain
|
|
183
183
|
* new access tokens. This is useful for logout functionality or when
|
|
184
184
|
* a token has been compromised.
|
|
185
185
|
*
|
|
186
|
-
* @param
|
|
186
|
+
* @param sessionId - The session id to revoke
|
|
187
187
|
* @returns Promise resolving when the token is revoked
|
|
188
188
|
* @throws {APIError} When token revocation fails
|
|
189
189
|
*
|
|
190
190
|
* @example
|
|
191
191
|
* ```typescript
|
|
192
|
-
* await authAPI.revokeToken(
|
|
192
|
+
* await authAPI.revokeToken(sessionId);
|
|
193
193
|
* console.log("Token revoked successfully");
|
|
194
194
|
* ```
|
|
195
195
|
*/
|
|
196
|
-
revokeToken(
|
|
196
|
+
revokeToken(sessionId: string): Promise<void>;
|
|
197
197
|
}
|
|
198
198
|
//# sourceMappingURL=api.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/api/auth/api.ts"],"names":[],"mappings":"AAAA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;;;;;;;;;;;;OAiBG;IACG,YAAY,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAkCvE;;;;;;;;;;;;;;;;OAgBG;IACG,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CA2BnD"}
|
package/dist/api/auth/api.js
CHANGED
|
@@ -320,23 +320,23 @@ export class AuthAPIImpl {
|
|
|
320
320
|
}
|
|
321
321
|
}
|
|
322
322
|
/**
|
|
323
|
-
* Revokes a
|
|
323
|
+
* Revokes a session token.
|
|
324
324
|
*
|
|
325
|
-
* Invalidates a
|
|
325
|
+
* Invalidates a session token, preventing it from being used to obtain
|
|
326
326
|
* new access tokens. This is useful for logout functionality or when
|
|
327
327
|
* a token has been compromised.
|
|
328
328
|
*
|
|
329
|
-
* @param
|
|
329
|
+
* @param sessionId - The session id to revoke
|
|
330
330
|
* @returns Promise resolving when the token is revoked
|
|
331
331
|
* @throws {APIError} When token revocation fails
|
|
332
332
|
*
|
|
333
333
|
* @example
|
|
334
334
|
* ```typescript
|
|
335
|
-
* await authAPI.revokeToken(
|
|
335
|
+
* await authAPI.revokeToken(sessionId);
|
|
336
336
|
* console.log("Token revoked successfully");
|
|
337
337
|
* ```
|
|
338
338
|
*/
|
|
339
|
-
async revokeToken(
|
|
339
|
+
async revokeToken(sessionId) {
|
|
340
340
|
try {
|
|
341
341
|
const response = await fetch(`${this.apiUrl}/api/v1/auth/revoke`, {
|
|
342
342
|
method: "POST",
|
|
@@ -344,7 +344,7 @@ export class AuthAPIImpl {
|
|
|
344
344
|
"Content-Type": "application/json",
|
|
345
345
|
},
|
|
346
346
|
body: JSON.stringify({
|
|
347
|
-
|
|
347
|
+
session_id: sessionId,
|
|
348
348
|
}),
|
|
349
349
|
});
|
|
350
350
|
if (!response.ok) {
|
package/dist/api/auth/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src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AAI,CAAC,MAAM,qBAAqB,EAAE;gBACjE,MAAM,EAAE,MAAM;gBACd,OAAO,EAAE;oBACR,cAAc,EAAE,kBAAkB;iBAClC;gBACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;oBACpB,UAAU,EAAE,SAAS;iBACrB,CAAC;aACF,CAAC,CAAC;YAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;gBAClB,MAAM,IAAI,QAAQ,CACjB,uBAAuB,QAAQ,CAAC,MAAM,EAAE,EACxC,GAAG,IAAI,CAAC,MAAM,qBAAqB,EACnC,QAAQ,CAAC,MAAM,CACf,CAAC;YACH,CAAC;QACF,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,MAAM,IAAI,QAAQ,CACjB,wBAAwB,EACxB,GAAG,IAAI,CAAC,MAAM,qBAAqB,EACnC,SAAS,CACT,CAAC;QACH,CAAC;IACF,CAAC;CACD"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base API Implementation
|
|
3
|
+
*
|
|
4
|
+
* Provides common functionality for all API classes including access token management,
|
|
5
|
+
* authenticated request handling, and standardized error responses.
|
|
6
|
+
*
|
|
7
|
+
* This base class eliminates code duplication across API implementations and provides
|
|
8
|
+
* a consistent interface for token-based authentication and HTTP request handling.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* class MyAPIImpl extends BaseAPI implements MyAPI {
|
|
13
|
+
* constructor(apiUrl: string) {
|
|
14
|
+
* super(apiUrl);
|
|
15
|
+
* }
|
|
16
|
+
*
|
|
17
|
+
* async getData(): Promise<any> {
|
|
18
|
+
* return this.makeAuthenticatedRequest<any>('/api/v1/data');
|
|
19
|
+
* }
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare abstract class BaseAPI {
|
|
24
|
+
protected readonly apiUrl: string;
|
|
25
|
+
protected accessToken?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Creates a new BaseAPI instance.
|
|
28
|
+
*
|
|
29
|
+
* @param apiUrl - The base URL for the Monaco API Gateway
|
|
30
|
+
*/
|
|
31
|
+
constructor(apiUrl: string);
|
|
32
|
+
/**
|
|
33
|
+
* Set the access token for authenticated requests.
|
|
34
|
+
*
|
|
35
|
+
* @param token - JWT access token
|
|
36
|
+
*/
|
|
37
|
+
setAccessToken(token: string): void;
|
|
38
|
+
/**
|
|
39
|
+
* Get the current access token.
|
|
40
|
+
*
|
|
41
|
+
* @returns The current access token or undefined if not set
|
|
42
|
+
*/
|
|
43
|
+
protected getAccessToken(): string | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Makes an authenticated API request with automatic token handling.
|
|
46
|
+
*
|
|
47
|
+
* This method automatically includes the Authorization header with the Bearer token
|
|
48
|
+
* and provides consistent error handling across all API operations.
|
|
49
|
+
*
|
|
50
|
+
* @param endpoint - The API endpoint to call (should start with /)
|
|
51
|
+
* @param options - Request options (method, body, headers, etc.)
|
|
52
|
+
* @returns Promise resolving to the response data
|
|
53
|
+
* @throws {APIError} When access token is not set or API request fails
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* // GET request
|
|
58
|
+
* const data = await this.makeAuthenticatedRequest<UserProfile>('/api/v1/profile');
|
|
59
|
+
*
|
|
60
|
+
* // POST request
|
|
61
|
+
* const result = await this.makeAuthenticatedRequest<CreateOrderResponse>(
|
|
62
|
+
* '/api/v1/orders',
|
|
63
|
+
* {
|
|
64
|
+
* method: 'POST',
|
|
65
|
+
* body: JSON.stringify({ trading_pair: 'ETH-USD', side: 'BUY' })
|
|
66
|
+
* }
|
|
67
|
+
* );
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
protected makeAuthenticatedRequest<T>(endpoint: string, options?: RequestInit): Promise<T>;
|
|
71
|
+
/**
|
|
72
|
+
* Makes an unauthenticated API request.
|
|
73
|
+
*
|
|
74
|
+
* This method is useful for endpoints that don't require authentication,
|
|
75
|
+
* such as public data endpoints or authentication endpoints themselves.
|
|
76
|
+
*
|
|
77
|
+
* @param endpoint - The API endpoint to call (should start with /)
|
|
78
|
+
* @param options - Request options (method, body, headers, etc.)
|
|
79
|
+
* @returns Promise resolving to the response data
|
|
80
|
+
* @throws {APIError} When API request fails
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* // Public endpoint
|
|
85
|
+
* const data = await this.makePublicRequest<PublicData>('/api/v1/public/markets');
|
|
86
|
+
*
|
|
87
|
+
* // Authentication endpoint
|
|
88
|
+
* const challenge = await this.makePublicRequest<ChallengeResponse>(
|
|
89
|
+
* '/api/v1/auth/challenge',
|
|
90
|
+
* {
|
|
91
|
+
* method: 'POST',
|
|
92
|
+
* body: JSON.stringify({ address, client_id: clientId })
|
|
93
|
+
* }
|
|
94
|
+
* );
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
protected makePublicRequest<T>(endpoint: string, options?: RequestInit): Promise<T>;
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/api/base.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAIH,8BAAsB,OAAO;IAQhB,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM;IAP7C,SAAS,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAE/B;;;;OAIG;gBAC4B,MAAM,EAAE,MAAM;IAE7C;;;;OAIG;IACH,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAInC;;;;OAIG;IACH,SAAS,CAAC,cAAc,IAAI,MAAM,GAAG,SAAS;IAI9C;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;cACa,wBAAwB,CAAC,CAAC,EACzC,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,WAAgB,GACvB,OAAO,CAAC,CAAC,CAAC;IA6Bb;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;cACa,iBAAiB,CAAC,CAAC,EAClC,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,WAAgB,GACvB,OAAO,CAAC,CAAC,CAAC;CAmBb"}
|
package/dist/api/base.js
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base API Implementation
|
|
3
|
+
*
|
|
4
|
+
* Provides common functionality for all API classes including access token management,
|
|
5
|
+
* authenticated request handling, and standardized error responses.
|
|
6
|
+
*
|
|
7
|
+
* This base class eliminates code duplication across API implementations and provides
|
|
8
|
+
* a consistent interface for token-based authentication and HTTP request handling.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* class MyAPIImpl extends BaseAPI implements MyAPI {
|
|
13
|
+
* constructor(apiUrl: string) {
|
|
14
|
+
* super(apiUrl);
|
|
15
|
+
* }
|
|
16
|
+
*
|
|
17
|
+
* async getData(): Promise<any> {
|
|
18
|
+
* return this.makeAuthenticatedRequest<any>('/api/v1/data');
|
|
19
|
+
* }
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
import { APIError } from "../errors";
|
|
24
|
+
export class BaseAPI {
|
|
25
|
+
/**
|
|
26
|
+
* Creates a new BaseAPI instance.
|
|
27
|
+
*
|
|
28
|
+
* @param apiUrl - The base URL for the Monaco API Gateway
|
|
29
|
+
*/
|
|
30
|
+
constructor(apiUrl) {
|
|
31
|
+
this.apiUrl = apiUrl;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Set the access token for authenticated requests.
|
|
35
|
+
*
|
|
36
|
+
* @param token - JWT access token
|
|
37
|
+
*/
|
|
38
|
+
setAccessToken(token) {
|
|
39
|
+
this.accessToken = token;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Get the current access token.
|
|
43
|
+
*
|
|
44
|
+
* @returns The current access token or undefined if not set
|
|
45
|
+
*/
|
|
46
|
+
getAccessToken() {
|
|
47
|
+
return this.accessToken;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Makes an authenticated API request with automatic token handling.
|
|
51
|
+
*
|
|
52
|
+
* This method automatically includes the Authorization header with the Bearer token
|
|
53
|
+
* and provides consistent error handling across all API operations.
|
|
54
|
+
*
|
|
55
|
+
* @param endpoint - The API endpoint to call (should start with /)
|
|
56
|
+
* @param options - Request options (method, body, headers, etc.)
|
|
57
|
+
* @returns Promise resolving to the response data
|
|
58
|
+
* @throws {APIError} When access token is not set or API request fails
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* // GET request
|
|
63
|
+
* const data = await this.makeAuthenticatedRequest<UserProfile>('/api/v1/profile');
|
|
64
|
+
*
|
|
65
|
+
* // POST request
|
|
66
|
+
* const result = await this.makeAuthenticatedRequest<CreateOrderResponse>(
|
|
67
|
+
* '/api/v1/orders',
|
|
68
|
+
* {
|
|
69
|
+
* method: 'POST',
|
|
70
|
+
* body: JSON.stringify({ trading_pair: 'ETH-USD', side: 'BUY' })
|
|
71
|
+
* }
|
|
72
|
+
* );
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
async makeAuthenticatedRequest(endpoint, options = {}) {
|
|
76
|
+
if (!this.accessToken) {
|
|
77
|
+
throw new APIError("Access token not set. Call setAccessToken() first.", `${this.apiUrl}${endpoint}`, 401);
|
|
78
|
+
}
|
|
79
|
+
const response = await fetch(`${this.apiUrl}${endpoint}`, {
|
|
80
|
+
headers: {
|
|
81
|
+
"Content-Type": "application/json",
|
|
82
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
83
|
+
...options.headers,
|
|
84
|
+
},
|
|
85
|
+
...options,
|
|
86
|
+
});
|
|
87
|
+
if (!response.ok) {
|
|
88
|
+
throw new APIError(`API request failed: ${response.status}`, `${this.apiUrl}${endpoint}`, response.status);
|
|
89
|
+
}
|
|
90
|
+
return response.json();
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Makes an unauthenticated API request.
|
|
94
|
+
*
|
|
95
|
+
* This method is useful for endpoints that don't require authentication,
|
|
96
|
+
* such as public data endpoints or authentication endpoints themselves.
|
|
97
|
+
*
|
|
98
|
+
* @param endpoint - The API endpoint to call (should start with /)
|
|
99
|
+
* @param options - Request options (method, body, headers, etc.)
|
|
100
|
+
* @returns Promise resolving to the response data
|
|
101
|
+
* @throws {APIError} When API request fails
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* // Public endpoint
|
|
106
|
+
* const data = await this.makePublicRequest<PublicData>('/api/v1/public/markets');
|
|
107
|
+
*
|
|
108
|
+
* // Authentication endpoint
|
|
109
|
+
* const challenge = await this.makePublicRequest<ChallengeResponse>(
|
|
110
|
+
* '/api/v1/auth/challenge',
|
|
111
|
+
* {
|
|
112
|
+
* method: 'POST',
|
|
113
|
+
* body: JSON.stringify({ address, client_id: clientId })
|
|
114
|
+
* }
|
|
115
|
+
* );
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
async makePublicRequest(endpoint, options = {}) {
|
|
119
|
+
const response = await fetch(`${this.apiUrl}${endpoint}`, {
|
|
120
|
+
headers: {
|
|
121
|
+
"Content-Type": "application/json",
|
|
122
|
+
...options.headers,
|
|
123
|
+
},
|
|
124
|
+
...options,
|
|
125
|
+
});
|
|
126
|
+
if (!response.ok) {
|
|
127
|
+
throw new APIError(`API request failed: ${response.status}`, `${this.apiUrl}${endpoint}`, response.status);
|
|
128
|
+
}
|
|
129
|
+
return response.json();
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/api/base.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;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AE;QAEzB,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,CAAC,MAAM,GAAG,QAAQ,EAAE,EAAE;YACzD,OAAO,EAAE;gBACR,cAAc,EAAE,kBAAkB;gBAClC,GAAG,OAAO,CAAC,OAAO;aAClB;YACD,GAAG,OAAO;SACV,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YAClB,MAAM,IAAI,QAAQ,CACjB,uBAAuB,QAAQ,CAAC,MAAM,EAAE,EACxC,GAAG,IAAI,CAAC,MAAM,GAAG,QAAQ,EAAE,EAC3B,QAAQ,CAAC,MAAM,CACf,CAAC;QACH,CAAC;QAED,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;IACxB,CAAC;CACD"}
|
package/dist/api/index.d.ts
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
*
|
|
4
4
|
* This module exports the new simplified APIs for the Monaco SDK.
|
|
5
5
|
*/
|
|
6
|
-
export * from "./
|
|
6
|
+
export * from "./applications";
|
|
7
|
+
export * from "./base";
|
|
8
|
+
export * from "./profile";
|
|
7
9
|
export * from "./trading";
|
|
10
|
+
export * from "./vault";
|
|
11
|
+
export * from "./websocket";
|
|
8
12
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/api/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC"}
|
package/dist/api/index.js
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
*
|
|
4
4
|
* This module exports the new simplified APIs for the Monaco SDK.
|
|
5
5
|
*/
|
|
6
|
-
export * from "./
|
|
6
|
+
export * from "./applications";
|
|
7
|
+
export * from "./base";
|
|
8
|
+
export * from "./profile";
|
|
7
9
|
export * from "./trading";
|
|
10
|
+
export * from "./vault";
|
|
11
|
+
export * from "./websocket";
|
|
8
12
|
//# sourceMappingURL=index.js.map
|
package/dist/api/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Profile API Implementation
|
|
3
|
+
*
|
|
4
|
+
* Handles user profile operations including fetching profile information.
|
|
5
|
+
* All operations use JWT authentication and go through the API Gateway.
|
|
6
|
+
*
|
|
7
|
+
* This class provides a complete interface for profile operations on the Monaco protocol,
|
|
8
|
+
* including fetching user profile data from the /api/v1/accounts/me endpoint.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const profileAPI = new ProfileAPIImpl(apiUrl);
|
|
13
|
+
* profileAPI.setAccessToken(jwtToken);
|
|
14
|
+
*
|
|
15
|
+
* // Get user profile
|
|
16
|
+
* const profile = await profileAPI.getProfile();
|
|
17
|
+
* console.log(`User: ${profile.username} (${profile.address})`);
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
import type { ProfileAPI, UserProfile } from "@0xmonaco/types";
|
|
21
|
+
import { BaseAPI } from "../base";
|
|
22
|
+
export declare class ProfileAPIImpl extends BaseAPI implements ProfileAPI {
|
|
23
|
+
/**
|
|
24
|
+
* Creates a new ProfileAPI instance.
|
|
25
|
+
*
|
|
26
|
+
* @param apiUrl - The base URL for the Monaco API Gateway
|
|
27
|
+
*/
|
|
28
|
+
constructor(apiUrl: string);
|
|
29
|
+
/**
|
|
30
|
+
* Get the current user's profile information.
|
|
31
|
+
*
|
|
32
|
+
* Fetches the profile data for the authenticated user using the /api/v1/accounts/me endpoint.
|
|
33
|
+
* Requires a valid access token to be set.
|
|
34
|
+
*
|
|
35
|
+
* @returns Promise resolving to the user's profile information
|
|
36
|
+
* @throws {APIError} When the request fails or user is not authenticated
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* // Set access token first
|
|
41
|
+
* profileAPI.setAccessToken(authResult.accessToken);
|
|
42
|
+
*
|
|
43
|
+
* // Get profile
|
|
44
|
+
* const profile = await profileAPI.getProfile();
|
|
45
|
+
* console.log(`User ID: ${profile.id}`);
|
|
46
|
+
* console.log(`Address: ${profile.address}`);
|
|
47
|
+
* console.log(`Username: ${profile.username}`);
|
|
48
|
+
* console.log(`Account type: ${profile.account_type}`);
|
|
49
|
+
* console.log(`Can withdraw: ${profile.can_withdraw}`);
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
getProfile(): Promise<UserProfile>;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/api/profile/api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE/D,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,qBAAa,cAAe,SAAQ,OAAQ,YAAW,UAAU;IAChE;;;;OAIG;gBACS,MAAM,EAAE,MAAM;IAI1B;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACG,UAAU,IAAI,OAAO,CAAC,WAAW,CAAC;CA0BxC"}
|