copper-sdk 0.6.3 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +3 -0
- package/README.md +7 -4
- package/dist/copper-sdk.js +23 -22
- package/dist/copper-sdk.min.js +1 -1
- package/dist/defer.d.ts +1 -1
- package/dist/index.d.ts +2 -2
- package/es/copper-sdk.js +21 -20
- package/es/defer.d.ts +1 -1
- package/es/index.d.ts +2 -2
- package/lib/copper-sdk.js +21 -20
- package/lib/defer.d.ts +1 -1
- package/lib/index.d.ts +2 -2
- package/package.json +16 -17
package/CHANGELOG.md
ADDED
package/README.md
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
Copper App SDK
|
2
2
|
====================
|
3
3
|
|
4
|
-
[![Travis branch](https://img.shields.io/travis/ProsperWorks/copper-sdk/master.svg?style=flat-square)](https://travis-ci.org/ProsperWorks/copper-sdk)
|
5
4
|
[![npm](https://img.shields.io/npm/v/copper-sdk.svg?style=flat-square)](https://www.npmjs.com/package/copper-sdk)
|
6
|
-
|
7
|
-
[![Maintainability](https://api.codeclimate.com/v1/badges/d8ef6bf3d4669616c465/maintainability)](https://codeclimate.com/github/ProsperWorks/copper-sdk/maintainability)
|
5
|
+
|
8
6
|
|
9
7
|
The javascript SDK provides client-side functionalities for adding embedded app to the Copper web client.
|
10
8
|
|
@@ -51,6 +49,9 @@ https://docs.copper.com/copper-sdk
|
|
51
49
|
|
52
50
|
## Development
|
53
51
|
### Prerequisites
|
52
|
+
|
53
|
+
We recommend Node 10 or newer.
|
54
|
+
|
54
55
|
Confirm all packages have been installed before development. Yarn will be used for this particular project.
|
55
56
|
|
56
57
|
```bash
|
@@ -60,8 +61,10 @@ yarn
|
|
60
61
|
### Developing SDK
|
61
62
|
```bash
|
62
63
|
## watch changes
|
64
|
+
yarn dev
|
65
|
+
|
66
|
+
## or run separately
|
63
67
|
yarn dev:es
|
64
|
-
# or
|
65
68
|
yarn dev:commonjs
|
66
69
|
|
67
70
|
## build
|
package/dist/copper-sdk.js
CHANGED
@@ -2,21 +2,21 @@
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
3
3
|
typeof define === 'function' && define.amd ? define(factory) :
|
4
4
|
(global = global || self, global.Copper = factory());
|
5
|
-
}(this, function () { 'use strict';
|
5
|
+
}(this, (function () { 'use strict';
|
6
6
|
|
7
7
|
/*! *****************************************************************************
|
8
|
-
Copyright (c) Microsoft Corporation.
|
9
|
-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
10
|
-
this file except in compliance with the License. You may obtain a copy of the
|
11
|
-
License at http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
Copyright (c) Microsoft Corporation.
|
12
9
|
|
13
|
-
|
14
|
-
|
15
|
-
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
16
|
-
MERCHANTABLITY OR NON-INFRINGEMENT.
|
10
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
11
|
+
purpose with or without fee is hereby granted.
|
17
12
|
|
18
|
-
|
19
|
-
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
14
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
15
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
16
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
17
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
18
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
19
|
+
PERFORMANCE OF THIS SOFTWARE.
|
20
20
|
***************************************************************************** */
|
21
21
|
|
22
22
|
var __assign = function() {
|
@@ -31,10 +31,11 @@
|
|
31
31
|
};
|
32
32
|
|
33
33
|
function __awaiter(thisArg, _arguments, P, generator) {
|
34
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
34
35
|
return new (P || (P = Promise))(function (resolve, reject) {
|
35
36
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
36
37
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
37
|
-
function step(result) { result.done ? resolve(result.value) :
|
38
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
38
39
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
39
40
|
});
|
40
41
|
}
|
@@ -67,7 +68,7 @@
|
|
67
68
|
}
|
68
69
|
}
|
69
70
|
|
70
|
-
var version = "0.
|
71
|
+
var version = "0.7.0";
|
71
72
|
|
72
73
|
var ENTITY_PATH_MAP = {
|
73
74
|
lead: 'leads',
|
@@ -168,7 +169,7 @@
|
|
168
169
|
get: function () {
|
169
170
|
return this._promise;
|
170
171
|
},
|
171
|
-
enumerable:
|
172
|
+
enumerable: false,
|
172
173
|
configurable: true
|
173
174
|
});
|
174
175
|
return Deferred;
|
@@ -339,14 +340,14 @@
|
|
339
340
|
get: function () {
|
340
341
|
return version;
|
341
342
|
},
|
342
|
-
enumerable:
|
343
|
+
enumerable: false,
|
343
344
|
configurable: true
|
344
345
|
});
|
345
346
|
Object.defineProperty(Copper.prototype, "win", {
|
346
347
|
get: function () {
|
347
348
|
return this._win;
|
348
349
|
},
|
349
|
-
enumerable:
|
350
|
+
enumerable: false,
|
350
351
|
configurable: true
|
351
352
|
});
|
352
353
|
Copper.prototype.getContext = function () {
|
@@ -565,7 +566,7 @@
|
|
565
566
|
};
|
566
567
|
Copper.prototype._postMessage = function (type, message) {
|
567
568
|
if (message === void 0) { message = {}; }
|
568
|
-
this.win.top.postMessage(__assign({}, message, {
|
569
|
+
this.win.top.postMessage(__assign(__assign({}, message), {
|
569
570
|
// as a credential to the parent frame, so parent frame can recoganize the origin
|
570
571
|
instanceId: this.instanceId,
|
571
572
|
// tell parent frame current sdk version
|
@@ -644,14 +645,14 @@
|
|
644
645
|
executor();
|
645
646
|
return deferred.promise;
|
646
647
|
};
|
647
|
-
Copper.prototype._deferredPost = function (name
|
648
|
+
Copper.prototype._deferredPost = function (name, data) {
|
648
649
|
var _this = this;
|
649
|
-
return this._createDeferredMethod(name
|
650
|
+
return this._createDeferredMethod(name, function () {
|
650
651
|
if (data) {
|
651
|
-
_this._postMessage(name
|
652
|
+
_this._postMessage(name, data);
|
652
653
|
}
|
653
654
|
else {
|
654
|
-
_this._postMessage(name
|
655
|
+
_this._postMessage(name);
|
655
656
|
}
|
656
657
|
});
|
657
658
|
};
|
@@ -667,4 +668,4 @@
|
|
667
668
|
|
668
669
|
return Copper;
|
669
670
|
|
670
|
-
}));
|
671
|
+
})));
|
package/dist/copper-sdk.min.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).Copper=e()}(this,function(){"use strict";var n=function(){return(n=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}).apply(this,arguments)};function e(o,s,a,u){return new(a||(a=Promise))(function(t,e){function n(t){try{r(u.next(t))}catch(t){e(t)}}function i(t){try{r(u.throw(t))}catch(t){e(t)}}function r(e){e.done?t(e.value):new a(function(t){t(e.value)}).then(n,i)}r((u=u.apply(o,s||[])).next())})}function f(n,i){var r,o,s,t,a={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]};return t={next:e(0),throw:e(1),return:e(2)},"function"==typeof Symbol&&(t[Symbol.iterator]=function(){return this}),t;function e(e){return function(t){return function(e){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,o&&(s=2&e[0]?o.return:e[0]?o.throw||((s=o.return)&&s.call(o),0):o.next)&&!(s=s.call(o,e[1])).done)return s;switch(o=0,s&&(e=[2&e[0],s.value]),e[0]){case 0:case 1:s=e;break;case 4:return a.label++,{value:e[1],done:!1};case 5:a.label++,o=e[1],e=[0];continue;case 7:e=a.ops.pop(),a.trys.pop();continue;default:if(!(s=0<(s=a.trys).length&&s[s.length-1])&&(6===e[0]||2===e[0])){a=0;continue}if(3===e[0]&&(!s||s[0]<e[1]&&e[1]<s[3])){a.label=e[1];break}if(6===e[0]&&a.label<s[1]){a.label=s[1],s=e;break}if(s&&a.label<s[2]){a.label=s[2],a.ops.push(e);break}s[2]&&a.ops.pop(),a.trys.pop();continue}e=i.call(n,a)}catch(t){e=[6,t],o=0}finally{r=s=0}if(5&e[0])throw e[1];return{value:e[0]?e[1]:void 0,done:!0}}([e,t])}}}var h,t,r="0.6.3",l={lead:"leads",person:"people",company:"companies",opportunity:"opportunities",task:"tasks",project:"projects"};(t=h||(h={})).ActivityLog="ActivityLog",t.ListView="ListView",t.Related="Related";var o=function(){function t(){var n=this;this.resolve=function(t){n._resolve(t)},this.reject=function(t){n._reject(t)},this._promise=new Promise(function(t,e){n._resolve=t,n._reject=e})}return Object.defineProperty(t.prototype,"promise",{get:function(){return this._promise},enumerable:!0,configurable:!0}),t}();function s(t,e){void 0===e&&(e=""),e||(e=window.location.href),t=t.replace(/[[]]/g,"\\$&");var n=RegExp("[?&]"+t+"(=([^&#]*)|&|#|$)").exec(e);return n&&n[2]?decodeURIComponent(n[2].replace(/\+/g," ")):""}function a(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];console.log.apply(console,t)}function u(t,e){t[e]||(t[e]=[])}function y(t,e){void 0===e&&(e=1e3),setTimeout(function(){t()},e)}var c=function(){function t(t,e,n,i){void 0===n&&(n=[]);var r=this._getEntityDataDefinition(e,n);r.type={enumerable:!1,writable:!1,value:t},r._onSave={enumerable:!1,value:i},Object.defineProperties(this,r)}return t.prototype.save=function(){return e(this,void 0,void 0,function(){return f(this,function(t){switch(t.label){case 0:return this._onSave?[4,this._onSave(this)]:[3,2];case 1:return[2,t.sent()];case 2:return[2,null]}})})},t.prototype.toJSON=function(){return JSON.stringify(this.toObject())},t.prototype.toObject=function(){var e=this,n={};return Object.keys(this).forEach(function(t){n[t]=e[t]}),n},t.prototype._getEntityDataDefinition=function(e,n){void 0===n&&(n=[]);var i={};return Object.keys(e).forEach(function(t){i[t]=-1==n.indexOf(t)?{get:function(){return e[t]},set:function(){a("property "+t+" is read only")},enumerable:!0}:{value:e[t],writable:!0,enumerable:!0}}),i},t}();return function(){function i(t,e,n,i){if(void 0===i&&(i=window),this.parentOrigin=t,this.instanceId=e,this.options=n,this._win=i,this.deferredQueues={},this.events={},!this.parentOrigin||!this.instanceId)throw new TypeError("parentOrigin or instanceId is empty");this._listenMessage(),this._subscribeContextUpdated(),this._postMessage("init")}return i.init=function(){var t=s("origin"),e=s("instanceId"),n={isGlobal:"1"===s("isGlobal")};if(!("undefined"==typeof window?(a("Copper can only run in browser environment"),0):(window.top===window&&a("Copper should be inside an iframe, otherwise it might not work as expected."),1)))throw Error("Environment checking does not pass.");return new i(t,e,n)},Object.defineProperty(i,"version",{get:function(){return r},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"win",{get:function(){return this._win},enumerable:!0,configurable:!0}),i.prototype.getContext=function(){return e(this,void 0,void 0,function(){var e;return f(this,function(t){switch(t.label){case 0:return[4,this._deferredPost("getContext")];case 1:return e=t.sent(),[2,this._createContextModel(e)]}})})},i.prototype.getUserInfo=function(){return e(this,void 0,void 0,function(){return f(this,function(t){return[2,this._deferredPost("getUserInfo")]})})},i.prototype.getRouteInfo=function(){return e(this,void 0,void 0,function(){return f(this,function(t){return[2,this._deferredPost("getRouteInfo")]})})},i.prototype.saveContext=function(n){return e(this,void 0,void 0,function(){var e;return f(this,function(t){switch(t.label){case 0:return[4,this._deferredPost("saveContext",{data:{entityType:n.type,entityData:n.toObject()}})];case 1:return e=t.sent(),[2,this._createContextModel(e)]}})})},i.prototype.setAppUI=function(t){this._postMessage("setUI",{data:t})},i.prototype.showModal=function(t){void 0===t&&(t={}),this._postMessage("showModal",{params:t})},i.prototype.closeModal=function(){this._postMessage("closeModal")},i.prototype.publishMessage=function(t,e,n){void 0===n&&(n={}),this._postMessage("publishMessage",{target:e,data:{type:t,msg:n}})},i.prototype.logActivity=function(s,a,u,c){return void 0===c&&(c=0),e(this,void 0,void 0,function(){var o;return f(this,function(t){switch(t.label){case 0:return[4,this._getCachedContext()];case 1:return o=t.sent(),r={parent:{type:(e=o).type,id:e.id},type:{category:"user",id:(n={activityType:s,details:a,activityDate:u}).activityType},details:n.details},(i=n.activityDate)&&(r.activity_date=i),[2,this._action({url:"/v1/activities",method:"POST",data:r,target:{name:h.ActivityLog}},c)]}var e,n,i,r})})},i.prototype.createEntity=function(c,p,d){return void 0===d&&(d=0),e(this,void 0,void 0,function(){var r,o,s,a,u=this;return f(this,function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,this._getCachedContext()];case 1:return r=t.sent(),[3,3];case 2:return t.sent(),r={},[3,3];case 3:return s=(o={url:"/v1/"+l[n=(e={entityType:c,data:p}).entityType],method:"POST",data:i=e.data,target:n===r.type?{name:h.ListView,data:{entityType:n,entityData:i}}:null}).target,[4,this.api(o.url,{method:o.method,body:JSON.stringify(o.data)})];case 4:return a=t.sent(),s&&s.data&&(s.data.entityData=a,y(function(){u.refreshUI(s)},d)),[2,a]}var e,n,i})})},i.prototype.relateEntity=function(a,u,c,p){return void 0===p&&(p=0),e(this,void 0,void 0,function(){var s;return f(this,function(t){switch(t.label){case 0:return[4,this._getCachedContext()];case 1:return s=t.sent(),e=s,[2,this._action({url:"/v1/"+l[i=(n={entityType:a,entityId:parseInt(u,10),data:c}).entityType]+"/"+(r=n.entityId)+"/related",method:"POST",data:{resource:o=n.data},target:i===e.type&&r===e.id?{name:h.Related,data:o}:null},p)]}var e,n,i,r,o})})},i.prototype.refreshUI=function(t){this._postMessage("refreshUI",{target:t})},i.prototype.on=function(t,e){u(this.events,t),this.events[t].push(e)},i.prototype.trigger=function(t,e){var n=this;this.events[t]&&this.events[t].forEach(function(t){t.call(n,e)})},i.prototype.api=function(t,e){if(!t)return Promise.reject({id:"sdk-api",version:i.version,detail:"url cannot be empty"});if(e&&e.body)try{JSON.parse(e.body)}catch(t){return Promise.reject({id:"sdk-api",version:i.version,detail:"body must be a valid JSON string"})}return this._deferredPost("api",{url:t,options:e})},i.prototype.navigateToEntityDetail=function(t,e){return this._deferredPost("navigateToEntityDetail",{entityType:t,entityId:e})},i.prototype.getSelectedRecords=function(t){var e=void 0===t?{}:t,n=e.pageSize,i=e.pageNumber;return this._deferredPost("getSelectedRecords",{pageSize:void 0===n?100:n,pageNumber:void 0===i?0:i})},i.prototype.getConfig=function(){return this._deferredPost("getConfig")},i.prototype._getCachedContext=function(){return e(this,void 0,void 0,function(){return f(this,function(t){switch(t.label){case 0:return this._context?[2,this._context]:[4,this.getContext()];case 1:return[2,t.sent().context]}})})},i.prototype._postMessage=function(t,e){void 0===e&&(e={}),this.win.top.postMessage(n({},e,{instanceId:this.instanceId,version:r,type:t}),this.parentOrigin)},i.prototype._listenMessage=function(){var e=this;this.win.addEventListener("message",function(t){e._isOriginValid(t)&&(e._resolveDeferred(t.data.type,t.data),t.data.type&&e.trigger(t.data.type,t.data.msg||t.data.data))},!1)},i.prototype._isOriginValid=function(t){return t.origin===this.parentOrigin},i.prototype._enqueueDeferred=function(t,e){u(this.deferredQueues,t),this.deferredQueues[t].push(e)},i.prototype._resolveDeferred=function(t,e){if(this.deferredQueues[t]){var n=this.deferredQueues[t].shift();if(n){if(e.error)return n.reject(e.error);n.resolve(e.data)}}},i.prototype._createContextModel=function(t){var e=t.entityType,n=new c(e,t.entityData,t.editableFields,this.saveContext.bind(this));return{type:e,context:this._context=n}},i.prototype._action=function(t,i){var r=t.url,o=t.method,s=t.data,a=t.target;return e(this,void 0,void 0,function(){var e,n=this;return f(this,function(t){switch(t.label){case 0:return[4,this.api(r,{method:o,body:JSON.stringify(s)})];case 1:return e=t.sent(),a&&y(function(){n.refreshUI(a)},i),[2,e]}})})},i.prototype._createDeferredMethod=function(t,e){var n=new o;return this._enqueueDeferred(t,n),e(),n.promise},i.prototype._deferredPost=function(t,e){var n=this;return this._createDeferredMethod(t,function(){e?n._postMessage(t,e):n._postMessage(t)})},i.prototype._subscribeContextUpdated=function(){var t=this;this.on("contextUpdated",function(){t._context=null})},i}()});
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).Copper=e()}(this,function(){"use strict";var n=function(){return(n=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}).apply(this,arguments)};function e(t,s,a,u){return new(a=a||Promise)(function(n,e){function i(t){try{o(u.next(t))}catch(t){e(t)}}function r(t){try{o(u.throw(t))}catch(t){e(t)}}function o(t){var e;t.done?n(t.value):((e=t.value)instanceof a?e:new a(function(t){t(e)})).then(i,r)}o((u=u.apply(t,s||[])).next())})}function d(i,r){var o,s,a,u={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]},t={next:e(0),throw:e(1),return:e(2)};return"function"==typeof Symbol&&(t[Symbol.iterator]=function(){return this}),t;function e(n){return function(t){var e=[n,t];if(o)throw new TypeError("Generator is already executing.");for(;u;)try{if(o=1,s&&(a=2&e[0]?s.return:e[0]?s.throw||((a=s.return)&&a.call(s),0):s.next)&&!(a=a.call(s,e[1])).done)return a;switch(s=0,(e=a?[2&e[0],a.value]:e)[0]){case 0:case 1:a=e;break;case 4:return u.label++,{value:e[1],done:!1};case 5:u.label++,s=e[1],e=[0];continue;case 7:e=u.ops.pop(),u.trys.pop();continue;default:if(!(a=0<(a=u.trys).length&&a[a.length-1])&&(6===e[0]||2===e[0])){u=0;continue}if(3===e[0]&&(!a||a[0]<e[1]&&e[1]<a[3]))u.label=e[1];else if(6===e[0]&&u.label<a[1])u.label=a[1],a=e;else{if(!a||a[2]<=u.label){a[2]&&u.ops.pop(),u.trys.pop();continue}u.label=a[2],u.ops.push(e)}}e=r.call(i,u)}catch(t){e=[6,t],s=0}finally{o=a=0}if(5&e[0])throw e[1];return{value:e[0]?e[1]:void 0,done:!0}}}}var f,t,i="0.7.0",h={lead:"leads",person:"people",company:"companies",opportunity:"opportunities",task:"tasks",project:"projects"};(t=f=f||{}).ActivityLog="ActivityLog",t.ListView="ListView";Object.defineProperty(o.prototype,"promise",{get:function(){return this._promise},enumerable:!(t.Related="Related"),configurable:!0});var r=o;function o(){var n=this;this.resolve=function(t){n._resolve(t)},this.reject=function(t){n._reject(t)},this._promise=new Promise(function(t,e){n._resolve=t,n._reject=e})}function s(t,e){e=(e=void 0===e?"":e)||window.location.href,t=t.replace(/[[]]/g,"\\$&");t=RegExp("[?&]"+t+"(=([^&#]*)|&|#|$)").exec(e);return t&&t[2]?decodeURIComponent(t[2].replace(/\+/g," ")):""}function a(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];console.log.apply(console,t)}function u(t,e){t[e]||(t[e]=[])}function l(t,e){setTimeout(function(){t()},e=void 0===e?1e3:e)}p.prototype.save=function(){return e(this,void 0,void 0,function(){return d(this,function(t){switch(t.label){case 0:return this._onSave?[4,this._onSave(this)]:[3,2];case 1:return[2,t.sent()];case 2:return[2,null]}})})},p.prototype.toJSON=function(){return JSON.stringify(this.toObject())},p.prototype.toObject=function(){var e=this,n={};return Object.keys(this).forEach(function(t){n[t]=e[t]}),n},p.prototype._getEntityDataDefinition=function(e,n){void 0===n&&(n=[]);var i={};return Object.keys(e).forEach(function(t){~n.indexOf(t)?i[t]={value:e[t],writable:!0,enumerable:!0}:i[t]={get:function(){return e[t]},set:function(){a("property "+t+" is read only")},enumerable:!0}}),i};var c=p;function p(t,e,n,i){e=this._getEntityDataDefinition(e,n=void 0===n?[]:n);e.type={enumerable:!1,writable:!1,value:t},e._onSave={enumerable:!1,value:i},Object.defineProperties(this,e)}function y(t,e,n,i){if(void 0===i&&(i=window),this.parentOrigin=t,this.instanceId=e,this.options=n,this._win=i,this.deferredQueues={},this.events={},!this.parentOrigin||!this.instanceId)throw new TypeError("parentOrigin or instanceId is empty");this._listenMessage(),this._subscribeContextUpdated(),this._postMessage("init")}return y.init=function(){var t=s("origin"),e=s("instanceId"),n={isGlobal:"1"===s("isGlobal")};if(function(){if("undefined"!=typeof window)return window.top===window&&a("Copper should be inside an iframe, otherwise it might not work as expected."),1;a("Copper can only run in browser environment")}())return new y(t,e,n);throw Error("Environment checking does not pass.")},Object.defineProperty(y,"version",{get:function(){return i},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"win",{get:function(){return this._win},enumerable:!1,configurable:!0}),y.prototype.getContext=function(){return e(this,void 0,void 0,function(){var e;return d(this,function(t){switch(t.label){case 0:return[4,this._deferredPost("getContext")];case 1:return e=t.sent(),[2,this._createContextModel(e)]}})})},y.prototype.getUserInfo=function(){return e(this,void 0,void 0,function(){return d(this,function(t){return[2,this._deferredPost("getUserInfo")]})})},y.prototype.getRouteInfo=function(){return e(this,void 0,void 0,function(){return d(this,function(t){return[2,this._deferredPost("getRouteInfo")]})})},y.prototype.saveContext=function(n){return e(this,void 0,void 0,function(){var e;return d(this,function(t){switch(t.label){case 0:return[4,this._deferredPost("saveContext",{data:{entityType:n.type,entityData:n.toObject()}})];case 1:return e=t.sent(),[2,this._createContextModel(e)]}})})},y.prototype.setAppUI=function(t){this._postMessage("setUI",{data:t})},y.prototype.showModal=function(t){this._postMessage("showModal",{params:t=void 0===t?{}:t})},y.prototype.closeModal=function(){this._postMessage("closeModal")},y.prototype.publishMessage=function(t,e,n){this._postMessage("publishMessage",{target:e,data:{type:t,msg:n=void 0===n?{}:n}})},y.prototype.logActivity=function(r,o,s,a){return void 0===a&&(a=0),e(this,void 0,void 0,function(){var i;return d(this,function(t){switch(t.label){case 0:return[4,this._getCachedContext()];case 1:return i=t.sent(),e={parent:{type:(e=i).type,id:e.id},type:{category:"user",id:(n={activityType:r,details:o,activityDate:s}).activityType},details:n.details},(n=n.activityDate)&&(e.activity_date=n),i={url:"/v1/activities",method:"POST",data:e,target:{name:f.ActivityLog}},[2,this._action(i,a)]}var e,n})})},y.prototype.createEntity=function(u,c,p){return void 0===p&&(p=0),e(this,void 0,void 0,function(){var r,o,s,a=this;return d(this,function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,this._getCachedContext()];case 1:return r=t.sent(),[3,3];case 2:return t.sent(),r={},[3,3];case 3:return e=r,i=(n={entityType:u,data:c}).entityType,n=n.data,o=(s={url:"/v1/"+h[i],method:"POST",data:n,target:i===e.type?{name:f.ListView,data:{entityType:i,entityData:n}}:null}).target,[4,this.api(s.url,{method:s.method,body:JSON.stringify(s.data)})];case 4:return s=t.sent(),o&&o.data&&(o.data.entityData=s,l(function(){a.refreshUI(o)},p)),[2,s]}var e,n,i})})},y.prototype.relateEntity=function(o,s,a,u){return void 0===u&&(u=0),e(this,void 0,void 0,function(){var r;return d(this,function(t){switch(t.label){case 0:return[4,this._getCachedContext()];case 1:return r=t.sent(),r={url:"/v1/"+h[n=(e={entityType:o,entityId:parseInt(s,10),data:a}).entityType]+"/"+(i=e.entityId)+"/related",method:"POST",data:{resource:e=e.data},target:n===(n=r).type&&i===n.id?{name:f.Related,data:e}:null},[2,this._action(r,u)]}var e,n,i})})},y.prototype.refreshUI=function(t){this._postMessage("refreshUI",{target:t})},y.prototype.on=function(t,e){u(this.events,t),this.events[t].push(e)},y.prototype.trigger=function(t,e){var n=this;this.events[t]&&this.events[t].forEach(function(t){t.call(n,e)})},y.prototype.api=function(t,e){if(!t)return Promise.reject({id:"sdk-api",version:y.version,detail:"url cannot be empty"});if(e&&e.body)try{JSON.parse(e.body)}catch(t){return Promise.reject({id:"sdk-api",version:y.version,detail:"body must be a valid JSON string"})}return this._deferredPost("api",{url:t,options:e})},y.prototype.navigateToEntityDetail=function(t,e){return this._deferredPost("navigateToEntityDetail",{entityType:t,entityId:e})},y.prototype.getSelectedRecords=function(t){var t=void 0===t?{}:t,e=t.pageSize,t=t.pageNumber;return this._deferredPost("getSelectedRecords",{pageSize:void 0===e?100:e,pageNumber:void 0===t?0:t})},y.prototype.getConfig=function(){return this._deferredPost("getConfig")},y.prototype._getCachedContext=function(){return e(this,void 0,void 0,function(){return d(this,function(t){switch(t.label){case 0:return this._context?[2,this._context]:[4,this.getContext()];case 1:return[2,t.sent().context]}})})},y.prototype._postMessage=function(t,e){this.win.top.postMessage(n(n({},e=void 0===e?{}:e),{instanceId:this.instanceId,version:i,type:t}),this.parentOrigin)},y.prototype._listenMessage=function(){var e=this;this.win.addEventListener("message",function(t){e._isOriginValid(t)&&(e._resolveDeferred(t.data.type,t.data),t.data.type)&&e.trigger(t.data.type,t.data.msg||t.data.data)},!1)},y.prototype._isOriginValid=function(t){return t.origin===this.parentOrigin},y.prototype._enqueueDeferred=function(t,e){u(this.deferredQueues,t),this.deferredQueues[t].push(e)},y.prototype._resolveDeferred=function(t,e){if(this.deferredQueues[t]){t=this.deferredQueues[t].shift();if(t){if(e.error)return t.reject(e.error);t.resolve(e.data)}}},y.prototype._createContextModel=function(t){var e=t.entityType,t=new c(e,t.entityData,t.editableFields,this.saveContext.bind(this));return{type:e,context:this._context=t}},y.prototype._action=function(t,i){var r=t.url,o=t.method,s=t.data,a=t.target;return e(this,void 0,void 0,function(){var e,n=this;return d(this,function(t){switch(t.label){case 0:return[4,this.api(r,{method:o,body:JSON.stringify(s)})];case 1:return e=t.sent(),a&&l(function(){n.refreshUI(a)},i),[2,e]}})})},y.prototype._createDeferredMethod=function(t,e){var n=new r;return this._enqueueDeferred(t,n),e(),n.promise},y.prototype._deferredPost=function(t,e){var n=this;return this._createDeferredMethod(t,function(){e?n._postMessage(t,e):n._postMessage(t)})},y.prototype._subscribeContextUpdated=function(){this.on("contextUpdated",function(){0})},y});
|
package/dist/defer.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
@@ -7,7 +7,7 @@ export default class Copper {
|
|
7
7
|
private options;
|
8
8
|
private _win;
|
9
9
|
static init(): Copper;
|
10
|
-
static
|
10
|
+
static get version(): string;
|
11
11
|
/**
|
12
12
|
* store deferred queues by name
|
13
13
|
*/
|
@@ -23,7 +23,7 @@ export default class Copper {
|
|
23
23
|
* @memberof Copper
|
24
24
|
*/
|
25
25
|
constructor(parentOrigin: string, instanceId: string, options: ISdkInitOptions, _win?: any);
|
26
|
-
|
26
|
+
get win(): Window;
|
27
27
|
getContext(): Promise<IContextData>;
|
28
28
|
getUserInfo(): Promise<any>;
|
29
29
|
getRouteInfo(): Promise<any>;
|
package/es/copper-sdk.js
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
/*! *****************************************************************************
|
2
|
-
Copyright (c) Microsoft Corporation.
|
3
|
-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
4
|
-
this file except in compliance with the License. You may obtain a copy of the
|
5
|
-
License at http://www.apache.org/licenses/LICENSE-2.0
|
2
|
+
Copyright (c) Microsoft Corporation.
|
6
3
|
|
7
|
-
|
8
|
-
|
9
|
-
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
10
|
-
MERCHANTABLITY OR NON-INFRINGEMENT.
|
4
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
5
|
+
purpose with or without fee is hereby granted.
|
11
6
|
|
12
|
-
|
13
|
-
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
8
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
9
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
10
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
11
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
12
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
13
|
+
PERFORMANCE OF THIS SOFTWARE.
|
14
14
|
***************************************************************************** */
|
15
15
|
|
16
16
|
var __assign = function() {
|
@@ -25,10 +25,11 @@ var __assign = function() {
|
|
25
25
|
};
|
26
26
|
|
27
27
|
function __awaiter(thisArg, _arguments, P, generator) {
|
28
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
28
29
|
return new (P || (P = Promise))(function (resolve, reject) {
|
29
30
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
30
31
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
31
|
-
function step(result) { result.done ? resolve(result.value) :
|
32
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
32
33
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
33
34
|
});
|
34
35
|
}
|
@@ -61,7 +62,7 @@ function __generator(thisArg, body) {
|
|
61
62
|
}
|
62
63
|
}
|
63
64
|
|
64
|
-
var version = "0.
|
65
|
+
var version = "0.7.0";
|
65
66
|
|
66
67
|
var ENTITY_PATH_MAP = {
|
67
68
|
lead: 'leads',
|
@@ -162,7 +163,7 @@ var Deferred = /** @class */ (function () {
|
|
162
163
|
get: function () {
|
163
164
|
return this._promise;
|
164
165
|
},
|
165
|
-
enumerable:
|
166
|
+
enumerable: false,
|
166
167
|
configurable: true
|
167
168
|
});
|
168
169
|
return Deferred;
|
@@ -333,14 +334,14 @@ var Copper = /** @class */ (function () {
|
|
333
334
|
get: function () {
|
334
335
|
return version;
|
335
336
|
},
|
336
|
-
enumerable:
|
337
|
+
enumerable: false,
|
337
338
|
configurable: true
|
338
339
|
});
|
339
340
|
Object.defineProperty(Copper.prototype, "win", {
|
340
341
|
get: function () {
|
341
342
|
return this._win;
|
342
343
|
},
|
343
|
-
enumerable:
|
344
|
+
enumerable: false,
|
344
345
|
configurable: true
|
345
346
|
});
|
346
347
|
Copper.prototype.getContext = function () {
|
@@ -559,7 +560,7 @@ var Copper = /** @class */ (function () {
|
|
559
560
|
};
|
560
561
|
Copper.prototype._postMessage = function (type, message) {
|
561
562
|
if (message === void 0) { message = {}; }
|
562
|
-
this.win.top.postMessage(__assign({}, message, {
|
563
|
+
this.win.top.postMessage(__assign(__assign({}, message), {
|
563
564
|
// as a credential to the parent frame, so parent frame can recoganize the origin
|
564
565
|
instanceId: this.instanceId,
|
565
566
|
// tell parent frame current sdk version
|
@@ -638,14 +639,14 @@ var Copper = /** @class */ (function () {
|
|
638
639
|
executor();
|
639
640
|
return deferred.promise;
|
640
641
|
};
|
641
|
-
Copper.prototype._deferredPost = function (name
|
642
|
+
Copper.prototype._deferredPost = function (name, data) {
|
642
643
|
var _this = this;
|
643
|
-
return this._createDeferredMethod(name
|
644
|
+
return this._createDeferredMethod(name, function () {
|
644
645
|
if (data) {
|
645
|
-
_this._postMessage(name
|
646
|
+
_this._postMessage(name, data);
|
646
647
|
}
|
647
648
|
else {
|
648
|
-
_this._postMessage(name
|
649
|
+
_this._postMessage(name);
|
649
650
|
}
|
650
651
|
});
|
651
652
|
};
|
package/es/defer.d.ts
CHANGED
package/es/index.d.ts
CHANGED
@@ -7,7 +7,7 @@ export default class Copper {
|
|
7
7
|
private options;
|
8
8
|
private _win;
|
9
9
|
static init(): Copper;
|
10
|
-
static
|
10
|
+
static get version(): string;
|
11
11
|
/**
|
12
12
|
* store deferred queues by name
|
13
13
|
*/
|
@@ -23,7 +23,7 @@ export default class Copper {
|
|
23
23
|
* @memberof Copper
|
24
24
|
*/
|
25
25
|
constructor(parentOrigin: string, instanceId: string, options: ISdkInitOptions, _win?: any);
|
26
|
-
|
26
|
+
get win(): Window;
|
27
27
|
getContext(): Promise<IContextData>;
|
28
28
|
getUserInfo(): Promise<any>;
|
29
29
|
getRouteInfo(): Promise<any>;
|
package/lib/copper-sdk.js
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
3
|
/*! *****************************************************************************
|
4
|
-
Copyright (c) Microsoft Corporation.
|
5
|
-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
6
|
-
this file except in compliance with the License. You may obtain a copy of the
|
7
|
-
License at http://www.apache.org/licenses/LICENSE-2.0
|
4
|
+
Copyright (c) Microsoft Corporation.
|
8
5
|
|
9
|
-
|
10
|
-
|
11
|
-
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
12
|
-
MERCHANTABLITY OR NON-INFRINGEMENT.
|
6
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
7
|
+
purpose with or without fee is hereby granted.
|
13
8
|
|
14
|
-
|
15
|
-
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
10
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
11
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
12
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
13
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
14
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
15
|
+
PERFORMANCE OF THIS SOFTWARE.
|
16
16
|
***************************************************************************** */
|
17
17
|
|
18
18
|
var __assign = function() {
|
@@ -27,10 +27,11 @@ var __assign = function() {
|
|
27
27
|
};
|
28
28
|
|
29
29
|
function __awaiter(thisArg, _arguments, P, generator) {
|
30
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
30
31
|
return new (P || (P = Promise))(function (resolve, reject) {
|
31
32
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
32
33
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
33
|
-
function step(result) { result.done ? resolve(result.value) :
|
34
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
34
35
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
35
36
|
});
|
36
37
|
}
|
@@ -63,7 +64,7 @@ function __generator(thisArg, body) {
|
|
63
64
|
}
|
64
65
|
}
|
65
66
|
|
66
|
-
var version = "0.
|
67
|
+
var version = "0.7.0";
|
67
68
|
|
68
69
|
var ENTITY_PATH_MAP = {
|
69
70
|
lead: 'leads',
|
@@ -164,7 +165,7 @@ var Deferred = /** @class */ (function () {
|
|
164
165
|
get: function () {
|
165
166
|
return this._promise;
|
166
167
|
},
|
167
|
-
enumerable:
|
168
|
+
enumerable: false,
|
168
169
|
configurable: true
|
169
170
|
});
|
170
171
|
return Deferred;
|
@@ -335,14 +336,14 @@ var Copper = /** @class */ (function () {
|
|
335
336
|
get: function () {
|
336
337
|
return version;
|
337
338
|
},
|
338
|
-
enumerable:
|
339
|
+
enumerable: false,
|
339
340
|
configurable: true
|
340
341
|
});
|
341
342
|
Object.defineProperty(Copper.prototype, "win", {
|
342
343
|
get: function () {
|
343
344
|
return this._win;
|
344
345
|
},
|
345
|
-
enumerable:
|
346
|
+
enumerable: false,
|
346
347
|
configurable: true
|
347
348
|
});
|
348
349
|
Copper.prototype.getContext = function () {
|
@@ -561,7 +562,7 @@ var Copper = /** @class */ (function () {
|
|
561
562
|
};
|
562
563
|
Copper.prototype._postMessage = function (type, message) {
|
563
564
|
if (message === void 0) { message = {}; }
|
564
|
-
this.win.top.postMessage(__assign({}, message, {
|
565
|
+
this.win.top.postMessage(__assign(__assign({}, message), {
|
565
566
|
// as a credential to the parent frame, so parent frame can recoganize the origin
|
566
567
|
instanceId: this.instanceId,
|
567
568
|
// tell parent frame current sdk version
|
@@ -640,14 +641,14 @@ var Copper = /** @class */ (function () {
|
|
640
641
|
executor();
|
641
642
|
return deferred.promise;
|
642
643
|
};
|
643
|
-
Copper.prototype._deferredPost = function (name
|
644
|
+
Copper.prototype._deferredPost = function (name, data) {
|
644
645
|
var _this = this;
|
645
|
-
return this._createDeferredMethod(name
|
646
|
+
return this._createDeferredMethod(name, function () {
|
646
647
|
if (data) {
|
647
|
-
_this._postMessage(name
|
648
|
+
_this._postMessage(name, data);
|
648
649
|
}
|
649
650
|
else {
|
650
|
-
_this._postMessage(name
|
651
|
+
_this._postMessage(name);
|
651
652
|
}
|
652
653
|
});
|
653
654
|
};
|
package/lib/defer.d.ts
CHANGED
package/lib/index.d.ts
CHANGED
@@ -7,7 +7,7 @@ export default class Copper {
|
|
7
7
|
private options;
|
8
8
|
private _win;
|
9
9
|
static init(): Copper;
|
10
|
-
static
|
10
|
+
static get version(): string;
|
11
11
|
/**
|
12
12
|
* store deferred queues by name
|
13
13
|
*/
|
@@ -23,7 +23,7 @@ export default class Copper {
|
|
23
23
|
* @memberof Copper
|
24
24
|
*/
|
25
25
|
constructor(parentOrigin: string, instanceId: string, options: ISdkInitOptions, _win?: any);
|
26
|
-
|
26
|
+
get win(): Window;
|
27
27
|
getContext(): Promise<IContextData>;
|
28
28
|
getUserInfo(): Promise<any>;
|
29
29
|
getRouteInfo(): Promise<any>;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "copper-sdk",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.7.0",
|
4
4
|
"description": "Copper App SDK",
|
5
5
|
"main": "lib/copper-sdk.js",
|
6
6
|
"module": "es/copper-sdk.js",
|
@@ -50,11 +50,11 @@
|
|
50
50
|
"homepage": "https://github.com/ProsperWorks/copper-sdk#readme",
|
51
51
|
"devDependencies": {
|
52
52
|
"@types/chai": "^4.1.7",
|
53
|
-
"@types/mocha": "^
|
53
|
+
"@types/mocha": "^8.2.2",
|
54
54
|
"@types/sinon": "^7.0.3",
|
55
55
|
"chai": "^4.1.2",
|
56
|
-
"concurrently": "^
|
57
|
-
"cross-env": "^
|
56
|
+
"concurrently": "^6.5.1",
|
57
|
+
"cross-env": "^7.0.3",
|
58
58
|
"gitbook-cli": "^2.3.2",
|
59
59
|
"gitbook-plugin-anker-enable": "0.0.4",
|
60
60
|
"gitbook-plugin-edit-link": "^2.0.2",
|
@@ -64,23 +64,22 @@
|
|
64
64
|
"gitbook-plugin-prism-ext": "^3.1.0",
|
65
65
|
"karma": "^3.1.4",
|
66
66
|
"karma-chai": "^0.1.0",
|
67
|
-
"karma-chrome-launcher": "^
|
68
|
-
"karma-coverage-istanbul-reporter": "^
|
69
|
-
"karma-mocha": "^
|
67
|
+
"karma-chrome-launcher": "^3.2.0",
|
68
|
+
"karma-coverage-istanbul-reporter": "^3.0.3",
|
69
|
+
"karma-mocha": "^2.0.1",
|
70
70
|
"karma-mocha-reporter": "^2.2.5",
|
71
|
-
"karma-rollup-preprocessor": "^
|
71
|
+
"karma-rollup-preprocessor": "^7.0.8",
|
72
72
|
"karma-sinon": "^1.0.5",
|
73
|
-
"mocha": "^
|
74
|
-
"rimraf": "^
|
75
|
-
"rollup": "
|
76
|
-
"rollup-plugin-istanbul": "^
|
77
|
-
"rollup-plugin-json": "^
|
73
|
+
"mocha": "^8.4.0",
|
74
|
+
"rimraf": "^3.0.2",
|
75
|
+
"rollup": "^1.32.1",
|
76
|
+
"rollup-plugin-istanbul": "^3.0.0",
|
77
|
+
"rollup-plugin-json": "^4.0.0",
|
78
78
|
"rollup-plugin-replace": "^2.0.0",
|
79
|
-
"rollup-plugin-typescript2": "^0.
|
79
|
+
"rollup-plugin-typescript2": "^0.30.0",
|
80
80
|
"rollup-plugin-uglify": "^6.0.1",
|
81
|
-
"sinon": "^
|
81
|
+
"sinon": "^13.0.2",
|
82
82
|
"tslint": "^5.12.1",
|
83
83
|
"typescript": "^3.2.2"
|
84
|
-
}
|
85
|
-
"dependencies": {}
|
84
|
+
}
|
86
85
|
}
|