@antelopejs/dms 0.7.13 → 0.7.15
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/CHANGELOG.md +44 -0
- package/dist/db/models/userNotifications.model.js +3 -27
- package/dist/db/models/userNotifications.model.js.map +1 -1
- package/dist/implementations/dms/client-ip.d.ts +2 -0
- package/dist/implementations/dms/client-ip.js +9 -0
- package/dist/implementations/dms/client-ip.js.map +1 -0
- package/dist/implementations/dms/frontend-modules.d.ts +4 -2
- package/dist/implementations/dms/frontend-modules.js +4 -0
- package/dist/implementations/dms/frontend-modules.js.map +1 -1
- package/dist/implementations/dms/frontend-public-endpoints.d.ts +3 -0
- package/dist/implementations/dms/frontend-public-endpoints.js +70 -0
- package/dist/implementations/dms/frontend-public-endpoints.js.map +1 -0
- package/dist/implementations/dms/manifest.d.ts +1 -0
- package/dist/implementations/dms/manifest.js +3 -1
- package/dist/implementations/dms/manifest.js.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/routes/auth/client-ip.d.ts +1 -4
- package/dist/routes/auth/client-ip.js.map +1 -1
- package/dist/test/integration/notifications.test.js +6 -3
- package/dist/test/integration/notifications.test.js.map +1 -1
- package/dist/test/unit/implementations/dms/frontend-public-endpoints.test.d.ts +1 -0
- package/dist/test/unit/implementations/dms/frontend-public-endpoints.test.js +74 -0
- package/dist/test/unit/implementations/dms/frontend-public-endpoints.test.js.map +1 -0
- package/dist/test/unit/implementations/dms/manifest-strip.test.js +5 -0
- package/dist/test/unit/implementations/dms/manifest-strip.test.js.map +1 -1
- package/dist/test/unit/interfaces/dms/client-ip.test.d.ts +1 -0
- package/dist/test/unit/interfaces/dms/client-ip.test.js +61 -0
- package/dist/test/unit/interfaces/dms/client-ip.test.js.map +1 -0
- package/frontend-vue/layers/dms-core/app/composables/period/periodLink.ts +60 -0
- package/frontend-vue/layers/dms-core/app/composables/translation/useTranslation.ts +9 -4
- package/frontend-vue/layers/dms-core/app/composables/useFieldErrors.ts +34 -4
- package/frontend-vue/layers/dms-core/app/types/confirm-dialog.ts +2 -0
- package/frontend-vue/layers/dms-layout/app/build/utils/pageValidationRedirect.ts +32 -0
- package/frontend-vue/layers/dms-layout/app/emails/components/EmailLayout.vue +35 -12
- package/frontend-vue/layers/dms-layout/app/emails/components/email-logo.ts +54 -0
- package/frontend-vue/layers/dms-layout/app/emails/components/index.ts +2 -0
- package/frontend-vue/layers/dms-layout/app/pages/[...slug].vue +29 -7
- package/frontend-vue/layers/dms-layout/app/types/page.ts +2 -0
- package/frontend-vue/layers/dms-ui/app/build/components/table/FiltersRow.vue +39 -2
- package/frontend-vue/layers/dms-ui/app/build/components/table/Table.vue +18 -1
- package/frontend-vue/layers/dms-ui/app/build/composables/actions/useActionTargets.ts +28 -7
- package/frontend-vue/layers/dms-ui/app/build/composables/confirm/confirmTextMatch.ts +16 -0
- package/frontend-vue/layers/dms-ui/app/build/composables/form/formControlErrors.ts +10 -0
- package/frontend-vue/layers/dms-ui/app/build/composables/form/numberRange.ts +53 -0
- package/frontend-vue/layers/dms-ui/app/build/composables/form/useControlError.ts +8 -32
- package/frontend-vue/layers/dms-ui/app/build/composables/period/periodQuery.ts +6 -29
- package/frontend-vue/layers/dms-ui/app/build/composables/table-view/utils/recordLink.ts +34 -3
- package/frontend-vue/layers/dms-ui/app/build/composables/table-view/utils/urlFilters.ts +29 -0
- package/frontend-vue/layers/dms-ui/app/build/utils/urlVariables.ts +6 -3
- package/frontend-vue/layers/dms-ui/app/components/confirm/ConfirmModal.vue +12 -2
- package/frontend-vue/layers/dms-ui/app/components/form/Form.vue +2 -2
- package/frontend-vue/layers/dms-ui/app/components/form/components/DatePicker.vue +1 -1
- package/frontend-vue/layers/dms-ui/app/components/form/components/InputCode.vue +1 -1
- package/frontend-vue/layers/dms-ui/app/components/form/components/InputNumber.vue +47 -8
- package/frontend-vue/layers/dms-ui/app/components/form/components/InputTags.vue +1 -1
- package/frontend-vue/layers/dms-ui/app/components/form/components/InputTime.vue +1 -1
- package/frontend-vue/layers/dms-ui/app/components/form/components/KeyValue.vue +1 -1
- package/frontend-vue/layers/dms-ui/app/components/table-view/TableView.vue +61 -2
- package/frontend-vue/layers/dms-ui/app/components/top-list/TopListCard.vue +21 -1
- package/frontend-vue/layers/dms-ui/app/composables/confirm/index.ts +1 -0
- package/frontend-vue/layers/dms-ui/app/composables/confirm/types.ts +20 -0
- package/frontend-vue/layers/dms-ui/app/composables/confirm/useConfirmFrom.ts +32 -0
- package/frontend-vue/layers/dms-ui/app/composables/form/useControlError.ts +30 -0
- package/frontend-vue/layers/dms-ui/app/composables/form/useForm.ts +2 -2
- package/frontend-vue/layers/dms-ui/app/composables/table-view/types/config.ts +4 -0
- package/frontend-vue/layers/dms-ui/i18n/locales/ui-en-GB.json +6 -0
- package/frontend-vue/layers/dms-ui/i18n/locales/ui-fr-FR.json +6 -0
- package/frontend-vue/tests/confirm-from.test.ts +101 -0
- package/frontend-vue/tests/confirm-typed-text.test.ts +35 -0
- package/frontend-vue/tests/context-links.test.ts +220 -0
- package/frontend-vue/tests/control-error-path.test.ts +11 -0
- package/frontend-vue/tests/email-layout.test.ts +124 -0
- package/frontend-vue/tests/field-errors.test.ts +35 -0
- package/frontend-vue/tests/form-required-legend.test.ts +34 -0
- package/frontend-vue/tests/form-server-field-errors.test.ts +18 -1
- package/frontend-vue/tests/input-number-range.test.ts +135 -0
- package/frontend-vue/tests/input-tags.test.ts +1 -1
- package/frontend-vue/tests/page-validation-redirect.test.ts +221 -0
- package/frontend-vue/tests/row-side-panel.test.ts +2 -2
- package/frontend-vue/tests/table-url-filters.test.ts +158 -0
- package/frontend-vue/tests/table-view-bulk-drawer.test.ts +23 -0
- package/package.json +2 -2
- package/skills/dms-module/SKILL.md +3 -0
- /package/frontend-vue/layers/dms-ui/app/{build/components → components}/form/FormRequiredLegend.vue +0 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const chai_1 = require("chai");
|
|
4
|
+
const page_1 = require("../../../../implementations/dms/page");
|
|
5
|
+
const RENDERER = { name: "public-endpoints-test", version: "1" };
|
|
6
|
+
function register(name, publicEndpoints) {
|
|
7
|
+
const config = {
|
|
8
|
+
name,
|
|
9
|
+
sourcePath: process.cwd(),
|
|
10
|
+
renderer: RENDERER,
|
|
11
|
+
};
|
|
12
|
+
if (publicEndpoints)
|
|
13
|
+
config.publicEndpoints = publicEndpoints;
|
|
14
|
+
(0, page_1.AddFrontendModule)(config);
|
|
15
|
+
}
|
|
16
|
+
function endpointsOf(name) {
|
|
17
|
+
return (0, page_1.GetFrontendModules)().find((module) => module.name === name)
|
|
18
|
+
?.publicEndpoints;
|
|
19
|
+
}
|
|
20
|
+
describe("[unit] frontend module public endpoints", () => {
|
|
21
|
+
it("defaults to declaring none", () => {
|
|
22
|
+
register("public-none");
|
|
23
|
+
(0, chai_1.expect)(endpointsOf("public-none")).to.deep.equal([]);
|
|
24
|
+
});
|
|
25
|
+
it("spells out the methods and lowercases the headers", () => {
|
|
26
|
+
register("public-declared", [
|
|
27
|
+
{
|
|
28
|
+
path: "/api/mailing/events/*/*",
|
|
29
|
+
headers: ["X-Mailing-Webhook-Secret"],
|
|
30
|
+
},
|
|
31
|
+
{ path: "/api/hooks/stripe", methods: ["post", "PUT"] },
|
|
32
|
+
]);
|
|
33
|
+
(0, chai_1.expect)(endpointsOf("public-declared")).to.deep.equal([
|
|
34
|
+
{
|
|
35
|
+
path: "/api/mailing/events/*/*",
|
|
36
|
+
methods: ["POST"],
|
|
37
|
+
headers: ["x-mailing-webhook-secret"],
|
|
38
|
+
},
|
|
39
|
+
{ path: "/api/hooks/stripe", methods: ["POST", "PUT"], headers: [] },
|
|
40
|
+
]);
|
|
41
|
+
});
|
|
42
|
+
it("hands out a copy the caller cannot use to widen the declaration", () => {
|
|
43
|
+
register("public-copy", [{ path: "/api/hooks/stripe" }]);
|
|
44
|
+
endpointsOf("public-copy")?.[0]?.headers?.push("x-other");
|
|
45
|
+
(0, chai_1.expect)(endpointsOf("public-copy")?.[0]?.headers).to.deep.equal([]);
|
|
46
|
+
});
|
|
47
|
+
for (const endpoint of [
|
|
48
|
+
{ path: "/hooks/stripe" },
|
|
49
|
+
{ path: "/api/../auth/login" },
|
|
50
|
+
{ path: "/api/hooks?token=1" },
|
|
51
|
+
{ path: "/api/hooks/**" },
|
|
52
|
+
{ path: "/api" },
|
|
53
|
+
{ path: "/api/" },
|
|
54
|
+
{ path: "/api/*" },
|
|
55
|
+
{ path: "/api/*/events" },
|
|
56
|
+
{ path: "/api//hooks" },
|
|
57
|
+
{ path: "/api/hooks/" },
|
|
58
|
+
{ path: "/api/hooks/../../auth/login" },
|
|
59
|
+
{ path: "/api/hooks/./stripe" },
|
|
60
|
+
{ path: "/api/%2e%2e/auth/login" },
|
|
61
|
+
{ path: "/api/hooks\\..\\auth" },
|
|
62
|
+
{ path: "/api/hooks", methods: [] },
|
|
63
|
+
{ path: "/api/hooks", methods: ["TRACE"] },
|
|
64
|
+
{ path: "/api/hooks", headers: ["authorization"] },
|
|
65
|
+
{ path: "/api/hooks", headers: ["x-forwarded-host"] },
|
|
66
|
+
{ path: "/api/hooks", headers: ["x-dms-oauth-relay"] },
|
|
67
|
+
"/api/hooks",
|
|
68
|
+
]) {
|
|
69
|
+
it(`refuses to register ${JSON.stringify(endpoint)}`, () => {
|
|
70
|
+
(0, chai_1.expect)(() => register("public-invalid", [endpoint])).to.throw(/invalid publicEndpoints/);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
//# sourceMappingURL=frontend-public-endpoints.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frontend-public-endpoints.test.js","sourceRoot":"","sources":["../../../../../src/test/unit/implementations/dms/frontend-public-endpoints.test.ts"],"names":[],"mappings":";;AAIA,+BAA8B;AAC9B,+DAG8C;AAE9C,MAAM,QAAQ,GA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AI,EAAE,YAAY,EAAE,OAAO,EAAE,CAAC,OAAO,CAAC,EAAE;QAC1C,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,CAAC,eAAe,CAAC,EAAE;QAClD,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,CAAC,kBAAkB,CAAC,EAAE;QACrD,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,CAAC,mBAAmB,CAAC,EAAE;QACtD,YAAiD;KAClD,EAAE,CAAC;QACF,EAAE,CAAC,uBAAuB,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,EAAE;YACzD,IAAA,aAAM,EAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,gBAAgB,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAC3D,yBAAyB,CAC1B,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC,CAAC"}
|
|
@@ -15,6 +15,9 @@ function buildManifest() {
|
|
|
15
15
|
options: { baseURL: "https://api.example.com" },
|
|
16
16
|
privateOptions: { oauth: { relaySecret: "s3cret" } },
|
|
17
17
|
authEstablishEndpoints: ["/api/saas/register/finalize"],
|
|
18
|
+
publicEndpoints: [
|
|
19
|
+
{ path: "/api/hooks/*", methods: ["POST"], headers: [] },
|
|
20
|
+
],
|
|
18
21
|
},
|
|
19
22
|
{
|
|
20
23
|
name: "@scope/dms-lang-layer",
|
|
@@ -69,6 +72,7 @@ describe("[unit] manifest field policy", () => {
|
|
|
69
72
|
(0, chai_1.expect)(module).to.not.have.property("privateOptions");
|
|
70
73
|
(0, chai_1.expect)(module).to.not.have.property("path");
|
|
71
74
|
(0, chai_1.expect)(module).to.not.have.property("authEstablishEndpoints");
|
|
75
|
+
(0, chai_1.expect)(module).to.not.have.property("publicEndpoints");
|
|
72
76
|
}
|
|
73
77
|
});
|
|
74
78
|
it("serves the declared establish endpoints to an entitled caller", () => {
|
|
@@ -80,6 +84,7 @@ describe("[unit] manifest field policy", () => {
|
|
|
80
84
|
(0, chai_1.expect)(shaped.modules[0].authEstablishEndpoints).to.deep.equal([
|
|
81
85
|
"/api/saas/register/finalize",
|
|
82
86
|
]);
|
|
87
|
+
(0, chai_1.expect)(shaped.modules[0].publicEndpoints).to.have.length(1);
|
|
83
88
|
(0, chai_1.expect)(shaped.modules[1]).to.not.have.property("authEstablishEndpoints");
|
|
84
89
|
});
|
|
85
90
|
it("leaves every other field untouched", () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manifest-strip.test.js","sourceRoot":"","sources":["../../../../../src/test/unit/implementations/dms/manifest-strip.test.ts"],"names":[],"mappings":";;AAAA,+BAA8B;AAC9B,uEAIkD;AASlD,SAAS,aAAa;IACpB,OAAO;QACL,IAAI,EAAE,uBAAuB;QAC7B,OAAO,EAAE;YACP;gBACE,IAAI,EAAE,qBAAqB;gBAC3B,WAAW,EAAE,qBAAqB;gBAClC,QAAQ,EAAE,CAAC;gBACX,SAAS,EAAE,KAAK;gBAChB,IAAI,EAAE,2CAA2C;gBACjD,OAAO,EAAE,EAAE,OAAO,EAAE,yBAAyB,EAAE;gBAC/C,cAAc,EAAE,EAAE,KAAK,EAAE,EAAE,WAAW,EAAE,QAAQ,EAAE,EAAE;gBACpD,sBAAsB,EAAE,CAAC,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"manifest-strip.test.js","sourceRoot":"","sources":["../../../../../src/test/unit/implementations/dms/manifest-strip.test.ts"],"names":[],"mappings":";;AAAA,+BAA8B;AAC9B,uEAIkD;AASlD,SAAS,aAAa;IACpB,OAAO;QACL,IAAI,EAAE,uBAAuB;QAC7B,OAAO,EAAE;YACP;gBACE,IAAI,EAAE,qBAAqB;gBAC3B,WAAW,EAAE,qBAAqB;gBAClC,QAAQ,EAAE,CAAC;gBACX,SAAS,EAAE,KAAK;gBAChB,IAAI,EAAE,2CAA2C;gBACjD,OAAO,EAAE,EA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,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;QAC/D,IAAA,aAAM,EAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;QACtE,IAAA,aAAM,EAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC/C,IAAA,aAAM,EAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACpD,IAAA,aAAM,EAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC;YAC9C,OAAO,EAAE,yBAAyB;SACnC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,yCAAyC,EAAE,GAAG,EAAE;QACjD,MAAM,QAAQ,GAAG,aAAa,EAAE,CAAC;QACjC,IAAA,qCAA0B,EAAC,QAAQ,EAAE;YACnC,cAAc,EAAE,KAAK;YACrB,IAAI,EAAE,KAAK;YACX,sBAAsB,EAAE,KAAK;SAC9B,CAAC,CAAC;QACH,IAAA,aAAM,EAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const chai_1 = require("chai");
|
|
4
|
+
const client_ip_1 = require("@antelopejs/interface-dms/client-ip");
|
|
5
|
+
const config_1 = require("../../../../config");
|
|
6
|
+
const PROXY_ADDRESS = "::ffff:10.0.0.9";
|
|
7
|
+
const CLIENT_ADDRESS = "109.132.199.8";
|
|
8
|
+
const SPOOFED_ADDRESS = "1.2.3.4";
|
|
9
|
+
function requestContext(request) {
|
|
10
|
+
const headers = request.forwardedFor === undefined
|
|
11
|
+
? {}
|
|
12
|
+
: { "x-forwarded-for": request.forwardedFor };
|
|
13
|
+
return {
|
|
14
|
+
rawRequest: {
|
|
15
|
+
socket: { remoteAddress: request.socketAddress },
|
|
16
|
+
headers,
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
describe("[unit] client ip interface", () => {
|
|
21
|
+
let configured;
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
configured = (0, config_1.getAuthConfig)().trustedProxies;
|
|
24
|
+
});
|
|
25
|
+
afterEach(() => {
|
|
26
|
+
(0, config_1.getAuthConfig)().trustedProxies = configured;
|
|
27
|
+
});
|
|
28
|
+
it("answers the socket peer, unmapped, when no proxy is trusted", async () => {
|
|
29
|
+
(0, config_1.getAuthConfig)().trustedProxies = 0;
|
|
30
|
+
const context = requestContext({
|
|
31
|
+
socketAddress: PROXY_ADDRESS,
|
|
32
|
+
forwardedFor: SPOOFED_ADDRESS,
|
|
33
|
+
});
|
|
34
|
+
(0, chai_1.expect)(await (0, client_ip_1.getClientIp)(context)).to.equal("10.0.0.9");
|
|
35
|
+
});
|
|
36
|
+
it("follows auth.trustedProxies through x-forwarded-for", async () => {
|
|
37
|
+
(0, config_1.getAuthConfig)().trustedProxies = 1;
|
|
38
|
+
const context = requestContext({
|
|
39
|
+
socketAddress: PROXY_ADDRESS,
|
|
40
|
+
forwardedFor: `${SPOOFED_ADDRESS}, ${CLIENT_ADDRESS}`,
|
|
41
|
+
});
|
|
42
|
+
(0, chai_1.expect)(await (0, client_ip_1.getClientIp)(context)).to.equal(CLIENT_ADDRESS);
|
|
43
|
+
});
|
|
44
|
+
it("reads a header repeated across lines as one chain", async () => {
|
|
45
|
+
(0, config_1.getAuthConfig)().trustedProxies = 1;
|
|
46
|
+
const context = requestContext({
|
|
47
|
+
socketAddress: PROXY_ADDRESS,
|
|
48
|
+
forwardedFor: [SPOOFED_ADDRESS, CLIENT_ADDRESS],
|
|
49
|
+
});
|
|
50
|
+
(0, chai_1.expect)(await (0, client_ip_1.getClientIp)(context)).to.equal(CLIENT_ADDRESS);
|
|
51
|
+
});
|
|
52
|
+
it("resolves a source handed to ResolveClientIp directly", async () => {
|
|
53
|
+
(0, config_1.getAuthConfig)().trustedProxies = 1;
|
|
54
|
+
const resolved = await (0, client_ip_1.ResolveClientIp)({
|
|
55
|
+
socketAddress: PROXY_ADDRESS,
|
|
56
|
+
forwardedFor: CLIENT_ADDRESS,
|
|
57
|
+
});
|
|
58
|
+
(0, chai_1.expect)(resolved).to.equal(CLIENT_ADDRESS);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
//# sourceMappingURL=client-ip.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-ip.test.js","sourceRoot":"","sources":["../../../../../src/test/unit/interfaces/dms/client-ip.test.ts"],"names":[],"mappings":";;AACA,+BAA8B;AAC9B,mEAG6C;AAC7C,+CAAmD;AAEnD,MAAM,aAAa,GAAG,iBAAiB,CAAC;AACxC,MAAM,cAAc,GAAG,eAAe,CAAC;AACvC,MAAM,eAAe,GAAG,SAAS,CAAC;AAOlC,SAAS,cAAc,CAAC,OAAoB;IAC1C,MAAM,OAAO,GACX,OAAO,CAAC,YAAY,KAAK,SAAS;QAChC,CAAC,CAAC,EAAE;QACJ,CAAC,CAAC,EAAE,iBAAiB,EAAE,OAAO,CAAC,YAAY,EAAE,CAAC;IAClD,OAAO;QACL,UAAU,EAAE;YACV,MAAM,EAAE,EAAE,aAAa,EAAE,OAAO,CAAC,aAAa,EAAE;YAChD,OAAO;SACR;KAC2B,CAAC;AACjC,CAAC;AAED,QA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,CAAC,CAAC;QACH,IAAA,aAAM,EAAC,MAAM,IAAA,uBAAW,EAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;IAC9D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,sDAAsD,EAAE,KAAK,IAAI,EAAE;QACpE,IAAA,sBAAa,GAAE,CAAC,cAAc,GAAG,CAAC,CAAC;QACnC,MAAM,QAAQ,GAAG,MAAM,IAAA,2BAAe,EAAC;YACrC,aAAa,EAAE,aAAa;YAC5B,YAAY,EAAE,cAAc;SAC7B,CAAC,CAAC;QACH,IAAA,aAAM,EAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;IAC5C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/** The keys one `PeriodSelector` keeps its period under in the page URL. */
|
|
2
|
+
export interface PeriodQueryKeys {
|
|
3
|
+
period: string;
|
|
4
|
+
compare: string;
|
|
5
|
+
from: string;
|
|
6
|
+
to: string;
|
|
7
|
+
compareFrom: string;
|
|
8
|
+
compareTo: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const KEY_NAMES: Array<keyof PeriodQueryKeys> = [
|
|
12
|
+
"period",
|
|
13
|
+
"compare",
|
|
14
|
+
"from",
|
|
15
|
+
"to",
|
|
16
|
+
"compareFrom",
|
|
17
|
+
"compareTo",
|
|
18
|
+
];
|
|
19
|
+
const QUERY_SEPARATOR = "?";
|
|
20
|
+
const FRAGMENT_SEPARATOR = "#";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The keys of selector `id` in the page URL (`<id>.period`), or the bare keys
|
|
24
|
+
* (`period`) of a selection kept on its own.
|
|
25
|
+
*/
|
|
26
|
+
export function periodQueryKeys(id?: string): PeriodQueryKeys {
|
|
27
|
+
const prefix = id ? `${id}.` : "";
|
|
28
|
+
return Object.fromEntries(
|
|
29
|
+
KEY_NAMES.map((name) => [name, `${prefix}${name}`]),
|
|
30
|
+
) as unknown as PeriodQueryKeys;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function firstText(value: unknown): string | undefined {
|
|
34
|
+
const text = Array.isArray(value) ? value[0] : value;
|
|
35
|
+
return typeof text === "string" && text ? text : undefined;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* `link` carrying the period selector `id` shows in `query` (the route query
|
|
40
|
+
* of the page it is followed from), so the page it opens, holding a selector
|
|
41
|
+
* with the same `id`, shows the same period. A key the link names itself
|
|
42
|
+
* wins, and a key the query does not hold is left out.
|
|
43
|
+
*/
|
|
44
|
+
export function withPeriodQuery(
|
|
45
|
+
link: string,
|
|
46
|
+
query: Record<string, unknown>,
|
|
47
|
+
id: string,
|
|
48
|
+
): string {
|
|
49
|
+
const [beforeFragment = "", ...fragment] = link.split(FRAGMENT_SEPARATOR);
|
|
50
|
+
const [path = "", ...search] = beforeFragment.split(QUERY_SEPARATOR);
|
|
51
|
+
const params = new URLSearchParams(search.join(QUERY_SEPARATOR));
|
|
52
|
+
for (const key of Object.values(periodQueryKeys(id))) {
|
|
53
|
+
const value = firstText(query[key]);
|
|
54
|
+
if (value && !params.has(key)) params.set(key, value);
|
|
55
|
+
}
|
|
56
|
+
const text = params.toString();
|
|
57
|
+
return [text ? `${path}${QUERY_SEPARATOR}${text}` : path, ...fragment].join(
|
|
58
|
+
FRAGMENT_SEPARATOR,
|
|
59
|
+
);
|
|
60
|
+
}
|
|
@@ -49,15 +49,17 @@ export function resolveI18nKey(
|
|
|
49
49
|
* (`$page.settings.invites.error.not_found`). `translate` echoes the key back
|
|
50
50
|
* when no translation exists in the active locale or its fallbacks: a message
|
|
51
51
|
* marked with `$` then falls back to the bare key, and an unmarked one — which
|
|
52
|
-
* may well be plain prose — is shown as it came in.
|
|
52
|
+
* may well be plain prose — is shown as it came in. `params` fill the
|
|
53
|
+
* translation's placeholders (`"At most {max}"` with `{ max: 5000 }`).
|
|
53
54
|
*/
|
|
54
55
|
export function resolveApiMessage(
|
|
55
56
|
translate: I18nTranslate,
|
|
56
57
|
message: unknown,
|
|
58
|
+
params?: Record<string, unknown> | null,
|
|
57
59
|
): string {
|
|
58
60
|
const text = typeof message === "string" ? message : String(message);
|
|
59
61
|
const marked = readTranslationKey(text);
|
|
60
|
-
const translated = translate(marked.key, {});
|
|
62
|
+
const translated = translate(marked.key, params ?? {});
|
|
61
63
|
|
|
62
64
|
if (translated !== marked.key) return translated;
|
|
63
65
|
return marked.isKey ? marked.key : text;
|
|
@@ -93,8 +95,11 @@ export const useTranslation = () => {
|
|
|
93
95
|
return resolveI18nKey(t, key, params);
|
|
94
96
|
}
|
|
95
97
|
|
|
96
|
-
function processApiMessage(
|
|
97
|
-
|
|
98
|
+
function processApiMessage(
|
|
99
|
+
message: unknown,
|
|
100
|
+
params?: Record<string, unknown> | null,
|
|
101
|
+
) {
|
|
102
|
+
return resolveApiMessage(t, message, params);
|
|
98
103
|
}
|
|
99
104
|
|
|
100
105
|
return {
|
|
@@ -22,6 +22,12 @@ export interface ApiFieldError {
|
|
|
22
22
|
message: string;
|
|
23
23
|
/** The values of the field the error names (addresses of a list…). */
|
|
24
24
|
values?: string[];
|
|
25
|
+
/**
|
|
26
|
+
* Values filling the placeholders of the translated message: a body
|
|
27
|
+
* `{ field: "budget", message: "$page.error.budget_max", params: { max: 5000 } }`
|
|
28
|
+
* shows "At most 5000" for a translation `"At most {max}"`.
|
|
29
|
+
*/
|
|
30
|
+
params?: ApiFieldErrorParams;
|
|
25
31
|
/**
|
|
26
32
|
* The part of the field the error names, as a dotted path from the field
|
|
27
33
|
* (`address.streetName`, `title.fr`); absent when it names the field.
|
|
@@ -29,6 +35,9 @@ export interface ApiFieldError {
|
|
|
29
35
|
path?: string;
|
|
30
36
|
}
|
|
31
37
|
|
|
38
|
+
/** Placeholder values of a field error's message. */
|
|
39
|
+
export type ApiFieldErrorParams = Record<string, string | number | boolean>;
|
|
40
|
+
|
|
32
41
|
/** A code the API answers with that belongs to a field. */
|
|
33
42
|
export type FieldErrorCode<F extends string = string> =
|
|
34
43
|
| F
|
|
@@ -224,10 +233,26 @@ function fromIssues(issues: ValidationIssue[]): ApiFieldError[] {
|
|
|
224
233
|
});
|
|
225
234
|
}
|
|
226
235
|
|
|
227
|
-
|
|
236
|
+
const PARAM_TYPES = new Set(["string", "number", "boolean"]);
|
|
237
|
+
|
|
238
|
+
/** The placeholder values of a body, keeping only the plain ones. */
|
|
239
|
+
function paramsOf(params: unknown): ApiFieldErrorParams | undefined {
|
|
240
|
+
if (typeof params !== "object" || params === null || Array.isArray(params)) {
|
|
241
|
+
return undefined;
|
|
242
|
+
}
|
|
243
|
+
const entries = Object.entries(params).filter(([, value]) =>
|
|
244
|
+
PARAM_TYPES.has(typeof value),
|
|
245
|
+
);
|
|
246
|
+
return entries.length > 0
|
|
247
|
+
? (Object.fromEntries(entries) as ApiFieldErrorParams)
|
|
248
|
+
: undefined;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/** `{ field, message, values?, params? }`, the shape the DMS answers with. */
|
|
228
252
|
function fromFieldObject(body: Record<string, unknown>): ApiFieldError[] {
|
|
229
|
-
const { field, message, values } = body;
|
|
253
|
+
const { field, message, values, params } = body;
|
|
230
254
|
if (typeof field !== "string" || typeof message !== "string") return [];
|
|
255
|
+
const placeholders = paramsOf(params);
|
|
231
256
|
return [
|
|
232
257
|
{
|
|
233
258
|
field,
|
|
@@ -235,6 +260,7 @@ function fromFieldObject(body: Record<string, unknown>): ApiFieldError[] {
|
|
|
235
260
|
values: Array.isArray(values)
|
|
236
261
|
? values.filter((value): value is string => typeof value === "string")
|
|
237
262
|
: undefined,
|
|
263
|
+
...(placeholders && { params: placeholders }),
|
|
238
264
|
},
|
|
239
265
|
];
|
|
240
266
|
}
|
|
@@ -311,7 +337,7 @@ function isClientError(status: number | undefined): status is number {
|
|
|
311
337
|
*
|
|
312
338
|
* Read, in order: a code the form maps to a field (`codes`, for any 4xx), a
|
|
313
339
|
* zod issue list (what `assertValidation` answers), a `{ field, message }`
|
|
314
|
-
* body, the data API's "Missing mandatory fields: a, b" / "Invalid field
|
|
340
|
+
* body (with optional `values` and `params`), the data API's "Missing mandatory fields: a, b" / "Invalid field
|
|
315
341
|
* type(s): a" and a `field: message` text. A network failure, a 403, a 429
|
|
316
342
|
* or a 5xx never resolves to a field.
|
|
317
343
|
*
|
|
@@ -478,7 +504,11 @@ export function useFieldErrors<F extends string>(
|
|
|
478
504
|
if (fields.length === 0) return false;
|
|
479
505
|
clear();
|
|
480
506
|
for (const entry of fields) {
|
|
481
|
-
errors[entry.field as F] = resolveApiMessage(
|
|
507
|
+
errors[entry.field as F] = resolveApiMessage(
|
|
508
|
+
translate,
|
|
509
|
+
entry.message,
|
|
510
|
+
entry.params,
|
|
511
|
+
);
|
|
482
512
|
}
|
|
483
513
|
await focus(fields[0]!.field as F);
|
|
484
514
|
return true;
|
|
@@ -83,6 +83,8 @@ export interface ConfirmDialog {
|
|
|
83
83
|
blocked?: boolean;
|
|
84
84
|
/** Text the user must type to confirm. */
|
|
85
85
|
confirmText?: string;
|
|
86
|
+
/** Compares the typed text with `confirmText` ignoring case. */
|
|
87
|
+
confirmTextCaseInsensitive?: boolean;
|
|
86
88
|
/** Fields whose values are sent with the action's request. */
|
|
87
89
|
fields?: ConfirmDialogField[];
|
|
88
90
|
/** A component drawn in the dialog's body. */
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { parseURL, withoutTrailingSlash } from "ufo";
|
|
2
|
+
import {
|
|
3
|
+
type ReplaceUrlVariablesContext,
|
|
4
|
+
resolveLinkVariables,
|
|
5
|
+
} from "#dms-ui/app/build/utils/urlVariables";
|
|
6
|
+
import type { PageValidation } from "../../types/page";
|
|
7
|
+
|
|
8
|
+
const ROOT_PATH = "/";
|
|
9
|
+
|
|
10
|
+
function normalizePath(path: string): string {
|
|
11
|
+
return withoutTrailingSlash(path) || ROOT_PATH;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Where a page that failed its validation sends the user: its `redirectTo`
|
|
16
|
+
* with the page URL's tokens filled, or `undefined` for the not-found error.
|
|
17
|
+
* A target on the page's own path would fail the same way again, so it is
|
|
18
|
+
* refused as well.
|
|
19
|
+
*/
|
|
20
|
+
export function pageValidationRedirect(
|
|
21
|
+
validation: PageValidation | undefined,
|
|
22
|
+
currentPath: string,
|
|
23
|
+
context: ReplaceUrlVariablesContext,
|
|
24
|
+
): string | undefined {
|
|
25
|
+
if (!validation?.redirectTo) return undefined;
|
|
26
|
+
const target = resolveLinkVariables(validation.redirectTo, context);
|
|
27
|
+
const targetPath = parseURL(target).pathname;
|
|
28
|
+
if (!targetPath || normalizePath(targetPath) === normalizePath(currentPath)) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
return target;
|
|
32
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import { emailStyles } from "./index";
|
|
2
|
+
import { emailLogoUrl, emailStyles } from "./index";
|
|
3
3
|
|
|
4
4
|
interface EmailAppConfig {
|
|
5
5
|
branding?: {
|
|
@@ -11,38 +11,61 @@ interface EmailAppConfig {
|
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
const props = withDefaults(
|
|
15
|
+
defineProps<{
|
|
16
|
+
/** Shown as the email's heading; no heading when omitted. */
|
|
17
|
+
title?: string;
|
|
18
|
+
lang?: string;
|
|
19
|
+
/** Inbox preview text, hidden in the message body. */
|
|
20
|
+
preheader?: string;
|
|
21
|
+
/** Draws the separator between the content and the `footer` slot. */
|
|
22
|
+
divider?: boolean;
|
|
23
|
+
logoAlt?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Leaves the logo out unless a mail client can load it: an absolute
|
|
26
|
+
* public http(s) URL, not an SVG (see `emailLogoUrl`).
|
|
27
|
+
*/
|
|
28
|
+
publicLogoOnly?: boolean;
|
|
29
|
+
}>(),
|
|
30
|
+
{ divider: true, logoAlt: "Logo", publicLogoOnly: false },
|
|
31
|
+
);
|
|
18
32
|
|
|
19
33
|
const appConfig = useDmsAppConfig() as EmailAppConfig;
|
|
20
34
|
const runtimeConfig = useDmsRuntimeConfig();
|
|
21
35
|
|
|
22
36
|
const logoPath = appConfig.branding?.logo?.default?.light;
|
|
23
37
|
const clientBaseUrl = runtimeConfig.public.dms?.clientBaseUrl ?? "";
|
|
24
|
-
const logoUrl =
|
|
25
|
-
?
|
|
26
|
-
: logoPath
|
|
38
|
+
const logoUrl = props.publicLogoOnly
|
|
39
|
+
? emailLogoUrl(logoPath, clientBaseUrl)
|
|
40
|
+
: logoPath?.startsWith("/")
|
|
41
|
+
? `${clientBaseUrl}${logoPath}`
|
|
42
|
+
: logoPath;
|
|
27
43
|
</script>
|
|
28
44
|
|
|
29
45
|
<template>
|
|
30
46
|
<EHtml :lang="lang ?? 'en'">
|
|
31
|
-
<EHead
|
|
47
|
+
<EHead>
|
|
48
|
+
<slot name="head" />
|
|
49
|
+
</EHead>
|
|
32
50
|
<EBody :style="emailStyles.main">
|
|
51
|
+
<EPreview v-if="preheader">{{ preheader }}</EPreview>
|
|
33
52
|
<EContainer :style="emailStyles.container">
|
|
34
53
|
<ESection :style="emailStyles.card">
|
|
35
54
|
<ESection v-if="logoUrl" :style="emailStyles.logo">
|
|
36
|
-
<EImg
|
|
55
|
+
<EImg
|
|
56
|
+
:src="logoUrl"
|
|
57
|
+
:alt="logoAlt"
|
|
58
|
+
:style="emailStyles.logoImage"
|
|
59
|
+
/>
|
|
37
60
|
</ESection>
|
|
38
61
|
|
|
39
|
-
<EHeading as="h1" :style="emailStyles.heading">
|
|
62
|
+
<EHeading v-if="title" as="h1" :style="emailStyles.heading">
|
|
40
63
|
{{ title }}
|
|
41
64
|
</EHeading>
|
|
42
65
|
|
|
43
66
|
<slot />
|
|
44
67
|
|
|
45
|
-
<EHr :style="emailStyles.divider" />
|
|
68
|
+
<EHr v-if="divider" :style="emailStyles.divider" />
|
|
46
69
|
|
|
47
70
|
<slot name="footer" />
|
|
48
71
|
</ESection>
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which logo URL an email may carry. A recipient's mail client fetches the
|
|
3
|
+
* image from the internet, so it needs an absolute public http(s) URL; Gmail
|
|
4
|
+
* and Outlook also refuse SVG. A logo that fails either test is left out
|
|
5
|
+
* rather than drawn as a broken image.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const ROOT_PATH = "/";
|
|
9
|
+
const WEB_PROTOCOLS = ["http:", "https:"];
|
|
10
|
+
const SVG_PATH = /\.svg(?:[?#]|$)/i;
|
|
11
|
+
const LOCAL_HOSTS = ["localhost", "0.0.0.0", "[::]", "[::1]"];
|
|
12
|
+
const LOCAL_SUFFIXES = [".localhost", ".local", ".internal"];
|
|
13
|
+
const PRIVATE_ADDRESSES = [
|
|
14
|
+
/^127\./,
|
|
15
|
+
/^10\./,
|
|
16
|
+
/^192\.168\./,
|
|
17
|
+
/^172\.(1[6-9]|2\d|3[01])\./,
|
|
18
|
+
/^169\.254\./,
|
|
19
|
+
/^\[f[cd][0-9a-f]{0,2}:/i,
|
|
20
|
+
/^\[fe[89ab][0-9a-f]:/i,
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
function absoluteUrl(path: string, clientBaseUrl: string): URL | null {
|
|
24
|
+
const source = path.startsWith(ROOT_PATH) ? `${clientBaseUrl}${path}` : path;
|
|
25
|
+
try {
|
|
26
|
+
return new URL(source);
|
|
27
|
+
} catch {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Whether a mail client out on the internet can reach `hostname`. */
|
|
33
|
+
export function isPublicEmailHost(hostname: string): boolean {
|
|
34
|
+
const name = hostname.toLowerCase();
|
|
35
|
+
if (LOCAL_HOSTS.includes(name)) return false;
|
|
36
|
+
if (LOCAL_SUFFIXES.some((suffix) => name.endsWith(suffix))) return false;
|
|
37
|
+
return !PRIVATE_ADDRESSES.some((pattern) => pattern.test(name));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The logo URL an email may use: `logoPath` made absolute against
|
|
42
|
+
* `clientBaseUrl` when it starts with `/`, or `""` when it is an SVG, not
|
|
43
|
+
* http(s), or served from a host a mail client cannot reach (localhost, a
|
|
44
|
+
* private address).
|
|
45
|
+
*/
|
|
46
|
+
export function emailLogoUrl(
|
|
47
|
+
logoPath: string | undefined,
|
|
48
|
+
clientBaseUrl: string,
|
|
49
|
+
): string {
|
|
50
|
+
if (!logoPath || SVG_PATH.test(logoPath)) return "";
|
|
51
|
+
const url = absoluteUrl(logoPath, clientBaseUrl);
|
|
52
|
+
if (!url || !WEB_PROTOCOLS.includes(url.protocol)) return "";
|
|
53
|
+
return isPublicEmailHost(url.hostname) ? url.href : "";
|
|
54
|
+
}
|
|
@@ -3,6 +3,7 @@ import { withoutTrailingSlash } from "ufo";
|
|
|
3
3
|
import { holdPageHeaderActions } from "../composables/layout/usePageHeaderActions";
|
|
4
4
|
import { useDevReloading } from "../build/composables/dev-reload/useDevReloadHolder";
|
|
5
5
|
import { usePageLiveHost } from "#dms-ui/app/build/composables/live/usePageLiveHost";
|
|
6
|
+
import { pageValidationRedirect } from "../build/utils/pageValidationRedirect";
|
|
6
7
|
|
|
7
8
|
defineOptions({ inheritAttrs: false });
|
|
8
9
|
|
|
@@ -95,13 +96,13 @@ async function recheckAccessWithFreshSession(): Promise<void> {
|
|
|
95
96
|
});
|
|
96
97
|
}
|
|
97
98
|
|
|
98
|
-
function
|
|
99
|
+
function isPageValid(
|
|
99
100
|
metadata: PageInfo | undefined,
|
|
100
101
|
query: Record<string, unknown>,
|
|
101
102
|
params: Record<string, unknown>,
|
|
102
|
-
):
|
|
103
|
+
): boolean {
|
|
103
104
|
if (!metadata?.validation) {
|
|
104
|
-
return;
|
|
105
|
+
return true;
|
|
105
106
|
}
|
|
106
107
|
|
|
107
108
|
const { validation } = metadata;
|
|
@@ -121,12 +122,31 @@ function validatePage(
|
|
|
121
122
|
{ query, params },
|
|
122
123
|
);
|
|
123
124
|
|
|
124
|
-
|
|
125
|
+
return isQueryValid && isCustomValid;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Set while a page failing its validation leaves for its `redirectTo`: its
|
|
129
|
+
// blocks are not drawn, so none of them requests a URL missing its context.
|
|
130
|
+
const isLeavingPage = ref(false);
|
|
131
|
+
|
|
132
|
+
async function enforcePageValidation(): Promise<void> {
|
|
133
|
+
const metadata = pagelayoutMetadata.value;
|
|
134
|
+
const query = route.query as Record<string, unknown>;
|
|
135
|
+
if (isPageValid(metadata, query, routeParams.value)) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const redirect = pageValidationRedirect(metadata?.validation, route.path, {
|
|
139
|
+
routeParams: routeParams.value,
|
|
140
|
+
routeQuery: query,
|
|
141
|
+
});
|
|
142
|
+
if (!redirect) {
|
|
125
143
|
throw createError({
|
|
126
144
|
statusCode: HTTP_NOT_FOUND,
|
|
127
145
|
statusMessage: "Page not found",
|
|
128
146
|
});
|
|
129
147
|
}
|
|
148
|
+
isLeavingPage.value = true;
|
|
149
|
+
await navigateDms(redirect, { replace: true });
|
|
130
150
|
}
|
|
131
151
|
|
|
132
152
|
defineDmsPageMeta({
|
|
@@ -159,7 +179,7 @@ if (siteLayout.loadingError && siteLayout.loadingError.value) {
|
|
|
159
179
|
});
|
|
160
180
|
}
|
|
161
181
|
|
|
162
|
-
|
|
182
|
+
await enforcePageValidation();
|
|
163
183
|
await checkPageMetadata(pagelayoutMetadata.value);
|
|
164
184
|
|
|
165
185
|
// Same reason as the guard inside `checkPageMetadata`: while a dev reload is in
|
|
@@ -207,7 +227,8 @@ watch(
|
|
|
207
227
|
siteLayout.refreshIfStale(),
|
|
208
228
|
refreshPermissionsIfStale(),
|
|
209
229
|
]);
|
|
210
|
-
|
|
230
|
+
isLeavingPage.value = false;
|
|
231
|
+
await enforcePageValidation();
|
|
211
232
|
await checkPageMetadata(pagelayoutMetadata.value);
|
|
212
233
|
},
|
|
213
234
|
);
|
|
@@ -488,7 +509,8 @@ if (import.meta.env.DEV) {
|
|
|
488
509
|
</script>
|
|
489
510
|
|
|
490
511
|
<template>
|
|
491
|
-
<
|
|
512
|
+
<template v-if="isLeavingPage" />
|
|
513
|
+
<div v-else-if="hidesEveryBlock" class="dms-card overflow-hidden">
|
|
492
514
|
<DmsEmptyState
|
|
493
515
|
variant="no-access"
|
|
494
516
|
:title="t('page.no_visible_blocks.title')"
|
|
@@ -9,6 +9,8 @@ export type MenuItemType = "label" | "link";
|
|
|
9
9
|
export interface PageValidation {
|
|
10
10
|
requiredQueryParams?: string[];
|
|
11
11
|
customFunctionId?: string;
|
|
12
|
+
/** Where a page failing its validation sends the user, not-found aside. */
|
|
13
|
+
redirectTo?: string;
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
export interface MenuOptions {
|