├── .eslintrc.json ├── .github └── workflows │ ├── build.yml │ └── publish.yml ├── .gitignore ├── .npmignore ├── LICENSE ├── README.md ├── commit_tag_push.sh ├── docs-src ├── statics │ └── images │ │ └── connect_logo_fullname.png └── tutorials │ ├── getting_started.json │ ├── getting_started.md │ ├── searches.json │ └── searches.md ├── docs ├── APIError.html ├── AbstractHttpAdapter.html ├── AccountResource.html ├── AccountUserResource.html ├── AssetResource.html ├── AssetUsageAgregates.html ├── AssetUsageAgregatesResource.html ├── BillingRequestResource.html ├── CaseAttachmentsResource.html ├── CaseCommentsResource.html ├── CaseResource.html ├── CaseSettingsResource.html ├── CategoryUsageFileResource.html ├── ConnectClient.html ├── ConversationResource.html ├── DefaultHttpAdapter.html ├── Directory.html ├── Fulfillment.html ├── GenericResource.html ├── HttpError.html ├── HubResource.html ├── Inventory.html ├── ListingRequestResource.html ├── Listings.html ├── MessageResource.html ├── ProductActionResource.html ├── ProductConfigurationResource.html ├── ProductConnectionsResource.html ├── ProductParameterResource.html ├── ProductResource.html ├── ProductUsageRuleResource.html ├── ProductUsageRulesResource.html ├── ProductVersionResource.html ├── RecurringAssetResource.html ├── RequestResource.html ├── Subscriptions.html ├── TierAccountRequestResource.html ├── TierAccountResource.html ├── TierAccountVersionResource.html ├── TierConfigRequestResource.html ├── TierConfigResource.html ├── UsageAggregateResource.html ├── UsageChunkResource.html ├── UsageFileResource.html ├── UsageReconciliationResource.html ├── UsageReconciliationsResource.html ├── UsageRecordResource.html ├── WebhookResource.html ├── images │ └── connect_logo_fullname.png ├── index.html ├── scripts │ ├── app.min.js │ └── linenumber.js ├── styles │ ├── app.min.css │ ├── iframe.css │ ├── prettify-jsdoc.css │ ├── prettify-tomorrow.css │ └── reset.css ├── tutorial-getting_started.html └── tutorial-searches.html ├── examples └── apiary_scenarios │ ├── asset_accept_workflow.js │ ├── asset_request_workflow.js │ ├── config.json │ ├── package.json │ └── yarn.lock ├── index.js ├── jest.config.js ├── jsdoc.config.js ├── lib └── connect │ ├── api │ ├── accounts.js │ ├── assets.js │ ├── base.js │ ├── billingRequests.js │ ├── cases.js │ ├── conversations.js │ ├── errors.js │ ├── hubs.js │ ├── index.js │ ├── listingRequests.js │ ├── products.js │ ├── recurringAssets.js │ ├── requests.js │ ├── tierAccountRequests.js │ ├── tierAccounts.js │ ├── tierConfigRequests.js │ ├── tierConfigs.js │ ├── usageAggregates.js │ ├── usageChunks.js │ ├── usageFiles.js │ ├── usageReconciliations.js │ ├── usageRecords.js │ ├── utils.js │ └── webhooks.js │ ├── client.js │ ├── http │ ├── adapter.js │ └── index.js │ ├── index.js │ ├── ops │ ├── directory.js │ ├── fulfillment.js │ ├── index.js │ ├── inventory.js │ ├── listings.js │ └── subscriptions.js │ ├── rql.js │ └── utils.js ├── mddocs.config.js ├── mddocs.js ├── mddocs ├── 000_README.md ├── 001_getting_started.md ├── 002_searches.md ├── 003_Class_HttpError.md ├── 004_Class_APIError.md ├── 005_Class_ConnectClient.md ├── 006_Class_AbstractHttpAdapter.md ├── 007_Class_DefaultHttpAdapter.md ├── 008_Class_Directory.md ├── 009_Class_Fulfillment.md ├── 010_Class_Inventory.md ├── 011_Class_Listings.md ├── 012_Class_Subscriptions.md ├── 013_Class_AccountUserResource.md ├── 014_Class_AccountResource.md ├── 015_Class_AssetUsageAgregatesResource.md ├── 016_Class_AssetResource.md ├── 017_Class_GenericResource.md ├── 018_Class_BillingRequestResource.md ├── 019_Class_CaseAttachmentsResource.md ├── 020_Class_CaseSettingsResource.md ├── 021_Class_CaseResource.md ├── 022_Class_MessageResource.md ├── 023_Class_ConversationResource.md ├── 024_Class_HubResource.md ├── 025_Class_ListingRequestResource.md ├── 026_Class_ProductActionResource.md ├── 027_Class_ProductVersionResource.md ├── 028_Class_ProductConfigurationResource.md ├── 029_Class_ProductParameterResource.md ├── 030_Class_ProductConnectionsResource.md ├── 031_Class_ProductUsageRuleResource.md ├── 032_Class_ProductResource.md ├── 033_Class_RecurringAssetResource.md ├── 034_Class_RequestResource.md ├── 035_Class_TierAccountRequestResource.md ├── 036_Class_TierAccountVersionResource.md ├── 037_Class_TierAccountResource.md ├── 038_Class_TierConfigRequestResource.md ├── 039_Class_TierConfigResource.md ├── 040_Class_UsageAggregateResource.md ├── 041_Class_UsageChunkResource.md ├── 042_Class_CategoryUsageFileResource.md ├── 043_Class_UsageFileResource.md ├── 044_Class_UsageReconciliationResource.md ├── 045_Class_UsageRecordResource.md ├── 046_Class_WebhookResource.md └── report.json ├── package-lock.json ├── package.json ├── sonar-project.properties ├── tests ├── helpers │ └── setup.js └── specs │ └── connect │ ├── api │ ├── accounts.spec.js │ ├── assets.spec.js │ ├── base.spec.js │ ├── billingRequests.spec.js │ ├── cases.spec.js │ ├── conversations.spec.js │ ├── errors.spec.js │ ├── listingRequests.spec.js │ ├── products.spec.js │ ├── requests.spec.js │ ├── tierAccountRequests.spec.js │ ├── tierConfigRequests.spec.js │ ├── usageAggregates.spec.js │ ├── usageChunks.spec.js │ ├── usageFiles.spec.js │ ├── usageReconciliations.spec.js │ └── usageRecords.spec.js │ ├── client.spec.js │ ├── data │ └── createParameterRequest.json │ ├── http │ └── adapter.spec.js │ ├── ops │ ├── directory.spec.js │ ├── fulfillment.spec.js │ ├── inventory.spec.js │ ├── listings.spec.js │ └── subscriptions.spec.js │ └── rql.spec.js └── yarn.lock /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": true, 4 | "commonjs": true, 5 | "es6": true, 6 | "node": true 7 | }, 8 | "extends": [ 9 | "airbnb-base", 10 | "plugin:jsdoc/recommended" 11 | ], 12 | "globals": { 13 | "Atomics": "readonly", 14 | "SharedArrayBuffer": "readonly" 15 | }, 16 | "parserOptions": { 17 | "ecmaVersion": 2018 18 | }, 19 | "rules": { 20 | "no-underscore-dangle": "off", 21 | "jsdoc/no-undefined-types": "off" 22 | }, 23 | "settings": { 24 | "jsdoc": { 25 | "tagNamePreference": { 26 | "category": "category", 27 | "augments": { 28 | "message": "@extends is to be used over @augments as it is more evocative of classes than @augments", 29 | "replacement": "extends" 30 | } 31 | } 32 | } 33 | }, 34 | "ignorePatterns": [ 35 | "jest.config.js", 36 | "mddocs.js", 37 | "tests/", 38 | "node_modules/" 39 | ] 40 | } -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: "*" 4 | tags: 5 | - '*' 6 | 7 | pull_request: 8 | branches: [ master ] 9 | 10 | jobs: 11 | build: 12 | runs-on: ubuntu-latest 13 | strategy: 14 | matrix: 15 | node: [ '10', '12' ] 16 | name: Node ${{ matrix.node }} 17 | steps: 18 | - uses: actions/checkout@v2 19 | - name: Setup node 20 | uses: actions/setup-node@v2 21 | with: 22 | node-version: ${{ matrix.node }} 23 | - name: Install dependencies 24 | run: npm install 25 | - name: Testing 26 | run: npm test 27 | - name: docs generation 28 | run: npm run mddocs 29 | - name: docs upload 30 | run: npm run docs 31 | - name: CodeCoverage 32 | run: npx codecov 33 | - name: SonarCloud 34 | uses: SonarSource/sonarcloud-github-action@master 35 | env: 36 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 37 | SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} 38 | - name: Wait sonar to process report 39 | uses: jakejarvis/wait-action@master 40 | with: 41 | time: '60s' 42 | - name: SonarQube Quality Gate check 43 | uses: sonarsource/sonarqube-quality-gate-action@master 44 | timeout-minutes: 5 45 | env: 46 | SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: [master] 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | name: Running Publish Build 9 | steps: 10 | - name: Checkout 11 | uses: actions/checkout@v2 12 | - name: Setup node 13 | uses: actions/setup-node@v2 14 | with: 15 | node-version: 12 16 | - name: Install dependencies 17 | run: npm install 18 | - name: Testing 19 | run: npm test 20 | - name: docs generation 21 | run: npm run mddocs 22 | - name: docs upload 23 | run: npm run docs 24 | - name: CodeCoverage 25 | run: npx codecov 26 | - name: SonarCloud 27 | uses: SonarSource/sonarcloud-github-action@master 28 | env: 29 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 30 | SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} 31 | - name: Wait sonar to process report 32 | uses: jakejarvis/wait-action@master 33 | with: 34 | time: '60s' 35 | - name: SonarQube Quality Gate check 36 | uses: sonarsource/sonarqube-quality-gate-action@master 37 | timeout-minutes: 5 38 | env: 39 | SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} 40 | - name: Commit docs and tagging 41 | run: | 42 | echo "::set-env name=TRAVIS_BRANCH::${TRAVIS_BRANCH:-$(echo $GITHUB_REF | awk 'BEGIN { FS = "/" } ; { print $3 }')}" 43 | ./commit_tag_push.sh 44 | env: 45 | ACTIONS_ALLOW_UNSECURE_COMMANDS: true 46 | TRAVIS_REPO_SLUG: ${{ github.repository }} 47 | TRAVIS_BRANCH: ${{ github.head_ref }} 48 | CONNECT_GITHUB_TOKEN: ${{ secrets.CONNECT_GITHUB_TOKEN }} 49 | - name: Publish NPM package 50 | uses: JS-DevTools/npm-publish@v1 51 | with: 52 | token: ${{ secrets.NPM_TOKEN }} 53 | access: "public" 54 | dry-run: false 55 | check-version: true 56 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | node_modules 3 | *.log 4 | .environment 5 | .env 6 | .nyc_output 7 | coverage 8 | docs/build 9 | .devcontainer 10 | .vscode 11 | .scannerwork 12 | test.js 13 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | docs 2 | test 3 | coverage 4 | .nyc_output 5 | yarn.lock -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Connect Javascript SDK 2 | 3 | 4 | [![Build Status](https://travis-ci.org/cloudblue/connect-javascript-sdk.svg?branch=master)](https://travis-ci.org/cloudblue/connect-javascript-sdk) 5 | [![codecov](https://codecov.io/gh/cloudblue/connect-javascript-sdk/branch/master/graph/badge.svg)](https://codecov.io/gh/cloudblue/connect-javascript-sdk) 6 | [![npm](https://img.shields.io/npm/v/@cloudblueconnect/connect-javascript-sdk)](https://img.shields.io/npm/v/@cloudblueconnect/connect-javascript-sdk) 7 | [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=cloudblue_connect-javascript-sdk&metric=alert_status)](https://sonarcloud.io/dashboard?id=cloudblue_connect-javascript-sdk) 8 | 9 | ## Introduction 10 | 11 | CloudBlue Connect is a supply automation platform that manages your products and services, contracts, 12 | ordering and fulfillment, usage and subscriptions. 13 | 14 | It supports any product, from physical goods to cloud products, as well as any channel, including your 15 | direct and indirect sales channels and internal procurement. 16 | 17 | With its flexible APIs, it can connect to any commerce platform. 18 | 19 | Vendors can leverage CloudBlue Connect to: 20 | 21 | * Reduce the total cost of ownership for homegrown technology supporting their indirect channel 22 | * Standardize integrations with partners 23 | * Increase efficiencies and minimize redundancies by bridging their direct and indirect sales channels 24 | 25 | Service providers can use CloudBlue Connect to: 26 | 27 | * Define, manage and distribute any type of product (omni-product) through any channel (omni-channel) 28 | * Transform perpetual licensed products into a subscription model 29 | * Onboard new products into their portfolio quickly to build and deliver unique solutions to end customers 30 | 31 | 32 | Connect Javascript SDK allows an easy and fast integration with the Cloud Blue Connect Platform. 33 | Thanks to it you can automate the fulfillment of orders generated by your products. 34 | 35 | 36 | 37 | ## Dependencies 38 | 39 | Connect Javascript SDK work with Node.js version 10 or later. 40 | 41 | Connect Javascript SDK also depends on: 42 | 43 | * [ramda](https://ramdajs.com/) version 0.26.1 44 | * [node-fetch](https://github.com/node-fetch/node-fetch) version 2.6.0 45 | 46 | 47 | 48 | ## Install 49 | 50 | To install the Connect Javascript SDK from a terminal window type: 51 | 52 | ```sh 53 | $ npm install --save @cloudblueconnect/connect-javascript-sdk 54 | ``` 55 | 56 | ## Documentation 57 | 58 | The full SDK documentation is available [here](https://cloudblue.github.io/connect-javascript-sdk). 59 | 60 | 61 | ## Example 62 | 63 | ```js 64 | 65 | // import the ConnectClient class 66 | const { ConnectClient } = require('@cloudblueconnect/connect-javascript-sdk'); 67 | 68 | // create an instance of the ConnectClient class 69 | const client = new ConnectClient('https:///', ''); 70 | 71 | // get a list of products 72 | const products = await client.products.search(); 73 | ``` 74 | 75 | ## Contribute 76 | 77 | If you want to contribute to the Connect Javascript SDK development feel free to open issues or fork the github repository and submit your pull request. 78 | 79 | 80 | ## License 81 | 82 | The Connect Javascript SDK is licensed under the [*Apache License 2.0*](http://www.apache.org/licenses/LICENSE-2.0). 83 | 84 | 85 | -------------------------------------------------------------------------------- /commit_tag_push.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | echo "Commit generated documentation" 5 | git config --global user.email "builds@travis-ci.org" 6 | git config --global user.name "Travis CI" 7 | git config --global push.default simple 8 | echo "Checkout current branch $TRAVIS_BRANCH" 9 | git checkout $TRAVIS_BRANCH 10 | echo "Configure remote" 11 | git remote set-url origin https://${CONNECT_GITHUB_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git > /dev/null 2>&1 12 | echo "Fetching tags from remote" 13 | git fetch --tags 14 | echo "Get version from package.json" 15 | export GIT_TAG=v$(node -p "require('./package.json').version") 16 | echo "Stage generated docs" 17 | git add . 18 | echo "Commit docs" 19 | git commit -m "[ci skip] Documentation generated for release $GIT_TAG" 20 | echo "Push docs commit" 21 | git push origin $TRAVIS_BRANCH 22 | CHECK_TAG=$(git tag -l "$GIT_TAG") 23 | if [ "$CHECK_TAG" != "$GIT_TAG" ]; then 24 | echo "Create tag $GIT_TAG" 25 | git tag -a $GIT_TAG -m "Generated tag from build" 26 | echo "Tag $GIT_TAG added" 27 | git push origin $TRAVIS_BRANCH --tags 28 | else 29 | echo "Tag $GIT_TAG already exists!" 30 | fi 31 | echo "Done for version $GIT_TAG!" 32 | -------------------------------------------------------------------------------- /docs-src/statics/images/connect_logo_fullname.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudblue/connect-javascript-sdk/78b3ba3c9d7855cbca427e4667de1fab86abfe7b/docs-src/statics/images/connect_logo_fullname.png -------------------------------------------------------------------------------- /docs-src/tutorials/getting_started.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Getting started", 3 | "children": [ 4 | ] 5 | } -------------------------------------------------------------------------------- /docs-src/tutorials/getting_started.md: -------------------------------------------------------------------------------- 1 | ## Introduction 2 | 3 | The *CloudBlue Connect Javascript SDK* provides programmers with a set of classes that facilitate 4 | the implementation of certain workflows for the *CloudBlue Connect* platform as long as direct access to public endpoints. 5 | 6 | 7 | ## Prerequisites 8 | 9 | The *CloudBlue Connect Javascript SDK* has been tested against with [Node.js](https://nodejs.org) version 10 or later. 10 | 11 | It also depends on the following 3rd party libraries: 12 | 13 | * [ramda](https://ramdajs.com/) version 4.17.15 14 | * [node-fetch](https://github.com/node-fetch/node-fetch) version 2.6.0 15 | 16 | 17 | ## Install 18 | 19 | To add the *CloudBlue Connect Javascript SDK* to your project, executes the following command in your project's root folder: 20 | 21 | ```sh 22 | $ npm install --save @cloudblueconnect/connect-javascript-sdk 23 | ``` 24 | 25 | ## Usage with operation classes 26 | 27 | The *CloudBlue Connect Javascript SDK* exposes to programmers the following set of "operation" classes: 28 | 29 | * {@link Fulfillment}: offers methods such as creation, modification and inquiring of parameters for the management of transactional objects namely asset requests as well as tier configuration requests. 30 | * {@link Directory}: offers methods to access persistent objects such as assets, tier configurations and accounts. 31 | * {@link Inventory}: offers methods to manage products. 32 | 33 | 34 | In order to use the *CloudBlue Connect Javascript SDK* first of all you must create an instance of the {@link ConnectClient} class. 35 | 36 | ```js 37 | const { ConnectClient } = require('@cloudblueconnect/connect-javascript-sdk'); 38 | 39 | const client = new ConnectClient(apiUrl, apiKey); 40 | ``` 41 | 42 | And then you must create an instance of the corresponding operation class: 43 | 44 | ```js 45 | const { Fulfillment } = require('@cloudblueconnect/connect-javascript-sdk'); 46 | 47 | const fulfillment = new Fulfillment(client); 48 | ``` 49 | 50 | ### Examples 51 | 52 | #### Create an asset purchase request 53 | 54 | ```js 55 | const { ConnectClient, Fulfillment } = require('@cloudblueconnect/connect-javascript-sdk'); 56 | 57 | const client = new ConnectClient(apiUrl, apiKey); 58 | const fulfillment = new Fulfillment(client); 59 | 60 | const purchaseRequest = await fulfillment.createRequest(requestObj); 61 | ``` 62 | 63 | > **_NOTE:_** Please refer to the *CloudBlue Connect API* documentation to know how a purchase request object is defined. 64 | 65 | #### Get the first 100 results of pending asset purchase requests 66 | 67 | ```js 68 | const { ConnectClient, Fulfillment } = require('@cloudblueconnect/connect-javascript-sdk'); 69 | 70 | const client = new ConnectClient(apiUrl, apiKey); 71 | const fulfillment = new Fulfillment(client); 72 | 73 | const filter = { 74 | status: 'pending', 75 | limit: 100, 76 | offset: 0 77 | } 78 | 79 | const pendingRequests = await fulfillment.search(filter); 80 | ``` 81 | 82 | > **_NOTE:_** Please see {@tutorial searches} for more informations on how to create filters. 83 | 84 | 85 | ## Direct access to public endpoints 86 | 87 | Each public endpoint of the *CloudBlue Connect API* is mapped by a "Resource" class that provides 88 | basic methods that implement CRUD operations against a resource. 89 | 90 | Moreover each "Resource" class exposes related actions and eventually access to subresources. 91 | 92 | Programmers can access "Resource" classes through the {@link ConnectClient} instance. 93 | 94 | ### Examples 95 | 96 | #### Get a list of users belonging to an account. 97 | 98 | ```js 99 | const { ConnectClient } = require('@cloudblueconnect/connect-javascript-sdk'); 100 | 101 | const client = new ConnectClient(apiUrl, apiKey); 102 | 103 | const users = client.accounts.users('VA-000-000').search(); 104 | ``` 105 | 106 | -------------------------------------------------------------------------------- /docs-src/tutorials/searches.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Querying endpoints", 3 | "children": [ 4 | ] 5 | } -------------------------------------------------------------------------------- /docs-src/tutorials/searches.md: -------------------------------------------------------------------------------- 1 | ## Resource Query Language 2 | 3 | The *CloudBlue Connect* public API supports the RQL query language to search, sort and paginate objects. 4 | 5 | A RQL query is a Javascript object that is defined according to the following typescript syntax: 6 | 7 | ``` 8 | interface IRQLFilter { 9 | $eq?: string|number, 10 | $ne?: string|number, 11 | $not?: IRQLFilter, 12 | $gt?: number, 13 | $ge?: number, 14 | $lt?: number, 15 | $le?: number, 16 | $like?: string, 17 | $ilike?: string, 18 | $empty?: boolean, 19 | $null?: boolean, 20 | $in?: Array, 21 | $out?: Array, 22 | $range?: { 23 | min: number, 24 | max: number, 25 | }, 26 | } 27 | 28 | 29 | interface IQueryFilters { 30 | $or?: Array; 31 | $ordering?: Array; 32 | limit?: number; 33 | offset?: number; 34 | [key: string]?: string|number|Array|boolean|IRQLFilter; 35 | } 36 | ``` 37 | 38 | ## Examples 39 | 40 | ### Simple filter 41 | 42 | ``` 43 | const filter = { 44 | name: 'eugene', 45 | age: 13, 46 | }; 47 | ``` 48 | 49 | ### Filter with text matching 50 | 51 | ``` 52 | const filter = { 53 | name: { 54 | $like: 'vasya*', 55 | $ilike: '***New', 56 | }, 57 | }; 58 | ``` 59 | 60 | ### Filter with list 61 | 62 | ``` 63 | const filter = { 64 | age: { 65 | $out: [1, 2], 66 | }, 67 | num: { 68 | $in: [3, 4, 5], 69 | }, 70 | }; 71 | ``` 72 | 73 | ### Filter with range 74 | 75 | ``` 76 | const filter = { 77 | age: { 78 | $range: { 79 | max: 5, 80 | min: 9, 81 | }, 82 | }, 83 | }; 84 | ``` 85 | 86 | ### Filter with relational 87 | 88 | ``` 89 | const filter = { 90 | name: { 91 | $eq: 'vasya', 92 | }, 93 | age: { 94 | $gt: 1, 95 | $lt: 8, 96 | }, 97 | num: { 98 | $lte: 9, 99 | $gte: 4, 100 | }, 101 | }; 102 | ``` 103 | 104 | ### Filter with logical NOT 105 | 106 | ``` 107 | const filter = { 108 | name: { 109 | $not: [{ 110 | $eq: 'vasya', 111 | }, { 112 | $eq: 'petya', 113 | }], 114 | }, 115 | age: { 116 | $not: { 117 | $eq: 10, 118 | $in: [1, 2, 3], 119 | }, 120 | }, 121 | }; 122 | ``` 123 | 124 | ### Filter with logical OR 125 | 126 | ``` 127 | const filter = { 128 | // You can use $or inside field 129 | color: { 130 | $or: [ 131 | // Inside { } may be some conditions and for all them is used logical operator AND 132 | { $eq: 'red' }, 133 | { $eq: 'blue' }, 134 | { $eq: 'yellow' }, 135 | ], 136 | }, 137 | 138 | 139 | // Also you can use $or in root level, then inside must be objects array with fields name 140 | $or: [ 141 | // Inside { } may be some fields with conditions and for all them is used logical operator AND 142 | { product: 'TV' }, 143 | { product: 'Computer' }, 144 | ], 145 | }; 146 | ``` 147 | 148 | ### Combine AND and OR filter 149 | 150 | ``` 151 | const filter = { 152 | $and: [ 153 | {$or: [ 154 | {status: 'new'}, 155 | {type: 'program'} 156 | ]}, 157 | {$or: [ 158 | {status: 'done'}, 159 | {type: 'service'} 160 | ]}, 161 | ] 162 | }; 163 | ``` 164 | 165 | ### Filter with control operators 166 | 167 | ``` 168 | const controlFilter = { 169 | limit: 100, 170 | offset: 0, 171 | $ordering: '-created', 172 | }; 173 | ``` 174 | 175 | ### Filter with empty values 176 | 177 | ``` 178 | // If values are empty, null, undefined then they will not be in the query. 179 | const filter = { 180 | $ordering: [], 181 | name: '', 182 | age: null, 183 | $or: [{name: undefined}], 184 | type: 'pending', 185 | }; 186 | ``` 187 | 188 | ### Combined 189 | 190 | ``` 191 | const combinationFilter = { 192 | offset: 0, 193 | limit: 10, 194 | $ordering: ['title', '-created'], 195 | $or: [ 196 | { 197 | type: 'distribution', 198 | owner: { $eq: 'me' }, 199 | }, 200 | { 201 | type: { $in: ['sourcing', 'service'] }, 202 | owner: { $not: { $eq: 'me' } }, 203 | }, 204 | ], 205 | name: { 206 | $or: [ 207 | { $like: 'my test' }, 208 | { $like: 'my' }, 209 | { $ilike: '***CONTRACT' }, 210 | ], 211 | }, 212 | }; 213 | ``` 214 | -------------------------------------------------------------------------------- /docs/images/connect_logo_fullname.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudblue/connect-javascript-sdk/78b3ba3c9d7855cbca427e4667de1fab86abfe7b/docs/images/connect_logo_fullname.png -------------------------------------------------------------------------------- /docs/scripts/app.min.js: -------------------------------------------------------------------------------- 1 | "use strict";$().ready(function(){});var sidebarIsVisible=!1,toggleSidebar=function(t){var i=!(0a&&window.pageYOffsete-o?t.find(".title").css({left:0,position:"absolute",bottom:"0",top:"auto"}):t.find(".title").css({left:i,bottom:"auto",position:"fixed",top:0}):t.find(".title").css({left:0,position:"absolute"})}var i=$(".vertical-section");if(0 a{ 6 | font-weight: 100; 7 | text-decoration: none; 8 | color: #BDC3CB; 9 | font-family: sans-serif; 10 | } 11 | .bd__button > a:hover { 12 | color: #798897; 13 | } -------------------------------------------------------------------------------- /docs/styles/prettify-jsdoc.css: -------------------------------------------------------------------------------- 1 | /* JSDoc prettify.js theme */ 2 | 3 | /* plain text */ 4 | .pln { 5 | color: #000000; 6 | font-weight: normal; 7 | font-style: normal; 8 | } 9 | 10 | /* string content */ 11 | .str { 12 | color: #006400; 13 | font-weight: normal; 14 | font-style: normal; 15 | } 16 | 17 | /* a keyword */ 18 | .kwd { 19 | color: #000000; 20 | font-weight: bold; 21 | font-style: normal; 22 | } 23 | 24 | /* a comment */ 25 | .com { 26 | font-weight: normal; 27 | font-style: italic; 28 | } 29 | 30 | /* a type name */ 31 | .typ { 32 | color: #000000; 33 | font-weight: normal; 34 | font-style: normal; 35 | } 36 | 37 | /* a literal value */ 38 | .lit { 39 | color: #006400; 40 | font-weight: normal; 41 | font-style: normal; 42 | } 43 | 44 | /* punctuation */ 45 | .pun { 46 | color: #000000; 47 | font-weight: bold; 48 | font-style: normal; 49 | } 50 | 51 | /* lisp open bracket */ 52 | .opn { 53 | color: #000000; 54 | font-weight: bold; 55 | font-style: normal; 56 | } 57 | 58 | /* lisp close bracket */ 59 | .clo { 60 | color: #000000; 61 | font-weight: bold; 62 | font-style: normal; 63 | } 64 | 65 | /* a markup tag name */ 66 | .tag { 67 | color: #006400; 68 | font-weight: normal; 69 | font-style: normal; 70 | } 71 | 72 | /* a markup attribute name */ 73 | .atn { 74 | color: #006400; 75 | font-weight: normal; 76 | font-style: normal; 77 | } 78 | 79 | /* a markup attribute value */ 80 | .atv { 81 | color: #006400; 82 | font-weight: normal; 83 | font-style: normal; 84 | } 85 | 86 | /* a declaration */ 87 | .dec { 88 | color: #000000; 89 | font-weight: bold; 90 | font-style: normal; 91 | } 92 | 93 | /* a variable name */ 94 | .var { 95 | color: #000000; 96 | font-weight: normal; 97 | font-style: normal; 98 | } 99 | 100 | /* a function name */ 101 | .fun { 102 | color: #000000; 103 | font-weight: bold; 104 | font-style: normal; 105 | } 106 | 107 | /* Specify class=linenums on a pre to get line numbering */ 108 | ol.linenums { 109 | margin-top: 0; 110 | margin-bottom: 0; 111 | } 112 | -------------------------------------------------------------------------------- /docs/styles/prettify-tomorrow.css: -------------------------------------------------------------------------------- 1 | /* Tomorrow Theme */ 2 | /* Original theme - https://github.com/chriskempson/tomorrow-theme */ 3 | /* Pretty printing styles. Used with prettify.js. */ 4 | /* SPAN elements with the classes below are added by prettyprint. */ 5 | /* plain text */ 6 | .pln { 7 | color: #4d4d4c; } 8 | 9 | @media screen { 10 | /* string content */ 11 | .str { 12 | color: #718c00; } 13 | 14 | /* a keyword */ 15 | .kwd { 16 | color: #8959a8; } 17 | 18 | /* a comment */ 19 | .com { 20 | color: #8e908c; } 21 | 22 | /* a type name */ 23 | .typ { 24 | color: #4271ae; } 25 | 26 | /* a literal value */ 27 | .lit { 28 | color: #f5871f; } 29 | 30 | /* punctuation */ 31 | .pun { 32 | color: #4d4d4c; } 33 | 34 | /* lisp open bracket */ 35 | .opn { 36 | color: #4d4d4c; } 37 | 38 | /* lisp close bracket */ 39 | .clo { 40 | color: #4d4d4c; } 41 | 42 | /* a markup tag name */ 43 | .tag { 44 | color: #c82829; } 45 | 46 | /* a markup attribute name */ 47 | .atn { 48 | color: #f5871f; } 49 | 50 | /* a markup attribute value */ 51 | .atv { 52 | color: #3e999f; } 53 | 54 | /* a declaration */ 55 | .dec { 56 | color: #f5871f; } 57 | 58 | /* a variable name */ 59 | .var { 60 | color: #c82829; } 61 | 62 | /* a function name */ 63 | .fun { 64 | color: #4271ae; } } 65 | /* Use higher contrast and text-weight for printable form. */ 66 | @media print, projection { 67 | .str { 68 | color: #060; } 69 | 70 | .kwd { 71 | color: #006; 72 | font-weight: bold; } 73 | 74 | .com { 75 | color: #600; 76 | font-style: italic; } 77 | 78 | .typ { 79 | color: #404; 80 | font-weight: bold; } 81 | 82 | .lit { 83 | color: #044; } 84 | 85 | .pun, .opn, .clo { 86 | color: #440; } 87 | 88 | .tag { 89 | color: #006; 90 | font-weight: bold; } 91 | 92 | .atn { 93 | color: #404; } 94 | 95 | .atv { 96 | color: #060; } } 97 | /* Style */ 98 | /* 99 | pre.prettyprint { 100 | background: white; 101 | font-family: Consolas, Monaco, 'Andale Mono', monospace; 102 | font-size: 12px; 103 | line-height: 1.5; 104 | border: 1px solid #ccc; 105 | padding: 10px; } 106 | */ 107 | 108 | /* Specify class=linenums on a pre to get line numbering */ 109 | ol.linenums { 110 | margin-top: 0; 111 | margin-bottom: 0; } 112 | 113 | /* IE indents via margin-left */ 114 | li.L0, 115 | li.L1, 116 | li.L2, 117 | li.L3, 118 | li.L4, 119 | li.L5, 120 | li.L6, 121 | li.L7, 122 | li.L8, 123 | li.L9 { 124 | /* */ } 125 | 126 | /* Alternate shading for lines */ 127 | li.L1, 128 | li.L3, 129 | li.L5, 130 | li.L7, 131 | li.L9 { 132 | /* */ } 133 | -------------------------------------------------------------------------------- /docs/styles/reset.css: -------------------------------------------------------------------------------- 1 | /* reset css */ 2 | html, body, div, span, applet, object, iframe, 3 | h1, h2, h3, h4, h5, h6, p, blockquote, pre, 4 | a, abbr, acronym, address, big, cite, code, 5 | del, dfn, em, img, ins, kbd, q, s, samp, 6 | small, strike, strong, sub, sup, tt, var, 7 | b, u, i, center, 8 | dl, dt, dd, ol, ul, li, 9 | fieldset, form, label, legend, 10 | table, caption, tbody, tfoot, thead, tr, th, td, 11 | article, aside, canvas, details, embed, 12 | figure, figcaption, footer, header, hgroup, 13 | menu, nav, output, ruby, section, summary, 14 | time, mark, audio, video { 15 | margin: 0; 16 | padding: 0; 17 | border: 0; 18 | font-size: 100%; 19 | font: inherit; 20 | vertical-align: baseline; 21 | } 22 | /* HTML5 display-role reset for older browsers */ 23 | article, aside, details, figcaption, figure, 24 | footer, header, hgroup, menu, nav, section { 25 | display: block; 26 | } 27 | body { 28 | line-height: 1; 29 | } 30 | ol, ul { 31 | list-style: none; 32 | } 33 | blockquote, q { 34 | quotes: none; 35 | } 36 | blockquote:before, blockquote:after, 37 | q:before, q:after { 38 | content: ''; 39 | content: none; 40 | } 41 | table { 42 | border-collapse: collapse; 43 | border-spacing: 0; 44 | } 45 | -------------------------------------------------------------------------------- /examples/apiary_scenarios/asset_accept_workflow.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | const { ConnectClient, Fulfillment } = require('@cloudblueconnect/connect-javascript-sdk'); 7 | const fetch = require('node-fetch'); 8 | const config = require('./config.json'); 9 | 10 | /* eslint-disable no-console */ 11 | 12 | /** 13 | * This module is an example of fulfillment flow between 14 | * Cloudblue Connect and Vendor System. 15 | * This connect with the Vendor System using an 16 | * example of API Vendor System implemented in apiary.io 17 | * and documented in the Cloudblue Connect Documentation Portal: 18 | * https://connect.cloudblue.com/community/sdk/vendor-scenario-example/fulfillment/ 19 | * 20 | * This module accept the Purchase Request into Connect when the tenant is ready in Vendor System. 21 | * 22 | * @category Operations 23 | */ 24 | const client = new ConnectClient( 25 | config.url, 26 | config.apiKey, 27 | ); 28 | const fulfillment = new Fulfillment(client); 29 | const urlBase = 'https://SET_YOUR_OWN_SAMPLE.apiary-mock.com/'; 30 | 31 | let tenantIdParam; 32 | let templateIdParam; 33 | 34 | /** 35 | * Process Purchase Request into Cloudblue Connect 36 | * 37 | * @param {object} element The request of Cloudblue Connect. 38 | * 39 | */ 40 | const processRequest = async (element) => { 41 | if (element.type === 'purchase') { 42 | element.asset.params.forEach((param) => { 43 | if (param.id === 'tenantId') { 44 | tenantIdParam = param.value; 45 | } 46 | }); 47 | if (tenantIdParam !== '') { 48 | element.asset.configuration.params.forEach((param) => { 49 | if (param.id === 'templateId') { 50 | templateIdParam = param.value; 51 | } 52 | }); 53 | const body = { 54 | template_id: templateIdParam, 55 | }; 56 | const responseApprove = await fulfillment.approveRequest(element.id, body); 57 | console.log(responseApprove); 58 | } else { 59 | throw new Error('This Tenant not exist in vendor'); 60 | } 61 | } else { 62 | console.log('This processor not handle this type of request'); 63 | } 64 | }; 65 | 66 | /** 67 | * Check if the request is ready into Vendor Portal 68 | * 69 | * @param {object} requests The request of Cloudblue Connect. 70 | * 71 | */ 72 | const checkTenant = async (requests) => { 73 | requests.forEach(async (element) => { 74 | // Verificamos si existe el tennant 75 | const urlGet = `${urlBase}/tenant?externalId=${element.asset.id}`; 76 | const res = await fetch(urlGet); 77 | const json = await res.json(); 78 | if (json.status === 'ready') { 79 | await processRequest(element); 80 | } else { 81 | throw new Error('This Tenant is in process or not exist yet'); 82 | } 83 | }); 84 | }; 85 | 86 | const main = async () => { 87 | const requests = await fulfillment.searchRequests(); 88 | await checkTenant(requests); 89 | }; 90 | 91 | 92 | main().catch((e) => console.log(e)); 93 | -------------------------------------------------------------------------------- /examples/apiary_scenarios/asset_request_workflow.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | const { ConnectClient, Fulfillment } = require('@cloudblueconnect/connect-javascript-sdk'); 7 | const fetch = require('node-fetch'); 8 | const config = require('./config.json'); 9 | 10 | /* eslint-disable no-console */ 11 | 12 | /** 13 | * This module is an example of fulfillment flow between 14 | * Cloudblue Connect and Vendor System. 15 | * This connect with the Vendor System using an 16 | * example of API Vendor System implemented in apiary.io 17 | * and documented in the Cloudblue Connect Documentation Portal: 18 | * https://connect.cloudblue.com/community/sdk/vendor-scenario-example/fulfillment/ 19 | * 20 | * This module creates a tenant in the Vendor System when is created in Cloudblue Connect. 21 | * 22 | * @category Operations 23 | */ 24 | const client = new ConnectClient( 25 | config.url, 26 | config.apiKey, 27 | ); 28 | const fulfillment = new Fulfillment(client); 29 | const urlBase = 'https://SET_YOUR_OWN_SAMPLE.apiary-mock.com/'; 30 | 31 | let tenantIdParam; 32 | 33 | /** 34 | * Create tenant into Vendor System 35 | * 36 | * @param {object} element The request of Cloudblue Connect. 37 | * 38 | */ 39 | const createTenant = async (element) => { 40 | let mpn; 41 | let quantity; 42 | if (element.asset.items && (element.asset.items.length === 1)) { 43 | element.asset.items.forEach((item) => { 44 | mpn = item.mpn; 45 | quantity = item.quantity; 46 | }); 47 | } else { 48 | throw new Error('Malformed request, bad quantity of item'); 49 | } 50 | const payload = { 51 | Attributes: { 52 | product: { mpn, quantity }, 53 | account: { 54 | accountFirstName: element.asset.tiers.customer.contact_info.contact.first_name, 55 | accountLastName: element.asset.tiers.customer.contact_info.contact.last_name, 56 | accountCompany: element.asset.tiers.customer.name, 57 | accountAddress: element.asset.tiers.customer.contact_info.address_line1, 58 | accountCity: element.asset.tiers.customer.contact_info.city, 59 | accountState: element.asset.tiers.customer.contact_info.state, 60 | accountPostalCode: element.asset.tiers.customer.contact_info.postal_code, 61 | accountCountry: element.asset.tiers.customer.contact_info.country, 62 | accountEmail: element.asset.tiers.customer.contact_info.contact.email, 63 | accountPhone: element.asset.tiers.customer.contact_info.contact.phone_number.phone_number, 64 | }, 65 | }, 66 | }; 67 | let data = await fetch(`${urlBase}/tenant`, { 68 | method: 'POST', 69 | headers: { 70 | 'Content-Type': 'application/json', 71 | }, 72 | body: JSON.stringify(payload), 73 | cache: 'no-cache', 74 | }); 75 | data = await data.json(); 76 | element.asset.params.forEach(async (param) => { 77 | if (param.id === 'tenantId') { 78 | const requests = await fulfillment.updateRequestParameters(element.id, [{ id: 'tenantId', value: data.tenantId }], 'Id of vendor system tenant'); 79 | console.log(requests); 80 | } 81 | }); 82 | }; 83 | 84 | 85 | /** 86 | * Check if the request exist into Vendor Portal 87 | * 88 | * @param {object} requests The request of Cloudblue Connect. 89 | * 90 | */ 91 | const checkTenant = async (requests) => { 92 | requests.forEach(async (element) => { 93 | if (element.type === 'purchase') { 94 | element.asset.params.forEach((param) => { 95 | console.log('param.id', param.id); 96 | if (param.id === 'tenantId') { 97 | tenantIdParam = param.value; 98 | } 99 | }); 100 | if (tenantIdParam === '') { 101 | console.log(element); 102 | await createTenant(element); 103 | } else { 104 | throw new Error('This Tenant exist in vendor'); 105 | } 106 | } else { 107 | console.log('This processor not handle this type of request'); 108 | } 109 | }); 110 | }; 111 | 112 | 113 | const main = async () => { 114 | const requests = await fulfillment.searchRequests(); 115 | await checkTenant(requests); 116 | }; 117 | 118 | 119 | main().catch((e) => console.log(e)); 120 | -------------------------------------------------------------------------------- /examples/apiary_scenarios/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "url": "https://api.connect.cloudblue.com/public/v1", 3 | "apiKey": "ApiKey SU-000-000-000:000000000000000000000000000000000000000000000" 4 | } -------------------------------------------------------------------------------- /examples/apiary_scenarios/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "apiary_scenarios", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "license": "Apache-2.0", 6 | "dependencies": { 7 | "@cloudblueconnect/connect-javascript-sdk": "^20.0", 8 | "node-fetch": "^3.1.1" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /examples/apiary_scenarios/yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | "@cloudblueconnect/connect-javascript-sdk@^20.0": 6 | version "20.0.1" 7 | resolved "https://registry.yarnpkg.com/@cloudblueconnect/connect-javascript-sdk/-/connect-javascript-sdk-20.0.1.tgz#38330e8186a8e1803fc76dde46c5e82d512b421d" 8 | integrity sha512-LVOGoqpQ52we9zZTe1zODEGKaOklkABpxj8cYMIyZH4xFUMxpzF9+BkH9rcPqmNeBbqa6OApYNObAYqo4N/9ZA== 9 | dependencies: 10 | node-fetch "^2.6.0" 11 | ramda "^0.26.1" 12 | 13 | data-uri-to-buffer@^4.0.0: 14 | version "4.0.0" 15 | resolved "https://registry.yarnpkg.com/data-uri-to-buffer/-/data-uri-to-buffer-4.0.0.tgz#b5db46aea50f6176428ac05b73be39a57701a64b" 16 | integrity sha512-Vr3mLBA8qWmcuschSLAOogKgQ/Jwxulv3RNE4FXnYWRGujzrRWQI4m12fQqRkwX06C0KanhLr4hK+GydchZsaA== 17 | 18 | fetch-blob@^3.1.2, fetch-blob@^3.1.4: 19 | version "3.1.5" 20 | resolved "https://registry.yarnpkg.com/fetch-blob/-/fetch-blob-3.1.5.tgz#0077bf5f3fcdbd9d75a0b5362f77dbb743489863" 21 | integrity sha512-N64ZpKqoLejlrwkIAnb9iLSA3Vx/kjgzpcDhygcqJ2KKjky8nCgUQ+dzXtbrLaWZGZNmNfQTsiQ0weZ1svglHg== 22 | dependencies: 23 | node-domexception "^1.0.0" 24 | web-streams-polyfill "^3.0.3" 25 | 26 | formdata-polyfill@^4.0.10: 27 | version "4.0.10" 28 | resolved "https://registry.yarnpkg.com/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz#24807c31c9d402e002ab3d8c720144ceb8848423" 29 | integrity sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g== 30 | dependencies: 31 | fetch-blob "^3.1.2" 32 | 33 | node-domexception@^1.0.0: 34 | version "1.0.0" 35 | resolved "https://registry.yarnpkg.com/node-domexception/-/node-domexception-1.0.0.tgz#6888db46a1f71c0b76b3f7555016b63fe64766e5" 36 | integrity sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ== 37 | 38 | node-fetch@^2.6.0: 39 | version "2.6.7" 40 | resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad" 41 | integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ== 42 | dependencies: 43 | whatwg-url "^5.0.0" 44 | 45 | node-fetch@^3.1.1: 46 | version "3.2.4" 47 | resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-3.2.4.tgz#3fbca2d8838111048232de54cb532bd3cf134947" 48 | integrity sha512-WvYJRN7mMyOLurFR2YpysQGuwYrJN+qrrpHjJDuKMcSPdfFccRUla/kng2mz6HWSBxJcqPbvatS6Gb4RhOzCJw== 49 | dependencies: 50 | data-uri-to-buffer "^4.0.0" 51 | fetch-blob "^3.1.4" 52 | formdata-polyfill "^4.0.10" 53 | 54 | ramda@^0.26.1: 55 | version "0.26.1" 56 | resolved "https://registry.yarnpkg.com/ramda/-/ramda-0.26.1.tgz#8d41351eb8111c55353617fc3bbffad8e4d35d06" 57 | integrity sha512-hLWjpy7EnsDBb0p+Z3B7rPi3GDeRG5ZtiI33kJhTt+ORCd38AbAIjB/9zRIUoeTbE/AVX5ZkU7m6bznsvrf8eQ== 58 | 59 | tr46@~0.0.3: 60 | version "0.0.3" 61 | resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a" 62 | integrity sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o= 63 | 64 | web-streams-polyfill@^3.0.3: 65 | version "3.2.1" 66 | resolved "https://registry.yarnpkg.com/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz#71c2718c52b45fd49dbeee88634b3a60ceab42a6" 67 | integrity sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q== 68 | 69 | webidl-conversions@^3.0.0: 70 | version "3.0.1" 71 | resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871" 72 | integrity sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE= 73 | 74 | whatwg-url@^5.0.0: 75 | version "5.0.0" 76 | resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d" 77 | integrity sha1-lmRU6HZUYuN2RNNib2dCzotwll0= 78 | dependencies: 79 | tr46 "~0.0.3" 80 | webidl-conversions "^3.0.0" 81 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | 7 | module.exports = require('./lib/connect'); 8 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | // For a detailed explanation regarding each configuration property, visit: 2 | // https://jestjs.io/docs/en/configuration.html 3 | 4 | module.exports = { 5 | collectCoverage: true, 6 | collectCoverageFrom: ['lib/**/*.js'], 7 | coverageDirectory: 'coverage', 8 | setupFiles: [ 9 | './tests/helpers/setup.js' 10 | ], 11 | testEnvironment: 'node', 12 | verbose: true, 13 | }; 14 | -------------------------------------------------------------------------------- /jsdoc.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | source: { 3 | include: ['lib', 'README.md'], 4 | exclude: [ 5 | 'lib/connect/ops/index.js', 6 | 'lib/connect/api/index.js', 7 | ], 8 | includePattern: '.+\\.js(doc|x)?$', 9 | excludePattern: '(^|\\/|\\\\)_', 10 | }, 11 | templates: { 12 | cleverLinks: false, 13 | monospaceLinks: false, 14 | default: { 15 | staticFiles: { 16 | include: [ 17 | './docs-src/statics', 18 | ], 19 | }, 20 | outputSourceFiles: false, 21 | includeDate: false, 22 | }, 23 | 'connect-jsdoc-theme': { 24 | name: 'CloudBlue Connect Javascript SDK', 25 | logo: 'images/connect_logo_fullname.png', 26 | homeTitle: 'Welcome!', 27 | hideGenerator: false, 28 | navigation: [ 29 | { 30 | label: 'Github', 31 | href: 'https://github.com/cloudblue/connect-javascript-sdk', 32 | }, 33 | { 34 | label: 'CloudBlue Connect', 35 | href: 'https://www.cloudblue.com/connect/', 36 | }, 37 | ], 38 | }, 39 | }, 40 | tags: { 41 | allowUnknownTags: true, 42 | }, 43 | plugins: [ 44 | 'plugins/markdown', 45 | './node_modules/@cloudblueconnect/connect-jsdoc-theme/category', 46 | ], 47 | opts: { 48 | template: './node_modules/@cloudblueconnect/connect-jsdoc-theme', 49 | recurse: true, 50 | verbose: false, 51 | readme: 'README.md', 52 | destination: './docs', 53 | tutorials: './docs-src/tutorials', 54 | }, 55 | }; 56 | -------------------------------------------------------------------------------- /lib/connect/api/accounts.js: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | /* eslint-disable max-classes-per-file */ 7 | 8 | 9 | const { identity, memoizeWith } = require('ramda'); 10 | 11 | const GenericResource = require('./base'); 12 | 13 | /** 14 | * The *AccountUserResource* allow consumers of the CloudBlue Connect 15 | * API to access information about *Users* related to an account. 16 | * 17 | * @extends GenericResource 18 | * @category Resources 19 | */ 20 | class AccountUserResource extends GenericResource {} 21 | 22 | /** 23 | * The *AccountResource* class provides methods to access the accounts 24 | * endpoint of the Cloud Blue Connect API. 25 | * 26 | * @extends GenericResource 27 | * @category Resources 28 | */ 29 | class AccountResource extends GenericResource { 30 | /** 31 | * Creates a new instance of the *AccountResource* class. 32 | * 33 | * @param {ConnectClient} client An instance of the *ConnectClient* class. 34 | * 35 | * @returns {AccountResource} An instance of the *AccountResource* class. 36 | */ 37 | constructor(client) { 38 | super(client, '/accounts'); 39 | this.users = memoizeWith(identity, this.users); 40 | } 41 | 42 | /** 43 | * Returns an instance of the *AccountUserResorce* class. 44 | * 45 | * @param {string} id The account unique identifier. 46 | * 47 | * @returns {AccountUserResource} An instance of *AccountUserResource*. 48 | */ 49 | users(id) { 50 | return new AccountUserResource(this._client, `${this.baseUri}/${id}/users`); 51 | } 52 | } 53 | 54 | module.exports = AccountResource; 55 | -------------------------------------------------------------------------------- /lib/connect/api/assets.js: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | 7 | /* eslint-disable max-classes-per-file */ 8 | 9 | const { memoizeWith, identity } = require('ramda'); 10 | const GenericResource = require('./base'); 11 | 12 | /** 13 | * The *AssetUsageAgregatesResource* class provides methods to access the 14 | * *AssetUsageAgregates* objects for a asset. 15 | * 16 | * @extends GenericResource 17 | * @category Resources 18 | */ 19 | class AssetUsageAgregatesResource extends GenericResource {} 20 | 21 | /** 22 | * The *AssetResource* class provides methods to access the assets 23 | * endpoint of the Cloud Blue Connect API. 24 | * 25 | * @extends GenericResource 26 | * @category Resources 27 | */ 28 | class AssetResource extends GenericResource { 29 | /** 30 | * Creates a new instance of the *AssetResource* class. 31 | * 32 | * @param {ConnectClient} client An instance of the *ConnectClient* class. 33 | * 34 | * @returns {AssetResource} An instance of the *AssetResource* class. 35 | */ 36 | constructor(client) { 37 | super(client, '/assets'); 38 | this.usageAgregates = memoizeWith(identity, this.usageAgregates); 39 | } 40 | 41 | /** 42 | * Returns an instance of the *AssetUsageAgregatesResource* for a *Asset*. 43 | * 44 | * @param {string} id The unique identifier of the *Product*. 45 | * 46 | * @returns {AssetUsageAgregatesResource} An instance of the *AssetUsageAgregatesResource* 47 | * for the asset. 48 | */ 49 | usageAgregates(id) { 50 | return new AssetUsageAgregatesResource(this._client, `${this.baseUri}/${id}/usage/agregates`); 51 | } 52 | } 53 | 54 | module.exports = AssetResource; 55 | -------------------------------------------------------------------------------- /lib/connect/api/base.js: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | 7 | const { buildUrl } = require('./utils'); 8 | const { HttpError, APIError } = require('./errors'); 9 | 10 | 11 | /** 12 | * The *GenericResource* map a generic endpoint of the CloudBlue 13 | * Connect API. Each API endpoint should extend this class and 14 | * implements endpoint specific actions and subresources access. 15 | * 16 | * @category Resources 17 | */ 18 | class GenericResource { 19 | /** 20 | * 21 | * @param {ConnectClient} client A *ConnectClient* instance. 22 | * @param {string} baseUri The base URI of the resource 23 | */ 24 | constructor(client, baseUri) { 25 | this._client = client; 26 | this._baseUri = baseUri; 27 | } 28 | 29 | /** 30 | * Returns the base URI of the resource mapped by this class. 31 | * 32 | * @type {string} 33 | */ 34 | get baseUri() { 35 | return this._baseUri; 36 | } 37 | 38 | /** 39 | * Retrieve a resource by its unique identifier. 40 | * 41 | * @param {string} id The unique identifier of the resource to retrieve. 42 | * 43 | * @returns {object} The resource. 44 | */ 45 | async get(id) { 46 | const url = `${this.baseUri}/${id}`; 47 | const response = await this.fetch(url); 48 | return response.json(); 49 | } 50 | 51 | /** 52 | * Create a new resource. 53 | * 54 | * @param {object} obj The resource to create. 55 | * 56 | * @returns {object} The created resource. 57 | */ 58 | async create(obj) { 59 | const options = { 60 | method: 'POST', 61 | body: obj, 62 | }; 63 | const response = await this.fetch(this.baseUri, options); 64 | return response.json(); 65 | } 66 | 67 | /** 68 | * Update a resource. 69 | * 70 | * @param {string} id The unique identifier of the resource to update. 71 | * @param {object} obj The eventually partial resource to update. 72 | * 73 | * @returns {object} The updated resource. 74 | */ 75 | async update(id, obj) { 76 | const url = `${this.baseUri}/${id}`; 77 | const options = { 78 | method: 'PUT', 79 | body: obj, 80 | }; 81 | const response = await this.fetch(url, options); 82 | return response.json(); 83 | } 84 | 85 | /** 86 | * Delete a resource. 87 | * 88 | * @param {string} id The unique identifier of the resource to delete. 89 | * 90 | */ 91 | async delete(id) { 92 | const url = `${this.baseUri}/${id}`; 93 | const options = { 94 | method: 'DELETE', 95 | }; 96 | await this.fetch(url, options); 97 | } 98 | 99 | /** 100 | * Search for a resource. 101 | * 102 | * @param {object} filters The query to send to the server as a RQL object. 103 | * 104 | * @returns {Array} An array of resources that match the provided filters. 105 | */ 106 | async search(filters) { 107 | const response = await this.fetch(buildUrl(this.baseUri, filters)); 108 | return response.json(); 109 | } 110 | 111 | /** 112 | * Fetch the URL and returns a response. 113 | * 114 | * @param {string} url the URL to fetch. 115 | * @param {object} options the request options. 116 | */ 117 | async fetch(url, options) { 118 | const response = await this._client.fetch(url, options); 119 | if (!response.ok) { 120 | if (response.headers.get('content-type') === 'application/json') { 121 | throw new APIError(response.status, await response.text()); 122 | } 123 | throw new HttpError(response.status, await response.text()); 124 | } 125 | return Promise.resolve(response); 126 | } 127 | } 128 | 129 | module.exports = GenericResource; 130 | -------------------------------------------------------------------------------- /lib/connect/api/billingRequests.js: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | 7 | const GenericResource = require('./base'); 8 | /** 9 | * The *BillingRequestResource* class provides methods to access the billing 10 | * requests endpoint of the Cloud Blue Connect API. 11 | * 12 | * @extends GenericResource 13 | * @category Resources 14 | */ 15 | class BillingRequestResource extends GenericResource { 16 | /** 17 | * Creates a new instance of the *BillingRequestResource* class. 18 | * 19 | * @param {ConnectClient} client An instance of the ConnectClient class. 20 | * 21 | * @returns {BillingRequestResource} An instance of the *BillingRequestResource* class. 22 | */ 23 | constructor(client) { 24 | super(client, '/subscriptions/requests'); 25 | } 26 | 27 | /** 28 | * Update billing request attributs. 29 | * 30 | * @param {string} id The unique identified of the *BillingRequest*. 31 | * @param {object} attributes An object containing the attributes to update. 32 | * 33 | * @returns {object} The updated attributes object. 34 | */ 35 | async updateAttributes(id, attributes) { 36 | const url = `${this.baseUri}/${id}/attributes`; 37 | const options = { 38 | method: 'PUT', 39 | body: attributes, 40 | }; 41 | const response = await this.fetch(url, options); 42 | return response.json(); 43 | } 44 | } 45 | 46 | module.exports = BillingRequestResource; 47 | -------------------------------------------------------------------------------- /lib/connect/api/conversations.js: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | 7 | /* eslint-disable max-classes-per-file */ 8 | 9 | const { memoizeWith, identity } = require('ramda'); 10 | 11 | 12 | const { buildUrl } = require('./utils'); 13 | 14 | const GenericResource = require('./base'); 15 | 16 | /** 17 | * The *MessageResources* class provides methods to access the 18 | * *attachment* objects for a case. 19 | * 20 | * @extends GenericResource 21 | * @category Resources 22 | */ 23 | class MessageResource extends GenericResource {} 24 | 25 | /** 26 | * The *ConversationResource* class provides methods to access the conversations 27 | * endpoint of the Cloud Blue Connect API. 28 | * 29 | * @extends GenericResource 30 | * @category Resources 31 | */ 32 | class ConversationResource extends GenericResource { 33 | /** 34 | * Creates a new instance of the *ConversationResource* class. 35 | * 36 | * @param {ConnectClient} client An instance of the ConnectClient class. 37 | * 38 | * @returns {ConversationResource} An instance of the *ConversationResource* class. 39 | */ 40 | constructor(client) { 41 | super(client, '/conversations'); 42 | this.messages = memoizeWith(identity, this.messages); 43 | } 44 | 45 | /** 46 | * Returns an instance of the *ConversationMessageResource* for a *Conversation*. 47 | * 48 | * @param {string} id The unique identifier of the *Conversation*. 49 | * 50 | * @returns {CaseCommentsResource} An instance of the *ConversationMessageResource* 51 | * for the case. 52 | */ 53 | messages(id) { 54 | return new MessageResource(this._client, `${this.baseUri}/${id}/messages`); 55 | } 56 | 57 | /** 58 | * Returns a list of conversations attached to the business object specified by its id. 59 | * 60 | * @param {string} id The unique id of the business object attached to a conversation. 61 | * 62 | * @returns {Array} A list of conversations attached to a business object. 63 | */ 64 | async getConversationsByObjectId(id) { 65 | const url = buildUrl(this.baseUri, { instance_id: id }); 66 | const response = await this.fetch(url); 67 | return response.json(); 68 | } 69 | 70 | /** 71 | * Add a message to a *Conversation* object. 72 | * 73 | * @param {string} id The unique identifier of the Conversation object. 74 | * @param {string} msg The text of the message to post. 75 | * 76 | * @returns {object} The newly created *Message* object. 77 | */ 78 | async createMessage(id, msg) { 79 | const url = `/conversations/${id}/messages`; 80 | const options = { 81 | method: 'POST', 82 | body: { 83 | text: msg, 84 | }, 85 | }; 86 | const response = await this.fetch(url, options); 87 | return response.json(); 88 | } 89 | } 90 | 91 | module.exports = ConversationResource; 92 | -------------------------------------------------------------------------------- /lib/connect/api/errors.js: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | 7 | /* eslint-disable max-classes-per-file */ 8 | 9 | /** 10 | * HttpError wraps any http response which status is != 2xx. 11 | * 12 | * @extends Error 13 | * @category Base 14 | */ 15 | class HttpError extends Error { 16 | /** 17 | * Create a new instance of the HttpError class. 18 | * 19 | * @param {number} status the http status code. 20 | * @param {string} message an error message. 21 | */ 22 | constructor(status, message) { 23 | super(message); 24 | /** 25 | * The http status code. 26 | * 27 | * @type {number} 28 | */ 29 | this.status = status; 30 | } 31 | } 32 | 33 | /** 34 | * APIError wraps CloudBlue Connect API errors. 35 | * Provides convenient methods to obtains error 36 | * code and error messages. 37 | * The Cloud Blue Connect JSON error looks like: 38 | * 39 | * @example 40 | * { 41 | * "error_code": "SYS_001", 42 | * "errors": [ 43 | * "error message 1" 44 | * ] 45 | * } 46 | * 47 | * @extends HttpError 48 | * @category Resources 49 | */ 50 | class APIError extends HttpError { 51 | /** 52 | * Create a new instance of the APIError class. 53 | * 54 | * @category Base 55 | * @param {number} status the http status code. 56 | * @param {string} message A JSON parseable object. 57 | */ 58 | constructor(status, message) { 59 | super(status, message); 60 | this._json = JSON.parse(message); 61 | } 62 | 63 | /** 64 | * Returns the JSON error object. 65 | * 66 | * @returns {object} The error object. 67 | */ 68 | get json() { 69 | return this._json; 70 | } 71 | 72 | /** 73 | * Returns the error code. 74 | * 75 | * @returns {string} The error code. 76 | */ 77 | get errorCode() { 78 | return this._json.error_code; 79 | } 80 | 81 | /** 82 | * Returns an array of error messages. 83 | * 84 | * @returns {Array} The error messages. 85 | */ 86 | get errors() { 87 | return this._json.errors; 88 | } 89 | } 90 | module.exports = { APIError, HttpError }; 91 | -------------------------------------------------------------------------------- /lib/connect/api/hubs.js: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | 7 | const GenericResource = require('./base'); 8 | 9 | /** 10 | * The *HubResource* class provides methods to access the hubs 11 | * endpoint of the Cloud Blue Connect API. 12 | * 13 | * @extends GenericResource 14 | * @category Resources 15 | */ 16 | class HubResource extends GenericResource { 17 | /** 18 | * Creates a new instance of the *HubResource* class. 19 | * 20 | * @param {ConnectClient} client An instance of the *ConnectClient* class. 21 | * 22 | * @returns {HubResource} An instance of the *HubResource* class. 23 | */ 24 | constructor(client) { 25 | super(client, '/hubs'); 26 | } 27 | } 28 | 29 | module.exports = HubResource; 30 | -------------------------------------------------------------------------------- /lib/connect/api/index.js: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | 7 | const GenericResource = require('./base'); 8 | const RequestResource = require('./requests'); 9 | const AccountResource = require('./accounts'); 10 | const AssetResource = require('./assets'); 11 | const BillingRequestResource = require('./billingRequests'); 12 | const ProductResource = require('./products'); 13 | const ConversationResource = require('./conversations'); 14 | const HubResource = require('./hubs'); 15 | const RecurringAssetResource = require('./recurringAssets'); 16 | const TierAccountResource = require('./tierAccounts'); 17 | const TierAccountRequestResource = require('./tierAccountRequests'); 18 | const TierConfigResource = require('./tierConfigs'); 19 | const TierConfigRequestResource = require('./tierConfigRequests'); 20 | const WebhookResource = require('./webhooks'); 21 | const ListingRequestResource = require('./listingRequests'); 22 | const CaseResource = require('./cases'); 23 | const UsageFileResource = require('./usageFiles'); 24 | const UsageChunkResource = require('./usageChunks'); 25 | const UsageRecordResource = require('./usageRecords'); 26 | const UsageReconciliationResource = require('./usageReconciliations'); 27 | const UsageAggregateResource = require('./usageAggregates'); 28 | 29 | 30 | module.exports = { 31 | GenericResource, 32 | AccountResource, 33 | AssetResource, 34 | BillingRequestResource, 35 | ProductResource, 36 | RequestResource, 37 | ConversationResource, 38 | HubResource, 39 | RecurringAssetResource, 40 | TierAccountResource, 41 | TierAccountRequestResource, 42 | TierConfigResource, 43 | TierConfigRequestResource, 44 | WebhookResource, 45 | ListingRequestResource, 46 | CaseResource, 47 | UsageFileResource, 48 | UsageChunkResource, 49 | UsageRecordResource, 50 | UsageReconciliationResource, 51 | UsageAggregateResource, 52 | }; 53 | -------------------------------------------------------------------------------- /lib/connect/api/listingRequests.js: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | 7 | const GenericResource = require('./base'); 8 | /** 9 | * The *ListingRequestResource* class provides methods to access the listing 10 | * requests endpoint of the Cloud Blue Connect API. 11 | * 12 | * @extends GenericResource 13 | * @category Resources 14 | */ 15 | class ListingRequestResource extends GenericResource { 16 | /** 17 | * Creates a new instance of the *ListingRequestResource* class. 18 | * 19 | * @param {ConnectClient} client An instance of the ConnectClient class. 20 | * 21 | * @returns {ListingRequestResource} An instance of the *ListingRequestResource* class. 22 | */ 23 | constructor(client) { 24 | super(client, '/listing-requests'); 25 | } 26 | 27 | /** 28 | * Cancel the ListingRequest. 29 | * 30 | * @param {string} id The unique identifier of the ListingRequest object. 31 | * 32 | */ 33 | async cancel(id) { 34 | const url = `${this.baseUri}/${id}/cancel`; 35 | const options = { 36 | method: 'POST', 37 | }; 38 | await this.fetch(url, options); 39 | } 40 | 41 | /** 42 | * Complete the ListingRequest. 43 | * 44 | * @param {string} id The unique identifier of the ListingRequest object. 45 | * 46 | */ 47 | async complete(id) { 48 | const url = `${this.baseUri}/${id}/complete`; 49 | const options = { 50 | method: 'POST', 51 | }; 52 | await this.fetch(url, options); 53 | } 54 | 55 | /** 56 | * Deploy the ListingRequest. 57 | * 58 | * @param {string} id The unique identifier of the ListingRequest object. 59 | * 60 | */ 61 | async deploy(id) { 62 | const url = `${this.baseUri}/${id}/deploy`; 63 | const options = { 64 | method: 'POST', 65 | }; 66 | await this.fetch(url, options); 67 | } 68 | 69 | /** 70 | * Refine the ListingRequest. 71 | * 72 | * @param {string} id The unique identifier of the ListingRequest object. 73 | * 74 | */ 75 | async refine(id) { 76 | const url = `${this.baseUri}/${id}/refine`; 77 | const options = { 78 | method: 'POST', 79 | }; 80 | await this.fetch(url, options); 81 | } 82 | 83 | /** 84 | * Submit the ListingRequest. 85 | * 86 | * @param {string} id The unique identifier of the ListingRequest object. 87 | * 88 | */ 89 | async submit(id) { 90 | const url = `${this.baseUri}/${id}/submit`; 91 | const options = { 92 | method: 'POST', 93 | }; 94 | await this.fetch(url, options); 95 | } 96 | } 97 | 98 | module.exports = ListingRequestResource; 99 | -------------------------------------------------------------------------------- /lib/connect/api/recurringAssets.js: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | 7 | const GenericResource = require('./base'); 8 | /** 9 | * The *RecurringAssetResource* class provides methods to access the recurring 10 | * assets endpoint of the Cloud Blue Connect API. 11 | * 12 | * @extends GenericResource 13 | * @category Resources 14 | */ 15 | class RecurringAssetResource extends GenericResource { 16 | /** 17 | * Creates a new instance of the *RecurringAssetResource* class. 18 | * 19 | * @param {ConnectClient} client An instance of the ConnectClient class. 20 | * 21 | * @returns {RecurringAssetResource} An instance of the *RecurringAssetResource* class. 22 | */ 23 | constructor(client) { 24 | super(client, '/subscriptions/assets'); 25 | } 26 | } 27 | 28 | module.exports = RecurringAssetResource; 29 | -------------------------------------------------------------------------------- /lib/connect/api/tierAccountRequests.js: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | 7 | const GenericResource = require('./base'); 8 | /** 9 | * The *TierAccountRequestResource* class provides methods to access the tier account 10 | * requests endpoint of the Cloud Blue Connect API. 11 | * 12 | * @extends GenericResource 13 | * @category Resources 14 | */ 15 | class TierAccountRequestResource extends GenericResource { 16 | /** 17 | * Creates a new instance of the *TierAccountRequestResource* class. 18 | * 19 | * @param {ConnectClient} client An instance of the ConnectClient class. 20 | * 21 | * @returns {TierAccountRequestResource} An instance of the *TierAccountRequestResource* class. 22 | */ 23 | constructor(client) { 24 | super(client, '/tier/account-requests'); 25 | } 26 | 27 | /** 28 | * Accept the TierAccountRequest. 29 | * 30 | * @param {string} id The unique identifier of the TierAccountRequest object. 31 | * 32 | * @returns {object} The accepted TierAccountRequest object. 33 | */ 34 | async accept(id) { 35 | const url = `${this.baseUri}/${id}/accept`; 36 | const options = { 37 | method: 'POST', 38 | }; 39 | const response = await this.fetch(url, options); 40 | return response.json(); 41 | } 42 | 43 | /** 44 | * Ignore the TierAccountRequest. 45 | * 46 | * @param {string} id The unique identifier of the TierAccountRequest object. 47 | * @param {string} reason The reason for which vendor ignore this request. 48 | * 49 | * @returns {object} The ignored TierAccountRequest object. 50 | */ 51 | async ignore(id, reason) { 52 | const url = `${this.baseUri}/${id}/ignore`; 53 | const options = { 54 | method: 'POST', 55 | body: { 56 | reason, 57 | }, 58 | }; 59 | const response = await this.fetch(url, options); 60 | return response.json(); 61 | } 62 | } 63 | 64 | module.exports = TierAccountRequestResource; 65 | -------------------------------------------------------------------------------- /lib/connect/api/tierAccounts.js: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | 7 | /* eslint-disable max-classes-per-file */ 8 | 9 | const { memoizeWith, identity } = require('ramda'); 10 | 11 | const GenericResource = require('./base'); 12 | 13 | /** 14 | * The *TierAccountVersionResource* class provides methods to access the 15 | * *Version* objects for a tier account. 16 | * 17 | * @extends GenericResource 18 | * @category Resources 19 | */ 20 | class TierAccountVersionResource extends GenericResource {} 21 | 22 | /** 23 | * The *TierAccountResource* class provides methods to access the tier accounts 24 | * endpoint of the Cloud Blue Connect API. 25 | * 26 | * @extends GenericResource 27 | * @category Resources 28 | */ 29 | class TierAccountResource extends GenericResource { 30 | /** 31 | * Creates a new instance of the *TierAccountResource* class. 32 | * 33 | * @param {ConnectClient} client An instance of the ConnectClient class. 34 | * 35 | * @returns {TierAccountResource} An instance of the *TierAccountResource* class. 36 | */ 37 | constructor(client) { 38 | super(client, '/tier/accounts'); 39 | this.versions = memoizeWith(identity, this.versions); 40 | } 41 | 42 | /** 43 | * Returns an instance of the *TierAccountVersionResource* for a *TierAccount*. 44 | * 45 | * @param {string} id The unique identifier of the *TierAccount*. 46 | * 47 | * @returns {TierAccountVersionResource} An instance of the *TierAccountVersionResource* 48 | * for the product. 49 | */ 50 | versions(id) { 51 | return new TierAccountVersionResource(this._client, `${this.baseUri}/${id}/versions`); 52 | } 53 | } 54 | 55 | module.exports = TierAccountResource; 56 | -------------------------------------------------------------------------------- /lib/connect/api/tierConfigRequests.js: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | 7 | const GenericResource = require('./base'); 8 | 9 | /** 10 | * The *TierConfigRequestResource* class provides methods to access the *TierConfigRequest* 11 | * endpoint of the Cloud Blue Connect API. 12 | * 13 | * @extends GenericResource 14 | * @category Resources 15 | */ 16 | class TierConfigRequestResource extends GenericResource { 17 | /** 18 | * Creates a new instance of the *TierConfigRequestResource* class. 19 | * 20 | * @param {ConnectClient} client An instance of the ConnectClient class. 21 | * 22 | * @returns {TierConfigRequestResource} An instance of the *TierConfigRequestResource* class. 23 | */ 24 | constructor(client) { 25 | super(client, '/tier/config-requests'); 26 | } 27 | 28 | /** 29 | * Changes the status of a *TierConfigurationRequest* to fail. 30 | * 31 | * @param {string} id The unique identifier of the TierConfigurationRequest object. 32 | * @param {string} reason The reason for which the TierConfigurationRequest has been failed. 33 | * 34 | */ 35 | async fail(id, reason) { 36 | const url = `/tier/config-requests/${id}/fail`; 37 | const options = { 38 | method: 'POST', 39 | body: { 40 | reason, 41 | }, 42 | }; 43 | await this.fetch(url, options); 44 | } 45 | 46 | /** 47 | * Changes the status of a *TierConfigurationRequest* to inquire. 48 | * 49 | * @param {string} id The unique identifier of the TierConfigurationRequest object. 50 | * 51 | */ 52 | 53 | async inquire(id) { 54 | const url = `/tier/config-requests/${id}/inquire`; 55 | const options = { 56 | method: 'POST', 57 | }; 58 | await this.fetch(url, options); 59 | } 60 | 61 | /** 62 | * Changes the status of a *TierConfigurationRequest* to pending. 63 | * 64 | * @param {string} id The unique identifier of the TierConfigurationRequest object. 65 | * 66 | */ 67 | 68 | async pending(id) { 69 | const url = `/tier/config-requests/${id}/pend`; 70 | const options = { 71 | method: 'POST', 72 | }; 73 | await this.fetch(url, options); 74 | } 75 | 76 | /** 77 | * Change the status of a *TierConfigurationRequest* to approved. 78 | * To change the status of the TierConfigurationRequest to approved 79 | * you must provide a Template id. 80 | * 81 | * @example 82 | * // request body using a template id 83 | * { 84 | * template: { 85 | * id: 'TL-000-000-000' 86 | * } 87 | * } 88 | * 89 | * @param {string} id The unique identifier of the TierConfigurationRequest object. 90 | * @param {object} request The request body. 91 | * 92 | * @returns {object} The rendered Template. 93 | */ 94 | async approve(id, request) { 95 | const url = `/tier/config-requests/${id}/approve`; 96 | const options = { 97 | method: 'POST', 98 | body: request, 99 | }; 100 | const response = await this.fetch(url, options); 101 | return response.json(); 102 | } 103 | } 104 | 105 | 106 | module.exports = TierConfigRequestResource; 107 | -------------------------------------------------------------------------------- /lib/connect/api/tierConfigs.js: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | 7 | const GenericResource = require('./base'); 8 | 9 | /** 10 | * The *TierConfigRequestResource* class provides methods to access the *TierConfig* 11 | * endpoint of the Cloud Blue Connect API. 12 | * 13 | * @extends GenericResource 14 | * @category Resources 15 | */ 16 | class TierConfigResource extends GenericResource { 17 | /** 18 | * Creates a new instance of the *TierConfigResource* class. 19 | * 20 | * @param {ConnectClient} client An instance of the ConnectClient class. 21 | * 22 | * @returns {TierConfigResource} An instance of the *TierConfigResource* class. 23 | */ 24 | constructor(client) { 25 | super(client, '/tier/configs'); 26 | } 27 | } 28 | 29 | 30 | module.exports = TierConfigResource; 31 | -------------------------------------------------------------------------------- /lib/connect/api/usageAggregates.js: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | 7 | /* eslint-disable max-classes-per-file */ 8 | 9 | const GenericResource = require('./base'); 10 | 11 | /** 12 | * The *UsageFileResource* class provides methods to access the usage file 13 | * endpoint of the Cloud Blue Connect API. 14 | * 15 | * @extends GenericResource 16 | * @category Resources 17 | */ 18 | class UsageAggregateResource extends GenericResource { 19 | /** 20 | * Creates a new instance of the *UsageAggregateResource* class. 21 | * 22 | * @param {ConnectClient} client An instance of the ConnectClient class. 23 | * 24 | * @returns {UsageAggregateResource} An instance of the *UsageAggregateResource* class. 25 | */ 26 | constructor(client) { 27 | super(client, '/usage/aggregates'); 28 | } 29 | } 30 | module.exports = UsageAggregateResource; 31 | -------------------------------------------------------------------------------- /lib/connect/api/usageChunks.js: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | 7 | /* eslint-disable max-classes-per-file */ 8 | 9 | const GenericResource = require('./base'); 10 | 11 | /** 12 | * The *UsageFileResource* class provides methods to access the usage file 13 | * endpoint of the Cloud Blue Connect API. 14 | * 15 | * @extends GenericResource 16 | * @category Resources 17 | */ 18 | class UsageChunkResource extends GenericResource { 19 | /** 20 | * Creates a new instance of the *UsageChunkResource* class. 21 | * 22 | * @param {ConnectClient} client An instance of the ConnectClient class. 23 | * 24 | * @returns {UsageChunkResource} An instance of the *UsageFileResource* class. 25 | */ 26 | constructor(client) { 27 | super(client, '/usage/chunks'); 28 | } 29 | 30 | /** 31 | * Close *Chunk File*. 32 | * 33 | * @param {string} id The unique identifier of the *Usage File*. 34 | * @param {string} externalBillingId Id of the billing to close chunk 35 | * @param {string} externalBillingNote Note of the billing to close chunk 36 | * @returns {UsageChunkResource} An instance of the *UsageChunkResource*. 37 | * 38 | */ 39 | async close(id, externalBillingId, externalBillingNote) { 40 | const url = `${this.baseUri}/${id}/close`; 41 | const options = { 42 | method: 'POST', 43 | body: { 44 | external_billing_id: externalBillingId, 45 | external_billing_note: externalBillingNote, 46 | }, 47 | }; 48 | const response = await this.fetch(url, options); 49 | return response.json(); 50 | } 51 | 52 | /** 53 | * Download *Chunk File*. 54 | * 55 | * @param {string} id The unique identifier of the *Usage File*. 56 | * @returns {UsageChunckResource} An instance of the *UsageChunkResource* 57 | * 58 | */ 59 | async download(id) { 60 | const url = `${this.baseUri}/${id}/download`; 61 | const options = { 62 | method: 'GET', 63 | }; 64 | const response = await this.fetch(url, options); 65 | return response.json(); 66 | } 67 | 68 | /** 69 | * Regenerate *Chunk File*. 70 | * 71 | * @param {string} id The unique identifier of the *Usage File*. 72 | * @returns {UsageChunckResource} An instance of the *UsageChunkResource* 73 | * 74 | */ 75 | async regenerate(id) { 76 | const url = `${this.baseUri}/${id}/regenerate`; 77 | const options = { 78 | method: 'POST', 79 | }; 80 | const response = await this.fetch(url, options); 81 | return response.json(); 82 | } 83 | } 84 | module.exports = UsageChunkResource; 85 | -------------------------------------------------------------------------------- /lib/connect/api/usageReconciliations.js: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | 7 | /* eslint-disable max-classes-per-file */ 8 | 9 | const GenericResource = require('./base'); 10 | 11 | /** 12 | * The *UsageFileResource* class provides methods to access the usage file 13 | * endpoint of the Cloud Blue Connect API. 14 | * 15 | * @extends GenericResource 16 | * @category Resources 17 | */ 18 | class UsageReconciliationResource extends GenericResource { 19 | /** 20 | * Creates a new instance of the *UsageReconciliationResource* class. 21 | * 22 | * @param {ConnectClient} client An instance of the ConnectClient class. 23 | * 24 | * @returns {UsageRecordResource} An instance of the *UsageFileResource* class. 25 | */ 26 | constructor(client) { 27 | super(client, '/usage/reconciliations'); 28 | } 29 | 30 | /** 31 | * Get processed files. 32 | * 33 | * @param {string} id The unique identifier of the *Usage File*. 34 | * @returns {UsageReconciliationResource} An instance of the *UsageReconciliationResource*. 35 | * 36 | */ 37 | async processedFile(id) { 38 | const url = `${this.baseUri}/${id}/processedFile`; 39 | const options = { 40 | method: 'GET', 41 | }; 42 | const response = await this.fetch(url, options); 43 | return response.json(); 44 | } 45 | 46 | /** 47 | * Get uploaded files. 48 | * 49 | * @param {string} id The unique identifier of the *Usage File*. 50 | * @returns {UsageReconciliationResource} An instance of the *UsageReconciliationResource*. 51 | * 52 | */ 53 | async uploadedFile(id) { 54 | const url = `${this.baseUri}/${id}/uploadedFile`; 55 | const options = { 56 | method: 'GET', 57 | }; 58 | const response = await this.fetch(url, options); 59 | return response.json(); 60 | } 61 | } 62 | module.exports = UsageReconciliationResource; 63 | -------------------------------------------------------------------------------- /lib/connect/api/usageRecords.js: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | 7 | /* eslint-disable max-classes-per-file */ 8 | 9 | const GenericResource = require('./base'); 10 | 11 | /** 12 | * The *UsageFileResource* class provides methods to access the usage file 13 | * endpoint of the Cloud Blue Connect API. 14 | * 15 | * @extends GenericResource 16 | * @category Resources 17 | */ 18 | class UsageRecordResource extends GenericResource { 19 | /** 20 | * Creates a new instance of the *UsageRecordResource* class. 21 | * 22 | * @param {ConnectClient} client An instance of the ConnectClient class. 23 | * 24 | * @returns {UsageRecordResource} An instance of the *UsageFileResource* class. 25 | */ 26 | constructor(client) { 27 | super(client, '/usage/records'); 28 | } 29 | 30 | /** 31 | * Close all *Record File*. 32 | * 33 | * @param {string} id The unique identifier of the *Usage File*. 34 | * @param {string} externalBillingId Id of the billing to close record 35 | * @param {string} externalBillingNote Note of the billing to close record 36 | * @returns {UsageChunkResource} An instance of the *UsageChunkResource*. 37 | * 38 | */ 39 | async close(id, externalBillingId, externalBillingNote) { 40 | const url = `${this.baseUri}/${id}/close`; 41 | const options = { 42 | method: 'POST', 43 | body: { 44 | external_billing_id: externalBillingId, 45 | external_billing_note: externalBillingNote, 46 | }, 47 | }; 48 | const response = await this.fetch(url, options); 49 | return response.json(); 50 | } 51 | 52 | /** 53 | * Close Records *Record File*. 54 | * 55 | * @param {string} id The unique identifier of the *Usage File*. 56 | * @param {string} recordId Id of the record to close 57 | * @param {string} externalBillingId Id of the billing to close record 58 | * @param {string} externalBillingNote Note of the billing to close record 59 | * @returns {UsageChunkResource} An instance of the *UsageChunkResource*. 60 | * 61 | */ 62 | async closeRecords(id, recordId, externalBillingId, externalBillingNote) { 63 | const url = `${this.baseUri}/${id}/close-records`; 64 | const options = { 65 | method: 'POST', 66 | body: { 67 | id: recordId, 68 | external_billing_id: externalBillingId, 69 | external_billing_note: externalBillingNote, 70 | }, 71 | }; 72 | const response = await this.fetch(url, options); 73 | return response.json(); 74 | } 75 | } 76 | module.exports = UsageRecordResource; 77 | -------------------------------------------------------------------------------- /lib/connect/api/utils.js: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | const { 7 | pickBy, 8 | isEmpty, 9 | replace, 10 | complement, 11 | } = require('ramda'); 12 | 13 | const { filterToQuery } = require('../rql'); 14 | 15 | const notEmpty = complement(isEmpty); 16 | 17 | const buildUrl = (url, queryParams = {}) => { 18 | const filteredParams = pickBy(notEmpty, queryParams); 19 | const query = filterToQuery(filteredParams); 20 | return replace(/\?$/, '', `${url}?${query}`); 21 | }; 22 | 23 | module.exports = { buildUrl }; 24 | -------------------------------------------------------------------------------- /lib/connect/api/webhooks.js: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | 7 | const GenericResource = require('./base'); 8 | 9 | /** 10 | * The *WebhookResource* class provides methods to access the webhooks 11 | * endpoint of the Cloud Blue Connect API. 12 | * 13 | * @extends GenericResource 14 | * @category Resources 15 | */ 16 | class WebhookResource extends GenericResource { 17 | /** 18 | * Creates a new instance of the *WebhookResource* class. 19 | * 20 | * @param {ConnectClient} client An instance of the ConnectClient class. 21 | * 22 | * @returns {WebhookResource} An instance of the *WebhookResource* class. 23 | */ 24 | constructor(client) { 25 | super(client, '/notifications/webhooks'); 26 | } 27 | } 28 | 29 | module.exports = WebhookResource; 30 | -------------------------------------------------------------------------------- /lib/connect/http/adapter.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | 7 | /* eslint max-classes-per-file: "off" */ 8 | const { forEach, mergeDeepRight, clone } = require('ramda'); 9 | const nodefetch = require('node-fetch'); 10 | 11 | const { isObjectStrict } = require('../utils'); 12 | 13 | /** 14 | * The *AbstractHttpAdapter* class allow a CloudBlue Connect SDK consumer 15 | * to wrap a preferred http client library and adapt requests and responses 16 | * to in order to work with this SDK. 17 | * 18 | * @category Base 19 | */ 20 | class AbstractHttpAdapter { 21 | /** 22 | * Create a subclass of AbstractHttpAdapter 23 | * 24 | * @param {Function} fetch the fetch function used to make the actual http call. 25 | */ 26 | constructor(fetch) { 27 | if (this.constructor === AbstractHttpAdapter) { 28 | throw new Error('HttpAdapter is abstract. You must subclass it!'); 29 | } 30 | this._fetch = fetch; 31 | this._before = []; 32 | this._after = []; 33 | } 34 | 35 | /** 36 | * Get or set a list of beforeRequest hook functions. 37 | * 38 | * @returns {Array} Array of hooks. 39 | */ 40 | get beforeRequest() { 41 | return this._before; 42 | } 43 | 44 | set beforeRequest(middlewares) { 45 | this._before = middlewares || []; 46 | } 47 | 48 | get afterResponse() { 49 | return this._after; 50 | } 51 | 52 | set afterResponse(middlewares) { 53 | this._after = middlewares || []; 54 | } 55 | 56 | /* eslint-disable class-methods-use-this, no-unused-vars */ 57 | prepareRequest(url, options) { 58 | throw new Error('Concrete class must implement this method!'); 59 | } 60 | 61 | parseResponse(response) { 62 | throw new Error('Concrete class must implement this method!'); 63 | } 64 | 65 | fetch(url, options) { 66 | let reqOptions = clone(options) || {}; 67 | let reqUrl = clone(url); 68 | forEach((middleware) => { 69 | const result = middleware(reqUrl, reqOptions); 70 | reqUrl = result.url; 71 | reqOptions = result.options; 72 | }, this._before); 73 | const req = this.prepareRequest(reqUrl, reqOptions); 74 | return this._fetch(req.url, req.options) 75 | .then((response) => { 76 | response.options = options; 77 | return response; 78 | }) 79 | .then(this.parseResponse) 80 | .then((response) => { 81 | forEach((middleware) => { 82 | response = middleware(response); /* eslint no-param-reassign: "off" */ 83 | }, this._after); 84 | return response; 85 | }); 86 | } 87 | } 88 | 89 | 90 | /** 91 | * The *DefaultHttpAdapter* is the default adapter used in the 92 | * CloudBlue Connect Javascript SDK based on the node-fetch http 93 | * client library. 94 | * 95 | * @extends AbstractHttpAdapter 96 | * @category Base 97 | */ 98 | class DefaultHttpAdapter extends AbstractHttpAdapter { 99 | constructor() { 100 | super(nodefetch); 101 | } 102 | 103 | prepareRequest(url, options) { 104 | const newOptions = clone(options); 105 | if (newOptions.body) { 106 | if (Array.isArray(newOptions.body) || isObjectStrict(newOptions.body)) { 107 | newOptions.body = JSON.stringify(newOptions.body); 108 | newOptions.headers = mergeDeepRight(newOptions.headers, { 'Content-Type': 'application/json' }); 109 | } 110 | } 111 | return { url, options: newOptions }; 112 | } 113 | 114 | parseResponse(response) { 115 | return response; 116 | } 117 | } 118 | 119 | module.exports = { 120 | AbstractHttpAdapter, 121 | DefaultHttpAdapter, 122 | }; 123 | -------------------------------------------------------------------------------- /lib/connect/http/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | 7 | module.exports = require('./adapter'); 8 | -------------------------------------------------------------------------------- /lib/connect/index.js: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | 7 | const { AbstractHttpAdapter } = require('./http'); 8 | const ConnectClient = require('./client'); 9 | const { HttpError, APIError } = require('./api/errors'); 10 | const { 11 | Fulfillment, 12 | Directory, 13 | Inventory, 14 | Subscriptions, 15 | Listings, 16 | } = require('./ops'); 17 | 18 | module.exports = { 19 | AbstractHttpAdapter, 20 | ConnectClient, 21 | HttpError, 22 | APIError, 23 | Fulfillment, 24 | Directory, 25 | Inventory, 26 | Subscriptions, 27 | Listings, 28 | }; 29 | -------------------------------------------------------------------------------- /lib/connect/ops/index.js: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | 7 | const Fulfillment = require('./fulfillment'); 8 | const Directory = require('./directory'); 9 | const Inventory = require('./inventory'); 10 | const Subscriptions = require('./subscriptions'); 11 | const Listings = require('./listings'); 12 | 13 | module.exports = { 14 | Directory, 15 | Fulfillment, 16 | Inventory, 17 | Subscriptions, 18 | Listings, 19 | }; 20 | -------------------------------------------------------------------------------- /lib/connect/ops/inventory.js: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | 7 | const { filter } = require('ramda'); 8 | 9 | /** 10 | * The Inventory class exposes specialized methods to help 11 | * developers to access the inventory (products, items etc). 12 | * 13 | * @category Operations 14 | */ 15 | class Inventory { 16 | /** 17 | * Creates an instance of the Inventory class. 18 | * 19 | * @param {ConnectClient} client An instance of the ConnectClient class. 20 | * 21 | * @returns {Inventory} An instance of the Inventory class. 22 | */ 23 | constructor(client) { 24 | this._client = client; 25 | } 26 | /** 27 | * Retrieves the list of parameters configured for the product. 28 | * 29 | * @param {string} id The unique product identifier for which retrieve the parameters. 30 | * 31 | * @returns {Array} An array with the Parameter objects. 32 | */ 33 | 34 | async getParametersByProduct(id) { 35 | return this._client.products.parameters(id).search(); 36 | } 37 | 38 | /** 39 | * Retrieves the list of parameters of scope asset and phase fulfillment configured for 40 | * the product. 41 | * 42 | * @param {string} id The unique product identifier for which retrieve the parameters. 43 | * 44 | * @returns {Array} An array with the Parameter objects. 45 | */ 46 | 47 | async getAssetParametersForFulfillmentByProduct(id) { 48 | return this._client.products.parameters(id).search({ 49 | scope: 'asset', 50 | phase: 'fulfillment', 51 | }); 52 | } 53 | 54 | /** 55 | * Returns the list of templates configured for a product. 56 | * 57 | * @param {string} id The unique identifier of the product. 58 | * 59 | * @returns {Array} An array of Template objects. 60 | */ 61 | async getProductTemplates(id) { 62 | return this._client.products.getTemplates(id); 63 | } 64 | 65 | /** 66 | * Returns the list of templates configured for a product with scope "asset". 67 | * 68 | * @param {string} id The unique identifier of the product. 69 | * 70 | * @returns {Array} An array of Template objects. 71 | */ 72 | async getProductAssetTemplates(id) { 73 | const templates = await this.getProductTemplates(id); 74 | return filter((template) => template.scope === 'asset', templates); 75 | } 76 | 77 | /** 78 | * Returns the action link for a product action. 79 | * 80 | * @param {string} id The unique identifier of the product. 81 | * @param {string} actionId The unique product action identifier. 82 | * @param {string} assetId The unique asset identifier. 83 | * 84 | * @returns {Array} An array of Template objects. 85 | */ 86 | async getProductActionLink(id, actionId, assetId) { 87 | return this._client.products.actions(id).link(actionId, assetId); 88 | } 89 | 90 | /** 91 | * Search the parameters configured for a product. 92 | * 93 | * @param {string} productId The id of the product for which search parameters. 94 | * @param {object} query The filter query. 95 | * 96 | * @returns {Array} An array with the Parameter objects. 97 | */ 98 | 99 | async searchProductParameters(productId, query) { 100 | return this._client.products.parameters(productId).search(query); 101 | } 102 | } 103 | 104 | module.exports = Inventory; 105 | -------------------------------------------------------------------------------- /lib/connect/ops/listings.js: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | 7 | /** 8 | * The Listings class exposes specialized methods to help 9 | * developers to handle listings and listing requests. 10 | * 11 | * @category Operations 12 | */ 13 | class Listings { 14 | /** 15 | * Creates an instance of the Listings class. 16 | * 17 | * @param {ConnectClient} client An instance of the ConnectClient class. 18 | * 19 | * @returns {Listings} An instance of the Listings class. 20 | */ 21 | constructor(client) { 22 | this._client = client; 23 | } 24 | 25 | /** 26 | * Returns a list of *ListingRequest* objects that match the provided 27 | * (optional) query. 28 | * 29 | * @param {object} query The optional query to filter results. 30 | * 31 | * @returns {Array} An array of *ListingRequest* object optionally matching 32 | * the provided query. 33 | */ 34 | async searchListingRequests(query) { 35 | return this._client.listingRequests.search(query); 36 | } 37 | 38 | /** 39 | * Creates a new *ListingRequest* 40 | * 41 | * @param {object} request The ListingRequest object. 42 | * 43 | * @returns {object} The created ListingRequest object. 44 | */ 45 | async createListingRequest(request) { 46 | return this._client.listingRequests.create(request); 47 | } 48 | 49 | /** 50 | * Retrieve the *ListingRequest* object identified by its id. 51 | * 52 | * @param {string} id The unique identifier of the *ListingRequest* object. 53 | * 54 | * @returns {object} The *ListingRequest* object. 55 | */ 56 | async getListingRequest(id) { 57 | return this._client.listingRequests.get(id); 58 | } 59 | 60 | /** 61 | * Submit the *ListingRequest* object identified by its id. 62 | * 63 | * @param {string} id The unique identifier of the *ListingRequest* object. 64 | * 65 | * @returns {object} The *ListingRequest* object. 66 | */ 67 | async submitListingRequest(id) { 68 | return this._client.listingRequests.submit(id); 69 | } 70 | 71 | /** 72 | * Cancel the *ListingRequest* object identified by its id. 73 | * 74 | * @param {string} id The unique identifier of the *ListingRequest* object. 75 | * 76 | * @returns {object} The *ListingRequest* object. 77 | */ 78 | async cancelListingRequest(id) { 79 | return this._client.listingRequests.cancel(id); 80 | } 81 | 82 | /** 83 | * Refine the *ListingRequest* object identified by its id. 84 | * 85 | * @param {string} id The unique identifier of the *ListingRequest* object. 86 | * 87 | * @returns {object} The *ListingRequest* object. 88 | */ 89 | async refineListingRequest(id) { 90 | return this._client.listingRequests.refine(id); 91 | } 92 | 93 | /** 94 | * Complete the *ListingRequest* object identified by its id. 95 | * 96 | * @param {string} id The unique identifier of the *ListingRequest* object. 97 | * 98 | * @returns {object} The *ListingRequest* object. 99 | */ 100 | async completeListingRequest(id) { 101 | return this._client.listingRequests.complete(id); 102 | } 103 | 104 | /** 105 | * Deploy the *ListingRequest* object identified by its id. 106 | * 107 | * @param {string} id The unique identifier of the *ListingRequest* object. 108 | * 109 | * @returns {object} The *ListingRequest* object. 110 | */ 111 | async deployListingRequest(id) { 112 | return this._client.listingRequests.deploy(id); 113 | } 114 | } 115 | 116 | module.exports = Listings; 117 | -------------------------------------------------------------------------------- /lib/connect/ops/subscriptions.js: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | 7 | /** 8 | * The Subscriptions class exposes specialized methods to help 9 | * developers to handle subscriptions (recurring assets and billing requests.). 10 | * 11 | * @category Operations 12 | */ 13 | class Subscriptions { 14 | /** 15 | * Creates an instance of the Subscriptions class. 16 | * 17 | * @param {ConnectClient} client An instance of the ConnectClient class. 18 | * 19 | * @returns {Subscriptions} An instance of the Subscriptions class. 20 | */ 21 | constructor(client) { 22 | this._client = client; 23 | } 24 | 25 | /** 26 | * Returns a list of *BillingRequest* objects that match the provided 27 | * (optional) query. 28 | * 29 | * @param {object} query The optional query to filter results. 30 | * 31 | * @returns {Array} An array of *BillingRequest* object optionally matching 32 | * the provided query. 33 | */ 34 | async searchBillingRequests(query) { 35 | return this._client.billingRequests.search(query); 36 | } 37 | 38 | /** 39 | * Creates a new *BillingRequest* 40 | * 41 | * @param {object} request The BillingRequest object. 42 | * 43 | * @returns {object} The created BillingRequest object. 44 | */ 45 | async createBillingRequest(request) { 46 | return this._client.billingRequests.create(request); 47 | } 48 | 49 | /** 50 | * Retrieve the *BillingRequest* object identified by its id. 51 | * 52 | * @param {string} id The unique identifier of the *BillingRequest* object. 53 | * 54 | * @returns {object} The *BillingRequest* object. 55 | */ 56 | async getBillingRequest(id) { 57 | return this._client.billingRequests.get(id); 58 | } 59 | 60 | /** 61 | * Updates the attributes of a *BillingRequest* object. 62 | * 63 | * @param {string} id The unique identifier of the BillingRequest object. 64 | * @param {object} attributes An attributes object to be updated. 65 | * 66 | * @returns {object} The updated BillingRequest attributes object. 67 | */ 68 | async updateBillingRequestAttributes(id, attributes) { 69 | return this._client.billingRequests.updateAttributes(id, attributes); 70 | } 71 | 72 | /** 73 | * Returns a list of *RecurringAsset* objects that match the provided 74 | * (optional) query. 75 | * 76 | * @param {object} query The optional query to filter results. 77 | * 78 | * @returns {Array} An array of *RecurringAsset* object optionally matching 79 | * the provided query. 80 | */ 81 | async searchRecurringAssets(query) { 82 | return this._client.recurringAssets.search(query); 83 | } 84 | 85 | /** 86 | * Retrieve the *RecurringAsset* object identified by its id. 87 | * 88 | * @param {string} id The unique identifier of the *RecurringAsset* object. 89 | * 90 | * @returns {object} The *RecurringAsset* object. 91 | */ 92 | async getRecurringAsset(id) { 93 | return this._client.recurringAssets.get(id); 94 | } 95 | } 96 | 97 | module.exports = Subscriptions; 98 | -------------------------------------------------------------------------------- /lib/connect/utils.js: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | 7 | const { 8 | type, 9 | pipe, 10 | equals, 11 | isEmpty, 12 | isNil, 13 | anyPass, 14 | curry, 15 | } = require('ramda'); 16 | 17 | const isObjectStrict = pipe(type, equals('Object')); 18 | const isNilOrEmpty = anyPass([isEmpty, isNil]); 19 | const alt = curry((t, f, c) => (c ? t : f)); 20 | 21 | 22 | module.exports = { 23 | isObjectStrict, 24 | isNilOrEmpty, 25 | alt, 26 | }; 27 | -------------------------------------------------------------------------------- /mddocs.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | destPath: './mddocs', 3 | urlPrefix: 'https://raw.githubusercontent.com/cloudblue/connect-javascript-sdk', 4 | objTypes: [ 5 | 'class', 6 | ], 7 | homeTitle: 'Welcome', 8 | }; 9 | -------------------------------------------------------------------------------- /mddocs/000_README.md: -------------------------------------------------------------------------------- 1 | # Connect Javascript SDK 2 | 3 | 4 | [![Build Status](https://travis-ci.org/cloudblue/connect-javascript-sdk.svg?branch=master)](https://travis-ci.org/cloudblue/connect-javascript-sdk) 5 | [![codecov](https://codecov.io/gh/cloudblue/connect-javascript-sdk/branch/master/graph/badge.svg)](https://codecov.io/gh/cloudblue/connect-javascript-sdk) 6 | [![npm](https://img.shields.io/npm/v/@cloudblueconnect/connect-javascript-sdk)](https://img.shields.io/npm/v/@cloudblueconnect/connect-javascript-sdk) 7 | [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=cloudblue_connect-javascript-sdk&metric=alert_status)](https://sonarcloud.io/dashboard?id=cloudblue_connect-javascript-sdk) 8 | 9 | ## Introduction 10 | 11 | CloudBlue Connect is a supply automation platform that manages your products and services, contracts, 12 | ordering and fulfillment, usage and subscriptions. 13 | 14 | It supports any product, from physical goods to cloud products, as well as any channel, including your 15 | direct and indirect sales channels and internal procurement. 16 | 17 | With its flexible APIs, it can connect to any commerce platform. 18 | 19 | Vendors can leverage CloudBlue Connect to: 20 | 21 | * Reduce the total cost of ownership for homegrown technology supporting their indirect channel 22 | * Standardize integrations with partners 23 | * Increase efficiencies and minimize redundancies by bridging their direct and indirect sales channels 24 | 25 | Service providers can use CloudBlue Connect to: 26 | 27 | * Define, manage and distribute any type of product (omni-product) through any channel (omni-channel) 28 | * Transform perpetual licensed products into a subscription model 29 | * Onboard new products into their portfolio quickly to build and deliver unique solutions to end customers 30 | 31 | 32 | Connect Javascript SDK allows an easy and fast integration with the Cloud Blue Connect Platform. 33 | Thanks to it you can automate the fulfillment of orders generated by your products. 34 | 35 | 36 | 37 | ## Dependencies 38 | 39 | Connect Javascript SDK work with Node.js version 10 or later. 40 | 41 | Connect Javascript SDK also depends on: 42 | 43 | * [ramda](https://ramdajs.com/) version 0.26.1 44 | * [node-fetch](https://github.com/node-fetch/node-fetch) version 2.6.0 45 | 46 | 47 | 48 | ## Install 49 | 50 | To install the Connect Javascript SDK from a terminal window type: 51 | 52 | ```sh 53 | $ npm install --save @cloudblueconnect/connect-javascript-sdk 54 | ``` 55 | 56 | ## Documentation 57 | 58 | The full SDK documentation is available [here](https://cloudblue.github.io/connect-javascript-sdk). 59 | 60 | 61 | ## Example 62 | 63 | ```js 64 | 65 | // import the ConnectClient class 66 | const { ConnectClient } = require('@cloudblueconnect/connect-javascript-sdk'); 67 | 68 | // create an instance of the ConnectClient class 69 | const client = new ConnectClient('https:///', ''); 70 | 71 | // get a list of products 72 | const products = await client.products.search(); 73 | ``` 74 | 75 | ## Contribute 76 | 77 | If you want to contribute to the Connect Javascript SDK development feel free to open issues or fork the github repository and submit your pull request. 78 | 79 | 80 | ## License 81 | 82 | The Connect Javascript SDK is licensed under the [*Apache License 2.0*](http://www.apache.org/licenses/LICENSE-2.0). 83 | 84 | 85 | -------------------------------------------------------------------------------- /mddocs/001_getting_started.md: -------------------------------------------------------------------------------- 1 | ## Introduction 2 | 3 | The *CloudBlue Connect Javascript SDK* provides programmers with a set of classes that facilitate 4 | the implementation of certain workflows for the *CloudBlue Connect* platform as long as direct access to public endpoints. 5 | 6 | 7 | ## Prerequisites 8 | 9 | The *CloudBlue Connect Javascript SDK* has been tested against with [Node.js](https://nodejs.org) version 10 or later. 10 | 11 | It also depends on the following 3rd party libraries: 12 | 13 | * [ramda](https://ramdajs.com/) version 4.17.15 14 | * [node-fetch](https://github.com/node-fetch/node-fetch) version 2.6.0 15 | 16 | 17 | ## Install 18 | 19 | To add the *CloudBlue Connect Javascript SDK* to your project, executes the following command in your project's root folder: 20 | 21 | ```sh 22 | $ npm install --save @cloudblueconnect/connect-javascript-sdk 23 | ``` 24 | 25 | ## Usage with operation classes 26 | 27 | The *CloudBlue Connect Javascript SDK* exposes to programmers the following set of "operation" classes: 28 | 29 | * {@link Fulfillment}: offers methods such as creation, modification and inquiring of parameters for the management of transactional objects namely asset requests as well as tier configuration requests. 30 | * {@link Directory}: offers methods to access persistent objects such as assets, tier configurations and accounts. 31 | * {@link Inventory}: offers methods to manage products. 32 | 33 | 34 | In order to use the *CloudBlue Connect Javascript SDK* first of all you must create an instance of the {@link ConnectClient} class. 35 | 36 | ```js 37 | const { ConnectClient } = require('@cloudblueconnect/connect-javascript-sdk'); 38 | 39 | const client = new ConnectClient(apiUrl, apiKey); 40 | ``` 41 | 42 | And then you must create an instance of the corresponding operation class: 43 | 44 | ```js 45 | const { Fulfillment } = require('@cloudblueconnect/connect-javascript-sdk'); 46 | 47 | const fulfillment = new Fulfillment(client); 48 | ``` 49 | 50 | ### Examples 51 | 52 | #### Create an asset purchase request 53 | 54 | ```js 55 | const { ConnectClient, Fulfillment } = require('@cloudblueconnect/connect-javascript-sdk'); 56 | 57 | const client = new ConnectClient(apiUrl, apiKey); 58 | const fulfillment = new Fulfillment(client); 59 | 60 | const purchaseRequest = await fulfillment.createRequest(requestObj); 61 | ``` 62 | 63 | > **_NOTE:_** Please refer to the *CloudBlue Connect API* documentation to know how a purchase request object is defined. 64 | 65 | #### Get the first 100 results of pending asset purchase requests 66 | 67 | ```js 68 | const { ConnectClient, Fulfillment } = require('@cloudblueconnect/connect-javascript-sdk'); 69 | 70 | const client = new ConnectClient(apiUrl, apiKey); 71 | const fulfillment = new Fulfillment(client); 72 | 73 | const filter = { 74 | status: 'pending', 75 | limit: 100, 76 | offset: 0 77 | } 78 | 79 | const pendingRequests = await fulfillment.search(filter); 80 | ``` 81 | 82 | > **_NOTE:_** Please see {@tutorial searches} for more informations on how to create filters. 83 | 84 | 85 | ## Direct access to public endpoints 86 | 87 | Each public endpoint of the *CloudBlue Connect API* is mapped by a "Resource" class that provides 88 | basic methods that implement CRUD operations against a resource. 89 | 90 | Moreover each "Resource" class exposes related actions and eventually access to subresources. 91 | 92 | Programmers can access "Resource" classes through the {@link ConnectClient} instance. 93 | 94 | ### Examples 95 | 96 | #### Get a list of users belonging to an account. 97 | 98 | ```js 99 | const { ConnectClient } = require('@cloudblueconnect/connect-javascript-sdk'); 100 | 101 | const client = new ConnectClient(apiUrl, apiKey); 102 | 103 | const users = client.accounts.users('VA-000-000').search(); 104 | ``` 105 | 106 | -------------------------------------------------------------------------------- /mddocs/002_searches.md: -------------------------------------------------------------------------------- 1 | ## Resource Query Language 2 | 3 | The *CloudBlue Connect* public API supports the RQL query language to search, sort and paginate objects. 4 | 5 | A RQL query is a Javascript object that is defined according to the following typescript syntax: 6 | 7 | ``` 8 | interface IRQLFilter { 9 | $eq?: string|number, 10 | $ne?: string|number, 11 | $not?: IRQLFilter, 12 | $gt?: number, 13 | $ge?: number, 14 | $lt?: number, 15 | $le?: number, 16 | $like?: string, 17 | $ilike?: string, 18 | $empty?: boolean, 19 | $null?: boolean, 20 | $in?: Array, 21 | $out?: Array, 22 | $range?: { 23 | min: number, 24 | max: number, 25 | }, 26 | } 27 | 28 | 29 | interface IQueryFilters { 30 | $or?: Array; 31 | $ordering?: Array; 32 | limit?: number; 33 | offset?: number; 34 | [key: string]?: string|number|Array|boolean|IRQLFilter; 35 | } 36 | ``` 37 | 38 | ## Examples 39 | 40 | ### Simple filter 41 | 42 | ``` 43 | const filter = { 44 | name: 'eugene', 45 | age: 13, 46 | }; 47 | ``` 48 | 49 | ### Filter with text matching 50 | 51 | ``` 52 | const filter = { 53 | name: { 54 | $like: 'vasya*', 55 | $ilike: '***New', 56 | }, 57 | }; 58 | ``` 59 | 60 | ### Filter with list 61 | 62 | ``` 63 | const filter = { 64 | age: { 65 | $out: [1, 2], 66 | }, 67 | num: { 68 | $in: [3, 4, 5], 69 | }, 70 | }; 71 | ``` 72 | 73 | ### Filter with range 74 | 75 | ``` 76 | const filter = { 77 | age: { 78 | $range: { 79 | max: 5, 80 | min: 9, 81 | }, 82 | }, 83 | }; 84 | ``` 85 | 86 | ### Filter with relational 87 | 88 | ``` 89 | const filter = { 90 | name: { 91 | $eq: 'vasya', 92 | }, 93 | age: { 94 | $gt: 1, 95 | $lt: 8, 96 | }, 97 | num: { 98 | $lte: 9, 99 | $gte: 4, 100 | }, 101 | }; 102 | ``` 103 | 104 | ### Filter with logical NOT 105 | 106 | ``` 107 | const filter = { 108 | name: { 109 | $not: [{ 110 | $eq: 'vasya', 111 | }, { 112 | $eq: 'petya', 113 | }], 114 | }, 115 | age: { 116 | $not: { 117 | $eq: 10, 118 | $in: [1, 2, 3], 119 | }, 120 | }, 121 | }; 122 | ``` 123 | 124 | ### Filter with logical OR 125 | 126 | ``` 127 | const filter = { 128 | // You can use $or inside field 129 | color: { 130 | $or: [ 131 | // Inside { } may be some conditions and for all them is used logical operator AND 132 | { $eq: 'red' }, 133 | { $eq: 'blue' }, 134 | { $eq: 'yellow' }, 135 | ], 136 | }, 137 | 138 | 139 | // Also you can use $or in root level, then inside must be objects array with fields name 140 | $or: [ 141 | // Inside { } may be some fields with conditions and for all them is used logical operator AND 142 | { product: 'TV' }, 143 | { product: 'Computer' }, 144 | ], 145 | }; 146 | ``` 147 | 148 | ### Combine AND and OR filter 149 | 150 | ``` 151 | const filter = { 152 | $and: [ 153 | {$or: [ 154 | {status: 'new'}, 155 | {type: 'program'} 156 | ]}, 157 | {$or: [ 158 | {status: 'done'}, 159 | {type: 'service'} 160 | ]}, 161 | ] 162 | }; 163 | ``` 164 | 165 | ### Filter with control operators 166 | 167 | ``` 168 | const controlFilter = { 169 | limit: 100, 170 | offset: 0, 171 | $ordering: '-created', 172 | }; 173 | ``` 174 | 175 | ### Filter with empty values 176 | 177 | ``` 178 | // If values are empty, null, undefined then they will not be in the query. 179 | const filter = { 180 | $ordering: [], 181 | name: '', 182 | age: null, 183 | $or: [{name: undefined}], 184 | type: 'pending', 185 | }; 186 | ``` 187 | 188 | ### Combined 189 | 190 | ``` 191 | const combinationFilter = { 192 | offset: 0, 193 | limit: 10, 194 | $ordering: ['title', '-created'], 195 | $or: [ 196 | { 197 | type: 'distribution', 198 | owner: { $eq: 'me' }, 199 | }, 200 | { 201 | type: { $in: ['sourcing', 'service'] }, 202 | owner: { $not: { $eq: 'me' } }, 203 | }, 204 | ], 205 | name: { 206 | $or: [ 207 | { $like: 'my test' }, 208 | { $like: 'my' }, 209 | { $ilike: '***CONTRACT' }, 210 | ], 211 | }, 212 | }; 213 | ``` 214 | -------------------------------------------------------------------------------- /mddocs/003_Class_HttpError.md: -------------------------------------------------------------------------------- 1 | ## Classes 2 | 3 |
4 |
HttpErrorError
5 |

HttpError wraps any http response which status is != 2xx.

6 |
7 |
APIErrorHttpError
8 |

APIError wraps CloudBlue Connect API errors. 9 | Provides convenient methods to obtains error 10 | code and error messages. 11 | The Cloud Blue Connect JSON error looks like:

12 |
13 |
14 | 15 | 16 | 17 | ## HttpError ⇐ Error 18 | HttpError wraps any http response which status is != 2xx. 19 | 20 | **Kind**: global class 21 | **Extends**: Error 22 | **Category**: Base 23 | 24 | * [HttpError](#HttpError) ⇐ Error 25 | * [new HttpError(status, message)](#new_HttpError_new) 26 | * [.status](#HttpError+status) : number 27 | 28 | 29 | 30 | ### new HttpError(status, message) 31 | Create a new instance of the HttpError class. 32 | 33 | 34 | | Param | Type | Description | 35 | | --- | --- | --- | 36 | | status | number | the http status code. | 37 | | message | string | an error message. | 38 | 39 | 40 | 41 | ### httpError.status : number 42 | The http status code. 43 | 44 | **Kind**: instance property of [HttpError](#HttpError) 45 | 46 | 47 | ## APIError ⇐ [HttpError](#HttpError) 48 | APIError wraps CloudBlue Connect API errors. 49 | Provides convenient methods to obtains error 50 | code and error messages. 51 | The Cloud Blue Connect JSON error looks like: 52 | 53 | **Kind**: global class 54 | **Extends**: [HttpError](#HttpError) 55 | **Category**: Resources 56 | 57 | * [APIError](#APIError) ⇐ [HttpError](#HttpError) 58 | * [new APIError(status, message)](#new_APIError_new) 59 | * [.json](#APIError+json) ⇒ object 60 | * [.errorCode](#APIError+errorCode) ⇒ string 61 | * [.errors](#APIError+errors) ⇒ Array 62 | * [.status](#HttpError+status) : number 63 | 64 | 65 | 66 | ### new APIError(status, message) 67 | Create a new instance of the APIError class. 68 | 69 | 70 | | Param | Type | Description | 71 | | --- | --- | --- | 72 | | status | number | the http status code. | 73 | | message | string | A JSON parseable object. | 74 | 75 | **Example** 76 | ```js 77 | { 78 | "error_code": "SYS_001", 79 | "errors": [ 80 | "error message 1" 81 | ] 82 | } 83 | ``` 84 | 85 | 86 | ### apiError.json ⇒ object 87 | Returns the JSON error object. 88 | 89 | **Kind**: instance property of [APIError](#APIError) 90 | **Returns**: object - The error object. 91 | 92 | 93 | ### apiError.errorCode ⇒ string 94 | Returns the error code. 95 | 96 | **Kind**: instance property of [APIError](#APIError) 97 | **Returns**: string - The error code. 98 | 99 | 100 | ### apiError.errors ⇒ Array 101 | Returns an array of error messages. 102 | 103 | **Kind**: instance property of [APIError](#APIError) 104 | **Returns**: Array - The error messages. 105 | 106 | 107 | ### apiError.status : number 108 | The http status code. 109 | 110 | **Kind**: instance property of [APIError](#APIError) 111 | **Overrides**: [status](#HttpError+status) 112 | -------------------------------------------------------------------------------- /mddocs/004_Class_APIError.md: -------------------------------------------------------------------------------- 1 | ## Classes 2 | 3 |
4 |
HttpErrorError
5 |

HttpError wraps any http response which status is != 2xx.

6 |
7 |
APIErrorHttpError
8 |

APIError wraps CloudBlue Connect API errors. 9 | Provides convenient methods to obtains error 10 | code and error messages. 11 | The Cloud Blue Connect JSON error looks like:

12 |
13 |
14 | 15 | 16 | 17 | ## HttpError ⇐ Error 18 | HttpError wraps any http response which status is != 2xx. 19 | 20 | **Kind**: global class 21 | **Extends**: Error 22 | **Category**: Base 23 | 24 | * [HttpError](#HttpError) ⇐ Error 25 | * [new HttpError(status, message)](#new_HttpError_new) 26 | * [.status](#HttpError+status) : number 27 | 28 | 29 | 30 | ### new HttpError(status, message) 31 | Create a new instance of the HttpError class. 32 | 33 | 34 | | Param | Type | Description | 35 | | --- | --- | --- | 36 | | status | number | the http status code. | 37 | | message | string | an error message. | 38 | 39 | 40 | 41 | ### httpError.status : number 42 | The http status code. 43 | 44 | **Kind**: instance property of [HttpError](#HttpError) 45 | 46 | 47 | ## APIError ⇐ [HttpError](#HttpError) 48 | APIError wraps CloudBlue Connect API errors. 49 | Provides convenient methods to obtains error 50 | code and error messages. 51 | The Cloud Blue Connect JSON error looks like: 52 | 53 | **Kind**: global class 54 | **Extends**: [HttpError](#HttpError) 55 | **Category**: Resources 56 | 57 | * [APIError](#APIError) ⇐ [HttpError](#HttpError) 58 | * [new APIError(status, message)](#new_APIError_new) 59 | * [.json](#APIError+json) ⇒ object 60 | * [.errorCode](#APIError+errorCode) ⇒ string 61 | * [.errors](#APIError+errors) ⇒ Array 62 | * [.status](#HttpError+status) : number 63 | 64 | 65 | 66 | ### new APIError(status, message) 67 | Create a new instance of the APIError class. 68 | 69 | 70 | | Param | Type | Description | 71 | | --- | --- | --- | 72 | | status | number | the http status code. | 73 | | message | string | A JSON parseable object. | 74 | 75 | **Example** 76 | ```js 77 | { 78 | "error_code": "SYS_001", 79 | "errors": [ 80 | "error message 1" 81 | ] 82 | } 83 | ``` 84 | 85 | 86 | ### apiError.json ⇒ object 87 | Returns the JSON error object. 88 | 89 | **Kind**: instance property of [APIError](#APIError) 90 | **Returns**: object - The error object. 91 | 92 | 93 | ### apiError.errorCode ⇒ string 94 | Returns the error code. 95 | 96 | **Kind**: instance property of [APIError](#APIError) 97 | **Returns**: string - The error code. 98 | 99 | 100 | ### apiError.errors ⇒ Array 101 | Returns an array of error messages. 102 | 103 | **Kind**: instance property of [APIError](#APIError) 104 | **Returns**: Array - The error messages. 105 | 106 | 107 | ### apiError.status : number 108 | The http status code. 109 | 110 | **Kind**: instance property of [APIError](#APIError) 111 | **Overrides**: [status](#HttpError+status) 112 | -------------------------------------------------------------------------------- /mddocs/006_Class_AbstractHttpAdapter.md: -------------------------------------------------------------------------------- 1 | ## Classes 2 | 3 |
4 |
AbstractHttpAdapter
5 |

The AbstractHttpAdapter class allow a CloudBlue Connect SDK consumer 6 | to wrap a preferred http client library and adapt requests and responses 7 | to in order to work with this SDK.

8 |
9 |
DefaultHttpAdapterAbstractHttpAdapter
10 |

The DefaultHttpAdapter is the default adapter used in the 11 | CloudBlue Connect Javascript SDK based on the node-fetch http 12 | client library.

13 |
14 |
15 | 16 | 17 | 18 | ## AbstractHttpAdapter 19 | The *AbstractHttpAdapter* class allow a CloudBlue Connect SDK consumer 20 | to wrap a preferred http client library and adapt requests and responses 21 | to in order to work with this SDK. 22 | 23 | **Kind**: global class 24 | **Category**: Base 25 | 26 | * [AbstractHttpAdapter](#AbstractHttpAdapter) 27 | * [new AbstractHttpAdapter(fetch)](#new_AbstractHttpAdapter_new) 28 | * [.beforeRequest](#AbstractHttpAdapter+beforeRequest) ⇒ Array 29 | 30 | 31 | 32 | ### new AbstractHttpAdapter(fetch) 33 | Create a subclass of AbstractHttpAdapter 34 | 35 | 36 | | Param | Type | Description | 37 | | --- | --- | --- | 38 | | fetch | function | the fetch function used to make the actual http call. | 39 | 40 | 41 | 42 | ### abstractHttpAdapter.beforeRequest ⇒ Array 43 | Get or set a list of beforeRequest hook functions. 44 | 45 | **Kind**: instance property of [AbstractHttpAdapter](#AbstractHttpAdapter) 46 | **Returns**: Array - Array of hooks. 47 | 48 | 49 | ## DefaultHttpAdapter ⇐ [AbstractHttpAdapter](#AbstractHttpAdapter) 50 | The *DefaultHttpAdapter* is the default adapter used in the 51 | CloudBlue Connect Javascript SDK based on the node-fetch http 52 | client library. 53 | 54 | **Kind**: global class 55 | **Extends**: [AbstractHttpAdapter](#AbstractHttpAdapter) 56 | **Category**: Base 57 | 58 | 59 | ### defaultHttpAdapter.beforeRequest ⇒ Array 60 | Get or set a list of beforeRequest hook functions. 61 | 62 | **Kind**: instance property of [DefaultHttpAdapter](#DefaultHttpAdapter) 63 | **Overrides**: [beforeRequest](#AbstractHttpAdapter+beforeRequest) 64 | **Returns**: Array - Array of hooks. 65 | -------------------------------------------------------------------------------- /mddocs/007_Class_DefaultHttpAdapter.md: -------------------------------------------------------------------------------- 1 | ## Classes 2 | 3 |
4 |
AbstractHttpAdapter
5 |

