@airmoney-degn/airmoney-cli 0.18.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -61,7 +61,7 @@ async function uploadCommand({ network, locationFolder, buttonImages, }) {
61
61
  buttonImages = 'assets';
62
62
  }
63
63
  (0, LogService_1.log)(buttonImages).white();
64
- const meta = (0, metadata_1.loadMetadata)();
64
+ const meta = await (0, metadata_1.loadMetadata)();
65
65
  if (!meta) {
66
66
  (0, LogService_1.log)('No metadata.json found. Aborting.').red();
67
67
  return;
package/dist/config.json CHANGED
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "0.18.0"
2
+ "version": "0.19.0"
3
3
  }
@@ -8,9 +8,12 @@ const express_1 = __importDefault(require("express"));
8
8
  const cors_1 = __importDefault(require("cors"));
9
9
  const server_1 = require("../../util/server");
10
10
  const LogService_1 = require("../log/LogService");
11
+ const AIRMONEY_SERVICE_PORT = 4040;
11
12
  class AirmoneyService {
12
13
  constructor(config) {
14
+ this.server = null;
13
15
  this.simulatorClient = null;
16
+ this.appName = null;
14
17
  this.config = config;
15
18
  this.app = (0, express_1.default)();
16
19
  this.setupMiddleware();
@@ -30,7 +33,7 @@ class AirmoneyService {
30
33
  switch (rpcReq.method) {
31
34
  case 'setImage':
32
35
  case 'setAnimate':
33
- event = (0, server_1.displayImage)(rpcReq, this.config.metadata?.name || '');
36
+ event = await (0, server_1.displayImage)(rpcReq, this.appName || '', this.config.appUrl);
34
37
  break;
35
38
  }
36
39
  if (simulator) {
@@ -59,10 +62,13 @@ class AirmoneyService {
59
62
  setSimulatorClient(simulatorClient) {
60
63
  this.simulatorClient = simulatorClient;
61
64
  }
65
+ setAppName(appName) {
66
+ this.appName = appName;
67
+ }
62
68
  async start() {
63
69
  return new Promise(resolve => {
64
- this.server = this.app.listen(this.config.port, () => {
65
- const url = `http://localhost:${this.config.port}`;
70
+ this.server = this.app.listen(AIRMONEY_SERVICE_PORT, () => {
71
+ const url = `http://localhost:${AIRMONEY_SERVICE_PORT}`;
66
72
  (0, LogService_1.log)(`Starting airmoney service server at ${url}`).green();
67
73
  resolve();
68
74
  });
@@ -13,8 +13,8 @@ const AirmoneyService_1 = require("../airmoney/AirmoneyService");
13
13
  const LogService_1 = require("../log/LogService");
14
14
  class ServeOrchestrator {
15
15
  constructor(config) {
16
+ this.metadata = null;
16
17
  this.config = config;
17
- this.metadata = (0, metadata_1.loadMetadata)();
18
18
  this.simulatorService = this.createSimulatorService();
19
19
  this.airmoneyService = this.createAirmoneyService();
20
20
  }
@@ -32,13 +32,16 @@ class ServeOrchestrator {
32
32
  }
33
33
  createAirmoneyService() {
34
34
  return new AirmoneyService_1.AirmoneyService({
35
- port: 4040,
36
- metadata: this.metadata ? { name: this.metadata.name } : undefined,
35
+ appUrl: this.config.appUrl,
37
36
  });
38
37
  }
39
38
  async start() {
40
39
  // Check for port conflicts first
41
40
  await PortManager_1.PortManager.checkPortConflicts();
41
+ // Load metadata (from remote URL if appUrl is provided, otherwise locally)
42
+ this.metadata = await (0, metadata_1.loadMetadata)('.', this.config.appUrl);
43
+ // Update AirmoneyService with loaded metadata
44
+ this.airmoneyService.setAppName(this.metadata?.name || null);
42
45
  // Validate metadata
43
46
  if (!this.metadata) {
44
47
  (0, LogService_1.log)('No metadata found. Skipping some possible checks.').white();
@@ -46,9 +49,9 @@ class ServeOrchestrator {
46
49
  // Start simulator service
47
50
  await this.simulatorService.start();
48
51
  // Set up callback to handle simulator client connections
49
- this.simulatorService.setOnClientConnected((client) => {
52
+ this.simulatorService.onClientConnectedCallback = client => {
50
53
  this.airmoneyService.setSimulatorClient(client);
51
- });
54
+ };
52
55
  // Start airmoney service
53
56
  await this.airmoneyService.start();
54
57
  // Start crypto service
@@ -11,8 +11,10 @@ const cors_1 = __importDefault(require("cors"));
11
11
  const open_1 = __importDefault(require("open"));
12
12
  const http_proxy_middleware_1 = require("http-proxy-middleware");
13
13
  const LogService_1 = require("../log/LogService");
14
+ const SIMULATOR_SERVICE_PORT = 4041;
14
15
  class BaseSimulatorService {
15
16
  constructor(config) {
17
+ this.server = null;
16
18
  this.simulatorClient = null;
17
19
  this.onClientConnectedCallback = null;
18
20
  this.config = config;
@@ -31,7 +33,7 @@ class BaseSimulatorService {
31
33
  return path_1.default.join(base, 'public', 'simulator');
32
34
  }
33
35
  setupWebSocket() {
34
- this.app.ws('/ws', (ws, req) => {
36
+ this.app.ws('/ws', (ws) => {
35
37
  this.simulatorClient = ws;
36
38
  // Notify callback about new connection
37
39
  if (this.onClientConnectedCallback) {
@@ -77,7 +79,7 @@ class BaseSimulatorService {
77
79
  }
78
80
  async openBrowser() {
79
81
  if (!this.config.noBrowser) {
80
- const url = `http://localhost:${this.config.port}/simulator`;
82
+ const url = `http://localhost:${SIMULATOR_SERVICE_PORT}/simulator`;
81
83
  try {
82
84
  await (0, open_1.default)(url);
83
85
  }
@@ -105,16 +107,13 @@ class BaseSimulatorService {
105
107
  }
106
108
  return false;
107
109
  }
108
- setOnClientConnected(callback) {
109
- this.onClientConnectedCallback = callback;
110
- }
111
110
  async start() {
112
111
  this.setupWebSocket();
113
112
  this.setupStaticFiles();
114
113
  this.setupProjectFiles();
115
114
  return new Promise(resolve => {
116
- this.server = this.app.listen(this.config.port, () => {
117
- const url = `http://localhost:${this.config.port}/simulator`;
115
+ this.server = this.app.listen(SIMULATOR_SERVICE_PORT, () => {
116
+ const url = `http://localhost:${SIMULATOR_SERVICE_PORT}/simulator`;
118
117
  (0, LogService_1.log)(`Starting simulator server at ${url}`).green();
119
118
  this.openBrowser();
120
119
  resolve();
@@ -11,7 +11,6 @@ class SimulatorService extends BaseSimulatorService_1.BaseSimulatorService {
11
11
  */
12
12
  static create(config = {}) {
13
13
  const defaultConfig = {
14
- port: 4041,
15
14
  noBrowser: false,
16
15
  ...config,
17
16
  };
package/dist/types.js CHANGED
@@ -3,11 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createPackage = createPackage;
4
4
  function createPackage(name, identifier) {
5
5
  return {
6
- name,
7
- identifier,
6
+ name: name,
7
+ identifier: identifier,
8
+ displayName: '',
8
9
  author: '',
9
- version: '0.1.0',
10
10
  maintainer: '',
11
11
  url: '',
12
+ themeColor: '',
13
+ version: '0.0.1',
14
+ whatsNew: '',
15
+ buildNumber: '',
16
+ commitHash: '',
17
+ buildDate: '',
12
18
  };
13
19
  }
@@ -39,14 +39,29 @@ exports.getPackageName = getPackageName;
39
39
  const fs = __importStar(require("fs"));
40
40
  const path = __importStar(require("path"));
41
41
  const LogService_1 = require("../service/log/LogService");
42
- function loadMetadata(projectPath = '.') {
42
+ const remote_1 = require("./remote");
43
+ async function loadMetadata(projectPath = '.', appUrl) {
43
44
  try {
44
- const filePath = path.join(projectPath, 'metadata.json');
45
- if (!fs.existsSync(filePath)) {
46
- (0, LogService_1.log)('Please run this command in Project directory').white();
47
- return null;
45
+ let raw;
46
+ if (appUrl) {
47
+ // Fetch from remote URL
48
+ const url = (0, remote_1.buildRemoteUrl)(appUrl, 'metadata.json');
49
+ const fetchedRaw = await (0, remote_1.fetchRemoteText)(url);
50
+ if (fetchedRaw === null) {
51
+ (0, LogService_1.log)('Error loading metadata from remote URL').red();
52
+ return null;
53
+ }
54
+ raw = fetchedRaw;
55
+ }
56
+ else {
57
+ // Read from local file system
58
+ const filePath = path.join(projectPath, 'metadata.json');
59
+ if (!fs.existsSync(filePath)) {
60
+ (0, LogService_1.log)('Please run this command in Project directory').white();
61
+ return null;
62
+ }
63
+ raw = fs.readFileSync(filePath, 'utf8');
48
64
  }
49
- const raw = fs.readFileSync(filePath, 'utf8');
50
65
  const data = JSON.parse(raw);
51
66
  return data;
52
67
  }
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ /**
3
+ * Utility functions for fetching resources from remote URLs
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.normalizeBaseUrl = normalizeBaseUrl;
7
+ exports.buildRemoteUrl = buildRemoteUrl;
8
+ exports.fetchRemoteText = fetchRemoteText;
9
+ exports.fetchRemoteBase64 = fetchRemoteBase64;
10
+ /**
11
+ * Normalizes a base URL by removing trailing slashes
12
+ */
13
+ function normalizeBaseUrl(url) {
14
+ return url.endsWith('/') ? url.slice(0, -1) : url;
15
+ }
16
+ /**
17
+ * Builds a URL by combining base URL with a path, encoding path segments
18
+ */
19
+ function buildRemoteUrl(baseUrl, path) {
20
+ const normalizedBase = normalizeBaseUrl(baseUrl);
21
+ const pathSegments = path.split('/').map(segment => encodeURIComponent(segment));
22
+ return `${normalizedBase}/${pathSegments.join('/')}`;
23
+ }
24
+ /**
25
+ * Fetches text content from a remote URL
26
+ */
27
+ async function fetchRemoteText(url) {
28
+ try {
29
+ const response = await fetch(url);
30
+ if (!response.ok) {
31
+ return null;
32
+ }
33
+ return await response.text();
34
+ }
35
+ catch (error) {
36
+ return null;
37
+ }
38
+ }
39
+ /**
40
+ * Fetches binary content from a remote URL and returns as base64 string
41
+ */
42
+ async function fetchRemoteBase64(url) {
43
+ try {
44
+ const response = await fetch(url);
45
+ if (!response.ok) {
46
+ return null;
47
+ }
48
+ const arrayBuffer = await response.arrayBuffer();
49
+ const buffer = Buffer.from(arrayBuffer);
50
+ return buffer.toString('base64');
51
+ }
52
+ catch (error) {
53
+ return null;
54
+ }
55
+ }
@@ -39,9 +39,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.displayImage = displayImage;
40
40
  const path_1 = __importDefault(require("path"));
41
41
  const fs = __importStar(require("fs"));
42
- function displayImage(request, appName) {
42
+ const remote_1 = require("./remote");
43
+ async function displayImage(request, appName, appUrl) {
43
44
  const f = request.params[0].replace(new RegExp(`^${appName}\\/`), '');
44
- let file = fs.readFileSync(f, { encoding: 'base64' });
45
+ let file;
46
+ if (appUrl) {
47
+ // Fetch from remote URL
48
+ const url = (0, remote_1.buildRemoteUrl)(appUrl, f);
49
+ const base64Content = await (0, remote_1.fetchRemoteBase64)(url);
50
+ if (base64Content === null) {
51
+ return null;
52
+ }
53
+ file = base64Content;
54
+ }
55
+ else {
56
+ // Read from local file system
57
+ file = fs.readFileSync(f, { encoding: 'base64' });
58
+ }
45
59
  const fileType = path_1.default.extname(f);
46
60
  let mime = '';
47
61
  switch (fileType.replace('.', '')) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@airmoney-degn/airmoney-cli",
3
- "version": "0.18.0",
3
+ "version": "0.19.0",
4
4
  "description": "airmoney-cli is a command-line interface tool designed to facilitate the development and management of decentralized applications (DApps) for Airmoney.",
5
5
  "publishConfig": {
6
6
  "access": "public"