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

@elemental-concept/grappa-jwt

Package Overview
Dependencies
Maintainers
2
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@elemental-concept/grappa-jwt - npm Package Compare versions

Comparing version 0.8.2 to 0.8.3

esm2020/elemental-concept-grappa-jwt.mjs

7

lib/grappa-jwt.module.d.ts

@@ -1,3 +0,3 @@

import { GrappaJwtConfig } from './public/models/grappa-jwt-config';
import { SessionManagerService } from './public/services/session-manager/session-manager.service';
import { GrappaJwtConfig, SessionManagerService } from './public';
import * as i0 from "@angular/core";
export declare class GrappaJwtModule {

@@ -7,2 +7,5 @@ private readonly sessionManagerService;

constructor(sessionManagerService: SessionManagerService, config: GrappaJwtConfig);
static ɵfac: i0.ɵɵFactoryDeclaration<GrappaJwtModule, never>;
static ɵmod: i0.ɵɵNgModuleDeclaration<GrappaJwtModule, never, never, never>;
static ɵinj: i0.ɵɵInjectorDeclaration<GrappaJwtModule>;
}

@@ -1,3 +0,2 @@

import { SessionManagerService } from '../public/services/session-manager/session-manager.service';
import { GrappaJwtConfig } from '../public/models/grappa-jwt-config';
import { GrappaJwtConfig, SessionManagerService } from '../public';
export declare const instances: Instances;

@@ -4,0 +3,0 @@ export interface Instances {

import { InjectionToken } from '@angular/core';
import { PersistenceManager } from '../persistence/persistence-manager';
import { PersistenceManager } from '../persistence';
export interface GrappaJwtConfig {

@@ -4,0 +4,0 @@ persistence?: PersistenceManager;

import { PersistenceManager } from './persistence-manager';
export declare class LocalStorage implements PersistenceManager {
get(): string | null;
put(value: string): void;
remove(): void;
get: () => string | null;
put: (value: string) => void;
remove: () => void;
}
import { PersistenceManager } from './persistence-manager';
export declare class SessionStorage implements PersistenceManager {
get(): string | null;
put(value: string): void;
remove(): void;
get: () => string | null;
put: (value: string) => void;
remove: () => void;
}
import { Observable } from 'rxjs';
import { GrappaJwtConfig } from '../../models/grappa-jwt-config';
import { GrappaJwtConfig } from '../../models';
import * as i0 from "@angular/core";
export declare class SessionManagerService {

@@ -9,9 +10,11 @@ private readonly config;

constructor(config: GrappaJwtConfig);
get authorised(): boolean;
get token(): string | null;
set token(value: string);
get token(): string | null;
get authorised(): boolean;
clear(): void;
tokenChanges(): Observable<string>;
authorisationChanges(): Observable<boolean>;
clear: () => void;
tokenChanges: () => Observable<string>;
authorisationChanges: () => Observable<boolean>;
private tokenIsNotEmpty;
static ɵfac: i0.ɵɵFactoryDeclaration<SessionManagerService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<SessionManagerService>;
}
{
"name": "@elemental-concept/grappa-jwt",
"version": "0.8.2",
"version": "0.8.3",
"description": "Decorator-powered JWT handling library for Grappa and Angular",

@@ -19,15 +19,27 @@ "author": "Elemental Concept",

"peerDependencies": {
"@angular/common": ">= 9 < 12",
"@angular/core": ">= 9 < 12",
"@elemental-concept/grappa": "^0.8.2",
"rxjs": ">= 6.0.0 < 7"
"@angular/common": ">= 9 < 15",
"@angular/core": ">= 9 < 15",
"@elemental-concept/grappa": "0.8.5",
"rxjs": ">= 6.0.0 < 8"
},
"main": "bundles/elemental-concept-grappa-jwt.umd.js",
"module": "fesm2015/elemental-concept-grappa-jwt.js",
"es2015": "fesm2015/elemental-concept-grappa-jwt.js",
"esm2015": "esm2015/elemental-concept-grappa-jwt.js",
"fesm2015": "fesm2015/elemental-concept-grappa-jwt.js",
"typings": "elemental-concept-grappa-jwt.d.ts",
"metadata": "elemental-concept-grappa-jwt.metadata.json",
"module": "fesm2015/elemental-concept-grappa-jwt.mjs",
"es2020": "fesm2020/elemental-concept-grappa-jwt.mjs",
"esm2020": "esm2020/elemental-concept-grappa-jwt.mjs",
"fesm2020": "fesm2020/elemental-concept-grappa-jwt.mjs",
"fesm2015": "fesm2015/elemental-concept-grappa-jwt.mjs",
"typings": "index.d.ts",
"exports": {
"./package.json": {
"default": "./package.json"
},
".": {
"types": "./index.d.ts",
"esm2020": "./esm2020/elemental-concept-grappa-jwt.mjs",
"es2020": "./fesm2020/elemental-concept-grappa-jwt.mjs",
"es2015": "./fesm2015/elemental-concept-grappa-jwt.mjs",
"node": "./fesm2015/elemental-concept-grappa-jwt.mjs",
"default": "./fesm2020/elemental-concept-grappa-jwt.mjs"
}
},
"sideEffects": false
}
}

@@ -1,24 +0,178 @@

# Lib
# Grappa Jwt
This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 8.0.1.
Decorator-powered JWT handling library for Grappa and **Angular 9+**, plus **RxJs 6+**.
## Code scaffolding
| Last version | Angular Versions | Node |
|--------------|------------------------|------------------|
| `0.8.3` | 9+ up to 14 (included) | 14.15.0 or later |
Run `ng generate component component-name --project lib` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project lib`.
> Note: Don't forget to add `--project lib` or else it will be added to the default project in your `angular.json` file.
## 🛠 Installation
## Build
- With **npm**: `npm i --save @elemental-concept/grappa-jwt`
- With **Yarn**: `yarn add @elemental-concept/grappa-jwt`
Run `ng build lib` to build the project. The build artifacts will be stored in the `dist/` directory.
Add `GrappaJwtModule` to your main `AppModule` to imports section.
## Publishing
```typescript
@NgModule({
declarations: [ ... ],
imports: [
...,
GrappaJwtModule
],
providers: [ ],
bootstrap: [ ... ]
})
export class AppModule {
}
```
After building your library with `ng build lib`, go to the dist folder `cd dist/lib` and run `npm publish`.
## 📖 Introduction
## Running unit tests
**Grappa JWT** provide a easy and automatic way of using JWT in your HttpClient.
To be able to use is you need to pass the token to the `SessionManagerService`:
Run `ng test lib` to execute the unit tests via [Karma](https://karma-runner.github.io).
```typescript
@Injectable()
export class JWTService {
constructor(sessionManagerService: SessionManagerService) {
}
## Further help
login = () =>
this.someService
.login(request)
.subscribe(
response => !!response.token
? this.authSuccess(response)
: this.authError(),
() => this.authError());
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).
private authSuccess(response: Response) {
this.sessionManagerService.token = `Bearer ${ response.token }`;
// do somehting
}
private authError() {
// error handling
}
}
```
You can use GrappaJwt with Grappa to have the full potential:
```typescript
@Injectable()
@RestClient('http://example.com/api/')
@Authenticate()
export class UserService {
@GET('/users')
list: () => Observable<User[]>;
@GET('/users/{0}')
find: (id: number) => Observable<User>;
@POST('/users')
create: (user: User) => Observable<User>;
@PUT('/users/{0}')
update: (id: number, user: User) => Observable<User>;
}
```
### Example of expiration handling
if you want somehthing
```typescript
@Injectable()
@RestClient('http://example.com/api/')
@Authenticate()
export class UserService {
constructor(sessionManagerService: SessionManagerService, router: Router) { }
@GET('/users')
list: () => Observable<User[]>;
@GET('/users/{0}')
find: (id: number) => Observable<User>;
@POST('/users')
create: (user: User) => Observable<User>;
@PUT('/users/{0}')
update: (id: number, user: User) => Observable<User>;
@AfterRequest()
expirationFilter(observable: Observable<any>) {
return observable.pipe(catchError(e => this.deauthorise(e)));
}
private deauthorise(e) {
if (e.status === 401 || e.status === 403) {
this.sessionManagerService.clear();
this.router.navigate([ '' ]).then();
}
return throwError(e);
}
}
```
### Custom Storage
by default GrappaJwt will use `window.sessionStorage`, but you can use it with other storage. The Ionic Storage is a good example:
You first need to add a new `PersistenceManager` using the Ionic Storage.
Remeber to user `GRAPPA-JWT` as key.
```typescript
export class PersistenceManager {
constructor(private readonly storage: Storage) { }
put(value: string) {
return this.storage.set('GRAPPA-JWT', value);
}
get() {
return this.storage.get('GRAPPA-JWT');
}
remove() {
this.storage.remove('GRAPPA-JWT');
}
}
```
Then you have to create a factory to create a `GrappaAuthConfigToken`
```typescript
export function grappaConfigFactory(storage: Storage) {
return {
persistence: new PersistenceManager(storage)
};
}
```
Finally, provide the `GrappaAuthConfigToken` using the `grappaConfigFactory` you created, passing `Storage` into the dependencies:
```typescript
@NgModule({
declarations: [ AppComponent ],
imports: [
...,
IonicStorageModule.forRoot(),
GrappaAuthModule,
GrappaModule,
],
providers: [
{
provide: GrappaAuthConfigToken,
useFactory: grappaConfigFactory,
deps:[ Storage ]
}
],
bootstrap: [ AppComponent ]
})
export class AppModule { }
```
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc