@syncbridge/common 2.1.0 → 2.2.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/constants.d.ts +1 -1
- package/constants.js +1 -1
- package/host-link/host-link.d.ts +2 -0
- package/host-link/host-link.js +2 -0
- package/host-link/host-permissions.d.ts +44 -0
- package/host-link/host-permissions.js +66 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +1 -1
package/constants.d.ts
CHANGED
package/constants.js
CHANGED
package/host-link/host-link.d.ts
CHANGED
|
@@ -41,3 +41,5 @@ export type HostLinkMessage = HostStatusMessage;
|
|
|
41
41
|
export declare const CONSOLE_USER_HEADER = "x-sb-console-user";
|
|
42
42
|
export declare const CONSOLE_USER_NAME_HEADER = "x-sb-console-user-name";
|
|
43
43
|
export declare const CONSOLE_ROLE_HEADER = "x-sb-console-role";
|
|
44
|
+
/** What the user may do inside the host: HostPermission values, comma-separated */
|
|
45
|
+
export declare const CONSOLE_PERMISSIONS_HEADER = "x-sb-console-permissions";
|
package/host-link/host-link.js
CHANGED
|
@@ -51,3 +51,5 @@ export function summarizeWorkers(workers) {
|
|
|
51
51
|
export const CONSOLE_USER_HEADER = 'x-sb-console-user';
|
|
52
52
|
export const CONSOLE_USER_NAME_HEADER = 'x-sb-console-user-name';
|
|
53
53
|
export const CONSOLE_ROLE_HEADER = 'x-sb-console-role';
|
|
54
|
+
/** What the user may do inside the host: HostPermission values, comma-separated */
|
|
55
|
+
export const CONSOLE_PERMISSIONS_HEADER = 'x-sb-console-permissions';
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a user may do inside a host. Console grants them to an
|
|
3
|
+
* organization's members and passes them on with each request
|
|
4
|
+
* (CONSOLE_PERMISSIONS_HEADER); the host's own users have their role's.
|
|
5
|
+
*/
|
|
6
|
+
export declare enum HostPermission {
|
|
7
|
+
/** Seeing the workers, their logs and configuration, and the settings */
|
|
8
|
+
WorkersView = "host.workers.view",
|
|
9
|
+
/** Starting, stopping and initializing workers */
|
|
10
|
+
WorkersControl = "host.workers.control",
|
|
11
|
+
/** Changing a worker's configuration and its log channels */
|
|
12
|
+
WorkersConfigure = "host.workers.configure",
|
|
13
|
+
/** Adding workers */
|
|
14
|
+
WorkersCreate = "host.workers.create",
|
|
15
|
+
/** Removing workers */
|
|
16
|
+
WorkersDelete = "host.workers.delete",
|
|
17
|
+
/** Changing the host's settings, uploading packages */
|
|
18
|
+
Settings = "host.settings",
|
|
19
|
+
/** Updating SyncBridge */
|
|
20
|
+
Updates = "host.updates",
|
|
21
|
+
/** The host's own users */
|
|
22
|
+
Users = "host.users",
|
|
23
|
+
/** Pairing with Console, restoring, restarting SyncBridge */
|
|
24
|
+
System = "host.system",
|
|
25
|
+
/**
|
|
26
|
+
* Installing packages from the registry: Console's own permission, sent
|
|
27
|
+
* with its installs
|
|
28
|
+
*/
|
|
29
|
+
Install = "hosts.install"
|
|
30
|
+
}
|
|
31
|
+
/** The roles inside a host, each a set of permissions */
|
|
32
|
+
export type HostRole = 'viewer' | 'operator' | 'admin';
|
|
33
|
+
/**
|
|
34
|
+
* The permissions of each role: a host's own users', and a user's whose
|
|
35
|
+
* Console sends a role alone (one older than the permissions)
|
|
36
|
+
*/
|
|
37
|
+
export declare const HOST_ROLE_PERMISSIONS: Readonly<Record<HostRole, readonly HostPermission[]>>;
|
|
38
|
+
/** The permissions of a role; none for a role not known */
|
|
39
|
+
export declare function hostRolePermissions(role: string | undefined | null): HostPermission[];
|
|
40
|
+
/**
|
|
41
|
+
* The permissions a CONSOLE_PERMISSIONS_HEADER value gives: comma-separated,
|
|
42
|
+
* those not known dropped. No header, undefined: the role's to be taken.
|
|
43
|
+
*/
|
|
44
|
+
export declare function parseHostPermissions(value: string | undefined | null): HostPermission[] | undefined;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a user may do inside a host. Console grants them to an
|
|
3
|
+
* organization's members and passes them on with each request
|
|
4
|
+
* (CONSOLE_PERMISSIONS_HEADER); the host's own users have their role's.
|
|
5
|
+
*/
|
|
6
|
+
export var HostPermission;
|
|
7
|
+
(function (HostPermission) {
|
|
8
|
+
/** Seeing the workers, their logs and configuration, and the settings */
|
|
9
|
+
HostPermission["WorkersView"] = "host.workers.view";
|
|
10
|
+
/** Starting, stopping and initializing workers */
|
|
11
|
+
HostPermission["WorkersControl"] = "host.workers.control";
|
|
12
|
+
/** Changing a worker's configuration and its log channels */
|
|
13
|
+
HostPermission["WorkersConfigure"] = "host.workers.configure";
|
|
14
|
+
/** Adding workers */
|
|
15
|
+
HostPermission["WorkersCreate"] = "host.workers.create";
|
|
16
|
+
/** Removing workers */
|
|
17
|
+
HostPermission["WorkersDelete"] = "host.workers.delete";
|
|
18
|
+
/** Changing the host's settings, uploading packages */
|
|
19
|
+
HostPermission["Settings"] = "host.settings";
|
|
20
|
+
/** Updating SyncBridge */
|
|
21
|
+
HostPermission["Updates"] = "host.updates";
|
|
22
|
+
/** The host's own users */
|
|
23
|
+
HostPermission["Users"] = "host.users";
|
|
24
|
+
/** Pairing with Console, restoring, restarting SyncBridge */
|
|
25
|
+
HostPermission["System"] = "host.system";
|
|
26
|
+
/**
|
|
27
|
+
* Installing packages from the registry: Console's own permission, sent
|
|
28
|
+
* with its installs
|
|
29
|
+
*/
|
|
30
|
+
HostPermission["Install"] = "hosts.install";
|
|
31
|
+
})(HostPermission || (HostPermission = {}));
|
|
32
|
+
const VIEWER = [HostPermission.WorkersView];
|
|
33
|
+
const OPERATOR = [
|
|
34
|
+
...VIEWER,
|
|
35
|
+
HostPermission.WorkersControl,
|
|
36
|
+
HostPermission.WorkersConfigure,
|
|
37
|
+
HostPermission.WorkersCreate,
|
|
38
|
+
HostPermission.Install,
|
|
39
|
+
];
|
|
40
|
+
/**
|
|
41
|
+
* The permissions of each role: a host's own users', and a user's whose
|
|
42
|
+
* Console sends a role alone (one older than the permissions)
|
|
43
|
+
*/
|
|
44
|
+
export const HOST_ROLE_PERMISSIONS = {
|
|
45
|
+
viewer: VIEWER,
|
|
46
|
+
operator: OPERATOR,
|
|
47
|
+
admin: Object.values(HostPermission),
|
|
48
|
+
};
|
|
49
|
+
const KNOWN = new Set(Object.values(HostPermission));
|
|
50
|
+
/** The permissions of a role; none for a role not known */
|
|
51
|
+
export function hostRolePermissions(role) {
|
|
52
|
+
return [...(HOST_ROLE_PERMISSIONS[role] || [])];
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The permissions a CONSOLE_PERMISSIONS_HEADER value gives: comma-separated,
|
|
56
|
+
* those not known dropped. No header, undefined: the role's to be taken.
|
|
57
|
+
*/
|
|
58
|
+
export function parseHostPermissions(value) {
|
|
59
|
+
if (value == null)
|
|
60
|
+
return;
|
|
61
|
+
const given = value
|
|
62
|
+
.split(',')
|
|
63
|
+
.map(s => s.trim())
|
|
64
|
+
.filter(s => KNOWN.has(s));
|
|
65
|
+
return [...new Set(given)];
|
|
66
|
+
}
|
package/index.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export * from './decorators/log-channel.decorator.js';
|
|
|
16
16
|
export * from './host-link/host-identity.js';
|
|
17
17
|
export * from './host-link/host-link.js';
|
|
18
18
|
export * from './host-link/host-packages.js';
|
|
19
|
+
export * from './host-link/host-permissions.js';
|
|
19
20
|
export * from './host-link/host-workers.js';
|
|
20
21
|
export * from './host-link/multiplexer.js';
|
|
21
22
|
export * from './host-link/sealed-box.js';
|
package/index.js
CHANGED
|
@@ -16,6 +16,7 @@ export * from './decorators/log-channel.decorator.js';
|
|
|
16
16
|
export * from './host-link/host-identity.js';
|
|
17
17
|
export * from './host-link/host-link.js';
|
|
18
18
|
export * from './host-link/host-packages.js';
|
|
19
|
+
export * from './host-link/host-permissions.js';
|
|
19
20
|
export * from './host-link/host-workers.js';
|
|
20
21
|
export * from './host-link/multiplexer.js';
|
|
21
22
|
export * from './host-link/sealed-box.js';
|