@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.
@@ -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(payorderId))
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
  * })
@@ -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(payorderId))
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 ?? "production"]);
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(payorderId) {
515
- send({ type: "subscribe", data: { payorder_id: payorderId } });
514
+ subscribe(orderId) {
515
+ send({ type: "subscribe", data: { order_id: orderId } });
516
516
  },
517
- unsubscribe(payorderId) {
518
- send({ type: "unsubscribe", data: { payorder_id: payorderId } });
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);
@@ -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 ?? "production"];
4
+ const baseUrl = API_URL[opts.environment || "production"];
5
5
  const response = await fetch(`${baseUrl}${opts.path}`, {
6
6
  ...opts.options,
7
7
  headers: {
@@ -143,7 +143,8 @@ export type WsConnectedMessage = {
143
143
  export type WsSubscriptionMessage = {
144
144
  type: WsMessageType.Subscription;
145
145
  data: {
146
- payorder_id: string;
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: (payorderId: string) => void;
163
- unsubscribe: (payorderId: string) => void;
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;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@coin-voyage/shared",
3
3
  "description": "Shared utilities for Coin Voyage",
4
- "version": "2.2.5-beta.0",
4
+ "version": "2.2.5-beta.1",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {