@fluidframework/tree-agent-ses 2.71.0 → 2.73.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/.eslintrc.cjs CHANGED
@@ -10,7 +10,7 @@ module.exports = {
10
10
  },
11
11
  rules: {
12
12
  // Allow reaching into FluidFramework package paths that end with alpha, beta, legacy, or internal
13
- "import/no-internal-modules": [
13
+ "import-x/no-internal-modules": [
14
14
  "error",
15
15
  {
16
16
  allow: [
@@ -29,7 +29,7 @@ module.exports = {
29
29
  project: ["./src/test/tsconfig.json"],
30
30
  },
31
31
  rules: {
32
- "import/no-internal-modules": [
32
+ "import-x/no-internal-modules": [
33
33
  "error",
34
34
  {
35
35
  allow: [
@@ -41,7 +41,7 @@ module.exports = {
41
41
  ],
42
42
  },
43
43
  ],
44
- "import/no-unresolved": "off",
44
+ "import-x/no-unresolved": "off",
45
45
  "@typescript-eslint/no-unsafe-assignment": "off",
46
46
  "@typescript-eslint/no-unsafe-call": "off",
47
47
  "@typescript-eslint/no-unsafe-member-access": "off",
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @fluidframework/tree-agent-ses
2
2
 
3
+ ## 2.73.0
4
+
5
+ Dependency updates only.
6
+
7
+ ## 2.72.0
8
+
9
+ Dependency updates only.
10
+
3
11
  ## 2.71.0
4
12
 
5
13
  Dependency updates only.
@@ -3,7 +3,8 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  import "ses";
6
- import type { AsynchronousEditor } from "@fluidframework/tree-agent/alpha";
6
+ import type { ImplicitFieldSchema } from "@fluidframework/tree";
7
+ import { type AsynchronousEditor } from "@fluidframework/tree-agent/alpha";
7
8
  /**
8
9
  * Create an implementation of {@link @fluidframework/tree-agent#SemanticAgentOptions.executeEdit} that uses the SES library
9
10
  * to run the provided code in a secure environment.
@@ -12,11 +13,11 @@ import type { AsynchronousEditor } from "@fluidframework/tree-agent/alpha";
12
13
  * @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
14
  * @alpha
14
15
  */
15
- export declare function createSesEditExecutor(options?: {
16
+ export declare function createSesEditExecutor<TSchema extends ImplicitFieldSchema>(options?: {
16
17
  compartmentOptions?: {
17
18
  globals?: Map<string, unknown>;
18
19
  [key: string]: unknown;
19
20
  };
20
21
  lockdownOptions?: Record<string, unknown>;
21
- }): AsynchronousEditor;
22
+ }): AsynchronousEditor<TSchema>;
22
23
  //# sourceMappingURL=executor.d.ts.map
@@ -1 +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,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAO3E;;;;;;;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,kBAAkB,CA6CrB"}
1
+ {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../src/executor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,CAAC;AAEb,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAEN,KAAK,kBAAkB,EAEvB,MAAM,kCAAkC,CAAC;AAO1C;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,SAAS,mBAAmB,EAAE,OAAO,CAAC,EAAE;IACpF,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,kBAAkB,CAAC,OAAO,CAAC,CA6C9B"}
package/dist/executor.js CHANGED
@@ -5,8 +5,9 @@
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.createSesEditExecutor = void 0;
8
- // eslint-disable-next-line import/no-unassigned-import
8
+ // eslint-disable-next-line import-x/no-unassigned-import
9
9
  require("ses");
10
+ const alpha_1 = require("@fluidframework/tree-agent/alpha");
10
11
  /**
11
12
  * Used to track whether the SES `lockdown` function has already been called by this module.
12
13
  */
@@ -48,12 +49,12 @@ function createSesEditExecutor(options) {
48
49
  }
49
50
  }
50
51
  }
51
- return async (context, code) => {
52
+ return async (tree, code) => {
52
53
  const compartmentOptions = {
53
54
  ...options?.compartmentOptions,
54
55
  globals: {
55
56
  ...Object.fromEntries(optionsGlobals),
56
- context,
57
+ context: (0, alpha_1.createContext)(tree),
57
58
  },
58
59
  };
59
60
  const compartment = new Compartment({ ...compartmentOptions, __options__: true });
@@ -1 +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,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C,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 { AsynchronousEditor } 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}): AsynchronousEditor {\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"]}
1
+ {"version":3,"file":"executor.js","sourceRoot":"","sources":["../src/executor.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,yDAAyD;AACzD,eAAa;AAGb,4DAI0C;AAE1C;;GAEG;AACH,MAAM,cAAc,GAAG,MAAM,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;AAE3D;;;;;;;GAOG;AACH,SAAgB,qBAAqB,CAAsC,OAG1E;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;gB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,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-x/no-unassigned-import\nimport \"ses\";\n\nimport type { ImplicitFieldSchema } from \"@fluidframework/tree\";\nimport {\n\tcreateContext,\n\ttype AsynchronousEditor,\n\ttype ViewOrTree,\n} 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<TSchema extends ImplicitFieldSchema>(options?: {\n\tcompartmentOptions?: { globals?: Map<string, unknown>; [key: string]: unknown };\n\tlockdownOptions?: Record<string, unknown>;\n}): AsynchronousEditor<TSchema> {\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 (tree: ViewOrTree<TSchema>, 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: createContext(tree),\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/executor.d.ts CHANGED
@@ -3,7 +3,8 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  import "ses";
6
- import type { AsynchronousEditor } from "@fluidframework/tree-agent/alpha";
6
+ import type { ImplicitFieldSchema } from "@fluidframework/tree";
7
+ import { type AsynchronousEditor } from "@fluidframework/tree-agent/alpha";
7
8
  /**
8
9
  * Create an implementation of {@link @fluidframework/tree-agent#SemanticAgentOptions.executeEdit} that uses the SES library
9
10
  * to run the provided code in a secure environment.
@@ -12,11 +13,11 @@ import type { AsynchronousEditor } from "@fluidframework/tree-agent/alpha";
12
13
  * @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
14
  * @alpha
14
15
  */
15
- export declare function createSesEditExecutor(options?: {
16
+ export declare function createSesEditExecutor<TSchema extends ImplicitFieldSchema>(options?: {
16
17
  compartmentOptions?: {
17
18
  globals?: Map<string, unknown>;
18
19
  [key: string]: unknown;
19
20
  };
20
21
  lockdownOptions?: Record<string, unknown>;
21
- }): AsynchronousEditor;
22
+ }): AsynchronousEditor<TSchema>;
22
23
  //# sourceMappingURL=executor.d.ts.map
@@ -1 +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,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAO3E;;;;;;;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,kBAAkB,CA6CrB"}
1
+ {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../src/executor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,CAAC;AAEb,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAEN,KAAK,kBAAkB,EAEvB,MAAM,kCAAkC,CAAC;AAO1C;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,SAAS,mBAAmB,EAAE,OAAO,CAAC,EAAE;IACpF,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,kBAAkB,CAAC,OAAO,CAAC,CA6C9B"}
package/lib/executor.js CHANGED
@@ -2,8 +2,9 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- // eslint-disable-next-line import/no-unassigned-import
5
+ // eslint-disable-next-line import-x/no-unassigned-import
6
6
  import "ses";
7
+ import { createContext, } from "@fluidframework/tree-agent/alpha";
7
8
  /**
8
9
  * Used to track whether the SES `lockdown` function has already been called by this module.
9
10
  */
@@ -45,12 +46,12 @@ export function createSesEditExecutor(options) {
45
46
  }
46
47
  }
47
48
  }
48
- return async (context, code) => {
49
+ return async (tree, code) => {
49
50
  const compartmentOptions = {
50
51
  ...options?.compartmentOptions,
51
52
  globals: {
52
53
  ...Object.fromEntries(optionsGlobals),
53
- context,
54
+ context: createContext(tree),
54
55
  },
55
56
  };
56
57
  const compartment = new Compartment({ ...compartmentOptions, __options__: true });
@@ -1 +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 { AsynchronousEditor } 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}): AsynchronousEditor {\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"]}
1
+ {"version":3,"file":"executor.js","sourceRoot":"","sources":["../src/executor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,yDAAyD;AACzD,OAAO,KAAK,CAAC;AAGb,OAAO,EACN,aAAa,GAGb,MAAM,kCAAkC,CAAC;AAE1C;;GAEG;AACH,MAAM,cAAc,GAAG,MAAM,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;AAE3D;;;;;;;GAOG;AACH,MAAM,UAAU,qBAAqB,CAAsC,OAG1E;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,IAAyB,EAAE,IAAY,EAAE,EAAE;QACxD,MAAM,kBAAkB,GAAG;YAC1B,GAAG,OAAO,EAAE,kBAAkB;YAC9B,OAAO,EAAE;gBACR,GAAG,MAAM,CAAC,WAAW,CAAC,cAAc,CAAC;gBACrC,OAAO,EAAE,aAAa,CAAC,IAAI,CAAC;aAC5B;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-x/no-unassigned-import\nimport \"ses\";\n\nimport type { ImplicitFieldSchema } from \"@fluidframework/tree\";\nimport {\n\tcreateContext,\n\ttype AsynchronousEditor,\n\ttype ViewOrTree,\n} 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<TSchema extends ImplicitFieldSchema>(options?: {\n\tcompartmentOptions?: { globals?: Map<string, unknown>; [key: string]: unknown };\n\tlockdownOptions?: Record<string, unknown>;\n}): AsynchronousEditor<TSchema> {\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 (tree: ViewOrTree<TSchema>, 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: createContext(tree),\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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/tree-agent-ses",
3
- "version": "2.71.0",
3
+ "version": "2.73.0",
4
4
  "description": "SES integration helpers for @fluidframework/tree-agent",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -69,18 +69,18 @@
69
69
  "temp-directory": "nyc/.nyc_output"
70
70
  },
71
71
  "dependencies": {
72
- "@fluidframework/tree-agent": "~2.71.0",
72
+ "@fluidframework/tree-agent": "~2.73.0",
73
73
  "ses": "^1.14.0"
74
74
  },
75
75
  "devDependencies": {
76
76
  "@arethetypeswrong/cli": "^0.17.1",
77
77
  "@biomejs/biome": "~1.9.3",
78
- "@fluid-internal/mocha-test-setup": "~2.71.0",
79
- "@fluid-tools/build-cli": "^0.58.3",
78
+ "@fluid-internal/mocha-test-setup": "~2.73.0",
79
+ "@fluid-tools/build-cli": "^0.60.0",
80
80
  "@fluidframework/build-common": "^2.0.3",
81
- "@fluidframework/build-tools": "^0.58.3",
82
- "@fluidframework/eslint-config-fluid": "^7.0.0",
83
- "@fluidframework/tree": "~2.71.0",
81
+ "@fluidframework/build-tools": "^0.60.0",
82
+ "@fluidframework/eslint-config-fluid": "~2.73.0",
83
+ "@fluidframework/tree": "~2.73.0",
84
84
  "@microsoft/api-extractor": "7.52.11",
85
85
  "@types/mocha": "^10.0.10",
86
86
  "@types/node": "^18.19.0",
@@ -92,7 +92,7 @@
92
92
  "eslint-config-prettier": "~10.1.8",
93
93
  "mocha": "^10.8.2",
94
94
  "mocha-multi-reporters": "^1.5.1",
95
- "prettier": "~3.0.3",
95
+ "prettier": "~3.6.2",
96
96
  "rimraf": "^4.4.0",
97
97
  "typescript": "~5.4.5"
98
98
  },
package/src/executor.ts CHANGED
@@ -3,10 +3,15 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- // eslint-disable-next-line import/no-unassigned-import
6
+ // eslint-disable-next-line import-x/no-unassigned-import
7
7
  import "ses";
8
8
 
9
- import type { AsynchronousEditor } from "@fluidframework/tree-agent/alpha";
9
+ import type { ImplicitFieldSchema } from "@fluidframework/tree";
10
+ import {
11
+ createContext,
12
+ type AsynchronousEditor,
13
+ type ViewOrTree,
14
+ } from "@fluidframework/tree-agent/alpha";
10
15
 
11
16
  /**
12
17
  * Used to track whether the SES `lockdown` function has already been called by this module.
@@ -21,10 +26,10 @@ const lockdownSymbol = Symbol.for("tree-agent.ses.locked");
21
26
  * @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
27
  * @alpha
23
28
  */
24
- export function createSesEditExecutor(options?: {
29
+ export function createSesEditExecutor<TSchema extends ImplicitFieldSchema>(options?: {
25
30
  compartmentOptions?: { globals?: Map<string, unknown>; [key: string]: unknown };
26
31
  lockdownOptions?: Record<string, unknown>;
27
- }): AsynchronousEditor {
32
+ }): AsynchronousEditor<TSchema> {
28
33
  const optionsGlobals: Map<string, unknown> =
29
34
  options?.compartmentOptions?.globals ?? new Map<string, unknown>();
30
35
 
@@ -57,12 +62,12 @@ export function createSesEditExecutor(options?: {
57
62
  }
58
63
  }
59
64
 
60
- return async (context: Record<string, unknown>, code: string) => {
65
+ return async (tree: ViewOrTree<TSchema>, code: string) => {
61
66
  const compartmentOptions = {
62
67
  ...options?.compartmentOptions,
63
68
  globals: {
64
69
  ...Object.fromEntries(optionsGlobals),
65
- context,
70
+ context: createContext(tree),
66
71
  },
67
72
  };
68
73