You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

@esri/arcgis-rest-portal

Package Overview
Dependencies
Maintainers
6
Versions
88
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@esri/arcgis-rest-portal - npm Package Compare versions

Comparing version

to
3.8.0

5

dist/esm/util/get-portal.js

@@ -31,4 +31,7 @@ /* Copyright (c) 2017-2019 Environmental Systems Research Institute, Inc.

var url = getPortalUrl(requestOptions) + "/portals/" + idOrSelf;
// default to a GET request
var options = __assign({ httpMethod: "GET" }, requestOptions);
if (idOrSelf === "self") {
// for self, always credentials to "include""
options.credentials = "include";
}
// send the request

@@ -35,0 +38,0 @@ return request(url, options);

@@ -35,4 +35,7 @@ "use strict";

var url = get_portal_url_1.getPortalUrl(requestOptions) + "/portals/" + idOrSelf;
// default to a GET request
var options = tslib_1.__assign({ httpMethod: "GET" }, requestOptions);
if (idOrSelf === "self") {
// for self, always credentials to "include""
options.credentials = "include";
}
// send the request

@@ -39,0 +42,0 @@ return arcgis_rest_request_1.request(url, options);

8

dist/umd/portal.umd.min.js
/* @preserve
* @esri/arcgis-rest-portal - v3.7.0 - Apache-2.0
* Copyright (c) 2017-2023 Esri, Inc.
* Thu Sep 07 2023 17:22:10 GMT-0700 (Pacific Daylight Time)
* @esri/arcgis-rest-portal - v3.8.0 - Apache-2.0
* Copyright (c) 2017-2025 Esri, Inc.
* Tue Apr 15 2025 13:30:55 GMT-0600 (Mountain Daylight Time)
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@esri/arcgis-rest-request")):"function"==typeof define&&define.amd?define(["exports","@esri/arcgis-rest-request"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).arcgisRest=e.arcgisRest||{},e.arcgisRest)}(this,function(e,u){"use strict";var s=function(){return(s=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)};function t(e,a,u,s){return new(u=u||Promise)(function(r,t){function n(e){try{i(s.next(e))}catch(e){t(e)}}function o(e){try{i(s.throw(e))}catch(e){t(e)}}function i(e){var t;e.done?r(e.value):((t=e.value)instanceof u?t:new u(function(e){e(t)})).then(n,o)}i((s=s.apply(e,a||[])).next())})}function c(r,n){var o,i,a,u={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]},e={next:t(0),throw:t(1),return:t(2)};return"function"==typeof Symbol&&(e[Symbol.iterator]=function(){return this}),e;function t(t){return function(e){return function(t){if(o)throw new TypeError("Generator is already executing.");for(;u;)try{if(o=1,i&&(a=2&t[0]?i.return:t[0]?i.throw||((a=i.return)&&a.call(i),0):i.next)&&!(a=a.call(i,t[1])).done)return a;switch(i=0,a&&(t=[2&t[0],a.value]),t[0]){case 0:case 1:a=t;break;case 4:return u.label++,{value:t[1],done:!1};case 5:u.label++,i=t[1],t=[0];continue;case 7:t=u.ops.pop(),u.trys.pop();continue;default:if(!(a=0<(a=u.trys).length&&a[a.length-1])&&(6===t[0]||2===t[0])){u=0;continue}if(3===t[0]&&(!a||t[1]>a[0]&&t[1]<a[3])){u.label=t[1];break}if(6===t[0]&&u.label<a[1]){u.label=a[1],a=t;break}if(a&&u.label<a[2]){u.label=a[2],u.ops.push(t);break}a[2]&&u.ops.pop(),u.trys.pop();continue}t=n.call(r,u)}catch(e){t=[6,e],i=0}finally{o=a=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}([t,e])}}}function m(e){return void 0===e&&(e={}),e.portal?u.cleanUrl(e.portal):e.authentication?e.authentication.portal:"https://www.arcgis.com/sharing/rest"}function n(e){var t=JSON.parse(JSON.stringify(e));return t.data&&("undefined"!=typeof Blob&&e.data instanceof Blob||"ReadStream"===e.data.constructor.name?t.file=e.data:t.text=e.data,delete t.data),t}function p(e){return e.owner?Promise.resolve(e.owner):e.item&&e.item.owner?Promise.resolve(e.item.owner):e.authentication&&e.authentication.getUsername?e.authentication.getUsername():Promise.reject(new Error("Could not determine the owner of this item. Pass the `owner`, `item.owner`, or `authentication` option."))}function o(e){return Array.isArray(e)&&Array.isArray(e[0])&&Array.isArray(e[1])}function i(e){return e.join(",")}function r(t){return p(t).then(function(e){e=t.folderId?m(t)+"/content/users/"+e+"/"+t.folderId+"/items/"+t.item.id+"/update":m(t)+"/content/users/"+e+"/items/"+t.item.id+"/update";return t.params=s(s({},t.params),n(t.item)),t.params.extent&&o(t.params.extent)&&(t.params.extent=i(t.params.extent)),t.params.file&&t.params.file.constructor&&"ReadStream"===t.params.file.constructor.name&&(t.params.dataSize=t.dataSize),u.request(e,t)})}function a(r){return r.multipart&&!r.filename?Promise.reject(new Error("The filename is required for a multipart request.")):p(r).then(function(e){var t=m(r)+"/content/users/"+e,e=t+"/addItem";r.folderId&&(e=t+"/"+r.folderId+"/addItem"),r.params=s(s({},r.params),n(r.item)),r.params.extent&&o(r.params.extent)&&(r.params.extent=i(r.params.extent));t=u.appendCustomParams(r,["owner","folderId","file","dataUrl","text","async","multipart","filename","overwrite"],{params:s({},r.params)});return u.request(e,t)})}var d=/[\x00-\x1F\x7F-\x9F\xA0]/g;function h(e){return e.replace(d,"")}var f=function(e,t){return("string"==typeof t?t:m(t))+"/content/items/"+e};function l(e,t){var r=t||{},n=r.fileName,r=r.readAs;return g(e,"/info/"+(void 0===n?"iteminfo.xml":n),void 0===r?"text":r,s({httpMethod:"GET"},t))}function g(e,t,r,n){var t=""+f(e,n)+t,n=s({params:{}},n),o=n.rawResponse;return n.rawResponse=!0,n.params.f=null,u.request(t,n).then(function(e){return o?e:"json"!==r?e[r]():e.text().then(function(e){return JSON.parse(h(e))})})}function v(e,t){e=m(t)+"/community/groups/"+e,t=s({httpMethod:"GET"},t);return u.request(e,t)}function y(e){var t=e.authentication.username,t=e.owner||t;return m(e)+"/content/users/"+encodeURIComponent(t)+"/items/"+e.id+"/share"}function I(e){var t=e.authentication.username;return(e.owner||t)===t}function q(e){return e.authentication.getUser(e).then(function(e){return e&&"org_admin"===e.role&&!e.roleId})}function w(e){return v(e.groupId,e).then(function(e){return e.userMembership.memberType}).catch(function(){return"none"})}var b=(T.prototype.match=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return this.termStack=this.termStack.concat(e),this},T.prototype.in=function(e){var t="`in("+(e?'"'+e+'"':"")+")`";return this.hasRange||this.hasTerms?(e&&"*"!==e&&(this.q+=e+":"),this.commit()):(u.warn(t+" was called with no call to `match(...)` or `from(...)`/`to(...)`. Your query was not modified."),this)},T.prototype.startGroup=function(){return this.commit(),0<this.openGroups&&(this.q+=" "),this.openGroups++,this.q+="(",this},T.prototype.endGroup=function(){return this.openGroups<=0?u.warn("`endGroup(...)` was called without calling `startGroup(...)` first. Your query was not modified."):(this.commit(),this.openGroups--,this.q+=")"),this},T.prototype.and=function(){return this.addModifier("and")},T.prototype.or=function(){return this.addModifier("or")},T.prototype.not=function(){return this.addModifier("not")},T.prototype.from=function(e){return this.hasTerms?u.warn('`from(...)` is not allowed after `match(...)` try using `.from(...).to(...).in(...)`. Optionally, you may see this because dates are incorrectly formatted. Dates should be a primative Date value, aka a number in milliseconds or Date object, ie new Date("2020-01-01"). Your query was not modified.'):this.rangeStack[0]=e,this},T.prototype.to=function(e){return this.hasTerms?u.warn('`to(...)` is not allowed after `match(...)` try using `.from(...).to(...).in(...)`. Optionally, you may see this because dates are incorrectly formatted. Dates should be a primative Date value, aka a number in milliseconds or Date object, ie new Date("2020-01-01"). Your query was not modified.'):this.rangeStack[1]=e,this},T.prototype.boost=function(e){return this.commit(),this.q+="^"+e,this},T.prototype.toParam=function(){return this.commit(),this.cleanup(),this.q},T.prototype.clone=function(){return this.commit(),this.cleanup(),new T(this.q+"")},T.prototype.addModifier=function(e){return this.currentModifer?(u.warn("You have called `"+this.currentModifer+"()` after `"+e+"()`. Your current query was not modified."),this):(this.commit(),""===this.q&&"not"!==e?u.warn("You have called `"+e+"()` without calling another method to modify your query first. Try calling `match()` first."):(this.currentModifer=e,this.q+=""===this.q?"":" ",this.q+=e.toUpperCase()+" "),this)},T.prototype.needsQuotes=function(e){return/\s|:/g.test(e)},T.prototype.formatTerm=function(e){return e instanceof Date?e.getTime():"string"==typeof e&&this.needsQuotes(e)?'"'+e+'"':e},T.prototype.commit=function(){var t=this;return this.currentModifer=void 0,this.hasRange&&(this.q+="["+this.formatTerm(this.rangeStack[0])+" TO "+this.formatTerm(this.rangeStack[1])+"]",this.rangeStack=[void 0,void 0]),this.hasTerms&&(this.q+=this.termStack.map(function(e){return t.formatTerm(e)}).join(" "),this.termStack=[]),this},Object.defineProperty(T.prototype,"hasTerms",{get:function(){return 0<this.termStack.length},enumerable:!1,configurable:!0}),Object.defineProperty(T.prototype,"hasRange",{get:function(){return this.rangeStack.length&&this.rangeStack[0]&&this.rangeStack[1]},enumerable:!1,configurable:!0}),T.prototype.cleanup=function(){if(0<this.openGroups)for(u.warn("Automatically closing "+this.openGroups+" group(s). You can use `endGroup(...)` to remove this warning.");0<this.openGroups;)this.q+=")",this.openGroups--;var e=this.q;this.q=e.replace(/( AND ?| NOT ?| OR ?)*$/,""),e!==this.q&&u.warn("`startGroup(...)` was called without calling `endGroup(...)` first. Your query was not modified."),this.q=this.q.replace(/(\(\))*/,"")},T);function T(e){void 0===e&&(e=""),this.termStack=[],this.rangeStack=[],this.openGroups=0,this.q=e}function G(r,n){var e,t="string"==typeof r||r instanceof b?{httpMethod:"GET",params:{q:r}}:u.appendCustomParams(r,["q","num","start","sortField","sortOrder","searchUserAccess","searchUserName","filter","countFields","countSize","categories","categoryFilters"],{httpMethod:"GET"});switch(n){case"item":e="/search";break;case"group":e="/community/groups";break;case"groupContent":if("string"==typeof r||r instanceof b||!r.groupId)return Promise.reject(new Error("you must pass a `groupId` option to `searchGroupContent`"));e="/content/groups/"+r.groupId+"/search";break;case"communityUser":e="/community/users";break;default:e="/portals/self/users/search"}var o=m(t)+e;return u.request(o,t).then(function(t){return t.nextStart&&-1!==t.nextStart&&(t.nextPage=function(){var e;return"string"==typeof r||r instanceof b?e={q:r,start:t.nextStart}:(e=r).start=t.nextStart,G(e,n)}),t})}function U(e){return G(e,"item")}function x(e,t){if(0===e.length)return[];for(var r=[],n=0;n<e.length;n+=t)r.push(e.slice(n,n+t));return r}function P(e){var t=e.id,r=m(e)+"/community/groups/"+t+"/addUsers",t=Object.assign({},e,{admins:void 0,users:void 0}),t=function(){for(var e=0,t=0,r=arguments.length;t<r;t++)e+=arguments[t].length;for(var n=Array(e),o=0,t=0;t<r;t++)for(var i=arguments[t],a=0,u=i.length;a<u;a++,o++)n[o]=i[a];return n}(S("users",e.users,t),S("admins",e.admins,t)).map(function(e){return t=r,e=e,u.request(t,e).catch(function(e){return{errors:[e]}});var t});return Promise.all(t).then(C)}function S(o,e,i){return!e||e.length<1?[]:x(e,25).map(function(e){return t=o,r=e,n=i,Object.assign({},n,((e={})[t]=r,e.params=s(s({},n.params),((n={})[t]=r,n)),e));var t,r,n})}function C(e){var t=e.filter(function(e){return e.notAdded}).reduce(function(e,t){return e.concat(t.notAdded)},[]),e=e.filter(function(e){return e.errors}).reduce(function(e,t){return e.concat(t.errors)},[]),t={notAdded:t};return 0<e.length&&(t.errors=e),t}function E(t){var e=t.id,r=t.users,n=m(t)+"/community/groups/"+e+"/removeUsers",r=x(r,25).map(function(e){e=s(s({},t),{users:e,params:{users:e}});return u.request(n,e).catch(function(e){return{errors:[e]}})});return Promise.all(r).then(function(e){var t=function(r){return e.filter(function(e){return e[r]}).reduce(function(e,t){return e.concat(t[r])},[])},r=t("errors"),t={notRemoved:t("notRemoved")};return r.length?s(s({},t),{errors:r}):t})}function M(e){var t=e.every(function(e){return e.success}),e=e.reduce(function(e,t){return e.concat(t.errors||[])},[]),t={success:t};return 0<e.length&&(t.errors=e),t}function R(e){var t=m(e)+"/community/groups/"+e.id+"/updateUsers",r={authentication:e.authentication,params:{}};return"admin"===e.newMemberType?r.params.admins=e.users:r.params.users=e.users,u.request(t,r)}function A(e){var t=e.every(function(e){return e.success}),e=e.reduce(function(e,t){return e.concat(t.errors||[])},[]),t={success:t};return 0<e.length&&(t.errors=e),t}function N(e){var t,r,n={httpMethod:"GET"};return"string"==typeof e?r="https://www.arcgis.com/sharing/rest/community/users/"+e:(t=e.username||e.authentication.username,r=m(e)+"/community/users/"+encodeURIComponent(t),n=s(s({},e),n)),u.request(r,n)}function O(e,t){return t.params=s({org:!1,everyone:!1},t.params),"private"===t.access&&(t.params.groups=" "),"org"===t.access&&(t.params.org=!0),"public"===t.access&&(t.params.account=!0,t.params.everyone=!0),u.request(e,t)}function j(t){return U({q:"id: "+t.id+" AND group: "+t.groupId,start:1,num:10,sortField:"title",authentication:t.authentication,httpMethod:"POST"}).then(function(e){if(0<e.total)return e.results.some(function(e){return e.id===t.id})})}function k(e,t,r){void 0===t&&(t=!1),void 0===r&&(r=!1);var n=e.authentication.username,o=e.owner||n,i=m(e)+"/content/items/"+e.id+"/share";return(o===n||t&&!r)&&(i=m(e)+"/content/users/"+o+"/items/"+e.id+"/share"),e.params={groups:e.groupId,confirmItemControl:e.confirmItemControl},u.request(i,e)}function F(e,t,r,n,o){var i,a,u=t.groups||[],s=u.find(function(e){return e.id===o.groupId});if(e.orgId!==t.orgId)throw Error("User "+t.username+" is not a member of the same org as "+e.username+". Consequently they can not be added added to group "+o.groupId+" nor can item "+o.id+" be shared to the group.");if(!s&&511<u.length)throw Error("User "+t.username+" already has 512 groups, and can not be added to group "+o.groupId+". Consequently item "+o.id+" can not be shared to the group.");return a=s?r&&"member"===s.userMembership.memberType?(i=R({id:o.groupId,users:[t.username],newMemberType:"admin",authentication:o.authentication}).then(function(e){e=e.results.reduce(function(e,t){return t.success||e.push(t.username),e},[]);return Promise.resolve({notAdded:e})}).catch(function(){return{notAdded:[t.username]}}),function(e){return R({id:o.groupId,users:[t.username],newMemberType:"member",authentication:o.authentication}).then(function(){return e}).catch(function(){return e})}):(i=Promise.resolve({notAdded:[]}),function(e){return Promise.resolve(e)}):(r=r?"admins":"users",i=P(((a={id:o.groupId})[r]=[t.username],a.authentication=o.authentication,a)).then(function(e){if(e.errors&&e.errors.length)throw e.errors[0];return e}).catch(function(){return{notAdded:[t.username]}}),function(e){return E({id:o.groupId,users:[t.username],authentication:o.authentication}).then(function(){return e})}),{promise:i.then(function(e){if(e.notAdded.length)throw new Error(n);return e}),revert:a}}function D(e,t,r){var n=r.portal+"/portals/self/isServiceNameAvailable";return u.request(n,{params:{name:e,type:t},httpMethod:"GET",authentication:r})}function Y(e,t){e=e||"self",e=m(t)+"/portals/"+e,t=s({httpMethod:"GET"},t);return u.request(e,t)}e.SearchQueryBuilder=b,e.acceptInvitation=function(e){var t=encodeURIComponent(e.authentication.username),t=m(e)+"/community/users/"+t+"/invitations/"+e.invitationId+"/accept",e=s({},e);return u.request(t,e)},e.addGroupUsers=P,e.addItemData=function(e){return delete(e=s({item:{id:e.id,data:e.data}},e)).id,delete e.data,r(e)},e.addItemPart=function(r){var n=r.partNum;return!Number.isInteger(n)||n<1||1e4<n?Promise.reject(new Error("The part number must be an integer between 1 to 10000, inclusive.")):p(r).then(function(e){var t=m(r)+"/content/users/"+e+"/items/"+r.id+"/addPart?partNum="+n,e=u.appendCustomParams(r,["file"],{params:s({},r.params)});return u.request(t,e)})},e.addItemRelationship=function(r){return p(r).then(function(e){var t=m(r)+"/content/users/"+e+"/addRelationship",e=u.appendCustomParams(r,["originItemId","destinationItemId","relationshipType"],{params:s({},r.params)});return u.request(t,e)})},e.addItemResource=function(t){return p(t).then(function(e){e=m(t)+"/content/users/"+e+"/items/"+t.id+"/addResources";return t.params=s({file:t.resource,fileName:t.name,resourcesPrefix:t.prefix,text:t.content,access:t.private?"private":"inherit"},t.params),u.request(e,t)})},e.bboxToString=i,e.cancelItemUpload=function(t){return p(t).then(function(e){e=m(t)+"/content/users/"+e+"/items/"+t.id+"/cancel";return u.request(e,t)})},e.commitItemUpload=function(r){return p(r).then(function(e){var t=m(r)+"/content/users/"+e+"/items/"+r.id+"/commit",e=u.appendCustomParams(r,[],{params:s(s({},r.params),n(r.item))});return u.request(t,e)})},e.createFolder=function(t){return p(t).then(function(e){e=m(t)+"/content/users/"+e+"/createFolder";return t.params=s({title:t.title},t.params),u.request(e,t)})},e.createGroup=function(e){var t=m(e)+"/community/createGroup";return e.params=s(s({},e.params),e.group),u.request(t,e)},e.createGroupNotification=function(e){var t=m(e)+"/community/groups/"+e.id+"/createNotification",e=s({params:s({subject:e.subject,message:e.message,users:e.users,notificationChannelType:e.notificationChannelType||"email",clientId:e.clientId,silentNotification:e.silentNotification,notifyAll:!e.users||0===e.users.length},e.params)},e);return u.request(t,e)},e.createItem=function(e){return a(s({folderId:null},e))},e.createItemInFolder=a,e.createOrgNotification=function(e){var n,r=m(e)+"/portals/self/createNotification",e=x((n=e).users,n.batchSize||25).map(function(e){return t=e,r=n,(e=Object.assign({},r)).params=s(s({},e.params),{users:t,subject:r.subject,message:r.message,notificationChannelType:e.notificationChannelType}),e;var t,r}).map(function(e){return t=r,e=e,u.request(t,e).catch(function(e){return{errors:[e]}});var t});return Promise.all(e).then(A)},e.declineInvitation=function(e){var t=encodeURIComponent(e.authentication.username),t=m(e)+"/community/users/"+t+"/invitations/"+e.invitationId+"/decline",e=s({},e);return u.request(t,e)},e.determineOwner=p,e.ensureMembership=F,e.exportItem=function(t){var r=t.authentication,n=t.id,o=t.title,i=t.exportFormat,a=t.exportParameters;return p(t).then(function(e){return m(t)+"/content/users/"+e+"/export"}).then(function(e){return u.request(e,{httpMethod:"POST",authentication:r,params:{itemId:n,title:o,exportFormat:i,exportParameters:a}})})},e.getGroup=v,e.getGroupCategorySchema=function(e,t){return e=m(t)+"/community/groups/"+e+"/categorySchema",t=s({httpMethod:"GET"},t),u.request(e,t)},e.getGroupContent=function(e,t){var r=m(t)+"/content/groups/"+e,e=s(s({httpMethod:"GET"},{params:{start:1,num:100}}),t);return t&&t.paging&&(e.params=s({},t.paging)),u.request(r,e)},e.getGroupUsers=function(e,t){return e=m(t)+"/community/groups/"+e+"/users",t=s({httpMethod:"GET"},t),u.request(e,t)},e.getItem=function(e,t){return e=f(e,t),t=s({httpMethod:"GET"},t),u.request(e,t)},e.getItemBaseUrl=f,e.getItemData=function(e,t){return e=f(e,t)+"/data",(t=s({httpMethod:"GET",params:{}},t)).file&&(t.params.f=null),u.request(e,t).catch(function(e){var t=RegExp(/The string did not match the expected pattern|(Unexpected end of (JSON input|data at line 1 column 1))/i);if(!t.test(e.message))throw e})},e.getItemGroups=function(e,t){return e=f(e,t)+"/groups",u.request(e,t)},e.getItemInfo=l,e.getItemMetadata=function(e,t){return l(e,s(s({},t),{fileName:"metadata/metadata.xml"}))},e.getItemParts=function(t){return p(t).then(function(e){e=m(t)+"/content/users/"+e+"/items/"+t.id+"/parts";return u.request(e,t)})},e.getItemResource=function(e,t){var r=t.readAs||"blob";return g(e,"/resources/"+t.fileName,r,t)},e.getItemResources=function(e,t){return e=f(e,t)+"/resources",(t=s({},t)).params=s({num:1e3},t.params),u.request(e,t)},e.getItemStatus=function(r){return p(r).then(function(e){var t=m(r)+"/content/users/"+e+"/items/"+r.id+"/status",e=u.appendCustomParams(r,["jobId","jobType"],{params:s({},r.params)});return u.request(t,e)})},e.getPortal=Y,e.getPortalSettings=function(e,t){return e=e||"self",e=m(t)+"/portals/"+e+"/settings",t=s({httpMethod:"GET"},t),u.request(e,t)},e.getPortalUrl=m,e.getRelatedItems=function(e){var t=f(e.id,e)+"/relatedItems",r=s({httpMethod:"GET",params:{direction:e.direction}},e);return"string"==typeof e.relationshipType?r.params.relationshipType=e.relationshipType:r.params.relationshipTypes=e.relationshipType,delete r.direction,delete r.relationshipType,u.request(t,r)},e.getSelf=function(e){return Y(null,e)},e.getSharingUrl=y,e.getSubscriptionInfo=function(e,t){return e=e||"self",e=m(t)+"/portals/"+e+"/subscriptionInfo",t=s({httpMethod:"GET"},t),u.request(e,t)},e.getUniqueServiceName=function t(r,n,o,i){var a=i?r+"_"+i:r;return D(a,n,o).then(function(e){return e.available?a:t(r,n,o,i+=1)})},e.getUser=N,e.getUserContent=function(t){var e=t.folderId,r=t.start,n=void 0===r?1:r,r=t.num,o=void 0===r?10:r,i=t.authentication,a=e?"/"+e:"";return p(t).then(function(e){return m(t)+"/content/users/"+e+a}).then(function(e){return u.request(e,{httpMethod:"GET",authentication:i,params:{start:n,num:o}})})},e.getUserInvitation=function(e){var t=encodeURIComponent(e.authentication.username),r=m(e)+"/community/users/"+t+"/invitations/"+e.invitationId,t={httpMethod:"GET"},t=s(s({},e),t);return u.request(r,t)},e.getUserInvitations=function(e){var t={httpMethod:"GET"},r=encodeURIComponent(e.authentication.username),r=m(e)+"/community/users/"+r+"/invitations",t=s(s({},e),t);return u.request(r,t)},e.getUserMembership=w,e.getUserNotifications=function(e){var t={httpMethod:"GET"},r=encodeURIComponent(e.authentication.username),r=m(e)+"/community/users/"+r+"/notifications",t=s(s({},e),t);return u.request(r,t)},e.getUserProperties=function(r,n){return t(this,void 0,void 0,function(){var t;return c(this,function(e){switch(e.label){case 0:return t=m(n)+"/community/users/"+encodeURIComponent(r)+"/properties",[4,u.request(t,s({httpMethod:"GET"},n))];case 1:return(t=e.sent()).properties.mapViewer||(t.properties.mapViewer="modern"),[2,t.properties]}})})},e.getUserTags=function(e){var t=e.username||e.authentication.username,t=m(e)+"/community/users/"+encodeURIComponent(t)+"/tags";return u.request(t,e)},e.getUserUrl=function(e){return m(e)+"/community/users/"+encodeURIComponent(e.username)},e.inviteGroupUsers=function(e){var t,r=e.id,n=m(e)+"/community/groups/"+r+"/invite",e=x((t=e).users,25).map(function(e){return function(e,t){t=Object.assign({},t);return t.params=s(s({},t.params),{users:e,role:t.role,expiration:t.expiration}),t}(e,t)}).map(function(e){return t=n,e=e,u.request(t,e).catch(function(e){return{errors:[e]}});var t});return Promise.all(e).then(M)},e.isBBox=o,e.isItemOwner=I,e.isItemSharedWithGroup=j,e.isOrgAdmin=q,e.isServiceNameAvailable=D,e.joinGroup=function(e){var t=m(e)+"/community/groups/"+e.id+"/join";return u.request(t,e)},e.leaveGroup=function(e){var t=m(e)+"/community/groups/"+e.id+"/leave";return u.request(t,e)},e.moveItem=function(r){return p(r).then(function(e){var t=m(r)+"/content/users/"+e+"/items/"+r.itemId+"/move",e=(e=r.folderId)||"/";return r.params=s({folder:e},r.params),u.request(t,r)})},e.protectGroup=function(e){var t=m(e)+"/community/groups/"+e.id+"/protect";return u.request(t,e)},e.protectItem=function(t){return p(t).then(function(e){e=m(t)+"/content/users/"+e+"/items/"+t.id+"/protect";return u.request(e,t)})},e.reassignItem=function(r){return q(r).then(function(e){if(!e)throw Error("Item "+r.id+" can not be reassigned because current user is not an organization administrator.");var t=m(r)+"/content/users/"+r.currentOwner+"/items/"+r.id+"/reassign",e={params:{targetUsername:r.targetUsername,targetFolderName:r.targetFolderName},authentication:r.authentication};return u.request(t,e)})},e.removeFolder=function(t){return p(t).then(function(e){e=m(t)+"/content/users/"+encodeURIComponent(e)+"/"+t.folderId+"/delete";return u.request(e,t)})},e.removeGroup=function(e){var t=m(e)+"/community/groups/"+e.id+"/delete",e=s({},e);return u.request(t,e)},e.removeGroupUsers=E,e.removeItem=function(t){return p(t).then(function(e){e=m(t)+"/content/users/"+e+"/items/"+t.id+"/delete";return u.request(e,t)})},e.removeItemRelationship=function(r){return p(r).then(function(e){var t=m(r)+"/content/users/"+e+"/deleteRelationship",e=u.appendCustomParams(r,["originItemId","destinationItemId","relationshipType"],{params:s({},r.params)});return u.request(t,e)})},e.removeItemResource=function(t){return p(t).then(function(e){e=m(t)+"/content/users/"+e+"/items/"+t.id+"/removeResources";return t.params=s(s({},t.params),{resource:t.resource}),void 0!==t.deleteAll&&(t.params.deleteAll=t.deleteAll),u.request(e,t)})},e.removeNotification=function(e){var t=encodeURIComponent(e.authentication.username),t=m(e)+"/community/users/"+t+"/notifications/"+e.id+"/delete";return u.request(t,e)},e.scrubControlChars=h,e.searchCommunityUsers=function(e){return G(e,"communityUser")},e.searchGroupContent=function(e){return G(e,"groupContent")},e.searchGroupUsers=function(e,t){return e=m(t)+"/community/groups/"+e+"/userlist",t=u.appendCustomParams(t||{},["name","num","start","sortField","sortOrder","joined","memberType"],{httpMethod:"GET"}),u.request(e,t)},e.searchGroups=function(e){return G(e,"group")},e.searchItems=U,e.searchUsers=function(e){return G(e,"user")},e.serializeItem=n,e.setItemAccess=function(t){var r=y(t);return I(t)?O(r,t):q(t).then(function(e){if(e)return O(r,t);throw Error("This item can not be shared by "+t.authentication.username+". They are neither the item owner nor an organization admin.")})},e.setUserProperties=function(o,i,a){return t(this,void 0,void 0,function(){var t,r,n;return c(this,function(e){switch(e.label){case 0:t=m(a)+"/community/users/"+encodeURIComponent(o)+"/setProperties",r=s({httpMethod:"POST",params:{properties:i}},a),e.label=1;case 1:return e.trys.push([1,3,,4]),[4,u.request(t,r)];case 2:if(!(n=e.sent()).success)throw new Error("Success was false");return[2,n];case 3:throw n=e.sent(),new Error("Failed to set user properties: "+n.message);case 4:return[2]}})})},e.shareItemWithGroup=function(u){return j(u).then(function(e){if(e)return{itemId:u.id,shortcut:!0,notSharedWith:[]};var t=u.authentication.username,e=u.owner,o=u.confirmItemControl,e=e||t;if(e===t)return k(u);var i=!1,a=!1;return Promise.all([N({username:t,authentication:u.authentication}),N({username:e,authentication:u.authentication}),w(u)]).then(function(e){var t=e[0],r=e[1],n=e[2],e=!!o;return i="org_admin"===t.role&&!t.roleId,a=t.orgId!==r.orgId,function(e,t,r,n,o,i){var a=[];if(i.groupId!==e.favGroupId)if(t){if(!n)throw Error("This item can not be shared to shared editing group "+i.groupId+" by "+e.username+" as they not the item owner or org admin.");a.push(F(e,e,!1,"Error adding "+e.username+" as member to edit group "+i.groupId+". Consequently item "+i.id+" was not shared to the group.",i),F(e,o,!0,"none"===r?"Error adding user "+o.username+" to edit group "+i.groupId+". Consequently item "+i.id+" was not shared to the group.":"Error promoting user "+o.username+" to admin in edit group "+i.groupId+". Consequently item "+i.id+" was not shared to the group.",i))}else if(n)a.push(F(e,e,!1,"Error adding "+e.username+" as member to view group "+i.groupId+". Consequently item "+i.id+" was not shared to the group.",i));else if("none"===r)throw new Error("This item can not be shared by "+e.username+" as they are not a member of the specified group "+i.groupId+".");return a}(t,e,n,i,r,u)}).then(function(e){var t=e[0],r=(void 0===t?{promise:Promise.resolve({notAdded:[]}),revert:function(e){return Promise.resolve(e)}}:t).revert;return Promise.all(e.map(function(e){return e.promise})).then(function(){return k(u,i,a)}).then(function(e){return r(e)})})}).then(function(e){if(e.notSharedWith.length)throw Error("Item "+u.id+" could not be shared to group "+u.groupId+".");return e})},e.unprotectGroup=function(e){var t=m(e)+"/community/groups/"+e.id+"/unprotect";return u.request(t,e)},e.unprotectItem=function(t){return p(t).then(function(e){e=m(t)+"/content/users/"+e+"/items/"+t.id+"/unprotect";return u.request(e,t)})},e.unshareItemWithGroup=function(i){return j(i).then(function(e){if(!e)return Promise.resolve({itemId:i.id,shortcut:!0,notUnsharedFrom:[]});var n=i.authentication.username,o=i.owner;return Promise.all([w(i),N({username:n,authentication:i.authentication})]).then(function(e){var t=e[0],r=e[1],e=(o||n)===n,r="org_admin"===r.role&&!r.roleId;if(!e&&!r&&["admin","owner"].indexOf(t)<0)throw Error("This item can not be unshared from group "+i.groupId+" by "+n+" as they not the item owner, an org admin, group admin or group owner.");return function(e){var t=e.authentication.username,r=e.owner||t,n=m(e)+"/content/items/"+e.id+"/unshare";r===t&&(n=m(e)+"/content/users/"+r+"/items/"+e.id+"/unshare");return e.params={groups:e.groupId},u.request(n,e)}(i)}).then(function(e){if(e.notUnsharedFrom.length)throw Error("Item "+i.id+" could not be unshared to group "+i.groupId);return e})})},e.updateGroup=function(e){var t=m(e)+"/community/groups/"+e.group.id+"/update";return e.params=s(s({},e.params),e.group),u.request(t,e)},e.updateItem=r,e.updateItemInfo=function(t){return p(t).then(function(e){e=m(t)+"/content/users/"+e+"/items/"+t.id+"/updateinfo";return t.params=s({folderName:t.folderName,file:t.file},t.params),u.request(e,t)})},e.updateItemResource=function(t){return p(t).then(function(e){e=m(t)+"/content/users/"+e+"/items/"+t.id+"/updateResources";return t.params=s({file:t.resource,fileName:t.name,resourcesPrefix:t.prefix,text:t.content},t.params),void 0!==t.private&&(t.params.access=t.private?"private":"inherit"),u.request(e,t)})},e.updateUser=function(e){var t=e.user.username||e.authentication.username,t=m(e)+"/community/users/"+encodeURIComponent(t)+"/update";return e.params=s(s({},e.user),e.params),delete e.user,u.request(t,e)},e.updateUserMemberships=R,Object.defineProperty(e,"__esModule",{value:!0})});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@esri/arcgis-rest-request")):"function"==typeof define&&define.amd?define(["exports","@esri/arcgis-rest-request"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).arcgisRest=e.arcgisRest||{},e.arcgisRest)}(this,function(e,u){"use strict";var s=function(){return(s=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)};function t(e,a,u,s){return new(u=u||Promise)(function(r,t){function n(e){try{i(s.next(e))}catch(e){t(e)}}function o(e){try{i(s.throw(e))}catch(e){t(e)}}function i(e){var t;e.done?r(e.value):((t=e.value)instanceof u?t:new u(function(e){e(t)})).then(n,o)}i((s=s.apply(e,a||[])).next())})}function c(r,n){var o,i,a,u={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]},e={next:t(0),throw:t(1),return:t(2)};return"function"==typeof Symbol&&(e[Symbol.iterator]=function(){return this}),e;function t(t){return function(e){return function(t){if(o)throw new TypeError("Generator is already executing.");for(;u;)try{if(o=1,i&&(a=2&t[0]?i.return:t[0]?i.throw||((a=i.return)&&a.call(i),0):i.next)&&!(a=a.call(i,t[1])).done)return a;switch(i=0,a&&(t=[2&t[0],a.value]),t[0]){case 0:case 1:a=t;break;case 4:return u.label++,{value:t[1],done:!1};case 5:u.label++,i=t[1],t=[0];continue;case 7:t=u.ops.pop(),u.trys.pop();continue;default:if(!(a=0<(a=u.trys).length&&a[a.length-1])&&(6===t[0]||2===t[0])){u=0;continue}if(3===t[0]&&(!a||t[1]>a[0]&&t[1]<a[3])){u.label=t[1];break}if(6===t[0]&&u.label<a[1]){u.label=a[1],a=t;break}if(a&&u.label<a[2]){u.label=a[2],u.ops.push(t);break}a[2]&&u.ops.pop(),u.trys.pop();continue}t=n.call(r,u)}catch(e){t=[6,e],i=0}finally{o=a=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}([t,e])}}}function m(e){return void 0===e&&(e={}),e.portal?u.cleanUrl(e.portal):e.authentication?e.authentication.portal:"https://www.arcgis.com/sharing/rest"}function n(e){var t=JSON.parse(JSON.stringify(e));return t.data&&("undefined"!=typeof Blob&&e.data instanceof Blob||"ReadStream"===e.data.constructor.name?t.file=e.data:t.text=e.data,delete t.data),t}function p(e){return e.owner?Promise.resolve(e.owner):e.item&&e.item.owner?Promise.resolve(e.item.owner):e.authentication&&e.authentication.getUsername?e.authentication.getUsername():Promise.reject(new Error("Could not determine the owner of this item. Pass the `owner`, `item.owner`, or `authentication` option."))}function o(e){return Array.isArray(e)&&Array.isArray(e[0])&&Array.isArray(e[1])}function i(e){return e.join(",")}function r(t){return p(t).then(function(e){e=t.folderId?m(t)+"/content/users/"+e+"/"+t.folderId+"/items/"+t.item.id+"/update":m(t)+"/content/users/"+e+"/items/"+t.item.id+"/update";return t.params=s(s({},t.params),n(t.item)),t.params.extent&&o(t.params.extent)&&(t.params.extent=i(t.params.extent)),t.params.file&&t.params.file.constructor&&"ReadStream"===t.params.file.constructor.name&&(t.params.dataSize=t.dataSize),u.request(e,t)})}function a(r){return r.multipart&&!r.filename?Promise.reject(new Error("The filename is required for a multipart request.")):p(r).then(function(e){var t=m(r)+"/content/users/"+e,e=t+"/addItem";r.folderId&&(e=t+"/"+r.folderId+"/addItem"),r.params=s(s({},r.params),n(r.item)),r.params.extent&&o(r.params.extent)&&(r.params.extent=i(r.params.extent));t=u.appendCustomParams(r,["owner","folderId","file","dataUrl","text","async","multipart","filename","overwrite"],{params:s({},r.params)});return u.request(e,t)})}var d=/[\x00-\x1F\x7F-\x9F\xA0]/g;function h(e){return e.replace(d,"")}var f=function(e,t){return("string"==typeof t?t:m(t))+"/content/items/"+e};function l(e,t){var r=t||{},n=r.fileName,r=r.readAs;return g(e,"/info/"+(void 0===n?"iteminfo.xml":n),void 0===r?"text":r,s({httpMethod:"GET"},t))}function g(e,t,r,n){var t=""+f(e,n)+t,n=s({params:{}},n),o=n.rawResponse;return n.rawResponse=!0,n.params.f=null,u.request(t,n).then(function(e){return o?e:"json"!==r?e[r]():e.text().then(function(e){return JSON.parse(h(e))})})}function v(e,t){e=m(t)+"/community/groups/"+e,t=s({httpMethod:"GET"},t);return u.request(e,t)}function y(e){var t=e.authentication.username,t=e.owner||t;return m(e)+"/content/users/"+encodeURIComponent(t)+"/items/"+e.id+"/share"}function I(e){var t=e.authentication.username;return(e.owner||t)===t}function q(e){return e.authentication.getUser(e).then(function(e){return e&&"org_admin"===e.role&&!e.roleId})}function w(e){return v(e.groupId,e).then(function(e){return e.userMembership.memberType}).catch(function(){return"none"})}var b=(T.prototype.match=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return this.termStack=this.termStack.concat(e),this},T.prototype.in=function(e){var t="`in("+(e?'"'+e+'"':"")+")`";return this.hasRange||this.hasTerms?(e&&"*"!==e&&(this.q+=e+":"),this.commit()):(u.warn(t+" was called with no call to `match(...)` or `from(...)`/`to(...)`. Your query was not modified."),this)},T.prototype.startGroup=function(){return this.commit(),0<this.openGroups&&(this.q+=" "),this.openGroups++,this.q+="(",this},T.prototype.endGroup=function(){return this.openGroups<=0?u.warn("`endGroup(...)` was called without calling `startGroup(...)` first. Your query was not modified."):(this.commit(),this.openGroups--,this.q+=")"),this},T.prototype.and=function(){return this.addModifier("and")},T.prototype.or=function(){return this.addModifier("or")},T.prototype.not=function(){return this.addModifier("not")},T.prototype.from=function(e){return this.hasTerms?u.warn('`from(...)` is not allowed after `match(...)` try using `.from(...).to(...).in(...)`. Optionally, you may see this because dates are incorrectly formatted. Dates should be a primative Date value, aka a number in milliseconds or Date object, ie new Date("2020-01-01"). Your query was not modified.'):this.rangeStack[0]=e,this},T.prototype.to=function(e){return this.hasTerms?u.warn('`to(...)` is not allowed after `match(...)` try using `.from(...).to(...).in(...)`. Optionally, you may see this because dates are incorrectly formatted. Dates should be a primative Date value, aka a number in milliseconds or Date object, ie new Date("2020-01-01"). Your query was not modified.'):this.rangeStack[1]=e,this},T.prototype.boost=function(e){return this.commit(),this.q+="^"+e,this},T.prototype.toParam=function(){return this.commit(),this.cleanup(),this.q},T.prototype.clone=function(){return this.commit(),this.cleanup(),new T(this.q+"")},T.prototype.addModifier=function(e){return this.currentModifer?(u.warn("You have called `"+this.currentModifer+"()` after `"+e+"()`. Your current query was not modified."),this):(this.commit(),""===this.q&&"not"!==e?u.warn("You have called `"+e+"()` without calling another method to modify your query first. Try calling `match()` first."):(this.currentModifer=e,this.q+=""===this.q?"":" ",this.q+=e.toUpperCase()+" "),this)},T.prototype.needsQuotes=function(e){return/\s|:/g.test(e)},T.prototype.formatTerm=function(e){return e instanceof Date?e.getTime():"string"==typeof e&&this.needsQuotes(e)?'"'+e+'"':e},T.prototype.commit=function(){var t=this;return this.currentModifer=void 0,this.hasRange&&(this.q+="["+this.formatTerm(this.rangeStack[0])+" TO "+this.formatTerm(this.rangeStack[1])+"]",this.rangeStack=[void 0,void 0]),this.hasTerms&&(this.q+=this.termStack.map(function(e){return t.formatTerm(e)}).join(" "),this.termStack=[]),this},Object.defineProperty(T.prototype,"hasTerms",{get:function(){return 0<this.termStack.length},enumerable:!1,configurable:!0}),Object.defineProperty(T.prototype,"hasRange",{get:function(){return this.rangeStack.length&&this.rangeStack[0]&&this.rangeStack[1]},enumerable:!1,configurable:!0}),T.prototype.cleanup=function(){if(0<this.openGroups)for(u.warn("Automatically closing "+this.openGroups+" group(s). You can use `endGroup(...)` to remove this warning.");0<this.openGroups;)this.q+=")",this.openGroups--;var e=this.q;this.q=e.replace(/( AND ?| NOT ?| OR ?)*$/,""),e!==this.q&&u.warn("`startGroup(...)` was called without calling `endGroup(...)` first. Your query was not modified."),this.q=this.q.replace(/(\(\))*/,"")},T);function T(e){void 0===e&&(e=""),this.termStack=[],this.rangeStack=[],this.openGroups=0,this.q=e}function G(r,n){var e,t="string"==typeof r||r instanceof b?{httpMethod:"GET",params:{q:r}}:u.appendCustomParams(r,["q","num","start","sortField","sortOrder","searchUserAccess","searchUserName","filter","countFields","countSize","categories","categoryFilters"],{httpMethod:"GET"});switch(n){case"item":e="/search";break;case"group":e="/community/groups";break;case"groupContent":if("string"==typeof r||r instanceof b||!r.groupId)return Promise.reject(new Error("you must pass a `groupId` option to `searchGroupContent`"));e="/content/groups/"+r.groupId+"/search";break;case"communityUser":e="/community/users";break;default:e="/portals/self/users/search"}var o=m(t)+e;return u.request(o,t).then(function(t){return t.nextStart&&-1!==t.nextStart&&(t.nextPage=function(){var e;return"string"==typeof r||r instanceof b?e={q:r,start:t.nextStart}:(e=r).start=t.nextStart,G(e,n)}),t})}function U(e){return G(e,"item")}function x(e,t){if(0===e.length)return[];for(var r=[],n=0;n<e.length;n+=t)r.push(e.slice(n,n+t));return r}function P(e){var t=e.id,r=m(e)+"/community/groups/"+t+"/addUsers",t=Object.assign({},e,{admins:void 0,users:void 0}),t=function(){for(var e=0,t=0,r=arguments.length;t<r;t++)e+=arguments[t].length;for(var n=Array(e),o=0,t=0;t<r;t++)for(var i=arguments[t],a=0,u=i.length;a<u;a++,o++)n[o]=i[a];return n}(S("users",e.users,t),S("admins",e.admins,t)).map(function(e){return t=r,e=e,u.request(t,e).catch(function(e){return{errors:[e]}});var t});return Promise.all(t).then(C)}function S(o,e,i){return!e||e.length<1?[]:x(e,25).map(function(e){return t=o,r=e,n=i,Object.assign({},n,((e={})[t]=r,e.params=s(s({},n.params),((n={})[t]=r,n)),e));var t,r,n})}function C(e){var t=e.filter(function(e){return e.notAdded}).reduce(function(e,t){return e.concat(t.notAdded)},[]),e=e.filter(function(e){return e.errors}).reduce(function(e,t){return e.concat(t.errors)},[]),t={notAdded:t};return 0<e.length&&(t.errors=e),t}function E(t){var e=t.id,r=t.users,n=m(t)+"/community/groups/"+e+"/removeUsers",r=x(r,25).map(function(e){e=s(s({},t),{users:e,params:{users:e}});return u.request(n,e).catch(function(e){return{errors:[e]}})});return Promise.all(r).then(function(e){var t=function(r){return e.filter(function(e){return e[r]}).reduce(function(e,t){return e.concat(t[r])},[])},r=t("errors"),t={notRemoved:t("notRemoved")};return r.length?s(s({},t),{errors:r}):t})}function M(e){var t=e.every(function(e){return e.success}),e=e.reduce(function(e,t){return e.concat(t.errors||[])},[]),t={success:t};return 0<e.length&&(t.errors=e),t}function R(e){var t=m(e)+"/community/groups/"+e.id+"/updateUsers",r={authentication:e.authentication,params:{}};return"admin"===e.newMemberType?r.params.admins=e.users:r.params.users=e.users,u.request(t,r)}function A(e){var t=e.every(function(e){return e.success}),e=e.reduce(function(e,t){return e.concat(t.errors||[])},[]),t={success:t};return 0<e.length&&(t.errors=e),t}function N(e){var t,r,n={httpMethod:"GET"};return"string"==typeof e?r="https://www.arcgis.com/sharing/rest/community/users/"+e:(t=e.username||e.authentication.username,r=m(e)+"/community/users/"+encodeURIComponent(t),n=s(s({},e),n)),u.request(r,n)}function O(e,t){return t.params=s({org:!1,everyone:!1},t.params),"private"===t.access&&(t.params.groups=" "),"org"===t.access&&(t.params.org=!0),"public"===t.access&&(t.params.account=!0,t.params.everyone=!0),u.request(e,t)}function j(t){return U({q:"id: "+t.id+" AND group: "+t.groupId,start:1,num:10,sortField:"title",authentication:t.authentication,httpMethod:"POST"}).then(function(e){if(0<e.total)return e.results.some(function(e){return e.id===t.id})})}function k(e,t,r){void 0===t&&(t=!1),void 0===r&&(r=!1);var n=e.authentication.username,o=e.owner||n,i=m(e)+"/content/items/"+e.id+"/share";return(o===n||t&&!r)&&(i=m(e)+"/content/users/"+o+"/items/"+e.id+"/share"),e.params={groups:e.groupId,confirmItemControl:e.confirmItemControl},u.request(i,e)}function F(e,t,r,n,o){var i,a,u=t.groups||[],s=u.find(function(e){return e.id===o.groupId});if(e.orgId!==t.orgId)throw Error("User "+t.username+" is not a member of the same org as "+e.username+". Consequently they can not be added added to group "+o.groupId+" nor can item "+o.id+" be shared to the group.");if(!s&&511<u.length)throw Error("User "+t.username+" already has 512 groups, and can not be added to group "+o.groupId+". Consequently item "+o.id+" can not be shared to the group.");return a=s?r&&"member"===s.userMembership.memberType?(i=R({id:o.groupId,users:[t.username],newMemberType:"admin",authentication:o.authentication}).then(function(e){e=e.results.reduce(function(e,t){return t.success||e.push(t.username),e},[]);return Promise.resolve({notAdded:e})}).catch(function(){return{notAdded:[t.username]}}),function(e){return R({id:o.groupId,users:[t.username],newMemberType:"member",authentication:o.authentication}).then(function(){return e}).catch(function(){return e})}):(i=Promise.resolve({notAdded:[]}),function(e){return Promise.resolve(e)}):(r=r?"admins":"users",i=P(((a={id:o.groupId})[r]=[t.username],a.authentication=o.authentication,a)).then(function(e){if(e.errors&&e.errors.length)throw e.errors[0];return e}).catch(function(){return{notAdded:[t.username]}}),function(e){return E({id:o.groupId,users:[t.username],authentication:o.authentication}).then(function(){return e})}),{promise:i.then(function(e){if(e.notAdded.length)throw new Error(n);return e}),revert:a}}function D(e,t,r){var n=r.portal+"/portals/self/isServiceNameAvailable";return u.request(n,{params:{name:e,type:t},httpMethod:"GET",authentication:r})}function Y(e,t){var r=e||"self",e=m(t)+"/portals/"+r,t=s({httpMethod:"GET"},t);return"self"===r&&(t.credentials="include"),u.request(e,t)}e.SearchQueryBuilder=b,e.acceptInvitation=function(e){var t=encodeURIComponent(e.authentication.username),t=m(e)+"/community/users/"+t+"/invitations/"+e.invitationId+"/accept",e=s({},e);return u.request(t,e)},e.addGroupUsers=P,e.addItemData=function(e){return delete(e=s({item:{id:e.id,data:e.data}},e)).id,delete e.data,r(e)},e.addItemPart=function(r){var n=r.partNum;return!Number.isInteger(n)||n<1||1e4<n?Promise.reject(new Error("The part number must be an integer between 1 to 10000, inclusive.")):p(r).then(function(e){var t=m(r)+"/content/users/"+e+"/items/"+r.id+"/addPart?partNum="+n,e=u.appendCustomParams(r,["file"],{params:s({},r.params)});return u.request(t,e)})},e.addItemRelationship=function(r){return p(r).then(function(e){var t=m(r)+"/content/users/"+e+"/addRelationship",e=u.appendCustomParams(r,["originItemId","destinationItemId","relationshipType"],{params:s({},r.params)});return u.request(t,e)})},e.addItemResource=function(t){return p(t).then(function(e){e=m(t)+"/content/users/"+e+"/items/"+t.id+"/addResources";return t.params=s({file:t.resource,fileName:t.name,resourcesPrefix:t.prefix,text:t.content,access:t.private?"private":"inherit"},t.params),u.request(e,t)})},e.bboxToString=i,e.cancelItemUpload=function(t){return p(t).then(function(e){e=m(t)+"/content/users/"+e+"/items/"+t.id+"/cancel";return u.request(e,t)})},e.commitItemUpload=function(r){return p(r).then(function(e){var t=m(r)+"/content/users/"+e+"/items/"+r.id+"/commit",e=u.appendCustomParams(r,[],{params:s(s({},r.params),n(r.item))});return u.request(t,e)})},e.createFolder=function(t){return p(t).then(function(e){e=m(t)+"/content/users/"+e+"/createFolder";return t.params=s({title:t.title},t.params),u.request(e,t)})},e.createGroup=function(e){var t=m(e)+"/community/createGroup";return e.params=s(s({},e.params),e.group),u.request(t,e)},e.createGroupNotification=function(e){var t=m(e)+"/community/groups/"+e.id+"/createNotification",e=s({params:s({subject:e.subject,message:e.message,users:e.users,notificationChannelType:e.notificationChannelType||"email",clientId:e.clientId,silentNotification:e.silentNotification,notifyAll:!e.users||0===e.users.length},e.params)},e);return u.request(t,e)},e.createItem=function(e){return a(s({folderId:null},e))},e.createItemInFolder=a,e.createOrgNotification=function(e){var n,r=m(e)+"/portals/self/createNotification",e=x((n=e).users,n.batchSize||25).map(function(e){return t=e,r=n,(e=Object.assign({},r)).params=s(s({},e.params),{users:t,subject:r.subject,message:r.message,notificationChannelType:e.notificationChannelType}),e;var t,r}).map(function(e){return t=r,e=e,u.request(t,e).catch(function(e){return{errors:[e]}});var t});return Promise.all(e).then(A)},e.declineInvitation=function(e){var t=encodeURIComponent(e.authentication.username),t=m(e)+"/community/users/"+t+"/invitations/"+e.invitationId+"/decline",e=s({},e);return u.request(t,e)},e.determineOwner=p,e.ensureMembership=F,e.exportItem=function(t){var r=t.authentication,n=t.id,o=t.title,i=t.exportFormat,a=t.exportParameters;return p(t).then(function(e){return m(t)+"/content/users/"+e+"/export"}).then(function(e){return u.request(e,{httpMethod:"POST",authentication:r,params:{itemId:n,title:o,exportFormat:i,exportParameters:a}})})},e.getGroup=v,e.getGroupCategorySchema=function(e,t){return e=m(t)+"/community/groups/"+e+"/categorySchema",t=s({httpMethod:"GET"},t),u.request(e,t)},e.getGroupContent=function(e,t){var r=m(t)+"/content/groups/"+e,e=s(s({httpMethod:"GET"},{params:{start:1,num:100}}),t);return t&&t.paging&&(e.params=s({},t.paging)),u.request(r,e)},e.getGroupUsers=function(e,t){return e=m(t)+"/community/groups/"+e+"/users",t=s({httpMethod:"GET"},t),u.request(e,t)},e.getItem=function(e,t){return e=f(e,t),t=s({httpMethod:"GET"},t),u.request(e,t)},e.getItemBaseUrl=f,e.getItemData=function(e,t){return e=f(e,t)+"/data",(t=s({httpMethod:"GET",params:{}},t)).file&&(t.params.f=null),u.request(e,t).catch(function(e){var t=RegExp(/The string did not match the expected pattern|(Unexpected end of (JSON input|data at line 1 column 1))/i);if(!t.test(e.message))throw e})},e.getItemGroups=function(e,t){return e=f(e,t)+"/groups",u.request(e,t)},e.getItemInfo=l,e.getItemMetadata=function(e,t){return l(e,s(s({},t),{fileName:"metadata/metadata.xml"}))},e.getItemParts=function(t){return p(t).then(function(e){e=m(t)+"/content/users/"+e+"/items/"+t.id+"/parts";return u.request(e,t)})},e.getItemResource=function(e,t){var r=t.readAs||"blob";return g(e,"/resources/"+t.fileName,r,t)},e.getItemResources=function(e,t){return e=f(e,t)+"/resources",(t=s({},t)).params=s({num:1e3},t.params),u.request(e,t)},e.getItemStatus=function(r){return p(r).then(function(e){var t=m(r)+"/content/users/"+e+"/items/"+r.id+"/status",e=u.appendCustomParams(r,["jobId","jobType"],{params:s({},r.params)});return u.request(t,e)})},e.getPortal=Y,e.getPortalSettings=function(e,t){return e=e||"self",e=m(t)+"/portals/"+e+"/settings",t=s({httpMethod:"GET"},t),u.request(e,t)},e.getPortalUrl=m,e.getRelatedItems=function(e){var t=f(e.id,e)+"/relatedItems",r=s({httpMethod:"GET",params:{direction:e.direction}},e);return"string"==typeof e.relationshipType?r.params.relationshipType=e.relationshipType:r.params.relationshipTypes=e.relationshipType,delete r.direction,delete r.relationshipType,u.request(t,r)},e.getSelf=function(e){return Y(null,e)},e.getSharingUrl=y,e.getSubscriptionInfo=function(e,t){return e=e||"self",e=m(t)+"/portals/"+e+"/subscriptionInfo",t=s({httpMethod:"GET"},t),u.request(e,t)},e.getUniqueServiceName=function t(r,n,o,i){var a=i?r+"_"+i:r;return D(a,n,o).then(function(e){return e.available?a:t(r,n,o,i+=1)})},e.getUser=N,e.getUserContent=function(t){var e=t.folderId,r=t.start,n=void 0===r?1:r,r=t.num,o=void 0===r?10:r,i=t.authentication,a=e?"/"+e:"";return p(t).then(function(e){return m(t)+"/content/users/"+e+a}).then(function(e){return u.request(e,{httpMethod:"GET",authentication:i,params:{start:n,num:o}})})},e.getUserInvitation=function(e){var t=encodeURIComponent(e.authentication.username),r=m(e)+"/community/users/"+t+"/invitations/"+e.invitationId,t={httpMethod:"GET"},t=s(s({},e),t);return u.request(r,t)},e.getUserInvitations=function(e){var t={httpMethod:"GET"},r=encodeURIComponent(e.authentication.username),r=m(e)+"/community/users/"+r+"/invitations",t=s(s({},e),t);return u.request(r,t)},e.getUserMembership=w,e.getUserNotifications=function(e){var t={httpMethod:"GET"},r=encodeURIComponent(e.authentication.username),r=m(e)+"/community/users/"+r+"/notifications",t=s(s({},e),t);return u.request(r,t)},e.getUserProperties=function(r,n){return t(this,void 0,void 0,function(){var t;return c(this,function(e){switch(e.label){case 0:return t=m(n)+"/community/users/"+encodeURIComponent(r)+"/properties",[4,u.request(t,s({httpMethod:"GET"},n))];case 1:return(t=e.sent()).properties.mapViewer||(t.properties.mapViewer="modern"),[2,t.properties]}})})},e.getUserTags=function(e){var t=e.username||e.authentication.username,t=m(e)+"/community/users/"+encodeURIComponent(t)+"/tags";return u.request(t,e)},e.getUserUrl=function(e){return m(e)+"/community/users/"+encodeURIComponent(e.username)},e.inviteGroupUsers=function(e){var t,r=e.id,n=m(e)+"/community/groups/"+r+"/invite",e=x((t=e).users,25).map(function(e){return function(e,t){t=Object.assign({},t);return t.params=s(s({},t.params),{users:e,role:t.role,expiration:t.expiration}),t}(e,t)}).map(function(e){return t=n,e=e,u.request(t,e).catch(function(e){return{errors:[e]}});var t});return Promise.all(e).then(M)},e.isBBox=o,e.isItemOwner=I,e.isItemSharedWithGroup=j,e.isOrgAdmin=q,e.isServiceNameAvailable=D,e.joinGroup=function(e){var t=m(e)+"/community/groups/"+e.id+"/join";return u.request(t,e)},e.leaveGroup=function(e){var t=m(e)+"/community/groups/"+e.id+"/leave";return u.request(t,e)},e.moveItem=function(r){return p(r).then(function(e){var t=m(r)+"/content/users/"+e+"/items/"+r.itemId+"/move",e=(e=r.folderId)||"/";return r.params=s({folder:e},r.params),u.request(t,r)})},e.protectGroup=function(e){var t=m(e)+"/community/groups/"+e.id+"/protect";return u.request(t,e)},e.protectItem=function(t){return p(t).then(function(e){e=m(t)+"/content/users/"+e+"/items/"+t.id+"/protect";return u.request(e,t)})},e.reassignItem=function(r){return q(r).then(function(e){if(!e)throw Error("Item "+r.id+" can not be reassigned because current user is not an organization administrator.");var t=m(r)+"/content/users/"+r.currentOwner+"/items/"+r.id+"/reassign",e={params:{targetUsername:r.targetUsername,targetFolderName:r.targetFolderName},authentication:r.authentication};return u.request(t,e)})},e.removeFolder=function(t){return p(t).then(function(e){e=m(t)+"/content/users/"+encodeURIComponent(e)+"/"+t.folderId+"/delete";return u.request(e,t)})},e.removeGroup=function(e){var t=m(e)+"/community/groups/"+e.id+"/delete",e=s({},e);return u.request(t,e)},e.removeGroupUsers=E,e.removeItem=function(t){return p(t).then(function(e){e=m(t)+"/content/users/"+e+"/items/"+t.id+"/delete";return u.request(e,t)})},e.removeItemRelationship=function(r){return p(r).then(function(e){var t=m(r)+"/content/users/"+e+"/deleteRelationship",e=u.appendCustomParams(r,["originItemId","destinationItemId","relationshipType"],{params:s({},r.params)});return u.request(t,e)})},e.removeItemResource=function(t){return p(t).then(function(e){e=m(t)+"/content/users/"+e+"/items/"+t.id+"/removeResources";return t.params=s(s({},t.params),{resource:t.resource}),void 0!==t.deleteAll&&(t.params.deleteAll=t.deleteAll),u.request(e,t)})},e.removeNotification=function(e){var t=encodeURIComponent(e.authentication.username),t=m(e)+"/community/users/"+t+"/notifications/"+e.id+"/delete";return u.request(t,e)},e.scrubControlChars=h,e.searchCommunityUsers=function(e){return G(e,"communityUser")},e.searchGroupContent=function(e){return G(e,"groupContent")},e.searchGroupUsers=function(e,t){return e=m(t)+"/community/groups/"+e+"/userlist",t=u.appendCustomParams(t||{},["name","num","start","sortField","sortOrder","joined","memberType"],{httpMethod:"GET"}),u.request(e,t)},e.searchGroups=function(e){return G(e,"group")},e.searchItems=U,e.searchUsers=function(e){return G(e,"user")},e.serializeItem=n,e.setItemAccess=function(t){var r=y(t);return I(t)?O(r,t):q(t).then(function(e){if(e)return O(r,t);throw Error("This item can not be shared by "+t.authentication.username+". They are neither the item owner nor an organization admin.")})},e.setUserProperties=function(o,i,a){return t(this,void 0,void 0,function(){var t,r,n;return c(this,function(e){switch(e.label){case 0:t=m(a)+"/community/users/"+encodeURIComponent(o)+"/setProperties",r=s({httpMethod:"POST",params:{properties:i}},a),e.label=1;case 1:return e.trys.push([1,3,,4]),[4,u.request(t,r)];case 2:if(!(n=e.sent()).success)throw new Error("Success was false");return[2,n];case 3:throw n=e.sent(),new Error("Failed to set user properties: "+n.message);case 4:return[2]}})})},e.shareItemWithGroup=function(u){return j(u).then(function(e){if(e)return{itemId:u.id,shortcut:!0,notSharedWith:[]};var t=u.authentication.username,e=u.owner,o=u.confirmItemControl,e=e||t;if(e===t)return k(u);var i=!1,a=!1;return Promise.all([N({username:t,authentication:u.authentication}),N({username:e,authentication:u.authentication}),w(u)]).then(function(e){var t=e[0],r=e[1],n=e[2],e=!!o;return i="org_admin"===t.role&&!t.roleId,a=t.orgId!==r.orgId,function(e,t,r,n,o,i){var a=[];if(i.groupId!==e.favGroupId)if(t){if(!n)throw Error("This item can not be shared to shared editing group "+i.groupId+" by "+e.username+" as they not the item owner or org admin.");a.push(F(e,e,!1,"Error adding "+e.username+" as member to edit group "+i.groupId+". Consequently item "+i.id+" was not shared to the group.",i),F(e,o,!0,"none"===r?"Error adding user "+o.username+" to edit group "+i.groupId+". Consequently item "+i.id+" was not shared to the group.":"Error promoting user "+o.username+" to admin in edit group "+i.groupId+". Consequently item "+i.id+" was not shared to the group.",i))}else if(n)a.push(F(e,e,!1,"Error adding "+e.username+" as member to view group "+i.groupId+". Consequently item "+i.id+" was not shared to the group.",i));else if("none"===r)throw new Error("This item can not be shared by "+e.username+" as they are not a member of the specified group "+i.groupId+".");return a}(t,e,n,i,r,u)}).then(function(e){var t=e[0],r=(void 0===t?{promise:Promise.resolve({notAdded:[]}),revert:function(e){return Promise.resolve(e)}}:t).revert;return Promise.all(e.map(function(e){return e.promise})).then(function(){return k(u,i,a)}).then(function(e){return r(e)})})}).then(function(e){if(e.notSharedWith.length)throw Error("Item "+u.id+" could not be shared to group "+u.groupId+".");return e})},e.unprotectGroup=function(e){var t=m(e)+"/community/groups/"+e.id+"/unprotect";return u.request(t,e)},e.unprotectItem=function(t){return p(t).then(function(e){e=m(t)+"/content/users/"+e+"/items/"+t.id+"/unprotect";return u.request(e,t)})},e.unshareItemWithGroup=function(i){return j(i).then(function(e){if(!e)return Promise.resolve({itemId:i.id,shortcut:!0,notUnsharedFrom:[]});var n=i.authentication.username,o=i.owner;return Promise.all([w(i),N({username:n,authentication:i.authentication})]).then(function(e){var t=e[0],r=e[1],e=(o||n)===n,r="org_admin"===r.role&&!r.roleId;if(!e&&!r&&["admin","owner"].indexOf(t)<0)throw Error("This item can not be unshared from group "+i.groupId+" by "+n+" as they not the item owner, an org admin, group admin or group owner.");return function(e){var t=e.authentication.username,r=e.owner||t,n=m(e)+"/content/items/"+e.id+"/unshare";r===t&&(n=m(e)+"/content/users/"+r+"/items/"+e.id+"/unshare");return e.params={groups:e.groupId},u.request(n,e)}(i)}).then(function(e){if(e.notUnsharedFrom.length)throw Error("Item "+i.id+" could not be unshared to group "+i.groupId);return e})})},e.updateGroup=function(e){var t=m(e)+"/community/groups/"+e.group.id+"/update";return e.params=s(s({},e.params),e.group),u.request(t,e)},e.updateItem=r,e.updateItemInfo=function(t){return p(t).then(function(e){e=m(t)+"/content/users/"+e+"/items/"+t.id+"/updateinfo";return t.params=s({folderName:t.folderName,file:t.file},t.params),u.request(e,t)})},e.updateItemResource=function(t){return p(t).then(function(e){e=m(t)+"/content/users/"+e+"/items/"+t.id+"/updateResources";return t.params=s({file:t.resource,fileName:t.name,resourcesPrefix:t.prefix,text:t.content},t.params),void 0!==t.private&&(t.params.access=t.private?"private":"inherit"),u.request(e,t)})},e.updateUser=function(e){var t=e.user.username||e.authentication.username,t=m(e)+"/community/users/"+encodeURIComponent(t)+"/update";return e.params=s(s({},e.user),e.params),delete e.user,u.request(t,e)},e.updateUserMemberships=R,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=portal.umd.min.js.map
{
"name": "@esri/arcgis-rest-portal",
"version": "3.7.0",
"version": "3.8.0",
"description": "ArcGIS Online and Enterprise content and user helpers for @esri/arcgis-rest-request",

@@ -16,8 +16,8 @@ "main": "dist/node/index.js",

"dependencies": {
"@esri/arcgis-rest-types": "^3.7.0",
"@esri/arcgis-rest-types": "^3.8.0",
"tslib": "^1.13.0"
},
"devDependencies": {
"@esri/arcgis-rest-auth": "^3.7.0",
"@esri/arcgis-rest-request": "^3.7.0"
"@esri/arcgis-rest-auth": "^3.8.0",
"@esri/arcgis-rest-request": "^3.8.0"
},

@@ -24,0 +24,0 @@ "peerDependencies": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet