@narrative.io/data-collaboration-sdk-ts 0.0.107 → 0.0.108

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.
Files changed (69) hide show
  1. package/build/access-rules/index.d.ts +44 -0
  2. package/build/access-rules/index.js +51 -0
  3. package/build/access-rules/types.d.ts +29 -0
  4. package/build/access-rules/types.js +1 -0
  5. package/build/apps/index.d.ts +3 -3
  6. package/build/apps/index.js +4 -4
  7. package/build/apps/types.d.ts +1 -1
  8. package/build/apps/types.js +0 -1
  9. package/build/attributes/index.d.ts +9 -9
  10. package/build/attributes/index.js +8 -8
  11. package/build/attributes/types.d.ts +5 -5
  12. package/build/authentication/index.d.ts +3 -3
  13. package/build/authentication/index.js +3 -3
  14. package/build/authentication/types.d.ts +3 -3
  15. package/build/base-api.d.ts +42 -42
  16. package/build/base-api.js +51 -51
  17. package/build/company-info/index.d.ts +3 -3
  18. package/build/company-info/index.js +2 -2
  19. package/build/contracts/index.d.ts +18 -18
  20. package/build/contracts/index.js +18 -18
  21. package/build/contracts/types.d.ts +3 -3
  22. package/build/data-streams/index.d.ts +10 -10
  23. package/build/data-streams/index.js +9 -9
  24. package/build/data-streams/types.d.ts +7 -7
  25. package/build/datasets/index.d.ts +30 -30
  26. package/build/datasets/index.js +32 -32
  27. package/build/datasets/types.d.ts +9 -9
  28. package/build/forecast/index.d.ts +3 -3
  29. package/build/forecast/index.js +3 -3
  30. package/build/forecast/types.d.ts +7 -7
  31. package/build/health/index.d.ts +2 -2
  32. package/build/health/index.js +2 -2
  33. package/build/health/types.d.ts +1 -1
  34. package/build/index.d.ts +32 -31
  35. package/build/index.js +44 -24
  36. package/build/installations/index.d.ts +3 -3
  37. package/build/installations/index.js +3 -3
  38. package/build/installations/types.d.ts +1 -1
  39. package/build/mappings/index.d.ts +16 -16
  40. package/build/mappings/index.js +18 -18
  41. package/build/mappings/types.d.ts +6 -6
  42. package/build/nql/DataRulesConverter.d.ts +3 -3
  43. package/build/nql/DataRulesConverter.js +55 -31
  44. package/build/nql/NQLParser.d.ts +4 -4
  45. package/build/nql/NQLParser.js +74 -57
  46. package/build/nql/SubstraitParser.d.ts +173 -173
  47. package/build/nql/SubstraitParser.js +270 -261
  48. package/build/nql/index.d.ts +4 -4
  49. package/build/nql/index.js +3 -3
  50. package/build/nql/types.d.ts +6 -6
  51. package/build/nql/types.js +59 -29
  52. package/build/ping/index.d.ts +2 -2
  53. package/build/ping/index.js +2 -2
  54. package/build/ping/types.d.ts +1 -1
  55. package/build/products/index.d.ts +6 -6
  56. package/build/products/index.js +6 -6
  57. package/build/products/types.d.ts +4 -4
  58. package/build/resources/index.d.ts +4 -4
  59. package/build/resources/index.js +2 -2
  60. package/build/resources/types.d.ts +3 -3
  61. package/build/rosetta/types.d.ts +12 -12
  62. package/build/rosetta/types.js +69 -42
  63. package/build/rosetta-stone/index.d.ts +3 -3
  64. package/build/rosetta-stone/index.js +3 -3
  65. package/build/types.d.ts +2 -2
  66. package/build/uploads/index.d.ts +8 -8
  67. package/build/uploads/index.js +8 -8
  68. package/build/utils.js +1 -1
  69. package/package.json +3 -1
