caprover-api 0.0.3 → 0.0.5

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
@@ -4,6 +4,8 @@ https://github.com/caprover/caprover-api
4
4
 
5
5
  A simple, typed Typescript SDK for the CapRover API.
6
6
 
7
+ EXPERIMENTAL - backward compatibility is not guaranteed.
8
+
7
9
  ## Install
8
10
 
9
11
  ```
@@ -31,8 +31,9 @@ export type AuthenticationContent = {
31
31
  export type AuthRequiredCallback = () => Promise<AuthenticationContent>;
32
32
  export default class ApiManager {
33
33
  private authCallback;
34
+ private authToken?;
34
35
  private http;
35
- constructor(baseDomain: string, authCallback: AuthRequiredCallback);
36
+ constructor(baseDomain: string, authCallback: AuthRequiredCallback, authToken?: string | undefined);
36
37
  destroy(): void;
37
38
  getAuthToken(): Promise<string>;
38
39
  getAllThemes(): Promise<{
@@ -5,13 +5,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const HttpClient_1 = __importDefault(require("./HttpClient"));
7
7
  class ApiManager {
8
- constructor(baseDomain, authCallback) {
8
+ constructor(baseDomain, authCallback, authToken) {
9
9
  this.authCallback = authCallback;
10
+ this.authToken = authToken;
10
11
  const self = this;
11
12
  const URL = baseDomain + '/api/v2';
12
13
  this.http = new HttpClient_1.default(URL, function () {
13
14
  return self.getAuthToken();
14
- });
15
+ }, authToken);
15
16
  }
16
17
  destroy() {
17
18
  this.http.destroy();
@@ -1,11 +1,11 @@
1
1
  export default class HttpClient {
2
2
  private baseUrl;
3
3
  private onAuthFailure;
4
+ private authToken?;
4
5
  readonly GET = "GET";
5
6
  readonly POST = "POST";
6
7
  isDestroyed: boolean;
7
- private authToken;
8
- constructor(baseUrl: string, onAuthFailure: () => Promise<string>);
8
+ constructor(baseUrl: string, onAuthFailure: () => Promise<string>, authToken?: string | undefined);
9
9
  createHeaders(): any;
10
10
  setAuthToken(authToken: string): void;
11
11
  destroy(): void;
@@ -9,14 +9,16 @@ let TOKEN_HEADER = 'x-captain-auth';
9
9
  let NAMESPACE = 'x-namespace';
10
10
  let CAPTAIN = 'captain';
11
11
  class HttpClient {
12
- constructor(baseUrl, onAuthFailure) {
12
+ constructor(baseUrl, onAuthFailure, authToken) {
13
13
  this.baseUrl = baseUrl;
14
14
  this.onAuthFailure = onAuthFailure;
15
+ this.authToken = authToken;
15
16
  this.GET = 'GET';
16
17
  this.POST = 'POST';
17
18
  this.isDestroyed = false;
18
- this.authToken = '';
19
- //
19
+ if (!authToken) {
20
+ this.authToken = '';
21
+ }
20
22
  }
21
23
  createHeaders() {
22
24
  let headers = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "caprover-api",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "API client for CapRover",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
@@ -43,13 +43,18 @@ export default class ApiManager {
43
43
 
44
44
  constructor(
45
45
  baseDomain: string,
46
- private authCallback: AuthRequiredCallback
46
+ private authCallback: AuthRequiredCallback,
47
+ private authToken?: string
47
48
  ) {
48
49
  const self = this
49
50
  const URL = baseDomain + '/api/v2'
50
- this.http = new HttpClient(URL, function () {
51
- return self.getAuthToken()
52
- })
51
+ this.http = new HttpClient(
52
+ URL,
53
+ function () {
54
+ return self.getAuthToken()
55
+ },
56
+ authToken
57
+ )
53
58
  }
54
59
 
55
60
  destroy() {
@@ -9,13 +9,15 @@ export default class HttpClient {
9
9
  public readonly GET = 'GET'
10
10
  public readonly POST = 'POST'
11
11
  public isDestroyed = false
12
- private authToken: string = ''
13
12
 
14
13
  constructor(
15
14
  private baseUrl: string,
16
- private onAuthFailure: () => Promise<string>
15
+ private onAuthFailure: () => Promise<string>,
16
+ private authToken?: string
17
17
  ) {
18
- //
18
+ if (!authToken) {
19
+ this.authToken = ''
20
+ }
19
21
  }
20
22
 
21
23
  createHeaders() {