The AbstractHttpAdapter class allow a CloudBlue Connect SDK consumer 6 | to wrap a preferred http client library and adapt requests and responses 7 | to in order to work with this SDK.

8 |
9 |
DefaultHttpAdapterAbstractHttpAdapter
10 |

The DefaultHttpAdapter is the default adapter used in the 11 | CloudBlue Connect Javascript SDK based on the node-fetch http 12 | client library.

13 |
14 |
15 | 16 | 17 | 18 | ## AbstractHttpAdapter 19 | The *AbstractHttpAdapter* class allow a CloudBlue Connect SDK consumer 20 | to wrap a preferred http client library and adapt requests and responses 21 | to in order to work with this SDK. 22 | 23 | **Kind**: global class 24 | **Category**: Base 25 | 26 | * [AbstractHttpAdapter](#AbstractHttpAdapter) 27 | * [new AbstractHttpAdapter(fetch)](#new_AbstractHttpAdapter_new) 28 | * [.beforeRequest](#AbstractHttpAdapter+beforeRequest) ⇒ Array 29 | 30 | 31 | 32 | ### new AbstractHttpAdapter(fetch) 33 | Create a subclass of AbstractHttpAdapter 34 | 35 | 36 | | Param | Type | Description | 37 | | --- | --- | --- | 38 | | fetch | function | the fetch function used to make the actual http call. | 39 | 40 | 41 | 42 | ### abstractHttpAdapter.beforeRequest ⇒ Array 43 | Get or set a list of beforeRequest hook functions. 44 | 45 | **Kind**: instance property of [AbstractHttpAdapter](#AbstractHttpAdapter) 46 | **Returns**: Array - Array of hooks. 47 | 48 | 49 | ## DefaultHttpAdapter ⇐ [AbstractHttpAdapter](#AbstractHttpAdapter) 50 | The *DefaultHttpAdapter* is the default adapter used in the 51 | CloudBlue Connect Javascript SDK based on the node-fetch http 52 | client library. 53 | 54 | **Kind**: global class 55 | **Extends**: [AbstractHttpAdapter](#AbstractHttpAdapter) 56 | **Category**: Base 57 | 58 | 59 | ### defaultHttpAdapter.beforeRequest ⇒ Array 60 | Get or set a list of beforeRequest hook functions. 61 | 62 | **Kind**: instance property of [DefaultHttpAdapter](#DefaultHttpAdapter) 63 | **Overrides**: [beforeRequest](#AbstractHttpAdapter+beforeRequest) 64 | **Returns**: Array - Array of hooks. 65 | -------------------------------------------------------------------------------- /mddocs/010_Class_Inventory.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Inventory 4 | The Inventory class exposes specialized methods to help 5 | developers to access the inventory (products, items etc). 6 | 7 | **Kind**: global class 8 | **Category**: Operations 9 | 10 | * [Inventory](#Inventory) 11 | * [new Inventory(client)](#new_Inventory_new) 12 | * [.getParametersByProduct(id)](#Inventory+getParametersByProduct) ⇒ Array 13 | * [.getAssetParametersForFulfillmentByProduct(id)](#Inventory+getAssetParametersForFulfillmentByProduct) ⇒ Array 14 | * [.getProductTemplates(id)](#Inventory+getProductTemplates) ⇒ Array 15 | * [.getProductAssetTemplates(id)](#Inventory+getProductAssetTemplates) ⇒ Array 16 | * [.getProductActionLink(id, actionId, assetId)](#Inventory+getProductActionLink) ⇒ Array 17 | * [.searchProductParameters(productId, query)](#Inventory+searchProductParameters) ⇒ Array 18 | 19 | 20 | 21 | ### new Inventory(client) 22 | Creates an instance of the Inventory class. 23 | 24 | **Returns**: [Inventory](#Inventory) - An instance of the Inventory class. 25 | 26 | | Param | Type | Description | 27 | | --- | --- | --- | 28 | | client | ConnectClient | An instance of the ConnectClient class. | 29 | 30 | 31 | 32 | ### inventory.getParametersByProduct(id) ⇒ Array 33 | Retrieves the list of parameters configured for the product. 34 | 35 | **Kind**: instance method of [Inventory](#Inventory) 36 | **Returns**: Array - An array with the Parameter objects. 37 | 38 | | Param | Type | Description | 39 | | --- | --- | --- | 40 | | id | string | The unique product identifier for which retrieve the parameters. | 41 | 42 | 43 | 44 | ### inventory.getAssetParametersForFulfillmentByProduct(id) ⇒ Array 45 | Retrieves the list of parameters of scope asset and phase fulfillment configured for 46 | the product. 47 | 48 | **Kind**: instance method of [Inventory](#Inventory) 49 | **Returns**: Array - An array with the Parameter objects. 50 | 51 | | Param | Type | Description | 52 | | --- | --- | --- | 53 | | id | string | The unique product identifier for which retrieve the parameters. | 54 | 55 | 56 | 57 | ### inventory.getProductTemplates(id) ⇒ Array 58 | Returns the list of templates configured for a product. 59 | 60 | **Kind**: instance method of [Inventory](#Inventory) 61 | **Returns**: Array - An array of Template objects. 62 | 63 | | Param | Type | Description | 64 | | --- | --- | --- | 65 | | id | string | The unique identifier of the product. | 66 | 67 | 68 | 69 | ### inventory.getProductAssetTemplates(id) ⇒ Array 70 | Returns the list of templates configured for a product with scope "asset". 71 | 72 | **Kind**: instance method of [Inventory](#Inventory) 73 | **Returns**: Array - An array of Template objects. 74 | 75 | | Param | Type | Description | 76 | | --- | --- | --- | 77 | | id | string | The unique identifier of the product. | 78 | 79 | 80 | 81 | ### inventory.getProductActionLink(id, actionId, assetId) ⇒ Array 82 | Returns the action link for a product action. 83 | 84 | **Kind**: instance method of [Inventory](#Inventory) 85 | **Returns**: Array - An array of Template objects. 86 | 87 | | Param | Type | Description | 88 | | --- | --- | --- | 89 | | id | string | The unique identifier of the product. | 90 | | actionId | string | The unique product action identifier. | 91 | | assetId | string | The unique asset identifier. | 92 | 93 | 94 | 95 | ### inventory.searchProductParameters(productId, query) ⇒ Array 96 | Search the parameters configured for a product. 97 | 98 | **Kind**: instance method of [Inventory](#Inventory) 99 | **Returns**: Array - An array with the Parameter objects. 100 | 101 | | Param | Type | Description | 102 | | --- | --- | --- | 103 | | productId | string | The id of the product for which search parameters. | 104 | | query | object | The filter query. | 105 | 106 | -------------------------------------------------------------------------------- /mddocs/013_Class_AccountUserResource.md: -------------------------------------------------------------------------------- 1 | ## Classes 2 | 3 |
4 |
AccountUserResourceGenericResource
5 |

The AccountUserResource allow consumers of the CloudBlue Connect 6 | API to access information about Users related to an account.

7 |
8 |
AccountResourceGenericResource
9 |

The AccountResource class provides methods to access the accounts 10 | endpoint of the Cloud Blue Connect API.

11 |
12 |
13 | 14 | 15 | 16 | ## AccountUserResource ⇐ GenericResource 17 | The *AccountUserResource* allow consumers of the CloudBlue Connect 18 | API to access information about *Users* related to an account. 19 | 20 | **Kind**: global class 21 | **Extends**: GenericResource 22 | **Category**: Resources 23 | 24 | 25 | ## AccountResource ⇐ GenericResource 26 | The *AccountResource* class provides methods to access the accounts 27 | endpoint of the Cloud Blue Connect API. 28 | 29 | **Kind**: global class 30 | **Extends**: GenericResource 31 | **Category**: Resources 32 | 33 | * [AccountResource](#AccountResource) ⇐ GenericResource 34 | * [new AccountResource(client)](#new_AccountResource_new) 35 | * [.users(id)](#AccountResource+users) ⇒ [AccountUserResource](#AccountUserResource) 36 | 37 | 38 | 39 | ### new AccountResource(client) 40 | Creates a new instance of the *AccountResource* class. 41 | 42 | **Returns**: [AccountResource](#AccountResource) - An instance of the *AccountResource* class. 43 | 44 | | Param | Type | Description | 45 | | --- | --- | --- | 46 | | client | ConnectClient | An instance of the *ConnectClient* class. | 47 | 48 | 49 | 50 | ### accountResource.users(id) ⇒ [AccountUserResource](#AccountUserResource) 51 | Returns an instance of the *AccountUserResorce* class. 52 | 53 | **Kind**: instance method of [AccountResource](#AccountResource) 54 | **Returns**: [AccountUserResource](#AccountUserResource) - An instance of *AccountUserResource*. 55 | 56 | | Param | Type | Description | 57 | | --- | --- | --- | 58 | | id | string | The account unique identifier. | 59 | 60 | -------------------------------------------------------------------------------- /mddocs/014_Class_AccountResource.md: -------------------------------------------------------------------------------- 1 | ## Classes 2 | 3 |
4 |
AccountUserResourceGenericResource
5 |

The AccountUserResource allow consumers of the CloudBlue Connect 6 | API to access information about Users related to an account.

7 |
8 |
AccountResourceGenericResource
9 |

The AccountResource class provides methods to access the accounts 10 | endpoint of the Cloud Blue Connect API.

11 |
12 |
13 | 14 | 15 | 16 | ## AccountUserResource ⇐ GenericResource 17 | The *AccountUserResource* allow consumers of the CloudBlue Connect 18 | API to access information about *Users* related to an account. 19 | 20 | **Kind**: global class 21 | **Extends**: GenericResource 22 | **Category**: Resources 23 | 24 | 25 | ## AccountResource ⇐ GenericResource 26 | The *AccountResource* class provides methods to access the accounts 27 | endpoint of the Cloud Blue Connect API. 28 | 29 | **Kind**: global class 30 | **Extends**: GenericResource 31 | **Category**: Resources 32 | 33 | * [AccountResource](#AccountResource) ⇐ GenericResource 34 | * [new AccountResource(client)](#new_AccountResource_new) 35 | * [.users(id)](#AccountResource+users) ⇒ [AccountUserResource](#AccountUserResource) 36 | 37 | 38 | 39 | ### new AccountResource(client) 40 | Creates a new instance of the *AccountResource* class. 41 | 42 | **Returns**: [AccountResource](#AccountResource) - An instance of the *AccountResource* class. 43 | 44 | | Param | Type | Description | 45 | | --- | --- | --- | 46 | | client | ConnectClient | An instance of the *ConnectClient* class. | 47 | 48 | 49 | 50 | ### accountResource.users(id) ⇒ [AccountUserResource](#AccountUserResource) 51 | Returns an instance of the *AccountUserResorce* class. 52 | 53 | **Kind**: instance method of [AccountResource](#AccountResource) 54 | **Returns**: [AccountUserResource](#AccountUserResource) - An instance of *AccountUserResource*. 55 | 56 | | Param | Type | Description | 57 | | --- | --- | --- | 58 | | id | string | The account unique identifier. | 59 | 60 | -------------------------------------------------------------------------------- /mddocs/015_Class_AssetUsageAgregatesResource.md: -------------------------------------------------------------------------------- 1 | ## Classes 2 | 3 |
4 |
AssetUsageAgregatesResourceGenericResource
5 |

The AssetUsageAgregatesResource class provides methods to access the 6 | AssetUsageAgregates objects for a asset.

7 |
8 |
AssetResourceGenericResource
9 |

The AssetResource class provides methods to access the assets 10 | endpoint of the Cloud Blue Connect API.

11 |
12 |
13 | 14 | 15 | 16 | ## AssetUsageAgregatesResource ⇐ GenericResource 17 | The *AssetUsageAgregatesResource* class provides methods to access the 18 | *AssetUsageAgregates* objects for a asset. 19 | 20 | **Kind**: global class 21 | **Extends**: GenericResource 22 | **Category**: Resources 23 | 24 | 25 | ## AssetResource ⇐ GenericResource 26 | The *AssetResource* class provides methods to access the assets 27 | endpoint of the Cloud Blue Connect API. 28 | 29 | **Kind**: global class 30 | **Extends**: GenericResource 31 | **Category**: Resources 32 | 33 | * [AssetResource](#AssetResource) ⇐ GenericResource 34 | * [new AssetResource(client)](#new_AssetResource_new) 35 | * [.usageAgregates(id)](#AssetResource+usageAgregates) ⇒ [AssetUsageAgregatesResource](#AssetUsageAgregatesResource) 36 | 37 | 38 | 39 | ### new AssetResource(client) 40 | Creates a new instance of the *AssetResource* class. 41 | 42 | **Returns**: [AssetResource](#AssetResource) - An instance of the *AssetResource* class. 43 | 44 | | Param | Type | Description | 45 | | --- | --- | --- | 46 | | client | ConnectClient | An instance of the *ConnectClient* class. | 47 | 48 | 49 | 50 | ### assetResource.usageAgregates(id) ⇒ [AssetUsageAgregatesResource](#AssetUsageAgregatesResource) 51 | Returns an instance of the *AssetUsageAgregatesResource* for a *Asset*. 52 | 53 | **Kind**: instance method of [AssetResource](#AssetResource) 54 | **Returns**: [AssetUsageAgregatesResource](#AssetUsageAgregatesResource) - An instance of the *AssetUsageAgregatesResource* 55 | for the asset. 56 | 57 | | Param | Type | Description | 58 | | --- | --- | --- | 59 | | id | string | The unique identifier of the *Product*. | 60 | 61 | -------------------------------------------------------------------------------- /mddocs/016_Class_AssetResource.md: -------------------------------------------------------------------------------- 1 | ## Classes 2 | 3 |
4 |
AssetUsageAgregatesResourceGenericResource
5 |

The AssetUsageAgregatesResource class provides methods to access the 6 | AssetUsageAgregates objects for a asset.

7 |
8 |
AssetResourceGenericResource
9 |

The AssetResource class provides methods to access the assets 10 | endpoint of the Cloud Blue Connect API.

