payid-rule-engine 0.2.3 → 0.2.5

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/wasm.ts +20 -14
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payid-rule-engine",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "scripts": {
package/src/wasm.ts CHANGED
@@ -1,21 +1,27 @@
1
- export async function loadWasm(binary?: Buffer): Promise<WebAssembly.Instance> {
2
- let wasmBinary = binary;
1
+ // URL to fetch WASM binary in browser environments.
2
+ // Override this before calling loadWasm() if hosting on custom CDN/IPFS:
3
+ // import { setWasmUrl } from 'payid-rule-engine/src/wasm';
4
+ // setWasmUrl('https://gateway.pinata.cloud/ipfs/YOUR_CID');
5
+ let _wasmUrl: string = 'https://gateway.pinata.cloud/ipfs/bafkreigwfxsb7oot7v55x7vxslvj23csxl2fhk2w7hsnboe55o26s2mgfy';
3
6
 
4
- if (!wasmBinary || wasmBinary.length === 0) {
5
- if (typeof process !== "undefined" && process.versions?.node) {
6
- const { readFileSync } = await import("fs");
7
- const { join, dirname } = await import("path");
8
- const { fileURLToPath } = await import("url");
7
+ export function setWasmUrl(url: string) {
8
+ _wasmUrl = url;
9
+ }
9
10
 
10
- const __dir = dirname(fileURLToPath(import.meta.url));
11
- wasmBinary = readFileSync(join(__dir, "wasm/rule_engine.wasm"));
11
+ export async function loadWasm(binary?: Buffer | Uint8Array): Promise<WebAssembly.Instance> {
12
+ let wasmBinary: Buffer | Uint8Array | undefined = binary;
12
13
 
13
- // Browser
14
+ if (!wasmBinary || wasmBinary.length === 0) {
15
+ if (typeof process !== 'undefined' && process.versions?.node) {
16
+ const { readFileSync } = await import(/* webpackIgnore: true */ 'fs');
17
+ const { join, dirname } = await import(/* webpackIgnore: true */ 'path');
18
+ const { fileURLToPath } = await import(/* webpackIgnore: true */ 'url');
19
+ const __dir = dirname(fileURLToPath(import.meta.url));
20
+ wasmBinary = readFileSync(join(__dir, 'wasm/rule_engine.wasm'));
14
21
  } else {
15
- const wasmUrl = new URL("../wasm/rule_engine.wasm", import.meta.url);
16
- const res = await fetch(wasmUrl);
17
- if (!res.ok) throw new Error(`Failed to load rule_engine.wasm: ${res.status}`);
18
- wasmBinary = Buffer.from(await res.arrayBuffer());
22
+ const res = await fetch(_wasmUrl);
23
+ if (!res.ok) throw new Error(`[PAY.ID] Failed to fetch WASM from ${_wasmUrl}: ${res.status}`);
24
+ wasmBinary = new Uint8Array(await res.arrayBuffer());
19
25
  }
20
26
  }
21
27