@arcjet/astro 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.
Files changed (3) hide show
  1. package/internal.d.ts +16 -6
  2. package/internal.js +13 -9
  3. package/package.json +12 -12
package/internal.d.ts CHANGED
@@ -4,12 +4,22 @@ type Simplify<T> = {
4
4
  [KeyType in keyof T]: T[KeyType];
5
5
  } & {};
6
6
  declare const emptyObjectSymbol: unique symbol;
7
- type WithoutCustomProps = {
8
- [emptyObjectSymbol]?: never;
9
- };
10
7
  type PlainObject = {
11
8
  [key: string]: unknown;
12
9
  };
10
+ /**
11
+ * Dynamically generate whether zero or one `properties` object must or can be passed.
12
+ */
13
+ type MaybeProperties<T> = {
14
+ [P in keyof T]?: T[P];
15
+ } extends T ? T extends {
16
+ [emptyObjectSymbol]?: never;
17
+ } ? [
18
+ ] : [
19
+ properties?: T
20
+ ] : [
21
+ properties: T
22
+ ];
13
23
  /**
14
24
  * Configuration for {@linkcode createRemoteClient}.
15
25
  */
@@ -77,7 +87,7 @@ export interface ArcjetAstro<Props extends PlainObject> {
77
87
  * Promise that resolves to an {@linkcode ArcjetDecision} indicating
78
88
  * Arcjet’s decision about the request.
79
89
  */
80
- protect(request: Request, ...props: Props extends WithoutCustomProps ? [] : [Props]): Promise<ArcjetDecision>;
90
+ protect(request: Request, ...props: MaybeProperties<Props>): Promise<ArcjetDecision>;
81
91
  /**
82
92
  * Augment the client with another rule.
83
93
  *
@@ -91,7 +101,7 @@ export interface ArcjetAstro<Props extends PlainObject> {
91
101
  * @returns
92
102
  * Arcjet instance augmented with the given rule.
93
103
  */
94
- withRule<Rule extends Primitive | Product>(rule: Rule): ArcjetAstro<Simplify<Props & ExtraProps<Rule>>>;
104
+ withRule<ChildProperties extends PlainObject>(rule: Primitive<ChildProperties> | Product<ChildProperties>): ArcjetAstro<Props & ChildProperties>;
95
105
  }
96
106
  /**
97
107
  * Create a new Astro integration of Arcjet.
@@ -105,4 +115,4 @@ export interface ArcjetAstro<Props extends PlainObject> {
105
115
  * @returns
106
116
  * Astro integration of Arcjet.
107
117
  */
108
- export declare function createArcjetClient<const Rules extends (Primitive | Product)[], const Characteristics extends readonly string[]>(options: ArcjetOptions<Rules, Characteristics>): ArcjetAstro<Simplify<ExtraProps<Rules> & CharacteristicProps<Characteristics>>>;
118
+ export declare function createArcjetClient<const Rules extends (Primitive | Product)[], const Characteristics extends readonly string[]>(options: ArcjetOptions<Rules, Characteristics>): ArcjetAstro<ExtraProps<Rules> & CharacteristicProps<Characteristics>>;
package/internal.js CHANGED
@@ -9,6 +9,7 @@ import { createClient } from '@arcjet/protocol/client.js';
9
9
  import { createTransport } from '@arcjet/transport';
10
10
  import { VERCEL, RENDER, FLY_APP_NAME, FIREBASE_CONFIG, ARCJET_LOG_LEVEL, ARCJET_KEY, ARCJET_ENV, ARCJET_BASE_URL } from 'astro:env/server';
11
11
 
12
+ let warnedForAutomaticBodyRead = false;
12
13
  // We use a middleware to store the IP address on a `Request` with this symbol.
13
14
  // This is due to Astro inconsistently using `Symbol.for("astro.clientAddress")`
14
15
  // to store the client address and not exporting it from their module.
