@alleyboss/micropay-solana-x402-paywall 2.1.2 → 2.2.0
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 +32 -17
- package/dist/index.cjs +30 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +29 -4
- package/dist/index.js.map +1 -1
- package/dist/middleware/index.cjs +15 -3
- package/dist/middleware/index.cjs.map +1 -1
- package/dist/middleware/index.d.cts +2 -1
- package/dist/middleware/index.d.ts +2 -1
- package/dist/middleware/index.js +15 -3
- package/dist/middleware/index.js.map +1 -1
- package/dist/{nextjs-Bm272Jkj.d.cts → nextjs-BDyOqGAq.d.cts} +4 -1
- package/dist/{nextjs-BK0pVb9Y.d.ts → nextjs-CbX8_9yK.d.ts} +4 -1
- package/dist/x402/index.cjs +21 -0
- package/dist/x402/index.cjs.map +1 -1
- package/dist/x402/index.d.cts +23 -3
- package/dist/x402/index.d.ts +23 -3
- package/dist/x402/index.js +20 -1
- package/dist/x402/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -3,9 +3,9 @@ export { a as SessionConfig, S as SessionData, c as SessionJWTPayload, b as Sess
|
|
|
3
3
|
export { R as RpcConnectionWithFallback, S as SolanaClientConfig, g as getConnection, a as getConnectionWithFallback, i as isMainnet, r as resetConnection, t as toX402Network, w as withFallback } from './client-D-dteoJw.cjs';
|
|
4
4
|
export { PriorityFeeConfig, SPLVerificationResult, TransactionVerificationResult, VerifyPaymentParams, VerifySPLPaymentParams, VersionedTransactionConfig, VersionedTransactionResult, buildVersionedTransaction, calculatePriorityFeeCost, createPriorityFeeInstructions, estimatePriorityFee, fetchLookupTables, getTokenDecimals, getWalletTransactions, isNativeAsset, isVersionedTransaction, lamportsToSol, resolveMintAddress, solToLamports, verifyPayment, verifySPLPayment, waitForConfirmation } from './solana/index.cjs';
|
|
5
5
|
export { addArticleToSession, createSession, isArticleUnlocked, validateSession } from './session/index.cjs';
|
|
6
|
-
export { BuildPaymentParams, X402_HEADERS, buildPaymentRequirement, create402Headers, create402ResponseBody, decodePaymentRequired, encodePaymentRequired, encodePaymentResponse, parsePaymentHeader, verifyX402Payment } from './x402/index.cjs';
|
|
6
|
+
export { BuildPaymentParams, X402_HEADERS, buildPaymentRequirement, create402Headers, create402Response, create402ResponseBody, decodePaymentRequired, encodePaymentRequired, encodePaymentRequirement, encodePaymentResponse, parsePaymentHeader, verifyX402Payment } from './x402/index.cjs';
|
|
7
7
|
export { StoreConfig, createRedisStore } from './store/index.cjs';
|
|
8
|
-
export { M as MiddlewareResult, P as PaywallMiddlewareConfig, a as checkPaywallAccess, c as createPaywallMiddleware, w as withPaywall } from './nextjs-
|
|
8
|
+
export { M as MiddlewareResult, P as PaywallMiddlewareConfig, a as checkPaywallAccess, c as createPaywallMiddleware, w as withPaywall } from './nextjs-BDyOqGAq.cjs';
|
|
9
9
|
export { RetryOptions, isRetryableRPCError, withRetry } from './utils/index.cjs';
|
|
10
10
|
export { PaymentFlowConfig, SolanaPayUrlParams, buildSolanaPayUrl, createPaymentFlow, createPaymentReference } from './client/index.cjs';
|
|
11
11
|
export { CustomPriceProvider, PriceConfig, PriceData, clearPriceCache, configurePricing, formatPriceDisplay, formatPriceSync, getProviders, getSolPrice, lamportsToUsd, usdToLamports } from './pricing/index.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -3,9 +3,9 @@ export { a as SessionConfig, S as SessionData, c as SessionJWTPayload, b as Sess
|
|
|
3
3
|
export { R as RpcConnectionWithFallback, S as SolanaClientConfig, g as getConnection, a as getConnectionWithFallback, i as isMainnet, r as resetConnection, t as toX402Network, w as withFallback } from './client-DfCIRrNG.js';
|
|
4
4
|
export { PriorityFeeConfig, SPLVerificationResult, TransactionVerificationResult, VerifyPaymentParams, VerifySPLPaymentParams, VersionedTransactionConfig, VersionedTransactionResult, buildVersionedTransaction, calculatePriorityFeeCost, createPriorityFeeInstructions, estimatePriorityFee, fetchLookupTables, getTokenDecimals, getWalletTransactions, isNativeAsset, isVersionedTransaction, lamportsToSol, resolveMintAddress, solToLamports, verifyPayment, verifySPLPayment, waitForConfirmation } from './solana/index.js';
|
|
5
5
|
export { addArticleToSession, createSession, isArticleUnlocked, validateSession } from './session/index.js';
|
|
6
|
-
export { BuildPaymentParams, X402_HEADERS, buildPaymentRequirement, create402Headers, create402ResponseBody, decodePaymentRequired, encodePaymentRequired, encodePaymentResponse, parsePaymentHeader, verifyX402Payment } from './x402/index.js';
|
|
6
|
+
export { BuildPaymentParams, X402_HEADERS, buildPaymentRequirement, create402Headers, create402Response, create402ResponseBody, decodePaymentRequired, encodePaymentRequired, encodePaymentRequirement, encodePaymentResponse, parsePaymentHeader, verifyX402Payment } from './x402/index.js';
|
|
7
7
|
export { StoreConfig, createRedisStore } from './store/index.js';
|
|
8
|
-
export { M as MiddlewareResult, P as PaywallMiddlewareConfig, a as checkPaywallAccess, c as createPaywallMiddleware, w as withPaywall } from './nextjs-
|
|
8
|
+
export { M as MiddlewareResult, P as PaywallMiddlewareConfig, a as checkPaywallAccess, c as createPaywallMiddleware, w as withPaywall } from './nextjs-CbX8_9yK.js';
|
|
9
9
|
export { RetryOptions, isRetryableRPCError, withRetry } from './utils/index.js';
|
|
10
10
|
export { PaymentFlowConfig, SolanaPayUrlParams, buildSolanaPayUrl, createPaymentFlow, createPaymentReference } from './client/index.js';
|
|
11
11
|
export { CustomPriceProvider, PriceConfig, PriceData, clearPriceCache, configurePricing, formatPriceDisplay, formatPriceSync, getProviders, getSolPrice, lamportsToUsd, usdToLamports } from './pricing/index.js';
|
package/dist/index.js
CHANGED
|
@@ -827,9 +827,28 @@ function parsePaymentHeader(header) {
|
|
|
827
827
|
return null;
|
|
828
828
|
}
|
|
829
829
|
}
|
|
830
|
+
function encodePaymentRequirement(requirement) {
|
|
831
|
+
return Buffer.from(JSON.stringify(requirement)).toString("base64");
|
|
832
|
+
}
|
|
830
833
|
function encodePaymentResponse(response) {
|
|
831
834
|
return Buffer.from(JSON.stringify(response)).toString("base64");
|
|
832
835
|
}
|
|
836
|
+
function create402Response(requirement, body) {
|
|
837
|
+
const headers = new Headers({
|
|
838
|
+
"Content-Type": "application/json",
|
|
839
|
+
"X-Payment-Required": encodePaymentRequirement(requirement)
|
|
840
|
+
});
|
|
841
|
+
const responseBody = body || {
|
|
842
|
+
error: "Payment Required",
|
|
843
|
+
message: "This resource requires payment to access",
|
|
844
|
+
x402Version: 1,
|
|
845
|
+
accepts: [requirement]
|
|
846
|
+
};
|
|
847
|
+
return new Response(JSON.stringify(responseBody), {
|
|
848
|
+
status: 402,
|
|
849
|
+
headers
|
|
850
|
+
});
|
|
851
|
+
}
|
|
833
852
|
|
|
834
853
|
// src/store/memory.ts
|
|
835
854
|
function createMemoryStore(options = {}) {
|
|
@@ -974,16 +993,22 @@ function createPaywallMiddleware(config2) {
|
|
|
974
993
|
const sessionToken = cookies[cookieName];
|
|
975
994
|
const result = await checkPaywallAccess(path, sessionToken, config2);
|
|
976
995
|
if (!result.allowed && result.requiresPayment) {
|
|
996
|
+
const headers = {
|
|
997
|
+
"Content-Type": "application/json"
|
|
998
|
+
};
|
|
999
|
+
if (config2.paymentRequirement) {
|
|
1000
|
+
const requirement = typeof config2.paymentRequirement === "function" ? config2.paymentRequirement(path) : config2.paymentRequirement;
|
|
1001
|
+
headers["X-Payment-Required"] = encodePaymentRequirement(requirement);
|
|
1002
|
+
}
|
|
977
1003
|
const body = config2.custom402Response ? config2.custom402Response(path) : {
|
|
978
1004
|
error: "Payment Required",
|
|
979
1005
|
message: "This resource requires payment to access",
|
|
1006
|
+
x402Version: 1,
|
|
980
1007
|
path
|
|
981
1008
|
};
|
|
982
1009
|
return new Response(JSON.stringify(body), {
|
|
983
1010
|
status: 402,
|
|
984
|
-
headers
|
|
985
|
-
"Content-Type": "application/json"
|
|
986
|
-
}
|
|
1011
|
+
headers
|
|
987
1012
|
});
|
|
988
1013
|
}
|
|
989
1014
|
return null;
|
|
@@ -1301,6 +1326,6 @@ function getProviders() {
|
|
|
1301
1326
|
return PROVIDERS.map((p) => ({ name: p.name, url: p.url }));
|
|
1302
1327
|
}
|
|
1303
1328
|
|
|
1304
|
-
export { TOKEN_MINTS, X402_HEADERS, addArticleToSession, buildPaymentRequirement, buildSolanaPayUrl, buildVersionedTransaction, calculatePriorityFeeCost, checkPaywallAccess, clearPriceCache, configurePricing, create402Headers, create402ResponseBody, createMemoryStore, createPaymentFlow, createPaymentReference, createPaywallMiddleware, createPriorityFeeInstructions, createRedisStore, createSession, decodePaymentRequired, encodePaymentRequired, encodePaymentResponse, estimatePriorityFee, fetchLookupTables, formatPriceDisplay, formatPriceSync, getConnection, getConnectionWithFallback, getProviders, getSolPrice, getTokenDecimals, getWalletTransactions, isArticleUnlocked, isMainnet, isNativeAsset, isRetryableRPCError, isVersionedTransaction, lamportsToSol, lamportsToUsd, parsePaymentHeader, resetConnection, resolveMintAddress, solToLamports, toX402Network, usdToLamports, validateSession, verifyPayment, verifySPLPayment, verifyX402Payment, waitForConfirmation, withFallback, withPaywall, withRetry };
|
|
1329
|
+
export { TOKEN_MINTS, X402_HEADERS, addArticleToSession, buildPaymentRequirement, buildSolanaPayUrl, buildVersionedTransaction, calculatePriorityFeeCost, checkPaywallAccess, clearPriceCache, configurePricing, create402Headers, create402Response, create402ResponseBody, createMemoryStore, createPaymentFlow, createPaymentReference, createPaywallMiddleware, createPriorityFeeInstructions, createRedisStore, createSession, decodePaymentRequired, encodePaymentRequired, encodePaymentRequirement, encodePaymentResponse, estimatePriorityFee, fetchLookupTables, formatPriceDisplay, formatPriceSync, getConnection, getConnectionWithFallback, getProviders, getSolPrice, getTokenDecimals, getWalletTransactions, isArticleUnlocked, isMainnet, isNativeAsset, isRetryableRPCError, isVersionedTransaction, lamportsToSol, lamportsToUsd, parsePaymentHeader, resetConnection, resolveMintAddress, solToLamports, toX402Network, usdToLamports, validateSession, verifyPayment, verifySPLPayment, verifyX402Payment, waitForConfirmation, withFallback, withPaywall, withRetry };
|
|
1305
1330
|
//# sourceMappingURL=index.js.map
|
|
1306
1331
|
//# sourceMappingURL=index.js.map
|