@webda/core 2.0.0-beta.1 → 2.0.0
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/lib/application.d.ts +9 -21
- package/lib/application.js +71 -84
- package/lib/application.js.map +1 -1
- package/lib/application.spec.js +121 -140
- package/lib/application.spec.js.map +1 -1
- package/lib/core.d.ts +86 -46
- package/lib/core.js +254 -316
- package/lib/core.js.map +1 -1
- package/lib/core.spec.js +326 -391
- package/lib/core.spec.js.map +1 -1
- package/lib/index.d.ts +49 -45
- package/lib/index.js +54 -67
- package/lib/index.js.map +1 -1
- package/lib/models/aclmodel.d.ts +2 -2
- package/lib/models/aclmodel.js +63 -90
- package/lib/models/aclmodel.js.map +1 -1
- package/lib/models/aclmodel.spec.js +127 -151
- package/lib/models/aclmodel.spec.js.map +1 -1
- package/lib/models/coremodel.d.ts +84 -11
- package/lib/models/coremodel.js +104 -103
- package/lib/models/coremodel.js.map +1 -1
- package/lib/models/coremodel.spec.js +91 -91
- package/lib/models/coremodel.spec.js.map +1 -1
- package/lib/models/deployment.js +1 -2
- package/lib/models/ident.d.ts +5 -3
- package/lib/models/ident.js +4 -9
- package/lib/models/ident.js.map +1 -1
- package/lib/models/ident.spec.js +9 -11
- package/lib/models/ident.spec.js.map +1 -1
- package/lib/models/ownermodel.d.ts +12 -2
- package/lib/models/ownermodel.js +54 -62
- package/lib/models/ownermodel.js.map +1 -1
- package/lib/models/ownermodel.spec.js +129 -152
- package/lib/models/ownermodel.spec.js.map +1 -1
- package/lib/models/rolemodel.d.ts +2 -2
- package/lib/models/rolemodel.js +24 -40
- package/lib/models/rolemodel.js.map +1 -1
- package/lib/models/rolemodel.spec.js +44 -61
- package/lib/models/rolemodel.spec.js.map +1 -1
- package/lib/models/user.d.ts +5 -5
- package/lib/models/user.js +3 -8
- package/lib/models/user.js.map +1 -1
- package/lib/models/user.spec.js +14 -16
- package/lib/models/user.spec.js.map +1 -1
- package/lib/queues/filequeue.d.ts +2 -2
- package/lib/queues/filequeue.js +72 -93
- package/lib/queues/filequeue.js.map +1 -1
- package/lib/queues/filequeue.spec.js +53 -70
- package/lib/queues/filequeue.spec.js.map +1 -1
- package/lib/queues/memoryqueue.d.ts +2 -2
- package/lib/queues/memoryqueue.js +37 -61
- package/lib/queues/memoryqueue.js.map +1 -1
- package/lib/queues/memoryqueue.spec.js +142 -165
- package/lib/queues/memoryqueue.spec.js.map +1 -1
- package/lib/queues/pubsubservice.d.ts +2 -2
- package/lib/queues/pubsubservice.js +3 -7
- package/lib/queues/pubsubservice.js.map +1 -1
- package/lib/queues/queue.spec.d.ts +1 -1
- package/lib/queues/queue.spec.js +42 -56
- package/lib/queues/queue.spec.js.map +1 -1
- package/lib/queues/queueservice.d.ts +4 -4
- package/lib/queues/queueservice.js +52 -67
- package/lib/queues/queueservice.js.map +1 -1
- package/lib/router.d.ts +7 -3
- package/lib/router.js +49 -48
- package/lib/router.js.map +1 -1
- package/lib/router.spec.js +64 -61
- package/lib/router.spec.js.map +1 -1
- package/lib/services/asyncevents.d.ts +2 -2
- package/lib/services/asyncevents.js +44 -64
- package/lib/services/asyncevents.js.map +1 -1
- package/lib/services/asyncevents.spec.js +81 -98
- package/lib/services/asyncevents.spec.js.map +1 -1
- package/lib/services/authentication.d.ts +28 -19
- package/lib/services/authentication.js +539 -571
- package/lib/services/authentication.js.map +1 -1
- package/lib/services/authentication.spec.js +411 -447
- package/lib/services/authentication.spec.js.map +1 -1
- package/lib/services/binary.d.ts +8 -6
- package/lib/services/binary.js +212 -244
- package/lib/services/binary.js.map +1 -1
- package/lib/services/binary.spec.d.ts +3 -3
- package/lib/services/binary.spec.js +390 -443
- package/lib/services/binary.spec.js.map +1 -1
- package/lib/services/cloudbinary.d.ts +3 -3
- package/lib/services/cloudbinary.js +46 -71
- package/lib/services/cloudbinary.js.map +1 -1
- package/lib/services/cloudbinary.spec.d.ts +3 -3
- package/lib/services/cloudbinary.spec.js +133 -162
- package/lib/services/cloudbinary.spec.js.map +1 -1
- package/lib/services/configuration.d.ts +6 -3
- package/lib/services/configuration.js +78 -103
- package/lib/services/configuration.js.map +1 -1
- package/lib/services/configuration.spec.js +63 -83
- package/lib/services/configuration.spec.js.map +1 -1
- package/lib/services/cron.d.ts +3 -2
- package/lib/services/cron.js +9 -13
- package/lib/services/cron.js.map +1 -1
- package/lib/services/cron.spec.js +18 -21
- package/lib/services/cron.spec.js.map +1 -1
- package/lib/services/cryptoservice.d.ts +258 -0
- package/lib/services/cryptoservice.js +312 -0
- package/lib/services/cryptoservice.js.map +1 -0
- package/lib/services/cryptoservice.spec.d.ts +1 -0
- package/lib/services/cryptoservice.spec.js +137 -0
- package/lib/services/cryptoservice.spec.js.map +1 -0
- package/lib/services/debugmailer.d.ts +1 -1
- package/lib/services/debugmailer.js +13 -34
- package/lib/services/debugmailer.js.map +1 -1
- package/lib/services/debugmailer.spec.js +16 -29
- package/lib/services/debugmailer.spec.js.map +1 -1
- package/lib/services/echo.d.ts +2 -2
- package/lib/services/echo.js +15 -31
- package/lib/services/echo.js.map +1 -1
- package/lib/services/echo.spec.js +27 -40
- package/lib/services/echo.spec.js.map +1 -1
- package/lib/services/filebinary.d.ts +15 -5
- package/lib/services/filebinary.js +171 -200
- package/lib/services/filebinary.js.map +1 -1
- package/lib/services/filebinary.spec.d.ts +2 -1
- package/lib/services/filebinary.spec.js +106 -117
- package/lib/services/filebinary.spec.js.map +1 -1
- package/lib/services/fileconfiguration.d.ts +2 -2
- package/lib/services/fileconfiguration.js +25 -43
- package/lib/services/fileconfiguration.js.map +1 -1
- package/lib/services/fileconfiguration.spec.js +79 -109
- package/lib/services/fileconfiguration.spec.js.map +1 -1
- package/lib/services/invitationservice.d.ts +9 -9
- package/lib/services/invitationservice.js +275 -313
- package/lib/services/invitationservice.js.map +1 -1
- package/lib/services/invitationservice.spec.js +442 -448
- package/lib/services/invitationservice.spec.js.map +1 -1
- package/lib/services/kubernetesconfiguration.d.ts +2 -2
- package/lib/services/kubernetesconfiguration.js +41 -59
- package/lib/services/kubernetesconfiguration.js.map +1 -1
- package/lib/services/kubernetesconfiguration.spec.js +80 -98
- package/lib/services/kubernetesconfiguration.spec.js.map +1 -1
- package/lib/services/mailer.d.ts +4 -4
- package/lib/services/mailer.js +62 -86
- package/lib/services/mailer.js.map +1 -1
- package/lib/services/mailer.spec.js +86 -127
- package/lib/services/mailer.spec.js.map +1 -1
- package/lib/services/notificationservice.d.ts +4 -4
- package/lib/services/notificationservice.js +23 -42
- package/lib/services/notificationservice.js.map +1 -1
- package/lib/services/notificationservice.spec.js +47 -73
- package/lib/services/notificationservice.spec.js.map +1 -1
- package/lib/services/oauth.d.ts +32 -6
- package/lib/services/oauth.js +73 -78
- package/lib/services/oauth.js.map +1 -1
- package/lib/services/oauth.spec.js +128 -147
- package/lib/services/oauth.spec.js.map +1 -1
- package/lib/services/proxy.d.ts +74 -0
- package/lib/services/proxy.js +126 -0
- package/lib/services/proxy.js.map +1 -0
- package/lib/services/proxy.spec.d.ts +1 -0
- package/lib/services/proxy.spec.js +59 -0
- package/lib/services/proxy.spec.js.map +1 -0
- package/lib/services/resource.d.ts +2 -2
- package/lib/services/resource.js +12 -18
- package/lib/services/resource.js.map +1 -1
- package/lib/services/resource.spec.js +67 -99
- package/lib/services/resource.spec.js.map +1 -1
- package/lib/services/service.d.ts +33 -7
- package/lib/services/service.js +74 -42
- package/lib/services/service.js.map +1 -1
- package/lib/services/service.spec.js +62 -67
- package/lib/services/service.spec.js.map +1 -1
- package/lib/services/version.d.ts +1 -1
- package/lib/services/version.js +3 -8
- package/lib/services/version.js.map +1 -1
- package/lib/services/version.spec.js +11 -24
- package/lib/services/version.spec.js.map +1 -1
- package/lib/stores/aggregator.d.ts +3 -3
- package/lib/stores/aggregator.js +37 -57
- package/lib/stores/aggregator.js.map +1 -1
- package/lib/stores/file.d.ts +3 -3
- package/lib/stores/file.js +93 -131
- package/lib/stores/file.js.map +1 -1
- package/lib/stores/file.spec.d.ts +2 -2
- package/lib/stores/file.spec.js +261 -289
- package/lib/stores/file.spec.js.map +1 -1
- package/lib/stores/mapper.d.ts +4 -4
- package/lib/stores/mapper.js +112 -137
- package/lib/stores/mapper.js.map +1 -1
- package/lib/stores/mapper.spec.js +131 -150
- package/lib/stores/mapper.spec.js.map +1 -1
- package/lib/stores/memory.d.ts +67 -6
- package/lib/stores/memory.js +155 -117
- package/lib/stores/memory.js.map +1 -1
- package/lib/stores/memory.spec.d.ts +3 -2
- package/lib/stores/memory.spec.js +127 -105
- package/lib/stores/memory.spec.js.map +1 -1
- package/lib/stores/store.d.ts +35 -15
- package/lib/stores/store.js +839 -821
- package/lib/stores/store.js.map +1 -1
- package/lib/stores/store.spec.d.ts +6 -4
- package/lib/stores/store.spec.js +627 -647
- package/lib/stores/store.spec.js.map +1 -1
- package/lib/stores/webdaql/WebdaQLLexer.d.ts +4 -4
- package/lib/stores/webdaql/WebdaQLLexer.js +9 -13
- package/lib/stores/webdaql/WebdaQLLexer.js.map +1 -1
- package/lib/stores/webdaql/WebdaQLParserLexer.d.ts +4 -4
- package/lib/stores/webdaql/WebdaQLParserLexer.js +9 -13
- package/lib/stores/webdaql/WebdaQLParserLexer.js.map +1 -1
- package/lib/stores/webdaql/WebdaQLParserListener.d.ts +2 -2
- package/lib/stores/webdaql/WebdaQLParserListener.js +1 -2
- package/lib/stores/webdaql/WebdaQLParserListener.js.map +1 -1
- package/lib/stores/webdaql/WebdaQLParserParser.d.ts +10 -10
- package/lib/stores/webdaql/WebdaQLParserParser.js +62 -91
- package/lib/stores/webdaql/WebdaQLParserParser.js.map +1 -1
- package/lib/stores/webdaql/WebdaQLParserVisitor.d.ts +2 -2
- package/lib/stores/webdaql/WebdaQLParserVisitor.js +1 -2
- package/lib/stores/webdaql/WebdaQLParserVisitor.js.map +1 -1
- package/lib/stores/webdaql/query.d.ts +4 -5
- package/lib/stores/webdaql/query.js +16 -19
- package/lib/stores/webdaql/query.js.map +1 -1
- package/lib/stores/webdaql/query.spec.js +30 -32
- package/lib/stores/webdaql/query.spec.js.map +1 -1
- package/lib/test.d.ts +3 -3
- package/lib/test.js +74 -94
- package/lib/test.js.map +1 -1
- package/lib/unpackedapplication.d.ts +1 -1
- package/lib/unpackedapplication.js +25 -31
- package/lib/unpackedapplication.js.map +1 -1
- package/lib/utils/abstractdeployer.js +1 -5
- package/lib/utils/abstractdeployer.js.map +1 -1
- package/lib/utils/abstractdeployer.spec.js +6 -8
- package/lib/utils/abstractdeployer.spec.js.map +1 -1
- package/lib/utils/context.d.ts +61 -29
- package/lib/utils/context.js +133 -127
- package/lib/utils/context.js.map +1 -1
- package/lib/utils/context.spec.js +147 -153
- package/lib/utils/context.spec.js.map +1 -1
- package/lib/utils/cookie.d.ts +66 -45
- package/lib/utils/cookie.js +69 -158
- package/lib/utils/cookie.js.map +1 -1
- package/lib/utils/cookie.spec.js +220 -238
- package/lib/utils/cookie.spec.js.map +1 -1
- package/lib/utils/esm.d.ts +4 -0
- package/lib/utils/esm.js +10 -0
- package/lib/utils/esm.js.map +1 -0
- package/lib/utils/httpcontext.d.ts +37 -9
- package/lib/utils/httpcontext.js +86 -57
- package/lib/utils/httpcontext.js.map +1 -1
- package/lib/utils/httpcontext.spec.js +37 -48
- package/lib/utils/httpcontext.spec.js.map +1 -1
- package/lib/utils/logger.d.ts +2 -2
- package/lib/utils/logger.js +15 -28
- package/lib/utils/logger.js.map +1 -1
- package/lib/utils/logger.spec.js +9 -11
- package/lib/utils/logger.spec.js.map +1 -1
- package/lib/utils/serializers.js +17 -20
- package/lib/utils/serializers.js.map +1 -1
- package/lib/utils/serializers.spec.js +43 -44
- package/lib/utils/serializers.spec.js.map +1 -1
- package/lib/utils/session.d.ts +120 -0
- package/lib/utils/session.js +155 -0
- package/lib/utils/session.js.map +1 -0
- package/lib/utils/session.spec.d.ts +1 -0
- package/lib/utils/session.spec.js +66 -0
- package/lib/utils/session.spec.js.map +1 -0
- package/lib/utils/waiter.d.ts +1 -1
- package/lib/utils/waiter.js +32 -52
- package/lib/utils/waiter.js.map +1 -1
- package/lib/utils/waiter.spec.js +75 -92
- package/lib/utils/waiter.spec.js.map +1 -1
- package/package.json +22 -14
- package/test/config-invitation.json +1 -3
- package/test/config.json +3 -3
- package/test/config.old.json +1 -2
- package/test/moddas/annotatedservice.js +5 -5
- package/test/moddas/debugmailer.js +2 -3
- package/test/moddas/fakeservice.js +2 -3
- package/test/moddas/voidstore.js +6 -4
- package/test/models/ident.js +2 -6
- package/test/models/task.js +3 -7
- package/test/package.json +2 -1
- package/webda.module.json +956 -188
|
@@ -1,37 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.MultiNotificationService = exports.MultiNotificationParameters = void 0;
|
|
13
|
-
const service_1 = require("./service");
|
|
1
|
+
import { Service, ServiceParameters } from "./service.js";
|
|
14
2
|
/**
|
|
15
3
|
* Parameters for multi notification service
|
|
16
4
|
*/
|
|
17
|
-
class MultiNotificationParameters extends
|
|
5
|
+
export class MultiNotificationParameters extends ServiceParameters {
|
|
18
6
|
/**
|
|
19
7
|
* @override
|
|
20
8
|
*/
|
|
21
9
|
constructor(params) {
|
|
22
|
-
var _a;
|
|
23
10
|
super(params);
|
|
24
|
-
|
|
11
|
+
this.senders ?? (this.senders = []);
|
|
25
12
|
}
|
|
26
13
|
}
|
|
27
|
-
exports.MultiNotificationParameters = MultiNotificationParameters;
|
|
28
14
|
/**
|
|
29
15
|
* Allow an aggregation of Notification to send via multiple media
|
|
30
16
|
* like SMS and Email
|
|
31
17
|
*
|
|
32
18
|
* @WebdaModda
|
|
33
19
|
*/
|
|
34
|
-
class MultiNotificationService extends
|
|
20
|
+
export default class MultiNotificationService extends Service {
|
|
35
21
|
/**
|
|
36
22
|
* @override
|
|
37
23
|
*/
|
|
@@ -42,6 +28,7 @@ class MultiNotificationService extends service_1.Service {
|
|
|
42
28
|
* @override
|
|
43
29
|
*/
|
|
44
30
|
resolve() {
|
|
31
|
+
super.resolve();
|
|
45
32
|
this.senders = this.parameters.senders.map(s => {
|
|
46
33
|
let service = this.getService(s);
|
|
47
34
|
if (!service) {
|
|
@@ -49,43 +36,37 @@ class MultiNotificationService extends service_1.Service {
|
|
|
49
36
|
}
|
|
50
37
|
return service;
|
|
51
38
|
});
|
|
39
|
+
return this;
|
|
52
40
|
}
|
|
53
41
|
/**
|
|
54
42
|
* @override
|
|
55
43
|
*/
|
|
56
|
-
sendNotification(user, notification, replacements) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return s;
|
|
61
|
-
}
|
|
62
|
-
})))).filter(s => s !== undefined);
|
|
63
|
-
if (!selectedSenders.length) {
|
|
64
|
-
return;
|
|
44
|
+
async sendNotification(user, notification, replacements) {
|
|
45
|
+
const selectedSenders = (await Promise.all(this.senders.map(async (s) => {
|
|
46
|
+
if ((await s.hasNotification(notification)) && (await s.handleNotificationFor(user))) {
|
|
47
|
+
return s;
|
|
65
48
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
49
|
+
}))).filter(s => s !== undefined);
|
|
50
|
+
if (!selectedSenders.length) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (!this.parameters.multiple) {
|
|
54
|
+
return selectedSenders.shift().sendNotification(user, notification, replacements);
|
|
55
|
+
}
|
|
56
|
+
await Promise.all(selectedSenders.map(s => s.sendNotification(user, notification, replacements)));
|
|
71
57
|
}
|
|
72
58
|
/**
|
|
73
59
|
* @override
|
|
74
60
|
*/
|
|
75
|
-
handleNotificationFor(user) {
|
|
76
|
-
return
|
|
77
|
-
return (yield Promise.all(this.senders.map(s => s.handleNotificationFor(user)))).some(s => s);
|
|
78
|
-
});
|
|
61
|
+
async handleNotificationFor(user) {
|
|
62
|
+
return (await Promise.all(this.senders.map(s => s.handleNotificationFor(user)))).some(s => s);
|
|
79
63
|
}
|
|
80
64
|
/**
|
|
81
65
|
* @override
|
|
82
66
|
*/
|
|
83
|
-
hasNotification(notification) {
|
|
84
|
-
return
|
|
85
|
-
return (yield Promise.all(this.senders.map(s => s.hasNotification(notification)))).some(s => s);
|
|
86
|
-
});
|
|
67
|
+
async hasNotification(notification) {
|
|
68
|
+
return (await Promise.all(this.senders.map(s => s.hasNotification(notification)))).some(s => s);
|
|
87
69
|
}
|
|
88
70
|
}
|
|
89
|
-
|
|
90
|
-
exports.MultiNotificationService = MultiNotificationService;
|
|
71
|
+
export { MultiNotificationService };
|
|
91
72
|
//# sourceMappingURL=notificationservice.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notificationservice.js","sourceRoot":"","sources":["../../src/services/notificationservice.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"notificationservice.js","sourceRoot":"","sources":["../../src/services/notificationservice.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAyBvD;;GAEG;AACH,MAAM,OAAO,2BAA4B,SAAQ,iBAAiB;IAchE;;OAEG;IACH,YAAY,MAAW;QACrB,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,OAAO,KAAZ,IAAI,CAAC,OAAO,GAAK,EAAE,EAAC;IACtB,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,CAAC,OAAO,OAAO,w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,GAAG,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,gBAAgB,CAAC,IAAI,EAAE,YAAY,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;IACpG,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,qBAAqB,CAAC,IAAkB;QAC5C,OAAO,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAChG,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,eAAe,CAAC,YAAoB;QACxC,OAAO,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAClG,CAAC;CACF;AAED,OAAO,EAAE,wBAAwB,EAAE,CAAC"}
|
|
@@ -1,104 +1,78 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
6
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
const mocha_1 = require("@testdeck/mocha");
|
|
19
|
-
const assert = require("assert");
|
|
20
|
-
const __1 = require("..");
|
|
21
|
-
const test_1 = require("../test");
|
|
22
|
-
const notificationservice_1 = require("./notificationservice");
|
|
23
|
-
class FakeNotification extends __1.Service {
|
|
7
|
+
import { suite, test } from "@testdeck/mocha";
|
|
8
|
+
import * as assert from "assert";
|
|
9
|
+
import { Service } from "...js";
|
|
10
|
+
import { WebdaTest } from "../test.js";
|
|
11
|
+
import { MultiNotificationService } from "./notificationservice.js";
|
|
12
|
+
class FakeNotification extends Service {
|
|
24
13
|
constructor() {
|
|
25
14
|
super(...arguments);
|
|
26
15
|
this.template = false;
|
|
27
16
|
this.user = false;
|
|
28
17
|
this.sent = 0;
|
|
29
18
|
}
|
|
30
|
-
hasNotification(notification) {
|
|
31
|
-
return
|
|
32
|
-
return this.template;
|
|
33
|
-
});
|
|
19
|
+
async hasNotification(notification) {
|
|
20
|
+
return this.template;
|
|
34
21
|
}
|
|
35
|
-
handleNotificationFor(user) {
|
|
36
|
-
return
|
|
37
|
-
return this.user;
|
|
38
|
-
});
|
|
22
|
+
async handleNotificationFor(user) {
|
|
23
|
+
return this.user;
|
|
39
24
|
}
|
|
40
|
-
sendNotification(user, notification, replacements) {
|
|
41
|
-
|
|
42
|
-
this.sent++;
|
|
43
|
-
});
|
|
25
|
+
async sendNotification(user, notification, replacements) {
|
|
26
|
+
this.sent++;
|
|
44
27
|
}
|
|
45
28
|
}
|
|
46
|
-
let NotificationServiceTest = class NotificationServiceTest extends
|
|
29
|
+
let NotificationServiceTest = class NotificationServiceTest extends WebdaTest {
|
|
47
30
|
getTestConfiguration() {
|
|
48
31
|
return process.cwd() + "/test/config-invitation.json";
|
|
49
32
|
}
|
|
50
|
-
before() {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
-
yield _super.before.call(this);
|
|
56
|
-
this.service = new notificationservice_1.MultiNotificationService(this.webda, "notif", {
|
|
57
|
-
senders: ["notifA", "notifB"]
|
|
58
|
-
});
|
|
59
|
-
this.fakeA = new FakeNotification(this.webda, "notifA", {});
|
|
60
|
-
this.fakeB = new FakeNotification(this.webda, "notifB", {});
|
|
61
|
-
this.registerService(this.fakeA);
|
|
62
|
-
this.registerService(this.fakeB);
|
|
63
|
-
this.registerService(this.service);
|
|
64
|
-
this.service.resolve();
|
|
33
|
+
async before() {
|
|
34
|
+
await super.before();
|
|
35
|
+
this.service = new MultiNotificationService(this.webda, "notif", {
|
|
36
|
+
senders: ["notifA", "notifB"]
|
|
65
37
|
});
|
|
38
|
+
this.fakeA = new FakeNotification(this.webda, "notifA", {});
|
|
39
|
+
this.fakeB = new FakeNotification(this.webda, "notifB", {});
|
|
40
|
+
this.registerService(this.fakeA);
|
|
41
|
+
this.registerService(this.fakeB);
|
|
42
|
+
this.registerService(this.service);
|
|
43
|
+
this.service.resolve();
|
|
66
44
|
}
|
|
67
|
-
cov() {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
assert.strictEqual(this.fakeA.sent + this.fakeB.sent, 4);
|
|
86
|
-
});
|
|
45
|
+
async cov() {
|
|
46
|
+
assert.strictEqual(await this.service.handleNotificationFor(undefined), false);
|
|
47
|
+
assert.strictEqual(await this.service.hasNotification(undefined), false);
|
|
48
|
+
this.fakeB.user = true;
|
|
49
|
+
assert.strictEqual(await this.service.handleNotificationFor(undefined), true);
|
|
50
|
+
this.fakeA.template = true;
|
|
51
|
+
assert.strictEqual(await this.service.hasNotification(undefined), true);
|
|
52
|
+
await this.service.sendNotification(undefined, undefined, undefined);
|
|
53
|
+
assert.strictEqual(this.fakeA.sent + this.fakeB.sent, 0);
|
|
54
|
+
this.fakeA.user = true;
|
|
55
|
+
await this.service.sendNotification(undefined, undefined, undefined);
|
|
56
|
+
assert.strictEqual(this.fakeA.sent + this.fakeB.sent, 1);
|
|
57
|
+
this.fakeB.template = true;
|
|
58
|
+
await this.service.sendNotification(undefined, undefined, undefined);
|
|
59
|
+
assert.strictEqual(this.fakeA.sent + this.fakeB.sent, 2);
|
|
60
|
+
this.service.getParameters().multiple = true;
|
|
61
|
+
await this.service.sendNotification(undefined, undefined, undefined);
|
|
62
|
+
assert.strictEqual(this.fakeA.sent + this.fakeB.sent, 4);
|
|
87
63
|
}
|
|
88
|
-
exception() {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
assert.throws(() => this.service.resolve(), /Unknown service 'unknown'/);
|
|
92
|
-
});
|
|
64
|
+
async exception() {
|
|
65
|
+
this.service.getParameters().senders.push("unknown");
|
|
66
|
+
assert.throws(() => this.service.resolve(), /Unknown service 'unknown'/);
|
|
93
67
|
}
|
|
94
68
|
};
|
|
95
69
|
__decorate([
|
|
96
|
-
|
|
70
|
+
test
|
|
97
71
|
], NotificationServiceTest.prototype, "cov", null);
|
|
98
72
|
__decorate([
|
|
99
|
-
|
|
73
|
+
test
|
|
100
74
|
], NotificationServiceTest.prototype, "exception", null);
|
|
101
75
|
NotificationServiceTest = __decorate([
|
|
102
|
-
|
|
76
|
+
suite
|
|
103
77
|
], NotificationServiceTest);
|
|
104
78
|
//# sourceMappingURL=notificationservice.spec.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notificationservice.spec.js","sourceRoot":"","sources":["../../src/services/notificationservice.spec.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"notificationservice.spec.js","sourceRoot":"","sources":["../../src/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AAS,CAAC,CAAC;QACrE,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;QACzD,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC;QAC3B,MAAM,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;QACrE,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;QACzD,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC,QAAQ,GAAG,IAAI,CAAC;QAC7C,MAAM,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;QACrE,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IAC3D,CAAC;IAGD,KAAK,CAAC,SAAS;QACb,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACrD,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,2BAA2B,CAAC,CAAC;IAC3E,CAAC;CACF,CAAA;AA3BC;IADC,IAAI;kDAqBJ;AAGD;IADC,IAAI;wDAIJ;AAjDG,uBAAuB;IAD5B,KAAK;GACA,uBAAuB,CAkD5B"}
|
package/lib/services/oauth.d.ts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { Authentication } from "./authentication";
|
|
4
|
-
import { Service, ServiceParameters } from "./service";
|
|
1
|
+
import { Core } from "../core.js";
|
|
2
|
+
import { Context, EventWithContext, RequestFilter } from "../index.js";
|
|
3
|
+
import { Authentication } from "./authentication.js";
|
|
4
|
+
import { Service, ServiceParameters } from "./service.js";
|
|
5
5
|
export interface EventOAuthToken extends EventWithContext {
|
|
6
6
|
/**
|
|
7
7
|
* Provider from
|
|
8
8
|
*/
|
|
9
9
|
provider: string;
|
|
10
|
+
/**
|
|
11
|
+
* token if we got a post of a JWT token
|
|
12
|
+
* callback if it was by http url
|
|
13
|
+
*/
|
|
14
|
+
type: "token" | "callback";
|
|
10
15
|
/**
|
|
11
16
|
* Profile comming from the provider
|
|
12
17
|
*/
|
|
@@ -70,8 +75,29 @@ export declare class OAuthServiceParameters extends ServiceParameters {
|
|
|
70
75
|
}
|
|
71
76
|
export declare type OAuthEvents = {
|
|
72
77
|
"OAuth.Callback": EventOAuthToken;
|
|
73
|
-
"OAuth.Token": EventOAuthToken;
|
|
74
78
|
};
|
|
79
|
+
/**
|
|
80
|
+
* OAuth Session variables
|
|
81
|
+
*/
|
|
82
|
+
export interface OAuthSession {
|
|
83
|
+
/**
|
|
84
|
+
* Store within an oauth object
|
|
85
|
+
*/
|
|
86
|
+
oauth?: {
|
|
87
|
+
/**
|
|
88
|
+
* state sent
|
|
89
|
+
*/
|
|
90
|
+
state?: string;
|
|
91
|
+
/**
|
|
92
|
+
* redirect after auth
|
|
93
|
+
*/
|
|
94
|
+
redirect?: string;
|
|
95
|
+
/**
|
|
96
|
+
* Profile retrieved
|
|
97
|
+
*/
|
|
98
|
+
profile?: any;
|
|
99
|
+
};
|
|
100
|
+
}
|
|
75
101
|
/**
|
|
76
102
|
* OAuth service implementing the default OAuth workflow
|
|
77
103
|
* It is abstract as it does not manage any provider as is
|
|
@@ -97,7 +123,7 @@ export declare abstract class OAuthService<T extends OAuthServiceParameters = OA
|
|
|
97
123
|
/**
|
|
98
124
|
* Resolve dynamic dependancy
|
|
99
125
|
*/
|
|
100
|
-
resolve():
|
|
126
|
+
resolve(): this;
|
|
101
127
|
/**
|
|
102
128
|
* Add routes for the authentication
|
|
103
129
|
*/
|
package/lib/services/oauth.js
CHANGED
|
@@ -1,31 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.OAuthService = exports.OAuthServiceParameters = void 0;
|
|
13
|
-
const service_1 = require("./service");
|
|
14
|
-
class OAuthServiceParameters extends service_1.ServiceParameters {
|
|
1
|
+
import { Service, ServiceParameters } from "./service.js";
|
|
2
|
+
export class OAuthServiceParameters extends ServiceParameters {
|
|
15
3
|
constructor(params) {
|
|
16
|
-
var _a, _b, _c;
|
|
17
4
|
super(params);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
5
|
+
this.scope ?? (this.scope = ["email"]);
|
|
6
|
+
this.exposeScope ?? (this.exposeScope = false);
|
|
7
|
+
this.authenticationService ?? (this.authenticationService = "Authentication");
|
|
21
8
|
}
|
|
22
9
|
}
|
|
23
|
-
exports.OAuthServiceParameters = OAuthServiceParameters;
|
|
24
10
|
/**
|
|
25
11
|
* OAuth service implementing the default OAuth workflow
|
|
26
12
|
* It is abstract as it does not manage any provider as is
|
|
27
13
|
*/
|
|
28
|
-
class OAuthService extends
|
|
14
|
+
export class OAuthService extends Service {
|
|
29
15
|
/**
|
|
30
16
|
* Ensure default parameter url
|
|
31
17
|
*/
|
|
@@ -50,26 +36,24 @@ class OAuthService extends service_1.Service {
|
|
|
50
36
|
* @param context
|
|
51
37
|
* @returns
|
|
52
38
|
*/
|
|
53
|
-
checkRequest(context) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
39
|
+
async checkRequest(context) {
|
|
40
|
+
// Only authorize url from this service
|
|
41
|
+
if (!context.getHttpContext().getRelativeUri().startsWith(this.parameters.url)) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
let regexps = this.getCallbackReferer();
|
|
45
|
+
let valid = false;
|
|
46
|
+
let referer = context.getHttpContext().getUniqueHeader("referer", "");
|
|
47
|
+
if (this.parameters.no_referer && referer === "") {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
for (let i in regexps) {
|
|
51
|
+
valid = referer.match(regexps[i]) !== null;
|
|
52
|
+
if (valid) {
|
|
53
|
+
break;
|
|
70
54
|
}
|
|
71
|
-
|
|
72
|
-
|
|
55
|
+
}
|
|
56
|
+
return valid;
|
|
73
57
|
}
|
|
74
58
|
/**
|
|
75
59
|
* Resolve dynamic dependancy
|
|
@@ -77,6 +61,7 @@ class OAuthService extends service_1.Service {
|
|
|
77
61
|
resolve() {
|
|
78
62
|
super.resolve();
|
|
79
63
|
this._authenticationService = this.getService(this.parameters.authenticationService);
|
|
64
|
+
return this;
|
|
80
65
|
}
|
|
81
66
|
/**
|
|
82
67
|
* Add routes for the authentication
|
|
@@ -182,11 +167,13 @@ class OAuthService extends service_1.Service {
|
|
|
182
167
|
}
|
|
183
168
|
}
|
|
184
169
|
}
|
|
170
|
+
const session = ctx.getSession();
|
|
171
|
+
session.oauth ?? (session.oauth = {});
|
|
185
172
|
// Generate 2 random uuid: nonce and state
|
|
186
|
-
|
|
173
|
+
session.oauth.state = this.getWebda().getUuid("base64");
|
|
187
174
|
// Redirect to the calling uri
|
|
188
|
-
|
|
189
|
-
ctx.redirect(this.generateAuthUrl(redirect_uri,
|
|
175
|
+
session.oauth.redirect = redirect;
|
|
176
|
+
ctx.redirect(this.generateAuthUrl(redirect_uri, session.oauth.state, ctx));
|
|
190
177
|
}
|
|
191
178
|
/**
|
|
192
179
|
* Handle a token return
|
|
@@ -194,11 +181,14 @@ class OAuthService extends service_1.Service {
|
|
|
194
181
|
* This is private to avoid any override
|
|
195
182
|
* @param context
|
|
196
183
|
*/
|
|
197
|
-
_token(context) {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
184
|
+
async _token(context) {
|
|
185
|
+
const res = await this.handleToken(context);
|
|
186
|
+
await this.handleReturn(context, res.identId, res.profile);
|
|
187
|
+
await this.emitSync("OAuth.Callback", {
|
|
188
|
+
...res,
|
|
189
|
+
type: "token",
|
|
190
|
+
provider: this.getName(),
|
|
191
|
+
context
|
|
202
192
|
});
|
|
203
193
|
}
|
|
204
194
|
/**
|
|
@@ -207,11 +197,14 @@ class OAuthService extends service_1.Service {
|
|
|
207
197
|
* This is private to avoid any override
|
|
208
198
|
* @param ctx
|
|
209
199
|
*/
|
|
210
|
-
_callback(ctx) {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
200
|
+
async _callback(ctx) {
|
|
201
|
+
const res = await this.handleCallback(ctx);
|
|
202
|
+
await this.handleReturn(ctx, res.identId, res.profile);
|
|
203
|
+
await this.emitSync("OAuth.Callback", {
|
|
204
|
+
...res,
|
|
205
|
+
type: "callback",
|
|
206
|
+
provider: this.getName(),
|
|
207
|
+
context: ctx
|
|
215
208
|
});
|
|
216
209
|
}
|
|
217
210
|
/**
|
|
@@ -220,32 +213,34 @@ class OAuthService extends service_1.Service {
|
|
|
220
213
|
* @param identId
|
|
221
214
|
* @param profile
|
|
222
215
|
*/
|
|
223
|
-
handleReturn(ctx, identId, profile, _tokens = undefined) {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
}
|
|
216
|
+
async handleReturn(ctx, identId, profile, _tokens = undefined) {
|
|
217
|
+
// If no identId has been provided error
|
|
218
|
+
if (!identId) {
|
|
219
|
+
throw 403;
|
|
220
|
+
}
|
|
221
|
+
const session = ctx.getSession();
|
|
222
|
+
session.oauth ?? (session.oauth = {});
|
|
223
|
+
// If authentication service then create a User/Ident couple
|
|
224
|
+
if (this._authenticationService) {
|
|
225
|
+
// Should call the onIdentLogin()
|
|
226
|
+
await this._authenticationService.onIdentLogin(ctx, this.getName().toLowerCase(), identId, profile);
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
// Login in session
|
|
230
|
+
ctx.getSession().login(identId, identId);
|
|
231
|
+
// Store the profile retrieved
|
|
232
|
+
session.oauth.profile = profile;
|
|
233
|
+
}
|
|
234
|
+
// Redirect to our targets
|
|
235
|
+
if (session.oauth.redirect) {
|
|
236
|
+
ctx.redirect(session.oauth.redirect);
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
ctx.write("Your authentication is successful");
|
|
240
|
+
}
|
|
241
|
+
// Clean variables from session
|
|
242
|
+
session.oauth.state = undefined;
|
|
243
|
+
session.oauth.redirect = undefined;
|
|
248
244
|
}
|
|
249
245
|
}
|
|
250
|
-
exports.OAuthService = OAuthService;
|
|
251
246
|
//# sourceMappingURL=oauth.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauth.js","sourceRoot":"","sources":["../../src/services/oauth.ts"],"names":[],"mappings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