@armory-sh/middleware 0.2.2 → 0.3.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/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _armory_sh_base from '@armory-sh/base';
2
- import { Address, CAIP2ChainId, CAIPAssetId, PaymentRequirements as PaymentRequirements$1, X402SettlementResponse, SettlementResponseV1, SettlementResponseV2, X402PaymentPayload, X402PaymentRequirements, ResolvedPaymentConfig, AcceptPaymentOptions, NetworkId, TokenId, ValidationError } from '@armory-sh/base';
2
+ import { Address, CAIP2ChainId, CAIPAssetId, PaymentRequirements as PaymentRequirements$1, X402SettlementResponse, SettlementResponseV1, SettlementResponseV2, X402PaymentPayload, X402PaymentRequirements, ResolvedPaymentConfig, PricingConfig, AcceptPaymentOptions, NetworkId, TokenId, ValidationError } from '@armory-sh/base';
3
3
  export { AcceptPaymentOptions, NetworkId, PaymentRequirementsV1, PaymentRequirementsV2, SettlementResponseV1, SettlementResponseV2, FacilitatorConfig as SimpleFacilitatorConfig, TokenId } from '@armory-sh/base';
4
4
  import { X402VerifyOptions } from '@armory-sh/facilitator';
5
5
 
@@ -108,24 +108,33 @@ declare const createResponseHeaders: (payerAddress: string, version: PaymentVers
108
108
  interface SimpleMiddlewareConfig {
109
109
  /** Address to receive payments */
110
110
  payTo: Address;
111
- /** Amount to charge (default: "1.0") */
111
+ /** Default amount to charge (default: "1.0") */
112
112
  amount?: string;
113
113
  /** Payment acceptance options */
114
114
  accept?: AcceptPaymentOptions;
115
115
  /** Fallback facilitator URL (if not using accept.facilitators) */
116
116
  facilitatorUrl?: string;
117
+ /** Per-network/token/facilitator pricing overrides */
118
+ pricing?: PricingConfig[];
117
119
  }
118
120
  /**
119
121
  * Resolved middleware configuration with all options validated
120
122
  */
121
123
  interface ResolvedMiddlewareConfig {
122
124
  /** All valid payment configurations (network/token combinations) */
123
- configs: ResolvedPaymentConfig[];
125
+ configs: ResolvedPaymentConfigWithPricing[];
124
126
  /** Protocol version */
125
127
  version: 1 | 2 | "auto";
126
128
  /** Facilitator configs */
127
129
  facilitators: FacilitatorConfig[];
128
130
  }
131
+ /** Extended config with pricing info */
132
+ interface ResolvedPaymentConfigWithPricing extends ResolvedPaymentConfig {
133
+ /** Facilitator URL (for per-facilitator pricing) */
134
+ facilitatorUrl?: string;
135
+ /** Pricing config entry (if any) */
136
+ pricing?: PricingConfig;
137
+ }
129
138
  /**
130
139
  * Resolve simple middleware config to full config
131
140
  */
@@ -135,7 +144,7 @@ declare const resolveMiddlewareConfig: (config: SimpleMiddlewareConfig) => Resol
135
144
  */
136
145
  declare const getRequirements: (config: ResolvedMiddlewareConfig, network: NetworkId, token: TokenId) => PaymentRequirements$1 | ValidationError;
137
146
  /**
138
- * Get the primary/default middleware config for legacy middlewares
147
+ * Get primary/default middleware config for legacy middlewares
139
148
  */
140
149
  declare const getPrimaryConfig: (resolved: ResolvedMiddlewareConfig) => MiddlewareConfig;
141
150
  /**
@@ -191,4 +200,4 @@ declare const acceptPaymentsViaArmory: (config: SimpleMiddlewareConfig & {
191
200
  type PaymentRequirements = _armory_sh_base.PaymentRequirementsV1 | _armory_sh_base.PaymentRequirementsV2;
192
201
  type SettlementResponse = _armory_sh_base.SettlementResponseV1 | _armory_sh_base.SettlementResponseV2;
193
202
 
194
- export { type AnyPaymentPayload, type BunMiddleware, type BunMiddlewareConfig, type FacilitatorConfig, type FacilitatorSettleResult, type FacilitatorVerifyResult, type HttpRequest, type HttpResponse, type LegacyPaymentPayloadV1, type LegacyPaymentPayloadV2, type MiddlewareConfig, type PayToAddress, type AnyPaymentPayload as PaymentPayload, type PaymentRequirements, type PaymentVerificationResult, type PaymentVersion, type ResolvedMiddlewareConfig, type SettlementMode, type SettlementResponse, type SimpleMiddlewareConfig, acceptPaymentsViaArmory, createBunMiddleware, createPaymentRequiredHeaders, createPaymentRequirements, createResponseHeaders, createSettlementHeaders, decodePayload, encodeRequirements, extractPayerAddress, getHeadersForVersion, getPrimaryConfig, getRequirements, getRequirementsVersion, getSupportedNetworks, getSupportedTokens, isSupported, resolveMiddlewareConfig, settleWithFacilitator, verifyPaymentWithRetry, verifyWithFacilitator };
203
+ export { type AnyPaymentPayload, type BunMiddleware, type BunMiddlewareConfig, type FacilitatorConfig, type FacilitatorSettleResult, type FacilitatorVerifyResult, type HttpRequest, type HttpResponse, type LegacyPaymentPayloadV1, type LegacyPaymentPayloadV2, type MiddlewareConfig, type PayToAddress, type AnyPaymentPayload as PaymentPayload, type PaymentRequirements, type PaymentVerificationResult, type PaymentVersion, type ResolvedMiddlewareConfig, type ResolvedPaymentConfigWithPricing, type SettlementMode, type SettlementResponse, type SimpleMiddlewareConfig, acceptPaymentsViaArmory, createBunMiddleware, createPaymentRequiredHeaders, createPaymentRequirements, createResponseHeaders, createSettlementHeaders, decodePayload, encodeRequirements, extractPayerAddress, getHeadersForVersion, getPrimaryConfig, getRequirements, getRequirementsVersion, getSupportedNetworks, getSupportedTokens, isSupported, resolveMiddlewareConfig, settleWithFacilitator, verifyPaymentWithRetry, verifyWithFacilitator };
package/dist/index.js CHANGED
@@ -267,8 +267,24 @@ import {
267
267
  validateAcceptConfig,
268
268
  isValidationError
269
269
  } from "@armory-sh/base";
270
+ var findPricingConfig = (pricing, network, token, facilitatorUrl) => {
271
+ if (!pricing) return void 0;
272
+ const withFacilitator = pricing.find(
273
+ (p) => p.network === network && p.token === token && p.facilitator === facilitatorUrl
274
+ );
275
+ if (withFacilitator) return withFacilitator;
276
+ const withNetworkToken = pricing.find(
277
+ (p) => p.network === network && p.token === token && !p.facilitator
278
+ );
279
+ if (withNetworkToken) return withNetworkToken;
280
+ const networkOnly = pricing.find(
281
+ (p) => p.network === network && !p.token && !p.facilitator
282
+ );
283
+ if (networkOnly) return networkOnly;
284
+ return void 0;
285
+ };
270
286
  var resolveMiddlewareConfig = (config) => {
271
- const { payTo, amount = "1.0", accept = {}, facilitatorUrl } = config;
287
+ const { payTo, amount = "1.0", accept = {}, facilitatorUrl, pricing } = config;
272
288
  const acceptOptions = facilitatorUrl ? {
273
289
  ...accept,
274
290
  facilitators: accept.facilitators ? [...Array.isArray(accept.facilitators) ? accept.facilitators : [accept.facilitators], { url: facilitatorUrl }] : { url: facilitatorUrl }
@@ -281,8 +297,23 @@ var resolveMiddlewareConfig = (config) => {
281
297
  url: f.url,
282
298
  createHeaders: f.input.headers
283
299
  })) ?? [];
300
+ const enrichedConfigs = result.config.map((c) => {
301
+ const networkName = c.network.config.name;
302
+ const tokenSymbol = c.token.config.symbol;
303
+ const facilitatorPricing = c.facilitators.map((f) => {
304
+ const pricingConfig = findPricingConfig(pricing, networkName, tokenSymbol, f.url);
305
+ return { url: f.url, pricing: pricingConfig };
306
+ });
307
+ const defaultPricing = findPricingConfig(pricing, networkName, tokenSymbol, "");
308
+ return {
309
+ ...c,
310
+ amount: defaultPricing?.amount ?? c.amount,
311
+ facilitatorUrl: facilitatorPricing[0]?.url,
312
+ pricing: defaultPricing
313
+ };
314
+ });
284
315
  return {
285
- configs: result.config,
316
+ configs: enrichedConfigs,
286
317
  version: acceptOptions.version ?? "auto",
287
318
  facilitators: facilitatorConfigs
288
319
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@armory-sh/middleware",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "license": "MIT",
5
5
  "author": "Sawyer Cutler <sawyer@dirtroad.dev>",
6
6
  "type": "module",
@@ -12,6 +12,22 @@
12
12
  "bun": "./src/index.ts",
13
13
  "default": "./dist/index.js"
14
14
  },
15
+ "./integrations/hono": {
16
+ "types": "./integrations/hono.ts",
17
+ "default": "./integrations/hono.ts"
18
+ },
19
+ "./integrations/hono-simple": {
20
+ "types": "./integrations/hono-simple.ts",
21
+ "default": "./integrations/hono-simple.ts"
22
+ },
23
+ "./integrations/express": {
24
+ "types": "./integrations/express.ts",
25
+ "default": "./integrations/express.ts"
26
+ },
27
+ "./integrations/elysia": {
28
+ "types": "./integrations/elysia.ts",
29
+ "default": "./integrations/elysia.ts"
30
+ },
15
31
  "./dist/*": "./dist/*.js"
16
32
  },
17
33
  "files": [