@t402/core 2.0.0 → 2.3.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 +1 -1
- package/dist/cjs/client/index.d.ts +22 -2
- package/dist/cjs/client/index.js +9 -6
- package/dist/cjs/client/index.js.map +1 -1
- package/dist/cjs/facilitator/index.d.ts +1 -1
- package/dist/cjs/facilitator/index.js +10 -8
- package/dist/cjs/facilitator/index.js.map +1 -1
- package/dist/cjs/http/index.d.ts +3 -3
- package/dist/cjs/http/index.js +11 -2
- package/dist/cjs/http/index.js.map +1 -1
- package/dist/cjs/{mechanisms-CmrqNl1M.d.ts → mechanisms-B-vz5yOj.d.ts} +209 -4
- package/dist/cjs/server/index.d.ts +2 -2
- package/dist/cjs/server/index.js +22 -12
- package/dist/cjs/server/index.js.map +1 -1
- package/dist/cjs/{t402HTTPClient-m6cjzTek.d.ts → t402HTTPClient-GIweW6nh.d.ts} +1 -1
- package/dist/cjs/{t402HTTPResourceServer-B-xmYMwj.d.ts → t402HTTPResourceServer-CcpZF3af.d.ts} +2 -2
- package/dist/cjs/types/index.d.ts +1 -1
- package/dist/cjs/types/index.js +38 -0
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/cjs/types/v1/index.d.ts +1 -1
- package/dist/cjs/utils/index.d.ts +1 -1
- package/dist/esm/chunk-4W2Y3RJM.mjs +15 -0
- package/dist/esm/{chunk-D5DYKKCZ.mjs → chunk-773TNE2Y.mjs} +12 -4
- package/dist/esm/{chunk-D5DYKKCZ.mjs.map → chunk-773TNE2Y.mjs.map} +1 -1
- package/dist/esm/client/index.d.mts +22 -2
- package/dist/esm/client/index.mjs +11 -8
- package/dist/esm/client/index.mjs.map +1 -1
- package/dist/esm/facilitator/index.d.mts +1 -1
- package/dist/esm/facilitator/index.mjs +11 -9
- package/dist/esm/facilitator/index.mjs.map +1 -1
- package/dist/esm/http/index.d.mts +3 -3
- package/dist/esm/http/index.mjs +2 -2
- package/dist/esm/index.mjs +1 -1
- package/dist/{cjs/mechanisms-DsJn3ZiM.d.ts → esm/mechanisms-B-vz5yOj.d.mts} +209 -4
- package/dist/esm/server/index.d.mts +2 -2
- package/dist/esm/server/index.mjs +15 -12
- package/dist/esm/server/index.mjs.map +1 -1
- package/dist/esm/{t402HTTPClient-C285YGCp.d.mts → t402HTTPClient-DbZqiMSO.d.mts} +1 -1
- package/dist/esm/{t402HTTPResourceServer-k_l3d8ua.d.mts → t402HTTPResourceServer-BbQ6HVBC.d.mts} +2 -2
- package/dist/esm/types/index.d.mts +1 -1
- package/dist/esm/types/index.mjs +28 -0
- package/dist/esm/types/index.mjs.map +1 -1
- package/dist/esm/types/v1/index.d.mts +1 -1
- package/dist/esm/utils/index.d.mts +1 -1
- package/dist/esm/utils/index.mjs +1 -1
- package/package.json +19 -18
- package/dist/cjs/t402HTTPResourceServer-Bcfxp2UO.d.ts +0 -719
- package/dist/esm/chunk-BJTO5JO5.mjs +0 -11
- package/dist/esm/mechanisms-CmrqNl1M.d.mts +0 -238
- /package/dist/esm/{chunk-BJTO5JO5.mjs.map → chunk-4W2Y3RJM.mjs.map} +0 -0
package/dist/esm/{t402HTTPResourceServer-k_l3d8ua.d.mts → t402HTTPResourceServer-BbQ6HVBC.d.mts}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as PaymentPayload, P as PaymentRequirements, V as VerifyResponse, S as SettleResponse, e as SupportedResponse, N as Network, f as SchemeNetworkServer, R as ResourceServerExtension, g as SupportedKind, h as Price, c as PaymentRequired } from './mechanisms-
|
|
1
|
+
import { a as PaymentPayload, P as PaymentRequirements, V as VerifyResponse, S as SettleResponse, e as SupportedResponse, N as Network, f as SchemeNetworkServer, R as ResourceServerExtension, g as SupportedKind, h as Price, c as PaymentRequired } from './mechanisms-B-vz5yOj.mjs';
|
|
2
2
|
|
|
3
3
|
interface FacilitatorConfig {
|
|
4
4
|
url?: string;
|
|
@@ -716,4 +716,4 @@ declare class t402HTTPResourceServer {
|
|
|
716
716
|
private getDisplayAmount;
|
|
717
717
|
}
|
|
718
718
|
|
|
719
|
-
export { type CompiledRoute as C, type DynamicPayTo as D, type FacilitatorClient as F,
|
|
719
|
+
export { type CompiledRoute as C, type DynamicPayTo as D, type FacilitatorClient as F, HTTPFacilitatorClient as H, type PaywallConfig as P, RouteConfigurationError as R, type UnpaidResponseBody as U, type HTTPAdapter as a, type HTTPRequestContext as b, type HTTPResponseInstructions as c, type HTTPProcessResult as d, type PaywallProvider as e, type PaymentOption as f, type RouteConfig as g, type RoutesConfig as h, type DynamicPrice as i, type UnpaidResponseResult as j, type ProcessSettleResultResponse as k, type ProcessSettleSuccessResponse as l, type ProcessSettleFailureResponse as m, type RouteValidationError as n, type FacilitatorConfig as o, t402ResourceServer as p, type ResourceConfig as q, type ResourceInfo as r, t402HTTPResourceServer as t };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { A as AssetAmount, M as Money, r as MoneyParser, N as Network, a as PaymentPayload, k as PaymentPayloadV1, c as PaymentRequired, j as PaymentRequiredV1, P as PaymentRequirements, i as PaymentRequirementsV1, h as Price, R as ResourceServerExtension, d as SchemeNetworkClient, b as SchemeNetworkFacilitator, f as SchemeNetworkServer, q as SettleRequest, S as SettleResponse, e as SupportedResponse, p as VerifyRequest, V as VerifyResponse } from '../mechanisms-
|
|
1
|
+
export { A as AssetAmount, M as Money, r as MoneyParser, N as Network, a as PaymentPayload, k as PaymentPayloadV1, c as PaymentRequired, j as PaymentRequiredV1, P as PaymentRequirements, i as PaymentRequirementsV1, h as Price, R as ResourceServerExtension, d as SchemeNetworkClient, b as SchemeNetworkFacilitator, f as SchemeNetworkServer, q as SettleRequest, S as SettleResponse, e as SupportedResponse, F as UPTO_DEFAULTS, E as UPTO_SCHEME, u as UptoEvmPayload, v as UptoEvmPayloadCompact, s as UptoExtra, t as UptoPayloadBase, U as UptoPaymentRequirements, w as UptoSettlement, y as UptoSettlementResponse, B as UptoUnit, x as UptoUsageDetails, z as UptoValidationResult, p as VerifyRequest, V as VerifyResponse, D as isUptoEvmPayload, C as isUptoPaymentRequirements } from '../mechanisms-B-vz5yOj.mjs';
|
package/dist/esm/types/index.mjs
CHANGED
|
@@ -1 +1,29 @@
|
|
|
1
|
+
import "../chunk-4W2Y3RJM.mjs";
|
|
2
|
+
|
|
3
|
+
// src/types/schemes/upto.ts
|
|
4
|
+
function isUptoPaymentRequirements(requirements) {
|
|
5
|
+
if (typeof requirements !== "object" || requirements === null) return false;
|
|
6
|
+
const req = requirements;
|
|
7
|
+
return req.scheme === "upto" && "maxAmount" in req;
|
|
8
|
+
}
|
|
9
|
+
function isUptoEvmPayload(payload) {
|
|
10
|
+
if (typeof payload !== "object" || payload === null) return false;
|
|
11
|
+
const p = payload;
|
|
12
|
+
return "signature" in p && "authorization" in p && typeof p.authorization === "object" && p.authorization !== null && "owner" in p.authorization && "spender" in p.authorization && "value" in p.authorization && "deadline" in p.authorization;
|
|
13
|
+
}
|
|
14
|
+
var UPTO_SCHEME = "upto";
|
|
15
|
+
var UPTO_DEFAULTS = {
|
|
16
|
+
/** Default minimum settlement amount (prevents dust) */
|
|
17
|
+
MIN_AMOUNT: "1000",
|
|
18
|
+
/** Default maximum timeout in seconds (5 minutes) */
|
|
19
|
+
MAX_TIMEOUT_SECONDS: 300,
|
|
20
|
+
/** Supported billing units */
|
|
21
|
+
UNITS: ["token", "request", "second", "minute", "byte", "kb", "mb"]
|
|
22
|
+
};
|
|
23
|
+
export {
|
|
24
|
+
UPTO_DEFAULTS,
|
|
25
|
+
UPTO_SCHEME,
|
|
26
|
+
isUptoEvmPayload,
|
|
27
|
+
isUptoPaymentRequirements
|
|
28
|
+
};
|
|
1
29
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/types/schemes/upto.ts"],"sourcesContent":["/**\n * Up-To Scheme Types\n *\n * The `upto` scheme authorizes transfer of up to a maximum amount,\n * enabling usage-based billing where the final settlement amount\n * is determined by actual usage.\n *\n * @example\n * ```typescript\n * // Client authorizes up to $1.00\n * const requirements: UptoPaymentRequirements = {\n * scheme: 'upto',\n * network: 'eip155:8453',\n * maxAmount: '1000000', // $1.00 in USDC\n * minAmount: '10000', // $0.01 minimum\n * asset: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',\n * payTo: '0x...',\n * maxTimeoutSeconds: 300,\n * extra: {\n * unit: 'token',\n * unitPrice: '100',\n * },\n * };\n *\n * // Server settles for actual usage ($0.15)\n * const settlement: UptoSettlement = {\n * settleAmount: '150000',\n * usageDetails: {\n * tokensGenerated: 1500,\n * unitPrice: '100',\n * },\n * };\n * ```\n */\n\nimport type { Network, PaymentRequirements } from \"../\";\n\n/**\n * Extended payment requirements for the upto scheme.\n */\nexport interface UptoPaymentRequirements extends Omit<PaymentRequirements, \"scheme\" | \"amount\"> {\n /** Scheme identifier - always 'upto' */\n scheme: \"upto\";\n\n /** Network identifier (CAIP-2 format) */\n network: Network;\n\n /** Maximum amount the client authorizes (in smallest denomination) */\n maxAmount: string;\n\n /** Minimum settlement amount (prevents dust payments) */\n minAmount?: string;\n\n /** Asset contract address or identifier */\n asset: string;\n\n /** Recipient address */\n payTo: string;\n\n /** Maximum time in seconds before payment expires */\n maxTimeoutSeconds: number;\n\n /** Additional scheme-specific data */\n extra: UptoExtra;\n}\n\n/**\n * Extra fields specific to the upto scheme.\n */\nexport interface UptoExtra extends Record<string, unknown> {\n /** Billing unit (e.g., 'token', 'request', 'second', 'byte') */\n unit?: string;\n\n /** Price per unit in smallest denomination */\n unitPrice?: string;\n\n /** EIP-712 domain name (for EVM) */\n name?: string;\n\n /** EIP-712 domain version (for EVM) */\n version?: string;\n\n /** Router contract address (for EVM) */\n routerAddress?: string;\n}\n\n/**\n * Base payload structure for upto scheme.\n */\nexport interface UptoPayloadBase {\n /** Unique nonce to prevent replay attacks */\n nonce: string;\n}\n\n/**\n * EVM-specific upto payload using EIP-2612 Permit.\n */\nexport interface UptoEvmPayload extends UptoPayloadBase {\n /** EIP-2612 permit signature components */\n signature: {\n v: number;\n r: `0x${string}`;\n s: `0x${string}`;\n };\n\n /** Permit authorization parameters */\n authorization: {\n /** Token owner address */\n owner: `0x${string}`;\n\n /** Spender address (router contract) */\n spender: `0x${string}`;\n\n /** Maximum authorized value */\n value: string;\n\n /** Permit deadline (unix timestamp) */\n deadline: string;\n\n /** Permit nonce (from token contract) */\n nonce: number;\n };\n}\n\n/**\n * Alternative EVM payload with combined signature.\n */\nexport interface UptoEvmPayloadCompact extends UptoPayloadBase {\n /** Combined EIP-2612 permit signature */\n signature: `0x${string}`;\n\n /** Permit authorization parameters */\n authorization: {\n owner: `0x${string}`;\n spender: `0x${string}`;\n value: string;\n deadline: string;\n nonce: number;\n };\n}\n\n/**\n * Settlement request for upto scheme.\n */\nexport interface UptoSettlement {\n /** Actual amount to settle (must be <= maxAmount) */\n settleAmount: string;\n\n /** Optional usage details for auditing */\n usageDetails?: UptoUsageDetails;\n}\n\n/**\n * Usage details for settlement auditing.\n */\nexport interface UptoUsageDetails {\n /** Number of units consumed */\n unitsConsumed?: number;\n\n /** Price per unit used */\n unitPrice?: string;\n\n /** Type of unit */\n unitType?: string;\n\n /** Start timestamp of usage period */\n startTime?: number;\n\n /** End timestamp of usage period */\n endTime?: number;\n\n /** Additional metadata */\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Settlement response for upto scheme.\n */\nexport interface UptoSettlementResponse {\n /** Whether settlement was successful */\n success: boolean;\n\n /** Transaction hash (if on-chain) */\n transactionHash?: string;\n\n /** Actual amount settled */\n settledAmount: string;\n\n /** Maximum amount that was authorized */\n maxAmount: string;\n\n /** Block number (if on-chain) */\n blockNumber?: number;\n\n /** Gas used (if on-chain) */\n gasUsed?: string;\n\n /** Error message if failed */\n error?: string;\n}\n\n/**\n * Validation result for upto payment.\n */\nexport interface UptoValidationResult {\n /** Whether the payment is valid */\n isValid: boolean;\n\n /** Reason if invalid */\n invalidReason?: string;\n\n /** Validated maximum amount */\n validatedMaxAmount?: string;\n\n /** Payer address */\n payer?: string;\n\n /** Expiration timestamp */\n expiresAt?: number;\n}\n\n/**\n * Type guard for UptoPaymentRequirements.\n *\n * @param requirements - The value to check\n * @returns True if the value is UptoPaymentRequirements\n */\nexport function isUptoPaymentRequirements(\n requirements: unknown,\n): requirements is UptoPaymentRequirements {\n if (typeof requirements !== \"object\" || requirements === null) return false;\n const req = requirements as Record<string, unknown>;\n return req.scheme === \"upto\" && \"maxAmount\" in req;\n}\n\n/**\n * Type guard for UptoEvmPayload.\n *\n * @param payload - The value to check\n * @returns True if the value is UptoEvmPayload\n */\nexport function isUptoEvmPayload(payload: unknown): payload is UptoEvmPayload {\n if (typeof payload !== \"object\" || payload === null) return false;\n const p = payload as Record<string, unknown>;\n return (\n \"signature\" in p &&\n \"authorization\" in p &&\n typeof p.authorization === \"object\" &&\n p.authorization !== null &&\n \"owner\" in (p.authorization as Record<string, unknown>) &&\n \"spender\" in (p.authorization as Record<string, unknown>) &&\n \"value\" in (p.authorization as Record<string, unknown>) &&\n \"deadline\" in (p.authorization as Record<string, unknown>)\n );\n}\n\n/**\n * Constants for upto scheme.\n */\nexport const UPTO_SCHEME = \"upto\" as const;\n\nexport const UPTO_DEFAULTS = {\n /** Default minimum settlement amount (prevents dust) */\n MIN_AMOUNT: \"1000\",\n\n /** Default maximum timeout in seconds (5 minutes) */\n MAX_TIMEOUT_SECONDS: 300,\n\n /** Supported billing units */\n UNITS: [\"token\", \"request\", \"second\", \"minute\", \"byte\", \"kb\", \"mb\"] as const,\n} as const;\n\nexport type UptoUnit = (typeof UPTO_DEFAULTS.UNITS)[number];\n"],"mappings":";;;AAmOO,SAAS,0BACd,cACyC;AACzC,MAAI,OAAO,iBAAiB,YAAY,iBAAiB,KAAM,QAAO;AACtE,QAAM,MAAM;AACZ,SAAO,IAAI,WAAW,UAAU,eAAe;AACjD;AAQO,SAAS,iBAAiB,SAA6C;AAC5E,MAAI,OAAO,YAAY,YAAY,YAAY,KAAM,QAAO;AAC5D,QAAM,IAAI;AACV,SACE,eAAe,KACf,mBAAmB,KACnB,OAAO,EAAE,kBAAkB,YAC3B,EAAE,kBAAkB,QACpB,WAAY,EAAE,iBACd,aAAc,EAAE,iBAChB,WAAY,EAAE,iBACd,cAAe,EAAE;AAErB;AAKO,IAAM,cAAc;AAEpB,IAAM,gBAAgB;AAAA;AAAA,EAE3B,YAAY;AAAA;AAAA,EAGZ,qBAAqB;AAAA;AAAA,EAGrB,OAAO,CAAC,SAAS,WAAW,UAAU,UAAU,QAAQ,MAAM,IAAI;AACpE;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { k as PaymentPayloadV1, j as PaymentRequiredV1, i as PaymentRequirementsV1, m as SettleRequestV1, n as SettleResponseV1, o as SupportedResponseV1, l as VerifyRequestV1 } from '../../mechanisms-
|
|
1
|
+
export { k as PaymentPayloadV1, j as PaymentRequiredV1, i as PaymentRequirementsV1, m as SettleRequestV1, n as SettleResponseV1, o as SupportedResponseV1, l as VerifyRequestV1 } from '../../mechanisms-B-vz5yOj.mjs';
|
package/dist/esm/utils/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,21 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@t402/core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"main": "./dist/cjs/index.js",
|
|
5
5
|
"module": "./dist/esm/index.js",
|
|
6
6
|
"types": "./dist/cjs/index.d.ts",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"start": "tsx --env-file=.env index.ts",
|
|
9
|
-
"build": "tsup",
|
|
10
|
-
"test": "vitest run",
|
|
11
|
-
"test:watch": "vitest",
|
|
12
|
-
"test:integration": "vitest run test/integrations",
|
|
13
|
-
"watch": "tsc --watch",
|
|
14
|
-
"format": "prettier -c .prettierrc --write \"**/*.{ts,js,cjs,json,md}\"",
|
|
15
|
-
"format:check": "prettier -c .prettierrc --check \"**/*.{ts,js,cjs,json,md}\"",
|
|
16
|
-
"lint": "eslint . --ext .ts --fix",
|
|
17
|
-
"lint:check": "eslint . --ext .ts"
|
|
18
|
-
},
|
|
19
7
|
"keywords": [],
|
|
20
8
|
"license": "Apache-2.0",
|
|
21
9
|
"author": "T402 Team",
|
|
@@ -30,13 +18,14 @@
|
|
|
30
18
|
"eslint-plugin-import": "^2.31.0",
|
|
31
19
|
"eslint-plugin-jsdoc": "^50.6.9",
|
|
32
20
|
"eslint-plugin-prettier": "^5.2.6",
|
|
21
|
+
"glob": "^13.0.0",
|
|
33
22
|
"prettier": "3.5.2",
|
|
34
23
|
"tsup": "^8.4.0",
|
|
35
|
-
"tsx": "^4.
|
|
24
|
+
"tsx": "^4.21.0",
|
|
36
25
|
"typescript": "^5.7.3",
|
|
37
|
-
"vite": "^
|
|
26
|
+
"vite": "^7.3.1",
|
|
38
27
|
"vite-tsconfig-paths": "^5.1.4",
|
|
39
|
-
"vitest": "^3.
|
|
28
|
+
"vitest": "^3.2.4"
|
|
40
29
|
},
|
|
41
30
|
"dependencies": {
|
|
42
31
|
"zod": "^3.24.2"
|
|
@@ -125,5 +114,17 @@
|
|
|
125
114
|
},
|
|
126
115
|
"files": [
|
|
127
116
|
"dist"
|
|
128
|
-
]
|
|
129
|
-
|
|
117
|
+
],
|
|
118
|
+
"scripts": {
|
|
119
|
+
"start": "tsx --env-file=.env index.ts",
|
|
120
|
+
"build": "tsup",
|
|
121
|
+
"test": "vitest run",
|
|
122
|
+
"test:watch": "vitest",
|
|
123
|
+
"test:integration": "vitest run test/integrations",
|
|
124
|
+
"watch": "tsc --watch",
|
|
125
|
+
"format": "prettier -c .prettierrc --write \"**/*.{ts,js,cjs,json,md}\"",
|
|
126
|
+
"format:check": "prettier -c .prettierrc --check \"**/*.{ts,js,cjs,json,md}\"",
|
|
127
|
+
"lint": "eslint . --ext .ts --fix",
|
|
128
|
+
"lint:check": "eslint . --ext .ts"
|
|
129
|
+
}
|
|
130
|
+
}
|