Skip to content

Commit

Permalink
Update author and audits fields (#78)
Browse files Browse the repository at this point in the history
* Update author and audits fields

* Update tests
  • Loading branch information
Mrtenz authored Sep 5, 2023
1 parent 5cdbc86 commit 57a3777
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 14 deletions.
18 changes: 16 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,30 @@ const VerifiedSnapVersionStruct = object({
checksum: ChecksumStruct,
});

export const AuthorStruct = object({
name: string(),
website: string(),
});

export type Author = Infer<typeof AuthorStruct>;

export const AuditStruct = object({
auditor: string(),
report: string(),
});

export type Audit = Infer<typeof AuditStruct>;

export const VerifiedSnapStruct = object({
id: NpmIdStruct,
metadata: object({
name: string(),
type: optional(enums(['account'])),
author: optional(string()),
author: optional(AuthorStruct),
website: optional(string()),
summary: optional(string()),
description: optional(string()),
audits: optional(array(string())),
audits: optional(array(AuditStruct)),
tags: optional(array(string())),
support: optional(string()),
sourceCode: optional(string()),
Expand Down
35 changes: 23 additions & 12 deletions src/registry.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { SemVerRange, SemVerVersion } from '@metamask/utils';
import { assert } from 'superstruct';

import type { SnapsRegistryDatabase } from '.';
import { SnapsRegistryDatabaseStruct } from '.';
import registry from './registry.json';

Expand All @@ -10,27 +12,36 @@ describe('Snaps Registry', () => {

it('has a valid account snap', () => {
/* eslint-disable @typescript-eslint/naming-convention */
const registryDb = {
const registryDb: SnapsRegistryDatabase = {
verifiedSnaps: {
'npm:example-snap': {
id: 'npm:example-snap',
metadata: {
name: 'Example Snap',
type: 'account',
author: 'Example Author',
author: {
name: 'MetaMask',
website: 'https://metamask.io',
},
website: 'https://metamask.io',
summary: 'Example Snap',
description: 'Longer Example Snap description.',
audits: [
'https://metamask.io/example/report-1.pdf',
'https://metamask.io/example/report-2.pdf',
{
auditor: 'Example Auditor',
report: 'https://metamask.io/example/report-1.pdf',
},
{
auditor: 'Example Auditor',
report: 'https://metamask.io/example/report-2.pdf',
},
],
support: 'https://metamask.io/example/support',
sourceCode: 'https://metamask.io/example/source-code',
tags: ['accounts', 'example'],
},
versions: {
'0.1.0': {
['0.1.0' as SemVerVersion]: {
checksum: 'A83r5/ZIcKeKw3An13HBeV4CAofj7jGK5hOStmHY6A0=',
},
},
Expand All @@ -39,7 +50,7 @@ describe('Snaps Registry', () => {
blockedSnaps: [
{
id: 'npm:example-blocked-snap',
versionRange: '^0.1.0',
versionRange: '^0.1.0' as SemVerRange,
reason: {
explanation: 'Example explanation',
url: 'https://metamask.io/example/explanation',
Expand All @@ -61,15 +72,15 @@ describe('Snaps Registry', () => {

it('has a only mandatory fields', () => {
/* eslint-disable @typescript-eslint/naming-convention */
const registryDb = {
const registryDb: SnapsRegistryDatabase = {
verifiedSnaps: {
'npm:example-snap': {
id: 'npm:example-snap',
metadata: {
name: 'Example Snap',
},
versions: {
'0.1.0': {
['0.1.0' as SemVerVersion]: {
checksum: 'A83r5/ZIcKeKw3An13HBeV4CAofj7jGK5hOStmHY6A0=',
},
},
Expand All @@ -78,7 +89,7 @@ describe('Snaps Registry', () => {
blockedSnaps: [
{
id: 'npm:example-blocked-snap',
versionRange: '^0.1.0',
versionRange: '^0.1.0' as SemVerRange,
},
{
checksum: 'B3ar53ZIcKeKw3An3aqBeV4CAofj7jGK5hOAAxQY6A0=',
Expand All @@ -91,17 +102,17 @@ describe('Snaps Registry', () => {
});

it('should throw when the metadata has an unexpected field', () => {
/* eslint-disable @typescript-eslint/naming-convention */
const registryDb = {
const registryDb: SnapsRegistryDatabase = {
verifiedSnaps: {
'npm:example-snap': {
id: 'npm:example-snap',
metadata: {
name: 'Example Snap',
// @ts-expect-error - Unexpected field.
unexpected: 'field',
},
versions: {
'0.1.0': {
['0.1.0' as SemVerVersion]: {
checksum: 'A83r5/ZIcKeKw3An13HBeV4CAofj7jGK5hOStmHY6A0=',
},
},
Expand Down

0 comments on commit 57a3777

Please sign in to comment.