@capxul/sdk-react 1.2.3 → 2.0.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.
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../errors/src/errors.ts","../../errors/src/convex-error-decoding.ts","../src/internal/require-bootstrapped-client.ts","../src/internal/unwrap-capxul-result.ts","../src/hooks/use-capxul-profile.ts","../src/hooks/use-capxul-account-balance.ts","../src/hooks/use-capxul-account-fund.ts","../src/hooks/use-capxul-sub-accounts.ts","../src/internal/invalidate-money-state.ts","../src/internal/reject-unresolved-actor.ts","../src/hooks/use-capxul-money.ts","../src/hooks/use-capxul-orgs.ts","../src/hooks/use-capxul-org-members.ts","../src/hooks/use-capxul-org-roles.ts","../src/hooks/use-capxul-org-deploy-roles.ts","../src/hooks/use-capxul-org-treasury.ts","../src/hooks/use-capxul-create-org.ts","../src/hooks/use-capxul-invite-member.ts","../src/hooks/use-capxul-remove-member.ts","../src/hooks/use-capxul-assign-role.ts","../src/headless/journey/journey-state.ts","../src/internal/use-debounced-value.ts","../src/headless/onboarding/use-capxul-username-availability.ts","../src/headless/media/use-capxul-image-upload.ts"],"sourcesContent":["// The canonical error-code catalog as a runtime constant. `CapxulErrorCode`\n// is derived from it so the type and any runtime check that needs to\n// enumerate codes (e.g. the convex-error codec's `KNOWN_CODES`) share a\n// single source of truth — a TypeScript union alone can't be introspected\n// at runtime, which previously forced a hand-maintained duplicate.\nexport const CAPXUL_ERROR_CODES = [\n \"NOT_AUTHENTICATED\",\n \"EMAIL_DELIVERY_FAILED\",\n \"PROFILE_NOT_FOUND\",\n \"SMART_ACCOUNT_MISSING\",\n \"PLAYER_NOT_FOUND\",\n \"ACCOUNT_NOT_FOUND\",\n \"PROVIDER_ERROR\",\n \"INVALID_INPUT\",\n \"ENV_MISSING\",\n \"NOT_IMPLEMENTED\",\n \"VERIFICATION_REQUIRED\",\n \"INSUFFICIENT_BALANCE\",\n \"INVALID_RECIPIENT\",\n \"ROLE_PERMISSION_DENIED\",\n \"TRANSACTION_FAILED\",\n \"RATE_LIMITED\",\n \"NETWORK_ERROR\",\n \"UNKNOWN\",\n \"OTP_EXPIRED\",\n \"SIGNER_REJECTED\",\n \"CANCELLED\",\n \"WRONG_STATE\",\n \"STALE_EPOCH\",\n \"SUPERSEDED\",\n \"WORK_DIED\",\n \"ACTOR_STOPPED\",\n] as const;\n\nexport type CapxulErrorCode = (typeof CAPXUL_ERROR_CODES)[number];\n\n/**\n * The error codes that represent an expected product outcome rather than a\n * defect. The SDK and backend observation boundaries both classify failures\n * against this set to route expected outcomes to their own PostHog event\n * stream; keeping the single copy here (adjacent to `CAPXUL_ERROR_CODES`, so a\n * code rename forces this set to move with it) stops the two sides of the wire\n * from drifting and silently splitting one outcome across two streams.\n */\nexport const EXPECTED_OPERATION_OUTCOMES: ReadonlySet<CapxulErrorCode> = new Set([\n \"INVALID_INPUT\",\n \"NOT_AUTHENTICATED\",\n // A user with no Safe yet — the normal post-OTP / pre-provision state. Reading\n // the account, current user, or balance in that window is an expected outcome,\n // not a defect, so both observation boundaries route it to their\n // `*_expected_outcome` stream instead of an unexpected `$exception` (#1031).\n \"SMART_ACCOUNT_MISSING\",\n \"CANCELLED\",\n \"SIGNER_REJECTED\",\n \"VERIFICATION_REQUIRED\",\n \"INSUFFICIENT_BALANCE\",\n \"INVALID_RECIPIENT\",\n \"ROLE_PERMISSION_DENIED\",\n \"RATE_LIMITED\",\n \"OTP_EXPIRED\",\n \"WRONG_STATE\",\n \"STALE_EPOCH\",\n \"SUPERSEDED\",\n \"ACTOR_STOPPED\",\n]);\n\n/**\n * Why an auth/provider call failed — a flat CAUSE enum. The *where* (which\n * OpenFort operation) stays in the separate `operation` detail field; this\n * names the root cause so a single `$exception` can be triaged without\n * parsing the message. Five members, no free strings:\n *\n * - `auth-origin-mismatch`: OTP cookies live on `localhost:PORT` but OpenFort\n * hits the Convex host → no session reaches the provider.\n * - `stale-openfort-cache`: an old `userId` in scoped storage makes the SDK\n * skip re-auth → 401 on `v2/accounts`.\n * - `app-env-allowlist`: the selected app/deployment origin is not allowlisted\n * → 401.\n * - `no-secure-context`: sandboxed/headless browser with no Web Crypto, so\n * `getAddress`/`configure` can never produce an address. Previously vanished\n * into `unknown`; the signer's secure-context probe now names it.\n * - `unknown`: catch-all when no cause could be determined.\n */\nexport type FailureMode =\n | \"auth-origin-mismatch\"\n | \"stale-openfort-cache\"\n | \"app-env-allowlist\"\n | \"no-secure-context\"\n | \"unknown\";\n\n/**\n * The one failure representation carried by domain state, actor work, and\n * public error projection. Keeping it beside the canonical error catalog\n * prevents a machine or shell from inventing a second code vocabulary.\n */\nexport interface Failure {\n readonly code: CapxulErrorCode;\n readonly message: string;\n readonly mode?: FailureMode;\n}\n\nexport type CapxulErrorDetails = Record<string, unknown>;\n\nexport type SignerSource = \"openfort-embedded\" | \"injected-eip1193\" | \"local-private-key\";\n\nexport type VerificationRequiredDetails =\n | { readonly requiredTier: number }\n | { readonly rail: string; readonly currentKind: string };\n\nexport type SerializedCapxulError = {\n readonly code: CapxulErrorCode;\n readonly message: string;\n readonly details?: CapxulErrorDetails;\n readonly correlationId?: string;\n readonly layer?: string;\n};\n\nexport type CapxulErrorOptions = {\n readonly cause?: unknown;\n readonly details?: CapxulErrorDetails;\n readonly correlationId?: string;\n readonly layer?: string;\n};\n\nexport class CapxulError extends Error {\n readonly code: CapxulErrorCode;\n readonly details?: CapxulErrorDetails;\n readonly correlationId?: string;\n readonly layer?: string;\n\n constructor(code: CapxulErrorCode, message: string, options: CapxulErrorOptions = {}) {\n super(message, \"cause\" in options ? { cause: options.cause } : undefined);\n this.name = \"CapxulError\";\n this.code = code;\n if (options.details !== undefined) {\n this.details = options.details;\n }\n if (options.correlationId !== undefined) {\n this.correlationId = options.correlationId;\n }\n if (options.layer !== undefined) {\n this.layer = options.layer;\n }\n }\n}\n\nexport function isCapxulError(value: unknown): value is CapxulError {\n return value instanceof CapxulError;\n}\n\nexport function serializeCapxulError(error: CapxulError): SerializedCapxulError {\n return compactSerialized({\n code: error.code,\n message: error.message,\n details: error.details,\n correlationId: error.correlationId,\n layer: error.layer,\n });\n}\n\nexport function deserializeCapxulError(serialized: SerializedCapxulError): CapxulError {\n return new CapxulError(\n serialized.code,\n serialized.message,\n compactErrorOptions({\n details: serialized.details,\n correlationId: serialized.correlationId,\n layer: serialized.layer,\n }),\n );\n}\n\nfunction compactSerialized(serialized: {\n readonly code: CapxulErrorCode;\n readonly message: string;\n readonly details: CapxulErrorDetails | undefined;\n readonly correlationId: string | undefined;\n readonly layer: string | undefined;\n}): SerializedCapxulError {\n const result: {\n code: CapxulErrorCode;\n message: string;\n details?: CapxulErrorDetails;\n correlationId?: string;\n layer?: string;\n } = {\n code: serialized.code,\n message: serialized.message,\n };\n\n if (serialized.details !== undefined) {\n result.details = serialized.details;\n }\n if (serialized.correlationId !== undefined) {\n result.correlationId = serialized.correlationId;\n }\n if (serialized.layer !== undefined) {\n result.layer = serialized.layer;\n }\n\n return result;\n}\n\nfunction compactErrorOptions(options: {\n readonly cause?: unknown;\n readonly details: CapxulErrorDetails | undefined;\n readonly correlationId: string | undefined;\n readonly layer: string | undefined;\n}): CapxulErrorOptions {\n const result: {\n cause?: unknown;\n details?: CapxulErrorDetails;\n correlationId?: string;\n layer?: string;\n } = {};\n\n if (\"cause\" in options) {\n result.cause = options.cause;\n }\n if (options.details !== undefined) {\n result.details = options.details;\n }\n if (options.correlationId !== undefined) {\n result.correlationId = options.correlationId;\n }\n if (options.layer !== undefined) {\n result.layer = options.layer;\n }\n\n return result;\n}\n\nexport const Errors = {\n notAuthenticated: (message?: string, opts?: { readonly failure_mode?: FailureMode }) =>\n new CapxulError(\n \"NOT_AUTHENTICATED\",\n message ?? \"Not authenticated\",\n opts?.failure_mode ? { details: { failure_mode: opts.failure_mode } } : undefined,\n ),\n emailDeliveryFailed: (detail: string) =>\n new CapxulError(\"EMAIL_DELIVERY_FAILED\", \"Failed to send email\", {\n details: { detail },\n }),\n\n profileNotFound: (authUserId: string) =>\n new CapxulError(\"PROFILE_NOT_FOUND\", `Profile not found for user ${authUserId}`, {\n details: { authUserId },\n }),\n\n smartAccountMissing: (authUserId: string) =>\n new CapxulError(\"SMART_ACCOUNT_MISSING\", \"Smart account not provisioned\", {\n details: { authUserId },\n }),\n\n playerNotFound: (playerId?: string) =>\n new CapxulError(\n \"PLAYER_NOT_FOUND\",\n playerId ? `Openfort player ${playerId} not found` : \"Openfort player not found\",\n playerId === undefined ? undefined : { details: { playerId } },\n ),\n\n accountNotFound: (accountId?: string) =>\n new CapxulError(\n \"ACCOUNT_NOT_FOUND\",\n accountId ? `Openfort account ${accountId} not found` : \"Openfort account not found\",\n accountId === undefined ? undefined : { details: { accountId } },\n ),\n\n providerError: (\n provider: string,\n operation: string,\n cause: unknown,\n opts?: { readonly failure_mode?: FailureMode },\n ) => {\n const details: Record<string, unknown> = { provider, operation };\n if (opts?.failure_mode) {\n details.failure_mode = opts.failure_mode;\n }\n return new CapxulError(\"PROVIDER_ERROR\", `Provider error: ${provider} ${operation}`, {\n cause,\n details,\n });\n },\n\n invalidInput: (field: string, reason: string) =>\n new CapxulError(\"INVALID_INPUT\", `Invalid ${field}: ${reason}`, {\n details: { field, reason },\n }),\n\n envMissing: (name: string) =>\n new CapxulError(\"ENV_MISSING\", `Environment variable ${name} not configured`, {\n details: { name },\n }),\n\n notImplemented: (domain: string, method: string) =>\n new CapxulError(\n \"NOT_IMPLEMENTED\",\n `${domain}.${method} is not yet implemented. This feature is planned for a future release.`,\n { details: { domain, method } },\n ),\n\n /**\n * Sibling factory to {@link Errors.providerError} for the per-state timeout\n * path in flows. Same `PROVIDER_ERROR` code as\n * `providerError`, plus a `details.reason: \"timeout\"` discriminator so\n * downstream observers can distinguish failure modes without parsing the\n * message string. The redacted message names the timeout budget; the\n * native `cause` carries the same information for `reportError` fidelity.\n */\n providerTimeout: (provider: string, operation: string, timeoutMs: number) =>\n new CapxulError(\n \"PROVIDER_ERROR\",\n `Provider error: ${provider} ${operation} (timeout exceeded ${timeoutMs}ms)`,\n {\n details: { provider, operation, reason: \"timeout\" },\n cause: new Error(`timeout: ${operation} exceeded ${timeoutMs}ms`),\n },\n ),\n\n verificationRequired: (details: VerificationRequiredDetails) => {\n const message =\n \"rail\" in details\n ? `Verification is required before ${details.rail} can use ${details.currentKind}.`\n : `Verification tier ${details.requiredTier} is required.`;\n\n return new CapxulError(\"VERIFICATION_REQUIRED\", message, {\n details,\n });\n },\n\n insufficientBalance: (asset: string, available: string, required: string) =>\n new CapxulError(\"INSUFFICIENT_BALANCE\", `Insufficient ${asset} balance`, {\n details: { asset, available, required },\n }),\n\n invalidRecipient: (reason: string) =>\n new CapxulError(\"INVALID_RECIPIENT\", `Invalid recipient: ${reason}`, {\n details: { reason },\n }),\n\n /**\n * The org Zodiac Roles modifier REFUSED the spend on-chain (G4 · #547): the\n * member's role condition (per-tx cap, per-day allowance, allowed recipient,\n * or membership) was violated, so `execTransactionWithRole` reverted. This is\n * a PERMISSION denial — explicitly NOT an `INSUFFICIENT_BALANCE` (the treasury\n * held the funds; the role's authority is what bound). `reason` discriminates\n * the violated condition (`over_cap` / `daily_cap` / `not_member` /\n * `disallowed_recipient` / `condition_violation`); leak-safe — no on-chain\n * identifiers ever enter the details.\n */\n rolePermissionDenied: (details: {\n readonly reason:\n | \"over_cap\"\n | \"daily_cap\"\n | \"not_member\"\n | \"disallowed_recipient\"\n | \"condition_violation\";\n readonly operation?: string;\n }) =>\n new CapxulError(\n \"ROLE_PERMISSION_DENIED\",\n `Org role denied this spend on-chain (${details.reason}).`,\n {\n details:\n details.operation === undefined\n ? { reason: details.reason }\n : { reason: details.reason, operation: details.operation },\n },\n ),\n\n /**\n * A transaction (or sponsored UserOp) failed. `details.reason` discriminates\n * the failure mode for callers that must distinguish a CONFIRMED on-chain\n * revert (`\"onchain_revert\"` — the op executed and reverted, e.g. a Zodiac\n * Roles condition violation) from an inconclusive infra failure. A confirmed\n * revert is the ONLY mode the org spend port may map to a roles denial.\n */\n transactionFailed: (operation: string, cause?: unknown, extra?: { readonly reason?: string }) =>\n new CapxulError(\"TRANSACTION_FAILED\", `Transaction failed: ${operation}`, {\n cause,\n details: extra?.reason === undefined ? { operation } : { operation, reason: extra.reason },\n }),\n\n rateLimited: (details?: { readonly retryAfterMs?: number; readonly resource?: string }) =>\n new CapxulError(\n \"RATE_LIMITED\",\n \"Rate limit exceeded\",\n details === undefined ? undefined : { details: { ...details } },\n ),\n\n networkError: (operation: string, cause?: unknown) =>\n new CapxulError(\"NETWORK_ERROR\", `Network error during ${operation}`, {\n cause,\n details: { operation },\n }),\n\n unknown: (cause?: unknown) => new CapxulError(\"UNKNOWN\", \"Unknown error\", { cause }),\n\n otpExpired: (details?: { readonly email?: string; readonly expiredAt?: number }) =>\n new CapxulError(\n \"OTP_EXPIRED\",\n \"Verification code has expired. Request a new one.\",\n details === undefined ? undefined : { details: { ...details } },\n ),\n\n signerRejected: (details: {\n readonly source: SignerSource;\n readonly reason?: string;\n readonly cause?: unknown;\n }) =>\n new CapxulError(\"SIGNER_REJECTED\", \"Signer rejected the request.\", {\n cause: details.cause,\n details:\n details.reason === undefined\n ? { source: details.source }\n : { source: details.source, reason: details.reason },\n }),\n\n cancelled: (details?: { readonly operation?: string; readonly reason?: string }) =>\n new CapxulError(\n \"CANCELLED\",\n \"Operation was cancelled.\",\n details === undefined ? undefined : { details: { ...details } },\n ),\n\n /**\n * Method called from a flow state where its precondition fails (TA16). The\n * SDK's method API short-circuits with this error before driving the\n * internal state machine. `currentState` is the Effect-machine snapshot\n * tag (stringified from the SDK's actor-shell snapshot; see\n * `packages/errors/CONTEXT.md`); `validStates`\n * enumerates the states the method accepts.\n */\n wrongState: (details: {\n readonly method: string;\n readonly currentState: string;\n readonly validStates: readonly string[];\n }) =>\n new CapxulError(\n \"WRONG_STATE\",\n `${details.method} called from state '${details.currentState}'; valid states: ${details.validStates.join(\", \")}`,\n { details: { ...details, validStates: [...details.validStates] } },\n ),\n} as const;\n","// Shared `decodeConvexError` helper (TA5) — used by both the SDK's\n// `ConvexCallAdapter.mapToCapxulError` AND the backend `credentials/http.ts`\n// `bootstrapClient` handler. Single source of truth for cross-Convex-boundary\n// error decoding rules.\n//\n// Recognizes the `ConvexError(SerializedCapxulError)` object-shape produced by\n// `withErrorBoundary` (Probe B finding, 2026-05-19):\n//\n// { name: \"ConvexError\", data: { code, message, details?, correlationId?, layer? } }\n//\n// AND the defensive string-shape branch for older Convex versions where\n// `data` is a JSON-serialized string. Pass-through for raw `CapxulError`\n// instances (which arrive directly when the throw happened in the same\n// V8 isolate as the catch). Returns null when the value is not a\n// recognizable shape — the caller falls back to NETWORK_ERROR + reportError.\n\nimport {\n CAPXUL_ERROR_CODES,\n CapxulError,\n type CapxulErrorCode,\n type SerializedCapxulError,\n deserializeCapxulError,\n} from \"./errors.ts\";\n\n// Derived from the canonical catalog in errors.ts — single source of truth,\n// so a new code added to `CAPXUL_ERROR_CODES` is recognized here automatically.\nconst KNOWN_CODES: ReadonlySet<CapxulErrorCode> = new Set(CAPXUL_ERROR_CODES);\n\nfunction isCapxulCode(value: unknown): value is CapxulErrorCode {\n return typeof value === \"string\" && KNOWN_CODES.has(value as CapxulErrorCode);\n}\n\nfunction reconstruct(serialized: Record<string, unknown>): CapxulError | null {\n if (!isCapxulCode(serialized.code)) return null;\n const payload: SerializedCapxulError = {\n code: serialized.code,\n message: typeof serialized.message === \"string\" ? serialized.message : String(serialized.code),\n ...(typeof serialized.details === \"object\" &&\n serialized.details !== null &&\n !Array.isArray(serialized.details)\n ? { details: serialized.details as Record<string, unknown> }\n : {}),\n ...(typeof serialized.correlationId === \"string\"\n ? { correlationId: serialized.correlationId }\n : {}),\n ...(typeof serialized.layer === \"string\" ? { layer: serialized.layer } : {}),\n };\n return deserializeCapxulError(payload);\n}\n\nexport function decodeConvexError(err: unknown): CapxulError | null {\n if (err === null || err === undefined) return null;\n\n // Pass-through: same isolate, real CapxulError instance.\n if (err instanceof CapxulError) return err;\n\n if (typeof err !== \"object\") return null;\n\n // The canonical shape produced by `withErrorBoundary` then crossed by\n // Convex's `ctx.runQuery` / `ConvexHttpClient`: a `ConvexError` whose\n // `data` is the `SerializedCapxulError` object literal.\n const record = err as Record<string, unknown>;\n if (!(\"data\" in record)) return null;\n const data = record.data;\n\n if (typeof data === \"object\" && data !== null) {\n return reconstruct(data as Record<string, unknown>);\n }\n\n // Defensive depth — some Convex versions JSON-stringify the data at\n // the runtime boundary. Probe B confirmed @convex-dev/better-auth 0.10.13\n // + convex 1.39.x do NOT do this, but the cheap parse keeps forward\n // compatibility.\n if (typeof data === \"string\") {\n try {\n const parsed = JSON.parse(data) as unknown;\n if (typeof parsed === \"object\" && parsed !== null) {\n return reconstruct(parsed as Record<string, unknown>);\n }\n } catch {\n // Fall through.\n }\n }\n\n return null;\n}\n","import { Errors } from \"@capxul/errors\";\nimport type { CapxulClient } from \"@capxul/sdk\";\n\n/**\n * Narrow the bootstrap-nullable client to a ready client inside a query /\n * mutation function (sdk-provider-owned-bootstrap.md). Data hooks gate their\n * queries on `enabled: client !== null`, so this only ever throws for a mutation\n * triggered while `<CapxulProvider>` is still bootstrapping.\n */\nexport function requireBootstrappedClient(\n client: CapxulClient | null,\n method: string,\n): CapxulClient {\n if (client === null) {\n throw Errors.wrongState({ method, currentState: \"bootstrapping\", validStates: [\"ready\"] });\n }\n return client;\n}\n","import type { TelemetryPort } from \"@capxul/sdk\";\nimport type { CapxulResult } from \"@capxul/sdk\";\n\n/**\n * Unwrap a `CapxulResult` for TanStack query/mutation functions and throw into\n * React Query's error path.\n *\n * Failure observation belongs to the core SDK method boundary. The legacy\n * telemetry/operation arguments remain temporarily source-compatible with the\n * existing hook call sites, but are deliberately ignored so React cannot\n * report the same logical failure a second time.\n */\nexport function unwrapCapxulResult<T>(\n result: CapxulResult<T>,\n _legacyTelemetry?: TelemetryPort,\n _legacyOperation: \"query\" | \"mutation\" = \"query\",\n): T {\n if (result.ok) {\n return result.value;\n }\n throw result.error;\n}\n","\"use client\";\n\nimport { useQuery, type UseQueryResult } from \"@tanstack/react-query\";\n\nimport type { CapxulError, Profile } from \"@capxul/sdk\";\n\nimport { useCapxulClientOrNull } from \"../internal/capxul-client-context\";\nimport { requireBootstrappedClient } from \"../internal/require-bootstrapped-client\";\nimport { capxulKeys } from \"../internal/reactivity-keys\";\nimport { unwrapCapxulResult } from \"../internal/unwrap-capxul-result\";\nimport { useCapxulIdentityOrNull } from \"../identity\";\n\nexport type UseCapxulProfileReturn = UseQueryResult<Profile | null, CapxulError>;\n\nexport function useCapxulProfile(): UseCapxulProfileReturn {\n const client = useCapxulClientOrNull();\n const identity = useCapxulIdentityOrNull();\n return useQuery({\n queryKey: capxulKeys.profile,\n queryFn: async () =>\n unwrapCapxulResult(\n await requireBootstrappedClient(client, \"identity.loadCurrent\").identity.loadCurrent(),\n client!._internal.telemetry,\n ),\n // loadCurrent answers null while the auth session snapshot is still\n // restoring — indistinguishable from \"no profile\". Fetching before the\n // session is restored caches that null for the whole page lifetime.\n enabled: client !== null && identity?.phase === \"authenticated\",\n });\n}\n","\"use client\";\n\nimport { useQuery, type UseQueryResult } from \"@tanstack/react-query\";\n\nimport type { Account, CapxulError } from \"@capxul/sdk\";\n\nimport { useCapxulClientOrNull } from \"../internal/capxul-client-context\";\nimport { requireBootstrappedClient } from \"../internal/require-bootstrapped-client\";\nimport { capxulKeys } from \"../internal/reactivity-keys\";\nimport { unwrapCapxulResult } from \"../internal/unwrap-capxul-result\";\n\nexport type UseCapxulAccountBalanceReturn = UseQueryResult<Account, CapxulError>;\n\nexport type UseCapxulAccountBalanceOptions = {\n /** When false, skips the Convex readBalance action until the account ladder is ready. */\n readonly enabled?: boolean;\n};\n\nexport function useCapxulAccountBalance(\n options?: UseCapxulAccountBalanceOptions,\n): UseCapxulAccountBalanceReturn {\n const client = useCapxulClientOrNull();\n return useQuery({\n queryKey: capxulKeys.accountBalance,\n queryFn: async () => {\n const bootstrappedClient = requireBootstrappedClient(client, \"accounts.read\");\n return unwrapCapxulResult(\n await bootstrappedClient.accounts.read(),\n bootstrappedClient._internal.telemetry,\n );\n },\n enabled: client !== null && (options?.enabled ?? true),\n });\n}\n","\"use client\";\n\nimport { useMutation, useQueryClient, type UseMutationResult } from \"@tanstack/react-query\";\n\nimport { useCapxulClientOrNull } from \"../internal/capxul-client-context\";\nimport { requireBootstrappedClient } from \"../internal/require-bootstrapped-client\";\nimport { capxulKeys } from \"../internal/reactivity-keys\";\nimport { unwrapCapxulResult } from \"../internal/unwrap-capxul-result\";\nimport type { CapxulError, Money } from \"@capxul/sdk\";\n\nexport type UseCapxulAccountFundReturn = UseMutationResult<\n { readonly txHash: string },\n CapxulError,\n Money\n>;\n\nexport function useCapxulAccountFund(): UseCapxulAccountFundReturn {\n const client = useCapxulClientOrNull();\n const queryClient = useQueryClient();\n return useMutation({\n mutationFn: async (amount: Money) => {\n const bootstrappedClient = requireBootstrappedClient(client, \"_internal.accounts.fund\");\n return unwrapCapxulResult(\n await bootstrappedClient._internal.accounts.fund(amount),\n bootstrappedClient._internal.telemetry,\n \"mutation\",\n );\n },\n onSuccess: async () => {\n await queryClient.invalidateQueries({ queryKey: capxulKeys.accountBalance });\n },\n });\n}\n","\"use client\";\n\nimport {\n useMutation,\n useQuery,\n useQueryClient,\n type UseMutationResult,\n type UseQueryResult,\n} from \"@tanstack/react-query\";\n\nimport { Errors } from \"@capxul/errors\";\nimport type {\n AccountId,\n CapxulError,\n SubAccount,\n SubAccountId,\n TransferInput,\n TransferResult,\n} from \"@capxul/sdk\";\n\nimport { useCapxulClientOrNull } from \"../internal/capxul-client-context\";\nimport { requireBootstrappedClient } from \"../internal/require-bootstrapped-client\";\nimport { capxulKeys } from \"../internal/reactivity-keys\";\nimport { unwrapCapxulResult } from \"../internal/unwrap-capxul-result\";\n\nexport type UseCapxulSubAccountsListOptions = {\n readonly enabled?: boolean;\n};\n\nexport type UseCapxulSubAccountsListReturn = UseQueryResult<readonly SubAccount[], CapxulError>;\n\nexport function useCapxulSubAccountsList(\n accountId: AccountId | undefined,\n options?: UseCapxulSubAccountsListOptions,\n): UseCapxulSubAccountsListReturn {\n const client = useCapxulClientOrNull();\n return useQuery({\n queryKey: capxulKeys.subAccounts(accountId),\n queryFn: async () => {\n if (accountId === undefined) {\n throw Errors.invalidInput(\"accountId\", \"required for subAccounts.list\");\n }\n const bootstrappedClient = requireBootstrappedClient(client, \"subAccounts.list\");\n return unwrapCapxulResult(\n await bootstrappedClient.subAccounts.list(accountId),\n bootstrappedClient._internal.telemetry,\n );\n },\n enabled: client !== null && (options?.enabled ?? true) && accountId !== undefined,\n });\n}\n\nexport type UseCapxulSubAccountCreateReturn = UseMutationResult<\n SubAccount,\n CapxulError,\n { readonly accountId: AccountId; readonly name: string }\n>;\n\nexport function useCapxulSubAccountCreate(): UseCapxulSubAccountCreateReturn {\n const client = useCapxulClientOrNull();\n const queryClient = useQueryClient();\n return useMutation({\n mutationFn: async (input) => {\n const bootstrappedClient = requireBootstrappedClient(client, \"subAccounts.create\");\n return unwrapCapxulResult(\n await bootstrappedClient.subAccounts.create(input.accountId, { name: input.name }),\n bootstrappedClient._internal.telemetry,\n \"mutation\",\n );\n },\n onSuccess: async (_value, variables) => {\n await queryClient.invalidateQueries({\n queryKey: capxulKeys.subAccounts(variables.accountId),\n });\n await queryClient.invalidateQueries({ queryKey: capxulKeys.accountBalance });\n },\n });\n}\n\nexport type UseCapxulSubAccountRenameReturn = UseMutationResult<\n SubAccount,\n CapxulError,\n { readonly accountId: AccountId; readonly subAccountId: SubAccountId; readonly name: string }\n>;\n\nexport function useCapxulSubAccountRename(): UseCapxulSubAccountRenameReturn {\n const client = useCapxulClientOrNull();\n const queryClient = useQueryClient();\n return useMutation({\n mutationFn: async (input) => {\n const bootstrappedClient = requireBootstrappedClient(client, \"subAccounts.rename\");\n return unwrapCapxulResult(\n await bootstrappedClient.subAccounts.rename(input.subAccountId, input.name),\n bootstrappedClient._internal.telemetry,\n \"mutation\",\n );\n },\n onSuccess: async (_value, variables) => {\n await queryClient.invalidateQueries({\n queryKey: capxulKeys.subAccounts(variables.accountId),\n });\n await queryClient.invalidateQueries({ queryKey: capxulKeys.accountBalance });\n },\n });\n}\n\nexport type UseCapxulSubAccountDeleteReturn = UseMutationResult<\n void,\n CapxulError,\n { readonly accountId: AccountId; readonly subAccountId: SubAccountId }\n>;\n\nexport function useCapxulSubAccountDelete(): UseCapxulSubAccountDeleteReturn {\n const client = useCapxulClientOrNull();\n const queryClient = useQueryClient();\n return useMutation({\n mutationFn: async (input) => {\n const bootstrappedClient = requireBootstrappedClient(client, \"subAccounts.delete\");\n return unwrapCapxulResult(\n await bootstrappedClient.subAccounts.delete(input.subAccountId),\n bootstrappedClient._internal.telemetry,\n \"mutation\",\n );\n },\n onSuccess: async (_value, variables) => {\n await queryClient.invalidateQueries({\n queryKey: capxulKeys.subAccounts(variables.accountId),\n });\n await queryClient.invalidateQueries({ queryKey: capxulKeys.accountBalance });\n },\n });\n}\n\n/**\n * Move money between two of the SAME Account's balances (canon §5/§12). The\n * consumer-facing labels are \"Add money\" (main → sub) and \"Move money out\"\n * (sub → main), both calling `transfer`. `accountId` is carried only to\n * invalidate the right cache keys; the SDK input itself is `{ from, to, amount }`.\n */\nexport type UseCapxulTransferReturn = UseMutationResult<\n TransferResult,\n CapxulError,\n { readonly accountId: AccountId } & TransferInput\n>;\n\nexport function useCapxulTransfer(): UseCapxulTransferReturn {\n const client = useCapxulClientOrNull();\n const queryClient = useQueryClient();\n return useMutation({\n mutationFn: async ({ from, to, amount }) => {\n const bootstrappedClient = requireBootstrappedClient(client, \"subAccounts.transfer\");\n return unwrapCapxulResult(\n await bootstrappedClient.subAccounts.transfer({ from, to, amount }),\n bootstrappedClient._internal.telemetry,\n \"mutation\",\n );\n },\n onSuccess: async (_value, variables) => {\n await queryClient.invalidateQueries({\n queryKey: capxulKeys.subAccounts(variables.accountId),\n });\n await queryClient.invalidateQueries({ queryKey: capxulKeys.accountBalance });\n },\n });\n}\n","import type { QueryClient } from \"@tanstack/react-query\";\n\nimport type { ActorReference, OrgId, Payment } from \"@capxul/sdk\";\n\nimport { capxulKeys } from \"./reactivity-keys\";\n\n/**\n * Actor scope a money mutation settled under.\n *\n * #1145 (DEMOLITION §D5): the insights, address-book and org-`account`\n * invalidations this used to fan out to named queries that no hook creates any\n * more — the actor-scope family and `useCapxulOrganizationAccount` are deleted.\n * Invalidating a key nothing reads is a no-op that reads as coverage.\n */\ntype MoneyActorScope =\n | { readonly kind: \"account\" }\n | { readonly kind: \"org\"; readonly orgId: string }\n | ActorReference;\n\nexport function isPayment(value: unknown): value is Payment {\n if (typeof value !== \"object\" || value === null) return false;\n const record = value as Record<string, unknown>;\n return (\n typeof record.id === \"string\" &&\n typeof record.status === \"string\" &&\n typeof record.paymentType === \"string\" &&\n typeof record.amount === \"object\" &&\n record.amount !== null\n );\n}\n\nexport function paymentsFromValue(value: unknown): readonly Payment[] {\n if (Array.isArray(value)) return value.filter(isPayment);\n if (isPayment(value)) return [value];\n if (typeof value !== \"object\" || value === null) return [];\n const payments = (value as Record<string, unknown>).payments;\n return Array.isArray(payments) ? payments.filter(isPayment) : [];\n}\n\nexport async function invalidateMoneyState(\n queryClient: QueryClient,\n input: {\n readonly actor: MoneyActorScope;\n readonly payment?: Payment;\n },\n): Promise<void> {\n const invalidations = [queryClient.invalidateQueries({ queryKey: capxulKeys.payments })];\n\n if (input.payment !== undefined) {\n invalidations.push(\n queryClient.invalidateQueries({ queryKey: capxulKeys.payment(input.payment.id) }),\n );\n }\n\n if (input.actor.kind === \"account\" || input.actor.kind === \"personal\") {\n invalidations.push(queryClient.invalidateQueries({ queryKey: capxulKeys.accountBalance }));\n } else {\n const orgId = (\n input.actor.kind === \"org\" ? input.actor.orgId : input.actor.organizationId\n ) as OrgId;\n invalidations.push(queryClient.invalidateQueries({ queryKey: capxulKeys.orgTreasury(orgId) }));\n }\n\n await Promise.all(invalidations);\n}\n","import { Errors } from \"@capxul/errors\";\n\n/**\n * Guard for mutation hooks whose variables carry an optional `actor` field\n * (`useCapxulPay`, `useCapxulPayout`, `useCapxulAddDestination`,\n * `useCapxulRemoveDestination`). Mirrors `requireActorScope` on the query path:\n * an EXPLICITLY-passed `actor: undefined` (the `capxulOrgScope(notYetLoadedOrgId)`\n * footgun) must fail loudly rather than silently fall back to the personal\n * scope. Omitting the `actor` key entirely keeps the personal-scope default.\n *\n * Throws `CapxulError` code `INVALID_INPUT` with `details.field === \"actor\"`;\n * called inside an async mutationFn it surfaces as `mutation.error: CapxulError`.\n */\nexport function rejectUnresolvedActor(variables: object, operation: string): void {\n if (\n Object.hasOwn(variables, \"actor\") &&\n (variables as { readonly actor?: unknown }).actor === undefined\n ) {\n throw Errors.invalidInput(\n \"actor\",\n `explicitly provided but undefined for ${operation} — actor scope not yet resolved; omit actor for the personal scope`,\n );\n }\n}\n","\"use client\";\n\nimport {\n useMutation,\n useQuery,\n useQueryClient,\n type UseMutationResult,\n type UseQueryResult,\n} from \"@tanstack/react-query\";\n\nimport { Errors } from \"@capxul/errors\";\nimport type {\n Payment,\n PaymentsPayInput,\n PaymentsPayoutInput,\n PaymentsWithdrawInput,\n} from \"@capxul/sdk\";\nimport type { CapxulError } from \"@capxul/sdk\";\n\nimport { useCapxulClientOrNull } from \"../internal/capxul-client-context\";\nimport { invalidateMoneyState } from \"../internal/invalidate-money-state\";\nimport { rejectUnresolvedActor } from \"../internal/reject-unresolved-actor\";\nimport { requireBootstrappedClient } from \"../internal/require-bootstrapped-client\";\nimport { capxulKeys } from \"../internal/reactivity-keys\";\nimport { unwrapCapxulResult } from \"../internal/unwrap-capxul-result\";\n\nexport type UseCapxulPayReturn = UseMutationResult<Payment, CapxulError, PaymentsPayInput>;\nexport function useCapxulPay(): UseCapxulPayReturn {\n const client = useCapxulClientOrNull();\n const queryClient = useQueryClient();\n return useMutation({\n mutationFn: async (input) => {\n rejectUnresolvedActor(input, \"payments.pay\");\n const bootstrappedClient = requireBootstrappedClient(client, \"payments.pay\");\n return unwrapCapxulResult(\n await bootstrappedClient.payments.pay(input),\n bootstrappedClient._internal.telemetry,\n \"mutation\",\n );\n },\n onSuccess: async (payment) => {\n await invalidateMoneyState(queryClient, { actor: { kind: \"personal\" }, payment });\n },\n });\n}\n\nexport type UseCapxulPayoutReturn = UseMutationResult<Payment, CapxulError, PaymentsPayoutInput>;\nexport function useCapxulPayout(): UseCapxulPayoutReturn {\n const client = useCapxulClientOrNull();\n const queryClient = useQueryClient();\n return useMutation({\n mutationFn: async (input) => {\n rejectUnresolvedActor(input, \"payments.payout\");\n const bootstrappedClient = requireBootstrappedClient(client, \"payments.payout\");\n return unwrapCapxulResult(\n await bootstrappedClient.payments.payout(input),\n bootstrappedClient._internal.telemetry,\n \"mutation\",\n );\n },\n onSuccess: async (payment, variables) => {\n const actor = variables.actor ?? { kind: \"personal\" as const };\n await invalidateMoneyState(queryClient, { actor, payment });\n },\n });\n}\n\nexport type UseCapxulWithdrawReturn = UseMutationResult<\n Payment,\n CapxulError,\n PaymentsWithdrawInput\n>;\nexport function useCapxulWithdraw(): UseCapxulWithdrawReturn {\n const client = useCapxulClientOrNull();\n const queryClient = useQueryClient();\n return useMutation({\n mutationFn: async (input) => {\n const bootstrappedClient = requireBootstrappedClient(client, \"payments.withdraw\");\n return unwrapCapxulResult(\n await bootstrappedClient.payments.withdraw(input),\n bootstrappedClient._internal.telemetry,\n \"mutation\",\n );\n },\n onSuccess: async (payment) => {\n await invalidateMoneyState(queryClient, { actor: { kind: \"personal\" }, payment });\n },\n });\n}\n\nexport type UseCapxulPaymentsReturn = UseQueryResult<readonly Payment[], CapxulError>;\nexport function useCapxulPayments(options?: {\n readonly enabled?: boolean;\n}): UseCapxulPaymentsReturn {\n const client = useCapxulClientOrNull();\n return useQuery({\n queryKey: capxulKeys.payments,\n queryFn: async () => {\n const bootstrappedClient = requireBootstrappedClient(client, \"payments.list\");\n return unwrapCapxulResult(\n await bootstrappedClient.payments.list(),\n bootstrappedClient._internal.telemetry,\n );\n },\n enabled: client !== null && (options?.enabled ?? true),\n });\n}\n\nexport type UseCapxulPaymentReturn = UseQueryResult<Payment | null, CapxulError>;\nexport function useCapxulPayment(\n paymentId: string | undefined,\n options?: { readonly enabled?: boolean },\n): UseCapxulPaymentReturn {\n const client = useCapxulClientOrNull();\n return useQuery({\n queryKey: capxulKeys.payment(paymentId),\n queryFn: async () => {\n if (paymentId === undefined)\n throw Errors.invalidInput(\"paymentId\", \"required for payments.get\");\n const bootstrappedClient = requireBootstrappedClient(client, \"payments.get\");\n return unwrapCapxulResult(\n await bootstrappedClient.payments.get(paymentId),\n bootstrappedClient._internal.telemetry,\n );\n },\n enabled: client !== null && paymentId !== undefined && (options?.enabled ?? true),\n });\n}\n","\"use client\";\n\nimport { useQuery, type UseQueryResult } from \"@tanstack/react-query\";\n\nimport type { CapxulError, OrgView } from \"@capxul/sdk\";\n\nimport { useCapxulClientOrNull } from \"../internal/capxul-client-context\";\nimport { requireBootstrappedClient } from \"../internal/require-bootstrapped-client\";\nimport { capxulKeys } from \"../internal/reactivity-keys\";\nimport { unwrapCapxulResult } from \"../internal/unwrap-capxul-result\";\n\n/**\n * List the Orgs you belong to (canon §C1 \"Org list\" / §C3). Binds directly to\n * the locked `capxul.orgs()` SDK method.\n */\nexport type UseCapxulOrgsReturn = UseQueryResult<readonly OrgView[], CapxulError>;\n\nexport type UseCapxulOrgsOptions = {\n /**\n * Gate the query on auth readiness. `client.orgs()` is a session-scoped\n * authenticated read; firing it before the session token settles surfaces a\n * spurious `NOT_AUTHENTICATED`. Consumers pass `enabled: <auth-ready>` (e.g.\n * \"the Organization surface is active\") — mirrors `useCapxulSubAccountsList`.\n * Defaults to `true` to preserve the bare `useCapxulOrgs()` call shape.\n */\n readonly enabled?: boolean;\n};\n\nexport function useCapxulOrgs(options?: UseCapxulOrgsOptions): UseCapxulOrgsReturn {\n const client = useCapxulClientOrNull();\n return useQuery({\n queryKey: capxulKeys.orgs,\n queryFn: async () => {\n const bootstrappedClient = requireBootstrappedClient(client, \"orgs\");\n return unwrapCapxulResult(\n await bootstrappedClient.orgs(),\n bootstrappedClient._internal.telemetry,\n );\n },\n enabled: client !== null && (options?.enabled ?? true),\n });\n}\n","\"use client\";\n\nimport { useQuery, type UseQueryResult } from \"@tanstack/react-query\";\n\nimport { Errors } from \"@capxul/errors\";\nimport type { CapxulError, MemberView, OrgId } from \"@capxul/sdk\";\n\nimport { useCapxulClientOrNull } from \"../internal/capxul-client-context\";\nimport { capxulKeys } from \"../internal/reactivity-keys\";\nimport { requireBootstrappedClient } from \"../internal/require-bootstrapped-client\";\nimport { unwrapCapxulResult } from \"../internal/unwrap-capxul-result\";\n\nexport type UseCapxulOrgMembersOptions = {\n readonly enabled?: boolean;\n};\n\n/**\n * The members of an Org (canon §C1 \"Members\" / §C3, D8/D9). Binds directly to\n * the entity-scoped `capxul.org(orgId).members()` (D13). Gated by\n * `orgId !== undefined`; callers may additionally gate on canonical identity\n * readiness through `options.enabled`.\n */\nexport type UseCapxulOrgMembersReturn = UseQueryResult<readonly MemberView[], CapxulError>;\n\nexport function useCapxulOrgMembers(\n orgId: OrgId | undefined,\n options?: UseCapxulOrgMembersOptions,\n): UseCapxulOrgMembersReturn {\n const client = useCapxulClientOrNull();\n const enabled = options?.enabled ?? true;\n return useQuery({\n queryKey: capxulKeys.orgMembers(orgId),\n queryFn: async () => {\n if (orgId === undefined) {\n throw Errors.invalidInput(\"orgId\", \"required for useCapxulOrgMembers\");\n }\n const bootstrappedClient = requireBootstrappedClient(client, \"org.members\");\n return unwrapCapxulResult(\n await bootstrappedClient.org(orgId).members(),\n bootstrappedClient._internal.telemetry,\n );\n },\n enabled: client !== null && enabled && orgId !== undefined,\n });\n}\n","\"use client\";\n\nimport { useQuery, type UseQueryResult } from \"@tanstack/react-query\";\n\nimport { Errors } from \"@capxul/errors\";\nimport type { CapxulError, OrgId, RoleView } from \"@capxul/sdk\";\n\nimport { useCapxulClientOrNull } from \"../internal/capxul-client-context\";\nimport { capxulKeys } from \"../internal/reactivity-keys\";\nimport { requireBootstrappedClient } from \"../internal/require-bootstrapped-client\";\nimport { unwrapCapxulResult } from \"../internal/unwrap-capxul-result\";\n\nexport type UseCapxulOrgRolesOptions = {\n readonly enabled?: boolean;\n};\n\n/**\n * The roles seeded on an Org (canon §C1 \"Roles\" / §C3, D4/D6). Binds directly\n * to the entity-scoped `capxul.org(orgId).roles()` (D13). Gated by\n * `orgId !== undefined`. RED until S2.\n */\nexport type UseCapxulOrgRolesReturn = UseQueryResult<readonly RoleView[], CapxulError>;\n\nexport function useCapxulOrgRoles(\n orgId: OrgId | undefined,\n options?: UseCapxulOrgRolesOptions,\n): UseCapxulOrgRolesReturn {\n const client = useCapxulClientOrNull();\n const enabled = options?.enabled ?? true;\n return useQuery({\n queryKey: capxulKeys.orgRoles(orgId),\n queryFn: async () => {\n if (orgId === undefined) {\n throw Errors.invalidInput(\"orgId\", \"required for useCapxulOrgRoles\");\n }\n const bootstrappedClient = requireBootstrappedClient(client, \"org.roles\");\n return unwrapCapxulResult(\n await bootstrappedClient.org(orgId).roles(),\n bootstrappedClient._internal.telemetry,\n );\n },\n enabled: client !== null && enabled && orgId !== undefined,\n });\n}\n","\"use client\";\n\nimport { useMutation, useQueryClient, type UseMutationResult } from \"@tanstack/react-query\";\n\nimport type { CapxulError, OrgId, RoleView } from \"@capxul/sdk\";\n\nimport { useCapxulClientOrNull } from \"../internal/capxul-client-context\";\nimport { capxulKeys } from \"../internal/reactivity-keys\";\nimport { requireBootstrappedClient } from \"../internal/require-bootstrapped-client\";\nimport { unwrapCapxulResult } from \"../internal/unwrap-capxul-result\";\n\nexport type UseCapxulOrgDeployRolesReturn = UseMutationResult<\n readonly RoleView[],\n CapxulError,\n OrgId\n>;\n\nexport function useCapxulOrgDeployRoles(): UseCapxulOrgDeployRolesReturn {\n const client = useCapxulClientOrNull();\n const queryClient = useQueryClient();\n return useMutation({\n mutationFn: async (orgId: OrgId) => {\n const bootstrappedClient = requireBootstrappedClient(client, \"org.deployRoles\");\n return unwrapCapxulResult(\n await bootstrappedClient.org(orgId).deployRoles(),\n bootstrappedClient._internal.telemetry,\n \"mutation\",\n );\n },\n onSuccess: async (_roles, orgId) => {\n await queryClient.invalidateQueries({ queryKey: capxulKeys.orgRoles(orgId) });\n await queryClient.invalidateQueries({ queryKey: capxulKeys.org(orgId) });\n await queryClient.invalidateQueries({ queryKey: capxulKeys.orgs });\n },\n });\n}\n","\"use client\";\n\nimport { useQuery, type UseQueryResult } from \"@tanstack/react-query\";\n\nimport { Errors } from \"@capxul/errors\";\nimport type { Account, CapxulError, OrgId } from \"@capxul/sdk\";\n\nimport { useCapxulClientOrNull } from \"../internal/capxul-client-context\";\nimport { capxulKeys } from \"../internal/reactivity-keys\";\nimport { requireBootstrappedClient } from \"../internal/require-bootstrapped-client\";\nimport { unwrapCapxulResult } from \"../internal/unwrap-capxul-result\";\n\nexport type UseCapxulOrgTreasuryOptions = {\n readonly enabled?: boolean;\n};\n\n/**\n * The Org treasury — the real M2 `Account` over the Org Safe (canon §C3, D3).\n * NEVER `AccountStatus` (the deploy-readiness ladder, no balance). Binds\n * directly to the entity-scoped `capxul.org(orgId).treasury()` (D13). Gated by\n * `orgId !== undefined`. RED until S1.\n */\nexport type UseCapxulOrgTreasuryReturn = UseQueryResult<Account, CapxulError>;\n\nexport function useCapxulOrgTreasury(\n orgId: OrgId | undefined,\n options?: UseCapxulOrgTreasuryOptions,\n): UseCapxulOrgTreasuryReturn {\n const client = useCapxulClientOrNull();\n const enabled = options?.enabled ?? true;\n return useQuery({\n queryKey: capxulKeys.orgTreasury(orgId),\n queryFn: async () => {\n if (orgId === undefined) {\n throw Errors.invalidInput(\"orgId\", \"required for useCapxulOrgTreasury\");\n }\n const bootstrappedClient = requireBootstrappedClient(client, \"org.treasury\");\n return unwrapCapxulResult(\n await bootstrappedClient.org(orgId).treasury(),\n bootstrappedClient._internal.telemetry,\n );\n },\n enabled: client !== null && enabled && orgId !== undefined,\n });\n}\n","\"use client\";\n\nimport { useMutation, useQueryClient, type UseMutationResult } from \"@tanstack/react-query\";\n\nimport type { CapxulError, CreateOrgInput, OrgView } from \"@capxul/sdk\";\n\nimport { useCapxulClientOrNull } from \"../internal/capxul-client-context\";\nimport { capxulKeys } from \"../internal/reactivity-keys\";\nimport { requireBootstrappedClient } from \"../internal/require-bootstrapped-client\";\nimport { unwrapCapxulResult } from \"../internal/unwrap-capxul-result\";\n\n/**\n * Create an Org (canon §C2 J1 / §C3, S1). Binds directly to the locked\n * `capxul.createOrg(input)` SDK method. On success, invalidates the org list.\n * RED until S1 — `mutate` rejects with `Errors.notImplemented(\"org\",\"createOrg\")`.\n */\nexport type UseCapxulCreateOrgReturn = UseMutationResult<OrgView, CapxulError, CreateOrgInput>;\n\nexport function useCapxulCreateOrg(): UseCapxulCreateOrgReturn {\n const client = useCapxulClientOrNull();\n const queryClient = useQueryClient();\n return useMutation({\n mutationFn: async (input: CreateOrgInput) => {\n const bootstrappedClient = requireBootstrappedClient(client, \"createOrg\");\n return unwrapCapxulResult(\n await bootstrappedClient.createOrg(input),\n bootstrappedClient._internal.telemetry,\n \"mutation\",\n );\n },\n onSuccess: async () => {\n await queryClient.invalidateQueries({ queryKey: capxulKeys.orgs });\n },\n });\n}\n","\"use client\";\n\nimport { useMutation, useQueryClient, type UseMutationResult } from \"@tanstack/react-query\";\n\nimport { Errors } from \"@capxul/errors\";\nimport type { CapxulError, InviteMemberInput, MemberView, OrgId } from \"@capxul/sdk\";\n\nimport { useCapxulClientOrNull } from \"../internal/capxul-client-context\";\nimport { capxulKeys } from \"../internal/reactivity-keys\";\nimport { requireBootstrappedClient } from \"../internal/require-bootstrapped-client\";\nimport { unwrapCapxulResult } from \"../internal/unwrap-capxul-result\";\n\n/**\n * Invite a member to an Org by email (canon §C2 J2 virality loop / §C3, S3, D8).\n * Entity-scoped via the closed-over `orgId` (D13). Binds directly to\n * `capxul.org(orgId).invite(input)`. On success, invalidates the member list.\n * RED until S3 — `mutate` rejects with `Errors.notImplemented(\"org\",\"invite\")`.\n */\nexport type UseCapxulInviteMemberReturn = UseMutationResult<\n MemberView,\n CapxulError,\n InviteMemberInput\n>;\n\nexport function useCapxulInviteMember(orgId: OrgId | undefined): UseCapxulInviteMemberReturn {\n const client = useCapxulClientOrNull();\n const queryClient = useQueryClient();\n return useMutation({\n mutationFn: async (input: InviteMemberInput) => {\n if (orgId === undefined) {\n throw Errors.invalidInput(\"orgId\", \"required for useCapxulInviteMember\");\n }\n const bootstrappedClient = requireBootstrappedClient(client, \"org.invite\");\n return unwrapCapxulResult(\n await bootstrappedClient.org(orgId).invite(input),\n bootstrappedClient._internal.telemetry,\n \"mutation\",\n );\n },\n onSuccess: async () => {\n if (orgId === undefined) return;\n await queryClient.invalidateQueries({ queryKey: capxulKeys.orgMembers(orgId) });\n },\n });\n}\n","\"use client\";\n\nimport { useMutation, useQueryClient, type UseMutationResult } from \"@tanstack/react-query\";\n\nimport { Errors } from \"@capxul/errors\";\nimport type { CapxulError, OrgId, RemoveMemberInput } from \"@capxul/sdk\";\n\nimport { useCapxulClientOrNull } from \"../internal/capxul-client-context\";\nimport { capxulKeys } from \"../internal/reactivity-keys\";\nimport { requireBootstrappedClient } from \"../internal/require-bootstrapped-client\";\nimport { unwrapCapxulResult } from \"../internal/unwrap-capxul-result\";\n\n/**\n * Remove a member from an Org (canon §C2 J2 / §C3, S3, D7/D8) — drives the\n * on-chain REVOKE + Convex mirror. Keyed on the member's personal Safe address\n * (D7). Entity-scoped via the closed-over `orgId` (D13). Binds directly to\n * `capxul.org(orgId).removeMember(input)`. On success, invalidates the member\n * list. RED until S3 — `mutate` rejects with\n * `Errors.notImplemented(\"org\",\"removeMember\")`.\n */\nexport type UseCapxulRemoveMemberReturn = UseMutationResult<void, CapxulError, RemoveMemberInput>;\n\nexport function useCapxulRemoveMember(orgId: OrgId | undefined): UseCapxulRemoveMemberReturn {\n const client = useCapxulClientOrNull();\n const queryClient = useQueryClient();\n return useMutation({\n mutationFn: async (input: RemoveMemberInput) => {\n if (orgId === undefined) {\n throw Errors.invalidInput(\"orgId\", \"required for useCapxulRemoveMember\");\n }\n const bootstrappedClient = requireBootstrappedClient(client, \"org.removeMember\");\n return unwrapCapxulResult(\n await bootstrappedClient.org(orgId).removeMember(input),\n bootstrappedClient._internal.telemetry,\n \"mutation\",\n );\n },\n onSuccess: async () => {\n if (orgId === undefined) return;\n await queryClient.invalidateQueries({ queryKey: capxulKeys.orgMembers(orgId) });\n },\n });\n}\n","\"use client\";\n\nimport { useMutation, useQueryClient, type UseMutationResult } from \"@tanstack/react-query\";\n\nimport { Errors } from \"@capxul/errors\";\nimport type { AssignRoleInput, CapxulError, MemberView, OrgId } from \"@capxul/sdk\";\n\nimport { useCapxulClientOrNull } from \"../internal/capxul-client-context\";\nimport { capxulKeys } from \"../internal/reactivity-keys\";\nimport { requireBootstrappedClient } from \"../internal/require-bootstrapped-client\";\nimport { unwrapCapxulResult } from \"../internal/unwrap-capxul-result\";\n\n/**\n * Assign a role to a member (canon §C2 J2 / §C3, S3, D7/D9) — drives the\n * on-chain GRANT + Convex mirror. Keyed on the member's personal Safe address\n * (D7); the `role` label maps deterministically to the on-chain `roleKey` (D9).\n * Entity-scoped via the closed-over `orgId` (D13). Binds directly to\n * `capxul.org(orgId).assignRole(input)`. On success, invalidates the member\n * list. RED until S3 — `mutate` rejects with\n * `Errors.notImplemented(\"org\",\"assignRole\")`.\n */\nexport type UseCapxulAssignRoleReturn = UseMutationResult<MemberView, CapxulError, AssignRoleInput>;\n\nexport function useCapxulAssignRole(orgId: OrgId | undefined): UseCapxulAssignRoleReturn {\n const client = useCapxulClientOrNull();\n const queryClient = useQueryClient();\n return useMutation({\n mutationFn: async (input: AssignRoleInput) => {\n if (orgId === undefined) {\n throw Errors.invalidInput(\"orgId\", \"required for useCapxulAssignRole\");\n }\n const bootstrappedClient = requireBootstrappedClient(client, \"org.assignRole\");\n return unwrapCapxulResult(\n await bootstrappedClient.org(orgId).assignRole(input),\n bootstrappedClient._internal.telemetry,\n \"mutation\",\n );\n },\n onSuccess: async () => {\n if (orgId === undefined) return;\n await queryClient.invalidateQueries({ queryKey: capxulKeys.orgMembers(orgId) });\n },\n });\n}\n","// #1066: the durable onboarding journey record — the proven #844 Reference\n// implementation promoted into the SDK headless layer. Behavior map §3:\n// versioned, sessionStorage-backed, owner-scoped; reload resumes, sign-out\n// clears. This module owns journey DATA and transitions only — mapping a step\n// to a route is the consuming app's projection (apps disagree on paths, never\n// on steps).\nexport type OnboardingIntent = \"personal\" | \"organization\";\nexport type OnboardingStep = \"profile\" | \"organization\" | \"provisioning\";\n\nexport type PayoutDraftChain = \"evm\" | \"solana\" | \"starknet\";\n\nexport type PayoutDraftEntry = {\n readonly chain: PayoutDraftChain;\n readonly address: string;\n};\n\nexport type ProfileDraft = {\n readonly displayName: string;\n readonly country: string;\n readonly withdrawalAddress: string;\n // #1062 / #1063: collected at the profile step, persisted at submit.\n readonly username?: string;\n readonly payoutAddresses?: readonly PayoutDraftEntry[];\n};\n\nexport type OrganizationDraft = {\n readonly name: string;\n readonly handle: string;\n readonly country: string;\n // #1064\n readonly bio?: string;\n readonly size?: string;\n};\n\nexport type OnboardingOrigin =\n | { readonly kind: \"personal\" }\n | { readonly kind: \"organization\"; readonly organizationId: string }\n | { readonly kind: \"proof\"; readonly organizationId?: string };\n\nexport type OnboardingJourney = {\n readonly version: 1;\n readonly ownerId: string;\n readonly journeyId: string;\n readonly intent: OnboardingIntent;\n readonly entryPoint: \"signup\" | \"dashboard\";\n readonly origin?: OnboardingOrigin;\n readonly step: OnboardingStep;\n readonly profile?: ProfileDraft;\n readonly organization?: OrganizationDraft;\n readonly stableHandle?: string;\n readonly organizationId?: string;\n};\n\n/**\n * The app-facing projection input: where a resumed journey stands. Consumers\n * map this to their own routes.\n */\nexport type OnboardingJourneyPosition = {\n readonly intent: OnboardingIntent;\n readonly step: OnboardingStep;\n readonly organizationId?: string;\n readonly proof: boolean;\n};\n\nconst JOURNEY_KEY = \"capxul.onboarding.journey.v1\";\nconst VALIDATED_OWNER_KEY = \"capxul.onboarding.validated-owner.v1\";\nconst JOURNEY_VERSION = 1;\nconst MAX_DRAFT_TEXT_LENGTH = 200;\nconst MAX_ID_LENGTH = 160;\nconst MAX_STORED_JOURNEY_LENGTH = 8_192;\nconst MAX_PAYOUT_DRAFT_ENTRIES = 10;\n\n/**\n * The owner whose stored journey may currently be attributed to observations.\n * Persisted in sessionStorage rather than module memory so `currentOnboarding-\n * JourneyId` is a pure function of durable state — attribution is the same\n * regardless of the order of renders, reloads, or telemetry emits. Established\n * only when an authenticated owner is (journey start, or an owner-matched load)\n * and cleared at every auth boundary or on discard.\n */\nfunction markOnboardingOwnerValidated(ownerId: string): void {\n try {\n sessionStorage.setItem(VALIDATED_OWNER_KEY, ownerId);\n } catch {\n // Browser recovery context is useful but never authoritative domain state.\n }\n}\n\nfunction clearValidatedOnboardingOwner(): void {\n try {\n sessionStorage.removeItem(VALIDATED_OWNER_KEY);\n } catch {\n // Domain completion remains durable even if browser cleanup is unavailable.\n }\n}\n\nfunction validatedOnboardingOwner(): string | null {\n try {\n return sessionStorage.getItem(VALIDATED_OWNER_KEY);\n } catch {\n return null;\n }\n}\n\nexport function startOnboardingJourney(input: {\n readonly intent: OnboardingIntent;\n readonly ownerId: string;\n readonly entryPoint: \"signup\" | \"dashboard\";\n readonly origin?: OnboardingOrigin;\n readonly step?: OnboardingStep;\n}): OnboardingJourney {\n const journey: OnboardingJourney = {\n version: JOURNEY_VERSION,\n ownerId: input.ownerId,\n journeyId: `journey_${createRandomId()}`,\n intent: input.intent,\n entryPoint: input.entryPoint,\n step: input.step ?? \"profile\",\n ...(input.origin === undefined ? {} : { origin: input.origin }),\n };\n markOnboardingOwnerValidated(journey.ownerId);\n saveOnboardingJourney(journey);\n return journey;\n}\n\nexport function loadOnboardingJourney(expectedOwnerId?: string): OnboardingJourney | null {\n try {\n const raw = sessionStorage.getItem(JOURNEY_KEY);\n if (raw === null) return null;\n if (raw.length > MAX_STORED_JOURNEY_LENGTH) return discardInvalidJourney();\n const value: unknown = JSON.parse(raw);\n if (!isValidJourney(value)) return discardInvalidJourney();\n if (expectedOwnerId !== undefined && value.ownerId !== expectedOwnerId) {\n return discardInvalidJourney();\n }\n if (expectedOwnerId !== undefined) markOnboardingOwnerValidated(expectedOwnerId);\n return value;\n } catch {\n return discardInvalidJourney();\n }\n}\n\nexport function saveOnboardingJourney(journey: OnboardingJourney): void {\n if (!isValidJourney(journey)) {\n discardInvalidJourney();\n return;\n }\n try {\n sessionStorage.setItem(JOURNEY_KEY, JSON.stringify(journey));\n } catch {\n // Browser recovery context is useful but never authoritative domain state.\n }\n}\n\nexport function currentOnboardingJourneyId(): string | undefined {\n const journey = loadOnboardingJourney();\n const owner = validatedOnboardingOwner();\n return journey !== null && owner !== null && journey.ownerId === owner\n ? journey.journeyId\n : undefined;\n}\n\n/** Stop observation attribution while no authenticated owner is established. */\nexport function invalidateOnboardingJourneyObservation(): void {\n clearValidatedOnboardingOwner();\n}\n\n/** Where the journey stands — the pure position apps map to their routes. */\nexport function onboardingJourneyPosition(journey: OnboardingJourney): OnboardingJourneyPosition {\n const proof = journey.origin?.kind === \"proof\";\n if (journey.organizationId !== undefined) {\n return {\n intent: journey.intent,\n step: \"provisioning\",\n organizationId: journey.organizationId,\n proof,\n };\n }\n return { intent: journey.intent, step: journey.step, proof };\n}\n\n/**\n * The interruption-recovery decision (behavior map §4): a journey that does\n * not match the ready destination the app just rendered must resume; a\n * matching one needs no recovery. Returns the journey to resume, or null.\n */\nexport function activeOnboardingRecovery(\n ownerId: string,\n renderedReadyDestination?:\n | { readonly kind: \"personal\" }\n | { readonly kind: \"organization\"; readonly organizationId: string },\n): OnboardingJourney | null {\n const journey = loadOnboardingJourney(ownerId);\n if (journey === null) return null;\n const isMatchingDestination =\n renderedReadyDestination?.kind === \"personal\"\n ? journey.intent === \"personal\" &&\n journey.step === \"provisioning\" &&\n journey.organizationId === undefined\n : renderedReadyDestination?.kind === \"organization\" &&\n journey.intent === \"organization\" &&\n journey.step === \"provisioning\" &&\n journey.organizationId === renderedReadyDestination.organizationId;\n return isMatchingDestination ? null : journey;\n}\n\nexport function acknowledgeOnboardingDestination(\n destination:\n | { readonly kind: \"personal\" }\n | { readonly kind: \"organization\"; readonly organizationId: string },\n ownerId: string,\n): boolean {\n const journey = loadOnboardingJourney(ownerId);\n if (journey === null) return false;\n const matches =\n destination.kind === \"personal\"\n ? journey.intent === \"personal\" && journey.step === \"provisioning\"\n : journey.intent === \"organization\" &&\n journey.step === \"provisioning\" &&\n journey.organizationId === destination.organizationId;\n if (!matches) return false;\n clearOnboardingJourney();\n return true;\n}\n\nexport function clearOnboardingJourney(): void {\n clearValidatedOnboardingOwner();\n try {\n sessionStorage.removeItem(JOURNEY_KEY);\n } catch {\n // Domain completion remains durable even if browser cleanup is unavailable.\n }\n}\n\nfunction isValidJourney(value: unknown): value is OnboardingJourney {\n if (!isRecord(value) || value.version !== JOURNEY_VERSION) return false;\n if (\n !hasOnlyKeys(value, [\n \"version\",\n \"ownerId\",\n \"journeyId\",\n \"intent\",\n \"entryPoint\",\n \"origin\",\n \"step\",\n \"profile\",\n \"organization\",\n \"stableHandle\",\n \"organizationId\",\n ])\n ) {\n return false;\n }\n if (!isBoundedId(value.ownerId)) return false;\n if (!isBoundedId(value.journeyId) || !value.journeyId.startsWith(\"journey_\")) return false;\n if (value.intent !== \"personal\" && value.intent !== \"organization\") return false;\n if (value.entryPoint !== \"signup\" && value.entryPoint !== \"dashboard\") return false;\n if (value.step !== \"profile\" && value.step !== \"organization\" && value.step !== \"provisioning\") {\n return false;\n }\n if (value.origin !== undefined && !isOrigin(value.origin)) return false;\n if (value.profile !== undefined && !isProfileDraft(value.profile)) return false;\n if (value.organization !== undefined && !isOrganizationDraft(value.organization)) return false;\n if (value.stableHandle !== undefined && !isDraftText(value.stableHandle)) return false;\n if (value.organizationId !== undefined && !isBoundedId(value.organizationId)) return false;\n if (value.organization !== undefined && value.stableHandle !== value.organization.handle) {\n return false;\n }\n if (value.stableHandle !== undefined && value.organization === undefined) return false;\n if (\n value.intent === \"personal\" &&\n (value.step === \"organization\" ||\n value.organization !== undefined ||\n value.stableHandle !== undefined)\n ) {\n return false;\n }\n if (value.step === \"organization\" && value.intent !== \"organization\") return false;\n if (value.organizationId !== undefined && value.intent !== \"organization\") return false;\n if (value.organizationId !== undefined && value.step !== \"provisioning\") return false;\n return true;\n}\n\nfunction isOrigin(value: unknown): value is OnboardingOrigin {\n if (!isRecord(value)) return false;\n if (value.kind === \"personal\") return hasOnlyKeys(value, [\"kind\"]);\n if (value.kind === \"organization\") {\n return hasOnlyKeys(value, [\"kind\", \"organizationId\"]) && isBoundedId(value.organizationId);\n }\n return (\n value.kind === \"proof\" &&\n hasOnlyKeys(value, [\"kind\", \"organizationId\"]) &&\n (value.organizationId === undefined || isBoundedId(value.organizationId))\n );\n}\n\nfunction isProfileDraft(value: unknown): value is ProfileDraft {\n if (\n !isRecord(value) ||\n !hasOnlyKeys(value, [\n \"displayName\",\n \"country\",\n \"withdrawalAddress\",\n \"username\",\n \"payoutAddresses\",\n ]) ||\n !isDraftText(value.displayName) ||\n !isDraftText(value.country) ||\n !isDraftText(value.withdrawalAddress)\n ) {\n return false;\n }\n if (value.username !== undefined && !isDraftText(value.username)) return false;\n if (value.payoutAddresses !== undefined && !isPayoutDraftList(value.payoutAddresses)) {\n return false;\n }\n return true;\n}\n\nfunction isPayoutDraftList(value: unknown): value is readonly PayoutDraftEntry[] {\n return (\n Array.isArray(value) &&\n value.length <= MAX_PAYOUT_DRAFT_ENTRIES &&\n value.every(\n (entry: unknown) =>\n isRecord(entry) &&\n hasOnlyKeys(entry, [\"chain\", \"address\"]) &&\n (entry.chain === \"evm\" || entry.chain === \"solana\" || entry.chain === \"starknet\") &&\n isDraftText(entry.address),\n )\n );\n}\n\nfunction isOrganizationDraft(value: unknown): value is OrganizationDraft {\n if (\n !isRecord(value) ||\n !hasOnlyKeys(value, [\"name\", \"handle\", \"country\", \"bio\", \"size\"]) ||\n !isDraftText(value.name) ||\n !isDraftText(value.handle) ||\n !isDraftText(value.country)\n ) {\n return false;\n }\n if (value.bio !== undefined && !isDraftText(value.bio)) return false;\n if (value.size !== undefined && !isDraftText(value.size)) return false;\n return true;\n}\n\nfunction isDraftText(value: unknown): value is string {\n return typeof value === \"string\" && value.length <= MAX_DRAFT_TEXT_LENGTH;\n}\n\nfunction isBoundedId(value: unknown): value is string {\n return typeof value === \"string\" && value.length > 0 && value.length <= MAX_ID_LENGTH;\n}\n\nfunction discardInvalidJourney(): null {\n clearValidatedOnboardingOwner();\n try {\n sessionStorage.removeItem(JOURNEY_KEY);\n } catch {\n // Invalid browser context remains non-authoritative when storage is unavailable.\n }\n return null;\n}\n\nfunction createRandomId(): string {\n if (typeof globalThis.crypto?.randomUUID === \"function\") return globalThis.crypto.randomUUID();\n return Math.random().toString(36).slice(2);\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction hasOnlyKeys(value: Record<string, unknown>, allowed: readonly string[]): boolean {\n return Object.keys(value).every((key) => allowed.includes(key));\n}\n","\"use client\";\n\nimport { useEffect, useState } from \"react\";\n\n/** The value as of `delayMs` after its last change (initial value immediate). */\nexport function useDebouncedValue<T>(value: T, delayMs: number): T {\n const [debounced, setDebounced] = useState(value);\n useEffect(() => {\n const timer = setTimeout(() => setDebounced(value), delayMs);\n return () => clearTimeout(timer);\n }, [value, delayMs]);\n return debounced;\n}\n","\"use client\";\n\nimport { useQuery, type UseQueryResult } from \"@tanstack/react-query\";\n\nimport type { CapxulError } from \"@capxul/sdk\";\n\nimport { useCapxulClientOrNull } from \"../../internal/capxul-client-context\";\nimport { capxulKeys } from \"../../internal/reactivity-keys\";\nimport { requireBootstrappedClient } from \"../../internal/require-bootstrapped-client\";\nimport { unwrapCapxulResult } from \"../../internal/unwrap-capxul-result\";\nimport { useDebouncedValue } from \"../../internal/use-debounced-value\";\n\nexport type UsernameAvailability = {\n readonly available: boolean;\n readonly normalized: string;\n};\n\nexport type UseCapxulUsernameAvailabilityReturn = UseQueryResult<UsernameAvailability, CapxulError>;\n\n/**\n * #1062: debounced availability probe for the username the user is typing.\n * Disabled until the candidate reaches the 3-character floor; a malformed or\n * reserved candidate surfaces as the query's error (INVALID_INPUT with the\n * boundary's message), not as `available: false` — only a username someone\n * else owns is \"taken\".\n */\nexport function useCapxulUsernameAvailability(\n username: string,\n options?: { readonly enabled?: boolean; readonly debounceMs?: number },\n): UseCapxulUsernameAvailabilityReturn {\n const client = useCapxulClientOrNull();\n const candidate = useDebouncedValue(username.trim(), options?.debounceMs ?? 300);\n return useQuery({\n queryKey: capxulKeys.usernameAvailability(candidate),\n queryFn: async () => {\n const bootstrappedClient = requireBootstrappedClient(client, \"identity.usernameAvailable\");\n return unwrapCapxulResult(\n await bootstrappedClient.identity.usernameAvailable(candidate),\n bootstrappedClient._internal.telemetry,\n );\n },\n enabled: client !== null && candidate.length >= 3 && (options?.enabled ?? true),\n });\n}\n","\"use client\";\n\nimport { useMutation, useQueryClient, type UseMutationResult } from \"@tanstack/react-query\";\n\nimport type { CapxulError } from \"@capxul/sdk\";\n\nimport { useCapxulClientOrNull } from \"../../internal/capxul-client-context\";\nimport { capxulKeys } from \"../../internal/reactivity-keys\";\nimport { requireBootstrappedClient } from \"../../internal/require-bootstrapped-client\";\nimport { unwrapCapxulResult } from \"../../internal/unwrap-capxul-result\";\n\nexport type ImageUploadTarget =\n | { readonly kind: \"profile\" }\n | { readonly kind: \"orgLogo\"; readonly orgId: string };\n\nexport type ImageUploadInput = {\n readonly blob: Blob;\n readonly target: ImageUploadTarget;\n};\n\nexport type UseCapxulImageUploadReturn = UseMutationResult<\n { readonly url: string | null },\n CapxulError,\n ImageUploadInput\n>;\n\n/**\n * #1061 / ADR-0014: the whole upload→record sequence as one mutation —\n * upload the blob, then bind the returned storage id to the profile image or\n * the org logo. The url is the resolved serving URL (re-read from queries,\n * never persisted by consumers).\n */\nexport function useCapxulImageUpload(): UseCapxulImageUploadReturn {\n const client = useCapxulClientOrNull();\n const queryClient = useQueryClient();\n return useMutation({\n mutationFn: async ({ blob, target }) => {\n const bootstrappedClient = requireBootstrappedClient(client, \"media.uploadImage\");\n const media = bootstrappedClient.media;\n const telemetry = bootstrappedClient._internal.telemetry;\n const uploaded = unwrapCapxulResult(await media.uploadImage(blob), telemetry);\n if (target.kind === \"profile\") {\n const set = unwrapCapxulResult(\n await media.setProfileImage({ storageId: uploaded.storageId }),\n telemetry,\n );\n return { url: set.imageUrl };\n }\n const set = unwrapCapxulResult(\n await media.setOrgLogo({ orgId: target.orgId, storageId: uploaded.storageId }),\n telemetry,\n );\n return { url: set.logoUrl };\n },\n onSuccess: async (_value, input) => {\n await queryClient.invalidateQueries({\n queryKey: input.target.kind === \"profile\" ? capxulKeys.profile : capxulKeys.orgs,\n });\n },\n });\n}\n"],"mappings":";;;;;AAKA,MAAa,qBAAqB;CAChC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AA4FA,IAAa,cAAb,cAAiC,MAAM;CACrC;CACA;CACA;CACA;CAEA,YAAY,MAAuB,SAAiB,UAA8B,CAAC,GAAG;EACpF,MAAM,SAAS,WAAW,UAAU,EAAE,OAAO,QAAQ,MAAM,IAAI,KAAA,CAAS;EACxE,KAAK,OAAO;EACZ,KAAK,OAAO;EACZ,IAAI,QAAQ,YAAY,KAAA,GACtB,KAAK,UAAU,QAAQ;EAEzB,IAAI,QAAQ,kBAAkB,KAAA,GAC5B,KAAK,gBAAgB,QAAQ;EAE/B,IAAI,QAAQ,UAAU,KAAA,GACpB,KAAK,QAAQ,QAAQ;CAEzB;AACF;AAwFA,MAAa,SAAS;CACpB,mBAAmB,SAAkB,SACnC,IAAI,YACF,qBACA,WAAW,qBACX,MAAM,eAAe,EAAE,SAAS,EAAE,cAAc,KAAK,aAAa,EAAE,IAAI,KAAA,C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,OAAO,OAAO;IAAO,WAAW,SAAS;GAAU,CAAC,GAC7E,SAEc,EAAE,QAAQ;EAC5B;EACA,WAAW,OAAO,QAAQ,UAAU;GAClC,MAAM,YAAY,kBAAkB,EAClC,UAAU,MAAM,OAAO,SAAS,YAAY,WAAW,UAAU,WAAW,KAC9E,CAAC;EACH;CACF,CAAC;AACH"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/testing/index.tsx"],"mappings":";;;;;;UA6BiB,mCAAA,SAA4C,6BAA6B;EAAA,SAC/E,OAAA,GAAU,gBAAA;AAAA;AAAA,UAGJ,sBAAA;EAAA,SACN,OAAA,EAAS,gBAAA;EAAA,SACT,MAAA,EAAQ,gBAAA;EAAA,SACR,QAAA,GAAW,QAAA,EAAU,SAAA,KAAc,KAAA,CAAM,GAAA,CAAI,OAAA;EAAA,SAC7C,cAAA,GAAiB,KAAA,EAAO,mBAAA,KAAwB,KAAA,CAAM,GAAA,CAAI,OAAA;EAAA,SAC1D,UAAA,GAAa,KAAA,EAAO,yBAAA,KAA8B,KAAA,CAAM,GAAA,CAAI,OAAA;AAAA;;iBAIvD,4BAAA,CACd,OAAA,GAAS,mCAAA,GACR,sBAAsB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../src/testing/index.tsx"],"sourcesContent":["import * as React from \"react\";\nimport type { ReactNode } from \"react\";\n\nimport {\n createCapxulTestClient,\n type CapxulTestClient,\n type CapxulTestClock,\n type CapxulTestObservation,\n type CreateCapxulTestClientOptions,\n type SeedTestIdentityInput,\n} from \"@capxul/sdk/testing\";\n\nimport {\n CapxulAuthenticationController,\n CapxulOnboardingController,\n type AuthenticationSlots,\n type OnboardingControllerProps,\n} from \"../controllers\";\nimport { CapxulProvider } from \"../provider\";\n\nexport { createCapxulTestClient };\nexport type {\n CapxulTestClient,\n CapxulTestClock,\n CapxulTestObservation,\n CreateCapxulTestClientOptions,\n SeedTestIdentityInput,\n};\n\nexport interface CreateCapxulReactTestHarnessOptions extends CreateCapxulTestClientOptions {\n readonly testing?: CapxulTestClient;\n}\n\nexport interface CapxulReactTestHarness {\n readonly testing: CapxulTestClient;\n readonly client: CapxulTestClient[\"client\"];\n readonly provider: (children: ReactNode) => React.JSX.Element;\n readonly authentication: (slots: AuthenticationSlots) => React.JSX.Element;\n readonly onboarding: (props: OnboardingControllerProps) => React.JSX.Element;\n}\n\n/** Build renderer-neutral React test elements over the real SDK testing client. */\nexport function createCapxulReactTestHarness(\n options: CreateCapxulReactTestHarnessOptions = {},\n): CapxulReactTestHarness {\n const { testing: suppliedTesting, ...clientOptions } = options;\n const testing = suppliedTesting ?? createCapxulTestClient(clientOptions);\n return {\n testing,\n client: testing.client,\n provider: (children) => <CapxulProvider client={testing.client}>{children}</CapxulProvider>,\n authentication: (slots) => <CapxulAuthenticationController slots={slots} />,\n onboarding: (props) => <CapxulOnboardingController {...props} />,\n };\n}\n"],"mappings":";;;;;;AA0CA,SAAgB,6BACd,UAA+C,CAAC,GACxB;CACxB,MAAM,EAAE,SAAS,iBAAiB,GAAG,kBAAkB;CACvD,MAAM,UAAU,mBAAmB,uBAAuB,aAAa;CACvE,OAAO;EACL;EACA,QAAQ,QAAQ;EAChB,WAAW,aAAa,oBAAC,gBAAD;GAAgB,QAAQ,QAAQ;GAAS;EAAyB,CAAA;EAC1F,iBAAiB,UAAU,oBAAC,gCAAD,EAAuC,MAAQ,CAAA;EAC1E,aAAa,UAAU,oBAAC,4BAAD,EAA4B,GAAI,MAAQ,CAAA;CACjE;AACF"}