@narrative.io/data-collaboration-sdk-ts 0.0.6 → 0.0.8
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 +47 -0
- package/build/base-api.js +77 -0
- package/build/datasets/index.d.ts +21 -0
- package/build/datasets/index.js +24 -0
- package/build/health/index.d.ts +5 -0
- package/build/health/index.js +7 -0
- package/build/index.d.ts +7 -0
- package/build/index.js +9 -0
- package/build/rosetta-stone/index.d.ts +5 -0
- package/build/rosetta-stone/index.js +7 -0
- package/build/utils.d.ts +1 -0
- package/build/utils.js +12 -0
- package/package.json +5 -7
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Config } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* BaseApi class provides basic functionality for making API requests.
|
|
4
|
+
*/
|
|
5
|
+
export declare abstract class BaseApi {
|
|
6
|
+
private readonly apiKey?;
|
|
7
|
+
private readonly environment;
|
|
8
|
+
private readonly base_api;
|
|
9
|
+
/**
|
|
10
|
+
* @param {Config} config - Configuration object.
|
|
11
|
+
* @param {string} [config.apiKey] - API key.
|
|
12
|
+
* @param {Environment} [config.environment='prod'] - Environment for the API (e.g. 'dev', 'prod').
|
|
13
|
+
*/
|
|
14
|
+
constructor(config: Config);
|
|
15
|
+
/**
|
|
16
|
+
* Makes a GET request to the given endpoint.
|
|
17
|
+
*
|
|
18
|
+
* @param {string} endpoint - Endpoint for the request.
|
|
19
|
+
* @returns {Promise<T>} - Promise that resolves with the response data.
|
|
20
|
+
* @template T - Type of the response data.
|
|
21
|
+
*/
|
|
22
|
+
protected get<T>(endpoint: string): Promise<T>;
|
|
23
|
+
/**
|
|
24
|
+
* Makes a POST request to the given endpoint with the given data.
|
|
25
|
+
*
|
|
26
|
+
* @param {string} endpoint - Endpoint for the request.
|
|
27
|
+
* @param {I} data - Data to be sent in the request.
|
|
28
|
+
* @returns {Promise<T>} - Promise that resolves with the response data.
|
|
29
|
+
* @template I - Type of the request data.
|
|
30
|
+
* @template T - Type of the response data.
|
|
31
|
+
*/
|
|
32
|
+
protected post<I, T>(endpoint: string, data: I): Promise<T>;
|
|
33
|
+
/**
|
|
34
|
+
* Returns the base URL for the API based on the environment.
|
|
35
|
+
*
|
|
36
|
+
* @returns {string} - Base URL for the API.
|
|
37
|
+
* @private
|
|
38
|
+
*/
|
|
39
|
+
private getBaseUrl;
|
|
40
|
+
/**
|
|
41
|
+
* Returns the headers for the API request.
|
|
42
|
+
*
|
|
43
|
+
* @returns {Object.<string, string>} - Headers for the API request.
|
|
44
|
+
* @private
|
|
45
|
+
*/
|
|
46
|
+
private getHeaders;
|
|
47
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { mande } from 'mande';
|
|
2
|
+
/**
|
|
3
|
+
* BaseApi class provides basic functionality for making API requests.
|
|
4
|
+
*/
|
|
5
|
+
export class BaseApi {
|
|
6
|
+
apiKey;
|
|
7
|
+
environment;
|
|
8
|
+
base_api;
|
|
9
|
+
/**
|
|
10
|
+
* @param {Config} config - Configuration object.
|
|
11
|
+
* @param {string} [config.apiKey] - API key.
|
|
12
|
+
* @param {Environment} [config.environment='prod'] - Environment for the API (e.g. 'dev', 'prod').
|
|
13
|
+
*/
|
|
14
|
+
constructor(config) {
|
|
15
|
+
this.apiKey = config.apiKey;
|
|
16
|
+
this.environment = config.environment === null ? config.environment : 'prod';
|
|
17
|
+
this.base_api = mande(`${this.getBaseUrl()}`, {
|
|
18
|
+
headers: this.getHeaders()
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Makes a GET request to the given endpoint.
|
|
23
|
+
*
|
|
24
|
+
* @param {string} endpoint - Endpoint for the request.
|
|
25
|
+
* @returns {Promise<T>} - Promise that resolves with the response data.
|
|
26
|
+
* @template T - Type of the response data.
|
|
27
|
+
*/
|
|
28
|
+
async get(endpoint) {
|
|
29
|
+
return await this.base_api.get(endpoint);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Makes a POST request to the given endpoint with the given data.
|
|
33
|
+
*
|
|
34
|
+
* @param {string} endpoint - Endpoint for the request.
|
|
35
|
+
* @param {I} data - Data to be sent in the request.
|
|
36
|
+
* @returns {Promise<T>} - Promise that resolves with the response data.
|
|
37
|
+
* @template I - Type of the request data.
|
|
38
|
+
* @template T - Type of the response data.
|
|
39
|
+
*/
|
|
40
|
+
async post(endpoint, data) {
|
|
41
|
+
return await this.base_api.post(endpoint, data);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Returns the base URL for the API based on the environment.
|
|
45
|
+
*
|
|
46
|
+
* @returns {string} - Base URL for the API.
|
|
47
|
+
* @private
|
|
48
|
+
*/
|
|
49
|
+
getBaseUrl() {
|
|
50
|
+
switch (this.environment) {
|
|
51
|
+
case 'prod': {
|
|
52
|
+
return 'https://api.narrative.io/';
|
|
53
|
+
}
|
|
54
|
+
case 'dev': {
|
|
55
|
+
return 'https://api-dev.narrative.io/';
|
|
56
|
+
}
|
|
57
|
+
default: {
|
|
58
|
+
return this.environment;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Returns the headers for the API request.
|
|
64
|
+
*
|
|
65
|
+
* @returns {Object.<string, string>} - Headers for the API request.
|
|
66
|
+
* @private
|
|
67
|
+
*/
|
|
68
|
+
getHeaders() {
|
|
69
|
+
const headers = {
|
|
70
|
+
'Content-type': 'application/json'
|
|
71
|
+
};
|
|
72
|
+
if (this.apiKey != null) {
|
|
73
|
+
headers.Authorization = `Bearer ${this.apiKey}`;
|
|
74
|
+
}
|
|
75
|
+
return headers;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type ApiRecords } from 'src/types';
|
|
2
|
+
import { BaseApi } from '../base-api';
|
|
3
|
+
import { type Dataset } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* @module DatasetApi
|
|
6
|
+
* @description This module provides methods for fetching datasets.
|
|
7
|
+
* @extends BaseApi
|
|
8
|
+
*/
|
|
9
|
+
export declare class DatasetApi extends BaseApi {
|
|
10
|
+
/**
|
|
11
|
+
* Get a single dataset by its ID
|
|
12
|
+
* @param {number} datasetId - The ID of the dataset
|
|
13
|
+
* @returns {Promise<Dataset>} - Promise resolving to the requested dataset
|
|
14
|
+
*/
|
|
15
|
+
getDataset(datasetId: number): Promise<Dataset>;
|
|
16
|
+
/**
|
|
17
|
+
* Get a list of all datasets
|
|
18
|
+
* @returns {Promise<ApiRecords<Dataset>>} - Promise resolving to an array of datasets
|
|
19
|
+
*/
|
|
20
|
+
getDatasets(): Promise<ApiRecords<Dataset>>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { BaseApi } from '../base-api';
|
|
2
|
+
const resourceName = 'datasets';
|
|
3
|
+
/**
|
|
4
|
+
* @module DatasetApi
|
|
5
|
+
* @description This module provides methods for fetching datasets.
|
|
6
|
+
* @extends BaseApi
|
|
7
|
+
*/
|
|
8
|
+
export class DatasetApi extends BaseApi {
|
|
9
|
+
/**
|
|
10
|
+
* Get a single dataset by its ID
|
|
11
|
+
* @param {number} datasetId - The ID of the dataset
|
|
12
|
+
* @returns {Promise<Dataset>} - Promise resolving to the requested dataset
|
|
13
|
+
*/
|
|
14
|
+
async getDataset(datasetId) {
|
|
15
|
+
return await this.get(`${resourceName}/${datasetId}`);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Get a list of all datasets
|
|
19
|
+
* @returns {Promise<ApiRecords<Dataset>>} - Promise resolving to an array of datasets
|
|
20
|
+
*/
|
|
21
|
+
async getDatasets() {
|
|
22
|
+
return await this.get(`${resourceName}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
package/build/index.d.ts
ADDED
package/build/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BaseApi } from './base-api';
|
|
2
|
+
import { HealthCheckApi } from './health';
|
|
3
|
+
// import { DatasetApi } from './datasets'
|
|
4
|
+
// import { RosettaStoneApi } from './rosetta-stone'
|
|
5
|
+
import { applyMixins } from './utils';
|
|
6
|
+
class NarrativeApi extends BaseApi {
|
|
7
|
+
}
|
|
8
|
+
applyMixins(NarrativeApi, [BaseApi, HealthCheckApi]);
|
|
9
|
+
export default NarrativeApi;
|
package/build/utils.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function applyMixins(derivedCtor: any, constructors: any[]): void;
|
package/build/utils.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// This can live anywhere in your codebase:
|
|
2
|
+
export function applyMixins(derivedCtor, constructors) {
|
|
3
|
+
constructors.forEach((baseCtor) => {
|
|
4
|
+
Object.getOwnPropertyNames(baseCtor.prototype).forEach((name) => {
|
|
5
|
+
let propertyDescriptor = Object.getOwnPropertyDescriptor(baseCtor.prototype, name);
|
|
6
|
+
if (propertyDescriptor === null || propertyDescriptor === undefined) {
|
|
7
|
+
propertyDescriptor = {};
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(derivedCtor.prototype, name, propertyDescriptor);
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
}
|
package/package.json
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@narrative.io/data-collaboration-sdk-ts",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"main": "
|
|
5
|
-
"module": "dist/index.m.js",
|
|
6
|
-
"umd:main": "dist/index.umd.js",
|
|
3
|
+
"version": "0.0.8",
|
|
4
|
+
"main": "build/index.js",
|
|
7
5
|
"repository": "github:narrative-io/data-collaboration-sdk-ts",
|
|
8
6
|
"source": "src/index.ts",
|
|
9
|
-
"types": "
|
|
7
|
+
"types": "build/index.d.ts",
|
|
10
8
|
"exports": {
|
|
11
|
-
"types": "./
|
|
9
|
+
"types": "./build/index.d.ts"
|
|
12
10
|
},
|
|
13
11
|
"description": "",
|
|
14
12
|
"scripts": {
|
|
@@ -41,6 +39,6 @@
|
|
|
41
39
|
"mande": "^2.0.3"
|
|
42
40
|
},
|
|
43
41
|
"files": [
|
|
44
|
-
"
|
|
42
|
+
"build"
|
|
45
43
|
]
|
|
46
44
|
}
|