@esri/arcgis-rest-portal
Version:
ArcGIS Online and Enterprise content and user helpers for @esri/arcgis-rest-request
8 lines (7 loc) • 26 kB
JavaScript
/* @preserve
* @esri/arcgis-rest-portal - v4.6.1 - Apache-2.0
* Copyright (c) 2017-2025 Esri, Inc.
* Wed Aug 13 2025 20:30:31 GMT+0000 (Coordinated Universal Time)
*/
import{cleanUrl as t,request as e,appendCustomParams as n,warn as r}from"@esri/arcgis-rest-request";function s(e={}){return e.portal?t(e.portal):e.authentication&&"string"!=typeof e.authentication?e.authentication.portal:"https://www.arcgis.com/sharing/rest"}function o(t){return t.owner?Promise.resolve(t.owner):t.item&&t.item.owner?Promise.resolve(t.item.owner):t.authentication&&t.authentication.getUsername?t.authentication.getUsername():Promise.reject(new Error("Could not determine the owner of this item. Pass the `owner`, `item.owner`, or `authentication` option."))}function i(t){return Array.isArray(t)&&Array.isArray(t[0])&&Array.isArray(t[1])}function a(t){return t.join(",")}function u(t){return o(t).then((n=>{const r=t.folderId?`${s(t)}/content/users/${n}/${t.folderId}/items/${t.item.id}/update`:`${s(t)}/content/users/${n}/items/${t.item.id}/update`;return t.params=Object.assign(Object.assign({},t.params),t.item),t.params.extent&&i(t.params.extent)&&(t.params.extent=a(t.params.extent)),e(r,t)}))}function c(t){return o(t).then((n=>{const r=`${s(t)}/content/users/${n}/items/${t.id}/updateinfo`;return t.params=Object.assign({folderName:t.folderName,file:t.file},t.params),e(r,t)}))}function m(t){return o(t).then((n=>{const r=`${s(t)}/content/users/${n}/items/${t.id}/updateResources`;return t.params=Object.assign({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"),e(r,t)}))}function h(t){return o(t).then((n=>{const r=`${s(t)}/content/users/${n}/items/${t.itemId}/move`;let o=t.folderId;return o||(o="/"),t.params=Object.assign({folder:o},t.params),e(r,t)}))}function d(t){const e=Object.assign({item:{id:t.id,text:t.text,file:t.file}},t);return delete e.id,delete e.data,u(e)}function p(t){return o(t).then((r=>{const o=`${s(t)}/content/users/${r}/addRelationship`,i=n(t,["originItemId","destinationItemId","relationshipType"],{params:Object.assign({},t.params)});return e(o,i)}))}function l(t){return o(t).then((n=>{const r=`${s(t)}/content/users/${n}/items/${t.id}/addResources`;return t.params=Object.assign({file:t.resource,fileName:t.name,resourcesPrefix:t.prefix,text:t.content,access:t.private?"private":"inherit"},t.params),e(r,t)}))}const g=t=>{const{folderId:n,start:r=1,num:i=10,authentication:a}=t,u=n?`/${n}`:"";return o(t).then((e=>`${s(t)}/content/users/${e}${u}`)).then((t=>e(t,{httpMethod:"GET",authentication:a,params:{start:r,num:i}})))};function f(t){return o(t).then((n=>{const r=`${`${s(t)}/content/users/${n}`}/createFolder`;return t.params=Object.assign({title:t.title},t.params),e(r,t)}))}function $(t){return t.multipart&&!t.filename?Promise.reject(new Error("The filename is required for a multipart request.")):o(t).then((r=>{const o=`${s(t)}/content/users/${r}`;let u=`${o}/addItem`;t.folderId&&(u=`${o}/${t.folderId}/addItem`),t.params=Object.assign(Object.assign({},t.params),t.item),t.params.extent&&i(t.params.extent)&&(t.params.extent=a(t.params.extent));const c=n(t,["owner","folderId","file","dataUrl","text","async","multipart","filename","overwrite"],{params:Object.assign({},t.params)});return e(u,c)}))}function b(t){return $(Object.assign({folderId:null},t))}const y=t=>{const{authentication:n,id:r,title:i,exportFormat:a,exportParameters:u}=t;return o(t).then((e=>`${s(t)}/content/users/${e}/export`)).then((t=>e(t,{httpMethod:"POST",authentication:n,params:{itemId:r,title:i,exportFormat:a,exportParameters:u}})))},w=/[\x00-\x1F\x7F-\x9F\xA0]/g;function j(t){return t.replace(w,"")}function O(t,n){const r=I(t,n),s=Object.assign({httpMethod:"GET"},n);return e(r,s)}const I=(t,e)=>`${"string"==typeof e?e:s(e)}/content/items/${t}`;function T(t,n){const r=`${I(t,n)}/data`,s=Object.assign({httpMethod:"GET",params:{}},n);return s.file&&(s.params.f=null),e(r,s).catch((t=>{if(!RegExp(/The string did not match the expected pattern|(Unexpected end of (JSON input|data at line 1 column 1))/i).test(t.message))throw t}))}function v(t){const n=`${I(t.id,t)}/relatedItems`,r=Object.assign({httpMethod:"GET",params:{direction:t.direction}},t);return"string"==typeof t.relationshipType?r.params.relationshipType=t.relationshipType:r.params.relationshipTypes=t.relationshipType,delete r.direction,delete r.relationshipType,e(n,r)}function x(t,n){const r=`${I(t,n)}/resources`,s=Object.assign({},n);return s.params=Object.assign({num:1e3},s.params),e(r,s)}function E(t,e){const n=e.readAs||"blob";return P(t,`/resources/${e.fileName}`,n,e)}function q(t,n){const r=`${I(t,n)}/groups`;return e(r,n)}function G(t){return o(t).then((r=>{const o=`${s(t)}/content/users/${r}/items/${t.id}/status`,i=n(t,["jobId","jobType"],{params:Object.assign({},t.params)});return e(o,i)}))}function M(t){return o(t).then((n=>{const r=`${s(t)}/content/users/${n}/items/${t.id}/parts`;return e(r,t)}))}function U(t,e){const{fileName:n="iteminfo.xml",readAs:r="text"}=e||{};return P(t,`/info/${n}`,r,Object.assign({httpMethod:"GET"},e))}function S(t,e){return U(t,Object.assign(Object.assign({},e),{fileName:"metadata/metadata.xml"}))}function P(t,n,r,s){const o=`${I(t,s)}${n}`,i=Object.assign({params:{}},s),a=i.rawResponse;return i.rawResponse=!0,i.params.f=null,e(o,i).then((t=>a?t:"json"!==r?t[r]():t.text().then((t=>JSON.parse(j(t))))))}function A(t){return o(t).then((n=>{const r=`${s(t)}/content/users/${n}/items/${t.id}/protect`;return e(r,t)}))}function C(t){return o(t).then((n=>{const r=`${s(t)}/content/users/${n}/items/${t.id}/unprotect`;return e(r,t)}))}function N(t,n){const r=`${s(n)}/community/groups/${t}`,o=Object.assign({httpMethod:"GET"},n);return e(r,o)}function R(t,n){const r=`${s(n)}/community/groups/${t}/categorySchema`,o=Object.assign({httpMethod:"GET"},n);return e(r,o)}function k(t,n){const r=`${s(n)}/content/groups/${t}`,o=Object.assign(Object.assign({httpMethod:"GET"},{params:{start:1,num:100}}),n);return n&&n.paging&&(o.params=Object.assign({},n.paging)),e(r,o)}function F(t,n){const r=`${s(n)}/community/groups/${t}/users`,o=Object.assign({httpMethod:"GET"},n);return e(r,o)}function D(t,r){const o=`${s(r)}/community/groups/${t}/userlist`,i=n(r||{},["name","num","start","sortField","sortOrder","joined","memberType"],{httpMethod:"GET"});return e(o,i)}function Y(t,e){const n=e||t.authentication.username,r=t.owner||n;return`${s(t)}/content/users/${encodeURIComponent(r)}/items/${t.id}/share`}function z(t,e){const n=e||t.authentication.username;return(t.owner||n)===n}function W(t){return t.authentication.getUser().then((t=>t&&"org_admin"===t.role&&!t.roleId))}function _(t){return N(t.groupId,t).then((t=>t.userMembership.memberType)).catch((()=>"none"))}function J(t){return W(t).then((n=>{if(!n)throw Error(`Item ${t.id} can not be reassigned because current user is not an organization administrator.`);const r=`${s(t)}/content/users/${t.currentOwner}/items/${t.id}/reassign`,o={params:{targetUsername:t.targetUsername,targetFolderName:t.targetFolderName},authentication:t.authentication};return e(r,o)}))}function V(t){return o(t).then((n=>{const r=`${s(t)}/content/users/${n}/items/${t.id}/delete`;return e(r,t)}))}function B(t){return o(t).then((r=>{const o=`${s(t)}/content/users/${r}/deleteRelationship`,i=n(t,["originItemId","destinationItemId","relationshipType"],{params:Object.assign({},t.params)});return e(o,i)}))}function H(t){return o(t).then((n=>{const r=`${s(t)}/content/users/${n}/items/${t.id}/removeResources`;return t.params=Object.assign(Object.assign({},t.params),{resource:t.resource}),void 0!==t.deleteAll&&(t.params.deleteAll=t.deleteAll),e(r,t)}))}function K(t){return o(t).then((n=>{const r=`${s(t)}/content/users/${encodeURIComponent(n)}/${t.folderId}/delete`;return e(r,t)}))}function L(t){return o(t).then((n=>{const r=`${s(t)}/content/users/${n}/items/${t.id}/deleteThumbnail`;return e(r,t)}))}class Q{constructor(t=""){this.termStack=[],this.rangeStack=[],this.openGroups=0,this.q=t}match(...t){return this.termStack=this.termStack.concat(t),this}in(t){const e=`\`in(${t?`"${t}"`:""})\``;return this.hasRange||this.hasTerms?(t&&"*"!==t&&(this.q+=`${t}:`),this.commit()):(r(`${e} was called with no call to \`match(...)\` or \`from(...)\`/\`to(...)\`. Your query was not modified.`),this)}startGroup(){return this.commit(),this.openGroups>0&&(this.q+=" "),this.openGroups++,this.q+="(",this}endGroup(){return this.openGroups<=0?(r("`endGroup(...)` was called without calling `startGroup(...)` first. Your query was not modified."),this):(this.commit(),this.openGroups--,this.q+=")",this)}and(){return this.addModifier("and")}or(){return this.addModifier("or")}not(){return this.addModifier("not")}from(t){return this.hasTerms?(r('`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):(this.rangeStack[0]=t,this)}to(t){return this.hasTerms?(r('`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):(this.rangeStack[1]=t,this)}boost(t){return this.commit(),this.q+=`^${t}`,this}toParam(){return this.commit(),this.cleanup(),this.q}clone(){return this.commit(),this.cleanup(),new Q(this.q+"")}addModifier(t){return this.currentModifer?(r(`You have called \`${this.currentModifer}()\` after \`${t}()\`. Your current query was not modified.`),this):(this.commit(),""===this.q&&"not"!==t?(r(`You have called \`${t}()\` without calling another method to modify your query first. Try calling \`match()\` first.`),this):(this.currentModifer=t,this.q+=""===this.q?"":" ",this.q+=`${t.toUpperCase()} `,this))}hasWhiteSpace(t){return/\s/g.test(t)}formatTerm(t){return t instanceof Date?t.getTime():"string"==typeof t&&this.hasWhiteSpace(t)?`"${t}"`:t}commit(){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((t=>this.formatTerm(t))).join(" "),this.termStack=[]),this}get hasTerms(){return this.termStack.length>0}get hasRange(){return this.rangeStack.length&&this.rangeStack[0]&&this.rangeStack[1]}cleanup(){if(this.openGroups>0)for(r(`Automatically closing ${this.openGroups} group(s). You can use \`endGroup(...)\` to remove this warning.`);this.openGroups>0;)this.q+=")",this.openGroups--;const t=this.q;this.q=t.replace(/( AND ?| NOT ?| OR ?)*$/,""),t!==this.q&&r("`startGroup(...)` was called without calling `endGroup(...)` first. Your query was not modified."),this.q=this.q.replace(/(\(\))*/,"")}}function X(t,r){let o,i;switch(o="string"==typeof t||t instanceof Q?{httpMethod:"GET",params:{q:t}}:n(t,["q","num","start","sortField","sortOrder","searchUserAccess","searchUserName","filter","countFields","countSize","categories","categoryFilters"],{httpMethod:"GET"}),r){case"item":i="/search";break;case"group":i="/community/groups";break;case"groupContent":if("string"==typeof t||t instanceof Q||!t.groupId)return Promise.reject(new Error("you must pass a `groupId` option to `searchGroupContent`"));i=`/content/groups/${t.groupId}/search`;break;case"communityUser":i="/community/users";break;default:i="/portals/self/users/search"}const a=s(o)+i;return e(a,o).then((e=>(e.nextStart&&-1!==e.nextStart&&(e.nextPage=function(){let n;return"string"==typeof t||t instanceof Q?n={q:t,start:e.nextStart}:(n=t,n.start=e.nextStart),X(n,r)}),e)))}function Z(t){return X(t,"item")}function tt(t){const r=t.partNum;return!Number.isInteger(r)||r<1||r>1e4?Promise.reject(new Error("The part number must be an integer between 1 to 10000, inclusive.")):o(t).then((o=>{const i=`${s(t)}/content/users/${o}/items/${t.id}/addPart?partNum=${r}`,a=n(t,["file"],{params:Object.assign({},t.params)});return e(i,a)}))}function et(t){return o(t).then((r=>{const o=`${s(t)}/content/users/${r}/items/${t.id}/commit`,i=n(t,[],{params:Object.assign(Object.assign({},t.params),t.item)});return e(o,i)}))}function nt(t){return o(t).then((n=>{const r=`${s(t)}/content/users/${n}/items/${t.id}/cancel`;return e(r,t)}))}function rt(t,e){if(0===t.length)return[];const n=[];for(let r=0;r<t.length;r+=e)n.push(t.slice(r,r+e));return n}function st(t){const n=t.id,r=`${s(t)}/community/groups/${n}/addUsers`,o=Object.assign({},t,{admins:void 0,users:void 0}),i=[...ot("users",t.users,o),...ot("admins",t.admins,o)].map((t=>function(t,n){return e(t,n).catch((t=>({errors:[t]})))}(r,t)));return Promise.all(i).then(it)}function ot(t,e,n){if(!e||e.length<1)return[];return rt(e,25).map((e=>function(t,e,n){return Object.assign({},n,{[t]:e,params:Object.assign(Object.assign({},n.params),{[t]:e})})}(t,e,n)))}function it(t){const e=t.filter((t=>t.notAdded)).reduce(((t,e)=>t.concat(e.notAdded)),[]),n=t.filter((t=>t.errors)).reduce(((t,e)=>t.concat(e.errors)),[]),r={notAdded:e};return n.length>0&&(r.errors=n),r}function at(t){const{id:n,users:r}=t,o=`${s(t)}/community/groups/${n}/removeUsers`,i=rt(r,25).map((n=>(n=>{const r=Object.assign(Object.assign({},t),{users:n,params:{users:n}});return e(o,r).catch((t=>({errors:[t]})))})(n)));return Promise.all(i).then((t=>{const e=e=>t.filter((t=>t[e])).reduce(((t,n)=>t.concat(n[e])),[]),n=e("errors"),r={notRemoved:e("notRemoved")};return n.length?Object.assign(Object.assign({},r),{errors:n}):r}))}function ut(t){const n=t.id,r=`${s(t)}/community/groups/${n}/invite`,o=function(t){const e=rt(t.users,25);return e.map((e=>function(t,e){const n=Object.assign({},e);return n.params=Object.assign(Object.assign({},n.params),{users:t,role:n.role,expiration:n.expiration}),n}(e,t)))}(t),i=o.map((t=>function(t,n){return e(t,n).catch((t=>({errors:[t]})))}(r,t)));return Promise.all(i).then(ct)}function ct(t){const e=t.every((t=>t.success)),n=t.reduce(((t,e)=>t.concat(e.errors||[])),[]),r={success:e};return n.length>0&&(r.errors=n),r}function mt(t){const n=`${s(t)}/community/createGroup`;return t.params=Object.assign(Object.assign({},t.params),t.group),e(n,t)}function ht(t){const n=`${s(t)}/community/groups/${t.id}/createNotification`,r=Object.assign({params:Object.assign({subject:t.subject,message:t.message,users:t.users,notificationChannelType:t.notificationChannelType||"email",clientId:t.clientId,silentNotification:t.silentNotification,notifyAll:!t.users||0===t.users.length},t.params)},t);return e(n,r)}function dt(t){const n=`${s(t)}/community/groups/${t.id}/protect`;return e(n,t)}function pt(t){const n=`${s(t)}/community/groups/${t.id}/unprotect`;return e(n,t)}function lt(t){const n=`${s(t)}/community/groups/${t.id}/delete`,r=Object.assign({},t);return e(n,r)}function gt(t){return X(t,"group")}function ft(t){return X(t,"groupContent")}function $t(t){const n=`${s(t)}/community/groups/${t.group.id}/update`;return t.params=Object.assign(Object.assign({},t.params),t.group),e(n,t)}function bt(t){const n=`${s(t)}/community/groups/${t.id}/updateUsers`,r={authentication:t.authentication,params:{}};return"admin"===t.newMemberType?r.params.admins=t.users:r.params.users=t.users,e(n,r)}function yt(t){const n=`${s(t)}/community/groups/${t.id}/join`;return e(n,t)}function wt(t){const n=`${s(t)}/community/groups/${t.id}/leave`;return e(n,t)}function jt(t){const n=`${s(t)}/portals/self/createNotification`,r=function(t){const e=rt(t.users,t.batchSize||25);return e.map((e=>function(t,e){const n=Object.assign({},e);return n.params=Object.assign(Object.assign({},n.params),{users:t,subject:e.subject,message:e.message,notificationChannelType:n.notificationChannelType}),n}(e,t)))}(t),o=r.map((t=>function(t,n){return e(t,n).catch((t=>({errors:[t]})))}(n,t)));return Promise.all(o).then(Ot)}function Ot(t){const e=t.every((t=>t.success)),n=t.reduce(((t,e)=>t.concat(e.errors||[])),[]),r={success:e};return n.length>0&&(r.errors=n),r}async function It(t){var e;return t.username?encodeURIComponent(t.username):(null===(e=t.authentication)||void 0===e?void 0:e.username)?encodeURIComponent(t.authentication.username):t.authentication?t.authentication.getUsername().then(encodeURIComponent):void 0}async function Tt(t){let n,r={httpMethod:"GET"};if("string"==typeof t)n=`https://www.arcgis.com/sharing/rest/community/users/${t}`;else{const e=await It(t);n=`${s(t)}/community/users/${e}`,r=Object.assign(Object.assign({},t),r)}return e(n,r)}async function vt(t){const n=await It(t),r=`${s(t)}/community/users/${n}/tags`;return e(r,t)}function xt(t){return`${s(t)}/community/users/${encodeURIComponent(t.username)}`}async function Et(t){let n={httpMethod:"GET"};const r=await It(t),o=`${s(t)}/community/users/${r}/invitations`;return n=Object.assign(Object.assign({},t),n),e(o,n)}async function qt(t){const n=await It(t),r=`${s(t)}/community/users/${n}/invitations/${t.invitationId}`;let o={httpMethod:"GET"};return o=Object.assign(Object.assign({},t),o),e(r,o)}async function Gt(t){const n=await It(t),r=`${s(t)}/community/users/${n}/invitations/${t.invitationId}/accept`,o=Object.assign({},t);return e(r,o)}async function Mt(t){const n=await It(t),r=`${s(t)}/community/users/${n}/invitations/${t.invitationId}/decline`,o=Object.assign({},t);return e(r,o)}async function Ut(t){let n={httpMethod:"GET"};const r=await It(t),o=`${s(t)}/community/users/${r}/notifications`;return n=Object.assign(Object.assign({},t),n),e(o,n)}async function St(t){const n=await It(t),r=`${s(t)}/community/users/${n}/notifications/${t.id}/delete`;return e(r,t)}function Pt(t){return X(t,"user")}function At(t){return X(t,"communityUser")}async function Ct(t){const n=t.user.username||await t.authentication.getUsername(),r=`${s(t)}/community/users/${encodeURIComponent(n)}/update`;return t.params=Object.assign(Object.assign({},t.user),t.params),delete t.user,e(r,t)}async function Nt(t,n){const r=`${s(n)}/community/users/${encodeURIComponent(t)}/properties`,o=await e(r,Object.assign({httpMethod:"GET"},n));return o.properties.mapViewer||(o.properties.mapViewer="modern"),o.properties}async function Rt(t,n,r){const o=`${s(r)}/community/users/${encodeURIComponent(t)}/setProperties`,i=Object.assign({httpMethod:"POST",params:{properties:n}},r);try{const t=await e(o,i);if(!t.success)throw new Error("Success was false");return t}catch(t){throw new Error(`Failed to set user properties: ${t.message}`)}}async function kt(t){const e=await t.authentication.getUsername(),n=Y(t,e);return z(t,e)?Ft(n,t):W(t).then((r=>{if(r)return Ft(n,t);throw Error(`This item can not be shared by ${e}. They are neither the item owner nor an organization admin.`)}))}function Ft(t,n){return n.params=Object.assign({org:!1,everyone:!1},n.params),"private"===n.access&&(n.params.groups=" "),"org"===n.access&&(n.params.org=!0),"public"===n.access&&(n.params.account=!0,n.params.everyone=!0),e(t,n)}function Dt(t){return Z({q:`id: ${t.id} AND group: ${t.groupId}`,start:1,num:10,sortField:"title",authentication:t.authentication,httpMethod:"POST"}).then((e=>{let n=!1;if(e.total>0)return n=e.results.some((e=>e.id===t.id)),n}))}async function Yt(t){return Dt(t).then((async e=>{if(e)return{itemId:t.id,shortcut:!0,notSharedWith:[]};const{owner:n,confirmItemControl:r}=t,s=await t.authentication.getUsername(),o=n||s;if(o!==s){let e=!1,n=!1;return Promise.all([Tt({username:s,authentication:t.authentication}),Tt({username:o,authentication:t.authentication}),_(t)]).then((([s,o,i])=>{const a=!!r;return e="org_admin"===s.role&&!s.roleId,n=s.orgId!==o.orgId,function(t,e,n,r,s,o){const i=[];if(o.groupId!==t.favGroupId)if(e){if(!r)throw Error(`This item can not be shared to shared editing group ${o.groupId} by ${t.username} as they not the item owner or org admin.`);i.push(Wt(t,t,!1,`Error adding ${t.username} as member to edit group ${o.groupId}. Consequently item ${o.id} was not shared to the group.`,o),Wt(t,s,!0,"none"===n?`Error adding user ${s.username} to edit group ${o.groupId}. Consequently item ${o.id} was not shared to the group.`:`Error promoting user ${s.username} to admin in edit group ${o.groupId}. Consequently item ${o.id} was not shared to the group.`,o))}else if(r)i.push(Wt(t,t,!1,`Error adding ${t.username} as member to view group ${o.groupId}. Consequently item ${o.id} was not shared to the group.`,o));else if("none"===n)throw new Error(`This item can not be shared by ${t.username} as they are not a member of the specified group ${o.groupId}.`);return i}(s,a,i,e,o,t)})).then((r=>{const[{revert:s}={promise:Promise.resolve({notAdded:[]}),revert:t=>Promise.resolve(t)}]=r;return Promise.all(r.map((({promise:t})=>t))).then((()=>zt(t,e,n))).then((t=>s(t)))}))}return zt(t)})).then((e=>{if(e.notSharedWith.length)throw Error(`Item ${t.id} could not be shared to group ${t.groupId}.`);return e}))}async function zt(t,n=!1,r=!1){const o=await t.authentication.getUsername(),i=t.owner||o;let a=`${s(t)}/content/items/${t.id}/share`;return(i===o||n&&!r)&&(a=`${s(t)}/content/users/${i}/items/${t.id}/share`),t.params={groups:t.groupId,confirmItemControl:t.confirmItemControl},e(a,t)}function Wt(t,e,n,r,s){const o=e.groups||[],i=o.find((t=>t.id===s.groupId));if(t.orgId!==e.orgId)throw Error(`User ${e.username} is not a member of the same org as ${t.username}. Consequently they can not be added added to group ${s.groupId} nor can item ${s.id} be shared to the group.`);if(!i&&o.length>511)throw Error(`User ${e.username} already has 512 groups, and can not be added to group ${s.groupId}. Consequently item ${s.id} can not be shared to the group.`);let a,u;if(i)n&&"member"===i.userMembership.memberType?(a=bt({id:s.groupId,users:[e.username],newMemberType:"admin",authentication:s.authentication}).then((t=>{const e=t.results.reduce(((t,e)=>(e.success||t.push(e.username),t)),[]);return Promise.resolve({notAdded:e})})).catch((()=>({notAdded:[e.username]}))),u=t=>bt({id:s.groupId,users:[e.username],newMemberType:"member",authentication:s.authentication}).then((()=>t)).catch((()=>t))):(a=Promise.resolve({notAdded:[]}),u=t=>Promise.resolve(t));else{const t=n?"admins":"users";a=st({id:s.groupId,[t]:[e.username],authentication:s.authentication}).then((t=>{if(t.errors&&t.errors.length)throw t.errors[0];return t})).catch((()=>({notAdded:[e.username]}))),u=t=>at({id:s.groupId,users:[e.username],authentication:s.authentication}).then((()=>t))}return{promise:a.then((t=>{if(t.notAdded.length)throw new Error(r);return t})),revert:u}}function _t(t){return Dt(t).then((async n=>{if(!n)return Promise.resolve({itemId:t.id,shortcut:!0,notUnsharedFrom:[]});const{owner:r}=t,o=await t.authentication.getUsername();return Promise.all([_(t),Tt({username:o,authentication:t.authentication})]).then((([n,i])=>{const a=(r||o)===o,u="org_admin"===i.role&&!i.roleId;if(!a&&!u&&["admin","owner"].indexOf(n)<0)throw Error(`This item can not be unshared from group ${t.groupId} by ${o} as they not the item owner, an org admin, group admin or group owner.`);return async function(t){const n=await t.authentication.getUsername(),r=t.owner||n;let o=`${s(t)}/content/items/${t.id}/unshare`;r===n&&(o=`${s(t)}/content/users/${r}/items/${t.id}/unshare`);return t.params={groups:t.groupId},e(o,t)}(t)})).then((e=>{if(e.notUnsharedFrom.length)throw Error(`Item ${t.id} could not be unshared to group ${t.groupId}`);return e}))}))}function Jt(t,n,r){const s=`${r.portal}/portals/self/isServiceNameAvailable`;return e(s,{params:{name:t,type:n},httpMethod:"GET",authentication:r})}function Vt(t,e,n,r){let s=t;return r&&(s=`${t}_${r}`),Jt(s,e,n).then((o=>o.available?s:Vt(t,e,n,r+=1)))}function Bt(t){return Ht(null,t)}function Ht(t,n){const r=t||"self",o=`${s(n)}/portals/${r}`,i=Object.assign({httpMethod:"GET"},n);return e(o,i)}function Kt(t,n){const r=t||"self",o=`${s(n)}/portals/${r}/settings`,i=Object.assign({httpMethod:"GET"},n);return e(o,i)}export{Q as SearchQueryBuilder,Gt as acceptInvitation,st as addGroupUsers,d as addItemData,tt as addItemPart,p as addItemRelationship,l as addItemResource,a as bboxToString,nt as cancelItemUpload,et as commitItemUpload,f as createFolder,mt as createGroup,ht as createGroupNotification,b as createItem,$ as createItemInFolder,jt as createOrgNotification,Mt as declineInvitation,o as determineOwner,It as determineUsername,Wt as ensureMembership,y as exportItem,N as getGroup,R as getGroupCategorySchema,k as getGroupContent,F as getGroupUsers,O as getItem,I as getItemBaseUrl,T as getItemData,q as getItemGroups,U as getItemInfo,S as getItemMetadata,M as getItemParts,E as getItemResource,x as getItemResources,G as getItemStatus,Ht as getPortal,Kt as getPortalSettings,s as getPortalUrl,v as getRelatedItems,Bt as getSelf,Y as getSharingUrl,Vt as getUniqueServiceName,Tt as getUser,g as getUserContent,qt as getUserInvitation,Et as getUserInvitations,_ as getUserMembership,Ut as getUserNotifications,Nt as getUserProperties,vt as getUserTags,xt as getUserUrl,ut as inviteGroupUsers,i as isBBox,z as isItemOwner,Dt as isItemSharedWithGroup,W as isOrgAdmin,Jt as isServiceNameAvailable,yt as joinGroup,wt as leaveGroup,h as moveItem,dt as protectGroup,A as protectItem,J as reassignItem,K as removeFolder,lt as removeGroup,at as removeGroupUsers,V as removeItem,B as removeItemRelationship,H as removeItemResource,L as removeItemThumbnail,St as removeNotification,j as scrubControlChars,At as searchCommunityUsers,ft as searchGroupContent,D as searchGroupUsers,gt as searchGroups,Z as searchItems,Pt as searchUsers,kt as setItemAccess,Rt as setUserProperties,Yt as shareItemWithGroup,pt as unprotectGroup,C as unprotectItem,_t as unshareItemWithGroup,$t as updateGroup,u as updateItem,c as updateItemInfo,m as updateItemResource,Ct as updateUser,bt as updateUserMemberships};
//# sourceMappingURL=portal.esm.min.js.map