@wocker/core 1.1.4-beta.1 → 1.1.5-beta.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/lib/env.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare const WOCKER_VERSION = "1.1.2";
1
+ export declare const WOCKER_VERSION = "1.1.5";
2
2
  export declare const WOCKER_VERSION_KEY = "__WOCKER_VERSION__";
3
3
  export declare const WOCKER_DATA_DIR: string;
4
4
  export declare const WOCKER_DATA_DIR_KEY = "__WOCKER_DATA_DIR__";
package/lib/env.js CHANGED
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.MODULE_METADATA = exports.PLUGIN_NAME_METADATA = exports.INJECT_TOKEN_METADATA = exports.SELF_DECLARED_DEPS_METADATA = exports.PARAMTYPES_METADATA = exports.ALIAS_METADATA = exports.ARGS_OLD_METADATA = exports.ARGS_METADATA = exports.LISTENER_METADATA = exports.COMPLETION_METADATA = exports.COMMAND_METADATA = exports.DESCRIPTION_METADATA = exports.INJECTABLE_WATERMARK = exports.IS_MODULE_METADATA = exports.IS_GLOBAL_METADATA = exports.IS_CONTROLLER_METADATA = exports.PLUGIN_DIR_KEY = exports.FILE_SYSTEM_DRIVER_KEY = exports.WOCKER_DATA_DIR_KEY = exports.WOCKER_DATA_DIR = exports.WOCKER_VERSION_KEY = exports.WOCKER_VERSION = void 0;
7
7
  const os_1 = __importDefault(require("os"));
8
8
  const path_1 = __importDefault(require("path"));
9
- exports.WOCKER_VERSION = "1.1.2";
9
+ exports.WOCKER_VERSION = "1.1.5";
10
10
  exports.WOCKER_VERSION_KEY = "__WOCKER_VERSION__";
11
11
  exports.WOCKER_DATA_DIR = process.env.WS_DIR || path_1.default.join(os_1.default.homedir(), ".workspace");
12
12
  exports.WOCKER_DATA_DIR_KEY = "__WOCKER_DATA_DIR__";
@@ -1,5 +1,5 @@
1
1
  import { FileSystem } from "./FileSystem";
