@hailer/app-sdk 1.0.0-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/README.md +12 -0
  2. package/lib/constants.d.ts +7 -0
  3. package/lib/constants.js +12 -0
  4. package/lib/hailer-api.d.ts +76 -0
  5. package/lib/hailer-api.js +165 -0
  6. package/lib/index.d.ts +2 -0
  7. package/lib/index.js +2 -0
  8. package/lib/modules/activity/kanban.d.ts +36 -0
  9. package/lib/modules/activity/kanban.js +75 -0
  10. package/lib/modules/activity.d.ts +83 -0
  11. package/lib/modules/activity.js +130 -0
  12. package/lib/modules/app.d.ts +12 -0
  13. package/lib/modules/app.js +29 -0
  14. package/lib/modules/insight.d.ts +25 -0
  15. package/lib/modules/insight.js +52 -0
  16. package/lib/modules/network.d.ts +14 -0
  17. package/lib/modules/network.js +33 -0
  18. package/lib/modules/process.d.ts +38 -0
  19. package/lib/modules/process.js +75 -0
  20. package/lib/modules/public/app.d.ts +17 -0
  21. package/lib/modules/public/app.js +45 -0
  22. package/lib/modules/public/form.d.ts +31 -0
  23. package/lib/modules/public/form.js +68 -0
  24. package/lib/modules/public/insight.d.ts +30 -0
  25. package/lib/modules/public/insight.js +69 -0
  26. package/lib/modules/public.d.ts +16 -0
  27. package/lib/modules/public.js +13 -0
  28. package/lib/modules/ui/activity.d.ts +28 -0
  29. package/lib/modules/ui/activity.js +28 -0
  30. package/lib/modules/ui/files.d.ts +18 -0
  31. package/lib/modules/ui/files.js +36 -0
  32. package/lib/modules/ui/snackbar.d.ts +18 -0
  33. package/lib/modules/ui/snackbar.js +31 -0
  34. package/lib/modules/ui.d.ts +11 -0
  35. package/lib/modules/ui.js +11 -0
  36. package/lib/modules/user.d.ts +36 -0
  37. package/lib/modules/user.js +73 -0
  38. package/lib/modules/workflow.d.ts +24 -0
  39. package/lib/modules/workflow.js +53 -0
  40. package/lib/types.d.ts +320 -0
  41. package/lib/types.js +9 -0
  42. package/package.json +28 -0
