mppx 0.17.5 → 0.18.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 +40 -0
- package/dist/cli/cli.js +141 -139
- package/dist/cli/plugins/index.js +6 -6
- package/dist/cli/stripe.d.ts +6 -1
- package/dist/cli/stripe.js +89 -5
- package/dist/client/Mppx.js +13 -3
- package/dist/client/internal/Fetch.js +9 -5
- package/dist/extensions/identity/attestation/Constants.d.ts +23 -0
- package/dist/extensions/identity/attestation/Constants.js +23 -0
- package/dist/extensions/identity/attestation/Jwks.d.ts +30 -0
- package/dist/extensions/identity/attestation/Jwks.js +114 -0
- package/dist/extensions/identity/attestation/Token.d.ts +80 -0
- package/dist/extensions/identity/attestation/Token.js +143 -0
- package/dist/extensions/identity/attestation/Types.d.ts +48 -0
- package/dist/extensions/identity/attestation/Types.js +2 -0
- package/dist/extensions/identity/attestation/client/index.d.ts +66 -0
- package/dist/extensions/identity/attestation/client/index.js +273 -0
- package/dist/extensions/identity/attestation/index.d.ts +20 -0
- package/dist/extensions/identity/attestation/index.js +18 -0
- package/dist/extensions/identity/attestation/internal/Cache.d.ts +120 -0
- package/dist/extensions/identity/attestation/internal/Cache.js +90 -0
- package/dist/extensions/identity/attestation/server/index.d.ts +66 -0
- package/dist/extensions/identity/attestation/server/index.js +119 -0
- package/dist/extensions/identity/email-otp/Constants.d.ts +16 -0
- package/dist/extensions/identity/email-otp/Constants.js +17 -0
- package/dist/extensions/identity/email-otp/Types.d.ts +12 -0
- package/dist/extensions/identity/email-otp/Types.js +2 -0
- package/dist/extensions/identity/email-otp/client/index.d.ts +123 -0
- package/dist/extensions/identity/email-otp/client/index.js +131 -0
- package/dist/extensions/identity/email-otp/index.d.ts +12 -0
- package/dist/extensions/identity/email-otp/index.js +11 -0
- package/dist/extensions/identity/email-otp/server/index.d.ts +48 -0
- package/dist/extensions/identity/email-otp/server/index.js +59 -0
- package/dist/extensions/identity/index.d.ts +4 -0
- package/dist/extensions/identity/index.js +4 -0
- package/dist/extensions/identity/internal/Verification.js +9 -5
- package/dist/identity/Callback.d.ts +66 -0
- package/dist/identity/Callback.js +88 -0
- package/dist/identity/Client.d.ts +78 -5
- package/dist/identity/Client.js +165 -48
- package/dist/identity/Headers.d.ts +16 -0
- package/dist/identity/Headers.js +19 -0
- package/dist/identity/Server.d.ts +159 -37
- package/dist/identity/Server.js +307 -138
- package/dist/identity/Status.d.ts +14 -0
- package/dist/identity/Status.js +19 -0
- package/dist/identity/Types.d.ts +161 -65
- package/dist/identity/index.d.ts +3 -0
- package/dist/identity/index.js +3 -0
- package/dist/identity/internal/Requirements.d.ts +28 -0
- package/dist/identity/internal/Requirements.js +78 -0
- package/dist/integrations/x402/Evm.d.ts +1 -0
- package/dist/internal/env.d.ts +14 -0
- package/dist/internal/env.js +38 -0
- package/dist/internal/version.d.ts +2 -2
- package/dist/internal/version.js +1 -1
- package/dist/proxy/internal/Headers.d.ts +1 -1
- package/dist/proxy/internal/Headers.js +7 -1
- package/dist/server/Mppx.d.ts +14 -6
- package/dist/server/Mppx.js +252 -148
- package/dist/server/internal/challengeMeta.d.ts +0 -6
- package/dist/server/internal/challengeMeta.js +3 -17
- package/dist/tempo/server/Charge.d.ts +14 -9
- package/dist/tempo/server/Charge.js +5 -1
- package/dist/tempo/server/Methods.js +4 -1
- package/dist/tempo/server/Subscription.d.ts +8 -0
- package/dist/tempo/server/internal/fallback-store.d.ts +7 -2
- package/dist/tempo/server/internal/fallback-store.js +12 -3
- package/dist/tempo/server/internal/html.gen.js +1 -1
- package/dist/tempo/session/server/Session.d.ts +5 -1
- package/package.json +9 -1
|
@@ -1,59 +1,181 @@
|
|
|
1
|
+
import type * as Challenge from '../Challenge.js';
|
|
2
|
+
import type * as Credential from '../Credential.js';
|
|
1
3
|
import type * as Types from './Types.js';
|
|
4
|
+
/** The value of an `anyOf` verifier: the index of the first valid member and its value. */
|
|
5
|
+
type AnyOfValue = {
|
|
6
|
+
readonly index: number;
|
|
7
|
+
readonly value: unknown;
|
|
8
|
+
};
|
|
9
|
+
type Rejected = Exclude<Types.Verification, {
|
|
10
|
+
status: 'valid';
|
|
11
|
+
}>;
|
|
2
12
|
/**
|
|
3
13
|
* Accepts the first of several identity protocols that verifies.
|
|
4
14
|
*
|
|
5
|
-
* Every member runs. The result is `valid` if any member verifies
|
|
6
|
-
*
|
|
7
|
-
*
|
|
15
|
+
* Every member runs. The result is `valid` if any member verifies (the first valid member
|
|
16
|
+
* wins). Otherwise the rejected member whose status has the highest precedence
|
|
17
|
+
* (`Identity.Status.precedence`) decides the status and reason, with every member's headers.
|
|
18
|
+
* Members' `Identity-Attestation-Required` values become one inner list of alternatives, such
|
|
19
|
+
* as `(email;issuer="https://a.example" email;issuer="https://b.example")`, so a client
|
|
20
|
+
* obtains one of them rather than all.
|
|
8
21
|
*
|
|
9
22
|
* @example
|
|
10
23
|
* ```ts
|
|
11
24
|
* mppx.charge({ amount: '1', identity: [Identity.anyOf(tap, webBotAuth)] })
|
|
12
25
|
* ```
|
|
13
26
|
*/
|
|
14
|
-
export declare function anyOf(...verifiers: readonly [Types.Verifier, Types.Verifier, ...Types.Verifier[]]): Types.Verifier<
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
} | {
|
|
23
|
-
status: 'missing' | 'invalid';
|
|
24
|
-
code: number;
|
|
25
|
-
headers: Headers;
|
|
26
|
-
reason: string;
|
|
27
|
+
export declare function anyOf(...verifiers: readonly [Types.Verifier, Types.Verifier, ...Types.Verifier[]]): Types.Verifier<AnyOfValue>;
|
|
28
|
+
/** A rejected outcome reduced to its fixed status, the HTTP code it is sent with, headers and reason. */
|
|
29
|
+
export type Decision = {
|
|
30
|
+
readonly status: Types.RejectionStatus;
|
|
31
|
+
/** HTTP status code: `Identity.Status.codes[status]`, unless a deprecated `code` overrides it. */
|
|
32
|
+
readonly code: number;
|
|
33
|
+
readonly headers: readonly (readonly [name: string, value: string])[];
|
|
34
|
+
readonly reason: string;
|
|
27
35
|
};
|
|
36
|
+
/** Verified values, keyed by the verifier (every `anyOf` level included) or payment check. */
|
|
37
|
+
export type Values = ReadonlyMap<Types.Verifier | Types.PaymentCheck, unknown>;
|
|
38
|
+
/** The combined outcome of verifiers or a payment check. @internal */
|
|
39
|
+
export type Outcome = {
|
|
40
|
+
readonly status: 'valid';
|
|
41
|
+
readonly values: Values;
|
|
42
|
+
} | Decision;
|
|
43
|
+
/** The outcome of no verifiers: valid, with no values. @internal */
|
|
44
|
+
export declare const none: Outcome;
|
|
28
45
|
/**
|
|
29
|
-
*
|
|
46
|
+
* Decides one rejection from rejected outcomes: the outcome whose fixed status has the highest
|
|
47
|
+
* precedence decides status, code and reason (the first such outcome on ties), and the headers
|
|
48
|
+
* of every outcome are merged. @internal
|
|
49
|
+
*/
|
|
50
|
+
export declare function decide(outcomes: readonly Rejected[]): Decision;
|
|
51
|
+
/**
|
|
52
|
+
* The identity state of one request. Every verifier runs at most once per context, so
|
|
53
|
+
* replay-protected nonces are consumed once even when `compose` calls several offers with
|
|
54
|
+
* the same request. `compose` creates one and passes it to every offer it calls; a route
|
|
55
|
+
* called directly creates its own. @internal
|
|
56
|
+
*/
|
|
57
|
+
export declare class Context {
|
|
58
|
+
/** Verification promises by verifier. Internal and mutable; outcomes are frozen. */
|
|
59
|
+
readonly verifications: Map<Types.Verifier<unknown>, Promise<Types.Verification<unknown>>>;
|
|
60
|
+
/**
|
|
61
|
+
* Payment check promises by check, then by Challenge id and attempt (`paid` or `unpaid`), so
|
|
62
|
+
* a check runs once per attempt even when `compose` calls the matched offer again.
|
|
63
|
+
*/
|
|
64
|
+
readonly checks: Map<Types.PaymentCheck<unknown>, Map<string, Promise<Outcome>>>;
|
|
65
|
+
}
|
|
66
|
+
/** Creates the identity context of one request. @internal */
|
|
67
|
+
export declare function createContext(): Context;
|
|
68
|
+
/** Returns `value` if it is an identity context, otherwise a new one. @internal */
|
|
69
|
+
export declare function contextOf(value: unknown): Context;
|
|
70
|
+
/**
|
|
71
|
+
* Runs request-stage verifiers and combines their outcomes.
|
|
30
72
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* per request and context, so replay-protected nonces are consumed once even
|
|
35
|
-
* when several handlers evaluate the same request.
|
|
73
|
+
* Valid only if every verifier is valid, with each value recorded at every `anyOf` level, so
|
|
74
|
+
* `results.get(leaf)` works when nested. Otherwise the precedence rule of {@link decide}.
|
|
75
|
+
* @internal
|
|
36
76
|
*/
|
|
37
|
-
export declare function verify(request: Request, verifiers: readonly Types.Verifier[]
|
|
77
|
+
export declare function verify(context: Context, request: Request, verifiers: readonly Types.Verifier[]): Promise<Outcome>;
|
|
38
78
|
/**
|
|
39
|
-
*
|
|
79
|
+
* Runs a payment check at most once per context, Challenge and attempt, and returns its
|
|
80
|
+
* outcome. @internal
|
|
81
|
+
*/
|
|
82
|
+
export declare function check(context: Context, paymentCheck: Types.PaymentCheck, parameters: Parameters<Types.PaymentCheck['verify']>[0]): Promise<Outcome>;
|
|
83
|
+
/**
|
|
84
|
+
* The identity state of one route call, as a state machine:
|
|
85
|
+
*
|
|
86
|
+
* - `request`: nothing checked yet.
|
|
87
|
+
* - `identified`: request-stage verifiers passed; no payment decision yet.
|
|
88
|
+
* - `payment`: the payment check runs for a Challenge, with the Credential on a paid retry
|
|
89
|
+
* or without one before `authorize`.
|
|
90
|
+
* - `accepted`: the payment check passed (or the route has none): paid work may run.
|
|
91
|
+
* - `challenged`: the route issued a 402 carrying `requirements`.
|
|
92
|
+
* - `rejected`: identity was rejected; the response is sent as is, never a fresh 402.
|
|
40
93
|
*
|
|
41
|
-
*
|
|
42
|
-
* in a composed 402 carries the same challenge. @internal
|
|
94
|
+
* @internal
|
|
43
95
|
*/
|
|
44
|
-
export
|
|
96
|
+
export type State = {
|
|
97
|
+
readonly phase: 'request';
|
|
98
|
+
} | {
|
|
99
|
+
readonly phase: 'identified';
|
|
100
|
+
readonly values: Values;
|
|
101
|
+
} | {
|
|
102
|
+
readonly phase: 'payment';
|
|
103
|
+
readonly values: Values;
|
|
104
|
+
readonly challenge: Challenge.Challenge;
|
|
105
|
+
readonly credential: Credential.Credential | undefined;
|
|
106
|
+
} | {
|
|
107
|
+
readonly phase: 'accepted';
|
|
108
|
+
readonly values: Values;
|
|
109
|
+
} | {
|
|
110
|
+
readonly phase: 'challenged';
|
|
111
|
+
readonly values: Values;
|
|
112
|
+
readonly requirements: readonly Types.Requirement[];
|
|
113
|
+
} | {
|
|
114
|
+
readonly phase: 'rejected';
|
|
115
|
+
readonly rejection: Types.Rejection;
|
|
116
|
+
readonly code: number;
|
|
117
|
+
readonly headers: Decision['headers'];
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* An input to {@link transition}. The caller runs verifiers and checks (the only I/O) and feeds
|
|
121
|
+
* their outcomes in. @internal
|
|
122
|
+
*/
|
|
123
|
+
export type Event =
|
|
124
|
+
/** Request-stage verifiers ran (`none` when the route has none). */
|
|
125
|
+
{
|
|
126
|
+
readonly type: 'verified';
|
|
127
|
+
readonly outcome: Outcome;
|
|
128
|
+
}
|
|
129
|
+
/** The payment check is about to run for `challenge`, with the paid retry's Credential if any. */
|
|
130
|
+
| {
|
|
131
|
+
readonly type: 'pay';
|
|
132
|
+
readonly challenge: Challenge.Challenge;
|
|
133
|
+
readonly credential: Credential.Credential | undefined;
|
|
134
|
+
}
|
|
135
|
+
/** The payment check ran (`none` when the route has none). */
|
|
136
|
+
| {
|
|
137
|
+
readonly type: 'checked';
|
|
138
|
+
readonly outcome: Outcome;
|
|
139
|
+
}
|
|
140
|
+
/** The route issues a 402 carrying `requirements`. */
|
|
141
|
+
| {
|
|
142
|
+
readonly type: 'challenge';
|
|
143
|
+
readonly requirements: readonly Types.Requirement[];
|
|
144
|
+
};
|
|
145
|
+
/** The state of a route call before identity runs. @internal */
|
|
146
|
+
export declare const initial: State;
|
|
45
147
|
/**
|
|
46
|
-
* Returns the identity
|
|
148
|
+
* Returns the next identity state. Pure: it never runs verifiers, and it throws a `TypeError`
|
|
149
|
+
* for an event the current phase does not accept.
|
|
47
150
|
*
|
|
48
|
-
*
|
|
151
|
+
* | Phase | Event | Next |
|
|
152
|
+
* | ------------------------ | ---------------------- | --------------------------------- |
|
|
153
|
+
* | `request` | `verified` (valid) | `identified` |
|
|
154
|
+
* | `request` | `verified` (rejected) | `rejected` (stage `request`) |
|
|
155
|
+
* | `identified` | `pay` | `payment` |
|
|
156
|
+
* | `payment` | `checked` (valid) | `accepted` |
|
|
157
|
+
* | `payment` + Credential | `checked` (rejected) | `rejected` (stage `payment`) |
|
|
158
|
+
* | `payment`, no Credential | `checked` (rejected) | `identified` (not authorized) |
|
|
159
|
+
* | `identified`, `accepted` | `challenge` | `challenged` |
|
|
160
|
+
*
|
|
161
|
+
* @internal
|
|
49
162
|
*/
|
|
50
|
-
export declare function
|
|
51
|
-
/** Builds the rejection response
|
|
52
|
-
export declare function toResponse(
|
|
53
|
-
|
|
163
|
+
export declare function transition(state: State, event: Event): State;
|
|
164
|
+
/** Builds the rejection response of a rejected state. @internal */
|
|
165
|
+
export declare function toResponse(state: Extract<State, {
|
|
166
|
+
phase: 'rejected';
|
|
54
167
|
}>): Response;
|
|
55
|
-
/**
|
|
56
|
-
export declare function results(
|
|
57
|
-
/**
|
|
58
|
-
export
|
|
168
|
+
/** Returns the frozen results lookup of a state's verified values. @internal */
|
|
169
|
+
export declare function results(state: State): Types.Results;
|
|
170
|
+
/** A route's parsed `identity` option. @internal */
|
|
171
|
+
export type RouteConfig = {
|
|
172
|
+
readonly request: readonly Types.Verifier[];
|
|
173
|
+
readonly payment: Types.PaymentCheck | undefined;
|
|
174
|
+
};
|
|
175
|
+
/**
|
|
176
|
+
* Parses a route's `identity` option. Throws a `TypeError` for a payment-stage or unknown-stage
|
|
177
|
+
* verifier, and for payment requirements that cannot be serialized. @internal
|
|
178
|
+
*/
|
|
179
|
+
export declare function route(identity: Types.Route | undefined): RouteConfig;
|
|
180
|
+
export {};
|
|
59
181
|
//# sourceMappingURL=Server.d.ts.map
|