learn-secrets-sdk 1.0.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/dist/client.d.ts +35 -0
- package/dist/client.js +77 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +2 -0
- package/dist/types.d.ts +22 -0
- package/dist/types.js +8 -0
- package/package.json +27 -0
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { SecretsSDKOptions, ProxyRequest } from './types';
|
|
2
|
+
export declare class SecretsSDK {
|
|
3
|
+
private appId;
|
|
4
|
+
private sessionToken;
|
|
5
|
+
private baseUrl;
|
|
6
|
+
constructor(options: SecretsSDKOptions);
|
|
7
|
+
/**
|
|
8
|
+
* Call an external API securely through the proxy
|
|
9
|
+
* @param keyName - Name of the API key to use
|
|
10
|
+
* @param endpoint - API endpoint path (e.g., '/v1/chat/completions')
|
|
11
|
+
* @param options - Request options (method, body, headers)
|
|
12
|
+
* @returns Promise with the API response
|
|
13
|
+
*/
|
|
14
|
+
call<T = any>(keyName: string, endpoint: string, options?: Omit<ProxyRequest, 'keyName' | 'endpoint'>): Promise<T>;
|
|
15
|
+
/**
|
|
16
|
+
* Make a GET request
|
|
17
|
+
*/
|
|
18
|
+
get<T = any>(keyName: string, endpoint: string, headers?: Record<string, string>): Promise<T>;
|
|
19
|
+
/**
|
|
20
|
+
* Make a POST request
|
|
21
|
+
*/
|
|
22
|
+
post<T = any>(keyName: string, endpoint: string, body: any, headers?: Record<string, string>): Promise<T>;
|
|
23
|
+
/**
|
|
24
|
+
* Make a PUT request
|
|
25
|
+
*/
|
|
26
|
+
put<T = any>(keyName: string, endpoint: string, body: any, headers?: Record<string, string>): Promise<T>;
|
|
27
|
+
/**
|
|
28
|
+
* Make a DELETE request
|
|
29
|
+
*/
|
|
30
|
+
delete<T = any>(keyName: string, endpoint: string, headers?: Record<string, string>): Promise<T>;
|
|
31
|
+
/**
|
|
32
|
+
* Make a PATCH request
|
|
33
|
+
*/
|
|
34
|
+
patch<T = any>(keyName: string, endpoint: string, body: any, headers?: Record<string, string>): Promise<T>;
|
|
35
|
+
}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { SecretsSDKError } from './types';
|
|
2
|
+
export class SecretsSDK {
|
|
3
|
+
constructor(options) {
|
|
4
|
+
this.appId = options.appId;
|
|
5
|
+
this.sessionToken = options.sessionToken;
|
|
6
|
+
this.baseUrl = options.baseUrl || 'https://learn.pages.dev';
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Call an external API securely through the proxy
|
|
10
|
+
* @param keyName - Name of the API key to use
|
|
11
|
+
* @param endpoint - API endpoint path (e.g., '/v1/chat/completions')
|
|
12
|
+
* @param options - Request options (method, body, headers)
|
|
13
|
+
* @returns Promise with the API response
|
|
14
|
+
*/
|
|
15
|
+
async call(keyName, endpoint, options = {}) {
|
|
16
|
+
try {
|
|
17
|
+
const response = await fetch(`${this.baseUrl}/api/sdk/${this.appId}/proxy`, {
|
|
18
|
+
method: 'POST',
|
|
19
|
+
headers: {
|
|
20
|
+
'Content-Type': 'application/json',
|
|
21
|
+
Authorization: `Bearer ${this.sessionToken}`
|
|
22
|
+
},
|
|
23
|
+
body: JSON.stringify({
|
|
24
|
+
keyName,
|
|
25
|
+
endpoint,
|
|
26
|
+
method: options.method || 'GET',
|
|
27
|
+
body: options.body,
|
|
28
|
+
headers: options.headers
|
|
29
|
+
})
|
|
30
|
+
});
|
|
31
|
+
const result = await response.json();
|
|
32
|
+
if (!response.ok) {
|
|
33
|
+
const errorMessage = result.data?.message ||
|
|
34
|
+
result?.message ||
|
|
35
|
+
`Request failed with status ${response.status}`;
|
|
36
|
+
throw new SecretsSDKError(errorMessage, response.status, result);
|
|
37
|
+
}
|
|
38
|
+
return result.data;
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
if (err instanceof SecretsSDKError) {
|
|
42
|
+
throw err;
|
|
43
|
+
}
|
|
44
|
+
throw new SecretsSDKError(err instanceof Error ? err.message : 'Unknown error occurred', 500);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Make a GET request
|
|
49
|
+
*/
|
|
50
|
+
async get(keyName, endpoint, headers) {
|
|
51
|
+
return this.call(keyName, endpoint, { method: 'GET', headers });
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Make a POST request
|
|
55
|
+
*/
|
|
56
|
+
async post(keyName, endpoint, body, headers) {
|
|
57
|
+
return this.call(keyName, endpoint, { method: 'POST', body, headers });
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Make a PUT request
|
|
61
|
+
*/
|
|
62
|
+
async put(keyName, endpoint, body, headers) {
|
|
63
|
+
return this.call(keyName, endpoint, { method: 'PUT', body, headers });
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Make a DELETE request
|
|
67
|
+
*/
|
|
68
|
+
async delete(keyName, endpoint, headers) {
|
|
69
|
+
return this.call(keyName, endpoint, { method: 'DELETE', headers });
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Make a PATCH request
|
|
73
|
+
*/
|
|
74
|
+
async patch(keyName, endpoint, body, headers) {
|
|
75
|
+
return this.call(keyName, endpoint, { method: 'PATCH', body, headers });
|
|
76
|
+
}
|
|
77
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface SecretsSDKOptions {
|
|
2
|
+
appId: string;
|
|
3
|
+
sessionToken: string;
|
|
4
|
+
baseUrl?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface ProxyRequest {
|
|
7
|
+
keyName: string;
|
|
8
|
+
endpoint: string;
|
|
9
|
+
method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
10
|
+
body?: any;
|
|
11
|
+
headers?: Record<string, string>;
|
|
12
|
+
}
|
|
13
|
+
export interface ProxyResponse<T = any> {
|
|
14
|
+
success: boolean;
|
|
15
|
+
status: number;
|
|
16
|
+
data: T;
|
|
17
|
+
}
|
|
18
|
+
export declare class SecretsSDKError extends Error {
|
|
19
|
+
status: number;
|
|
20
|
+
response?: any | undefined;
|
|
21
|
+
constructor(message: string, status: number, response?: any | undefined);
|
|
22
|
+
}
|
package/dist/types.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "learn-secrets-sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Secure API proxy SDK for static sites",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.esm.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsc && tsc --project tsconfig.esm.json",
|
|
13
|
+
"prepublishOnly": "npm run build"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"api",
|
|
17
|
+
"proxy",
|
|
18
|
+
"secrets",
|
|
19
|
+
"static-sites",
|
|
20
|
+
"security"
|
|
21
|
+
],
|
|
22
|
+
"author": "",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"typescript": "^5.0.0"
|
|
26
|
+
}
|
|
27
|
+
}
|