@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.
Files changed (40) 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 +74 -0
  5. package/lib/hailer-api.js +163 -0
  6. package/lib/index.d.ts +2 -0
  7. package/lib/index.js +2 -0
  8. package/lib/modules/activity/kanban.d.ts +38 -0
  9. package/lib/modules/activity/kanban.js +77 -0
  10. package/lib/modules/activity.d.ts +83 -0
  11. package/lib/modules/activity.js +130 -0
  12. package/lib/modules/insight.d.ts +27 -0
  13. package/lib/modules/insight.js +54 -0
  14. package/lib/modules/network.d.ts +14 -0
  15. package/lib/modules/network.js +33 -0
  16. package/lib/modules/process.d.ts +40 -0
  17. package/lib/modules/process.js +77 -0
  18. package/lib/modules/public/app.d.ts +17 -0
  19. package/lib/modules/public/app.js +45 -0
  20. package/lib/modules/public/form.d.ts +31 -0
  21. package/lib/modules/public/form.js +68 -0
  22. package/lib/modules/public/insight.d.ts +30 -0
  23. package/lib/modules/public/insight.js +69 -0
  24. package/lib/modules/public.d.ts +16 -0
  25. package/lib/modules/public.js +13 -0
  26. package/lib/modules/ui/activity.d.ts +25 -0
  27. package/lib/modules/ui/activity.js +28 -0
  28. package/lib/modules/ui/files.d.ts +18 -0
  29. package/lib/modules/ui/files.js +36 -0
  30. package/lib/modules/ui/snackbar.d.ts +19 -0
  31. package/lib/modules/ui/snackbar.js +32 -0
  32. package/lib/modules/ui.d.ts +11 -0
  33. package/lib/modules/ui.js +11 -0
  34. package/lib/modules/user.d.ts +39 -0
  35. package/lib/modules/user.js +76 -0
  36. package/lib/modules/workflow.d.ts +25 -0
  37. package/lib/modules/workflow.js +54 -0
  38. package/lib/types.d.ts +326 -0
  39. package/lib/types.js +9 -0
  40. package/package.json +28 -0
