@lenne.tech/ng-base 0.3.10 → 0.3.13
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.
- package/bundles/lenne.tech-ng-base-src-lib-base.umd.js +38 -27
- package/bundles/lenne.tech-ng-base-src-lib-base.umd.js.map +1 -1
- package/bundles/lenne.tech-ng-base.umd.js +38 -27
- package/bundles/lenne.tech-ng-base.umd.js.map +1 -1
- package/esm2015/lib/base/base.module.js +3 -2
- package/esm2015/lib/base/factories/apollo-options.factory.js +14 -24
- package/esm2015/lib/base/public-api.js +2 -1
- package/esm2015/lib/base/services/auth.service.js +9 -4
- package/esm2015/lib/base/services/ws.service.js +16 -0
- package/esm2015/src/lib/base/base.module.js +3 -2
- package/esm2015/src/lib/base/factories/apollo-options.factory.js +14 -24
- package/esm2015/src/lib/base/public-api.js +2 -1
- package/esm2015/src/lib/base/services/auth.service.js +9 -4
- package/esm2015/src/lib/base/services/ws.service.js +16 -0
- package/fesm2015/lenne.tech-ng-base-src-lib-base.js +35 -28
- package/fesm2015/lenne.tech-ng-base-src-lib-base.js.map +1 -1
- package/fesm2015/lenne.tech-ng-base.js +35 -28
- package/fesm2015/lenne.tech-ng-base.js.map +1 -1
- package/lib/base/factories/apollo-options.factory.d.ts +2 -1
- package/lib/base/public-api.d.ts +1 -0
- package/lib/base/services/auth.service.d.ts +3 -1
- package/lib/base/services/ws.service.d.ts +5 -0
- package/package.json +1 -1
- package/src/lib/base/factories/apollo-options.factory.d.ts +2 -1
- package/src/lib/base/lenne.tech-ng-base-src-lib-base.metadata.json +1 -1
- package/src/lib/base/public-api.d.ts +1 -0
- package/src/lib/base/services/auth.service.d.ts +3 -1
- package/src/lib/base/services/ws.service.d.ts +5 -0
|
@@ -146,6 +146,20 @@ StorageService.ctorParameters = () => [
|
|
|
146
146
|
{ type: undefined, decorators: [{ type: Inject, args: [BASE_MODULE_CONFIG,] }] }
|
|
147
147
|
];
|
|
148
148
|
|
|
149
|
+
class WsService {
|
|
150
|
+
reconnect() {
|
|
151
|
+
var _a, _b;
|
|
152
|
+
(_a = this.client) === null || _a === void 0 ? void 0 : _a.close();
|
|
153
|
+
(_b = this.client) === null || _b === void 0 ? void 0 : _b.connect();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
WsService.ɵprov = i0.ɵɵdefineInjectable({ factory: function WsService_Factory() { return new WsService(); }, token: WsService, providedIn: "root" });
|
|
157
|
+
WsService.decorators = [
|
|
158
|
+
{ type: Injectable, args: [{
|
|
159
|
+
providedIn: 'root',
|
|
160
|
+
},] }
|
|
161
|
+
];
|
|
162
|
+
|
|
149
163
|
/**
|
|
150
164
|
* Authentication service
|
|
151
165
|
*/
|
|
@@ -153,9 +167,10 @@ class AuthService {
|
|
|
153
167
|
/**
|
|
154
168
|
* Constructor
|
|
155
169
|
*/
|
|
156
|
-
constructor(moduleConfig, storageService) {
|
|
170
|
+
constructor(moduleConfig, storageService, wsService) {
|
|
157
171
|
this.moduleConfig = moduleConfig;
|
|
158
172
|
this.storageService = storageService;
|
|
173
|
+
this.wsService = wsService;
|
|
159
174
|
// Subjects
|
|
160
175
|
this._currentUser = new BehaviorSubject(null);
|
|
161
176
|
this._token = new BehaviorSubject(null);
|
|
@@ -192,12 +207,13 @@ class AuthService {
|
|
|
192
207
|
set token(token) {
|
|
193
208
|
this._token.next(token);
|
|
194
209
|
this.storageService.save('token', token);
|
|
210
|
+
this.wsService.reconnect();
|
|
195
211
|
}
|
|
196
212
|
get tokenObservable() {
|
|
197
213
|
return this._token.asObservable();
|
|
198
214
|
}
|
|
199
215
|
}
|
|
200
|
-
AuthService.ɵprov = i0.ɵɵdefineInjectable({ factory: function AuthService_Factory() { return new AuthService(i0.ɵɵinject(BASE_MODULE_CONFIG), i0.ɵɵinject(StorageService)); }, token: AuthService, providedIn: "root" });
|
|
216
|
+
AuthService.ɵprov = i0.ɵɵdefineInjectable({ factory: function AuthService_Factory() { return new AuthService(i0.ɵɵinject(BASE_MODULE_CONFIG), i0.ɵɵinject(StorageService), i0.ɵɵinject(WsService)); }, token: AuthService, providedIn: "root" });
|
|
201
217
|
AuthService.decorators = [
|
|
202
218
|
{ type: Injectable, args: [{
|
|
203
219
|
providedIn: 'root',
|
|
@@ -205,13 +221,14 @@ AuthService.decorators = [
|
|
|
205
221
|
];
|
|
206
222
|
AuthService.ctorParameters = () => [
|
|
207
223
|
{ type: undefined, decorators: [{ type: Inject, args: [BASE_MODULE_CONFIG,] }] },
|
|
208
|
-
{ type: StorageService }
|
|
224
|
+
{ type: StorageService },
|
|
225
|
+
{ type: WsService }
|
|
209
226
|
];
|
|
210
227
|
|
|
211
228
|
/**
|
|
212
229
|
* Factory for apollo-angular options
|
|
213
230
|
*/
|
|
214
|
-
function apolloOptionsFactory(baseModuleConfig, httpLink, authService) {
|
|
231
|
+
function apolloOptionsFactory(baseModuleConfig, httpLink, authService, wsService) {
|
|
215
232
|
const links = [];
|
|
216
233
|
const defaultUrl = 'api.' + window.location.href + '/graphql';
|
|
217
234
|
const http = httpLink.create({
|
|
@@ -229,27 +246,17 @@ function apolloOptionsFactory(baseModuleConfig, httpLink, authService) {
|
|
|
229
246
|
return forward(operation);
|
|
230
247
|
});
|
|
231
248
|
if (baseModuleConfig.wsUrl) {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
else {
|
|
246
|
-
wsClient = new WebSocketLink({
|
|
247
|
-
uri: baseModuleConfig.wsUrl,
|
|
248
|
-
options: {
|
|
249
|
-
reconnect: true,
|
|
250
|
-
},
|
|
251
|
-
});
|
|
252
|
-
}
|
|
249
|
+
const wsLink = new WebSocketLink({
|
|
250
|
+
uri: baseModuleConfig.wsUrl,
|
|
251
|
+
options: {
|
|
252
|
+
reconnect: true,
|
|
253
|
+
connectionParams: () => ({
|
|
254
|
+
Authorization: authService.token ? 'Bearer ' + authService.token : undefined,
|
|
255
|
+
}),
|
|
256
|
+
},
|
|
257
|
+
});
|
|
258
|
+
// Set client for reconnection on logout/login
|
|
259
|
+
wsService.client = wsLink.subscriptionClient;
|
|
253
260
|
// using the ability to split links, you can send data to each link
|
|
254
261
|
// depending on what kind of operation is being sent
|
|
255
262
|
links.push(split(
|
|
@@ -258,7 +265,7 @@ function apolloOptionsFactory(baseModuleConfig, httpLink, authService) {
|
|
|
258
265
|
// @ts-ignore
|
|
259
266
|
const { kind, operation } = getMainDefinition(query);
|
|
260
267
|
return kind === 'OperationDefinition' && operation === 'subscription';
|
|
261
|
-
},
|
|
268
|
+
}, wsLink, concat(authMiddleware, http)));
|
|
262
269
|
}
|
|
263
270
|
else {
|
|
264
271
|
links.push(http);
|
|
@@ -1035,7 +1042,7 @@ class BaseModule {
|
|
|
1035
1042
|
providers.push({
|
|
1036
1043
|
provide: APOLLO_OPTIONS,
|
|
1037
1044
|
useFactory: apolloOptionsFactory,
|
|
1038
|
-
deps: [BASE_MODULE_CONFIG, HttpLink, AuthService],
|
|
1045
|
+
deps: [BASE_MODULE_CONFIG, HttpLink, AuthService, WsService],
|
|
1039
1046
|
});
|
|
1040
1047
|
}
|
|
1041
1048
|
else if (config.logging) {
|
|
@@ -2416,5 +2423,5 @@ function MustMatch(controlName, matchingControlName) {
|
|
|
2416
2423
|
* Generated bundle index. Do not edit.
|
|
2417
2424
|
*/
|
|
2418
2425
|
|
|
2419
|
-
export { AuthGuard, AuthService, BASE_MODULE_CONFIG, BaseModule, BasicUser, CanDeactivateGuard, ComparisonOperatorEnum, ContextMenuDirective, EllipsesPipe, FullscreenService, GraphQLEnum, GraphQLMeta, GraphQLMetaService, GraphQLPlusService, GraphQLRequestType, GraphQLService, GraphQLType, Helper, ImageService, LazyLoadDirective, LoaderService, LogicalOperatorEnum, LogoutGuard, MatchHeightDirective, MustMatch, ResizableDirective, SEOService, SafeHtmlPipe, ScrollService, SortOrderEnum, Standard, StorageService, apolloOptionsFactory };
|
|
2426
|
+
export { AuthGuard, AuthService, BASE_MODULE_CONFIG, BaseModule, BasicUser, CanDeactivateGuard, ComparisonOperatorEnum, ContextMenuDirective, EllipsesPipe, FullscreenService, GraphQLEnum, GraphQLMeta, GraphQLMetaService, GraphQLPlusService, GraphQLRequestType, GraphQLService, GraphQLType, Helper, ImageService, LazyLoadDirective, LoaderService, LogicalOperatorEnum, LogoutGuard, MatchHeightDirective, MustMatch, ResizableDirective, SEOService, SafeHtmlPipe, ScrollService, SortOrderEnum, Standard, StorageService, WsService, apolloOptionsFactory };
|
|
2420
2427
|
//# sourceMappingURL=lenne.tech-ng-base-src-lib-base.js.map
|