@hailer/app-sdk 1.0.1-beta → 1.0.1-beta3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/hailer-api.js DELETED
@@ -1,165 +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 { Client } from '@wishcore/wish-rpc';
11
- import { UserApi } from './modules/user';
12
- import { ActivityApi } from './modules/activity';
13
- import { WorkspaceApi } from './modules/network';
14
- import { Ui } from './modules/ui';
15
- import { Process } from './modules/process';
16
- import { DEFAULT_ALLOWED_URLS, DEFAULT_API_VERSION, DEFAULT_BACKEND_URL, publicBackendMap } from './constants';
17
- import { HailerPublicApi } from './modules/public';
18
- import { WorkflowApi } from './modules/workflow';
19
- import { AppApi } from './modules/app';
20
- import { InsightApi } from './modules/insight';
21
- export class HailerApi {
22
- /**
23
- * Create a Hailer API client for inteacting with Hailer. **NOTE** This only works when inside Hailer.
24
- *
25
- * This should be run after window is initialized for example in ***onMount*** in Svelte or in ***useEffect*** in React
26
- */
27
- constructor(options = {}) {
28
- var _a, _b;
29
- this.options = options;
30
- /**
31
- * Hailer API state
32
- *
33
- * ```
34
- * true // outside hailer
35
- * false // logged into hailer
36
- * null // state not yet detected
37
- * ```
38
- */
39
- this.outside = null;
40
- const allowedUrls = (_a = options.allowedUrls) !== null && _a !== void 0 ? _a : DEFAULT_ALLOWED_URLS;
41
- this.apiVersion = (_b = options.apiVersion) !== null && _b !== void 0 ? _b : DEFAULT_API_VERSION;
42
- this.subscribedSignals = options.subscribedSignals;
43
- this.client = new Client(msg => {
44
- if (this.hostUrl) {
45
- parent.postMessage(JSON.stringify(msg), this.hostUrl);
46
- }
47
- });
48
- this.user = new UserApi(this.client);
49
- this.app = new AppApi(this.client);
50
- this.activity = new ActivityApi(this.client);
51
- this.insight = new InsightApi(this.client);
52
- this.network = new WorkspaceApi(this.client);
53
- this.process = new Process(this.client);
54
- this.workflow = new WorkflowApi(this.client);
55
- this.public = new HailerPublicApi(this.options);
56
- this.ui = new Ui(this.client);
57
- const registerMessage = JSON.stringify({ op: 'register', args: [] });
58
- // If we are not in Iframe set location to outside, else wait 100ms for response to register to check if we are in Hailer
59
- if (window.location === window.parent.location) {
60
- // Pick a backend to use for public requests, unless it is set
61
- if (!this.options.publicBackendUrl) {
62
- this.options.publicBackendUrl = DEFAULT_BACKEND_URL;
63
- }
64
- this.public.app.config().then(config => {
65
- // CSM app assumes we are inside hailer when config is called... breaks the thing...
66
- // this.options.config?.(config);
67
- var _a, _b;
68
- this.outside = true;
69
- (_b = (_a = this.options).outside) === null || _b === void 0 ? void 0 : _b.call(_a, config);
70
- }).catch(error => {
71
- var _a, _b;
72
- (_b = (_a = this.options).error) === null || _b === void 0 ? void 0 : _b.call(_a, error);
73
- console.error('Failed to get app configuration in Public App.', error);
74
- });
75
- }
76
- else {
77
- // if in a frame, try register to Hailer by sending register to all allowed urls
78
- allowedUrls.forEach(url => parent.postMessage(registerMessage, url));
79
- this.timer = setTimeout(() => {
80
- var _a, _b;
81
- this.outside = true;
82
- (_b = (_a = this.options).outside) === null || _b === void 0 ? void 0 : _b.call(_a);
83
- }, 100);
84
- }
85
- this.createEventListener();
86
- }
87
- createEventListener() {
88
- window.addEventListener('message', (event) => __awaiter(this, void 0, void 0, function* () {
89
- var _a, _b;
90
- const data = event.data;
91
- try {
92
- const msg = JSON.parse(data);
93
- if (msg.op === 'register') {
94
- if (this.appId) {
95
- console.error('App Id is already set...! Are you using hot-reload?');
96
- return;
97
- }
98
- clearTimeout(this.timer);
99
- this.appId = msg.data.appId;
100
- // Set host url now that we have a response
101
- this.hostUrl = event.origin;
102
- // Pick a backend to use for public requests, unless it is set
103
- if (!this.options.publicBackendUrl) {
104
- this.options.publicBackendUrl = publicBackendMap[this.hostUrl] || DEFAULT_BACKEND_URL;
105
- }
106
- // Register listeners for config and settings
107
- this.client.request('v1.ui.settings', [], (error, data, end) => {
108
- var _a, _b;
109
- if (error) {
110
- console.log('ui.settings error:', error, data);
111
- return;
112
- }
113
- (_b = (_a = this.options).settings) === null || _b === void 0 ? void 0 : _b.call(_a, data);
114
- });
115
- this.client.request('v1.config', [], (error, data, end) => {
116
- var _a, _b;
117
- if (error) {
118
- console.log('config error:', error, data);
119
- return;
120
- }
121
- (_b = (_a = this.options).config) === null || _b === void 0 ? void 0 : _b.call(_a, data);
122
- });
123
- // Register subscribed signals
124
- if (this.subscribedSignals) {
125
- this.client.request('v1.signals', [this.subscribedSignals], (error, data, end) => {
126
- var _a, _b;
127
- if (error) {
128
- console.log('signals error:', error, data);
129
- return;
130
- }
131
- if (data) {
132
- (_b = (_a = this.options).signals) === null || _b === void 0 ? void 0 : _b.call(_a, data);
133
- }
134
- });
135
- }
136
- this.outside = false;
137
- // Call connected callback
138
- (_b = (_a = this.options).connected) === null || _b === void 0 ? void 0 : _b.call(_a);
139
- return;
140
- }
141
- // bail out unless appId is set, as the app is not properly registered
142
- if (!this.appId) {
143
- return;
144
- }
145
- this.client.messageReceived(msg);
146
- }
147
- catch (error) {
148
- console.error('Error handling message:', error);
149
- }
150
- }));
151
- }
152
- info() {
153
- return {
154
- hostUrl: this.hostUrl,
155
- config: this.config,
156
- outside: this.outside,
157
- };
158
- }
159
- // TODO: This is here for development and debugging, might be removed later
160
- request(op, args) {
161
- return __awaiter(this, void 0, void 0, function* () {
162
- return yield this.client.requestAsync(op, args);
163
- });
164
- }
165
- }
package/lib/index.js DELETED
@@ -1,2 +0,0 @@
1
- export { HailerApi } from './hailer-api';
2
- export * from './types';
@@ -1,75 +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 Kanban {
12
- constructor(client) {
13
- this.client = client;
14
- }
15
- /**
16
- * Lists all activities in a kanban grouped by phases
17
- *
18
- * @param processId the id of the process the kanban relates to
19
- * @param options ActivityKanbanListOptions
20
- *
21
- * @returns activities in kanban list format
22
- *
23
- * @throws {HailerError} if request fails
24
- */
25
- list(processId, options) {
26
- return __awaiter(this, void 0, void 0, function* () {
27
- try {
28
- const res = yield this.client.requestAsync('v1.activity.kanban.list', [processId, ...options ? [options] : []]);
29
- return res;
30
- }
31
- catch (error) {
32
- throw new HailerError(error);
33
- }
34
- });
35
- }
36
- /**
37
- * Loads a single activity in kanban format
38
- *
39
- * @param activityId activityId of the wanted activity
40
- *
41
- * @returns activity in kanban format
42
- *
43
- * @throws {HailerError} if request is incorrect
44
- */
45
- load(activityId) {
46
- return __awaiter(this, void 0, void 0, function* () {
47
- try {
48
- const res = yield this.client.requestAsync('v1.activity.kanban.load', [activityId]);
49
- return res;
50
- }
51
- catch (error) {
52
- throw new HailerError(error);
53
- }
54
- });
55
- }
56
- /**
57
- * Updates priority of activities in kanban
58
- *
59
- * @param activityId activityId of the wanted activity
60
- * @param priority new priority for the activity
61
- *
62
- * @throws {HailerError} if request is incorrect
63
- */
64
- updatePriority(activityId, priority) {
65
- return __awaiter(this, void 0, void 0, function* () {
66
- try {
67
- const res = yield this.client.requestAsync('v1.activity.kanban.updatePriority', [{ activityId, priority }]);
68
- return res;
69
- }
70
- catch (error) {
71
- throw new HailerError(error);
72
- }
73
- });
74
- }
75
- }
@@ -1,130 +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
- import { Kanban } from './activity/kanban';
12
- export class ActivityApi {
13
- constructor(client) {
14
- this.client = client;
15
- this.kanban = new Kanban(client);
16
- }
17
- /**
18
- * Lists all activities from the specified process and phase
19
- *
20
- * @param processId process from current network
21
- * @param phaseId phase in the process specified in processId
22
- * @param options ActivityListOptions
23
- *
24
- * @returns List of Hailer activities from process and phase filtered with supplied options
25
- *
26
- * @throws {HailerError} if request is incorrect
27
- */
28
- list(processId, phaseId, options) {
29
- return __awaiter(this, void 0, void 0, function* () {
30
- try {
31
- const res = yield this.client.requestAsync('v1.activity.list', [processId, phaseId, options]);
32
- return res.activities;
33
- }
34
- catch (error) {
35
- throw new HailerError(error);
36
- }
37
- });
38
- }
39
- /**
40
- * Gets single activity
41
- *
42
- * @param activityId activity Id of the process specified in processId
43
- * @param processId Process where the activityId is
44
- * @param phaseId Phase where the activityId is in process specified by processId
45
- * @param options options containing apiVersion
46
- *
47
- * @returns Hailer activity information or undefined if no activity is found
48
- *
49
- * @throws {HailerError} if request is incorrect
50
- */
51
- get(activityId) {
52
- return __awaiter(this, void 0, void 0, function* () {
53
- try {
54
- // Uses the same endpoint as getAll but only returns the activity in question
55
- return yield this.client.requestAsync('v1.activity.get', [activityId]);
56
- }
57
- catch (error) {
58
- throw new HailerError(error);
59
- }
60
- });
61
- }
62
- /**
63
- * Creates activities
64
- *
65
- * @param processId The process where the activity is created
66
- * @param activities new activities as objects
67
- * @param activities.name name of the activity
68
- * @param activities.fields fields of the activity
69
- * @param options ActivityCreateOptions
70
- *
71
- * @throws {HailerError} if request is incorrect
72
- */
73
- create(processId, activities, options) {
74
- return __awaiter(this, void 0, void 0, function* () {
75
- try {
76
- const res = yield this.client.requestAsync('v1.activity.create', [processId, activities, ...options ? [options] : []]);
77
- return res;
78
- }
79
- catch (error) {
80
- throw new HailerError(error);
81
- }
82
- });
83
- }
84
- /**
85
- * Updates activites
86
- *
87
- * Each activity has the following parameters
88
- * @param activities updated activity objects of an activity to edit
89
- * @param activities.name New name of the activity
90
- * @param activities.fields change values of fields, null removes current value
91
- * @param activities.phaseId New phase of the activity
92
- * @param options
93
- *
94
- * @returns The number of updated activities
95
- *
96
- * @throws {HailerError} if request is incorrect
97
- */
98
- update(activities) {
99
- return __awaiter(this, void 0, void 0, function* () {
100
- try {
101
- const res = yield this.client.requestAsync('v1.activity.update', activities);
102
- return res;
103
- }
104
- catch (error) {
105
- throw new HailerError(error);
106
- }
107
- });
108
- }
109
- /**
110
- * Removes activities
111
- *
112
- * @param activities Ids of activities to be removed
113
- * @param options options containing apiVersion
114
- *
115
- * @returns The number of removed activities
116
- *
117
- * @throws {HailerError} if request is incorrect
118
- */
119
- remove(activities) {
120
- return __awaiter(this, void 0, void 0, function* () {
121
- try {
122
- const res = yield this.client.requestAsync('v1.activity.remove', activities);
123
- return res;
124
- }
125
- catch (error) {
126
- throw new HailerError(error);
127
- }
128
- });
129
- }
130
- }
@@ -1,29 +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
- /**
12
- * This class is used to access Hailer public API even when the app is outside of Hailer
13
- */
14
- export class AppApi {
15
- constructor(client) {
16
- this.client = client;
17
- this.config = {
18
- update: (appId, config) => __awaiter(this, void 0, void 0, function* () {
19
- try {
20
- return yield this.client.requestAsync('v1.app.config.update', [appId, config]);
21
- }
22
- catch (error) {
23
- console.log('Errorasd ', error);
24
- throw new HailerError(error);
25
- }
26
- })
27
- };
28
- }
29
- }
@@ -1,52 +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 InsightApi {
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
- *
20
- * @returns data from the Insight
21
- *
22
- * @throws {HailerError} if request is incorrect
23
- */
24
- data(insightId) {
25
- return __awaiter(this, void 0, void 0, function* () {
26
- try {
27
- return yield this.client.requestAsync('v1.insight.data', [insightId]);
28
- }
29
- catch (error) {
30
- throw new HailerError(error);
31
- }
32
- });
33
- }
34
- /**
35
- * Get Insight data
36
- *
37
- *
38
- * @returns data from the Insight
39
- *
40
- * @throws {HailerError} if request is incorrect
41
- */
42
- list() {
43
- return __awaiter(this, void 0, void 0, function* () {
44
- try {
45
- return yield this.client.requestAsync('v1.insight.list', []);
46
- }
47
- catch (error) {
48
- throw new HailerError(error);
49
- }
50
- });
51
- }
52
- }
@@ -1,33 +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 WorkspaceApi {
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
- }
@@ -1,75 +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
- /** @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
- *
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.process.get', [processId]);
47
- return process;
48
- }
49
- catch (error) {
50
- throw new HailerError(error);
51
- }
52
- });
53
- }
54
- /**
55
- * Gets an id of a field in a process by its name
56
- *
57
- * @param processId the id of the process in question
58
- * @param fieldName name of the field
59
- *
60
- * @returns the field id as string
61
- *
62
- * @throws {HailerError} if request is incorrect
63
- */
64
- getFieldIdByName(processId, fieldName) {
65
- var _a, _b;
66
- return __awaiter(this, void 0, void 0, function* () {
67
- try {
68
- 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;
69
- }
70
- catch (error) {
71
- throw new HailerError(error);
72
- }
73
- });
74
- }
75
- }
@@ -1,45 +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 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
- }
@@ -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
- }