11 |
12 |
13 | 14 | 15 | 16 | ## AssetUsageAgregatesResource ⇐ GenericResource 17 | The *AssetUsageAgregatesResource* class provides methods to access the 18 | *AssetUsageAgregates* objects for a asset. 19 | 20 | **Kind**: global class 21 | **Extends**: GenericResource 22 | **Category**: Resources 23 | 24 | 25 | ## AssetResource ⇐ GenericResource 26 | The *AssetResource* class provides methods to access the assets 27 | endpoint of the Cloud Blue Connect API. 28 | 29 | **Kind**: global class 30 | **Extends**: GenericResource 31 | **Category**: Resources 32 | 33 | * [AssetResource](#AssetResource) ⇐ GenericResource 34 | * [new AssetResource(client)](#new_AssetResource_new) 35 | * [.usageAgregates(id)](#AssetResource+usageAgregates) ⇒ [AssetUsageAgregatesResource](#AssetUsageAgregatesResource) 36 | 37 | 38 | 39 | ### new AssetResource(client) 40 | Creates a new instance of the *AssetResource* class. 41 | 42 | **Returns**: [AssetResource](#AssetResource) - An instance of the *AssetResource* class. 43 | 44 | | Param | Type | Description | 45 | | --- | --- | --- | 46 | | client | ConnectClient | An instance of the *ConnectClient* class. | 47 | 48 | 49 | 50 | ### assetResource.usageAgregates(id) ⇒ [AssetUsageAgregatesResource](#AssetUsageAgregatesResource) 51 | Returns an instance of the *AssetUsageAgregatesResource* for a *Asset*. 52 | 53 | **Kind**: instance method of [AssetResource](#AssetResource) 54 | **Returns**: [AssetUsageAgregatesResource](#AssetUsageAgregatesResource) - An instance of the *AssetUsageAgregatesResource* 55 | for the asset. 56 | 57 | | Param | Type | Description | 58 | | --- | --- | --- | 59 | | id | string | The unique identifier of the *Product*. | 60 | 61 | -------------------------------------------------------------------------------- /mddocs/017_Class_GenericResource.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## GenericResource 4 | The *GenericResource* map a generic endpoint of the CloudBlue 5 | Connect API. Each API endpoint should extend this class and 6 | implements endpoint specific actions and subresources access. 7 | 8 | **Kind**: global class 9 | **Category**: Resources 10 | 11 | * [GenericResource](#GenericResource) 12 | * [new GenericResource(client, baseUri)](#new_GenericResource_new) 13 | * [.baseUri](#GenericResource+baseUri) : string 14 | * [.get(id)](#GenericResource+get) ⇒ object 15 | * [.create(obj)](#GenericResource+create) ⇒ object 16 | * [.update(id, obj)](#GenericResource+update) ⇒ object 17 | * [.delete(id)](#GenericResource+delete) 18 | * [.search(filters)](#GenericResource+search) ⇒ Array 19 | * [.fetch(url, options)](#GenericResource+fetch) 20 | 21 | 22 | 23 | ### new GenericResource(client, baseUri) 24 | 25 | | Param | Type | Description | 26 | | --- | --- | --- | 27 | | client | ConnectClient | A *ConnectClient* instance. | 28 | | baseUri | string | The base URI of the resource | 29 | 30 | 31 | 32 | ### genericResource.baseUri : string 33 | Returns the base URI of the resource mapped by this class. 34 | 35 | **Kind**: instance property of [GenericResource](#GenericResource) 36 | 37 | 38 | ### genericResource.get(id) ⇒ object 39 | Retrieve a resource by its unique identifier. 40 | 41 | **Kind**: instance method of [GenericResource](#GenericResource) 42 | **Returns**: object - The resource. 43 | 44 | | Param | Type | Description | 45 | | --- | --- | --- | 46 | | id | string | The unique identifier of the resource to retrieve. | 47 | 48 | 49 | 50 | ### genericResource.create(obj) ⇒ object 51 | Create a new resource. 52 | 53 | **Kind**: instance method of [GenericResource](#GenericResource) 54 | **Returns**: object - The created resource. 55 | 56 | | Param | Type | Description | 57 | | --- | --- | --- | 58 | | obj | object | The resource to create. | 59 | 60 | 61 | 62 | ### genericResource.update(id, obj) ⇒ object 63 | Update a resource. 64 | 65 | **Kind**: instance method of [GenericResource](#GenericResource) 66 | **Returns**: object - The updated resource. 67 | 68 | | Param | Type | Description | 69 | | --- | --- | --- | 70 | | id | string | The unique identifier of the resource to update. | 71 | | obj | object | The eventually partial resource to update. | 72 | 73 | 74 | 75 | ### genericResource.delete(id) 76 | Delete a resource. 77 | 78 | **Kind**: instance method of [GenericResource](#GenericResource) 79 | 80 | | Param | Type | Description | 81 | | --- | --- | --- | 82 | | id | string | The unique identifier of the resource to delete. | 83 | 84 | 85 | 86 | ### genericResource.search(filters) ⇒ Array 87 | Search for a resource. 88 | 89 | **Kind**: instance method of [GenericResource](#GenericResource) 90 | **Returns**: Array - An array of resources that match the provided filters. 91 | 92 | | Param | Type | Description | 93 | | --- | --- | --- | 94 | | filters | object | The query to send to the server as a RQL object. | 95 | 96 | 97 | 98 | ### genericResource.fetch(url, options) 99 | Fetch the URL and returns a response. 100 | 101 | **Kind**: instance method of [GenericResource](#GenericResource) 102 | 103 | | Param | Type | Description | 104 | | --- | --- | --- | 105 | | url | string | the URL to fetch. | 106 | | options | object | the request options. | 107 | 108 | -------------------------------------------------------------------------------- /mddocs/018_Class_BillingRequestResource.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## BillingRequestResource ⇐ GenericResource 4 | The *BillingRequestResource* class provides methods to access the billing 5 | requests endpoint of the Cloud Blue Connect API. 6 | 7 | **Kind**: global class 8 | **Extends**: GenericResource 9 | **Category**: Resources 10 | 11 | * [BillingRequestResource](#BillingRequestResource) ⇐ GenericResource 12 | * [new BillingRequestResource(client)](#new_BillingRequestResource_new) 13 | * [.updateAttributes(id, attributes)](#BillingRequestResource+updateAttributes) ⇒ object 14 | 15 | 16 | 17 | ### new BillingRequestResource(client) 18 | Creates a new instance of the *BillingRequestResource* class. 19 | 20 | **Returns**: [BillingRequestResource](#BillingRequestResource) - An instance of the *BillingRequestResource* class. 21 | 22 | | Param | Type | Description | 23 | | --- | --- | --- | 24 | | client | ConnectClient | An instance of the ConnectClient class. | 25 | 26 | 27 | 28 | ### billingRequestResource.updateAttributes(id, attributes) ⇒ object 29 | Update billing request attributs. 30 | 31 | **Kind**: instance method of [BillingRequestResource](#BillingRequestResource) 32 | **Returns**: object - The updated attributes object. 33 | 34 | | Param | Type | Description | 35 | | --- | --- | --- | 36 | | id | string | The unique identified of the *BillingRequest*. | 37 | | attributes | object | An object containing the attributes to update. | 38 | 39 | -------------------------------------------------------------------------------- /mddocs/022_Class_MessageResource.md: -------------------------------------------------------------------------------- 1 | ## Classes 2 | 3 |
4 |
MessageResourceGenericResource
5 |

The MessageResources class provides methods to access the 6 | attachment objects for a case.

7 |
8 |
ConversationResourceGenericResource
9 |

The ConversationResource class provides methods to access the conversations 10 | endpoint of the Cloud Blue Connect API.

11 |
12 |
13 | 14 | 15 | 16 | ## MessageResource ⇐ GenericResource 17 | The *MessageResources* class provides methods to access the 18 | *attachment* objects for a case. 19 | 20 | **Kind**: global class 21 | **Extends**: GenericResource 22 | **Category**: Resources 23 | 24 | 25 | ## ConversationResource ⇐ GenericResource 26 | The *ConversationResource* class provides methods to access the conversations 27 | endpoint of the Cloud Blue Connect API. 28 | 29 | **Kind**: global class 30 | **Extends**: GenericResource 31 | **Category**: Resources 32 | 33 | * [ConversationResource](#ConversationResource) ⇐ GenericResource 34 | * [new ConversationResource(client)](#new_ConversationResource_new) 35 | * [.messages(id)](#ConversationResource+messages) ⇒ CaseCommentsResource 36 | * [.getConversationsByObjectId(id)](#ConversationResource+getConversationsByObjectId) ⇒ Array 37 | * [.createMessage(id, msg)](#ConversationResource+createMessage) ⇒ object 38 | 39 | 40 | 41 | ### new ConversationResource(client) 42 | Creates a new instance of the *ConversationResource* class. 43 | 44 | **Returns**: [ConversationResource](#ConversationResource) - An instance of the *ConversationResource* class. 45 | 46 | | Param | Type | Description | 47 | | --- | --- | --- | 48 | | client | ConnectClient | An instance of the ConnectClient class. | 49 | 50 | 51 | 52 | ### conversationResource.messages(id) ⇒ CaseCommentsResource 53 | Returns an instance of the *ConversationMessageResource* for a *Conversation*. 54 | 55 | **Kind**: instance method of [ConversationResource](#ConversationResource) 56 | **Returns**: CaseCommentsResource - An instance of the *ConversationMessageResource* 57 | for the case. 58 | 59 | | Param | Type | Description | 60 | | --- | --- | --- | 61 | | id | string | The unique identifier of the *Conversation*. | 62 | 63 | 64 | 65 | ### conversationResource.getConversationsByObjectId(id) ⇒ Array 66 | Returns a list of conversations attached to the business object specified by its id. 67 | 68 | **Kind**: instance method of [ConversationResource](#ConversationResource) 69 | **Returns**: Array - A list of conversations attached to a business object. 70 | 71 | | Param | Type | Description | 72 | | --- | --- | --- | 73 | | id | string | The unique id of the business object attached to a conversation. | 74 | 75 | 76 | 77 | ### conversationResource.createMessage(id, msg) ⇒ object 78 | Add a message to a *Conversation* object. 79 | 80 | **Kind**: instance method of [ConversationResource](#ConversationResource) 81 | **Returns**: object - The newly created *Message* object. 82 | 83 | | Param | Type | Description | 84 | | --- | --- | --- | 85 | | id | string | The unique identifier of the Conversation object. | 86 | | msg | string | The text of the message to post. | 87 | 88 | -------------------------------------------------------------------------------- /mddocs/023_Class_ConversationResource.md: -------------------------------------------------------------------------------- 1 | ## Classes 2 | 3 |
4 |
MessageResourceGenericResource
5 |

The MessageResources class provides methods to access the 6 | attachment objects for a case.

7 |
8 |
ConversationResourceGenericResource
9 |

The ConversationResource class provides methods to access the conversations 10 | endpoint of the Cloud Blue Connect API.

11 |
12 |
13 | 14 | 15 | 16 | ## MessageResource ⇐ GenericResource 17 | The *MessageResources* class provides methods to access the 18 | *attachment* objects for a case. 19 | 20 | **Kind**: global class 21 | **Extends**: GenericResource 22 | **Category**: Resources 23 | 24 | 25 | ## ConversationResource ⇐ GenericResource 26 | The *ConversationResource* class provides methods to access the conversations 27 | endpoint of the Cloud Blue Connect API. 28 | 29 | **Kind**: global class 30 | **Extends**: GenericResource 31 | **Category**: Resources 32 | 33 | * [ConversationResource](#ConversationResource) ⇐ GenericResource 34 | * [new ConversationResource(client)](#new_ConversationResource_new) 35 | * [.messages(id)](#ConversationResource+messages) ⇒ CaseCommentsResource 36 | * [.getConversationsByObjectId(id)](#ConversationResource+getConversationsByObjectId) ⇒ Array 37 | * [.createMessage(id, msg)](#ConversationResource+createMessage) ⇒ object 38 | 39 | 40 | 41 | ### new ConversationResource(client) 42 | Creates a new instance of the *ConversationResource* class. 43 | 44 | **Returns**: [ConversationResource](#ConversationResource) - An instance of the *ConversationResource* class. 45 | 46 | | Param | Type | Description | 47 | | --- | --- | --- | 48 | | client | ConnectClient | An instance of the ConnectClient class. | 49 | 50 | 51 | 52 | ### conversationResource.messages(id) ⇒ CaseCommentsResource 53 | Returns an instance of the *ConversationMessageResource* for a *Conversation*. 54 | 55 | **Kind**: instance method of [ConversationResource](#ConversationResource) 56 | **Returns**: CaseCommentsResource - An instance of the *ConversationMessageResource* 57 | for the case. 58 | 59 | | Param | Type | Description | 60 | | --- | --- | --- | 61 | | id | string | The unique identifier of the *Conversation*. | 62 | 63 | 64 | 65 | ### conversationResource.getConversationsByObjectId(id) ⇒ Array 66 | Returns a list of conversations attached to the business object specified by its id. 67 | 68 | **Kind**: instance method of [ConversationResource](#ConversationResource) 69 | **Returns**: Array - A list of conversations attached to a business object. 70 | 71 | | Param | Type | Description | 72 | | --- | --- | --- | 73 | | id | string | The unique id of the business object attached to a conversation. | 74 | 75 | 76 | 77 | ### conversationResource.createMessage(id, msg) ⇒ object 78 | Add a message to a *Conversation* object. 79 | 80 | **Kind**: instance method of [ConversationResource](#ConversationResource) 81 | **Returns**: object - The newly created *Message* object. 82 | 83 | | Param | Type | Description | 84 | | --- | --- | --- | 85 | | id | string | The unique identifier of the Conversation object. | 86 | | msg | string | The text of the message to post. | 87 | 88 | -------------------------------------------------------------------------------- /mddocs/024_Class_HubResource.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## HubResource ⇐ GenericResource 4 | The *HubResource* class provides methods to access the hubs 5 | endpoint of the Cloud Blue Connect API. 6 | 7 | **Kind**: global class 8 | **Extends**: GenericResource 9 | **Category**: Resources 10 | 11 | 12 | ### new HubResource(client) 13 | Creates a new instance of the *HubResource* class. 14 | 15 | **Returns**: [HubResource](#HubResource) - An instance of the *HubResource* class. 16 | 17 | | Param | Type | Description | 18 | | --- | --- | --- | 19 | | client | ConnectClient | An instance of the *ConnectClient* class. | 20 | 21 | -------------------------------------------------------------------------------- /mddocs/025_Class_ListingRequestResource.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## ListingRequestResource ⇐ GenericResource 4 | The *ListingRequestResource* class provides methods to access the listing 5 | requests endpoint of the Cloud Blue Connect API. 6 | 7 | **Kind**: global class 8 | **Extends**: GenericResource 9 | **Category**: Resources 10 | 11 | * [ListingRequestResource](#ListingRequestResource) ⇐ GenericResource 12 | * [new ListingRequestResource(client)](#new_ListingRequestResource_new) 13 | * [.cancel(id)](#ListingRequestResource+cancel) 14 | * [.complete(id)](#ListingRequestResource+complete) 15 | * [.deploy(id)](#ListingRequestResource+deploy) 16 | * [.refine(id)](#ListingRequestResource+refine) 17 | * [.submit(id)](#ListingRequestResource+submit) 18 | 19 | 20 | 21 | ### new ListingRequestResource(client) 22 | Creates a new instance of the *ListingRequestResource* class. 23 | 24 | **Returns**: [ListingRequestResource](#ListingRequestResource) - An instance of the *ListingRequestResource* class. 25 | 26 | | Param | Type | Description | 27 | | --- | --- | --- | 28 | | client | ConnectClient | An instance of the ConnectClient class. | 29 | 30 | 31 | 32 | ### listingRequestResource.cancel(id) 33 | Cancel the ListingRequest. 34 | 35 | **Kind**: instance method of [ListingRequestResource](#ListingRequestResource) 36 | 37 | | Param | Type | Description | 38 | | --- | --- | --- | 39 | | id | string | The unique identifier of the ListingRequest object. | 40 | 41 | 42 | 43 | ### listingRequestResource.complete(id) 44 | Complete the ListingRequest. 45 | 46 | **Kind**: instance method of [ListingRequestResource](#ListingRequestResource) 47 | 48 | | Param | Type | Description | 49 | | --- | --- | --- | 50 | | id | string | The unique identifier of the ListingRequest object. | 51 | 52 | 53 | 54 | ### listingRequestResource.deploy(id) 55 | Deploy the ListingRequest. 56 | 57 | **Kind**: instance method of [ListingRequestResource](#ListingRequestResource) 58 | 59 | | Param | Type | Description | 60 | | --- | --- | --- | 61 | | id | string | The unique identifier of the ListingRequest object. | 62 | 63 | 64 | 65 | ### listingRequestResource.refine(id) 66 | Refine the ListingRequest. 67 | 68 | **Kind**: instance method of [ListingRequestResource](#ListingRequestResource) 69 | 70 | | Param | Type | Description | 71 | | --- | --- | --- | 72 | | id | string | The unique identifier of the ListingRequest object. | 73 | 74 | 75 | 76 | ### listingRequestResource.submit(id) 77 | Submit the ListingRequest. 78 | 79 | **Kind**: instance method of [ListingRequestResource](#ListingRequestResource) 80 | 81 | | Param | Type | Description | 82 | | --- | --- | --- | 83 | | id | string | The unique identifier of the ListingRequest object. | 84 | 85 | -------------------------------------------------------------------------------- /mddocs/033_Class_RecurringAssetResource.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## RecurringAssetResource ⇐ GenericResource 4 | The *RecurringAssetResource* class provides methods to access the recurring 5 | assets endpoint of the Cloud Blue Connect API. 6 | 7 | **Kind**: global class 8 | **Extends**: GenericResource 9 | **Category**: Resources 10 | 11 | 12 | ### new RecurringAssetResource(client) 13 | Creates a new instance of the *RecurringAssetResource* class. 14 | 15 | **Returns**: [RecurringAssetResource](#RecurringAssetResource) - An instance of the *RecurringAssetResource* class. 16 | 17 | | Param | Type | Description | 18 | | --- | --- | --- | 19 | | client | ConnectClient | An instance of the ConnectClient class. | 20 | 21 | -------------------------------------------------------------------------------- /mddocs/035_Class_TierAccountRequestResource.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## TierAccountRequestResource ⇐ GenericResource 4 | The *TierAccountRequestResource* class provides methods to access the tier account 5 | requests endpoint of the Cloud Blue Connect API. 6 | 7 | **Kind**: global class 8 | **Extends**: GenericResource 9 | **Category**: Resources 10 | 11 | * [TierAccountRequestResource](#TierAccountRequestResource) ⇐ GenericResource 12 | * [new TierAccountRequestResource(client)](#new_TierAccountRequestResource_new) 13 | * [.accept(id)](#TierAccountRequestResource+accept) ⇒ object 14 | * [.ignore(id, reason)](#TierAccountRequestResource+ignore) ⇒ object 15 | 16 | 17 | 18 | ### new TierAccountRequestResource(client) 19 | Creates a new instance of the *TierAccountRequestResource* class. 20 | 21 | **Returns**: [TierAccountRequestResource](#TierAccountRequestResource) - An instance of the *TierAccountRequestResource* class. 22 | 23 | | Param | Type | Description | 24 | | --- | --- | --- | 25 | | client | ConnectClient | An instance of the ConnectClient class. | 26 | 27 | 28 | 29 | ### tierAccountRequestResource.accept(id) ⇒ object 30 | Accept the TierAccountRequest. 31 | 32 | **Kind**: instance method of [TierAccountRequestResource](#TierAccountRequestResource) 33 | **Returns**: object - The accepted TierAccountRequest object. 34 | 35 | | Param | Type | Description | 36 | | --- | --- | --- | 37 | | id | string | The unique identifier of the TierAccountRequest object. | 38 | 39 | 40 | 41 | ### tierAccountRequestResource.ignore(id, reason) ⇒ object 42 | Ignore the TierAccountRequest. 43 | 44 | **Kind**: instance method of [TierAccountRequestResource](#TierAccountRequestResource) 45 | **Returns**: object - The ignored TierAccountRequest object. 46 | 47 | | Param | Type | Description | 48 | | --- | --- | --- | 49 | | id | string | The unique identifier of the TierAccountRequest object. | 50 | | reason | string | The reason for which vendor ignore this request. | 51 | 52 | -------------------------------------------------------------------------------- /mddocs/036_Class_TierAccountVersionResource.md: -------------------------------------------------------------------------------- 1 | ## Classes 2 | 3 |
4 |
TierAccountVersionResourceGenericResource
5 |

The TierAccountVersionResource class provides methods to access the 6 | Version objects for a tier account.

7 |
8 |
TierAccountResourceGenericResource
9 |

The TierAccountResource class provides methods to access the tier accounts 10 | endpoint of the Cloud Blue Connect API.

11 |
12 |
13 | 14 | 15 | 16 | ## TierAccountVersionResource ⇐ GenericResource 17 | The *TierAccountVersionResource* class provides methods to access the 18 | *Version* objects for a tier account. 19 | 20 | **Kind**: global class 21 | **Extends**: GenericResource 22 | **Category**: Resources 23 | 24 | 25 | ## TierAccountResource ⇐ GenericResource 26 | The *TierAccountResource* class provides methods to access the tier accounts 27 | endpoint of the Cloud Blue Connect API. 28 | 29 | **Kind**: global class 30 | **Extends**: GenericResource 31 | **Category**: Resources 32 | 33 | * [TierAccountResource](#TierAccountResource) ⇐ GenericResource 34 | * [new TierAccountResource(client)](#new_TierAccountResource_new) 35 | * [.versions(id)](#TierAccountResource+versions) ⇒ [TierAccountVersionResource](#TierAccountVersionResource) 36 | 37 | 38 | 39 | ### new TierAccountResource(client) 40 | Creates a new instance of the *TierAccountResource* class. 41 | 42 | **Returns**: [TierAccountResource](#TierAccountResource) - An instance of the *TierAccountResource* class. 43 | 44 | | Param | Type | Description | 45 | | --- | --- | --- | 46 | | client | ConnectClient | An instance of the ConnectClient class. | 47 | 48 | 49 | 50 | ### tierAccountResource.versions(id) ⇒ [TierAccountVersionResource](#TierAccountVersionResource) 51 | Returns an instance of the *TierAccountVersionResource* for a *TierAccount*. 52 | 53 | **Kind**: instance method of [TierAccountResource](#TierAccountResource) 54 | **Returns**: [TierAccountVersionResource](#TierAccountVersionResource) - An instance of the *TierAccountVersionResource* 55 | for the product. 56 | 57 | | Param | Type | Description | 58 | | --- | --- | --- | 59 | | id | string | The unique identifier of the *TierAccount*. | 60 | 61 | -------------------------------------------------------------------------------- /mddocs/037_Class_TierAccountResource.md: -------------------------------------------------------------------------------- 1 | ## Classes 2 | 3 |
4 |
TierAccountVersionResourceGenericResource
5 |

The TierAccountVersionResource class provides methods to access the 6 | Version objects for a tier account.

7 |
8 |
TierAccountResourceGenericResource
9 |

The TierAccountResource class provides methods to access the tier accounts 10 | endpoint of the Cloud Blue Connect API.

