{"version":3,"sources":["node_modules/@arcgis/core/layers/mixins/PortalLayer.js"],"sourcesContent":["/*\nAll material copyright ESRI, All Rights Reserved, unless otherwise specified.\nSee https://js.arcgis.com/4.31/esri/copyright.txt for details.\n*/\nimport { _ as t } from \"../../chunks/tslib.es6.js\";\nimport e from \"../../config.js\";\nimport { id as r } from \"../../kernel.js\";\nimport s from \"../../request.js\";\nimport { result as i } from \"../../core/asyncUtils.js\";\nimport o from \"../../core/Error.js\";\nimport a from \"../../core/Logger.js\";\nimport { destroyMaybe as l } from \"../../core/maybe.js\";\nimport { throwIfAborted as n, isAbortError as p, throwIfAbortError as u } from \"../../core/promiseUtils.js\";\nimport { hasSameCanonicalPortal as c, normalize as d, hasSamePortal as m } from \"../../core/urlUtils.js\";\nimport { property as h } from \"../../core/accessorSupport/decorators/property.js\";\nimport \"../../core/has.js\";\nimport \"../../core/RandomLCG.js\";\nimport { reader as f } from \"../../core/accessorSupport/decorators/reader.js\";\nimport { subclass as g } from \"../../core/accessorSupport/decorators/subclass.js\";\nimport { writer as y } from \"../../core/accessorSupport/decorators/writer.js\";\nimport { getOwningPortalUrl as I } from \"../support/layerUtils.js\";\nimport v from \"../../portal/Portal.js\";\nimport P from \"../../portal/PortalItem.js\";\nimport w from \"../../portal/PortalUser.js\";\nimport { getUserPrivileges as U } from \"../../portal/support/portalItemUtils.js\";\nconst j = j => {\n let _ = class extends j {\n constructor() {\n super(...arguments), this.resourceReferences = {\n portalItem: null,\n paths: []\n }, this.userHasEditingPrivileges = !0, this.userHasFullEditingPrivileges = !1, this.userHasUpdateItemPrivileges = !1;\n }\n destroy() {\n this.portalItem = l(this.portalItem), this.resourceReferences.portalItem = null, this.resourceReferences.paths.length = 0;\n }\n set portalItem(t) {\n t !== this._get(\"portalItem\") && (this.removeOrigin(\"portal-item\"), this._set(\"portalItem\", t));\n }\n readPortalItem(t, e, r) {\n if (e.itemId) return new P({\n id: e.itemId,\n portal: r?.portal\n });\n }\n writePortalItem(t, e) {\n t?.id && (e.itemId = t.id);\n }\n async loadFromPortal(t, e) {\n if (this.portalItem?.id) try {\n const {\n load: r\n } = await import(\"../../portal/support/layersLoader.js\");\n return n(e), await r({\n instance: this,\n supportedTypes: t.supportedTypes,\n validateItem: t.validateItem,\n supportsData: t.supportsData,\n layerModuleTypeMap: t.layerModuleTypeMap\n }, e);\n } catch (r) {\n throw p(r) || a.getLogger(this).warn(`Failed to load layer (${this.title}, ${this.id}) portal item (${this.portalItem.id})\\n ${r}`), r;\n }\n }\n async finishLoadEditablePortalLayer(t) {\n this._set(\"userHasEditingPrivileges\", await this._fetchUserHasEditingPrivileges(t).catch(t => (u(t), !0)));\n }\n async setUserPrivileges(t, r) {\n if (!e.userPrivilegesApplied) return this.finishLoadEditablePortalLayer(r);\n if (this.url) try {\n const {\n features: {\n edit: e,\n fullEdit: s\n },\n content: {\n updateItem: i\n }\n } = await this._fetchUserPrivileges(t, r);\n this._set(\"userHasEditingPrivileges\", e), this._set(\"userHasFullEditingPrivileges\", s), this._set(\"userHasUpdateItemPrivileges\", i);\n } catch (s) {\n u(s);\n }\n }\n async _fetchUserPrivileges(t, e) {\n let s = this.portalItem;\n if (!t || !s || !s.loaded || s.sourceUrl) return this._fetchFallbackUserPrivileges(e);\n const i = t === s.id;\n if (i && s.portal.user) return U(s);\n let o, a;\n if (i) o = s.portal.url;else try {\n o = await I(this.url, e);\n } catch (d) {\n u(d);\n }\n if (!o || !c(o, s.portal.url)) return this._fetchFallbackUserPrivileges(e);\n try {\n const t = null != e ? e.signal : null;\n a = await r?.getCredential(`${o}/sharing`, {\n prompt: !1,\n signal: t\n });\n } catch (d) {\n u(d);\n }\n const l = !0,\n n = !1,\n p = !1;\n if (!a) return {\n features: {\n edit: l,\n fullEdit: n\n },\n content: {\n updateItem: p\n }\n };\n try {\n if (i ? await s.reload() : (s = new P({\n id: t,\n portal: {\n url: o\n }\n }), await s.load(e)), s.portal.user) return U(s);\n } catch (d) {\n u(d);\n }\n return {\n features: {\n edit: l,\n fullEdit: n\n },\n content: {\n updateItem: p\n }\n };\n }\n async _fetchFallbackUserPrivileges(t) {\n let e = !0;\n try {\n e = await this._fetchUserHasEditingPrivileges(t);\n } catch (r) {\n u(r);\n }\n return {\n features: {\n edit: e,\n fullEdit: !1\n },\n content: {\n updateItem: !1\n }\n };\n }\n async _fetchUserHasEditingPrivileges(t) {\n const e = this.url ? r?.findCredential(this.url) : null;\n if (!e) return !0;\n const s = E.credential === e ? E.user : await this._fetchEditingUser(t);\n return E.credential = e, E.user = s, null == s?.privileges || s.privileges.includes(\"features:user:edit\");\n }\n async _fetchEditingUser(t) {\n const e = this.portalItem?.portal?.user;\n if (e) return e;\n const o = r?.findServerInfo(this.url ?? \"\");\n if (!o?.owningSystemUrl) return null;\n const a = `${o.owningSystemUrl}/sharing/rest`,\n l = v.getDefault();\n if (l && l.loaded && d(l.restUrl) === d(a)) return l.user;\n const n = `${a}/community/self`,\n p = null != t ? t.signal : null,\n u = await i(s(n, {\n authMode: \"no-prompt\",\n query: {\n f: \"json\"\n },\n signal: p\n }));\n return u.ok ? w.fromJSON(u.value.data) : null;\n }\n read(t, e) {\n e && (e.layer = this), super.read(t, e);\n }\n write(t, e) {\n const r = e?.portal,\n s = this.portalItem?.id && (this.portalItem.portal || v.getDefault());\n return r && s && !m(s.restUrl, r.restUrl) ? (e.messages && e.messages.push(new o(\"layer:cross-portal\", `The layer '${this.title} (${this.id})' cannot be persisted because it refers to an item on a different portal than the one being saved to. To save, set layer.portalItem to null or save to the same portal as the item associated with the layer`, {\n layer: this\n })), null) : super.write(t, {\n ...e,\n layer: this\n });\n }\n };\n return t([h({\n type: P\n })], _.prototype, \"portalItem\", null), t([f(\"web-document\", \"portalItem\", [\"itemId\"])], _.prototype, \"readPortalItem\", null), t([y(\"web-document\", \"portalItem\", {\n itemId: {\n type: String\n }\n })], _.prototype, \"writePortalItem\", null), t([h({\n clonable: !1\n })], _.prototype, \"resourceReferences\", void 0), t([h({\n type: Boolean,\n readOnly: !0\n })], _.prototype, \"userHasEditingPrivileges\", void 0), t([h({\n type: Boolean,\n readOnly: !0\n })], _.prototype, \"userHasFullEditingPrivileges\", void 0), t([h({\n type: Boolean,\n readOnly: !0\n })], _.prototype, \"userHasUpdateItemPrivileges\", void 0), _ = t([g(\"esri.layers.mixins.PortalLayer\")], _), _;\n },\n E = {\n credential: null,\n user: null\n };\nexport { j as PortalLayer };"],"mappings":"ssBAyBA,IAAMA,GAAIA,GAAK,CACX,IAAIC,EAAI,cAAcD,CAAE,CACtB,aAAc,CACZ,MAAM,GAAG,SAAS,EAAG,KAAK,mBAAqB,CAC7C,WAAY,KACZ,MAAO,CAAC,CACV,EAAG,KAAK,yBAA2B,GAAI,KAAK,6BAA+B,GAAI,KAAK,4BAA8B,EACpH,CACA,SAAU,CACR,KAAK,WAAaE,EAAE,KAAK,UAAU,EAAG,KAAK,mBAAmB,WAAa,KAAM,KAAK,mBAAmB,MAAM,OAAS,CAC1H,CACA,IAAI,WAAWC,EAAG,CAChBA,IAAM,KAAK,KAAK,YAAY,IAAM,KAAK,aAAa,aAAa,EAAG,KAAK,KAAK,aAAcA,CAAC,EAC/F,CACA,eAAeA,EAAGC,EAAGC,EAAG,CACtB,GAAID,EAAE,OAAQ,OAAO,IAAIE,EAAE,CACzB,GAAIF,EAAE,OACN,OAAQC,GAAG,MACb,CAAC,CACH,CACA,gBAAgBF,EAAGC,EAAG,CACpBD,GAAG,KAAOC,EAAE,OAASD,EAAE,GACzB,CACM,eAAeA,EAAGC,EAAG,QAAAG,EAAA,sBACzB,GAAI,KAAK,YAAY,GAAI,GAAI,CAC3B,GAAM,CACJ,KAAMF,CACR,EAAI,KAAM,QAAO,qBAAsC,EACvD,OAAOG,EAAEJ,CAAC,EAAG,MAAMC,EAAE,CACnB,SAAU,KACV,eAAgBF,EAAE,eAClB,aAAcA,EAAE,aAChB,aAAcA,EAAE,aAChB,mBAAoBA,EAAE,kBACxB,EAAGC,CAAC,CACN,OAASC,EAAG,CACV,MAAMI,EAAEJ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EAAE,UAAW,iBAAkB,IAAI,EAAGI,EAAE,CAACA,EAAE,eAAgB,aAAc,CAC/J,OAAQ,CACN,KAAM,MACR,CACF,CAAC,CAAC,EAAGJ,EAAE,UAAW,kBAAmB,IAAI,EAAGI,EAAE,CAACoB,EAAE,CAC/C,SAAU,EACZ,CAAC,CAAC,EAAGxB,EAAE,UAAW,qBAAsB,MAAM,EAAGI,EAAE,CAACoB,EAAE,CACpD,KAAM,QACN,SAAU,EACZ,CAAC,CAAC,EAAGxB,EAAE,UAAW,2BAA4B,MAAM,EAAGI,EAAE,CAACoB,EAAE,CAC1D,KAAM,QACN,SAAU,EACZ,CAAC,CAAC,EAAGxB,EAAE,UAAW,+BAAgC,MAAM,EAAGI,EAAE,CAACoB,EAAE,CAC9D,KAAM,QACN,SAAU,EACZ,CAAC,CAAC,EAAGxB,EAAE,UAAW,8BAA+B,MAAM,EAAGA,EAAII,EAAE,CAACM,EAAE,gCAAgC,CAAC,EAAGV,CAAC,EAAGA,CAC7G,EACAY,EAAI,CACF,WAAY,KACZ,KAAM,IACR","names":["j","_","u","t","e","r","S","__async","s","b","n","a","i","E","o","x","d","W","l","p","K","U","N","__spreadProps","__spreadValues","m"],"x_google_ignoreList":[0]}