@capxul/sdk 2.8.2 → 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
- import { A as toPartyId, B as Errors, G as decodeChainCause, H as CHAIN_UPSTREAMS, J as revertSummaryText, K as failureFingerprint, L as CAPXUL_ERROR_CODES, M as toPayrollRunId, P as toRoleKey, R as CapxulError, S as toCurrencyCode, U as FAILURE_MODES$1, V as isCapxulError, W as chainCauseProperties, b as toChainId, c as BYTES32_RE, d as WEI_RE, f as ZERO_BYTES32, h as toAddress, j as toPayrollGroupId, k as toOrgId, l as EVM_ADDRESS_RE$1, m as toAccountId, n as BrowserAuthCacheAdapter, q as isFailureMode, s as APP_ID_RE, t as InMemoryAuthCacheAdapter, u as SUPPORTED_CURRENCY_CODES, v as toAuthUserId, w as toEmail, x as toCountryCode, y as toBudgetId, z as EXPECTED_OPERATION_OUTCOMES } from "./InMemoryAuthCacheAdapter-BrEN-men.mjs";
2
- import { concat, encodeAbiParameters, encodeFunctionData, encodePacked, formatUnits, getContractAddress, keccak256, padHex, parseUnits, recoverAddress, stringToHex, toBytes, toEventSelector, toFunctionSelector, toFunctionSignature } from "viem";
1
+ import { $ as CHAIN_UPSTREAMS, A as toBudgetId, B as toOrgId, C as ZERO_BYTES32, E as toAddress, F as toEmail, G as toRoleKey, H as toPayrollGroupId, J as CAPXUL_ERROR_CODES, M as toCountryCode, N as toCurrencyCode, Q as isCapxulError, S as WEI_RE, T as toAccountId, U as toPayrollRunId, V as toPartyId, X as EXPECTED_OPERATION_OUTCOMES, Y as CapxulError, Z as Errors, _ as deriveCapxulSafeAddress, at as failureFingerprint, b as EVM_ADDRESS_RE$1, ct as revertSummaryText, et as FAILURE_MODES$1, it as decodeChainCause, j as toChainId, k as toAuthUserId, lt as containsSensitiveMaterial, n as InMemoryAuthCacheAdapter, nt as chainCauseProperties, ot as isChainUpstream, p as orgRoleKeyForLabel, r as BrowserAuthCacheAdapter, rt as chainEvidenceLabel, st as isFailureMode, tt as boundedResponseHeaders, ut as redactSecrets, v as APP_ID_RE, x as SUPPORTED_CURRENCY_CODES, y as BYTES32_RE } from "./clock-m_aHLaNm.mjs";
2
+ import { formatUnits, keccak256, parseUnits, recoverAddress, toBytes } from "viem";
3
3
  import { Context, Data, Deferred, Duration, Effect, Exit, Fiber, Layer, Queue, Ref, Result, Schema, SchemaGetter, Scope } from "effect";
4
4
  import { makeFunctionReference } from "convex/server";
5
5
  //#region src/domain/identity/model.ts
@@ -19,7 +19,10 @@ const DEFINITIVE_PROVIDER_MODES = /* @__PURE__ */ new Set([
19
19
  "insufficient-balance",
20
20
  "insufficient-allowance",
21
21
  "rejected",
22
- "unauthorized"
22
+ "unauthorized",
23
+ "forbidden",
24
+ "bad-request",
25
+ "method-unsupported"
23
26
  ]);
