Skip to content

Commit

Permalink
Merge pull request #6 from cloudblue/sprint/s158
Browse files Browse the repository at this point in the history
Sprint/s158
  • Loading branch information
marcserrat committed Dec 16, 2019
2 parents f76cdf9 + bf77fef commit 0ed95b6
Show file tree
Hide file tree
Showing 33 changed files with 2,924 additions and 72 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ node_modules
.env
.nyc_output
coverage
docs/build
docs/build
.devcontainer
.vscode
5 changes: 5 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
docs
test
coverage
.nyc_output
yarn.lock
3 changes: 2 additions & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Sphinx==2.2.1
Sphinx==1.8.5
sphinx-js==2.8
sphinx_rtd_theme==0.4.3
76 changes: 76 additions & 0 deletions lib/connect/api/conversations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* This file is part of the Ingram Micro Cloud Blue Connect SDK.
*
* @copyright (c) 2019. Ingram Micro. All Rights Reserved.
*/

const BaseService = require('./base');

/**
* The ConversationService class provides methods to access the conversations
* endpoint of the Cloud Blue Connect API.
*/
class ConversationService extends BaseService {
/**
* Retrieves the id of the conversation of request.
*
* @param {string} id The unique request identifier for which retrieve the conversationId.
*
* @returns {string} Conversation ID.
*/

async getConversationIdByRequest(id) {
const url = this.addParams('/conversations', { instance_id: id });
const response = await this.fetch(url);
this.checkResponse(response);
const conv = await response.json();
if (conv.length === 1) {
return conv[0].id;
}
return null;
}

/**
* Publish a message in a convesation of the id request.
*
* @param {string} id The unique request identifier for which publish.
* @param {string} msg The message to publish.
*
* @returns {string} An array with the id oof the message.
*/
async createMessage(id, msg) {
const messageId = await this.getConversationIdByRequest(id);
const url = `/conversations/${messageId}/messages`;
const options = {
method: 'POST',
body: {
text: msg,
},
};
const response = await this.fetch(url, options);
await this.checkResponse(response);
return response.json();
}

/**
* Get messages of the id request.
*
* @param {string} id The unique request identifier for which publish.
*
* @returns {object} An object with the messages.
*/
async getMessages(id) {
const conversationId = await this.getConversationIdByRequest(id);
const url = `/conversations/${conversationId}`;
const options = {
method: 'GET',
};
const response = await this.fetch(url, options);
await this.checkResponse(response);
return response.json();
}


}

module.exports = ConversationService;
2 changes: 1 addition & 1 deletion lib/connect/api/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

/**
* HttpError wraps any http response whose status is != 2xx.
* HttpError wraps any http response whose status is != 2xx.
*/
class HttpError extends Error {
/**
Expand Down
26 changes: 26 additions & 0 deletions lib/connect/api/hubs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* This file is part of the Ingram Micro Cloud Blue Connect SDK.
*
* @copyright (c) 2019. Ingram Micro. All Rights Reserved.
*/

const BaseService = require('./base');

/**
* The AccountService class provides methods to access the accounts
* endpoint of the Cloud Blue Connect API.
*/
class HubService extends BaseService {
/**
* Get a list of tier accounts.
*
* @return {Array} Returns an Array of the Hub object.
*/
async list() {
const response = await this.fetch('/hubs');
await this.checkResponse(response);
return response.json();
}
}

module.exports = HubService;
12 changes: 11 additions & 1 deletion lib/connect/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,15 @@
const RequestService = require('./requests');
const AccountService = require('./accounts');
const ProductService = require('./products');
const ConversationService = require('./conversations');
const HubService = require('./hubs');
const TierAccountService = require('./tierAccounts');

module.exports = { AccountService, ProductService, RequestService };
module.exports = {
AccountService,
ProductService,
RequestService,
ConversationService,
HubService,
TierAccountService,
};
19 changes: 15 additions & 4 deletions lib/connect/api/products.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class ProductService extends BaseService {
}

/**
* Retrieves the list of parameters of scope asset and phase fulfillment configured for the product.
* Retrieves the list of parameters of scope asset and phase fulfillment configured for
* the product.
*
* @param {string} id The unique product identifier for which retrieve the parameters.
*
Expand All @@ -51,9 +52,7 @@ class ProductService extends BaseService {

async getAssetParametersForFulfillmentByProduct(id) {
const params = await this.getParametersByProduct(id);
return _.filter(params, param => {
return param.scope === 'asset' && param.phase === 'fulfillment';
});
return _.filter(params, (param) => param.scope === 'asset' && param.phase === 'fulfillment');
}

/**
Expand All @@ -68,6 +67,18 @@ class ProductService extends BaseService {
await this.checkResponse(response);
return response.json();
}

/**
* Returns the list of templates configured for a product with scope "asset".
*
* @param {string} id The unique identifier of the product.
*
* @return {Array} An array of Template objects.
*/
async getProductAssetTemplates(id) {
const templates = await this.getProductTemplates(id);
return _.filter(templates, (template) => template.scope === 'asset');
}
}


Expand Down
148 changes: 132 additions & 16 deletions lib/connect/api/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,77 @@

const BaseService = require('./base');

const { addFilterParam } = require('./utils');

