@partrocks/secrets 0.1.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/error.d.ts +5 -0
- package/dist/error.js +10 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +8 -0
- package/dist/request.d.ts +9 -0
- package/dist/request.js +30 -0
- package/package.json +25 -0
package/dist/error.d.ts
ADDED
package/dist/error.js
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type ClientOptions } from "./request.js";
|
|
2
|
+
export { PartRocksError } from "./error.js";
|
|
3
|
+
export type { ClientOptions } from "./request.js";
|
|
4
|
+
export declare function createSecrets(options: ClientOptions): {
|
|
5
|
+
getConfig: () => Promise<{
|
|
6
|
+
entries: Record<string, string>;
|
|
7
|
+
}>;
|
|
8
|
+
};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type ClientOptions = {
|
|
2
|
+
baseUrl: string;
|
|
3
|
+
apiKey: string;
|
|
4
|
+
};
|
|
5
|
+
export type RequestOptions = {
|
|
6
|
+
body?: unknown;
|
|
7
|
+
accessToken?: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function createRequest(options: ClientOptions): (method: string, path: string, extra?: RequestOptions) => Promise<unknown>;
|
package/dist/request.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { PartRocksError } from "./error.js";
|
|
2
|
+
export function createRequest(options) {
|
|
3
|
+
const baseUrl = options.baseUrl.replace(/\/+$/, "");
|
|
4
|
+
return async function request(method, path, extra = {}) {
|
|
5
|
+
const headers = {
|
|
6
|
+
Accept: "application/json",
|
|
7
|
+
"X-API-Key": options.apiKey,
|
|
8
|
+
};
|
|
9
|
+
if (extra.accessToken) {
|
|
10
|
+
headers.Authorization = `Bearer ${extra.accessToken}`;
|
|
11
|
+
}
|
|
12
|
+
const init = { method, headers };
|
|
13
|
+
if (extra.body !== undefined) {
|
|
14
|
+
headers["Content-Type"] = "application/json";
|
|
15
|
+
init.body = JSON.stringify(extra.body);
|
|
16
|
+
}
|
|
17
|
+
const response = await fetch(`${baseUrl}${path}`, init);
|
|
18
|
+
if (response.status === 204) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
const text = await response.text();
|
|
22
|
+
const data = text === "" ? null : JSON.parse(text);
|
|
23
|
+
if (!response.ok) {
|
|
24
|
+
const message = typeof data?.error === "string" ? data.error : `Request failed with status ${response.status}`;
|
|
25
|
+
const code = typeof data?.code === "string" ? data.code : "request_failed";
|
|
26
|
+
throw new PartRocksError(message, code, response.status);
|
|
27
|
+
}
|
|
28
|
+
return data;
|
|
29
|
+
};
|
|
30
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@partrocks/secrets",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Server-side PartRocks Secrets client",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=20"
|
|
9
|
+
},
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsc",
|
|
23
|
+
"test": "tsx --test test/*.test.ts"
|
|
24
|
+
}
|
|
25
|
+
}
|