@narrative.io/data-collaboration-sdk-ts 0.0.33 → 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/attributes/types.d.ts +6 -7
- package/build/base-api.d.ts +1 -0
- package/build/base-api.js +20 -1
- package/build/datasets/types.d.ts +2 -0
- package/build/index.d.ts +3 -2
- package/build/index.js +3 -2
- package/build/resources/index.d.ts +38 -0
- package/build/resources/index.js +42 -0
- package/build/resources/types.d.ts +31 -0
- package/build/resources/types.js +1 -0
- 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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type Attribute = PrimitiveAttribute | ArrayAttribute | ObjectAttribute;
|
|
2
|
-
interface BaseAttribute {
|
|
2
|
+
export interface BaseAttribute {
|
|
3
3
|
id: number;
|
|
4
4
|
name: string;
|
|
5
5
|
display_name?: string;
|
|
@@ -7,26 +7,25 @@ interface BaseAttribute {
|
|
|
7
7
|
type: string;
|
|
8
8
|
validations?: string[];
|
|
9
9
|
}
|
|
10
|
-
interface PrimitiveAttribute extends BaseAttribute {
|
|
10
|
+
export interface PrimitiveAttribute extends BaseAttribute {
|
|
11
11
|
type: 'string' | 'boolean' | 'double' | 'long' | 'timestamptz';
|
|
12
12
|
enum?: string[] | number[] | boolean[];
|
|
13
13
|
is_join_key?: boolean;
|
|
14
14
|
}
|
|
15
|
-
type SubAttribute = Partial<Omit<Attribute, 'name' | 'id'>> & {
|
|
15
|
+
export type SubAttribute = Partial<Omit<Attribute, 'name' | 'id'>> & {
|
|
16
16
|
type: string;
|
|
17
17
|
enum?: string[] | number[] | boolean[];
|
|
18
18
|
is_join_key?: boolean;
|
|
19
19
|
};
|
|
20
|
-
interface RefAttribute {
|
|
20
|
+
export interface RefAttribute {
|
|
21
21
|
$ref: number;
|
|
22
22
|
}
|
|
23
|
-
interface ArrayAttribute extends BaseAttribute {
|
|
23
|
+
export interface ArrayAttribute extends BaseAttribute {
|
|
24
24
|
type: 'array';
|
|
25
25
|
items: SubAttribute;
|
|
26
26
|
}
|
|
27
|
-
interface ObjectAttribute extends BaseAttribute {
|
|
27
|
+
export interface ObjectAttribute extends BaseAttribute {
|
|
28
28
|
type: 'object';
|
|
29
29
|
properties: Record<string, SubAttribute | RefAttribute>;
|
|
30
30
|
required?: string[];
|
|
31
31
|
}
|
|
32
|
-
export {};
|
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/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { type DatasetTableSummaryAPIResponse, type Dataset, type DatasetTableSum
|
|
|
7
7
|
import { type HealthCheckResult } from './health/types';
|
|
8
8
|
import { type SampleRecords } from './rosetta-stone/types';
|
|
9
9
|
import { AttributeApi } from './attributes';
|
|
10
|
+
import { type Resource, ResourceApi, type BucketCreationRequest, type UpdateAccessTypeRequest } from './resources';
|
|
10
11
|
import { type Attribute } from './attributes/types';
|
|
11
12
|
import { PingApi } from './ping';
|
|
12
13
|
import { UploadsApi } from './uploads';
|
|
@@ -17,6 +18,6 @@ import { CompanyInfoApi, type CompanyInfo } from './company-info';
|
|
|
17
18
|
import { InstallationsApi, type Installation } from './installations';
|
|
18
19
|
declare class NarrativeApi extends BaseApi {
|
|
19
20
|
}
|
|
20
|
-
interface NarrativeApi extends BaseApi, HealthCheckApi, DatasetApi, RosettaStoneApi, AttributeApi, PingApi, CompanyInfoApi, InstallationsApi, UploadsApi {
|
|
21
|
+
interface NarrativeApi extends BaseApi, HealthCheckApi, DatasetApi, RosettaStoneApi, AttributeApi, PingApi, CompanyInfoApi, InstallationsApi, UploadsApi, ResourceApi {
|
|
21
22
|
}
|
|
22
|
-
export { NarrativeApi, AttributeApi, HealthCheckApi, DatasetApi, PingApi, ProductsApi, CompanyInfoApi, InstallationsApi, UploadsApi, type UploadsResponse, type PingStatus, type Attribute, type Environment, type Config, type ApiRecords, type Dataset, type HealthCheckResult, type SampleRecords, type DatasetTableSummary, type DatasetTableSummaryAPIResponse, type Product, type MonetaryAmount, type CompanyInfo, type Installation, type FilePerSnapshotResponse };
|
|
23
|
+
export { NarrativeApi, AttributeApi, HealthCheckApi, DatasetApi, PingApi, ProductsApi, CompanyInfoApi, InstallationsApi, UploadsApi, ResourceApi, type Resource, type UploadsResponse, type PingStatus, type Attribute, type Environment, type Config, type ApiRecords, type Dataset, type HealthCheckResult, type SampleRecords, type DatasetTableSummary, type DatasetTableSummaryAPIResponse, type Product, type MonetaryAmount, type CompanyInfo, type Installation, type FilePerSnapshotResponse, type BucketCreationRequest, type UpdateAccessTypeRequest };
|
package/build/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import { HealthCheckApi } from './health';
|
|
|
4
4
|
import { RosettaStoneApi } from './rosetta-stone';
|
|
5
5
|
import { applyMixins } from './utils';
|
|
6
6
|
import { AttributeApi } from './attributes';
|
|
7
|
+
import { ResourceApi } from './resources';
|
|
7
8
|
import { PingApi } from './ping';
|
|
8
9
|
import { UploadsApi } from './uploads';
|
|
9
10
|
import { ProductsApi } from './products';
|
|
@@ -11,5 +12,5 @@ import { CompanyInfoApi } from './company-info';
|
|
|
11
12
|
import { InstallationsApi } from './installations';
|
|
12
13
|
class NarrativeApi extends BaseApi {
|
|
13
14
|
}
|
|
14
|
-
applyMixins(NarrativeApi, [BaseApi, HealthCheckApi, DatasetApi, RosettaStoneApi, AttributeApi, PingApi, CompanyInfoApi, InstallationsApi, UploadsApi]);
|
|
15
|
-
export { NarrativeApi, AttributeApi, HealthCheckApi, DatasetApi, PingApi, ProductsApi, CompanyInfoApi, InstallationsApi, UploadsApi };
|
|
15
|
+
applyMixins(NarrativeApi, [BaseApi, HealthCheckApi, DatasetApi, RosettaStoneApi, AttributeApi, PingApi, CompanyInfoApi, InstallationsApi, UploadsApi, ResourceApi]);
|
|
16
|
+
export { NarrativeApi, AttributeApi, HealthCheckApi, DatasetApi, PingApi, ProductsApi, CompanyInfoApi, InstallationsApi, UploadsApi, ResourceApi };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview This module provides methods for fetching resources.
|
|
3
|
+
* @author Your Name
|
|
4
|
+
*/
|
|
5
|
+
import { type ApiRecords } from '../types';
|
|
6
|
+
import { BaseApi } from '../base-api';
|
|
7
|
+
import { type Resource, type BucketCreationRequest, type UpdateAccessTypeRequest } from './types';
|
|
8
|
+
export { type Resource, type BucketCreationRequest, type UpdateAccessTypeRequest };
|
|
9
|
+
/**
|
|
10
|
+
* @class ResourceApi
|
|
11
|
+
* @extends {BaseApi}
|
|
12
|
+
* @description This class provides methods for fetching resources.
|
|
13
|
+
*/
|
|
14
|
+
export declare class ResourceApi extends BaseApi {
|
|
15
|
+
/**
|
|
16
|
+
* @function getBuckets
|
|
17
|
+
* @memberof ResourceApi
|
|
18
|
+
* @description Fetches a list of buckets for a given datasetId.
|
|
19
|
+
* @returns {Promise<ApiRecords<Resource>>} A promise that resolves to the list of resources.
|
|
20
|
+
*/
|
|
21
|
+
getBuckets(): Promise<ApiRecords<Resource>>;
|
|
22
|
+
/**
|
|
23
|
+
* @function createBucket
|
|
24
|
+
* @memberof ResourceApi
|
|
25
|
+
* @description Creates a new bucket.
|
|
26
|
+
* @param {BucketCreationRequest} request - The bucket creation request object.
|
|
27
|
+
* @returns {Promise<Resource>} A promise that resolves to the created resource.
|
|
28
|
+
*/
|
|
29
|
+
createBucket(request: BucketCreationRequest): Promise<Resource>;
|
|
30
|
+
/**
|
|
31
|
+
* @function updateAccessType
|
|
32
|
+
* @memberof ResourceApi
|
|
33
|
+
* @description Updates the access type of a resource.
|
|
34
|
+
* @param {UpdateAccessTypeRequest} request - The update access type request object.
|
|
35
|
+
* @returns {Promise<Resource>} A promise that resolves to the updated resource.
|
|
36
|
+
*/
|
|
37
|
+
updateAccessType(request: UpdateAccessTypeRequest): Promise<Resource>;
|
|
38
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview This module provides methods for fetching resources.
|
|
3
|
+
* @author Your Name
|
|
4
|
+
*/
|
|
5
|
+
import { BaseApi } from '../base-api';
|
|
6
|
+
const resourceName = 'resources';
|
|
7
|
+
/**
|
|
8
|
+
* @class ResourceApi
|
|
9
|
+
* @extends {BaseApi}
|
|
10
|
+
* @description This class provides methods for fetching resources.
|
|
11
|
+
*/
|
|
12
|
+
export class ResourceApi extends BaseApi {
|
|
13
|
+
/**
|
|
14
|
+
* @function getBuckets
|
|
15
|
+
* @memberof ResourceApi
|
|
16
|
+
* @description Fetches a list of buckets for a given datasetId.
|
|
17
|
+
* @returns {Promise<ApiRecords<Resource>>} A promise that resolves to the list of resources.
|
|
18
|
+
*/
|
|
19
|
+
async getBuckets() {
|
|
20
|
+
return await this.get(`${resourceName}/buckets`);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* @function createBucket
|
|
24
|
+
* @memberof ResourceApi
|
|
25
|
+
* @description Creates a new bucket.
|
|
26
|
+
* @param {BucketCreationRequest} request - The bucket creation request object.
|
|
27
|
+
* @returns {Promise<Resource>} A promise that resolves to the created resource.
|
|
28
|
+
*/
|
|
29
|
+
async createBucket(request) {
|
|
30
|
+
return await this.post(`${resourceName}/buckets`, request);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* @function updateAccessType
|
|
34
|
+
* @memberof ResourceApi
|
|
35
|
+
* @description Updates the access type of a resource.
|
|
36
|
+
* @param {UpdateAccessTypeRequest} request - The update access type request object.
|
|
37
|
+
* @returns {Promise<Resource>} A promise that resolves to the updated resource.
|
|
38
|
+
*/
|
|
39
|
+
async updateAccessType(request) {
|
|
40
|
+
return await this.post(`${resourceName}/buckets/access`, request);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface Resource {
|
|
2
|
+
id: string;
|
|
3
|
+
company_id: number;
|
|
4
|
+
auth: {
|
|
5
|
+
type: 'bucket_policy' | 'role';
|
|
6
|
+
account_id: string;
|
|
7
|
+
external_id?: string;
|
|
8
|
+
role?: string;
|
|
9
|
+
};
|
|
10
|
+
name: string;
|
|
11
|
+
created_at: string;
|
|
12
|
+
updated_at: string;
|
|
13
|
+
is_access_mutable: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface RoleBasedBucketAccess {
|
|
16
|
+
type: 'role';
|
|
17
|
+
external_id: string;
|
|
18
|
+
}
|
|
19
|
+
export interface PolicyBasedBucketAccess {
|
|
20
|
+
type: 'bucket_policy';
|
|
21
|
+
}
|
|
22
|
+
export interface UpdateAccessTypeRequest {
|
|
23
|
+
bucket_name: string;
|
|
24
|
+
new_access: BucketAccess;
|
|
25
|
+
}
|
|
26
|
+
export type BucketAccess = RoleBasedBucketAccess | PolicyBasedBucketAccess;
|
|
27
|
+
export interface BucketCreationRequest {
|
|
28
|
+
account_id: string;
|
|
29
|
+
resource_id: string;
|
|
30
|
+
access: BucketAccess;
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
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
|
+
}
|