@holoscript/core 6.0.4 → 7.0.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.
Files changed (236) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -1
  3. package/dist/compiler/index.d.ts +82 -0
  4. package/dist/constants.d.ts +3 -2
  5. package/dist/coordinators/index.d.ts +189 -0
  6. package/dist/index.d.ts +501 -19
  7. package/dist/paper-0c-spike/index.d.ts +29 -0
  8. package/dist/reconstruction/index.d.ts +78 -0
  9. package/dist/tools/index.d.ts +22 -1
  10. package/dist/traitDocs/traitDocs.d.ts +69 -0
  11. package/dist/traits/index.d.ts +61 -0
  12. package/package.json +105 -57
  13. package/dist/GLTFPipeline-DEN36VNK.js +0 -12
  14. package/dist/GLTFPipeline-YPCAK236.cjs +0 -33
  15. package/dist/HoloScriptPlusParser-BN6KVRCM.js +0 -692
  16. package/dist/HoloScriptPlusParser-NC5FE6AL.cjs +0 -697
  17. package/dist/USDZExporter-NTMBNTDB.js +0 -707
  18. package/dist/USDZExporter-UWGWNMMD.cjs +0 -709
  19. package/dist/chunk-27LWW5FU.cjs +0 -410
  20. package/dist/chunk-2CWOLHTE.js +0 -69
  21. package/dist/chunk-33LSUQDD.cjs +0 -835
  22. package/dist/chunk-3FJCK5XA.js +0 -2232
  23. package/dist/chunk-3FXV5S25.cjs +0 -633
  24. package/dist/chunk-3FYZOR7S.cjs +0 -69
  25. package/dist/chunk-3SAK5KFL.cjs +0 -83
  26. package/dist/chunk-4XSNJCLC.cjs +0 -1859
  27. package/dist/chunk-54FHG2MX.js +0 -655
  28. package/dist/chunk-56IF4NTA.js +0 -56
  29. package/dist/chunk-5BGSECRJ.cjs +0 -2237
  30. package/dist/chunk-5GLCTO44.js +0 -161
  31. package/dist/chunk-5O6TQC6M.cjs +0 -1871
  32. package/dist/chunk-5OEOHAAW.cjs +0 -682
  33. package/dist/chunk-5TOFIR6L.js +0 -407
  34. package/dist/chunk-5WUNN6ZN.cjs +0 -428
  35. package/dist/chunk-6TZPZCOJ.cjs +0 -1404
  36. package/dist/chunk-6UEHYZ7V.cjs +0 -773
  37. package/dist/chunk-6XSERL6L.js +0 -5678
  38. package/dist/chunk-72EQECGT.cjs +0 -908
  39. package/dist/chunk-7AGYRWKW.cjs +0 -507
  40. package/dist/chunk-7LCYLPW2.cjs +0 -663
  41. package/dist/chunk-A7PIMZGU.js +0 -263
  42. package/dist/chunk-ATSKSYVE.cjs +0 -51683
  43. package/dist/chunk-B5TCIAPQ.cjs +0 -117
  44. package/dist/chunk-BF2235SI.cjs +0 -5714
  45. package/dist/chunk-BKIGPPVM.js +0 -629
  46. package/dist/chunk-BND3ST2K.cjs +0 -662
  47. package/dist/chunk-BU7VWW2K.js +0 -2522
  48. package/dist/chunk-BWFJEM5A.js +0 -5419
  49. package/dist/chunk-CAUCGUEA.cjs +0 -130
  50. package/dist/chunk-CBJSLA2E.cjs +0 -5423
  51. package/dist/chunk-CDPGV4DN.js +0 -114
  52. package/dist/chunk-CLYEIWA5.cjs +0 -408
  53. package/dist/chunk-CS2EMTGF.js +0 -1966
  54. package/dist/chunk-DMG7C4H2.js +0 -975
  55. package/dist/chunk-DXJQDCFL.js +0 -468
  56. package/dist/chunk-E3FWRT3Z.js +0 -608
  57. package/dist/chunk-E3UALNFA.js +0 -421
  58. package/dist/chunk-EONILVMF.js +0 -762
  59. package/dist/chunk-EQV4R3EV.cjs +0 -769
  60. package/dist/chunk-F3HH56EB.cjs +0 -5538
  61. package/dist/chunk-F4IULT7N.js +0 -1488
  62. package/dist/chunk-FF3Q7ADR.js +0 -380
  63. package/dist/chunk-FFKU7BTK.cjs +0 -1046
  64. package/dist/chunk-FHQVYCH2.js +0 -70
  65. package/dist/chunk-FSF7EQVA.cjs +0 -1974
  66. package/dist/chunk-G4VZTCIB.js +0 -659
  67. package/dist/chunk-G7CT3EMP.cjs +0 -1002
  68. package/dist/chunk-GGHSW2NN.js +0 -51334
  69. package/dist/chunk-GVUR45UF.cjs +0 -777
  70. package/dist/chunk-H5Z7NASB.js +0 -9662
  71. package/dist/chunk-HE7ULERA.cjs +0 -697
  72. package/dist/chunk-HJJLD366.js +0 -1169
  73. package/dist/chunk-HPS76H7Q.js +0 -309
  74. package/dist/chunk-HQUEA5R6.cjs +0 -424
  75. package/dist/chunk-HYNTS5CP.js +0 -422
  76. package/dist/chunk-I6XZ5DZF.cjs +0 -488
  77. package/dist/chunk-IBDG74G2.cjs +0 -1219
  78. package/dist/chunk-IFNQFCTM.js +0 -3098
  79. package/dist/chunk-IHOUYQIA.js +0 -406
  80. package/dist/chunk-ILRBGFVD.cjs +0 -72
  81. package/dist/chunk-IWI6J7FX.js +0 -421
  82. package/dist/chunk-K3JDKWGI.cjs +0 -270
  83. package/dist/chunk-K6EKD26I.js +0 -630
  84. package/dist/chunk-KCQ5NDYC.cjs +0 -3172
  85. package/dist/chunk-KED34ILP.js +0 -832
  86. package/dist/chunk-KSGXLT74.cjs +0 -457
  87. package/dist/chunk-L4G4RLXX.js +0 -767
  88. package/dist/chunk-LDP5OK6G.js +0 -1216
  89. package/dist/chunk-LGGRPKTV.cjs +0 -735
  90. package/dist/chunk-LK5IAVH6.cjs +0 -1173
  91. package/dist/chunk-LSW7P7ML.js +0 -3675
  92. package/dist/chunk-LXJ4667L.cjs +0 -3874
  93. package/dist/chunk-LZ266PCM.cjs +0 -4499
  94. package/dist/chunk-MD6KDHVE.cjs +0 -237
  95. package/dist/chunk-MEASWI2Y.js +0 -126
  96. package/dist/chunk-MPXBVFHQ.js +0 -768
  97. package/dist/chunk-N5FTS757.cjs +0 -415
  98. package/dist/chunk-NCUKG4SK.cjs +0 -3075
  99. package/dist/chunk-NDQNIJEH.js +0 -1715
  100. package/dist/chunk-NOZZ46QU.js +0 -168
  101. package/dist/chunk-OFKWH2IP.js +0 -449
  102. package/dist/chunk-PHENW4MQ.js +0 -65
  103. package/dist/chunk-PMGODDJA.cjs +0 -319
  104. package/dist/chunk-Q4QX3AET.cjs +0 -1505
  105. package/dist/chunk-Q56TT7IL.js +0 -483
  106. package/dist/chunk-Q5JT3YML.cjs +0 -129
  107. package/dist/chunk-Q5SJOGHQ.cjs +0 -4256
  108. package/dist/chunk-QGKNANZ3.js +0 -3071
  109. package/dist/chunk-QLEAOI3Q.cjs +0 -424
  110. package/dist/chunk-R7MA7QWV.js +0 -732
  111. package/dist/chunk-RVYPEYPX.js +0 -678
  112. package/dist/chunk-S2N5TNMA.js +0 -1855
  113. package/dist/chunk-S565K7NK.js +0 -752
  114. package/dist/chunk-SDAMZIRE.js +0 -765
  115. package/dist/chunk-T36DDXSF.js +0 -4250
  116. package/dist/chunk-T4NKMBDL.js +0 -5474
  117. package/dist/chunk-T7LEXZUZ.cjs +0 -2526
  118. package/dist/chunk-TEWCN33Y.js +0 -694
  119. package/dist/chunk-TQSZUOW5.cjs +0 -793
  120. package/dist/chunk-TSH3MSQU.cjs +0 -129
  121. package/dist/chunk-UERJ3YJV.js +0 -504
  122. package/dist/chunk-UPJBDCVF.js +0 -1395
  123. package/dist/chunk-V3NN3HPP.js +0 -4462
  124. package/dist/chunk-VJ3L7CHT.cjs +0 -169
  125. package/dist/chunk-WB4Z63GG.js +0 -229
  126. package/dist/chunk-WDW67DZB.cjs +0 -9728
  127. package/dist/chunk-WGMEAYBG.js +0 -126
  128. package/dist/chunk-X4ZF6CNE.cjs +0 -473
  129. package/dist/chunk-X6SEAXAX.cjs +0 -3681
  130. package/dist/chunk-XCWFGZAA.js +0 -1043
  131. package/dist/chunk-XD6IYDUX.js +0 -903
  132. package/dist/chunk-XG23EUQX.cjs +0 -1717
  133. package/dist/chunk-XRKWN5PL.cjs +0 -173
  134. package/dist/chunk-XUILI4KB.cjs +0 -430
  135. package/dist/chunk-XUTX5CBW.js +0 -126
  136. package/dist/chunk-XWPNTWDN.cjs +0 -755
  137. package/dist/chunk-XXINBTZK.cjs +0 -633
  138. package/dist/chunk-YCXFCXDS.js +0 -1868
  139. package/dist/chunk-YQK5JNFK.js +0 -3725
  140. package/dist/chunk-YYXH45E2.js +0 -426
  141. package/dist/chunk-Z34RLXRA.cjs +0 -612
  142. package/dist/chunk-ZP4D3CSX.cjs +0 -72
  143. package/dist/cli/holoscript-runner.cjs +0 -2259
  144. package/dist/cli/holoscript-runner.js +0 -2234
  145. package/dist/codebase/index.cjs +0 -336
  146. package/dist/codebase/index.js +0 -331
  147. package/dist/compiler/agent-inference.cjs +0 -28
  148. package/dist/compiler/agent-inference.js +0 -5
  149. package/dist/compiler/android-xr.cjs +0 -19
  150. package/dist/compiler/android-xr.js +0 -9
  151. package/dist/compiler/android.cjs +0 -20
  152. package/dist/compiler/android.js +0 -10
  153. package/dist/compiler/ar.cjs +0 -20
  154. package/dist/compiler/ar.js +0 -8
  155. package/dist/compiler/babylon.cjs +0 -17
  156. package/dist/compiler/babylon.js +0 -11
  157. package/dist/compiler/coco.cjs +0 -27
  158. package/dist/compiler/coco.js +0 -4
  159. package/dist/compiler/domain-block-utils.cjs +0 -602
  160. package/dist/compiler/domain-block-utils.js +0 -8
  161. package/dist/compiler/dtdl.cjs +0 -24
  162. package/dist/compiler/dtdl.js +0 -8
  163. package/dist/compiler/gltf-pipeline.cjs +0 -39
  164. package/dist/compiler/gltf-pipeline.js +0 -4
  165. package/dist/compiler/godot.cjs +0 -15
  166. package/dist/compiler/godot.js +0 -9
  167. package/dist/compiler/incremental.cjs +0 -29
  168. package/dist/compiler/incremental.js +0 -4
  169. package/dist/compiler/index.cjs +0 -2578
  170. package/dist/compiler/index.js +0 -2383
  171. package/dist/compiler/ios.cjs +0 -20
  172. package/dist/compiler/ios.js +0 -10
  173. package/dist/compiler/multi-layer.cjs +0 -20
  174. package/dist/compiler/multi-layer.js +0 -11
  175. package/dist/compiler/nodetoy.cjs +0 -23
  176. package/dist/compiler/nodetoy.js +0 -4
  177. package/dist/compiler/openxr.cjs +0 -15
  178. package/dist/compiler/openxr.js +0 -9
  179. package/dist/compiler/playcanvas.cjs +0 -16
  180. package/dist/compiler/playcanvas.js +0 -10
  181. package/dist/compiler/r3f.cjs +0 -34
  182. package/dist/compiler/r3f.js +0 -12
  183. package/dist/compiler/remotion.cjs +0 -23
  184. package/dist/compiler/remotion.js +0 -4
  185. package/dist/compiler/reproducibility.cjs +0 -39
  186. package/dist/compiler/reproducibility.js +0 -4
  187. package/dist/compiler/sdf.cjs +0 -21
  188. package/dist/compiler/sdf.js +0 -9
  189. package/dist/compiler/semantic-scene.cjs +0 -31
  190. package/dist/compiler/semantic-scene.js +0 -4
  191. package/dist/compiler/state.cjs +0 -17
  192. package/dist/compiler/state.js +0 -7
  193. package/dist/compiler/trait-composition.cjs +0 -26
  194. package/dist/compiler/trait-composition.js +0 -5
  195. package/dist/compiler/unity.cjs +0 -15
  196. package/dist/compiler/unity.js +0 -9
  197. package/dist/compiler/unreal.cjs +0 -19
  198. package/dist/compiler/unreal.js +0 -9
  199. package/dist/compiler/urdf.cjs +0 -45
  200. package/dist/compiler/urdf.js +0 -9
  201. package/dist/compiler/usd-physics.cjs +0 -23
  202. package/dist/compiler/usd-physics.js +0 -6
  203. package/dist/compiler/visionos.cjs +0 -15
  204. package/dist/compiler/visionos.js +0 -9
  205. package/dist/compiler/vrchat.cjs +0 -19
  206. package/dist/compiler/vrchat.js +0 -9
  207. package/dist/compiler/vrr.cjs +0 -21
  208. package/dist/compiler/vrr.js +0 -9
  209. package/dist/compiler/wasm.cjs +0 -33
  210. package/dist/compiler/wasm.js +0 -9
  211. package/dist/compiler/webgpu.cjs +0 -15
  212. package/dist/compiler/webgpu.js +0 -9
  213. package/dist/debugger.cjs +0 -21
  214. package/dist/debugger.js +0 -8
  215. package/dist/entries/interop.cjs +0 -62
  216. package/dist/entries/interop.js +0 -5
  217. package/dist/entries/scripting.cjs +0 -68
  218. package/dist/entries/scripting.js +0 -11
  219. package/dist/index.cjs +0 -40921
  220. package/dist/index.js +0 -37763
  221. package/dist/math/vec3.cjs +0 -57
  222. package/dist/math/vec3.js +0 -4
  223. package/dist/ml-dsa-PHCWUBPX.cjs +0 -1178
  224. package/dist/ml-dsa-WYLJHJO6.js +0 -1178
  225. package/dist/parser.cjs +0 -27
  226. package/dist/parser.js +0 -10
  227. package/dist/playwright-5OSAPTNH.js +0 -98660
  228. package/dist/playwright-RL6GY4F7.cjs +0 -98673
  229. package/dist/runtime.cjs +0 -16
  230. package/dist/runtime.js +0 -7
  231. package/dist/storage/index.cjs +0 -37
  232. package/dist/storage/index.js +0 -4
  233. package/dist/traits/index.cjs +0 -14649
  234. package/dist/traits/index.js +0 -12243
  235. package/dist/type-checker.cjs +0 -18
  236. package/dist/type-checker.js +0 -5
