Skip to content

Commit

Permalink
Merge branch 'main' into chore/relax-node-version
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarenaldi authored Mar 8, 2024
2 parents ceb8634 + 74c3817 commit 39295fb
Show file tree
Hide file tree
Showing 22 changed files with 117 additions and 108 deletions.
5 changes: 5 additions & 0 deletions .changeset/seven-doors-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lens-protocol/metadata': patch
---

**fix:** internal `MarketplaceMetadataSchema` for parsing of Lens v1 Collect NFTs.
2 changes: 1 addition & 1 deletion src/builders/publications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { v4 } from 'uuid';

import { evaluate } from './ValidationError';
import { RecursiveUnbrand, InputForPublicationMetadataDetails } from './utils';
import { MarketplaceMetadata } from '../marketplace';
import {
ThreeDMetadata,
ThreeDSchema,
Expand Down Expand Up @@ -33,7 +34,6 @@ import {
TransactionSchema,
VideoMetadata,
VideoSchema,
MarketplaceMetadata,
ArticleMetadataDetails,
AudioMetadataDetails,
CheckingInMetadataDetails,
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from './builders/index.js';
export * from './constants.js';
export * from './extractVersion.js';
export * from './formatters.js';
export * from './marketplace.js';
export * from './MetadataAttribute.js';
export * from './module/index.js';
export * from './primitives.js';
Expand Down
16 changes: 2 additions & 14 deletions src/legacy/__tests__/PublicationMetadataSchema.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,6 @@ describe(`Given the PublicationMetadataSchema`, () => {
});

describe(`when parsing an invalid v1 object`, () => {
it(`then it should complain about missing basic mandatory fields`, () => {
expectResult(() =>
PublicationMetadataSchema.safeParse({
version: '1.0.0',
}),
).toMatchInlineSnapshot(`
"fix the following issues
· "name": Required"
`);
});

it('then it should pass on expected nullable fields', () => {
expectResult(() =>
PublicationMetadataSchema.safeParse({
Expand Down Expand Up @@ -165,7 +154,6 @@ describe(`Given the PublicationMetadataSchema`, () => {
}),
).toMatchInlineSnapshot(`
"fix the following issues
· "name": Required
· "content": Required
· "locale": Required"
`);
Expand Down Expand Up @@ -648,7 +636,7 @@ describe(`Given the PublicationMetadataSchema`, () => {
Ut quis quod et voluptatem nobis est dolores reprehenderit nam porro consequuntur. Aut aperiam unde non quia sint est quia nihil ut dolor dolores rem esse veniam. Ut neque voluptatem ut dolorum eveniet est reprehenderit quia sed sunt necessitatibus qui aliquam rerum.",
"external_url": null,
"image": "ipfs//:bafkreibbydhgzfdapyu3ra3ei7xxnhaqaw4acczhdmb5b6xqrobuzmlkaa",
"image": null,
"imageMimeType": null,
"locale": "en-us",
"mainContentFocus": "TEXT_ONLY",
Expand Down Expand Up @@ -1279,7 +1267,7 @@ describe(`Given the PublicationMetadataSchema`, () => {
"encryptionKey": "09a605177283511c4662ccc1154193f42c0eff4bd27e529cc08ebe83c9ac98d2502580f788bca99ded0c01c56207c00e9094aa7a19b156d63ee05b0bbf7c08918779ed62fe366b33cd660bc36d80ca278a34ac17b2321521e091600a8be060b6c6cd0c30c2d55f9d9b61a0e47aa98a938525b67393c5cfb59ab724ca6d23b0bf0000000000000020f3c7c41c82ff1d66f2e4b6bcfdae224fda8b5e32a45c4e5c5df3286832c41f14a9b087bc74486f566d07b11b612c47b0",
},
},
"external_url": "This publication is gated.",
"external_url": null,
"image": null,
"imageMimeType": null,
"locale": "en-AU",
Expand Down
94 changes: 47 additions & 47 deletions src/legacy/publication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { v4 } from 'uuid';
import { z } from 'zod';

import { MarketplaceMetadataSchema } from '../marketplace.js';
import {
LocaleSchema,
Markdown,
Expand All @@ -12,16 +13,15 @@ import {
import * as latest from '../publication';
import {
ConditionComparisonOperator,
MarketplaceMetadataAttributeSchema,
NftContractType,
PublicationContentWarning,
} from '../publication/common';
import { hasTwoOrMore } from '../utils.js';

// re-export under legacy namespace
export { ConditionComparisonOperator, NftContractType, PublicationContentWarning };
export { MarketplaceMetadataAttributeDisplayType } from '../publication/common';
export type { MarketplaceMetadataAttribute, MarketplaceMetadata } from '../publication/common';
export { MarketplaceMetadataAttributeDisplayType } from '../marketplace.js';
export type { MarketplaceMetadataAttribute, MarketplaceMetadata } from '../marketplace.js';
export type * from '../primitives.js';

export enum PublicationMetadataVersion {
Expand Down Expand Up @@ -104,47 +104,47 @@ const AnimationUrlSchema = z.string({
'WebGL, and more. Scripts and relative paths within the HTML page are now supported. However, access to browser extensions is not supported.',
});

const OpenSeaSchema = z
.object({
description: z
.string({
description:
'A human-readable description of the item. It could be plain text or markdown.',
})
.optional()
.nullable()
.catch(null),

external_url: z
.string({
description:
`This is the URL that will appear below the asset's image on OpenSea and others etc. ` +
'and will allow users to leave OpenSea and view the item on the site.',
})
.optional()
.nullable(),

name: z.string({ description: 'Name of the NFT item.' }),

attributes: MarketplaceMetadataAttributeSchema.array()
.describe(
'These are the attributes for the item, which will show up on the OpenSea and others NFT trading websites on the item.',
)
.catch([]),

image: z
.string({
description: 'Marketplaces will store any NFT image here.',
})
.optional()
.nullable()
.catch(null),

animation_url: AnimationUrlSchema.optional().nullable(),

version: z.nativeEnum(PublicationMetadataVersion),
})
.passthrough(); // loose validation for any unknown fields
// const OpenSeaSchema = z
// .object({
// description: z
// .string({
// description:
// 'A human-readable description of the item. It could be plain text or markdown.',
// })
// .optional()
// .nullable()
// .catch(null),

// external_url: z
// .string({
// description:
// `This is the URL that will appear below the asset's image on OpenSea and others etc. ` +
// 'and will allow users to leave OpenSea and view the item on the site.',
// })
// .optional()
// .nullable(),

// name: z.string({ description: 'Name of the NFT item.' }),

// attributes: MarketplaceMetadataAttributeSchema.array()
// .describe(
// 'These are the attributes for the item, which will show up on the OpenSea and others NFT trading websites on the item.',
// )
// .catch([]),

// image: z
// .string({
// description: 'Marketplaces will store any NFT image here.',
// })
// .optional()
// .nullable()
// .catch(null),

// animation_url: AnimationUrlSchema.optional().nullable(),

// version: z.nativeEnum(PublicationMetadataVersion),
// })
// .passthrough(); // loose validation for any unknown fields

/**
* @internal
Expand Down Expand Up @@ -186,7 +186,7 @@ function isEmptyString(value: string | null | undefined): value is '' | null | u
return isNullish(value) || value.length === 0;
}

const PublicationCommonSchema = OpenSeaSchema.extend({
const PublicationCommonSchema = MarketplaceMetadataSchema.extend({
metadata_id: z
.string({
description:
Expand All @@ -213,6 +213,8 @@ const PublicationCommonSchema = OpenSeaSchema.extend({
.optional()
.nullable()
.describe('The App Id that this publication belongs to.'),

version: z.nativeEnum(PublicationMetadataVersion),
});

/**
Expand Down Expand Up @@ -629,6 +631,4 @@ export const PublicationMetadataSchema: z.ZodType<PublicationMetadata, z.ZodType

return v2Result.data;
}

return z.NEVER;
});
74 changes: 45 additions & 29 deletions src/publication/common/marketplace.ts → src/marketplace.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from 'zod';

import { Markdown, URI, markdown, nonEmptyStringSchema, uriSchema } from '../../primitives.js';
import { Markdown, URI, markdown, nonEmptyStringSchema, uriSchema } from './primitives.js';

/**
* The display type of a marketplace metadata attribute.
Expand Down Expand Up @@ -48,12 +48,12 @@ export type MarketplaceMetadata = {
/**
* A human-readable description of the item. It could be plain text or markdown.
*/
description?: Markdown;
description?: Markdown | null;
/**
* This is the URL that will appear below the asset's image on OpenSea and others etc.
* and will allow users to leave OpenSea and view the item on the site.
*/
external_url?: URI;
external_url?: URI | null;
/**
* Name of the NFT item.
*/
Expand All @@ -67,45 +67,61 @@ export type MarketplaceMetadata = {
/**
* Marketplaces will store any NFT image here.
*/
image?: URI;
image?: URI | null;
/**
* A URL to a multi-media attachment for the item. The file extensions GLTF, GLB, WEBM, MP4, M4V, OGV,
* and OGG are supported, along with the audio-only extensions MP3, WAV, and OGA.
* `animation_url` also supports HTML pages, allowing you to build rich experiences and interactive NFTs using JavaScript canvas,
* WebGL, and more. Scripts and relative paths within the HTML page are now supported. However, access to browser extensions is not supported.
*/
animation_url?: URI;
animation_url?: URI | null;
};

/**
* @internal
*/
export const MarketplaceMetadataSchema = z.object({
description: markdown(
z.string({
description: 'A human-readable description of the item. It could be plain text or markdown.',
}),
).optional(),
export const MarketplaceMetadataSchema = z
.object({
description: markdown(
z.string({
description:
'A human-readable description of the item. It could be plain text or markdown.',
}),
)
.optional()
.nullable()
.catch(null),

external_url: uriSchema(
`This is the URL that will appear below the asset's image on OpenSea and others etc. ` +
'and will allow users to leave OpenSea and view the item on the site.',
).optional(),
external_url: uriSchema(
`This is the URL that will appear below the asset's image on OpenSea and others etc. ` +
'and will allow users to leave OpenSea and view the item on the site.',
)
.optional()
.nullable()
.catch(null),

name: z.string({ description: 'Name of the NFT item.' }).optional(),
name: z.string({ description: 'Name of the NFT item.' }).optional(),

attributes: MarketplaceMetadataAttributeSchema.array()
.optional()
.describe(
'These are the attributes for the item, which will show up on the OpenSea and others NFT trading websites on the item.',
),
attributes: MarketplaceMetadataAttributeSchema.array()
.optional()
.describe(
'These are the attributes for the item, which will show up on the OpenSea and others NFT trading websites on the item.',
)
.catch([]),

image: uriSchema('Marketplaces will store any NFT image here.').optional(),
image: uriSchema('Marketplaces will store any NFT image here.')
.optional()
.nullable()
.catch(null),

animation_url: uriSchema(
'A URL to a multi-media attachment for the item. The file extensions GLTF, GLB, WEBM, MP4, M4V, OGV, ' +
'and OGG are supported, along with the audio-only extensions MP3, WAV, and OGA. ' +
'Animation_url also supports HTML pages, allowing you to build rich experiences and interactive NFTs using JavaScript canvas, ' +
'WebGL, and more. Scripts and relative paths within the HTML page are now supported. However, access to browser extensions is not supported.',
).optional(),
});
animation_url: uriSchema(
'A URL to a multi-media attachment for the item. The file extensions GLTF, GLB, WEBM, MP4, M4V, OGV, ' +
'and OGG are supported, along with the audio-only extensions MP3, WAV, and OGA. ' +
'Animation_url also supports HTML pages, allowing you to build rich experiences and interactive NFTs using JavaScript canvas, ' +
'WebGL, and more. Scripts and relative paths within the HTML page are now supported. However, access to browser extensions is not supported.',
)
.optional()
.nullable()
.catch(null),
})
.passthrough(); // loose validation for any unknown fields;
2 changes: 1 addition & 1 deletion src/publication/3D.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
MetadataLicenseType,
MetadataLicenseTypeSchema,
publicationWith,
MarketplaceMetadata,
optionalContentSchema,
} from './common';
import { MarketplaceMetadata } from '../marketplace.js';
import {
EncryptableMarkdown,
nonEmptyStringSchema,
Expand Down
2 changes: 1 addition & 1 deletion src/publication/ArticleSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { PublicationSchemaId } from './PublicationSchemaId.js';
import {
AnyMedia,
AnyMediaSchema,
MarketplaceMetadata,
PublicationMetadataCommon,
mainContentFocus,
metadataDetailsWith,
publicationWith,
} from './common';
import { MarketplaceMetadata } from '../marketplace.js';
import {
EncryptableMarkdown,
Signature,
Expand Down
2 changes: 1 addition & 1 deletion src/publication/AudioSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import {
AnyMedia,
AnyMediaSchema,
mainContentFocus,
MarketplaceMetadata,
MediaAudio,
MediaAudioSchema,
metadataDetailsWith,
optionalContentSchema,
PublicationMetadataCommon,
publicationWith,
} from './common';
import { MarketplaceMetadata } from '../marketplace.js';
import { EncryptableMarkdown, nonEmptyStringSchema, Signature } from '../primitives.js';

export type AudioMetadataDetails = PublicationMetadataCommon & {
Expand Down
2 changes: 1 addition & 1 deletion src/publication/CheckingInSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { PublicationSchemaId } from './PublicationSchemaId.js';
import {
AnyMedia,
AnyMediaSchema,
MarketplaceMetadata,
PublicationMetadataCommon,
mainContentFocus,
metadataDetailsWith,
optionalContentSchema,
publicationWith,
} from './common';
import { MarketplaceMetadata } from '../marketplace.js';
import {
EncryptableGeoURI,
EncryptableMarkdown,
Expand Down
2 changes: 1 addition & 1 deletion src/publication/EmbedSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { PublicationSchemaId } from './PublicationSchemaId.js';
import {
AnyMedia,
AnyMediaSchema,
MarketplaceMetadata,
PublicationMetadataCommon,
mainContentFocus,
metadataDetailsWith,
optionalContentSchema,
publicationWith,
} from './common';
import { MarketplaceMetadata } from '../marketplace.js';
import {
EncryptableMarkdown,
EncryptableURI,
Expand Down
Loading

0 comments on commit 39295fb

Please sign in to comment.