@coin-voyage/shared 2.2.5-beta.0 → 2.2.5-beta.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/dist/api/client.d.ts +2 -2
- package/dist/api/client.js +12 -6
- package/dist/api/fetcher.js +1 -1
- package/dist/types/api.d.ts +6 -3
- package/package.json +1 -1
package/dist/api/client.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { type APIEnvironment } from "./config";
|
|
|
4
4
|
import { type APIResponse } from "./fetcher";
|
|
5
5
|
export declare class ApiClient {
|
|
6
6
|
private readonly apiKey;
|
|
7
|
-
private readonly environment
|
|
7
|
+
private readonly environment;
|
|
8
8
|
private readonly sessionId?;
|
|
9
9
|
private readonly version?;
|
|
10
10
|
constructor({ apiKey, sessionId, environment, version, }: {
|
|
@@ -278,7 +278,7 @@ export declare class ApiClient {
|
|
|
278
278
|
* Subscribe to an order's events after the connection is open:
|
|
279
279
|
* ```ts
|
|
280
280
|
* const socket = apiClient.subscribeOrderStatus()
|
|
281
|
-
* socket.onOpen(() => socket.subscribe(
|
|
281
|
+
* socket.onOpen(() => socket.subscribe(orderId)) // omit orderId to subscribe to all org orders
|
|
282
282
|
* socket.onMessage((msg) => {
|
|
283
283
|
* if (msg.type === 'event') console.log(msg.data)
|
|
284
284
|
* })
|
package/dist/api/client.js
CHANGED
|
@@ -471,7 +471,7 @@ export class ApiClient {
|
|
|
471
471
|
* Subscribe to an order's events after the connection is open:
|
|
472
472
|
* ```ts
|
|
473
473
|
* const socket = apiClient.subscribeOrderStatus()
|
|
474
|
-
* socket.onOpen(() => socket.subscribe(
|
|
474
|
+
* socket.onOpen(() => socket.subscribe(orderId)) // omit orderId to subscribe to all org orders
|
|
475
475
|
* socket.onMessage((msg) => {
|
|
476
476
|
* if (msg.type === 'event') console.log(msg.data)
|
|
477
477
|
* })
|
|
@@ -480,7 +480,7 @@ export class ApiClient {
|
|
|
480
480
|
* @returns {OrderStatusSocket} - Handle for subscribing, receiving messages, and closing the connection.
|
|
481
481
|
*/
|
|
482
482
|
subscribeOrderStatus() {
|
|
483
|
-
const ws = new WebSocket(WS_URL[this.environment
|
|
483
|
+
const ws = new WebSocket(WS_URL[this.environment]);
|
|
484
484
|
const messageListeners = [];
|
|
485
485
|
const pendingMessages = [];
|
|
486
486
|
ws.addEventListener("open", () => {
|
|
@@ -511,11 +511,17 @@ export class ApiClient {
|
|
|
511
511
|
}
|
|
512
512
|
};
|
|
513
513
|
return {
|
|
514
|
-
subscribe(
|
|
515
|
-
send({ type: "subscribe", data: {
|
|
514
|
+
subscribe(orderId) {
|
|
515
|
+
send({ type: "subscribe", data: { order_id: orderId } });
|
|
516
516
|
},
|
|
517
|
-
|
|
518
|
-
send({ type: "
|
|
517
|
+
subscribeOrg() {
|
|
518
|
+
send({ type: "subscribe", data: {} });
|
|
519
|
+
},
|
|
520
|
+
unsubscribe(orderId) {
|
|
521
|
+
send({ type: "unsubscribe", data: orderId ? { order_id: orderId } : {} });
|
|
522
|
+
},
|
|
523
|
+
unsubscribeOrg() {
|
|
524
|
+
send({ type: "unsubscribe", data: {} });
|
|
519
525
|
},
|
|
520
526
|
onMessage(callback) {
|
|
521
527
|
messageListeners.push(callback);
|
package/dist/api/fetcher.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { API_URL } from "./config";
|
|
2
2
|
export async function fetchApi(opts) {
|
|
3
3
|
try {
|
|
4
|
-
const baseUrl = API_URL[opts.environment
|
|
4
|
+
const baseUrl = API_URL[opts.environment || "production"];
|
|
5
5
|
const response = await fetch(`${baseUrl}${opts.path}`, {
|
|
6
6
|
...opts.options,
|
|
7
7
|
headers: {
|
package/dist/types/api.d.ts
CHANGED
|
@@ -143,7 +143,8 @@ export type WsConnectedMessage = {
|
|
|
143
143
|
export type WsSubscriptionMessage = {
|
|
144
144
|
type: WsMessageType.Subscription;
|
|
145
145
|
data: {
|
|
146
|
-
|
|
146
|
+
order_id?: string;
|
|
147
|
+
scope: "order" | "organization";
|
|
147
148
|
status: "subscribed" | "unsubscribed";
|
|
148
149
|
};
|
|
149
150
|
};
|
|
@@ -159,8 +160,10 @@ export type WsErrorMessage = {
|
|
|
159
160
|
};
|
|
160
161
|
export type WsServerMessage = WsConnectedMessage | WsSubscriptionMessage | WsEventMessage | WsErrorMessage;
|
|
161
162
|
export type OrderStatusSocket = {
|
|
162
|
-
subscribe: (
|
|
163
|
-
|
|
163
|
+
subscribe: (orderId: string) => void;
|
|
164
|
+
subscribeOrg: () => void;
|
|
165
|
+
unsubscribe: (orderId?: string) => void;
|
|
166
|
+
unsubscribeOrg: () => void;
|
|
164
167
|
onMessage: (callback: (msg: WsServerMessage) => void) => void;
|
|
165
168
|
onOpen: (callback: () => void) => void;
|
|
166
169
|
onClose: (callback: (event: CloseEvent) => void) => void;
|