@narrative.io/data-collaboration-sdk-ts 0.0.34 → 0.0.35
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/build/base-api.d.ts +1 -0
- package/build/base-api.js +20 -1
- package/build/types.d.ts +1 -0
- package/build/utils.d.ts +6 -0
- package/build/utils.js +8 -0
- package/package.json +1 -1
package/build/base-api.d.ts
CHANGED
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.headers)}`);
|
|
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,8 @@ 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}...`);
|
|
63
76
|
return await this.base_api.get(endpoint);
|
|
64
77
|
}
|
|
65
78
|
/**
|
|
@@ -72,6 +85,8 @@ export class BaseApi {
|
|
|
72
85
|
* @template T - Type of the response data.
|
|
73
86
|
*/
|
|
74
87
|
async post(endpoint, data) {
|
|
88
|
+
if (this.verbose)
|
|
89
|
+
console.log(`Making POST request to ${endpoint} with data: ${JSON.stringify(data)}...`);
|
|
75
90
|
return await this.base_api.post(endpoint, data);
|
|
76
91
|
}
|
|
77
92
|
/**
|
|
@@ -82,6 +97,8 @@ export class BaseApi {
|
|
|
82
97
|
* @protected
|
|
83
98
|
*/
|
|
84
99
|
async delete(endpoint) {
|
|
100
|
+
if (this.verbose)
|
|
101
|
+
console.log(`Making GET request to ${endpoint}...`);
|
|
85
102
|
await this.base_api.delete(endpoint);
|
|
86
103
|
}
|
|
87
104
|
/**
|
|
@@ -92,6 +109,8 @@ export class BaseApi {
|
|
|
92
109
|
* @returns A Promise that resolves to the data returned by the server.
|
|
93
110
|
*/
|
|
94
111
|
async put(endpoint, data) {
|
|
112
|
+
if (this.verbose)
|
|
113
|
+
console.log(`Making GET request to ${endpoint} with data: ${JSON.stringify(data)}...`);
|
|
95
114
|
return await this.base_api.put(endpoint, data);
|
|
96
115
|
}
|
|
97
116
|
/**
|
|
@@ -109,7 +128,7 @@ export class BaseApi {
|
|
|
109
128
|
return 'https://api-dev.narrative.io/';
|
|
110
129
|
}
|
|
111
130
|
default: {
|
|
112
|
-
return this.environment;
|
|
131
|
+
return addTrailingSlash(this.environment);
|
|
113
132
|
}
|
|
114
133
|
}
|
|
115
134
|
}
|
package/build/types.d.ts
CHANGED
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
|
+
}
|