mppx 0.11.0 → 0.12.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 +28 -0
- package/README.md +22 -1
- package/dist/cli/agent.d.ts +3 -0
- package/dist/cli/agent.js +20 -0
- package/dist/cli/cli.d.ts +1 -1
- package/dist/cli/cli.js +135 -135
- package/dist/cli/plugins/index.js +12 -12
- package/dist/cli/validate/payment.js +29 -12
- package/dist/evm/server/Methods.d.ts +164 -3
- package/dist/evm/server/Methods.js +50 -2
- package/dist/internal/version.d.ts +2 -2
- package/dist/internal/version.js +1 -1
- package/dist/server/Mppx.d.ts +5 -1
- package/dist/server/Mppx.js +120 -49
- package/dist/server/internal/html/compose.main.gen.d.ts +1 -1
- package/dist/server/internal/html/serviceWorker.gen.d.ts +1 -1
- package/dist/stripe/server/Methods.js +2 -4
- package/dist/stripe/server/internal/html.gen.d.ts +1 -1
- package/dist/tempo/internal/currencies.d.ts +19 -0
- package/dist/tempo/internal/currencies.js +41 -0
- package/dist/tempo/internal/defaults.d.ts +5 -3
- package/dist/tempo/internal/defaults.js +6 -2
- package/dist/tempo/internal/fee-payer.d.ts +5 -4
- package/dist/tempo/internal/fee-payer.js +7 -5
- package/dist/tempo/server/Charge.d.ts +12 -1
- package/dist/tempo/server/Charge.js +34 -32
- package/dist/tempo/server/Methods.d.ts +5003 -40
- package/dist/tempo/server/Methods.js +104 -13
- 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/server/ChannelStore.d.ts +2 -0
- package/dist/tempo/session/server/ChannelStore.js +12 -3
- package/dist/tempo/session/server/CredentialVerification.d.ts +2 -0
- package/dist/tempo/session/server/CredentialVerification.js +22 -13
- package/dist/tempo/session/server/RequestState.d.ts +6 -0
- package/dist/tempo/session/server/RequestState.js +11 -4
- package/dist/tempo/session/server/Session.js +8 -1
- package/dist/tempo/session/server/Settlement.d.ts +2 -0
- package/dist/tempo/session/server/Settlement.js +13 -8
- package/dist/tempo/subscription/KeyAuthorization.d.ts +70 -8
- package/package.json +3 -3
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import * as Store from '../../Store.js';
|
|
2
|
+
import * as Currencies from '../internal/currencies.js';
|
|
3
|
+
import * as ChannelStore from '../session/server/ChannelStore.js';
|
|
1
4
|
import { charge as sessionCharge_, session as session_, settle as settle_, settleBatch as settleBatch_, } from '../session/server/Session.js';
|
|
2
5
|
import * as Ws_ from '../session/server/Ws.js';
|
|
3
6
|
import { charge as charge_ } from './Charge.js';
|
|
@@ -11,18 +14,28 @@ function createChargeMethod(parameters) {
|
|
|
11
14
|
// `tempo()` accepts the intersection of charge/session parameters, then
|
|
12
15
|
// forwards only the fields each method understands. Preserve the inferred
|
|
13
16
|
// parameter type so configured request defaults remain visible to handlers.
|
|
14
|
-
return
|
|
17
|
+
return charge_(parameters);
|
|
15
18
|
}
|
|
16
19
|
function createSessionMethod(parameters) {
|
|
17
|
-
//
|
|
18
|
-
|
|
19
|
-
// session routing has its own complete lifecycle support.
|
|
20
|
-
const { machineTokenEnabled: _machineTokenEnabled, ...sessionParameters } = parameters ?? {};
|
|
20
|
+
// These options apply only to charge, even when configured at the family level.
|
|
21
|
+
const { allowedFeeTokens: _allowedFeeTokens, machineTokenEnabled: _machineTokenEnabled, ...sessionParameters } = parameters ?? {};
|
|
21
22
|
return sessionServer(sessionParameters);
|
|
22
23
|
}
|
|
23
24
|
/**
|
|
24
25
|
* Creates the common Tempo `charge` and `session` methods from shared parameters.
|
|
25
26
|
*
|
|
27
|
+
* Mainnet accepts OUSD first, then USDC.e. Testnet accepts OUSD first, then pathUSD.
|
|
28
|
+
* Use `currencies`
|
|
29
|
+
* for an ordered list of addresses/token definitions, including a one-element
|
|
30
|
+
* list for a single asset. Each currency creates charge and session offers; list
|
|
31
|
+
* order is presentation order, not a requirement on the client's choice.
|
|
32
|
+
* Chain-indexed definitions (including `tokens.tempo` from `viem/tokens`) are
|
|
33
|
+
* filtered to USD tokens deployed on `chainId`. Duplicates are removed by address.
|
|
34
|
+
* Explicit lists replace the defaults; an empty resolved list throws.
|
|
35
|
+
*
|
|
36
|
+
* The chain defaults to Tempo mainnet (Moderato with `testnet: true`). Set
|
|
37
|
+
* `chainId` explicitly when using a custom client for another network.
|
|
38
|
+
*
|
|
26
39
|
* When configured, `relay` applies to the `charge` method. Session vouchers
|
|
27
40
|
* remain local state transitions and session relay delegation will be added
|
|
28
41
|
* with its action-specific lifecycle support.
|
|
@@ -32,22 +45,41 @@ function createSessionMethod(parameters) {
|
|
|
32
45
|
* import { Mppx, tempo } from 'mppx/server'
|
|
33
46
|
*
|
|
34
47
|
* const mppx = Mppx.create({
|
|
35
|
-
* methods: [tempo.common({
|
|
48
|
+
* methods: [tempo.common({ recipient: '0x...' })],
|
|
36
49
|
* })
|
|
37
50
|
* ```
|
|
38
51
|
*/
|
|
39
52
|
export function tempo(parameters) {
|
|
40
|
-
|
|
53
|
+
if (parameters?.currency !== undefined) {
|
|
54
|
+
if (parameters.currencies !== undefined)
|
|
55
|
+
throw new Error('Specify either `currency` or `currencies`, not both.');
|
|
56
|
+
return [createChargeMethod(parameters), createSessionMethod(parameters)];
|
|
57
|
+
}
|
|
58
|
+
const { currencies: _currencies, ...shared } = parameters ?? {};
|
|
59
|
+
const [first, ...rest] = Currencies.resolve(parameters ?? {});
|
|
60
|
+
const sessions = sessionOffers(parameters);
|
|
61
|
+
function createMethods(currency, index) {
|
|
62
|
+
const configured = { ...shared, ...currency };
|
|
63
|
+
return [createChargeMethod(configured), sessions[index]];
|
|
64
|
+
}
|
|
65
|
+
return [
|
|
66
|
+
...createMethods(first, 0),
|
|
67
|
+
...rest.flatMap((currency, index) => createMethods(currency, index + 1)),
|
|
68
|
+
];
|
|
41
69
|
}
|
|
42
70
|
(function (tempo) {
|
|
43
|
-
/** Creates
|
|
44
|
-
tempo.charge =
|
|
71
|
+
/** Creates ordered Tempo charge offers: OUSD first, then the network fallback. */
|
|
72
|
+
tempo.charge = chargeOffers;
|
|
45
73
|
/** Creates the common Tempo `charge` and `session` methods from shared parameters. */
|
|
46
74
|
tempo.common = tempo;
|
|
47
|
-
/** Creates
|
|
48
|
-
tempo.session =
|
|
49
|
-
|
|
50
|
-
|
|
75
|
+
/** Creates ordered TIP-1034 session offers with shared storage and settlement helpers. */
|
|
76
|
+
tempo.session = Object.assign(sessionOffers, {
|
|
77
|
+
charge: sessionCharge_,
|
|
78
|
+
settle: settle_,
|
|
79
|
+
settleBatch: settleBatch_,
|
|
80
|
+
});
|
|
81
|
+
/** Creates ordered subscription offers. Existing subscriptions retain their authorized currency. */
|
|
82
|
+
tempo.subscription = subscriptionOffers;
|
|
51
83
|
/** Renews an overdue Tempo subscription outside of the HTTP request path. */
|
|
52
84
|
tempo.renewSubscription = renewSubscription_;
|
|
53
85
|
/** One-shot settle: reads highest voucher from storage and submits on-chain. */
|
|
@@ -57,4 +89,63 @@ export function tempo(parameters) {
|
|
|
57
89
|
/** Experimental websocket helpers for Tempo sessions. */
|
|
58
90
|
tempo.Ws = Ws_;
|
|
59
91
|
})(tempo || (tempo = {}));
|
|
92
|
+
/** Resolves the public factory configuration while preserving explicit legacy currencies. */
|
|
93
|
+
function resolveCurrencies(parameters) {
|
|
94
|
+
if (parameters.currency !== undefined && parameters.currencies !== undefined)
|
|
95
|
+
throw new Error('Specify either `currency` or `currencies`, not both.');
|
|
96
|
+
return Currencies.resolve({
|
|
97
|
+
...parameters,
|
|
98
|
+
...(parameters.currency === undefined ? {} : { currencies: [parameters.currency] }),
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
/** Creates OUSD-first charge offers, with explicit currency lists replacing the defaults. */
|
|
102
|
+
function chargeOffers(parameters) {
|
|
103
|
+
const { currencies: _currencies, ...shared } = parameters ?? {};
|
|
104
|
+
const [first, ...rest] = resolveCurrencies(parameters ?? {});
|
|
105
|
+
function create(currency) {
|
|
106
|
+
const configured = { ...shared, ...currency };
|
|
107
|
+
return charge_(configured);
|
|
108
|
+
}
|
|
109
|
+
return [create(first), ...rest.map(create)];
|
|
110
|
+
}
|
|
111
|
+
/** Creates OUSD-first session offers with shared storage and currency-aware settlement helpers. */
|
|
112
|
+
function sessionOffers(parameters) {
|
|
113
|
+
const { currencies: _currencies, ...shared } = parameters ?? {};
|
|
114
|
+
const [first, ...rest] = resolveCurrencies(parameters ?? {});
|
|
115
|
+
const store = parameters?.store ?? Store.memory();
|
|
116
|
+
const settlements = new Map();
|
|
117
|
+
const key = (chainId, currency) => `${chainId}:${currency.toLowerCase()}`;
|
|
118
|
+
const settleScheduled = (channel) => {
|
|
119
|
+
const settle = settlements.get(key(channel.chainId, channel.token));
|
|
120
|
+
if (!settle)
|
|
121
|
+
throw new Error('Channel currency is not configured for this session handler.');
|
|
122
|
+
return settle(channel);
|
|
123
|
+
};
|
|
124
|
+
const extensions = {
|
|
125
|
+
settleScheduled,
|
|
126
|
+
serveWebSocket: (options) => Ws_.serve({
|
|
127
|
+
...options,
|
|
128
|
+
store: ChannelStore.fromStore(store),
|
|
129
|
+
onChargeCommitted: settleScheduled,
|
|
130
|
+
}),
|
|
131
|
+
};
|
|
132
|
+
function create(currency) {
|
|
133
|
+
const configured = { ...shared, ...currency, store };
|
|
134
|
+
const method = session_(configured);
|
|
135
|
+
settlements.set(key(currency.chainId, currency.currency), method.extensions.settleScheduled);
|
|
136
|
+
return { ...method, extensions };
|
|
137
|
+
}
|
|
138
|
+
return [create(first), ...rest.map(create)];
|
|
139
|
+
}
|
|
140
|
+
/** Offers currencies for new subscriptions; stored subscriptions retain their authorized currency. */
|
|
141
|
+
function subscriptionOffers(parameters) {
|
|
142
|
+
const { currencies: _currencies, ...shared } = parameters;
|
|
143
|
+
const [first, ...rest] = resolveCurrencies(parameters);
|
|
144
|
+
const store = parameters.store ?? Store.memory();
|
|
145
|
+
function create(currency) {
|
|
146
|
+
const configured = { ...shared, ...currency, store };
|
|
147
|
+
return subscription_(configured);
|
|
148
|
+
}
|
|
149
|
+
return [create(first), ...rest.map(create)];
|
|
150
|
+
}
|
|
60
151
|
//# sourceMappingURL=Methods.js.map
|