Skip to content

Commit

Permalink
Add links to profile schema (#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
agusaldasoro authored Jun 9, 2023
1 parent 2fd4f01 commit 71f8952
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
24 changes: 24 additions & 0 deletions report/schemas.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export type Avatar = {
userId: string;
name: string;
description: string;
links?: Link[];
ethAddress: EthAddress;
version: number;
tutorialStep: number;
Expand Down Expand Up @@ -937,6 +938,29 @@ export enum ItemSortBy {
// @public
export type JSONSchema<T> = JSONSchemaType<T>;

// @alpha
export type Link = {
title: string;
url: LinkUrl;
};

// @alpha
export namespace Link {
const // (undocumented)
schema: JSONSchema<Link>;
}

// @alpha
export type LinkUrl = string;

// @alpha
export namespace LinkUrl {
const // (undocumented)
schema: JSONSchema<LinkUrl>;
const // (undocumented)
validate: ValidateFunction<LinkUrl>;
}

// Warning: (ae-missing-release-tag) "ListingStatus" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
// Warning: (ae-missing-release-tag) "ListingStatus" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
Expand Down
52 changes: 52 additions & 0 deletions src/platform/profile/avatar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,51 @@ export namespace AvatarInfo {
export const validate: ValidateFunction<AvatarInfo> = generateLazyValidator(schema)
}

/**
* LinkUrl
* @alpha
*/
export type LinkUrl = string

/**
* LinkUrl
* @alpha
*/
export namespace LinkUrl {
export const schema: JSONSchema<LinkUrl> = {
type: 'string',
pattern: '^((https?:)?\\/\\/)?([\\da-z.-]+)\\.([a-z.]{2,6})([\\/\\w.-]*)*\\/?$' // RFC-3986: Uniform Resource Identifier (URI): Generic Syntax // Parsing a URI Reference with a Regular Expression
}
const regexp = new RegExp(schema.pattern!, 'i')
export const validate: ValidateFunction<LinkUrl> = (url: any): url is LinkUrl => regexp.test(url)
}

/**
* Link
* @alpha
*/
export type Link = {
title: string
url: LinkUrl
}

/**
* Link
* @alpha
*/
export namespace Link {
export const schema: JSONSchema<Link> = {
type: 'object',
required: ['title', 'url'],
properties: {
title: {
type: 'string'
},
url: LinkUrl.schema
}
}
}

/**
* Avatar represents a profile avatar. Used both for comms, internal state of the
* explorer and the deployed profiles.
Expand All @@ -118,6 +163,7 @@ export type Avatar = {
userId: string
name: string
description: string
links?: Link[]
ethAddress: EthAddress
version: number
tutorialStep: number
Expand Down Expand Up @@ -152,6 +198,12 @@ export namespace Avatar {
description: {
type: 'string'
},
links: {
type: 'array',
maxItems: 5,
items: Link.schema,
nullable: true
},
ethAddress: EthAddress.schema,
version: {
type: 'number'
Expand Down
10 changes: 10 additions & 0 deletions test/platform/profiles/avatar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ export const AVATAR: Avatar = {
name: 'Some Name',
hasClaimedName: true,
description: 'Some Description',
links: [
{
title: 'Twitter',
url: 'https://twitter.com/decentraland'
},
{
title: 'Discord',
url: 'https://discord.gg/decentraland'
}
],
ethAddress: '0x87956abC4078a0Cc3b89b419628b857B8AF826Ed',
version: 44,
avatar: AVATAR_INFO,
Expand Down

0 comments on commit 71f8952

Please sign in to comment.