monday-sdk-js 0.4.11 → 0.5.0

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.
package/dist/main.js CHANGED
@@ -1 +1 @@
1
- !function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=3)}([function(e,t){const n="undefined"!=typeof window&&void 0!==window.document;e.exports={convertToArrayIfNeeded:e=>Array.isArray(e)?e:[e],isBrowser:n}},function(e,t,n){e.exports=n(5)},function(e,t,n){(function(t){const{isBrowser:r}=n(0),i=!r&&!1,o=i&&t.env.MONDAY_COM_PROTOCOL||"https",s=i&&t.env.MONDAY_COM_DOMAIN||"monday.com",a=`${o}://api.${s}/v2`,c=`${o}://auth.${s}/oauth2/authorize`,u=`${o}://auth.${s}/oauth2/token`;e.exports={MONDAY_DOMAIN:s,MONDAY_PROTOCOL:o,MONDAY_API_URL:a,MONDAY_OAUTH_URL:c,MONDAY_OAUTH_TOKEN_URL:u}}).call(this,n(6))},function(e,t,n){var r,i;const{isBrowser:o}=n(0),s=n(o?4:12);"undefined"!=typeof self&&self,void 0===(i="function"==typeof(r=function(){return window.mondaySdk=s,s})?r.call(t,n,t,e):r)||(e.exports=i)},function(e,t,n){const r=n(1),{MONDAY_OAUTH_URL:i}=n(2),{convertToArrayIfNeeded:o}=n(0),{initScrollHelperIfNeeded:s}=n(9),{initBackgroundTracking:a}=n(10),c=[];class u{constructor(e={}){this._clientId=e.clientId,this._apiToken=e.apiToken,this.listeners={},this.setClientId=this.setClientId.bind(this),this.setToken=this.setToken.bind(this),this.api=this.api.bind(this),this.listen=this.listen.bind(this),this.get=this.get.bind(this),this.set=this.set.bind(this),this.execute=this.execute.bind(this),this.oauth=this.oauth.bind(this),this._receiveMessage=this._receiveMessage.bind(this),this.storage={instance:{setItem:this.setStorageInstanceItem.bind(this),getItem:this.getStorageInstanceItem.bind(this),deleteItem:this.deleteStorageInstanceItem.bind(this)}},window.addEventListener("message",this._receiveMessage,!1),e.withoutScrollHelper||s(),a(this)}setClientId(e){this._clientId=e}setToken(e){this._apiToken=e}api(e,t={}){const n={query:e,variables:t.variables},i=t.token||this._apiToken;return i?r.execute(n,i):new Promise((e,t)=>{this._localApi("api",{params:n}).then(t=>{e(t.data)}).catch(e=>t(e))})}listen(e,t,n){const r=o(e),i=[];return r.forEach(e=>{i.push(this._addListener(e,t)),this._localApi("listen",{type:e,params:n})}),()=>{i.forEach(e=>e())}}get(e,t){return this._localApi("get",{type:e,params:t})}set(e,t){return this._localApi("set",{type:e,params:t})}execute(e,t){return this._localApi("execute",{type:e,params:t})}track(e,t){return this.execute("track",{name:e,data:t})}oauth(e={}){const t=e.clientId||this._clientId;if(!t)throw new Error("clientId is required");const n=`${e.mondayOauthUrl||i}?client_id=${t}`;window.location=n}setStorageInstanceItem(e,t,n={}){return this._localApi("storage",{method:"set",key:e,value:t,options:n,segment:"instance"})}getStorageInstanceItem(e,t={}){return this._localApi("storage",{method:"get",key:e,options:t,segment:"instance"})}deleteStorageInstanceItem(e,t={}){return this._localApi("storage",{method:"delete",key:e,options:t,segment:"instance"})}_localApi(e,t){return new Promise((r,i)=>{const o=this._generateRequestId(),s=this._clientId,a=n(11).version;window.parent.postMessage({method:e,args:t,requestId:o,clientId:s,version:a},"*");const c=this._addListener(o,e=>{if(c(),e.errorMessage){const t=new Error(e.errorMessage);t.data=e.data,i(t)}else r(e)})})}_receiveMessage(e){const{method:t,type:n,requestId:r}=e.data,i=this.listeners[t]||c,o=this.listeners[n]||c,s=this.listeners[r]||c;let a=new Set([...i,...o,...s]);a&&a.forEach(t=>{try{t(e.data)}catch(e){console.error("Message callback error: ",e)}})}_addListener(e,t){return this.listeners[e]=this.listeners[e]||new Set,this.listeners[e].add(t),()=>{this.listeners[e].delete(t),0===this.listeners[e].size&&delete this.listeners[e]}}_generateRequestId(){return Math.random().toString(36).substring(2,9)}_removeEventListener(){window.removeEventListener("message",this._receiveMessage,!1)}_clearListeners(){this.listeners=[]}}e.exports=function(e={}){return new u(e)}},function(e,t,n){const{MONDAY_API_URL:r,MONDAY_OAUTH_TOKEN_URL:i}=n(2),o=n(7);e.exports={execute:async function(e,t,n={}){if(!t&&n.url!==i)throw new Error("Token is required");const s=`${n.url||r}${n.path||""}`;let a=await function(e,t,n,r={}){return o.nodeFetch(e,{method:r.method||"POST",body:JSON.stringify(t||{}),headers:{Authorization:n,"Content-Type":"application/json"}})}(s,e,t,n);const c=a.status,u=a.headers.get("content-type");if(!u||!u.includes("application/json")){if(504===c)throw new Error("Received timeout from monday.com's GraphQL API");const e=await a.text();throw new Error(e)}try{return await a.json()}catch(e){throw new Error("Could not parse JSON from monday.com's GraphQL API response")}},COULD_NOT_PARSE_JSON_RESPONSE_ERROR:"Could not parse JSON from monday.com's GraphQL API response",TOKEN_IS_REQUIRED_ERROR:"Token is required",API_TIMEOUT_ERROR:"Received timeout from monday.com's GraphQL API"}},function(e,t){var n,r,i=e.exports={};function o(){throw new Error("setTimeout has not been defined")}function s(){throw new Error("clearTimeout has not been defined")}function a(e){if(n===setTimeout)return setTimeout(e,0);if((n===o||!n)&&setTimeout)return n=setTimeout,setTimeout(e,0);try{return n(e,0)}catch(t){try{return n.call(null,e,0)}catch(t){return n.call(this,e,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:o}catch(e){n=o}try{r="function"==typeof clearTimeout?clearTimeout:s}catch(e){r=s}}();var c,u=[],l=!1,d=-1;function h(){l&&c&&(l=!1,c.length?u=c.concat(u):d=-1,u.length&&p())}function p(){if(!l){var e=a(h);l=!0;for(var t=u.length;t;){for(c=u,u=[];++d<t;)c&&c[d].run();d=-1,t=u.length}c=null,l=!1,function(e){if(r===clearTimeout)return clearTimeout(e);if((r===s||!r)&&clearTimeout)return r=clearTimeout,clearTimeout(e);try{r(e)}catch(t){try{return r.call(null,e)}catch(t){return r.call(this,e)}}}(e)}}function f(e,t){this.fun=e,this.array=t}function m(){}i.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];u.push(new f(e,t)),1!==u.length||l||a(p)},f.prototype.run=function(){this.fun.apply(null,this.array)},i.title="browser",i.browser=!0,i.env={},i.argv=[],i.version="",i.versions={},i.on=m,i.addListener=m,i.once=m,i.off=m,i.removeListener=m,i.removeAllListeners=m,i.emit=m,i.prependListener=m,i.prependOnceListener=m,i.listeners=function(e){return[]},i.binding=function(e){throw new Error("process.binding is not supported")},i.cwd=function(){return"/"},i.chdir=function(e){throw new Error("process.chdir is not supported")},i.umask=function(){return 0}},function(e,t,n){const r=n(8);e.exports={nodeFetch:function(e,t={}){return r(e,t)}}},function(e,t,n){"use strict";var r=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if(void 0!==r)return r;throw new Error("unable to locate global object")}();e.exports=t=r.fetch,t.default=r.fetch.bind(r),t.Headers=r.Headers,t.Request=r.Request,t.Response=r.Response},function(e,t){let n=!1;e.exports={initScrollHelperIfNeeded:function(){if(n)return;n=!0;const e=document.createElement("style");e.appendChild(document.createTextNode('body::before { content: ""; position: fixed; top: 0; right: 0; bottom: 0; left: 0; pointer-events: none; z-index: 2147483647; /* mondaySdk css - can be disabled with: mondaySdk({withoutScrollHelper: true }) */ }')),(document.head||document.getElementsByTagName("head")[0]).appendChild(e)}}},function(e,t){let n=!1;e.exports={initBackgroundTracking:e=>{if(n)return;n=!0;const t=()=>{e.track("ping")};t(),setInterval(t,3e5)}}},function(e){e.exports=JSON.parse('{"name":"monday-sdk-js","version":"0.1.6","private":false,"repository":"https://github.com/mondaycom/monday-sdk-js","main":"src/index.js","author":"talharamati <tal@monday.com>","license":"MIT","files":["LICENSE","README.md","dist/","src/","server-sdk.js"],"dependencies":{"@types/source-map":"^0.5.2","node-fetch":"^2.6.0"},"devDependencies":{"@babel/cli":"^7.6.0","@babel/core":"^7.6.0","@babel/node":"^7.6.1","@babel/preset-env":"^7.6.0","@babel/preset-react":"^7.0.0","@babel/register":"^7.6.0","babel-loader":"^8.0.6","chai":"^4.2.0","eslint":"^6.8.0","jsdom":"^16.2.0","mocha":"^7.1.0","prettier":"^1.19.1","sinon":"^9.0.0","sinon-chai":"^3.5.0","webpack":"^4.38.0","webpack-cli":"^3.3.6","webpack-dev-server":"^3.7.2"},"scripts":{"start":"webpack-dev-server","build":"webpack --mode=production --env.WEBPACK_BUILD=true","test":"mocha \'./src/**/*-test.js\'","test:watch":"mocha \'./src/**/*-test.js\' --watch","precommit":"yarn lint && yarn style-check","lint":"eslint \'./src/**/*.*\'","style-check":"prettier --check \'./src/**/*.js\'"}}')},function(e,t,n){const r=n(1),{oauthToken:i}=n(13);class o{constructor(e={}){this._token=e.token,this.setToken=this.setToken.bind(this),this.api=this.api.bind(this)}setToken(e){this._token=e}async api(e,t={}){const n={query:e,variables:t.variables},i=t.token||this._token;if(!i)throw new Error("Should send 'token' as an option or call mondaySdk.setToken(TOKEN)");return await r.execute(n,i)}oauthToken(e,t,n){return i(e,t,n)}}e.exports=function(e={}){return new o(e)}},function(e,t,n){const{execute:r}=n(1),{MONDAY_OAUTH_TOKEN_URL:i}=n(2);e.exports={oauthToken:(e,t,n)=>r({code:e,client_id:t,client_secret:n},null,{url:i})}}]);
1
+ !function(e){var t={};function n(i){if(t[i])return t[i].exports;var r=t[i]={i:i,l:!1,exports:{}};return e[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(i,r,function(t){return e[t]}.bind(null,r));return i},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=4)}([function(e,t,n){e.exports=n(6)},function(e,t,n){(function(t){function n(){return void 0!==t&&!1}const i=(e,i)=>n()&&"undefined"!==t.env[e]&&void 0!==t.env[e]?t.env[e]:i,r=()=>i("MONDAY_COM_PROTOCOL","https"),s=()=>i("MONDAY_COM_DOMAIN","monday.com"),o=()=>i("MONDAY_OAUTH_SUBDOMAIN","auth."),a=()=>`${r()}://${i("MONDAY_SUBDOMAIN_API","api.")}${s()}/v2`;e.exports={get MONDAY_DOMAIN(){return s()},get MONDAY_PROTOCOL(){return r()},get MONDAY_API_URL(){return a()},get MONDAY_OAUTH_URL(){return`${r()}://${o()}${s()}/oauth2/authorize`},get MONDAY_OAUTH_TOKEN_URL(){return`${r()}://${o()}${s()}/oauth2/token`}}}).call(this,n(7))},function(e,t){const n="undefined"!=typeof window&&void 0!==window.document;e.exports={convertToArrayIfNeeded:e=>Array.isArray(e)?e:[e],isBrowser:n}},function(e,t){e.exports={logWarnings:e=>{const t=e&&e.extensions&&e.extensions.warnings;return t&&Array.isArray(t)?(t.forEach(e=>{if(e&&e.message)try{const t=e.locations&&e.locations.map(e=>`line ${e.line}, column ${e.column}`).join("; "),n=e.path&&e.path.join(" → ");let i=e.message;i=i.replace(/\.$/,""),i=i.charAt(0).toLowerCase()+i.slice(1);const r=["[monday API]",`${n}:`,i,t&&`@ ${t}`,e.extensions?["\n\nAdditional details:",e.extensions]:void 0].flat().filter(Boolean);console.warn(...r)}catch(t){e&&console.warn("[monday API] Warning:",e)}}),e):e}}},function(e,t,n){var i,r;const{isBrowser:s}=n(2),o=n(s?5:13);"undefined"!=typeof self&&self,void 0===(r="function"==typeof(i=function(){return window.mondaySdk=o,o})?i.call(t,n,t,e):i)||(e.exports=r)},function(e,t,n){const i=n(0),{MONDAY_OAUTH_URL:r}=n(1),{convertToArrayIfNeeded:s}=n(2),{initScrollHelperIfNeeded:o}=n(10),{initBackgroundTracking:a}=n(11),{logWarnings:c}=n(3),l=[],u="v2",d="instance";class h{constructor(e={}){this._clientId=e.clientId,this._apiToken=e.apiToken,this._apiVersion=e.apiVersion,this.listeners={},this.setClientId=this.setClientId.bind(this),this.setToken=this.setToken.bind(this),this.setApiVersion=this.setApiVersion.bind(this),this.api=this.api.bind(this),this.listen=this.listen.bind(this),this.get=this.get.bind(this),this.set=this.set.bind(this),this.execute=this.execute.bind(this),this.oauth=this.oauth.bind(this),this._receiveMessage=this._receiveMessage.bind(this),this.storage={setItem:this.setStorageItem.bind(this),getItem:this.getStorageItem.bind(this),deleteItem:this.deleteStorageItem.bind(this),instance:{setItem:this.setStorageInstanceItem.bind(this),getItem:this.getStorageInstanceItem.bind(this),deleteItem:this.deleteStorageInstanceItem.bind(this)}},window.addEventListener("message",this._receiveMessage,!1),e.withoutScrollHelper||o(),a(this)}setClientId(e){this._clientId=e}setToken(e){this._apiToken=e}setApiVersion(e){this._apiVersion=e}api(e,t={}){const n={query:e,variables:t.variables},r=t.token||this._apiToken,s=t.apiVersion||this._apiVersion;let o;return o=r?i.execute(n,r,{apiVersion:s}):this._localApi("api",{params:n,apiVersion:s}).then(e=>e.data),o.then(c)}listen(e,t,n){const i=s(e),r=[];return i.forEach(e=>{r.push(this._addListener(e,t)),this._localApi("listen",{type:e,params:n})}),()=>{r.forEach(e=>e())}}get(e,t){return this._localApi("get",{type:e,params:t})}set(e,t){return this._localApi("set",{type:e,params:t})}execute(e,t){return this._localApi("execute",{type:e,params:t})}track(e,t){return this.execute("track",{name:e,data:t})}oauth(e={}){const t=e.clientId||this._clientId;if(!t)throw new Error("clientId is required");const n=`${e.mondayOauthUrl||r}?client_id=${t}`;window.location=n}setStorageItem(e,t,n={}){return this._localApi("storage",{method:"set",key:e,value:t,options:n,segment:u})}getStorageItem(e,t={}){return this._localApi("storage",{method:"get",key:e,options:t,segment:u})}deleteStorageItem(e,t={}){return this._localApi("storage",{method:"delete",key:e,options:t,segment:u})}setStorageInstanceItem(e,t,n={}){return this._localApi("storage",{method:"set",key:e,value:t,options:n,segment:d})}getStorageInstanceItem(e,t={}){return this._localApi("storage",{method:"get",key:e,options:t,segment:d})}deleteStorageInstanceItem(e,t={}){return this._localApi("storage",{method:"delete",key:e,options:t,segment:d})}_localApi(e,t){return new Promise((i,r)=>{const s=this._generateRequestId(),o=this._clientId,a=n(12).version;window.parent.postMessage({method:e,args:t,requestId:s,clientId:o,version:a},"*");const c=this._addListener(s,e=>{if(c(),e.errorMessage){const t=new Error(e.errorMessage);t.data=e.data,r(t)}else i(e)})})}_receiveMessage(e){const{method:t,type:n,requestId:i}=e.data,r=this.listeners[t]||l,s=this.listeners[n]||l,o=this.listeners[i]||l;let a=new Set([...r,...s,...o]);a&&a.forEach(t=>{try{t(e.data)}catch(e){console.error("Message callback error: ",e)}})}_addListener(e,t){return this.listeners[e]=this.listeners[e]||new Set,this.listeners[e].add(t),()=>{this.listeners[e].delete(t),0===this.listeners[e].size&&delete this.listeners[e]}}_generateRequestId(){return Math.random().toString(36).substring(2,9)}_removeEventListener(){window.removeEventListener("message",this._receiveMessage,!1)}_clearListeners(){this.listeners=[]}}e.exports=function(e={}){return new h(e)}},function(e,t,n){const{MONDAY_API_URL:i,MONDAY_OAUTH_TOKEN_URL:r}=n(1),s=n(8);e.exports={execute:async function(e,t,n={}){if(!t&&n.url!==r)throw new Error("Token is required");const o=`${n.url||i}${n.path||""}`;let a=await function(e,t,n,i={}){return s.nodeFetch(e,{method:i.method||"POST",body:JSON.stringify(t||{}),headers:{Authorization:n,"Content-Type":"application/json",...i.apiVersion?{"API-Version":i.apiVersion}:{}}})}(o,e,t,n);const c=a.status,l=a.headers.get("content-type");if(!l||!l.includes("application/json")){if(504===c)throw new Error("Received timeout from monday.com's GraphQL API");const e=await a.text();throw new Error(e)}try{return await a.json()}catch(e){throw new Error("Could not parse JSON from monday.com's GraphQL API response")}},COULD_NOT_PARSE_JSON_RESPONSE_ERROR:"Could not parse JSON from monday.com's GraphQL API response",TOKEN_IS_REQUIRED_ERROR:"Token is required",API_TIMEOUT_ERROR:"Received timeout from monday.com's GraphQL API"}},function(e,t){var n,i,r=e.exports={};function s(){throw new Error("setTimeout has not been defined")}function o(){throw new Error("clearTimeout has not been defined")}function a(e){if(n===setTimeout)return setTimeout(e,0);if((n===s||!n)&&setTimeout)return n=setTimeout,setTimeout(e,0);try{return n(e,0)}catch(t){try{return n.call(null,e,0)}catch(t){return n.call(this,e,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:s}catch(e){n=s}try{i="function"==typeof clearTimeout?clearTimeout:o}catch(e){i=o}}();var c,l=[],u=!1,d=-1;function h(){u&&c&&(u=!1,c.length?l=c.concat(l):d=-1,l.length&&p())}function p(){if(!u){var e=a(h);u=!0;for(var t=l.length;t;){for(c=l,l=[];++d<t;)c&&c[d].run();d=-1,t=l.length}c=null,u=!1,function(e){if(i===clearTimeout)return clearTimeout(e);if((i===o||!i)&&clearTimeout)return i=clearTimeout,clearTimeout(e);try{i(e)}catch(t){try{return i.call(null,e)}catch(t){return i.call(this,e)}}}(e)}}function f(e,t){this.fun=e,this.array=t}function m(){}r.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];l.push(new f(e,t)),1!==l.length||u||a(p)},f.prototype.run=function(){this.fun.apply(null,this.array)},r.title="browser",r.browser=!0,r.env={},r.argv=[],r.version="",r.versions={},r.on=m,r.addListener=m,r.once=m,r.off=m,r.removeListener=m,r.removeAllListeners=m,r.emit=m,r.prependListener=m,r.prependOnceListener=m,r.listeners=function(e){return[]},r.binding=function(e){throw new Error("process.binding is not supported")},r.cwd=function(){return"/"},r.chdir=function(e){throw new Error("process.chdir is not supported")},r.umask=function(){return 0}},function(e,t,n){const i=n(9);e.exports={nodeFetch:function(e,t={}){return i(e,t)}}},function(e,t,n){"use strict";var i=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if(void 0!==i)return i;throw new Error("unable to locate global object")}();e.exports=t=i.fetch,t.default=i.fetch.bind(i),t.Headers=i.Headers,t.Request=i.Request,t.Response=i.Response},function(e,t){let n=!1;e.exports={initScrollHelperIfNeeded:function(){if(n)return;n=!0;const e=document.createElement("style");e.appendChild(document.createTextNode('body::before { content: ""; position: fixed; top: 0; right: 0; bottom: 0; left: 0; pointer-events: none; z-index: 2147483647; /* mondaySdk css - can be disabled with: mondaySdk({withoutScrollHelper: true }) */ }')),(document.head||document.getElementsByTagName("head")[0]).appendChild(e)}}},function(e,t){let n=!1;e.exports={initBackgroundTracking:e=>{if(n)return;n=!0;const t=()=>{e.track("ping")};t(),setInterval(t,3e5)}}},function(e){e.exports=JSON.parse('{"name":"monday-sdk-js","version":"0.4.12","private":false,"repository":"https://github.com/mondaycom/monday-sdk-js","main":"src/index.js","types":"types/index.d.ts","author":"talharamati <tal@monday.com>","license":"MIT","files":["LICENSE","README.md","dist/","src/","types/","server-sdk.js"],"dependencies":{"node-fetch":"^2.6.0"},"devDependencies":{"@babel/cli":"^7.6.0","@babel/core":"^7.6.0","@babel/node":"^7.6.1","@babel/preset-env":"^7.6.0","@babel/preset-react":"^7.0.0","@babel/register":"^7.6.0","@types/source-map":"^0.5.2","babel-loader":"^8.0.6","chai":"^4.2.0","eslint":"^6.8.0","jsdom":"^16.2.0","mocha":"^7.1.0","prettier":"^1.19.1","sinon":"^9.0.0","sinon-chai":"^3.5.0","typescript":"^4.9.5","webpack":"^4.38.0","webpack-cli":"^3.3.6","webpack-dev-server":"^3.7.2"},"scripts":{"start":"webpack-dev-server","build":"webpack --mode=production --env.WEBPACK_BUILD=true","test":"mocha \'./src/**/*-test.js\'","test:watch":"mocha \'./src/**/*-test.js\' --watch","precommit":"yarn lint && yarn style-check","lint":"eslint \'./src/**/*.*\'","style-check":"prettier --check \'./src/**/*.js\'","style-fix":"prettier --write \'./src/**/*.js\'","compile-types":"tsc --noEmit"}}')},function(e,t,n){const{logWarnings:i}=n(3),r=n(0),{oauthToken:s}=n(14);class o{constructor(e={}){this._token=e.token,this._apiVersion=e.apiVersion,this.setToken=this.setToken.bind(this),this.setApiVersion=this.setApiVersion.bind(this),this.api=this.api.bind(this)}setToken(e){this._token=e}setApiVersion(e){this._apiVersion=e}api(e,t={}){const n={query:e,variables:t.variables},s=t.token||this._token,o=t.apiVersion||this._apiVersion;if(!s)throw new Error("Should send 'token' as an option or call mondaySdk.setToken(TOKEN)");return r.execute(n,s,{apiVersion:o}).then(i)}oauthToken(e,t,n){return s(e,t,n)}}e.exports=function(e={}){return new o(e)}},function(e,t,n){const{execute:i}=n(0),{MONDAY_OAUTH_TOKEN_URL:r}=n(1);e.exports={oauthToken:(e,t,n)=>i({code:e,client_id:t,client_secret:n},null,{url:r})}}]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "monday-sdk-js",
3
- "version": "0.4.11",
3
+ "version": "0.5.0",
4
4
  "private": false,
