Merge pull request #3 from StevanFreeborn/fix/update-documentation
fix: update documentation
This commit is contained in:
@@ -52,6 +52,10 @@ jobs:
|
|||||||
TEST_SURVEY_ID: ${{ vars.TEST_SURVEY_ID }}
|
TEST_SURVEY_ID: ${{ vars.TEST_SURVEY_ID }}
|
||||||
TEST_SURVEY_RECORD_ID: ${{ vars.TEST_SURVEY_RECORD_ID }}
|
TEST_SURVEY_RECORD_ID: ${{ vars.TEST_SURVEY_RECORD_ID }}
|
||||||
TEST_TEXT_FIELD: ${{ vars.TEST_TEXT_FIELD }}
|
TEST_TEXT_FIELD: ${{ vars.TEST_TEXT_FIELD }}
|
||||||
|
- name: Upload coverage reports to Codecov
|
||||||
|
uses: codecov/codecov-action@v3
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.CODECOV_TOKEN }}
|
||||||
- name: Upload build artifact
|
- name: Upload build artifact
|
||||||
uses: actions/upload-artifact@v3.1.2
|
uses: actions/upload-artifact@v3.1.2
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -113,10 +113,24 @@ jobs:
|
|||||||
TEST_SURVEY_ID: ${{ vars.TEST_SURVEY_ID }}
|
TEST_SURVEY_ID: ${{ vars.TEST_SURVEY_ID }}
|
||||||
TEST_SURVEY_RECORD_ID: ${{ vars.TEST_SURVEY_RECORD_ID }}
|
TEST_SURVEY_RECORD_ID: ${{ vars.TEST_SURVEY_RECORD_ID }}
|
||||||
TEST_TEXT_FIELD: ${{ vars.TEST_TEXT_FIELD }}
|
TEST_TEXT_FIELD: ${{ vars.TEST_TEXT_FIELD }}
|
||||||
|
- name: Upload test coverage artifact
|
||||||
|
uses: actions/upload-artifact@v3.1.2
|
||||||
|
with:
|
||||||
|
name: coverage
|
||||||
|
path: ./coverage
|
||||||
publish_test_coverage:
|
publish_test_coverage:
|
||||||
needs: test
|
needs: test
|
||||||
name: publish_test_coverage
|
name: publish_test_coverage
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
- name: Check out repository
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Download test coverage artifact
|
||||||
|
uses: actions/download-artifact@v3.0.2
|
||||||
|
with:
|
||||||
|
name: coverage
|
||||||
|
path: ./coverage
|
||||||
- name: Upload coverage reports to Codecov
|
- name: Upload coverage reports to Codecov
|
||||||
uses: codecov/codecov-action@v3
|
uses: codecov/codecov-action@v3
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.CODECOV_TOKEN }}
|
||||||
|
|||||||
Regular → Executable
@@ -6,8 +6,18 @@
|
|||||||
"functions": 100,
|
"functions": 100,
|
||||||
"statements": 100,
|
"statements": 100,
|
||||||
"all": true,
|
"all": true,
|
||||||
"include": ["src/**/*.ts"],
|
"include": [
|
||||||
"exclude": ["src/index.ts", "**/*.spec.ts"],
|
"src/**/*.ts"
|
||||||
"reporter": ["html", "lcov", "text", "text-summary"],
|
],
|
||||||
|
"exclude": [
|
||||||
|
"src/index.ts",
|
||||||
|
"**/*.spec.ts"
|
||||||
|
],
|
||||||
|
"reporter": [
|
||||||
|
"html",
|
||||||
|
"lcov",
|
||||||
|
"text",
|
||||||
|
"text-summary"
|
||||||
|
],
|
||||||
"report-dir": "coverage"
|
"report-dir": "coverage"
|
||||||
}
|
}
|
||||||
@@ -4,5 +4,624 @@
|
|||||||
[](https://codecov.io/github/StevanFreeborn/onspring-api-sdk-javascript)
|
[](https://codecov.io/github/StevanFreeborn/onspring-api-sdk-javascript)
|
||||||
[](https://github.com/StevanFreeborn/onspring-api-sdk-javascript/actions/workflows/build_publish.yml)
|
[](https://github.com/StevanFreeborn/onspring-api-sdk-javascript/actions/workflows/build_publish.yml)
|
||||||
[](https://github.com/semantic-release/semantic-release)
|
[](https://github.com/semantic-release/semantic-release)
|
||||||
|
[](License.txt)
|
||||||
|

|
||||||
|
|
||||||
A javascript SDK for interacting with version 2 of the Onspring API.
|
The Javascript SDK for the Onspring API is meant to simplify development in Javascript for Onspring customers who want to build integrations with their Onspring instance.
|
||||||
|
|
||||||
|
**Note:** This is an unofficial SDK for the Onspring API. It was not built in consultation with Onspring Technologies LLC or a member of their development team.
|
||||||
|
|
||||||
|
This SDK was developed independently using Onspring's existing [C# SDK](https://github.com/onspring-technologies/onspring-api-sdk), the Onspring API's [swagger page](https://api.onspring.com/swagger/index.html), and [api documentation](https://software.onspring.com/hubfs/Training/Admin%20Guide%20-%20v2%20API.pdf) as the starting point with the intention of making development of integrations done in Javascript with an Onspring instance quicker and more convenient.
|
||||||
|
|
||||||
|
## 🛠️ Dependencies
|
||||||
|
|
||||||
|
### Node.js
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Requires use of [Node.js](https://nodejs.org/en/) 14.x or later.
|
||||||
|
|
||||||
|
### Axios
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
All methods for the `OnspringClient` make use of the [Axios](https://axios-http.com/) http client to interact with the Onspring API.
|
||||||
|
|
||||||
|
### Form-Data
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
When it is necessary to send requests to the Onspring API using `multi-part/form-data` the [Form-Data](https://www.npmjs.com/package/form-data) package is used.
|
||||||
|
|
||||||
|
## 💾 Installation
|
||||||
|
|
||||||
|
Install the SDK using [npm](https://www.npmjs.com/):
|
||||||
|
|
||||||
|
`npm install onspring-api-sdk`
|
||||||
|
|
||||||
|
## 🔑 API Key
|
||||||
|
|
||||||
|
In order to successfully interact with the Onspring Api you will need an API key. API keys are obtained by an Onspring user with permissions to at least **Read** API Keys for your instance via the following steps:
|
||||||
|
|
||||||
|
1. Login to the Onspring instance.
|
||||||
|
2. Navigate to **Administration** > **Security** > **API Keys**
|
||||||
|
3. On the list page, add a new API Key - this will require **Create** permissions - or click an existing API key to view its details.
|
||||||
|
4. Click on the **Developer Information** tab.
|
||||||
|
5. Copy the **X-ApiKey Header** value from this tab.
|
||||||
|
|
||||||
|
**Important:**
|
||||||
|
|
||||||
|
- An API Key must have a status of `Enabled` in order to make authorized requests.
|
||||||
|
- Each API Key must have an assigned Role. This role controls the permissions for requests made. If the API Key used does not have sufficient permissions the requests made won't be successful.
|
||||||
|
|
||||||
|
### 🔒 Permission Considerations
|
||||||
|
|
||||||
|
You can think of any API Key as another user in your Onspring instance and therefore it is subject to all the same permission considerations as any other user when it comes to its ability to access data in your instance. The API Key you use needs to have all the correct permissions within your instance to access the data requested. Things to think about in this context are `role security`, `content security`, and `field security`.
|
||||||
|
|
||||||
|
## 🧑🏻💻 Start Coding
|
||||||
|
|
||||||
|
### `OnspringClient`
|
||||||
|
|
||||||
|
The most common way to use the SDK is to create an `OnspringClient` instance and call its methods. Its constructor requires two parameters:
|
||||||
|
|
||||||
|
- `baseUrl` - currently this should always be: `https://api.onspring.com`
|
||||||
|
- `apiKey` - the value obtained by following the steps in the **API Key** section
|
||||||
|
|
||||||
|
It is best practice to read these values in from a configuration file for both flexibility and security purposes.
|
||||||
|
|
||||||
|
Example `.env` file:
|
||||||
|
|
||||||
|
```env
|
||||||
|
API_KEY=000000ffffff000000ffffff/00000000-ffff-0000-ffff-000000000000
|
||||||
|
BASE_URL=https://api.onspring.com
|
||||||
|
```
|
||||||
|
|
||||||
|
Example constructing `OnspringClient`:
|
||||||
|
|
||||||
|
`CommonJS`
|
||||||
|
|
||||||
|
```js
|
||||||
|
const { OnspringClient } = require('onspring-api-sdk');
|
||||||
|
const dotenv = require('dotenv');
|
||||||
|
dotenv.config();
|
||||||
|
|
||||||
|
const client = new OnspringClient(process.env.BASE_URL, process.env.API_KEY);
|
||||||
|
```
|
||||||
|
|
||||||
|
`ES Module`
|
||||||
|
|
||||||
|
```js
|
||||||
|
import dotenv from 'dotenv';
|
||||||
|
import { OnspringClient } from 'onspring-api-sdk';
|
||||||
|
dotenv.config();
|
||||||
|
|
||||||
|
const client = new OnspringClient(process.env.BASE_URL, process.env.API_KEY);
|
||||||
|
```
|
||||||
|
|
||||||
|
### `Axios` Instance Configuration
|
||||||
|
|
||||||
|
By default when you construct an instance of the `OnspringClient` the a new `Axios` instance will also be created. Its `baseURL` property will always be set to the `baseUrl` parameter based to the `OnspringClient`'s constructor and its headers will always contain the proper `x-api-key` header.
|
||||||
|
|
||||||
|
You can though pass a third optional argument to the `OnspringClient` constructor that specifies additional configuration options for the `Axios` instance used to make requests.
|
||||||
|
|
||||||
|
```js
|
||||||
|
import dotenv from 'dotenv';
|
||||||
|
import { OnspringClient } from 'onspring-api-sdk';
|
||||||
|
dotenv.config();
|
||||||
|
|
||||||
|
const configs = {
|
||||||
|
timeout: 5000,
|
||||||
|
};
|
||||||
|
|
||||||
|
const client = new OnspringClient(
|
||||||
|
process.env.BASE_URL,
|
||||||
|
process.env.API_KEY,
|
||||||
|
configs
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
### `ApiResponse`
|
||||||
|
|
||||||
|
Each `OnspringClient` method - aside from `canConnect` - returns an `ApiResponse` object which will have the following properties:
|
||||||
|
|
||||||
|
- `statusCode` - The http status code of the response.
|
||||||
|
- `isSuccessful` - Indicates whether the request succeeded.
|
||||||
|
- `data` - If the request was successful will contain the response data deserialized to custom classes.
|
||||||
|
- `message` - A message that may provide more detail about the request when no successful
|
||||||
|
|
||||||
|
### CommonJS or ES Modules
|
||||||
|
|
||||||
|
There is support for using either CommonJS or ES Modules depending upon your preference. This documentation will use the later in the usage examples.
|
||||||
|
|
||||||
|
### Types
|
||||||
|
|
||||||
|
The package is written in typescript and all types are exported and available for you to use.
|
||||||
|
|
||||||
|
### Full API Documentation
|
||||||
|
|
||||||
|
You may wish to refer to the full [Onspring API documentation](https://software.onspring.com/hubfs/Training/Admin%20Guide%20-%20v2%20API.pdf) when determining which values to pass as parameters to some of the `OnspringClient` methods. There is also a [swagger page](https://api.onspring.com/swagger/index.html) that you can use for making exploratory requests.
|
||||||
|
|
||||||
|
## 📋 Examples
|
||||||
|
|
||||||
|
Note the following code snippets assume you've already instantiated an `OnspringClient` as shown in the [OnspringClient](#onspringclient) section.
|
||||||
|
|
||||||
|
### Connectivity
|
||||||
|
|
||||||
|
#### Verify connectivity
|
||||||
|
|
||||||
|
```js
|
||||||
|
const res = await client.canConnect();
|
||||||
|
console.log(res); // true or false
|
||||||
|
```
|
||||||
|
|
||||||
|
### Apps
|
||||||
|
|
||||||
|
#### Get Apps
|
||||||
|
|
||||||
|
Returns a paged collection of apps and/or surveys that can be paged through. By default the page size is 50 and page number is 1.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const res = await client.getApps();
|
||||||
|
const apps = res.data.items;
|
||||||
|
|
||||||
|
for (const app of apps) {
|
||||||
|
console.log(app);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
You can set your own page size and page number (max is 1,000) as well.
|
||||||
|
|
||||||
|
```js
|
||||||
|
import { PagingRequest } from 'onspring-api-sdk';
|
||||||
|
|
||||||
|
const res = await client.getApps(new PagingRequest(1, 1));
|
||||||
|
const apps = res.data.items;
|
||||||
|
|
||||||
|
for (const app of apps) {
|
||||||
|
console.log(app);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Get App By Id
|
||||||
|
|
||||||
|
Returns an Onspring app or survey according to provided id.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const res = await client.getAppById(130);
|
||||||
|
const app = res.data;
|
||||||
|
|
||||||
|
console.log(app);
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Get Apps By Ids
|
||||||
|
|
||||||
|
Returns a collection of Onspring apps and/or surveys according to provided ids.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const res = await client.getAppsByIds([130, 131]);
|
||||||
|
const apps = res.data.items;
|
||||||
|
|
||||||
|
for (const app of apps) {
|
||||||
|
console.log(app);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Fields
|
||||||
|
|
||||||
|
#### Get Field By Id
|
||||||
|
|
||||||
|
Returns an Onspring field according to provided id.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const res = await client.getFieldById(4793);
|
||||||
|
const field = res.data;
|
||||||
|
|
||||||
|
console.log(field);
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Get Fields By Ids
|
||||||
|
|
||||||
|
Returns a collection of Onspring fields according to provided ids.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const res = await client.getFieldsByIds([4793, 4801]);
|
||||||
|
const fields = res.data.items;
|
||||||
|
|
||||||
|
for (const field of fields) {
|
||||||
|
console.log(field);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Get Fields By App Id
|
||||||
|
|
||||||
|
Returns a paged collection of fields that can be paged through. By default the page size is 50 and page number is 1.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const res = await client.getFieldsByAppId(132);
|
||||||
|
const fields = res.data.items;
|
||||||
|
|
||||||
|
for (const field of fields) {
|
||||||
|
console.log(field);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
You can set your own page size and page number (max is 1,000) as well.
|
||||||
|
|
||||||
|
```js
|
||||||
|
import { PagingRequest } from 'onspring-api-sdk';
|
||||||
|
|
||||||
|
const res = await client.getFieldsByAppId(132, new PagingRequest(1, 1));
|
||||||
|
const fields = res.data.items;
|
||||||
|
|
||||||
|
for (const field of fields) {
|
||||||
|
console.log(field);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Files
|
||||||
|
|
||||||
|
#### Get File Info By Id
|
||||||
|
|
||||||
|
Returns the Onspring file's metadata.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const res = await client.getFileInfoById(1, 4806, 909);
|
||||||
|
const fileInfo = res.data;
|
||||||
|
|
||||||
|
console.log(fileInfo);
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Get File By Id
|
||||||
|
|
||||||
|
Returns the file itself.
|
||||||
|
|
||||||
|
```js
|
||||||
|
import fs from 'fs';
|
||||||
|
|
||||||
|
const res = await client.getFileById(1, 4806, 909);
|
||||||
|
const file = res.data;
|
||||||
|
|
||||||
|
console.log(file.contentLength);
|
||||||
|
console.log(file.contentType);
|
||||||
|
console.log(file.fileName);
|
||||||
|
file.stream.pipe(fs.createWriteStream(file.fileName));
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Save File
|
||||||
|
|
||||||
|
```js
|
||||||
|
import fs from 'fs';
|
||||||
|
import { SaveFileRequest } from 'onspring-api-sdk';
|
||||||
|
|
||||||
|
const request = new SaveFileRequest(
|
||||||
|
1,
|
||||||
|
4806,
|
||||||
|
'notes',
|
||||||
|
new Date(),
|
||||||
|
'test-attachment.txt',
|
||||||
|
'text/plain',
|
||||||
|
fs.createReadStream('test-attachment.txt')
|
||||||
|
);
|
||||||
|
|
||||||
|
const res = await client.saveFile(request);
|
||||||
|
const fileId = res.data.id;
|
||||||
|
|
||||||
|
console.log(fileId);
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Delete File By Id
|
||||||
|
|
||||||
|
```js
|
||||||
|
const res = await client.deleteFileById(1, 4806, 1505);
|
||||||
|
|
||||||
|
res.statusCode === 204
|
||||||
|
? console.log('File deleted')
|
||||||
|
: console.log('Error deleting file');
|
||||||
|
```
|
||||||
|
|
||||||
|
### Lists
|
||||||
|
|
||||||
|
#### Add Or Update List Value
|
||||||
|
|
||||||
|
To add a list value don't provide an id value.
|
||||||
|
|
||||||
|
```js
|
||||||
|
import { ListItemRequest } from 'onspring-api-sdk';
|
||||||
|
|
||||||
|
const request = new ListItemRequest(638, null, 'New Value', 1, '#000000');
|
||||||
|
const res = await client.addOrUpdateListItem(request);
|
||||||
|
const itemId = res.data.id;
|
||||||
|
|
||||||
|
console.log(itemId);
|
||||||
|
```
|
||||||
|
|
||||||
|
To update a list value provide an id value.
|
||||||
|
|
||||||
|
```js
|
||||||
|
import { ListItemRequest } from 'onspring-api-sdk';
|
||||||
|
|
||||||
|
const request = new ListItemRequest(
|
||||||
|
638,
|
||||||
|
'35c79a46-04b8-4069-bbc1-161a175f962c',
|
||||||
|
'Updated Value',
|
||||||
|
1,
|
||||||
|
'#000000'
|
||||||
|
);
|
||||||
|
|
||||||
|
const res = await client.addOrUpdateListItem(request);
|
||||||
|
const itemId = res.data.id;
|
||||||
|
|
||||||
|
console.log(itemId);
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Delete List Value
|
||||||
|
|
||||||
|
```js
|
||||||
|
const res = await client.deleteListItemById(
|
||||||
|
638,
|
||||||
|
'35c79a46-04b8-4069-bbc1-161a175f962c'
|
||||||
|
);
|
||||||
|
|
||||||
|
res.statusCode === 204
|
||||||
|
? console.log('List item deleted')
|
||||||
|
: console.log('Error deleting list item');
|
||||||
|
```
|
||||||
|
|
||||||
|
### Records
|
||||||
|
|
||||||
|
#### Get Records By App Id
|
||||||
|
|
||||||
|
Returns a paged collection of records that can be paged through. By default the page size is 50 and page number is 1.
|
||||||
|
|
||||||
|
```js
|
||||||
|
import { GetRecordsByAppIdRequest } from 'onspring-api-sdk';
|
||||||
|
|
||||||
|
const request = new GetRecordsByAppIdRequest(130);
|
||||||
|
const res = await client.getRecordsByAppId(request);
|
||||||
|
const apps = res.data.items;
|
||||||
|
|
||||||
|
for (const app of apps) {
|
||||||
|
console.log(app);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
You can set your own page size and page number (max is 1,000) as well. In addition to specifying what field values to return and in what format (Raw vs. Formatted) to return them.
|
||||||
|
|
||||||
|
```js
|
||||||
|
import {
|
||||||
|
DataFormat,
|
||||||
|
GetRecordsByAppIdRequest,
|
||||||
|
PagingRequest,
|
||||||
|
} from 'onspring-api-sdk';
|
||||||
|
|
||||||
|
const request = new GetRecordsByAppIdRequest(
|
||||||
|
130,
|
||||||
|
[4804],
|
||||||
|
DataFormat.Raw,
|
||||||
|
new PagingRequest(1, 1)
|
||||||
|
);
|
||||||
|
|
||||||
|
const res = await client.getRecordsByAppId(request);
|
||||||
|
const apps = res.data.items;
|
||||||
|
|
||||||
|
for (const app of apps) {
|
||||||
|
console.log(app);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Get Record By Id
|
||||||
|
|
||||||
|
Returns an onspring record based on the provided app and record ids.
|
||||||
|
|
||||||
|
```js
|
||||||
|
import { GetRecordRequest } from 'onspring-api-sdk';
|
||||||
|
|
||||||
|
const request = new GetRecordRequest(130, 1);
|
||||||
|
const res = await client.getRecordById(request);
|
||||||
|
const record = res.data;
|
||||||
|
|
||||||
|
console.log(record);
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also specify what field values to return and in what format (Raw vs. Formatted) to return them.
|
||||||
|
|
||||||
|
```js
|
||||||
|
import { DataFormat, GetRecordRequest } from 'onspring-api-sdk';
|
||||||
|
|
||||||
|
const request = new GetRecordRequest(130, 1, [4804], DataFormat.Raw);
|
||||||
|
const res = await client.getRecordById(request);
|
||||||
|
const record = res.data;
|
||||||
|
|
||||||
|
console.log(record);
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Get Records By Ids
|
||||||
|
|
||||||
|
Returns a collection of Onspring records based on the provided appId and recordIds.
|
||||||
|
|
||||||
|
```js
|
||||||
|
import { GetRecordsRequest } from 'onspring-api-sdk';
|
||||||
|
|
||||||
|
const request = new GetRecordsRequest(130, [1]);
|
||||||
|
const res = await client.getRecordsByIds(request);
|
||||||
|
const records = res.data.items;
|
||||||
|
|
||||||
|
for (const record of records) {
|
||||||
|
console.log(record);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also specify what field values to return and in what format (Raw vs. Formatted) to return them.
|
||||||
|
|
||||||
|
```js
|
||||||
|
import { DataFormat, GetRecordsRequest } from 'onspring-api-sdk';
|
||||||
|
|
||||||
|
const request = new GetRecordsRequest(130, [1], [4804], DataFormat.Formatted);
|
||||||
|
const res = await client.getRecordsByIds(request);
|
||||||
|
const records = res.data.items;
|
||||||
|
|
||||||
|
for (const record of records) {
|
||||||
|
console.log(record);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Query Records
|
||||||
|
|
||||||
|
Returns a paged collection of records based on a criteria that can be paged through. By default the page size is 50 and page number is 1.
|
||||||
|
|
||||||
|
```js
|
||||||
|
import {
|
||||||
|
FilterOperators,
|
||||||
|
QueryFilter,
|
||||||
|
QueryRecordsRequest,
|
||||||
|
} from 'onspring-api-sdk';
|
||||||
|
|
||||||
|
const filter = new QueryFilter(4745, FilterOperators.GreaterThan, 0);
|
||||||
|
const request = new QueryRecordsRequest(130, filter);
|
||||||
|
const res = await client.queryRecords(request);
|
||||||
|
const records = res.data.items;
|
||||||
|
|
||||||
|
for (const record of records) {
|
||||||
|
console.log(record);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
You can set your own page size and page number (max is 1,000) as well. In addition to specifying what field values to return and in what format (Raw vs. Formatted) to return them.
|
||||||
|
|
||||||
|
```js
|
||||||
|
import {
|
||||||
|
DataFormat,
|
||||||
|
FilterOperators,
|
||||||
|
PagingRequest,
|
||||||
|
QueryFilter,
|
||||||
|
QueryRecordsRequest,
|
||||||
|
} from 'onspring-api-sdk';
|
||||||
|
|
||||||
|
const filter = new QueryFilter(4745, FilterOperators.GreaterThan, 0);
|
||||||
|
const request = new QueryRecordsRequest(
|
||||||
|
130,
|
||||||
|
filter,
|
||||||
|
[4804],
|
||||||
|
DataFormat.Formatted,
|
||||||
|
new PagingRequest(1, 1)
|
||||||
|
);
|
||||||
|
|
||||||
|
const res = await client.queryRecords(request);
|
||||||
|
const records = res.data.items;
|
||||||
|
|
||||||
|
for (const record of records) {
|
||||||
|
console.log(record);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
For further details on constructing the `filter` parameter please refer to the [documentation](https://software.onspring.com/hubfs/Training/Admin%20Guide%20-%20v2%20API.pdf) for the Onspring API.
|
||||||
|
|
||||||
|
#### Add or Update A Record
|
||||||
|
|
||||||
|
You can add a record by not providing a record id value. If successful will return the id of the added record.
|
||||||
|
|
||||||
|
```js
|
||||||
|
import { Record, StringRecordValue } from 'onspring-api-sdk';
|
||||||
|
|
||||||
|
const record = new Record(130, null);
|
||||||
|
const fieldValue = new StringRecordValue(4804, 'Test');
|
||||||
|
record.addValue(fieldValue);
|
||||||
|
|
||||||
|
const res = await client.saveRecord(record);
|
||||||
|
const newRecordId = res.data.id;
|
||||||
|
|
||||||
|
console.log(newRecordId);
|
||||||
|
```
|
||||||
|
|
||||||
|
You can update a record by providing its id. If successful will return the id of record updated.
|
||||||
|
|
||||||
|
```js
|
||||||
|
import { Record, StringRecordValue } from 'onspring-api-sdk';
|
||||||
|
|
||||||
|
const record = new Record(130, 607);
|
||||||
|
const fieldValue = new StringRecordValue(4804, 'Updated');
|
||||||
|
record.addValue(fieldValue);
|
||||||
|
|
||||||
|
const res = await client.saveRecord(record);
|
||||||
|
const updatedRecordId = res.data.id;
|
||||||
|
|
||||||
|
console.log(updatedRecordId);
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Delete Record By Id
|
||||||
|
|
||||||
|
Delete an individual record based upon its id.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const res = await client.deleteRecordById(130, 607);
|
||||||
|
|
||||||
|
res.statusCode === 204
|
||||||
|
? console.log('Record deleted')
|
||||||
|
: console.log('Error deleting record');
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Delete Records By Ids
|
||||||
|
|
||||||
|
Delete a batch of records based upon their ids.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const res = await client.deleteRecordsByIds(130, [608, 609]);
|
||||||
|
|
||||||
|
res.statusCode === 204
|
||||||
|
? console.log('Records deleted')
|
||||||
|
: console.log('Error deleting records');
|
||||||
|
```
|
||||||
|
|
||||||
|
### Reports
|
||||||
|
|
||||||
|
#### Get Report By Id
|
||||||
|
|
||||||
|
Returns the report for the provided id.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const res = await client.getReportById(408);
|
||||||
|
const report = res.data;
|
||||||
|
|
||||||
|
console.log(report);
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also specify the format of the data in the report as well as whether you are requesting the report's data or its chart data.
|
||||||
|
|
||||||
|
```js
|
||||||
|
import { DataFormat, ReportDataType } from 'onspring-api-sdk';
|
||||||
|
|
||||||
|
const res = await client.getReportById(
|
||||||
|
409,
|
||||||
|
DataFormat.Formatted,
|
||||||
|
ReportDataType.ChartData
|
||||||
|
);
|
||||||
|
const report = res.data;
|
||||||
|
|
||||||
|
console.log(report);
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Get Reports By App Id
|
||||||
|
|
||||||
|
Returns a paged collection of reports that can be paged through. By default the page size is 50 and page number is 1.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const res = await client.getReportsByAppId(130);
|
||||||
|
const reports = res.data.items;
|
||||||
|
|
||||||
|
for (const report of reports) {
|
||||||
|
console.log(report);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
You can set your own page size and page number (max is 1,000) as well.
|
||||||
|
|
||||||
|
```js
|
||||||
|
import { PagingRequest } from 'onspring-api-sdk';
|
||||||
|
|
||||||
|
const res = await client.getReportsByAppId(130, new PagingRequest(1, 1));
|
||||||
|
const reports = res.data.items;
|
||||||
|
|
||||||
|
for (const report of reports) {
|
||||||
|
console.log(report);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|||||||
+1
-1
@@ -48,7 +48,7 @@
|
|||||||
"lint-fix": "eslint --fix --ignore-path .eslintignore --ext .js,.ts . --max-warnings=0",
|
"lint-fix": "eslint --fix --ignore-path .eslintignore --ext .js,.ts . --max-warnings=0",
|
||||||
"format-staged": "pretty-quick --staged",
|
"format-staged": "pretty-quick --staged",
|
||||||
"format": "pretty-quick",
|
"format": "pretty-quick",
|
||||||
"build": "npm run tests && npm run clean && tsc --project tsconfig.cjs.json && tsc --project tsconfig.esm.json && node ./scripts/create_dist_package_json.js",
|
"build": "npm run test-coverage:ci && npm run clean && tsc --project tsconfig.cjs.json && tsc --project tsconfig.esm.json && node ./scripts/create_dist_package_json.js",
|
||||||
"test:unit": "mocha -r ts-node/register",
|
"test:unit": "mocha -r ts-node/register",
|
||||||
"test:integration": "mocha -r ts-node/register -r integrationTests/mochaRootHooks.ts",
|
"test:integration": "mocha -r ts-node/register -r integrationTests/mochaRootHooks.ts",
|
||||||
"tests:unit": "mocha -R progress -r ts-node/register ./tests/**/*.spec.ts",
|
"tests:unit": "mocha -R progress -r ts-node/register ./tests/**/*.spec.ts",
|
||||||
|
|||||||
@@ -1,4 +1,16 @@
|
|||||||
|
/**
|
||||||
|
* @enum DelegateType - The type of delegate
|
||||||
|
*/
|
||||||
export enum DelegateType {
|
export enum DelegateType {
|
||||||
|
/**
|
||||||
|
* @constant External - The delegate is external.
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
External = 'External',
|
External = 'External',
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @constant Internal - The delegate is internal.
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
Internal = 'Internal',
|
Internal = 'Internal',
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
/**
|
||||||
|
* @enum FileStorageSite - The site where the file is stored.
|
||||||
|
*/
|
||||||
export enum FileStorageSite {
|
export enum FileStorageSite {
|
||||||
/**
|
/**
|
||||||
* @constant Internal - The file is stored in the internal file storage.
|
* @constant Internal - The file is stored in the internal file storage.
|
||||||
|
|||||||
@@ -4,60 +4,70 @@
|
|||||||
export enum FilterOperators {
|
export enum FilterOperators {
|
||||||
/**
|
/**
|
||||||
* @constant Equal - The equal operator
|
* @constant Equal - The equal operator
|
||||||
|
* @type {string}
|
||||||
* @remarks Can be used with text, auto-number, date, and number fields as well as their formula equivalents.
|
* @remarks Can be used with text, auto-number, date, and number fields as well as their formula equivalents.
|
||||||
*/
|
*/
|
||||||
Equal = 'eq',
|
Equal = 'eq',
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant NotEqual - The not equal operator
|
* @constant NotEqual - The not equal operator
|
||||||
|
* @type {string}
|
||||||
* @remarks Can be used with text, auto-number, date, and number fields as well as their formula equivalents.
|
* @remarks Can be used with text, auto-number, date, and number fields as well as their formula equivalents.
|
||||||
*/
|
*/
|
||||||
NotEqual = 'ne',
|
NotEqual = 'ne',
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant Contains - The contains operator
|
* @constant Contains - The contains operator
|
||||||
|
* @type {string}
|
||||||
* @remarks Can be used with list fields as well as their formula equivalents.
|
* @remarks Can be used with list fields as well as their formula equivalents.
|
||||||
*/
|
*/
|
||||||
Contains = 'contains',
|
Contains = 'contains',
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant IsNull - The is null operator
|
* @constant IsNull - The is null operator
|
||||||
|
* @type {string}
|
||||||
* @remarks Can be used with text, date, and number fields as well as their formula equivalents.
|
* @remarks Can be used with text, date, and number fields as well as their formula equivalents.
|
||||||
*/
|
*/
|
||||||
IsNull = 'isnull',
|
IsNull = 'isnull',
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant NotNull - The not null operator
|
* @constant NotNull - The not null operator
|
||||||
|
* @type {string}
|
||||||
* @remarks Can be used with text, date, and number fields as well as their formula equivalents.
|
* @remarks Can be used with text, date, and number fields as well as their formula equivalents.
|
||||||
*/
|
*/
|
||||||
NotNull = 'notnull',
|
NotNull = 'notnull',
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant GreaterThan - The greater than operator
|
* @constant GreaterThan - The greater than operator
|
||||||
|
* @type {string}
|
||||||
* @remarks Can be used with auto-number, date, and number fields as well as their formula equivalents.
|
* @remarks Can be used with auto-number, date, and number fields as well as their formula equivalents.
|
||||||
*/
|
*/
|
||||||
GreaterThan = 'gt',
|
GreaterThan = 'gt',
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant LessThan - The less than operator
|
* @constant LessThan - The less than operator
|
||||||
|
* @type {string}
|
||||||
* @remarks Can be used with auto-number, date, and number fields as well as their formula equivalents.
|
* @remarks Can be used with auto-number, date, and number fields as well as their formula equivalents.
|
||||||
*/
|
*/
|
||||||
LessThan = 'lt',
|
LessThan = 'lt',
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant And - The and operator
|
* @constant And - The and operator
|
||||||
|
* @type {string}
|
||||||
* @remarks Can be used to create compound filters.
|
* @remarks Can be used to create compound filters.
|
||||||
*/
|
*/
|
||||||
And = 'and',
|
And = 'and',
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant Or - The or operator
|
* @constant Or - The or operator
|
||||||
|
* @type {string}
|
||||||
* @remarks Can be used to create compound filters.
|
* @remarks Can be used to create compound filters.
|
||||||
*/
|
*/
|
||||||
Or = 'or',
|
Or = 'or',
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant Not - The not operator
|
* @constant Not - The not operator
|
||||||
|
* @type {string}
|
||||||
* @remarks Can be used to negate a filter and create compound filters.
|
* @remarks Can be used to negate a filter and create compound filters.
|
||||||
*/
|
*/
|
||||||
Not = 'not',
|
Not = 'not',
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
/**
|
||||||
|
* @enum FormulaOutputType - The type of the formula output.
|
||||||
|
*/
|
||||||
export enum FormulaOutputType {
|
export enum FormulaOutputType {
|
||||||
/**
|
/**
|
||||||
* @constant Text - The formula output is a text value.
|
* @constant Text - The formula output is a text value.
|
||||||
|
|||||||
@@ -238,6 +238,10 @@ export class ApiResponse<T> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method asFileInfoType - Converts the ApiResponse to an ApiResponse<FileInfo>.
|
||||||
|
* @returns {ApiResponse<FileInfo>} - An ApiResponse<FileInfo>.
|
||||||
|
*/
|
||||||
public asFileInfoType(): ApiResponse<FileInfo> {
|
public asFileInfoType(): ApiResponse<FileInfo> {
|
||||||
const apiResponse = this as ApiResponse<any>;
|
const apiResponse = this as ApiResponse<any>;
|
||||||
|
|
||||||
@@ -259,6 +263,10 @@ export class ApiResponse<T> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method asFileType - Converts the ApiResponse to an ApiResponse<File>.
|
||||||
|
* @returns {ApiResponse<File>} - An ApiResponse<File>.
|
||||||
|
*/
|
||||||
public asFileType(response: AxiosResponse): ApiResponse<File> {
|
public asFileType(response: AxiosResponse): ApiResponse<File> {
|
||||||
const apiResponse = this as ApiResponse<any>;
|
const apiResponse = this as ApiResponse<any>;
|
||||||
const fileName = response.headers['content-disposition']
|
const fileName = response.headers['content-disposition']
|
||||||
@@ -408,6 +416,10 @@ export class ApiResponse<T> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method asRecordCollectionType - Converts the ApiResponse to an ApiResponse<CollectionResponse<Record>>.
|
||||||
|
* @returns {ApiResponse<CollectionResponse<Record>>} - An ApiResponse<CollectionResponse<Record>>.
|
||||||
|
*/
|
||||||
public asRecordCollectionType(): ApiResponse<CollectionResponse<Record>> {
|
public asRecordCollectionType(): ApiResponse<CollectionResponse<Record>> {
|
||||||
const apiResponse = this as ApiResponse<any>;
|
const apiResponse = this as ApiResponse<any>;
|
||||||
|
|
||||||
@@ -431,6 +443,10 @@ export class ApiResponse<T> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method asSaveRecordResponseType - Converts the ApiResponse to an ApiResponse<SaveRecordResponse>.
|
||||||
|
* @returns {ApiResponse<SaveRecordResponse>} - An ApiResponse<SaveRecordResponse>.
|
||||||
|
*/
|
||||||
public asSaveRecordResponseType(): ApiResponse<SaveRecordResponse> {
|
public asSaveRecordResponseType(): ApiResponse<SaveRecordResponse> {
|
||||||
const apiResponse = this as ApiResponse<any>;
|
const apiResponse = this as ApiResponse<any>;
|
||||||
const response = new SaveRecordResponse(
|
const response = new SaveRecordResponse(
|
||||||
@@ -444,6 +460,11 @@ export class ApiResponse<T> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method getRecordValueByType - Gets the RecordValue by by type.
|
||||||
|
* @param {RecordValue} recordValueItem - The record value item.
|
||||||
|
* @returns {RecordValue} - The RecordValue.
|
||||||
|
*/
|
||||||
private static getRecordValueByType(recordValueItem: any): RecordValue<any> {
|
private static getRecordValueByType(recordValueItem: any): RecordValue<any> {
|
||||||
const type = RecordValueType[recordValueItem.type];
|
const type = RecordValueType[recordValueItem.type];
|
||||||
|
|
||||||
@@ -626,6 +647,11 @@ export class ApiResponse<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method convertToDelegate - Converts the delegate item to a Delegate object.
|
||||||
|
* @param {any} delegateItem - The delegate item to convert.
|
||||||
|
* @returns {Delegate} - The converted Delegate object.
|
||||||
|
*/
|
||||||
private static convertToDelegate(delegateItem: any): Delegate {
|
private static convertToDelegate(delegateItem: any): Delegate {
|
||||||
const delegateType = DelegateType[delegateItem.delegateType];
|
const delegateType = DelegateType[delegateItem.delegateType];
|
||||||
|
|
||||||
@@ -712,7 +738,7 @@ export class ApiResponse<T> {
|
|||||||
const hasRecurrence =
|
const hasRecurrence =
|
||||||
timeSpanItem.recurrence !== null && timeSpanItem.recurrence !== undefined;
|
timeSpanItem.recurrence !== null && timeSpanItem.recurrence !== undefined;
|
||||||
|
|
||||||
const recurrene = hasRecurrence
|
const recurrence = hasRecurrence
|
||||||
? TimeSpanRecurrenceType[timeSpanItem.recurrence]
|
? TimeSpanRecurrenceType[timeSpanItem.recurrence]
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
@@ -735,7 +761,7 @@ export class ApiResponse<T> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (recurrene === undefined) {
|
if (recurrence === undefined) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`${
|
`${
|
||||||
timeSpanItem.recurrence as string
|
timeSpanItem.recurrence as string
|
||||||
@@ -746,7 +772,7 @@ export class ApiResponse<T> {
|
|||||||
return new TimeSpanData(
|
return new TimeSpanData(
|
||||||
timeSpanItem.quantity,
|
timeSpanItem.quantity,
|
||||||
increment,
|
increment,
|
||||||
recurrene,
|
recurrence,
|
||||||
endAfterOccurrences,
|
endAfterOccurrences,
|
||||||
endByDate
|
endByDate
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -60,7 +60,9 @@ export class ApiResponseFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @method getStreamDataAsString - Gets the data from a stream as a string
|
||||||
|
* @param {Readable} stream - The stream that will be used to get the data
|
||||||
|
* @returns {Promise<string>} - A promise that resolves to the data from the stream as a string
|
||||||
*/
|
*/
|
||||||
private static async getStreamDataAsString(
|
private static async getStreamDataAsString(
|
||||||
stream: Readable
|
stream: Readable
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
/**
|
||||||
|
* @class CreatedWithIdResponse<T> - Represents a response to a request to create a resource.
|
||||||
|
*/
|
||||||
export class CreatedWithIdResponse<T> {
|
export class CreatedWithIdResponse<T> {
|
||||||
/**
|
/**
|
||||||
* @property {T} id - The id of the created object.
|
* @property {T} id - The id of the created object.
|
||||||
|
|||||||
@@ -1,7 +1,16 @@
|
|||||||
import { RecordValue } from './RecordValue.js';
|
import { RecordValue } from './RecordValue.js';
|
||||||
import { RecordValueType } from '../enums/RecordValueType.js';
|
import { RecordValueType } from '../enums/RecordValueType.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class DecimalRecordValue - Represents a decimal record value
|
||||||
|
*/
|
||||||
export class DecimalRecordValue extends RecordValue<number> {
|
export class DecimalRecordValue extends RecordValue<number> {
|
||||||
|
/**
|
||||||
|
* @constructor - Creates a new instance of DecimalRecordValue
|
||||||
|
* @param {number} fieldId - The id of the field
|
||||||
|
* @param {number} value - The value of the field
|
||||||
|
* @returns {DecimalRecordValue} - A new instance of DecimalRecordValue
|
||||||
|
*/
|
||||||
constructor(fieldId: number, value: number) {
|
constructor(fieldId: number, value: number) {
|
||||||
super(RecordValueType.Decimal, fieldId, value);
|
super(RecordValueType.Decimal, fieldId, value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,16 @@ import { RecordValueType } from '../enums/RecordValueType.js';
|
|||||||
import { type Delegate } from './Delegate.js';
|
import { type Delegate } from './Delegate.js';
|
||||||
import { RecordValue } from './RecordValue.js';
|
import { RecordValue } from './RecordValue.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class DelegateListRecordValue - Represents a delegate list record value.
|
||||||
|
*/
|
||||||
export class DelegateListRecordValue extends RecordValue<Delegate[]> {
|
export class DelegateListRecordValue extends RecordValue<Delegate[]> {
|
||||||
|
/**
|
||||||
|
* @constructor - Creates a new instance of DelegateListRecordValue.
|
||||||
|
* @param {number} fieldId - The id of the field.
|
||||||
|
* @param {Delegate[]} value - The value of the field.
|
||||||
|
* @returns {DelegateListRecordValue} - A new instance of DelegateListRecordValue.
|
||||||
|
*/
|
||||||
constructor(fieldId: number, value: Delegate[]) {
|
constructor(fieldId: number, value: Delegate[]) {
|
||||||
super(RecordValueType.DelegateList, fieldId, value);
|
super(RecordValueType.DelegateList, fieldId, value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,16 @@ import { RecordValueType } from '../enums/RecordValueType.js';
|
|||||||
import { type File } from './File.js';
|
import { type File } from './File.js';
|
||||||
import { RecordValue } from './RecordValue.js';
|
import { RecordValue } from './RecordValue.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class FileListRecordValue - Represents a file list record value.
|
||||||
|
*/
|
||||||
export class FileListRecordValue extends RecordValue<File[]> {
|
export class FileListRecordValue extends RecordValue<File[]> {
|
||||||
|
/**
|
||||||
|
* @constructor - Creates a new instance of FileListRecordValue.
|
||||||
|
* @param {number} fieldId - The id of the field.
|
||||||
|
* @param {File[]} value - The value of the field.
|
||||||
|
* @returns {FileListRecordValue} - A new instance of FileListRecordValue.
|
||||||
|
*/
|
||||||
constructor(fieldId: number, value: File[]) {
|
constructor(fieldId: number, value: File[]) {
|
||||||
super(RecordValueType.FileList, fieldId, value);
|
super(RecordValueType.FileList, fieldId, value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import { DataFormat } from '../enums/DataFormat.js';
|
import { DataFormat } from '../enums/DataFormat.js';
|
||||||
import { PagingRequest } from './PagingRequest.js';
|
import { PagingRequest } from './PagingRequest.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class GetRecordsByAppIdRequest - Represents a request to get records by app id.
|
||||||
|
*/
|
||||||
export class GetRecordsByAppIdRequest {
|
export class GetRecordsByAppIdRequest {
|
||||||
/**
|
/**
|
||||||
* @property {number} appId - The id of the app that the records belong to.
|
* @property {number} appId - The id of the app that the records belong to.
|
||||||
|
|||||||
@@ -1,7 +1,16 @@
|
|||||||
import { RecordValueType } from '../enums/RecordValueType.js';
|
import { RecordValueType } from '../enums/RecordValueType.js';
|
||||||
import { RecordValue } from './RecordValue.js';
|
import { RecordValue } from './RecordValue.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class GuidListRecordValue - Represents a guid list record value.
|
||||||
|
*/
|
||||||
export class GuidListRecordValue extends RecordValue<string[]> {
|
export class GuidListRecordValue extends RecordValue<string[]> {
|
||||||
|
/**
|
||||||
|
* @constructor - Creates a new instance of GuidListRecordValue.
|
||||||
|
* @param {number} fieldId - The id of the field.
|
||||||
|
* @param {string[]} value - The value of the field.
|
||||||
|
* @returns {GuidListRecordValue} - A new instance of GuidListRecordValue.
|
||||||
|
*/
|
||||||
constructor(fieldId: number, value: string[]) {
|
constructor(fieldId: number, value: string[]) {
|
||||||
super(RecordValueType.GuidList, fieldId, value);
|
super(RecordValueType.GuidList, fieldId, value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,16 @@
|
|||||||
import { RecordValueType } from '../enums/RecordValueType.js';
|
import { RecordValueType } from '../enums/RecordValueType.js';
|
||||||
import { RecordValue } from './RecordValue.js';
|
import { RecordValue } from './RecordValue.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class GuidRecordValue - Represents a guid record value.
|
||||||
|
*/
|
||||||
export class GuidRecordValue extends RecordValue<string> {
|
export class GuidRecordValue extends RecordValue<string> {
|
||||||
|
/**
|
||||||
|
* @constructor - Creates a new instance of GuidRecordValue.
|
||||||
|
* @param {number} fieldId - The id of the field.
|
||||||
|
* @param {string} value - The value of the field.
|
||||||
|
* @returns {GuidRecordValue} - A new instance of GuidRecordValue.
|
||||||
|
*/
|
||||||
constructor(fieldId: number, value: string) {
|
constructor(fieldId: number, value: string) {
|
||||||
super(RecordValueType.Guid, fieldId, value);
|
super(RecordValueType.Guid, fieldId, value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,16 @@
|
|||||||
import { RecordValueType } from '../enums/RecordValueType.js';
|
import { RecordValueType } from '../enums/RecordValueType.js';
|
||||||
import { RecordValue } from './RecordValue.js';
|
import { RecordValue } from './RecordValue.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class IntegerListRecordValue - Represents an integer list record value.
|
||||||
|
*/
|
||||||
export class IntegerListRecordValue extends RecordValue<number[]> {
|
export class IntegerListRecordValue extends RecordValue<number[]> {
|
||||||
|
/**
|
||||||
|
* @constructor - Creates a new instance of IntegerListRecordValue.
|
||||||
|
* @param {number} fieldId - The id of the field.
|
||||||
|
* @param {number[]} value - The value of the field.
|
||||||
|
* @returns {IntegerListRecordValue} - A new instance of IntegerListRecordValue.
|
||||||
|
*/
|
||||||
constructor(fieldId: number, value: number[]) {
|
constructor(fieldId: number, value: number[]) {
|
||||||
super(RecordValueType.IntegerList, fieldId, value);
|
super(RecordValueType.IntegerList, fieldId, value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -282,6 +282,13 @@ export class OnspringClient {
|
|||||||
return apiResponse.asCreatedWithIdResponseType<number>();
|
return apiResponse.asCreatedWithIdResponseType<number>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method deleteFileById - Deletes a file by its id.
|
||||||
|
* @param {number} recordId - The id of the record that the file is held on.
|
||||||
|
* @param {number} fieldId - The id of the field that the file is held in.
|
||||||
|
* @param {number} fileId - The id of the file to delete.
|
||||||
|
* @returns {Promise<ApiResponse<any>>} - A promise that resolves to an ApiResponse of type any.
|
||||||
|
*/
|
||||||
public async deleteFileById(
|
public async deleteFileById(
|
||||||
recordId: number,
|
recordId: number,
|
||||||
fieldId: number,
|
fieldId: number,
|
||||||
@@ -416,6 +423,11 @@ export class OnspringClient {
|
|||||||
return apiResponse.asGetPagedRecordsResponseType();
|
return apiResponse.asGetPagedRecordsResponseType();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method saveRecord - Saves a record.
|
||||||
|
* @param {Record | SaveRecordRequest} request - The record or request that will be used to save the record.
|
||||||
|
* @returns {Promise<ApiResponse<SaveRecordResponse>>} - A promise that resolves to an ApiResponse of type SaveRecordResponse.
|
||||||
|
*/
|
||||||
public async saveRecord(
|
public async saveRecord(
|
||||||
request: Record | SaveRecordRequest
|
request: Record | SaveRecordRequest
|
||||||
): Promise<ApiResponse<SaveRecordResponse>> {
|
): Promise<ApiResponse<SaveRecordResponse>> {
|
||||||
|
|||||||
@@ -1,10 +1,32 @@
|
|||||||
import { FilterOperators } from '../enums/FilterOperators.js';
|
import { FilterOperators } from '../enums/FilterOperators.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class QueryFilter - Represents a query filter.
|
||||||
|
*/
|
||||||
export class QueryFilter {
|
export class QueryFilter {
|
||||||
|
/**
|
||||||
|
* @property {number} fieldId - The id of the field to filter on.
|
||||||
|
*/
|
||||||
public fieldId: number;
|
public fieldId: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property {FilterOperators} operator - The operator for the filter.
|
||||||
|
*/
|
||||||
public operator: FilterOperators;
|
public operator: FilterOperators;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property {string | number | Date | null} value - The value for the filter.
|
||||||
|
*/
|
||||||
public value: string | number | Date | null;
|
public value: string | number | Date | null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @constructor - Creates a new instance of the QueryFilter class.
|
||||||
|
* @param {number} fieldId - The id of the field to filter on.
|
||||||
|
* @param {FilterOperators} operator - The operator for the filter.
|
||||||
|
* @param {string | number | Date | null} value - The value for the filter.
|
||||||
|
* @returns {QueryFilter} - A new instance of the QueryFilter class.
|
||||||
|
* @throws {Error} - If the value is null and the operator is not IsNull or NotNull.
|
||||||
|
*/
|
||||||
constructor(
|
constructor(
|
||||||
fieldId: number,
|
fieldId: number,
|
||||||
operator: FilterOperators,
|
operator: FilterOperators,
|
||||||
@@ -23,6 +45,10 @@ export class QueryFilter {
|
|||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method toString - Converts the filter to a string.
|
||||||
|
* @returns {string} - The filter as a string.
|
||||||
|
*/
|
||||||
public toString(): string {
|
public toString(): string {
|
||||||
if (this.value == null) {
|
if (this.value == null) {
|
||||||
return `${this.fieldId} ${this.operator}`;
|
return `${this.fieldId} ${this.operator}`;
|
||||||
|
|||||||
@@ -55,6 +55,10 @@ export class Record {
|
|||||||
this.fieldData = this.fieldData.concat(fieldData);
|
this.fieldData = this.fieldData.concat(fieldData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method convertToSaveRecordRequest - Converts the record to a SaveRecordRequest.
|
||||||
|
* @returns {SaveRecordRequest} - A SaveRecordRequest.
|
||||||
|
*/
|
||||||
public convertToSaveRecordRequest(): SaveRecordRequest {
|
public convertToSaveRecordRequest(): SaveRecordRequest {
|
||||||
const fields = this.fieldData.reduce((acc, cur) => {
|
const fields = this.fieldData.reduce((acc, cur) => {
|
||||||
acc.set(cur.fieldId, cur.value);
|
acc.set(cur.fieldId, cur.value);
|
||||||
|
|||||||
@@ -1,8 +1,20 @@
|
|||||||
import { CreatedWithIdResponse } from './CreatedWithIdResponse.js';
|
import { CreatedWithIdResponse } from './CreatedWithIdResponse.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class SaveRecordResponse - Response from saving a record
|
||||||
|
*/
|
||||||
export class SaveRecordResponse extends CreatedWithIdResponse<number> {
|
export class SaveRecordResponse extends CreatedWithIdResponse<number> {
|
||||||
|
/**
|
||||||
|
* @property {string[]} warnings - The warnings from saving the record.
|
||||||
|
*/
|
||||||
public warnings: string[];
|
public warnings: string[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @constructor - Creates a new instance of SaveRecordResponse.
|
||||||
|
* @param {number} id - The id of the record.
|
||||||
|
* @param {string[]} warnings - The warnings from saving the record.
|
||||||
|
* @returns {SaveRecordResponse} - A new instance of SaveRecordResponse.s
|
||||||
|
*/
|
||||||
constructor(id: number, warnings: string[] = []) {
|
constructor(id: number, warnings: string[] = []) {
|
||||||
super(id);
|
super(id);
|
||||||
this.warnings = warnings;
|
this.warnings = warnings;
|
||||||
|
|||||||
@@ -2,7 +2,16 @@ import { RecordValueType } from '../enums/RecordValueType.js';
|
|||||||
import { RecordValue } from './RecordValue.js';
|
import { RecordValue } from './RecordValue.js';
|
||||||
import { type ScoringGroup } from './ScoringGroup.js';
|
import { type ScoringGroup } from './ScoringGroup.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class ScoringGroupListRecordValue - Represents a scoring group list record value.
|
||||||
|
*/
|
||||||
export class ScoringGroupListRecordValue extends RecordValue<ScoringGroup[]> {
|
export class ScoringGroupListRecordValue extends RecordValue<ScoringGroup[]> {
|
||||||
|
/**
|
||||||
|
* @constructor - Creates a new instance of ScoringGroupListRecordValue.
|
||||||
|
* @param {number} fieldId - The id of the field.
|
||||||
|
* @param {ScoringGroup[]} value - The value of the field.
|
||||||
|
* @returns {ScoringGroupListRecordValue} - A new instance of ScoringGroupListRecordValue.
|
||||||
|
*/
|
||||||
constructor(fieldId: number, value: ScoringGroup[]) {
|
constructor(fieldId: number, value: ScoringGroup[]) {
|
||||||
super(RecordValueType.ScoringGroupList, fieldId, value);
|
super(RecordValueType.ScoringGroupList, fieldId, value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,16 @@
|
|||||||
import { RecordValueType } from '../enums/RecordValueType.js';
|
import { RecordValueType } from '../enums/RecordValueType.js';
|
||||||
import { RecordValue } from './RecordValue.js';
|
import { RecordValue } from './RecordValue.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class StringListRecordValue - Represents a string list record value.
|
||||||
|
*/
|
||||||
export class StringListRecordValue extends RecordValue<string[]> {
|
export class StringListRecordValue extends RecordValue<string[]> {
|
||||||
|
/**
|
||||||
|
* @constructor - Creates a new instance of StringListRecordValue.
|
||||||
|
* @param {number} fieldId - The id of the field.
|
||||||
|
* @param {string[]} value - The value of the field.
|
||||||
|
* @returns {StringListRecordValue} - A new instance of StringListRecordValue.
|
||||||
|
*/
|
||||||
constructor(fieldId: number, value: string[]) {
|
constructor(fieldId: number, value: string[]) {
|
||||||
super(RecordValueType.StringList, fieldId, value);
|
super(RecordValueType.StringList, fieldId, value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,16 @@ import { RecordValueType } from '../enums/RecordValueType.js';
|
|||||||
import { RecordValue } from './RecordValue.js';
|
import { RecordValue } from './RecordValue.js';
|
||||||
import { type TimeSpanData } from './TimeSpanData.js';
|
import { type TimeSpanData } from './TimeSpanData.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class TimeSpanRecordValue - Represents a time span record value.
|
||||||
|
*/
|
||||||
export class TimeSpanRecordValue extends RecordValue<TimeSpanData> {
|
export class TimeSpanRecordValue extends RecordValue<TimeSpanData> {
|
||||||
|
/**
|
||||||
|
* @constructor - Creates a new instance of TimeSpanRecordValue.
|
||||||
|
* @param {number} fieldId - The id of the field.
|
||||||
|
* @param {TimeSpanData} value - The value of the field.
|
||||||
|
* @returns {TimeSpanRecordValue} - A new instance of TimeSpanRecordValue.
|
||||||
|
*/
|
||||||
constructor(fieldId: number, value: TimeSpanData) {
|
constructor(fieldId: number, value: TimeSpanData) {
|
||||||
super(RecordValueType.TimeSpan, fieldId, value);
|
super(RecordValueType.TimeSpan, fieldId, value);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user