@@ -1,663 +0,0 @@
1
- 'use strict';
2
-
3
- // src/storage/IPFSTypes.ts
4
- var IPFSUploadError = class extends Error {
5
- constructor(message, provider, originalError) {
6
- super(message);
7
- this.provider = provider;
8
- this.originalError = originalError;
9
- this.name = "IPFSUploadError";
10
- }
11
- };
12
- var IPFSPinError = class extends Error {
13
- constructor(message, cid, originalError) {
14
- super(message);
15
- this.cid = cid;
16
- this.originalError = originalError;
17
- this.name = "IPFSPinError";
18
- }
19
- };
20
- var FileSizeExceededError = class extends Error {
21
- constructor(fileSize, maxSize) {
22
- super(`File size ${fileSize} bytes exceeds maximum ${maxSize} bytes`);
23
- this.fileSize = fileSize;
24
- this.maxSize = maxSize;
25
- this.name = "FileSizeExceededError";
26
- }
27
- };
28
-
29
- // src/storage/IPFSProviders.ts
30
- var PinataProvider = class {
31
- constructor(apiKey, apiSecret) {
32
- this.baseUrl = "https://api.pinata.cloud";
33
- this.apiKey = apiKey;
34
- this.apiSecret = apiSecret || "";
35
- }
36
- async upload(files, options) {
37
- const formData = new FormData();
38
- for (const file of files) {
39
- const blob = new Blob([file.content]);
40
- formData.append("file", blob, file.path);
41
- }
42
- const metadata = {
43
- name: options.metadata?.name || options.name,
44
- keyvalues: options.metadata?.keyvalues || {}
45
- };
46
- formData.append("pinataMetadata", JSON.stringify(metadata));
47
- const pinataOptions = {
48
- cidVersion: 1
49
- };
50
- formData.append("pinataOptions", JSON.stringify(pinataOptions));
51
- const response = await fetch(`${this.baseUrl}/pinning/pinFileToIPFS`, {
52
- method: "POST",
53
- headers: {
54
- pinata_api_key: this.apiKey,
55
- pinata_secret_api_key: this.apiSecret
56
- },
57
- body: formData
58
- });
59
- if (!response.ok) {
60
- const error = await response.text();
61
- throw new Error(`Pinata upload failed: ${error}`);
62
- }
63
- const data = await response.json();
64
- return {
65
- cid: data.IpfsHash,
66
- size: data.PinSize
67
- };
68
- }
69
- async pin(cid, name) {
70
- const response = await fetch(`${this.baseUrl}/pinning/pinByHash`, {
71
- method: "POST",
72
- headers: {
73
- "Content-Type": "application/json",
74
- pinata_api_key: this.apiKey,
75
- pinata_secret_api_key: this.apiSecret
76
- },
77
- body: JSON.stringify({
78
- hashToPin: cid,
79
- pinataMetadata: {
80
- name: name || cid
81
- }
82
- })
83
- });
84
- if (!response.ok) {
85
- const error = await response.text();
86
- throw new Error(`Pinata pin failed: ${error}`);
87
- }
88
- }
89
- async unpin(cid) {
90
- const response = await fetch(`${this.baseUrl}/pinning/unpin/${cid}`, {
91
- method: "DELETE",
92
- headers: {
93
- pinata_api_key: this.apiKey,
94
- pinata_secret_api_key: this.apiSecret
95
- }
96
- });
97
- if (!response.ok) {
98
- const error = await response.text();
99
- throw new Error(`Pinata unpin failed: ${error}`);
100
- }
101
- }
102
- async getPinStatus(cid) {
103
- const response = await fetch(
104
- `${this.baseUrl}/data/pinList?hashContains=${cid}&status=pinned,pinning`,
105
- {
106
- headers: {
107
- pinata_api_key: this.apiKey,
108
- pinata_secret_api_key: this.apiSecret
109
- }
110
- }
111
- );
112
- if (!response.ok) {
113
- return "unpinned";
114
- }
115
- const data = await response.json();
116
- if (data.count === 0) {
117
- return "unpinned";
118
- }
119
- const pin = data.rows[0];
120
- return pin.status === "pinned" ? "pinned" : "pinning";
121
- }
122
- async listPins() {
123
- const response = await fetch(`${this.baseUrl}/data/pinList?status=pinned`, {
124
- headers: {
125
- pinata_api_key: this.apiKey,
126
- pinata_secret_api_key: this.apiSecret
127
- }
128
- });
129
- if (!response.ok) {
130
- throw new Error("Failed to list pins");
131
- }
132
- const data = await response.json();
133
- return data.rows.map((pin) => ({
134
- // @ts-expect-error
135
- cid: pin.ipfs_pin_hash,
136
- // @ts-expect-error
137
- name: pin.metadata?.name || pin.ipfs_pin_hash,
138
- // @ts-expect-error
139
- size: pin.size,
140
- // @ts-expect-error
141
- status: pin.status,
142
- // @ts-expect-error
143
- created: new Date(pin.date_pinned)
144
- }));
145
- }
146
- async verifyCID(cid) {
147
- try {
148
- const status = await this.getPinStatus(cid);
149
- return status === "pinned" || status === "pinning";
150
- } catch {
151
- return false;
152
- }
153
- }
154
- };
155
- var NFTStorageProvider = class {
156
- constructor(apiKey) {
157
- this.baseUrl = "https://api.nft.storage";
158
- this.apiKey = apiKey;
159
- }
160
- async upload(files, options) {
161
- const formData = new FormData();
162
- for (const file of files) {
163
- const blob = new Blob([file.content]);
164
- formData.append("file", blob, file.path);
165
- }
166
- const response = await fetch(`${this.baseUrl}/upload`, {
167
- method: "POST",
168
- headers: {
169
- Authorization: `Bearer ${this.apiKey}`
170
- },
171
- body: formData
172
- });
173
- if (!response.ok) {
174
- const error = await response.text();
175
- throw new Error(`NFT.Storage upload failed: ${error}`);
176
- }
177
- const data = await response.json();
178
- return {
179
- cid: data.value.cid,
180
- size: data.value.size
181
- };
182
- }
183
- async pin(cid, name) {
184
- }
185
- async unpin(cid) {
186
- const response = await fetch(`${this.baseUrl}/${cid}`, {
187
- method: "DELETE",
188
- headers: {
189
- Authorization: `Bearer ${this.apiKey}`
190
- }
191
- });
192
- if (!response.ok) {
193
- const error = await response.text();
194
- throw new Error(`NFT.Storage unpin failed: ${error}`);
195
- }
196
- }
197
- async getPinStatus(cid) {
198
- const response = await fetch(`${this.baseUrl}/${cid}`, {
199
- headers: {
200
- Authorization: `Bearer ${this.apiKey}`
201
- }
202
- });
203
- if (!response.ok) {
204
- return "unpinned";
205
- }
206
- const data = await response.json();
207
- return data.pin?.status === "pinned" ? "pinned" : "pinning";
208
- }
209
- async listPins() {
210
- const response = await fetch(`${this.baseUrl}`, {
211
- headers: {
212
- Authorization: `Bearer ${this.apiKey}`
213
- }
214
- });
215
- if (!response.ok) {
216
- throw new Error("Failed to list pins");
217
- }
218
- const data = await response.json();
219
- return data.value.map((item) => ({
220
- // @ts-expect-error
221
- cid: item.cid,
222
- // @ts-expect-error
223
- name: item.name || item.cid,
224
- // @ts-expect-error
225
- size: item.size,
226
- // @ts-expect-error
227
- status: item.pin?.status || "pinned",
228
- // @ts-expect-error
229
- created: new Date(item.created)
230
- }));
231
- }
232
- async verifyCID(cid) {
233
- try {
234
- const status = await this.getPinStatus(cid);
235
- return status === "pinned" || status === "pinning";
236
- } catch {
237
- return false;
238
- }
239
- }
240
- };
241
- var InfuraProvider = class {
242
- constructor(projectId, projectSecret) {
243
- this.baseUrl = "https://ipfs.infura.io:5001/api/v0";
244
- this.projectId = projectId;
245
- this.projectSecret = projectSecret || "";
246
- }
247
- getAuthHeader() {
248
- const auth = Buffer.from(`${this.projectId}:${this.projectSecret}`).toString("base64");
249
- return `Basic ${auth}`;
250
- }
251
- async upload(files, options) {
252
- const formData = new FormData();
253
- for (const file of files) {
254
- const blob = new Blob([file.content]);
255
- formData.append("file", blob, file.path);
256
- }
257
- const response = await fetch(`${this.baseUrl}/add?wrap-with-directory=true`, {
258
- method: "POST",
259
- headers: {
260
- Authorization: this.getAuthHeader()
261
- },
262
- body: formData
263
- });
264
- if (!response.ok) {
265
- const error = await response.text();
266
- throw new Error(`Infura upload failed: ${error}`);
267
- }
268
- const text = await response.text();
269
- const lines = text.trim().split("\n");
270
- const lastLine = JSON.parse(lines[lines.length - 1]);
271
- let totalSize = 0;
272
- for (const line of lines) {
273
- const data = JSON.parse(line);
274
- totalSize += data.Size || 0;
275
- }
276
- return {
277
- cid: lastLine.Hash,
278
- size: totalSize
279
- };
280
- }
281
- async pin(cid, name) {
282
- const response = await fetch(`${this.baseUrl}/pin/add?arg=${cid}`, {
283
- method: "POST",
284
- headers: {
285
- Authorization: this.getAuthHeader()
286
- }
287
- });
288
- if (!response.ok) {
289
- const error = await response.text();
290
- throw new Error(`Infura pin failed: ${error}`);
291
- }
292
- }
293
- async unpin(cid) {
294
- const response = await fetch(`${this.baseUrl}/pin/rm?arg=${cid}`, {
295
- method: "POST",
296
- headers: {
297
- Authorization: this.getAuthHeader()
298
- }
299
- });
300
- if (!response.ok) {
301
- const error = await response.text();
302
- throw new Error(`Infura unpin failed: ${error}`);
303
- }
304
- }
305
- async getPinStatus(cid) {
306
- const response = await fetch(`${this.baseUrl}/pin/ls?arg=${cid}`, {
307
- headers: {
308
- Authorization: this.getAuthHeader()
309
- }
310
- });
311
- if (!response.ok) {
312
- return "unpinned";
313
- }
314
- const data = await response.json();
315
- return data.Keys && data.Keys[cid] ? "pinned" : "unpinned";
316
- }
317
- async listPins() {
318
- const response = await fetch(`${this.baseUrl}/pin/ls`, {
319
- headers: {
320
- Authorization: this.getAuthHeader()
321
- }
322
- });
323
- if (!response.ok) {
324
- throw new Error("Failed to list pins");
325
- }
326
- const data = await response.json();
327
- return Object.entries(data.Keys || {}).map(([cid, info]) => ({
328
- cid,
329
- name: cid,
330
- size: 0,
331
- // Infura doesn't provide size in pin list
332
- status: "pinned"
333
- }));
334
- }
335
- async verifyCID(cid) {
336
- try {
337
- const response = await fetch(`${this.baseUrl}/cat?arg=${cid}`, {
338
- method: "POST",
339
- headers: {
340
- Authorization: this.getAuthHeader()
341
- }
342
- });
343
- return response.ok;
344
- } catch {
345
- return false;
346
- }
347
- }
348
- };
349
-
350
- // src/storage/IPFSService.ts
351
- var IPFSService = class {
352
- constructor(options) {
353
- this.fallbackProviders = [];
354
- this.defaultGateway = "https://ipfs.io/ipfs";
355
- this.cdnGateway = "https://cloudflare-ipfs.com/ipfs";
356
- this.options = {
357
- ...options,
358
- fallbackProviders: options.fallbackProviders || [],
359
- enableCDN: options.enableCDN ?? true,
360
- maxFileSize: options.maxFileSize || 100 * 1024 * 1024,
361
- // 100MB
362
- chunkSize: options.chunkSize || 5 * 1024 * 1024,
363
- // 5MB
364
- maxRetries: options.maxRetries || 3,
365
- retryDelay: options.retryDelay || 1e3,
366
- gatewayUrl: options.gatewayUrl || this.defaultGateway,
367
- apiSecret: options.apiSecret
368
- };
369
- this.primaryProvider = this.createProvider(
370
- this.options.provider,
371
- this.options.apiKey,
372
- this.options.apiSecret
373
- );
374
- for (const fallback of this.options.fallbackProviders) {
375
- const provider = this.createProvider(fallback.provider, fallback.apiKey, fallback.apiSecret);
376
- this.fallbackProviders.push(provider);
377
- }
378
- }
379
- /**
380
- * Create provider instance
381
- */
382
- createProvider(type, apiKey, apiSecret) {
383
- switch (type) {
384
- case "pinata":
385
- return new PinataProvider(apiKey, apiSecret);
386
- case "nft.storage":
387
- return new NFTStorageProvider(apiKey);
388
- case "infura":
389
- return new InfuraProvider(apiKey, apiSecret);
390
- default:
391
- throw new Error(`Unknown IPFS provider: ${type}`);
392
- }
393
- }
394
- /**
395
- * Upload files to IPFS
396
- *
397
- * Returns CID and gateway URLs. Automatically retries on failure and falls back
398
- * to backup providers if primary fails.
399
- *
400
- * @param options Upload options
401
- * @returns Upload result with CID and URLs
402
- * @throws {FileSizeExceededError} If file size exceeds maximum
403
- * @throws {IPFSUploadError} If upload fails on all providers
404
- */
405
- async upload(options) {
406
- const startTime = Date.now();
407
- const totalSize = options.files.reduce((sum, file) => {
408
- const size = file.content instanceof Buffer || file.content instanceof Uint8Array ? file.content.length : Buffer.from(file.content).length;
409
- return sum + size;
410
- }, 0);
411
- if (totalSize > this.options.maxFileSize) {
412
- throw new FileSizeExceededError(totalSize, this.options.maxFileSize);
413
- }
414
- const needsChunking = totalSize > this.options.chunkSize;
415
- try {
416
- const result = await this.uploadWithRetry(
417
- this.primaryProvider,
418
- this.options.provider,
419
- options,
420
- needsChunking
421
- );
422
- return this.buildUploadResult(result.cid, result.size, startTime, options.pin ?? true);
423
- } catch (primaryError) {
424
- console.warn(`Primary provider ${this.options.provider} failed:`, primaryError);
425
- for (let i = 0; i < this.fallbackProviders.length; i++) {
426
- const provider = this.fallbackProviders[i];
427
- const providerType = this.options.fallbackProviders[i].provider;
428
- try {
429
- const result = await this.uploadWithRetry(provider, providerType, options, needsChunking);
430
- return this.buildUploadResult(result.cid, result.size, startTime, options.pin ?? true);
431
- } catch (error) {
432
- console.warn(`Fallback provider ${providerType} failed:`, error);
433
- continue;
434
- }
435
- }
436
- throw new IPFSUploadError(
437
- "Upload failed on all providers",
438
- this.options.provider,
439
- primaryError
440
- );
441
- }
442
- }
443
- /**
444
- * Upload with retry logic
445
- */
446
- async uploadWithRetry(provider, providerType, options, needsChunking) {
447
- let lastError;
448
- for (let attempt = 0; attempt < this.options.maxRetries; attempt++) {
449
- try {
450
- if (needsChunking) {
451
- return await this.uploadChunked(provider, options);
452
- } else {
453
- if (options.onProgress) {
454
- const totalSize = options.files.reduce((sum, file) => {
455
- const size = file.content instanceof Buffer || file.content instanceof Uint8Array ? file.content.length : Buffer.from(file.content).length;
456
- return sum + size;
457
- }, 0);
458
- let uploadedBytes = 0;
459
- for (const file of options.files) {
460
- const size = file.content instanceof Buffer || file.content instanceof Uint8Array ? file.content.length : Buffer.from(file.content).length;
461
- uploadedBytes += size;
462
- options.onProgress({
463
- uploadedBytes,
464
- totalBytes: totalSize,
465
- percentage: uploadedBytes / totalSize * 100,
466
- currentFile: file.path
467
- });
468
- }
469
- }
470
- return await provider.upload(options.files, options);
471
- }
472
- } catch (error) {
473
- lastError = error;
474
- if (attempt < this.options.maxRetries - 1) {
475
- const delay = this.options.retryDelay * Math.pow(2, attempt);
476
- await this.delay(delay);
477
- }
478
- }
479
- }
480
- throw new IPFSUploadError(
481
- `Upload failed after ${this.options.maxRetries} attempts`,
482
- providerType,
483
- lastError
484
- );
485
- }
486
- /**
487
- * Upload large files in chunks
488
- *
489
- * Breaks large files into smaller chunks, uploads them separately,
490
- * and combines them into a single IPFS directory.
491
- */
492
- async uploadChunked(provider, options) {
493
- const chunks = [];
494
- let totalSize = 0;
495
- let uploadedBytes = 0;
496
- for (const file of options.files) {
497
- const content = file.content instanceof Buffer || file.content instanceof Uint8Array ? file.content : Buffer.from(file.content);
498
- const fileSize = content.length;
499
- totalSize += fileSize;
500
- if (fileSize > this.options.chunkSize) {
501
- const numChunks = Math.ceil(fileSize / this.options.chunkSize);
502
- for (let i = 0; i < numChunks; i++) {
503
- const start = i * this.options.chunkSize;
504
- const end = Math.min(start + this.options.chunkSize, fileSize);
505
- const chunk = content.slice(start, end);
506
- chunks.push({
507
- path: `${file.path}.chunk${i}`,
508
- content: chunk
509
- });
510
- uploadedBytes += chunk.length;
511
- if (options.onProgress) {
512
- options.onProgress({
513
- uploadedBytes,
514
- totalBytes: totalSize,
515
- percentage: uploadedBytes / totalSize * 100,
516
- currentFile: file.path
517
- });
518
- }
519
- }
520
- } else {
521
- chunks.push(file);
522
- uploadedBytes += fileSize;
523
- if (options.onProgress) {
524
- options.onProgress({
525
- uploadedBytes,
526
- totalBytes: totalSize,
527
- percentage: uploadedBytes / totalSize * 100,
528
- currentFile: file.path
529
- });
530
- }
531
- }
532
- }
533
- return await provider.upload(chunks, options);
534
- }
535
- /**
536
- * Build upload result
537
- */
538
- buildUploadResult(cid, size, startTime, pinned) {
539
- const gatewayUrl = `${this.options.gatewayUrl}/${cid}`;
540
- const cdnUrl = this.options.enableCDN ? `${this.cdnGateway}/${cid}` : void 0;
541
- return {
542
- cid,
543
- uri: `ipfs://${cid}`,
544
- gatewayUrl,
545
- cdnUrl,
546
- pinned,
547
- size,
548
- duration: Date.now() - startTime
549
- };
550
- }
551
- /**
552
- * Pin existing CID to IPFS
553
- *
554
- * @param cid IPFS CID to pin
555
- * @param name Optional name for the pin
556
- * @throws {IPFSPinError} If pin operation fails
557
- */
558
- async pin(cid, name) {
559
- try {
560
- await this.primaryProvider.pin(cid, name);
561
- } catch (error) {
562
- throw new IPFSPinError(`Failed to pin CID ${cid}`, cid, error);
563
- }
564
- }
565
- /**
566
- * Unpin CID from IPFS
567
- *
568
- * @param cid IPFS CID to unpin
569
- * @throws {IPFSPinError} If unpin operation fails
570
- */
571
- async unpin(cid) {
572
- try {
573
- await this.primaryProvider.unpin(cid);
574
- } catch (error) {
575
- throw new IPFSPinError(`Failed to unpin CID ${cid}`, cid, error);
576
- }
577
- }
578
- /**
579
- * Get pin status for CID
580
- *
581
- * @param cid IPFS CID to check
582
- * @returns Pin status ('pinned', 'pinning', or 'unpinned')
583
- */
584
- async getPinStatus(cid) {
585
- return await this.primaryProvider.getPinStatus(cid);
586
- }
587
- /**
588
- * Verify CID exists and is accessible
589
- *
590
- * @param cid IPFS CID to verify
591
- * @returns True if CID is accessible
592
- */
593
- async verifyCID(cid) {
594
- return await this.primaryProvider.verifyCID(cid);
595
- }
596
- /**
597
- * Get file from IPFS
598
- *
599
- * @param cid IPFS CID
600
- * @param path Optional path within directory
601
- * @returns File content as Uint8Array
602
- */
603
- async get(cid, path) {
604
- const url = path ? `${this.options.gatewayUrl}/${cid}/${path}` : `${this.options.gatewayUrl}/${cid}`;
605
- const response = await fetch(url);
606
- if (!response.ok) {
607
- throw new Error(`Failed to fetch CID ${cid}: ${response.statusText}`);
608
- }
609
- const buffer = await response.arrayBuffer();
610
- return new Uint8Array(buffer);
611
- }
612
- /**
613
- * List all pins for account
614
- *
615
- * @returns Array of pin information
616
- */
617
- async listPins() {
618
- return await this.primaryProvider.listPins();
619
- }
620
- /**
621
- * Delay helper for retry logic
622
- */
623
- delay(ms) {
624
- return new Promise((resolve) => setTimeout(resolve, ms));
625
- }
626
- /**
627
- * Get CDN URL for CID
628
- *
629
- * @param cid IPFS CID
630
- * @returns CDN URL if enabled, otherwise gateway URL
631
- */
632
- getCDNUrl(cid) {
633
- return this.options.enableCDN ? `${this.cdnGateway}/${cid}` : `${this.options.gatewayUrl}/${cid}`;
634
- }
635
- /**
636
- * Get gateway URL for CID
637
- *
638
- * @param cid IPFS CID
639
- * @returns Gateway URL
640
- */
641
- getGatewayUrl(cid) {
642
- return `${this.options.gatewayUrl}/${cid}`;
643
- }
644
- /**
645
- * Get IPFS URI for CID
646
- *
647
- * @param cid IPFS CID
648
- * @returns IPFS URI (ipfs://...)
649
- */
650
- getIPFSUri(cid) {
651
- return `ipfs://${cid}`;
652
- }
653
- };
654
-
655
- exports.FileSizeExceededError = FileSizeExceededError;
656
- exports.IPFSPinError = IPFSPinError;
657
- exports.IPFSService = IPFSService;
658
- exports.IPFSUploadError = IPFSUploadError;
659
- exports.InfuraProvider = InfuraProvider;
660
- exports.NFTStorageProvider = NFTStorageProvider;
661
- exports.PinataProvider = PinataProvider;
662
- //# sourceMappingURL=chunk-7LCYLPW2.cjs.map
663
- //# sourceMappingURL=chunk-7LCYLPW2.cjs.map