@syncbridge/common 2.1.0 → 2.3.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 CHANGED
@@ -1,4 +1,4 @@
1
- export declare const version = "2.1.0";
1
+ export declare const version = "2.3.0";
2
2
  export declare const CLASS_METADATA: unique symbol;
3
3
  export declare const CLASS_TYPE: unique symbol;
4
4
  export declare const VARIABLE_CONTAINER: unique symbol;
package/constants.js CHANGED
@@ -1,4 +1,4 @@
1
- export const version = '2.1.0';
1
+ export const version = '2.3.0';
2
2
  export const CLASS_METADATA = Symbol.for('CLASS_METADATA');
3
3
  export const CLASS_TYPE = Symbol.for('CLASS_TYPE');
4
4
  export const VARIABLE_CONTAINER = Symbol.for('VARIABLE_CONTAINER');
@@ -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";
@@ -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';
@@ -23,3 +23,47 @@ export interface HostPackagePlanItem {
23
23
  export interface HostPackagesResolveResponse {
24
24
  items: HostPackagePlanItem[];
25
25
  }
26
+ /** Where, under Console's API, a host's packages' updates are asked */
27
+ export declare const HOST_PACKAGE_UPDATES_PATH = "host/packages/updates";
28
+ /** What a host asks of its packages' updates */
29
+ export interface HostPackageUpdatesRequest {
30
+ /**
31
+ * check: what is newer of the versions it has; download: grants to read
32
+ * the versions it installs
33
+ */
34
+ mode: 'check' | 'download';
35
+ /** "@org/name" -> its newest version installed (check), or the one it installs (download) */
36
+ packages: Record<string, string>;
37
+ }
38
+ /** A version offered: what it needs of the registry's packages */
39
+ export interface HostPackageOffer {
40
+ version: string;
41
+ /** Registry packages it depends on: name -> range */
42
+ dependencies: Record<string, string>;
43
+ }
44
+ /** What is newer of a package, or why it was not told */
45
+ export interface HostPackageUpdate {
46
+ name: string;
47
+ /** The version sent */
48
+ version: string;
49
+ /**
50
+ * NOT_FOUND: not in the registry, or (download) no such version;
51
+ * NO_ACCESS: the host's workspace may not use it; SUSPENDED (download):
52
+ * the version is suspended
53
+ */
54
+ problem?: 'NOT_FOUND' | 'NO_ACCESS' | 'SUSPENDED';
55
+ /** check: the newest of its minor, newer than the one sent (a fix) */
56
+ patch?: HostPackageOffer;
57
+ /** check: the newest of its major, newer than the one sent */
58
+ minor?: HostPackageOffer;
59
+ /** check: a newer major's newest - told, never installed without asking */
60
+ major?: string;
61
+ /** download: the version sent, its grant in its link; a few minutes good */
62
+ download?: HostPackagePlanItem & {
63
+ dependencies: Record<string, string>;
64
+ };
65
+ }
66
+ /** Each package sent, answered */
67
+ export interface HostPackageUpdatesResponse {
68
+ items: HostPackageUpdate[];
69
+ }
@@ -7,3 +7,15 @@
7
7
  */
8
8
  /** Where, under Console's API, a host's packages are planned */
9
9
  export const HOST_PACKAGES_PATH = 'host/packages';
10
+ /*
11
+ * A host's packages' updates: what the registry has newer of each package
12
+ * it has, asked in one call. To check, its installed versions sent - each
13
+ * answered the newest of its minor (a fix), of its major (fixes and
14
+ * features) and a newer major, told apart; nothing signed. To install, the
15
+ * very versions it takes sent - each answered with a short-lived grant to
16
+ * read it: read by it without its access asked again, unless that version,
17
+ * its package or the host's workspace is suspended, or the access ended,
18
+ * since.
19
+ */
20
+ /** Where, under Console's API, a host's packages' updates are asked */
21
+ export const HOST_PACKAGE_UPDATES_PATH = 'host/packages/updates';
@@ -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';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@syncbridge/common",
3
- "version": "2.1.0",
3
+ "version": "2.3.0",
4
4
  "description": "SyncBridge Common utilities",
5
5
  "author": "Panates Inc",
6
6
  "license": "MIT",