├── .eslintignore ├── .eslintrc.js ├── .github └── workflows │ └── ci.yml ├── .gitignore ├── .npmignore ├── .prettierrc ├── LICENSE ├── README.md ├── jestconfig.json ├── lib ├── index.d.ts ├── index.js ├── install.d.ts ├── install.js ├── useAuthorizer.d.ts └── useAuthorizer.js ├── package.json ├── src ├── __test__ │ ├── examples │ │ ├── abac_with_obj_rule_model.conf │ │ ├── abac_with_obj_rule_policy.csv │ │ ├── basic_model.conf │ │ ├── basic_policy.csv │ │ ├── rbac_model.conf │ │ ├── rbac_policy.csv │ │ ├── rbac_with_domains_model.conf │ │ └── rbac_with_domains_policy.csv │ ├── index.test.ts │ └── util.ts ├── index.ts ├── install.ts ├── useAuthorizer.ts └── webpack-dev-server-template.html ├── tsconfig.json ├── webpack.base.js ├── webpack.dev.js ├── webpack.prod.js └── yarn.lock /.eslintignore: -------------------------------------------------------------------------------- 1 | # don't ever lint node_modules 2 | node_modules 3 | # don't lint build output (make sure it's set to your correct build folder name) 4 | lib 5 | dist 6 | example -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | parser: '@typescript-eslint/parser', 4 | plugins: [ 5 | '@typescript-eslint', 6 | ], 7 | env: { 8 | "browser": true, 9 | "node": true 10 | }, 11 | extends: [ 12 | 'eslint:recommended', 13 | 'plugin:@typescript-eslint/recommended', 14 | 'prettier' 15 | ], 16 | rules: { 17 | '@typescript-eslint/no-var-requires': 0, 18 | '@typescript-eslint/explicit-module-boundary-types': 0, 19 | '@typescript-eslint/no-unused-vars': 0, 20 | 'no-useless-catch': 0, 21 | 'no-multiple-empty-lines': ["error", { "max": 2, "maxEOF": 1 }], 22 | "no-trailing-spaces": ["error", {"skipBlankLines": true}], 23 | "require-await": 2, 24 | } 25 | }; -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: [ push, pull_request ] 4 | 5 | jobs: 6 | build-and-test: 7 | runs-on: ubuntu-latest 8 | strategy: 9 | fail-fast: false 10 | matrix: 11 | node-version: [ ^12, ^14, ^16 ] 12 | steps: 13 | - uses: actions/checkout@v3 14 | - uses: actions/setup-node@v2 15 | with: 16 | node-version: ${{ matrix.node-version }} 17 | 18 | - run: yarn install 19 | - run: yarn lint 20 | - run: yarn test 21 | - run: yarn coverage 22 | - run: yarn build 23 | 24 | - name: Codecov 25 | uses: codecov/codecov-action@v1 26 | 27 | semantic-release: 28 | needs: [ build-and-test ] 29 | runs-on: ubuntu-latest 30 | steps: 31 | - uses: actions/checkout@v3 32 | - name: Run semantic-release 33 | if: github.repository == 'casbin-js/vue-authz' && github.event_name == 'push' 34 | run: yarn install && yarn semantic-release 35 | env: 36 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 37 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### Windows template 3 | # Windows thumbnail cache files 4 | Thumbs.db 5 | Thumbs.db:encryptable 6 | ehthumbs.db 7 | ehthumbs_vista.db 8 | 9 | # Dump file 10 | *.stackdump 11 | 12 | # Folder config file 13 | [Dd]esktop.ini 14 | 15 | # Recycle Bin used on file shares 16 | $RECYCLE.BIN/ 17 | 18 | # Windows Installer files 19 | *.cab 20 | *.msi 21 | *.msix 22 | *.msm 23 | *.msp 24 | 25 | # Windows shortcuts 26 | *.lnk 27 | 28 | ### JetBrains template 29 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider 30 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 31 | 32 | # User-specific stuff 33 | .idea/**/workspace.xml 34 | .idea/**/tasks.xml 35 | .idea/**/usage.statistics.xml 36 | .idea/**/dictionaries 37 | .idea/**/shelf 38 | 39 | # Generated files 40 | .idea/**/contentModel.xml 41 | 42 | # Sensitive or high-churn files 43 | .idea/**/dataSources/ 44 | .idea/**/dataSources.ids 45 | .idea/**/dataSources.local.xml 46 | .idea/**/sqlDataSources.xml 47 | .idea/**/dynamic.xml 48 | .idea/**/uiDesigner.xml 49 | .idea/**/dbnavigator.xml 50 | 51 | # Gradle 52 | .idea/**/gradle.xml 53 | .idea/**/libraries 54 | 55 | # Gradle and Maven with auto-import 56 | # When using Gradle or Maven with auto-import, you should exclude module files, 57 | # since they will be recreated, and may cause churn. Uncomment if using 58 | # auto-import. 59 | # .idea/artifacts 60 | # .idea/compiler.xml 61 | # .idea/jarRepositories.xml 62 | # .idea/modules.xml 63 | # .idea/*.iml 64 | # .idea/modules 65 | # *.iml 66 | # *.ipr 67 | 68 | # CMake 69 | cmake-build-*/ 70 | 71 | # Mongo Explorer plugin 72 | .idea/**/mongoSettings.xml 73 | 74 | # File-based project format 75 | *.iws 76 | 77 | # IntelliJ 78 | out/ 79 | 80 | # mpeltonen/sbt-idea plugin 81 | .idea_modules/ 82 | 83 | # JIRA plugin 84 | atlassian-ide-plugin.xml 85 | 86 | # Cursive Clojure plugin 87 | .idea/replstate.xml 88 | 89 | # Crashlytics plugin (for Android Studio and IntelliJ) 90 | com_crashlytics_export_strings.xml 91 | crashlytics.properties 92 | crashlytics-build.properties 93 | fabric.properties 94 | 95 | # Editor-based Rest Client 96 | .idea/httpRequests 97 | 98 | # Android studio 3.1+ serialized cache file 99 | .idea/caches/build_file_checksums.ser 100 | 101 | ### Node template 102 | # Logs 103 | logs 104 | *.log 105 | npm-debug.log* 106 | yarn-debug.log* 107 | yarn-error.log* 108 | lerna-debug.log* 109 | 110 | # Diagnostic reports (https://nodejs.org/api/report.html) 111 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 112 | 113 | # Runtime data 114 | pids 115 | *.pid 116 | *.seed 117 | *.pid.lock 118 | 119 | # Directory for instrumented libs generated by jscoverage/JSCover 120 | lib-cov 121 | 122 | # Coverage directory used by tools like istanbul 123 | coverage 124 | *.lcov 125 | 126 | # nyc test coverage 127 | .nyc_output 128 | 129 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 130 | .grunt 131 | 132 | # Bower dependency directory (https://bower.io/) 133 | bower_components 134 | 135 | # node-waf configuration 136 | .lock-wscript 137 | 138 | # Compiled binary addons (https://nodejs.org/api/addons.html) 139 | build/Release 140 | 141 | # Dependency directories 142 | node_modules/ 143 | jspm_packages/ 144 | 145 | # Snowpack dependency directory (https://snowpack.dev/) 146 | web_modules/ 147 | 148 | # TypeScript cache 149 | *.tsbuildinfo 150 | 151 | # Optional npm cache directory 152 | .npm 153 | 154 | # Optional eslint cache 155 | .eslintcache 156 | 157 | # Microbundle cache 158 | .rpt2_cache/ 159 | .rts2_cache_cjs/ 160 | .rts2_cache_es/ 161 | .rts2_cache_umd/ 162 | 163 | # Optional REPL history 164 | .node_repl_history 165 | 166 | # Output of 'npm pack' 167 | *.tgz 168 | 169 | # Yarn Integrity file 170 | .yarn-integrity 171 | 172 | # dotenv environment variables file 173 | .env 174 | .env.test 175 | 176 | # parcel-bundler cache (https://parceljs.org/) 177 | .cache 178 | .parcel-cache 179 | 180 | # Next.js build output 181 | .next 182 | out 183 | 184 | # Nuxt.js build / generate output 185 | .nuxt 186 | dist 187 | 188 | # Gatsby files 189 | .cache/ 190 | # Comment in the public line in if your project uses Gatsby and not Next.js 191 | # https://nextjs.org/blog/next-9-1#public-directory-support 192 | # public 193 | 194 | # vuepress build output 195 | .vuepress/dist 196 | 197 | # Serverless directories 198 | .serverless/ 199 | 200 | # FuseBox cache 201 | .fusebox/ 202 | 203 | # DynamoDB Local files 204 | .dynamodb/ 205 | 206 | # TernJS port file 207 | .tern-port 208 | 209 | # Stores VSCode versions used for testing VSCode extensions 210 | .vscode-test 211 | 212 | # yarn v2 213 | .yarn/cache 214 | .yarn/unplugged 215 | .yarn/build-state.yml 216 | .yarn/install-state.gz 217 | .pnp.* 218 | 219 | ### Example user template template 220 | ### Example user template 221 | 222 | # IntelliJ project files 223 | .idea 224 | *.iml 225 | gen 226 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | node_modules/ 3 | 4 | # Src and test suites 5 | src/ 6 | 7 | # Other extensions 8 | extensions/ 9 | 10 | .idea/ 11 | package-lock.json 12 | yarn.lock 13 | 14 | # webpack configurations 15 | webpack.* 16 | 17 | npm-debug.log -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "semi": true, 3 | "singleQuote": true, 4 | "printWidth": 140, 5 | "tabWidth": 4 6 | } 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vue-authz 2 | 3 | [![NPM version][npm-image]][npm-url] 4 | [![NPM download][download-image]][download-url] 5 | [![CI](https://github.com/casbin-js/vue-authz/actions/workflows/ci.yml/badge.svg)](https://github.com/casbin-js/vue-authz/actions/workflows/ci.yml) 6 | [![Coverage Status](https://codecov.io/gh/casbin-js/vue-authz/branch/master/graph/badge.svg)](https://codecov.io/gh/casbin-js/vue-authz?branch=master) 7 | 8 | [npm-image]: https://img.shields.io/npm/v/vue-authz.svg?style=flat-square 9 | [npm-url]: https://www.npmjs.com/package/vue-authz 10 | [download-image]: https://img.shields.io/npm/dm/vue-authz.svg?style=flat-square 11 | [download-url]: https://www.npmjs.com/package/vue-authz 12 | 13 | This package allows you to integrate [Casbin.js](https://github.com/casbin/casbin.js) (An authorization library) with 14 | your Vue 3 application. 15 | 16 | ## Installation 17 | 18 | ```bash 19 | npm install vue-authz 20 | # or 21 | yarn add vue-authz 22 | # or 23 | pnpm add vue-authz 24 | ``` 25 | 26 | ## Getting started 27 | 28 | This package provides a Vue plugin, several hooks for 29 | new [Vue Composition API](https://v3.vuejs.org/guide/composition-api-introduction.html) 30 | 31 | ### The plugin 32 | 33 | ```typescript 34 | import { createApp } from 'vue'; 35 | import CasbinPlugin from 'vue-authz'; 36 | import { Authorizer } from 'casbin.js'; 37 | 38 | const permission = { 39 | "read": ['data1', 'data2'], 40 | "write": ['data1'] 41 | } 42 | 43 | // Run casbin.js in manual mode, which requires you to set the permission manually. 44 | const authorizer = new casbinjs.Authorizer("manual"); 45 | 46 | authorizer.setPermission(permission); 47 | 48 | createApp() 49 | .use(CasbinPlugin, authorizer, { 50 | useGlobalProperties: true 51 | }).mount('#app'); 52 | ``` 53 | 54 | After that, you can use `$authorizer` and `$can` in every component. 55 | 56 | ```vue 57 | 58 | 65 | ``` 66 | 67 | `useGlobalProperties` will mount `$can` and `$authorizer` on every component. Sometimes, you may want to use some other 68 | function as `$can`. In this condition, you can 69 | use [provide/inject API](https://v3.vuejs.org/guide/component-provide-inject.html) in Vue 3 to get the `$authorizer`. 70 | 71 | ```typescript 72 | createApp() 73 | .use(CasbinPlugin, authorizer) 74 | .mount('#app'); 75 | ``` 76 | 77 | And inject it with `AUTHORIZER_KEY` 78 | 79 | ```vue 80 | 81 | 86 | 87 | 96 | ``` 97 | 98 | You can also use `useAuthorizer` function. 99 | 100 | ```vue 101 | 102 | 107 | 108 | 120 | ``` 121 | 122 | ## License 123 | 124 | This project is licensed under the [Apache 2.0 license](LICENSE). 125 | 126 | ## Contact 127 | 128 | If you have any issues or feature requests, please contact us. PR is welcomed. 129 | 130 | - https://github.com/casbin-js/vue-authz/issues 131 | - hsluoyz@gmail.com 132 | - Tencent QQ group: [546057381](//shang.qq.com/wpa/qunwpa?idkey=8ac8b91fc97ace3d383d0035f7aa06f7d670fd8e8d4837347354a31c18fac885) 133 | -------------------------------------------------------------------------------- /jestconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "transform": { 3 | "^.+\\.(t|j)sx?$": "ts-jest" 4 | }, 5 | "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", 6 | "moduleFileExtensions": [ 7 | "ts", 8 | "tsx", 9 | "js", 10 | "jsx", 11 | "json", 12 | "node" 13 | ], 14 | "coveragePathIgnorePatterns": [ 15 | "/node_modules/" 16 | ] 17 | } -------------------------------------------------------------------------------- /lib/index.d.ts: -------------------------------------------------------------------------------- 1 | export { install } from './install'; 2 | export * from './useAuthorizer'; 3 | import { install } from './install'; 4 | export default install; 5 | -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { 3 | if (k2 === undefined) k2 = k; 4 | Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); 5 | }) : (function(o, m, k, k2) { 6 | if (k2 === undefined) k2 = k; 7 | o[k2] = m[k]; 8 | })); 9 | var __exportStar = (this && this.__exportStar) || function(m, exports) { 10 | for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); 11 | }; 12 | Object.defineProperty(exports, "__esModule", { value: true }); 13 | var install_1 = require("./install"); 14 | Object.defineProperty(exports, "install", { enumerable: true, get: function () { return install_1.install; } }); 15 | __exportStar(require("./useAuthorizer"), exports); 16 | var install_2 = require("./install"); 17 | exports.default = install_2.install; 18 | -------------------------------------------------------------------------------- /lib/install.d.ts: -------------------------------------------------------------------------------- 1 | import { App } from 'vue'; 2 | import { Authorizer } from 'casbin.js'; 3 | export interface CasbinPluginOptions { 4 | useGlobalProperties?: boolean; 5 | customProperties?: Array; 6 | } 7 | declare const install: (app: App, authorizer: Authorizer, options?: CasbinPluginOptions) => void; 8 | export { install }; 9 | -------------------------------------------------------------------------------- /lib/install.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | exports.install = void 0; 4 | var casbin_js_1 = require("casbin.js"); 5 | var useAuthorizer_1 = require("./useAuthorizer"); 6 | var install = function (app, authorizer, options) { 7 | var availableProperties = [ 8 | 'getPermission', 9 | 'setPermission', 10 | 'initEnforcer', 11 | 'getEnforcerDataFromSvr', 12 | 'setUser', 13 | 'can', 14 | 'cannot', 15 | 'canAll', 16 | 'canAny', 17 | ]; 18 | app.provide(useAuthorizer_1.AUTHORIZER_KEY, authorizer); 19 | if (!authorizer || !(authorizer instanceof casbin_js_1.Authorizer)) { 20 | throw new Error('Please provide an authorizer instance to plugin.'); 21 | } 22 | if (options) { 23 | // I cannot implement this because of the limitation of Vue. 24 | // If you have any idea, plz tell me. 25 | // 26 | // TODO: add autoload option when Authorizer in 'auto' mode is given. 27 | // 28 | // if (options.autoload) { 29 | // if (authorizer.mode!=='auto'){ 30 | // throw new Error('autoload will only work on auto mode Authorizer. You don\'t need this.') 31 | // } 32 | // 33 | // if (!(options.autoload instanceof String)) { 34 | // throw new Error('autoload option should have argument username:string') 35 | // } 36 | // 37 | // authorizer.setUser(options.autoload) 38 | // } 39 | if (options.useGlobalProperties) { 40 | app.config.globalProperties.$authorizer = authorizer; 41 | if (options.customProperties) { 42 | var targetProperties = availableProperties.filter(function (property) { 43 | return options.customProperties.indexOf(property) !== -1; 44 | }); 45 | targetProperties.forEach(function (propertyStr) { 46 | var property = Object.getOwnPropertyDescriptor(authorizer, "" + propertyStr); 47 | if (property) { 48 | app.config.globalProperties["$" + propertyStr] = property.value; 49 | } 50 | else { 51 | throw new Error('Unexpected Error.'); 52 | } 53 | }); 54 | } 55 | else { 56 | app.config.globalProperties.$can = authorizer.can; 57 | } 58 | } 59 | } 60 | }; 61 | exports.install = install; 62 | -------------------------------------------------------------------------------- /lib/useAuthorizer.d.ts: -------------------------------------------------------------------------------- 1 | import { InjectionKey } from 'vue'; 2 | import { Authorizer } from 'casbin.js'; 3 | declare const AUTHORIZER_KEY: InjectionKey; 4 | declare const useAuthorizer: () => T; 5 | declare const provideAuthorizer: (authorizer: Authorizer) => void; 6 | export { provideAuthorizer, useAuthorizer, AUTHORIZER_KEY }; 7 | -------------------------------------------------------------------------------- /lib/useAuthorizer.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | exports.AUTHORIZER_KEY = exports.useAuthorizer = exports.provideAuthorizer = void 0; 4 | var vue_1 = require("vue"); 5 | var AUTHORIZER_KEY = Symbol('casbinjs_authorizer'); 6 | exports.AUTHORIZER_KEY = AUTHORIZER_KEY; 7 | var useAuthorizer = function () { 8 | var authorizer = vue_1.inject(AUTHORIZER_KEY); 9 | if (!authorizer) { 10 | throw new Error("Cannot inject Authorizer instance because it didn't exist"); 11 | } 12 | return authorizer; 13 | }; 14 | exports.useAuthorizer = useAuthorizer; 15 | var provideAuthorizer = function (authorizer) { 16 | vue_1.provide(AUTHORIZER_KEY, authorizer); 17 | }; 18 | exports.provideAuthorizer = provideAuthorizer; 19 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue-authz", 3 | "version": "0.0.1", 4 | "main": "./lib/index.js", 5 | "types": "./lib/index.d.ts", 6 | "repository": "https://github.com/casbin-js/vue-authz.git", 7 | "author": { 8 | "name": "Zxilly", 9 | "email": "zhouxinyu1001@gmail.com", 10 | "url": "https://learningman.top" 11 | }, 12 | "license": "Apache-2.0", 13 | "scripts": { 14 | "format": "prettier --write 'src/**/*.ts'", 15 | "lint": "yarn eslint . --ext .js,.jsx,.ts,.tsx --fix", 16 | "build": "rimraf lib && tsc", 17 | "test": "jest --config jestconfig.json --unhandled-rejections=strict", 18 | "coverage": "jest --config jestconfig.json --coverage", 19 | "prod": "webpack --config webpack.prod.js", 20 | "dev": "webpack --config webpack.dev.js" 21 | }, 22 | "devDependencies": { 23 | "@babel/plugin-proposal-optional-chaining": "^7.11.0", 24 | "@semantic-release/changelog": "^5.0.1", 25 | "@semantic-release/commit-analyzer": "^8.0.1", 26 | "@semantic-release/git": "^9.0.0", 27 | "@semantic-release/github": "^7.2.3", 28 | "@semantic-release/npm": "^7.1.3", 29 | "@semantic-release/release-notes-generator": "^9.0.3", 30 | "@types/express": "^4.17.6", 31 | "@types/jest": "^25.2.3", 32 | "@types/js-cookie": "^2.2.6", 33 | "@typescript-eslint/eslint-plugin": "^3.2.0", 34 | "@typescript-eslint/parser": "^3.2.0", 35 | "casbin": "^5.18.0", 36 | "clean-webpack-plugin": "^3.0.0", 37 | "eslint": "^7.7.0", 38 | "eslint-config-prettier": "^6.11.0", 39 | "express": "^4.17.1", 40 | "html-webpack-plugin": "^4.3.0", 41 | "jest": "^26.1.0", 42 | "prettier": "^2.0.5", 43 | "rimraf": "^3.0.2", 44 | "semantic-release": "^17.4.4", 45 | "ts-jest": "^26.1.0", 46 | "ts-loader": "^8.0.2", 47 | "tslint-config-prettier": "^1.18.0", 48 | "typescript": "^4.8.3", 49 | "vue": "^3.0.7", 50 | "webpack": "^4.43.0", 51 | "webpack-cli": "^3.3.12", 52 | "webpack-dev-server": "^3.11.0", 53 | "webpack-merge": "^5.0.8" 54 | }, 55 | "dependencies": { 56 | "@babel/core": "^7.11.4", 57 | "@babel/preset-env": "^7.11.0", 58 | "axios": "^0.21.1", 59 | "babel-loader": "^8.1.0", 60 | "casbin.js": "^0.4.1", 61 | "vue-demi": "^0.13.11" 62 | }, 63 | "peerDependencies": { 64 | "@vue/composition-api": "^1.3.0", 65 | "vue": "^2.0.0 || >=3.0.0" 66 | }, 67 | "peerDependenciesMeta": { 68 | "@vue/composition-api": { 69 | "optional": true 70 | } 71 | } 72 | } -------------------------------------------------------------------------------- /src/__test__/examples/abac_with_obj_rule_model.conf: -------------------------------------------------------------------------------- 1 | [request_definition] 2 | r = sub, obj, act 3 | 4 | [policy_definition] 5 | p = sub, obj_rule, act 6 | 7 | [policy_effect] 8 | e = some(where (p.eft == allow)) 9 | 10 | [matchers] 11 | m = eval(p.obj_rule) && r.act == p.act -------------------------------------------------------------------------------- /src/__test__/examples/abac_with_obj_rule_policy.csv: -------------------------------------------------------------------------------- 1 | p, bob, r.sub == r.obj.Creator, write -------------------------------------------------------------------------------- /src/__test__/examples/basic_model.conf: -------------------------------------------------------------------------------- 1 | [request_definition] 2 | r = sub, obj, act 3 | 4 | [policy_definition] 5 | p = sub, obj, act 6 | 7 | [policy_effect] 8 | e = some(where (p.eft == allow)) 9 | 10 | [matchers] 11 | m = r.sub == p.sub && r.obj == p.obj && r.act == p.act 12 | -------------------------------------------------------------------------------- /src/__test__/examples/basic_policy.csv: -------------------------------------------------------------------------------- 1 | p, alice, data1, read 2 | p, alice, data2, read 3 | p, alice, data2, write 4 | p, bob, data2, write -------------------------------------------------------------------------------- /src/__test__/examples/rbac_model.conf: -------------------------------------------------------------------------------- 1 | [request_definition] 2 | r = sub, obj, act 3 | 4 | [policy_definition] 5 | p = sub, obj, act 6 | 7 | [role_definition] 8 | g = _, _ 9 | 10 | [policy_effect] 11 | e = some(where (p.eft == allow)) 12 | 13 | [matchers] 14 | m = g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act -------------------------------------------------------------------------------- /src/__test__/examples/rbac_policy.csv: -------------------------------------------------------------------------------- 1 | p, alice, data1, read 2 | p, bob, data2, write 3 | p, data2_admin, data2, read 4 | p, data2_admin, data2, write 5 | g, alice, data2_admin -------------------------------------------------------------------------------- /src/__test__/examples/rbac_with_domains_model.conf: -------------------------------------------------------------------------------- 1 | [request_definition] 2 | r = sub, dom, obj, act 3 | 4 | [policy_definition] 5 | p = sub, dom, obj, act 6 | 7 | [role_definition] 8 | g = _, _, _ 9 | 10 | [policy_effect] 11 | e = some(where (p.eft == allow)) 12 | 13 | [matchers] 14 | m = g(r.sub, p.sub, r.dom) && r.dom == p.dom && r.obj == p.obj && r.act == p.act -------------------------------------------------------------------------------- /src/__test__/examples/rbac_with_domains_policy.csv: -------------------------------------------------------------------------------- 1 | p, admin, domain1, data1, read 2 | p, admin, domain1, data1, write 3 | p, admin, domain2, data2, read 4 | p, admin, domain2, data2, write 5 | p, alice, domain1, data3, read 6 | 7 | g, alice, admin, domain1 8 | g, bob, admin, domain2 -------------------------------------------------------------------------------- /src/__test__/index.test.ts: -------------------------------------------------------------------------------- 1 | import { Authorizer } from 'casbin.js'; 2 | import { defineComponent, createApp } from 'vue'; 3 | import { AUTHORIZER_KEY, useAuthorizer } from '../useAuthorizer'; 4 | import { basicModelStr } from './util'; 5 | import plugin from '../index'; 6 | 7 | const respData = JSON.stringify({ 8 | m: basicModelStr, 9 | p: [ 10 | ['p', 'alice', 'data1', 'read'], 11 | ['p', 'alice', 'data2', 'write'], 12 | ], 13 | }); 14 | 15 | describe('Enforcer plugin test', () => { 16 | let authorizer; 17 | let vm; 18 | let app; 19 | let appRoot; 20 | 21 | const App = defineComponent({ 22 | // eslint-disable-next-line @typescript-eslint/ban-ts-comment 23 | // @ts-ignore 24 | inject: { 25 | authorizer: { 26 | // eslint-disable-next-line @typescript-eslint/ban-ts-comment 27 | // @ts-ignore 28 | from: AUTHORIZER_KEY, 29 | }, 30 | }, 31 | render() { 32 | return this.authorizer.can('write', 'data2'); 33 | }, 34 | }); 35 | 36 | beforeEach(async () => { 37 | authorizer = new Authorizer('auto', { endpoint: 'something' }); 38 | await authorizer.initEnforcer(respData); 39 | authorizer.user = 'alice'; 40 | appRoot = window.document.createElement('div'); 41 | }); 42 | 43 | it('Throw Error when authorizer is not provided.', () => { 44 | // eslint-disable-next-line @typescript-eslint/ban-ts-comment 45 | // @ts-ignore 46 | expect(() => createApp().use(plugin)).toThrowError('Please provide an authorizer instance to plugin.'); 47 | }); 48 | 49 | it('Throw Error when fake authorizer is provided.', () => { 50 | // eslint-disable-next-line @typescript-eslint/ban-ts-comment 51 | // @ts-ignore 52 | expect(() => createApp().use(plugin, {})).toThrowError('Please provide an authorizer instance to plugin.'); 53 | }); 54 | 55 | describe('by default', () => { 56 | beforeEach(() => { 57 | app = createApp(App).use(plugin, authorizer); 58 | vm = app.mount(appRoot); 59 | }); 60 | 61 | it('should not have globalProperties', () => { 62 | expect(vm.$authorizer).toBeFalsy(); 63 | expect(vm.$can).toBeFalsy(); 64 | }); 65 | 66 | it('should have authorizer', function () { 67 | expect(vm.authorizer).toEqual(authorizer); 68 | }); 69 | }); 70 | 71 | describe('when use useGlobalProperties option', () => { 72 | beforeEach(() => { 73 | app = createApp(App).use(plugin, authorizer, { 74 | useGlobalProperties: true, 75 | }); 76 | vm = app.mount(appRoot); 77 | }); 78 | 79 | it('should have globalProperties', () => { 80 | expect(vm.$authorizer).toBeDefined(); 81 | expect(vm.$can).toBeDefined(); 82 | }); 83 | 84 | it('should have authorizer', function () { 85 | expect(vm.authorizer).toEqual(authorizer); 86 | }); 87 | }); 88 | 89 | describe('when use customProperties option', () => { 90 | function addCustomApp(apiInNeed: string[]) { 91 | app = createApp(App).use(plugin, authorizer, { 92 | useGlobalProperties: true, 93 | customProperties: apiInNeed, 94 | }); 95 | vm = app.mount(appRoot); 96 | } 97 | 98 | it("should have 'can' and 'cannot'", function () { 99 | addCustomApp(['can', 'cannot']); 100 | 101 | expect(vm.$can).toBeDefined(); 102 | expect(vm.$cannot).toBeDefined(); 103 | expect(vm.$authorizer).toBeDefined(); 104 | }); 105 | 106 | it("should have 'can', 'cannot', 'canAll' and 'canAny'", function () { 107 | addCustomApp(['can', 'cannot', 'canAll', 'canAny']); 108 | 109 | expect(vm.$can).toBeDefined(); 110 | expect(vm.$cannot).toBeDefined(); 111 | expect(vm.$canAll).toBeDefined(); 112 | expect(vm.$canAny).toBeDefined(); 113 | expect(vm.$authorizer).toBeDefined(); 114 | }); 115 | }); 116 | }); 117 | -------------------------------------------------------------------------------- /src/__test__/util.ts: -------------------------------------------------------------------------------- 1 | import { readFileSync } from 'fs'; 2 | 3 | const basicExample = 'src/__test__/examples/basic_model.conf'; 4 | export const basicModelStr = readFileSync(basicExample).toString(); 5 | 6 | const rbacExample = 'src/__test__/examples/rbac_model.conf'; 7 | export const rbacModelStr = readFileSync(rbacExample).toString(); 8 | 9 | const abacWithObjRuleExample = 'src/__test__/examples/abac_with_obj_rule_policy.csv'; 10 | export const abacWithObjRuleModelStr = readFileSync(abacWithObjRuleExample).toString(); 11 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | export { install } from './install'; 2 | export * from './useAuthorizer'; 3 | 4 | import { install } from './install'; 5 | 6 | export default install; 7 | -------------------------------------------------------------------------------- /src/install.ts: -------------------------------------------------------------------------------- 1 | import { Authorizer } from 'casbin.js'; 2 | import { AUTHORIZER_KEY } from './useAuthorizer'; 3 | import { isVue3 } from 'vue-demi'; 4 | 5 | export interface CasbinPluginOptions { 6 | useGlobalProperties?: boolean; 7 | customProperties?: Array; 8 | } 9 | 10 | const install = function (app, authorizer: Authorizer, options?: CasbinPluginOptions) { 11 | const availableProperties = [ 12 | 'getPermission', 13 | 'setPermission', 14 | 'initEnforcer', 15 | 'getEnforcerDataFromSvr', 16 | 'setUser', 17 | 'can', 18 | 'cannot', 19 | 'canAll', 20 | 'canAny', 21 | ]; 22 | 23 | app.provide(AUTHORIZER_KEY, authorizer); 24 | 25 | if (!authorizer || !(authorizer instanceof Authorizer)) { 26 | throw new Error('Please provide an authorizer instance to plugin.'); 27 | } 28 | 29 | if (options) { 30 | // I cannot implement this because of the limitation of Vue. 31 | // If you have any idea, plz tell me. 32 | // 33 | // TODO: add autoload option when Authorizer in 'auto' mode is given. 34 | // 35 | // if (options.autoload) { 36 | // if (authorizer.mode!=='auto'){ 37 | // throw new Error('autoload will only work on auto mode Authorizer. You don\'t need this.') 38 | // } 39 | // 40 | // if (!(options.autoload instanceof String)) { 41 | // throw new Error('autoload option should have argument username:string') 42 | // } 43 | // 44 | // authorizer.setUser(options.autoload) 45 | // } 46 | 47 | if (options.useGlobalProperties) { 48 | const vueProperty = isVue3 ? app.config.globalProperties : app.prototype; 49 | vueProperty.$authorizer = authorizer; 50 | 51 | if (options.customProperties) { 52 | const targetProperties = availableProperties.filter((property: string) => { 53 | return (options.customProperties as string[]).indexOf(property) !== -1; 54 | }); 55 | 56 | targetProperties.forEach((propertyStr: string) => { 57 | 58 | const property = Object.getPrototypeOf(authorizer)[propertyStr] 59 | if (property) { 60 | const propertyKey = `$${propertyStr}` 61 | // app.config.globalProperties[propertyKey] = property; 62 | Object.defineProperty(vueProperty, propertyKey, { 63 | enumerable: true, 64 | configurable: true, 65 | writable: true, 66 | value: property 67 | }) 68 | } else { 69 | throw new Error('Unexpected Error.'); 70 | } 71 | }); 72 | } else { 73 | vueProperty.$can = authorizer.can; 74 | } 75 | } 76 | } 77 | }; 78 | 79 | export { install }; 80 | -------------------------------------------------------------------------------- /src/useAuthorizer.ts: -------------------------------------------------------------------------------- 1 | import { inject, provide, InjectionKey } from 'vue-demi'; 2 | import { Authorizer } from 'casbin.js'; 3 | 4 | const AUTHORIZER_KEY: InjectionKey = Symbol('casbinjs_authorizer'); 5 | 6 | const useAuthorizer = function (): T { 7 | const authorizer = inject(AUTHORIZER_KEY); 8 | 9 | if (!authorizer) { 10 | throw new Error("Cannot inject Authorizer instance because it didn't exist"); 11 | } 12 | 13 | return authorizer; 14 | }; 15 | 16 | const provideAuthorizer = function (authorizer: Authorizer): void { 17 | provide(AUTHORIZER_KEY, authorizer); 18 | }; 19 | 20 | export { provideAuthorizer, useAuthorizer, AUTHORIZER_KEY }; 21 | -------------------------------------------------------------------------------- /src/webpack-dev-server-template.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | <%= htmlWebpackPlugin.options.title %> 6 | 7 | 8 |

