@arcjet/node 1.0.0-beta.2 → 1.0.0-beta.4
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.js +41 -8
- package/package.json +15 -14
package/index.js
CHANGED
|
@@ -2,12 +2,43 @@ import core__default from 'arcjet';
|
|
|
2
2
|
export * from 'arcjet';
|
|
3
3
|
import findIP from '@arcjet/ip';
|
|
4
4
|
import ArcjetHeaders from '@arcjet/headers';
|
|
5
|
-
import { logLevel,
|
|
5
|
+
import { logLevel, isDevelopment, baseUrl, platform } from '@arcjet/env';
|
|
6
6
|
import { Logger } from '@arcjet/logger';
|
|
7
7
|
import { createClient } from '@arcjet/protocol/client.js';
|
|
8
8
|
import { createTransport } from '@arcjet/transport';
|
|
9
9
|
import { readBody } from '@arcjet/body';
|
|
10
10
|
|
|
11
|
+
// An object with getters that access the `process.env.SOMEVAR` values directly.
|
|
12
|
+
// This allows bundlers to replace the dot-notation access with string literals
|
|
13
|
+
// while still allowing dynamic access in runtime environments.
|
|
14
|
+
// WARNING: This is fragile because any time we add a new key to `Env`, we need
|
|
15
|
+
// to add another getter here.
|
|
16
|
+
const env = {
|
|
17
|
+
get FLY_APP_NAME() {
|
|
18
|
+
return process.env.FLY_APP_NAME;
|
|
19
|
+
},
|
|
20
|
+
get VERCEL() {
|
|
21
|
+
return process.env.VERCEL;
|
|
22
|
+
},
|
|
23
|
+
get MODE() {
|
|
24
|
+
return process.env.MODE;
|
|
25
|
+
},
|
|
26
|
+
get NODE_ENV() {
|
|
27
|
+
return process.env.NODE_ENV;
|
|
28
|
+
},
|
|
29
|
+
get ARCJET_KEY() {
|
|
30
|
+
return process.env.ARCJET_KEY;
|
|
31
|
+
},
|
|
32
|
+
get ARCJET_ENV() {
|
|
33
|
+
return process.env.ARCJET_ENV;
|
|
34
|
+
},
|
|
35
|
+
get ARCJET_LOG_LEVEL() {
|
|
36
|
+
return process.env.ARCJET_LOG_LEVEL;
|
|
37
|
+
},
|
|
38
|
+
get ARCJET_BASE_URL() {
|
|
39
|
+
return process.env.ARCJET_BASE_URL;
|
|
40
|
+
},
|
|
41
|
+
};
|
|
11
42
|
// TODO: Deduplicate with other packages
|
|
12
43
|
function errorMessage(err) {
|
|
13
44
|
if (err) {
|
|
@@ -25,14 +56,14 @@ function errorMessage(err) {
|
|
|
25
56
|
function createRemoteClient(options) {
|
|
26
57
|
// The base URL for the Arcjet API. Will default to the standard production
|
|
27
58
|
// API unless environment variable `ARCJET_BASE_URL` is set.
|
|
28
|
-
const url = options?.baseUrl ?? baseUrl(
|
|
59
|
+
const url = options?.baseUrl ?? baseUrl(env);
|
|
29
60
|
// The timeout for the Arcjet API in milliseconds. This is set to a low value
|
|
30
61
|
// in production so calls fail open.
|
|
31
|
-
const timeout = options?.timeout ?? (isDevelopment(
|
|
62
|
+
const timeout = options?.timeout ?? (isDevelopment(env) ? 1000 : 500);
|
|
32
63
|
// Transport is the HTTP client that the client uses to make requests.
|
|
33
64
|
const transport = createTransport(url);
|
|
34
65
|
const sdkStack = "NODEJS";
|
|
35
|
-
const sdkVersion = "1.0.0-beta.
|
|
66
|
+
const sdkVersion = "1.0.0-beta.4";
|
|
36
67
|
return createClient({
|
|
37
68
|
transport,
|
|
38
69
|
baseUrl: url,
|
|
@@ -64,8 +95,11 @@ function arcjet(options) {
|
|
|
64
95
|
const log = options.log
|
|
65
96
|
? options.log
|
|
66
97
|
: new Logger({
|
|
67
|
-
level: logLevel(
|
|
98
|
+
level: logLevel(env),
|
|
68
99
|
});
|
|
100
|
+
if (isDevelopment(env)) {
|
|
101
|
+
log.warn("Arcjet will use 127.0.0.1 when missing public IP address in development mode");
|
|
102
|
+
}
|
|
69
103
|
function toArcjetRequest(request, props) {
|
|
70
104
|
// We pull the cookies from the request before wrapping them in ArcjetHeaders
|
|
71
105
|
const cookies = cookiesToString(request.headers?.cookie);
|
|
@@ -74,12 +108,11 @@ function arcjet(options) {
|
|
|
74
108
|
let ip = findIP({
|
|
75
109
|
socket: request.socket,
|
|
76
110
|
headers,
|
|
77
|
-
}, { platform: platform(
|
|
111
|
+
}, { platform: platform(env), proxies: options.proxies });
|
|
78
112
|
if (ip === "") {
|
|
79
113
|
// If the `ip` is empty but we're in development mode, we default the IP
|
|
80
114
|
// so the request doesn't fail.
|
|
81
|
-
if (isDevelopment(
|
|
82
|
-
log.warn("Using 127.0.0.1 as IP address in development mode");
|
|
115
|
+
if (isDevelopment(env)) {
|
|
83
116
|
ip = "127.0.0.1";
|
|
84
117
|
}
|
|
85
118
|
else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcjet/node",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.4",
|
|
4
4
|
"description": "Arcjet SDK for Node.js",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://arcjet.com",
|
|
@@ -39,23 +39,24 @@
|
|
|
39
39
|
"test": "node --test --experimental-test-coverage"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@arcjet/env": "1.0.0-beta.
|
|
43
|
-
"@arcjet/headers": "1.0.0-beta.
|
|
44
|
-
"@arcjet/ip": "1.0.0-beta.
|
|
45
|
-
"@arcjet/logger": "1.0.0-beta.
|
|
46
|
-
"@arcjet/protocol": "1.0.0-beta.
|
|
47
|
-
"@arcjet/transport": "1.0.0-beta.
|
|
48
|
-
"@arcjet/body": "1.0.0-beta.
|
|
49
|
-
"arcjet": "1.0.0-beta.
|
|
42
|
+
"@arcjet/env": "1.0.0-beta.4",
|
|
43
|
+
"@arcjet/headers": "1.0.0-beta.4",
|
|
44
|
+
"@arcjet/ip": "1.0.0-beta.4",
|
|
45
|
+
"@arcjet/logger": "1.0.0-beta.4",
|
|
46
|
+
"@arcjet/protocol": "1.0.0-beta.4",
|
|
47
|
+
"@arcjet/transport": "1.0.0-beta.4",
|
|
48
|
+
"@arcjet/body": "1.0.0-beta.4",
|
|
49
|
+
"arcjet": "1.0.0-beta.4"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@arcjet/eslint-config": "1.0.0-beta.
|
|
53
|
-
"@arcjet/rollup-config": "1.0.0-beta.
|
|
54
|
-
"@arcjet/tsconfig": "1.0.0-beta.
|
|
52
|
+
"@arcjet/eslint-config": "1.0.0-beta.4",
|
|
53
|
+
"@arcjet/rollup-config": "1.0.0-beta.4",
|
|
54
|
+
"@arcjet/tsconfig": "1.0.0-beta.4",
|
|
55
55
|
"@types/node": "18.18.0",
|
|
56
|
-
"@rollup/wasm-node": "4.
|
|
56
|
+
"@rollup/wasm-node": "4.35.0",
|
|
57
|
+
"eslint": "9.22.0",
|
|
57
58
|
"expect": "29.7.0",
|
|
58
|
-
"typescript": "5.
|
|
59
|
+
"typescript": "5.8.2"
|
|
59
60
|
},
|
|
60
61
|
"publishConfig": {
|
|
61
62
|
"access": "public",
|