@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
@@ -1,93 +0,0 @@
1
- function _class_call_check(instance, Constructor) {
2
- if (!(instance instanceof Constructor)) {
3
- throw new TypeError("Cannot call a class as a function");
4
- }
5
- }
6
- function _defineProperties(target, props) {
7
- for(var i = 0; i < props.length; i++){
8
- var descriptor = props[i];
9
- descriptor.enumerable = descriptor.enumerable || false;
10
- descriptor.configurable = true;
11
- if ("value" in descriptor) descriptor.writable = true;
12
- Object.defineProperty(target, descriptor.key, descriptor);
13
- }
14
- }
15
- function _create_class(Constructor, protoProps, staticProps) {
16
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
17
- if (staticProps) _defineProperties(Constructor, staticProps);
18
- return Constructor;
19
- }
20
- function _define_property(obj, key, value) {
21
- if (key in obj) {
22
- Object.defineProperty(obj, key, {
23
- value: value,
24
- enumerable: true,
25
- configurable: true,
26
- writable: true
27
- });
28
- } else {
29
- obj[key] = value;
30
- }
31
- return obj;
32
- }
33
- function _instanceof(left, right) {
34
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
35
- return !!right[Symbol.hasInstance](left);
36
- } else {
37
- return left instanceof right;
38
- }
39
- }
40
- export var S3StorageManager = /*#__PURE__*/ function() {
41
- "use strict";
42
- function S3StorageManager(envVars) {
43
- _class_call_check(this, S3StorageManager);
44
- _define_property(this, "envVars", void 0);
45
- _define_property(this, "_config", void 0);
46
- this.envVars = envVars;
47
- this._config = undefined;
48
- if (envVars.hasS3EnvArgs) {
49
- this._config = {
50
- accessKey: this.envVars.s3Config.accessKey,
51
- secretKey: this.envVars.s3Config.secretKey,
52
- bucketName: this.envVars.s3Config.bucketName,
53
- regionName: this.envVars.s3Config.regionName
54
- };
55
- }
56
- }
57
- _create_class(S3StorageManager, [
58
- {
59
- key: "hasS3Config",
60
- get: function get() {
61
- return this._config != undefined;
62
- }
63
- },
64
- {
65
- key: "s3Config",
66
- get: function get() {
67
- return this._config;
68
- }
69
- },
70
- {
71
- key: "parseCmdArg",
72
- value: function parseCmdArg(cmdArg) {
73
- if (!cmdArg || cmdArg == "") return;
74
- try {
75
- //This will overwrite any existing parameters already obtained from the .env file
76
- var parsedArray = JSON.parse("".concat(cmdArg));
77
- if (_instanceof(parsedArray, Array) && parsedArray[0] == "s3") {
78
- if (parsedArray.length != 5) throw new Error("Invalid parameters");
79
- this._config = {
80
- accessKey: parsedArray[1],
81
- secretKey: parsedArray[2],
82
- bucketName: parsedArray[3],
83
- regionName: parsedArray[4]
84
- };
85
- }
86
- } catch (e) {
87
- throw new Error("There was an error parsing your s3 parameters from the CLI. Please ensure they are formatted correctly.");
88
- }
89
- }
90
- }
91
- ]);
92
- return S3StorageManager;
93
- }();
@@ -1,2 +0,0 @@
1
- export * from "./EnvVariables.js";
2
- export * from "./S3StorageManager.js";
@@ -1 +0,0 @@
1
- {"publisher":{"name":"<<[REQUIRED] YOUR_PUBLISHER_NAME>>","website":"<<[REQUIRED] URL_OF_PUBLISHER_WEBSITE>>","email":"<<[REQUIRED] EMAIL_ADDRESS_TO_CONTACT_PUBLISHER>>","support_email":"<<[Optional] SUPPORT_EMAIL_ADDRESS_FOR_END_USERS>>"},"app":{"name":"<<[REQUIRED] APP_NAME>>","address":"","android_package":"<<[REQUIRED] ANDROID_PACKAGE_NAME>>","urls":{"license_url":"<<[REQUIRED] URL For App's T&C. Don't put placeholder urls.>>","copyright_url":"<<[REQUIRED] URL For App's Copyright. Don't put placeholder urls.>>","privacy_policy_url":"<<[REQUIRED] URL For App's Privacy Policy. Don't put placeholder urls.>>","website":"<<[REQUIRED] URL_OF_APP_WEBSITE>>"},"media":[{"purpose":"icon","uri":"<<[REQUIRED] RELATIVE_PATH_TO_APP_ICON>>"}]},"release":{"address":"","media":[{"purpose":"icon","uri":"<<[REQUIRED] RELATIVE_PATH_TO_RELEASE_ICON>>"},{"purpose":"banner","uri":"<<[REQUIRED] RELATIVE_PATH_TO_BANNER>>"},{"purpose":"featureGraphic","uri":"<<[Optional] RELATIVE_PATH_TO_FEATURE_GRAPHIC>>"},{"purpose":"screenshot","uri":"<<[REQUIRED] RELATIVE_PATH_TO_SCREENSHOT1>>"},{"purpose":"screenshot","uri":"<<[REQUIRED] RELATIVE_PATH_TO_SCREENSHOT2>>"},{"purpose":"screenshot","uri":"<<[REQUIRED] RELATIVE_PATH_TO_SCREENSHOT3>>"},{"purpose":"screenshot","uri":"<<[REQUIRED] RELATIVE_PATH_TO_SCREENSHOT4>>"},{"purpose":"video","uri":"<<[Optional] RELATIVE_PATH_TO_VIDEO1>>"}],"files":[{"purpose":"install","uri":"<<[REQUIRED] RELATIVE_PATH_TO_APK>>"}],"catalog":{"en-US":{"name":"<<[REQUIRED] APP_NAME>>","short_description":"<<[REQUIRED] SHORT_APP_DESCRIPTION>>","long_description":"<<[REQUIRED] LONG_APP_DESCRIPTION>>","new_in_version":"<<[REQUIRED] WHATS_NEW_IN_THIS_VERSION>>","saga_features":"<<[Optional.] ANY_FEATURES_ONLY_AVAILBLE_WHEN_RUNNING_ON_SAGA>>"}},"android_details":{"locales":["en-US","<Add more supported locales>"]}},"solana_mobile_dapp_publisher_portal":{"google_store_package":"<<[Optional] ANDROID_PACKAGE_NAME_OF_GOOGLE_PLAY_STORE_VERSION>>","testing_instructions":"<<[REQUIRED] TESTING_INSTRUCTIONS. Please provide any test account details if applicable>>","alpha_testers":[{"address":"<<Optional. genesis token wallet address>>","comment":"<<Optional. For internal use only>>"},{"address":"<<Optional. genesis token wallet address>>","comment":"<<Optional. For internal use only>>"}]}}
@@ -1 +0,0 @@
1
- {"type":"object","properties":{"publisher":{"type":"object","properties":{"name":{"type":"string"},"website":{"type":"string"},"email":{"type":"string"},"support_email":{"type":"string"}},"required":["name","website","email"]},"app":{"type":"object","properties":{"name":{"type":"string"},"address":{"type":"string"},"android_package":{"type":"string"},"urls":{"type":"object","properties":{"license_url":{"type":"string"},"copyright_url":{"type":"string"},"privacy_policy_url":{"type":"string"},"website":{"type":"string"}}},"media":{"type":"array","items":{"type":"object","properties":{"purpose":{"type":"string"},"uri":{"type":"string"}}}}}},"release":{"type":"object","properties":{"address":{"type":"string"},"media":{"type":"array","items":{"type":"object","properties":{"purpose":{"type":"string"},"uri":{"type":"string"}},"required":["purpose","uri"]}},"files":{"type":"array","items":{"type":"object","properties":{"purpose":{"type":"string"},"uri":{"type":"string"}}}},"catalog":{"type":"object","properties":{"en-US":{"type":"object","properties":{"name":{"type":"string"},"short_description":{"type":"string"},"long_description":{"type":"string"},"new_in_version":{"type":"string"},"saga_features":{"type":"string"}},"required":["short_description"]}}},"android_details":{"type":"object","properties":{"locales":{"type":"array","items":{"type":"string"}}}}}},"solana_mobile_dapp_publisher_portal":{"type":"object","properties":{"google_store_package":{"type":"string"},"testing_instructions":{"type":"string"},"alpha_testers":{"type":"array","items":{"type":"object","properties":{"address":{"type":"string"},"comment":{"type":"string"}},"required":["address","comment"]}}}}}}
@@ -1,64 +0,0 @@
1
- publisher:
2
- name: <<[REQUIRED] YOUR_PUBLISHER_NAME>>
3
- website: <<[REQUIRED] URL_OF_PUBLISHER_WEBSITE>>
4
- email: <<[REQUIRED] EMAIL_ADDRESS_TO_CONTACT_PUBLISHER>>
5
- support_email: <<[Optional] SUPPORT_EMAIL_ADDRESS_FOR_END_USERS>>
6
- app:
7
- name: <<[REQUIRED] APP_NAME>>
8
- address: ""
9
- android_package: <<[REQUIRED] ANDROID_PACKAGE_NAME>>
10
- urls:
11
- license_url: <<[REQUIRED] URL For App's T&C. Don't put placeholder urls.>>
12
- copyright_url: <<[REQUIRED] URL For App's Copyright. Don't put placeholder urls.>>
13
- privacy_policy_url: <<[REQUIRED] URL For App's Privacy Policy. Don't put placeholder urls.>>
14
- website: <<[REQUIRED] URL_OF_APP_WEBSITE>>
15
- media:
16
- - purpose: icon
17
- uri: <<[REQUIRED] RELATIVE_PATH_TO_APP_ICON>>
18
- release:
19
- address: ""
20
- media:
21
- - purpose: icon
22
- uri: <<[REQUIRED] RELATIVE_PATH_TO_RELEASE_ICON>>
23
- - purpose: banner
24
- uri: <<[REQUIRED] RELATIVE_PATH_TO_BANNER>>
25
- - purpose: featureGraphic
26
- uri: <<[Optional] RELATIVE_PATH_TO_FEATURE_GRAPHIC>>
27
- - purpose: screenshot
28
- uri: <<[REQUIRED] RELATIVE_PATH_TO_SCREENSHOT1>>
29
- - purpose: screenshot
30
- uri: <<[REQUIRED] RELATIVE_PATH_TO_SCREENSHOT2>>
31
- - purpose: screenshot
32
- uri: <<[REQUIRED] RELATIVE_PATH_TO_SCREENSHOT3>>
33
- - purpose: screenshot
34
- uri: <<[REQUIRED] RELATIVE_PATH_TO_SCREENSHOT4>>
35
- - purpose: video
36
- uri: <<[Optional] RELATIVE_PATH_TO_VIDEO1>>
37
- files:
38
- - purpose: install
39
- uri: <<[REQUIRED] RELATIVE_PATH_TO_APK>>
40
- catalog:
41
- en-US:
42
- name: >-
43
- <<[REQUIRED] APP_NAME>>
44
- short_description: >-
45
- <<[REQUIRED] SHORT_APP_DESCRIPTION>>
46
- long_description: >-
47
- <<[REQUIRED] LONG_APP_DESCRIPTION>>
48
- new_in_version: >-
49
- <<[REQUIRED] WHATS_NEW_IN_THIS_VERSION>>
50
- saga_features: >-
51
- <<[Optional.] ANY_FEATURES_ONLY_AVAILBLE_WHEN_RUNNING_ON_SAGA>>
52
- android_details:
53
- locales:
54
- - en-US
55
- - <Add more supported locales>
56
- solana_mobile_dapp_publisher_portal:
57
- google_store_package: <<[Optional] ANDROID_PACKAGE_NAME_OF_GOOGLE_PLAY_STORE_VERSION>>
58
- testing_instructions: >-
59
- <<[REQUIRED] TESTING_INSTRUCTIONS. Please provide any test account details if applicable>>
60
- alpha_testers:
61
- - address: <<Optional. genesis token wallet address>>
62
- comment: <<Optional. For internal use only>>
63
- - address: <<Optional. genesis token wallet address>>
64
- comment: <<Optional. For internal use only>>
@@ -1,25 +0,0 @@
1
- import fs from "fs";
2
- import yaml from "js-yaml";
3
- import generateSchema from "generate-schema";
4
- try {
5
- var yamlSrc = fs.readFileSync('./src/prebuild_schema/publishing_source.yaml', 'utf8');
6
- var convertedYaml = yaml.load(yamlSrc);
7
- fs.writeFileSync('./src/generated/config_obj.json', Buffer.from(JSON.stringify(convertedYaml)), 'utf-8');
8
- var schema = generateSchema.json('result', convertedYaml);
9
- // CLI 0.3.0: Adding requirement for `short_description` so validation will catch
10
- schema["properties"]["release"]["properties"]["catalog"]["properties"]["en-US"].required = [
11
- "short_description"
12
- ];
13
- schema["properties"]["publisher"].required = [
14
- "name",
15
- "website",
16
- "email"
17
- ];
18
- // Generator adds some keys/values we don't need & mess up validation
19
- delete schema.$schema;
20
- delete schema.title;
21
- var toWrite = Buffer.from(JSON.stringify(schema));
22
- fs.writeFileSync('./src/generated/config_schema.json', toWrite, 'utf-8');
23
- } catch (e) {
24
- console.log(":: Schema generation step failed ::");
25
- }
@@ -1,458 +0,0 @@
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 _class_call_check(instance, Constructor) {
39
- if (!(instance instanceof Constructor)) {
40
- throw new TypeError("Cannot call a class as a function");
41
- }
42
- }
43
- function _defineProperties(target, props) {
44
- for(var i = 0; i < props.length; i++){
45
- var descriptor = props[i];
46
- descriptor.enumerable = descriptor.enumerable || false;
47
- descriptor.configurable = true;
48
- if ("value" in descriptor) descriptor.writable = true;
49
- Object.defineProperty(target, descriptor.key, descriptor);
50
- }
51
- }
52
- function _create_class(Constructor, protoProps, staticProps) {
53
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
54
- if (staticProps) _defineProperties(Constructor, staticProps);
55
- return Constructor;
56
- }
57
- function _define_property(obj, key, value) {
58
- if (key in obj) {
59
- Object.defineProperty(obj, key, {
60
- value: value,
61
- enumerable: true,
62
- configurable: true,
63
- writable: true
64
- });
65
- } else {
66
- obj[key] = value;
67
- }
68
- return obj;
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;
97
- }
98
- }
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);
118
- }
119
- function _ts_generator(thisArg, body) {
120
- var f, y, t, _ = {
121
- label: 0,
122
- sent: function() {
123
- if (t[0] & 1) throw t[1];
124
- return t[1];
125
- },
126
- trys: [],
127
- ops: []
128
- }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
129
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
130
- return this;
131
- }), g;
132
- function verb(n) {
133
- return function(v) {
134
- return step([
135
- n,
136
- v
137
- ]);
138
- };
139
- }
140
- function step(op) {
141
- if (f) throw new TypeError("Generator is already executing.");
142
- while(g && (g = 0, op[0] && (_ = 0)), _)try {
143
- 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;
144
- if (y = 0, t) op = [
145
- op[0] & 2,
146
- t.value
147
- ];
148
- switch(op[0]){
149
- case 0:
150
- case 1:
151
- t = op;
152
- break;
153
- case 4:
154
- _.label++;
155
- return {
156
- value: op[1],
157
- done: false
158
- };
159
- case 5:
160
- _.label++;
161
- y = op[1];
162
- op = [
163
- 0
164
- ];
165
- continue;
166
- case 7:
167
- op = _.ops.pop();
168
- _.trys.pop();
169
- continue;
170
- default:
171
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
172
- _ = 0;
173
- continue;
174
- }
175
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
176
- _.label = op[1];
177
- break;
178
- }
179
- if (op[0] === 6 && _.label < t[1]) {
180
- _.label = t[1];
181
- t = op;
182
- break;
183
- }
184
- if (t && _.label < t[2]) {
185
- _.label = t[2];
186
- _.ops.push(op);
187
- break;
188
- }
189
- if (t[2]) _.ops.pop();
190
- _.trys.pop();
191
- continue;
192
- }
193
- op = body.call(thisArg, _);
194
- } catch (e) {
195
- op = [
196
- 6,
197
- e
198
- ];
199
- y = 0;
200
- } finally{
201
- f = t = 0;
202
- }
203
- if (op[0] & 5) throw op[1];
204
- return {
205
- value: op[0] ? op[1] : void 0,
206
- done: true
207
- };
208
- }
209
- }
210
- import fs from "fs";
211
- import path from "path";
212
- import { createHash } from "crypto";
213
- import { normalizePublicContentUrl } from "./contentGateway.js";
214
- // TODO(jon): We need to manage the removal / replacement of assets in the manifest
215
- export var CachedStorageDriver = /*#__PURE__*/ function() {
216
- "use strict";
217
- function CachedStorageDriver(storageDriver, param) {
218
- var assetManifestPath = param.assetManifestPath;
219
- _class_call_check(this, CachedStorageDriver);
220
- _define_property(this, "assetManifest", void 0);
221
- _define_property(this, "assetManifestPath", void 0);
222
- _define_property(this, "storageDriver", void 0);
223
- this.assetManifestPath = assetManifestPath;
224
- var _this_loadAssetManifest;
225
- this.assetManifest = (_this_loadAssetManifest = this.loadAssetManifest(assetManifestPath)) !== null && _this_loadAssetManifest !== void 0 ? _this_loadAssetManifest : {
226
- schema_version: CachedStorageDriver.SCHEMA_VERSION,
227
- assets: {}
228
- };
229
- this.storageDriver = storageDriver;
230
- }
231
- _create_class(CachedStorageDriver, [
232
- {
233
- key: "getUploadPrice",
234
- value: function getUploadPrice(bytes) {
235
- return _async_to_generator(function() {
236
- return _ts_generator(this, function(_state) {
237
- return [
238
- 2,
239
- this.storageDriver.getUploadPrice(bytes)
240
- ];
241
- });
242
- }).call(this);
243
- }
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
- },
330
- {
331
- key: "loadAssetManifest",
332
- value: function loadAssetManifest(filename) {
333
- try {
334
- return this.normalizeAssetManifest(JSON.parse(fs.readFileSync(this.resolveAssetManifestPath(filename), "utf-8")));
335
- } catch (error) {
336
- console.warn("Failed opening ".concat(filename, "; initializing with a blank asset manifest"));
337
- return;
338
- }
339
- }
340
- },
341
- {
342
- key: "uploadedAsset",
343
- value: function uploadedAsset(filename, param) {
344
- var sha256 = param.sha256;
345
- var _this_assetManifest_assets_filename;
346
- if (((_this_assetManifest_assets_filename = this.assetManifest.assets[filename]) === null || _this_assetManifest_assets_filename === void 0 ? void 0 : _this_assetManifest_assets_filename.sha256) === sha256) {
347
- return this.assetManifest.assets[filename];
348
- }
349
- return null;
350
- }
351
- },
352
- {
353
- key: "upload",
354
- value: function upload(file) {
355
- return _async_to_generator(function() {
356
- var hash, uploadedAsset, normalizedUri, error, message, uri;
357
- return _ts_generator(this, function(_state) {
358
- switch(_state.label){
359
- case 0:
360
- if (!(file.fileName === "inline.json")) return [
361
- 3,
362
- 2
363
- ];
364
- return [
365
- 4,
366
- this.storageDriver.upload(file)
367
- ];
368
- case 1:
369
- return [
370
- 2,
371
- normalizePublicContentUrl.apply(void 0, [
372
- _state.sent()
373
- ])
374
- ];
375
- case 2:
376
- hash = createHash("sha256").update(file.buffer).digest("base64");
377
- uploadedAsset = this.uploadedAsset(file.fileName, {
378
- sha256: hash
379
- });
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:
423
- console.log("Uploading ".concat(file.fileName));
424
- return [
425
- 4,
426
- this.storageDriver.upload(file)
427
- ];
428
- case 8:
429
- uri = normalizePublicContentUrl.apply(void 0, [
430
- _state.sent()
431
- ]);
432
- this.assetManifest.assets[file.fileName] = {
433
- path: file.fileName,
434
- sha256: hash,
435
- uri: uri
436
- };
437
- return [
438
- 4,
439
- this.writeAssetManifest()
440
- ];
441
- case 9:
442
- _state.sent();
443
- console.log("".concat(file.fileName, " uploaded at ").concat(uri));
444
- return [
445
- 2,
446
- uri
447
- ];
448
- }
449
- });
450
- }).call(this);
451
- }
452
- }
453
- ]);
454
- return CachedStorageDriver;
455
- }();
456
- // NOTE: this schema version is independent of the publishing JSON schema. It should be updated
457
- // when the AssetManifestSchema or Asset types are updated.
458
- _define_property(CachedStorageDriver, "SCHEMA_VERSION", "0.1");