@solana-mobile/dapp-store-cli 0.16.0 → 1.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 (113) hide show
  1. package/bin/dapp-store.js +3 -1
  2. package/lib/CliSetup.js +304 -505
  3. package/lib/CliUtils.js +6 -376
  4. package/lib/__tests__/CliSetupTest.js +484 -74
  5. package/lib/cli/__tests__/parseErrors.test.js +25 -0
  6. package/lib/cli/__tests__/signer.test.js +436 -0
  7. package/lib/cli/constants.js +23 -0
  8. package/lib/cli/messages.js +21 -0
  9. package/lib/cli/parseErrors.js +41 -0
  10. package/lib/{commands/publish/PublishCliSupport.js → cli/selfUpdate.js} +72 -38
  11. package/lib/{commands/publish/PublishCliRemove.js → cli/signer.js} +35 -56
  12. package/lib/index.js +96 -5
  13. package/lib/package.json +5 -24
  14. package/lib/portal/__tests__/releaseMetadata.test.js +647 -0
  15. package/lib/portal/__tests__/translators.test.js +76 -0
  16. package/lib/portal/__tests__/workflowClient.test.js +457 -0
  17. package/lib/portal/attestationClient.js +143 -0
  18. package/lib/portal/files.js +64 -0
  19. package/lib/portal/http.js +364 -0
  20. package/lib/portal/records.js +64 -0
  21. package/lib/portal/releaseMetadata.js +748 -0
  22. package/lib/portal/translators.js +460 -0
  23. package/lib/portal/types.js +1 -0
  24. package/lib/portal/workflowClient.js +704 -0
  25. package/lib/publication/PublicationProgressReporter.js +1051 -0
  26. package/lib/publication/__tests__/PublicationProgressReporter.test.js +174 -0
  27. package/lib/{commands/ValidateCommand.js → publication/__tests__/fundingPreflight.test.js} +90 -66
  28. package/lib/publication/__tests__/publicationSummary.test.js +26 -0
  29. package/lib/publication/cliValidation.js +482 -0
  30. package/lib/publication/fundingPreflight.js +246 -0
  31. package/lib/publication/publicationSummary.js +99 -0
  32. package/lib/{commands/utils.js → publication/runPublicationWorkflow.js} +16 -46
  33. package/package.json +5 -24
  34. package/src/CliSetup.ts +370 -505
  35. package/src/CliUtils.ts +9 -233
  36. package/src/__tests__/CliSetupTest.ts +272 -120
  37. package/src/cli/__tests__/parseErrors.test.ts +34 -0
  38. package/src/cli/__tests__/signer.test.ts +359 -0
  39. package/src/cli/constants.ts +3 -0
  40. package/src/cli/messages.ts +27 -0
  41. package/src/cli/parseErrors.ts +62 -0
  42. package/src/cli/selfUpdate.ts +59 -0
  43. package/src/cli/signer.ts +38 -0
  44. package/src/index.ts +31 -4
  45. package/src/portal/__tests__/releaseMetadata.test.ts +508 -0
  46. package/src/portal/__tests__/translators.test.ts +82 -0
  47. package/src/portal/__tests__/workflowClient.test.ts +278 -0
  48. package/src/portal/attestationClient.ts +19 -0
  49. package/src/portal/files.ts +73 -0
  50. package/src/portal/http.ts +170 -0
  51. package/src/portal/records.ts +38 -0
  52. package/src/portal/releaseMetadata.ts +489 -0
  53. package/src/portal/translators.ts +750 -0
  54. package/src/portal/types.ts +27 -0
  55. package/src/portal/workflowClient.ts +575 -0
  56. package/src/publication/PublicationProgressReporter.ts +1026 -0
  57. package/src/publication/__tests__/PublicationProgressReporter.test.ts +210 -0
  58. package/src/publication/__tests__/fundingPreflight.test.ts +78 -0
  59. package/src/publication/__tests__/publicationSummary.test.ts +30 -0
  60. package/src/publication/cliValidation.ts +264 -0
  61. package/src/publication/fundingPreflight.ts +123 -0
  62. package/src/publication/publicationSummary.ts +26 -0
  63. package/src/publication/runPublicationWorkflow.ts +46 -0
  64. package/lib/commands/create/CreateCliApp.js +0 -223
  65. package/lib/commands/create/CreateCliRelease.js +0 -290
  66. package/lib/commands/create/index.js +0 -40
  67. package/lib/commands/index.js +0 -3
  68. package/lib/commands/publish/PublishCliSubmit.js +0 -208
  69. package/lib/commands/publish/PublishCliUpdate.js +0 -211
  70. package/lib/commands/publish/index.js +0 -22
  71. package/lib/commands/scaffolding/ScaffoldInit.js +0 -15
  72. package/lib/commands/scaffolding/index.js +0 -1
  73. package/lib/config/EnvVariables.js +0 -59
  74. package/lib/config/PublishDetails.js +0 -915
  75. package/lib/config/S3StorageManager.js +0 -93
  76. package/lib/config/index.js +0 -2
  77. package/lib/generated/config_obj.json +0 -1
  78. package/lib/generated/config_schema.json +0 -1
  79. package/lib/prebuild_schema/publishing_source.yaml +0 -64
  80. package/lib/prebuild_schema/schemagen.js +0 -25
  81. package/lib/upload/CachedStorageDriver.js +0 -458
  82. package/lib/upload/TurboStorageDriver.js +0 -718
  83. package/lib/upload/__tests__/CachedStorageDriver.test.js +0 -437
  84. package/lib/upload/__tests__/TurboStorageDriver.test.js +0 -17
  85. package/lib/upload/__tests__/contentGateway.test.js +0 -17
  86. package/lib/upload/contentGateway.js +0 -23
  87. package/lib/upload/index.js +0 -2
  88. package/src/commands/ValidateCommand.ts +0 -82
  89. package/src/commands/create/CreateCliApp.ts +0 -93
  90. package/src/commands/create/CreateCliRelease.ts +0 -149
  91. package/src/commands/create/index.ts +0 -47
  92. package/src/commands/index.ts +0 -3
  93. package/src/commands/publish/PublishCliRemove.ts +0 -66
  94. package/src/commands/publish/PublishCliSubmit.ts +0 -93
  95. package/src/commands/publish/PublishCliSupport.ts +0 -66
  96. package/src/commands/publish/PublishCliUpdate.ts +0 -101
  97. package/src/commands/publish/index.ts +0 -29
  98. package/src/commands/scaffolding/ScaffoldInit.ts +0 -20
  99. package/src/commands/scaffolding/index.ts +0 -1
  100. package/src/commands/utils.ts +0 -33
  101. package/src/config/EnvVariables.ts +0 -39
  102. package/src/config/PublishDetails.ts +0 -456
  103. package/src/config/S3StorageManager.ts +0 -47
  104. package/src/config/index.ts +0 -2
  105. package/src/prebuild_schema/publishing_source.yaml +0 -64
  106. package/src/prebuild_schema/schemagen.js +0 -31
  107. package/src/upload/CachedStorageDriver.ts +0 -179
  108. package/src/upload/TurboStorageDriver.ts +0 -283
  109. package/src/upload/__tests__/CachedStorageDriver.test.ts +0 -246
  110. package/src/upload/__tests__/TurboStorageDriver.test.ts +0 -15
  111. package/src/upload/__tests__/contentGateway.test.ts +0 -31
  112. package/src/upload/contentGateway.ts +0 -37
  113. package/src/upload/index.ts +0 -2
