@narrative.io/data-collaboration-sdk-ts 0.0.30 → 0.0.32
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 +24 -11
- package/build/base-api.d.ts +28 -2
- package/build/base-api.js +39 -4
- package/build/nql/index.d.ts +19 -0
- package/build/nql/index.js +35 -0
- package/build/nql/types.d.ts +28 -0
- package/build/nql/types.js +1 -0
- package/build/types.d.ts +1 -0
- package/build/uploads/index.d.ts +1 -1
- package/build/uploads/index.js +1 -1
- package/package.json +5 -5
|
@@ -1,19 +1,32 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type Attribute = PrimitiveAttribute | ArrayAttribute | ObjectAttribute;
|
|
2
|
+
interface BaseAttribute {
|
|
2
3
|
id: number;
|
|
3
4
|
name: string;
|
|
5
|
+
display_name?: string;
|
|
4
6
|
description?: string;
|
|
5
|
-
display_name: string;
|
|
6
7
|
type: string;
|
|
7
|
-
enum?: string[] | number[];
|
|
8
8
|
validations?: string[];
|
|
9
|
+
}
|
|
10
|
+
interface PrimitiveAttribute extends BaseAttribute {
|
|
11
|
+
type: 'string' | 'boolean' | 'double' | 'long' | 'timestamptz';
|
|
12
|
+
enum?: string[] | number[] | boolean[];
|
|
13
|
+
is_join_key?: boolean;
|
|
14
|
+
}
|
|
15
|
+
type SubAttribute = Partial<Omit<Attribute, 'name' | 'id'>> & {
|
|
16
|
+
type: string;
|
|
17
|
+
enum?: string[] | number[] | boolean[];
|
|
9
18
|
is_join_key?: boolean;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
};
|
|
20
|
+
interface RefAttribute {
|
|
21
|
+
$ref: number;
|
|
22
|
+
}
|
|
23
|
+
interface ArrayAttribute extends BaseAttribute {
|
|
24
|
+
type: 'array';
|
|
25
|
+
items: SubAttribute;
|
|
26
|
+
}
|
|
27
|
+
interface ObjectAttribute extends BaseAttribute {
|
|
28
|
+
type: 'object';
|
|
29
|
+
properties: Record<string, SubAttribute | RefAttribute>;
|
|
18
30
|
required?: string[];
|
|
19
31
|
}
|
|
32
|
+
export {};
|
package/build/base-api.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type MandeInstance } from 'mande';
|
|
1
2
|
import { type Config } from './types';
|
|
2
3
|
/**
|
|
3
4
|
* BaseApi class provides basic functionality for making API requests.
|
|
@@ -6,12 +7,37 @@ export declare abstract class BaseApi {
|
|
|
6
7
|
private readonly apiKey?;
|
|
7
8
|
private readonly environment;
|
|
8
9
|
private readonly base_api;
|
|
10
|
+
private readonly headers;
|
|
9
11
|
/**
|
|
10
12
|
* @param {Config} config - Configuration object.
|
|
11
13
|
* @param {string} [config.apiKey] - API key.
|
|
12
14
|
* @param {Environment} [config.environment='prod'] - Environment for the API (e.g. 'dev', 'prod').
|
|
13
15
|
*/
|
|
14
16
|
constructor(config: Config);
|
|
17
|
+
/**
|
|
18
|
+
* Retrieves the headers associated with the API instance.
|
|
19
|
+
*
|
|
20
|
+
* @returns An object containing key-value pairs representing the headers.
|
|
21
|
+
*/
|
|
22
|
+
getHeaders(): Record<string, string>;
|
|
23
|
+
/**
|
|
24
|
+
* Retrieves the base API instance created using Mande.
|
|
25
|
+
*
|
|
26
|
+
* @returns A MandeInstance object representing the base API instance.
|
|
27
|
+
*/
|
|
28
|
+
getBaseApi(): MandeInstance;
|
|
29
|
+
/**
|
|
30
|
+
* Retrieves the API key associated with the API instance, if it exists.
|
|
31
|
+
*
|
|
32
|
+
* @returns The API key as a string if it is set, or undefined if not set.
|
|
33
|
+
*/
|
|
34
|
+
getApiKey(): string | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Retrieves the environment associated with the API instance.
|
|
37
|
+
*
|
|
38
|
+
* @returns A string representing the environment (e.g., 'dev', 'prod').
|
|
39
|
+
*/
|
|
40
|
+
getEnvironment(): string;
|
|
15
41
|
/**
|
|
16
42
|
* Makes a GET request to the given endpoint.
|
|
17
43
|
*
|
|
@@ -52,12 +78,12 @@ export declare abstract class BaseApi {
|
|
|
52
78
|
* @returns {string} - Base URL for the API.
|
|
53
79
|
* @private
|
|
54
80
|
*/
|
|
55
|
-
|
|
81
|
+
getBaseUrl(): string;
|
|
56
82
|
/**
|
|
57
83
|
* Returns the headers for the API request.
|
|
58
84
|
*
|
|
59
85
|
* @returns {Object.<string, string>} - Headers for the API request.
|
|
60
86
|
* @private
|
|
61
87
|
*/
|
|
62
|
-
private
|
|
88
|
+
private constructHeaders;
|
|
63
89
|
}
|
package/build/base-api.js
CHANGED
|
@@ -6,6 +6,7 @@ export class BaseApi {
|
|
|
6
6
|
apiKey;
|
|
7
7
|
environment;
|
|
8
8
|
base_api;
|
|
9
|
+
headers;
|
|
9
10
|
/**
|
|
10
11
|
* @param {Config} config - Configuration object.
|
|
11
12
|
* @param {string} [config.apiKey] - API key.
|
|
@@ -14,10 +15,43 @@ export class BaseApi {
|
|
|
14
15
|
constructor(config) {
|
|
15
16
|
this.apiKey = config.apiKey;
|
|
16
17
|
this.environment = config.environment ?? 'prod';
|
|
18
|
+
this.headers = config.headers ?? {};
|
|
17
19
|
this.base_api = mande(`${this.getBaseUrl()}`, {
|
|
18
|
-
headers: this.
|
|
20
|
+
headers: this.constructHeaders()
|
|
19
21
|
});
|
|
20
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Retrieves the headers associated with the API instance.
|
|
25
|
+
*
|
|
26
|
+
* @returns An object containing key-value pairs representing the headers.
|
|
27
|
+
*/
|
|
28
|
+
getHeaders() {
|
|
29
|
+
return this.constructHeaders();
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Retrieves the base API instance created using Mande.
|
|
33
|
+
*
|
|
34
|
+
* @returns A MandeInstance object representing the base API instance.
|
|
35
|
+
*/
|
|
36
|
+
getBaseApi() {
|
|
37
|
+
return this.base_api;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Retrieves the API key associated with the API instance, if it exists.
|
|
41
|
+
*
|
|
42
|
+
* @returns The API key as a string if it is set, or undefined if not set.
|
|
43
|
+
*/
|
|
44
|
+
getApiKey() {
|
|
45
|
+
return this.apiKey;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Retrieves the environment associated with the API instance.
|
|
49
|
+
*
|
|
50
|
+
* @returns A string representing the environment (e.g., 'dev', 'prod').
|
|
51
|
+
*/
|
|
52
|
+
getEnvironment() {
|
|
53
|
+
return this.environment;
|
|
54
|
+
}
|
|
21
55
|
/**
|
|
22
56
|
* Makes a GET request to the given endpoint.
|
|
23
57
|
*
|
|
@@ -85,11 +119,12 @@ export class BaseApi {
|
|
|
85
119
|
* @returns {Object.<string, string>} - Headers for the API request.
|
|
86
120
|
* @private
|
|
87
121
|
*/
|
|
88
|
-
|
|
122
|
+
constructHeaders() {
|
|
89
123
|
const headers = {
|
|
90
|
-
|
|
124
|
+
...this.headers,
|
|
125
|
+
'Content-Type': this.headers['Content-Type'] ?? 'application/json'
|
|
91
126
|
};
|
|
92
|
-
if (this.apiKey != null) {
|
|
127
|
+
if (!('Authorization' in headers) && (this.apiKey != null)) {
|
|
93
128
|
headers.Authorization = `Bearer ${this.apiKey}`;
|
|
94
129
|
}
|
|
95
130
|
return headers;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type Config } from 'src/types';
|
|
2
|
+
import { BaseApi } from '../base-api';
|
|
3
|
+
import { type NqlResult } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* A class for accessing the NQL API.
|
|
6
|
+
* @extends BaseApi
|
|
7
|
+
*/
|
|
8
|
+
declare class NqlApi extends BaseApi {
|
|
9
|
+
constructor(config: Config);
|
|
10
|
+
/**
|
|
11
|
+
* Executes an NQL query and returns the result.
|
|
12
|
+
*
|
|
13
|
+
* @param {string} token - The bearer token for authorization.
|
|
14
|
+
* @param {string} nqlQuery - The NQL query to execute.
|
|
15
|
+
* @returns {Promise<object>} A promise that resolves with the result of the NQL query.
|
|
16
|
+
*/
|
|
17
|
+
executeNql(token: string, nqlQuery: string): Promise<object>;
|
|
18
|
+
}
|
|
19
|
+
export { NqlApi, type NqlResult };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { BaseApi } from '../base-api';
|
|
2
|
+
/**
|
|
3
|
+
* The name of the resource to be used in API requests.
|
|
4
|
+
* @constant
|
|
5
|
+
* @private
|
|
6
|
+
* @type {string}
|
|
7
|
+
*/
|
|
8
|
+
const resourceName = 'nql';
|
|
9
|
+
/**
|
|
10
|
+
* A class for accessing the NQL API.
|
|
11
|
+
* @extends BaseApi
|
|
12
|
+
*/
|
|
13
|
+
class NqlApi extends BaseApi {
|
|
14
|
+
constructor(config) {
|
|
15
|
+
super({
|
|
16
|
+
...config,
|
|
17
|
+
headers: {
|
|
18
|
+
...config.headers,
|
|
19
|
+
'Content-Type': 'application/vnd.nql'
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Executes an NQL query and returns the result.
|
|
25
|
+
*
|
|
26
|
+
* @param {string} token - The bearer token for authorization.
|
|
27
|
+
* @param {string} nqlQuery - The NQL query to execute.
|
|
28
|
+
* @returns {Promise<object>} A promise that resolves with the result of the NQL query.
|
|
29
|
+
*/
|
|
30
|
+
async executeNql(token, nqlQuery) {
|
|
31
|
+
const response = await this.post(resourceName, nqlQuery);
|
|
32
|
+
return response;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export { NqlApi };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export interface NqlResult {
|
|
2
|
+
id: string;
|
|
3
|
+
company_id: number;
|
|
4
|
+
completed_at: string;
|
|
5
|
+
created_at: string;
|
|
6
|
+
failures: any[];
|
|
7
|
+
idempotency_key: string;
|
|
8
|
+
input: {
|
|
9
|
+
nql: string;
|
|
10
|
+
};
|
|
11
|
+
request_source: {
|
|
12
|
+
type: string;
|
|
13
|
+
company_id: number;
|
|
14
|
+
user_id: number;
|
|
15
|
+
};
|
|
16
|
+
result: {
|
|
17
|
+
success: {
|
|
18
|
+
result: {
|
|
19
|
+
forecast: {
|
|
20
|
+
rows: number;
|
|
21
|
+
cost: number;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
state: string;
|
|
27
|
+
updated_at: string;
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/build/types.d.ts
CHANGED
package/build/uploads/index.d.ts
CHANGED
package/build/uploads/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@narrative.io/data-collaboration-sdk-ts",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.32",
|
|
4
4
|
"main": "build/index.js",
|
|
5
5
|
"repository": "github:narrative-io/data-collaboration-sdk-ts",
|
|
6
6
|
"source": "src/index.ts",
|
|
@@ -9,13 +9,12 @@
|
|
|
9
9
|
"scripts": {
|
|
10
10
|
"build": "tsc",
|
|
11
11
|
"lint": "npx eslint . --fix",
|
|
12
|
-
"prepare": "npx eslint . --fix && npm run build",
|
|
12
|
+
"prepare": "npx eslint . --fix && npm run build && husky install",
|
|
13
13
|
"prepublishOnly": "npm test && npm run lint",
|
|
14
14
|
"preversion": "npm run lint",
|
|
15
15
|
"version": "npm run && git add -A src",
|
|
16
16
|
"postversion": "git push && git push --tags",
|
|
17
|
-
"test": "jest"
|
|
18
|
-
"coverage": "jest --coverage"
|
|
17
|
+
"test": "jest --coverage"
|
|
19
18
|
},
|
|
20
19
|
"keywords": [],
|
|
21
20
|
"author": "",
|
|
@@ -36,7 +35,8 @@
|
|
|
36
35
|
"eslint-plugin-promise": "^6.1.1",
|
|
37
36
|
"jest": "^29.4.3",
|
|
38
37
|
"ts-jest": "^29.0.5",
|
|
39
|
-
"typescript": "^4.9.5"
|
|
38
|
+
"typescript": "^4.9.5",
|
|
39
|
+
"husky": "^8.0.0"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"mande": "^2.0.3"
|