@rangka/core 0.1.1 → 0.1.3
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 +6 -2
- package/.claude/skills/extend-core/SKILL.md +0 -133
- package/.turbo/turbo-build.log +0 -4
- package/CHANGELOG.md +0 -25
- package/CLAUDE.md +0 -180
- package/src/__tests__/coerce.test.ts +0 -154
- package/src/__tests__/context.test.ts +0 -111
- package/src/__tests__/helpers.ts +0 -21
- package/src/__tests__/index.test.ts +0 -7
- package/src/__tests__/widgets.test.ts +0 -197
- package/src/api/__tests__/handlers.test.ts +0 -389
- package/src/api/__tests__/include-resolver.test.ts +0 -393
- package/src/api/__tests__/middleware.test.ts +0 -100
- package/src/api/__tests__/openapi-schema.test.ts +0 -210
- package/src/api/__tests__/query-parser.test.ts +0 -291
- package/src/api/__tests__/route-generator.test.ts +0 -137
- package/src/api/__tests__/server.test.ts +0 -73
- package/src/api/__tests__/swagger.test.ts +0 -166
- package/src/api/handlers.ts +0 -274
- package/src/api/include-resolver.ts +0 -27
- package/src/api/index.ts +0 -4
- package/src/api/meta-handler.ts +0 -254
- package/src/api/openapi-schema.ts +0 -99
- package/src/api/query-parser.ts +0 -315
- package/src/api/route-generator.ts +0 -448
- package/src/api/server.ts +0 -147
- package/src/api/types.ts +0 -16
- package/src/audit/__tests__/audit.test.ts +0 -144
- package/src/audit/index.ts +0 -3
- package/src/audit/record.ts +0 -69
- package/src/audit/tables.ts +0 -48
- package/src/audit/types.ts +0 -26
- package/src/auth/__tests__/core-module.test.ts +0 -54
- package/src/auth/__tests__/debug.test.ts +0 -47
- package/src/auth/__tests__/field-permissions.test.ts +0 -245
- package/src/auth/__tests__/integration.test.ts +0 -208
- package/src/auth/__tests__/meta-boot.test.ts +0 -538
- package/src/auth/__tests__/model-permissions.test.ts +0 -205
- package/src/auth/__tests__/password.test.ts +0 -29
- package/src/auth/__tests__/permission-registry.test.ts +0 -313
- package/src/auth/__tests__/scope-hook.test.ts +0 -509
- package/src/auth/__tests__/scope-registry.test.ts +0 -297
- package/src/auth/__tests__/scopes.test.ts +0 -66
- package/src/auth/__tests__/session.test.ts +0 -214
- package/src/auth/core-models.ts +0 -52
- package/src/auth/core-module.ts +0 -59
- package/src/auth/debug.ts +0 -157
- package/src/auth/field-permissions.ts +0 -116
- package/src/auth/index.ts +0 -37
- package/src/auth/model-permissions.ts +0 -59
- package/src/auth/password.ts +0 -22
- package/src/auth/permission-registry.ts +0 -171
- package/src/auth/scope-filters.ts +0 -11
- package/src/auth/scope-registry.ts +0 -121
- package/src/auth/scopes.ts +0 -146
- package/src/auth/seed.ts +0 -44
- package/src/auth/session.ts +0 -178
- package/src/auth/types.ts +0 -50
- package/src/boot/__tests__/page-scanning.test.ts +0 -170
- package/src/boot/__tests__/page-utils.test.ts +0 -225
- package/src/boot/__tests__/project-scanner.test.ts +0 -88
- package/src/boot/dependency-sort.ts +0 -82
- package/src/boot/discovery.ts +0 -85
- package/src/boot/index.ts +0 -457
- package/src/boot/page-utils.ts +0 -110
- package/src/boot/project-scanner.ts +0 -397
- package/src/boot/schema-loader.ts +0 -26
- package/src/boot/schema-merger.ts +0 -125
- package/src/boot/traits.ts +0 -25
- package/src/boot/types.ts +0 -73
- package/src/context.ts +0 -105
- package/src/db/__tests__/cascade-delete.test.ts +0 -182
- package/src/db/__tests__/desired-state.test.ts +0 -136
- package/src/db/__tests__/diff-engine.test.ts +0 -635
- package/src/db/__tests__/field-mapper.test.ts +0 -355
- package/src/db/__tests__/introspect.test.ts +0 -70
- package/src/db/__tests__/search-filter.test.ts +0 -45
- package/src/db/__tests__/sequence.test.ts +0 -221
- package/src/db/auto-sync.ts +0 -133
- package/src/db/client.ts +0 -147
- package/src/db/desired-state.ts +0 -98
- package/src/db/diff-engine.ts +0 -305
- package/src/db/field-mapper.ts +0 -504
- package/src/db/filter-applier.ts +0 -89
- package/src/db/include-resolver.ts +0 -40
- package/src/db/index.ts +0 -23
- package/src/db/introspect.ts +0 -265
- package/src/db/model-include-resolver.ts +0 -327
- package/src/db/model-ops.ts +0 -281
- package/src/db/scope-enforcer.ts +0 -37
- package/src/db/types.ts +0 -98
- package/src/errors.ts +0 -41
- package/src/events/__tests__/bus.test.ts +0 -105
- package/src/events/bus.ts +0 -89
- package/src/events/index.ts +0 -2
- package/src/events/types.ts +0 -9
- package/src/external-model/__tests__/computed-fields.test.ts +0 -106
- package/src/external-model/__tests__/field-mapper.test.ts +0 -160
- package/src/external-model/__tests__/in-memory-ops.test.ts +0 -247
- package/src/external-model/__tests__/mutation-executor.test.ts +0 -160
- package/src/external-model/__tests__/query-executor.test.ts +0 -284
- package/src/external-model/__tests__/schema-converter.test.ts +0 -174
- package/src/external-model/computed-fields.ts +0 -15
- package/src/external-model/define.ts +0 -5
- package/src/external-model/external-model-ops.ts +0 -108
- package/src/external-model/field-mapper.ts +0 -66
- package/src/external-model/in-memory-ops.ts +0 -107
- package/src/external-model/index.ts +0 -7
- package/src/external-model/mutation-executor.ts +0 -71
- package/src/external-model/query-executor.ts +0 -100
- package/src/external-model/schema-converter.ts +0 -53
- package/src/external-model/types.ts +0 -32
- package/src/fixtures/__tests__/fixtures.test.ts +0 -203
- package/src/fixtures/index.ts +0 -10
- package/src/fixtures/loader.ts +0 -196
- package/src/fixtures/registry.ts +0 -125
- package/src/fixtures/types.ts +0 -33
- package/src/helpers/assert-ownership.ts +0 -19
- package/src/helpers/coerce.ts +0 -28
- package/src/helpers/stamping.ts +0 -28
- package/src/helpers/validation.ts +0 -14
- package/src/hooks/__tests__/context.test.ts +0 -73
- package/src/hooks/__tests__/executor.test.ts +0 -433
- package/src/hooks/__tests__/middleware.test.ts +0 -224
- package/src/hooks/__tests__/registry.test.ts +0 -50
- package/src/hooks/context.ts +0 -89
- package/src/hooks/errors.ts +0 -11
- package/src/hooks/executor.ts +0 -115
- package/src/hooks/index.ts +0 -10
- package/src/hooks/middleware.ts +0 -220
- package/src/hooks/registry.ts +0 -20
- package/src/hooks/types.ts +0 -32
- package/src/index.ts +0 -172
- package/src/jobs/__tests__/enqueue.test.ts +0 -77
- package/src/jobs/__tests__/integration.test.ts +0 -71
- package/src/jobs/__tests__/registry.test.ts +0 -103
- package/src/jobs/__tests__/scheduler.test.ts +0 -92
- package/src/jobs/__tests__/worker-execution.test.ts +0 -202
- package/src/jobs/__tests__/worker.test.ts +0 -119
- package/src/jobs/enqueue.ts +0 -93
- package/src/jobs/index.ts +0 -14
- package/src/jobs/registry.ts +0 -92
- package/src/jobs/scheduler.ts +0 -205
- package/src/jobs/tables.ts +0 -132
- package/src/jobs/types.ts +0 -62
- package/src/jobs/worker.ts +0 -272
- package/src/model-api/__tests__/cross-boundary-includes.test.ts +0 -366
- package/src/model-api/__tests__/extended-api.test.ts +0 -244
- package/src/model-api/__tests__/filter-applier.test.ts +0 -177
- package/src/model-api/__tests__/filter-translator.test.ts +0 -186
- package/src/model-api/__tests__/include-resolver.test.ts +0 -226
- package/src/model-api/__tests__/model-access.test.ts +0 -284
- package/src/model-api/__tests__/query-builder.test.ts +0 -224
- package/src/model-api/__tests__/scope-enforcer.test.ts +0 -268
- package/src/model-api/field-access.ts +0 -28
- package/src/model-api/filter-applier.ts +0 -1
- package/src/model-api/filter-translator.ts +0 -67
- package/src/model-api/include-resolver.ts +0 -2
- package/src/model-api/index.ts +0 -86
- package/src/model-api/query-builder.ts +0 -155
- package/src/model-api/scope-enforcer.ts +0 -3
- package/src/model-api/types.ts +0 -139
- package/src/plugins/__tests__/adapter-registry.test.ts +0 -92
- package/src/plugins/__tests__/lifecycle.test.ts +0 -96
- package/src/plugins/__tests__/loader.test.ts +0 -273
- package/src/plugins/__tests__/validator.test.ts +0 -275
- package/src/plugins/adapter-registry.ts +0 -42
- package/src/plugins/define.ts +0 -5
- package/src/plugins/index.ts +0 -28
- package/src/plugins/lifecycle.ts +0 -27
- package/src/plugins/loader.ts +0 -126
- package/src/plugins/types.ts +0 -76
- package/src/plugins/validator.ts +0 -141
- package/src/schema/__tests__/registry-models-by-module.test.ts +0 -58
- package/src/schema/registry.ts +0 -93
- package/src/schema/relationships.ts +0 -93
- package/src/schema/types.ts +0 -43
- package/src/services/__tests__/integration.test.ts +0 -63
- package/src/services/__tests__/registry.test.ts +0 -175
- package/src/services/index.ts +0 -13
- package/src/services/registry.ts +0 -156
- package/src/services/types.ts +0 -27
- package/src/validation/__tests__/field-validator.test.ts +0 -195
- package/src/validation/field-validator.ts +0 -113
- package/src/validation/index.ts +0 -1
- package/src/widgets/index.ts +0 -3
- package/src/widgets/slot-validator.ts +0 -87
- package/src/widgets/widget-registry.ts +0 -32
- package/tests/boot.test.ts +0 -323
- package/tests/dependency-sort.test.ts +0 -99
- package/tests/discovery.test.ts +0 -126
- package/tests/registry.test.ts +0 -216
- package/tests/schema-loader.test.ts +0 -52
- package/tests/schema-merger.test.ts +0 -180
- package/tsconfig.json +0 -9
- package/tsconfig.tsbuildinfo +0 -1
- package/vitest.config.ts +0 -14
|
@@ -1,538 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { PermissionRegistry } from '../permission-registry.js';
|
|
3
|
-
import { createAuthHook } from '../session.js';
|
|
4
|
-
import { createMetaBootHandler } from '../../api/meta-handler.js';
|
|
5
|
-
import type { MetaBootContext } from '../../api/meta-handler.js';
|
|
6
|
-
import { SchemaRegistry } from '../../schema/registry.js';
|
|
7
|
-
import type { ResolvedModel } from '../../schema/types.js';
|
|
8
|
-
import type { ModuleConfig, PageDefinition } from '@rangka/shared';
|
|
9
|
-
import { hashPassword } from '../password.js';
|
|
10
|
-
import { createTestServer } from '../../__tests__/helpers.js';
|
|
11
|
-
|
|
12
|
-
const orderModel: ResolvedModel = {
|
|
13
|
-
qualifiedName: 'sales.order',
|
|
14
|
-
app: 'sales',
|
|
15
|
-
module: 'sales',
|
|
16
|
-
name: 'order',
|
|
17
|
-
label: 'Sales Order',
|
|
18
|
-
auditLog: false,
|
|
19
|
-
traits: [],
|
|
20
|
-
fields: [
|
|
21
|
-
{
|
|
22
|
-
name: 'id',
|
|
23
|
-
config: { type: 'string', required: true } as any,
|
|
24
|
-
provenance: { source: 'base' },
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
name: 'customer',
|
|
28
|
-
config: { type: 'link', model: 'sales.customer', label: 'Customer' } as any,
|
|
29
|
-
provenance: { source: 'base' },
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
name: 'total',
|
|
33
|
-
config: { type: 'decimal', label: 'Total' } as any,
|
|
34
|
-
provenance: { source: 'base' },
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
name: 'status',
|
|
38
|
-
config: { type: 'enum', options: ['draft', 'confirmed'], label: 'Status' } as any,
|
|
39
|
-
provenance: { source: 'base' },
|
|
40
|
-
},
|
|
41
|
-
],
|
|
42
|
-
indexes: [],
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const payslipModel: ResolvedModel = {
|
|
46
|
-
qualifiedName: 'hr.payslip',
|
|
47
|
-
app: 'hr',
|
|
48
|
-
module: 'hr',
|
|
49
|
-
name: 'payslip',
|
|
50
|
-
label: 'Payslip',
|
|
51
|
-
auditLog: false,
|
|
52
|
-
traits: [],
|
|
53
|
-
fields: [
|
|
54
|
-
{
|
|
55
|
-
name: 'id',
|
|
56
|
-
config: { type: 'string', required: true } as any,
|
|
57
|
-
provenance: { source: 'base' },
|
|
58
|
-
},
|
|
59
|
-
{ name: 'amount', config: { type: 'decimal' } as any, provenance: { source: 'base' } },
|
|
60
|
-
],
|
|
61
|
-
indexes: [],
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const contactModel: ResolvedModel = {
|
|
65
|
-
qualifiedName: 'contacts.contact',
|
|
66
|
-
app: 'contacts',
|
|
67
|
-
module: 'contacts',
|
|
68
|
-
name: 'contact',
|
|
69
|
-
label: 'Contact',
|
|
70
|
-
auditLog: false,
|
|
71
|
-
traits: [],
|
|
72
|
-
fields: [
|
|
73
|
-
{
|
|
74
|
-
name: 'id',
|
|
75
|
-
config: { type: 'string', required: true } as any,
|
|
76
|
-
provenance: { source: 'base' },
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
name: 'name',
|
|
80
|
-
config: { type: 'string', label: 'Name' } as any,
|
|
81
|
-
provenance: { source: 'base' },
|
|
82
|
-
},
|
|
83
|
-
],
|
|
84
|
-
indexes: [],
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
const pages: Array<{ module: string; page: PageDefinition }> = [
|
|
88
|
-
{
|
|
89
|
-
module: 'sales',
|
|
90
|
-
page: {
|
|
91
|
-
key: 'sales.orders',
|
|
92
|
-
label: 'Orders',
|
|
93
|
-
type: 'collection',
|
|
94
|
-
path: '/sales/orders',
|
|
95
|
-
body: [
|
|
96
|
-
{ type: 'data', source: { model: 'sales.order' }, children: [] },
|
|
97
|
-
{ type: 'data', source: { model: 'contacts.contact' }, children: [] },
|
|
98
|
-
],
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
module: 'hr',
|
|
103
|
-
page: {
|
|
104
|
-
key: 'hr.payroll',
|
|
105
|
-
label: 'Payroll',
|
|
106
|
-
type: 'collection',
|
|
107
|
-
path: '/hr/payroll',
|
|
108
|
-
body: [{ type: 'data', source: { model: 'hr.payslip' }, children: [] }],
|
|
109
|
-
},
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
module: 'admin',
|
|
113
|
-
page: {
|
|
114
|
-
key: 'admin.dashboard',
|
|
115
|
-
label: 'Admin Dashboard',
|
|
116
|
-
type: 'dashboard',
|
|
117
|
-
path: '/admin/dashboard',
|
|
118
|
-
body: [{ type: 'text', props: { content: 'Dashboard' } }],
|
|
119
|
-
},
|
|
120
|
-
},
|
|
121
|
-
];
|
|
122
|
-
|
|
123
|
-
const modules: ModuleConfig[] = [
|
|
124
|
-
{
|
|
125
|
-
name: 'sales',
|
|
126
|
-
label: 'Sales',
|
|
127
|
-
icon: 'shopping-cart',
|
|
128
|
-
order: 1,
|
|
129
|
-
navigation: [
|
|
130
|
-
{
|
|
131
|
-
section: 'Orders',
|
|
132
|
-
items: [{ page: 'sales.orders', label: 'Orders', icon: 'list' }],
|
|
133
|
-
},
|
|
134
|
-
],
|
|
135
|
-
},
|
|
136
|
-
{
|
|
137
|
-
name: 'hr',
|
|
138
|
-
label: 'Human Resources',
|
|
139
|
-
icon: 'users',
|
|
140
|
-
order: 2,
|
|
141
|
-
navigation: [
|
|
142
|
-
{
|
|
143
|
-
section: 'Payroll',
|
|
144
|
-
items: [{ page: 'hr.payroll', label: 'Payroll', icon: 'dollar' }],
|
|
145
|
-
},
|
|
146
|
-
],
|
|
147
|
-
},
|
|
148
|
-
{
|
|
149
|
-
name: 'admin',
|
|
150
|
-
label: 'Administration',
|
|
151
|
-
icon: 'settings',
|
|
152
|
-
order: 3,
|
|
153
|
-
navigation: [
|
|
154
|
-
{
|
|
155
|
-
section: 'System',
|
|
156
|
-
items: [{ page: 'admin.dashboard', label: 'Dashboard', icon: 'dashboard' }],
|
|
157
|
-
},
|
|
158
|
-
],
|
|
159
|
-
},
|
|
160
|
-
];
|
|
161
|
-
|
|
162
|
-
function createMockDb(opts?: { noSession?: boolean; expiredSession?: boolean }) {
|
|
163
|
-
const users = [
|
|
164
|
-
{
|
|
165
|
-
id: 'u1',
|
|
166
|
-
email: 'sales@test.com',
|
|
167
|
-
full_name: 'Sales User',
|
|
168
|
-
enabled: true,
|
|
169
|
-
password_hash: hashPassword('pass'),
|
|
170
|
-
},
|
|
171
|
-
];
|
|
172
|
-
const roles = [{ id: 'r1', name: 'SalesRep' }];
|
|
173
|
-
const userRoles = [{ user_id: 'u1', role_id: 'r1' }];
|
|
174
|
-
const sessions = opts?.noSession
|
|
175
|
-
? []
|
|
176
|
-
: [
|
|
177
|
-
{
|
|
178
|
-
id: 's1',
|
|
179
|
-
token: 'test-token',
|
|
180
|
-
user_id: 'u1',
|
|
181
|
-
expires_at: opts?.expiredSession
|
|
182
|
-
? new Date(Date.now() - 60000).toISOString()
|
|
183
|
-
: new Date(Date.now() + 60000).toISOString(),
|
|
184
|
-
},
|
|
185
|
-
];
|
|
186
|
-
|
|
187
|
-
return {
|
|
188
|
-
selectFrom(table: string) {
|
|
189
|
-
const store =
|
|
190
|
-
table === 'core.user'
|
|
191
|
-
? users
|
|
192
|
-
: table === 'core.role'
|
|
193
|
-
? roles
|
|
194
|
-
: table === 'core.user_role'
|
|
195
|
-
? userRoles
|
|
196
|
-
: table === 'core.session'
|
|
197
|
-
? sessions
|
|
198
|
-
: [];
|
|
199
|
-
|
|
200
|
-
return {
|
|
201
|
-
selectAll() {
|
|
202
|
-
return this;
|
|
203
|
-
},
|
|
204
|
-
where(field: string, op: string, value: any) {
|
|
205
|
-
const filtered = (store as any[]).filter((r) => {
|
|
206
|
-
if (op === '=') return r[field] === value;
|
|
207
|
-
if (op === 'in') return value.includes(r[field]);
|
|
208
|
-
return false;
|
|
209
|
-
});
|
|
210
|
-
return {
|
|
211
|
-
executeTakeFirst: async () => filtered[0],
|
|
212
|
-
execute: async () => filtered,
|
|
213
|
-
where(f2: string, o2: string, v2: any) {
|
|
214
|
-
const f = filtered.filter((r: any) => {
|
|
215
|
-
if (o2 === '=') return r[f2] === v2;
|
|
216
|
-
if (o2 === 'in') return v2.includes(r[f2]);
|
|
217
|
-
return false;
|
|
218
|
-
});
|
|
219
|
-
return { executeTakeFirst: async () => f[0], execute: async () => f };
|
|
220
|
-
},
|
|
221
|
-
};
|
|
222
|
-
},
|
|
223
|
-
executeTakeFirst: async () => undefined,
|
|
224
|
-
execute: async () => [],
|
|
225
|
-
};
|
|
226
|
-
},
|
|
227
|
-
} as any;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
function buildServer(
|
|
231
|
-
permissionRegistry: PermissionRegistry,
|
|
232
|
-
db: any,
|
|
233
|
-
schemaRegistry: SchemaRegistry,
|
|
234
|
-
) {
|
|
235
|
-
const server = createTestServer();
|
|
236
|
-
const metaCtx: MetaBootContext = {
|
|
237
|
-
schemaRegistry,
|
|
238
|
-
pages,
|
|
239
|
-
modules,
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
server.get('/api/meta/boot', {
|
|
243
|
-
onRequest: createAuthHook(db, permissionRegistry),
|
|
244
|
-
handler: createMetaBootHandler(metaCtx),
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
return server;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
describe('GET /api/meta/boot', () => {
|
|
251
|
-
it('returns correct boot response for authenticated user with filtered pages/nav/models', async () => {
|
|
252
|
-
const permissionRegistry = new PermissionRegistry();
|
|
253
|
-
permissionRegistry.registerRoles(
|
|
254
|
-
{
|
|
255
|
-
SalesRep: {
|
|
256
|
-
label: 'Sales Rep',
|
|
257
|
-
models: { 'sales.order': { read: true, create: true } },
|
|
258
|
-
pages: ['admin.dashboard'],
|
|
259
|
-
},
|
|
260
|
-
},
|
|
261
|
-
'sales',
|
|
262
|
-
);
|
|
263
|
-
|
|
264
|
-
const schemaRegistry = new SchemaRegistry([orderModel, payslipModel, contactModel]);
|
|
265
|
-
const db = createMockDb();
|
|
266
|
-
const server = buildServer(permissionRegistry, db, schemaRegistry);
|
|
267
|
-
|
|
268
|
-
const res = await server.inject({
|
|
269
|
-
method: 'GET',
|
|
270
|
-
url: '/api/meta/boot',
|
|
271
|
-
headers: { authorization: 'Bearer test-token' },
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
expect(res.statusCode).toBe(200);
|
|
275
|
-
const body = res.json();
|
|
276
|
-
|
|
277
|
-
// User
|
|
278
|
-
expect(body.user).toEqual({
|
|
279
|
-
id: 'u1',
|
|
280
|
-
name: 'Sales User',
|
|
281
|
-
email: 'sales@test.com',
|
|
282
|
-
roles: ['SalesRep'],
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
// Permissions
|
|
286
|
-
expect(body.permissions.models['sales.order']).toEqual({ read: true, create: true });
|
|
287
|
-
expect(body.permissions.pages).toContain('admin.dashboard');
|
|
288
|
-
|
|
289
|
-
// Pages: sales.orders (model access), admin.dashboard (explicit pages), NOT hr.payroll
|
|
290
|
-
const pageKeys = body.pages.map((p: any) => p.key);
|
|
291
|
-
expect(pageKeys).toContain('sales.orders');
|
|
292
|
-
expect(pageKeys).toContain('admin.dashboard');
|
|
293
|
-
expect(pageKeys).not.toContain('hr.payroll');
|
|
294
|
-
|
|
295
|
-
// Navigation: sales and admin modules, NOT hr
|
|
296
|
-
const navModules = body.navigation.map((n: any) => n.module);
|
|
297
|
-
expect(navModules).toContain('sales');
|
|
298
|
-
expect(navModules).toContain('admin');
|
|
299
|
-
expect(navModules).not.toContain('hr');
|
|
300
|
-
|
|
301
|
-
// Models: sales.order and contacts.contact (from overlay), NOT hr.payslip
|
|
302
|
-
expect(body.models['sales.order']).toBeDefined();
|
|
303
|
-
expect(body.models['contacts.contact']).toBeDefined();
|
|
304
|
-
expect(body.models['hr.payslip']).toBeUndefined();
|
|
305
|
-
|
|
306
|
-
// Model metadata shape
|
|
307
|
-
expect(body.models['sales.order'].qualifiedName).toBe('sales.order');
|
|
308
|
-
expect(body.models['sales.order'].fields.length).toBe(4);
|
|
309
|
-
const statusField = body.models['sales.order'].fields.find((f: any) => f.name === 'status');
|
|
310
|
-
expect(statusField.type).toBe('enum');
|
|
311
|
-
expect(statusField.options).toEqual(['draft', 'confirmed']);
|
|
312
|
-
const customerField = body.models['sales.order'].fields.find((f: any) => f.name === 'customer');
|
|
313
|
-
expect(customerField.relationship).toEqual({ type: 'link', model: 'sales.customer' });
|
|
314
|
-
});
|
|
315
|
-
|
|
316
|
-
it('returns 401 for unauthenticated request', async () => {
|
|
317
|
-
const permissionRegistry = new PermissionRegistry();
|
|
318
|
-
permissionRegistry.registerRoles({ SalesRep: { label: 'Sales Rep', models: {} } }, 'sales');
|
|
319
|
-
|
|
320
|
-
const schemaRegistry = new SchemaRegistry([orderModel]);
|
|
321
|
-
const db = createMockDb();
|
|
322
|
-
const server = buildServer(permissionRegistry, db, schemaRegistry);
|
|
323
|
-
|
|
324
|
-
const res = await server.inject({
|
|
325
|
-
method: 'GET',
|
|
326
|
-
url: '/api/meta/boot',
|
|
327
|
-
});
|
|
328
|
-
|
|
329
|
-
expect(res.statusCode).toBe(401);
|
|
330
|
-
expect(res.json().error.code).toBe('UNAUTHORIZED');
|
|
331
|
-
});
|
|
332
|
-
|
|
333
|
-
it('user with limited permissions only sees accessible pages and referenced models', async () => {
|
|
334
|
-
const permissionRegistry = new PermissionRegistry();
|
|
335
|
-
permissionRegistry.registerRoles(
|
|
336
|
-
{
|
|
337
|
-
SalesRep: {
|
|
338
|
-
label: 'Sales Rep',
|
|
339
|
-
models: { 'hr.payslip': { read: true } },
|
|
340
|
-
},
|
|
341
|
-
},
|
|
342
|
-
'app',
|
|
343
|
-
);
|
|
344
|
-
|
|
345
|
-
const schemaRegistry = new SchemaRegistry([orderModel, payslipModel, contactModel]);
|
|
346
|
-
const db = createMockDb();
|
|
347
|
-
const server = buildServer(permissionRegistry, db, schemaRegistry);
|
|
348
|
-
|
|
349
|
-
const res = await server.inject({
|
|
350
|
-
method: 'GET',
|
|
351
|
-
url: '/api/meta/boot',
|
|
352
|
-
headers: { authorization: 'Bearer test-token' },
|
|
353
|
-
});
|
|
354
|
-
|
|
355
|
-
expect(res.statusCode).toBe(200);
|
|
356
|
-
const body = res.json();
|
|
357
|
-
|
|
358
|
-
const pageKeys = body.pages.map((p: any) => p.key);
|
|
359
|
-
expect(pageKeys).toContain('hr.payroll');
|
|
360
|
-
expect(pageKeys).toContain('admin.dashboard');
|
|
361
|
-
expect(pageKeys).not.toContain('sales.orders');
|
|
362
|
-
|
|
363
|
-
expect(body.models['hr.payslip']).toBeDefined();
|
|
364
|
-
expect(body.models['sales.order']).toBeUndefined();
|
|
365
|
-
});
|
|
366
|
-
|
|
367
|
-
it('non-model page accessible via explicit pages permission', async () => {
|
|
368
|
-
const permissionRegistry = new PermissionRegistry();
|
|
369
|
-
permissionRegistry.registerRoles(
|
|
370
|
-
{
|
|
371
|
-
SalesRep: {
|
|
372
|
-
label: 'Sales Rep',
|
|
373
|
-
models: {},
|
|
374
|
-
pages: ['admin.dashboard'],
|
|
375
|
-
},
|
|
376
|
-
},
|
|
377
|
-
'app',
|
|
378
|
-
);
|
|
379
|
-
|
|
380
|
-
const schemaRegistry = new SchemaRegistry([orderModel, payslipModel, contactModel]);
|
|
381
|
-
const db = createMockDb();
|
|
382
|
-
const server = buildServer(permissionRegistry, db, schemaRegistry);
|
|
383
|
-
|
|
384
|
-
const res = await server.inject({
|
|
385
|
-
method: 'GET',
|
|
386
|
-
url: '/api/meta/boot',
|
|
387
|
-
headers: { authorization: 'Bearer test-token' },
|
|
388
|
-
});
|
|
389
|
-
|
|
390
|
-
expect(res.statusCode).toBe(200);
|
|
391
|
-
const body = res.json();
|
|
392
|
-
|
|
393
|
-
const pageKeys = body.pages.map((p: any) => p.key);
|
|
394
|
-
expect(pageKeys).toContain('admin.dashboard');
|
|
395
|
-
expect(pageKeys).not.toContain('sales.orders');
|
|
396
|
-
expect(pageKeys).not.toContain('hr.payroll');
|
|
397
|
-
|
|
398
|
-
// No models referenced since admin.dashboard has no model sources
|
|
399
|
-
expect(Object.keys(body.models)).toHaveLength(0);
|
|
400
|
-
});
|
|
401
|
-
|
|
402
|
-
it('empty modules/sections are omitted from navigation', async () => {
|
|
403
|
-
const permissionRegistry = new PermissionRegistry();
|
|
404
|
-
permissionRegistry.registerRoles(
|
|
405
|
-
{
|
|
406
|
-
SalesRep: {
|
|
407
|
-
label: 'Sales Rep',
|
|
408
|
-
models: { 'sales.order': { read: true } },
|
|
409
|
-
},
|
|
410
|
-
},
|
|
411
|
-
'app',
|
|
412
|
-
);
|
|
413
|
-
|
|
414
|
-
const schemaRegistry = new SchemaRegistry([orderModel, payslipModel, contactModel]);
|
|
415
|
-
const db = createMockDb();
|
|
416
|
-
const server = buildServer(permissionRegistry, db, schemaRegistry);
|
|
417
|
-
|
|
418
|
-
const res = await server.inject({
|
|
419
|
-
method: 'GET',
|
|
420
|
-
url: '/api/meta/boot',
|
|
421
|
-
headers: { authorization: 'Bearer test-token' },
|
|
422
|
-
});
|
|
423
|
-
|
|
424
|
-
expect(res.statusCode).toBe(200);
|
|
425
|
-
const body = res.json();
|
|
426
|
-
|
|
427
|
-
const navModules = body.navigation.map((n: any) => n.module);
|
|
428
|
-
expect(navModules).toContain('sales');
|
|
429
|
-
expect(navModules).toContain('admin');
|
|
430
|
-
expect(navModules).not.toContain('hr');
|
|
431
|
-
|
|
432
|
-
// Navigation is sorted by order
|
|
433
|
-
expect(body.navigation[0].module).toBe('sales');
|
|
434
|
-
});
|
|
435
|
-
|
|
436
|
-
it('includes widget and view metadata in boot response', async () => {
|
|
437
|
-
const permissionRegistry = new PermissionRegistry();
|
|
438
|
-
permissionRegistry.registerRoles(
|
|
439
|
-
{
|
|
440
|
-
SalesRep: {
|
|
441
|
-
label: 'Sales Rep',
|
|
442
|
-
models: { 'sales.order': { read: true } },
|
|
443
|
-
},
|
|
444
|
-
},
|
|
445
|
-
'sales',
|
|
446
|
-
);
|
|
447
|
-
|
|
448
|
-
const schemaRegistry = new SchemaRegistry([orderModel]);
|
|
449
|
-
const db = createMockDb();
|
|
450
|
-
const server = createTestServer();
|
|
451
|
-
|
|
452
|
-
const widgetDefs: import('@rangka/shared').WidgetDefinitionMeta[] = [
|
|
453
|
-
{
|
|
454
|
-
name: 'button',
|
|
455
|
-
label: 'Button',
|
|
456
|
-
category: 'action',
|
|
457
|
-
schema: { label: { type: 'string', required: true } },
|
|
458
|
-
binding: 'none',
|
|
459
|
-
triggers: ['click'],
|
|
460
|
-
container: false,
|
|
461
|
-
},
|
|
462
|
-
{
|
|
463
|
-
name: 'input',
|
|
464
|
-
label: 'Input',
|
|
465
|
-
category: 'input',
|
|
466
|
-
schema: {},
|
|
467
|
-
binding: 'field',
|
|
468
|
-
triggers: ['change'],
|
|
469
|
-
container: false,
|
|
470
|
-
},
|
|
471
|
-
];
|
|
472
|
-
|
|
473
|
-
const metaCtx: MetaBootContext = {
|
|
474
|
-
schemaRegistry,
|
|
475
|
-
pages,
|
|
476
|
-
modules,
|
|
477
|
-
widgets: widgetDefs,
|
|
478
|
-
};
|
|
479
|
-
|
|
480
|
-
server.get('/api/meta/boot', {
|
|
481
|
-
onRequest: createAuthHook(db, permissionRegistry),
|
|
482
|
-
handler: createMetaBootHandler(metaCtx),
|
|
483
|
-
});
|
|
484
|
-
|
|
485
|
-
const res = await server.inject({
|
|
486
|
-
method: 'GET',
|
|
487
|
-
url: '/api/meta/boot',
|
|
488
|
-
headers: { authorization: 'Bearer test-token' },
|
|
489
|
-
});
|
|
490
|
-
|
|
491
|
-
expect(res.statusCode).toBe(200);
|
|
492
|
-
const body = res.json();
|
|
493
|
-
|
|
494
|
-
expect(body.widgets).toHaveLength(2);
|
|
495
|
-
expect(body.widgets[0].name).toBe('button');
|
|
496
|
-
expect(body.widgets[1].name).toBe('input');
|
|
497
|
-
});
|
|
498
|
-
|
|
499
|
-
it('returns empty arrays when no widgets are registered', async () => {
|
|
500
|
-
const permissionRegistry = new PermissionRegistry();
|
|
501
|
-
permissionRegistry.registerRoles(
|
|
502
|
-
{
|
|
503
|
-
SalesRep: {
|
|
504
|
-
label: 'Sales Rep',
|
|
505
|
-
models: { 'sales.order': { read: true } },
|
|
506
|
-
},
|
|
507
|
-
},
|
|
508
|
-
'sales',
|
|
509
|
-
);
|
|
510
|
-
|
|
511
|
-
const schemaRegistry = new SchemaRegistry([orderModel]);
|
|
512
|
-
const db = createMockDb();
|
|
513
|
-
const server = createTestServer();
|
|
514
|
-
|
|
515
|
-
const metaCtx: MetaBootContext = {
|
|
516
|
-
schemaRegistry,
|
|
517
|
-
pages,
|
|
518
|
-
modules,
|
|
519
|
-
widgets: [],
|
|
520
|
-
};
|
|
521
|
-
|
|
522
|
-
server.get('/api/meta/boot', {
|
|
523
|
-
onRequest: createAuthHook(db, permissionRegistry),
|
|
524
|
-
handler: createMetaBootHandler(metaCtx),
|
|
525
|
-
});
|
|
526
|
-
|
|
527
|
-
const res = await server.inject({
|
|
528
|
-
method: 'GET',
|
|
529
|
-
url: '/api/meta/boot',
|
|
530
|
-
headers: { authorization: 'Bearer test-token' },
|
|
531
|
-
});
|
|
532
|
-
|
|
533
|
-
expect(res.statusCode).toBe(200);
|
|
534
|
-
const body = res.json();
|
|
535
|
-
|
|
536
|
-
expect(body.widgets).toEqual([]);
|
|
537
|
-
});
|
|
538
|
-
});
|