@arcjet/analyze
Advanced tools
Comparing version 1.0.0-alpha.13 to 1.0.0-alpha.14
@@ -34,4 +34,5 @@ // @generated by wasm2module - DO NOT EDIT | ||
async function wasm() { | ||
// This uses fetch to decode the wasm data url | ||
const wasmDecode = await fetch(wasmBase64); | ||
// This uses fetch to decode the wasm data url, but disabling cache so files | ||
// larger than 2mb don't fail to parse in the Next.js App Router | ||
const wasmDecode = await fetch(wasmBase64, { cache: "no-store" }); | ||
const buf = await wasmDecode.arrayBuffer(); | ||
@@ -38,0 +39,0 @@ // And then we return it as a WebAssembly.Module |
@@ -34,4 +34,5 @@ // @generated by wasm2module - DO NOT EDIT | ||
async function wasm() { | ||
// This uses fetch to decode the wasm data url | ||
const wasmDecode = await fetch(wasmBase64); | ||
// This uses fetch to decode the wasm data url, but disabling cache so files | ||
// larger than 2mb don't fail to parse in the Next.js App Router | ||
const wasmDecode = await fetch(wasmBase64, { cache: "no-store" }); | ||
const buf = await wasmDecode.arrayBuffer(); | ||
@@ -38,0 +39,0 @@ // And then we return it as a WebAssembly.Module |
@@ -0,2 +1,6 @@ | ||
import type { ArcjetLogger } from "@arcjet/protocol"; | ||
import type { EmailValidationConfig, BotDetectionResult, BotType } from "./wasm/arcjet_analyze_js_req.component.js"; | ||
interface AnalyzeContext { | ||
log: ArcjetLogger; | ||
} | ||
export { type EmailValidationConfig, type BotType, | ||
@@ -22,4 +26,4 @@ /** | ||
*/ | ||
export declare function generateFingerprint(ip: string): Promise<string>; | ||
export declare function isValidEmail(candidate: string, options?: EmailValidationConfig): Promise<boolean>; | ||
export declare function detectBot(headers: string, patterns_add: string, patterns_remove: string): Promise<BotDetectionResult>; | ||
export declare function generateFingerprint(context: AnalyzeContext, ip: string): Promise<string>; | ||
export declare function isValidEmail(context: AnalyzeContext, candidate: string, options?: EmailValidationConfig): Promise<boolean>; | ||
export declare function detectBot(context: AnalyzeContext, headers: string, patterns_add: string, patterns_remove: string): Promise<BotDetectionResult>; |
94
index.js
@@ -1,3 +0,5 @@ | ||
import logger from '@arcjet/logger'; | ||
import { instantiate } from './wasm/arcjet_analyze_js_req.component.js'; | ||
import { wasm } from './_virtual/arcjet_analyze_js_req.component.core.js'; | ||
import { wasm as wasm$1 } from './_virtual/arcjet_analyze_js_req.component.core2.js'; | ||
import { wasm as wasm$2 } from './_virtual/arcjet_analyze_js_req.component.core3.js'; | ||
@@ -11,59 +13,31 @@ // TODO: Do we actually need this wasmCache or does `import` cache correctly? | ||
} | ||
if (process.env["NEXT_RUNTIME"] === "edge") { | ||
const wasmPrefix = "arcjet_analyze_js_req.component"; | ||
if (path === "arcjet_analyze_js_req.component.core.wasm") { | ||
const mod = await import( | ||
/* @vite-ignore */ | ||
`./wasm/${wasmPrefix}.core.wasm?module`); | ||
wasmCache.set(path, mod.default); | ||
return mod.default; | ||
} | ||
if (path === "arcjet_analyze_js_req.component.core2.wasm") { | ||
const mod = await import( | ||
/* @vite-ignore */ | ||
`./wasm/${wasmPrefix}.core2.wasm?module`); | ||
wasmCache.set(path, mod.default); | ||
return mod.default; | ||
} | ||
if (path === "arcjet_analyze_js_req.component.core3.wasm") { | ||
const mod = await import( | ||
/* @vite-ignore */ | ||
`./wasm/${wasmPrefix}.core3.wasm?module`); | ||
wasmCache.set(path, mod.default); | ||
return mod.default; | ||
} | ||
if (path === "arcjet_analyze_js_req.component.core.wasm") { | ||
const mod = await wasm(); | ||
wasmCache.set(path, mod); | ||
return mod; | ||
} | ||
else { | ||
if (path === "arcjet_analyze_js_req.component.core.wasm") { | ||
const { wasm } = await import('./_virtual/arcjet_analyze_js_req.component.core.js'); | ||
const mod = await wasm(); | ||
wasmCache.set(path, mod); | ||
return mod; | ||
} | ||
if (path === "arcjet_analyze_js_req.component.core2.wasm") { | ||
const { wasm } = await import('./_virtual/arcjet_analyze_js_req.component.core2.js'); | ||
const mod = await wasm(); | ||
wasmCache.set(path, mod); | ||
return mod; | ||
} | ||
if (path === "arcjet_analyze_js_req.component.core3.wasm") { | ||
const { wasm } = await import('./_virtual/arcjet_analyze_js_req.component.core3.js'); | ||
const mod = await wasm(); | ||
wasmCache.set(path, mod); | ||
return mod; | ||
} | ||
if (path === "arcjet_analyze_js_req.component.core2.wasm") { | ||
const mod = await wasm$1(); | ||
wasmCache.set(path, mod); | ||
return mod; | ||
} | ||
if (path === "arcjet_analyze_js_req.component.core3.wasm") { | ||
const mod = await wasm$2(); | ||
wasmCache.set(path, mod); | ||
return mod; | ||
} | ||
throw new Error(`Unknown path: ${path}`); | ||
} | ||
const coreImports = { | ||
"arcjet:js-req/logger": { | ||
debug(msg) { | ||
logger.debug(msg); | ||
async function init(context) { | ||
const { log } = context; | ||
const coreImports = { | ||
"arcjet:js-req/logger": { | ||
debug(msg) { | ||
log.debug(msg); | ||
}, | ||
error(msg) { | ||
log.error(msg); | ||
}, | ||
}, | ||
error(msg) { | ||
logger.error(msg); | ||
}, | ||
}, | ||
}; | ||
async function init() { | ||
}; | ||
try { | ||
@@ -73,3 +47,3 @@ return instantiate(moduleFromPath, coreImports); | ||
catch { | ||
logger.debug("WebAssembly is not supported in this runtime"); | ||
log.debug("WebAssembly is not supported in this runtime"); | ||
} | ||
@@ -83,7 +57,7 @@ } | ||
*/ | ||
async function generateFingerprint(ip) { | ||
async function generateFingerprint(context, ip) { | ||
if (ip == "") { | ||
return ""; | ||
} | ||
const analyze = await init(); | ||
const analyze = await init(context); | ||
if (typeof analyze !== "undefined") { | ||
@@ -111,4 +85,4 @@ return analyze.generateFingerprint(ip); | ||
} | ||
async function isValidEmail(candidate, options) { | ||
const analyze = await init(); | ||
async function isValidEmail(context, candidate, options) { | ||
const analyze = await init(context); | ||
if (typeof analyze !== "undefined") { | ||
@@ -122,4 +96,4 @@ return analyze.isValidEmail(candidate, options); | ||
} | ||
async function detectBot(headers, patterns_add, patterns_remove) { | ||
const analyze = await init(); | ||
async function detectBot(context, headers, patterns_add, patterns_remove) { | ||
const analyze = await init(context); | ||
if (typeof analyze !== "undefined") { | ||
@@ -126,0 +100,0 @@ return analyze.detectBot(headers, patterns_add, patterns_remove); |
112
index.ts
@@ -1,2 +0,2 @@ | ||
import logger from "@arcjet/logger"; | ||
import type { ArcjetLogger } from "@arcjet/protocol"; | ||
@@ -11,2 +11,10 @@ import * as core from "./wasm/arcjet_analyze_js_req.component.js"; | ||
import { wasm as componentCoreWasm } from "./wasm/arcjet_analyze_js_req.component.core.wasm?js"; | ||
import { wasm as componentCore2Wasm } from "./wasm/arcjet_analyze_js_req.component.core2.wasm?js"; | ||
import { wasm as componentCore3Wasm } from "./wasm/arcjet_analyze_js_req.component.core3.wasm?js"; | ||
interface AnalyzeContext { | ||
log: ArcjetLogger; | ||
} | ||
// TODO: Do we actually need this wasmCache or does `import` cache correctly? | ||
@@ -21,54 +29,17 @@ const wasmCache = new Map<string, WebAssembly.Module>(); | ||
if (process.env["NEXT_RUNTIME"] === "edge") { | ||
const wasmPrefix = "arcjet_analyze_js_req.component"; | ||
if (path === "arcjet_analyze_js_req.component.core.wasm") { | ||
const mod = await import( | ||
/* @vite-ignore */ | ||
`./wasm/${wasmPrefix}.core.wasm?module` | ||
); | ||
wasmCache.set(path, mod.default); | ||
return mod.default; | ||
} | ||
if (path === "arcjet_analyze_js_req.component.core2.wasm") { | ||
const mod = await import( | ||
/* @vite-ignore */ | ||
`./wasm/${wasmPrefix}.core2.wasm?module` | ||
); | ||
wasmCache.set(path, mod.default); | ||
return mod.default; | ||
} | ||
if (path === "arcjet_analyze_js_req.component.core3.wasm") { | ||
const mod = await import( | ||
/* @vite-ignore */ | ||
`./wasm/${wasmPrefix}.core3.wasm?module` | ||
); | ||
wasmCache.set(path, mod.default); | ||
return mod.default; | ||
} | ||
} else { | ||
if (path === "arcjet_analyze_js_req.component.core.wasm") { | ||
const { wasm } = await import( | ||
"./wasm/arcjet_analyze_js_req.component.core.wasm" | ||
); | ||
const mod = await wasm(); | ||
wasmCache.set(path, mod); | ||
return mod; | ||
} | ||
if (path === "arcjet_analyze_js_req.component.core2.wasm") { | ||
const { wasm } = await import( | ||
"./wasm/arcjet_analyze_js_req.component.core2.wasm" | ||
); | ||
const mod = await wasm(); | ||
wasmCache.set(path, mod); | ||
return mod; | ||
} | ||
if (path === "arcjet_analyze_js_req.component.core3.wasm") { | ||
const { wasm } = await import( | ||
"./wasm/arcjet_analyze_js_req.component.core3.wasm" | ||
); | ||
const mod = await wasm(); | ||
wasmCache.set(path, mod); | ||
return mod; | ||
} | ||
if (path === "arcjet_analyze_js_req.component.core.wasm") { | ||
const mod = await componentCoreWasm(); | ||
wasmCache.set(path, mod); | ||
return mod; | ||
} | ||
if (path === "arcjet_analyze_js_req.component.core2.wasm") { | ||
const mod = await componentCore2Wasm(); | ||
wasmCache.set(path, mod); | ||
return mod; | ||
} | ||
if (path === "arcjet_analyze_js_req.component.core3.wasm") { | ||
const mod = await componentCore3Wasm(); | ||
wasmCache.set(path, mod); | ||
return mod; | ||
} | ||
@@ -78,18 +49,20 @@ throw new Error(`Unknown path: ${path}`); | ||
const coreImports: ImportObject = { | ||
"arcjet:js-req/logger": { | ||
debug(msg) { | ||
logger.debug(msg); | ||
async function init(context: AnalyzeContext) { | ||
const { log } = context; | ||
const coreImports: ImportObject = { | ||
"arcjet:js-req/logger": { | ||
debug(msg) { | ||
log.debug(msg); | ||
}, | ||
error(msg) { | ||
log.error(msg); | ||
}, | ||
}, | ||
error(msg) { | ||
logger.error(msg); | ||
}, | ||
}, | ||
}; | ||
}; | ||
async function init() { | ||
try { | ||
return core.instantiate(moduleFromPath, coreImports); | ||
} catch { | ||
logger.debug("WebAssembly is not supported in this runtime"); | ||
log.debug("WebAssembly is not supported in this runtime"); | ||
} | ||
@@ -122,3 +95,6 @@ } | ||
*/ | ||
export async function generateFingerprint(ip: string): Promise<string> { | ||
export async function generateFingerprint( | ||
context: AnalyzeContext, | ||
ip: string, | ||
): Promise<string> { | ||
if (ip == "") { | ||
@@ -128,3 +104,3 @@ return ""; | ||
const analyze = await init(); | ||
const analyze = await init(context); | ||
@@ -163,6 +139,7 @@ if (typeof analyze !== "undefined") { | ||
export async function isValidEmail( | ||
context: AnalyzeContext, | ||
candidate: string, | ||
options?: EmailValidationConfig, | ||
) { | ||
const analyze = await init(); | ||
const analyze = await init(context); | ||
@@ -178,2 +155,3 @@ if (typeof analyze !== "undefined") { | ||
export async function detectBot( | ||
context: AnalyzeContext, | ||
headers: string, | ||
@@ -183,3 +161,3 @@ patterns_add: string, | ||
): Promise<BotDetectionResult> { | ||
const analyze = await init(); | ||
const analyze = await init(context); | ||
@@ -186,0 +164,0 @@ if (typeof analyze !== "undefined") { |
{ | ||
"name": "@arcjet/analyze", | ||
"version": "1.0.0-alpha.13", | ||
"version": "1.0.0-alpha.14", | ||
"description": "Arcjet local analysis engine", | ||
@@ -27,2 +27,7 @@ "license": "Apache-2.0", | ||
"types": "./index.d.ts", | ||
"exports": { | ||
"edge-light": "./edge-light.js", | ||
"workerd": "./workerd.js", | ||
"default": "./index.js" | ||
}, | ||
"files": [ | ||
@@ -50,11 +55,11 @@ "LICENSE", | ||
"dependencies": { | ||
"@arcjet/logger": "1.0.0-alpha.13" | ||
"@arcjet/protocol": "1.0.0-alpha.14" | ||
}, | ||
"devDependencies": { | ||
"@arcjet/eslint-config": "1.0.0-alpha.13", | ||
"@arcjet/rollup-config": "1.0.0-alpha.13", | ||
"@arcjet/tsconfig": "1.0.0-alpha.13", | ||
"@arcjet/eslint-config": "1.0.0-alpha.14", | ||
"@arcjet/rollup-config": "1.0.0-alpha.14", | ||
"@arcjet/tsconfig": "1.0.0-alpha.14", | ||
"@bytecodealliance/jco": "1.2.4", | ||
"@jest/globals": "29.7.0", | ||
"@rollup/wasm-node": "4.17.2", | ||
"@rollup/wasm-node": "4.18.0", | ||
"@types/node": "18.18.0", | ||
@@ -61,0 +66,0 @@ "jest": "29.7.0", |
<a href="https://arcjet.com" target="_arcjet-home"> | ||
<picture> | ||
<source media="(prefers-color-scheme: dark)" srcset="https://arcjet.com/arcjet-logo-dark-planet-arrival.svg"> | ||
<img src="https://arcjet.com/arcjet-logo-light-planet-arrival.svg" alt="Arcjet Logo" height="144" width="auto"> | ||
<source media="(prefers-color-scheme: dark)" srcset="https://arcjet.com/logo/arcjet-dark-lockup-voyage-horizontal.svg"> | ||
<img src="https://arcjet.com/logo/arcjet-light-lockup-voyage-horizontal.svg" alt="Arcjet Logo" height="128" width="auto"> | ||
</picture> | ||
@@ -20,3 +20,3 @@ </a> | ||
[Arcjet][arcjet] helps developers protect their apps in just a few lines of | ||
code. Implement rate limiting, bot protection, email verification & defend | ||
code. Implement rate limiting, bot protection, email verification, and defense | ||
against common attacks. | ||
@@ -23,0 +23,0 @@ |
/** | ||
* Cloudflare uses the `.wasm?module` suffix to make WebAssembly | ||
* available in their Workers product. This is documented at | ||
* https://developers.cloudflare.com/workers/runtime-apis/webassembly/javascript/#bundling | ||
* Next.js supports the same syntax, but it is undocumented. | ||
* Vercel uses the `.wasm?module` suffix to make WebAssembly available in their | ||
* Vercel Functions product. | ||
* | ||
* https://vercel.com/docs/functions/wasm#using-a-webassembly-file | ||
*/ | ||
@@ -12,7 +12,18 @@ declare module "*.wasm?module" { | ||
/** | ||
* Our Rollup build turns plain `.wasm` imports into JS imports that provide the | ||
* The Cloudflare docs say they support the `.wasm?module` suffix, but that | ||
* seems to no longer be the case with Wrangler 2 so we need to have separate | ||
* imports for just the `.wasm` files. | ||
* | ||
* https://developers.cloudflare.com/workers/runtime-apis/webassembly/javascript/#bundling | ||
*/ | ||
declare module "*.wasm" { | ||
export default WebAssembly.Module; | ||
} | ||
/** | ||
* Our Rollup build turns `.wasm?js` imports into JS imports that provide the | ||
* `wasm()` function which decodes a base64 Data URL into a WebAssembly Module | ||
*/ | ||
declare module "*.wasm" { | ||
declare module "*.wasm?js" { | ||
export function wasm(): Promise<WebAssembly.Module>; | ||
} |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
5687709
23
10115
0
+ Added@arcjet/protocol@1.0.0-alpha.14(transitive)
+ Added@bufbuild/protobuf@1.10.0(transitive)
+ Added@connectrpc/connect@1.4.0(transitive)
+ Addedtypeid-js@0.7.0(transitive)
+ Addeduuidv7@0.6.3(transitive)
- Removed@arcjet/logger@1.0.0-alpha.13
- Removed@arcjet/logger@1.0.0-alpha.13(transitive)