@dhilipsiva/nf_ndc_connect_public 0.2.2 → 0.3.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 CHANGED
@@ -1,3 +1,179 @@
1
- # nf-ndc-connect-public
1
+ # nf_ndc_connect_public
2
2
 
3
- Describe your project here.
3
+ **One Logic, Three Platforms.**
4
+ This library provides a unified, secure, and high-performance Identity Provider (IDP) Claims & Authorization helper. It is written in **Rust** and compiled for:
5
+
6
+ * **Rust** (Native Crate)
7
+ * **Python** (via PyO3)
8
+ * **Node.js / Web** (via Wasm-Pack)
9
+
10
+ It handles JWT validation, Role-Based Access Control (RBAC) checks, and parsing of complex IDP organization trees.
11
+
12
+ ---
13
+
14
+ ## 📦 Installation
15
+
16
+ ### 🦀 Rust
17
+
18
+ ```bash
19
+ cargo add nf_ndc_connect_public
20
+
21
+ ```
22
+
23
+ ### 🐍 Python
24
+
25
+ ```bash
26
+ pip install nf_ndc_connect_public
27
+
28
+ ```
29
+
30
+ ### 📦 Node.js (npm)
31
+
32
+ ```bash
33
+ npm install @dhilipsiva/nf_ndc_connect_public
34
+
35
+ ```
36
+
37
+ ---
38
+
39
+ ## 🚀 Usage
40
+
41
+ ### 🐍 Python Example
42
+
43
+ ```python
44
+ import nf_ndc_connect_public
45
+ import json
46
+
47
+ # 1. Initialize with your Public Key (PEM format)
48
+ with open("cert.pem", "r") as f:
49
+ public_key = f.read()
50
+
51
+ helper = nf_ndc_connect_public.IdpAuthHelper(public_key)
52
+
53
+ # 2. Validate a JWT
54
+ raw_jwt = "eyJhbGciOiJ..."
55
+ if helper.is_valid(raw_jwt):
56
+ print("✅ JWT is valid!")
57
+
58
+ # 3. Check specific Roles or Permissions
59
+ org_id = "dhilipsiva_dev/nf-apex"
60
+ if helper.has_role(raw_jwt, org_id, "nf-apex-adm"):
61
+ print("User is an Admin!")
62
+
63
+ # 4. Get full authorization tree (returns JSON string)
64
+ tree_json = helper.get_org_authorisations(raw_jwt)
65
+ print(json.loads(tree_json))
66
+ else:
67
+ print("❌ Invalid or Expired Token")
68
+
69
+ ```
70
+
71
+ ### 📦 Node.js Example
72
+
73
+ ```javascript
74
+ const { IdpAuthHelper } = require("@dhilipsiva/nf_ndc_connect_public");
75
+ const fs = require("fs");
76
+
77
+ // 1. Initialize
78
+ const publicKey = fs.readFileSync("./cert.pem", "utf8");
79
+ const helper = new IdpAuthHelper(publicKey);
80
+
81
+ const rawJwt = "eyJhbGciOiJ...";
82
+
83
+ // 2. Validate
84
+ const isValid = helper.isValid(rawJwt);
85
+ console.log(`Is Valid? ${isValid}`);
86
+
87
+ if (isValid) {
88
+ // 3. Check Role
89
+ const hasRole = helper.hasRole(rawJwt, "dhilipsiva_dev/nf-apex", "nf-apex-adm");
90
+ console.log(`Has Admin Role? ${hasRole}`);
91
+
92
+ // 4. Get Auth Tree
93
+ // Returns a native JS object (not a string) in Node
94
+ const tree = helper.getOrgAuthorisations(rawJwt);
95
+ console.log(tree);
96
+ }
97
+
98
+ ```
99
+
100
+ ### 🦀 Rust Example
101
+
102
+ ```rust
103
+ use nf_ndc_connect_public::AuthHelper;
104
+
105
+ fn main() {
106
+ let public_key = include_str!("../cert.pem");
107
+ let helper = AuthHelper::new(public_key).expect("Invalid Key");
108
+
109
+ let jwt = "eyJhbGciOiJ...";
110
+
111
+ match helper.is_valid(jwt) {
112
+ Ok(claims) => {
113
+ println!("✅ Valid Token for subject: {}", claims.sub);
114
+
115
+ if helper.has_role(jwt, "dhilipsiva_dev/nf-apex", "nf-apex-adm") {
116
+ println!("User is Admin");
117
+ }
118
+ },
119
+ Err(e) => println!("❌ Error: {}", e),
120
+ }
121
+ }
122
+
123
+ ```
124
+
125
+ ---
126
+
127
+ ## 🛠️ Development
128
+
129
+ This project uses **Nix** for a reproducible environment and **Just** for command automation.
130
+
131
+ ### Prerequisites
132
+
133
+ 1. Install [Nix](https://nixos.org/download.html).
134
+ 2. Enable flakes (standard in newer installers).
135
+
136
+ ### Setup
137
+
138
+ Enter the development shell. This installs Rust, Python, Maturin, Node.js, and Wasm-Pack automatically.
139
+
140
+ ```bash
141
+ nix develop
142
+
143
+ ```
144
+
145
+ ### Build Commands (via `just`)
146
+
147
+ | Command | Description |
148
+ | --- | --- |
149
+ | `just py-dev` | Build Python wheel in debug mode & install to venv |
150
+ | `just py-build` | Build Python wheel for release |
151
+ | `just wasm` | Build the Wasm package for Node.js |
152
+ | `just test` | Run standard Cargo tests |
153
+ | `just clean` | Remove all build artifacts (`target/`, `pkg/`, `.venv/`) |
154
+
155
+ ### 🚢 Release Process
156
+
157
+ To publish a new version to PyPI, NPM, and Crates.io simultaneously:
158
+
159
+ 1. **Ensure you are in the Nix shell** (`nix develop`).
160
+ 2. **Run the release command:**
161
+ ```bash
162
+ # Usage: just release <version>
163
+ just release 0.2.3
164
+
165
+ ```
166
+
167
+
168
+ This will:
169
+ * Update `Cargo.toml` and `pyproject.toml`.
170
+ * Run checks.
171
+ * Commit the changes.
172
+ * Create a git tag `v0.2.3`.
173
+
174
+
175
+ 3. **Push to trigger CI/CD:**
176
+ ```bash
177
+ git push && git push --tags
178
+
179
+ ```
Binary file
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@dhilipsiva/nf_ndc_connect_public",
3
3
  "type": "module",
4
4
  "description": "Shared IDP Claims & Auth Logic for Rust, Python (Maturin), and Wasm (Wasm-Pack)",
5
- "version": "0.2.2",
5
+ "version": "0.3.0",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",