@@ -0,0 +1,44 @@
1
+ import type { ApiRecords } from "../types";
2
+ import { BaseApi } from "../base-api";
3
+ import type { AccessRule } from "./types";
4
+ /**
5
+ * @module AccessRulesApi
6
+ * @description This module provides methods for working with access rules.
7
+ * @extends BaseApi
8
+ */
9
+ declare class AccessRulesApi extends BaseApi {
10
+ /**
11
+ * Retrieves all the access rules.
12
+ *
13
+ * @returns {Promise<ApiRecords<AccessRule>>} A promise that resolves to an object containing access rules.
14
+ * @example
15
+ * const api = new AccessRulesApi();
16
+ * api.getAccessRules().then(rules => {
17
+ * console.log(rules);
18
+ * });
19
+ */
20
+ getAccessRules(): Promise<ApiRecords<AccessRule>>;
21
+ /**
22
+ * Deletes an access rule by ID.
23
+ *
24
+ * @param {number} id - The ID of the access rule to be deleted.
25
+ * @returns {Promise<void>} A promise that resolves once the deletion is successful.
26
+ */
27
+ deleteAccessRule(id: number): Promise<void>;
28
+ /**
29
+ * Creates a new access rule.
30
+ *
31
+ * @param {Omit<AccessRule, "id" | "created_at" | "updated_at">} rule - The access rule data.
32
+ * @returns {Promise<AccessRule>} A promise that resolves to the created access rule.
33
+ */
34
+ createAccessRule(rule: Omit<AccessRule, "id" | "created_at" | "updated_at">): Promise<AccessRule>;
35
+ /**
36
+ * Updates an existing access rule by ID.
37
+ *
38
+ * @param {number} id - The ID of the access rule to be updated.
39
+ * @param {Partial<Omit<AccessRule, "id" | "created_at" | "updated_at" | "dataset_id">>} rule - The updated access rule data.
40
+ * @returns {Promise<AccessRule>} A promise that resolves to the updated access rule.
41
+ */
42
+ updateAccessRule(id: number, rule: Partial<Omit<AccessRule, "id" | "created_at" | "updated_at" | "dataset_id">>): Promise<AccessRule>;
43
+ }
44
+ export { AccessRulesApi, type AccessRule };
@@ -0,0 +1,51 @@
1
+ import { BaseApi } from "../base-api";
2
+ const resourceName = "access-rules";
3
+ /**
4
+ * @module AccessRulesApi
5
+ * @description This module provides methods for working with access rules.
6
+ * @extends BaseApi
7
+ */
8
+ class AccessRulesApi extends BaseApi {
9
+ /**
10
+ * Retrieves all the access rules.
11
+ *
12
+ * @returns {Promise<ApiRecords<AccessRule>>} A promise that resolves to an object containing access rules.
13
+ * @example
14
+ * const api = new AccessRulesApi();
15
+ * api.getAccessRules().then(rules => {
16
+ * console.log(rules);
17
+ * });
18
+ */
19
+ async getAccessRules() {
20
+ return await this.get(resourceName);
21
+ }
22
+ /**
23
+ * Deletes an access rule by ID.
24
+ *
25
+ * @param {number} id - The ID of the access rule to be deleted.
26
+ * @returns {Promise<void>} A promise that resolves once the deletion is successful.
27
+ */
28
+ async deleteAccessRule(id) {
29
+ await this.delete(`${resourceName}/${id}`);
30
+ }
31
+ /**
32
+ * Creates a new access rule.
33
+ *
34
+ * @param {Omit<AccessRule, "id" | "created_at" | "updated_at">} rule - The access rule data.
35
+ * @returns {Promise<AccessRule>} A promise that resolves to the created access rule.
36
+ */
37
+ async createAccessRule(rule) {
38
+ return await this.post(resourceName, rule);
39
+ }
40
+ /**
41
+ * Updates an existing access rule by ID.
42
+ *
43
+ * @param {number} id - The ID of the access rule to be updated.
44
+ * @param {Partial<Omit<AccessRule, "id" | "created_at" | "updated_at" | "dataset_id">>} rule - The updated access rule data.
45
+ * @returns {Promise<AccessRule>} A promise that resolves to the updated access rule.
46
+ */
47
+ async updateAccessRule(id, rule) {
48
+ return await this.put(`${resourceName}/${id}`, rule);
49
+ }
50
+ }
51
+ export { AccessRulesApi };
@@ -0,0 +1,29 @@
1
+ export interface AccessRule {
2
+ id: number;
3
+ dataset_id?: AccessRuleDatasetId;
4
+ policy?: AccessRulePolicy;
5
+ company_constraint?: AccessRuleCompanyConstraint;
6
+ constraints?: AccessRuleConstraints;
7
+ created_at: string;
8
+ description?: AccessRuleDescription;
9
+ pricing: AccessRulePricing;
10
+ status: "active";
11
+ updated_at: string;
12
+ }
13
+ type AccessRuleDatasetId = number;
14
+ interface AccessRulePolicyDataset {
15
+ id: string;
16
+ columns: string[];
17
+ }
18
+ interface AccessRulePolicy {
19
+ query: string;
20
+ datasets: AccessRulePolicyDataset;
21
+ }
22
+ interface AccessRuleCompanyConstraint {
23
+ type: "inclusion" | "exclusion";
24
+ company_ids: number[];
25
+ }
26
+ type AccessRuleConstraints = string[];
27
+ type AccessRuleDescription = string;
28
+ type AccessRulePricing = number;
29
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1,6 +1,6 @@
1
- import { type ApiRecords } from '../types';
2
- import { BaseApi } from '../base-api';
3
- import { type App, type Installation } from './types';
1
+ import { type ApiRecords } from "../types";
2
+ import { BaseApi } from "../base-api";
3
+ import { type App, type Installation } from "./types";
4
4
  /**
5
5
  * @module AppsApi
6
6
  * @description This module provides methods for fetching app records.
@@ -1,5 +1,5 @@
1
- import { BaseApi } from '../base-api';
2
- const resourceName = 'apps';
1
+ import { BaseApi } from "../base-api";
2
+ const resourceName = "apps";
3
3
  /**
4
4
  * @module AppsApi
5
5
  * @description This module provides methods for fetching app records.
@@ -12,12 +12,12 @@ class AppsApi extends BaseApi {
12
12
  * @returns {Promise<ApiRecords<Installation>>} - Promise resolving with the list of installations.
13
13
  */
