@echoxyz/sonar-react 0.12.2 → 0.13.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/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @echoxyz/sonar-react
2
2
 
3
+ ## 0.13.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [7101949]
8
+ - @echoxyz/sonar-core@0.14.1
9
+
10
+ ## 0.13.0
11
+
12
+ ### Minor Changes
13
+
14
+ - Add wrapper function and hook for ReadCommitmentData endpoint
15
+
16
+ ### Patch Changes
17
+
18
+ - Updated dependencies
19
+ - @echoxyz/sonar-core@0.14.0
20
+
3
21
  ## 0.12.2
4
22
 
5
23
  ### Patch Changes
package/README.md CHANGED
@@ -231,6 +231,12 @@ function PurchaseButton({
231
231
 
232
232
  - `useSonarEntities()` → `{ authenticated, loading, entities?, error? }` high-level hook for fetching all entities available to the authenticated user.
233
233
 
234
+ - `useSonarPurchase()` → `{ loading, readyToPurchase, error?, generatePurchasePermit() }` high-level hook to check if the user is ready to purchase and generate a purchase permit.
235
+
236
+ - `useEntityInvestmentHistory()` → `{ loading, investmentHistory?, error? }` high-level hook to fetch Echo private group investment history for a given entity.
237
+
238
+ - `useCommitmentData()` → `{ loading, commitmentData?, error? }` high-level hook to poll for commitment data for a given sale. Note this calls a public API endpoint so the client does not need to be authenticated.
239
+
234
240
  ## Notes
235
241
 
236
242
  - Tokens are not auto-refreshed. On expiry, call `logout()` and re-run the OAuth flow.
package/dist/index.cjs CHANGED
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  SonarProvider: () => SonarProvider,
24
+ useCommitmentData: () => useCommitmentData,
24
25
  useEntityInvestmentHistory: () => useEntityInvestmentHistory,
25
26
  useSonarAuth: () => useSonarAuth,
26
27
  useSonarClient: () => useSonarClient,
@@ -406,9 +407,49 @@ function useEntityInvestmentHistory() {
406
407
  error: state.error
407
408
  };
408
409
  }
410
+ var MIN_POLLING_INTERVAL_MS = 1e3;
411
+ function useCommitmentData(args) {
412
+ const saleUUID = args.saleUUID;
413
+ const pollingIntervalMs = args.pollingIntervalMs;
414
+ if (pollingIntervalMs !== void 0 && pollingIntervalMs < MIN_POLLING_INTERVAL_MS) {
415
+ throw new Error(`pollingIntervalMs must be at least ${MIN_POLLING_INTERVAL_MS}ms`);
416
+ }
417
+ const client = useSonarClient();
418
+ const [state, setState] = (0, import_react2.useState)({
419
+ loading: false
420
+ });
421
+ const refetch = (0, import_react2.useCallback)(async () => {
422
+ setState((s) => ({ ...s, loading: true }));
423
+ try {
424
+ const resp = await client.readCommitmentData({ saleUUID });
425
+ setState({
426
+ loading: false,
427
+ commitmentData: resp,
428
+ error: void 0
429
+ });
430
+ } catch (err) {
431
+ const error = err instanceof Error ? err : new Error(String(err));
432
+ setState({ loading: false, commitmentData: void 0, error });
433
+ }
434
+ }, [client, saleUUID]);
435
+ (0, import_react2.useEffect)(() => {
436
+ refetch();
437
+ if (pollingIntervalMs === void 0) {
438
+ return;
439
+ }
440
+ const intervalId = setInterval(() => {
441
+ refetch();
442
+ }, pollingIntervalMs);
443
+ return () => {
444
+ clearInterval(intervalId);
445
+ };
446
+ }, [refetch, pollingIntervalMs]);
447
+ return state;
448
+ }
409
449
  // Annotate the CommonJS export names for ESM import in node:
410
450
  0 && (module.exports = {
411
451
  SonarProvider,
452
+ useCommitmentData,
412
453
  useEntityInvestmentHistory,
413
454
  useSonarAuth,
414
455
  useSonarClient,
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import React from 'react';
3
- import { SonarClient, EntityDetails, GeneratePurchasePermitResponse, PrePurchaseFailureReason, EntityID, MyProfileResponse, EntityInvestmentHistoryResponse } from '@echoxyz/sonar-core';
3
+ import { SonarClient, EntityDetails, GeneratePurchasePermitResponse, PrePurchaseFailureReason, EntityID, MyProfileResponse, EntityInvestmentHistoryResponse, ReadCommitmentDataResponse } from '@echoxyz/sonar-core';
4
4
 
5
5
  type SonarProviderProps = {
6
6
  children: React.ReactNode;
@@ -91,5 +91,17 @@ type UseEntityInvestmentHistoryResult = {
91
91
  error?: Error;
92
92
  };
93
93
  declare function useEntityInvestmentHistory(): UseEntityInvestmentHistoryResult;
94
+ type UseCommitmentDataResult = {
95
+ loading: boolean;
96
+ commitmentData?: ReadCommitmentDataResponse;
97
+ error?: Error;
98
+ };
99
+ /**
100
+ * Fetches commitment data for a sale and optionally polls for updates. Polling is disabled by default.
101
+ */
102
+ declare function useCommitmentData(args: {
103
+ saleUUID: string;
104
+ pollingIntervalMs?: number;
105
+ }): UseCommitmentDataResult;
94
106
 
95
- export { SonarProvider, type SonarProviderConfig, type UseEntityInvestmentHistoryResult, type UseSonarEntitiesResult, type UseSonarEntityResult, type UseSonarProfileResult, type UseSonarPurchaseResult, type UseSonarPurchaseResultError, type UseSonarPurchaseResultLoading, type UseSonarPurchaseResultNotReadyToPurchase, type UseSonarPurchaseResultReadyToPurchase, useEntityInvestmentHistory, useSonarAuth, useSonarClient, useSonarEntities, useSonarEntity, useSonarProfile, useSonarPurchase };
107
+ export { SonarProvider, type SonarProviderConfig, type UseCommitmentDataResult, type UseEntityInvestmentHistoryResult, type UseSonarEntitiesResult, type UseSonarEntityResult, type UseSonarProfileResult, type UseSonarPurchaseResult, type UseSonarPurchaseResultError, type UseSonarPurchaseResultLoading, type UseSonarPurchaseResultNotReadyToPurchase, type UseSonarPurchaseResultReadyToPurchase, useCommitmentData, useEntityInvestmentHistory, useSonarAuth, useSonarClient, useSonarEntities, useSonarEntity, useSonarProfile, useSonarPurchase };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import React from 'react';
3
- import { SonarClient, EntityDetails, GeneratePurchasePermitResponse, PrePurchaseFailureReason, EntityID, MyProfileResponse, EntityInvestmentHistoryResponse } from '@echoxyz/sonar-core';
3
+ import { SonarClient, EntityDetails, GeneratePurchasePermitResponse, PrePurchaseFailureReason, EntityID, MyProfileResponse, EntityInvestmentHistoryResponse, ReadCommitmentDataResponse } from '@echoxyz/sonar-core';
4
4
 
5
5
  type SonarProviderProps = {
6
6
  children: React.ReactNode;
@@ -91,5 +91,17 @@ type UseEntityInvestmentHistoryResult = {
91
91
  error?: Error;
92
92
  };
93
93
  declare function useEntityInvestmentHistory(): UseEntityInvestmentHistoryResult;
94
+ type UseCommitmentDataResult = {
95
+ loading: boolean;
96
+ commitmentData?: ReadCommitmentDataResponse;
97
+ error?: Error;
98
+ };
99
+ /**
100
+ * Fetches commitment data for a sale and optionally polls for updates. Polling is disabled by default.
101
+ */
102
+ declare function useCommitmentData(args: {
103
+ saleUUID: string;
104
+ pollingIntervalMs?: number;
105
+ }): UseCommitmentDataResult;
94
106
 
95
- export { SonarProvider, type SonarProviderConfig, type UseEntityInvestmentHistoryResult, type UseSonarEntitiesResult, type UseSonarEntityResult, type UseSonarProfileResult, type UseSonarPurchaseResult, type UseSonarPurchaseResultError, type UseSonarPurchaseResultLoading, type UseSonarPurchaseResultNotReadyToPurchase, type UseSonarPurchaseResultReadyToPurchase, useEntityInvestmentHistory, useSonarAuth, useSonarClient, useSonarEntities, useSonarEntity, useSonarProfile, useSonarPurchase };
107
+ export { SonarProvider, type SonarProviderConfig, type UseCommitmentDataResult, type UseEntityInvestmentHistoryResult, type UseSonarEntitiesResult, type UseSonarEntityResult, type UseSonarProfileResult, type UseSonarPurchaseResult, type UseSonarPurchaseResultError, type UseSonarPurchaseResultLoading, type UseSonarPurchaseResultNotReadyToPurchase, type UseSonarPurchaseResultReadyToPurchase, useCommitmentData, useEntityInvestmentHistory, useSonarAuth, useSonarClient, useSonarEntities, useSonarEntity, useSonarProfile, useSonarPurchase };
package/dist/index.js CHANGED
@@ -375,8 +375,48 @@ function useEntityInvestmentHistory() {
375
375
  error: state.error
376
376
  };
377
377
  }
378
+ var MIN_POLLING_INTERVAL_MS = 1e3;
379
+ function useCommitmentData(args) {
380
+ const saleUUID = args.saleUUID;
381
+ const pollingIntervalMs = args.pollingIntervalMs;
382
+ if (pollingIntervalMs !== void 0 && pollingIntervalMs < MIN_POLLING_INTERVAL_MS) {
383
+ throw new Error(`pollingIntervalMs must be at least ${MIN_POLLING_INTERVAL_MS}ms`);
384
+ }
385
+ const client = useSonarClient();
386
+ const [state, setState] = useState2({
387
+ loading: false
388
+ });
389
+ const refetch = useCallback2(async () => {
390
+ setState((s) => ({ ...s, loading: true }));
391
+ try {
392
+ const resp = await client.readCommitmentData({ saleUUID });
393
+ setState({
394
+ loading: false,
395
+ commitmentData: resp,
396
+ error: void 0
397
+ });
398
+ } catch (err) {
399
+ const error = err instanceof Error ? err : new Error(String(err));
400
+ setState({ loading: false, commitmentData: void 0, error });
401
+ }
402
+ }, [client, saleUUID]);
403
+ useEffect2(() => {
404
+ refetch();
405
+ if (pollingIntervalMs === void 0) {
406
+ return;
407
+ }
408
+ const intervalId = setInterval(() => {
409
+ refetch();
410
+ }, pollingIntervalMs);
411
+ return () => {
412
+ clearInterval(intervalId);
413
+ };
414
+ }, [refetch, pollingIntervalMs]);
415
+ return state;
416
+ }
378
417
  export {
379
418
  SonarProvider,
419
+ useCommitmentData,
380
420
  useEntityInvestmentHistory,
381
421
  useSonarAuth,
382
422
  useSonarClient,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@echoxyz/sonar-react",
3
- "version": "0.12.2",
3
+ "version": "0.13.1",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -16,7 +16,7 @@
16
16
  "react": ">=18"
17
17
  },
18
18
  "dependencies": {
19
- "@echoxyz/sonar-core": "0.13.0"
19
+ "@echoxyz/sonar-core": "0.14.1"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@testing-library/react": "^16.0.0",