@dexterai/x402 1.9.0 → 1.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +101 -8
- package/dist/client/index.cjs +28 -0
- package/dist/client/index.cjs.map +1 -1
- package/dist/client/index.d.cts +2 -1
- package/dist/client/index.d.ts +2 -1
- package/dist/client/index.js +25 -0
- package/dist/client/index.js.map +1 -1
- package/dist/react/index.cjs +40 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +10 -1
- package/dist/react/index.d.ts +10 -1
- package/dist/react/index.js +38 -1
- package/dist/react/index.js.map +1 -1
- package/dist/server/index.cjs +16 -1
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.cts +10 -1
- package/dist/server/index.d.ts +10 -1
- package/dist/server/index.js +15 -1
- package/dist/server/index.js.map +1 -1
- package/dist/{x402-client-BDaOwfgE.d.cts → sponsored-access-BCB2CxdG.d.cts} +68 -1
- package/dist/{x402-client-DIcp-PvX.d.ts → sponsored-access-H1EX6zpi.d.ts} +68 -1
- package/package.json +2 -6
package/dist/react/index.d.cts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { a as X402Client } from '../
|
|
1
|
+
import { a as X402Client } from '../sponsored-access-BCB2CxdG.cjs';
|
|
2
|
+
export { f as fireImpressionBeacon, b as getSponsoredRecommendations } from '../sponsored-access-BCB2CxdG.cjs';
|
|
2
3
|
import { W as WalletSet, B as BalanceInfo } from '../types-DmqH9yD8.cjs';
|
|
4
|
+
import { SponsoredRecommendation } from '@dexterai/x402-ads-types';
|
|
5
|
+
export { SponsoredRecommendation } from '@dexterai/x402-ads-types';
|
|
3
6
|
import { a as AccessPassTier } from '../types-BQvaF8lB.cjs';
|
|
4
7
|
export { A as AccessPassClientConfig, b as AccessPassInfo, X as X402Error } from '../types-BQvaF8lB.cjs';
|
|
5
8
|
|
|
@@ -114,6 +117,12 @@ interface UseX402PaymentReturn {
|
|
|
114
117
|
/** Seconds remaining on the pass */
|
|
115
118
|
remainingSeconds: number | null;
|
|
116
119
|
} | null;
|
|
120
|
+
/**
|
|
121
|
+
* Sponsored recommendations from the most recent payment.
|
|
122
|
+
* Populated when the facilitator returns sponsored-access extensions
|
|
123
|
+
* in the settlement response. Null if no recommendations were delivered.
|
|
124
|
+
*/
|
|
125
|
+
sponsoredRecommendations: SponsoredRecommendation[] | null;
|
|
117
126
|
}
|
|
118
127
|
/**
|
|
119
128
|
* React hook for managing x402 v2 payments across chains
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { a as X402Client } from '../
|
|
1
|
+
import { a as X402Client } from '../sponsored-access-H1EX6zpi.js';
|
|
2
|
+
export { f as fireImpressionBeacon, b as getSponsoredRecommendations } from '../sponsored-access-H1EX6zpi.js';
|
|
2
3
|
import { W as WalletSet, B as BalanceInfo } from '../types-ENcnkof8.js';
|
|
4
|
+
import { SponsoredRecommendation } from '@dexterai/x402-ads-types';
|
|
5
|
+
export { SponsoredRecommendation } from '@dexterai/x402-ads-types';
|
|
3
6
|
import { a as AccessPassTier } from '../types-BQvaF8lB.js';
|
|
4
7
|
export { A as AccessPassClientConfig, b as AccessPassInfo, X as X402Error } from '../types-BQvaF8lB.js';
|
|
5
8
|
|
|
@@ -114,6 +117,12 @@ interface UseX402PaymentReturn {
|
|
|
114
117
|
/** Seconds remaining on the pass */
|
|
115
118
|
remainingSeconds: number | null;
|
|
116
119
|
} | null;
|
|
120
|
+
/**
|
|
121
|
+
* Sponsored recommendations from the most recent payment.
|
|
122
|
+
* Populated when the facilitator returns sponsored-access extensions
|
|
123
|
+
* in the settlement response. Null if no recommendations were delivered.
|
|
124
|
+
*/
|
|
125
|
+
sponsoredRecommendations: SponsoredRecommendation[] | null;
|
|
117
126
|
}
|
|
118
127
|
/**
|
|
119
128
|
* React hook for managing x402 v2 payments across chains
|
package/dist/react/index.js
CHANGED
|
@@ -449,6 +449,9 @@ function isKnownUSDC(asset) {
|
|
|
449
449
|
|
|
450
450
|
// src/client/x402-client.ts
|
|
451
451
|
var receiptStore = /* @__PURE__ */ new WeakMap();
|
|
452
|
+
function getPaymentReceipt(response) {
|
|
453
|
+
return receiptStore.get(response);
|
|
454
|
+
}
|
|
452
455
|
function createX402Client(config) {
|
|
453
456
|
const {
|
|
454
457
|
adapters = [createSolanaAdapter({ verbose: config.verbose }), createEvmAdapter({ verbose: config.verbose })],
|
|
@@ -878,6 +881,28 @@ function getExplorerUrl(txSignature, network) {
|
|
|
878
881
|
return `https://solscan.io/tx/${txSignature}`;
|
|
879
882
|
}
|
|
880
883
|
|
|
884
|
+
// src/client/sponsored-access.ts
|
|
885
|
+
function getSponsoredAccessInfo(response) {
|
|
886
|
+
const receipt = getPaymentReceipt(response);
|
|
887
|
+
if (!receipt?.extensions?.["sponsored-access"]) return void 0;
|
|
888
|
+
return receipt.extensions["sponsored-access"];
|
|
889
|
+
}
|
|
890
|
+
function getSponsoredRecommendations(response) {
|
|
891
|
+
const info = getSponsoredAccessInfo(response);
|
|
892
|
+
if (!info?.recommendations?.length) return void 0;
|
|
893
|
+
return info.recommendations;
|
|
894
|
+
}
|
|
895
|
+
async function fireImpressionBeacon(response) {
|
|
896
|
+
const info = getSponsoredAccessInfo(response);
|
|
897
|
+
const beaconUrl = info?.tracking?.impressionBeacon;
|
|
898
|
+
if (!beaconUrl) return false;
|
|
899
|
+
try {
|
|
900
|
+
await fetch(beaconUrl, { method: "GET" });
|
|
901
|
+
} catch {
|
|
902
|
+
}
|
|
903
|
+
return true;
|
|
904
|
+
}
|
|
905
|
+
|
|
881
906
|
// src/react/useX402Payment.ts
|
|
882
907
|
function useX402Payment(config) {
|
|
883
908
|
const {
|
|
@@ -893,6 +918,7 @@ function useX402Payment(config) {
|
|
|
893
918
|
const [transactionId, setTransactionId] = useState(null);
|
|
894
919
|
const [transactionNetwork, setTransactionNetwork] = useState(null);
|
|
895
920
|
const [balances, setBalances] = useState([]);
|
|
921
|
+
const [sponsoredRecommendations, setSponsoredRecommendations] = useState(null);
|
|
896
922
|
const log = useCallback((...args) => {
|
|
897
923
|
if (verbose) console.log("[useX402Payment]", ...args);
|
|
898
924
|
}, [verbose]);
|
|
@@ -980,6 +1006,7 @@ function useX402Payment(config) {
|
|
|
980
1006
|
setError(null);
|
|
981
1007
|
setTransactionId(null);
|
|
982
1008
|
setTransactionNetwork(null);
|
|
1009
|
+
setSponsoredRecommendations(null);
|
|
983
1010
|
}, []);
|
|
984
1011
|
const client = useMemo(() => createX402Client({
|
|
985
1012
|
adapters,
|
|
@@ -1017,6 +1044,13 @@ function useX402Payment(config) {
|
|
|
1017
1044
|
log("Could not parse PAYMENT-RESPONSE header");
|
|
1018
1045
|
}
|
|
1019
1046
|
}
|
|
1047
|
+
const recs = getSponsoredRecommendations(response);
|
|
1048
|
+
setSponsoredRecommendations(recs ?? null);
|
|
1049
|
+
if (recs) {
|
|
1050
|
+
log("Sponsored recommendations received:", recs.length);
|
|
1051
|
+
fireImpressionBeacon(response).catch(() => {
|
|
1052
|
+
});
|
|
1053
|
+
}
|
|
1020
1054
|
setStatus("success");
|
|
1021
1055
|
return response;
|
|
1022
1056
|
} catch (err) {
|
|
@@ -1047,8 +1081,9 @@ function useX402Payment(config) {
|
|
|
1047
1081
|
isAnyWalletConnected,
|
|
1048
1082
|
reset,
|
|
1049
1083
|
refreshBalances,
|
|
1050
|
-
accessPass: null
|
|
1084
|
+
accessPass: null,
|
|
1051
1085
|
// Access pass state managed by useAccessPass hook for granular control
|
|
1086
|
+
sponsoredRecommendations
|
|
1052
1087
|
};
|
|
1053
1088
|
}
|
|
1054
1089
|
|
|
@@ -1246,6 +1281,8 @@ function useAccessPass(config) {
|
|
|
1246
1281
|
}
|
|
1247
1282
|
export {
|
|
1248
1283
|
X402Error,
|
|
1284
|
+
fireImpressionBeacon,
|
|
1285
|
+
getSponsoredRecommendations,
|
|
1249
1286
|
useAccessPass,
|
|
1250
1287
|
useX402Payment
|
|
1251
1288
|
};
|