@@ -0,0 +1,748 @@
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
+ }
9
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
10
+ try {
11
+ var info = gen[key](arg);
12
+ var value = info.value;
13
+ } catch (error) {
14
+ reject(error);
15
+ return;
16
+ }
17
+ if (info.done) {
18
+ resolve(value);
19
+ } else {
20
+ Promise.resolve(value).then(_next, _throw);
21
+ }
22
+ }
23
+ function _async_to_generator(fn) {
24
+ return function() {
25
+ var self = this, args = arguments;
26
+ return new Promise(function(resolve, reject) {
27
+ var gen = fn.apply(self, args);
28
+ function _next(value) {
29
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
30
+ }
31
+ function _throw(err) {
32
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
33
+ }
34
+ _next(undefined);
35
+ });
36
+ };
37
+ }
38
+ function _define_property(obj, key, value) {
39
+ if (key in obj) {
40
+ Object.defineProperty(obj, key, {
41
+ value: value,
42
+ enumerable: true,
43
+ configurable: true,
44
+ writable: true
45
+ });
46
+ } else {
47
+ obj[key] = value;
48
+ }
49
+ return obj;
50
+ }
51
+ function _instanceof(left, right) {
52
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
53
+ return !!right[Symbol.hasInstance](left);
54
+ } else {
55
+ return left instanceof right;
56
+ }
57
+ }
58
+ function _iterable_to_array_limit(arr, i) {
59
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
60
+ if (_i == null) return;
61
+ var _arr = [];
62
+ var _n = true;
63
+ var _d = false;
64
+ var _s, _e;
65
+ try {
66
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
67
+ _arr.push(_s.value);
68
+ if (i && _arr.length === i) break;
69
+ }
70
+ } catch (err) {
71
+ _d = true;
72
+ _e = err;
73
+ } finally{
74
+ try {
75
+ if (!_n && _i["return"] != null) _i["return"]();
76
+ } finally{
77
+ if (_d) throw _e;
78
+ }
79
+ }
80
+ return _arr;
81
+ }
82
+ function _non_iterable_rest() {
83
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
84
+ }
85
+ function _object_spread(target) {
86
+ for(var i = 1; i < arguments.length; i++){
87
+ var source = arguments[i] != null ? arguments[i] : {};
88
+ var ownKeys = Object.keys(source);
89
+ if (typeof Object.getOwnPropertySymbols === "function") {
90
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
91
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
92
+ }));
93
+ }
94
+ ownKeys.forEach(function(key) {
95
+ _define_property(target, key, source[key]);
96
+ });
97
+ }
98
+ return target;
99
+ }
100
+ function ownKeys(object, enumerableOnly) {
101
+ var keys = Object.keys(object);
102
+ if (Object.getOwnPropertySymbols) {
103
+ var symbols = Object.getOwnPropertySymbols(object);
104
+ if (enumerableOnly) {
105
+ symbols = symbols.filter(function(sym) {
106
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
107
+ });
108
+ }
109
+ keys.push.apply(keys, symbols);
110
+ }
111
+ return keys;
112
+ }
113
+ function _object_spread_props(target, source) {
114
+ source = source != null ? source : {};
115
+ if (Object.getOwnPropertyDescriptors) {
116
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
117
+ } else {
118
+ ownKeys(Object(source)).forEach(function(key) {
119
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
120
+ });
121
+ }
122
+ return target;
123
+ }
124
+ function _sliced_to_array(arr, i) {
125
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
126
+ }
127
+ function _unsupported_iterable_to_array(o, minLen) {
128
+ if (!o) return;
129
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
130
+ var n = Object.prototype.toString.call(o).slice(8, -1);
131
+ if (n === "Object" && o.constructor) n = o.constructor.name;
132
+ if (n === "Map" || n === "Set") return Array.from(n);
133
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
134
+ }
135
+ function _ts_generator(thisArg, body) {
136
+ var f, y, t, _ = {
137
+ label: 0,
138
+ sent: function() {
139
+ if (t[0] & 1) throw t[1];
140
+ return t[1];
141
+ },
142
+ trys: [],
143
+ ops: []
144
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
145
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
146
+ return this;
147
+ }), g;
148
+ function verb(n) {
149
+ return function(v) {
150
+ return step([
151
+ n,
152
+ v
153
+ ]);
154
+ };
155
+ }
156
+ function step(op) {
157
+ if (f) throw new TypeError("Generator is already executing.");
158
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
159
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
160
+ if (y = 0, t) op = [
161
+ op[0] & 2,
162
+ t.value
163
+ ];
164
+ switch(op[0]){
165
+ case 0:
166
+ case 1:
167
+ t = op;
168
+ break;
169
+ case 4:
170
+ _.label++;
171
+ return {
172
+ value: op[1],
173
+ done: false
174
+ };
175
+ case 5:
176
+ _.label++;
177
+ y = op[1];
178
+ op = [
179
+ 0
180
+ ];
181
+ continue;
182
+ case 7:
183
+ op = _.ops.pop();
184
+ _.trys.pop();
185
+ continue;
186
+ default:
187
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
188
+ _ = 0;
189
+ continue;
190
+ }
191
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
192
+ _.label = op[1];
193
+ break;
194
+ }
195
+ if (op[0] === 6 && _.label < t[1]) {
196
+ _.label = t[1];
197
+ t = op;
198
+ break;
199
+ }
200
+ if (t && _.label < t[2]) {
201
+ _.label = t[2];
202
+ _.ops.push(op);
203
+ break;
204
+ }
205
+ if (t[2]) _.ops.pop();
206
+ _.trys.pop();
207
+ continue;
208
+ }
209
+ op = body.call(thisArg, _);
210
+ } catch (e) {
211
+ op = [
212
+ 6,
213
+ e
214
+ ];
215
+ y = 0;
216
+ } finally{
217
+ f = t = 0;
218
+ }
219
+ if (op[0] & 5) throw op[1];
220
+ return {
221
+ value: op[0] ? op[1] : void 0,
222
+ done: true
223
+ };
224
+ }
225
+ }
226
+ import { createHash } from "node:crypto";
227
+ import fs from "node:fs/promises";
228
+ import os from "node:os";
229
+ import path from "node:path";
230
+ import getVideoDimensions from "get-video-dimensions";
231
+ import { imageSize } from "image-size";
232
+ import { ensureHttpsUrl, inferFileNameFromUrl, inferMimeType } from "./files.js";
233
+ import { uploadBytes } from "./http.js";
234
+ import { firstString, readDeep } from "./records.js";
235
+ var NFT_SCHEMA_VERSION = "0.4.0";
236
+ var DEFAULT_R2_PUBLIC_HOSTS = [
237
+ "r2.solanamobiledappstore.com",
238
+ "r2-staging.solanamobiledappstore.com"
239
+ ];
240
+ function asStringArray(value) {
241
+ return Array.isArray(value) ? value.filter(function(item) {
242
+ return typeof item === "string";
243
+ }) : [];
244
+ }
245
+ function normalizeMimeType(value) {
246
+ var _value_split_;
247
+ return value === null || value === void 0 ? void 0 : (_value_split_ = value.split(";")[0]) === null || _value_split_ === void 0 ? void 0 : _value_split_.trim().toLowerCase();
248
+ }
249
+ function toPositiveNumber(value) {
250
+ return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : undefined;
251
+ }
252
+ function isR2PublicUrl(url) {
253
+ try {
254
+ var hostname = new URL(url).hostname.toLowerCase();
255
+ return DEFAULT_R2_PUBLIC_HOSTS.includes(hostname);
256
+ } catch (e) {
257
+ return false;
258
+ }
259
+ }
260
+ function inferExtensionFromMimeType(mimeType) {
261
+ switch(mimeType){
262
+ case "image/png":
263
+ return "png";
264
+ case "image/jpeg":
265
+ return "jpg";
266
+ case "image/webp":
267
+ return "webp";
268
+ case "image/gif":
269
+ return "gif";
270
+ case "image/svg+xml":
271
+ return "svg";
272
+ case "video/mp4":
273
+ return "mp4";
274
+ case "video/webm":
275
+ return "webm";
276
+ case "video/quicktime":
277
+ return "mov";
278
+ case "application/json":
279
+ return "json";
280
+ default:
281
+ {
282
+ var _mimeType_split__split_, _mimeType_split_;
283
+ var subtype = (_mimeType_split_ = mimeType.split("/")[1]) === null || _mimeType_split_ === void 0 ? void 0 : (_mimeType_split__split_ = _mimeType_split_.split("+")[0]) === null || _mimeType_split__split_ === void 0 ? void 0 : _mimeType_split__split_.trim().toLowerCase();
284
+ return (subtype === null || subtype === void 0 ? void 0 : subtype.replace(/[^a-z0-9]/g, "")) || undefined;
285
+ }
286
+ }
287
+ }
288
+ function inferUploadFileExtension(fileName, mimeType) {
289
+ var _fileName_split_pop;
290
+ var byName = (_fileName_split_pop = fileName.split(".").pop()) === null || _fileName_split_pop === void 0 ? void 0 : _fileName_split_pop.trim().toLowerCase();
291
+ if (byName && /^[a-z0-9]+$/.test(byName)) {
292
+ return byName;
293
+ }
294
+ return inferExtensionFromMimeType(mimeType) || "bin";
295
+ }
296
+ function normalizeOptionalUrl(value) {
297
+ if (!value) {
298
+ return undefined;
299
+ }
300
+ var trimmed = value.trim();
301
+ if (!trimmed) {
302
+ return undefined;
303
+ }
304
+ return ensureHttpsUrl(trimmed);
305
+ }
306
+ function normalizeReleaseName(value) {
307
+ var trimmed = value.trim();
308
+ return trimmed.length <= 32 ? trimmed : trimmed.slice(0, 32);
309
+ }
310
+ function isVideoMimeType(mimeType) {
311
+ return mimeType.startsWith("video/");
312
+ }
313
+ function getVideoMediaDimensions(fileBytes, fileName, mimeType) {
314
+ return _async_to_generator(function() {
315
+ var tempFilePath, dimensions, width, height;
316
+ return _ts_generator(this, function(_state) {
317
+ switch(_state.label){
318
+ case 0:
319
+ tempFilePath = path.join(os.tmpdir(), "dapp-store-media-".concat(process.pid, "-").concat(Date.now(), "-").concat(Math.random().toString(36).slice(2), ".").concat(inferUploadFileExtension(fileName, mimeType)));
320
+ return [
321
+ 4,
322
+ fs.writeFile(tempFilePath, fileBytes)
323
+ ];
324
+ case 1:
325
+ _state.sent();
326
+ _state.label = 2;
327
+ case 2:
328
+ _state.trys.push([
329
+ 2,
330
+ ,
331
+ 4,
332
+ 6
333
+ ]);
334
+ return [
335
+ 4,
336
+ getVideoDimensions(tempFilePath)
337
+ ];
338
+ case 3:
339
+ dimensions = _state.sent();
340
+ width = toPositiveNumber(dimensions.width);
341
+ height = toPositiveNumber(dimensions.height);
342
+ if (!width || !height) {
343
+ throw new Error("Unable to determine video dimensions for ".concat(fileName));
344
+ }
345
+ return [
346
+ 2,
347
+ {
348
+ width: width,
349
+ height: height
350
+ }
351
+ ];
352
+ case 4:
353
+ return [
354
+ 4,
355
+ fs.rm(tempFilePath, {
356
+ force: true
357
+ })
358
+ ];
359
+ case 5:
360
+ _state.sent();
361
+ return [
362
+ 7
363
+ ];
364
+ case 6:
365
+ return [
366
+ 2
367
+ ];
368
+ }
369
+ });
370
+ })();
371
+ }
372
+ function getMediaDimensions(fileBytes, fileName, mimeType) {
373
+ return _async_to_generator(function() {
374
+ var dimensions, width, height;
375
+ return _ts_generator(this, function(_state) {
376
+ switch(_state.label){
377
+ case 0:
378
+ if (!isVideoMimeType(mimeType)) return [
379
+ 3,
380
+ 2
381
+ ];
382
+ return [
383
+ 4,
384
+ getVideoMediaDimensions(fileBytes, fileName, mimeType)
385
+ ];
386
+ case 1:
387
+ return [
388
+ 2,
389
+ _state.sent()
390
+ ];
391
+ case 2:
392
+ dimensions = imageSize(fileBytes);
393
+ width = toPositiveNumber(dimensions.width);
394
+ height = toPositiveNumber(dimensions.height);
395
+ if (!width || !height) {
396
+ throw new Error("Unable to determine image dimensions for ".concat(fileName));
397
+ }
398
+ return [
399
+ 2,
400
+ {
401
+ width: width,
402
+ height: height
403
+ }
404
+ ];
405
+ }
406
+ });
407
+ })();
408
+ }
409
+ function getPreferredFeatureGraphicUrl(bundle) {
410
+ return firstString(bundle, [
411
+ "dapp.editorsChoiceGraphicUrl",
412
+ "dapp.featureGraphicUrl"
413
+ ]) || "";
414
+ }
415
+ function resolveMediaItem(client, input) {
416
+ return _async_to_generator(function() {
417
+ var resolvedUri, isAlreadyPublicR2, remoteFile, error, message, fileBytes, remoteFileName, resolvedMimeType, fileHash, dimensions, uploadTarget;
418
+ return _ts_generator(this, function(_state) {
419
+ switch(_state.label){
420
+ case 0:
421
+ resolvedUri = ensureHttpsUrl(input.uri);
422
+ isAlreadyPublicR2 = isR2PublicUrl(resolvedUri);
423
+ _state.label = 1;
424
+ case 1:
425
+ _state.trys.push([
426
+ 1,
427
+ 3,
428
+ ,
429
+ 4
430
+ ]);
431
+ return [
432
+ 4,
433
+ client.fetchRemoteFile({
434
+ url: resolvedUri,
435
+ fileName: input.fallbackFileName,
436
+ expectedMimeType: input.expectedMimeType
437
+ })
438
+ ];
439
+ case 2:
440
+ remoteFile = _state.sent();
441
+ return [
442
+ 3,
443
+ 4
444
+ ];
445
+ case 3:
446
+ error = _state.sent();
447
+ message = _instanceof(error, Error) ? error.message : String(error);
448
+ throw new Error("Failed to fetch ".concat(input.purpose, " media from ").concat(resolvedUri, ": ").concat(message));
449
+ case 4:
450
+ fileBytes = Buffer.from(remoteFile.data, "base64");
451
+ if (fileBytes.byteLength === 0) {
452
+ throw new Error("Remote media file is empty: ".concat(resolvedUri));
453
+ }
454
+ remoteFileName = remoteFile.fileName || input.fallbackFileName;
455
+ resolvedMimeType = normalizeMimeType(remoteFile.mimeType) || input.defaultMimeType || inferMimeType(remoteFileName);
456
+ fileHash = createHash("sha256").update(fileBytes).digest("hex");
457
+ return [
458
+ 4,
459
+ getMediaDimensions(fileBytes, remoteFileName, resolvedMimeType)
460
+ ];
461
+ case 5:
462
+ dimensions = _state.sent();
463
+ if (isAlreadyPublicR2) {
464
+ return [
465
+ 2,
466
+ {
467
+ mime: resolvedMimeType,
468
+ purpose: input.purpose,
469
+ uri: resolvedUri,
470
+ width: dimensions.width,
471
+ height: dimensions.height,
472
+ sha256: fileHash
473
+ }
474
+ ];
475
+ }
476
+ return [
477
+ 4,
478
+ client.createUploadTarget({
479
+ fileHash: fileHash,
480
+ fileExtension: inferUploadFileExtension(remoteFileName, resolvedMimeType),
481
+ contentType: resolvedMimeType
482
+ })
483
+ ];
484
+ case 6:
485
+ uploadTarget = _state.sent();
486
+ if (!uploadTarget.uploadUrl || !uploadTarget.publicUrl) {
487
+ throw new Error("The portal did not return a valid upload target for ".concat(input.purpose, "."));
488
+ }
489
+ return [
490
+ 4,
491
+ uploadBytes(uploadTarget.uploadUrl, fileBytes, resolvedMimeType)
492
+ ];
493
+ case 7:
494
+ _state.sent();
495
+ return [
496
+ 2,
497
+ {
498
+ mime: resolvedMimeType,
499
+ purpose: input.purpose,
500
+ uri: uploadTarget.publicUrl,
501
+ width: dimensions.width,
502
+ height: dimensions.height,
503
+ sha256: fileHash
504
+ }
505
+ ];
506
+ }
507
+ });
508
+ })();
509
+ }
510
+ export function buildReleaseMetadataDocument(client, bundle, sourceKind) {
511
+ return _async_to_generator(function() {
512
+ var _bundle_metadata, _bundle_metadata1, _bundle_metadata2, _bundle_metadata3, _bundle_metadata4, _bundle_metadata5, _bundle_metadata6, _bundle_metadata7, _bundle_metadata8, _bundle_metadata9, releaseName, shortDescription, longDescription, newInVersion, publisherAddress, publisherName, publisherWebsite, publisherContact, publisherSupportEmail, iconUri, installUri, installMimeType, _bundle_installFile_size, _ref, installSize, installSha256, androidPackage, versionName, _bundle_release_versionCode, versionCode, _bundle_release_minSdkVersion, minSdkVersion, targetSdkRaw, targetSdkVersion, certificateFingerprint, _bundle_release_permissions, permissions, locales, _bundle_dapp_dappPreviewUrls, previewUris, bannerUri, featureGraphicUri, media, iconMedia, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _step_value, index, previewUri, _, err, _1, _2, licenseUrl, copyrightUrl, privacyPolicyUrl;
513
+ return _ts_generator(this, function(_state) {
514
+ switch(_state.label){
515
+ case 0:
516
+ releaseName = normalizeReleaseName(((_bundle_metadata = bundle.metadata) === null || _bundle_metadata === void 0 ? void 0 : _bundle_metadata.localizedName) || bundle.release.localizedName || bundle.release.releaseName || bundle.dapp.dappName || "Release update");
517
+ shortDescription = ((_bundle_metadata1 = bundle.metadata) === null || _bundle_metadata1 === void 0 ? void 0 : _bundle_metadata1.shortDescription) || bundle.release.shortDescription || bundle.dapp.subtitle || "Release NFT";
518
+ longDescription = ((_bundle_metadata2 = bundle.metadata) === null || _bundle_metadata2 === void 0 ? void 0 : _bundle_metadata2.longDescription) || bundle.release.longDescription || bundle.dapp.description || shortDescription;
519
+ newInVersion = ((_bundle_metadata3 = bundle.metadata) === null || _bundle_metadata3 === void 0 ? void 0 : _bundle_metadata3.newInVersion) || bundle.release.newInVersion || "";
520
+ publisherAddress = bundle.signerAuthority.dappWalletAddress || bundle.signerAuthority.collectionAuthority || bundle.dapp.walletAddress || "";
521
+ publisherName = bundle.publisher.name || "";
522
+ publisherWebsite = normalizeOptionalUrl(((_bundle_metadata4 = bundle.metadata) === null || _bundle_metadata4 === void 0 ? void 0 : _bundle_metadata4.publisherWebsite) || bundle.publisher.website || bundle.dapp.appWebsite || bundle.dapp.website || undefined);
523
+ publisherContact = bundle.publisher.email || bundle.dapp.contactEmail || bundle.dapp.supportEmail || "";
524
+ publisherSupportEmail = bundle.publisher.supportEmail || ((_bundle_metadata5 = bundle.metadata) === null || _bundle_metadata5 === void 0 ? void 0 : _bundle_metadata5.supportEmail) || bundle.dapp.supportEmail || bundle.dapp.contactEmail || bundle.publisher.email || publisherContact;
525
+ iconUri = bundle.dapp.dappIconUrl || "";
526
+ if (!iconUri) {
527
+ throw new Error("Publication bundle did not include a public app icon URL.");
528
+ }
529
+ installUri = bundle.installFile.uri || bundle.release.releaseFileUrl || "";
530
+ installMimeType = bundle.installFile.mimeType || inferMimeType(inferFileNameFromUrl(installUri));
531
+ installSize = (_ref = (_bundle_installFile_size = bundle.installFile.size) !== null && _bundle_installFile_size !== void 0 ? _bundle_installFile_size : bundle.release.releaseFileSize) !== null && _ref !== void 0 ? _ref : 0;
532
+ installSha256 = bundle.installFile.sha256 || bundle.release.releaseFileHash || "";
533
+ androidPackage = bundle.release.androidPackage || bundle.dapp.androidPackage;
534
+ versionName = bundle.release.versionName || "";
535
+ versionCode = (_bundle_release_versionCode = bundle.release.versionCode) !== null && _bundle_release_versionCode !== void 0 ? _bundle_release_versionCode : 0;
536
+ minSdkVersion = (_bundle_release_minSdkVersion = bundle.release.minSdkVersion) !== null && _bundle_release_minSdkVersion !== void 0 ? _bundle_release_minSdkVersion : 1;
537
+ targetSdkRaw = readDeep(bundle, "release.targetSdkVersion");
538
+ targetSdkVersion = typeof targetSdkRaw === "number" ? targetSdkRaw : Number(targetSdkRaw || 0) || null;
539
+ certificateFingerprint = bundle.release.certificateFingerprint || "";
540
+ permissions = (_bundle_release_permissions = bundle.release.permissions) !== null && _bundle_release_permissions !== void 0 ? _bundle_release_permissions : [];
541
+ locales = bundle.release.locales && bundle.release.locales.length > 0 ? bundle.release.locales : ((_bundle_metadata6 = bundle.metadata) === null || _bundle_metadata6 === void 0 ? void 0 : _bundle_metadata6.locales) && bundle.metadata.locales.length > 0 ? bundle.metadata.locales : bundle.dapp.languages && bundle.dapp.languages.length > 0 ? bundle.dapp.languages : [
542
+ "en-US"
543
+ ];
544
+ previewUris = (_bundle_dapp_dappPreviewUrls = bundle.dapp.dappPreviewUrls) !== null && _bundle_dapp_dappPreviewUrls !== void 0 ? _bundle_dapp_dappPreviewUrls : [];
545
+ bannerUri = bundle.dapp.bannerUrl || "";
546
+ featureGraphicUri = getPreferredFeatureGraphicUrl(bundle);
547
+ media = [];
548
+ return [
549
+ 4,
550
+ resolveMediaItem(client, {
551
+ defaultMimeType: "image/png",
552
+ fallbackFileName: "release-icon.png",
553
+ purpose: "icon",
554
+ uri: iconUri
555
+ })
556
+ ];
557
+ case 1:
558
+ iconMedia = _state.sent();
559
+ media.push(iconMedia);
560
+ _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
561
+ _state.label = 2;
562
+ case 2:
563
+ _state.trys.push([
564
+ 2,
565
+ 7,
566
+ 8,
567
+ 9
568
+ ]);
569
+ _iterator = previewUris.entries()[Symbol.iterator]();
570
+ _state.label = 3;
571
+ case 3:
572
+ if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
573
+ 3,
574
+ 6
575
+ ];
576
+ _step_value = _sliced_to_array(_step.value, 2), index = _step_value[0], previewUri = _step_value[1];
577
+ _ = media.push;
578
+ return [
579
+ 4,
580
+ resolveMediaItem(client, {
581
+ fallbackFileName: "release-screenshot-".concat(index + 1),
582
+ purpose: "screenshot",
583
+ uri: previewUri
584
+ })
585
+ ];
586
+ case 4:
587
+ _.apply(media, [
588
+ _state.sent()
589
+ ]);
590
+ _state.label = 5;
591
+ case 5:
592
+ _iteratorNormalCompletion = true;
593
+ return [
594
+ 3,
595
+ 3
596
+ ];
597
+ case 6:
598
+ return [
599
+ 3,
600
+ 9
601
+ ];
602
+ case 7:
603
+ err = _state.sent();
604
+ _didIteratorError = true;
605
+ _iteratorError = err;
606
+ return [
607
+ 3,
608
+ 9
609
+ ];
610
+ case 8:
611
+ try {
612
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
613
+ _iterator.return();
614
+ }
615
+ } finally{
616
+ if (_didIteratorError) {
617
+ throw _iteratorError;
618
+ }
619
+ }
620
+ return [
621
+ 7
622
+ ];
623
+ case 9:
624
+ if (!bannerUri) return [
625
+ 3,
626
+ 11
627
+ ];
628
+ _1 = media.push;
629
+ return [
630
+ 4,
631
+ resolveMediaItem(client, {
632
+ defaultMimeType: inferMimeType(inferFileNameFromUrl(bannerUri)),
633
+ fallbackFileName: "release-banner.png",
634
+ purpose: "banner",
635
+ uri: bannerUri
636
+ })
637
+ ];
638
+ case 10:
639
+ _1.apply(media, [
640
+ _state.sent()
641
+ ]);
642
+ _state.label = 11;
643
+ case 11:
644
+ if (!featureGraphicUri) return [
645
+ 3,
646
+ 13
647
+ ];
648
+ _2 = media.push;
649
+ return [
650
+ 4,
651
+ resolveMediaItem(client, {
652
+ defaultMimeType: inferMimeType(inferFileNameFromUrl(featureGraphicUri)),
653
+ fallbackFileName: "release-feature-graphic.png",
654
+ purpose: "featureGraphic",
655
+ uri: featureGraphicUri
656
+ })
657
+ ];
658
+ case 12:
659
+ _2.apply(media, [
660
+ _state.sent()
661
+ ]);
662
+ _state.label = 13;
663
+ case 13:
664
+ licenseUrl = normalizeOptionalUrl(((_bundle_metadata7 = bundle.metadata) === null || _bundle_metadata7 === void 0 ? void 0 : _bundle_metadata7.legal.licenseUrl) || bundle.dapp.licenseUrl || undefined);
665
+ copyrightUrl = ((_bundle_metadata8 = bundle.metadata) === null || _bundle_metadata8 === void 0 ? void 0 : _bundle_metadata8.legal.copyrightUrl) || bundle.dapp.copyrightUrl || undefined;
666
+ privacyPolicyUrl = normalizeOptionalUrl(((_bundle_metadata9 = bundle.metadata) === null || _bundle_metadata9 === void 0 ? void 0 : _bundle_metadata9.legal.privacyPolicyUrl) || bundle.dapp.privacyPolicyUrl || undefined);
667
+ return [
668
+ 2,
669
+ _object_spread_props(_object_spread({
670
+ schema_version: NFT_SCHEMA_VERSION,
671
+ name: releaseName,
672
+ description: shortDescription,
673
+ image: iconMedia.uri
674
+ }, publisherWebsite ? {
675
+ external_url: publisherWebsite
676
+ } : {}), {
677
+ properties: {
678
+ category: "dApp",
679
+ creators: [
680
+ {
681
+ address: publisherAddress,
682
+ share: 100
683
+ }
684
+ ]
685
+ },
686
+ extensions: {
687
+ solana_dapp_store: {
688
+ publisher_details: _object_spread_props(_object_spread({
689
+ name: publisherName
690
+ }, publisherWebsite ? {
691
+ website: publisherWebsite
692
+ } : {}), {
693
+ contact: publisherContact,
694
+ support_email: publisherSupportEmail
695
+ }),
696
+ release_details: _object_spread_props(_object_spread({
697
+ updated_on: new Date().toISOString()
698
+ }, licenseUrl ? {
699
+ license_url: licenseUrl
700
+ } : {}, copyrightUrl ? {
701
+ copyright_url: copyrightUrl
702
+ } : {}, privacyPolicyUrl ? {
703
+ privacy_policy_url: privacyPolicyUrl
704
+ } : {}), {
705
+ localized_resources: {
706
+ long_description: "1",
707
+ new_in_version: "2",
708
+ name: "4",
709
+ short_description: "5"
710
+ }
711
+ }),
712
+ media: media,
713
+ files: [
714
+ {
715
+ mime: installMimeType,
716
+ purpose: "install",
717
+ size: installSize,
718
+ sha256: installSha256,
719
+ uri: installUri
720
+ }
721
+ ],
722
+ android_details: {
723
+ android_package: androidPackage,
724
+ version: versionName,
725
+ version_code: versionCode,
726
+ min_sdk: minSdkVersion,
727
+ target_sdk: targetSdkVersion,
728
+ cert_fingerprint: certificateFingerprint,
729
+ permissions: asStringArray(permissions),
730
+ locales: asStringArray(locales)
731
+ }
732
+ },
733
+ i18n: {
734
+ "en-US": {
735
+ "1": longDescription,
736
+ "2": newInVersion,
737
+ "4": releaseName,
738
+ "5": shortDescription.slice(0, 50)
739
+ }
740
+ }
741
+ },
742
+ __origin: sourceKind
743
+ })
744
+ ];
745
+ }
746
+ });
747
+ })();
748
+ }