@esri/arcgis-rest-portal
Advanced tools
Comparing version 4.0.3 to 4.0.4
/* @preserve | ||
* @esri/arcgis-rest-portal - v4.0.2 - Apache-2.0 | ||
* @esri/arcgis-rest-portal - v4.0.3 - Apache-2.0 | ||
* Copyright (c) 2017-2022 Esri, Inc. | ||
* Wed May 11 2022 17:55:15 GMT+0000 (Coordinated Universal Time) | ||
* Mon Aug 22 2022 19:56:33 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 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),e(r,t)}))}function a(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 u(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 c(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 m(t){const e=Object.assign({item:{id:t.id,text:t.text,file:t.file}},t);return delete e.id,delete e.data,i(e)}function h(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 d(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 p=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 l(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 g(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 i=`${o}/addItem`;t.folderId&&(i=`${o}/${t.folderId}/addItem`),t.params=Object.assign(Object.assign({},t.params),t.item);const a=n(t,["owner","folderId","file","dataUrl","text","async","multipart","filename","overwrite"],{params:Object.assign({},t.params)});return e(i,a)}))}function f(t){return g(Object.assign({folderId:null},t))}const $=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}})))},b=/[\x00-\x1F\x7F-\x9F\xA0]/g;function y(t){return t.replace(b,"")}function j(t,n){const r=O(t,n),s=Object.assign({httpMethod:"GET"},n);return e(r,s)}const O=(t,e)=>`${"string"==typeof e?e:s(e)}/content/items/${t}`;function I(t,n){const r=`${O(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 w(t){const n=`${O(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 T(t,n){const r=`${O(t,n)}/resources`,s=Object.assign({},n);return s.params=Object.assign({num:1e3},s.params),e(r,s)}function v(t,e){const n=e.readAs||"blob";return C(t,`/resources/${e.fileName}`,n,e)}function q(t,n){const r=`${O(t,n)}/groups`;return e(r,n)}function E(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 G(t){return o(t).then((n=>{const r=`${s(t)}/content/users/${n}/items/${t.id}/parts`;return e(r,t)}))}function x(t,e){const{fileName:n="iteminfo.xml",readAs:r="text"}=e||{};return C(t,`/info/${n}`,r,Object.assign({httpMethod:"GET"},e))}function M(t,e){return x(t,Object.assign(Object.assign({},e),{fileName:"metadata/metadata.xml"}))}function C(t,n,r,s){const o=`${O(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(y(t))))))}function S(t){return o(t).then((n=>{const r=`${s(t)}/content/users/${n}/items/${t.id}/protect`;return e(r,t)}))}function P(t){return o(t).then((n=>{const r=`${s(t)}/content/users/${n}/items/${t.id}/unprotect`;return e(r,t)}))}function U(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 N(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 A(t,n){const r=`${s(n)}/community/groups/${t}/users`,o=Object.assign({httpMethod:"GET"},n);return e(r,o)}function k(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 F(t){const e=t.authentication.username,n=t.owner||e;return`${s(t)}/content/users/${encodeURIComponent(n)}/items/${t.id}/share`}function D(t){const e=t.authentication.username;return(t.owner||e)===e}function Y(t){return t.authentication.getUser(t).then((t=>t&&"org_admin"===t.role&&!t.roleId))}function W(t){return U(t.groupId,t).then((t=>t.userMembership.memberType)).catch((()=>"none"))}function _(t){return Y(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 z(t){return o(t).then((n=>{const r=`${s(t)}/content/users/${n}/items/${t.id}/delete`;return e(r,t)}))}function J(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 B(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 H(t){return o(t).then((n=>{const r=`${s(t)}/content/users/${encodeURIComponent(n)}/${t.folderId}/delete`;return e(r,t)}))}class K{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 K(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 L(t,r){let o,i;switch(o="string"==typeof t||t instanceof K?{httpMethod:"GET",params:{q:t}}:n(t,["q","num","start","sortField","sortOrder","searchUserAccess","searchUserName"],{httpMethod:"GET"}),r){case"item":i="/search";break;case"group":i="/community/groups";break;case"groupContent":if("string"==typeof t||t instanceof K||!t.groupId)return Promise.reject(new Error("you must pass a `groupId` option to `searchGroupContent`"));i=`/content/groups/${t.groupId}/search`;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 K?n={q:t,start:e.nextStart}:(n=t,n.start=e.nextStart),L(n,r)}),e)))}function Q(t){return L(t,"item")}function V(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 X(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 Z(t){return o(t).then((n=>{const r=`${s(t)}/content/users/${n}/items/${t.id}/cancel`;return e(r,t)}))}function tt(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 et(t){const n=t.id,r=`${s(t)}/community/groups/${n}/addUsers`,o=Object.assign({},t,{admins:void 0,users:void 0}),i=[...nt("users",t.users,o),...nt("admins",t.admins,o)].map((t=>function(t,n){return e(t,n).catch((t=>({errors:[t]})))}(r,t)));return Promise.all(i).then(rt)}function nt(t,e,n){if(!e||e.length<1)return[];return tt(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 rt(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 st(t){const{id:n,users:r}=t,o=`${s(t)}/community/groups/${n}/removeUsers`,i=tt(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 ot(t){const n=t.id,r=`${s(t)}/community/groups/${n}/invite`,o=function(t){return tt(t.users,25).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).map((t=>function(t,n){return e(t,n).catch((t=>({errors:[t]})))}(r,t)));return Promise.all(o).then(it)}function it(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 at(t){const n=`${s(t)}/community/createGroup`;return t.params=Object.assign(Object.assign({},t.params),t.group),e(n,t)}function ut(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 ct(t){const n=`${s(t)}/community/groups/${t.id}/protect`;return e(n,t)}function mt(t){const n=`${s(t)}/community/groups/${t.id}/unprotect`;return e(n,t)}function ht(t){const n=`${s(t)}/community/groups/${t.id}/delete`,r=Object.assign({},t);return e(n,r)}function dt(t){return L(t,"group")}function pt(t){return L(t,"groupContent")}function lt(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 gt(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 ft(t){const n=`${s(t)}/community/groups/${t.id}/join`;return e(n,t)}function $t(t){const n=`${s(t)}/community/groups/${t.id}/leave`;return e(n,t)}function bt(t){const n=`${s(t)}/portals/self/createNotification`,r=function(t){return tt(t.users,t.batchSize||25).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).map((t=>function(t,n){return e(t,n).catch((t=>({errors:[t]})))}(n,t)));return Promise.all(r).then(yt)}function yt(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 jt(t){let n,r={httpMethod:"GET"};if("string"==typeof t)n=`https://www.arcgis.com/sharing/rest/community/users/${t}`;else{const e=t.username||t.authentication.username;n=`${s(t)}/community/users/${encodeURIComponent(e)}`,r=Object.assign(Object.assign({},t),r)}return e(n,r)}function Ot(t){const n=t.username||t.authentication.username,r=`${s(t)}/community/users/${encodeURIComponent(n)}/tags`;return e(r,t)}function It(t){return`${s(t)}/community/users/${encodeURIComponent(t.username)}`}function wt(t){let n={httpMethod:"GET"};const r=encodeURIComponent(t.authentication.username),o=`${s(t)}/community/users/${r}/invitations`;return n=Object.assign(Object.assign({},t),n),e(o,n)}function Tt(t){const n=encodeURIComponent(t.authentication.username),r=`${s(t)}/community/users/${n}/invitations/${t.invitationId}`;let o={httpMethod:"GET"};return o=Object.assign(Object.assign({},t),o),e(r,o)}function vt(t){const n=encodeURIComponent(t.authentication.username),r=`${s(t)}/community/users/${n}/invitations/${t.invitationId}/accept`,o=Object.assign({},t);return e(r,o)}function qt(t){const n=encodeURIComponent(t.authentication.username),r=`${s(t)}/community/users/${n}/invitations/${t.invitationId}/decline`,o=Object.assign({},t);return e(r,o)}function Et(t){let n={httpMethod:"GET"};const r=encodeURIComponent(t.authentication.username),o=`${s(t)}/community/users/${r}/notifications`;return n=Object.assign(Object.assign({},t),n),e(o,n)}function Gt(t){const n=encodeURIComponent(t.authentication.username),r=`${s(t)}/community/users/${n}/notifications/${t.id}/delete`;return e(r,t)}function xt(t){return L(t,"user")}function Mt(t){const n=t.user.username||t.authentication.username,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)}function Ct(t){const e=F(t);return D(t)?St(e,t):Y(t).then((n=>{if(n)return St(e,t);throw Error(`This item can not be shared by ${t.authentication.username}. They are neither the item owner nor an organization admin.`)}))}function St(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 Pt(t){return Q({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}))}function Ut(t){return Pt(t).then((e=>{if(e)return{itemId:t.id,shortcut:!0,notSharedWith:[]};const{authentication:{username:n},owner:r,confirmItemControl:s}=t,o=r||n;if(o!==n){let e=!1;return Promise.all([jt({username:n,authentication:t.authentication}),jt({username:o,authentication:t.authentication}),W(t)]).then((([n,r,o])=>{const i=!!s;return e="org_admin"===n.role&&!n.roleId,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(Nt(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),Nt(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(Nt(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}(n,i,o,e,r,t)})).then((n=>{const[{revert:r}={promise:Promise.resolve({notAdded:[]}),revert:t=>Promise.resolve(t)}]=n;return Promise.all(n.map((({promise:t})=>t))).then((()=>Rt(t,e))).then((t=>r(t)))}))}return Rt(t)})).then((e=>{if(e.notSharedWith.length)throw Error(`Item ${t.id} could not be shared to group ${t.groupId}.`);return e}))}function Rt(t,n=!1){const r=t.authentication.username,o=t.owner||r;let i=`${s(t)}/content/items/${t.id}/share`;return(o===r||n)&&(i=`${s(t)}/content/users/${o}/items/${t.id}/share`),t.params={groups:t.groupId,confirmItemControl:t.confirmItemControl},e(i,t)}function Nt(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=gt({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=>gt({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=et({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=>st({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 At(t){return Pt(t).then((n=>{if(!n)return Promise.resolve({itemId:t.id,shortcut:!0,notUnsharedFrom:[]});const{authentication:{username:r},owner:o}=t;return Promise.all([W(t),jt({username:r,authentication:t.authentication})]).then((([n,i])=>{const a=(o||r)===r,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 ${r} as they not the item owner, an org admin, group admin or group owner.`);return function(t){const n=t.authentication.username,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 kt(t,n,r){const s=`${r.portal}/portals/self/isServiceNameAvailable`;return e(s,{params:{name:t,type:n},httpMethod:"GET",authentication:r})}function Ft(t,e,n,r){let s=t;return r&&(s=`${t}_${r}`),kt(s,e,n).then((o=>o.available?s:Ft(t,e,n,r+=1)))}function Dt(t){return Yt(null,t)}function Yt(t,n){const r=t||"self",o=`${s(n)}/portals/${r}`,i=Object.assign({httpMethod:"GET"},n);return e(o,i)}function Wt(t,n){const r=t||"self",o=`${s(n)}/portals/${r}/settings`,i=Object.assign({httpMethod:"GET"},n);return e(o,i)}export{K as SearchQueryBuilder,vt as acceptInvitation,et as addGroupUsers,m as addItemData,V as addItemPart,h as addItemRelationship,d as addItemResource,Z as cancelItemUpload,X as commitItemUpload,l as createFolder,at as createGroup,ut as createGroupNotification,f as createItem,g as createItemInFolder,bt as createOrgNotification,qt as declineInvitation,o as determineOwner,Nt as ensureMembership,$ as exportItem,U as getGroup,R as getGroupCategorySchema,N as getGroupContent,A as getGroupUsers,j as getItem,O as getItemBaseUrl,I as getItemData,q as getItemGroups,x as getItemInfo,M as getItemMetadata,G as getItemParts,v as getItemResource,T as getItemResources,E as getItemStatus,Yt as getPortal,Wt as getPortalSettings,s as getPortalUrl,w as getRelatedItems,Dt as getSelf,F as getSharingUrl,Ft as getUniqueServiceName,jt as getUser,p as getUserContent,Tt as getUserInvitation,wt as getUserInvitations,W as getUserMembership,Et as getUserNotifications,Ot as getUserTags,It as getUserUrl,ot as inviteGroupUsers,D as isItemOwner,Pt as isItemSharedWithGroup,Y as isOrgAdmin,kt as isServiceNameAvailable,ft as joinGroup,$t as leaveGroup,c as moveItem,ct as protectGroup,S as protectItem,_ as reassignItem,H as removeFolder,ht as removeGroup,st as removeGroupUsers,z as removeItem,J as removeItemRelationship,B as removeItemResource,Gt as removeNotification,y as scrubControlChars,pt as searchGroupContent,k as searchGroupUsers,dt as searchGroups,Q as searchItems,xt as searchUsers,Ct as setItemAccess,Ut as shareItemWithGroup,mt as unprotectGroup,P as unprotectItem,At as unshareItemWithGroup,lt as updateGroup,i as updateItem,a as updateItemInfo,u as updateItemResource,Mt as updateUser,gt as updateUserMemberships}; | ||
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 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),e(r,t)}))}function a(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 u(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 c(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 m(t){const e=Object.assign({item:{id:t.id,text:t.text,file:t.file}},t);return delete e.id,delete e.data,i(e)}function h(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 d(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 p=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 l(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 g(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 i=`${o}/addItem`;t.folderId&&(i=`${o}/${t.folderId}/addItem`),t.params=Object.assign(Object.assign({},t.params),t.item);const a=n(t,["owner","folderId","file","dataUrl","text","async","multipart","filename","overwrite"],{params:Object.assign({},t.params)});return e(i,a)}))}function f(t){return g(Object.assign({folderId:null},t))}const $=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}})))},b=/[\x00-\x1F\x7F-\x9F\xA0]/g;function y(t){return t.replace(b,"")}function j(t,n){const r=O(t,n),s=Object.assign({httpMethod:"GET"},n);return e(r,s)}const O=(t,e)=>`${"string"==typeof e?e:s(e)}/content/items/${t}`;function I(t,n){const r=`${O(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 w(t){const n=`${O(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 T(t,n){const r=`${O(t,n)}/resources`,s=Object.assign({},n);return s.params=Object.assign({num:1e3},s.params),e(r,s)}function v(t,e){const n=e.readAs||"blob";return C(t,`/resources/${e.fileName}`,n,e)}function q(t,n){const r=`${O(t,n)}/groups`;return e(r,n)}function E(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 G(t){return o(t).then((n=>{const r=`${s(t)}/content/users/${n}/items/${t.id}/parts`;return e(r,t)}))}function x(t,e){const{fileName:n="iteminfo.xml",readAs:r="text"}=e||{};return C(t,`/info/${n}`,r,Object.assign({httpMethod:"GET"},e))}function M(t,e){return x(t,Object.assign(Object.assign({},e),{fileName:"metadata/metadata.xml"}))}function C(t,n,r,s){const o=`${O(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(y(t))))))}function S(t){return o(t).then((n=>{const r=`${s(t)}/content/users/${n}/items/${t.id}/protect`;return e(r,t)}))}function P(t){return o(t).then((n=>{const r=`${s(t)}/content/users/${n}/items/${t.id}/unprotect`;return e(r,t)}))}function U(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 N(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 A(t,n){const r=`${s(n)}/community/groups/${t}/users`,o=Object.assign({httpMethod:"GET"},n);return e(r,o)}function k(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 F(t){const e=t.authentication.username,n=t.owner||e;return`${s(t)}/content/users/${encodeURIComponent(n)}/items/${t.id}/share`}function D(t){const e=t.authentication.username;return(t.owner||e)===e}function Y(t){return t.authentication.getUser(t).then((t=>t&&"org_admin"===t.role&&!t.roleId))}function W(t){return U(t.groupId,t).then((t=>t.userMembership.memberType)).catch((()=>"none"))}function _(t){return Y(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 z(t){return o(t).then((n=>{const r=`${s(t)}/content/users/${n}/items/${t.id}/delete`;return e(r,t)}))}function J(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 B(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 H(t){return o(t).then((n=>{const r=`${s(t)}/content/users/${encodeURIComponent(n)}/${t.folderId}/delete`;return e(r,t)}))}class K{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 K(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 L(t,r){let o,i;switch(o="string"==typeof t||t instanceof K?{httpMethod:"GET",params:{q:t}}:n(t,["q","num","start","sortField","sortOrder","searchUserAccess","searchUserName"],{httpMethod:"GET"}),r){case"item":i="/search";break;case"group":i="/community/groups";break;case"groupContent":if("string"==typeof t||t instanceof K||!t.groupId)return Promise.reject(new Error("you must pass a `groupId` option to `searchGroupContent`"));i=`/content/groups/${t.groupId}/search`;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 K?n={q:t,start:e.nextStart}:(n=t,n.start=e.nextStart),L(n,r)}),e)))}function Q(t){return L(t,"item")}function V(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 X(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 Z(t){return o(t).then((n=>{const r=`${s(t)}/content/users/${n}/items/${t.id}/cancel`;return e(r,t)}))}function tt(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 et(t){const n=t.id,r=`${s(t)}/community/groups/${n}/addUsers`,o=Object.assign({},t,{admins:void 0,users:void 0}),i=[...nt("users",t.users,o),...nt("admins",t.admins,o)].map((t=>function(t,n){return e(t,n).catch((t=>({errors:[t]})))}(r,t)));return Promise.all(i).then(rt)}function nt(t,e,n){if(!e||e.length<1)return[];return tt(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 rt(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 st(t){const{id:n,users:r}=t,o=`${s(t)}/community/groups/${n}/removeUsers`,i=tt(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 ot(t){const n=t.id,r=`${s(t)}/community/groups/${n}/invite`,o=function(t){return tt(t.users,25).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).map((t=>function(t,n){return e(t,n).catch((t=>({errors:[t]})))}(r,t)));return Promise.all(o).then(it)}function it(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 at(t){const n=`${s(t)}/community/createGroup`;return t.params=Object.assign(Object.assign({},t.params),t.group),e(n,t)}function ut(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 ct(t){const n=`${s(t)}/community/groups/${t.id}/protect`;return e(n,t)}function mt(t){const n=`${s(t)}/community/groups/${t.id}/unprotect`;return e(n,t)}function ht(t){const n=`${s(t)}/community/groups/${t.id}/delete`,r=Object.assign({},t);return e(n,r)}function dt(t){return L(t,"group")}function pt(t){return L(t,"groupContent")}function lt(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 gt(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 ft(t){const n=`${s(t)}/community/groups/${t.id}/join`;return e(n,t)}function $t(t){const n=`${s(t)}/community/groups/${t.id}/leave`;return e(n,t)}function bt(t){const n=`${s(t)}/portals/self/createNotification`,r=function(t){return tt(t.users,t.batchSize||25).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).map((t=>function(t,n){return e(t,n).catch((t=>({errors:[t]})))}(n,t)));return Promise.all(r).then(yt)}function yt(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 jt(t){let n,r={httpMethod:"GET"};if("string"==typeof t)n=`https://www.arcgis.com/sharing/rest/community/users/${t}`;else{const e=t.username||t.authentication.username;n=`${s(t)}/community/users/${encodeURIComponent(e)}`,r=Object.assign(Object.assign({},t),r)}return e(n,r)}function Ot(t){const n=t.username||t.authentication.username,r=`${s(t)}/community/users/${encodeURIComponent(n)}/tags`;return e(r,t)}function It(t){return`${s(t)}/community/users/${encodeURIComponent(t.username)}`}function wt(t){let n={httpMethod:"GET"};const r=encodeURIComponent(t.authentication.username),o=`${s(t)}/community/users/${r}/invitations`;return n=Object.assign(Object.assign({},t),n),e(o,n)}function Tt(t){const n=encodeURIComponent(t.authentication.username),r=`${s(t)}/community/users/${n}/invitations/${t.invitationId}`;let o={httpMethod:"GET"};return o=Object.assign(Object.assign({},t),o),e(r,o)}function vt(t){const n=encodeURIComponent(t.authentication.username),r=`${s(t)}/community/users/${n}/invitations/${t.invitationId}/accept`,o=Object.assign({},t);return e(r,o)}function qt(t){const n=encodeURIComponent(t.authentication.username),r=`${s(t)}/community/users/${n}/invitations/${t.invitationId}/decline`,o=Object.assign({},t);return e(r,o)}function Et(t){let n={httpMethod:"GET"};const r=encodeURIComponent(t.authentication.username),o=`${s(t)}/community/users/${r}/notifications`;return n=Object.assign(Object.assign({},t),n),e(o,n)}function Gt(t){const n=encodeURIComponent(t.authentication.username),r=`${s(t)}/community/users/${n}/notifications/${t.id}/delete`;return e(r,t)}function xt(t){return L(t,"user")}function Mt(t){const n=t.user.username||t.authentication.username,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)}function Ct(t){const e=F(t);return D(t)?St(e,t):Y(t).then((n=>{if(n)return St(e,t);throw Error(`This item can not be shared by ${t.authentication.username}. They are neither the item owner nor an organization admin.`)}))}function St(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 Pt(t){return Q({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}))}function Ut(t){return Pt(t).then((e=>{if(e)return{itemId:t.id,shortcut:!0,notSharedWith:[]};const{authentication:{username:n},owner:r,confirmItemControl:s}=t,o=r||n;if(o!==n){let e=!1,r=!1;return Promise.all([jt({username:n,authentication:t.authentication}),jt({username:o,authentication:t.authentication}),W(t)]).then((([n,o,i])=>{const a=!!s;return e="org_admin"===n.role&&!n.roleId,r=n.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(Nt(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),Nt(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(Nt(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}(n,a,i,e,o,t)})).then((n=>{const[{revert:s}={promise:Promise.resolve({notAdded:[]}),revert:t=>Promise.resolve(t)}]=n;return Promise.all(n.map((({promise:t})=>t))).then((()=>Rt(t,e,r))).then((t=>s(t)))}))}return Rt(t)})).then((e=>{if(e.notSharedWith.length)throw Error(`Item ${t.id} could not be shared to group ${t.groupId}.`);return e}))}function Rt(t,n=!1,r=!1){const o=t.authentication.username,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 Nt(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=gt({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=>gt({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=et({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=>st({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 At(t){return Pt(t).then((n=>{if(!n)return Promise.resolve({itemId:t.id,shortcut:!0,notUnsharedFrom:[]});const{authentication:{username:r},owner:o}=t;return Promise.all([W(t),jt({username:r,authentication:t.authentication})]).then((([n,i])=>{const a=(o||r)===r,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 ${r} as they not the item owner, an org admin, group admin or group owner.`);return function(t){const n=t.authentication.username,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 kt(t,n,r){const s=`${r.portal}/portals/self/isServiceNameAvailable`;return e(s,{params:{name:t,type:n},httpMethod:"GET",authentication:r})}function Ft(t,e,n,r){let s=t;return r&&(s=`${t}_${r}`),kt(s,e,n).then((o=>o.available?s:Ft(t,e,n,r+=1)))}function Dt(t){return Yt(null,t)}function Yt(t,n){const r=t||"self",o=`${s(n)}/portals/${r}`,i=Object.assign({httpMethod:"GET"},n);return e(o,i)}function Wt(t,n){const r=t||"self",o=`${s(n)}/portals/${r}/settings`,i=Object.assign({httpMethod:"GET"},n);return e(o,i)}export{K as SearchQueryBuilder,vt as acceptInvitation,et as addGroupUsers,m as addItemData,V as addItemPart,h as addItemRelationship,d as addItemResource,Z as cancelItemUpload,X as commitItemUpload,l as createFolder,at as createGroup,ut as createGroupNotification,f as createItem,g as createItemInFolder,bt as createOrgNotification,qt as declineInvitation,o as determineOwner,Nt as ensureMembership,$ as exportItem,U as getGroup,R as getGroupCategorySchema,N as getGroupContent,A as getGroupUsers,j as getItem,O as getItemBaseUrl,I as getItemData,q as getItemGroups,x as getItemInfo,M as getItemMetadata,G as getItemParts,v as getItemResource,T as getItemResources,E as getItemStatus,Yt as getPortal,Wt as getPortalSettings,s as getPortalUrl,w as getRelatedItems,Dt as getSelf,F as getSharingUrl,Ft as getUniqueServiceName,jt as getUser,p as getUserContent,Tt as getUserInvitation,wt as getUserInvitations,W as getUserMembership,Et as getUserNotifications,Ot as getUserTags,It as getUserUrl,ot as inviteGroupUsers,D as isItemOwner,Pt as isItemSharedWithGroup,Y as isOrgAdmin,kt as isServiceNameAvailable,ft as joinGroup,$t as leaveGroup,c as moveItem,ct as protectGroup,S as protectItem,_ as reassignItem,H as removeFolder,ht as removeGroup,st as removeGroupUsers,z as removeItem,J as removeItemRelationship,B as removeItemResource,Gt as removeNotification,y as scrubControlChars,pt as searchGroupContent,k as searchGroupUsers,dt as searchGroups,Q as searchItems,xt as searchUsers,Ct as setItemAccess,Ut as shareItemWithGroup,mt as unprotectGroup,P as unprotectItem,At as unshareItemWithGroup,lt as updateGroup,i as updateItem,a as updateItemInfo,u as updateItemResource,Mt as updateUser,gt as updateUserMemberships}; | ||
//# sourceMappingURL=portal.esm.min.js.map |
/* @preserve | ||
* @esri/arcgis-rest-portal - v4.0.2 - Apache-2.0 | ||
* @esri/arcgis-rest-portal - v4.0.3 - Apache-2.0 | ||
* Copyright (c) 2017-2022 Esri, Inc. | ||
* Wed May 11 2022 17:55:15 GMT+0000 (Coordinated Universal Time) | ||
* Mon Aug 22 2022 19:56:33 GMT+0000 (Coordinated Universal 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,t){"use strict";function r(e={}){return e.portal?t.cleanUrl(e.portal):e.authentication&&"string"!=typeof e.authentication?e.authentication.portal:"https://www.arcgis.com/sharing/rest"}function n(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 s(e){return n(e).then((n=>{const s=e.folderId?`${r(e)}/content/users/${n}/${e.folderId}/items/${e.item.id}/update`:`${r(e)}/content/users/${n}/items/${e.item.id}/update`;return e.params=Object.assign(Object.assign({},e.params),e.item),t.request(s,e)}))}function o(e){return e.multipart&&!e.filename?Promise.reject(new Error("The filename is required for a multipart request.")):n(e).then((n=>{const s=`${r(e)}/content/users/${n}`;let o=`${s}/addItem`;e.folderId&&(o=`${s}/${e.folderId}/addItem`),e.params=Object.assign(Object.assign({},e.params),e.item);const i=t.appendCustomParams(e,["owner","folderId","file","dataUrl","text","async","multipart","filename","overwrite"],{params:Object.assign({},e.params)});return t.request(o,i)}))}const i=/[\x00-\x1F\x7F-\x9F\xA0]/g;function a(e){return e.replace(i,"")}const u=(e,t)=>`${"string"==typeof t?t:r(t)}/content/items/${e}`;function c(e,t){const{fileName:r="iteminfo.xml",readAs:n="text"}=t||{};return m(e,`/info/${r}`,n,Object.assign({httpMethod:"GET"},t))}function m(e,r,n,s){const o=`${u(e,s)}${r}`,i=Object.assign({params:{}},s),c=i.rawResponse;return i.rawResponse=!0,i.params.f=null,t.request(o,i).then((e=>c?e:"json"!==n?e[n]():e.text().then((e=>JSON.parse(a(e))))))}function d(e,n){const s=`${r(n)}/community/groups/${e}`,o=Object.assign({httpMethod:"GET"},n);return t.request(s,o)}function h(e){const t=e.authentication.username,n=e.owner||t;return`${r(e)}/content/users/${encodeURIComponent(n)}/items/${e.id}/share`}function p(e){const t=e.authentication.username;return(e.owner||t)===t}function l(e){return e.authentication.getUser(e).then((e=>e&&"org_admin"===e.role&&!e.roleId))}function g(e){return d(e.groupId,e).then((e=>e.userMembership.memberType)).catch((()=>"none"))}class f{constructor(e=""){this.termStack=[],this.rangeStack=[],this.openGroups=0,this.q=e}match(...e){return this.termStack=this.termStack.concat(e),this}in(e){const r=`\`in(${e?`"${e}"`:""})\``;return this.hasRange||this.hasTerms?(e&&"*"!==e&&(this.q+=`${e}:`),this.commit()):(t.warn(`${r} 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?(t.warn("`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(e){return this.hasTerms?(t.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):(this.rangeStack[0]=e,this)}to(e){return this.hasTerms?(t.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):(this.rangeStack[1]=e,this)}boost(e){return this.commit(),this.q+=`^${e}`,this}toParam(){return this.commit(),this.cleanup(),this.q}clone(){return this.commit(),this.cleanup(),new f(this.q+"")}addModifier(e){return this.currentModifer?(t.warn(`You have called \`${this.currentModifer}()\` after \`${e}()\`. Your current query was not modified.`),this):(this.commit(),""===this.q&&"not"!==e?(t.warn(`You have called \`${e}()\` without calling another method to modify your query first. Try calling \`match()\` first.`),this):(this.currentModifer=e,this.q+=""===this.q?"":" ",this.q+=`${e.toUpperCase()} `,this))}hasWhiteSpace(e){return/\s/g.test(e)}formatTerm(e){return e instanceof Date?e.getTime():"string"==typeof e&&this.hasWhiteSpace(e)?`"${e}"`:e}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((e=>this.formatTerm(e))).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(t.warn(`Automatically closing ${this.openGroups} group(s). You can use \`endGroup(...)\` to remove this warning.`);this.openGroups>0;)this.q+=")",this.openGroups--;const e=this.q;this.q=e.replace(/( AND ?| NOT ?| OR ?)*$/,""),e!==this.q&&t.warn("`startGroup(...)` was called without calling `endGroup(...)` first. Your query was not modified."),this.q=this.q.replace(/(\(\))*/,"")}}function $(e,n){let s,o;switch(s="string"==typeof e||e instanceof f?{httpMethod:"GET",params:{q:e}}:t.appendCustomParams(e,["q","num","start","sortField","sortOrder","searchUserAccess","searchUserName"],{httpMethod:"GET"}),n){case"item":o="/search";break;case"group":o="/community/groups";break;case"groupContent":if("string"==typeof e||e instanceof f||!e.groupId)return Promise.reject(new Error("you must pass a `groupId` option to `searchGroupContent`"));o=`/content/groups/${e.groupId}/search`;break;default:o="/portals/self/users/search"}const i=r(s)+o;return t.request(i,s).then((t=>(t.nextStart&&-1!==t.nextStart&&(t.nextPage=function(){let r;return"string"==typeof e||e instanceof f?r={q:e,start:t.nextStart}:(r=e,r.start=t.nextStart),$(r,n)}),t)))}function b(e){return $(e,"item")}function I(e,t){if(0===e.length)return[];const r=[];for(let n=0;n<e.length;n+=t)r.push(e.slice(n,n+t));return r}function y(e){const n=e.id,s=`${r(e)}/community/groups/${n}/addUsers`,o=Object.assign({},e,{admins:void 0,users:void 0}),i=[...q("users",e.users,o),...q("admins",e.admins,o)].map((e=>function(e,r){return t.request(e,r).catch((e=>({errors:[e]})))}(s,e)));return Promise.all(i).then(j)}function q(e,t,r){if(!t||t.length<1)return[];return I(t,25).map((t=>function(e,t,r){return Object.assign({},r,{[e]:t,params:Object.assign(Object.assign({},r.params),{[e]:t})})}(e,t,r)))}function j(e){const t=e.filter((e=>e.notAdded)).reduce(((e,t)=>e.concat(t.notAdded)),[]),r=e.filter((e=>e.errors)).reduce(((e,t)=>e.concat(t.errors)),[]),n={notAdded:t};return r.length>0&&(n.errors=r),n}function O(e){const{id:n,users:s}=e,o=`${r(e)}/community/groups/${n}/removeUsers`,i=I(s,25).map((r=>(r=>{const n=Object.assign(Object.assign({},e),{users:r,params:{users:r}});return t.request(o,n).catch((e=>({errors:[e]})))})(r)));return Promise.all(i).then((e=>{const t=t=>e.filter((e=>e[t])).reduce(((e,r)=>e.concat(r[t])),[]),r=t("errors"),n={notRemoved:t("notRemoved")};return r.length?Object.assign(Object.assign({},n),{errors:r}):n}))}function w(e){const t=e.every((e=>e.success)),r=e.reduce(((e,t)=>e.concat(t.errors||[])),[]),n={success:t};return r.length>0&&(n.errors=r),n}function v(e){const n=`${r(e)}/community/groups/${e.id}/updateUsers`,s={authentication:e.authentication,params:{}};return"admin"===e.newMemberType?s.params.admins=e.users:s.params.users=e.users,t.request(n,s)}function T(e){const t=e.every((e=>e.success)),r=e.reduce(((e,t)=>e.concat(t.errors||[])),[]),n={success:t};return r.length>0&&(n.errors=r),n}function G(e){let n,s={httpMethod:"GET"};if("string"==typeof e)n=`https://www.arcgis.com/sharing/rest/community/users/${e}`;else{const t=e.username||e.authentication.username;n=`${r(e)}/community/users/${encodeURIComponent(t)}`,s=Object.assign(Object.assign({},e),s)}return t.request(n,s)}function U(e,r){return r.params=Object.assign({org:!1,everyone:!1},r.params),"private"===r.access&&(r.params.groups=" "),"org"===r.access&&(r.params.org=!0),"public"===r.access&&(r.params.account=!0,r.params.everyone=!0),t.request(e,r)}function C(e){return b({q:`id: ${e.id} AND group: ${e.groupId}`,start:1,num:10,sortField:"title",authentication:e.authentication,httpMethod:"POST"}).then((t=>{let r=!1;if(t.total>0)return r=t.results.some((t=>t.id===e.id)),r}))}function P(e,n=!1){const s=e.authentication.username,o=e.owner||s;let i=`${r(e)}/content/items/${e.id}/share`;return(o===s||n)&&(i=`${r(e)}/content/users/${o}/items/${e.id}/share`),e.params={groups:e.groupId,confirmItemControl:e.confirmItemControl},t.request(i,e)}function M(e,t,r,n,s){const o=t.groups||[],i=o.find((e=>e.id===s.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 ${s.groupId} nor can item ${s.id} be shared to the group.`);if(!i&&o.length>511)throw Error(`User ${t.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)r&&"member"===i.userMembership.memberType?(a=v({id:s.groupId,users:[t.username],newMemberType:"admin",authentication:s.authentication}).then((e=>{const t=e.results.reduce(((e,t)=>(t.success||e.push(t.username),e)),[]);return Promise.resolve({notAdded:t})})).catch((()=>({notAdded:[t.username]}))),u=e=>v({id:s.groupId,users:[t.username],newMemberType:"member",authentication:s.authentication}).then((()=>e)).catch((()=>e))):(a=Promise.resolve({notAdded:[]}),u=e=>Promise.resolve(e));else{const e=r?"admins":"users";a=y({id:s.groupId,[e]:[t.username],authentication:s.authentication}).then((e=>{if(e.errors&&e.errors.length)throw e.errors[0];return e})).catch((()=>({notAdded:[t.username]}))),u=e=>O({id:s.groupId,users:[t.username],authentication:s.authentication}).then((()=>e))}return{promise:a.then((e=>{if(e.notAdded.length)throw new Error(n);return e})),revert:u}}function S(e,r,n){const s=`${n.portal}/portals/self/isServiceNameAvailable`;return t.request(s,{params:{name:e,type:r},httpMethod:"GET",authentication:n})}function x(e,n){const s=e||"self",o=`${r(n)}/portals/${s}`,i=Object.assign({httpMethod:"GET"},n);return t.request(o,i)}e.SearchQueryBuilder=f,e.acceptInvitation=function(e){const n=encodeURIComponent(e.authentication.username),s=`${r(e)}/community/users/${n}/invitations/${e.invitationId}/accept`,o=Object.assign({},e);return t.request(s,o)},e.addGroupUsers=y,e.addItemData=function(e){const t=Object.assign({item:{id:e.id,text:e.text,file:e.file}},e);return delete t.id,delete t.data,s(t)},e.addItemPart=function(e){const s=e.partNum;return!Number.isInteger(s)||s<1||s>1e4?Promise.reject(new Error("The part number must be an integer between 1 to 10000, inclusive.")):n(e).then((n=>{const o=`${r(e)}/content/users/${n}/items/${e.id}/addPart?partNum=${s}`,i=t.appendCustomParams(e,["file"],{params:Object.assign({},e.params)});return t.request(o,i)}))},e.addItemRelationship=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${n}/addRelationship`,o=t.appendCustomParams(e,["originItemId","destinationItemId","relationshipType"],{params:Object.assign({},e.params)});return t.request(s,o)}))},e.addItemResource=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${n}/items/${e.id}/addResources`;return e.params=Object.assign({file:e.resource,fileName:e.name,resourcesPrefix:e.prefix,text:e.content,access:e.private?"private":"inherit"},e.params),t.request(s,e)}))},e.cancelItemUpload=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${n}/items/${e.id}/cancel`;return t.request(s,e)}))},e.commitItemUpload=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${n}/items/${e.id}/commit`,o=t.appendCustomParams(e,[],{params:Object.assign(Object.assign({},e.params),e.item)});return t.request(s,o)}))},e.createFolder=function(e){return n(e).then((n=>{const s=`${`${r(e)}/content/users/${n}`}/createFolder`;return e.params=Object.assign({title:e.title},e.params),t.request(s,e)}))},e.createGroup=function(e){const n=`${r(e)}/community/createGroup`;return e.params=Object.assign(Object.assign({},e.params),e.group),t.request(n,e)},e.createGroupNotification=function(e){const n=`${r(e)}/community/groups/${e.id}/createNotification`,s=Object.assign({params:Object.assign({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 t.request(n,s)},e.createItem=function(e){return o(Object.assign({folderId:null},e))},e.createItemInFolder=o,e.createOrgNotification=function(e){const n=`${r(e)}/portals/self/createNotification`,s=function(e){return I(e.users,e.batchSize||25).map((t=>function(e,t){const r=Object.assign({},t);return r.params=Object.assign(Object.assign({},r.params),{users:e,subject:t.subject,message:t.message,notificationChannelType:r.notificationChannelType}),r}(t,e)))}(e).map((e=>function(e,r){return t.request(e,r).catch((e=>({errors:[e]})))}(n,e)));return Promise.all(s).then(T)},e.declineInvitation=function(e){const n=encodeURIComponent(e.authentication.username),s=`${r(e)}/community/users/${n}/invitations/${e.invitationId}/decline`,o=Object.assign({},e);return t.request(s,o)},e.determineOwner=n,e.ensureMembership=M,e.exportItem=e=>{const{authentication:s,id:o,title:i,exportFormat:a,exportParameters:u}=e;return n(e).then((t=>`${r(e)}/content/users/${t}/export`)).then((e=>t.request(e,{httpMethod:"POST",authentication:s,params:{itemId:o,title:i,exportFormat:a,exportParameters:u}})))},e.getGroup=d,e.getGroupCategorySchema=function(e,n){const s=`${r(n)}/community/groups/${e}/categorySchema`,o=Object.assign({httpMethod:"GET"},n);return t.request(s,o)},e.getGroupContent=function(e,n){const s=`${r(n)}/content/groups/${e}`,o=Object.assign(Object.assign({httpMethod:"GET"},{params:{start:1,num:100}}),n);return n&&n.paging&&(o.params=Object.assign({},n.paging)),t.request(s,o)},e.getGroupUsers=function(e,n){const s=`${r(n)}/community/groups/${e}/users`,o=Object.assign({httpMethod:"GET"},n);return t.request(s,o)},e.getItem=function(e,r){const n=u(e,r),s=Object.assign({httpMethod:"GET"},r);return t.request(n,s)},e.getItemBaseUrl=u,e.getItemData=function(e,r){const n=`${u(e,r)}/data`,s=Object.assign({httpMethod:"GET",params:{}},r);return s.file&&(s.params.f=null),t.request(n,s).catch((e=>{if(!RegExp(/The string did not match the expected pattern|(Unexpected end of (JSON input|data at line 1 column 1))/i).test(e.message))throw e}))},e.getItemGroups=function(e,r){const n=`${u(e,r)}/groups`;return t.request(n,r)},e.getItemInfo=c,e.getItemMetadata=function(e,t){return c(e,Object.assign(Object.assign({},t),{fileName:"metadata/metadata.xml"}))},e.getItemParts=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${n}/items/${e.id}/parts`;return t.request(s,e)}))},e.getItemResource=function(e,t){const r=t.readAs||"blob";return m(e,`/resources/${t.fileName}`,r,t)},e.getItemResources=function(e,r){const n=`${u(e,r)}/resources`,s=Object.assign({},r);return s.params=Object.assign({num:1e3},s.params),t.request(n,s)},e.getItemStatus=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${n}/items/${e.id}/status`,o=t.appendCustomParams(e,["jobId","jobType"],{params:Object.assign({},e.params)});return t.request(s,o)}))},e.getPortal=x,e.getPortalSettings=function(e,n){const s=e||"self",o=`${r(n)}/portals/${s}/settings`,i=Object.assign({httpMethod:"GET"},n);return t.request(o,i)},e.getPortalUrl=r,e.getRelatedItems=function(e){const r=`${u(e.id,e)}/relatedItems`,n=Object.assign({httpMethod:"GET",params:{direction:e.direction}},e);return"string"==typeof e.relationshipType?n.params.relationshipType=e.relationshipType:n.params.relationshipTypes=e.relationshipType,delete n.direction,delete n.relationshipType,t.request(r,n)},e.getSelf=function(e){return x(null,e)},e.getSharingUrl=h,e.getUniqueServiceName=function e(t,r,n,s){let o=t;return s&&(o=`${t}_${s}`),S(o,r,n).then((i=>i.available?o:e(t,r,n,s+=1)))},e.getUser=G,e.getUserContent=e=>{const{folderId:s,start:o=1,num:i=10,authentication:a}=e,u=s?`/${s}`:"";return n(e).then((t=>`${r(e)}/content/users/${t}${u}`)).then((e=>t.request(e,{httpMethod:"GET",authentication:a,params:{start:o,num:i}})))},e.getUserInvitation=function(e){const n=encodeURIComponent(e.authentication.username),s=`${r(e)}/community/users/${n}/invitations/${e.invitationId}`;let o={httpMethod:"GET"};return o=Object.assign(Object.assign({},e),o),t.request(s,o)},e.getUserInvitations=function(e){let n={httpMethod:"GET"};const s=encodeURIComponent(e.authentication.username),o=`${r(e)}/community/users/${s}/invitations`;return n=Object.assign(Object.assign({},e),n),t.request(o,n)},e.getUserMembership=g,e.getUserNotifications=function(e){let n={httpMethod:"GET"};const s=encodeURIComponent(e.authentication.username),o=`${r(e)}/community/users/${s}/notifications`;return n=Object.assign(Object.assign({},e),n),t.request(o,n)},e.getUserTags=function(e){const n=e.username||e.authentication.username,s=`${r(e)}/community/users/${encodeURIComponent(n)}/tags`;return t.request(s,e)},e.getUserUrl=function(e){return`${r(e)}/community/users/${encodeURIComponent(e.username)}`},e.inviteGroupUsers=function(e){const n=e.id,s=`${r(e)}/community/groups/${n}/invite`,o=function(e){return I(e.users,25).map((t=>function(e,t){const r=Object.assign({},t);return r.params=Object.assign(Object.assign({},r.params),{users:e,role:r.role,expiration:r.expiration}),r}(t,e)))}(e).map((e=>function(e,r){return t.request(e,r).catch((e=>({errors:[e]})))}(s,e)));return Promise.all(o).then(w)},e.isItemOwner=p,e.isItemSharedWithGroup=C,e.isOrgAdmin=l,e.isServiceNameAvailable=S,e.joinGroup=function(e){const n=`${r(e)}/community/groups/${e.id}/join`;return t.request(n,e)},e.leaveGroup=function(e){const n=`${r(e)}/community/groups/${e.id}/leave`;return t.request(n,e)},e.moveItem=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${n}/items/${e.itemId}/move`;let o=e.folderId;return o||(o="/"),e.params=Object.assign({folder:o},e.params),t.request(s,e)}))},e.protectGroup=function(e){const n=`${r(e)}/community/groups/${e.id}/protect`;return t.request(n,e)},e.protectItem=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${n}/items/${e.id}/protect`;return t.request(s,e)}))},e.reassignItem=function(e){return l(e).then((n=>{if(!n)throw Error(`Item ${e.id} can not be reassigned because current user is not an organization administrator.`);const s=`${r(e)}/content/users/${e.currentOwner}/items/${e.id}/reassign`,o={params:{targetUsername:e.targetUsername,targetFolderName:e.targetFolderName},authentication:e.authentication};return t.request(s,o)}))},e.removeFolder=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${encodeURIComponent(n)}/${e.folderId}/delete`;return t.request(s,e)}))},e.removeGroup=function(e){const n=`${r(e)}/community/groups/${e.id}/delete`,s=Object.assign({},e);return t.request(n,s)},e.removeGroupUsers=O,e.removeItem=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${n}/items/${e.id}/delete`;return t.request(s,e)}))},e.removeItemRelationship=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${n}/deleteRelationship`,o=t.appendCustomParams(e,["originItemId","destinationItemId","relationshipType"],{params:Object.assign({},e.params)});return t.request(s,o)}))},e.removeItemResource=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${n}/items/${e.id}/removeResources`;return e.params=Object.assign(Object.assign({},e.params),{resource:e.resource}),void 0!==e.deleteAll&&(e.params.deleteAll=e.deleteAll),t.request(s,e)}))},e.removeNotification=function(e){const n=encodeURIComponent(e.authentication.username),s=`${r(e)}/community/users/${n}/notifications/${e.id}/delete`;return t.request(s,e)},e.scrubControlChars=a,e.searchGroupContent=function(e){return $(e,"groupContent")},e.searchGroupUsers=function(e,n){const s=`${r(n)}/community/groups/${e}/userlist`,o=t.appendCustomParams(n||{},["name","num","start","sortField","sortOrder","joined","memberType"],{httpMethod:"GET"});return t.request(s,o)},e.searchGroups=function(e){return $(e,"group")},e.searchItems=b,e.searchUsers=function(e){return $(e,"user")},e.setItemAccess=function(e){const t=h(e);return p(e)?U(t,e):l(e).then((r=>{if(r)return U(t,e);throw Error(`This item can not be shared by ${e.authentication.username}. They are neither the item owner nor an organization admin.`)}))},e.shareItemWithGroup=function(e){return C(e).then((t=>{if(t)return{itemId:e.id,shortcut:!0,notSharedWith:[]};const{authentication:{username:r},owner:n,confirmItemControl:s}=e,o=n||r;if(o!==r){let t=!1;return Promise.all([G({username:r,authentication:e.authentication}),G({username:o,authentication:e.authentication}),g(e)]).then((([r,n,o])=>{const i=!!s;return t="org_admin"===r.role&&!r.roleId,function(e,t,r,n,s,o){const i=[];if(o.groupId!==e.favGroupId)if(t){if(!n)throw Error(`This item can not be shared to shared editing group ${o.groupId} by ${e.username} as they not the item owner or org admin.`);i.push(M(e,e,!1,`Error adding ${e.username} as member to edit group ${o.groupId}. Consequently item ${o.id} was not shared to the group.`,o),M(e,s,!0,"none"===r?`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(n)i.push(M(e,e,!1,`Error adding ${e.username} as member to view group ${o.groupId}. Consequently item ${o.id} was not shared to the group.`,o));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 ${o.groupId}.`);return i}(r,i,o,t,n,e)})).then((r=>{const[{revert:n}={promise:Promise.resolve({notAdded:[]}),revert:e=>Promise.resolve(e)}]=r;return Promise.all(r.map((({promise:e})=>e))).then((()=>P(e,t))).then((e=>n(e)))}))}return P(e)})).then((t=>{if(t.notSharedWith.length)throw Error(`Item ${e.id} could not be shared to group ${e.groupId}.`);return t}))},e.unprotectGroup=function(e){const n=`${r(e)}/community/groups/${e.id}/unprotect`;return t.request(n,e)},e.unprotectItem=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${n}/items/${e.id}/unprotect`;return t.request(s,e)}))},e.unshareItemWithGroup=function(e){return C(e).then((n=>{if(!n)return Promise.resolve({itemId:e.id,shortcut:!0,notUnsharedFrom:[]});const{authentication:{username:s},owner:o}=e;return Promise.all([g(e),G({username:s,authentication:e.authentication})]).then((([n,i])=>{const a=(o||s)===s,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 ${e.groupId} by ${s} as they not the item owner, an org admin, group admin or group owner.`);return function(e){const n=e.authentication.username,s=e.owner||n;let o=`${r(e)}/content/items/${e.id}/unshare`;s===n&&(o=`${r(e)}/content/users/${s}/items/${e.id}/unshare`);return e.params={groups:e.groupId},t.request(o,e)}(e)})).then((t=>{if(t.notUnsharedFrom.length)throw Error(`Item ${e.id} could not be unshared to group ${e.groupId}`);return t}))}))},e.updateGroup=function(e){const n=`${r(e)}/community/groups/${e.group.id}/update`;return e.params=Object.assign(Object.assign({},e.params),e.group),t.request(n,e)},e.updateItem=s,e.updateItemInfo=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${n}/items/${e.id}/updateinfo`;return e.params=Object.assign({folderName:e.folderName,file:e.file},e.params),t.request(s,e)}))},e.updateItemResource=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${n}/items/${e.id}/updateResources`;return e.params=Object.assign({file:e.resource,fileName:e.name,resourcesPrefix:e.prefix,text:e.content},e.params),void 0!==e.private&&(e.params.access=e.private?"private":"inherit"),t.request(s,e)}))},e.updateUser=function(e){const n=e.user.username||e.authentication.username,s=`${r(e)}/community/users/${encodeURIComponent(n)}/update`;return e.params=Object.assign(Object.assign({},e.user),e.params),delete e.user,t.request(s,e)},e.updateUserMemberships=v,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,t){"use strict";function r(e={}){return e.portal?t.cleanUrl(e.portal):e.authentication&&"string"!=typeof e.authentication?e.authentication.portal:"https://www.arcgis.com/sharing/rest"}function n(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 s(e){return n(e).then((n=>{const s=e.folderId?`${r(e)}/content/users/${n}/${e.folderId}/items/${e.item.id}/update`:`${r(e)}/content/users/${n}/items/${e.item.id}/update`;return e.params=Object.assign(Object.assign({},e.params),e.item),t.request(s,e)}))}function o(e){return e.multipart&&!e.filename?Promise.reject(new Error("The filename is required for a multipart request.")):n(e).then((n=>{const s=`${r(e)}/content/users/${n}`;let o=`${s}/addItem`;e.folderId&&(o=`${s}/${e.folderId}/addItem`),e.params=Object.assign(Object.assign({},e.params),e.item);const i=t.appendCustomParams(e,["owner","folderId","file","dataUrl","text","async","multipart","filename","overwrite"],{params:Object.assign({},e.params)});return t.request(o,i)}))}const i=/[\x00-\x1F\x7F-\x9F\xA0]/g;function a(e){return e.replace(i,"")}const u=(e,t)=>`${"string"==typeof t?t:r(t)}/content/items/${e}`;function c(e,t){const{fileName:r="iteminfo.xml",readAs:n="text"}=t||{};return m(e,`/info/${r}`,n,Object.assign({httpMethod:"GET"},t))}function m(e,r,n,s){const o=`${u(e,s)}${r}`,i=Object.assign({params:{}},s),c=i.rawResponse;return i.rawResponse=!0,i.params.f=null,t.request(o,i).then((e=>c?e:"json"!==n?e[n]():e.text().then((e=>JSON.parse(a(e))))))}function d(e,n){const s=`${r(n)}/community/groups/${e}`,o=Object.assign({httpMethod:"GET"},n);return t.request(s,o)}function h(e){const t=e.authentication.username,n=e.owner||t;return`${r(e)}/content/users/${encodeURIComponent(n)}/items/${e.id}/share`}function p(e){const t=e.authentication.username;return(e.owner||t)===t}function g(e){return e.authentication.getUser(e).then((e=>e&&"org_admin"===e.role&&!e.roleId))}function l(e){return d(e.groupId,e).then((e=>e.userMembership.memberType)).catch((()=>"none"))}class f{constructor(e=""){this.termStack=[],this.rangeStack=[],this.openGroups=0,this.q=e}match(...e){return this.termStack=this.termStack.concat(e),this}in(e){const r=`\`in(${e?`"${e}"`:""})\``;return this.hasRange||this.hasTerms?(e&&"*"!==e&&(this.q+=`${e}:`),this.commit()):(t.warn(`${r} 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?(t.warn("`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(e){return this.hasTerms?(t.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):(this.rangeStack[0]=e,this)}to(e){return this.hasTerms?(t.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):(this.rangeStack[1]=e,this)}boost(e){return this.commit(),this.q+=`^${e}`,this}toParam(){return this.commit(),this.cleanup(),this.q}clone(){return this.commit(),this.cleanup(),new f(this.q+"")}addModifier(e){return this.currentModifer?(t.warn(`You have called \`${this.currentModifer}()\` after \`${e}()\`. Your current query was not modified.`),this):(this.commit(),""===this.q&&"not"!==e?(t.warn(`You have called \`${e}()\` without calling another method to modify your query first. Try calling \`match()\` first.`),this):(this.currentModifer=e,this.q+=""===this.q?"":" ",this.q+=`${e.toUpperCase()} `,this))}hasWhiteSpace(e){return/\s/g.test(e)}formatTerm(e){return e instanceof Date?e.getTime():"string"==typeof e&&this.hasWhiteSpace(e)?`"${e}"`:e}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((e=>this.formatTerm(e))).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(t.warn(`Automatically closing ${this.openGroups} group(s). You can use \`endGroup(...)\` to remove this warning.`);this.openGroups>0;)this.q+=")",this.openGroups--;const e=this.q;this.q=e.replace(/( AND ?| NOT ?| OR ?)*$/,""),e!==this.q&&t.warn("`startGroup(...)` was called without calling `endGroup(...)` first. Your query was not modified."),this.q=this.q.replace(/(\(\))*/,"")}}function $(e,n){let s,o;switch(s="string"==typeof e||e instanceof f?{httpMethod:"GET",params:{q:e}}:t.appendCustomParams(e,["q","num","start","sortField","sortOrder","searchUserAccess","searchUserName"],{httpMethod:"GET"}),n){case"item":o="/search";break;case"group":o="/community/groups";break;case"groupContent":if("string"==typeof e||e instanceof f||!e.groupId)return Promise.reject(new Error("you must pass a `groupId` option to `searchGroupContent`"));o=`/content/groups/${e.groupId}/search`;break;default:o="/portals/self/users/search"}const i=r(s)+o;return t.request(i,s).then((t=>(t.nextStart&&-1!==t.nextStart&&(t.nextPage=function(){let r;return"string"==typeof e||e instanceof f?r={q:e,start:t.nextStart}:(r=e,r.start=t.nextStart),$(r,n)}),t)))}function b(e){return $(e,"item")}function I(e,t){if(0===e.length)return[];const r=[];for(let n=0;n<e.length;n+=t)r.push(e.slice(n,n+t));return r}function y(e){const n=e.id,s=`${r(e)}/community/groups/${n}/addUsers`,o=Object.assign({},e,{admins:void 0,users:void 0}),i=[...q("users",e.users,o),...q("admins",e.admins,o)].map((e=>function(e,r){return t.request(e,r).catch((e=>({errors:[e]})))}(s,e)));return Promise.all(i).then(j)}function q(e,t,r){if(!t||t.length<1)return[];return I(t,25).map((t=>function(e,t,r){return Object.assign({},r,{[e]:t,params:Object.assign(Object.assign({},r.params),{[e]:t})})}(e,t,r)))}function j(e){const t=e.filter((e=>e.notAdded)).reduce(((e,t)=>e.concat(t.notAdded)),[]),r=e.filter((e=>e.errors)).reduce(((e,t)=>e.concat(t.errors)),[]),n={notAdded:t};return r.length>0&&(n.errors=r),n}function O(e){const{id:n,users:s}=e,o=`${r(e)}/community/groups/${n}/removeUsers`,i=I(s,25).map((r=>(r=>{const n=Object.assign(Object.assign({},e),{users:r,params:{users:r}});return t.request(o,n).catch((e=>({errors:[e]})))})(r)));return Promise.all(i).then((e=>{const t=t=>e.filter((e=>e[t])).reduce(((e,r)=>e.concat(r[t])),[]),r=t("errors"),n={notRemoved:t("notRemoved")};return r.length?Object.assign(Object.assign({},n),{errors:r}):n}))}function w(e){const t=e.every((e=>e.success)),r=e.reduce(((e,t)=>e.concat(t.errors||[])),[]),n={success:t};return r.length>0&&(n.errors=r),n}function v(e){const n=`${r(e)}/community/groups/${e.id}/updateUsers`,s={authentication:e.authentication,params:{}};return"admin"===e.newMemberType?s.params.admins=e.users:s.params.users=e.users,t.request(n,s)}function T(e){const t=e.every((e=>e.success)),r=e.reduce(((e,t)=>e.concat(t.errors||[])),[]),n={success:t};return r.length>0&&(n.errors=r),n}function G(e){let n,s={httpMethod:"GET"};if("string"==typeof e)n=`https://www.arcgis.com/sharing/rest/community/users/${e}`;else{const t=e.username||e.authentication.username;n=`${r(e)}/community/users/${encodeURIComponent(t)}`,s=Object.assign(Object.assign({},e),s)}return t.request(n,s)}function U(e,r){return r.params=Object.assign({org:!1,everyone:!1},r.params),"private"===r.access&&(r.params.groups=" "),"org"===r.access&&(r.params.org=!0),"public"===r.access&&(r.params.account=!0,r.params.everyone=!0),t.request(e,r)}function C(e){return b({q:`id: ${e.id} AND group: ${e.groupId}`,start:1,num:10,sortField:"title",authentication:e.authentication,httpMethod:"POST"}).then((t=>{let r=!1;if(t.total>0)return r=t.results.some((t=>t.id===e.id)),r}))}function P(e,n=!1,s=!1){const o=e.authentication.username,i=e.owner||o;let a=`${r(e)}/content/items/${e.id}/share`;return(i===o||n&&!s)&&(a=`${r(e)}/content/users/${i}/items/${e.id}/share`),e.params={groups:e.groupId,confirmItemControl:e.confirmItemControl},t.request(a,e)}function M(e,t,r,n,s){const o=t.groups||[],i=o.find((e=>e.id===s.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 ${s.groupId} nor can item ${s.id} be shared to the group.`);if(!i&&o.length>511)throw Error(`User ${t.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)r&&"member"===i.userMembership.memberType?(a=v({id:s.groupId,users:[t.username],newMemberType:"admin",authentication:s.authentication}).then((e=>{const t=e.results.reduce(((e,t)=>(t.success||e.push(t.username),e)),[]);return Promise.resolve({notAdded:t})})).catch((()=>({notAdded:[t.username]}))),u=e=>v({id:s.groupId,users:[t.username],newMemberType:"member",authentication:s.authentication}).then((()=>e)).catch((()=>e))):(a=Promise.resolve({notAdded:[]}),u=e=>Promise.resolve(e));else{const e=r?"admins":"users";a=y({id:s.groupId,[e]:[t.username],authentication:s.authentication}).then((e=>{if(e.errors&&e.errors.length)throw e.errors[0];return e})).catch((()=>({notAdded:[t.username]}))),u=e=>O({id:s.groupId,users:[t.username],authentication:s.authentication}).then((()=>e))}return{promise:a.then((e=>{if(e.notAdded.length)throw new Error(n);return e})),revert:u}}function S(e,r,n){const s=`${n.portal}/portals/self/isServiceNameAvailable`;return t.request(s,{params:{name:e,type:r},httpMethod:"GET",authentication:n})}function x(e,n){const s=e||"self",o=`${r(n)}/portals/${s}`,i=Object.assign({httpMethod:"GET"},n);return t.request(o,i)}e.SearchQueryBuilder=f,e.acceptInvitation=function(e){const n=encodeURIComponent(e.authentication.username),s=`${r(e)}/community/users/${n}/invitations/${e.invitationId}/accept`,o=Object.assign({},e);return t.request(s,o)},e.addGroupUsers=y,e.addItemData=function(e){const t=Object.assign({item:{id:e.id,text:e.text,file:e.file}},e);return delete t.id,delete t.data,s(t)},e.addItemPart=function(e){const s=e.partNum;return!Number.isInteger(s)||s<1||s>1e4?Promise.reject(new Error("The part number must be an integer between 1 to 10000, inclusive.")):n(e).then((n=>{const o=`${r(e)}/content/users/${n}/items/${e.id}/addPart?partNum=${s}`,i=t.appendCustomParams(e,["file"],{params:Object.assign({},e.params)});return t.request(o,i)}))},e.addItemRelationship=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${n}/addRelationship`,o=t.appendCustomParams(e,["originItemId","destinationItemId","relationshipType"],{params:Object.assign({},e.params)});return t.request(s,o)}))},e.addItemResource=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${n}/items/${e.id}/addResources`;return e.params=Object.assign({file:e.resource,fileName:e.name,resourcesPrefix:e.prefix,text:e.content,access:e.private?"private":"inherit"},e.params),t.request(s,e)}))},e.cancelItemUpload=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${n}/items/${e.id}/cancel`;return t.request(s,e)}))},e.commitItemUpload=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${n}/items/${e.id}/commit`,o=t.appendCustomParams(e,[],{params:Object.assign(Object.assign({},e.params),e.item)});return t.request(s,o)}))},e.createFolder=function(e){return n(e).then((n=>{const s=`${`${r(e)}/content/users/${n}`}/createFolder`;return e.params=Object.assign({title:e.title},e.params),t.request(s,e)}))},e.createGroup=function(e){const n=`${r(e)}/community/createGroup`;return e.params=Object.assign(Object.assign({},e.params),e.group),t.request(n,e)},e.createGroupNotification=function(e){const n=`${r(e)}/community/groups/${e.id}/createNotification`,s=Object.assign({params:Object.assign({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 t.request(n,s)},e.createItem=function(e){return o(Object.assign({folderId:null},e))},e.createItemInFolder=o,e.createOrgNotification=function(e){const n=`${r(e)}/portals/self/createNotification`,s=function(e){return I(e.users,e.batchSize||25).map((t=>function(e,t){const r=Object.assign({},t);return r.params=Object.assign(Object.assign({},r.params),{users:e,subject:t.subject,message:t.message,notificationChannelType:r.notificationChannelType}),r}(t,e)))}(e).map((e=>function(e,r){return t.request(e,r).catch((e=>({errors:[e]})))}(n,e)));return Promise.all(s).then(T)},e.declineInvitation=function(e){const n=encodeURIComponent(e.authentication.username),s=`${r(e)}/community/users/${n}/invitations/${e.invitationId}/decline`,o=Object.assign({},e);return t.request(s,o)},e.determineOwner=n,e.ensureMembership=M,e.exportItem=e=>{const{authentication:s,id:o,title:i,exportFormat:a,exportParameters:u}=e;return n(e).then((t=>`${r(e)}/content/users/${t}/export`)).then((e=>t.request(e,{httpMethod:"POST",authentication:s,params:{itemId:o,title:i,exportFormat:a,exportParameters:u}})))},e.getGroup=d,e.getGroupCategorySchema=function(e,n){const s=`${r(n)}/community/groups/${e}/categorySchema`,o=Object.assign({httpMethod:"GET"},n);return t.request(s,o)},e.getGroupContent=function(e,n){const s=`${r(n)}/content/groups/${e}`,o=Object.assign(Object.assign({httpMethod:"GET"},{params:{start:1,num:100}}),n);return n&&n.paging&&(o.params=Object.assign({},n.paging)),t.request(s,o)},e.getGroupUsers=function(e,n){const s=`${r(n)}/community/groups/${e}/users`,o=Object.assign({httpMethod:"GET"},n);return t.request(s,o)},e.getItem=function(e,r){const n=u(e,r),s=Object.assign({httpMethod:"GET"},r);return t.request(n,s)},e.getItemBaseUrl=u,e.getItemData=function(e,r){const n=`${u(e,r)}/data`,s=Object.assign({httpMethod:"GET",params:{}},r);return s.file&&(s.params.f=null),t.request(n,s).catch((e=>{if(!RegExp(/The string did not match the expected pattern|(Unexpected end of (JSON input|data at line 1 column 1))/i).test(e.message))throw e}))},e.getItemGroups=function(e,r){const n=`${u(e,r)}/groups`;return t.request(n,r)},e.getItemInfo=c,e.getItemMetadata=function(e,t){return c(e,Object.assign(Object.assign({},t),{fileName:"metadata/metadata.xml"}))},e.getItemParts=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${n}/items/${e.id}/parts`;return t.request(s,e)}))},e.getItemResource=function(e,t){const r=t.readAs||"blob";return m(e,`/resources/${t.fileName}`,r,t)},e.getItemResources=function(e,r){const n=`${u(e,r)}/resources`,s=Object.assign({},r);return s.params=Object.assign({num:1e3},s.params),t.request(n,s)},e.getItemStatus=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${n}/items/${e.id}/status`,o=t.appendCustomParams(e,["jobId","jobType"],{params:Object.assign({},e.params)});return t.request(s,o)}))},e.getPortal=x,e.getPortalSettings=function(e,n){const s=e||"self",o=`${r(n)}/portals/${s}/settings`,i=Object.assign({httpMethod:"GET"},n);return t.request(o,i)},e.getPortalUrl=r,e.getRelatedItems=function(e){const r=`${u(e.id,e)}/relatedItems`,n=Object.assign({httpMethod:"GET",params:{direction:e.direction}},e);return"string"==typeof e.relationshipType?n.params.relationshipType=e.relationshipType:n.params.relationshipTypes=e.relationshipType,delete n.direction,delete n.relationshipType,t.request(r,n)},e.getSelf=function(e){return x(null,e)},e.getSharingUrl=h,e.getUniqueServiceName=function e(t,r,n,s){let o=t;return s&&(o=`${t}_${s}`),S(o,r,n).then((i=>i.available?o:e(t,r,n,s+=1)))},e.getUser=G,e.getUserContent=e=>{const{folderId:s,start:o=1,num:i=10,authentication:a}=e,u=s?`/${s}`:"";return n(e).then((t=>`${r(e)}/content/users/${t}${u}`)).then((e=>t.request(e,{httpMethod:"GET",authentication:a,params:{start:o,num:i}})))},e.getUserInvitation=function(e){const n=encodeURIComponent(e.authentication.username),s=`${r(e)}/community/users/${n}/invitations/${e.invitationId}`;let o={httpMethod:"GET"};return o=Object.assign(Object.assign({},e),o),t.request(s,o)},e.getUserInvitations=function(e){let n={httpMethod:"GET"};const s=encodeURIComponent(e.authentication.username),o=`${r(e)}/community/users/${s}/invitations`;return n=Object.assign(Object.assign({},e),n),t.request(o,n)},e.getUserMembership=l,e.getUserNotifications=function(e){let n={httpMethod:"GET"};const s=encodeURIComponent(e.authentication.username),o=`${r(e)}/community/users/${s}/notifications`;return n=Object.assign(Object.assign({},e),n),t.request(o,n)},e.getUserTags=function(e){const n=e.username||e.authentication.username,s=`${r(e)}/community/users/${encodeURIComponent(n)}/tags`;return t.request(s,e)},e.getUserUrl=function(e){return`${r(e)}/community/users/${encodeURIComponent(e.username)}`},e.inviteGroupUsers=function(e){const n=e.id,s=`${r(e)}/community/groups/${n}/invite`,o=function(e){return I(e.users,25).map((t=>function(e,t){const r=Object.assign({},t);return r.params=Object.assign(Object.assign({},r.params),{users:e,role:r.role,expiration:r.expiration}),r}(t,e)))}(e).map((e=>function(e,r){return t.request(e,r).catch((e=>({errors:[e]})))}(s,e)));return Promise.all(o).then(w)},e.isItemOwner=p,e.isItemSharedWithGroup=C,e.isOrgAdmin=g,e.isServiceNameAvailable=S,e.joinGroup=function(e){const n=`${r(e)}/community/groups/${e.id}/join`;return t.request(n,e)},e.leaveGroup=function(e){const n=`${r(e)}/community/groups/${e.id}/leave`;return t.request(n,e)},e.moveItem=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${n}/items/${e.itemId}/move`;let o=e.folderId;return o||(o="/"),e.params=Object.assign({folder:o},e.params),t.request(s,e)}))},e.protectGroup=function(e){const n=`${r(e)}/community/groups/${e.id}/protect`;return t.request(n,e)},e.protectItem=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${n}/items/${e.id}/protect`;return t.request(s,e)}))},e.reassignItem=function(e){return g(e).then((n=>{if(!n)throw Error(`Item ${e.id} can not be reassigned because current user is not an organization administrator.`);const s=`${r(e)}/content/users/${e.currentOwner}/items/${e.id}/reassign`,o={params:{targetUsername:e.targetUsername,targetFolderName:e.targetFolderName},authentication:e.authentication};return t.request(s,o)}))},e.removeFolder=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${encodeURIComponent(n)}/${e.folderId}/delete`;return t.request(s,e)}))},e.removeGroup=function(e){const n=`${r(e)}/community/groups/${e.id}/delete`,s=Object.assign({},e);return t.request(n,s)},e.removeGroupUsers=O,e.removeItem=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${n}/items/${e.id}/delete`;return t.request(s,e)}))},e.removeItemRelationship=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${n}/deleteRelationship`,o=t.appendCustomParams(e,["originItemId","destinationItemId","relationshipType"],{params:Object.assign({},e.params)});return t.request(s,o)}))},e.removeItemResource=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${n}/items/${e.id}/removeResources`;return e.params=Object.assign(Object.assign({},e.params),{resource:e.resource}),void 0!==e.deleteAll&&(e.params.deleteAll=e.deleteAll),t.request(s,e)}))},e.removeNotification=function(e){const n=encodeURIComponent(e.authentication.username),s=`${r(e)}/community/users/${n}/notifications/${e.id}/delete`;return t.request(s,e)},e.scrubControlChars=a,e.searchGroupContent=function(e){return $(e,"groupContent")},e.searchGroupUsers=function(e,n){const s=`${r(n)}/community/groups/${e}/userlist`,o=t.appendCustomParams(n||{},["name","num","start","sortField","sortOrder","joined","memberType"],{httpMethod:"GET"});return t.request(s,o)},e.searchGroups=function(e){return $(e,"group")},e.searchItems=b,e.searchUsers=function(e){return $(e,"user")},e.setItemAccess=function(e){const t=h(e);return p(e)?U(t,e):g(e).then((r=>{if(r)return U(t,e);throw Error(`This item can not be shared by ${e.authentication.username}. They are neither the item owner nor an organization admin.`)}))},e.shareItemWithGroup=function(e){return C(e).then((t=>{if(t)return{itemId:e.id,shortcut:!0,notSharedWith:[]};const{authentication:{username:r},owner:n,confirmItemControl:s}=e,o=n||r;if(o!==r){let t=!1,n=!1;return Promise.all([G({username:r,authentication:e.authentication}),G({username:o,authentication:e.authentication}),l(e)]).then((([r,o,i])=>{const a=!!s;return t="org_admin"===r.role&&!r.roleId,n=r.orgId!==o.orgId,function(e,t,r,n,s,o){const i=[];if(o.groupId!==e.favGroupId)if(t){if(!n)throw Error(`This item can not be shared to shared editing group ${o.groupId} by ${e.username} as they not the item owner or org admin.`);i.push(M(e,e,!1,`Error adding ${e.username} as member to edit group ${o.groupId}. Consequently item ${o.id} was not shared to the group.`,o),M(e,s,!0,"none"===r?`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(n)i.push(M(e,e,!1,`Error adding ${e.username} as member to view group ${o.groupId}. Consequently item ${o.id} was not shared to the group.`,o));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 ${o.groupId}.`);return i}(r,a,i,t,o,e)})).then((r=>{const[{revert:s}={promise:Promise.resolve({notAdded:[]}),revert:e=>Promise.resolve(e)}]=r;return Promise.all(r.map((({promise:e})=>e))).then((()=>P(e,t,n))).then((e=>s(e)))}))}return P(e)})).then((t=>{if(t.notSharedWith.length)throw Error(`Item ${e.id} could not be shared to group ${e.groupId}.`);return t}))},e.unprotectGroup=function(e){const n=`${r(e)}/community/groups/${e.id}/unprotect`;return t.request(n,e)},e.unprotectItem=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${n}/items/${e.id}/unprotect`;return t.request(s,e)}))},e.unshareItemWithGroup=function(e){return C(e).then((n=>{if(!n)return Promise.resolve({itemId:e.id,shortcut:!0,notUnsharedFrom:[]});const{authentication:{username:s},owner:o}=e;return Promise.all([l(e),G({username:s,authentication:e.authentication})]).then((([n,i])=>{const a=(o||s)===s,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 ${e.groupId} by ${s} as they not the item owner, an org admin, group admin or group owner.`);return function(e){const n=e.authentication.username,s=e.owner||n;let o=`${r(e)}/content/items/${e.id}/unshare`;s===n&&(o=`${r(e)}/content/users/${s}/items/${e.id}/unshare`);return e.params={groups:e.groupId},t.request(o,e)}(e)})).then((t=>{if(t.notUnsharedFrom.length)throw Error(`Item ${e.id} could not be unshared to group ${e.groupId}`);return t}))}))},e.updateGroup=function(e){const n=`${r(e)}/community/groups/${e.group.id}/update`;return e.params=Object.assign(Object.assign({},e.params),e.group),t.request(n,e)},e.updateItem=s,e.updateItemInfo=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${n}/items/${e.id}/updateinfo`;return e.params=Object.assign({folderName:e.folderName,file:e.file},e.params),t.request(s,e)}))},e.updateItemResource=function(e){return n(e).then((n=>{const s=`${r(e)}/content/users/${n}/items/${e.id}/updateResources`;return e.params=Object.assign({file:e.resource,fileName:e.name,resourcesPrefix:e.prefix,text:e.content},e.params),void 0!==e.private&&(e.params.access=e.private?"private":"inherit"),t.request(s,e)}))},e.updateUser=function(e){const n=e.user.username||e.authentication.username,s=`${r(e)}/community/users/${encodeURIComponent(n)}/update`;return e.params=Object.assign(Object.assign({},e.user),e.params),delete e.user,t.request(s,e)},e.updateUserMemberships=v,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=portal.umd.min.js.map |
@@ -54,5 +54,5 @@ "use strict"; | ||
// export * from "./util/generic-search"; because its an internal utility method | ||
// Types that are used in this package are re-exported for convenience and | ||
// Types that are used in this package are re-exported for convenience and | ||
// to make the links work correctly in the documentation pages. | ||
(0, tslib_1.__exportStar)(require("./helpers.js"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -48,2 +48,4 @@ "use strict"; | ||
let isAdmin = false; | ||
// track if the admin & owner are in the same org | ||
let isCrossOrgSharing = false; | ||
// next perform any necessary membership adjustments for | ||
@@ -65,2 +67,3 @@ // current user and/or item owner | ||
isAdmin = currentUser.role === "org_admin" && !currentUser.roleId; | ||
isCrossOrgSharing = currentUser.orgId !== ownerUser.orgId; | ||
return getMembershipAdjustments(currentUser, isSharedEditingGroup, membership, isAdmin, ownerUser, requestOptions); | ||
@@ -79,3 +82,3 @@ }) | ||
// then attempt the share | ||
return shareToGroup(requestOptions, isAdmin); | ||
return shareToGroup(requestOptions, isAdmin, isCrossOrgSharing); | ||
}) | ||
@@ -132,3 +135,3 @@ .then((sharingResults) => { | ||
} | ||
function shareToGroup(requestOptions, isAdmin = false) { | ||
function shareToGroup(requestOptions, isAdmin = false, isCrossOrgSharing = false) { | ||
const username = requestOptions.authentication.username; | ||
@@ -141,4 +144,4 @@ const itemOwner = requestOptions.owner || username; | ||
// Note: When using this end-point as an admin, apparently the admin does not need to be a member of the group (the itemOwner does) | ||
// Have not validated this but came up in conversations w/ Sharing API team | ||
if (itemOwner === username || isAdmin) { | ||
// Note: Admin's can only use this route when the item is in the same org they are admin for | ||
if (itemOwner === username || (isAdmin && !isCrossOrgSharing)) { | ||
url = `${(0, get_portal_url_js_1.getPortalUrl)(requestOptions)}/content/users/${itemOwner}/items/${requestOptions.id}/share`; | ||
@@ -145,0 +148,0 @@ } |
@@ -23,3 +23,3 @@ "use strict"; | ||
* ```js | ||
* import { getPortal } from "@esri/arcgis-rest-request"; | ||
* import { getPortal } from "@esri/arcgis-rest-portal"; | ||
* // | ||
@@ -26,0 +26,0 @@ * getPortal() |
@@ -12,3 +12,3 @@ "use strict"; | ||
* ```js | ||
* import { getSubscriptionInfo } from "@esri/arcgis-rest-request"; | ||
* import { getSubscriptionInfo } from "@esri/arcgis-rest-portal"; | ||
* | ||
@@ -15,0 +15,0 @@ * getSubscriptionInfo() |
@@ -47,3 +47,3 @@ export * from "./items/add.js"; | ||
export * from "./util/SearchQueryBuilder.js"; | ||
export * from './helpers.js'; | ||
export * from "./helpers.js"; | ||
export type { IUser, IGroup, IGroupAdd, GroupMembership } from "@esri/arcgis-rest-request"; |
@@ -51,5 +51,5 @@ /* Copyright (c) 2018-2019 Environmental Systems Research Institute, Inc. | ||
// export * from "./util/generic-search"; because its an internal utility method | ||
// Types that are used in this package are re-exported for convenience and | ||
// Types that are used in this package are re-exported for convenience and | ||
// to make the links work correctly in the documentation pages. | ||
export * from './helpers.js'; | ||
export * from "./helpers.js"; | ||
//# sourceMappingURL=index.js.map |
@@ -45,2 +45,4 @@ import { request } from "@esri/arcgis-rest-request"; | ||
let isAdmin = false; | ||
// track if the admin & owner are in the same org | ||
let isCrossOrgSharing = false; | ||
// next perform any necessary membership adjustments for | ||
@@ -62,2 +64,3 @@ // current user and/or item owner | ||
isAdmin = currentUser.role === "org_admin" && !currentUser.roleId; | ||
isCrossOrgSharing = currentUser.orgId !== ownerUser.orgId; | ||
return getMembershipAdjustments(currentUser, isSharedEditingGroup, membership, isAdmin, ownerUser, requestOptions); | ||
@@ -76,3 +79,3 @@ }) | ||
// then attempt the share | ||
return shareToGroup(requestOptions, isAdmin); | ||
return shareToGroup(requestOptions, isAdmin, isCrossOrgSharing); | ||
}) | ||
@@ -128,3 +131,3 @@ .then((sharingResults) => { | ||
} | ||
function shareToGroup(requestOptions, isAdmin = false) { | ||
function shareToGroup(requestOptions, isAdmin = false, isCrossOrgSharing = false) { | ||
const username = requestOptions.authentication.username; | ||
@@ -137,4 +140,4 @@ const itemOwner = requestOptions.owner || username; | ||
// Note: When using this end-point as an admin, apparently the admin does not need to be a member of the group (the itemOwner does) | ||
// Have not validated this but came up in conversations w/ Sharing API team | ||
if (itemOwner === username || isAdmin) { | ||
// Note: Admin's can only use this route when the item is in the same org they are admin for | ||
if (itemOwner === username || (isAdmin && !isCrossOrgSharing)) { | ||
url = `${getPortalUrl(requestOptions)}/content/users/${itemOwner}/items/${requestOptions.id}/share`; | ||
@@ -141,0 +144,0 @@ } |
@@ -19,3 +19,3 @@ import { IRequestOptions } from "@esri/arcgis-rest-request"; | ||
* ```js | ||
* import { getPortal } from "@esri/arcgis-rest-request"; | ||
* import { getPortal } from "@esri/arcgis-rest-portal"; | ||
* // | ||
@@ -22,0 +22,0 @@ * getPortal() |
@@ -19,3 +19,3 @@ /* Copyright (c) 2017-2019 Environmental Systems Research Institute, Inc. | ||
* ```js | ||
* import { getPortal } from "@esri/arcgis-rest-request"; | ||
* import { getPortal } from "@esri/arcgis-rest-portal"; | ||
* // | ||
@@ -22,0 +22,0 @@ * getPortal() |
@@ -10,3 +10,3 @@ import { IRequestOptions } from "@esri/arcgis-rest-request"; | ||
* ```js | ||
* import { getSubscriptionInfo } from "@esri/arcgis-rest-request"; | ||
* import { getSubscriptionInfo } from "@esri/arcgis-rest-portal"; | ||
* | ||
@@ -13,0 +13,0 @@ * getSubscriptionInfo() |
@@ -9,3 +9,3 @@ /* Copyright (c) 2017-2019 Environmental Systems Research Institute, Inc. | ||
* ```js | ||
* import { getSubscriptionInfo } from "@esri/arcgis-rest-request"; | ||
* import { getSubscriptionInfo } from "@esri/arcgis-rest-portal"; | ||
* | ||
@@ -12,0 +12,0 @@ * getSubscriptionInfo() |
{ | ||
"name": "@esri/arcgis-rest-portal", | ||
"version": "4.0.3", | ||
"version": "4.0.4", | ||
"description": "ArcGIS Online and Enterprise content and user helpers for @esri/arcgis-rest-request", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0", |
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
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
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 not supported yet
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 not supported yet
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 not supported yet
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 not supported yet
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 not supported yet
Sorry, the diff of this file is not supported yet
1744610
14424