@arcjet/node 1.0.0-alpha.14 → 1.0.0-alpha.16
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 +6 -2
- package/index.js +11 -12
- package/index.ts +13 -15
- package/package.json +10 -9
package/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ArcjetDecision, ArcjetOptions, Primitive, Product, ExtraProps
|
|
1
|
+
import { ArcjetDecision, ArcjetOptions, Primitive, Product, ExtraProps } from "arcjet";
|
|
2
2
|
export * from "arcjet";
|
|
3
3
|
type Simplify<T> = {
|
|
4
4
|
[KeyType in keyof T]: T[KeyType];
|
|
@@ -10,7 +10,11 @@ type WithoutCustomProps = {
|
|
|
10
10
|
type PlainObject = {
|
|
11
11
|
[key: string]: unknown;
|
|
12
12
|
};
|
|
13
|
-
export
|
|
13
|
+
export type RemoteClientOptions = {
|
|
14
|
+
baseUrl?: string;
|
|
15
|
+
timeout?: number;
|
|
16
|
+
};
|
|
17
|
+
export declare function createRemoteClient(options?: RemoteClientOptions): import("@arcjet/protocol/client.js").Client;
|
|
14
18
|
export interface ArcjetNodeRequest {
|
|
15
19
|
headers?: Record<string, string | string[] | undefined>;
|
|
16
20
|
socket?: Partial<{
|
package/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { createConnectTransport } from '@connectrpc/connect-node';
|
|
2
|
-
import core__default
|
|
2
|
+
import core__default from 'arcjet';
|
|
3
3
|
export * from 'arcjet';
|
|
4
4
|
import findIP from '@arcjet/ip';
|
|
5
5
|
import ArcjetHeaders from '@arcjet/headers';
|
|
6
6
|
import { logLevel, baseUrl, isProduction, platform, isDevelopment } from '@arcjet/env';
|
|
7
7
|
import { Logger } from '@arcjet/logger';
|
|
8
|
+
import { createClient } from '@arcjet/protocol/client.js';
|
|
8
9
|
|
|
9
|
-
function
|
|
10
|
+
function createRemoteClient(options) {
|
|
10
11
|
// The base URL for the Arcjet API. Will default to the standard production
|
|
11
12
|
// API unless environment variable `ARCJET_BASE_URL` is set.
|
|
12
13
|
const url = options?.baseUrl ?? baseUrl(process.env);
|
|
@@ -14,15 +15,13 @@ function createNodeRemoteClient(options) {
|
|
|
14
15
|
// in production so calls fail open.
|
|
15
16
|
const timeout = options?.timeout ?? (isProduction(process.env) ? 500 : 1000);
|
|
16
17
|
// Transport is the HTTP client that the client uses to make requests.
|
|
17
|
-
const transport =
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
});
|
|
22
|
-
// TODO(#223): Create separate options type to exclude these
|
|
18
|
+
const transport = createConnectTransport({
|
|
19
|
+
baseUrl: url,
|
|
20
|
+
httpVersion: "2",
|
|
21
|
+
});
|
|
23
22
|
const sdkStack = "NODEJS";
|
|
24
|
-
const sdkVersion = "1.0.0-alpha.
|
|
25
|
-
return
|
|
23
|
+
const sdkVersion = "1.0.0-alpha.16";
|
|
24
|
+
return createClient({
|
|
26
25
|
transport,
|
|
27
26
|
baseUrl: url,
|
|
28
27
|
timeout,
|
|
@@ -120,7 +119,7 @@ function withClient(aj) {
|
|
|
120
119
|
* @param options - Arcjet configuration options to apply to all requests.
|
|
121
120
|
*/
|
|
122
121
|
function arcjet(options) {
|
|
123
|
-
const client = options.client ??
|
|
122
|
+
const client = options.client ?? createRemoteClient();
|
|
124
123
|
const log = options.log
|
|
125
124
|
? options.log
|
|
126
125
|
: new Logger({
|
|
@@ -130,4 +129,4 @@ function arcjet(options) {
|
|
|
130
129
|
return withClient(aj);
|
|
131
130
|
}
|
|
132
131
|
|
|
133
|
-
export {
|
|
132
|
+
export { createRemoteClient, arcjet as default };
|
package/index.ts
CHANGED
|
@@ -6,9 +6,6 @@ import core, {
|
|
|
6
6
|
Product,
|
|
7
7
|
ArcjetRequest,
|
|
8
8
|
ExtraProps,
|
|
9
|
-
RemoteClient,
|
|
10
|
-
RemoteClientOptions,
|
|
11
|
-
createRemoteClient,
|
|
12
9
|
Arcjet,
|
|
13
10
|
} from "arcjet";
|
|
14
11
|
import findIP from "@arcjet/ip";
|
|
@@ -21,6 +18,7 @@ import {
|
|
|
21
18
|
platform,
|
|
22
19
|
} from "@arcjet/env";
|
|
23
20
|
import { Logger } from "@arcjet/logger";
|
|
21
|
+
import { createClient } from "@arcjet/protocol/client.js";
|
|
24
22
|
|
|
25
23
|
// Re-export all named exports from the generic SDK
|
|
26
24
|
export * from "arcjet";
|
|
@@ -62,9 +60,12 @@ type PlainObject = {
|
|
|
62
60
|
[key: string]: unknown;
|
|
63
61
|
};
|
|
64
62
|
|
|
65
|
-
export
|
|
66
|
-
|
|
67
|
-
|
|
63
|
+
export type RemoteClientOptions = {
|
|
64
|
+
baseUrl?: string;
|
|
65
|
+
timeout?: number;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export function createRemoteClient(options?: RemoteClientOptions) {
|
|
68
69
|
// The base URL for the Arcjet API. Will default to the standard production
|
|
69
70
|
// API unless environment variable `ARCJET_BASE_URL` is set.
|
|
70
71
|
const url = options?.baseUrl ?? baseUrl(process.env);
|
|
@@ -74,18 +75,15 @@ export function createNodeRemoteClient(
|
|
|
74
75
|
const timeout = options?.timeout ?? (isProduction(process.env) ? 500 : 1000);
|
|
75
76
|
|
|
76
77
|
// Transport is the HTTP client that the client uses to make requests.
|
|
77
|
-
const transport =
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
httpVersion: "2",
|
|
82
|
-
});
|
|
78
|
+
const transport = createConnectTransport({
|
|
79
|
+
baseUrl: url,
|
|
80
|
+
httpVersion: "2",
|
|
81
|
+
});
|
|
83
82
|
|
|
84
|
-
// TODO(#223): Create separate options type to exclude these
|
|
85
83
|
const sdkStack = "NODEJS";
|
|
86
84
|
const sdkVersion = "__ARCJET_SDK_VERSION__";
|
|
87
85
|
|
|
88
|
-
return
|
|
86
|
+
return createClient({
|
|
89
87
|
transport,
|
|
90
88
|
baseUrl: url,
|
|
91
89
|
timeout,
|
|
@@ -249,7 +247,7 @@ function withClient<const Rules extends (Primitive | Product)[]>(
|
|
|
249
247
|
export default function arcjet<const Rules extends (Primitive | Product)[]>(
|
|
250
248
|
options: ArcjetOptions<Rules>,
|
|
251
249
|
): ArcjetNode<Simplify<ExtraProps<Rules>>> {
|
|
252
|
-
const client = options.client ??
|
|
250
|
+
const client = options.client ?? createRemoteClient();
|
|
253
251
|
|
|
254
252
|
const log = options.log
|
|
255
253
|
? options.log
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcjet/node",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.16",
|
|
4
4
|
"description": "Arcjet SDK for Node.js",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://arcjet.com",
|
|
@@ -40,17 +40,18 @@
|
|
|
40
40
|
"test": "NODE_OPTIONS=--experimental-vm-modules jest --passWithNoTests"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@arcjet/env": "1.0.0-alpha.
|
|
44
|
-
"@arcjet/headers": "1.0.0-alpha.
|
|
45
|
-
"@arcjet/ip": "1.0.0-alpha.
|
|
46
|
-
"@arcjet/logger": "1.0.0-alpha.
|
|
43
|
+
"@arcjet/env": "1.0.0-alpha.16",
|
|
44
|
+
"@arcjet/headers": "1.0.0-alpha.16",
|
|
45
|
+
"@arcjet/ip": "1.0.0-alpha.16",
|
|
46
|
+
"@arcjet/logger": "1.0.0-alpha.16",
|
|
47
|
+
"@arcjet/protocol": "1.0.0-alpha.16",
|
|
47
48
|
"@connectrpc/connect-node": "1.4.0",
|
|
48
|
-
"arcjet": "1.0.0-alpha.
|
|
49
|
+
"arcjet": "1.0.0-alpha.16"
|
|
49
50
|
},
|
|
50
51
|
"devDependencies": {
|
|
51
|
-
"@arcjet/eslint-config": "1.0.0-alpha.
|
|
52
|
-
"@arcjet/rollup-config": "1.0.0-alpha.
|
|
53
|
-
"@arcjet/tsconfig": "1.0.0-alpha.
|
|
52
|
+
"@arcjet/eslint-config": "1.0.0-alpha.16",
|
|
53
|
+
"@arcjet/rollup-config": "1.0.0-alpha.16",
|
|
54
|
+
"@arcjet/tsconfig": "1.0.0-alpha.16",
|
|
54
55
|
"@jest/globals": "29.7.0",
|
|
55
56
|
"@types/node": "18.18.0",
|
|
56
57
|
"@rollup/wasm-node": "4.18.0",
|