@vicaniddouglas/js_aide 1.19.2 → 1.20.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/README.md +17 -0
- package/declarations.d.ts +85 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -44,6 +44,23 @@ Specialized formatting for financial data. Includes native support for **UGX** (
|
|
|
44
44
|
|
|
45
45
|
A smart loader for external libraries (like SheetJS or jsPDF). Manages CDN fallbacks, retry logic, and ensures libraries are only loaded when needed.
|
|
46
46
|
|
|
47
|
+
### `Response (ok / error)`
|
|
48
|
+
|
|
49
|
+
A standardized response helper mirroring the Python `py_aide.response.Response` pattern. Every operation returns `{ status, data, log }`.
|
|
50
|
+
|
|
51
|
+
- `ok(data)` — creates a success response (truthy via `valueOf()`)
|
|
52
|
+
- `error(message)` — creates an error response (falsy via `valueOf()`)
|
|
53
|
+
- The `Response` class has a **guarded constructor** — only `ok()` and `error()` can instantiate it; direct `new Response(...)` throws.
|
|
54
|
+
|
|
55
|
+
### `FieldTokenizer`
|
|
56
|
+
|
|
57
|
+
A cryptographic token engine compatible with the Python `FieldTokenizer`. Produces v3 tokens (URL-safe base64) that are byte-for-byte interchangeable between JS and Python.
|
|
58
|
+
|
|
59
|
+
- **Non-deterministic** — same value produces a different token each time (random XOR seed)
|
|
60
|
+
- **Integrity** — HMAC-SHA256 verification detects tampering
|
|
61
|
+
- **TTL support** — tokens can expire; expiry is checked on `detokenize()`
|
|
62
|
+
- **Isolated secrets** — different keys produce incompatible tokens
|
|
63
|
+
|
|
47
64
|
### `WebSocket Client`
|
|
48
65
|
|
|
49
66
|
A professional-grade WebSocket implementation with automatic reconnection, heartbeat monitoring, and a registry to prevent duplicate connections.
|
package/declarations.d.ts
CHANGED
|
@@ -1614,4 +1614,89 @@ declare module "@vicaniddouglas/js_aide" {
|
|
|
1614
1614
|
* @returns Object with element, callback, and pool counts
|
|
1615
1615
|
*/
|
|
1616
1616
|
export function getWatcherStats(): WatcherStats;
|
|
1617
|
+
|
|
1618
|
+
// =========================================================
|
|
1619
|
+
// Response (from response.js)
|
|
1620
|
+
// =========================================================
|
|
1621
|
+
/**
|
|
1622
|
+
* Standardized response object with { status, data, log } shape.
|
|
1623
|
+
* Cannot be instantiated directly — use ok() or error() instead.
|
|
1624
|
+
*/
|
|
1625
|
+
export class Response {
|
|
1626
|
+
/** true on success, false on error */
|
|
1627
|
+
status: boolean;
|
|
1628
|
+
/** Error message on failure, "" on success */
|
|
1629
|
+
log: string;
|
|
1630
|
+
/** The payload on success, null on error */
|
|
1631
|
+
data: any;
|
|
1632
|
+
|
|
1633
|
+
/** @throws Error — use ok() / error() instead */
|
|
1634
|
+
private constructor();
|
|
1635
|
+
|
|
1636
|
+
/** Truthy on success, falsy on error */
|
|
1637
|
+
valueOf(): boolean;
|
|
1638
|
+
}
|
|
1639
|
+
|
|
1640
|
+
/**
|
|
1641
|
+
* Create a success Response.
|
|
1642
|
+
* @param data Optional payload (defaults to undefined)
|
|
1643
|
+
*/
|
|
1644
|
+
export function ok(data?: any): Response;
|
|
1645
|
+
|
|
1646
|
+
/**
|
|
1647
|
+
* Create an error Response.
|
|
1648
|
+
* @param message Error description
|
|
1649
|
+
*/
|
|
1650
|
+
export function error(message: string): Response;
|
|
1651
|
+
|
|
1652
|
+
// =========================================================
|
|
1653
|
+
// Tokenizer (from tokens/tokenizer.js)
|
|
1654
|
+
// =========================================================
|
|
1655
|
+
interface TokenizeOptions {
|
|
1656
|
+
/** Time-to-live in seconds */
|
|
1657
|
+
ttl?: number;
|
|
1658
|
+
/** Explicit timestamp (Unix seconds) for testing */
|
|
1659
|
+
timestamp?: number;
|
|
1660
|
+
}
|
|
1661
|
+
|
|
1662
|
+
interface DetokenizeOptions {
|
|
1663
|
+
/** Skip TTL expiry check (default: true) */
|
|
1664
|
+
verify_ttl?: boolean;
|
|
1665
|
+
}
|
|
1666
|
+
|
|
1667
|
+
/**
|
|
1668
|
+
* Cryptographic token engine compatible with Python FieldTokenizer.
|
|
1669
|
+
* Produces v3 tokens with HMAC-SHA256 integrity and optional TTL.
|
|
1670
|
+
*/
|
|
1671
|
+
export class FieldTokenizer {
|
|
1672
|
+
/**
|
|
1673
|
+
* @param secret HMAC key — required, no default.
|
|
1674
|
+
*/
|
|
1675
|
+
constructor(secret: string);
|
|
1676
|
+
|
|
1677
|
+
/**
|
|
1678
|
+
* Transform a value into a non-deterministic, integrity-checked v3 token.
|
|
1679
|
+
* @returns Response with .data = base64url token string on success
|
|
1680
|
+
*/
|
|
1681
|
+
tokenize(value: any, options?: TokenizeOptions): Response;
|
|
1682
|
+
|
|
1683
|
+
/**
|
|
1684
|
+
* Recover the original value from a token, verifying integrity.
|
|
1685
|
+
* Handles v1, v2, and v3 tokens transparently.
|
|
1686
|
+
* @returns Response with .data = original value on success
|
|
1687
|
+
*/
|
|
1688
|
+
detokenize(token: string, options?: DetokenizeOptions): Response;
|
|
1689
|
+
}
|
|
1690
|
+
|
|
1691
|
+
/**
|
|
1692
|
+
* Quick token creation — one call, cached secret.
|
|
1693
|
+
* Pass opts.secret on first call to set the secret.
|
|
1694
|
+
*/
|
|
1695
|
+
export function tokenize(value: any, options?: TokenizeOptions & { secret?: string }): Response;
|
|
1696
|
+
|
|
1697
|
+
/**
|
|
1698
|
+
* Quick token verification — one call, cached secret.
|
|
1699
|
+
* Pass opts.secret on first call to set the secret.
|
|
1700
|
+
*/
|
|
1701
|
+
export function detokenize(token: string, options?: DetokenizeOptions & { secret?: string }): Response;
|
|
1617
1702
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vicaniddouglas/js_aide",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.20.1",
|
|
4
4
|
"description": "A versatile collection of modular JavaScript utility helpers designed to streamline single-page application (SPA) development and general web programming tasks.",
|
|
5
5
|
"main": "dist/js_aide.cjs.js",
|
|
6
6
|
"module": "dist/js_aide.esm.js",
|