Skip to content

Commit

Permalink
feat: Add types for profiles (#1383)
Browse files Browse the repository at this point in the history
* export profile functions for wallet-sdk

* feat: add PublicPersonProfile type

* fix: export PublicPersonProfile type

* fix: type is required

* fix: add base PublicProfile type

* fix: add missing type

* fix: adopt Profile type from wallet-sdk

* chore: fix lint

Co-authored-by: friedger <mail@friedger.de>
Co-authored-by: janniks <janniks@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 23, 2022
1 parent fef15b4 commit 872478c
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 3 deletions.
2 changes: 2 additions & 0 deletions packages/profile/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ export {
verifyProfileToken,
extractProfile,
} from './profileTokens';

export { PublicProfile, PublicPersonProfile } from './types';
5 changes: 3 additions & 2 deletions packages/profile/src/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import * as inspector from 'schema-inspector';

import { Logger } from '@stacks/common';
import { createFetchFn, FetchFn } from '@stacks/network';
import { PublicPersonProfile } from './types';

const schemaDefinition: { [key: string]: any } = {
type: 'object',
Expand Down Expand Up @@ -165,7 +166,7 @@ const personSchemaDefinition = {
* @ignore
*/
export class Person extends Profile {
constructor(profile = {}) {
constructor(profile: PublicPersonProfile = { '@type': 'Person' }) {
super(profile);
this._profile = Object.assign(
{},
Expand All @@ -182,7 +183,7 @@ export class Person extends Profile {
}

static fromToken(token: string, publicKeyOrAddress: string | null = null): Person {
const profile = extractProfile(token, publicKeyOrAddress);
const profile = extractProfile(token, publicKeyOrAddress) as PublicPersonProfile;
return new Person(profile);
}

Expand Down
4 changes: 3 additions & 1 deletion packages/profile/src/profileSchemas/personLegacy.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { ProfileType } from '../types';

/**
*
* @param serviceName
Expand Down Expand Up @@ -27,7 +29,7 @@ function formatAccount(serviceName: string, data: any) {
*/
export function getPersonFromLegacyFormat(profile: any) {
const profileData: {
['@type']: string;
['@type']: ProfileType;
account?: any[];
name?: string;
description?: string;
Expand Down
73 changes: 73 additions & 0 deletions packages/profile/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
const PERSON_TYPE = 'Person';
const CONTEXT = 'http://schema.org';
const IMAGE_TYPE = 'ImageObject';

export type ProfileType = typeof PERSON_TYPE;

export interface ProfileImage {
'@type': typeof IMAGE_TYPE;
name?: string;
contentUrl?: string;
[k: string]: unknown;
}

export interface PublicProfileBase {
'@type'?: ProfileType;
'@context'?: typeof CONTEXT;
apps?: {
[origin: string]: string;
};
appsMeta?: {
[origin: string]: {
publicKey: string;
storage: string;
};
};
}

export interface PublicPersonProfile extends PublicProfileBase {
'@type': typeof PERSON_TYPE;
name?: string;
givenName?: string;
familyName?: string;
description?: string;
image?: ProfileImage[];
website?: {
'@type'?: string;
url?: string;
[k: string]: unknown;
}[];
account?: {
'@type'?: string;
service?: string;
identifier?: string;
proofType?: string;
proofUrl?: string;
proofMessage?: string;
proofSignature?: string;
[k: string]: unknown;
}[];
worksFor?: {
'@type'?: string;
'@id'?: string;
[k: string]: unknown;
}[];
knows?: {
'@type'?: string;
'@id'?: string;
[k: string]: unknown;
}[];
address?: {
'@type'?: string;
streetAddress?: string;
addressLocality?: string;
postalCode?: string;
addressCountry?: string;
[k: string]: unknown;
};
birthDate?: string;
taxID?: string;
[k: string]: unknown;
}

export type PublicProfile = PublicPersonProfile;

1 comment on commit 872478c

@vercel
Copy link

@vercel vercel bot commented on 872478c Nov 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.