@hahnpro/flow-sdk 4.16.0 → 4.19.1

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 (81) hide show
  1. package/dist/FlowApplication.d.ts +2 -2
  2. package/dist/FlowApplication.js +2 -2
  3. package/dist/FlowElement.d.ts +2 -1
  4. package/dist/FlowElement.js +14 -2
  5. package/dist/index.d.ts +1 -1
  6. package/dist/index.js +1 -1
  7. package/package.json +12 -16
  8. package/dist/api/Queue.d.ts +0 -15
  9. package/dist/api/Queue.js +0 -27
  10. package/dist/api/api.d.ts +0 -62
  11. package/dist/api/api.js +0 -52
  12. package/dist/api/asset.interface.d.ts +0 -54
  13. package/dist/api/asset.interface.js +0 -2
  14. package/dist/api/asset.service.d.ts +0 -10
  15. package/dist/api/asset.service.js +0 -21
  16. package/dist/api/assettypes.service.d.ts +0 -6
  17. package/dist/api/assettypes.service.js +0 -10
  18. package/dist/api/content.interface.d.ts +0 -35
  19. package/dist/api/content.interface.js +0 -12
  20. package/dist/api/content.service.d.ts +0 -17
  21. package/dist/api/content.service.js +0 -39
  22. package/dist/api/data.interface.d.ts +0 -29
  23. package/dist/api/data.interface.js +0 -2
  24. package/dist/api/data.service.d.ts +0 -15
  25. package/dist/api/data.service.js +0 -49
  26. package/dist/api/endpoint.interface.d.ts +0 -22
  27. package/dist/api/endpoint.interface.js +0 -2
  28. package/dist/api/endpoint.service.d.ts +0 -8
  29. package/dist/api/endpoint.service.js +0 -17
  30. package/dist/api/events.interface.d.ts +0 -16
  31. package/dist/api/events.interface.js +0 -2
  32. package/dist/api/events.service.d.ts +0 -7
  33. package/dist/api/events.service.js +0 -13
  34. package/dist/api/http.service.d.ts +0 -26
  35. package/dist/api/http.service.js +0 -74
  36. package/dist/api/index.d.ts +0 -12
  37. package/dist/api/index.js +0 -16
  38. package/dist/api/mock/api.mock.d.ts +0 -158
  39. package/dist/api/mock/api.mock.js +0 -111
  40. package/dist/api/mock/asset.mock.service.d.ts +0 -12
  41. package/dist/api/mock/asset.mock.service.js +0 -21
  42. package/dist/api/mock/assetTypes.mock.service.d.ts +0 -6
  43. package/dist/api/mock/assetTypes.mock.service.js +0 -11
  44. package/dist/api/mock/content.mock.service.d.ts +0 -18
  45. package/dist/api/mock/content.mock.service.js +0 -64
  46. package/dist/api/mock/data.mock.service.d.ts +0 -13
  47. package/dist/api/mock/data.mock.service.js +0 -52
  48. package/dist/api/mock/endpoint.mock.service.d.ts +0 -15
  49. package/dist/api/mock/endpoint.mock.service.js +0 -24
  50. package/dist/api/mock/events.mock.service.d.ts +0 -7
  51. package/dist/api/mock/events.mock.service.js +0 -14
  52. package/dist/api/mock/index.d.ts +0 -9
  53. package/dist/api/mock/index.js +0 -12
  54. package/dist/api/mock/secret.mock.service.d.ts +0 -6
  55. package/dist/api/mock/secret.mock.service.js +0 -11
  56. package/dist/api/mock/task.mock.service.d.ts +0 -7
  57. package/dist/api/mock/task.mock.service.js +0 -15
  58. package/dist/api/mock/timeseries.mock.service.d.ts +0 -19
  59. package/dist/api/mock/timeseries.mock.service.js +0 -69
  60. package/dist/api/mock/user.mock.service.d.ts +0 -7
  61. package/dist/api/mock/user.mock.service.js +0 -14
  62. package/dist/api/proxy.service.d.ts +0 -11
  63. package/dist/api/proxy.service.js +0 -17
  64. package/dist/api/secret.interface.d.ts +0 -7
  65. package/dist/api/secret.interface.js +0 -2
  66. package/dist/api/secret.service.d.ts +0 -6
  67. package/dist/api/secret.service.js +0 -10
  68. package/dist/api/sidriveiq.interface.d.ts +0 -104
  69. package/dist/api/sidriveiq.interface.js +0 -2
  70. package/dist/api/sidriveiq.service.d.ts +0 -97
  71. package/dist/api/sidriveiq.service.js +0 -97
  72. package/dist/api/task.interface.d.ts +0 -22
  73. package/dist/api/task.interface.js +0 -2
  74. package/dist/api/task.service.d.ts +0 -7
  75. package/dist/api/task.service.js +0 -13
  76. package/dist/api/timeseries.interface.d.ts +0 -39
  77. package/dist/api/timeseries.interface.js +0 -2
  78. package/dist/api/timeseries.service.d.ts +0 -17
  79. package/dist/api/timeseries.service.js +0 -38
  80. package/dist/api/user.service.d.ts +0 -6
  81. package/dist/api/user.service.js +0 -21
