@zarex/bun 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/dist/index.cjs +103 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +29 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +79 -0
- package/dist/index.js.map +1 -0
- package/package.json +32 -3
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kodjogbe
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
CLOUDFLARE_RANGES: () => import_core2.CLOUDFLARE_RANGES,
|
|
24
|
+
PRIVATE_NETWORKS: () => import_core2.PRIVATE_NETWORKS,
|
|
25
|
+
createZarex: () => import_core2.createZarex,
|
|
26
|
+
detectBot: () => import_core2.detectBot,
|
|
27
|
+
emailValidation: () => import_core2.emailValidation,
|
|
28
|
+
phoneValidation: () => import_core2.phoneValidation,
|
|
29
|
+
promptInjection: () => import_core2.promptInjection,
|
|
30
|
+
rateLimit: () => import_core2.rateLimit,
|
|
31
|
+
requestFilter: () => import_core2.requestFilter,
|
|
32
|
+
secureHeaders: () => import_core2.secureHeaders,
|
|
33
|
+
sensitiveInfo: () => import_core2.sensitiveInfo,
|
|
34
|
+
shield: () => import_core2.shield,
|
|
35
|
+
tokenBucket: () => import_core2.tokenBucket,
|
|
36
|
+
withSecureHeaders: () => import_core2.withSecureHeaders,
|
|
37
|
+
zarexBun: () => zarexBun
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(index_exports);
|
|
40
|
+
var import_core = require("@zarex/core");
|
|
41
|
+
var import_core2 = require("@zarex/core");
|
|
42
|
+
function zarexBun(options, extra = {}) {
|
|
43
|
+
const isInstance = typeof options.protect === "function";
|
|
44
|
+
const instance = isInstance ? options : (0, import_core.createZarex)(options);
|
|
45
|
+
const opts = isInstance ? extra : options;
|
|
46
|
+
const finalizer = (0, import_core.createWebFinalizer)({ secureHeaders: opts.secureHeaders, responseGuard: opts.responseGuard });
|
|
47
|
+
const finalize = async (res, request) => {
|
|
48
|
+
if (!finalizer || !res) return res;
|
|
49
|
+
try {
|
|
50
|
+
return await finalizer(res, request);
|
|
51
|
+
} catch {
|
|
52
|
+
return res;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
return function wrap(handler) {
|
|
56
|
+
return async function fetchWithZarex(request, server) {
|
|
57
|
+
let deny;
|
|
58
|
+
try {
|
|
59
|
+
let socketIp;
|
|
60
|
+
try {
|
|
61
|
+
socketIp = server?.requestIP?.(request)?.address;
|
|
62
|
+
} catch {
|
|
63
|
+
socketIp = void 0;
|
|
64
|
+
}
|
|
65
|
+
let call;
|
|
66
|
+
try {
|
|
67
|
+
call = opts.call?.(request);
|
|
68
|
+
} catch {
|
|
69
|
+
call = void 0;
|
|
70
|
+
}
|
|
71
|
+
({ deny } = await (0, import_core.guardWebRequest)(instance, request, {
|
|
72
|
+
socketIp,
|
|
73
|
+
...opts.inspectBody ? { inspectBody: true } : {},
|
|
74
|
+
...opts.onDeny ? { onDeny: opts.onDeny } : {},
|
|
75
|
+
...opts.onDegraded ? { onDegraded: opts.onDegraded } : {},
|
|
76
|
+
...call ? { call } : {}
|
|
77
|
+
}));
|
|
78
|
+
} catch {
|
|
79
|
+
deny = void 0;
|
|
80
|
+
}
|
|
81
|
+
return finalize(deny ?? await handler(request, server), request);
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
86
|
+
0 && (module.exports = {
|
|
87
|
+
CLOUDFLARE_RANGES,
|
|
88
|
+
PRIVATE_NETWORKS,
|
|
89
|
+
createZarex,
|
|
90
|
+
detectBot,
|
|
91
|
+
emailValidation,
|
|
92
|
+
phoneValidation,
|
|
93
|
+
promptInjection,
|
|
94
|
+
rateLimit,
|
|
95
|
+
requestFilter,
|
|
96
|
+
secureHeaders,
|
|
97
|
+
sensitiveInfo,
|
|
98
|
+
shield,
|
|
99
|
+
tokenBucket,
|
|
100
|
+
withSecureHeaders,
|
|
101
|
+
zarexBun
|
|
102
|
+
});
|
|
103
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { createWebFinalizer, createZarex, guardWebRequest, type ResponseGuardOptions, type SecureHeadersOptions, type Decision, type ProtectCall, type WebGuardOptions, type Zarex, type ZarexOptions } from \"@zarex/core\";\r\n\r\n/** Ce que Bun fournit comme second argument de `fetch` : l'adresse de la connexion. */\r\nexport interface BunServerLike {\r\n requestIP(request: Request): { address: string } | null;\r\n}\r\n\r\nexport interface BunZarexOptions extends ZarexOptions {\r\n inspectBody?: boolean;\r\n /** En-têtes de sécurité ajoutés à chaque réponse (true = défauts prudents). */\r\n secureHeaders?: SecureHeadersOptions | boolean;\r\n /** Surveille les réponses : masque les cartes bancaires, clés d'API, etc. */\r\n responseGuard?: ResponseGuardOptions | boolean;\r\n onDeny?: WebGuardOptions[\"onDeny\"];\r\n onDegraded?: WebGuardOptions[\"onDegraded\"];\r\n call?: (request: Request) => ProtectCall | undefined;\r\n}\r\n\r\ntype Fetch<S> = (request: Request, server: S) => Response | Promise<Response> | undefined | Promise<Response | undefined>;\r\n\r\n/**\r\n * Bun.serve({ fetch: zarexBun({ key, baseUrl, ipSource: { proxies: 1 }, rules: [shield()] })(handler) })\r\n *\r\n * Bun donne l'adresse de la connexion (server.requestIP) : toutes les sources d'IP fonctionnent.\r\n * Le résultat de la décision est dans `(request as any).zarex` uniquement si vous le lisez via `onDegraded`.\r\n */\r\nexport function zarexBun(options: BunZarexOptions | Zarex, extra: Pick<BunZarexOptions, \"inspectBody\" | \"onDeny\" | \"onDegraded\" | \"call\" | \"secureHeaders\" | \"responseGuard\"> = {}) {\r\n const isInstance = typeof (options as Zarex).protect === \"function\";\r\n const instance: Zarex = isInstance ? (options as Zarex) : createZarex(options as BunZarexOptions);\r\n const opts = (isInstance ? extra : options) as BunZarexOptions;\r\n\r\n const finalizer = createWebFinalizer({ secureHeaders: opts.secureHeaders, responseGuard: opts.responseGuard });\r\n const finalize = async (res: Response | undefined, request: Request): Promise<Response | undefined> => {\r\n if (!finalizer || !res) return res;\r\n try {\r\n return await finalizer(res, request);\r\n } catch {\r\n return res;\r\n }\r\n };\r\n\r\n return function wrap<S extends BunServerLike>(handler: Fetch<S>): Fetch<S> {\r\n return async function fetchWithZarex(request, server) {\r\n let deny: Response | undefined;\r\n try {\r\n let socketIp: string | undefined;\r\n try {\r\n socketIp = server?.requestIP?.(request)?.address;\r\n } catch {\r\n socketIp = undefined;\r\n }\r\n let call: ProtectCall | undefined;\r\n try {\r\n call = opts.call?.(request);\r\n } catch {\r\n call = undefined;\r\n }\r\n ({ deny } = await guardWebRequest(instance, request, {\r\n socketIp,\r\n ...(opts.inspectBody ? { inspectBody: true } : {}),\r\n ...(opts.onDeny ? { onDeny: opts.onDeny } : {}),\r\n ...(opts.onDegraded ? { onDegraded: opts.onDegraded } : {}),\r\n ...(call ? { call } : {}),\r\n }));\r\n } catch {\r\n deny = undefined;\r\n }\r\n return finalize(deny ?? (await handler(request, server)), request);\r\n };\r\n };\r\n}\r\n\r\nexport {\r\n shield,\r\n rateLimit,\r\n tokenBucket,\r\n detectBot,\r\n requestFilter,\r\n sensitiveInfo,\r\n emailValidation,\r\n phoneValidation,\r\n promptInjection,\r\n secureHeaders,\r\n withSecureHeaders,\r\n createZarex,\r\n PRIVATE_NETWORKS,\r\n CLOUDFLARE_RANGES,\r\n} from \"@zarex/core\";\r\nexport type { SecureHeadersOptions, ResponseGuardOptions, ResponseGuardEvent } from \"@zarex/core\";\r\nexport type { Decision, Zarex, ZarexOptions, IpSource, Rule, ProtectCall } from \"@zarex/core\";"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA6M;AAwE7M,IAAAA,eAeO;AA7DA,SAAS,SAAS,SAAkC,QAAqH,CAAC,GAAG;AAClL,QAAM,aAAa,OAAQ,QAAkB,YAAY;AACzD,QAAM,WAAkB,aAAc,cAAoB,yBAAY,OAA0B;AAChG,QAAM,OAAQ,aAAa,QAAQ;AAEnC,QAAM,gBAAY,gCAAmB,EAAE,eAAe,KAAK,eAAe,eAAe,KAAK,cAAc,CAAC;AAC7G,QAAM,WAAW,OAAO,KAA2B,YAAoD;AACrG,QAAI,CAAC,aAAa,CAAC,IAAK,QAAO;AAC/B,QAAI;AACF,aAAO,MAAM,UAAU,KAAK,OAAO;AAAA,IACrC,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO,SAAS,KAA8B,SAA6B;AACzE,WAAO,eAAe,eAAe,SAAS,QAAQ;AACpD,UAAI;AACJ,UAAI;AACF,YAAI;AACJ,YAAI;AACF,qBAAW,QAAQ,YAAY,OAAO,GAAG;AAAA,QAC3C,QAAQ;AACN,qBAAW;AAAA,QACb;AACA,YAAI;AACJ,YAAI;AACF,iBAAO,KAAK,OAAO,OAAO;AAAA,QAC5B,QAAQ;AACN,iBAAO;AAAA,QACT;AACA,SAAC,EAAE,KAAK,IAAI,UAAM,6BAAgB,UAAU,SAAS;AAAA,UACnD;AAAA,UACA,GAAI,KAAK,cAAc,EAAE,aAAa,KAAK,IAAI,CAAC;AAAA,UAChD,GAAI,KAAK,SAAS,EAAE,QAAQ,KAAK,OAAO,IAAI,CAAC;AAAA,UAC7C,GAAI,KAAK,aAAa,EAAE,YAAY,KAAK,WAAW,IAAI,CAAC;AAAA,UACzD,GAAI,OAAO,EAAE,KAAK,IAAI,CAAC;AAAA,QACzB,CAAC;AAAA,MACH,QAAQ;AACN,eAAO;AAAA,MACT;AACA,aAAO,SAAS,QAAS,MAAM,QAAQ,SAAS,MAAM,GAAI,OAAO;AAAA,IACnE;AAAA,EACF;AACF;","names":["import_core"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ZarexOptions, SecureHeadersOptions, ResponseGuardOptions, WebGuardOptions, ProtectCall, Zarex } from '@zarex/core';
|
|
2
|
+
export { CLOUDFLARE_RANGES, Decision, IpSource, PRIVATE_NETWORKS, ProtectCall, ResponseGuardEvent, ResponseGuardOptions, Rule, SecureHeadersOptions, Zarex, ZarexOptions, createZarex, detectBot, emailValidation, phoneValidation, promptInjection, rateLimit, requestFilter, secureHeaders, sensitiveInfo, shield, tokenBucket, withSecureHeaders } from '@zarex/core';
|
|
3
|
+
|
|
4
|
+
/** Ce que Bun fournit comme second argument de `fetch` : l'adresse de la connexion. */
|
|
5
|
+
interface BunServerLike {
|
|
6
|
+
requestIP(request: Request): {
|
|
7
|
+
address: string;
|
|
8
|
+
} | null;
|
|
9
|
+
}
|
|
10
|
+
interface BunZarexOptions extends ZarexOptions {
|
|
11
|
+
inspectBody?: boolean;
|
|
12
|
+
/** En-têtes de sécurité ajoutés à chaque réponse (true = défauts prudents). */
|
|
13
|
+
secureHeaders?: SecureHeadersOptions | boolean;
|
|
14
|
+
/** Surveille les réponses : masque les cartes bancaires, clés d'API, etc. */
|
|
15
|
+
responseGuard?: ResponseGuardOptions | boolean;
|
|
16
|
+
onDeny?: WebGuardOptions["onDeny"];
|
|
17
|
+
onDegraded?: WebGuardOptions["onDegraded"];
|
|
18
|
+
call?: (request: Request) => ProtectCall | undefined;
|
|
19
|
+
}
|
|
20
|
+
type Fetch<S> = (request: Request, server: S) => Response | Promise<Response> | undefined | Promise<Response | undefined>;
|
|
21
|
+
/**
|
|
22
|
+
* Bun.serve({ fetch: zarexBun({ key, baseUrl, ipSource: { proxies: 1 }, rules: [shield()] })(handler) })
|
|
23
|
+
*
|
|
24
|
+
* Bun donne l'adresse de la connexion (server.requestIP) : toutes les sources d'IP fonctionnent.
|
|
25
|
+
* Le résultat de la décision est dans `(request as any).zarex` uniquement si vous le lisez via `onDegraded`.
|
|
26
|
+
*/
|
|
27
|
+
declare function zarexBun(options: BunZarexOptions | Zarex, extra?: Pick<BunZarexOptions, "inspectBody" | "onDeny" | "onDegraded" | "call" | "secureHeaders" | "responseGuard">): <S extends BunServerLike>(handler: Fetch<S>) => Fetch<S>;
|
|
28
|
+
|
|
29
|
+
export { type BunServerLike, type BunZarexOptions, zarexBun };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ZarexOptions, SecureHeadersOptions, ResponseGuardOptions, WebGuardOptions, ProtectCall, Zarex } from '@zarex/core';
|
|
2
|
+
export { CLOUDFLARE_RANGES, Decision, IpSource, PRIVATE_NETWORKS, ProtectCall, ResponseGuardEvent, ResponseGuardOptions, Rule, SecureHeadersOptions, Zarex, ZarexOptions, createZarex, detectBot, emailValidation, phoneValidation, promptInjection, rateLimit, requestFilter, secureHeaders, sensitiveInfo, shield, tokenBucket, withSecureHeaders } from '@zarex/core';
|
|
3
|
+
|
|
4
|
+
/** Ce que Bun fournit comme second argument de `fetch` : l'adresse de la connexion. */
|
|
5
|
+
interface BunServerLike {
|
|
6
|
+
requestIP(request: Request): {
|
|
7
|
+
address: string;
|
|
8
|
+
} | null;
|
|
9
|
+
}
|
|
10
|
+
interface BunZarexOptions extends ZarexOptions {
|
|
11
|
+
inspectBody?: boolean;
|
|
12
|
+
/** En-têtes de sécurité ajoutés à chaque réponse (true = défauts prudents). */
|
|
13
|
+
secureHeaders?: SecureHeadersOptions | boolean;
|
|
14
|
+
/** Surveille les réponses : masque les cartes bancaires, clés d'API, etc. */
|
|
15
|
+
responseGuard?: ResponseGuardOptions | boolean;
|
|
16
|
+
onDeny?: WebGuardOptions["onDeny"];
|
|
17
|
+
onDegraded?: WebGuardOptions["onDegraded"];
|
|
18
|
+
call?: (request: Request) => ProtectCall | undefined;
|
|
19
|
+
}
|
|
20
|
+
type Fetch<S> = (request: Request, server: S) => Response | Promise<Response> | undefined | Promise<Response | undefined>;
|
|
21
|
+
/**
|
|
22
|
+
* Bun.serve({ fetch: zarexBun({ key, baseUrl, ipSource: { proxies: 1 }, rules: [shield()] })(handler) })
|
|
23
|
+
*
|
|
24
|
+
* Bun donne l'adresse de la connexion (server.requestIP) : toutes les sources d'IP fonctionnent.
|
|
25
|
+
* Le résultat de la décision est dans `(request as any).zarex` uniquement si vous le lisez via `onDegraded`.
|
|
26
|
+
*/
|
|
27
|
+
declare function zarexBun(options: BunZarexOptions | Zarex, extra?: Pick<BunZarexOptions, "inspectBody" | "onDeny" | "onDegraded" | "call" | "secureHeaders" | "responseGuard">): <S extends BunServerLike>(handler: Fetch<S>) => Fetch<S>;
|
|
28
|
+
|
|
29
|
+
export { type BunServerLike, type BunZarexOptions, zarexBun };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { createWebFinalizer, createZarex, guardWebRequest } from "@zarex/core";
|
|
3
|
+
import {
|
|
4
|
+
shield,
|
|
5
|
+
rateLimit,
|
|
6
|
+
tokenBucket,
|
|
7
|
+
detectBot,
|
|
8
|
+
requestFilter,
|
|
9
|
+
sensitiveInfo,
|
|
10
|
+
emailValidation,
|
|
11
|
+
phoneValidation,
|
|
12
|
+
promptInjection,
|
|
13
|
+
secureHeaders,
|
|
14
|
+
withSecureHeaders,
|
|
15
|
+
createZarex as createZarex2,
|
|
16
|
+
PRIVATE_NETWORKS,
|
|
17
|
+
CLOUDFLARE_RANGES
|
|
18
|
+
} from "@zarex/core";
|
|
19
|
+
function zarexBun(options, extra = {}) {
|
|
20
|
+
const isInstance = typeof options.protect === "function";
|
|
21
|
+
const instance = isInstance ? options : createZarex(options);
|
|
22
|
+
const opts = isInstance ? extra : options;
|
|
23
|
+
const finalizer = createWebFinalizer({ secureHeaders: opts.secureHeaders, responseGuard: opts.responseGuard });
|
|
24
|
+
const finalize = async (res, request) => {
|
|
25
|
+
if (!finalizer || !res) return res;
|
|
26
|
+
try {
|
|
27
|
+
return await finalizer(res, request);
|
|
28
|
+
} catch {
|
|
29
|
+
return res;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
return function wrap(handler) {
|
|
33
|
+
return async function fetchWithZarex(request, server) {
|
|
34
|
+
let deny;
|
|
35
|
+
try {
|
|
36
|
+
let socketIp;
|
|
37
|
+
try {
|
|
38
|
+
socketIp = server?.requestIP?.(request)?.address;
|
|
39
|
+
} catch {
|
|
40
|
+
socketIp = void 0;
|
|
41
|
+
}
|
|
42
|
+
let call;
|
|
43
|
+
try {
|
|
44
|
+
call = opts.call?.(request);
|
|
45
|
+
} catch {
|
|
46
|
+
call = void 0;
|
|
47
|
+
}
|
|
48
|
+
({ deny } = await guardWebRequest(instance, request, {
|
|
49
|
+
socketIp,
|
|
50
|
+
...opts.inspectBody ? { inspectBody: true } : {},
|
|
51
|
+
...opts.onDeny ? { onDeny: opts.onDeny } : {},
|
|
52
|
+
...opts.onDegraded ? { onDegraded: opts.onDegraded } : {},
|
|
53
|
+
...call ? { call } : {}
|
|
54
|
+
}));
|
|
55
|
+
} catch {
|
|
56
|
+
deny = void 0;
|
|
57
|
+
}
|
|
58
|
+
return finalize(deny ?? await handler(request, server), request);
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export {
|
|
63
|
+
CLOUDFLARE_RANGES,
|
|
64
|
+
PRIVATE_NETWORKS,
|
|
65
|
+
createZarex2 as createZarex,
|
|
66
|
+
detectBot,
|
|
67
|
+
emailValidation,
|
|
68
|
+
phoneValidation,
|
|
69
|
+
promptInjection,
|
|
70
|
+
rateLimit,
|
|
71
|
+
requestFilter,
|
|
72
|
+
secureHeaders,
|
|
73
|
+
sensitiveInfo,
|
|
74
|
+
shield,
|
|
75
|
+
tokenBucket,
|
|
76
|
+
withSecureHeaders,
|
|
77
|
+
zarexBun
|
|
78
|
+
};
|
|
79
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { createWebFinalizer, createZarex, guardWebRequest, type ResponseGuardOptions, type SecureHeadersOptions, type Decision, type ProtectCall, type WebGuardOptions, type Zarex, type ZarexOptions } from \"@zarex/core\";\r\n\r\n/** Ce que Bun fournit comme second argument de `fetch` : l'adresse de la connexion. */\r\nexport interface BunServerLike {\r\n requestIP(request: Request): { address: string } | null;\r\n}\r\n\r\nexport interface BunZarexOptions extends ZarexOptions {\r\n inspectBody?: boolean;\r\n /** En-têtes de sécurité ajoutés à chaque réponse (true = défauts prudents). */\r\n secureHeaders?: SecureHeadersOptions | boolean;\r\n /** Surveille les réponses : masque les cartes bancaires, clés d'API, etc. */\r\n responseGuard?: ResponseGuardOptions | boolean;\r\n onDeny?: WebGuardOptions[\"onDeny\"];\r\n onDegraded?: WebGuardOptions[\"onDegraded\"];\r\n call?: (request: Request) => ProtectCall | undefined;\r\n}\r\n\r\ntype Fetch<S> = (request: Request, server: S) => Response | Promise<Response> | undefined | Promise<Response | undefined>;\r\n\r\n/**\r\n * Bun.serve({ fetch: zarexBun({ key, baseUrl, ipSource: { proxies: 1 }, rules: [shield()] })(handler) })\r\n *\r\n * Bun donne l'adresse de la connexion (server.requestIP) : toutes les sources d'IP fonctionnent.\r\n * Le résultat de la décision est dans `(request as any).zarex` uniquement si vous le lisez via `onDegraded`.\r\n */\r\nexport function zarexBun(options: BunZarexOptions | Zarex, extra: Pick<BunZarexOptions, \"inspectBody\" | \"onDeny\" | \"onDegraded\" | \"call\" | \"secureHeaders\" | \"responseGuard\"> = {}) {\r\n const isInstance = typeof (options as Zarex).protect === \"function\";\r\n const instance: Zarex = isInstance ? (options as Zarex) : createZarex(options as BunZarexOptions);\r\n const opts = (isInstance ? extra : options) as BunZarexOptions;\r\n\r\n const finalizer = createWebFinalizer({ secureHeaders: opts.secureHeaders, responseGuard: opts.responseGuard });\r\n const finalize = async (res: Response | undefined, request: Request): Promise<Response | undefined> => {\r\n if (!finalizer || !res) return res;\r\n try {\r\n return await finalizer(res, request);\r\n } catch {\r\n return res;\r\n }\r\n };\r\n\r\n return function wrap<S extends BunServerLike>(handler: Fetch<S>): Fetch<S> {\r\n return async function fetchWithZarex(request, server) {\r\n let deny: Response | undefined;\r\n try {\r\n let socketIp: string | undefined;\r\n try {\r\n socketIp = server?.requestIP?.(request)?.address;\r\n } catch {\r\n socketIp = undefined;\r\n }\r\n let call: ProtectCall | undefined;\r\n try {\r\n call = opts.call?.(request);\r\n } catch {\r\n call = undefined;\r\n }\r\n ({ deny } = await guardWebRequest(instance, request, {\r\n socketIp,\r\n ...(opts.inspectBody ? { inspectBody: true } : {}),\r\n ...(opts.onDeny ? { onDeny: opts.onDeny } : {}),\r\n ...(opts.onDegraded ? { onDegraded: opts.onDegraded } : {}),\r\n ...(call ? { call } : {}),\r\n }));\r\n } catch {\r\n deny = undefined;\r\n }\r\n return finalize(deny ?? (await handler(request, server)), request);\r\n };\r\n };\r\n}\r\n\r\nexport {\r\n shield,\r\n rateLimit,\r\n tokenBucket,\r\n detectBot,\r\n requestFilter,\r\n sensitiveInfo,\r\n emailValidation,\r\n phoneValidation,\r\n promptInjection,\r\n secureHeaders,\r\n withSecureHeaders,\r\n createZarex,\r\n PRIVATE_NETWORKS,\r\n CLOUDFLARE_RANGES,\r\n} from \"@zarex/core\";\r\nexport type { SecureHeadersOptions, ResponseGuardOptions, ResponseGuardEvent } from \"@zarex/core\";\r\nexport type { Decision, Zarex, ZarexOptions, IpSource, Rule, ProtectCall } from \"@zarex/core\";"],"mappings":";AAAA,SAAS,oBAAoB,aAAa,uBAAmK;AAwE7M;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,eAAAA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AA7DA,SAAS,SAAS,SAAkC,QAAqH,CAAC,GAAG;AAClL,QAAM,aAAa,OAAQ,QAAkB,YAAY;AACzD,QAAM,WAAkB,aAAc,UAAoB,YAAY,OAA0B;AAChG,QAAM,OAAQ,aAAa,QAAQ;AAEnC,QAAM,YAAY,mBAAmB,EAAE,eAAe,KAAK,eAAe,eAAe,KAAK,cAAc,CAAC;AAC7G,QAAM,WAAW,OAAO,KAA2B,YAAoD;AACrG,QAAI,CAAC,aAAa,CAAC,IAAK,QAAO;AAC/B,QAAI;AACF,aAAO,MAAM,UAAU,KAAK,OAAO;AAAA,IACrC,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO,SAAS,KAA8B,SAA6B;AACzE,WAAO,eAAe,eAAe,SAAS,QAAQ;AACpD,UAAI;AACJ,UAAI;AACF,YAAI;AACJ,YAAI;AACF,qBAAW,QAAQ,YAAY,OAAO,GAAG;AAAA,QAC3C,QAAQ;AACN,qBAAW;AAAA,QACb;AACA,YAAI;AACJ,YAAI;AACF,iBAAO,KAAK,OAAO,OAAO;AAAA,QAC5B,QAAQ;AACN,iBAAO;AAAA,QACT;AACA,SAAC,EAAE,KAAK,IAAI,MAAM,gBAAgB,UAAU,SAAS;AAAA,UACnD;AAAA,UACA,GAAI,KAAK,cAAc,EAAE,aAAa,KAAK,IAAI,CAAC;AAAA,UAChD,GAAI,KAAK,SAAS,EAAE,QAAQ,KAAK,OAAO,IAAI,CAAC;AAAA,UAC7C,GAAI,KAAK,aAAa,EAAE,YAAY,KAAK,WAAW,IAAI,CAAC;AAAA,UACzD,GAAI,OAAO,EAAE,KAAK,IAAI,CAAC;AAAA,QACzB,CAAC;AAAA,MACH,QAAQ;AACN,eAAO;AAAA,MACT;AACA,aAAO,SAAS,QAAS,MAAM,QAAQ,SAAS,MAAM,GAAI,OAAO;AAAA,IACnE;AAAA,EACF;AACF;","names":["createZarex"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zarex/bun",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Zarex — Bun.serve",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"type": "module",
|
|
10
|
+
"main": "./dist/index.cjs",
|
|
11
|
+
"module": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"import": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"default": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"require": {
|
|
20
|
+
"types": "./dist/index.d.cts",
|
|
21
|
+
"default": "./dist/index.cjs"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
28
|
+
"sideEffects": false,
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@zarex/core": "^0.1.0"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsup"
|
|
34
|
+
}
|
|
6
35
|
}
|
package/README.md
DELETED