@defarm/sdk 0.1.0 → 0.1.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 +14 -0
- package/dist/client.d.ts +2 -0
- package/dist/client.js +8 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -0
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,6 +21,20 @@ const circuits = await sdk.circuits.list();
|
|
|
21
21
|
console.log(circuits);
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
+
## Autenticação por API key (parceiro)
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { DefarmSdk } from "@defarm/sdk";
|
|
28
|
+
|
|
29
|
+
const sdk = new DefarmSdk({
|
|
30
|
+
gatewayBaseUrl: "https://gateway.defarm.net",
|
|
31
|
+
apiKey: process.env.DEFARM_API_KEY,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const circuits = await sdk.circuits.list();
|
|
35
|
+
console.log(circuits);
|
|
36
|
+
```
|
|
37
|
+
|
|
24
38
|
## Testes
|
|
25
39
|
|
|
26
40
|
```bash
|
package/dist/client.d.ts
CHANGED
|
@@ -2,7 +2,9 @@ import { HttpMethod, SdkConfig } from "./types.js";
|
|
|
2
2
|
export declare class DefarmHttpClient {
|
|
3
3
|
private readonly config;
|
|
4
4
|
private accessToken?;
|
|
5
|
+
private apiKey?;
|
|
5
6
|
constructor(config: SdkConfig);
|
|
6
7
|
setAccessToken(token?: string): void;
|
|
8
|
+
setApiKey(apiKey?: string): void;
|
|
7
9
|
request<T>(method: HttpMethod, path: string, body?: unknown): Promise<T>;
|
|
8
10
|
}
|
package/dist/client.js
CHANGED
|
@@ -3,15 +3,20 @@ import { DefarmApiError } from "./types.js";
|
|
|
3
3
|
export class DefarmHttpClient {
|
|
4
4
|
config;
|
|
5
5
|
accessToken;
|
|
6
|
+
apiKey;
|
|
6
7
|
constructor(config) {
|
|
7
8
|
this.config = {
|
|
8
9
|
timeoutMs: 20000,
|
|
9
10
|
...config,
|
|
10
11
|
};
|
|
12
|
+
this.apiKey = config.apiKey;
|
|
11
13
|
}
|
|
12
14
|
setAccessToken(token) {
|
|
13
15
|
this.accessToken = token;
|
|
14
16
|
}
|
|
17
|
+
setApiKey(apiKey) {
|
|
18
|
+
this.apiKey = apiKey;
|
|
19
|
+
}
|
|
15
20
|
async request(method, path, body) {
|
|
16
21
|
const url = `${this.config.gatewayBaseUrl.replace(/\/$/, "")}${path}`;
|
|
17
22
|
const headers = {
|
|
@@ -20,6 +25,9 @@ export class DefarmHttpClient {
|
|
|
20
25
|
if (this.accessToken) {
|
|
21
26
|
headers.authorization = `Bearer ${this.accessToken}`;
|
|
22
27
|
}
|
|
28
|
+
if (this.apiKey) {
|
|
29
|
+
headers["x-api-key"] = this.apiKey;
|
|
30
|
+
}
|
|
23
31
|
const response = await undiciRequest(url, {
|
|
24
32
|
method,
|
|
25
33
|
headers,
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/types.d.ts
CHANGED