@arcjet/bun 1.0.0-beta.17 → 1.0.0-beta.18
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/index.d.ts +16 -6
- package/index.js +13 -9
- package/package.json +13 -13
package/index.d.ts
CHANGED
|
@@ -5,12 +5,22 @@ type Simplify<T> = {
|
|
|
5
5
|
[KeyType in keyof T]: T[KeyType];
|
|
6
6
|
} & {};
|
|
7
7
|
declare const emptyObjectSymbol: unique symbol;
|
|
8
|
-
type WithoutCustomProps = {
|
|
9
|
-
[emptyObjectSymbol]?: never;
|
|
10
|
-
};
|
|
11
8
|
type PlainObject = {
|
|
12
9
|
[key: string]: unknown;
|
|
13
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* Dynamically generate whether zero or one `properties` object must or can be passed.
|
|
13
|
+
*/
|
|
14
|
+
type MaybeProperties<T> = {
|
|
15
|
+
[P in keyof T]?: T[P];
|
|
16
|
+
} extends T ? T extends {
|
|
17
|
+
[emptyObjectSymbol]?: never;
|
|
18
|
+
} ? [
|
|
19
|
+
] : [
|
|
20
|
+
properties?: T
|
|
21
|
+
] : [
|
|
22
|
+
properties: T
|
|
23
|
+
];
|
|
14
24
|
/**
|
|
15
25
|
* Configuration for {@linkcode createRemoteClient}.
|
|
16
26
|
*/
|
|
@@ -80,7 +90,7 @@ export interface ArcjetBun<Props extends PlainObject> {
|
|
|
80
90
|
* Promise that resolves to an {@linkcode ArcjetDecision} indicating
|
|
81
91
|
* Arcjet’s decision about the request.
|
|
82
92
|
*/
|
|
83
|
-
protect(request: Request, ...
|
|
93
|
+
protect(request: Request, ...properties: MaybeProperties<Props>): Promise<ArcjetDecision>;
|
|
84
94
|
/**
|
|
85
95
|
* Augment the client with another rule.
|
|
86
96
|
*
|
|
@@ -94,7 +104,7 @@ export interface ArcjetBun<Props extends PlainObject> {
|
|
|
94
104
|
* @returns
|
|
95
105
|
* Arcjet instance augmented with the given rule.
|
|
96
106
|
*/
|
|
97
|
-
withRule<
|
|
107
|
+
withRule<ChildProperties extends PlainObject>(rule: Primitive<ChildProperties> | Product<ChildProperties>): ArcjetBun<Props & ChildProperties>;
|
|
98
108
|
/**
|
|
99
109
|
* Wrap the Bun `fetch` handler to provide additional details when calling
|
|
100
110
|
* the `protect()` method.
|
|
@@ -118,4 +128,4 @@ export interface ArcjetBun<Props extends PlainObject> {
|
|
|
118
128
|
* @returns
|
|
119
129
|
* Bun integration of Arcjet.
|
|
120
130
|
*/
|
|
121
|
-
export default function arcjet<const Rules extends (Primitive | Product)[], const Characteristics extends readonly string[]>(options: ArcjetOptions<Rules, Characteristics>): ArcjetBun<
|
|
131
|
+
export default function arcjet<const Rules extends (Primitive | Product)[], const Characteristics extends readonly string[]>(options: ArcjetOptions<Rules, Characteristics>): ArcjetBun<ExtraProps<Rules> & CharacteristicProps<Characteristics>>;
|
package/index.js
CHANGED
|
@@ -11,6 +11,7 @@ import { createClient } from '@arcjet/protocol/client.js';
|
|
|
11
11
|
import { createTransport } from '@arcjet/transport';
|
|
12
12
|
|
|
13
13
|
/// <reference types="bun-types" />
|
|
14
|
+
let warnedForAutomaticBodyRead = false;
|
|
14
15
|
/**
|
|
15
16
|
* Create a remote client.
|
|
16
17
|
*
|
|
@@ -25,7 +26,7 @@ function createRemoteClient(options) {
|
|
|
25
26
|
// Transport is the HTTP client that the client uses to make requests.
|
|
26
27
|
const transport = createTransport(url);
|
|
27
28
|
const sdkStack = "BUN";
|
|
28
|
-
const sdkVersion = "1.0.0-beta.
|
|
29
|
+
const sdkVersion = "1.0.0-beta.18";
|
|
29
30
|
return createClient({
|
|
30
31
|
transport,
|
|
31
32
|
baseUrl: url,
|
|
@@ -64,7 +65,7 @@ function arcjet(options) {
|
|
|
64
65
|
log.warn("Arcjet will use 127.0.0.1 when missing public IP address in development mode");
|
|
65
66
|
}
|
|
66
67
|
function toArcjetRequest(request, props) {
|
|
67
|
-
const cookies = request.headers.get("cookie") ??
|
|
68
|
+
const cookies = request.headers.get("cookie") ?? "";
|
|
68
69
|
// We construct an ArcjetHeaders to normalize over Headers
|
|
69
70
|
const headers = new ArcjetHeaders(request.headers);
|
|
70
71
|
const url = new URL(request.url);
|
|
@@ -102,16 +103,14 @@ function arcjet(options) {
|
|
|
102
103
|
};
|
|
103
104
|
}
|
|
104
105
|
function withClient(aj) {
|
|
105
|
-
|
|
106
|
+
const client = {
|
|
106
107
|
withRule(rule) {
|
|
107
108
|
const client = aj.withRule(rule);
|
|
108
109
|
return withClient(client);
|
|
109
110
|
},
|
|
110
|
-
async protect(request,
|
|
111
|
-
//
|
|
112
|
-
|
|
113
|
-
// the definition of `props` in the signature but it's hard to track down
|
|
114
|
-
const req = toArcjetRequest(request, props ?? {});
|
|
111
|
+
async protect(request, props) {
|
|
112
|
+
// Cast of `{}` because here we switch from `undefined` to `Properties`.
|
|
113
|
+
const req = toArcjetRequest(request, props || {});
|
|
115
114
|
const getBody = async () => {
|
|
116
115
|
if (request.bodyUsed) {
|
|
117
116
|
throw new Error("Cannot read body: already read");
|
|
@@ -126,6 +125,10 @@ function arcjet(options) {
|
|
|
126
125
|
if (!clonedRequest.body) {
|
|
127
126
|
throw new Error("Cannot read body: body is missing");
|
|
128
127
|
}
|
|
128
|
+
if (!warnedForAutomaticBodyRead) {
|
|
129
|
+
warnedForAutomaticBodyRead = true;
|
|
130
|
+
log.warn("Automatically reading the request body is deprecated; please pass an explicit `sensitiveInfoValue` field. See <https://docs.arcjet.com/upgrading/sdk-migration>.");
|
|
131
|
+
}
|
|
129
132
|
return readBodyWeb(clonedRequest.body, { expectedLength });
|
|
130
133
|
};
|
|
131
134
|
return aj.protect({ getBody }, req);
|
|
@@ -139,7 +142,8 @@ function arcjet(options) {
|
|
|
139
142
|
return fetch.call(server, request, server);
|
|
140
143
|
};
|
|
141
144
|
},
|
|
142
|
-
}
|
|
145
|
+
};
|
|
146
|
+
return Object.freeze(client);
|
|
143
147
|
}
|
|
144
148
|
const aj = core__default({ ...options, client, log });
|
|
145
149
|
return withClient(aj);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcjet/bun",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.18",
|
|
4
4
|
"description": "Arcjet SDK for Bun",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"analyze",
|
|
@@ -45,23 +45,23 @@
|
|
|
45
45
|
"test": "npm run build && npm run lint"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@arcjet/body": "1.0.0-beta.
|
|
49
|
-
"@arcjet/env": "1.0.0-beta.
|
|
50
|
-
"@arcjet/headers": "1.0.0-beta.
|
|
51
|
-
"@arcjet/ip": "1.0.0-beta.
|
|
52
|
-
"@arcjet/logger": "1.0.0-beta.
|
|
53
|
-
"@arcjet/protocol": "1.0.0-beta.
|
|
54
|
-
"@arcjet/transport": "1.0.0-beta.
|
|
55
|
-
"arcjet": "1.0.0-beta.
|
|
48
|
+
"@arcjet/body": "1.0.0-beta.18",
|
|
49
|
+
"@arcjet/env": "1.0.0-beta.18",
|
|
50
|
+
"@arcjet/headers": "1.0.0-beta.18",
|
|
51
|
+
"@arcjet/ip": "1.0.0-beta.18",
|
|
52
|
+
"@arcjet/logger": "1.0.0-beta.18",
|
|
53
|
+
"@arcjet/protocol": "1.0.0-beta.18",
|
|
54
|
+
"@arcjet/transport": "1.0.0-beta.18",
|
|
55
|
+
"arcjet": "1.0.0-beta.18"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@arcjet/eslint-config": "1.0.0-beta.
|
|
59
|
-
"@arcjet/rollup-config": "1.0.0-beta.
|
|
58
|
+
"@arcjet/eslint-config": "1.0.0-beta.18",
|
|
59
|
+
"@arcjet/rollup-config": "1.0.0-beta.18",
|
|
60
60
|
"@rollup/wasm-node": "4.55.1",
|
|
61
|
-
"bun-types": "1.3.
|
|
61
|
+
"bun-types": "1.3.6",
|
|
62
62
|
"eslint": "9.39.2",
|
|
63
63
|
"typescript": "5.9.3",
|
|
64
|
-
"undici-types": "7.18.
|
|
64
|
+
"undici-types": "7.18.2"
|
|
65
65
|
},
|
|
66
66
|
"publishConfig": {
|
|
67
67
|
"access": "public",
|