@qidcloud/sdk 1.1.1 → 1.2.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,310 +1,153 @@
1
1
  # @qidcloud/sdk
2
2
 
3
- Official JavaScript/TypeScript SDK for QidCloud Authentication - Quantum-resistant, passwordless authentication for modern applications.
3
+ The official JavaScript/TypeScript SDK for QidCloud. Build PQC-secured, enclave-backed applications in minutes.
4
4
 
5
- ## Installation
5
+ ## 🚀 30-Minute Quick Start
6
6
 
7
+ ### 1. Install
7
8
  ```bash
8
9
  npm install @qidcloud/sdk
9
10
  ```
10
11
 
11
- ## Quick Start
12
-
12
+ ### 2. Initialize
13
13
  ```typescript
14
14
  import { QidCloud } from '@qidcloud/sdk';
15
15
 
16
- // Initialize with your API key
17
- const qgate = new QidCloud({
18
- apiKey: 'your-api-key-here'
19
- // baseUrl is optional, defaults to https://qgate.onrender.com
16
+ const qid = new QidCloud({
17
+ apiKey: 'your_api_key', // Found in QidCloud Console -> Settings
18
+ tenantId: 'your_project_id'
20
19
  });
21
-
22
- // Register a new user
23
- const user = await qgate.register('alice');
24
-
25
- // Login
26
- const token = await qgate.login();
27
-
28
- // Get user profile
29
- const profile = await qgate.getProfile();
30
-
31
- // Logout
32
- await qgate.logout();
33
20
  ```
34
21
 
35
- ## Features
22
+ ---
36
23
 
37
- **Quantum-Resistant** - Uses CRYSTALS-Dilithium and Kyber
38
- ✅ **Passwordless** - No passwords to remember or manage
39
- ✅ **Zero-Knowledge** - Keys never leave the device
40
- ✅ **TypeScript Support** - Full type definitions included
41
- ✅ **Browser & Node.js** - Works everywhere
24
+ ## 🔑 Identity (`qid.auth`)
42
25
 
43
- ## API Reference
26
+ Enforce Pure Post-Quantum Identity with zero passwords.
44
27
 
45
- ### `new QidCloud(config)`
28
+ ### `createSession()`
29
+ Initiates a new QR handshake session.
30
+ - **Returns**: `Promise<QidAuthSession>`
31
+ - `sessionId`: String
32
+ - `qrData`: String (Format: `qid:handshake:...`)
33
+ - `expiresAt`: Number (Timestamp)
46
34
 
47
- Initialize the QidCloud client.
35
+ ### `listen(sessionId, onAuthorized, onDenied)`
36
+ Listens for the mobile app to approve the session.
37
+ - **`sessionId`**: String (from `createSession`)
38
+ - **`onAuthorized`**: `(token: string) => void` - Callback when login succeeds.
39
+ - **`onDenied`**: `(msg: string) => void` - Callback when user rejects.
48
40
 
49
- **Parameters:**
50
- - `config.apiKey` (required): Your QidCloud API key
51
- - `config.baseUrl` (optional): Custom backend URL, defaults to `https://qgate.onrender.com`
52
- - `config.storage` (optional): Custom storage implementation (defaults to localStorage in browser, memory in Node.js)
53
-
54
- **Example:**
55
- ```typescript
56
- const qgate = new QidCloud({
57
- apiKey: 'qg-abc123...',
58
- baseUrl: 'https://custom-backend.com' // optional
59
- });
60
- ```
41
+ ### `getProfile(token)`
42
+ Fetches user details.
43
+ - **`token`**: String (The session token)
44
+ - **Returns**: `Promise<QidUser>`
61
45
 
62
46
  ---
63
47
 
64
- ### `qgate.register(username, tenantId?)`
48
+ ## 🗄️ Enclave DB (`qid.db`)
65
49
 
66
- Register a new user identity.
50
+ Programmatic SQL access to your project's isolated Postgres schema.
67
51
 
