@hailer/app-sdk 2.0.0-beta-3 → 2.0.0-beta-5

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 (42) hide show
  1. package/lib/app-sdk.js +2 -2
  2. package/lib/app-sdk.js.map +2 -2
  3. package/lib/modules/insight.d.ts +8 -0
  4. package/lib/modules/network.d.ts +14 -0
  5. package/lib/modules/process.d.ts +38 -0
  6. package/lib/modules/product-installed.d.ts +40 -0
  7. package/lib/modules/product-version.d.ts +38 -0
  8. package/lib/modules/public/product-version.d.ts +16 -0
  9. package/lib/modules/public/version.d.ts +16 -0
  10. package/lib/modules/version.d.ts +16 -0
  11. package/lib/src/constants.d.ts +7 -0
  12. package/lib/src/hailer-api.d.ts +92 -0
  13. package/lib/src/index.d.ts +2 -0
  14. package/lib/src/modules/activity/kanban.d.ts +36 -0
  15. package/lib/src/modules/activity.d.ts +83 -0
  16. package/lib/src/modules/app.d.ts +12 -0
  17. package/lib/src/modules/insight.d.ts +36 -0
  18. package/lib/src/modules/network.d.ts +14 -0
  19. package/lib/src/modules/permission.d.ts +9 -0
  20. package/lib/src/modules/process.d.ts +38 -0
  21. package/lib/src/modules/product-installed.d.ts +40 -0
  22. package/lib/src/modules/product-version.d.ts +16 -0
  23. package/lib/src/modules/product.d.ts +104 -0
  24. package/lib/src/modules/public/app.d.ts +17 -0
  25. package/lib/src/modules/public/form.d.ts +31 -0
  26. package/lib/src/modules/public/insight.d.ts +30 -0
  27. package/lib/src/modules/public/product-version.d.ts +16 -0
  28. package/lib/src/modules/public/product.d.ts +27 -0
  29. package/lib/src/modules/public.d.ts +22 -0
  30. package/lib/src/modules/ui/activity.d.ts +30 -0
  31. package/lib/src/modules/ui/files.d.ts +18 -0
  32. package/lib/src/modules/ui/snackbar.d.ts +18 -0
  33. package/lib/src/modules/ui.d.ts +17 -0
  34. package/lib/src/modules/user.d.ts +36 -0
  35. package/lib/src/modules/workflow.d.ts +24 -0
  36. package/lib/src/types.d.ts +381 -0
  37. package/lib/tools/publish.cjs +186 -218
  38. package/lib/tools/publish.d.ts +1 -0
  39. package/lib/tools/replace-private.d.ts +1 -0
  40. package/lib/tools/replace-private.js +33 -0
  41. package/lib/version.d.ts +0 -0
  42. package/package.json +4 -3
@@ -1,233 +1,201 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") {
10
- for (let key of __getOwnPropNames(from))
11
- if (!__hasOwnProp.call(to, key) && key !== except)
12
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
- }
14
- return to;
15
- };
16
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
- // If the importer is in node compatibility mode or this is not an ESM
18
- // file that has been converted to a CommonJS file using a Babel-
19
- // compatible transform (i.e. "__esModule" has not been set), then set
20
- // "default" to the CommonJS "module.exports" for node compatibility.
21
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
- mod
23
- ));
24
-
25
- // tools/publish.ts
26
- var import_cli = require("@hailer/cli");
27
- var request = __toESM(require("request"));
28
- var import_fs = require("fs");
29
-
30
- // tools/minimal-password-prompt.ts
31
- var stdin = process.stdin;
32
- var stdout = process.stdout;
33
- var captureStdin = (onData) => {
34
- stdin.setEncoding("utf-8");
35
- stdin.setRawMode(true);
36
- stdin.on("data", onData);
37
- stdin.resume();
38
- };
39
- var releaseStdin = (onData) => {
40
- stdin.pause();
41
- stdin.removeListener("data", onData);
42
- stdin.setRawMode(false);
43
- stdout.write("\n");
44
- };
45
- var prompt = (question, ctrlcExits = true) => new Promise((resolve, reject) => {
46
- let input = "";
47
- const onData = (data) => {
48
- switch (data) {
49
- case "\n":
50
- case "\r":
51
- case "":
52
- releaseStdin(onData);
53
- resolve(input);
54
- break;
55
- case "":
56
- releaseStdin(onData);
57
- if (ctrlcExits) {
58
- process.exit();
59
- } else {
60
- reject(new Error("Ctrl+C"));
61
- }
62
- break;
63
- case "\b":
64
- case "\x7F":
65
- input = input.slice(0, -1);
66
- break;
67
- default:
68
- input += data;
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
69
7
  }
70
- ;
71
- };
72
- captureStdin(onData);
73
- stdout.write(question);
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
74
17
  });
75
-
76
- // tools/publish.ts
77
- var import_util = require("util");
78
- var import_readline = require("readline");
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const hailer_cli_1 = require("@hailer-oy/hailer-cli");
30
+ const request = __importStar(require("request"));
31
+ const fs_1 = require("fs");
32
+ const minimal_password_prompt_1 = __importDefault(require("minimal-password-prompt"));
33
+ const util_1 = require("util");
34
+ const readline_1 = require("readline");
79
35
  if (!process.env.EMAIL && !process.env.LOCAL) {
80
- console.log("Please set environment variable EMAIL to Hailer user name.");
81
- console.log("");
82
- console.log("Usage:");
83
- console.log(" EMAIL=user.name@mail.com npm run publish-production");
84
- process.exit(10);
36
+ console.log('Please set environment variable EMAIL to Hailer user name.');
37
+ console.log('');
38
+ console.log('Usage:');
39
+ console.log(' EMAIL=user.name@mail.com npm run publish-production');
40
+ process.exit(10);
85
41
  }
86
42
  (async () => {
87
- let email = process.env.EMAIL;
88
- let password = process.env.LOCAL || await prompt("enter password for " + email + ": ");
89
- const market = process.env.MARKET === "true";
90
- const appPackageFile = process.argv[2];
91
- const mode = process.argv[3];
92
- let host = process.env.HOST || "https://localhost:9443";
93
- switch (mode) {
94
- case "--development":
95
- host = process.env.HOST || "https://testapi.hailer.biz";
96
- break;
97
- case "--staging":
98
- host = process.env.HOST || "https://api.hailer.biz";
99
- break;
100
- case "--production":
101
- host = process.env.HOST || "https://api.hailer.com";
102
- break;
103
- }
104
- if (process.env.LOCAL || mode === "--local") {
105
- console.log("Overriding credentials with local settings!");
106
- email = "el@hailero.es";
107
- password = "el@hailero.es";
108
- host = process.env.HOST || "https://api.hailer.local.gd";
109
- }
110
- const cli = await import_cli.Client.create({ host, username: email, password }).catch(
111
- (error) => {
112
- if (error.msg === "Invalid Login Data") {
113
- console.log("Invalid username or password when logging into Hailer.");
114
- } else {
115
- console.log("Hailer Cli Error:", error);
116
- }
117
- process.exit(8);
118
- }
119
- );
120
- if (!appPackageFile?.endsWith(".tgz")) {
121
- console.log("Failed getting .tgz file, found:", appPackageFile);
122
- process.exit(7);
123
- }
124
- const manifest = JSON.parse((0, import_fs.readFileSync)("./dist/manifest.json").toString());
125
- const content = (0, import_fs.readFileSync)(appPackageFile);
126
- const info = await cli.request("v2.core.init", [["network", "networks", "apps"]]);
127
- if (market) {
128
- if (!manifest.version) {
129
- manifest.version = "";
130
- manifest.versionDescription = "";
131
- const updatedManifestContent = JSON.stringify(manifest, null, 2);
132
- (0, import_fs.writeFileSync)("./public/manifest.json", updatedManifestContent, "utf-8");
133
- console.log("");
134
- console.log("Please set version & versionDescription in file public/manifest.json! You have added MARKET=true in your publish string.");
135
- console.log("");
136
- process.exit(10);
43
+ let email = process.env.EMAIL;
44
+ let password = process.env.LOCAL || await (0, minimal_password_prompt_1.default)('enter password for ' + email + ': ');
45
+ // Market code
46
+ const market = process.env.MARKET === 'true';
47
+ const appPackageFile = process.argv[2];
48
+ /** Alternatives: `--development` | `--staging` | `--production` */
49
+ const mode = process.argv[3];
50
+ let host = 'https://localhost:9443';
51
+ switch (mode) {
52
+ case '--development':
53
+ host = 'https://testapi.hailer.biz';
54
+ break;
55
+ case '--staging':
56
+ host = 'https://api.hailer.biz';
57
+ break;
58
+ case '--production':
59
+ host = 'https://api.hailer.com';
60
+ break;
137
61
  }
138
- }
139
- const getAppById = (manifestAppId) => {
140
- for (const appMap of Object.values(info.apps)) {
141
- for (const [appId, app2] of Object.entries(appMap)) {
142
- if (appId === manifestAppId) {
143
- return app2;
144
- }
145
- }
62
+ if (process.env.LOCAL || mode === '--local') {
63
+ console.log('Overriding credentials with local settings!');
64
+ email = 'el@hailero.es';
65
+ password = 'thispasswordshouldbestrongenough';
66
+ host = 'http://localhost:1337';
146
67
  }
147
- return null;
148
- };
149
- const app = getAppById(manifest.appId);
150
- if (!app) {
151
- console.log("The app was not found using this user:", email);
152
- process.exit(2);
153
- }
154
- const personalApp = !app.cid;
155
- console.log("Publishing App");
156
- console.log(" Id:", manifest.appId);
157
- console.log(" Name:", app.name);
158
- if (personalApp) {
159
- console.log(" Workspace: any (personal app)");
160
- } else {
161
- console.log(" Workspace:", info.networks[app.cid]?.name, "(" + app.cid + ")");
162
- }
163
- console.log(" Environment:", host);
164
- console.log();
165
- if (market) {
166
- console.log(" Note: Also publishing app to Hailer market");
167
- }
168
- const promptOverwriteQuestion = async () => {
169
- if (process.argv.includes("--yes")) {
170
- return true;
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);
171
72
  }
172
- return new Promise((resolve) => {
173
- const rl = (0, import_readline.createInterface)(process.stdin, process.stdout);
174
- rl.setPrompt("Overwrite the app? (Y/n): ");
175
- rl.prompt();
176
- rl.on("line", (line) => {
177
- if (line.trim().toLocaleLowerCase().startsWith("n")) {
178
- resolve(false);
179
- } else {
180
- resolve(true);
73
+ cli.on('error', (error) => {
74
+ if (error.msg === 'Invalid Login Data') {
75
+ console.log('Invalid username or password when logging into Hailer.');
76
+ process.exit(8);
181
77
  }
182
- rl.close();
183
- });
78
+ console.log('Hailer Cli Error:', error);
184
79
  });
185
- };
186
- const shouldOverwrite = await promptOverwriteQuestion();
187
- if (!shouldOverwrite) {
188
- console.log("Aborted publishing app.");
189
- process.exit(0);
190
- }
191
- await new Promise((resolve, reject) => {
192
- request.post({
193
- uri: host + "/app/publish",
194
- headers: { hlrkey: cli.sessionKey },
195
- formData: {
196
- file: {
197
- value: content,
198
- options: {
199
- filename: appPackageFile
200
- }
201
- },
202
- appId: manifest.appId,
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);
203
84
  // Market code
204
- publishMarket: market.toString()
205
- }
206
- }, function(error, resp, body) {
207
- if (error) {
208
- console.log("Publish error uploading file:", error);
209
- process.exit(9);
210
- }
211
- let response;
212
- let infoMarket = "";
213
- try {
214
- response = JSON.parse(body);
215
- if (response.manifest && response.manifest.targetId) {
216
- infoMarket = "Note! Use targetId in public/manifest.json file when creating the product in market!";
217
- manifest.targetId = response.manifest.targetId;
218
- const updatedManifestContent = JSON.stringify(manifest, null, 2);
219
- (0, import_fs.writeFileSync)("./public/manifest.json", updatedManifestContent, "utf-8");
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
+ }
99
+ }
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
+ }
106
+ }
107
+ }
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
+ }
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);
220
152
  }
221
- } catch (error2) {
222
- }
223
- console.log("App info:", (0, import_util.inspect)(response, { depth: 10, colors: true }));
224
- console.log();
225
- console.log(infoMarket);
226
- console.log();
227
- console.log("Published successfully!");
228
- resolve();
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(),
167
+ }
168
+ }, function (error, resp, body) {
169
+ if (error) {
170
+ console.log('Publish error uploading file:', error);
171
+ process.exit(9);
172
+ }
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');
186
+ }
187
+ }
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
+ });
198
+ });
199
+ cli.disconnect();
229
200
  });
230
- });
231
- cli.disconnect();
232
201
  })();
233
- //# sourceMappingURL=publish.cjs.map
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const fs_1 = require("fs");
4
+ const path_1 = require("path");
5
+ const srcFolder = (0, path_1.join)(__dirname, '../src');
6
+ const publicSrcFolder = (0, path_1.join)(__dirname, '../public-src');
7
+ const replacePrivateComments = (fileContent) => {
8
+ // Replaces all occurences of /* @ private */ with private
9
+ return fileContent.replace(/\/\* @private \*\//g, 'private');
10
+ };
11
+ const copyAndReplaceFiles = (src, dest) => {
12
+ (0, fs_1.mkdirSync)(dest, { recursive: true });
13
+ console.log('Created folder: ', dest);
14
+ (0, fs_1.readdirSync)(src).forEach((file) => {
15
+ const srcFile = (0, path_1.join)(src, file);
16
+ const destFile = (0, path_1.join)(dest, file);
17
+ if ((0, fs_1.lstatSync)(srcFile).isDirectory()) {
18
+ copyAndReplaceFiles(srcFile, destFile);
19
+ }
20
+ else if (srcFile.endsWith('.ts')) {
21
+ const updatedContent = replacePrivateComments((0, fs_1.readFileSync)(srcFile, 'utf8'));
22
+ (0, fs_1.writeFileSync)(destFile, updatedContent, 'utf8');
23
+ }
24
+ else {
25
+ (0, fs_1.copyFileSync)(srcFile, destFile);
26
+ }
27
+ });
28
+ };
29
+ if ((0, fs_1.existsSync)(publicSrcFolder)) {
30
+ (0, fs_1.rmdirSync)(publicSrcFolder, { recursive: true });
31
+ }
32
+ copyAndReplaceFiles(srcFolder, publicSrcFolder);
33
+ console.log('Public source files generated in /public-src/');
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hailer/app-sdk",
3
- "version": "2.0.0-beta-3",
3
+ "version": "2.0.0-beta-5",
4
4
  "description": "SDK for building Hailer Apps",
5
5
  "author": "",
6
6
  "license": "ISC",
@@ -11,7 +11,7 @@
11
11
  "./lib/**/*"
12
12
  ],
