@agg-build/hooks 4.27.3 → 4.28.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/index.mjs CHANGED
@@ -59,12 +59,51 @@ const parseAuthCallbackCode = (callbackUrl) => {
59
59
  const parseLinkConfirmToken = (callbackUrl) => {
60
60
  return resolveAuthCallbackUrl(callbackUrl)?.searchParams.get("link_confirm_token") ?? null;
61
61
  };
62
+ const AUTH_METHOD_IDS = [
63
+ "siwe",
64
+ "siws",
65
+ "google",
66
+ "twitter",
67
+ "apple",
68
+ "email"
69
+ ];
70
+ const EXISTING_METHOD_NAMES = {
71
+ email: "an email link",
72
+ google: "Google",
73
+ apple: "Apple"
74
+ };
75
+ var AggIdentityExistsError = class extends Error {
76
+ constructor(message, existingMethod, attemptedMethod) {
77
+ super(message);
78
+ this.existingMethod = existingMethod;
79
+ this.attemptedMethod = attemptedMethod;
80
+ this.code = "identity_exists";
81
+ this.name = "AggIdentityExistsError";
82
+ }
83
+ };
84
+ const IDENTITY_EXISTS_PARAMS = [
85
+ "error",
86
+ "message",
87
+ "existing_method",
88
+ "attempted_method"
89
+ ];
90
+ const parseAuthCallbackIdentityExists = (callbackUrl) => {
91
+ const params = resolveAuthCallbackUrl(callbackUrl)?.searchParams;
92
+ if (params?.get("error") !== "identity_exists") return null;
93
+ const existingMethod = params.get("existing_method");
94
+ if (existingMethod !== "email" && existingMethod !== "google" && existingMethod !== "apple") return null;
95
+ const attemptedMethod = AUTH_METHOD_IDS.find((id) => id === params.get("attempted_method"));
96
+ if (!attemptedMethod) return null;
97
+ const name = EXISTING_METHOD_NAMES[existingMethod];
98
+ return new AggIdentityExistsError(`You've signed in with ${name} before. Please continue with ${name}.`, existingMethod, attemptedMethod);
99
+ };
62
100
  const getAuthCallbackCleanupPath = (callbackUrl) => {
63
101
  const resolvedUrl = resolveAuthCallbackUrl(callbackUrl);
64
102
  if (!resolvedUrl) return null;
65
103
  const params = new URLSearchParams(resolvedUrl.search);
66
104
  params.delete("code");
67
105
  params.delete("link_confirm_token");
106
+ if (params.get("error") === "identity_exists") for (const name of IDENTITY_EXISTS_PARAMS) params.delete(name);
68
107
  const search = params.toString();
69
108
  return `${resolvedUrl.pathname}${search ? `?${search}` : ""}`;
70
109
  };
@@ -308,6 +347,11 @@ function AggAuthProvider({ children }) {
308
347
  setIsLoading(true);
309
348
  setError(null);
310
349
  try {
350
+ const identityError = parseAuthCallbackIdentityExists(callbackUrl);
351
+ if (identityError) {
352
+ if (callbackUrl === void 0) replaceAuthCallbackUrl(getAuthCallbackCleanupPath(callbackUrl));
353
+ throw identityError;
354
+ }
311
355
  const exchangedSession = await exchangeAuthCallbackCode(client, callbackUrl);
312
356
  if (exchangedSession) {
313
357
  const resolvedUser = await refreshCurrentUser(client);
@@ -2761,9 +2805,9 @@ function useLinkAccount() {
2761
2805
  //#endregion
2762
2806
  //#region src/auth-chooser-events.ts
2763
2807
  const AUTH_CHOOSER_OPEN_EVENT = "agg-auth:open-chooser";
2764
- const requestAggAuthChooserOpen = () => {
2808
+ const requestAggAuthChooserOpen = (detail = {}) => {
2765
2809
  if (typeof window === "undefined") return;
2766
- window.dispatchEvent(new Event(AUTH_CHOOSER_OPEN_EVENT));
2810
+ window.dispatchEvent(new CustomEvent(AUTH_CHOOSER_OPEN_EVENT, { detail }));
2767
2811
  };
2768
2812
  //#endregion
2769
2813
  //#region src/use-categories.ts
@@ -5366,7 +5410,6 @@ function useMarketSearch(options) {
5366
5410
  status,
5367
5411
  limit,
5368
5412
  enabled: enableSuggestions && trimmedDebounced.length >= minLength,
5369
- deep: false,
5370
5413
  mode: "instant"
5371
5414
  });
5372
5415
  const submittedQ = submittedQuery?.trim() ?? "";
@@ -5376,8 +5419,7 @@ function useMarketSearch(options) {
5376
5419
  categoryIds,
5377
5420
  status,
5378
5421
  limit,
5379
- enabled: submittedQ.length > 0,
5380
- deep: true
5422
+ enabled: submittedQ.length > 0
5381
5423
  });
5382
5424
  return {
5383
5425
  /** Current input value (controlled). */
@@ -5388,7 +5430,7 @@ function useMarketSearch(options) {
5388
5430
  }, []),
5389
5431
  /** The query value that produced the current `results`, or null if none. */
5390
5432
  submittedQuery,
5391
- /** Fire a deep search. Use this on Enter / Search button. */
5433
+ /** Fire a full-page search. Use this on Enter / Search button. */
5392
5434
  submit: useCallback((q) => {
5393
5435
  const target = (q ?? query).trim();
5394
5436
  if (target.length === 0) return;
@@ -5861,6 +5903,7 @@ const RESOLVING_POLL_INTERVAL_MS = 15e3;
5861
5903
  const FALLBACK_VENUE_EVENT_PAGE_LIMIT = 100;
5862
5904
  const FALLBACK_VENUE_EVENT_MAX_PAGES = 5;
5863
5905
  const FALLBACK_TARGET_WINDOW_COUNT = 5;
5906
+ const TIMELINE_FUTURE_WINDOWS = 4;
5864
5907
  const RECURRING_MARKET_STATUSES = [
5865
5908
  MarketStatus$1.open,
5866
5909
  MarketStatus$1.closed,
@@ -6205,6 +6248,10 @@ const fetchRecurringCryptoMarkets = async (client, event, signal, now = Date.now
6205
6248
  const { asset, duration, windowStart: anchorStart } = identity;
6206
6249
  const queryAssets = event.aggKey?.match(RECURRING_CRYPTO_DAILY_AGG_KEY_PATTERN) ? void 0 : asset ? [asset] : void 0;
6207
6250
  const canonicalAggKeyWindowsPromise = fetchCanonicalAggKeyWindows(client, event, identity, signal, now).catch(() => []);
6251
+ const durationMs = RECURRING_DURATION_MS[duration];
6252
+ const timelineStart = now - durationMs * 2;
6253
+ const timelineEnd = now + durationMs * TIMELINE_FUTURE_WINDOWS;
6254
+ const anchorInTimeline = anchorStart != null && anchorStart >= timelineStart && anchorStart <= timelineEnd;
6208
6255
  const anchorOptions = anchorStart == null ? {
6209
6256
  assets: queryAssets,
6210
6257
  durations: [duration],
@@ -6215,8 +6262,8 @@ const fetchRecurringCryptoMarkets = async (client, event, signal, now = Date.now
6215
6262
  assets: queryAssets,
6216
6263
  durations: [duration],
6217
6264
  venues: [event.venue],
6218
- windowStartFrom: (/* @__PURE__ */ new Date(anchorStart - 1e3)).toISOString(),
6219
- windowStartTo: new Date(anchorStart + 1e3).toISOString(),
6265
+ windowStartFrom: new Date(anchorInTimeline ? timelineStart : anchorStart - 1e3).toISOString(),
6266
+ windowStartTo: new Date(anchorInTimeline ? timelineEnd : anchorStart + 1e3).toISOString(),
6220
6267
  includeDirectVenueMarkets: duration === "P1D"
6221
6268
  };
6222
6269
  let anchorResponse = await fetchRecurringCryptoPage(client, anchorOptions, signal);
@@ -6244,25 +6291,27 @@ const fetchRecurringCryptoMarkets = async (client, event, signal, now = Date.now
6244
6291
  }
6245
6292
  }
6246
6293
  if (!anchor) return fetchFallbackVenueEventWindows(client, event, identity, signal, now);
6247
- const timelineStart = now - RECURRING_DURATION_MS[duration] * 2;
6248
6294
  const windows = [anchor, ...anchorResponse.data.filter((windowMarket) => windowMarket.asset === anchor.asset && windowMarket.duration === duration)];
6249
- const seenCursors = /* @__PURE__ */ new Set();
6250
- let cursor;
6251
- do {
6252
- const response = await fetchRecurringCryptoPage(client, {
6253
- assets: [anchor.asset],
6254
- durations: [duration],
6255
- venues: timelineVenues,
6256
- windowStartFrom: new Date(timelineStart).toISOString(),
6257
- includeDirectVenueMarkets: duration === "P1D",
6258
- cursor
6259
- }, signal);
6260
- windows.push(...response.data);
6261
- const nextCursor = response.hasMore ? response.nextCursor ?? void 0 : void 0;
6262
- if (!nextCursor || seenCursors.has(nextCursor)) break;
6263
- seenCursors.add(nextCursor);
6264
- cursor = nextCursor;
6265
- } while (cursor);
6295
+ if (!anchorInTimeline || anchorResponse.hasMore) {
6296
+ const seenCursors = /* @__PURE__ */ new Set();
6297
+ let cursor;
6298
+ do {
6299
+ const response = await fetchRecurringCryptoPage(client, {
6300
+ assets: [anchor.asset],
6301
+ durations: [duration],
6302
+ venues: timelineVenues,
6303
+ windowStartFrom: new Date(timelineStart).toISOString(),
6304
+ windowStartTo: new Date(timelineEnd).toISOString(),
6305
+ includeDirectVenueMarkets: duration === "P1D",
6306
+ cursor
6307
+ }, signal);
6308
+ windows.push(...response.data);
6309
+ const nextCursor = response.hasMore ? response.nextCursor ?? void 0 : void 0;
6310
+ if (!nextCursor || seenCursors.has(nextCursor)) break;
6311
+ seenCursors.add(nextCursor);
6312
+ cursor = nextCursor;
6313
+ } while (cursor);
6314
+ }
6266
6315
  windows.push(...canonicalAggKeyWindows ?? await canonicalAggKeyWindowsPromise);
6267
6316
  return mergeRecurringCryptoWindows(windows);
6268
6317
  };
@@ -7320,6 +7369,6 @@ function useHostedVenueTransfers(accountId, environment) {
7320
7369
  };
7321
7370
  }
7322
7371
  //#endregion
7323
- export { AUTH_CHOOSER_OPEN_EVENT, AggBalanceProvider, AggProvider, AggProvider as AggSdkProvider, AggUiProvider, CHART_TIME_RANGES, CONFIRMED_MATCH_STATUSES, DEFAULT_AGG_ROOT_CLASS_NAME, EventListStateProvider, LEADERBOARD_PERIODS, MAX_ORDER_VENUE_MARKET_IDS_PER_REQUEST, MAX_PRICE_GAP_PCT, MIN_PRICE_GAP_PCT, MarketStatus, MatchStatus, MatchType, QueryClient, QueryClientProvider, RedeemRejectedError, SPORTS_LIVE_POLL_INTERVAL_MS, SPORTS_SCHEDULED_POLL_INTERVAL_MS, TradeSide, TurnstileChallengeError, Venue, appConfigQueryKey, buildLiveBestPriceCandidates, computeClosedPositionTotals, computePriceGaps, defaultAggUiConfig, defaultAggUiConfig as defaultSdkUiConfig, executionKeys, extractOutcomeBestCandidate, fetchRecurringCryptoMarkets, findLivePriceById, getBuilder, getDepositAddress, getOrCreateBuilder, getVenueAvailabilityState, getVisibleVenueIdsByConfig, getVisibleVenuesByConfig, getWalletAddressFromUserProfile, hostedVenueAccountQueryKeys, invalidateBalanceQueries, invalidatePositionQueries, invalidateUserActivityQueries, invalidateUserClaimState, invalidateUserMoneyState, isVenueDisabledByConfig, leaderboardQueryKeys, leaderboardRange, mergeBestPricesPreferringLive, mergeRecurringCryptoWindows, normalizeVenueId, optimizedImageUrl, parseEmail, parseEmailStrict, rangeToSeconds, recurringCryptoTransitionPollInterval, requestAggAuthChooserOpen, resolveAggUiLabels, resolveDefaultMarket as resolveDefaultTradingMarket, resolveEventTradingState, resolveLimitOrderSizeRulesByVenue, resolveMarketTradingState, resolveMarketWinningOutcome, resolveOrderEligibility, resolveRecurringCryptoIdentity, resolveRecurringCryptoTimeline, resolveRollingWindow, resolveTradingStateKind, retinaImageUrl, sharedKycQueryKeys, sortVenues, sportsLiveQueryKey, sportsLiveRefetchInterval, timeRangeToInterval, tradingReducer, useAggAuth, useAggAuthContext, useAggAuthState, useAggBalance, useAggBalanceContext, useAggBalanceState, useAggClient, useAggLabels, useAggUiConfig, useAggWebSocket, useAppConfig, useArbFeed, useBalanceRefillPolicies, useCachedAppConfig, useCancelManagedOrder, useCategories, useCategoryChildren, useDebouncedValue, useDepositAddresses, useEnrichedVenueEvent, useEventListState, useEventOrderbookData, useEventTradingContext, useExecuteManaged, useExecutionOrders, useExecutionOrdersForMarkets, useExecutionPositions, useExecutionProgress, useExternalId, useGeoBlock, useHostedVenueAccount, useHostedVenueActivity, useHostedVenueTransfers, useLabels, useLeaderboard, useLimitOrderVenueQuotes, useLinkAccount, useLiveBestPriceCandidates, useLiveBestPrices, useLiveCandleOverlay, useLiveCandles, useLiveMarket, useLiveMarketStores, useLiveOutcomePrices, useLiveTrades, useManagedBalances, useMarketArb, useMarketChart, useMarketCharts, useMarketOrderbook, useMarketSearch, useMidpoints, useOnBalanceUpdate, useOnOrderEvent, useOnOrderSubmitted, useOnRedeemEvent, useOnWithdrawalLifecycle, useOptionalAggClient, useOrderBook, useOrderbookQuote, useOrders, usePaperOnboarding, usePlaceLimitOrder, usePositions, useQueryClient, useRampQuotes, useRampSession, useRecurringCryptoMarkets, useRedeem, useRedeemEligibleCount, useRedeemLifecycle, useRedeemLifecycles, useResolvedExecutionMode, useRollingChartWindow, useSdkLabels, useSdkUiConfig, useSearch, useSettlementDetailsData, useSharedKyc, useSmartRoute, useSportsLive, useSyncBalances, useUserActivity, useUserHoldings, useVenueEvent, useVenueEvents, useVenueKeyStatus, useVenueMarketMidpoints, useVenueMarkets, useVenueSellQuotes, useViewportMidpoints, useVisibleIds, useWithdrawEstimate, useWithdrawFlow, useWithdrawManaged, useWithdrawPreview, useWithdrawalLifecycle, userActivityQueryKeys, venueKeyQueryKeys };
7372
+ export { AUTH_CHOOSER_OPEN_EVENT, AggBalanceProvider, AggIdentityExistsError, AggProvider, AggProvider as AggSdkProvider, AggUiProvider, CHART_TIME_RANGES, CONFIRMED_MATCH_STATUSES, DEFAULT_AGG_ROOT_CLASS_NAME, EventListStateProvider, LEADERBOARD_PERIODS, MAX_ORDER_VENUE_MARKET_IDS_PER_REQUEST, MAX_PRICE_GAP_PCT, MIN_PRICE_GAP_PCT, MarketStatus, MatchStatus, MatchType, QueryClient, QueryClientProvider, RedeemRejectedError, SPORTS_LIVE_POLL_INTERVAL_MS, SPORTS_SCHEDULED_POLL_INTERVAL_MS, TradeSide, TurnstileChallengeError, Venue, appConfigQueryKey, buildLiveBestPriceCandidates, computeClosedPositionTotals, computePriceGaps, defaultAggUiConfig, defaultAggUiConfig as defaultSdkUiConfig, executionKeys, extractOutcomeBestCandidate, fetchRecurringCryptoMarkets, findLivePriceById, getBuilder, getDepositAddress, getOrCreateBuilder, getVenueAvailabilityState, getVisibleVenueIdsByConfig, getVisibleVenuesByConfig, getWalletAddressFromUserProfile, hostedVenueAccountQueryKeys, invalidateBalanceQueries, invalidatePositionQueries, invalidateUserActivityQueries, invalidateUserClaimState, invalidateUserMoneyState, isVenueDisabledByConfig, leaderboardQueryKeys, leaderboardRange, mergeBestPricesPreferringLive, mergeRecurringCryptoWindows, normalizeVenueId, optimizedImageUrl, parseAuthCallbackIdentityExists, parseEmail, parseEmailStrict, rangeToSeconds, recurringCryptoTransitionPollInterval, requestAggAuthChooserOpen, resolveAggUiLabels, resolveDefaultMarket as resolveDefaultTradingMarket, resolveEventTradingState, resolveLimitOrderSizeRulesByVenue, resolveMarketTradingState, resolveMarketWinningOutcome, resolveOrderEligibility, resolveRecurringCryptoIdentity, resolveRecurringCryptoTimeline, resolveRollingWindow, resolveTradingStateKind, retinaImageUrl, sharedKycQueryKeys, sortVenues, sportsLiveQueryKey, sportsLiveRefetchInterval, timeRangeToInterval, tradingReducer, useAggAuth, useAggAuthContext, useAggAuthState, useAggBalance, useAggBalanceContext, useAggBalanceState, useAggClient, useAggLabels, useAggUiConfig, useAggWebSocket, useAppConfig, useArbFeed, useBalanceRefillPolicies, useCachedAppConfig, useCancelManagedOrder, useCategories, useCategoryChildren, useDebouncedValue, useDepositAddresses, useEnrichedVenueEvent, useEventListState, useEventOrderbookData, useEventTradingContext, useExecuteManaged, useExecutionOrders, useExecutionOrdersForMarkets, useExecutionPositions, useExecutionProgress, useExternalId, useGeoBlock, useHostedVenueAccount, useHostedVenueActivity, useHostedVenueTransfers, useLabels, useLeaderboard, useLimitOrderVenueQuotes, useLinkAccount, useLiveBestPriceCandidates, useLiveBestPrices, useLiveCandleOverlay, useLiveCandles, useLiveMarket, useLiveMarketStores, useLiveOutcomePrices, useLiveTrades, useManagedBalances, useMarketArb, useMarketChart, useMarketCharts, useMarketOrderbook, useMarketSearch, useMidpoints, useOnBalanceUpdate, useOnOrderEvent, useOnOrderSubmitted, useOnRedeemEvent, useOnWithdrawalLifecycle, useOptionalAggClient, useOrderBook, useOrderbookQuote, useOrders, usePaperOnboarding, usePlaceLimitOrder, usePositions, useQueryClient, useRampQuotes, useRampSession, useRecurringCryptoMarkets, useRedeem, useRedeemEligibleCount, useRedeemLifecycle, useRedeemLifecycles, useResolvedExecutionMode, useRollingChartWindow, useSdkLabels, useSdkUiConfig, useSearch, useSettlementDetailsData, useSharedKyc, useSmartRoute, useSportsLive, useSyncBalances, useUserActivity, useUserHoldings, useVenueEvent, useVenueEvents, useVenueKeyStatus, useVenueMarketMidpoints, useVenueMarkets, useVenueSellQuotes, useViewportMidpoints, useVisibleIds, useWithdrawEstimate, useWithdrawFlow, useWithdrawManaged, useWithdrawPreview, useWithdrawalLifecycle, userActivityQueryKeys, venueKeyQueryKeys };
7324
7373
 
7325
7374
  //# sourceMappingURL=index.mjs.map