@narrative.io/data-collaboration-sdk-ts 0.0.4 → 0.0.7

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.
@@ -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
+ }
@@ -1,5 +1,5 @@
1
- import { BaseApi } from "../base-api";
2
- import type { HealthCheckResult } from "./types";
3
- export declare class HealthCheckApi extends BaseApi {
4
- getHealthCheck(): Promise<HealthCheckResult>;
5
- }
1
+ import { BaseApi } from '../base-api';
2
+ import type { HealthCheckResult } from './types';
3
+ export declare class HealthCheckApi extends BaseApi {
4
+ getHealthCheck(): Promise<HealthCheckResult>;
5
+ }
@@ -0,0 +1,7 @@
1
+ import { BaseApi } from '../base-api';
2
+ const resourceName = 'health';
3
+ export class HealthCheckApi extends BaseApi {
4
+ async getHealthCheck() {
5
+ return await this.get(resourceName);
6
+ }
7
+ }
@@ -0,0 +1,7 @@
1
+ import { BaseApi } from './base-api';
2
+ import { HealthCheckApi } from './health';
3
+ declare class NarrativeApi extends BaseApi {
4
+ }
5
+ interface NarrativeApi extends BaseApi, HealthCheckApi {
6
+ }
7
+ export default NarrativeApi;
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;
@@ -1,5 +1,5 @@
1
- import { BaseApi } from "../base-api";
2
- import { RosettaStoneResponse, SampleRecords } from "./types";
3
- export declare class RosettaStoneApi extends BaseApi {
4
- getLabelsFromSample(sample: SampleRecords): Promise<RosettaStoneResponse[]>;
5
- }
1
+ import { BaseApi } from '../base-api';
2
+ import { type RosettaStoneResponse, type SampleRecords } from './types';
3
+ export declare class RosettaStoneApi extends BaseApi {
4
+ getLabelsFromSample(sample: SampleRecords): Promise<RosettaStoneResponse[]>;
5
+ }
@@ -0,0 +1,7 @@
1
+ import { BaseApi } from '../base-api';
2
+ const resourceName = 'rosetta-stone';
3
+ export class RosettaStoneApi extends BaseApi {
4
+ async getLabelsFromSample(sample) {
5
+ return await this.post(`${resourceName}/labels/sample`, sample);
6
+ }
7
+ }
@@ -1 +1 @@
1
- export declare function applyMixins(derivedCtor: any, constructors: any[]): void;
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@narrative.io/data-collaboration-sdk-ts",
3
- "version": "0.0.4",
3
+ "version": "0.0.7",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.m.js",
6
6
  "umd:main": "dist/index.umd.js",
@@ -12,10 +12,14 @@
12
12
  },
13
13
  "description": "",
14
14
  "scripts": {
15
- "build": "rm -rf dist && microbundle --generateTypes true --tsconfig tsconfig.json",
16
- "dev": "microbundle watch --tsconfig tsconfig.json",
17
- "test": "vitest run --coverage",
18
- "push": "npm run build && npm test && npm publish --access public"
15
+ "build": "tsc",
16
+ "lint": "npx eslint . --fix",
17
+ "prepare": "npm run build",
18
+ "prepublishOnly": "npm test && npm run lint",
19
+ "preversion": "npm run lint",
20
+ "version": "npm run && git add -A src",
21
+ "postversion": "git push && git push --tags",
22
+ "test": "vitest --coverage"
19
23
  },
20
24
  "keywords": [],
21
25
  "author": "",
@@ -37,6 +41,6 @@
37
41
  "mande": "^2.0.3"
38
42
  },
39
43
  "files": [
40
- "dist"
44
+ "build"
41
45
  ]
42
46
  }
