Skip to content

Commit

Permalink
Validate snap ids (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
FrederikBolding authored Sep 4, 2023
1 parent a9ebda1 commit e5f0835
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,20 @@ import {
union,
optional,
enums,
refine,
} from 'superstruct';

// For now, validate that each snap is using an NPM id.
const NpmIdStruct = refine(string(), 'Npm ID', (value) =>
value.startsWith('npm:'),
);

const VerifiedSnapVersionStruct = object({
checksum: ChecksumStruct,
});

export const VerifiedSnapStruct = object({
id: string(),
id: NpmIdStruct,
metadata: object({
name: string(),
type: optional(enums(['account'])),
Expand All @@ -44,15 +50,15 @@ export type BlockReason = Infer<typeof BlockReasonStruct>;

export const BlockedSnapStruct = union([
object({
id: string(),
id: NpmIdStruct,
versionRange: VersionRangeStruct,
reason: optional(BlockReasonStruct),
}),
object({ checksum: ChecksumStruct, reason: optional(BlockReasonStruct) }),
]);

export const SnapsRegistryDatabaseStruct = object({
verifiedSnaps: record(string(), VerifiedSnapStruct),
verifiedSnaps: record(NpmIdStruct, VerifiedSnapStruct),
blockedSnaps: array(BlockedSnapStruct),
});

Expand Down

0 comments on commit e5f0835

Please sign in to comment.