@abgov/nx-adsp 13.18.1 → 13.18.2
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/package.json +1 -1
- package/src/generators/vue-admin-crud/files/src/views/__editViewFileName__.vue__tmpl__ +4 -2
- package/src/generators/vue-admin-crud/files/src/views/__listViewFileName__.vue__tmpl__ +3 -1
- package/src/generators/vue-admin-crud/vue-admin-crud.spec.ts +2 -2
- package/src/generators/vue-app/files/src/router/index.ts__tmpl__ +14 -2
- package/src/generators/vue-app/vue-app.spec.ts +12 -0
- package/src/generators/vue-components/files/src/lib/patterns/AppSideMenu.vue__tmpl__ +2 -0
- package/src/generators/vue-detail-view/files/src/views/__viewFileName__.vue__tmpl__ +3 -1
- package/src/generators/vue-detail-view/vue-detail-view.spec.ts +1 -1
- package/src/generators/vue-intake-view/files/shared/src/views/__reviewViewFileName__.vue__tmpl__ +4 -2
- package/src/generators/vue-intake-view/files/steps/src/views/__stepViewFileName__.vue__tmpl__ +4 -2
- package/src/generators/vue-intake-view/vue-intake-view.spec.ts +1 -1
- package/src/generators/vue-workspace-view/files/src/views/__viewFileName__.vue__tmpl__ +4 -1
- package/src/generators/vue-workspace-view/vue-workspace-view.spec.ts +1 -1
package/package.json
CHANGED
|
@@ -3,10 +3,12 @@ import { reactive, ref, computed, onMounted } from 'vue';
|
|
|
3
3
|
import { useRoute, useRouter } from 'vue-router';
|
|
4
4
|
import { useKeycloak } from '@dsb-norge/vue-keycloak-js';
|
|
5
5
|
import { GoabInput, GoabCheckbox } from '<%= goaImportPath %>';
|
|
6
|
+
import { useApi } from '../composables/useApi';
|
|
6
7
|
|
|
7
8
|
const route = useRoute();
|
|
8
9
|
const router = useRouter();
|
|
9
10
|
const kc = useKeycloak();
|
|
11
|
+
const { apiFetch } = useApi();
|
|
10
12
|
|
|
11
13
|
const idParam = computed(() => String(route.params.id ?? ''));
|
|
12
14
|
const isNew = computed(() => idParam.value === 'new' || idParam.value === '');
|
|
@@ -32,7 +34,7 @@ async function load() {
|
|
|
32
34
|
loading.value = true;
|
|
33
35
|
loadError.value = null;
|
|
34
36
|
try {
|
|
35
|
-
const res = await
|
|
37
|
+
const res = await apiFetch(`/api/<%= resource %>/${idParam.value}`);
|
|
36
38
|
if (!res.ok) throw new Error(`Failed to load (${res.status})`);
|
|
37
39
|
const data = await res.json();
|
|
38
40
|
<% fields.forEach(function (field) { -%>
|
|
@@ -67,7 +69,7 @@ async function onSubmit() {
|
|
|
67
69
|
saving.value = true;
|
|
68
70
|
saveError.value = null;
|
|
69
71
|
try {
|
|
70
|
-
const res = await
|
|
72
|
+
const res = await apiFetch(
|
|
71
73
|
isNew.value ? '/api/<%= resource %>' : `/api/<%= resource %>/${idParam.value}`,
|
|
72
74
|
{
|
|
73
75
|
method: isNew.value ? 'POST' : 'PUT',
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
import { ref, onMounted } from 'vue';
|
|
3
3
|
import { useKeycloak } from '@dsb-norge/vue-keycloak-js';
|
|
4
4
|
import { WorkspaceTable } from '<%= goaImportPath %>';
|
|
5
|
+
import { useApi } from '../composables/useApi';
|
|
5
6
|
|
|
6
7
|
const kc = useKeycloak();
|
|
8
|
+
const { apiFetch } = useApi();
|
|
7
9
|
|
|
8
10
|
const columns = [
|
|
9
11
|
<% fields.forEach(function (field) { -%>
|
|
@@ -21,7 +23,7 @@ async function load() {
|
|
|
21
23
|
loading.value = true;
|
|
22
24
|
error.value = null;
|
|
23
25
|
try {
|
|
24
|
-
const res = await
|
|
26
|
+
const res = await apiFetch('/api/<%= resource %>');
|
|
25
27
|
if (!res.ok) throw new Error(`Failed to load (${res.status})`);
|
|
26
28
|
const data = await res.json();
|
|
27
29
|
// Accept either a bare array or a { results } envelope.
|
|
@@ -61,7 +61,7 @@ describe('Vue Admin CRUD Generator', () => {
|
|
|
61
61
|
.read('apps/test/src/views/RegionsListView.vue')
|
|
62
62
|
.toString();
|
|
63
63
|
expect(view).toContain('<h1>Regions</h1>');
|
|
64
|
-
expect(view).toContain("
|
|
64
|
+
expect(view).toContain("apiFetch('/api/regions')");
|
|
65
65
|
expect(view).toContain("import { WorkspaceTable } from '@proj/vue-components';");
|
|
66
66
|
expect(view).toContain('<WorkspaceTable');
|
|
67
67
|
// No pagination props bound -- this is the "reused without its pagination/
|
|
@@ -92,7 +92,7 @@ describe('Vue Admin CRUD Generator', () => {
|
|
|
92
92
|
expect(view).not.toContain('errors.active');
|
|
93
93
|
expect(view).toContain("method: isNew.value ? 'POST' : 'PUT'");
|
|
94
94
|
expect(view).toContain("isNew.value ? '/api/regions'");
|
|
95
|
-
expect(view).toContain('
|
|
95
|
+
expect(view).toContain('apiFetch(`/api/regions/${idParam.value}`');
|
|
96
96
|
expect(view).toContain("router.push('/regions')");
|
|
97
97
|
expect(view).toContain('Create Regions');
|
|
98
98
|
expect(view).toContain('Edit Regions');
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { watch } from 'vue';
|
|
1
2
|
import { createRouter, createWebHistory } from 'vue-router';
|
|
2
3
|
import { useKeycloak } from '@dsb-norge/vue-keycloak-js';
|
|
3
4
|
import HomeView from '../views/HomeView.vue';
|
|
@@ -14,12 +15,23 @@ const router = createRouter({
|
|
|
14
15
|
],
|
|
15
16
|
});
|
|
16
17
|
|
|
17
|
-
router.beforeEach((to) => {
|
|
18
|
+
router.beforeEach(async (to) => {
|
|
18
19
|
if (to.meta.requiresAuth) {
|
|
19
20
|
// Read fields off the reactive instance (don't destructure) — consistent with
|
|
20
21
|
// the views and safe if this ever moves out of the per-navigation callback.
|
|
21
22
|
const kc = useKeycloak();
|
|
22
|
-
if (!kc.ready)
|
|
23
|
+
if (!kc.ready) {
|
|
24
|
+
// Keycloak init is async and may not have settled before the initial navigation
|
|
25
|
+
// fires (app.mount() triggers navigation synchronously). Block and wait rather
|
|
26
|
+
// than allowing through — a direct-URL load to a protected route would otherwise
|
|
27
|
+
// render the page unauthenticated with no login redirect.
|
|
28
|
+
await new Promise<void>((resolve) => {
|
|
29
|
+
const stop = watch(
|
|
30
|
+
() => kc.ready,
|
|
31
|
+
(ready) => { if (ready) { stop(); resolve() } },
|
|
32
|
+
)
|
|
33
|
+
})
|
|
34
|
+
}
|
|
23
35
|
if (!kc.authenticated) {
|
|
24
36
|
kc.keycloak?.login({ redirectUri: window.location.origin + to.fullPath });
|
|
25
37
|
return false;
|
|
@@ -314,6 +314,18 @@ describe('Vue App Generator', () => {
|
|
|
314
314
|
expect(homeView).not.toContain('Authorization');
|
|
315
315
|
}, 30000);
|
|
316
316
|
|
|
317
|
+
it('router guard waits for Keycloak readiness before making auth decisions', async () => {
|
|
318
|
+
await generator(host, options);
|
|
319
|
+
const router = host.read('apps/test/src/router/index.ts').toString();
|
|
320
|
+
// Returning `true` when !kc.ready lets unauthenticated direct-URL loads through
|
|
321
|
+
// to protected routes before Keycloak has finished init. The guard must block
|
|
322
|
+
// and wait (async watch) instead of allowing.
|
|
323
|
+
expect(router).toContain('async');
|
|
324
|
+
expect(router).toContain('kc.ready');
|
|
325
|
+
expect(router).not.toMatch(/if\s*\(!kc\.ready\)\s*return\s*true/);
|
|
326
|
+
expect(router).toContain('watch');
|
|
327
|
+
}, 30000);
|
|
328
|
+
|
|
317
329
|
it('index.html is at the Vite entry root and its mount target matches main.ts', async () => {
|
|
318
330
|
await generator(host, options);
|
|
319
331
|
// Vite's entry is <projectRoot>/index.html, not src/index.html — a template
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { ref, onMounted } from 'vue';
|
|
3
3
|
import { useRoute, useRouter } from 'vue-router';
|
|
4
4
|
import { RecordDetailShell } from '<%= goaImportPath %>';
|
|
5
|
+
import { useApi } from '../composables/useApi';
|
|
5
6
|
|
|
6
7
|
// The fetched record's shape isn't known to this generator -- read fields
|
|
7
8
|
// defensively rather than declaring (and likely getting wrong) a fake interface.
|
|
@@ -11,12 +12,13 @@ const error = ref<string | null>(null);
|
|
|
11
12
|
|
|
12
13
|
const route = useRoute();
|
|
13
14
|
const router = useRouter();
|
|
15
|
+
const { apiFetch } = useApi();
|
|
14
16
|
|
|
15
17
|
async function load() {
|
|
16
18
|
loading.value = true;
|
|
17
19
|
error.value = null;
|
|
18
20
|
try {
|
|
19
|
-
const res = await
|
|
21
|
+
const res = await apiFetch(`/api/<%= resource %>/${route.params.id}`);
|
|
20
22
|
if (!res.ok) throw new Error(`Failed to load (${res.status})`);
|
|
21
23
|
record.value = await res.json();
|
|
22
24
|
} catch (e) {
|
|
@@ -97,7 +97,7 @@ describe('Vue Detail View Generator', () => {
|
|
|
97
97
|
.read('apps/test/src/views/ApplicationDetailView.vue')
|
|
98
98
|
.toString();
|
|
99
99
|
expect(view).toContain('heading="Application Detail"');
|
|
100
|
-
expect(view).toContain("
|
|
100
|
+
expect(view).toContain("apiFetch(`/api/applications/${route.params.id}`)");
|
|
101
101
|
expect(view).toContain(
|
|
102
102
|
"<goa-badge type=\"information\" :content=\"String(record['status'] ?? '—')\" />",
|
|
103
103
|
);
|
package/src/generators/vue-intake-view/files/shared/src/views/__reviewViewFileName__.vue__tmpl__
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
import { ref, computed, onMounted } from 'vue';
|
|
3
3
|
import { useRoute, useRouter } from 'vue-router';
|
|
4
4
|
import { GoabCheckbox } from '<%= goaImportPath %>';
|
|
5
|
+
import { useApi } from '../composables/useApi';
|
|
5
6
|
|
|
6
7
|
const route = useRoute();
|
|
7
8
|
const router = useRouter();
|
|
9
|
+
const { apiFetch } = useApi();
|
|
8
10
|
|
|
9
11
|
const idParam = computed(() => String(route.params.id ?? ''));
|
|
10
12
|
|
|
@@ -21,7 +23,7 @@ async function load() {
|
|
|
21
23
|
loading.value = true;
|
|
22
24
|
loadError.value = null;
|
|
23
25
|
try {
|
|
24
|
-
const res = await
|
|
26
|
+
const res = await apiFetch(`/api/<%= resource %>/${idParam.value}`);
|
|
25
27
|
if (!res.ok) throw new Error(`Failed to load (${res.status})`);
|
|
26
28
|
record.value = await res.json();
|
|
27
29
|
} catch (e) {
|
|
@@ -42,7 +44,7 @@ async function onSubmit() {
|
|
|
42
44
|
submitting.value = true;
|
|
43
45
|
submitError.value = null;
|
|
44
46
|
try {
|
|
45
|
-
const res = await
|
|
47
|
+
const res = await apiFetch(`/api/<%= resource %>/${idParam.value}/submit`, {
|
|
46
48
|
method: 'POST',
|
|
47
49
|
});
|
|
48
50
|
if (!res.ok) throw new Error(`Failed to submit (${res.status})`);
|
package/src/generators/vue-intake-view/files/steps/src/views/__stepViewFileName__.vue__tmpl__
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { reactive, ref, computed, onMounted } from 'vue';
|
|
3
3
|
import { useRoute, useRouter } from 'vue-router';
|
|
4
4
|
import { Stepper, StepErrorSummary, GoabInput } from '<%= goaImportPath %>';
|
|
5
|
+
import { useApi } from '../composables/useApi';
|
|
5
6
|
|
|
6
7
|
const STEPS = [
|
|
7
8
|
<% stepperSteps.forEach(function (step) { -%>
|
|
@@ -11,6 +12,7 @@ const STEPS = [
|
|
|
11
12
|
|
|
12
13
|
const route = useRoute();
|
|
13
14
|
const router = useRouter();
|
|
15
|
+
const { apiFetch } = useApi();
|
|
14
16
|
|
|
15
17
|
const idParam = computed(() => String(route.params.id ?? ''));
|
|
16
18
|
const isNew = computed(() => idParam.value === 'new' || idParam.value === '');
|
|
@@ -48,7 +50,7 @@ async function load() {
|
|
|
48
50
|
loading.value = true;
|
|
49
51
|
loadError.value = null;
|
|
50
52
|
try {
|
|
51
|
-
const res = await
|
|
53
|
+
const res = await apiFetch(`/api/<%= resource %>/${idParam.value}`);
|
|
52
54
|
if (!res.ok) throw new Error(`Failed to load (${res.status})`);
|
|
53
55
|
const data = await res.json();
|
|
54
56
|
completedSteps.value = Array.isArray(data.completedSteps) ? data.completedSteps : [];
|
|
@@ -96,7 +98,7 @@ async function onSaveAndContinue() {
|
|
|
96
98
|
...form,
|
|
97
99
|
completedSteps: [...new Set([...completedSteps.value, '<%- stepKey %>'])],
|
|
98
100
|
};
|
|
99
|
-
const res = await
|
|
101
|
+
const res = await apiFetch(
|
|
100
102
|
isNew.value ? '/api/<%= resource %>' : `/api/<%= resource %>/${idParam.value}`,
|
|
101
103
|
{
|
|
102
104
|
method: isNew.value ? 'POST' : 'PUT',
|
|
@@ -123,7 +123,7 @@ describe('Vue Intake View Generator', () => {
|
|
|
123
123
|
expect(review).toContain("record['fullName'] ?? '—'");
|
|
124
124
|
expect(review).toContain("record['email'] ?? '—'");
|
|
125
125
|
expect(review).toContain(':disabled="!declared || submitting || undefined"');
|
|
126
|
-
expect(review).toContain("
|
|
126
|
+
expect(review).toContain("apiFetch(`/api/applications/${idParam.value}/submit`");
|
|
127
127
|
expect(review).toContain('/applications/${idParam.value}/confirmation');
|
|
128
128
|
}, 30000);
|
|
129
129
|
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { ref, onMounted } from 'vue';
|
|
3
3
|
import { WorkspaceTable } from '<%= goaImportPath %>';
|
|
4
|
+
import { useApi } from '../composables/useApi';
|
|
5
|
+
|
|
6
|
+
const { apiFetch } = useApi();
|
|
4
7
|
|
|
5
8
|
const columns = [
|
|
6
9
|
<% columns.forEach(function (column) { -%>
|
|
@@ -39,7 +42,7 @@ async function load() {
|
|
|
39
42
|
params.set('sortBy', sortBy.value);
|
|
40
43
|
params.set('sortDir', sortDir.value);
|
|
41
44
|
}
|
|
42
|
-
const res = await
|
|
45
|
+
const res = await apiFetch(`/api/<%= resource %>?${params.toString()}`);
|
|
43
46
|
if (!res.ok) throw new Error(`Failed to load (${res.status})`);
|
|
44
47
|
const data = await res.json();
|
|
45
48
|
// Accept either a bare array or a { results, total } page envelope.
|
|
@@ -99,7 +99,7 @@ describe('Vue Workspace View Generator', () => {
|
|
|
99
99
|
expect(view).toContain(
|
|
100
100
|
"{ key: 'lastSaved', label: 'Last saved', sortable: true }",
|
|
101
101
|
);
|
|
102
|
-
expect(view).toContain('
|
|
102
|
+
expect(view).toContain('apiFetch(`/api/applications?${params.toString()}`)');
|
|
103
103
|
expect(view).toContain(
|
|
104
104
|
"<goa-badge type=\"information\" :content=\"String(row['status'] ?? '—')\" />",
|
|
105
105
|
);
|