Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@descope/role-management-widget

Package Overview
Dependencies
Maintainers
0
Versions
132
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@descope/role-management-widget - npm Package Compare versions

Comparing version 0.1.105 to 0.1.106

4

dist/esm/index.js
/**
* @descope/role-management-widget v0.1.105
* @descope/role-management-widget v0.1.106
*/
import{pluralize as e,createSingletonMixin as t,compose as i,createTemplate as o,withMemCache as s,debounce as n}from"@descope/sdk-helpers";import{__awaiter as a,__classPrivateFieldGet as r,__classPrivateFieldSet as l,__rest as d}from"tslib";import{projectIdMixin as c,observeAttributesMixin as u,loggerMixin as h,baseUrlMixin as g,createValidateAttributesMixin as v,createStateManagementMixin as m,initLifecycleMixin as p,staticResourcesMixin as R,descopeUiMixin as f,initElementMixin as y,modalMixin as w,formMixin as b,notificationsMixin as M,debuggerMixin as C,themeMixin as W}from"@descope/sdk-mixins";import{ButtonDriver as k,MultiSelectDriver as x,TextDriver as S,TextFieldDriver as j,GridDriver as P}from"@descope/sdk-component-drivers";import{createSelector as L}from"reselect";import{createAsyncThunk as O}from"@reduxjs/toolkit";import I from"@descope/web-js-sdk";const N=e=>e.selectedRolesIds,F=e=>e.notifications,$=e=>e.tenantPermissions.data||[],q=L((e=>e.rolesList.data),(e=>e.map((e=>{var t;return Object.assign(Object.assign({},e),{editable:0===(null===(t=null==e?void 0:e.tenantId)||void 0===t?void 0:t.length)?"no":"yes"})})))),B=L(N,q,((e,t)=>t.filter((t=>e.includes(t.name))))),D=L(N,(e=>!!e.length)),T=L(N,(e=>1===e.length)),E=L(B,(e=>1===e.length?e[0].name:`${e.length} roles`)),A=e=>(...t)=>i=>{i.addCase(e.pending,((e,i)=>{t.forEach((({onPending:t})=>{null==t||t(e,i)}))})),i.addCase(e.fulfilled,((e,i)=>{t.forEach((({onFulfilled:t})=>{null==t||t(e,i)}))})),i.addCase(e.rejected,((e,i)=>{t.forEach((({onRejected:t})=>{null==t||t(e,i)}))}))},H=e=>({onFulfilled:t=>{e(t).loading=!1},onPending:t=>{e(t).loading=!0,e(t).error=null},onRejected:(t,i)=>{e(t).loading=!1,e(t).error=i.error}}),Z=({getErrorMsg:e,getSuccessMsg:t})=>({onFulfilled:(e,i)=>{t&&e.notifications.push({type:"success",msg:t(i)})},onRejected:(t,i)=>{e&&t.notifications.push({type:"error",msg:e(i)})}}),V=O("roles/create",((e,{extra:{api:t}})=>t.role.create(e))),U=A(V)({onFulfilled:(e,t)=>{e.rolesList.data.unshift(t.payload)}},H((e=>e.createRole)),Z({getSuccessMsg:()=>"Role created successfully",getErrorMsg:e=>{var t;return`\n <div>\n <div>Failed to create role</div>\n ${null===(t=e.error)||void 0===t?void 0:t.message}\n </div>`}})),z={action:V,reducer:U},J=O("roles/delete",((e,{extra:{api:t}})=>t.role.deleteBatch(e))),G=A(J)({onFulfilled:(e,t)=>{e.rolesList.data=e.rolesList.data.filter((e=>{var i;return 0===(null===(i=null==e?void 0:e.tenantId)||void 0===i?void 0:i.length)||!t.meta.arg.includes(e.name)})),e.selectedRolesIds=[]}},H((e=>e.deleteRole)),Z({getSuccessMsg:t=>e(t.meta.arg.length)`${["",t.meta.arg.length]} ${["R","r"]}ole${["","s"]} deleted successfully`,getErrorMsg:t=>e(t.meta.arg.length)`Failed to delete role${["","s"]}`})),K={action:J,reducer:G},Q=O("roles/search",((e,{extra:{api:t},getState:i})=>{const o=i().searchParams;return t.role.search(Object.assign(Object.assign({},o),e))})),X=A(Q)({onPending:(e,t)=>{e.searchParams=Object.assign(Object.assign({},e.searchParams),t.meta.arg)},onFulfilled:(e,t)=>{e.rolesList.data=t.payload}},H((e=>e.rolesList))),Y={action:Q,reducer:X},_=O("roles/update",((e,{extra:{api:t}})=>t.role.update(e))),ee=A(_)({onFulfilled:(e,t)=>{const i=e.rolesList.data.findIndex((e=>e.name===t.payload.oldName));-1!==i&&(e.rolesList.data[i]=t.payload)}},H((e=>e.updateRole)),Z({getSuccessMsg:()=>"Role updated successfully",getErrorMsg:e=>{var t;return`\n <div>\n <div>Failed to update role</div>\n ${null===(t=e.error)||void 0===t?void 0:t.message}\n </div>`}})),te={action:_,reducer:ee},ie=O("tenant/getTenantPermissions",((e,{extra:{api:t}})=>t.tenant.getTenantPermissions())),oe={action:ie,reducer:A(ie)({onFulfilled:(e,t)=>{e.tenantPermissions.data=t.payload.permissions}},H((e=>e.tenantPermissions)))},se={rolesList:{data:[],loading:!1,error:null},createRole:{loading:!1,error:null},updateRole:{loading:!1,error:null},deleteRole:{loading:!1,error:null},tenantPermissions:{loading:!1,error:null,data:[]},searchParams:{text:"",sort:[]},selectedRolesIds:[],notifications:[]},ne={search:"/v1/mgmt/role/search",deleteBatch:"/v1/mgmt/role/delete/batch",create:"/v1/mgmt/role/create",update:"/v1/mgmt/role/update"},ae={permissions:"/v1/mgmt/permission/all"},re=e=>a(void 0,void 0,void 0,(function*(){const t=yield e.text(),i=JSON.parse(t);if(!e.ok){const t=`${i.errorDescription}${i.errorMessage?`: ${i.errorMessage}`:""}`;throw Error(t||`${e.status} ${e.statusText}`)}e.json=()=>Promise.resolve(i),e.text=()=>Promise.resolve(t)})),le=({text:e,sort:t},i)=>a(void 0,void 0,void 0,(function*(){return new Promise((o=>{const s=[];for(let e=1;e<10;e+=1)s.push({name:`Role ${e}`,description:`Role description ${e}`,permissionNames:[`Permission ${e}`],createdTime:new Date,tenantId:i});t.forEach((e=>{s.sort(((t,i)=>{var o,s;return e.desc?null===(s=i[e.field])||void 0===s?void 0:s.localeCompare(t[e.field]):null===(o=t[e.field])||void 0===o?void 0:o.localeCompare(i[e.field])}))})),o(s.filter((t=>t.name.toLowerCase().includes(e.toLowerCase())||t.description.toLowerCase().includes(e.toLowerCase()))))}))})),de=({name:e,description:t,permissionNames:i},o)=>a(void 0,void 0,void 0,(function*(){return new Promise((s=>{s({name:e,description:t,permissionNames:i,createdTime:new Date,tenantId:o})}))})),ce=({name:e,newName:t,description:i,permissionNames:o},s)=>a(void 0,void 0,void 0,(function*(){return new Promise((n=>{n({name:t,description:i,permissionNames:o,createdTime:new Date,oldName:e,tenantId:s})}))})),ue=()=>a(void 0,void 0,void 0,(function*(){})),he=()=>new Promise((e=>{const t=[];for(let e=1;e<5;e+=1)t.push({name:`Permission ${e}`});e({permissions:t})})),ge=({httpClient:e,tenant:t,mock:i})=>({search:({page:o,limit:s=1e4,text:n,sort:r}={})=>a(void 0,void 0,void 0,(function*(){if(i)return le({page:o,limit:s,text:n,sort:r},t);const a=yield e.post(ne.search,{limit:s,page:o,text:n,sort:r},{queryParams:{tenant:t}});yield re(a);return(yield a.json()).roles})),deleteBatch:o=>a(void 0,void 0,void 0,(function*(){if(i)return ue();const s=yield e.post(ne.deleteBatch,{roleNames:o},{queryParams:{tenant:t}});return yield re(s),s.json()})),create:({name:o,description:s,permissionNames:n})=>a(void 0,void 0,void 0,(function*(){if(i)return de({name:o,description:s,permissionNames:n},t);const a=yield e.post(ne.create,{name:o,description:s,permissionNames:n,tenantId:t},{queryParams:{tenant:t}});yield re(a);return yield a.json()})),update:({name:o,newName:s,description:n,permissionNames:r})=>a(void 0,void 0,void 0,(function*(){if(i)return ce({name:o,newName:s,description:n,permissionNames:r},t);const a=yield e.post(ne.update,{name:o,newName:s,description:n,permissionNames:r,tenantId:t},{queryParams:{tenant:t}});yield re(a);const l=yield a.json();return l.oldName=o,l}))}),ve=({httpClient:e,tenant:t,mock:i})=>({getTenantPermissions:()=>a(void 0,void 0,void 0,(function*(){if(i)return he();const o=yield e.get(ae.permissions,{queryParams:{tenant:t}});return yield re(o),o.json()}))}),me=t((e=>{var t,o,s,n;const d=i(c,u,h,g,v({tenant:v.missingAttrValidator}))(e);return n=class extends d{constructor(){super(...arguments),t.add(this),o.set(this,void 0)}get tenant(){return this.getAttribute("tenant")}get widgetId(){return this.getAttribute("widget-id")}get mock(){return this.getAttribute("mock")}get api(){return r(this,o,"f")||r(this,t,"m",s).call(this),r(this,o,"f")}init(){const e=Object.create(null,{init:{get:()=>super.init}});var i;return a(this,void 0,void 0,(function*(){yield null===(i=e.init)||void 0===i?void 0:i.call(this),this.observeAttributes(["project-id","base-url","tenant"],(()=>{r(this,o,"f")&&r(this,t,"m",s).call(this)}))}))}},o=new WeakMap,t=new WeakSet,s=function(){this.logger.debug("creating an sdk instance"),l(this,o,((e,t,i,o)=>{const s=I(Object.assign(Object.assign({},e),{persistTokens:!0,baseHeaders:{"x-descope-widget-type":"role-management-widget","x-descope-widget-id":o,"x-descope-widget-version":"0.1.105"}}));return{role:ge({httpClient:s.httpClient,tenant:t,mock:i}),tenant:ve({httpClient:s.httpClient,tenant:t,mock:i})}})({projectId:this.projectId,baseUrl:this.baseUrl},this.tenant,"true"===this.mock,this.widgetId),"f")},n})),pe=t((e=>{const t=i(m({name:"widget",initialState:se,reducers:{setSelectedRolesIds:(e,{payload:t})=>{e.selectedRolesIds=t},clearNotifications:e=>{e.notifications=[]}},extraReducers:e=>{z.reducer(e),te.reducer(e),K.reducer(e),Y.reducer(e),oe.reducer(e)},asyncActions:{searchRoles:Y.action,createRole:z.action,updateRole:te.action,deleteRoles:K.action,getTenantPermissions:oe.action}}),p,h,me)(e);return class extends t{constructor(...e){super(...e),this.state=se,this.subscribe((e=>{this.logger.debug("State update:",e),this.state=e}))}}})),Re=t((e=>{const t=i(R,v({"widget-id":v.missingAttrValidator}))(e);return class extends t{get widgetId(){return this.getAttribute("widget-id")}fetchWidgetPage(e){return a(this,void 0,void 0,(function*(){return(yield this.fetchStaticResource(`role-management-widget/${this.widgetId}/${e}`,"text")).body}))}}})),fe=t((e=>{var t,s,n;return n=class extends(i(h,p,f,y,Re,pe)(e)){constructor(){super(...arguments),t.add(this)}onWidgetRootReady(){return a(this,void 0,void 0,(function*(){}))}init(){const e=Object.create(null,{init:{get:()=>super.init}});var i;return a(this,void 0,void 0,(function*(){yield null===(i=e.init)||void 0===i?void 0:i.call(this),yield Promise.all([r(this,t,"m",s).call(this),this.actions.searchRoles(),this.actions.getTenantPermissions()]),this.onWidgetRootReady()}))}},t=new WeakSet,s=function(){return a(this,void 0,void 0,(function*(){const e=o(yield this.fetchWidgetPage("root.html"));yield this.loadDescopeUiComponents(e),this.contentRootElement.append(e.content.cloneNode(!0))}))},n})),ye=t((e=>{var t,s,n,d,c;return c=class extends(i(pe,w,b,h,fe)(e)){constructor(){super(...arguments),t.add(this),s.set(this,void 0),d.set(this,(()=>a(this,void 0,void 0,(function*(){var e;yield r(this,s,"f").setData(null===(e=$(this.state))||void 0===e?void 0:e.map((({name:e})=>({value:e,label:e}))))}))))}onWidgetRootReady(){const e=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});var i;return a(this,void 0,void 0,(function*(){yield null===(i=e.onWidgetRootReady)||void 0===i?void 0:i.call(this),r(this,t,"m",n).call(this)}))}},s=new WeakMap,d=new WeakMap,t=new WeakSet,n=function(){return a(this,void 0,void 0,(function*(){this.createRoleModal=this.createModal(),this.createRoleModal.setContent(o(yield this.fetchWidgetPage("create-role-modal.html")));const e=new k((()=>{var e;return null===(e=this.createRoleModal.ele)||void 0===e?void 0:e.querySelector('[data-id="modal-cancel"]')}),{logger:this.logger});e.onClick((()=>{this.createRoleModal.close(),this.resetFormData(this.createRoleModal.ele)}));const t=new k((()=>{var e;return null===(e=this.createRoleModal.ele)||void 0===e?void 0:e.querySelector('[data-id="modal-submit"]')}),{logger:this.logger});t.onClick((()=>a(this,void 0,void 0,(function*(){this.validateForm(this.createRoleModal.ele)&&(this.actions.createRole(Object.assign({},this.getFormData(this.createRoleModal.ele))),this.createRoleModal.close(),this.resetFormData(this.createRoleModal.ele))})))),l(this,s,new x((()=>{var e;return null===(e=this.createRoleModal.ele)||void 0===e?void 0:e.querySelector('[data-id="permissions-multiselect"]')}),{logger:this.logger}),"f"),r(this,d,"f").call(this)}))},c})),we=t((e=>{var t,o,s;return s=class extends(i(h,ye,fe)(e)){constructor(){super(...arguments),t.add(this)}onWidgetRootReady(){const e=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});var i;return a(this,void 0,void 0,(function*(){yield null===(i=e.onWidgetRootReady)||void 0===i?void 0:i.call(this),r(this,t,"m",o).call(this)}))}},t=new WeakSet,o=function(){var e;this.createButton=new k(null===(e=this.shadowRoot)||void 0===e?void 0:e.querySelector('[data-id="create-role"]'),{logger:this.logger}),this.createButton.onClick((()=>this.createRoleModal.open()))},s})),be=t((e=>{var t,s,n;return n=class extends(i(pe,w,h,fe)(e)){constructor(){super(...arguments),t.add(this)}onWidgetRootReady(){const e=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});var i;return a(this,void 0,void 0,(function*(){yield null===(i=e.onWidgetRootReady)||void 0===i?void 0:i.call(this),yield r(this,t,"m",s).call(this)}))}},t=new WeakSet,s=function(){var e;return a(this,void 0,void 0,(function*(){this.deleteRolesModal=this.createModal(),this.deleteRolesModal.setContent(o(yield this.fetchWidgetPage("delete-roles-modal.html")));const t=new k((()=>{var e;return null===(e=this.deleteRolesModal.ele)||void 0===e?void 0:e.querySelector('[data-id="modal-cancel"]')}),{logger:this.logger});t.onClick((()=>this.deleteRolesModal.close()));const i=new k((()=>{var e;return null===(e=this.deleteRolesModal.ele)||void 0===e?void 0:e.querySelector('[data-id="modal-submit"]')}),{logger:this.logger});i.onClick((()=>{const e=B(this.state);this.actions.deleteRoles(null==e?void 0:e.map((e=>e.name))),this.deleteRolesModal.close()}));const s=new S(null===(e=this.deleteRolesModal.ele)||void 0===e?void 0:e.querySelector('[data-id="body-text"]'),{logger:this.logger});this.deleteRolesModal.beforeOpen=()=>{const e=E(this.state);s.text=`Delete ${e}?`}}))},n})),Me=t((e=>{var t,o,n,l;return l=class extends(i(h,fe,pe,be)(e)){constructor(){super(...arguments),t.add(this),n.set(this,s((e=>{e?this.deleteButton.enable():this.deleteButton.disable()})))}onWidgetRootReady(){const e=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});var i;return a(this,void 0,void 0,(function*(){yield null===(i=e.onWidgetRootReady)||void 0===i?void 0:i.call(this),r(this,t,"m",o).call(this),this.subscribe(r(this,n,"f").bind(this),D)}))}},n=new WeakMap,t=new WeakSet,o=function(){var e;this.deleteButton=new k(null===(e=this.shadowRoot)||void 0===e?void 0:e.querySelector('[data-id="delete-roles"]'),{logger:this.logger}),this.deleteButton.disable(),this.deleteButton.onClick((()=>{this.deleteRolesModal.open()}))},l})),Ce=t((e=>{var t,s,n,c,u,g,v,m;return m=class extends(i(pe,w,h,b,fe)(e)){constructor(){super(...arguments),t.add(this),s.set(this,void 0),u.set(this,(()=>a(this,void 0,void 0,(function*(){var e;yield r(this,s,"f").setData(null===(e=$(this.state))||void 0===e?void 0:e.map((({name:e})=>({value:e,label:e}))))})))),g.set(this,(()=>{var e;const t=null===(e=B(this.state))||void 0===e?void 0:e[0],i={name:null==t?void 0:t.name,description:null==t?void 0:t.description,permissionNames:null==t?void 0:t.permissionNames};this.setFormData(this.editRoleModal.ele,i)}))}onWidgetRootReady(){const e=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});var i;return a(this,void 0,void 0,(function*(){yield null===(i=e.onWidgetRootReady)||void 0===i?void 0:i.call(this),yield r(this,t,"m",v).call(this)}))}},s=new WeakMap,u=new WeakMap,g=new WeakMap,t=new WeakSet,n=function(){const e=new k((()=>{var e;return null===(e=this.editRoleModal.ele)||void 0===e?void 0:e.querySelector('[data-id="modal-cancel"]')}),{logger:this.logger});e.onClick((()=>this.editRoleModal.close()))},c=function(){const e=new k((()=>{var e;return null===(e=this.editRoleModal.ele)||void 0===e?void 0:e.querySelector('[data-id="modal-submit"]')}),{logger:this.logger});e.onClick((()=>{var e;if(this.validateForm(this.editRoleModal.ele)){const t=this.getFormData(this.editRoleModal.ele),{name:i}=t,o=d(t,["name"]),s=null===(e=B(this.state))||void 0===e?void 0:e[0];this.actions.updateRole(Object.assign({newName:i,name:s.name},o)),this.editRoleModal.close(),this.resetFormData(this.editRoleModal.ele)}}))},v=function(){return a(this,void 0,void 0,(function*(){this.editRoleModal=this.createModal(),this.editRoleModal.setContent(o(yield this.fetchWidgetPage("edit-role-modal.html"))),r(this,t,"m",n).call(this),r(this,t,"m",c).call(this),l(this,s,new x((()=>{var e;return null===(e=this.editRoleModal.ele)||void 0===e?void 0:e.querySelector('[data-id="permissions-multiselect"]')}),{logger:this.logger}),"f"),this.editRoleModal.beforeOpen=()=>a(this,void 0,void 0,(function*(){yield r(this,u,"f").call(this),r(this,g,"f").call(this)}))}))},m})),We=t((e=>{var t,o,n,l;return l=class extends(i(h,fe,pe,Ce,b)(e)){constructor(){super(...arguments),t.add(this),n.set(this,s((e=>{e?this.editButton.enable():this.editButton.disable()})))}onWidgetRootReady(){const e=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});var i;return a(this,void 0,void 0,(function*(){yield null===(i=e.onWidgetRootReady)||void 0===i?void 0:i.call(this),r(this,t,"m",o).call(this),this.subscribe(r(this,n,"f").bind(this),T)}))}},n=new WeakMap,t=new WeakSet,o=function(){var e;this.editButton=new k(null===(e=this.shadowRoot)||void 0===e?void 0:e.querySelector('[data-id="edit-role"]'),{logger:this.logger}),this.editButton.disable(),this.editButton.onClick((()=>{this.editRoleModal.open()}))},l})),ke=t((e=>{var t,o,s,l;return l=class extends(i(h,fe,pe)(e)){constructor(){super(...arguments),t.add(this),o.set(this,n((()=>{this.actions.searchRoles({text:this.searchInput.value})})))}onWidgetRootReady(){const e=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});var i;return a(this,void 0,void 0,(function*(){yield null===(i=e.onWidgetRootReady)||void 0===i?void 0:i.call(this),r(this,t,"m",s).call(this)}))}},o=new WeakMap,t=new WeakSet,s=function(){var e;this.searchInput=new j(null===(e=this.shadowRoot)||void 0===e?void 0:e.querySelector('[data-id="search-input"]'),{logger:this.logger}),this.searchInput.onInput(r(this,o,"f"))},l}));const xe={success:(new DOMParser).parseFromString('<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">\n<g id="Checkmark">\n<path id="Shape" d="M10.0485 15.6396C9.5799 15.171 8.8201 15.171 8.35147 15.6396C7.88284 16.1082 7.88284 16.868 8.35147 17.3367L12.7072 21.6924C13.1759 22.1611 13.9357 22.1611 14.4043 21.6924L24.7152 11.3815C25.1838 10.9129 25.1838 10.1531 24.7152 9.68448C24.2466 9.21585 23.4868 9.21585 23.0181 9.68448L13.5558 19.1469L10.0485 15.6396Z" fill="currentcolor"/>\n</g>\n</svg>\n',"image/svg+xml").firstChild,error:(new DOMParser).parseFromString('<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">\n<g id="Icon">\n<path id="Vector" d="M15.9998 26.6558C10.1118 26.6558 5.34375 21.8878 5.34375 15.9998C5.34375 10.1118 10.1118 5.34375 15.9998 5.34375C21.8878 5.34375 26.6558 10.1118 26.6558 15.9998C26.6558 21.8878 21.8878 26.6558 15.9998 26.6558ZM15.9998 24.4798C20.6718 24.4798 24.4798 20.7038 24.4798 15.9998C24.4798 11.3278 20.7038 7.51975 15.9998 7.51975C11.3278 7.51975 7.51975 11.2958 7.51975 15.9998C7.51975 20.6718 11.2958 24.4798 15.9998 24.4798ZM15.3278 9.34375H16.6718C17.0558 9.34375 17.3438 9.63175 17.3118 9.98375L16.9598 16.9278C16.9598 17.1838 16.7678 17.3438 16.5438 17.3438H15.4558C15.2318 17.3438 15.0398 17.1518 15.0398 16.9278L14.6878 9.98375C14.6878 9.63175 14.9758 9.34375 15.3278 9.34375ZM15.4558 19.4558H16.5438C16.9278 19.4558 17.2158 19.7438 17.1838 20.1278V21.1838C17.1838 21.5678 16.8958 21.8558 16.5438 21.8558H15.4558C15.0718 21.8558 14.7838 21.5678 14.7838 21.1838V20.1278C14.7838 19.7438 15.0718 19.4558 15.4558 19.4558Z" fill="currentcolor"/>\n</g>\n</svg>\n',"image/svg+xml").firstChild},Se=t((e=>{var t,o,n,l,d;return d=class extends(i(h,pe,M,p)(e)){constructor(){super(...arguments),t.add(this),l.set(this,s((e=>{e.length&&(e.forEach((({type:e,msg:i})=>{const s=r(this,t,"m",n).call(this,e);s.setContent(r(this,t,"m",o).call(this,{type:e,msg:i})),s.show()})),setTimeout((()=>this.actions.clearNotifications())))})))}init(){const e=Object.create(null,{init:{get:()=>super.init}});var t;return a(this,void 0,void 0,(function*(){yield null===(t=e.init)||void 0===t?void 0:t.call(this),this.subscribe(r(this,l,"f").bind(this),F)}))}},l=new WeakMap,t=new WeakSet,o=function({type:e,msg:t}){const i=xe[e],o=Object.assign((new DOMParser).parseFromString('<svg width="2em" height="2em" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n<g id="Icon">\n<path id="Shape" d="M10.6712 12L7.27521 8.60406C6.90826 8.23711 6.90826 7.64216 7.27521 7.27521C7.64216 6.90826 8.23711 6.90826 8.60406 7.27521L12 10.6712L15.3959 7.27521C15.7629 6.90826 16.3578 6.90826 16.7248 7.27521C17.0917 7.64216 17.0917 8.23711 16.7248 8.60406L13.3288 12L16.7248 15.3959C17.0917 15.7629 17.0917 16.3578 16.7248 16.7248C16.3578 17.0917 15.7629 17.0917 15.3959 16.7248L12 13.3288L8.60406 16.7248C8.23711 17.0917 7.64216 17.0917 7.27521 16.7248C6.90826 16.3578 6.90826 15.7629 7.27521 15.3959L10.6712 12Z" fill="currentcolor"/>\n</g>\n</svg>\n',"image/svg+xml").firstChild,{slot:"close"});return`${(null==i?void 0:i.outerHTML)||""}${t}${o.outerHTML}`},n=function(e){return this.createNotification({mode:e,duration:"error"===e?0:3e3,position:"bottom-start",size:"sm"})},d})),je=t((e=>{var t,o,l,d,c;return c=class extends(i(pe,h,fe)(e)){constructor(){super(...arguments),t.add(this),l.set(this,s((e=>{this.rolesTable.data=e}))),d.set(this,n(((e,t)=>{const i=[],{value:o}=t;if(o){const t=e.path;i.push({field:t,desc:"desc"===o})}this.actions.searchRoles({sort:i})})))}onWidgetRootReady(){const e=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});var i;return a(this,void 0,void 0,(function*(){yield null===(i=e.onWidgetRootReady)||void 0===i?void 0:i.call(this),r(this,t,"m",o).call(this),this.rolesTable.columns.forEach((e=>{e.onSortDirectionChange((e=>{r(this,d,"f").call(this,e.target,e.detail)}))})),r(this,l,"f").call(this,q(this.state)),this.subscribe(r(this,l,"f").bind(this),q)}))}},l=new WeakMap,d=new WeakMap,t=new WeakSet,o=function(){var e;this.rolesTable=new P(null===(e=this.shadowRoot)||void 0===e?void 0:e.querySelector('[data-id="roles-table"]'),{logger:this.logger}),this.rolesTable.onSelectedItemsChange((e=>{this.actions.setSelectedRolesIds(e.detail.value.map((({name:e})=>e)))}))},c})),Pe=t((e=>class extends(i(C,W,je,we,Me,We,ke,Se)(e)){init(){const e=Object.create(null,{init:{get:()=>super.init}});var t;return a(this,void 0,void 0,(function*(){yield null===(t=e.init)||void 0===t?void 0:t.call(this)}))}})),Le=i((e=>class extends(Pe(e)){}))(HTMLElement);customElements.define("descope-role-management-widget",Le);export{Le as default};
import{pluralize as e,createSingletonMixin as t,compose as i,createTemplate as o,withMemCache as s,debounce as n}from"@descope/sdk-helpers";import{__awaiter as a,__classPrivateFieldGet as r,__classPrivateFieldSet as l,__rest as d}from"tslib";import{projectIdMixin as c,observeAttributesMixin as u,loggerMixin as h,baseUrlMixin as g,createValidateAttributesMixin as v,createStateManagementMixin as m,initLifecycleMixin as p,staticResourcesMixin as R,descopeUiMixin as f,initElementMixin as y,modalMixin as w,formMixin as b,notificationsMixin as M,debuggerMixin as C,themeMixin as W}from"@descope/sdk-mixins";import{ButtonDriver as k,MultiSelectDriver as x,TextDriver as S,TextFieldDriver as j,GridDriver as P}from"@descope/sdk-component-drivers";import{createSelector as L}from"reselect";import{createAsyncThunk as O}from"@reduxjs/toolkit";import I from"@descope/web-js-sdk";const N=e=>e.selectedRolesIds,F=e=>e.notifications,$=e=>e.tenantPermissions.data||[],q=L((e=>e.rolesList.data),(e=>e.map((e=>{var t;return Object.assign(Object.assign({},e),{editable:0===(null===(t=null==e?void 0:e.tenantId)||void 0===t?void 0:t.length)?"no":"yes"})})))),B=L(N,q,((e,t)=>t.filter((t=>e.includes(t.name))))),D=L(N,(e=>!!e.length)),T=L(N,(e=>1===e.length)),E=L(B,(e=>1===e.length?e[0].name:`${e.length} roles`)),A=e=>(...t)=>i=>{i.addCase(e.pending,((e,i)=>{t.forEach((({onPending:t})=>{null==t||t(e,i)}))})),i.addCase(e.fulfilled,((e,i)=>{t.forEach((({onFulfilled:t})=>{null==t||t(e,i)}))})),i.addCase(e.rejected,((e,i)=>{t.forEach((({onRejected:t})=>{null==t||t(e,i)}))}))},H=e=>({onFulfilled:t=>{e(t).loading=!1},onPending:t=>{e(t).loading=!0,e(t).error=null},onRejected:(t,i)=>{e(t).loading=!1,e(t).error=i.error}}),Z=({getErrorMsg:e,getSuccessMsg:t})=>({onFulfilled:(e,i)=>{t&&e.notifications.push({type:"success",msg:t(i)})},onRejected:(t,i)=>{e&&t.notifications.push({type:"error",msg:e(i)})}}),V=O("roles/create",((e,{extra:{api:t}})=>t.role.create(e))),U=A(V)({onFulfilled:(e,t)=>{e.rolesList.data.unshift(t.payload)}},H((e=>e.createRole)),Z({getSuccessMsg:()=>"Role created successfully",getErrorMsg:e=>{var t;return`\n <div>\n <div>Failed to create role</div>\n ${null===(t=e.error)||void 0===t?void 0:t.message}\n </div>`}})),z={action:V,reducer:U},J=O("roles/delete",((e,{extra:{api:t}})=>t.role.deleteBatch(e))),G=A(J)({onFulfilled:(e,t)=>{e.rolesList.data=e.rolesList.data.filter((e=>{var i;return 0===(null===(i=null==e?void 0:e.tenantId)||void 0===i?void 0:i.length)||!t.meta.arg.includes(e.name)})),e.selectedRolesIds=[]}},H((e=>e.deleteRole)),Z({getSuccessMsg:t=>e(t.meta.arg.length)`${["",t.meta.arg.length]} ${["R","r"]}ole${["","s"]} deleted successfully`,getErrorMsg:t=>e(t.meta.arg.length)`Failed to delete role${["","s"]}`})),K={action:J,reducer:G},Q=O("roles/search",((e,{extra:{api:t},getState:i})=>{const o=i().searchParams;return t.role.search(Object.assign(Object.assign({},o),e))})),X=A(Q)({onPending:(e,t)=>{e.searchParams=Object.assign(Object.assign({},e.searchParams),t.meta.arg)},onFulfilled:(e,t)=>{e.rolesList.data=t.payload}},H((e=>e.rolesList))),Y={action:Q,reducer:X},_=O("roles/update",((e,{extra:{api:t}})=>t.role.update(e))),ee=A(_)({onFulfilled:(e,t)=>{const i=e.rolesList.data.findIndex((e=>e.name===t.payload.oldName));-1!==i&&(e.rolesList.data[i]=t.payload)}},H((e=>e.updateRole)),Z({getSuccessMsg:()=>"Role updated successfully",getErrorMsg:e=>{var t;return`\n <div>\n <div>Failed to update role</div>\n ${null===(t=e.error)||void 0===t?void 0:t.message}\n </div>`}})),te={action:_,reducer:ee},ie=O("tenant/getTenantPermissions",((e,{extra:{api:t}})=>t.tenant.getTenantPermissions())),oe={action:ie,reducer:A(ie)({onFulfilled:(e,t)=>{e.tenantPermissions.data=t.payload.permissions}},H((e=>e.tenantPermissions)))},se={rolesList:{data:[],loading:!1,error:null},createRole:{loading:!1,error:null},updateRole:{loading:!1,error:null},deleteRole:{loading:!1,error:null},tenantPermissions:{loading:!1,error:null,data:[]},searchParams:{text:"",sort:[]},selectedRolesIds:[],notifications:[]},ne={search:"/v1/mgmt/role/search",deleteBatch:"/v1/mgmt/role/delete/batch",create:"/v1/mgmt/role/create",update:"/v1/mgmt/role/update"},ae={permissions:"/v1/mgmt/permission/all"},re=e=>a(void 0,void 0,void 0,(function*(){const t=yield e.text(),i=JSON.parse(t);if(!e.ok){const t=`${i.errorDescription}${i.errorMessage?`: ${i.errorMessage}`:""}`;throw Error(t||`${e.status} ${e.statusText}`)}e.json=()=>Promise.resolve(i),e.text=()=>Promise.resolve(t)})),le=({text:e,sort:t},i)=>a(void 0,void 0,void 0,(function*(){return new Promise((o=>{const s=[];for(let e=1;e<10;e+=1)s.push({name:`Role ${e}`,description:`Role description ${e}`,permissionNames:[`Permission ${e}`],createdTime:new Date,tenantId:i});t.forEach((e=>{s.sort(((t,i)=>{var o,s;return e.desc?null===(s=i[e.field])||void 0===s?void 0:s.localeCompare(t[e.field]):null===(o=t[e.field])||void 0===o?void 0:o.localeCompare(i[e.field])}))})),o(s.filter((t=>t.name.toLowerCase().includes(e.toLowerCase())||t.description.toLowerCase().includes(e.toLowerCase()))))}))})),de=({name:e,description:t,permissionNames:i},o)=>a(void 0,void 0,void 0,(function*(){return new Promise((s=>{s({name:e,description:t,permissionNames:i,createdTime:new Date,tenantId:o})}))})),ce=({name:e,newName:t,description:i,permissionNames:o},s)=>a(void 0,void 0,void 0,(function*(){return new Promise((n=>{n({name:t,description:i,permissionNames:o,createdTime:new Date,oldName:e,tenantId:s})}))})),ue=()=>a(void 0,void 0,void 0,(function*(){})),he=()=>new Promise((e=>{const t=[];for(let e=1;e<5;e+=1)t.push({name:`Permission ${e}`});e({permissions:t})})),ge=({httpClient:e,tenant:t,mock:i})=>({search:({page:o,limit:s=1e4,text:n,sort:r}={})=>a(void 0,void 0,void 0,(function*(){if(i)return le({page:o,limit:s,text:n,sort:r},t);const a=yield e.post(ne.search,{limit:s,page:o,text:n,sort:r},{queryParams:{tenant:t}});yield re(a);return(yield a.json()).roles})),deleteBatch:o=>a(void 0,void 0,void 0,(function*(){if(i)return ue();const s=yield e.post(ne.deleteBatch,{roleNames:o},{queryParams:{tenant:t}});return yield re(s),s.json()})),create:({name:o,description:s,permissionNames:n})=>a(void 0,void 0,void 0,(function*(){if(i)return de({name:o,description:s,permissionNames:n},t);const a=yield e.post(ne.create,{name:o,description:s,permissionNames:n,tenantId:t},{queryParams:{tenant:t}});yield re(a);return yield a.json()})),update:({name:o,newName:s,description:n,permissionNames:r})=>a(void 0,void 0,void 0,(function*(){if(i)return ce({name:o,newName:s,description:n,permissionNames:r},t);const a=yield e.post(ne.update,{name:o,newName:s,description:n,permissionNames:r,tenantId:t},{queryParams:{tenant:t}});yield re(a);const l=yield a.json();return l.oldName=o,l}))}),ve=({httpClient:e,tenant:t,mock:i})=>({getTenantPermissions:()=>a(void 0,void 0,void 0,(function*(){if(i)return he();const o=yield e.get(ae.permissions,{queryParams:{tenant:t}});return yield re(o),o.json()}))}),me=t((e=>{var t,o,s,n;const d=i(c,u,h,g,v({tenant:v.missingAttrValidator}))(e);return n=class extends d{constructor(){super(...arguments),t.add(this),o.set(this,void 0)}get tenant(){return this.getAttribute("tenant")}get widgetId(){return this.getAttribute("widget-id")}get mock(){return this.getAttribute("mock")}get api(){return r(this,o,"f")||r(this,t,"m",s).call(this),r(this,o,"f")}init(){const e=Object.create(null,{init:{get:()=>super.init}});var i;return a(this,void 0,void 0,(function*(){yield null===(i=e.init)||void 0===i?void 0:i.call(this),this.observeAttributes(["project-id","base-url","tenant"],(()=>{r(this,o,"f")&&r(this,t,"m",s).call(this)}))}))}},o=new WeakMap,t=new WeakSet,s=function(){this.logger.debug("creating an sdk instance"),l(this,o,((e,t,i,o)=>{const s=I(Object.assign(Object.assign({},e),{persistTokens:!0,baseHeaders:{"x-descope-widget-type":"role-management-widget","x-descope-widget-id":o,"x-descope-widget-version":"0.1.106"}}));return{role:ge({httpClient:s.httpClient,tenant:t,mock:i}),tenant:ve({httpClient:s.httpClient,tenant:t,mock:i})}})({projectId:this.projectId,baseUrl:this.baseUrl},this.tenant,"true"===this.mock,this.widgetId),"f")},n})),pe=t((e=>{const t=i(m({name:"widget",initialState:se,reducers:{setSelectedRolesIds:(e,{payload:t})=>{e.selectedRolesIds=t},clearNotifications:e=>{e.notifications=[]}},extraReducers:e=>{z.reducer(e),te.reducer(e),K.reducer(e),Y.reducer(e),oe.reducer(e)},asyncActions:{searchRoles:Y.action,createRole:z.action,updateRole:te.action,deleteRoles:K.action,getTenantPermissions:oe.action}}),p,h,me)(e);return class extends t{constructor(...e){super(...e),this.state=se,this.subscribe((e=>{this.logger.debug("State update:",e),this.state=e}))}}})),Re=t((e=>{const t=i(R,v({"widget-id":v.missingAttrValidator}))(e);return class extends t{get widgetId(){return this.getAttribute("widget-id")}fetchWidgetPage(e){return a(this,void 0,void 0,(function*(){return(yield this.fetchStaticResource(`role-management-widget/${this.widgetId}/${e}`,"text")).body}))}}})),fe=t((e=>{var t,s,n;return n=class extends(i(h,p,f,y,Re,pe)(e)){constructor(){super(...arguments),t.add(this)}onWidgetRootReady(){return a(this,void 0,void 0,(function*(){}))}init(){const e=Object.create(null,{init:{get:()=>super.init}});var i;return a(this,void 0,void 0,(function*(){yield null===(i=e.init)||void 0===i?void 0:i.call(this),yield Promise.all([r(this,t,"m",s).call(this),this.actions.searchRoles(),this.actions.getTenantPermissions()]),this.onWidgetRootReady()}))}},t=new WeakSet,s=function(){return a(this,void 0,void 0,(function*(){const e=o(yield this.fetchWidgetPage("root.html"));yield this.loadDescopeUiComponents(e),this.contentRootElement.append(e.content.cloneNode(!0))}))},n})),ye=t((e=>{var t,s,n,d,c;return c=class extends(i(pe,w,b,h,fe)(e)){constructor(){super(...arguments),t.add(this),s.set(this,void 0),d.set(this,(()=>a(this,void 0,void 0,(function*(){var e;yield r(this,s,"f").setData(null===(e=$(this.state))||void 0===e?void 0:e.map((({name:e})=>({value:e,label:e}))))}))))}onWidgetRootReady(){const e=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});var i;return a(this,void 0,void 0,(function*(){yield null===(i=e.onWidgetRootReady)||void 0===i?void 0:i.call(this),r(this,t,"m",n).call(this)}))}},s=new WeakMap,d=new WeakMap,t=new WeakSet,n=function(){return a(this,void 0,void 0,(function*(){this.createRoleModal=this.createModal(),this.createRoleModal.setContent(o(yield this.fetchWidgetPage("create-role-modal.html")));const e=new k((()=>{var e;return null===(e=this.createRoleModal.ele)||void 0===e?void 0:e.querySelector('[data-id="modal-cancel"]')}),{logger:this.logger});e.onClick((()=>{this.createRoleModal.close(),this.resetFormData(this.createRoleModal.ele)}));const t=new k((()=>{var e;return null===(e=this.createRoleModal.ele)||void 0===e?void 0:e.querySelector('[data-id="modal-submit"]')}),{logger:this.logger});t.onClick((()=>a(this,void 0,void 0,(function*(){this.validateForm(this.createRoleModal.ele)&&(this.actions.createRole(Object.assign({},this.getFormData(this.createRoleModal.ele))),this.createRoleModal.close(),this.resetFormData(this.createRoleModal.ele))})))),l(this,s,new x((()=>{var e;return null===(e=this.createRoleModal.ele)||void 0===e?void 0:e.querySelector('[data-id="permissions-multiselect"]')}),{logger:this.logger}),"f"),r(this,d,"f").call(this)}))},c})),we=t((e=>{var t,o,s;return s=class extends(i(h,ye,fe)(e)){constructor(){super(...arguments),t.add(this)}onWidgetRootReady(){const e=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});var i;return a(this,void 0,void 0,(function*(){yield null===(i=e.onWidgetRootReady)||void 0===i?void 0:i.call(this),r(this,t,"m",o).call(this)}))}},t=new WeakSet,o=function(){var e;this.createButton=new k(null===(e=this.shadowRoot)||void 0===e?void 0:e.querySelector('[data-id="create-role"]'),{logger:this.logger}),this.createButton.onClick((()=>this.createRoleModal.open()))},s})),be=t((e=>{var t,s,n;return n=class extends(i(pe,w,h,fe)(e)){constructor(){super(...arguments),t.add(this)}onWidgetRootReady(){const e=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});var i;return a(this,void 0,void 0,(function*(){yield null===(i=e.onWidgetRootReady)||void 0===i?void 0:i.call(this),yield r(this,t,"m",s).call(this)}))}},t=new WeakSet,s=function(){var e;return a(this,void 0,void 0,(function*(){this.deleteRolesModal=this.createModal(),this.deleteRolesModal.setContent(o(yield this.fetchWidgetPage("delete-roles-modal.html")));const t=new k((()=>{var e;return null===(e=this.deleteRolesModal.ele)||void 0===e?void 0:e.querySelector('[data-id="modal-cancel"]')}),{logger:this.logger});t.onClick((()=>this.deleteRolesModal.close()));const i=new k((()=>{var e;return null===(e=this.deleteRolesModal.ele)||void 0===e?void 0:e.querySelector('[data-id="modal-submit"]')}),{logger:this.logger});i.onClick((()=>{const e=B(this.state);this.actions.deleteRoles(null==e?void 0:e.map((e=>e.name))),this.deleteRolesModal.close()}));const s=new S(null===(e=this.deleteRolesModal.ele)||void 0===e?void 0:e.querySelector('[data-id="body-text"]'),{logger:this.logger});this.deleteRolesModal.beforeOpen=()=>{const e=E(this.state);s.text=`Delete ${e}?`}}))},n})),Me=t((e=>{var t,o,n,l;return l=class extends(i(h,fe,pe,be)(e)){constructor(){super(...arguments),t.add(this),n.set(this,s((e=>{e?this.deleteButton.enable():this.deleteButton.disable()})))}onWidgetRootReady(){const e=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});var i;return a(this,void 0,void 0,(function*(){yield null===(i=e.onWidgetRootReady)||void 0===i?void 0:i.call(this),r(this,t,"m",o).call(this),this.subscribe(r(this,n,"f").bind(this),D)}))}},n=new WeakMap,t=new WeakSet,o=function(){var e;this.deleteButton=new k(null===(e=this.shadowRoot)||void 0===e?void 0:e.querySelector('[data-id="delete-roles"]'),{logger:this.logger}),this.deleteButton.disable(),this.deleteButton.onClick((()=>{this.deleteRolesModal.open()}))},l})),Ce=t((e=>{var t,s,n,c,u,g,v,m;return m=class extends(i(pe,w,h,b,fe)(e)){constructor(){super(...arguments),t.add(this),s.set(this,void 0),u.set(this,(()=>a(this,void 0,void 0,(function*(){var e;yield r(this,s,"f").setData(null===(e=$(this.state))||void 0===e?void 0:e.map((({name:e})=>({value:e,label:e}))))})))),g.set(this,(()=>{var e;const t=null===(e=B(this.state))||void 0===e?void 0:e[0],i={name:null==t?void 0:t.name,description:null==t?void 0:t.description,permissionNames:null==t?void 0:t.permissionNames};this.setFormData(this.editRoleModal.ele,i)}))}onWidgetRootReady(){const e=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});var i;return a(this,void 0,void 0,(function*(){yield null===(i=e.onWidgetRootReady)||void 0===i?void 0:i.call(this),yield r(this,t,"m",v).call(this)}))}},s=new WeakMap,u=new WeakMap,g=new WeakMap,t=new WeakSet,n=function(){const e=new k((()=>{var e;return null===(e=this.editRoleModal.ele)||void 0===e?void 0:e.querySelector('[data-id="modal-cancel"]')}),{logger:this.logger});e.onClick((()=>this.editRoleModal.close()))},c=function(){const e=new k((()=>{var e;return null===(e=this.editRoleModal.ele)||void 0===e?void 0:e.querySelector('[data-id="modal-submit"]')}),{logger:this.logger});e.onClick((()=>{var e;if(this.validateForm(this.editRoleModal.ele)){const t=this.getFormData(this.editRoleModal.ele),{name:i}=t,o=d(t,["name"]),s=null===(e=B(this.state))||void 0===e?void 0:e[0];this.actions.updateRole(Object.assign({newName:i,name:s.name},o)),this.editRoleModal.close(),this.resetFormData(this.editRoleModal.ele)}}))},v=function(){return a(this,void 0,void 0,(function*(){this.editRoleModal=this.createModal(),this.editRoleModal.setContent(o(yield this.fetchWidgetPage("edit-role-modal.html"))),r(this,t,"m",n).call(this),r(this,t,"m",c).call(this),l(this,s,new x((()=>{var e;return null===(e=this.editRoleModal.ele)||void 0===e?void 0:e.querySelector('[data-id="permissions-multiselect"]')}),{logger:this.logger}),"f"),this.editRoleModal.beforeOpen=()=>a(this,void 0,void 0,(function*(){yield r(this,u,"f").call(this),r(this,g,"f").call(this)}))}))},m})),We=t((e=>{var t,o,n,l;return l=class extends(i(h,fe,pe,Ce,b)(e)){constructor(){super(...arguments),t.add(this),n.set(this,s((e=>{e?this.editButton.enable():this.editButton.disable()})))}onWidgetRootReady(){const e=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});var i;return a(this,void 0,void 0,(function*(){yield null===(i=e.onWidgetRootReady)||void 0===i?void 0:i.call(this),r(this,t,"m",o).call(this),this.subscribe(r(this,n,"f").bind(this),T)}))}},n=new WeakMap,t=new WeakSet,o=function(){var e;this.editButton=new k(null===(e=this.shadowRoot)||void 0===e?void 0:e.querySelector('[data-id="edit-role"]'),{logger:this.logger}),this.editButton.disable(),this.editButton.onClick((()=>{this.editRoleModal.open()}))},l})),ke=t((e=>{var t,o,s,l;return l=class extends(i(h,fe,pe)(e)){constructor(){super(...arguments),t.add(this),o.set(this,n((()=>{this.actions.searchRoles({text:this.searchInput.value})})))}onWidgetRootReady(){const e=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});var i;return a(this,void 0,void 0,(function*(){yield null===(i=e.onWidgetRootReady)||void 0===i?void 0:i.call(this),r(this,t,"m",s).call(this)}))}},o=new WeakMap,t=new WeakSet,s=function(){var e;this.searchInput=new j(null===(e=this.shadowRoot)||void 0===e?void 0:e.querySelector('[data-id="search-input"]'),{logger:this.logger}),this.searchInput.onInput(r(this,o,"f"))},l}));const xe={success:(new DOMParser).parseFromString('<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">\n<g id="Checkmark">\n<path id="Shape" d="M10.0485 15.6396C9.5799 15.171 8.8201 15.171 8.35147 15.6396C7.88284 16.1082 7.88284 16.868 8.35147 17.3367L12.7072 21.6924C13.1759 22.1611 13.9357 22.1611 14.4043 21.6924L24.7152 11.3815C25.1838 10.9129 25.1838 10.1531 24.7152 9.68448C24.2466 9.21585 23.4868 9.21585 23.0181 9.68448L13.5558 19.1469L10.0485 15.6396Z" fill="currentcolor"/>\n</g>\n</svg>\n',"image/svg+xml").firstChild,error:(new DOMParser).parseFromString('<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">\n<g id="Icon">\n<path id="Vector" d="M15.9998 26.6558C10.1118 26.6558 5.34375 21.8878 5.34375 15.9998C5.34375 10.1118 10.1118 5.34375 15.9998 5.34375C21.8878 5.34375 26.6558 10.1118 26.6558 15.9998C26.6558 21.8878 21.8878 26.6558 15.9998 26.6558ZM15.9998 24.4798C20.6718 24.4798 24.4798 20.7038 24.4798 15.9998C24.4798 11.3278 20.7038 7.51975 15.9998 7.51975C11.3278 7.51975 7.51975 11.2958 7.51975 15.9998C7.51975 20.6718 11.2958 24.4798 15.9998 24.4798ZM15.3278 9.34375H16.6718C17.0558 9.34375 17.3438 9.63175 17.3118 9.98375L16.9598 16.9278C16.9598 17.1838 16.7678 17.3438 16.5438 17.3438H15.4558C15.2318 17.3438 15.0398 17.1518 15.0398 16.9278L14.6878 9.98375C14.6878 9.63175 14.9758 9.34375 15.3278 9.34375ZM15.4558 19.4558H16.5438C16.9278 19.4558 17.2158 19.7438 17.1838 20.1278V21.1838C17.1838 21.5678 16.8958 21.8558 16.5438 21.8558H15.4558C15.0718 21.8558 14.7838 21.5678 14.7838 21.1838V20.1278C14.7838 19.7438 15.0718 19.4558 15.4558 19.4558Z" fill="currentcolor"/>\n</g>\n</svg>\n',"image/svg+xml").firstChild},Se=t((e=>{var t,o,n,l,d;return d=class extends(i(h,pe,M,p)(e)){constructor(){super(...arguments),t.add(this),l.set(this,s((e=>{e.length&&(e.forEach((({type:e,msg:i})=>{const s=r(this,t,"m",n).call(this,e);s.setContent(r(this,t,"m",o).call(this,{type:e,msg:i})),s.show()})),setTimeout((()=>this.actions.clearNotifications())))})))}init(){const e=Object.create(null,{init:{get:()=>super.init}});var t;return a(this,void 0,void 0,(function*(){yield null===(t=e.init)||void 0===t?void 0:t.call(this),this.subscribe(r(this,l,"f").bind(this),F)}))}},l=new WeakMap,t=new WeakSet,o=function({type:e,msg:t}){const i=xe[e],o=Object.assign((new DOMParser).parseFromString('<svg width="2em" height="2em" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n<g id="Icon">\n<path id="Shape" d="M10.6712 12L7.27521 8.60406C6.90826 8.23711 6.90826 7.64216 7.27521 7.27521C7.64216 6.90826 8.23711 6.90826 8.60406 7.27521L12 10.6712L15.3959 7.27521C15.7629 6.90826 16.3578 6.90826 16.7248 7.27521C17.0917 7.64216 17.0917 8.23711 16.7248 8.60406L13.3288 12L16.7248 15.3959C17.0917 15.7629 17.0917 16.3578 16.7248 16.7248C16.3578 17.0917 15.7629 17.0917 15.3959 16.7248L12 13.3288L8.60406 16.7248C8.23711 17.0917 7.64216 17.0917 7.27521 16.7248C6.90826 16.3578 6.90826 15.7629 7.27521 15.3959L10.6712 12Z" fill="currentcolor"/>\n</g>\n</svg>\n',"image/svg+xml").firstChild,{slot:"close"});return`${(null==i?void 0:i.outerHTML)||""}${t}${o.outerHTML}`},n=function(e){return this.createNotification({mode:e,duration:"error"===e?0:3e3,position:"bottom-start",size:"sm"})},d})),je=t((e=>{var t,o,l,d,c;return c=class extends(i(pe,h,fe)(e)){constructor(){super(...arguments),t.add(this),l.set(this,s((e=>{this.rolesTable.data=e}))),d.set(this,n(((e,t)=>{const i=[],{value:o}=t;if(o){const t=e.path;i.push({field:t,desc:"desc"===o})}this.actions.searchRoles({sort:i})})))}onWidgetRootReady(){const e=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});var i;return a(this,void 0,void 0,(function*(){yield null===(i=e.onWidgetRootReady)||void 0===i?void 0:i.call(this),r(this,t,"m",o).call(this),this.rolesTable.columns.forEach((e=>{e.onSortDirectionChange((e=>{r(this,d,"f").call(this,e.target,e.detail)}))})),r(this,l,"f").call(this,q(this.state)),this.subscribe(r(this,l,"f").bind(this),q)}))}},l=new WeakMap,d=new WeakMap,t=new WeakSet,o=function(){var e;this.rolesTable=new P(null===(e=this.shadowRoot)||void 0===e?void 0:e.querySelector('[data-id="roles-table"]'),{logger:this.logger}),this.rolesTable.onSelectedItemsChange((e=>{this.actions.setSelectedRolesIds(e.detail.value.map((({name:e})=>e)))}))},c})),Pe=t((e=>class extends(i(C,W,je,we,Me,We,ke,Se)(e)){init(){const e=Object.create(null,{init:{get:()=>super.init}});var t;return a(this,void 0,void 0,(function*(){yield null===(t=e.init)||void 0===t?void 0:t.call(this)}))}})),Le=i((e=>class extends(Pe(e)){}))(HTMLElement);customElements.define("descope-role-management-widget",Le);export{Le as default};
//# sourceMappingURL=index.js.map
{
"name": "@descope/role-management-widget",
"version": "0.1.105",
"version": "0.1.106",
"author": "Descope Team <info@descope.com>",

@@ -33,3 +33,3 @@ "homepage": "https://github.com/descope/descope-js",

"@types/jest": "^29.0.0",
"@types/node": "20.14.2",
"@types/node": "20.14.5",
"@types/testing-library__jest-dom": "5.14.9",

@@ -80,6 +80,6 @@ "dotenv": "^16.0.3",

"immer": "^10.0.3",
"@descope/web-js-sdk": "1.15.2",
"@descope/sdk-mixins": "0.2.37",
"@descope/sdk-helpers": "0.1.52",
"@descope/sdk-component-drivers": "0.2.33"
"@descope/sdk-helpers": "0.1.53",
"@descope/sdk-component-drivers": "0.2.34",
"@descope/web-js-sdk": "1.15.3",
"@descope/sdk-mixins": "0.2.38"
},