@@ -0,0 +1,31 @@
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
+ */
20
+ open(
21
+ /** The text displayed on the snackbar */
22
+ text,
23
+ /** The label for the button on the snackbar, for example 'OK' */
24
+ buttonLabel,
25
+ /** The time the snackbar is visible in ms */
26
+ duration) {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ yield this.client.requestAsync('v1.ui.snackbar.open', [text, buttonLabel, duration]);
29
+ });
30
+ }
31
+ }
@@ -0,0 +1,11 @@
1
+ import { Client } from '@wishcore/wish-rpc';
2
+ import { Activity } from './ui/activity';
3
+ import { Snackbar } from './ui/snackbar';
4
+ import { Files } from './ui/files';
5
+ export declare class Ui {
6
+ private client;
7
+ activity: Activity;
8
+ snackbar: Snackbar;
9
+ files: Files;
10
+ constructor(client: Client);
11
+ }
@@ -0,0 +1,11 @@
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
+ }
@@ -0,0 +1,36 @@
1
+ import { Client } from '@wishcore/wish-rpc';
2
+ import { User } from '../types';
3
+ export declare class UserApi {
4
+ private client;
5
+ constructor(client: Client);
6
+ /**
7
+ * Returns the specified user
8
+ *
9
+ * @param userId id of the Hailer user
10
+ *
11
+ * @returns Hailer user information
12
+ *
13
+ * @throws {HailerError} if request is incorrect
14
+ */
15
+ get(userId: string): Promise<User>;
16
+ /**
17
+ * Returns the current user
18
+ *
19
+ *
20
+ * @returns the current Hailer user information
21
+ *
22
+ * @throws {HailerError} if request is incorrect
23
+ */
24
+ current(): Promise<User>;
25
+ /**
26
+ * Lists all Hailer users from a workspace
27
+ *
28
+ *
29
+ * @returns list of Hailer users in the workspace the app user is currently in
30
+ *
31
+ * @throws {HailerError} if request is incorrect
32
+ */
33
+ list(): Promise<{
34
+ [key: string]: User;
35
+ }>;
36
+ }
@@ -0,0 +1,73 @@
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 UserApi {
12
+ constructor(client) {
13
+ this.client = client;
14
+ }
15
+ /**
16
+ * Returns the specified user
17
+ *
18
+ * @param userId id of the Hailer user
19
+ *
20
+ * @returns Hailer user information
21
+ *
22
+ * @throws {HailerError} if request is incorrect
23
+ */
24
+ get(userId) {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ try {
27
+ const res = yield this.client.requestAsync('v1.user.get', [userId]);
28
+ return res;
29
+ }
30
+ catch (error) {
31
+ throw new HailerError(error);
32
+ }
33
+ });
34
+ }
35
+ /**
36
+ * Returns the current user
37
+ *
38
+ *
39
+ * @returns the current Hailer user information
40
+ *
41
+ * @throws {HailerError} if request is incorrect
42
+ */
43
+ current() {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ try {
46
+ const res = yield this.client.requestAsync('v1.user.current', []);
47
+ return res;
48
+ }
49
+ catch (error) {
50
+ throw new HailerError(error);
51
+ }
52
+ });
53
+ }
54
+ /**
55
+ * Lists all Hailer users from a workspace
56
+ *
57
+ *
58
+ * @returns list of Hailer users in the workspace the app user is currently in
59
+ *
60
+ * @throws {HailerError} if request is incorrect
61
+ */
62
+ list() {
63
+ return __awaiter(this, void 0, void 0, function* () {
64
+ try {
65
+ const users = yield this.client.requestAsync('v1.user.list', []);
66
+ return users;
67
+ }
68
+ catch (error) {
69
+ throw new HailerError(error);
70
+ }
71
+ });
72
+ }
73
+ }
@@ -0,0 +1,24 @@
1
+ import { Client } from '@wishcore/wish-rpc';
2
+ import { Workflow } from '../types';
3
+ export declare class WorkflowApi {
4
+ private client;
5
+ constructor(client: Client);
6
+ /**
7
+ * Lists all processes from a workspace
8
+ *
9
+ * @returns all Hailer processes in the workspace the app user is currently in
10
+ *
11
+ * @throws {HailerError} if request is incorrect
12
+ */
13
+ list(): Promise<Workflow[]>;
14
+ /**
15
+ * Gets a single process from a workspace
16
+ *
17
+ * @param processId the id of the process in question
18
+ *
19
+ * @returns the specified Hailer process
20
+ *
21
+ * @throws {HailerError} if request is incorrect
22
+ */
23
+ get(processId: string): Promise<Workflow>;
24
+ }
@@ -0,0 +1,53 @@
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 WorkflowApi {
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
+ *
38
+ * @returns the specified Hailer process
39
+ *
40
+ * @throws {HailerError} if request is incorrect
41
+ */
42
+ get(processId) {
43
+ return __awaiter(this, void 0, void 0, function* () {
44
+ try {
45
+ const process = yield this.client.requestAsync('v1.workflow.get', [processId]);
46
+ return process;
47
+ }
48
+ catch (error) {
49
+ throw new HailerError(error);
50
+ }
51
+ });
52
+ }
53
+ }
package/lib/types.d.ts ADDED
@@ -0,0 +1,320 @@
1
+ export interface User {
2
+ firstname: string;
3
+ lastname: string;
4
+ email: string;
5
+ lastSeen: number;
6
+ status?: string;
7
+ managedUser?: boolean;
8
+ removed?: number;
9
+ }
10
+ export interface Workspace {
11
+ _id: string;
12
+ name: string;
13
+ members: string[];
14
+ settings: {
15
+ isolatedTeams?: boolean;
16
+ defaultView: string;
17
+ functionFieldVersion?: 1 | 2;
18
+ color?: string;
19
+ allowPublicCopy?: boolean;
20
+ };
21
+ license: object;
22
+ invoicing?: any;
23
+ propertyFields?: {
24
+ [section: string]: {
25
+ [field: string]: any;
26
+ };
27
+ };
28
+ }
29
+ export interface Activity {
30
+ _id: string;
31
+ process: string;
32
+ teamAccount: TeamAccount;
33
+ created: number;
34
+ uid: string;
35
+ cid: string;
36
+ discussion: string;
37
+ currentPhase: string;
38
+ active?: boolean;
39
+ history?: any[];
40
+ name?: string;
41
+ followers?: string[];
42
+ completePhases?: string[];
43
+ location?: {
44
+ type: 'point' | 'area' | 'polyline';
45
+ label: string | null;
46
+ data: {
47
+ lat: number;
48
+ lng: number;
49
+ }[];
50
+ };
51
+ fields?: any;
52
+ files?: any[];
53
+ updated?: number;
54
+ updatedBy?: string;
55
+ priority?: number;
56
+ sequence?: number;
57
+ }
58
+ export interface TeamAccount {
59
+ account: string;
60
+ team: string;
61
+ }
62
+ export interface FormsData {
63
+ files: string[];
64
+ history: {
65
+ 0: {
66
+ [fieldId: string]: {
67
+ value: any;
68
+ };
69
+ };
70
+ };
71
+ name: string;
72
+ location?: boolean;
73
+ uid?: string;
74
+ }
75
+ export interface FormsResponse {
76
+ name: string;
77
+ description?: string;
78
+ enableUnlinkedMode: boolean;
79
+ enableAttachments: boolean;
80
+ enableMapLocation: boolean;
81
+ locationRequired: 1;
82
+ phases: {
83
+ _id: string;
84
+ followers: [];
85
+ name: string;
86
+ description: string;
87
+ uid: string;
88
+ created: number;
89
+ fields: string[];
90
+ announcementFields: [];
91
+ announcementRecipients: [];
92
+ announcementFieldsOrder: [];
93
+ isEndpoint: boolean;
94
+ }[];
95
+ phasesOrder: string[];
96
+ fields: {
97
+ [id: string]: {
98
+ data: [];
99
+ label: string;
100
+ required: boolean;
101
+ type: string;
102
+ inviteToDiscussionOnChange: boolean;
103
+ _id: string;
104
+ created: number;
105
+ updated: number;
106
+ uid: string;
107
+ functionEnabled: boolean;
108
+ };
109
+ };
110
+ enableMessenger: boolean;
111
+ publicForm: {
112
+ enableMessaging: boolean;
113
+ };
114
+ fieldsOrder: [];
115
+ }
116
+ export interface FormCreateResponse {
117
+ key: string;
118
+ creator: string;
119
+ followers: string;
120
+ active: boolean;
121
+ enableMessaging: boolean;
122
+ allowRead: boolean;
123
+ }
124
+ export interface InsightResponse {
125
+ insight: {
126
+ name: string;
127
+ };
128
+ data: InsightResponseData;
129
+ }
130
+ export interface InsightResponseData {
131
+ headers: string[];
132
+ rows: [];
133
+ time: number;
134
+ }
135
+ export interface HailerAppConfig {
136
+ fields?: {
137
+ [fieldName: string]: {
138
+ type: string;
139
+ value?: string | number | boolean;
140
+ };
141
+ };
142
+ }
143
+ export type HailerProcess = Workflow;
144
+ export interface Workflow {
145
+ _id: string;
146
+ cid: string;
147
+ name: string;
148
+ description?: string;
149
+ fields: {
150
+ [fieldId: string]: any;
151
+ };
152
+ phases: {
153
+ [phase_id: string]: WorkflowPhase;
154
+ };
155
+ phasesOrder: string[];
156
+ }
157
+ export interface WorkflowPhase {
158
+ _id: string;
159
+ name: string;
160
+ description?: string;
161
+ }
162
+ export type PermissionType = 'admin' | 'own' | 'ownteam' | 'any' | 'edit';
163
+ export interface Member {
164
+ id: string;
165
+ info: {
166
+ [key: string]: string | number | boolean | null;
167
+ };
168
+ permissions: PermissionType[];
169
+ }
170
+ export interface InsightWorkflowSource {
171
+ name: string;
172
+ workflowId: string;
173
+ fields: {
174
+ name: string;
175
+ fieldId?: string;
176
+ /** Used for phaseLastMove meta */
177
+ phaseId?: string;
178
+ /** Activity information, like _id, created, phaseId etc. */
179
+ meta?: string;
180
+ }[];
181
+ }
182
+ export interface InsightDoc {
183
+ name: string;
184
+ sources: InsightWorkflowSource[];
185
+ cid: string;
186
+ /** User id of creator */
187
+ uid: string;
188
+ members: Member[];
189
+ updated: number;
190
+ public: boolean;
191
+ /** Key for accessing Insight when set to public */
192
+ publicKey?: string;
193
+ /** sandboxed javascript with access to all activities in given workflows */
194
+ function?: string;
195
+ /** To be used with SQLite if we want to.... */
196
+ query?: string;
197
+ }
198
+ export interface InsightData {
199
+ headers: string[];
200
+ rows: (string | number | null)[][];
201
+ time: number;
202
+ }
203
+ export interface InsightResponseAsObjectItem {
204
+ [key: string]: any;
205
+ }
206
+ export type InsightResponseAsObjects = InsightResponseAsObjectItem[];
207
+ export interface KanbanListResponse {
208
+ map: {
209
+ [phaseId: string]: {
210
+ activities: {
211
+ _id: string;
212
+ followers: string[];
213
+ name: string;
214
+ fields: {
215
+ [key: string]: any;
216
+ };
217
+ files: string[];
218
+ primaryDateField: number;
219
+ priority: number;
220
+ }[];
221
+ meta: {
222
+ count: number;
223
+ totalPrimaryNumericValue: number;
224
+ primaryNumericFieldUnit: string | null;
225
+ };
226
+ };
227
+ };
228
+ }
229
+ export interface KanbanLoadResponse {
230
+ activity: {
231
+ _id: string;
232
+ followers: string[];
233
+ name: string;
234
+ fields: {
235
+ [key: string]: any;
236
+ };
237
+ files: string[];
238
+ primaryDateField: number | null;
239
+ priority: number;
240
+ linkedFromCount: number;
241
+ };
242
+ process: string;
243
+ phase: string;
244
+ }
245
+ export interface ActivityListOptions {
246
+ sortBy?: 'name' | 'created' | 'updated' | 'following' | 'owner' | 'team' | 'completedOn' | 'priority';
247
+ sortOrder?: 'asc' | 'desc';
248
+ limit?: number;
249
+ skip?: number;
250
+ includeUsers?: boolean;
251
+ includeTeams?: boolean;
252
+ includeHistory?: boolean;
253
+ filters?: any;
254
+ }
255
+ export interface ActivityCreateOptions {
256
+ teamId?: string;
257
+ fileIds?: string[];
258
+ followerIds?: string[];
259
+ location?: {
260
+ label?: string;
261
+ type: 'area' | 'point' | 'polyline';
262
+ data: [{
263
+ lat: number;
264
+ lng: number;
265
+ }];
266
+ };
267
+ discussionId?: string;
268
+ phaseId?: string;
269
+ returnDocument?: boolean;
270
+ }
271
+ export interface ActivityKanbanListOptions {
272
+ filter: {
273
+ user?: {
274
+ uid: string;
275
+ field: string;
276
+ };
277
+ account?: string;
278
+ team?: string;
279
+ dates?: {
280
+ field: string;
281
+ start: number;
282
+ end: number;
283
+ };
284
+ };
285
+ search?: string;
286
+ limit?: number;
287
+ skip?: number;
288
+ phase?: string;
289
+ includeUsers?: boolean;
290
+ includeTeams?: boolean;
291
+ }
292
+ export interface HailerSettings {
293
+ theme: 'light' | 'dark';
294
+ preferredLanguages: string[];
295
+ }
296
+ export interface HailerError {
297
+ code: number;
298
+ msg: string;
299
+ debug: object;
300
+ }
301
+ export interface HailerApiInfo {
302
+ /** Url of the Hailer instance hosting the API */
303
+ hostUrl?: string;
304
+ config?: HailerAppConfig;
305
+ outside: boolean | null;
306
+ }
307
+ export declare class HailerError extends Error {
308
+ code: number;
309
+ msg: string;
310
+ debug: object;
311
+ constructor(error: {
312
+ code: number;
313
+ msg: string;
314
+ debug: object;
315
+ });
316
+ }
317
+ export interface HailerSignal {
318
+ sig: string;
319
+ meta: any;
320
+ }
package/lib/types.js ADDED
@@ -0,0 +1,9 @@
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
+ }
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@hailer/app-sdk",
3
+ "version": "1.0.0-beta",
4
+ "description": "SDK for building Hailer Apps",
5
+ "author": "",
6
+ "license": "ISC",
7
+ "main": "./lib/index.js",
8
+ "types": "./lib/index.d.ts",
9
+ "files": [
10
+ "./lib/**/*"
11
+ ],
12
+ "scripts": {
13
+ "build": "tsc",
14
+ "docs": "typedoc --entryPointStrategy expand ./src && open-cli ./docs/index.html"
15
+ },
16
+ "dependencies": {
17
+ "@wishcore/wish-rpc": "0.6.11"
18
+ },
19
+ "devDependencies": {
20
+ "@types/node": "^18.15.10",
21
+ "@typescript-eslint/eslint-plugin": "^5.60.0",
22
+ "@typescript-eslint/parser": "^5.60.0",
23
+ "eslint": "^8.43.0",
24
+ "open-cli": "^7.2.0",
25
+ "typedoc": "^0.24.8",
26
+ "typescript": "^5.1.3"
27
+ }
28
+ }