@qodalis/cli-files 2.0.0-beta.13 → 2.0.0-beta.15

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qodalis/cli-files",
3
- "version": "2.0.0-beta.13",
3
+ "version": "2.0.0-beta.15",
4
4
  "description": "@qodalis/cli extension for Linux file management commands with in-memory filesystem.",
5
5
  "author": "Nicolae Lupei, Qodalis Solutions",
6
6
  "license": "MIT",
@@ -23,7 +23,7 @@
23
23
  "umd": "./umd/index.global.js",
24
24
  "unpkg": "./umd/index.global.js",
25
25
  "dependencies": {
26
- "@qodalis/cli-core": "2.0.0-beta.13"
26
+ "@qodalis/cli-core": "2.0.0-beta.15"
27
27
  },
28
28
  "sideEffects": false,
29
29
  "main": "./public-api.js",
package/public-api.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _qodalis_cli_core from '@qodalis/cli-core';
2
- import { ICliOwnership, ICliCommandProcessor, CliProcessCommand, ICliExecutionContext, CliHeadersProvider, ICliFileTransferService, ICliFileEntry, ICliCompletionProvider, ICliCompletionContext, ICliConfigurableModule } from '@qodalis/cli-core';
2
+ import { ICliOwnership, CliAccessAction, ICliCommandProcessor, CliProcessCommand, ICliExecutionContext, CliHeadersProvider, ICliFileTransferService, ICliFileEntry, ICliCompletionProvider, ICliCompletionContext, ICliConfigurableModule } from '@qodalis/cli-core';
3
3
  import { Subscription } from 'rxjs';
4
4
 
5
5
  /**
@@ -29,6 +29,17 @@ interface IFileNode {
29
29
  }
30
30
 
31
31
  declare const IFileSystemService_TOKEN = "cli-file-system-service";
32
+ /**
33
+ * Decides whether the current principal may act on a node. Set by the files
34
+ * module from the generic authorization layer (`cliCanAccess`); when no policy
35
+ * is set (no auth module loaded) every operation is allowed.
36
+ */
37
+ interface CliFileAccessPolicy {
38
+ /** rwx check on a file or directory */
39
+ canAccess(node: IFileNode, action: CliAccessAction): boolean;
40
+ /** May the principal chmod/chown this node (owner, or `files:chown` / `files:admin`) */
41
+ canChangeOwnership(node: IFileNode, newOwnership?: ICliOwnership): boolean;
42
+ }
32
43
  /**
33
44
  * Abstraction for virtual filesystem operations.
34
45
  */
@@ -52,6 +63,17 @@ interface IFileSystemService {
52
63
  move(src: string, dest: string): void;
53
64
  chmod(path: string, permissions: string): void;
54
65
  chown(path: string, ownership: ICliOwnership): void;
66
+ setAccessPolicy?(policy?: CliFileAccessPolicy): void;
67
+ /** False when the current principal may not reach `path` (needs `x` on every parent) */
68
+ canTraverse?(path: string): boolean;
69
+ /** Run `fn` without access checks (system tasks such as creating home directories) */
70
+ runAsSystem?<T>(fn: () => T): T;
71
+ /**
72
+ * System task (no access checks): give every node owned by `fromUid`
73
+ * (case-insensitive) to `toUid`, e.g. after a user was renamed or deleted.
74
+ * Returns the number of nodes changed.
75
+ */
76
+ reassignOwner?(fromUid: string, toUid: string): number;
55
77
  initialize(): Promise<void>;
56
78
  persist(): Promise<void>;
57
79
  }
@@ -256,6 +278,8 @@ declare class CliTreeCommandProcessor implements ICliCommandProcessor {
256
278
  type: "number";
257
279
  }[];
258
280
  processCommand(command: CliProcessCommand, context: ICliExecutionContext): Promise<void>;
281
+ /** File system of the running command (listing goes through access checks) */
282
+ private fs?;
259
283
  private printTree;
260
284
  }
261
285
 
@@ -349,6 +373,8 @@ declare class CliFindCommandProcessor implements ICliCommandProcessor {
349
373
  processCommand(command: CliProcessCommand, context: ICliExecutionContext): Promise<void>;
350
374
  private parseSearchPath;
351
375
  private globToRegex;
376
+ /** File system of the running command (listing goes through access checks) */
377
+ private fs?;
352
378
  private walk;
353
379
  }