14
14
  async getApps(appCategory) {
15
- const appCategoryQuery = appCategory !== undefined ? `?app_category=${appCategory}` : '';
15
+ const appCategoryQuery = appCategory !== undefined ? `?app_category=${appCategory}` : "";
16
16
  const url = `${resourceName}${appCategoryQuery}`;
17
17
  return await this.get(url);
18
18
  }
19
19
  async getInstalledApps(appCategory) {
20
- const appCategoryQuery = appCategory !== undefined ? `?app_category=${appCategory}` : '';
20
+ const appCategoryQuery = appCategory !== undefined ? `?app_category=${appCategory}` : "";
21
21
  const url = `installations${appCategoryQuery}`;
22
22
  return await this.get(url);
23
23
  }
@@ -1,5 +1,5 @@
1
1
  interface Permission {
2
- access: 'read' | 'write';
2
+ access: "read" | "write";
3
3
  resource: string;
4
4
  }
5
5
  export interface Installation {
@@ -1,2 +1 @@
1
- ;
2
1
  export {};
@@ -1,6 +1,6 @@
1
- import { type ApiRecords } from '../types';
2
- import { BaseApi } from '../base-api';
3
- import { type Attribute, type ShallowAttribute, type RefAttribute, type SubAttribute, type PrimitiveAttribute, type ObjectAttribute, type ArrayAttribute } from './types';
1
+ import { type ApiRecords } from "../types";
2
+ import { BaseApi } from "../base-api";
3
+ import { type Attribute, type ShallowAttribute, type RefAttribute, type SubAttribute, type PrimitiveAttribute, type ObjectAttribute, type ArrayAttribute } from "./types";
4
4
  /**
5
5
  * A class for accessing the Attribute API.
6
6
  * @extends BaseApi
@@ -13,11 +13,11 @@ declare class AttributeApi extends BaseApi {
13
13
  */
14
14
  getAttributes(): Promise<ApiRecords<Attribute>>;
15
15
  /**
16
- * Gets a single attribute from the API by its ID.
17
- *
18
- * @param {number} attributeId - The ID of the attribute to retrieve.
19
- * @returns {Promise<Attribute>} A promise that resolves with the attribute.
20
- */
16
+ * Gets a single attribute from the API by its ID.
17
+ *
18
+ * @param {number} attributeId - The ID of the attribute to retrieve.
19
+ * @returns {Promise<Attribute>} A promise that resolves with the attribute.
20
+ */
21
21
  getAttribute(attributeId: number): Promise<Attribute>;
22
22
  /**
23
23
  * Deletes a single attribute from the API by its ID.
@@ -34,4 +34,4 @@ declare class AttributeApi extends BaseApi {
34
34
  */
35
35
  createAttribute(data: Attribute): Promise<Attribute>;
36
36
  }
