locator-ars-lib 1.0.0 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/locator-ars-lib.es.js +1 -1
- package/dist/locator-ars-lib.umd.js +1 -1
- package/package.json +11 -12
- package/tsconfig.json +1 -0
- package/types/index.d.ts +42 -0
- package/types/locator-ars-lib.d.ts +44 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
var h = Object.defineProperty;
|
2
2
|
var y = (e, s, n) => s in e ? h(e, s, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[s] = n;
|
3
|
-
var o = (e, s, n) =>
|
3
|
+
var o = (e, s, n) => y(e, typeof s != "symbol" ? s + "" : s, n);
|
4
4
|
import { inject as v, ref as l, computed as m, watch as _, onUnmounted as g, defineComponent as k, toRefs as w, renderSlot as u } from "vue";
|
5
5
|
import P from "axios";
|
6
6
|
class S {
|
@@ -1 +1 @@
|
|
1
|
-
(function(n,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("vue"),require("axios")):typeof define=="function"&&define.amd?define(["exports","vue","axios"],i):(n=typeof globalThis<"u"?globalThis:n||self,i(n.LocatorArsLib={},n.Vue,n.axios))})(this,function(n,i,
|
1
|
+
(function(n,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("vue"),require("axios")):typeof define=="function"&&define.amd?define(["exports","vue","axios"],i):(n=typeof globalThis<"u"?globalThis:n||self,i(n.LocatorArsLib={},n.Vue,n.axios))})(this,function(n,i,o){"use strict";var $=Object.defineProperty;var L=(n,i,o)=>i in n?$(n,i,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[i]=o;var u=(n,i,o)=>L(n,typeof i!="symbol"?i+"":i,o);class P{constructor(s){u(this,"axios");u(this,"cache",new Map);u(this,"endpoint");this.axios=o.create({baseURL:(s==null?void 0:s.baseUrl)||""}),this.endpoint=(s==null?void 0:s.endpoint)||"/api/v1/dashboard/access"}async can(s){if(this.cache.has(s))return this.cache.get(s);try{const a=(await this.axios.get(this.endpoint,{params:{action:s}})).data.allowed||!1;return this.cache.set(s,a),a}catch(r){return console.error(`Error checking permission for ${s}:`,r),!1}}clearCache(s){s?this.cache.delete(s):this.cache.clear()}}const p=Symbol("Permissions");function m(e){return new P(e)}const S={install(e,s){const r=m(s);e.provide(p,r)}};function d(){const e=i.inject(p);if(!e)throw new Error("Permissions plugin not installed!");return e}function h(e,s={}){const r=d(),a=i.ref(null),t=i.ref(!1),l=i.ref(null),_=i.computed(()=>typeof e=="string"?e:e.value),f=async()=>{if(_.value){t.value=!0,l.value=null;try{a.value=await r.can(_.value)}catch(c){l.value=c instanceof Error?c:new Error(String(c)),a.value=!1}finally{t.value=!1}}};if(s.autoCheck!==!1&&f(),typeof e!="string"){const c=i.watch(e,()=>{f()});i.onUnmounted(()=>{c()})}return{isAllowed:a,isLoading:t,error:l,check:f,can:i.computed(()=>a.value===!0)}}const g=i.defineComponent({name:"Check",props:{action:{type:String,required:!0},fallback:{type:Boolean,default:!1}},setup(e){const{action:s}=i.toRefs(e),{can:r,isLoading:a}=h(s,{autoCheck:!0});return{can:r,isLoading:a}}}),k=(e,s)=>{const r=e.__vccOpts||e;for(const[a,t]of s)r[a]=t;return r};function w(e,s,r,a,t,l){return e.can?i.renderSlot(e.$slots,"default",{key:0}):e.isLoading?i.renderSlot(e.$slots,"loading",{key:2}):i.renderSlot(e.$slots,"fallback",{key:1})}const y=k(g,[["render",w]]),v={async mounted(e,s){const r=e.style.display;e._permission_data={action:s.value,originalDisplay:r},await d().can(s.value)||(e.style.display="none")},async updated(e,s){(!e._permission_data||e._permission_data.action!==s.value)&&(e._permission_data={action:s.value,originalDisplay:e.style.display||""},await d().can(s.value)?e.style.display=e._permission_data.originalDisplay:e.style.display="none")},unmounted(e){e._permission_data&&(e.style.display=e._permission_data.originalDisplay,delete e._permission_data)}},C={install(e,s){e.use(S,s),e.component("Check",y),e.directive("can",v)}};n.Check=y,n.default=C,n.setupPermissions=m,n.usePermissions=h,n.vCan=v,Object.defineProperties(n,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/package.json
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
{
|
2
2
|
"name": "locator-ars-lib",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.3",
|
4
4
|
"description": "Permissions library for Vue 3 applications",
|
5
5
|
"main": "dist/index.js",
|
6
|
-
"types": "
|
6
|
+
"types": "types/index.d.ts",
|
7
7
|
"scripts": {
|
8
8
|
"build": "vue-tsc && vite build",
|
9
9
|
"test": "vitest run",
|
@@ -18,17 +18,16 @@
|
|
18
18
|
"author": "badkiko",
|
19
19
|
"license": "MIT",
|
20
20
|
"peerDependencies": {
|
21
|
-
"
|
22
|
-
"
|
21
|
+
"vue": "^3.0.0 || ^3.5.0",
|
22
|
+
"axios": "^1.7.9"
|
23
23
|
},
|
24
24
|
"devDependencies": {
|
25
|
-
"@types/node": "^
|
26
|
-
"@vitejs/plugin-vue": "^
|
27
|
-
"
|
28
|
-
"
|
29
|
-
"
|
30
|
-
"
|
31
|
-
"vue": "^3.
|
32
|
-
"vue-tsc": "^1.0.9"
|
25
|
+
"@types/node": "^22.10.5",
|
26
|
+
"@vitejs/plugin-vue": "^5.2.1",
|
27
|
+
"typescript": "~5.6.2",
|
28
|
+
"vite": "^6.0.5",
|
29
|
+
"vue-tsc": "^2.2.0",
|
30
|
+
"axios": "^1.7.9",
|
31
|
+
"vue": "^3.5.13"
|
33
32
|
}
|
34
33
|
}
|
package/tsconfig.json
CHANGED
package/types/index.d.ts
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
import { App, Component, Ref, ComputedRef, ObjectDirective } from 'vue'
|
2
|
+
|
3
|
+
export interface PermissionsOptions {
|
4
|
+
baseUrl?: string
|
5
|
+
endpoint?: string
|
6
|
+
}
|
7
|
+
|
8
|
+
export interface UsePermissionsOptions {
|
9
|
+
autoCheck?: boolean
|
10
|
+
}
|
11
|
+
|
12
|
+
export interface UsePermissionsResult {
|
13
|
+
isAllowed: Ref<boolean | null>
|
14
|
+
isLoading: Ref<boolean>
|
15
|
+
error: Ref<Error | null>
|
16
|
+
check: () => Promise<void>
|
17
|
+
can: ComputedRef<boolean>
|
18
|
+
}
|
19
|
+
|
20
|
+
export class PermissionsService {
|
21
|
+
constructor(options?: PermissionsOptions)
|
22
|
+
can(action: string): Promise<boolean>
|
23
|
+
clearCache(action?: string): void
|
24
|
+
}
|
25
|
+
|
26
|
+
export const Check: Component
|
27
|
+
export const vCan: ObjectDirective
|
28
|
+
|
29
|
+
export function usePermissions(
|
30
|
+
action: string | Ref<string>,
|
31
|
+
options?: UsePermissionsOptions
|
32
|
+
): UsePermissionsResult
|
33
|
+
|
34
|
+
export function setupPermissions(
|
35
|
+
options?: PermissionsOptions
|
36
|
+
): PermissionsService
|
37
|
+
|
38
|
+
declare const _default: {
|
39
|
+
install(app: App, options?: PermissionsOptions): void
|
40
|
+
}
|
41
|
+
|
42
|
+
export default _default
|
@@ -0,0 +1,44 @@
|
|
1
|
+
declare module 'locator-ars-lib' {
|
2
|
+
import { App, Component, Ref, ComputedRef, ObjectDirective } from 'vue'
|
3
|
+
|
4
|
+
export interface PermissionsOptions {
|
5
|
+
baseUrl?: string
|
6
|
+
endpoint?: string
|
7
|
+
}
|
8
|
+
|
9
|
+
export interface UsePermissionsOptions {
|
10
|
+
autoCheck?: boolean
|
11
|
+
}
|
12
|
+
|
13
|
+
export interface UsePermissionsResult {
|
14
|
+
isAllowed: Ref<boolean | null>
|
15
|
+
isLoading: Ref<boolean>
|
16
|
+
error: Ref<Error | null>
|
17
|
+
check: () => Promise<void>
|
18
|
+
can: ComputedRef<boolean>
|
19
|
+
}
|
20
|
+
|
21
|
+
export class PermissionsService {
|
22
|
+
constructor(options?: PermissionsOptions)
|
23
|
+
can(action: string): Promise<boolean>
|
24
|
+
clearCache(action?: string): void
|
25
|
+
}
|
26
|
+
|
27
|
+
export const Check: Component
|
28
|
+
export const vCan: ObjectDirective
|
29
|
+
|
30
|
+
export function usePermissions(
|
31
|
+
action: string | Ref<string>,
|
32
|
+
options?: UsePermissionsOptions
|
33
|
+
): UsePermissionsResult
|
34
|
+
|
35
|
+
export function setupPermissions(
|
36
|
+
options?: PermissionsOptions
|
37
|
+
): PermissionsService
|
38
|
+
|
39
|
+
const plugin: {
|
40
|
+
install(app: App, options?: PermissionsOptions): void
|
41
|
+
}
|
42
|
+
|
43
|
+
export default plugin
|
44
|
+
}
|