@f-o-t/ofx 1.2.1 → 2.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.
Files changed (4) hide show
  1. package/README.md +125 -4
  2. package/dist/index.d.ts +1522 -38
  3. package/dist/index.js +581 -302
  4. package/package.json +5 -11
package/README.md CHANGED
@@ -123,6 +123,112 @@ console.log({
123
123
  });
124
124
  ```
125
125
 
126
+ ### Generation Functions
127
+
128
+ #### `generateBankStatement(options: GenerateBankStatementOptions): string`
129
+
130
+ Generates a complete OFX bank statement file.
131
+
132
+ ```typescript
133
+ import { generateBankStatement } from "@fot/ofx";
134
+
135
+ const statement = generateBankStatement({
136
+ bankId: "123456",
137
+ accountId: "987654321",
138
+ accountType: "CHECKING",
139
+ currency: "USD",
140
+ startDate: new Date("2025-01-01"),
141
+ endDate: new Date("2025-01-31"),
142
+ transactions: [
143
+ {
144
+ type: "CREDIT",
145
+ datePosted: new Date(),
146
+ amount: 1000,
147
+ fitId: "1",
148
+ name: "Deposit",
149
+ },
150
+ ],
151
+ });
152
+
153
+ console.log(statement);
154
+ ```
155
+
156
+ #### `generateCreditCardStatement(options: GenerateCreditCardStatementOptions): string`
157
+
158
+ Generates a complete OFX credit card statement file.
159
+
160
+ ```typescript
161
+ import { generateCreditCardStatement } from "@fot/ofx";
162
+
163
+ const statement = generateCreditCardStatement({
164
+ accountId: "123456789",
165
+ currency: "USD",
166
+ startDate: new Date("2025-01-01"),
167
+ endDate: new Date("2025-01-31"),
168
+ transactions: [
169
+ {
170
+ type: "DEBIT",
171
+ datePosted: new Date(),
172
+ amount: -75.5,
173
+ fitId: "2",
174
+ name: "Purchase at a store",
175
+ },
176
+ ],
177
+ });
178
+
179
+ console.log(statement);
180
+ ```
181
+
182
+ ### Streaming Functions
183
+
184
+ For processing large OFX files with low memory footprint.
185
+
186
+ #### `parseStream(input): AsyncGenerator<StreamEvent>`
187
+
188
+ Parses an OFX file as a stream, yielding events as they are parsed.
189
+
190
+ ```typescript
191
+ import { parseStream } from "@fot/ofx";
192
+
193
+ // From a ReadableStream (e.g., fetch response)
194
+ const response = await fetch("https://example.com/statement.ofx");
195
+ for await (const event of parseStream(response.body)) {
196
+ switch (event.type) {
197
+ case "header":
198
+ console.log("OFX Version:", event.data.VERSION);
199
+ break;
200
+ case "account":
201
+ console.log("Account:", event.data.ACCTID);
202
+ break;
203
+ case "transaction":
204
+ console.log("Transaction:", event.data.NAME, event.data.TRNAMT);
205
+ break;
206
+ case "balance":
207
+ console.log("Ledger Balance:", event.data.ledger?.BALAMT);
208
+ break;
209
+ case "complete":
210
+ console.log("Total transactions:", event.transactionCount);
211
+ break;
212
+ }
213
+ }
214
+ ```
215
+
216
+ #### `parseStreamToArray(input): Promise<StreamResult>`
217
+
218
+ Collects all stream events into arrays for easier processing.
219
+
220
+ ```typescript
221
+ import { parseStreamToArray } from "@fot/ofx";
222
+
223
+ const response = await fetch("https://example.com/statement.ofx");
224
+ const result = await parseStreamToArray(response.body);
225
+
226
+ console.log("Header:", result.header);
227
+ console.log("Transactions:", result.transactions.length);
228
+ console.log("Accounts:", result.accounts);
229
+ console.log("Balances:", result.balances);
230
+ ```
231
+
126
232
  ## Types
127
233
 
128
234
  ### OFXTransaction
@@ -227,6 +333,17 @@ interface BalanceInfo {
227
333
  }
228
334
  ```
229
335
 
336
+ ### StreamEvent
337
+
338
+ ```typescript
339
+ type StreamEvent =
340
+ | { type: "header"; data: OFXHeader }
341
+ | { type: "transaction"; data: OFXTransaction }
342
+ | { type: "account"; data: OFXBankAccount | OFXCreditCardAccount }
343
+ | { type: "balance"; data: { ledger?: OFXBalance; available?: OFXBalance } }
344
+ | { type: "complete"; transactionCount: number };
345
+ ```
346
+
230
347
  ## Schemas
231
348
 
232
349
  All Zod schemas are exported for custom validation:
@@ -264,13 +381,17 @@ Tested on realistic business statement sizes:
264
381
 
265
382
  | Transactions | File Size | Parse Time |
266
383
  | ------------ | --------- | ---------- |
267
- | ~10,000 | 2.5 MB | ~800ms |
268
- | ~25,000 | 5.4 MB | ~1.3s |
269
- | ~50,000 | 10.4 MB | ~4.3s |
270
- | ~100,000 | 20.5 MB | ~27s |
384
+ | ~5,000 | 1.2 MB | ~37ms |
385
+ | ~10,000 | 2.5 MB | ~108ms |
386
+ | ~25,000 | 5.4 MB | ~230ms |
387
+ | ~50,000 | 10.4 MB | ~450ms |
271
388
 
272
389
  Extraction operations (`getTransactions`, `getBalance`, etc.) are sub-millisecond even on large datasets.
273
390
 
391
+ ### Streaming Performance
392
+
393
+ The streaming API achieves ~55,000-66,000 transactions/sec throughput with minimal memory overhead, making it ideal for processing very large files or network streams.
394
+
274
395
  ## License
275
396
 
276
397
  MIT