@privateaim/core-http-kit 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/LICENSE +202 -0
  3. package/dist/client/index.d.ts +2 -0
  4. package/dist/client/index.d.ts.map +1 -0
  5. package/dist/client/module.d.ts +21 -0
  6. package/dist/client/module.d.ts.map +1 -0
  7. package/dist/domains/analysis/index.d.ts +2 -0
  8. package/dist/domains/analysis/index.d.ts.map +1 -0
  9. package/dist/domains/analysis/module.d.ts +20 -0
  10. package/dist/domains/analysis/module.d.ts.map +1 -0
  11. package/dist/domains/analysis-bucket/index.d.ts +2 -0
  12. package/dist/domains/analysis-bucket/index.d.ts.map +1 -0
  13. package/dist/domains/analysis-bucket/module.d.ts +9 -0
  14. package/dist/domains/analysis-bucket/module.d.ts.map +1 -0
  15. package/dist/domains/analysis-bucket-file/index.d.ts +2 -0
  16. package/dist/domains/analysis-bucket-file/index.d.ts.map +1 -0
  17. package/dist/domains/analysis-bucket-file/module.d.ts +12 -0
  18. package/dist/domains/analysis-bucket-file/module.d.ts.map +1 -0
  19. package/dist/domains/analysis-log/index.d.ts +2 -0
  20. package/dist/domains/analysis-log/index.d.ts.map +1 -0
  21. package/dist/domains/analysis-log/module.d.ts +12 -0
  22. package/dist/domains/analysis-log/module.d.ts.map +1 -0
  23. package/dist/domains/analysis-node/index.d.ts +2 -0
  24. package/dist/domains/analysis-node/index.d.ts.map +1 -0
  25. package/dist/domains/analysis-node/module.d.ts +12 -0
  26. package/dist/domains/analysis-node/module.d.ts.map +1 -0
  27. package/dist/domains/base.d.ts +8 -0
  28. package/dist/domains/base.d.ts.map +1 -0
  29. package/dist/domains/index.d.ts +14 -0
  30. package/dist/domains/index.d.ts.map +1 -0
  31. package/dist/domains/master-image/index.d.ts +2 -0
  32. package/dist/domains/master-image/index.d.ts.map +1 -0
  33. package/dist/domains/master-image/module.d.ts +11 -0
  34. package/dist/domains/master-image/module.d.ts.map +1 -0
  35. package/dist/domains/master-image-group/index.d.ts +2 -0
  36. package/dist/domains/master-image-group/index.d.ts.map +1 -0
  37. package/dist/domains/master-image-group/module.d.ts +9 -0
  38. package/dist/domains/master-image-group/module.d.ts.map +1 -0
  39. package/dist/domains/node/index.d.ts +2 -0
  40. package/dist/domains/node/index.d.ts.map +1 -0
  41. package/dist/domains/node/module.d.ts +13 -0
  42. package/dist/domains/node/module.d.ts.map +1 -0
  43. package/dist/domains/project/index.d.ts +2 -0
  44. package/dist/domains/project/index.d.ts.map +1 -0
  45. package/dist/domains/project/module.d.ts +12 -0
  46. package/dist/domains/project/module.d.ts.map +1 -0
  47. package/dist/domains/project-node/index.d.ts +2 -0
  48. package/dist/domains/project-node/index.d.ts.map +1 -0
  49. package/dist/domains/project-node/module.d.ts +12 -0
  50. package/dist/domains/project-node/module.d.ts.map +1 -0
  51. package/dist/domains/registry/index.d.ts +2 -0
  52. package/dist/domains/registry/index.d.ts.map +1 -0
  53. package/dist/domains/registry/module.d.ts +12 -0
  54. package/dist/domains/registry/module.d.ts.map +1 -0
  55. package/dist/domains/registry-project/index.d.ts +2 -0
  56. package/dist/domains/registry-project/index.d.ts.map +1 -0
  57. package/dist/domains/registry-project/module.d.ts +12 -0
  58. package/dist/domains/registry-project/module.d.ts.map +1 -0
  59. package/dist/domains/service/index.d.ts +2 -0
  60. package/dist/domains/service/index.d.ts.map +1 -0
  61. package/dist/domains/service/module.d.ts +12 -0
  62. package/dist/domains/service/module.d.ts.map +1 -0
  63. package/dist/domains/types-base.d.ts +29 -0
  64. package/dist/domains/types-base.d.ts.map +1 -0
  65. package/dist/index.cjs +1177 -0
  66. package/dist/index.cjs.map +1 -0
  67. package/dist/index.d.ts +3 -0
  68. package/dist/index.d.ts.map +1 -0
  69. package/dist/index.mjs +1163 -0
  70. package/dist/index.mjs.map +1 -0
  71. package/dist/utils/duplicate-slashes.d.ts +2 -0
  72. package/dist/utils/duplicate-slashes.d.ts.map +1 -0
  73. package/dist/utils/index.d.ts +3 -0
  74. package/dist/utils/index.d.ts.map +1 -0
  75. package/dist/utils/object-property.d.ts +4 -0
  76. package/dist/utils/object-property.d.ts.map +1 -0
  77. package/package.json +43 -0
  78. package/rollup.config.mjs +19 -0
  79. package/src/client/index.ts +8 -0
  80. package/src/client/module.ts +83 -0
  81. package/src/domains/analysis/index.ts +8 -0
  82. package/src/domains/analysis/module.ts +107 -0
  83. package/src/domains/analysis-bucket/index.ts +8 -0
  84. package/src/domains/analysis-bucket/module.ts +30 -0
  85. package/src/domains/analysis-bucket-file/index.ts +8 -0
  86. package/src/domains/analysis-bucket-file/module.ts +51 -0
  87. package/src/domains/analysis-log/index.ts +8 -0
  88. package/src/domains/analysis-log/module.ts +43 -0
  89. package/src/domains/analysis-node/index.ts +8 -0
  90. package/src/domains/analysis-node/module.ts +43 -0
  91. package/src/domains/base.ts +30 -0
  92. package/src/domains/index.ts +20 -0
  93. package/src/domains/master-image/index.ts +7 -0
  94. package/src/domains/master-image/module.ts +47 -0
  95. package/src/domains/master-image-group/index.ts +7 -0
  96. package/src/domains/master-image-group/module.ts +25 -0
  97. package/src/domains/node/index.ts +8 -0
  98. package/src/domains/node/module.ts +51 -0
  99. package/src/domains/project/index.ts +8 -0
  100. package/src/domains/project/module.ts +42 -0
  101. package/src/domains/project-node/index.ts +8 -0
  102. package/src/domains/project-node/module.ts +45 -0
  103. package/src/domains/registry/index.ts +8 -0
  104. package/src/domains/registry/module.ts +45 -0
  105. package/src/domains/registry-project/index.ts +8 -0
  106. package/src/domains/registry-project/module.ts +45 -0
  107. package/src/domains/service/index.ts +8 -0
  108. package/src/domains/service/module.ts +36 -0
  109. package/src/domains/types-base.ts +42 -0
  110. package/src/index.ts +9 -0
  111. package/src/utils/duplicate-slashes.ts +16 -0
  112. package/src/utils/index.ts +9 -0
  113. package/src/utils/object-property.ts +47 -0
  114. package/tsconfig.build.json +11 -0
  115. package/tsconfig.json +10 -0
