mppx 0.17.5 → 0.17.6

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.
Files changed (38) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cli/cli.js +14 -12
  3. package/dist/cli/stripe.d.ts +6 -1
  4. package/dist/cli/stripe.js +89 -5
  5. package/dist/client/Mppx.js +1 -0
  6. package/dist/extensions/identity/email-otp/Constants.d.ts +16 -0
  7. package/dist/extensions/identity/email-otp/Constants.js +16 -0
  8. package/dist/extensions/identity/email-otp/Types.d.ts +12 -0
  9. package/dist/extensions/identity/email-otp/Types.js +2 -0
  10. package/dist/extensions/identity/email-otp/client/index.d.ts +116 -0
  11. package/dist/extensions/identity/email-otp/client/index.js +119 -0
  12. package/dist/extensions/identity/email-otp/index.d.ts +17 -0
  13. package/dist/extensions/identity/email-otp/index.js +16 -0
  14. package/dist/extensions/identity/email-otp/internal/Attestation.d.ts +66 -0
  15. package/dist/extensions/identity/email-otp/internal/Attestation.js +128 -0
  16. package/dist/extensions/identity/email-otp/internal/Constants.d.ts +20 -0
  17. package/dist/extensions/identity/email-otp/internal/Constants.js +20 -0
  18. package/dist/extensions/identity/email-otp/internal/Jwks.d.ts +30 -0
  19. package/dist/extensions/identity/email-otp/internal/Jwks.js +114 -0
  20. package/dist/extensions/identity/email-otp/internal/Prover.d.ts +46 -0
  21. package/dist/extensions/identity/email-otp/internal/Prover.js +168 -0
  22. package/dist/extensions/identity/email-otp/internal/Types.d.ts +48 -0
  23. package/dist/extensions/identity/email-otp/internal/Types.js +2 -0
  24. package/dist/extensions/identity/email-otp/internal/Verifier.d.ts +56 -0
  25. package/dist/extensions/identity/email-otp/internal/Verifier.js +116 -0
  26. package/dist/extensions/identity/email-otp/server/index.d.ts +48 -0
  27. package/dist/extensions/identity/email-otp/server/index.js +56 -0
  28. package/dist/extensions/identity/index.d.ts +2 -0
  29. package/dist/extensions/identity/index.js +2 -0
  30. package/dist/identity/Callback.d.ts +47 -0
  31. package/dist/identity/Callback.js +64 -0
  32. package/dist/identity/index.d.ts +1 -0
  33. package/dist/identity/index.js +1 -0
  34. package/dist/internal/version.d.ts +2 -2
  35. package/dist/internal/version.js +1 -1
  36. package/dist/proxy/internal/Headers.js +2 -0
  37. package/dist/tempo/server/internal/html.gen.js +1 -1
  38. package/package.json +5 -1
