@webda/core 2.0.0-beta.3 → 2.1.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 +5 -5
- 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 +21 -25
- package/lib/core.js +233 -320
- package/lib/core.js.map +1 -1
- package/lib/core.spec.js +334 -406
- package/lib/core.spec.js.map +1 -1
- package/lib/index.d.ts +49 -48
- package/lib/index.js +53 -70
- 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 +128 -152
- package/lib/models/aclmodel.spec.js.map +1 -1
- package/lib/models/coremodel.d.ts +33 -14
- package/lib/models/coremodel.js +160 -117
- package/lib/models/coremodel.js.map +1 -1
- package/lib/models/coremodel.spec.js +143 -107
- package/lib/models/coremodel.spec.js.map +1 -1
- package/lib/models/deployment.js +1 -2
- package/lib/models/ident.d.ts +3 -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 +2 -2
- package/lib/models/ownermodel.js +39 -62
- package/lib/models/ownermodel.js.map +1 -1
- package/lib/models/ownermodel.spec.js +126 -168
- package/lib/models/ownermodel.spec.js.map +1 -1
- package/lib/models/rolemodel.d.ts +1 -1
- package/lib/models/rolemodel.js +24 -40
- package/lib/models/rolemodel.js.map +1 -1
- package/lib/models/rolemodel.spec.js +44 -63
- package/lib/models/rolemodel.spec.js.map +1 -1
- package/lib/models/user.d.ts +9 -9
- 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 +3 -3
- package/lib/queues/queueservice.js +51 -67
- package/lib/queues/queueservice.js.map +1 -1
- package/lib/router.d.ts +3 -3
- package/lib/router.js +46 -47
- 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 +23 -13
- package/lib/services/authentication.js +540 -566
- 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 -245
- 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 +45 -70
- 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 +1 -1
- package/lib/services/configuration.js +78 -105
- 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 +9 -4
- package/lib/services/cryptoservice.js +187 -221
- package/lib/services/cryptoservice.js.map +1 -1
- package/lib/services/cryptoservice.spec.js +88 -115
- package/lib/services/cryptoservice.spec.js.map +1 -1
- 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 +5 -5
- package/lib/services/filebinary.js +165 -210
- package/lib/services/filebinary.js.map +1 -1
- package/lib/services/filebinary.spec.d.ts +2 -1
- package/lib/services/filebinary.spec.js +106 -116
- package/lib/services/filebinary.spec.js.map +1 -1
- package/lib/services/fileconfiguration.d.ts +1 -1
- package/lib/services/fileconfiguration.js +25 -44
- 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 +8 -8
- package/lib/services/invitationservice.js +274 -314
- package/lib/services/invitationservice.js.map +1 -1
- package/lib/services/invitationservice.spec.js +443 -449
- package/lib/services/invitationservice.spec.js.map +1 -1
- package/lib/services/kubernetesconfiguration.d.ts +1 -1
- package/lib/services/kubernetesconfiguration.js +41 -60
- 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 +3 -3
- package/lib/services/notificationservice.js +21 -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 +4 -4
- package/lib/services/oauth.js +68 -83
- package/lib/services/oauth.js.map +1 -1
- package/lib/services/oauth.spec.js +130 -156
- package/lib/services/oauth.spec.js.map +1 -1
- package/lib/services/proxy.d.ts +2 -6
- package/lib/services/proxy.js +45 -58
- package/lib/services/proxy.js.map +1 -1
- package/lib/services/proxy.spec.js +34 -53
- package/lib/services/proxy.spec.js.map +1 -1
- 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 +26 -3
- package/lib/services/service.js +68 -40
- 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 +2 -2
- package/lib/stores/aggregator.js +37 -58
- 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 +262 -289
- package/lib/stores/file.spec.js.map +1 -1
- package/lib/stores/mapper.d.ts +3 -3
- package/lib/stores/mapper.js +110 -137
- package/lib/stores/mapper.js.map +1 -1
- package/lib/stores/mapper.spec.js +133 -150
- package/lib/stores/mapper.spec.js.map +1 -1
- package/lib/stores/memory.d.ts +3 -3
- package/lib/stores/memory.js +98 -144
- package/lib/stores/memory.js.map +1 -1
- package/lib/stores/memory.spec.d.ts +2 -2
- package/lib/stores/memory.spec.js +124 -145
- package/lib/stores/memory.spec.js.map +1 -1
- package/lib/stores/store.d.ts +27 -17
- package/lib/stores/store.js +833 -849
- package/lib/stores/store.js.map +1 -1
- package/lib/stores/store.spec.d.ts +5 -4
- package/lib/stores/store.spec.js +625 -669
- 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 +73 -100
- package/lib/test.js.map +1 -1
- package/lib/unpackedapplication.d.ts +1 -1
- package/lib/unpackedapplication.js +49 -39
- 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 +7 -5
- package/lib/utils/context.js +95 -103
- package/lib/utils/context.js.map +1 -1
- package/lib/utils/context.spec.js +139 -163
- package/lib/utils/context.spec.js.map +1 -1
- package/lib/utils/cookie.d.ts +3 -3
- package/lib/utils/cookie.js +42 -61
- package/lib/utils/cookie.js.map +1 -1
- package/lib/utils/cookie.spec.js +42 -64
- 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 +3 -0
- package/lib/utils/httpcontext.js +48 -65
- package/lib/utils/httpcontext.js.map +1 -1
- package/lib/utils/httpcontext.spec.js +37 -56
- 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 +6 -6
- package/lib/utils/session.js +37 -59
- package/lib/utils/session.js.map +1 -1
- package/lib/utils/session.spec.js +38 -51
- package/lib/utils/session.spec.js.map +1 -1
- 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 +18 -13
- package/test/config-invitation.json +1 -3
- package/test/config.json +1 -2
- 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 +895 -190
|
@@ -1,29 +1,17 @@
|
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
};
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.FakeCloudBinaryTest = exports.CloudBinaryTest = void 0;
|
|
19
|
-
const mocha_1 = require("@testdeck/mocha");
|
|
20
|
-
const assert = require("assert");
|
|
21
|
-
const sinon = require("sinon");
|
|
22
|
-
const coremodel_1 = require("../models/coremodel");
|
|
23
|
-
const test_1 = require("../test");
|
|
24
|
-
const binary_spec_1 = require("./binary.spec");
|
|
25
|
-
const cloudbinary_1 = require("./cloudbinary");
|
|
26
|
-
class CloudBinaryFakeService extends cloudbinary_1.CloudBinary {
|
|
7
|
+
import { suite, test } from "@testdeck/mocha";
|
|
8
|
+
import * as assert from "assert";
|
|
9
|
+
import * as sinon from "sinon";
|
|
10
|
+
import { CoreModel } from "../models/coremodel.js";
|
|
11
|
+
import { WebdaTest } from "../test.js";
|
|
12
|
+
import { BinaryTest } from "./binary.spec.js";
|
|
13
|
+
import { CloudBinary, CloudBinaryParameters } from "./cloudbinary.js";
|
|
14
|
+
class CloudBinaryFakeService extends CloudBinary {
|
|
27
15
|
store(object, property, file, metadata) {
|
|
28
16
|
throw new Error("Method not implemented.");
|
|
29
17
|
}
|
|
@@ -33,180 +21,163 @@ class CloudBinaryFakeService extends cloudbinary_1.CloudBinary {
|
|
|
33
21
|
/**
|
|
34
22
|
* Clean usage for a hash
|
|
35
23
|
*/
|
|
36
|
-
_cleanUsage(hash, uuid) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
_get() {
|
|
40
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
-
return undefined;
|
|
42
|
-
});
|
|
24
|
+
async _cleanUsage(hash, uuid) { }
|
|
25
|
+
async _get() {
|
|
26
|
+
return undefined;
|
|
43
27
|
}
|
|
44
28
|
/**
|
|
45
29
|
* Retrieve one signed URL to download the file in parameter
|
|
46
30
|
* @param {GetSignedUrlParams} params
|
|
47
31
|
* @returns {string} URL in order to download the file
|
|
48
32
|
*/
|
|
49
|
-
getSignedUrlFromMap(map, expires) {
|
|
50
|
-
return
|
|
51
|
-
return `${map.hash}:${expires}`;
|
|
52
|
-
});
|
|
33
|
+
async getSignedUrlFromMap(map, expires) {
|
|
34
|
+
return `${map.hash}:${expires}`;
|
|
53
35
|
}
|
|
54
36
|
}
|
|
55
|
-
class CloudBinaryTest extends
|
|
56
|
-
redirectUrl() {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
assert.ok(ctx.getResponseHeaders().Location !== undefined);
|
|
63
|
-
});
|
|
37
|
+
export class CloudBinaryTest extends BinaryTest {
|
|
38
|
+
async redirectUrl() {
|
|
39
|
+
let { user1, ctx } = await this.setupDefault();
|
|
40
|
+
// Making sure we are redirected on GET
|
|
41
|
+
let executor = this.getExecutor(ctx, "test.webda.io", "GET", `/binary/users/${user1.getUuid()}/images/0`, {});
|
|
42
|
+
await executor.execute(ctx);
|
|
43
|
+
assert.ok(ctx.getResponseHeaders().Location !== undefined);
|
|
64
44
|
}
|
|
65
|
-
redirectUrlInfo() {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
assert.notStrictEqual(JSON.parse(ctx.getResponseBody()).Location, undefined);
|
|
73
|
-
});
|
|
45
|
+
async redirectUrlInfo() {
|
|
46
|
+
let { user1, ctx } = await this.setupDefault();
|
|
47
|
+
// Making sure we are redirected on GET
|
|
48
|
+
let executor = this.getExecutor(ctx, "test.webda.io", "GET", `/binary/users/${user1.getUuid()}/images/0/url`, {});
|
|
49
|
+
await executor.execute(ctx);
|
|
50
|
+
assert.ok(ctx.getResponseHeaders().Location === undefined);
|
|
51
|
+
assert.notStrictEqual(JSON.parse(ctx.getResponseBody()).Location, undefined);
|
|
74
52
|
}
|
|
75
53
|
}
|
|
76
54
|
__decorate([
|
|
77
|
-
|
|
55
|
+
test
|
|
78
56
|
], CloudBinaryTest.prototype, "redirectUrl", null);
|
|
79
57
|
__decorate([
|
|
80
|
-
|
|
58
|
+
test
|
|
81
59
|
], CloudBinaryTest.prototype, "redirectUrlInfo", null);
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
let stub = sinon.stub(service, "_cleanUsage").callsFake(() => {
|
|
90
|
-
throw new Error();
|
|
91
|
-
});
|
|
92
|
-
// Should not fail even with exception
|
|
93
|
-
yield service.cascadeDelete(binaryMap, "plop");
|
|
94
|
-
stub.restore();
|
|
95
|
-
assert.strictEqual(service._getKey("hash"), "hash/data");
|
|
96
|
-
service.getParameters().prefix = "prefix";
|
|
97
|
-
assert.strictEqual(service._getKey("hash", "plop"), "prefix/hash/plop");
|
|
98
|
-
assert.strictEqual(new cloudbinary_1.CloudBinaryParameters({}, service).prefix, "");
|
|
99
|
-
sinon.stub(service, "deleteSuccess").resolves();
|
|
100
|
-
let model = new coremodel_1.CoreModel();
|
|
101
|
-
model.load({ plop: [{}, { hash: "fake" }] }, true);
|
|
102
|
-
yield service.delete(model, "plop", 1);
|
|
103
|
-
// Check called with "fake", 1
|
|
60
|
+
let FakeCloudBinaryTest = class FakeCloudBinaryTest extends WebdaTest {
|
|
61
|
+
async testDefaults() {
|
|
62
|
+
let service = new CloudBinaryFakeService(this.webda, "fake", {});
|
|
63
|
+
let binaryMap = { hash: "test", size: 10 };
|
|
64
|
+
await service.cascadeDelete(binaryMap, "plop");
|
|
65
|
+
let stub = sinon.stub(service, "_cleanUsage").callsFake(() => {
|
|
66
|
+
throw new Error();
|
|
104
67
|
});
|
|
68
|
+
// Should not fail even with exception
|
|
69
|
+
await service.cascadeDelete(binaryMap, "plop");
|
|
70
|
+
stub.restore();
|
|
71
|
+
assert.strictEqual(service._getKey("hash"), "hash/data");
|
|
72
|
+
service.getParameters().prefix = "prefix";
|
|
73
|
+
assert.strictEqual(service._getKey("hash", "plop"), "prefix/hash/plop");
|
|
74
|
+
assert.strictEqual(new CloudBinaryParameters({}, service).prefix, "");
|
|
75
|
+
sinon.stub(service, "deleteSuccess").resolves();
|
|
76
|
+
let model = new CoreModel();
|
|
77
|
+
model.load({ plop: [{}, { hash: "fake" }] }, true);
|
|
78
|
+
await service.delete(model, "plop", 1);
|
|
79
|
+
// Check called with "fake", 1
|
|
105
80
|
}
|
|
106
|
-
initRoutes() {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
counter++;
|
|
113
|
-
});
|
|
114
|
-
service.initRoutes();
|
|
115
|
-
assert.strictEqual(counter, 0);
|
|
116
|
-
service.getParameters().expose = {
|
|
117
|
-
url: "plop",
|
|
118
|
-
restrict: {}
|
|
119
|
-
};
|
|
120
|
-
service.initRoutes();
|
|
121
|
-
assert.strictEqual(counter, 7);
|
|
122
|
-
counter = 0;
|
|
123
|
-
service.getParameters().expose = {
|
|
124
|
-
url: "plop",
|
|
125
|
-
restrict: {
|
|
126
|
-
get: true
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
service.initRoutes();
|
|
130
|
-
assert.strictEqual(counter, 4);
|
|
81
|
+
async initRoutes() {
|
|
82
|
+
let service = new CloudBinaryFakeService(this.webda, "fake", {});
|
|
83
|
+
let counter = 0;
|
|
84
|
+
// @ts-ignore addRoute is a protected method of service
|
|
85
|
+
let stub = sinon.stub(service, "addRoute").callsFake(() => {
|
|
86
|
+
counter++;
|
|
131
87
|
});
|
|
88
|
+
service.initRoutes();
|
|
89
|
+
assert.strictEqual(counter, 0);
|
|
90
|
+
service.getParameters().expose = {
|
|
91
|
+
url: "plop",
|
|
92
|
+
restrict: {}
|
|
93
|
+
};
|
|
94
|
+
service.initRoutes();
|
|
95
|
+
assert.strictEqual(counter, 7);
|
|
96
|
+
counter = 0;
|
|
97
|
+
service.getParameters().expose = {
|
|
98
|
+
url: "plop",
|
|
99
|
+
restrict: {
|
|
100
|
+
get: true
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
service.initRoutes();
|
|
104
|
+
assert.strictEqual(counter, 4);
|
|
132
105
|
}
|
|
133
|
-
routes() {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
106
|
+
async routes() {
|
|
107
|
+
let service = new CloudBinaryFakeService(this.webda, "fake", {});
|
|
108
|
+
let wrote;
|
|
109
|
+
let wroteHead;
|
|
110
|
+
let context = {
|
|
111
|
+
parameter: name => {
|
|
112
|
+
return name === "index" ? 1 : name;
|
|
113
|
+
},
|
|
114
|
+
write: (...arg) => {
|
|
115
|
+
wrote = arg;
|
|
116
|
+
},
|
|
117
|
+
writeHead: (...arg) => {
|
|
118
|
+
wroteHead = arg;
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
let storeGetResult;
|
|
122
|
+
// @ts-ignore
|
|
123
|
+
sinon.stub(service, "_verifyMapAndStore").callsFake(() => {
|
|
124
|
+
return {
|
|
125
|
+
get: async () => {
|
|
126
|
+
return storeGetResult;
|
|
147
127
|
}
|
|
148
128
|
};
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
storeGetResult = {
|
|
164
|
-
property: [1]
|
|
165
|
-
};
|
|
166
|
-
yield assert.rejects(() => service.getRedirectUrl(context), /404/);
|
|
167
|
-
let myEvt;
|
|
168
|
-
storeGetResult = {
|
|
169
|
-
property: [
|
|
170
|
-
1,
|
|
171
|
-
{
|
|
172
|
-
hash: "myhash"
|
|
173
|
-
}
|
|
174
|
-
],
|
|
175
|
-
canAct: (ctx, evt) => {
|
|
176
|
-
myEvt = evt;
|
|
177
|
-
}
|
|
178
|
-
};
|
|
179
|
-
let counter = 0;
|
|
180
|
-
service.on("Binary.Get", () => {
|
|
181
|
-
counter++;
|
|
182
|
-
});
|
|
183
|
-
yield service.getRedirectUrl(context);
|
|
184
|
-
assert.deepStrictEqual(wroteHead, [302, { Location: "myhash:30" }]);
|
|
185
|
-
yield service.getRedirectUrlInfo(context);
|
|
186
|
-
assert.strictEqual(counter, 2);
|
|
187
|
-
assert.deepStrictEqual(wrote, [
|
|
129
|
+
});
|
|
130
|
+
await assert.rejects(() => service.getRedirectUrl(context), /404/);
|
|
131
|
+
storeGetResult = {
|
|
132
|
+
property: "plop"
|
|
133
|
+
};
|
|
134
|
+
await assert.rejects(() => service.getRedirectUrl(context), /404/);
|
|
135
|
+
storeGetResult = {
|
|
136
|
+
property: [1]
|
|
137
|
+
};
|
|
138
|
+
await assert.rejects(() => service.getRedirectUrl(context), /404/);
|
|
139
|
+
let myEvt;
|
|
140
|
+
storeGetResult = {
|
|
141
|
+
property: [
|
|
142
|
+
1,
|
|
188
143
|
{
|
|
189
|
-
|
|
190
|
-
Map: {
|
|
191
|
-
hash: "myhash"
|
|
192
|
-
}
|
|
144
|
+
hash: "myhash"
|
|
193
145
|
}
|
|
194
|
-
]
|
|
195
|
-
|
|
146
|
+
],
|
|
147
|
+
canAct: (ctx, evt) => {
|
|
148
|
+
myEvt = evt;
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
let counter = 0;
|
|
152
|
+
service.on("Binary.Get", () => {
|
|
153
|
+
counter++;
|
|
196
154
|
});
|
|
155
|
+
await service.getRedirectUrl(context);
|
|
156
|
+
assert.deepStrictEqual(wroteHead, [302, { Location: "myhash:30" }]);
|
|
157
|
+
await service.getRedirectUrlInfo(context);
|
|
158
|
+
assert.strictEqual(counter, 2);
|
|
159
|
+
assert.deepStrictEqual(wrote, [
|
|
160
|
+
{
|
|
161
|
+
Location: "myhash:30",
|
|
162
|
+
Map: {
|
|
163
|
+
hash: "myhash"
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
]);
|
|
167
|
+
assert.strictEqual(myEvt, "get_binary");
|
|
197
168
|
}
|
|
198
169
|
};
|
|
199
170
|
__decorate([
|
|
200
|
-
|
|
171
|
+
test
|
|
201
172
|
], FakeCloudBinaryTest.prototype, "testDefaults", null);
|
|
202
173
|
__decorate([
|
|
203
|
-
|
|
174
|
+
test
|
|
204
175
|
], FakeCloudBinaryTest.prototype, "initRoutes", null);
|
|
205
176
|
__decorate([
|
|
206
|
-
|
|
177
|
+
test
|
|
207
178
|
], FakeCloudBinaryTest.prototype, "routes", null);
|
|
208
179
|
FakeCloudBinaryTest = __decorate([
|
|
209
|
-
|
|
180
|
+
suite
|
|
210
181
|
], FakeCloudBinaryTest);
|
|
211
|
-
|
|
182
|
+
export { FakeCloudBinaryTest };
|
|
212
183
|
//# sourceMappingURL=cloudbinary.spec.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cloudbinary.spec.js","sourceRoot":"","sources":["../../src/services/cloudbinary.spec.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cloudbinary.spec.js","sourceRoot":"","sources":["../../src/services/cloudbinary.spec.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGpC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAEnE,MAAM,sBAAuB,SAAQ,WAAW;IAC9C,KAAK,CAAC,MAAiB,EAAE,QAAgB,EAAE,IAAgB,EAAE,QAAyB;QACpF,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IACD,aAAa,CAAC,IAAY;QACxB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IACD;;OAEG;IACH,KAAK,CAAC,WAAW,CAAC,IAAY,EAAE,IAAY,IAAkB,CAAC;IAE/D,KAAK,CAAC,IAAI;QACR,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,mBAAmB,CAAC,GAAc,EAAE,OAAe;QACvD,OAAO,GAAG,GAAG,CAAC,IAAI,IAAI,OAAO,EAAE,CAAC;IAClC,CAAC;CACF;AAED,MAAM,OAAO,eAEX,SAAQ,UAAa;IAErB,KAAK,CAAC,WAAW;QACf,IA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CAAC,GAAG,EAAE,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC;QACpE,MAAM,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;QAC1C,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;QAC/B,MAAM,CAAC,eAAe,CAAC,KAAK,EAAE;YAC5B;gBACE,QAAQ,EAAE,WAAW;gBACrB,GAAG,EAAE;oBACH,IAAI,EAAE,QAAQ;iBACf;aACF;SACF,CAAC,CAAC;QACH,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;IAC1C,CAAC;CACF,CAAA;AApHC;IADC,IAAI;uDAwBJ;AAGD;IADC,IAAI;qDAyBJ;AAGD;IADC,IAAI;iDA+DJ;AAvHU,mBAAmB;IAD/B,KAAK;GACO,mBAAmB,CAwH/B;SAxHY,mBAAmB"}
|
|
@@ -1,26 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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.ConfigurationService = exports.ConfigurationServiceParameters = void 0;
|
|
13
|
-
const jsonpath = require("jsonpath");
|
|
14
|
-
const core_1 = require("../core");
|
|
15
|
-
const service_1 = require("./service");
|
|
16
|
-
class ConfigurationServiceParameters extends service_1.ServiceParameters {
|
|
1
|
+
import jsonpath from "jsonpath";
|
|
2
|
+
import { WebdaError } from "../core.js";
|
|
3
|
+
import { Service, ServiceParameters } from "./service.js";
|
|
4
|
+
export class ConfigurationServiceParameters extends ServiceParameters {
|
|
17
5
|
constructor(params) {
|
|
18
|
-
var _a;
|
|
19
6
|
super(params);
|
|
20
|
-
|
|
7
|
+
this.checkInterval ?? (this.checkInterval = 3600);
|
|
21
8
|
}
|
|
22
9
|
}
|
|
23
|
-
exports.ConfigurationServiceParameters = ConfigurationServiceParameters;
|
|
24
10
|
/**
|
|
25
11
|
* Handle sessionSecret ( rolling between two secrets ) expire every hour
|
|
26
12
|
* Handle longTermSecret ( rolling between two longer secret ) expire every month
|
|
@@ -33,7 +19,7 @@ exports.ConfigurationServiceParameters = ConfigurationServiceParameters;
|
|
|
33
19
|
* @category CoreServices
|
|
34
20
|
* @WebdaModda
|
|
35
21
|
*/
|
|
36
|
-
class ConfigurationService extends
|
|
22
|
+
export default class ConfigurationService extends Service {
|
|
37
23
|
constructor() {
|
|
38
24
|
super(...arguments);
|
|
39
25
|
/**
|
|
@@ -53,33 +39,31 @@ class ConfigurationService extends service_1.Service {
|
|
|
53
39
|
/**
|
|
54
40
|
* @inheritdoc
|
|
55
41
|
*/
|
|
56
|
-
init() {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return this;
|
|
82
|
-
});
|
|
42
|
+
async init() {
|
|
43
|
+
// Check interval by default every hour
|
|
44
|
+
if (!this.parameters.source) {
|
|
45
|
+
throw new WebdaError("CONFIGURATION_SOURCE_MISSING", "Need a source for ConfigurationService");
|
|
46
|
+
}
|
|
47
|
+
let source = this.parameters.source.split(":");
|
|
48
|
+
this.sourceService = this.getService(source[0]);
|
|
49
|
+
if (!this.sourceService) {
|
|
50
|
+
throw new WebdaError("CONFIGURATION_SOURCE_INVALID", 'Need a valid service for source ("sourceService:sourceId")');
|
|
51
|
+
}
|
|
52
|
+
this.sourceId = source[1];
|
|
53
|
+
if (!this.sourceId) {
|
|
54
|
+
throw new WebdaError("CONFIGURATION_SOURCE_INVALID", 'Need a valid source ("sourceService:sourceId")');
|
|
55
|
+
}
|
|
56
|
+
if (!this.sourceService.getConfiguration) {
|
|
57
|
+
throw new WebdaError("CONFIGURATION_SOURCE_INVALID", `Service '${source[0]}' is not implementing ConfigurationProvider interface`);
|
|
58
|
+
}
|
|
59
|
+
this.serializedConfiguration = JSON.stringify(this.parameters.default);
|
|
60
|
+
await this.checkUpdate();
|
|
61
|
+
if (!this.sourceService.canTriggerConfiguration(this.sourceId, this.checkUpdate.bind(this, true))) {
|
|
62
|
+
this.interval = setInterval(this.checkUpdate.bind(this), 1000);
|
|
63
|
+
}
|
|
64
|
+
// Add webda info
|
|
65
|
+
this.watch("$.webda.services", this._webda.reinit.bind(this._webda));
|
|
66
|
+
return this;
|
|
83
67
|
}
|
|
84
68
|
/**
|
|
85
69
|
* Watch a specific configuration modification
|
|
@@ -112,25 +96,19 @@ class ConfigurationService extends service_1.Service {
|
|
|
112
96
|
*
|
|
113
97
|
* @inheritdoc
|
|
114
98
|
*/
|
|
115
|
-
reinit(_config) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
return this;
|
|
119
|
-
});
|
|
99
|
+
async reinit(_config) {
|
|
100
|
+
// Need to prevent any reinit
|
|
101
|
+
return this;
|
|
120
102
|
}
|
|
121
103
|
/**
|
|
122
104
|
* Load the configuration by calling the source service with the source id
|
|
123
105
|
* @returns
|
|
124
106
|
*/
|
|
125
|
-
loadConfiguration() {
|
|
126
|
-
return
|
|
127
|
-
return this.sourceService.getConfiguration(this.sourceId);
|
|
128
|
-
});
|
|
107
|
+
async loadConfiguration() {
|
|
108
|
+
return this.sourceService.getConfiguration(this.sourceId);
|
|
129
109
|
}
|
|
130
|
-
initConfiguration() {
|
|
131
|
-
|
|
132
|
-
throw new Error("ConfigurationService with dependencies cannot be used");
|
|
133
|
-
});
|
|
110
|
+
async initConfiguration() {
|
|
111
|
+
throw new Error("ConfigurationService with dependencies cannot be used");
|
|
134
112
|
}
|
|
135
113
|
/**
|
|
136
114
|
* Checking for configuration updates
|
|
@@ -139,46 +117,44 @@ class ConfigurationService extends service_1.Service {
|
|
|
139
117
|
*
|
|
140
118
|
* @returns
|
|
141
119
|
*/
|
|
142
|
-
checkUpdate(dynamic = false) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
this.configuration.webda.services[i] = this.getWebda().getServiceParams(i, this.configuration.webda);
|
|
162
|
-
}
|
|
120
|
+
async checkUpdate(dynamic = false) {
|
|
121
|
+
// If the ConfigurationProvider cannot trigger we check at interval
|
|
122
|
+
if (!dynamic && this.interval && this.nextCheck > Date.now()) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
this.log("DEBUG", "Refreshing configuration");
|
|
126
|
+
const newConfig = (await this.loadConfiguration()) || this.parameters.default;
|
|
127
|
+
const serializedConfig = JSON.stringify(newConfig);
|
|
128
|
+
if (serializedConfig !== this.serializedConfiguration) {
|
|
129
|
+
this.emit("Configuration.Applying", undefined);
|
|
130
|
+
this.log("DEBUG", "Apply new configuration");
|
|
131
|
+
this.serializedConfiguration = serializedConfig;
|
|
132
|
+
this.configuration = newConfig;
|
|
133
|
+
// Add the webda parameters logical
|
|
134
|
+
if (this.configuration.webda && this.configuration.webda.services) {
|
|
135
|
+
// Merge parameters with each service
|
|
136
|
+
for (let i in this.configuration.webda.services) {
|
|
137
|
+
if (this.getWebda().getService(i)) {
|
|
138
|
+
this.configuration.webda.services[i] = this.getWebda().getServiceParams(i, this.configuration.webda);
|
|
163
139
|
}
|
|
164
140
|
}
|
|
165
|
-
let promises = [];
|
|
166
|
-
this.watchs.forEach(w => {
|
|
167
|
-
this.log("TRACE", "Apply new configuration value", jsonpath.query(newConfig, w.path).pop() || w.defaultValue);
|
|
168
|
-
let p = w.callback(jsonpath.query(newConfig, w.path).pop() || w.defaultValue);
|
|
169
|
-
if (p) {
|
|
170
|
-
promises.push(p);
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
yield Promise.all(promises);
|
|
174
|
-
this.emit("Configuration.Applied", undefined);
|
|
175
141
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
this.
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
142
|
+
let promises = [];
|
|
143
|
+
this.watchs.forEach(w => {
|
|
144
|
+
this.log("TRACE", "Apply new configuration value", jsonpath.query(newConfig, w.path).pop() || w.defaultValue);
|
|
145
|
+
let p = w.callback(jsonpath.query(newConfig, w.path).pop() || w.defaultValue);
|
|
146
|
+
if (p) {
|
|
147
|
+
promises.push(p);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
await Promise.all(promises);
|
|
151
|
+
this.emit("Configuration.Applied", undefined);
|
|
152
|
+
}
|
|
153
|
+
// If the ConfigurationProvider cannot trigger we check at interval
|
|
154
|
+
if (this.interval) {
|
|
155
|
+
this.updateNextCheck();
|
|
156
|
+
this.log("DEBUG", "Next configuration refresh in", this.parameters.checkInterval, "s");
|
|
157
|
+
}
|
|
182
158
|
}
|
|
183
159
|
/**
|
|
184
160
|
* Update the next check time
|
|
@@ -189,14 +165,11 @@ class ConfigurationService extends service_1.Service {
|
|
|
189
165
|
/**
|
|
190
166
|
* Read the file and store it
|
|
191
167
|
*/
|
|
192
|
-
loadAndStoreConfiguration() {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
return res;
|
|
197
|
-
});
|
|
168
|
+
async loadAndStoreConfiguration() {
|
|
169
|
+
let res = await this.loadConfiguration();
|
|
170
|
+
this.serializedConfiguration = JSON.stringify(res);
|
|
171
|
+
return res;
|
|
198
172
|
}
|
|
199
173
|
}
|
|
200
|
-
|
|
201
|
-
exports.ConfigurationService = ConfigurationService;
|
|
174
|
+
export { ConfigurationService };
|
|
202
175
|
//# sourceMappingURL=configuration.js.map
|