@neuralinnovations/dataisland-sdk 0.0.1-dev1 → 0.0.1-dev10

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 (74) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +174 -1
  3. package/dist/dataisland-sdk.d.ts +1594 -0
  4. package/dist/dataisland-sdk.js +2890 -0
  5. package/dist/dataisland-sdk.js.map +1 -0
  6. package/index.d.ts +1 -0
  7. package/index.js +1 -0
  8. package/package.json +41 -3
  9. package/src/appBuilder.ts +24 -5
  10. package/src/commands/startCommandHandler.ts +14 -0
  11. package/src/context.ts +31 -0
  12. package/src/credentials.ts +31 -9
  13. package/src/dataIslandApp.ts +59 -0
  14. package/src/disposable.ts +4 -5
  15. package/src/dto/accessGroupResponse.ts +35 -0
  16. package/src/dto/chatResponse.ts +103 -0
  17. package/src/dto/userInfoResponse.ts +47 -0
  18. package/src/dto/workspacesResponse.ts +49 -0
  19. package/src/events.ts +13 -17
  20. package/src/index.ts +44 -18
  21. package/src/internal/app.impl.ts +97 -32
  22. package/src/internal/appBuilder.impl.ts +39 -12
  23. package/src/internal/createApp.impl.ts +5 -5
  24. package/src/middleware.ts +1 -1
  25. package/src/services/commandService.ts +44 -0
  26. package/src/services/credentialService.ts +3 -3
  27. package/src/services/middlewareService.ts +8 -6
  28. package/src/services/organizationService.ts +28 -0
  29. package/src/services/requestBuilder.ts +127 -0
  30. package/src/services/responseUtils.ts +32 -0
  31. package/src/services/rpcService.ts +129 -52
  32. package/src/services/service.ts +10 -8
  33. package/src/services/userProfileService.ts +38 -0
  34. package/src/storages/chats/answer.impl.ts +163 -0
  35. package/src/storages/chats/answer.ts +42 -0
  36. package/src/storages/chats/chat.impl.ts +87 -0
  37. package/src/storages/chats/chat.ts +38 -0
  38. package/src/storages/chats/chats.impl.ts +142 -0
  39. package/src/storages/chats/chats.ts +47 -0
  40. package/src/storages/files/file.impl.ts +69 -0
  41. package/src/storages/files/file.ts +28 -0
  42. package/src/storages/files/files.impl.ts +213 -0
  43. package/src/storages/files/files.ts +38 -0
  44. package/src/storages/files/filesPage.ts +27 -0
  45. package/src/storages/groups/groups.impl.ts +326 -0
  46. package/src/storages/groups/groups.ts +101 -0
  47. package/src/storages/organizations/organization.impl.ts +95 -0
  48. package/src/storages/organizations/organization.ts +44 -0
  49. package/src/storages/organizations/organizations.impl.ts +197 -0
  50. package/src/storages/organizations/organizations.ts +56 -0
  51. package/src/storages/user/userProfile.impl.ts +56 -0
  52. package/src/storages/user/userProfile.ts +42 -0
  53. package/src/storages/workspaces/workspace.impl.ts +109 -0
  54. package/src/storages/workspaces/workspace.ts +49 -0
  55. package/src/storages/workspaces/workspaces.impl.ts +212 -0
  56. package/src/storages/workspaces/workspaces.ts +53 -0
  57. package/src/unitTest.ts +53 -0
  58. package/.browserslistrc +0 -5
  59. package/.editorconfig +0 -22
  60. package/.eslintrc.json +0 -44
  61. package/.github/workflows/publish-npm.yml +0 -28
  62. package/.prettierignore +0 -1
  63. package/.prettierrc +0 -11
  64. package/.yarnrc +0 -2
  65. package/babel.config.js +0 -6
  66. package/jest.config.ts +0 -199
  67. package/src/appSdk.ts +0 -40
  68. package/src/internal/context.ts +0 -13
  69. package/src/types.ts +0 -110
  70. package/test/disposable.test.ts +0 -39
  71. package/test/events.test.ts +0 -151
  72. package/test/index.test.ts +0 -83
  73. package/test/registry.test.ts +0 -44
  74. package/tsconfig.json +0 -31
