@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.
- package/CHANGELOG.md +9 -0
- package/LICENSE +202 -0
- package/dist/client/index.d.ts +2 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/module.d.ts +21 -0
- package/dist/client/module.d.ts.map +1 -0
- package/dist/domains/analysis/index.d.ts +2 -0
- package/dist/domains/analysis/index.d.ts.map +1 -0
- package/dist/domains/analysis/module.d.ts +20 -0
- package/dist/domains/analysis/module.d.ts.map +1 -0
- package/dist/domains/analysis-bucket/index.d.ts +2 -0
- package/dist/domains/analysis-bucket/index.d.ts.map +1 -0
- package/dist/domains/analysis-bucket/module.d.ts +9 -0
- package/dist/domains/analysis-bucket/module.d.ts.map +1 -0
- package/dist/domains/analysis-bucket-file/index.d.ts +2 -0
- package/dist/domains/analysis-bucket-file/index.d.ts.map +1 -0
- package/dist/domains/analysis-bucket-file/module.d.ts +12 -0
- package/dist/domains/analysis-bucket-file/module.d.ts.map +1 -0
- package/dist/domains/analysis-log/index.d.ts +2 -0
- package/dist/domains/analysis-log/index.d.ts.map +1 -0
- package/dist/domains/analysis-log/module.d.ts +12 -0
- package/dist/domains/analysis-log/module.d.ts.map +1 -0
- package/dist/domains/analysis-node/index.d.ts +2 -0
- package/dist/domains/analysis-node/index.d.ts.map +1 -0
- package/dist/domains/analysis-node/module.d.ts +12 -0
- package/dist/domains/analysis-node/module.d.ts.map +1 -0
- package/dist/domains/base.d.ts +8 -0
- package/dist/domains/base.d.ts.map +1 -0
- package/dist/domains/index.d.ts +14 -0
- package/dist/domains/index.d.ts.map +1 -0
- package/dist/domains/master-image/index.d.ts +2 -0
- package/dist/domains/master-image/index.d.ts.map +1 -0
- package/dist/domains/master-image/module.d.ts +11 -0
- package/dist/domains/master-image/module.d.ts.map +1 -0
- package/dist/domains/master-image-group/index.d.ts +2 -0
- package/dist/domains/master-image-group/index.d.ts.map +1 -0
- package/dist/domains/master-image-group/module.d.ts +9 -0
- package/dist/domains/master-image-group/module.d.ts.map +1 -0
- package/dist/domains/node/index.d.ts +2 -0
- package/dist/domains/node/index.d.ts.map +1 -0
- package/dist/domains/node/module.d.ts +13 -0
- package/dist/domains/node/module.d.ts.map +1 -0
- package/dist/domains/project/index.d.ts +2 -0
- package/dist/domains/project/index.d.ts.map +1 -0
- package/dist/domains/project/module.d.ts +12 -0
- package/dist/domains/project/module.d.ts.map +1 -0
- package/dist/domains/project-node/index.d.ts +2 -0
- package/dist/domains/project-node/index.d.ts.map +1 -0
- package/dist/domains/project-node/module.d.ts +12 -0
- package/dist/domains/project-node/module.d.ts.map +1 -0
- package/dist/domains/registry/index.d.ts +2 -0
- package/dist/domains/registry/index.d.ts.map +1 -0
- package/dist/domains/registry/module.d.ts +12 -0
- package/dist/domains/registry/module.d.ts.map +1 -0
- package/dist/domains/registry-project/index.d.ts +2 -0
- package/dist/domains/registry-project/index.d.ts.map +1 -0
- package/dist/domains/registry-project/module.d.ts +12 -0
- package/dist/domains/registry-project/module.d.ts.map +1 -0
- package/dist/domains/service/index.d.ts +2 -0
- package/dist/domains/service/index.d.ts.map +1 -0
- package/dist/domains/service/module.d.ts +12 -0
- package/dist/domains/service/module.d.ts.map +1 -0
- package/dist/domains/types-base.d.ts +29 -0
- package/dist/domains/types-base.d.ts.map +1 -0
- package/dist/index.cjs +1177 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +1163 -0
- package/dist/index.mjs.map +1 -0
- package/dist/utils/duplicate-slashes.d.ts +2 -0
- package/dist/utils/duplicate-slashes.d.ts.map +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/object-property.d.ts +4 -0
- package/dist/utils/object-property.d.ts.map +1 -0
- package/package.json +43 -0
- package/rollup.config.mjs +19 -0
- package/src/client/index.ts +8 -0
- package/src/client/module.ts +83 -0
- package/src/domains/analysis/index.ts +8 -0
- package/src/domains/analysis/module.ts +107 -0
- package/src/domains/analysis-bucket/index.ts +8 -0
- package/src/domains/analysis-bucket/module.ts +30 -0
- package/src/domains/analysis-bucket-file/index.ts +8 -0
- package/src/domains/analysis-bucket-file/module.ts +51 -0
- package/src/domains/analysis-log/index.ts +8 -0
- package/src/domains/analysis-log/module.ts +43 -0
- package/src/domains/analysis-node/index.ts +8 -0
- package/src/domains/analysis-node/module.ts +43 -0
- package/src/domains/base.ts +30 -0
- package/src/domains/index.ts +20 -0
- package/src/domains/master-image/index.ts +7 -0
- package/src/domains/master-image/module.ts +47 -0
- package/src/domains/master-image-group/index.ts +7 -0
- package/src/domains/master-image-group/module.ts +25 -0
- package/src/domains/node/index.ts +8 -0
- package/src/domains/node/module.ts +51 -0
- package/src/domains/project/index.ts +8 -0
- package/src/domains/project/module.ts +42 -0
- package/src/domains/project-node/index.ts +8 -0
- package/src/domains/project-node/module.ts +45 -0
- package/src/domains/registry/index.ts +8 -0
- package/src/domains/registry/module.ts +45 -0
- package/src/domains/registry-project/index.ts +8 -0
- package/src/domains/registry-project/module.ts +45 -0
- package/src/domains/service/index.ts +8 -0
- package/src/domains/service/module.ts +36 -0
- package/src/domains/types-base.ts +42 -0
- package/src/index.ts +9 -0
- package/src/utils/duplicate-slashes.ts +16 -0
- package/src/utils/index.ts +9 -0
- package/src/utils/object-property.ts +47 -0
- package/tsconfig.build.json +11 -0
- 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,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,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,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,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,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,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,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,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,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
|
+
}
|