@solana-mobile/dapp-store-cli 0.3.0 → 0.4.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 (114) hide show
  1. package/lib/esm/CliUtils.js +105 -0
  2. package/lib/esm/CliUtils.js.map +1 -0
  3. package/lib/esm/commands/{validate.js → ValidateCommand.js} +4 -3
  4. package/lib/esm/commands/ValidateCommand.js.map +1 -0
  5. package/lib/esm/commands/create/{app.js → CreateCliApp.js} +10 -7
  6. package/lib/esm/commands/create/CreateCliApp.js.map +1 -0
  7. package/lib/esm/commands/create/{publisher.js → CreateCliPublisher.js} +10 -7
  8. package/lib/esm/commands/create/CreateCliPublisher.js.map +1 -0
  9. package/lib/esm/commands/create/{release.js → CreateCliRelease.js} +10 -7
  10. package/lib/esm/commands/create/CreateCliRelease.js.map +1 -0
  11. package/lib/esm/commands/create/index.js +3 -3
  12. package/lib/esm/commands/create/index.js.map +1 -1
  13. package/lib/esm/commands/index.js +1 -1
  14. package/lib/esm/commands/index.js.map +1 -1
  15. package/lib/esm/commands/publish/{remove.js → PublishCliRemove.js} +4 -3
  16. package/lib/esm/commands/publish/PublishCliRemove.js.map +1 -0
  17. package/lib/esm/commands/publish/{submit.js → PublishCliSubmit.js} +4 -3
  18. package/lib/esm/commands/publish/PublishCliSubmit.js.map +1 -0
  19. package/lib/esm/commands/publish/{support.js → PublishCliSupport.js} +4 -3
  20. package/lib/esm/commands/publish/PublishCliSupport.js.map +1 -0
  21. package/lib/esm/commands/publish/{update.js → PublishCliUpdate.js} +4 -3
  22. package/lib/esm/commands/publish/PublishCliUpdate.js.map +1 -0
  23. package/lib/esm/commands/publish/index.js +4 -4
  24. package/lib/esm/commands/publish/index.js.map +1 -1
  25. package/lib/esm/commands/scaffolding/{init.js → ScaffoldInit.js} +2 -2
  26. package/lib/esm/commands/scaffolding/ScaffoldInit.js.map +1 -0
  27. package/lib/esm/commands/scaffolding/index.js +1 -1
  28. package/lib/esm/commands/scaffolding/index.js.map +1 -1
  29. package/lib/esm/config/PublishDetails.js +178 -0
  30. package/lib/esm/config/PublishDetails.js.map +1 -0
  31. package/lib/esm/generated/config_obj.json +1 -1
  32. package/lib/esm/index.js +16 -16
  33. package/lib/esm/index.js.map +1 -1
  34. package/lib/esm/package.json +2 -2
  35. package/lib/types/{utils.d.ts → CliUtils.d.ts} +2 -11
  36. package/lib/types/CliUtils.d.ts.map +1 -0
  37. package/lib/types/commands/{validate.d.ts → ValidateCommand.d.ts} +1 -1
  38. package/lib/types/commands/ValidateCommand.d.ts.map +1 -0
  39. package/lib/types/commands/create/{app.d.ts → CreateCliApp.d.ts} +2 -2
  40. package/lib/types/commands/create/CreateCliApp.d.ts.map +1 -0
  41. package/lib/types/commands/create/{publisher.d.ts → CreateCliPublisher.d.ts} +1 -1
  42. package/lib/types/commands/create/CreateCliPublisher.d.ts.map +1 -0
  43. package/lib/types/commands/create/{release.d.ts → CreateCliRelease.d.ts} +2 -2
  44. package/lib/types/commands/create/CreateCliRelease.d.ts.map +1 -0
  45. package/lib/types/commands/create/index.d.ts +3 -3
  46. package/lib/types/commands/create/index.d.ts.map +1 -1
  47. package/lib/types/commands/index.d.ts +1 -1
  48. package/lib/types/commands/index.d.ts.map +1 -1
  49. package/lib/types/commands/publish/{remove.d.ts → PublishCliRemove.d.ts} +2 -2
  50. package/lib/types/commands/publish/PublishCliRemove.d.ts.map +1 -0
  51. package/lib/types/commands/publish/{submit.d.ts → PublishCliSubmit.d.ts} +2 -2
  52. package/lib/types/commands/publish/PublishCliSubmit.d.ts.map +1 -0
  53. package/lib/types/commands/publish/{support.d.ts → PublishCliSupport.d.ts} +2 -2
  54. package/lib/types/commands/publish/PublishCliSupport.d.ts.map +1 -0
  55. package/lib/types/commands/publish/{update.d.ts → PublishCliUpdate.d.ts} +2 -2
  56. package/lib/types/commands/publish/PublishCliUpdate.d.ts.map +1 -0
  57. package/lib/types/commands/publish/index.d.ts +4 -4
  58. package/lib/types/commands/publish/index.d.ts.map +1 -1
  59. package/lib/types/commands/scaffolding/{init.d.ts → ScaffoldInit.d.ts} +1 -1
  60. package/lib/types/commands/scaffolding/ScaffoldInit.d.ts.map +1 -0
  61. package/lib/types/commands/scaffolding/index.d.ts +1 -1
  62. package/lib/types/commands/scaffolding/index.d.ts.map +1 -1
  63. package/lib/types/config/PublishDetails.d.ts +17 -0
  64. package/lib/types/config/PublishDetails.d.ts.map +1 -0
  65. package/lib/types/upload/CachedStorageDriver.d.ts +3 -3
  66. package/lib/types/upload/CachedStorageDriver.d.ts.map +1 -1
  67. package/package.json +2 -2
  68. package/src/CliUtils.ts +135 -0
  69. package/src/commands/{validate.ts → ValidateCommand.ts} +3 -2
  70. package/src/commands/create/{app.ts → CreateCliApp.ts} +9 -8
  71. package/src/commands/create/{publisher.ts → CreateCliPublisher.ts} +9 -8
  72. package/src/commands/create/{release.ts → CreateCliRelease.ts} +9 -10
  73. package/src/commands/create/index.ts +3 -3
  74. package/src/commands/index.ts +1 -1
  75. package/src/commands/publish/{remove.ts → PublishCliRemove.ts} +3 -2
  76. package/src/commands/publish/{submit.ts → PublishCliSubmit.ts} +3 -2
  77. package/src/commands/publish/{support.ts → PublishCliSupport.ts} +3 -2
  78. package/src/commands/publish/{update.ts → PublishCliUpdate.ts} +3 -2
  79. package/src/commands/publish/index.ts +4 -4
  80. package/src/commands/scaffolding/{init.ts → ScaffoldInit.ts} +1 -1
  81. package/src/commands/scaffolding/index.ts +1 -1
  82. package/src/config/PublishDetails.ts +273 -0
  83. package/src/index.ts +18 -18
  84. package/src/prebuild_schema/publishing_source.yaml +6 -6
  85. package/README.md +0 -86
  86. package/lib/esm/commands/create/app.js.map +0 -1
  87. package/lib/esm/commands/create/publisher.js.map +0 -1
  88. package/lib/esm/commands/create/release.js.map +0 -1
  89. package/lib/esm/commands/publish/remove.js.map +0 -1
  90. package/lib/esm/commands/publish/submit.js.map +0 -1
  91. package/lib/esm/commands/publish/support.js.map +0 -1
  92. package/lib/esm/commands/publish/update.js.map +0 -1
  93. package/lib/esm/commands/scaffolding/init.js.map +0 -1
  94. package/lib/esm/commands/validate.js.map +0 -1
  95. package/lib/esm/config/index.js +0 -18
  96. package/lib/esm/config/index.js.map +0 -1
  97. package/lib/esm/utils.js +0 -238
  98. package/lib/esm/utils.js.map +0 -1
  99. package/lib/types/commands/create/app.d.ts.map +0 -1
  100. package/lib/types/commands/create/publisher.d.ts.map +0 -1
  101. package/lib/types/commands/create/release.d.ts.map +0 -1
  102. package/lib/types/commands/publish/remove.d.ts.map +0 -1
  103. package/lib/types/commands/publish/submit.d.ts.map +0 -1
  104. package/lib/types/commands/publish/support.d.ts.map +0 -1
  105. package/lib/types/commands/publish/update.d.ts.map +0 -1
  106. package/lib/types/commands/scaffolding/init.d.ts.map +0 -1
  107. package/lib/types/commands/validate.d.ts.map +0 -1
  108. package/lib/types/config/index.d.ts +0 -9
  109. package/lib/types/config/index.d.ts.map +0 -1
  110. package/lib/types/utils.d.ts.map +0 -1
  111. package/src/config/index.ts +0 -38
  112. package/src/generated/config_obj.json +0 -1
  113. package/src/generated/config_schema.json +0 -1
  114. package/src/utils.ts +0 -342
package/src/utils.ts DELETED
@@ -1,342 +0,0 @@
1
- import fs from "fs";
2
- import type { AndroidDetails, App, Publisher, Release, ReleaseJsonMetadata } from "@solana-mobile/dapp-store-publishing-tools";
3
- import type { Connection } from "@solana/web3.js";
4
- import { Keypair, PublicKey } from "@solana/web3.js";
5
- import type { CLIConfig } from "./config/index.js";
6
- import { getConfig } from "./config/index.js";
7
- import debugModule from "debug";
8
- import { dump } from "js-yaml";
9
- import * as util from "util";
10
- import { exec } from "child_process";
11
- import * as path from "path";
12
- import { BundlrStorageDriver, keypairIdentity, Metaplex, toMetaplexFile } from "@metaplex-foundation/js";
13
- import { imageSize } from "image-size";
14
- import updateNotifier from "update-notifier";
15
- import cliPackage from "./package.json" assert { type: "json" };
16
- import boxen from "boxen";
17
- import ver from "semver";
18
-
19
- import { CachedStorageDriver } from "./upload/CachedStorageDriver.js";
20
-
21
- const runImgSize = util.promisify(imageSize);
22
- const runExec = util.promisify(exec);
23
-
24
- export class Constants {
25
- static CLI_VERSION = "0.3.0";
26
- static CONFIG_FILE_NAME = "config.yaml";
27
- }
28
-
29
- export const debug = debugModule("CLI");
30
-
31
- export const checkForSelfUpdate = async () => {
32
- const notifier = updateNotifier({ pkg: cliPackage });
33
- const updateInfo = await notifier.fetchInfo();
34
-
35
- const latestVer = new ver.SemVer(updateInfo.latest);
36
- const currentVer = new ver.SemVer(updateInfo.current);
37
-
38
- if (latestVer.major > currentVer.major || latestVer.minor > currentVer.minor) {
39
- throw new Error("Please update to the latest version of the dApp Store CLI before proceeding.");
40
- }
41
- };
42
-
43
- export const checkMintedStatus = async (conn: Connection, pubAddr: string, appAddr: string, releaseAddr: string) => {
44
- const results = await conn.getMultipleAccountsInfo([
45
- new PublicKey(pubAddr),
46
- new PublicKey(appAddr),
47
- new PublicKey(releaseAddr),
48
- ]);
49
-
50
- const rentAccounts = results.filter((item) => !(item == undefined) && item?.lamports > 0);
51
- if (rentAccounts?.length != 3) {
52
- throw new Error("Please ensure you have minted all of your NFTs before submitting to the Solana Mobile dApp publisher portal.");
53
- }
54
- };
55
-
56
- export const parseKeypair = (pathToKeypairFile: string) => {
57
- try {
58
- const keypairFile = fs.readFileSync(pathToKeypairFile, "utf-8");
59
- return Keypair.fromSecretKey(Buffer.from(JSON.parse(keypairFile)));
60
- } catch (e) {
61
- console.error(
62
- `Something went wrong when attempting to retrieve the keypair at ${pathToKeypairFile}`
63
- );
64
- }
65
- };
66
-
67
- const AaptPrefixes = {
68
- quoteRegex: "'(.*?)'",
69
- quoteNonLazyRegex: "'(.*)'",
70
- packagePrefix: "package: name=",
71
- verCodePrefix: "versionCode=",
72
- verNamePrefix: "versionName=",
73
- sdkPrefix: "sdkVersion:",
74
- permissionPrefix: "uses-permission: name=",
75
- localePrefix: "locales: ",
76
- };
77
-
78
- export const getConfigWithChecks = async (
79
- buildToolsDir: string | null = null
80
- ): Promise<CLIConfig> => {
81
- const configFilePath = `${process.cwd()}/${Constants.CONFIG_FILE_NAME}`;
82
-
83
- const config = await getConfig(configFilePath);
84
-
85
- if (buildToolsDir && fs.lstatSync(buildToolsDir).isDirectory()) {
86
- // We validate that the config is going to have at least one installable asset
87
- const apkEntry = config.release.files.find(
88
- (asset: CLIConfig["release"]["files"][0]) => asset.purpose === "install"
89
- )!;
90
- const apkPath = path.join(process.cwd(), apkEntry?.uri);
91
- if (!fs.existsSync(apkPath)) {
92
- throw new Error("Invalid path to APK file.");
93
- }
94
-
95
- config.release.android_details = await getAndroidDetails(
96
- buildToolsDir,
97
- apkPath
98
- );
99
- }
100
-
101
- const publisherIcon = config.publisher.media?.find(
102
- (asset: any) => asset.purpose === "icon"
103
- )?.uri;
104
-
105
- if (publisherIcon) {
106
- const iconPath = path.join(process.cwd(), publisherIcon);
107
- await checkIconCompatibility(iconPath, "Publisher");
108
-
109
- const iconBuffer = await fs.promises.readFile(iconPath);
110
- config.publisher.icon = toMetaplexFile(iconBuffer, publisherIcon);
111
- }
112
-
113
- const appIcon = config.app.media?.find(
114
- (asset: any) => asset.purpose === "icon"
115
- )?.uri;
116
-
117
- if (appIcon) {
118
- const iconPath = path.join(process.cwd(), appIcon);
119
- await checkIconCompatibility(iconPath, "App");
120
-
121
- const iconBuffer = await fs.promises.readFile(iconPath);
122
- config.app.icon = toMetaplexFile(iconBuffer, appIcon);
123
- }
124
-
125
- const releaseIcon = config.release.media?.find(
126
- (asset: any) => asset.purpose === "icon"
127
- )?.uri;
128
-
129
- if (releaseIcon) {
130
- const iconPath = path.join(process.cwd(), releaseIcon);
131
- await checkIconCompatibility(iconPath, "Release");
132
- }
133
-
134
- if (!appIcon && !releaseIcon) {
135
- throw new Error("Please specify at least one media entry of type icon in your configuration file");
136
- }
137
-
138
- config.release.media.forEach((item: CLIConfig["release"]["media"][0]) => {
139
- const imagePath = path.join(process.cwd(), item.uri);
140
- if (!fs.existsSync(imagePath) || !checkImageExtension(imagePath)) {
141
- throw new Error(`Invalid media path or file type: ${item.uri}. Please ensure the file is a jpeg, png, or webp file.`)
142
- }
143
- });
144
-
145
- const baselineSize = Object.keys(config.release.catalog["en-US"]).length;
146
- Object.keys(config.release.catalog).forEach((locale) => {
147
- const size = Object.keys(config.release.catalog[locale]).length;
148
-
149
- if (size != baselineSize) {
150
- throw new Error("Please ensure you have included all localized strings for all locales in your configuration file.");
151
- }
152
- });
153
-
154
- return config;
155
- };
156
-
157
- const checkIconCompatibility = async (path: string, typeString: string) => {
158
- if (!fs.existsSync(path) || !checkImageExtension(path)) {
159
- throw new Error(`Please check the path to your ${typeString} icon and ensure the file is a jpeg, png, or webp file.`)
160
- }
161
-
162
- if (await checkIconDimensions(path)) {
163
- throw new Error("Icons must have square dimensions and be no greater than 512px by 512px.")
164
- }
165
- };
166
-
167
- const checkImageExtension = (uri: string): boolean => {
168
- const fileExt = path.extname(uri).toLowerCase();
169
- return (
170
- fileExt == ".png" ||
171
- fileExt == ".jpg" ||
172
- fileExt == ".jpeg" ||
173
- fileExt == ".webp"
174
- );
175
- };
176
-
177
- export const isDevnet = (rpcUrl: string): boolean => {
178
- return rpcUrl.indexOf("devnet") != -1;
179
- };
180
-
181
- export const isTestnet = (rpcUrl: string): boolean => {
182
- return rpcUrl.indexOf("testnet") != -1;
183
- };
184
-
185
- export const checkSubmissionNetwork = (rpcUrl: string) => {
186
- if (isDevnet(rpcUrl) || isTestnet(rpcUrl)) {
187
- throw new Error("It looks like you are attempting to submit a request with a devnet or testnet RPC endpoint. Please ensure that your NFTs are minted on mainnet beta, and re-run with a mainnet beta RPC endpoint.");
188
- }
189
- };
190
-
191
- export const generateNetworkSuffix = (rpcUrl: string): string => {
192
- let suffix = "";
193
-
194
- if (isDevnet(rpcUrl)) {
195
- suffix = "?cluster=devnet";
196
- } else if (isTestnet(rpcUrl)) {
197
- suffix = "?cluster=testnet";
198
- } else {
199
- suffix = "?cluster=mainnet";
200
- }
201
-
202
- return suffix;
203
- };
204
-
205
- export const showMessage = (
206
- titleMessage = "",
207
- contentMessage = "",
208
- type: "standard" | "error" | "warning" = "standard",
209
- ): string => {
210
- let color = "cyan";
211
- if (type == "error") {
212
- color = "redBright";
213
- } else if (type == "warning") {
214
- color = "yellow";
215
- }
216
-
217
- const msg = boxen(contentMessage, {
218
- title: titleMessage,
219
- padding: 1,
220
- margin: 1,
221
- borderStyle: 'single',
222
- borderColor: color,
223
- textAlignment: "left",
224
- titleAlignment: "center",
225
- });
226
-
227
- console.log(msg);
228
- return msg;
229
- };
230
-
231
- const checkIconDimensions = async (iconPath: string): Promise<boolean> => {
232
- const size = await runImgSize(iconPath);
233
-
234
- return size?.width != size?.height || (size?.width ?? 0) > 512;
235
- };
236
-
237
- const getAndroidDetails = async (
238
- aaptDir: string,
239
- apkPath: string
240
- ): Promise<AndroidDetails> => {
241
- const { stdout } = await runExec(`${aaptDir}/aapt2 dump badging ${apkPath}`);
242
-
243
- const appPackage = new RegExp(
244
- AaptPrefixes.packagePrefix + AaptPrefixes.quoteRegex
245
- ).exec(stdout);
246
- const versionCode = new RegExp(
247
- AaptPrefixes.verCodePrefix + AaptPrefixes.quoteRegex
248
- ).exec(stdout);
249
- const versionName = new RegExp(
250
- AaptPrefixes.verNamePrefix + AaptPrefixes.quoteRegex
251
- ).exec(stdout);
252
- const minSdk = new RegExp(
253
- AaptPrefixes.sdkPrefix + AaptPrefixes.quoteRegex
254
- ).exec(stdout);
255
- const permissions = new RegExp(
256
- AaptPrefixes.permissionPrefix + AaptPrefixes.quoteNonLazyRegex
257
- ).exec(stdout);
258
- const locales = new RegExp(
259
- AaptPrefixes.localePrefix + AaptPrefixes.quoteNonLazyRegex
260
- ).exec(stdout);
261
-
262
- let permissionArray = Array.from(permissions?.values() ?? []);
263
- if (permissionArray.length >= 2) {
264
- permissionArray = permissionArray.slice(1);
265
- }
266
-
267
- let localeArray = Array.from(locales?.values() ?? []);
268
- if (localeArray.length == 2) {
269
- const localesSrc = localeArray[1];
270
- localeArray = ["en-US"].concat(localesSrc.split("' '").slice(1));
271
- }
272
-
273
- return {
274
- android_package: appPackage?.[1] ?? "",
275
- min_sdk: parseInt(minSdk?.[1] ?? "0", 10),
276
- version_code: parseInt(versionCode?.[1] ?? "0", 10),
277
- version: versionName?.[1] ?? "0",
278
- permissions: permissionArray,
279
- locales: localeArray,
280
- };
281
- };
282
-
283
- type SaveToConfigArgs = {
284
- publisher?: Pick<Publisher, "address">;
285
- app?: Pick<App, "address">;
286
- release?: Pick<Release, "address">;
287
- };
288
-
289
- export const saveToConfig = async ({
290
- publisher,
291
- app,
292
- release,
293
- }: SaveToConfigArgs) => {
294
- const currentConfig = await getConfigWithChecks();
295
-
296
- delete currentConfig.publisher.icon;
297
- delete currentConfig.app.icon;
298
-
299
- const newConfig: CLIConfig = {
300
- publisher: {
301
- ...currentConfig.publisher,
302
- address: publisher?.address ?? currentConfig.publisher.address,
303
- },
304
- app: {
305
- ...currentConfig.app,
306
- address: app?.address ?? currentConfig.app.address,
307
- },
308
- release: {
309
- ...currentConfig.release,
310
- address: release?.address ?? currentConfig.release.address,
311
- },
312
- solana_mobile_dapp_publisher_portal:
313
- currentConfig.solana_mobile_dapp_publisher_portal,
314
- };
315
-
316
- // TODO(jon): Verify the contents of the YAML file
317
- fs.writeFileSync(`${process.cwd()}/${Constants.CONFIG_FILE_NAME}`, dump(newConfig));
318
- };
319
-
320
- export const getMetaplexInstance = (
321
- connection: Connection,
322
- keypair: Keypair
323
- ) => {
324
- const metaplex = Metaplex.make(connection).use(keypairIdentity(keypair));
325
- const isDevnet = connection.rpcEndpoint.includes("devnet");
326
-
327
- const bundlrStorageDriver = isDevnet
328
- ? new BundlrStorageDriver(metaplex, {
329
- address: "https://devnet.bundlr.network",
330
- providerUrl: "https://api.devnet.solana.com",
331
- })
332
- : new BundlrStorageDriver(metaplex);
333
-
334
- metaplex.storage().setDriver(
335
- new CachedStorageDriver(bundlrStorageDriver, {
336
- assetManifestPath: isDevnet
337
- ? "./.asset-manifest-devnet.json"
338
- : "./.asset-manifest.json",
339
- })
340
- );
341
- return metaplex;
342
- };