13
13
  "scripts": {
14
- "build": "esbuild tools/publish.ts --platform=node --packages=external --bundle --format=cjs --sourcemap --outfile=lib/tools/publish.cjs && tsc && esbuild src/index.ts --bundle --format=esm --minify --sourcemap --outfile=lib/app-sdk.js",
14
+ "build": "tsc --project tools/tsconfig.json && mv lib/tools/publish.js lib/tools/publish.cjs && tsc && esbuild src/index.ts --bundle --format=esm --minify --sourcemap --outfile=lib/app-sdk.js",
15
15
  "prepublishOnly": "npm run build",
16
16
  "watch": "concurrently --kill-others \"npm run watch-tsc\" \"npm run watch-esbuild\"",
17
17
  "watch-tsc": "tsc --watch",
@@ -19,8 +19,9 @@
19
19
  "docs": "typedoc --entryPointStrategy expand ./src && open-cli ./docs/index.html"
20
20
  },
21
21
  "dependencies": {
22
- "@hailer/cli": "1.1.8",
22
+ "@hailer-oy/hailer-cli": "^1.1.6",
23
23
  "@wishcore/wish-rpc": "0.6.11",
24
+ "minimal-password-prompt": "1.1.0",
24
25
  "request": "2.88.2"
25
26
  },
26
27
  "devDependencies": {