Skip to content

Commit d549dc1

Browse files
authored
feat(jwt): jwt service decoder and expire
JWT Service module to control decode/encode and expiration of a jwt token (#26 ). * feat(jwt): service jwt init * docs(readme): update project states * docs(readme): test svg links * test(jwt): init service tests * docs(readme): update assets data * test(jwt): exceptions types * docs(readme): test base64 image * test(coverall): travis coverall config * ci(travis): change testing stage * ci(travis): fix scripts order
1 parent 30ff701 commit d549dc1

23 files changed

+500
-18
lines changed

.release-it.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
"tokenRef": "GH_TOKEN",
1919
"releaseName": "Release ${version}",
2020
"assets": [
21-
"dist/libs/support/*.tgz",
22-
"dist/libs/configurator/*.tgz"
21+
"dist/libs/configurator/*.tgz",
22+
"dist/libs/hub/*.tgz",
23+
"dist/libs/jwt/*.tgz",
24+
"dist/libs/responsive/*.tgz",
25+
"dist/libs/support/*.tgz"
2326
]
2427
},
2528
"npm": {

.travis.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ jobs:
3030
- stage: linting
3131
script: npm run lint
3232
- stage: testing
33-
script: npm run test
33+
script:
34+
- npm run test
35+
- 'cat coverage/libs/configurator/lcov.info | node_modules/coveralls/bin/coveralls.js'
36+
- 'cat coverage/libs/hub/lcov.info | node_modules/coveralls/bin/coveralls.js'
37+
- 'cat coverage/libs/jwt/lcov.info | node_modules/coveralls/bin/coveralls.js'
38+
- 'cat coverage/libs/responsive/lcov.info | node_modules/coveralls/bin/coveralls.js'
39+
- 'cat coverage/libs/support/lcov.info | node_modules/coveralls/bin/coveralls.js'
3440
- stage: building
3541
script: npm run build
3642
- stage: deploying

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
**Angular functional library**
88

9-
[![npm version](https://img.shields.io/npm/v/@ng-lab/support.svg?maxAge=3600&style=flat)](https://www.npmjs.com/package/automatic-release)
9+
[![npm version](https://img.shields.io/npm/v/@ng-lab/support.svg?maxAge=3600&style=flat)](https://www.npmjs.com/package/ng-lab)
1010
[![dependency status](https://img.shields.io/david/miguelramos/ng-lab.svg?maxAge=3600&style=flat)](https://david-dm.org/miguelramos/ng-lab)
1111
[![Build Status](https://travis-ci.com/miguelramos/ng-lab.svg?branch=master)](https://travis-ci.com/miguelramos/ng-lab)
1212
[![license](https://img.shields.io/npm/l/ng-lab.svg?maxAge=3600&style=flat)](https://github.com/miguelramos/ng-lab/LICENSE)
@@ -35,8 +35,9 @@ First check each package describe or just navigate to demo app for more informat
3535
|-------|----|-----|
3636
|@ng-lab/support| Many helpers functions | ![npm (scoped)](https://img.shields.io/npm/v/@ng-lab/support.svg?color=green&style=flat) |
3737
|@ng-lab/configurator| Service to regulate configurations | ![npm (scoped)](https://img.shields.io/npm/v/@ng-lab/configurator.svg?color=green&style=flat) |
38-
|@ng-lab/responsive| Service to observe responsive media queries | In development |
39-
|@ng-lab/hub| Service to trigger/listener hub events like pub/sub | In development |
38+
|@ng-lab/responsive| Service to observe responsive media queries | ![npm (scoped)](https://img.shields.io/npm/v/@ng-lab/responsive.svg?color=green&style=flat) |
39+
|@ng-lab/hub| Service to trigger/listener hub events like pub/sub | ![npm (scoped)](https://img.shields.io/npm/v/@ng-lab/hub.svg?color=green&style=flat) |
40+
|@ng-lab/jwt | Service to control jwt tokens | In Development |
4041

4142
#### For Development
4243

angular.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,44 @@
273273
"styleext": "scss"
274274
}
275275
}
276+
},
277+
"jwt": {
278+
"root": "libs/jwt",
279+
"sourceRoot": "libs/jwt/src",
280+
"projectType": "library",
281+
"prefix": "ng-lab",
282+
"architect": {
283+
"build": {
284+
"builder": "@angular-devkit/build-ng-packagr:build",
285+
"options": {
286+
"tsConfig": "libs/jwt/tsconfig.lib.json",
287+
"project": "libs/jwt/ng-package.json"
288+
}
289+
},
290+
"lint": {
291+
"builder": "@angular-devkit/build-angular:tslint",
292+
"options": {
293+
"tsConfig": [
294+
"libs/jwt/tsconfig.lib.json",
295+
"libs/jwt/tsconfig.spec.json"
296+
],
297+
"exclude": ["**/node_modules/**"]
298+
}
299+
},
300+
"test": {
301+
"builder": "@nrwl/builders:jest",
302+
"options": {
303+
"jestConfig": "libs/jwt/jest.config.js",
304+
"tsConfig": "libs/jwt/tsconfig.spec.json",
305+
"setupFile": "libs/jwt/src/test-setup.ts"
306+
}
307+
}
308+
},
309+
"schematics": {
310+
"@nrwl/schematics:component": {
311+
"styleext": "scss"
312+
}
313+
}
276314
}
277315
},
278316
"cli": {

libs/jwt/jest.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
name: 'jwt',
3+
preset: '../../jest.config.js',
4+
coverageDirectory: '../../coverage/libs/jwt'
5+
};

libs/jwt/ng-package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
3+
"dest": "../../dist/libs/jwt",
4+
"lib": {
5+
"entryFile": "src/index.ts"
6+
}
7+
}

libs/jwt/package.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "@ng-lab/jwt",
3+
"version": "0.0.0-PLACEHOLDER",
4+
"peerDependencies": {
5+
"@angular/common": "^7.2.0",
6+
"@angular/core": "^7.2.0",
7+
"@ng-lab/support": "0.0.0-PLACEHOLDER"
8+
},
9+
"publishConfig": {
10+
"access": "public"
11+
},
12+
"private": false,
13+
"author": {
14+
"name": "Miguel Ramos",
15+
"email": "miguel.marques.ramos@gmail.com",
16+
"url": "https://ng-lab.github.com/"
17+
},
18+
"license": "MIT",
19+
"repository": {
20+
"type": "git",
21+
"url": "https://github.com/miguelramos/ng-lab"
22+
},
23+
"homepage": "https://github.com/miguelramos/ng-lab",
24+
"bugs": {
25+
"url": "https://github.com/miguelramos/ng-lab/issues"
26+
},
27+
"keywords": [
28+
"angular",
29+
"library",
30+
"ng-lab",
31+
"jwt"
32+
]
33+
}

libs/jwt/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './lib/jwt.module';

libs/jwt/src/lib/jwt-errors.ts

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/**
2+
* @license
3+
* Copyright NgLab All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://www.ng-lab.com/license
7+
*/
8+
import { ErrorDetails } from '@ng-lab/support';
9+
10+
export class JWTIllegalBaseDecodeError extends Error {
11+
/**
12+
* The validation error type.
13+
*
14+
* @see PropertyError
15+
*/
16+
type: string;
17+
details: ErrorDetails | undefined;
18+
19+
/**
20+
* Construct a property validation error.
21+
*
22+
* @param type The validation error type.
23+
* @param message The error message.
24+
*/
25+
constructor(type: string, message: string, details?: ErrorDetails) {
26+
super(message);
27+
28+
this.name = 'JWTIllegalBaseDecodeError';
29+
this.stack = new Error().stack;
30+
this.type = type;
31+
this.details = details;
32+
33+
// Required in order for error instances to be able to use instanceof.
34+
// SEE: https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md
35+
(this as any).__proto__ = JWTIllegalBaseDecodeError.prototype;
36+
}
37+
}
38+
39+
export class JWTAtobDecodeError extends Error {
40+
/**
41+
* The validation error type.
42+
*
43+
* @see PropertyError
44+
*/
45+
type: string;
46+
details: ErrorDetails | undefined;
47+
48+
/**
49+
* Construct a property validation error.
50+
*
51+
* @param type The validation error type.
52+
* @param message The error message.
53+
*/
54+
constructor(type: string, message: string, details?: ErrorDetails) {
55+
super(message);
56+
57+
this.name = 'JWTAtobDecodeError';
58+
this.stack = new Error().stack;
59+
this.type = type;
60+
this.details = details;
61+
62+
// Required in order for error instances to be able to use instanceof.
63+
// SEE: https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md
64+
(this as any).__proto__ = JWTAtobDecodeError.prototype;
65+
}
66+
}
67+
68+
export class JWTSplitDecodeError extends Error {
69+
/**
70+
* The validation error type.
71+
*
72+
* @see PropertyError
73+
*/
74+
type: string;
75+
details: ErrorDetails | undefined;
76+
77+
/**
78+
* Construct a property validation error.
79+
*
80+
* @param type The validation error type.
81+
* @param message The error message.
82+
*/
83+
constructor(type: string, message: string, details?: ErrorDetails) {
84+
super(message);
85+
86+
this.name = 'JWTSplitDecodeError';
87+
this.stack = new Error().stack;
88+
this.type = type;
89+
this.details = details;
90+
91+
// Required in order for error instances to be able to use instanceof.
92+
// SEE: https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md
93+
(this as any).__proto__ = JWTSplitDecodeError.prototype;
94+
}
95+
}

libs/jwt/src/lib/jwt.module.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { async, TestBed } from '@angular/core/testing';
2+
import { JwtModule } from './jwt.module';
3+
import { JWTService } from './jwt.service';
4+
5+
describe('> JWTModule', () => {
6+
beforeEach(async(() => {
7+
TestBed.configureTestingModule({
8+
imports: [JwtModule]
9+
}).compileComponents();
10+
}));
11+
12+
it('# Should have module defined.', () => {
13+
expect(JwtModule).toBeDefined();
14+
});
15+
16+
it('# Should have JWTService on dependency injector.', () => {
17+
const service = TestBed.get(JWTService, null);
18+
19+
expect(typeof service === 'object').toBeTruthy();
20+
});
21+
});

0 commit comments

Comments
 (0)