2
- import { EnvConfig, PackageManagerType, PluginRef, PresetRef, ProjectRef, ProjectOldRef } from "../types";
2
+ import { EnvConfig, PackageManagerType, Permissions, PluginRef, PresetRef, ProjectRef, ProjectOldRef } from "../types";
3
3
  export declare abstract class AppConfig {
4
4
  debug?: boolean;
5
5
  pm?: PackageManagerType;
@@ -9,6 +9,7 @@ export declare abstract class AppConfig {
9
9
  projects: ProjectRef[];
10
10
  meta?: EnvConfig;
11
11
  env?: EnvConfig;
12
+ permissions?: Permissions;
12
13
  constructor(data: AppConfig.Data);
13
14
  addPlugin(name: string, env?: PluginRef["env"]): void;
14
15
  removePlugin(name: string): void;
@@ -27,6 +28,12 @@ export declare abstract class AppConfig {
27
28
  getEnv(key: string, byDefault: string): string;
28
29
  setEnv(name: string, value: string): void;
29
30
  unsetEnv(name: string): void;
31
+ isMountAllowed(path: string): boolean;
32
+ addMountAllow(path: string): void;
33
+ removeMountAllow(path: string): void;
34
+ addMountDeny(path: string): void;
35
+ removeMountDeny(path: string): void;
36
+ protected prunePermissions(): void;
30
37
  abstract save(): void;
31
38
  toObject(): AppConfig.Data;
32
39
  toJsString(): string;
@@ -42,5 +49,6 @@ export declare namespace AppConfig {
42
49
  projects?: ProjectOldRef[];
43
50
  meta?: EnvConfig;
44
51
  env?: EnvConfig;
52
+ permissions?: Permissions;
45
53
  };
46
54
  }
@@ -12,6 +12,7 @@ var __rest = (this && this.__rest) || function (s, e) {
12
12
  };
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.AppConfig = void 0;
15
+ const isPathAllowed_1 = require("../utils/isPathAllowed");
15
16
  class AppConfig {
16
17
  constructor(data) {
17
18
  const { plugins = [], presets = [], projects = [] } = data, rest = __rest(data, ["plugins", "presets", "projects"]);
@@ -159,6 +160,74 @@ class AppConfig {
159
160
  delete this.env;
160
161
  }
161
162
  }
163
+ isMountAllowed(path) {
164
+ var _a, _b, _c, _d;
165
+ return (0, isPathAllowed_1.isPathAllowed)(path, (_b = (_a = this.permissions) === null || _a === void 0 ? void 0 : _a.mounts) === null || _b === void 0 ? void 0 : _b.allow, (_d = (_c = this.permissions) === null || _c === void 0 ? void 0 : _c.mounts) === null || _d === void 0 ? void 0 : _d.deny);
166
+ }
167
+ addMountAllow(path) {
168
+ if (!this.permissions) {
169
+ this.permissions = {};
170
+ }
171
+ if (!this.permissions.mounts) {
172
+ this.permissions.mounts = {};
173
+ }
174
+ if (!this.permissions.mounts.allow) {
175
+ this.permissions.mounts.allow = [];
176
+ }
177
+ if (!this.permissions.mounts.allow.includes(path)) {
178
+ this.permissions.mounts.allow.push(path);
179
+ }
180
+ this.removeMountDeny(path);
181
+ }
182
+ removeMountAllow(path) {
183
+ var _a, _b;
184
+ if (!((_b = (_a = this.permissions) === null || _a === void 0 ? void 0 : _a.mounts) === null || _b === void 0 ? void 0 : _b.allow)) {
185
+ return;
186
+ }
187
+ this.permissions.mounts.allow = this.permissions.mounts.allow.filter((entry) => entry !== path);
188
+ this.prunePermissions();
189
+ }
190
+ addMountDeny(path) {
191
+ if (!this.permissions) {
192
+ this.permissions = {};
193
+ }
194
+ if (!this.permissions.mounts) {
195
+ this.permissions.mounts = {};
196
+ }
197
+ if (!this.permissions.mounts.deny) {
198
+ this.permissions.mounts.deny = [];
199
+ }
200
+ if (!this.permissions.mounts.deny.includes(path)) {
201
+ this.permissions.mounts.deny.push(path);
202
+ }
203
+ this.removeMountAllow(path);
204
+ }
205
+ removeMountDeny(path) {
206
+ var _a, _b;
207
+ if (!((_b = (_a = this.permissions) === null || _a === void 0 ? void 0 : _a.mounts) === null || _b === void 0 ? void 0 : _b.deny)) {
208
+ return;
209
+ }
210
+ this.permissions.mounts.deny = this.permissions.mounts.deny.filter((entry) => entry !== path);
211
+ this.prunePermissions();
212
+ }
213
+ prunePermissions() {
214
+ var _a, _b, _c;
215
+ if (!((_a = this.permissions) === null || _a === void 0 ? void 0 : _a.mounts)) {
216
+ return;
217
+ }
218
+ if (((_b = this.permissions.mounts.allow) === null || _b === void 0 ? void 0 : _b.length) === 0) {
219
+ delete this.permissions.mounts.allow;
220
+ }
221
+ if (((_c = this.permissions.mounts.deny) === null || _c === void 0 ? void 0 : _c.length) === 0) {
222
+ delete this.permissions.mounts.deny;
223
+ }
224
+ if (Object.keys(this.permissions.mounts).length === 0) {
225
+ delete this.permissions.mounts;
226
+ }
227
+ if (Object.keys(this.permissions).length === 0) {
228
+ delete this.permissions;
229
+ }
230
+ }
162
231
  toObject() {
163
232
  return {
164
233
  debug: this.debug,
@@ -168,7 +237,8 @@ class AppConfig {
168
237
  presets: this.presets.length > 0 ? this.presets : undefined,
169
238
  projects: this.projects.length > 0 ? this.projects : undefined,
170
239
  env: this.env,
171
- meta: this.meta
240
+ meta: this.meta,
241
+ permissions: this.permissions
172
242
  };
173
243
  }
174
244
  toJsString() {
@@ -0,0 +1,6 @@
1
+ export type Permissions = {
2
+ mounts?: {
3
+ allow?: string[];
4
+ deny?: string[];
5
+ };
6
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -7,6 +7,7 @@ export * from "./LogLevel";
7
7
  export * from "./ModuleMetadata";
8
8
  export * from "./PackageManagerType";
9
9
  export * from "./PickProperties";
10
+ export * from "./Permissions";
10
11
  export * from "./PluginMetadata";
11
12
  export * from "./ProjectConfigScope";
12
13
  export * from "./PluginRef";
@@ -23,6 +23,7 @@ __exportStar(require("./LogLevel"), exports);
23
23
  __exportStar(require("./ModuleMetadata"), exports);
24
24
  __exportStar(require("./PackageManagerType"), exports);
25
25
  __exportStar(require("./PickProperties"), exports);
26
+ __exportStar(require("./Permissions"), exports);
26
27
  __exportStar(require("./PluginMetadata"), exports);
27
28
  __exportStar(require("./ProjectConfigScope"), exports);
28
29
  __exportStar(require("./PluginRef"), exports);
@@ -0,0 +1 @@
1
+ export declare const isPathAllowed: (target: string, allow?: string[], deny?: string[]) => boolean;
@@ -0,0 +1,18 @@
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
+ exports.isPathAllowed = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const isPathAllowed = (target, allow = [], deny = []) => {
9
+ const matches = (list) => list.some((entry) => {
10
+ const normalized = path_1.default.resolve(entry);
11
+ return target === normalized || target.startsWith(normalized + path_1.default.sep);
12
+ });
13
+ if (matches(deny)) {
14
+ return false;
15
+ }
16
+ return matches(allow);
17
+ };
18
+ exports.isPathAllowed = isPathAllowed;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wocker/core",
3
3
  "type": "commonjs",
4
- "version": "1.1.4-beta.1",
4
+ "version": "1.1.5-beta.0",
5
5
  "author": "Kris Papercut <krispcut@gmail.com>",
6
6
  "description": "Core of the Wocker",
7
7
  "license": "MIT",