@narrative.io/data-collaboration-sdk-ts 0.0.34 → 0.0.36

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.
@@ -8,6 +8,7 @@ export declare abstract class BaseApi {
8
8
  private readonly environment;
9
9
  private readonly base_api;
10
10
  private readonly headers;
11
+ private readonly verbose;
11
12
  /**
12
13
  * @param {Config} config - Configuration object.
13
14
  * @param {string} [config.apiKey] - API key.
package/build/base-api.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { mande } from 'mande';
2
+ import { addTrailingSlash } from './utils';
2
3
  /**
3
4
  * BaseApi class provides basic functionality for making API requests.
4
5
  */
@@ -7,18 +8,28 @@ export class BaseApi {
7
8
  environment;
8
9
  base_api;
9
10
  headers;
11
+ verbose;
10
12
  /**
11
13
  * @param {Config} config - Configuration object.
12
14
  * @param {string} [config.apiKey] - API key.
13
15
  * @param {Environment} [config.environment='prod'] - Environment for the API (e.g. 'dev', 'prod').
14
16
  */
15
17
  constructor(config) {
18
+ this.verbose = config.verbose ?? false;
16
19
  this.apiKey = config.apiKey;
17
20
  this.environment = config.environment ?? 'prod';
18
21
  this.headers = config.headers ?? {};
19
22
  this.base_api = mande(`${this.getBaseUrl()}`, {
20
23
  headers: this.constructHeaders()
21
24
  });
25
+ if (this.verbose) {
26
+ console.log(`Using environment: ${this.environment}`);
27
+ console.log(`Using API key: ${this.apiKey ?? 'undefined'}`);
28
+ console.log(`Using headers: ${JSON.stringify(this.constructHeaders())}`);
29
+ console.log(`Using base URL: ${this.getBaseUrl()}`);
30
+ console.log(`Using base API: ${JSON.stringify(this.base_api)}`);
31
+ console.log(`This is us: ${JSON.stringify(this)}`);
32
+ }
22
33
  }
23
34
  /**
24
35
  * Retrieves the headers associated with the API instance.
@@ -60,6 +71,11 @@ export class BaseApi {
60
71
  * @template T - Type of the response data.
61
72
  */
62
73
  async get(endpoint) {
74
+ if (this.verbose) {
75
+ console.log(`Making GET request to ${endpoint}...`);
76
+ const resp = await this.base_api.get(endpoint);
77
+ console.log(`Response: ${JSON.stringify(resp)}`);
78
+ }
63
79
  return await this.base_api.get(endpoint);
64
80
  }
65
81
  /**
@@ -72,6 +88,8 @@ export class BaseApi {
72
88
  * @template T - Type of the response data.
73
89
  */
74
90
  async post(endpoint, data) {
91
+ if (this.verbose)
92
+ console.log(`Making POST request to ${endpoint} with data: ${JSON.stringify(data)}...`);
75
93
  return await this.base_api.post(endpoint, data);
76
94
  }
77
95
  /**
@@ -82,6 +100,8 @@ export class BaseApi {
82
100
  * @protected
83
101
  */
84
102
  async delete(endpoint) {
103
+ if (this.verbose)
104
+ console.log(`Making GET request to ${endpoint}...`);
85
105
  await this.base_api.delete(endpoint);
86
106
  }
87
107
  /**
@@ -92,6 +112,8 @@ export class BaseApi {
92
112
  * @returns A Promise that resolves to the data returned by the server.
93
113
  */
94
114
  async put(endpoint, data) {
115
+ if (this.verbose)
116
+ console.log(`Making GET request to ${endpoint} with data: ${JSON.stringify(data)}...`);
95
117
  return await this.base_api.put(endpoint, data);
96
118
  }
97
119
  /**
@@ -109,7 +131,7 @@ export class BaseApi {
109
131
  return 'https://api-dev.narrative.io/';
110
132
  }
111
133
  default: {
112
- return this.environment;
134
+ return addTrailingSlash(this.environment);
113
135
  }
114
136
  }
115
137
  }
package/build/types.d.ts CHANGED
@@ -15,6 +15,7 @@ export interface Config {
15
15
  apiKey?: string;
16
16
  environment?: Environment;
17
17
  headers?: Record<string, string>;
18
+ verbose?: boolean;
18
19
  }
19
20
  export interface ApiRecords<T> {
20
21
  records: T[];
package/build/utils.d.ts CHANGED
@@ -1 +1,7 @@
1
1
  export declare function applyMixins(derivedCtor: any, constructors: any[]): void;
2
+ /**
3
+ * Adds a trailing slash to the given string if it doesn't already end with one.
4
+ * @param str - The input string.
5
+ * @returns The modified string with a trailing slash.
6
+ */
7
+ export declare function addTrailingSlash(str: string): string;
package/build/utils.js CHANGED
@@ -10,3 +10,11 @@ export function applyMixins(derivedCtor, constructors) {
10
10
  });
11
11
  });
12
12
  }
13
+ /**
14
+ * Adds a trailing slash to the given string if it doesn't already end with one.
15
+ * @param str - The input string.
16
+ * @returns The modified string with a trailing slash.
17
+ */
18
+ export function addTrailingSlash(str) {
19
+ return str.endsWith('/') ? str : str + '/';
20
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@narrative.io/data-collaboration-sdk-ts",
3
- "version": "0.0.34",
3
+ "version": "0.0.36",
4
4
  "main": "build/index.js",
5
5
  "repository": "github:narrative-io/data-collaboration-sdk-ts",
6
6
  "source": "src/index.ts",