@narrative.io/data-collaboration-sdk-ts 2.58.1 → 2.59.0

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/README.md CHANGED
@@ -1,18 +1,316 @@
1
- # SDK
1
+ # Narrative.io Data Collaboration SDK for TypeScript
2
2
 
3
- ## Make a release
3
+ [![npm version](https://img.shields.io/npm/v/@narrative.io/data-collaboration-sdk-ts.svg)](https://www.npmjs.com/package/@narrative.io/data-collaboration-sdk-ts)
4
4
 
5
- To make a new release of the SDK, create a branch, make your changes, create a commit with a message following this
6
- format: `chore(main): release x.y.z` where x.y.z is the release number that you want. You can calculate it like this:
5
+ The official TypeScript SDK for the Narrative.io Data Collaboration Platform. This SDK provides a simple and intuitive interface for interacting with Narrative's APIs, allowing you to manage datasets, subscriptions, data streams, and more.
6
+
7
+ ## Table of Contents
8
+
9
+ - [Installation](#installation)
10
+ - [Quick Start](#quick-start)
11
+ - [API Overview](#api-overview)
12
+ - [Usage Examples](#usage-examples)
13
+ - [Configuration](#configuration)
14
+ - [TypeScript Support](#typescript-support)
15
+ - [Error Handling](#error-handling)
16
+ - [API Reference](#api-reference)
17
+ - [Contributing](#contributing)
18
+ - [License](#license)
19
+
20
+ ## Installation
21
+
22
+ Install the SDK using npm:
23
+
24
+ ```bash
25
+ npm install @narrative.io/data-collaboration-sdk-ts
26
+ ```
27
+
28
+ Or using yarn:
29
+
30
+ ```bash
31
+ yarn add @narrative.io/data-collaboration-sdk-ts
32
+ ```
33
+
34
+ Or using bun:
7
35
 
8
36
  ```bash
9
- VERSION=$(cat package.json | jq -r .version); \
10
- PATCH=$(expr $(echo $VERSION|cut -f3 -d.) + 1); \
11
- NEW_VERSION=$(printf "$(echo $VERSION | cut -f1,2 -d.).$PATCH\n"); \
12
- echo $NEW_VERSION | pbcopy; \
13
- echo "The new VERSION=${NEW_VERSION} is in your clipboard."
37
+ bun add @narrative.io/data-collaboration-sdk-ts
38
+ ```
39
+
40
+ ## Quick Start
41
+
42
+ ```typescript
43
+ import { NarrativeApi } from '@narrative.io/data-collaboration-sdk-ts';
44
+
45
+ // Initialize the SDK with your API key
46
+ const narrative = new NarrativeApi({
47
+ apiKey: 'your-api-key-here',
48
+ environment: 'prod' // 'prod' or 'dev'
49
+ });
50
+
51
+ // Make your first API call
52
+ async function getMyCompanyInfo() {
53
+ try {
54
+ const companyInfo = await narrative.getCompanyInfo();
55
+ console.log('Company:', companyInfo);
56
+ } catch (error) {
57
+ console.error('Error:', error);
58
+ }
59
+ }
60
+
61
+ getMyCompanyInfo();
62
+ ```
63
+
64
+ ## API Overview
65
+
66
+ The SDK provides access to the following Narrative.io API modules:
67
+
68
+ ### Core APIs
69
+ - **Authentication** - Manage API authentication
70
+ - **Company Info** - Retrieve company information
71
+ - **Health Check** - Check API health status
72
+ - **Who Am I** - Get current user information
73
+
74
+ ### Data Management
75
+ - **Datasets** - Create and manage datasets
76
+ - **Data Streams** - Configure real-time data streams
77
+ - **Data Planes** - Manage data plane configurations
78
+ - **Subscriptions** - Handle data subscriptions
79
+ - **Uploads** - Upload data files
80
+
81
+ ### Data Operations
82
+ - **Queries** - Execute data queries
83
+ - **Forecast** - Generate data forecasts
84
+ - **NQL (Narrative Query Language)** - Build and execute NQL queries
85
+ - **Views** - Create and manage data views
86
+
87
+ ### Marketplace & Collaboration
88
+ - **Products** - Browse and manage data products
89
+ - **Contracts** - Handle data contracts
90
+ - **Connections** - Manage data connections
91
+ - **Installations** - Track app installations
92
+
93
+ ### Advanced Features
94
+ - **Attributes** - Define data attributes
95
+ - **Mappings** - Configure data mappings
96
+ - **Models** - Work with ML models
97
+ - **Model Training** - Train custom models
98
+ - **Rosetta Stone** - Data transformation tools
99
+ - **Access Rules** - Set data access permissions
100
+ - **Access Tokens** - Manage API tokens
101
+ - **Encryption Materials** - Handle encryption keys
102
+
103
+ ## Usage Examples
104
+
105
+ ### Working with Datasets
106
+
107
+ ```typescript
108
+ // List all datasets
109
+ const datasets = await narrative.getDatasets();
110
+ console.log(`Found ${datasets.length} datasets`);
111
+
112
+ // Get a specific dataset
113
+ const datasetId = 'your-dataset-id';
114
+ const dataset = await narrative.getDataset(datasetId);
115
+ console.log('Dataset name:', dataset.name);
116
+
117
+ // Create a new dataset
118
+ const newDataset = await narrative.createDataset({
119
+ name: 'My New Dataset',
120
+ description: 'A dataset created via SDK',
121
+ schema: {
122
+ // Your schema definition
123
+ }
124
+ });
125
+ ```
126
+
127
+ ### Managing Subscriptions
128
+
129
+ ```typescript
130
+ // List active subscriptions
131
+ const subscriptions = await narrative.getSubscriptions();
132
+ subscriptions.forEach(sub => {
133
+ console.log(`Subscription: ${sub.name} - Status: ${sub.status}`);
134
+ });
135
+
136
+ // Create a subscription
137
+ const subscription = await narrative.createSubscription({
138
+ name: 'Daily Data Feed',
139
+ datasetId: 'dataset-id',
140
+ frequency: 'daily'
141
+ });
142
+ ```
143
+
144
+ ### Executing NQL Queries
145
+
146
+ ```typescript
147
+ // Build and execute an NQL query
148
+ const nqlQuery = `
149
+ SELECT *
150
+ FROM narrative.datasets
151
+ WHERE created_date >= '2024-01-01'
152
+ LIMIT 100
153
+ `;
154
+
155
+ const results = await narrative.executeNql(nqlQuery);
156
+ console.log('Query returned', results.rows.length, 'rows');
157
+ ```
158
+
159
+ ### Uploading Data
160
+
161
+ ```typescript
162
+ // Upload a file to a dataset
163
+ const upload = await narrative.createUpload({
164
+ datasetId: 'your-dataset-id',
165
+ fileName: 'data.csv',
166
+ fileSize: 1024000 // Size in bytes
167
+ });
168
+
169
+ // Get the upload URL and upload your file
170
+ console.log('Upload URL:', upload.uploadUrl);
171
+ // Use the uploadUrl to PUT your file data
172
+ ```
173
+
174
+ ## Configuration
175
+
176
+ ### Environment Configuration
177
+
178
+ The SDK supports multiple environments:
179
+
180
+ ```typescript
181
+ // Production environment (default)
182
+ const narrativeProd = new NarrativeApi({
183
+ apiKey: 'your-api-key'
184
+ });
185
+
186
+ // Development environment
187
+ const narrativeDev = new NarrativeApi({
188
+ apiKey: 'your-api-key',
189
+ environment: 'dev'
190
+ });
191
+ ```
192
+
193
+ ### Custom Headers
194
+
195
+ Add custom headers to all requests:
196
+
197
+ ```typescript
198
+ const narrative = new NarrativeApi({
199
+ apiKey: 'your-api-key',
200
+ headers: {
201
+ 'X-Custom-Header': 'custom-value'
202
+ }
203
+ });
204
+ ```
205
+
206
+ ### API Key Management
207
+
208
+ Store your API key securely using environment variables:
209
+
210
+ ```typescript
211
+ // .env file
212
+ NARRATIVE_API_KEY=your-api-key-here
213
+
214
+ // Your code
215
+ import { NarrativeApi } from '@narrative.io/data-collaboration-sdk-ts';
216
+
217
+ const narrative = new NarrativeApi({
218
+ apiKey: process.env.NARRATIVE_API_KEY!
219
+ });
220
+ ```
221
+
222
+ ## TypeScript Support
223
+
224
+ The SDK is written in TypeScript and provides comprehensive type definitions:
225
+
226
+ ```typescript
227
+ import {
228
+ NarrativeApi,
229
+ Dataset,
230
+ Subscription,
231
+ DataStream,
232
+ NqlQuery
233
+ } from '@narrative.io/data-collaboration-sdk-ts';
234
+
235
+ // Type-safe API calls
236
+ const narrative = new NarrativeApi({
237
+ apiKey: 'your-api-key'
238
+ });
239
+
240
+ // TypeScript will provide intellisense and type checking
241
+ const dataset: Dataset = await narrative.getDataset('dataset-id');
242
+ const subscriptions: Subscription[] = await narrative.getSubscriptions();
243
+ ```
244
+
245
+ ### Working with Types
246
+
247
+ ```typescript
248
+ import type {
249
+ Config,
250
+ PaginationOptions,
251
+ Dataset,
252
+ CreateDatasetRequest
253
+ } from '@narrative.io/data-collaboration-sdk-ts';
254
+
255
+ // Use types for better code organization
256
+ const config: Config = {
257
+ apiKey: process.env.NARRATIVE_API_KEY!,
258
+ environment: 'prod'
259
+ };
260
+
261
+ const paginationOptions: PaginationOptions = {
262
+ limit: 100,
263
+ offset: 0
264
+ };
14
265
  ```
15
266
 
16
- Push your changes to the branch, merge it to the `main` branch. Once the merge is completed (i.e., github actions
17
- completed) a new release pull request will be available on the github project. Merge the new pull request and the
18
- github actions will publish the new version of the SKD for you.
267
+ ## Error Handling
268
+
269
+ The SDK provides detailed error information:
270
+
271
+ ```typescript
272
+ import { NarrativeApi } from '@narrative.io/data-collaboration-sdk-ts';
273
+
274
+ const narrative = new NarrativeApi({
275
+ apiKey: 'your-api-key'
276
+ });
277
+
278
+ try {
279
+ const dataset = await narrative.getDataset('non-existent-id');
280
+ } catch (error) {
281
+ if (error.response) {
282
+ // API returned an error response
283
+ console.error('API Error:', error.response.status);
284
+ console.error('Error Message:', error.response.data.message);
285
+ } else if (error.request) {
286
+ // Request was made but no response received
287
+ console.error('Network Error:', error.message);
288
+ } else {
289
+ // Something else happened
290
+ console.error('Error:', error.message);
291
+ }
292
+ }
293
+ ```
294
+
295
+ ### Common Error Patterns
296
+
297
+ ```typescript
298
+ // Handle specific error codes
299
+ try {
300
+ const result = await narrative.someApiCall();
301
+ } catch (error) {
302
+ if (error.response?.status === 401) {
303
+ console.error('Authentication failed. Check your API key.');
304
+ } else if (error.response?.status === 404) {
305
+ console.error('Resource not found.');
306
+ } else if (error.response?.status === 429) {
307
+ console.error('Rate limit exceeded. Please retry later.');
308
+ } else {
309
+ console.error('Unexpected error:', error);
310
+ }
311
+ }
312
+ ```
313
+
314
+ ## API Reference
315
+
316
+ For detailed API documentation, please visit the [Narrative.io API Documentation](https://api.narrative.dev).
@@ -1,5 +1,5 @@
1
1
  import { BaseApi } from "../base-api";
2
- import type { ModelTrainingConfig, OutputModel, TrainModelRequest, TrainModelResponse } from "./types";
2
+ import type { ModelTrainingConfig, OutputModel, TrainClassifierRequest, TrainClassifierResponse, TrainModelRequest, TrainModelResponse } from "./types";
3
3
  /**
4
4
  * A class for accessing the Model Training API.
5
5
  * @extends BaseApi
@@ -12,5 +12,12 @@ declare class ModelTrainingApi extends BaseApi {
12
12
  * @returns {Promise<NqlQueryResponse>} A promise that resolves with the model training response.
13
13
  */
14
14
  trainModel(data: TrainModelRequest): Promise<TrainModelResponse>;
15
+ /**
16
+ * Trains a classifier model.
17
+ *
18
+ * @param {TrainClassifierRequest} data - The data for the classifier training.
19
+ * @returns {Promise<TrainClassifierResponse>} A promise that resolves with the classifier training response.
20
+ */
21
+ trainClassifier(data: TrainClassifierRequest): Promise<TrainClassifierResponse>;
15
22
  }
16
- export { ModelTrainingApi, type OutputModel, type TrainModelRequest, type TrainModelResponse, type ModelTrainingConfig, };
23
+ export { ModelTrainingApi, type OutputModel, type TrainModelRequest, type TrainModelResponse, type ModelTrainingConfig, type TrainClassifierRequest, type TrainClassifierResponse, };
@@ -20,5 +20,14 @@ class ModelTrainingApi extends BaseApi {
20
20
  async trainModel(data) {
21
21
  return await this.post(`${resourceName}/run`, data);
22
22
  }
23
+ /**
24
+ * Trains a classifier model.
25
+ *
26
+ * @param {TrainClassifierRequest} data - The data for the classifier training.
27
+ * @returns {Promise<TrainClassifierResponse>} A promise that resolves with the classifier training response.
28
+ */
29
+ async trainClassifier(data) {
30
+ return await this.post("train-classifier", data);
31
+ }
23
32
  }
24
33
  export { ModelTrainingApi, };
@@ -19,3 +19,11 @@ export interface ModelTrainingConfig {
19
19
  instance_type: string;
20
20
  custom_axolotl_config_override?: string;
21
21
  }
22
+ export interface TrainClassifierRequest {
23
+ config: Record<string, unknown>;
24
+ data_plane_id: string;
25
+ tags: string[];
26
+ }
27
+ export interface TrainClassifierResponse {
28
+ job_id: string;
29
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@narrative.io/data-collaboration-sdk-ts",
3
- "version": "2.58.1",
3
+ "version": "2.59.0",
4
4
  "main": "build/index.js",
5
5
  "repository": "github:narrative-io/data-collaboration-sdk-ts",
6
6
  "source": "src/index.ts",