├── .editorconfig ├── .gitignore ├── PUBLISH.MD ├── README.MD ├── angular.json ├── package.json ├── projects └── abp-ng2-module │ ├── README.md │ ├── karma.conf.js │ ├── ng-package.json │ ├── package.json │ ├── src │ ├── lib │ │ ├── abp.module.ts │ │ ├── interceptors │ │ │ ├── abp-http-configuration.service.ts │ │ │ ├── abpHttpInterceptor.ts │ │ │ ├── index.ts │ │ │ └── refresh-token.service.ts │ │ ├── models │ │ │ └── index.ts │ │ └── services │ │ │ ├── abp-user-configuration.service.ts │ │ │ ├── auth │ │ │ ├── permission-checker.service.ts │ │ │ └── token.service.ts │ │ │ ├── features │ │ │ └── feature-checker.service.ts │ │ │ ├── index.ts │ │ │ ├── localization │ │ │ └── localization.service.ts │ │ │ ├── log │ │ │ └── log.service.ts │ │ │ ├── message │ │ │ └── message.service.ts │ │ │ ├── multi-tenancy │ │ │ └── abp-multi-tenancy.service.ts │ │ │ ├── notify │ │ │ └── notify.service.ts │ │ │ ├── session │ │ │ └── abp-session.service.ts │ │ │ ├── settings │ │ │ └── setting.service.ts │ │ │ └── utils │ │ │ └── utils.service.ts │ ├── public-api.ts │ └── test.ts │ ├── tsconfig.lib.json │ ├── tsconfig.lib.prod.json │ ├── tsconfig.spec.json │ ├── tslint.json │ └── yarn.lock ├── tsconfig.json ├── tslint.json ├── typings.d.ts └── yarn.lock /.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see https://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | max_line_length = off 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | # Only exists if Bazel was run 8 | /bazel-out 9 | 10 | # dependencies 11 | /node_modules 12 | /projects/abp-ng2-module/node_modules 13 | 14 | # profiling files 15 | chrome-profiler-events*.json 16 | speed-measure-plugin*.json 17 | 18 | # IDEs and editors 19 | /.idea 20 | .project 21 | .classpath 22 | .c9/ 23 | *.launch 24 | .settings/ 25 | *.sublime-workspace 26 | 27 | # IDE - VSCode 28 | .vscode/* 29 | !.vscode/settings.json 30 | !.vscode/tasks.json 31 | !.vscode/launch.json 32 | !.vscode/extensions.json 33 | .history/* 34 | 35 | # misc 36 | /.angular/cache 37 | /.sass-cache 38 | /connect.lock 39 | /coverage 40 | /libpeerconnection.log 41 | npm-debug.log 42 | yarn-error.log 43 | testem.log 44 | /typings 45 | 46 | # System Files 47 | .DS_Store 48 | Thumbs.db 49 | .npmrc 50 | -------------------------------------------------------------------------------- /PUBLISH.MD: -------------------------------------------------------------------------------- 1 | # Publish Package 2 | 3 | 1. Go to root directory and run `ng build abp-ng2-module --configuration production` 4 | 2. Go to `dist\abp-ng2-module` folder 5 | 3. Run `npm publish` -------------------------------------------------------------------------------- /README.MD: -------------------------------------------------------------------------------- 1 | # Important 2 | 3 | Issues of this repository are tracked on https://github.com/aspnetboilerplate/aspnetboilerplate. Please create your issues on https://github.com/aspnetboilerplate/aspnetboilerplate/issues. 4 | 5 | # abp-ng2-module 6 | 7 | ## Installation 8 | 9 | To install this library, run: 10 | 11 | ```bash 12 | $ npm install abp-ng2-module --save 13 | ``` 14 | ## Development 15 | 16 | To generate all `*.js`, `*.js.map` and `*.d.ts` files: 17 | 18 | ```bash 19 | $ ng build abp-ng2-module --configuration=production 20 | ``` 21 | 22 | ## AbpHttpInterceptor 23 | 24 | In order to use AbpHttpInterceptor in your module, first import it and AbpHttpInterceptor into your module like below; 25 | 26 | ```ts 27 | import { AbpModule } from '@abp/abp.module'; 28 | import { AbpHttpInterceptor } from '@abp/abpHttpInterceptor'; 29 | import { HTTP_INTERCEPTORS } from '@angular/common/http'; 30 | ``` 31 | 32 | then, add it to your module providers like below; 33 | 34 | ```ts 35 | imports: [ 36 | ///other imports 37 | ], 38 | providers: [ 39 | ///other providers 40 | { provide: HTTP_INTERCEPTORS, useClass: AbpHttpInterceptor, multi: true } 41 | ] 42 | ``` 43 | 44 | ## License 45 | 46 | MIT -------------------------------------------------------------------------------- /angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "abp-ng2-module": { 7 | "projectType": "library", 8 | "root": "projects/abp-ng2-module", 9 | "sourceRoot": "projects/abp-ng2-module/src", 10 | "prefix": "lib", 11 | "architect": { 12 | "build": { 13 | "builder": "@angular-devkit/build-ng-packagr:build", 14 | "options": { 15 | "tsConfig": "projects/abp-ng2-module/tsconfig.lib.json", 16 | "project": "projects/abp-ng2-module/ng-package.json" 17 | }, 18 | "configurations": { 19 | "production": { 20 | "tsConfig": "projects/abp-ng2-module/tsconfig.lib.prod.json" 21 | } 22 | } 23 | }, 24 | "test": { 25 | "builder": "@angular-devkit/build-angular:karma", 26 | "options": { 27 | "main": "projects/abp-ng2-module/src/test.ts", 28 | "tsConfig": "projects/abp-ng2-module/tsconfig.spec.json", 29 | "karmaConfig": "projects/abp-ng2-module/karma.conf.js" 30 | } 31 | } 32 | } 33 | }}, 34 | "defaultProject": "abp-ng2-module" 35 | } 36 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "abp-ng2-module", 3 | "version": "12.1.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve", 7 | "build": "ng build", 8 | "test": "ng test", 9 | "lint": "ng lint", 10 | "e2e": "ng e2e", 11 | "publish": "ng build abp-ng2-module --configuration production && cd dist && cd abp-ng2-module && npm publish" 12 | }, 13 | "private": false, 14 | "keywords": [ 15 | "angular", 16 | "angular19", 17 | "angular 19", 18 | "aspnetboilerplate" 19 | ], 20 | "author": { 21 | "name": "Halil İbrahim Kalkan", 22 | "email": "hi_kalkan@yahoo.com" 23 | }, 24 | "license": "MIT", 25 | "repository": { 26 | "type": "git", 27 | "url": "https://github.com/aspnetboilerplate/abp-ng2-module" 28 | }, 29 | "bugs": { 30 | "url": "https://github.com/aspnetboilerplate/abp-ng2-module/issues" 31 | }, 32 | "dependencies": { 33 | "@angular/animations": "~19.1.7", 34 | "@angular/common": "~19.1.7", 35 | "@angular/compiler": "~19.1.7", 36 | "@angular/core": "~19.1.7", 37 | "@angular/forms": "~19.1.7", 38 | "@angular/platform-browser": "~19.1.7", 39 | "@angular/platform-browser-dynamic": "~19.1.7", 40 | "@angular/router": "~19.1.7", 41 | "rxjs": "~7.8.2", 42 | "tslib": "^2.8.1", 43 | "zone.js": "~0.15.0", 44 | "abp-web-resources": "6.1.0" 45 | }, 46 | "devDependencies": { 47 | "@angular-devkit/build-angular": "~19.1.8", 48 | "@angular-devkit/build-ng-packagr": "~0.1002.0", 49 | "@angular/cli": "~19.1.8", 50 | "@angular/compiler-cli": "~19.1.7", 51 | "@angular/language-service": "~19.1.7", 52 | "@types/node": "^22.13.5", 53 | "@types/jasmine": "~5.1.7", 54 | "@types/jasminewd2": "~2.0.13", 55 | "codelyzer": "^6.0.2", 56 | "jasmine-core": "~5.6.0", 57 | "jasmine-spec-reporter": "~7.0.0", 58 | "karma": "~6.4.4", 59 | "karma-chrome-launcher": "~3.2.0", 60 | "karma-coverage-istanbul-reporter": "~3.0.3", 61 | "karma-jasmine": "~5.1.0", 62 | "karma-jasmine-html-reporter": "^2.1.0", 63 | "ng-packagr": "^19.1.2", 64 | "protractor": "~7.0.0", 65 | "ts-node": "~10.9.2", 66 | "tslint": "~6.1.3", 67 | "typescript": "~5.7.3" 68 | } 69 | } -------------------------------------------------------------------------------- /projects/abp-ng2-module/README.md: -------------------------------------------------------------------------------- 1 | # AbpNgxLibrary 2 | 3 | This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 9.0.7. 4 | 5 | ## Code scaffolding 6 | 7 | Run `ng generate component component-name --project abp-ng2-module` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project abp-ng2-module`. 8 | > Note: Don't forget to add `--project abp-ng2-module` or else it will be added to the default project in your `angular.json` file. 9 | 10 | ## Build 11 | 12 | Run `ng build abp-ng2-module` to build the project. The build artifacts will be stored in the `dist/` directory. 13 | 14 | ## Publishing 15 | 16 | After building your library with `ng build abp-ng2-module`, go to the dist folder `cd dist/abp-ng2-module` and run `npm publish`. 17 | 18 | ## Running unit tests 19 | 20 | Run `ng test abp-ng2-module` to execute the unit tests via [Karma](https://karma-runner.github.io). 21 | 22 | ## Further help 23 | 24 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md). 25 | -------------------------------------------------------------------------------- /projects/abp-ng2-module/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage-istanbul-reporter'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | dir: require('path').join(__dirname, '../../coverage/abp-ng2-module'), 20 | reports: ['html', 'lcovonly', 'text-summary'], 21 | fixWebpackSourcePaths: true 22 | }, 23 | reporters: ['progress', 'kjhtml'], 24 | port: 9876, 25 | colors: true, 26 | logLevel: config.LOG_INFO, 27 | autoWatch: true, 28 | browsers: ['Chrome'], 29 | singleRun: false, 30 | restartOnFileChange: true 31 | }); 32 | }; 33 | -------------------------------------------------------------------------------- /projects/abp-ng2-module/ng-package.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "../../node_modules/ng-packagr/ng-package.schema.json", 3 | "dest": "../../dist/abp-ng2-module", 4 | "lib": { 5 | "entryFile": "src/public-api.ts" 6 | } 7 | } -------------------------------------------------------------------------------- /projects/abp-ng2-module/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "abp-ng2-module", 3 | "version": "12.1.0", 4 | "keywords": [ 5 | "angular", 6 | "aspnetboilerplate" 7 | ], 8 | "author": { 9 | "name": "Halil İbrahim Kalkan", 10 | "email": "hi_kalkan@yahoo.com" 11 | }, 12 | "license": "MIT", 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/aspnetboilerplate/abp-ng2-module" 16 | }, 17 | "bugs": { 18 | "url": "https://github.com/aspnetboilerplate/abp-ng2-module/issues" 19 | }, 20 | "peerDependencies": { 21 | "@angular/common": "^19.1.7", 22 | "@angular/core": "^19.1.7" 23 | }, 24 | "dependencies": { 25 | "tslib": "^2.8.1" 26 | } 27 | } -------------------------------------------------------------------------------- /projects/abp-ng2-module/src/lib/abp.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | 3 | @NgModule({ 4 | declarations: [], 5 | imports: [ 6 | ], 7 | exports: [] 8 | }) 9 | export class AbpModule { } 10 | -------------------------------------------------------------------------------- /projects/abp-ng2-module/src/lib/interceptors/abp-http-configuration.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { Observable } from 'rxjs'; 3 | import { MessageService } from '../services/message/message.service'; 4 | import { LogService } from '../services/log/log.service'; 5 | import { HttpResponse } from '@angular/common/http'; 6 | import { IErrorInfo, IAjaxResponse } from '../models'; 7 | 8 | @Injectable({ 9 | providedIn: 'root' 10 | }) 11 | export class AbpHttpConfigurationService { 12 | 13 | constructor( 14 | private _messageService: MessageService, 15 | private _logService: LogService) { 16 | } 17 | 18 | forceHeaderCookieWrite = true; 19 | 20 | defaultError = { 21 | message: 'An error has occurred!', 22 | details: 'Error details were not sent by server.' 23 | }; 24 | 25 | defaultError401 = { 26 | message: 'You are not authenticated!', 27 | details: 'You should be authenticated (sign in) in order to perform this operation.' 28 | }; 29 | 30 | defaultError403 = { 31 | message: 'You are not authorized!', 32 | details: 'You are not allowed to perform this operation.' 33 | }; 34 | 35 | defaultError404 = { 36 | message: 'Resource not found!', 37 | details: 'The resource requested could not be found on the server.' 38 | }; 39 | 40 | logError(error: IErrorInfo): void { 41 | this._logService.error(error); 42 | } 43 | 44 | showError(error: IErrorInfo): any { 45 | if (error.details) { 46 | return this._messageService.error(error.details, error.message || this.defaultError.message); 47 | } else { 48 | return this._messageService.error(error.message || this.defaultError.message); 49 | } 50 | } 51 | 52 | handleTargetUrl(targetUrl: string): void { 53 | if (!targetUrl) { 54 | location.href = '/'; 55 | } else { 56 | location.href = targetUrl; 57 | } 58 | } 59 | 60 | handleUnAuthorizedRequest(messagePromise: any, targetUrl?: string) { 61 | const self = this; 62 | 63 | if (messagePromise) { 64 | messagePromise.done(() => { 65 | this.handleTargetUrl(targetUrl || '/'); 66 | }); 67 | } else { 68 | self.handleTargetUrl(targetUrl || '/'); 69 | } 70 | } 71 | 72 | handleNonAbpErrorResponse(response: HttpResponse) { 73 | const self = this; 74 | 75 | switch (response.status) { 76 | case 401: 77 | self.handleUnAuthorizedRequest( 78 | self.showError(self.defaultError401), 79 | '/' 80 | ); 81 | break; 82 | case 403: 83 | self.showError(self.defaultError403); 84 | break; 85 | case 404: 86 | self.showError(self.defaultError404); 87 | break; 88 | default: 89 | self.showError(self.defaultError); 90 | break; 91 | } 92 | } 93 | 94 | handleAbpResponse(response: HttpResponse, ajaxResponse: IAjaxResponse): HttpResponse { 95 | var newResponse: HttpResponse; 96 | 97 | if (ajaxResponse.success) { 98 | 99 | newResponse = response.clone({ 100 | body: ajaxResponse.result 101 | }); 102 | 103 | if (ajaxResponse.targetUrl) { 104 | this.handleTargetUrl(ajaxResponse.targetUrl);; 105 | } 106 | } else { 107 | 108 | newResponse = response.clone({ 109 | body: ajaxResponse.result 110 | }); 111 | 112 | if (!ajaxResponse.error) { 113 | ajaxResponse.error = this.defaultError; 114 | } 115 | 116 | this.logError(ajaxResponse.error); 117 | this.showError(ajaxResponse.error); 118 | 119 | if (response.status === 401) { 120 | this.handleUnAuthorizedRequest(null, ajaxResponse.targetUrl); 121 | } 122 | } 123 | 124 | return newResponse; 125 | } 126 | 127 | getAbpAjaxResponseOrNull(response: HttpResponse): IAjaxResponse | null { 128 | if (!response || !response.headers) { 129 | return null; 130 | } 131 | 132 | var contentType = response.headers.get('Content-Type'); 133 | if (!contentType) { 134 | this._logService.warn('Content-Type is not sent!'); 135 | return null; 136 | } 137 | 138 | if (contentType.indexOf("application/json") < 0) { 139 | this._logService.warn('Content-Type is not application/json: ' + contentType); 140 | return null; 141 | } 142 | 143 | var responseObj = JSON.parse(JSON.stringify(response.body)); 144 | if (!responseObj.__abp) { 145 | return null; 146 | } 147 | 148 | return responseObj as IAjaxResponse; 149 | } 150 | 151 | handleResponse(response: HttpResponse): HttpResponse { 152 | var ajaxResponse = this.getAbpAjaxResponseOrNull(response); 153 | if (ajaxResponse == null) { 154 | return response; 155 | } 156 | 157 | return this.handleAbpResponse(response, ajaxResponse); 158 | } 159 | 160 | blobToText(blob: any): Observable { 161 | return new Observable((observer: any) => { 162 | if (!blob) { 163 | observer.next(""); 164 | observer.complete(); 165 | } else { 166 | let reader = new FileReader(); 167 | reader.onload = function () { 168 | observer.next(this.result); 169 | observer.complete(); 170 | } 171 | reader.readAsText(blob); 172 | } 173 | }); 174 | } 175 | } -------------------------------------------------------------------------------- /projects/abp-ng2-module/src/lib/interceptors/abpHttpInterceptor.ts: -------------------------------------------------------------------------------- 1 | import { Injectable, Injector } from '@angular/core'; 2 | import { Observable, of, BehaviorSubject } from 'rxjs'; 3 | import { LogService } from '../services/log/log.service'; 4 | import { TokenService } from '../services/auth/token.service'; 5 | import { UtilsService } from '../services/utils/utils.service'; 6 | import { HttpInterceptor, HttpHandler, HttpRequest, HttpEvent, HttpResponse, HttpErrorResponse, HttpHeaders } from '@angular/common/http'; 7 | import { switchMap, filter, take, catchError, tap, map } from 'rxjs/operators'; 8 | import { throwError } from 'rxjs'; 9 | import { AbpHttpConfigurationService } from './abp-http-configuration.service' 10 | import { RefreshTokenService } from './refresh-token.service' 11 | declare const abp: any; 12 | 13 | @Injectable() 14 | export class AbpHttpInterceptor implements HttpInterceptor { 15 | 16 | protected configuration: AbpHttpConfigurationService; 17 | private _tokenService: TokenService = new TokenService(); 18 | private _utilsService: UtilsService = new UtilsService(); 19 | private _logService: LogService = new LogService(); 20 | 21 | constructor(configuration: AbpHttpConfigurationService, 22 | private _injector: Injector) { 23 | this.configuration = configuration; 24 | } 25 | 26 | intercept(request: HttpRequest, next: HttpHandler): Observable> { 27 | var modifiedRequest = this.normalizeRequestHeaders(request); 28 | return next.handle(modifiedRequest) 29 | .pipe( 30 | catchError(error => { 31 | if (error instanceof HttpErrorResponse && error.status === 401) { 32 | return this.tryAuthWithRefreshToken(request, next, error); 33 | } else { 34 | return this.handleErrorResponse(error); 35 | } 36 | }), 37 | switchMap((event) => { 38 | return this.handleSuccessResponse(event); 39 | }) 40 | ); 41 | } 42 | 43 | protected tryGetRefreshTokenService(): Observable { 44 | var _refreshTokenService = this._injector.get(RefreshTokenService, null); 45 | 46 | if (_refreshTokenService) { 47 | return _refreshTokenService.tryAuthWithRefreshToken(); 48 | } 49 | return of(false); 50 | } 51 | 52 | private isRefreshing = false; 53 | private refreshTokenSubject: BehaviorSubject = new BehaviorSubject(null); 54 | 55 | private tryAuthWithRefreshToken(request: HttpRequest, next: HttpHandler, error: any) { 56 | if (!this.isRefreshing) { 57 | this.isRefreshing = true; 58 | this.refreshTokenSubject.next(null); 59 | 60 | return this.tryGetRefreshTokenService().pipe( 61 | switchMap((authResult: boolean) => { 62 | this.isRefreshing = false; 63 | if (authResult) { 64 | this.refreshTokenSubject.next(authResult); 65 | let modifiedRequest = this.normalizeRequestHeaders(request); 66 | return next.handle(modifiedRequest); 67 | } else { 68 | return this.handleErrorResponse(error); 69 | } 70 | })); 71 | } else { 72 | return this.refreshTokenSubject.pipe( 73 | filter(authResult => authResult != null), 74 | take(1), 75 | switchMap(authResult => { 76 | let modifiedRequest = this.normalizeRequestHeaders(request); 77 | return next.handle(modifiedRequest); 78 | })); 79 | } 80 | } 81 | 82 | protected normalizeRequestHeaders(request: HttpRequest): HttpRequest { 83 | var modifiedHeaders = new HttpHeaders(); 84 | modifiedHeaders = request.headers.set("Pragma", "no-cache") 85 | .set("Cache-Control", "no-cache") 86 | .set("Expires", "Sat, 01 Jan 2000 00:00:00 GMT"); 87 | 88 | modifiedHeaders = this.addXRequestedWithHeader(modifiedHeaders); 89 | modifiedHeaders = this.addAuthorizationHeaders(modifiedHeaders); 90 | modifiedHeaders = this.addAspNetCoreCultureHeader(modifiedHeaders); 91 | modifiedHeaders = this.addAcceptLanguageHeader(modifiedHeaders); 92 | modifiedHeaders = this.addTenantIdHeader(modifiedHeaders); 93 | 94 | return request.clone({ 95 | headers: modifiedHeaders 96 | }); 97 | } 98 | 99 | protected addXRequestedWithHeader(headers: HttpHeaders): HttpHeaders { 100 | if (headers) { 101 | headers = headers.set('X-Requested-With', 'XMLHttpRequest'); 102 | } 103 | 104 | return headers; 105 | } 106 | 107 | protected addAspNetCoreCultureHeader(headers: HttpHeaders): HttpHeaders { 108 | let cookieLangValue = this._utilsService.getCookieValue("Abp.Localization.CultureName"); 109 | if (cookieLangValue && headers && (!headers.has('.AspNetCore.Culture') || this.configuration.forceHeaderCookieWrite)) { 110 | headers = headers.set('.AspNetCore.Culture', cookieLangValue); 111 | } 112 | 113 | return headers; 114 | } 115 | 116 | protected addAcceptLanguageHeader(headers: HttpHeaders): HttpHeaders { 117 | let cookieLangValue = this._utilsService.getCookieValue("Abp.Localization.CultureName"); 118 | if (cookieLangValue && headers && !headers.has('Accept-Language')) { 119 | headers = headers.set('Accept-Language', cookieLangValue); 120 | } 121 | 122 | return headers; 123 | } 124 | 125 | protected addTenantIdHeader(headers: HttpHeaders): HttpHeaders { 126 | let cookieTenantIdValue = this._utilsService.getCookieValue(abp.multiTenancy.tenantIdCookieName); 127 | if (cookieTenantIdValue && headers && !headers.has(abp.multiTenancy.tenantIdCookieName)) { 128 | headers = headers.set(abp.multiTenancy.tenantIdCookieName, cookieTenantIdValue); 129 | } 130 | 131 | return headers; 132 | } 133 | 134 | protected addAuthorizationHeaders(headers: HttpHeaders): HttpHeaders { 135 | let authorizationHeaders = headers ? headers.getAll('Authorization') : null; 136 | if (!authorizationHeaders) { 137 | authorizationHeaders = []; 138 | } 139 | 140 | if (!this.itemExists(authorizationHeaders, (item: string) => item.indexOf('Bearer ') == 0)) { 141 | let token = this._tokenService.getToken(); 142 | if (headers && token) { 143 | headers = headers.set('Authorization', 'Bearer ' + token); 144 | } 145 | } 146 | 147 | return headers; 148 | } 149 | 150 | protected handleSuccessResponse(event: HttpEvent): Observable> { 151 | var self = this; 152 | 153 | if (event instanceof HttpResponse) { 154 | if (event.body instanceof Blob && event.body.type && event.body.type.indexOf("application/json") >= 0) { 155 | return self.configuration.blobToText(event.body).pipe( 156 | map( 157 | json => { 158 | const responseBody = json == "null" ? {} : JSON.parse(json); 159 | 160 | var modifiedResponse = self.configuration.handleResponse(event.clone({ 161 | body: responseBody 162 | })); 163 | 164 | return modifiedResponse.clone({ 165 | body: new Blob([JSON.stringify(modifiedResponse.body)], { type: 'application/json' }) 166 | }); 167 | }) 168 | ); 169 | } 170 | } 171 | return of(event); 172 | } 173 | 174 | protected handleErrorResponse(error: any): Observable { 175 | if (!(error.error instanceof Blob)) { 176 | return throwError(error); 177 | } 178 | 179 | return this.configuration.blobToText(error.error).pipe( 180 | switchMap((json) => { 181 | const errorBody = (json == "" || json == "null") ? {} : JSON.parse(json); 182 | const errorResponse = new HttpResponse({ 183 | headers: error.headers, 184 | status: error.status, 185 | body: errorBody 186 | }); 187 | 188 | var ajaxResponse = this.configuration.getAbpAjaxResponseOrNull(errorResponse); 189 | 190 | if (ajaxResponse != null) { 191 | this.configuration.handleAbpResponse(errorResponse, ajaxResponse); 192 | } else { 193 | this.configuration.handleNonAbpErrorResponse(errorResponse); 194 | } 195 | 196 | return throwError(error); 197 | }) 198 | ); 199 | } 200 | 201 | private itemExists(items: T[], predicate: (item: T) => boolean): boolean { 202 | for (let i = 0; i < items.length; i++) { 203 | if (predicate(items[i])) { 204 | return true; 205 | } 206 | } 207 | 208 | return false; 209 | } 210 | } 211 | -------------------------------------------------------------------------------- /projects/abp-ng2-module/src/lib/interceptors/index.ts: -------------------------------------------------------------------------------- 1 | export * from './abpHttpInterceptor'; 2 | export * from './abp-http-configuration.service'; 3 | export * from './refresh-token.service'; 4 | -------------------------------------------------------------------------------- /projects/abp-ng2-module/src/lib/interceptors/refresh-token.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { Observable } from 'rxjs'; 3 | 4 | @Injectable() 5 | export abstract class RefreshTokenService { 6 | /** 7 | * Try to authenticate with refresh token and return if auth succeed 8 | */ 9 | abstract tryAuthWithRefreshToken(): Observable; 10 | } -------------------------------------------------------------------------------- /projects/abp-ng2-module/src/lib/models/index.ts: -------------------------------------------------------------------------------- 1 | export interface IValidationErrorInfo { 2 | 3 | message: string; 4 | 5 | members: string[]; 6 | 7 | } 8 | 9 | export interface IErrorInfo { 10 | 11 | code: number; 12 | 13 | message: string; 14 | 15 | details: string; 16 | 17 | validationErrors: IValidationErrorInfo[]; 18 | 19 | } 20 | 21 | export interface IAjaxResponse { 22 | 23 | success: boolean; 24 | 25 | result?: any; 26 | 27 | targetUrl?: string; 28 | 29 | error?: IErrorInfo; 30 | 31 | unAuthorizedRequest: boolean; 32 | 33 | __abp: boolean; 34 | 35 | } -------------------------------------------------------------------------------- /projects/abp-ng2-module/src/lib/services/abp-user-configuration.service.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import { Injectable } from '@angular/core'; 4 | import { HttpClient } from '@angular/common/http'; 5 | 6 | declare var jQuery: any; 7 | declare var abp: any; 8 | 9 | @Injectable({ 10 | providedIn: 'root' 11 | }) 12 | export class AbpUserConfigurationService { 13 | 14 | constructor(private _http: HttpClient) { 15 | 16 | } 17 | 18 | initialize(): void { 19 | this._http.get('/AbpUserConfiguration/GetAll') 20 | .subscribe(result => { 21 | jQuery.extend(true, abp, JSON.parse(JSON.stringify(result))); 22 | }); 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /projects/abp-ng2-module/src/lib/services/auth/permission-checker.service.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import { Injectable } from '@angular/core'; 4 | 5 | @Injectable({ 6 | providedIn: 'root' 7 | }) 8 | export class PermissionCheckerService { 9 | 10 | isGranted(permissionName: string): boolean { 11 | return abp.auth.isGranted(permissionName); 12 | } 13 | 14 | } -------------------------------------------------------------------------------- /projects/abp-ng2-module/src/lib/services/auth/token.service.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import { Injectable } from '@angular/core'; 4 | 5 | @Injectable({ 6 | providedIn: 'root' 7 | }) 8 | export class TokenService { 9 | 10 | getToken(): string { 11 | return abp.auth.getToken(); 12 | } 13 | 14 | getTokenCookieName(): string { 15 | return abp.auth.tokenCookieName; 16 | } 17 | 18 | clearToken(): void { 19 | abp.auth.clearToken(); 20 | } 21 | 22 | setToken(authToken: string, expireDate?: Date): void { 23 | abp.auth.setToken(authToken, expireDate); 24 | } 25 | 26 | //refresh token 27 | getRefreshToken(): string { 28 | return abp.auth.getRefreshToken(); 29 | } 30 | 31 | getRefreshTokenCookieName(): string { 32 | return abp.auth.refreshTokenCookieName; 33 | } 34 | 35 | clearRefreshToken(): void { 36 | abp.auth.clearRefreshToken(); 37 | } 38 | 39 | setRefreshToken(refreshToken: string, expireDate?: Date): void { 40 | abp.auth.setRefreshToken(refreshToken, expireDate); 41 | } 42 | } -------------------------------------------------------------------------------- /projects/abp-ng2-module/src/lib/services/features/feature-checker.service.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import { Injectable } from '@angular/core'; 4 | 5 | @Injectable({ 6 | providedIn: 'root' 7 | }) 8 | export class FeatureCheckerService { 9 | 10 | get(featureName: string): abp.features.IFeature { 11 | return abp.features.get(featureName); 12 | } 13 | 14 | getValue(featureName: string): string { 15 | return abp.features.getValue(featureName); 16 | } 17 | 18 | isEnabled(featureName: string): boolean { 19 | return abp.features.isEnabled(featureName); 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /projects/abp-ng2-module/src/lib/services/index.ts: -------------------------------------------------------------------------------- 1 | export * from './auth/token.service'; 2 | export * from './auth/permission-checker.service'; 3 | export * from './features/feature-checker.service'; 4 | export * from './localization/localization.service'; 5 | export * from './log/log.service'; 6 | export * from './message/message.service'; 7 | export * from './multi-tenancy/abp-multi-tenancy.service'; 8 | export * from './notify/notify.service'; 9 | export * from './session/abp-session.service'; 10 | export * from './settings/setting.service'; 11 | export * from './utils/utils.service'; 12 | export * from './abp-user-configuration.service'; -------------------------------------------------------------------------------- /projects/abp-ng2-module/src/lib/services/localization/localization.service.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import { Injectable } from '@angular/core'; 4 | 5 | @Injectable({ 6 | providedIn: 'root' 7 | }) 8 | export class LocalizationService { 9 | 10 | get languages(): abp.localization.ILanguageInfo[] { 11 | return abp.localization.languages; 12 | } 13 | 14 | get currentLanguage(): abp.localization.ILanguageInfo { 15 | return abp.localization.currentLanguage; 16 | } 17 | 18 | localize(key: string, sourceName: string): string { 19 | return abp.localization.localize(key, sourceName); 20 | } 21 | 22 | getSource(sourceName: string): (...key: string[]) => string { 23 | return abp.localization.getSource(sourceName); 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /projects/abp-ng2-module/src/lib/services/log/log.service.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import { Injectable } from '@angular/core'; 4 | 5 | @Injectable({ 6 | providedIn: 'root' 7 | }) 8 | export class LogService { 9 | 10 | debug(logObject?: any): void { 11 | abp.log.debug(logObject); 12 | } 13 | 14 | info(logObject?: any): void { 15 | abp.log.info(logObject); 16 | } 17 | 18 | warn(logObject?: any): void { 19 | abp.log.warn(logObject); 20 | } 21 | 22 | error(logObject?: any): void { 23 | abp.log.error(logObject); 24 | } 25 | 26 | fatal(logObject?: any): void { 27 | abp.log.fatal(logObject); 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /projects/abp-ng2-module/src/lib/services/message/message.service.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import { Injectable } from '@angular/core'; 4 | 5 | @Injectable({ 6 | providedIn: 'root' 7 | }) 8 | export class MessageService { 9 | 10 | info(message: string, title?: string, options?: any): any { 11 | return abp.message.info(message, title, options); 12 | } 13 | 14 | success(message: string, title?: string, options?: any): any { 15 | return abp.message.success(message, title, options); 16 | } 17 | 18 | warn(message: string, title?: string, options?: any): any { 19 | return abp.message.warn(message, title, options); 20 | } 21 | 22 | error(message: string, title?: string, options?: any): any { 23 | return abp.message.error(message, title, options); 24 | } 25 | 26 | confirm(message: string, title?: string, callback?: (result: boolean, info?: any) => void, options?: any): any { 27 | return abp.message.confirm(message, title, callback, options); 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /projects/abp-ng2-module/src/lib/services/multi-tenancy/abp-multi-tenancy.service.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import { Injectable } from '@angular/core'; 4 | 5 | @Injectable({ 6 | providedIn: 'root' 7 | }) 8 | export class AbpMultiTenancyService { 9 | 10 | get isEnabled(): boolean { 11 | return abp.multiTenancy.isEnabled; 12 | } 13 | 14 | } -------------------------------------------------------------------------------- /projects/abp-ng2-module/src/lib/services/notify/notify.service.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import { Injectable } from '@angular/core'; 4 | 5 | @Injectable({ 6 | providedIn: 'root' 7 | }) 8 | export class NotifyService { 9 | 10 | info(message: string, title?: string, options?: any): void { 11 | abp.notify.info(message, title, options); 12 | } 13 | 14 | success(message: string, title?: string, options?: any): void { 15 | abp.notify.success(message, title, options); 16 | } 17 | 18 | warn(message: string, title?: string, options?: any): void { 19 | abp.notify.warn(message, title, options); 20 | } 21 | 22 | error(message: string, title?: string, options?: any): void { 23 | abp.notify.error(message, title, options); 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /projects/abp-ng2-module/src/lib/services/session/abp-session.service.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import { Injectable } from '@angular/core'; 4 | 5 | @Injectable({ 6 | providedIn: 'root' 7 | }) 8 | export class AbpSessionService { 9 | 10 | get userId(): number | undefined { 11 | return abp.session.userId; 12 | } 13 | 14 | get tenantId(): number | undefined { 15 | return abp.session.tenantId; 16 | } 17 | 18 | get impersonatorUserId(): number | undefined { 19 | return abp.session.impersonatorUserId; 20 | } 21 | 22 | get impersonatorTenantId(): number | undefined { 23 | return abp.session.impersonatorTenantId; 24 | } 25 | 26 | get multiTenancySide(): abp.multiTenancy.sides { 27 | return abp.session.multiTenancySide; 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /projects/abp-ng2-module/src/lib/services/settings/setting.service.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import { Injectable } from '@angular/core'; 4 | 5 | @Injectable({ 6 | providedIn: 'root' 7 | }) 8 | export class SettingService { 9 | 10 | get(name: string): string { 11 | return abp.setting.get(name); 12 | } 13 | 14 | getBoolean(name: string): boolean { 15 | return abp.setting.getBoolean(name); 16 | } 17 | 18 | getInt(name: string): number { 19 | return abp.setting.getInt(name); 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /projects/abp-ng2-module/src/lib/services/utils/utils.service.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import {Injectable} from '@angular/core'; 4 | 5 | @Injectable({ 6 | providedIn: 'root' 7 | }) 8 | export class UtilsService { 9 | getCookieValue(key: string): string { 10 | return abp.utils.getCookieValue(key); 11 | } 12 | 13 | setCookieValue(key: string, value: string, expireDate?: Date, path?: string, domain?: string, attributes?: any): void { 14 | abp.utils.setCookieValue(key, value, expireDate, path, domain, attributes); 15 | } 16 | 17 | deleteCookie(key: string, path?: string): void { 18 | abp.utils.deleteCookie(key, path); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /projects/abp-ng2-module/src/public-api.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Public API Surface of abp-ng2-module 3 | */ 4 | 5 | export * from './lib/abp.module'; 6 | export * from './lib/services/'; 7 | export * from './lib/interceptors/'; 8 | export * from './lib/models/'; 9 | -------------------------------------------------------------------------------- /projects/abp-ng2-module/src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/zone'; 4 | import 'zone.js/dist/zone-testing'; 5 | import { getTestBed } from '@angular/core/testing'; 6 | import { 7 | BrowserDynamicTestingModule, 8 | platformBrowserDynamicTesting 9 | } from '@angular/platform-browser-dynamic/testing'; 10 | 11 | declare const require: { 12 | context(path: string, deep?: boolean, filter?: RegExp): { 13 | keys(): string[]; 14 | (id: string): T; 15 | }; 16 | }; 17 | 18 | // First, initialize the Angular testing environment. 19 | getTestBed().initTestEnvironment( 20 | BrowserDynamicTestingModule, 21 | platformBrowserDynamicTesting() 22 | ); 23 | // Then we find all the tests. 24 | const context = require.context('./', true, /\.spec\.ts$/); 25 | // And load the modules. 26 | context.keys().map(context); 27 | -------------------------------------------------------------------------------- /projects/abp-ng2-module/tsconfig.lib.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../../out-tsc/lib", 5 | "target": "es2015", 6 | "declaration": true, 7 | "inlineSources": true, 8 | "types": [], 9 | "lib": [ 10 | "dom", 11 | "es2018" 12 | ] 13 | }, 14 | "angularCompilerOptions": { 15 | "skipTemplateCodegen": true, 16 | "strictMetadataEmit": true, 17 | "enableResourceInlining": true 18 | }, 19 | "exclude": [ 20 | "src/test.ts", 21 | "**/*.spec.ts" 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /projects/abp-ng2-module/tsconfig.lib.prod.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.lib.json", 3 | "angularCompilerOptions": { 4 | "compilationMode": "partial" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /projects/abp-ng2-module/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../../out-tsc/spec", 5 | "types": [ 6 | "jasmine", 7 | "node" 8 | ] 9 | }, 10 | "files": [ 11 | "src/test.ts" 12 | ], 13 | "include": [ 14 | "**/*.spec.ts", 15 | "**/*.d.ts" 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /projects/abp-ng2-module/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tslint.json", 3 | "rules": { 4 | "directive-selector": [ 5 | true, 6 | "attribute", 7 | "lib", 8 | "camelCase" 9 | ], 10 | "component-selector": [ 11 | true, 12 | "element", 13 | "lib", 14 | "kebab-case" 15 | ] 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /projects/abp-ng2-module/yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | tslib@^2.5.3: 6 | version "2.5.3" 7 | resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.5.3.tgz#24944ba2d990940e6e982c4bea147aba80209913" 8 | integrity sha512-mSxlJJwl3BMEQCUNnxXBU9jP4JBktcEGhURcPR6VQVlnP0FdDEsIaz0C35dXNGLyRfrATNofF0F5p2KPxQgB+w== 9 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "downlevelIteration": true, 9 | "experimentalDecorators": true, 10 | "module": "esnext", 11 | "moduleResolution": "node", 12 | "importHelpers": true, 13 | "target": "es2015", 14 | "lib": [ 15 | "es2018", 16 | "dom" 17 | ], 18 | "paths": { 19 | "abp-ng2-module": [ 20 | "dist/abp-ng2-module/abp-ng2-module", 21 | "dist/abp-ng2-module" 22 | ] 23 | } 24 | }, 25 | "angularCompilerOptions": { 26 | "fullTemplateTypeCheck": true, 27 | "strictInjectionParameters": true 28 | }, 29 | "include": [ 30 | "./typings.d.ts" 31 | ] 32 | } -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "tslint:recommended", 3 | "rulesDirectory": [ 4 | "codelyzer" 5 | ], 6 | "rules": { 7 | "array-type": false, 8 | "arrow-parens": false, 9 | "deprecation": { 10 | "severity": "warning" 11 | }, 12 | "import-blacklist": [ 13 | true, 14 | "rxjs/Rx" 15 | ], 16 | "interface-name": false, 17 | "max-classes-per-file": false, 18 | "max-line-length": [ 19 | true, 20 | 140 21 | ], 22 | "member-access": false, 23 | "member-ordering": [ 24 | true, 25 | { 26 | "order": [ 27 | "static-field", 28 | "instance-field", 29 | "static-method", 30 | "instance-method" 31 | ] 32 | } 33 | ], 34 | "no-consecutive-blank-lines": false, 35 | "no-console": [ 36 | true, 37 | "debug", 38 | "info", 39 | "time", 40 | "timeEnd", 41 | "trace" 42 | ], 43 | "no-empty": false, 44 | "no-inferrable-types": [ 45 | true, 46 | "ignore-params" 47 | ], 48 | "no-non-null-assertion": true, 49 | "no-redundant-jsdoc": true, 50 | "no-switch-case-fall-through": true, 51 | "no-var-requires": false, 52 | "object-literal-key-quotes": [ 53 | true, 54 | "as-needed" 55 | ], 56 | "object-literal-sort-keys": false, 57 | "ordered-imports": false, 58 | "quotemark": [ 59 | true, 60 | "single" 61 | ], 62 | "trailing-comma": false, 63 | "component-class-suffix": true, 64 | "contextual-lifecycle": true, 65 | "directive-class-suffix": true, 66 | "no-conflicting-lifecycle": true, 67 | "no-host-metadata-property": true, 68 | "no-input-rename": true, 69 | "no-inputs-metadata-property": true, 70 | "no-output-native": true, 71 | "no-output-on-prefix": true, 72 | "no-output-rename": true, 73 | "no-outputs-metadata-property": true, 74 | "template-banana-in-box": true, 75 | "template-no-negated-async": true, 76 | "use-lifecycle-interface": true, 77 | "use-pipe-transform-interface": true 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /typings.d.ts: -------------------------------------------------------------------------------- 1 | /// --------------------------------------------------------------------------------