@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 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
@@ -11,4 +11,5 @@ export declare class DefarmSdk {
11
11
  readonly http: DefarmHttpClient;
12
12
  constructor(config: SdkConfig);
13
13
  setAccessToken(token?: string): void;
14
+ setApiKey(apiKey?: string): void;
14
15
  }
package/dist/index.js CHANGED
@@ -19,4 +19,7 @@ export class DefarmSdk {
19
19
  setAccessToken(token) {
20
20
  this.http.setAccessToken(token);
21
21
  }
22
+ setApiKey(apiKey) {
23
+ this.http.setApiKey(apiKey);
24
+ }
22
25
  }
package/dist/types.d.ts CHANGED
@@ -3,6 +3,7 @@ export type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
3
3
  export interface SdkConfig {
4
4
  gatewayBaseUrl: string;
5
5
  timeoutMs?: number;
6
+ apiKey?: string;
6
7
  }
7
8
  export interface AuthTokens {
8
9
  access_token: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defarm/sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "DeFarm SDK for CLI and partner integrations",
5
5
  "license": "MIT",
6
6
  "repository": {