UNPKG

@kintone/rest-api-client-wechat-mp

Version:
1 lines 38 kB
module.exports=function(e){var t={};function r(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,r),i.l=!0,i.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 i in e)r.d(n,i,function(t){return e[t]}.bind(null,i));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=5)}([function(e,t,r){"use strict";var n=Object.prototype.hasOwnProperty,i=Array.isArray,o=function(){for(var e=[],t=0;t<256;++t)e.push("%"+((t<16?"0":"")+t.toString(16)).toUpperCase());return e}(),s=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:s,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 o=t[n],s=o.obj[o.prop],a=Object.keys(s),u=0;u<a.length;++u){var c=a[u],l=s[c];"object"==typeof l&&null!==l&&-1===r.indexOf(l)&&(t.push({obj:s,prop:c}),r.push(l))}return function(e){for(;e.length>1;){var t=e.pop(),r=t.obj[t.prop];if(i(r)){for(var n=[],o=0;o<r.length;++o)void 0!==r[o]&&n.push(r[o]);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 i="",s=0;s<n.length;++s){var a=n.charCodeAt(s);45===a||46===a||95===a||126===a||a>=48&&a<=57||a>=65&&a<=90||a>=97&&a<=122?i+=n.charAt(s):a<128?i+=o[a]:a<2048?i+=o[192|a>>6]+o[128|63&a]:a<55296||a>=57344?i+=o[224|a>>12]+o[128|a>>6&63]+o[128|63&a]:(s+=1,a=65536+((1023&a)<<10|1023&n.charCodeAt(s)),i+=o[240|a>>18]+o[128|a>>12&63]+o[128|a>>6&63]+o[128|63&a])}return i},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)},maybeMap: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)},merge:function e(t,r,o){if(!r)return t;if("object"!=typeof r){if(i(t))t.push(r);else{if(!t||"object"!=typeof t)return[t,r];(o&&(o.plainObjects||o.allowPrototypes)||!n.call(Object.prototype,r))&&(t[r]=!0)}return t}if(!t||"object"!=typeof t)return[t].concat(r);var a=t;return i(t)&&!i(r)&&(a=s(t,o)),i(t)&&i(r)?(r.forEach((function(r,i){if(n.call(t,i)){var s=t[i];s&&"object"==typeof s&&r&&"object"==typeof r?t[i]=e(s,r,o):t.push(r)}else t[i]=r})),t):Object.keys(r).reduce((function(t,i){var s=r[i];return n.call(t,i)?t[i]=e(t[i],s,o):t[i]=s,t}),a)}}},function(e,t,r){"use strict";var n=String.prototype.replace,i=/%20/g,o=r(0),s={RFC1738:"RFC1738",RFC3986:"RFC3986"};e.exports=o.assign({default:s.RFC3986,formatters:{RFC1738:function(e){return n.call(e,i,"+")},RFC3986:function(e){return String(e)}}},s)},function(e,t,r){"use strict";var n=r(3),i=r(4),o=r(1);e.exports={formats:o,parse:i,stringify:n}},function(e,t,r){"use strict";var n=r(0),i=r(1),o=Object.prototype.hasOwnProperty,s={brackets:function(e){return e+"[]"},comma:"comma",indices:function(e,t){return e+"["+t+"]"},repeat:function(e){return e}},a=Array.isArray,u=Array.prototype.push,c=function(e,t){u.apply(e,a(t)?t:[t])},l=Date.prototype.toISOString,p=i.default,d={addQueryPrefix:!1,allowDots:!1,charset:"utf-8",charsetSentinel:!1,delimiter:"&",encode:!0,encoder:n.encode,encodeValuesOnly:!1,format:p,formatter:i.formatters[p],indices:!1,serializeDate:function(e){return l.call(e)},skipNulls:!1,strictNullHandling:!1},h=function e(t,r,i,o,s,u,l,p,h,f,y,v,b){var m,g=t;if("function"==typeof l?g=l(r,g):g instanceof Date?g=f(g):"comma"===i&&a(g)&&(g=n.maybeMap(g,(function(e){return e instanceof Date?f(e):e})).join(",")),null===g){if(o)return u&&!v?u(r,d.encoder,b,"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?[y(v?r:u(r,d.encoder,b,"key"))+"="+y(u(g,d.encoder,b,"value"))]:[y(r)+"="+y(String(g))];var w,R=[];if(void 0===g)return R;if(a(l))w=l;else{var S=Object.keys(g);w=p?S.sort(p):S}for(var P=0;P<w.length;++P){var O=w[P],I=g[O];if(!s||null!==I){var A=a(g)?"function"==typeof i?i(r,O):r:r+(h?"."+O:"["+O+"]");c(R,e(I,A,i,o,s,u,l,p,h,f,y,v,b))}}return R};e.exports=function(e,t){var r,n=e,u=function(e){if(!e)return d;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||d.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=i.default;if(void 0!==e.format){if(!o.call(i.formatters,e.format))throw new TypeError("Unknown format option provided.");r=e.format}var n=i.formatters[r],s=d.filter;return("function"==typeof e.filter||a(e.filter))&&(s=e.filter),{addQueryPrefix:"boolean"==typeof e.addQueryPrefix?e.addQueryPrefix:d.addQueryPrefix,allowDots:void 0===e.allowDots?d.allowDots:!!e.allowDots,charset:t,charsetSentinel:"boolean"==typeof e.charsetSentinel?e.charsetSentinel:d.charsetSentinel,delimiter:void 0===e.delimiter?d.delimiter:e.delimiter,encode:"boolean"==typeof e.encode?e.encode:d.encode,encoder:"function"==typeof e.encoder?e.encoder:d.encoder,encodeValuesOnly:"boolean"==typeof e.encodeValuesOnly?e.encodeValuesOnly:d.encodeValuesOnly,filter:s,formatter:n,serializeDate:"function"==typeof e.serializeDate?e.serializeDate:d.serializeDate,skipNulls:"boolean"==typeof e.skipNulls?e.skipNulls:d.skipNulls,sort:"function"==typeof e.sort?e.sort:null,strictNullHandling:"boolean"==typeof e.strictNullHandling?e.strictNullHandling:d.strictNullHandling}}(t);"function"==typeof u.filter?n=(0,u.filter)("",n):a(u.filter)&&(r=u.filter);var l,p=[];if("object"!=typeof n||null===n)return"";l=t&&t.arrayFormat in s?t.arrayFormat:t&&"indices"in t?t.indices?"indices":"repeat":"indices";var f=s[l];r||(r=Object.keys(n)),u.sort&&r.sort(u.sort);for(var y=0;y<r.length;++y){var v=r[y];u.skipNulls&&null===n[v]||c(p,h(n[v],v,f,u.strictNullHandling,u.skipNulls,u.encode?u.encoder:null,u.filter,u.sort,u.allowDots,u.serializeDate,u.formatter,u.encodeValuesOnly,u.charset))}var b=p.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&"),b.length>0?m+b:""}},function(e,t,r){"use strict";var n=r(0),i=Object.prototype.hasOwnProperty,o=Array.isArray,s={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},a=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,r,n){if(e){var o=r.allowDots?e.replace(/\.([^.[]+)/g,"[$1]"):e,s=/(\[[^[\]]*])/g,a=r.depth>0&&/(\[[^[\]]*])/.exec(o),c=a?o.slice(0,a.index):o,l=[];if(c){if(!r.plainObjects&&i.call(Object.prototype,c)&&!r.allowPrototypes)return;l.push(c)}for(var p=0;r.depth>0&&null!==(a=s.exec(o))&&p<r.depth;){if(p+=1,!r.plainObjects&&i.call(Object.prototype,a[1].slice(1,-1))&&!r.allowPrototypes)return;l.push(a[1])}return a&&l.push("["+o.slice(a.index)+"]"),function(e,t,r,n){for(var i=n?t:u(t,r),o=e.length-1;o>=0;--o){var s,a=e[o];if("[]"===a&&r.parseArrays)s=[].concat(i);else{s=r.plainObjects?Object.create(null):{};var c="["===a.charAt(0)&&"]"===a.charAt(a.length-1)?a.slice(1,-1):a,l=parseInt(c,10);r.parseArrays||""!==c?!isNaN(l)&&a!==c&&String(l)===c&&l>=0&&r.parseArrays&&l<=r.arrayLimit?(s=[])[l]=i:s[c]=i:s={0:i}}i=s}return i}(l,t,r,n)}};e.exports=function(e,t){var r=function(e){if(!e)return s;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?s.charset:e.charset;return{allowDots:void 0===e.allowDots?s.allowDots:!!e.allowDots,allowPrototypes:"boolean"==typeof e.allowPrototypes?e.allowPrototypes:s.allowPrototypes,arrayLimit:"number"==typeof e.arrayLimit?e.arrayLimit:s.arrayLimit,charset:t,charsetSentinel:"boolean"==typeof e.charsetSentinel?e.charsetSentinel:s.charsetSentinel,comma:"boolean"==typeof e.comma?e.comma:s.comma,decoder:"function"==typeof e.decoder?e.decoder:s.decoder,delimiter:"string"==typeof e.delimiter||n.isRegExp(e.delimiter)?e.delimiter:s.delimiter,depth:"number"==typeof e.depth||!1===e.depth?+e.depth:s.depth,ignoreQueryPrefix:!0===e.ignoreQueryPrefix,interpretNumericEntities:"boolean"==typeof e.interpretNumericEntities?e.interpretNumericEntities:s.interpretNumericEntities,parameterLimit:"number"==typeof e.parameterLimit?e.parameterLimit:s.parameterLimit,parseArrays:!1!==e.parseArrays,plainObjects:"boolean"==typeof e.plainObjects?e.plainObjects:s.plainObjects,strictNullHandling:"boolean"==typeof e.strictNullHandling?e.strictNullHandling:s.strictNullHandling}}(t);if(""===e||null==e)return r.plainObjects?Object.create(null):{};for(var l="string"==typeof e?function(e,t){var r,c={},l=t.ignoreQueryPrefix?e.replace(/^\?/,""):e,p=t.parameterLimit===1/0?void 0:t.parameterLimit,d=l.split(t.delimiter,p),h=-1,f=t.charset;if(t.charsetSentinel)for(r=0;r<d.length;++r)0===d[r].indexOf("utf8=")&&("utf8=%E2%9C%93"===d[r]?f="utf-8":"utf8=%26%2310003%3B"===d[r]&&(f="iso-8859-1"),h=r,r=d.length);for(r=0;r<d.length;++r)if(r!==h){var y,v,b=d[r],m=b.indexOf("]="),g=-1===m?b.indexOf("="):m+1;-1===g?(y=t.decoder(b,s.decoder,f,"key"),v=t.strictNullHandling?null:""):(y=t.decoder(b.slice(0,g),s.decoder,f,"key"),v=n.maybeMap(u(b.slice(g+1),t),(function(e){return t.decoder(e,s.decoder,f,"value")}))),v&&t.interpretNumericEntities&&"iso-8859-1"===f&&(v=a(v)),b.indexOf("[]=")>-1&&(v=o(v)?[v]:v),i.call(c,y)?c[y]=n.combine(c[y],v):c[y]=v}return c}(e,r):e,p=r.plainObjects?Object.create(null):{},d=Object.keys(l),h=0;h<d.length;++h){var f=d[h],y=c(f,l[f],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 F})),r.d(t,"KintoneRestAPIClientWeChatMP",(function(){return _}));var n,i=function(e){var t=e.endpointName,r=e.guestSpaceId;return"/k"+(void 0!==r?"/guest/"+r:"")+"/v1"+(e.preview?"/preview":"")+"/"+t+".json"},o=function(){return(o=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)},s=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 i=0;for(n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]])}return r},a=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=s(e,["endpointName"]);return o({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 i(o(o({},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,i,o,s){var a=this,u=i-n.length,c=t.extractErrorIndex(u,o,s),l=t.buildErrorMessage(u,i,c);return(a=e.call(this,l)||this).name="KintoneAllRecordsError",a.processedRecordsResult=r,a.unprocessedRecords=n,a.error=o,a.errorIndex=c,a.message=l,Object.setPrototypeOf(a,t.prototype),a}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 i=t.parseErrorIndex(r.errors);if(null!==i)return e+r.bulkRequestIndex*n+i}},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 i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)},p=function(e,t,r,n){return new(r||(r=Promise))((function(i,o){function s(e){try{u(n.next(e))}catch(e){o(e)}}function a(e){try{u(n.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,a)}u((n=n.apply(e,t||[])).next())}))},d=function(e,t){var r,n,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;s;)try{if(r=1,n&&(i=2&o[0]?n.return:o[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,o[1])).done)return i;switch(n=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,n=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){s.label=o[1];break}if(6===o[0]&&s.label<i[1]){s.label=i[1],i=o;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(o);break}i[2]&&s.ops.pop(),s.trys.pop();continue}o=t.call(e,s)}catch(e){o=[6,e],n=0}finally{r=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}},h=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 i=0;for(n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]])}return r},f=function(){for(var e=0,t=0,r=arguments.length;t<r;t++)e+=arguments[t].length;var n=Array(e),i=0;for(t=0;t<r;t++)for(var o=arguments[t],s=0,a=o.length;s<a;s++,i++)n[i]=o[s];return n},y=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 p(this,void 0,void 0,(function(){var t,r,n,i,o,s;return d(this,(function(a){switch(a.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(i=a.sent().records).length>0?[4,this.updateRecord(e)]:[3,3];case 2:return o=a.sent().revision,[2,{id:i[0].$id.value,revision:o}];case 3:return[2,this.addRecord({app:t,record:l(l({},n),(s={},s[r.field]={value:r.value},s))})]}}))}))},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 p(this,void 0,void 0,(function(){var t,r,n,i;return d(this,(function(o){switch(o.label){case 0:return t=this.buildPathWithGuestSpaceId({endpointName:"records"}),[4,this.client.post(t,e)];case 1:return r=o.sent(),n=r.ids,i=r.revisions,[2,{ids:n,revisions:i,records:n.map((function(e,t){return{id:e,revision:i[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 p(this,void 0,void 0,(function(){var t,r,n,i,o,s;return d(this,(function(a){return t=e.condition,r=e.orderBy,n=e.withCursor,i=void 0===n||n,o=h(e,["condition","orderBy","withCursor"]),r?i?(s=(t?t+" ":"")+(r?"order by "+r:""),[2,this.getAllRecordsWithCursor(l(l({},o),{query:s}))]):[2,this.getAllRecordsWithOffset(l(l({},o),{orderBy:r,condition:t}))]:[2,this.getAllRecordsWithId(l(l({},o),{condition:t}))]}))}))},e.prototype.getAllRecordsWithId=function(e){return p(this,void 0,void 0,(function(){var t,r,n;return d(this,(function(i){return t=e.fields,r=h(e,["fields"]),(n=t)&&n.length>0&&-1===n.indexOf("$id")&&(n=f(n,["$id"])),[2,this.getAllRecordsRecursiveWithId(l(l({},r),{fields:n}),0,[])]}))}))},e.prototype.getAllRecordsRecursiveWithId=function(e,t,r){return p(this,void 0,void 0,(function(){var n,i,o,s,a,u,c;return d(this,(function(p){switch(p.label){case 0:return n=500,i=e.condition,o=h(e,["condition"]),s=(i?i+" and ":"")+"$id > "+t+" order by $id asc limit "+n,[4,this.getRecords(l(l({},o),{query:s}))];case 1:return a=p.sent(),u=r.concat(a.records),a.records.length<n?[2,u]:(c=a.records[a.records.length-1].$id.value,[2,this.getAllRecordsRecursiveWithId(e,c,u)])}}))}))},e.prototype.getAllRecordsWithOffset=function(e){return p(this,void 0,void 0,(function(){return d(this,(function(t){return[2,this.getAllRecordsRecursiveWithOffset(e,0,[])]}))}))},e.prototype.getAllRecordsRecursiveWithOffset=function(e,t,r){return p(this,void 0,void 0,(function(){var n,i,o,s,a,u,c;return d(this,(function(p){switch(p.label){case 0:return n=500,i=e.condition,o=e.orderBy,s=h(e,["condition","orderBy"]),a=(i?i+" ":"")+(o?"order by "+o+" ":"")+"limit "+n+" offset "+t,[4,this.getRecords(l(l({},s),{query:a}))];case 1:return u=p.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 p(this,void 0,void 0,(function(){var t,r;return d(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 p(this,void 0,void 0,(function(){var r,n;return d(this,(function(i){switch(i.label){case 0:return[4,this.getRecordsByCursor({id:e})];case 1:return r=i.sent(),n=t.concat(r.records),r.next?[2,this.getAllRecordsRecursiveByCursor(e,n)]:[2,n]}}))}))},e.prototype.addAllRecords=function(e){return p(this,void 0,void 0,(function(){return d(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 p(this,void 0,void 0,(function(){var n,i,o,s,a,u;return d(this,(function(l){switch(l.label){case 0:if(n=100*this.bulkRequestClient.REQUESTS_LENGTH_LIMIT,i=e.app,o=e.records,0===(s=o.slice(0,n)).length)return[2,{records:r}];l.label=1;case 1:return l.trys.push([1,3,,4]),[4,this.addAllRecordsWithBulkRequest({app:i,records:s})];case 2:return a=l.sent(),[3,4];case 3:throw u=l.sent(),new c({records:r},o,t,u,100);case 4:return[2,this.addAllRecordsRecursive({app:i,records:o.slice(n)},t,r.concat(a))]}}))}))},e.prototype.addAllRecordsWithBulkRequest=function(e){return p(this,void 0,void 0,(function(){var t,r,n=this;return d(this,(function(i){switch(i.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,i.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 p(this,void 0,void 0,(function(){return d(this,(function(t){return[2,this.updateAllRecordsRecursive(e,e.records.length,[])]}))}))},e.prototype.updateAllRecordsRecursive=function(e,t,r){return p(this,void 0,void 0,(function(){var n,i,o,s,a,u;return d(this,(function(l){switch(l.label){case 0:if(n=100*this.bulkRequestClient.REQUESTS_LENGTH_LIMIT,i=e.app,o=e.records,0===(s=o.slice(0,n)).length)return[2,{records:r}];l.label=1;case 1:return l.trys.push([1,3,,4]),[4,this.updateAllRecordsWithBulkRequest({app:i,records:s})];case 2:return a=l.sent(),[3,4];case 3:throw u=l.sent(),new c({records:r},o,t,u,100);case 4:return[2,this.updateAllRecordsRecursive({app:i,records:o.slice(n)},t,r.concat(a))]}}))}))},e.prototype.updateAllRecordsWithBulkRequest=function(e){return p(this,void 0,void 0,(function(){var t,r,n=this;return d(this,(function(i){switch(i.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,i.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 p(this,void 0,void 0,(function(){var r,n,i,o,s;return d(this,(function(a){switch(a.label){case 0:if(r=100*this.bulkRequestClient.REQUESTS_LENGTH_LIMIT,n=e.app,i=e.records,0===(o=i.slice(0,r)).length)return[2,{}];a.label=1;case 1:return a.trys.push([1,3,,4]),[4,this.deleteAllRecordsWithBulkRequest({app:n,records:o})];case 2:return a.sent(),[3,4];case 3:throw s=a.sent(),new c({},i,t,s,100);case 4:return[2,this.deleteAllRecordsRecursive({app:n,records:i.slice(r)},t)]}}))}))},e.prototype.deleteAllRecordsWithBulkRequest=function(e){return p(this,void 0,void 0,(function(){var t,r,n=this;return d(this,(function(i){switch(i.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 i.sent(),[2]}}))}))},e.prototype.separateArrayRecursive=function(e,t,r){var n=r.slice(0,e);return 0===n.length?t:this.separateArrayRecursive(e,f(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 i(l(l({},e),{guestSpaceId:this.guestSpaceId}))},e}(),v=function(){return(v=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)},b=function(e,t,r,n){return new(r||(r=Promise))((function(i,o){function s(e){try{u(n.next(e))}catch(e){o(e)}}function a(e){try{u(n.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,a)}u((n=n.apply(e,t||[])).next())}))},m=function(e,t){var r,n,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;s;)try{if(r=1,n&&(i=2&o[0]?n.return:o[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,o[1])).done)return i;switch(n=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,n=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){s.label=o[1];break}if(6===o[0]&&s.label<i[1]){s.label=i[1],i=o;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(o);break}i[2]&&s.ops.pop(),s.trys.pop();continue}o=t.call(e,s)}catch(e){o=[6,e],n=0}finally{r=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}},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 i=0;for(n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]])}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,v({},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,v({},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 b(this,void 0,void 0,(function(){var t,r,n,i,o;return m(this,(function(s){switch(s.label){case 0:return t=e.name,r=e.space,n=this.buildPathWithGuestSpaceId({endpointName:"app",preview:!0}),r?(i=this.buildPathWithGuestSpaceId({endpointName:"space"}),[4,this.client.get(i,{id:r})]):[3,2];case 1:return o=s.sent().defaultThread,[2,this.client.post(n,v(v({},e),{thread:o}))];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,v({},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,v({},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,v({},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,v({},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 i(v(v({},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 WeChat 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 i({...e,guestSpaceId:this.guestSpaceId})}}const S="function"==typeof btoa,P="function"==typeof Buffer,O=[..."ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="],I=((e=>{let t={};e.forEach((e,r)=>t[e]=r)})(O),String.fromCharCode.bind(String),"function"==typeof Uint8Array.from&&Uint8Array.from.bind(Uint8Array),e=>e.replace(/[+\/]/g,e=>"+"==e?"-":"_").replace(/=+$/m,"")),A=e=>{let t,r,n,i,o="";const s=e.length%3;for(let s=0;s<e.length;){if((r=e.charCodeAt(s++))>255||(n=e.charCodeAt(s++))>255||(i=e.charCodeAt(s++))>255)throw new TypeError("invalid character found");t=r<<16|n<<8|i,o+=O[t>>18&63]+O[t>>12&63]+O[t>>6&63]+O[63&t]}return s?o.slice(0,s-3)+"===".substring(s):o},N=S?e=>btoa(e):P?e=>Buffer.from(e,"binary").toString("base64"):A,W=e=>unescape(encodeURIComponent(e)),j=P?e=>Buffer.from(e,"utf8").toString("base64"):e=>N(W(e)),x=(e,t=!1)=>t?I(j(e)):j(e),C=x;var k=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)}}(),E=function(e){function t(r){var n=this,i=t.buildErrorResponseDateWithIndex(r),o=i.data,s=i.bulkRequestIndex;return(n=e.call(this,o.message)||this).name="KintoneRestAPIError",n.id=o.id,n.code=o.code,n.errors=o.errors,n.status=r.status,n.bulkRequestIndex=s,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 k(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),G=r(2),q=r.n(G);class T{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,name:"file",fileMethod:"upload"});return this.sendRequest(r)}async sendRequest(e){let t;try{t=await this.wxSendRequest(e)}catch(e){this.errorResponseHandler(e)}return t}callWxAPI(e){switch(e.fileMethod){case"download":return wx.downloadFile(e);case"upload":return wx.uploadFile(e);case"read":return wx.getFileSystemManager().readFileSync(e.tempFilePath,"utf8");default:return wx.request(e)}}wxSendRequest(e){return new Promise((t,r)=>{switch(e.fail=e=>{r(e)},e.fileMethod){case"download":e.success=e=>{200===e.statusCode?t({tempFilePath:e.tempFilePath}):r({...e,data:JSON.parse(this.callWxAPI({fileMethod:"read",tempFilePath:e.tempFilePath}))})};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.statusCode?t(e.data):r(e)}}this.callWxAPI(e)})}buildRequestConfig(e,t,r,n){const i={method:e,header:this.headers,url:`${this.baseUrl}${t}`,...n||{}};switch(e){case"get":{const e=this.buildRequestUrl(t,r);return e.length>4096?{...i,method:"post",header:{...this.headers,"X-HTTP-Method-Override":"GET"},data:{...this.params,...r}}:{...i,header:{...this.headers,"content-type":"application/html"},url:e}}case"post":case"put":case"delete":return{...i,data:{...this.params,...r}};default:throw new Error(e+" method is not supported")}}buildRequestUrl(e,t){return`${this.baseUrl}${e}?${q.a.stringify(t)}`}}const F=e=>{if(!e.data)throw new Error(e.errMsg);throw e.status=e.statusCode,e.headers=e.header,new E(e)};class _{constructor(e={}){const t="baseUrl"in e?e.baseUrl:"",r="auth"in e?e.auth:{},{guestSpaceId:n}=e,{basicAuth:i}=e,o=this.buildAuth(r);if(this.headers=this.buildHeaders(o,i),this.baseUrl=t,""===this.baseUrl)throw new Error("in WeChat environment, baseUrl is required");const s=new T({baseUrl:this.baseUrl,headers:this.headers,params:{},errorResponseHandler:F});this.bulkRequest_=new a(s,n),this.record=new y(s,this.bulkRequest_,n),this.app=new w(s,n),this.file=new R(s,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 WeChat environment, auth is required")}buildHeaders(e,t){const r=t?{Authorization:"Basic "+C(`${t.username}:${t.password}`)}:{};switch(e.type){case"password":return{...r,"X-Cybozu-Authorization":C(`${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)}}}]);