transaction-signal 0.1.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 +35 -0
- package/package.json +23 -0
- package/transaction_signal.d.ts +4 -0
- package/transaction_signal.js +9 -0
- package/transaction_signal_bg.js +321 -0
- package/transaction_signal_bg.wasm +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# transaction-signal
|
|
2
|
+
|
|
3
|
+
Local, deterministic extraction of transaction signals from financial messages.
|
|
4
|
+
|
|
5
|
+
This library answers one question only:
|
|
6
|
+
|
|
7
|
+
> Should the user be worried about this transaction right now?
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- Local parsing (no servers)
|
|
14
|
+
- Deterministic, rule-based extraction
|
|
15
|
+
- Indian bank support (UPI, Card, IMPS, NEFT, Clearing)
|
|
16
|
+
- Shared core for:
|
|
17
|
+
- Rust
|
|
18
|
+
- CLI
|
|
19
|
+
- Web (WASM)
|
|
20
|
+
- React Native (WebView + WASM)
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Rust usage
|
|
25
|
+
|
|
26
|
+
```rust
|
|
27
|
+
use transaction_signal::analyze::{analyze_signal, AnalyzeInput};
|
|
28
|
+
|
|
29
|
+
let signals = analyze_signal(AnalyzeInput {
|
|
30
|
+
body: email_body,
|
|
31
|
+
sender: Some("alerts@bank.com".into()),
|
|
32
|
+
subject: None,
|
|
33
|
+
received_at: None,
|
|
34
|
+
rule_version: None,
|
|
35
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "transaction-signal",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"description": "Probabilistic extraction of financial awareness signals from email-like text",
|
|
5
|
+
"version": "0.1.0",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/your-org/transaction-signal"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"transaction_signal_bg.wasm",
|
|
13
|
+
"transaction_signal.js",
|
|
14
|
+
"transaction_signal_bg.js",
|
|
15
|
+
"transaction_signal.d.ts"
|
|
16
|
+
],
|
|
17
|
+
"main": "transaction_signal.js",
|
|
18
|
+
"types": "transaction_signal.d.ts",
|
|
19
|
+
"sideEffects": [
|
|
20
|
+
"./transaction_signal.js",
|
|
21
|
+
"./snippets/*"
|
|
22
|
+
]
|
|
23
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/* @ts-self-types="./transaction_signal.d.ts" */
|
|
2
|
+
|
|
3
|
+
import * as wasm from "./transaction_signal_bg.wasm";
|
|
4
|
+
import { __wbg_set_wasm } from "./transaction_signal_bg.js";
|
|
5
|
+
__wbg_set_wasm(wasm);
|
|
6
|
+
wasm.__wbindgen_start();
|
|
7
|
+
export {
|
|
8
|
+
analyze_mail
|
|
9
|
+
} from "./transaction_signal_bg.js";
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {any} input
|
|
3
|
+
* @returns {any}
|
|
4
|
+
*/
|
|
5
|
+
export function analyze_mail(input) {
|
|
6
|
+
const ret = wasm.analyze_mail(input);
|
|
7
|
+
if (ret[2]) {
|
|
8
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
9
|
+
}
|
|
10
|
+
return takeFromExternrefTable0(ret[0]);
|
|
11
|
+
}
|
|
12
|
+
export function __wbg_Error_8c4e43fe74559d73(arg0, arg1) {
|
|
13
|
+
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
14
|
+
return ret;
|
|
15
|
+
}
|
|
16
|
+
export function __wbg_String_8f0eb39a4a4c2f66(arg0, arg1) {
|
|
17
|
+
const ret = String(arg1);
|
|
18
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
19
|
+
const len1 = WASM_VECTOR_LEN;
|
|
20
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
21
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
22
|
+
}
|
|
23
|
+
export function __wbg___wbindgen_boolean_get_bbbb1c18aa2f5e25(arg0) {
|
|
24
|
+
const v = arg0;
|
|
25
|
+
const ret = typeof(v) === 'boolean' ? v : undefined;
|
|
26
|
+
return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
|
|
27
|
+
}
|
|
28
|
+
export function __wbg___wbindgen_debug_string_0bc8482c6e3508ae(arg0, arg1) {
|
|
29
|
+
const ret = debugString(arg1);
|
|
30
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
31
|
+
const len1 = WASM_VECTOR_LEN;
|
|
32
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
33
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
34
|
+
}
|
|
35
|
+
export function __wbg___wbindgen_in_47fa6863be6f2f25(arg0, arg1) {
|
|
36
|
+
const ret = arg0 in arg1;
|
|
37
|
+
return ret;
|
|
38
|
+
}
|
|
39
|
+
export function __wbg___wbindgen_is_object_5ae8e5880f2c1fbd(arg0) {
|
|
40
|
+
const val = arg0;
|
|
41
|
+
const ret = typeof(val) === 'object' && val !== null;
|
|
42
|
+
return ret;
|
|
43
|
+
}
|
|
44
|
+
export function __wbg___wbindgen_is_undefined_9e4d92534c42d778(arg0) {
|
|
45
|
+
const ret = arg0 === undefined;
|
|
46
|
+
return ret;
|
|
47
|
+
}
|
|
48
|
+
export function __wbg___wbindgen_jsval_loose_eq_9dd77d8cd6671811(arg0, arg1) {
|
|
49
|
+
const ret = arg0 == arg1;
|
|
50
|
+
return ret;
|
|
51
|
+
}
|
|
52
|
+
export function __wbg___wbindgen_number_get_8ff4255516ccad3e(arg0, arg1) {
|
|
53
|
+
const obj = arg1;
|
|
54
|
+
const ret = typeof(obj) === 'number' ? obj : undefined;
|
|
55
|
+
getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
|
|
56
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
|
|
57
|
+
}
|
|
58
|
+
export function __wbg___wbindgen_string_get_72fb696202c56729(arg0, arg1) {
|
|
59
|
+
const obj = arg1;
|
|
60
|
+
const ret = typeof(obj) === 'string' ? obj : undefined;
|
|
61
|
+
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
62
|
+
var len1 = WASM_VECTOR_LEN;
|
|
63
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
64
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
65
|
+
}
|
|
66
|
+
export function __wbg___wbindgen_throw_be289d5034ed271b(arg0, arg1) {
|
|
67
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
68
|
+
}
|
|
69
|
+
export function __wbg_getTime_1e3cd1391c5c3995(arg0) {
|
|
70
|
+
const ret = arg0.getTime();
|
|
71
|
+
return ret;
|
|
72
|
+
}
|
|
73
|
+
export function __wbg_get_with_ref_key_1dc361bd10053bfe(arg0, arg1) {
|
|
74
|
+
const ret = arg0[arg1];
|
|
75
|
+
return ret;
|
|
76
|
+
}
|
|
77
|
+
export function __wbg_instanceof_ArrayBuffer_c367199e2fa2aa04(arg0) {
|
|
78
|
+
let result;
|
|
79
|
+
try {
|
|
80
|
+
result = arg0 instanceof ArrayBuffer;
|
|
81
|
+
} catch (_) {
|
|
82
|
+
result = false;
|
|
83
|
+
}
|
|
84
|
+
const ret = result;
|
|
85
|
+
return ret;
|
|
86
|
+
}
|
|
87
|
+
export function __wbg_instanceof_Uint8Array_9b9075935c74707c(arg0) {
|
|
88
|
+
let result;
|
|
89
|
+
try {
|
|
90
|
+
result = arg0 instanceof Uint8Array;
|
|
91
|
+
} catch (_) {
|
|
92
|
+
result = false;
|
|
93
|
+
}
|
|
94
|
+
const ret = result;
|
|
95
|
+
return ret;
|
|
96
|
+
}
|
|
97
|
+
export function __wbg_length_32ed9a279acd054c(arg0) {
|
|
98
|
+
const ret = arg0.length;
|
|
99
|
+
return ret;
|
|
100
|
+
}
|
|
101
|
+
export function __wbg_new_0_73afc35eb544e539() {
|
|
102
|
+
const ret = new Date();
|
|
103
|
+
return ret;
|
|
104
|
+
}
|
|
105
|
+
export function __wbg_new_361308b2356cecd0() {
|
|
106
|
+
const ret = new Object();
|
|
107
|
+
return ret;
|
|
108
|
+
}
|
|
109
|
+
export function __wbg_new_3eb36ae241fe6f44() {
|
|
110
|
+
const ret = new Array();
|
|
111
|
+
return ret;
|
|
112
|
+
}
|
|
113
|
+
export function __wbg_new_dd2b680c8bf6ae29(arg0) {
|
|
114
|
+
const ret = new Uint8Array(arg0);
|
|
115
|
+
return ret;
|
|
116
|
+
}
|
|
117
|
+
export function __wbg_prototypesetcall_bdcdcc5842e4d77d(arg0, arg1, arg2) {
|
|
118
|
+
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
|
|
119
|
+
}
|
|
120
|
+
export function __wbg_set_3f1d0b984ed272ed(arg0, arg1, arg2) {
|
|
121
|
+
arg0[arg1] = arg2;
|
|
122
|
+
}
|
|
123
|
+
export function __wbg_set_f43e577aea94465b(arg0, arg1, arg2) {
|
|
124
|
+
arg0[arg1 >>> 0] = arg2;
|
|
125
|
+
}
|
|
126
|
+
export function __wbindgen_cast_0000000000000001(arg0) {
|
|
127
|
+
// Cast intrinsic for `F64 -> Externref`.
|
|
128
|
+
const ret = arg0;
|
|
129
|
+
return ret;
|
|
130
|
+
}
|
|
131
|
+
export function __wbindgen_cast_0000000000000002(arg0) {
|
|
132
|
+
// Cast intrinsic for `I64 -> Externref`.
|
|
133
|
+
const ret = arg0;
|
|
134
|
+
return ret;
|
|
135
|
+
}
|
|
136
|
+
export function __wbindgen_cast_0000000000000003(arg0, arg1) {
|
|
137
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
138
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
139
|
+
return ret;
|
|
140
|
+
}
|
|
141
|
+
export function __wbindgen_init_externref_table() {
|
|
142
|
+
const table = wasm.__wbindgen_externrefs;
|
|
143
|
+
const offset = table.grow(4);
|
|
144
|
+
table.set(0, undefined);
|
|
145
|
+
table.set(offset + 0, undefined);
|
|
146
|
+
table.set(offset + 1, null);
|
|
147
|
+
table.set(offset + 2, true);
|
|
148
|
+
table.set(offset + 3, false);
|
|
149
|
+
}
|
|
150
|
+
function debugString(val) {
|
|
151
|
+
// primitive types
|
|
152
|
+
const type = typeof val;
|
|
153
|
+
if (type == 'number' || type == 'boolean' || val == null) {
|
|
154
|
+
return `${val}`;
|
|
155
|
+
}
|
|
156
|
+
if (type == 'string') {
|
|
157
|
+
return `"${val}"`;
|
|
158
|
+
}
|
|
159
|
+
if (type == 'symbol') {
|
|
160
|
+
const description = val.description;
|
|
161
|
+
if (description == null) {
|
|
162
|
+
return 'Symbol';
|
|
163
|
+
} else {
|
|
164
|
+
return `Symbol(${description})`;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (type == 'function') {
|
|
168
|
+
const name = val.name;
|
|
169
|
+
if (typeof name == 'string' && name.length > 0) {
|
|
170
|
+
return `Function(${name})`;
|
|
171
|
+
} else {
|
|
172
|
+
return 'Function';
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
// objects
|
|
176
|
+
if (Array.isArray(val)) {
|
|
177
|
+
const length = val.length;
|
|
178
|
+
let debug = '[';
|
|
179
|
+
if (length > 0) {
|
|
180
|
+
debug += debugString(val[0]);
|
|
181
|
+
}
|
|
182
|
+
for(let i = 1; i < length; i++) {
|
|
183
|
+
debug += ', ' + debugString(val[i]);
|
|
184
|
+
}
|
|
185
|
+
debug += ']';
|
|
186
|
+
return debug;
|
|
187
|
+
}
|
|
188
|
+
// Test for built-in
|
|
189
|
+
const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
|
|
190
|
+
let className;
|
|
191
|
+
if (builtInMatches && builtInMatches.length > 1) {
|
|
192
|
+
className = builtInMatches[1];
|
|
193
|
+
} else {
|
|
194
|
+
// Failed to match the standard '[object ClassName]'
|
|
195
|
+
return toString.call(val);
|
|
196
|
+
}
|
|
197
|
+
if (className == 'Object') {
|
|
198
|
+
// we're a user defined class or Object
|
|
199
|
+
// JSON.stringify avoids problems with cycles, and is generally much
|
|
200
|
+
// easier than looping through ownProperties of `val`.
|
|
201
|
+
try {
|
|
202
|
+
return 'Object(' + JSON.stringify(val) + ')';
|
|
203
|
+
} catch (_) {
|
|
204
|
+
return 'Object';
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
// errors
|
|
208
|
+
if (val instanceof Error) {
|
|
209
|
+
return `${val.name}: ${val.message}\n${val.stack}`;
|
|
210
|
+
}
|
|
211
|
+
// TODO we could test for more things here, like `Set`s and `Map`s.
|
|
212
|
+
return className;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
216
|
+
ptr = ptr >>> 0;
|
|
217
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
let cachedDataViewMemory0 = null;
|
|
221
|
+
function getDataViewMemory0() {
|
|
222
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
223
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
224
|
+
}
|
|
225
|
+
return cachedDataViewMemory0;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function getStringFromWasm0(ptr, len) {
|
|
229
|
+
ptr = ptr >>> 0;
|
|
230
|
+
return decodeText(ptr, len);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
let cachedUint8ArrayMemory0 = null;
|
|
234
|
+
function getUint8ArrayMemory0() {
|
|
235
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
236
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
237
|
+
}
|
|
238
|
+
return cachedUint8ArrayMemory0;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function isLikeNone(x) {
|
|
242
|
+
return x === undefined || x === null;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
246
|
+
if (realloc === undefined) {
|
|
247
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
248
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
249
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
250
|
+
WASM_VECTOR_LEN = buf.length;
|
|
251
|
+
return ptr;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
let len = arg.length;
|
|
255
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
256
|
+
|
|
257
|
+
const mem = getUint8ArrayMemory0();
|
|
258
|
+
|
|
259
|
+
let offset = 0;
|
|
260
|
+
|
|
261
|
+
for (; offset < len; offset++) {
|
|
262
|
+
const code = arg.charCodeAt(offset);
|
|
263
|
+
if (code > 0x7F) break;
|
|
264
|
+
mem[ptr + offset] = code;
|
|
265
|
+
}
|
|
266
|
+
if (offset !== len) {
|
|
267
|
+
if (offset !== 0) {
|
|
268
|
+
arg = arg.slice(offset);
|
|
269
|
+
}
|
|
270
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
271
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
272
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
273
|
+
|
|
274
|
+
offset += ret.written;
|
|
275
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
WASM_VECTOR_LEN = offset;
|
|
279
|
+
return ptr;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function takeFromExternrefTable0(idx) {
|
|
283
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
284
|
+
wasm.__externref_table_dealloc(idx);
|
|
285
|
+
return value;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
289
|
+
cachedTextDecoder.decode();
|
|
290
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
291
|
+
let numBytesDecoded = 0;
|
|
292
|
+
function decodeText(ptr, len) {
|
|
293
|
+
numBytesDecoded += len;
|
|
294
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
295
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
296
|
+
cachedTextDecoder.decode();
|
|
297
|
+
numBytesDecoded = len;
|
|
298
|
+
}
|
|
299
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
const cachedTextEncoder = new TextEncoder();
|
|
303
|
+
|
|
304
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
305
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
306
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
307
|
+
view.set(buf);
|
|
308
|
+
return {
|
|
309
|
+
read: arg.length,
|
|
310
|
+
written: buf.length
|
|
311
|
+
};
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
let WASM_VECTOR_LEN = 0;
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
let wasm;
|
|
319
|
+
export function __wbg_set_wasm(val) {
|
|
320
|
+
wasm = val;
|
|
321
|
+
}
|
|
Binary file
|