@usearete/react 0.50.0 → 0.51.0
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.cjs +51 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +39 -6
- package/dist/index.esm.js +48 -4
- package/dist/index.esm.js.map +1 -1
- package/dist/testing.d.ts +10 -0
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
|
-
import { StackDefinition, WalletAdapter, ConnectOptions, AuthConfig, AreteError, Schema, ProgramSdkDefinition, ConnectionState, ConnectedArete, StackWithAttachedPrograms, Session, SessionDefinition, CompositionSessionOptions, SessionOptions, PreparedOperation, TransactionFailureOutcome, OperationExecutionEvent, OperationExecutionSuccessEvent, OperationTransactionReceipt, TransactionOutcome, ProgramInterface, TypedInstruction, OperationReceiptFor, StorageAdapter, StorageAdapterConfig, UpdateCallback, RichUpdateCallback, Update, RichUpdate, ViewSortConfig, QueriesInterface, ChainClient, StackConnectedExtensions, SocketIssue, StackQueryDefinition, ViewGroup, ViewDef, OperationExecutionOptions, SendOptions, ProgramError, PlatformHttpClient, ContextSlotOptions, NativeBalanceInfo, TokenBalanceInput, TokenBalanceInfo, ProtocolTypeMap, ProtocolClient, ProtocolKeyClass, ProtocolInstanceDetail, ProtocolStepAvailabilityFor, ProtocolWalletActions, ProtocolParticipantDetail, ProtocolStreamEvent, WaitForProcessedSlotOptions } from '@usearete/sdk';
|
|
3
|
-
export { AccountCategory, AccountMeta, AccountResolutionOptions, AccountResolutionResult, Arete, AreteError, AreteOptions, AreteOptionsWithStorage, ArgSchema, ArgType, AuthConfig, AuthTokenRequest, BuildOptions, BuiltAccountMeta, BuiltInstruction, ConfirmationLevel, ConnectOptions, ConnectedArete, ConnectionManager, ConnectionState, ContextSlotOptions, DEFAULT_CONFIG, DEFAULT_MAX_ENTRIES_PER_VIEW, DefaultViewKey, EntityFrame, ErrorFrame, ErrorMetadata, ExecuteOptions, ExecutionResult, Frame, FrameMode, FrameOp, FrameProcessor, FrameProcessorConfig, FrameValidationDiagnostic, InstructionError, InstructionExecutor, InstructionHandler, InstructionHandlerConfig, MemoryAdapter, MergeProgramMaps, NativeBalanceInfo, OperationCallbackError, OperationExecutionError, OperationExecutionOptions, OperationReceiptFor, OperationTransactionReceipt, PdaConfig, PdaSeed, PlatformHttpClient, PlatformHttpRequest, PlatformHttpResponse, PreparedFlow, PreparedInstruction, PreparedOperation, PreparedTransaction, PreparedTransactionInstruction, ProcessedSlotTimeoutError, ProgramError, QueryLease, QuerySnapshot, QueryStore, ReadRequestError, ResolvedAccount, ResolvedAccounts, RichUpdate, RichUpdateCallback, Schema, SendOptions, SendResult, Session, SessionDefinition, SessionOptions, SnapshotEntity, SnapshotFrame, SocketIssue, StackDefinition, StackWithAttachedPrograms, StorageAdapter, StorageAdapterConfig, StringifiedBigints, SubscribedFrame, Subscription, SubscriptionQuery, SubscriptionRegistry, SubscriptionRequest, SubscriptionSnapshotOptions, TokenBalanceInfo, TokenBalanceInput, TransactionExecutionError, TransactionFailureOutcome, TransactionOptions, TransactionOutcome, TypedInstruction, UnsubscribedFrame, Update, UpdateCallback, ViewDef, ViewGroup, ViewKeyValue, WaitForProcessedSlotOptions, WalletAdapter, WalletConnectOptions, WalletState, buildInstruction, canonicalQueryKey, createInstructionExecutor, createInstructionHandler, createPlatformHttpClient, createPublicKeySeed, createSeed, derivePda, executeInstruction, formatProgramError, formatRawToUi, getTransactionFailureOutcome, isErrorFrame, isHostedAreteEndpoint, isSnapshotFrame, isSubscribedFrame, isUnsubscribedFrame, isValidFrame, normalizeSubscriptionQuery, parseFrame, parseFrameFromBlob, parseInstructionError, resolveAccounts, safeToRawAmount, serializeInstructionData, serializeViewKey, stringifyBigints, toRawAmount, unwrapOperationExecutionError, validateAccountResolution, withPrograms } from '@usearete/sdk';
|
|
2
|
+
import { StackDefinition, WalletAdapter, ConnectOptions, AuthConfig, AreteError, Schema, ProgramSdkDefinition, ConnectionState, ConnectedArete, StackWithAttachedPrograms, ClientEnvironment, Session, SessionDefinition, CompositionSessionOptions, SessionOptions, PreparedOperation, TransactionFailureOutcome, OperationExecutionEvent, OperationExecutionSuccessEvent, OperationTransactionReceipt, TransactionOutcome, ProgramInterface, TypedInstruction, OperationReceiptFor, StorageAdapter, StorageAdapterConfig, UpdateCallback, RichUpdateCallback, Update, RichUpdate, ViewSortConfig, QueriesInterface, ChainClient, StackConnectedExtensions, SocketIssue, StackQueryDefinition, ViewGroup, ViewDef, OperationExecutionOptions, SendOptions, ProgramError, PlatformHttpClient, ContextSlotOptions, NativeBalanceInfo, TokenBalanceInput, TokenBalanceInfo, ProtocolTypeMap, ProtocolClient, ProtocolKeyClass, ProtocolInstanceDetail, ProtocolStepAvailabilityFor, ProtocolWalletActions, ProtocolParticipantDetail, ProtocolStreamEvent, WaitForProcessedSlotOptions } from '@usearete/sdk';
|
|
3
|
+
export { AccountCategory, AccountMeta, AccountResolutionOptions, AccountResolutionResult, Arete, AreteError, AreteOptions, AreteOptionsWithStorage, ArgSchema, ArgType, AuthConfig, AuthTokenRequest, BuildOptions, BuiltAccountMeta, BuiltInstruction, ClientEnvironment, ConfirmationLevel, ConnectOptions, ConnectedArete, ConnectionManager, ConnectionState, ContextSlotOptions, DEFAULT_CONFIG, DEFAULT_MAX_ENTRIES_PER_VIEW, DefaultViewKey, DevEnvironmentError, EntityFrame, EnvironmentOption, ErrorFrame, ErrorMetadata, ExecuteOptions, ExecutionResult, Frame, FrameMode, FrameOp, FrameProcessor, FrameProcessorConfig, FrameValidationDiagnostic, InstructionError, InstructionExecutor, InstructionHandler, InstructionHandlerConfig, MemoryAdapter, MergeProgramMaps, NativeBalanceInfo, OperationCallbackError, OperationExecutionError, OperationExecutionOptions, OperationReceiptFor, OperationTransactionReceipt, PdaConfig, PdaSeed, PlatformHttpClient, PlatformHttpRequest, PlatformHttpResponse, PreparedFlow, PreparedInstruction, PreparedOperation, PreparedTransaction, PreparedTransactionInstruction, ProcessedSlotTimeoutError, ProgramError, QueryLease, QuerySnapshot, QueryStore, ReadRequestError, ResolvedAccount, ResolvedAccounts, RichUpdate, RichUpdateCallback, Schema, SendOptions, SendResult, Session, SessionDefinition, SessionOptions, SnapshotEntity, SnapshotFrame, SocketIssue, StackDefinition, StackWithAttachedPrograms, StorageAdapter, StorageAdapterConfig, StringifiedBigints, SubscribedFrame, Subscription, SubscriptionQuery, SubscriptionRegistry, SubscriptionRequest, SubscriptionSnapshotOptions, TokenBalanceInfo, TokenBalanceInput, TransactionExecutionError, TransactionFailureOutcome, TransactionOptions, TransactionOutcome, TypedInstruction, UnsubscribedFrame, Update, UpdateCallback, ViewDef, ViewGroup, ViewKeyValue, WaitForProcessedSlotOptions, WalletAdapter, WalletConnectOptions, WalletState, buildInstruction, canonicalQueryKey, createInstructionExecutor, createInstructionHandler, createPlatformHttpClient, createPublicKeySeed, createSeed, derivePda, executeInstruction, formatProgramError, formatRawToUi, getTransactionFailureOutcome, isErrorFrame, isHostedAreteEndpoint, isSnapshotFrame, isSubscribedFrame, isUnsubscribedFrame, isValidFrame, normalizeSubscriptionQuery, parseFrame, parseFrameFromBlob, parseInstructionError, resolveAccounts, safeToRawAmount, serializeInstructionData, serializeViewKey, stringifyBigints, toRawAmount, unwrapOperationExecutionError, validateAccountResolution, withPrograms } from '@usearete/sdk';
|
|
4
4
|
import { UseBoundStore, StoreApi } from 'zustand';
|
|
5
5
|
|
|
6
6
|
type ViewMode = 'state' | 'list';
|
|
@@ -72,6 +72,16 @@ interface AreteConfig {
|
|
|
72
72
|
* applies to clients created afterwards; call `retry()` to reconnect one.
|
|
73
73
|
*/
|
|
74
74
|
auth?: AuthConfig;
|
|
75
|
+
/**
|
|
76
|
+
* Production (the default) or the project's dev environment. A browser
|
|
77
|
+
* reads no process variable, so pass it from the framework's public
|
|
78
|
+
* variables, for example
|
|
79
|
+
* `environment={import.meta.env.VITE_ARETE_ENVIRONMENT === 'dev' ? { kind: 'dev', url: import.meta.env.VITE_ARETE_DEV_URL } : 'production'}`.
|
|
80
|
+
* In dev mode every client the provider creates goes through the edge
|
|
81
|
+
* `a4 dev up` serves; the page holds no Arete key. Applies to clients
|
|
82
|
+
* created afterwards, like `auth`.
|
|
83
|
+
*/
|
|
84
|
+
environment?: ConnectOptions['environment'];
|
|
75
85
|
}
|
|
76
86
|
/**
|
|
77
87
|
* Client lookup/connect options for React hooks.
|
|
@@ -252,6 +262,29 @@ declare function AreteProvider({ children, ...config }: AreteConfig & {
|
|
|
252
262
|
declare function useAreteContext(): AreteContextValue;
|
|
253
263
|
declare function useConnectionState(stack?: StackDefinition, options?: ClientLookupOptions): ConnectionState;
|
|
254
264
|
|
|
265
|
+
/**
|
|
266
|
+
* The world the enclosing `AreteProvider`'s clients talk to: `'dev'` for
|
|
267
|
+
* the project's dev environment, `'production'` otherwise. With a stack,
|
|
268
|
+
* the connected client's own `client.environment`; before it connects (or
|
|
269
|
+
* without a stack), what the provider's `environment` decides. Outside a
|
|
270
|
+
* provider, `'production'`.
|
|
271
|
+
*/
|
|
272
|
+
declare function useAreteEnvironment(stack?: StackDefinition, options?: ClientLookupOptions): ClientEnvironment;
|
|
273
|
+
interface AreteEnvironmentBadgeProps {
|
|
274
|
+
/** Text shown in dev mode. Defaults to `Dev environment`. */
|
|
275
|
+
label?: React.ReactNode;
|
|
276
|
+
className?: string;
|
|
277
|
+
style?: React.CSSProperties;
|
|
278
|
+
/** Report this stack's client (see {@link useAreteEnvironment}). */
|
|
279
|
+
stack?: StackDefinition;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* A small badge that says the app is talking to the dev environment.
|
|
283
|
+
* Renders nothing in production, so it can stay in the app's status or
|
|
284
|
+
* diagnostics area. Carries `data-arete-environment="dev"` for styling.
|
|
285
|
+
*/
|
|
286
|
+
declare function AreteEnvironmentBadge({ label, className, style, stack, }: AreteEnvironmentBadgeProps): React.ReactElement | null;
|
|
287
|
+
|
|
255
288
|
/** Any session from `createSession`. */
|
|
256
289
|
type AnySession = Session<any, any, any>;
|
|
257
290
|
/**
|
|
@@ -304,8 +337,8 @@ interface OwnedAreteSessionProviderProps<TDef extends SessionDefinition> extends
|
|
|
304
337
|
/** What to open, as for `createSession(definition, options)`. */
|
|
305
338
|
definition: TDef;
|
|
306
339
|
/**
|
|
307
|
-
* `createSession` options. `auth` and `
|
|
308
|
-
* `AreteProvider`'s. A change reopens the session (see the README).
|
|
340
|
+
* `createSession` options. `auth`, `fetch` and `environment` default to
|
|
341
|
+
* the enclosing `AreteProvider`'s. A change reopens the session (see the README).
|
|
309
342
|
*/
|
|
310
343
|
options?: AreteSessionOptions<TDef>;
|
|
311
344
|
session?: never;
|
|
@@ -1162,5 +1195,5 @@ interface DefaultReconciliationFn {
|
|
|
1162
1195
|
*/
|
|
1163
1196
|
declare function createProcessedSlotReconciliation(client: ProcessedSlotClient | null | undefined, baseOverrides?: MutationReconcileOverrides): DefaultReconciliationFn;
|
|
1164
1197
|
|
|
1165
|
-
export { AreteProvider, AreteSessionProvider, AreteSessionUnavailableError, DEFAULT_RECONCILIATION_TIMEOUT_MS, OperationMutationError, ZustandAdapter, createAreteReact, createProcessedSlotReconciliation, isAreteSessionUnavailableError, isWalletRejection, reconcileProcessedSlot, summarizeStatuses, summarizeViews, toOperationMutationError, useAllowedSteps, useArete, useAreteContext, useAreteSession, useAsyncRead, useConnectionState, useInstructionMutation, useNativeBalance, useOperationMutation, usePlatformHttpClient, useProtocolEvents, useProtocolInstance, useProtocolParticipant, useReconcileProcessedSlot, useTokenBalance, useWalletActions };
|
|
1166
|
-
export type { AnyProtocolClient, AnySession, AnyStackClient, AreteConfig, AreteDefaultStackRegistry, AreteSessionOptions, AreteSessionProviderProps, AreteSessionStatus, AreteStore, AsyncReadContext, AsyncReadKey, AsyncReadStatus, BalanceHookOptions, BoundAreteProviderProps, ClientLookupOptions, DefaultReconciliationFn, ExternalAreteSessionProviderProps, ListOneViewHookOptions, ListParams, ListParamsBase, ListParamsMultiple, ListParamsSingle, ListViewHook, ListViewHookOptions, MemberStackDefinition, MutationExecutionObserver, MutationExecutor, MutationLifecycleEvent, MutationPhase, MutationReconcileFn, MutationReconcileOverrides, MutationReconciliationContext, MutationStatus, OperationExecutor, OperationExecutorSource, OperationMutationErrorKind, OperationMutationStatus, OperationPrepareFn, OperationRunOptions, OwnedAreteSessionProviderProps, PreparedOperationWithSigners, ProcessedSlotClient, ProcessedSlotReconciliationOptions, ProcessedSlotReconciliationResult, ReactReadInterface, ReadHookInterface, ReadHookOptions, ReconciliationRefresh, ReconciliationRefreshTarget, SessionOf, StackOfClient, StateViewHook, StateViewHookOptions, StatusSource, SummarizedStatus, SummarizedViewStatus, TransactionDefinition, UseAreteMemberOptions, UseAreteMemberPlaceholderOptions, UseAreteOptions, UseAreteResult, UseAreteSessionResult, UseAsyncReadOptions, UseAsyncReadResult, UseMutationOptions, UseMutationResult, UseMutationReturn, UseOperationMutationOptions, UseOperationMutationResult, UsePlatformHttpClientOptions, UseProtocolEventsOptions, UseProtocolInstanceOptions, UseProtocolInstanceResult, UseProtocolStepsOptions, UseWalletActionsInput, ViewHookOptions, ViewHookResult, ViewMode, ViewSchemaValidationDiagnostic, ViewSchemaValidationErrorCallback, ViewStatus, ViewStatusSource };
|
|
1198
|
+
export { AreteEnvironmentBadge, AreteProvider, AreteSessionProvider, AreteSessionUnavailableError, DEFAULT_RECONCILIATION_TIMEOUT_MS, OperationMutationError, ZustandAdapter, createAreteReact, createProcessedSlotReconciliation, isAreteSessionUnavailableError, isWalletRejection, reconcileProcessedSlot, summarizeStatuses, summarizeViews, toOperationMutationError, useAllowedSteps, useArete, useAreteContext, useAreteEnvironment, useAreteSession, useAsyncRead, useConnectionState, useInstructionMutation, useNativeBalance, useOperationMutation, usePlatformHttpClient, useProtocolEvents, useProtocolInstance, useProtocolParticipant, useReconcileProcessedSlot, useTokenBalance, useWalletActions };
|
|
1199
|
+
export type { AnyProtocolClient, AnySession, AnyStackClient, AreteConfig, AreteDefaultStackRegistry, AreteEnvironmentBadgeProps, AreteSessionOptions, AreteSessionProviderProps, AreteSessionStatus, AreteStore, AsyncReadContext, AsyncReadKey, AsyncReadStatus, BalanceHookOptions, BoundAreteProviderProps, ClientLookupOptions, DefaultReconciliationFn, ExternalAreteSessionProviderProps, ListOneViewHookOptions, ListParams, ListParamsBase, ListParamsMultiple, ListParamsSingle, ListViewHook, ListViewHookOptions, MemberStackDefinition, MutationExecutionObserver, MutationExecutor, MutationLifecycleEvent, MutationPhase, MutationReconcileFn, MutationReconcileOverrides, MutationReconciliationContext, MutationStatus, OperationExecutor, OperationExecutorSource, OperationMutationErrorKind, OperationMutationStatus, OperationPrepareFn, OperationRunOptions, OwnedAreteSessionProviderProps, PreparedOperationWithSigners, ProcessedSlotClient, ProcessedSlotReconciliationOptions, ProcessedSlotReconciliationResult, ReactReadInterface, ReadHookInterface, ReadHookOptions, ReconciliationRefresh, ReconciliationRefreshTarget, SessionOf, StackOfClient, StateViewHook, StateViewHookOptions, StatusSource, SummarizedStatus, SummarizedViewStatus, TransactionDefinition, UseAreteMemberOptions, UseAreteMemberPlaceholderOptions, UseAreteOptions, UseAreteResult, UseAreteSessionResult, UseAsyncReadOptions, UseAsyncReadResult, UseMutationOptions, UseMutationResult, UseMutationReturn, UseOperationMutationOptions, UseOperationMutationResult, UsePlatformHttpClientOptions, UseProtocolEventsOptions, UseProtocolInstanceOptions, UseProtocolInstanceResult, UseProtocolStepsOptions, UseWalletActionsInput, ViewHookOptions, ViewHookResult, ViewMode, ViewSchemaValidationDiagnostic, ViewSchemaValidationErrorCallback, ViewStatus, ViewStatusSource };
|
package/dist/index.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { createContext, useRef, useCallback, useEffect, useContext, useState, useMemo, useSyncExternalStore } from 'react';
|
|
2
|
-
import { Arete, createSession, getTransactionFailureOutcome, OperationExecutionError, unwrapOperationExecutionError, InstructionError, compareProgramIdentity, serializeViewKey, canonicalQueryKey, AreteError, getStackRuntimeExtensions, createPlatformHttpClient } from '@usearete/sdk';
|
|
3
|
-
export { Arete, AreteError, ConnectionManager, DEFAULT_CONFIG, DEFAULT_MAX_ENTRIES_PER_VIEW, FrameProcessor, InstructionError, MemoryAdapter, OperationCallbackError, OperationExecutionError, ProcessedSlotTimeoutError, QueryStore, ReadRequestError, SubscriptionRegistry, TransactionExecutionError, buildInstruction, canonicalQueryKey, createInstructionExecutor, createInstructionHandler, createPlatformHttpClient, createPublicKeySeed, createSeed, derivePda, executeInstruction, formatProgramError, formatRawToUi, getTransactionFailureOutcome, isErrorFrame, isHostedAreteEndpoint, isSnapshotFrame, isSubscribedFrame, isUnsubscribedFrame, isValidFrame, normalizeSubscriptionQuery, parseFrame, parseFrameFromBlob, parseInstructionError, resolveAccounts, safeToRawAmount, serializeInstructionData, serializeViewKey, stringifyBigints, toRawAmount, unwrapOperationExecutionError, validateAccountResolution, withPrograms } from '@usearete/sdk';
|
|
2
|
+
import { Arete, resolveEnvironmentSwitch, createSession, getTransactionFailureOutcome, OperationExecutionError, unwrapOperationExecutionError, InstructionError, compareProgramIdentity, serializeViewKey, canonicalQueryKey, AreteError, getStackRuntimeExtensions, createPlatformHttpClient } from '@usearete/sdk';
|
|
3
|
+
export { Arete, AreteError, ConnectionManager, DEFAULT_CONFIG, DEFAULT_MAX_ENTRIES_PER_VIEW, DevEnvironmentError, FrameProcessor, InstructionError, MemoryAdapter, OperationCallbackError, OperationExecutionError, ProcessedSlotTimeoutError, QueryStore, ReadRequestError, SubscriptionRegistry, TransactionExecutionError, buildInstruction, canonicalQueryKey, createInstructionExecutor, createInstructionHandler, createPlatformHttpClient, createPublicKeySeed, createSeed, derivePda, executeInstruction, formatProgramError, formatRawToUi, getTransactionFailureOutcome, isErrorFrame, isHostedAreteEndpoint, isSnapshotFrame, isSubscribedFrame, isUnsubscribedFrame, isValidFrame, normalizeSubscriptionQuery, parseFrame, parseFrameFromBlob, parseInstructionError, resolveAccounts, safeToRawAmount, serializeInstructionData, serializeViewKey, stringifyBigints, toRawAmount, unwrapOperationExecutionError, validateAccountResolution, withPrograms } from '@usearete/sdk';
|
|
4
4
|
import { create } from 'zustand';
|
|
5
5
|
|
|
6
6
|
const DEFAULT_FLUSH_INTERVAL_MS = 16;
|
|
@@ -292,6 +292,7 @@ function AreteProvider({ children, ...config }) {
|
|
|
292
292
|
validateFrames: config.validateFrames,
|
|
293
293
|
onFrameValidationError: config.onFrameValidationError,
|
|
294
294
|
auth: config.auth,
|
|
295
|
+
...(config.environment !== undefined ? { environment: config.environment } : {}),
|
|
295
296
|
wallet: latestWalletRef.current,
|
|
296
297
|
}).then((client) => {
|
|
297
298
|
const ownsAttempt = lifecycleRef.current.active
|
|
@@ -323,7 +324,7 @@ function AreteProvider({ children, ...config }) {
|
|
|
323
324
|
trackConnectingPromise(connectingRef.current, cacheKey, connectionPromise);
|
|
324
325
|
notifyClientChange({ cacheKey, status: 'connecting' });
|
|
325
326
|
return connectionPromise;
|
|
326
|
-
}, [config.autoConnect, config.autoReconnect, config.reconnectIntervals, config.maxReconnectAttempts, config.maxEntriesPerView, config.flushIntervalMs, config.fetch, config.validateFrames, config.onFrameValidationError, config.auth, notifyClientChange]);
|
|
327
|
+
}, [config.autoConnect, config.autoReconnect, config.reconnectIntervals, config.maxReconnectAttempts, config.maxEntriesPerView, config.flushIntervalMs, config.fetch, config.validateFrames, config.onFrameValidationError, config.auth, config.environment, notifyClientChange]);
|
|
327
328
|
const getClient = useCallback((stack, options) => {
|
|
328
329
|
if (!stack) {
|
|
329
330
|
if (clientsRef.current.size === 1) {
|
|
@@ -425,6 +426,45 @@ function useConnectionState(stack, options) {
|
|
|
425
426
|
return state;
|
|
426
427
|
}
|
|
427
428
|
|
|
429
|
+
/**
|
|
430
|
+
* The world the enclosing `AreteProvider`'s clients talk to: `'dev'` for
|
|
431
|
+
* the project's dev environment, `'production'` otherwise. With a stack,
|
|
432
|
+
* the connected client's own `client.environment`; before it connects (or
|
|
433
|
+
* without a stack), what the provider's `environment` decides. Outside a
|
|
434
|
+
* provider, `'production'`.
|
|
435
|
+
*/
|
|
436
|
+
function useAreteEnvironment(stack, options) {
|
|
437
|
+
const context = useOptionalAreteContext();
|
|
438
|
+
// Read again when a client connects.
|
|
439
|
+
const [, setRevision] = React.useState(0);
|
|
440
|
+
const subscribe = context?.subscribeToClientChanges;
|
|
441
|
+
React.useEffect(() => subscribe?.(() => setRevision((revision) => revision + 1)), [subscribe]);
|
|
442
|
+
const client = context?.getClient(stack ?? context.config.stack, options);
|
|
443
|
+
if (client)
|
|
444
|
+
return client.environment;
|
|
445
|
+
if (!context)
|
|
446
|
+
return 'production';
|
|
447
|
+
try {
|
|
448
|
+
return resolveEnvironmentSwitch(context.config.environment).mode;
|
|
449
|
+
}
|
|
450
|
+
catch {
|
|
451
|
+
// A malformed switch fails the client with INVALID_CONFIG; the badge
|
|
452
|
+
// only reports where a working client goes.
|
|
453
|
+
return 'production';
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* A small badge that says the app is talking to the dev environment.
|
|
458
|
+
* Renders nothing in production, so it can stay in the app's status or
|
|
459
|
+
* diagnostics area. Carries `data-arete-environment="dev"` for styling.
|
|
460
|
+
*/
|
|
461
|
+
function AreteEnvironmentBadge({ label = 'Dev environment', className, style, stack, }) {
|
|
462
|
+
const environment = useAreteEnvironment(stack);
|
|
463
|
+
if (environment !== 'dev')
|
|
464
|
+
return null;
|
|
465
|
+
return (React.createElement("span", { role: "status", "data-arete-environment": "dev", className: className, style: style }, label));
|
|
466
|
+
}
|
|
467
|
+
|
|
428
468
|
const AreteSessionContext = createContext(null);
|
|
429
469
|
/**
|
|
430
470
|
* `ready()` rejects with this when its `AreteSessionProvider` was removed
|
|
@@ -545,10 +585,14 @@ function AreteSessionProvider(props) {
|
|
|
545
585
|
const given = (props.options ?? {});
|
|
546
586
|
const inheritedAuth = arete?.config.auth;
|
|
547
587
|
const inheritedFetch = arete?.config.fetch;
|
|
588
|
+
const inheritedEnvironment = arete?.config.environment;
|
|
548
589
|
const options = useSameShape({
|
|
549
590
|
...given,
|
|
550
591
|
...(given.auth === undefined && inheritedAuth ? { auth: inheritedAuth } : {}),
|
|
551
592
|
...(given.fetch === undefined && inheritedFetch ? { fetch: inheritedFetch } : {}),
|
|
593
|
+
...(given.environment === undefined && inheritedEnvironment !== undefined
|
|
594
|
+
? { environment: inheritedEnvironment }
|
|
595
|
+
: {}),
|
|
552
596
|
});
|
|
553
597
|
const [attempt, setAttempt] = useState(0);
|
|
554
598
|
const key = useMemo(() => ({ definition, options, external: externalSession, attempt }), [definition, options, externalSession, attempt]);
|
|
@@ -3255,5 +3299,5 @@ function useProtocolEvents(client, instanceId, options) {
|
|
|
3255
3299
|
}, [client, instanceId, enabled]);
|
|
3256
3300
|
}
|
|
3257
3301
|
|
|
3258
|
-
export { AreteProvider, AreteSessionProvider, AreteSessionUnavailableError, DEFAULT_RECONCILIATION_TIMEOUT_MS, OperationMutationError, ZustandAdapter, createAreteReact, createProcessedSlotReconciliation, isAreteSessionUnavailableError, isWalletRejection, reconcileProcessedSlot, summarizeStatuses, summarizeViews, toOperationMutationError, useAllowedSteps, useArete, useAreteContext, useAreteSession, useAsyncRead, useConnectionState, useInstructionMutation, useNativeBalance, useOperationMutation, usePlatformHttpClient, useProtocolEvents, useProtocolInstance, useProtocolParticipant, useReconcileProcessedSlot, useTokenBalance, useWalletActions };
|
|
3302
|
+
export { AreteEnvironmentBadge, AreteProvider, AreteSessionProvider, AreteSessionUnavailableError, DEFAULT_RECONCILIATION_TIMEOUT_MS, OperationMutationError, ZustandAdapter, createAreteReact, createProcessedSlotReconciliation, isAreteSessionUnavailableError, isWalletRejection, reconcileProcessedSlot, summarizeStatuses, summarizeViews, toOperationMutationError, useAllowedSteps, useArete, useAreteContext, useAreteEnvironment, useAreteSession, useAsyncRead, useConnectionState, useInstructionMutation, useNativeBalance, useOperationMutation, usePlatformHttpClient, useProtocolEvents, useProtocolInstance, useProtocolParticipant, useReconcileProcessedSlot, useTokenBalance, useWalletActions };
|
|
3259
3303
|
//# sourceMappingURL=index.esm.js.map
|