@@ -1,47 +0,0 @@
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 apiKey?;
7
- private environment;
8
- private 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
- }
@@ -1,21 +0,0 @@
1
- import { ApiRecords } from "src/types";
2
- import { BaseApi } from "../base-api";
3
- import { 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} dataset_id - The ID of the dataset
13
- * @returns {Promise<Dataset>} - Promise resolving to the requested dataset
14
- */
15
- getDataset(dataset_id: 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
- }
package/dist/index.d.ts DELETED
@@ -1,9 +0,0 @@
1
- import { BaseApi } from './base-api';
2
- import { HealthCheckApi } from './health';
3
- import { DatasetApi } from './datasets';
4
- import { RosettaStoneApi } from './rosetta-stone';
5
- declare class NarrativeApi extends BaseApi {
6
- }
7
- interface NarrativeApi extends BaseApi, HealthCheckApi, DatasetApi, RosettaStoneApi {
8
- }
9
- export default NarrativeApi;
package/dist/index.js DELETED
@@ -1,2 +0,0 @@
1
- var t=require("mande");function e(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,r(t,e)}function r(t,e){return r=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},r(t,e)}var n,o=/*#__PURE__*/function(){function e(e){this.apiKey=void 0,this.environment=void 0,this.base_api=void 0,this.apiKey=e.apiKey,this.environment=e.environment||"prod",this.base_api=t.mande(""+this.getBaseUrl(),{headers:this.getHeaders()})}var r=e.prototype;return r.get=function(t){return this.base_api.get(t)},r.post=function(t,e){return this.base_api.post(t,e)},r.getBaseUrl=function(){switch(this.environment){case"prod":return"https://api.narrative.io/";case"dev":return"https://api-dev.narrative.io/";default:return this.environment}},r.getHeaders=function(){var t={"Content-type":"application/json"};return this.apiKey&&(t.Authorization="Bearer "+this.apiKey),t},e}(),i=/*#__PURE__*/function(t){function r(){return t.apply(this,arguments)||this}return e(r,t),r.prototype.getHealthCheck=function(){try{return Promise.resolve(this.get("health"))}catch(t){return Promise.reject(t)}},r}(o),s="datasets",a=/*#__PURE__*/function(t){function r(){return t.apply(this,arguments)||this}e(r,t);var n=r.prototype;return n.getDataset=function(t){try{return Promise.resolve(this.get(s+"/"+t))}catch(t){return Promise.reject(t)}},n.getDatasets=function(){try{return Promise.resolve(this.get(""+s))}catch(t){return Promise.reject(t)}},r}(o),p=/*#__PURE__*/function(t){function r(){return t.apply(this,arguments)||this}return e(r,t),r.prototype.getLabelsFromSample=function(t){try{return Promise.resolve(this.post("rosetta-stone/labels/sample",t))}catch(t){return Promise.reject(t)}},r}(o),c=/*#__PURE__*/function(t){function r(){return t.apply(this,arguments)||this}return e(r,t),r}(o);n=c,[i,a,p].forEach(function(t){Object.getOwnPropertyNames(t.prototype).forEach(function(e){Object.defineProperty(n.prototype,e,Object.getOwnPropertyDescriptor(t.prototype,e)||Object.create(null))})}),module.exports=c;
2
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":["../src/base-api.ts","../src/utils.ts","../src/health/index.ts","../src/datasets/index.ts","../src/rosetta-stone/index.ts","../src/index.ts"],"sourcesContent":["import { mande, MandeInstance } from 'mande'\nimport type { Config } from './types'\n\n/**\n * BaseApi class provides basic functionality for making API requests.\n */\nexport abstract class BaseApi {\n private apiKey?: string\n private environment: string\n private base_api: MandeInstance\n\n /**\n * @param {Config} config - Configuration object.\n * @param {string} [config.apiKey] - API key.\n * @param {Environment} [config.environment='prod'] - Environment for the API (e.g. 'dev', 'prod').\n */\n constructor(config: Config) {\n this.apiKey = config.apiKey\n this.environment = config.environment || 'prod'\n this.base_api = mande(`${this.getBaseUrl()}`, {\n headers: this.getHeaders(),\n })\n }\n\n /**\n * Makes a GET request to the given endpoint.\n *\n * @param {string} endpoint - Endpoint for the request.\n * @returns {Promise<T>} - Promise that resolves with the response data.\n * @template T - Type of the response data.\n */\n protected get<T>(endpoint: string): Promise<T> {\n return this.base_api.get<T>(endpoint)\n }\n\n /**\n * Makes a POST request to the given endpoint with the given data.\n *\n * @param {string} endpoint - Endpoint for the request.\n * @param {I} data - Data to be sent in the request.\n * @returns {Promise<T>} - Promise that resolves with the response data.\n * @template I - Type of the request data.\n * @template T - Type of the response data.\n */\n protected post<I, T>(endpoint: string, data: I): Promise<T> {\n return this.base_api.post<T>(endpoint, data)\n }\n\n /**\n * Returns the base URL for the API based on the environment.\n *\n * @returns {string} - Base URL for the API.\n * @private\n */\n private getBaseUrl(): string {\n switch (this.environment) {\n case 'prod': {\n return `https://api.narrative.io/`\n }\n case 'dev': {\n return `https://api-dev.narrative.io/`\n }\n default: {\n return this.environment\n }\n }\n }\n\n /**\n * Returns the headers for the API request.\n *\n * @returns {Object.<string, string>} - Headers for the API request.\n * @private\n */\n private getHeaders(): { [key: string]: string } {\n const headers: { [key: string]: string } = {\n 'Content-type': 'application/json'\n }\n\n if (this.apiKey) {\n headers['Authorization'] = `Bearer ${this.apiKey}`\n }\n\n return headers\n }\n}","export function applyMixins(derivedCtor: any, constructors: any[]) {\n constructors.forEach((baseCtor) => {\n Object.getOwnPropertyNames(baseCtor.prototype).forEach((name) => {\n Object.defineProperty(\n derivedCtor.prototype,\n name,\n Object.getOwnPropertyDescriptor(baseCtor.prototype, name) ||\n Object.create(null)\n );\n });\n });\n}","import { BaseApi } from \"../base-api\";\nimport type { HealthCheckResult } from \"./types\";\n\nconst resourceName = 'health';\n\nexport class HealthCheckApi extends BaseApi {\n public async getHealthCheck(): Promise<HealthCheckResult> {\n return await this.get<HealthCheckResult>(resourceName);\n }\n}","import { ApiRecords } from \"src/types\";\nimport { BaseApi } from \"../base-api\";\nimport { Dataset } from \"./types\";\n\nconst resourceName = 'datasets';\n\n/**\n * @module DatasetApi\n * @description This module provides methods for fetching datasets.\n * @extends BaseApi\n */\nexport class DatasetApi extends BaseApi {\n \n /**\n * Get a single dataset by its ID\n * @param {number} dataset_id - The ID of the dataset\n * @returns {Promise<Dataset>} - Promise resolving to the requested dataset\n */\n public async getDataset(dataset_id: number): Promise<Dataset> {\n return this.get<Dataset>(`${resourceName}/${dataset_id}`);\n }\n\n /**\n * Get a list of all datasets\n * @returns {Promise<ApiRecords<Dataset>>} - Promise resolving to an array of datasets\n */\n public async getDatasets(): Promise<ApiRecords<Dataset>> {\n return this.get<ApiRecords<Dataset>>(`${resourceName}`);\n }\n}","import { BaseApi } from \"../base-api\";\nimport { RosettaStoneResponse, SampleRecords } from \"./types\";\n\nconst resourceName = 'rosetta-stone';\n\nexport class RosettaStoneApi extends BaseApi {\n public async getLabelsFromSample(sample: SampleRecords): Promise<RosettaStoneResponse[]> {\n return this.post<SampleRecords, RosettaStoneResponse[]>(`${resourceName}/labels/sample`, sample);\n }\n}","import { BaseApi } from './base-api';\nimport { HealthCheckApi } from './health'\nimport { DatasetApi } from './datasets'\nimport { RosettaStoneApi } from './rosetta-stone'\nimport { applyMixins } from './utils'\n\nclass NarrativeApi extends BaseApi { }\ninterface NarrativeApi extends BaseApi, HealthCheckApi, DatasetApi, RosettaStoneApi { }\napplyMixins(NarrativeApi, [HealthCheckApi, DatasetApi, RosettaStoneApi]);\n\nexport default NarrativeApi"],"names":["derivedCtor","BaseApi","config","apiKey","this","environment","base_api","mande","getBaseUrl","headers","getHeaders","get","endpoint","post","data","_proto","HealthCheckApi","_BaseApi","apply","arguments","_inheritsLoose","prototype","getHealthCheck","Promise","resolve","e","reject","resourceName","getDataset","dataset_id","getDatasets","RosettaStoneApi","getLabelsFromSample","sample","NarrativeApi","DatasetApi","forEach","baseCtor","Object","getOwnPropertyNames","name","defineProperty","getOwnPropertyDescriptor","create"],"mappings":"wOAMA,ICN4BA,iBDgBxB,WAAA,SAAAC,EAAYC,QATJC,YAAM,EAAAC,KACNC,iBAAW,EAAAD,KACXE,cAQJ,EAAAF,KAAKD,OAASD,EAAOC,OACrBC,KAAKC,YAAcH,EAAOG,aAAe,OACzCD,KAAKE,SAAWC,EAAKA,SAAIH,KAAKI,aAAgB,CAC1CC,QAASL,KAAKM,cAEtB,CAAC,IASSC,EAAAA,EAAAA,UAqDT,OArDSA,EAAAA,IAAA,SAAOC,GACb,OAAOR,KAAKE,SAASK,IAAOC,EAChC,EAWUC,EAAAA,KAAA,SAAWD,EAAkBE,GACnC,OAAWV,KAACE,SAASO,KAAQD,EAAUE,EAC3C,EAACC,EAQOP,WAAA,WACJ,OAAQJ,KAAKC,aACT,IAAK,OACD,MACH,4BACD,IAAK,MACD,MAAA,gCAEJ,QACI,OAAOD,KAAKC,YAGxB,IAQQK,WAAA,WACJ,IAAaD,EAA8B,CACvC,eAAgB,oBAOpB,OAJIL,KAAKD,SACLM,EAAuB,cAAC,UAAaL,KAAKD,SAIlD,EAACF,CAAA,CApED,GEXwBe,eAAA,SAAAC,GAAA,SAAAD,IAAA,OAAAC,EAAAC,MAAAd,KAAAe,YAAAf,IAAA,CAGvB,OAHuBgB,EAAAJ,EAAAC,GAAAD,EAAAK,UACXC,eAAc,WAAA,IACN,OAAAC,QAAAC,QAAJpB,KAAKO,IAJL,UAKhB,CAAA,MAAAc,GAAA,OAAAF,QAAAG,OAAAD,EAAA,CAAA,EAAAT,CAAA,CAHuB,CAAQf,GCDlB0B,EAAG,0BAcJC,SAAAA,GAAAA,SAAAA,IAAAA,OAAAA,EAAAA,MAAAA,KAAAA,YAAAA,IAAAA,CAAAA,EAAAA,EAAAA,GAAAA,IAAAA,EAAAA,EAAAA,iBAAAA,EAAAA,oBAAWC,GAAkB,IACtC,uBAAOzB,KAAKO,IAAgBgB,EAAY,IAAIE,GAOnCC,CANZ,MAMYA,GAAAA,OAAAA,QAAAA,OAAAA,EAAAA,CAAAA,EAAAA,EAAAA,2BACT,OAAOP,QAAAC,QAAApB,KAAKO,IAA4BgB,GAAAA,IAC3C,sCAVYC,CAPe3B,GCNH8B,eAAA,SAAAd,GAAA,SAAAc,IAAA,OAAAd,EAAAC,MAAAd,KAAAe,YAAAf,IAAA,QAAAgB,EAAAW,EAAAd,GAAAc,EAAAV,UACZW,oBAAoBC,SAAAA,GAAqB,IAClD,OAAOV,QAAAC,QAAApB,KAAKS,KAA+Cc,8BAA8BM,IAC5F,sCAHwB,CAAQhC,GCClBiC,eAAA,SAAAjB,GAAA,SAAAiB,IAAA,OAAAjB,EAAAC,MAAAd,KAAAe,YAAAf,IAAA,CAAA,OAAAgB,EAAAc,EAAAjB,GAAAiB,CAAA,CAAA,CAAQjC,GJNCD,EIQhBkC,EAAc,CAAClB,EAAgBmB,EAAYJ,GJPtCK,QAAQ,SAACC,GAClBC,OAAOC,oBAAoBF,EAAShB,WAAWe,QAAQ,SAACI,GACpDF,OAAOG,eACHzC,EAAYqB,UACZmB,EACAF,OAAOI,yBAAyBL,EAAShB,UAAWmB,IACpDF,OAAOK,OAAO,MAEtB,EACJ"}
package/dist/index.m.js DELETED
@@ -1,2 +0,0 @@
1
- import{mande as t}from"mande";function e(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,r(t,e)}function r(t,e){return r=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},r(t,e)}var n,o=/*#__PURE__*/function(){function e(e){this.apiKey=void 0,this.environment=void 0,this.base_api=void 0,this.apiKey=e.apiKey,this.environment=e.environment||"prod",this.base_api=t(""+this.getBaseUrl(),{headers:this.getHeaders()})}var r=e.prototype;return r.get=function(t){return this.base_api.get(t)},r.post=function(t,e){return this.base_api.post(t,e)},r.getBaseUrl=function(){switch(this.environment){case"prod":return"https://api.narrative.io/";case"dev":return"https://api-dev.narrative.io/";default:return this.environment}},r.getHeaders=function(){var t={"Content-type":"application/json"};return this.apiKey&&(t.Authorization="Bearer "+this.apiKey),t},e}(),i=/*#__PURE__*/function(t){function r(){return t.apply(this,arguments)||this}return e(r,t),r.prototype.getHealthCheck=function(){try{return Promise.resolve(this.get("health"))}catch(t){return Promise.reject(t)}},r}(o),s="datasets",a=/*#__PURE__*/function(t){function r(){return t.apply(this,arguments)||this}e(r,t);var n=r.prototype;return n.getDataset=function(t){try{return Promise.resolve(this.get(s+"/"+t))}catch(t){return Promise.reject(t)}},n.getDatasets=function(){try{return Promise.resolve(this.get(""+s))}catch(t){return Promise.reject(t)}},r}(o),p=/*#__PURE__*/function(t){function r(){return t.apply(this,arguments)||this}return e(r,t),r.prototype.getLabelsFromSample=function(t){try{return Promise.resolve(this.post("rosetta-stone/labels/sample",t))}catch(t){return Promise.reject(t)}},r}(o),c=/*#__PURE__*/function(t){function r(){return t.apply(this,arguments)||this}return e(r,t),r}(o);n=c,[i,a,p].forEach(function(t){Object.getOwnPropertyNames(t.prototype).forEach(function(e){Object.defineProperty(n.prototype,e,Object.getOwnPropertyDescriptor(t.prototype,e)||Object.create(null))})});export{c as default};
2
- //# sourceMappingURL=index.m.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.m.js","sources":["../src/base-api.ts","../src/utils.ts","../src/health/index.ts","../src/datasets/index.ts","../src/rosetta-stone/index.ts","../src/index.ts"],"sourcesContent":["import { mande, MandeInstance } from 'mande'\nimport type { Config } from './types'\n\n/**\n * BaseApi class provides basic functionality for making API requests.\n */\nexport abstract class BaseApi {\n private apiKey?: string\n private environment: string\n private base_api: MandeInstance\n\n /**\n * @param {Config} config - Configuration object.\n * @param {string} [config.apiKey] - API key.\n * @param {Environment} [config.environment='prod'] - Environment for the API (e.g. 'dev', 'prod').\n */\n constructor(config: Config) {\n this.apiKey = config.apiKey\n this.environment = config.environment || 'prod'\n this.base_api = mande(`${this.getBaseUrl()}`, {\n headers: this.getHeaders(),\n })\n }\n\n /**\n * Makes a GET request to the given endpoint.\n *\n * @param {string} endpoint - Endpoint for the request.\n * @returns {Promise<T>} - Promise that resolves with the response data.\n * @template T - Type of the response data.\n */\n protected get<T>(endpoint: string): Promise<T> {\n return this.base_api.get<T>(endpoint)\n }\n\n /**\n * Makes a POST request to the given endpoint with the given data.\n *\n * @param {string} endpoint - Endpoint for the request.\n * @param {I} data - Data to be sent in the request.\n * @returns {Promise<T>} - Promise that resolves with the response data.\n * @template I - Type of the request data.\n * @template T - Type of the response data.\n */\n protected post<I, T>(endpoint: string, data: I): Promise<T> {\n return this.base_api.post<T>(endpoint, data)\n }\n\n /**\n * Returns the base URL for the API based on the environment.\n *\n * @returns {string} - Base URL for the API.\n * @private\n */\n private getBaseUrl(): string {\n switch (this.environment) {\n case 'prod': {\n return `https://api.narrative.io/`\n }\n case 'dev': {\n return `https://api-dev.narrative.io/`\n }\n default: {\n return this.environment\n }\n }\n }\n\n /**\n * Returns the headers for the API request.\n *\n * @returns {Object.<string, string>} - Headers for the API request.\n * @private\n */\n private getHeaders(): { [key: string]: string } {\n const headers: { [key: string]: string } = {\n 'Content-type': 'application/json'\n }\n\n if (this.apiKey) {\n headers['Authorization'] = `Bearer ${this.apiKey}`\n }\n\n return headers\n }\n}","export function applyMixins(derivedCtor: any, constructors: any[]) {\n constructors.forEach((baseCtor) => {\n Object.getOwnPropertyNames(baseCtor.prototype).forEach((name) => {\n Object.defineProperty(\n derivedCtor.prototype,\n name,\n Object.getOwnPropertyDescriptor(baseCtor.prototype, name) ||\n Object.create(null)\n );\n });\n });\n}","import { BaseApi } from \"../base-api\";\nimport type { HealthCheckResult } from \"./types\";\n\nconst resourceName = 'health';\n\nexport class HealthCheckApi extends BaseApi {\n public async getHealthCheck(): Promise<HealthCheckResult> {\n return await this.get<HealthCheckResult>(resourceName);\n }\n}","import { ApiRecords } from \"src/types\";\nimport { BaseApi } from \"../base-api\";\nimport { Dataset } from \"./types\";\n\nconst resourceName = 'datasets';\n\n/**\n * @module DatasetApi\n * @description This module provides methods for fetching datasets.\n * @extends BaseApi\n */\nexport class DatasetApi extends BaseApi {\n \n /**\n * Get a single dataset by its ID\n * @param {number} dataset_id - The ID of the dataset\n * @returns {Promise<Dataset>} - Promise resolving to the requested dataset\n */\n public async getDataset(dataset_id: number): Promise<Dataset> {\n return this.get<Dataset>(`${resourceName}/${dataset_id}`);\n }\n\n /**\n * Get a list of all datasets\n * @returns {Promise<ApiRecords<Dataset>>} - Promise resolving to an array of datasets\n */\n public async getDatasets(): Promise<ApiRecords<Dataset>> {\n return this.get<ApiRecords<Dataset>>(`${resourceName}`);\n }\n}","import { BaseApi } from \"../base-api\";\nimport { RosettaStoneResponse, SampleRecords } from \"./types\";\n\nconst resourceName = 'rosetta-stone';\n\nexport class RosettaStoneApi extends BaseApi {\n public async getLabelsFromSample(sample: SampleRecords): Promise<RosettaStoneResponse[]> {\n return this.post<SampleRecords, RosettaStoneResponse[]>(`${resourceName}/labels/sample`, sample);\n }\n}","import { BaseApi } from './base-api';\nimport { HealthCheckApi } from './health'\nimport { DatasetApi } from './datasets'\nimport { RosettaStoneApi } from './rosetta-stone'\nimport { applyMixins } from './utils'\n\nclass NarrativeApi extends BaseApi { }\ninterface NarrativeApi extends BaseApi, HealthCheckApi, DatasetApi, RosettaStoneApi { }\napplyMixins(NarrativeApi, [HealthCheckApi, DatasetApi, RosettaStoneApi]);\n\nexport default NarrativeApi"],"names":["derivedCtor","BaseApi","config","apiKey","this","environment","base_api","mande","getBaseUrl","headers","getHeaders","get","endpoint","post","data","_proto","HealthCheckApi","_BaseApi","apply","arguments","_inheritsLoose","prototype","getHealthCheck","Promise","resolve","e","reject","resourceName","getDataset","dataset_id","getDatasets","RosettaStoneApi","getLabelsFromSample","sample","NarrativeApi","DatasetApi","forEach","baseCtor","Object","getOwnPropertyNames","name","defineProperty","getOwnPropertyDescriptor","create"],"mappings":"+OAMA,ICN4BA,iBDgBxB,WAAA,SAAAC,EAAYC,QATJC,YAAM,EAAAC,KACNC,iBAAW,EAAAD,KACXE,cAQJ,EAAAF,KAAKD,OAASD,EAAOC,OACrBC,KAAKC,YAAcH,EAAOG,aAAe,OACzCD,KAAKE,SAAWC,KAASH,KAAKI,aAAgB,CAC1CC,QAASL,KAAKM,cAEtB,CAAC,IASSC,EAAAA,EAAAA,UAqDT,OArDSA,EAAAA,IAAA,SAAOC,GACb,OAAOR,KAAKE,SAASK,IAAOC,EAChC,EAWUC,EAAAA,KAAA,SAAWD,EAAkBE,GACnC,OAAWV,KAACE,SAASO,KAAQD,EAAUE,EAC3C,EAACC,EAQOP,WAAA,WACJ,OAAQJ,KAAKC,aACT,IAAK,OACD,MACH,4BACD,IAAK,MACD,MAAA,gCAEJ,QACI,OAAOD,KAAKC,YAGxB,IAQQK,WAAA,WACJ,IAAaD,EAA8B,CACvC,eAAgB,oBAOpB,OAJIL,KAAKD,SACLM,EAAuB,cAAC,UAAaL,KAAKD,SAIlD,EAACF,CAAA,CApED,GEXwBe,eAAA,SAAAC,GAAA,SAAAD,IAAA,OAAAC,EAAAC,MAAAd,KAAAe,YAAAf,IAAA,CAGvB,OAHuBgB,EAAAJ,EAAAC,GAAAD,EAAAK,UACXC,eAAc,WAAA,IACN,OAAAC,QAAAC,QAAJpB,KAAKO,IAJL,UAKhB,CAAA,MAAAc,GAAA,OAAAF,QAAAG,OAAAD,EAAA,CAAA,EAAAT,CAAA,CAHuB,CAAQf,GCDlB0B,EAAG,0BAcJC,SAAAA,GAAAA,SAAAA,IAAAA,OAAAA,EAAAA,MAAAA,KAAAA,YAAAA,IAAAA,CAAAA,EAAAA,EAAAA,GAAAA,IAAAA,EAAAA,EAAAA,iBAAAA,EAAAA,oBAAWC,GAAkB,IACtC,uBAAOzB,KAAKO,IAAgBgB,EAAY,IAAIE,GAOnCC,CANZ,MAMYA,GAAAA,OAAAA,QAAAA,OAAAA,EAAAA,CAAAA,EAAAA,EAAAA,2BACT,OAAOP,QAAAC,QAAApB,KAAKO,IAA4BgB,GAAAA,IAC3C,sCAVYC,CAPe3B,GCNH8B,eAAA,SAAAd,GAAA,SAAAc,IAAA,OAAAd,EAAAC,MAAAd,KAAAe,YAAAf,IAAA,QAAAgB,EAAAW,EAAAd,GAAAc,EAAAV,UACZW,oBAAoBC,SAAAA,GAAqB,IAClD,OAAOV,QAAAC,QAAApB,KAAKS,KAA+Cc,8BAA8BM,IAC5F,sCAHwB,CAAQhC,GCClBiC,eAAA,SAAAjB,GAAA,SAAAiB,IAAA,OAAAjB,EAAAC,MAAAd,KAAAe,YAAAf,IAAA,CAAA,OAAAgB,EAAAc,EAAAjB,GAAAiB,CAAA,CAAA,CAAQjC,GJNCD,EIQhBkC,EAAc,CAAClB,EAAgBmB,EAAYJ,GJPtCK,QAAQ,SAACC,GAClBC,OAAOC,oBAAoBF,EAAShB,WAAWe,QAAQ,SAACI,GACpDF,OAAOG,eACHzC,EAAYqB,UACZmB,EACAF,OAAOI,yBAAyBL,EAAShB,UAAWmB,IACpDF,OAAOK,OAAO,MAEtB,EACJ"}
@@ -1,2 +0,0 @@
1
- import{mande as t}from"mande";class e{constructor(e){this.apiKey=void 0,this.environment=void 0,this.base_api=void 0,this.apiKey=e.apiKey,this.environment=e.environment||"prod",this.base_api=t(`${this.getBaseUrl()}`,{headers:this.getHeaders()})}get(t){return this.base_api.get(t)}post(t,e){return this.base_api.post(t,e)}getBaseUrl(){switch(this.environment){case"prod":return"https://api.narrative.io/";case"dev":return"https://api-dev.narrative.io/";default:return this.environment}}getHeaders(){const t={"Content-type":"application/json"};return this.apiKey&&(t.Authorization=`Bearer ${this.apiKey}`),t}}const s="datasets";class a extends e{}var r;r=a,[class extends e{async getHealthCheck(){return await this.get("health")}},class extends e{async getDataset(t){return this.get(`${s}/${t}`)}async getDatasets(){return this.get(`${s}`)}},class extends e{async getLabelsFromSample(t){return this.post("rosetta-stone/labels/sample",t)}}].forEach(t=>{Object.getOwnPropertyNames(t.prototype).forEach(e=>{Object.defineProperty(r.prototype,e,Object.getOwnPropertyDescriptor(t.prototype,e)||Object.create(null))})});export{a as default};
2
- //# sourceMappingURL=index.modern.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.modern.mjs","sources":["../src/base-api.ts","../src/datasets/index.ts","../src/index.ts","../src/utils.ts","../src/health/index.ts","../src/rosetta-stone/index.ts"],"sourcesContent":["import { mande, MandeInstance } from 'mande'\nimport type { Config } from './types'\n\n/**\n * BaseApi class provides basic functionality for making API requests.\n */\nexport abstract class BaseApi {\n private apiKey?: string\n private environment: string\n private base_api: MandeInstance\n\n /**\n * @param {Config} config - Configuration object.\n * @param {string} [config.apiKey] - API key.\n * @param {Environment} [config.environment='prod'] - Environment for the API (e.g. 'dev', 'prod').\n */\n constructor(config: Config) {\n this.apiKey = config.apiKey\n this.environment = config.environment || 'prod'\n this.base_api = mande(`${this.getBaseUrl()}`, {\n headers: this.getHeaders(),\n })\n }\n\n /**\n * Makes a GET request to the given endpoint.\n *\n * @param {string} endpoint - Endpoint for the request.\n * @returns {Promise<T>} - Promise that resolves with the response data.\n * @template T - Type of the response data.\n */\n protected get<T>(endpoint: string): Promise<T> {\n return this.base_api.get<T>(endpoint)\n }\n\n /**\n * Makes a POST request to the given endpoint with the given data.\n *\n * @param {string} endpoint - Endpoint for the request.\n * @param {I} data - Data to be sent in the request.\n * @returns {Promise<T>} - Promise that resolves with the response data.\n * @template I - Type of the request data.\n * @template T - Type of the response data.\n */\n protected post<I, T>(endpoint: string, data: I): Promise<T> {\n return this.base_api.post<T>(endpoint, data)\n }\n\n /**\n * Returns the base URL for the API based on the environment.\n *\n * @returns {string} - Base URL for the API.\n * @private\n */\n private getBaseUrl(): string {\n switch (this.environment) {\n case 'prod': {\n return `https://api.narrative.io/`\n }\n case 'dev': {\n return `https://api-dev.narrative.io/`\n }\n default: {\n return this.environment\n }\n }\n }\n\n /**\n * Returns the headers for the API request.\n *\n * @returns {Object.<string, string>} - Headers for the API request.\n * @private\n */\n private getHeaders(): { [key: string]: string } {\n const headers: { [key: string]: string } = {\n 'Content-type': 'application/json'\n }\n\n if (this.apiKey) {\n headers['Authorization'] = `Bearer ${this.apiKey}`\n }\n\n return headers\n }\n}","import { ApiRecords } from \"src/types\";\nimport { BaseApi } from \"../base-api\";\nimport { Dataset } from \"./types\";\n\nconst resourceName = 'datasets';\n\n/**\n * @module DatasetApi\n * @description This module provides methods for fetching datasets.\n * @extends BaseApi\n */\nexport class DatasetApi extends BaseApi {\n \n /**\n * Get a single dataset by its ID\n * @param {number} dataset_id - The ID of the dataset\n * @returns {Promise<Dataset>} - Promise resolving to the requested dataset\n */\n public async getDataset(dataset_id: number): Promise<Dataset> {\n return this.get<Dataset>(`${resourceName}/${dataset_id}`);\n }\n\n /**\n * Get a list of all datasets\n * @returns {Promise<ApiRecords<Dataset>>} - Promise resolving to an array of datasets\n */\n public async getDatasets(): Promise<ApiRecords<Dataset>> {\n return this.get<ApiRecords<Dataset>>(`${resourceName}`);\n }\n}","import { BaseApi } from './base-api';\nimport { HealthCheckApi } from './health'\nimport { DatasetApi } from './datasets'\nimport { RosettaStoneApi } from './rosetta-stone'\nimport { applyMixins } from './utils'\n\nclass NarrativeApi extends BaseApi { }\ninterface NarrativeApi extends BaseApi, HealthCheckApi, DatasetApi, RosettaStoneApi { }\napplyMixins(NarrativeApi, [HealthCheckApi, DatasetApi, RosettaStoneApi]);\n\nexport default NarrativeApi","export function applyMixins(derivedCtor: any, constructors: any[]) {\n constructors.forEach((baseCtor) => {\n Object.getOwnPropertyNames(baseCtor.prototype).forEach((name) => {\n Object.defineProperty(\n derivedCtor.prototype,\n name,\n Object.getOwnPropertyDescriptor(baseCtor.prototype, name) ||\n Object.create(null)\n );\n });\n });\n}","import { BaseApi } from \"../base-api\";\nimport type { HealthCheckResult } from \"./types\";\n\nconst resourceName = 'health';\n\nexport class HealthCheckApi extends BaseApi {\n public async getHealthCheck(): Promise<HealthCheckResult> {\n return await this.get<HealthCheckResult>(resourceName);\n }\n}","import { BaseApi } from \"../base-api\";\nimport { RosettaStoneResponse, SampleRecords } from \"./types\";\n\nconst resourceName = 'rosetta-stone';\n\nexport class RosettaStoneApi extends BaseApi {\n public async getLabelsFromSample(sample: SampleRecords): Promise<RosettaStoneResponse[]> {\n return this.post<SampleRecords, RosettaStoneResponse[]>(`${resourceName}/labels/sample`, sample);\n }\n}"],"names":["BaseApi","constructor","config","this","apiKey","environment","base_api","mande","getBaseUrl","headers","getHeaders","get","endpoint","post","data","resourceName","NarrativeApi","applyMixins","derivedCtor","async","dataset_id","sample","forEach","baseCtor","Object","getOwnPropertyNames","prototype","name","defineProperty","getOwnPropertyDescriptor","create"],"mappings":"oCAM6BA,EAUzBC,YAAYC,GAAcC,KATlBC,YAAM,EAAAD,KACNE,iBACAC,EAAAA,KAAAA,cAQJ,EAAAH,KAAKC,OAASF,EAAOE,OACrBD,KAAKE,YAAcH,EAAOG,aAAe,OACzCF,KAAKG,SAAWC,EAAS,GAAAJ,KAAKK,eAAgB,CAC1CC,QAASN,KAAKO,cAEtB,CASUC,IAAOC,GACb,OAAWT,KAACG,SAASK,IAAOC,EAChC,CAWUC,KAAWD,EAAkBE,GACnC,OAAWX,KAACG,SAASO,KAAQD,EAAUE,EAC3C,CAQQN,aACJ,OAAQL,KAAKE,aACT,IAAK,OACD,kCAEJ,IAAK,MACD,sCAEJ,QACI,OAAOF,KAAKE,YAGxB,CAQQK,aACJ,MAAMD,EAAqC,CACvC,eAAgB,oBAOpB,OAJIN,KAAKC,SACLK,EAAuB,wBAAcN,KAAKC,WAIlD,EChFJ,MAAkBW,EAAG,WCErB,MAAmBC,aCNHC,IAAYC,IDQhBF,EAAc,CEHpB,cAAqChB,EAChCmB,uBACH,aAAiBhB,KAACQ,IAJL,SAKjB,mBHUOQ,iBAAiBC,GACpB,OAAOjB,KAAKQ,IAAa,GAAGI,KAAgBK,IAChD,CAMOD,oBACH,YAAYR,OAA4BI,IAC5C,GIvBE,gBACKI,0BAA0BE,GAC7B,YAAYR,KAA4C,8BAAiCQ,EAC7F,IFPaC,QAASC,IAClBC,OAAOC,oBAAoBF,EAASG,WAAWJ,QAASK,IACpDH,OAAOI,eACHV,EAAYQ,UACZC,EACAH,OAAOK,yBAAyBN,EAASG,UAAWC,IACpDH,OAAOM,OAAO,MAEtB,EACJ"}
package/dist/index.umd.js DELETED
@@ -1,2 +0,0 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("mande")):"function"==typeof define&&define.amd?define(["mande"],e):(t||self).dataCollaborationSdkTs=e(t.mande)}(this,function(t){function e(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,r(t,e)}function r(t,e){return r=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},r(t,e)}var n,o=/*#__PURE__*/function(){function e(e){this.apiKey=void 0,this.environment=void 0,this.base_api=void 0,this.apiKey=e.apiKey,this.environment=e.environment||"prod",this.base_api=t.mande(""+this.getBaseUrl(),{headers:this.getHeaders()})}var r=e.prototype;return r.get=function(t){return this.base_api.get(t)},r.post=function(t,e){return this.base_api.post(t,e)},r.getBaseUrl=function(){switch(this.environment){case"prod":return"https://api.narrative.io/";case"dev":return"https://api-dev.narrative.io/";default:return this.environment}},r.getHeaders=function(){var t={"Content-type":"application/json"};return this.apiKey&&(t.Authorization="Bearer "+this.apiKey),t},e}(),i=/*#__PURE__*/function(t){function r(){return t.apply(this,arguments)||this}return e(r,t),r.prototype.getHealthCheck=function(){try{return Promise.resolve(this.get("health"))}catch(t){return Promise.reject(t)}},r}(o),s="datasets",a=/*#__PURE__*/function(t){function r(){return t.apply(this,arguments)||this}e(r,t);var n=r.prototype;return n.getDataset=function(t){try{return Promise.resolve(this.get(s+"/"+t))}catch(t){return Promise.reject(t)}},n.getDatasets=function(){try{return Promise.resolve(this.get(""+s))}catch(t){return Promise.reject(t)}},r}(o),p=/*#__PURE__*/function(t){function r(){return t.apply(this,arguments)||this}return e(r,t),r.prototype.getLabelsFromSample=function(t){try{return Promise.resolve(this.post("rosetta-stone/labels/sample",t))}catch(t){return Promise.reject(t)}},r}(o),u=/*#__PURE__*/function(t){function r(){return t.apply(this,arguments)||this}return e(r,t),r}(o);return n=u,[i,a,p].forEach(function(t){Object.getOwnPropertyNames(t.prototype).forEach(function(e){Object.defineProperty(n.prototype,e,Object.getOwnPropertyDescriptor(t.prototype,e)||Object.create(null))})}),u});
2
- //# sourceMappingURL=index.umd.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.umd.js","sources":["../src/base-api.ts","../src/utils.ts","../src/health/index.ts","../src/datasets/index.ts","../src/rosetta-stone/index.ts","../src/index.ts"],"sourcesContent":["import { mande, MandeInstance } from 'mande'\nimport type { Config } from './types'\n\n/**\n * BaseApi class provides basic functionality for making API requests.\n */\nexport abstract class BaseApi {\n private apiKey?: string\n private environment: string\n private base_api: MandeInstance\n\n /**\n * @param {Config} config - Configuration object.\n * @param {string} [config.apiKey] - API key.\n * @param {Environment} [config.environment='prod'] - Environment for the API (e.g. 'dev', 'prod').\n */\n constructor(config: Config) {\n this.apiKey = config.apiKey\n this.environment = config.environment || 'prod'\n this.base_api = mande(`${this.getBaseUrl()}`, {\n headers: this.getHeaders(),\n })\n }\n\n /**\n * Makes a GET request to the given endpoint.\n *\n * @param {string} endpoint - Endpoint for the request.\n * @returns {Promise<T>} - Promise that resolves with the response data.\n * @template T - Type of the response data.\n */\n protected get<T>(endpoint: string): Promise<T> {\n return this.base_api.get<T>(endpoint)\n }\n\n /**\n * Makes a POST request to the given endpoint with the given data.\n *\n * @param {string} endpoint - Endpoint for the request.\n * @param {I} data - Data to be sent in the request.\n * @returns {Promise<T>} - Promise that resolves with the response data.\n * @template I - Type of the request data.\n * @template T - Type of the response data.\n */\n protected post<I, T>(endpoint: string, data: I): Promise<T> {\n return this.base_api.post<T>(endpoint, data)\n }\n\n /**\n * Returns the base URL for the API based on the environment.\n *\n * @returns {string} - Base URL for the API.\n * @private\n */\n private getBaseUrl(): string {\n switch (this.environment) {\n case 'prod': {\n return `https://api.narrative.io/`\n }\n case 'dev': {\n return `https://api-dev.narrative.io/`\n }\n default: {\n return this.environment\n }\n }\n }\n\n /**\n * Returns the headers for the API request.\n *\n * @returns {Object.<string, string>} - Headers for the API request.\n * @private\n */\n private getHeaders(): { [key: string]: string } {\n const headers: { [key: string]: string } = {\n 'Content-type': 'application/json'\n }\n\n if (this.apiKey) {\n headers['Authorization'] = `Bearer ${this.apiKey}`\n }\n\n return headers\n }\n}","export function applyMixins(derivedCtor: any, constructors: any[]) {\n constructors.forEach((baseCtor) => {\n Object.getOwnPropertyNames(baseCtor.prototype).forEach((name) => {\n Object.defineProperty(\n derivedCtor.prototype,\n name,\n Object.getOwnPropertyDescriptor(baseCtor.prototype, name) ||\n Object.create(null)\n );\n });\n });\n}","import { BaseApi } from \"../base-api\";\nimport type { HealthCheckResult } from \"./types\";\n\nconst resourceName = 'health';\n\nexport class HealthCheckApi extends BaseApi {\n public async getHealthCheck(): Promise<HealthCheckResult> {\n return await this.get<HealthCheckResult>(resourceName);\n }\n}","import { ApiRecords } from \"src/types\";\nimport { BaseApi } from \"../base-api\";\nimport { Dataset } from \"./types\";\n\nconst resourceName = 'datasets';\n\n/**\n * @module DatasetApi\n * @description This module provides methods for fetching datasets.\n * @extends BaseApi\n */\nexport class DatasetApi extends BaseApi {\n \n /**\n * Get a single dataset by its ID\n * @param {number} dataset_id - The ID of the dataset\n * @returns {Promise<Dataset>} - Promise resolving to the requested dataset\n */\n public async getDataset(dataset_id: number): Promise<Dataset> {\n return this.get<Dataset>(`${resourceName}/${dataset_id}`);\n }\n\n /**\n * Get a list of all datasets\n * @returns {Promise<ApiRecords<Dataset>>} - Promise resolving to an array of datasets\n */\n public async getDatasets(): Promise<ApiRecords<Dataset>> {\n return this.get<ApiRecords<Dataset>>(`${resourceName}`);\n }\n}","import { BaseApi } from \"../base-api\";\nimport { RosettaStoneResponse, SampleRecords } from \"./types\";\n\nconst resourceName = 'rosetta-stone';\n\nexport class RosettaStoneApi extends BaseApi {\n public async getLabelsFromSample(sample: SampleRecords): Promise<RosettaStoneResponse[]> {\n return this.post<SampleRecords, RosettaStoneResponse[]>(`${resourceName}/labels/sample`, sample);\n }\n}","import { BaseApi } from './base-api';\nimport { HealthCheckApi } from './health'\nimport { DatasetApi } from './datasets'\nimport { RosettaStoneApi } from './rosetta-stone'\nimport { applyMixins } from './utils'\n\nclass NarrativeApi extends BaseApi { }\ninterface NarrativeApi extends BaseApi, HealthCheckApi, DatasetApi, RosettaStoneApi { }\napplyMixins(NarrativeApi, [HealthCheckApi, DatasetApi, RosettaStoneApi]);\n\nexport default NarrativeApi"],"names":["derivedCtor","BaseApi","config","apiKey","this","environment","base_api","mande","getBaseUrl","headers","getHeaders","get","endpoint","post","data","_proto","HealthCheckApi","_BaseApi","apply","arguments","_inheritsLoose","prototype","getHealthCheck","Promise","resolve","e","reject","resourceName","getDataset","dataset_id","getDatasets","RosettaStoneApi","getLabelsFromSample","sample","NarrativeApi","DatasetApi","forEach","baseCtor","Object","getOwnPropertyNames","name","defineProperty","getOwnPropertyDescriptor","create"],"mappings":"4dAMA,ICN4BA,iBDgBxB,WAAA,SAAAC,EAAYC,QATJC,YAAM,EAAAC,KACNC,iBAAW,EAAAD,KACXE,cAQJ,EAAAF,KAAKD,OAASD,EAAOC,OACrBC,KAAKC,YAAcH,EAAOG,aAAe,OACzCD,KAAKE,SAAWC,EAAKA,SAAIH,KAAKI,aAAgB,CAC1CC,QAASL,KAAKM,cAEtB,CAAC,IASSC,EAAAA,EAAAA,UAqDT,OArDSA,EAAAA,IAAA,SAAOC,GACb,OAAOR,KAAKE,SAASK,IAAOC,EAChC,EAWUC,EAAAA,KAAA,SAAWD,EAAkBE,GACnC,OAAWV,KAACE,SAASO,KAAQD,EAAUE,EAC3C,EAACC,EAQOP,WAAA,WACJ,OAAQJ,KAAKC,aACT,IAAK,OACD,MACH,4BACD,IAAK,MACD,MAAA,gCAEJ,QACI,OAAOD,KAAKC,YAGxB,IAQQK,WAAA,WACJ,IAAaD,EAA8B,CACvC,eAAgB,oBAOpB,OAJIL,KAAKD,SACLM,EAAuB,cAAC,UAAaL,KAAKD,SAIlD,EAACF,CAAA,CApED,GEXwBe,eAAA,SAAAC,GAAA,SAAAD,IAAA,OAAAC,EAAAC,MAAAd,KAAAe,YAAAf,IAAA,CAGvB,OAHuBgB,EAAAJ,EAAAC,GAAAD,EAAAK,UACXC,eAAc,WAAA,IACN,OAAAC,QAAAC,QAAJpB,KAAKO,IAJL,UAKhB,CAAA,MAAAc,GAAA,OAAAF,QAAAG,OAAAD,EAAA,CAAA,EAAAT,CAAA,CAHuB,CAAQf,GCDlB0B,EAAG,0BAcJC,SAAAA,GAAAA,SAAAA,IAAAA,OAAAA,EAAAA,MAAAA,KAAAA,YAAAA,IAAAA,CAAAA,EAAAA,EAAAA,GAAAA,IAAAA,EAAAA,EAAAA,iBAAAA,EAAAA,oBAAWC,GAAkB,IACtC,uBAAOzB,KAAKO,IAAgBgB,EAAY,IAAIE,GAOnCC,CANZ,MAMYA,GAAAA,OAAAA,QAAAA,OAAAA,EAAAA,CAAAA,EAAAA,EAAAA,2BACT,OAAOP,QAAAC,QAAApB,KAAKO,IAA4BgB,GAAAA,IAC3C,sCAVYC,CAPe3B,GCNH8B,eAAA,SAAAd,GAAA,SAAAc,IAAA,OAAAd,EAAAC,MAAAd,KAAAe,YAAAf,IAAA,QAAAgB,EAAAW,EAAAd,GAAAc,EAAAV,UACZW,oBAAoBC,SAAAA,GAAqB,IAClD,OAAOV,QAAAC,QAAApB,KAAKS,KAA+Cc,8BAA8BM,IAC5F,sCAHwB,CAAQhC,GCClBiC,eAAA,SAAAjB,GAAA,SAAAiB,IAAA,OAAAjB,EAAAC,MAAAd,KAAAe,YAAAf,IAAA,CAAA,OAAAgB,EAAAc,EAAAjB,GAAAiB,CAAA,CAAA,CAAQjC,UJNCD,EIQhBkC,EAAc,CAAClB,EAAgBmB,EAAYJ,GJPtCK,QAAQ,SAACC,GAClBC,OAAOC,oBAAoBF,EAAShB,WAAWe,QAAQ,SAACI,GACpDF,OAAOG,eACHzC,EAAYqB,UACZmB,EACAF,OAAOI,yBAAyBL,EAAShB,UAAWmB,IACpDF,OAAOK,OAAO,MAEtB,EACJ"}