@solana-mobile/dapp-store-cli 0.16.0 → 0.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,1051 @@
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_without_holes(arr) {
7
+ if (Array.isArray(arr)) return _array_like_to_array(arr);
8
+ }
9
+ function _class_call_check(instance, Constructor) {
10
+ if (!(instance instanceof Constructor)) {
11
+ throw new TypeError("Cannot call a class as a function");
12
+ }
13
+ }
14
+ function _defineProperties(target, props) {
15
+ for(var i = 0; i < props.length; i++){
16
+ var descriptor = props[i];
17
+ descriptor.enumerable = descriptor.enumerable || false;
18
+ descriptor.configurable = true;
19
+ if ("value" in descriptor) descriptor.writable = true;
20
+ Object.defineProperty(target, descriptor.key, descriptor);
21
+ }
22
+ }
23
+ function _create_class(Constructor, protoProps, staticProps) {
24
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
25
+ if (staticProps) _defineProperties(Constructor, staticProps);
26
+ return Constructor;
27
+ }
28
+ function _define_property(obj, key, value) {
29
+ if (key in obj) {
30
+ Object.defineProperty(obj, key, {
31
+ value: value,
32
+ enumerable: true,
33
+ configurable: true,
34
+ writable: true
35
+ });
36
+ } else {
37
+ obj[key] = value;
38
+ }
39
+ return obj;
40
+ }
41
+ function _instanceof(left, right) {
42
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
43
+ return !!right[Symbol.hasInstance](left);
44
+ } else {
45
+ return left instanceof right;
46
+ }
47
+ }
48
+ function _iterable_to_array(iter) {
49
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
50
+ }
51
+ function _non_iterable_spread() {
52
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
53
+ }
54
+ function _to_consumable_array(arr) {
55
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
56
+ }
57
+ function _unsupported_iterable_to_array(o, minLen) {
58
+ if (!o) return;
59
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
60
+ var n = Object.prototype.toString.call(o).slice(8, -1);
61
+ if (n === "Object" && o.constructor) n = o.constructor.name;
62
+ if (n === "Map" || n === "Set") return Array.from(n);
63
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
64
+ }
65
+ import * as readline from 'node:readline';
66
+ var SPINNER_FRAMES = [
67
+ '|',
68
+ '/',
69
+ '-',
70
+ '\\'
71
+ ];
72
+ var PHASES = [
73
+ {
74
+ key: 'source',
75
+ label: 'Prepare source'
76
+ },
77
+ {
78
+ key: 'ingestion',
79
+ label: 'Process APK'
80
+ },
81
+ {
82
+ key: 'context',
83
+ label: 'Load release context'
84
+ },
85
+ {
86
+ key: 'mint',
87
+ label: 'Mint release NFT'
88
+ },
89
+ {
90
+ key: 'verify',
91
+ label: 'Verify collection'
92
+ },
93
+ {
94
+ key: 'attest',
95
+ label: 'Create attestation'
96
+ },
97
+ {
98
+ key: 'submit',
99
+ label: 'Submit to review'
100
+ }
101
+ ];
102
+ var PHASE_WEIGHT_PROFILES = {
103
+ 'apk-file': {
104
+ source: 0.42,
105
+ ingestion: 0.2,
106
+ context: 0.08,
107
+ mint: 0.12,
108
+ verify: 0.08,
109
+ attest: 0.04,
110
+ submit: 0.06
111
+ },
112
+ 'apk-url': {
113
+ source: 0.05,
114
+ ingestion: 0.43,
115
+ context: 0.12,
116
+ mint: 0.16,
117
+ verify: 0.1,
118
+ attest: 0.05,
119
+ submit: 0.09
120
+ },
121
+ resume: {
122
+ source: 0.42,
123
+ ingestion: 0.2,
124
+ context: 0.08,
125
+ mint: 0.12,
126
+ verify: 0.08,
127
+ attest: 0.04,
128
+ submit: 0.06
129
+ }
130
+ };
131
+ var STEP_PROGRESS_RANGES = {
132
+ 'source.prepare': {
133
+ start: 0.02,
134
+ end: 0.1
135
+ },
136
+ 'source.upload': {
137
+ start: 0.1,
138
+ end: 1
139
+ },
140
+ 'source.ready': {
141
+ start: 0.2,
142
+ end: 1
143
+ },
144
+ 'ingestion.create': {
145
+ start: 0.05,
146
+ end: 0.2
147
+ },
148
+ 'ingestion.wait': {
149
+ start: 0.2,
150
+ end: 1
151
+ },
152
+ 'bundle.load': {
153
+ start: 0.1,
154
+ end: 0.55
155
+ },
156
+ 'session.load': {
157
+ start: 0.55,
158
+ end: 1
159
+ },
160
+ 'mint.prepare': {
161
+ start: 0.05,
162
+ end: 0.3
163
+ },
164
+ 'mint.submit': {
165
+ start: 0.3,
166
+ end: 0.65
167
+ },
168
+ 'mint.save': {
169
+ start: 0.65,
170
+ end: 1
171
+ },
172
+ 'verify.prepare': {
173
+ start: 0.05,
174
+ end: 0.35
175
+ },
176
+ 'verify.submit': {
177
+ start: 0.35,
178
+ end: 1
179
+ },
180
+ 'attestation.create': {
181
+ start: 0.05,
182
+ end: 1
183
+ },
184
+ 'submit.store': {
185
+ start: 0.05,
186
+ end: 1
187
+ }
188
+ };
189
+ var DEFAULT_RUNNING_STEP_PROGRESS = 0.2;
190
+ var STEP_TO_PHASE = {
191
+ 'source.prepare': 'source',
192
+ 'source.upload': 'source',
193
+ 'source.ready': 'source',
194
+ 'ingestion.create': 'ingestion',
195
+ 'ingestion.wait': 'ingestion',
196
+ 'bundle.load': 'context',
197
+ 'session.load': 'context',
198
+ 'mint.prepare': 'mint',
199
+ 'mint.submit': 'mint',
200
+ 'mint.save': 'mint',
201
+ 'verify.prepare': 'verify',
202
+ 'verify.submit': 'verify',
203
+ 'attestation.create': 'attest',
204
+ 'submit.store': 'submit'
205
+ };
206
+ var PHASE_FINAL_STEPS = {
207
+ source: [
208
+ 'source.ready',
209
+ 'source.upload'
210
+ ],
211
+ ingestion: [
212
+ 'ingestion.wait'
213
+ ],
214
+ context: [
215
+ 'session.load'
216
+ ],
217
+ mint: [
218
+ 'mint.save'
219
+ ],
220
+ verify: [
221
+ 'verify.submit'
222
+ ],
223
+ attest: [
224
+ 'attestation.create'
225
+ ],
226
+ submit: [
227
+ 'submit.store'
228
+ ]
229
+ };
230
+ var STAGE_COMPLETED_PHASES = {
231
+ PreparedForMint: [
232
+ 'source',
233
+ 'ingestion',
234
+ 'context'
235
+ ],
236
+ MintSubmitted: [
237
+ 'source',
238
+ 'ingestion',
239
+ 'context'
240
+ ],
241
+ MintSaved: [
242
+ 'source',
243
+ 'ingestion',
244
+ 'context',
245
+ 'mint'
246
+ ],
247
+ VerificationSubmitted: [
248
+ 'source',
249
+ 'ingestion',
250
+ 'context',
251
+ 'mint'
252
+ ],
253
+ Verified: [
254
+ 'source',
255
+ 'ingestion',
256
+ 'context',
257
+ 'mint',
258
+ 'verify'
259
+ ],
260
+ Attested: [
261
+ 'source',
262
+ 'ingestion',
263
+ 'context',
264
+ 'mint',
265
+ 'verify',
266
+ 'attest'
267
+ ],
268
+ Submitted: [
269
+ 'source',
270
+ 'ingestion',
271
+ 'context',
272
+ 'mint',
273
+ 'verify',
274
+ 'attest',
275
+ 'submit'
276
+ ]
277
+ };
278
+ var MAX_RECENT_EVENTS = 2;
279
+ var VERBOSE_PREFIX = 'Verbose';
280
+ export function createPublicationProgressReporter(input) {
281
+ return new PublicationProgressReporter(input);
282
+ }
283
+ var PublicationProgressReporter = /*#__PURE__*/ function() {
284
+ "use strict";
285
+ function PublicationProgressReporter(input) {
286
+ var _this = this;
287
+ _class_call_check(this, PublicationProgressReporter);
288
+ _define_property(this, "logger", void 0);
289
+ _define_property(this, "title", void 0);
290
+ _define_property(this, "stream", void 0);
291
+ _define_property(this, "interactive", void 0);
292
+ _define_property(this, "verbose", void 0);
293
+ _define_property(this, "phaseStates", void 0);
294
+ _define_property(this, "phaseProgress", void 0);
295
+ _define_property(this, "verboseValues", new Map());
296
+ _define_property(this, "currentMessage", void 0);
297
+ _define_property(this, "recentEvents", []);
298
+ _define_property(this, "context", {});
299
+ _define_property(this, "spinnerIndex", 0);
300
+ _define_property(this, "renderedLineCount", 0);
301
+ _define_property(this, "intervalId", void 0);
302
+ _define_property(this, "finalState", void 0);
303
+ this.title = input.title;
304
+ var _input_stream;
305
+ this.stream = (_input_stream = input.stream) !== null && _input_stream !== void 0 ? _input_stream : process.stdout;
306
+ this.interactive = Boolean(this.stream.isTTY) && process.env.TERM !== 'dumb';
307
+ this.verbose = Boolean(input.verbose);
308
+ this.phaseStates = Object.fromEntries(PHASES.map(function(param) {
309
+ var key = param.key;
310
+ return [
311
+ key,
312
+ 'pending'
313
+ ];
314
+ }));
315
+ this.phaseProgress = Object.fromEntries(PHASES.map(function(param) {
316
+ var key = param.key;
317
+ return [
318
+ key,
319
+ 0
320
+ ];
321
+ }));
322
+ this.currentMessage = input.mode === 'resume' ? 'Loading existing publication state' : 'Preparing publication workflow';
323
+ if (input.mode === 'resume') {
324
+ this.context.sourceKind = 'resume';
325
+ }
326
+ if (input.mode === 'resume') {
327
+ this.phaseStates.source = 'complete';
328
+ this.phaseStates.ingestion = 'complete';
329
+ this.phaseProgress.source = 1;
330
+ this.phaseProgress.ingestion = 1;
331
+ }
332
+ this.logger = {
333
+ debug: function(message, metadata) {
334
+ _this.handleEvent('debug', message, metadata);
335
+ },
336
+ info: function(message, metadata) {
337
+ _this.handleEvent('info', message, metadata);
338
+ },
339
+ warn: function(message, metadata) {
340
+ _this.handleEvent('warn', message, metadata);
341
+ }
342
+ };
343
+ }
344
+ _create_class(PublicationProgressReporter, [
345
+ {
346
+ key: "start",
347
+ value: function start(input) {
348
+ var _this = this;
349
+ if (input === null || input === void 0 ? void 0 : input.message) {
350
+ this.currentMessage = input.message;
351
+ }
352
+ if (input === null || input === void 0 ? void 0 : input.metadata) {
353
+ this.updateContext(input.metadata);
354
+ }
355
+ this.ensureActivePhase();
356
+ if (this.interactive) {
357
+ var _this_intervalId_unref, _this_intervalId;
358
+ this.stream.write('\x1B[?25l');
359
+ this.render();
360
+ this.intervalId = setInterval(function() {
361
+ if (_this.finalState) {
362
+ return;
363
+ }
364
+ _this.spinnerIndex = (_this.spinnerIndex + 1) % SPINNER_FRAMES.length;
365
+ _this.render();
366
+ }, 120);
367
+ (_this_intervalId_unref = (_this_intervalId = this.intervalId).unref) === null || _this_intervalId_unref === void 0 ? void 0 : _this_intervalId_unref.call(_this_intervalId);
368
+ return;
369
+ }
370
+ console.log("".concat(this.title, ": ").concat(this.currentMessage));
371
+ }
372
+ },
373
+ {
374
+ key: "complete",
375
+ value: function complete(result) {
376
+ this.finalState = 'complete';
377
+ this.currentMessage = 'Publication workflow completed';
378
+ var _result_collectionTransactionSignature;
379
+ this.updateContext({
380
+ androidPackage: result.publicationBundle.release.androidPackage,
381
+ versionName: result.publicationBundle.release.versionName,
382
+ releaseId: result.releaseId,
383
+ publicationSessionId: result.publicationSessionId,
384
+ ingestionSessionId: result.ingestionSessionId,
385
+ mintAddress: result.releaseMintAddress,
386
+ transactionSignature: (_result_collectionTransactionSignature = result.collectionTransactionSignature) !== null && _result_collectionTransactionSignature !== void 0 ? _result_collectionTransactionSignature : result.releaseTransactionSignature,
387
+ hubspotTicketId: result.hubspotTicketId,
388
+ requestUniqueId: result.attestationRequestUniqueId
389
+ });
390
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
391
+ try {
392
+ for(var _iterator = PHASES[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
393
+ var key = _step.value.key;
394
+ this.phaseStates[key] = 'complete';
395
+ this.phaseProgress[key] = 1;
396
+ }
397
+ } catch (err) {
398
+ _didIteratorError = true;
399
+ _iteratorError = err;
400
+ } finally{
401
+ try {
402
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
403
+ _iterator.return();
404
+ }
405
+ } finally{
406
+ if (_didIteratorError) {
407
+ throw _iteratorError;
408
+ }
409
+ }
410
+ }
411
+ this.pushRecentEvent('Publication workflow completed');
412
+ this.stopAndRenderFinalState();
413
+ }
414
+ },
415
+ {
416
+ key: "fail",
417
+ value: function fail(error) {
418
+ this.finalState = 'failed';
419
+ if (_instanceof(error, Error) && error.message.trim().length > 0) {
420
+ this.pushRecentEvent("Failed: ".concat(error.message.trim()));
421
+ }
422
+ this.stopAndRenderFinalState();
423
+ }
424
+ },
425
+ {
426
+ key: "handleEvent",
427
+ value: function handleEvent(level, message, metadata) {
428
+ this.currentMessage = message.trim().length > 0 ? message : this.currentMessage;
429
+ if (metadata) {
430
+ this.updateContext(metadata);
431
+ this.updatePhaseState(metadata);
432
+ this.applyStageHint(metadata);
433
+ this.emitVerboseMetadata(metadata);
434
+ }
435
+ if (level === 'warn') {
436
+ this.pushRecentEvent("Warning: ".concat(message));
437
+ } else if (level === 'info' && this.readString(metadata, 'status') === 'complete') {
438
+ this.pushRecentEvent(message);
439
+ }
440
+ if (this.interactive) {
441
+ this.render();
442
+ return;
443
+ }
444
+ if (level === 'debug') {
445
+ return;
446
+ }
447
+ console.log(this.buildLogLine(level, message, metadata));
448
+ }
449
+ },
450
+ {
451
+ key: "updatePhaseState",
452
+ value: function updatePhaseState(metadata) {
453
+ var step = this.readString(metadata, 'step');
454
+ if (!step) {
455
+ return;
456
+ }
457
+ var phaseKey = STEP_TO_PHASE[step];
458
+ if (!phaseKey) {
459
+ return;
460
+ }
461
+ var phaseIndex = this.getPhaseIndex(phaseKey);
462
+ for(var index = 0; index < phaseIndex; index += 1){
463
+ this.phaseStates[PHASES[index].key] = 'complete';
464
+ this.phaseProgress[PHASES[index].key] = 1;
465
+ }
466
+ if (this.phaseStates[phaseKey] !== 'complete') {
467
+ this.phaseStates[phaseKey] = 'active';
468
+ }
469
+ var status = this.readString(metadata, 'status');
470
+ var resolvedProgress = this.resolvePhaseProgress(step, metadata, status);
471
+ if (resolvedProgress !== undefined) {
472
+ this.phaseProgress[phaseKey] = Math.max(this.phaseProgress[phaseKey], resolvedProgress);
473
+ }
474
+ if (status === 'complete' && PHASE_FINAL_STEPS[phaseKey].includes(step)) {
475
+ this.phaseStates[phaseKey] = 'complete';
476
+ this.phaseProgress[phaseKey] = 1;
477
+ this.ensureActivePhase();
478
+ }
479
+ }
480
+ },
481
+ {
482
+ key: "resolvePhaseProgress",
483
+ value: function resolvePhaseProgress(step, metadata, status) {
484
+ var range = STEP_PROGRESS_RANGES[step];
485
+ var _this_readProgress;
486
+ var explicitProgress = (_this_readProgress = this.readProgress(metadata, 'stepProgress')) !== null && _this_readProgress !== void 0 ? _this_readProgress : this.readByteProgress(metadata);
487
+ if (status === 'complete') {
488
+ var _range_end;
489
+ return (_range_end = range === null || range === void 0 ? void 0 : range.end) !== null && _range_end !== void 0 ? _range_end : 1;
490
+ }
491
+ if (!range) {
492
+ return explicitProgress;
493
+ }
494
+ if (explicitProgress !== undefined) {
495
+ return this.interpolateProgress(range, explicitProgress);
496
+ }
497
+ if (status === 'running') {
498
+ return this.interpolateProgress(range, DEFAULT_RUNNING_STEP_PROGRESS);
499
+ }
500
+ return undefined;
501
+ }
502
+ },
503
+ {
504
+ key: "interpolateProgress",
505
+ value: function interpolateProgress(range, progress) {
506
+ var clampedProgress = Math.max(0, Math.min(1, progress));
507
+ return range.start + (range.end - range.start) * clampedProgress;
508
+ }
509
+ },
510
+ {
511
+ key: "applyStageHint",
512
+ value: function applyStageHint(metadata) {
513
+ var stage = this.readString(metadata, 'stage');
514
+ if (!stage) {
515
+ return;
516
+ }
517
+ var completedPhases = STAGE_COMPLETED_PHASES[stage];
518
+ if (!completedPhases) {
519
+ return;
520
+ }
521
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
522
+ try {
523
+ for(var _iterator = completedPhases[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
524
+ var phaseKey = _step.value;
525
+ this.phaseStates[phaseKey] = 'complete';
526
+ this.phaseProgress[phaseKey] = 1;
527
+ }
528
+ } catch (err) {
529
+ _didIteratorError = true;
530
+ _iteratorError = err;
531
+ } finally{
532
+ try {
533
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
534
+ _iterator.return();
535
+ }
536
+ } finally{
537
+ if (_didIteratorError) {
538
+ throw _iteratorError;
539
+ }
540
+ }
541
+ }
542
+ this.ensureActivePhase();
543
+ }
544
+ },
545
+ {
546
+ key: "updateContext",
547
+ value: function updateContext(metadata) {
548
+ var sourceKind = this.readString(metadata, 'sourceKind');
549
+ if (sourceKind === 'apk-file' || sourceKind === 'apk-url' || sourceKind === 'resume') {
550
+ this.context.sourceKind = sourceKind;
551
+ }
552
+ var fileName = this.readString(metadata, 'fileName');
553
+ if (fileName) {
554
+ this.context.fileName = fileName;
555
+ }
556
+ var apkUrl = this.readString(metadata, 'apkUrl');
557
+ if (apkUrl) {
558
+ this.context.apkUrl = apkUrl;
559
+ }
560
+ var sourceReleaseId = this.readString(metadata, 'sourceReleaseId');
561
+ if (sourceReleaseId) {
562
+ this.context.sourceReleaseId = sourceReleaseId;
563
+ }
564
+ var androidPackage = this.readString(metadata, 'androidPackage');
565
+ if (androidPackage) {
566
+ this.context.androidPackage = androidPackage;
567
+ }
568
+ var versionName = this.readString(metadata, 'versionName');
569
+ if (versionName) {
570
+ this.context.versionName = versionName;
571
+ }
572
+ var releaseId = this.readString(metadata, 'releaseId');
573
+ if (releaseId) {
574
+ this.context.releaseId = releaseId;
575
+ }
576
+ var _this_readString;
577
+ var publicationSessionId = (_this_readString = this.readString(metadata, 'publicationSessionId')) !== null && _this_readString !== void 0 ? _this_readString : this.readString(metadata, 'sessionId');
578
+ if (publicationSessionId) {
579
+ this.context.publicationSessionId = publicationSessionId;
580
+ }
581
+ var ingestionSessionId = this.readString(metadata, 'ingestionSessionId');
582
+ if (ingestionSessionId) {
583
+ this.context.ingestionSessionId = ingestionSessionId;
584
+ }
585
+ var mintAddress = this.readString(metadata, 'mintAddress');
586
+ if (mintAddress) {
587
+ this.context.mintAddress = mintAddress;
588
+ }
589
+ var transactionSignature = this.readString(metadata, 'transactionSignature');
590
+ if (transactionSignature) {
591
+ this.context.transactionSignature = transactionSignature;
592
+ }
593
+ var hubspotTicketId = this.readString(metadata, 'hubspotTicketId');
594
+ if (hubspotTicketId) {
595
+ this.context.hubspotTicketId = hubspotTicketId;
596
+ }
597
+ var requestUniqueId = this.readString(metadata, 'requestUniqueId');
598
+ if (requestUniqueId) {
599
+ this.context.requestUniqueId = requestUniqueId;
600
+ }
601
+ var fileSize = this.readNumber(metadata, 'fileSize');
602
+ if (fileSize !== undefined) {
603
+ this.context.fileSize = fileSize;
604
+ }
605
+ var bytesUploaded = this.readNumber(metadata, 'bytesUploaded');
606
+ if (bytesUploaded !== undefined) {
607
+ this.context.bytesUploaded = bytesUploaded;
608
+ }
609
+ var _this_readNumber;
610
+ var bytesTotal = (_this_readNumber = this.readNumber(metadata, 'bytesTotal')) !== null && _this_readNumber !== void 0 ? _this_readNumber : this.readNumber(metadata, 'fileSize');
611
+ if (bytesTotal !== undefined) {
612
+ this.context.bytesTotal = bytesTotal;
613
+ }
614
+ var ingestionStatus = this.readString(metadata, 'ingestionStatus');
615
+ if (ingestionStatus) {
616
+ this.context.ingestionStatus = ingestionStatus;
617
+ }
618
+ var ingestionProgress = this.readNumber(metadata, 'ingestionProgress');
619
+ if (ingestionProgress !== undefined) {
620
+ this.context.ingestionProgress = Math.max(0, Math.min(100, ingestionProgress));
621
+ }
622
+ var ingestionStage = this.readString(metadata, 'ingestionStage');
623
+ if (ingestionStage) {
624
+ this.context.ingestionStage = ingestionStage;
625
+ }
626
+ var ingestionDetail = this.readString(metadata, 'ingestionDetail');
627
+ if (ingestionDetail) {
628
+ this.context.ingestionDetail = ingestionDetail;
629
+ }
630
+ var activeStep = this.readString(metadata, 'step');
631
+ if (activeStep) {
632
+ this.context.activeStep = activeStep;
633
+ }
634
+ }
635
+ },
636
+ {
637
+ key: "stopAndRenderFinalState",
638
+ value: function stopAndRenderFinalState() {
639
+ if (this.intervalId) {
640
+ clearInterval(this.intervalId);
641
+ this.intervalId = undefined;
642
+ }
643
+ if (this.interactive) {
644
+ this.render();
645
+ this.stream.write('\n');
646
+ this.stream.write('\x1B[?25h');
647
+ return;
648
+ }
649
+ var statusLabel = this.finalState === 'complete' ? 'completed' : 'failed';
650
+ console.log("".concat(this.title, ": ").concat(statusLabel));
651
+ }
652
+ },
653
+ {
654
+ key: "ensureActivePhase",
655
+ value: function ensureActivePhase() {
656
+ var _this = this;
657
+ if (this.finalState) {
658
+ return;
659
+ }
660
+ var activePhase = PHASES.find(function(param) {
661
+ var key = param.key;
662
+ return _this.phaseStates[key] === 'active';
663
+ });
664
+ if (activePhase) {
665
+ return;
666
+ }
667
+ var nextPendingPhase = PHASES.find(function(param) {
668
+ var key = param.key;
669
+ return _this.phaseStates[key] === 'pending';
670
+ });
671
+ if (nextPendingPhase) {
672
+ this.phaseStates[nextPendingPhase.key] = 'active';
673
+ }
674
+ }
675
+ },
676
+ {
677
+ key: "render",
678
+ value: function render() {
679
+ var lines = this.buildLines();
680
+ if (this.renderedLineCount > 0) {
681
+ readline.moveCursor(this.stream, 0, -(this.renderedLineCount - 1));
682
+ readline.cursorTo(this.stream, 0);
683
+ readline.clearScreenDown(this.stream);
684
+ }
685
+ this.stream.write(lines.join('\n'));
686
+ this.renderedLineCount = lines.length;
687
+ }
688
+ },
689
+ {
690
+ key: "buildLines",
691
+ value: function buildLines() {
692
+ var _this = this;
693
+ var completedCount = PHASES.filter(function(param) {
694
+ var key = param.key;
695
+ return _this.phaseStates[key] === 'complete';
696
+ }).length;
697
+ var activePhase = this.getActivePhaseKey();
698
+ var phaseLabel = activePhase && this.finalState !== 'complete' ? PHASES[this.getPhaseIndex(activePhase)].label : 'Complete';
699
+ var percent = this.getProgressPercent();
700
+ var bar = this.buildProgressBar(percent);
701
+ var statusToken = this.getStatusToken();
702
+ var lines = [
703
+ this.fitToWidth("".concat(this.title, " [").concat(statusToken, "] ").concat(completedCount, "/").concat(PHASES.length, " complete | ").concat(phaseLabel)),
704
+ this.fitToWidth("".concat(bar, " ").concat(Math.round(percent * 100), "%")),
705
+ this.fitToWidth("Working: ".concat(this.currentMessage))
706
+ ].concat(_to_consumable_array(this.buildDetailLines()));
707
+ return lines;
708
+ }
709
+ },
710
+ {
711
+ key: "buildDetailLines",
712
+ value: function buildDetailLines() {
713
+ var targetTokens = [
714
+ this.context.androidPackage ? "app ".concat(this.truncateMiddle(this.context.androidPackage, 42)) : null,
715
+ this.context.versionName ? "version ".concat(this.truncateMiddle(this.context.versionName, 24)) : null,
716
+ this.context.fileName ? "file ".concat(this.truncateMiddle(this.context.fileName, 26)) : null,
717
+ this.context.apkUrl ? "url ".concat(this.truncateMiddle(this.compactUrl(this.context.apkUrl), 32)) : null,
718
+ this.context.sourceReleaseId ? "source ".concat(this.compactIdentifier(this.context.sourceReleaseId)) : null
719
+ ].filter(function(token) {
720
+ return token !== null;
721
+ });
722
+ var lines = [];
723
+ if (targetTokens.length > 0) {
724
+ lines.push(this.fitToWidth("Target: ".concat(targetTokens.join(' | '))));
725
+ }
726
+ var uploadLine = this.buildUploadLine();
727
+ if (uploadLine) {
728
+ lines.push(this.fitToWidth(uploadLine));
729
+ }
730
+ var ingestionLine = this.buildIngestionLine();
731
+ if (ingestionLine) {
732
+ lines.push(this.fitToWidth(ingestionLine));
733
+ }
734
+ if (this.recentEvents.length > 0) {
735
+ lines.push(this.fitToWidth("Recent: ".concat(this.recentEvents[this.recentEvents.length - 1])));
736
+ }
737
+ return lines;
738
+ }
739
+ },
740
+ {
741
+ key: "buildProgressBar",
742
+ value: function buildProgressBar(percent) {
743
+ var _this_stream_columns;
744
+ var columns = (_this_stream_columns = this.stream.columns) !== null && _this_stream_columns !== void 0 ? _this_stream_columns : 100;
745
+ var barWidth = Math.min(32, Math.max(10, columns - 44));
746
+ var filled = Math.max(0, Math.min(barWidth, Math.round(percent * barWidth)));
747
+ var empty = Math.max(0, barWidth - filled);
748
+ return "[".concat('#'.repeat(filled)).concat('-'.repeat(empty), "]");
749
+ }
750
+ },
751
+ {
752
+ key: "buildUploadLine",
753
+ value: function buildUploadLine() {
754
+ if (this.context.bytesTotal === undefined || this.context.bytesUploaded === undefined) {
755
+ return null;
756
+ }
757
+ var activeStep = this.context.activeStep;
758
+ if (activeStep !== 'source.upload' && this.finalState !== 'complete') {
759
+ return null;
760
+ }
761
+ var ratio = this.context.bytesTotal > 0 ? this.context.bytesUploaded / this.context.bytesTotal : 1;
762
+ return "Upload: ".concat(this.formatBytes(this.context.bytesUploaded), " / ").concat(this.formatBytes(this.context.bytesTotal), " (").concat(Math.round(Math.max(0, Math.min(1, ratio)) * 100), "%)");
763
+ }
764
+ },
765
+ {
766
+ key: "buildIngestionLine",
767
+ value: function buildIngestionLine() {
768
+ if (!this.context.ingestionStatus && !this.context.ingestionStage && this.context.ingestionProgress === undefined) {
769
+ return null;
770
+ }
771
+ var activePhase = this.getActivePhaseKey();
772
+ if (activePhase !== 'ingestion' && this.finalState !== 'complete') {
773
+ return null;
774
+ }
775
+ var _this_context_ingestionDetail, _ref;
776
+ var detail = (_ref = (_this_context_ingestionDetail = this.context.ingestionDetail) !== null && _this_context_ingestionDetail !== void 0 ? _this_context_ingestionDetail : this.context.ingestionStage) !== null && _ref !== void 0 ? _ref : this.context.ingestionStatus;
777
+ var progress = this.context.ingestionProgress === undefined ? null : "".concat(Math.round(this.context.ingestionProgress), "%");
778
+ if (detail && progress) {
779
+ return "Ingestion: ".concat(detail, " (").concat(progress, ")");
780
+ }
781
+ if (detail) {
782
+ return "Ingestion: ".concat(detail);
783
+ }
784
+ if (progress) {
785
+ return "Ingestion: ".concat(progress);
786
+ }
787
+ return null;
788
+ }
789
+ },
790
+ {
791
+ key: "getProgressPercent",
792
+ value: function getProgressPercent() {
793
+ var _this = this;
794
+ if (this.finalState === 'complete') {
795
+ return 1;
796
+ }
797
+ var weights = this.getPhaseWeights();
798
+ var progress = PHASES.reduce(function(total, param) {
799
+ var key = param.key;
800
+ var phaseProgress = Math.max(0, Math.min(1, _this.phaseProgress[key]));
801
+ return total + phaseProgress * weights[key];
802
+ }, 0);
803
+ return Math.max(0, Math.min(0.99, progress));
804
+ }
805
+ },
806
+ {
807
+ key: "getStatusToken",
808
+ value: function getStatusToken() {
809
+ if (this.finalState === 'complete') {
810
+ return 'done';
811
+ }
812
+ if (this.finalState === 'failed') {
813
+ return 'fail';
814
+ }
815
+ return SPINNER_FRAMES[this.spinnerIndex];
816
+ }
817
+ },
818
+ {
819
+ key: "getActivePhaseKey",
820
+ value: function getActivePhaseKey() {
821
+ var _this = this;
822
+ var activePhase = PHASES.find(function(param) {
823
+ var key = param.key;
824
+ return _this.phaseStates[key] === 'active';
825
+ });
826
+ if (activePhase) {
827
+ return activePhase.key;
828
+ }
829
+ var pendingPhase = PHASES.find(function(param) {
830
+ var key = param.key;
831
+ return _this.phaseStates[key] === 'pending';
832
+ });
833
+ return pendingPhase === null || pendingPhase === void 0 ? void 0 : pendingPhase.key;
834
+ }
835
+ },
836
+ {
837
+ key: "getPhaseIndex",
838
+ value: function getPhaseIndex(phaseKey) {
839
+ return PHASES.findIndex(function(param) {
840
+ var key = param.key;
841
+ return key === phaseKey;
842
+ });
843
+ }
844
+ },
845
+ {
846
+ key: "emitVerboseMetadata",
847
+ value: function emitVerboseMetadata(metadata) {
848
+ if (!this.verbose) {
849
+ return;
850
+ }
851
+ var lines = this.buildVerboseMetadataLines(metadata);
852
+ if (lines.length === 0) {
853
+ return;
854
+ }
855
+ if (this.interactive && this.renderedLineCount > 0) {
856
+ readline.moveCursor(this.stream, 0, -(this.renderedLineCount - 1));
857
+ readline.cursorTo(this.stream, 0);
858
+ readline.clearScreenDown(this.stream);
859
+ this.renderedLineCount = 0;
860
+ }
861
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
862
+ try {
863
+ for(var _iterator = lines[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
864
+ var line = _step.value;
865
+ this.stream.write("".concat(line, "\n"));
866
+ }
867
+ } catch (err) {
868
+ _didIteratorError = true;
869
+ _iteratorError = err;
870
+ } finally{
871
+ try {
872
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
873
+ _iterator.return();
874
+ }
875
+ } finally{
876
+ if (_didIteratorError) {
877
+ throw _iteratorError;
878
+ }
879
+ }
880
+ }
881
+ }
882
+ },
883
+ {
884
+ key: "buildVerboseMetadataLines",
885
+ value: function buildVerboseMetadataLines(metadata) {
886
+ var lines = [];
887
+ var step = this.readString(metadata, 'step');
888
+ this.appendVerboseField(lines, 'releaseId', 'Release ID', this.readString(metadata, 'releaseId'));
889
+ var _this_readString;
890
+ this.appendVerboseField(lines, 'publicationSessionId', 'Publication session ID', (_this_readString = this.readString(metadata, 'publicationSessionId')) !== null && _this_readString !== void 0 ? _this_readString : this.readString(metadata, 'sessionId'));
891
+ this.appendVerboseField(lines, 'ingestionSessionId', 'Ingestion session ID', this.readString(metadata, 'ingestionSessionId'));
892
+ var transactionSignature = this.readString(metadata, 'transactionSignature');
893
+ if (transactionSignature) {
894
+ var transactionKey = step === 'verify.submit' ? 'collectionTransactionSignature' : 'releaseTransactionSignature';
895
+ var transactionLabel = step === 'verify.submit' ? 'Collection transaction signature' : 'Release transaction signature';
896
+ this.appendVerboseField(lines, transactionKey, transactionLabel, transactionSignature);
897
+ }
898
+ this.appendVerboseField(lines, 'attestationRequestUniqueId', 'Attestation request ID', this.readString(metadata, 'requestUniqueId'));
899
+ this.appendVerboseField(lines, 'ticketId', 'Ticket ID', this.readString(metadata, 'hubspotTicketId'));
900
+ return lines;
901
+ }
902
+ },
903
+ {
904
+ key: "appendVerboseField",
905
+ value: function appendVerboseField(lines, key, label, value) {
906
+ if (!value) {
907
+ return;
908
+ }
909
+ var previousValue = this.verboseValues.get(key);
910
+ if (previousValue === value) {
911
+ return;
912
+ }
913
+ this.verboseValues.set(key, value);
914
+ lines.push("".concat(VERBOSE_PREFIX, ": ").concat(label, ": ").concat(value));
915
+ }
916
+ },
917
+ {
918
+ key: "pushRecentEvent",
919
+ value: function pushRecentEvent(message) {
920
+ this.recentEvents.push(this.truncateMiddle(message.trim(), 96));
921
+ if (this.recentEvents.length > MAX_RECENT_EVENTS) {
922
+ this.recentEvents = this.recentEvents.slice(-MAX_RECENT_EVENTS);
923
+ }
924
+ }
925
+ },
926
+ {
927
+ key: "buildLogLine",
928
+ value: function buildLogLine(level, message, metadata) {
929
+ var step = this.readString(metadata, 'step');
930
+ var phaseKey = step ? STEP_TO_PHASE[step] : this.getActivePhaseKey();
931
+ var phaseIndex = phaseKey ? this.getPhaseIndex(phaseKey) + 1 : 0;
932
+ var phaseLabel = phaseKey ? PHASES[this.getPhaseIndex(phaseKey)].label : 'Publication workflow';
933
+ var prefix = level === 'warn' ? 'warning' : phaseIndex > 0 ? "".concat(phaseIndex, "/").concat(PHASES.length) : 'info';
934
+ return "".concat(prefix, " ").concat(phaseLabel, ": ").concat(message);
935
+ }
936
+ },
937
+ {
938
+ key: "compactIdentifier",
939
+ value: function compactIdentifier(value) {
940
+ return this.truncateMiddle(value, 18);
941
+ }
942
+ },
943
+ {
944
+ key: "getPhaseWeights",
945
+ value: function getPhaseWeights() {
946
+ var _this_context_sourceKind;
947
+ var profile = (_this_context_sourceKind = this.context.sourceKind) !== null && _this_context_sourceKind !== void 0 ? _this_context_sourceKind : this.context.apkUrl ? 'apk-url' : 'apk-file';
948
+ return PHASE_WEIGHT_PROFILES[profile];
949
+ }
950
+ },
951
+ {
952
+ key: "compactUrl",
953
+ value: function compactUrl(value) {
954
+ try {
955
+ var url = new URL(value);
956
+ var path = url.pathname === '/' ? '' : url.pathname;
957
+ return "".concat(url.host).concat(path);
958
+ } catch (e) {
959
+ return value;
960
+ }
961
+ }
962
+ },
963
+ {
964
+ key: "fitToWidth",
965
+ value: function fitToWidth(value) {
966
+ var _this_stream_columns;
967
+ var width = (_this_stream_columns = this.stream.columns) !== null && _this_stream_columns !== void 0 ? _this_stream_columns : 100;
968
+ if (width <= 3) {
969
+ return value.slice(0, Math.max(0, width));
970
+ }
971
+ return value.length <= width ? value : "".concat(value.slice(0, width - 3), "...");
972
+ }
973
+ },
974
+ {
975
+ key: "truncateMiddle",
976
+ value: function truncateMiddle(value, maxLength) {
977
+ if (value.length <= maxLength) {
978
+ return value;
979
+ }
980
+ if (maxLength <= 3) {
981
+ return value.slice(0, maxLength);
982
+ }
983
+ var startLength = Math.ceil((maxLength - 3) / 2);
984
+ var endLength = Math.floor((maxLength - 3) / 2);
985
+ return "".concat(value.slice(0, startLength), "...").concat(value.slice(-endLength));
986
+ }
987
+ },
988
+ {
989
+ key: "readString",
990
+ value: function readString(metadata, key) {
991
+ var value = metadata === null || metadata === void 0 ? void 0 : metadata[key];
992
+ return typeof value === 'string' && value.trim().length > 0 ? value.trim() : undefined;
993
+ }
994
+ },
995
+ {
996
+ key: "readNumber",
997
+ value: function readNumber(metadata, key) {
998
+ var value = metadata === null || metadata === void 0 ? void 0 : metadata[key];
999
+ return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
1000
+ }
1001
+ },
1002
+ {
1003
+ key: "readProgress",
1004
+ value: function readProgress(metadata, key) {
1005
+ var value = this.readNumber(metadata, key);
1006
+ if (value === undefined) {
1007
+ return undefined;
1008
+ }
1009
+ if (value > 1) {
1010
+ return Math.max(0, Math.min(1, value / 100));
1011
+ }
1012
+ return Math.max(0, Math.min(1, value));
1013
+ }
1014
+ },
1015
+ {
1016
+ key: "readByteProgress",
1017
+ value: function readByteProgress(metadata) {
1018
+ var bytesUploaded = this.readNumber(metadata, 'bytesUploaded');
1019
+ var _this_readNumber;
1020
+ var bytesTotal = (_this_readNumber = this.readNumber(metadata, 'bytesTotal')) !== null && _this_readNumber !== void 0 ? _this_readNumber : this.readNumber(metadata, 'fileSize');
1021
+ if (bytesUploaded === undefined || bytesTotal === undefined || bytesTotal <= 0) {
1022
+ return undefined;
1023
+ }
1024
+ return Math.max(0, Math.min(1, bytesUploaded / bytesTotal));
1025
+ }
1026
+ },
1027
+ {
1028
+ key: "formatBytes",
1029
+ value: function formatBytes(value) {
1030
+ if (value < 1024) {
1031
+ return "".concat(Math.round(value), " B");
1032
+ }
1033
+ var units = [
1034
+ 'KB',
1035
+ 'MB',
1036
+ 'GB',
1037
+ 'TB'
1038
+ ];
1039
+ var size = value;
1040
+ var unitIndex = -1;
1041
+ do {
1042
+ size /= 1024;
1043
+ unitIndex += 1;
1044
+ }while (size >= 1024 && unitIndex < units.length - 1);
1045
+ var digits = size >= 100 ? 0 : size >= 10 ? 1 : 2;
1046
+ return "".concat(size.toFixed(digits), " ").concat(units[unitIndex]);
1047
+ }
1048
+ }
1049
+ ]);
1050
+ return PublicationProgressReporter;
1051
+ }();