@arcjet/analyze-wasm 1.0.0-beta.8 → 1.0.0

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,63 @@ 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,
30
37
 
31
- ## Implementation
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`.
32
45
 
33
- This package provides analyze logic implemented as a WebAssembly module which
34
- will run local analysis on request details.
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 [SDKs][github-arcjet-sdks] (such as `@arcjet/next`).
35
52
 
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.
53
+ ## When should I use this?
38
54
 
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.
55
+ This is an internal Arcjet package not designed for public use.
56
+ See our [_Get started_ guide][arcjet-get-started] for how to use Arcjet in your
57
+ application.
43
58
 
44
- It is then decoded into an ArrayBuffer to be used directly via WebAssembly's
45
- `compile()` function in our entry point file.
59
+ ## Install
60
+
61
+ This package is ESM only.
62
+ Install with npm in Node.js:
63
+
64
+ ```sh
65
+ npm install @arcjet/analyze-wasm
66
+ ```
46
67
 
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.
68
+ ## Use
51
69
 
52
- In the future, we hope to do away with this workaround when all bundlers
53
- properly support consistent asset bundling techniques.
70
+ Use [`@arcjet/analyze`][file-analyze] instead.
54
71
 
55
72
  ## License
56
73
 
57
- Licensed under the [Apache License, Version 2.0][apache-license].
74
+ [Apache License, Version 2.0][apache-license] © [Arcjet Labs, Inc.][arcjet]
58
75
 
59
76
  [arcjet]: https://arcjet.com
77
+ [arcjet-get-started]: https://docs.arcjet.com/get-started
78
+ [file-analyze]: ../analyze/
60
79
  [mdn-data-url]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs
61
80
  [wasm-base64-blog]: https://blobfolio.com/2019/better-binary-batter-mixing-base64-and-uint8array/
62
81
  [apache-license]: http://www.apache.org/licenses/LICENSE-2.0
82
+ [github-arcjet-analyze]: https://github.com/arcjet/arcjet-js/tree/main/analyze
83
+ [github-arcjet-sdks]: https://github.com/arcjet/arcjet-js#sdks
84
+ [tc39-proposal-import-bytes]: https://github.com/tc39/proposal-import-bytes