@resconet/jsbridge 17.1.0-beta.3 → 17.1.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/JSBridge.js +177 -39
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@resconet/jsbridge",
3
- "version": "17.1.0-beta.3",
3
+ "version": "17.1.0-beta.4",
4
4
  "main": "./src/JSBridge.js",
5
5
  "types": "./src/JSBridge.d.ts",
6
6
  "description": "Install npm JSBridge module",
package/src/JSBridge.js CHANGED
@@ -25,6 +25,21 @@
25
25
  }
26
26
  return null;
27
27
  };
28
+ var _normalizeArray = function (arr, convertCallback) {
29
+ var retVal = undefined;
30
+ if (arr instanceof Array && arr.length > 0) {
31
+ const normArr = [];
32
+ for (const o of arr) {
33
+ if (o) {
34
+ normArr.push(convertCallback(o));
35
+ }
36
+ }
37
+ if (normArr.length > 0) {
38
+ retVal = normArr;
39
+ }
40
+ }
41
+ return retVal;
42
+ };
28
43
  var _addProperty = function (obj, name, writable, value) {
29
44
  if (!obj._privVals) {
30
45
  obj._privVals = {};
@@ -398,11 +413,19 @@
398
413
  /// <field name="entity" type="MobileCRM.FetchXml.Entity">An entity object.</field>
399
414
  /// <field name="page" type="int">1-based index of the data page to retrieve.</field>
400
415
  /// <field name="distinct" type="Boolean">Whether to return only distinct (different) values.</field>
401
- this.entity = entity;
402
- this.count = count;
403
- this.page = page;
416
+ if (entity) {
417
+ this.entity = entity;
418
+ }
419
+ if (typeof count !== "undefined") {
420
+ this.count = count;
421
+ }
422
+ if (typeof page !== "undefined") {
423
+ this.page = page;
424
+ }
404
425
  this.aggregate = false;
405
- this.distinct = distinct;
426
+ if (typeof distinct !== "undefined") {
427
+ this.distinct = distinct;
428
+ }
406
429
  },
407
430
  Entity: function (name) {
408
431
  /// <summary>Represents a FetchXml query root entity.</summary>
@@ -412,25 +435,23 @@
412
435
  /// <field name="linkentities" type="Array">An array of <see cref="MobileCRM.FetchXml.LinkEntity">MobileCRM.FetchXml.LinkEntity</see> objects.</field>
413
436
  /// <field name="name" type="String">An entity logical name.</field>
414
437
  /// <field name="order" type="Array">An array of <see cref="MobileCRM.FetchXml.Order">MobileCRM.FetchXml.Order</see> objects.</field>
415
- this.name = name;
438
+ if (name) {
439
+ this.name = name;
440
+ }
416
441
  this.attributes = [];
417
442
  this.order = [];
418
443
  this.filter = null;
419
444
  this.linkentities = [];
420
445
  },
421
- LinkEntity: function (name) {
446
+ LinkEntity: function () {
422
447
  /// <summary>Represents a FetchXml query linked entity.</summary>
423
448
  /// <remarks>This object is derived from <see cref="MobileCRM.FetchXml.Entity">MobileCRM.FetchXml.Entity</see></remarks>
449
+ /// <param name="name" type="String">An entity name</param>
424
450
  /// <field name="alias" type="String">A link alias.</field>
425
451
  /// <field name="from" type="String">The "from" field (if parent then target entity primary key).</field>
426
452
  /// <field name="linkType" type="String">The link (join) type ("inner" or "outer").</field>
427
- /// <param name="name" type="String">An entity name</param>
428
453
  /// <field name="to" type="String">The "to" field.</field>
429
454
  MobileCRM.FetchXml.LinkEntity.superproto.constructor.apply(this, arguments);
430
- this.from = null;
431
- this.to = null;
432
- this.linktype = null;
433
- this.alias = null;
434
455
  },
435
456
  Attribute: function (name) {
436
457
  /// <summary>Represents a FetchXml select statement (CRM field).</summary>
@@ -440,11 +461,10 @@
440
461
  /// <field name="dategrouping" type="String">A date group by modifier (year, quarter, month, week, day).</field>
441
462
  /// <field name="groupby" type="Boolean">Indicates whether to group by this attribute.</field>
442
463
  /// <field name="name" type="String">A lower-case entity attribute name (CRM logical field name).</field>
443
- this.name = name;
444
- this.aggregate = null;
464
+ if (name) {
465
+ this.name = name;
466
+ }
445
467
  this.groupby = false;
446
- this.alias = null;
447
- this.dategrouping = null;
448
468
  },
449
469
  Order: function (attribute, descending) {
450
470
  /// <summary>Represents a FetchXml order statement.</summary>
@@ -453,8 +473,9 @@
453
473
  /// <field name="alias" type="String">Defines an order alias.</field>
454
474
  /// <field name="attribute" type="String">An attribute name (CRM logical field name).</field>
455
475
  /// <field name="descending" type="Boolean">true, for descending order; false, for ascending order.</field>
456
- this.attribute = attribute;
457
- this.alias = null;
476
+ if (attribute) {
477
+ this.attribute = attribute;
478
+ }
458
479
  this.descending = descending ? true : false;
459
480
  },
460
481
  Filter: function () {
@@ -462,7 +483,6 @@
462
483
  /// <field name="conditions" type="Array">An array of <see cref="MobileCRM.FetchXml.Condition">Condition</see> objects.</field>
463
484
  /// <field name="filters" type="Array">An array of <see cref="MobileCRM.FetchXml.Filter">Filter</see> objects representing child-filters.</field>
464
485
  /// <field name="type" type="String">Defines the filter operator ("or" / "and").</field>
465
- this.type = null;
466
486
  this.conditions = [];
467
487
  this.filters = [];
468
488
  },
@@ -474,15 +494,10 @@
474
494
  /// <field name="uitype" type="String">The lookup target entity logical name.</field>
475
495
  /// <field name="value" type="">The value to compare to.</field>
476
496
  /// <field name="values" type="Array">The list of values to compare to.</field>
477
- this.attribute = null;
478
- this.operator = null;
479
- this.uitype = null;
480
- this.uiname = null;
481
- this.value = null;
482
497
  this.values = [];
483
498
  },
484
499
  },