@@ -0,0 +1,48 @@
1
+ import type * as Identity from '../../../../identity/Types.js';
2
+ import type { MaybePromise } from '../../../../internal/types.js';
3
+ import type * as AttestationTypes from '../internal/Types.js';
4
+ import type * as Types from '../Types.js';
5
+ /**
6
+ * Creates a request-stage verifier that requires a verified email address.
7
+ *
8
+ * A request without one gets 401 with `Identity-Attestation-Required: email;issuer="…"`.
9
+ * The client obtains an attestation from the issuer with a one-time code sent to
10
+ * the address and sends it in `Identity-Attestation`. `allow` applies the
11
+ * route's policy, such as a domain allowlist.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * const email = EmailOtp.Server.verifier({
16
+ * audience: 'https://api.example',
17
+ * issuer: 'https://issuer.example',
18
+ * allow: (email) => email.endsWith('@example.com'),
19
+ * })
20
+ * const result = await mppx.charge({ amount: '1', identity: [email] })(request)
21
+ * if (result.status === 200) result.identity?.get(email)?.email
22
+ * ```
23
+ */
24
+ export declare function verifier(config: verifier.Config): Identity.Verifier<Types.VerifiedEmail>;
25
+ export declare namespace verifier {
26
+ type Config = {
27
+ /** Trusted issuer URL. */
28
+ issuer: string;
29
+ /** Accepts or rejects (403) a verified, lowercased email address. Defaults to any. */
30
+ allow?: ((email: string, request: Request) => MaybePromise<boolean>) | undefined;
31
+ /**
32
+ * This server's public origin, such as `https://api.example`, which attestations must be bound to.
33
+ *
34
+ * A function may derive it from the request only where the platform
35
+ * guarantees the request's host (such as a Cloudflare Worker route).
36
+ */
37
+ audience: string | ((request: Request) => string);
38
+ /** Resolves issuer keys. Defaults to the issuer's JSON Web Key Set. */
39
+ keyResolver?: AttestationTypes.KeyResolver | undefined;
40
+ /** Fetch used for the default JSON Web Key Set resolver. */
41
+ fetch?: typeof globalThis.fetch | undefined;
42
+ /** Oldest accepted attestation, in seconds since it was issued. Defaults to its own expiry. */
43
+ maxAge?: number | undefined;
44
+ /** Clock tolerance in seconds. @default 60 */
45
+ clockTolerance?: number | undefined;
46
+ };
47
+ }
48
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,56 @@
1
+ import { Constants } from '../Constants.js';
2
+ import * as Attestation from '../internal/Verifier.js';
3
+ /**
4
+ * Creates a request-stage verifier that requires a verified email address.
5
+ *
6
+ * A request without one gets 401 with `Identity-Attestation-Required: email;issuer="…"`.
7
+ * The client obtains an attestation from the issuer with a one-time code sent to
8
+ * the address and sends it in `Identity-Attestation`. `allow` applies the
9
+ * route's policy, such as a domain allowlist.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const email = EmailOtp.Server.verifier({
14
+ * audience: 'https://api.example',
15
+ * issuer: 'https://issuer.example',
16
+ * allow: (email) => email.endsWith('@example.com'),
17
+ * })
18
+ * const result = await mppx.charge({ amount: '1', identity: [email] })(request)
19
+ * if (result.status === 200) result.identity?.get(email)?.email
20
+ * ```
21
+ */
22
+ export function verifier(config) {
23
+ const inner = Attestation.verifier({
24
+ audience: config.audience,
25
+ clockTolerance: config.clockTolerance,
26
+ fetch: config.fetch,
27
+ issuer: config.issuer,
28
+ keyResolver: config.keyResolver,
29
+ maxAge: config.maxAge,
30
+ type: Constants.type,
31
+ async validate(claims, request) {
32
+ if (!config.allow || (await config.allow(claims.sub.toLowerCase(), request)))
33
+ return undefined;
34
+ return 'This email address is not allowed.';
35
+ },
36
+ });
37
+ return {
38
+ stage: 'request',
39
+ async verify(request, context) {
40
+ const result = await inner.verify(request, context);
41
+ if (result.status !== 'valid')
42
+ return result;
43
+ const { claims } = result.value;
44
+ return {
45
+ status: 'valid',
46
+ value: {
47
+ email: claims.sub.toLowerCase(),
48
+ expiresAt: new Date(claims.exp * 1_000),
49
+ id: claims.jti,
50
+ issuer: claims.iss,
51
+ },
52
+ };
53
+ },
54
+ };
55
+ }
56
+ //# sourceMappingURL=index.js.map
@@ -1,3 +1,5 @@
1
+ /** Email address verification with a one-time code. */
2
+ export * as EmailOtp from './email-otp/index.js';
1
3
  /** Client and server adapters for the TAP agent-recognition signature profile. */
2
4
  export * as Tap from './tap/index.js';
3
5
  /** Client and server adapters for the Web Bot Auth HTTPS-directory profile. */
@@ -1,3 +1,5 @@
1
+ /** Email address verification with a one-time code. */
2
+ export * as EmailOtp from './email-otp/index.js';
1
3
  /** Client and server adapters for the TAP agent-recognition signature profile. */
2
4
  export * as Tap from './tap/index.js';
3
5
  /** Client and server adapters for the Web Bot Auth HTTPS-directory profile. */