68
- **Parameters:**
69
- - `username` (required): Unique username
70
- - `tenantId` (optional): Custom tenant ID, defaults to 'default'
52
+ ### `query(sql, params, userToken?)`
53
+ Executor for **all** SQL operations (Select, Insert, Update, Delete, and DDL).
54
+ - **`sql`**: String (e.g., `'INSERT INTO users (name) VALUES ($1) RETURNING *'`)
55
+ - **`params`**: Array (Parameterized values to prevent SQL injection)
56
+ - **`userToken`**: Optional String (Required if the user's role must be checked for Mutations/Schema changes)
57
+ - **Returns**: `Promise<QidDbResponse>`
71
58
 
72
- **Returns:** `Promise<UserProfile>`
59
+ **Examples:**
60
+ ```javascript
61
+ // Mutation (Write)
62
+ await qid.db.query('INSERT INTO logs (message) VALUES ($1)', ['User logged in']);
73
63
 
74
- **Example:**
75
- ```typescript
76
- const user = await qgate.register('alice');
77
- console.log(user);
78
- // { userId: "uuid", username: "alice", role: "user" }
64
+ // Schema (DDL)
65
+ await qid.db.query('CREATE TABLE IF NOT EXISTS test (id SERIAL PRIMARY KEY)');
79
66
  ```
80
67
 
81
- **Note:** This generates and stores cryptographic keys locally. **Backup the seed!**
68
+ ### `setup(userToken?)`
69
+ Ensures the project's isolated Postgres schema is properly initialized.
70
+ - **`userToken`**: Optional String
71
+ - **Returns**: `Promise<{ success: boolean; schemaName: string }>`
82
72
 
83
73
  ---
84
74
 
85
- ### `qgate.login()`
86
-
87
- Authenticate using stored identity.
75
+ ## ⚡ Edge Compute (`qid.edge`)
88
76
 
89
- **Returns:** `Promise<string>` - Session token
77
+ Invoke serverless functions within your enclave.
90
78
 
91
- **Example:**
92
- ```typescript
93
- const token = await qgate.login();
94
- // Use token for API requests
95
- ```
79
+ ### `invoke(name, params, userToken?)`
80
+ - **`name`**: String (Function name)
81
+ - **`params`**: Object (Arguments)
82
+ - **`userToken`**: Optional String
83
+ - **Returns**: `Promise<QidEdgeResponse>`
96
84
 
97
- **Throws:**
98
- - `NO_IDENTITY` - User must register first
99
- - `MISSING_USER_ID` - Re-registration required
100
-
101
- ---
85
+ ### `list()`
86
+ Lists all deployed functions in the project.
102
87
 
103
- ### `qgate.getProfile()`
88
+ ### `getLogs(name, userToken?)`
89
+ Fetches the latest execution logs for a specific function.
90
+ - **`name`**: String (Function name)
104
91
 
105
- Get current user's profile.
92
+ ### `getProjectLogs(userToken?)`
93
+ Fetches all enclave-wide system logs. Great for debugging connectivity/auth issues.
106
94
 
107
- **Returns:** `Promise<UserProfile>`
108
-
109
- **Example:**
110
- ```typescript
111
- const profile = await qgate.getProfile();
112
- console.log(profile);
113
- // { userId: "uuid", username: "alice", role: "user", status: "active" }
114
- ```
115
-
116
- **Requires:** Active session (must be logged in)
95
+ ### `delete(name, userToken?)`
96
+ Permanently destroys a function from the enclave.
117
97
 
118
98
  ---
119
99
 
120
- ### `qgate.logout()`
100
+ ## 📦 Vault Storage (`qid.vault`)
121
101
 
122
- End the current session.
102
+ Secure file management.
123
103
 
124
- **Returns:** `Promise<void>`
104
+ ### `upload(file, fileName, metadata?, userToken?)`
105
+ - **`file`**: Buffer | Blob
106
+ - **`fileName`**: String
107
+ - **`metadata`**: Object (Custom tags/E2EE keys)
108
+ - **`userToken`**: Optional String
125
109
 
126
- **Example:**
127
- ```typescript
128
- await qgate.logout();
129
- ```
110
+ ### `list(userToken?)`
111
+ Lists enclave files.
130
112
 
131
- **Note:** Local keys are preserved for future login.
113
+ ### `delete(fileId, userToken?)`
114
+ Permanently destroys a file from storage.
132
115
 
133
116
  ---
134
117
 
135
- ### `qgate.hasIdentity()`
118
+ ## 📝 App Logs (`qid.logs`)
136
119
 
137
- Check if user has registered identity.
120
+ Audit logs for your application logic.
138
121
 
139
- **Returns:** `Promise<boolean>`
122
+ ### `write(message, source?, level?, metadata?)`
123
+ - **`message`**: String (Log content)
124
+ - **`source`**: String (Optional, e.g., 'frontend', 'auth-service')
125
+ - **`level`**: String (Default: `'info'`)
126
+ - **`metadata`**: Object (e.g., `{ userId: '123', event: 'checkout' }`)
140
127
 
141
- **Example:**
142
- ```typescript
143
- if (await qgate.hasIdentity()) {
144
- await qgate.login();
145
- } else {
146
- await qgate.register('alice');
147
- }
148
- ```
128
+ ### `fetch(query?)`
129
+ - **`query`**: Object (e.g., `{ limit: 50, level: 'error' }`)
149
130
 
150
131
  ---
151
132
 
152
- ## Advanced Usage
153
-
154
- ### Custom Storage
155
-
156
- Provide your own storage implementation:
157
-
158
- ```typescript
159
- import { QidCloud, IStorage } from '@qidcloud/sdk';
160
-
161
- class CustomStorage implements IStorage {
162
- async getItem(key: string): Promise<string | null> {
163
- // Your implementation
164
- }
165
-
166
- async setItem(key: string, value: string): Promise<void> {
167
- // Your implementation
168
- }
169
-
170
- async removeItem(key: string): Promise<void> {
171
- // Your implementation
172
- }
173
- }
174
-
175
- const qgate = new QidCloud({
176
- apiKey: 'your-key',
177
- storage: new CustomStorage()
178
- });
179
- ```
180
-
181
- ### Error Handling
182
-
183
- ```typescript
184
- try {
185
- await qgate.login();
186
- } catch (error) {
187
- if (error.message === 'NO_IDENTITY') {
188
- console.log('User not registered');
189
- } else if (error.response?.status === 401) {
190
- console.log('Authentication failed');
191
- }
192
- }
193
- ```
133
+ ## 🎨 UI Components (React)
194
134
 
195
- ### Session Management
135
+ ### `QidSignInButton`
136
+ The easiest way to add QR login.
137
+ ```tsx
138
+ import { QidSignInButton } from '@qidcloud/sdk';
196
139
 
197
- ```typescript
198
- // Check if user is logged in
199
- const hasIdentity = await qgate.hasIdentity();
200
-
201
- // Auto-login on app start
202
- if (hasIdentity) {
203
- try {
204
- await qgate.login();
205
- } catch {
206
- // Handle expired/invalid session
207
- }
208
- }
140
+ <QidSignInButton
141
+ sdk={qid}
142
+ onSuccess={(user, token) => console.log(user)}
143
+ onError={(err) => alert(err)}
144
+ buttonText="Authorize with QidCloud"
145
+ />
209
146
  ```
210
147
 
211
- ## TypeScript
212
-
213
- Full TypeScript support included:
214
-
215
- ```typescript
216
- import { QidCloud, QidConfig, UserProfile } from '@qidcloud/sdk';
217
-
218
- const config: QidConfig = {
219
- apiKey: 'your-key'
220
- };
221
-
222
- const qgate = new QidCloud(config);
223
-
224
- const profile: UserProfile = await qgate.getProfile();
225
- ```
226
-
227
- ## Security Notes
228
-
229
- 🔒 **Private keys never leave the device**
230
- 🔒 **All communication is encrypted**
231
- 🔒 **Quantum-resistant cryptography**
232
- 🔒 **Store API keys securely (environment variables)**
233
-
234
- ## Examples
235
-
236
- ### React Integration
237
-
238
- ```typescript
239
- import { useState, useEffect } from 'react';
240
- import { QidCloud } from '@qidcloud/sdk';
241
-
242
- const qgate = new QidCloud({ apiKey: process.env.REACT_APP_QGATE_KEY });
243
-
244
- function App() {
245
- const [user, setUser] = useState(null);
246
-
247
- useEffect(() => {
248
- async function init() {
249
- if (await qgate.hasIdentity()) {
250
- await qgate.login();
251
- const profile = await qgate.getProfile();
252
- setUser(profile);
253
- }
254
- }
255
- init();
256
- }, []);
257
-
258
- const register = async (username) => {
259
- const user = await qgate.register(username);
260
- setUser(user);
261
- };
262
-
263
- const logout = async () => {
264
- await qgate.logout();
265
- setUser(null);
266
- };
267
-
268
- return user ? (
269
- <div>
270
- <h1>Welcome, {user.username}!</h1>
271
- <button onClick={logout}>Logout</button>
272
- </div>
273
- ) : (
274
- <button onClick={() => register('alice')}>Register</button>
275
- );
276
- }
277
- ```
278
-
279
- ### Node.js Backend
280
-
281
- ```javascript
282
- const { QidCloud } = require('@qidcloud/sdk');
283
-
284
- const qgate = new QidCloud({
285
- apiKey: process.env.QGATE_API_KEY
286
- });
287
-
288
- async function authenticateUser(username) {
289
- if (!await qgate.hasIdentity()) {
290
- await qgate.register(username);
291
- }
292
-
293
- const token = await qgate.login();
294
- return token;
295
- }
296
- ```
297
-
298
- ## Support
299
-
300
- **Documentation:** [Provider Guide](../PROVIDER_API_GUIDE.md)
301
- **Issues:** [GitHub Issues](https://github.com/qgate/sdk/issues)
302
- **Email:** support@qgate.io
303
-
304
- ## License
305
-
306
- ISC
307
-
308
- ---
309
-
310
- **Built with ❤️ by the QidCloud Team**
148
+ **Props:**
149
+ - `sdk`: Instance of `QidCloud`
150
+ - `onSuccess`: `(user, token) => void`
151
+ - `onError`: `(error) => void`
152
+ - `buttonText`: String (Default: "Login with QidCloud")
153
+ - `className`: String (Custom CSS class)
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import { QidCloud } from '../index';
3
+ import { QidUser } from '../types';
4
+ interface QidSignInButtonProps {
5
+ sdk: QidCloud;
6
+ onSuccess: (user: QidUser, token: string) => void;
7
+ onError?: (error: string) => void;
8
+ className?: string;
9
+ buttonText?: string;
10
+ }
11
+ export declare const QidSignInButton: React.FC<QidSignInButtonProps>;
12
+ export {};
package/dist/index.d.ts CHANGED
@@ -1,5 +1,24 @@
1
- import { QidCloud, QidConfig, UserProfile } from './QidCloud';
2
- import UnifiedStorage from './storage';
3
- import * as PQC from './crypto/pqc';
4
- export { QidCloud, QidCloud as PQAuth, QidConfig, UserProfile, UnifiedStorage, PQC };
1
+ import { AxiosInstance } from 'axios';
2
+ import { QidConfig } from './types';
3
+ import { AuthModule } from './modules/auth';
4
+ import { DbModule } from './modules/db';
5
+ import { EdgeModule } from './modules/edge';
6
+ import { VaultModule } from './modules/vault';
7
+ import { LogsModule } from './modules/logs';
8
+ export declare class QidCloud {
9
+ private config;
10
+ api: AxiosInstance;
11
+ auth: AuthModule;
12
+ db: DbModule;
13
+ edge: EdgeModule;
14
+ vault: VaultModule;
15
+ logs: LogsModule;
16
+ constructor(config: QidConfig);
17
+ /**
18
+ * Get the current project configuration
19
+ */
20
+ getConfig(): QidConfig;
21
+ }
5
22
  export default QidCloud;
23
+ export * from './types';
24
+ export { QidSignInButton } from './components/QidSignInButton';