11 |
12 |
13 | 14 | 15 | 16 | ## TierAccountVersionResource ⇐ GenericResource 17 | The *TierAccountVersionResource* class provides methods to access the 18 | *Version* objects for a tier account. 19 | 20 | **Kind**: global class 21 | **Extends**: GenericResource 22 | **Category**: Resources 23 | 24 | 25 | ## TierAccountResource ⇐ GenericResource 26 | The *TierAccountResource* class provides methods to access the tier accounts 27 | endpoint of the Cloud Blue Connect API. 28 | 29 | **Kind**: global class 30 | **Extends**: GenericResource 31 | **Category**: Resources 32 | 33 | * [TierAccountResource](#TierAccountResource) ⇐ GenericResource 34 | * [new TierAccountResource(client)](#new_TierAccountResource_new) 35 | * [.versions(id)](#TierAccountResource+versions) ⇒ [TierAccountVersionResource](#TierAccountVersionResource) 36 | 37 | 38 | 39 | ### new TierAccountResource(client) 40 | Creates a new instance of the *TierAccountResource* class. 41 | 42 | **Returns**: [TierAccountResource](#TierAccountResource) - An instance of the *TierAccountResource* class. 43 | 44 | | Param | Type | Description | 45 | | --- | --- | --- | 46 | | client | ConnectClient | An instance of the ConnectClient class. | 47 | 48 | 49 | 50 | ### tierAccountResource.versions(id) ⇒ [TierAccountVersionResource](#TierAccountVersionResource) 51 | Returns an instance of the *TierAccountVersionResource* for a *TierAccount*. 52 | 53 | **Kind**: instance method of [TierAccountResource](#TierAccountResource) 54 | **Returns**: [TierAccountVersionResource](#TierAccountVersionResource) - An instance of the *TierAccountVersionResource* 55 | for the product. 56 | 57 | | Param | Type | Description | 58 | | --- | --- | --- | 59 | | id | string | The unique identifier of the *TierAccount*. | 60 | 61 | -------------------------------------------------------------------------------- /mddocs/038_Class_TierConfigRequestResource.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## TierConfigRequestResource ⇐ GenericResource 4 | The *TierConfigRequestResource* class provides methods to access the *TierConfigRequest* 5 | endpoint of the Cloud Blue Connect API. 6 | 7 | **Kind**: global class 8 | **Extends**: GenericResource 9 | **Category**: Resources 10 | 11 | * [TierConfigRequestResource](#TierConfigRequestResource) ⇐ GenericResource 12 | * [new TierConfigRequestResource(client)](#new_TierConfigRequestResource_new) 13 | * [.fail(id, reason)](#TierConfigRequestResource+fail) 14 | * [.inquire(id)](#TierConfigRequestResource+inquire) 15 | * [.pending(id)](#TierConfigRequestResource+pending) 16 | * [.approve(id, request)](#TierConfigRequestResource+approve) ⇒ object 17 | 18 | 19 | 20 | ### new TierConfigRequestResource(client) 21 | Creates a new instance of the *TierConfigRequestResource* class. 22 | 23 | **Returns**: [TierConfigRequestResource](#TierConfigRequestResource) - An instance of the *TierConfigRequestResource* class. 24 | 25 | | Param | Type | Description | 26 | | --- | --- | --- | 27 | | client | ConnectClient | An instance of the ConnectClient class. | 28 | 29 | 30 | 31 | ### tierConfigRequestResource.fail(id, reason) 32 | Changes the status of a *TierConfigurationRequest* to fail. 33 | 34 | **Kind**: instance method of [TierConfigRequestResource](#TierConfigRequestResource) 35 | 36 | | Param | Type | Description | 37 | | --- | --- | --- | 38 | | id | string | The unique identifier of the TierConfigurationRequest object. | 39 | | reason | string | The reason for which the TierConfigurationRequest has been failed. | 40 | 41 | 42 | 43 | ### tierConfigRequestResource.inquire(id) 44 | Changes the status of a *TierConfigurationRequest* to inquire. 45 | 46 | **Kind**: instance method of [TierConfigRequestResource](#TierConfigRequestResource) 47 | 48 | | Param | Type | Description | 49 | | --- | --- | --- | 50 | | id | string | The unique identifier of the TierConfigurationRequest object. | 51 | 52 | 53 | 54 | ### tierConfigRequestResource.pending(id) 55 | Changes the status of a *TierConfigurationRequest* to pending. 56 | 57 | **Kind**: instance method of [TierConfigRequestResource](#TierConfigRequestResource) 58 | 59 | | Param | Type | Description | 60 | | --- | --- | --- | 61 | | id | string | The unique identifier of the TierConfigurationRequest object. | 62 | 63 | 64 | 65 | ### tierConfigRequestResource.approve(id, request) ⇒ object 66 | Change the status of a *TierConfigurationRequest* to approved. 67 | To change the status of the TierConfigurationRequest to approved 68 | you must provide a Template id. 69 | 70 | **Kind**: instance method of [TierConfigRequestResource](#TierConfigRequestResource) 71 | **Returns**: object - The rendered Template. 72 | 73 | | Param | Type | Description | 74 | | --- | --- | --- | 75 | | id | string | The unique identifier of the TierConfigurationRequest object. | 76 | | request | object | The request body. | 77 | 78 | **Example** 79 | ```js 80 | // request body using a template id 81 | { 82 | template: { 83 | id: 'TL-000-000-000' 84 | } 85 | } 86 | ``` 87 | -------------------------------------------------------------------------------- /mddocs/039_Class_TierConfigResource.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## TierConfigResource ⇐ GenericResource 4 | The *TierConfigRequestResource* class provides methods to access the *TierConfig* 5 | endpoint of the Cloud Blue Connect API. 6 | 7 | **Kind**: global class 8 | **Extends**: GenericResource 9 | **Category**: Resources 10 | 11 | 12 | ### new TierConfigResource(client) 13 | Creates a new instance of the *TierConfigResource* class. 14 | 15 | **Returns**: [TierConfigResource](#TierConfigResource) - An instance of the *TierConfigResource* class. 16 | 17 | | Param | Type | Description | 18 | | --- | --- | --- | 19 | | client | ConnectClient | An instance of the ConnectClient class. | 20 | 21 | -------------------------------------------------------------------------------- /mddocs/040_Class_UsageAggregateResource.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## UsageAggregateResource ⇐ GenericResource 4 | The *UsageFileResource* class provides methods to access the usage file 5 | endpoint of the Cloud Blue Connect API. 6 | 7 | **Kind**: global class 8 | **Extends**: GenericResource 9 | **Category**: Resources 10 | 11 | 12 | ### new UsageAggregateResource(client) 13 | Creates a new instance of the *UsageAggregateResource* class. 14 | 15 | **Returns**: [UsageAggregateResource](#UsageAggregateResource) - An instance of the *UsageAggregateResource* class. 16 | 17 | | Param | Type | Description | 18 | | --- | --- | --- | 19 | | client | ConnectClient | An instance of the ConnectClient class. | 20 | 21 | -------------------------------------------------------------------------------- /mddocs/041_Class_UsageChunkResource.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## UsageChunkResource ⇐ GenericResource 4 | The *UsageFileResource* class provides methods to access the usage file 5 | endpoint of the Cloud Blue Connect API. 6 | 7 | **Kind**: global class 8 | **Extends**: GenericResource 9 | **Category**: Resources 10 | 11 | * [UsageChunkResource](#UsageChunkResource) ⇐ GenericResource 12 | * [new UsageChunkResource(client)](#new_UsageChunkResource_new) 13 | * [.close(id, externalBillingId, externalBillingNote)](#UsageChunkResource+close) ⇒ [UsageChunkResource](#UsageChunkResource) 14 | * [.download(id)](#UsageChunkResource+download) ⇒ UsageChunckResource 15 | * [.regenerate(id)](#UsageChunkResource+regenerate) ⇒ UsageChunckResource 16 | 17 | 18 | 19 | ### new UsageChunkResource(client) 20 | Creates a new instance of the *UsageChunkResource* class. 21 | 22 | **Returns**: [UsageChunkResource](#UsageChunkResource) - An instance of the *UsageFileResource* class. 23 | 24 | | Param | Type | Description | 25 | | --- | --- | --- | 26 | | client | ConnectClient | An instance of the ConnectClient class. | 27 | 28 | 29 | 30 | ### usageChunkResource.close(id, externalBillingId, externalBillingNote) ⇒ [UsageChunkResource](#UsageChunkResource) 31 | Close *Chunk File*. 32 | 33 | **Kind**: instance method of [UsageChunkResource](#UsageChunkResource) 34 | **Returns**: [UsageChunkResource](#UsageChunkResource) - An instance of the *UsageChunkResource*. 35 | 36 | | Param | Type | Description | 37 | | --- | --- | --- | 38 | | id | string | The unique identifier of the *Usage File*. | 39 | | externalBillingId | string | Id of the billing to close chunk | 40 | | externalBillingNote | string | Note of the billing to close chunk | 41 | 42 | 43 | 44 | ### usageChunkResource.download(id) ⇒ UsageChunckResource 45 | Download *Chunk File*. 46 | 47 | **Kind**: instance method of [UsageChunkResource](#UsageChunkResource) 48 | **Returns**: UsageChunckResource - An instance of the *UsageChunkResource* 49 | 50 | | Param | Type | Description | 51 | | --- | --- | --- | 52 | | id | string | The unique identifier of the *Usage File*. | 53 | 54 | 55 | 56 | ### usageChunkResource.regenerate(id) ⇒ UsageChunckResource 57 | Regenerate *Chunk File*. 58 | 59 | **Kind**: instance method of [UsageChunkResource](#UsageChunkResource) 60 | **Returns**: UsageChunckResource - An instance of the *UsageChunkResource* 61 | 62 | | Param | Type | Description | 63 | | --- | --- | --- | 64 | | id | string | The unique identifier of the *Usage File*. | 65 | 66 | -------------------------------------------------------------------------------- /mddocs/044_Class_UsageReconciliationResource.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## UsageReconciliationResource ⇐ GenericResource 4 | The *UsageFileResource* class provides methods to access the usage file 5 | endpoint of the Cloud Blue Connect API. 6 | 7 | **Kind**: global class 8 | **Extends**: GenericResource 9 | **Category**: Resources 10 | 11 | * [UsageReconciliationResource](#UsageReconciliationResource) ⇐ GenericResource 12 | * [new UsageReconciliationResource(client)](#new_UsageReconciliationResource_new) 13 | * [.processedFile(id)](#UsageReconciliationResource+processedFile) ⇒ [UsageReconciliationResource](#UsageReconciliationResource) 14 | * [.uploadedFile(id)](#UsageReconciliationResource+uploadedFile) ⇒ [UsageReconciliationResource](#UsageReconciliationResource) 15 | 16 | 17 | 18 | ### new UsageReconciliationResource(client) 19 | Creates a new instance of the *UsageReconciliationResource* class. 20 | 21 | **Returns**: UsageRecordResource - An instance of the *UsageFileResource* class. 22 | 23 | | Param | Type | Description | 24 | | --- | --- | --- | 25 | | client | ConnectClient | An instance of the ConnectClient class. | 26 | 27 | 28 | 29 | ### usageReconciliationResource.processedFile(id) ⇒ [UsageReconciliationResource](#UsageReconciliationResource) 30 | Get processed files. 31 | 32 | **Kind**: instance method of [UsageReconciliationResource](#UsageReconciliationResource) 33 | **Returns**: [UsageReconciliationResource](#UsageReconciliationResource) - An instance of the *UsageReconciliationResource*. 34 | 35 | | Param | Type | Description | 36 | | --- | --- | --- | 37 | | id | string | The unique identifier of the *Usage File*. | 38 | 39 | 40 | 41 | ### usageReconciliationResource.uploadedFile(id) ⇒ [UsageReconciliationResource](#UsageReconciliationResource) 42 | Get uploaded files. 43 | 44 | **Kind**: instance method of [UsageReconciliationResource](#UsageReconciliationResource) 45 | **Returns**: [UsageReconciliationResource](#UsageReconciliationResource) - An instance of the *UsageReconciliationResource*. 46 | 47 | | Param | Type | Description | 48 | | --- | --- | --- | 49 | | id | string | The unique identifier of the *Usage File*. | 50 | 51 | -------------------------------------------------------------------------------- /mddocs/045_Class_UsageRecordResource.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## UsageRecordResource ⇐ GenericResource 4 | The *UsageFileResource* class provides methods to access the usage file 5 | endpoint of the Cloud Blue Connect API. 6 | 7 | **Kind**: global class 8 | **Extends**: GenericResource 9 | **Category**: Resources 10 | 11 | * [UsageRecordResource](#UsageRecordResource) ⇐ GenericResource 12 | * [new UsageRecordResource(client)](#new_UsageRecordResource_new) 13 | * [.close(id, externalBillingId, externalBillingNote)](#UsageRecordResource+close) ⇒ UsageChunkResource 14 | * [.closeRecords(id, recordId, externalBillingId, externalBillingNote)](#UsageRecordResource+closeRecords) ⇒ UsageChunkResource 15 | 16 | 17 | 18 | ### new UsageRecordResource(client) 19 | Creates a new instance of the *UsageRecordResource* class. 20 | 21 | **Returns**: [UsageRecordResource](#UsageRecordResource) - An instance of the *UsageFileResource* class. 22 | 23 | | Param | Type | Description | 24 | | --- | --- | --- | 25 | | client | ConnectClient | An instance of the ConnectClient class. | 26 | 27 | 28 | 29 | ### usageRecordResource.close(id, externalBillingId, externalBillingNote) ⇒ UsageChunkResource 30 | Close all *Record File*. 31 | 32 | **Kind**: instance method of [UsageRecordResource](#UsageRecordResource) 33 | **Returns**: UsageChunkResource - An instance of the *UsageChunkResource*. 34 | 35 | | Param | Type | Description | 36 | | --- | --- | --- | 37 | | id | string | The unique identifier of the *Usage File*. | 38 | | externalBillingId | string | Id of the billing to close record | 39 | | externalBillingNote | string | Note of the billing to close record | 40 | 41 | 42 | 43 | ### usageRecordResource.closeRecords(id, recordId, externalBillingId, externalBillingNote) ⇒ UsageChunkResource 44 | Close Records *Record File*. 45 | 46 | **Kind**: instance method of [UsageRecordResource](#UsageRecordResource) 47 | **Returns**: UsageChunkResource - An instance of the *UsageChunkResource*. 48 | 49 | | Param | Type | Description | 50 | | --- | --- | --- | 51 | | id | string | The unique identifier of the *Usage File*. | 52 | | recordId | string | Id of the record to close | 53 | | externalBillingId | string | Id of the billing to close record | 54 | | externalBillingNote | string | Note of the billing to close record | 55 | 56 | -------------------------------------------------------------------------------- /mddocs/046_Class_WebhookResource.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## WebhookResource ⇐ GenericResource 4 | The *WebhookResource* class provides methods to access the webhooks 5 | endpoint of the Cloud Blue Connect API. 6 | 7 | **Kind**: global class 8 | **Extends**: GenericResource 9 | **Category**: Resources 10 | 11 | 12 | ### new WebhookResource(client) 13 | Creates a new instance of the *WebhookResource* class. 14 | 15 | **Returns**: [WebhookResource](#WebhookResource) - An instance of the *WebhookResource* class. 16 | 17 | | Param | Type | Description | 18 | | --- | --- | --- | 19 | | client | ConnectClient | An instance of the ConnectClient class. | 20 | 21 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@cloudblueconnect/connect-javascript-sdk", 3 | "version": "25.0.0", 4 | "description": "Cloud Blue Connect Javascript SDK", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --no-cache", 8 | "test:dev": "jest --no-cache --watch", 9 | "lint": "eslint lib/**", 10 | "docs": "jsdoc -c jsdoc.config.js", 11 | "mddocs": "node mddocs.js" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/cloudblue/connect-javascript-sdk.git" 16 | }, 17 | "keywords": [ 18 | "sdk", 19 | "cloudblue", 20 | "connect" 21 | ], 22 | "author": "Ingram Micro Inc", 23 | "license": "Apache-2.0", 24 | "bugs": { 25 | "url": "https://github.com/cloudblue/connect-javascript-sdk/issues" 26 | }, 27 | "homepage": "https://github.com/cloudblue/connect-javascript-sdk#readme", 28 | "dependencies": { 29 | "node-fetch": "^3.1.1", 30 | "ramda": "^0.26.1" 31 | }, 32 | "devDependencies": { 33 | "@cloudblueconnect/connect-jsdoc-theme": "^19.2.1", 34 | "eslint": "^6.7.1", 35 | "eslint-config-airbnb-base": "^14.0.0", 36 | "eslint-plugin-import": "^2.18.2", 37 | "eslint-plugin-jsdoc": "^21.0.0", 38 | "jest": "^25.1.0", 39 | "jest-fetch-mock": "^3.0.1", 40 | "jsdoc": "^3.6.3", 41 | "jsdoc-to-markdown": "^5.0.3" 42 | }, 43 | "publishConfig": { 44 | "access": "public" 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /sonar-project.properties: -------------------------------------------------------------------------------- 1 | sonar.projectKey=cloudblue_connect-javascript-sdk 2 | sonar.organization=cloudbluesonarcube 3 | sonar.javascript.lcov.reportPaths=coverage/lcov.info 4 | sonar.exclusions=tests/**, docs/**, mddocs/**, mddocs.*, examples/** 5 | -------------------------------------------------------------------------------- /tests/helpers/setup.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | require('jest-fetch-mock').enableMocks(); -------------------------------------------------------------------------------- /tests/specs/connect/api/accounts.spec.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | 7 | 8 | const AccountResource = require('../../../../lib/connect/api/accounts'); 9 | const { ConnectClient } = require('../../../../index'); 10 | 11 | describe('AccountResource', () => { 12 | let client; 13 | 14 | const contentTypeJson = { 'content-type': 'application/json' }; 15 | 16 | beforeAll(() => { 17 | client = new ConnectClient('https://localhost', '1234567890'); 18 | }); 19 | beforeEach(() => { 20 | fetch.resetMocks(); 21 | }); 22 | it('returns a list of users that belongs to an account', async () => { 23 | const acc = new AccountResource(client); 24 | const users = [ 25 | { 26 | id: 'UR-001', 27 | name: 'Test user', 28 | email: 'test@example.com' 29 | } 30 | ] 31 | fetch.mockResponseOnce(JSON.stringify(users), { status: 200, headers: contentTypeJson }); 32 | await expect(acc.users('VA-001').search()).resolves.toEqual(users); 33 | expect(fetch).toBeCalledWith('https://localhost/accounts/VA-001/users', expect.anything()); 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /tests/specs/connect/api/assets.spec.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | 7 | const { converge, concat, compose, toUpper, head, tail } = require('ramda'); 8 | const AssetResource = require('../../../../lib/connect/api/assets'); 9 | const { ConnectClient } = require('../../../../index'); 10 | 11 | const capitalize = converge(concat, [compose(toUpper, head), tail]); 12 | 13 | describe('AssetResource', () => { 14 | let client; 15 | 16 | const contentTypeJson = { 'content-type': 'application/json' }; 17 | 18 | beforeAll(() => { 19 | client = new ConnectClient('https://localhost', '1234567890'); 20 | }); 21 | beforeEach(() => { 22 | fetch.resetMocks(); 23 | }); 24 | 25 | it('returns a list of asset usage agregates for an asset', async () => { 26 | const asset = new AssetResource(client); 27 | const test = [{ id: 'AS-000', name: 'test product' }]; 28 | fetch.mockResponseOnce(JSON.stringify(test), { status: 200, headers: contentTypeJson }); 29 | await expect(asset.usageAgregates('AS-000').search()).resolves.toEqual(test); 30 | expect(fetch).toBeCalledWith('https://localhost/assets/AS-000/usage/agregates', expect.anything()); }); 31 | }); 32 | -------------------------------------------------------------------------------- /tests/specs/connect/api/billingRequests.spec.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | 7 | const BillingRequestResource = require('../../../../lib/connect/api/billingRequests'); 8 | const { ConnectClient } = require('../../../../index'); 9 | 10 | 11 | describe('BillingRequestResource', () => { 12 | let client; 13 | 14 | const contentTypeJson = { 'content-type': 'application/json' }; 15 | 16 | beforeAll(() => { 17 | client = new ConnectClient('https://localhost', '1234567890'); 18 | }); 19 | beforeEach(() => { 20 | fetch.resetMocks(); 21 | }); 22 | 23 | it('updates the billing request attributes', async () => { 24 | const req = new BillingRequestResource(client); 25 | const response = { 26 | attributes: { 27 | vendor: { 28 | external_id: '1233-321', 29 | }, 30 | provider: { 31 | external_id: '123-32-321', 32 | }, 33 | }, 34 | }; 35 | 36 | fetch.mockResponseOnce(JSON.stringify(response), { status: 200, headers: contentTypeJson }); 37 | const reqBody = { 38 | attributes: { 39 | vendor: { 40 | external_id: '1233-321', 41 | } 42 | } 43 | }; 44 | await expect(req.updateAttributes('BRP-0000', reqBody)).resolves.toEqual(response); 45 | expect(fetch).toBeCalledWith('https://localhost/subscriptions/requests/BRP-0000/attributes', { 46 | method: 'PUT', 47 | headers: expect.anything(), 48 | body: JSON.stringify(reqBody), 49 | }); 50 | }); 51 | }); -------------------------------------------------------------------------------- /tests/specs/connect/api/cases.spec.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | 7 | const { converge, concat, compose, toUpper, head, tail } = require('ramda'); 8 | const CaseResource = require('../../../../lib/connect/api/cases'); 9 | const { ConnectClient } = require('../../../../index'); 10 | 11 | const capitalize = converge(concat, [compose(toUpper, head), tail]); 12 | 13 | describe('CaseResource', () => { 14 | let client; 15 | 16 | const contentTypeJson = { 'content-type': 'application/json' }; 17 | 18 | beforeAll(() => { 19 | client = new ConnectClient('https://localhost', '1234567890'); 20 | }); 21 | beforeEach(() => { 22 | fetch.resetMocks(); 23 | }); 24 | 25 | it('returns the attachment of the helpdesk case', async () => { 26 | const cases = new CaseResource(client); 27 | const attachment = [{ id: 'CA-000-000-000', name: 'test helpdesk case' }]; 28 | fetch.mockResponseOnce(JSON.stringify(attachment), { status: 200, headers: contentTypeJson }); 29 | await expect(cases.attachments('CA-000-000-000').search()).resolves.toEqual(attachment); 30 | expect(fetch).toBeCalledWith('https://localhost/helpdesk/cases/CA-000-000-000/attachments', expect.anything()); 31 | }); 32 | 33 | it('returns the settings of the helpdesk case', async () => { 34 | const cases = new CaseResource(client); 35 | const settings = [{ id: 'CA-000-000-000', name: 'test helpdesk case' }]; 36 | fetch.mockResponseOnce(JSON.stringify(settings), { status: 200, headers: contentTypeJson }); 37 | await expect(cases.settings('CA-000-000-000').search()).resolves.toEqual(settings); 38 | expect(fetch).toBeCalledWith('https://localhost/helpdesk/cases/CA-000-000-000/settings', expect.anything()); 39 | }); 40 | 41 | it.each([ 42 | ['pend'], 43 | ['inquire'], 44 | ['resolve'], 45 | ])('invoke the %s a action on a case request', async (action) => { 46 | const lstr = new CaseResource(client); 47 | fetch.mockResponseOnce('{}', { status: 200, headers: contentTypeJson }); 48 | const method = lstr[action].bind(lstr); 49 | await method('CA-000-000-000'); 50 | expect(fetch).toBeCalledWith(`https://localhost/helpdesk/cases/CA-000-000-000/${action}`, expect.anything()); 51 | }); 52 | 53 | it('close helpdesk case', async () => { 54 | const req = new CaseResource(client); 55 | const response = { 56 | feedback: 'Cool resolution', 57 | rating: 5, 58 | }; 59 | 60 | fetch.mockResponseOnce(JSON.stringify(response), { status: 200, headers: contentTypeJson }); 61 | const reqBody = { 62 | rating: 5, 63 | feedback: 'Cool resolution', 64 | }; 65 | await expect(req.close('CA-0000', 5, 'Cool resolution')).resolves.toEqual(response); 66 | expect(fetch).toBeCalledWith('https://localhost/helpdesk/cases/CA-0000/close', { 67 | method: 'POST', 68 | headers: expect.anything(), 69 | body: JSON.stringify(reqBody), 70 | }); 71 | }); 72 | }); 73 | -------------------------------------------------------------------------------- /tests/specs/connect/api/conversations.spec.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | 7 | 8 | const ConversationResource = require('../../../../lib/connect/api/conversations'); 9 | const { ConnectClient } = require('../../../../index'); 10 | 11 | describe('ConversationResource', () => { 12 | let client; 13 | 14 | const contentTypeJson = { 'content-type': 'application/json' }; 15 | 16 | beforeAll(() => { 17 | client = new ConnectClient('https://localhost', '1234567890'); 18 | }); 19 | beforeEach(() => { 20 | fetch.resetMocks(); 21 | }); 22 | it('returns a list of conversations attached to the business object specified by its id', async () => { 23 | const conv = new ConversationResource(client); 24 | const conversations = [ 25 | { 26 | id: 'CV-001', 27 | messages: [] 28 | } 29 | ] 30 | fetch.mockResponseOnce(JSON.stringify(conversations), { status: 200, headers: contentTypeJson }); 31 | await expect(conv.getConversationsByObjectId('PR-001')).resolves.toEqual(conversations); 32 | expect(fetch).toBeCalledWith('https://localhost/conversations?instance_id=PR-001', expect.anything()); 33 | }); 34 | 35 | it('returns a list of messages of a conversation specified by its id', async () => { 36 | const conv = new ConversationResource(client); 37 | const messages = [ 38 | { 39 | id: 'ME-000', 40 | conversation: 'CO-000', 41 | account: { 42 | id: 'VA-00-000', 43 | name: 'Vendor name' 44 | }, 45 | created: '2021-02-22T08:52:11+00:00', 46 | creator: { 47 | id: 'SU-000-000', 48 | name: 'name' 49 | }, 50 | text: 'text message', 51 | type: 'message', 52 | events: { 53 | created: { 54 | at: '2021-02-22T08:52:11+00:00', 55 | by: { 56 | id: 'SU-000-000', 57 | name: 'name' 58 | } 59 | }, 60 | updated: { 61 | at: '2021-02-22T08:52:11+00:00' 62 | } 63 | } 64 | }, 65 | ]; 66 | fetch.mockResponseOnce(JSON.stringify(messages), { status: 200, headers: contentTypeJson }); 67 | await expect(conv.messages('PR-001').search()).resolves.toEqual(messages); 68 | expect(fetch).toBeCalledWith('https://localhost/conversations/PR-001/messages', expect.anything()); 69 | }); 70 | 71 | it('append a message to a conversation', async () => { 72 | const conv = new ConversationResource(client); 73 | const obj = {id: 'ME-000', conversation: 'CO-000', text: 'hello'}; 74 | const body = JSON.stringify(obj); 75 | fetch.mockResponseOnce(body, { status: 200, headers: contentTypeJson }); 76 | await expect(conv.createMessage('CO-000', 'hello')).resolves.toEqual(obj); 77 | expect(fetch).toBeCalledWith('https://localhost/conversations/CO-000/messages', { 78 | method: 'POST', 79 | body: JSON.stringify({text: 'hello'}), 80 | headers: expect.objectContaining({'Content-Type': 'application/json'}), 81 | }); 82 | }); 83 | }); 84 | -------------------------------------------------------------------------------- /tests/specs/connect/api/errors.spec.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | 7 | const { APIError } = require('../../../../lib/connect/api/errors'); 8 | 9 | describe('APIError', () => { 10 | it('creates a new APIError', () => { 11 | const errObj = { 12 | error_code: 'code', 13 | errors: ['first', 'second'] 14 | } 15 | const apiError = new APIError(400, JSON.stringify(errObj)); 16 | expect(apiError.status).toEqual(400); 17 | expect(apiError.errorCode).toEqual(errObj.error_code); 18 | expect(apiError.json).toEqual(errObj); 19 | expect(apiError.errors).toEqual(errObj.errors); 20 | }); 21 | }); -------------------------------------------------------------------------------- /tests/specs/connect/api/listingRequests.spec.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | 7 | const ListingRequestResource = require('../../../../lib/connect/api/listingRequests'); 8 | const { ConnectClient } = require('../../../../index'); 9 | 10 | 11 | describe('ListingRequestResource', () => { 12 | let client; 13 | 14 | const contentTypeJson = { 'content-type': 'application/json' }; 15 | 16 | beforeAll(() => { 17 | client = new ConnectClient('https://localhost', '1234567890'); 18 | }); 19 | beforeEach(() => { 20 | fetch.resetMocks(); 21 | }); 22 | 23 | it.each([ 24 | ['cancel'], 25 | ['complete'], 26 | ['deploy'], 27 | ['refine'], 28 | ['submit'], 29 | ])('invoke the %s a action on a listing request', async (action) => { 30 | const lstr = new ListingRequestResource(client); 31 | fetch.mockResponseOnce('', { status: 200, headers: contentTypeJson }); 32 | const method = lstr[action].bind(lstr); 33 | await method('LSTR-000'); 34 | expect(fetch).toBeCalledWith(`https://localhost/listing-requests/LSTR-000/${action}`, expect.anything()); 35 | }); 36 | }); -------------------------------------------------------------------------------- /tests/specs/connect/api/requests.spec.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | 7 | const RequestResource = require('../../../../lib/connect/api/requests'); 8 | const { ConnectClient } = require('../../../../index'); 9 | 10 | describe('RequestResource', () => { 11 | let client; 12 | 13 | const contentTypeJson = { 'content-type': 'application/json' }; 14 | 15 | beforeAll(() => { 16 | client = new ConnectClient('https://localhost', '1234567890'); 17 | }); 18 | beforeEach(() => { 19 | fetch.resetMocks(); 20 | }); 21 | it.each([ 22 | ['inquire', { template_id: 'TL-000' }, {id: 'PR-000', type: 'purchase'}], 23 | ['approve', { template_id: 'TL-000' }, {id: 'PR-000', type: 'purchase'}], 24 | ['schedule', { data: {'planned_date': '2021-08-04T20:10:59+00:00'} }, {id: 'PR-000', type: 'purchase'}], 25 | ['revoke', { data: {'reason': 'abcd'} }, {id: 'PR-000', type: 'purchase'}] 26 | 27 | ])('performs the %s action', async (action, request, response) => { 28 | const req = new RequestResource(client); 29 | fetch.mockResponseOnce(JSON.stringify(response), { status: 200, headers: contentTypeJson }); 30 | const method = req[action].bind(req); 31 | await expect(method('PR-000', request)).resolves.toEqual(response); 32 | expect(fetch).toBeCalledWith(`https://localhost/requests/PR-000/${action}`, expect.anything()); 33 | }); 34 | it('changes the status of the request to pending', async () => { 35 | const req = new RequestResource(client); 36 | const response = {id: 'PR-000', type: 'purchase', status: 'pending'}; 37 | fetch.mockResponseOnce(JSON.stringify(response), { status: 200, headers: contentTypeJson }); 38 | await expect(req.pending('PR-000')).resolves.toEqual(response); 39 | expect(fetch).toBeCalledWith('https://localhost/requests/PR-000/pend', { 40 | method: 'POST', 41 | headers: expect.anything() 42 | }); 43 | }); 44 | it('changes the status of the request to failed', async () => { 45 | const req = new RequestResource(client); 46 | const response = {id: 'PR-000', type: 'purchase', status: 'failed'}; 47 | fetch.mockResponseOnce(JSON.stringify(response), { status: 200, headers: contentTypeJson }); 48 | await expect(req.fail('PR-000', 'test reason')).resolves.toEqual(response); 49 | expect(fetch).toBeCalledWith('https://localhost/requests/PR-000/fail', { 50 | method: 'POST', 51 | body: JSON.stringify({ 52 | reason: 'test reason', 53 | }), 54 | headers: expect.anything() 55 | }); 56 | }); 57 | 58 | it('changes the status of the request to revoked', async () => { 59 | const req = new RequestResource(client); 60 | const response = {id: 'PR-000', type: 'purchase', status: 'revoked'}; 61 | fetch.mockResponseOnce(JSON.stringify(response), { status: 200, headers: contentTypeJson }); 62 | await expect(req.confirm('PR-000')).resolves.toEqual(response); 63 | expect(fetch).toBeCalledWith('https://localhost/requests/PR-000/confirm', { 64 | method: 'POST', 65 | headers: expect.anything() 66 | }); 67 | }); 68 | }); -------------------------------------------------------------------------------- /tests/specs/connect/api/tierAccountRequests.spec.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | 7 | const TierAccountRequestResource = require('../../../../lib/connect/api/tierAccountRequests'); 8 | const { ConnectClient } = require('../../../../index'); 9 | 10 | 11 | describe('TierAccountRequestResource', () => { 12 | let client; 13 | 14 | const contentTypeJson = { 'content-type': 'application/json' }; 15 | 16 | beforeAll(() => { 17 | client = new ConnectClient('https://localhost', '1234567890'); 18 | }); 19 | beforeEach(() => { 20 | fetch.resetMocks(); 21 | }); 22 | 23 | it('changes the status of the request to accepted', async () => { 24 | const req = new TierAccountRequestResource(client); 25 | const response = { id: 'TAR-000', status: 'accepted' }; 26 | fetch.mockResponseOnce(JSON.stringify(response), { status: 200, headers: contentTypeJson }); 27 | await expect(req.accept('TAR-000')).resolves.toEqual(response); 28 | expect(fetch).toBeCalledWith('https://localhost/tier/account-requests/TAR-000/accept', { 29 | method: 'POST', 30 | headers: expect.anything(), 31 | 32 | }); 33 | }); 34 | it('changes the status of the request to ignored', async () => { 35 | const req = new TierAccountRequestResource(client); 36 | const response = { id: 'TAR-000', status: 'ignored' }; 37 | fetch.mockResponseOnce(JSON.stringify(response), { status: 200, headers: contentTypeJson }); 38 | await expect(req.ignore('TAR-000', 'ignore')).resolves.toEqual(response); 39 | expect(fetch).toBeCalledWith('https://localhost/tier/account-requests/TAR-000/ignore', { 40 | method: 'POST', 41 | headers: expect.anything(), 42 | body: JSON.stringify({ 43 | reason: 'ignore', 44 | }), 45 | }); 46 | }); 47 | }); -------------------------------------------------------------------------------- /tests/specs/connect/api/tierConfigRequests.spec.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | 7 | const TierConfigRequestResource = require('../../../../lib/connect/api/tierConfigRequests'); 8 | const { ConnectClient } = require('../../../../index'); 9 | 10 | 11 | describe('TierConfigRequestResource', () => { 12 | let client; 13 | 14 | const contentTypeJson = { 'content-type': 'application/json' }; 15 | 16 | beforeAll(() => { 17 | client = new ConnectClient('https://localhost', '1234567890'); 18 | }); 19 | beforeEach(() => { 20 | fetch.resetMocks(); 21 | }); 22 | 23 | it('changes the status of the request to pending', async () => { 24 | const req = new TierConfigRequestResource(client); 25 | fetch.mockResponseOnce({ status: 204 }); 26 | await expect(req.pending('TCR-000')).resolves.toBeUndefined(); 27 | expect(fetch).toBeCalledWith('https://localhost/tier/config-requests/TCR-000/pend', { 28 | method: 'POST', 29 | headers: expect.anything() 30 | }); 31 | }); 32 | it('changes the status of the request to inquire', async () => { 33 | const req = new TierConfigRequestResource(client); 34 | fetch.mockResponseOnce({ status: 204 }); 35 | await expect(req.inquire('TCR-000')).resolves.toBeUndefined(); 36 | expect(fetch).toBeCalledWith('https://localhost/tier/config-requests/TCR-000/inquire', { 37 | method: 'POST', 38 | headers: expect.anything() 39 | }); 40 | }); 41 | it('changes the status of the request to failed', async () => { 42 | const req = new TierConfigRequestResource(client); 43 | fetch.mockResponseOnce({ status: 204 }); 44 | await expect(req.fail('TCR-000', 'test reason')).resolves.toBeUndefined(); 45 | expect(fetch).toBeCalledWith('https://localhost/tier/config-requests/TCR-000/fail', { 46 | method: 'POST', 47 | body: JSON.stringify({ 48 | reason: 'test reason', 49 | }), 50 | headers: expect.anything() 51 | }); 52 | }); 53 | it('approves the request and returns the rendered template', async () => { 54 | const req = new TierConfigRequestResource(client); 55 | const request = { 56 | template: { 57 | id: 'TL-000' 58 | }, 59 | }; 60 | const response = { template: { id: 'TL-000', name: 'test template' } }; 61 | fetch.mockResponseOnce(JSON.stringify(response), { status: 204, headers: contentTypeJson }); 62 | await expect(req.approve('TCR-000', request)).resolves.toEqual(response); 63 | expect(fetch).toBeCalledWith('https://localhost/tier/config-requests/TCR-000/approve', { 64 | method: 'POST', 65 | body: JSON.stringify(request), 66 | headers: expect.anything() 67 | }); 68 | }); 69 | }); -------------------------------------------------------------------------------- /tests/specs/connect/api/usageAggregates.spec.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | 7 | const { converge, concat, compose, toUpper, head, tail } = require('ramda'); 8 | const UsageAggregateResource = require('../../../../lib/connect/api/usageAggregates'); 9 | const { ConnectClient } = require('../../../../index'); 10 | 11 | const capitalize = converge(concat, [compose(toUpper, head), tail]); 12 | 13 | describe('UsageAggregateResource', () => { 14 | let client; 15 | 16 | const contentTypeJson = { 'content-type': 'application/json' }; 17 | 18 | beforeAll(() => { 19 | client = new ConnectClient('https://localhost', '1234567890'); 20 | }); 21 | beforeEach(() => { 22 | fetch.resetMocks(); 23 | }); 24 | 25 | 26 | it('returns agregates resource of usage', async () => { 27 | const cases = new UsageAggregateResource(client); 28 | const attachment = [{ asset_id: 'AS-000' }]; 29 | fetch.mockResponseOnce(JSON.stringify(attachment), { status: 200, headers: contentTypeJson }); 30 | await expect(cases.search()).resolves.toEqual(attachment); 31 | expect(fetch).toBeCalledWith('https://localhost/usage/aggregates', expect.anything()); 32 | }); 33 | 34 | }); 35 | -------------------------------------------------------------------------------- /tests/specs/connect/api/usageChunks.spec.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | 7 | const { converge, concat, compose, toUpper, head, tail } = require('ramda'); 8 | const UsageChunkResource = require('../../../../lib/connect/api/usageChunks'); 9 | const { ConnectClient } = require('../../../../index'); 10 | const capitalize = converge(concat, [compose(toUpper, head), tail]); 11 | 12 | describe('UsageChunkResource', () => { 13 | let client; 14 | const contentTypeJson = { 'content-type': 'application/json' }; 15 | 16 | beforeAll(() => { 17 | client = new ConnectClient('https://localhost', '1234567890'); 18 | }); 19 | beforeEach(() => { 20 | fetch.resetMocks(); 21 | }); 22 | 23 | it('close chunk file', async () => { 24 | const req = new UsageChunkResource(client); 25 | const response = { 26 | id: 'UF-0000', 27 | }; 28 | fetch.mockResponseOnce(JSON.stringify(response), { status: 200, headers: contentTypeJson }); 29 | const reqBody = { 30 | external_billing_id: 'BI-000', 31 | external_billing_note: 'Some Note', 32 | }; 33 | await expect(req.close('UF-0000', 'BI-000', 'Some Note')).resolves.toEqual(response); 34 | expect(fetch).toBeCalledWith('https://localhost/usage/chunks/UF-0000/close', { 35 | method: 'POST', 36 | headers: expect.anything(), 37 | body: JSON.stringify(reqBody), 38 | }); 39 | }); 40 | 41 | it.each([ 42 | ['download', 'GET'], 43 | ['regenerate', 'POST'] 44 | ])('performs the %s action', async (action, act) => { 45 | const req = new UsageChunkResource(client); 46 | const response = { 47 | id: 'UF-0000', 48 | }; 49 | fetch.mockResponseOnce(JSON.stringify(response), { status: 200, headers: contentTypeJson }); 50 | const method = req[action].bind(req); 51 | await method('UF-0000'); 52 | expect(fetch).toBeCalledWith(`https://localhost/usage/chunks/UF-0000/${action}`, { 53 | method: act, 54 | headers: expect.anything(), 55 | }); 56 | }); 57 | }); 58 | -------------------------------------------------------------------------------- /tests/specs/connect/api/usageFiles.spec.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | 7 | const { converge, concat, compose, toUpper, head, tail } = require('ramda'); 8 | const UsageFileResource = require('../../../../lib/connect/api/usageFiles'); 9 | const { ConnectClient } = require('../../../../index'); 10 | 11 | const capitalize = converge(concat, [compose(toUpper, head), tail]); 12 | 13 | describe('UsageFileResource', () => { 14 | let client; 15 | 16 | const contentTypeJson = { 'content-type': 'application/json' }; 17 | 18 | beforeAll(() => { 19 | client = new ConnectClient('https://localhost', '1234567890'); 20 | }); 21 | beforeEach(() => { 22 | fetch.resetMocks(); 23 | }); 24 | 25 | it('returns the category of the usage file', async () => { 26 | const usageFile = new UsageFileResource(client); 27 | const attachment = [{ id: 'UF-000', name: 'test usage file category' }]; 28 | fetch.mockResponseOnce(JSON.stringify(attachment), { status: 200, headers: contentTypeJson }); 29 | await expect(usageFile.categories('UF-000').search()).resolves.toEqual(attachment); 30 | expect(fetch).toBeCalledWith('https://localhost/usage/files/UF-000/categories', expect.anything()); 31 | }); 32 | 33 | it('accept usage file', async () => { 34 | const req = new UsageFileResource(client); 35 | const response = { 36 | id: 'UF-0000', 37 | status: 'accepted', 38 | }; 39 | fetch.mockResponseOnce(JSON.stringify(response), { status: 200, headers: contentTypeJson }); 40 | const reqBody = { 41 | acceptance_note: 'accepted', 42 | }; 43 | await expect(req.accept('UF-0000', 'accepted')).resolves.toEqual(response); 44 | expect(fetch).toBeCalledWith('https://localhost/usage/files/UF-0000/accept', { 45 | method: 'POST', 46 | headers: expect.anything(), 47 | body: JSON.stringify(reqBody), 48 | }); 49 | }); 50 | 51 | it.each([ 52 | ['approveAll', 'approve-all', 'PUT'], 53 | ['close', 'close', 'POST'], 54 | ['delete', 'delete', 'POST'], 55 | ['reprocess', 'reprocess', 'POST'], 56 | ['submit', 'submit', 'POST'], 57 | ])('performs the %s action', async (action, request, act) => { 58 | const req = new UsageFileResource(client); 59 | const response = { 60 | id: 'UF-0000', 61 | }; 62 | fetch.mockResponseOnce(JSON.stringify(response), { status: 200, headers: contentTypeJson }); 63 | const method = req[action].bind(req); 64 | await method('UF-0000'); 65 | expect(fetch).toBeCalledWith(`https://localhost/usage/files/UF-0000/${request}`, { 66 | method: act, 67 | headers: expect.anything(), 68 | }); 69 | }); 70 | 71 | it.each([ 72 | ['reconciliation', 'reconFile', 'recon_file'], 73 | ['reject', 'rejectionNote', 'rejection_note'], 74 | ['upload', 'usageFile', 'usage_file'], 75 | ])('performs the %s action', async (action, fileFunc, fileField) => { 76 | const req = new UsageFileResource(client); 77 | const reqBody = ({[fileField]: fileFunc}); 78 | const response = { 79 | id: 'UF-0000', 80 | }; 81 | fetch.mockResponseOnce(JSON.stringify(response), { status: 200, headers: contentTypeJson }); 82 | const method = req[action].bind(req); 83 | await method('UF-0000', fileFunc); 84 | expect(fetch).toBeCalledWith(`https://localhost/usage/files/UF-0000/${action}`, { 85 | method: 'POST', 86 | body: JSON.stringify(reqBody), 87 | headers: expect.anything(), 88 | }); 89 | }); 90 | }); 91 | -------------------------------------------------------------------------------- /tests/specs/connect/api/usageReconciliations.spec.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | 7 | const { converge, concat, compose, toUpper, head, tail } = require('ramda'); 8 | const UsageReconciliationResource = require('../../../../lib/connect/api/usageReconciliations'); 9 | const { ConnectClient } = require('../../../../index'); 10 | const capitalize = converge(concat, [compose(toUpper, head), tail]); 11 | 12 | describe('UsageChunkResource', () => { 13 | let client; 14 | const contentTypeJson = { 'content-type': 'application/json' }; 15 | 16 | beforeAll(() => { 17 | client = new ConnectClient('https://localhost', '1234567890'); 18 | }); 19 | beforeEach(() => { 20 | fetch.resetMocks(); 21 | }); 22 | 23 | it.each([ 24 | ['processedFile'], 25 | ['uploadedFile'] 26 | ])('performs the %s action', async (action) => { 27 | const req = new UsageReconciliationResource(client); 28 | const response = { 29 | id: 'UF-0000', 30 | }; 31 | fetch.mockResponseOnce(JSON.stringify(response), { status: 200, headers: contentTypeJson }); 32 | const method = req[action].bind(req); 33 | await method('UF-0000'); 34 | expect(fetch).toBeCalledWith(`https://localhost/usage/reconciliations/UF-0000/${action}`, { 35 | method: 'GET', 36 | headers: expect.anything(), 37 | }); 38 | }); 39 | }); 40 | -------------------------------------------------------------------------------- /tests/specs/connect/api/usageRecords.spec.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | 7 | const { converge, concat, compose, toUpper, head, tail } = require('ramda'); 8 | const UsageRecordResource = require('../../../../lib/connect/api/usageRecords'); 9 | const { ConnectClient } = require('../../../../index'); 10 | const capitalize = converge(concat, [compose(toUpper, head), tail]); 11 | 12 | describe('UsageRecordResource', () => { 13 | let client; 14 | const contentTypeJson = { 'content-type': 'application/json' }; 15 | 16 | beforeAll(() => { 17 | client = new ConnectClient('https://localhost', '1234567890'); 18 | }); 19 | beforeEach(() => { 20 | fetch.resetMocks(); 21 | }); 22 | 23 | it('close all records file', async () => { 24 | const req = new UsageRecordResource(client); 25 | const response = { 26 | id: 'UF-0000', 27 | }; 28 | fetch.mockResponseOnce(JSON.stringify(response), { status: 200, headers: contentTypeJson }); 29 | const reqBody = { 30 | external_billing_id: 'BI-000', 31 | external_billing_note: 'Some Note', 32 | }; 33 | await expect(req.close('UF-0000', 'BI-000', 'Some Note')).resolves.toEqual(response); 34 | expect(fetch).toBeCalledWith('https://localhost/usage/records/UF-0000/close', { 35 | method: 'POST', 36 | headers: expect.anything(), 37 | body: JSON.stringify(reqBody), 38 | }); 39 | }); 40 | it('close all record file', async () => { 41 | const req = new UsageRecordResource(client); 42 | const response = { 43 | id: 'UF-0000', 44 | }; 45 | fetch.mockResponseOnce(JSON.stringify(response), { status: 200, headers: contentTypeJson }); 46 | const reqBody = { 47 | id: 'RI-000', 48 | external_billing_id: 'BI-000', 49 | external_billing_note: 'Some Note', 50 | }; 51 | await expect(req.closeRecords('UF-0000', 'RI-000', 'BI-000', 'Some Note')).resolves.toEqual(response); 52 | expect(fetch).toBeCalledWith('https://localhost/usage/records/UF-0000/close-records', { 53 | method: 'POST', 54 | headers: expect.anything(), 55 | body: JSON.stringify(reqBody), 56 | }); 57 | }); 58 | }); 59 | -------------------------------------------------------------------------------- /tests/specs/connect/client.spec.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of the Ingram Micro Cloud Blue Connect SDK. 3 | * 4 | * @copyright (c) 2020. Ingram Micro. All Rights Reserved. 5 | */ 6 | 7 | 8 | const { ConnectClient } = require('../../../index'); 9 | const api = require('../../../lib/connect/api'); 10 | describe('ConnectClient', () => { 11 | it.each([ 12 | ['accounts', api.AccountResource], 13 | ['assets', api.AssetResource], 14 | ['billingRequests', api.BillingRequestResource], 15 | ['conversations', api.ConversationResource], 16 | ['products', api.ProductResource], 17 | ['requests', api.RequestResource], 18 | ['hubs', api.HubResource], 19 | ['recurringAssets', api.RecurringAssetResource], 20 | ['tierAccounts', api.TierAccountResource], 21 | ['tierAccountRequests', api.TierAccountRequestResource], 22 | ['tierConfigs', api.TierConfigResource], 23 | ['tierConfigRequests', api.TierConfigRequestResource], 24 | ['webhooks', api.WebhookResource], 25 | ['listingRequests', api.ListingRequestResource], 26 | ['cases', api.CaseResource], 27 | ['usageFiles', api.UsageFileResource], 28 | ['usageReconciliations', api.UsageReconciliationResource], 29 | ['usageRecords', api.UsageRecordResource], 30 | ['usageChunks', api.UsageChunkResource], 31 | ['usageAggregates', api.UsageAggregateResource] 32 | ])('%s returns an instance of the corresponding endpoint', (property, type) => { 33 | const client = new ConnectClient('http://server', '1234567890'); 34 | expect(client[property]).toBeInstanceOf(type); 35 | }); 36 | it('append before hook function to the adapter beforeRequest hooks', () => { 37 | const client = new ConnectClient('http://server', '1234567890'); 38 | const myHook = (url, options) => ({url, options}); 39 | client.addBeforeRequestHook(myHook); 40 | expect(client._adapter.beforeRequest).toContain(myHook); 41 | }); 42 | it('append after hook function to the adapter afterResponse hooks', () => { 43 | const client = new ConnectClient('http://server', '1234567890'); 44 | const myHook = (response) => response; 45 | client.addAfterResponseHook(myHook); 46 | expect(client._adapter.afterResponse).toContain(myHook); 47 | }); 48 | }); -------------------------------------------------------------------------------- /tests/specs/connect/data/createParameterRequest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "magic_param_c", 3 | "title": "Title of the Magic Parameter C", 4 | "description": "This is a backup email for emergency", 5 | "type": "checkbox", 6 | "scope": "asset", 7 | "phase": "ordering", 8 | "constraints": { 9 | "required": false, 10 | "hidden": false, 11 | "unique": false, 12 | "choices": [ 13 | { 14 | "label": "val1", 15 | "value": "test1", 16 | "default": true 17 | }, 18 | { 19 | "label": "val2", 20 | "value": "test2" 21 | }, 22 | { 23 | "label": "val3", 24 | "value": "test3" 25 | } 26 | ] 27 | } 28 | } -------------------------------------------------------------------------------- /tests/specs/connect/ops/directory.spec.js: -------------------------------------------------------------------------------- 1 | const { ConnectClient, Directory } = require('../../../../index'); 2 | 3 | describe('Directory', () => { 4 | let client; 5 | 6 | beforeAll(() => { 7 | client = new ConnectClient('https://localhost', '1234567890'); 8 | }); 9 | beforeEach(() => { 10 | jest.clearAllMocks(); 11 | }); 12 | it('searchTierAccounts invokes search on tier accounts endpoint', async () => { 13 | const mockedFn = client.tierAccounts.search = jest.fn(); 14 | const dir = new Directory(client); 15 | await dir.searchTierAccounts({ field: 'value'}); 16 | expect(mockedFn).toHaveBeenCalledWith({field: 'value'}); 17 | }); 18 | it('searchAssets invokes search on assets endpoint', async () => { 19 | const mockedFn = client.assets.search = jest.fn(); 20 | const dir = new Directory(client); 21 | await dir.searchAssets({ field: 'value'}); 22 | expect(mockedFn).toHaveBeenCalledWith({ field: 'value'}); 23 | }); 24 | it('searchTierConfigurations invokes search on tierConfigs endpoint', async () => { 25 | const mockedFn = client.tierConfigs.search = jest.fn(); 26 | const dir = new Directory(client); 27 | await dir.searchTierConfigurations({field: 'value'}); 28 | expect(mockedFn).toHaveBeenCalledWith({field: 'value'}); 29 | }); 30 | it('getTierAccount invokes get on tier accounts endpoint', async () => { 31 | const mockedFn = client.tierAccounts.get = jest.fn(); 32 | const dir = new Directory(client); 33 | await dir.getTierAccount('TA-000'); 34 | expect(mockedFn).toHaveBeenCalledWith('TA-000'); 35 | }); 36 | it('getAssetsByProductIdExternalId invokes search on tier accounts endpoint', async () => { 37 | const mockedFn = client.assets.search = jest.fn(); 38 | const dir = new Directory(client); 39 | await dir.getAssetsByProductIdExternalId('PRD-000', 'ext_id'); 40 | expect(mockedFn).toHaveBeenCalledWith({ 41 | external_id: 'ext_id', 42 | 'product.id': 'PRD-000', 43 | }); 44 | }); 45 | it('createTierAccountRequest invokes create on tier account requests endpoint', async () => { 46 | const mockedFn = client.tierAccountRequests.create = jest.fn(); 47 | const dir = new Directory(client); 48 | await dir.createTierAccountRequest({}); 49 | expect(mockedFn).toHaveBeenCalledWith({}); 50 | }); 51 | it('searchTierAccountRequests invokes search on tier account requests endpoint', async () => { 52 | const mockedFn = client.tierAccountRequests.search = jest.fn(); 53 | const dir = new Directory(client); 54 | await dir.searchTierAccountRequests({ field: 'value'}); 55 | expect(mockedFn).toHaveBeenCalledWith({ field: 'value'}); 56 | }); 57 | it('getTierAccountRequest invokes get on tier account requests endpoint', async () => { 58 | const mockedFn = client.tierAccountRequests.get = jest.fn(); 59 | const dir = new Directory(client); 60 | await dir.getTierAccountRequest('TAR-0000'); 61 | expect(mockedFn).toHaveBeenCalledWith('TAR-0000'); 62 | }); 63 | it('acceptTierAccountRequest invokes accept on tier account requests endpoint', async () => { 64 | const mockedFn = client.tierAccountRequests.accept = jest.fn(); 65 | const dir = new Directory(client); 66 | await dir.acceptTierAccountRequest('TAR-0000'); 67 | expect(mockedFn).toHaveBeenCalledWith('TAR-0000'); 68 | }); 69 | it('ignoreTierAccountRequest invokes get on tier account requests endpoint', async () => { 70 | const mockedFn = client.tierAccountRequests.ignore = jest.fn(); 71 | const dir = new Directory(client); 72 | await dir.ignoreTierAccountRequest('TAR-0000', 'reason'); 73 | expect(mockedFn).toHaveBeenCalledWith('TAR-0000', 'reason'); 74 | }); 75 | it('getTierAccountVersion invokes get on tier account requests endpoint', async () => { 76 | const accVersionResource = client.tierAccounts.versions('TAR-0000'); 77 | const mockedFn = accVersionResource.get = jest.fn(); 78 | const dir = new Directory(client); 79 | await dir.getTierAccountVersion('TAR-0000', 1); 80 | expect(mockedFn).toHaveBeenCalledWith(1); 81 | }); 82 | }); -------------------------------------------------------------------------------- /tests/specs/connect/ops/inventory.spec.js: -------------------------------------------------------------------------------- 1 | const { ConnectClient, Inventory } = require('../../../../index'); 2 | 3 | describe('Inventory', () => { 4 | let client; 5 | 6 | beforeAll(() => { 7 | client = new ConnectClient('https://localhost', '1234567890'); 8 | }); 9 | beforeEach(() => { 10 | jest.clearAllMocks(); 11 | }); 12 | it('getParametersByProduct invokes get on product parameters endpoint', async () => { 13 | const mockedFn = client.products.parameters('PRD-000').search = jest.fn(); 14 | const inv = new Inventory(client); 15 | await inv.getParametersByProduct('PRD-000'); 16 | expect(mockedFn).toHaveBeenCalled(); 17 | }); 18 | it('getAssetParametersForFulfillmentByProduct search parameters with scope=asset and phase=fulfillment', async () => { 19 | const mockedFn = client.products.parameters('PRD-000').search = jest.fn(); 20 | const inv = new Inventory(client); 21 | await inv.getAssetParametersForFulfillmentByProduct('PRD-000'); 22 | expect(mockedFn).toHaveBeenCalledWith({ 23 | scope: 'asset', 24 | phase: 'fulfillment', 25 | }); 26 | }); 27 | it('getParametersByProduct invokes search on the product parameters endpoint', async () => { 28 | const mockedFn = client.products.parameters('PRD-000').search = jest.fn(); 29 | const inv = new Inventory(client); 30 | await inv.getParametersByProduct('PRD-000'); 31 | expect(mockedFn).toHaveBeenCalled(); 32 | }); 33 | it('getProductTemplates invokes getTemplates on products endpoint', async () => { 34 | const mockedFn = client.products.getTemplates = jest.fn(); 35 | const inv = new Inventory(client); 36 | await inv.getProductTemplates('PRD-000'); 37 | expect(mockedFn).toHaveBeenCalledWith('PRD-000'); 38 | }); 39 | it('getProductActionLink invokes link on product actions endpoint', async () => { 40 | const prodActionResource = client.products.actions('PRD-000'); 41 | const mockedFn = prodActionResource.link = jest.fn(); 42 | const inv = new Inventory(client); 43 | await inv.getProductActionLink('PRD-000', 'sso_action', 'AS-000'); 44 | expect(mockedFn).toHaveBeenCalledWith('sso_action', 'AS-000'); 45 | }); 46 | it('getProductAssetTemplates invokes this.getProductTemplates and filter by scope=asset', async () => { 47 | const inv = new Inventory(client); 48 | inv.getProductTemplates = jest.fn(); 49 | inv.getProductTemplates.mockImplementation(id => [ 50 | { 51 | id: 'TL-000', 52 | scope: 'asset', 53 | }, 54 | { 55 | id: 'TL-001', 56 | scope: 'tier1', 57 | }, 58 | { 59 | id: 'TL-002', 60 | scope: 'tier2', 61 | } 62 | ]); 63 | await expect(inv.getProductAssetTemplates('PRD-000')).resolves.toEqual([ 64 | { 65 | id: 'TL-000', 66 | scope: 'asset', 67 | } 68 | ]); 69 | expect(inv.getProductTemplates).toHaveBeenCalledWith('PRD-000'); 70 | }); 71 | it('searchProductParameters invokes search on the product parameters endpoint', async () => { 72 | const mockedFn = client.products.parameters('PRD-000').search = jest.fn(); 73 | const inv = new Inventory(client); 74 | const query = { 75 | scope: 'asset', 76 | phase: 'ordering', 77 | }; 78 | await inv.searchProductParameters('PRD-000', query) 79 | expect(mockedFn).toHaveBeenCalledWith(query); 80 | }); 81 | }); -------------------------------------------------------------------------------- /tests/specs/connect/ops/listings.spec.js: -------------------------------------------------------------------------------- 1 | const { ConnectClient, Listings } = require('../../../../index'); 2 | 3 | describe('Listings', () => { 4 | let client; 5 | 6 | beforeAll(() => { 7 | client = new ConnectClient('https://localhost', '1234567890'); 8 | }); 9 | beforeEach(() => { 10 | jest.clearAllMocks(); 11 | }); 12 | it('searchListingRequests invokes search on listing requests endpoint', async () => { 13 | const mockedFn = client.listingRequests.search = jest.fn(); 14 | const sub = new Listings(client); 15 | await sub.searchListingRequests({field: 'value'}); 16 | expect(mockedFn).toHaveBeenCalledWith({field: 'value'}); 17 | }); 18 | it('createListingRequest invokes create on listing requests endpoint', async () => { 19 | const mockedFn = client.listingRequests.create = jest.fn(); 20 | const sub = new Listings(client); 21 | await sub.createListingRequest({}); 22 | expect(mockedFn).toHaveBeenCalledWith({}); 23 | }); 24 | it.each([ 25 | ['cancel'], 26 | ['complete'], 27 | ['deploy'], 28 | ['refine'], 29 | ['submit'], 30 | ['get'], 31 | ])('%sListingRequest invoke the corresponding a action on a listing request', async (action) => { 32 | const mockedFn = client.listingRequests[action] = jest.fn(); 33 | const listings = new Listings(client); 34 | const method = listings[`${action}ListingRequest`].bind(listings); 35 | await method('LSTR-000'); 36 | expect(mockedFn).toHaveBeenCalledWith('LSTR-000'); 37 | }); 38 | }); -------------------------------------------------------------------------------- /tests/specs/connect/ops/subscriptions.spec.js: -------------------------------------------------------------------------------- 1 | const { ConnectClient, Subscriptions } = require('../../../../index'); 2 | 3 | describe('Subscriptions', () => { 4 | let client; 5 | 6 | beforeAll(() => { 7 | client = new ConnectClient('https://localhost', '1234567890'); 8 | }); 9 | beforeEach(() => { 10 | jest.clearAllMocks(); 11 | }); 12 | it('searchBillingRequests invokes search on billing requests endpoint', async () => { 13 | const mockedFn = client.billingRequests.search = jest.fn(); 14 | const sub = new Subscriptions(client); 15 | await sub.searchBillingRequests({ field: 'value'}); 16 | expect(mockedFn).toHaveBeenCalledWith({field: 'value'}); 17 | }); 18 | it('searchRecurringAssets invokes search on recurring assets endpoint', async () => { 19 | const mockedFn = client.recurringAssets.search = jest.fn(); 20 | const sub = new Subscriptions(client); 21 | await sub.searchRecurringAssets({ field: 'value'}); 22 | expect(mockedFn).toHaveBeenCalledWith({field: 'value'}); 23 | }); 24 | it('getBillingRequest invokes get on billing requests endpoint', async () => { 25 | const mockedFn = client.billingRequests.get = jest.fn(); 26 | const sub = new Subscriptions(client); 27 | await sub.getBillingRequest('BRP-0000'); 28 | expect(mockedFn).toHaveBeenCalledWith('BRP-0000'); 29 | }); 30 | it('getRecurringAsset invokes get on recurring assets endpoint', async () => { 31 | const mockedFn = client.recurringAssets.get = jest.fn(); 32 | const sub = new Subscriptions(client); 33 | await sub.getRecurringAsset('AS-0000'); 34 | expect(mockedFn).toHaveBeenCalledWith('AS-0000'); 35 | }); 36 | it('createBillingRequest invokes create on billing requests endpoint', async () => { 37 | const mockedFn = client.billingRequests.create = jest.fn(); 38 | const sub = new Subscriptions(client); 39 | await sub.createBillingRequest({}); 40 | expect(mockedFn).toHaveBeenCalledWith({}); 41 | }); 42 | 43 | it('updateBillingRequestAttributes invokes updateAttributes on billing requests endpoint', async () => { 44 | const mockedFn = client.billingRequests.updateAttributes = jest.fn(); 45 | const reqBody = { 46 | attributes: { 47 | vendor: { 48 | external_id: '1233-321', 49 | } 50 | } 51 | }; 52 | const sub = new Subscriptions(client); 53 | await sub.updateBillingRequestAttributes('BRP-0000', reqBody); 54 | expect(mockedFn).toHaveBeenCalledWith('BRP-0000', reqBody); 55 | }); 56 | }); --------------------------------------------------------------------------------