@qidcloud/sdk 1.2.0 → 1.2.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 +18 -103
- package/dist/components/QidSignInButton.d.ts +3 -0
- package/dist/hooks/useQidAuth.d.ts +18 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +237 -54
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +237 -55
- package/dist/index.mjs.map +1 -1
- package/dist/modules/edge.d.ts +28 -0
- package/dist/modules/vault.d.ts +24 -1
- package/package.json +34 -51
- package/rollup.config.mjs +26 -0
- package/src/components/QidSignInButton.tsx +174 -0
- package/src/hooks/useQidAuth.ts +104 -0
- package/src/index.ts +57 -0
- package/src/modules/auth.ts +77 -0
- package/src/modules/db.ts +40 -0
- package/src/modules/edge.ts +98 -0
- package/src/modules/logs.ts +30 -0
- package/src/modules/vault.ts +124 -0
- package/src/types.ts +52 -0
- package/tsconfig.json +31 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { QidCloud } from '../index';
|
|
2
|
+
import { QidEdgeResponse } from '../types';
|
|
3
|
+
|
|
4
|
+
export class EdgeModule {
|
|
5
|
+
private sdk: QidCloud;
|
|
6
|
+
|
|
7
|
+
constructor(sdk: QidCloud) {
|
|
8
|
+
this.sdk = sdk;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Invoke a serverless edge function
|
|
13
|
+
* @param name Name of the function to invoke
|
|
14
|
+
* @param params Arguments passed to the function
|
|
15
|
+
* @param userToken Optional session token for user-scoped access
|
|
16
|
+
*/
|
|
17
|
+
async invoke(name: string, params: any = {}, userToken?: string): Promise<QidEdgeResponse> {
|
|
18
|
+
const headers: any = {};
|
|
19
|
+
if (userToken) {
|
|
20
|
+
headers['Authorization'] = `Bearer ${userToken}`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const resp = await this.sdk.api.post('/api/edge/invoke', { name, params }, { headers });
|
|
24
|
+
return resp.data;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* List all functions in the project enclave
|
|
29
|
+
*/
|
|
30
|
+
async list(): Promise<any[]> {
|
|
31
|
+
const resp = await this.sdk.api.get('/api/edge/list');
|
|
32
|
+
return resp.data;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Get logs for a specific function
|
|
37
|
+
* @param name Function name
|
|
38
|
+
* @param userToken Optional session token
|
|
39
|
+
*/
|
|
40
|
+
async getLogs(name: string, userToken?: string): Promise<any[]> {
|
|
41
|
+
const headers: any = {};
|
|
42
|
+
if (userToken) headers['Authorization'] = `Bearer ${userToken}`;
|
|
43
|
+
const resp = await this.sdk.api.get(`/api/edge/${name}/logs`, { headers });
|
|
44
|
+
return resp.data;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Get project-wide enclave logs
|
|
49
|
+
*/
|
|
50
|
+
async getProjectLogs(userToken?: string): Promise<any[]> {
|
|
51
|
+
const headers: any = {};
|
|
52
|
+
if (userToken) headers['Authorization'] = `Bearer ${userToken}`;
|
|
53
|
+
const resp = await this.sdk.api.get('/api/edge/logs/project', { headers });
|
|
54
|
+
return resp.data;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Delete a function from the enclave
|
|
59
|
+
*/
|
|
60
|
+
async delete(name: string, userToken?: string): Promise<{ success: boolean }> {
|
|
61
|
+
const headers: any = {};
|
|
62
|
+
if (userToken) headers['Authorization'] = `Bearer ${userToken}`;
|
|
63
|
+
const resp = await this.sdk.api.delete(`/api/edge/${name}`, { headers });
|
|
64
|
+
return resp.data;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Deploy a new function or update an existing one
|
|
69
|
+
* @param data Deployment data including name, code, and optional envVars
|
|
70
|
+
* @param userToken Optional session token
|
|
71
|
+
*/
|
|
72
|
+
async deploy(data: { name: string; code: string; runtime?: string; envVars?: any; overwrite?: boolean }, userToken?: string): Promise<{ success: boolean; message: string }> {
|
|
73
|
+
const headers: any = {};
|
|
74
|
+
if (userToken) headers['Authorization'] = `Bearer ${userToken}`;
|
|
75
|
+
const resp = await this.sdk.api.post('/api/edge/deploy', data, { headers });
|
|
76
|
+
return resp.data;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Get available serverless runtimes
|
|
81
|
+
*/
|
|
82
|
+
async getRuntimes(): Promise<string[]> {
|
|
83
|
+
const resp = await this.sdk.api.get('/api/edge/runtimes');
|
|
84
|
+
return resp.data;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Toggle centralized logging for the project's edge functions
|
|
89
|
+
* @param enabled Whether to enable or disable logging
|
|
90
|
+
* @param userToken Optional session token
|
|
91
|
+
*/
|
|
92
|
+
async toggleLogging(enabled: boolean, userToken?: string): Promise<{ success: boolean; loggingEnabled: boolean }> {
|
|
93
|
+
const headers: any = {};
|
|
94
|
+
if (userToken) headers['Authorization'] = `Bearer ${userToken}`;
|
|
95
|
+
const resp = await this.sdk.api.post('/api/edge/logs/settings', { enabled }, { headers });
|
|
96
|
+
return resp.data;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { QidCloud } from '../index';
|
|
2
|
+
|
|
3
|
+
export class LogsModule {
|
|
4
|
+
private sdk: QidCloud;
|
|
5
|
+
|
|
6
|
+
constructor(sdk: QidCloud) {
|
|
7
|
+
this.sdk = sdk;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Write a custom application log to the project enclave
|
|
12
|
+
* @param message The log message
|
|
13
|
+
* @param source The source of the log (e.g. 'auth-service', 'frontend')
|
|
14
|
+
* @param level Log level (info, warn, error)
|
|
15
|
+
* @param metadata Structured data for searching/filtering
|
|
16
|
+
*/
|
|
17
|
+
async write(message: string, source: string = 'app', level: string = 'info', metadata: any = {}): Promise<{ success: boolean }> {
|
|
18
|
+
const resp = await this.sdk.api.post('/api/logs', { message, source, level, metadata });
|
|
19
|
+
return resp.data;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Retrieve application logs for the project
|
|
24
|
+
* @param query Filters (limit, level, etc.)
|
|
25
|
+
*/
|
|
26
|
+
async fetch(query: any = {}): Promise<any[]> {
|
|
27
|
+
const resp = await this.sdk.api.get('/api/logs', { params: query });
|
|
28
|
+
return resp.data;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { QidCloud } from '../index';
|
|
2
|
+
import { QidFile, QidUploadResponse } from '../types';
|
|
3
|
+
|
|
4
|
+
export class VaultModule {
|
|
5
|
+
private sdk: QidCloud;
|
|
6
|
+
|
|
7
|
+
constructor(sdk: QidCloud) {
|
|
8
|
+
this.sdk = sdk;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Upload a file to the project's secure enclave storage
|
|
13
|
+
* @param file The file data (Buffer or Blob)
|
|
14
|
+
* @param fileName Name of the file
|
|
15
|
+
* @param metadata Optional E2EE metadata or custom tags
|
|
16
|
+
* @param userToken Session token for user-scoped storage
|
|
17
|
+
*/
|
|
18
|
+
async upload(file: any, fileName: string, metadata: any = {}, userToken?: string): Promise<QidUploadResponse> {
|
|
19
|
+
const formData = new FormData();
|
|
20
|
+
formData.append('file', file, fileName);
|
|
21
|
+
formData.append('metadata', JSON.stringify(metadata));
|
|
22
|
+
|
|
23
|
+
const headers: any = {
|
|
24
|
+
'Content-Type': 'multipart/form-data'
|
|
25
|
+
};
|
|
26
|
+
if (userToken) {
|
|
27
|
+
headers['Authorization'] = `Bearer ${userToken}`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const resp = await this.sdk.api.post('/api/storage/upload', formData, { headers });
|
|
31
|
+
return resp.data;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* List files in the project enclave
|
|
36
|
+
* @param userToken Session token for user-scoped storage
|
|
37
|
+
*/
|
|
38
|
+
async list(userToken?: string): Promise<QidFile[]> {
|
|
39
|
+
const headers: any = {};
|
|
40
|
+
if (userToken) {
|
|
41
|
+
headers['Authorization'] = `Bearer ${userToken}`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const resp = await this.sdk.api.get('/api/storage/list', { headers });
|
|
45
|
+
return resp.data;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Download a file from storage
|
|
50
|
+
* @param fileId Unique ID of the file
|
|
51
|
+
* @param userToken Session token for user-scoped storage
|
|
52
|
+
*/
|
|
53
|
+
async download(fileId: string, userToken?: string): Promise<ArrayBuffer> {
|
|
54
|
+
const headers: any = {};
|
|
55
|
+
if (userToken) {
|
|
56
|
+
headers['Authorization'] = `Bearer ${userToken}`;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const resp = await this.sdk.api.get(`/api/storage/${fileId}`, {
|
|
60
|
+
headers,
|
|
61
|
+
responseType: 'arraybuffer'
|
|
62
|
+
});
|
|
63
|
+
return resp.data;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Delete a file from storage (Soft Delete)
|
|
68
|
+
* @param fileId Unique ID of the file
|
|
69
|
+
* @param userToken Session token for user-scoped storage
|
|
70
|
+
*/
|
|
71
|
+
async delete(fileId: string, userToken?: string): Promise<{ success: boolean; message: string }> {
|
|
72
|
+
const headers: any = {};
|
|
73
|
+
if (userToken) {
|
|
74
|
+
headers['Authorization'] = `Bearer ${userToken}`;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const resp = await this.sdk.api.delete(`/api/storage/${fileId}`, { headers });
|
|
78
|
+
return resp.data;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* List deleted files in the project enclave (Recycle Bin)
|
|
83
|
+
* @param userToken Session token for user-scoped storage
|
|
84
|
+
*/
|
|
85
|
+
async listDeleted(userToken?: string): Promise<QidFile[]> {
|
|
86
|
+
const headers: any = {};
|
|
87
|
+
if (userToken) {
|
|
88
|
+
headers['Authorization'] = `Bearer ${userToken}`;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const resp = await this.sdk.api.get('/api/storage/deleted', { headers });
|
|
92
|
+
return resp.data;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Restore a deleted file from the recycle bin
|
|
97
|
+
* @param fileId Unique ID of the file
|
|
98
|
+
* @param userToken Session token for user-scoped storage
|
|
99
|
+
*/
|
|
100
|
+
async restore(fileId: string, userToken?: string): Promise<{ success: boolean; message: string }> {
|
|
101
|
+
const headers: any = {};
|
|
102
|
+
if (userToken) {
|
|
103
|
+
headers['Authorization'] = `Bearer ${userToken}`;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const resp = await this.sdk.api.post(`/api/storage/restore/${fileId}`, {}, { headers });
|
|
107
|
+
return resp.data;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Permanently purge a deleted file
|
|
112
|
+
* @param fileId Unique ID of the file
|
|
113
|
+
* @param userToken Session token for user-scoped storage
|
|
114
|
+
*/
|
|
115
|
+
async purge(fileId: string, userToken?: string): Promise<{ success: boolean; message: string }> {
|
|
116
|
+
const headers: any = {};
|
|
117
|
+
if (userToken) {
|
|
118
|
+
headers['Authorization'] = `Bearer ${userToken}`;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const resp = await this.sdk.api.delete(`/api/storage/purge/${fileId}`, { headers });
|
|
122
|
+
return resp.data;
|
|
123
|
+
}
|
|
124
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export interface QidConfig {
|
|
2
|
+
apiKey: string;
|
|
3
|
+
tenantId: string;
|
|
4
|
+
baseUrl?: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface QidUser {
|
|
8
|
+
userId: string;
|
|
9
|
+
regUserId: string;
|
|
10
|
+
username: string;
|
|
11
|
+
email?: string;
|
|
12
|
+
role: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface QidAuthSession {
|
|
16
|
+
sessionId: string;
|
|
17
|
+
qrData: string;
|
|
18
|
+
expiresAt: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface QidDbResponse<T = any> {
|
|
22
|
+
success: boolean;
|
|
23
|
+
data?: T;
|
|
24
|
+
error?: string;
|
|
25
|
+
count?: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface QidEdgeResponse {
|
|
29
|
+
success: boolean;
|
|
30
|
+
result: any;
|
|
31
|
+
computeTime: string;
|
|
32
|
+
logs?: string[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface QidFile {
|
|
36
|
+
fileId: string;
|
|
37
|
+
originalName: string;
|
|
38
|
+
mimeType: string;
|
|
39
|
+
size: number;
|
|
40
|
+
createdAt: string;
|
|
41
|
+
clientMetadata?: any;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface QidUploadResponse {
|
|
45
|
+
success: boolean;
|
|
46
|
+
message: string;
|
|
47
|
+
file: {
|
|
48
|
+
id: string;
|
|
49
|
+
name: string;
|
|
50
|
+
url: string;
|
|
51
|
+
};
|
|
52
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "node",
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"outDir": "./dist",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"jsx": "react",
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"forceConsistentCasingInFileNames": true,
|
|
13
|
+
"lib": [
|
|
14
|
+
"DOM",
|
|
15
|
+
"ESNext"
|
|
16
|
+
],
|
|
17
|
+
"baseUrl": ".",
|
|
18
|
+
"paths": {
|
|
19
|
+
"*": [
|
|
20
|
+
"src/*"
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"include": [
|
|
25
|
+
"src/**/*"
|
|
26
|
+
],
|
|
27
|
+
"exclude": [
|
|
28
|
+
"node_modules",
|
|
29
|
+
"dist"
|
|
30
|
+
]
|
|
31
|
+
}
|