@introspectivelabs/nestjs-x402 0.1.0-beta.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/README.md +98 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/payment-discovery.service.d.ts +61 -0
- package/dist/payment-discovery.service.d.ts.map +1 -0
- package/dist/payment-discovery.service.js +125 -0
- package/dist/payment-discovery.service.js.map +1 -0
- package/dist/payment-registry.service.d.ts +40 -0
- package/dist/payment-registry.service.d.ts.map +1 -0
- package/dist/payment-registry.service.js +70 -0
- package/dist/payment-registry.service.js.map +1 -0
- package/dist/payment.decorator.d.ts +20 -0
- package/dist/payment.decorator.d.ts.map +1 -0
- package/dist/payment.decorator.js +17 -0
- package/dist/payment.decorator.js.map +1 -0
- package/dist/payment.interceptor.d.ts +39 -0
- package/dist/payment.interceptor.d.ts.map +1 -0
- package/dist/payment.interceptor.js +102 -0
- package/dist/payment.interceptor.js.map +1 -0
- package/dist/x402.module-definition.d.ts +22 -0
- package/dist/x402.module-definition.d.ts.map +1 -0
- package/dist/x402.module-definition.js +15 -0
- package/dist/x402.module-definition.js.map +1 -0
- package/dist/x402.module.d.ts +23 -0
- package/dist/x402.module.d.ts.map +1 -0
- package/dist/x402.module.js +116 -0
- package/dist/x402.module.js.map +1 -0
- package/package.json +70 -0
package/README.md
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# @introspectivelabs/nestjs-x402
|
|
2
|
+
|
|
3
|
+
x402 Payment Protocol NestJS integration with `@Payment()` decorator support and ERC-4337 UserOperation handling.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @introspectivelabs/nestjs-x402
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
### Peer Dependencies
|
|
12
|
+
|
|
13
|
+
- `@introspectivelabs/x402-evm` >= 0.1.0-beta.1
|
|
14
|
+
- `@nestjs/common` >= 10.0.0
|
|
15
|
+
- `@nestjs/config` >= 3.0.0
|
|
16
|
+
- `@nestjs/core` >= 10.0.0
|
|
17
|
+
- `@x402/core` 2.*
|
|
18
|
+
- `@x402/express` 2.*
|
|
19
|
+
- `rxjs` >= 7.0.0
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
### Module Setup
|
|
24
|
+
|
|
25
|
+
Register the module in your app with `forRoot` or `forRootAsync`:
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { X402Module } from "@introspectivelabs/nestjs-x402";
|
|
29
|
+
|
|
30
|
+
@Module({
|
|
31
|
+
imports: [
|
|
32
|
+
X402Module.forRoot({
|
|
33
|
+
facilitatorUrl: "https://facilitator.example.com",
|
|
34
|
+
seller: {
|
|
35
|
+
address: "0xYourSellerAddress",
|
|
36
|
+
defaultConfig: {
|
|
37
|
+
network: "eip155:84532",
|
|
38
|
+
price: "$0.01",
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
}),
|
|
42
|
+
],
|
|
43
|
+
})
|
|
44
|
+
export class AppModule {}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Or with async configuration:
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
X402Module.forRootAsync({
|
|
51
|
+
imports: [ConfigModule],
|
|
52
|
+
useFactory: (config: ConfigService) => ({
|
|
53
|
+
facilitatorUrl: config.get("FACILITATOR_URL"),
|
|
54
|
+
seller: {
|
|
55
|
+
address: config.get("SELLER_ADDRESS"),
|
|
56
|
+
defaultConfig: {
|
|
57
|
+
network: config.get("NETWORK"),
|
|
58
|
+
price: config.get("PRICE"),
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
}),
|
|
62
|
+
inject: [ConfigService],
|
|
63
|
+
});
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### @Payment() Decorator
|
|
67
|
+
|
|
68
|
+
Protect any route with the `@Payment()` decorator:
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
import { Controller, Get } from "@nestjs/common";
|
|
72
|
+
import { Payment } from "@introspectivelabs/nestjs-x402";
|
|
73
|
+
|
|
74
|
+
@Controller("api")
|
|
75
|
+
export class ApiController {
|
|
76
|
+
@Get("premium")
|
|
77
|
+
@Payment({
|
|
78
|
+
accepts: {
|
|
79
|
+
price: "$0.05",
|
|
80
|
+
network: "eip155:84532",
|
|
81
|
+
},
|
|
82
|
+
})
|
|
83
|
+
getPremiumData() {
|
|
84
|
+
return { data: "premium content" };
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### How It Works
|
|
90
|
+
|
|
91
|
+
1. `X402Module` registers a global interceptor that processes x402 payment headers.
|
|
92
|
+
2. `PaymentDiscoveryService` scans all controllers on startup and finds `@Payment()` decorated routes.
|
|
93
|
+
3. `PaymentRegistryService` stores payment configurations and merges seller defaults.
|
|
94
|
+
4. `PaymentInterceptor` intercepts requests to payment-protected routes and validates x402 UserOperation payments via the facilitator.
|
|
95
|
+
|
|
96
|
+
## License
|
|
97
|
+
|
|
98
|
+
Apache-2.0
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { X402Module, X402ModuleOptions, X402_MODULE_OPTIONS } from "./x402.module";
|
|
2
|
+
export { OPTIONS_TYPE, ASYNC_OPTIONS_TYPE } from "./x402.module-definition";
|
|
3
|
+
export { Payment, PaymentConfig, PaymentOption, PAYMENT_CONFIG_KEY } from "./payment.decorator";
|
|
4
|
+
export { PaymentInterceptor, PaymentInterceptorConfig } from "./payment.interceptor";
|
|
5
|
+
export { PaymentRegistryService, X402SellerConfig } from "./payment-registry.service";
|
|
6
|
+
export { PaymentDiscoveryService } from "./payment-discovery.service";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACnF,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC5E,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAChG,OAAO,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AACrF,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AACtF,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PaymentDiscoveryService = exports.PaymentRegistryService = exports.PaymentInterceptor = exports.PAYMENT_CONFIG_KEY = exports.Payment = exports.ASYNC_OPTIONS_TYPE = exports.OPTIONS_TYPE = exports.X402_MODULE_OPTIONS = exports.X402Module = void 0;
|
|
4
|
+
var x402_module_1 = require("./x402.module");
|
|
5
|
+
Object.defineProperty(exports, "X402Module", { enumerable: true, get: function () { return x402_module_1.X402Module; } });
|
|
6
|
+
Object.defineProperty(exports, "X402_MODULE_OPTIONS", { enumerable: true, get: function () { return x402_module_1.X402_MODULE_OPTIONS; } });
|
|
7
|
+
var x402_module_definition_1 = require("./x402.module-definition");
|
|
8
|
+
Object.defineProperty(exports, "OPTIONS_TYPE", { enumerable: true, get: function () { return x402_module_definition_1.OPTIONS_TYPE; } });
|
|
9
|
+
Object.defineProperty(exports, "ASYNC_OPTIONS_TYPE", { enumerable: true, get: function () { return x402_module_definition_1.ASYNC_OPTIONS_TYPE; } });
|
|
10
|
+
var payment_decorator_1 = require("./payment.decorator");
|
|
11
|
+
Object.defineProperty(exports, "Payment", { enumerable: true, get: function () { return payment_decorator_1.Payment; } });
|
|
12
|
+
Object.defineProperty(exports, "PAYMENT_CONFIG_KEY", { enumerable: true, get: function () { return payment_decorator_1.PAYMENT_CONFIG_KEY; } });
|
|
13
|
+
var payment_interceptor_1 = require("./payment.interceptor");
|
|
14
|
+
Object.defineProperty(exports, "PaymentInterceptor", { enumerable: true, get: function () { return payment_interceptor_1.PaymentInterceptor; } });
|
|
15
|
+
var payment_registry_service_1 = require("./payment-registry.service");
|
|
16
|
+
Object.defineProperty(exports, "PaymentRegistryService", { enumerable: true, get: function () { return payment_registry_service_1.PaymentRegistryService; } });
|
|
17
|
+
var payment_discovery_service_1 = require("./payment-discovery.service");
|
|
18
|
+
Object.defineProperty(exports, "PaymentDiscoveryService", { enumerable: true, get: function () { return payment_discovery_service_1.PaymentDiscoveryService; } });
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,6CAAmF;AAA1E,yGAAA,UAAU,OAAA;AAAqB,kHAAA,mBAAmB,OAAA;AAC3D,mEAA4E;AAAnE,sHAAA,YAAY,OAAA;AAAE,4HAAA,kBAAkB,OAAA;AACzC,yDAAgG;AAAvF,4GAAA,OAAO,OAAA;AAAgC,uHAAA,kBAAkB,OAAA;AAClE,6DAAqF;AAA5E,yHAAA,kBAAkB,OAAA;AAC3B,uEAAsF;AAA7E,kIAAA,sBAAsB,OAAA;AAC/B,yEAAsE;AAA7D,oIAAA,uBAAuB,OAAA"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { OnModuleInit } from "@nestjs/common";
|
|
2
|
+
import { DiscoveryService, MetadataScanner, Reflector } from "@nestjs/core";
|
|
3
|
+
import { PaymentRegistryService } from "./payment-registry.service";
|
|
4
|
+
/**
|
|
5
|
+
* Service that auto-discovers @Payment() decorated routes on module initialization.
|
|
6
|
+
*/
|
|
7
|
+
export declare class PaymentDiscoveryService implements OnModuleInit {
|
|
8
|
+
private readonly discoveryService;
|
|
9
|
+
private readonly metadataScanner;
|
|
10
|
+
private readonly reflector;
|
|
11
|
+
private readonly paymentRegistry;
|
|
12
|
+
/**
|
|
13
|
+
* Creates the discovery service with required NestJS internals.
|
|
14
|
+
*
|
|
15
|
+
* @param discoveryService - NestJS provider discovery service
|
|
16
|
+
* @param metadataScanner - NestJS metadata scanner
|
|
17
|
+
* @param reflector - NestJS reflector for reading metadata
|
|
18
|
+
* @param paymentRegistry - payment registry to register discovered routes
|
|
19
|
+
*/
|
|
20
|
+
constructor(discoveryService: DiscoveryService, metadataScanner: MetadataScanner, reflector: Reflector, paymentRegistry: PaymentRegistryService);
|
|
21
|
+
/**
|
|
22
|
+
* Lifecycle hook that triggers route discovery on module init.
|
|
23
|
+
*/
|
|
24
|
+
onModuleInit(): void;
|
|
25
|
+
/**
|
|
26
|
+
* Scans all controllers and registers payment-decorated routes.
|
|
27
|
+
*/
|
|
28
|
+
private discoverPaymentConfigs;
|
|
29
|
+
/**
|
|
30
|
+
* Extract the controller base path from metadata.
|
|
31
|
+
*
|
|
32
|
+
* @param metatype - the controller class
|
|
33
|
+
* @returns the controller path string
|
|
34
|
+
*/
|
|
35
|
+
private getControllerPath;
|
|
36
|
+
/**
|
|
37
|
+
* Extract the route path from a handler method's metadata.
|
|
38
|
+
*
|
|
39
|
+
* @param instance - the controller instance
|
|
40
|
+
* @param methodName - the handler method name
|
|
41
|
+
* @returns the route path or null
|
|
42
|
+
*/
|
|
43
|
+
private getRoutePath;
|
|
44
|
+
/**
|
|
45
|
+
* Extract the HTTP method from a handler method's metadata.
|
|
46
|
+
*
|
|
47
|
+
* @param instance - the controller instance
|
|
48
|
+
* @param methodName - the handler method name
|
|
49
|
+
* @returns the HTTP method string
|
|
50
|
+
*/
|
|
51
|
+
private getHttpMethod;
|
|
52
|
+
/**
|
|
53
|
+
* Combine a controller path and route path into a full path.
|
|
54
|
+
*
|
|
55
|
+
* @param controllerPath - the controller base path
|
|
56
|
+
* @param routePath - the route method path
|
|
57
|
+
* @returns the combined full path
|
|
58
|
+
*/
|
|
59
|
+
private combinePaths;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=payment-discovery.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment-discovery.service.d.ts","sourceRoot":"","sources":["../src/payment-discovery.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,YAAY,EAAuB,MAAM,gBAAgB,CAAC;AAC/E,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE5E,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAIpE;;GAEG;AACH,qBACa,uBAAwB,YAAW,YAAY;IAUxD,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IACjC,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,eAAe;IAZlC;;;;;;;OAOG;gBAEgB,gBAAgB,EAAE,gBAAgB,EAClC,eAAe,EAAE,eAAe,EAChC,SAAS,EAAE,SAAS,EACpB,eAAe,EAAE,sBAAsB;IAG1D;;OAEG;IACH,YAAY;IAIZ;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAwB9B;;;;;OAKG;IACH,OAAO,CAAC,iBAAiB;IAIzB;;;;;;OAMG;IACH,OAAO,CAAC,YAAY;IAKpB;;;;;;OAMG;IACH,OAAO,CAAC,aAAa;IAOrB;;;;;;OAMG;IACH,OAAO,CAAC,YAAY;CAUrB"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.PaymentDiscoveryService = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const core_1 = require("@nestjs/core");
|
|
15
|
+
const payment_decorator_1 = require("./payment.decorator");
|
|
16
|
+
const payment_registry_service_1 = require("./payment-registry.service");
|
|
17
|
+
const constants_1 = require("@nestjs/common/constants");
|
|
18
|
+
/**
|
|
19
|
+
* Service that auto-discovers @Payment() decorated routes on module initialization.
|
|
20
|
+
*/
|
|
21
|
+
let PaymentDiscoveryService = class PaymentDiscoveryService {
|
|
22
|
+
/**
|
|
23
|
+
* Creates the discovery service with required NestJS internals.
|
|
24
|
+
*
|
|
25
|
+
* @param discoveryService - NestJS provider discovery service
|
|
26
|
+
* @param metadataScanner - NestJS metadata scanner
|
|
27
|
+
* @param reflector - NestJS reflector for reading metadata
|
|
28
|
+
* @param paymentRegistry - payment registry to register discovered routes
|
|
29
|
+
*/
|
|
30
|
+
constructor(discoveryService, metadataScanner, reflector, paymentRegistry) {
|
|
31
|
+
this.discoveryService = discoveryService;
|
|
32
|
+
this.metadataScanner = metadataScanner;
|
|
33
|
+
this.reflector = reflector;
|
|
34
|
+
this.paymentRegistry = paymentRegistry;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Lifecycle hook that triggers route discovery on module init.
|
|
38
|
+
*/
|
|
39
|
+
onModuleInit() {
|
|
40
|
+
this.discoverPaymentConfigs();
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Scans all controllers and registers payment-decorated routes.
|
|
44
|
+
*/
|
|
45
|
+
discoverPaymentConfigs() {
|
|
46
|
+
const controllers = this.discoveryService.getControllers();
|
|
47
|
+
controllers.forEach(wrapper => {
|
|
48
|
+
const { instance, metatype } = wrapper;
|
|
49
|
+
const controllerPath = this.getControllerPath(metatype);
|
|
50
|
+
const methodNames = this.metadataScanner.getAllMethodNames(instance);
|
|
51
|
+
methodNames.forEach(methodName => {
|
|
52
|
+
const method = instance[methodName];
|
|
53
|
+
const paymentConfig = this.reflector.get(payment_decorator_1.PAYMENT_CONFIG_KEY, method);
|
|
54
|
+
if (paymentConfig) {
|
|
55
|
+
const routePath = this.getRoutePath(instance, methodName);
|
|
56
|
+
const httpMethod = this.getHttpMethod(instance, methodName);
|
|
57
|
+
if (httpMethod && routePath !== null) {
|
|
58
|
+
const fullPath = this.combinePaths(controllerPath, routePath);
|
|
59
|
+
this.paymentRegistry.registerRoute(httpMethod, fullPath, paymentConfig);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Extract the controller base path from metadata.
|
|
67
|
+
*
|
|
68
|
+
* @param metatype - the controller class
|
|
69
|
+
* @returns the controller path string
|
|
70
|
+
*/
|
|
71
|
+
getControllerPath(metatype) {
|
|
72
|
+
return this.reflector.get(constants_1.PATH_METADATA, metatype) || "";
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Extract the route path from a handler method's metadata.
|
|
76
|
+
*
|
|
77
|
+
* @param instance - the controller instance
|
|
78
|
+
* @param methodName - the handler method name
|
|
79
|
+
* @returns the route path or null
|
|
80
|
+
*/
|
|
81
|
+
getRoutePath(instance, methodName) {
|
|
82
|
+
const method = instance[methodName];
|
|
83
|
+
return this.reflector.get(constants_1.PATH_METADATA, method) || "";
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Extract the HTTP method from a handler method's metadata.
|
|
87
|
+
*
|
|
88
|
+
* @param instance - the controller instance
|
|
89
|
+
* @param methodName - the handler method name
|
|
90
|
+
* @returns the HTTP method string
|
|
91
|
+
*/
|
|
92
|
+
getHttpMethod(instance, methodName) {
|
|
93
|
+
const method = instance[methodName];
|
|
94
|
+
const metadata = this.reflector.get(constants_1.METHOD_METADATA, method);
|
|
95
|
+
const httpMethod = common_1.RequestMethod[metadata];
|
|
96
|
+
return httpMethod?.toString() || common_1.RequestMethod.GET.toString();
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Combine a controller path and route path into a full path.
|
|
100
|
+
*
|
|
101
|
+
* @param controllerPath - the controller base path
|
|
102
|
+
* @param routePath - the route method path
|
|
103
|
+
* @returns the combined full path
|
|
104
|
+
*/
|
|
105
|
+
combinePaths(controllerPath, routePath) {
|
|
106
|
+
const controller = controllerPath.startsWith("/") ? controllerPath : `/${controllerPath}`;
|
|
107
|
+
const route = routePath.startsWith("/") ? routePath : `/${routePath}`;
|
|
108
|
+
if (controller === "/" && route === "/")
|
|
109
|
+
return "/";
|
|
110
|
+
if (controller === "/")
|
|
111
|
+
return route;
|
|
112
|
+
if (route === "/")
|
|
113
|
+
return controller;
|
|
114
|
+
return `${controller}${route}`;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
exports.PaymentDiscoveryService = PaymentDiscoveryService;
|
|
118
|
+
exports.PaymentDiscoveryService = PaymentDiscoveryService = __decorate([
|
|
119
|
+
(0, common_1.Injectable)(),
|
|
120
|
+
__metadata("design:paramtypes", [core_1.DiscoveryService,
|
|
121
|
+
core_1.MetadataScanner,
|
|
122
|
+
core_1.Reflector,
|
|
123
|
+
payment_registry_service_1.PaymentRegistryService])
|
|
124
|
+
], PaymentDiscoveryService);
|
|
125
|
+
//# sourceMappingURL=payment-discovery.service.js.map
|
|
@@ -0,0 +1 @@
|
|
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CAAC,IAAI,cAAc,EAAE,CAAC;QAC1F,MAAM,KAAK,GAAG,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,SAAS,EAAE,CAAC;QAEtE,IAAI,UAAU,KAAK,GAAG,IAAI,KAAK,KAAK,GAAG;YAAE,OAAO,GAAG,CAAC;QACpD,IAAI,UAAU,KAAK,GAAG;YAAE,OAAO,KAAK,CAAC;QACrC,IAAI,KAAK,KAAK,GAAG;YAAE,OAAO,UAAU,CAAC;QAErC,OAAO,GAAG,UAAU,GAAG,KAAK,EAAE,CAAC;IACjC,CAAC;CACF,CAAA;AAvGY,0DAAuB;kCAAvB,uBAAuB;IADnC,IAAA,mBAAU,GAAE;qCAW0B,uBAAgB;QACjB,sBAAe;QACrB,gBAAS;QACH,iDAAsB;GAb/C,uBAAuB,CAuGnC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { RouteConfig, PaymentOption } from "@x402/core/http";
|
|
2
|
+
export interface X402SellerConfig {
|
|
3
|
+
defaultConfig: Partial<PaymentOption>;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Service that stores and retrieves x402 payment route configurations.
|
|
7
|
+
*/
|
|
8
|
+
export declare class PaymentRegistryService {
|
|
9
|
+
private paymentConfigs;
|
|
10
|
+
private sellerConfig?;
|
|
11
|
+
/**
|
|
12
|
+
* Set the global seller configuration for default payment options.
|
|
13
|
+
*
|
|
14
|
+
* @param config - seller configuration with default payment options
|
|
15
|
+
*/
|
|
16
|
+
setSellerConfig(config: X402SellerConfig): void;
|
|
17
|
+
/**
|
|
18
|
+
* Register a route with its payment configuration.
|
|
19
|
+
*
|
|
20
|
+
* @param method - HTTP method
|
|
21
|
+
* @param path - route path
|
|
22
|
+
* @param config - payment route configuration
|
|
23
|
+
*/
|
|
24
|
+
registerRoute(method: string, path: string, config: RouteConfig): void;
|
|
25
|
+
/**
|
|
26
|
+
* Get the payment configuration for a specific route.
|
|
27
|
+
*
|
|
28
|
+
* @param method - HTTP method
|
|
29
|
+
* @param path - route path
|
|
30
|
+
* @returns the route config or undefined if not found
|
|
31
|
+
*/
|
|
32
|
+
getPaymentConfig(method: string, path: string): RouteConfig | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Get all registered payment configurations.
|
|
35
|
+
*
|
|
36
|
+
* @returns record of all route configs keyed by "METHOD path"
|
|
37
|
+
*/
|
|
38
|
+
getAllConfigs(): Record<string, RouteConfig>;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=payment-registry.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment-registry.service.d.ts","sourceRoot":"","sources":["../src/payment-registry.service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAElE,MAAM,WAAW,gBAAgB;IAC/B,aAAa,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;CACvC;AAED;;GAEG;AACH,qBACa,sBAAsB;IACjC,OAAO,CAAC,cAAc,CAAkC;IACxD,OAAO,CAAC,YAAY,CAAC,CAAmB;IAExC;;;;OAIG;IACH,eAAe,CAAC,MAAM,EAAE,gBAAgB;IAIxC;;;;;;OAMG;IACH,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW;IAa/D;;;;;;OAMG;IACH,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS;IAKvE;;;;OAIG;IACH,aAAa,IAAI,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC;CAK7C"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.PaymentRegistryService = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
/**
|
|
12
|
+
* Service that stores and retrieves x402 payment route configurations.
|
|
13
|
+
*/
|
|
14
|
+
let PaymentRegistryService = class PaymentRegistryService {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.paymentConfigs = new Map();
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Set the global seller configuration for default payment options.
|
|
20
|
+
*
|
|
21
|
+
* @param config - seller configuration with default payment options
|
|
22
|
+
*/
|
|
23
|
+
setSellerConfig(config) {
|
|
24
|
+
this.sellerConfig = config;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Register a route with its payment configuration.
|
|
28
|
+
*
|
|
29
|
+
* @param method - HTTP method
|
|
30
|
+
* @param path - route path
|
|
31
|
+
* @param config - payment route configuration
|
|
32
|
+
*/
|
|
33
|
+
registerRoute(method, path, config) {
|
|
34
|
+
const routeKey = `${method.toUpperCase()} ${path}`;
|
|
35
|
+
const defaultAccepts = this.sellerConfig?.defaultConfig;
|
|
36
|
+
this.paymentConfigs.set(routeKey, {
|
|
37
|
+
...config,
|
|
38
|
+
accepts: {
|
|
39
|
+
...defaultAccepts,
|
|
40
|
+
...config.accepts,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Get the payment configuration for a specific route.
|
|
46
|
+
*
|
|
47
|
+
* @param method - HTTP method
|
|
48
|
+
* @param path - route path
|
|
49
|
+
* @returns the route config or undefined if not found
|
|
50
|
+
*/
|
|
51
|
+
getPaymentConfig(method, path) {
|
|
52
|
+
const routeKey = `${method.toUpperCase()} ${path}`;
|
|
53
|
+
return this.paymentConfigs.get(routeKey);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Get all registered payment configurations.
|
|
57
|
+
*
|
|
58
|
+
* @returns record of all route configs keyed by "METHOD path"
|
|
59
|
+
*/
|
|
60
|
+
getAllConfigs() {
|
|
61
|
+
const configs = {};
|
|
62
|
+
this.paymentConfigs.forEach((config, route) => (configs[route] = config));
|
|
63
|
+
return configs;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
exports.PaymentRegistryService = PaymentRegistryService;
|
|
67
|
+
exports.PaymentRegistryService = PaymentRegistryService = __decorate([
|
|
68
|
+
(0, common_1.Injectable)()
|
|
69
|
+
], PaymentRegistryService);
|
|
70
|
+
//# sourceMappingURL=payment-registry.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment-registry.service.js","sourceRoot":"","sources":["../src/payment-registry.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAO5C;;GAEG;AAEI,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;IAA5B;QACG,mBAAc,GAAG,IAAI,GAAG,EAAuB,CAAC;IAsD1D,CAAC;IAnDC;;;;OAIG;IACH,eAAe,CAAC,MAAwB;QACtC,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC;IAC7B,CAAC;IAED;;;;;;OAMG;IACH,aAAa,CAAC,MAAc,EAAE,IAAY,EAAE,MAAmB;QAC7D,MAAM,QAAQ,GAAG,GAAG,MAAM,CAAC,WAAW,EAAE,IAAI,IAAI,EAAE,CAAC;QACnD,MAAM,cAAc,GAAG,IAAI,CAAC,YAAY,EAAE,aAAa,CAAC;QAExD,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,QAAQ,EAAE;YAChC,GAAG,MAAM;YACT,OAAO,EAAE;gBACP,GAAG,cAAc;gBACjB,GAAG,MAAM,CAAC,OAAO;aACD;SACnB,CAAC,CAAC;IACL,CAAC;IAED;;;;;;OAMG;IACH,gBAAgB,CAAC,MAAc,EAAE,IAAY;QAC3C,MAAM,QAAQ,GAAG,GAAG,MAAM,CAAC,WAAW,EAAE,IAAI,IAAI,EAAE,CAAC;QACnD,OAAO,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC3C,CAAC;IAED;;;;OAIG;IACH,aAAa;QACX,MAAM,OAAO,GAAgC,EAAE,CAAC;QAChD,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC;QAC1E,OAAO,OAAO,CAAC;IACjB,CAAC;CACF,CAAA;AAvDY,wDAAsB;iCAAtB,sBAAsB;IADlC,IAAA,mBAAU,GAAE;GACA,sBAAsB,CAuDlC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { RouteConfig } from "@x402/core/http";
|
|
2
|
+
import type { Network, Price } from "@x402/core/types";
|
|
3
|
+
import type { PaymentOption as X402PaymentOption } from "@x402/core/http";
|
|
4
|
+
export interface PaymentOption extends Partial<X402PaymentOption> {
|
|
5
|
+
price?: Price;
|
|
6
|
+
network?: Network;
|
|
7
|
+
payTo?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface PaymentConfig extends Partial<Omit<RouteConfig, "accepts">> {
|
|
10
|
+
accepts?: PaymentOption | PaymentOption[];
|
|
11
|
+
}
|
|
12
|
+
export declare const PAYMENT_CONFIG_KEY = "payment_config";
|
|
13
|
+
/**
|
|
14
|
+
* Decorator that marks a route as x402 payment-protected.
|
|
15
|
+
*
|
|
16
|
+
* @param config - payment configuration for the route
|
|
17
|
+
* @returns a method decorator
|
|
18
|
+
*/
|
|
19
|
+
export declare const Payment: (config?: PaymentConfig) => import("@nestjs/common").CustomDecorator<string>;
|
|
20
|
+
//# sourceMappingURL=payment.decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment.decorator.d.ts","sourceRoot":"","sources":["../src/payment.decorator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAE,aAAa,IAAI,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAE1E,MAAM,WAAW,aAAc,SAAQ,OAAO,CAAC,iBAAiB,CAAC;IAC/D,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,aAAc,SAAQ,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;IAC1E,OAAO,CAAC,EAAE,aAAa,GAAG,aAAa,EAAE,CAAC;CAC3C;AAED,eAAO,MAAM,kBAAkB,mBAAmB,CAAC;AAEnD;;;;;GAKG;AACH,eAAO,MAAM,OAAO,GAAI,SAAQ,aAAkB,qDAI9C,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Payment = exports.PAYMENT_CONFIG_KEY = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
exports.PAYMENT_CONFIG_KEY = "payment_config";
|
|
6
|
+
/**
|
|
7
|
+
* Decorator that marks a route as x402 payment-protected.
|
|
8
|
+
*
|
|
9
|
+
* @param config - payment configuration for the route
|
|
10
|
+
* @returns a method decorator
|
|
11
|
+
*/
|
|
12
|
+
const Payment = (config = {}) => (0, common_1.SetMetadata)(exports.PAYMENT_CONFIG_KEY, {
|
|
13
|
+
mimeType: "application/json",
|
|
14
|
+
...config,
|
|
15
|
+
});
|
|
16
|
+
exports.Payment = Payment;
|
|
17
|
+
//# sourceMappingURL=payment.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment.decorator.js","sourceRoot":"","sources":["../src/payment.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAehC,QAAA,kBAAkB,GAAG,gBAAgB,CAAC;AAEnD;;;;;GAKG;AACI,MAAM,OAAO,GAAG,CAAC,SAAwB,EAAE,EAAE,EAAE,CACpD,IAAA,oBAAW,EAAC,0BAAkB,EAAE;IAC9B,QAAQ,EAAE,kBAAkB;IAC5B,GAAG,MAAM;CACV,CAAC,CAAC;AAJQ,QAAA,OAAO,WAIf"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { NestInterceptor, ExecutionContext, CallHandler } from "@nestjs/common";
|
|
2
|
+
import { Observable } from "rxjs";
|
|
3
|
+
import { PaymentRegistryService } from "./payment-registry.service";
|
|
4
|
+
import type { Network } from "@x402/core/types";
|
|
5
|
+
export interface PaymentInterceptorConfig {
|
|
6
|
+
facilitatorUrl: string;
|
|
7
|
+
defaultNetwork?: Network;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* NestJS interceptor that validates x402 payment headers on protected routes.
|
|
11
|
+
*/
|
|
12
|
+
export declare class PaymentInterceptor implements NestInterceptor {
|
|
13
|
+
private readonly paymentRegistry;
|
|
14
|
+
private facilitatorClient;
|
|
15
|
+
private resourceServer;
|
|
16
|
+
private schemeServer;
|
|
17
|
+
private initialized;
|
|
18
|
+
/**
|
|
19
|
+
* Creates the interceptor with the payment registry.
|
|
20
|
+
*
|
|
21
|
+
* @param paymentRegistry - registry of payment-protected routes
|
|
22
|
+
*/
|
|
23
|
+
constructor(paymentRegistry: PaymentRegistryService);
|
|
24
|
+
/**
|
|
25
|
+
* Initialize the interceptor with facilitator and scheme server clients.
|
|
26
|
+
*
|
|
27
|
+
* @param config - facilitator URL and default network configuration
|
|
28
|
+
*/
|
|
29
|
+
initialize(config: PaymentInterceptorConfig): void;
|
|
30
|
+
/**
|
|
31
|
+
* Intercept requests and validate x402 payment if the route is protected.
|
|
32
|
+
*
|
|
33
|
+
* @param context - NestJS execution context
|
|
34
|
+
* @param next - call handler to proceed to the route handler
|
|
35
|
+
* @returns observable of the response
|
|
36
|
+
*/
|
|
37
|
+
intercept(context: ExecutionContext, next: CallHandler): Observable<unknown>;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=payment.interceptor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment.interceptor.d.ts","sourceRoot":"","sources":["../src/payment.interceptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,eAAe,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC5F,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAElC,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAQpE,OAAO,KAAK,EAAE,OAAO,EAAuB,MAAM,kBAAkB,CAAC;AAErE,MAAM,WAAW,wBAAwB;IACvC,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED;;GAEG;AACH,qBACa,kBAAmB,YAAW,eAAe;IAW5C,OAAO,CAAC,QAAQ,CAAC,eAAe;IAV5C,OAAO,CAAC,iBAAiB,CAAqB;IAC9C,OAAO,CAAC,cAAc,CAAsB;IAC5C,OAAO,CAAC,YAAY,CAA+B;IACnD,OAAO,CAAC,WAAW,CAAS;IAE5B;;;;OAIG;gBAC0B,eAAe,EAAE,sBAAsB;IAEpE;;;;OAIG;IACH,UAAU,CAAC,MAAM,EAAE,wBAAwB;IAqB3C;;;;;;OAMG;IACH,SAAS,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW,GAAG,UAAU,CAAC,OAAO,CAAC;CA6C7E"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.PaymentInterceptor = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const rxjs_1 = require("rxjs");
|
|
15
|
+
const payment_registry_service_1 = require("./payment-registry.service");
|
|
16
|
+
const express_1 = require("@x402/express");
|
|
17
|
+
const x402_evm_1 = require("@introspectivelabs/x402-evm");
|
|
18
|
+
/**
|
|
19
|
+
* NestJS interceptor that validates x402 payment headers on protected routes.
|
|
20
|
+
*/
|
|
21
|
+
let PaymentInterceptor = class PaymentInterceptor {
|
|
22
|
+
/**
|
|
23
|
+
* Creates the interceptor with the payment registry.
|
|
24
|
+
*
|
|
25
|
+
* @param paymentRegistry - registry of payment-protected routes
|
|
26
|
+
*/
|
|
27
|
+
constructor(paymentRegistry) {
|
|
28
|
+
this.paymentRegistry = paymentRegistry;
|
|
29
|
+
this.initialized = false;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Initialize the interceptor with facilitator and scheme server clients.
|
|
33
|
+
*
|
|
34
|
+
* @param config - facilitator URL and default network configuration
|
|
35
|
+
*/
|
|
36
|
+
initialize(config) {
|
|
37
|
+
if (this.initialized)
|
|
38
|
+
return;
|
|
39
|
+
const { HTTPFacilitatorClient: HTTPFacClient } =
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
41
|
+
require("@x402/core/http");
|
|
42
|
+
this.facilitatorClient = new HTTPFacClient({
|
|
43
|
+
url: config.facilitatorUrl,
|
|
44
|
+
});
|
|
45
|
+
this.resourceServer = new express_1.x402ResourceServer(this.facilitatorClient);
|
|
46
|
+
this.schemeServer = new x402_evm_1.ExactEvmSchemeERC4337Server();
|
|
47
|
+
const defaultNetwork = config.defaultNetwork || "eip155:84532";
|
|
48
|
+
this.resourceServer.register(defaultNetwork, this.schemeServer);
|
|
49
|
+
this.initialized = true;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Intercept requests and validate x402 payment if the route is protected.
|
|
53
|
+
*
|
|
54
|
+
* @param context - NestJS execution context
|
|
55
|
+
* @param next - call handler to proceed to the route handler
|
|
56
|
+
* @returns observable of the response
|
|
57
|
+
*/
|
|
58
|
+
intercept(context, next) {
|
|
59
|
+
if (!this.initialized) {
|
|
60
|
+
return next.handle();
|
|
61
|
+
}
|
|
62
|
+
const ctx = context.switchToHttp();
|
|
63
|
+
const request = ctx.getRequest();
|
|
64
|
+
const response = ctx.getResponse();
|
|
65
|
+
const method = request.method;
|
|
66
|
+
const path = request.route?.path || request.path;
|
|
67
|
+
const paymentConfig = this.paymentRegistry.getPaymentConfig(method, path);
|
|
68
|
+
if (!paymentConfig) {
|
|
69
|
+
return next.handle();
|
|
70
|
+
}
|
|
71
|
+
return new rxjs_1.Observable(observer => {
|
|
72
|
+
(0, x402_evm_1.transformRouteForUserOperation)(paymentConfig, this.schemeServer)
|
|
73
|
+
.then(config => {
|
|
74
|
+
const middleware = (0, express_1.paymentMiddleware)(config, this.resourceServer);
|
|
75
|
+
void middleware(request, response, (error) => {
|
|
76
|
+
if (error) {
|
|
77
|
+
observer.error(error);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (response.headersSent) {
|
|
81
|
+
observer.complete();
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
next.handle().subscribe({
|
|
85
|
+
next: value => observer.next(value),
|
|
86
|
+
error: err => observer.error(err),
|
|
87
|
+
complete: () => observer.complete(),
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
})
|
|
91
|
+
.catch(error => {
|
|
92
|
+
observer.error(error);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
exports.PaymentInterceptor = PaymentInterceptor;
|
|
98
|
+
exports.PaymentInterceptor = PaymentInterceptor = __decorate([
|
|
99
|
+
(0, common_1.Injectable)(),
|
|
100
|
+
__metadata("design:paramtypes", [payment_registry_service_1.PaymentRegistryService])
|
|
101
|
+
], PaymentInterceptor);
|
|
102
|
+
//# sourceMappingURL=payment.interceptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment.interceptor.js","sourceRoot":"","sources":["../src/payment.interceptor.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4F;AAC5F,+BAAkC;AAElC,yEAAoE;AACpE,2CAAsE;AAGtE,0DAGqC;AAQrC;;GAEG;AAEI,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAM7B;;;;OAIG;IACH,YAA6B,eAAuC;QAAvC,oBAAe,GAAf,eAAe,CAAwB;QAP5D,gBAAW,GAAG,KAAK,CAAC;IAO2C,CAAC;IAExE;;;;OAIG;IACH,UAAU,CAAC,MAAgC;QACzC,IAAI,IAAI,CAAC,WAAW;YAAE,OAAO;QAE7B,MAAM,EAAE,qBAAqB,EAAE,aAAa,EAAE;QAC5C,iEAAiE;QACjE,OAAO,CAAC,iBAAiB,CAExB,CAAC;QAEJ,IAAI,CAAC,iBAAiB,GAAG,IAAI,aAAa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iB,EAAC,MAAsB,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;gBAElF,KAAK,UAAU,CAAC,OAAO,EAAE,QAAQ,EAAE,CAAC,KAAe,EAAE,EAAE;oBACrD,IAAI,KAAK,EAAE,CAAC;wBACV,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;wBACtB,OAAO;oBACT,CAAC;oBAED,IAAI,QAAQ,CAAC,WAAW,EAAE,CAAC;wBACzB,QAAQ,CAAC,QAAQ,EAAE,CAAC;wBACpB,OAAO;oBACT,CAAC;oBAED,IAAI,CAAC,MAAM,EAAE,CAAC,SAAS,CAAC;wBACtB,IAAI,EAAE,KAAK,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC;wBACnC,KAAK,EAAE,GAAG,CAAC,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC;wBACjC,QAAQ,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE;qBACpC,CAAC,CAAC;gBACL,CAAC,CAAC,CAAC;YACL,CAAC,CAAC;iBACD,KAAK,CAAC,KAAK,CAAC,EAAE;gBACb,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YACxB,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AA3FY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,mBAAU,GAAE;qCAYmC,iDAAsB;GAXzD,kBAAkB,CA2F9B"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Network, Price } from "@x402/core/types";
|
|
2
|
+
export interface X402ModuleOptions {
|
|
3
|
+
facilitatorUrl: string;
|
|
4
|
+
seller: {
|
|
5
|
+
address: string;
|
|
6
|
+
defaultConfig: {
|
|
7
|
+
scheme?: string;
|
|
8
|
+
price?: Price;
|
|
9
|
+
network?: Network;
|
|
10
|
+
payTo?: string;
|
|
11
|
+
extra?: Record<string, unknown>;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export declare const ConfigurableModuleClass: import("@nestjs/common").ConfigurableModuleCls<X402ModuleOptions, "forRoot", "create", {
|
|
16
|
+
isGlobal: boolean;
|
|
17
|
+
}>, X402_MODULE_OPTIONS: string | symbol, OPTIONS_TYPE: X402ModuleOptions & Partial<{
|
|
18
|
+
isGlobal: boolean;
|
|
19
|
+
}>, ASYNC_OPTIONS_TYPE: import("@nestjs/common").ConfigurableModuleAsyncOptions<X402ModuleOptions, "create"> & Partial<{
|
|
20
|
+
isGlobal: boolean;
|
|
21
|
+
}>;
|
|
22
|
+
//# sourceMappingURL=x402.module-definition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"x402.module-definition.d.ts","sourceRoot":"","sources":["../src/x402.module-definition.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEvD,MAAM,WAAW,iBAAiB;IAChC,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE;QACN,OAAO,EAAE,MAAM,CAAC;QAChB,aAAa,EAAE;YACb,MAAM,CAAC,EAAE,MAAM,CAAC;YAChB,KAAK,CAAC,EAAE,KAAK,CAAC;YACd,OAAO,CAAC,EAAE,OAAO,CAAC;YAClB,KAAK,CAAC,EAAE,MAAM,CAAC;YACf,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;SACjC,CAAC;KACH,CAAC;CACH;AAED,eAAO,MACL,uBAAuB;;IACD,mBAAmB,mBACzC,YAAY;;IACZ,kBAAkB;;EAYV,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.ASYNC_OPTIONS_TYPE = exports.OPTIONS_TYPE = exports.X402_MODULE_OPTIONS = exports.ConfigurableModuleClass = void 0;
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
_a = new common_1.ConfigurableModuleBuilder()
|
|
7
|
+
.setClassMethodName("forRoot")
|
|
8
|
+
.setExtras({
|
|
9
|
+
isGlobal: true,
|
|
10
|
+
}, (definition, extras) => ({
|
|
11
|
+
...definition,
|
|
12
|
+
global: extras.isGlobal,
|
|
13
|
+
}))
|
|
14
|
+
.build(), exports.ConfigurableModuleClass = _a.ConfigurableModuleClass, exports.X402_MODULE_OPTIONS = _a.MODULE_OPTIONS_TOKEN, exports.OPTIONS_TYPE = _a.OPTIONS_TYPE, exports.ASYNC_OPTIONS_TYPE = _a.ASYNC_OPTIONS_TYPE;
|
|
15
|
+
//# sourceMappingURL=x402.module-definition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"x402.module-definition.js","sourceRoot":"","sources":["../src/x402.module-definition.ts"],"names":[],"mappings":";;;;AAAA,2CAA2D;AAiB9C,KAKT,IAAI,kCAAyB,EAAqB;KACnD,kBAAkB,CAAC,SAAS,CAAC;KAC7B,SAAS,CACR;IACE,QAAQ,EAAE,IAAI;CACf,EACD,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;IACvB,GAAG,UAAU;IACb,MAAM,EAAE,MAAM,CAAC,QAAQ;CACxB,CAAC,CACH;KACA,KAAK,EAAE,EAfR,+BAAuB,+BACD,2BAAmB,4BACzC,oBAAY,oBACZ,0BAAkB,yBAYT"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { DynamicModule } from "@nestjs/common";
|
|
2
|
+
import { ConfigurableModuleClass, X402_MODULE_OPTIONS, type X402ModuleOptions, type OPTIONS_TYPE, type ASYNC_OPTIONS_TYPE } from "./x402.module-definition";
|
|
3
|
+
export { X402_MODULE_OPTIONS, type X402ModuleOptions };
|
|
4
|
+
/**
|
|
5
|
+
* NestJS dynamic module for x402 payment protocol integration.
|
|
6
|
+
*/
|
|
7
|
+
export declare class X402Module extends ConfigurableModuleClass {
|
|
8
|
+
/**
|
|
9
|
+
* Register the module with static options.
|
|
10
|
+
*
|
|
11
|
+
* @param options - module configuration including facilitator URL and seller config
|
|
12
|
+
* @returns the configured dynamic module
|
|
13
|
+
*/
|
|
14
|
+
static forRoot(options: typeof OPTIONS_TYPE): DynamicModule;
|
|
15
|
+
/**
|
|
16
|
+
* Register the module with async/factory options.
|
|
17
|
+
*
|
|
18
|
+
* @param options - async module configuration with useFactory
|
|
19
|
+
* @returns the configured dynamic module
|
|
20
|
+
*/
|
|
21
|
+
static forRootAsync(options: typeof ASYNC_OPTIONS_TYPE): DynamicModule;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=x402.module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"x402.module.d.ts","sourceRoot":"","sources":["../src/x402.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAU,MAAM,gBAAgB,CAAC;AAMvD,OAAO,EACL,uBAAuB,EACvB,mBAAmB,EACnB,KAAK,iBAAiB,EACtB,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACxB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,mBAAmB,EAAE,KAAK,iBAAiB,EAAE,CAAC;AAEvD;;GAEG;AACH,qBACa,UAAW,SAAQ,uBAAuB;IACrD;;;;;OAKG;IACH,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,YAAY,GAAG,aAAa;IA4C3D;;;;;OAKG;IACH,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,OAAO,kBAAkB,GAAG,aAAa;CA2CvE"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.X402Module = exports.X402_MODULE_OPTIONS = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const core_1 = require("@nestjs/core");
|
|
12
|
+
const payment_registry_service_1 = require("./payment-registry.service");
|
|
13
|
+
const payment_discovery_service_1 = require("./payment-discovery.service");
|
|
14
|
+
const payment_interceptor_1 = require("./payment.interceptor");
|
|
15
|
+
const x402_module_definition_1 = require("./x402.module-definition");
|
|
16
|
+
Object.defineProperty(exports, "X402_MODULE_OPTIONS", { enumerable: true, get: function () { return x402_module_definition_1.X402_MODULE_OPTIONS; } });
|
|
17
|
+
/**
|
|
18
|
+
* NestJS dynamic module for x402 payment protocol integration.
|
|
19
|
+
*/
|
|
20
|
+
let X402Module = class X402Module extends x402_module_definition_1.ConfigurableModuleClass {
|
|
21
|
+
/**
|
|
22
|
+
* Register the module with static options.
|
|
23
|
+
*
|
|
24
|
+
* @param options - module configuration including facilitator URL and seller config
|
|
25
|
+
* @returns the configured dynamic module
|
|
26
|
+
*/
|
|
27
|
+
static forRoot(options) {
|
|
28
|
+
const baseModule = super.forRoot(options);
|
|
29
|
+
return {
|
|
30
|
+
...baseModule,
|
|
31
|
+
providers: [
|
|
32
|
+
...(baseModule.providers || []),
|
|
33
|
+
payment_registry_service_1.PaymentRegistryService,
|
|
34
|
+
payment_discovery_service_1.PaymentDiscoveryService,
|
|
35
|
+
core_1.DiscoveryService,
|
|
36
|
+
core_1.MetadataScanner,
|
|
37
|
+
{
|
|
38
|
+
provide: payment_interceptor_1.PaymentInterceptor,
|
|
39
|
+
useFactory: (registry) => {
|
|
40
|
+
return new payment_interceptor_1.PaymentInterceptor(registry);
|
|
41
|
+
},
|
|
42
|
+
inject: [payment_registry_service_1.PaymentRegistryService],
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
provide: core_1.APP_INTERCEPTOR,
|
|
46
|
+
useExisting: payment_interceptor_1.PaymentInterceptor,
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
provide: "X402_MODULE_INIT",
|
|
50
|
+
useFactory: (registry, interceptor, opts) => {
|
|
51
|
+
registry.setSellerConfig({
|
|
52
|
+
defaultConfig: opts.seller.defaultConfig,
|
|
53
|
+
});
|
|
54
|
+
interceptor.initialize({
|
|
55
|
+
facilitatorUrl: opts.facilitatorUrl,
|
|
56
|
+
defaultNetwork: opts.seller.defaultConfig.network,
|
|
57
|
+
});
|
|
58
|
+
return true;
|
|
59
|
+
},
|
|
60
|
+
inject: [payment_registry_service_1.PaymentRegistryService, payment_interceptor_1.PaymentInterceptor, x402_module_definition_1.X402_MODULE_OPTIONS],
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
exports: [payment_registry_service_1.PaymentRegistryService, payment_interceptor_1.PaymentInterceptor],
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Register the module with async/factory options.
|
|
68
|
+
*
|
|
69
|
+
* @param options - async module configuration with useFactory
|
|
70
|
+
* @returns the configured dynamic module
|
|
71
|
+
*/
|
|
72
|
+
static forRootAsync(options) {
|
|
73
|
+
const baseModule = super.forRootAsync(options);
|
|
74
|
+
return {
|
|
75
|
+
...baseModule,
|
|
76
|
+
providers: [
|
|
77
|
+
...(baseModule.providers || []),
|
|
78
|
+
payment_registry_service_1.PaymentRegistryService,
|
|
79
|
+
payment_discovery_service_1.PaymentDiscoveryService,
|
|
80
|
+
core_1.DiscoveryService,
|
|
81
|
+
core_1.MetadataScanner,
|
|
82
|
+
{
|
|
83
|
+
provide: payment_interceptor_1.PaymentInterceptor,
|
|
84
|
+
useFactory: (registry) => {
|
|
85
|
+
return new payment_interceptor_1.PaymentInterceptor(registry);
|
|
86
|
+
},
|
|
87
|
+
inject: [payment_registry_service_1.PaymentRegistryService],
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
provide: core_1.APP_INTERCEPTOR,
|
|
91
|
+
useExisting: payment_interceptor_1.PaymentInterceptor,
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
provide: "X402_MODULE_INIT",
|
|
95
|
+
useFactory: (registry, interceptor, opts) => {
|
|
96
|
+
registry.setSellerConfig({
|
|
97
|
+
defaultConfig: opts.seller.defaultConfig,
|
|
98
|
+
});
|
|
99
|
+
interceptor.initialize({
|
|
100
|
+
facilitatorUrl: opts.facilitatorUrl,
|
|
101
|
+
defaultNetwork: opts.seller.defaultConfig.network,
|
|
102
|
+
});
|
|
103
|
+
return true;
|
|
104
|
+
},
|
|
105
|
+
inject: [payment_registry_service_1.PaymentRegistryService, payment_interceptor_1.PaymentInterceptor, x402_module_definition_1.X402_MODULE_OPTIONS],
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
exports: [payment_registry_service_1.PaymentRegistryService, payment_interceptor_1.PaymentInterceptor],
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
exports.X402Module = X402Module;
|
|
113
|
+
exports.X402Module = X402Module = __decorate([
|
|
114
|
+
(0, common_1.Module)({})
|
|
115
|
+
], X402Module);
|
|
116
|
+
//# sourceMappingURL=x402.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"x402.module.js","sourceRoot":"","sources":["../src/x402.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAuD;AACvD,uCAAkF;AAClF,yEAAoE;AACpE,2EAAsE;AACtE,+DAA2D;AAE3D,qEAMkC;AAEzB,oGANP,4CAAmB,OAMO;AAE5B;;GAEG;AAEI,IAAM,UAAU,GAAhB,MAAM,UAAW,SAAQ,gDAAuB;IACrD;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b,SAAS,EAAE;gBACT,GAAG,CAAC,UAAU,CAAC,SAAS,IAAI,EAAE,CAAC;gBAC/B,iDAAsB;gBACtB,mDAAuB;gBACvB,uBAAgB;gBAChB,sBAAe;gBACf;oBACE,OAAO,EAAE,wCAAkB;oBAC3B,UAAU,EAAE,CAAC,QAAgC,EAAE,EAAE;wBAC/C,OAAO,IAAI,wCAAkB,CAAC,QAAQ,CAAC,CAAC;oBAC1C,CAAC;oBACD,MAAM,EAAE,CAAC,iDAAsB,CAAC;iBACjC;gBACD;oBACE,OAAO,EAAE,sBAAe;oBACxB,WAAW,EAAE,wCAAkB;iBAChC;gBACD;oBACE,OAAO,EAAE,kBAAkB;oBAC3B,UAAU,EAAE,CACV,QAAgC,EAChC,WAA+B,EAC/B,IAAuB,EACvB,EAAE;wBACF,QAAQ,CAAC,eAAe,CAAC;4BACvB,aAAa,EAAE,IAAI,CAAC,MAAM,CAAC,aAAuC;yBACnE,CAAC,CAAC;wBACH,WAAW,CAAC,UAAU,CAAC;4BACrB,cAAc,EAAE,IAAI,CAAC,cAAc;4BACnC,cAAc,EAAE,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,OAAO;yBAClD,CAAC,CAAC;wBACH,OAAO,IAAI,CAAC;oBACd,CAAC;oBACD,MAAM,EAAE,CAAC,iDAAsB,EAAE,wCAAkB,EAAE,4CAAmB,CAAC;iBAC1E;aACF;YACD,OAAO,EAAE,CAAC,iDAAsB,EAAE,wCAAkB,CAAC;SACtD,CAAC;IACJ,CAAC;CACF,CAAA;AApGY,gCAAU;qBAAV,UAAU;IADtB,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,UAAU,CAoGtB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@introspectivelabs/nestjs-x402",
|
|
3
|
+
"version": "0.1.0-beta.0",
|
|
4
|
+
"main": "./dist/index.js",
|
|
5
|
+
"types": "./dist/index.d.ts",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"x402",
|
|
8
|
+
"payment",
|
|
9
|
+
"nestjs",
|
|
10
|
+
"erc4337"
|
|
11
|
+
],
|
|
12
|
+
"license": "Apache-2.0",
|
|
13
|
+
"author": "Introspective Labs",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/Introspective-Labs/x402-modules.git",
|
|
17
|
+
"directory": "packages/nestjs-x402"
|
|
18
|
+
},
|
|
19
|
+
"description": "x402 Payment Protocol NestJS integration with @Payment() decorator support",
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public",
|
|
22
|
+
"registry": "https://registry.npmjs.org"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"@introspectivelabs/x402-evm": ">=0.1.0-beta.1",
|
|
26
|
+
"@nestjs/common": ">=10.0.0",
|
|
27
|
+
"@nestjs/config": ">=3.0.0",
|
|
28
|
+
"@nestjs/core": ">=10.0.0",
|
|
29
|
+
"@x402/core": "2.*",
|
|
30
|
+
"@x402/express": "2.*",
|
|
31
|
+
"rxjs": ">=7.0.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@eslint/js": "^9.24.0",
|
|
35
|
+
"@nestjs/common": "^11.0.1",
|
|
36
|
+
"@nestjs/config": "^4.0.2",
|
|
37
|
+
"@nestjs/core": "^11.0.1",
|
|
38
|
+
"@nestjs/testing": "^11.0.1",
|
|
39
|
+
"@swc/core": "^1.15.11",
|
|
40
|
+
"@typescript-eslint/eslint-plugin": "^8.29.1",
|
|
41
|
+
"@typescript-eslint/parser": "^8.29.1",
|
|
42
|
+
"@x402/core": "^2.1.0",
|
|
43
|
+
"@x402/express": "^2.1.0",
|
|
44
|
+
"eslint": "^9.24.0",
|
|
45
|
+
"eslint-plugin-import": "^2.31.0",
|
|
46
|
+
"eslint-plugin-jsdoc": "^50.6.9",
|
|
47
|
+
"eslint-plugin-prettier": "^5.2.6",
|
|
48
|
+
"prettier": "3.5.2",
|
|
49
|
+
"rxjs": "^7.8.1",
|
|
50
|
+
"typescript": "^5.7.3",
|
|
51
|
+
"unplugin-swc": "^1.5.9",
|
|
52
|
+
"vite": "^6.2.6",
|
|
53
|
+
"vite-tsconfig-paths": "^5.1.4",
|
|
54
|
+
"vitest": "^3.0.5",
|
|
55
|
+
"@introspectivelabs/x402-evm": "0.1.0-beta.4"
|
|
56
|
+
},
|
|
57
|
+
"files": [
|
|
58
|
+
"dist"
|
|
59
|
+
],
|
|
60
|
+
"scripts": {
|
|
61
|
+
"build": "tsc",
|
|
62
|
+
"test": "vitest run",
|
|
63
|
+
"test:watch": "vitest",
|
|
64
|
+
"lint": "eslint . --ext .ts --fix",
|
|
65
|
+
"lint:check": "eslint . --ext .ts",
|
|
66
|
+
"format": "prettier -c .prettierrc --write \"**/*.{ts,js,cjs,json,md}\"",
|
|
67
|
+
"format:check": "prettier -c .prettierrc --check \"**/*.{ts,js,cjs,json,md}\"",
|
|
68
|
+
"publish:dev": "pnpm dlx yalc publish --push"
|
|
69
|
+
}
|
|
70
|
+
}
|