@kintone/rest-api-client-dingtalk-mp
Version:
kintone REST API client for DingTalk Mini Program
1 lines • 41.5 kB
JavaScript
module.exports=function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=7)}([function(e,t,r){"use strict";var n=Object.prototype.hasOwnProperty,o=Array.isArray,i=function(){for(var e=[],t=0;t<256;++t)e.push("%"+((t<16?"0":"")+t.toString(16)).toUpperCase());return e}(),a=function(e,t){for(var r=t&&t.plainObjects?Object.create(null):{},n=0;n<e.length;++n)void 0!==e[n]&&(r[n]=e[n]);return r};e.exports={arrayToObject:a,assign:function(e,t){return Object.keys(t).reduce((function(e,r){return e[r]=t[r],e}),e)},combine:function(e,t){return[].concat(e,t)},compact:function(e){for(var t=[{obj:{o:e},prop:"o"}],r=[],n=0;n<t.length;++n)for(var i=t[n],a=i.obj[i.prop],s=Object.keys(a),u=0;u<s.length;++u){var c=s[u],l=a[c];"object"==typeof l&&null!==l&&-1===r.indexOf(l)&&(t.push({obj:a,prop:c}),r.push(l))}return function(e){for(;e.length>1;){var t=e.pop(),r=t.obj[t.prop];if(o(r)){for(var n=[],i=0;i<r.length;++i)void 0!==r[i]&&n.push(r[i]);t.obj[t.prop]=n}}}(t),e},decode:function(e,t,r){var n=e.replace(/\+/g," ");if("iso-8859-1"===r)return n.replace(/%[0-9a-f]{2}/gi,unescape);try{return decodeURIComponent(n)}catch(e){return n}},encode:function(e,t,r){if(0===e.length)return e;var n=e;if("symbol"==typeof e?n=Symbol.prototype.toString.call(e):"string"!=typeof e&&(n=String(e)),"iso-8859-1"===r)return escape(n).replace(/%u[0-9a-f]{4}/gi,(function(e){return"%26%23"+parseInt(e.slice(2),16)+"%3B"}));for(var o="",a=0;a<n.length;++a){var s=n.charCodeAt(a);45===s||46===s||95===s||126===s||s>=48&&s<=57||s>=65&&s<=90||s>=97&&s<=122?o+=n.charAt(a):s<128?o+=i[s]:s<2048?o+=i[192|s>>6]+i[128|63&s]:s<55296||s>=57344?o+=i[224|s>>12]+i[128|s>>6&63]+i[128|63&s]:(a+=1,s=65536+((1023&s)<<10|1023&n.charCodeAt(a)),o+=i[240|s>>18]+i[128|s>>12&63]+i[128|s>>6&63]+i[128|63&s])}return o},isBuffer:function(e){return!(!e||"object"!=typeof e)&&!!(e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer(e))},isRegExp:function(e){return"[object RegExp]"===Object.prototype.toString.call(e)},merge:function e(t,r,i){if(!r)return t;if("object"!=typeof r){if(o(t))t.push(r);else{if(!t||"object"!=typeof t)return[t,r];(i&&(i.plainObjects||i.allowPrototypes)||!n.call(Object.prototype,r))&&(t[r]=!0)}return t}if(!t||"object"!=typeof t)return[t].concat(r);var s=t;return o(t)&&!o(r)&&(s=a(t,i)),o(t)&&o(r)?(r.forEach((function(r,o){if(n.call(t,o)){var a=t[o];a&&"object"==typeof a&&r&&"object"==typeof r?t[o]=e(a,r,i):t.push(r)}else t[o]=r})),t):Object.keys(r).reduce((function(t,o){var a=r[o];return n.call(t,o)?t[o]=e(t[o],a,i):t[o]=a,t}),s)}}},function(module,exports,__webpack_require__){(function(global){var __WEBPACK_AMD_DEFINE_ARRAY__,__WEBPACK_AMD_DEFINE_RESULT__;!function(e,t){module.exports=t(e)}("undefined"!=typeof self?self:"undefined"!=typeof window?window:void 0!==global?global:this,(function(global){"use strict";global=global||{};var _Base64=global.Base64,version="2.5.2",buffer;if(module.exports)try{buffer=eval("require('buffer').Buffer")}catch(e){buffer=void 0}var b64chars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",b64tab=function(e){for(var t={},r=0,n=e.length;r<n;r++)t[e.charAt(r)]=r;return t}(b64chars),fromCharCode=String.fromCharCode,cb_utob=function(e){if(e.length<2)return(t=e.charCodeAt(0))<128?e:t<2048?fromCharCode(192|t>>>6)+fromCharCode(128|63&t):fromCharCode(224|t>>>12&15)+fromCharCode(128|t>>>6&63)+fromCharCode(128|63&t);var t=65536+1024*(e.charCodeAt(0)-55296)+(e.charCodeAt(1)-56320);return fromCharCode(240|t>>>18&7)+fromCharCode(128|t>>>12&63)+fromCharCode(128|t>>>6&63)+fromCharCode(128|63&t)},re_utob=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g,utob=function(e){return e.replace(re_utob,cb_utob)},cb_encode=function(e){var t=[0,2,1][e.length%3],r=e.charCodeAt(0)<<16|(e.length>1?e.charCodeAt(1):0)<<8|(e.length>2?e.charCodeAt(2):0);return[b64chars.charAt(r>>>18),b64chars.charAt(r>>>12&63),t>=2?"=":b64chars.charAt(r>>>6&63),t>=1?"=":b64chars.charAt(63&r)].join("")},btoa=global.btoa?function(e){return global.btoa(e)}:function(e){return e.replace(/[\s\S]{1,3}/g,cb_encode)},_encode=function(e){return"[object Uint8Array]"===Object.prototype.toString.call(e)?e.toString("base64"):btoa(utob(String(e)))},encode=function(e,t){return t?_encode(String(e)).replace(/[+\/]/g,(function(e){return"+"==e?"-":"_"})).replace(/=/g,""):_encode(e)},encodeURI=function(e){return encode(e,!0)},re_btou=/[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g,cb_btou=function(e){switch(e.length){case 4:var t=((7&e.charCodeAt(0))<<18|(63&e.charCodeAt(1))<<12|(63&e.charCodeAt(2))<<6|63&e.charCodeAt(3))-65536;return fromCharCode(55296+(t>>>10))+fromCharCode(56320+(1023&t));case 3:return fromCharCode((15&e.charCodeAt(0))<<12|(63&e.charCodeAt(1))<<6|63&e.charCodeAt(2));default:return fromCharCode((31&e.charCodeAt(0))<<6|63&e.charCodeAt(1))}},btou=function(e){return e.replace(re_btou,cb_btou)},cb_decode=function(e){var t=e.length,r=t%4,n=(t>0?b64tab[e.charAt(0)]<<18:0)|(t>1?b64tab[e.charAt(1)]<<12:0)|(t>2?b64tab[e.charAt(2)]<<6:0)|(t>3?b64tab[e.charAt(3)]:0),o=[fromCharCode(n>>>16),fromCharCode(n>>>8&255),fromCharCode(255&n)];return o.length-=[0,0,2,1][r],o.join("")},_atob=global.atob?function(e){return global.atob(e)}:function(e){return e.replace(/\S{1,4}/g,cb_decode)},atob=function(e){return _atob(String(e).replace(/[^A-Za-z0-9\+\/]/g,""))},_decode=buffer?buffer.from&&Uint8Array&&buffer.from!==Uint8Array.from?function(e){return(e.constructor===buffer.constructor?e:buffer.from(e,"base64")).toString()}:function(e){return(e.constructor===buffer.constructor?e:new buffer(e,"base64")).toString()}:function(e){return btou(_atob(e))},decode=function(e){return _decode(String(e).replace(/[-_]/g,(function(e){return"-"==e?"+":"/"})).replace(/[^A-Za-z0-9\+\/]/g,""))},noConflict=function(){var e=global.Base64;return global.Base64=_Base64,e};if(global.Base64={VERSION:version,atob:atob,btoa:btoa,fromBase64:decode,toBase64:encode,utob:utob,encode:encode,encodeURI:encodeURI,btou:btou,decode:decode,noConflict:noConflict,__buffer__:buffer},"function"==typeof Object.defineProperty){var noEnum=function(e){return{value:e,enumerable:!1,writable:!0,configurable:!0}};global.Base64.extendString=function(){Object.defineProperty(String.prototype,"fromBase64",noEnum((function(){return decode(this)}))),Object.defineProperty(String.prototype,"toBase64",noEnum((function(e){return encode(this,e)}))),Object.defineProperty(String.prototype,"toBase64URI",noEnum((function(){return encode(this,!0)})))}}return global.Meteor&&(Base64=global.Base64),module.exports?module.exports.Base64=global.Base64:(__WEBPACK_AMD_DEFINE_ARRAY__=[],__WEBPACK_AMD_DEFINE_RESULT__=function(){return global.Base64}.apply(exports,__WEBPACK_AMD_DEFINE_ARRAY__),void 0===__WEBPACK_AMD_DEFINE_RESULT__||(module.exports=__WEBPACK_AMD_DEFINE_RESULT__)),{Base64:global.Base64}}))}).call(this,__webpack_require__(4))},function(e,t,r){"use strict";var n=String.prototype.replace,o=/%20/g,i=r(0),a={RFC1738:"RFC1738",RFC3986:"RFC3986"};e.exports=i.assign({default:a.RFC3986,formatters:{RFC1738:function(e){return n.call(e,o,"+")},RFC3986:function(e){return String(e)}}},a)},function(e,t,r){"use strict";var n=r(5),o=r(6),i=r(2);e.exports={formats:i,parse:o,stringify:n}},function(e,t){var r;r=function(){return this}();try{r=r||new Function("return this")()}catch(e){"object"==typeof window&&(r=window)}e.exports=r},function(e,t,r){"use strict";var n=r(0),o=r(2),i=Object.prototype.hasOwnProperty,a={brackets:function(e){return e+"[]"},comma:"comma",indices:function(e,t){return e+"["+t+"]"},repeat:function(e){return e}},s=Array.isArray,u=Array.prototype.push,c=function(e,t){u.apply(e,s(t)?t:[t])},l=Date.prototype.toISOString,d=o.default,p={addQueryPrefix:!1,allowDots:!1,charset:"utf-8",charsetSentinel:!1,delimiter:"&",encode:!0,encoder:n.encode,encodeValuesOnly:!1,format:d,formatter:o.formatters[d],indices:!1,serializeDate:function(e){return l.call(e)},skipNulls:!1,strictNullHandling:!1},f=function e(t,r,o,i,a,u,l,d,f,h,b,y,v){var m,g=t;if("function"==typeof l?g=l(r,g):g instanceof Date?g=h(g):"comma"===o&&s(g)&&(g=g.join(",")),null===g){if(i)return u&&!y?u(r,p.encoder,v,"key"):r;g=""}if("string"==typeof(m=g)||"number"==typeof m||"boolean"==typeof m||"symbol"==typeof m||"bigint"==typeof m||n.isBuffer(g))return u?[b(y?r:u(r,p.encoder,v,"key"))+"="+b(u(g,p.encoder,v,"value"))]:[b(r)+"="+b(String(g))];var w,R=[];if(void 0===g)return R;if(s(l))w=l;else{var S=Object.keys(g);w=d?S.sort(d):S}for(var A=0;A<w.length;++A){var P=w[A];a&&null===g[P]||(s(g)?c(R,e(g[P],"function"==typeof o?o(r,P):r,o,i,a,u,l,d,f,h,b,y,v)):c(R,e(g[P],r+(f?"."+P:"["+P+"]"),o,i,a,u,l,d,f,h,b,y,v)))}return R};e.exports=function(e,t){var r,n=e,u=function(e){if(!e)return p;if(null!==e.encoder&&void 0!==e.encoder&&"function"!=typeof e.encoder)throw new TypeError("Encoder has to be a function.");var t=e.charset||p.charset;if(void 0!==e.charset&&"utf-8"!==e.charset&&"iso-8859-1"!==e.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var r=o.default;if(void 0!==e.format){if(!i.call(o.formatters,e.format))throw new TypeError("Unknown format option provided.");r=e.format}var n=o.formatters[r],a=p.filter;return("function"==typeof e.filter||s(e.filter))&&(a=e.filter),{addQueryPrefix:"boolean"==typeof e.addQueryPrefix?e.addQueryPrefix:p.addQueryPrefix,allowDots:void 0===e.allowDots?p.allowDots:!!e.allowDots,charset:t,charsetSentinel:"boolean"==typeof e.charsetSentinel?e.charsetSentinel:p.charsetSentinel,delimiter:void 0===e.delimiter?p.delimiter:e.delimiter,encode:"boolean"==typeof e.encode?e.encode:p.encode,encoder:"function"==typeof e.encoder?e.encoder:p.encoder,encodeValuesOnly:"boolean"==typeof e.encodeValuesOnly?e.encodeValuesOnly:p.encodeValuesOnly,filter:a,formatter:n,serializeDate:"function"==typeof e.serializeDate?e.serializeDate:p.serializeDate,skipNulls:"boolean"==typeof e.skipNulls?e.skipNulls:p.skipNulls,sort:"function"==typeof e.sort?e.sort:null,strictNullHandling:"boolean"==typeof e.strictNullHandling?e.strictNullHandling:p.strictNullHandling}}(t);"function"==typeof u.filter?n=(0,u.filter)("",n):s(u.filter)&&(r=u.filter);var l,d=[];if("object"!=typeof n||null===n)return"";l=t&&t.arrayFormat in a?t.arrayFormat:t&&"indices"in t?t.indices?"indices":"repeat":"indices";var h=a[l];r||(r=Object.keys(n)),u.sort&&r.sort(u.sort);for(var b=0;b<r.length;++b){var y=r[b];u.skipNulls&&null===n[y]||c(d,f(n[y],y,h,u.strictNullHandling,u.skipNulls,u.encode?u.encoder:null,u.filter,u.sort,u.allowDots,u.serializeDate,u.formatter,u.encodeValuesOnly,u.charset))}var v=d.join(u.delimiter),m=!0===u.addQueryPrefix?"?":"";return u.charsetSentinel&&("iso-8859-1"===u.charset?m+="utf8=%26%2310003%3B&":m+="utf8=%E2%9C%93&"),v.length>0?m+v:""}},function(e,t,r){"use strict";var n=r(0),o=Object.prototype.hasOwnProperty,i=Array.isArray,a={allowDots:!1,allowPrototypes:!1,arrayLimit:20,charset:"utf-8",charsetSentinel:!1,comma:!1,decoder:n.decode,delimiter:"&",depth:5,ignoreQueryPrefix:!1,interpretNumericEntities:!1,parameterLimit:1e3,parseArrays:!0,plainObjects:!1,strictNullHandling:!1},s=function(e){return e.replace(/&#(\d+);/g,(function(e,t){return String.fromCharCode(parseInt(t,10))}))},u=function(e,t){return e&&"string"==typeof e&&t.comma&&e.indexOf(",")>-1?e.split(","):e},c=function(e,t){if(i(e)){for(var r=[],n=0;n<e.length;n+=1)r.push(t(e[n]));return r}return t(e)},l=function(e,t,r,n){if(e){var i=r.allowDots?e.replace(/\.([^.[]+)/g,"[$1]"):e,a=/(\[[^[\]]*])/g,s=r.depth>0&&/(\[[^[\]]*])/.exec(i),c=s?i.slice(0,s.index):i,l=[];if(c){if(!r.plainObjects&&o.call(Object.prototype,c)&&!r.allowPrototypes)return;l.push(c)}for(var d=0;r.depth>0&&null!==(s=a.exec(i))&&d<r.depth;){if(d+=1,!r.plainObjects&&o.call(Object.prototype,s[1].slice(1,-1))&&!r.allowPrototypes)return;l.push(s[1])}return s&&l.push("["+i.slice(s.index)+"]"),function(e,t,r,n){for(var o=n?t:u(t,r),i=e.length-1;i>=0;--i){var a,s=e[i];if("[]"===s&&r.parseArrays)a=[].concat(o);else{a=r.plainObjects?Object.create(null):{};var c="["===s.charAt(0)&&"]"===s.charAt(s.length-1)?s.slice(1,-1):s,l=parseInt(c,10);r.parseArrays||""!==c?!isNaN(l)&&s!==c&&String(l)===c&&l>=0&&r.parseArrays&&l<=r.arrayLimit?(a=[])[l]=o:a[c]=o:a={0:o}}o=a}return o}(l,t,r,n)}};e.exports=function(e,t){var r=function(e){if(!e)return a;if(null!==e.decoder&&void 0!==e.decoder&&"function"!=typeof e.decoder)throw new TypeError("Decoder has to be a function.");if(void 0!==e.charset&&"utf-8"!==e.charset&&"iso-8859-1"!==e.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var t=void 0===e.charset?a.charset:e.charset;return{allowDots:void 0===e.allowDots?a.allowDots:!!e.allowDots,allowPrototypes:"boolean"==typeof e.allowPrototypes?e.allowPrototypes:a.allowPrototypes,arrayLimit:"number"==typeof e.arrayLimit?e.arrayLimit:a.arrayLimit,charset:t,charsetSentinel:"boolean"==typeof e.charsetSentinel?e.charsetSentinel:a.charsetSentinel,comma:"boolean"==typeof e.comma?e.comma:a.comma,decoder:"function"==typeof e.decoder?e.decoder:a.decoder,delimiter:"string"==typeof e.delimiter||n.isRegExp(e.delimiter)?e.delimiter:a.delimiter,depth:"number"==typeof e.depth||!1===e.depth?+e.depth:a.depth,ignoreQueryPrefix:!0===e.ignoreQueryPrefix,interpretNumericEntities:"boolean"==typeof e.interpretNumericEntities?e.interpretNumericEntities:a.interpretNumericEntities,parameterLimit:"number"==typeof e.parameterLimit?e.parameterLimit:a.parameterLimit,parseArrays:!1!==e.parseArrays,plainObjects:"boolean"==typeof e.plainObjects?e.plainObjects:a.plainObjects,strictNullHandling:"boolean"==typeof e.strictNullHandling?e.strictNullHandling:a.strictNullHandling}}(t);if(""===e||null==e)return r.plainObjects?Object.create(null):{};for(var d="string"==typeof e?function(e,t){var r,l={},d=t.ignoreQueryPrefix?e.replace(/^\?/,""):e,p=t.parameterLimit===1/0?void 0:t.parameterLimit,f=d.split(t.delimiter,p),h=-1,b=t.charset;if(t.charsetSentinel)for(r=0;r<f.length;++r)0===f[r].indexOf("utf8=")&&("utf8=%E2%9C%93"===f[r]?b="utf-8":"utf8=%26%2310003%3B"===f[r]&&(b="iso-8859-1"),h=r,r=f.length);for(r=0;r<f.length;++r)if(r!==h){var y,v,m=f[r],g=m.indexOf("]="),w=-1===g?m.indexOf("="):g+1;-1===w?(y=t.decoder(m,a.decoder,b,"key"),v=t.strictNullHandling?null:""):(y=t.decoder(m.slice(0,w),a.decoder,b,"key"),v=c(u(m.slice(w+1),t),(function(e){return t.decoder(e,a.decoder,b,"value")}))),v&&t.interpretNumericEntities&&"iso-8859-1"===b&&(v=s(v)),m.indexOf("[]=")>-1&&(v=i(v)?[v]:v),o.call(l,y)?l[y]=n.combine(l[y],v):l[y]=v}return l}(e,r):e,p=r.plainObjects?Object.create(null):{},f=Object.keys(d),h=0;h<f.length;++h){var b=f[h],y=l(b,d[b],r,"string"==typeof e);p=n.merge(p,y,r)}return n.compact(p)}},function(e,t,r){"use strict";r.r(t),r.d(t,"errorResponseHandler",(function(){return C})),r.d(t,"KintoneRestAPIClientDingTalkMP",(function(){return N}));var n,o=function(e){var t=e.endpointName,r=e.guestSpaceId;return"/k"+(void 0!==r?"/guest/"+r:"")+"/v1"+(e.preview?"/preview":"")+"/"+t+".json"},i=function(){return(i=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},a=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(r[n[o]]=e[n[o]])}return r},s=function(){function e(e,t){this.client=e,this.guestSpaceId=t,this.REQUESTS_LENGTH_LIMIT=20}return e.prototype.send=function(e){var t=this,r=e.requests.map((function(e){if("endpointName"in e){var r=e.endpointName,n=a(e,["endpointName"]);return i({api:t.buildPathWithGuestSpaceId({endpointName:r})},n)}return e})),n=this.buildPathWithGuestSpaceId({endpointName:"bulkRequest"});return this.client.post(n,{requests:r})},e.prototype.buildPathWithGuestSpaceId=function(e){return o(i(i({},e),{guestSpaceId:this.guestSpaceId}))},e}(),u=(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)},function(e,t){function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}),c=function(e){function t(r,n,o,i,a){var s=this,u=o-n.length,c=t.extractErrorIndex(u,i,a),l=t.buildErrorMessage(u,o,c);return(s=e.call(this,l)||this).name="KintoneAllRecordsError",s.processedRecordsResult=r,s.unprocessedRecords=n,s.error=i,s.errorIndex=c,s.message=l,Object.setPrototypeOf(s,t.prototype),s}return u(t,e),t.parseErrorIndex=function(e){var t=Object.keys(e)[0].match(/records\[(\d+)\]/);return t?Number(t[1]):null},t.extractErrorIndex=function(e,r,n){if(void 0!==r.bulkRequestIndex&&r.errors){var o=t.parseErrorIndex(r.errors);if(null!==o)return e+r.bulkRequestIndex*n+o}},t.buildErrorMessage=function(e,t,r){var n="";return void 0!==r&&(n="An error occurred at records["+r+"]. "),n+=e+"/"+t+" records are processed successfully"},t}(Error),l=function(){return(l=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},d=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},p=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}},f=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(r[n[o]]=e[n[o]])}return r},h=function(){for(var e=0,t=0,r=arguments.length;t<r;t++)e+=arguments[t].length;var n=Array(e),o=0;for(t=0;t<r;t++)for(var i=arguments[t],a=0,s=i.length;a<s;a++,o++)n[o]=i[a];return n},b=function(){function e(e,t,r){this.client=e,this.bulkRequestClient=t,this.guestSpaceId=r,this.didWarnMaximumOffsetValue=!1}return e.prototype.getRecord=function(e){var t=this.buildPathWithGuestSpaceId({endpointName:"record"});return this.client.get(t,e)},e.prototype.addRecord=function(e){var t=this.buildPathWithGuestSpaceId({endpointName:"record"});return this.client.post(t,e)},e.prototype.updateRecord=function(e){var t=this.buildPathWithGuestSpaceId({endpointName:"record"});return this.client.put(t,e)},e.prototype.upsertRecord=function(e){return d(this,void 0,void 0,(function(){var t,r,n,o,i,a;return p(this,(function(s){switch(s.label){case 0:return t=e.app,r=e.updateKey,n=e.record,[4,this.getRecords({app:t,query:r.field+' = "'+r.value+'"'})];case 1:return(o=s.sent().records).length>0?[4,this.updateRecord(e)]:[3,3];case 2:return i=s.sent().revision,[2,{id:o[0].$id.value,revision:i}];case 3:return[2,this.addRecord({app:t,record:l(l({},n),(a={},a[r.field]={value:r.value},a))})]}}))}))},e.prototype.getRecords=function(e){var t=this.buildPathWithGuestSpaceId({endpointName:"records"});if(e.query){var r=e.query.match(/offset\s+(\d+)/i);!this.didWarnMaximumOffsetValue&&r&&Number(r[1])>1e4&&(this.didWarnMaximumOffsetValue=!0,console.warn("Warning: The maximum offset value will be limited to 10,000 in the future. Please use `createCursor()` and `getRecordsByCursor()` instead."))}return this.client.get(t,e)},e.prototype.addRecords=function(e){return d(this,void 0,void 0,(function(){var t,r,n,o;return p(this,(function(i){switch(i.label){case 0:return t=this.buildPathWithGuestSpaceId({endpointName:"records"}),[4,this.client.post(t,e)];case 1:return r=i.sent(),n=r.ids,o=r.revisions,[2,{ids:n,revisions:o,records:n.map((function(e,t){return{id:e,revision:o[t]}}))}]}}))}))},e.prototype.updateRecords=function(e){var t=this.buildPathWithGuestSpaceId({endpointName:"records"});return this.client.put(t,e)},e.prototype.deleteRecords=function(e){var t=this.buildPathWithGuestSpaceId({endpointName:"records"});return this.client.delete(t,e)},e.prototype.createCursor=function(e){var t=this.buildPathWithGuestSpaceId({endpointName:"records/cursor"});return this.client.post(t,e)},e.prototype.getRecordsByCursor=function(e){var t=this.buildPathWithGuestSpaceId({endpointName:"records/cursor"});return this.client.get(t,e)},e.prototype.deleteCursor=function(e){var t=this.buildPathWithGuestSpaceId({endpointName:"records/cursor"});return this.client.delete(t,e)},e.prototype.getAllRecords=function(e){return d(this,void 0,void 0,(function(){var t,r,n,o,i,a;return p(this,(function(s){return t=e.condition,r=e.orderBy,n=e.withCursor,o=void 0===n||n,i=f(e,["condition","orderBy","withCursor"]),r?o?(a=(t?t+" ":"")+(r?"order by "+r:""),[2,this.getAllRecordsWithCursor(l(l({},i),{query:a}))]):[2,this.getAllRecordsWithOffset(l(l({},i),{orderBy:r,condition:t}))]:[2,this.getAllRecordsWithId(l(l({},i),{condition:t}))]}))}))},e.prototype.getAllRecordsWithId=function(e){return d(this,void 0,void 0,(function(){var t,r,n;return p(this,(function(o){return t=e.fields,r=f(e,["fields"]),(n=t)&&n.length>0&&-1===n.indexOf("$id")&&(n=h(n,["$id"])),[2,this.getAllRecordsRecursiveWithId(l(l({},r),{fields:n}),0,[])]}))}))},e.prototype.getAllRecordsRecursiveWithId=function(e,t,r){return d(this,void 0,void 0,(function(){var n,o,i,a,s,u,c;return p(this,(function(d){switch(d.label){case 0:return n=500,o=e.condition,i=f(e,["condition"]),a=(o?o+" and ":"")+"$id > "+t+" order by $id asc limit "+n,[4,this.getRecords(l(l({},i),{query:a}))];case 1:return s=d.sent(),u=r.concat(s.records),s.records.length<n?[2,u]:(c=s.records[s.records.length-1].$id.value,[2,this.getAllRecordsRecursiveWithId(e,c,u)])}}))}))},e.prototype.getAllRecordsWithOffset=function(e){return d(this,void 0,void 0,(function(){return p(this,(function(t){return[2,this.getAllRecordsRecursiveWithOffset(e,0,[])]}))}))},e.prototype.getAllRecordsRecursiveWithOffset=function(e,t,r){return d(this,void 0,void 0,(function(){var n,o,i,a,s,u,c;return p(this,(function(d){switch(d.label){case 0:return n=500,o=e.condition,i=e.orderBy,a=f(e,["condition","orderBy"]),s=(o?o+" ":"")+(i?"order by "+i+" ":"")+"limit "+n+" offset "+t,[4,this.getRecords(l(l({},a),{query:s}))];case 1:return u=d.sent(),c=r.concat(u.records),u.records.length<n?[2,c]:[2,this.getAllRecordsRecursiveWithOffset(e,t+n,c)]}}))}))},e.prototype.getAllRecordsWithCursor=function(e){return d(this,void 0,void 0,(function(){var t,r;return p(this,(function(n){switch(n.label){case 0:return[4,this.createCursor(e)];case 1:t=n.sent().id,n.label=2;case 2:return n.trys.push([2,4,,5]),[4,this.getAllRecordsRecursiveByCursor(t,[])];case 3:return[2,n.sent()];case 4:throw r=n.sent(),this.deleteCursor({id:t}),r;case 5:return[2]}}))}))},e.prototype.getAllRecordsRecursiveByCursor=function(e,t){return d(this,void 0,void 0,(function(){var r,n;return p(this,(function(o){switch(o.label){case 0:return[4,this.getRecordsByCursor({id:e})];case 1:return r=o.sent(),n=t.concat(r.records),r.next?[2,this.getAllRecordsRecursiveByCursor(e,n)]:[2,n]}}))}))},e.prototype.addAllRecords=function(e){return d(this,void 0,void 0,(function(){return p(this,(function(t){if(!e.records.every((function(e){return!Array.isArray(e)&&e instanceof Object})))throw new Error("the `records` parameter must be an array of object.");return[2,this.addAllRecordsRecursive(e,e.records.length,[])]}))}))},e.prototype.addAllRecordsRecursive=function(e,t,r){return d(this,void 0,void 0,(function(){var n,o,i,a,s,u;return p(this,(function(l){switch(l.label){case 0:if(n=100*this.bulkRequestClient.REQUESTS_LENGTH_LIMIT,o=e.app,i=e.records,0===(a=i.slice(0,n)).length)return[2,{records:r}];l.label=1;case 1:return l.trys.push([1,3,,4]),[4,this.addAllRecordsWithBulkRequest({app:o,records:a})];case 2:return s=l.sent(),[3,4];case 3:throw u=l.sent(),new c({records:r},i,t,u,100);case 4:return[2,this.addAllRecordsRecursive({app:o,records:i.slice(n)},t,r.concat(s))]}}))}))},e.prototype.addAllRecordsWithBulkRequest=function(e){return d(this,void 0,void 0,(function(){var t,r,n=this;return p(this,(function(o){switch(o.label){case 0:return t=this.separateArrayRecursive(100,[],e.records),r=t.map((function(t){return{method:"POST",api:n.buildPathWithGuestSpaceId({endpointName:"records"}),payload:{app:e.app,records:t}}})),[4,this.bulkRequestClient.send({requests:r})];case 1:return[2,o.sent().results.map((function(e){var t=e.ids,r=e.revisions;return t.map((function(e,t){return{id:e,revision:r[t]}}))})).reduce((function(e,t){return e.concat(t)}),[])]}}))}))},e.prototype.updateAllRecords=function(e){return d(this,void 0,void 0,(function(){return p(this,(function(t){return[2,this.updateAllRecordsRecursive(e,e.records.length,[])]}))}))},e.prototype.updateAllRecordsRecursive=function(e,t,r){return d(this,void 0,void 0,(function(){var n,o,i,a,s,u;return p(this,(function(l){switch(l.label){case 0:if(n=100*this.bulkRequestClient.REQUESTS_LENGTH_LIMIT,o=e.app,i=e.records,0===(a=i.slice(0,n)).length)return[2,{records:r}];l.label=1;case 1:return l.trys.push([1,3,,4]),[4,this.updateAllRecordsWithBulkRequest({app:o,records:a})];case 2:return s=l.sent(),[3,4];case 3:throw u=l.sent(),new c({records:r},i,t,u,100);case 4:return[2,this.updateAllRecordsRecursive({app:o,records:i.slice(n)},t,r.concat(s))]}}))}))},e.prototype.updateAllRecordsWithBulkRequest=function(e){return d(this,void 0,void 0,(function(){var t,r,n=this;return p(this,(function(o){switch(o.label){case 0:return t=this.separateArrayRecursive(100,[],e.records),r=t.map((function(t){return{method:"PUT",api:n.buildPathWithGuestSpaceId({endpointName:"records"}),payload:{app:e.app,records:t}}})),[4,this.bulkRequestClient.send({requests:r})];case 1:return[2,o.sent().results.map((function(e){return e.records})).reduce((function(e,t){return e.concat(t)}),[])]}}))}))},e.prototype.deleteAllRecords=function(e){return this.deleteAllRecordsRecursive(e,e.records.length)},e.prototype.deleteAllRecordsRecursive=function(e,t){return d(this,void 0,void 0,(function(){var r,n,o,i,a;return p(this,(function(s){switch(s.label){case 0:if(r=100*this.bulkRequestClient.REQUESTS_LENGTH_LIMIT,n=e.app,o=e.records,0===(i=o.slice(0,r)).length)return[2,{}];s.label=1;case 1:return s.trys.push([1,3,,4]),[4,this.deleteAllRecordsWithBulkRequest({app:n,records:i})];case 2:return s.sent(),[3,4];case 3:throw a=s.sent(),new c({},o,t,a,100);case 4:return[2,this.deleteAllRecordsRecursive({app:n,records:o.slice(r)},t)]}}))}))},e.prototype.deleteAllRecordsWithBulkRequest=function(e){return d(this,void 0,void 0,(function(){var t,r,n=this;return p(this,(function(o){switch(o.label){case 0:return t=this.separateArrayRecursive(100,[],e.records),r=t.map((function(t){return{method:"DELETE",api:n.buildPathWithGuestSpaceId({endpointName:"records"}),payload:{app:e.app,ids:t.map((function(e){return e.id})),revisions:t.map((function(e){return e.revision}))}}})),[4,this.bulkRequestClient.send({requests:r})];case 1:return o.sent(),[2]}}))}))},e.prototype.separateArrayRecursive=function(e,t,r){var n=r.slice(0,e);return 0===n.length?t:this.separateArrayRecursive(e,h(t,[n]),r.slice(e))},e.prototype.addRecordComment=function(e){var t=this.buildPathWithGuestSpaceId({endpointName:"record/comment"});return this.client.post(t,e)},e.prototype.deleteRecordComment=function(e){var t=this.buildPathWithGuestSpaceId({endpointName:"record/comment"});return this.client.delete(t,e)},e.prototype.getRecordComments=function(e){var t=this.buildPathWithGuestSpaceId({endpointName:"record/comments"});return this.client.get(t,e)},e.prototype.updateRecordAssignees=function(e){var t=this.buildPathWithGuestSpaceId({endpointName:"record/assignees"});return this.client.put(t,e)},e.prototype.updateRecordStatus=function(e){var t=this.buildPathWithGuestSpaceId({endpointName:"record/status"});return this.client.put(t,e)},e.prototype.updateRecordsStatus=function(e){var t=this.buildPathWithGuestSpaceId({endpointName:"records/status"});return this.client.put(t,e)},e.prototype.buildPathWithGuestSpaceId=function(e){return o(l(l({},e),{guestSpaceId:this.guestSpaceId}))},e}(),y=function(){return(y=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},v=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},m=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}},g=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(r[n[o]]=e[n[o]])}return r},w=function(){function e(e,t){this.client=e,this.guestSpaceId=t}return e.prototype.getFormFields=function(e){var t=e.preview,r=g(e,["preview"]),n=this.buildPathWithGuestSpaceId({endpointName:"app/form/fields",preview:t});return this.client.get(n,y({},r))},e.prototype.addFormFields=function(e){var t=this.buildPathWithGuestSpaceId({endpointName:"app/form/fields",preview:!0});return this.client.post(t,e)},e.prototype.updateFormFields=function(e){var t=this.buildPathWithGuestSpaceId({endpointName:"app/form/fields",preview:!0});return this.client.put(t,e)},e.prototype.deleteFormFields=function(e){var t=this.buildPathWithGuestSpaceId({endpointName:"app/form/fields",preview:!0});return this.client.delete(t,e)},e.prototype.getFormLayout=function(e){var t=e.preview,r=g(e,["preview"]),n=this.buildPathWithGuestSpaceId({endpointName:"app/form/layout",preview:t});return this.client.get(n,y({},r))},e.prototype.updateFormLayout=function(e){var t=this.buildPathWithGuestSpaceId({endpointName:"app/form/layout",preview:!0});return this.client.put(t,e)},e.prototype.getViews=function(e){var t=e.preview,r=g(e,["preview"]),n=this.buildPathWithGuestSpaceId({endpointName:"app/views",preview:t});return this.client.get(n,r)},e.prototype.updateViews=function(e){var t=this.buildPathWithGuestSpaceId({endpointName:"app/views",preview:!0});return this.client.put(t,e)},e.prototype.getApp=function(e){var t=this.buildPathWithGuestSpaceId({endpointName:"app"});return this.client.get(t,e)},e.prototype.getApps=function(e){var t=this.buildPathWithGuestSpaceId({endpointName:"apps"});return this.client.get(t,e)},e.prototype.addApp=function(e){return v(this,void 0,void 0,(function(){var t,r,n,o,i;return m(this,(function(a){switch(a.label){case 0:return t=e.name,r=e.space,n=this.buildPathWithGuestSpaceId({endpointName:"app",preview:!0}),r?(o=this.buildPathWithGuestSpaceId({endpointName:"space"}),[4,this.client.get(o,{id:r})]):[3,2];case 1:return i=a.sent().defaultThread,[2,this.client.post(n,y(y({},e),{thread:i}))];case 2:return[2,this.client.post(n,{name:t})]}}))}))},e.prototype.getAppSettings=function(e){var t=e.preview,r=g(e,["preview"]),n=this.buildPathWithGuestSpaceId({endpointName:"app/settings",preview:t});return this.client.get(n,r)},e.prototype.updateAppSettings=function(e){var t=this.buildPathWithGuestSpaceId({endpointName:"app/settings",preview:!0});return this.client.put(t,e)},e.prototype.getProcessManagement=function(e){var t=e.preview,r=g(e,["preview"]),n=this.buildPathWithGuestSpaceId({endpointName:"app/status",preview:t});return this.client.get(n,r)},e.prototype.updateProcessManagement=function(e){var t=this.buildPathWithGuestSpaceId({endpointName:"app/status",preview:!0});return this.client.put(t,e)},e.prototype.getDeployStatus=function(e){var t=this.buildPathWithGuestSpaceId({endpointName:"app/deploy",preview:!0});return this.client.get(t,e)},e.prototype.deployApp=function(e){var t=this.buildPathWithGuestSpaceId({endpointName:"app/deploy",preview:!0});return this.client.post(t,e)},e.prototype.getFieldAcl=function(e){var t=e.preview,r=g(e,["preview"]),n=this.buildPathWithGuestSpaceId({endpointName:"field/acl",preview:t});return this.client.get(n,y({},r))},e.prototype.updateFieldAcl=function(e){var t=this.buildPathWithGuestSpaceId({endpointName:"field/acl",preview:!0});return this.client.put(t,e)},e.prototype.getAppAcl=function(e){var t=e.preview,r=g(e,["preview"]),n=this.buildPathWithGuestSpaceId({endpointName:"app/acl",preview:t});return this.client.get(n,y({},r))},e.prototype.updateAppAcl=function(e){var t=this.buildPathWithGuestSpaceId({endpointName:"app/acl",preview:!0});return this.client.put(t,e)},e.prototype.evaluateRecordsAcl=function(e){var t=this.buildPathWithGuestSpaceId({endpointName:"records/acl/evaluate"});return this.client.get(t,e)},e.prototype.getRecordAcl=function(e){var t=e.preview,r=g(e,["preview"]),n=this.buildPathWithGuestSpaceId({endpointName:"record/acl",preview:t});return this.client.get(n,y({},r))},e.prototype.updateRecordAcl=function(e){var t=this.buildPathWithGuestSpaceId({endpointName:"record/acl",preview:!0});return this.client.put(t,e)},e.prototype.getAppCustomize=function(e){var t=e.preview,r=g(e,["preview"]),n=this.buildPathWithGuestSpaceId({endpointName:"app/customize",preview:t});return this.client.get(n,y({},r))},e.prototype.updateAppCustomize=function(e){var t=this.buildPathWithGuestSpaceId({endpointName:"app/customize",preview:!0});return this.client.put(t,e)},e.prototype.buildPathWithGuestSpaceId=function(e){return o(y(y({},e),{guestSpaceId:this.guestSpaceId}))},e}();class R{constructor(e,t){this.client=e,this.guestSpaceId=t}async uploadFile(e){const t=this.buildPathWithGuestSpaceId({endpointName:"file"});if("object"!=typeof e||void 0===e.filePath)throw new Error("in DingTalk environment, filePath is required");return this.client.uploadFile(t,e)}async downloadFile(e){const t=this.buildPathWithGuestSpaceId({endpointName:"file"});return this.client.downloadFile(t,e)}buildPathWithGuestSpaceId(e){return o({...e,guestSpaceId:this.guestSpaceId})}}var S=r(1),A=function(){var e=function(t,r){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(t,r)};return function(t,r){function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),P=function(e){function t(r){var n=this,o=t.buildErrorResponseDateWithIndex(r),i=o.data,a=o.bulkRequestIndex;return(n=e.call(this,i.message)||this).name="KintoneRestAPIError",n.id=i.id,n.code=i.code,n.errors=i.errors,n.status=r.status,n.bulkRequestIndex=a,n.headers=r.headers,n.message="["+r.status+"] ["+n.code+"] "+n.message+" ("+n.id+")",Error.captureStackTrace&&Error.captureStackTrace(n,t),Object.setPrototypeOf(n,t.prototype),n}return A(t,e),t.findErrorResponseDataWithIndex=function(e){for(var t=0;t<e.length;t++){if(0!==Object.keys(e[t]).length)return{data:e[t],bulkRequestIndex:t}}throw Error("Missing response data in `results`. This error is likely caused by a bug in Kintone REST API Client. Please file an issue.")},t.buildErrorResponseDateWithIndex=function(e){return"results"in e.data?t.findErrorResponseDataWithIndex(e.data.results):{data:e.data}},t}(Error),O=r(3),I=r.n(O);class _{constructor({baseUrl:e,headers:t,params:r,errorResponseHandler:n}){this.baseUrl=e,this.headers=t,this.params=r,this.errorResponseHandler=n}async get(e,t){const r=this.buildRequestConfig("get",e,t);return this.sendRequest(r)}async post(e,t){const r=this.buildRequestConfig("post",e,t);return this.sendRequest(r)}async put(e,t){const r=this.buildRequestConfig("put",e,t);return this.sendRequest(r)}async delete(e,t){const r=this.buildRequestConfig("delete",e,t);return this.sendRequest(r)}async downloadFile(e,t){const r=this.buildRequestConfig("get",e,t,{fileMethod:"download"});return this.sendRequest(r)}async uploadFile(e,t){const r=this.buildRequestConfig("post",e,{},{filePath:t.filePath,fileName:"file",fileType:"image",fileMethod:"upload"});return this.sendRequest(r)}async sendRequest(e){let t;try{t=await this.ddSendRequest(e)}catch(e){this.errorResponseHandler(e)}return t}callDdAPI(e){switch(e.fileMethod){case"download":return dd.downloadFile(e);case"upload":return dd.uploadFile(e);default:return dd.httpRequest(e)}}ddSendRequest(e){return new Promise((t,r)=>{switch(e.fail=e=>{r(e)},e.fileMethod){case"download":e.success=e=>{t({filePath:e.filePath})};break;case"upload":e.success=e=>{200===e.statusCode?t(JSON.parse(e.data)):r({...e,data:JSON.parse(e.data)})};break;default:e.success=e=>{200===e.status?t(e.data):r(e)}}this.callDdAPI(e)})}buildRequestConfig(e,t,r,n){const o={method:e,header:this.headers,headers:this.headers,url:`${this.baseUrl}${t}`,...n||{}};switch(e){case"get":{const e=this.buildRequestUrl(t,r);return e.length>4096?{...o,method:"post",header:{...this.headers,"X-HTTP-Method-Override":"GET"},data:{...this.params,...r}}:{...o,header:{...this.headers,"content-type":"application/html"},url:e}}case"post":case"put":case"delete":return{...o,headers:{...this.headers,"content-type":"application/json"},data:JSON.stringify({...this.params,...r})};default:throw new Error(e+" method is not supported")}}buildRequestUrl(e,t){return`${this.baseUrl}${e}?${I.a.stringify(t)}`}}const C=e=>{if(!e.data)throw new Error(e.error);throw new P(e)};class N{constructor(e={}){const t="baseUrl"in e?e.baseUrl:"",r="auth"in e?e.auth:{},{guestSpaceId:n}=e,{basicAuth:o}=e,i=this.buildAuth(r);if(this.headers=this.buildHeaders(i,o),this.baseUrl=t,""===this.baseUrl)throw new Error("in DingTalk environment, baseUrl is required");const a=new _({baseUrl:this.baseUrl,headers:this.headers,params:{},errorResponseHandler:C});this.bulkRequest_=new s(a,n),this.record=new b(a,this.bulkRequest_,n),this.app=new w(a,n),this.file=new R(a,n)}getBaseUrl(){return this.baseUrl}getHeaders(){return this.headers}buildAuth(e){if("username"in e)return{type:"password",...e};if("apiToken"in e)return{type:"apiToken",...e};throw new Error("in DingTalk environment, auth is required")}buildHeaders(e,t){const r=t?{Authorization:"Basic "+S.Base64.encode(`${t.username}:${t.password}`)}:{};switch(e.type){case"password":return{...r,"X-Cybozu-Authorization":S.Base64.encode(`${e.username}:${e.password}`)};case"apiToken":return Array.isArray(e.apiToken)?{...r,"X-Cybozu-API-Token":e.apiToken.join(",")}:{...r,"X-Cybozu-API-Token":e.apiToken};default:return{...r}}}bulkRequest(e){return this.bulkRequest_.send(e)}}}]);