@endo/compartment-mapper 1.0.0 → 1.1.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/package.json +10 -10
- package/src/bundle-cjs.d.ts.map +1 -1
- package/src/bundle-cjs.js +9 -1
- package/src/bundle.d.ts.map +1 -1
- package/src/bundle.js +10 -1
- package/src/import.d.ts +1 -1
- package/src/import.d.ts.map +1 -1
- package/src/import.js +1 -1
- package/src/link.d.ts +1 -1
- package/src/link.d.ts.map +1 -1
- package/src/node-modules.d.ts.map +1 -1
- package/src/node-modules.js +21 -14
- package/src/policy-format.d.ts +6 -8
- package/src/policy-format.d.ts.map +1 -1
- package/src/policy-format.js +54 -28
- package/src/policy.d.ts +20 -15
- package/src/policy.d.ts.map +1 -1
- package/src/policy.js +83 -48
- package/src/types.d.ts +87 -8
- package/src/types.d.ts.map +1 -1
- package/src/types.js +82 -7
- package/types.d.ts +3 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@endo/compartment-mapper",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "The compartment mapper assembles Node applications in a sandbox",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"node",
|
|
@@ -38,18 +38,18 @@
|
|
|
38
38
|
"build:types": "tsc --build tsconfig.build.json",
|
|
39
39
|
"clean:types": "git clean -f '*.d.ts*'",
|
|
40
40
|
"cover": "c8 ava",
|
|
41
|
-
"lint": "yarn lint:types && yarn lint:
|
|
41
|
+
"lint": "yarn lint:types && yarn lint:eslint",
|
|
42
42
|
"lint-fix": "eslint --fix .",
|
|
43
|
-
"lint:
|
|
43
|
+
"lint:eslint": "eslint .",
|
|
44
44
|
"lint:types": "tsc",
|
|
45
45
|
"prettier-fixtures": "prettier --write --with-node-modules './test/fixtures-*/**/*.*js'",
|
|
46
46
|
"test": "ava"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@endo/cjs-module-analyzer": "^1.0.
|
|
50
|
-
"@endo/static-module-record": "^1.0.
|
|
51
|
-
"@endo/zip": "^1.0.
|
|
52
|
-
"ses": "^1.
|
|
49
|
+
"@endo/cjs-module-analyzer": "^1.0.1",
|
|
50
|
+
"@endo/static-module-record": "^1.0.2",
|
|
51
|
+
"@endo/zip": "^1.0.1",
|
|
52
|
+
"ses": "^1.1.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"ava": "^5.3.0",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"eslint-plugin-eslint-comments": "^3.1.2",
|
|
62
62
|
"eslint-plugin-import": "^2.29.0",
|
|
63
63
|
"prettier": "^3.0.0",
|
|
64
|
-
"typescript": "~5.
|
|
64
|
+
"typescript": "~5.3.3"
|
|
65
65
|
},
|
|
66
66
|
"files": [
|
|
67
67
|
"LICENSE*",
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
"timeout": "2m"
|
|
98
98
|
},
|
|
99
99
|
"typeCoverage": {
|
|
100
|
-
"atLeast":
|
|
100
|
+
"atLeast": 86.14
|
|
101
101
|
},
|
|
102
|
-
"gitHead": "
|
|
102
|
+
"gitHead": "373f9eebab66c94ed42350473c90fb25e6054f0a"
|
|
103
103
|
}
|
package/src/bundle-cjs.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundle-cjs.d.ts","sourceRoot":"","sources":["bundle-cjs.js"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"bundle-cjs.d.ts","sourceRoot":"","sources":["bundle-cjs.js"],"names":[],"mappings":";;IAuDE;;;;;;;;;;;;MAsBC;;;AA7DH,8BAmCa"}
|
package/src/bundle-cjs.js
CHANGED
|
@@ -34,7 +34,15 @@ const runtime = function wrapCjsFunctor(num) {
|
|
|
34
34
|
.filter(k => moduleCells[k] === undefined)
|
|
35
35
|
.map(k => (moduleCells[k] = cell(k, cModule.exports[k])));
|
|
36
36
|
// Update the star cell from all cells.
|
|
37
|
-
const starExports = Object.create(null
|
|
37
|
+
const starExports = Object.create(null, {
|
|
38
|
+
// Make this appear like an ESM module namespace object.
|
|
39
|
+
[Symbol.toStringTag]: {
|
|
40
|
+
value: 'Module',
|
|
41
|
+
writable: false,
|
|
42
|
+
enumerable: false,
|
|
43
|
+
configurable: false,
|
|
44
|
+
},
|
|
45
|
+
});
|
|
38
46
|
Object.keys(moduleCells)
|
|
39
47
|
.filter(k => k !== '*')
|
|
40
48
|
.map(k => Object.defineProperty(starExports, k, moduleCells[k]));
|
package/src/bundle.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["bundle.js"],"names":[],"mappings":"AA4KO,iCAXI,MAAM,kBACN,MAAM;;;;yBAKN,MAAM;;;gBAGJ,QAAQ,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["bundle.js"],"names":[],"mappings":"AA4KO,iCAXI,MAAM,kBACN,MAAM;;;;yBAKN,MAAM;;;gBAGJ,QAAQ,MAAM,CAAC,CA8J3B;AASM,mCANI,OAAO,QACP,MAAM,kBACN,MAAM,kBACN,MAAM,4EAahB;0BAxVa,OAAO,KAAK,EAAE,WAAW;+CACzB,OAAO,KAAK,EAAE,gCAAgC;mCAC9C,OAAO,YAAY,EAAE,oBAAoB;oCACzC,OAAO,YAAY,EAAE,qBAAqB;iCAC1C,OAAO,YAAY,EAAE,kBAAkB;qBACvC,OAAO,YAAY,EAAE,MAAM;+BAC3B,OAAO,YAAY,EAAE,gBAAgB;sBACrC,OAAO,YAAY,EAAE,OAAO;sBAC5B,OAAO,YAAY,EAAE,OAAO;6BAC5B,OAAO,YAAY,EAAE,cAAc"}
|
package/src/bundle.js
CHANGED
|
@@ -302,7 +302,16 @@ ${''.concat(...modules.map(m => m.bundlerKit.getCells()))}\
|
|
|
302
302
|
|
|
303
303
|
${''.concat(...modules.map(m => m.bundlerKit.getReexportsWiring()))}\
|
|
304
304
|
|
|
305
|
-
|
|
305
|
+
const namespaces = cells.map(cells => Object.freeze(Object.create(null, {
|
|
306
|
+
...cells,
|
|
307
|
+
// Make this appear like an ESM module namespace object.
|
|
308
|
+
[Symbol.toStringTag]: {
|
|
309
|
+
value: 'Module',
|
|
310
|
+
writable: false,
|
|
311
|
+
enumerable: false,
|
|
312
|
+
configurable: false,
|
|
313
|
+
},
|
|
314
|
+
})));
|
|
306
315
|
|
|
307
316
|
for (let index = 0; index < namespaces.length; index += 1) {
|
|
308
317
|
cells[index]['*'] = cell('*', namespaces[index]);
|
package/src/import.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** @type {Record<string, ParserImplementation>} */
|
|
2
2
|
export const parserForLanguage: Record<string, ParserImplementation>;
|
|
3
3
|
export function loadLocation(readPowers: ReadFn | ReadPowers, moduleLocation: string, options?: import("./types.js").ArchiveOptions | undefined): Promise<Application>;
|
|
4
|
-
export function importLocation(readPowers: ReadFn | ReadPowers, moduleLocation: string, options?: (import("./types.js").ExecuteOptions & import("./types.js").ArchiveOptions) | undefined): Promise<
|
|
4
|
+
export function importLocation(readPowers: ReadFn | ReadPowers, moduleLocation: string, options?: (import("./types.js").ExecuteOptions & import("./types.js").ArchiveOptions) | undefined): Promise<import('./types.js').SomeObject>;
|
|
5
5
|
export type Application = import('./types.js').Application;
|
|
6
6
|
export type ArchiveOptions = import('./types.js').ArchiveOptions;
|
|
7
7
|
export type ExecuteFn = import('./types.js').ExecuteFn;
|
package/src/import.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"import.d.ts","sourceRoot":"","sources":["import.js"],"names":[],"mappings":"AA0BA,mDAAmD;AACnD,gCADW,OAAO,MAAM,EAAE,oBAAoB,CAAC,CAO7C;AAQK,yCALI,MAAM,GAAG,UAAU,kBACnB,MAAM,8DAEJ,QAAQ,WAAW,CAAC,CAwEhC;AASM,2CANI,MAAM,GAAG,UAAU,kBACnB,MAAM,sGAEJ,QAAQ,
|
|
1
|
+
{"version":3,"file":"import.d.ts","sourceRoot":"","sources":["import.js"],"names":[],"mappings":"AA0BA,mDAAmD;AACnD,gCADW,OAAO,MAAM,EAAE,oBAAoB,CAAC,CAO7C;AAQK,yCALI,MAAM,GAAG,UAAU,kBACnB,MAAM,8DAEJ,QAAQ,WAAW,CAAC,CAwEhC;AASM,2CANI,MAAM,GAAG,UAAU,kBACnB,MAAM,sGAEJ,QAAQ,OAAO,YAAY,EAAE,UAAU,CAAC,CAUpD;0BA5Ha,OAAO,YAAY,EAAE,WAAW;6BAChC,OAAO,YAAY,EAAE,cAAc;wBACnC,OAAO,YAAY,EAAE,SAAS;6BAC9B,OAAO,YAAY,EAAE,cAAc;mCACnC,OAAO,YAAY,EAAE,oBAAoB;qBACzC,OAAO,YAAY,EAAE,MAAM;yBAC3B,OAAO,YAAY,EAAE,UAAU"}
|
package/src/import.js
CHANGED
|
@@ -115,7 +115,7 @@ export const loadLocation = async (readPowers, moduleLocation, options) => {
|
|
|
115
115
|
* @param {ReadFn | ReadPowers} readPowers
|
|
116
116
|
* @param {string} moduleLocation
|
|
117
117
|
* @param {ExecuteOptions & ArchiveOptions} [options]
|
|
118
|
-
* @returns {Promise<
|
|
118
|
+
* @returns {Promise<import('./types.js').SomeObject>} the object of the imported modules exported
|
|
119
119
|
* names.
|
|
120
120
|
*/
|
|
121
121
|
export const importLocation = async (
|
package/src/link.d.ts
CHANGED
|
@@ -18,5 +18,5 @@ export type CompartmentDescriptor = import('./types.js').CompartmentDescriptor;
|
|
|
18
18
|
export type CompartmentMapDescriptor = import('./types.js').CompartmentMapDescriptor;
|
|
19
19
|
export type DeferredAttenuatorsProvider = import('./types.js').DeferredAttenuatorsProvider;
|
|
20
20
|
export type LinkOptions = import('./types.js').LinkOptions;
|
|
21
|
-
export type ERef<T_1> =
|
|
21
|
+
export type ERef<T_1> = import('@endo/eventual-send').ERef<T>;
|
|
22
22
|
//# sourceMappingURL=link.d.ts.map
|
package/src/link.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link.d.ts","sourceRoot":"","sources":["link.js"],"names":[],"mappings":"AA+IO,iDAPI,OAAO,MAAM,EAAE,QAAQ,CAAC,8BACxB,OAAO,MAAM,EAAE,MAAM,CAAC,qBAEtB,OAAO,MAAM,EAAE,oBAAoB,CAAC,qBACpC,gBAAgB,GACd,OAAO,CA0BnB;AAmKM,sEAHI,wBAAwB,wIACxB,WAAW;;;;;EA0IrB;AAMM,yCAHI,wBAAwB,WACxB,WAAW,eAGqB;4BAvd7B,OAAO,KAAK,EAAE,aAAa;0BAC3B,OAAO,KAAK,EAAE,WAAW;sBACzB,OAAO,YAAY,EAAE,OAAO;mCAC5B,OAAO,YAAY,EAAE,oBAAoB;+BACzC,OAAO,YAAY,EAAE,gBAAgB;+BACrC,OAAO,YAAY,EAAE,gBAAgB;uBACrC,OAAO,YAAY,EAAE,QAAQ;+BAC7B,OAAO,YAAY,EAAE,gBAAgB;oCACrC,OAAO,YAAY,EAAE,qBAAqB;uCAC1C,OAAO,YAAY,EAAE,wBAAwB;0CAC7C,OAAO,YAAY,EAAE,2BAA2B;0BAChD,OAAO,YAAY,EAAE,WAAW"}
|
|
1
|
+
{"version":3,"file":"link.d.ts","sourceRoot":"","sources":["link.js"],"names":[],"mappings":"AA+IO,iDAPI,OAAO,MAAM,EAAE,QAAQ,CAAC,8BACxB,OAAO,MAAM,EAAE,MAAM,CAAC,qBAEtB,OAAO,MAAM,EAAE,oBAAoB,CAAC,qBACpC,gBAAgB,GACd,OAAO,CA0BnB;AAmKM,sEAHI,wBAAwB,wIACxB,WAAW;;;;;EA0IrB;AAMM,yCAHI,wBAAwB,WACxB,WAAW,eAGqB;4BAvd7B,OAAO,KAAK,EAAE,aAAa;0BAC3B,OAAO,KAAK,EAAE,WAAW;sBACzB,OAAO,YAAY,EAAE,OAAO;mCAC5B,OAAO,YAAY,EAAE,oBAAoB;+BACzC,OAAO,YAAY,EAAE,gBAAgB;+BACrC,OAAO,YAAY,EAAE,gBAAgB;uBACrC,OAAO,YAAY,EAAE,QAAQ;+BAC7B,OAAO,YAAY,EAAE,gBAAgB;oCACrC,OAAO,YAAY,EAAE,qBAAqB;uCAC1C,OAAO,YAAY,EAAE,wBAAwB;0CAC7C,OAAO,YAAY,EAAE,2BAA2B;0BAChD,OAAO,YAAY,EAAE,WAAW;wBACpB,OAAO,qBAAqB,EAAE,IAAI,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-modules.d.ts","sourceRoot":"","sources":["node-modules.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"node-modules.d.ts","sourceRoot":"","sources":["node-modules.js"],"names":[],"mappings":"AAwsBO,yDAXI,MAAM,GAAG,UAAU,GAAG,eAAe,mBACrC,MAAM,QACN,IAAI,MAAM,CAAC,qBACX,MAAM,mBACN,MAAM;;yBAGN,MAAM;aACN,MAAM;gBACJ,QAAQ,wBAAwB,CAAC,CA+C7C;uBAlvBa,OAAO,YAAY,EAAE,QAAQ;qBAC7B,OAAO,YAAY,EAAE,MAAM;0BAC3B,OAAO,YAAY,EAAE,WAAW;0BAChC,OAAO,YAAY,EAAE,WAAW;uCAChC,OAAO,YAAY,EAAE,wBAAwB;+BAC7C,OAAO,YAAY,EAAE,gBAAgB;8BACrC,OAAO,YAAY,EAAE,eAAe;oCACpC,OAAO,YAAY,EAAE,qBAAqB;yBAC1C,OAAO,YAAY,EAAE,UAAU;8BAC/B,OAAO,YAAY,EAAE,eAAe;;;;;;;oBAQrC,OAAO,MAAM,EAAE,IAAI,CAAC;;WAKnB,MAAM;UACN,MAAM;UACN,MAAM,MAAM,CAAC;iBACb,MAAM,MAAM,CAAC;qBACb,OAAO;qBACP,OAAO,MAAM,EAAE,MAAM,CAAC;qBACtB,OAAO,MAAM,EAAE,MAAM,CAAC;;;;;yBACtB,OAAO,MAAM,EAAE,MAAM,CAAC;;;;;aAEtB,OAAO,MAAM,EAAE,QAAQ,CAAC;;;;;WAExB,OAAO,MAAM,EAAE,QAAQ,CAAC;;0CAKzB,OAAO,MAAM,EAAE;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAC,CAAC;iDA+E/C,MAAM,KACJ,QAAQ,MAAM,CAAC"}
|
package/src/node-modules.js
CHANGED
|
@@ -42,18 +42,18 @@
|
|
|
42
42
|
* @typedef {Record<string, {spec: string, alias: string}>} CommonDependencyDescriptors
|
|
43
43
|
*/
|
|
44
44
|
|
|
45
|
+
import { pathCompare } from './compartment-map.js';
|
|
45
46
|
import { inferExportsAndAliases } from './infer-exports.js';
|
|
46
|
-
import { searchDescriptor } from './search.js';
|
|
47
47
|
import { parseLocatedJson } from './json.js';
|
|
48
|
-
import {
|
|
48
|
+
import { join } from './node-module-specifier.js';
|
|
49
|
+
import { assertPolicy } from './policy-format.js';
|
|
49
50
|
import {
|
|
50
|
-
getPolicyForPackage,
|
|
51
51
|
ATTENUATORS_COMPARTMENT,
|
|
52
52
|
dependencyAllowedByPolicy,
|
|
53
|
+
getPolicyForPackage,
|
|
53
54
|
} from './policy.js';
|
|
54
|
-
import {
|
|
55
|
-
import {
|
|
56
|
-
import { assertPolicy } from './policy-format.js';
|
|
55
|
+
import { unpackReadPowers } from './powers.js';
|
|
56
|
+
import { searchDescriptor } from './search.js';
|
|
57
57
|
|
|
58
58
|
const { assign, create, keys, values } = Object;
|
|
59
59
|
|
|
@@ -566,7 +566,7 @@ const graphPackages = async (
|
|
|
566
566
|
* @param {Graph} graph
|
|
567
567
|
* @param {Set<string>} tags - build tags about the target environment
|
|
568
568
|
* for selecting relevant exports, e.g., "browser" or "node".
|
|
569
|
-
* @param {
|
|
569
|
+
* @param {import('./types.js').Policy} [policy]
|
|
570
570
|
* @returns {CompartmentMapDescriptor}
|
|
571
571
|
*/
|
|
572
572
|
const translateGraph = (
|
|
@@ -612,6 +612,12 @@ const translateGraph = (
|
|
|
612
612
|
policy,
|
|
613
613
|
);
|
|
614
614
|
|
|
615
|
+
/* c8 ignore next */
|
|
616
|
+
if (policy && !packagePolicy) {
|
|
617
|
+
// this should never happen
|
|
618
|
+
throw new TypeError('Unexpectedly falsy package policy');
|
|
619
|
+
}
|
|
620
|
+
|
|
615
621
|
/**
|
|
616
622
|
* @param {string} dependencyName
|
|
617
623
|
* @param {string} packageLocation
|
|
@@ -626,13 +632,14 @@ const translateGraph = (
|
|
|
626
632
|
const localPath = join(dependencyName, exportPath);
|
|
627
633
|
if (
|
|
628
634
|
!policy ||
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
635
|
+
(packagePolicy &&
|
|
636
|
+
dependencyAllowedByPolicy(
|
|
637
|
+
{
|
|
638
|
+
name,
|
|
639
|
+
path,
|
|
640
|
+
},
|
|
641
|
+
packagePolicy,
|
|
642
|
+
))
|
|
636
643
|
) {
|
|
637
644
|
moduleDescriptors[localPath] = {
|
|
638
645
|
compartment: packageLocation,
|
package/src/policy-format.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
export function policyLookupHelper(packagePolicy:
|
|
2
|
-
export function isAllowingEverything(policyValue:
|
|
3
|
-
export function isAttenuationDefinition(
|
|
4
|
-
export function getAttenuatorFromDefinition(attenuationDefinition: AttenuationDefinition): UnifiedAttenuationDefinition;
|
|
5
|
-
export function assertPackagePolicy(allegedPackagePolicy: unknown, path: string, url?: string | undefined): void;
|
|
6
|
-
export function assertPolicy(allegedPolicy: unknown): void;
|
|
7
|
-
export type AttenuationDefinition = import('./types.js').AttenuationDefinition;
|
|
8
|
-
export type UnifiedAttenuationDefinition = import('./types.js').UnifiedAttenuationDefinition;
|
|
1
|
+
export function policyLookupHelper(packagePolicy: import('./types.js').PackagePolicy, field: 'builtins' | 'globals' | 'packages', itemName: string): boolean | import('./types.js').AttenuationDefinition;
|
|
2
|
+
export function isAllowingEverything(policyValue: unknown): policyValue is "any";
|
|
3
|
+
export function isAttenuationDefinition(allegedDefinition: unknown): allegedDefinition is import("./types.js").AttenuationDefinition;
|
|
4
|
+
export function getAttenuatorFromDefinition(attenuationDefinition: import('./types.js').AttenuationDefinition): import('./types.js').UnifiedAttenuationDefinition;
|
|
5
|
+
export function assertPackagePolicy(allegedPackagePolicy: unknown, path: string, url?: string | undefined): asserts allegedPackagePolicy is import("./types.js").PackagePolicy<void, void, void> | undefined;
|
|
6
|
+
export function assertPolicy(allegedPolicy: unknown): asserts allegedPolicy is import("./types.js").Policy<void, void, void> | undefined;
|
|
9
7
|
//# sourceMappingURL=policy-format.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"policy-format.d.ts","sourceRoot":"","sources":["policy-format.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"policy-format.d.ts","sourceRoot":"","sources":["policy-format.js"],"names":[],"mappings":"AAsBO,kDALI,OAAO,YAAY,EAAE,aAAa,SAClC,UAAU,GAAC,SAAS,GAAC,UAAU,YAC/B,MAAM,GACJ,OAAO,GAAG,OAAO,YAAY,EAAE,qBAAqB,CAyBhE;AAQM,kDAHI,OAAO,wBAIqB;AAOhC,2DAHI,OAAO,mEAUjB;AAOM,mEAHI,OAAO,YAAY,EAAE,qBAAqB,GACxC,OAAO,YAAY,EAAE,4BAA4B,CAuB7D;AA0CM,0DALI,OAAO,QACP,MAAM,8HA4DhB;AAUM,4CAHI,OAAO,sFAiCjB"}
|
package/src/policy-format.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
-
/** @typedef {import('./types.js').AttenuationDefinition} AttenuationDefinition */
|
|
4
|
-
/** @typedef {import('./types.js').UnifiedAttenuationDefinition} UnifiedAttenuationDefinition */
|
|
5
|
-
|
|
6
3
|
const { entries, keys } = Object;
|
|
7
4
|
const { isArray } = Array;
|
|
8
5
|
const q = JSON.stringify;
|
|
@@ -10,14 +7,18 @@ const q = JSON.stringify;
|
|
|
10
7
|
const ATTENUATOR_KEY = 'attenuate';
|
|
11
8
|
const ATTENUATOR_PARAMS_KEY = 'params';
|
|
12
9
|
const WILDCARD_POLICY_VALUE = 'any';
|
|
13
|
-
const POLICY_FIELDS_LOOKUP =
|
|
10
|
+
const POLICY_FIELDS_LOOKUP = /** @type {const} */ ([
|
|
11
|
+
'builtins',
|
|
12
|
+
'globals',
|
|
13
|
+
'packages',
|
|
14
|
+
]);
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
*
|
|
17
|
-
* @param {
|
|
18
|
-
* @param {
|
|
18
|
+
* @param {import('./types.js').PackagePolicy} packagePolicy
|
|
19
|
+
* @param {'builtins'|'globals'|'packages'} field
|
|
19
20
|
* @param {string} itemName
|
|
20
|
-
* @returns {boolean |
|
|
21
|
+
* @returns {boolean | import('./types.js').AttenuationDefinition}
|
|
21
22
|
*/
|
|
22
23
|
export const policyLookupHelper = (packagePolicy, field, itemName) => {
|
|
23
24
|
if (!POLICY_FIELDS_LOOKUP.includes(field)) {
|
|
@@ -34,38 +35,43 @@ export const policyLookupHelper = (packagePolicy, field, itemName) => {
|
|
|
34
35
|
if (packagePolicy[field] === WILDCARD_POLICY_VALUE) {
|
|
35
36
|
return true;
|
|
36
37
|
}
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
|
|
39
|
+
const value = /** @type {import('./types.js').AttenuationDefinition} */ (
|
|
40
|
+
packagePolicy[field]
|
|
41
|
+
);
|
|
42
|
+
if (itemName in value) {
|
|
43
|
+
return value[itemName];
|
|
39
44
|
}
|
|
40
45
|
return false;
|
|
41
46
|
};
|
|
42
47
|
|
|
43
48
|
/**
|
|
44
|
-
*
|
|
49
|
+
* Type guard; checks if the policy value is set to the wildcard value to allow everything
|
|
45
50
|
*
|
|
46
|
-
* @param {
|
|
47
|
-
* @returns {
|
|
51
|
+
* @param {unknown} policyValue
|
|
52
|
+
* @returns {policyValue is import('./types.js').WildcardPolicy}
|
|
48
53
|
*/
|
|
49
54
|
export const isAllowingEverything = policyValue =>
|
|
50
55
|
policyValue === WILDCARD_POLICY_VALUE;
|
|
51
56
|
|
|
52
57
|
/**
|
|
53
|
-
*
|
|
54
|
-
* @param {
|
|
55
|
-
* @returns {
|
|
58
|
+
* Type guard for `AttenuationDefinition`
|
|
59
|
+
* @param {unknown} allegedDefinition
|
|
60
|
+
* @returns {allegedDefinition is import('./types.js').AttenuationDefinition}
|
|
56
61
|
*/
|
|
57
|
-
export const isAttenuationDefinition =
|
|
58
|
-
return (
|
|
59
|
-
(
|
|
60
|
-
typeof
|
|
61
|
-
|
|
62
|
+
export const isAttenuationDefinition = allegedDefinition => {
|
|
63
|
+
return Boolean(
|
|
64
|
+
(allegedDefinition &&
|
|
65
|
+
typeof allegedDefinition === 'object' &&
|
|
66
|
+
typeof allegedDefinition[ATTENUATOR_KEY] === 'string') || // object with attenuator name
|
|
67
|
+
isArray(allegedDefinition), // params for default attenuator
|
|
62
68
|
);
|
|
63
69
|
};
|
|
64
70
|
|
|
65
71
|
/**
|
|
66
72
|
*
|
|
67
|
-
* @param {AttenuationDefinition} attenuationDefinition
|
|
68
|
-
* @returns {UnifiedAttenuationDefinition}
|
|
73
|
+
* @param {import('./types.js').AttenuationDefinition} attenuationDefinition
|
|
74
|
+
* @returns {import('./types.js').UnifiedAttenuationDefinition}
|
|
69
75
|
*/
|
|
70
76
|
export const getAttenuatorFromDefinition = attenuationDefinition => {
|
|
71
77
|
if (!isAttenuationDefinition(attenuationDefinition)) {
|
|
@@ -90,28 +96,45 @@ export const getAttenuatorFromDefinition = attenuationDefinition => {
|
|
|
90
96
|
}
|
|
91
97
|
};
|
|
92
98
|
|
|
99
|
+
// TODO: should be a type guard
|
|
93
100
|
const isRecordOf = (item, predicate) => {
|
|
94
101
|
if (typeof item !== 'object' || item === null || isArray(item)) {
|
|
95
102
|
return false;
|
|
96
103
|
}
|
|
97
104
|
return entries(item).every(([key, value]) => predicate(value, key));
|
|
98
105
|
};
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Type guard for `boolean`
|
|
109
|
+
* @param {unknown} item
|
|
110
|
+
* @returns {item is boolean}
|
|
111
|
+
*/
|
|
99
112
|
const isBoolean = item => typeof item === 'boolean';
|
|
113
|
+
|
|
114
|
+
// TODO: should be a type guard
|
|
100
115
|
const predicateOr =
|
|
101
116
|
(...predicates) =>
|
|
102
117
|
item =>
|
|
103
118
|
predicates.some(p => p(item));
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* @param {unknown} item
|
|
122
|
+
* @returns {item is import('./types.js').PolicyItem}
|
|
123
|
+
*/
|
|
104
124
|
const isPolicyItem = item =>
|
|
105
125
|
item === undefined ||
|
|
106
126
|
item === WILDCARD_POLICY_VALUE ||
|
|
107
127
|
isRecordOf(item, isBoolean);
|
|
108
128
|
|
|
109
129
|
/**
|
|
130
|
+
* This asserts (i.e., throws) that `allegedPackagePolicy` is a valid `PackagePolicy`.
|
|
131
|
+
*
|
|
132
|
+
* Mild-mannered during the day, but fights crime at night as a type guard.
|
|
110
133
|
*
|
|
111
|
-
* @param {unknown} allegedPackagePolicy
|
|
112
|
-
* @param {string} path
|
|
113
|
-
* @param {string} [url]
|
|
114
|
-
* @returns {
|
|
134
|
+
* @param {unknown} allegedPackagePolicy - Alleged `PackagePolicy` to test
|
|
135
|
+
* @param {string} path - Path in the `Policy` object; used for error messages only
|
|
136
|
+
* @param {string} [url] - URL of the policy file; used for error messages only
|
|
137
|
+
* @returns {asserts allegedPackagePolicy is import('./types.js').PackagePolicy|undefined}
|
|
115
138
|
*/
|
|
116
139
|
export const assertPackagePolicy = (allegedPackagePolicy, path, url) => {
|
|
117
140
|
if (allegedPackagePolicy === undefined) {
|
|
@@ -172,9 +195,12 @@ export const assertPackagePolicy = (allegedPackagePolicy, path, url) => {
|
|
|
172
195
|
};
|
|
173
196
|
|
|
174
197
|
/**
|
|
198
|
+
* This asserts (i.e., throws) that `allegedPolicy` is a valid `Policy`
|
|
199
|
+
*
|
|
200
|
+
* It also moonlights as a type guard.
|
|
175
201
|
*
|
|
176
|
-
* @param {unknown} allegedPolicy
|
|
177
|
-
* @returns {
|
|
202
|
+
* @param {unknown} allegedPolicy - Alleged `Policy` to test
|
|
203
|
+
* @returns {asserts allegedPolicy is import('./types.js').Policy|undefined}
|
|
178
204
|
*/
|
|
179
205
|
export const assertPolicy = allegedPolicy => {
|
|
180
206
|
if (allegedPolicy === undefined) {
|
package/src/policy.d.ts
CHANGED
|
@@ -2,19 +2,24 @@
|
|
|
2
2
|
* Const string to identify the internal attenuators compartment
|
|
3
3
|
*/
|
|
4
4
|
export const ATTENUATORS_COMPARTMENT: "<ATTENUATORS>";
|
|
5
|
-
export function detectAttenuators(policy
|
|
6
|
-
export function dependencyAllowedByPolicy(namingKit: PackageNamingKit, packagePolicy:
|
|
7
|
-
export function getPolicyForPackage(namingKit: PackageNamingKit, policy
|
|
8
|
-
export function makeDeferredAttenuatorsProvider(compartments: Record<string, Compartment>, compartmentDescriptors: Record<string, CompartmentDescriptor>): DeferredAttenuatorsProvider;
|
|
9
|
-
export function attenuateGlobals(globalThis: object, globals: object, packagePolicy:
|
|
10
|
-
export function enforceModulePolicy(specifier: string, compartmentDescriptor: import('./types.js').CompartmentDescriptor,
|
|
11
|
-
export function attenuateModuleHook(specifier: string, originalModuleRecord: ThirdPartyStaticModuleInterface, policy:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export type
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
5
|
+
export function detectAttenuators(policy?: import("./types.js").Policy<void, void, void> | undefined): Array<string>;
|
|
6
|
+
export function dependencyAllowedByPolicy(namingKit: import('./types.js').PackageNamingKit, packagePolicy: import('./types.js').PackagePolicy): boolean;
|
|
7
|
+
export function getPolicyForPackage(namingKit: import('./types.js').PackageNamingKit, policy?: import("./types.js").Policy<void, void, void> | undefined): any;
|
|
8
|
+
export function makeDeferredAttenuatorsProvider(compartments: Record<string, Compartment>, compartmentDescriptors: Record<string, import('./types.js').CompartmentDescriptor>): import('./types.js').DeferredAttenuatorsProvider;
|
|
9
|
+
export function attenuateGlobals(globalThis: object, globals: object, packagePolicy: import('./types.js').PackagePolicy, attenuators: import('./types.js').DeferredAttenuatorsProvider, pendingJobs: Array<Promise<any>>, name?: string): void;
|
|
10
|
+
export function enforceModulePolicy(specifier: string, compartmentDescriptor: import('./types.js').CompartmentDescriptor, { exit, errorHint }?: EnforceModulePolicyOptions | undefined): void;
|
|
11
|
+
export function attenuateModuleHook(specifier: string, originalModuleRecord: import('ses').ThirdPartyStaticModuleInterface, policy: import('./types.js').PackagePolicy, attenuators: import('./types.js').DeferredAttenuatorsProvider): Promise<import('ses').ThirdPartyStaticModuleInterface>;
|
|
12
|
+
/**
|
|
13
|
+
* Options for {@link enforceModulePolicy }
|
|
14
|
+
*/
|
|
15
|
+
export type EnforceModulePolicyOptions = {
|
|
16
|
+
/**
|
|
17
|
+
* - Whether it is an exit module
|
|
18
|
+
*/
|
|
19
|
+
exit?: boolean | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* - Error hint message
|
|
22
|
+
*/
|
|
23
|
+
errorHint?: string | undefined;
|
|
24
|
+
};
|
|
20
25
|
//# sourceMappingURL=policy.d.ts.map
|
package/src/policy.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["policy.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["policy.js"],"names":[],"mappings":"AAYA;;GAEG;AACH,sDAAuD;AAkDhD,uGAFM,MAAM,MAAM,CAAC,CAezB;AA0BM,qDAJI,OAAO,YAAY,EAAE,gBAAgB,iBACrC,OAAO,YAAY,EAAE,aAAa,GAChC,OAAO,CASnB;AA0BM,+CAHI,OAAO,YAAY,EAAE,gBAAgB,2EAuB/C;AAsDM,8DAJI,OAAO,MAAM,EAAE,WAAW,CAAC,0BAC3B,OAAO,MAAM,EAAE,OAAO,YAAY,EAAE,qBAAqB,CAAC,GACxD,OAAO,YAAY,EAAE,2BAA2B,CA2C5D;AAoDM,6CARI,MAAM,WACN,MAAM,iBACN,OAAO,YAAY,EAAE,aAAa,eAClC,OAAO,YAAY,EAAE,2BAA2B,eAChD,mBAAc,SACd,MAAM,GACJ,IAAI,CAgDhB;AA2BM,+CAJI,MAAM,yBACN,OAAO,YAAY,EAAE,qBAAqB,sEAiCpD;AAgDM,+CANI,MAAM,wBACN,OAAO,KAAK,EAAE,+BAA+B,UAC7C,OAAO,YAAY,EAAE,aAAa,eAClC,OAAO,YAAY,EAAE,2BAA2B,GAC9C,QAAQ,OAAO,KAAK,EAAE,+BAA+B,CAAC,CAyBlE"}
|
package/src/policy.js
CHANGED
|
@@ -1,20 +1,10 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
-
/** @typedef {import('./types.js').PackageNamingKit} PackageNamingKit */
|
|
4
|
-
/** @typedef {import('./types.js').AttenuationDefinition} AttenuationDefinition */
|
|
5
|
-
/** @typedef {import('./types.js').FullAttenuationDefinition} FullAttenuationDefinition */
|
|
6
|
-
/** @typedef {import('./types.js').ImplicitAttenuationDefinition} ImplicitAttenuationDefinition */
|
|
7
|
-
/** @typedef {import('./types.js').Attenuator} Attenuator */
|
|
8
|
-
/** @typedef {import('./types.js').DeferredAttenuatorsProvider} DeferredAttenuatorsProvider */
|
|
9
|
-
/** @typedef {import('./types.js').CompartmentDescriptor} CompartmentDescriptor */
|
|
10
|
-
// get StaticModuleRecord from the ses package's types
|
|
11
|
-
/** @typedef {import('ses').ThirdPartyStaticModuleInterface} ThirdPartyStaticModuleInterface */
|
|
12
|
-
|
|
13
3
|
import {
|
|
14
|
-
policyLookupHelper,
|
|
15
|
-
isAttenuationDefinition,
|
|
16
4
|
getAttenuatorFromDefinition,
|
|
17
5
|
isAllowingEverything,
|
|
6
|
+
isAttenuationDefinition,
|
|
7
|
+
policyLookupHelper,
|
|
18
8
|
} from './policy-format.js';
|
|
19
9
|
|
|
20
10
|
const { create, entries, values, assign, keys, freeze } = Object;
|
|
@@ -46,8 +36,15 @@ const selectiveCopy = (from, to, list) => {
|
|
|
46
36
|
return to;
|
|
47
37
|
};
|
|
48
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Parses an attenuation definition for attenuator names
|
|
41
|
+
*
|
|
42
|
+
* Note: this function is recursive
|
|
43
|
+
* @param {string[]} attenuators - List of attenuator names; may be mutated
|
|
44
|
+
* @param {import('./types.js').AttenuationDefinition|import('./types.js').Policy} policyFragment
|
|
45
|
+
*/
|
|
49
46
|
const collectAttenuators = (attenuators, policyFragment) => {
|
|
50
|
-
if (policyFragment
|
|
47
|
+
if ('attenuate' in policyFragment) {
|
|
51
48
|
attenuators.push(policyFragment.attenuate);
|
|
52
49
|
}
|
|
53
50
|
for (const value of values(policyFragment)) {
|
|
@@ -58,11 +55,12 @@ const collectAttenuators = (attenuators, policyFragment) => {
|
|
|
58
55
|
};
|
|
59
56
|
|
|
60
57
|
const attenuatorsCache = new WeakMap();
|
|
58
|
+
|
|
61
59
|
/**
|
|
62
60
|
* Goes through policy and lists all attenuator specifiers used.
|
|
63
61
|
* Memoization keyed on policy object reference
|
|
64
62
|
*
|
|
65
|
-
* @param {
|
|
63
|
+
* @param {import('./types.js').Policy} [policy]
|
|
66
64
|
* @returns {Array<string>} attenuators
|
|
67
65
|
*/
|
|
68
66
|
export const detectAttenuators = policy => {
|
|
@@ -83,7 +81,7 @@ export const detectAttenuators = policy => {
|
|
|
83
81
|
/**
|
|
84
82
|
* Generates a string identifying a package for policy lookup purposes.
|
|
85
83
|
*
|
|
86
|
-
* @param {PackageNamingKit} namingKit
|
|
84
|
+
* @param {import('./types.js').PackageNamingKit} namingKit
|
|
87
85
|
* @returns {string}
|
|
88
86
|
*/
|
|
89
87
|
const generateCanonicalName = ({ isEntry = false, name, path }) => {
|
|
@@ -97,11 +95,11 @@ const generateCanonicalName = ({ isEntry = false, name, path }) => {
|
|
|
97
95
|
};
|
|
98
96
|
|
|
99
97
|
/**
|
|
100
|
-
* Verifies if a module identified by namingKit can be a dependency of a package per packagePolicy
|
|
101
|
-
* packagePolicy is required, when policy is not set, skipping needs to be handled by the caller.
|
|
98
|
+
* Verifies if a module identified by `namingKit` can be a dependency of a package per `packagePolicy`.
|
|
99
|
+
* `packagePolicy` is required, when policy is not set, skipping needs to be handled by the caller.
|
|
102
100
|
*
|
|
103
|
-
* @param {PackageNamingKit} namingKit
|
|
104
|
-
* @param {
|
|
101
|
+
* @param {import('./types.js').PackageNamingKit} namingKit
|
|
102
|
+
* @param {import('./types.js').PackagePolicy} packagePolicy
|
|
105
103
|
* @returns {boolean}
|
|
106
104
|
*/
|
|
107
105
|
export const dependencyAllowedByPolicy = (namingKit, packagePolicy) => {
|
|
@@ -116,9 +114,26 @@ export const dependencyAllowedByPolicy = (namingKit, packagePolicy) => {
|
|
|
116
114
|
/**
|
|
117
115
|
* Returns the policy applicable to the canonicalName of the package
|
|
118
116
|
*
|
|
119
|
-
* @
|
|
120
|
-
* @param {
|
|
121
|
-
* @
|
|
117
|
+
* @overload
|
|
118
|
+
* @param {import('./types.js').PackageNamingKit} namingKit - a key in the policy resources spec is derived from these
|
|
119
|
+
* @param {import('./types.js').Policy} policy - user supplied policy
|
|
120
|
+
* @returns {import('./types.js').PackagePolicy} packagePolicy if policy was specified
|
|
121
|
+
*/
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Returns `undefined`
|
|
125
|
+
*
|
|
126
|
+
* @overload
|
|
127
|
+
* @param {import('./types.js').PackageNamingKit} namingKit - a key in the policy resources spec is derived from these
|
|
128
|
+
* @param {import('./types.js').Policy} [policy] - user supplied policy
|
|
129
|
+
* @returns {import('./types.js').PackagePolicy|undefined} packagePolicy if policy was specified
|
|
130
|
+
*/
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Returns the policy applicable to the canonicalName of the package
|
|
134
|
+
*
|
|
135
|
+
* @param {import('./types.js').PackageNamingKit} namingKit - a key in the policy resources spec is derived from these
|
|
136
|
+
* @param {import('./types.js').Policy} [policy] - user supplied policy
|
|
122
137
|
*/
|
|
123
138
|
export const getPolicyForPackage = (namingKit, policy) => {
|
|
124
139
|
if (!policy) {
|
|
@@ -142,8 +157,13 @@ export const getPolicyForPackage = (namingKit, policy) => {
|
|
|
142
157
|
}
|
|
143
158
|
};
|
|
144
159
|
|
|
160
|
+
/**
|
|
161
|
+
* Get list of globals from package policy
|
|
162
|
+
* @param {import('./types.js').PackagePolicy} [packagePolicy]
|
|
163
|
+
* @returns {Array<string>}
|
|
164
|
+
*/
|
|
145
165
|
const getGlobalsList = packagePolicy => {
|
|
146
|
-
if (!packagePolicy.globals) {
|
|
166
|
+
if (!packagePolicy || !packagePolicy.globals) {
|
|
147
167
|
return [];
|
|
148
168
|
}
|
|
149
169
|
return entries(packagePolicy.globals)
|
|
@@ -153,10 +173,11 @@ const getGlobalsList = packagePolicy => {
|
|
|
153
173
|
|
|
154
174
|
const GLOBAL_ATTENUATOR = 'attenuateGlobals';
|
|
155
175
|
const MODULE_ATTENUATOR = 'attenuateModule';
|
|
176
|
+
|
|
156
177
|
/**
|
|
157
|
-
*
|
|
158
|
-
* @param {AttenuationDefinition} attenuationDefinition
|
|
159
|
-
* @param {DeferredAttenuatorsProvider} attenuatorsProvider
|
|
178
|
+
* Imports attenuator per its definition and provider
|
|
179
|
+
* @param {import('./types.js').AttenuationDefinition} attenuationDefinition
|
|
180
|
+
* @param {import('./types.js').DeferredAttenuatorsProvider} attenuatorsProvider
|
|
160
181
|
* @param {string} attenuatorExportName
|
|
161
182
|
* @returns {Promise<Function>}
|
|
162
183
|
*/
|
|
@@ -183,10 +204,10 @@ const importAttenuatorForDefinition = async (
|
|
|
183
204
|
};
|
|
184
205
|
|
|
185
206
|
/**
|
|
186
|
-
*
|
|
207
|
+
* Makes an async provider for attenuators
|
|
187
208
|
* @param {Record<string, Compartment>} compartments
|
|
188
|
-
* @param {Record<string, CompartmentDescriptor>} compartmentDescriptors
|
|
189
|
-
* @returns {DeferredAttenuatorsProvider}
|
|
209
|
+
* @param {Record<string, import('./types.js').CompartmentDescriptor>} compartmentDescriptors
|
|
210
|
+
* @returns {import('./types.js').DeferredAttenuatorsProvider}
|
|
190
211
|
*/
|
|
191
212
|
export const makeDeferredAttenuatorsProvider = (
|
|
192
213
|
compartments,
|
|
@@ -210,7 +231,7 @@ export const makeDeferredAttenuatorsProvider = (
|
|
|
210
231
|
/**
|
|
211
232
|
*
|
|
212
233
|
* @param {string} attenuatorSpecifier
|
|
213
|
-
* @returns {Promise<Attenuator>}
|
|
234
|
+
* @returns {Promise<import('./types.js').Attenuator>}
|
|
214
235
|
*/
|
|
215
236
|
importAttenuator = async attenuatorSpecifier => {
|
|
216
237
|
if (!attenuatorSpecifier) {
|
|
@@ -232,10 +253,11 @@ export const makeDeferredAttenuatorsProvider = (
|
|
|
232
253
|
};
|
|
233
254
|
|
|
234
255
|
/**
|
|
256
|
+
* Attenuates the `globalThis` object
|
|
235
257
|
*
|
|
236
258
|
* @param {object} options
|
|
237
|
-
* @param {DeferredAttenuatorsProvider} options.attenuators
|
|
238
|
-
* @param {AttenuationDefinition} options.attenuationDefinition
|
|
259
|
+
* @param {import('./types.js').DeferredAttenuatorsProvider} options.attenuators
|
|
260
|
+
* @param {import('./types.js').AttenuationDefinition} options.attenuationDefinition
|
|
239
261
|
* @param {object} options.globalThis
|
|
240
262
|
* @param {object} options.globals
|
|
241
263
|
*/
|
|
@@ -274,8 +296,8 @@ async function attenuateGlobalThis({
|
|
|
274
296
|
*
|
|
275
297
|
* @param {object} globalThis
|
|
276
298
|
* @param {object} globals
|
|
277
|
-
* @param {
|
|
278
|
-
* @param {DeferredAttenuatorsProvider} attenuators
|
|
299
|
+
* @param {import('./types.js').PackagePolicy} packagePolicy
|
|
300
|
+
* @param {import('./types.js').DeferredAttenuatorsProvider} attenuators
|
|
279
301
|
* @param {Array<Promise>} pendingJobs
|
|
280
302
|
* @param {string} name
|
|
281
303
|
* @returns {void}
|
|
@@ -328,37 +350,49 @@ export const attenuateGlobals = (
|
|
|
328
350
|
freezeGlobalThisUnlessOptedOut();
|
|
329
351
|
};
|
|
330
352
|
|
|
353
|
+
/**
|
|
354
|
+
* @param {string} [errorHint]
|
|
355
|
+
* @returns {string}
|
|
356
|
+
*/
|
|
331
357
|
const diagnoseModulePolicy = errorHint => {
|
|
332
358
|
if (!errorHint) {
|
|
333
359
|
return '';
|
|
334
360
|
}
|
|
335
361
|
return ` (info: ${errorHint})`;
|
|
336
362
|
};
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Options for {@link enforceModulePolicy}
|
|
366
|
+
* @typedef EnforceModulePolicyOptions
|
|
367
|
+
* @property {boolean} [exit] - Whether it is an exit module
|
|
368
|
+
* @property {string} [errorHint] - Error hint message
|
|
369
|
+
*/
|
|
370
|
+
|
|
337
371
|
/**
|
|
338
372
|
* Throws if importing of the specifier is not allowed by the policy
|
|
339
373
|
*
|
|
340
374
|
* @param {string} specifier
|
|
341
375
|
* @param {import('./types.js').CompartmentDescriptor} compartmentDescriptor
|
|
342
|
-
* @param {
|
|
376
|
+
* @param {EnforceModulePolicyOptions} [options]
|
|
343
377
|
*/
|
|
344
378
|
export const enforceModulePolicy = (
|
|
345
379
|
specifier,
|
|
346
380
|
compartmentDescriptor,
|
|
347
|
-
|
|
381
|
+
{ exit, errorHint } = {},
|
|
348
382
|
) => {
|
|
349
383
|
const { policy, modules, label } = compartmentDescriptor;
|
|
350
384
|
if (!policy) {
|
|
351
385
|
return;
|
|
352
386
|
}
|
|
353
387
|
|
|
354
|
-
if (!
|
|
388
|
+
if (!exit) {
|
|
355
389
|
if (!modules[specifier]) {
|
|
356
390
|
throw Error(
|
|
357
391
|
`Importing ${q(specifier)} in ${q(
|
|
358
392
|
label,
|
|
359
393
|
)} was not allowed by packages policy ${q(
|
|
360
394
|
policy.packages,
|
|
361
|
-
)}${diagnoseModulePolicy(
|
|
395
|
+
)}${diagnoseModulePolicy(errorHint)}`,
|
|
362
396
|
);
|
|
363
397
|
}
|
|
364
398
|
return;
|
|
@@ -368,18 +402,18 @@ export const enforceModulePolicy = (
|
|
|
368
402
|
throw Error(
|
|
369
403
|
`Importing ${q(specifier)} was not allowed by policy builtins:${q(
|
|
370
404
|
policy.builtins,
|
|
371
|
-
)}${diagnoseModulePolicy(
|
|
405
|
+
)}${diagnoseModulePolicy(errorHint)}`,
|
|
372
406
|
);
|
|
373
407
|
}
|
|
374
408
|
};
|
|
375
409
|
|
|
376
410
|
/**
|
|
377
|
-
*
|
|
411
|
+
* Attenuates a module
|
|
378
412
|
* @param {object} options
|
|
379
|
-
* @param {DeferredAttenuatorsProvider} options.attenuators
|
|
380
|
-
* @param {AttenuationDefinition} options.attenuationDefinition
|
|
381
|
-
* @param {ThirdPartyStaticModuleInterface} options.originalModuleRecord
|
|
382
|
-
* @returns {Promise<ThirdPartyStaticModuleInterface>}
|
|
413
|
+
* @param {import('./types.js').DeferredAttenuatorsProvider} options.attenuators
|
|
414
|
+
* @param {import('./types.js').AttenuationDefinition} options.attenuationDefinition
|
|
415
|
+
* @param {import('ses').ThirdPartyStaticModuleInterface} options.originalModuleRecord
|
|
416
|
+
* @returns {Promise<import('ses').ThirdPartyStaticModuleInterface>}
|
|
383
417
|
*/
|
|
384
418
|
async function attenuateModule({
|
|
385
419
|
attenuators,
|
|
@@ -409,14 +443,15 @@ async function attenuateModule({
|
|
|
409
443
|
},
|
|
410
444
|
});
|
|
411
445
|
}
|
|
446
|
+
|
|
412
447
|
/**
|
|
413
448
|
* Throws if importing of the specifier is not allowed by the policy
|
|
414
449
|
*
|
|
415
450
|
* @param {string} specifier - exit module name
|
|
416
|
-
* @param {ThirdPartyStaticModuleInterface} originalModuleRecord - reference to the exit module
|
|
417
|
-
* @param {
|
|
418
|
-
* @param {DeferredAttenuatorsProvider} attenuators - a key-value where attenuations can be found
|
|
419
|
-
* @returns {Promise<ThirdPartyStaticModuleInterface>} - the attenuated module
|
|
451
|
+
* @param {import('ses').ThirdPartyStaticModuleInterface} originalModuleRecord - reference to the exit module
|
|
452
|
+
* @param {import('./types.js').PackagePolicy} policy - local compartment policy
|
|
453
|
+
* @param {import('./types.js').DeferredAttenuatorsProvider} attenuators - a key-value where attenuations can be found
|
|
454
|
+
* @returns {Promise<import('ses').ThirdPartyStaticModuleInterface>} - the attenuated module
|
|
420
455
|
*/
|
|
421
456
|
export const attenuateModuleHook = async (
|
|
422
457
|
specifier,
|
package/src/types.d.ts
CHANGED
|
@@ -112,7 +112,7 @@ export type Application = {
|
|
|
112
112
|
import: ExecuteFn;
|
|
113
113
|
sha512?: string | undefined;
|
|
114
114
|
};
|
|
115
|
-
export type ExecuteFn = (options?: ExecuteOptions | undefined) => Promise<
|
|
115
|
+
export type ExecuteFn = (options?: ExecuteOptions | undefined) => Promise<SomeObject>;
|
|
116
116
|
export type SnapshotFn = () => Promise<Uint8Array>;
|
|
117
117
|
export type ReadPowers = {
|
|
118
118
|
read: ReadFn;
|
|
@@ -259,22 +259,101 @@ export type PackageNamingKit = {
|
|
|
259
259
|
name: string;
|
|
260
260
|
path: Array<string>;
|
|
261
261
|
};
|
|
262
|
+
/**
|
|
263
|
+
* An object representing a full attenuation definition.
|
|
264
|
+
*/
|
|
262
265
|
export type FullAttenuationDefinition = {
|
|
263
|
-
|
|
264
|
-
|
|
266
|
+
/**
|
|
267
|
+
* - The type of attenuation.
|
|
268
|
+
*/
|
|
269
|
+
attenuate: string;
|
|
270
|
+
/**
|
|
271
|
+
* - The parameters for the attenuation.
|
|
272
|
+
*/
|
|
273
|
+
params: ImplicitAttenuationDefinition;
|
|
265
274
|
};
|
|
266
|
-
|
|
267
|
-
|
|
275
|
+
/**
|
|
276
|
+
* An array of any type representing an implicit attenuation definition.
|
|
277
|
+
*/
|
|
278
|
+
export type ImplicitAttenuationDefinition = [any, ...any[]];
|
|
279
|
+
/**
|
|
280
|
+
* A type representing an attenuation definition, which can be either a full or implicit definition.
|
|
281
|
+
*/
|
|
282
|
+
export type AttenuationDefinition = FullAttenuationDefinition | [any, ...any[]];
|
|
268
283
|
export type UnifiedAttenuationDefinition = {
|
|
269
284
|
displayName: string;
|
|
270
285
|
specifier: string | null;
|
|
271
286
|
params?: any[] | undefined;
|
|
272
287
|
};
|
|
273
|
-
export type Attenuator = {
|
|
274
|
-
attenuateGlobals?:
|
|
275
|
-
attenuateModule?:
|
|
288
|
+
export type Attenuator<GlobalParams extends [any, ...any[]] = [any, ...any[]], ModuleParams extends [any, ...any[]] = [any, ...any[]]> = {
|
|
289
|
+
attenuateGlobals?: GlobalAttenuatorFn<GlobalParams> | undefined;
|
|
290
|
+
attenuateModule?: ModuleAttenuatorFn<ModuleParams, unknown, unknown> | undefined;
|
|
276
291
|
};
|
|
292
|
+
export type GlobalAttenuatorFn<Params extends [any, ...any[]] = [any, ...any[]]> = (params: Params, originalObject: Record<PropertyKey, any>, globalThis: Record<PropertyKey, any>) => void;
|
|
293
|
+
export type ModuleAttenuatorFn<Params extends [any, ...any[]] = [any, ...any[]], T = unknown, U = T> = (params: Params, ns: T) => U;
|
|
277
294
|
export type DeferredAttenuatorsProvider = {
|
|
278
295
|
import: (attenuatorSpecifier: string | null) => Promise<Attenuator>;
|
|
279
296
|
};
|
|
297
|
+
/**
|
|
298
|
+
* A type representing a wildcard policy, which can be 'any'.
|
|
299
|
+
*/
|
|
300
|
+
export type WildcardPolicy = 'any';
|
|
301
|
+
/**
|
|
302
|
+
* A type representing a property policy, which is a record of string keys and boolean values.
|
|
303
|
+
*/
|
|
304
|
+
export type PropertyPolicy = Record<string, boolean>;
|
|
305
|
+
/**
|
|
306
|
+
* A type representing a policy item, which can be a {@link WildcardPolicy wildcard policy}, a property policy, `undefined`, or defined by an attenuator
|
|
307
|
+
*/
|
|
308
|
+
export type PolicyItem<T = void> = WildcardPolicy | PropertyPolicy | T;
|
|
309
|
+
/**
|
|
310
|
+
* An object representing a nested attenuation definition.
|
|
311
|
+
*/
|
|
312
|
+
export type NestedAttenuationDefinition = Record<string, AttenuationDefinition | boolean>;
|
|
313
|
+
/**
|
|
314
|
+
* An object representing a base package policy.
|
|
315
|
+
*/
|
|
316
|
+
export type PackagePolicy<PackagePolicyItem = void, GlobalsPolicyItem = void, BuiltinsPolicyItem = void> = {
|
|
317
|
+
/**
|
|
318
|
+
* - The default attenuator.
|
|
319
|
+
*/
|
|
320
|
+
defaultAttenuator?: string | undefined;
|
|
321
|
+
/**
|
|
322
|
+
* - The policy item for packages.
|
|
323
|
+
*/
|
|
324
|
+
packages?: PolicyItem<PackagePolicyItem> | undefined;
|
|
325
|
+
/**
|
|
326
|
+
* - The policy item or full attenuation definition for globals.
|
|
327
|
+
*/
|
|
328
|
+
globals?: AttenuationDefinition | PolicyItem<GlobalsPolicyItem> | undefined;
|
|
329
|
+
/**
|
|
330
|
+
* - The policy item or nested attenuation definition for builtins.
|
|
331
|
+
*/
|
|
332
|
+
builtins?: NestedAttenuationDefinition | PolicyItem<BuiltinsPolicyItem> | undefined;
|
|
333
|
+
/**
|
|
334
|
+
* - Whether to disable global freeze.
|
|
335
|
+
*/
|
|
336
|
+
noGlobalFreeze?: boolean | undefined;
|
|
337
|
+
};
|
|
338
|
+
/**
|
|
339
|
+
* An object representing a base policy.
|
|
340
|
+
*/
|
|
341
|
+
export type Policy<PackagePolicyItem = void, GlobalsPolicyItem = void, BuiltinsPolicyItem = void> = {
|
|
342
|
+
/**
|
|
343
|
+
* - The package policies for the resources.
|
|
344
|
+
*/
|
|
345
|
+
resources: Record<string, PackagePolicy<PackagePolicyItem, GlobalsPolicyItem, BuiltinsPolicyItem>>;
|
|
346
|
+
/**
|
|
347
|
+
* - The default attenuator.
|
|
348
|
+
*/
|
|
349
|
+
defaultAttenuator?: string | undefined;
|
|
350
|
+
/**
|
|
351
|
+
* - The package policy for the entry.
|
|
352
|
+
*/
|
|
353
|
+
entry?: PackagePolicy<PackagePolicyItem, GlobalsPolicyItem, BuiltinsPolicyItem> | undefined;
|
|
354
|
+
};
|
|
355
|
+
/**
|
|
356
|
+
* Any object. All objects. Not `null`, though.
|
|
357
|
+
*/
|
|
358
|
+
export type SomeObject = Record<PropertyKey, any>;
|
|
280
359
|
//# sourceMappingURL=types.d.ts.map
|
package/src/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["types.js"],"names":[],"mappings":"oCAKc,OAAO,KAAK,EAAE,qBAAqB;8CACnC,OAAO,KAAK,EAAE,+BAA+B;yBAC7C,OAAO,KAAK,EAAE,UAAU;+BACxB,OAAO,KAAK,EAAE,gBAAgB;wBAC9B,OAAO,KAAK,EAAE,SAAS;;;;;;UAWvB,MAAM,MAAM,CAAC;WACb,eAAe;kBACf,OAAO,MAAM,EAAE,qBAAqB,CAAC;;;;;;;iBAQrC,MAAM;YACN,MAAM;;;;;;;;WASN,MAAM;;;;;;;;;;;UAGN,MAAM;cAGN,MAAM;;;;;;;aAIN,OAAO,MAAM,EAAE,gBAAgB,CAAC;YAChC,OAAO,MAAM,EAAE,eAAe,CAAC;;;;aAC/B,OAAO,MAAM,EAAE,QAAQ,CAAC;;;;WACxB,OAAO,MAAM,EAAE,QAAQ,CAAC;;;;YACxB,MAAM;;;;;;;kBAQN,MAAM;;;;;;;;;;;;;;;;;;;iBAiBN,MAAM;;;uBAKP,KAAK,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,cAAc,GAAG,cAAc;;WAS1E,OAAO;cACP,UAAU;;iCAKb,MAAM,SACN,UAAU,KACR,QAAQ,IAAI,CAAC;;UAKZ,MAAM;;gCAKT,MAAM,KACJ,QAAQ,UAAU,CAAC;;;;qCAOrB,MAAM,KACJ,QAAQ,UAAU,GAAG,SAAS,CAAC;;;;;;qCASjC,MAAM,KACJ,QAAQ,MAAM,CAAC;6BAKjB,MAAM,GAAG,UAAU,KACjB,MAAM;;YAKL,SAAS;;;kEAOV,QAAQ,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["types.js"],"names":[],"mappings":"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"}
|
package/src/types.js
CHANGED
|
@@ -146,7 +146,7 @@ export {};
|
|
|
146
146
|
/**
|
|
147
147
|
* @callback ExecuteFn
|
|
148
148
|
* @param {ExecuteOptions} [options]
|
|
149
|
-
* @returns {Promise<
|
|
149
|
+
* @returns {Promise<SomeObject>}
|
|
150
150
|
*/
|
|
151
151
|
|
|
152
152
|
/**
|
|
@@ -399,16 +399,19 @@ export {};
|
|
|
399
399
|
*/
|
|
400
400
|
|
|
401
401
|
/**
|
|
402
|
+
* An object representing a full attenuation definition.
|
|
402
403
|
* @typedef {object} FullAttenuationDefinition
|
|
403
|
-
* @property {string}
|
|
404
|
-
* @property {
|
|
404
|
+
* @property {string} attenuate - The type of attenuation.
|
|
405
|
+
* @property {ImplicitAttenuationDefinition} params - The parameters for the attenuation.
|
|
405
406
|
*/
|
|
406
407
|
|
|
407
408
|
/**
|
|
408
|
-
*
|
|
409
|
+
* An array of any type representing an implicit attenuation definition.
|
|
410
|
+
* @typedef {[any, ...any[]]} ImplicitAttenuationDefinition
|
|
409
411
|
*/
|
|
410
412
|
|
|
411
413
|
/**
|
|
414
|
+
* A type representing an attenuation definition, which can be either a full or implicit definition.
|
|
412
415
|
* @typedef {FullAttenuationDefinition | ImplicitAttenuationDefinition} AttenuationDefinition
|
|
413
416
|
*/
|
|
414
417
|
|
|
@@ -420,12 +423,84 @@ export {};
|
|
|
420
423
|
*/
|
|
421
424
|
|
|
422
425
|
/**
|
|
423
|
-
* @
|
|
424
|
-
* @
|
|
425
|
-
* @
|
|
426
|
+
* @template {[any, ...any[]]} [GlobalParams=[any, ...any[]]]
|
|
427
|
+
* @template {[any, ...any[]]} [ModuleParams=[any, ...any[]]]
|
|
428
|
+
* @typedef Attenuator
|
|
429
|
+
* @property {GlobalAttenuatorFn<GlobalParams>} [attenuateGlobals]
|
|
430
|
+
* @property {ModuleAttenuatorFn<ModuleParams>} [attenuateModule]
|
|
431
|
+
*/
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* @template {[any, ...any[]]} [Params=[any, ...any[]]]
|
|
435
|
+
* @callback GlobalAttenuatorFn
|
|
436
|
+
* @param {Params} params
|
|
437
|
+
* @param {Record<PropertyKey, any>} originalObject
|
|
438
|
+
* @param {Record<PropertyKey, any>} globalThis
|
|
439
|
+
* @returns {void}
|
|
440
|
+
* @todo Unsure if we can do much typing of `originalObject` and `globalThis` here.
|
|
441
|
+
*/
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* @template {[any, ...any[]]} [Params=[any, ...any[]]]
|
|
445
|
+
* @template [T=unknown]
|
|
446
|
+
* @template [U=T]
|
|
447
|
+
* @callback ModuleAttenuatorFn
|
|
448
|
+
* @param {Params} params
|
|
449
|
+
* @param {T} ns
|
|
450
|
+
* @returns {U}
|
|
426
451
|
*/
|
|
427
452
|
|
|
428
453
|
/**
|
|
429
454
|
* @typedef {object} DeferredAttenuatorsProvider
|
|
430
455
|
* @property {(attenuatorSpecifier: string|null) => Promise<Attenuator>} import
|
|
431
456
|
*/
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* A type representing a wildcard policy, which can be 'any'.
|
|
460
|
+
* @typedef {'any'} WildcardPolicy
|
|
461
|
+
*/
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* A type representing a property policy, which is a record of string keys and boolean values.
|
|
465
|
+
* @typedef {Record<string, boolean>} PropertyPolicy
|
|
466
|
+
*/
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* A type representing a policy item, which can be a {@link WildcardPolicy wildcard policy}, a property policy, `undefined`, or defined by an attenuator
|
|
470
|
+
* @template [T=void]
|
|
471
|
+
* @typedef {WildcardPolicy|PropertyPolicy|T} PolicyItem
|
|
472
|
+
*/
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* An object representing a nested attenuation definition.
|
|
476
|
+
* @typedef {Record<string, AttenuationDefinition | boolean>} NestedAttenuationDefinition
|
|
477
|
+
*/
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* An object representing a base package policy.
|
|
481
|
+
* @template [PackagePolicyItem=void]
|
|
482
|
+
* @template [GlobalsPolicyItem=void]
|
|
483
|
+
* @template [BuiltinsPolicyItem=void]
|
|
484
|
+
* @typedef {object} PackagePolicy
|
|
485
|
+
* @property {string} [defaultAttenuator] - The default attenuator.
|
|
486
|
+
* @property {PolicyItem<PackagePolicyItem>} [packages] - The policy item for packages.
|
|
487
|
+
* @property {PolicyItem<GlobalsPolicyItem>|AttenuationDefinition} [globals] - The policy item or full attenuation definition for globals.
|
|
488
|
+
* @property {PolicyItem<BuiltinsPolicyItem>|NestedAttenuationDefinition} [builtins] - The policy item or nested attenuation definition for builtins.
|
|
489
|
+
* @property {boolean} [noGlobalFreeze] - Whether to disable global freeze.
|
|
490
|
+
*/
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* An object representing a base policy.
|
|
494
|
+
* @template [PackagePolicyItem=void]
|
|
495
|
+
* @template [GlobalsPolicyItem=void]
|
|
496
|
+
* @template [BuiltinsPolicyItem=void]
|
|
497
|
+
* @typedef {object} Policy
|
|
498
|
+
* @property {Record<string, PackagePolicy<PackagePolicyItem, GlobalsPolicyItem, BuiltinsPolicyItem>>} resources - The package policies for the resources.
|
|
499
|
+
* @property {string} [defaultAttenuator] - The default attenuator.
|
|
500
|
+
* @property {PackagePolicy<PackagePolicyItem, GlobalsPolicyItem, BuiltinsPolicyItem>} [entry] - The package policy for the entry.
|
|
501
|
+
*/
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Any object. All objects. Not `null`, though.
|
|
505
|
+
* @typedef {Record<PropertyKey, any>} SomeObject
|
|
506
|
+
*/
|
package/types.d.ts
CHANGED
|
@@ -14,3 +14,6 @@ export {
|
|
|
14
14
|
export { search } from './src/search.js';
|
|
15
15
|
export { compartmentMapForNodeModules } from './src/node-modules.js';
|
|
16
16
|
export { makeBundle, writeBundle } from './src/bundle.js';
|
|
17
|
+
|
|
18
|
+
// eslint-disable-next-line import/export -- ESLint doesn't understand this
|
|
19
|
+
export type * from './src/types.js';
|