Skip to content

Commit

Permalink
pr remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
levalleux-ludo committed Jan 25, 2024
1 parent a25a160 commit cc55db7
Show file tree
Hide file tree
Showing 26 changed files with 139 additions and 80 deletions.
1 change: 1 addition & 0 deletions e2e/tests/bundle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ describe("Bundle e2e tests", () => {
product?.variants.some((variant) => variant.offer.id === bundleOffer.id)
).toBe(true);
});
xtest("Create a BUNDLE that contains a multi-variant product already listed as single offer", async () => {});
});

// TODO: check methods getAllProductsWithNotVoidedVariants() / getAllProductsWithVariants() with BUNDLE offers
2 changes: 1 addition & 1 deletion packages/ipfs-storage/src/ipfs/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class IpfsMetadataStorage

/**
* Validates and stores supported offer metadata on IPFS.
* @param metadata - Offer metadata of type `BASE` or `PRODUCT_V1`.
* @param metadata - Offer metadata of any type.
* @returns Metadata CID.
*/
public async storeMetadata(metadata: AnyMetadata): Promise<string> {
Expand Down
28 changes: 23 additions & 5 deletions packages/ipfs-storage/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,39 @@
import { AnyMetadata } from "@bosonprotocol/metadata";
import { MetadataType } from "@bosonprotocol/metadata/dist/cjs/iMetadata";

export type ERC721Metadata = AnyMetadata & {
external_url: string;
animation_url: string;
image_data?: string;
external_url?: string;
animation_url?: string;
youtube_url?: string;
external_link?: string;
attributes?: {
trait_type: string;
value: string;
display_type?: string;
}[];
};

/**
* The ERC721 metadata standard defines the property `external_url` in snake_case.
* We prefer to use camelCase though. To comply with the standard but still be consistent
* in our code, we redundantly add the property `external_url` with the value of `externalUrl`.
* Same with animationUrl field, and attributes items
*/
export function convertToERC721Metadata(metadata: AnyMetadata): ERC721Metadata {
return {
...metadata,
external_url: metadata["externalUrl"],
animation_url: metadata["animationUrl"]
image_data: metadata["image_data"] || metadata["imageData"],
external_url: metadata["external_url"] || metadata["externalUrl"],
animation_url: metadata["animation_url"] || metadata["animationUrl"],
youtube_url: metadata["youtube_url"] || metadata["youtubeUrl"],
external_link: metadata["external_link"] || metadata["externalLink"],
attributes: metadata["attributes"]?.map((attr) => {
return {
...attr,
trait_type: attr["trait_type"] || attr["traitType"],
display_type: attr["display_type"] || attr["displayType"]
};
})
};
}

Expand Down
8 changes: 5 additions & 3 deletions packages/metadata/src/base/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@
"name": { "type": "string" },
"description": { "type": "string" },
"image": { "type": "string" },
"imageData": { "type": "string" },
"externalUrl": { "type": "string" },
"licenseUrl": { "type": "string" },
"condition": { "type": "string" },
"animationUrl": { "type": "string" },
"youtubeUrl": { "type": "string" },
"attributes": {
"type": "array",
"items": {
"type": "object",
"properties": {
"trait_type": { "type": "string"},
"traitType": { "type": "string"},
"value": { "type": "string"},
"display_type": { "type": "string"}
"displayType": { "type": "string"}
},
"required": ["trait_type", "value"]
"required": ["traitType", "value"]
}
}
},
Expand Down
8 changes: 5 additions & 3 deletions packages/metadata/src/bundle/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@
"name": { "type": "string" },
"description": { "type": "string" },
"image": { "type": "string" },
"imageData": { "type": "string" },
"externalUrl": { "type": "string" },
"licenseUrl": { "type": "string" },
"youtubeUrl": { "type": "string" },
"condition": { "type": "string" },
"animationUrl": { "type": "string" },
"attributes": {
"type": "array",
"items": {
"type": "object",
"properties": {
"trait_type": { "type": "string"},
"traitType": { "type": "string"},
"value": { "type": "string"},
"display_type": { "type": "string"}
"displayType": { "type": "string"}
},
"required": ["trait_type", "value"]
"required": ["traitType", "value"]
}
},
"bundleUuid": { "type": "string"},
Expand Down
3 changes: 2 additions & 1 deletion packages/metadata/src/collection/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type CollectionMetadata = Omit<IMetadata, "type"> & {
name: string;
description?: string;
image?: string;
external_link?: string;
externalLink?: string;
external_link?: string; // Stay compliant with https://docs.opensea.io/docs/contract-level-metadata
collaborators?: string[];
};
1 change: 1 addition & 0 deletions packages/metadata/src/collection/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"name": { "type": "string" },
"description": { "type": "string" },
"image": { "type": "string" },
"externalLink": { "type": "string" },
"external_link": { "type": "string" },
"collaborators": {
"type": "array",
Expand Down
23 changes: 18 additions & 5 deletions packages/metadata/src/nftItem/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,26 @@ export type NftItem = Omit<IItemMetadata, "type"> & {
name: string;
description?: string;
image?: string;
imageData?: string;
externalUrl?: string;
animationUrl?: string;
attributes?: {
trait_type: string;
value: string;
display_type?: string;
}[];
youtubeUrl?: string;
image_data?: string; // stay compliant with https://docs.opensea.io/docs/metadata-standards
external_url?: string; // stay compliant with https://docs.opensea.io/docs/metadata-standards
animation_url?: string; // stay compliant with https://docs.opensea.io/docs/metadata-standards
youtube_url?: string; // stay compliant with https://docs.opensea.io/docs/metadata-standards
attributes?:
| {
traitType: string;
value: string;
displayType?: string;
}[]
| {
// stay compliant with https://docs.opensea.io/docs/metadata-standards
trait_type: string;
value: string;
display_type?: string;
}[];
chainId?: number;
contract?: string;
tokenId?: string;
Expand Down
10 changes: 9 additions & 1 deletion packages/metadata/src/nftItem/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,26 @@
"name": { "type": "string" },
"description": { "type": "string" },
"image": { "type": "string" },
"imageData": { "type": "string" },
"externalUrl": { "type": "string" },
"animationUrl": { "type": "string" },
"youtubeUrl": { "type": "string" },
"image_data": { "type": "string" },
"external_url": { "type": "string" },
"animation_url": { "type": "string" },
"youtube_url": { "type": "string" },
"attributes": {
"type": "array",
"items": {
"type": "object",
"properties": {
"traitType": { "type": "string"},
"trait_type": { "type": "string"},
"value": { "type": "string"},
"displayType": { "type": "string"},
"display_type": { "type": "string"}
},
"required": ["trait_type", "value"]
"required": ["value"]
}
},
"chainId": { "type": "number" },
Expand Down
2 changes: 1 addition & 1 deletion packages/metadata/src/product-v1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function createVariantProductMetadata(
// add some attributes depending on variation
const variantAttributes = metadata.variations?.map((variation) => {
return {
trait_type: variation.type,
traitType: variation.type,
value: variation.option
};
});
Expand Down
8 changes: 5 additions & 3 deletions packages/metadata/src/product-v1/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,21 @@
"description": { "type": "string" },
"externalUrl": { "type": "string" },
"licenseUrl": { "type": "string" },
"youtubeUrl": { "type": "string" },
"condition": { "type": "string" },
"image": { "type": "string" },
"imageData": { "type": "string" },
"animationUrl": { "type": "string" },
"attributes": {
"type": "array",
"items": {
"type": "object",
"properties": {
"trait_type": { "type": "string"},
"traitType": { "type": "string"},
"value": { "type": "string"},
"display_type": { "type": "string"}
"displayType": { "type": "string"}
},
"required": ["trait_type", "value"]
"required": ["traitType", "value"]
},
"minItems": 2
},
Expand Down
6 changes: 4 additions & 2 deletions packages/metadata/src/rNFT/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ export type RNftMetadata = Omit<IMetadata, "type"> & {
name: string;
description: string;
image?: string;
imageData?: string;
externalUrl: string;
licenseUrl: string;
condition?: string;
animationUrl?: string;
youtubeUrl?: string;
attributes?: {
trait_type: string;
traitType: string;
value: string;
display_type?: string;
displayType?: string;
}[];
};
6 changes: 3 additions & 3 deletions packages/metadata/src/rNFT/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
"items": {
"type": "object",
"properties": {
"trait_type": { "type": "string"},
"traitType": { "type": "string"},
"value": { "type": "string"},
"display_type": { "type": "string"}
"displayType": { "type": "string"}
},
"required": ["trait_type", "value"]
"required": ["traitType", "value"]
}
}
},
Expand Down
8 changes: 4 additions & 4 deletions packages/metadata/tests/bundle/valid/full.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
"condition": "this offer requires to own at least one NFT of Makersplace collection: https://opensea.io/collection/makersplace",
"attributes": [
{
"trait_type": "Creator",
"traitType": "Creator",
"value": "MetaFactory"
},
{
"trait_type": "Redeemable Until",
"display_type": "date",
"traitType": "Redeemable Until",
"displayType": "date",
"value": "1658492054"
},
{
"trait_type": "Offer Category",
"traitType": "Offer Category",
"value": "PHYGITAL"
}
],
Expand Down
8 changes: 4 additions & 4 deletions packages/metadata/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ describe("#validateMetadata()", () => {

xtest("throw if missing 'Redeemable Until' attribute", () => {
const attributes = productV1ValidFullOffer.attributes.map((attr) => {
if (attr.trait_type === "Redeemable Until") {
if (attr.traitType === "Redeemable Until") {
return {
...attr,
trait_type: "XXXXXX"
traitType: "XXXXXX"
};
}
return attr;
Expand All @@ -161,10 +161,10 @@ describe("#validateMetadata()", () => {

xtest("throw if missing 'Offer Category' attribute", () => {
const attributes = productV1ValidFullOffer.attributes.map((attr) => {
if (attr.trait_type === "Offer Category") {
if (attr.traitType === "Offer Category") {
return {
...attr,
trait_type: "XXXXXX"
traitType: "XXXXXX"
};
}
return attr;
Expand Down
4 changes: 2 additions & 2 deletions packages/metadata/tests/nft-item/valid/full.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"value": "MetaFactory"
},
{
"trait_type": "Redeemable Until",
"display_type": "date",
"traitType": "Redeemable Until",
"displayType": "date",
"value": "1658492054"
},
{
Expand Down
2 changes: 1 addition & 1 deletion packages/metadata/tests/product-v1/missingArguments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const productMissingArguments = [
// data: {
// attributes: [
// {
// trait_type: "Offer Category",
// traitType: "Offer Category",
// value: "PHYSICAL"
// }
// ]
Expand Down
6 changes: 3 additions & 3 deletions packages/metadata/tests/product-v1/valid/fullOffer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
"image": "https://bsn-portal-production-image-upload-storage.s3.amazonaws.com/fc11acc4-e27b-4ede-b7d3-f16735fab406",
"attributes": [
{
"trait_type": "Creator",
"traitType": "Creator",
"value": "MetaFactory"
},
{
"trait_type": "Redeemable Until",
"traitType": "Redeemable Until",
"display_type": "date",
"value": "1658492054"
},
{
"trait_type": "Offer Category",
"traitType": "Offer Category",
"value": "PHYGITAL"
}
],
Expand Down
6 changes: 3 additions & 3 deletions packages/metadata/tests/product-v1/valid/minimalOffer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
"image": "https://bsn-portal-production-image-upload-storage.s3.amazonaws.com/fc11acc4-e27b-4ede-b7d3-f16735fab406",
"attributes": [
{
"trait_type": "Redeemable Until",
"display_type": "date",
"traitType": "Redeemable Until",
"displayType": "date",
"value": "1658492054"
},
{
"trait_type": "Offer Category",
"traitType": "Offer Category",
"value": "PHYSICAL"
}
],
Expand Down
11 changes: 7 additions & 4 deletions packages/metadata/tests/product-v1/valid/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@
"name": "",
"description": "",
"externalUrl": "",
"animationUrl": "",
"youtubeUrl": "",
"image": "",
"imageData": "",
"attributes": [
{
"trait_type": "",
"traitType": "",
"value": "",
"display_type": ""
"displayType": ""
},{
"trait_type": "",
"traitType": "",
"value": "",
"display_type": ""
"displayType": ""
}
],
"product": {
Expand Down
Loading

0 comments on commit cc55db7

Please sign in to comment.