@hailer/app-sdk 2.0.0-beta-1 → 2.0.0-beta-2

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.
@@ -22,14 +22,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
25
  Object.defineProperty(exports, "__esModule", { value: true });
29
- const hailer_cli_1 = require("@hailer-oy/hailer-cli");
26
+ const cli_1 = require("@hailer/cli");
30
27
  const request = __importStar(require("request"));
31
28
  const fs_1 = require("fs");
32
- const minimal_password_prompt_1 = __importDefault(require("minimal-password-prompt"));
29
+ const minimal_password_prompt_1 = require("minimal-password-prompt");
33
30
  const util_1 = require("util");
34
31
  const readline_1 = require("readline");
35
32
  if (!process.env.EMAIL && !process.env.LOCAL) {
@@ -41,7 +38,7 @@ if (!process.env.EMAIL && !process.env.LOCAL) {
41
38
  }
42
39
  (async () => {
43
40
  let email = process.env.EMAIL;
44
- let password = process.env.LOCAL || await (0, minimal_password_prompt_1.default)('enter password for ' + email + ': ');
41
+ let password = process.env.LOCAL || await (0, minimal_password_prompt_1.prompt)('enter password for ' + email + ': ');
45
42
  // Market code
46
43
  const market = process.env.MARKET === 'true';
47
44
  const appPackageFile = process.argv[2];
@@ -65,137 +62,136 @@ if (!process.env.EMAIL && !process.env.LOCAL) {
65
62
  password = 'thispasswordshouldbestrongenough';
66
63
  host = 'http://localhost:1337';
67
64
  }
68
- const cli = new hailer_cli_1.Cli(host, email, password);
69
- if (!appPackageFile?.endsWith('.tgz')) {
70
- console.log('Failed getting .tgz file, found:', appPackageFile);
71
- process.exit(7);
72
- }
73
- cli.on('error', (error) => {
65
+ const cli = await cli_1.Client.create({ host, username: email, password }).catch((error) => {
74
66
  if (error.msg === 'Invalid Login Data') {
75
67
  console.log('Invalid username or password when logging into Hailer.');
76
- process.exit(8);
77
68
  }
78
- console.log('Hailer Cli Error:', error);
69
+ else {
70
+ console.log('Hailer Cli Error:', error);
71
+ }
72
+ process.exit(8);
79
73
  });
80
- cli.on('ready', async () => {
81
- const manifest = JSON.parse((0, fs_1.readFileSync)('./dist/manifest.json').toString());
82
- const content = (0, fs_1.readFileSync)(appPackageFile);
83
- const info = await cli.request('v2.core.init', [['network', 'networks', 'apps']], undefined);
84
- // Market code
85
- if (market) {
86
- // Check if version exist in manifest.json. If not, add empty version and let user fill it in
87
- if (!manifest.version) {
88
- manifest.version = '';
89
- manifest.versionDescription = '';
90
- // Convert the modified object back to JSON
91
- const updatedManifestContent = JSON.stringify(manifest, null, 2);
92
- // Write the updated JSON content back to manifest.json
93
- (0, fs_1.writeFileSync)('./public/manifest.json', updatedManifestContent, 'utf-8');
94
- console.log('');
95
- console.log('Please set version & versionDescription in file public/manifest.json! You have added MARKET=true in your publish string.');
96
- console.log('');
97
- process.exit(10);
98
- }
74
+ if (!appPackageFile?.endsWith('.tgz')) {
75
+ console.log('Failed getting .tgz file, found:', appPackageFile);
76
+ process.exit(7);
77
+ }
78
+ const manifest = JSON.parse((0, fs_1.readFileSync)('./dist/manifest.json').toString());
79
+ const content = (0, fs_1.readFileSync)(appPackageFile);
80
+ const info = await cli.request('v2.core.init', [['network', 'networks', 'apps']]);
81
+ // Market code
82
+ if (market) {
83
+ // Check if version exist in manifest.json. If not, add empty version and let user fill it in
84
+ if (!manifest.version) {
85
+ manifest.version = '';
86
+ manifest.versionDescription = '';
87
+ // Convert the modified object back to JSON
88
+ const updatedManifestContent = JSON.stringify(manifest, null, 2);
89
+ // Write the updated JSON content back to manifest.json
90
+ (0, fs_1.writeFileSync)('./public/manifest.json', updatedManifestContent, 'utf-8');
91
+ console.log('');
92
+ console.log('Please set version & versionDescription in file public/manifest.json! You have added MARKET=true in your publish string.');
93
+ console.log('');
94
+ process.exit(10);
99
95
  }
100
- const getAppById = (manifestAppId) => {
101
- for (const appMap of Object.values(info.apps)) {
102
- for (const [appId, app] of Object.entries(appMap)) {
103
- if (appId === manifestAppId) {
104
- return app;
105
- }
96
+ }
97
+ const getAppById = (manifestAppId) => {
98
+ for (const appMap of Object.values(info.apps)) {
99
+ for (const [appId, app] of Object.entries(appMap)) {
100
+ if (appId === manifestAppId) {
101
+ return app;
106
102
  }
107
103
  }
108
- return null;
109
- };
110
- const app = getAppById(manifest.appId);
111
- if (!app) {
112
- console.log('The app was not found using this user:', email);
113
- process.exit(2);
114
- }
115
- const personalApp = !app.cid;
116
- console.log('Publishing App');
117
- console.log(' Id:', manifest.appId);
118
- console.log(' Name:', app.name);
119
- if (personalApp) {
120
- console.log(' Workspace: any (personal app)');
121
- }
122
- else {
123
- console.log(' Workspace:', info.networks[app.cid]?.name, '(' + app.cid + ')');
124
- }
125
- console.log(' Environment:', host);
126
- console.log();
127
- // Market code
128
- if (market) {
129
- console.log(' Note: Also publishing app to Hailer market');
130
104
  }
131
- /** Default to publish (yes) */
132
- const promptOverwriteQuestion = () => {
133
- return new Promise(resolve => {
134
- const rl = (0, readline_1.createInterface)(process.stdin, process.stdout);
135
- rl.setPrompt('Overwrite the app? (Y/n): ');
136
- rl.prompt();
137
- rl.on('line', (line) => {
138
- if (line.trim().toLocaleLowerCase().startsWith('n')) {
139
- resolve(false);
140
- }
141
- else {
142
- resolve(true);
143
- }
144
- rl.close();
145
- });
146
- });
147
- };
148
- const shouldOverwrite = await promptOverwriteQuestion();
149
- if (!shouldOverwrite) {
150
- console.log('Aborted publishing app.');
151
- process.exit(0);
152
- }
153
- await new Promise((resolve, reject) => {
154
- request.post({
155
- uri: host + '/app/publish',
156
- headers: { hlrkey: cli.client.sessionKey },
157
- formData: {
158
- file: {
159
- value: content,
160
- options: {
161
- filename: appPackageFile,
162
- }
163
- },
164
- appId: manifest.appId,
165
- // Market code
166
- publishMarket: market.toString(),
105
+ return null;
106
+ };
107
+ const app = getAppById(manifest.appId);
108
+ if (!app) {
109
+ console.log('The app was not found using this user:', email);
110
+ process.exit(2);
111
+ }
112
+ const personalApp = !app.cid;
113
+ console.log('Publishing App');
114
+ console.log(' Id:', manifest.appId);
115
+ console.log(' Name:', app.name);
116
+ if (personalApp) {
117
+ console.log(' Workspace: any (personal app)');
118
+ }
119
+ else {
120
+ console.log(' Workspace:', info.networks[app.cid]?.name, '(' + app.cid + ')');
121
+ }
122
+ console.log(' Environment:', host);
123
+ console.log();
124
+ // Market code
125
+ if (market) {
126
+ console.log(' Note: Also publishing app to Hailer market');
127
+ }
128
+ /** Default to publish (yes) */
129
+ const promptOverwriteQuestion = () => {
130
+ return new Promise(resolve => {
131
+ const rl = (0, readline_1.createInterface)(process.stdin, process.stdout);
132
+ rl.setPrompt('Overwrite the app? (Y/n): ');
133
+ rl.prompt();
134
+ rl.on('line', (line) => {
135
+ if (line.trim().toLocaleLowerCase().startsWith('n')) {
136
+ resolve(false);
167
137
  }
168
- }, function (error, resp, body) {
169
- if (error) {
170
- console.log('Publish error uploading file:', error);
171
- process.exit(9);
138
+ else {
139
+ resolve(true);
172
140
  }
173
- let response;
174
- let infoMarket = '';
175
- try {
176
- response = JSON.parse(body);
177
- // Market code
178
- if (response.manifest && response.manifest.targetId) {
179
- infoMarket = 'Note! Use targetId in public/manifest.json file when creating the product in market!';
180
- // Write targetId to manifest.json
181
- manifest.targetId = response.manifest.targetId;
182
- // Convert the modified object back to JSON
183
- const updatedManifestContent = JSON.stringify(manifest, null, 2);
184
- // Write the updated JSON content back to manifest.json
185
- (0, fs_1.writeFileSync)('./public/manifest.json', updatedManifestContent, 'utf-8');
141
+ rl.close();
142
+ });
143
+ });
144
+ };
145
+ const shouldOverwrite = await promptOverwriteQuestion();
146
+ if (!shouldOverwrite) {
147
+ console.log('Aborted publishing app.');
148
+ process.exit(0);
149
+ }
150
+ await new Promise((resolve, reject) => {
151
+ request.post({
152
+ uri: host + '/app/publish',
153
+ headers: { hlrkey: cli.sessionKey },
154
+ formData: {
155
+ file: {
156
+ value: content,
157
+ options: {
158
+ filename: appPackageFile,
186
159
  }
160
+ },
161
+ appId: manifest.appId,
162
+ // Market code
163
+ publishMarket: market.toString(),
164
+ }
165
+ }, function (error, resp, body) {
166
+ if (error) {
167
+ console.log('Publish error uploading file:', error);
168
+ process.exit(9);
169
+ }
170
+ let response;
171
+ let infoMarket = '';
172
+ try {
173
+ response = JSON.parse(body);
174
+ // Market code
175
+ if (response.manifest && response.manifest.targetId) {
176
+ infoMarket = 'Note! Use targetId in public/manifest.json file when creating the product in market!';
177
+ // Write targetId to manifest.json
178
+ manifest.targetId = response.manifest.targetId;
179
+ // Convert the modified object back to JSON
180
+ const updatedManifestContent = JSON.stringify(manifest, null, 2);
181
+ // Write the updated JSON content back to manifest.json
182
+ (0, fs_1.writeFileSync)('./public/manifest.json', updatedManifestContent, 'utf-8');
187
183
  }
188
- catch (error) {
189
- // ingore
190
- }
191
- console.log('App info:', (0, util_1.inspect)(response, { depth: 10, colors: true }));
192
- console.log();
193
- console.log(infoMarket);
194
- console.log();
195
- console.log('Published successfully!');
196
- resolve();
197
- });
184
+ }
185
+ catch (error) {
186
+ // ingore
187
+ }
188
+ console.log('App info:', (0, util_1.inspect)(response, { depth: 10, colors: true }));
189
+ console.log();
190
+ console.log(infoMarket);
191
+ console.log();
192
+ console.log('Published successfully!');
193
+ resolve();
198
194
  });
199
- cli.disconnect();
200
195
  });
196
+ cli.disconnect();
201
197
  })();
package/lib/types.js ADDED
@@ -0,0 +1,28 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
16
+ var HailerError = /** @class */ (function (_super) {
17
+ __extends(HailerError, _super);
18
+ function HailerError(error) {
19
+ var _this = _super.call(this) || this;
20
+ _this.code = error.code;
21
+ _this.msg = error.msg;
22
+ _this.debug = error.debug;
23
+ Object.setPrototypeOf(_this, HailerError.prototype);
24
+ return _this;
25
+ }
26
+ return HailerError;
27
+ }(Error));
28
+ export { HailerError };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hailer/app-sdk",
3
- "version": "2.0.0-beta-1",
3
+ "version": "2.0.0-beta-2",
4
4
  "description": "SDK for building Hailer Apps",
5
5
  "author": "",
6
6
  "license": "ISC",
@@ -19,9 +19,8 @@
19
19
  "docs": "typedoc --entryPointStrategy expand ./src && open-cli ./docs/index.html"
20
20
  },
21
21
  "dependencies": {
22
- "@hailer-oy/hailer-cli": "^1.1.6",
22
+ "@hailer/cli": "1.1.8",
23
23
  "@wishcore/wish-rpc": "0.6.11",
24
- "minimal-password-prompt": "1.1.0",
25
24
  "request": "2.88.2"
26
25
  },
27
26
  "devDependencies": {