1.7.1 • Published 9 months ago

@neurotic.cloud/sdk v1.7.1

Weekly downloads
-
License
ISC
Repository
-
Last release
9 months ago

Neurotic SDK

The Neurotic SDK provides a convenient way to interact with the Neurotic API, enabling actions, mutations, and queries. This README provides an overview of the SDK's usage and functionality.

Installation

To install the SDK, use npm or yarn:

npm install @neurotic.cloud/sdk

or

yarn add @neurotic.cloud/sdk

Usage

Import the necessary modules:

import { Mode, SDK } from '@neurotic.cloud/sdk';

Configuration

Create an instance of the SDK with your network, API key, and mode (optional):

const sdk = new SDK('network-identifier', 'your-api-key', Mode.Development); // Mode can be 'local', 'development', or 'production'

API Methods

Files

Interact with files in your system:

// Get all files with optional filters, sorting, and selection
const allFiles = await sdk.files().getAll({ filter: [['name', 'like', 'example%']] });

// Get a single file by its ID with optional selection
const file = await sdk.files().getOne(1, { select: ['id', 'name'] });

// Get a list of files with optional filters, sorting, and selection
const files = await sdk.files().getList(0, 100, { filter: [['name', 'like', 'example%']] });

// Get the first file from a list with optional filters, sorting, and selection
const firstFile = await sdk.files().getFirstOfList({ sort: 'created_at' });

// Upload a new file of type File
const uploadedFile = await sdk.files().create(file);

// Update an existing file
const updatedFile = await sdk.files().update(1, { name: 'newName.txt' });

// Delete a file
const deleteResponse = await sdk.files().delete(1);

Dataset

Interact with datasets and records:

// Define a dataset and its collection
const dataset = sdk.dataset('dataset-identifier').collection('collection-identifier');

// Get all records in the dataset with optional filters, sorting, expansion, and selection
const allRecords = await dataset.getAll({ filter: [['status', '=', 'active']], expand: ['relatedData'] });

// Get a single record by its ID with optional expansion and selection
const record = await dataset.getOne('record-id', { expand: ['relatedData'], select: ['id', 'name'] });

// Get a list of records with optional filters, sorting, expansion, and selection
const records = await dataset.getList(0, 100, { filter: [['status', '=', 'active']], sort: 'name', expand: ['relatedData'] });

// Get the first record from a list with optional filters, sorting, expansion, and selection
const firstRecord = await dataset.getFirstOfList({ sort: 'created_at', expand: ['relatedData'] });

// Create a new record
const newRecord = await dataset.create({ name: 'New Record', status: 'active' });

// Update an existing record
const updatedRecord = await dataset.update('record-id', { status: 'inactive' });

// Delete a record
const deleteRecordResponse = await dataset.delete('record-id');

Error Handling

The SDK includes error handling for network issues and API errors. If an error occurs, the error message will be logged to the console, and the response data will be returned.

Example:

try {
  const response = await sdk.files().getOne(1);
  console.log(response);
} catch (error) {
  console.error('An error occurred:', error);
}

Modes

The SDK operates in three different modes:

  • local: Interacts with a local instance.
  • development: Connects to the development server (dev.neurotic.cloud).
  • production: Connects to the production server (app.neurotic.cloud).

These modes help manage different environments and ensure that the correct API endpoints are used.

Contributing

If you'd like to contribute to the SDK, please fork the repository and use a feature branch. Pull requests are warmly welcome.

License

This project is licensed under the MIT License. See the LICENSE file for details.

1.7.1

9 months ago

1.7.0

9 months ago

1.6.2

9 months ago

1.6.1

9 months ago

1.6.0

9 months ago

1.5.0

9 months ago

1.4.2

10 months ago

1.4.1

10 months ago

1.4.0

10 months ago

1.3.2

10 months ago

1.3.1

10 months ago

1.3.0

10 months ago

1.2.6

11 months ago

1.2.5

11 months ago

1.2.4

11 months ago

1.2.3

11 months ago

1.2.2

11 months ago

1.2.1

11 months ago

1.2.0

11 months ago

1.1.5

12 months ago

1.1.4

12 months ago

1.1.3

12 months ago

1.1.1

12 months ago

1.1.0

12 months ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago