@nakedcreativity/membrs-angular-helper 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/README.md +24 -0
  2. package/bundles/nakedcreativity-membrs-angular-helper.umd.js +467 -0
  3. package/bundles/nakedcreativity-membrs-angular-helper.umd.js.map +1 -0
  4. package/bundles/nakedcreativity-membrs-angular-helper.umd.min.js +16 -0
  5. package/bundles/nakedcreativity-membrs-angular-helper.umd.min.js.map +1 -0
  6. package/esm2015/lib/config.interface.js +1 -0
  7. package/esm2015/lib/config.service.js +7 -0
  8. package/esm2015/lib/membrs.module.js +100 -0
  9. package/esm2015/lib/membrs.service.js +98 -0
  10. package/esm2015/lib/router.config.js +25 -0
  11. package/esm2015/nakedcreativity-membrs-angular-helper.js +6 -0
  12. package/esm2015/public-api.js +9 -0
  13. package/esm5/lib/config.interface.js +1 -0
  14. package/esm5/lib/config.service.js +7 -0
  15. package/esm5/lib/membrs.module.js +104 -0
  16. package/esm5/lib/membrs.service.js +113 -0
  17. package/esm5/lib/router.config.js +25 -0
  18. package/esm5/nakedcreativity-membrs-angular-helper.js +6 -0
  19. package/esm5/public-api.js +9 -0
  20. package/fesm2015/nakedcreativity-membrs-angular-helper.js +226 -0
  21. package/fesm2015/nakedcreativity-membrs-angular-helper.js.map +1 -0
  22. package/fesm5/nakedcreativity-membrs-angular-helper.js +245 -0
  23. package/fesm5/nakedcreativity-membrs-angular-helper.js.map +1 -0
  24. package/lib/config.interface.d.ts +7 -0
  25. package/lib/config.service.d.ts +7 -0
  26. package/lib/membrs.module.d.ts +23 -0
  27. package/lib/membrs.service.d.ts +17 -0
  28. package/lib/router.config.d.ts +3 -0
  29. package/nakedcreativity-membrs-angular-helper.d.ts +6 -0
  30. package/nakedcreativity-membrs-angular-helper.metadata.json +1 -0
  31. package/package.json +21 -0
  32. package/public-api.d.ts +3 -0
@@ -0,0 +1,25 @@
1
+ import { MembrsConfigService } from './config.service';
2
+ import { Injector } from '@angular/core';
3
+ export function routerConfigFn(router, injector) {
4
+ var transitionService = router.transitionService;
5
+ var stateService = router.stateService;
6
+ var config = Injector.call(MembrsConfigService);
7
+ console.log('config in router config fn');
8
+ console.log(config);
9
+ // transitionService.onStart({}, (transition)=>{
10
+ // console.log('start transition')
11
+ // console.log(transition.params())
12
+ // console.log(transition.paramsChanged())
13
+ // })
14
+ stateService.defaultErrorHandler(function (error) {
15
+ // console.log('error')
16
+ // console.log(error)
17
+ console.log('default error handler');
18
+ if (error.detail == 'NOT_LOGGED_IN')
19
+ window.location.href = config.login;
20
+ //console.log(MembrsSettings)
21
+ if (error.detail == 'INSUFFICIENT_PERMISSIONS')
22
+ stateService.go(config.defaultState);
23
+ });
24
+ }
25
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicm91dGVyLmNvbmZpZy5qcyIsInNvdXJjZVJvb3QiOiJuZzovL0BuYWtlZGNyZWF0aXZpdHkvbWVtYnJzLWFuZ3VsYXItaGVscGVyLyIsInNvdXJjZXMiOlsibGliL3JvdXRlci5jb25maWcudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxFQUFFLG1CQUFtQixFQUFFLE1BQU0sa0JBQWtCLENBQUE7QUFFdEQsT0FBTyxFQUFFLFFBQVEsRUFBRSxNQUFNLGVBQWUsQ0FBQztBQUV6QyxNQUFNLFVBQVUsY0FBYyxDQUFDLE1BQWdCLEVBQUUsUUFBa0I7SUFFakUsSUFBTSxpQkFBaUIsR0FBRyxNQUFNLENBQUMsaUJBQWlCLENBQUM7SUFDbkQsSUFBTSxZQUFZLEdBQUcsTUFBTSxDQUFDLFlBQVksQ0FBQTtJQUd4QyxJQUFNLE1BQU0sR0FBRyxRQUFRLENBQUMsSUFBSSxDQUFDLG1CQUFtQixDQUFDLENBQUE7SUFFakQsT0FBTyxDQUFDLEdBQUcsQ0FBQyw0QkFBNEIsQ0FBQyxDQ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IHN0YXRlU2VydmljZSA9IHJvdXRlci5zdGF0ZVNlcnZpY2VcblxuXG4gIGNvbnN0IGNvbmZpZyA9IEluamVjdG9yLmNhbGwoTWVtYnJzQ29uZmlnU2VydmljZSlcblxuICBjb25zb2xlLmxvZygnY29uZmlnIGluIHJvdXRlciBjb25maWcgZm4nKVxuICBjb25zb2xlLmxvZyhjb25maWcpXG5cbi8vICAgdHJhbnNpdGlvblNlcnZpY2Uub25TdGFydCh7fSwgKHRyYW5zaXRpb24pPT57XG4vLyAgIFx0Y29uc29sZS5sb2coJ3N0YXJ0IHRyYW5zaXRpb24nKVxuLy8gXHQgIGNvbnNvbGUubG9nKHRyYW5zaXRpb24ucGFyYW1zKCkpXG4vLyBcdCAgY29uc29sZS5sb2codHJhbnNpdGlvbi5wYXJhbXNDaGFuZ2VkKCkpXG4vLyAgIH0pXG5cbiBcdHN0YXRlU2VydmljZS5kZWZhdWx0RXJyb3JIYW5kbGVyKGZ1bmN0aW9uKGVycm9yKSB7XG5cdFx0IFxuXHRcdC8vIGNvbnNvbGUubG9nKCdlcnJvcicpXG5cdFx0Ly8gY29uc29sZS5sb2coZXJyb3IpXG5cdFx0Y29uc29sZS5sb2coJ2RlZmF1bHQgZXJyb3IgaGFuZGxlcicpXG4gIFx0ICBcdGlmKGVycm9yLmRldGFpbCA9PSAnTk9UX0xPR0dFRF9JTicpXG5cdFx0XHR3aW5kb3cubG9jYXRpb24uaHJlZiA9IGNvbmZpZy5sb2dpbjtcblx0XHRcdC8vY29uc29sZS5sb2coTWVtYnJzU2V0dGluZ3MpXG5cblx0XHRpZihlcnJvci5kZXRhaWwgPT0gJ0lOU1VGRklDSUVOVF9QRVJNSVNTSU9OUycpXG5cdFx0XHRzdGF0ZVNlcnZpY2UuZ28oY29uZmlnLmRlZmF1bHRTdGF0ZSlcblxuXHR9KTtcblx0XG59Il19
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Generated bundle index. Do not edit.
3
+ */
4
+ export * from './public-api';
5
+ export { MembrsConfigService as ɵa } from './lib/config.service';
6
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibmFrZWRjcmVhdGl2aXR5LW1lbWJycy1hbmd1bGFyLWhlbHBlci5qcyIsInNvdXJjZVJvb3QiOiJuZzovL0BuYWtlZGNyZWF0aXZpdHkvbWVtYnJzLWFuZ3VsYXItaGVscGVyLyIsInNvdXJjZXMiOlsibmFrZWRjcmVhdGl2aXR5LW1lbWJycy1hbmd1bGFyLWhlbHBlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7R0FFRztBQUVILGNBQWMsY0FBYyxDQUFDO0FBRzdCLE9BQU8sRUFBQyxtQkFBbUIsSUFBSSxFQUFFLEVBQUMsTUFBTSxzQkFBc0IsQ0FBQyIsInNvdXJjZXNDb250ZW50IjpbIi8qKlxuICogR2VuZXJhdGVkIGJ1bmRsZSBpbmRleC4gRG8gbm90IGVkaXQuXG4gKi9cblxuZXhwb3J0ICogZnJvbSAnLi9wdWJsaWMtYXBpJztcblxuZXhwb3J0IHtNZW1icnNDb25maWcgYXMgybVifSBmcm9tICcuL2xpYi9jb25maWcuaW50ZXJmYWNlJztcbmV4cG9ydCB7TWVtYnJzQ29uZmlnU2VydmljZSBhcyDJtWF9IGZyb20gJy4vbGliL2NvbmZpZy5zZXJ2aWNlJzsiXX0=
@@ -0,0 +1,9 @@
1
+ /*
2
+ * Public API Surface of membrs
3
+ */
4
+ export * from './lib/membrs.service';
5
+ export * from './lib/membrs.module';
6
+ export function retrieveToken() {
7
+ return localStorage.getItem('membrs');
8
+ }
9
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHVibGljLWFwaS5qcyIsInNvdXJjZVJvb3QiOiJuZzovL0BuYWtlZGNyZWF0aXZpdHkvbWVtYnJzLWFuZ3VsYXItaGVscGVyLyIsInNvdXJjZXMiOlsicHVibGljLWFwaS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7R0FFRztBQUVILGNBQWMsc0JBQXNCLENBQUM7QUFDckMsY0FBYyxxQkFBcUIsQ0FBQztBQUVwQyxNQUFNLFVBQVUsYUFBYTtJQUN6QixPQUFPLFlBQVksQ0FBQyxPQUFPLENBQUMsUUFBUSxDQUFDLENBQUM7QUFDMUMsQ0FBQyIsInNvdXJjZXNDb250ZW50IjpbIi8qXG4gKiBQdWJsaWMgQVBJIFN1cmZhY2Ugb2YgbWVtYnJzXG4gKi9cblxuZXhwb3J0ICogZnJvbSAnLi9saWIvbWVtYnJzLnNlcnZpY2UnO1xuZXhwb3J0ICogZnJvbSAnLi9saWIvbWVtYnJzLm1vZHVsZSc7XG5cbmV4cG9ydCBmdW5jdGlvbiByZXRyaWV2ZVRva2VuKCkge1xuICAgIHJldHVybiBsb2NhbFN0b3JhZ2UuZ2V0SXRlbSgnbWVtYnJzJyk7XG59Il19
@@ -0,0 +1,226 @@
1
+ import { __decorate, __param, __metadata } from 'tslib';
2
+ import { InjectionToken, Inject, ɵɵdefineInjectable, ɵɵinject, Injectable, Injector, NgModule } from '@angular/core';
3
+ import { JwtHelperService, JwtModule } from '@auth0/angular-jwt';
4
+ import { HttpClient, HttpClientModule } from '@angular/common/http';
5
+ import { CommonModule } from '@angular/common';
6
+ import { Transition, UIRouter, UIRouterModule } from '@uirouter/angular';
7
+
8
+ /**
9
+ * This is not a real service, but it looks like it from the outside.
10
+ * It's just an InjectionTToken used to import the config object, provided from the outside
11
+ */
12
+ const MembrsConfigService = new InjectionToken("MembrsConfig");
13
+
14
+ let MembrsService = class MembrsService {
15
+ constructor(jwtService, http, config) {
16
+ this.jwtService = jwtService;
17
+ this.http = http;
18
+ this.config = config;
19
+ this._lsKey = 'membrs';
20
+ console.log('membrs constructor');
21
+ // if the token exists in local storage, retrieve it back to the service
22
+ if (localStorage.getItem(this._lsKey)) {
23
+ this.token = localStorage.getItem(this._lsKey);
24
+ }
25
+ }
26
+ reissue(token) {
27
+ return new Promise((resolve, reject) => {
28
+ if (!token && !this._token) {
29
+ console.log('reject, not logged in');
30
+ reject('NOT_LOGGED_IN');
31
+ }
32
+ if (token)
33
+ this.token = token;
34
+ // check stored token has not expired, or needs to be reissued soon
35
+ var reissueIn = this._decoded.exp - Math.floor(Date.now() / 1000);
36
+ // token has expired
37
+ if (reissueIn < 0) {
38
+ reject('NOT_LOGGED_IN');
39
+ }
40
+ // token expiring soon
41
+ if (reissueIn < 300) {
42
+ console.log('expires less than 300');
43
+ // to-do: call Apollo here
44
+ this.http.post(this.config.apiProtocol + this.config.api + '/token/' + this._token, {}).subscribe((response) => {
45
+ console.log('reissue response');
46
+ console.log(response);
47
+ if (response.token) {
48
+ this.token = response.token;
49
+ resolve(this._token);
50
+ }
51
+ else {
52
+ reject('NOT_LOGGED_IN');
53
+ }
54
+ }, error => {
55
+ reject('NOT_LOGGED_IN');
56
+ });
57
+ }
58
+ else {
59
+ console.log('token ok');
60
+ resolve(this._token);
61
+ }
62
+ });
63
+ }
64
+ set token(token) {
65
+ this._token = token;
66
+ localStorage.setItem(this._lsKey, token);
67
+ this._decoded = this.jwtService.decodeToken(this._token);
68
+ }
69
+ get profile() {
70
+ return this._decoded;
71
+ }
72
+ get admin() {
73
+ return this.profile.permission == 1;
74
+ }
75
+ logout() {
76
+ return new Promise((resolve, reject) => {
77
+ this.http.get(this.config.apiProtocol + this.config.api + '/token/' + this._token + '/delete', { responseType: 'text' }).subscribe((response) => {
78
+ this._token = null;
79
+ localStorage.removeItem(this._lsKey);
80
+ resolve(this.config.login);
81
+ //this.router.stateService.go('dashboard')
82
+ }, error => {
83
+ reject(this.config.login);
84
+ });
85
+ });
86
+ }
87
+ };
88
+ MembrsService.ctorParameters = () => [
89
+ { type: JwtHelperService },
90
+ { type: HttpClient },
91
+ { type: undefined, decorators: [{ type: Inject, args: [MembrsConfigService,] }] }
92
+ ];
93
+ MembrsService.ɵprov = ɵɵdefineInjectable({ factory: function MembrsService_Factory() { return new MembrsService(ɵɵinject(JwtHelperService), ɵɵinject(HttpClient), ɵɵinject(MembrsConfigService)); }, token: MembrsService, providedIn: "root" });
94
+ MembrsService = __decorate([
95
+ Injectable({
96
+ providedIn: 'root'
97
+ }),
98
+ __param(2, Inject(MembrsConfigService)),
99
+ __metadata("design:paramtypes", [JwtHelperService, HttpClient, Object])
100
+ ], MembrsService);
101
+
102
+ function routerConfigFn(router, injector) {
103
+ const transitionService = router.transitionService;
104
+ const stateService = router.stateService;
105
+ const config = Injector.call(MembrsConfigService);
106
+ console.log('config in router config fn');
107
+ console.log(config);
108
+ // transitionService.onStart({}, (transition)=>{
109
+ // console.log('start transition')
110
+ // console.log(transition.params())
111
+ // console.log(transition.paramsChanged())
112
+ // })
113
+ stateService.defaultErrorHandler(function (error) {
114
+ // console.log('error')
115
+ // console.log(error)
116
+ console.log('default error handler');
117
+ if (error.detail == 'NOT_LOGGED_IN')
118
+ window.location.href = config.login;
119
+ //console.log(MembrsSettings)
120
+ if (error.detail == 'INSUFFICIENT_PERMISSIONS')
121
+ stateService.go(config.defaultState);
122
+ });
123
+ }
124
+
125
+ var MembrsModule_1;
126
+ const validateResolve = {
127
+ token: 'reissue',
128
+ deps: [Transition, UIRouter, MembrsService],
129
+ resolveFn: validateResolveFn
130
+ };
131
+ const reissueResolve = {
132
+ token: 'reissue',
133
+ deps: [Transition, UIRouter, MembrsService],
134
+ resolveFn: reissueResolveFn
135
+ };
136
+ const reissueState = {
137
+ name: 'reissue',
138
+ url: '/reissue?token',
139
+ views: {},
140
+ resolve: [
141
+ reissueResolve
142
+ ]
143
+ };
144
+ function reissueResolveFn(transition, router, membrsService) {
145
+ //console.log(membrsService)
146
+ return new Promise((resolve, reject) => {
147
+ console.log('reissue promise resolve');
148
+ console.log(transition.params().token);
149
+ membrsService.reissue(transition.params().token).then((response) => {
150
+ console.log('redirect to dashboard state');
151
+ router.stateService.go('dashboard', {}, { inherit: false });
152
+ resolve();
153
+ }).catch(error => {
154
+ //window.location.href = environment.login
155
+ reject(error);
156
+ });
157
+ });
158
+ }
159
+ function validateResolveFn(transition, router, membrsService) {
160
+ //console.log(membrsService)
161
+ return new Promise((resolve, reject) => {
162
+ console.log('validate promise resolve');
163
+ membrsService.reissue().then((response) => {
164
+ resolve();
165
+ }).catch(error => {
166
+ //window.location.href = environment.login
167
+ reject(error);
168
+ });
169
+ });
170
+ }
171
+ /** The top level state(s) */
172
+ const STATES = [
173
+ reissueState
174
+ ];
175
+ let MembrsModule = MembrsModule_1 = class MembrsModule {
176
+ static forRoot(config) {
177
+ const moduleProviders = JwtModule.forRoot({}).providers;
178
+ moduleProviders.push(UIRouterModule.forChild({
179
+ states: STATES,
180
+ config: routerConfigFn
181
+ }).providers);
182
+ moduleProviders.push(MembrsService);
183
+ moduleProviders.push({ provide: MembrsConfigService, useValue: config });
184
+ return {
185
+ ngModule: MembrsModule_1,
186
+ providers: moduleProviders
187
+ };
188
+ return {
189
+ ngModule: MembrsModule_1,
190
+ providers: [
191
+ MembrsService,
192
+ {
193
+ provide: MembrsConfigService,
194
+ useValue: config
195
+ },
196
+ ]
197
+ };
198
+ }
199
+ };
200
+ MembrsModule = MembrsModule_1 = __decorate([
201
+ NgModule({
202
+ imports: [
203
+ CommonModule,
204
+ HttpClientModule
205
+ // UIRouterModule.forChild({
206
+ // states: STATES,
207
+ // config: routerConfigFn,
208
+ // }),
209
+ // JwtModule.forRoot({})
210
+ ]
211
+ })
212
+ ], MembrsModule);
213
+
214
+ /*
215
+ * Public API Surface of membrs
216
+ */
217
+ function retrieveToken() {
218
+ return localStorage.getItem('membrs');
219
+ }
220
+
221
+ /**
222
+ * Generated bundle index. Do not edit.
223
+ */
224
+
225
+ export { MembrsModule, MembrsService, STATES, reissueResolve, reissueResolveFn, reissueState, retrieveToken, validateResolve, validateResolveFn, MembrsConfigService as ɵa };
226
+ //# sourceMappingURL=nakedcreativity-membrs-angular-helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nakedcreativity-membrs-angular-helper.js","sources":["ng://@nakedcreativity/membrs-angular-helper/lib/config.service.ts","ng://@nakedcreativity/membrs-angular-helper/lib/membrs.service.ts","ng://@nakedcreativity/membrs-angular-helper/lib/router.config.ts","ng://@nakedcreativity/membrs-angular-helper/lib/membrs.module.ts","ng://@nakedcreativity/membrs-angular-helper/public-api.ts","ng://@nakedcreativity/membrs-angular-helper/nakedcreativity-membrs-angular-helper.ts"],"sourcesContent":["import { InjectionToken } from '@angular/core';\nimport { MembrsConfig } from './config.interface';\n\n/**\n * This is not a real service, but it looks like it from the outside.\n * It's just an InjectionTToken used to import the config object, provided from the outside\n */\nexport const MembrsConfigService = new InjectionToken<MembrsConfig>(\"MembrsConfig\");\n","import { Injectable, Inject } from '@angular/core';\nimport { JwtHelperService } from '@auth0/angular-jwt';\nimport { HttpClient } from '@angular/common/http'\nimport { MembrsConfigService } from './config.service'\nimport { MembrsConfig } from './config.interface';\n\n@Injectable({\n providedIn: 'root'\n})\n\nexport class MembrsService {\n\n private _token: string;\n private _decoded: any;\n private _lsKey: string = 'membrs';\n\n constructor(private jwtService: JwtHelperService, private http: HttpClient, @Inject(MembrsConfigService) private config: MembrsConfig) {\n\n console.log('membrs constructor')\n // if the token exists in local storage, retrieve it back to the service\n if(localStorage.getItem(this._lsKey)){\n this.token = localStorage.getItem(this._lsKey)\n }\n \n }\n\n reissue(token?:string){\n\n return new Promise((resolve, reject)=>{\n\n if(!token && !this._token){\n console.log('reject, not logged in')\n reject('NOT_LOGGED_IN')\n }\n\n if(token)\n this.token = token\n\n // check stored token has not expired, or needs to be reissued soon\n var reissueIn = this._decoded.exp - Math.floor(Date.now()/1000)\n \n // token has expired\n if(reissueIn < 0){\n reject('NOT_LOGGED_IN')\n }\n \n // token expiring soon\n if(reissueIn < 300){\n \n console.log('expires less than 300')\n // to-do: call Apollo here\n\n this.http.post(this.config.apiProtocol + this.config.api+'/token/'+this._token, {}).subscribe((response:any)=>{\n console.log('reissue response')\n console.log(response)\n if(response.token){\n this.token = response.token\n resolve(this._token)\n }else {\n reject('NOT_LOGGED_IN')\n }\n \n }, error=>{\n reject('NOT_LOGGED_IN')\n })\n\n }else {\n console.log('token ok')\n resolve(this._token)\n }\n \n })\n \n }\n\n set token(token){\n this._token = token\n localStorage.setItem(this._lsKey, token)\n this._decoded = this.jwtService.decodeToken(this._token)\n }\n\n get profile(){\n return this._decoded\n }\n\n get admin (){\n return this.profile.permission == 1\n }\n\n logout(){\n return new Promise((resolve, reject)=>{\n this.http.get(this.config.apiProtocol+this.config.api+'/token/'+this._token+'/delete', {responseType: 'text'}).subscribe((response:any)=>{\n this._token = null;\n localStorage.removeItem(this._lsKey)\n resolve(this.config.login)\n //this.router.stateService.go('dashboard')\n }, error=>{\n reject(this.config.login)\n })\n })\n \n }\n\n\n}\n","import { UIRouter } from '@uirouter/core';\nimport { MembrsConfigService } from './config.service'\nimport { MembrsConfig } from './config.interface';\nimport { Injector } from '@angular/core';\n\nexport function routerConfigFn(router: UIRouter, injector: Injector) {\n\n const transitionService = router.transitionService;\n const stateService = router.stateService\n\n\n const config = Injector.call(MembrsConfigService)\n\n console.log('config in router config fn')\n console.log(config)\n\n// transitionService.onStart({}, (transition)=>{\n// \tconsole.log('start transition')\n// \t console.log(transition.params())\n// \t console.log(transition.paramsChanged())\n// })\n\n \tstateService.defaultErrorHandler(function(error) {\n\t\t \n\t\t// console.log('error')\n\t\t// console.log(error)\n\t\tconsole.log('default error handler')\n \t \tif(error.detail == 'NOT_LOGGED_IN')\n\t\t\twindow.location.href = config.login;\n\t\t\t//console.log(MembrsSettings)\n\n\t\tif(error.detail == 'INSUFFICIENT_PERMISSIONS')\n\t\t\tstateService.go(config.defaultState)\n\n\t});\n\t\n}","import { NgModule, ModuleWithProviders, Injector } from '@angular/core';\nimport { CommonModule } from '@angular/common';\nimport { MembrsService } from './membrs.service';\nimport { JwtModule } from \"@auth0/angular-jwt\";\nimport { HttpClientModule } from \"@angular/common/http\";\nimport { UIRouterModule } from '@uirouter/angular'\n\nimport { Ng2StateDeclaration } from '@uirouter/angular';\nimport { Transition, UIRouter } from '@uirouter/angular'\n\nimport { routerConfigFn } from './router.config';\nimport { MembrsConfig } from './config.interface';\nimport { MembrsConfigService } from './config.service';\n\nexport const validateResolve = {\n token: 'reissue',\n deps: [ Transition, UIRouter, MembrsService ],\n resolveFn: validateResolveFn\n}\n\nexport const reissueResolve = {\n token: 'reissue',\n deps: [ Transition, UIRouter, MembrsService ],\n resolveFn: reissueResolveFn\n}\n\nexport const reissueState:Ng2StateDeclaration = {\n\tname: 'reissue', \n\turl: '/reissue?token',\n\tviews: { },\n\tresolve: [\n reissueResolve\n\t]\n}\n\nexport function reissueResolveFn(transition, router, membrsService) {\n \n //console.log(membrsService)\n return new Promise((resolve, reject) => {\n console.log('reissue promise resolve')\n console.log(transition.params().token)\n membrsService.reissue(transition.params().token).then((response)=>{\n console.log('redirect to dashboard state')\n router.stateService.go('dashboard',{}, {inherit:false})\n resolve()\n }).catch(error=>{\n //window.location.href = environment.login\n reject(error)\n })\n\n\t})\n}\n\nexport function validateResolveFn(transition, router, membrsService) {\n \n //console.log(membrsService)\n return new Promise((resolve, reject) => {\n console.log('validate promise resolve')\n \n membrsService.reissue().then((response)=>{\n resolve()\n }).catch(error=>{\n //window.location.href = environment.login\n reject(error)\n })\n\n})\n}\n\n\n/** The top level state(s) */\nexport const STATES = [\n reissueState\n]\n\n\n@NgModule({\n imports: [\n CommonModule,\n HttpClientModule\n // UIRouterModule.forChild({\n // states: STATES,\n // config: routerConfigFn,\n // }),\n // JwtModule.forRoot({})\n ]\n})\n\n\n\nexport class MembrsModule { \n static forRoot(config: MembrsConfig): ModuleWithProviders<MembrsModule> {\n\n\n const moduleProviders = JwtModule.forRoot({}).providers;\n moduleProviders.push(UIRouterModule.forChild({\n states: STATES,\n config: routerConfigFn\n }).providers)\n \n moduleProviders.push(MembrsService)\n moduleProviders.push({provide: MembrsConfigService,useValue: config});\n return {\n ngModule: MembrsModule, \n providers: moduleProviders\n };\n\n\n return {\n ngModule: MembrsModule,\n providers: [\n MembrsService,\n {\n provide: MembrsConfigService,\n useValue: config\n },\n ]\n }\n }\n\n}\n","/*\n * Public API Surface of membrs\n */\n\nexport * from './lib/membrs.service';\nexport * from './lib/membrs.module';\n\nexport function retrieveToken() {\n return localStorage.getItem('membrs');\n}","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n\nexport {MembrsConfig as ɵb} from './lib/config.interface';\nexport {MembrsConfigService as ɵa} from './lib/config.service';"],"names":[],"mappings":";;;;;;;AAGA;;;;MAIa,mBAAmB,GAAG,IAAI,cAAc,CAAe,cAAc;;ICGrE,aAAa,GAA1B,MAAa,aAAa;IAMxB,YAAoB,UAA4B,EAAU,IAAgB,EAAuC,MAAoB;QAAjH,eAAU,GAAV,UAAU,CAAkB;QAAU,SAAI,GAAJ,IAAI,CAAY;QAAuC,WAAM,GAAN,MAAM,CAAc;QAF7H,WAAM,GAAW,QAAQ,CAAC;QAIhC,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAA;;QAEjC,IAAG,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAC;YACnC,IAAI,CAAC,KAAK,GAAG,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;SAC/C;KAEF;IAED,OAAO,CAAC,KAAa;QAEnB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM;YAEjC,IAAG,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,MAAM,EAAC;gBACxB,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAA;gBACpC,MAAM,CAAC,eAAe,CAAC,CAAA;aACxB;YAED,IAAG,KAAK;gBACN,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;;YAGpB,IAAI,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAC,IAAI,CAAC,CAAA;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aACF;SACF,CAAA;KACF;CAEF,CAAA;AA9BY,YAAY;IAdxB,QAAQ,CAAC;QACR,OAAO,EAAE;YACP,YAAY;YACZ,gBAAgB;;;;;;SAMjB;KACF,CAAC;GAIW,YAAY,CA8BxB;;ACxHD;;;AAIA,SAGgB,aAAa;IACzB,OAAO,YAAY,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;AAC1C,CAAC;;ACTD;;GAEG;;;;"}
@@ -0,0 +1,245 @@
1
+ import { __decorate, __param, __metadata } from 'tslib';
2
+ import { InjectionToken, Inject, ɵɵdefineInjectable, ɵɵinject, Injectable, Injector, NgModule } from '@angular/core';
3
+ import { JwtHelperService, JwtModule } from '@auth0/angular-jwt';
4
+ import { HttpClient, HttpClientModule } from '@angular/common/http';
5
+ import { CommonModule } from '@angular/common';
6
+ import { Transition, UIRouter, UIRouterModule } from '@uirouter/angular';
7
+
8
+ /**
9
+ * This is not a real service, but it looks like it from the outside.
10
+ * It's just an InjectionTToken used to import the config object, provided from the outside
11
+ */
12
+ var MembrsConfigService = new InjectionToken("MembrsConfig");
13
+
14
+ var MembrsService = /** @class */ (function () {
15
+ function MembrsService(jwtService, http, config) {
16
+ this.jwtService = jwtService;
17
+ this.http = http;
18
+ this.config = config;
19
+ this._lsKey = 'membrs';
20
+ console.log('membrs constructor');
21
+ // if the token exists in local storage, retrieve it back to the service
22
+ if (localStorage.getItem(this._lsKey)) {
23
+ this.token = localStorage.getItem(this._lsKey);
24
+ }
25
+ }
26
+ MembrsService.prototype.reissue = function (token) {
27
+ var _this = this;
28
+ return new Promise(function (resolve, reject) {
29
+ if (!token && !_this._token) {
30
+ console.log('reject, not logged in');
31
+ reject('NOT_LOGGED_IN');
32
+ }
33
+ if (token)
34
+ _this.token = token;
35
+ // check stored token has not expired, or needs to be reissued soon
36
+ var reissueIn = _this._decoded.exp - Math.floor(Date.now() / 1000);
37
+ // token has expired
38
+ if (reissueIn < 0) {
39
+ reject('NOT_LOGGED_IN');
40
+ }
41
+ // token expiring soon
42
+ if (reissueIn < 300) {
43
+ console.log('expires less than 300');
44
+ // to-do: call Apollo here
45
+ _this.http.post(_this.config.apiProtocol + _this.config.api + '/token/' + _this._token, {}).subscribe(function (response) {
46
+ console.log('reissue response');
47
+ console.log(response);
48
+ if (response.token) {
49
+ _this.token = response.token;
50
+ resolve(_this._token);
51
+ }
52
+ else {
53
+ reject('NOT_LOGGED_IN');
54
+ }
55
+ }, function (error) {
56
+ reject('NOT_LOGGED_IN');
57
+ });
58
+ }
59
+ else {
60
+ console.log('token ok');
61
+ resolve(_this._token);
62
+ }
63
+ });
64
+ };
65
+ Object.defineProperty(MembrsService.prototype, "token", {
66
+ set: function (token) {
67
+ this._token = token;
68
+ localStorage.setItem(this._lsKey, token);
69
+ this._decoded = this.jwtService.decodeToken(this._token);
70
+ },
71
+ enumerable: true,
72
+ configurable: true
73
+ });
74
+ Object.defineProperty(MembrsService.prototype, "profile", {
75
+ get: function () {
76
+ return this._decoded;
77
+ },
78
+ enumerable: true,
79
+ configurable: true
80
+ });
81
+ Object.defineProperty(MembrsService.prototype, "admin", {
82
+ get: function () {
83
+ return this.profile.permission == 1;
84
+ },
85
+ enumerable: true,
86
+ configurable: true
87
+ });
88
+ MembrsService.prototype.logout = function () {
89
+ var _this = this;
90
+ return new Promise(function (resolve, reject) {
91
+ _this.http.get(_this.config.apiProtocol + _this.config.api + '/token/' + _this._token + '/delete', { responseType: 'text' }).subscribe(function (response) {
92
+ _this._token = null;
93
+ localStorage.removeItem(_this._lsKey);
94
+ resolve(_this.config.login);
95
+ //this.router.stateService.go('dashboard')
96
+ }, function (error) {
97
+ reject(_this.config.login);
98
+ });
99
+ });
100
+ };
101
+ MembrsService.ctorParameters = function () { return [
102
+ { type: JwtHelperService },
103
+ { type: HttpClient },
104
+ { type: undefined, decorators: [{ type: Inject, args: [MembrsConfigService,] }] }
105
+ ]; };
106
+ MembrsService.ɵprov = ɵɵdefineInjectable({ factory: function MembrsService_Factory() { return new MembrsService(ɵɵinject(JwtHelperService), ɵɵinject(HttpClient), ɵɵinject(MembrsConfigService)); }, token: MembrsService, providedIn: "root" });
107
+ MembrsService = __decorate([
108
+ Injectable({
109
+ providedIn: 'root'
110
+ }),
111
+ __param(2, Inject(MembrsConfigService)),
112
+ __metadata("design:paramtypes", [JwtHelperService, HttpClient, Object])
113
+ ], MembrsService);
114
+ return MembrsService;
115
+ }());
116
+
117
+ function routerConfigFn(router, injector) {
118
+ var transitionService = router.transitionService;
119
+ var stateService = router.stateService;
120
+ var config = Injector.call(MembrsConfigService);
121
+ console.log('config in router config fn');
122
+ console.log(config);
123
+ // transitionService.onStart({}, (transition)=>{
124
+ // console.log('start transition')
125
+ // console.log(transition.params())
126
+ // console.log(transition.paramsChanged())
127
+ // })
128
+ stateService.defaultErrorHandler(function (error) {
129
+ // console.log('error')
130
+ // console.log(error)
131
+ console.log('default error handler');
132
+ if (error.detail == 'NOT_LOGGED_IN')
133
+ window.location.href = config.login;
134
+ //console.log(MembrsSettings)
135
+ if (error.detail == 'INSUFFICIENT_PERMISSIONS')
136
+ stateService.go(config.defaultState);
137
+ });
138
+ }
139
+
140
+ var validateResolve = {
141
+ token: 'reissue',
142
+ deps: [Transition, UIRouter, MembrsService],
143
+ resolveFn: validateResolveFn
144
+ };
145
+ var reissueResolve = {
146
+ token: 'reissue',
147
+ deps: [Transition, UIRouter, MembrsService],
148
+ resolveFn: reissueResolveFn
149
+ };
150
+ var reissueState = {
151
+ name: 'reissue',
152
+ url: '/reissue?token',
153
+ views: {},
154
+ resolve: [
155
+ reissueResolve
156
+ ]
157
+ };
158
+ function reissueResolveFn(transition, router, membrsService) {
159
+ //console.log(membrsService)
160
+ return new Promise(function (resolve, reject) {
161
+ console.log('reissue promise resolve');
162
+ console.log(transition.params().token);
163
+ membrsService.reissue(transition.params().token).then(function (response) {
164
+ console.log('redirect to dashboard state');
165
+ router.stateService.go('dashboard', {}, { inherit: false });
166
+ resolve();
167
+ }).catch(function (error) {
168
+ //window.location.href = environment.login
169
+ reject(error);
170
+ });
171
+ });
172
+ }
173
+ function validateResolveFn(transition, router, membrsService) {
174
+ //console.log(membrsService)
175
+ return new Promise(function (resolve, reject) {
176
+ console.log('validate promise resolve');
177
+ membrsService.reissue().then(function (response) {
178
+ resolve();
179
+ }).catch(function (error) {
180
+ //window.location.href = environment.login
181
+ reject(error);
182
+ });
183
+ });
184
+ }
185
+ /** The top level state(s) */
186
+ var STATES = [
187
+ reissueState
188
+ ];
189
+ var MembrsModule = /** @class */ (function () {
190
+ function MembrsModule() {
191
+ }
192
+ MembrsModule_1 = MembrsModule;
193
+ MembrsModule.forRoot = function (config) {
194
+ var moduleProviders = JwtModule.forRoot({}).providers;
195
+ moduleProviders.push(UIRouterModule.forChild({
196
+ states: STATES,
197
+ config: routerConfigFn
198
+ }).providers);
199
+ moduleProviders.push(MembrsService);
200
+ moduleProviders.push({ provide: MembrsConfigService, useValue: config });
201
+ return {
202
+ ngModule: MembrsModule_1,
203
+ providers: moduleProviders
204
+ };
205
+ return {
206
+ ngModule: MembrsModule_1,
207
+ providers: [
208
+ MembrsService,
209
+ {
210
+ provide: MembrsConfigService,
211
+ useValue: config
212
+ },
213
+ ]
214
+ };
215
+ };
216
+ var MembrsModule_1;
217
+ MembrsModule = MembrsModule_1 = __decorate([
218
+ NgModule({
219
+ imports: [
220
+ CommonModule,
221
+ HttpClientModule
222
+ // UIRouterModule.forChild({
223
+ // states: STATES,
224
+ // config: routerConfigFn,
225
+ // }),
226
+ // JwtModule.forRoot({})
227
+ ]
228
+ })
229
+ ], MembrsModule);
230
+ return MembrsModule;
231
+ }());
232
+
233
+ /*
234
+ * Public API Surface of membrs
235
+ */
236
+ function retrieveToken() {
237
+ return localStorage.getItem('membrs');
238
+ }
239
+
240
+ /**
241
+ * Generated bundle index. Do not edit.
242
+ */
243
+
244
+ export { MembrsModule, MembrsService, STATES, reissueResolve, reissueResolveFn, reissueState, retrieveToken, validateResolve, validateResolveFn, MembrsConfigService as ɵa };
245
+ //# sourceMappingURL=nakedcreativity-membrs-angular-helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nakedcreativity-membrs-angular-helper.js","sources":["ng://@nakedcreativity/membrs-angular-helper/lib/config.service.ts","ng://@nakedcreativity/membrs-angular-helper/lib/membrs.service.ts","ng://@nakedcreativity/membrs-angular-helper/lib/router.config.ts","ng://@nakedcreativity/membrs-angular-helper/lib/membrs.module.ts","ng://@nakedcreativity/membrs-angular-helper/public-api.ts","ng://@nakedcreativity/membrs-angular-helper/nakedcreativity-membrs-angular-helper.ts"],"sourcesContent":["import { InjectionToken } from '@angular/core';\nimport { MembrsConfig } from './config.interface';\n\n/**\n * This is not a real service, but it looks like it from the outside.\n * It's just an InjectionTToken used to import the config object, provided from the outside\n */\nexport const MembrsConfigService = new InjectionToken<MembrsConfig>(\"MembrsConfig\");\n","import { Injectable, Inject } from '@angular/core';\nimport { JwtHelperService } from '@auth0/angular-jwt';\nimport { HttpClient } from '@angular/common/http'\nimport { MembrsConfigService } from './config.service'\nimport { MembrsConfig } from './config.interface';\n\n@Injectable({\n providedIn: 'root'\n})\n\nexport class MembrsService {\n\n private _token: string;\n private _decoded: any;\n private _lsKey: string = 'membrs';\n\n constructor(private jwtService: JwtHelperService, private http: HttpClient, @Inject(MembrsConfigService) private config: MembrsConfig) {\n\n console.log('membrs constructor')\n // if the token exists in local storage, retrieve it back to the service\n if(localStorage.getItem(this._lsKey)){\n this.token = localStorage.getItem(this._lsKey)\n }\n \n }\n\n reissue(token?:string){\n\n return new Promise((resolve, reject)=>{\n\n if(!token && !this._token){\n console.log('reject, not logged in')\n reject('NOT_LOGGED_IN')\n }\n\n if(token)\n this.token = token\n\n // check stored token has not expired, or needs to be reissued soon\n var reissueIn = this._decoded.exp - Math.floor(Date.now()/1000)\n \n // token has expired\n if(reissueIn < 0){\n reject('NOT_LOGGED_IN')\n }\n \n // token expiring soon\n if(reissueIn < 300){\n \n console.log('expires less than 300')\n // to-do: call Apollo here\n\n this.http.post(this.config.apiProtocol + this.config.api+'/token/'+this._token, {}).subscribe((response:any)=>{\n console.log('reissue response')\n console.log(response)\n if(response.token){\n this.token = response.token\n resolve(this._token)\n }else {\n reject('NOT_LOGGED_IN')\n }\n \n }, error=>{\n reject('NOT_LOGGED_IN')\n })\n\n }else {\n console.log('token ok')\n resolve(this._token)\n }\n \n })\n \n }\n\n set token(token){\n this._token = token\n localStorage.setItem(this._lsKey, token)\n this._decoded = this.jwtService.decodeToken(this._token)\n }\n\n get profile(){\n return this._decoded\n }\n\n get admin (){\n return this.profile.permission == 1\n }\n\n logout(){\n return new Promise((resolve, reject)=>{\n this.http.get(this.config.apiProtocol+this.config.api+'/token/'+this._token+'/delete', {responseType: 'text'}).subscribe((response:any)=>{\n this._token = null;\n localStorage.removeItem(this._lsKey)\n resolve(this.config.login)\n //this.router.stateService.go('dashboard')\n }, error=>{\n reject(this.config.login)\n })\n })\n \n }\n\n\n}\n","import { UIRouter } from '@uirouter/core';\nimport { MembrsConfigService } from './config.service'\nimport { MembrsConfig } from './config.interface';\nimport { Injector } from '@angular/core';\n\nexport function routerConfigFn(router: UIRouter, injector: Injector) {\n\n const transitionService = router.transitionService;\n const stateService = router.stateService\n\n\n const config = Injector.call(MembrsConfigService)\n\n console.log('config in router config fn')\n console.log(config)\n\n// transitionService.onStart({}, (transition)=>{\n// \tconsole.log('start transition')\n// \t console.log(transition.params())\n// \t console.log(transition.paramsChanged())\n// })\n\n \tstateService.defaultErrorHandler(function(error) {\n\t\t \n\t\t// console.log('error')\n\t\t// console.log(error)\n\t\tconsole.log('default error handler')\n \t \tif(error.detail == 'NOT_LOGGED_IN')\n\t\t\twindow.location.href = config.login;\n\t\t\t//console.log(MembrsSettings)\n\n\t\tif(error.detail == 'INSUFFICIENT_PERMISSIONS')\n\t\t\tstateService.go(config.defaultState)\n\n\t});\n\t\n}","import { NgModule, ModuleWithProviders, Injector } from '@angular/core';\nimport { CommonModule } from '@angular/common';\nimport { MembrsService } from './membrs.service';\nimport { JwtModule } from \"@auth0/angular-jwt\";\nimport { HttpClientModule } from \"@angular/common/http\";\nimport { UIRouterModule } from '@uirouter/angular'\n\nimport { Ng2StateDeclaration } from '@uirouter/angular';\nimport { Transition, UIRouter } from '@uirouter/angular'\n\nimport { routerConfigFn } from './router.config';\nimport { MembrsConfig } from './config.interface';\nimport { MembrsConfigService } from './config.service';\n\nexport const validateResolve = {\n token: 'reissue',\n deps: [ Transition, UIRouter, MembrsService ],\n resolveFn: validateResolveFn\n}\n\nexport const reissueResolve = {\n token: 'reissue',\n deps: [ Transition, UIRouter, MembrsService ],\n resolveFn: reissueResolveFn\n}\n\nexport const reissueState:Ng2StateDeclaration = {\n\tname: 'reissue', \n\turl: '/reissue?token',\n\tviews: { },\n\tresolve: [\n reissueResolve\n\t]\n}\n\nexport function reissueResolveFn(transition, router, membrsService) {\n \n //console.log(membrsService)\n return new Promise((resolve, reject) => {\n console.log('reissue promise resolve')\n console.log(transition.params().token)\n membrsService.reissue(transition.params().token).then((response)=>{\n console.log('redirect to dashboard state')\n router.stateService.go('dashboard',{}, {inherit:false})\n resolve()\n }).catch(error=>{\n //window.location.href = environment.login\n reject(error)\n })\n\n\t})\n}\n\nexport function validateResolveFn(transition, router, membrsService) {\n \n //console.log(membrsService)\n return new Promise((resolve, reject) => {\n console.log('validate promise resolve')\n \n membrsService.reissue().then((response)=>{\n resolve()\n }).catch(error=>{\n //window.location.href = environment.login\n reject(error)\n })\n\n})\n}\n\n\n/** The top level state(s) */\nexport const STATES = [\n reissueState\n]\n\n\n@NgModule({\n imports: [\n CommonModule,\n HttpClientModule\n // UIRouterModule.forChild({\n // states: STATES,\n // config: routerConfigFn,\n // }),\n // JwtModule.forRoot({})\n ]\n})\n\n\n\nexport class MembrsModule { \n static forRoot(config: MembrsConfig): ModuleWithProviders<MembrsModule> {\n\n\n const moduleProviders = JwtModule.forRoot({}).providers;\n moduleProviders.push(UIRouterModule.forChild({\n states: STATES,\n config: routerConfigFn\n }).providers)\n \n moduleProviders.push(MembrsService)\n moduleProviders.push({provide: MembrsConfigService,useValue: config});\n return {\n ngModule: MembrsModule, \n providers: moduleProviders\n };\n\n\n return {\n ngModule: MembrsModule,\n providers: [\n MembrsService,\n {\n provide: MembrsConfigService,\n useValue: config\n },\n ]\n }\n }\n\n}\n","/*\n * Public API Surface of membrs\n */\n\nexport * from './lib/membrs.service';\nexport * from './lib/membrs.module';\n\nexport function retrieveToken() {\n return localStorage.getItem('membrs');\n}","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n\nexport {MembrsConfig as ɵb} from './lib/config.interface';\nexport {MembrsConfigService as ɵa} from './lib/config.service';"],"names":[],"mappings":";;;;;;;AAGA;;;;IAIa,mBAAmB,GAAG,IAAI,cAAc,CAAe,cAAc;;;ICShF,uBAAoB,UAA4B,EAAU,IAAgB,EAAuC,MAAoB;QAAjH,eAAU,GAAV,UAAU,CAAkB;QAAU,SAAI,GAAJ,IAAI,CAAY;QAAuC,WAAM,GAAN,MAAM,CAAc;QAF7H,WAAM,GAAW,QAAQ,CAAC;QAIhC,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAA;;QAEjC,IAAG,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAC;YACnC,IAAI,CAAC,KAAK,GAAG,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;SAC/C;KAEF;IAED,+BAAO,GAAP,UAAQ,KAAa;QAArB,iBA+CC;QA7CC,OAAO,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;YAEjC,IAAG,CAAC,KAAK,IAAI,CAAC,KAAI,CAAC,MAAM,EAAC;gBACxB,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAA;gBACpC,MAAM,CAAC,eAAe,CAAC,CAAA;aACxB;YAED,IAAG,KAAK;gBACN,KAAI,CAAC,KAAK,GAAG,KAAK,CAAA;;YAGpB,IAAI,SAAS,GAAG,KAAI,CAAC,QAAQ,CAAC,G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cAAY;YACtB,SAAS,EAAE,eAAe;SAC3B,CAAC;QAGF,OAAO;YACL,QAAQ,EAAE,cAAY;YACtB,SAAS,EAAE;gBACT,aAAa;gBACb;oBACE,OAAO,EAAE,mBAAmB;oBAC5B,QAAQ,EAAE,MAAM;iBACjB;aACF;SACF,CAAA;KACF;;IA5BU,YAAY;QAdxB,QAAQ,CAAC;YACR,OAAO,EAAE;gBACP,YAAY;gBACZ,gBAAgB;;;;;;aAMjB;SACF,CAAC;OAIW,YAAY,CA8BxB;IAAD,mBAAC;CA9BD;;AC1FA;;;AAIA,SAGgB,aAAa;IACzB,OAAO,YAAY,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;AAC1C,CAAC;;ACTD;;GAEG;;;;"}
@@ -0,0 +1,7 @@
1
+ export interface MembrsConfig {
2
+ graphQL: string;
3
+ api: string;
4
+ apiProtocol: string;
5
+ login: string;
6
+ defaultState: string;
7
+ }
@@ -0,0 +1,7 @@
1
+ import { InjectionToken } from '@angular/core';
2
+ import { MembrsConfig } from './config.interface';
3
+ /**
4
+ * This is not a real service, but it looks like it from the outside.
5
+ * It's just an InjectionTToken used to import the config object, provided from the outside
6
+ */
7
+ export declare const MembrsConfigService: InjectionToken<MembrsConfig>;
@@ -0,0 +1,23 @@
1
+ import { ModuleWithProviders } from '@angular/core';
2
+ import { MembrsService } from './membrs.service';
3
+ import { Ng2StateDeclaration } from '@uirouter/angular';
4
+ import { Transition, UIRouter } from '@uirouter/angular';
5
+ import { MembrsConfig } from './config.interface';
6
+ export declare const validateResolve: {
7
+ token: string;
8
+ deps: (typeof MembrsService | typeof Transition | typeof UIRouter)[];
9
+ resolveFn: typeof validateResolveFn;
10
+ };
11
+ export declare const reissueResolve: {
12
+ token: string;
13
+ deps: (typeof MembrsService | typeof Transition | typeof UIRouter)[];
14
+ resolveFn: typeof reissueResolveFn;
15
+ };
16
+ export declare const reissueState: Ng2StateDeclaration;
17
+ export declare function reissueResolveFn(transition: any, router: any, membrsService: any): Promise<unknown>;
18
+ export declare function validateResolveFn(transition: any, router: any, membrsService: any): Promise<unknown>;
19
+ /** The top level state(s) */
20
+ export declare const STATES: Ng2StateDeclaration[];
21
+ export declare class MembrsModule {
22
+ static forRoot(config: MembrsConfig): ModuleWithProviders<MembrsModule>;
23
+ }
@@ -0,0 +1,17 @@
1
+ import { JwtHelperService } from '@auth0/angular-jwt';
2
+ import { HttpClient } from '@angular/common/http';
3
+ import { MembrsConfig } from './config.interface';
4
+ export declare class MembrsService {
5
+ private jwtService;
6
+ private http;
7
+ private config;
8
+ private _token;
9
+ private _decoded;
10
+ private _lsKey;
11
+ constructor(jwtService: JwtHelperService, http: HttpClient, config: MembrsConfig);
12
+ reissue(token?: string): Promise<unknown>;
13
+ set token(token: any);
14
+ get profile(): any;
15
+ get admin(): boolean;
16
+ logout(): Promise<unknown>;
17
+ }
@@ -0,0 +1,3 @@
1
+ import { UIRouter } from '@uirouter/core';
2
+ import { Injector } from '@angular/core';
3
+ export declare function routerConfigFn(router: UIRouter, injector: Injector): void;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Generated bundle index. Do not edit.
3
+ */
4
+ export * from './public-api';
5
+ export { MembrsConfig as ɵb } from './lib/config.interface';
6
+ export { MembrsConfigService as ɵa } from './lib/config.service';