@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.
- package/lib/app-sdk.js +2 -2
- package/lib/app-sdk.js.map +3 -3
- package/lib/constants.js +3 -0
- package/lib/hailer-api.js +147 -0
- package/lib/index.js +3 -0
- package/lib/modules/activity/kanban.js +88 -0
- package/lib/modules/activity.js +170 -0
- package/lib/modules/insight.js +73 -0
- package/lib/modules/network.js +74 -0
- package/lib/modules/process.js +104 -0
- package/lib/modules/public/form.js +117 -0
- package/lib/modules/public/insight.js +114 -0
- package/lib/modules/ui/activity.js +72 -0
- package/lib/modules/ui.js +10 -0
- package/lib/modules/user.js +133 -0
- package/lib/public-api.d.ts +16 -0
- package/lib/public-api.js +13 -0
- package/lib/tools/minimal-password-prompt.d.ts +1 -0
- package/lib/tools/minimal-password-prompt.js +50 -0
- package/lib/tools/publish.cjs +121 -125
- package/lib/types.js +28 -0
- package/package.json +2 -3
package/lib/tools/publish.cjs
CHANGED
|
@@ -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
|
|
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 =
|
|
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.
|
|
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 =
|
|
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
|
-
|
|
69
|
+
else {
|
|
70
|
+
console.log('Hailer Cli Error:', error);
|
|
71
|
+
}
|
|
72
|
+
process.exit(8);
|
|
79
73
|
});
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
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
|
-
|
|
169
|
-
|
|
170
|
-
console.log('Publish error uploading file:', error);
|
|
171
|
-
process.exit(9);
|
|
138
|
+
else {
|
|
139
|
+
resolve(true);
|
|
172
140
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
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-
|
|
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
|
|
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": {
|