@solana-mobile/dapp-store-cli 0.15.0 → 0.16.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.
package/lib/CliUtils.js CHANGED
@@ -156,7 +156,7 @@ export var Constants = function Constants() {
156
156
  "use strict";
157
157
  _class_call_check(this, Constants);
158
158
  };
159
- _define_property(Constants, "CLI_VERSION", "0.15.0");
159
+ _define_property(Constants, "CLI_VERSION", "0.16.0");
160
160
  _define_property(Constants, "CONFIG_FILE_NAME", "config.yaml");
161
161
  _define_property(Constants, "DEFAULT_RPC_DEVNET", "https://api.devnet.solana.com");
162
162
  _define_property(Constants, "DEFAULT_PRIORITY_FEE", 500000);
package/lib/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solana-mobile/dapp-store-cli",
3
- "version": "0.15.0",
3
+ "version": "0.16.0",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -51,10 +51,10 @@
51
51
  "ts-node": "^10.9.1"
52
52
  },
53
53
  "dependencies": {
54
- "@ardrive/turbo-sdk": "^1.31.1",
54
+ "@ardrive/turbo-sdk": "^1.41.0",
55
55
  "@aws-sdk/client-s3": "^3.321.1",
56
56
  "@metaplex-foundation/js-plugin-aws": "^0.20.0",
57
- "@solana-mobile/dapp-store-publishing-tools": "workspace:0.15.0",
57
+ "@solana-mobile/dapp-store-publishing-tools": "workspace:0.16.0",
58
58
  "@solana/web3.js": "1.92.1",
59
59
  "@types/semver": "^7.3.13",
60
60
  "ajv": "^8.11.0",
@@ -1,3 +1,11 @@
1
+ function _array_like_to_array(arr, len) {
2
+ if (len == null || len > arr.length) len = arr.length;
3
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
+ return arr2;
5
+ }
6
+ function _array_with_holes(arr) {
7
+ if (Array.isArray(arr)) return arr;
8
+ }
1
9
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
10
  try {
3
11
  var info = gen[key](arg);
@@ -59,20 +67,54 @@ function _define_property(obj, key, value) {
59
67
  }
60
68
  return obj;
61
69
  }
62
- function _object_spread(target) {
63
- for(var i = 1; i < arguments.length; i++){
64
- var source = arguments[i] != null ? arguments[i] : {};
65
- var ownKeys = Object.keys(source);
66
- if (typeof Object.getOwnPropertySymbols === "function") {
67
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
68
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
69
- }));
70
+ function _instanceof(left, right) {
71
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
72
+ return !!right[Symbol.hasInstance](left);
73
+ } else {
74
+ return left instanceof right;
75
+ }
76
+ }
77
+ function _iterable_to_array_limit(arr, i) {
78
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
79
+ if (_i == null) return;
80
+ var _arr = [];
81
+ var _n = true;
82
+ var _d = false;
83
+ var _s, _e;
84
+ try {
85
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
86
+ _arr.push(_s.value);
87
+ if (i && _arr.length === i) break;
88
+ }
89
+ } catch (err) {
90
+ _d = true;
91
+ _e = err;
92
+ } finally{
93
+ try {
94
+ if (!_n && _i["return"] != null) _i["return"]();
95
+ } finally{
96
+ if (_d) throw _e;
70
97
  }
71
- ownKeys.forEach(function(key) {
72
- _define_property(target, key, source[key]);
73
- });
74
98
  }
75
- return target;
99
+ return _arr;
100
+ }
101
+ function _non_iterable_rest() {
102
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
103
+ }
104
+ function _sliced_to_array(arr, i) {
105
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
106
+ }
107
+ function _type_of(obj) {
108
+ "@swc/helpers - typeof";
109
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
110
+ }
111
+ function _unsupported_iterable_to_array(o, minLen) {
112
+ if (!o) return;
113
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
114
+ var n = Object.prototype.toString.call(o).slice(8, -1);
115
+ if (n === "Object" && o.constructor) n = o.constructor.name;
116
+ if (n === "Map" || n === "Set") return Array.from(n);
117
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
76
118
  }
