@arcjet/bun 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.
Files changed (4) hide show
  1. package/index.d.ts +6 -2
  2. package/index.js +11 -12
  3. package/index.ts +13 -15
  4. package/package.json +11 -10
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /// <reference types="bun-types/bun.d.ts" />
2
- import { ArcjetDecision, ArcjetOptions, Primitive, Product, ExtraProps, RemoteClient, RemoteClientOptions } from "arcjet";
2
+ import { ArcjetDecision, ArcjetOptions, Primitive, Product, ExtraProps } from "arcjet";
3
3
  import type { Server } from "bun";
4
4
  export * from "arcjet";
5
5
  type Simplify<T> = {
@@ -12,7 +12,11 @@ type WithoutCustomProps = {
12
12
  type PlainObject = {
13
13
  [key: string]: unknown;
14
14
  };
15
- export declare function createBunRemoteClient(options?: Partial<RemoteClientOptions>): RemoteClient;
15
+ export type RemoteClientOptions = {
16
+ baseUrl?: string;
17
+ timeout?: number;
18
+ };
19
+ export declare function createRemoteClient(options?: RemoteClientOptions): import("@arcjet/protocol/client.js").Client;
16
20
  /**
17
21
  * The ArcjetBun client provides a public `protect()` method to
18
22
  * make a decision about how a Bun.sh request should be handled.
package/index.js CHANGED
@@ -1,14 +1,15 @@
1
1
  import { createConnectTransport } from '@connectrpc/connect-node';
2
- import core__default, { createRemoteClient } from 'arcjet';
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 { env } from 'bun';
7
7
  import { logLevel, baseUrl, isProduction, platform, isDevelopment } from '@arcjet/env';
8
8
  import { Logger } from '@arcjet/logger';
9
+ import { createClient } from '@arcjet/protocol/client.js';
9
10
 
10
11
  /// <reference types="bun-types/bun.d.ts" />
11
- function createBunRemoteClient(options) {
12
+ function createRemoteClient(options) {
12
13
  // The base URL for the Arcjet API. Will default to the standard production
13
14
  // API unless environment variable `ARCJET_BASE_URL` is set.
14
15
  const url = options?.baseUrl ?? baseUrl(env);
@@ -16,15 +17,13 @@ function createBunRemoteClient(options) {
16
17
  // in production so calls fail open.
17
18
  const timeout = options?.timeout ?? (isProduction(env) ? 500 : 1000);
18
19
  // Transport is the HTTP client that the client uses to make requests.
19
- const transport = options?.transport ??
20
- createConnectTransport({
21
- baseUrl: url,
22
- httpVersion: "1.1",
23
- });
24
- // TODO(#223): Create separate options type to exclude these
20
+ const transport = createConnectTransport({
21
+ baseUrl: url,
22
+ httpVersion: "1.1",
23
+ });
25
24
  const sdkStack = "BUN";
26
- const sdkVersion = "1.0.0-alpha.14";
27
- return createRemoteClient({
25
+ const sdkVersion = "1.0.0-alpha.16";
26
+ return createClient({
28
27
  transport,
29
28
  baseUrl: url,
30
29
  timeout,
@@ -101,7 +100,7 @@ function withClient(aj) {
101
100
  * @param options - Arcjet configuration options to apply to all requests.
102
101
  */
103
102
  function arcjet(options) {
104
- const client = options.client ?? createBunRemoteClient();
103
+ const client = options.client ?? createRemoteClient();
105
104
  const log = options.log
106
105
  ? options.log
107
106
  : new Logger({
@@ -111,4 +110,4 @@ function arcjet(options) {
111
110
  return withClient(aj);
112
111
  }
113
112
 
114
- export { createBunRemoteClient, arcjet as default };
113
+ export { createRemoteClient, arcjet as default };
package/index.ts CHANGED
@@ -7,9 +7,6 @@ import core, {
7
7
  Product,
8
8
  ArcjetRequest,
9
9
  ExtraProps,
10
- RemoteClient,
11
- RemoteClientOptions,
12
- createRemoteClient,
13
10
  Arcjet,
14
11
  } from "arcjet";
15
12
  import findIP from "@arcjet/ip";
@@ -24,6 +21,7 @@ import {
24
21
  platform,
25
22
  } from "@arcjet/env";
26
23
  import { Logger } from "@arcjet/logger";
24
+ import { createClient } from "@arcjet/protocol/client.js";
27
25
 
28
26
  // Re-export all named exports from the generic SDK
29
27
  export * from "arcjet";
@@ -65,9 +63,12 @@ type PlainObject = {
65
63
  [key: string]: unknown;
66
64
  };
67
65
 
68
- export function createBunRemoteClient(
69
- options?: Partial<RemoteClientOptions>,
70
- ): RemoteClient {
66
+ export type RemoteClientOptions = {
67
+ baseUrl?: string;
68
+ timeout?: number;
69
+ };
70
+
71
+ export function createRemoteClient(options?: RemoteClientOptions) {
71
72
  // The base URL for the Arcjet API. Will default to the standard production
72
73
  // API unless environment variable `ARCJET_BASE_URL` is set.
73
74
  const url = options?.baseUrl ?? baseUrl(env);
@@ -77,18 +78,15 @@ export function createBunRemoteClient(
77
78
  const timeout = options?.timeout ?? (isProduction(env) ? 500 : 1000);
78
79
 
79
80
  // Transport is the HTTP client that the client uses to make requests.
80
- const transport =
81
- options?.transport ??
82
- createConnectTransport({
83
- baseUrl: url,
84
- httpVersion: "1.1",
85
- });
81
+ const transport = createConnectTransport({
82
+ baseUrl: url,
83
+ httpVersion: "1.1",
84
+ });
86
85
 
87
- // TODO(#223): Create separate options type to exclude these
88
86
  const sdkStack = "BUN";
89
87
  const sdkVersion = "__ARCJET_SDK_VERSION__";
90
88
 
91
- return createRemoteClient({
89
+ return createClient({
92
90
  transport,
93
91
  baseUrl: url,
94
92
  timeout,
@@ -255,7 +253,7 @@ function withClient<const Rules extends (Primitive | Product)[]>(
255
253
  export default function arcjet<const Rules extends (Primitive | Product)[]>(
256
254
  options: ArcjetOptions<Rules>,
257
255
  ): ArcjetBun<Simplify<ExtraProps<Rules>>> {
258
- const client = options.client ?? createBunRemoteClient();
256
+ const client = options.client ?? createRemoteClient();
259
257
 
260
258
  const log = options.log
261
259
  ? options.log
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcjet/bun",
3
- "version": "1.0.0-alpha.14",
3
+ "version": "1.0.0-alpha.16",
4
4
  "description": "Arcjet SDK for Bun.sh",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://arcjet.com",
@@ -38,21 +38,22 @@
38
38
  "test": "NODE_OPTIONS=--experimental-vm-modules jest --passWithNoTests"
39
39
  },
40
40
  "dependencies": {
41
- "@arcjet/env": "1.0.0-alpha.14",
42
- "@arcjet/headers": "1.0.0-alpha.14",
43
- "@arcjet/ip": "1.0.0-alpha.14",
44
- "@arcjet/logger": "1.0.0-alpha.14",
41
+ "@arcjet/env": "1.0.0-alpha.16",
42
+ "@arcjet/headers": "1.0.0-alpha.16",
43
+ "@arcjet/ip": "1.0.0-alpha.16",
44
+ "@arcjet/logger": "1.0.0-alpha.16",
45
+ "@arcjet/protocol": "1.0.0-alpha.16",
45
46
  "@connectrpc/connect-node": "1.4.0",
46
- "arcjet": "1.0.0-alpha.14"
47
+ "arcjet": "1.0.0-alpha.16"
47
48
  },
48
49
  "devDependencies": {
49
- "@arcjet/eslint-config": "1.0.0-alpha.14",
50
- "@arcjet/rollup-config": "1.0.0-alpha.14",
51
- "@arcjet/tsconfig": "1.0.0-alpha.14",
50
+ "@arcjet/eslint-config": "1.0.0-alpha.16",
51
+ "@arcjet/rollup-config": "1.0.0-alpha.16",
52
+ "@arcjet/tsconfig": "1.0.0-alpha.16",
52
53
  "@jest/globals": "29.7.0",
53
54
  "@types/node": "20.12.12",
54
55
  "@rollup/wasm-node": "4.18.0",
55
- "bun-types": "1.1.12",
56
+ "bun-types": "1.1.13",
56
57
  "jest": "29.7.0",
57
58
  "typescript": "5.4.5"
58
59
  },