conductor-node 0.0.18 → 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.
@@ -1,7 +1,8 @@
1
+ import type { Environment } from "./environment";
1
2
  export interface BaseClientOptions {
2
3
  apiKey: string;
3
4
  verbose?: boolean;
4
- environment?: "development" | "staging";
5
+ environment?: Environment;
5
6
  }
6
7
  export default class BaseClient {
7
8
  protected readonly apiKey: string;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const environment_1 = require("./environment");
3
4
  // Store properties via superclass `BaseClient` instead of on `Client` passed to
4
5
  // the integration clients (e.g., `ClientQBD`) to hide these properties from the
5
6
  // dev user while still allowing the integration clients to access them.
@@ -10,15 +11,10 @@ class BaseClient {
10
11
  apiKey;
11
12
  verbose;
12
13
  serverURL;
13
- constructor({ apiKey, verbose = false, environment = "development", }) {
14
+ constructor({ apiKey, verbose = false, environment = "staging", }) {
14
15
  this.apiKey = apiKey;
15
16
  this.verbose = verbose;
16
- if (environment === "development") {
17
- this.serverURL = "https://conductor.ngrok.io";
18
- }
19
- else {
20
- throw new Error(`Unsupported environment: ${environment}`);
21
- }
17
+ this.serverURL = (0, environment_1.envToBaseServerURL)(environment);
22
18
  }
23
19
  }
24
20
  exports.default = BaseClient;
@@ -0,0 +1,2 @@
1
+ export declare type Environment = "development" | "staging";
2
+ export declare function envToBaseServerURL(environment: Environment): string;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.envToBaseServerURL = void 0;
4
+ const STAGING_BASE_URL = "https://conductor-vgag.onrender.com";
5
+ const DEVELOPMENT_BASE_URL = "https://conductor.ngrok.io";
6
+ function envToBaseServerURL(environment) {
7
+ switch (environment) {
8
+ case "staging":
9
+ return STAGING_BASE_URL;
10
+ case "development":
11
+ return DEVELOPMENT_BASE_URL;
12
+ default:
13
+ throw new Error("Invalid environment");
14
+ }
15
+ }
16
+ exports.envToBaseServerURL = envToBaseServerURL;
@@ -12,7 +12,7 @@ class ClientQBD extends BaseClient_1.default {
12
12
  */
13
13
  async sendRequest(qbwcUsername, requestObj) {
14
14
  if (this.verbose) {
15
- console.log(`Client sent request for user ${qbwcUsername}:`, JSON.stringify(requestObj, null, 2));
15
+ console.log(`Client sent request to ${this.serverURL} for user ${qbwcUsername}:`, JSON.stringify(requestObj, null, 2));
16
16
  }
17
17
  const response = await fetch(this.serverURL, {
18
18
  body: JSON.stringify({ qbwcUsername, requestObj }),
@@ -22,6 +22,9 @@ class ClientQBD extends BaseClient_1.default {
22
22
  },
23
23
  method: "POST",
24
24
  });
25
+ if (response.status >= 400) {
26
+ throw new Error(`Request to ${this.serverURL} failed with status ${response.status}: ${response.statusText}`);
27
+ }
25
28
  const responseObj = (await response.json());
26
29
  if (this.verbose) {
27
30
  console.log(`Client received response for user ${qbwcUsername}:`, JSON.stringify(responseObj, null, 2));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "conductor-node",
3
- "version": "0.0.18",
3
+ "version": "0.1.0",
4
4
  "description": "Conductor API wrapper",
5
5
  "author": "Danny Nemer <hi@DannyNemer.com>",
6
6
  "license": "MIT",