@bejibun/core 0.1.50 → 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 +66 -0
- package/README.md +1 -5
- package/builders/RouterBuilder.d.ts +3 -1
- package/builders/RouterBuilder.js +8 -1
- package/commands/Kernel.js +5 -1
- package/facades/Router.d.ts +1 -0
- package/facades/Router.js +3 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/middlewares/X402Middleware.d.ts +9 -0
- package/middlewares/X402Middleware.js +23 -0
- package/middlewares/index.d.ts +2 -0
- package/middlewares/index.js +2 -0
- package/package.json +7 -6
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,72 @@ 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
|
+
|
|
34
|
+
## [v0.1.51](https://github.com/crenata/bejibun-core/compare/v0.1.49...v0.1.51) - 2025-11-04
|
|
35
|
+
|
|
36
|
+
### 🩹 Fixes
|
|
37
|
+
|
|
38
|
+
### 📖 Changes
|
|
39
|
+
What's New :
|
|
40
|
+
|
|
41
|
+
Everyone can create their own packages,
|
|
42
|
+
and now `Bejibun` support for commands from external packages
|
|
43
|
+
and can be added to `config/command.ts`.
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
const config: Array<Record<string, any>> = [
|
|
47
|
+
/*
|
|
48
|
+
{
|
|
49
|
+
path: "your-dependencies/your-directory-commands",
|
|
50
|
+
path: "@bejibun/database/commands" // Example
|
|
51
|
+
}
|
|
52
|
+
*/
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
export default config;
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Or the external package itself can automatically add them to `config/command.ts`
|
|
59
|
+
using the configuration package by creating `configure.ts` in your package root.
|
|
60
|
+
|
|
61
|
+
When the user runs `bun ace install your-package` it will automatically run the configuration package.
|
|
62
|
+
|
|
63
|
+
So when user runs `bun ace` your command will appear in the list.
|
|
64
|
+
|
|
65
|
+
### ❤️Contributors
|
|
66
|
+
- Ghulje ([@ghulje](https://github.com/ghulje))
|
|
67
|
+
|
|
68
|
+
**Full Changelog**: https://github.com/crenata/bejibun-core/blob/master/CHANGELOG.md
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
6
72
|
## [v0.1.49](https://github.com/crenata/bejibun-core/compare/v0.1.47...v0.1.49) - 2025-10-27
|
|
7
73
|
|
|
8
74
|
### 🩹 Fixes
|
package/README.md
CHANGED
|
@@ -84,11 +84,7 @@ bun ace migrate:latest --help
|
|
|
84
84
|
|
|
85
85
|
## ☕ Support / Donate
|
|
86
86
|
|
|
87
|
-
If you find this project helpful and want to support it, you can donate via
|
|
88
|
-
|
|
89
|
-
[](https://paypal.me/hafiizhghulam)
|
|
90
|
-
|
|
91
|
-
Or if you are prefer using crypto :
|
|
87
|
+
If you find this project helpful and want to support it, you can donate via crypto :
|
|
92
88
|
|
|
93
89
|
| EVM | Solana |
|
|
94
90
|
| ------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import
|
|
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 = {};
|
package/commands/Kernel.js
CHANGED
|
@@ -2,6 +2,7 @@ import App from "@bejibun/app";
|
|
|
2
2
|
import { defineValue, isEmpty } from "@bejibun/utils";
|
|
3
3
|
export default class Kernel {
|
|
4
4
|
static registerCommands(program) {
|
|
5
|
+
const rootCommands = require(App.Path.configPath("command.ts")).default;
|
|
5
6
|
const paths = [
|
|
6
7
|
{
|
|
7
8
|
absolute: true,
|
|
@@ -15,7 +16,10 @@ export default class Kernel {
|
|
|
15
16
|
absolute: true,
|
|
16
17
|
cwd: "node_modules/@bejibun/database/commands"
|
|
17
18
|
}
|
|
18
|
-
]
|
|
19
|
+
].concat(rootCommands.map(value => ({
|
|
20
|
+
absolute: true,
|
|
21
|
+
cwd: `node_modules/${value.path}`
|
|
22
|
+
})));
|
|
19
23
|
const files = paths
|
|
20
24
|
.map(value => Array.from(new Bun.Glob("**/*").scanSync({
|
|
21
25
|
absolute: value.absolute,
|
package/facades/Router.d.ts
CHANGED
|
@@ -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
package/index.js
CHANGED
|
@@ -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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bejibun/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.52",
|
|
4
4
|
"author": "Havea Crenata <havea.crenata@gmail.com>",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -9,17 +9,18 @@
|
|
|
9
9
|
"main": "index.js",
|
|
10
10
|
"module": "index.js",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@bejibun/app": "^0.1.
|
|
13
|
-
"@bejibun/cors": "^0.1.
|
|
14
|
-
"@bejibun/database": "^0.1.
|
|
15
|
-
"@bejibun/logger": "^0.1.
|
|
16
|
-
"@bejibun/utils": "^0.1.
|
|
12
|
+
"@bejibun/app": "^0.1.22",
|
|
13
|
+
"@bejibun/cors": "^0.1.16",
|
|
14
|
+
"@bejibun/database": "^0.1.19",
|
|
15
|
+
"@bejibun/logger": "^0.1.22",
|
|
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"
|