@@ -1,8 +1,8 @@
1
1
  import 'reflect-metadata';
2
2
  import type { CloudEvent } from 'cloudevents';
3
3
  import { PartialObserver } from 'rxjs';
4
+ import { API } from '@hahnpro/hpc-api';
4
5
  import { AmqpConnection, Nack } from './amqp';
5
- import { API } from './api';
6
6
  import type { ClassType, Flow, FlowElementContext } from './flow.interface';
7
7
  import type { FlowEvent } from './FlowEvent';
8
8
  import { Logger } from './FlowLogger';
@@ -34,7 +34,7 @@ export declare class FlowApplication {
34
34
  publishEvent: (event: FlowEvent) => Promise<void>;
35
35
  get rpcClient(): RpcClient;
36
36
  /**
37
- * Calls onDestroy lifecycle mehtod on all flow elements,
37
+ * Calls onDestroy lifecycle method on all flow elements,
38
38
  * closes amqp connection after allowing logs to be processed and published
39
39
  * then exits process
40
40
  */
@@ -9,8 +9,8 @@ const rxjs_1 = require("rxjs");
9
9
  const operators_1 = require("rxjs/operators");
10
10
  const util_1 = require("util");
11
11
  const uuid_1 = require("uuid");
12
+ const hpc_api_1 = require("@hahnpro/hpc-api");
12
13
  const amqp_1 = require("./amqp");
13
- const api_1 = require("./api");
14
14
  const utils_1 = require("./utils");
15
15
  const FlowLogger_1 = require("./FlowLogger");
16
16
  const RpcClient_1 = require("./RpcClient");
@@ -176,7 +176,7 @@ class FlowApplication {
176
176
  });
177
177
  try {
178
178
  if (skipApi !== true) {
179
- this.api = new api_1.API();
179
+ this.api = new hpc_api_1.API();
180
180
  }
181
181
  }
