@hotfusion/modeller 0.0.2 → 0.0.3
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 +32 -454
- package/docs/CORE.md +191 -0
- package/docs/ERRORS.md +90 -0
- package/docs/MODEL.md +296 -0
- package/docs/PATTERNS.md +182 -0
- package/docs/SERVER.md +88 -0
- package/docs/UTILITIES.md +111 -0
- package/package.json +2 -1
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# Utilities
|
|
2
|
+
|
|
3
|
+
Helpers exported from `@hotfusion/modeller` and from `src/utils`.
|
|
4
|
+
|
|
5
|
+
> [← Back to README](../README.md)
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Public exports
|
|
10
|
+
|
|
11
|
+
| Export | Purpose |
|
|
12
|
+
|-----------|------------------------------------------------------------------------|
|
|
13
|
+
| `Bundler` | Rollup-based bundler for shipping client code (TS, JSON, LESS, terser).|
|
|
14
|
+
| `KeyGen` | System-wide secret generator. |
|
|
15
|
+
| `Adapter` | Base class for persistence — extend to plug in a backing store. |
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## `Bundler`
|
|
20
|
+
|
|
21
|
+
A Rollup wrapper preconfigured for the Modeller stack. Bundles TypeScript, inlines JSON, compiles LESS via `rollup-plugin-postcss`, supports `@rollup/plugin-replace` for build-time substitutions, and minifies with terser.
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { Bundler } from '@hotfusion/modeller';
|
|
25
|
+
|
|
26
|
+
const result = await Bundler.bundle({
|
|
27
|
+
entry : 'src/client/index.ts',
|
|
28
|
+
output : 'dist/client.js'
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Use it for shipping client bundles served by the [Server layer](./SERVER.md), or for any pre-built artifact you want to expose at runtime.
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## `KeyGen`
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { KeyGen } from '@hotfusion/modeller';
|
|
40
|
+
|
|
41
|
+
const secret = KeyGen.getSystemSecret(); // → hex string
|
|
42
|
+
const bytes = KeyGen.getSystemSecret('uint8Array'); // → Uint8Array
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
`getSystemSecret()` returns a stable 32-byte secret. On first call it generates one and caches it to disk (`_secret.key`); subsequent calls return the same value. Use it as the JWT signing key, the session secret, or wherever a stable per-installation secret is needed.
|
|
46
|
+
|
|
47
|
+
`KeyGen.generateSecret(false)` returns a fresh random secret each time — use this for one-off keys (per-document encryption, single-use tokens).
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## `Adapter`
|
|
52
|
+
|
|
53
|
+
Base class for persistence. See the full contract in the [Core layer doc](./CORE.md#adapter).
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import { Adapter } from '@hotfusion/modeller';
|
|
57
|
+
|
|
58
|
+
class MyAdapter extends Adapter {
|
|
59
|
+
async sync(id, doc) { /* persist */ }
|
|
60
|
+
async pull() { /* return docs */ return []; }
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## Internal utilities
|
|
67
|
+
|
|
68
|
+
These live in `src/utils` and aren't re-exported from the package root, but are stable and safe to import directly.
|
|
69
|
+
|
|
70
|
+
### `encrypt` / `decrypt`
|
|
71
|
+
|
|
72
|
+
AES-256-GCM wrappers using a `Uint8Array` secret.
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
import { encrypt, decrypt } from '@hotfusion/modeller/dist/utils/encryption';
|
|
76
|
+
|
|
77
|
+
const hash = await encrypt('plaintext', secretBytes);
|
|
78
|
+
const plain = await decrypt(hash, secretBytes);
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Pair with `KeyGen.getSystemSecret('uint8Array')` for the secret.
|
|
82
|
+
|
|
83
|
+
### `signJWT` / `decodeJWT`
|
|
84
|
+
|
|
85
|
+
`jose`-backed JWT helpers.
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
import { signJWT } from '@hotfusion/modeller/dist/utils/sign-jwt';
|
|
89
|
+
import { decodeJWT } from '@hotfusion/modeller/dist/utils/decode-jwt';
|
|
90
|
+
|
|
91
|
+
const token = await signJWT(payload, secret, { exp: '1h' });
|
|
92
|
+
const claims = decodeJWT(token);
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### `request`
|
|
96
|
+
|
|
97
|
+
Minimal `fetch` wrapper used internally by the connector. Returns the parsed body, throws on non-2xx.
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
import { request } from '@hotfusion/modeller/dist/utils/request';
|
|
101
|
+
|
|
102
|
+
const data = await request('https://api.example.com/x', { method: 'GET' });
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### `ObjectCollection`
|
|
106
|
+
|
|
107
|
+
A typed `Map`-with-extras used internally for keyed collections. Useful when you need a `Map` plus filtering / iteration helpers.
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
> **Related:** [Core →](./CORE.md) · [Errors →](./ERRORS.md)
|
package/package.json
CHANGED