@hailer/app-sdk 1.0.0
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/README.md +12 -0
- package/lib/constants.d.ts +7 -0
- package/lib/constants.js +12 -0
- package/lib/hailer-api.d.ts +74 -0
- package/lib/hailer-api.js +163 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/modules/activity/kanban.d.ts +38 -0
- package/lib/modules/activity/kanban.js +77 -0
- package/lib/modules/activity.d.ts +83 -0
- package/lib/modules/activity.js +130 -0
- package/lib/modules/insight.d.ts +27 -0
- package/lib/modules/insight.js +54 -0
- package/lib/modules/network.d.ts +14 -0
- package/lib/modules/network.js +33 -0
- package/lib/modules/process.d.ts +40 -0
- package/lib/modules/process.js +77 -0
- package/lib/modules/public/app.d.ts +17 -0
- package/lib/modules/public/app.js +45 -0
- package/lib/modules/public/form.d.ts +31 -0
- package/lib/modules/public/form.js +68 -0
- package/lib/modules/public/insight.d.ts +30 -0
- package/lib/modules/public/insight.js +69 -0
- package/lib/modules/public.d.ts +16 -0
- package/lib/modules/public.js +13 -0
- package/lib/modules/ui/activity.d.ts +25 -0
- package/lib/modules/ui/activity.js +28 -0
- package/lib/modules/ui/files.d.ts +18 -0
- package/lib/modules/ui/files.js +36 -0
- package/lib/modules/ui/snackbar.d.ts +19 -0
- package/lib/modules/ui/snackbar.js +32 -0
- package/lib/modules/ui.d.ts +11 -0
- package/lib/modules/ui.js +11 -0
- package/lib/modules/user.d.ts +39 -0
- package/lib/modules/user.js +76 -0
- package/lib/modules/workflow.d.ts +25 -0
- package/lib/modules/workflow.js +54 -0
- package/lib/types.d.ts +326 -0
- package/lib/types.js +9 -0
- package/package.json +28 -0
|
@@ -0,0 +1,54 @@
|
|
|
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(client) {
|
|
13
|
+
this.client = client;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Get Insight data
|
|
17
|
+
*
|
|
18
|
+
* @param insightId the id of the Insight the data is fetched from
|
|
19
|
+
* @param options object containing apiVersion option
|
|
20
|
+
*
|
|
21
|
+
* @returns data from the Insight
|
|
22
|
+
*
|
|
23
|
+
* @throws {HailerError} if request is incorrect
|
|
24
|
+
*/
|
|
25
|
+
data(insightId) {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
try {
|
|
28
|
+
return yield this.client.requestAsync('v1.insight.data', [insightId]);
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
throw new HailerError(error);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Get Insight data
|
|
37
|
+
*
|
|
38
|
+
* @param options object containing apiVersion option
|
|
39
|
+
*
|
|
40
|
+
* @returns data from the Insight
|
|
41
|
+
*
|
|
42
|
+
* @throws {HailerError} if request is incorrect
|
|
43
|
+
*/
|
|
44
|
+
list() {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
try {
|
|
47
|
+
return yield this.client.requestAsync('v1.insight.list', []);
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
throw new HailerError(error);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Client } from '@wishcore/wish-rpc';
|
|
2
|
+
import { HailerWorkspace } from '../types';
|
|
3
|
+
export declare class Network {
|
|
4
|
+
private client;
|
|
5
|
+
constructor(client: Client);
|
|
6
|
+
/**
|
|
7
|
+
* Returns the current network
|
|
8
|
+
*
|
|
9
|
+
* @returns the Hailer Workspace information the user is currently in
|
|
10
|
+
*
|
|
11
|
+
* @throws {HailerError} if request is incorrect
|
|
12
|
+
*/
|
|
13
|
+
current(): Promise<HailerWorkspace>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
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 Network {
|
|
12
|
+
constructor(client) {
|
|
13
|
+
this.client = client;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Returns the current network
|
|
17
|
+
*
|
|
18
|
+
* @returns the Hailer Workspace information the user is currently in
|
|
19
|
+
*
|
|
20
|
+
* @throws {HailerError} if request is incorrect
|
|
21
|
+
*/
|
|
22
|
+
current() {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
try {
|
|
25
|
+
const res = yield this.client.requestAsync('v1.network.current', []);
|
|
26
|
+
return res;
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
throw new HailerError(error);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Client } from '@wishcore/wish-rpc';
|
|
2
|
+
import { HailerProcess } from '../types';
|
|
3
|
+
/** @deprecated Use Workflow instead */
|
|
4
|
+
export declare class Process {
|
|
5
|
+
private client;
|
|
6
|
+
constructor(client: Client);
|
|
7
|
+
/**
|
|
8
|
+
* Lists all processes from a workspace
|
|
9
|
+
*
|
|
10
|
+
* @returns all Hailer processes in the workspace the app user is currently in
|
|
11
|
+
*
|
|
12
|
+
* @throws {HailerError} if request is incorrect
|
|
13
|
+
*/
|
|
14
|
+
list(): Promise<{
|
|
15
|
+
[key: string]: HailerProcess;
|
|
16
|
+
}>;
|
|
17
|
+
/**
|
|
18
|
+
* Gets a single process from a workspace
|
|
19
|
+
*
|
|
20
|
+
* @param processId the id of the process in question
|
|
21
|
+
* @param options object containing apiVersion option
|
|
22
|
+
*
|
|
23
|
+
* @returns the specified Hailer process
|
|
24
|
+
*
|
|
25
|
+
* @throws {HailerError} if request is incorrect
|
|
26
|
+
*/
|
|
27
|
+
get(processId: string): Promise<HailerProcess>;
|
|
28
|
+
/**
|
|
29
|
+
* Gets an id of a field in a process by its name
|
|
30
|
+
*
|
|
31
|
+
* @param processId the id of the process in question
|
|
32
|
+
* @param fieldName name of the field
|
|
33
|
+
* @param options object containing apiVersion option
|
|
34
|
+
*
|
|
35
|
+
* @returns the field id as string
|
|
36
|
+
*
|
|
37
|
+
* @throws {HailerError} if request is incorrect
|
|
38
|
+
*/
|
|
39
|
+
getFieldIdByName(processId: string, fieldName: string): Promise<string>;
|
|
40
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
/** @deprecated Use Workflow instead */
|
|
12
|
+
export class Process {
|
|
13
|
+
constructor(client) {
|
|
14
|
+
this.client = client;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Lists all processes from a workspace
|
|
18
|
+
*
|
|
19
|
+
* @returns all Hailer processes in the workspace the app user is currently in
|
|
20
|
+
*
|
|
21
|
+
* @throws {HailerError} if request is incorrect
|
|
22
|
+
*/
|
|
23
|
+
list() {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
try {
|
|
26
|
+
const processes = yield this.client.requestAsync('v1.process.list', []);
|
|
27
|
+
return processes;
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
throw new HailerError(error);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Gets a single process from a workspace
|
|
36
|
+
*
|
|
37
|
+
* @param processId the id of the process in question
|
|
38
|
+
* @param options object containing apiVersion option
|
|
39
|
+
*
|
|
40
|
+
* @returns the specified Hailer process
|
|
41
|
+
*
|
|
42
|
+
* @throws {HailerError} if request is incorrect
|
|
43
|
+
*/
|
|
44
|
+
get(processId) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
try {
|
|
47
|
+
const process = yield this.client.requestAsync('v1.process.get', [processId]);
|
|
48
|
+
return process;
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
throw new HailerError(error);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Gets an id of a field in a process by its name
|
|
57
|
+
*
|
|
58
|
+
* @param processId the id of the process in question
|
|
59
|
+
* @param fieldName name of the field
|
|
60
|
+
* @param options object containing apiVersion option
|
|
61
|
+
*
|
|
62
|
+
* @returns the field id as string
|
|
63
|
+
*
|
|
64
|
+
* @throws {HailerError} if request is incorrect
|
|
65
|
+
*/
|
|
66
|
+
getFieldIdByName(processId, fieldName) {
|
|
67
|
+
var _a, _b;
|
|
68
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
try {
|
|
70
|
+
return (_b = Object.values(((_a = (yield this.get(processId))) === null || _a === void 0 ? void 0 : _a.fields) || {}).find((field) => field.label.toLowerCase() === fieldName)) === null || _b === void 0 ? void 0 : _b._id;
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
throw new HailerError(error);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Options } from '../../hailer-api';
|
|
2
|
+
import { HailerAppConfig } from '../../types';
|
|
3
|
+
export declare class App {
|
|
4
|
+
private options;
|
|
5
|
+
constructor(options: Options);
|
|
6
|
+
/**
|
|
7
|
+
* Read data from app API
|
|
8
|
+
*
|
|
9
|
+
* @param appId key of a specific insight
|
|
10
|
+
*
|
|
11
|
+
* @returns App manifest
|
|
12
|
+
*
|
|
13
|
+
* @throws {HailerError} if there is something wrong with the request or insight cannot be found
|
|
14
|
+
* @throws {TypeError} if Hailer cannot be reached
|
|
15
|
+
*/
|
|
16
|
+
config(): Promise<HailerAppConfig>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
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 App {
|
|
11
|
+
constructor(options) {
|
|
12
|
+
this.options = options;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Read data from app API
|
|
16
|
+
*
|
|
17
|
+
* @param appId key of a specific insight
|
|
18
|
+
*
|
|
19
|
+
* @returns App manifest
|
|
20
|
+
*
|
|
21
|
+
* @throws {HailerError} if there is something wrong with the request or insight cannot be found
|
|
22
|
+
* @throws {TypeError} if Hailer cannot be reached
|
|
23
|
+
*/
|
|
24
|
+
config() {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const manifestFile = 'manifest.json';
|
|
27
|
+
const location = window.location.origin + window.location.pathname;
|
|
28
|
+
let manifestUrl = location + manifestFile;
|
|
29
|
+
if (location.endsWith('/index.html')) {
|
|
30
|
+
manifestUrl = location.slice(0, -10) + manifestFile;
|
|
31
|
+
}
|
|
32
|
+
const manifestContent = yield (yield fetch(manifestUrl)).text();
|
|
33
|
+
const manifest = JSON.parse(manifestContent);
|
|
34
|
+
const appId = manifest.appId;
|
|
35
|
+
const res = yield fetch(this.options.publicBackendUrl + '/api/v3/app/public', {
|
|
36
|
+
method: 'POST',
|
|
37
|
+
headers: {
|
|
38
|
+
'Content-Type': 'application/json',
|
|
39
|
+
},
|
|
40
|
+
body: JSON.stringify([appId])
|
|
41
|
+
});
|
|
42
|
+
return yield res.json();
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Options } from '../../hailer-api';
|
|
2
|
+
import { FormCreateResponse, FormsData, FormsResponse } from '../../types';
|
|
3
|
+
export declare class Form {
|
|
4
|
+
private options;
|
|
5
|
+
constructor(options: Options);
|
|
6
|
+
/**
|
|
7
|
+
* Read data from forms
|
|
8
|
+
*
|
|
9
|
+
* @param formsKey key of a form
|
|
10
|
+
* @param options Overrides default request options, url defaults to https://api.hailer.com/api/v2/forms
|
|
11
|
+
*
|
|
12
|
+
* @returns forms data as object or null if form could not be found
|
|
13
|
+
*
|
|
14
|
+
* @throws {HailerError} if there is something wrong with the request or form cannot be found
|
|
15
|
+
* @throws {TypeError} if Hailer cannot be reached
|
|
16
|
+
*/
|
|
17
|
+
data(formsKey: string): Promise<FormsResponse>;
|
|
18
|
+
/**
|
|
19
|
+
* Submits form to specified process
|
|
20
|
+
*
|
|
21
|
+
* @param formsKey key of a form
|
|
22
|
+
* @param formsData Data to be sent to form endpoint
|
|
23
|
+
* @param options Overrides default request options, url defaults to https://api.hailer.com/api/v2/forms
|
|
24
|
+
*
|
|
25
|
+
* @returns form creation data or null if form could not be created
|
|
26
|
+
*
|
|
27
|
+
* @throws {HailerError} if there is something wrong with the request or form cannot be found
|
|
28
|
+
* @throws {TypeError} if Hailer cannot be reached
|
|
29
|
+
*/
|
|
30
|
+
submit(formsKey: string, formsData: FormsData): Promise<FormCreateResponse>;
|
|
31
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Options } from '../../hailer-api';
|
|
2
|
+
import { InsightResponse, InsightResponseAsObjects } from '../../types';
|
|
3
|
+
export declare class Insight {
|
|
4
|
+
private options;
|
|
5
|
+
constructor(options: Options);
|
|
6
|
+
/**
|
|
7
|
+
* Read data from insight API
|
|
8
|
+
*
|
|
9
|
+
* @param insightKey key of a specific insight
|
|
10
|
+
* @param options Overrides default request options, url defaults to https://api.hailer.com/api/v3/insight/public
|
|
11
|
+
*
|
|
12
|
+
* @returns Insight data as object
|
|
13
|
+
*
|
|
14
|
+
* @throws {HailerError} if there is something wrong with the request or insight cannot be found
|
|
15
|
+
* @throws {TypeError} if Hailer cannot be reached
|
|
16
|
+
*/
|
|
17
|
+
data(insightKey: string): Promise<InsightResponse>;
|
|
18
|
+
/**
|
|
19
|
+
* Read data from insight API and return in an array of JavaScript objects
|
|
20
|
+
*
|
|
21
|
+
* @param insightKey key of a specific insight
|
|
22
|
+
* @param options Overrides default request options, url defaults to https://api.hailer.com/api/v3/insight/public
|
|
23
|
+
*
|
|
24
|
+
* @returns Insight data as array of JavaScript objects
|
|
25
|
+
*
|
|
26
|
+
* @throws {HailerError} if there is something wrong with the request or insight cannot be found
|
|
27
|
+
* @throws {TypeError} if Hailer cannot be reached
|
|
28
|
+
*/
|
|
29
|
+
dataAsObject(insightKey: string): Promise<InsightResponseAsObjects>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Options } from '../hailer-api';
|
|
2
|
+
import { App } from './public/app';
|
|
3
|
+
import { Form } from './public/form';
|
|
4
|
+
import { Insight } from './public/insight';
|
|
5
|
+
/**
|
|
6
|
+
* This class is used to access Hailer public API even when the app is outside of Hailer
|
|
7
|
+
*/
|
|
8
|
+
export declare class HailerApiPublic {
|
|
9
|
+
/** Allows accessing public insight methods. Used for reading data from Hailer even when app is outside of Hailer */
|
|
10
|
+
insight: Insight;
|
|
11
|
+
/** Allows accessing public forms methods. Used for sending data to Hailer even when app is outside of Hailer */
|
|
12
|
+
form: Form;
|
|
13
|
+
/** Access public App information */
|
|
14
|
+
app: App;
|
|
15
|
+
constructor(options: Options);
|
|
16
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Client } from '@wishcore/wish-rpc';
|
|
2
|
+
export type ActivityTabTypes = 'detail' | 'discussion' | 'files' | 'location' | 'linkedFrom' | 'options';
|
|
3
|
+
export declare class Activity {
|
|
4
|
+
private client;
|
|
5
|
+
constructor(client: Client);
|
|
6
|
+
/** Opens an activity in Hailer sidebar */
|
|
7
|
+
open(
|
|
8
|
+
/** Hailer Activity Id */
|
|
9
|
+
activityId: string, options?: {
|
|
10
|
+
/** Which tab to open in activity aside */
|
|
11
|
+
tab?: ActivityTabTypes;
|
|
12
|
+
}): Promise<void>;
|
|
13
|
+
/** Opens activity creation view in Hailer sidebar */
|
|
14
|
+
create(processId: string, options?: {
|
|
15
|
+
/** Activity name/title */
|
|
16
|
+
name?: string;
|
|
17
|
+
/** Prepopulate fields */
|
|
18
|
+
fields?: {
|
|
19
|
+
[fieldId: string]: number | string | {
|
|
20
|
+
start: number;
|
|
21
|
+
end: number;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
}): Promise<void>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Client } from '@wishcore/wish-rpc';
|
|
2
|
+
export declare class Files {
|
|
3
|
+
private client;
|
|
4
|
+
constructor(client: Client);
|
|
5
|
+
/**
|
|
6
|
+
* Uploads a file to Hailer
|
|
7
|
+
*
|
|
8
|
+
* @param file file to be uploaded
|
|
9
|
+
* @param publicFile is the file accessible outside of Hailer
|
|
10
|
+
* @param options if file is public
|
|
11
|
+
*
|
|
12
|
+
* @returns File ID in Hailer as string
|
|
13
|
+
*/
|
|
14
|
+
uploadFile(file: File, filename: string, options: {
|
|
15
|
+
isPublic?: boolean;
|
|
16
|
+
}): Promise<string>;
|
|
17
|
+
private toBase64;
|
|
18
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Client } from '@wishcore/wish-rpc';
|
|
2
|
+
export declare class Snackbar {
|
|
3
|
+
private client;
|
|
4
|
+
constructor(client: Client);
|
|
5
|
+
/**
|
|
6
|
+
* Opens a snackbar in Hailer
|
|
7
|
+
* @param text the text displayed on the snackbar
|
|
8
|
+
* @param buttonLabel the label for the button on the snackbar, for example 'OK'
|
|
9
|
+
* @param duration the time the snackbar is visible in ms
|
|
10
|
+
* @param options object containing apiVersion option
|
|
11
|
+
*/
|
|
12
|
+
open(
|
|
13
|
+
/** The text displayed on the snackbar */
|
|
14
|
+
text: string,
|
|
15
|
+
/** The label for the button on the snackbar, for example 'OK' */
|
|
16
|
+
buttonLabel: string,
|
|
17
|
+
/** The time the snackbar is visible in ms */
|
|
18
|
+
duration?: number): Promise<void>;
|
|
19
|
+
}
|