This is a webpack development test page.

9 | 10 | 13 | 14 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Visit https://aka.ms/tsconfig.json to read more about this file */ 4 | 5 | /* Basic Options */ 6 | // "incremental": true, /* Enable incremental compilation */ 7 | "target": "es5", 8 | /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ 9 | "module": "commonjs", 10 | /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ 11 | "lib": [ 12 | "es6", 13 | "DOM" 14 | ], 15 | /* Specify library files to be included in the compilation. */ 16 | // "allowJs": true, /* Allow javascript files to be compiled. */ 17 | // "checkJs": true, /* Report errors in .js files. */ 18 | // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ 19 | "declaration": true, 20 | /* Generates corresponding '.d.ts' file. */ 21 | // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ 22 | // "sourceMap": true, /* Generates corresponding '.map' file. */ 23 | // "outFile": "./", /* Concatenate and emit output to single file. */ 24 | "outDir": "./lib", 25 | /* Redirect output structure to the directory. */ 26 | // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ 27 | // "composite": true, /* Enable project compilation */ 28 | // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ 29 | // "removeComments": true, /* Do not emit comments to output. */ 30 | // "noEmit": true, /* Do not emit outputs. */ 31 | // "importHelpers": true, /* Import emit helpers from 'tslib'. */ 32 | // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ 33 | // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ 34 | 35 | /* Strict Type-Checking Options */ 36 | "strict": false, 37 | /* Enable all strict type-checking options. */ 38 | // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ 39 | // "strictNullChecks": true, /* Enable strict null checks. */ 40 | // "strictFunctionTypes": true, /* Enable strict checking of function types. */ 41 | // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ 42 | // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ 43 | // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ 44 | // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ 45 | 46 | /* Additional Checks */ 47 | // "noUnusedLocals": true, /* Report errors on unused locals. */ 48 | // "noUnusedParameters": true, /* Report errors on unused parameters. */ 49 | // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ 50 | // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ 51 | 52 | /* Module Resolution Options */ 53 | // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ 54 | // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ 55 | // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ 56 | // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ 57 | // "typeRoots": [], /* List of folders to include type definitions from. */ 58 | // "types": [], /* Type declaration files to be included in compilation. */ 59 | // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ 60 | "esModuleInterop": true, 61 | /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ 62 | // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ 63 | // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ 64 | 65 | /* Source Map Options */ 66 | // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ 67 | // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ 68 | // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ 69 | // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ 70 | 71 | /* Experimental Options */ 72 | // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ 73 | // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ 74 | 75 | /* Advanced Options */ 76 | "skipLibCheck": true, 77 | /* Skip type checking of declaration files. */ 78 | "forceConsistentCasingInFileNames": true 79 | /* Disallow inconsistently-cased references to the same file. */ 80 | }, 81 | "include": [ 82 | "./src" 83 | ], 84 | "exclude": [ 85 | "node_modules", 86 | "**/__test__/*" 87 | ] 88 | } -------------------------------------------------------------------------------- /webpack.base.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const { CleanWebpackPlugin } = require('clean-webpack-plugin'); 3 | const HtmlWebpackPlugin = require('html-webpack-plugin'); 4 | 5 | 6 | module.exports = { 7 | entry: './src/index.ts', 8 | module: { 9 | rules: [ 10 | { 11 | test: /\.tsx?$/, 12 | use: 'ts-loader', 13 | exclude: /node_modules/, 14 | }, 15 | { 16 | test: /\.jsx?$/, 17 | use: { 18 | loader: 'babel-loader', 19 | options: { 20 | presets: ['@babel/preset-env'], 21 | plugins: ['@babel/plugin-proposal-optional-chaining'] 22 | }, 23 | }, 24 | } 25 | ], 26 | }, 27 | resolve: { 28 | extensions: [ '.tsx', '.ts', '.js' ], 29 | }, 30 | 31 | output: { 32 | library: 'vue-casbin', 33 | libraryTarget: 'module', 34 | filename: 'vue-casbin.js', 35 | path: path.resolve(__dirname, 'dist'), 36 | }, 37 | plugins: [ 38 | new CleanWebpackPlugin() 39 | ] 40 | }; -------------------------------------------------------------------------------- /webpack.dev.js: -------------------------------------------------------------------------------- 1 | const { merge } = require('webpack-merge'); 2 | const HtmlWebpackPlugin = require('html-webpack-plugin'); 3 | const base = require('./webpack.base'); 4 | 5 | module.exports = merge(base, { 6 | mode: 'development', 7 | devtool: 'inline-source-map', 8 | devServer: { 9 | contentBase: './dist', 10 | port: 9001 11 | }, 12 | plugins: [ 13 | new HtmlWebpackPlugin({ 14 | 'title': 'Development', 15 | 'filename': 'index.html', 16 | 'template': './src/webpack-dev-server-template.html', 17 | 'inject': false 18 | }) 19 | ] 20 | 21 | }) -------------------------------------------------------------------------------- /webpack.prod.js: -------------------------------------------------------------------------------- 1 | const { merge } = require('webpack-merge'); 2 | const base = require('./webpack.base'); 3 | module.exports = merge(base, { 4 | mode: 'production' 5 | }) --------------------------------------------------------------------------------