-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgetProductV1Metadata.ts
More file actions
190 lines (185 loc) · 6.6 KB
/
getProductV1Metadata.ts
File metadata and controls
190 lines (185 loc) · 6.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import {
Media,
MetadataType,
productV1,
productV1Item
} from "@bosonprotocol/react-kit";
import dayjs from "dayjs";
import localizedFormat from "dayjs/plugin/localizedFormat";
import uuid from "react-uuid";
dayjs.extend(localizedFormat);
import { FileProps } from "../../../components/form/Upload/types";
import {
CreateProductForm,
OPTIONS_EXCHANGE_POLICY
} from "../../../components/product/utils";
import { CONFIG } from "../../../lib/config";
import { getIpfsGatewayUrl } from "../../../lib/utils/ipfs";
import { SELLER_DEFAULT_VERSION } from "./const";
import { SupportedJuridiction } from "./types";
type GetProductV1MetadataProps = {
contactPreference: string;
offerUuid: string;
productInformation: CreateProductForm["productInformation"];
productAnimation: FileProps | undefined;
externalUrl: string;
licenseUrl: string;
productMainImageLink: string | undefined;
nftAttributes: {
traitType: string;
value: string;
displayType?: string;
}[];
additionalAttributes: {
traitType: string;
value: string;
displayType?: string;
}[];
createYourProfile: CreateProductForm["createYourProfile"];
productType: CreateProductForm["productType"];
visualImages: productV1Item.ProductBase["visuals_images"];
shippingInfo: CreateProductForm["shippingInfo"];
termsOfExchange: CreateProductForm["termsOfExchange"];
supportedJurisdictions: Array<SupportedJuridiction>;
redemptionPointUrl: string;
};
export async function getProductV1Metadata({
contactPreference,
offerUuid,
productInformation,
productAnimation,
externalUrl,
licenseUrl,
productMainImageLink,
nftAttributes,
additionalAttributes,
createYourProfile,
productType,
visualImages,
shippingInfo,
termsOfExchange,
supportedJurisdictions,
redemptionPointUrl
}: GetProductV1MetadataProps): Promise<productV1.ProductV1Metadata> {
const profileImage = createYourProfile?.logo?.[0];
const coverImage = createYourProfile?.coverPicture?.[0];
const sellerImages: productV1.ProductV1Metadata["seller"]["images"] = [
{
url: profileImage?.src || "",
tag: "profile",
height: profileImage?.height ?? undefined,
width: profileImage?.width ?? undefined,
type: profileImage?.type
},
{
url: coverImage?.src || "",
tag: "cover",
height: coverImage?.height ?? undefined,
width: coverImage?.width ?? undefined,
type: coverImage?.type
}
];
const animationUrl = getIpfsGatewayUrl(productAnimation?.src || "");
const visualsVideos: Media[] =
animationUrl === ""
? []
: [
{
url: animationUrl,
tag: ""
}
];
return {
schemaUrl: "https://schema.org/",
uuid: offerUuid,
name: productInformation.productTitle,
description: `${productInformation.description}\n\nTerms for the Boson rNFT Voucher: ${licenseUrl}`,
animationUrl,
animationMetadata: productAnimation
? {
height: productAnimation.height ?? undefined,
width: productAnimation.width ?? undefined,
type: productAnimation.type
}
: undefined,
externalUrl,
licenseUrl,
image: productMainImageLink ? productMainImageLink : "",
type: MetadataType.PRODUCT_V1,
attributes: [
...nftAttributes,
...additionalAttributes,
{ traitType: "roblox asset id", value: "607700713" }
],
condition: /*tokenGating?.tokenGatingDesc ||*/ undefined,
product: {
uuid: uuid(),
version: 1,
title: productInformation.productTitle?.toString(),
description: productInformation.description?.toString(),
identification_sKU: productInformation.sku?.toString(),
identification_productId: productInformation.id?.toString(),
identification_productIdType: productInformation.idType?.toString(),
productionInformation_brandName:
productInformation.brandName?.toString() || createYourProfile.name,
productionInformation_manufacturer:
productInformation.manufacture?.toString(),
productionInformation_manufacturerPartNumber:
productInformation.manufactureModelName?.toString(),
productionInformation_modelNumber:
productInformation.partNumber?.toString(),
productionInformation_materials: productInformation.materials?.split(","),
details_category: productInformation.category.value?.toString(),
details_subCategory: undefined, // no entry in the UI
details_subCategory2: undefined, // no entry in the UI
details_offerCategory: productType.productType.toUpperCase(),
details_tags: productInformation.tags,
details_sections: undefined, // no entry in the UI
details_personalisation: undefined, // no entry in the UI
visuals_images: visualImages,
visuals_videos: visualsVideos, // no entry in the UI
packaging_packageQuantity: undefined, // no entry in the UI
packaging_dimensions_length: shippingInfo.length?.toString(),
packaging_dimensions_width: shippingInfo.width?.toString(),
packaging_dimensions_height: shippingInfo.height?.toString(),
packaging_dimensions_unit: shippingInfo.measurementUnit.value?.toString(),
packaging_weight_value: shippingInfo?.weight?.toString() || "",
packaging_weight_unit: shippingInfo?.weightUnit.value?.toString() || ""
},
seller: {
defaultVersion: SELLER_DEFAULT_VERSION,
name: createYourProfile.name,
description: createYourProfile.description,
externalUrl: createYourProfile.website,
tokenId: undefined, // no entry in the UI
contactLinks: [
{
url: createYourProfile.email,
tag: "email"
}
],
images: sellerImages,
contactPreference
},
exchangePolicy: {
uuid: Date.now().toString(),
version: 1,
label: termsOfExchange.exchangePolicy.label,
template:
termsOfExchange.exchangePolicy.value === "fairExchangePolicy" // if there is data in localstorage, the exchangePolicy.value might be the old 'fairExchangePolicy'
? OPTIONS_EXCHANGE_POLICY[0].value
: termsOfExchange.exchangePolicy.value || "",
sellerContactMethod: CONFIG.defaultSellerContactMethod,
disputeResolverContactMethod: `email to: ${CONFIG.defaultDisputeResolverContactMethod}`
},
shipping: {
defaultVersion: 1,
countryOfOrigin:
/*TODO: NOTE: we might add it back in the future: shippingInfo.country?.label || */ "",
supportedJurisdictions:
supportedJurisdictions.length > 0 ? supportedJurisdictions : undefined,
returnPeriod: shippingInfo.returnPeriod.toString(),
redemptionPoint: redemptionPointUrl
}
};
}