@@ -86,0 +86,0 @@ "overrides": {

@@ -21,3 +21,4 @@ # @descope/role-management-widget

```
<script src="https://cdn.jsdelivr.net/npm/@descope/role-management-widget/dist/index.js"></script>
// replace x.x.x with the latest release of the widget: https://www.npmjs.com/package/@descope/role-management-widget
<script src="https://static.descope.com/npm/@descope/role-management-widget@x.x.x/dist/index.js"></script>
<descope-role-management-widget

@@ -89,8 +90,2 @@ base-url="<DESCOPE_BASE_URL>"

### UI Components
Widget UI is composed of [`@descope/web-components-ui`](https://github.com/descope/web-components-ui), which is loaded during the widget init in runtime.
For optimization, we load only the relevant components, defined on the widget screens DOM.
## Dev

@@ -101,11 +96,1 @@

Since screen are fetched dynamically, when developing a new screen for the widget you will probably want to use mock templates. To do so, simply replace the call to `fetchWidgetPage` with a string which includes your HTML.
### Use local components
In some cases you want to make changes to components anf see how it affects the widget. To do so, you need to build [`web-components-ui`](https://github.com/descope/web-components-ui) and serve the `dist` folder from your machine (with `npx serve` or other util).
Add the key `base.ui.components.url` to your localStorage and set its value to the URL of the served dist `umd/index.js` file.
###
Pay attention that _theme changes_ will not take affect until the components

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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc