@medialane/ui 0.401.0 → 0.402.0

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,91 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var server_reads_exports = {};
20
+ __export(server_reads_exports, {
21
+ createServerReads: () => createServerReads
22
+ });
23
+ module.exports = __toCommonJS(server_reads_exports);
24
+ var import_sdk = require("@medialane/sdk");
25
+ var import_ipfs = require("./ipfs.js");
26
+ const DETAIL_REVALIDATE_SECONDS = 300;
27
+ const LIST_REVALIDATE_SECONDS = 60;
28
+ const FAILED_READ_REVALIDATE_SECONDS = 1;
29
+ const ABSENT_STATUSES = /* @__PURE__ */ new Set([400, 404]);
30
+ const isAbsent = (error) => ABSENT_STATUSES.has(error?.status);
31
+ function isAddress(value) {
32
+ try {
33
+ (0, import_sdk.normalizeAddress)("STARKNET", value);
34
+ return true;
35
+ } catch {
36
+ return false;
37
+ }
38
+ }
39
+ function createServerReads({ api, cache, backendUrl, absoluteUrl }) {
40
+ const backendOrigin = new URL(backendUrl).origin;
41
+ const expireSoon = cache(async () => null, ["failed-read"], { revalidate: FAILED_READ_REVALIDATE_SECONDS });
42
+ function cached(name, read, revalidate = DETAIL_REVALIDATE_SECONDS) {
43
+ const load = cache(
44
+ async (...args) => {
45
+ try {
46
+ return await read(...args);
47
+ } catch (error) {
48
+ if (isAbsent(error)) return null;
49
+ throw error;
50
+ }
51
+ },
52
+ [name],
53
+ { revalidate }
54
+ );
55
+ return async (...args) => {
56
+ try {
57
+ return await load(...args);
58
+ } catch {
59
+ return expireSoon();
60
+ }
61
+ };
62
+ }
63
+ const atAddress = (read) => async (...args) => isAddress(args[0]) ? read(...args) : null;
64
+ return {
65
+ ipfsToHttpServer(uri) {
66
+ const url = (0, import_ipfs.toAbsoluteImageUrl)(uri);
67
+ return url.startsWith(`${backendOrigin}/`) ? absoluteUrl(`/api/img?url=${encodeURIComponent(url)}`) : url;
68
+ },
69
+ fetchTokenMeta: cached("token-meta", atAddress((contract, tokenId) => api().tokens.get(contract, tokenId))),
70
+ fetchCollectionMeta: cached("collection-meta", atAddress((contract) => api().collections.get(contract))),
71
+ fetchCollectionBySlug: cached("collection-by-slug", (slug) => api().collections.findBySlug(slug)),
72
+ fetchDropMeta: cached("drop-meta", atAddress((contract) => api().drops.find(contract))),
73
+ fetchCoinMeta: cached("coin-meta", atAddress((contract) => api().coins.get(contract))),
74
+ fetchCreatorProfile: cached("creator-profile", (username) => api().creators.findByUsername(username)),
75
+ fetchFeaturedCollections: cached(
76
+ "featured-collections",
77
+ async (limit) => (await api().collections.list({ page: 1, limit, sort: "recent", isFeatured: true, hideEmpty: true })).data,
78
+ LIST_REVALIDATE_SECONDS
79
+ ),
80
+ fetchActiveOrders: cached(
81
+ "active-orders",
82
+ async (limit) => (await api().orders.list({ status: "ACTIVE", sort: "recent", page: 1, limit })).data,
83
+ LIST_REVALIDATE_SECONDS
84
+ )
85
+ };
86
+ }
87
+ // Annotate the CommonJS export names for ESM import in node:
88
+ 0 && (module.exports = {
89
+ createServerReads
90
+ });
91
+ //# sourceMappingURL=server-reads.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/server-reads.ts"],"sourcesContent":["import { normalizeAddress, type ApiClient } from \"@medialane/sdk\";\nimport { toAbsoluteImageUrl } from \"./ipfs.js\";\n\nconst DETAIL_REVALIDATE_SECONDS = 300;\nconst LIST_REVALIDATE_SECONDS = 60;\nconst FAILED_READ_REVALIDATE_SECONDS = 1;\nconst ABSENT_STATUSES = new Set<unknown>([400, 404]);\n\nexport type ServerReadCache = <T extends (...args: any[]) => Promise<any>>(\n read: T,\n key: string[],\n options: { revalidate: number },\n) => T;\n\nexport interface ServerReadsOptions {\n api: () => ApiClient;\n cache: ServerReadCache;\n backendUrl: string;\n absoluteUrl: (path: string) => string;\n}\n\nconst isAbsent = (error: unknown) => ABSENT_STATUSES.has((error as { status?: unknown } | null)?.status);\n\nfunction isAddress(value: string): boolean {\n try {\n normalizeAddress(\"STARKNET\", value);\n return true;\n } catch {\n return false;\n }\n}\n\nexport function createServerReads({ api, cache, backendUrl, absoluteUrl }: ServerReadsOptions) {\n const backendOrigin = new URL(backendUrl).origin;\n const expireSoon = cache(async () => null, [\"failed-read\"], { revalidate: FAILED_READ_REVALIDATE_SECONDS });\n\n function cached<A extends (string | number)[], T>(\n name: string,\n read: (...args: A) => Promise<T>,\n revalidate = DETAIL_REVALIDATE_SECONDS,\n ): (...args: A) => Promise<T | null> {\n const load = cache(\n async (...args: A): Promise<T | null> => {\n try {\n return await read(...args);\n } catch (error) {\n if (isAbsent(error)) return null;\n throw error;\n }\n },\n [name],\n { revalidate },\n );\n return async (...args: A) => {\n try {\n return await load(...args);\n } catch {\n return expireSoon();\n }\n };\n }\n\n const atAddress = <A extends [string, ...(string | number)[]], T>(read: (...args: A) => Promise<T>) =>\n async (...args: A): Promise<T | null> => (isAddress(args[0]) ? read(...args) : null);\n\n return {\n ipfsToHttpServer(uri: string | null | undefined): string {\n const url = toAbsoluteImageUrl(uri);\n return url.startsWith(`${backendOrigin}/`) ? absoluteUrl(`/api/img?url=${encodeURIComponent(url)}`) : url;\n },\n fetchTokenMeta: cached(\"token-meta\", atAddress((contract: string, tokenId: string) => api().tokens.get(contract, tokenId))),\n fetchCollectionMeta: cached(\"collection-meta\", atAddress((contract: string) => api().collections.get(contract))),\n fetchCollectionBySlug: cached(\"collection-by-slug\", (slug: string) => api().collections.findBySlug(slug)),\n fetchDropMeta: cached(\"drop-meta\", atAddress((contract: string) => api().drops.find(contract))),\n fetchCoinMeta: cached(\"coin-meta\", atAddress((contract: string) => api().coins.get(contract))),\n fetchCreatorProfile: cached(\"creator-profile\", (username: string) => api().creators.findByUsername(username)),\n fetchFeaturedCollections: cached(\n \"featured-collections\",\n async (limit: number) =>\n (await api().collections.list({ page: 1, limit, sort: \"recent\", isFeatured: true, hideEmpty: true })).data,\n LIST_REVALIDATE_SECONDS,\n ),\n fetchActiveOrders: cached(\n \"active-orders\",\n async (limit: number) => (await api().orders.list({ status: \"ACTIVE\", sort: \"recent\", page: 1, limit })).data,\n LIST_REVALIDATE_SECONDS,\n ),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAiD;AACjD,kBAAmC;AAEnC,MAAM,4BAA4B;AAClC,MAAM,0BAA0B;AAChC,MAAM,iCAAiC;AACvC,MAAM,kBAAkB,oBAAI,IAAa,CAAC,KAAK,GAAG,CAAC;AAenD,MAAM,WAAW,CAAC,UAAmB,gBAAgB,IAAK,OAAuC,MAAM;AAEvG,SAAS,UAAU,OAAwB;AACzC,MAAI;AACF,qCAAiB,YAAY,KAAK;AAClC,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEO,SAAS,kBAAkB,EAAE,KAAK,OAAO,YAAY,YAAY,GAAuB;AAC7F,QAAM,gBAAgB,IAAI,IAAI,UAAU,EAAE;AAC1C,QAAM,aAAa,MAAM,YAAY,MAAM,CAAC,aAAa,GAAG,EAAE,YAAY,+BAA+B,CAAC;AAE1G,WAAS,OACP,MACA,MACA,aAAa,2BACsB;AACnC,UAAM,OAAO;AA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,MACxB;AAAA,MACA,OAAO,WACJ,MAAM,IAAI,EAAE,YAAY,KAAK,EAAE,MAAM,GAAG,OAAO,MAAM,UAAU,YAAY,MAAM,WAAW,KAAK,CAAC,GAAG;AAAA,MACxG;AAAA,IACF;AAAA,IACA,mBAAmB;AAAA,MACjB;AAAA,MACA,OAAO,WAAmB,MAAM,IAAI,EAAE,OAAO,KAAK,EAAE,QAAQ,UAAU,MAAM,UAAU,MAAM,GAAG,MAAM,CAAC,GAAG;AAAA,MACzG;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,269 @@
1
+ import * as _medialane_sdk from '@medialane/sdk';
2
+ import { ApiClient } from '@medialane/sdk';
3
+
4
+ type ServerReadCache = <T extends (...args: any[]) => Promise<any>>(read: T, key: string[], options: {
5
+ revalidate: number;
6
+ }) => T;
7
+ interface ServerReadsOptions {
8
+ api: () => ApiClient;
9
+ cache: ServerReadCache;
10
+ backendUrl: string;
11
+ absoluteUrl: (path: string) => string;
12
+ }
13
+ declare function createServerReads({ api, cache, backendUrl, absoluteUrl }: ServerReadsOptions): {
14
+ ipfsToHttpServer(uri: string | null | undefined): string;
15
+ fetchTokenMeta: (contract: string, tokenId: string) => Promise<{
16
+ id: string;
17
+ chain: string;
18
+ contractAddress: string;
19
+ tokenId: string;
20
+ owner: string | null;
21
+ tokenUri: string | null;
22
+ metadataStatus: "PENDING" | "FETCHING" | "FETCHED" | "FAILED";
23
+ isArchived: boolean;
24
+ standard: "ERC721" | "ERC1155" | null;
25
+ metadata: {
26
+ name: string | null;
27
+ description: string | null;
28
+ image: string | null;
29
+ animationUrl: string | null;
30
+ attributes: {
31
+ [x: string]: unknown;
32
+ trait_type: string;
33
+ value: string | number | boolean;
34
+ display_type?: string | undefined;
35
+ }[] | null;
36
+ ipType: string | null;
37
+ licenseType: string | null;
38
+ commercialUse: boolean | null;
39
+ author: string | null;
40
+ externalUrl: string | null;
41
+ };
42
+ balances: {
43
+ owner: string;
44
+ amount: string;
45
+ }[] | null;
46
+ activeOrders: {
47
+ id: string;
48
+ chain: string;
49
+ orderHash: string;
50
+ offerer: string;
51
+ offer: {
52
+ itemType: string;
53
+ token: string;
54
+ identifier: string;
55
+ startAmount: string;
56
+ endAmount: string;
57
+ };
58
+ consideration: {
59
+ itemType: string;
60
+ token: string;
61
+ identifier: string;
62
+ startAmount: string;
63
+ endAmount: string;
64
+ recipient: string;
65
+ };
66
+ startTime: string;
67
+ endTime: string;
68
+ status: "ACTIVE" | "FULFILLED" | "CANCELLED" | "EXPIRED";
69
+ fulfiller: string | null;
70
+ nftContract: string | null;
71
+ nftTokenId: string | null;
72
+ price: {
73
+ raw: string | null;
74
+ formatted: string | null;
75
+ currency: string | null;
76
+ decimals: number;
77
+ };
78
+ txHash: {
79
+ created: string | null;
80
+ fulfilled: string | null;
81
+ cancelled: string | null;
82
+ };
83
+ createdBlockNumber: string;
84
+ remainingAmount: string | null;
85
+ createdAt: string;
86
+ updatedAt: string;
87
+ token: {
88
+ name: string | null;
89
+ image: string | null;
90
+ description: string | null;
91
+ animationUrl: string | null;
92
+ } | null;
93
+ parentOrderHash?: string | null | undefined;
94
+ counterOfferMessage?: string | null | undefined;
95
+ hasActiveCounterOffer?: boolean | undefined;
96
+ }[];
97
+ createdAt: string;
98
+ updatedAt: string;
99
+ holderCount?: number | undefined;
100
+ supply?: string | undefined;
101
+ } | null>;
102
+ fetchCollectionMeta: (contract: string) => Promise<{
103
+ id: string;
104
+ chain: string;
105
+ contractAddress: string;
106
+ collectionId: string | null;
107
+ name: string | null;
108
+ symbol: string | null;
109
+ description: string | null;
110
+ image: string | null;
111
+ attributes: {
112
+ [x: string]: unknown;
113
+ trait_type: string;
114
+ value: string | number | boolean;
115
+ display_type?: string | undefined;
116
+ }[] | null;
117
+ owner: string | null;
118
+ startBlock: string;
119
+ metadataStatus: "PENDING" | "FETCHING" | "FETCHED" | "FAILED";
120
+ standard: "ERC721" | "ERC1155";
121
+ isFeatured: boolean;
122
+ isHidden: boolean;
123
+ service: string | null;
124
+ floorPrice: string | null;
125
+ totalVolume: string | null;
126
+ holderCount: number;
127
+ totalSupply: number;
128
+ createdAt: string;
129
+ updatedAt: string;
130
+ profile: {
131
+ hasGatedContent: boolean;
132
+ gatedContentTitle: string | null;
133
+ slug: string | null;
134
+ image: string | null;
135
+ displayName: string | null;
136
+ description: string | null;
137
+ } | null;
138
+ } | null>;
139
+ fetchCollectionBySlug: (slug: string) => Promise<{
140
+ id: string;
141
+ chain: string;
142
+ contractAddress: string;
143
+ collectionId: string | null;
144
+ name: string | null;
145
+ symbol: string | null;
146
+ description: string | null;
147
+ image: string | null;
148
+ attributes: {
149
+ [x: string]: unknown;
150
+ trait_type: string;
151
+ value: string | number | boolean;
152
+ display_type?: string | undefined;
153
+ }[] | null;
154
+ owner: string | null;
155
+ startBlock: string;
156
+ metadataStatus: "PENDING" | "FETCHING" | "FETCHED" | "FAILED";
157
+ standard: "ERC721" | "ERC1155";
158
+ isFeatured: boolean;
159
+ isHidden: boolean;
160
+ service: string | null;
161
+ floorPrice: string | null;
162
+ totalVolume: string | null;
163
+ holderCount: number;
164
+ totalSupply: number;
165
+ createdAt: string;
166
+ updatedAt: string;
167
+ profile: {
168
+ hasGatedContent: boolean;
169
+ gatedContentTitle: string | null;
170
+ slug: string | null;
171
+ image: string | null;
172
+ displayName: string | null;
173
+ description: string | null;
174
+ } | null;
175
+ } | null>;
176
+ fetchDropMeta: (contract: string) => Promise<_medialane_sdk.ApiDrop | null>;
177
+ fetchCoinMeta: (contract: string) => Promise<_medialane_sdk.ApiCoin | null>;
178
+ fetchCreatorProfile: (username: string) => Promise<_medialane_sdk.ApiCreatorProfile | null>;
179
+ fetchFeaturedCollections: (limit: number) => Promise<{
180
+ id: string;
181
+ chain: string;
182
+ contractAddress: string;
183
+ collectionId: string | null;
184
+ name: string | null;
185
+ symbol: string | null;
186
+ description: string | null;
187
+ image: string | null;
188
+ attributes: {
189
+ [x: string]: unknown;
190
+ trait_type: string;
191
+ value: string | number | boolean;
192
+ display_type?: string | undefined;
193
+ }[] | null;
194
+ owner: string | null;
195
+ startBlock: string;
196
+ metadataStatus: "PENDING" | "FETCHING" | "FETCHED" | "FAILED";
197
+ standard: "ERC721" | "ERC1155";
198
+ isFeatured: boolean;
199
+ isHidden: boolean;
200
+ service: string | null;
201
+ floorPrice: string | null;
202
+ totalVolume: string | null;
203
+ holderCount: number;
204
+ totalSupply: number;
205
+ createdAt: string;
206
+ updatedAt: string;
207
+ profile: {
208
+ hasGatedContent: boolean;
209
+ gatedContentTitle: string | null;
210
+ slug: string | null;
211
+ image: string | null;
212
+ displayName: string | null;
213
+ description: string | null;
214
+ } | null;
215
+ }[] | null>;
216
+ fetchActiveOrders: (limit: number) => Promise<{
217
+ id: string;
218
+ chain: string;
219
+ orderHash: string;
220
+ offerer: string;
221
+ offer: {
222
+ itemType: string;
223
+ token: string;
224
+ identifier: string;
225
+ startAmount: string;
226
+ endAmount: string;
227
+ };
228
+ consideration: {
229
+ itemType: string;
230
+ token: string;
231
+ identifier: string;
232
+ startAmount: string;
233
+ endAmount: string;
234
+ recipient: string;
235
+ };
236
+ startTime: string;
237
+ endTime: string;
238
+ status: "ACTIVE" | "FULFILLED" | "CANCELLED" | "EXPIRED";
239
+ fulfiller: string | null;
240
+ nftContract: string | null;
241
+ nftTokenId: string | null;
242
+ price: {
243
+ raw: string | null;
244
+ formatted: string | null;
245
+ currency: string | null;
246
+ decimals: number;
247
+ };
248
+ txHash: {
249
+ created: string | null;
250
+ fulfilled: string | null;
251
+ cancelled: string | null;
252
+ };
253
+ createdBlockNumber: string;
254
+ remainingAmount: string | null;
255
+ createdAt: string;
256
+ updatedAt: string;
257
+ token: {
258
+ name: string | null;
259
+ image: string | null;
260
+ description: string | null;
261
+ animationUrl: string | null;
262
+ } | null;
263
+ parentOrderHash?: string | null | undefined;
264
+ counterOfferMessage?: string | null | undefined;
265
+ hasActiveCounterOffer?: boolean | undefined;
266
+ }[] | null>;
267
+ };
268
+
269
+ export { type ServerReadCache, type ServerReadsOptions, createServerReads };
@@ -0,0 +1,269 @@
1
+ import * as _medialane_sdk from '@medialane/sdk';
2
+ import { ApiClient } from '@medialane/sdk';
3
+
4
+ type ServerReadCache = <T extends (...args: any[]) => Promise<any>>(read: T, key: string[], options: {
5
+ revalidate: number;
6
+ }) => T;
7
+ interface ServerReadsOptions {
8
+ api: () => ApiClient;
9
+ cache: ServerReadCache;
10
+ backendUrl: string;
11
+ absoluteUrl: (path: string) => string;
12
+ }
13
+ declare function createServerReads({ api, cache, backendUrl, absoluteUrl }: ServerReadsOptions): {
14
+ ipfsToHttpServer(uri: string | null | undefined): string;
15
+ fetchTokenMeta: (contract: string, tokenId: string) => Promise<{
16
+ id: string;
17
+ chain: string;
18
+ contractAddress: string;
19
+ tokenId: string;
20
+ owner: string | null;
21
+ tokenUri: string | null;
22
+ metadataStatus: "PENDING" | "FETCHING" | "FETCHED" | "FAILED";
23
+ isArchived: boolean;
24
+ standard: "ERC721" | "ERC1155" | null;
25
+ metadata: {
26
+ name: string | null;
27
+ description: string | null;
28
+ image: string | null;
29
+ animationUrl: string | null;
30
+ attributes: {
31
+ [x: string]: unknown;
32
+ trait_type: string;
33
+ value: string | number | boolean;
34
+ display_type?: string | undefined;
35
+ }[] | null;
36
+ ipType: string | null;
37
+ licenseType: string | null;
38
+ commercialUse: boolean | null;
39
+ author: string | null;
40
+ externalUrl: string | null;
41
+ };
42
+ balances: {
43
+ owner: string;
44
+ amount: string;
45
+ }[] | null;
46
+ activeOrders: {
47
+ id: string;
48
+ chain: string;
49
+ orderHash: string;
50
+ offerer: string;
51
+ offer: {
52
+ itemType: string;
53
+ token: string;
54
+ identifier: string;
55
+ startAmount: string;
56
+ endAmount: string;
57
+ };
58
+ consideration: {
59
+ itemType: string;
60
+ token: string;
61
+ identifier: string;
62
+ startAmount: string;
63
+ endAmount: string;
64
+ recipient: string;
65
+ };
66
+ startTime: string;
67
+ endTime: string;
68
+ status: "ACTIVE" | "FULFILLED" | "CANCELLED" | "EXPIRED";
69
+ fulfiller: string | null;
70
+ nftContract: string | null;
71
+ nftTokenId: string | null;
72
+ price: {
73
+ raw: string | null;
74
+ formatted: string | null;
75
+ currency: string | null;
76
+ decimals: number;
77
+ };
78
+ txHash: {
79
+ created: string | null;
80
+ fulfilled: string | null;
81
+ cancelled: string | null;
82
+ };
83
+ createdBlockNumber: string;
84
+ remainingAmount: string | null;
85
+ createdAt: string;
86
+ updatedAt: string;
87
+ token: {
88
+ name: string | null;
89
+ image: string | null;
90
+ description: string | null;
91
+ animationUrl: string | null;
92
+ } | null;
93
+ parentOrderHash?: string | null | undefined;
94
+ counterOfferMessage?: string | null | undefined;
95
+ hasActiveCounterOffer?: boolean | undefined;
96
+ }[];
97
+ createdAt: string;
98
+ updatedAt: string;
99
+ holderCount?: number | undefined;
100
+ supply?: string | undefined;
101
+ } | null>;
102
+ fetchCollectionMeta: (contract: string) => Promise<{
103
+ id: string;
104
+ chain: string;
105
+ contractAddress: string;
106
+ collectionId: string | null;
107
+ name: string | null;
108
+ symbol: string | null;
109
+ description: string | null;
110
+ image: string | null;
111
+ attributes: {
112
+ [x: string]: unknown;
113
+ trait_type: string;
114
+ value: string | number | boolean;
115
+ display_type?: string | undefined;
116
+ }[] | null;
117
+ owner: string | null;
118
+ startBlock: string;
119
+ metadataStatus: "PENDING" | "FETCHING" | "FETCHED" | "FAILED";
120
+ standard: "ERC721" | "ERC1155";
121
+ isFeatured: boolean;
122
+ isHidden: boolean;
123
+ service: string | null;
124
+ floorPrice: string | null;
125
+ totalVolume: string | null;
126
+ holderCount: number;
127
+ totalSupply: number;
128
+ createdAt: string;
129
+ updatedAt: string;
130
+ profile: {
131
+ hasGatedContent: boolean;
132
+ gatedContentTitle: string | null;
133
+ slug: string | null;
134
+ image: string | null;
135
+ displayName: string | null;
136
+ description: string | null;
137
+ } | null;
138
+ } | null>;
139
+ fetchCollectionBySlug: (slug: string) => Promise<{
140
+ id: string;
141
+ chain: string;
142
+ contractAddress: string;
143
+ collectionId: string | null;
144
+ name: string | null;
145
+ symbol: string | null;
146
+ description: string | null;
147
+ image: string | null;
148
+ attributes: {
149
+ [x: string]: unknown;
150
+ trait_type: string;
151
+ value: string | number | boolean;
152
+ display_type?: string | undefined;
153
+ }[] | null;
154
+ owner: string | null;
155
+ startBlock: string;
156
+ metadataStatus: "PENDING" | "FETCHING" | "FETCHED" | "FAILED";
157
+ standard: "ERC721" | "ERC1155";
158
+ isFeatured: boolean;
159
+ isHidden: boolean;
160
+ service: string | null;
161
+ floorPrice: string | null;
162
+ totalVolume: string | null;
163
+ holderCount: number;
164
+ totalSupply: number;
165
+ createdAt: string;
166
+ updatedAt: string;
167
+ profile: {
168
+ hasGatedContent: boolean;
169
+ gatedContentTitle: string | null;
170
+ slug: string | null;
171
+ image: string | null;
172
+ displayName: string | null;
173
+ description: string | null;
174
+ } | null;
175
+ } | null>;
176
+ fetchDropMeta: (contract: string) => Promise<_medialane_sdk.ApiDrop | null>;
177
+ fetchCoinMeta: (contract: string) => Promise<_medialane_sdk.ApiCoin | null>;
178
+ fetchCreatorProfile: (username: string) => Promise<_medialane_sdk.ApiCreatorProfile | null>;
179
+ fetchFeaturedCollections: (limit: number) => Promise<{
180
+ id: string;
181
+ chain: string;
182
+ contractAddress: string;
183
+ collectionId: string | null;
184
+ name: string | null;
185
+ symbol: string | null;
186
+ description: string | null;
187
+ image: string | null;
188
+ attributes: {
189
+ [x: string]: unknown;
190
+ trait_type: string;
191
+ value: string | number | boolean;
192
+ display_type?: string | undefined;
193
+ }[] | null;
194
+ owner: string | null;
195
+ startBlock: string;
196
+ metadataStatus: "PENDING" | "FETCHING" | "FETCHED" | "FAILED";
197
+ standard: "ERC721" | "ERC1155";
198
+ isFeatured: boolean;
199
+ isHidden: boolean;
200
+ service: string | null;
201
+ floorPrice: string | null;
202
+ totalVolume: string | null;
203
+ holderCount: number;
204
+ totalSupply: number;
205
+ createdAt: string;
206
+ updatedAt: string;
207
+ profile: {
208
+ hasGatedContent: boolean;
209
+ gatedContentTitle: string | null;
210
+ slug: string | null;
211
+ image: string | null;
212
+ displayName: string | null;
213
+ description: string | null;
214
+ } | null;
215
+ }[] | null>;
216
+ fetchActiveOrders: (limit: number) => Promise<{
217
+ id: string;
218
+ chain: string;
219
+ orderHash: string;
220
+ offerer: string;
221
+ offer: {
222
+ itemType: string;
223
+ token: string;
224
+ identifier: string;
225
+ startAmount: string;
226
+ endAmount: string;
227
+ };
228
+ consideration: {
229
+ itemType: string;
230
+ token: string;
231
+ identifier: string;
232
+ startAmount: string;
233
+ endAmount: string;
234
+ recipient: string;
235
+ };
236
+ startTime: string;
237
+ endTime: string;
238
+ status: "ACTIVE" | "FULFILLED" | "CANCELLED" | "EXPIRED";
239
+ fulfiller: string | null;
240
+ nftContract: string | null;
241
+ nftTokenId: string | null;
242
+ price: {
243
+ raw: string | null;
244
+ formatted: string | null;
245
+ currency: string | null;
246
+ decimals: number;
247
+ };
248
+ txHash: {
249
+ created: string | null;
250
+ fulfilled: string | null;
251
+ cancelled: string | null;
252
+ };
253
+ createdBlockNumber: string;
254
+ remainingAmount: string | null;
255
+ createdAt: string;
256
+ updatedAt: string;
257
+ token: {
258
+ name: string | null;
259
+ image: string | null;
260
+ description: string | null;
261
+ animationUrl: string | null;
262
+ } | null;
263
+ parentOrderHash?: string | null | undefined;
264
+ counterOfferMessage?: string | null | undefined;
265
+ hasActiveCounterOffer?: boolean | undefined;
266
+ }[] | null>;
267
+ };
268
+
269
+ export { type ServerReadCache, type ServerReadsOptions, createServerReads };
@@ -0,0 +1,67 @@
1
+ import { normalizeAddress } from "@medialane/sdk";
2
+ import { toAbsoluteImageUrl } from "./ipfs.js";
3
+ const DETAIL_REVALIDATE_SECONDS = 300;
4
+ const LIST_REVALIDATE_SECONDS = 60;
5
+ const FAILED_READ_REVALIDATE_SECONDS = 1;
6
+ const ABSENT_STATUSES = /* @__PURE__ */ new Set([400, 404]);
7
+ const isAbsent = (error) => ABSENT_STATUSES.has(error?.status);
8
+ function isAddress(value) {
9
+ try {
10
+ normalizeAddress("STARKNET", value);
11
+ return true;
12
+ } catch {
13
+ return false;
14
+ }
15
+ }
16
+ function createServerReads({ api, cache, backendUrl, absoluteUrl }) {
17
+ const backendOrigin = new URL(backendUrl).origin;
18
+ const expireSoon = cache(async () => null, ["failed-read"], { revalidate: FAILED_READ_REVALIDATE_SECONDS });
19
+ function cached(name, read, revalidate = DETAIL_REVALIDATE_SECONDS) {
20
+ const load = cache(
21
+ async (...args) => {
22
+ try {
23
+ return await read(...args);
24
+ } catch (error) {
25
+ if (isAbsent(error)) return null;
26
+ throw error;
27
+ }
28
+ },
29
+ [name],
30
+ { revalidate }
31
+ );
32
+ return async (...args) => {
33
+ try {
34
+ return await load(...args);
35
+ } catch {
36
+ return expireSoon();
37
+ }
38
+ };
39
+ }
40
+ const atAddress = (read) => async (...args) => isAddress(args[0]) ? read(...args) : null;
41
+ return {
42
+ ipfsToHttpServer(uri) {
43
+ const url = toAbsoluteImageUrl(uri);
44
+ return url.startsWith(`${backendOrigin}/`) ? absoluteUrl(`/api/img?url=${encodeURIComponent(url)}`) : url;
45
+ },
46
+ fetchTokenMeta: cached("token-meta", atAddress((contract, tokenId) => api().tokens.get(contract, tokenId))),
47
+ fetchCollectionMeta: cached("collection-meta", atAddress((contract) => api().collections.get(contract))),
48
+ fetchCollectionBySlug: cached("collection-by-slug", (slug) => api().collections.findBySlug(slug)),
49
+ fetchDropMeta: cached("drop-meta", atAddress((contract) => api().drops.find(contract))),
50
+ fetchCoinMeta: cached("coin-meta", atAddress((contract) => api().coins.get(contract))),
51
+ fetchCreatorProfile: cached("creator-profile", (username) => api().creators.findByUsername(username)),
52
+ fetchFeaturedCollections: cached(
53
+ "featured-collections",
54
+ async (limit) => (await api().collections.list({ page: 1, limit, sort: "recent", isFeatured: true, hideEmpty: true })).data,
55
+ LIST_REVALIDATE_SECONDS
56
+ ),
57
+ fetchActiveOrders: cached(
58
+ "active-orders",
59
+ async (limit) => (await api().orders.list({ status: "ACTIVE", sort: "recent", page: 1, limit })).data,
60
+ LIST_REVALIDATE_SECONDS
61
+ )
62
+ };
63
+ }
64
+ export {
65
+ createServerReads
66
+ };
67
+ //# sourceMappingURL=server-reads.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/server-reads.ts"],"sourcesContent":["import { normalizeAddress, type ApiClient } from \"@medialane/sdk\";\nimport { toAbsoluteImageUrl } from \"./ipfs.js\";\n\nconst DETAIL_REVALIDATE_SECONDS = 300;\nconst LIST_REVALIDATE_SECONDS = 60;\nconst FAILED_READ_REVALIDATE_SECONDS = 1;\nconst ABSENT_STATUSES = new Set<unknown>([400, 404]);\n\nexport type ServerReadCache = <T extends (...args: any[]) => Promise<any>>(\n read: T,\n key: string[],\n options: { revalidate: number },\n) => T;\n\nexport interface ServerReadsOptions {\n api: () => ApiClient;\n cache: ServerReadCache;\n backendUrl: string;\n absoluteUrl: (path: string) => string;\n}\n\nconst isAbsent = (error: unknown) => ABSENT_STATUSES.has((error as { status?: unknown } | null)?.status);\n\nfunction isAddress(value: string): boolean {\n try {\n normalizeAddress(\"STARKNET\", value);\n return true;\n } catch {\n return false;\n }\n}\n\nexport function createServerReads({ api, cache, backendUrl, absoluteUrl }: ServerReadsOptions) {\n const backendOrigin = new URL(backendUrl).origin;\n const expireSoon = cache(async () => null, [\"failed-read\"], { revalidate: FAILED_READ_REVALIDATE_SECONDS });\n\n function cached<A extends (string | number)[], T>(\n name: string,\n read: (...args: A) => Promise<T>,\n revalidate = DETAIL_REVALIDATE_SECONDS,\n ): (...args: A) => Promise<T | null> {\n const load = cache(\n async (...args: A): Promise<T | null> => {\n try {\n return await read(...args);\n } catch (error) {\n if (isAbsent(error)) return null;\n throw error;\n }\n },\n [name],\n { revalidate },\n );\n return async (...args: A) => {\n try {\n return await load(...args);\n } catch {\n return expireSoon();\n }\n };\n }\n\n const atAddress = <A extends [string, ...(string | number)[]], T>(read: (...args: A) => Promise<T>) =>\n async (...args: A): Promise<T | null> => (isAddress(args[0]) ? read(...args) : null);\n\n return {\n ipfsToHttpServer(uri: string | null | undefined): string {\n const url = toAbsoluteImageUrl(uri);\n return url.startsWith(`${backendOrigin}/`) ? absoluteUrl(`/api/img?url=${encodeURIComponent(url)}`) : url;\n },\n fetchTokenMeta: cached(\"token-meta\", atAddress((contract: string, tokenId: string) => api().tokens.get(contract, tokenId))),\n fetchCollectionMeta: cached(\"collection-meta\", atAddress((contract: string) => api().collections.get(contract))),\n fetchCollectionBySlug: cached(\"collection-by-slug\", (slug: string) => api().collections.findBySlug(slug)),\n fetchDropMeta: cached(\"drop-meta\", atAddress((contract: string) => api().drops.find(contract))),\n fetchCoinMeta: cached(\"coin-meta\", atAddress((contract: string) => api().coins.get(contract))),\n fetchCreatorProfile: cached(\"creator-profile\", (username: string) => api().creators.findByUsername(username)),\n fetchFeaturedCollections: cached(\n \"featured-collections\",\n async (limit: number) =>\n (await api().collections.list({ page: 1, limit, sort: \"recent\", isFeatured: true, hideEmpty: true })).data,\n LIST_REVALIDATE_SECONDS,\n ),\n fetchActiveOrders: cached(\n \"active-orders\",\n async (limit: number) => (await api().orders.list({ status: \"ACTIVE\", sort: \"recent\", page: 1, limit })).data,\n LIST_REVALIDATE_SECONDS,\n ),\n };\n}\n"],"mappings":"AAAA,SAAS,wBAAwC;AACjD,SAAS,0BAA0B;AAEnC,MAAM,4BAA4B;AAClC,MAAM,0BAA0B;AAChC,MAAM,iCAAiC;AACvC,MAAM,kBAAkB,oBAAI,IAAa,CAAC,KAAK,GAAG,CAAC;AAenD,MAAM,WAAW,CAAC,UAAmB,gBAAgB,IAAK,OAAuC,MAAM;AAEvG,SAAS,UAAU,OAAwB;AACzC,MAAI;AACF,qBAAiB,YAAY,KAAK;AAClC,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEO,SAAS,kBAAkB,EAAE,KAAK,OAAO,YAAY,YAAY,GAAuB;AAC7F,QAAM,gBAAgB,IAAI,IAAI,UAAU,EAAE;AAC1C,QAA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QAAQ,CAAC,CAAC;AAAA,IAC7F,qBAAqB,OAAO,mBAAmB,CAAC,aAAqB,IAAI,EAAE,SAAS,eAAe,QAAQ,CAAC;AAAA,IAC5G,0BAA0B;AAAA,MACxB;AAAA,MACA,OAAO,WACJ,MAAM,IAAI,EAAE,YAAY,KAAK,EAAE,MAAM,GAAG,OAAO,MAAM,UAAU,YAAY,MAAM,WAAW,KAAK,CAAC,GAAG;AAAA,MACxG;AAAA,IACF;AAAA,IACA,mBAAmB;AAAA,MACjB;AAAA,MACA,OAAO,WAAmB,MAAM,IAAI,EAAE,OAAO,KAAK,EAAE,QAAQ,UAAU,MAAM,UAAU,MAAM,GAAG,MAAM,CAAC,GAAG;AAAA,MACzG;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@medialane/ui",
3
- "version": "0.401.0",
3
+ "version": "0.402.0",
4
4
  "description": "Shared UI components for Medialane apps",
5
5
  "type": "module",
6
6
  "sideEffects": false,