@kapeta/local-cluster-service 0.7.6 → 0.8.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.
- package/CHANGELOG.md +14 -0
- package/definitions.d.ts +0 -7
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/src/attachments/routes.d.ts +3 -0
- package/dist/cjs/src/attachments/routes.js +61 -0
- package/dist/cjs/src/identities/routes.js +12 -2
- package/dist/cjs/src/storageService.d.ts +1 -1
- package/dist/cjs/src/storageService.js +4 -1
- package/dist/esm/index.js +2 -0
- package/dist/esm/src/attachments/routes.d.ts +3 -0
- package/dist/esm/src/attachments/routes.js +56 -0
- package/dist/esm/src/identities/routes.js +12 -2
- package/dist/esm/src/storageService.d.ts +1 -1
- package/dist/esm/src/storageService.js +4 -1
- package/index.ts +2 -0
- package/package.json +1 -1
- package/src/attachments/routes.ts +66 -0
- package/src/identities/routes.ts +11 -2
- package/src/storageService.ts +5 -1
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
## [0.8.1](https://github.com/kapetacom/local-cluster-service/compare/v0.8.0...v0.8.1) (2023-07-22)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* Removed debug ([e002caa](https://github.com/kapetacom/local-cluster-service/commit/e002caa3ae20c5a9a7f521e6e47bf46abfcb9e96))
|
7
|
+
|
8
|
+
# [0.8.0](https://github.com/kapetacom/local-cluster-service/compare/v0.7.6...v0.8.0) (2023-07-22)
|
9
|
+
|
10
|
+
|
11
|
+
### Features
|
12
|
+
|
13
|
+
* Added route for uploading attachments to assets ([#46](https://github.com/kapetacom/local-cluster-service/issues/46)) ([e668f33](https://github.com/kapetacom/local-cluster-service/commit/e668f33072e772077a3186fc753e8c516e15171d))
|
14
|
+
|
1
15
|
## [0.7.6](https://github.com/kapetacom/local-cluster-service/compare/v0.7.5...v0.7.6) (2023-07-17)
|
2
16
|
|
3
17
|
|
package/definitions.d.ts
CHANGED
@@ -1,10 +1,3 @@
|
|
1
|
-
declare module '@kapeta/nodejs-api-client' {
|
2
|
-
export class KapetaAPI {
|
3
|
-
getCurrentIdentity(): Promise<any>;
|
4
|
-
getMemberships(identityId: string): Promise<any>;
|
5
|
-
}
|
6
|
-
}
|
7
|
-
|
8
1
|
declare module 'recursive-watch' {
|
9
2
|
export default function watch(path:string, callback:(filename:string) => void):() => void;
|
10
3
|
}
|
package/dist/cjs/index.js
CHANGED
@@ -19,6 +19,7 @@ const routes_5 = __importDefault(require("./src/identities/routes"));
|
|
19
19
|
const routes_6 = __importDefault(require("./src/filesystem/routes"));
|
20
20
|
const routes_7 = __importDefault(require("./src/assets/routes"));
|
21
21
|
const routes_8 = __importDefault(require("./src/providers/routes"));
|
22
|
+
const routes_9 = __importDefault(require("./src/attachments/routes"));
|
22
23
|
const utils_1 = require("./src/utils/utils");
|
23
24
|
let currentServer = null;
|
24
25
|
function createServer() {
|
@@ -31,6 +32,7 @@ function createServer() {
|
|
31
32
|
app.use('/files', routes_6.default);
|
32
33
|
app.use('/assets', routes_7.default);
|
33
34
|
app.use('/providers', routes_8.default);
|
35
|
+
app.use('/attachments', routes_9.default);
|
34
36
|
app.use('/', (req, res) => {
|
35
37
|
console.error('Invalid request: %s %s', req.method, req.originalUrl);
|
36
38
|
res.status(400).send({
|
@@ -0,0 +1,61 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
const express_promise_router_1 = __importDefault(require("express-promise-router"));
|
7
|
+
const nodejs_api_client_1 = require("@kapeta/nodejs-api-client");
|
8
|
+
const cors_1 = require("../middleware/cors");
|
9
|
+
const storageService_1 = require("../storageService");
|
10
|
+
const router = (0, express_promise_router_1.default)();
|
11
|
+
const api = new nodejs_api_client_1.KapetaAPI();
|
12
|
+
const DEFAULT_REGISTRY_BASE = 'https://registry.kapeta.com';
|
13
|
+
function getBaseUrl() {
|
14
|
+
const endpoint = storageService_1.storageService.get('endpoints', 'registry', DEFAULT_REGISTRY_BASE);
|
15
|
+
return `${endpoint}/v1/registry`;
|
16
|
+
}
|
17
|
+
router.use('/', cors_1.corsHandler);
|
18
|
+
router.put('/:handle/:name', async (req, res) => {
|
19
|
+
const endpoint = getBaseUrl();
|
20
|
+
if (!req.headers['content-type']) {
|
21
|
+
res.status(400).send({
|
22
|
+
status: 400,
|
23
|
+
error: 'Missing content-type header'
|
24
|
+
});
|
25
|
+
return;
|
26
|
+
}
|
27
|
+
if (!req.headers['content-length']) {
|
28
|
+
res.status(400).send({
|
29
|
+
status: 400,
|
30
|
+
error: 'Missing content-length header'
|
31
|
+
});
|
32
|
+
return;
|
33
|
+
}
|
34
|
+
if (!req.headers['content-disposition']) {
|
35
|
+
res.status(400).send({
|
36
|
+
status: 400,
|
37
|
+
error: 'Missing content-disposition header'
|
38
|
+
});
|
39
|
+
return;
|
40
|
+
}
|
41
|
+
try {
|
42
|
+
const { handle, name } = req.params;
|
43
|
+
const url = `${endpoint}/${handle}/${name}/attachments`;
|
44
|
+
const result = await api.send({
|
45
|
+
method: 'PUT',
|
46
|
+
url,
|
47
|
+
auth: true,
|
48
|
+
headers: {
|
49
|
+
'content-type': req.headers['content-type'],
|
50
|
+
'content-length': req.headers['content-length'],
|
51
|
+
'content-disposition': req.headers['content-disposition'],
|
52
|
+
},
|
53
|
+
body: req
|
54
|
+
});
|
55
|
+
res.send(result);
|
56
|
+
}
|
57
|
+
catch (e) {
|
58
|
+
res.status(e.status ?? 500).send(e);
|
59
|
+
}
|
60
|
+
});
|
61
|
+
exports.default = router;
|
@@ -10,9 +10,19 @@ const router = (0, express_promise_router_1.default)();
|
|
10
10
|
const api = new nodejs_api_client_1.KapetaAPI();
|
11
11
|
router.use('/', cors_1.corsHandler);
|
12
12
|
router.get('/current', async (req, res) => {
|
13
|
-
|
13
|
+
try {
|
14
|
+
res.send(await api.getCurrentIdentity());
|
15
|
+
}
|
16
|
+
catch (e) {
|
17
|
+
res.status(e.status ?? 500).send(e);
|
18
|
+
}
|
14
19
|
});
|
15
20
|
router.get('/:identityId/memberships', async (req, res) => {
|
16
|
-
|
21
|
+
try {
|
22
|
+
res.send(await api.getMemberships(req.params.identityId));
|
23
|
+
}
|
24
|
+
catch (e) {
|
25
|
+
res.status(e.status ?? 500).send(e);
|
26
|
+
}
|
17
27
|
});
|
18
28
|
exports.default = router;
|
@@ -9,7 +9,7 @@ declare class StorageService {
|
|
9
9
|
_writeConfig(): void;
|
10
10
|
section<T = any>(section: string, defaultValue?: any): T;
|
11
11
|
put(section: string, property: string | any, value?: any): void;
|
12
|
-
get(section: string, property?: string):
|
12
|
+
get<T = any>(section: string, property?: string, defaultValue?: T): T | undefined;
|
13
13
|
contains(section: string, property: string): any;
|
14
14
|
ensure(section: string, property: string, value: any): any;
|
15
15
|
}
|
@@ -47,10 +47,13 @@ class StorageService {
|
|
47
47
|
this.section(section)[property] = value;
|
48
48
|
this._writeConfig();
|
49
49
|
}
|
50
|
-
get(section, property) {
|
50
|
+
get(section, property, defaultValue) {
|
51
51
|
if (!property) {
|
52
52
|
return this.section(section);
|
53
53
|
}
|
54
|
+
if (!this.contains(section, property)) {
|
55
|
+
return defaultValue;
|
56
|
+
}
|
54
57
|
return this.section(section)[property];
|
55
58
|
}
|
56
59
|
contains(section, property) {
|
package/dist/esm/index.js
CHANGED
@@ -14,6 +14,7 @@ import IdentitiesRoutes from './src/identities/routes';
|
|
14
14
|
import FilesystemRoutes from './src/filesystem/routes';
|
15
15
|
import AssetsRoutes from './src/assets/routes';
|
16
16
|
import ProviderRoutes from './src/providers/routes';
|
17
|
+
import AttachmentRoutes from './src/attachments/routes';
|
17
18
|
import { getBindHost } from './src/utils/utils';
|
18
19
|
let currentServer = null;
|
19
20
|
function createServer() {
|
@@ -26,6 +27,7 @@ function createServer() {
|
|
26
27
|
app.use('/files', FilesystemRoutes);
|
27
28
|
app.use('/assets', AssetsRoutes);
|
28
29
|
app.use('/providers', ProviderRoutes);
|
30
|
+
app.use('/attachments', AttachmentRoutes);
|
29
31
|
app.use('/', (req, res) => {
|
30
32
|
console.error('Invalid request: %s %s', req.method, req.originalUrl);
|
31
33
|
res.status(400).send({
|
@@ -0,0 +1,56 @@
|
|
1
|
+
import Router from 'express-promise-router';
|
2
|
+
import { KapetaAPI } from '@kapeta/nodejs-api-client';
|
3
|
+
import { corsHandler } from '../middleware/cors';
|
4
|
+
import { storageService } from "../storageService";
|
5
|
+
const router = Router();
|
6
|
+
const api = new KapetaAPI();
|
7
|
+
const DEFAULT_REGISTRY_BASE = 'https://registry.kapeta.com';
|
8
|
+
function getBaseUrl() {
|
9
|
+
const endpoint = storageService.get('endpoints', 'registry', DEFAULT_REGISTRY_BASE);
|
10
|
+
return `${endpoint}/v1/registry`;
|
11
|
+
}
|
12
|
+
router.use('/', corsHandler);
|
13
|
+
router.put('/:handle/:name', async (req, res) => {
|
14
|
+
const endpoint = getBaseUrl();
|
15
|
+
if (!req.headers['content-type']) {
|
16
|
+
res.status(400).send({
|
17
|
+
status: 400,
|
18
|
+
error: 'Missing content-type header'
|
19
|
+
});
|
20
|
+
return;
|
21
|
+
}
|
22
|
+
if (!req.headers['content-length']) {
|
23
|
+
res.status(400).send({
|
24
|
+
status: 400,
|
25
|
+
error: 'Missing content-length header'
|
26
|
+
});
|
27
|
+
return;
|
28
|
+
}
|
29
|
+
if (!req.headers['content-disposition']) {
|
30
|
+
res.status(400).send({
|
31
|
+
status: 400,
|
32
|
+
error: 'Missing content-disposition header'
|
33
|
+
});
|
34
|
+
return;
|
35
|
+
}
|
36
|
+
try {
|
37
|
+
const { handle, name } = req.params;
|
38
|
+
const url = `${endpoint}/${handle}/${name}/attachments`;
|
39
|
+
const result = await api.send({
|
40
|
+
method: 'PUT',
|
41
|
+
url,
|
42
|
+
auth: true,
|
43
|
+
headers: {
|
44
|
+
'content-type': req.headers['content-type'],
|
45
|
+
'content-length': req.headers['content-length'],
|
46
|
+
'content-disposition': req.headers['content-disposition'],
|
47
|
+
},
|
48
|
+
body: req
|
49
|
+
});
|
50
|
+
res.send(result);
|
51
|
+
}
|
52
|
+
catch (e) {
|
53
|
+
res.status(e.status ?? 500).send(e);
|
54
|
+
}
|
55
|
+
});
|
56
|
+
export default router;
|
@@ -5,9 +5,19 @@ const router = Router();
|
|
5
5
|
const api = new KapetaAPI();
|
6
6
|
router.use('/', corsHandler);
|
7
7
|
router.get('/current', async (req, res) => {
|
8
|
-
|
8
|
+
try {
|
9
|
+
res.send(await api.getCurrentIdentity());
|
10
|
+
}
|
11
|
+
catch (e) {
|
12
|
+
res.status(e.status ?? 500).send(e);
|
13
|
+
}
|
9
14
|
});
|
10
15
|
router.get('/:identityId/memberships', async (req, res) => {
|
11
|
-
|
16
|
+
try {
|
17
|
+
res.send(await api.getMemberships(req.params.identityId));
|
18
|
+
}
|
19
|
+
catch (e) {
|
20
|
+
res.status(e.status ?? 500).send(e);
|
21
|
+
}
|
12
22
|
});
|
13
23
|
export default router;
|
@@ -9,7 +9,7 @@ declare class StorageService {
|
|
9
9
|
_writeConfig(): void;
|
10
10
|
section<T = any>(section: string, defaultValue?: any): T;
|
11
11
|
put(section: string, property: string | any, value?: any): void;
|
12
|
-
get(section: string, property?: string):
|
12
|
+
get<T = any>(section: string, property?: string, defaultValue?: T): T | undefined;
|
13
13
|
contains(section: string, property: string): any;
|
14
14
|
ensure(section: string, property: string, value: any): any;
|
15
15
|
}
|
@@ -41,10 +41,13 @@ class StorageService {
|
|
41
41
|
this.section(section)[property] = value;
|
42
42
|
this._writeConfig();
|
43
43
|
}
|
44
|
-
get(section, property) {
|
44
|
+
get(section, property, defaultValue) {
|
45
45
|
if (!property) {
|
46
46
|
return this.section(section);
|
47
47
|
}
|
48
|
+
if (!this.contains(section, property)) {
|
49
|
+
return defaultValue;
|
50
|
+
}
|
48
51
|
return this.section(section)[property];
|
49
52
|
}
|
50
53
|
contains(section, property) {
|
package/index.ts
CHANGED
@@ -15,6 +15,7 @@ import IdentitiesRoutes from './src/identities/routes';
|
|
15
15
|
import FilesystemRoutes from './src/filesystem/routes';
|
16
16
|
import AssetsRoutes from './src/assets/routes';
|
17
17
|
import ProviderRoutes from './src/providers/routes';
|
18
|
+
import AttachmentRoutes from './src/attachments/routes';
|
18
19
|
import { getBindHost } from './src/utils/utils';
|
19
20
|
|
20
21
|
export type LocalClusterService = HTTP.Server & { host?: string; port?: number };
|
@@ -33,6 +34,7 @@ function createServer() {
|
|
33
34
|
app.use('/files', FilesystemRoutes);
|
34
35
|
app.use('/assets', AssetsRoutes);
|
35
36
|
app.use('/providers', ProviderRoutes);
|
37
|
+
app.use('/attachments', AttachmentRoutes);
|
36
38
|
app.use('/', (req: express.Request, res: express.Response) => {
|
37
39
|
console.error('Invalid request: %s %s', req.method, req.originalUrl);
|
38
40
|
res.status(400).send({
|
package/package.json
CHANGED
@@ -0,0 +1,66 @@
|
|
1
|
+
import Router from 'express-promise-router';
|
2
|
+
import { KapetaAPI } from '@kapeta/nodejs-api-client';
|
3
|
+
|
4
|
+
import { corsHandler } from '../middleware/cors';
|
5
|
+
import { Request, Response } from 'express';
|
6
|
+
import {storageService} from "../storageService";
|
7
|
+
|
8
|
+
const router = Router();
|
9
|
+
const api = new KapetaAPI();
|
10
|
+
|
11
|
+
const DEFAULT_REGISTRY_BASE = 'https://registry.kapeta.com';
|
12
|
+
|
13
|
+
function getBaseUrl() {
|
14
|
+
const endpoint = storageService.get('endpoints', 'registry', DEFAULT_REGISTRY_BASE);
|
15
|
+
return `${endpoint}/v1/registry`;
|
16
|
+
}
|
17
|
+
|
18
|
+
router.use('/', corsHandler);
|
19
|
+
|
20
|
+
router.put('/:handle/:name', async (req: Request, res: Response) => {
|
21
|
+
const endpoint = getBaseUrl();
|
22
|
+
if (!req.headers['content-type']) {
|
23
|
+
res.status(400).send({
|
24
|
+
status: 400,
|
25
|
+
error: 'Missing content-type header'
|
26
|
+
});
|
27
|
+
return;
|
28
|
+
}
|
29
|
+
|
30
|
+
if (!req.headers['content-length']) {
|
31
|
+
res.status(400).send({
|
32
|
+
status: 400,
|
33
|
+
error: 'Missing content-length header'
|
34
|
+
});
|
35
|
+
return;
|
36
|
+
}
|
37
|
+
|
38
|
+
if (!req.headers['content-disposition']) {
|
39
|
+
res.status(400).send({
|
40
|
+
status: 400,
|
41
|
+
error: 'Missing content-disposition header'
|
42
|
+
});
|
43
|
+
return;
|
44
|
+
}
|
45
|
+
|
46
|
+
try {
|
47
|
+
const {handle, name} = req.params;
|
48
|
+
const url = `${endpoint}/${handle}/${name}/attachments`;
|
49
|
+
const result = await api.send<{url:string}>({
|
50
|
+
method: 'PUT',
|
51
|
+
url,
|
52
|
+
auth: true,
|
53
|
+
headers: {
|
54
|
+
'content-type': req.headers['content-type'],
|
55
|
+
'content-length': req.headers['content-length'],
|
56
|
+
'content-disposition': req.headers['content-disposition'],
|
57
|
+
},
|
58
|
+
body: req
|
59
|
+
});
|
60
|
+
res.send(result);
|
61
|
+
} catch (e:any) {
|
62
|
+
res.status(e.status ?? 500).send(e);
|
63
|
+
}
|
64
|
+
});
|
65
|
+
|
66
|
+
export default router;
|
package/src/identities/routes.ts
CHANGED
@@ -10,11 +10,20 @@ const api = new KapetaAPI();
|
|
10
10
|
router.use('/', corsHandler);
|
11
11
|
|
12
12
|
router.get('/current', async (req: Request, res: Response) => {
|
13
|
-
|
13
|
+
try {
|
14
|
+
res.send(await api.getCurrentIdentity());
|
15
|
+
} catch (e:any) {
|
16
|
+
res.status(e.status ?? 500).send(e);
|
17
|
+
}
|
18
|
+
|
14
19
|
});
|
15
20
|
|
16
21
|
router.get('/:identityId/memberships', async (req: Request, res: Response) => {
|
17
|
-
|
22
|
+
try {
|
23
|
+
res.send(await api.getMemberships(req.params.identityId));
|
24
|
+
} catch (e:any) {
|
25
|
+
res.status(e.status ?? 500).send(e);
|
26
|
+
}
|
18
27
|
});
|
19
28
|
|
20
29
|
export default router;
|
package/src/storageService.ts
CHANGED
@@ -53,11 +53,15 @@ class StorageService {
|
|
53
53
|
this._writeConfig();
|
54
54
|
}
|
55
55
|
|
56
|
-
get(section: string, property?: string):
|
56
|
+
get<T = any>(section: string, property?: string, defaultValue?:T): T|undefined {
|
57
57
|
if (!property) {
|
58
58
|
return this.section(section);
|
59
59
|
}
|
60
60
|
|
61
|
+
if (!this.contains(section, property)) {
|
62
|
+
return defaultValue;
|
63
|
+
}
|
64
|
+
|
61
65
|
return this.section(section)[property];
|
62
66
|
}
|
63
67
|
|