Skip to content

Commit

Permalink
Merge pull request #1 from searchunify/feat/oops
Browse files Browse the repository at this point in the history
The JavaScript SDK has been updated to include the Oops feature, which will help improve maintainability. This feature provides a more efficient way of handling errors, allowing developers to easily debug and resolve issues. Additionally, the Oops feature also allows developers to quickly identify and rectify any potential issues, leading to improved product reliability.
  • Loading branch information
mahajanankur authored Mar 2, 2023
2 parents 0cbf0d9 + 2dcf97c commit ad04d0d
Show file tree
Hide file tree
Showing 35 changed files with 6,805 additions and 1,381 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "./node_modules/easy-linter/index.js"
}
63 changes: 33 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,45 @@ Sign up for SearchUnify, before you begin, you need a SearchUnify account. Pleas
## Installation
SDK requires [Node.js](https://nodejs.org/) to run. Install the dependencies and devDependencies and start the server.

## Authentication
Initialize the SDK, with OAuth 2.0 creds. Access token will be generated internally and will be used by SDK to serve the request to your SearchUnify instance.

The access token expires after 4 hours, SDK recreates access token once the token expires using refresh token.

## Execution
Initiate SearchUnify javascript SDK on Server. Using the SDK, you can use SearchUnify functional interface to retrieve or save data. To start using, initialize the SDK with your URL and API key.
```javascript
const { Searchunify } = require('su-sdk');
const { oauth, analytics } = new Searchunify({
instance: 'https://xxxx.searchunify.com'
});
```
const { SearchUnifyRestClient } = require('su-sdk');

## Authentication
Initialize the SDK, to generate OAuth 2.0 token. This token will be internally used by SDK to serve the request to your SearchUnify instance.
```javascript
(async() => {
try {
const accessToken = await oauth.generateToken({
username: 'changeme',
password: 'changeme',
clientId: 'changeme',
clientSecret: 'changeme'
})
console.log(accessToken);
} catch (error) {
console.log(error.message);
}
})();
const suRestClient = new SearchUnifyRestClient({
instance: 'https://yourInstance.searchunify.com',
timeout: 60000,
oauth2: {
username: 'changeme',
password: 'changeme',
clientId: 'changeme',
clientSecret: 'changeme'
}
})
```
The access token will expire after 4 hours, so you need to generate a new access token from the refresh token.

## Sample API call
```javascript
(async() => {
try {
const refreshToken = await oauth.getRefreshedToken();
console.log(refreshToken);
} catch (error) {
console.log(error.message);
}
})();
const tileData = async() => {
try {
const Analytics = suRestClient.Analytics();
const data = await Analytics.getTilesData({
startDate: '2022-12-09',
endDate: '2022-12-10',
searchClientId: 'searchClient UID'
});
console.log("data", data);
} catch (error) {
console.log("error", error);
}
};

tileData();
```
## Documentation
Please refer to the SearchUnify developer guide to use the SDK. https://docs.searchunify.com/Content/Developer-Guides/SDKs.htm
Expand Down
35 changes: 5 additions & 30 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,7 @@
const APIs = require('./src/core');
const validations = require('./src/validations');
const { startClient } = require('./src/core/client/start-client');

/**
* @class Searchunify
* @summary Initilize SearchUnify SDK.
* @param {Object} instance SearchUnify Instance URL.
* @param {Object} timeout APIs Request Timeout (Default 60000ms).
* @author Mohan Rana
*/

function Searchunify(clientProps) {
try {
const isValid = validations.client.initilize(clientProps);
if (isValid.error) throw new Error(isValid.error.message);
startClient(isValid.value);

return {
oauth: APIs.oauth2,
analytics: APIs.analytics,
content: APIs.content,
search: APIs.search
};
} catch (error) {
throw new Error(error);
}
}
const { SearchUnifyRestClient } = require('./src/core/su-rest-client');
const { SearchUnifyPluginClient } = require('./src/su-plugins/su-plugin-client');

module.exports = {
Searchunify
}
SearchUnifyRestClient,
SearchUnifyPluginClient
};
Loading

0 comments on commit ad04d0d

Please sign in to comment.