mppx 0.9.3 → 0.10.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/CHANGELOG.md +14 -0
- package/dist/cli/cli.js +137 -137
- package/dist/cli/internal.d.ts +4 -1
- package/dist/cli/internal.js +38 -5
- package/dist/cli/plugins/index.js +13 -13
- package/dist/cli/validate/discovery.d.ts +3 -1
- package/dist/cli/validate/discovery.js +28 -1
- package/dist/cli/validate/helpers.d.ts +3 -2
- package/dist/cli/validate/helpers.js +3 -0
- package/dist/cli/validate/index.js +3 -1
- package/dist/cli/validate/payment.js +106 -53
- package/dist/client/Mppx.d.ts +32 -0
- package/dist/client/Mppx.js +180 -6
- package/dist/client/internal/Fetch.d.ts +6 -0
- package/dist/client/internal/Fetch.js +4 -2
- package/dist/internal/version.d.ts +2 -2
- package/dist/internal/version.js +1 -1
- package/dist/tempo/client/Charge.d.ts +8 -2
- package/dist/tempo/client/Charge.js +19 -11
- package/dist/tempo/server/internal/html.gen.d.ts +1 -1
- package/dist/tempo/server/internal/html.gen.js +1 -1
- package/dist/tempo/session/client/CredentialState.d.ts +2 -0
- package/dist/tempo/session/client/CredentialState.js +9 -3
- package/dist/tempo/session/client/Session.d.ts +6 -0
- package/dist/tempo/session/client/Session.js +4 -1
- package/dist/tempo/session/client/SessionManager.d.ts +6 -0
- package/dist/tempo/session/client/SessionManager.js +7 -0
- package/dist/validation/core.d.ts +1 -0
- package/dist/validation/core.js +7 -2
- package/dist/viem/Client.d.ts +4 -0
- package/dist/viem/Client.js +13 -0
- package/package.json +1 -1
package/dist/cli/internal.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as Challenge from '../Challenge.js';
|
|
2
2
|
import type * as Method from '../Method.js';
|
|
3
3
|
import type { Config } from './config.js';
|
|
4
4
|
import type * as Extension from './Extension.js';
|
|
5
5
|
import type { Plugin } from './plugins/plugin.js';
|
|
6
6
|
/** Runs configured payment extensions in order and threads credential context between them. */
|
|
7
7
|
export declare function preparePayment(challenge: Challenge.Challenge, extensions: readonly Extension.Extension[] | undefined, credentialContext?: unknown): Promise<unknown>;
|
|
8
|
+
/** Resolves explicit payment configuration before falling back to built-in plugins. */
|
|
8
9
|
export declare function resolvePlugin(challenge: Challenge.Challenge, config?: {
|
|
9
10
|
plugins?: Plugin[] | undefined;
|
|
10
11
|
methods?: any;
|
|
@@ -25,4 +26,6 @@ export declare function loadConfig(configFile?: string | undefined): Promise<{
|
|
|
25
26
|
config: Config;
|
|
26
27
|
path: string;
|
|
27
28
|
} | undefined>;
|
|
29
|
+
/** Rejects retry challenges that change the payment the caller approved. */
|
|
30
|
+
export declare function assertSamePaymentRequest(approved: Challenge.Challenge, retry: Challenge.Challenge): void;
|
|
28
31
|
//# sourceMappingURL=internal.d.ts.map
|
package/dist/cli/internal.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as fs from 'node:fs';
|
|
2
2
|
import * as path from 'node:path';
|
|
3
|
+
import * as Challenge from '../Challenge.js';
|
|
3
4
|
import * as AcceptPayment from '../internal/AcceptPayment.js';
|
|
4
5
|
import { evm as evmPlugin, stripe as stripePlugin, tempo as tempoPlugin, x402 as x402Plugin, } from './plugins/index.js';
|
|
5
6
|
const builtinPlugins = [tempoPlugin(), stripePlugin(), evmPlugin(), x402Plugin()];
|
|
@@ -16,17 +17,21 @@ export async function preparePayment(challenge, extensions, credentialContext) {
|
|
|
16
17
|
}
|
|
17
18
|
return current;
|
|
18
19
|
}
|
|
20
|
+
/** Resolves explicit payment configuration before falling back to built-in plugins. */
|
|
19
21
|
export function resolvePlugin(challenge, config) {
|
|
20
22
|
const configPlugin = config?.plugins?.find((p) => supportsPlugin(p, challenge));
|
|
21
23
|
if (configPlugin)
|
|
22
24
|
return { plugin: configPlugin };
|
|
23
|
-
const builtin = builtinPlugins.find((p) => supportsPlugin(p, challenge));
|
|
24
|
-
if (builtin)
|
|
25
|
-
return { plugin: builtin };
|
|
26
25
|
const configMethods = flattenConfigMethods(config);
|
|
27
|
-
const
|
|
26
|
+
const matching = configMethods?.filter((m) => m.name === challenge.method && m.intent === challenge.intent);
|
|
27
|
+
const matched = matching?.find((m) => m.canHandleChallenge?.({ challenge }) ?? true);
|
|
28
28
|
if (matched)
|
|
29
29
|
return { method: matched };
|
|
30
|
+
if (matching?.length)
|
|
31
|
+
return {};
|
|
32
|
+
const builtin = builtinPlugins.find((p) => supportsPlugin(p, challenge));
|
|
33
|
+
if (builtin)
|
|
34
|
+
return { plugin: builtin };
|
|
30
35
|
return {};
|
|
31
36
|
}
|
|
32
37
|
export function selectChallenge(challenges, config) {
|
|
@@ -35,7 +40,11 @@ export function selectChallenge(challenges, config) {
|
|
|
35
40
|
const resolvedPreferences = AcceptPayment.resolve(configMethods, config?.paymentPreferences);
|
|
36
41
|
const selected = AcceptPayment.selectChallenge(challenges, configMethods, resolvedPreferences.entries);
|
|
37
42
|
if (selected) {
|
|
38
|
-
|
|
43
|
+
const plugin = config?.plugins?.find((plugin) => supportsPlugin(plugin, selected.challenge));
|
|
44
|
+
return {
|
|
45
|
+
challenge: selected.challenge,
|
|
46
|
+
...(plugin ? { plugin } : { method: selected.method }),
|
|
47
|
+
};
|
|
39
48
|
}
|
|
40
49
|
return undefined;
|
|
41
50
|
}
|
|
@@ -84,4 +93,28 @@ function resolveConfigPath(configFile) {
|
|
|
84
93
|
}
|
|
85
94
|
return undefined;
|
|
86
95
|
}
|
|
96
|
+
/** Rejects retry challenges that change the payment the caller approved. */
|
|
97
|
+
export function assertSamePaymentRequest(approved, retry) {
|
|
98
|
+
function paymentTerms(challenge) {
|
|
99
|
+
const request = { ...challenge.request };
|
|
100
|
+
if (challenge.method === 'tempo' && challenge.intent === 'session') {
|
|
101
|
+
const methodDetails = { ...request.methodDetails };
|
|
102
|
+
// Snapshots advance session state; the session method validates them against
|
|
103
|
+
// the unchanged payment terms before authorizing the next credential.
|
|
104
|
+
delete methodDetails.sessionSnapshot;
|
|
105
|
+
if (Object.keys(methodDetails).length)
|
|
106
|
+
request.methodDetails = methodDetails;
|
|
107
|
+
else
|
|
108
|
+
delete request.methodDetails;
|
|
109
|
+
}
|
|
110
|
+
return Challenge.serialize({
|
|
111
|
+
...challenge,
|
|
112
|
+
request,
|
|
113
|
+
id: approved.id,
|
|
114
|
+
expires: approved.expires,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
if (paymentTerms(retry) !== paymentTerms(approved))
|
|
118
|
+
throw new Error('Payment request changed on retry. Run the command again to approve the new payment.');
|
|
119
|
+
}
|
|
87
120
|
//# sourceMappingURL=internal.js.map
|