@narrative.io/data-collaboration-sdk-ts 0.0.100 → 0.0.101
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
CHANGED
|
@@ -4,11 +4,11 @@ import { type Config } from './types';
|
|
|
4
4
|
* BaseApi class provides basic functionality for making API requests.
|
|
5
5
|
*/
|
|
6
6
|
export declare abstract class BaseApi {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
protected readonly apiKey?: string;
|
|
8
|
+
protected readonly environment: string;
|
|
9
|
+
protected readonly base_api: MandeInstance;
|
|
10
|
+
protected readonly headers: Record<string, string>;
|
|
11
|
+
protected readonly verbose: boolean;
|
|
12
12
|
/**
|
|
13
13
|
* @param {Config} config - Configuration object.
|
|
14
14
|
* @param {string} [config.apiKey] - API key.
|
|
@@ -6,7 +6,7 @@ import { type CompanyInfo, type WhoAmI } from './types';
|
|
|
6
6
|
* @extends BaseApi
|
|
7
7
|
*/
|
|
8
8
|
declare class CompanyInfoApi extends BaseApi {
|
|
9
|
-
companyId
|
|
9
|
+
companyId(): Promise<number>;
|
|
10
10
|
/**
|
|
11
11
|
* Get the logged in company id
|
|
12
12
|
* @returns {Promise<WhoAmI>}
|
|
@@ -11,9 +11,9 @@ const resourceName = 'company-info';
|
|
|
11
11
|
* @extends BaseApi
|
|
12
12
|
*/
|
|
13
13
|
class CompanyInfoApi extends BaseApi {
|
|
14
|
-
|
|
14
|
+
async companyId() {
|
|
15
15
|
return (await this.get(`${resourceName}/whoami`)).id;
|
|
16
|
-
}
|
|
16
|
+
}
|
|
17
17
|
/**
|
|
18
18
|
* Get the logged in company id
|
|
19
19
|
* @returns {Promise<WhoAmI>}
|
|
@@ -1,21 +1,37 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Config, ApiRecords } from 'src/types';
|
|
2
2
|
import { BaseApi } from '../base-api';
|
|
3
3
|
import type { CreateMapping, Mapping } from './types';
|
|
4
|
+
import { CompanyInfoApi } from '../company-info';
|
|
4
5
|
/**
|
|
5
6
|
* A class for accessing the Mappings API.
|
|
6
7
|
* @extends BaseApi
|
|
7
8
|
*/
|
|
8
9
|
declare class MappingsApi extends BaseApi {
|
|
10
|
+
private readonly companyInfoApi?;
|
|
11
|
+
constructor(config: Config, companyInfoApi?: CompanyInfoApi | undefined);
|
|
9
12
|
/**
|
|
10
13
|
* Fetches all mappings.
|
|
11
14
|
* @return {Promise<ApiRecords<Mapping>>} Promise object represents the API records of mappings.
|
|
12
15
|
*/
|
|
13
16
|
getMappings(): Promise<ApiRecords<Mapping>>;
|
|
14
17
|
/**
|
|
15
|
-
* Creates a
|
|
18
|
+
* Creates a private (specific to a company) mapping between a dataset and an attribute.
|
|
19
|
+
*
|
|
16
20
|
* @param {CreateMapping} mapping - The mapping to be created.
|
|
17
|
-
* @
|
|
21
|
+
* @param {number} [companyId] - The ID of the company. If not provided, will be fetched from the API.
|
|
22
|
+
* @returns {Promise<Mapping>} - A promise that resolves to the created mapping.
|
|
23
|
+
* @public
|
|
24
|
+
* @throws {Error} - If the company ID is undefined and cannot be fetched from the API.
|
|
25
|
+
* @async
|
|
18
26
|
*/
|
|
19
|
-
|
|
27
|
+
createPrivateMapping(mapping: CreateMapping, companyId?: number): Promise<Mapping>;
|
|
28
|
+
/**
|
|
29
|
+
* Retrieves the company ID from the API.
|
|
30
|
+
*
|
|
31
|
+
* @returns {Promise<number | undefined>} - A promise that resolves to the company ID.
|
|
32
|
+
* @private
|
|
33
|
+
* @async
|
|
34
|
+
*/
|
|
35
|
+
private getCompanyId;
|
|
20
36
|
}
|
|
21
37
|
export { type Mapping, MappingsApi, type CreateMapping };
|
package/build/mappings/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BaseApi } from '../base-api';
|
|
2
|
+
import { CompanyInfoApi } from '../company-info';
|
|
2
3
|
/**
|
|
3
4
|
* The name of the resource to be used in API requests.
|
|
4
5
|
* @constant
|
|
@@ -11,6 +12,19 @@ const resourceName = 'mappings';
|
|
|
11
12
|
* @extends BaseApi
|
|
12
13
|
*/
|
|
13
14
|
class MappingsApi extends BaseApi {
|
|
15
|
+
companyInfoApi;
|
|
16
|
+
constructor(config, companyInfoApi) {
|
|
17
|
+
super(config);
|
|
18
|
+
this.companyInfoApi = companyInfoApi;
|
|
19
|
+
if (companyInfoApi === undefined) {
|
|
20
|
+
this.companyInfoApi = new CompanyInfoApi({
|
|
21
|
+
apiKey: this.apiKey,
|
|
22
|
+
environment: this.environment,
|
|
23
|
+
verbose: this.verbose,
|
|
24
|
+
headers: this.headers
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
14
28
|
/**
|
|
15
29
|
* Fetches all mappings.
|
|
16
30
|
* @return {Promise<ApiRecords<Mapping>>} Promise object represents the API records of mappings.
|
|
@@ -19,12 +33,31 @@ class MappingsApi extends BaseApi {
|
|
|
19
33
|
return await this.get(resourceName);
|
|
20
34
|
}
|
|
21
35
|
/**
|
|
22
|
-
* Creates a
|
|
36
|
+
* Creates a private (specific to a company) mapping between a dataset and an attribute.
|
|
37
|
+
*
|
|
23
38
|
* @param {CreateMapping} mapping - The mapping to be created.
|
|
24
|
-
* @
|
|
39
|
+
* @param {number} [companyId] - The ID of the company. If not provided, will be fetched from the API.
|
|
40
|
+
* @returns {Promise<Mapping>} - A promise that resolves to the created mapping.
|
|
41
|
+
* @public
|
|
42
|
+
* @throws {Error} - If the company ID is undefined and cannot be fetched from the API.
|
|
43
|
+
* @async
|
|
25
44
|
*/
|
|
26
|
-
async
|
|
27
|
-
|
|
45
|
+
async createPrivateMapping(mapping, companyId) {
|
|
46
|
+
companyId = companyId ?? await this.getCompanyId();
|
|
47
|
+
if (companyId === undefined)
|
|
48
|
+
throw new Error('Company ID is undefined');
|
|
49
|
+
const resource = `${resourceName}/companies/${companyId}`;
|
|
50
|
+
return await this.post(resource, mapping);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Retrieves the company ID from the API.
|
|
54
|
+
*
|
|
55
|
+
* @returns {Promise<number | undefined>} - A promise that resolves to the company ID.
|
|
56
|
+
* @private
|
|
57
|
+
* @async
|
|
58
|
+
*/
|
|
59
|
+
async getCompanyId() {
|
|
60
|
+
return await this.companyInfoApi?.companyId();
|
|
28
61
|
}
|
|
29
62
|
}
|
|
30
63
|
export { MappingsApi };
|