37
- export { AttributeApi, type Attribute, type ShallowAttribute, type RefAttribute, type SubAttribute, type PrimitiveAttribute, type ArrayAttribute, type ObjectAttribute };
37
+ export { AttributeApi, type Attribute, type ShallowAttribute, type RefAttribute, type SubAttribute, type PrimitiveAttribute, type ArrayAttribute, type ObjectAttribute, };
@@ -1,11 +1,11 @@
1
- import { BaseApi } from '../base-api';
1
+ import { BaseApi } from "../base-api";
2
2
  /**
3
3
  * The name of the resource to be used in API requests.
4
4
  * @constant
5
5
  * @private
6
6
  * @type {string}
7
7
  */
8
- const resourceName = 'attributes';
8
+ const resourceName = "attributes";
9
9
  /**
10
10
  * A class for accessing the Attribute API.
11
11
  * @extends BaseApi
@@ -20,11 +20,11 @@ class AttributeApi extends BaseApi {
20
20
  return await this.get(resourceName);
21
21
  }
22
22
  /**
23
- * Gets a single attribute from the API by its ID.
24
- *
25
- * @param {number} attributeId - The ID of the attribute to retrieve.
26
- * @returns {Promise<Attribute>} A promise that resolves with the attribute.
27
- */
23
+ * Gets a single attribute from the API by its ID.
24
+ *
25
+ * @param {number} attributeId - The ID of the attribute to retrieve.
26
+ * @returns {Promise<Attribute>} A promise that resolves with the attribute.
27
+ */
28
28
  async getAttribute(attributeId) {
29
29
  return await this.get(`${resourceName}/${attributeId}`);
30
30
  }
@@ -47,4 +47,4 @@ class AttributeApi extends BaseApi {
47
47
  return await this.post(`${resourceName}`, data);
48
48
  }
49
49
  }
50
- export { AttributeApi };
50
+ export { AttributeApi, };
@@ -1,5 +1,5 @@
1
1
  export type Attribute = PrimitiveAttribute | ArrayAttribute | ObjectAttribute;