182
182
  catch (err) {
@@ -1,5 +1,5 @@
1
1
  import { PythonShell } from 'python-shell';
2
- import { API } from './api';
2
+ import { API } from '@hahnpro/hpc-api';
3
3
  import { ClassType, DeploymentMessage, FlowContext, FlowElementContext } from './flow.interface';
4
4
  import { Context } from './FlowApplication';
5
5
  import { FlowEvent } from './FlowEvent';
@@ -30,6 +30,7 @@ export declare abstract class FlowElement<T = any> {
30
30
  protected emitOutput(data?: any, outputId?: string, time?: Date): FlowEvent;
31
31
  protected emitEvent(data: any, inputEvent: FlowEvent, outputId?: string, time?: Date): FlowEvent;
32
32
  protected validateProperties<P>(classType: ClassType<P>, properties?: any, whitelist?: boolean): P;
33
+ protected logValidationErrors(error: any, parent?: string): void;
33
34
  protected validateEventData<E>(classType: ClassType<E>, event: FlowEvent, whitelist?: boolean): E;
34
35
  protected interpolate: (value: any, ...templateVariables: any) => any;
35
36
  protected callRpcFunction(functionName: string, ...args: any[]): Promise<unknown>;
@@ -64,9 +64,9 @@ class FlowElement {
64
64
  validateProperties(classType, properties = {}, whitelist = false) {
65
65
  const props = (0, class_transformer_1.plainToClass)(classType, properties);
66
66
  const errors = (0, class_validator_1.validateSync)(props, { whitelist });
67
- if (errors && Array.isArray(errors) && errors.length > 0) {
67
+ if (Array.isArray(errors) && errors.length > 0) {
68
68
  for (const e of errors) {
69
- this.logger.error(`Validation for property "${e.property}" failed:\n${JSON.stringify(e.constraints || {})}\nvalue: ${e.value}`);
69
+ this.logValidationErrors(e);
70
70
  }
71
71
  throw new Error('Properties Validation failed');
72
72
  }
@@ -74,6 +74,18 @@ class FlowElement {
74
74
  return props;
75
75
  }
76
76
  }
77
+ logValidationErrors(error, parent) {
78
+ const { children, constraints, property, value } = error;
79
+ const name = parent ? parent + '.' + property : property;
80
+ if (constraints) {
81
+ this.logger.error(`Validation for property "${name}" failed:\n${JSON.stringify(constraints || {})}\nvalue: ${value}`);
82
+ }
83
+ else if (Array.isArray(children)) {
84
+ for (const child of children) {
85
+ this.logValidationErrors(child, name);
86
+ }
87
+ }
88
+ }
77
89
  validateEventData(classType, event, whitelist = false) {
78
90
  return this.validateProperties(classType, event.getData(), whitelist);
79
91
  }
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * from './api';
1
+ export * from '@hahnpro/hpc-api';
2
2
  export * from './flow.interface';
3
3
  export * from './utils';
4
4
  export * from './FlowApplication';
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.IncompatableWith = void 0;
4
4
  const tslib_1 = require("tslib");
5
- (0, tslib_1.__exportStar)(require("./api"), exports);
5
+ (0, tslib_1.__exportStar)(require("@hahnpro/hpc-api"), exports);
6
6
  (0, tslib_1.__exportStar)(require("./flow.interface"), exports);
7
7
  (0, tslib_1.__exportStar)(require("./utils"), exports);
8
8
  (0, tslib_1.__exportStar)(require("./FlowApplication"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hahnpro/flow-sdk",
3
- "version": "4.16.0",
3
+ "version": "4.19.1",
4
4
  "description": "SDK for building Flow Modules",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -24,34 +24,30 @@
24
24
  "access": "public"
25
25
  },
26
26
  "dependencies": {
27
+ "@hahnpro/hpc-api": "1.0.1",
27
28
  "amqp-connection-manager": "^3.7.0",
28
29
  "amqplib": "^0.8.0",
29
- "axios": "^0.22.0",
30
- "class-transformer": "0.3.1",
31
- "class-validator": "~0.12.2",
32
- "class-validator-jsonschema": "^2.2.0",
33
- "cloudevents": "^4.0.3",
34
- "form-data": "^4.0.0",
35
- "jwt-decode": "^3.1.2",
30
+ "class-transformer": "0.4.0",
31
+ "class-validator": "~0.13.1",
32
+ "class-validator-jsonschema": "^3.1.0",
33
+ "cloudevents": "^5.0.0",
36
34
  "lodash": "^4.17.21",
37
35
  "object-sizeof": "^1.6.1",
38
- "p-queue": "^6.6.2",
39
- "python-shell": "^3.0.0",
36
+ "python-shell": "^3.0.1",
40
37
  "reflect-metadata": "^0.1.13",
41
- "rxjs": "^7.3.1",
38
+ "rxjs": "^7.4.0",
42
39
  "string-interp": "^0.3.6",
43
40
  "uuid": "^8.3.2"
44
41
  },
45
42
  "devDependencies": {
46
- "@golevelup/nestjs-rabbitmq": "^1.17.1",
43
+ "@golevelup/nestjs-rabbitmq": "^1.18.0",
47
44
  "@types/amqp-connection-manager": "^2.0.12",
48
45
  "@types/amqplib": "^0.8.2",
49
46
  "@types/jest": "^27.0.2",
50
47
  "@types/lodash": "^4.14.175",
51
- "@types/node": "^14.17.20",
52
- "axios-mock-adapter": "^1.20.0",
53
- "jest": "^27.2.4",
54
- "typescript": "^4.4.3"
48
+ "@types/node": "^14.17.22",
49
+ "jest": "^27.2.5",
50
+ "typescript": "^4.4.4"
55
51
  },
56
52
  "engines": {
57
53
  "node": ">=v14.13"
@@ -1,15 +0,0 @@
1
- import PQueue from 'p-queue';
2
- export declare class Queue extends PQueue {
3
- private peak;
4
- private total;
5
- constructor(options?: QueueOptions);
6
- getStats(): {
7
- peak: number;
8
- pending: number;
9
- size: number;
10
- total: number;
11
- };
12
- }
13
- export interface QueueOptions {
14
- concurrent?: number;
15
- }
package/dist/api/Queue.js DELETED
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Queue = void 0;
4
- const tslib_1 = require("tslib");
5
- const p_queue_1 = (0, tslib_1.__importDefault)(require("p-queue"));
6
- class Queue extends p_queue_1.default {
7
- constructor(options = { concurrent: 1 }) {
8
- super({ concurrency: options.concurrent || 1 });
9
- this.peak = 0;
10
- this.total = 0;
11
- this.on('add', () => {
12
- this.peak = Math.max(this.peak, this.size);
13
- });
14
- this.on('active', () => {
15
- this.total++;
16
- });
17
- }
18
- getStats() {
19
- return {
20
- peak: this.peak,
21
- pending: this.pending,
22
- size: this.size,
23
- total: this.total,
24
- };
25
- }
26
- }
27
- exports.Queue = Queue;
package/dist/api/api.d.ts DELETED
@@ -1,62 +0,0 @@
1
- import { AssetService } from './asset.service';
2
- import { AssetTypesService } from './assettypes.service';
3
- import { ContentService } from './content.service';
4
- import { EndpointService } from './endpoint.service';
5
- import { EventsService } from './events.service';
6
- import { HttpClient } from './http.service';
7
- import { ProxyService } from './proxy.service';
8
- import { SecretService } from './secret.service';
9
- import { SiDriveIqService } from './sidriveiq.service';
10
- import { TaskService } from './task.service';
11
- import { TimeSeriesService } from './timeseries.service';
12
- import { UserService } from './user.service';
13
- export declare class API {
14
- httpClient: HttpClient;
15
- assets: AssetService;
16
- assetTypes: AssetTypesService;
17
- contents: ContentService;
18
- endpoints: EndpointService;
19
- events: EventsService;
20
- proxy: ProxyService;
21
- secrets: SecretService;
22
- tasks: TaskService;
23
- timeSeries: TimeSeriesService;
24
- users: UserService;
25
- /**
26
- * @deprecated use "assets" instead
27
- */
28
- assetManager: AssetService;
29
- /**
30
- * @deprecated use "contents" instead
31
- */
32
- contentManager: ContentService;
33
- /**
34
- * @deprecated use "endpoints" instead
35
- */
36
- endpointManager: EndpointService;
37
- /**
38
- * @deprecated use "events" instead
39
- */
40
- eventsManager: EventsService;
41
- /**
42
- * @deprecated use "secrets" instead
43
- */
44
- secretsManager: SecretService;
45
- /**
46
- * @deprecated use proxy service instead
47
- */
48
- siDrive: SiDriveIqService;
49
- /**
50
- * @deprecated use "tasks" instead
51
- */
52
- taskManager: TaskService;
53
- /**
54
- * @deprecated use "timeSeries" instead
55
- */
56
- timeSeriesManager: TimeSeriesService;
57
- /**
58
- * @deprecated use "users" instead
59
- */
60
- userManager: UserService;
61
- constructor();
62
- }
package/dist/api/api.js DELETED
@@ -1,52 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.API = void 0;
4
- const asset_service_1 = require("./asset.service");
5
- const assettypes_service_1 = require("./assettypes.service");
6
- const content_service_1 = require("./content.service");
7
- const endpoint_service_1 = require("./endpoint.service");
8
- const events_service_1 = require("./events.service");
9
- const http_service_1 = require("./http.service");
10
- const proxy_service_1 = require("./proxy.service");
11
- const secret_service_1 = require("./secret.service");
12
- const sidriveiq_service_1 = require("./sidriveiq.service");
13
- const task_service_1 = require("./task.service");
14
- const timeseries_service_1 = require("./timeseries.service");
15
- const user_service_1 = require("./user.service");
16
- class API {
17
- constructor() {
18
- let apiBaseUrl = process.env.API_BASE_URL || 'https://testing.hahnpro.com';
19
- if (!apiBaseUrl.startsWith('https') && !apiBaseUrl.startsWith('http')) {
20
- console.info('no protocol specified - using HTTPS');
21
- apiBaseUrl = `https://${apiBaseUrl}`;
22
- }
23
- const authBaseUrl = process.env.AUTH_BASE_URL || apiBaseUrl;
24
- const realm = process.env.AUTH_REALM || 'hpc';
25
- const client = process.env.API_USER || 'flow-executor-service';
26
- const secret = process.env.AUTH_SECRET;
27
- if (!secret) {
28
- throw new Error('"API_BASE_URL", "API_USER", "AUTH_REALM" and "AUTH_SECRET" environment variables must be set');
29
- }
30
- this.httpClient = new http_service_1.HttpClient(apiBaseUrl, authBaseUrl, realm, client, secret);
31
- this.assets = new asset_service_1.AssetService(this.httpClient);
32
- this.assetTypes = new assettypes_service_1.AssetTypesService(this.httpClient);
33
- this.contents = new content_service_1.ContentService(this.httpClient);
34
- this.endpoints = new endpoint_service_1.EndpointService(this.httpClient);
35
- this.events = new events_service_1.EventsService(this.httpClient);
36
- this.proxy = new proxy_service_1.ProxyService(this.httpClient);
37
- this.secrets = new secret_service_1.SecretService(this.httpClient);
38
- this.tasks = new task_service_1.TaskService(this.httpClient);
39
- this.timeSeries = new timeseries_service_1.TimeSeriesService(this.httpClient);
40
- this.users = new user_service_1.UserService(this.httpClient);
41
- this.assetManager = this.assets;
42
- this.contentManager = this.contents;
43
- this.endpointManager = this.endpoints;
44
- this.eventsManager = this.events;
45
- this.secretsManager = this.secrets;
46
- this.siDrive = new sidriveiq_service_1.SiDriveIqService(this.httpClient);
47
- this.taskManager = this.tasks;
48
- this.timeSeriesManager = this.timeSeries;
49
- this.userManager = this.users;
50
- }
51
- }
52
- exports.API = API;
@@ -1,54 +0,0 @@
1
- export interface Asset {
2
- id?: string;
3
- name: string;
4
- type: string | AssetType;
5
- type$name?: string;
6
- readPermissions: string[];
7
- readWritePermissions: string[];
8
- tags?: string[];
9
- parent?: any | Asset;
10
- parent$name?: string;
11
- data?: any;
12
- attachments?: string[];
13
- image?: string;
14
- actions?: string[];
15
- notificationEndpoints?: string[];
16
- createdAt?: string;
17
- updatedAt?: string;
18
- }
19
- export interface AssetType {
20
- id?: string;
21
- name: string;
22
- allowedParent?: string;
23
- allowedParent$name?: string;
24
- readPermissions: string[];
25
- readWritePermissions: string[];
26
- typeSchema: any;
27
- supertype?: string;
28
- supertype$name?: string;
29
- uiSchema: any;
30
- actions?: string[];
31
- createdAt?: string;
32
- updatedAt?: string;
33
- }
34
- export interface Attachment {
35
- id?: string;
36
- filename: string;
37
- metadata: {
38
- mimetype: string;
39
- };
40
- }
41
- export interface Action {
42
- id?: string;
43
- name?: string;
44
- description?: string;
45
- type?: string;
46
- method?: string;
47
- authToken?: string;
48
- isAuthFromAsset?: boolean;
49
- url?: string;
50
- data?: string;
51
- responseType?: string;
52
- readPermissions: string[];
53
- readWritePermissions: string[];
54
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,10 +0,0 @@
1
- import FormData from 'form-data';
2
- import { Asset } from './asset.interface';
3
- import { Paginated, RequestParameter } from './data.interface';
4
- import { DataService } from './data.service';
5
- import { HttpClient } from './http.service';
6
- export declare class AssetService extends DataService<Asset> {
7
- constructor(httpClient: HttpClient);
8
- addAttachment: (id: string, form: FormData) => Promise<Asset>;
9
- getChildren(assetId: string, params?: RequestParameter): Promise<Paginated<Asset[]>>;
10
- }
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AssetService = void 0;
4
- const data_service_1 = require("./data.service");
5
- class AssetService extends data_service_1.DataService {
6
- constructor(httpClient) {
7
- super(httpClient, process.env.DEBUG_ASSET_URL || 'api/assets');
8
- this.addAttachment = (id, form) => {
9
- const headers = Object.assign({}, form.getHeaders());
10
- return this.httpClient.post(`${this.basePath}/${id}/attachment`, form, {
11
- headers,
12
- maxBodyLength: Infinity,
13
- maxContentLength: Infinity,
14
- });
15
- };
16
- }
17
- getChildren(assetId, params = {}) {
18
- return this.getManyFiltered({ parent: assetId }, params);
19
- }
20
- }
21
- exports.AssetService = AssetService;
@@ -1,6 +0,0 @@
1
- import { AssetType } from './asset.interface';
2
- import { DataService } from './data.service';
3
- import { HttpClient } from './http.service';
4
- export declare class AssetTypesService extends DataService<AssetType> {
5
- constructor(httpClient: HttpClient);
6
- }
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AssetTypesService = void 0;
4
- const data_service_1 = require("./data.service");
5
- class AssetTypesService extends data_service_1.DataService {
6
- constructor(httpClient) {
7
- super(httpClient, 'api/assettypes');
8
- }
9
- }
10
- exports.AssetTypesService = AssetTypesService;
@@ -1,35 +0,0 @@
1
- declare type FileType = 'original' | 'preview-sm' | 'preview-md' | 'preview-lg';
2
- declare type StorageProvider = 's3' | 'mongo';
3
- export interface Storage {
4
- id: string;
5
- filename: string;
6
- mimetype: string;
7
- size: number;
8
- createdAt: string;
9
- provider?: StorageProvider;
10
- type?: FileType;
11
- md5?: string;
12
- }
13
- export interface Content {
14
- id?: string;
15
- fileId: string;
16
- filename: string;
17
- mimetype: string;
18
- size: number;
19
- readPermissions: string[];
20
- readWritePermissions: string[];
21
- tags?: string[];
22
- assets?: string[];
23
- files?: Storage[];
24
- createdAt?: string;
25
- updatedAt?: string;
26
- }
27
- export declare enum ReturnType {
28
- TEXT = 0,
29
- JSON = 1,
30
- NODEBUFFER = 2,
31
- BLOB = 3,
32
- ARRAYBUFFER = 4,
33
- NODESTREAM = 5
34
- }
35
- export {};
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ReturnType = void 0;
4
- var ReturnType;
5
- (function (ReturnType) {
6
- ReturnType[ReturnType["TEXT"] = 0] = "TEXT";
7
- ReturnType[ReturnType["JSON"] = 1] = "JSON";
8
- ReturnType[ReturnType["NODEBUFFER"] = 2] = "NODEBUFFER";
9
- ReturnType[ReturnType["BLOB"] = 3] = "BLOB";
10
- ReturnType[ReturnType["ARRAYBUFFER"] = 4] = "ARRAYBUFFER";
11
- ReturnType[ReturnType["NODESTREAM"] = 5] = "NODESTREAM";
12
- })(ReturnType = exports.ReturnType || (exports.ReturnType = {}));
@@ -1,17 +0,0 @@
1
- /// <reference types="node" />
2
- import FormData from 'form-data';
3
- import { Content, ReturnType } from './content.interface';
4
- import { DataService } from './data.service';
5
- import { HttpClient } from './http.service';
6
- import { Readable } from 'stream';
7
- export declare class ContentService extends DataService<Content> {
8
- constructor(httpClient: HttpClient);
9
- upload: (form: FormData) => Promise<Content>;
10
- download(id: string, raw?: boolean): Promise<Blob | ArrayBuffer>;
11
- download(id: string, returnType: ReturnType.TEXT): Promise<string>;
12
- download(id: string, returnType: ReturnType.JSON): Promise<Record<string, unknown>>;
13
- download(id: string, returnType: ReturnType.NODEBUFFER): Promise<Buffer>;
14
- download(id: string, returnType: ReturnType.BLOB): Promise<Blob>;
15
- download(id: string, returnType: ReturnType.ARRAYBUFFER): Promise<ArrayBuffer>;
16
- download(id: string, returnType: ReturnType.NODESTREAM): Promise<Readable>;
17
- }
@@ -1,39 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ContentService = void 0;
4
- const content_interface_1 = require("./content.interface");
5
- const data_service_1 = require("./data.service");
6
- class ContentService extends data_service_1.DataService {
7
- constructor(httpClient) {
8
- super(httpClient, process.env.DEBUG_CONTENT_URL || 'api/contents');
9
- this.upload = (form) => {
10
- const headers = Object.assign({}, form.getHeaders());
11
- return this.httpClient.post(`${this.basePath}`, form, { headers, maxBodyLength: Infinity, maxContentLength: Infinity });
12
- };
13
- }
14
- async download(id, second) {
15
- let returnType;
16
- if (typeof second === 'boolean' || !second) {
17
- returnType = second ? content_interface_1.ReturnType.ARRAYBUFFER : content_interface_1.ReturnType.BLOB;
18
- }
19
- else {
20
- returnType = second;
21
- }
22
- const url = `${this.basePath}/${id}/download`;
23
- switch (returnType) {
24
- case content_interface_1.ReturnType.TEXT:
25
- return this.httpClient.get(url, { responseType: 'text' });
26
- case content_interface_1.ReturnType.JSON:
27
- return this.httpClient.get(url, { responseType: 'json' });
28
- case content_interface_1.ReturnType.NODEBUFFER:
29
- return Buffer.from(new Uint8Array(await this.httpClient.get(url, { responseType: 'arraybuffer' })));
30
- case content_interface_1.ReturnType.BLOB:
31
- return this.httpClient.get(url, { responseType: 'blob' });
32
- case content_interface_1.ReturnType.ARRAYBUFFER:
33
- return this.httpClient.get(url, { responseType: 'arraybuffer' });
34
- case content_interface_1.ReturnType.NODESTREAM:
35
- return this.httpClient.get(url, { responseType: 'stream' });
36
- }
37
- }
38
- }
39
- exports.ContentService = ContentService;
@@ -1,29 +0,0 @@
1
- export interface Paginated<T> {
2
- docs: T;
3
- total: number;
4
- limit: number;
5
- page?: number;
6
- pages?: number;
7
- offset?: number;
8
- }
9
- export interface RequestParameter {
10
- filter?: string;
11
- limit?: number;
12
- page?: number;
13
- populate?: string;
14
- sort?: string;
15
- }
16
- export interface Filter {
17
- tags?: string[];
18
- type?: string;
19
- parent?: string;
20
- }
21
- export interface DataInterface<T> {
22
- addOne(dto: any): Promise<T>;
23
- addMany(dto: any[]): Promise<T[]>;
24
- getOne(id: string, options?: any): Promise<T>;
25
- getMany(params?: RequestParameter, parentId?: string): Promise<Paginated<T[]>>;
26
- getManyFiltered(filter: Filter, params?: RequestParameter, parentId?: string): Promise<Paginated<T[]>>;
27
- updateOne(id: string, dto: any): Promise<T>;
28
- deleteOne(id: string): Promise<any>;
29
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,15 +0,0 @@
1
- import { DataInterface, Filter, Paginated, RequestParameter } from './data.interface';
2
- import { HttpClient } from './http.service';
3
- export declare class DataService<T> implements DataInterface<T> {
4
- protected readonly httpClient: HttpClient;
5
- protected readonly basePath: any;
6
- constructor(httpClient: HttpClient, basePath: any);
7
- addOne(dto: any): Promise<T>;
8
- addMany(dto: any[]): Promise<T[]>;
9
- getOne(id: string, options?: any): Promise<T>;
10
- getMany(params?: RequestParameter): Promise<Paginated<T[]>>;
11
- getManyFiltered(filter: Filter, params?: RequestParameter): Promise<Paginated<T[]>>;
12
- updateOne(id: string, dto: any): Promise<T>;
13
- deleteOne(id: string): Promise<any>;
14
- protected getFilterString(filter: Filter): string;
15
- }
@@ -1,49 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DataService = void 0;
4
- class DataService {
5
- constructor(httpClient, basePath) {
6
- this.httpClient = httpClient;
7
- this.basePath = basePath;
8
- }
9
- addOne(dto) {
10
- return this.httpClient.post(this.basePath, dto);
11
- }
12
- addMany(dto) {
13
- return this.httpClient.post(`${this.basePath}/many`, dto);
14
- }
15
- getOne(id, options = {}) {
16
- const params = options.populate ? { populate: options.populate } : {};
17
- return this.httpClient.get(`${this.basePath}/${id}`, { params });
18
- }
19
- getMany(params = {}) {
20
- params.limit = params.limit || 0;
21
- params.page = params.page || 1;
22
- return this.httpClient.get(`${this.basePath}`, { params });
23
- }
24
- getManyFiltered(filter, params = {}) {
25
- params.filter = this.getFilterString(filter);
26
- return this.getMany(params);
27
- }
28
- updateOne(id, dto) {
29
- return this.httpClient.put(`${this.basePath}/${id}`, dto);
30
- }
31
- deleteOne(id) {
32
- return this.httpClient.delete(`${this.basePath}/${id}`);
33
- }
34
- getFilterString(filter) {
35
- const { parent, tags, type } = filter;
36
- const filters = [];
37
- if (tags) {
38
- filters.push('tags=@' + tags.join());
39
- }
40
- if (type) {
41
- filters.push('type==' + type);
42
- }
43
- if (parent) {
44
- filters.push('parent==' + parent);
45
- }
46
- return filters.join(';');
47
- }
48
- }
49
- exports.DataService = DataService;
@@ -1,22 +0,0 @@
1
- export interface Endpoint {
2
- id?: string;
3
- name: string;
4
- description?: string;
5
- status: string;
6
- config: {
7
- type: string;
8
- url?: string;
9
- authToken: string;
10
- recipients?: string[];
11
- };
12
- readPermissions: string[];
13
- readWritePermissions: string[];
14
- }
15
- export interface EndpointLog {
16
- id?: string;
17
- endpoint: string;
18
- type?: 'info' | 'error';
19
- data?: string;
20
- group?: string;
21
- updatedAt?: string;
22
- }