@@ -0,0 +1,2890 @@
1
+ define("src/middleware", ["require", "exports"], function (require, exports) {
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ });
5
+ define("src/internal/registry", ["require", "exports"], function (require, exports) {
6
+ "use strict";
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.Registry = exports.RegistryItem = void 0;
9
+ class Provider {
10
+ }
11
+ class MethodProvider extends Provider {
12
+ constructor(provider, providerOnce = false) {
13
+ super();
14
+ this.provider = provider;
15
+ this.providerOnce = providerOnce;
16
+ this.provided = false;
17
+ }
18
+ provide() {
19
+ if (this.providerOnce && this.provided) {
20
+ return this.instance;
21
+ }
22
+ this.provided = true;
23
+ this.instance = this.provider();
24
+ return this.instance;
25
+ }
26
+ }
27
+ class ValueProvider extends Provider {
28
+ constructor(value) {
29
+ super();
30
+ this.value = value;
31
+ }
32
+ provide() {
33
+ return this.value;
34
+ }
35
+ }
36
+ class RegistryItem {
37
+ constructor(registry, type) {
38
+ this.registry = registry;
39
+ this.type = type;
40
+ }
41
+ asValue(value) {
42
+ this.registry.set(this.type, new ValueProvider(value));
43
+ }
44
+ asProvider(provider, oneTime = false) {
45
+ this.registry.set(this.type, new MethodProvider(provider, oneTime));
46
+ }
47
+ asFactory(provider) {
48
+ this.registry.set(this.type, new MethodProvider(provider, false));
49
+ }
50
+ asSingleton(provider) {
51
+ this.registry.set(this.type, new MethodProvider(provider, true));
52
+ }
53
+ }
54
+ exports.RegistryItem = RegistryItem;
55
+ class Registry {
56
+ constructor() {
57
+ this.services = new Map();
58
+ }
59
+ map(type) {
60
+ return new RegistryItem(this.services, type);
61
+ }
62
+ set(type, provider) {
63
+ this.services.set(type, provider);
64
+ }
65
+ get(type) {
66
+ const provider = this.services.get(type);
67
+ if (provider === undefined) {
68
+ return undefined;
69
+ }
70
+ return provider.provide();
71
+ }
72
+ }
73
+ exports.Registry = Registry;
74
+ });
75
+ define("src/disposable", ["require", "exports"], function (require, exports) {
76
+ "use strict";
77
+ Object.defineProperty(exports, "__esModule", { value: true });
78
+ exports.disposable = exports.DisposableContainer = exports.Lifetime = void 0;
79
+ /**
80
+ * Represents a lifetime.
81
+ */
82
+ class Lifetime {
83
+ constructor(container) {
84
+ this.container = container;
85
+ }
86
+ /**
87
+ * Define a new nested disposable to this lifetime.
88
+ */
89
+ defineNested() {
90
+ return this.container.defineNested();
91
+ }
92
+ /**
93
+ * Shows whether this lifetime is disposed.
94
+ */
95
+ get isDisposed() {
96
+ return this.container.isDisposed;
97
+ }
98
+ /**
99
+ * Adds a disposable to this lifetime.
100
+ */
101
+ add(disposable) {
102
+ this.container.add(disposable);
103
+ return this;
104
+ }
105
+ /**
106
+ * Adds a callback to this lifetime.
107
+ */
108
+ addCallback(callback, target) {
109
+ this.container.addCallback(callback, target);
110
+ return this;
111
+ }
112
+ }
113
+ exports.Lifetime = Lifetime;
114
+ /**
115
+ * A container for disposables.
116
+ * Last added, first disposed.
117
+ * @example
118
+ * const container = new DisposableContainer();
119
+ * container.add(someDisposable);
120
+ * container.addCallback(() => console.log('disposed'));
121
+ * container.dispose();
122
+ */
123
+ class DisposableContainer {
124
+ constructor() {
125
+ this._disposables = [];
126
+ this._isDisposed = false;
127
+ }
128
+ /**
129
+ * Gets whether this container is disposed.
130
+ */
131
+ get isDisposed() {
132
+ return this._isDisposed;
133
+ }
134
+ /**
135
+ * Define new lifetime.
136
+ */
137
+ get lifetime() {
138
+ var _a;
139
+ return (_a = this._lifetime) !== null && _a !== void 0 ? _a : (this._lifetime = new Lifetime(this));
140
+ }
141
+ /**
142
+ * Adds a disposable to this container.
143
+ * @param disposable The disposable to add.
144
+ * @returns The disposable container.
145
+ */
146
+ add(disposable) {
147
+ this._throwIfDisposed();
148
+ this._disposables.push(disposable);
149
+ return disposable;
150
+ }
151
+ /**
152
+ * Adds a callback to be executed when this container is disposed.
153
+ * @param callback The callback to execute.
154
+ * @param target The target to bind the callback to.
155
+ * @returns The disposable container.
156
+ */
157
+ addCallback(callback, target) {
158
+ this._throwIfDisposed();
159
+ return this.add({
160
+ dispose() {
161
+ callback.call(target);
162
+ }
163
+ });
164
+ }
165
+ /**
166
+ * Defines a nested disposable container.
167
+ */
168
+ defineNested() {
169
+ const nested = new DisposableContainer();
170
+ this._disposables.push(nested);
171
+ nested.addCallback(() => {
172
+ const index = this._disposables.indexOf(nested);
173
+ if (index > -1) {
174
+ this._disposables.splice(index, 1);
175
+ }
176
+ }, this);
177
+ return nested;
178
+ }
179
+ /**
180
+ * Disposes all disposables in this container. Last added, first disposed.
181
+ */
182
+ dispose() {
183
+ this._throwIfDisposed();
184
+ this._isDisposed = true;
185
+ this._disposables
186
+ .slice()
187
+ .reverse()
188
+ .forEach(it => {
189
+ it.dispose();
190
+ });
191
+ this._disposables = [];
192
+ }
193
+ /**
194
+ * Throws an error if this container is disposed.
195
+ */
196
+ _throwIfDisposed() {
197
+ if (this._isDisposed) {
198
+ throw new Error("Object disposed");
199
+ }
200
+ }
201
+ }
202
+ exports.DisposableContainer = DisposableContainer;
203
+ /**
204
+ * Creates a disposable.
205
+ * @param action The action to execute when disposed.
206
+ * @param target The target to bind the action to.
207
+ * @returns The disposable.
208
+ */
209
+ function disposable(action, target) {
210
+ return new DisposableContainer().addCallback(() => {
211
+ action.call(target);
212
+ });
213
+ }
214
+ exports.disposable = disposable;
215
+ });
216
+ define("src/services/commandService", ["require", "exports", "tslib", "src/services/service"], function (require, exports, tslib_1, service_1) {
217
+ "use strict";
218
+ Object.defineProperty(exports, "__esModule", { value: true });
219
+ exports.CommandService = exports.Command = exports.CommandHandler = void 0;
220
+ class CommandHandler {
221
+ constructor(context) {
222
+ this.context = context;
223
+ }
224
+ resolve(type) {
225
+ return this.context.resolve(type);
226
+ }
227
+ }
228
+ exports.CommandHandler = CommandHandler;
229
+ class Command {
230
+ }
231
+ exports.Command = Command;
232
+ class CommandService extends service_1.Service {
233
+ constructor() {
234
+ super(...arguments);
235
+ this._registry = new Map();
236
+ this._lastPromise = Promise.resolve();
237
+ }
238
+ register(messageType, commandFactory) {
239
+ this._registry.set(messageType, commandFactory);
240
+ }
241
+ execute(message) {
242
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
243
+ const commandFactory = this._registry.get(message.constructor);
244
+ if (commandFactory) {
245
+ const command = commandFactory(this.context);
246
+ yield this._lastPromise;
247
+ this._lastPromise = command.execute(message);
248
+ yield this._lastPromise;
249
+ }
250
+ else {
251
+ throw new Error(`Command not found for message type ${message.constructor.name}`);
252
+ }
253
+ });
254
+ }
255
+ }
256
+ exports.CommandService = CommandService;
257
+ });
258
+ define("src/context", ["require", "exports", "tslib", "src/services/commandService"], function (require, exports, tslib_2, commandService_1) {
259
+ "use strict";
260
+ Object.defineProperty(exports, "__esModule", { value: true });
261
+ exports.Context = void 0;
262
+ /**
263
+ * DataIsland App context.
264
+ */
265
+ class Context {
266
+ constructor(registry, lifetime, appName) {
267
+ this.registry = registry;
268
+ this.lifetime = lifetime;
269
+ this.appName = appName;
270
+ }
271
+ /**
272
+ * Resolve a service from the context.
273
+ * @param type of the service
274
+ */
275
+ resolve(type) {
276
+ return this.registry.get(type);
277
+ }
278
+ /**
279
+ * Execute a command.
280
+ * @param command to execute
281
+ */
282
+ execute(command) {
283
+ return tslib_2.__awaiter(this, void 0, void 0, function* () {
284
+ const service = this.resolve(commandService_1.CommandService);
285
+ yield service.execute(command);
286
+ });
287
+ }
288
+ }
289
+ exports.Context = Context;
290
+ });
291
+ define("src/services/service", ["require", "exports", "tslib"], function (require, exports, tslib_3) {
292
+ "use strict";
293
+ Object.defineProperty(exports, "__esModule", { value: true });
294
+ exports.Service = exports.ServiceContext = void 0;
295
+ class ServiceContext {
296
+ constructor(context, disposableContainer) {
297
+ this.context = context;
298
+ this.disposableContainer = disposableContainer;
299
+ this.onRegister = () => tslib_3.__awaiter(this, void 0, void 0, function* () {
300
+ yield Promise.resolve();
301
+ });
302
+ this.onStart = () => tslib_3.__awaiter(this, void 0, void 0, function* () {
303
+ yield Promise.resolve();
304
+ });
305
+ this.onUnregister = () => {
306
+ // do nothing
307
+ };
308
+ }
309
+ get lifetime() {
310
+ return this.disposableContainer.lifetime;
311
+ }
312
+ resolve(type) {
313
+ return this.context.resolve(type);
314
+ }
315
+ }
316
+ exports.ServiceContext = ServiceContext;
317
+ class Service {
318
+ resolve(type) {
319
+ return this.serviceContext.resolve(type);
320
+ }
321
+ get lifetime() {
322
+ return this.serviceContext.lifetime;
323
+ }
324
+ get context() {
325
+ return this.serviceContext.context;
326
+ }
327
+ constructor(serviceContext) {
328
+ this.serviceContext = serviceContext;
329
+ }
330
+ }
331
+ exports.Service = Service;
332
+ });
333
+ define("src/services/middlewareService", ["require", "exports", "tslib", "src/services/service"], function (require, exports, tslib_4, service_2) {
334
+ "use strict";
335
+ Object.defineProperty(exports, "__esModule", { value: true });
336
+ exports.MiddlewareService = void 0;
337
+ class MiddlewareService extends service_2.Service {
338
+ constructor() {
339
+ super(...arguments);
340
+ this._middlewares = [];
341
+ }
342
+ useMiddleware(middleware) {
343
+ this._middlewares.push(middleware);
344
+ const result = this.lifetime.defineNested();
345
+ result.addCallback(() => {
346
+ this._middlewares = this._middlewares.filter(m => m !== middleware);
347
+ }, this);
348
+ return result;
349
+ }
350
+ process(req, next) {
351
+ return tslib_4.__awaiter(this, void 0, void 0, function* () {
352
+ const middlewares = this._middlewares.slice();
353
+ let index = -1;
354
+ const processNext = (request) => tslib_4.__awaiter(this, void 0, void 0, function* () {
355
+ index++;
356
+ if (index < middlewares.length) {
357
+ return yield middlewares[index](request, processNext);
358
+ }
359
+ else {
360
+ return yield next(request);
361
+ }
362
+ });
363
+ return yield processNext(req);
364
+ });
365
+ }
366
+ }
367
+ exports.MiddlewareService = MiddlewareService;
368
+ });
369
+ define("src/credentials", ["require", "exports", "tslib", "src/services/middlewareService"], function (require, exports, tslib_5, middlewareService_1) {
370
+ "use strict";
371
+ Object.defineProperty(exports, "__esModule", { value: true });
372
+ exports.BearerCredential = exports.DebugCredential = exports.BasicCredential = exports.DefaultCredential = exports.CredentialBase = void 0;
373
+ /**
374
+ * DataIsland App credential.
375
+ */
376
+ class CredentialBase {
377
+ }
378
+ exports.CredentialBase = CredentialBase;
379
+ class DefaultCredential extends CredentialBase {
380
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
381
+ onRegister(lifetime, context) {
382
+ // Do nothing.
383
+ }
384
+ }
385
+ exports.DefaultCredential = DefaultCredential;
386
+ class BasicCredential extends CredentialBase {
387
+ constructor(email, password) {
388
+ super();
389
+ this.email = email;
390
+ this.password = password;
391
+ }
392
+ onRegister(lifetime, context) {
393
+ const service = context.resolve(middlewareService_1.MiddlewareService);
394
+ if (service === undefined) {
395
+ throw new Error("MiddlewareService is not registered.");
396
+ }
397
+ lifetime.add(service.useMiddleware((req, next) => tslib_5.__awaiter(this, void 0, void 0, function* () {
398
+ req.headers.set("Authorization", `Basic ${this.email}:${this.password}`);
399
+ return yield next(req);
400
+ })));
401
+ }
402
+ }
403
+ exports.BasicCredential = BasicCredential;
404
+ class DebugCredential extends CredentialBase {
405
+ constructor(token) {
406
+ super();
407
+ this.token = token;
408
+ }
409
+ onRegister(lifetime, context) {
410
+ const service = context.resolve(middlewareService_1.MiddlewareService);
411
+ if (service === undefined) {
412
+ throw new Error("MiddlewareService is not registered.");
413
+ }
414
+ lifetime.add(service.useMiddleware((req, next) => tslib_5.__awaiter(this, void 0, void 0, function* () {
415
+ req.headers.set("Authorization", `Debug ${this.token}`);
416
+ return yield next(req);
417
+ })));
418
+ }
419
+ }
420
+ exports.DebugCredential = DebugCredential;
421
+ class BearerCredential extends CredentialBase {
422
+ constructor(token) {
423
+ super();
424
+ this.token = token;
425
+ }
426
+ onRegister(lifetime, context) {
427
+ const service = context.resolve(middlewareService_1.MiddlewareService);
428
+ if (service === undefined) {
429
+ throw new Error("MiddlewareService is not registered.");
430
+ }
431
+ lifetime.add(service.useMiddleware((req, next) => tslib_5.__awaiter(this, void 0, void 0, function* () {
432
+ req.headers.set("Authorization", `Bearer ${this.token}`);
433
+ return yield next(req);
434
+ })));
435
+ }
436
+ }
437
+ exports.BearerCredential = BearerCredential;
438
+ });
439
+ define("src/appBuilder", ["require", "exports"], function (require, exports) {
440
+ "use strict";
441
+ Object.defineProperty(exports, "__esModule", { value: true });
442
+ exports.AppBuilder = void 0;
443
+ /**
444
+ * DataIsland App builder.
445
+ */
446
+ class AppBuilder {
447
+ }
448
+ exports.AppBuilder = AppBuilder;
449
+ });
450
+ define("src/events", ["require", "exports", "src/disposable"], function (require, exports, disposable_1) {
451
+ "use strict";
452
+ Object.defineProperty(exports, "__esModule", { value: true });
453
+ exports.EventDispatcher = void 0;
454
+ class EventDispatcher {
455
+ constructor() {
456
+ this._listeners = [];
457
+ }
458
+ dispatch(input) {
459
+ this._listeners.slice().forEach(it => {
460
+ const value = {
461
+ type: input.type,
462
+ data: input.data,
463
+ unsubscribe: () => {
464
+ it.disposable.dispose();
465
+ }
466
+ };
467
+ it.callback(value);
468
+ });
469
+ }
470
+ subscribe(callback, type) {
471
+ const container = new disposable_1.DisposableContainer();
472
+ if (type !== undefined) {
473
+ const cb = callback;
474
+ const listener = (evt) => {
475
+ if (evt.type === type) {
476
+ cb(evt);
477
+ }
478
+ };
479
+ const value = {
480
+ callback: listener,
481
+ disposable: container
482
+ };
483
+ container.addCallback(() => {
484
+ this._listeners = this._listeners.filter(it => it !== value);
485
+ }, this);
486
+ this._listeners.push(value);
487
+ return container;
488
+ }
489
+ const value = {
490
+ callback,
491
+ disposable: container
492
+ };
493
+ container.addCallback(() => {
494
+ this._listeners = this._listeners.filter(it => it !== value);
495
+ }, this);
496
+ this._listeners.push(value);
497
+ return container;
498
+ }
499
+ }
500
+ exports.EventDispatcher = EventDispatcher;
501
+ });
502
+ define("src/dto/workspacesResponse", ["require", "exports"], function (require, exports) {
503
+ "use strict";
504
+ Object.defineProperty(exports, "__esModule", { value: true });
505
+ });
506
+ define("src/storages/files/file", ["require", "exports"], function (require, exports) {
507
+ "use strict";
508
+ Object.defineProperty(exports, "__esModule", { value: true });
509
+ exports.File = void 0;
510
+ /**
511
+ * File.
512
+ */
513
+ class File {
514
+ }
515
+ exports.File = File;
516
+ });
517
+ define("src/storages/files/filesPage", ["require", "exports"], function (require, exports) {
518
+ "use strict";
519
+ Object.defineProperty(exports, "__esModule", { value: true });
520
+ exports.FilesPage = void 0;
521
+ /**
522
+ * Files page.
523
+ */
524
+ class FilesPage {
525
+ }
526
+ exports.FilesPage = FilesPage;
527
+ });
528
+ define("src/storages/files/files", ["require", "exports", "src/events"], function (require, exports, events_1) {
529
+ "use strict";
530
+ Object.defineProperty(exports, "__esModule", { value: true });
531
+ exports.Files = exports.FilesEvent = void 0;
532
+ /**
533
+ * Files event.
534
+ */
535
+ var FilesEvent;
536
+ (function (FilesEvent) {
537
+ FilesEvent["ADDED"] = "added";
538
+ FilesEvent["REMOVED"] = "removed";
539
+ })(FilesEvent || (exports.FilesEvent = FilesEvent = {}));
540
+ /**
541
+ * Files storage.
542
+ */
543
+ class Files extends events_1.EventDispatcher {
544
+ }
545
+ exports.Files = Files;
546
+ });
547
+ define("src/storages/workspaces/workspace", ["require", "exports", "src/events"], function (require, exports, events_2) {
548
+ "use strict";
549
+ Object.defineProperty(exports, "__esModule", { value: true });
550
+ exports.Workspace = exports.WorkspaceEvent = void 0;
551
+ /**
552
+ * Workspace event.
553
+ */
554
+ var WorkspaceEvent;
555
+ (function (WorkspaceEvent) {
556
+ WorkspaceEvent["CHANGED"] = "changed";
557
+ })(WorkspaceEvent || (exports.WorkspaceEvent = WorkspaceEvent = {}));
558
+ /**
559
+ * Workspace.
560
+ */
561
+ class Workspace extends events_2.EventDispatcher {
562
+ }
563
+ exports.Workspace = Workspace;
564
+ });
565
+ define("src/storages/workspaces/workspaces", ["require", "exports", "src/events"], function (require, exports, events_3) {
566
+ "use strict";
567
+ Object.defineProperty(exports, "__esModule", { value: true });
568
+ exports.Workspaces = exports.WorkspacesEvent = void 0;
569
+ /**
570
+ * Workspaces event.
571
+ */
572
+ var WorkspacesEvent;
573
+ (function (WorkspacesEvent) {
574
+ WorkspacesEvent["ADDED"] = "added";
575
+ WorkspacesEvent["REMOVED"] = "removed";
576
+ })(WorkspacesEvent || (exports.WorkspacesEvent = WorkspacesEvent = {}));
577
+ /**
578
+ * Organization's workspaces.
579
+ */
580
+ class Workspaces extends events_3.EventDispatcher {
581
+ }
582
+ exports.Workspaces = Workspaces;
583
+ });
584
+ define("src/dto/userInfoResponse", ["require", "exports"], function (require, exports) {
585
+ "use strict";
586
+ Object.defineProperty(exports, "__esModule", { value: true });
587
+ });
588
+ define("src/dto/accessGroupResponse", ["require", "exports"], function (require, exports) {
589
+ "use strict";
590
+ Object.defineProperty(exports, "__esModule", { value: true });
591
+ });
592
+ define("src/storages/groups/groups", ["require", "exports", "src/events"], function (require, exports, events_4) {
593
+ "use strict";
594
+ Object.defineProperty(exports, "__esModule", { value: true });
595
+ exports.Groups = exports.Group = exports.GroupEvent = void 0;
596
+ /**
597
+ * Group event.
598
+ */
599
+ var GroupEvent;
600
+ (function (GroupEvent) {
601
+ GroupEvent["ADDED"] = "added";
602
+ GroupEvent["REMOVED"] = "removed";
603
+ GroupEvent["UPDATED"] = "updated";
604
+ })(GroupEvent || (exports.GroupEvent = GroupEvent = {}));
605
+ /**
606
+ * Group.
607
+ */
608
+ class Group extends events_4.EventDispatcher {
609
+ }
610
+ exports.Group = Group;
611
+ /**
612
+ * Groups storage.
613
+ */
614
+ class Groups extends events_4.EventDispatcher {
615
+ }
616
+ exports.Groups = Groups;
617
+ });
618
+ define("src/dto/chatResponse", ["require", "exports"], function (require, exports) {
619
+ "use strict";
620
+ Object.defineProperty(exports, "__esModule", { value: true });
621
+ exports.StepTypeInfo = exports.StepType = exports.StepStatus = exports.AnswerStatus = void 0;
622
+ var AnswerStatus;
623
+ (function (AnswerStatus) {
624
+ AnswerStatus[AnswerStatus["RUNNING"] = 0] = "RUNNING";
625
+ AnswerStatus[AnswerStatus["SUCCESS"] = 1] = "SUCCESS";
626
+ AnswerStatus[AnswerStatus["CANCELED"] = 2] = "CANCELED";
627
+ AnswerStatus[AnswerStatus["FAIL"] = 3] = "FAIL";
628
+ })(AnswerStatus || (exports.AnswerStatus = AnswerStatus = {}));
629
+ var StepStatus;
630
+ (function (StepStatus) {
631
+ StepStatus[StepStatus["RUNNING"] = 0] = "RUNNING";
632
+ StepStatus[StepStatus["SUCCESS"] = 1] = "SUCCESS";
633
+ StepStatus[StepStatus["FAIL"] = 2] = "FAIL";
634
+ StepStatus[StepStatus["CANCELED"] = 3] = "CANCELED";
635
+ })(StepStatus || (exports.StepStatus = StepStatus = {}));
636
+ var StepType;
637
+ (function (StepType) {
638
+ StepType[StepType["PREPARE"] = 0] = "PREPARE";
639
+ StepType[StepType["SOURCES"] = 1] = "SOURCES";
640
+ StepType[StepType["GENERATE_ANSWER"] = 6] = "GENERATE_ANSWER";
641
+ StepType[StepType["FINALIZE_RESULT"] = 9] = "FINALIZE_RESULT";
642
+ StepType[StepType["DONE"] = 10] = "DONE";
643
+ })(StepType || (exports.StepType = StepType = {}));
644
+ class StepTypeInfo {
645
+ static hasTokens(type) {
646
+ switch (type) {
647
+ case StepType.GENERATE_ANSWER:
648
+ case StepType.DONE:
649
+ case StepType.FINALIZE_RESULT:
650
+ return true;
651
+ }
652
+ return false;
653
+ }
654
+ static hasSources(type) {
655
+ switch (type) {
656
+ case StepType.SOURCES:
657
+ return true;
658
+ }
659
+ return false;
660
+ }
661
+ }
662
+ exports.StepTypeInfo = StepTypeInfo;
663
+ });
664
+ define("src/storages/chats/answer", ["require", "exports"], function (require, exports) {
665
+ "use strict";
666
+ Object.defineProperty(exports, "__esModule", { value: true });
667
+ exports.Answer = void 0;
668
+ class Answer {
669
+ }
670
+ exports.Answer = Answer;
671
+ });
672
+ define("src/storages/chats/chat", ["require", "exports"], function (require, exports) {
673
+ "use strict";
674
+ Object.defineProperty(exports, "__esModule", { value: true });
675
+ exports.Chat = exports.ChatAnswerType = void 0;
676
+ var ChatAnswerType;
677
+ (function (ChatAnswerType) {
678
+ ChatAnswerType["SHORT"] = "short";
679
+ ChatAnswerType["LONG"] = "long";
680
+ })(ChatAnswerType || (exports.ChatAnswerType = ChatAnswerType = {}));
681
+ class Chat {
682
+ }
683
+ exports.Chat = Chat;
684
+ });
685
+ define("src/storages/chats/chats", ["require", "exports", "src/events"], function (require, exports, events_5) {
686
+ "use strict";
687
+ Object.defineProperty(exports, "__esModule", { value: true });
688
+ exports.Chats = exports.ChatsEvent = void 0;
689
+ var ChatsEvent;
690
+ (function (ChatsEvent) {
691
+ ChatsEvent["ADDED"] = "added";
692
+ ChatsEvent["REMOVED"] = "removed";
693
+ })(ChatsEvent || (exports.ChatsEvent = ChatsEvent = {}));
694
+ /**
695
+ * Chats storage.
696
+ */
697
+ class Chats extends events_5.EventDispatcher {
698
+ }
699
+ exports.Chats = Chats;
700
+ });
701
+ define("src/storages/organizations/organization", ["require", "exports"], function (require, exports) {
702
+ "use strict";
703
+ Object.defineProperty(exports, "__esModule", { value: true });
704
+ exports.Organization = void 0;
705
+ /**
706
+ * Organization.
707
+ */
708
+ class Organization {
709
+ }
710
+ exports.Organization = Organization;
711
+ });
712
+ define("src/storages/organizations/organizations", ["require", "exports", "src/events"], function (require, exports, events_6) {
713
+ "use strict";
714
+ Object.defineProperty(exports, "__esModule", { value: true });
715
+ exports.Organizations = exports.OrganizationsEvent = void 0;
716
+ /**
717
+ * Organization event.
718
+ */
719
+ var OrganizationsEvent;
720
+ (function (OrganizationsEvent) {
721
+ OrganizationsEvent["ADDED"] = "added";
722
+ OrganizationsEvent["REMOVED"] = "removed";
723
+ OrganizationsEvent["CURRENT_CHANGED"] = "currentChanged";
724
+ })(OrganizationsEvent || (exports.OrganizationsEvent = OrganizationsEvent = {}));
725
+ /**
726
+ * Organizations storage.
727
+ */
728
+ class Organizations extends events_6.EventDispatcher {
729
+ }
730
+ exports.Organizations = Organizations;
731
+ });
732
+ define("src/storages/user/userProfile", ["require", "exports", "src/events"], function (require, exports, events_7) {
733
+ "use strict";
734
+ Object.defineProperty(exports, "__esModule", { value: true });
735
+ exports.UserProfile = exports.UserEvent = void 0;
736
+ var UserEvent;
737
+ (function (UserEvent) {
738
+ UserEvent["CHANGED"] = "changed";
739
+ })(UserEvent || (exports.UserEvent = UserEvent = {}));
740
+ class UserProfile extends events_7.EventDispatcher {
741
+ }
742
+ exports.UserProfile = UserProfile;
743
+ });
744
+ define("src/dataIslandApp", ["require", "exports"], function (require, exports) {
745
+ "use strict";
746
+ Object.defineProperty(exports, "__esModule", { value: true });
747
+ exports.DataIslandApp = void 0;
748
+ /**
749
+ * DataIsland App instance.
750
+ */
751
+ class DataIslandApp {
752
+ }
753
+ exports.DataIslandApp = DataIslandApp;
754
+ });
755
+ define("package", [], {
756
+ "name": "@neuralinnovations/dataisland-sdk",
757
+ "version": "0.0.1-dev10",
758
+ "description": "SDK for DataIsland project",
759
+ "licenses": [
760
+ {
761
+ "type": "Apache-2.0",
762
+ "url": "https://www.apache.org/licenses/LICENSE-2.0.html"
763
+ }
764
+ ],
765
+ "repository": {
766
+ "type": "git",
767
+ "url": "https://github.com/NeuralInnovations/dataisland-client-js-sdk.git"
768
+ },
769
+ "publishConfig": {
770
+ "access": "public"
771
+ },
772
+ "exports": {
773
+ ".": "./dist/dataisland-sdk.js"
774
+ },
775
+ "main": "dist/dataisland-sdk.js",
776
+ "types": "dist/dataisland-sdk.d.ts",
777
+ "browser": "dist/dataisland-sdk.js",
778
+ "directories": {
779
+ "test": "test"
780
+ },
781
+ "files": [
782
+ "dist",
783
+ "src",
784
+ "index.js",
785
+ "index.d.ts"
786
+ ],
787
+ "engines": {
788
+ "node": ">=16"
789
+ },
790
+ "scripts": {
791
+ "build": "tsc",
792
+ "test": "jest --runInBand",
793
+ "lint": "eslint --ext .ts,.tsx src test",
794
+ "lint:fix": "eslint --fix --ext .ts,.tsx src test",
795
+ "docs": "typedoc --disableSources --includeVersion --plugin typedoc-plugin-markdown --out docs src/index.ts && node scripts/docs/index.js"
796
+ },
797
+ "keywords": [
798
+ "dataisland",
799
+ "sdk",
800
+ "neuralinnovations",
801
+ "neural innovations",
802
+ "neural-innovations",
803
+ "neural"
804
+ ],
805
+ "author": "Neural Innovations LTD",
806
+ "license": "Apache-2.0",
807
+ "bugs": {
808
+ "url": "https://github.com/NeuralInnovations/dataisland-client-js-sdk/issues"
809
+ },
810
+ "homepage": "https://github.com/NeuralInnovations/dataisland-client-js-sdk#readme",
811
+ "devDependencies": {
812
+ "@babel/core": "^7.22.11",
813
+ "@babel/plugin-transform-modules-commonjs": "7.22.11",
814
+ "@babel/preset-env": "^7.22.10",
815
+ "@babel/preset-typescript": "^7.23.3",
816
+ "@babel/register": "7.22.5",
817
+ "@jest/globals": "^29.7.0",
818
+ "@types/jest": "^29.5.11",
819
+ "@typescript-eslint/eslint-plugin": "^6.19.0",
820
+ "@typescript-eslint/parser": "^6.19.0",
821
+ "babel-jest": "^29.7.0",
822
+ "babel-loader": "8.3.0",
823
+ "eslint": "^8.56.0",
824
+ "eslint-config-semistandard": "^17.0.0",
825
+ "eslint-config-standard": "^17.1.0",
826
+ "eslint-config-standard-with-typescript": "^43.0.0",
827
+ "eslint-config-xo": "^0.43.1",
828
+ "eslint-config-xo-typescript": "^1.0.1",
829
+ "eslint-plugin-import": "^2.29.1",
830
+ "eslint-plugin-n": "^15.7.0",
831
+ "eslint-plugin-promise": "^6.1.1",
832
+ "eslint-plugin-react": "^7.33.2",
833
+ "glob": "7.2.3",
834
+ "jest": "^29.7.0",
835
+ "prettier": "2.8.7",
836
+ "ts-jest": "^29.1.1",
837
+ "ts-loader": "8.4.0",
838
+ "ts-node": "10.9.1",
839
+ "tslib": "^2.6.2",
840
+ "tslint": "6.1.3",
841
+ "typedoc": "^0.25.7",
842
+ "typedoc-plugin-markdown": "^3.17.1",
843
+ "typescript": "^5.3.3",
844
+ "watch": "^0.13.0",
845
+ "webpack": "5.76.0",
846
+ "yargs": "17.7.2"
847
+ },
848
+ "dependencies": {
849
+ "dotenv": "^16.3.2",
850
+ "jsdom": "^23.2.0"
851
+ }
852
+ });
853
+ define("src/unitTest", ["require", "exports", "tslib"], function (require, exports, tslib_6) {
854
+ "use strict";
855
+ Object.defineProperty(exports, "__esModule", { value: true });
856
+ exports.isUnitTest = exports.appTestCurrent = exports.appTest = exports.UnitTest = void 0;
857
+ var UnitTest;
858
+ (function (UnitTest) {
859
+ UnitTest[UnitTest["DO_NOTHING"] = 0] = "DO_NOTHING";
860
+ UnitTest[UnitTest["DO_NOT_START"] = 1] = "DO_NOT_START";
861
+ UnitTest[UnitTest["DO_NOT_PRINT_INITIALIZED_LOG"] = 2] = "DO_NOT_PRINT_INITIALIZED_LOG";
862
+ UnitTest[UnitTest["DEFAULT"] = 3] = "DEFAULT";
863
+ })(UnitTest || (exports.UnitTest = UnitTest = {}));
864
+ class AppSdkUnitTest {
865
+ static get current() {
866
+ return this._stack[this._stack.length - 1];
867
+ }
868
+ static test(unitTest = UnitTest.DEFAULT, func) {
869
+ return tslib_6.__awaiter(this, void 0, void 0, function* () {
870
+ this._stack.push(unitTest);
871
+ if (func) {
872
+ const result = func();
873
+ if (result) {
874
+ yield result;
875
+ }
876
+ AppSdkUnitTest.end();
877
+ }
878
+ });
879
+ }
880
+ static end() {
881
+ if (this._stack.length > 1) {
882
+ this._stack.pop();
883
+ }
884
+ }
885
+ }
886
+ AppSdkUnitTest._stack = [UnitTest.DO_NOTHING];
887
+ const appTest = (unitTest = UnitTest.DEFAULT, func) => tslib_6.__awaiter(void 0, void 0, void 0, function* () {
888
+ yield AppSdkUnitTest.test(unitTest, func);
889
+ });
890
+ exports.appTest = appTest;
891
+ const appTestCurrent = () => {
892
+ return AppSdkUnitTest.current;
893
+ };
894
+ exports.appTestCurrent = appTestCurrent;
895
+ const isUnitTest = (mask) => {
896
+ return (AppSdkUnitTest.current & mask) == mask;
897
+ };
898
+ exports.isUnitTest = isUnitTest;
899
+ });
900
+ define("src/internal/appBuilder.impl", ["require", "exports", "src/appBuilder", "src/index", "src/credentials", "src/unitTest"], function (require, exports, appBuilder_1, index_1, credentials_1, unitTest_1) {
901
+ "use strict";
902
+ Object.defineProperty(exports, "__esModule", { value: true });
903
+ exports.AppBuilderImplementation = void 0;
904
+ class AppBuilderImplementation extends appBuilder_1.AppBuilder {
905
+ constructor() {
906
+ super(...arguments);
907
+ this.envData = {
908
+ unitTest: unitTest_1.UnitTest.DO_NOTHING
909
+ };
910
+ this.host = index_1.DEFAULT_HOST;
911
+ this.automaticDataCollectionEnabled = true;
912
+ this.credential = new credentials_1.DefaultCredential();
913
+ this.middlewares = [];
914
+ this.services = [];
915
+ this.commands = [];
916
+ }
917
+ get env() {
918
+ return this.envData;
919
+ }
920
+ useHost(host) {
921
+ this.host = host !== null && host !== void 0 ? host : index_1.DEFAULT_HOST;
922
+ return this;
923
+ }
924
+ useAutomaticDataCollectionEnabled(value) {
925
+ if (value === undefined || value === null) {
926
+ throw new Error("useAutomaticDataCollectionEnabled, value is undefined|null");
927
+ }
928
+ this.automaticDataCollectionEnabled = value;
929
+ return this;
930
+ }
931
+ useCredential(credential) {
932
+ if (credential === undefined || credential === null) {
933
+ throw new Error("useCredential, credential is undefined|null");
934
+ }
935
+ this.credential = credential;
936
+ return this;
937
+ }
938
+ registerMiddleware(middleware) {
939
+ if (middleware === undefined || middleware === null) {
940
+ throw new Error("addMiddleware, middleware is undefined|null");
941
+ }
942
+ this.middlewares.push(middleware);
943
+ return this;
944
+ }
945
+ registerService(type, factory) {
946
+ if (type === undefined || type === null) {
947
+ throw new Error("registerService, type is undefined|null");
948
+ }
949
+ if (factory === undefined || factory === null) {
950
+ throw new Error("registerService, factory is undefined|null");
951
+ }
952
+ this.services.push([type, factory]);
953
+ return this;
954
+ }
955
+ registerCommand(messageType, commandFactory) {
956
+ if (messageType === undefined || messageType === null) {
957
+ throw new Error("registerCommand, messageType is undefined|null");
958
+ }
959
+ if (commandFactory === undefined || commandFactory === null) {
960
+ throw new Error("registerCommand, commandFactory is undefined|null");
961
+ }
962
+ this.commands.push([messageType, commandFactory]);
963
+ return this;
964
+ }
965
+ }
966
+ exports.AppBuilderImplementation = AppBuilderImplementation;
967
+ });
968
+ define("src/services/credentialService", ["require", "exports", "src/services/service"], function (require, exports, service_3) {
969
+ "use strict";
970
+ Object.defineProperty(exports, "__esModule", { value: true });
971
+ exports.CredentialService = void 0;
972
+ class CredentialService extends service_3.Service {
973
+ constructor() {
974
+ super(...arguments);
975
+ this._credentialDispose = undefined;
976
+ this._credential = undefined;
977
+ }
978
+ get credential() {
979
+ return this._credential;
980
+ }
981
+ useCredential(credential) {
982
+ if (credential !== this._credential) {
983
+ if (this._credentialDispose !== undefined) {
984
+ this._credentialDispose.dispose();
985
+ }
986
+ this._credentialDispose = this.lifetime.defineNested();
987
+ this._credential = credential;
988
+ credential.onRegister(this._credentialDispose.lifetime, this.context);
989
+ }
990
+ }
991
+ }
992
+ exports.CredentialService = CredentialService;
993
+ });
994
+ define("src/services/requestBuilder", ["require", "exports", "tslib"], function (require, exports, tslib_7) {
995
+ "use strict";
996
+ Object.defineProperty(exports, "__esModule", { value: true });
997
+ exports.RequestBuilder = void 0;
998
+ class RequestBuilder {
999
+ constructor(_url, _request) {
1000
+ this._url = _url;
1001
+ this._request = _request;
1002
+ this._headers = new Headers();
1003
+ this._searchParams = new URLSearchParams();
1004
+ }
1005
+ header(name, value) {
1006
+ this._headers.set(name, value);
1007
+ return this;
1008
+ }
1009
+ headers(headers) {
1010
+ if (headers === undefined) {
1011
+ return this;
1012
+ }
1013
+ if (headers instanceof Headers) {
1014
+ headers.forEach((value, name) => {
1015
+ this._headers.set(name, value);
1016
+ });
1017
+ }
1018
+ else {
1019
+ Object.entries(headers).forEach(([name, value]) => {
1020
+ this._headers.set(name, value);
1021
+ });
1022
+ }
1023
+ return this;
1024
+ }
1025
+ searchParam(name, value) {
1026
+ this._searchParams.set(name, value);
1027
+ return this;
1028
+ }
1029
+ searchParams(searchParams) {
1030
+ if (searchParams === undefined) {
1031
+ return this;
1032
+ }
1033
+ searchParams.forEach((value, name) => {
1034
+ this._searchParams.set(name, value);
1035
+ });
1036
+ return this;
1037
+ }
1038
+ sendPostFormData(body) {
1039
+ return tslib_7.__awaiter(this, void 0, void 0, function* () {
1040
+ const url = this._url;
1041
+ // set search params
1042
+ url.search = this._searchParams.toString();
1043
+ // create request
1044
+ const req = new Request(url, {
1045
+ method: "POST",
1046
+ headers: this._headers,
1047
+ body
1048
+ });
1049
+ // discard content type
1050
+ const reqAny = req;
1051
+ reqAny.discardContentType = true;
1052
+ return yield this._request(req);
1053
+ });
1054
+ }
1055
+ sendPostJson(body) {
1056
+ return tslib_7.__awaiter(this, void 0, void 0, function* () {
1057
+ const url = this._url;
1058
+ url.search = this._searchParams.toString();
1059
+ let json = null;
1060
+ if (body !== undefined && body !== null && typeof body === "object") {
1061
+ json = JSON.stringify(body);
1062
+ }
1063
+ const request = new Request(url, {
1064
+ method: "POST",
1065
+ headers: this._headers,
1066
+ body: json
1067
+ });
1068
+ return yield this._request(request);
1069
+ });
1070
+ }
1071
+ sendGet() {
1072
+ return tslib_7.__awaiter(this, void 0, void 0, function* () {
1073
+ const url = this._url;
1074
+ url.search = this._searchParams.toString();
1075
+ return yield this._request(new Request(url, {
1076
+ method: "GET",
1077
+ headers: this._headers
1078
+ }));
1079
+ });
1080
+ }
1081
+ sendDelete() {
1082
+ return tslib_7.__awaiter(this, void 0, void 0, function* () {
1083
+ const url = this._url;
1084
+ url.search = this._searchParams.toString();
1085
+ return yield this._request(new Request(url, {
1086
+ method: "DELETE",
1087
+ headers: this._headers
1088
+ }));
1089
+ });
1090
+ }
1091
+ sendPutJson(body) {
1092
+ return tslib_7.__awaiter(this, void 0, void 0, function* () {
1093
+ const url = this._url;
1094
+ url.search = this._searchParams.toString();
1095
+ let json = null;
1096
+ if (body !== undefined && body !== null && typeof body === "object") {
1097
+ json = JSON.stringify(body);
1098
+ }
1099
+ return yield this._request(new Request(url, {
1100
+ method: "PUT",
1101
+ headers: this._headers,
1102
+ body: json
1103
+ }));
1104
+ });
1105
+ }
1106
+ }
1107
+ exports.RequestBuilder = RequestBuilder;
1108
+ });
1109
+ define("src/services/rpcService", ["require", "exports", "tslib", "src/services/service", "src/services/middlewareService", "src/services/requestBuilder"], function (require, exports, tslib_8, service_4, middlewareService_2, requestBuilder_1) {
1110
+ "use strict";
1111
+ Object.defineProperty(exports, "__esModule", { value: true });
1112
+ exports.RpcService = void 0;
1113
+ /**
1114
+ * RPC service.
1115
+ */
1116
+ class RpcService extends service_4.Service {
1117
+ constructor(serviceContext,
1118
+ /**
1119
+ * Host of the RPC service.
1120
+ * It is not used if you use the `urlBuilder` option.
1121
+ */
1122
+ host,
1123
+ /**
1124
+ * Options for the RpcService.
1125
+ */
1126
+ options) {
1127
+ super(serviceContext);
1128
+ this.host = host;
1129
+ this.options = options;
1130
+ serviceContext.onRegister = () => tslib_8.__awaiter(this, void 0, void 0, function* () {
1131
+ var _a;
1132
+ (_a = serviceContext.resolve(middlewareService_2.MiddlewareService)) === null || _a === void 0 ? void 0 : _a.useMiddleware((req, next) => {
1133
+ if (!req.headers.has("accept")) {
1134
+ req.headers.set("accept", "text/plain");
1135
+ }
1136
+ if (req.discardContentType) {
1137
+ delete req.discardContentType;
1138
+ }
1139
+ else {
1140
+ req.headers.set("content-type", "application/json");
1141
+ }
1142
+ return next(req);
1143
+ });
1144
+ });
1145
+ }
1146
+ /**
1147
+ * Request method.
1148
+ */
1149
+ request(req) {
1150
+ var _a, _b, _c;
1151
+ return tslib_8.__awaiter(this, void 0, void 0, function* () {
1152
+ const middlewareService = this.resolve(middlewareService_2.MiddlewareService);
1153
+ if (middlewareService !== undefined) {
1154
+ return yield middlewareService.process(req, (req) => tslib_8.__awaiter(this, void 0, void 0, function* () {
1155
+ var _d, _e, _f;
1156
+ return (_f = (yield ((_e = (_d = this.options) === null || _d === void 0 ? void 0 : _d.fetchMethod) === null || _e === void 0 ? void 0 : _e.call(_d, req)))) !== null && _f !== void 0 ? _f : (yield fetch(req));
1157
+ }));
1158
+ }
1159
+ return (_c = (yield ((_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.fetchMethod) === null || _b === void 0 ? void 0 : _b.call(_a, req)))) !== null && _c !== void 0 ? _c : (yield fetch(req));
1160
+ });
1161
+ }
1162
+ /**
1163
+ * Build URL.
1164
+ * @param path
1165
+ */
1166
+ buildUrl(path) {
1167
+ if (this.options !== undefined && this.options.urlBuilder !== undefined) {
1168
+ return this.options.urlBuilder(path);
1169
+ }
1170
+ if (this.host.endsWith("/") && path.startsWith("/")) {
1171
+ return new URL(`${this.host}${path.slice(1)}`);
1172
+ }
1173
+ if (!this.host.endsWith("/") && !path.startsWith("/")) {
1174
+ return new URL(`${this.host}/${path}`);
1175
+ }
1176
+ return new URL(`${this.host}${path}`);
1177
+ }
1178
+ /**
1179
+ * Create a request builder.
1180
+ * @param path
1181
+ */
1182
+ requestBuilder(path) {
1183
+ return new requestBuilder_1.RequestBuilder(this.buildUrl(path), this.request.bind(this));
1184
+ }
1185
+ /**
1186
+ * Send a GET request.
1187
+ * @param path
1188
+ * @param options
1189
+ */
1190
+ get(path, options) {
1191
+ return tslib_8.__awaiter(this, void 0, void 0, function* () {
1192
+ return this.requestBuilder(path)
1193
+ .searchParams(options === null || options === void 0 ? void 0 : options.searchParams)
1194
+ .headers(options === null || options === void 0 ? void 0 : options.headers)
1195
+ .sendGet();
1196
+ });
1197
+ }
1198
+ /**
1199
+ * Send a POST request.
1200
+ * @param path
1201
+ * @param body JSON object
1202
+ * @param options
1203
+ */
1204
+ post(path, body, options) {
1205
+ return tslib_8.__awaiter(this, void 0, void 0, function* () {
1206
+ return this.requestBuilder(path)
1207
+ .searchParams(options === null || options === void 0 ? void 0 : options.searchParams)
1208
+ .headers(options === null || options === void 0 ? void 0 : options.headers)
1209
+ .sendPostJson(body);
1210
+ });
1211
+ }
1212
+ /**
1213
+ * Send a PUT request.
1214
+ * @param path
1215
+ * @param body JSON object
1216
+ * @param options
1217
+ */
1218
+ put(path, body, options) {
1219
+ return tslib_8.__awaiter(this, void 0, void 0, function* () {
1220
+ return this.requestBuilder(path)
1221
+ .searchParams(options === null || options === void 0 ? void 0 : options.searchParams)
1222
+ .headers(options === null || options === void 0 ? void 0 : options.headers)
1223
+ .sendPutJson(body);
1224
+ });
1225
+ }
1226
+ /**
1227
+ * Send a DELETE request.
1228
+ * @param path
1229
+ * @param options
1230
+ */
1231
+ delete(path, options) {
1232
+ return tslib_8.__awaiter(this, void 0, void 0, function* () {
1233
+ return this.requestBuilder(path)
1234
+ .searchParams(options === null || options === void 0 ? void 0 : options.searchParams)
1235
+ .headers(options === null || options === void 0 ? void 0 : options.headers)
1236
+ .sendDelete();
1237
+ });
1238
+ }
1239
+ }
1240
+ exports.RpcService = RpcService;
1241
+ });
1242
+ define("src/services/responseUtils", ["require", "exports", "tslib"], function (require, exports, tslib_9) {
1243
+ "use strict";
1244
+ Object.defineProperty(exports, "__esModule", { value: true });
1245
+ exports.ResponseUtils = void 0;
1246
+ class ResponseUtils {
1247
+ static isOk(response) {
1248
+ return response !== undefined && response !== null && response.ok;
1249
+ }
1250
+ static isFail(response) {
1251
+ return !ResponseUtils.isOk(response);
1252
+ }
1253
+ static throwError(message, response) {
1254
+ var _a;
1255
+ return tslib_9.__awaiter(this, void 0, void 0, function* () {
1256
+ if (response === undefined) {
1257
+ throw new Error(`${message}. Response is undefined`);
1258
+ }
1259
+ if (response === null) {
1260
+ throw new Error(`${message}. Response is null`);
1261
+ }
1262
+ let errorBody = "";
1263
+ if (response) {
1264
+ try {
1265
+ errorBody = (_a = (yield response.text())) !== null && _a !== void 0 ? _a : "";
1266
+ }
1267
+ catch (e) {
1268
+ console.error(e);
1269
+ }
1270
+ }
1271
+ throw new Error(`${message}. Response fail. Status: ${response === null || response === void 0 ? void 0 : response.status},${response === null || response === void 0 ? void 0 : response.statusText}, body: ${errorBody}`);
1272
+ });
1273
+ }
1274
+ }
1275
+ exports.ResponseUtils = ResponseUtils;
1276
+ });
1277
+ define("src/storages/files/file.impl", ["require", "exports", "tslib", "src/services/rpcService", "src/services/responseUtils", "src/storages/files/file"], function (require, exports, tslib_10, rpcService_1, responseUtils_1, file_1) {
1278
+ "use strict";
1279
+ Object.defineProperty(exports, "__esModule", { value: true });
1280
+ exports.FileImpl = void 0;
1281
+ class FileImpl extends file_1.File {
1282
+ constructor(context) {
1283
+ super();
1284
+ this.context = context;
1285
+ this._isDisposed = false;
1286
+ }
1287
+ initFrom(file) {
1288
+ this._content = file;
1289
+ return this;
1290
+ }
1291
+ get isDisposed() {
1292
+ return this._isDisposed;
1293
+ }
1294
+ dispose() {
1295
+ this._isDisposed = true;
1296
+ }
1297
+ get id() {
1298
+ var _a;
1299
+ return (_a = this._content) === null || _a === void 0 ? void 0 : _a.id;
1300
+ }
1301
+ get name() {
1302
+ var _a;
1303
+ return (_a = this._content) === null || _a === void 0 ? void 0 : _a.name;
1304
+ }
1305
+ url() {
1306
+ var _a;
1307
+ return tslib_10.__awaiter(this, void 0, void 0, function* () {
1308
+ const response = yield ((_a = this.context
1309
+ .resolve(rpcService_1.RpcService)) === null || _a === void 0 ? void 0 : _a.requestBuilder("api/v1/Files/url").searchParam("id", this.id).sendGet());
1310
+ if (responseUtils_1.ResponseUtils.isFail(response)) {
1311
+ yield responseUtils_1.ResponseUtils.throwError(`Failed to get file ${this.id} url`, response);
1312
+ }
1313
+ return (yield response.json()).url;
1314
+ });
1315
+ }
1316
+ status() {
1317
+ var _a;
1318
+ return tslib_10.__awaiter(this, void 0, void 0, function* () {
1319
+ const response = yield ((_a = this.context
1320
+ .resolve(rpcService_1.RpcService)) === null || _a === void 0 ? void 0 : _a.requestBuilder("api/v1/Files/fetch").searchParam("id", this.id).sendGet());
1321
+ if (responseUtils_1.ResponseUtils.isFail(response)) {
1322
+ yield responseUtils_1.ResponseUtils.throwError(`Failed to get file ${this.id}`, response);
1323
+ }
1324
+ const content = yield response.json();
1325
+ return content.progress;
1326
+ });
1327
+ }
1328
+ }
1329
+ exports.FileImpl = FileImpl;
1330
+ });
1331
+ define("src/storages/files/files.impl", ["require", "exports", "tslib", "src/services/rpcService", "src/storages/files/file.impl", "src/storages/files/files", "src/services/responseUtils", "src/storages/files/filesPage"], function (require, exports, tslib_11, rpcService_2, file_impl_1, files_1, responseUtils_2, filesPage_1) {
1332
+ "use strict";
1333
+ Object.defineProperty(exports, "__esModule", { value: true });
1334
+ exports.FilesImpl = exports.FilesPageImpl = void 0;
1335
+ class FilesPageImpl extends filesPage_1.FilesPage {
1336
+ constructor() {
1337
+ super(...arguments);
1338
+ this._isDisposed = false;
1339
+ this.files = [];
1340
+ this.total = 0;
1341
+ this.filesPerPage = 0;
1342
+ this.page = 0;
1343
+ }
1344
+ get pages() {
1345
+ return Math.ceil(Math.max(this.total / this.filesPerPage, 1.0));
1346
+ }
1347
+ get isDisposed() {
1348
+ return this._isDisposed;
1349
+ }
1350
+ dispose() {
1351
+ this._isDisposed = true;
1352
+ }
1353
+ }
1354
+ exports.FilesPageImpl = FilesPageImpl;
1355
+ class FilesImpl extends files_1.Files {
1356
+ constructor(workspace, context) {
1357
+ super();
1358
+ this.workspace = workspace;
1359
+ this.context = context;
1360
+ }
1361
+ upload(file) {
1362
+ return tslib_11.__awaiter(this, void 0, void 0, function* () {
1363
+ return yield this.internalUpload(file);
1364
+ });
1365
+ }
1366
+ delete(id) {
1367
+ return tslib_11.__awaiter(this, void 0, void 0, function* () {
1368
+ return yield this.internalDeleteFile(id);
1369
+ });
1370
+ }
1371
+ query(query, page, limit) {
1372
+ return tslib_11.__awaiter(this, void 0, void 0, function* () {
1373
+ return yield this.internalQuery(query, page, limit);
1374
+ });
1375
+ }
1376
+ //----------------------------------------------------------------------------
1377
+ // INTERNALS
1378
+ //----------------------------------------------------------------------------
1379
+ /**
1380
+ * Delete organization.
1381
+ * @param id
1382
+ */
1383
+ internalDeleteFile(id) {
1384
+ var _a;
1385
+ return tslib_11.__awaiter(this, void 0, void 0, function* () {
1386
+ if (id === undefined || id === null) {
1387
+ throw new Error("File delete, id is undefined or null");
1388
+ }
1389
+ if (id.length === 0 || id.trim().length === 0) {
1390
+ throw new Error("File delete, id is empty");
1391
+ }
1392
+ const response = yield ((_a = this.context
1393
+ .resolve(rpcService_2.RpcService)) === null || _a === void 0 ? void 0 : _a.requestBuilder("/api/v1/Files").searchParam("id", id).sendDelete());
1394
+ if (responseUtils_2.ResponseUtils.isFail(response)) {
1395
+ yield responseUtils_2.ResponseUtils.throwError(`File ${id} delete, failed`, response);
1396
+ }
1397
+ const file = this.filesList.files.find(f => f.id === id);
1398
+ const index = this.filesList.files.indexOf(file);
1399
+ if (index < 0) {
1400
+ throw new Error("Organization delete, index is not found");
1401
+ }
1402
+ // remove file from collection
1403
+ this.filesList.files.splice(index, 1);
1404
+ // dispatch event, file removed
1405
+ this.dispatch({
1406
+ type: files_1.FilesEvent.REMOVED,
1407
+ data: file
1408
+ });
1409
+ // dispose file
1410
+ file.dispose();
1411
+ });
1412
+ }
1413
+ internalQuery(query, page, limit) {
1414
+ var _a;
1415
+ return tslib_11.__awaiter(this, void 0, void 0, function* () {
1416
+ // check page
1417
+ if (page === undefined || page === null) {
1418
+ throw new Error("File fetch, page is undefined or null");
1419
+ }
1420
+ if (page < 0) {
1421
+ throw new Error("File fetch, page is negative");
1422
+ }
1423
+ // check limit
1424
+ if (limit === undefined || limit === null) {
1425
+ throw new Error("File fetch, limit is undefined or null");
1426
+ }
1427
+ if (limit === 0) {
1428
+ throw new Error("File fetch, limit is 0");
1429
+ }
1430
+ // send request to the server
1431
+ const response = yield ((_a = this.context
1432
+ .resolve(rpcService_2.RpcService)) === null || _a === void 0 ? void 0 : _a.requestBuilder("api/v1/Files/list").searchParam("workspaceId", this.workspace.id).searchParam("organizationId", this.workspace.organization.id).searchParam("query", query).searchParam("page", page.toString()).searchParam("limit", limit.toString()).sendGet());
1433
+ // check response status
1434
+ if (responseUtils_2.ResponseUtils.isFail(response)) {
1435
+ yield responseUtils_2.ResponseUtils.throwError(`Files fetch query:${query}, page:${page}, limit:${limit}, failed`, response);
1436
+ }
1437
+ // parse files from the server's response
1438
+ const files = (yield response.json());
1439
+ // create files list
1440
+ const filesList = new FilesPageImpl();
1441
+ filesList.total = files.totalFilesCount;
1442
+ filesList.filesPerPage = files.filesPerPage;
1443
+ filesList.page = page;
1444
+ // init files from the server's response
1445
+ for (const fl of files.files) {
1446
+ // create file implementation
1447
+ const file = new file_impl_1.FileImpl(this.context).initFrom(fl);
1448
+ // add file to the collection
1449
+ filesList.files.push(file);
1450
+ // dispatch event, file added
1451
+ this.dispatch({
1452
+ type: files_1.FilesEvent.ADDED,
1453
+ data: file
1454
+ });
1455
+ }
1456
+ // set files list
1457
+ this.filesList = filesList;
1458
+ return filesList;
1459
+ });
1460
+ }
1461
+ internalUpload(file) {
1462
+ var _a, _b;
1463
+ return tslib_11.__awaiter(this, void 0, void 0, function* () {
1464
+ // check file
1465
+ if (file === undefined || file === null) {
1466
+ throw new Error("File upload, file is undefined or null");
1467
+ }
1468
+ // form data to send
1469
+ const form = new FormData();
1470
+ form.append("organizationId", this.workspace.organization.id);
1471
+ form.append("workspaceId", this.workspace.id);
1472
+ form.append("name", file.name);
1473
+ form.append("file", file, file.name);
1474
+ // send request to the server
1475
+ const response = yield ((_a = this.context
1476
+ .resolve(rpcService_2.RpcService)) === null || _a === void 0 ? void 0 : _a.requestBuilder("api/v1/Files").sendPostFormData(form));
1477
+ // check response status
1478
+ if (responseUtils_2.ResponseUtils.isFail(response)) {
1479
+ yield responseUtils_2.ResponseUtils.throwError(`File upload ${file.name}`, response);
1480
+ }
1481
+ // parse file from the server's response
1482
+ const result = (yield response.json()).file;
1483
+ // create file implementation
1484
+ const fileImpl = new file_impl_1.FileImpl(this.context).initFrom(result);
1485
+ // TODO: why is this here?
1486
+ (_b = this.filesList) === null || _b === void 0 ? void 0 : _b.files.push(fileImpl);
1487
+ // dispatch event, file added
1488
+ this.dispatch({
1489
+ type: files_1.FilesEvent.ADDED,
1490
+ data: fileImpl
1491
+ });
1492
+ return fileImpl;
1493
+ });
1494
+ }
1495
+ }
1496
+ exports.FilesImpl = FilesImpl;
1497
+ });
1498
+ define("src/storages/workspaces/workspace.impl", ["require", "exports", "tslib", "src/storages/workspaces/workspace", "src/services/rpcService", "src/storages/files/files.impl", "src/services/responseUtils"], function (require, exports, tslib_12, workspace_1, rpcService_3, files_impl_1, responseUtils_3) {
1499
+ "use strict";
1500
+ Object.defineProperty(exports, "__esModule", { value: true });
1501
+ exports.WorkspaceImpl = void 0;
1502
+ class WorkspaceImpl extends workspace_1.Workspace {
1503
+ constructor(organization, context) {
1504
+ super();
1505
+ this.organization = organization;
1506
+ this.context = context;
1507
+ this._isMarkAsDeleted = false;
1508
+ this._files = new files_impl_1.FilesImpl(this, context);
1509
+ }
1510
+ get id() {
1511
+ if (this._workspace) {
1512
+ return this._workspace.id;
1513
+ }
1514
+ throw new Error("Workspace is not loaded.");
1515
+ }
1516
+ get name() {
1517
+ if (this._workspace) {
1518
+ return this._workspace.profile.name;
1519
+ }
1520
+ throw new Error("Workspace is not loaded.");
1521
+ }
1522
+ get description() {
1523
+ if (this._workspace) {
1524
+ return this._workspace.profile.description;
1525
+ }
1526
+ throw new Error("Workspace is not loaded.");
1527
+ }
1528
+ get files() {
1529
+ return this._files;
1530
+ }
1531
+ change(name, description) {
1532
+ var _a;
1533
+ return tslib_12.__awaiter(this, void 0, void 0, function* () {
1534
+ if (!this._workspace) {
1535
+ throw new Error("Workspace is not loaded.");
1536
+ }
1537
+ if (this._isMarkAsDeleted) {
1538
+ throw new Error("Workspace is marked as deleted.");
1539
+ }
1540
+ if (name === this.name && description === this.description) {
1541
+ return Promise.resolve();
1542
+ }
1543
+ if (name === undefined || name === null || name.trim() === "") {
1544
+ throw new Error("Name is required. Please provide a valid name.");
1545
+ }
1546
+ if (description === undefined ||
1547
+ description === null ||
1548
+ description.trim() === "") {
1549
+ throw new Error("Description is required. Please provide a valid description.");
1550
+ }
1551
+ const response = yield ((_a = this.context
1552
+ .resolve(rpcService_3.RpcService)) === null || _a === void 0 ? void 0 : _a.requestBuilder("api/v1/Workspaces").sendPutJson({
1553
+ workspaceId: this.id,
1554
+ profile: {
1555
+ name,
1556
+ description
1557
+ }
1558
+ }));
1559
+ if (responseUtils_3.ResponseUtils.isFail(response)) {
1560
+ yield responseUtils_3.ResponseUtils.throwError("Failed to change workspace", response);
1561
+ }
1562
+ if (this._workspace) {
1563
+ this._workspace.profile.name = name;
1564
+ this._workspace.profile.description = description;
1565
+ }
1566
+ this.dispatch({
1567
+ type: workspace_1.WorkspaceEvent.CHANGED,
1568
+ data: this
1569
+ });
1570
+ });
1571
+ }
1572
+ initFrom(workspace) {
1573
+ return tslib_12.__awaiter(this, void 0, void 0, function* () {
1574
+ this._workspace = workspace;
1575
+ });
1576
+ }
1577
+ get isMarkAsDeleted() {
1578
+ return this._isMarkAsDeleted;
1579
+ }
1580
+ markToDelete() {
1581
+ this._isMarkAsDeleted = true;
1582
+ }
1583
+ }
1584
+ exports.WorkspaceImpl = WorkspaceImpl;
1585
+ });
1586
+ define("src/storages/workspaces/workspaces.impl", ["require", "exports", "tslib", "src/storages/workspaces/workspaces", "src/storages/workspaces/workspace.impl", "src/services/rpcService", "src/services/responseUtils"], function (require, exports, tslib_13, workspaces_1, workspace_impl_1, rpcService_4, responseUtils_4) {
1587
+ "use strict";
1588
+ Object.defineProperty(exports, "__esModule", { value: true });
1589
+ exports.WorkspacesImpl = void 0;
1590
+ class WorkspacesImpl extends workspaces_1.Workspaces {
1591
+ constructor(organization, context) {
1592
+ super();
1593
+ this.organization = organization;
1594
+ this.context = context;
1595
+ this._workspaces = [];
1596
+ }
1597
+ get collection() {
1598
+ return this._workspaces;
1599
+ }
1600
+ get(id) {
1601
+ return this.tryGet(id);
1602
+ }
1603
+ tryGet(id) {
1604
+ return this._workspaces.find(workspace => workspace.id === id);
1605
+ }
1606
+ contains(id) {
1607
+ return this._workspaces.find(workspace => workspace.id === id) !== undefined;
1608
+ }
1609
+ /**
1610
+ * Create workspace.
1611
+ * @param name
1612
+ * @param description
1613
+ * @param regulation
1614
+ */
1615
+ create(name, description, regulation) {
1616
+ var _a, _b, _c, _d;
1617
+ return tslib_13.__awaiter(this, void 0, void 0, function* () {
1618
+ if (name === undefined || name === null || name.trim() === "") {
1619
+ throw new Error("Name is required, must be not empty");
1620
+ }
1621
+ if (description === undefined ||
1622
+ description === null ||
1623
+ description.trim() === "") {
1624
+ throw new Error("Description is required, must be not empty");
1625
+ }
1626
+ if (regulation) {
1627
+ if (regulation.isCreateNewGroup === undefined ||
1628
+ regulation.isCreateNewGroup === null) {
1629
+ throw new Error("isCreateNewGroup is required, must be not empty");
1630
+ }
1631
+ if (regulation.newGroupName === undefined ||
1632
+ regulation.newGroupName === null ||
1633
+ regulation.newGroupName.trim() === "") {
1634
+ throw new Error("newGroupName is required, must be not empty");
1635
+ }
1636
+ if (regulation.groupIds === undefined ||
1637
+ regulation.groupIds === null ||
1638
+ regulation.groupIds.length === 0) {
1639
+ throw new Error("groupIds is required, must be not empty");
1640
+ }
1641
+ }
1642
+ // send create request to the server
1643
+ const response = yield ((_a = this.context
1644
+ .resolve(rpcService_4.RpcService)) === null || _a === void 0 ? void 0 : _a.requestBuilder("api/v1/Workspaces").sendPostJson({
1645
+ organizationId: this.organization.id,
1646
+ profile: {
1647
+ name: name,
1648
+ description: description
1649
+ },
1650
+ regulation: {
1651
+ isCreateNewGroup: (_b = regulation === null || regulation === void 0 ? void 0 : regulation.isCreateNewGroup) !== null && _b !== void 0 ? _b : false,
1652
+ newGroupName: (_c = regulation === null || regulation === void 0 ? void 0 : regulation.newGroupName) !== null && _c !== void 0 ? _c : "",
1653
+ groupIds: (_d = regulation === null || regulation === void 0 ? void 0 : regulation.groupIds) !== null && _d !== void 0 ? _d : []
1654
+ }
1655
+ }));
1656
+ // check response status
1657
+ if (responseUtils_4.ResponseUtils.isFail(response)) {
1658
+ yield responseUtils_4.ResponseUtils.throwError(`Failed to create workspace, in organization: ${this.organization.id}`, response);
1659
+ }
1660
+ // parse workspace from the server's response
1661
+ const content = (yield response.json()).workspace;
1662
+ // create workspace implementation
1663
+ const workspace = new workspace_impl_1.WorkspaceImpl(this.organization, this.context);
1664
+ yield workspace.initFrom(content);
1665
+ // add workspace to the collection
1666
+ this._workspaces.push(workspace);
1667
+ // dispatch event
1668
+ this.dispatch({
1669
+ type: workspaces_1.WorkspacesEvent.ADDED,
1670
+ data: workspace
1671
+ });
1672
+ return workspace;
1673
+ });
1674
+ }
1675
+ /**
1676
+ * Delete workspace.
1677
+ * @param id
1678
+ */
1679
+ delete(id) {
1680
+ var _a;
1681
+ return tslib_13.__awaiter(this, void 0, void 0, function* () {
1682
+ // get workspace by id
1683
+ const workspace = this.tryGet(id);
1684
+ // check if workspace is found
1685
+ if (!workspace) {
1686
+ throw new Error(`Workspace ${id} is not found`);
1687
+ }
1688
+ // check if workspace is already marked as deleted
1689
+ if (workspace.isMarkAsDeleted) {
1690
+ throw new Error(`Workspace ${id} is already marked as deleted, in organization: ${this.organization.id}`);
1691
+ }
1692
+ // mark workspace as deleted
1693
+ workspace.markToDelete();
1694
+ // send delete request to the server
1695
+ const response = yield ((_a = this.context
1696
+ .resolve(rpcService_4.RpcService)) === null || _a === void 0 ? void 0 : _a.requestBuilder("api/v1/Workspaces").searchParam("id", id).sendDelete());
1697
+ // check response status
1698
+ if (responseUtils_4.ResponseUtils.isFail(response)) {
1699
+ yield responseUtils_4.ResponseUtils.throwError(`Failed to delete workspace: ${workspace.organization.name}/${workspace.name}:${id}, in organization: ${this.organization.id}`, response);
1700
+ }
1701
+ // remove workspace from the collection
1702
+ const index = this._workspaces.indexOf(workspace);
1703
+ if (index < 0) {
1704
+ throw new Error(`Workspace ${id} is not found`);
1705
+ }
1706
+ this._workspaces.splice(index, 1);
1707
+ // dispatch event
1708
+ this.dispatch({
1709
+ type: workspaces_1.WorkspacesEvent.REMOVED,
1710
+ data: workspace
1711
+ });
1712
+ });
1713
+ }
1714
+ initFrom(organizationId) {
1715
+ var _a;
1716
+ return tslib_13.__awaiter(this, void 0, void 0, function* () {
1717
+ // init workspaces from the server's response
1718
+ const response = yield ((_a = this.context
1719
+ .resolve(rpcService_4.RpcService)) === null || _a === void 0 ? void 0 : _a.requestBuilder("api/v1/Organizations").searchParam("id", organizationId).sendGet());
1720
+ // check response status
1721
+ if (responseUtils_4.ResponseUtils.isFail(response)) {
1722
+ yield responseUtils_4.ResponseUtils.throwError(`Failed to fetch workspaces in organization: ${organizationId}`, response);
1723
+ }
1724
+ // parse workspaces from the server's response
1725
+ const workspaces = (yield response.json())
1726
+ .workspaces;
1727
+ // init workspaces from the server's response
1728
+ for (const workspace of workspaces) {
1729
+ // create workspace implementation
1730
+ const workspaceImpl = new workspace_impl_1.WorkspaceImpl(this.organization, this.context);
1731
+ // init workspace from the server's response
1732
+ yield workspaceImpl.initFrom(workspace);
1733
+ // add workspace to the collection
1734
+ this._workspaces.push(workspaceImpl);
1735
+ // dispatch event
1736
+ this.dispatch({
1737
+ type: workspaces_1.WorkspacesEvent.ADDED,
1738
+ data: workspaceImpl
1739
+ });
1740
+ }
1741
+ });
1742
+ }
1743
+ }
1744
+ exports.WorkspacesImpl = WorkspacesImpl;
1745
+ });
1746
+ define("src/storages/groups/groups.impl", ["require", "exports", "tslib", "src/services/rpcService", "src/storages/groups/groups", "src/services/responseUtils"], function (require, exports, tslib_14, rpcService_5, groups_1, responseUtils_5) {
1747
+ "use strict";
1748
+ Object.defineProperty(exports, "__esModule", { value: true });
1749
+ exports.GroupsImpl = exports.GroupImpl = void 0;
1750
+ class GroupImpl extends groups_1.Group {
1751
+ constructor(context, organization) {
1752
+ super();
1753
+ this.context = context;
1754
+ this.organization = organization;
1755
+ this._isDisposed = false;
1756
+ }
1757
+ initFrom(id) {
1758
+ var _a;
1759
+ return tslib_14.__awaiter(this, void 0, void 0, function* () {
1760
+ // fetch group
1761
+ const response = yield ((_a = this.context.resolve(rpcService_5.RpcService)) === null || _a === void 0 ? void 0 : _a.requestBuilder("api/v1/AccessGroups").searchParam("id", id).sendGet());
1762
+ // check response status
1763
+ if (responseUtils_5.ResponseUtils.isFail(response)) {
1764
+ yield responseUtils_5.ResponseUtils.throwError(`Failed to get group: ${id}, organization: ${this}`, response);
1765
+ }
1766
+ // parse group from the server's response
1767
+ const group = (yield response.json());
1768
+ // init group
1769
+ this._content = group.group;
1770
+ this._members = group.members;
1771
+ return this;
1772
+ });
1773
+ }
1774
+ get id() {
1775
+ if (this._content) {
1776
+ return this._content.id;
1777
+ }
1778
+ throw new Error("Access group is not loaded.");
1779
+ }
1780
+ get group() {
1781
+ if (this._content) {
1782
+ return this._content;
1783
+ }
1784
+ throw new Error("Access group is not loaded.");
1785
+ }
1786
+ getWorkspaces() {
1787
+ var _a;
1788
+ return tslib_14.__awaiter(this, void 0, void 0, function* () {
1789
+ // fetch workspaces
1790
+ const response = yield ((_a = this.context.resolve(rpcService_5.RpcService)) === null || _a === void 0 ? void 0 : _a.requestBuilder("api/v1/Organizations/workspaces").searchParam("groupId", this.id).sendGet());
1791
+ if (responseUtils_5.ResponseUtils.isFail(response)) {
1792
+ yield responseUtils_5.ResponseUtils.throwError(`Failed to get workspaces for group: ${this.id}, organization: ${this.organization.id}`, response);
1793
+ }
1794
+ // parse workspaces from the server's response
1795
+ const workspaces = (yield response.json());
1796
+ return workspaces.workspaces;
1797
+ });
1798
+ }
1799
+ get members() {
1800
+ if (this._members) {
1801
+ return this._members;
1802
+ }
1803
+ throw new Error("Access group is not loaded.");
1804
+ }
1805
+ setName(name) {
1806
+ var _a;
1807
+ return tslib_14.__awaiter(this, void 0, void 0, function* () {
1808
+ if (name === undefined || name === null) {
1809
+ throw new Error("Groups change, name is undefined or null");
1810
+ }
1811
+ if (name.length === 0 || name.trim().length === 0) {
1812
+ throw new Error("Groups change, name is empty");
1813
+ }
1814
+ // send request to the server
1815
+ const response = yield ((_a = this.context
1816
+ .resolve(rpcService_5.RpcService)) === null || _a === void 0 ? void 0 : _a.requestBuilder("api/v1/AccessGroups/name").sendPutJson({
1817
+ groupId: this.id,
1818
+ name: name
1819
+ }));
1820
+ // check response status
1821
+ if (responseUtils_5.ResponseUtils.isFail(response)) {
1822
+ yield responseUtils_5.ResponseUtils.throwError(`Failed to change group name, group: ${this.id}, organization: ${this.organization.id}`, response);
1823
+ }
1824
+ });
1825
+ }
1826
+ setPermits(permits) {
1827
+ var _a;
1828
+ return tslib_14.__awaiter(this, void 0, void 0, function* () {
1829
+ // send request to the server
1830
+ const response = yield ((_a = this.context
1831
+ .resolve(rpcService_5.RpcService)) === null || _a === void 0 ? void 0 : _a.requestBuilder("api/v1/AccessGroups/permits").sendPutJson({
1832
+ groupId: this.id,
1833
+ permits: permits
1834
+ }));
1835
+ if (responseUtils_5.ResponseUtils.isFail(response)) {
1836
+ yield responseUtils_5.ResponseUtils.throwError(`Failed to change group permits, group: ${this.id}, organization: ${this.organization.id}`, response);
1837
+ }
1838
+ });
1839
+ }
1840
+ setWorkspaces(workspaces) {
1841
+ var _a;
1842
+ return tslib_14.__awaiter(this, void 0, void 0, function* () {
1843
+ if (workspaces === null || workspaces === undefined) {
1844
+ throw new Error("Group add workspaces, workspaces is undefined or null");
1845
+ }
1846
+ // send request to the server
1847
+ const response = yield ((_a = this.context
1848
+ .resolve(rpcService_5.RpcService)) === null || _a === void 0 ? void 0 : _a.requestBuilder("api/v1/AccessGroups/workspaces").sendPutJson({
1849
+ groupId: this.id,
1850
+ actualWorkspaceIds: workspaces
1851
+ }));
1852
+ if (responseUtils_5.ResponseUtils.isFail(response)) {
1853
+ yield responseUtils_5.ResponseUtils.throwError(`Failed to set workspaces for group: ${this.id}, organization: ${this.organization.id}`, response);
1854
+ }
1855
+ });
1856
+ }
1857
+ setMembersIds(members) {
1858
+ var _a;
1859
+ return tslib_14.__awaiter(this, void 0, void 0, function* () {
1860
+ if (members === null || members === undefined) {
1861
+ throw new Error("Group add members, members is undefined or null");
1862
+ }
1863
+ // send request to the server
1864
+ const response = yield ((_a = this.context
1865
+ .resolve(rpcService_5.RpcService)) === null || _a === void 0 ? void 0 : _a.requestBuilder("api/v1/AccessGroups/members").sendPutJson({
1866
+ groupId: this.id,
1867
+ memberIds: members
1868
+ }));
1869
+ if (responseUtils_5.ResponseUtils.isFail(response)) {
1870
+ yield responseUtils_5.ResponseUtils.throwError(`Failed to set members for group: ${this.id}, organization: ${this.organization.id}`, response);
1871
+ }
1872
+ });
1873
+ }
1874
+ get isDisposed() {
1875
+ return this._isDisposed;
1876
+ }
1877
+ dispose() {
1878
+ this._isDisposed = true;
1879
+ }
1880
+ }
1881
+ exports.GroupImpl = GroupImpl;
1882
+ class GroupsImpl extends groups_1.Groups {
1883
+ constructor(organization, context) {
1884
+ super();
1885
+ this.organization = organization;
1886
+ this.context = context;
1887
+ this._groups = [];
1888
+ }
1889
+ initialize() {
1890
+ return tslib_14.__awaiter(this, void 0, void 0, function* () {
1891
+ yield this.internalInit();
1892
+ });
1893
+ }
1894
+ create(name, organizationId, permits, memberIds) {
1895
+ return tslib_14.__awaiter(this, void 0, void 0, function* () {
1896
+ return yield this.internalCreate(name, organizationId, permits, memberIds);
1897
+ });
1898
+ }
1899
+ get(id) {
1900
+ return this._groups.find(group => group.id === id);
1901
+ }
1902
+ delete(id) {
1903
+ return tslib_14.__awaiter(this, void 0, void 0, function* () {
1904
+ return yield this.internalDeleteGroup(id);
1905
+ });
1906
+ }
1907
+ //----------------------------------------------------------------------------
1908
+ // INTERNALS
1909
+ //----------------------------------------------------------------------------
1910
+ /**
1911
+ * Init access groups.
1912
+ */
1913
+ internalInit() {
1914
+ var _a;
1915
+ return tslib_14.__awaiter(this, void 0, void 0, function* () {
1916
+ // fetch groups
1917
+ const response = yield ((_a = this.context.resolve(rpcService_5.RpcService)) === null || _a === void 0 ? void 0 : _a.requestBuilder("api/v1/Organizations/access_groups").searchParam("id", this.organization.id).sendGet());
1918
+ // check response status
1919
+ if (responseUtils_5.ResponseUtils.isFail(response)) {
1920
+ yield responseUtils_5.ResponseUtils.throwError(`Failed to get groups for organization: ${this.organization.id}`, response);
1921
+ }
1922
+ // parse groups from the server's response
1923
+ const groups = (yield response.json());
1924
+ // init groups
1925
+ for (const gr of groups.groups) {
1926
+ // create group implementation
1927
+ const group = yield new GroupImpl(this.context, this.organization).initFrom(gr.id);
1928
+ // add group to the collection
1929
+ this._groups.push(group);
1930
+ // dispatch event
1931
+ this.dispatch({
1932
+ type: groups_1.GroupEvent.ADDED,
1933
+ data: group
1934
+ });
1935
+ }
1936
+ });
1937
+ }
1938
+ internalCreate(name, organizationId, permits, memberIds) {
1939
+ var _a;
1940
+ return tslib_14.__awaiter(this, void 0, void 0, function* () {
1941
+ if (name === undefined || name === null) {
1942
+ throw new Error("Group create, name is undefined or null");
1943
+ }
1944
+ if (name.length === 0 || name.trim().length === 0) {
1945
+ throw new Error("Group create, name is empty");
1946
+ }
1947
+ // send request to the server
1948
+ const response = yield ((_a = this.context
1949
+ .resolve(rpcService_5.RpcService)) === null || _a === void 0 ? void 0 : _a.requestBuilder("api/v1/AccessGroups").sendPostJson({
1950
+ name: name,
1951
+ organizationId: organizationId,
1952
+ permits: permits,
1953
+ memberIds: memberIds
1954
+ }));
1955
+ // check response status
1956
+ if (responseUtils_5.ResponseUtils.isFail(response)) {
1957
+ yield responseUtils_5.ResponseUtils.throwError(`Failed to create group, organization: ${this.organization.id}`, response);
1958
+ }
1959
+ // parse group from the server's response
1960
+ const content = (yield response.json());
1961
+ // create group implementation
1962
+ const group = yield new GroupImpl(this.context, this.organization).initFrom(content.group.id);
1963
+ // add group to the collection
1964
+ this._groups.push(group);
1965
+ // dispatch event
1966
+ this.dispatch({
1967
+ type: groups_1.GroupEvent.ADDED,
1968
+ data: group
1969
+ });
1970
+ return group;
1971
+ });
1972
+ }
1973
+ /**
1974
+ * Delete group.
1975
+ * @param id
1976
+ */
1977
+ internalDeleteGroup(id) {
1978
+ var _a;
1979
+ return tslib_14.__awaiter(this, void 0, void 0, function* () {
1980
+ if (id === undefined || id === null) {
1981
+ throw new Error("Group delete, id is undefined or null");
1982
+ }
1983
+ if (id.length === 0 || id.trim().length === 0) {
1984
+ throw new Error("Group delete, id is empty");
1985
+ }
1986
+ // send request to the server
1987
+ const response = yield ((_a = this.context
1988
+ .resolve(rpcService_5.RpcService)) === null || _a === void 0 ? void 0 : _a.requestBuilder("/api/v1/AccessGroups").searchParam("groupId", id).sendDelete());
1989
+ // check response status
1990
+ if (responseUtils_5.ResponseUtils.isFail(response)) {
1991
+ yield responseUtils_5.ResponseUtils.throwError(`Failed to delete group: ${id}, organization: ${this.organization.id}`, response);
1992
+ }
1993
+ // delete group from collection
1994
+ const group = this._groups.find(f => f.id === id);
1995
+ const index = this._groups.indexOf(group);
1996
+ if (index < 0) {
1997
+ throw new Error("Group delete, index is not found");
1998
+ }
1999
+ // remove group from collection
2000
+ this._groups.splice(index, 1);
2001
+ // dispatch event, group removed
2002
+ this.dispatch({
2003
+ type: groups_1.GroupEvent.REMOVED,
2004
+ data: group
2005
+ });
2006
+ // dispose group
2007
+ group.dispose();
2008
+ });
2009
+ }
2010
+ }
2011
+ exports.GroupsImpl = GroupsImpl;
2012
+ });
2013
+ define("src/storages/chats/answer.impl", ["require", "exports", "tslib", "src/services/responseUtils", "src/services/rpcService", "src/storages/chats/answer"], function (require, exports, tslib_15, responseUtils_6, rpcService_6, answer_1) {
2014
+ "use strict";
2015
+ Object.defineProperty(exports, "__esModule", { value: true });
2016
+ exports.AnswerImpl = void 0;
2017
+ class AnswerImpl extends answer_1.Answer {
2018
+ constructor(chat, context) {
2019
+ super();
2020
+ this.chat = chat;
2021
+ this.context = context;
2022
+ }
2023
+ initFromData(answer) {
2024
+ return tslib_15.__awaiter(this, void 0, void 0, function* () {
2025
+ this._content = answer;
2026
+ this._id = answer.id;
2027
+ // fetch answer
2028
+ yield this.fetch();
2029
+ return this;
2030
+ });
2031
+ }
2032
+ initFromId(id) {
2033
+ return tslib_15.__awaiter(this, void 0, void 0, function* () {
2034
+ this._id = id;
2035
+ // fetch answer
2036
+ yield this.fetch();
2037
+ return this;
2038
+ });
2039
+ }
2040
+ get id() {
2041
+ return this._id;
2042
+ }
2043
+ get status() {
2044
+ return this._status;
2045
+ }
2046
+ getStep(type) {
2047
+ var _a;
2048
+ return (_a = this._steps) === null || _a === void 0 ? void 0 : _a.find(step => step.type === type);
2049
+ }
2050
+ sources(type) {
2051
+ var _a;
2052
+ return tslib_15.__awaiter(this, void 0, void 0, function* () {
2053
+ // fetch answer
2054
+ yield this.fetch();
2055
+ // get step
2056
+ const step = this.getStep(type);
2057
+ // check step
2058
+ if (!step) {
2059
+ throw new Error(`Step with type ${type.toString()} is not found, answer: ${this.id}, organization: ${this.chat.organization.id}`);
2060
+ }
2061
+ // get sources
2062
+ const response = yield ((_a = this.context
2063
+ .resolve(rpcService_6.RpcService)) === null || _a === void 0 ? void 0 : _a.requestBuilder("api/v1/Chats/answer/sources").searchParam("chat_uid", this.chat.id).searchParam("uid", this.id).searchParam("step_id", step.id).sendGet());
2064
+ // check response status
2065
+ if (responseUtils_6.ResponseUtils.isFail(response)) {
2066
+ yield responseUtils_6.ResponseUtils.throwError(`Failed to get sources for ${type.toString()}, answer: ${this.id}, organization: ${this.chat.organization.id}`, response);
2067
+ }
2068
+ // parse sources from the server's response
2069
+ const sources = (yield response.json()).sources;
2070
+ return sources;
2071
+ });
2072
+ }
2073
+ fetch() {
2074
+ var _a;
2075
+ return tslib_15.__awaiter(this, void 0, void 0, function* () {
2076
+ // fetch answer from position 0
2077
+ const position = 0;
2078
+ // fetch answer
2079
+ const response = yield ((_a = this.context
2080
+ .resolve(rpcService_6.RpcService)) === null || _a === void 0 ? void 0 : _a.requestBuilder("api/v1/Chats/answer/fetch").searchParam("chatId", this.chat.id).searchParam("questionId", this.id).searchParam("position", position.toString()).sendGet());
2081
+ // check response status
2082
+ if (responseUtils_6.ResponseUtils.isFail(response)) {
2083
+ yield responseUtils_6.ResponseUtils.throwError(`Failed to fetch answer ${this.id}`, response);
2084
+ }
2085
+ // parse answer from the server's response
2086
+ const answer = (yield response.json());
2087
+ // update answer
2088
+ this._status = answer.status;
2089
+ this._steps = answer.steps;
2090
+ });
2091
+ }
2092
+ fetchTokens(type, token_start_at) {
2093
+ var _a;
2094
+ return tslib_15.__awaiter(this, void 0, void 0, function* () {
2095
+ // fetch answer
2096
+ yield this.fetch();
2097
+ // get step
2098
+ const step = this.getStep(type);
2099
+ // check step
2100
+ if (!step) {
2101
+ throw new Error(`Step with type ${type.toString()} is not found`);
2102
+ }
2103
+ // get tokens
2104
+ const response = yield ((_a = this.context
2105
+ .resolve(rpcService_6.RpcService)) === null || _a === void 0 ? void 0 : _a.requestBuilder("api/v1/Chats/answer/fetch/tokens").searchParam("chat_uid", this.chat.id).searchParam("uid", this.id).searchParam("step_id", step.id).searchParam("token_start_at", token_start_at.toString()).sendGet());
2106
+ // check response status
2107
+ if (responseUtils_6.ResponseUtils.isFail(response)) {
2108
+ yield responseUtils_6.ResponseUtils.throwError(`Failed to get sources for ${type.toString()}`, response);
2109
+ }
2110
+ // parse tokens from the server's response
2111
+ const tokens = (yield response.json());
2112
+ return tokens;
2113
+ });
2114
+ }
2115
+ cancel() {
2116
+ var _a;
2117
+ return tslib_15.__awaiter(this, void 0, void 0, function* () {
2118
+ // send request to the server
2119
+ const response = yield ((_a = this.context
2120
+ .resolve(rpcService_6.RpcService)) === null || _a === void 0 ? void 0 : _a.requestBuilder("api/v1/Chats/answer/cancel").sendPutJson({
2121
+ chat_id: this.chat.id,
2122
+ uid: this.id
2123
+ }));
2124
+ // check response status
2125
+ if (responseUtils_6.ResponseUtils.isFail(response)) {
2126
+ yield responseUtils_6.ResponseUtils.throwError("Failed to cancel a question", response);
2127
+ }
2128
+ });
2129
+ }
2130
+ }
2131
+ exports.AnswerImpl = AnswerImpl;
2132
+ });
2133
+ define("src/storages/chats/chat.impl", ["require", "exports", "tslib", "src/storages/chats/chat", "src/storages/chats/answer.impl", "src/services/rpcService", "src/services/responseUtils"], function (require, exports, tslib_16, chat_1, answer_impl_1, rpcService_7, responseUtils_7) {
2134
+ "use strict";
2135
+ Object.defineProperty(exports, "__esModule", { value: true });
2136
+ exports.ChatImpl = void 0;
2137
+ class ChatImpl extends chat_1.Chat {
2138
+ constructor(context, organization) {
2139
+ super();
2140
+ this.context = context;
2141
+ this.organization = organization;
2142
+ this._isDisposed = false;
2143
+ this._answers = [];
2144
+ }
2145
+ initFrom(chat) {
2146
+ return tslib_16.__awaiter(this, void 0, void 0, function* () {
2147
+ this._content = chat;
2148
+ // init answers
2149
+ for (const ans of chat.answers) {
2150
+ // create answer implementation
2151
+ const answer = yield new answer_impl_1.AnswerImpl(this, this.context).initFromData(ans);
2152
+ // add answer to the collection
2153
+ this._answers.push(answer);
2154
+ }
2155
+ return this;
2156
+ });
2157
+ }
2158
+ get id() {
2159
+ var _a;
2160
+ return (_a = this._content) === null || _a === void 0 ? void 0 : _a.id;
2161
+ }
2162
+ get name() {
2163
+ var _a;
2164
+ return (_a = this._content) === null || _a === void 0 ? void 0 : _a.name;
2165
+ }
2166
+ get collection() {
2167
+ return this._answers;
2168
+ }
2169
+ get isDisposed() {
2170
+ return this._isDisposed;
2171
+ }
2172
+ ask(message, answerType) {
2173
+ var _a;
2174
+ return tslib_16.__awaiter(this, void 0, void 0, function* () {
2175
+ // send request to the server
2176
+ const response = yield ((_a = this.context
2177
+ .resolve(rpcService_7.RpcService)) === null || _a === void 0 ? void 0 : _a.requestBuilder("api/v1/Chats/question").sendPutJson({
2178
+ chatId: this.id,
2179
+ questionMessage: message,
2180
+ isLongAnswer: (answerType === chat_1.ChatAnswerType.LONG)
2181
+ }));
2182
+ // check response status
2183
+ if (responseUtils_7.ResponseUtils.isFail(response)) {
2184
+ yield responseUtils_7.ResponseUtils.throwError(`Failed to ask a question, organization: ${this.organization.id}`, response);
2185
+ }
2186
+ // parse answer id from the server's response
2187
+ const id = (yield response.json()).id;
2188
+ // create answer implementation
2189
+ const answer = yield new answer_impl_1.AnswerImpl(this, this.context).initFromId(id);
2190
+ // add answer to the collection
2191
+ this._answers.push(answer);
2192
+ return answer;
2193
+ });
2194
+ }
2195
+ dispose() {
2196
+ this._isDisposed = true;
2197
+ }
2198
+ }
2199
+ exports.ChatImpl = ChatImpl;
2200
+ });
2201
+ define("src/storages/chats/chats.impl", ["require", "exports", "tslib", "src/services/responseUtils", "src/services/rpcService", "src/storages/chats/chat.impl", "src/storages/chats/chats"], function (require, exports, tslib_17, responseUtils_8, rpcService_8, chat_impl_1, chats_1) {
2202
+ "use strict";
2203
+ Object.defineProperty(exports, "__esModule", { value: true });
2204
+ exports.ChatsImpl = void 0;
2205
+ class ChatsImpl extends chats_1.Chats {
2206
+ constructor(organization, context) {
2207
+ super();
2208
+ this.organization = organization;
2209
+ this.context = context;
2210
+ this._chats = [];
2211
+ }
2212
+ initFrom(organizationId) {
2213
+ var _a;
2214
+ return tslib_17.__awaiter(this, void 0, void 0, function* () {
2215
+ // init chats from the server's response
2216
+ const limit = 100;
2217
+ const page = 0;
2218
+ const response = yield ((_a = this.context
2219
+ .resolve(rpcService_8.RpcService)) === null || _a === void 0 ? void 0 : _a.requestBuilder("api/v1/Chats/list").searchParam("organizationId", organizationId).searchParam("limit", limit.toString()).searchParam("page", page.toString()).sendGet());
2220
+ // check response status
2221
+ if (responseUtils_8.ResponseUtils.isFail(response)) {
2222
+ yield responseUtils_8.ResponseUtils.throwError(`Chats list org id:${organizationId}, page:${page}, limit:${limit}, failed`, response);
2223
+ }
2224
+ // parse chats from the server's response
2225
+ const chats = (yield response.json());
2226
+ // init chats
2227
+ for (const cht of chats.chats) {
2228
+ // create chat implementation
2229
+ const chat = yield new chat_impl_1.ChatImpl(this.context, this.organization).initFrom(cht);
2230
+ // add chat to the collection
2231
+ this._chats.push(chat);
2232
+ // dispatch event
2233
+ this.dispatch({
2234
+ type: chats_1.ChatsEvent.ADDED,
2235
+ data: chat
2236
+ });
2237
+ }
2238
+ });
2239
+ }
2240
+ get collection() {
2241
+ return this._chats;
2242
+ }
2243
+ get(id) {
2244
+ return this.tryGet(id);
2245
+ }
2246
+ tryGet(id) {
2247
+ return this._chats.find(chat => chat.id === id);
2248
+ }
2249
+ create() {
2250
+ var _a;
2251
+ return tslib_17.__awaiter(this, void 0, void 0, function* () {
2252
+ // send create request to the server
2253
+ const response = yield ((_a = this.context
2254
+ .resolve(rpcService_8.RpcService)) === null || _a === void 0 ? void 0 : _a.requestBuilder("api/v1/Chats").sendPostJson({ organizationId: this.organization.id }));
2255
+ // check response status
2256
+ if (responseUtils_8.ResponseUtils.isFail(response)) {
2257
+ yield responseUtils_8.ResponseUtils.throwError(`Failed to create chat, organization: ${this.organization.id}`, response);
2258
+ }
2259
+ // parse workspace from the server's response
2260
+ const content = (yield response.json()).chat;
2261
+ // create workspace implementation
2262
+ const chat = new chat_impl_1.ChatImpl(this.context, this.organization);
2263
+ yield chat.initFrom(content);
2264
+ // add chat to the collection
2265
+ this._chats.push(chat);
2266
+ // dispatch event
2267
+ this.dispatch({
2268
+ type: chats_1.ChatsEvent.ADDED,
2269
+ data: chat
2270
+ });
2271
+ return chat;
2272
+ });
2273
+ }
2274
+ delete(id) {
2275
+ var _a;
2276
+ return tslib_17.__awaiter(this, void 0, void 0, function* () {
2277
+ // get chat by id
2278
+ const chat = this.tryGet(id);
2279
+ // check if chat is found
2280
+ if (!chat) {
2281
+ throw new Error(`Chat ${id} is not found, organization: ${this.organization.id}`);
2282
+ }
2283
+ // send delete request to the server
2284
+ const response = yield ((_a = this.context
2285
+ .resolve(rpcService_8.RpcService)) === null || _a === void 0 ? void 0 : _a.requestBuilder("api/v1/Chats").searchParam("id", id).sendDelete());
2286
+ // check response status
2287
+ if (responseUtils_8.ResponseUtils.isFail(response)) {
2288
+ yield responseUtils_8.ResponseUtils.throwError(`Failed to delete chat: ${id}, organization: ${this.organization.id}`, response);
2289
+ }
2290
+ // remove chat from the collection
2291
+ const index = this._chats.indexOf(chat);
2292
+ if (index < 0) {
2293
+ throw new Error(`Chat ${id} is not found, organization: ${this.organization.id}`);
2294
+ }
2295
+ this._chats.splice(index, 1);
2296
+ // dispatch event
2297
+ this.dispatch({
2298
+ type: chats_1.ChatsEvent.REMOVED,
2299
+ data: chat
2300
+ });
2301
+ });
2302
+ }
2303
+ }
2304
+ exports.ChatsImpl = ChatsImpl;
2305
+ });
2306
+ define("src/storages/organizations/organization.impl", ["require", "exports", "tslib", "src/storages/workspaces/workspaces.impl", "src/storages/organizations/organization", "src/storages/groups/groups.impl", "src/storages/chats/chats.impl", "src/services/rpcService", "src/services/responseUtils"], function (require, exports, tslib_18, workspaces_impl_1, organization_1, groups_impl_1, chats_impl_1, rpcService_9, responseUtils_9) {
2307
+ "use strict";
2308
+ Object.defineProperty(exports, "__esModule", { value: true });
2309
+ exports.OrganizationImpl = void 0;
2310
+ class OrganizationImpl extends organization_1.Organization {
2311
+ constructor(context) {
2312
+ super();
2313
+ this.context = context;
2314
+ this._isDisposed = false;
2315
+ this._isAdmin = false;
2316
+ this._workspaces = new workspaces_impl_1.WorkspacesImpl(this, this.context);
2317
+ this._accessGroups = new groups_impl_1.GroupsImpl(this, this.context);
2318
+ this._chats = new chats_impl_1.ChatsImpl(this, this.context);
2319
+ }
2320
+ initFrom(content, isAdmin) {
2321
+ return tslib_18.__awaiter(this, void 0, void 0, function* () {
2322
+ this._content = content;
2323
+ this._isAdmin = isAdmin;
2324
+ // init workspaces by organization id
2325
+ yield this._workspaces.initFrom(content.id);
2326
+ return this;
2327
+ });
2328
+ }
2329
+ get isAdmin() {
2330
+ return this._isAdmin;
2331
+ }
2332
+ get isDisposed() {
2333
+ return this._isDisposed;
2334
+ }
2335
+ dispose() {
2336
+ this._isDisposed = true;
2337
+ }
2338
+ get id() {
2339
+ var _a;
2340
+ return (_a = this._content) === null || _a === void 0 ? void 0 : _a.id;
2341
+ }
2342
+ get name() {
2343
+ var _a;
2344
+ return (_a = this._content) === null || _a === void 0 ? void 0 : _a.profile.name;
2345
+ }
2346
+ get description() {
2347
+ var _a;
2348
+ return (_a = this._content) === null || _a === void 0 ? void 0 : _a.profile.description;
2349
+ }
2350
+ get workspaces() {
2351
+ return this._workspaces;
2352
+ }
2353
+ get accessGroups() {
2354
+ return this._accessGroups;
2355
+ }
2356
+ get chats() {
2357
+ return this._chats;
2358
+ }
2359
+ createInviteLink(emails, accessGroups) {
2360
+ var _a;
2361
+ return tslib_18.__awaiter(this, void 0, void 0, function* () {
2362
+ const response = yield ((_a = this.context
2363
+ .resolve(rpcService_9.RpcService)) === null || _a === void 0 ? void 0 : _a.requestBuilder("api/v1/Invites").sendPostJson({
2364
+ organizationId: this.id,
2365
+ emails: emails,
2366
+ accessGroupIds: accessGroups
2367
+ }));
2368
+ if (responseUtils_9.ResponseUtils.isFail(response)) {
2369
+ yield responseUtils_9.ResponseUtils.throwError(`Invite link creation failed for organization ${this.id}`, response);
2370
+ }
2371
+ });
2372
+ }
2373
+ }
2374
+ exports.OrganizationImpl = OrganizationImpl;
2375
+ });
2376
+ define("src/storages/organizations/organizations.impl", ["require", "exports", "tslib", "src/storages/organizations/organizations", "src/storages/organizations/organization.impl", "src/services/rpcService", "src/services/responseUtils"], function (require, exports, tslib_19, organizations_1, organization_impl_1, rpcService_10, responseUtils_10) {
2377
+ "use strict";
2378
+ Object.defineProperty(exports, "__esModule", { value: true });
2379
+ exports.OrganizationsImpl = void 0;
2380
+ class OrganizationsImpl extends organizations_1.Organizations {
2381
+ constructor(context) {
2382
+ super();
2383
+ this.context = context;
2384
+ this.organizations = [];
2385
+ }
2386
+ get collection() {
2387
+ return this.organizations;
2388
+ }
2389
+ get current() {
2390
+ return this.currentOrganizationId;
2391
+ }
2392
+ set current(value) {
2393
+ if (this.currentOrganizationId !== value) {
2394
+ const org = this.tryGet(value);
2395
+ if (org) {
2396
+ this.currentOrganizationId = value;
2397
+ this.dispatch({
2398
+ type: organizations_1.OrganizationsEvent.CURRENT_CHANGED,
2399
+ data: org
2400
+ });
2401
+ }
2402
+ else {
2403
+ throw new Error(`Organization ${value} is not found`);
2404
+ }
2405
+ }
2406
+ }
2407
+ get(id) {
2408
+ return this.tryGet(id);
2409
+ }
2410
+ tryGet(id) {
2411
+ return this.organizations.find(organization => organization.id === id);
2412
+ }
2413
+ contains(id) {
2414
+ return this.organizations.some(organization => organization.id === id);
2415
+ }
2416
+ create(name, description) {
2417
+ return tslib_19.__awaiter(this, void 0, void 0, function* () {
2418
+ return this.internalCreateOrganization(name, description);
2419
+ });
2420
+ }
2421
+ delete(id) {
2422
+ return this.internalDeleteOrganization(id);
2423
+ }
2424
+ //----------------------------------------------------------------------------
2425
+ // INTERNALS
2426
+ //----------------------------------------------------------------------------
2427
+ /**
2428
+ * Delete organization.
2429
+ * @param id
2430
+ */
2431
+ internalDeleteOrganization(id) {
2432
+ var _a;
2433
+ return tslib_19.__awaiter(this, void 0, void 0, function* () {
2434
+ if (id === undefined || id === null) {
2435
+ throw new Error("Organization delete, id is undefined or null");
2436
+ }
2437
+ if (id.length === 0 || id.trim().length === 0) {
2438
+ throw new Error("Organization delete, id is empty");
2439
+ }
2440
+ if (!this.contains(id)) {
2441
+ throw new Error(`Organization delete, id: ${id} is not found`);
2442
+ }
2443
+ // send request to the server
2444
+ const response = yield ((_a = this.context
2445
+ .resolve(rpcService_10.RpcService)) === null || _a === void 0 ? void 0 : _a.requestBuilder("/api/v1/Organizations").searchParam("id", id).sendDelete());
2446
+ // check response status
2447
+ if (responseUtils_10.ResponseUtils.isFail(response)) {
2448
+ yield responseUtils_10.ResponseUtils.throwError(`Organization ${id} delete, failed`, response);
2449
+ }
2450
+ // check organization in collection
2451
+ const org = this.get(id);
2452
+ const index = this.organizations.indexOf(org);
2453
+ if (index < 0) {
2454
+ throw new Error("Organization delete, index is not found");
2455
+ }
2456
+ // remove organization from collection
2457
+ this.organizations.splice(index, 1);
2458
+ // dispatch event, organization removed
2459
+ this.dispatch({
2460
+ type: organizations_1.OrganizationsEvent.REMOVED,
2461
+ data: org
2462
+ });
2463
+ // dispose organization
2464
+ org.dispose();
2465
+ });
2466
+ }
2467
+ /**
2468
+ * Create organization.
2469
+ * @param name
2470
+ * @param description
2471
+ */
2472
+ internalCreateOrganization(name, description) {
2473
+ var _a;
2474
+ return tslib_19.__awaiter(this, void 0, void 0, function* () {
2475
+ if (name === undefined || name === null) {
2476
+ throw new Error("Organization create, name is undefined or null");
2477
+ }
2478
+ if (description === undefined || description === null) {
2479
+ throw new Error("Organization create, description is undefined or null");
2480
+ }
2481
+ if (name.length === 0 || name.trim().length === 0) {
2482
+ throw new Error("Organization create, name is empty");
2483
+ }
2484
+ const response = yield ((_a = this.context
2485
+ .resolve(rpcService_10.RpcService)) === null || _a === void 0 ? void 0 : _a.requestBuilder("api/v1/Organizations").sendPostJson({
2486
+ profile: {
2487
+ name: name,
2488
+ description: description
2489
+ }
2490
+ }));
2491
+ if (responseUtils_10.ResponseUtils.isFail(response)) {
2492
+ yield responseUtils_10.ResponseUtils.throwError(`Organization create failed, name: ${name}, description: ${description}`, response);
2493
+ }
2494
+ const content = (yield response.json()).organization;
2495
+ // create organization and init from content
2496
+ const org = yield new organization_impl_1.OrganizationImpl(this.context).initFrom(content, true);
2497
+ // add organization to collection
2498
+ this.organizations.push(org);
2499
+ // dispatch event, organization added
2500
+ this.dispatch({
2501
+ type: organizations_1.OrganizationsEvent.ADDED,
2502
+ data: org
2503
+ });
2504
+ return org;
2505
+ });
2506
+ }
2507
+ /**
2508
+ * Init organizations from user profile.
2509
+ * @param adminInOrganization
2510
+ * @param organizations
2511
+ * @param settings
2512
+ */
2513
+ internalInitFrom(adminInOrganization, organizations, settings) {
2514
+ return tslib_19.__awaiter(this, void 0, void 0, function* () {
2515
+ this.currentOrganizationId = settings === null || settings === void 0 ? void 0 : settings.activeOrganizationId;
2516
+ for (const organization of organizations) {
2517
+ // create organization and init from content
2518
+ const org = yield new organization_impl_1.OrganizationImpl(this.context).initFrom(organization, adminInOrganization.includes(organization.id));
2519
+ // add organization to collection
2520
+ this.organizations.push(org);
2521
+ // dispatch event, organization added
2522
+ this.dispatch({
2523
+ type: organizations_1.OrganizationsEvent.ADDED,
2524
+ data: org
2525
+ });
2526
+ }
2527
+ });
2528
+ }
2529
+ }
2530
+ exports.OrganizationsImpl = OrganizationsImpl;
2531
+ });
2532
+ define("src/services/organizationService", ["require", "exports", "tslib", "src/services/service", "src/storages/organizations/organizations.impl"], function (require, exports, tslib_20, service_5, organizations_impl_1) {
2533
+ "use strict";
2534
+ Object.defineProperty(exports, "__esModule", { value: true });
2535
+ exports.OrganizationService = void 0;
2536
+ class OrganizationService extends service_5.Service {
2537
+ get impl() {
2538
+ var _a;
2539
+ return (_a = this._impl) !== null && _a !== void 0 ? _a : (this._impl = new organizations_impl_1.OrganizationsImpl(this.context));
2540
+ }
2541
+ get organizations() {
2542
+ return this.impl;
2543
+ }
2544
+ initFrom(adminInOrganization, organizations, settings) {
2545
+ return tslib_20.__awaiter(this, void 0, void 0, function* () {
2546
+ yield this.impl.internalInitFrom(adminInOrganization, organizations, settings);
2547
+ });
2548
+ }
2549
+ }
2550
+ exports.OrganizationService = OrganizationService;
2551
+ });
2552
+ define("src/storages/user/userProfile.impl", ["require", "exports", "src/storages/user/userProfile"], function (require, exports, userProfile_1) {
2553
+ "use strict";
2554
+ Object.defineProperty(exports, "__esModule", { value: true });
2555
+ exports.UserProfileImpl = void 0;
2556
+ class UserProfileImpl extends userProfile_1.UserProfile {
2557
+ get id() {
2558
+ if (this.content) {
2559
+ return this.content.user.id;
2560
+ }
2561
+ throw new Error("The profile is not loaded.");
2562
+ }
2563
+ get name() {
2564
+ if (this.content) {
2565
+ return this.content.user.profile.name;
2566
+ }
2567
+ throw new Error("The profile is not loaded.");
2568
+ }
2569
+ get email() {
2570
+ if (this.content) {
2571
+ return this.content.user.profile.email;
2572
+ }
2573
+ throw new Error("The profile is not loaded.");
2574
+ }
2575
+ get isDeleted() {
2576
+ if (this.content) {
2577
+ return this.content.user.isDeleted;
2578
+ }
2579
+ throw new Error("The profile is not loaded.");
2580
+ }
2581
+ get createdAt() {
2582
+ if (this.content) {
2583
+ return new Date(this.content.user.created_at);
2584
+ }
2585
+ throw new Error("The profile is not loaded.");
2586
+ }
2587
+ get modifiedAt() {
2588
+ if (this.content) {
2589
+ return new Date(this.content.user.modified_at);
2590
+ }
2591
+ throw new Error("The profile is not loaded.");
2592
+ }
2593
+ initFrom(content) {
2594
+ this.content = content;
2595
+ this.dispatch({
2596
+ type: userProfile_1.UserEvent.CHANGED,
2597
+ data: this
2598
+ });
2599
+ }
2600
+ }
2601
+ exports.UserProfileImpl = UserProfileImpl;
2602
+ });
2603
+ define("src/services/userProfileService", ["require", "exports", "tslib", "src/services/service", "src/services/rpcService", "src/services/organizationService", "src/storages/user/userProfile.impl", "src/services/responseUtils"], function (require, exports, tslib_21, service_6, rpcService_11, organizationService_1, userProfile_impl_1, responseUtils_11) {
2604
+ "use strict";
2605
+ Object.defineProperty(exports, "__esModule", { value: true });
2606
+ exports.UserProfileService = void 0;
2607
+ class UserProfileService extends service_6.Service {
2608
+ constructor() {
2609
+ super(...arguments);
2610
+ this.impl = new userProfile_impl_1.UserProfileImpl();
2611
+ }
2612
+ get userProfile() {
2613
+ return this.impl;
2614
+ }
2615
+ fetch() {
2616
+ return tslib_21.__awaiter(this, void 0, void 0, function* () {
2617
+ const rpc = this.resolve(rpcService_11.RpcService);
2618
+ const response = yield rpc.requestBuilder("api/v1/Users/self2").sendGet();
2619
+ if (responseUtils_11.ResponseUtils.isFail(response)) {
2620
+ yield responseUtils_11.ResponseUtils.throwError("Failed to fetch user profile", response);
2621
+ }
2622
+ const content = (yield response.json());
2623
+ // init user profile from the server's response
2624
+ this.impl.initFrom(content);
2625
+ const organizationService = this.resolve(organizationService_1.OrganizationService);
2626
+ // init organization service from user profile
2627
+ yield organizationService.initFrom(content.adminInOrganization, content.organizations, content.user.settings);
2628
+ });
2629
+ }
2630
+ }
2631
+ exports.UserProfileService = UserProfileService;
2632
+ });
2633
+ define("src/commands/startCommandHandler", ["require", "exports", "tslib", "src/services/commandService", "src/services/userProfileService"], function (require, exports, tslib_22, commandService_2, userProfileService_1) {
2634
+ "use strict";
2635
+ Object.defineProperty(exports, "__esModule", { value: true });
2636
+ exports.StartCommandHandler = exports.StartCommand = void 0;
2637
+ class StartCommand extends commandService_2.Command {
2638
+ }
2639
+ exports.StartCommand = StartCommand;
2640
+ class StartCommandHandler extends commandService_2.CommandHandler {
2641
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2642
+ execute(message) {
2643
+ return tslib_22.__awaiter(this, void 0, void 0, function* () {
2644
+ const service = this.context.resolve(userProfileService_1.UserProfileService);
2645
+ yield service.fetch();
2646
+ });
2647
+ }
2648
+ }
2649
+ exports.StartCommandHandler = StartCommandHandler;
2650
+ });
2651
+ define("src/internal/app.impl", ["require", "exports", "tslib", "src/index", "src/internal/appBuilder.impl", "src/internal/registry", "src/context", "src/disposable", "src/services/service", "src/services/credentialService", "src/services/middlewareService", "src/dataIslandApp", "src/services/rpcService", "src/services/commandService", "src/commands/startCommandHandler", "src/services/userProfileService", "src/services/organizationService", "src/unitTest"], function (require, exports, tslib_23, index_2, appBuilder_impl_1, registry_1, context_1, disposable_2, service_7, credentialService_1, middlewareService_3, dataIslandApp_1, rpcService_12, commandService_3, startCommandHandler_1, userProfileService_2, organizationService_2, unitTest_2) {
2652
+ "use strict";
2653
+ Object.defineProperty(exports, "__esModule", { value: true });
2654
+ exports.DataIslandAppImpl = void 0;
2655
+ class DataIslandAppImpl extends dataIslandApp_1.DataIslandApp {
2656
+ constructor(name) {
2657
+ super();
2658
+ this._host = index_2.DEFAULT_HOST;
2659
+ this._automaticDataCollectionEnabled = true;
2660
+ this.resolve = (type) => this._registry.get(type);
2661
+ this.name = name;
2662
+ this._registry = new registry_1.Registry();
2663
+ this._disposable = new disposable_2.DisposableContainer();
2664
+ this._context = new context_1.Context(this._registry, this._disposable.lifetime, name);
2665
+ this._registry.map(context_1.Context).asValue(this._context);
2666
+ }
2667
+ get context() {
2668
+ return this._context;
2669
+ }
2670
+ get credential() {
2671
+ var _a;
2672
+ return (_a = this.resolve(credentialService_1.CredentialService)) === null || _a === void 0 ? void 0 : _a.credential;
2673
+ }
2674
+ set credential(value) {
2675
+ var _a;
2676
+ (_a = this.resolve(credentialService_1.CredentialService)) === null || _a === void 0 ? void 0 : _a.useCredential(value);
2677
+ }
2678
+ get lifetime() {
2679
+ return this._disposable.lifetime;
2680
+ }
2681
+ get automaticDataCollectionEnabled() {
2682
+ return this._automaticDataCollectionEnabled;
2683
+ }
2684
+ get host() {
2685
+ return this._host;
2686
+ }
2687
+ get organizations() {
2688
+ var _a;
2689
+ return (_a = this.resolve(organizationService_2.OrganizationService)) === null || _a === void 0 ? void 0 : _a.organizations;
2690
+ }
2691
+ get userProfile() {
2692
+ var _a;
2693
+ return (_a = this.resolve(userProfileService_2.UserProfileService)) === null || _a === void 0 ? void 0 : _a.userProfile;
2694
+ }
2695
+ initialize(setup) {
2696
+ return tslib_23.__awaiter(this, void 0, void 0, function* () {
2697
+ // create app builder
2698
+ const builder = new appBuilder_impl_1.AppBuilderImplementation();
2699
+ // register commands
2700
+ builder.registerCommand(startCommandHandler_1.StartCommand, (context) => {
2701
+ return new startCommandHandler_1.StartCommandHandler(context);
2702
+ });
2703
+ // register services
2704
+ builder.registerService(credentialService_1.CredentialService, (context) => {
2705
+ return new credentialService_1.CredentialService(context);
2706
+ });
2707
+ builder.registerService(middlewareService_3.MiddlewareService, (context) => {
2708
+ return new middlewareService_3.MiddlewareService(context);
2709
+ });
2710
+ builder.registerService(rpcService_12.RpcService, (context) => {
2711
+ return new rpcService_12.RpcService(context, builder.host);
2712
+ });
2713
+ builder.registerService(commandService_3.CommandService, (context) => {
2714
+ return new commandService_3.CommandService(context);
2715
+ });
2716
+ builder.registerService(userProfileService_2.UserProfileService, (context) => {
2717
+ return new userProfileService_2.UserProfileService(context);
2718
+ });
2719
+ builder.registerService(organizationService_2.OrganizationService, (context) => {
2720
+ return new organizationService_2.OrganizationService(context);
2721
+ });
2722
+ // call customer setup
2723
+ if (setup !== undefined) {
2724
+ yield setup(builder);
2725
+ }
2726
+ // host
2727
+ this._host = builder.host;
2728
+ // automaticDataCollectionEnabled
2729
+ this._automaticDataCollectionEnabled =
2730
+ builder.automaticDataCollectionEnabled;
2731
+ // register services
2732
+ const services = [];
2733
+ builder.services.forEach(serviceFactory => {
2734
+ const serviceContext = new service_7.ServiceContext(this._context, this._disposable.defineNested());
2735
+ serviceContext.lifetime.addCallback(() => {
2736
+ serviceContext.onUnregister();
2737
+ }, serviceContext);
2738
+ const serviceInstance = serviceFactory[1](serviceContext);
2739
+ services.push([serviceContext, serviceInstance]);
2740
+ this._registry.map(serviceFactory[0]).asValue(serviceInstance);
2741
+ });
2742
+ builder.middlewares.forEach(middleware => {
2743
+ var _a;
2744
+ (_a = this.resolve(middlewareService_3.MiddlewareService)) === null || _a === void 0 ? void 0 : _a.useMiddleware(middleware);
2745
+ });
2746
+ builder.commands.forEach(command => {
2747
+ var _a;
2748
+ (_a = this.resolve(commandService_3.CommandService)) === null || _a === void 0 ? void 0 : _a.register(command[0], command[1]);
2749
+ });
2750
+ this.credential = builder.credential;
2751
+ //-------------------------------------------------------------------------
2752
+ // register services
2753
+ //-------------------------------------------------------------------------
2754
+ const waitList = [];
2755
+ // call onRegister service's callback
2756
+ services.forEach(([serviceContext]) => {
2757
+ if (typeof serviceContext.onRegister === "function") {
2758
+ waitList.push(serviceContext.onRegister());
2759
+ }
2760
+ });
2761
+ // wait for all services to register
2762
+ yield Promise.all(waitList);
2763
+ //-------------------------------------------------------------------------
2764
+ //-------------------------------------------------------------------------
2765
+ // start services
2766
+ //-------------------------------------------------------------------------
2767
+ waitList.length = 0;
2768
+ // call onStart service's callback
2769
+ services.forEach(([serviceContext]) => {
2770
+ if (typeof serviceContext.onStart === "function") {
2771
+ waitList.push(serviceContext.onStart());
2772
+ }
2773
+ });
2774
+ // wait for all services to start
2775
+ yield Promise.all(waitList);
2776
+ //-------------------------------------------------------------------------
2777
+ // start app, execute start command
2778
+ if (!(0, unitTest_2.isUnitTest)(unitTest_2.UnitTest.DO_NOT_START)) {
2779
+ yield this.context.execute(new startCommandHandler_1.StartCommand());
2780
+ }
2781
+ // log app initialized
2782
+ if (!(0, unitTest_2.isUnitTest)(unitTest_2.UnitTest.DO_NOT_PRINT_INITIALIZED_LOG)) {
2783
+ console.log(`DataIsland ${this.name} initialized`);
2784
+ }
2785
+ });
2786
+ }
2787
+ }
2788
+ exports.DataIslandAppImpl = DataIslandAppImpl;
2789
+ });
2790
+ define("src/internal/createApp.impl", ["require", "exports", "tslib", "src/internal/app.impl"], function (require, exports, tslib_24, app_impl_1) {
2791
+ "use strict";
2792
+ Object.defineProperty(exports, "__esModule", { value: true });
2793
+ exports._createApp = void 0;
2794
+ function _createApp(name, setup) {
2795
+ return tslib_24.__awaiter(this, void 0, void 0, function* () {
2796
+ const app = new app_impl_1.DataIslandAppImpl(name);
2797
+ yield app.initialize(setup);
2798
+ return app;
2799
+ });
2800
+ }
2801
+ exports._createApp = _createApp;
2802
+ });
2803
+ define("src/index", ["require", "exports", "tslib", "package", "src/internal/createApp.impl", "src/events", "src/disposable", "src/credentials", "src/dataIslandApp", "src/appBuilder", "src/context", "src/middleware", "src/storages/organizations/organizations", "src/storages/organizations/organization", "src/storages/workspaces/workspaces", "src/storages/workspaces/workspace", "src/storages/groups/groups", "src/storages/user/userProfile", "src/storages/files/files", "src/storages/files/file", "src/storages/files/filesPage", "src/storages/chats/chats", "src/storages/chats/chat", "src/storages/files/file", "src/storages/files/filesPage"], function (require, exports, tslib_25, package_json_1, createApp_impl_1, events_8, disposable_3, credentials_2, dataIslandApp_2, appBuilder_2, context_2, middleware_1, organizations_2, organization_2, workspaces_2, workspace_2, groups_2, userProfile_2, files_2, file_2, filesPage_2, chats_2, chat_2, file_3, filesPage_3) {
2804
+ "use strict";
2805
+ Object.defineProperty(exports, "__esModule", { value: true });
2806
+ exports.FilesPage = exports.File = exports.dataIslandApp = exports.dataIslandInstances = exports.DEFAULT_HOST = exports.DEFAULT_NAME = exports.SDK_VERSION = void 0;
2807
+ tslib_25.__exportStar(events_8, exports);
2808
+ tslib_25.__exportStar(disposable_3, exports);
2809
+ tslib_25.__exportStar(credentials_2, exports);
2810
+ tslib_25.__exportStar(dataIslandApp_2, exports);
2811
+ tslib_25.__exportStar(appBuilder_2, exports);
2812
+ tslib_25.__exportStar(context_2, exports);
2813
+ tslib_25.__exportStar(middleware_1, exports);
2814
+ tslib_25.__exportStar(organizations_2, exports);
2815
+ tslib_25.__exportStar(organization_2, exports);
2816
+ tslib_25.__exportStar(workspaces_2, exports);
2817
+ tslib_25.__exportStar(workspace_2, exports);
2818
+ tslib_25.__exportStar(groups_2, exports);
2819
+ tslib_25.__exportStar(userProfile_2, exports);
2820
+ tslib_25.__exportStar(files_2, exports);
2821
+ tslib_25.__exportStar(file_2, exports);
2822
+ tslib_25.__exportStar(filesPage_2, exports);
2823
+ tslib_25.__exportStar(chats_2, exports);
2824
+ tslib_25.__exportStar(chat_2, exports);
2825
+ const _appsNotReady = new Map();
2826
+ const _appsReady = new Map();
2827
+ /**
2828
+ * Current SDK version.
2829
+ */
2830
+ exports.SDK_VERSION = package_json_1.version;
2831
+ /**
2832
+ * Default DataIsland App name.
2833
+ */
2834
+ exports.DEFAULT_NAME = "[DEFAULT]";
2835
+ /**
2836
+ * Default DataIsland App host.
2837
+ */
2838
+ exports.DEFAULT_HOST = "https://api.dataisland.com.ua";
2839
+ /**
2840
+ * Returns a list of DataIsland App instances.
2841
+ */
2842
+ function dataIslandInstances() {
2843
+ return Array.from(_appsReady.values());
2844
+ }
2845
+ exports.dataIslandInstances = dataIslandInstances;
2846
+ /**
2847
+ * Returns a DataIsland App instance.
2848
+ * @param name Optional The name of the app.
2849
+ * @param setup Optional setup function.
2850
+ * @returns A DataIsland App instance.
2851
+ * @example
2852
+ * ```js
2853
+ * import { dataIslandApp, DEFAULT_NAME } from '@neuralinnovations/dataisland-sdk'
2854
+ *
2855
+ * const app = await dataIslandApp(DEFAULT_NAME, builder => {
2856
+ * builder.useHost("https://dataisland.com.ua")
2857
+ * builder.useAutomaticDataCollectionEnabled(true)
2858
+ * builder.useCredential(new BasicCredential("email", "password"))
2859
+ * })
2860
+ * ```
2861
+ */
2862
+ function dataIslandApp(name, setup) {
2863
+ return tslib_25.__awaiter(this, void 0, void 0, function* () {
2864
+ name = name !== null && name !== void 0 ? name : exports.DEFAULT_NAME;
2865
+ let appPromise = _appsNotReady.get(name);
2866
+ if (appPromise === undefined) {
2867
+ appPromise = (0, createApp_impl_1._createApp)(name, setup);
2868
+ appPromise
2869
+ .then(app => {
2870
+ _appsReady.set(name !== null && name !== void 0 ? name : exports.DEFAULT_NAME, app);
2871
+ })
2872
+ .catch(reason => {
2873
+ console.error(`Error: ${reason}`);
2874
+ _appsNotReady.delete(name !== null && name !== void 0 ? name : exports.DEFAULT_NAME);
2875
+ });
2876
+ _appsNotReady.set(name, appPromise);
2877
+ }
2878
+ else {
2879
+ if (setup !== undefined) {
2880
+ throw new Error(`DataIsland ${name} is initializing. You can't setup the same again.`);
2881
+ }
2882
+ }
2883
+ return yield appPromise;
2884
+ });
2885
+ }
2886
+ exports.dataIslandApp = dataIslandApp;
2887
+ Object.defineProperty(exports, "File", { enumerable: true, get: function () { return file_3.File; } });
2888
+ Object.defineProperty(exports, "FilesPage", { enumerable: true, get: function () { return filesPage_3.FilesPage; } });
2889
+ });
2890
+ //# sourceMappingURL=dataisland-sdk.js.map