1
- /*! dynamics-web-api v1.3.3 (c) 2017 Aleksandr Rogov */
1
+ /*! dynamics-web-api v1.3.4 (c) 2017 Aleksandr Rogov */
2
2
( function webpackUniversalModuleDefinition ( root , factory ) {
3
3
if ( typeof exports === 'object' && typeof module === 'object' )
4
4
module . exports = factory ( ) ;
@@ -278,6 +278,38 @@ var ErrorHelper = {
278
278
}
279
279
} ,
280
280
281
+ /**
282
+ * @param parameter {string} - parameter
283
+ *
284
+ */
285
+ keyParameterCheck : function ( parameter , functionName , parameterName ) {
286
+
287
+ try {
288
+ ErrorHelper . stringParameterCheck ( parameter , functionName , parameterName ) ;
289
+
290
+ //check if the param is a guid
291
+ var match = / [ 0 - 9 A - F ] { 8 } [ - ] ? ( [ 0 - 9 A - F ] { 4 } [ - ] ? ) { 3 } [ 0 - 9 A - F ] { 12 } / i. exec ( parameter ) ;
292
+ if ( match ) {
293
+ return match [ 0 ] ;
294
+ }
295
+
296
+ //check the alternate key
297
+ var alternateKeys = parameter . split ( ',' ) ;
298
+
299
+ if ( alternateKeys . length ) {
300
+ for ( var i = 0 ; i < alternateKeys . length ; i ++ ) {
301
+ alternateKeys [ i ] = alternateKeys [ i ] . trim ( ) ;
302
+ / ^ [ \w \d \_ ] + \= ' [ ^ \' \r \n ] + ' $ / i. exec ( alternateKeys [ i ] ) [ 0 ] ;
303
+ }
304
+ }
305
+
306
+ return alternateKeys . join ( ',' ) ;
307
+ }
308
+ catch ( error ) {
309
+ throwParameterError ( functionName , parameterName , "String representing GUID or Alternate Key" ) ;
310
+ }
311
+ } ,
312
+
281
313
callbackParameterCheck : function ( callbackParameter , functionName , parameterName ) {
282
314
///<summary>
283
315
/// Private function used to check whether required callback parameters are functions
@@ -490,12 +522,12 @@ function convertRequestOptions(request, functionName, url, joinSymbol, config) {
490
522
491
523
if ( request ) {
492
524
if ( request . navigationProperty ) {
493
- ErrorHelper . stringParameterCheck ( request . navigationProperty , " DynamicsWebApi." + functionName , "request.navigationProperty" ) ;
525
+ ErrorHelper . stringParameterCheck ( request . navigationProperty , ' DynamicsWebApi.' + functionName , "request.navigationProperty" ) ;
494
526
url += "/" + request . navigationProperty ;
495
527
}
496
528
497
529
if ( request . select != null && request . select . length ) {
498
- ErrorHelper . arrayParameterCheck ( request . select , " DynamicsWebApi." + functionName , "request.select" ) ;
530
+ ErrorHelper . arrayParameterCheck ( request . select , ' DynamicsWebApi.' + functionName , "request.select" ) ;
499
531
500
532
if ( functionName == "retrieve" && request . select . length == 1 && request . select [ 0 ] . endsWith ( "/$ref" ) ) {
501
533
url += "/" + request . select [ 0 ] ;
@@ -518,30 +550,30 @@ function convertRequestOptions(request, functionName, url, joinSymbol, config) {
518
550
}
519
551
520
552
if ( request . filter ) {
521
- ErrorHelper . stringParameterCheck ( request . filter , " DynamicsWebApi." + functionName , "request.filter" ) ;
553
+ ErrorHelper . stringParameterCheck ( request . filter , ' DynamicsWebApi.' + functionName , "request.filter" ) ;
522
554
requestArray . push ( "$filter=" + request . filter ) ;
523
555
}
524
556
525
557
if ( request . savedQuery ) {
526
- requestArray . push ( "savedQuery=" + ErrorHelper . guidParameterCheck ( request . savedQuery , " DynamicsWebApi." + functionName , "request.savedQuery" ) ) ;
558
+ requestArray . push ( "savedQuery=" + ErrorHelper . guidParameterCheck ( request . savedQuery , ' DynamicsWebApi.' + functionName , "request.savedQuery" ) ) ;
527
559
}
528
560
529
561
if ( request . userQuery ) {
530
- requestArray . push ( "userQuery=" + ErrorHelper . guidParameterCheck ( request . userQuery , " DynamicsWebApi." + functionName , "request.userQuery" ) ) ;
562
+ requestArray . push ( "userQuery=" + ErrorHelper . guidParameterCheck ( request . userQuery , ' DynamicsWebApi.' + functionName , "request.userQuery" ) ) ;
531
563
}
532
564
533
565
if ( request . count ) {
534
- ErrorHelper . boolParameterCheck ( request . count , " DynamicsWebApi." + functionName , "request.count" ) ;
566
+ ErrorHelper . boolParameterCheck ( request . count , ' DynamicsWebApi.' + functionName , "request.count" ) ;
535
567
requestArray . push ( "$count=" + request . count ) ;
536
568
}
537
569
538
570
if ( request . top && request . top > 0 ) {
539
- ErrorHelper . numberParameterCheck ( request . top , " DynamicsWebApi." + functionName , "request.top" ) ;
571
+ ErrorHelper . numberParameterCheck ( request . top , ' DynamicsWebApi.' + functionName , "request.top" ) ;
540
572
requestArray . push ( "$top=" + request . top ) ;
541
573
}
542
574
543
575
if ( request . orderBy != null && request . orderBy . length ) {
544
- ErrorHelper . arrayParameterCheck ( request . orderBy , " DynamicsWebApi." + functionName , "request.orderBy" ) ;
576
+ ErrorHelper . arrayParameterCheck ( request . orderBy , ' DynamicsWebApi.' + functionName , "request.orderBy" ) ;
545
577
requestArray . push ( "$orderby=" + request . orderBy . join ( ',' ) ) ;
546
578
}
547
579
@@ -552,33 +584,38 @@ function convertRequestOptions(request, functionName, url, joinSymbol, config) {
552
584
}
553
585
554
586
if ( request . ifmatch != null && request . ifnonematch != null ) {
555
- throw new Error ( " DynamicsWebApi." + functionName + ". Either one of request.ifmatch or request.ifnonematch parameters should be used in a call, not both." )
587
+ throw new Error ( ' DynamicsWebApi.' + functionName + ". Either one of request.ifmatch or request.ifnonematch parameters should be used in a call, not both." )
556
588
}
557
589
558
590
if ( request . ifmatch ) {
559
- ErrorHelper . stringParameterCheck ( request . ifmatch , " DynamicsWebApi." + functionName , "request.ifmatch" ) ;
591
+ ErrorHelper . stringParameterCheck ( request . ifmatch , ' DynamicsWebApi.' + functionName , "request.ifmatch" ) ;
560
592
headers [ 'If-Match' ] = request . ifmatch ;
561
593
}
562
594
563
595
if ( request . ifnonematch ) {
564
- ErrorHelper . stringParameterCheck ( request . ifnonematch , " DynamicsWebApi." + functionName , "request.ifnonematch" ) ;
596
+ ErrorHelper . stringParameterCheck ( request . ifnonematch , ' DynamicsWebApi.' + functionName , "request.ifnonematch" ) ;
565
597
headers [ 'If-None-Match' ] = request . ifnonematch ;
566
598
}
567
599
568
600
if ( request . impersonate ) {
569
- ErrorHelper . stringParameterCheck ( request . impersonate , " DynamicsWebApi." + functionName , "request.impersonate" ) ;
570
- headers [ 'MSCRMCallerID' ] = ErrorHelper . guidParameterCheck ( request . impersonate , " DynamicsWebApi." + functionName , "request.impersonate" ) ;
601
+ ErrorHelper . stringParameterCheck ( request . impersonate , ' DynamicsWebApi.' + functionName , "request.impersonate" ) ;
602
+ headers [ 'MSCRMCallerID' ] = ErrorHelper . guidParameterCheck ( request . impersonate , ' DynamicsWebApi.' + functionName , "request.impersonate" ) ;
571
603
}
572
604
573
605
if ( request . token ) {
574
- ErrorHelper . stringParameterCheck ( request . token , "DynamicsWebApi." + functionName , "request.token" ) ;
575
- headers [ "Authorization" ] = "Bearer " + request . token ;
606
+ ErrorHelper . stringParameterCheck ( request . token , 'DynamicsWebApi.' + functionName , "request.token" ) ;
607
+ headers [ 'Authorization' ] = 'Bearer ' + request . token ;
608
+ }
609
+
610
+ if ( request . duplicateDetection ) {
611
+ ErrorHelper . boolParameterCheck ( request . duplicateDetection , 'DynamicsWebApi.' + functionName , 'request.duplicateDetection' ) ;
612
+ headers [ 'MSCRM.SuppressDuplicateDetection' ] = 'false' ;
576
613
}
577
614
578
615
if ( request . expand && request . expand . length ) {
579
- ErrorHelper . stringOrArrayParameterCheck ( request . expand , " DynamicsWebApi." + functionName , "request.expand" ) ;
580
- if ( typeof request . expand === " string" ) {
581
- requestArray . push ( " $expand=" + request . expand ) ;
616
+ ErrorHelper . stringOrArrayParameterCheck ( request . expand , ' DynamicsWebApi.' + functionName , "request.expand" ) ;
617
+ if ( typeof request . expand === ' string' ) {
618
+ requestArray . push ( ' $expand=' + request . expand ) ;
582
619
}
583
620
else {
584
621
var expandRequestArray = [ ] ;
@@ -624,17 +661,24 @@ function getCollectionName(collectionName) {
624
661
function convertRequest ( request , functionName , config ) {
625
662
626
663
if ( ! request . collection ) {
627
- ErrorHelper . parameterCheck ( request . collection , " DynamicsWebApi." + functionName , "request.collection" ) ;
664
+ ErrorHelper . parameterCheck ( request . collection , ' DynamicsWebApi.' + functionName , "request.collection" ) ;
628
665
}
629
666
else {
630
- ErrorHelper . stringParameterCheck ( request . collection , " DynamicsWebApi." + functionName , "request.collection" ) ;
667
+ ErrorHelper . stringParameterCheck ( request . collection , ' DynamicsWebApi.' + functionName , "request.collection" ) ;
631
668
}
632
669
633
670
var url = getCollectionName ( request . collection ) ;
634
671
635
- if ( request . id ) {
636
- request . id = ErrorHelper . guidParameterCheck ( request . id , "DynamicsWebApi." + functionName , "request.id" ) ;
637
- url += "(" + request . id + ")" ;
672
+ //add alternate key feature
673
+ if ( request . key ) {
674
+ request . key = ErrorHelper . keyParameterCheck ( request . key , 'DynamicsWebApi.' + functionName , "request.key" ) ;
675
+ }
676
+ else if ( request . id ) {
677
+ request . key = ErrorHelper . guidParameterCheck ( request . id , 'DynamicsWebApi.' + functionName , "request.id" ) ;
678
+ }
679
+
680
+ if ( request . key ) {
681
+ url += "(" + request . key + ")" ;
638
682
}
639
683
640
684
var result = convertRequestOptions ( request , functionName , url , '&' , config ) ;
@@ -644,7 +688,7 @@ function convertRequest(request, functionName, config) {
644
688
}
645
689
646
690
if ( request . hasOwnProperty ( 'async' ) && request . async != null ) {
647
- ErrorHelper . boolParameterCheck ( request . async , " DynamicsWebApi." + functionName , "request.async" ) ;
691
+ ErrorHelper . boolParameterCheck ( request . async , ' DynamicsWebApi.' + functionName , "request.async" ) ;
648
692
result . async = request . async ;
649
693
}
650
694
else {
@@ -932,16 +976,16 @@ function DynamicsWebApi(config) {
932
976
/**
933
977
* Sends an asynchronous request to retrieve a record.
934
978
*
935
- * @param {string } id - A String representing the GUID value for the record to retrieve.
979
+ * @param {string } key - A String representing the GUID value or Aternate Key for the record to retrieve.
936
980
* @param {string } collection - The Name of the Entity Collection.
937
981
* @param {Array } [select] - An Array representing the $select Query Option to control which attributes will be returned.
938
982
* @param {string|Array } [expand] - A String or Array of Expand Objects representing the $expand Query Option value to control which related records need to be returned.
939
983
* @returns {Promise }
940
984
*/
941
- this . retrieve = function ( id , collection , select , expand ) {
985
+ this . retrieve = function ( key , collection , select , expand ) {
942
986
943
- ErrorHelper . stringParameterCheck ( id , "DynamicsWebApi.retrieve" , "id " ) ;
944
- id = ErrorHelper . guidParameterCheck ( id , "DynamicsWebApi.retrieve" , "id " )
987
+ ErrorHelper . stringParameterCheck ( key , "DynamicsWebApi.retrieve" , "key " ) ;
988
+ key = ErrorHelper . keyParameterCheck ( key , "DynamicsWebApi.retrieve" , "key " )
945
989
ErrorHelper . stringParameterCheck ( collection , "DynamicsWebApi.retrieve" , "collection" ) ;
946
990
947
991
if ( select && select . length ) {
@@ -954,7 +998,7 @@ function DynamicsWebApi(config) {
954
998
955
999
var request = {
956
1000
collection : collection ,
957
- id : id ,
1001
+ key : key ,
958
1002
select : select ,
959
1003
expand : expand
960
1004
} ;
@@ -1002,17 +1046,17 @@ function DynamicsWebApi(config) {
1002
1046
/**
1003
1047
* Sends an asynchronous request to update a record.
1004
1048
*
1005
- * @param {string } id - A String representing the GUID value for the record to update.
1049
+ * @param {string } key - A String representing the GUID value or Alternate Key for the record to update.
1006
1050
* @param {string } collection - The Name of the Entity Collection.
1007
1051
* @param {Object } object - A JavaScript object valid for update operations.
1008
1052
* @param {string } [prefer] - If set to "return=representation" the function will return an updated object
1009
1053
* @param {Array } [select] - An Array representing the $select Query Option to control which attributes will be returned.
1010
1054
* @returns {Promise }
1011
1055
*/
1012
- this . update = function ( id , collection , object , prefer , select ) {
1056
+ this . update = function ( key , collection , object , prefer , select ) {
1013
1057
1014
- ErrorHelper . stringParameterCheck ( id , "DynamicsWebApi.update" , "id " ) ;
1015
- id = ErrorHelper . guidParameterCheck ( id , "DynamicsWebApi.update" , "id " )
1058
+ ErrorHelper . stringParameterCheck ( key , "DynamicsWebApi.update" , "key " ) ;
1059
+ key = ErrorHelper . keyParameterCheck ( key , "DynamicsWebApi.update" , "key " )
1016
1060
ErrorHelper . parameterCheck ( object , "DynamicsWebApi.update" , "object" ) ;
1017
1061
ErrorHelper . stringParameterCheck ( collection , "DynamicsWebApi.update" , "collection" ) ;
1018
1062
@@ -1026,7 +1070,7 @@ function DynamicsWebApi(config) {
1026
1070
1027
1071
var request = {
1028
1072
collection : collection ,
1029
- id : id ,
1073
+ key : key ,
1030
1074
select : select ,
1031
1075
prefer : prefer ,
1032
1076
entity : object
@@ -1038,22 +1082,22 @@ function DynamicsWebApi(config) {
1038
1082
/**
1039
1083
* Sends an asynchronous request to update a single value in the record.
1040
1084
*
1041
- * @param {string } id - A String representing the GUID value for the record to update.
1085
+ * @param {string } key - A String representing the GUID value or Alternate Key for the record to update.
1042
1086
* @param {string } collection - The Name of the Entity Collection.
1043
1087
* @param {Object } keyValuePair - keyValuePair object with a logical name of the field as a key and a value to update with. Example: {subject: "Update Record"}
1044
1088
* @param {string|Array } [prefer] - If set to "return=representation" the function will return an updated object
1045
1089
* @param {Array } [select] - An Array representing the $select Query Option to control which attributes will be returned.
1046
1090
* @returns {Promise }
1047
1091
*/
1048
- this . updateSingleProperty = function ( id , collection , keyValuePair , prefer , select ) {
1092
+ this . updateSingleProperty = function ( key , collection , keyValuePair , prefer , select ) {
1049
1093
1050
- ErrorHelper . stringParameterCheck ( id , "DynamicsWebApi.updateSingleProperty" , "id " ) ;
1051
- id = ErrorHelper . guidParameterCheck ( id , "DynamicsWebApi.updateSingleProperty" , "id " )
1094
+ ErrorHelper . stringParameterCheck ( key , "DynamicsWebApi.updateSingleProperty" , "key " ) ;
1095
+ key = ErrorHelper . keyParameterCheck ( key , "DynamicsWebApi.updateSingleProperty" , "key " )
1052
1096
ErrorHelper . parameterCheck ( keyValuePair , "DynamicsWebApi.updateSingleProperty" , "keyValuePair" ) ;
1053
1097
ErrorHelper . stringParameterCheck ( collection , "DynamicsWebApi.updateSingleProperty" , "collection" ) ;
1054
1098
1055
- var key = Object . keys ( keyValuePair ) [ 0 ] ;
1056
- var keyValue = keyValuePair [ key ] ;
1099
+ var field = Object . keys ( keyValuePair ) [ 0 ] ;
1100
+ var fieldValue = keyValuePair [ field ] ;
1057
1101
1058
1102
if ( prefer ) {
1059
1103
ErrorHelper . stringOrArrayParameterCheck ( prefer , "DynamicsWebApi.updateSingleProperty" , "prefer" ) ;
@@ -1065,15 +1109,15 @@ function DynamicsWebApi(config) {
1065
1109
1066
1110
var request = {
1067
1111
collection : collection ,
1068
- id : id ,
1112
+ key : key ,
1069
1113
select : select ,
1070
1114
prefer : prefer ,
1071
- navigationProperty : key
1115
+ navigationProperty : field
1072
1116
} ;
1073
1117
1074
1118
var result = RequestConverter . convertRequest ( request , "updateSingleProperty" , _internalConfig ) ;
1075
1119
1076
- return _sendRequest ( "PUT" , result . url , { value : keyValue } , result . headers , result . async )
1120
+ return _sendRequest ( "PUT" , result . url , { value : fieldValue } , result . headers , result . async )
1077
1121
. then ( function ( response ) {
1078
1122
if ( response . data ) {
1079
1123
return response . data ;
@@ -1112,21 +1156,21 @@ function DynamicsWebApi(config) {
1112
1156
/**
1113
1157
* Sends an asynchronous request to delete a record.
1114
1158
*
1115
- * @param {string } id - A String representing the GUID value for the record to delete.
1159
+ * @param {string } key - A String representing the GUID value or Alternate Key for the record to delete.
1116
1160
* @param {string } collection - The Name of the Entity Collection.
1117
1161
* @param {string } [propertyName] - The name of the property which needs to be emptied. Instead of removing a whole record only the specified property will be cleared.
1118
1162
* @returns {Promise }
1119
1163
*/
1120
- this . deleteRecord = function ( id , collection , propertyName ) {
1164
+ this . deleteRecord = function ( key , collection , propertyName ) {
1121
1165
1122
- ErrorHelper . stringParameterCheck ( id , "DynamicsWebApi.deleteRecord" , "id " ) ;
1123
- id = ErrorHelper . guidParameterCheck ( id , "DynamicsWebApi.deleteRecord" , "id " )
1166
+ ErrorHelper . stringParameterCheck ( key , "DynamicsWebApi.deleteRecord" , "key " ) ;
1167
+ key = ErrorHelper . keyParameterCheck ( key , "DynamicsWebApi.deleteRecord" , "key " )
1124
1168
ErrorHelper . stringParameterCheck ( collection , "DynamicsWebApi.deleteRecord" , "collection" ) ;
1125
1169
1126
1170
if ( propertyName != null )
1127
1171
ErrorHelper . stringParameterCheck ( propertyName , "DynamicsWebApi.deleteRecord" , "propertyName" ) ;
1128
1172
1129
- var url = collection . toLowerCase ( ) + "(" + id + ")" ;
1173
+ var url = collection . toLowerCase ( ) + "(" + key + ")" ;
1130
1174
1131
1175
if ( propertyName != null )
1132
1176
url += "/" + propertyName ;
@@ -1181,17 +1225,17 @@ function DynamicsWebApi(config) {
1181
1225
/**
1182
1226
* Sends an asynchronous request to upsert a record.
1183
1227
*
1184
- * @param {string } id - A String representing the GUID value for the record to upsert.
1228
+ * @param {string } key - A String representing the GUID value or Alternate Key for the record to upsert.
1185
1229
* @param {string } collection - The Name of the Entity Collection.
1186
1230
* @param {Object } object - A JavaScript object valid for update operations.
1187
1231
* @param {string|Array } [prefer] - If set to "return=representation" the function will return an updated object
1188
1232
* @param {Array } [select] - An Array representing the $select Query Option to control which attributes will be returned.
1189
1233
* @returns {Promise }
1190
1234
*/
1191
- this . upsert = function ( id , collection , object , prefer , select ) {
1235
+ this . upsert = function ( key , collection , object , prefer , select ) {
1192
1236
1193
- ErrorHelper . stringParameterCheck ( id , "DynamicsWebApi.upsert" , "id " ) ;
1194
- id = ErrorHelper . guidParameterCheck ( id , "DynamicsWebApi.upsert" , "id " )
1237
+ ErrorHelper . stringParameterCheck ( key , "DynamicsWebApi.upsert" , "key " ) ;
1238
+ key = ErrorHelper . keyParameterCheck ( key , "DynamicsWebApi.upsert" , "key " )
1195
1239
1196
1240
ErrorHelper . parameterCheck ( object , "DynamicsWebApi.upsert" , "object" ) ;
1197
1241
ErrorHelper . stringParameterCheck ( collection , "DynamicsWebApi.upsert" , "collection" ) ;
@@ -1206,7 +1250,7 @@ function DynamicsWebApi(config) {
1206
1250
1207
1251
var request = {
1208
1252
collection : collection ,
1209
- id : id ,
1253
+ key : key ,
1210
1254
select : select ,
1211
1255
prefer : prefer ,
1212
1256
entity : object
0 commit comments