@usearete/sdk 0.31.0 → 0.33.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/README.md +26 -0
- package/dist/index.cjs +131 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +24 -3
- package/dist/index.esm.js +130 -7
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1263,8 +1263,19 @@ interface AuthConfig {
|
|
|
1263
1263
|
getToken?: (request?: AuthTokenRequest) => Promise<string | AuthTokenResult>;
|
|
1264
1264
|
/** Arete Cloud token endpoint URL */
|
|
1265
1265
|
tokenEndpoint?: string;
|
|
1266
|
-
/**
|
|
1266
|
+
/**
|
|
1267
|
+
* Publishable key (`a4_pk_...`) for code shipped to a browser. It is bound
|
|
1268
|
+
* to the origins it was created for; create one with
|
|
1269
|
+
* `a4 auth keys create-publishable --origin <scheme://host[:port]>`.
|
|
1270
|
+
*/
|
|
1267
1271
|
publishableKey?: string;
|
|
1272
|
+
/**
|
|
1273
|
+
* Agent key (`a4_ak_...`) or secret key (`a4_sk_...`) for servers, agents
|
|
1274
|
+
* and local scripts. Server-only: setting it in a browser throws. When no
|
|
1275
|
+
* auth option is set, outside browsers it defaults to the `ARETE_API_KEY`
|
|
1276
|
+
* environment variable.
|
|
1277
|
+
*/
|
|
1278
|
+
secretKey?: string;
|
|
1268
1279
|
/** Pre-minted static token (for server-side use) */
|
|
1269
1280
|
token?: string;
|
|
1270
1281
|
/** How the websocket token is sent to the server */
|
|
@@ -3082,6 +3093,16 @@ interface ProgramReadTransport {
|
|
|
3082
3093
|
read<T>(request: ProgramReadRequest): Promise<T>;
|
|
3083
3094
|
}
|
|
3084
3095
|
|
|
3096
|
+
/** Environment variable read for a secret-class key outside browsers. */
|
|
3097
|
+
declare const ARETE_API_KEY_ENV = "ARETE_API_KEY";
|
|
3098
|
+
/**
|
|
3099
|
+
* Key class inferred from an API key's prefix. `unknown` covers keys this SDK
|
|
3100
|
+
* does not recognise (for example self-hosted credentials); they are passed
|
|
3101
|
+
* through unvalidated.
|
|
3102
|
+
*/
|
|
3103
|
+
type ApiKeyClass = 'publishable' | 'secret' | 'unknown';
|
|
3104
|
+
declare function classifyApiKey(key: string): ApiKeyClass;
|
|
3105
|
+
|
|
3085
3106
|
declare class MemoryAdapter implements StorageAdapter {
|
|
3086
3107
|
private views;
|
|
3087
3108
|
private updateCallbacks;
|
|
@@ -3138,5 +3159,5 @@ declare const Arete: typeof Arete$1 & {
|
|
|
3138
3159
|
session: typeof createSession;
|
|
3139
3160
|
};
|
|
3140
3161
|
|
|
3141
|
-
export { API_PROBLEM_SCHEMA_VERSION, ASSOCIATED_TOKEN_PROGRAM_ADDRESS, Arete, AreteError, CLAIM_AGENT_MATERIALIZER_PATH, ConnectionManager, DEFAULT_CONFIG, DEFAULT_INITIAL_DATA_TIMEOUT_MS, DEFAULT_MAX_ENTRIES_PER_VIEW, EXTENSION_API_VERSION, FrameProcessor, InitialDataTimeoutError, InstructionError, MANAGED_SOLANA_CONTRACT_VERSION, MAX_MANAGED_BATCH_ADDRESSES, MAX_MANAGED_PAGE_SIZE, MemoryAdapter, OPERATION_KIND, OperationCallbackError, OperationExecutionError, PROGRAM_KEY_CONFLICT, PROGRAM_OPERATION_EXTENSIONS, ProcessedSlotTimeoutError, QueryStore, ReadRequestError, SPL_TOKEN_PROGRAM_ADDRESS, STACK_RUNTIME_EXTENSIONS, SYSTEM_PROGRAM_ADDRESS, StreamGapError, SubscriptionRegistry, TOKEN_2022_PROGRAM_ADDRESS, TRANSACTION_RESOURCE_OPTION_KEYS, TransactionExecutionError, TransactionOptionsError, TransactionTransportError, account, accountTombstone, appendFlowTransactions, appendTransactionInstructions, applyConnectedStackExtensions, arg, buildInstruction, bytes, canonicalQueryKey, chainAccountLoader, compareProgramIdentity, createChainClient, createEntityStream, createHostedSolanaGatewayTransports, createInstructionExecutor, createInstructionHandler, createPreparedFlow, createPreparedInstruction, createPreparedTransaction, createPreparedTransactionBody, createProgramPdas, createPublicKeySeed, createRichUpdateStream, createSeed, createSession, createSignerRegistry, createSubscriptionId, createTransactionTransport, createTypedListView, createTypedStateView, createTypedViews, createUpdateStream, decodeBase58, defineProgramExtensions, defineStackExtensions, deriveAssociatedTokenAccount, deriveHttpEndpoint, findProgramAddress as derivePda, describePreparedOperation, encodeBase58, executeInstruction, executePreparedOperation, extendProgram, extendPrograms, extendStack, findProgramAddress, findProgramAddressSync, flowOperation, formatPreparedOperation, formatProgramError, formatRawToUi, getMintDecimals, getOperationKind, getProgramRuntimeExtensions, getStackRuntimeExtensions, getTransactionFailureOutcome, hostedWebsocketSuffixes, inspectPreparedOperation, instructionOperation, isClaimAgentRecoveryAction, isEntityFrame, isErrorFrame, isHostedAreteEndpoint, isReplayErrorCode, isSafeClaimActionUrl, isSameProgramSdk, isSnapshotFrame, isStackVersionRefusalCode, isSubscribedFrame, isUnsubscribedFrame, isValidFrame, literal, managedAddress, managedContext, managedDiscovery, managedPage, managedReadOptions, managedU64, normalizeSubscription, normalizeSubscriptionQuery, normalizeSubscriptionRequest, normalizeTransactionError, parseApiProblem, parseFrame, parseFrameFromBlob, parseInstructionError, parseUiAmountToRaw, pda, prependFlowTransactionInstructions, prependTransactionInstructions, programAccountRead, programQuery, resolveAccounts, resolveAmount, resolveAmountToRaw, resolveAmountsToRaw, resolveTokenProgramAddress, resolveTransactionBuildOptions, safeToRawAmount, serializeInstructionData, serializeViewKey, setHostedWebsocketSuffixes, stackQuery, stringifyBigints, toJsonValue, toRawAmount, toWireResourceOptions, transactionOperation, unwrapOperationExecutionError, validateAccountResolution, validateProgramReadDescriptor, validateSubscriptionId, withProgramIdentity, withProgramRead, withPrograms };
|
|
3142
|
-
export type { AccountCategory, AccountLoader, AccountMeta, AccountResolutionOptions, AccountResolutionResult, AccountTombstone, AmountInput, AnyOperation, ApiProblemV1, AreteConfig, AreteOptions, AreteOptionsWithStorage, ArgSchema, ArgType, AuthConfig, AuthTokenRequest, AuthTokenResult, AuthTokenTarget, BuildOptions, BuiltAccountMeta, BuiltInstruction, ChainClient, ChainClock, ChainFailedTransactionOutcome, CompositionSessionOptions, ConfirmationLevel, ConfirmedTransaction, ConfirmedTransactionOutcome, ConnectOptions, ConnectedArete, ConnectedStackClient, ConnectionState, ConnectionStateCallback, ContextSlotOptions, Contextual, CreatePreparedFlowInput, CreatePreparedInstructionInput, CreatePreparedTransactionInput, DefaultViewKey, DiscoveryProvenance, EntityFrame, ErrorFrame, ErrorMetadata, ExecuteOptions, ExecutionResult, ExtendedProgramDefinition, ExtendedStackDefinition, FlowOperation, FlowOperationNamespace, FlowOperationReceipt, Frame, FrameMode, FrameOp, FrameProcessorConfig, FrameValidationDiagnostic, GetOptions, HostedSolanaGatewayBindings, HostedSolanaGatewayCapabilityBinding, HostedSolanaGatewayTransportOptions, HostedSolanaGatewayTransports, HttpAuthMetadata, InstructionExecutor, InstructionHandler, InstructionHandlerConfig, InstructionOperation, InstructionOperationNamespace, JsonObject, JsonPrimitive, JsonValue, LatestBlockhashResult, ManagedReadOptions, MergeProgramMaps, MintAccountInfo, NativeBalanceInfo, NativePositionPage, NativePositionQuery, NonEmptyReadonlyArray, NotSubmittedTransactionOutcome, OperationCallbackPhase, OperationExecutionEvent, OperationExecutionHost, OperationExecutionOptions, OperationExecutionSuccessEvent, OperationInspection, OperationInspectionOptions, OperationKind, OperationKindBrand, OperationNamespace, OperationPlan, OperationReceiptFor, OperationTransactionReceipt, OwnerTokenAccount, OwnerTokenAccountsPage, OwnerTokenAccountsRequest, PdaConfig, PdaDeriveContext, PdaFactory, PdaProgram, PdaProgramSelector, PdaSeed, PreparedFlow, PreparedInstruction, PreparedOperation, PreparedOperationDescription, PreparedTransaction, PreparedTransactionBody, PreparedTransactionInstruction, PreparedTransactionOperation, ProgramAccountBatchItem, ProgramAccountBatchResult, ProgramAccountReadDefinition, ProgramError, ProgramExtensionInput, ProgramIdentityMatch, ProgramInterface, ProgramOperationContext, ProgramOperations, ProgramOperationsOf, ProgramPdas, ProgramQueryDefinition, ProgramReadBinding, ProgramReadBindingAuthTarget, ProgramReadDescriptor, ProgramReadDescriptors, ProgramReadOf, ProgramReadOverride, ProgramReadOverrides, ProgramReadRequest, ProgramReadTransport, ProgramReleaseReference, ProgramRuntimeExtensionCarrier, ProgramRuntimeExtensions, ProgramSdkDefinition, ProgramSdkIdentity, ProgramsInterface, QueriesInterface, QueryLease, QuerySnapshot, RawAccountInfo, RawInstructionsInterface, RawProgramsInterface, ReadArgumentCount, ReadArgumentCounts, ReadContext, ReadTransportMethod, ReadyRecoveryAction, ReadyRecoveryActionV1, RecoveryAction, ReplayErrorCode, ReplayWindow, ResolvedAccount, ResolvedAccounts, ResolvedTransactionBuildOptions, ResolvedTransactionResourceOptions, ResourceLamports, ResourceUnits, RichUpdate, RichUpdateCallback, Schema, SchemaResult, SeedDef, SendOptions, SendResult, Session, SessionDefinition, SessionMemberOptions, SessionOptions, SignerRegistry, SingleTransactionOperationReceipt, SnapshotEntity, SnapshotFrame, SocketIssue, SocketIssueCallback, SolanaGatewayAuthMetadata, SolanaGatewayAuthScope, SolanaGatewayBindingAuthTarget, SortConfig, SortOrder, StackConnectedExtensions, StackDefinition, StackEndpoints, StackExtensionClient, StackExtensionInput, StackQueryDefinition, StackRelease, StackRuntimeExtensionCarrier, StackRuntimeExtensions, StackVersionRefusal, StackWithAttachedPrograms, StorageAdapter, StorageAdapterConfig, StringifiedBigints, SubmittedUnknownTransactionOutcome, SubscribeCallback, SubscribedFrame, Subscription, SubscriptionIdentity, SubscriptionOptions, SubscriptionQuery, SubscriptionRequest, SubscriptionSnapshotOptions, TokenAccountInfo, TokenBalanceInfo, TokenBalanceInput, TransactionAccountBalance, TransactionBuildCapability, TransactionBuildOptions, TransactionCommitment, TransactionExecutionMetadata, TransactionFailureOutcome, TransactionFailurePhase, TransactionFailureStatus, TransactionFeeResult, TransactionInspectOptions, TransactionInspectionOptions, TransactionInspectionResult, TransactionOperation, TransactionOperationNamespace, TransactionOptions, TransactionOptionsErrorCode, TransactionOutcome, TransactionRequestContext, TransactionResourceOptionKey, TransactionResourceOptions, TransactionSendOptions, TransactionSendResult, TransactionSignatureStatus, TransactionSimulationOptions, TransactionSimulationResult, TransactionTransport, TransactionTransportErrorBody, TransactionVersion, TypedAccountReader, TypedInstruction, TypedListView, TypedQueryExecutor, TypedStateView, TypedViewGroup, TypedViews, UnsubscribeFn, UnsubscribedFrame, Update, UpdateCallback, UsageLimit, ViewDef, ViewGroup, ViewKeyFields, ViewKeyValue, ViewSortConfig, WaitForProcessedSlotOptions, WalletAdapter, WalletConnectOptions, WalletExecutionContext, WalletState, WatchOptions, WebSocketFactoryInit };
|
|
3162
|
+
export { API_PROBLEM_SCHEMA_VERSION, ARETE_API_KEY_ENV, ASSOCIATED_TOKEN_PROGRAM_ADDRESS, Arete, AreteError, CLAIM_AGENT_MATERIALIZER_PATH, ConnectionManager, DEFAULT_CONFIG, DEFAULT_INITIAL_DATA_TIMEOUT_MS, DEFAULT_MAX_ENTRIES_PER_VIEW, EXTENSION_API_VERSION, FrameProcessor, InitialDataTimeoutError, InstructionError, MANAGED_SOLANA_CONTRACT_VERSION, MAX_MANAGED_BATCH_ADDRESSES, MAX_MANAGED_PAGE_SIZE, MemoryAdapter, OPERATION_KIND, OperationCallbackError, OperationExecutionError, PROGRAM_KEY_CONFLICT, PROGRAM_OPERATION_EXTENSIONS, ProcessedSlotTimeoutError, QueryStore, ReadRequestError, SPL_TOKEN_PROGRAM_ADDRESS, STACK_RUNTIME_EXTENSIONS, SYSTEM_PROGRAM_ADDRESS, StreamGapError, SubscriptionRegistry, TOKEN_2022_PROGRAM_ADDRESS, TRANSACTION_RESOURCE_OPTION_KEYS, TransactionExecutionError, TransactionOptionsError, TransactionTransportError, account, accountTombstone, appendFlowTransactions, appendTransactionInstructions, applyConnectedStackExtensions, arg, buildInstruction, bytes, canonicalQueryKey, chainAccountLoader, classifyApiKey, compareProgramIdentity, createChainClient, createEntityStream, createHostedSolanaGatewayTransports, createInstructionExecutor, createInstructionHandler, createPreparedFlow, createPreparedInstruction, createPreparedTransaction, createPreparedTransactionBody, createProgramPdas, createPublicKeySeed, createRichUpdateStream, createSeed, createSession, createSignerRegistry, createSubscriptionId, createTransactionTransport, createTypedListView, createTypedStateView, createTypedViews, createUpdateStream, decodeBase58, defineProgramExtensions, defineStackExtensions, deriveAssociatedTokenAccount, deriveHttpEndpoint, findProgramAddress as derivePda, describePreparedOperation, encodeBase58, executeInstruction, executePreparedOperation, extendProgram, extendPrograms, extendStack, findProgramAddress, findProgramAddressSync, flowOperation, formatPreparedOperation, formatProgramError, formatRawToUi, getMintDecimals, getOperationKind, getProgramRuntimeExtensions, getStackRuntimeExtensions, getTransactionFailureOutcome, hostedWebsocketSuffixes, inspectPreparedOperation, instructionOperation, isClaimAgentRecoveryAction, isEntityFrame, isErrorFrame, isHostedAreteEndpoint, isReplayErrorCode, isSafeClaimActionUrl, isSameProgramSdk, isSnapshotFrame, isStackVersionRefusalCode, isSubscribedFrame, isUnsubscribedFrame, isValidFrame, literal, managedAddress, managedContext, managedDiscovery, managedPage, managedReadOptions, managedU64, normalizeSubscription, normalizeSubscriptionQuery, normalizeSubscriptionRequest, normalizeTransactionError, parseApiProblem, parseFrame, parseFrameFromBlob, parseInstructionError, parseUiAmountToRaw, pda, prependFlowTransactionInstructions, prependTransactionInstructions, programAccountRead, programQuery, resolveAccounts, resolveAmount, resolveAmountToRaw, resolveAmountsToRaw, resolveTokenProgramAddress, resolveTransactionBuildOptions, safeToRawAmount, serializeInstructionData, serializeViewKey, setHostedWebsocketSuffixes, stackQuery, stringifyBigints, toJsonValue, toRawAmount, toWireResourceOptions, transactionOperation, unwrapOperationExecutionError, validateAccountResolution, validateProgramReadDescriptor, validateSubscriptionId, withProgramIdentity, withProgramRead, withPrograms };
|
|
3163
|
+
export type { AccountCategory, AccountLoader, AccountMeta, AccountResolutionOptions, AccountResolutionResult, AccountTombstone, AmountInput, AnyOperation, ApiKeyClass, ApiProblemV1, AreteConfig, AreteOptions, AreteOptionsWithStorage, ArgSchema, ArgType, AuthConfig, AuthTokenRequest, AuthTokenResult, AuthTokenTarget, BuildOptions, BuiltAccountMeta, BuiltInstruction, ChainClient, ChainClock, ChainFailedTransactionOutcome, CompositionSessionOptions, ConfirmationLevel, ConfirmedTransaction, ConfirmedTransactionOutcome, ConnectOptions, ConnectedArete, ConnectedStackClient, ConnectionState, ConnectionStateCallback, ContextSlotOptions, Contextual, CreatePreparedFlowInput, CreatePreparedInstructionInput, CreatePreparedTransactionInput, DefaultViewKey, DiscoveryProvenance, EntityFrame, ErrorFrame, ErrorMetadata, ExecuteOptions, ExecutionResult, ExtendedProgramDefinition, ExtendedStackDefinition, FlowOperation, FlowOperationNamespace, FlowOperationReceipt, Frame, FrameMode, FrameOp, FrameProcessorConfig, FrameValidationDiagnostic, GetOptions, HostedSolanaGatewayBindings, HostedSolanaGatewayCapabilityBinding, HostedSolanaGatewayTransportOptions, HostedSolanaGatewayTransports, HttpAuthMetadata, InstructionExecutor, InstructionHandler, InstructionHandlerConfig, InstructionOperation, InstructionOperationNamespace, JsonObject, JsonPrimitive, JsonValue, LatestBlockhashResult, ManagedReadOptions, MergeProgramMaps, MintAccountInfo, NativeBalanceInfo, NativePositionPage, NativePositionQuery, NonEmptyReadonlyArray, NotSubmittedTransactionOutcome, OperationCallbackPhase, OperationExecutionEvent, OperationExecutionHost, OperationExecutionOptions, OperationExecutionSuccessEvent, OperationInspection, OperationInspectionOptions, OperationKind, OperationKindBrand, OperationNamespace, OperationPlan, OperationReceiptFor, OperationTransactionReceipt, OwnerTokenAccount, OwnerTokenAccountsPage, OwnerTokenAccountsRequest, PdaConfig, PdaDeriveContext, PdaFactory, PdaProgram, PdaProgramSelector, PdaSeed, PreparedFlow, PreparedInstruction, PreparedOperation, PreparedOperationDescription, PreparedTransaction, PreparedTransactionBody, PreparedTransactionInstruction, PreparedTransactionOperation, ProgramAccountBatchItem, ProgramAccountBatchResult, ProgramAccountReadDefinition, ProgramError, ProgramExtensionInput, ProgramIdentityMatch, ProgramInterface, ProgramOperationContext, ProgramOperations, ProgramOperationsOf, ProgramPdas, ProgramQueryDefinition, ProgramReadBinding, ProgramReadBindingAuthTarget, ProgramReadDescriptor, ProgramReadDescriptors, ProgramReadOf, ProgramReadOverride, ProgramReadOverrides, ProgramReadRequest, ProgramReadTransport, ProgramReleaseReference, ProgramRuntimeExtensionCarrier, ProgramRuntimeExtensions, ProgramSdkDefinition, ProgramSdkIdentity, ProgramsInterface, QueriesInterface, QueryLease, QuerySnapshot, RawAccountInfo, RawInstructionsInterface, RawProgramsInterface, ReadArgumentCount, ReadArgumentCounts, ReadContext, ReadTransportMethod, ReadyRecoveryAction, ReadyRecoveryActionV1, RecoveryAction, ReplayErrorCode, ReplayWindow, ResolvedAccount, ResolvedAccounts, ResolvedTransactionBuildOptions, ResolvedTransactionResourceOptions, ResourceLamports, ResourceUnits, RichUpdate, RichUpdateCallback, Schema, SchemaResult, SeedDef, SendOptions, SendResult, Session, SessionDefinition, SessionMemberOptions, SessionOptions, SignerRegistry, SingleTransactionOperationReceipt, SnapshotEntity, SnapshotFrame, SocketIssue, SocketIssueCallback, SolanaGatewayAuthMetadata, SolanaGatewayAuthScope, SolanaGatewayBindingAuthTarget, SortConfig, SortOrder, StackConnectedExtensions, StackDefinition, StackEndpoints, StackExtensionClient, StackExtensionInput, StackQueryDefinition, StackRelease, StackRuntimeExtensionCarrier, StackRuntimeExtensions, StackVersionRefusal, StackWithAttachedPrograms, StorageAdapter, StorageAdapterConfig, StringifiedBigints, SubmittedUnknownTransactionOutcome, SubscribeCallback, SubscribedFrame, Subscription, SubscriptionIdentity, SubscriptionOptions, SubscriptionQuery, SubscriptionRequest, SubscriptionSnapshotOptions, TokenAccountInfo, TokenBalanceInfo, TokenBalanceInput, TransactionAccountBalance, TransactionBuildCapability, TransactionBuildOptions, TransactionCommitment, TransactionExecutionMetadata, TransactionFailureOutcome, TransactionFailurePhase, TransactionFailureStatus, TransactionFeeResult, TransactionInspectOptions, TransactionInspectionOptions, TransactionInspectionResult, TransactionOperation, TransactionOperationNamespace, TransactionOptions, TransactionOptionsErrorCode, TransactionOutcome, TransactionRequestContext, TransactionResourceOptionKey, TransactionResourceOptions, TransactionSendOptions, TransactionSendResult, TransactionSignatureStatus, TransactionSimulationOptions, TransactionSimulationResult, TransactionTransport, TransactionTransportErrorBody, TransactionVersion, TypedAccountReader, TypedInstruction, TypedListView, TypedQueryExecutor, TypedStateView, TypedViewGroup, TypedViews, UnsubscribeFn, UnsubscribedFrame, Update, UpdateCallback, UsageLimit, ViewDef, ViewGroup, ViewKeyFields, ViewKeyValue, ViewSortConfig, WaitForProcessedSlotOptions, WalletAdapter, WalletConnectOptions, WalletExecutionContext, WalletState, WatchOptions, WebSocketFactoryInit };
|
package/dist/index.esm.js
CHANGED
|
@@ -1041,6 +1041,124 @@ const AUTH_ERROR_CODES_BY_WIRE = {
|
|
|
1041
1041
|
'stack-version-unknown': 'STACK_VERSION_UNKNOWN',
|
|
1042
1042
|
};
|
|
1043
1043
|
|
|
1044
|
+
/** Environment variable read for a secret-class key outside browsers. */
|
|
1045
|
+
const ARETE_API_KEY_ENV = 'ARETE_API_KEY';
|
|
1046
|
+
const CREATE_PUBLISHABLE_HINT = 'create one with `a4 auth keys create-publishable --origin <scheme://host[:port]>`';
|
|
1047
|
+
const PUBLISHABLE_PREFIXES = ['a4_pk_', 'hspk_'];
|
|
1048
|
+
const SECRET_PREFIXES = ['a4_sk_', 'a4_ak_', 'hsk_'];
|
|
1049
|
+
function classifyApiKey(key) {
|
|
1050
|
+
const trimmed = key.trim();
|
|
1051
|
+
if (PUBLISHABLE_PREFIXES.some((prefix) => trimmed.startsWith(prefix)))
|
|
1052
|
+
return 'publishable';
|
|
1053
|
+
if (SECRET_PREFIXES.some((prefix) => trimmed.startsWith(prefix)))
|
|
1054
|
+
return 'secret';
|
|
1055
|
+
return 'unknown';
|
|
1056
|
+
}
|
|
1057
|
+
/**
|
|
1058
|
+
* True in a browser page: both `window` and `document` exist. Web workers,
|
|
1059
|
+
* service workers, edge runtimes, SSR (Node/Bun) and Deno have no `document`
|
|
1060
|
+
* and count as server-side.
|
|
1061
|
+
*/
|
|
1062
|
+
function isBrowserEnvironment() {
|
|
1063
|
+
const scope = globalThis;
|
|
1064
|
+
return typeof scope.window === 'object'
|
|
1065
|
+
&& scope.window !== null
|
|
1066
|
+
&& typeof scope.document === 'object'
|
|
1067
|
+
&& scope.document !== null;
|
|
1068
|
+
}
|
|
1069
|
+
/**
|
|
1070
|
+
* Read an environment variable in Node, Bun or Deno without prompting for or
|
|
1071
|
+
* failing on missing permissions. Browsers have no environment.
|
|
1072
|
+
*/
|
|
1073
|
+
function readEnvironmentVariable(name) {
|
|
1074
|
+
try {
|
|
1075
|
+
const deno = globalThis.Deno;
|
|
1076
|
+
if (deno) {
|
|
1077
|
+
// Reading without --allow-env throws or prompts; ask first.
|
|
1078
|
+
const state = deno.permissions?.querySync?.({ name: 'env', variable: name })?.state;
|
|
1079
|
+
if (state !== 'granted')
|
|
1080
|
+
return undefined;
|
|
1081
|
+
const value = deno.env?.get?.(name);
|
|
1082
|
+
return typeof value === 'string' ? value : undefined;
|
|
1083
|
+
}
|
|
1084
|
+
const value = globalThis
|
|
1085
|
+
.process?.env?.[name];
|
|
1086
|
+
return typeof value === 'string' ? value : undefined;
|
|
1087
|
+
}
|
|
1088
|
+
catch {
|
|
1089
|
+
return undefined;
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
const warned$1 = new Set();
|
|
1093
|
+
function warnOnce$1(id, message) {
|
|
1094
|
+
if (warned$1.has(id))
|
|
1095
|
+
return;
|
|
1096
|
+
warned$1.add(id);
|
|
1097
|
+
console.warn(`[arete] ${message}`);
|
|
1098
|
+
}
|
|
1099
|
+
function hasExplicitAuth(auth) {
|
|
1100
|
+
return auth !== undefined && (auth.token !== undefined
|
|
1101
|
+
|| auth.getToken !== undefined
|
|
1102
|
+
|| auth.tokenEndpoint !== undefined
|
|
1103
|
+
|| auth.publishableKey !== undefined
|
|
1104
|
+
|| auth.secretKey !== undefined);
|
|
1105
|
+
}
|
|
1106
|
+
/**
|
|
1107
|
+
* Validate the configured API keys and apply the `ARETE_API_KEY` fallback.
|
|
1108
|
+
*
|
|
1109
|
+
* - `secretKey` is refused in browsers and refuses publishable keys.
|
|
1110
|
+
* - A secret-class key in `publishableKey` is refused in browsers and warned
|
|
1111
|
+
* about elsewhere (it still works server-side, as it always has).
|
|
1112
|
+
* - Outside browsers, when no auth option is set at all, `ARETE_API_KEY`
|
|
1113
|
+
* supplies `secretKey`.
|
|
1114
|
+
*
|
|
1115
|
+
* Error and warning text never includes key material.
|
|
1116
|
+
*/
|
|
1117
|
+
function resolveAuthConfig(auth) {
|
|
1118
|
+
const browser = isBrowserEnvironment();
|
|
1119
|
+
if (auth?.secretKey !== undefined) {
|
|
1120
|
+
if (browser) {
|
|
1121
|
+
throw new AreteError('auth.secretKey cannot be used in a browser: anything shipped to a browser is public. '
|
|
1122
|
+
+ 'Use auth.publishableKey with a publishable key (a4_pk_...) instead; '
|
|
1123
|
+
+ `${CREATE_PUBLISHABLE_HINT}. Keep secret and agent keys on servers and in local scripts.`, 'INVALID_CONFIG');
|
|
1124
|
+
}
|
|
1125
|
+
if (auth.secretKey.trim() === '') {
|
|
1126
|
+
throw new AreteError('auth.secretKey is empty', 'INVALID_CONFIG');
|
|
1127
|
+
}
|
|
1128
|
+
if (classifyApiKey(auth.secretKey) === 'publishable') {
|
|
1129
|
+
throw new AreteError('auth.secretKey was given a publishable key (a4_pk_...). Pass it as auth.publishableKey '
|
|
1130
|
+
+ 'instead; auth.secretKey takes an agent key (a4_ak_...) or secret key (a4_sk_...).', 'INVALID_CONFIG');
|
|
1131
|
+
}
|
|
1132
|
+
if (auth.publishableKey !== undefined) {
|
|
1133
|
+
throw new AreteError('Set either auth.secretKey (servers and scripts) or auth.publishableKey (browsers), not both.', 'INVALID_CONFIG');
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
if (auth?.publishableKey !== undefined && classifyApiKey(auth.publishableKey) === 'secret') {
|
|
1137
|
+
if (browser) {
|
|
1138
|
+
throw new AreteError('auth.publishableKey was given a secret-class key (a4_sk_... or a4_ak_...). Never ship a '
|
|
1139
|
+
+ 'secret or agent key to a browser. Use a publishable key (a4_pk_...) instead; '
|
|
1140
|
+
+ `${CREATE_PUBLISHABLE_HINT}.`, 'INVALID_CONFIG');
|
|
1141
|
+
}
|
|
1142
|
+
warnOnce$1('secret-in-publishable', 'auth.publishableKey was given a secret-class key (a4_sk_... or a4_ak_...). '
|
|
1143
|
+
+ 'Pass it as auth.secretKey instead (servers and scripts only), or set ARETE_API_KEY.');
|
|
1144
|
+
}
|
|
1145
|
+
if (browser || hasExplicitAuth(auth))
|
|
1146
|
+
return auth;
|
|
1147
|
+
const environmentKey = readEnvironmentVariable(ARETE_API_KEY_ENV)?.trim();
|
|
1148
|
+
if (!environmentKey)
|
|
1149
|
+
return auth;
|
|
1150
|
+
if (classifyApiKey(environmentKey) === 'publishable') {
|
|
1151
|
+
warnOnce$1('publishable-in-env', `${ARETE_API_KEY_ENV} holds a publishable key (a4_pk_...) and was ignored. Set it to an agent `
|
|
1152
|
+
+ 'key (a4_ak_...) or secret key (a4_sk_...), or pass the publishable key as auth.publishableKey.');
|
|
1153
|
+
return auth;
|
|
1154
|
+
}
|
|
1155
|
+
return { ...auth, secretKey: environmentKey };
|
|
1156
|
+
}
|
|
1157
|
+
/** The key sent as the token endpoint bearer credential, if any. */
|
|
1158
|
+
function tokenEndpointApiKey(auth) {
|
|
1159
|
+
return auth?.secretKey ?? auth?.publishableKey;
|
|
1160
|
+
}
|
|
1161
|
+
|
|
1044
1162
|
const GZIP_MAGIC_0 = 0x1f;
|
|
1045
1163
|
const GZIP_MAGIC_1 = 0x8b;
|
|
1046
1164
|
const FRAME_MODES = new Set(['state', 'append', 'list']);
|
|
@@ -1848,7 +1966,7 @@ class ConnectionManager {
|
|
|
1848
1966
|
this.reconnectIntervals = config.reconnectIntervals ?? DEFAULT_CONFIG.reconnectIntervals;
|
|
1849
1967
|
this.maxReconnectAttempts =
|
|
1850
1968
|
config.maxReconnectAttempts ?? DEFAULT_CONFIG.maxReconnectAttempts;
|
|
1851
|
-
this.authConfig = config.auth;
|
|
1969
|
+
this.authConfig = resolveAuthConfig(config.auth);
|
|
1852
1970
|
this.release = normalizeStackRelease(config.release);
|
|
1853
1971
|
this.authFetch = config.fetch ?? ((input, init) => {
|
|
1854
1972
|
if (typeof globalThis.fetch !== 'function') {
|
|
@@ -2100,12 +2218,11 @@ class ConnectionManager {
|
|
|
2100
2218
|
};
|
|
2101
2219
|
}
|
|
2102
2220
|
async fetchTokenFromEndpoint(tokenEndpoint, request) {
|
|
2221
|
+
const apiKey = tokenEndpointApiKey(this.authConfig);
|
|
2103
2222
|
const response = await this.authFetch(tokenEndpoint, {
|
|
2104
2223
|
method: 'POST',
|
|
2105
2224
|
headers: {
|
|
2106
|
-
...(
|
|
2107
|
-
? { Authorization: `Bearer ${this.authConfig.publishableKey}` }
|
|
2108
|
-
: {}),
|
|
2225
|
+
...(apiKey ? { Authorization: `Bearer ${apiKey}` } : {}),
|
|
2109
2226
|
...(this.authConfig?.tokenEndpointHeaders ?? {}),
|
|
2110
2227
|
'Content-Type': 'application/json',
|
|
2111
2228
|
},
|
|
@@ -5451,7 +5568,10 @@ function hasRuntimeAuthStrategy(auth) {
|
|
|
5451
5568
|
|| auth?.getToken !== undefined
|
|
5452
5569
|
|| auth?.tokenEndpoint !== undefined;
|
|
5453
5570
|
}
|
|
5454
|
-
function bindingAuthConfig(binding,
|
|
5571
|
+
function bindingAuthConfig(binding, configuredAuth) {
|
|
5572
|
+
// Resolve ARETE_API_KEY before the binding endpoint is filled in, so an
|
|
5573
|
+
// otherwise unconfigured client still authenticates.
|
|
5574
|
+
const runtimeAuth = resolveAuthConfig(configuredAuth);
|
|
5455
5575
|
if (hasRuntimeAuthStrategy(runtimeAuth))
|
|
5456
5576
|
return runtimeAuth;
|
|
5457
5577
|
if (!binding.auth.required)
|
|
@@ -7498,7 +7618,10 @@ function parseProgramReadResponse(response, path, body) {
|
|
|
7498
7618
|
throw new AreteError(`Program read '${path}' returned invalid JSON`, 'INVALID_RESPONSE', error);
|
|
7499
7619
|
}
|
|
7500
7620
|
}
|
|
7501
|
-
function hostedAuthConfig(binding,
|
|
7621
|
+
function hostedAuthConfig(binding, configuredAuth) {
|
|
7622
|
+
// Resolve ARETE_API_KEY before the binding endpoint is filled in, so an
|
|
7623
|
+
// otherwise unconfigured client still authenticates.
|
|
7624
|
+
const runtimeAuth = resolveAuthConfig(configuredAuth);
|
|
7502
7625
|
const metadata = binding.auth;
|
|
7503
7626
|
const runtimeStrategyConfigured = runtimeAuth?.token !== undefined
|
|
7504
7627
|
|| runtimeAuth?.getToken !== undefined
|
|
@@ -8972,5 +9095,5 @@ function stringifyBigints(value) {
|
|
|
8972
9095
|
|
|
8973
9096
|
const Arete = Object.assign(Arete$1, { session: createSession });
|
|
8974
9097
|
|
|
8975
|
-
export { API_PROBLEM_SCHEMA_VERSION, ASSOCIATED_TOKEN_PROGRAM_ADDRESS, Arete, AreteError, CLAIM_AGENT_MATERIALIZER_PATH, ConnectionManager, DEFAULT_CONFIG, DEFAULT_INITIAL_DATA_TIMEOUT_MS, DEFAULT_MAX_ENTRIES_PER_VIEW, EXTENSION_API_VERSION, FrameProcessor, InitialDataTimeoutError, InstructionError, MANAGED_SOLANA_CONTRACT_VERSION, MAX_MANAGED_BATCH_ADDRESSES, MAX_MANAGED_PAGE_SIZE, MemoryAdapter, OPERATION_KIND, OperationCallbackError, OperationExecutionError, PROGRAM_KEY_CONFLICT, PROGRAM_OPERATION_EXTENSIONS, ProcessedSlotTimeoutError, QueryStore, ReadRequestError, SPL_TOKEN_PROGRAM_ADDRESS, STACK_RUNTIME_EXTENSIONS, SYSTEM_PROGRAM_ADDRESS, StreamGapError, SubscriptionRegistry, TOKEN_2022_PROGRAM_ADDRESS, TRANSACTION_RESOURCE_OPTION_KEYS, TransactionExecutionError, TransactionOptionsError, TransactionTransportError, account, accountTombstone, appendFlowTransactions, appendTransactionInstructions, applyConnectedStackExtensions, arg, buildInstruction, bytes, canonicalQueryKey, chainAccountLoader, compareProgramIdentity, createChainClient, createEntityStream, createHostedSolanaGatewayTransports, createInstructionExecutor, createInstructionHandler, createPreparedFlow, createPreparedInstruction, createPreparedTransaction, createPreparedTransactionBody, createProgramPdas, createPublicKeySeed, createRichUpdateStream, createSeed, createSession, createSignerRegistry, createSubscriptionId, createTransactionTransport, createTypedListView, createTypedStateView, createTypedViews, createUpdateStream, decodeBase58, defineProgramExtensions, defineStackExtensions, deriveAssociatedTokenAccount, deriveHttpEndpoint, findProgramAddress as derivePda, describePreparedOperation, encodeBase58, executeInstruction, executePreparedOperation, extendProgram, extendPrograms, extendStack, findProgramAddress, findProgramAddressSync, flowOperation, formatPreparedOperation, formatProgramError, formatRawToUi, getMintDecimals, getOperationKind, getProgramRuntimeExtensions, getStackRuntimeExtensions, getTransactionFailureOutcome, hostedWebsocketSuffixes, inspectPreparedOperation, instructionOperation, isClaimAgentRecoveryAction, isEntityFrame, isErrorFrame, isHostedAreteEndpoint, isReplayErrorCode, isSafeClaimActionUrl, isSameProgramSdk, isSnapshotFrame, isStackVersionRefusalCode, isSubscribedFrame, isUnsubscribedFrame, isValidFrame, literal, managedAddress, managedContext, managedDiscovery, managedPage, managedReadOptions, managedU64, normalizeSubscription, normalizeSubscriptionQuery, normalizeSubscriptionRequest, normalizeTransactionError, parseApiProblem, parseFrame, parseFrameFromBlob, parseInstructionError, parseUiAmountToRaw, pda, prependFlowTransactionInstructions, prependTransactionInstructions, programAccountRead, programQuery, resolveAccounts, resolveAmount, resolveAmountToRaw, resolveAmountsToRaw, resolveTokenProgramAddress, resolveTransactionBuildOptions, safeToRawAmount, serializeInstructionData, serializeViewKey, setHostedWebsocketSuffixes, stackQuery, stringifyBigints, toJsonValue, toRawAmount, toWireResourceOptions, transactionOperation, unwrapOperationExecutionError, validateAccountResolution, validateProgramReadDescriptor, validateSubscriptionId, withProgramIdentity, withProgramRead, withPrograms };
|
|
9098
|
+
export { API_PROBLEM_SCHEMA_VERSION, ARETE_API_KEY_ENV, ASSOCIATED_TOKEN_PROGRAM_ADDRESS, Arete, AreteError, CLAIM_AGENT_MATERIALIZER_PATH, ConnectionManager, DEFAULT_CONFIG, DEFAULT_INITIAL_DATA_TIMEOUT_MS, DEFAULT_MAX_ENTRIES_PER_VIEW, EXTENSION_API_VERSION, FrameProcessor, InitialDataTimeoutError, InstructionError, MANAGED_SOLANA_CONTRACT_VERSION, MAX_MANAGED_BATCH_ADDRESSES, MAX_MANAGED_PAGE_SIZE, MemoryAdapter, OPERATION_KIND, OperationCallbackError, OperationExecutionError, PROGRAM_KEY_CONFLICT, PROGRAM_OPERATION_EXTENSIONS, ProcessedSlotTimeoutError, QueryStore, ReadRequestError, SPL_TOKEN_PROGRAM_ADDRESS, STACK_RUNTIME_EXTENSIONS, SYSTEM_PROGRAM_ADDRESS, StreamGapError, SubscriptionRegistry, TOKEN_2022_PROGRAM_ADDRESS, TRANSACTION_RESOURCE_OPTION_KEYS, TransactionExecutionError, TransactionOptionsError, TransactionTransportError, account, accountTombstone, appendFlowTransactions, appendTransactionInstructions, applyConnectedStackExtensions, arg, buildInstruction, bytes, canonicalQueryKey, chainAccountLoader, classifyApiKey, compareProgramIdentity, createChainClient, createEntityStream, createHostedSolanaGatewayTransports, createInstructionExecutor, createInstructionHandler, createPreparedFlow, createPreparedInstruction, createPreparedTransaction, createPreparedTransactionBody, createProgramPdas, createPublicKeySeed, createRichUpdateStream, createSeed, createSession, createSignerRegistry, createSubscriptionId, createTransactionTransport, createTypedListView, createTypedStateView, createTypedViews, createUpdateStream, decodeBase58, defineProgramExtensions, defineStackExtensions, deriveAssociatedTokenAccount, deriveHttpEndpoint, findProgramAddress as derivePda, describePreparedOperation, encodeBase58, executeInstruction, executePreparedOperation, extendProgram, extendPrograms, extendStack, findProgramAddress, findProgramAddressSync, flowOperation, formatPreparedOperation, formatProgramError, formatRawToUi, getMintDecimals, getOperationKind, getProgramRuntimeExtensions, getStackRuntimeExtensions, getTransactionFailureOutcome, hostedWebsocketSuffixes, inspectPreparedOperation, instructionOperation, isClaimAgentRecoveryAction, isEntityFrame, isErrorFrame, isHostedAreteEndpoint, isReplayErrorCode, isSafeClaimActionUrl, isSameProgramSdk, isSnapshotFrame, isStackVersionRefusalCode, isSubscribedFrame, isUnsubscribedFrame, isValidFrame, literal, managedAddress, managedContext, managedDiscovery, managedPage, managedReadOptions, managedU64, normalizeSubscription, normalizeSubscriptionQuery, normalizeSubscriptionRequest, normalizeTransactionError, parseApiProblem, parseFrame, parseFrameFromBlob, parseInstructionError, parseUiAmountToRaw, pda, prependFlowTransactionInstructions, prependTransactionInstructions, programAccountRead, programQuery, resolveAccounts, resolveAmount, resolveAmountToRaw, resolveAmountsToRaw, resolveTokenProgramAddress, resolveTransactionBuildOptions, safeToRawAmount, serializeInstructionData, serializeViewKey, setHostedWebsocketSuffixes, stackQuery, stringifyBigints, toJsonValue, toRawAmount, toWireResourceOptions, transactionOperation, unwrapOperationExecutionError, validateAccountResolution, validateProgramReadDescriptor, validateSubscriptionId, withProgramIdentity, withProgramRead, withPrograms };
|
|
8976
9099
|
//# sourceMappingURL=index.esm.js.map
|