5
5
  "repository": "https://github.com/mondaycom/monday-sdk-js",
6
6
  "main": "src/index.js",
@@ -19,6 +19,7 @@
19
19
  "node-fetch": "^2.6.0"
20
20
  },
21
21
  "devDependencies": {
22
+ "monday-ui-react-core": "^2.63.2",
22
23
  "@babel/cli": "^7.6.0",
23
24
  "@babel/core": "^7.6.0",
24
25
  "@babel/node": "^7.6.1",
@@ -0,0 +1,238 @@
1
+ import type { Theme } from "monday-ui-react-core/dist/types/components/ThemeProvider/ThemeProviderConstants";
2
+
3
+ type User = {
4
+ id: string;
5
+ isAdmin: boolean;
6
+ isGuest: boolean;
7
+ isViewOnly: boolean;
8
+ countryCode: string;
9
+ currentLanguage: string;
10
+ timeFormat: string;
11
+ timeZoneOffset: number;
12
+ };
13
+
14
+ type Account = {
15
+ id: string;
16
+ };
17
+
18
+ type App = {
19
+ id: number;
20
+ clientId: string;
21
+ };
22
+
23
+ type AppVersion = {
24
+ id: number;
25
+ name: string;
26
+ status: string;
27
+ type: string;
28
+ versionData: {
29
+ major: number;
30
+ minor: number;
31
+ patch: number;
32
+ type: string;
33
+ };
34
+ };
35
+
36
+ export type BaseContext = {
37
+ themeConfig?: Theme;
38
+ theme: string;
39
+ account: Account;
40
+ user: User;
41
+ region: string;
42
+ app: App;
43
+ appVersion: AppVersion;
44
+ };
45
+
46
+ export type AppFeatureBoardViewContext = BaseContext & {
47
+ boardId: number;
48
+ boardIds: number[];
49
+ boardViewId: number;
50
+ viewMode: string;
51
+ instanceId: number;
52
+ instanceType: string;
53
+ workspaceId: number;
54
+ };
55
+
56
+ export type AppFeatureAiBoardMainMenuHeaderContext = BaseContext & {
57
+ location: string;
58
+ locationContext: {
59
+ boardId: number;
60
+ workspaceId: number;
61
+ };
62
+ appFeatureId: number;
63
+ withExternalWidth: boolean;
64
+ withHeaderPadding: boolean;
65
+ boardId: number;
66
+ workspaceId: number;
67
+ };
68
+
69
+ export type AppFeatureDashboardWidgetContext = BaseContext & {
70
+ boardIds: number[];
71
+ widgetId: number;
72
+ viewMode: string;
73
+ editMode: boolean;
74
+ instanceId: number;
75
+ instanceType: string;
76
+ };
77
+
78
+ export type AppFeatureItemMenuActionContext = BaseContext & {
79
+ boardId: number;
80
+ pulseId: number;
81
+ itemId: number;
82
+ };
83
+
84
+ export type AppFeatureItemBatchActionContext = BaseContext & {
85
+ boardId: number;
86
+ itemId: number;
87
+ selectedPulsesIds: number[];
88
+ };
89
+
90
+ export type AppFeatureGroupMenuActionContext = BaseContext & {
91
+ groupId: string;
92
+ boardId: number;
93
+ groupColor: string;
94
+ };
95
+
96
+ export type AppFeatureObjectContext = BaseContext & {
97
+ boardId: number;
98
+ boardIds: [number];
99
+ workspaceId: number;
100
+ appFeatureId: number;
101
+ instanceId: number;
102
+ instanceType: string;
103
+ isFullScreen: boolean;
104
+ isPresentingMode: boolean;
105
+ objectPermissions: string;
106
+ isFirstLevelControlPinned: boolean;
107
+ isSlidePanelOpen: boolean;
108
+ boardLoadingState: number;
109
+ };
110
+
111
+ export type AppFeatureWorkspaceViewContext = BaseContext & {
112
+ workspaceId: number;
113
+ };
114
+
115
+ export type AppFeatureItemViewContext = BaseContext & {
116
+ workspaceId: number;
117
+ boardId: number;
118
+ boardIds: [number];
119
+ itemId: number;
120
+ instanceId: number;
121
+ instanceType: string;
122
+ };
123
+
124
+ export type AppFeatureAiDocQuickStartType = BaseContext & {
125
+ location: string;
126
+ locationContext: {
127
+ docId: number;
128
+ objectId: number;
129
+ workspaceId: number;
130
+ additionalSdkMethodsList: string[];
131
+ };
132
+ appFeatureId: number;
133
+ withExternalWidth: boolean;
134
+ withHeaderPadding: boolean;
135
+ docId: number;
136
+ objectId: number;
137
+ workspaceId: number;
138
+ additionalSdkMethodsList: string[];
139
+ };
140
+
141
+ export type AppFeatureAiDocTopBarContext = BaseContext & {
142
+ location: string;
143
+ locationContext: {
144
+ input: string;
145
+ docId: number;
146
+ objectId: number;
147
+ workspaceId: number;
148
+ additionalSdkMethodsList: string[];
149
+ };
150
+ appFeatureId: number;
151
+ withExternalWidth: boolean;
152
+ withHeaderPadding: boolean;
153
+ input: string;
154
+ docId: number;
155
+ objectId: number;
156
+ workspaceId: number;
157
+ additionalSdkMethodsList: string[];
158
+ };
159
+ export type FocusedBlock = {
160
+ id: string;
161
+ createdUserId: number;
162
+ accountId: number;
163
+ docId: number;
164
+ type: string;
165
+ content: {
166
+ alignment: string;
167
+ direction: string;
168
+ deltaFormat: Array<{
169
+ insert: string;
170
+ }>;
171
+ base64Encoded: string;
172
+ };
173
+ position: number;
174
+ parentBlockId: string | null;
175
+ createdAt: string;
176
+ updatedAt: string;
177
+ };
178
+
179
+ export type AppFeatureAiDocSlashCommandContext = BaseContext & {
180
+ location: string;
181
+ locationContext: {
182
+ focusedBlocks: FocusedBlock[];
183
+ canMoveToNextSelectedTextualBlock: boolean;
184
+ canMoveToPrevSelectedTextualBlock: boolean;
185
+ input: string;
186
+ isTextSelectedInBlock: boolean;
187
+ docId: number;
188
+ objectId: number;
189
+ workspaceId: number;
190
+ additionalSdkMethodsList: string[];
191
+ };
192
+ appFeatureId: number;
193
+ withExternalWidth: boolean;
194
+ withHeaderPadding: boolean;
195
+ focusedBlocks: FocusedBlock[];
196
+ canMoveToNextSelectedTextualBlock: boolean;
197
+ canMoveToPrevSelectedTextualBlock: boolean;
198
+ input: string;
199
+ isTextSelectedInBlock: boolean;
200
+ docId: number;
201
+ objectId: number;
202
+ workspaceId: number;
203
+ additionalSdkMethodsList: string[];
204
+ };
205
+
206
+ export type AppFeatureDocActionsContext = BaseContext & {
207
+ themeConfig: Theme;
208
+ docId: number;
209
+ objectId: number;
210
+ workspaceId: number;
211
+ focusedBlocks: FocusedBlock[];
212
+ placement: string;
213
+ highlightedText: string;
214
+ range: {
215
+ index: number;
216
+ length: number;
217
+ };
218
+ blockId: string;
219
+ };
220
+
221
+ export type AppFeatureContextMap = {
222
+ Base: BaseContext;
223
+ AppFeatureBoardView: AppFeatureBoardViewContext;
224
+ AppFeatureAiBoardMainMenuHeader: AppFeatureAiBoardMainMenuHeaderContext;
225
+ AppFeatureDashboardWidget: AppFeatureDashboardWidgetContext;
226
+ AppFeatureItemMenuAction: AppFeatureItemMenuActionContext;
227
+ AppFeatureItemBatchAction: AppFeatureItemBatchActionContext;
228
+ AppFeatureGroupMenuAction: AppFeatureGroupMenuActionContext;
229
+ AppFeatureObject: AppFeatureObjectContext;
230
+ AppFeatureWorkspaceView: AppFeatureWorkspaceViewContext;
231
+ AppFeatureItemView: AppFeatureItemViewContext;
232
+ AppFeatureAiDocQuickStart: AppFeatureAiDocQuickStartType;
233
+ AppFeatureAiDocTopBar: AppFeatureAiDocTopBarContext;
234
+ AppFeatureAiDocSlashCommand: AppFeatureAiDocSlashCommandContext;
235
+ AppFeatureDocActions: AppFeatureDocActionsContext;
236
+ };
237
+
238
+ export type AppFeatureTypes = keyof AppFeatureContextMap;
@@ -1,133 +1,155 @@
1
- type SubscribableEvents = 'context' | 'settings' | 'itemIds' | 'events';
1
+ import { AppFeatureContextMap, AppFeatureTypes } from "./client-context.type";
2
2
 
3
- type SettableTypes = 'settings';
3
+ type SubscribableEventsResponse<AppFeatureType extends AppFeatureTypes = AppFeatureTypes> = {
4
+ context: AppFeatureContextMap[AppFeatureType];
5
+ settings: Record<string, any>;
6
+ itemIds: number[];
7
+ events: Record<string, any>;
8
+ };
9
+
10
+ type SubscribableEvents = keyof SubscribableEventsResponse;
11
+
12
+ type SettableTypes = "settings";
4
13
 
5
14
  interface GetResponse {
6
- data: {
7
- success: boolean;
8
- value: any;
9
- version?: any;
10
- };
11
- errorMessage?: string | undefined;
12
- method: string;
13
- requestId: string;
14
- type?: string | undefined;
15
+ data: {
16
+ success: boolean;
17
+ value: any;
18
+ version?: any;
19
+ };
20
+ errorMessage?: string | undefined;
21
+ method: string;
22
+ requestId: string;
23
+ type?: string | undefined;
15
24
  }
16
25
 
17
26
  interface DeleteResponse {
18
- data: {
19
- success: boolean;
20
- value: any;
21
- };
22
- errorMessage?: string | undefined;
23
- method: string;
24
- requestId: string;
25
- type?: string | undefined;
27
+ data: {
28
+ success: boolean;
29
+ value: any;
30
+ };
31
+ errorMessage?: string | undefined;
32
+ method: string;
33
+ requestId: string;
34
+ type?: string | undefined;
26
35
  }
27
36
 
28
37
  interface SetResponse {
29
- data: {
30
- success: boolean;
31
- version: string;
32
- reason?: string | undefined;
33
- error?: string | undefined;
34
- };
35
- errorMessage?: string | undefined;
36
- requestId: string;
37
- method: string;
38
- type?: string | undefined;
38
+ data: {
39
+ success: boolean;
40
+ version: string;
41
+ reason?: string | undefined;
42
+ error?: string | undefined;
43
+ };
44
+ errorMessage?: string | undefined;
45
+ requestId: string;
46
+ method: string;
47
+ type?: string | undefined;
39
48
  }
40
49
 
41
-
50
+ export type GetterResponse<AppFeatureType extends AppFeatureTypes = AppFeatureTypes> = {
51
+ context: AppFeatureContextMap[AppFeatureType];
52
+ settings: Record<string, any>;
53
+ itemIds: number[];
54
+ sessionToken: string;
55
+ };
42
56
  export interface ClientData {
43
- /**
44
- * Used for retrieving data from the parent monday.com application where your app is currently running.
45
- * This object can only be used when your app is running inside an `iframe`. This can only be used in client-side apps.
46
- * @param type The type of requested information (available values below)
47
- * - `'context'` Information about where this app is currently displayed, depending on the type of feature
48
- * - `'settings'` The application settings as configured by the user that installed the app
49
- * - `'itemIds'` The list of item IDs that are filtered in the current board (or all items if no filters are applied)
50
- * - `'sessionToken'` A JWT token which is decoded with your app's secret and can be used as a session token between your app's frontend & backend
51
- * @param params Reserved for future use
52
- */
53
- get(type: 'context' | 'settings' | 'itemIds' | 'sessionToken', params?: object): Promise<any>;
57
+ /**
58
+ * Used for retrieving data from the parent monday.com application where your app is currently running.
59
+ * This object can only be used when your app is running inside an `iframe`. This can only be used in client-side apps.
60
+ * @param type The type of requested information (available values below)
61
+ * - `'context'` Information about where this app is currently displayed, depending on the type of feature
62
+ * - `'settings'` The application settings as configured by the user that installed the app
63
+ * - `'itemIds'` The list of item IDs that are filtered in the current board (or all items if no filters are applied)
64
+ * - `'sessionToken'` A JWT token which is decoded with your app's secret and can be used as a session token between your app's frontend & backend
65
+ * @param params Reserved for future use
66
+ */
67
+ get<
68
+ CustomResponse,
69
+ T extends keyof GetterResponse = keyof GetterResponse,
70
+ AppFeatureType extends AppFeatureTypes = AppFeatureTypes
71
+ >(
72
+ type: T,
73
+ params?: object & { appFeatureType?: AppFeatureType }
74
+ ): Promise<GetterResponse<AppFeatureType>[T] & CustomResponse>;
75
+
76
+ /**
77
+ * Creates a listener which allows subscribing to certain types of client-side events.
78
+ * @param typeOrTypes The type, or array of types, of events to subscribe to
79
+ * @param callback A callback function that is fired when the listener is triggered by a client-side event
80
+ * @param params Reserved for future use
81
+ */
82
+ listen<
83
+ CustomResponse,
84
+ T extends SubscribableEvents = SubscribableEvents,
85
+ AppFeatureType extends AppFeatureTypes = AppFeatureTypes
86
+ >(
87
+ typeOrTypes: T | ReadonlyArray<T>,
88
+ callback: (res: { data: SubscribableEventsResponse<AppFeatureType>[T] & CustomResponse }) => void,
89
+ params?: object & { appFeatureType?: AppFeatureType }
90
+ ): void;
54
91
 
92
+ /**
93
+ * Set data in your application, such as updating settings
94
+ * @param type The type of data that can be set
95
+ * @param params object containing the data you want to update
96
+ */
97
+ set(type: SettableTypes, params: object): Promise<any>;
98
+
99
+ /**
100
+ * The Storage API is in early beta stages, its API is likely to change
101
+ *
102
+ * The monday apps infrastructure includes a persistent, key-value database storage that developers
103
+ * can leverage to store data without having to create their own backend and maintain their own database.
104
+ *
105
+ * The database currently offers instance-level storage only, meaning that each application instance (i.e. a single board view or a dashboard widget) maintains its own storage.
106
+ * Apps cannot share storage across accounts or even across apps installed in the same location.
107
+ */
108
+ storage: {
55
109
  /**
56
- * Creates a listener which allows subscribing to certain types of client-side events.
57
- * @param typeOrTypes The type, or array of types, of events to subscribe to
58
- * @param callback A callback function that is fired when the listener is triggered by a client-side event
59
- * @param params Reserved for future use
110
+ * Returns a stored value from the database under `key` for the app (**without any reference to the instance**)
111
+ * @param {string} key - Used to access to stored data
60
112
  */
61
- listen(
62
- typeOrTypes: SubscribableEvents | ReadonlyArray<SubscribableEvents>,
63
- callback: (res: { data: object }) => void,
64
- params?: object,
65
- ): void;
66
-
113
+ getItem(key: string): Promise<GetResponse>;
114
+
67
115
  /**
68
- * Set data in your application, such as updating settings
69
- * @param type The type of data that can be set
70
- * @param params object containing the data you want to update
116
+ * Deletes a stored value from the database under `key` for the app (**without any reference to the instance**)
117
+ * @param {string} key - Used to delete the stored data
71
118
  */
72
- set(
73
- type: SettableTypes,
74
- params: object,
75
- ): Promise<any>;
119
+ deleteItem(key: string): Promise<DeleteResponse>;
76
120
 
77
121
  /**
78
- * The Storage API is in early beta stages, its API is likely to change
79
- *
80
- * The monday apps infrastructure includes a persistent, key-value database storage that developers
81
- * can leverage to store data without having to create their own backend and maintain their own database.
82
- *
83
- * The database currently offers instance-level storage only, meaning that each application instance (i.e. a single board view or a dashboard widget) maintains its own storage.
84
- * Apps cannot share storage across accounts or even across apps installed in the same location.
122
+ * Stores `value` under `key` in the database for the app (**without any reference to the instance**)
123
+ * @param {string} key - Used to delete the stored data
124
+ * @param {any} value - The value to store
125
+ * @param {object=} options
126
+ * @param {string=} options.previous_version - Use the new version of the storage (instance-less)
85
127
  */
86
- storage: {
87
- /**
88
- * Returns a stored value from the database under `key` for the app (**without any reference to the instance**)
89
- * @param {string} key - Used to access to stored data
90
- */
91
- getItem(key: string): Promise<GetResponse>;
92
-
93
- /**
94
- * Deletes a stored value from the database under `key` for the app (**without any reference to the instance**)
95
- * @param {string} key - Used to delete the stored data
96
- */
97
- deleteItem(key: string): Promise<DeleteResponse>;
98
-
99
- /**
100
- * Stores `value` under `key` in the database for the app (**without any reference to the instance**)
101
- * @param {string} key - Used to delete the stored data
102
- * @param {any} value - The value to store
103
- * @param {object=} options
104
- * @param {string=} options.previous_version - Use the new version of the storage (instance-less)
105
- */
106
- setItem(key: string, value: any, options?: { previous_version?: string }): Promise<SetResponse>;
107
- /***
108
- * The instance storage is a key-value database that is scoped to a specific app instance.
109
- * **Does not work** for instance-less apps.
110
- */
111
- instance: {
112
- /**
113
- * Returns a stored value from the database under `key` for a specific app instance
114
- * @param key
115
- */
116
- getItem(key: string): Promise<GetResponse>;
117
-
118
- /**
119
- * Deletes a stored value from the database under `key` for a specific app instance
120
- * @param key
121
- */
122
- deleteItem(key: string): Promise<DeleteResponse>;
123
-
124
- /**
125
- * Stores `value` under `key` in the database for a specific app instance
126
- * @param key
127
- * @param value
128
- * @param options
129
- */
130
- setItem(key: string, value: any, options?: { previous_version?: string }): Promise<SetResponse>;
131
- };
128
+ setItem(key: string, value: any, options?: { previous_version?: string }): Promise<SetResponse>;
129
+ /***
130
+ * The instance storage is a key-value database that is scoped to a specific app instance.
131
+ * **Does not work** for instance-less apps.
132
+ */
133
+ instance: {
134
+ /**
135
+ * Returns a stored value from the database under `key` for a specific app instance
136
+ * @param key
137
+ */
138
+ getItem(key: string): Promise<GetResponse>;
139
+
140
+ /**
141
+ * Deletes a stored value from the database under `key` for a specific app instance
142
+ * @param key
143
+ */
144
+ deleteItem(key: string): Promise<DeleteResponse>;
145
+
146
+ /**
147
+ * Stores `value` under `key` in the database for a specific app instance
148
+ * @param key
149
+ * @param value
150
+ * @param options
151
+ */
152
+ setItem(key: string, value: any, options?: { previous_version?: string }): Promise<SetResponse>;
132
153
  };
154
+ };
133
155
  }