2
- export type ShallowAttribute = Omit<Attribute, 'properties'>;
2
+ export type ShallowAttribute = Omit<Attribute, "properties">;
3
3
  export interface BaseAttribute {
4
4
  id: number;
5
5
  name: string;
@@ -10,11 +10,11 @@ export interface BaseAttribute {
10
10
  metadata?: AttributeMetadata;
11
11
  }
12
12
  export interface PrimitiveAttribute extends BaseAttribute {
13
- type: 'string' | 'boolean' | 'double' | 'long' | 'timestamptz';
13
+ type: "string" | "boolean" | "double" | "long" | "timestamptz";
14
14
  enum?: string[] | number[] | boolean[];
15
15
  is_join_key?: boolean;
16
16
  }
17
- export type SubAttribute = Partial<Omit<Attribute, 'name' | 'id'>> & {
17
+ export type SubAttribute = Partial<Omit<Attribute, "name" | "id">> & {
18
18
  type: string;
19
19
  enum?: string[] | number[] | boolean[];
20
20
  is_join_key?: boolean;
@@ -23,11 +23,11 @@ export interface RefAttribute {
23
23
  $ref: number;
24
24
  }
25
25
  export interface ArrayAttribute extends BaseAttribute {
26
- type: 'array';
26
+ type: "array";
27
27
  items: SubAttribute;
28
28
  }
29
29
  export interface ObjectAttribute extends BaseAttribute {
30
- type: 'object';
30
+ type: "object";
31
31
  properties: Record<string, SubAttribute | RefAttribute>;
32
32
  required?: string[];
33
33
  }
@@ -1,5 +1,5 @@
1
- import { BaseApi } from '../base-api';
2
- import { type LoginRequest, type LoginResponse, type RegisterRequest, type RegisterResponse, type LoggedInUser, type StytchToken, type ApiToken, type UserRole, type RegistrationStatus, type RegistrationStatusRequest, type RegistrationStatusResponse } from './types';
1
+ import { BaseApi } from "../base-api";
2
+ import { type LoginRequest, type LoginResponse, type RegisterRequest, type RegisterResponse, type LoggedInUser, type StytchToken, type ApiToken, type UserRole, type RegistrationStatus, type RegistrationStatusRequest, type RegistrationStatusResponse } from "./types";
3
3
  /**
4
4
  * A class for accessing the Authentication API
5
5
  * @extends BaseApi
@@ -27,4 +27,4 @@ declare class AuthenticationApi extends BaseApi {
27
27
  */
28
28
  checkRegistrationStatus(statusRequest: RegistrationStatusRequest): Promise<RegistrationStatusResponse>;
29
29
  }
30
- export { type LoginRequest, type LoginResponse, type RegisterRequest, type RegisterResponse, type LoggedInUser, type StytchToken, type ApiToken, type UserRole, type RegistrationStatus, type RegistrationStatusRequest, type RegistrationStatusResponse, AuthenticationApi };
30
+ export { type LoginRequest, type LoginResponse, type RegisterRequest, type RegisterResponse, type LoggedInUser, type StytchToken, type ApiToken, type UserRole, type RegistrationStatus, type RegistrationStatusRequest, type RegistrationStatusResponse, AuthenticationApi, };
@@ -1,11 +1,11 @@
1
- import { BaseApi } from '../base-api';
1
+ import { BaseApi } from "../base-api";
2
2
  /**
3
3
  * The name of the resource to be used in API requests.
4
4
  * @constant
5
5
  * @private
6
6
  * @type {string}
7
7
  */
8
- const resourceName = 'authentication';
8
+ const resourceName = "authentication";
9
9
  /**
10
10
  * A class for accessing the Authentication API
11
11
  * @extends BaseApi
@@ -39,4 +39,4 @@ class AuthenticationApi extends BaseApi {
39
39
  return await this.post(`${resourceName}/registration-status`, statusRequest);
40
40
  }
41
41
  }
42
- export { AuthenticationApi };
42
+ export { AuthenticationApi, };
@@ -37,9 +37,9 @@ export interface LoggedInUser {
37
37
  }
38
38
  export interface StytchToken {
39
39
  token: string;
40
- token_type: 'magiclinks' | 'oauth';
40
+ token_type: "magiclinks" | "oauth";
41
41
  }
42
- export type UserRole = 'global_admin' | 'partner_admin' | 'partner_user';
42
+ export type UserRole = "global_admin" | "partner_admin" | "partner_user";
43
43
  export interface RegistrationStatusRequest {
44
44
  stytch_token: StytchToken;
45
45
  session_duration_minutes?: number;
@@ -50,4 +50,4 @@ export interface RegistrationStatusResponse {
50
50
  stytch_session_token: string;
51
51
  stytch_session_jwt: string;
52
52
  }
53
- export type RegistrationStatus = 'complete' | 'pending';
53
+ export type RegistrationStatus = "complete" | "pending";
@@ -1,5 +1,5 @@
1
- import { type MandeInstance } from 'mande';
2
- import { type Config } from './types';
1
+ import { type MandeInstance } from "mande";
2
+ import { type Config } from "./types";
3
3
  /**
4
4
  * BaseApi class provides basic functionality for making API requests.
5
5
  */
@@ -10,10 +10,10 @@ export declare abstract class BaseApi {
10
10
  protected readonly headers: Record<string, string>;
11
11
  protected readonly verbose: boolean;
12
12
  /**
13
- * @param {Config} config - Configuration object.
14
- * @param {string} [config.apiKey] - API key.
15
- * @param {Environment} [config.environment='prod'] - Environment for the API (e.g. 'dev', 'prod').
16
- */
13
+ * @param {Config} config - Configuration object.
14
+ * @param {string} [config.apiKey] - API key.
15
+ * @param {Environment} [config.environment='prod'] - Environment for the API (e.g. 'dev', 'prod').
16
+ */
17
17
  constructor(config: Config);
18
18
  /**
19
19
  * Retrieves the headers associated with the API instance.
@@ -22,40 +22,40 @@ export declare abstract class BaseApi {
22
22
  */
23
23
  getHeaders(): Record<string, string>;
24
24
  /**
25
- * Retrieves the base API instance created using Mande.
26
- *
27
- * @returns A MandeInstance object representing the base API instance.
28
- */
25
+ * Retrieves the base API instance created using Mande.
26
+ *
27
+ * @returns A MandeInstance object representing the base API instance.
28
+ */
29
29
  getBaseApi(): MandeInstance;
30
30
  /**
31
- * Retrieves the API key associated with the API instance, if it exists.
32
- *
33
- * @returns The API key as a string if it is set, or undefined if not set.
34
- */
31
+ * Retrieves the API key associated with the API instance, if it exists.
32
+ *
33
+ * @returns The API key as a string if it is set, or undefined if not set.
34
+ */
35
35
  getApiKey(): string | undefined;
36
36
  /**
37
- * Retrieves the environment associated with the API instance.
38
- *
39
- * @returns A string representing the environment (e.g., 'dev', 'prod').
40
- */
37
+ * Retrieves the environment associated with the API instance.
38
+ *
39
+ * @returns A string representing the environment (e.g., 'dev', 'prod').
40
+ */
41
41
  getEnvironment(): string;
42
42
  /**
43
- * Makes a GET request to the given endpoint.
44
- *
45
- * @param {string} endpoint - Endpoint for the request.
46
- * @returns {Promise<T>} - Promise that resolves with the response data.
47
- * @template T - Type of the response data.
48
- */
43
+ * Makes a GET request to the given endpoint.
44
+ *
45
+ * @param {string} endpoint - Endpoint for the request.
46
+ * @returns {Promise<T>} - Promise that resolves with the response data.
47
+ * @template T - Type of the response data.
48
+ */
49
49
  protected get<T>(endpoint: string): Promise<T>;
50
50
  /**
51
- * Makes a POST request to the given endpoint with the given data.
52
- *
53
- * @param {string} endpoint - Endpoint for the request.
54
- * @param {I} data - Data to be sent in the request.
55
- * @returns {Promise<T>} - Promise that resolves with the response data.
56
- * @template I - Type of the request data.
57
- * @template T - Type of the response data.
58
- */
51
+ * Makes a POST request to the given endpoint with the given data.
52
+ *
53
+ * @param {string} endpoint - Endpoint for the request.
54
+ * @param {I} data - Data to be sent in the request.
55
+ * @returns {Promise<T>} - Promise that resolves with the response data.
56
+ * @template I - Type of the request data.
57
+ * @template T - Type of the response data.
58
+ */
59
59
  protected post<I, T>(endpoint: string, data?: I): Promise<T>;
60
60
  /**
61
61
  * Sends a DELETE request to the specified endpoint.
@@ -74,17 +74,17 @@ export declare abstract class BaseApi {
74
74
  */
75
75
  protected put<I, T>(endpoint: string, data: I): Promise<T>;
76
76
  /**
77
- * Returns the base URL for the API based on the environment.
78
- *
79
- * @returns {string} - Base URL for the API.
80
- * @private
81
- */
77
+ * Returns the base URL for the API based on the environment.
78
+ *
79
+ * @returns {string} - Base URL for the API.
80
+ * @private
81
+ */
82
82
  getBaseUrl(): string;
83
83
  /**
84
- * Returns the headers for the API request.
85
- *
86
- * @returns {Object.<string, string>} - Headers for the API request.
87
- * @private
88
- */
84
+ * Returns the headers for the API request.
85
+ *
86
+ * @returns {Object.<string, string>} - Headers for the API request.
87
+ * @private
88
+ */
89
89
  private constructHeaders;
90
90
  }
package/build/base-api.js CHANGED
@@ -1,5 +1,5 @@
1
- import { mande } from 'mande';
2
- import { addTrailingSlash } from './utils';
1
+ import { mande } from "mande";
2
+ import { addTrailingSlash } from "./utils";
3
3
  /**
4
4
  * BaseApi class provides basic functionality for making API requests.
5
5
  */
@@ -10,21 +10,21 @@ export class BaseApi {
10
10
  headers;
11
11
  verbose;
12
12
  /**
13
- * @param {Config} config - Configuration object.
14
- * @param {string} [config.apiKey] - API key.
15
- * @param {Environment} [config.environment='prod'] - Environment for the API (e.g. 'dev', 'prod').
16
- */
13
+ * @param {Config} config - Configuration object.
14
+ * @param {string} [config.apiKey] - API key.
15
+ * @param {Environment} [config.environment='prod'] - Environment for the API (e.g. 'dev', 'prod').
16
+ */
17
17
  constructor(config) {
18
18
  this.verbose = config.verbose ?? false;
19
19
  this.apiKey = config.apiKey;
20
- this.environment = config.environment ?? 'prod';
20
+ this.environment = config.environment ?? "prod";
21
21
  this.headers = config.headers ?? {};
22
22
  this.base_api = mande(`${this.getBaseUrl()}`, {
23
- headers: this.constructHeaders()
23
+ headers: this.constructHeaders(),
24
24
  });
25
25
  if (this.verbose) {
26
26
  console.log(`Using environment: ${this.environment}`);
27
- console.log(`Using API key: ${this.apiKey ?? 'undefined'}`);
27
+ console.log(`Using API key: ${this.apiKey ?? "undefined"}`);
28
28
  console.log(`Using headers: ${JSON.stringify(this.constructHeaders())}`);
29
29
  console.log(`Using base URL: ${this.getBaseUrl()}`);
30
30
  console.log(`Using base API: ${JSON.stringify(this.base_api)}`);
@@ -40,36 +40,36 @@ export class BaseApi {
40
40
  return this.constructHeaders();
41
41
  }
42
42
  /**
43
- * Retrieves the base API instance created using Mande.
44
- *
45
- * @returns A MandeInstance object representing the base API instance.
46
- */
43
+ * Retrieves the base API instance created using Mande.
44
+ *
45
+ * @returns A MandeInstance object representing the base API instance.
46
+ */
47
47
  getBaseApi() {
48
48
  return this.base_api;
49
49
  }
50
50
  /**
51
- * Retrieves the API key associated with the API instance, if it exists.
52
- *
53
- * @returns The API key as a string if it is set, or undefined if not set.
54
- */
51
+ * Retrieves the API key associated with the API instance, if it exists.
52
+ *
53
+ * @returns The API key as a string if it is set, or undefined if not set.
54
+ */
55
55
  getApiKey() {
56
56
  return this.apiKey;
57
57
  }
58
58
  /**
59
- * Retrieves the environment associated with the API instance.
60
- *
61
- * @returns A string representing the environment (e.g., 'dev', 'prod').
62
- */
59
+ * Retrieves the environment associated with the API instance.
60
+ *
61
+ * @returns A string representing the environment (e.g., 'dev', 'prod').
62
+ */
63
63
  getEnvironment() {
64
64
  return this.environment;
65
65
  }
66
66
  /**
67
- * Makes a GET request to the given endpoint.
68
- *
69
- * @param {string} endpoint - Endpoint for the request.
70
- * @returns {Promise<T>} - Promise that resolves with the response data.
71
- * @template T - Type of the response data.
72
- */
67
+ * Makes a GET request to the given endpoint.
68
+ *
69
+ * @param {string} endpoint - Endpoint for the request.
70
+ * @returns {Promise<T>} - Promise that resolves with the response data.
71
+ * @template T - Type of the response data.
72
+ */
73
73
  async get(endpoint) {
74
74
  if (this.verbose) {
75
75
  console.log(`Making GET request to ${endpoint}...`);
@@ -79,14 +79,14 @@ export class BaseApi {
79
79
  return await this.base_api.get(endpoint);
80
80
  }
81
81
  /**
82
- * Makes a POST request to the given endpoint with the given data.
83
- *
84
- * @param {string} endpoint - Endpoint for the request.
85
- * @param {I} data - Data to be sent in the request.
86
- * @returns {Promise<T>} - Promise that resolves with the response data.
87
- * @template I - Type of the request data.
88
- * @template T - Type of the response data.
89
- */
82
+ * Makes a POST request to the given endpoint with the given data.
83
+ *
84
+ * @param {string} endpoint - Endpoint for the request.
85
+ * @param {I} data - Data to be sent in the request.
86
+ * @returns {Promise<T>} - Promise that resolves with the response data.
87
+ * @template I - Type of the request data.
88
+ * @template T - Type of the response data.
89
+ */
90
90
  async post(endpoint, data) {
91
91
  if (this.verbose)
92
92
  console.log(`Making POST request to ${endpoint} with data: ${JSON.stringify(data)}...`);
@@ -117,18 +117,18 @@ export class BaseApi {
117
117
  return await this.base_api.put(endpoint, data);
118
118
  }
119
119
  /**
120
- * Returns the base URL for the API based on the environment.
121
- *
122
- * @returns {string} - Base URL for the API.
123
- * @private
124
- */
120
+ * Returns the base URL for the API based on the environment.
121
+ *
122
+ * @returns {string} - Base URL for the API.
123
+ * @private
124
+ */
125
125
  getBaseUrl() {
126
126
  switch (this.environment) {
127
- case 'prod': {
128
- return 'https://api.narrative.io/';
127
+ case "prod": {
128
+ return "https://api.narrative.io/";
129
129
  }
130
- case 'dev': {
131
- return 'https://api-dev.narrative.io/';
130
+ case "dev": {
131
+ return "https://api-dev.narrative.io/";
132
132
  }
133
133
  default: {
134
134
  return addTrailingSlash(this.environment);
@@ -136,17 +136,17 @@ export class BaseApi {
136
136
  }
137
137
  }
138
138
  /**
139
- * Returns the headers for the API request.
140
- *
141
- * @returns {Object.<string, string>} - Headers for the API request.
142
- * @private
143
- */
139
+ * Returns the headers for the API request.
140
+ *
141
+ * @returns {Object.<string, string>} - Headers for the API request.
142
+ * @private
143
+ */
144
144
  constructHeaders() {
145
145
  const headers = {
146
146
  ...this.headers,
147
- 'Content-Type': this.headers['Content-Type'] ?? 'application/json'
147
+ "Content-Type": this.headers["Content-Type"] ?? "application/json",
148
148
  };
149
- if (!('Authorization' in headers) && (this.apiKey != null)) {
149
+ if (!("Authorization" in headers) && this.apiKey != null) {
150
150
  headers.Authorization = `Bearer ${this.apiKey}`;
151
151
  }
152
152
  return headers;
@@ -1,6 +1,6 @@
1
- import { BaseApi } from '../base-api';
2
- import { type ApiRecords } from '../types';
3
- import { type CompanyInfo, type WhoAmI } from './types';
1
+ import { BaseApi } from "../base-api";
2
+ import { type ApiRecords } from "../types";
3
+ import { type CompanyInfo, type WhoAmI } from "./types";
4
4
  /**
5
5
  * A class for accessing the Company Info API
6
6
  * @extends BaseApi
@@ -1,11 +1,11 @@
1
- import { BaseApi } from '../base-api';
1
+ import { BaseApi } from "../base-api";
2
2
  /**
3
3
  * The name of the resource to be used in API requests.
4
4
  * @constant
5
5
  * @private
6
6
  * @type {string}
7
7
  */
8
- const resourceName = 'company-info';
8
+ const resourceName = "company-info";
9
9
  /**
10
10
  * A class for accessing the Company Info API
11
11
  * @extends BaseApi