@nextsparkjs/core 0.1.0-beta.62 → 0.1.0-beta.64

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.
@@ -1,5 +1,5 @@
1
1
  {
2
- "generated": "2026-01-22T00:37:48.187Z",
2
+ "generated": "2026-01-22T01:03:14.201Z",
3
3
  "totalClasses": 1047,
4
4
  "classes": [
5
5
  "!text-2xl",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nextsparkjs/core",
3
- "version": "0.1.0-beta.62",
3
+ "version": "0.1.0-beta.64",
4
4
  "description": "NextSpark - The complete SaaS framework for Next.js",
5
5
  "license": "MIT",
6
6
  "author": "NextSpark <hello@nextspark.dev>",
@@ -108,12 +108,14 @@ function parseEntitiesFromConfig(content) {
108
108
  // - Simple word: customers
109
109
  // - Quoted with hyphens: "ai-agents" or 'ai-agents'
110
110
  //
111
- // Lookahead handles:
112
- // - Next entity (quoted or unquoted)
113
- // - End of content ($)
114
- // - Trailing comments (// ...)
115
- // - Closing brace of entities object (})
116
- const entityBlockRegex = /["']?([\w-]+)["']?:\s*\[([\s\S]*?)\],?(?=\s*(?:\/\/[^\n]*\n)?\s*(?:["'][\w-]+["']:|[\w-]+:|\}|$))/g
111
+ // IMPORTANT: The closing bracket must be at the start of a line (after newline + whitespace)
112
+ // This prevents matching `]` inside nested arrays like `roles: ['owner', 'admin']`
113
+ // which appear in the MIDDLE of a line, not at the start.
114
+ //
115
+ // The regex requires:
116
+ // - Entity key at start of line (newline + whitespace)
117
+ // - Closing bracket at start of line (newline + whitespace)
118
+ const entityBlockRegex = /\n\s*['"]?([\w-]+)['"]?:\s*\[([\s\S]*?)\n\s*\]/g
117
119
  let entityMatch
118
120
 
119
121
  while ((entityMatch = entityBlockRegex.exec(entitiesContent)) !== null) {
@@ -14,8 +14,10 @@ import assert from 'node:assert'
14
14
  * Test the entity block regex pattern
15
15
  */
16
16
  describe('Entity Block Regex', () => {
17
- // The regex pattern from permissions.mjs
18
- const entityBlockRegex = /["']?([\w-]+)["']?:\s*\[([\s\S]*?)\],?(?=\s*(?:\/\/[^\n]*\n)?\s*(?:["'][\w-]+["']:|[\w-]+:|\}|$))/g
17
+ // The regex pattern from permissions.mjs (MUST match the actual implementation!)
18
+ // IMPORTANT: The closing bracket must be at the start of a line (after newline + whitespace)
19
+ // This prevents matching `]` inside nested arrays like `roles: ['owner', 'admin']`
20
+ const entityBlockRegex = /\n\s*['"]?([\w-]+)['"]?:\s*\[([\s\S]*?)\n\s*\]/g
19
21
 
20
22
  it('should match simple entity keys', () => {
21
23
  const content = `
@@ -141,9 +143,14 @@ describe('Entity Block Regex', () => {
141
143
  assert.strictEqual(matches[0][1], 'ai-landing-page-templates')
142
144
  })
143
145
 
144
- it('should handle empty actions array', () => {
146
+ it('should handle empty actions array (multiline format)', () => {
147
+ // Note: Empty arrays on a single line (e.g., "customers: [],") won't be matched
148
+ // because the regex requires the closing ] to be on its own line.
149
+ // In practice, if you define permissions for an entity, you'd have at least one.
150
+ // This test covers the multiline empty array case.
145
151
  const content = `
146
- customers: [],
152
+ customers: [
153
+ ],
147
154
  tasks: [
148
155
  { action: 'read', roles: ['member'] }
149
156
  ]
@@ -154,6 +161,65 @@ describe('Entity Block Regex', () => {
154
161
  assert.strictEqual(matches[0][1], 'customers')
155
162
  assert.strictEqual(matches[0][2].trim(), '')
156
163
  })
164
+
165
+ /**
166
+ * CRITICAL TEST: This is the exact bug that broke beta.62
167
+ * The regex was matching `roles: ['owner', 'admin']` inside action objects
168
+ * as if it were an entity key, causing "Invalid entity slug: roles" errors.
169
+ */
170
+ it('should NOT match roles inside action objects as entity keys', () => {
171
+ // This is the exact structure from a real permissions.config.ts
172
+ const content = `
173
+ patterns: [
174
+ { action: 'create', label: 'Create Patterns', description: 'Can create patterns', roles: ['owner', 'admin'] },
175
+ { action: 'read', label: 'View Patterns', description: 'Can view patterns', roles: ['owner', 'admin', 'member'] },
176
+ { action: 'delete', label: 'Delete Patterns', description: 'Can delete patterns', roles: ['owner', 'admin'], dangerous: true },
177
+ ],
178
+
179
+ 'ai-agents': [
180
+ { action: 'create', label: 'Create AI Agents', description: 'Can create agents', roles: ['owner', 'admin'] },
181
+ { action: 'read', label: 'View AI Agents', description: 'Can view agents', roles: ['owner', 'admin', 'member'] },
182
+ ],
183
+
184
+ analysis: [
185
+ { action: 'create', label: 'Create Analysis', description: 'Can create analyses', roles: ['owner'] },
186
+ { action: 'read', label: 'View Analysis', description: 'Can view analyses', roles: ['owner', 'admin', 'member'] },
187
+ ],
188
+ }`
189
+
190
+ const matches = [...content.matchAll(entityBlockRegex)]
191
+
192
+ // Should find exactly 3 entity keys: patterns, ai-agents, analysis
193
+ // Should NOT find 'roles' as an entity key
194
+ assert.strictEqual(matches.length, 3, `Expected 3 entities but found ${matches.length}: ${matches.map(m => m[1]).join(', ')}`)
195
+
196
+ const entityNames = matches.map(m => m[1])
197
+ assert.ok(entityNames.includes('patterns'), 'Should include patterns')
198
+ assert.ok(entityNames.includes('ai-agents'), 'Should include ai-agents')
199
+ assert.ok(entityNames.includes('analysis'), 'Should include analysis')
200
+ assert.ok(!entityNames.includes('roles'), 'Should NOT include roles (that\'s inside action objects)')
201
+ })
202
+
203
+ it('should handle real-world permissions config structure', () => {
204
+ // Mimics the exact indentation and structure of a real config file
205
+ const content = `
206
+ // PATTERNS ENTITY
207
+ patterns: [
208
+ { action: 'create', label: 'Create', roles: ['owner', 'admin'] },
209
+ { action: 'read', label: 'Read', roles: ['owner', 'admin', 'member'] },
210
+ ],
211
+
212
+ // AI-AGENTS ENTITY (hyphenated, quoted)
213
+ 'ai-agents': [
214
+ { action: 'create', label: 'Create', roles: ['owner'] },
215
+ ],
216
+ }`
217
+
218
+ const matches = [...content.matchAll(entityBlockRegex)]
219
+ assert.strictEqual(matches.length, 2)
220
+ assert.strictEqual(matches[0][1], 'patterns')
221
+ assert.strictEqual(matches[1][1], 'ai-agents')
222
+ })
157
223
  })
158
224
 
159
225
  /**
@@ -12,7 +12,6 @@ export { CONFIG, CONTENT_TYPES, rootDir } from './config.mjs'
12
12
 
13
13
  // Discovery functions
14
14
  export {
15
- discoverAll,
16
15
  discoverPlugins,
17
16
  discoverRouteFiles,
18
17
  discoverEntities,