@bejibun/core 0.1.51 → 0.1.52

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 CHANGED
@@ -3,6 +3,34 @@ All notable changes to this project will be documented in this file.
3
3
 
4
4
  ---
5
5
 
6
+ ## [v0.1.52](https://github.com/crenata/bejibun-core/compare/v0.1.51...v0.1.52) - 2025-11-17
7
+
8
+ ### 🩹 Fixes
9
+
10
+ ### 📖 Changes
11
+ What's New :
12
+
13
+ Adding support for x402 protocol. You can secure your paid endpoint by adding `.x402()` chaining on router.
14
+
15
+ How to use it :
16
+
17
+ First, you need to install the package by running `bun ace install @bejibun/x402`.
18
+
19
+ Customize your `config/x402.ts` with your own configuration.
20
+
21
+ Add `.x402()` chain into router you want to add for payment middleware.
22
+ ```ts
23
+ Router.x402()
24
+ ```
25
+
26
+ ### ❤️Contributors
27
+ - Havea Crenata ([@crenata](https://github.com/crenata))
28
+ - Ghulje ([@ghulje](https://github.com/ghulje))
29
+
30
+ **Full Changelog**: https://github.com/crenata/bejibun-core/blob/master/CHANGELOG.md
31
+
32
+ ---
33
+
6
34
  ## [v0.1.51](https://github.com/crenata/bejibun-core/compare/v0.1.49...v0.1.51) - 2025-11-04
7
35
 
8
36
  ### 🩹 Fixes
@@ -1,6 +1,7 @@
1
- import HttpMethodEnum from "@bejibun/utils/enums/HttpMethodEnum";
1
+ import type { TFacilitator, TPaywall, TX402Config } from "@bejibun/x402";
2
2
  import type { IMiddleware } from "../types/middleware";
3
3
  import type { HandlerType, ResourceAction, RouterGroup } from "../types/router";
4
+ import HttpMethodEnum from "@bejibun/utils/enums/HttpMethodEnum";
4
5
  export interface ResourceOptions {
5
6
  only?: Array<ResourceAction>;
6
7
  except?: Array<ResourceAction>;
@@ -12,6 +13,7 @@ export default class RouterBuilder {
12
13
  prefix(basePath: string): RouterBuilder;
13
14
  middleware(...middlewares: Array<IMiddleware>): RouterBuilder;
14
15
  namespace(baseNamespace: string): RouterBuilder;
16
+ x402(config?: TX402Config, facilitatorConfig?: TFacilitator, paywallConfig?: TPaywall): RouterBuilder;
15
17
  group(routes: RouterGroup | Array<RouterGroup>): RouterGroup;
16
18
  resources(controller: Record<string, HandlerType>, options?: ResourceOptions): RouterGroup;
17
19
  buildSingle(method: HttpMethodEnum, path: string, handler: string | HandlerType): RouterGroup;
@@ -1,9 +1,10 @@
1
1
  import App from "@bejibun/app";
2
- import { isEmpty } from "@bejibun/utils";
2
+ import { isEmpty, isModuleExists } from "@bejibun/utils";
3
3
  import HttpMethodEnum from "@bejibun/utils/enums/HttpMethodEnum";
4
4
  import Enum from "@bejibun/utils/facades/Enum";
5
5
  import path from "path";
6
6
  import RouterInvalidException from "../exceptions/RouterInvalidException";
7
+ import X402Middleware from "../middlewares/X402Middleware";
7
8
  export default class RouterBuilder {
8
9
  basePath = "";
9
10
  middlewares = [];
@@ -20,6 +21,12 @@ export default class RouterBuilder {
20
21
  this.baseNamespace = baseNamespace;
21
22
  return this;
22
23
  }
24
+ x402(config, facilitatorConfig, paywallConfig) {
25
+ if (!isModuleExists("@bejibun/x402"))
26
+ throw new RouterInvalidException("@bejibun/x402 is not installed.");
27
+ this.middlewares.push(new X402Middleware(config, facilitatorConfig, paywallConfig));
28
+ return this;
29
+ }
23
30
  group(routes) {
24
31
  const routeList = Array.isArray(routes) ? routes : [routes];
25
32
  const newRoutes = {};
@@ -6,6 +6,7 @@ export default class Router {
6
6
  static prefix(basePath: string): RouterBuilder;
7
7
  static middleware(...middlewares: Array<IMiddleware>): RouterBuilder;
8
8
  static namespace(baseNamespace: string): RouterBuilder;
9
+ static x402(): RouterBuilder;
9
10
  static resources(controller: Record<string, HandlerType>, options?: ResourceOptions): RouterGroup;
10
11
  static group(routes: RouterGroup, prefix?: string, middlewares?: Array<IMiddleware>): RouterGroup;
11
12
  static connect(path: string, handler: string | HandlerType): RouterGroup;
package/facades/Router.js CHANGED
@@ -10,6 +10,9 @@ export default class Router {
10
10
  static namespace(baseNamespace) {
11
11
  return new RouterBuilder().namespace(baseNamespace);
12
12
  }
13
+ static x402() {
14
+ return new RouterBuilder().x402();
15
+ }
13
16
  static resources(controller, options) {
14
17
  return new RouterBuilder().resources(controller, options);
15
18
  }
package/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./bases/index";
2
2
  export * from "./exceptions/index";
3
3
  export * from "./facades/index";
4
+ export * from "./middlewares/index";
package/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./bases/index";
2
2
  export * from "./exceptions/index";
3
3
  export * from "./facades/index";
4
+ export * from "./middlewares/index";
@@ -0,0 +1,9 @@
1
+ import type { TFacilitator, TPaywall, TX402Config } from "@bejibun/x402";
2
+ import type { HandlerType } from "../types/router";
3
+ export default class X402Middleware {
4
+ protected config?: TX402Config;
5
+ protected facilitatorConfig?: TFacilitator;
6
+ protected paywallConfig?: TPaywall;
7
+ constructor(config?: TX402Config, facilitatorConfig?: TFacilitator, paywallConfig?: TPaywall);
8
+ handle(handler: HandlerType): HandlerType;
9
+ }
@@ -0,0 +1,23 @@
1
+ import X402 from "@bejibun/x402";
2
+ export default class X402Middleware {
3
+ config;
4
+ facilitatorConfig;
5
+ paywallConfig;
6
+ constructor(config, facilitatorConfig, paywallConfig) {
7
+ this.config = config;
8
+ this.facilitatorConfig = facilitatorConfig;
9
+ this.paywallConfig = paywallConfig;
10
+ }
11
+ handle(handler) {
12
+ return async (request) => {
13
+ return X402
14
+ .setConfig(this.config)
15
+ .setFacilitator(this.facilitatorConfig)
16
+ .setPaywall(this.paywallConfig)
17
+ .setRequest(request)
18
+ .middleware(() => {
19
+ return handler(request);
20
+ });
21
+ };
22
+ }
23
+ }
@@ -0,0 +1,2 @@
1
+ export * from "../middlewares/MaintenanceMiddleware";
2
+ export * from "../middlewares/X402Middleware";
@@ -0,0 +1,2 @@
1
+ export * from "../middlewares/MaintenanceMiddleware";
2
+ export * from "../middlewares/X402Middleware";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bejibun/core",
3
- "version": "0.1.51",
3
+ "version": "0.1.52",
4
4
  "author": "Havea Crenata <havea.crenata@gmail.com>",
5
5
  "repository": {
6
6
  "type": "git",
@@ -13,13 +13,14 @@
13
13
  "@bejibun/cors": "^0.1.16",
14
14
  "@bejibun/database": "^0.1.19",
15
15
  "@bejibun/logger": "^0.1.22",
16
- "@bejibun/utils": "^0.1.20",
16
+ "@bejibun/utils": "^0.1.21",
17
17
  "@vinejs/vine": "^3.0.1",
18
18
  "commander": "^14.0.2",
19
19
  "luxon": "^3.7.2",
20
20
  "objection": "^3.1.5"
21
21
  },
22
22
  "devDependencies": {
23
+ "@bejibun/x402": "^0.1.1",
23
24
  "@types/bun": "latest",
24
25
  "@types/luxon": "^3.7.1",
25
26
  "tsc-alias": "^1.8.16"