@@ -0,0 +1,32 @@
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
+ }
@@ -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,39 @@
1
+ import { Client } from '@wishcore/wish-rpc';
2
+ import { HailerUser } from '../types';
3
+ export declare class User {
4
+ private client;
5
+ constructor(client: Client);
6
+ /**
7
+ * Returns the specified user
8
+ *
9
+ * @param userId id of the Hailer user
10
+ * @param options object containing apiVersion option
11
+ *
12
+ * @returns Hailer user information
13
+ *
14
+ * @throws {HailerError} if request is incorrect
15
+ */
16
+ get(userId: string): Promise<HailerUser>;
17
+ /**
18
+ * Returns the current user
19
+ *
20
+ * @param options object containing apiVersion option
21
+ *
22
+ * @returns the current Hailer user information
23
+ *
24
+ * @throws {HailerError} if request is incorrect
25
+ */
26
+ current(): Promise<HailerUser>;
27
+ /**
28
+ * Lists all Hailer users from a workspace
29
+ *
30
+ * @param options object containing apiVersion option
31
+ *
32
+ * @returns list of Hailer users in the workspace the app user is currently in
33
+ *
34
+ * @throws {HailerError} if request is incorrect
35
+ */
36
+ list(): Promise<{
37
+ [key: string]: HailerUser;
38
+ }>;
39
+ }
@@ -0,0 +1,76 @@
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
+ }
@@ -0,0 +1,25 @@
1
+ import { Client } from '@wishcore/wish-rpc';
2
+ import { HailerProcess } from '../types';
3
+ export declare class Workflow {
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<HailerProcess[]>;
14
+ /**
15
+ * Gets a single process from a workspace
16
+ *
17
+ * @param processId the id of the process in question
18
+ * @param options object containing apiVersion option
19
+ *
20
+ * @returns the specified Hailer process
21
+ *
22
+ * @throws {HailerError} if request is incorrect
23
+ */
24
+ get(processId: string): Promise<HailerProcess>;
25
+ }
@@ -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 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.d.ts ADDED
@@ -0,0 +1,326 @@
1
+ export interface HailerUser {
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 HailerWorkspace {
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 HailerActivity {
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 Link {
63
+ id: string;
64
+ linkId: string;
65
+ type: LinkType;
66
+ created: string;
67
+ }
68
+ export type LinkType = 'user-mention' | 'reaction' | 'tag' | 'apple-id' | 'feed.lastseen' | 'google-folder-id';
69
+ export interface FormsData {
70
+ files: string[];
71
+ history: {
72
+ 0: {
73
+ [fieldId: string]: {
74
+ value: any;
75
+ };
76
+ };
77
+ };
78
+ name: string;
79
+ location?: boolean;
80
+ uid?: string;
81
+ }
82
+ export interface FormsResponse {
83
+ name: string;
84
+ description?: string;
85
+ enableUnlinkedMode: boolean;
86
+ enableAttachments: boolean;
87
+ enableMapLocation: boolean;
88
+ locationRequired: 1;
89
+ phases: {
90
+ _id: string;
91
+ followers: [];
92
+ name: string;
93
+ description: string;
94
+ uid: string;
95
+ created: number;
96
+ fields: string[];
97
+ announcementFields: [];
98
+ announcementRecipients: [];
99
+ announcementFieldsOrder: [];
100
+ isEndpoint: boolean;
101
+ }[];
102
+ phasesOrder: string[];
103
+ fields: {
104
+ [id: string]: {
105
+ data: [];
106
+ label: string;
107
+ required: boolean;
108
+ type: string;
109
+ inviteToDiscussionOnChange: boolean;
110
+ _id: string;
111
+ created: number;
112
+ updated: number;
113
+ uid: string;
114
+ functionEnabled: boolean;
115
+ };
116
+ };
117
+ enableMessenger: boolean;
118
+ publicForm: {
119
+ enableMessaging: boolean;
120
+ };
121
+ fieldsOrder: [];
122
+ }
123
+ export interface FormCreateResponse {
124
+ key: string;
125
+ creator: string;
126
+ followers: string;
127
+ active: boolean;
128
+ enableMessaging: boolean;
129
+ allowRead: boolean;
130
+ }
131
+ export interface InsightResponse {
132
+ insight: {
133
+ name: string;
134
+ };
135
+ data: InsightResponseData;
136
+ }
137
+ export interface InsightResponseData {
138
+ headers: string[];
139
+ rows: [];
140
+ time: number;
141
+ }
142
+ export interface HailerAppConfig {
143
+ fields?: {
144
+ [fieldName: string]: {
145
+ type: string;
146
+ value?: string | number | boolean;
147
+ };
148
+ };
149
+ }
150
+ export interface HailerProcess {
151
+ _id: string;
152
+ cid: string;
153
+ name: string;
154
+ description?: string;
155
+ fields: {
156
+ [fieldId: string]: any;
157
+ };
158
+ phases: {
159
+ [phase_id: string]: HailerPhase;
160
+ };
161
+ }
162
+ export interface HailerPhase {
163
+ _id: string;
164
+ name: string;
165
+ description?: string;
166
+ }
167
+ export type PermissionType = 'admin' | 'own' | 'ownteam' | 'any' | 'edit';
168
+ export interface MemberDoc {
169
+ id: string;
170
+ info: {
171
+ [key: string]: string | number | boolean | null;
172
+ };
173
+ permissions: PermissionType[];
174
+ }
175
+ export interface InsightWorkflowSource {
176
+ name: string;
177
+ workflowId: string;
178
+ fields: {
179
+ name: string;
180
+ fieldId?: string;
181
+ /** Used for phaseLastMove meta */
182
+ phaseId?: string;
183
+ /** Activity information, like _id, created, phaseId etc. */
184
+ meta?: string;
185
+ }[];
186
+ }
187
+ export interface InsightDoc {
188
+ name: string;
189
+ sources: InsightWorkflowSource[];
190
+ cid: string;
191
+ /** User id of creator */
192
+ uid: string;
193
+ members: MemberDoc[];
194
+ updated: number;
195
+ public: boolean;
196
+ /** Key for accessing Insight when set to public */
197
+ publicKey?: string;
198
+ /** sandboxed javascript with access to all activities in given workflows */
199
+ function?: string;
200
+ /** To be used with SQLite if we want to.... */
201
+ query?: string;
202
+ }
203
+ export interface InsightData {
204
+ headers: string[];
205
+ rows: (string | number | null)[][];
206
+ time: number;
207
+ }
208
+ export interface InsightResponseAsObjectItem {
209
+ [key: string]: any;
210
+ }
211
+ export type InsightResponseAsObjects = InsightResponseAsObjectItem[];
212
+ export interface KanbanListResponse {
213
+ map: {
214
+ [phaseId: string]: {
215
+ activities: {
216
+ _id: string;
217
+ followers: string[];
218
+ name: string;
219
+ fields: {
220
+ [key: string]: any;
221
+ };
222
+ files: string[];
223
+ primaryDateField: number;
224
+ priority: number;
225
+ }[];
226
+ meta: {
227
+ count: number;
228
+ totalPrimaryNumericValue: number;
229
+ primaryNumericFieldUnit: string | null;
230
+ };
231
+ };
232
+ };
233
+ }
234
+ export interface KanbanLoadResponse {
235
+ activity: {
236
+ _id: string;
237
+ followers: string[];
238
+ name: string;
239
+ fields: {
240
+ [key: string]: any;
241
+ };
242
+ files: string[];
243
+ primaryDateField: number | null;
244
+ priority: number;
245
+ linkedFromCount: number;
246
+ };
247
+ process: string;
248
+ phase: string;
249
+ }
250
+ export interface ActivityListOptions {
251
+ sortBy?: 'name' | 'created' | 'updated' | 'following' | 'owner' | 'team' | 'completedOn' | 'priority';
252
+ sortOrder?: 'asc' | 'desc';
253
+ limit?: number;
254
+ skip?: number;
255
+ includeUsers?: boolean;
256
+ includeTeams?: boolean;
257
+ includeHistory?: boolean;
258
+ filters?: any;
259
+ }
260
+ export interface ActivityCreateOptions {
261
+ teamId?: string;
262
+ fileIds?: string[];
263
+ followerIds?: string[];
264
+ location?: {
265
+ label?: string;
266
+ type: 'area' | 'point' | 'polyline';
267
+ data: [{
268
+ lat: number;
269
+ lng: number;
270
+ }];
271
+ };
272
+ discussionId?: string;
273
+ phaseId?: string;
274
+ returnDocument?: boolean;
275
+ }
276
+ export interface ActivityKanbanListOptions {
277
+ filter: {
278
+ user?: {
279
+ uid: string;
280
+ field: string;
281
+ };
282
+ account?: string;
283
+ team?: string;
284
+ dates?: {
285
+ field: string;
286
+ start: number;
287
+ end: number;
288
+ };
289
+ };
290
+ search?: string;
291
+ limit?: number;
292
+ skip?: number;
293
+ phase?: string;
294
+ includeUsers?: boolean;
295
+ includeTeams?: boolean;
296
+ }
297
+ export type ApiVersion = 1;
298
+ export interface HailerSettings {
299
+ theme: 'light' | 'dark';
300
+ preferredLanguages: string[];
301
+ }
302
+ export interface HailerError {
303
+ code: number;
304
+ msg: string;
305
+ debug: object;
306
+ }
307
+ export interface HailerApiInfo {
308
+ /** Url of the Hailer instance hosting the API */
309
+ hostUrl?: string;
310
+ config?: HailerAppConfig;
311
+ outside: boolean | null;
312
+ }
313
+ export declare class HailerError extends Error {
314
+ code: number;
315
+ msg: string;
316
+ debug: object;
317
+ constructor(error: {
318
+ code: number;
319
+ msg: string;
320
+ debug: object;
321
+ });
322
+ }
323
+ export interface HailerSignal {
324
+ sig: string;
325
+ meta: any;
326
+ }
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",
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
+ }