354
380
 
@@ -635,6 +661,8 @@ declare class CliDuCommandProcessor implements ICliCommandProcessor {
635
661
  })[];
636
662
  processCommand(command: CliProcessCommand, context: ICliExecutionContext): Promise<void>;
637
663
  private parseArgs;
664
+ /** File system of the running command (listing goes through access checks) */
665
+ private fs?;
638
666
  private collectSizes;
639
667
  private formatSize;
640
668
  }
@@ -845,12 +873,33 @@ declare class CliShCommandProcessor implements ICliCommandProcessor {
845
873
  */
846
874
  declare function executeScript(content: string, context: ICliExecutionContext): Promise<void>;
847
875
 
876
+ /** Owner of system directories and of legacy nodes created without an owner */
877
+ declare const SYSTEM_OWNERSHIP: ICliOwnership;
878
+ /** Owner of files created while nobody is signed in */
879
+ declare const ANONYMOUS_OWNERSHIP: ICliOwnership;
848
880
  declare class IndexedDbFileSystemService implements IFileSystemService {
849
881
  private root;
850
882
  private cwd;
851
883
  private homePath;
852
884
  private currentUid;
853
885
  private currentGroups;
886
+ private accessPolicy?;
887
+ private systemDepth;
888
+ setAccessPolicy(policy?: CliFileAccessPolicy): void;
889
+ runAsSystem<T>(fn: () => T): T;
890
+ reassignOwner(fromUid: string, toUid: string): number;
891
+ canTraverse(path: string): boolean;
892
+ private get enforcing();
893
+ private deny;
894
+ /** `x` on every existing directory on the way to `resolved` (excluding the target). */
895
+ private assertTraverse;
896
+ private assertAccess;
897
+ /** Recursive delete: every directory inside must allow removing its entries (`w` + `x`, readable). */
898
+ private assertRemovableTree;
899
+ /** Copying reads everything it copies: `r` on every file, `r` + `x` on every directory. */
900
+ private assertReadableTree;
901
+ /** Creating/removing entries needs `w` and `x` on the containing directory. */
902
+ private assertModifyDir;
854
903
  setCurrentUser(uid: string, groups: string[]): void;
855
904
  private getDefaultOwnership;
856
905
  getCurrentDirectory(): string;
@@ -873,6 +922,8 @@ declare class IndexedDbFileSystemService implements IFileSystemService {
873
922
  chown(path: string, ownership: ICliOwnership): void;
874
923
  initialize(): Promise<void>;
875
924
  persist(): Promise<void>;
925
+ /** A copy belongs to whoever made it (like `cp` without `-p`) */
926
+ private ownedByCurrentUser;
876
927
  private cloneNode;
877
928
  private openDb;
878
929
  private idbGet;
@@ -969,6 +1020,35 @@ declare class VirtualFsFileTransferService implements ICliFileTransferService {
969
1020
  } | null>;
970
1021
  }
971
1022
 
1023
+ /** Permissions the files module understands. */
1024
+ declare const CliFilesPermissions: {
1025
+ /** Bypass all file permission checks */
1026
+ readonly Admin: "files:admin";
1027
+ /** chmod/chown files you do not own */
1028
+ readonly Chown: "files:chown";
1029
+ };
1030
+ /** Mode for newly created home directories (owner full, group read/traverse) */
1031
+ declare const HOME_DIR_PERMISSIONS = "rwxr-x---";
1032
+ /**
1033
+ * Access policy built on the generic authorization layer. Allows everything
1034
+ * when no authorization service is registered (no auth module loaded).
1035
+ */
1036
+ declare function createFileAccessPolicy(context: ICliExecutionContext): CliFileAccessPolicy;
1037
+ /**
1038
+ * Follow the signed-in user (from any auth module that provides
1039
+ * {@link ICliUserSessionService}): ownership for new files, home directory
1040
+ * creation and `~`, and moving to the home directory when the user changes.
1041
+ */
1042
+ declare function followUserSession(context: ICliExecutionContext, fs: IFileSystemService): Subscription | undefined;
1043
+ /**
1044
+ * Keep file ownership (stored by login name) in step with the accounts of
1045
+ * any auth module that emits {@link ICliUserEventService} events: a rename
1046
+ * moves the user's files to the new name, a deletion gives them to `root`, so
1047
+ * a later account with the same name never inherits them. Runs as a system
1048
+ * task (no rwx checks for the acting user). No-op without such a module.
1049
+ */
1050
+ declare function followUserAccounts(context: ICliExecutionContext, fs: IFileSystemService): Subscription | undefined;
1051
+
972
1052
  /**
973
1053
  * Provides tab-completion for file and directory names from the virtual filesystem.
974
1054
  * Priority 50 (checked before command/parameter providers for file-related commands).
@@ -994,7 +1074,11 @@ interface CliFilesModuleConfig {
994
1074
  interface ICliFilesModule extends ICliConfigurableModule<CliFilesModuleConfig> {
995
1075
  /** Subscription for drag-and-drop file uploads, cleaned up in onDestroy */
996
1076
  _dragDropSubscription?: Subscription;
1077
+ /** Subscription following the signed-in user, cleaned up in onDestroy */
1078
+ _sessionSubscription?: Subscription;
1079
+ /** Subscription following account renames/deletions, cleaned up in onDestroy */
1080
+ _accountsSubscription?: Subscription;
997
1081
  }
998
1082
  declare const filesModule: ICliFilesModule;
999
1083
 
1000
- export { CliAwkCommandProcessor, CliBasenameCommandProcessor, CliCatCommandProcessor, CliCdCommandProcessor, CliChmodCommandProcessor, CliChownCommandProcessor, CliCpCommandProcessor, CliCutCommandProcessor, CliDiffCommandProcessor, CliDirnameCommandProcessor, CliDuCommandProcessor, CliEchoCommandProcessor, type CliFilesModuleConfig, CliFindCommandProcessor, CliGrepCommandProcessor, CliHeadCommandProcessor, CliLnCommandProcessor, CliLsCommandProcessor, CliMkdirCommandProcessor, CliMvCommandProcessor, CliPasteCommandProcessor, CliPwdCommandProcessor, CliRmCommandProcessor, CliRmdirCommandProcessor, CliSedCommandProcessor, CliShCommandProcessor, CliSortCommandProcessor, CliStatCommandProcessor, CliTacCommandProcessor, CliTailCommandProcessor, CliTeeCommandProcessor, CliTouchCommandProcessor, CliTrCommandProcessor, CliTreeCommandProcessor, CliUniqCommandProcessor, CliWcCommandProcessor, CliXargsCommandProcessor, FilePathCompletionProvider, type IFileNode, type IFileSystemService, IFileSystemService_TOKEN, IndexedDbFileSystemService, type ServerFileSystemOptions, ServerFileSystemService, VirtualFsFileTransferService, executeScript, filesModule };
1084
+ export { ANONYMOUS_OWNERSHIP, CliAwkCommandProcessor, CliBasenameCommandProcessor, CliCatCommandProcessor, CliCdCommandProcessor, CliChmodCommandProcessor, CliChownCommandProcessor, CliCpCommandProcessor, CliCutCommandProcessor, CliDiffCommandProcessor, CliDirnameCommandProcessor, CliDuCommandProcessor, CliEchoCommandProcessor, type CliFileAccessPolicy, type CliFilesModuleConfig, CliFilesPermissions, CliFindCommandProcessor, CliGrepCommandProcessor, CliHeadCommandProcessor, CliLnCommandProcessor, CliLsCommandProcessor, CliMkdirCommandProcessor, CliMvCommandProcessor, CliPasteCommandProcessor, CliPwdCommandProcessor, CliRmCommandProcessor, CliRmdirCommandProcessor, CliSedCommandProcessor, CliShCommandProcessor, CliSortCommandProcessor, CliStatCommandProcessor, CliTacCommandProcessor, CliTailCommandProcessor, CliTeeCommandProcessor, CliTouchCommandProcessor, CliTrCommandProcessor, CliTreeCommandProcessor, CliUniqCommandProcessor, CliWcCommandProcessor, CliXargsCommandProcessor, FilePathCompletionProvider, HOME_DIR_PERMISSIONS, type IFileNode, type IFileSystemService, IFileSystemService_TOKEN, IndexedDbFileSystemService, SYSTEM_OWNERSHIP, type ServerFileSystemOptions, ServerFileSystemService, VirtualFsFileTransferService, createFileAccessPolicy, executeScript, filesModule, followUserAccounts, followUserSession };
package/public-api.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _qodalis_cli_core from '@qodalis/cli-core';
2
- import { ICliOwnership, ICliCommandProcessor, CliProcessCommand, ICliExecutionContext, CliHeadersProvider, ICliFileTransferService, ICliFileEntry, ICliCompletionProvider, ICliCompletionContext, ICliConfigurableModule } from '@qodalis/cli-core';
2
+ import { ICliOwnership, CliAccessAction, ICliCommandProcessor, CliProcessCommand, ICliExecutionContext, CliHeadersProvider, ICliFileTransferService, ICliFileEntry, ICliCompletionProvider, ICliCompletionContext, ICliConfigurableModule } from '@qodalis/cli-core';
3
3
  import { Subscription } from 'rxjs';
4
4
 
5
5
  /**
@@ -29,6 +29,17 @@ interface IFileNode {
29
29
  }
30
30
 
31
31
  declare const IFileSystemService_TOKEN = "cli-file-system-service";
32
+ /**
33
+ * Decides whether the current principal may act on a node. Set by the files
34
+ * module from the generic authorization layer (`cliCanAccess`); when no policy
35
+ * is set (no auth module loaded) every operation is allowed.
36
+ */
37
+ interface CliFileAccessPolicy {
38
+ /** rwx check on a file or directory */
39
+ canAccess(node: IFileNode, action: CliAccessAction): boolean;
40
+ /** May the principal chmod/chown this node (owner, or `files:chown` / `files:admin`) */
41
+ canChangeOwnership(node: IFileNode, newOwnership?: ICliOwnership): boolean;
42
+ }
32
43
  /**
33
44
  * Abstraction for virtual filesystem operations.
34
45
  */
@@ -52,6 +63,17 @@ interface IFileSystemService {
52
63
  move(src: string, dest: string): void;
53
64
  chmod(path: string, permissions: string): void;
54
65
  chown(path: string, ownership: ICliOwnership): void;
66
+ setAccessPolicy?(policy?: CliFileAccessPolicy): void;
67
+ /** False when the current principal may not reach `path` (needs `x` on every parent) */
68
+ canTraverse?(path: string): boolean;
69
+ /** Run `fn` without access checks (system tasks such as creating home directories) */
70
+ runAsSystem?<T>(fn: () => T): T;
71
+ /**
72
+ * System task (no access checks): give every node owned by `fromUid`
73
+ * (case-insensitive) to `toUid`, e.g. after a user was renamed or deleted.
74
+ * Returns the number of nodes changed.
75
+ */
76
+ reassignOwner?(fromUid: string, toUid: string): number;
55
77
  initialize(): Promise<void>;
56
78
  persist(): Promise<void>;
57
79
  }
@@ -256,6 +278,8 @@ declare class CliTreeCommandProcessor implements ICliCommandProcessor {
256
278
  type: "number";
257
279
  }[];
258
280
  processCommand(command: CliProcessCommand, context: ICliExecutionContext): Promise<void>;
281
+ /** File system of the running command (listing goes through access checks) */
282
+ private fs?;
259
283
  private printTree;
260
284
  }
261
285
 
@@ -349,6 +373,8 @@ declare class CliFindCommandProcessor implements ICliCommandProcessor {
349
373
  processCommand(command: CliProcessCommand, context: ICliExecutionContext): Promise<void>;
350
374
  private parseSearchPath;
351
375
  private globToRegex;
376
+ /** File system of the running command (listing goes through access checks) */
377
+ private fs?;
352
378
  private walk;
353
379
  }
354
380
 
@@ -635,6 +661,8 @@ declare class CliDuCommandProcessor implements ICliCommandProcessor {
635
661
  })[];
636
662
  processCommand(command: CliProcessCommand, context: ICliExecutionContext): Promise<void>;
637
663
  private parseArgs;
664
+ /** File system of the running command (listing goes through access checks) */
665
+ private fs?;
638
666
  private collectSizes;
639
667
  private formatSize;
640
668
  }
@@ -845,12 +873,33 @@ declare class CliShCommandProcessor implements ICliCommandProcessor {
845
873
  */
846
874
  declare function executeScript(content: string, context: ICliExecutionContext): Promise<void>;
847
875
 
876
+ /** Owner of system directories and of legacy nodes created without an owner */
877
+ declare const SYSTEM_OWNERSHIP: ICliOwnership;
878
+ /** Owner of files created while nobody is signed in */
879
+ declare const ANONYMOUS_OWNERSHIP: ICliOwnership;
848
880
  declare class IndexedDbFileSystemService implements IFileSystemService {
849
881
  private root;
850
882
  private cwd;
851
883
  private homePath;
852
884
  private currentUid;
853
885
  private currentGroups;
886
+ private accessPolicy?;
887
+ private systemDepth;
888
+ setAccessPolicy(policy?: CliFileAccessPolicy): void;
889
+ runAsSystem<T>(fn: () => T): T;
890
+ reassignOwner(fromUid: string, toUid: string): number;
891
+ canTraverse(path: string): boolean;
892
+ private get enforcing();
893
+ private deny;
894
+ /** `x` on every existing directory on the way to `resolved` (excluding the target). */
895
+ private assertTraverse;
896
+ private assertAccess;
897
+ /** Recursive delete: every directory inside must allow removing its entries (`w` + `x`, readable). */
898
+ private assertRemovableTree;
899
+ /** Copying reads everything it copies: `r` on every file, `r` + `x` on every directory. */
900
+ private assertReadableTree;
901
+ /** Creating/removing entries needs `w` and `x` on the containing directory. */
902
+ private assertModifyDir;
854
903
  setCurrentUser(uid: string, groups: string[]): void;
855
904
  private getDefaultOwnership;
856
905
  getCurrentDirectory(): string;
@@ -873,6 +922,8 @@ declare class IndexedDbFileSystemService implements IFileSystemService {
873
922
  chown(path: string, ownership: ICliOwnership): void;
874
923
  initialize(): Promise<void>;
875
924
  persist(): Promise<void>;
925
+ /** A copy belongs to whoever made it (like `cp` without `-p`) */
926
+ private ownedByCurrentUser;
876
927
  private cloneNode;
877
928
  private openDb;
878
929
  private idbGet;
@@ -969,6 +1020,35 @@ declare class VirtualFsFileTransferService implements ICliFileTransferService {
969
1020
  } | null>;
970
1021
  }
971
1022
 
1023
+ /** Permissions the files module understands. */
1024
+ declare const CliFilesPermissions: {
1025
+ /** Bypass all file permission checks */
1026
+ readonly Admin: "files:admin";
1027
+ /** chmod/chown files you do not own */
1028
+ readonly Chown: "files:chown";
1029
+ };
1030
+ /** Mode for newly created home directories (owner full, group read/traverse) */
1031
+ declare const HOME_DIR_PERMISSIONS = "rwxr-x---";
1032
+ /**
1033
+ * Access policy built on the generic authorization layer. Allows everything
1034
+ * when no authorization service is registered (no auth module loaded).
1035
+ */
1036
+ declare function createFileAccessPolicy(context: ICliExecutionContext): CliFileAccessPolicy;
1037
+ /**
1038
+ * Follow the signed-in user (from any auth module that provides
1039
+ * {@link ICliUserSessionService}): ownership for new files, home directory
1040
+ * creation and `~`, and moving to the home directory when the user changes.
1041
+ */
1042
+ declare function followUserSession(context: ICliExecutionContext, fs: IFileSystemService): Subscription | undefined;
1043
+ /**
1044
+ * Keep file ownership (stored by login name) in step with the accounts of
1045
+ * any auth module that emits {@link ICliUserEventService} events: a rename
1046
+ * moves the user's files to the new name, a deletion gives them to `root`, so
1047
+ * a later account with the same name never inherits them. Runs as a system
1048
+ * task (no rwx checks for the acting user). No-op without such a module.
1049
+ */
1050
+ declare function followUserAccounts(context: ICliExecutionContext, fs: IFileSystemService): Subscription | undefined;
1051
+
972
1052
  /**
973
1053
  * Provides tab-completion for file and directory names from the virtual filesystem.
974
1054
  * Priority 50 (checked before command/parameter providers for file-related commands).
@@ -994,7 +1074,11 @@ interface CliFilesModuleConfig {
994
1074
  interface ICliFilesModule extends ICliConfigurableModule<CliFilesModuleConfig> {
995
1075
  /** Subscription for drag-and-drop file uploads, cleaned up in onDestroy */
996
1076
  _dragDropSubscription?: Subscription;
1077
+ /** Subscription following the signed-in user, cleaned up in onDestroy */
1078
+ _sessionSubscription?: Subscription;
1079
+ /** Subscription following account renames/deletions, cleaned up in onDestroy */
1080
+ _accountsSubscription?: Subscription;
997
1081
  }
998
1082
  declare const filesModule: ICliFilesModule;
999
1083
 
1000
- export { CliAwkCommandProcessor, CliBasenameCommandProcessor, CliCatCommandProcessor, CliCdCommandProcessor, CliChmodCommandProcessor, CliChownCommandProcessor, CliCpCommandProcessor, CliCutCommandProcessor, CliDiffCommandProcessor, CliDirnameCommandProcessor, CliDuCommandProcessor, CliEchoCommandProcessor, type CliFilesModuleConfig, CliFindCommandProcessor, CliGrepCommandProcessor, CliHeadCommandProcessor, CliLnCommandProcessor, CliLsCommandProcessor, CliMkdirCommandProcessor, CliMvCommandProcessor, CliPasteCommandProcessor, CliPwdCommandProcessor, CliRmCommandProcessor, CliRmdirCommandProcessor, CliSedCommandProcessor, CliShCommandProcessor, CliSortCommandProcessor, CliStatCommandProcessor, CliTacCommandProcessor, CliTailCommandProcessor, CliTeeCommandProcessor, CliTouchCommandProcessor, CliTrCommandProcessor, CliTreeCommandProcessor, CliUniqCommandProcessor, CliWcCommandProcessor, CliXargsCommandProcessor, FilePathCompletionProvider, type IFileNode, type IFileSystemService, IFileSystemService_TOKEN, IndexedDbFileSystemService, type ServerFileSystemOptions, ServerFileSystemService, VirtualFsFileTransferService, executeScript, filesModule };
1084
+ export { ANONYMOUS_OWNERSHIP, CliAwkCommandProcessor, CliBasenameCommandProcessor, CliCatCommandProcessor, CliCdCommandProcessor, CliChmodCommandProcessor, CliChownCommandProcessor, CliCpCommandProcessor, CliCutCommandProcessor, CliDiffCommandProcessor, CliDirnameCommandProcessor, CliDuCommandProcessor, CliEchoCommandProcessor, type CliFileAccessPolicy, type CliFilesModuleConfig, CliFilesPermissions, CliFindCommandProcessor, CliGrepCommandProcessor, CliHeadCommandProcessor, CliLnCommandProcessor, CliLsCommandProcessor, CliMkdirCommandProcessor, CliMvCommandProcessor, CliPasteCommandProcessor, CliPwdCommandProcessor, CliRmCommandProcessor, CliRmdirCommandProcessor, CliSedCommandProcessor, CliShCommandProcessor, CliSortCommandProcessor, CliStatCommandProcessor, CliTacCommandProcessor, CliTailCommandProcessor, CliTeeCommandProcessor, CliTouchCommandProcessor, CliTrCommandProcessor, CliTreeCommandProcessor, CliUniqCommandProcessor, CliWcCommandProcessor, CliXargsCommandProcessor, FilePathCompletionProvider, HOME_DIR_PERMISSIONS, type IFileNode, type IFileSystemService, IFileSystemService_TOKEN, IndexedDbFileSystemService, SYSTEM_OWNERSHIP, type ServerFileSystemOptions, ServerFileSystemService, VirtualFsFileTransferService, createFileAccessPolicy, executeScript, filesModule, followUserAccounts, followUserSession };