@@ -0,0 +1,47 @@
1
+ import type { MaybePromise } from '../internal/types.js';
2
+ import type * as Types from './Types.js';
3
+ /**
4
+ * Creates a request-stage verifier from a function, such as a lookup in your
5
+ * own database, session store or KYC provider.
6
+ *
7
+ * `verify` returns the caller's identity, which the route handler reads with
8
+ * `result.identity.get(verifier)`; `undefined` or `null` when the request carries none
9
+ * (401, with `challenge` headers if set); or throws a {@link Rejection} to
10
+ * reject the identity it carries.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * const customer = Identity.from({
15
+ * async verify(request) {
16
+ * const key = request.headers.get('X-Api-Key')
17
+ * if (!key) return undefined
18
+ * const row = await db.customerByKey(key)
19
+ * if (!row) throw new Identity.Rejection('Unknown API key.', { code: 403 })
20
+ * return row
21
+ * },
22
+ * })
23
+ * mppx.charge({ amount: '1', identity: [customer] })
24
+ * ```
25
+ */
26
+ export declare function from<value>(config: from.Config<value>): Types.Verifier<value>;
27
+ export declare namespace from {
28
+ type Config<value> = {
29
+ /**
30
+ * Returns the request's verified identity, `undefined` or `null` when it carries none,
31
+ * or throws a {@link Rejection} to reject the one it carries.
32
+ */
33
+ verify: (request: Request) => MaybePromise<value | null | undefined>;
34
+ /** Headers sent with a rejection, telling the client what identity to present. */
35
+ challenge?: HeadersInit | undefined;
36
+ };
37
+ }
38
+ /** Rejects an identity a {@link from} verifier was given. */
39
+ export declare class Rejection extends Error {
40
+ readonly name = "Rejection";
41
+ /** HTTP status of the rejection. @default 401 */
42
+ readonly code: number;
43
+ constructor(message: string, options?: {
44
+ code?: number | undefined;
45
+ });
46
+ }
47
+ //# sourceMappingURL=Callback.d.ts.map
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Creates a request-stage verifier from a function, such as a lookup in your
3
+ * own database, session store or KYC provider.
4
+ *
5
+ * `verify` returns the caller's identity, which the route handler reads with
6
+ * `result.identity.get(verifier)`; `undefined` or `null` when the request carries none
7
+ * (401, with `challenge` headers if set); or throws a {@link Rejection} to
8
+ * reject the identity it carries.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * const customer = Identity.from({
13
+ * async verify(request) {
14
+ * const key = request.headers.get('X-Api-Key')
15
+ * if (!key) return undefined
16
+ * const row = await db.customerByKey(key)
17
+ * if (!row) throw new Identity.Rejection('Unknown API key.', { code: 403 })
18
+ * return row
19
+ * },
20
+ * })
21
+ * mppx.charge({ amount: '1', identity: [customer] })
22
+ * ```
23
+ */
24
+ export function from(config) {
25
+ return {
26
+ stage: 'request',
27
+ async verify(request) {
28
+ let value;
29
+ try {
30
+ value = await config.verify(request);
31
+ }
32
+ catch (error) {
33
+ if (!(error instanceof Rejection))
34
+ throw error;
35
+ return {
36
+ status: 'invalid',
37
+ code: error.code,
38
+ headers: config.challenge,
39
+ reason: error.message,
40
+ };
41
+ }
42
+ // A lookup that found nothing often returns null: treat it as no identity.
43
+ if (value === undefined || value === null)
44
+ return {
45
+ status: 'missing',
46
+ code: 401,
47
+ headers: config.challenge,
48
+ reason: 'Identity verification is required.',
49
+ };
50
+ return { status: 'valid', value };
51
+ },
52
+ };
53
+ }
54
+ /** Rejects an identity a {@link from} verifier was given. */
55
+ export class Rejection extends Error {
56
+ name = 'Rejection';
57
+ /** HTTP status of the rejection. @default 401 */
58
+ code;
59
+ constructor(message, options = {}) {
60
+ super(message);
61
+ this.code = options.code ?? 401;
62
+ }
63
+ }
64
+ //# sourceMappingURL=Callback.js.map
@@ -1,6 +1,7 @@
1
1
  export * as Client from './Client.js';
2
2
  export * as Server from './Server.js';
3
3
  export { anyOf } from './Server.js';
4
+ export { from, Rejection } from './Callback.js';
4
5
  export * as Store from '../Store.js';
5
6
  export type * from './Types.js';
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -1,5 +1,6 @@
1
1
  export * as Client from './Client.js';
2
2
  export * as Server from './Server.js';
3
3
  export { anyOf } from './Server.js';
4
+ export { from, Rejection } from './Callback.js';
4
5
  export * as Store from '../Store.js';
5
6
  //# sourceMappingURL=index.js.map
@@ -1,5 +1,5 @@
1
1
  /** Current mppx package version. */
2
- export declare const version = "0.17.5";
2
+ export declare const version = "0.17.6";
3
3
  /** Canonical SDK identifier for this mppx release. */
4
- export declare const sdkIdentifier = "mppx/0.17.5";
4
+ export declare const sdkIdentifier = "mppx/0.17.6";
5
5
  //# sourceMappingURL=version.d.ts.map
@@ -1,6 +1,6 @@
1
1
  // Generated by scripts/sync-version.ts.
2
2
  /** Current mppx package version. */
3
- export const version = '0.17.5';
3
+ export const version = '0.17.6';
4
4
  /** Canonical SDK identifier for this mppx release. */
5
5
  export const sdkIdentifier = `mppx/${version}`;
6
6
  //# sourceMappingURL=version.js.map
@@ -11,6 +11,8 @@ const hopByHopHeaders = new Set([
11
11
  // Payment credentials are consumed by the proxy and must never reach upstream services.
12
12
  const paymentHeaders = new Set([
13
13
  'accept-payment',
14
+ 'identity-attestation',
15
+ 'identity-attestation-required',
14
16
  'authorization',
15
17
  'payment-authorization',
16
18
  'payment-receipt',