485
- Platform: function (props) {
500
+ Platform: function () {
486
501
  /// <summary>Represents object for querying platform specific information and executing platform integrated actions.</summary>
487
502
  /// <remarks>This object cannot be created directly. To obtain/modify this object, use <see cref="MobileCRM.Platform.requestObject">MobileCRM.Platform.requestObject</see> function.</remarks>
488
503
  /// <field name="capabilities" type="Number">Gets the mask of capability flags supported by this device (MakePhoneCalls=1; HasMapView=2).</field>
@@ -544,7 +559,7 @@
544
559
  },
545
560
  UI: {
546
561
  FormManager: {},
547
- EntityForm: function (props) {
562
+ EntityForm: function () {
548
563
  /// <summary>Represents the Javascript equivalent of native entity form object.</summary>
549
564
  /// <remarks>This object cannot be created directly. To obtain/modify this object, use <see cref="MobileCRM.UI.EntityForm.requestObject">MobileCRM.UI.EntityForm.requestObject</see> function.</remarks>
550
565
  /// <field name="associatedViews" type="Array">Gets the associated views as an array of <see cref="MobileCRM.UI._EntityList">MobileCRM.UI._EntityList</see> objects.</field>
@@ -572,11 +587,11 @@
572
587
  /// <field name="relationship" type="MobileCRM.Relationship">Gets the relation source and related entity. &quot;null&quot;, if there is no relationship.</field>
573
588
  MobileCRM.UI.QuestionnaireForm.superproto.constructor.apply(this, arguments);
574
589
  },
575
- EntityChart: function (props) {
590
+ EntityChart: function () {
576
591
  /// <summary>[13.0] Represents the Javascript equivalent of native entity chart object.</summary>
577
592
  MobileCRM.UI.EntityChart.superproto.constructor.apply(this, arguments);
578
593
  },
579
- EntityList: function (props) {
594
+ EntityList: function () {
580
595
  /// <summary>[v9.2] Represents the Javascript equivalent of native entity list object.</summary>
581
596
  /// <field name="allowAddExisting" type="Boolean">Gets or sets whether adding an existing entity is allowed.</field>
582
597
  /// <field name="allowCreateNew" type="Boolean">Gets or sets whether create a new entity (or managing the N:N entities in the case of N:N list) is allowed.</field>
@@ -604,7 +619,7 @@
604
619
  /// <field name="uniqueName" type="Number">Gets or sets the unique name of the list. Used to save/load list specific settings.</field>
605
620
  MobileCRM.UI.EntityList.superproto.constructor.apply(this, arguments);
606
621
  },
607
- HomeForm: function (props) {
622
+ HomeForm: function () {
608
623
  /// <summary>[v8.0] Represents the Javascript equivalent of the home form object which contains the Home/UI replacement iFrame.</summary>
609
624
  /// <remarks><p>This class works only from Home/UI replacement iFrame.</p><p>This object cannot be created directly. To obtain/modify this object, use <see cref="MobileCRM.UI.HomeForm.requestObject">MobileCRM.UI.HomeForm.requestObject</see> function.</p></remarks>
610
625
  /// <field name="form" type="MobileCRM.UI.Form">Gets the top level form.</field>
@@ -2527,21 +2542,144 @@
2527
2542
  /// <param name="scope" type="">A scope for calling the callbacks; set &quot;null&quot; to call the callbacks in global scope.</param>
2528
2543
  _global.MobileCRM.bridge.command("fetchXML", fetchXmlData, success, failed, scope);
2529
2544
  };
2545
+ MobileCRM.FetchXml.Condition._constructConditionParams = function (condition) {
2546
+ if (condition) {
2547
+ var conditionParams = {};
2548
+ if (condition.attribute) {
2549
+ conditionParams.attribute = condition.attribute;
2550
+ }
2551
+ if (condition.operator) {
2552
+ conditionParams.operator = condition.operator;
2553
+ }
2554
+ if (condition.uiname) {
2555
+ conditionParams.uiname = condition.uiname;
2556
+ }
2557
+ if (condition.uitype) {
2558
+ conditionParams.uitype = condition.uitype;
2559
+ }
2560
+ if (typeof condition.value !== "undefined") {
2561
+ conditionParams.value = condition.value;
2562
+ }
2563
+ if (condition.values instanceof Array && condition.values.length > 0) {
2564
+ conditionParams.values = condition.values;
2565
+ }
2566
+ return conditionParams;
2567
+ } else {
2568
+ return undefined;
2569
+ }
2570
+ };
2571
+ MobileCRM.FetchXml.Filter._constructFilterParams = function (filter) {
2572
+ if (filter) {
2573
+ var filterParams = {};
2574
+ if (filter.type) {
2575
+ filterParams.type = filter.type;
2576
+ }
2577
+ filterParams.conditions = _normalizeArray(filter.conditions, MobileCRM.FetchXml.Condition._constructConditionParams);
2578
+ filterParams.filters = _normalizeArray(filter.filters, MobileCRM.FetchXml.Filter._constructFilterParams);
2579
+ return filterParams;
2580
+ } else {
2581
+ return undefined;
2582
+ }
2583
+ };
2584
+ MobileCRM.FetchXml.Order._constructOrderParams = function (order) {
2585
+ if (order) {
2586
+ var orderParams = { attribute: order.attribute };
2587
+ if (typeof order.descending != "undefined") {
2588
+ orderParams.descending = order.descending;
2589
+ }
2590
+ if (order.alias) {
2591
+ orderParams.alias = order.alias;
2592
+ }
2593
+ return orderParams;
2594
+ } else {
2595
+ return undefined;
2596
+ }
2597
+ };
2598
+ MobileCRM.FetchXml.Attribute._constructAttributeParams = function (attribute) {
2599
+ if (attribute) {
2600
+ var attrParams = {};
2601
+ if (attribute.name) {
2602
+ attrParams.name = attribute.name;
2603
+ }
2604
+ if (attribute.aggregate) {
2605
+ attrParams.aggregate = attribute.aggregate;
2606
+ }
2607
+ if (typeof attribute.groupby != "undefined") {
2608
+ attrParams.groupby = attribute.groupby;
2609
+ }
2610
+ if (attribute.alias) {
2611
+ attrParams.alias = attribute.alias;
2612
+ }
2613
+ if (attribute.dategrouping) {
2614
+ attrParams.dategrouping = attribute.dategrouping;
2615
+ }
2616
+ return attrParams;
2617
+ } else {
2618
+ return undefined;
2619
+ }
2620
+ };
2621
+ MobileCRM.FetchXml.Entity._constructEntityParams = function (entity) {
2622
+ if (entity) {
2623
+ var entityParams = {};
2624
+ if (entity.name) {
2625
+ entityParams.name = entity.name;
2626
+ }
2627
+ entityParams.attributes = _normalizeArray(entity.attributes, MobileCRM.FetchXml.Attribute._constructAttributeParams);
2628
+ entityParams.order = _normalizeArray(entity.order, MobileCRM.FetchXml.Order._constructOrderParams);
2629
+ if (entity.filter) {
2630
+ entityParams.filter = MobileCRM.FetchXml.Filter._constructFilterParams(entity.filter);
2631
+ }
2632
+ entityParams.linkentities = _normalizeArray(entity.linkentities, MobileCRM.FetchXml.LinkEntity._constructLinkParams);
2633
+ return entityParams;
2634
+ } else {
2635
+ return undefined;
2636
+ }
2637
+ };
2638
+ MobileCRM.FetchXml.LinkEntity._constructLinkParams = function (linkEntity) {
2639
+ var linkParams = MobileCRM.FetchXml.Entity._constructEntityParams(linkEntity);
2640
+ if (linkParams) {
2641
+ if (linkEntity.alias) {
2642
+ linkParams.alias = linkEntity.alias;
2643
+ }
2644
+ if (linkEntity.from) {
2645
+ linkParams.from = linkEntity.from;
2646
+ }
2647
+ if (linkEntity.to) {
2648
+ linkParams.to = linkEntity.to;
2649
+ }
2650
+ if (linkEntity.linkType) {
2651
+ linkParams.linkType = linkEntity.linkType;
2652
+ }
2653
+ }
2654
+ return linkParams;
2655
+ };
2656
+ MobileCRM.FetchXml.Fetch.prototype._constructFetchParams = function () {
2657
+ var reqParams = { entity: MobileCRM.FetchXml.Entity._constructEntityParams(this.entity) };
2658
+ if (typeof this.page !== "undefined") {
2659
+ reqParams.page = this.page;
2660
+ }
2661
+ if (typeof this.count !== "undefined") {
2662
+ reqParams.count = this.count;
2663
+ }
2664
+ if (typeof this.aggregate !== "undefined") {
2665
+ reqParams.aggregate = this.aggregate;
2666
+ }
2667
+ if (this.distinct) {
2668
+ reqParams.distinct = this.distinct;
2669
+ }
2670
+ return reqParams;
2671
+ };
2530
2672
  MobileCRM.FetchXml.Fetch.prototype.execute = function (output, success, failed, scope) {
2531
2673
  /// <summary>Performs the asynchronous CRM Fetch request.</summary>
2532
2674
  /// <param name="output" type="String">A string defining the output format: Array, JSON, XML or DynamicEntities.</param>
2533
2675
  /// <param name="success" type="function(result)">A callback function for successful asynchronous result. The <b>result</b> argument will carry the objects array of type specified by <b>output</b> argument.</param>
2534
2676
  /// <param name="failed" type="function(error)">A callback function for command failure. The <b>error</b> argument will carry the error message.</param>
2535
2677
  /// <param name="scope" type="">A scope for calling the callbacks; set &quot;null&quot; to call the callbacks in global scope.</param>
2536
- var reqParams = JSON.stringify({
2537
- entity: this.entity,
2538
- resultformat: output,
2539
- page: this.page,
2540
- count: this.count,
2541
- aggregate: this.aggregate,
2542
- distinct: this.distinct,
2543
- });
2544
- MobileCRM.bridge.command("fetch", reqParams, success, failed, scope);
2678
+ var reqParams = this._constructFetchParams();
2679
+ if (output) {
2680
+ reqParams.resultformat = output;
2681
+ }
2682
+ MobileCRM.bridge.command("fetch", JSON.stringify(reqParams), success, failed, scope);
2545
2683
  };
2546
2684
  MobileCRM.FetchXml.Fetch.prototype.executeOnline = function (output, success, failed, scope) {
2547
2685
  /// <summary>[v8.0] Performs the online CRM Fetch request regardless of the app online/offline mode.</summary>
@@ -2605,13 +2743,13 @@
2605
2743
  /// <param name="success" type="function(String)">A callback function for successful asynchronous result. The <b>result</b> argument will carry the XML representation of the Fetch object.</param>
2606
2744
  /// <param name="failed" type="function(error)">A callback function for command failure. The <b>error</b> argument will carry the error message.</param>
2607
2745
  /// <param name="scope" type="">A scope for calling the callbacks; set &quot;null&quot; to call the callbacks in global scope.</param>
2608
- var reqParams = JSON.stringify({ entity: this.entity, page: this.page, count: this.count, aggregate: this.aggregate, distinct: this.distinct });
2746
+ var reqParams = this._constructFetchParams();
2609
2747
  MobileCRM.bridge.command("fetchToXml", reqParams, success, failed, scope);
2610
2748
  };
2611
2749
  MobileCRM.FetchXml.Fetch.prototype.serializeToXmlAsync = function () {
2612
2750
  /// <summary>[v10.0] Serializes the Fetch object to XML.</summary>
2613
2751
  /// <returns type="Promise&lt;string&gt;">A Promise object which will be resolved with the XML representation of this Fetch object.</returns>
2614
- var reqParams = JSON.stringify({ entity: this.entity, page: this.page, count: this.count, aggregate: this.aggregate, distinct: this.distinct });
2752
+ var reqParams = this._constructFetchParams();
2615
2753
  return MobileCRM.bridge.invokeCommandPromise("fetchToXml", reqParams);
2616
2754
  };
2617
2755
  // MobileCRM.FetchXml.Entity