24
27
  const isRetryable = (failure) => {
25
28
  if (failure.code === "CANCELLED" || failure.code === "SIGNER_REJECTED") return true;
@@ -398,938 +401,6 @@ const isRestoring = (state) => {
398
401
  * it in #1521; this ticket ships the selector they move onto. */
399
402
  const isClaimed = (state) => state.phase === "authenticated" && state.account.at === "claimed";
400
403
  //#endregion
401
- //#region ../config/src/tokens.ts
402
- /** `TestUSDC` ("USDX") — Base Sepolia, 6 decimals, open `mint`. (Canon §1.) */
403
- const USDX_ADDRESS_BASE_SEPOLIA = "0xf09fcbb6df9f8f918e58f9c8ab15a76ade862b77";
404
- USDX_ADDRESS_BASE_SEPOLIA.toLowerCase();
405
- //#endregion
406
- //#region ../config/src/org-payments.ts
407
- /** Zodiac MultiSendCallOnly module on Base Sepolia. */
408
- const MULTI_SEND_CALL_ONLY = "0x9641d764fc13c8b624c04430c7356c1c7c8102e2";
409
- //#endregion
410
- //#region ../config/src/safe.ts
411
- const BASE_SEPOLIA_CHAIN_ID = 84532;
412
- const SAFE_PROXY_FACTORY = "0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67";
413
- const SAFE_L2_SINGLETON = "0x29fcB43b46531BcA003ddC8FCB67FFE91900C762";
414
- const SAFE_MODULE_SETUP = "0x2dd68b007B46fBe91B9A7c3EDa5A7a1063cB5b47";
415
- const SAFE_4337_MODULE = "0x75cf11467937ce3F2f357CE24ffc3DBF8fD5c226";
416
- const MULTI_SEND = "0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526";
417
- /**
418
- * The Capxul bootstrap owner — the sole `setup()` owner of every unclaimed
419
- * personal Safe under derivation v2. This address is part of the CREATE2
420
- * preimage of EVERY personal Safe address: treat it exactly like
421
- * `SAFE_PROXY_FACTORY` (changing it is a derivation-version event → v3).
422
- * The private key lives backend-only (`CAPXUL_BOOTSTRAP_OWNER_PRIVATE_KEY`)
423
- * and signs exactly one kind of operation: the claim userOp that deploys the
424
- * Safe and swaps this owner out for the user's signer (PRD #462). The earlier
425
- * ClaimGuard derivation-v3 placeholder (#461) is closed; future mainnet-scale
426
- * hardening should be filed against the current payments/claim architecture.
427
- */
428
- const CAPXUL_BOOTSTRAP_OWNER = "0x425fca96f4a3e18fb80974e38096b5da460f2704";
429
- const SAFE_PROXY_CREATION_CODE = "0x608060405234801561001057600080fd5b506040516101e63803806101e68339818101604052602081101561003357600080fd5b8101908080519060200190929190505050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156100ca576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806101c46022913960400191505060405180910390fd5b806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505060ab806101196000396000f3fe608060405273ffffffffffffffffffffffffffffffffffffffff600054167fa619486e0000000000000000000000000000000000000000000000000000000060003514156050578060005260206000f35b3660008037600080366000845af43d6000803e60008114156070573d6000fd5b3d6000f3fea264697066735822122003d1488ee65e08fa41e58e888a9865554c535f2c77126a82cb4c0f917f31441364736f6c63430007060033496e76616c69642073696e676c65746f6e20616464726573732070726f7669646564";
430
- /**
431
- * Normalize an email for use as a Capxul Safe salt input.
432
- *
433
- * Trims surrounding whitespace and lowercases the address so that
434
- * `" User+Demo@Example.COM "` and `"user+demo@example.com"` derive
435
- * the same `safeAddress`. This is the canonical normalization rule —
436
- * any future change here would shift every existing user's Safe
437
- * address, so the rule is pinned by the fixture matrix in
438
- * `packages/config/tests/safe-address-conformance.test.ts`.
439
- *
440
- * @param email - The raw email address to normalize
441
- * @returns The trimmed, lowercased email
442
- */
443
- function normalizeSafeSaltEmail(email) {
444
- return email.trim().toLowerCase();
445
- }
446
- /**
447
- * Compute the deterministic Safe salt nonce for a `(namespace, email)`
448
- * pair. The salt nonce is the `bigint` reading of
449
- * `keccak256(namespace + ":" + normalizeSafeSaltEmail(email))`.
450
- *
451
- * Namespace defaults to `CAPXUL_SAFE_SALT_NAMESPACE`
452
- * (`"capxul:safe:email:v2"`) — the per-version Capxul scheme. Pass a
453
- * different namespace only for pinned pre-v2 artifacts
454
- * (`CAPXUL_SAFE_SALT_NAMESPACE_V1`, faucet Safe) or when bumping the scheme.
455
- *
456
- * @param input.email - The email to derive the salt nonce from
457
- * @param input.namespace - Optional namespace override (defaults to `CAPXUL_SAFE_SALT_NAMESPACE`)
458
- * @returns The Capxul-namespaced salt nonce as a `bigint`
459
- */
460
- function computeCapxulSafeSaltNonce(input) {
461
- const namespace = input.namespace ?? "capxul:safe:email:v2";
462
- const normalizedEmail = normalizeSafeSaltEmail(input.email);
463
- return BigInt(keccak256(toBytes(`${namespace}:${normalizedEmail}`)));
464
- }
465
- const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
466
- const safeSetupAbi = [{
467
- type: "function",
468
- name: "setup",
469
- stateMutability: "nonpayable",
470
- inputs: [
471
- {
472
- name: "_owners",
473
- type: "address[]"
474
- },
475
- {
476
- name: "_threshold",
477
- type: "uint256"
478
- },
479
- {
480
- name: "to",
481
- type: "address"
482
- },
483
- {
484
- name: "data",
485
- type: "bytes"
486
- },
487
- {
488
- name: "fallbackHandler",
489
- type: "address"
490
- },
491
- {
492
- name: "paymentToken",
493
- type: "address"
494
- },
495
- {
496
- name: "payment",
497
- type: "uint256"
498
- },
499
- {
500
- name: "paymentReceiver",
501
- type: "address"
502
- }
503
- ],
504
- outputs: []
505
- }];
506
- const enableModulesAbi = [{
507
- type: "function",
508
- name: "enableModules",
509
- stateMutability: "nonpayable",
510
- inputs: [{
511
- name: "modules",
512
- type: "address[]"
513
- }],
514
- outputs: []
515
- }];
516
- const multiSendAbi = [{
517
- type: "function",
518
- name: "multiSend",
519
- stateMutability: "payable",
520
- inputs: [{
521
- name: "transactions",
522
- type: "bytes"
523
- }],
524
- outputs: []
525
- }];
526
- function buildCapxulSafeInitializer(owner) {
527
- const enableModulesCall = encodeFunctionData({
528
- abi: enableModulesAbi,
529
- functionName: "enableModules",
530
- args: [[SAFE_4337_MODULE]]
531
- });
532
- const enableModulesByteLen = BigInt((enableModulesCall.length - 2) / 2);
533
- const multiSendPayload = encodePacked([
534
- "uint8",
535
- "address",
536
- "uint256",
537
- "uint256",
538
- "bytes"
539
- ], [
540
- 1,
541
- SAFE_MODULE_SETUP,
542
- 0n,
543
- enableModulesByteLen,
544
- enableModulesCall
545
- ]);
546
- const setupData = encodeFunctionData({
547
- abi: multiSendAbi,
548
- functionName: "multiSend",
549
- args: [multiSendPayload]
550
- });
551
- return encodeFunctionData({
552
- abi: safeSetupAbi,
553
- functionName: "setup",
554
- args: [
555
- [owner],
556
- 1n,
557
- MULTI_SEND,
558
- setupData,
559
- SAFE_4337_MODULE,
560
- ZERO_ADDRESS,
561
- 0n,
562
- ZERO_ADDRESS
563
- ]
564
- });
565
- }
566
- const ADDRESS_REGEX = /^0x[0-9a-fA-F]{40}$/;
567
- function validateAndNormalizeAddress(field, value) {
568
- const address = value.toLowerCase();
569
- if (!ADDRESS_REGEX.test(address)) throw Errors.invalidInput(field, `must be 0x + 40 hex chars, got ${value}`);
570
- return address;
571
- }
572
- /**
573
- * Pure derivation of the Capxul personal Safe address — **v2: email only**
574
- * (PRD #462). The Safe v1.4.1 (SafeL2) + 4337-module initializer's sole owner
575
- * is the fixed `CAPXUL_BOOTSTRAP_OWNER`, so the address is a pure function of
576
- * the (normalized) email and exists before any user signer does. The user's
577
- * signer is installed at claim time via `swapOwner` — signer rotation can
578
- * never move the address (org-domain rule D7, now system-wide).
579
- *
580
- * Returns the lowercased `0x` + 40 hex string (raw — no brand applied so this
581
- * function is callable from both `@capxul/config` consumers that don't have
582
- * `@capxul/types` available, and from packages that re-brand at their own
583
- * boundary).
584
- *
585
- * Algorithm: exactly mirrors `permissionless.toSafeSmartAccount({ version:
586
- * "1.4.1", safeSingletonAddress: SAFE_L2_SINGLETON, owners: [BOOTSTRAP] })`
587
- * + the Capxul-canonical module setup (delegatecall into
588
- * `SafeModuleSetup.enableModules([SAFE_4337_MODULE])` via the MultiSend lane
589
- * during proxy setup). The proxy creation code is pinned at
590
- * `SAFE_PROXY_CREATION_CODE`; the salt is Capxul-namespaced (v2) via
591
- * `computeCapxulSafeSaltNonce({ email })`.
592
- *
593
- * Canonical: SDK deployment adapters and
594
- * `packages/backend/convex/smartAccount/mutations.ts:provision` import this
595
- * function; the conformance test at
596
- * `packages/config/tests/safe-address-conformance.test.ts` pins the matrix.
597
- */
598
- function deriveCapxulSafeAddress(input) {
599
- return deriveCapxulSafeAddressForOwner({
600
- ownerAddress: CAPXUL_BOOTSTRAP_OWNER,
601
- email: input.email
602
- });
603
- }
604
- /**
605
- * Owner-parametrized derivation core. Two callers only:
606
- * 1. `deriveCapxulSafeAddress` (canonical v2: owner = bootstrap, namespace v2);
607
- * 2. the backend faucet Safe (`testUsdcMint.ts`: owner = deployer EOA,
608
- * namespace pinned to `CAPXUL_SAFE_SALT_NAMESPACE_V1` so its deployed
609
- * address never moves).
610
- * Do NOT introduce new owner-parametrized lanes — per-user owners in the
611
- * derivation is exactly the v1 mistake v2 removes.
612
- */
613
- function deriveCapxulSafeAddressForOwner(input) {
614
- const initializer = buildCapxulSafeInitializer(validateAndNormalizeAddress("ownerAddress", input.ownerAddress));
615
- const saltNonce = computeCapxulSafeSaltNonce(input.namespace === void 0 ? { email: input.email } : {
616
- email: input.email,
617
- namespace: input.namespace
618
- });
619
- const salt = keccak256(encodePacked(["bytes32", "uint256"], [keccak256(initializer), saltNonce]));
620
- const deploymentCode = concat([SAFE_PROXY_CREATION_CODE, encodeAbiParameters([{ type: "uint256" }], [BigInt(SAFE_L2_SINGLETON)])]);
621
- return getContractAddress({
622
- opcode: "CREATE2",
623
- from: SAFE_PROXY_FACTORY,
624
- salt,
625
- bytecodeHash: keccak256(deploymentCode)
626
- }).toLowerCase();
627
- }
628
- /**
629
- * Normalize a raw email for binding id + Safe salt derivation.
630
- * Delegates to {@link normalizeSafeSaltEmail} so binding resolution and
631
- * `deriveCapxulSafeAddress` never drift apart.
632
- */
633
- function normalizeBindingEmail(email) {
634
- return normalizeSafeSaltEmail(email);
635
- }
636
- //#endregion
637
- //#region ../config/src/capxul-payments-v2.ts
638
- /** The exact compiled CapxulPaymentsV2 ABI. */
639
- const CAPXUL_PAYMENTS_V2_ABI = [
640
- {
641
- type: "function",
642
- name: "cancel",
643
- inputs: [{
644
- name: "commitmentId",
645
- type: "uint256",
646
- internalType: "uint256"
647
- }, {
648
- name: "documentHash",
649
- type: "bytes32",
650
- internalType: "bytes32"
651
- }],
652
- outputs: [],
653
- stateMutability: "nonpayable"
654
- },
655
- {
656
- type: "function",
657
- name: "claim",
658
- inputs: [{
659
- name: "commitmentId",
660
- type: "uint256",
661
- internalType: "uint256"
662
- }],
663
- outputs: [],
664
- stateMutability: "nonpayable"
665
- },
666
- {
667
- type: "function",
668
- name: "claimableAmount",
669
- inputs: [{
670
- name: "commitmentId",
671
- type: "uint256",
672
- internalType: "uint256"
673
- }],
674
- outputs: [{
675
- name: "",
676
- type: "uint256",
677
- internalType: "uint256"
678
- }],
679
- stateMutability: "view"
680
- },
681
- {
682
- type: "function",
683
- name: "commitments",
684
- inputs: [{
685
- name: "",
686
- type: "uint256",
687
- internalType: "uint256"
688
- }],
689
- outputs: [
690
- {
691
- name: "settlementId",
692
- type: "bytes32",
693
- internalType: "bytes32"
694
- },
695
- {
696
- name: "creator",
697
- type: "address",
698
- internalType: "address"
699
- },
700
- {
701
- name: "recipient",
702
- type: "address",
703
- internalType: "address"
704
- },
705
- {
706
- name: "token",
707
- type: "address",
708
- internalType: "address"
709
- },
710
- {
711
- name: "totalAmount",
712
- type: "uint256",
713
- internalType: "uint256"
714
- },
715
- {
716
- name: "claimed",
717
- type: "uint256",
718
- internalType: "uint256"
719
- },
720
- {
721
- name: "startTime",
722
- type: "uint48",
723
- internalType: "uint48"
724
- },
725
- {
726
- name: "cliffTime",
727
- type: "uint48",
728
- internalType: "uint48"
729
- },
730
- {
731
- name: "endTime",
732
- type: "uint48",
733
- internalType: "uint48"
734
- },
735
- {
736
- name: "kind",
737
- type: "uint16",
738
- internalType: "uint16"
739
- },
740
- {
741
- name: "documentHash",
742
- type: "bytes32",
743
- internalType: "bytes32"
744
- },
745
- {
746
- name: "cancelled",
747
- type: "bool",
748
- internalType: "bool"
749
- }
750
- ],
751
- stateMutability: "view"
752
- },
753
- {
754
- type: "function",
755
- name: "createCommitment",
756
- inputs: [{
757
- name: "input",
758
- type: "tuple",
759
- internalType: "struct CapxulPaymentsV2.CommitmentInput",
760
- components: [
761
- {
762
- name: "settlementId",
763
- type: "bytes32",
764
- internalType: "bytes32"
765
- },
766
- {
767
- name: "recipient",
768
- type: "address",
769
- internalType: "address"
770
- },
771
- {
772
- name: "token",
773
- type: "address",
774
- internalType: "address"
775
- },
776
- {
777
- name: "totalAmount",
778
- type: "uint256",
779
- internalType: "uint256"
780
- },
781
- {
782
- name: "startTime",
783
- type: "uint48",
784
- internalType: "uint48"
785
- },
786
- {
787
- name: "cliffTime",
788
- type: "uint48",
789
- internalType: "uint48"
790
- },
791
- {
792
- name: "endTime",
793
- type: "uint48",
794
- internalType: "uint48"
795
- },
796
- {
797
- name: "kind",
798
- type: "uint16",
799
- internalType: "uint16"
800
- },
801
- {
802
- name: "documentHash",
803
- type: "bytes32",
804
- internalType: "bytes32"
805
- }
806
- ]
807
- }],
808
- outputs: [{
809
- name: "commitmentId",
810
- type: "uint256",
811
- internalType: "uint256"
812
- }],
813
- stateMutability: "nonpayable"
814
- },
815
- {
816
- type: "function",
817
- name: "nextCommitmentId",
818
- inputs: [],
819
- outputs: [{
820
- name: "",
821
- type: "uint256",
822
- internalType: "uint256"
823
- }],
824
- stateMutability: "view"
825
- },
826
- {
827
- type: "function",
828
- name: "redirect",
829
- inputs: [
830
- {
831
- name: "commitmentId",
832
- type: "uint256",
833
- internalType: "uint256"
834
- },
835
- {
836
- name: "recipient",
837
- type: "address",
838
- internalType: "address"
839
- },
840
- {
841
- name: "documentHash",
842
- type: "bytes32",
843
- internalType: "bytes32"
844
- }
845
- ],
846
- outputs: [],
847
- stateMutability: "nonpayable"
848
- },
849
- {
850
- type: "function",
851
- name: "send",
852
- inputs: [{
853
- name: "item",
854
- type: "tuple",
855
- internalType: "struct CapxulPaymentsV2.PaymentItem",
856
- components: [
857
- {
858
- name: "settlementId",
859
- type: "bytes32",
860
- internalType: "bytes32"
861
- },
862
- {
863
- name: "recipient",
864
- type: "address",
865
- internalType: "address"
866
- },
867
- {
868
- name: "token",
869
- type: "address",
870
- internalType: "address"
871
- },
872
- {
873
- name: "amount",
874
- type: "uint256",
875
- internalType: "uint256"
876
- },
877
- {
878
- name: "kind",
879
- type: "uint16",
880
- internalType: "uint16"
881
- },
882
- {
883
- name: "documentHash",
884
- type: "bytes32",
885
- internalType: "bytes32"
886
- }
887
- ]
888
- }],
889
- outputs: [],
890
- stateMutability: "nonpayable"
891
- },
892
- {
893
- type: "function",
894
- name: "sendBatch",
895
- inputs: [{
896
- name: "items",
897
- type: "tuple[]",
898
- internalType: "struct CapxulPaymentsV2.PaymentItem[]",
899
- components: [
900
- {
901
- name: "settlementId",
902
- type: "bytes32",
903
- internalType: "bytes32"
904
- },
905
- {
906
- name: "recipient",
907
- type: "address",
908
- internalType: "address"
909
- },
910
- {
911
- name: "token",
912
- type: "address",
913
- internalType: "address"
914
- },
915
- {
916
- name: "amount",
917
- type: "uint256",
918
- internalType: "uint256"
919
- },
920
- {
921
- name: "kind",
922
- type: "uint16",
923
- internalType: "uint16"
924
- },
925
- {
926
- name: "documentHash",
927
- type: "bytes32",
928
- internalType: "bytes32"
929
- }
930
- ]
931
- }],
932
- outputs: [],
933
- stateMutability: "nonpayable"
934
- },
935
- {
936
- type: "function",
937
- name: "vestedAmount",
938
- inputs: [{
939
- name: "commitmentId",
940
- type: "uint256",
941
- internalType: "uint256"
942
- }],
943
- outputs: [{
944
- name: "",
945
- type: "uint256",
946
- internalType: "uint256"
947
- }],
948
- stateMutability: "view"
949
- },
950
- {
951
- type: "event",
952
- name: "CommitmentCancelled",
953
- inputs: [
954
- {
955
- name: "commitmentId",
956
- type: "uint256",
957
- indexed: true,
958
- internalType: "uint256"
959
- },
960
- {
961
- name: "settlementId",
962
- type: "bytes32",
963
- indexed: true,
964
- internalType: "bytes32"
965
- },
966
- {
967
- name: "creator",
968
- type: "address",
969
- indexed: true,
970
- internalType: "address"
971
- },
972
- {
973
- name: "vestedUnclaimed",
974
- type: "uint256",
975
- indexed: false,
976
- internalType: "uint256"
977
- },
978
- {
979
- name: "unvestedReturned",
980
- type: "uint256",
981
- indexed: false,
982
- internalType: "uint256"
983
- },
984
- {
985
- name: "documentHash",
986
- type: "bytes32",
987
- indexed: false,
988
- internalType: "bytes32"
989
- }
990
- ],
991
- anonymous: false
992
- },
993
- {
994
- type: "event",
995
- name: "CommitmentCreated",
996
- inputs: [
997
- {
998
- name: "commitmentId",
999
- type: "uint256",
1000
- indexed: true,
1001
- internalType: "uint256"
1002
- },
1003
- {
1004
- name: "settlementId",
1005
- type: "bytes32",
1006
- indexed: true,
1007
- internalType: "bytes32"
1008
- },
1009
- {
1010
- name: "creator",
1011
- type: "address",
1012
- indexed: true,
1013
- internalType: "address"
1014
- },
1015
- {
1016
- name: "recipient",
1017
- type: "address",
1018
- indexed: false,
1019
- internalType: "address"
1020
- },
1021
- {
1022
- name: "token",
1023
- type: "address",
1024
- indexed: false,
1025
- internalType: "address"
1026
- },
1027
- {
1028
- name: "totalAmount",
1029
- type: "uint256",
1030
- indexed: false,
1031
- internalType: "uint256"
1032
- },
1033
- {
1034
- name: "startTime",
1035
- type: "uint48",
1036
- indexed: false,
1037
- internalType: "uint48"
1038
- },
1039
- {
1040
- name: "cliffTime",
1041
- type: "uint48",
1042
- indexed: false,
1043
- internalType: "uint48"
1044
- },
1045
- {
1046
- name: "endTime",
1047
- type: "uint48",
1048
- indexed: false,
1049
- internalType: "uint48"
1050
- },
1051
- {
1052
- name: "kind",
1053
- type: "uint16",
1054
- indexed: false,
1055
- internalType: "uint16"
1056
- },
1057
- {
1058
- name: "documentHash",
1059
- type: "bytes32",
1060
- indexed: false,
1061
- internalType: "bytes32"
1062
- }
1063
- ],
1064
- anonymous: false
1065
- },
1066
- {
1067
- type: "event",
1068
- name: "CommitmentRedirected",
1069
- inputs: [
1070
- {
1071
- name: "commitmentId",
1072
- type: "uint256",
1073
- indexed: true,
1074
- internalType: "uint256"
1075
- },
1076
- {
1077
- name: "settlementId",
1078
- type: "bytes32",
1079
- indexed: true,
1080
- internalType: "bytes32"
1081
- },
1082
- {
1083
- name: "oldRecipient",
1084
- type: "address",
1085
- indexed: true,
1086
- internalType: "address"
1087
- },
1088
- {
1089
- name: "newRecipient",
1090
- type: "address",
1091
- indexed: false,
1092
- internalType: "address"
1093
- },
1094
- {
1095
- name: "documentHash",
1096
- type: "bytes32",
1097
- indexed: false,
1098
- internalType: "bytes32"
1099
- }
1100
- ],
1101
- anonymous: false
1102
- },
1103
- {
1104
- type: "event",
1105
- name: "FundsClaimed",
1106
- inputs: [
1107
- {
1108
- name: "commitmentId",
1109
- type: "uint256",
1110
- indexed: true,
1111
- internalType: "uint256"
1112
- },
1113
- {
1114
- name: "settlementId",
1115
- type: "bytes32",
1116
- indexed: true,
1117
- internalType: "bytes32"
1118
- },
1119
- {
1120
- name: "recipient",
1121
- type: "address",
1122
- indexed: true,
1123
- internalType: "address"
1124
- },
1125
- {
1126
- name: "amount",
1127
- type: "uint256",
1128
- indexed: false,
1129
- internalType: "uint256"
1130
- },
1131
- {
1132
- name: "documentHash",
1133
- type: "bytes32",
1134
- indexed: false,
1135
- internalType: "bytes32"
1136
- }
1137
- ],
1138
- anonymous: false
1139
- },
1140
- {
1141
- type: "event",
1142
- name: "PaymentSent",
1143
- inputs: [
1144
- {
1145
- name: "settlementId",
1146
- type: "bytes32",
1147
- indexed: true,
1148
- internalType: "bytes32"
1149
- },
1150
- {
1151
- name: "sender",
1152
- type: "address",
1153
- indexed: true,
1154
- internalType: "address"
1155
- },
1156
- {
1157
- name: "recipient",
1158
- type: "address",
1159
- indexed: true,
1160
- internalType: "address"
1161
- },
1162
- {
1163
- name: "token",
1164
- type: "address",
1165
- indexed: false,
1166
- internalType: "address"
1167
- },
1168
- {
1169
- name: "amount",
1170
- type: "uint256",
1171
- indexed: false,
1172
- internalType: "uint256"
1173
- },
1174
- {
1175
- name: "kind",
1176
- type: "uint16",
1177
- indexed: false,
1178
- internalType: "uint16"
1179
- },
1180
- {
1181
- name: "documentHash",
1182
- type: "bytes32",
1183
- indexed: false,
1184
- internalType: "bytes32"
1185
- }
1186
- ],
1187
- anonymous: false
1188
- },
1189
- {
1190
- type: "error",
1191
- name: "AlreadyCancelled",
1192
- inputs: []
1193
- },
1194
- {
1195
- type: "error",
1196
- name: "AlreadyClaimed",
1197
- inputs: []
1198
- },
1199
- {
1200
- type: "error",
1201
- name: "DocumentHashMismatch",
1202
- inputs: [{
1203
- name: "expected",
1204
- type: "bytes32",
1205
- internalType: "bytes32"
1206
- }, {
1207
- name: "supplied",
1208
- type: "bytes32",
1209
- internalType: "bytes32"
1210
- }]
1211
- },
1212
- {
1213
- type: "error",
1214
- name: "InvalidTimeParams",
1215
- inputs: []
1216
- },
1217
- {
1218
- type: "error",
1219
- name: "NotCreator",
1220
- inputs: []
1221
- },
1222
- {
1223
- type: "error",
1224
- name: "NotRecipient",
1225
- inputs: []
1226
- },
1227
- {
1228
- type: "error",
1229
- name: "NothingToClaim",
1230
- inputs: []
1231
- },
1232
- {
1233
- type: "error",
1234
- name: "SettlementIdConsumed",
1235
- inputs: [{
1236
- name: "settlementId",
1237
- type: "bytes32",
1238
- internalType: "bytes32"
1239
- }]
1240
- },
1241
- {
1242
- type: "error",
1243
- name: "TokenCallReturnedFalse",
1244
- inputs: [{
1245
- name: "token",
1246
- type: "address",
1247
- internalType: "address"
1248
- }]
1249
- },
1250
- {
1251
- type: "error",
1252
- name: "TokenHasNoCode",
1253
- inputs: [{
1254
- name: "token",
1255
- type: "address",
1256
- internalType: "address"
1257
- }]
1258
- },
1259
- {
1260
- type: "error",
1261
- name: "ZeroAddress",
1262
- inputs: []
1263
- },
1264
- {
1265
- type: "error",
1266
- name: "ZeroAmount",
1267
- inputs: []
1268
- },
1269
- {
1270
- type: "error",
1271
- name: "ZeroDocumentHash",
1272
- inputs: []
1273
- },
1274
- {
1275
- type: "error",
1276
- name: "ZeroSettlementId",
1277
- inputs: []
1278
- }
1279
- ];
1280
- /** Immutable CapxulPaymentsV2 deployment on Base Sepolia. */
1281
- const CAPXUL_PAYMENTS_V2_ADDRESS = "0x7a5c25aB7ce91d7a475B71cd1ec33E230291f8a4";
1282
- //#endregion
1283
- //#region ../config/src/route.ts
1284
- /** USDX on Base Sepolia — the only settlement token in v1. */
1285
- const USDX_BASE_SEPOLIA_TOKEN = {
1286
- chainId: BASE_SEPOLIA_CHAIN_ID,
1287
- address: USDX_ADDRESS_BASE_SEPOLIA,
1288
- decimals: 6
1289
- };
1290
- USDX_BASE_SEPOLIA_TOKEN.chainId;
1291
- USDX_BASE_SEPOLIA_TOKEN.chainId;
1292
- 10n ** BigInt(6);
1293
- function normalizeOrgRoleLabel(label) {
1294
- const normalized = label.trim().replace(/\s+/g, " ");
1295
- if (normalized.length === 0) throw Errors.invalidInput("role.label", "must be a non-empty role label");
1296
- return normalized;
1297
- }
1298
- function orgRoleKeyForLabel(label) {
1299
- return keccak256(toBytes(normalizeOrgRoleLabel(label).toLowerCase()));
1300
- }
1301
- padHex(stringToHex("FM_DAILY"), {
1302
- size: 32,
1303
- dir: "right"
1304
- }), padHex(stringToHex("TL_DAILY"), {
1305
- size: 32,
1306
- dir: "right"
1307
- });
1308
- padHex(concat([MULTI_SEND_CALL_ONLY, "0x8d80ff0a"]), {
1309
- dir: "right",
1310
- size: 32
1311
- });
1312
- function paymentsV2Signature(name) {
1313
- const item = CAPXUL_PAYMENTS_V2_ABI.find((candidate) => candidate.type === "function" && candidate.name === name);
1314
- if (item === void 0) throw new Error(`CapxulPaymentsV2 ABI has no ${name} function`);
1315
- return toFunctionSignature(item);
1316
- }
1317
- paymentsV2Signature("send");
1318
- paymentsV2Signature("sendBatch");
1319
- paymentsV2Signature("createCommitment");
1320
- paymentsV2Signature("cancel");
1321
- paymentsV2Signature("redirect");
1322
- new Map([
1323
- ["assignRoles(address,bytes32[],bool[])", "AssignRoles(address,bytes32[],bool[])"],
1324
- ["allowTarget(bytes32,address,uint8)", "AllowTarget(bytes32,address,uint8)"],
1325
- ["scopeTarget(bytes32,address)", "ScopeTarget(bytes32,address)"],
1326
- ["revokeTarget(bytes32,address)", "RevokeTarget(bytes32,address)"],
1327
- ["allowFunction(bytes32,address,bytes4,uint8)", "AllowFunction(bytes32,address,bytes4,uint8)"],
1328
- ["scopeFunction(bytes32,address,bytes4,(uint8,uint8,uint8,bytes)[],uint8)", "ScopeFunction(bytes32,address,bytes4,(uint8,uint8,uint8,bytes)[],uint8)"],
1329
- ["revokeFunction(bytes32,address,bytes4)", "RevokeFunction(bytes32,address,bytes4)"],
1330
- ["setAllowance(bytes32,uint128,uint128,uint128,uint64,uint64)", "SetAllowance(bytes32,uint128,uint128,uint128,uint64,uint64)"]
1331
- ].map(([functionSignature, eventSignature]) => [toFunctionSelector(functionSignature), toEventSelector(eventSignature)]));
1332
- //#endregion
1333
404
  //#region ../wire/src/brands.ts
1334
405
  const lowercasedString = Schema.String.pipe(Schema.decodeTo(Schema.String, {
1335
406
  decode: SchemaGetter.transform((value) => value.toLowerCase()),
@@ -2950,33 +2021,6 @@ Schema.Struct({
2950
2021
  @media (max-width:540px){.capxul-doc{padding:1.75rem 1.25rem}.capxul-doc .doc-parties{grid-template-columns:1fr}}
2951
2022
  `.trim();
2952
2023
  //#endregion
2953
- //#region ../wire/src/secret-material.ts
2954
- const SENSITIVE_MATERIAL_PATTERNS = [
2955
- /0x[a-fA-F0-9]{40,}/u,
2956
- /(?:^|[^a-fA-F0-9])[a-fA-F0-9]{64}(?:$|[^a-fA-F0-9])/u,
2957
- /eyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/u,
2958
- /(?:(?:sk|pk|rk)_(?:live|test)|(?:phc|phx|ghp|gho|ghu|ghs|ghr|whsec)_|github_pat_|xox[baprs]-|AKIA[0-9A-Z]{16}|AIza)[A-Za-z0-9_-]*/iu
2959
- ];
2960
- const RAW_PRIVATE_KEY_MASK = /(^|[^a-fA-F0-9])[a-fA-F0-9]{64}(?=$|[^a-fA-F0-9])/gu;
2961
- const KNOWN_CREDENTIAL_MASK = /(?:(?:sk|pk|rk)_(?:live|test)|(?:phc|phx|ghp|gho|ghu|ghs|ghr|whsec)_|github_pat_|xox[baprs]-|AKIA[0-9A-Z]{16}|AIza)[A-Za-z0-9_-]*/giu;
2962
- const LABELLED_SECRET_MASK = /\b(api[ _-]?key|access[ _-]?token|token|secret|password|passphrase|private[ _-]?key|authorization|cookie|signature|request[ _-]?body|credential|otp|one[ _-]?time[ _-]?(?:password|code)|verification[ _-]?code)\b\s*[:=]\s*(?:"[^"]*"|'[^']*'|[^\s,;]+)/giu;
2963
- /**
2964
- * Reject: does the value carry any known secret material? Best effort — callers
2965
- * drop the whole value on a match; a false negative is a leak, a false positive
2966
- * merely omits an observation field.
2967
- */
2968
- function containsSensitiveMaterial(value) {
2969
- return SENSITIVE_MATERIAL_PATTERNS.some((pattern) => pattern.test(value));
2970
- }
2971
- /**
2972
- * Mask: return the value with every known secret rewritten to `[REDACTED]`,
2973
- * preserving surrounding text. Used where a value must still be shown (log
2974
- * lines, issue bodies) but must not carry live credentials.
2975
- */
2976
- function redactSecrets(value) {
2977
- return value.replace(/\bBearer\s+[^\s,;]+/giu, "Bearer [REDACTED]").replace(/\beyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\b/gu, "[REDACTED]").replace(/\b0x[a-fA-F0-9]{40,}\b/gu, "[REDACTED]").replace(RAW_PRIVATE_KEY_MASK, "$1[REDACTED]").replace(KNOWN_CREDENTIAL_MASK, "[REDACTED]").replace(LABELLED_SECRET_MASK, (_match, label) => `${label}=[REDACTED]`);
2978
- }
2979
- //#endregion
2980
2024
  //#region ../wire/src/observation-context.ts
2981
2025
  /** Single bounded HTTP carrier used before a Convex action envelope exists. */
2982
2026
  const OBSERVATION_CONTEXT_HEADER = "x-capxul-observation-context";
@@ -4546,7 +3590,7 @@ const moneyExecutionContract = {
4546
3590
  };
4547
3591
  //#endregion
4548
3592
  //#region package.json
4549
- var version = "2.8.2";
3593
+ var version = "3.0.2";
4550
3594
  //#endregion
4551
3595
  //#region src/telemetry/exception-projection.ts
4552
3596
  /** Fixed fallback for failures that have no safe message. */
@@ -4558,6 +3602,10 @@ function projectSdkException(input) {
4558
3602
  const errorKind = normalizeExceptionErrorKind(input.errorKind);
4559
3603
  const mode = isFailureMode(input.failureMode) ? input.failureMode : void 0;
4560
3604
  const message = input.message ?? "Capxul SDK operation failed";
3605
+ const evidence = mode === void 0 ? "" : chainEvidenceLabel({
3606
+ httpStatus: input.chainHttpStatus,
3607
+ rpcCode: input.chainRpcCode
3608
+ });
4561
3609
  const where = input.chainUpstream === void 0 ? "" : ` on ${input.chainUpstream}${input.chainMethod === void 0 ? "" : ` during ${input.chainMethod}`}`;
4562
3610
  return {
4563
3611
  ...input.properties,
@@ -4569,13 +3617,19 @@ function projectSdkException(input) {
4569
3617
  $exception_message: message,
4570
3618
  $exception_level: "error",
4571
3619
  $exception_fingerprint: failureFingerprint(errorKind, mode, operation),
4572
- $issue_name: `${errorKind}${mode === void 0 ? "" : `: ${mode}`}${where} (${operation})`,
3620
+ $issue_name: `${errorKind}${mode === void 0 ? "" : `: ${mode}`}${evidence}${where} (${operation})`,
4573
3621
  $issue_description: input.issueDescription ?? message,
4574
3622
  $exception_list: input.exceptionList
4575
3623
  };
4576
3624
  }
3625
+ /**
3626
+ * `:` and `/` are allowed because this also accepts a `provider_operation`
3627
+ * fallback, and a Convex function names itself `dir/file:function`. Kept byte-
3628
+ * equal to the backend's own `normalizeOperation`: when the two disagree, one
3629
+ * side silently rewrites the operation to `unknown` and the issue loses its name.
3630
+ */
4577
3631
  function normalizeExceptionOperation(value) {
4578
- return typeof value === "string" && /^[A-Za-z0-9_][A-Za-z0-9_.-]{0,255}$/u.test(value) ? value : "unknown";
3632
+ return typeof value === "string" && /^[A-Za-z0-9_][A-Za-z0-9_.:/-]{0,255}$/u.test(value) ? value : "unknown";
4579
3633
  }
4580
3634
  function normalizeExceptionErrorKind(value) {
4581
3635
  return safeExceptionLabel(value) ?? "UNKNOWN";
@@ -4743,7 +3797,7 @@ function report(adapter, kind, operation, cause, invocation, origin) {
4743
3797
  }
4744
3798
  } else if (reportedByMachine(cause)) return;
4745
3799
  const operationName = normalizeOperation(operation);
4746
- const kindName = normalizeErrorKind(errorKind$1(cause));
3800
+ const kindName = normalizeErrorKind(errorKind(cause));
4747
3801
  const context = sanitizeObservationContext({
4748
3802
  ...invocation.context,
4749
3803
  ...isCapxulError(cause) && cause.correlationId !== void 0 ? { correlationId: cause.correlationId } : {}
@@ -4840,6 +3894,8 @@ function projectFailureException(failure, properties) {
4840
3894
  issueDescription: issueDescription(failure, message),
4841
3895
  ...failure.detail?.chain_upstream === void 0 ? {} : { chainUpstream: failure.detail.chain_upstream },
4842
3896
  ...failure.detail?.chain_method === void 0 ? {} : { chainMethod: failure.detail.chain_method },
3897
+ ...failure.detail?.chain_http_status === void 0 ? {} : { chainHttpStatus: failure.detail.chain_http_status },
3898
+ ...failure.detail?.chain_rpc_code === void 0 ? {} : { chainRpcCode: failure.detail.chain_rpc_code },
4843
3899
  exceptionList: [{
4844
3900
  type: failure.errorKind,
4845
3901
  value: message,
@@ -4864,8 +3920,8 @@ function projectFailureException(failure, properties) {
4864
3920
  });
4865
3921
  }
4866
3922
  /**
4867
- * The decoded revert leads the description: the provider's own message masks
4868
- * the raw revert data (`reason: [REDACTED]`), and the name plus arguments
3923
+ * The decoded revert leads the description: the provider's own message carries
3924
+ * the raw revert data (`reason: 0x…`), and the name plus arguments
4869
3925
  * (`Error(message=GS205)`) is what tells one revert from another.
4870
3926
  */
4871
3927
  function issueDescription(failure, message) {
@@ -4945,7 +4001,7 @@ function failureEvidence(cause) {
4945
4001
  return {};
4946
4002
  }
4947
4003
  }
4948
- function errorKind$1(cause) {
4004
+ function errorKind(cause) {
4949
4005
  try {
4950
4006
  if (isCapxulError(cause)) return normalizeErrorKind(cause.code);
4951
4007
  if (cause instanceof Error) return normalizeErrorKind(cause.name);
@@ -5025,13 +4081,13 @@ function observationError(cause) {
5025
4081
  function sanitizeChainDetail(source, detail) {
5026
4082
  for (const key of [
5027
4083
  "provider",
5028
- "provider_operation",
5029
4084
  "failure_mode",
5030
4085
  "reason"
5031
4086
  ]) {
5032
4087
  const value = source[key];
5033
4088
  if (typeof value === "string" && ENUMERATED_DETAIL_RE.test(value)) detail[key] = value;
5034
4089
  }
4090
+ sanitizeProviderOperation(source, detail);
5035
4091
  sanitizeProviderErrorDetail(source, detail);
5036
4092
  const status = source.http_status;
5037
4093
  if (typeof status === "number" && Number.isInteger(status) && status >= 100 && status <= 599) detail.http_status = status;
@@ -5060,6 +4116,43 @@ function sanitizeChainDetail(source, detail) {
5060
4116
  }
5061
4117
  const providerMessage = evidenceText(source.chain_provider_message);
5062
4118
  if (providerMessage !== void 0) detail.chain_provider_message = providerMessage;
4119
+ sanitizeChainAttempts(source, detail);
4120
+ }
4121
+ /** One flat attempt entry, or undefined when a field is not what the vocabulary allows. */
4122
+ function sanitizeChainAttempt(entry) {
4123
+ if (!isPlainObject(entry)) return void 0;
4124
+ const duration = entry.duration_ms;
4125
+ if (!isChainUpstream(entry.upstream) || !isFailureMode(entry.failure_mode) || typeof duration !== "number" || !Number.isFinite(duration) || duration < 0) return;
4126
+ return {
4127
+ upstream: entry.upstream,
4128
+ failure_mode: entry.failure_mode,
4129
+ ...typeof entry.http_status === "number" && Number.isInteger(entry.http_status) ? { http_status: entry.http_status } : {},
4130
+ ...typeof entry.rpc_code === "number" && Number.isInteger(entry.rpc_code) ? { rpc_code: entry.rpc_code } : {},
4131
+ duration_ms: Math.round(duration)
4132
+ };
4133
+ }
4134
+ /**
4135
+ * The attempt sequence and the refusing upstream's headers (#1818), same
4136
+ * bounds as the backend; a malformed entry is dropped, never invented.
4137
+ */
4138
+ function sanitizeChainAttempts(source, detail) {
4139
+ if (Array.isArray(source.chain_attempts)) {
4140
+ const attempts = source.chain_attempts.slice(0, 5).map(sanitizeChainAttempt);
4141
+ if (attempts.length > 0 && attempts.every((attempt) => attempt !== void 0)) detail.chain_attempts = attempts;
4142
+ }
4143
+ if (isPlainObject(source.chain_response_headers)) {
4144
+ const raw = source.chain_response_headers;
4145
+ const headers = boundedResponseHeaders((name) => {
4146
+ const value = raw[name];
4147
+ return typeof value === "string" ? value : null;
4148
+ });
4149
+ if (Object.keys(headers).length > 0) detail.chain_response_headers = headers;
4150
+ }
4151
+ }
4152
+ /** Its own check because a provider operation carries that provider's separators. */
4153
+ function sanitizeProviderOperation(source, detail) {
4154
+ const value = source.provider_operation;
4155
+ if (typeof value === "string" && PROVIDER_OPERATION_RE.test(value)) detail.provider_operation = value;
5063
4156
  }
5064
4157
  function sanitizeProviderErrorDetail(source, detail) {
5065
4158
  if (source.provider_error_source !== "openfort") return;
@@ -5105,14 +4198,25 @@ function sanitizeFailureDetail(input) {
5105
4198
  }
5106
4199
  /** Enumerated codes only (`convex`, `no-secure-context`, `bootstrap-encode`); free text fails. */
5107
4200
  const ENUMERATED_DETAIL_RE = /^[A-Za-z][A-Za-z0-9_.-]{0,63}$/u;
4201
+ /**
4202
+ * A provider operation NAMES A FUNCTION on the provider, so it carries that
4203
+ * provider's separators. Convex writes its own as `dir/file:function`
4204
+ * (`media:setProfileImage`), and the enumerated shape above rejects both `:`
4205
+ * and `/` — so the operation was dropped and the PostHog issue lost the name of
4206
+ * what actually failed (staging, 2026-09-03). This widens the separators, not
4207
+ * the class: no spaces, same bound, and it matches the backend's own
4208
+ * `normalizeOperation`, which has always accepted them.
4209
+ */
4210
+ const PROVIDER_OPERATION_RE = /^[A-Za-z][A-Za-z0-9_.:/-]{0,63}$/u;
5108
4211
  const TARGET_HOST_RE = /^[A-Za-z0-9.[\]:-]{1,253}$/u;
5109
4212
  /** A four-byte revert selector, or the bare `0x` of an empty revert. */
5110
4213
  const REVERT_SELECTOR_RE = /^0x(?:[0-9a-fA-F]{8})?$/u;
5111
4214
  function normalizeSdkVersion(value) {
5112
4215
  return typeof value === "string" && /^[A-Za-z0-9][A-Za-z0-9.+_-]{0,127}$/u.test(value) ? value : "unknown";
5113
4216
  }
4217
+ /** Same shape as the backend's `normalizeOperation`: a Convex path (`dir/file:fn`) survives. */
5114
4218
  function normalizeOperation(value) {
5115
- return typeof value === "string" && /^[A-Za-z0-9_][A-Za-z0-9_.-]{0,255}$/u.test(value) ? value : "unknown";
4219
+ return typeof value === "string" && /^[A-Za-z0-9_][A-Za-z0-9_.:/-]{0,255}$/u.test(value) ? value : "unknown";
5116
4220
  }
5117
4221
  function normalizeErrorKind(value) {
5118
4222
  return typeof value === "string" && /^[A-Za-z][A-Za-z0-9_.-]{0,63}$/u.test(value) ? value : "Error";
@@ -6214,42 +5318,6 @@ function mapOk(result, f) {
6214
5318
  }
6215
5319
  }
6216
5320
  //#endregion
6217
- //#region src/ports/auth-client.ts
6218
- var AuthClientError = class extends Data.TaggedError("AuthClientError") {};
6219
- var AuthClientPortTag = class extends Context.Service()("@capxul/sdk/ports/AuthClientPort") {};
6220
- //#endregion
6221
- //#region src/adapters/auth-client/effect-port.ts
6222
- function authClientPortFromPromiseAdapter(adapter) {
6223
- return {
6224
- canSendOtp: (input, options) => fromResult("canSendOtp", () => adapter.canSendOtp(input, options)),
6225
- sendOtp: (input, options) => fromResult("sendOtp", () => adapter.sendOtp(input, options)),
6226
- verifyOtp: (input, options) => fromResult("verifyOtp", () => adapter.verifyOtp(input, options)),
6227
- getSession: (options) => fromResult("getSession", () => adapter.getSession(options)),
6228
- signOut: (options) => fromResult("signOut", () => adapter.signOut(options)),
6229
- getConvexJwt: (options) => fromResult("getConvexJwt", () => adapter.getConvexJwt(options))
6230
- };
6231
- }
6232
- function fromResult(operation, run) {
6233
- return Effect.tryPromise({
6234
- try: run,
6235
- catch: (cause) => new AuthClientError({
6236
- operation,
6237
- kind: "thrown",
6238
- cause
6239
- })
6240
- }).pipe(Effect.flatMap((result) => result.ok ? Effect.succeed(result.value) : Effect.fail(new AuthClientError({
6241
- operation,
6242
- kind: errorKind(result.error),
6243
- cause: result.error
6244
- }))));
6245
- }
6246
- function errorKind(error) {
6247
- if (error.code === "CANCELLED") return "cancelled";
6248
- if (error.code === "NETWORK_ERROR") return "network";
6249
- if (error.code === "INVALID_INPUT" || error.code === "OTP_EXPIRED") return "validation";
6250
- return "provider";
6251
- }
6252
- //#endregion
6253
5321
  //#region src/ports/bootstrap.ts
6254
5322
  var BootstrapError = class extends Data.TaggedError("BootstrapError") {};
6255
5323
  function bootstrapErrorFromCapxul(kind, error) {
@@ -6263,10 +5331,6 @@ function bootstrapErrorFromCapxul(kind, error) {
6263
5331
  }
6264
5332
  var BootstrapPortTag = class extends Context.Service()("@capxul/sdk/ports/BootstrapPort") {};
6265
5333
  //#endregion
6266
- //#region src/ports/clock.ts
6267
- var ClockError = class extends Data.TaggedError("ClockError") {};
6268
- var ClockPortTag = class extends Context.Service()("@capxul/sdk/ports/ClockPort") {};
6269
- //#endregion
6270
5334
  //#region src/ports/convex-call.ts
6271
5335
  var ConvexCallError = class extends Data.TaggedError("ConvexCallError") {};
6272
5336
  function convexCallErrorFromCapxul(operation, error, transport) {
@@ -6434,6 +5498,29 @@ const TelemetryEnvelopeProps = {
6434
5498
  */
6435
5499
  const FailureModeSchema = Schema.Literals(FAILURE_MODES$1);
6436
5500
  const ChainUpstreamSchema = Schema.Literals(CHAIN_UPSTREAMS);
5501
+ /**
5502
+ * The refusing upstream's response headers (#1818): exactly the names in
5503
+ * `RESPONSE_HEADER_ALLOWLIST`, each optional, so the catalog itself refuses a
5504
+ * `set-cookie` or `authorization` that a producer let through.
5505
+ */
5506
+ const ResponseHeadersSchema = Schema.Struct({
5507
+ "retry-after": OptionalString,
5508
+ "www-authenticate": OptionalString,
5509
+ "content-type": OptionalString,
5510
+ "x-request-id": OptionalString,
5511
+ "cf-ray": OptionalString,
5512
+ "x-ratelimit-remaining": OptionalString,
5513
+ "x-ratelimit-reset": OptionalString,
5514
+ server: OptionalString
5515
+ });
5516
+ /** One upstream tried, flat (#1818): the `chain_attempts` entry on every producer's row. */
5517
+ const ChainAttemptSchema = Schema.Struct({
5518
+ upstream: ChainUpstreamSchema,
5519
+ failure_mode: FailureModeSchema,
5520
+ http_status: Schema.optional(Schema.Number),
5521
+ rpc_code: Schema.optional(Schema.Number),
5522
+ duration_ms: Schema.Number
5523
+ });
6437
5524
  const ChainCauseTelemetryProps = {
6438
5525
  failure_mode: Schema.optional(FailureModeSchema),
6439
5526
  chain_upstream: Schema.optional(ChainUpstreamSchema),
@@ -6444,7 +5531,9 @@ const ChainCauseTelemetryProps = {
6444
5531
  chain_revert_name: OptionalString,
6445
5532
  chain_revert_selector: OptionalString,
6446
5533
  chain_revert_args: Schema.optional(Schema.Record(Schema.String, Schema.String)),
6447
- chain_provider_message: OptionalString
5534
+ chain_provider_message: OptionalString,
5535
+ chain_attempts: Schema.optional(Schema.Array(ChainAttemptSchema)),
5536
+ chain_response_headers: Schema.optional(ResponseHeadersSchema)
6448
5537
  };
6449
5538
  /**
6450
5539
  * Stamp the required envelope onto an event at its emit boundary. Call-site
@@ -6562,7 +5651,8 @@ const ChainUpstreamFallbackProps = Schema.Struct({
6562
5651
  failure_mode: FailureModeSchema,
6563
5652
  exhausted: Schema.Boolean,
6564
5653
  http_status: Schema.optional(Schema.Number),
6565
- rpc_code: Schema.optional(Schema.Number)
5654
+ rpc_code: Schema.optional(Schema.Number),
5655
+ response_headers: Schema.optional(ResponseHeadersSchema)
6566
5656
  });
6567
5657
  const BundlerErrorProps = Schema.Struct({
6568
5658
  ...TelemetryEnvelopeProps,
@@ -9089,10 +8179,18 @@ async function recordSetupFailure(setup, orgId, error, retryable, observationSou
9089
8179
  if (!scopedRecorded.ok) return scopedRecorded;
9090
8180
  return scopedRecorded;
9091
8181
  }
8182
+ /**
8183
+ * ADR-0023 R7: the layer that saw the chain failure says whether the same
8184
+ * request can succeed later; its word wins over the mode table. The table is
8185
+ * the one `identity/model.ts` uses, so the two gates read one list
8186
+ * (`org.account.get` retried a `transient: false` 403 in 1.5 s, 2026-09-03).
8187
+ */
9092
8188
  function isRetryableProviderFailure(error) {
9093
- const mode = error.details?.failure_mode;
9094
- return mode !== "auth-origin-mismatch" && mode !== "app-env-allowlist" && mode !== "no-secure-context";
8189
+ if (error.chain !== void 0) return error.chain.retryable;
8190
+ const mode = error.mode ?? error.details?.failure_mode;
8191
+ return !DEFINITIVE_PROVIDER_MODES.has(isFailureMode(mode) ? mode : void 0);
9095
8192
  }
8193
+ /** @internal Exported for the retry-gate test; the surface calls it from the setup loop. */
9096
8194
  function isRetryableOrganizationSetupFailure(error) {
9097
8195
  if (error.code === "CANCELLED" || error.code === "SIGNER_REJECTED") return true;
9098
8196
  if (error.code === "PROVIDER_ERROR") return isRetryableProviderFailure(error);
@@ -9809,4 +8907,4 @@ function withHostObservationControls(snapshot, input) {
9809
8907
  return captured === void 0 ? copied : attachInvocationObservation(copied, captured);
9810
8908
  }
9811
8909
  //#endregion
9812
- export { sanitizeObservationContext as $, observationContextProps as A, fromWei as B, AuthClientError as C, CAPXUL_SDK_EXPECTED_OUTCOME_EVENT as D, toWei as E, normalizeExceptionErrorKind as F, isSignerNotReadySignal as G, formatTraceparent as H, normalizeExceptionOperation as I, resolveFailureMode as J, openfortSignerNotReadyCode as K, projectSdkException as L, postHogFailureObservation as M, EXCEPTION_MESSAGE as N, failureDetail as O, SDK_VERSION as P, encodeObservationContextHeader as Q, safeExceptionLabel as R, authClientPortFromPromiseAdapter as S, fingerprintPaymentIntent as T, causeChain as U, isSettingUpLifecycle as V, injectedWalletSigner as W, readInvocationObservation as X, copyInvocationObservation as Y, OBSERVATION_CONTEXT_HEADER as Z, convexCallErrorFromCapxul as _, AccountReadPortTag as a, CAPXUL_PAYMENTS_V2_ADDRESS as at, BootstrapPortTag as b, redactTelemetryEvent as c, deriveCapxulSafeAddress as ct, retryIdempotentRead as d, isRestoring as dt, PAYMENT_DIRECTIONS as et, PRODUCT_INVOCATION as f, ConvexCallPortTag as g, identityErrorFromCapxul as h, smartAccountErrorFromCapxul as i, EngineeringTelemetryBootstrapPolicy as it, observeFailedResult as j, failureEvidenceProps as k, redactTelemetryProps as l, destination as lt, IdentityPortTag as m, detectAuthCacheAdapter as n, CAPXUL_FUNCTIONS as nt, accountReadErrorFromCapxul as o, normalizeBindingEmail as ot, wireChainId as p, signerFailure as q, SmartAccountPortTag as r, BootstrapEnvelope as rt, TelemetryPortTag as s, BASE_SEPOLIA_CHAIN_ID as st, assembleCapxulClient as t, PAYMENT_STATUSES as tt, stampTelemetryEnvelope as u, isClaimed as ut, ClockError as v, AuthClientPortTag as w, bootstrapErrorFromCapxul as x, ClockPortTag as y, version as z };
8910
+ export { EngineeringTelemetryBootstrapPolicy as $, normalizeExceptionErrorKind as A, isSignerNotReadySignal as B, failureDetail as C, postHogFailureObservation as D, observeFailedResult as E, fromWei as F, readInvocationObservation as G, signerFailure as H, isSettingUpLifecycle as I, sanitizeObservationContext as J, OBSERVATION_CONTEXT_HEADER as K, formatTraceparent as L, projectSdkException as M, safeExceptionLabel as N, EXCEPTION_MESSAGE as O, version as P, BootstrapEnvelope as Q, causeChain as R, CAPXUL_SDK_EXPECTED_OUTCOME_EVENT as S, observationContextProps as T, resolveFailureMode as U, openfortSignerNotReadyCode as V, copyInvocationObservation as W, PAYMENT_STATUSES as X, PAYMENT_DIRECTIONS as Y, CAPXUL_FUNCTIONS as Z, convexCallErrorFromCapxul as _, AccountReadPortTag as a, fingerprintPaymentIntent as b, redactTelemetryEvent as c, retryIdempotentRead as d, destination as et, PRODUCT_INVOCATION as f, ConvexCallPortTag as g, identityErrorFromCapxul as h, smartAccountErrorFromCapxul as i, normalizeExceptionOperation as j, SDK_VERSION as k, redactTelemetryProps as l, IdentityPortTag as m, detectAuthCacheAdapter as n, isRestoring as nt, accountReadErrorFromCapxul as o, wireChainId as p, encodeObservationContextHeader as q, SmartAccountPortTag as r, TelemetryPortTag as s, assembleCapxulClient as t, isClaimed as tt, stampTelemetryEnvelope as u, BootstrapPortTag as v, failureEvidenceProps as w, toWei as x, bootstrapErrorFromCapxul as y, injectedWalletSigner as z };