zone4code-sdk 1.0.2 → 1.0.4

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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Official TypeScript & JavaScript Client SDK for the **Zone4Code Platform** & **Singulary**.
4
4
 
5
- Provides a type-safe, chainable interface (similar to Supabase / Prisma) for **Keycloak Authentication**, **Adaptive Object-Model (AOM) Dynamic Schemas**, and **JSONB Querying** over the Unified API Gateway.
5
+ Provides a type-safe, chainable interface (similar to Supabase / Prisma) for **Keycloak Authentication**, **Adaptive Object-Model (AOM) Dynamic Schemas**, **JSONB Querying**, **Audit Revisions**, **Graph Relations**, and **Workflow Plugins** over the Unified API Gateway.
6
6
 
7
7
  ---
8
8
 
@@ -22,11 +22,12 @@ pnpm add zone4code-sdk
22
22
  import { createClient } from 'zone4code-sdk';
23
23
 
24
24
  const client = createClient({
25
- gatewayUrl: 'http://localhost:8080', // Or your remote server: https://api.yourdomain.com
26
- tenantId: 'my-workspace-id'
25
+ gatewayUrl: 'http://localhost:8080', // Or your production server: https://api.yourdomain.com
26
+ tenantId: 'my-workspace-id',
27
+ // storageKey: 'stayz.tokens' // Optional custom storage key name
27
28
  });
28
29
 
29
- // 1. Check Gateway Health
30
+ // Check Gateway Health
30
31
  const health = await client.health();
31
32
  console.log('Connected to Gateway:', health.licenseTier);
32
33
  ```
@@ -35,25 +36,60 @@ console.log('Connected to Gateway:', health.licenseTier);
35
36
 
36
37
  ## 🔐 Authentication
37
38
 
39
+ ### 1. Registration & Auto-Login
40
+ Registers a user in Keycloak (`POST /auth/:tenantId/user`) and automatically signs them in:
38
41
  ```typescript
39
- // Register a new user
40
- await client.auth.register({
42
+ const { token, user } = await client.auth.register({
41
43
  email: 'alice@example.com',
42
44
  password: 'SecurePassword123!',
43
45
  name: 'Alice Smith'
44
46
  });
47
+ ```
45
48
 
46
- // Login (JWT token is automatically saved to localStorage/Memory)
47
- const { token } = await client.auth.login({
49
+ ### 2. Login
50
+ Accepts `email`, `username`, or `login`:
51
+ ```typescript
52
+ const { token, refreshToken, user } = await client.auth.login({
48
53
  email: 'alice@example.com',
49
54
  password: 'SecurePassword123!'
50
55
  });
56
+ ```
57
+
58
+ ### 3. Synchronous User Inspection (`getUser`)
59
+ Decodes the active JWT token instantaneously without any network overhead:
60
+ ```typescript
61
+ const user = client.auth.getUser();
62
+ console.log(user?.id, user?.email, user?.roles);
63
+ ```
64
+
65
+ ### 4. Password Recovery & Reset
66
+ ```typescript
67
+ // Send recovery email
68
+ await client.auth.forgotPassword('alice@example.com');
69
+
70
+ // Complete reset with action token
71
+ await client.auth.resetPassword({
72
+ token: actionTokenFromEmail,
73
+ newPassword: 'NewSecurePassword123!'
74
+ });
51
75
 
52
- // Check status & profile
53
- if (client.auth.isAuthenticated()) {
54
- const profile = await client.auth.getProfile();
55
- console.log('Logged in as:', profile.email);
56
- }
76
+ // Change password (while logged in)
77
+ await client.auth.changePassword({
78
+ oldPassword: 'OldPassword123!',
79
+ newPassword: 'NewSecurePassword123!'
80
+ });
81
+ ```
82
+
83
+ ### 5. Token Renewal & Google OAuth
84
+ ```typescript
85
+ // Silent token renewal
86
+ await client.auth.refreshToken();
87
+
88
+ // Google OAuth login
89
+ await client.auth.loginWithGoogle(googleIdToken);
90
+
91
+ // Update user profile attributes
92
+ await client.auth.updateProfile({ firstName: 'Alice', attributes: { theme: 'dark' } });
57
93
 
58
94
  // Logout
59
95
  client.auth.logout();
@@ -90,14 +126,56 @@ console.log(`Found ${total} orders:`, data);
90
126
  ### 3. Update & Delete
91
127
  ```typescript
92
128
  // Update
93
- await client.from('order').update(orderId, {
94
- status: 'paid'
95
- });
129
+ await client.from('order').update(orderId, { status: 'paid' });
96
130
 
97
131
  // Soft Delete
98
132
  await client.from('order').delete(orderId);
99
133
  ```
100
134
 
135
+ ### 4. Revisions & Audit History
136
+ ```typescript
137
+ const revisions = await client.from('order').revisions(orderId);
138
+ console.log('Audit history:', revisions);
139
+ ```
140
+
141
+ ### 5. Graph Relations (Linking Records)
142
+ ```typescript
143
+ // Link order to a client record
144
+ await client.from('order').link(orderId, {
145
+ targetTypeName: 'client',
146
+ targetId: clientId,
147
+ relationName: 'belongs_to'
148
+ });
149
+
150
+ // Fetch all relations
151
+ const relations = await client.from('order').getRelations(orderId);
152
+
153
+ // Unlink
154
+ await client.from('order').unlink(orderId, 'belongs_to', clientId, 'client');
155
+ ```
156
+
157
+ ### 6. Workflow Plugin Actions
158
+ ```typescript
159
+ // Type-level action (e.g. checkout quote)
160
+ await client.from('quote').action('checkout', { quoteId });
161
+
162
+ // Instance-level action (e.g. cancel order)
163
+ await client.from('order').instanceAction(orderId, 'cancel', { reason: 'Customer request' });
164
+ ```
165
+
166
+ ### 7. Export CSV
167
+ ```typescript
168
+ // Returns raw CSV string matching active filters
169
+ const csv = await client.from('order').eq('status', 'paid').exportCsv();
170
+ ```
171
+
172
+ ### 8. User Profile & Wallet (`/me`)
173
+ ```typescript
174
+ // Returns user profile + loyalty wallet points from generic-api
175
+ const me = await client.getMe();
176
+ console.log(me.name, me.wallet?.available_points);
177
+ ```
178
+
101
179
  ---
102
180
 
103
181
  ## 🛠️ Dynamic Schema Alteration