@capxul/sdk-react 0.1.0-alpha.8 → 0.2.0-alpha.3
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/CHANGELOG.md +117 -0
- package/README.md +1 -1
- package/dist/index.cjs +456 -71
- package/dist/index.d.cts +234 -35
- package/dist/index.d.ts +234 -35
- package/dist/index.js +450 -74
- package/dist/proof/index.cjs +21 -13
- package/dist/proof/index.js +18 -10
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -12,6 +12,22 @@ var viem = require('viem');
|
|
|
12
12
|
var accounts = require('viem/accounts');
|
|
13
13
|
|
|
14
14
|
// src/provider.tsx
|
|
15
|
+
var AuthServiceContext = react.createContext(null);
|
|
16
|
+
function AuthServiceProvider({
|
|
17
|
+
authService,
|
|
18
|
+
children
|
|
19
|
+
}) {
|
|
20
|
+
return /* @__PURE__ */ jsxRuntime.jsx(AuthServiceContext.Provider, { value: authService, children });
|
|
21
|
+
}
|
|
22
|
+
function useAuthService() {
|
|
23
|
+
const authService = react.useContext(AuthServiceContext);
|
|
24
|
+
if (!authService) {
|
|
25
|
+
throw new Error(
|
|
26
|
+
"useAuthService() was called outside a <CapxulProvider>. Wrap your app in <CapxulProvider config={...}> before rendering hooks from @capxul/sdk-react."
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
return authService;
|
|
30
|
+
}
|
|
15
31
|
var CapxulClientContext = react.createContext(null);
|
|
16
32
|
function CapxulClientProvider({
|
|
17
33
|
client,
|
|
@@ -81,10 +97,16 @@ var Errors = {
|
|
|
81
97
|
`Shield API error (${status}): ${detail}`,
|
|
82
98
|
{ details: { provider: "shield", status } }
|
|
83
99
|
),
|
|
84
|
-
providerError: (provider, operation, cause) =>
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
100
|
+
providerError: (provider, operation, cause) => (
|
|
101
|
+
// Public `message` is redacted to a fixed shape so provider-side
|
|
102
|
+
// exception text never leaks to the client. The original `cause`
|
|
103
|
+
// is preserved on `Error.cause` for server-side debugging via
|
|
104
|
+
// observability sinks (Sentry, console traces).
|
|
105
|
+
new CapxulError(
|
|
106
|
+
"PROVIDER_ERROR",
|
|
107
|
+
`Provider error: ${provider} ${operation}`,
|
|
108
|
+
{ cause, details: { provider, operation } }
|
|
109
|
+
)
|
|
88
110
|
),
|
|
89
111
|
invalidInput: (field, reason) => new CapxulError(
|
|
90
112
|
"INVALID_INPUT",
|
|
@@ -149,7 +171,7 @@ function roleKeyFromLabel(label) {
|
|
|
149
171
|
}
|
|
150
172
|
roleKeyFromLabel("OWNER");
|
|
151
173
|
roleKeyFromLabel("FINANCE_MANAGER");
|
|
152
|
-
roleKeyFromLabel("
|
|
174
|
+
roleKeyFromLabel("PAYMENTS_OPERATOR");
|
|
153
175
|
|
|
154
176
|
// src/config.ts
|
|
155
177
|
function createCapxulConfig(input) {
|
|
@@ -288,7 +310,7 @@ function CapxulProvider({
|
|
|
288
310
|
[]
|
|
289
311
|
);
|
|
290
312
|
const effectiveClient = queryClient ?? defaultClient;
|
|
291
|
-
return /* @__PURE__ */ jsxRuntime.jsx(reactQuery.QueryClientProvider, { client: effectiveClient, children: /* @__PURE__ */ jsxRuntime.jsx(CapxulTransportProvider, { transport: wiring.transport, children: /* @__PURE__ */ jsxRuntime.jsx(CapxulClientProvider, { client: wiring.client, children }) }) });
|
|
313
|
+
return /* @__PURE__ */ jsxRuntime.jsx(reactQuery.QueryClientProvider, { client: effectiveClient, children: /* @__PURE__ */ jsxRuntime.jsx(CapxulTransportProvider, { transport: wiring.transport, children: /* @__PURE__ */ jsxRuntime.jsx(CapxulClientProvider, { client: wiring.client, children: /* @__PURE__ */ jsxRuntime.jsx(AuthServiceProvider, { authService: wiring.authService, children }) }) }) });
|
|
292
314
|
}
|
|
293
315
|
function buildWiring(config, sessionStore) {
|
|
294
316
|
const validated = createCapxulConfig(config);
|
|
@@ -297,7 +319,7 @@ function buildWiring(config, sessionStore) {
|
|
|
297
319
|
const sdkConfig = {
|
|
298
320
|
_transport: transport,
|
|
299
321
|
publishableKey: validated.mode === "publishable-key" ? validated.publishableKey : void 0,
|
|
300
|
-
|
|
322
|
+
_data: dataClient ?? void 0,
|
|
301
323
|
auth: validated.mode === "build-time-urls" || validated.mode === "publishable-key" ? {
|
|
302
324
|
// The auth client builds the BetterAuth root URL from this
|
|
303
325
|
// value. Convex's `.cloud` URL is the wrong host (BetterAuth
|
|
@@ -307,29 +329,16 @@ function buildWiring(config, sessionStore) {
|
|
|
307
329
|
// `core/auth.ts`'s `createTransportProvider` short-circuits
|
|
308
330
|
// to the externally-injected `_transport` cache slot.
|
|
309
331
|
baseUrl: transport.authBaseUrl,
|
|
310
|
-
sessionStore
|
|
311
|
-
createDataClient: async (_session) => {
|
|
312
|
-
dataClient.refreshAuth();
|
|
313
|
-
return dataClient;
|
|
314
|
-
}
|
|
332
|
+
sessionStore
|
|
315
333
|
} : void 0
|
|
316
334
|
};
|
|
317
335
|
const client = sdk.createCapxulClient(sdkConfig);
|
|
318
|
-
|
|
319
|
-
const originalSignOut = client.auth.signOut;
|
|
320
|
-
Object.assign(client.auth, {
|
|
321
|
-
signOut: async () => {
|
|
322
|
-
const result = await originalSignOut();
|
|
323
|
-
dataClient.refreshAuth();
|
|
324
|
-
sdkConfig.data = dataClient;
|
|
325
|
-
return result;
|
|
326
|
-
}
|
|
327
|
-
});
|
|
328
|
-
}
|
|
336
|
+
const authService = new sdk.AuthService(sdkConfig);
|
|
329
337
|
return {
|
|
330
338
|
client,
|
|
331
339
|
transport,
|
|
332
|
-
dataClient
|
|
340
|
+
dataClient,
|
|
341
|
+
authService
|
|
333
342
|
};
|
|
334
343
|
}
|
|
335
344
|
function createMemorySessionStore() {
|
|
@@ -438,11 +447,59 @@ function useAccount(accountId) {
|
|
|
438
447
|
[capxul, accountId]
|
|
439
448
|
);
|
|
440
449
|
}
|
|
441
|
-
function useOrganization(
|
|
442
|
-
|
|
450
|
+
function useOrganization(organizationId) {
|
|
451
|
+
const capxul = useCapxul();
|
|
452
|
+
return reactQuery.useQuery({
|
|
453
|
+
queryKey: [capxul.id, "capxul", "organizations", organizationId],
|
|
454
|
+
queryFn: () => capxul.organizations.retrieve(organizationId).then(([error, data]) => {
|
|
455
|
+
if (error) {
|
|
456
|
+
throw error;
|
|
457
|
+
}
|
|
458
|
+
return data;
|
|
459
|
+
}).catch((cause) => {
|
|
460
|
+
if (cause instanceof sdk.CapxulError) {
|
|
461
|
+
throw cause;
|
|
462
|
+
}
|
|
463
|
+
throw new sdk.CapxulError({
|
|
464
|
+
code: "UNKNOWN",
|
|
465
|
+
message: "SDK read failed before returning a CapxulResult.",
|
|
466
|
+
cause
|
|
467
|
+
});
|
|
468
|
+
}),
|
|
469
|
+
staleTime: 3e4
|
|
470
|
+
});
|
|
443
471
|
}
|
|
444
|
-
function useMember(
|
|
445
|
-
|
|
472
|
+
function useMember(args) {
|
|
473
|
+
const capxul = useCapxul();
|
|
474
|
+
return reactQuery.useQuery({
|
|
475
|
+
queryKey: [
|
|
476
|
+
capxul.id,
|
|
477
|
+
"capxul",
|
|
478
|
+
"organizations",
|
|
479
|
+
args.organizationId,
|
|
480
|
+
"members",
|
|
481
|
+
args.memberId
|
|
482
|
+
],
|
|
483
|
+
queryFn: () => capxul.organizations.members.retrieve({
|
|
484
|
+
organizationId: args.organizationId,
|
|
485
|
+
memberId: args.memberId
|
|
486
|
+
}).then(([error, data]) => {
|
|
487
|
+
if (error) {
|
|
488
|
+
throw error;
|
|
489
|
+
}
|
|
490
|
+
return data;
|
|
491
|
+
}).catch((cause) => {
|
|
492
|
+
if (cause instanceof sdk.CapxulError) {
|
|
493
|
+
throw cause;
|
|
494
|
+
}
|
|
495
|
+
throw new sdk.CapxulError({
|
|
496
|
+
code: "UNKNOWN",
|
|
497
|
+
message: "SDK read failed before returning a CapxulResult.",
|
|
498
|
+
cause
|
|
499
|
+
});
|
|
500
|
+
}),
|
|
501
|
+
staleTime: 3e4
|
|
502
|
+
});
|
|
446
503
|
}
|
|
447
504
|
function useSafe(safeId) {
|
|
448
505
|
const capxul = useCapxul();
|
|
@@ -451,8 +508,33 @@ function useSafe(safeId) {
|
|
|
451
508
|
[capxul, safeId]
|
|
452
509
|
);
|
|
453
510
|
}
|
|
454
|
-
function useTreasury(
|
|
455
|
-
|
|
511
|
+
function useTreasury(organizationId) {
|
|
512
|
+
const capxul = useCapxul();
|
|
513
|
+
return reactQuery.useQuery({
|
|
514
|
+
queryKey: [
|
|
515
|
+
capxul.id,
|
|
516
|
+
"capxul",
|
|
517
|
+
"organizations",
|
|
518
|
+
organizationId,
|
|
519
|
+
"treasury"
|
|
520
|
+
],
|
|
521
|
+
queryFn: () => capxul.organizations.treasury.retrieve(organizationId).then(([error, data]) => {
|
|
522
|
+
if (error) {
|
|
523
|
+
throw error;
|
|
524
|
+
}
|
|
525
|
+
return data;
|
|
526
|
+
}).catch((cause) => {
|
|
527
|
+
if (cause instanceof sdk.CapxulError) {
|
|
528
|
+
throw cause;
|
|
529
|
+
}
|
|
530
|
+
throw new sdk.CapxulError({
|
|
531
|
+
code: "UNKNOWN",
|
|
532
|
+
message: "SDK read failed before returning a CapxulResult.",
|
|
533
|
+
cause
|
|
534
|
+
});
|
|
535
|
+
}),
|
|
536
|
+
staleTime: 3e4
|
|
537
|
+
});
|
|
456
538
|
}
|
|
457
539
|
function useApiKey(_args) {
|
|
458
540
|
return notImplementedQuery("useApiKey");
|
|
@@ -460,9 +542,6 @@ function useApiKey(_args) {
|
|
|
460
542
|
function useKycProfile(_accountId) {
|
|
461
543
|
return notImplementedQuery("useKycProfile");
|
|
462
544
|
}
|
|
463
|
-
function useKybProfile(_organizationId) {
|
|
464
|
-
return notImplementedQuery("useKybProfile");
|
|
465
|
-
}
|
|
466
545
|
function useExternalAccount(args) {
|
|
467
546
|
const capxul = useCapxul();
|
|
468
547
|
return useSdkQuery(
|
|
@@ -473,8 +552,12 @@ function useExternalAccount(args) {
|
|
|
473
552
|
[capxul, args.ownerKind, args.ownerId, args.externalAccountId]
|
|
474
553
|
);
|
|
475
554
|
}
|
|
476
|
-
function useSubAccount(
|
|
477
|
-
|
|
555
|
+
function useSubAccount(subAccountId) {
|
|
556
|
+
const capxul = useCapxul();
|
|
557
|
+
return useSdkQuery(
|
|
558
|
+
() => capxul.subAccounts.retrieve(subAccountId),
|
|
559
|
+
[capxul, subAccountId]
|
|
560
|
+
);
|
|
478
561
|
}
|
|
479
562
|
function useVirtualAccount(_virtualAccountId) {
|
|
480
563
|
return notImplementedQuery("useVirtualAccount");
|
|
@@ -482,8 +565,27 @@ function useVirtualAccount(_virtualAccountId) {
|
|
|
482
565
|
function useVirtualCard(_virtualCardId) {
|
|
483
566
|
return notImplementedQuery("useVirtualCard");
|
|
484
567
|
}
|
|
485
|
-
function usePayment(
|
|
486
|
-
|
|
568
|
+
function usePayment(paymentId) {
|
|
569
|
+
const capxul = useCapxul();
|
|
570
|
+
return reactQuery.useQuery({
|
|
571
|
+
queryKey: [capxul.id, "capxul", "payments", paymentId],
|
|
572
|
+
queryFn: () => capxul.payments.retrieve(paymentId).then(([error, data]) => {
|
|
573
|
+
if (error) {
|
|
574
|
+
throw error;
|
|
575
|
+
}
|
|
576
|
+
return data;
|
|
577
|
+
}).catch((cause) => {
|
|
578
|
+
if (cause instanceof sdk.CapxulError) {
|
|
579
|
+
throw cause;
|
|
580
|
+
}
|
|
581
|
+
throw new sdk.CapxulError({
|
|
582
|
+
code: "UNKNOWN",
|
|
583
|
+
message: "SDK read failed before returning a CapxulResult.",
|
|
584
|
+
cause
|
|
585
|
+
});
|
|
586
|
+
}),
|
|
587
|
+
staleTime: 3e4
|
|
588
|
+
});
|
|
487
589
|
}
|
|
488
590
|
function useTransfer(_transferId) {
|
|
489
591
|
return notImplementedQuery("useTransfer");
|
|
@@ -495,25 +597,32 @@ function useTokenTransfer(args) {
|
|
|
495
597
|
[capxul, args.txHash, args.logIndex, args.chainId]
|
|
496
598
|
);
|
|
497
599
|
}
|
|
498
|
-
function useBalanceLedgerEntry(
|
|
499
|
-
|
|
600
|
+
function useBalanceLedgerEntry(args) {
|
|
601
|
+
const capxul = useCapxul();
|
|
602
|
+
return useSdkQuery(
|
|
603
|
+
() => args.ownerKind === "account" ? capxul.accounts.balanceLedger.retrieve(args.entryId) : capxul.organizations.balanceLedger.retrieve({
|
|
604
|
+
organizationId: args.ownerId,
|
|
605
|
+
entryId: args.entryId
|
|
606
|
+
}),
|
|
607
|
+
[capxul, args.ownerKind, args.ownerId, args.entryId]
|
|
608
|
+
);
|
|
500
609
|
}
|
|
501
610
|
function useDocument(_documentId) {
|
|
502
611
|
return notImplementedQuery("useDocument");
|
|
503
612
|
}
|
|
504
613
|
function useWithdrawal(withdrawalId) {
|
|
505
614
|
const capxul = useCapxul();
|
|
506
|
-
return useSdkQuery(
|
|
507
|
-
capxul,
|
|
508
|
-
withdrawalId
|
|
509
|
-
|
|
615
|
+
return useSdkQuery(
|
|
616
|
+
() => capxul.withdrawals.retrieve(withdrawalId),
|
|
617
|
+
[capxul, withdrawalId]
|
|
618
|
+
);
|
|
510
619
|
}
|
|
511
620
|
function useOperation(operationId) {
|
|
512
621
|
const capxul = useCapxul();
|
|
513
|
-
return useSdkQuery(
|
|
514
|
-
capxul,
|
|
515
|
-
operationId
|
|
516
|
-
|
|
622
|
+
return useSdkQuery(
|
|
623
|
+
() => capxul.operations.retrieve(operationId),
|
|
624
|
+
[capxul, operationId]
|
|
625
|
+
);
|
|
517
626
|
}
|
|
518
627
|
function useWebhookEndpoint(_endpointId) {
|
|
519
628
|
return notImplementedQuery("useWebhookEndpoint");
|
|
@@ -521,13 +630,57 @@ function useWebhookEndpoint(_endpointId) {
|
|
|
521
630
|
function useWebhookEvent(_eventId) {
|
|
522
631
|
return notImplementedQuery("useWebhookEvent");
|
|
523
632
|
}
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
633
|
+
function useOrganizations(filters) {
|
|
634
|
+
const capxul = useCapxul();
|
|
635
|
+
return reactQuery.useQuery({
|
|
636
|
+
queryKey: [capxul.id, "capxul", "organizations", "list", filters],
|
|
637
|
+
queryFn: () => capxul.organizations.list(filters).then(([error, data]) => {
|
|
638
|
+
if (error) {
|
|
639
|
+
throw error;
|
|
640
|
+
}
|
|
641
|
+
return data;
|
|
642
|
+
}).catch((cause) => {
|
|
643
|
+
if (cause instanceof sdk.CapxulError) {
|
|
644
|
+
throw cause;
|
|
645
|
+
}
|
|
646
|
+
throw new sdk.CapxulError({
|
|
647
|
+
code: "UNKNOWN",
|
|
648
|
+
message: "SDK read failed before returning a CapxulResult.",
|
|
649
|
+
cause
|
|
650
|
+
});
|
|
651
|
+
}),
|
|
652
|
+
staleTime: 3e4
|
|
653
|
+
});
|
|
528
654
|
}
|
|
529
|
-
function useMembers(
|
|
530
|
-
|
|
655
|
+
function useMembers(organizationId, filters) {
|
|
656
|
+
const capxul = useCapxul();
|
|
657
|
+
return reactQuery.useQuery({
|
|
658
|
+
queryKey: [
|
|
659
|
+
capxul.id,
|
|
660
|
+
"capxul",
|
|
661
|
+
"organizations",
|
|
662
|
+
organizationId,
|
|
663
|
+
"members",
|
|
664
|
+
"list",
|
|
665
|
+
filters?.status
|
|
666
|
+
],
|
|
667
|
+
queryFn: () => capxul.organizations.members.list({ organizationId, status: filters?.status }).then(([error, data]) => {
|
|
668
|
+
if (error) {
|
|
669
|
+
throw error;
|
|
670
|
+
}
|
|
671
|
+
return data;
|
|
672
|
+
}).catch((cause) => {
|
|
673
|
+
if (cause instanceof sdk.CapxulError) {
|
|
674
|
+
throw cause;
|
|
675
|
+
}
|
|
676
|
+
throw new sdk.CapxulError({
|
|
677
|
+
code: "UNKNOWN",
|
|
678
|
+
message: "SDK read failed before returning a CapxulResult.",
|
|
679
|
+
cause
|
|
680
|
+
});
|
|
681
|
+
}),
|
|
682
|
+
staleTime: 3e4
|
|
683
|
+
});
|
|
531
684
|
}
|
|
532
685
|
function useExternalAccounts(args) {
|
|
533
686
|
const capxul = useCapxul();
|
|
@@ -538,8 +691,14 @@ function useExternalAccounts(args) {
|
|
|
538
691
|
[capxul, args.ownerKind, args.ownerId]
|
|
539
692
|
);
|
|
540
693
|
}
|
|
541
|
-
function useSubAccounts(
|
|
542
|
-
|
|
694
|
+
function useSubAccounts(args) {
|
|
695
|
+
const capxul = useCapxul();
|
|
696
|
+
return useSdkQuery(
|
|
697
|
+
() => args.ownerKind === "account" ? capxul.accounts.subAccounts.list({ accountId: args.ownerId }) : capxul.organizations.subAccounts.list({
|
|
698
|
+
organizationId: args.ownerId
|
|
699
|
+
}),
|
|
700
|
+
[capxul, args.ownerKind, args.ownerId]
|
|
701
|
+
);
|
|
543
702
|
}
|
|
544
703
|
function useVirtualAccounts(_filters) {
|
|
545
704
|
return notImplementedQuery("useVirtualAccounts");
|
|
@@ -547,8 +706,27 @@ function useVirtualAccounts(_filters) {
|
|
|
547
706
|
function useVirtualCards(_filters) {
|
|
548
707
|
return notImplementedQuery("useVirtualCards");
|
|
549
708
|
}
|
|
550
|
-
function usePayments(
|
|
551
|
-
|
|
709
|
+
function usePayments(filters) {
|
|
710
|
+
const capxul = useCapxul();
|
|
711
|
+
return reactQuery.useQuery({
|
|
712
|
+
queryKey: [capxul.id, "capxul", "payments", "list", filters],
|
|
713
|
+
queryFn: () => capxul.payments.list(filters).then(([error, data]) => {
|
|
714
|
+
if (error) {
|
|
715
|
+
throw error;
|
|
716
|
+
}
|
|
717
|
+
return data;
|
|
718
|
+
}).catch((cause) => {
|
|
719
|
+
if (cause instanceof sdk.CapxulError) {
|
|
720
|
+
throw cause;
|
|
721
|
+
}
|
|
722
|
+
throw new sdk.CapxulError({
|
|
723
|
+
code: "UNKNOWN",
|
|
724
|
+
message: "SDK read failed before returning a CapxulResult.",
|
|
725
|
+
cause
|
|
726
|
+
});
|
|
727
|
+
}),
|
|
728
|
+
staleTime: 3e4
|
|
729
|
+
});
|
|
552
730
|
}
|
|
553
731
|
function useOrgPayments(_args) {
|
|
554
732
|
return notImplementedQuery("useOrgPayments");
|
|
@@ -566,8 +744,34 @@ function useTokenTransfers(filters) {
|
|
|
566
744
|
[capxul, filters?.limit, filters?.cursor, filters?.direction]
|
|
567
745
|
);
|
|
568
746
|
}
|
|
569
|
-
function useBalanceLedger(
|
|
570
|
-
|
|
747
|
+
function useBalanceLedger(args) {
|
|
748
|
+
const capxul = useCapxul();
|
|
749
|
+
return useSdkQuery(
|
|
750
|
+
() => args.ownerKind === "account" ? capxul.accounts.balanceLedger.list({
|
|
751
|
+
accountId: args.ownerId,
|
|
752
|
+
limit: args.limit,
|
|
753
|
+
cursor: args.cursor
|
|
754
|
+
}) : capxul.organizations.balanceLedger.list({
|
|
755
|
+
organizationId: args.ownerId,
|
|
756
|
+
limit: args.limit,
|
|
757
|
+
cursor: args.cursor
|
|
758
|
+
}),
|
|
759
|
+
[capxul, args.ownerKind, args.ownerId, args.limit, args.cursor]
|
|
760
|
+
);
|
|
761
|
+
}
|
|
762
|
+
function useAccountBalanceLedger(accountId, filters) {
|
|
763
|
+
const capxul = useCapxul();
|
|
764
|
+
return useSdkQuery(
|
|
765
|
+
() => capxul.accounts.balanceLedger.list({ accountId, ...filters }),
|
|
766
|
+
[capxul, accountId, filters?.limit, filters?.cursor]
|
|
767
|
+
);
|
|
768
|
+
}
|
|
769
|
+
function useOrgBalanceLedger(args) {
|
|
770
|
+
const capxul = useCapxul();
|
|
771
|
+
return useSdkQuery(
|
|
772
|
+
() => capxul.organizations.balanceLedger.list(args),
|
|
773
|
+
[capxul, args.organizationId, args.limit, args.cursor]
|
|
774
|
+
);
|
|
571
775
|
}
|
|
572
776
|
function useDocuments(_filters) {
|
|
573
777
|
return notImplementedQuery("useDocuments");
|
|
@@ -595,12 +799,194 @@ function useApiKeys(_organizationId) {
|
|
|
595
799
|
function useWebhookEndpoints() {
|
|
596
800
|
return notImplementedQuery("useWebhookEndpoints");
|
|
597
801
|
}
|
|
802
|
+
function useInviteMember() {
|
|
803
|
+
const capxul = useCapxul();
|
|
804
|
+
return reactQuery.useMutation({
|
|
805
|
+
mutationFn: async (args) => {
|
|
806
|
+
const [error, data] = await capxul.organizations.members.invite(args);
|
|
807
|
+
if (error) throw error;
|
|
808
|
+
return data;
|
|
809
|
+
}
|
|
810
|
+
});
|
|
811
|
+
}
|
|
812
|
+
function useAcceptInvitation() {
|
|
813
|
+
const capxul = useCapxul();
|
|
814
|
+
return reactQuery.useMutation({
|
|
815
|
+
mutationFn: async (args) => {
|
|
816
|
+
const [error, data] = await capxul.organizations.members.accept(args);
|
|
817
|
+
if (error) throw error;
|
|
818
|
+
return data;
|
|
819
|
+
}
|
|
820
|
+
});
|
|
821
|
+
}
|
|
822
|
+
function useUpdateMemberRole() {
|
|
823
|
+
const capxul = useCapxul();
|
|
824
|
+
return reactQuery.useMutation({
|
|
825
|
+
mutationFn: async (args) => {
|
|
826
|
+
const [error, data] = await capxul.organizations.members.updateRole(args);
|
|
827
|
+
if (error) throw error;
|
|
828
|
+
return data;
|
|
829
|
+
}
|
|
830
|
+
});
|
|
831
|
+
}
|
|
832
|
+
function useRevokeMember() {
|
|
833
|
+
const capxul = useCapxul();
|
|
834
|
+
return reactQuery.useMutation({
|
|
835
|
+
mutationFn: async (args) => {
|
|
836
|
+
const [error, data] = await capxul.organizations.members.revoke(args);
|
|
837
|
+
if (error) throw error;
|
|
838
|
+
return data;
|
|
839
|
+
}
|
|
840
|
+
});
|
|
841
|
+
}
|
|
842
|
+
function useRemoveMember() {
|
|
843
|
+
const capxul = useCapxul();
|
|
844
|
+
return reactQuery.useMutation({
|
|
845
|
+
mutationFn: async (args) => {
|
|
846
|
+
const [error, data] = await capxul.organizations.members.remove(args);
|
|
847
|
+
if (error) throw error;
|
|
848
|
+
return data;
|
|
849
|
+
}
|
|
850
|
+
});
|
|
851
|
+
}
|
|
852
|
+
function useResendInvitation() {
|
|
853
|
+
const capxul = useCapxul();
|
|
854
|
+
return reactQuery.useMutation({
|
|
855
|
+
mutationFn: async (args) => {
|
|
856
|
+
const [error, data] = await capxul.organizations.members.resend(args);
|
|
857
|
+
if (error) throw error;
|
|
858
|
+
return data;
|
|
859
|
+
}
|
|
860
|
+
});
|
|
861
|
+
}
|
|
862
|
+
function useAuth(options) {
|
|
863
|
+
const authService = useAuthService();
|
|
864
|
+
const signerProvisioner = useMemoizedSignerProvisioner();
|
|
865
|
+
const injectedSigner = options?.signer;
|
|
866
|
+
const [state, setState] = react.useState("idle");
|
|
867
|
+
const [user, setUser] = react.useState(null);
|
|
868
|
+
const [error, setError] = react.useState(null);
|
|
869
|
+
const signIn = react.useCallback(
|
|
870
|
+
async (email) => {
|
|
871
|
+
setState("sendingOtp");
|
|
872
|
+
setError(null);
|
|
873
|
+
try {
|
|
874
|
+
await authService.sendOtp(email);
|
|
875
|
+
setState("awaitingOtp");
|
|
876
|
+
} catch (err) {
|
|
877
|
+
const wrapped = err instanceof Error ? err : new Error(String(err));
|
|
878
|
+
setError(wrapped);
|
|
879
|
+
setState("error");
|
|
880
|
+
throw wrapped;
|
|
881
|
+
}
|
|
882
|
+
},
|
|
883
|
+
[authService]
|
|
884
|
+
);
|
|
885
|
+
const verifyOtp = react.useCallback(
|
|
886
|
+
async (email, otp) => {
|
|
887
|
+
setState("awaitingOtp");
|
|
888
|
+
setError(null);
|
|
889
|
+
try {
|
|
890
|
+
const result = await authService.verifyOtp(email, otp);
|
|
891
|
+
if (result.kind === "existing_member") {
|
|
892
|
+
const nextUser2 = {
|
|
893
|
+
account: result.account,
|
|
894
|
+
username: result.username,
|
|
895
|
+
safe: result.safe,
|
|
896
|
+
session: result.session
|
|
897
|
+
};
|
|
898
|
+
setUser(nextUser2);
|
|
899
|
+
setState("authenticated");
|
|
900
|
+
return result.session;
|
|
901
|
+
}
|
|
902
|
+
setState("bootstrapping");
|
|
903
|
+
const signer = injectedSigner ?? signerProvisioner.provision().signer;
|
|
904
|
+
const username = result.username ?? generateUsernameFromEmail(result.email);
|
|
905
|
+
const bootstrapResult = await authService.completeBootstrap(
|
|
906
|
+
{
|
|
907
|
+
bootstrapToken: result.bootstrapToken,
|
|
908
|
+
username
|
|
909
|
+
},
|
|
910
|
+
signer
|
|
911
|
+
);
|
|
912
|
+
const nextUser = {
|
|
913
|
+
account: bootstrapResult.account,
|
|
914
|
+
username: bootstrapResult.username,
|
|
915
|
+
safe: bootstrapResult.safe,
|
|
916
|
+
session: bootstrapResult.session
|
|
917
|
+
};
|
|
918
|
+
setUser(nextUser);
|
|
919
|
+
setState("authenticated");
|
|
920
|
+
return bootstrapResult.session;
|
|
921
|
+
} catch (err) {
|
|
922
|
+
const wrapped = err instanceof Error ? err : new Error(String(err));
|
|
923
|
+
setError(wrapped);
|
|
924
|
+
setState("error");
|
|
925
|
+
throw wrapped;
|
|
926
|
+
}
|
|
927
|
+
},
|
|
928
|
+
[authService, signerProvisioner, injectedSigner]
|
|
929
|
+
);
|
|
930
|
+
const signOut = react.useCallback(async () => {
|
|
931
|
+
setError(null);
|
|
932
|
+
try {
|
|
933
|
+
await authService.signOut();
|
|
934
|
+
setUser(null);
|
|
935
|
+
setState("idle");
|
|
936
|
+
} catch (err) {
|
|
937
|
+
const wrapped = err instanceof Error ? err : new Error(String(err));
|
|
938
|
+
setError(wrapped);
|
|
939
|
+
setState("error");
|
|
940
|
+
throw wrapped;
|
|
941
|
+
}
|
|
942
|
+
}, [authService]);
|
|
943
|
+
return react.useMemo(
|
|
944
|
+
() => ({
|
|
945
|
+
state,
|
|
946
|
+
user,
|
|
947
|
+
error,
|
|
948
|
+
signIn,
|
|
949
|
+
verifyOtp,
|
|
950
|
+
signOut
|
|
951
|
+
}),
|
|
952
|
+
[state, user, error, signIn, verifyOtp, signOut]
|
|
953
|
+
);
|
|
954
|
+
}
|
|
955
|
+
function useMemoizedSignerProvisioner() {
|
|
956
|
+
const [provisioner] = react.useState(() => new sdk.SignerProvisioner());
|
|
957
|
+
return provisioner;
|
|
958
|
+
}
|
|
959
|
+
function generateUsernameFromEmail(email) {
|
|
960
|
+
const local = email.split("@")[0]?.toLowerCase() ?? "user";
|
|
961
|
+
let sanitized = local.replace(/[^a-z0-9_-]/g, "_");
|
|
962
|
+
if (/^[0-9]/.test(sanitized)) {
|
|
963
|
+
sanitized = "u" + sanitized;
|
|
964
|
+
}
|
|
965
|
+
if (sanitized.length < 3) {
|
|
966
|
+
sanitized = sanitized + "_".repeat(3 - sanitized.length);
|
|
967
|
+
}
|
|
968
|
+
if (sanitized.length > 30) {
|
|
969
|
+
sanitized = sanitized.slice(0, 30);
|
|
970
|
+
}
|
|
971
|
+
try {
|
|
972
|
+
return sdk.toUsername(sanitized);
|
|
973
|
+
} catch {
|
|
974
|
+
const fallback = `user_${Date.now() % 1e6}`;
|
|
975
|
+
return sdk.toUsername(fallback);
|
|
976
|
+
}
|
|
977
|
+
}
|
|
598
978
|
function useAuthFlow() {
|
|
599
979
|
const client = useCapxul();
|
|
600
980
|
const machine = react.useMemo(() => client.flows.auth(), [client]);
|
|
601
981
|
const [snapshot, send] = react$1.useActor(machine);
|
|
602
982
|
return { snapshot, send };
|
|
603
983
|
}
|
|
984
|
+
function useAuthBootstrapFlow() {
|
|
985
|
+
const client = useCapxul();
|
|
986
|
+
const machine = react.useMemo(() => client.flows.authBootstrap(), [client]);
|
|
987
|
+
const [snapshot, send] = react$1.useActor(machine);
|
|
988
|
+
return { snapshot, send };
|
|
989
|
+
}
|
|
604
990
|
function useOnboardingFlow() {
|
|
605
991
|
const client = useCapxul();
|
|
606
992
|
const machine = react.useMemo(() => client.flows.onboarding(), [client]);
|
|
@@ -654,10 +1040,6 @@ function localPrivateKeyConnector(options) {
|
|
|
654
1040
|
"must be a 0x-prefixed 32-byte (64 hex chars) string."
|
|
655
1041
|
);
|
|
656
1042
|
}
|
|
657
|
-
const safeAddress = validateAndNormalizeEvmAddress(
|
|
658
|
-
"safeAddress",
|
|
659
|
-
options.safeAddress
|
|
660
|
-
);
|
|
661
1043
|
const id = options.id ?? "local-private-key";
|
|
662
1044
|
return {
|
|
663
1045
|
id,
|
|
@@ -669,13 +1051,7 @@ function localPrivateKeyConnector(options) {
|
|
|
669
1051
|
return {
|
|
670
1052
|
connectorId: id,
|
|
671
1053
|
connectorKind: "local-private-key",
|
|
672
|
-
signerAddress: account.address
|
|
673
|
-
safeAddress,
|
|
674
|
-
signerProvider: {
|
|
675
|
-
kind: "local-private-key",
|
|
676
|
-
signerAddress: account.address,
|
|
677
|
-
safeAddress
|
|
678
|
-
}
|
|
1054
|
+
signerAddress: account.address
|
|
679
1055
|
};
|
|
680
1056
|
}
|
|
681
1057
|
};
|
|
@@ -715,9 +1091,13 @@ exports.CapxulTransportProvider = CapxulTransportProvider;
|
|
|
715
1091
|
exports.createCapxulConfig = createCapxulConfig;
|
|
716
1092
|
exports.injectedConnector = injectedConnector;
|
|
717
1093
|
exports.localPrivateKeyConnector = localPrivateKeyConnector;
|
|
1094
|
+
exports.useAcceptInvitation = useAcceptInvitation;
|
|
718
1095
|
exports.useAccount = useAccount;
|
|
1096
|
+
exports.useAccountBalanceLedger = useAccountBalanceLedger;
|
|
719
1097
|
exports.useApiKey = useApiKey;
|
|
720
1098
|
exports.useApiKeys = useApiKeys;
|
|
1099
|
+
exports.useAuth = useAuth;
|
|
1100
|
+
exports.useAuthBootstrapFlow = useAuthBootstrapFlow;
|
|
721
1101
|
exports.useAuthFlow = useAuthFlow;
|
|
722
1102
|
exports.useBalanceLedger = useBalanceLedger;
|
|
723
1103
|
exports.useBalanceLedgerEntry = useBalanceLedgerEntry;
|
|
@@ -727,13 +1107,14 @@ exports.useDocument = useDocument;
|
|
|
727
1107
|
exports.useDocuments = useDocuments;
|
|
728
1108
|
exports.useExternalAccount = useExternalAccount;
|
|
729
1109
|
exports.useExternalAccounts = useExternalAccounts;
|
|
730
|
-
exports.
|
|
1110
|
+
exports.useInviteMember = useInviteMember;
|
|
731
1111
|
exports.useKycProfile = useKycProfile;
|
|
732
1112
|
exports.useMe = useMe;
|
|
733
1113
|
exports.useMember = useMember;
|
|
734
1114
|
exports.useMembers = useMembers;
|
|
735
1115
|
exports.useOnboardingFlow = useOnboardingFlow;
|
|
736
1116
|
exports.useOperation = useOperation;
|
|
1117
|
+
exports.useOrgBalanceLedger = useOrgBalanceLedger;
|
|
737
1118
|
exports.useOrgDocuments = useOrgDocuments;
|
|
738
1119
|
exports.useOrgPayments = useOrgPayments;
|
|
739
1120
|
exports.useOrgTransfers = useOrgTransfers;
|
|
@@ -743,6 +1124,9 @@ exports.useOrganizations = useOrganizations;
|
|
|
743
1124
|
exports.usePayment = usePayment;
|
|
744
1125
|
exports.usePayments = usePayments;
|
|
745
1126
|
exports.useProvisioningFlow = useProvisioningFlow;
|
|
1127
|
+
exports.useRemoveMember = useRemoveMember;
|
|
1128
|
+
exports.useResendInvitation = useResendInvitation;
|
|
1129
|
+
exports.useRevokeMember = useRevokeMember;
|
|
746
1130
|
exports.useSafe = useSafe;
|
|
747
1131
|
exports.useSubAccount = useSubAccount;
|
|
748
1132
|
exports.useSubAccounts = useSubAccounts;
|
|
@@ -751,6 +1135,7 @@ exports.useTokenTransfers = useTokenTransfers;
|
|
|
751
1135
|
exports.useTransfer = useTransfer;
|
|
752
1136
|
exports.useTransfers = useTransfers;
|
|
753
1137
|
exports.useTreasury = useTreasury;
|
|
1138
|
+
exports.useUpdateMemberRole = useUpdateMemberRole;
|
|
754
1139
|
exports.useVirtualAccount = useVirtualAccount;
|
|
755
1140
|
exports.useVirtualAccounts = useVirtualAccounts;
|
|
756
1141
|
exports.useVirtualCard = useVirtualCard;
|