@coin-voyage/shared 2.2.5-beta.0 → 2.2.5-beta.3

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))
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))
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: {
@@ -1,7 +1,7 @@
1
1
  import { FiatCurrency } from "../common/currencies";
2
2
  import { ChainId, ChainType, PayOrderStatus } from "./enums";
3
3
  import { PayOrderEvent } from "./events";
4
- import { Currency, CurrencyAmount, CurrencyBase, CurrencyWithAmount, PaymentData, PayOrderMetadata, QuoteWithCurrency } from "./model";
4
+ import { CurrencyAmount, CurrencyBase, CurrencyWithAmount, PaymentData, PayOrderMetadata, QuoteWithCurrency } from "./model";
5
5
  export type PayOrderParams = {
6
6
  /**
7
7
  * Intent of the order.
@@ -26,22 +26,6 @@ export type PaymentDetailsParams = {
26
26
  export type PaymentDetails = {
27
27
  payorder_id: string;
28
28
  status: PayOrderStatus;
29
- /** @deprecated Use `data.expires_at` instead */
30
- expires_at: Date;
31
- /** @deprecated Use `data.refund_address` instead */
32
- refund_address: string;
33
- /** @deprecated Use `data.deposit_address` instead */
34
- deposit_address: string;
35
- /** @deprecated Use `data.receiving_address` instead */
36
- receiving_address: string;
37
- /** @deprecated Use `data.src` instead */
38
- source_currency: Currency;
39
- /** @deprecated Use `data.src.currency_amount` instead */
40
- source_amount: CurrencyAmount;
41
- /** @deprecated Use `data.dst` instead */
42
- destination_currency: Currency;
43
- /** @deprecated Use `data.dst.currency_amount` instead */
44
- destination_amount: CurrencyAmount;
45
29
  data: PaymentData;
46
30
  };
47
31
  export type PayOrderIntent = {
@@ -143,7 +127,8 @@ export type WsConnectedMessage = {
143
127
  export type WsSubscriptionMessage = {
144
128
  type: WsMessageType.Subscription;
145
129
  data: {
146
- payorder_id: string;
130
+ order_id?: string;
131
+ scope: "order" | "organization";
147
132
  status: "subscribed" | "unsubscribed";
148
133
  };
149
134
  };
@@ -159,8 +144,10 @@ export type WsErrorMessage = {
159
144
  };
160
145
  export type WsServerMessage = WsConnectedMessage | WsSubscriptionMessage | WsEventMessage | WsErrorMessage;
161
146
  export type OrderStatusSocket = {
162
- subscribe: (payorderId: string) => void;
163
- unsubscribe: (payorderId: string) => void;
147
+ subscribe: (orderId: string) => void;
148
+ subscribeOrg: () => void;
149
+ unsubscribe: (orderId?: string) => void;
150
+ unsubscribeOrg: () => void;
164
151
  onMessage: (callback: (msg: WsServerMessage) => void) => void;
165
152
  onOpen: (callback: () => void) => void;
166
153
  onClose: (callback: (event: CloseEvent) => void) => void;
@@ -1,12 +1,14 @@
1
1
  import { ParsedPayOrderMetadata } from "./model";
2
2
  import { Hex } from "./crypto";
3
3
  import { PaymentData } from "./model";
4
+ import { PayOrderStatus } from "./enums";
4
5
  export type PayOrderCreationErrorEvent = {
5
6
  type: "payorder_creation_error";
6
7
  errorMessage: string;
7
8
  };
8
9
  type EventBase = {
9
10
  payorder_id: string;
11
+ status: PayOrderStatus;
10
12
  metadata?: ParsedPayOrderMetadata;
11
13
  };
12
14
  export type PayOrderCreatedEvent = EventBase & {
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.3",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {