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

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.
@@ -1,197 +1,233 @@
1
1
  "use strict";
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]; } };
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;
7
69
  }
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;
70
+ ;
71
+ };
72
+ captureStdin(onData);
73
+ stdout.write(question);
17
74
  });
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
- Object.defineProperty(exports, "__esModule", { value: true });
26
- const cli_1 = require("@hailer/cli");
27
- const request = __importStar(require("request"));
28
- const fs_1 = require("fs");
29
- const minimal_password_prompt_1 = require("minimal-password-prompt");
30
- const util_1 = require("util");
31
- const readline_1 = require("readline");
75
+
76
+ // tools/publish.ts
77
+ var import_util = require("util");
78
+ var import_readline = require("readline");
32
79
  if (!process.env.EMAIL && !process.env.LOCAL) {
33
- console.log('Please set environment variable EMAIL to Hailer user name.');
34
- console.log('');
35
- console.log('Usage:');
36
- console.log(' EMAIL=user.name@mail.com npm run publish-production');
37
- process.exit(10);
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);
38
85
  }
39
86
  (async () => {
40
- let email = process.env.EMAIL;
41
- let password = process.env.LOCAL || await (0, minimal_password_prompt_1.prompt)('enter password for ' + email + ': ');
42
- // Market code
43
- const market = process.env.MARKET === 'true';
44
- const appPackageFile = process.argv[2];
45
- /** Alternatives: `--development` | `--staging` | `--production` */
46
- const mode = process.argv[3];
47
- let host = 'https://localhost:9443';
48
- switch (mode) {
49
- case '--development':
50
- host = 'https://testapi.hailer.biz';
51
- break;
52
- case '--staging':
53
- host = 'https://api.hailer.biz';
54
- break;
55
- case '--production':
56
- host = 'https://api.hailer.com';
57
- break;
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);
58
118
  }
59
- if (process.env.LOCAL || mode === '--local') {
60
- console.log('Overriding credentials with local settings!');
61
- email = 'el@hailero.es';
62
- password = 'thispasswordshouldbestrongenough';
63
- host = 'http://localhost:1337';
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);
64
137
  }
65
- const cli = await cli_1.Client.create({ host, username: email, password }).catch((error) => {
66
- if (error.msg === 'Invalid Login Data') {
67
- console.log('Invalid username or password when logging into Hailer.');
68
- }
69
- else {
70
- console.log('Hailer Cli Error:', error);
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;
71
144
  }
72
- process.exit(8);
73
- });
74
- if (!appPackageFile?.endsWith('.tgz')) {
75
- console.log('Failed getting .tgz file, found:', appPackageFile);
76
- process.exit(7);
145
+ }
77
146
  }
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);
95
- }
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;
96
171
  }
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;
102
- }
103
- }
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);
104
181
  }
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);
137
- }
138
- else {
139
- resolve(true);
140
- }
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,
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');
183
- }
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();
194
- });
182
+ rl.close();
183
+ });
184
+ });
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,
203
+ // 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");
220
+ }
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();
195
229
  });
196
- cli.disconnect();
230
+ });
231
+ cli.disconnect();
197
232
  })();
