@arcjet/analyze-wasm 1.0.0-beta.1 → 1.0.0-beta.10

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/README.md CHANGED
@@ -22,41 +22,64 @@ against common attacks.
22
22
 
23
23
  This package provides WebAssembly bindings to [Arcjet's][arcjet] local analysis engine.
24
24
 
25
- ## Installation
25
+ - [npm package (`@arcjet/analyze-wasm`)](https://www.npmjs.com/package/@arcjet/analyze-wasm)
26
+ - [GitHub source code (`analyze-wasm/` in `arcjet/arcjet-js`)](https://github.com/arcjet/arcjet-js/tree/main/analyze-wasm)
26
27
 
27
- ```shell
28
- npm install -S @arcjet/analyze-wasm
29
- ```
28
+ ## What is this?
29
+
30
+ This package provides logic in WebAssembly to locally analyze requests.
31
+
32
+ To load these binary files everywhere until something like
33
+ [_Import Bytes_][tc39-proposal-import-bytes] is available,
34
+ we settled on a technique that seems to work well everywhere.
35
+ This technique gives us compatibility with for example Next.js which right now
36
+ requires a special experimental `asyncWebAssembly` webpack configuration,
37
+
38
+ The file `_virtual/arcjet_analyze_js_req.component.core.js` contains the
39
+ WebAssembly inlined as a [`data:` URL][mdn-data-url].
40
+ This is about 3 times smaller than using a `Uint8Array` (see
41
+ [_Better Binary Batter: Mixing Base64 and Uint8Array_][wasm-base64-blog] for more
42
+ info).
43
+ That URL is then turned into an `ArrayBuffer` and passed to
44
+ `WebAssembly.compile`.
30
45
 
31
- ## Implementation
46
+ The files here are generated.
47
+ They are wrapped up into [`@arcjet/analyze`][github-arcjet-analyze] for use in
48
+ JavaScript,
49
+ in turn exposed in our core package
50
+ ([`arcjet`][github-arcjet-arcjet])
51
+ and our adapters (such as `@arcjet/next`).
32
52
 
33
- This package provides analyze logic implemented as a WebAssembly module which
34
- will run local analysis on request details.
53
+ <!-- TODO(@wooorm-arcjet): link `adapters` above when the main repo is up to date. -->
35
54
 
36
- The `_virtual/arcjet_analyze_js_req.component.core.js` file contains the binary inlined as
37
- a base64 [Data URL][mdn-data-url] with the `application/wasm` MIME type.
55
+ ## When should I use this?
38
56
 
39
- This was chosen to save on storage space over inlining the file directly as a
40
- Uint8Array, which would take up ~3x the space of the Wasm file. See
41
- [Better Binary Batter: Mixing Base64 and Uint8Array][wasm-base64-blog] for more
42
- details.
57
+ This is an internal Arcjet package not designed for public use.
58
+ See our [_Get started_ guide][arcjet-get-started] for how to use Arcjet in your
59
+ application.
43
60
 
44
- It is then decoded into an ArrayBuffer to be used directly via WebAssembly's
45
- `compile()` function in our entry point file.
61
+ ## Install
62
+
63
+ This package is ESM only.
64
+ Install with npm in Node.js:
65
+
66
+ ```sh
67
+ npm install @arcjet/analyze-wasm
68
+ ```
46
69
 
47
- This is all done to avoid trying to read or bundle the Wasm asset in various
48
- ways based on the platform or bundler a user is targeting. One example being
49
- that Next.js requires special `asyncWebAssembly` webpack config to load our
50
- Wasm file if we don't do this.
70
+ ## Use
51
71
 
52
- In the future, we hope to do away with this workaround when all bundlers
53
- properly support consistent asset bundling techniques.
72
+ Use [`@arcjet/analyze`][file-analyze] instead.
54
73
 
55
74
  ## License
56
75
 
57
- Licensed under the [Apache License, Version 2.0][apache-license].
76
+ [Apache License, Version 2.0][apache-license] © [Arcjet Labs, Inc.][arcjet]
58
77
 
59
78
  [arcjet]: https://arcjet.com
79
+ [arcjet-get-started]: https://docs.arcjet.com/get-started
80
+ [file-analyze]: ../analyze/
60
81
  [mdn-data-url]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs
61
82
  [wasm-base64-blog]: https://blobfolio.com/2019/better-binary-batter-mixing-base64-and-uint8array/
62
83
  [apache-license]: http://www.apache.org/licenses/LICENSE-2.0
84
+ [github-arcjet-analyze]: https://github.com/arcjet/arcjet-js/tree/main/analyze
85
+ [tc39-proposal-import-bytes]: https://github.com/tc39/proposal-import-bytes