@@ -39,7 +40,7 @@ function createRemoteClient(options) {
39
40
  // Transport is the HTTP client that the client uses to make requests.
40
41
  const transport = createTransport(url);
41
42
  const sdkStack = "ASTRO";
42
- const sdkVersion = "1.0.0-beta.17";
43
+ const sdkVersion = "1.0.0-beta.18";
43
44
  return createClient({
44
45
  transport,
45
46
  baseUrl: url,
@@ -78,7 +79,7 @@ function createArcjetClient(options) {
78
79
  if (!clientAddress) {
79
80
  throw new Error("`protect()` cannot be used in prerendered pages");
80
81
  }
81
- const cookies = request.headers.get("cookie") ?? undefined;
82
+ const cookies = request.headers.get("cookie") ?? "";
82
83
  // We construct an ArcjetHeaders to normalize over Headers
83
84
  const headers = new ArcjetHeaders(request.headers);
84
85
  const url = new URL(request.url);
@@ -110,16 +111,14 @@ function createArcjetClient(options) {
110
111
  };
111
112
  }
112
113
  function withClient(aj) {
113
- return Object.freeze({
114
+ const client = {
114
115
  withRule(rule) {
115
116
  const client = aj.withRule(rule);
116
117
  return withClient(client);
117
118
  },
118
- async protect(request, ...[props]) {
119
- // TODO(#220): The generic manipulations get really mad here, so we cast
120
- // Further investigation makes it seem like it has something to do with
121
- // the definition of `props` in the signature but it's hard to track down
122
- const req = toArcjetRequest(request, props ?? {});
119
+ async protect(request, props) {
120
+ // Cast of `{}` because here we switch from `undefined` to `Properties`.
121
+ const req = toArcjetRequest(request, props || {});
123
122
  const getBody = async () => {
124
123
  const clonedRequest = request.clone();
125
124
  let expectedLength;
@@ -131,11 +130,16 @@ function createArcjetClient(options) {
131
130
  if (!clonedRequest.body) {
132
131
  throw new Error("Cannot read body: body is missing");
133
132
  }
133
+ if (!warnedForAutomaticBodyRead) {
134
+ warnedForAutomaticBodyRead = true;
135
+ log.warn("Automatically reading the request body is deprecated; please pass an explicit `sensitiveInfoValue` field. See <https://docs.arcjet.com/upgrading/sdk-migration>.");
136
+ }
134
137
  return readBodyWeb(clonedRequest.body, { expectedLength });
135
138
  };
136
139
  return aj.protect({ getBody }, req);
137
140
  },
138
- });
141
+ };
142
+ return Object.freeze(client);
139
143
  }
140
144
  const aj = core__default({ ...options, client, log });
141
145
  return withClient(aj);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcjet/astro",
3
- "version": "1.0.0-beta.17",
3
+ "version": "1.0.0-beta.18",
4
4
  "description": "Arcjet helps developers protect their Astro sites in just a few lines of code. Bot detection. Rate limiting. Email validation. Attack protection. Data redaction. A developer-first approach to security.",
5
5
  "keywords": [
6
6
  "analyze",
@@ -52,23 +52,23 @@
52
52
  "test": "npm run build && npm run lint && npm run test-coverage"
53
53
  },
54
54
  "dependencies": {
55
- "@arcjet/body": "1.0.0-beta.17",
56
- "@arcjet/env": "1.0.0-beta.17",
57
- "@arcjet/headers": "1.0.0-beta.17",
58
- "@arcjet/ip": "1.0.0-beta.17",
59
- "@arcjet/logger": "1.0.0-beta.17",
60
- "@arcjet/protocol": "1.0.0-beta.17",
61
- "@arcjet/transport": "1.0.0-beta.17",
62
- "arcjet": "1.0.0-beta.17"
55
+ "@arcjet/body": "1.0.0-beta.18",
56
+ "@arcjet/env": "1.0.0-beta.18",
57
+ "@arcjet/headers": "1.0.0-beta.18",
58
+ "@arcjet/ip": "1.0.0-beta.18",
59
+ "@arcjet/logger": "1.0.0-beta.18",
60
+ "@arcjet/protocol": "1.0.0-beta.18",
61
+ "@arcjet/transport": "1.0.0-beta.18",
62
+ "arcjet": "1.0.0-beta.18"
63
63
  },
64
64
  "peerDependencies": {
65
65
  "astro": "^5.9.3"
66
66
  },
67
67
  "devDependencies": {
68
- "@arcjet/eslint-config": "1.0.0-beta.17",
69
- "@arcjet/rollup-config": "1.0.0-beta.17",
68
+ "@arcjet/eslint-config": "1.0.0-beta.18",
69
+ "@arcjet/rollup-config": "1.0.0-beta.18",
70
70
  "@rollup/wasm-node": "4.55.1",
71
- "astro": "5.16.6",
71
+ "astro": "5.16.9",
72
72
  "eslint": "9.39.2",
73
73
  "typescript": "5.9.3"
74
74
  },