@capxul/sdk-react 0.2.0-alpha.4 → 1.0.0-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs ADDED
@@ -0,0 +1,1485 @@
1
+ "use client";
2
+ import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
3
+ import { QueryClient, QueryClientProvider, useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
4
+ import { captureExceptionSync, createCapxulClient, isSettingUpLifecycle } from "@capxul/sdk";
5
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
6
+ //#region src/internal/capxul-bootstrap-context.tsx
7
+ const CapxulBootstrapContext = createContext(null);
8
+ function CapxulBootstrapProvider({ value, children }) {
9
+ return /* @__PURE__ */ jsx(CapxulBootstrapContext.Provider, {
10
+ value,
11
+ children
12
+ });
13
+ }
14
+ function useCapxul() {
15
+ const state = useContext(CapxulBootstrapContext);
16
+ if (state === null) throw new Error("useCapxul must be used within <CapxulProvider>");
17
+ return state;
18
+ }
19
+ //#endregion
20
+ //#region src/internal/capxul-client-context.tsx
21
+ const MISSING_CAPXUL_CLIENT_PROVIDER = Symbol("MISSING_CAPXUL_CLIENT_PROVIDER");
22
+ const CapxulClientContext = createContext(MISSING_CAPXUL_CLIENT_PROVIDER);
23
+ function CapxulClientProvider({ client, children }) {
24
+ return /* @__PURE__ */ jsx(CapxulClientContext.Provider, {
25
+ value: client,
26
+ children
27
+ });
28
+ }
29
+ function useCapxulClient() {
30
+ const client = useCapxulClientOrNull();
31
+ if (client === null) throw new Error("useCapxulClient called before <CapxulProvider> bootstrap resolved");
32
+ return client;
33
+ }
34
+ /**
35
+ * Returns the client, or `null` while `<CapxulProvider>` is still bootstrapping.
36
+ * Data hooks use this so they can sit in `isPending` (disabled query) until the
37
+ * client resolves, rather than throwing during bootstrap.
38
+ */
39
+ function useCapxulClientOrNull() {
40
+ const client = useContext(CapxulClientContext);
41
+ if (client === MISSING_CAPXUL_CLIENT_PROVIDER) throw new Error("useCapxulClient must be used within <CapxulProvider>");
42
+ return client;
43
+ }
44
+ //#endregion
45
+ //#region src/provider.tsx
46
+ function makeDefaultQueryClient() {
47
+ return new QueryClient({ defaultOptions: {
48
+ queries: {
49
+ retry: 2,
50
+ staleTime: 3e4
51
+ },
52
+ mutations: { retry: 0 }
53
+ } });
54
+ }
55
+ function isCapxulQueryKey(queryKey) {
56
+ return queryKey[0] === "capxul";
57
+ }
58
+ function clearClientScopedQueries(queryClient, ownsQueryClient) {
59
+ if (ownsQueryClient) {
60
+ queryClient.clear();
61
+ return;
62
+ }
63
+ queryClient.removeQueries({ predicate: (query) => isCapxulQueryKey(query.queryKey) });
64
+ }
65
+ function CapxulProvider(props) {
66
+ const { publishableKey, client: injectedClient, requirement, signer, queryClient, children } = props;
67
+ const [resolvedQueryClient] = useState(() => queryClient ?? makeDefaultQueryClient());
68
+ const [ownsQueryClient] = useState(() => queryClient === void 0);
69
+ const [client, setClient] = useState(injectedClient ?? null);
70
+ const previousClientRef = useRef(injectedClient ?? null);
71
+ const [status, setStatus] = useState(injectedClient === void 0 ? "bootstrapping" : "ready");
72
+ const [error, setError] = useState(null);
73
+ const [attempt, setAttempt] = useState(0);
74
+ const retry = useCallback(() => {
75
+ setAttempt((n) => n + 1);
76
+ }, []);
77
+ useEffect(() => {
78
+ if (publishableKey === void 0) return;
79
+ let cancelled = false;
80
+ let created = null;
81
+ setStatus("bootstrapping");
82
+ setError(null);
83
+ setClient(null);
84
+ (async () => {
85
+ const result = await createCapxulClient({
86
+ publishableKey,
87
+ ...requirement === void 0 ? {} : { requirement },
88
+ ...signer === void 0 ? {} : { signer }
89
+ });
90
+ if (cancelled) {
91
+ if (result.ok) await result.value._internal.close?.();
92
+ return;
93
+ }
94
+ if (result.ok) {
95
+ created = result.value;
96
+ setClient(result.value);
97
+ setStatus("ready");
98
+ } else {
99
+ setError(result.error);
100
+ setStatus("error");
101
+ }
102
+ })();
103
+ return () => {
104
+ cancelled = true;
105
+ created?._internal.close?.();
106
+ };
107
+ }, [
108
+ publishableKey,
109
+ requirement,
110
+ signer,
111
+ attempt
112
+ ]);
113
+ useEffect(() => {
114
+ if (injectedClient === void 0) return;
115
+ setClient(injectedClient);
116
+ setStatus("ready");
117
+ setError(null);
118
+ }, [injectedClient]);
119
+ useEffect(() => {
120
+ const previous = previousClientRef.current;
121
+ if (previous !== null && previous !== client) clearClientScopedQueries(resolvedQueryClient, ownsQueryClient);
122
+ previousClientRef.current = client;
123
+ }, [
124
+ client,
125
+ ownsQueryClient,
126
+ resolvedQueryClient
127
+ ]);
128
+ const bootstrapState = useMemo(() => ({
129
+ status,
130
+ error,
131
+ retry
132
+ }), [
133
+ status,
134
+ error,
135
+ retry
136
+ ]);
137
+ if (publishableKey === void 0 === (injectedClient === void 0)) throw new Error("CapxulProvider requires exactly one of `publishableKey` or `client`");
138
+ return /* @__PURE__ */ jsx(QueryClientProvider, {
139
+ client: resolvedQueryClient,
140
+ children: /* @__PURE__ */ jsx(CapxulBootstrapProvider, {
141
+ value: bootstrapState,
142
+ children: /* @__PURE__ */ jsx(CapxulClientProvider, {
143
+ client,
144
+ children
145
+ })
146
+ })
147
+ });
148
+ }
149
+ //#endregion
150
+ //#region ../errors/src/errors.ts
151
+ const CAPXUL_ERROR_CODES = [
152
+ "NOT_AUTHENTICATED",
153
+ "EMAIL_DELIVERY_FAILED",
154
+ "PROFILE_NOT_FOUND",
155
+ "SMART_ACCOUNT_MISSING",
156
+ "PLAYER_NOT_FOUND",
157
+ "ACCOUNT_NOT_FOUND",
158
+ "PROVIDER_ERROR",
159
+ "INVALID_INPUT",
160
+ "ENV_MISSING",
161
+ "NOT_IMPLEMENTED",
162
+ "VERIFICATION_REQUIRED",
163
+ "INSUFFICIENT_BALANCE",
164
+ "INVALID_RECIPIENT",
165
+ "ROLE_PERMISSION_DENIED",
166
+ "TRANSACTION_FAILED",
167
+ "RATE_LIMITED",
168
+ "NETWORK_ERROR",
169
+ "UNKNOWN",
170
+ "OTP_EXPIRED",
171
+ "SIGNER_REJECTED",
172
+ "CANCELLED",
173
+ "WRONG_STATE"
174
+ ];
175
+ var CapxulError = class extends Error {
176
+ code;
177
+ details;
178
+ correlationId;
179
+ layer;
180
+ constructor(code, message, options = {}) {
181
+ super(message, "cause" in options ? { cause: options.cause } : void 0);
182
+ this.name = "CapxulError";
183
+ this.code = code;
184
+ if (options.details !== void 0) this.details = options.details;
185
+ if (options.correlationId !== void 0) this.correlationId = options.correlationId;
186
+ if (options.layer !== void 0) this.layer = options.layer;
187
+ }
188
+ };
189
+ function isCapxulError(value) {
190
+ return value instanceof CapxulError;
191
+ }
192
+ const Errors = {
193
+ notAuthenticated: (message, opts) => new CapxulError("NOT_AUTHENTICATED", message ?? "Not authenticated", opts?.failure_mode ? { details: { failure_mode: opts.failure_mode } } : void 0),
194
+ emailDeliveryFailed: (detail) => new CapxulError("EMAIL_DELIVERY_FAILED", "Failed to send email", { details: { detail } }),
195
+ profileNotFound: (authUserId) => new CapxulError("PROFILE_NOT_FOUND", `Profile not found for user ${authUserId}`, { details: { authUserId } }),
196
+ smartAccountMissing: (authUserId) => new CapxulError("SMART_ACCOUNT_MISSING", "Smart account not provisioned", { details: { authUserId } }),
197
+ playerNotFound: (playerId) => new CapxulError("PLAYER_NOT_FOUND", playerId ? `Openfort player ${playerId} not found` : "Openfort player not found", playerId === void 0 ? void 0 : { details: { playerId } }),
198
+ accountNotFound: (accountId) => new CapxulError("ACCOUNT_NOT_FOUND", accountId ? `Openfort account ${accountId} not found` : "Openfort account not found", accountId === void 0 ? void 0 : { details: { accountId } }),
199
+ providerError: (provider, operation, cause, opts) => {
200
+ const details = {
201
+ provider,
202
+ operation
203
+ };
204
+ if (opts?.failure_mode) details.failure_mode = opts.failure_mode;
205
+ return new CapxulError("PROVIDER_ERROR", `Provider error: ${provider} ${operation}`, {
206
+ cause,
207
+ details
208
+ });
209
+ },
210
+ invalidInput: (field, reason) => new CapxulError("INVALID_INPUT", `Invalid ${field}: ${reason}`, { details: {
211
+ field,
212
+ reason
213
+ } }),
214
+ envMissing: (name) => new CapxulError("ENV_MISSING", `Environment variable ${name} not configured`, { details: { name } }),
215
+ notImplemented: (domain, method) => new CapxulError("NOT_IMPLEMENTED", `${domain}.${method} is not yet implemented. This feature is planned for a future release.`, { details: {
216
+ domain,
217
+ method
218
+ } }),
219
+ /**
220
+ * Sibling factory to {@link Errors.providerError} for the per-state timeout
221
+ * path in flows (initially ProvisioningFlow's mint_openfort / deploy_safe /
222
+ * register_indexer `after:` timers). Same `PROVIDER_ERROR` code as
223
+ * `providerError`, plus a `details.reason: "timeout"` discriminator so
224
+ * downstream observers can distinguish failure modes without parsing the
225
+ * message string. The redacted message names the timeout budget; the
226
+ * native `cause` carries the same information for `reportError` fidelity.
227
+ */
228
+ providerTimeout: (provider, operation, timeoutMs) => new CapxulError("PROVIDER_ERROR", `Provider error: ${provider} ${operation} (timeout exceeded ${timeoutMs}ms)`, {
229
+ details: {
230
+ provider,
231
+ operation,
232
+ reason: "timeout"
233
+ },
234
+ cause: /* @__PURE__ */ new Error(`timeout: ${operation} exceeded ${timeoutMs}ms`)
235
+ }),
236
+ verificationRequired: (details) => {
237
+ return new CapxulError("VERIFICATION_REQUIRED", "rail" in details ? `Verification is required before ${details.rail} can use ${details.currentKind}.` : `Verification tier ${details.requiredTier} is required.`, { details });
238
+ },
239
+ insufficientBalance: (asset, available, required) => new CapxulError("INSUFFICIENT_BALANCE", `Insufficient ${asset} balance`, { details: {
240
+ asset,
241
+ available,
242
+ required
243
+ } }),
244
+ invalidRecipient: (reason) => new CapxulError("INVALID_RECIPIENT", `Invalid recipient: ${reason}`, { details: { reason } }),
245
+ /**
246
+ * The org Zodiac Roles modifier REFUSED the spend on-chain (G4 · #547): the
247
+ * member's role condition (per-tx cap, per-day allowance, allowed recipient,
248
+ * or membership) was violated, so `execTransactionWithRole` reverted. This is
249
+ * a PERMISSION denial — explicitly NOT an `INSUFFICIENT_BALANCE` (the treasury
250
+ * held the funds; the role's authority is what bound). `reason` discriminates
251
+ * the violated condition (`over_cap` / `daily_cap` / `not_member` /
252
+ * `disallowed_recipient` / `condition_violation`); leak-safe — no on-chain
253
+ * identifiers ever enter the details.
254
+ */
255
+ rolePermissionDenied: (details) => new CapxulError("ROLE_PERMISSION_DENIED", `Org role denied this spend on-chain (${details.reason}).`, { details: details.operation === void 0 ? { reason: details.reason } : {
256
+ reason: details.reason,
257
+ operation: details.operation
258
+ } }),
259
+ /**
260
+ * A transaction (or sponsored UserOp) failed. `details.reason` discriminates
261
+ * the failure mode for callers that must distinguish a CONFIRMED on-chain
262
+ * revert (`"onchain_revert"` — the op executed and reverted, e.g. a Zodiac
263
+ * Roles condition violation) from an inconclusive infra failure. A confirmed
264
+ * revert is the ONLY mode the org spend port may map to a roles denial.
265
+ */
266
+ transactionFailed: (operation, cause, extra) => new CapxulError("TRANSACTION_FAILED", `Transaction failed: ${operation}`, {
267
+ cause,
268
+ details: extra?.reason === void 0 ? { operation } : {
269
+ operation,
270
+ reason: extra.reason
271
+ }
272
+ }),
273
+ rateLimited: (details) => new CapxulError("RATE_LIMITED", "Rate limit exceeded", details === void 0 ? void 0 : { details: { ...details } }),
274
+ networkError: (operation, cause) => new CapxulError("NETWORK_ERROR", `Network error during ${operation}`, {
275
+ cause,
276
+ details: { operation }
277
+ }),
278
+ unknown: (cause) => new CapxulError("UNKNOWN", "Unknown error", { cause }),
279
+ otpExpired: (details) => new CapxulError("OTP_EXPIRED", "Verification code has expired. Request a new one.", details === void 0 ? void 0 : { details: { ...details } }),
280
+ signerRejected: (details) => new CapxulError("SIGNER_REJECTED", "Signer rejected the request.", {
281
+ cause: details.cause,
282
+ details: details.reason === void 0 ? { source: details.source } : {
283
+ source: details.source,
284
+ reason: details.reason
285
+ }
286
+ }),
287
+ cancelled: (details) => new CapxulError("CANCELLED", "Operation was cancelled.", details === void 0 ? void 0 : { details: { ...details } }),
288
+ /**
289
+ * Method called from a flow state where its precondition fails (TA16). The
290
+ * SDK's method API short-circuits with this error before driving the
291
+ * internal state machine. `currentState` is the Effect-machine snapshot
292
+ * tag (stringified — substrate is `@effect/experimental/Machine` per
293
+ * `docs/canon/decisions/state-machine-substrate.md`); `validStates`
294
+ * enumerates the states the method accepts.
295
+ */
296
+ wrongState: (details) => new CapxulError("WRONG_STATE", `${details.method} called from state '${details.currentState}'; valid states: ${details.validStates.join(", ")}`, { details: {
297
+ ...details,
298
+ validStates: [...details.validStates]
299
+ } })
300
+ };
301
+ new Set(CAPXUL_ERROR_CODES);
302
+ //#endregion
303
+ //#region src/internal/require-bootstrapped-client.ts
304
+ /**
305
+ * Narrow the bootstrap-nullable client to a ready client inside a query /
306
+ * mutation function (sdk-provider-owned-bootstrap.md). Data hooks gate their
307
+ * queries on `enabled: client !== null`, so this only ever throws for a mutation
308
+ * triggered while `<CapxulProvider>` is still bootstrapping.
309
+ */
310
+ function requireBootstrappedClient(client, method) {
311
+ if (client === null) throw Errors.wrongState({
312
+ method,
313
+ currentState: "bootstrapping",
314
+ validStates: ["ready"]
315
+ });
316
+ return client;
317
+ }
318
+ //#endregion
319
+ //#region src/internal/reactivity-keys.ts
320
+ function actorKey(actor) {
321
+ if (actor === void 0) return ["pending"];
322
+ return actor.kind === "account" ? ["account"] : ["org", actor.orgId];
323
+ }
324
+ const capxulKeys = {
325
+ session: ["capxul", "session"],
326
+ profile: ["capxul", "profile"],
327
+ account: ["capxul", "account"],
328
+ accountLifecycle: ["capxul", "accountLifecycle"],
329
+ provisioning: ["capxul", "provisioning"],
330
+ binding: ["capxul", "binding"],
331
+ accountBalance: ["capxul", "accountBalance"],
332
+ subAccounts: (accountId) => [
333
+ "capxul",
334
+ "subAccounts",
335
+ accountId ?? "pending"
336
+ ],
337
+ orgs: ["capxul", "orgs"],
338
+ org: (orgId) => [
339
+ "capxul",
340
+ "org",
341
+ orgId ?? "pending"
342
+ ],
343
+ orgMembers: (orgId) => [
344
+ "capxul",
345
+ "org",
346
+ orgId ?? "pending",
347
+ "members"
348
+ ],
349
+ orgRoles: (orgId) => [
350
+ "capxul",
351
+ "org",
352
+ orgId ?? "pending",
353
+ "roles"
354
+ ],
355
+ orgTreasury: (orgId) => [
356
+ "capxul",
357
+ "org",
358
+ orgId ?? "pending",
359
+ "treasury"
360
+ ],
361
+ actorAddressBook: (actor) => [
362
+ "capxul",
363
+ "actor",
364
+ ...actorKey(actor),
365
+ "addressBook"
366
+ ],
367
+ actorAddressBookEntry: (actor, entryId) => [
368
+ "capxul",
369
+ "actor",
370
+ ...actorKey(actor),
371
+ "addressBook",
372
+ entryId ?? "pending"
373
+ ],
374
+ actorRequests: (actor) => [
375
+ "capxul",
376
+ "actor",
377
+ ...actorKey(actor),
378
+ "requests"
379
+ ],
380
+ actorRequest: (actor, requestId) => [
381
+ "capxul",
382
+ "actor",
383
+ ...actorKey(actor),
384
+ "requests",
385
+ requestId ?? "pending"
386
+ ],
387
+ actorInbox: (actor) => [
388
+ "capxul",
389
+ "actor",
390
+ ...actorKey(actor),
391
+ "inbox"
392
+ ],
393
+ actorInsightsSummary: (actor) => [
394
+ "capxul",
395
+ "actor",
396
+ ...actorKey(actor),
397
+ "insights",
398
+ "summary"
399
+ ],
400
+ actorInsightsHistory: (actor) => [
401
+ "capxul",
402
+ "actor",
403
+ ...actorKey(actor),
404
+ "insights",
405
+ "history"
406
+ ],
407
+ actorDestinationsScope: (actor) => [
408
+ "capxul",
409
+ "actor",
410
+ ...actorKey(actor),
411
+ "destinations"
412
+ ],
413
+ actorDestinations: (actor, refKey) => [
414
+ "capxul",
415
+ "actor",
416
+ ...actorKey(actor),
417
+ "destinations",
418
+ refKey ?? "pending"
419
+ ],
420
+ payments: ["capxul", "payments"],
421
+ payment: (paymentId) => [
422
+ "capxul",
423
+ "payments",
424
+ paymentId ?? "pending"
425
+ ],
426
+ paymentRequests: ["capxul", "paymentRequests"],
427
+ payrollRoster: (orgId) => [
428
+ "capxul",
429
+ "org",
430
+ orgId ?? "pending",
431
+ "payroll",
432
+ "roster"
433
+ ]
434
+ };
435
+ //#endregion
436
+ //#region src/internal/unwrap-capxul-result.ts
437
+ /**
438
+ * Unwrap a `CapxulResult` for TanStack query/mutation functions —
439
+ * throws into error paths, optionally reporting the error to telemetry first.
440
+ *
441
+ * When `telemetry` is provided and the result is `{ ok: false }`,
442
+ * `captureExceptionSync` is called (fire-and-forget) before the throw. `operation`
443
+ * tags the telemetry event so query reads and mutation writes stay
444
+ * distinguishable in error tracking (defaults to `"query"`).
445
+ */
446
+ function unwrapCapxulResult(result, telemetry, operation = "query") {
447
+ if (result.ok) return result.value;
448
+ if (telemetry) try {
449
+ captureExceptionSync(telemetry, result.error, {
450
+ layer: "react-query",
451
+ operation
452
+ });
453
+ } catch {}
454
+ throw result.error;
455
+ }
456
+ //#endregion
457
+ //#region src/hooks/use-capxul-session.ts
458
+ function useCapxulSession() {
459
+ const client = useCapxulClientOrNull();
460
+ return useQuery({
461
+ queryKey: capxulKeys.session,
462
+ queryFn: async () => unwrapCapxulResult(await requireBootstrappedClient(client, "auth.getSession").auth.getSession(), client._internal.telemetry),
463
+ enabled: client !== null
464
+ });
465
+ }
466
+ //#endregion
467
+ //#region src/hooks/use-capxul-profile.ts
468
+ function useCapxulProfile() {
469
+ const client = useCapxulClientOrNull();
470
+ return useQuery({
471
+ queryKey: capxulKeys.profile,
472
+ queryFn: async () => unwrapCapxulResult(await requireBootstrappedClient(client, "identity.loadCurrent").identity.loadCurrent(), client._internal.telemetry),
473
+ enabled: client !== null
474
+ });
475
+ }
476
+ //#endregion
477
+ //#region src/internal/is-vitest-runtime.ts
478
+ /** True under Vitest — disables hook polling intervals that fight fake timers. */
479
+ function isVitestRuntime() {
480
+ return typeof process !== "undefined" && process.env["VITEST"] === "true";
481
+ }
482
+ //#endregion
483
+ //#region src/internal/invalidate-auth-boundary.ts
484
+ /** Background refetch after verifyOtp — avoids hard reset cancel errors in UI. */
485
+ async function invalidateAuthBoundary(queryClient) {
486
+ await Promise.all([
487
+ queryClient.invalidateQueries({ queryKey: capxulKeys.session }),
488
+ queryClient.invalidateQueries({ queryKey: capxulKeys.profile }),
489
+ queryClient.invalidateQueries({ queryKey: capxulKeys.accountLifecycle }),
490
+ queryClient.invalidateQueries({ queryKey: capxulKeys.accountBalance })
491
+ ]);
492
+ }
493
+ /** Hard reset after signOut — drop cached authenticated rows immediately. */
494
+ async function resetAuthBoundary(queryClient) {
495
+ await queryClient.cancelQueries({ queryKey: capxulKeys.accountBalance });
496
+ await Promise.all([
497
+ queryClient.resetQueries({ queryKey: capxulKeys.session }),
498
+ queryClient.resetQueries({ queryKey: capxulKeys.profile }),
499
+ queryClient.resetQueries({ queryKey: capxulKeys.accountLifecycle }),
500
+ queryClient.resetQueries({ queryKey: capxulKeys.accountBalance })
501
+ ]);
502
+ }
503
+ //#endregion
504
+ //#region src/hooks/use-capxul-account-lifecycle.ts
505
+ const LOADING_LIFECYCLE = { status: "loading" };
506
+ function useCapxulAccountLifecycle() {
507
+ const client = useCapxulClientOrNull();
508
+ const queryClient = useQueryClient();
509
+ const query = useQuery({
510
+ queryKey: capxulKeys.accountLifecycle,
511
+ queryFn: async () => {
512
+ const bootstrappedClient = requireBootstrappedClient(client, "account.getLifecycle");
513
+ return unwrapCapxulResult(await bootstrappedClient.account.getLifecycle(), bootstrappedClient._internal.telemetry);
514
+ },
515
+ enabled: client !== null,
516
+ refetchInterval: (q) => {
517
+ if (isVitestRuntime()) return false;
518
+ const data = q.state.data;
519
+ if (data === void 0) return false;
520
+ if (data.status === "loading" || isSettingUpLifecycle(data)) return 2e3;
521
+ return false;
522
+ }
523
+ });
524
+ const retryMutation = useMutation({
525
+ mutationFn: async () => {
526
+ const bootstrappedClient = requireBootstrappedClient(client, "account.retrySetup");
527
+ return unwrapCapxulResult(await bootstrappedClient.account.retrySetup(), bootstrappedClient._internal.telemetry, "mutation");
528
+ },
529
+ onSuccess: async () => {
530
+ await invalidateAuthBoundary(queryClient);
531
+ }
532
+ });
533
+ const lifecycle = query.data ?? LOADING_LIFECYCLE;
534
+ const failedError = lifecycle.status === "failed" ? lifecycle.error : null;
535
+ const queryError = query.isError ? query.error : null;
536
+ return {
537
+ lifecycle: queryError !== null && lifecycle.status === "loading" ? {
538
+ status: "failed",
539
+ at: "connecting",
540
+ error: queryError
541
+ } : lifecycle,
542
+ isSettingUp: isSettingUpLifecycle(lifecycle),
543
+ error: failedError ?? queryError,
544
+ isLoading: query.isLoading,
545
+ isFetching: query.isFetching,
546
+ isError: query.isError,
547
+ retry: retryMutation.mutateAsync,
548
+ isRetrying: retryMutation.isPending
549
+ };
550
+ }
551
+ //#endregion
552
+ //#region src/hooks/use-capxul-account-balance.ts
553
+ function useCapxulAccountBalance(options) {
554
+ const client = useCapxulClientOrNull();
555
+ return useQuery({
556
+ queryKey: capxulKeys.accountBalance,
557
+ queryFn: async () => {
558
+ const bootstrappedClient = requireBootstrappedClient(client, "accounts.read");
559
+ return unwrapCapxulResult(await bootstrappedClient.accounts.read(), bootstrappedClient._internal.telemetry);
560
+ },
561
+ enabled: client !== null && (options?.enabled ?? true)
562
+ });
563
+ }
564
+ //#endregion
565
+ //#region src/hooks/use-capxul-account-fund.ts
566
+ function useCapxulAccountFund() {
567
+ const client = useCapxulClientOrNull();
568
+ const queryClient = useQueryClient();
569
+ return useMutation({
570
+ mutationFn: async (amount) => {
571
+ const bootstrappedClient = requireBootstrappedClient(client, "_internal.accounts.fund");
572
+ return unwrapCapxulResult(await bootstrappedClient._internal.accounts.fund(amount), bootstrappedClient._internal.telemetry, "mutation");
573
+ },
574
+ onSuccess: async () => {
575
+ await queryClient.invalidateQueries({ queryKey: capxulKeys.accountBalance });
576
+ }
577
+ });
578
+ }
579
+ //#endregion
580
+ //#region src/hooks/use-capxul-sign-in.ts
581
+ function useCapxulSignIn() {
582
+ const client = useCapxulClientOrNull();
583
+ return useMutation({ mutationFn: async (input) => {
584
+ const bootstrappedClient = requireBootstrappedClient(client, "auth.signIn");
585
+ return unwrapCapxulResult(await bootstrappedClient.auth.signIn(input), bootstrappedClient._internal.telemetry, "mutation");
586
+ } });
587
+ }
588
+ //#endregion
589
+ //#region src/hooks/use-capxul-verify-otp.ts
590
+ function useCapxulVerifyOtp() {
591
+ const client = useCapxulClientOrNull();
592
+ const queryClient = useQueryClient();
593
+ return useMutation({
594
+ mutationFn: async (input) => {
595
+ const bootstrappedClient = requireBootstrappedClient(client, "auth.verifyOtp");
596
+ return unwrapCapxulResult(await bootstrappedClient.auth.verifyOtp(input), bootstrappedClient._internal.telemetry, "mutation");
597
+ },
598
+ onSuccess: async () => {
599
+ await invalidateAuthBoundary(queryClient);
600
+ }
601
+ });
602
+ }
603
+ //#endregion
604
+ //#region src/hooks/use-capxul-sign-out.ts
605
+ function useCapxulSignOut() {
606
+ const client = useCapxulClientOrNull();
607
+ const queryClient = useQueryClient();
608
+ return useMutation({
609
+ onMutate: async () => {
610
+ await queryClient.cancelQueries({ queryKey: capxulKeys.accountBalance });
611
+ },
612
+ mutationFn: async () => {
613
+ const bootstrappedClient = requireBootstrappedClient(client, "auth.signOut");
614
+ return unwrapCapxulResult(await bootstrappedClient.auth.signOut(), bootstrappedClient._internal.telemetry, "mutation");
615
+ },
616
+ onSuccess: () => resetAuthBoundary(queryClient)
617
+ });
618
+ }
619
+ //#endregion
620
+ //#region src/hooks/use-capxul-sub-accounts.ts
621
+ function useCapxulSubAccountsList(accountId, options) {
622
+ const client = useCapxulClientOrNull();
623
+ return useQuery({
624
+ queryKey: capxulKeys.subAccounts(accountId),
625
+ queryFn: async () => {
626
+ if (accountId === void 0) throw Errors.invalidInput("accountId", "required for subAccounts.list");
627
+ const bootstrappedClient = requireBootstrappedClient(client, "subAccounts.list");
628
+ return unwrapCapxulResult(await bootstrappedClient.subAccounts.list(accountId), bootstrappedClient._internal.telemetry);
629
+ },
630
+ enabled: client !== null && (options?.enabled ?? true) && accountId !== void 0
631
+ });
632
+ }
633
+ function useCapxulSubAccountCreate() {
634
+ const client = useCapxulClientOrNull();
635
+ const queryClient = useQueryClient();
636
+ return useMutation({
637
+ mutationFn: async (input) => {
638
+ const bootstrappedClient = requireBootstrappedClient(client, "subAccounts.create");
639
+ return unwrapCapxulResult(await bootstrappedClient.subAccounts.create(input.accountId, { name: input.name }), bootstrappedClient._internal.telemetry, "mutation");
640
+ },
641
+ onSuccess: async (_value, variables) => {
642
+ await queryClient.invalidateQueries({ queryKey: capxulKeys.subAccounts(variables.accountId) });
643
+ await queryClient.invalidateQueries({ queryKey: capxulKeys.accountBalance });
644
+ }
645
+ });
646
+ }
647
+ function useCapxulSubAccountRename() {
648
+ const client = useCapxulClientOrNull();
649
+ const queryClient = useQueryClient();
650
+ return useMutation({
651
+ mutationFn: async (input) => {
652
+ const bootstrappedClient = requireBootstrappedClient(client, "subAccounts.rename");
653
+ return unwrapCapxulResult(await bootstrappedClient.subAccounts.rename(input.subAccountId, input.name), bootstrappedClient._internal.telemetry, "mutation");
654
+ },
655
+ onSuccess: async (_value, variables) => {
656
+ await queryClient.invalidateQueries({ queryKey: capxulKeys.subAccounts(variables.accountId) });
657
+ await queryClient.invalidateQueries({ queryKey: capxulKeys.accountBalance });
658
+ }
659
+ });
660
+ }
661
+ function useCapxulSubAccountDelete() {
662
+ const client = useCapxulClientOrNull();
663
+ const queryClient = useQueryClient();
664
+ return useMutation({
665
+ mutationFn: async (input) => {
666
+ const bootstrappedClient = requireBootstrappedClient(client, "subAccounts.delete");
667
+ return unwrapCapxulResult(await bootstrappedClient.subAccounts.delete(input.subAccountId), bootstrappedClient._internal.telemetry, "mutation");
668
+ },
669
+ onSuccess: async (_value, variables) => {
670
+ await queryClient.invalidateQueries({ queryKey: capxulKeys.subAccounts(variables.accountId) });
671
+ await queryClient.invalidateQueries({ queryKey: capxulKeys.accountBalance });
672
+ }
673
+ });
674
+ }
675
+ function useCapxulTransfer() {
676
+ const client = useCapxulClientOrNull();
677
+ const queryClient = useQueryClient();
678
+ return useMutation({
679
+ mutationFn: async ({ from, to, amount }) => {
680
+ const bootstrappedClient = requireBootstrappedClient(client, "subAccounts.transfer");
681
+ return unwrapCapxulResult(await bootstrappedClient.subAccounts.transfer({
682
+ from,
683
+ to,
684
+ amount
685
+ }), bootstrappedClient._internal.telemetry, "mutation");
686
+ },
687
+ onSuccess: async (_value, variables) => {
688
+ await queryClient.invalidateQueries({ queryKey: capxulKeys.subAccounts(variables.accountId) });
689
+ await queryClient.invalidateQueries({ queryKey: capxulKeys.accountBalance });
690
+ }
691
+ });
692
+ }
693
+ //#endregion
694
+ //#region src/internal/invalidate-money-state.ts
695
+ function isPayment(value) {
696
+ if (typeof value !== "object" || value === null) return false;
697
+ const record = value;
698
+ return typeof record.id === "string" && typeof record.status === "string" && typeof record.paymentType === "string" && typeof record.amount === "object" && record.amount !== null;
699
+ }
700
+ function paymentsFromValue(value) {
701
+ if (Array.isArray(value)) return value.filter(isPayment);
702
+ if (isPayment(value)) return [value];
703
+ if (typeof value !== "object" || value === null) return [];
704
+ const payments = value.payments;
705
+ return Array.isArray(payments) ? payments.filter(isPayment) : [];
706
+ }
707
+ async function invalidateMoneyState(queryClient, input) {
708
+ const invalidations = [
709
+ queryClient.invalidateQueries({ queryKey: capxulKeys.payments }),
710
+ queryClient.invalidateQueries({ queryKey: capxulKeys.actorInsightsSummary(input.actor) }),
711
+ queryClient.invalidateQueries({ queryKey: capxulKeys.actorInsightsHistory(input.actor) })
712
+ ];
713
+ if (input.payment !== void 0) invalidations.push(queryClient.invalidateQueries({ queryKey: capxulKeys.payment(input.payment.id) }));
714
+ if (input.actor.kind === "account") invalidations.push(queryClient.invalidateQueries({ queryKey: capxulKeys.accountBalance }));
715
+ else invalidations.push(queryClient.invalidateQueries({ queryKey: capxulKeys.orgTreasury(input.actor.orgId) }));
716
+ if (input.includeAddressBook === true) invalidations.push(queryClient.invalidateQueries({ queryKey: capxulKeys.actorAddressBook(input.actor) }));
717
+ await Promise.all(invalidations);
718
+ }
719
+ //#endregion
720
+ //#region src/hooks/use-capxul-money.ts
721
+ function useCapxulPay() {
722
+ const client = useCapxulClientOrNull();
723
+ const queryClient = useQueryClient();
724
+ return useMutation({
725
+ mutationFn: async (input) => {
726
+ const bootstrappedClient = requireBootstrappedClient(client, "payments.pay");
727
+ return unwrapCapxulResult(await bootstrappedClient.payments.pay(input), bootstrappedClient._internal.telemetry, "mutation");
728
+ },
729
+ onSuccess: async (payment) => {
730
+ await invalidateMoneyState(queryClient, {
731
+ actor: { kind: "account" },
732
+ payment,
733
+ includeAddressBook: true
734
+ });
735
+ }
736
+ });
737
+ }
738
+ function useCapxulPayout() {
739
+ const client = useCapxulClientOrNull();
740
+ const queryClient = useQueryClient();
741
+ return useMutation({
742
+ mutationFn: async (input) => {
743
+ const bootstrappedClient = requireBootstrappedClient(client, "payments.payout");
744
+ return unwrapCapxulResult(await bootstrappedClient.payments.payout(input), bootstrappedClient._internal.telemetry, "mutation");
745
+ },
746
+ onSuccess: async (payment, variables) => {
747
+ await invalidateMoneyState(queryClient, {
748
+ actor: variables.actor ?? { kind: "account" },
749
+ payment
750
+ });
751
+ }
752
+ });
753
+ }
754
+ function useCapxulWithdraw() {
755
+ const client = useCapxulClientOrNull();
756
+ const queryClient = useQueryClient();
757
+ return useMutation({
758
+ mutationFn: async (input) => {
759
+ const bootstrappedClient = requireBootstrappedClient(client, "payments.withdraw");
760
+ return unwrapCapxulResult(await bootstrappedClient.payments.withdraw(input), bootstrappedClient._internal.telemetry, "mutation");
761
+ },
762
+ onSuccess: async (payment) => {
763
+ await invalidateMoneyState(queryClient, {
764
+ actor: { kind: "account" },
765
+ payment
766
+ });
767
+ }
768
+ });
769
+ }
770
+ function useCapxulPayments(options) {
771
+ const client = useCapxulClientOrNull();
772
+ return useQuery({
773
+ queryKey: capxulKeys.payments,
774
+ queryFn: async () => {
775
+ const bootstrappedClient = requireBootstrappedClient(client, "payments.list");
776
+ return unwrapCapxulResult(await bootstrappedClient.payments.list(), bootstrappedClient._internal.telemetry);
777
+ },
778
+ enabled: client !== null && (options?.enabled ?? true)
779
+ });
780
+ }
781
+ function useCapxulPayment(paymentId, options) {
782
+ const client = useCapxulClientOrNull();
783
+ return useQuery({
784
+ queryKey: capxulKeys.payment(paymentId),
785
+ queryFn: async () => {
786
+ if (paymentId === void 0) throw Errors.invalidInput("paymentId", "required for payments.get");
787
+ const bootstrappedClient = requireBootstrappedClient(client, "payments.get");
788
+ return unwrapCapxulResult(await bootstrappedClient.payments.get(paymentId), bootstrappedClient._internal.telemetry);
789
+ },
790
+ enabled: client !== null && paymentId !== void 0 && (options?.enabled ?? true)
791
+ });
792
+ }
793
+ //#endregion
794
+ //#region src/hooks/use-capxul-actor-scope.ts
795
+ const capxulAccountScope = { kind: "account" };
796
+ function capxulOrgScope(orgId) {
797
+ return orgId === void 0 ? void 0 : {
798
+ kind: "org",
799
+ orgId
800
+ };
801
+ }
802
+ function requireActorScope(actor, operation) {
803
+ if (actor === void 0) throw Errors.invalidInput("actor", `required for ${operation}`);
804
+ return actor;
805
+ }
806
+ function actorMethods(client, actor) {
807
+ return actor.kind === "account" ? client.account : client.org(actor.orgId);
808
+ }
809
+ function entryIdFromData(data) {
810
+ if (typeof data !== "object" || data === null) return void 0;
811
+ const id = data.id;
812
+ return typeof id === "string" ? id : void 0;
813
+ }
814
+ function requestIdFromMutation(data, variables) {
815
+ if (typeof variables === "string") return variables;
816
+ if (typeof variables === "object" && variables !== null) {
817
+ const requestId = variables.requestId;
818
+ if (typeof requestId === "string") return requestId;
819
+ }
820
+ if (isPayment(data)) return void 0;
821
+ return entryIdFromData(data);
822
+ }
823
+ function useCapxulAddressBook(actor, options) {
824
+ const client = useCapxulClientOrNull();
825
+ return useQuery({
826
+ queryKey: capxulKeys.actorAddressBook(actor),
827
+ queryFn: async () => {
828
+ const bootstrappedClient = requireBootstrappedClient(client, "addressBook.list");
829
+ return unwrapCapxulResult(await actorMethods(bootstrappedClient, requireActorScope(actor, "addressBook.list")).addressBook.list(), bootstrappedClient._internal.telemetry);
830
+ },
831
+ enabled: client !== null && actor !== void 0 && (options?.enabled ?? true)
832
+ });
833
+ }
834
+ function useCapxulAddressBookEntry(actor, entryId, options) {
835
+ const client = useCapxulClientOrNull();
836
+ return useQuery({
837
+ queryKey: capxulKeys.actorAddressBookEntry(actor, entryId),
838
+ queryFn: async () => {
839
+ if (entryId === void 0) throw Errors.invalidInput("entryId", "required for addressBook.get");
840
+ const bootstrappedClient = requireBootstrappedClient(client, "addressBook.get");
841
+ return unwrapCapxulResult(await actorMethods(bootstrappedClient, requireActorScope(actor, "addressBook.get")).addressBook.get(entryId), bootstrappedClient._internal.telemetry);
842
+ },
843
+ enabled: client !== null && actor !== void 0 && entryId !== void 0 && (options?.enabled ?? true)
844
+ });
845
+ }
846
+ function useAddressBookMutation(actor, operation, run) {
847
+ const client = useCapxulClientOrNull();
848
+ const queryClient = useQueryClient();
849
+ return useMutation({
850
+ mutationFn: async (variables) => {
851
+ const bootstrappedClient = requireBootstrappedClient(client, operation);
852
+ return unwrapCapxulResult(await run(actorMethods(bootstrappedClient, requireActorScope(actor, operation)), variables), bootstrappedClient._internal.telemetry, "mutation");
853
+ },
854
+ onSuccess: async (data) => {
855
+ await queryClient.invalidateQueries({ queryKey: capxulKeys.actorAddressBook(actor) });
856
+ const entryId = entryIdFromData(data);
857
+ if (entryId !== void 0) await queryClient.invalidateQueries({ queryKey: capxulKeys.actorAddressBookEntry(actor, entryId) });
858
+ }
859
+ });
860
+ }
861
+ const useCapxulAddAddressBookEntry = (actor = capxulAccountScope) => useAddressBookMutation(actor, "addressBook.add", (methods, input) => methods.addressBook.add(input));
862
+ const useCapxulHideAddressBookEntry = (actor = capxulAccountScope) => useAddressBookMutation(actor, "addressBook.hide", (methods, entryId) => methods.addressBook.hide(entryId));
863
+ const useCapxulUnhideAddressBookEntry = (actor = capxulAccountScope) => useAddressBookMutation(actor, "addressBook.unhide", (methods, entryId) => methods.addressBook.unhide(entryId));
864
+ const useCapxulLabelAddressBookEntry = (actor = capxulAccountScope) => useAddressBookMutation(actor, "addressBook.label", (methods, input) => methods.addressBook.label(input));
865
+ function useCapxulRequests(actor, options) {
866
+ const client = useCapxulClientOrNull();
867
+ return useQuery({
868
+ queryKey: capxulKeys.actorRequests(actor),
869
+ queryFn: async () => {
870
+ const bootstrappedClient = requireBootstrappedClient(client, "requests.list");
871
+ return unwrapCapxulResult(await actorMethods(bootstrappedClient, requireActorScope(actor, "requests.list")).requests.list(), bootstrappedClient._internal.telemetry);
872
+ },
873
+ enabled: client !== null && actor !== void 0 && (options?.enabled ?? true)
874
+ });
875
+ }
876
+ function useCapxulRequest(actor, requestId, options) {
877
+ const client = useCapxulClientOrNull();
878
+ return useQuery({
879
+ queryKey: capxulKeys.actorRequest(actor, requestId),
880
+ queryFn: async () => {
881
+ if (requestId === void 0) throw Errors.invalidInput("requestId", "required for requests.get");
882
+ const bootstrappedClient = requireBootstrappedClient(client, "requests.get");
883
+ return unwrapCapxulResult(await actorMethods(bootstrappedClient, requireActorScope(actor, "requests.get")).requests.get(requestId), bootstrappedClient._internal.telemetry);
884
+ },
885
+ enabled: client !== null && actor !== void 0 && requestId !== void 0 && (options?.enabled ?? true)
886
+ });
887
+ }
888
+ function useRequestMutation(actor, operation, run, invalidateInbox = false) {
889
+ const client = useCapxulClientOrNull();
890
+ const queryClient = useQueryClient();
891
+ return useMutation({
892
+ mutationFn: async (variables) => {
893
+ const bootstrappedClient = requireBootstrappedClient(client, operation);
894
+ return unwrapCapxulResult(await run(actorMethods(bootstrappedClient, requireActorScope(actor, operation)), variables), bootstrappedClient._internal.telemetry, "mutation");
895
+ },
896
+ onSuccess: async (data, variables) => {
897
+ await queryClient.invalidateQueries({ queryKey: capxulKeys.actorRequests(actor) });
898
+ await queryClient.invalidateQueries({ queryKey: capxulKeys.actorAddressBook(actor) });
899
+ const requestId = requestIdFromMutation(data, variables);
900
+ if (requestId !== void 0) await queryClient.invalidateQueries({ queryKey: capxulKeys.actorRequest(actor, requestId) });
901
+ if (invalidateInbox) await queryClient.invalidateQueries({ queryKey: capxulKeys.actorInbox(actor) });
902
+ await queryClient.invalidateQueries({ queryKey: capxulKeys.actorInsightsSummary(actor) });
903
+ await queryClient.invalidateQueries({ queryKey: capxulKeys.actorInsightsHistory(actor) });
904
+ if (isPayment(data)) await invalidateMoneyState(queryClient, {
905
+ actor: requireActorScope(actor, operation),
906
+ payment: data
907
+ });
908
+ }
909
+ });
910
+ }
911
+ const useCapxulIssueRequest = (actor = capxulAccountScope) => useRequestMutation(actor, "requests.issue", (methods, input) => methods.requests.issue(input));
912
+ const useCapxulCancelRequest = (actor = capxulAccountScope) => useRequestMutation(actor, "requests.cancel", (methods, requestId) => methods.requests.cancel(requestId), true);
913
+ const useCapxulReconcileRequests = (actor = capxulAccountScope) => useRequestMutation(actor, "requests.reconcile", (methods) => methods.requests.reconcile());
914
+ function useCapxulInbox(actor, options) {
915
+ const client = useCapxulClientOrNull();
916
+ return useQuery({
917
+ queryKey: capxulKeys.actorInbox(actor),
918
+ queryFn: async () => {
919
+ const bootstrappedClient = requireBootstrappedClient(client, "inbox.list");
920
+ return unwrapCapxulResult(await actorMethods(bootstrappedClient, requireActorScope(actor, "inbox.list")).inbox.list(), bootstrappedClient._internal.telemetry);
921
+ },
922
+ enabled: client !== null && actor !== void 0 && (options?.enabled ?? true)
923
+ });
924
+ }
925
+ const useCapxulApproveInboxRequest = (actor = capxulAccountScope) => useRequestMutation(actor, "inbox.approve", (methods, input) => methods.inbox.approve(input), true);
926
+ const useCapxulDeclineInboxRequest = (actor = capxulAccountScope) => useRequestMutation(actor, "inbox.decline", (methods, requestId) => methods.inbox.decline(requestId), true);
927
+ function useCapxulInsightsSummary(actor, options) {
928
+ const client = useCapxulClientOrNull();
929
+ return useQuery({
930
+ queryKey: capxulKeys.actorInsightsSummary(actor),
931
+ queryFn: async () => {
932
+ const bootstrappedClient = requireBootstrappedClient(client, "insights.summary");
933
+ return unwrapCapxulResult(await actorMethods(bootstrappedClient, requireActorScope(actor, "insights.summary")).insights.summary(), bootstrappedClient._internal.telemetry);
934
+ },
935
+ enabled: client !== null && actor !== void 0 && (options?.enabled ?? true)
936
+ });
937
+ }
938
+ function useCapxulInsightsHistory(actor, options) {
939
+ const client = useCapxulClientOrNull();
940
+ return useQuery({
941
+ queryKey: capxulKeys.actorInsightsHistory(actor),
942
+ queryFn: async () => {
943
+ const bootstrappedClient = requireBootstrappedClient(client, "insights.history");
944
+ return unwrapCapxulResult(await actorMethods(bootstrappedClient, requireActorScope(actor, "insights.history")).insights.history(), bootstrappedClient._internal.telemetry);
945
+ },
946
+ enabled: client !== null && actor !== void 0 && (options?.enabled ?? true)
947
+ });
948
+ }
949
+ //#endregion
950
+ //#region src/hooks/use-capxul-destinations.ts
951
+ function refKeyForRef(ref) {
952
+ switch (ref.kind) {
953
+ case "handle": return `handle:${ref.handle}`;
954
+ case "email": return `email:${ref.email}`;
955
+ case "orgHandle": return `orgHandle:${ref.orgHandle}`;
956
+ case "capxulUserId": return `capxulUserId:${ref.capxulUserId}`;
957
+ case "payeeId": return `payeeId:${ref.payeeId}`;
958
+ }
959
+ }
960
+ function refCacheKey(input) {
961
+ return input === void 0 ? void 0 : refKeyForRef(input.ref);
962
+ }
963
+ function useCapxulDestinations(input, options) {
964
+ const client = useCapxulClientOrNull();
965
+ return useQuery({
966
+ queryKey: capxulKeys.actorDestinations(input?.actor ?? { kind: "account" }, refCacheKey(input)),
967
+ queryFn: async () => {
968
+ if (input === void 0) throw Errors.invalidInput("ref", "required for destinations.list");
969
+ const bootstrappedClient = requireBootstrappedClient(client, "destinations.list");
970
+ return unwrapCapxulResult(await bootstrappedClient.destinations.list(input), bootstrappedClient._internal.telemetry);
971
+ },
972
+ enabled: client !== null && input !== void 0 && (options?.enabled ?? true)
973
+ });
974
+ }
975
+ function useCapxulAddDestination() {
976
+ const client = useCapxulClientOrNull();
977
+ const queryClient = useQueryClient();
978
+ return useMutation({
979
+ mutationFn: async (input) => {
980
+ const bootstrappedClient = requireBootstrappedClient(client, "destinations.add");
981
+ return unwrapCapxulResult(await bootstrappedClient.destinations.add(input), bootstrappedClient._internal.telemetry, "mutation");
982
+ },
983
+ onSuccess: async (_value, variables) => {
984
+ await queryClient.invalidateQueries({ queryKey: capxulKeys.actorDestinationsScope(variables.actor ?? { kind: "account" }) });
985
+ await queryClient.invalidateQueries({ queryKey: capxulKeys.actorAddressBook(variables.actor ?? { kind: "account" }) });
986
+ }
987
+ });
988
+ }
989
+ function useCapxulRemoveDestination() {
990
+ const client = useCapxulClientOrNull();
991
+ const queryClient = useQueryClient();
992
+ return useMutation({
993
+ mutationFn: async (input) => {
994
+ const bootstrappedClient = requireBootstrappedClient(client, "destinations.remove");
995
+ return unwrapCapxulResult(await bootstrappedClient.destinations.remove(input), bootstrappedClient._internal.telemetry, "mutation");
996
+ },
997
+ onSuccess: async (_value, variables) => {
998
+ await queryClient.invalidateQueries({ queryKey: capxulKeys.actorDestinationsScope(variables.actor ?? { kind: "account" }) });
999
+ }
1000
+ });
1001
+ }
1002
+ //#endregion
1003
+ //#region src/hooks/use-capxul-payroll.ts
1004
+ function useCapxulPayrollRoster(orgId, options) {
1005
+ const client = useCapxulClientOrNull();
1006
+ return useQuery({
1007
+ queryKey: capxulKeys.payrollRoster(orgId),
1008
+ queryFn: async () => {
1009
+ if (orgId === void 0) throw Errors.invalidInput("orgId", "required for payroll.roster.list");
1010
+ const bootstrappedClient = requireBootstrappedClient(client, "payroll.roster.list");
1011
+ return unwrapCapxulResult(await bootstrappedClient.org(orgId).payroll.roster.list(), bootstrappedClient._internal.telemetry);
1012
+ },
1013
+ enabled: client !== null && orgId !== void 0 && (options?.enabled ?? true)
1014
+ });
1015
+ }
1016
+ function usePayrollMutation(orgId, operation, run) {
1017
+ const client = useCapxulClientOrNull();
1018
+ const queryClient = useQueryClient();
1019
+ return useMutation({
1020
+ mutationFn: async (variables) => {
1021
+ if (orgId === void 0) throw Errors.invalidInput("orgId", `required for ${operation}`);
1022
+ const bootstrappedClient = requireBootstrappedClient(client, operation);
1023
+ return unwrapCapxulResult(await run(bootstrappedClient.org(orgId), variables), bootstrappedClient._internal.telemetry, "mutation");
1024
+ },
1025
+ onSuccess: async (data) => {
1026
+ await queryClient.invalidateQueries({ queryKey: capxulKeys.payrollRoster(orgId) });
1027
+ await queryClient.invalidateQueries({ queryKey: capxulKeys.actorInsightsSummary(orgId === void 0 ? void 0 : {
1028
+ kind: "org",
1029
+ orgId
1030
+ }) });
1031
+ await queryClient.invalidateQueries({ queryKey: capxulKeys.actorInsightsHistory(orgId === void 0 ? void 0 : {
1032
+ kind: "org",
1033
+ orgId
1034
+ }) });
1035
+ if (orgId === void 0) return;
1036
+ const actor = {
1037
+ kind: "org",
1038
+ orgId
1039
+ };
1040
+ const payments = paymentsFromValue(data);
1041
+ if (payments.length === 0) return;
1042
+ await Promise.all(payments.map((payment) => invalidateMoneyState(queryClient, {
1043
+ actor,
1044
+ payment,
1045
+ includeAddressBook: true
1046
+ })));
1047
+ }
1048
+ });
1049
+ }
1050
+ const useCapxulAddPayrollRosterLine = (orgId) => usePayrollMutation(orgId, "payroll.roster.add", (org, input) => org.payroll.roster.add(input));
1051
+ const useCapxulUpdatePayrollRosterLine = (orgId) => usePayrollMutation(orgId, "payroll.roster.update", (org, variables) => org.payroll.roster.update(variables.rosterLineId, variables.input));
1052
+ const useCapxulRemovePayrollRosterLine = (orgId) => usePayrollMutation(orgId, "payroll.roster.remove", (org, rosterLineId) => org.payroll.roster.remove(rosterLineId));
1053
+ const useCapxulRunPayroll = (orgId) => usePayrollMutation(orgId, "payroll.run", (org, input) => org.payroll.run(input));
1054
+ //#endregion
1055
+ //#region src/hooks/use-capxul-orgs.ts
1056
+ function useCapxulOrgs(options) {
1057
+ const client = useCapxulClientOrNull();
1058
+ return useQuery({
1059
+ queryKey: capxulKeys.orgs,
1060
+ queryFn: async () => {
1061
+ const bootstrappedClient = requireBootstrappedClient(client, "orgs");
1062
+ return unwrapCapxulResult(await bootstrappedClient.orgs(), bootstrappedClient._internal.telemetry);
1063
+ },
1064
+ enabled: client !== null && (options?.enabled ?? true)
1065
+ });
1066
+ }
1067
+ //#endregion
1068
+ //#region src/hooks/use-capxul-org.ts
1069
+ function useCapxulOrg(orgId, options) {
1070
+ const client = useCapxulClient();
1071
+ return useQuery({
1072
+ queryKey: capxulKeys.org(orgId),
1073
+ queryFn: async () => {
1074
+ if (orgId === void 0) throw Errors.invalidInput("orgId", "required for useCapxulOrg");
1075
+ return unwrapCapxulResult(await client.orgs(), client._internal.telemetry).find((org) => org.id === orgId) ?? null;
1076
+ },
1077
+ enabled: (options?.enabled ?? true) && orgId !== void 0
1078
+ });
1079
+ }
1080
+ //#endregion
1081
+ //#region src/hooks/use-capxul-org-members.ts
1082
+ function useCapxulOrgMembers(orgId, options) {
1083
+ const client = useCapxulClient();
1084
+ return useQuery({
1085
+ queryKey: capxulKeys.orgMembers(orgId),
1086
+ queryFn: async () => {
1087
+ if (orgId === void 0) throw Errors.invalidInput("orgId", "required for useCapxulOrgMembers");
1088
+ return unwrapCapxulResult(await client.org(orgId).members(), client._internal.telemetry);
1089
+ },
1090
+ enabled: (options?.enabled ?? true) && orgId !== void 0
1091
+ });
1092
+ }
1093
+ //#endregion
1094
+ //#region src/hooks/use-capxul-org-roles.ts
1095
+ function useCapxulOrgRoles(orgId, options) {
1096
+ const client = useCapxulClient();
1097
+ return useQuery({
1098
+ queryKey: capxulKeys.orgRoles(orgId),
1099
+ queryFn: async () => {
1100
+ if (orgId === void 0) throw Errors.invalidInput("orgId", "required for useCapxulOrgRoles");
1101
+ return unwrapCapxulResult(await client.org(orgId).roles(), client._internal.telemetry);
1102
+ },
1103
+ enabled: (options?.enabled ?? true) && orgId !== void 0
1104
+ });
1105
+ }
1106
+ //#endregion
1107
+ //#region src/hooks/use-capxul-org-deploy-roles.ts
1108
+ function useCapxulOrgDeployRoles() {
1109
+ const client = useCapxulClient();
1110
+ const queryClient = useQueryClient();
1111
+ return useMutation({
1112
+ mutationFn: async (orgId) => {
1113
+ return unwrapCapxulResult(await client.org(orgId).deployRoles(), client._internal.telemetry, "mutation");
1114
+ },
1115
+ onSuccess: async (_roles, orgId) => {
1116
+ await queryClient.invalidateQueries({ queryKey: capxulKeys.orgRoles(orgId) });
1117
+ await queryClient.invalidateQueries({ queryKey: capxulKeys.org(orgId) });
1118
+ await queryClient.invalidateQueries({ queryKey: capxulKeys.orgs });
1119
+ }
1120
+ });
1121
+ }
1122
+ //#endregion
1123
+ //#region src/hooks/use-capxul-org-treasury.ts
1124
+ function useCapxulOrgTreasury(orgId, options) {
1125
+ const client = useCapxulClient();
1126
+ return useQuery({
1127
+ queryKey: capxulKeys.orgTreasury(orgId),
1128
+ queryFn: async () => {
1129
+ if (orgId === void 0) throw Errors.invalidInput("orgId", "required for useCapxulOrgTreasury");
1130
+ return unwrapCapxulResult(await client.org(orgId).treasury(), client._internal.telemetry);
1131
+ },
1132
+ enabled: (options?.enabled ?? true) && orgId !== void 0
1133
+ });
1134
+ }
1135
+ //#endregion
1136
+ //#region src/hooks/use-capxul-create-org.ts
1137
+ function useCapxulCreateOrg() {
1138
+ const client = useCapxulClient();
1139
+ const queryClient = useQueryClient();
1140
+ return useMutation({
1141
+ mutationFn: async (input) => unwrapCapxulResult(await client.createOrg(input), client._internal.telemetry, "mutation"),
1142
+ onSuccess: async () => {
1143
+ await queryClient.invalidateQueries({ queryKey: capxulKeys.orgs });
1144
+ }
1145
+ });
1146
+ }
1147
+ //#endregion
1148
+ //#region src/hooks/use-capxul-complete-personal-onboarding.ts
1149
+ function useCapxulCompletePersonalOnboarding() {
1150
+ const client = useCapxulClient();
1151
+ const queryClient = useQueryClient();
1152
+ return useMutation({
1153
+ mutationFn: async (input) => unwrapCapxulResult(await client.onboarding.completePersonal(input), client._internal.telemetry, "mutation"),
1154
+ onSuccess: async () => {
1155
+ await Promise.all([queryClient.invalidateQueries({ queryKey: capxulKeys.profile }), queryClient.invalidateQueries({ queryKey: capxulKeys.accountLifecycle })]);
1156
+ }
1157
+ });
1158
+ }
1159
+ //#endregion
1160
+ //#region src/hooks/use-capxul-complete-organization-onboarding.ts
1161
+ function useCapxulCompleteOrganizationOnboarding() {
1162
+ const client = useCapxulClient();
1163
+ const queryClient = useQueryClient();
1164
+ return useMutation({
1165
+ mutationFn: async (input) => unwrapCapxulResult(await client.onboarding.completeOrganization(input), client._internal.telemetry, "mutation"),
1166
+ onSuccess: async () => {
1167
+ await Promise.all([
1168
+ queryClient.invalidateQueries({ queryKey: capxulKeys.profile }),
1169
+ queryClient.invalidateQueries({ queryKey: capxulKeys.accountLifecycle }),
1170
+ queryClient.invalidateQueries({ queryKey: capxulKeys.orgs })
1171
+ ]);
1172
+ }
1173
+ });
1174
+ }
1175
+ //#endregion
1176
+ //#region src/hooks/use-capxul-invite-member.ts
1177
+ function useCapxulInviteMember(orgId) {
1178
+ const client = useCapxulClient();
1179
+ const queryClient = useQueryClient();
1180
+ return useMutation({
1181
+ mutationFn: async (input) => {
1182
+ if (orgId === void 0) throw Errors.invalidInput("orgId", "required for useCapxulInviteMember");
1183
+ return unwrapCapxulResult(await client.org(orgId).invite(input), client._internal.telemetry, "mutation");
1184
+ },
1185
+ onSuccess: async () => {
1186
+ if (orgId === void 0) return;
1187
+ await queryClient.invalidateQueries({ queryKey: capxulKeys.orgMembers(orgId) });
1188
+ }
1189
+ });
1190
+ }
1191
+ //#endregion
1192
+ //#region src/hooks/use-capxul-remove-member.ts
1193
+ function useCapxulRemoveMember(orgId) {
1194
+ const client = useCapxulClient();
1195
+ const queryClient = useQueryClient();
1196
+ return useMutation({
1197
+ mutationFn: async (input) => {
1198
+ if (orgId === void 0) throw Errors.invalidInput("orgId", "required for useCapxulRemoveMember");
1199
+ return unwrapCapxulResult(await client.org(orgId).removeMember(input), client._internal.telemetry, "mutation");
1200
+ },
1201
+ onSuccess: async () => {
1202
+ if (orgId === void 0) return;
1203
+ await queryClient.invalidateQueries({ queryKey: capxulKeys.orgMembers(orgId) });
1204
+ }
1205
+ });
1206
+ }
1207
+ //#endregion
1208
+ //#region src/hooks/use-capxul-assign-role.ts
1209
+ function useCapxulAssignRole(orgId) {
1210
+ const client = useCapxulClient();
1211
+ const queryClient = useQueryClient();
1212
+ return useMutation({
1213
+ mutationFn: async (input) => {
1214
+ if (orgId === void 0) throw Errors.invalidInput("orgId", "required for useCapxulAssignRole");
1215
+ return unwrapCapxulResult(await client.org(orgId).assignRole(input), client._internal.telemetry, "mutation");
1216
+ },
1217
+ onSuccess: async () => {
1218
+ if (orgId === void 0) return;
1219
+ await queryClient.invalidateQueries({ queryKey: capxulKeys.orgMembers(orgId) });
1220
+ }
1221
+ });
1222
+ }
1223
+ //#endregion
1224
+ //#region src/hooks/use-capxul-switch-acting-entity.ts
1225
+ function useCapxulSwitchActingEntity() {
1226
+ return useMutation({ mutationFn: async (_input) => void 0 });
1227
+ }
1228
+ //#endregion
1229
+ //#region src/headless/shared/headless-error-view.ts
1230
+ const FAILURE_MODES = new Set([
1231
+ "auth-origin-mismatch",
1232
+ "stale-openfort-cache",
1233
+ "app-env-allowlist",
1234
+ "no-secure-context",
1235
+ "unknown"
1236
+ ]);
1237
+ function isFailureMode(value) {
1238
+ return typeof value === "string" && FAILURE_MODES.has(value);
1239
+ }
1240
+ function getFailureMode(error) {
1241
+ const candidate = error.details?.failure_mode;
1242
+ return isFailureMode(candidate) ? candidate : void 0;
1243
+ }
1244
+ const FAILURE_USER_MESSAGES = {
1245
+ "auth-origin-mismatch": "Your sign-in session is not visible to the wallet. Sign out and sign in again.",
1246
+ "stale-openfort-cache": "Stale wallet data from a previous session is blocking setup. Sign out, then sign in with your current email.",
1247
+ "app-env-allowlist": "This app origin is not authorized for the publishable key. Check configuration.",
1248
+ "no-secure-context": "Your browser cannot access secure wallet features. Open the app in a standard browser window.",
1249
+ unknown: "Something went wrong setting up your wallet. Try again or sign out and sign in."
1250
+ };
1251
+ const FAILURE_SUGGESTED_ACTIONS = {
1252
+ "auth-origin-mismatch": "sign_out_and_in",
1253
+ "stale-openfort-cache": "sign_out_and_in",
1254
+ "app-env-allowlist": "check_configuration",
1255
+ "no-secure-context": "check_configuration",
1256
+ unknown: "retry"
1257
+ };
1258
+ const FAILURE_RECOVERABLE = {
1259
+ "auth-origin-mismatch": false,
1260
+ "stale-openfort-cache": true,
1261
+ "app-env-allowlist": false,
1262
+ "no-secure-context": false,
1263
+ unknown: true
1264
+ };
1265
+ function coerceToCapxulError(cause) {
1266
+ if (isCapxulError(cause)) return cause;
1267
+ if (cause instanceof Error) return Errors.unknown(cause);
1268
+ return Errors.unknown(String(cause));
1269
+ }
1270
+ function toHeadlessErrorView(error) {
1271
+ const failureMode = getFailureMode(error);
1272
+ const suggestedAction = failureMode ? FAILURE_SUGGESTED_ACTIONS[failureMode] : defaultSuggestedAction(error);
1273
+ const userMessage = failureMode ? FAILURE_USER_MESSAGES[failureMode] : defaultUserMessage(error);
1274
+ const recoverable = failureMode ? FAILURE_RECOVERABLE[failureMode] : defaultRecoverable(error);
1275
+ return {
1276
+ code: error.code,
1277
+ failureMode,
1278
+ userMessage,
1279
+ suggestedAction,
1280
+ recoverable,
1281
+ diagnostics: buildDiagnostics(error, failureMode),
1282
+ correlationId: error.correlationId
1283
+ };
1284
+ }
1285
+ function defaultUserMessage(error) {
1286
+ if (error.code === "OTP_EXPIRED") return "Verification code has expired. Request a new one.";
1287
+ if (error.code === "NOT_AUTHENTICATED") return "You are not signed in. Sign in and try again.";
1288
+ if (error.code === "RATE_LIMITED") return "Too many attempts. Wait a moment and try again.";
1289
+ if (error.code === "NETWORK_ERROR") return "Network error. Check your connection and try again.";
1290
+ return error.message;
1291
+ }
1292
+ function defaultSuggestedAction(error) {
1293
+ switch (error.code) {
1294
+ case "NOT_AUTHENTICATED":
1295
+ case "OTP_EXPIRED":
1296
+ case "WRONG_STATE": return "sign_out_and_in";
1297
+ case "ENV_MISSING": return "check_configuration";
1298
+ case "RATE_LIMITED":
1299
+ case "NETWORK_ERROR":
1300
+ case "PROVIDER_ERROR":
1301
+ case "TRANSACTION_FAILED": return "retry";
1302
+ default: return "contact_support";
1303
+ }
1304
+ }
1305
+ function defaultRecoverable(error) {
1306
+ switch (error.code) {
1307
+ case "ENV_MISSING":
1308
+ case "NOT_IMPLEMENTED": return false;
1309
+ default: return true;
1310
+ }
1311
+ }
1312
+ function buildDiagnostics(error, failureMode) {
1313
+ const parts = [`code=${error.code}`];
1314
+ if (failureMode !== void 0) parts.push(`failure_mode=${failureMode}`);
1315
+ if (error.layer !== void 0) parts.push(`layer=${error.layer}`);
1316
+ const provider = error.details?.provider;
1317
+ if (typeof provider === "string") parts.push(`provider=${provider}`);
1318
+ const operation = error.details?.operation;
1319
+ if (typeof operation === "string") parts.push(`operation=${operation}`);
1320
+ return parts.join(" ");
1321
+ }
1322
+ //#endregion
1323
+ //#region src/headless/shared/types.ts
1324
+ function toQuerySlotState(query) {
1325
+ return {
1326
+ data: query.data,
1327
+ isLoading: query.isLoading,
1328
+ isFetching: query.isFetching,
1329
+ isError: query.isError,
1330
+ error: query.error === null ? null : toHeadlessErrorView(query.error)
1331
+ };
1332
+ }
1333
+ //#endregion
1334
+ //#region ../types/src/index.ts
1335
+ const SUPPORTED_CURRENCIES = [
1336
+ {
1337
+ code: "USD",
1338
+ symbol: "$",
1339
+ name: "US Dollar"
1340
+ },
1341
+ {
1342
+ code: "NGN",
1343
+ symbol: "NGN",
1344
+ name: "Nigerian Naira"
1345
+ },
1346
+ {
1347
+ code: "GHS",
1348
+ symbol: "GHS",
1349
+ name: "Ghanaian Cedi"
1350
+ },
1351
+ {
1352
+ code: "KES",
1353
+ symbol: "KSh",
1354
+ name: "Kenyan Shilling"
1355
+ },
1356
+ {
1357
+ code: "UGX",
1358
+ symbol: "USh",
1359
+ name: "Ugandan Shilling"
1360
+ }
1361
+ ];
1362
+ SUPPORTED_CURRENCIES.map((currency) => currency.code);
1363
+ Object.fromEntries(SUPPORTED_CURRENCIES.map((currency) => [currency.code, currency.symbol]));
1364
+ Math.floor(Number.MAX_SAFE_INTEGER / 1e3);
1365
+ //#endregion
1366
+ //#region src/headless/money/SendMoney.tsx
1367
+ function SendMoney({ initialValue = null, slots, onSent }) {
1368
+ const pay = useCapxulPay();
1369
+ const [value, setValue] = useState(initialValue);
1370
+ const [error, setError] = useState(null);
1371
+ const submit = async () => {
1372
+ setError(null);
1373
+ if (value === null) return;
1374
+ try {
1375
+ await pay.mutateAsync(value);
1376
+ onSent?.();
1377
+ } catch (cause) {
1378
+ setError(toHeadlessErrorView(coerceToCapxulError(cause)));
1379
+ }
1380
+ };
1381
+ const slot = slots.form?.({
1382
+ value,
1383
+ setValue,
1384
+ submit: () => void submit(),
1385
+ pending: pay.isPending,
1386
+ disabled: pay.isPending || value === null,
1387
+ succeeded: pay.isSuccess,
1388
+ error
1389
+ });
1390
+ const children = /* @__PURE__ */ jsxs(Fragment, { children: [slot, error === null ? null : slots.error?.(error)] });
1391
+ return slots.root?.({ children }) ?? children;
1392
+ }
1393
+ //#endregion
1394
+ //#region src/headless/relationship/AddressBook.tsx
1395
+ function AddressBook(props) {
1396
+ const { slots } = props;
1397
+ const actor = "actor" in props ? props.actor : capxulAccountScope;
1398
+ const entries = useCapxulAddressBook(actor);
1399
+ const add = useCapxulAddAddressBookEntry(actor);
1400
+ const hide = useCapxulHideAddressBookEntry(actor);
1401
+ const unhide = useCapxulUnhideAddressBookEntry(actor);
1402
+ const label = useCapxulLabelAddressBookEntry(actor);
1403
+ const pending = add.isPending || hide.isPending || unhide.isPending || label.isPending;
1404
+ const children = /* @__PURE__ */ jsxs(Fragment, { children: [slots.entries?.(toQuerySlotState(entries)), slots.actions?.({
1405
+ add: (input) => add.mutateAsync(input),
1406
+ hide: (entryId) => hide.mutateAsync(entryId),
1407
+ unhide: (entryId) => unhide.mutateAsync(entryId),
1408
+ label: (input) => label.mutateAsync(input),
1409
+ pending,
1410
+ disabled: pending || actor === void 0
1411
+ })] });
1412
+ return slots.root?.({ children }) ?? children;
1413
+ }
1414
+ //#endregion
1415
+ //#region src/headless/relationship/RequestInbox.tsx
1416
+ function RequestInbox(props) {
1417
+ const { slots } = props;
1418
+ const actor = "actor" in props ? props.actor : capxulAccountScope;
1419
+ const requests = useCapxulRequests(actor);
1420
+ const inbox = useCapxulInbox(actor);
1421
+ const issue = useCapxulIssueRequest(actor);
1422
+ const cancel = useCapxulCancelRequest(actor);
1423
+ const approve = useCapxulApproveInboxRequest(actor);
1424
+ const decline = useCapxulDeclineInboxRequest(actor);
1425
+ const pending = issue.isPending || cancel.isPending || approve.isPending || decline.isPending;
1426
+ const children = /* @__PURE__ */ jsxs(Fragment, { children: [
1427
+ slots.requests?.(toQuerySlotState(requests)),
1428
+ slots.inbox?.(toQuerySlotState(inbox)),
1429
+ slots.actions?.({
1430
+ issue: (input) => issue.mutateAsync(input),
1431
+ cancel: (requestId) => cancel.mutateAsync(requestId),
1432
+ approve: (input) => approve.mutateAsync(input),
1433
+ decline: (requestId) => decline.mutateAsync(requestId),
1434
+ pending,
1435
+ disabled: pending || actor === void 0
1436
+ })
1437
+ ] });
1438
+ return slots.root?.({ children }) ?? children;
1439
+ }
1440
+ //#endregion
1441
+ //#region src/headless/relationship/InsightsSummary.tsx
1442
+ function InsightsSummary(props) {
1443
+ const { slots } = props;
1444
+ const summary = useCapxulInsightsSummary("actor" in props ? props.actor : capxulAccountScope);
1445
+ const children = slots.summary?.(toQuerySlotState(summary));
1446
+ return slots.root?.({ children }) ?? children;
1447
+ }
1448
+ //#endregion
1449
+ //#region src/headless/relationship/PayrollRoster.tsx
1450
+ function PayrollRoster({ orgId, slots }) {
1451
+ const roster = useCapxulPayrollRoster(orgId);
1452
+ const add = useCapxulAddPayrollRosterLine(orgId);
1453
+ const update = useCapxulUpdatePayrollRosterLine(orgId);
1454
+ const remove = useCapxulRemovePayrollRosterLine(orgId);
1455
+ const run = useCapxulRunPayroll(orgId);
1456
+ const pending = add.isPending || update.isPending || remove.isPending || run.isPending;
1457
+ const children = /* @__PURE__ */ jsxs(Fragment, { children: [slots.roster?.(toQuerySlotState(roster)), slots.actions?.({
1458
+ add: (input) => add.mutateAsync(input),
1459
+ update: (input) => update.mutateAsync(input),
1460
+ remove: (rosterLineId) => remove.mutateAsync(rosterLineId),
1461
+ run: (input) => run.mutateAsync(input),
1462
+ pending,
1463
+ disabled: pending
1464
+ })] });
1465
+ return slots.root?.({ children }) ?? children;
1466
+ }
1467
+ //#endregion
1468
+ //#region src/headless/relationship/Destinations.tsx
1469
+ function Destinations({ input, slots }) {
1470
+ const destinations = useCapxulDestinations(input);
1471
+ const add = useCapxulAddDestination();
1472
+ const remove = useCapxulRemoveDestination();
1473
+ const pending = add.isPending || remove.isPending;
1474
+ const children = /* @__PURE__ */ jsxs(Fragment, { children: [slots.destinations?.(toQuerySlotState(destinations)), slots.actions?.({
1475
+ add: (value) => add.mutateAsync(value),
1476
+ remove: (value) => remove.mutateAsync(value),
1477
+ pending,
1478
+ disabled: pending
1479
+ })] });
1480
+ return slots.root?.({ children }) ?? children;
1481
+ }
1482
+ //#endregion
1483
+ export { AddressBook, CapxulProvider, Destinations, InsightsSummary, PayrollRoster, RequestInbox, SendMoney, capxulAccountScope, capxulOrgScope, useCapxul, useCapxulAccountBalance, useCapxulAccountFund, useCapxulAccountLifecycle, useCapxulAddAddressBookEntry, useCapxulAddDestination, useCapxulAddPayrollRosterLine, useCapxulAddressBook, useCapxulAddressBookEntry, useCapxulApproveInboxRequest, useCapxulAssignRole, useCapxulCancelRequest, useCapxulClientOrNull, useCapxulCompleteOrganizationOnboarding, useCapxulCompletePersonalOnboarding, useCapxulCreateOrg, useCapxulDeclineInboxRequest, useCapxulDestinations, useCapxulHideAddressBookEntry, useCapxulInbox, useCapxulInsightsHistory, useCapxulInsightsSummary, useCapxulInviteMember, useCapxulIssueRequest, useCapxulLabelAddressBookEntry, useCapxulOrg, useCapxulOrgDeployRoles, useCapxulOrgMembers, useCapxulOrgRoles, useCapxulOrgTreasury, useCapxulOrgs, useCapxulPay, useCapxulPayment, useCapxulPayments, useCapxulPayout, useCapxulPayrollRoster, useCapxulProfile, useCapxulReconcileRequests, useCapxulRemoveDestination, useCapxulRemoveMember, useCapxulRemovePayrollRosterLine, useCapxulRequest, useCapxulRequests, useCapxulRunPayroll, useCapxulSession, useCapxulSignIn, useCapxulSignOut, useCapxulSubAccountCreate, useCapxulSubAccountDelete, useCapxulSubAccountRename, useCapxulSubAccountsList, useCapxulSwitchActingEntity, useCapxulTransfer, useCapxulUnhideAddressBookEntry, useCapxulUpdatePayrollRosterLine, useCapxulVerifyOtp, useCapxulWithdraw };
1484
+
1485
+ //# sourceMappingURL=index.mjs.map