@zoralabs/protocol-sdk 0.7.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,99 @@
1
+ import { getFetchableUrl } from "./gateway";
2
+ import {
3
+ DEFAULT_THUMBNAIL_CID_HASHES,
4
+ TEXT_PLAIN,
5
+ getMimeType,
6
+ isImage,
7
+ mimeTypeToMedia,
8
+ } from "./mimeTypes";
9
+ import {
10
+ MakeMediaMetadataParams,
11
+ MakeTextMetadataParams,
12
+ TokenMetadataJson,
13
+ } from "./types";
14
+
15
+ /**
16
+ * Takes properties for a text based nft and formats it as proper json metadata
17
+ * for the token, which should be uploaded to IPFS.
18
+ * @param parameters - The parameters to format into metadata {@link MakeTextMetadataParams}
19
+ */
20
+ export const makeTextTokenMetadata = (
21
+ parameters: MakeTextMetadataParams,
22
+ ): TokenMetadataJson => {
23
+ const { name, textFileUrl, thumbnailUrl, attributes = [] } = parameters;
24
+
25
+ const content = textFileUrl
26
+ ? {
27
+ mime: TEXT_PLAIN,
28
+ uri: textFileUrl,
29
+ }
30
+ : null;
31
+
32
+ const image = thumbnailUrl;
33
+ const animation_url = textFileUrl;
34
+
35
+ return {
36
+ name,
37
+ image,
38
+ animation_url,
39
+ content,
40
+ attributes,
41
+ };
42
+ };
43
+
44
+ /**
45
+ * Takes properties for a media based nft (video, image, etc) and formats it as proper json metadata
46
+ * for the token, which should be uploaded to IPFS.
47
+ * @param parameters - The parameters to format into metadata {@link MakeMediaMetadataParams}
48
+ */
49
+ export const makeMediaTokenMetadata = async ({
50
+ name,
51
+ description,
52
+ attributes = [],
53
+ mediaUrl,
54
+ thumbnailUrl,
55
+ }: MakeMediaMetadataParams): Promise<TokenMetadataJson> => {
56
+ const contentUrl = mediaUrl;
57
+ const fetchableContentUrl = getFetchableUrl(contentUrl);
58
+
59
+ if (!fetchableContentUrl)
60
+ throw new Error(`Content url (${contentUrl}) is not fetchable`);
61
+
62
+ const mimeType = await getMimeType(fetchableContentUrl);
63
+ const mediaType = mimeTypeToMedia(mimeType);
64
+
65
+ let image: string | undefined = undefined;
66
+ let animation_url: string | null = null;
67
+
68
+ // If the media is an image, just set the image field
69
+ // Otherwise we require a thumbnail, set image and animation_url
70
+ if (isImage(mimeType)) {
71
+ image = contentUrl;
72
+ } else {
73
+ image = thumbnailUrl;
74
+ animation_url = mediaUrl;
75
+ }
76
+
77
+ // If no image determined, use a fallback placeholder
78
+ if (!image)
79
+ image = `ipfs://${
80
+ DEFAULT_THUMBNAIL_CID_HASHES[mediaType] ||
81
+ DEFAULT_THUMBNAIL_CID_HASHES.default
82
+ }`;
83
+
84
+ const content = contentUrl
85
+ ? {
86
+ mime: mimeType || "application/octet-stream",
87
+ uri: contentUrl,
88
+ }
89
+ : null;
90
+
91
+ return {
92
+ name,
93
+ description,
94
+ image,
95
+ animation_url,
96
+ content,
97
+ attributes,
98
+ };
99
+ };
@@ -0,0 +1,54 @@
1
+ export type CreateERC1155TokenAttributes = {
2
+ trait_type: string;
3
+ value: string;
4
+ };
5
+
6
+ export type ContractMetadataJson = {
7
+ name?: string;
8
+ description?: string;
9
+ image?: string;
10
+ };
11
+
12
+ export type TokenMetadataJson = {
13
+ name: string;
14
+ description?: string;
15
+ /** Primary image file */
16
+ image?: string;
17
+ animation_url?: string | null;
18
+ content?: {
19
+ mime: string;
20
+ uri: string;
21
+ } | null;
22
+ attributes: Array<CreateERC1155TokenAttributes>;
23
+ };
24
+
25
+ export type BaseMetadataParams = {
26
+ /** Token name */
27
+ name: string;
28
+ /** Optional description */
29
+ description?: string;
30
+ /** Optional attributes to tag the token with */
31
+ attributes?: CreateERC1155TokenAttributes[];
32
+ };
33
+
34
+ export type MakeTextMetadataParams = BaseMetadataParams & {
35
+ /** Ipfs url where media is hosted */
36
+ textFileUrl: string;
37
+ /** If thumbnail was generate for text file, thumbnail image url */
38
+ thumbnailUrl?: string;
39
+ };
40
+
41
+ export type TextMetadataFiles = {
42
+ name: string;
43
+ /** File that holds the text, and is the primary media */
44
+ mediaUrlFile: File;
45
+ /** Thumbnail image preview of the text */
46
+ thumbnailFile: File;
47
+ };
48
+
49
+ export type MakeMediaMetadataParams = BaseMetadataParams & {
50
+ /** Ipfs url where media is hosted */
51
+ mediaUrl: string;
52
+ /** Ipfs url where thumbnail of media is hosted */
53
+ thumbnailUrl?: string;
54
+ };
@@ -65,7 +65,7 @@ type PremintedV2LogType = DecodeEventLogReturnType<
65
65
  "PremintedV2"
66
66
  >["args"];
67
67
 
68
- type URLSReturnType = {
68
+ export type URLSReturnType = {
69
69
  explorer: null | string;
70
70
  zoraCollect: null | string;
71
71
  zoraManage: null | string;
@@ -433,6 +433,7 @@ type PremintReturn<T extends PremintConfigVersion> = {
433
433
  signAndSubmit: (params: SignAndSubmitParams) => Promise<SignAndSubmitReturn>;
434
434
  /** For the case where the premint is signed externally, takes the signature for the Premint, and submits it and the Premint to the Zora Premint API */
435
435
  submit: (params: SubmitParams) => Promise<void>;
436
+ urls: URLSReturnType;
436
437
  } & PremintConfigWithVersion<T>;
437
438
 
438
439
  function makePremintReturn<T extends PremintConfigVersion>({
@@ -503,6 +504,12 @@ function makePremintReturn<T extends PremintConfigVersion>({
503
504
  });
504
505
  };
505
506
 
507
+ const urls = makeUrls({
508
+ chainId,
509
+ address: collectionAddress,
510
+ uid: premintConfig.uid,
511
+ });
512
+
506
513
  return {
507
514
  premintConfig,
508
515
  premintConfigVersion,
@@ -510,6 +517,7 @@ function makePremintReturn<T extends PremintConfigVersion>({
510
517
  collectionAddress,
511
518
  signAndSubmit,
512
519
  submit,
520
+ urls,
513
521
  };
514
522
  }
515
523