/**
* The RequestService class provides methods to access the products
* endpoint of the Cloud Blue Connect API.
*/
class RequestService extends BaseService {
/* eslint-disable max-len */
/**
* Get a list of purchase requests filtered by statuses and optionally products.
* Get a list of requests that match all the filter values provided as input.
* Some fields accept an array of values (search with the `in` operator).
*
* @param {Object} filter A filter object as described below.
*
* @return {Array} An Array of Request objects.
* @param {string|Array} filter.type The request type (purchase|change|suspend|resume|renew|cancel).
* @param {string|Array} filter.status The status of the request (pending|inquiring|failed|approved).
* @param {string|Array} filter.id The id of the request.
* @param {string|Array} filter.assetId The id of the asset that belongs to the request.
* @param {string|Array} filter.assetProductId The id of the product that belongs to asset of the request.
* @param {string|Array} filter.assetProductName The name of the product that belongs to asset of the request (exact match case-insensitive).
* @param {string|Array} filter.assetConnectionType The type of the connection.
* @param {string|Array} filter.assetConnectionHubId The id of the hub involved in the asset connection.
* @param {string|Array} filter.assetConnectionHubName The name of the hub involved in the asset connection.
* @param {string|Array} filter.assetConnectionProviderId The id of the provider involved in the asset connection.
* @param {string|Array} filter.assetConnectionProviderName The name of the provider involved in the asset connection.
* @param {string|Array} filter.assetConnectionVendorId The id of the vendor involved in the asset connection.
* @param {string|Array} filter.assetConnectionVendorName The name of the vendor involved in the asset connection.
* @param {string} filter.assetTiersCustomerId The id of the customer account for this asset.
* @param {string} filter.assetTiersTier1Id The id of T1 account for this asset.
* @param {string} filter.assetTiersTier2Id The id of T2 account for this asset.
*
* @return {Array} An array of Request objects that match the provided filters.
*/
async list(statuses, products) {
const params = {
status__in: statuses.join(),
};
if (products) {
params.product_id__in = products.join();
}
/* eslint-enable max-len */
async list({
type,
status,
id,
assetId,
assetProductId,
assetProductName,
assetConnectionType,
assetConnectionHubId,
assetConnectionHubName,
assetConnectionProviderId,
assetConnectionProviderName,
assetConnectionVendorId,
assetConnectionVendorName,
assetTiersCustomerId,
assetTiersTier1Id,
assetTiersTier2Id,
}) {
const params = {};
addFilterParam(params, 'type', type);
addFilterParam(params, 'status', status);
addFilterParam(params, 'id', id);
addFilterParam(params, 'asset.id', assetId);
addFilterParam(params, 'asset.product.id', assetProductId);
addFilterParam(params, 'asset.product.name', assetProductName);
addFilterParam(params, 'asset.connection.type', assetConnectionType);
addFilterParam(params, 'asset.connection.hub.id', assetConnectionHubId);
addFilterParam(params, 'asset.connection.hub.name', assetConnectionHubName);
addFilterParam(params, 'asset.connection.provider.id', assetConnectionProviderId);
addFilterParam(params, 'asset.connection.provider.name', assetConnectionProviderName);
addFilterParam(params, 'asset.connection.vendor.id', assetConnectionVendorId);
addFilterParam(params, 'asset.connection.vendor.name', assetConnectionVendorName);
addFilterParam(params, 'asset.tiers.customer.id', assetTiersCustomerId);
addFilterParam(params, 'asset.tiers.tier1.id', assetTiersTier1Id);
addFilterParam(params, 'asset.tiers.tier2.id', assetTiersTier2Id);


const url = this.addParams('/requests', params);
const response = await this.fetch(url);
await this.checkResponse(response);
Expand Down Expand Up @@ -50,6 +104,50 @@ class RequestService extends BaseService {
return response.json();
}


/**
* Set Inquire a request.
*
* @param {string} id Id of the purchase request.
* @param {sring} reason Description of the reason of inquire
* @param {sring} templateId Activation Template ID
* @param {Array} params An array of parameter objects ({id, value}) to update for Request.
*
* @return {*} [Check return type]£
*/
async inquireRequest(id, reason, templateId, params) {
await this.updateRequestParameters(id, params, reason);
const url = `/requests/${id}/inquire`;
const options = {
method: 'POST',
body: {
template_id: templateId,
},
};
const response = await this.fetch(url, options);
await this.checkResponse(response);
return response.json();
}

/**
* Update fields of the root of Request
*
* @param {string} id The unique identifier of the Request to update.
* @param {Array} params An array of parameter objects to update for the root of Request.
*
* @return {Object} The updated Request object.
*/
async updateRequest(id, request) {
const url = `/requests/${id}`;
const options = {
method: 'PUT',
body: request,
};
const response = await this.fetch(url, options);
await this.checkResponse(response);
return response.json();
}

/**
* [updateRequestParameters description]
*
Expand All @@ -65,16 +163,16 @@ class RequestService extends BaseService {
method: 'PUT',
body: {
asset: {
params
}
params,
},
},
};
if (note !== undefined) {
options.body.note = note;
}
const response = await this.fetch(url, options);
await this.checkResponse(response);
return response.json();
return response.json();
}

/**
Expand All @@ -90,12 +188,30 @@ class RequestService extends BaseService {
const options = {
method: 'POST',
body: {
template_id: templateId
}
}
template_id: templateId,
},
};
const response = await this.fetch(url, options);
await this.checkResponse(response);
return response.json();
return response.json();
}

/**
* Creates a new Request.
*
* @param {Object} req The Request to create.
*
* @return {Object} A newly created Request (partial).
*/
async create(req) {
const url = '/requests';
const options = {
method: 'POST',
body: req,
};
const response = await this.fetch(url, options);
await this.checkResponse(response);
return response.json();
}
}

Expand Down

0 comments on commit 0ed95b6

Please sign in to comment.