@@ -0,0 +1,30 @@
1
+ /*
2
+ * Copyright (c) 2023-2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ import { createClient, isClient } from 'hapic';
9
+ import type { Client, RequestBaseOptions } from 'hapic';
10
+ import type { BaseAPIContext } from './types-base';
11
+
12
+ export class BaseAPI {
13
+ protected client! : Client;
14
+
15
+ // -----------------------------------------------------------------------------------
16
+
17
+ constructor(context?: BaseAPIContext) {
18
+ context = context || {};
19
+
20
+ this.setClient(context.client);
21
+ }
22
+
23
+ // -----------------------------------------------------------------------------------
24
+
25
+ setClient(input?: Client | RequestBaseOptions) {
26
+ this.client = isClient(input) ?
27
+ input :
28
+ createClient(input);
29
+ }
30
+ }
@@ -0,0 +1,20 @@
1
+ /*
2
+ * Copyright (c) 2021-2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ export * from './master-image-group';
9
+ export * from './master-image';
10
+ export * from './project';
11
+ export * from './project-node';
12
+ export * from './registry';
13
+ export * from './registry-project';
14
+ export * from './node';
15
+ export * from './analysis';
16
+ export * from './analysis-bucket-file';
17
+ export * from './analysis-log';
18
+ export * from './analysis-node';
19
+ export * from './service';
20
+ export * from './types-base';
@@ -0,0 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2021-2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+ export * from './module';
@@ -0,0 +1,47 @@
1
+ /*
2
+ * Copyright (c) 2021-2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ import type { BuildInput } from 'rapiq';
9
+ import { buildQuery } from 'rapiq';
10
+
11
+ import type { MasterImage, MasterImageCommand } from '@privateaim/core';
12
+ import { BaseAPI } from '../base';
13
+ import type { CollectionResourceResponse, SingleResourceResponse } from '../types-base';
14
+
15
+ export class MasterImageAPI extends BaseAPI {
16
+ async getMany(data?: BuildInput<MasterImage>): Promise<CollectionResourceResponse<MasterImage>> {
17
+ const response = await this.client.get(`master-images${buildQuery(data)}`);
18
+ return response.data;
19
+ }
20
+
21
+ async getOne(
22
+ id: MasterImage['id'],
23
+ data?: BuildInput<MasterImage>,
24
+ ): Promise<SingleResourceResponse<MasterImage>> {
25
+ const response = await this.client.get(`master-images/${id}${buildQuery(data)}`);
26
+ return response.data;
27
+ }
28
+
29
+ async delete(id: MasterImage['id']): Promise<SingleResourceResponse<MasterImage>> {
30
+ const response = await this.client.delete(`master-images/${id}`);
31
+ return response.data;
32
+ }
33
+
34
+ async runCommand(
35
+ command: MasterImageCommand,
36
+ data: Record<string, any> = {},
37
+ ): Promise<SingleResourceResponse<Record<string, any>>> {
38
+ const actionData = {
39
+ command,
40
+ ...data,
41
+ };
42
+
43
+ const { data: response } = await this.client.post('master-images/command', actionData);
44
+
45
+ return response;
46
+ }
47
+ }
@@ -0,0 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2021-2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+ export * from './module';
@@ -0,0 +1,25 @@
1
+ /*
2
+ * Copyright (c) 2021-2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ import type { BuildInput } from 'rapiq';
9
+ import { buildQuery } from 'rapiq';
10
+ import type { MasterImageGroup } from '@privateaim/core';
11
+ import { BaseAPI } from '../base';
12
+
13
+ import type { CollectionResourceResponse, SingleResourceResponse } from '../types-base';
14
+
15
+ export class MasterImageGroupAPI extends BaseAPI {
16
+ async getMany(data?: BuildInput<MasterImageGroup>): Promise<CollectionResourceResponse<MasterImageGroup>> {
17
+ const response = await this.client.get(`master-image-groups${buildQuery(data)}`);
18
+ return response.data;
19
+ }
20
+
21
+ async getOne(id: MasterImageGroup['id']): Promise<SingleResourceResponse<MasterImageGroup>> {
22
+ const response = await this.client.delete(`master-image-groups/${id}`);
23
+ return response.data;
24
+ }
25
+ }
@@ -0,0 +1,8 @@
1
+ /*
2
+ * Copyright (c) 2021-2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ export * from './module';
@@ -0,0 +1,51 @@
1
+ /*
2
+ * Copyright (c) 2021-2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ import type { BuildInput } from 'rapiq';
9
+ import { buildQuery } from 'rapiq';
10
+ import type { Node } from '@privateaim/core';
11
+ import { BaseAPI } from '../base';
12
+ import type { CollectionResourceResponse, SingleResourceResponse } from '../types-base';
13
+ import { nullifyEmptyObjectProperties } from '../../utils';
14
+
15
+ export class NodeAPI extends BaseAPI {
16
+ async getMany(options?: BuildInput<Node>): Promise<CollectionResourceResponse<Node>> {
17
+ const response = await this.client.get(`nodes${buildQuery(options)}`);
18
+
19
+ return response.data;
20
+ }
21
+
22
+ async getOne(id: Node['id'], options?: BuildInput<Node>): Promise<SingleResourceResponse<Node>> {
23
+ const response = await this.client.get(`nodes/${id}${buildQuery(options)}`);
24
+
25
+ return response.data;
26
+ }
27
+
28
+ async create(data: Record<string, any>): Promise<SingleResourceResponse<Node>> {
29
+ const response = await this.client.post('nodes', nullifyEmptyObjectProperties(data));
30
+
31
+ return response.data;
32
+ }
33
+
34
+ async update(id: Node['id'], data: Record<string, any>): Promise<SingleResourceResponse<Node>> {
35
+ const response = await this.client.post(`nodes/${id}`, nullifyEmptyObjectProperties(data));
36
+
37
+ return response.data;
38
+ }
39
+
40
+ async delete(id: Node['id']): Promise<SingleResourceResponse<Node>> {
41
+ const response = await this.client.delete(`nodes/${id}`);
42
+
43
+ return response.data;
44
+ }
45
+
46
+ async runCommand(id: Node['id'], task: string, data: Record<string, any>): Promise<SingleResourceResponse<Node>> {
47
+ const response = await this.client.post(`nodes/${id}/task`, { task, ...data });
48
+
49
+ return response.data;
50
+ }
51
+ }
@@ -0,0 +1,8 @@
1
+ /*
2
+ * Copyright (c) 2021-2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ export * from './module';
@@ -0,0 +1,42 @@
1
+ /*
2
+ * Copyright (c) 2021-2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ import type { BuildInput } from 'rapiq';
9
+ import { buildQuery } from 'rapiq';
10
+ import type { Project } from '@privateaim/core';
11
+ import { BaseAPI } from '../base';
12
+ import { nullifyEmptyObjectProperties } from '../../utils';
13
+ import type { CollectionResourceResponse, SingleResourceResponse } from '../types-base';
14
+
15
+ export class ProjectAPI extends BaseAPI {
16
+ async getMany(record?: BuildInput<Project>): Promise<CollectionResourceResponse<Project>> {
17
+ const response = await this.client.get(`projects${buildQuery(record)}`);
18
+ return response.data;
19
+ }
20
+
21
+ async getOne(id: Project['id'], requestRecord?: BuildInput<Project>): Promise<SingleResourceResponse<Project>> {
22
+ const response = await this.client.get(`projects/${id}${buildQuery(requestRecord)}`);
23
+
24
+ return response.data;
25
+ }
26
+
27
+ async create(data: Record<string, any>): Promise<SingleResourceResponse<Project>> {
28
+ const response = await this.client.post('projects', nullifyEmptyObjectProperties(data));
29
+
30
+ return response.data;
31
+ }
32
+
33
+ async delete(id: Project['id']): Promise<SingleResourceResponse<Project>> {
34
+ const response = await this.client.delete(`projects/${id}`);
35
+ return response.data;
36
+ }
37
+
38
+ async update(id: Project['id'], data: Record<string, any>): Promise<SingleResourceResponse<Project>> {
39
+ const response = await this.client.post(`projects/${id}`, nullifyEmptyObjectProperties(data));
40
+ return response.data;
41
+ }
42
+ }
@@ -0,0 +1,8 @@
1
+ /*
2
+ * Copyright (c) 2021-2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ export * from './module';
@@ -0,0 +1,45 @@
1
+ /*
2
+ * Copyright (c) 2021-2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ import type { BuildInput } from 'rapiq';
9
+ import { buildQuery } from 'rapiq';
10
+ import type { ProjectNode } from '@privateaim/core';
11
+ import { nullifyEmptyObjectProperties } from '../../utils';
12
+ import { BaseAPI } from '../base';
13
+ import type { CollectionResourceResponse, SingleResourceResponse } from '../types-base';
14
+
15
+ export class ProjectNodeAPI extends BaseAPI {
16
+ async getMany(data?: BuildInput<ProjectNode>): Promise<CollectionResourceResponse<ProjectNode>> {
17
+ const response = await this.client.get(`project-nodes${buildQuery(data)}`);
18
+
19
+ return response.data;
20
+ }
21
+
22
+ async getOne(id: ProjectNode['id'], data?: BuildInput<ProjectNode>): Promise<SingleResourceResponse<ProjectNode>> {
23
+ const response = await this.client.get(`project-nodes/${id}${buildQuery(data)}`);
24
+
25
+ return response.data;
26
+ }
27
+
28
+ async create(data: Partial<ProjectNode>): Promise<SingleResourceResponse<ProjectNode>> {
29
+ const response = await this.client.post('project-nodes', data);
30
+
31
+ return response.data;
32
+ }
33
+
34
+ async update(id: ProjectNode['id'], data: Partial<ProjectNode>): Promise<SingleResourceResponse<ProjectNode>> {
35
+ const response = await this.client.post(`project-nodes/${id}`, nullifyEmptyObjectProperties(data));
36
+
37
+ return response.data;
38
+ }
39
+
40
+ async delete(id: ProjectNode['id']): Promise<SingleResourceResponse<ProjectNode>> {
41
+ const response = await this.client.delete(`project-nodes/${id}`);
42
+
43
+ return response.data;
44
+ }
45
+ }
@@ -0,0 +1,8 @@
1
+ /*
2
+ * Copyright (c) 2022-2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ export * from './module';
@@ -0,0 +1,45 @@
1
+ /*
2
+ * Copyright (c) 2021-2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ import type { BuildInput } from 'rapiq';
9
+ import { buildQuery } from 'rapiq';
10
+ import type { Registry } from '@privateaim/core';
11
+ import { BaseAPI } from '../base';
12
+ import type { CollectionResourceResponse, SingleResourceResponse } from '../types-base';
13
+ import { nullifyEmptyObjectProperties } from '../../utils';
14
+
15
+ export class RegistryAPI extends BaseAPI {
16
+ async getMany(options?: BuildInput<Registry>): Promise<CollectionResourceResponse<Registry>> {
17
+ const response = await this.client.get(`registries${buildQuery(options)}`);
18
+
19
+ return response.data;
20
+ }
21
+
22
+ async getOne(id: Registry['id'], options?: BuildInput<Registry>): Promise<SingleResourceResponse<Registry>> {
23
+ const response = await this.client.get(`registries/${id}${buildQuery(options)}`);
24
+
25
+ return response.data;
26
+ }
27
+
28
+ async create(data: Record<string, any>): Promise<SingleResourceResponse<Registry>> {
29
+ const response = await this.client.post('registries', nullifyEmptyObjectProperties(data));
30
+
31
+ return response.data;
32
+ }
33
+
34
+ async update(id: Registry['id'], data: Record<string, any>): Promise<SingleResourceResponse<Registry>> {
35
+ const response = await this.client.post(`registries/${id}`, nullifyEmptyObjectProperties(data));
36
+
37
+ return response.data;
38
+ }
39
+
40
+ async delete(id: Registry['id']): Promise<SingleResourceResponse<Registry>> {
41
+ const response = await this.client.delete(`registries/${id}`);
42
+
43
+ return response.data;
44
+ }
45
+ }
@@ -0,0 +1,8 @@
1
+ /*
2
+ * Copyright (c) 2022-2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ export * from './module';
@@ -0,0 +1,45 @@
1
+ /*
2
+ * Copyright (c) 2021-2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ import type { BuildInput } from 'rapiq';
9
+ import { buildQuery } from 'rapiq';
10
+ import type { RegistryProject } from '@privateaim/core';
11
+ import { BaseAPI } from '../base';
12
+ import type { CollectionResourceResponse, SingleResourceResponse } from '../types-base';
13
+ import { nullifyEmptyObjectProperties } from '../../utils';
14
+
15
+ export class RegistryProjectAPI extends BaseAPI {
16
+ async getMany(options?: BuildInput<RegistryProject>): Promise<CollectionResourceResponse<RegistryProject>> {
17
+ const response = await this.client.get(`registry-projects${buildQuery(options)}`);
18
+
19
+ return response.data;
20
+ }
21
+
22
+ async getOne(id: RegistryProject['id'], options?: BuildInput<RegistryProject>): Promise<SingleResourceResponse<RegistryProject>> {
23
+ const response = await this.client.get(`registry-projects/${id}${buildQuery(options)}`);
24
+
25
+ return response.data;
26
+ }
27
+
28
+ async create(data: Record<string, any>): Promise<SingleResourceResponse<RegistryProject>> {
29
+ const response = await this.client.post('registry-projects', nullifyEmptyObjectProperties(data));
30
+
31
+ return response.data;
32
+ }
33
+
34
+ async update(id: RegistryProject['id'], data: Record<string, any>): Promise<SingleResourceResponse<RegistryProject>> {
35
+ const response = await this.client.post(`registry-projects/${id}`, nullifyEmptyObjectProperties(data));
36
+
37
+ return response.data;
38
+ }
39
+
40
+ async delete(id: RegistryProject['id']): Promise<SingleResourceResponse<RegistryProject>> {
41
+ const response = await this.client.delete(`registry-projects/${id}`);
42
+
43
+ return response.data;
44
+ }
45
+ }
@@ -0,0 +1,8 @@
1
+ /*
2
+ * Copyright (c) 2021-2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ export * from './module';
@@ -0,0 +1,36 @@
1
+ /*
2
+ * Copyright (c) 2021-2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ import type { Registry, RegistryAPICommand, RegistryProject } from '@privateaim/core';
9
+ import { ServiceID } from '@privateaim/core';
10
+ import type { SingleResourceResponse } from '../types-base';
11
+ import { BaseAPI } from '../base';
12
+ import { nullifyEmptyObjectProperties } from '../../utils';
13
+
14
+ export class ServiceAPI extends BaseAPI {
15
+ async runCommand(
16
+ id: `${ServiceID}`,
17
+ command: string,
18
+ data?: Record<string, any>,
19
+ ): Promise<SingleResourceResponse<Record<string, any>>> {
20
+ data = data || {};
21
+
22
+ const { data: resultData } = await this.client.post(`services/${id}/command`, nullifyEmptyObjectProperties({ command, ...data }));
23
+
24
+ return resultData;
25
+ }
26
+
27
+ async runRegistryCommand(
28
+ command: `${RegistryAPICommand}`,
29
+ data: {
30
+ id: Registry['id'] | RegistryProject['id'],
31
+ [key: string]: any
32
+ },
33
+ ): Promise<SingleResourceResponse<Record<string, any>>> {
34
+ return this.runCommand(ServiceID.REGISTRY, command, data);
35
+ }
36
+ }
@@ -0,0 +1,42 @@
1
+ /*
2
+ * Copyright (c) 2021-2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ import type { Client, RequestBaseOptions } from 'hapic';
9
+ import type { BuildInput } from 'rapiq';
10
+
11
+ export type SingleResourceResponse<R> = R;
12
+ export type CollectionResourceResponse<R> = {
13
+ data: R[],
14
+ meta: {
15
+ limit: number,
16
+ offset: number,
17
+ total: number
18
+ }
19
+ };
20
+
21
+ export type DomainEntityWithID = {
22
+ [key: string]: any,
23
+ id: any
24
+ };
25
+ export type DomainEntityID<T> = T extends DomainEntityWithID ?
26
+ T['id'] :
27
+ never;
28
+
29
+ export interface DomainAPISlim<T> {
30
+ getMany(record?: BuildInput<T>) : Promise<CollectionResourceResponse<T>>;
31
+ getOne(id: DomainEntityID<T>, record?: BuildInput<T>) : Promise<SingleResourceResponse<T>>;
32
+ delete(id: DomainEntityID<T>) : Promise<SingleResourceResponse<T>>;
33
+ create(data: Partial<T>) : Promise<SingleResourceResponse<T>>;
34
+ }
35
+
36
+ export interface DomainAPI<T> extends DomainAPISlim<T> {
37
+ update(id: DomainEntityID<T>, data: Partial<T>) : Promise<SingleResourceResponse<T>>;
38
+ }
39
+
40
+ export type BaseAPIContext = {
41
+ client?: Client | RequestBaseOptions
42
+ };
package/src/index.ts ADDED
@@ -0,0 +1,9 @@
1
+ /*
2
+ * Copyright (c) 2021-2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ export * from './client';
9
+ export * from './domains';
@@ -0,0 +1,16 @@
1
+ /*
2
+ * Copyright (c) 2022.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ export function cleanDoubleSlashes(input: string) : string {
9
+ if (input.indexOf('://') !== -1) {
10
+ return input.split('://')
11
+ .map((str) => cleanDoubleSlashes(str))
12
+ .join('://');
13
+ }
14
+
15
+ return input.replace(/\/+/g, '/');
16
+ }
@@ -0,0 +1,9 @@
1
+ /*
2
+ * Copyright (c) 2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ export * from './duplicate-slashes';
9
+ export * from './object-property';
@@ -0,0 +1,47 @@
1
+ /*
2
+ * Copyright (c) 2021.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ import { isPropertySet } from '@authup/kit';
9
+
10
+ export function nullifyEmptyObjectProperties<T extends Record<string, any>>(data: T) : T {
11
+ const keys : (keyof T)[] = Object.keys(data);
12
+
13
+ for (let i = 0; i < keys.length; i++) {
14
+ if (data[keys[i]] === '') {
15
+ data[keys[i]] = null as T[keyof T];
16
+ }
17
+ }
18
+
19
+ return data;
20
+ }
21
+
22
+ export function deleteUndefinedObjectProperties<T extends Record<string, any>>(data: T) : T {
23
+ const keys : string[] = Object.keys(data);
24
+
25
+ for (let i = 0; i < keys.length; i++) {
26
+ if (typeof data[keys[i]] === 'undefined') {
27
+ delete data[keys[i]];
28
+ }
29
+ }
30
+
31
+ return data;
32
+ }
33
+
34
+ export function extractObjectProperty<T extends Record<string, any>, K extends keyof T>(
35
+ data: T | undefined,
36
+ key: K,
37
+ ) : T[K] | undefined {
38
+ if (!data) {
39
+ return undefined;
40
+ }
41
+
42
+ if (isPropertySet(data, key)) {
43
+ return data[key];
44
+ }
45
+
46
+ return undefined;
47
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "../../tsconfig.build.json",
3
+
4
+ "compilerOptions": {
5
+ "outDir": "./dist"
6
+ },
7
+
8
+ "include": [
9
+ "src/**/*.ts"
10
+ ]
11
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "paths": {
5
+ "@privateaim/core": [
6
+ "./packages/core/src"
7
+ ]
8
+ }
9
+ }
10
+ }