From f3c69d3a343c742d420643cdc487fdba299ff100 Mon Sep 17 00:00:00 2001 From: StevanFreeborn <65925598+StevanFreeborn@users.noreply.github.com> Date: Mon, 20 Feb 2023 19:12:15 -0600 Subject: [PATCH 1/3] fix: update jsdoc comments for enums --- src/enums/DelegateType.ts | 20 ++++++++++++++++---- src/enums/FileStorageSite.ts | 3 +++ src/enums/FilterOperators.ts | 10 ++++++++++ src/enums/FormulaOutputType.ts | 3 +++ 4 files changed, 32 insertions(+), 4 deletions(-) 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. From 396660e80142b82442b3ab08e1f7ab97331499e1 Mon Sep 17 00:00:00 2001 From: StevanFreeborn <=> Date: Mon, 20 Feb 2023 21:08:22 -0600 Subject: [PATCH 2/3] fix: add jsdoc comments to models --- src/models/ApiResponse.ts | 46 ++++++++++++++++++----- src/models/ApiResponseFactory.ts | 4 +- src/models/CreatedWithIdResponse.ts | 3 ++ src/models/DecimalRecordValue.ts | 9 +++++ src/models/DelegateListRecordValue.ts | 9 +++++ src/models/FileListRecordValue.ts | 9 +++++ src/models/GetRecordsByAppIdRequest.ts | 3 ++ src/models/GuidListRecordValue.ts | 9 +++++ src/models/GuidRecordValue.ts | 9 +++++ src/models/IntegerListRecordValue.ts | 9 +++++ src/models/OnspringClient.ts | 18 ++++++++- src/models/QueryFilter.ts | 26 +++++++++++++ src/models/Record.ts | 4 ++ src/models/SaveRecordResponse.ts | 12 ++++++ src/models/ScoringGroupListRecordValue.ts | 9 +++++ src/models/StringListRecordValue.ts | 9 +++++ src/models/TimeSpanRecordValue.ts | 9 +++++ 17 files changed, 185 insertions(+), 12 deletions(-) diff --git a/src/models/ApiResponse.ts b/src/models/ApiResponse.ts index be44d7d..db78f0a 100644 --- a/src/models/ApiResponse.ts +++ b/src/models/ApiResponse.ts @@ -92,17 +92,17 @@ export class ApiResponse { public asGetPagedAppsResponseType(): ApiResponse { const apiResponse = this as ApiResponse; -const apps = apiResponse.data.items.map((item: any) => { - return new App(item.href, item.id, item.name); -}); + const apps = apiResponse.data.items.map((item: any) => { + return new App(item.href, item.id, item.name); + }); -const getAppsPagedResponse = new GetPagedAppsResponse( - apps, - apiResponse.data.pageNumber, - apiResponse.data.pageSize, - apiResponse.data.totalPages, - apiResponse.data.totalRecords -); + const getAppsPagedResponse = new GetPagedAppsResponse( + apps, + apiResponse.data.pageNumber, + apiResponse.data.pageSize, + apiResponse.data.totalPages, + apiResponse.data.totalRecords + ); return new ApiResponse( apiResponse.statusCode, @@ -238,6 +238,10 @@ const getAppsPagedResponse = new GetPagedAppsResponse( ); } + /** + * @method asFileInfoType - Converts the ApiResponse to an ApiResponse. + * @returns {ApiResponse} - An ApiResponse. + */ public asFileInfoType(): ApiResponse { const apiResponse = this as ApiResponse; @@ -259,6 +263,10 @@ const getAppsPagedResponse = new GetPagedAppsResponse( ); } + /** + * @method asFileType - Converts the ApiResponse to an ApiResponse. + * @returns {ApiResponse} - An ApiResponse. + */ public asFileType(response: AxiosResponse): ApiResponse { const apiResponse = this as ApiResponse; @@ -411,6 +419,10 @@ const getAppsPagedResponse = new GetPagedAppsResponse( ); } + /** + * @method asRecordCollectionType - Converts the ApiResponse to an ApiResponse>. + * @returns {ApiResponse>} - An ApiResponse>. + */ public asRecordCollectionType(): ApiResponse> { const apiResponse = this as ApiResponse; @@ -434,6 +446,10 @@ const getAppsPagedResponse = new GetPagedAppsResponse( ); } + /** + * @method asSaveRecordResponseType - Converts the ApiResponse to an ApiResponse. + * @returns {ApiResponse} - An ApiResponse. + */ public asSaveRecordResponseType(): ApiResponse { const apiResponse = this as ApiResponse; const response = new SaveRecordResponse( @@ -447,6 +463,11 @@ const getAppsPagedResponse = new GetPagedAppsResponse( ); } + /** + * @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]; @@ -629,6 +650,11 @@ const getAppsPagedResponse = new GetPagedAppsResponse( } } + /** + * @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]; diff --git a/src/models/ApiResponseFactory.ts b/src/models/ApiResponseFactory.ts index f4cc601..5f0ee93 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 38d206b..455799c 100644 --- a/src/models/DecimalRecordValue.ts +++ b/src/models/DecimalRecordValue.ts @@ -1,7 +1,16 @@ import { RecordValue } from './RecordValue'; import { RecordValueType } from '../enums/RecordValueType'; +/** + * @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 1ac9a6f..adc61ce 100644 --- a/src/models/DelegateListRecordValue.ts +++ b/src/models/DelegateListRecordValue.ts @@ -2,7 +2,16 @@ import { RecordValue } from './RecordValue'; import { RecordValueType } from '../enums/RecordValueType'; import { type Delegate } from './Delegate'; +/** + * @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 bd49bc5..247ae64 100644 --- a/src/models/FileListRecordValue.ts +++ b/src/models/FileListRecordValue.ts @@ -2,7 +2,16 @@ import { RecordValue } from './RecordValue'; import { RecordValueType } from '../enums/RecordValueType'; import { type File } from './File'; +/** + * @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 b49435b..b7e4ecc 100644 --- a/src/models/GetRecordsByAppIdRequest.ts +++ b/src/models/GetRecordsByAppIdRequest.ts @@ -1,6 +1,9 @@ import { DataFormat } from '../enums/DataFormat'; import { PagingRequest } from './PagingRequest'; +/** + * @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 7e9a064..7b33f30 100644 --- a/src/models/GuidListRecordValue.ts +++ b/src/models/GuidListRecordValue.ts @@ -1,7 +1,16 @@ import { RecordValueType } from '../enums/RecordValueType'; import { RecordValue } from './RecordValue'; +/** + * @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 9af101c..ae4e9b9 100644 --- a/src/models/GuidRecordValue.ts +++ b/src/models/GuidRecordValue.ts @@ -1,7 +1,16 @@ import { RecordValueType } from '../enums/RecordValueType'; import { RecordValue } from './RecordValue'; +/** + * @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 0fce22b..439b408 100644 --- a/src/models/IntegerListRecordValue.ts +++ b/src/models/IntegerListRecordValue.ts @@ -1,7 +1,16 @@ import { RecordValueType } from '../enums/RecordValueType'; import { RecordValue } from './RecordValue'; +/** + * @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 2b58b6a..ff2f1ec 100644 --- a/src/models/OnspringClient.ts +++ b/src/models/OnspringClient.ts @@ -49,7 +49,11 @@ export class OnspringClient { * @throws {Error} - Thrown when the apiKey is null/undefined/empty/whitespace. * @returns {OnspringClient} - A new instance of the OnspringClient class. */ - constructor(baseUrl: string | undefined | null, apiKey: string | undefined | null, config: CreateAxiosDefaults = {}) { + constructor( + baseUrl: string | undefined | null, + apiKey: string | undefined | null, + config: CreateAxiosDefaults = {} + ) { if (ArgumentValidator.isValidUrl(baseUrl) === false || baseUrl === null) { throw new Error('baseUrl must be an absolute and well-formed URI.'); } @@ -278,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, @@ -412,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 8bc6e49..6ea0c06 100644 --- a/src/models/QueryFilter.ts +++ b/src/models/QueryFilter.ts @@ -1,10 +1,32 @@ import { FilterOperators } from '../enums/FilterOperators'; +/** + * @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 92a804b..c2e1307 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 ad70380..28086e0 100644 --- a/src/models/SaveRecordResponse.ts +++ b/src/models/SaveRecordResponse.ts @@ -1,8 +1,20 @@ import { CreatedWithIdResponse } from './CreatedWithIdResponse'; +/** + * @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 67b4859..9bd3e2a 100644 --- a/src/models/ScoringGroupListRecordValue.ts +++ b/src/models/ScoringGroupListRecordValue.ts @@ -2,7 +2,16 @@ import { RecordValueType } from '../enums/RecordValueType'; import { RecordValue } from './RecordValue'; import { type ScoringGroup } from './ScoringGroup'; +/** + * @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 674dadb..430c904 100644 --- a/src/models/StringListRecordValue.ts +++ b/src/models/StringListRecordValue.ts @@ -1,7 +1,16 @@ import { RecordValueType } from '../enums/RecordValueType'; import { RecordValue } from './RecordValue'; +/** + * @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 cead1dc..d729942 100644 --- a/src/models/TimeSpanRecordValue.ts +++ b/src/models/TimeSpanRecordValue.ts @@ -2,7 +2,16 @@ import { RecordValueType } from '../enums/RecordValueType'; import { RecordValue } from './RecordValue'; import { type TimeSpanData } from './TimeSpanData'; +/** + * @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); } From f48189a88106dff2f2b77219bd2e3c4e2c15cb8c Mon Sep 17 00:00:00 2001 From: StevanFreeborn <=> Date: Tue, 21 Feb 2023 08:59:14 -0600 Subject: [PATCH 3/3] docs: stub out README.md --- README.md | 317 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 316 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index df38cc3..4f18195 100644 --- a/README.md +++ b/README.md @@ -5,4 +5,319 @@ [![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) -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 their existing C# SDK, their swagger page, and api documentation 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 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: + +`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. + +## 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 + +``` + +`ES Module` + +```js + +``` + +### `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 availabe for you to use if you prefer to use typescript. + +## 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. + +### Connectivity + +#### Verify connectivity + +```js + +``` + +### 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 + +``` + +You can set your own page size and page number (max is 1,000) as well. + +```js + +``` + +#### Get App By Id + +Returns an Onspring app or survey according to provided id. + +```js + +``` + +#### Get Apps By Ids + +Returns a collection of Onspring apps and/or surveys according to provided ids. + +```js + +``` + +### Fields + +#### Get Field By Id + +Returns an Onspring field according to provided id. + +```js + +``` + +#### Get Fields By Ids + +Returns a collection of Onspring fields according to provided ids. + +```js + +``` + +#### 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 + +``` + +You can set your own page size and page number (max is 1,000) as well. + +```js + +``` + +### Files + +#### Get File Info By Id + +Returns the Onspring file's metadata. + +```js + +``` + +#### Get File By Id + +Returns the file itself. + +```js + +``` + +#### Save File + +```js + +``` + +#### Delete File By Id + +```js + +``` + +### Lists + +#### Add Or Update List Value + +To add a list value don't provide an id value. + +```js + +``` + +To update a list value provide an id value. + +```js + +``` + +#### Delete List Value + +```js + +``` + +### Records + +#### Get Records By App Id + +Returns a paged colletion of records that can be paged through. By default the page size is 50 and page number is 1. + +```js + +``` + +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 + +``` + +#### Get Record By Id + +Returns an onspring record based on the provided app and record ids. + +```js + +``` + +You can also specify what field values to return and in what format (Raw vs. Formatted) to return them. + +```js + +``` + +#### Get Records By Ids + +Returns a collection of Onspring records based on the provided appId and recordIds. + +```js + +``` + +You can also specify what field values to return and in what format (Raw vs. Formatted) to return them. + +```js + +``` + +#### Query Records + +Returns a paged colletion of records based on a criteria that can be paged through. By default the page size is 50 and page number is 1. + +```js + +``` + +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 + +``` + +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 v2 of 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 + +``` + +You can update a record by providing its id. If successful will return the id of record updated. + +```js + +``` + +#### Delete Records By Ids + +```js + +``` + +### Reports + +#### Get Report By Id + +Returns the report for the provided id. + +```js + +``` + +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 + +``` + +#### 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 + +```