mppx 0.9.2 → 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 +32 -0
- package/README.md +19 -0
- package/dist/Method.d.ts +2 -0
- package/dist/cli/Extension.d.ts +20 -0
- package/dist/cli/Extension.js +5 -0
- package/dist/cli/cli.js +137 -137
- package/dist/cli/config.d.ts +4 -0
- package/dist/cli/config.js +1 -0
- package/dist/cli/internal.d.ts +7 -1
- package/dist/cli/internal.js +51 -5
- package/dist/cli/plugins/index.js +12 -12
- package/dist/cli/plugins/plugin.d.ts +2 -2
- package/dist/cli/sessions/request.d.ts +1 -0
- package/dist/cli/sessions/request.js +1 -0
- 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 +118 -59
- 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/evm/client/Charge.d.ts +2 -2
- package/dist/evm/client/Charge.js +1 -1
- package/dist/evm/server/Charge.d.ts +7 -2
- package/dist/evm/server/Charge.js +28 -2
- package/dist/evm/server/Methods.d.ts +1 -1
- package/dist/internal/version.d.ts +5 -0
- package/dist/internal/version.js +6 -0
- package/dist/server/Mppx.d.ts +7 -6
- package/dist/server/Mppx.js +84 -2
- package/dist/server/internal/html/config.js +1 -3
- package/dist/stripe/Methods.d.ts +4 -3
- package/dist/stripe/Methods.js +14 -11
- package/dist/stripe/client/Charge.d.ts +3 -3
- package/dist/stripe/client/Methods.d.ts +3 -3
- package/dist/stripe/internal/parse-units.d.ts +8 -0
- package/dist/stripe/internal/parse-units.js +20 -0
- package/dist/stripe/internal/payment-intent.d.ts +29 -0
- package/dist/stripe/internal/payment-intent.js +8 -0
- package/dist/stripe/server/Charge.d.ts +5 -3
- package/dist/stripe/server/Charge.js +17 -21
- package/dist/stripe/server/Methods.d.ts +6 -4
- package/dist/stripe/server/Methods.js +42 -14
- package/dist/stripe/server/internal/analytics.d.ts +6 -0
- package/dist/stripe/server/internal/analytics.js +16 -0
- package/dist/stripe/server/internal/html.gen.d.ts +1 -1
- package/dist/stripe/server/internal/html.gen.js +1 -1
- package/dist/stripe/server/internal/record-payment.d.ts +1 -0
- package/dist/stripe/server/internal/record-payment.js +7 -5
- package/dist/tempo/client/Charge.d.ts +8 -2
- package/dist/tempo/client/Charge.js +19 -11
- package/dist/tempo/client/Subscription.js +6 -2
- package/dist/tempo/internal/fee-payer.d.ts +2 -0
- package/dist/tempo/internal/fee-payer.js +4 -0
- package/dist/tempo/server/Subscription.js +1 -0
- 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 +11 -0
- package/dist/tempo/session/client/SessionManager.js +23 -2
- package/dist/tempo/session/precompile/Chain.js +3 -0
- package/dist/tempo/subscription/KeyAuthorization.d.ts +7 -1
- package/dist/tempo/subscription/KeyAuthorization.js +21 -3
- 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/dist/x402/client/Exact.d.ts +2 -2
- package/dist/x402/client/Exact.js +1 -1
- package/dist/x402/server/EvmCharge.d.ts +2 -0
- package/dist/x402/server/EvmCharge.js +34 -26
- package/package.json +1 -1
package/dist/cli/config.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export { resolveAccount } from './account.js';
|
|
2
|
+
export * as Extension from './Extension.js';
|
|
2
3
|
import type * as Mppx from '../client/Mppx.js';
|
|
4
|
+
import type * as Extension from './Extension.js';
|
|
3
5
|
import type { Plugin } from './plugins/plugin.js';
|
|
4
6
|
/**
|
|
5
7
|
* Define mppx configuration file
|
|
@@ -35,6 +37,8 @@ export declare namespace defineConfig {
|
|
|
35
37
|
paymentPreferences?: methods extends Mppx.Methods ? Mppx.create.Config<methods>['paymentPreferences'] : undefined;
|
|
36
38
|
/** Array of plugins to use. */
|
|
37
39
|
plugins?: Plugin[] | undefined;
|
|
40
|
+
/** Ordered, method-agnostic payment lifecycle extensions. */
|
|
41
|
+
extensions?: readonly Extension.Extension[] | undefined;
|
|
38
42
|
};
|
|
39
43
|
}
|
|
40
44
|
export type Config = defineConfig.Config<Mppx.Methods>;
|
package/dist/cli/config.js
CHANGED
package/dist/cli/internal.d.ts
CHANGED
|
@@ -1,7 +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
|
+
import type * as Extension from './Extension.js';
|
|
4
5
|
import type { Plugin } from './plugins/plugin.js';
|
|
6
|
+
/** Runs configured payment extensions in order and threads credential context between them. */
|
|
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. */
|
|
5
9
|
export declare function resolvePlugin(challenge: Challenge.Challenge, config?: {
|
|
6
10
|
plugins?: Plugin[] | undefined;
|
|
7
11
|
methods?: any;
|
|
@@ -22,4 +26,6 @@ export declare function loadConfig(configFile?: string | undefined): Promise<{
|
|
|
22
26
|
config: Config;
|
|
23
27
|
path: string;
|
|
24
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;
|
|
25
31
|
//# sourceMappingURL=internal.d.ts.map
|
package/dist/cli/internal.js
CHANGED
|
@@ -1,19 +1,37 @@
|
|
|
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()];
|
|
7
|
+
/** Runs configured payment extensions in order and threads credential context between them. */
|
|
8
|
+
export async function preparePayment(challenge, extensions, credentialContext) {
|
|
9
|
+
let current = credentialContext;
|
|
10
|
+
for (const extension of extensions ?? []) {
|
|
11
|
+
const result = await extension.preparePayment?.({
|
|
12
|
+
challenge,
|
|
13
|
+
...(current !== undefined ? { credentialContext: current } : {}),
|
|
14
|
+
});
|
|
15
|
+
if (result && 'credentialContext' in result)
|
|
16
|
+
current = result.credentialContext;
|
|
17
|
+
}
|
|
18
|
+
return current;
|
|
19
|
+
}
|
|
20
|
+
/** Resolves explicit payment configuration before falling back to built-in plugins. */
|
|
6
21
|
export function resolvePlugin(challenge, config) {
|
|
7
22
|
const configPlugin = config?.plugins?.find((p) => supportsPlugin(p, challenge));
|
|
8
23
|
if (configPlugin)
|
|
9
24
|
return { plugin: configPlugin };
|
|
10
|
-
const builtin = builtinPlugins.find((p) => supportsPlugin(p, challenge));
|
|
11
|
-
if (builtin)
|
|
12
|
-
return { plugin: builtin };
|
|
13
25
|
const configMethods = flattenConfigMethods(config);
|
|
14
|
-
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);
|
|
15
28
|
if (matched)
|
|
16
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 };
|
|
17
35
|
return {};
|
|
18
36
|
}
|
|
19
37
|
export function selectChallenge(challenges, config) {
|
|
@@ -22,7 +40,11 @@ export function selectChallenge(challenges, config) {
|
|
|
22
40
|
const resolvedPreferences = AcceptPayment.resolve(configMethods, config?.paymentPreferences);
|
|
23
41
|
const selected = AcceptPayment.selectChallenge(challenges, configMethods, resolvedPreferences.entries);
|
|
24
42
|
if (selected) {
|
|
25
|
-
|
|
43
|
+
const plugin = config?.plugins?.find((plugin) => supportsPlugin(plugin, selected.challenge));
|
|
44
|
+
return {
|
|
45
|
+
challenge: selected.challenge,
|
|
46
|
+
...(plugin ? { plugin } : { method: selected.method }),
|
|
47
|
+
};
|
|
26
48
|
}
|
|
27
49
|
return undefined;
|
|
28
50
|
}
|
|
@@ -71,4 +93,28 @@ function resolveConfigPath(configFile) {
|
|
|
71
93
|
}
|
|
72
94
|
return undefined;
|
|
73
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
|
+
}
|
|
74
120
|
//# sourceMappingURL=internal.js.map
|