b5-api-client 0.0.28 → 0.0.29

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.
@@ -1,5 +1,5 @@
1
1
  import { AxiosRequestConfig } from 'axios';
2
- import { CreateOrderRequest, CreateUserRequest, Order, OrderResponse, TakeOrderRequest, TestEventParams, UpdateOrderRequest, TransactionStatusResponse, RateUserRequest, OrderEventsResponse, PushNotificationsRegisterRequest, ConfigResponse, DashboardMetricsResponse, UsersResponse, GetOrdersParams, CreateDisputeRequest, DisputesResponse, OrderOffersResponse, TransactionRequest, KioscoinOperationResponse, UpdateUserSettingsRequest, NotificationsResponse, VerifyEmailRequest } from './types';
2
+ import { CreateOrderRequest, CreateUserRequest, Order, OrderResponse, TakeOrderRequest, TestEventParams, UpdateOrderRequest, TransactionStatusResponse, RateUserRequest, OrderEventsResponse, PushNotificationsRegisterRequest, ConfigResponse, DashboardMetricsResponse, UsersResponse, GetOrdersParams, CreateDisputeRequest, DisputesResponse, OrderOffersResponse, TransactionRequest, KioscoinOperationResponse, UpdateUserSettingsRequest, NotificationsResponse, VerifyEmailRequest, CreateSessionRequest, CreateSessionResponse } from './types';
3
3
  import { AuthTokenProvider } from './auth/AuthTokenProvider';
4
4
  export interface RequestConfigWithRetry extends AxiosRequestConfig {
5
5
  _retry?: boolean;
@@ -37,5 +37,22 @@ declare class P2PMarketplaceAPIClient {
37
37
  releaseFunds(order: Order, testParams?: TestEventParams, headers?: Record<string, string>): Promise<string>;
38
38
  getTransactionStatus(txHash: string, headers?: Record<string, string>): Promise<TransactionStatusResponse>;
39
39
  createDispute(request: CreateDisputeRequest, headers?: Record<string, string>): Promise<DisputesResponse>;
40
+ /**
41
+ * Create or refresh a session with Firebase ID token
42
+ * Sets a session cookie that will be used for WebSocket authentication
43
+ */
44
+ createSession(request: CreateSessionRequest, headers?: Record<string, string>): Promise<CreateSessionResponse>;
45
+ /**
46
+ * Check if the current session is valid
47
+ * Returns session status and userId if valid
48
+ */
49
+ getSessionStatus(headers?: Record<string, string>): Promise<CreateSessionResponse>;
50
+ /**
51
+ * Clear the session cookie (logout)
52
+ * Destroys the session on the backend
53
+ */
54
+ clearSession(headers?: Record<string, string>): Promise<{
55
+ success: boolean;
56
+ }>;
40
57
  }
41
58
  export default P2PMarketplaceAPIClient;
@@ -19,6 +19,7 @@ class P2PMarketplaceAPIClient {
19
19
  this.client = axios_1.default.create({
20
20
  baseURL,
21
21
  timeout,
22
+ withCredentials: true, // Enable sending/receiving cookies
22
23
  });
23
24
  this.defaultHeaders = {
24
25
  'x-api-secret': 'test',
@@ -307,6 +308,45 @@ class P2PMarketplaceAPIClient {
307
308
  return this.post(url, request, headers);
308
309
  });
309
310
  }
311
+ // Session Management
312
+ /**
313
+ * Create or refresh a session with Firebase ID token
314
+ * Sets a session cookie that will be used for WebSocket authentication
315
+ */
316
+ createSession(request, headers) {
317
+ return __awaiter(this, void 0, void 0, function* () {
318
+ const url = '/api/session';
319
+ return this.post(url, request, headers);
320
+ });
321
+ }
322
+ /**
323
+ * Check if the current session is valid
324
+ * Returns session status and userId if valid
325
+ */
326
+ getSessionStatus(headers) {
327
+ return __awaiter(this, void 0, void 0, function* () {
328
+ const url = '/api/session';
329
+ return this.get(url, headers);
330
+ });
331
+ }
332
+ /**
333
+ * Clear the session cookie (logout)
334
+ * Destroys the session on the backend
335
+ */
336
+ clearSession(headers) {
337
+ return __awaiter(this, void 0, void 0, function* () {
338
+ const url = '/api/session';
339
+ const config = this.createConfig(headers);
340
+ try {
341
+ const response = yield this.client.delete(url, config);
342
+ return response.data;
343
+ }
344
+ catch (error) {
345
+ console.error(`DELETE request to ${url} failed:`, error);
346
+ throw error;
347
+ }
348
+ });
349
+ }
310
350
  }
