Skip to content

Commit 89e5113

Browse files
rekmarksclaude
andcommitted
refactor(omnium): Simplify CapletId validation to allow any ASCII string
Remove strict reverse DNS format requirement for CapletId to allow more flexibility during early development. Now accepts any non-empty ASCII string without whitespace, removing restrictions on hyphens, underscores, uppercase, and segment count. Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
1 parent 7d960a2 commit 89e5113

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

packages/omnium-gatherum/src/controllers/caplet/types.test.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,23 @@ import {
1010
describe('isCapletId', () => {
1111
it.each([
1212
['com.example.test', true],
13-
['org.metamask.keyring', true],
14-
['io.github.user.package', true],
15-
['a.b', true],
16-
['a1.b2', true],
17-
['test.caplet123', true],
13+
['simple', true],
14+
['bitcoin-signer', true],
15+
['test_caplet', true],
16+
['My-Caplet', true],
17+
['123', true],
18+
['a.b.c.d', true],
1819
])('validates "%s" as %s', (value, expected) => {
1920
expect(isCapletId(value)).toBe(expected);
2021
});
2122

2223
it.each([
23-
['', false],
24-
['single', false], // Must have at least 2 segments
25-
['com.Example.test', false], // No uppercase
26-
['com.123.test', false], // Segments cannot start with number
27-
['com..test', false], // Empty segment
28-
['com.test-name', false], // No hyphens
29-
['com.test_name', false], // No underscores
30-
['.com.test', false], // Cannot start with dot
31-
['com.test.', false], // Cannot end with dot
24+
['', false], // Empty
25+
['has space', false], // Whitespace
26+
['has\ttab', false], // Tab
27+
['has\nnewline', false], // Newline
28+
['café', false], // Non-ASCII
29+
['🎉', false], // Emoji
3230
[123, false], // Not a string
3331
[null, false],
3432
[undefined, false],
@@ -93,7 +91,7 @@ describe('isCapletManifest', () => {
9391
});
9492

9593
it('rejects manifest with invalid id', () => {
96-
expect(isCapletManifest({ ...validManifest, id: 'invalid' })).toBe(false);
94+
expect(isCapletManifest({ ...validManifest, id: 'has space' })).toBe(false);
9795
});
9896

9997
it('rejects manifest with invalid version', () => {
@@ -129,7 +127,7 @@ describe('assertCapletManifest', () => {
129127
});
130128

131129
it('throws for invalid manifest', () => {
132-
expect(() => assertCapletManifest({ id: 'bad' })).toThrow(
130+
expect(() => assertCapletManifest({ id: '' })).toThrow(
133131
'Invalid CapletManifest',
134132
);
135133
});

packages/omnium-gatherum/src/controllers/caplet/types.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,23 @@ import type { Infer } from '@metamask/superstruct';
33
import semverValid from 'semver/functions/valid';
44

55
/**
6-
* Unique identifier for a Caplet.
7-
* Uses reverse domain notation (e.g., "com.example.bitcoin-signer").
6+
* Unique identifier for a Caplet (any non-empty ASCII string without whitespace).
87
*/
98
export type CapletId = string;
109

1110
/**
1211
* Validate CapletId format.
13-
* Requires lowercase alphanumeric segments separated by dots, minimum 2 segments.
12+
* Requires non-empty ASCII string with no whitespace.
1413
*
1514
* @param value - The value to validate.
1615
* @returns True if valid CapletId format.
1716
*/
1817
export const isCapletId = (value: unknown): value is CapletId =>
1918
typeof value === 'string' &&
2019
value.length > 0 &&
21-
/^[a-z][a-z0-9]*(\.[a-z][a-z0-9]*)+$/u.test(value);
20+
// eslint-disable-next-line no-control-regex
21+
/^[\x00-\x7F]+$/u.test(value) && // ASCII only
22+
!/\s/u.test(value); // No whitespace
2223

2324
export const CapletIdStruct = define<CapletId>('CapletId', isCapletId);
2425

0 commit comments

Comments
 (0)