77
119
  function _ts_generator(thisArg, body) {
78
120
  var f, y, t, _ = {
@@ -168,6 +210,7 @@ function _ts_generator(thisArg, body) {
168
210
  import fs from "fs";
169
211
  import path from "path";
170
212
  import { createHash } from "crypto";
213
+ import { normalizePublicContentUrl } from "./contentGateway.js";
171
214
  // TODO(jon): We need to manage the removal / replacement of assets in the manifest
172
215
  export var CachedStorageDriver = /*#__PURE__*/ function() {
173
216
  "use strict";
@@ -199,11 +242,96 @@ export var CachedStorageDriver = /*#__PURE__*/ function() {
199
242
  }).call(this);
200
243
  }
201
244
  },
245
+ {
246
+ key: "resolveAssetManifestPath",
247
+ value: function resolveAssetManifestPath() {
248
+ var filename = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : this.assetManifestPath;
249
+ return path.resolve(process.cwd(), filename);
250
+ }
251
+ },
252
+ {
253
+ key: "normalizeAsset",
254
+ value: function normalizeAsset(filename, asset) {
255
+ if (!asset || (typeof asset === "undefined" ? "undefined" : _type_of(asset)) !== "object") return;
256
+ var candidate = asset;
257
+ var pathValue = typeof candidate.path === "string" ? candidate.path : filename;
258
+ if (typeof candidate.sha256 !== "string" || typeof candidate.uri !== "string") {
259
+ return;
260
+ }
261
+ return {
262
+ path: pathValue,
263
+ sha256: candidate.sha256,
264
+ uri: candidate.uri
265
+ };
266
+ }
267
+ },
268
+ {
269
+ key: "normalizeAssetManifest",
270
+ value: function normalizeAssetManifest(assetManifest) {
271
+ if (!assetManifest || (typeof assetManifest === "undefined" ? "undefined" : _type_of(assetManifest)) !== "object") return;
272
+ var assets = {};
273
+ var assetEntries = assetManifest.assets && _type_of(assetManifest.assets) === "object" ? Object.entries(assetManifest.assets) : [];
274
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
275
+ try {
276
+ for(var _iterator = assetEntries[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
277
+ var _step_value = _sliced_to_array(_step.value, 2), filename = _step_value[0], asset = _step_value[1];
278
+ var normalizedAsset = this.normalizeAsset(filename, asset);
279
+ if (normalizedAsset) {
280
+ assets[filename] = normalizedAsset;
281
+ }
282
+ }
283
+ } catch (err) {
284
+ _didIteratorError = true;
285
+ _iteratorError = err;
286
+ } finally{
287
+ try {
288
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
289
+ _iterator.return();
290
+ }
291
+ } finally{
292
+ if (_didIteratorError) {
293
+ throw _iteratorError;
294
+ }
295
+ }
296
+ }
297
+ return {
298
+ schema_version: typeof assetManifest.schema_version === "string" ? assetManifest.schema_version : CachedStorageDriver.SCHEMA_VERSION,
299
+ assets: assets
300
+ };
301
+ }
302
+ },
303
+ {
304
+ key: "writeAssetManifest",
305
+ value: function writeAssetManifest() {
306
+ return _async_to_generator(function() {
307
+ var normalizedAssetManifest;
308
+ return _ts_generator(this, function(_state) {
309
+ switch(_state.label){
310
+ case 0:
311
+ normalizedAssetManifest = this.normalizeAssetManifest(this.assetManifest);
312
+ if (!normalizedAssetManifest) {
313
+ throw new Error("Asset manifest is not serializable");
314
+ }
315
+ this.assetManifest = normalizedAssetManifest;
316
+ return [
317
+ 4,
318
+ fs.promises.writeFile(this.resolveAssetManifestPath(), JSON.stringify(this.assetManifest, null, 2), "utf-8")
319
+ ];
320
+ case 1:
321
+ _state.sent();
322
+ return [
323
+ 2
324
+ ];
325
+ }
326
+ });
327
+ }).call(this);
328
+ }
329
+ },
202
330
  {
203
331
  key: "loadAssetManifest",
204
332
  value: function loadAssetManifest(filename) {
205
333
  try {
206
- return JSON.parse(fs.readFileSync(filename, "utf-8"));
334
+ return this.normalizeAssetManifest(JSON.parse(fs.readFileSync(this.resolveAssetManifestPath(filename), "utf-8")));
207
335
  } catch (error) {
208
336
  console.warn("Failed opening ".concat(filename, "; initializing with a blank asset manifest"));
209
337
  return;
@@ -225,7 +353,7 @@ export var CachedStorageDriver = /*#__PURE__*/ function() {
225
353
  key: "upload",
226
354
  value: function upload(file) {
227
355
  return _async_to_generator(function() {
228
- var hash, uploadedAsset, uri;
356
+ var hash, uploadedAsset, normalizedUri, error, message, uri;
229
357
  return _ts_generator(this, function(_state) {
230
358
  switch(_state.label){
231
359
  case 0:
@@ -240,27 +368,67 @@ export var CachedStorageDriver = /*#__PURE__*/ function() {
240
368
  case 1:
241
369
  return [
242
370
  2,
243
- _state.sent()
371
+ normalizePublicContentUrl.apply(void 0, [
372
+ _state.sent()
373
+ ])
244
374
  ];
245
375
  case 2:
246
376
  hash = createHash("sha256").update(file.buffer).digest("base64");
247
377
  uploadedAsset = this.uploadedAsset(file.fileName, {
248
378
  sha256: hash
249
379
  });
250
- if (uploadedAsset) {
251
- console.log("Asset ".concat(file.fileName, " already uploaded at ").concat(uploadedAsset.uri));
252
- return [
253
- 2,
254
- uploadedAsset.uri
255
- ];
256
- }
380
+ if (!uploadedAsset) return [
381
+ 3,
382
+ 7
383
+ ];
384
+ normalizedUri = normalizePublicContentUrl(uploadedAsset.uri);
385
+ if (!(normalizedUri !== uploadedAsset.uri)) return [
386
+ 3,
387
+ 6
388
+ ];
389
+ uploadedAsset.uri = normalizedUri;
390
+ _state.label = 3;
391
+ case 3:
392
+ _state.trys.push([
393
+ 3,
394
+ 5,
395
+ ,
396
+ 6
397
+ ]);
398
+ return [
399
+ 4,
400
+ this.writeAssetManifest()
401
+ ];
402
+ case 4:
403
+ _state.sent();
404
+ return [
405
+ 3,
406
+ 6
407
+ ];
408
+ case 5:
409
+ error = _state.sent();
410
+ message = _instanceof(error, Error) ? error.message : String(error);
411
+ console.warn("Failed to rewrite ".concat(this.assetManifestPath, "; continuing with normalized URL: ").concat(message));
412
+ return [
413
+ 3,
414
+ 6
415
+ ];
416
+ case 6:
417
+ console.log("Asset ".concat(file.fileName, " already uploaded at ").concat(normalizedUri));
418
+ return [
419
+ 2,
420
+ normalizedUri
421
+ ];
422
+ case 7:
257
423
  console.log("Uploading ".concat(file.fileName));
258
424
  return [
259
425
  4,
260
426
  this.storageDriver.upload(file)
261
427
  ];
262
- case 3:
263
- uri = _state.sent();
428
+ case 8:
429
+ uri = normalizePublicContentUrl.apply(void 0, [
430
+ _state.sent()
431
+ ]);
264
432
  this.assetManifest.assets[file.fileName] = {
265
433
  path: file.fileName,
266
434
  sha256: hash,
@@ -268,12 +436,9 @@ export var CachedStorageDriver = /*#__PURE__*/ function() {
268
436
  };
269
437
  return [
270
438
  4,
271
- fs.promises.writeFile(path.join(process.cwd(), this.assetManifestPath), // Something is really weird, I can't seem to stringify `this.assetManifest` straight-up. Here be dragons
272
- JSON.stringify({
273
- assets: _object_spread({}, this.assetManifest.assets)
274
- }, null, 2), "utf-8")
439
+ this.writeAssetManifest()
275
440
  ];
276
- case 4:
441
+ case 9:
277
442
  _state.sent();
278
443
  console.log("".concat(file.fileName, " uploaded at ").concat(uri));
279
444
  return [
@@ -247,6 +247,7 @@ function _ts_values(o) {
247
247
  import { TurboFactory, lamportToTokenAmount } from "@ardrive/turbo-sdk";
248
248
  import bs58 from "bs58";
249
249
  import debugModule from "debug";
250
+ import { buildPublicContentUrl } from "./contentGateway.js";
250
251
  var debug = debugModule("cli:turbo-storage");
251
252
  var SOL_IN_LAMPORTS = 1000000000;
252
253
  var MIN_TOP_UP_LAMPORTS = 1000000;
@@ -262,9 +263,16 @@ var CONSTANTS = {
262
263
  BASE_MS: 500,
263
264
  MAX_MS: 8000
264
265
  },
265
- GATEWAYS: {
266
- devnet: "https://turbo.ardrive.dev/raw",
267
- mainnet: "https://arweave.net"
266
+ SERVICE_URLS: {
267
+ devnet: {
268
+ gatewayUrl: "https://api.devnet.solana.com",
269
+ uploadServiceConfig: {
270
+ url: "https://upload.ardrive.dev"
271
+ },
272
+ paymentServiceConfig: {
273
+ url: "https://payment.ardrive.dev"
274
+ }
275
+ }
268
276
  }
269
277
  };
270
278
  var delay = function(ms) {
@@ -287,19 +295,9 @@ export var TurboStorageDriver = /*#__PURE__*/ function() {
287
295
  this.turbo = TurboFactory.authenticated(_object_spread({
288
296
  privateKey: bs58.encode(keypair.secretKey),
289
297
  token: "solana"
290
- }, this.getServiceUrls(network === "devnet")));
298
+ }, getTurboServiceConfig(network)));
291
299
  }
292
300
  _create_class(TurboStorageDriver, [
293
- {
294
- key: "getServiceUrls",
295
- value: function getServiceUrls(isDev) {
296
- var base = isDev ? "ardrive.dev" : "ardrive.io";
297
- return {
298
- uploadUrl: "https://upload.".concat(base),
299
- paymentUrl: "https://payment.".concat(base)
300
- };
301
- }
302
- },
303
301
  {
304
302
  key: "getUploadPrice",
305
303
  value: function getUploadPrice(bytes) {
@@ -571,7 +569,7 @@ export var TurboStorageDriver = /*#__PURE__*/ function() {
571
569
  switch(_state.label){
572
570
  case 0:
573
571
  _loop = function() {
574
- var item, estimated, _item_file_tags, tags, uploadResult, gateway, url, error;
572
+ var item, estimated, _item_file_tags, tags, uploadResult, url, error;
575
573
  return _ts_generator(this, function(_state) {
576
574
  switch(_state.label){
577
575
  case 0:
@@ -624,8 +622,7 @@ export var TurboStorageDriver = /*#__PURE__*/ function() {
624
622
  ];
625
623
  case 4:
626
624
  uploadResult = _state.sent();
627
- gateway = CONSTANTS.GATEWAYS[_this.network];
628
- url = "".concat(gateway, "/").concat(uploadResult.id);
625
+ url = buildPublicContentUrl(uploadResult.id, _this.network);
629
626
  debug("Upload complete: ".concat(url));
630
627
  item.resolve(url);
631
628
  if (!(_this.uploadQueue.length > 0)) return [
@@ -716,3 +713,6 @@ export var TurboStorageDriver = /*#__PURE__*/ function() {
716
713
  ]);
717
714
  return TurboStorageDriver;
718
715
  }();
716
+ export var getTurboServiceConfig = function(network) {
717
+ return network === "devnet" ? CONSTANTS.SERVICE_URLS.devnet : {};
718
+ };