311
351
  function toSnakeCase(obj) {
312
352
  if (Array.isArray(obj)) {
package/dist/types.d.ts CHANGED
@@ -64,6 +64,13 @@ export interface UpdateUserSettingsRequest {
64
64
  export interface VerifyEmailRequest {
65
65
  loginId: string;
66
66
  }
67
+ export interface CreateSessionRequest {
68
+ idToken: string;
69
+ }
70
+ export interface CreateSessionResponse {
71
+ success: boolean;
72
+ userId?: string;
73
+ }
67
74
  export interface PaymentMethod {
68
75
  type: string;
69
76
  alias?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "b5-api-client",
3
- "version": "0.0.28",
3
+ "version": "0.0.29",
4
4
  "description": "Escrow Backend API client",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,5 +1,5 @@
1
1
  import axios, { AxiosError, AxiosInstance, AxiosRequestConfig } from 'axios';
2
- import { CreateOrderRequest, CreateUserRequest, Order, OrderResponse, TakeOrderRequest, TestEventParams, UpdateOrderRequest, TransactionStatusResponse, RateUserRequest, OrderEventsResponse, PushNotificationsRegisterRequest, ConfigResponse, DashboardMetricsResponse, UsersResponse, GetOrdersParams, CreateDisputeRequest, DisputesResponse, OrderOffersResponse, TransactionRequest, KioscoinOperationResponse, UpdateUserSettingsRequest, NotificationsResponse, VerifyEmailRequest } from './types';
2
+ import { CreateOrderRequest, CreateUserRequest, Order, OrderResponse, TakeOrderRequest, TestEventParams, UpdateOrderRequest, TransactionStatusResponse, RateUserRequest, OrderEventsResponse, PushNotificationsRegisterRequest, ConfigResponse, DashboardMetricsResponse, UsersResponse, GetOrdersParams, CreateDisputeRequest, DisputesResponse, OrderOffersResponse, TransactionRequest, KioscoinOperationResponse, UpdateUserSettingsRequest, NotificationsResponse, VerifyEmailRequest, CreateSessionRequest, CreateSessionResponse } from './types';
3
3
  import { AuthTokenProvider } from './auth/AuthTokenProvider';
4
4
  import { isPlainObject, camelCase, snakeCase, transform } from 'lodash';
5
5
 
@@ -17,6 +17,7 @@ class P2PMarketplaceAPIClient {
17
17
  this.client = axios.create({
18
18
  baseURL,
19
19
  timeout,
20
+ withCredentials: true, // Enable sending/receiving cookies
20
21
  });
21
22
 
22
23
  this.defaultHeaders = {
@@ -290,6 +291,42 @@ class P2PMarketplaceAPIClient {
290
291
  return this.post<DisputesResponse>(url, request, headers);
291
292
  }
292
293
 
294
+ // Session Management
295
+
296
+ /**
297
+ * Create or refresh a session with Firebase ID token
298
+ * Sets a session cookie that will be used for WebSocket authentication
299
+ */
300
+ public async createSession(request: CreateSessionRequest, headers?: Record<string, string>): Promise<CreateSessionResponse> {
301
+ const url = '/api/session';
302
+ return this.post<CreateSessionResponse>(url, request, headers);
303
+ }
304
+
305
+ /**
306
+ * Check if the current session is valid
307
+ * Returns session status and userId if valid
308
+ */
309
+ public async getSessionStatus(headers?: Record<string, string>): Promise<CreateSessionResponse> {
310
+ const url = '/api/session';
311
+ return this.get<CreateSessionResponse>(url, headers);
312
+ }
313
+
314
+ /**
315
+ * Clear the session cookie (logout)
316
+ * Destroys the session on the backend
317
+ */
318
+ public async clearSession(headers?: Record<string, string>): Promise<{ success: boolean }> {
319
+ const url = '/api/session';
320
+ const config = this.createConfig(headers);
321
+ try {
322
+ const response = await this.client.delete<{ success: boolean }>(url, config);
323
+ return response.data;
324
+ } catch (error) {
325
+ console.error(`DELETE request to ${url} failed:`, error);
326
+ throw error;
327
+ }
328
+ }
329
+
293
330
  }
294
331
 
295
332
  function toSnakeCase(obj: any): any {
package/src/types.ts CHANGED
@@ -92,6 +92,15 @@ export interface VerifyEmailRequest {
92
92
  loginId: string;
93
93
  }
94
94
 
95
+ export interface CreateSessionRequest {
96
+ idToken: string;
97
+ }
98
+
99
+ export interface CreateSessionResponse {
100
+ success: boolean;
101
+ userId?: string;
102
+ }
103
+
95
104
  export interface PaymentMethod {
96
105
  type: string;
97
106
  alias?: string;