@hailer/app-sdk 1.0.0 → 1.0.1-beta2

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,68 +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
- import { HailerError } from '../../types';
11
- export class Form {
12
- constructor(options) {
13
- this.options = options;
14
- }
15
- /**
16
- * Read data from forms
17
- *
18
- * @param formsKey key of a form
19
- * @param options Overrides default request options, url defaults to https://api.hailer.com/api/v2/forms
20
- *
21
- * @returns forms data as object or null if form could not be found
22
- *
23
- * @throws {HailerError} if there is something wrong with the request or form cannot be found
24
- * @throws {TypeError} if Hailer cannot be reached
25
- */
26
- data(formsKey) {
27
- return __awaiter(this, void 0, void 0, function* () {
28
- const res = yield fetch(this.options.publicBackendUrl + '/api/v2/forms/process/get', {
29
- method: 'POST',
30
- headers: {
31
- 'Content-Type': 'application/json',
32
- },
33
- body: JSON.stringify([formsKey])
34
- });
35
- if (!res.ok) {
36
- throw new HailerError(yield res.json());
37
- }
38
- return yield res.json();
39
- });
40
- }
41
- /**
42
- * Submits form to specified process
43
- *
44
- * @param formsKey key of a form
45
- * @param formsData Data to be sent to form endpoint
46
- * @param options Overrides default request options, url defaults to https://api.hailer.com/api/v2/forms
47
- *
48
- * @returns form creation data or null if form could not be created
49
- *
50
- * @throws {HailerError} if there is something wrong with the request or form cannot be found
51
- * @throws {TypeError} if Hailer cannot be reached
52
- */
53
- submit(formsKey, formsData) {
54
- return __awaiter(this, void 0, void 0, function* () {
55
- const res = yield fetch(this.options.publicBackendUrl + '/api/v2/forms/activity/create', {
56
- method: 'POST',
57
- headers: {
58
- 'Content-Type': 'application/json',
59
- },
60
- body: JSON.stringify([formsKey, formsData])
61
- });
62
- if (!res.ok) {
63
- throw new HailerError(yield res.json());
64
- }
65
- return yield res.json();
66
- });
67
- }
68
- }
@@ -1,69 +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
- import { HailerError } from '../../types';
11
- export class Insight {
12
- constructor(options) {
13
- this.options = options;
14
- }
15
- /**
16
- * Read data from insight API
17
- *
18
- * @param insightKey key of a specific insight
19
- * @param options Overrides default request options, url defaults to https://api.hailer.com/api/v3/insight/public
20
- *
21
- * @returns Insight data as object
22
- *
23
- * @throws {HailerError} if there is something wrong with the request or insight cannot be found
24
- * @throws {TypeError} if Hailer cannot be reached
25
- */
26
- data(insightKey) {
27
- return __awaiter(this, void 0, void 0, function* () {
28
- const res = yield fetch(this.options.publicBackendUrl + '/api/v3/insight/public', {
29
- method: 'POST',
30
- headers: {
31
- 'Content-Type': 'application/json',
32
- },
33
- body: JSON.stringify([insightKey])
34
- });
35
- if (!res.ok) {
36
- throw new HailerError(yield res.json());
37
- }
38
- return yield res.json();
39
- });
40
- }
41
- /**
42
- * Read data from insight API and return in an array of JavaScript objects
43
- *
44
- * @param insightKey key of a specific insight
45
- * @param options Overrides default request options, url defaults to https://api.hailer.com/api/v3/insight/public
46
- *
47
- * @returns Insight data as array of JavaScript objects
48
- *
49
- * @throws {HailerError} if there is something wrong with the request or insight cannot be found
50
- * @throws {TypeError} if Hailer cannot be reached
51
- */
52
- dataAsObject(insightKey) {
53
- return __awaiter(this, void 0, void 0, function* () {
54
- const res = yield this.data(insightKey);
55
- const input = res.data;
56
- const data = [];
57
- input.rows.forEach((row) => {
58
- // The object keys are constructed dynamically, so any is necessary
59
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
60
- const object = {};
61
- input.headers.forEach((header, headerIndex) => {
62
- object[header] = row[headerIndex];
63
- });
64
- data.push(object);
65
- });
66
- return data;
67
- });
68
- }
69
- }
@@ -1,13 +0,0 @@
1
- import { App } from './public/app';
2
- import { Form } from './public/form';
3
- import { Insight } from './public/insight';
4
- /**
5
- * This class is used to access Hailer public API even when the app is outside of Hailer
6
- */
7
- export class HailerApiPublic {
8
- constructor(options) {
9
- this.insight = new Insight(options);
10
- this.form = new Form(options);
11
- this.app = new App(options);
12
- }
13
- }
@@ -1,28 +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
- export class Activity {
11
- constructor(client) {
12
- this.client = client;
13
- }
14
- /** Opens an activity in Hailer sidebar */
15
- open(
16
- /** Hailer Activity Id */
17
- activityId, options) {
18
- return __awaiter(this, void 0, void 0, function* () {
19
- yield this.client.requestAsync('v1.ui.activity.open', [activityId, ...options ? [options] : []]);
20
- });
21
- }
22
- /** Opens activity creation view in Hailer sidebar */
23
- create(processId, options) {
24
- return __awaiter(this, void 0, void 0, function* () {
25
- return yield this.client.requestAsync('v1.ui.activity.create', [processId, ...options ? [options] : []]);
26
- });
27
- }
28
- }
@@ -1,36 +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
- export class Files {
11
- constructor(client) {
12
- this.client = client;
13
- }
14
- /**
15
- * Uploads a file to Hailer
16
- *
17
- * @param file file to be uploaded
18
- * @param publicFile is the file accessible outside of Hailer
19
- * @param options if file is public
20
- *
21
- * @returns File ID in Hailer as string
22
- */
23
- uploadFile(file, filename, options) {
24
- return __awaiter(this, void 0, void 0, function* () {
25
- return yield this.client.requestAsync('v1.ui.file.upload', [yield this.toBase64(file), filename, !!(options === null || options === void 0 ? void 0 : options.isPublic)]);
26
- });
27
- }
28
- toBase64(file) {
29
- return new Promise((resolve, reject) => {
30
- const reader = new FileReader();
31
- reader.readAsDataURL(file);
32
- reader.onload = () => { var _a; return resolve((_a = reader.result) !== null && _a !== void 0 ? _a : ''); };
33
- reader.onerror = reject;
34
- });
35
- }
36
- }
@@ -1,32 +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
- export class Snackbar {
11
- constructor(client) {
12
- this.client = client;
13
- }
14
- /**
15
- * Opens a snackbar in Hailer
16
- * @param text the text displayed on the snackbar
17
- * @param buttonLabel the label for the button on the snackbar, for example 'OK'
18
- * @param duration the time the snackbar is visible in ms
19
- * @param options object containing apiVersion option
20
- */
21
- open(
22
- /** The text displayed on the snackbar */
23
- text,
24
- /** The label for the button on the snackbar, for example 'OK' */
25
- buttonLabel,
26
- /** The time the snackbar is visible in ms */
27
- duration) {
28
- return __awaiter(this, void 0, void 0, function* () {
29
- yield this.client.requestAsync('v1.ui.snackbar.open', [text, buttonLabel, duration]);
30
- });
31
- }
32
- }
package/lib/modules/ui.js DELETED
@@ -1,11 +0,0 @@
1
- import { Activity } from './ui/activity';
2
- import { Snackbar } from './ui/snackbar';
3
- import { Files } from './ui/files';
4
- export class Ui {
5
- constructor(client) {
6
- this.client = client;
7
- this.activity = new Activity(client);
8
- this.snackbar = new Snackbar(client);
9
- this.files = new Files(client);
10
- }
11
- }
@@ -1,76 +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
- import { HailerError } from '../types';
11
- export class User {
12
- constructor(client) {
13
- this.client = client;
14
- }
15
- /**
16
- * Returns the specified user
17
- *
18
- * @param userId id of the Hailer user
19
- * @param options object containing apiVersion option
20
- *
21
- * @returns Hailer user information
22
- *
23
- * @throws {HailerError} if request is incorrect
24
- */
25
- get(userId) {
26
- return __awaiter(this, void 0, void 0, function* () {
27
- try {
28
- const res = yield this.client.requestAsync('v1.user.get', [userId]);
29
- return res;
30
- }
31
- catch (error) {
32
- throw new HailerError(error);
33
- }
34
- });
35
- }
36
- /**
37
- * Returns the current user
38
- *
39
- * @param options object containing apiVersion option
40
- *
41
- * @returns the current Hailer user information
42
- *
43
- * @throws {HailerError} if request is incorrect
44
- */
45
- current() {
46
- return __awaiter(this, void 0, void 0, function* () {
47
- try {
48
- const res = yield this.client.requestAsync('v1.user.current', []);
49
- return res;
50
- }
51
- catch (error) {
52
- throw new HailerError(error);
53
- }
54
- });
55
- }
56
- /**
57
- * Lists all Hailer users from a workspace
58
- *
59
- * @param options object containing apiVersion option
60
- *
61
- * @returns list of Hailer users in the workspace the app user is currently in
62
- *
63
- * @throws {HailerError} if request is incorrect
64
- */
65
- list() {
66
- return __awaiter(this, void 0, void 0, function* () {
67
- try {
68
- const users = yield this.client.requestAsync('v1.user.list', []);
69
- return users;
70
- }
71
- catch (error) {
72
- throw new HailerError(error);
73
- }
74
- });
75
- }
76
- }
@@ -1,54 +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
- import { HailerError } from '../types';
11
- export class Workflow {
12
- constructor(client) {
13
- this.client = client;
14
- }
15
- /**
16
- * Lists all processes from a workspace
17
- *
18
- * @returns all Hailer processes in the workspace the app user is currently in
19
- *
20
- * @throws {HailerError} if request is incorrect
21
- */
22
- list() {
23
- return __awaiter(this, void 0, void 0, function* () {
24
- try {
25
- const processes = yield this.client.requestAsync('v1.workflow.list', []);
26
- return processes;
27
- }
28
- catch (error) {
29
- throw new HailerError(error);
30
- }
31
- });
32
- }
33
- /**
34
- * Gets a single process from a workspace
35
- *
36
- * @param processId the id of the process in question
37
- * @param options object containing apiVersion option
38
- *
39
- * @returns the specified Hailer process
40
- *
41
- * @throws {HailerError} if request is incorrect
42
- */
43
- get(processId) {
44
- return __awaiter(this, void 0, void 0, function* () {
45
- try {
46
- const process = yield this.client.requestAsync('v1.workflow.get', [processId]);
47
- return process;
48
- }
49
- catch (error) {
50
- throw new HailerError(error);
51
- }
52
- });
53
- }
54
- }
package/lib/types.js DELETED
@@ -1,9 +0,0 @@
1
- export class HailerError extends Error {
2
- constructor(error) {
3
- super();
4
- this.code = error.code;
5
- this.msg = error.msg;
6
- this.debug = error.debug;
7
- Object.setPrototypeOf(this, HailerError.prototype);
8
- }
9
- }