diff --git a/.github/workflows/build_publish.yml b/.github/workflows/build_publish.yml index 1a32349..e4157bd 100644 --- a/.github/workflows/build_publish.yml +++ b/.github/workflows/build_publish.yml @@ -52,6 +52,10 @@ jobs: TEST_SURVEY_ID: ${{ vars.TEST_SURVEY_ID }} TEST_SURVEY_RECORD_ID: ${{ vars.TEST_SURVEY_RECORD_ID }} 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 uses: actions/upload-artifact@v3.1.2 with: diff --git a/.github/workflows/lint_format_test.yaml b/.github/workflows/lint_format_test.yaml index 6bbc4c3..ef795f1 100644 --- a/.github/workflows/lint_format_test.yaml +++ b/.github/workflows/lint_format_test.yaml @@ -113,10 +113,24 @@ jobs: TEST_SURVEY_ID: ${{ vars.TEST_SURVEY_ID }} TEST_SURVEY_RECORD_ID: ${{ vars.TEST_SURVEY_RECORD_ID }} 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: needs: test name: publish_test_coverage runs-on: ubuntu-latest 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 uses: codecov/codecov-action@v3 + with: + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.husky/commit-msg b/.husky/commit-msg old mode 100644 new mode 100755 diff --git a/.nycrc b/.nycrc index f7ac663..9b12abb 100644 --- a/.nycrc +++ b/.nycrc @@ -6,8 +6,18 @@ "functions": 100, "statements": 100, "all": true, - "include": ["src/**/*.ts"], - "exclude": ["src/index.ts", "**/*.spec.ts"], - "reporter": ["html", "lcov", "text", "text-summary"], + "include": [ + "src/**/*.ts" + ], + "exclude": [ + "src/index.ts", + "**/*.spec.ts" + ], + "reporter": [ + "html", + "lcov", + "text", + "text-summary" + ], "report-dir": "coverage" -} +} \ No newline at end of file diff --git a/README.md b/README.md index df38cc3..06d6c00 100644 --- a/README.md +++ b/README.md @@ -4,5 +4,624 @@ [![codecov](https://codecov.io/github/StevanFreeborn/onspring-api-sdk-javascript/branch/master/graph/badge.svg?token=G1L3GKE0LV)](https://codecov.io/github/StevanFreeborn/onspring-api-sdk-javascript) [![build_publish](https://github.com/StevanFreeborn/onspring-api-sdk-javascript/actions/workflows/build_publish.yml/badge.svg?branch=master)](https://github.com/StevanFreeborn/onspring-api-sdk-javascript/actions/workflows/build_publish.yml) [![semantic-release: angular](https://img.shields.io/badge/semantic--release-angular-e10079?logo=semantic-release)](https://github.com/semantic-release/semantic-release) +[![NPM](https://img.shields.io/npm/l/onspring-api-sdk)](License.txt) +![npm](https://img.shields.io/npm/v/onspring-api-sdk) -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 + +![node-current](https://img.shields.io/node/v/onspring-api-sdk) + +Requires use of [Node.js](https://nodejs.org/en/) 14.x or later. + +### Axios + +![npm (prod) dependency version](https://img.shields.io/npm/dependency-version/onspring-api-sdk/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 + +![npm (prod) dependency version](https://img.shields.io/npm/dependency-version/onspring-api-sdk/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); +} +``` diff --git a/package.json b/package.json index 5f85799..4bd3d28 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "lint-fix": "eslint --fix --ignore-path .eslintignore --ext .js,.ts . --max-warnings=0", "format-staged": "pretty-quick --staged", "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:integration": "mocha -r ts-node/register -r integrationTests/mochaRootHooks.ts", "tests:unit": "mocha -R progress -r ts-node/register ./tests/**/*.spec.ts", diff --git a/src/enums/DelegateType.ts b/src/enums/DelegateType.ts index 5a8c529..57e23fa 100644 --- a/src/enums/DelegateType.ts +++ b/src/enums/DelegateType.ts @@ -1,4 +1,16 @@ -export enum DelegateType { - External = 'External', - Internal = 'Internal', -} +/** + * @enum DelegateType - The type of delegate + */ +export enum DelegateType { + /** + * @constant External - The delegate is external. + * @type {string} + */ + External = 'External', + + /** + * @constant Internal - The delegate is internal. + * @type {string} + */ + Internal = 'Internal', +} diff --git a/src/enums/FileStorageSite.ts b/src/enums/FileStorageSite.ts index 34883a1..bf13da4 100644 --- a/src/enums/FileStorageSite.ts +++ b/src/enums/FileStorageSite.ts @@ -1,3 +1,6 @@ +/** + * @enum FileStorageSite - The site where the file is stored. + */ export enum FileStorageSite { /** * @constant Internal - The file is stored in the internal file storage. diff --git a/src/enums/FilterOperators.ts b/src/enums/FilterOperators.ts index 5210291..b66d368 100644 --- a/src/enums/FilterOperators.ts +++ b/src/enums/FilterOperators.ts @@ -4,60 +4,70 @@ export enum FilterOperators { /** * @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. */ Equal = 'eq', /** * @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. */ NotEqual = 'ne', /** * @constant Contains - The contains operator + * @type {string} * @remarks Can be used with list fields as well as their formula equivalents. */ Contains = 'contains', /** * @constant IsNull - The is null operator + * @type {string} * @remarks Can be used with text, date, and number fields as well as their formula equivalents. */ IsNull = 'isnull', /** * @constant NotNull - The not null operator + * @type {string} * @remarks Can be used with text, date, and number fields as well as their formula equivalents. */ NotNull = 'notnull', /** * @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. */ GreaterThan = 'gt', /** * @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. */ LessThan = 'lt', /** * @constant And - The and operator + * @type {string} * @remarks Can be used to create compound filters. */ And = 'and', /** * @constant Or - The or operator + * @type {string} * @remarks Can be used to create compound filters. */ Or = 'or', /** * @constant Not - The not operator + * @type {string} * @remarks Can be used to negate a filter and create compound filters. */ Not = 'not', diff --git a/src/enums/FormulaOutputType.ts b/src/enums/FormulaOutputType.ts index ca7c9b8..5de8038 100644 --- a/src/enums/FormulaOutputType.ts +++ b/src/enums/FormulaOutputType.ts @@ -1,3 +1,6 @@ +/** + * @enum FormulaOutputType - The type of the formula output. + */ export enum FormulaOutputType { /** * @constant Text - The formula output is a text value. diff --git a/src/models/ApiResponse.ts b/src/models/ApiResponse.ts index 9a9ab61..76cb555 100644 --- a/src/models/ApiResponse.ts +++ b/src/models/ApiResponse.ts @@ -238,6 +238,10 @@ export class ApiResponse { ); } + /** + * @method asFileInfoType - Converts the ApiResponse to an ApiResponse. + * @returns {ApiResponse} - An ApiResponse. + */ public asFileInfoType(): ApiResponse { const apiResponse = this as ApiResponse; @@ -259,6 +263,10 @@ export class ApiResponse { ); } + /** + * @method asFileType - Converts the ApiResponse to an ApiResponse. + * @returns {ApiResponse} - An ApiResponse. + */ public asFileType(response: AxiosResponse): ApiResponse { const apiResponse = this as ApiResponse; const fileName = response.headers['content-disposition'] @@ -408,6 +416,10 @@ export class ApiResponse { ); } + /** + * @method asRecordCollectionType - Converts the ApiResponse to an ApiResponse>. + * @returns {ApiResponse>} - An ApiResponse>. + */ public asRecordCollectionType(): ApiResponse> { const apiResponse = this as ApiResponse; @@ -431,6 +443,10 @@ export class ApiResponse { ); } + /** + * @method asSaveRecordResponseType - Converts the ApiResponse to an ApiResponse. + * @returns {ApiResponse} - An ApiResponse. + */ public asSaveRecordResponseType(): ApiResponse { const apiResponse = this as ApiResponse; const response = new SaveRecordResponse( @@ -444,6 +460,11 @@ export class ApiResponse { ); } + /** + * @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 { const type = RecordValueType[recordValueItem.type]; @@ -626,6 +647,11 @@ export class ApiResponse { } } + /** + * @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 { const delegateType = DelegateType[delegateItem.delegateType]; @@ -712,7 +738,7 @@ export class ApiResponse { const hasRecurrence = timeSpanItem.recurrence !== null && timeSpanItem.recurrence !== undefined; - const recurrene = hasRecurrence + const recurrence = hasRecurrence ? TimeSpanRecurrenceType[timeSpanItem.recurrence] : null; @@ -735,7 +761,7 @@ export class ApiResponse { ); } - if (recurrene === undefined) { + if (recurrence === undefined) { throw new Error( `${ timeSpanItem.recurrence as string @@ -746,7 +772,7 @@ export class ApiResponse { return new TimeSpanData( timeSpanItem.quantity, increment, - recurrene, + recurrence, endAfterOccurrences, endByDate ); diff --git a/src/models/ApiResponseFactory.ts b/src/models/ApiResponseFactory.ts index 054751a..91292a2 100644 --- a/src/models/ApiResponseFactory.ts +++ b/src/models/ApiResponseFactory.ts @@ -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} - A promise that resolves to the data from the stream as a string */ private static async getStreamDataAsString( stream: Readable diff --git a/src/models/CreatedWithIdResponse.ts b/src/models/CreatedWithIdResponse.ts index 9907e65..993acaa 100644 --- a/src/models/CreatedWithIdResponse.ts +++ b/src/models/CreatedWithIdResponse.ts @@ -1,3 +1,6 @@ +/** + * @class CreatedWithIdResponse - Represents a response to a request to create a resource. + */ export class CreatedWithIdResponse { /** * @property {T} id - The id of the created object. diff --git a/src/models/DecimalRecordValue.ts b/src/models/DecimalRecordValue.ts index 06f45df..3c11e7d 100644 --- a/src/models/DecimalRecordValue.ts +++ b/src/models/DecimalRecordValue.ts @@ -1,7 +1,16 @@ import { RecordValue } from './RecordValue.js'; import { RecordValueType } from '../enums/RecordValueType.js'; +/** + * @class DecimalRecordValue - Represents a decimal record value + */ export class DecimalRecordValue extends RecordValue { + /** + * @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) { super(RecordValueType.Decimal, fieldId, value); } diff --git a/src/models/DelegateListRecordValue.ts b/src/models/DelegateListRecordValue.ts index 335d7c7..f8ffc85 100644 --- a/src/models/DelegateListRecordValue.ts +++ b/src/models/DelegateListRecordValue.ts @@ -2,7 +2,16 @@ import { RecordValueType } from '../enums/RecordValueType.js'; import { type Delegate } from './Delegate.js'; import { RecordValue } from './RecordValue.js'; +/** + * @class DelegateListRecordValue - Represents a delegate list record value. + */ export class DelegateListRecordValue extends RecordValue { + /** + * @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[]) { super(RecordValueType.DelegateList, fieldId, value); } diff --git a/src/models/FileListRecordValue.ts b/src/models/FileListRecordValue.ts index c2b18b1..39e1bf2 100644 --- a/src/models/FileListRecordValue.ts +++ b/src/models/FileListRecordValue.ts @@ -2,7 +2,16 @@ import { RecordValueType } from '../enums/RecordValueType.js'; import { type File } from './File.js'; import { RecordValue } from './RecordValue.js'; +/** + * @class FileListRecordValue - Represents a file list record value. + */ export class FileListRecordValue extends RecordValue { + /** + * @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[]) { super(RecordValueType.FileList, fieldId, value); } diff --git a/src/models/GetRecordsByAppIdRequest.ts b/src/models/GetRecordsByAppIdRequest.ts index 993b616..91d51be 100644 --- a/src/models/GetRecordsByAppIdRequest.ts +++ b/src/models/GetRecordsByAppIdRequest.ts @@ -1,6 +1,9 @@ import { DataFormat } from '../enums/DataFormat.js'; import { PagingRequest } from './PagingRequest.js'; +/** + * @class GetRecordsByAppIdRequest - Represents a request to get records by app id. + */ export class GetRecordsByAppIdRequest { /** * @property {number} appId - The id of the app that the records belong to. diff --git a/src/models/GuidListRecordValue.ts b/src/models/GuidListRecordValue.ts index fa61a6f..b27b15d 100644 --- a/src/models/GuidListRecordValue.ts +++ b/src/models/GuidListRecordValue.ts @@ -1,7 +1,16 @@ import { RecordValueType } from '../enums/RecordValueType.js'; import { RecordValue } from './RecordValue.js'; +/** + * @class GuidListRecordValue - Represents a guid list record value. + */ export class GuidListRecordValue extends RecordValue { + /** + * @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[]) { super(RecordValueType.GuidList, fieldId, value); } diff --git a/src/models/GuidRecordValue.ts b/src/models/GuidRecordValue.ts index 354ed79..76f82c1 100644 --- a/src/models/GuidRecordValue.ts +++ b/src/models/GuidRecordValue.ts @@ -1,7 +1,16 @@ import { RecordValueType } from '../enums/RecordValueType.js'; import { RecordValue } from './RecordValue.js'; +/** + * @class GuidRecordValue - Represents a guid record value. + */ export class GuidRecordValue extends RecordValue { + /** + * @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) { super(RecordValueType.Guid, fieldId, value); } diff --git a/src/models/IntegerListRecordValue.ts b/src/models/IntegerListRecordValue.ts index 7160477..963e486 100644 --- a/src/models/IntegerListRecordValue.ts +++ b/src/models/IntegerListRecordValue.ts @@ -1,7 +1,16 @@ import { RecordValueType } from '../enums/RecordValueType.js'; import { RecordValue } from './RecordValue.js'; +/** + * @class IntegerListRecordValue - Represents an integer list record value. + */ export class IntegerListRecordValue extends RecordValue { + /** + * @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[]) { super(RecordValueType.IntegerList, fieldId, value); } diff --git a/src/models/OnspringClient.ts b/src/models/OnspringClient.ts index c57e623..a957bba 100644 --- a/src/models/OnspringClient.ts +++ b/src/models/OnspringClient.ts @@ -282,6 +282,13 @@ export class OnspringClient { return apiResponse.asCreatedWithIdResponseType(); } + /** + * @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>} - A promise that resolves to an ApiResponse of type any. + */ public async deleteFileById( recordId: number, fieldId: number, @@ -416,6 +423,11 @@ export class OnspringClient { 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>} - A promise that resolves to an ApiResponse of type SaveRecordResponse. + */ public async saveRecord( request: Record | SaveRecordRequest ): Promise> { diff --git a/src/models/QueryFilter.ts b/src/models/QueryFilter.ts index fbd49e1..6de4679 100644 --- a/src/models/QueryFilter.ts +++ b/src/models/QueryFilter.ts @@ -1,10 +1,32 @@ import { FilterOperators } from '../enums/FilterOperators.js'; +/** + * @class QueryFilter - Represents a query filter. + */ export class QueryFilter { + /** + * @property {number} fieldId - The id of the field to filter on. + */ public fieldId: number; + + /** + * @property {FilterOperators} operator - The operator for the filter. + */ public operator: FilterOperators; + + /** + * @property {string | number | Date | null} value - The value for the filter. + */ 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( fieldId: number, operator: FilterOperators, @@ -23,6 +45,10 @@ export class QueryFilter { this.value = value; } + /** + * @method toString - Converts the filter to a string. + * @returns {string} - The filter as a string. + */ public toString(): string { if (this.value == null) { return `${this.fieldId} ${this.operator}`; diff --git a/src/models/Record.ts b/src/models/Record.ts index 4379b50..929b6a6 100644 --- a/src/models/Record.ts +++ b/src/models/Record.ts @@ -55,6 +55,10 @@ export class Record { this.fieldData = this.fieldData.concat(fieldData); } + /** + * @method convertToSaveRecordRequest - Converts the record to a SaveRecordRequest. + * @returns {SaveRecordRequest} - A SaveRecordRequest. + */ public convertToSaveRecordRequest(): SaveRecordRequest { const fields = this.fieldData.reduce((acc, cur) => { acc.set(cur.fieldId, cur.value); diff --git a/src/models/SaveRecordResponse.ts b/src/models/SaveRecordResponse.ts index 8af03f0..b5a8cc2 100644 --- a/src/models/SaveRecordResponse.ts +++ b/src/models/SaveRecordResponse.ts @@ -1,8 +1,20 @@ import { CreatedWithIdResponse } from './CreatedWithIdResponse.js'; +/** + * @class SaveRecordResponse - Response from saving a record + */ export class SaveRecordResponse extends CreatedWithIdResponse { + /** + * @property {string[]} warnings - The warnings from saving the record. + */ 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[] = []) { super(id); this.warnings = warnings; diff --git a/src/models/ScoringGroupListRecordValue.ts b/src/models/ScoringGroupListRecordValue.ts index 39cd571..64318e7 100644 --- a/src/models/ScoringGroupListRecordValue.ts +++ b/src/models/ScoringGroupListRecordValue.ts @@ -2,7 +2,16 @@ import { RecordValueType } from '../enums/RecordValueType.js'; import { RecordValue } from './RecordValue.js'; import { type ScoringGroup } from './ScoringGroup.js'; +/** + * @class ScoringGroupListRecordValue - Represents a scoring group list record value. + */ export class ScoringGroupListRecordValue extends RecordValue { + /** + * @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[]) { super(RecordValueType.ScoringGroupList, fieldId, value); } diff --git a/src/models/StringListRecordValue.ts b/src/models/StringListRecordValue.ts index 943cf73..537c134 100644 --- a/src/models/StringListRecordValue.ts +++ b/src/models/StringListRecordValue.ts @@ -1,7 +1,16 @@ import { RecordValueType } from '../enums/RecordValueType.js'; import { RecordValue } from './RecordValue.js'; +/** + * @class StringListRecordValue - Represents a string list record value. + */ export class StringListRecordValue extends RecordValue { + /** + * @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[]) { super(RecordValueType.StringList, fieldId, value); } diff --git a/src/models/TimeSpanRecordValue.ts b/src/models/TimeSpanRecordValue.ts index 186cba7..8b85272 100644 --- a/src/models/TimeSpanRecordValue.ts +++ b/src/models/TimeSpanRecordValue.ts @@ -2,7 +2,16 @@ import { RecordValueType } from '../enums/RecordValueType.js'; import { RecordValue } from './RecordValue.js'; import { type TimeSpanData } from './TimeSpanData.js'; +/** + * @class TimeSpanRecordValue - Represents a time span record value. + */ export class TimeSpanRecordValue extends RecordValue { + /** + * @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) { super(RecordValueType.TimeSpan, fieldId, value); }