dynamics-web-api
Advanced tools
Comparing version 1.7.5 to 1.7.6
function throwParameterError(functionName, parameterName, type) { | ||
throw new Error(type | ||
? functionName + " requires the " + parameterName + " parameter to be of type " + type | ||
: functionName + " requires the " + parameterName + " parameter."); | ||
}; | ||
throw new Error( | ||
type | ||
? functionName + " requires the " + parameterName + " parameter to be of type " + type | ||
: functionName + " requires the " + parameterName + " parameter." | ||
); | ||
} | ||
var ErrorHelper = { | ||
handleErrorResponse: function (req) { | ||
///<summary> | ||
/// Private function return an Error object to the errorCallback | ||
///</summary> | ||
///<param name="req" type="XMLHttpRequest"> | ||
/// The XMLHttpRequest response that returned an error. | ||
///</param> | ||
///<returns>Error</returns> | ||
throw new Error("Error: " + | ||
req.status + ": " + | ||
req.message); | ||
}, | ||
handleErrorResponse: function (req) { | ||
///<summary> | ||
/// Private function return an Error object to the errorCallback | ||
///</summary> | ||
///<param name="req" type="XMLHttpRequest"> | ||
/// The XMLHttpRequest response that returned an error. | ||
///</param> | ||
///<returns>Error</returns> | ||
throw new Error("Error: " + req.status + ": " + req.message); | ||
}, | ||
parameterCheck: function (parameter, functionName, parameterName, type) { | ||
///<summary> | ||
/// Private function used to check whether required parameters are null or undefined | ||
///</summary> | ||
///<param name="parameter" type="Object"> | ||
/// The parameter to check; | ||
///</param> | ||
///<param name="message" type="String"> | ||
/// The error message text to include when the error is thrown. | ||
///</param> | ||
if ((typeof parameter === "undefined") || parameter === null || parameter == "") { | ||
throwParameterError(functionName, parameterName, type); | ||
} | ||
}, | ||
parameterCheck: function (parameter, functionName, parameterName, type) { | ||
///<summary> | ||
/// Private function used to check whether required parameters are null or undefined | ||
///</summary> | ||
///<param name="parameter" type="Object"> | ||
/// The parameter to check; | ||
///</param> | ||
///<param name="message" type="String"> | ||
/// The error message text to include when the error is thrown. | ||
///</param> | ||
if (typeof parameter === "undefined" || parameter === null || parameter == "") { | ||
throwParameterError(functionName, parameterName, type); | ||
} | ||
}, | ||
stringParameterCheck: function (parameter, functionName, parameterName) { | ||
///<summary> | ||
/// Private function used to check whether required parameters are null or undefined | ||
///</summary> | ||
///<param name="parameter" type="String"> | ||
/// The string parameter to check; | ||
///</param> | ||
///<param name="message" type="String"> | ||
/// The error message text to include when the error is thrown. | ||
///</param> | ||
if (typeof parameter != "string") { | ||
throwParameterError(functionName, parameterName, "String"); | ||
} | ||
}, | ||
stringParameterCheck: function (parameter, functionName, parameterName) { | ||
///<summary> | ||
/// Private function used to check whether required parameters are null or undefined | ||
///</summary> | ||
///<param name="parameter" type="String"> | ||
/// The string parameter to check; | ||
///</param> | ||
///<param name="message" type="String"> | ||
/// The error message text to include when the error is thrown. | ||
///</param> | ||
if (typeof parameter != "string") { | ||
throwParameterError(functionName, parameterName, "String"); | ||
} | ||
}, | ||
arrayParameterCheck: function (parameter, functionName, parameterName) { | ||
///<summary> | ||
/// Private function used to check whether required parameters are null or undefined | ||
///</summary> | ||
///<param name="parameter" type="String"> | ||
/// The string parameter to check; | ||
///</param> | ||
///<param name="message" type="String"> | ||
/// The error message text to include when the error is thrown. | ||
///</param> | ||
if (parameter.constructor !== Array) { | ||
throwParameterError(functionName, parameterName, "Array"); | ||
} | ||
}, | ||
arrayParameterCheck: function (parameter, functionName, parameterName) { | ||
///<summary> | ||
/// Private function used to check whether required parameters are null or undefined | ||
///</summary> | ||
///<param name="parameter" type="String"> | ||
/// The string parameter to check; | ||
///</param> | ||
///<param name="message" type="String"> | ||
/// The error message text to include when the error is thrown. | ||
///</param> | ||
if (parameter.constructor !== Array) { | ||
throwParameterError(functionName, parameterName, "Array"); | ||
} | ||
}, | ||
stringOrArrayParameterCheck: function (parameter, functionName, parameterName) { | ||
if (parameter.constructor !== Array && typeof parameter != "string") { | ||
throwParameterError(functionName, parameterName, "String or Array"); | ||
} | ||
}, | ||
stringOrArrayParameterCheck: function (parameter, functionName, parameterName) { | ||
if (parameter.constructor !== Array && typeof parameter != "string") { | ||
throwParameterError(functionName, parameterName, "String or Array"); | ||
} | ||
}, | ||
numberParameterCheck: function (parameter, functionName, parameterName) { | ||
///<summary> | ||
/// Private function used to check whether required parameters are null or undefined | ||
///</summary> | ||
///<param name="parameter" type="Number"> | ||
/// The string parameter to check; | ||
///</param> | ||
///<param name="message" type="String"> | ||
/// The error message text to include when the error is thrown. | ||
///</param> | ||
if (typeof parameter != "number") { | ||
if (typeof parameter === "string" && parameter) { | ||
if (!isNaN(parseInt(parameter))) { | ||
return; | ||
} | ||
} | ||
throwParameterError(functionName, parameterName, "Number"); | ||
} | ||
}, | ||
numberParameterCheck: function (parameter, functionName, parameterName) { | ||
///<summary> | ||
/// Private function used to check whether required parameters are null or undefined | ||
///</summary> | ||
///<param name="parameter" type="Number"> | ||
/// The string parameter to check; | ||
///</param> | ||
///<param name="message" type="String"> | ||
/// The error message text to include when the error is thrown. | ||
///</param> | ||
if (typeof parameter != "number") { | ||
if (typeof parameter === "string" && parameter) { | ||
if (!isNaN(parseInt(parameter))) { | ||
return; | ||
} | ||
} | ||
throwParameterError(functionName, parameterName, "Number"); | ||
} | ||
}, | ||
boolParameterCheck: function (parameter, functionName, parameterName) { | ||
///<summary> | ||
/// Private function used to check whether required parameters are null or undefined | ||
///</summary> | ||
///<param name="parameter" type="Boolean"> | ||
/// The string parameter to check; | ||
///</param> | ||
///<param name="message" type="String"> | ||
/// The error message text to include when the error is thrown. | ||
///</param> | ||
if (typeof parameter != "boolean") { | ||
throwParameterError(functionName, parameterName, "Boolean"); | ||
} | ||
}, | ||
boolParameterCheck: function (parameter, functionName, parameterName) { | ||
///<summary> | ||
/// Private function used to check whether required parameters are null or undefined | ||
///</summary> | ||
///<param name="parameter" type="Boolean"> | ||
/// The string parameter to check; | ||
///</param> | ||
///<param name="message" type="String"> | ||
/// The error message text to include when the error is thrown. | ||
///</param> | ||
if (typeof parameter != "boolean") { | ||
throwParameterError(functionName, parameterName, "Boolean"); | ||
} | ||
}, | ||
guidParameterCheck: function (parameter, functionName, parameterName) { | ||
///<summary> | ||
/// Private function used to check whether required parameter is a valid GUID | ||
///</summary> | ||
///<param name="parameter" type="String"> | ||
/// The GUID parameter to check; | ||
///</param> | ||
///<param name="message" type="String"> | ||
/// The error message text to include when the error is thrown. | ||
///</param> | ||
/// <returns type="String" /> | ||
guidParameterCheck: function (parameter, functionName, parameterName) { | ||
///<summary> | ||
/// Private function used to check whether required parameter is a valid GUID | ||
///</summary> | ||
///<param name="parameter" type="String"> | ||
/// The GUID parameter to check; | ||
///</param> | ||
///<param name="message" type="String"> | ||
/// The error message text to include when the error is thrown. | ||
///</param> | ||
/// <returns type="String" /> | ||
try { | ||
var match = /[0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12}/i.exec(parameter)[0]; | ||
try { | ||
var match = /[0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12}/i.exec(parameter)[0]; | ||
return match; | ||
} | ||
catch (error) { | ||
throwParameterError(functionName, parameterName, "GUID String"); | ||
} | ||
}, | ||
return match; | ||
} catch (error) { | ||
throwParameterError(functionName, parameterName, "GUID String"); | ||
} | ||
}, | ||
keyParameterCheck: function (parameter, functionName, parameterName) { | ||
keyParameterCheck: function (parameter, functionName, parameterName) { | ||
try { | ||
ErrorHelper.stringParameterCheck(parameter, functionName, parameterName); | ||
try { | ||
ErrorHelper.stringParameterCheck(parameter, functionName, parameterName); | ||
//check if the param is a guid | ||
var match = /^{?([0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12})}?$/i.exec(parameter); | ||
if (match) { | ||
return match[1]; | ||
} | ||
//check if the param is a guid | ||
var match = /^{?([0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12})}?$/i.exec(parameter); | ||
if (match) { | ||
return match[1]; | ||
} | ||
//check the alternate key | ||
var alternateKeys = parameter.split(","); | ||
//check the alternate key | ||
var alternateKeys = parameter.split(','); | ||
if (alternateKeys.length) { | ||
for (var i = 0; i < alternateKeys.length; i++) { | ||
alternateKeys[i] = alternateKeys[i].trim().replace(/"/g, "'"); | ||
/^[\w\d\_]+\=(.+)$/i.exec(alternateKeys[i])[0]; | ||
} | ||
} | ||
if (alternateKeys.length) { | ||
for (var i = 0; i < alternateKeys.length; i++) { | ||
alternateKeys[i] = alternateKeys[i].trim().replace('"', "'"); | ||
/^[\w\d\_]+\=('[^\'\r\n]+'|\d+)$/i.exec(alternateKeys[i])[0]; | ||
} | ||
} | ||
return alternateKeys.join(","); | ||
} catch (error) { | ||
throwParameterError(functionName, parameterName, "String representing GUID or Alternate Key"); | ||
} | ||
}, | ||
return alternateKeys.join(','); | ||
} | ||
catch (error) { | ||
throwParameterError(functionName, parameterName, "String representing GUID or Alternate Key"); | ||
} | ||
}, | ||
callbackParameterCheck: function (callbackParameter, functionName, parameterName) { | ||
///<summary> | ||
/// Private function used to check whether required callback parameters are functions | ||
///</summary> | ||
///<param name="callbackParameter" type="Function"> | ||
/// The callback parameter to check; | ||
///</param> | ||
///<param name="message" type="String"> | ||
/// The error message text to include when the error is thrown. | ||
///</param> | ||
if (typeof callbackParameter != "function") { | ||
throwParameterError(functionName, parameterName, "Function"); | ||
} | ||
}, | ||
callbackParameterCheck: function (callbackParameter, functionName, parameterName) { | ||
///<summary> | ||
/// Private function used to check whether required callback parameters are functions | ||
///</summary> | ||
///<param name="callbackParameter" type="Function"> | ||
/// The callback parameter to check; | ||
///</param> | ||
///<param name="message" type="String"> | ||
/// The error message text to include when the error is thrown. | ||
///</param> | ||
if (typeof callbackParameter != "function") { | ||
throwParameterError(functionName, parameterName, "Function"); | ||
} | ||
}, | ||
batchIncompatible: function (functionName, isBatch) { | ||
if (isBatch) { | ||
isBatch = false; | ||
throw new Error(functionName + " cannot be used in a BATCH request."); | ||
} | ||
}, | ||
batchIncompatible: function (functionName, isBatch) { | ||
if (isBatch) { | ||
isBatch = false; | ||
throw new Error(functionName + " cannot be used in a BATCH request."); | ||
} | ||
}, | ||
batchNotStarted: function (isBatch) { | ||
if (!isBatch) { | ||
throw new Error( | ||
"Batch operation has not been started. Please call a DynamicsWebApi.startBatch() function prior to calling DynamicsWebApi.executeBatch() to perform a batch request correctly." | ||
); | ||
} | ||
}, | ||
batchNotStarted: function (isBatch) { | ||
if (!isBatch) { | ||
throw new Error("Batch operation has not been started. Please call a DynamicsWebApi.startBatch() function prior to calling DynamicsWebApi.executeBatch() to perform a batch request correctly."); | ||
} | ||
}, | ||
batchIsEmpty: function () { | ||
return [new Error("Payload of the batch operation is empty. Please make that you have other operations in between startBatch() and executeBatch() to successfuly build a batch payload.")]; | ||
batchIsEmpty: function () { | ||
return [ | ||
new Error( | ||
"Payload of the batch operation is empty. Please make that you have other operations in between startBatch() and executeBatch() to successfuly build a batch payload." | ||
), | ||
]; | ||
}, | ||
handleHttpError: function (parsedError, parameters) { | ||
var error = new Error(); | ||
handleHttpError: function (parsedError, parameters) { | ||
var error = new Error(); | ||
Object.keys(parsedError).forEach(function(k) { | ||
error[k] = parsedError[k]; | ||
}); | ||
Object.keys(parsedError).forEach(function (k) { | ||
error[k] = parsedError[k]; | ||
}); | ||
if (parameters) { | ||
Object.keys(parameters).forEach(function (k) { | ||
error[k] = parameters[k]; | ||
}); | ||
} | ||
if (parameters) { | ||
Object.keys(parameters).forEach(function (k) { | ||
error[k] = parameters[k]; | ||
}); | ||
} | ||
return error; | ||
} | ||
return error; | ||
}, | ||
}; | ||
module.exports = ErrorHelper; | ||
module.exports = ErrorHelper; |
{ | ||
"name": "dynamics-web-api", | ||
"version": "1.7.5", | ||
"version": "1.7.6", | ||
"description": "DynamicsWebApi is a Microsoft Dynamics CRM Web API helper library", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -565,2 +565,4 @@ // Type definitions for dynamics-web-api v1.7.5 | ||
navigationPropertyKey?: string; | ||
/**An Array(of Strings) representing the $select OData System Query Option to control which attributes will be returned. */ | ||
select?: string[]; | ||
/**Sets Prefer header request with value "return=representation".Use this property to return just created or updated entity in a single request. */ | ||
@@ -567,0 +569,0 @@ returnRepresentation?: boolean; |
Sorry, the diff of this file is too big to display
5432
2200
354780