233
+ //# sourceMappingURL=publish.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../tools/publish.ts", "../../tools/minimal-password-prompt.ts"],
4
+ "sourcesContent": ["import { Client } from '@hailer/cli';\nimport * as request from 'request';\nimport { readFileSync, writeFileSync } from 'fs';\nimport { prompt } from './minimal-password-prompt';\nimport { inspect } from 'util';\nimport { createInterface } from 'readline';\n\nif (!process.env.EMAIL && !process.env.LOCAL) {\n console.log('Please set environment variable EMAIL to Hailer user name.');\n console.log('');\n console.log('Usage:');\n console.log(' EMAIL=user.name@mail.com npm run publish-production');\n process.exit(10);\n}\n\n(async () => {\n\n let email = process.env.EMAIL;\n let password = process.env.LOCAL || await prompt('enter password for ' + email + ': ');\n\n // Market code\n const market = process.env.MARKET === 'true';\n\n const appPackageFile = process.argv[2];\n\n /** Alternatives: `--development` | `--staging` | `--production` */\n const mode = process.argv[3];\n\n let host = process.env.HOST || 'https://localhost:9443';\n\n switch (mode) {\n case '--development':\n host = process.env.HOST || 'https://testapi.hailer.biz';\n break;\n case '--staging':\n host = process.env.HOST || 'https://api.hailer.biz';\n break;\n case '--production':\n host = process.env.HOST || 'https://api.hailer.com';\n break;\n }\n\n if (process.env.LOCAL || mode === '--local') {\n console.log('Overriding credentials with local settings!');\n email = 'el@hailero.es';\n password = 'el@hailero.es';\n host = process.env.HOST || 'https://api.hailer.local.gd';\n }\n\n const cli = await Client.create({ host, username: email, password }).catch(\n (error) => {\n if (error.msg === 'Invalid Login Data') {\n console.log('Invalid username or password when logging into Hailer.');\n } else {\n console.log('Hailer Cli Error:', error);\n }\n\n process.exit(8);\n }\n );\n\n if (!appPackageFile?.endsWith('.tgz')) {\n console.log('Failed getting .tgz file, found:', appPackageFile);\n process.exit(7);\n }\n\n const manifest = JSON.parse(readFileSync('./dist/manifest.json').toString());\n const content = readFileSync(appPackageFile);\n const info = await cli.request('v2.core.init', [['network', 'networks', 'apps']]);\n\n // Market code\n if (market) {\n // Check if version exist in manifest.json. If not, add empty version and let user fill it in\n if (!manifest.version) {\n manifest.version = '';\n manifest.versionDescription = '';\n\n // Convert the modified object back to JSON\n const updatedManifestContent = JSON.stringify(manifest, null, 2);\n \n // Write the updated JSON content back to manifest.json\n writeFileSync('./public/manifest.json', updatedManifestContent, 'utf-8');\n\n console.log('');\n console.log('Please set version & versionDescription in file public/manifest.json! You have added MARKET=true in your publish string.');\n console.log('');\n process.exit(10);\n }\n }\n\n const getAppById = (manifestAppId: string): { _id: string, name: string, cid: string } | null => {\n for (const appMap of Object.values(info.apps)) {\n for (const [appId, app] of Object.entries(appMap as any)) {\n if (appId === manifestAppId) {\n return app as any;\n }\n }\n }\n\n return null;\n }\n\n const app = getAppById(manifest.appId);\n\n if (!app) {\n console.log('The app was not found using this user:', email);\n process.exit(2);\n }\n\n const personalApp = !app.cid;\n\n console.log('Publishing App');\n console.log(' Id:', manifest.appId);\n console.log(' Name:', app.name);\n if (personalApp) {\n console.log(' Workspace: any (personal app)');\n } else {\n console.log(' Workspace:', info.networks[app.cid]?.name, '(' + app.cid + ')');\n }\n console.log(' Environment:', host);\n console.log();\n\n // Market code\n if (market) {\n console.log(' Note: Also publishing app to Hailer market');\n }\n\n /** Default to publish (yes) */\n const promptOverwriteQuestion = async () => {\n if (process.argv.includes('--yes')) {\n return true;\n }\n\n return new Promise<boolean>(resolve => {\n const rl = createInterface(process.stdin, process.stdout);\n\n rl.setPrompt('Overwrite the app? (Y/n): ');\n rl.prompt();\n rl.on('line', (line) => {\n if (line.trim().toLocaleLowerCase().startsWith('n')) {\n resolve(false);\n } else {\n resolve(true);\n }\n rl.close();\n });\n });\n }\n\n const shouldOverwrite = await promptOverwriteQuestion();\n\n if (!shouldOverwrite) {\n console.log('Aborted publishing app.');\n process.exit(0);\n }\n\n await new Promise<void>((resolve, reject) => {\n request.post({\n uri: host + '/app/publish',\n headers: { hlrkey: cli.sessionKey },\n formData: {\n file: {\n value: content,\n options: {\n filename: appPackageFile,\n }\n },\n appId: manifest.appId,\n // Market code\n publishMarket: market.toString(),\n }\n }, function (error, resp, body) {\n if (error) {\n console.log('Publish error uploading file:', error);\n process.exit(9);\n }\n\n let response;\n let infoMarket = '';\n\n try {\n response = JSON.parse(body);\n\n // Market code\n if (response.manifest && response.manifest.targetId) {\n infoMarket = 'Note! Use targetId in public/manifest.json file when creating the product in market!';\n // Write targetId to manifest.json\n manifest.targetId = response.manifest.targetId;\n\n // Convert the modified object back to JSON\n const updatedManifestContent = JSON.stringify(manifest, null, 2);\n \n // Write the updated JSON content back to manifest.json\n writeFileSync('./public/manifest.json', updatedManifestContent, 'utf-8');\n }\n } catch (error) {\n // ingore\n }\n\n console.log('App info:', inspect(response, { depth: 10, colors: true }));\n console.log();\n console.log(infoMarket);\n console.log();\n console.log('Published successfully!');\n resolve();\n });\n });\n\n cli.disconnect();\n})();\n", "// Re-written to TypeScript to fix typing issue, see: https://www.npmjs.com/package/minimal-password-prompt/v/1.1.0\n\nconst stdin = process.stdin;\nconst stdout = process.stdout;\n\nconst captureStdin = (onData: (data: string) => void) => {\n stdin.setEncoding('utf-8');\n stdin.setRawMode(true);\n stdin.on('data', onData);\n stdin.resume();\n};\n\nconst releaseStdin = (onData: (data: string) => void) => {\n stdin.pause();\n stdin.removeListener('data', onData);\n stdin.setRawMode(false);\n stdout.write('\\n');\n};\n\nexport const prompt = (question: string, ctrlcExits = true): Promise<string> => (\n new Promise((resolve, reject) => {\n let input = '';\n const onData = (data: string) => {\n switch (data) {\n case '\\u000A': // \\n\n case '\\u000D': // \\r\n case '\\u0004': // Ctrl+D\n releaseStdin(onData);\n resolve(input);\n break;\n case '\\u0003': // Ctrl+C\n releaseStdin(onData);\n if (ctrlcExits) { // exit or raise error\n process.exit();\n } else {\n reject(new Error('Ctrl+C'));\n }\n break;\n case '\\u0008': // Backspace\n case '\\u007F': // Delete\n input = input.slice(0, -1);\n break;\n default: // any other\n input += data;\n };\n };\n captureStdin(onData);\n stdout.write(question);\n })\n);\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iBAAuB;AACvB,cAAyB;AACzB,gBAA4C;;;ACA5C,IAAM,QAAQ,QAAQ;AACtB,IAAM,SAAS,QAAQ;AAEvB,IAAM,eAAe,CAAC,WAAmC;AACrD,QAAM,YAAY,OAAO;AACzB,QAAM,WAAW,IAAI;AACrB,QAAM,GAAG,QAAQ,MAAM;AACvB,QAAM,OAAO;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
+ "version": "2.0.0-beta-3",
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": "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",
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",
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",
package/lib/constants.js DELETED
@@ -1,3 +0,0 @@
1
- // Changing this will be a breaking change
2
- export var DEFAULT_API_VERSION = 1;
3
- export var DEFAULT_ALLOWED_URLS = ['https://app.hailer.com', 'https://next.hailer.com', 'https://testapp.hailer.biz', 'https://app.hailer.biz'];
package/lib/hailer-api.js DELETED
@@ -1,147 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __generator = (this && this.__generator) || function (thisArg, body) {
11
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
- function verb(n) { return function (v) { return step([n, v]); }; }
14
- function step(op) {
15
- if (f) throw new TypeError("Generator is already executing.");
16
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
- if (y = 0, t) op = [op[0] & 2, t.value];
19
- switch (op[0]) {
20
- case 0: case 1: t = op; break;
21
- case 4: _.label++; return { value: op[1], done: false };
22
- case 5: _.label++; y = op[1]; op = [0]; continue;
23
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
- default:
25
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
- if (t[2]) _.ops.pop();
30
- _.trys.pop(); continue;
31
- }
32
- op = body.call(thisArg, _);
33
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
- }
36
- };
37
- import { Client } from '@wishcore/wish-rpc';
38
- import { User } from './modules/user';
39
- import { Activity } from './modules/activity';
40
- import { Network } from './modules/network';
41
- import { Ui } from './modules/ui';
42
- import { Insight } from './modules/insight';
43
- import { Process } from './modules/process';
44
- import { DEFAULT_ALLOWED_URLS, DEFAULT_API_VERSION } from './constants';
45
- var HailerApi = /** @class */ (function () {
46
- /**
47
- * Create a Hailer API client for inteacting with Hailer. **NOTE** This only works when inside Hailer.
48
- *
49
- * This should be run after window is initialized for example in ***onMount*** in Svelte or in ***useEffect*** in React
50
- */
51
- function HailerApi(options) {
52
- if (options === void 0) { options = {}; }
53
- var _this = this;
54
- var _a, _b, _c, _d;
55
- this.options = options;
56
- var allowedUrls = (_a = options.allowedUrls) !== null && _a !== void 0 ? _a : DEFAULT_ALLOWED_URLS;
57
- this.apiVersion = (_b = options.apiVersion) !== null && _b !== void 0 ? _b : DEFAULT_API_VERSION;
58
- this.subscribedSignals = options.subscribedSignals;
59
- this.client = new Client(function (msg) {
60
- if (_this.hostUrl) {
61
- parent.postMessage(JSON.stringify(msg), _this.hostUrl);
62
- }
63
- });
64
- this.user = new User(this.client, this.apiVersion);
65
- this.activity = new Activity(this.client, this.apiVersion);
66
- this.insight = new Insight(this.client, this.apiVersion);
67
- this.network = new Network(this.client, this.apiVersion);
68
- this.process = new Process(this.client, this.apiVersion);
69
- this.ui = new Ui(this.client, this.apiVersion);
70
- var registerMessage = JSON.stringify({ op: 'register', args: [] });
71
- // If we are not in Iframe set location to outside, else wait 100ms for response to register to check if we are in Hailer
72
- if (window.location === window.parent.location) {
73
- (_d = (_c = this.options).outside) === null || _d === void 0 ? void 0 : _d.call(_c);
74
- }
75
- else {
76
- // if in a frame, try register to Hailer by sending register to all allowed urls
77
- allowedUrls.forEach(function (url) { return parent.postMessage(registerMessage, url); });
78
- this.timer = setTimeout(function () { var _a, _b; return (_b = (_a = _this.options).outside) === null || _b === void 0 ? void 0 : _b.call(_a); }, 100);
79
- }
80
- this.createEventListener();
81
- }
82
- HailerApi.prototype.createEventListener = function () {
83
- var _this = this;
84
- window.addEventListener('message', function (event) {
85
- var _a, _b;
86
- var data = event.data;
87
- try {
88
- var msg = JSON.parse(data);
89
- if (msg.op === 'register') {
90
- clearTimeout(_this.timer);
91
- _this.appId = msg.data.appId;
92
- // Set host url now that we have a response
93
- _this.hostUrl = event.origin;
94
- // Register listeners for config and settings
95
- _this.client.request("v".concat(_this.apiVersion, ".ui.settings"), [], function (error, data, end) {
96
- var _a, _b;
97
- if (error) {
98
- console.log('ui.settings error:', error, data);
99
- return;
100
- }
101
- (_b = (_a = _this.options).settings) === null || _b === void 0 ? void 0 : _b.call(_a, data);
102
- });
103
- _this.client.request("v".concat(_this.apiVersion, ".config"), [], function (error, data, end) {
104
- var _a, _b;
105
- if (error) {
106
- console.log('config error:', error, data);
107
- return;
108
- }
109
- (_b = (_a = _this.options).config) === null || _b === void 0 ? void 0 : _b.call(_a, data);
110
- });
111
- // Register subscribed signals
112
- if (_this.subscribedSignals) {
113
- _this.client.request("v".concat(_this.apiVersion, ".signals"), [_this.subscribedSignals], function (error, data, end) {
114
- var _a, _b;
115
- if (error) {
116
- console.log('signals error:', error, data);
117
- return;
118
- }
119
- if (data) {
120
- (_b = (_a = _this.options).signals) === null || _b === void 0 ? void 0 : _b.call(_a, data);
121
- }
122
- });
123
- }
124
- // Call connected callback
125
- (_b = (_a = _this.options).connected) === null || _b === void 0 ? void 0 : _b.call(_a);
126
- }
127
- _this.client.messageReceived(msg);
128
- }
129
- catch (error) {
130
- console.error(error);
131
- }
132
- });
133
- };
134
- // TODO: This is here for development and debugging, might be removed later
135
- HailerApi.prototype.request = function (op, args) {
136
- return __awaiter(this, void 0, void 0, function () {
137
- return __generator(this, function (_a) {
138
- switch (_a.label) {
139
- case 0: return [4 /*yield*/, this.client.requestAsync(op, args)];
140
- case 1: return [2 /*return*/, _a.sent()];
141
- }
142
- });
143
- });
144
- };
145
- return HailerApi;
146
- }());
147
- export { HailerApi };
package/lib/index.js DELETED
@@ -1,3 +0,0 @@
1
- export { HailerApi } from './hailer-api';
2
- export { HailerApiPublic } from './public-api';
3
- export * from './types';