@fluidframework/tree-agent-ses 2.63.0-359962
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/.eslintrc.cjs +54 -0
- package/.mocharc.cjs +12 -0
- package/.vscode/extensions.json +3 -0
- package/.vscode/settings.json +21 -0
- package/.vscode/tree-agent-ses.code-workspace +22 -0
- package/CHANGELOG.md +5 -0
- package/LICENSE +21 -0
- package/README.md +23 -0
- package/alpha.d.ts +11 -0
- package/api-extractor/api-extractor-lint-alpha.cjs.json +5 -0
- package/api-extractor/api-extractor-lint-alpha.esm.json +5 -0
- package/api-extractor/api-extractor-lint-bundle.json +5 -0
- package/api-extractor/api-extractor-lint-index.cjs.json +5 -0
- package/api-extractor/api-extractor-lint-index.esm.json +5 -0
- package/api-extractor/api-extractor-lint-public.cjs.json +5 -0
- package/api-extractor/api-extractor-lint-public.esm.json +5 -0
- package/api-extractor-lint.json +4 -0
- package/api-extractor.json +4 -0
- package/biome.jsonc +4 -0
- package/dist/alpha.d.ts +21 -0
- package/dist/executor.d.ts +22 -0
- package/dist/executor.d.ts.map +1 -0
- package/dist/executor.js +78 -0
- package/dist/executor.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/package.json +4 -0
- package/dist/public.d.ts +16 -0
- package/internal.d.ts +11 -0
- package/lib/alpha.d.ts +21 -0
- package/lib/executor.d.ts +22 -0
- package/lib/executor.d.ts.map +1 -0
- package/lib/executor.js +74 -0
- package/lib/executor.js.map +1 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +11 -0
- package/lib/index.js.map +1 -0
- package/lib/public.d.ts +16 -0
- package/package.json +157 -0
- package/src/executor.ts +86 -0
- package/src/index.ts +12 -0
- package/tsconfig.cjs.json +7 -0
- package/tsconfig.json +14 -0
- package/tsdoc.json +4 -0
package/.eslintrc.cjs
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
module.exports = {
|
|
7
|
+
extends: [require.resolve("@fluidframework/eslint-config-fluid/strict"), "prettier"],
|
|
8
|
+
parserOptions: {
|
|
9
|
+
project: ["./tsconfig.json"],
|
|
10
|
+
},
|
|
11
|
+
rules: {
|
|
12
|
+
// Allow reaching into FluidFramework package paths that end with alpha, beta, legacy, or internal
|
|
13
|
+
"import/no-internal-modules": [
|
|
14
|
+
"error",
|
|
15
|
+
{
|
|
16
|
+
allow: [
|
|
17
|
+
"@fluidframework/*/alpha",
|
|
18
|
+
"@fluidframework/*/beta",
|
|
19
|
+
"@fluidframework/*/legacy",
|
|
20
|
+
"@fluidframework/*/internal",
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
},
|
|
25
|
+
overrides: [
|
|
26
|
+
{
|
|
27
|
+
files: ["src/test/**/*"],
|
|
28
|
+
parserOptions: {
|
|
29
|
+
project: ["./src/test/tsconfig.json"],
|
|
30
|
+
},
|
|
31
|
+
rules: {
|
|
32
|
+
"import/no-internal-modules": [
|
|
33
|
+
"error",
|
|
34
|
+
{
|
|
35
|
+
allow: [
|
|
36
|
+
"*/index.js",
|
|
37
|
+
"@fluidframework/*/alpha",
|
|
38
|
+
"@fluidframework/*/beta",
|
|
39
|
+
"@fluidframework/*/legacy",
|
|
40
|
+
"@fluidframework/*/internal",
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
"import/no-unresolved": "off",
|
|
45
|
+
"@typescript-eslint/no-unsafe-assignment": "off",
|
|
46
|
+
"@typescript-eslint/no-unsafe-call": "off",
|
|
47
|
+
"@typescript-eslint/no-unsafe-member-access": "off",
|
|
48
|
+
"@typescript-eslint/no-unsafe-return": "off",
|
|
49
|
+
"@typescript-eslint/no-unsafe-argument": "off",
|
|
50
|
+
"@typescript-eslint/strict-boolean-expressions": "off",
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
};
|
package/.mocharc.cjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
const getFluidTestMochaConfig = require("@fluid-internal/mocha-test-setup/mocharc-common");
|
|
9
|
+
|
|
10
|
+
// Reuse shared Fluid test mocha config for this package
|
|
11
|
+
const config = getFluidTestMochaConfig(__dirname);
|
|
12
|
+
module.exports = config;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"search.exclude": {
|
|
3
|
+
"**/node_modules": true,
|
|
4
|
+
"**/dist": true,
|
|
5
|
+
"**/lib": true,
|
|
6
|
+
},
|
|
7
|
+
"mochaExplorer.files": ["dist/test/**/*.*js"],
|
|
8
|
+
"mochaExplorer.require": [
|
|
9
|
+
"node_modules/@fluid-internal/mocha-test-setup",
|
|
10
|
+
"source-map-support/register",
|
|
11
|
+
],
|
|
12
|
+
"mochaExplorer.configFile": ".mocharc.cjs",
|
|
13
|
+
"mochaExplorer.timeout": 999999,
|
|
14
|
+
"mochaExplorer.nodeArgv": ["--conditions", "allow-ff-test-exports"],
|
|
15
|
+
"cSpell.words": ["fluidframework"],
|
|
16
|
+
"editor.defaultFormatter": "biomejs.biome",
|
|
17
|
+
"editor.insertSpaces": false,
|
|
18
|
+
"[json]": { "editor.defaultFormatter": "biomejs.biome" },
|
|
19
|
+
"[javascript]": { "editor.defaultFormatter": "biomejs.biome" },
|
|
20
|
+
"[typescript]": { "editor.defaultFormatter": "biomejs.biome" },
|
|
21
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"folders": [
|
|
3
|
+
{
|
|
4
|
+
"name": "FluidFramework",
|
|
5
|
+
"path": "../../../../"
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
"name": "@fluidframework/tree-agent-ses",
|
|
9
|
+
"path": ".."
|
|
10
|
+
}
|
|
11
|
+
],
|
|
12
|
+
"settings": {
|
|
13
|
+
"search.followSymlinks": false,
|
|
14
|
+
"typescript.preferences.autoImportFileExcludePatterns": [
|
|
15
|
+
"**/node_modules/**/@fluid*/*-previous",
|
|
16
|
+
"**/node_modules/**/@fluid*/*-previous/*"
|
|
17
|
+
],
|
|
18
|
+
"typescript.preferences.importModuleSpecifier": "project-relative",
|
|
19
|
+
"typescript.preferences.preferTypeOnlyAutoImports": true,
|
|
20
|
+
"typescript.tsdk": "FluidFramework\\node_modules\\typescript\\lib"
|
|
21
|
+
}
|
|
22
|
+
}
|
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# @fluidframework/tree-agent-ses
|
|
2
|
+
|
|
3
|
+
Secure edit execution helpers for the `@fluidframework/tree-agent` package backed by the SES runtime.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @fluidframework/tree-agent-ses
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { createSesEditExecutor } from "@fluidframework/tree-agent-ses";
|
|
15
|
+
|
|
16
|
+
const executeEdit = createSesEditExecutor();
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The returned callback can be provided as the `executeEdit` option when constructing a `SharedTreeSemanticAgent` from `@fluidframework/tree-agent`.
|
|
20
|
+
|
|
21
|
+
## Licensing
|
|
22
|
+
|
|
23
|
+
This project is licensed under the [MIT License](./LICENSE).
|
package/alpha.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
|
8
|
+
* Generated by "flub generate entrypoints" in @fluid-tools/build-cli.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export * from "./lib/alpha.js";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
|
|
3
|
+
"extends": "<projectFolder>/../../../common/build/build-common/api-extractor-lint.entrypoint.json",
|
|
4
|
+
"mainEntryPointFilePath": "<projectFolder>/dist/alpha.d.ts"
|
|
5
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
|
|
3
|
+
"extends": "<projectFolder>/../../../common/build/build-common/api-extractor-lint.entrypoint.json",
|
|
4
|
+
"mainEntryPointFilePath": "<projectFolder>/lib/alpha.d.ts"
|
|
5
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
|
|
3
|
+
"extends": "<projectFolder>/../../../common/build/build-common/api-extractor-lint.entrypoint.json",
|
|
4
|
+
"mainEntryPointFilePath": "<projectFolder>/dist/index.d.ts"
|
|
5
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
|
|
3
|
+
"extends": "<projectFolder>/../../../common/build/build-common/api-extractor-lint.entrypoint.json",
|
|
4
|
+
"mainEntryPointFilePath": "<projectFolder>/lib/index.d.ts"
|
|
5
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
|
|
3
|
+
"extends": "<projectFolder>/../../../common/build/build-common/api-extractor-lint.entrypoint.json",
|
|
4
|
+
"mainEntryPointFilePath": "<projectFolder>/dist/public.d.ts"
|
|
5
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
|
|
3
|
+
"extends": "<projectFolder>/../../../common/build/build-common/api-extractor-lint.entrypoint.json",
|
|
4
|
+
"mainEntryPointFilePath": "<projectFolder>/lib/public.d.ts"
|
|
5
|
+
}
|
package/biome.jsonc
ADDED
package/dist/alpha.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
|
8
|
+
* Generated by "flub generate entrypoints" in @fluid-tools/build-cli.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* SES helpers for the {@link @fluidframework/tree-agent#SharedTreeSemanticAgent | SharedTreeSemanticAgent}.
|
|
13
|
+
*
|
|
14
|
+
* @packageDocumentation
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export {
|
|
18
|
+
// #region @alpha APIs
|
|
19
|
+
createSesEditExecutor
|
|
20
|
+
// #endregion
|
|
21
|
+
} from "./index.js";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import "ses";
|
|
6
|
+
import type { SemanticAgentOptions } from "@fluidframework/tree-agent/alpha";
|
|
7
|
+
/**
|
|
8
|
+
* Create an implementation of {@link @fluidframework/tree-agent#SemanticAgentOptions.executeEdit} that uses the SES library
|
|
9
|
+
* to run the provided code in a secure environment.
|
|
10
|
+
* @param options - Optional configuration for the underlying SES compartment and lockdown invocation.
|
|
11
|
+
* @returns A function that can be used as the {@link @fluidframework/tree-agent#SemanticAgentOptions.executeEdit | executeEdit} callback.
|
|
12
|
+
* @remarks This function will call the SES `lockdown` API the first time it is invoked. For best performance, create the executor once during application initialization.
|
|
13
|
+
* @alpha
|
|
14
|
+
*/
|
|
15
|
+
export declare function createSesEditExecutor(options?: {
|
|
16
|
+
compartmentOptions?: {
|
|
17
|
+
globals?: Map<string, unknown>;
|
|
18
|
+
[key: string]: unknown;
|
|
19
|
+
};
|
|
20
|
+
lockdownOptions?: Record<string, unknown>;
|
|
21
|
+
}): SemanticAgentOptions["executeEdit"];
|
|
22
|
+
//# sourceMappingURL=executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../src/executor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,CAAC;AAEb,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAO7E;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE;IAC/C,kBAAkB,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;IAChF,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC1C,GAAG,oBAAoB,CAAC,aAAa,CAAC,CA6CtC"}
|
package/dist/executor.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.createSesEditExecutor = void 0;
|
|
8
|
+
// eslint-disable-next-line import/no-unassigned-import
|
|
9
|
+
require("ses");
|
|
10
|
+
/**
|
|
11
|
+
* Used to track whether the SES `lockdown` function has already been called by this module.
|
|
12
|
+
*/
|
|
13
|
+
const lockdownSymbol = Symbol.for("tree-agent.ses.locked");
|
|
14
|
+
/**
|
|
15
|
+
* Create an implementation of {@link @fluidframework/tree-agent#SemanticAgentOptions.executeEdit} that uses the SES library
|
|
16
|
+
* to run the provided code in a secure environment.
|
|
17
|
+
* @param options - Optional configuration for the underlying SES compartment and lockdown invocation.
|
|
18
|
+
* @returns A function that can be used as the {@link @fluidframework/tree-agent#SemanticAgentOptions.executeEdit | executeEdit} callback.
|
|
19
|
+
* @remarks This function will call the SES `lockdown` API the first time it is invoked. For best performance, create the executor once during application initialization.
|
|
20
|
+
* @alpha
|
|
21
|
+
*/
|
|
22
|
+
function createSesEditExecutor(options) {
|
|
23
|
+
const optionsGlobals = options?.compartmentOptions?.globals ?? new Map();
|
|
24
|
+
if (optionsGlobals.has("context") === true) {
|
|
25
|
+
throw new Error("The 'context' global is reserved and cannot be overridden in the compartment options.");
|
|
26
|
+
}
|
|
27
|
+
if (!(lockdownSymbol in globalThis)) {
|
|
28
|
+
try {
|
|
29
|
+
lockdown(options?.lockdownOptions);
|
|
30
|
+
Object.defineProperty(globalThis, lockdownSymbol, {
|
|
31
|
+
value: true,
|
|
32
|
+
writable: false,
|
|
33
|
+
configurable: false,
|
|
34
|
+
enumerable: false,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
if (toErrorString(error).includes("SES_ALREADY_LOCKED_DOWN")) {
|
|
39
|
+
Object.defineProperty(globalThis, lockdownSymbol, {
|
|
40
|
+
value: true,
|
|
41
|
+
writable: false,
|
|
42
|
+
configurable: false,
|
|
43
|
+
enumerable: false,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return async (context, code) => {
|
|
52
|
+
const compartmentOptions = {
|
|
53
|
+
...options?.compartmentOptions,
|
|
54
|
+
globals: {
|
|
55
|
+
...Object.fromEntries(optionsGlobals),
|
|
56
|
+
context,
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
const compartment = new Compartment({ ...compartmentOptions, __options__: true });
|
|
60
|
+
await compartment.evaluate(code);
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
exports.createSesEditExecutor = createSesEditExecutor;
|
|
64
|
+
/**
|
|
65
|
+
* Stringify an unknown error value.
|
|
66
|
+
*/
|
|
67
|
+
function toErrorString(error) {
|
|
68
|
+
if (error instanceof Error) {
|
|
69
|
+
return error.message;
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
return JSON.stringify(error);
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return String(error);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=executor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../src/executor.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,uDAAuD;AACvD,eAAa;AAIb;;GAEG;AACH,MAAM,cAAc,GAAG,MAAM,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;AAE3D;;;;;;;GAOG;AACH,SAAgB,qBAAqB,CAAC,OAGrC;IACA,MAAM,cAAc,GACnB,OAAO,EAAE,kBAAkB,EAAE,OAAO,IAAI,IAAI,GAAG,EAAmB,CAAC;IAEpE,IAAI,cAAc,CAAC,GAAG,CAAC,SAAS,CAAC,KAAK,IAAI,EAAE,CAAC;QAC5C,MAAM,IAAI,KAAK,CACd,uFAAuF,CACvF,CAAC;IACH,CAAC;IAED,IAAI,CAAC,CAAC,cAAc,IAAI,UAAU,CAAC,EAAE,CAAC;QACrC,IAAI,CAAC;YACJ,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;YACnC,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,cAAc,EAAE;gBACjD,KAAK,EAAE,IAAI;gBACX,QAAQ,EAAE,KAAK;gBACf,YAAY,EAAE,KAAK;gBACnB,UAAU,EAAE,KAAK;aACjB,CAAC,CAAC;QACJ,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACzB,IAAI,aAAa,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,yBAAyB,CAAC,EAAE,CAAC;gBAC9D,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,cAAc,EAAE;oBACjD,KAAK,EAAE,IAAI;oBACX,QAAQ,EAAE,KAAK;oBACf,YAAY,EAAE,KAAK;oBACnB,UAAU,EAAE,KAAK;iBACjB,CAAC,CAAC;YACJ,CAAC;iBAAM,CAAC;gBACP,MAAM,KAAK,CAAC;YACb,CAAC;QACF,CAAC;IACF,CAAC;IAED,OAAO,KAAK,EAAE,OAAgC,EAAE,IAAY,EAAE,EAAE;QAC/D,MAAM,kBAAkB,GAAG;YAC1B,GAAG,OAAO,EAAE,kBAAkB;YAC9B,OAAO,EAAE;gBACR,GAAG,MAAM,CAAC,WAAW,CAAC,cAAc,CAAC;gBACrC,OAAO;aACP;SACD,CAAC;QAEF,MAAM,WAAW,GAAG,IAAI,WAAW,CAAC,EAAE,GAAG,kBAAkB,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;QAClF,MAAM,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC,CAAC;AACH,CAAC;AAhDD,sDAgDC;AAED;;GAEG;AACH,SAAS,aAAa,CAAC,KAAc;IACpC,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC5B,OAAO,KAAK,CAAC,OAAO,CAAC;IACtB,CAAC;IACD,IAAI,CAAC;QACJ,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n// eslint-disable-next-line import/no-unassigned-import\nimport \"ses\";\n\nimport type { SemanticAgentOptions } from \"@fluidframework/tree-agent/alpha\";\n\n/**\n * Used to track whether the SES `lockdown` function has already been called by this module.\n */\nconst lockdownSymbol = Symbol.for(\"tree-agent.ses.locked\");\n\n/**\n * Create an implementation of {@link @fluidframework/tree-agent#SemanticAgentOptions.executeEdit} that uses the SES library\n * to run the provided code in a secure environment.\n * @param options - Optional configuration for the underlying SES compartment and lockdown invocation.\n * @returns A function that can be used as the {@link @fluidframework/tree-agent#SemanticAgentOptions.executeEdit | executeEdit} callback.\n * @remarks This function will call the SES `lockdown` API the first time it is invoked. For best performance, create the executor once during application initialization.\n * @alpha\n */\nexport function createSesEditExecutor(options?: {\n\tcompartmentOptions?: { globals?: Map<string, unknown>; [key: string]: unknown };\n\tlockdownOptions?: Record<string, unknown>;\n}): SemanticAgentOptions[\"executeEdit\"] {\n\tconst optionsGlobals: Map<string, unknown> =\n\t\toptions?.compartmentOptions?.globals ?? new Map<string, unknown>();\n\n\tif (optionsGlobals.has(\"context\") === true) {\n\t\tthrow new Error(\n\t\t\t\"The 'context' global is reserved and cannot be overridden in the compartment options.\",\n\t\t);\n\t}\n\n\tif (!(lockdownSymbol in globalThis)) {\n\t\ttry {\n\t\t\tlockdown(options?.lockdownOptions);\n\t\t\tObject.defineProperty(globalThis, lockdownSymbol, {\n\t\t\t\tvalue: true,\n\t\t\t\twritable: false,\n\t\t\t\tconfigurable: false,\n\t\t\t\tenumerable: false,\n\t\t\t});\n\t\t} catch (error: unknown) {\n\t\t\tif (toErrorString(error).includes(\"SES_ALREADY_LOCKED_DOWN\")) {\n\t\t\t\tObject.defineProperty(globalThis, lockdownSymbol, {\n\t\t\t\t\tvalue: true,\n\t\t\t\t\twritable: false,\n\t\t\t\t\tconfigurable: false,\n\t\t\t\t\tenumerable: false,\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn async (context: Record<string, unknown>, code: string) => {\n\t\tconst compartmentOptions = {\n\t\t\t...options?.compartmentOptions,\n\t\t\tglobals: {\n\t\t\t\t...Object.fromEntries(optionsGlobals),\n\t\t\t\tcontext,\n\t\t\t},\n\t\t};\n\n\t\tconst compartment = new Compartment({ ...compartmentOptions, __options__: true });\n\t\tawait compartment.evaluate(code);\n\t};\n}\n\n/**\n * Stringify an unknown error value.\n */\nfunction toErrorString(error: unknown): string {\n\tif (error instanceof Error) {\n\t\treturn error.message;\n\t}\n\ttry {\n\t\treturn JSON.stringify(error);\n\t} catch {\n\t\treturn String(error);\n\t}\n}\n"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* SES helpers for the {@link @fluidframework/tree-agent#SharedTreeSemanticAgent | SharedTreeSemanticAgent}.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
export { createSesEditExecutor } from "./executor.js";
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.createSesEditExecutor = void 0;
|
|
8
|
+
/**
|
|
9
|
+
* SES helpers for the {@link @fluidframework/tree-agent#SharedTreeSemanticAgent | SharedTreeSemanticAgent}.
|
|
10
|
+
*
|
|
11
|
+
* @packageDocumentation
|
|
12
|
+
*/
|
|
13
|
+
var executor_js_1 = require("./executor.js");
|
|
14
|
+
Object.defineProperty(exports, "createSesEditExecutor", { enumerable: true, get: function () { return executor_js_1.createSesEditExecutor; } });
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;;;GAIG;AAEH,6CAAsD;AAA7C,oHAAA,qBAAqB,OAAA","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * SES helpers for the {@link @fluidframework/tree-agent#SharedTreeSemanticAgent | SharedTreeSemanticAgent}.\n *\n * @packageDocumentation\n */\n\nexport { createSesEditExecutor } from \"./executor.js\";\n"]}
|
package/dist/public.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
|
8
|
+
* Generated by "flub generate entrypoints" in @fluid-tools/build-cli.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* SES helpers for the {@link @fluidframework/tree-agent#SharedTreeSemanticAgent | SharedTreeSemanticAgent}.
|
|
13
|
+
*
|
|
14
|
+
* @packageDocumentation
|
|
15
|
+
*/export {}
|
|
16
|
+
|
package/internal.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
|
8
|
+
* Generated by "flub generate entrypoints" in @fluid-tools/build-cli.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export * from "./lib/index.js";
|
package/lib/alpha.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
|
8
|
+
* Generated by "flub generate entrypoints" in @fluid-tools/build-cli.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* SES helpers for the {@link @fluidframework/tree-agent#SharedTreeSemanticAgent | SharedTreeSemanticAgent}.
|
|
13
|
+
*
|
|
14
|
+
* @packageDocumentation
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export {
|
|
18
|
+
// #region @alpha APIs
|
|
19
|
+
createSesEditExecutor
|
|
20
|
+
// #endregion
|
|
21
|
+
} from "./index.js";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import "ses";
|
|
6
|
+
import type { SemanticAgentOptions } from "@fluidframework/tree-agent/alpha";
|
|
7
|
+
/**
|
|
8
|
+
* Create an implementation of {@link @fluidframework/tree-agent#SemanticAgentOptions.executeEdit} that uses the SES library
|
|
9
|
+
* to run the provided code in a secure environment.
|
|
10
|
+
* @param options - Optional configuration for the underlying SES compartment and lockdown invocation.
|
|
11
|
+
* @returns A function that can be used as the {@link @fluidframework/tree-agent#SemanticAgentOptions.executeEdit | executeEdit} callback.
|
|
12
|
+
* @remarks This function will call the SES `lockdown` API the first time it is invoked. For best performance, create the executor once during application initialization.
|
|
13
|
+
* @alpha
|
|
14
|
+
*/
|
|
15
|
+
export declare function createSesEditExecutor(options?: {
|
|
16
|
+
compartmentOptions?: {
|
|
17
|
+
globals?: Map<string, unknown>;
|
|
18
|
+
[key: string]: unknown;
|
|
19
|
+
};
|
|
20
|
+
lockdownOptions?: Record<string, unknown>;
|
|
21
|
+
}): SemanticAgentOptions["executeEdit"];
|
|
22
|
+
//# sourceMappingURL=executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../src/executor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,CAAC;AAEb,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAO7E;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE;IAC/C,kBAAkB,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;IAChF,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC1C,GAAG,oBAAoB,CAAC,aAAa,CAAC,CA6CtC"}
|
package/lib/executor.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
// eslint-disable-next-line import/no-unassigned-import
|
|
6
|
+
import "ses";
|
|
7
|
+
/**
|
|
8
|
+
* Used to track whether the SES `lockdown` function has already been called by this module.
|
|
9
|
+
*/
|
|
10
|
+
const lockdownSymbol = Symbol.for("tree-agent.ses.locked");
|
|
11
|
+
/**
|
|
12
|
+
* Create an implementation of {@link @fluidframework/tree-agent#SemanticAgentOptions.executeEdit} that uses the SES library
|
|
13
|
+
* to run the provided code in a secure environment.
|
|
14
|
+
* @param options - Optional configuration for the underlying SES compartment and lockdown invocation.
|
|
15
|
+
* @returns A function that can be used as the {@link @fluidframework/tree-agent#SemanticAgentOptions.executeEdit | executeEdit} callback.
|
|
16
|
+
* @remarks This function will call the SES `lockdown` API the first time it is invoked. For best performance, create the executor once during application initialization.
|
|
17
|
+
* @alpha
|
|
18
|
+
*/
|
|
19
|
+
export function createSesEditExecutor(options) {
|
|
20
|
+
const optionsGlobals = options?.compartmentOptions?.globals ?? new Map();
|
|
21
|
+
if (optionsGlobals.has("context") === true) {
|
|
22
|
+
throw new Error("The 'context' global is reserved and cannot be overridden in the compartment options.");
|
|
23
|
+
}
|
|
24
|
+
if (!(lockdownSymbol in globalThis)) {
|
|
25
|
+
try {
|
|
26
|
+
lockdown(options?.lockdownOptions);
|
|
27
|
+
Object.defineProperty(globalThis, lockdownSymbol, {
|
|
28
|
+
value: true,
|
|
29
|
+
writable: false,
|
|
30
|
+
configurable: false,
|
|
31
|
+
enumerable: false,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
if (toErrorString(error).includes("SES_ALREADY_LOCKED_DOWN")) {
|
|
36
|
+
Object.defineProperty(globalThis, lockdownSymbol, {
|
|
37
|
+
value: true,
|
|
38
|
+
writable: false,
|
|
39
|
+
configurable: false,
|
|
40
|
+
enumerable: false,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return async (context, code) => {
|
|
49
|
+
const compartmentOptions = {
|
|
50
|
+
...options?.compartmentOptions,
|
|
51
|
+
globals: {
|
|
52
|
+
...Object.fromEntries(optionsGlobals),
|
|
53
|
+
context,
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
const compartment = new Compartment({ ...compartmentOptions, __options__: true });
|
|
57
|
+
await compartment.evaluate(code);
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Stringify an unknown error value.
|
|
62
|
+
*/
|
|
63
|
+
function toErrorString(error) {
|
|
64
|
+
if (error instanceof Error) {
|
|
65
|
+
return error.message;
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
return JSON.stringify(error);
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return String(error);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=executor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../src/executor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,uDAAuD;AACvD,OAAO,KAAK,CAAC;AAIb;;GAEG;AACH,MAAM,cAAc,GAAG,MAAM,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;AAE3D;;;;;;;GAOG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAGrC;IACA,MAAM,cAAc,GACnB,OAAO,EAAE,kBAAkB,EAAE,OAAO,IAAI,IAAI,GAAG,EAAmB,CAAC;IAEpE,IAAI,cAAc,CAAC,GAAG,CAAC,SAAS,CAAC,KAAK,IAAI,EAAE,CAAC;QAC5C,MAAM,IAAI,KAAK,CACd,uFAAuF,CACvF,CAAC;IACH,CAAC;IAED,IAAI,CAAC,CAAC,cAAc,IAAI,UAAU,CAAC,EAAE,CAAC;QACrC,IAAI,CAAC;YACJ,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;YACnC,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,cAAc,EAAE;gBACjD,KAAK,EAAE,IAAI;gBACX,QAAQ,EAAE,KAAK;gBACf,YAAY,EAAE,KAAK;gBACnB,UAAU,EAAE,KAAK;aACjB,CAAC,CAAC;QACJ,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACzB,IAAI,aAAa,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,yBAAyB,CAAC,EAAE,CAAC;gBAC9D,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,cAAc,EAAE;oBACjD,KAAK,EAAE,IAAI;oBACX,QAAQ,EAAE,KAAK;oBACf,YAAY,EAAE,KAAK;oBACnB,UAAU,EAAE,KAAK;iBACjB,CAAC,CAAC;YACJ,CAAC;iBAAM,CAAC;gBACP,MAAM,KAAK,CAAC;YACb,CAAC;QACF,CAAC;IACF,CAAC;IAED,OAAO,KAAK,EAAE,OAAgC,EAAE,IAAY,EAAE,EAAE;QAC/D,MAAM,kBAAkB,GAAG;YAC1B,GAAG,OAAO,EAAE,kBAAkB;YAC9B,OAAO,EAAE;gBACR,GAAG,MAAM,CAAC,WAAW,CAAC,cAAc,CAAC;gBACrC,OAAO;aACP;SACD,CAAC;QAEF,MAAM,WAAW,GAAG,IAAI,WAAW,CAAC,EAAE,GAAG,kBAAkB,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;QAClF,MAAM,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAS,aAAa,CAAC,KAAc;IACpC,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC5B,OAAO,KAAK,CAAC,OAAO,CAAC;IACtB,CAAC;IACD,IAAI,CAAC;QACJ,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n// eslint-disable-next-line import/no-unassigned-import\nimport \"ses\";\n\nimport type { SemanticAgentOptions } from \"@fluidframework/tree-agent/alpha\";\n\n/**\n * Used to track whether the SES `lockdown` function has already been called by this module.\n */\nconst lockdownSymbol = Symbol.for(\"tree-agent.ses.locked\");\n\n/**\n * Create an implementation of {@link @fluidframework/tree-agent#SemanticAgentOptions.executeEdit} that uses the SES library\n * to run the provided code in a secure environment.\n * @param options - Optional configuration for the underlying SES compartment and lockdown invocation.\n * @returns A function that can be used as the {@link @fluidframework/tree-agent#SemanticAgentOptions.executeEdit | executeEdit} callback.\n * @remarks This function will call the SES `lockdown` API the first time it is invoked. For best performance, create the executor once during application initialization.\n * @alpha\n */\nexport function createSesEditExecutor(options?: {\n\tcompartmentOptions?: { globals?: Map<string, unknown>; [key: string]: unknown };\n\tlockdownOptions?: Record<string, unknown>;\n}): SemanticAgentOptions[\"executeEdit\"] {\n\tconst optionsGlobals: Map<string, unknown> =\n\t\toptions?.compartmentOptions?.globals ?? new Map<string, unknown>();\n\n\tif (optionsGlobals.has(\"context\") === true) {\n\t\tthrow new Error(\n\t\t\t\"The 'context' global is reserved and cannot be overridden in the compartment options.\",\n\t\t);\n\t}\n\n\tif (!(lockdownSymbol in globalThis)) {\n\t\ttry {\n\t\t\tlockdown(options?.lockdownOptions);\n\t\t\tObject.defineProperty(globalThis, lockdownSymbol, {\n\t\t\t\tvalue: true,\n\t\t\t\twritable: false,\n\t\t\t\tconfigurable: false,\n\t\t\t\tenumerable: false,\n\t\t\t});\n\t\t} catch (error: unknown) {\n\t\t\tif (toErrorString(error).includes(\"SES_ALREADY_LOCKED_DOWN\")) {\n\t\t\t\tObject.defineProperty(globalThis, lockdownSymbol, {\n\t\t\t\t\tvalue: true,\n\t\t\t\t\twritable: false,\n\t\t\t\t\tconfigurable: false,\n\t\t\t\t\tenumerable: false,\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn async (context: Record<string, unknown>, code: string) => {\n\t\tconst compartmentOptions = {\n\t\t\t...options?.compartmentOptions,\n\t\t\tglobals: {\n\t\t\t\t...Object.fromEntries(optionsGlobals),\n\t\t\t\tcontext,\n\t\t\t},\n\t\t};\n\n\t\tconst compartment = new Compartment({ ...compartmentOptions, __options__: true });\n\t\tawait compartment.evaluate(code);\n\t};\n}\n\n/**\n * Stringify an unknown error value.\n */\nfunction toErrorString(error: unknown): string {\n\tif (error instanceof Error) {\n\t\treturn error.message;\n\t}\n\ttry {\n\t\treturn JSON.stringify(error);\n\t} catch {\n\t\treturn String(error);\n\t}\n}\n"]}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* SES helpers for the {@link @fluidframework/tree-agent#SharedTreeSemanticAgent | SharedTreeSemanticAgent}.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
export { createSesEditExecutor } from "./executor.js";
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* SES helpers for the {@link @fluidframework/tree-agent#SharedTreeSemanticAgent | SharedTreeSemanticAgent}.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
export { createSesEditExecutor } from "./executor.js";
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * SES helpers for the {@link @fluidframework/tree-agent#SharedTreeSemanticAgent | SharedTreeSemanticAgent}.\n *\n * @packageDocumentation\n */\n\nexport { createSesEditExecutor } from \"./executor.js\";\n"]}
|
package/lib/public.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
|
8
|
+
* Generated by "flub generate entrypoints" in @fluid-tools/build-cli.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* SES helpers for the {@link @fluidframework/tree-agent#SharedTreeSemanticAgent | SharedTreeSemanticAgent}.
|
|
13
|
+
*
|
|
14
|
+
* @packageDocumentation
|
|
15
|
+
*/export {}
|
|
16
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fluidframework/tree-agent-ses",
|
|
3
|
+
"version": "2.63.0-359962",
|
|
4
|
+
"description": "SES integration helpers for @fluidframework/tree-agent",
|
|
5
|
+
"homepage": "https://fluidframework.com",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/microsoft/FluidFramework.git",
|
|
9
|
+
"directory": "packages/framework/tree-agent-ses"
|
|
10
|
+
},
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"author": "Microsoft and contributors",
|
|
13
|
+
"sideEffects": false,
|
|
14
|
+
"type": "module",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"import": {
|
|
18
|
+
"types": "./lib/public.d.ts",
|
|
19
|
+
"default": "./lib/index.js"
|
|
20
|
+
},
|
|
21
|
+
"require": {
|
|
22
|
+
"types": "./dist/public.d.ts",
|
|
23
|
+
"default": "./dist/index.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"./alpha": {
|
|
27
|
+
"import": {
|
|
28
|
+
"types": "./lib/alpha.d.ts",
|
|
29
|
+
"default": "./lib/index.js"
|
|
30
|
+
},
|
|
31
|
+
"require": {
|
|
32
|
+
"types": "./dist/alpha.d.ts",
|
|
33
|
+
"default": "./dist/index.js"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"./internal": {
|
|
37
|
+
"import": {
|
|
38
|
+
"types": "./lib/index.d.ts",
|
|
39
|
+
"default": "./lib/index.js"
|
|
40
|
+
},
|
|
41
|
+
"require": {
|
|
42
|
+
"types": "./dist/index.d.ts",
|
|
43
|
+
"default": "./dist/index.js"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"main": "lib/index.js",
|
|
48
|
+
"types": "lib/public.d.ts",
|
|
49
|
+
"c8": {
|
|
50
|
+
"all": true,
|
|
51
|
+
"cache-dir": "nyc/.cache",
|
|
52
|
+
"exclude": [
|
|
53
|
+
"src/test/**/*.*ts",
|
|
54
|
+
"dist/test/**/*.*js",
|
|
55
|
+
"lib/test/**/*.*js"
|
|
56
|
+
],
|
|
57
|
+
"exclude-after-remap": false,
|
|
58
|
+
"include": [
|
|
59
|
+
"src/**/*.*ts",
|
|
60
|
+
"dist/**/*.*js",
|
|
61
|
+
"lib/**/*.*js"
|
|
62
|
+
],
|
|
63
|
+
"report-dir": "nyc/report",
|
|
64
|
+
"reporter": [
|
|
65
|
+
"cobertura",
|
|
66
|
+
"html",
|
|
67
|
+
"text"
|
|
68
|
+
],
|
|
69
|
+
"temp-directory": "nyc/.nyc_output"
|
|
70
|
+
},
|
|
71
|
+
"dependencies": {
|
|
72
|
+
"@fluidframework/tree-agent": "2.63.0-359962",
|
|
73
|
+
"ses": "^1.14.0"
|
|
74
|
+
},
|
|
75
|
+
"devDependencies": {
|
|
76
|
+
"@arethetypeswrong/cli": "^0.17.1",
|
|
77
|
+
"@biomejs/biome": "~1.9.3",
|
|
78
|
+
"@fluid-internal/mocha-test-setup": "2.63.0-359962",
|
|
79
|
+
"@fluid-tools/build-cli": "^0.58.3",
|
|
80
|
+
"@fluidframework/build-common": "^2.0.3",
|
|
81
|
+
"@fluidframework/build-tools": "^0.58.3",
|
|
82
|
+
"@fluidframework/eslint-config-fluid": "^6.0.0",
|
|
83
|
+
"@fluidframework/tree": "2.63.0-359962",
|
|
84
|
+
"@microsoft/api-extractor": "7.52.11",
|
|
85
|
+
"@types/mocha": "^10.0.10",
|
|
86
|
+
"@types/node": "^18.19.0",
|
|
87
|
+
"c8": "^10.1.3",
|
|
88
|
+
"concurrently": "^8.2.1",
|
|
89
|
+
"copyfiles": "^2.4.1",
|
|
90
|
+
"cross-env": "^7.0.3",
|
|
91
|
+
"eslint": "~8.55.0",
|
|
92
|
+
"eslint-config-prettier": "~9.0.0",
|
|
93
|
+
"mocha": "^10.8.2",
|
|
94
|
+
"mocha-multi-reporters": "^1.5.1",
|
|
95
|
+
"prettier": "~3.0.3",
|
|
96
|
+
"rimraf": "^4.4.0",
|
|
97
|
+
"typescript": "~5.4.5"
|
|
98
|
+
},
|
|
99
|
+
"fluidBuild": {
|
|
100
|
+
"tasks": {
|
|
101
|
+
"build:esnext": [
|
|
102
|
+
"...",
|
|
103
|
+
"typetests:gen"
|
|
104
|
+
],
|
|
105
|
+
"tsc": [
|
|
106
|
+
"...",
|
|
107
|
+
"typetests:gen"
|
|
108
|
+
]
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
"typeValidation": {
|
|
112
|
+
"disabled": true,
|
|
113
|
+
"broken": {},
|
|
114
|
+
"entrypoint": "internal"
|
|
115
|
+
},
|
|
116
|
+
"scripts": {
|
|
117
|
+
"api": "fluid-build . --task api",
|
|
118
|
+
"api-extractor:commonjs": "flub generate entrypoints --outFileLegacyBeta legacy --outDir ./dist",
|
|
119
|
+
"api-extractor:esnext": "flub generate entrypoints --outFileLegacyBeta legacy --outDir ./lib --node10TypeCompat",
|
|
120
|
+
"build": "fluid-build . --task build",
|
|
121
|
+
"build:commonjs": "fluid-build . --task commonjs",
|
|
122
|
+
"build:compile": "fluid-build . --task compile",
|
|
123
|
+
"build:docs": "api-extractor run --local",
|
|
124
|
+
"build:esnext": "tsc --project ./tsconfig.json",
|
|
125
|
+
"build:test": "npm run build:test:esm && npm run build:test:cjs",
|
|
126
|
+
"build:test:cjs": "fluid-tsc commonjs --project ./src/test/tsconfig.cjs.json",
|
|
127
|
+
"build:test:esm": "tsc --project ./src/test/tsconfig.json",
|
|
128
|
+
"check:are-the-types-wrong": "attw --pack . --profile node16",
|
|
129
|
+
"check:biome": "biome check .",
|
|
130
|
+
"check:exports": "concurrently \"npm:check:exports:*\"",
|
|
131
|
+
"check:exports:bundle-release-tags": "api-extractor run --config api-extractor/api-extractor-lint-bundle.json",
|
|
132
|
+
"check:exports:cjs:alpha": "api-extractor run --config api-extractor/api-extractor-lint-alpha.cjs.json",
|
|
133
|
+
"check:exports:cjs:index": "api-extractor run --config api-extractor/api-extractor-lint-index.cjs.json",
|
|
134
|
+
"check:exports:cjs:public": "api-extractor run --config api-extractor/api-extractor-lint-public.cjs.json",
|
|
135
|
+
"check:exports:esm:alpha": "api-extractor run --config api-extractor/api-extractor-lint-alpha.esm.json",
|
|
136
|
+
"check:exports:esm:index": "api-extractor run --config api-extractor/api-extractor-lint-index.esm.json",
|
|
137
|
+
"check:exports:esm:public": "api-extractor run --config api-extractor/api-extractor-lint-public.esm.json",
|
|
138
|
+
"check:format": "npm run check:biome",
|
|
139
|
+
"ci:build:docs": "api-extractor run",
|
|
140
|
+
"clean": "rimraf --glob dist lib {alpha,beta,internal,legacy}.d.ts \"**/*.tsbuildinfo\" \"**/*.build.log\" _api-extractor-temp nyc",
|
|
141
|
+
"eslint": "eslint --format stylish src",
|
|
142
|
+
"eslint:fix": "eslint --format stylish src --fix --fix-type problem,suggestion,layout",
|
|
143
|
+
"format": "npm run format:biome",
|
|
144
|
+
"format:biome": "biome check . --write",
|
|
145
|
+
"lint": "fluid-build . --task lint",
|
|
146
|
+
"lint:fix": "fluid-build . --task eslint:fix --task format",
|
|
147
|
+
"test": "npm run test:mocha",
|
|
148
|
+
"test:coverage": "c8 npm test",
|
|
149
|
+
"test:mocha": "npm run test:mocha:esm && echo skipping cjs to avoid overhead - npm run test:mocha:cjs",
|
|
150
|
+
"test:mocha:cjs": "cross-env FLUID_TEST_MODULE_SYSTEM=CJS mocha",
|
|
151
|
+
"test:mocha:esm": "mocha",
|
|
152
|
+
"test:mocha:verbose": "cross-env FLUID_TEST_VERBOSE=1 npm run test:mocha",
|
|
153
|
+
"tsc": "fluid-tsc commonjs --project ./tsconfig.cjs.json && copyfiles -f ../../../common/build/build-common/src/cjs/package.json ./dist",
|
|
154
|
+
"typetests:gen": "flub generate typetests --dir . -v",
|
|
155
|
+
"typetests:prepare": "flub typetests --dir . --reset --previous --normalize"
|
|
156
|
+
}
|
|
157
|
+
}
|
package/src/executor.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// eslint-disable-next-line import/no-unassigned-import
|
|
7
|
+
import "ses";
|
|
8
|
+
|
|
9
|
+
import type { SemanticAgentOptions } from "@fluidframework/tree-agent/alpha";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Used to track whether the SES `lockdown` function has already been called by this module.
|
|
13
|
+
*/
|
|
14
|
+
const lockdownSymbol = Symbol.for("tree-agent.ses.locked");
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Create an implementation of {@link @fluidframework/tree-agent#SemanticAgentOptions.executeEdit} that uses the SES library
|
|
18
|
+
* to run the provided code in a secure environment.
|
|
19
|
+
* @param options - Optional configuration for the underlying SES compartment and lockdown invocation.
|
|
20
|
+
* @returns A function that can be used as the {@link @fluidframework/tree-agent#SemanticAgentOptions.executeEdit | executeEdit} callback.
|
|
21
|
+
* @remarks This function will call the SES `lockdown` API the first time it is invoked. For best performance, create the executor once during application initialization.
|
|
22
|
+
* @alpha
|
|
23
|
+
*/
|
|
24
|
+
export function createSesEditExecutor(options?: {
|
|
25
|
+
compartmentOptions?: { globals?: Map<string, unknown>; [key: string]: unknown };
|
|
26
|
+
lockdownOptions?: Record<string, unknown>;
|
|
27
|
+
}): SemanticAgentOptions["executeEdit"] {
|
|
28
|
+
const optionsGlobals: Map<string, unknown> =
|
|
29
|
+
options?.compartmentOptions?.globals ?? new Map<string, unknown>();
|
|
30
|
+
|
|
31
|
+
if (optionsGlobals.has("context") === true) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
"The 'context' global is reserved and cannot be overridden in the compartment options.",
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (!(lockdownSymbol in globalThis)) {
|
|
38
|
+
try {
|
|
39
|
+
lockdown(options?.lockdownOptions);
|
|
40
|
+
Object.defineProperty(globalThis, lockdownSymbol, {
|
|
41
|
+
value: true,
|
|
42
|
+
writable: false,
|
|
43
|
+
configurable: false,
|
|
44
|
+
enumerable: false,
|
|
45
|
+
});
|
|
46
|
+
} catch (error: unknown) {
|
|
47
|
+
if (toErrorString(error).includes("SES_ALREADY_LOCKED_DOWN")) {
|
|
48
|
+
Object.defineProperty(globalThis, lockdownSymbol, {
|
|
49
|
+
value: true,
|
|
50
|
+
writable: false,
|
|
51
|
+
configurable: false,
|
|
52
|
+
enumerable: false,
|
|
53
|
+
});
|
|
54
|
+
} else {
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return async (context: Record<string, unknown>, code: string) => {
|
|
61
|
+
const compartmentOptions = {
|
|
62
|
+
...options?.compartmentOptions,
|
|
63
|
+
globals: {
|
|
64
|
+
...Object.fromEntries(optionsGlobals),
|
|
65
|
+
context,
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const compartment = new Compartment({ ...compartmentOptions, __options__: true });
|
|
70
|
+
await compartment.evaluate(code);
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Stringify an unknown error value.
|
|
76
|
+
*/
|
|
77
|
+
function toErrorString(error: unknown): string {
|
|
78
|
+
if (error instanceof Error) {
|
|
79
|
+
return error.message;
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
return JSON.stringify(error);
|
|
83
|
+
} catch {
|
|
84
|
+
return String(error);
|
|
85
|
+
}
|
|
86
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* SES helpers for the {@link @fluidframework/tree-agent#SharedTreeSemanticAgent | SharedTreeSemanticAgent}.
|
|
8
|
+
*
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export { createSesEditExecutor } from "./executor.js";
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../../common/build/build-common/tsconfig.node16.json",
|
|
3
|
+
"include": ["src/**/*"],
|
|
4
|
+
"exclude": ["src/test/**/*"],
|
|
5
|
+
"compilerOptions": {
|
|
6
|
+
"rootDir": "./src",
|
|
7
|
+
"outDir": "./lib",
|
|
8
|
+
"noImplicitAny": true,
|
|
9
|
+
"preserveConstEnums": true,
|
|
10
|
+
"exactOptionalPropertyTypes": false,
|
|
11
|
+
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
|
12
|
+
"skipLibCheck": true,
|
|
13
|
+
},
|
|
14
|
+
}
|
package/tsdoc.json
ADDED