payid-rule-engine 0.2.8 → 0.3.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payid-rule-engine",
3
- "version": "0.2.8",
3
+ "version": "0.3.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "scripts": {
@@ -10,8 +10,8 @@
10
10
  "dependencies": {
11
11
  "@types/lodash": "^4.17.21",
12
12
  "lodash": "^4.17.21",
13
- "payid-attestation": "^0.1.3",
14
- "payid-types": "^0.1.7",
13
+ "payid-attestation": "^0.1.4",
14
+ "payid-types": "^0.2.0",
15
15
  "wasi": "^0.0.6"
16
16
  },
17
17
  "devDependencies": {
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { RuleContext, RuleResult } from "payid-types";
2
2
  import { runWasmRule } from "./sandbox";
3
+ export * from "./wasm";
3
4
  export * from "./sandbox";
4
5
  export * from "./preprocess";
5
6
 
package/src/tsSandbox.ts CHANGED
@@ -1,21 +1,18 @@
1
1
  // sandbox.ts — Pure TypeScript rule engine (no WASM)
2
2
  //
3
- // Implements semua operator v4: exists, not_exists, transforms, regex, mod_ne, dll.
4
3
  // Tidak butuh compile Rust, tidak butuh WASI.
5
4
 
6
5
  import type { RuleContext, RuleResult } from "payid-types";
7
6
 
8
- // ── Entry point (sama interface dengan runWasmRule) ───────────────────────────
9
-
10
7
  export async function runWasmRule(
11
- _wasmBinary: Buffer, // ignored — pakai TS implementation
8
+ _wasmBinary: Buffer,
12
9
  context: RuleContext,
13
10
  config: any
14
11
  ): Promise<RuleResult> {
15
12
  return evaluateRule(context, config);
16
13
  }
17
14
 
18
- // ── Core evaluation ───────────────────────────────────────────────────────────
15
+ // Core evaluation
19
16
 
20
17
  function evaluateRule(context: any, config: any): RuleResult {
21
18
  const rules: any[] = config?.rules;
@@ -85,7 +82,7 @@ function evalOneRule(context: any, rule: any): RuleResult {
85
82
  return { decision: "REJECT", code: ruleId, reason: "rule has no evaluable condition" };
86
83
  }
87
84
 
88
- // ── Condition evaluation ──────────────────────────────────────────────────────
85
+ // Condition evaluation
89
86
 
90
87
  function evalCondition(context: any, cond: any): boolean {
91
88
  const fieldExpr: string = cond?.field;
@@ -114,7 +111,7 @@ function evalCondition(context: any, cond: any): boolean {
114
111
  return applyOp(actual, op, expected);
115
112
  }
116
113
 
117
- // ── Field resolution ──────────────────────────────────────────────────────────
114
+ // Field resolution
118
115
 
119
116
  function resolveField(ctx: any, path: string): any {
120
117
  const base = splitTransform(path)[0];
@@ -127,7 +124,7 @@ function splitTransform(expr: string): [string, string | null] {
127
124
  return [expr.slice(0, i), expr.slice(i + 1)];
128
125
  }
129
126
 
130
- // ── Field transforms ──────────────────────────────────────────────────────────
127
+ // Field transforms
131
128
 
132
129
  function applyTransform(val: any, expr: string): any {
133
130
  const transform = splitTransform(expr)[1];
@@ -173,7 +170,7 @@ function toU128(v: any): bigint | null {
173
170
  } catch { return null; }
174
171
  }
175
172
 
176
- // ── Gregorian calendar ────────────────────────────────────────────────────────
173
+ // Gregorian calendar
177
174
 
178
175
  function isLeap(y: number): boolean { return (y % 4 === 0 && y % 100 !== 0) || y % 400 === 0; }
179
176
 
@@ -190,7 +187,7 @@ function daysToYMD(days: number): [number, number, number] {
190
187
  function dayOfMonth(days: number): number { return daysToYMD(days)[2]; }
191
188
  function monthOfYear(days: number): number { return daysToYMD(days)[1]; }
192
189
 
193
- // ── Operator dispatch ─────────────────────────────────────────────────────────
190
+ // Operator dispatch
194
191
 
195
192
  function applyOp(actual: any, op: string, expected: any): boolean {
196
193
  const a = toU128(actual);
@@ -249,7 +246,7 @@ function looseEq(a: any, b: any): boolean {
249
246
  return ba !== null && bb !== null && ba === bb;
250
247
  }
251
248
 
252
- // ── Message interpolation ─────────────────────────────────────────────────────
249
+ // Message interpolation
253
250
 
254
251
  function interpolate(template: string, context: any): string {
255
252
  return template.replace(/\{([^}]+)\}/g, (_, key) => {
package/src/wasm.ts CHANGED
@@ -1,4 +1,4 @@
1
- let _wasmUrl = '/rule_engine.wasm';
1
+ let _wasmUrl = 'https://gateway.pinata.cloud/ipfs/bafkreigwfxsb7oot7v55x7vxslvj23csxl2fhk2w7hsnboe55o26s2mgfy';
2
2
 
3
3
  let _instance: WebAssembly.Instance | null = null;
4
4
  let _loading: Promise<WebAssembly.Instance> | null = null;