# @endo/static-module-record

> Shim for the SES StaticModuleRecord and module-to-program transformer

Latest version **1.1.2** (published 2024-05-07) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @endo/static-module-record
pnpm add @endo/static-module-record
yarn add @endo/static-module-record
bun add @endo/static-module-record
```

## Health

**Score 45/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2024-05-07 |
| First published | 2021-06-02 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 5 |
| Unpacked size | 59.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1055 |
| Author | Agoric |
| Maintainers | mhofman, kriskowal, michaelfig, erights, warner |
| Keywords | ses, StaticModuleRecord, modules, ESM |

## Links

- npm: https://www.npmjs.com/package/@endo/static-module-record
- Repository: https://github.com/endojs/endo
- Homepage: https://github.com/endojs/endo/tree/master/packages/static-module-record#readme
- Issues: https://github.com/endojs/endo/issues
- npm.io page: https://npm.io/package/@endo/static-module-record

## Dependencies (5)

- [ses](https://npm.io/package/ses.md) ^1.5.0
- [@babel/types](https://npm.io/package/@babel/types.md) ^7.24.0
- [@babel/parser](https://npm.io/package/@babel/parser.md) ^7.23.6
- [@babel/traverse](https://npm.io/package/@babel/traverse.md) ^7.23.6
- [@agoric/babel-generator](https://npm.io/package/@agoric/babel-generator.md) ^7.17.6

## Alternatives

- [@clerk/clerk-expo](https://npm.io/package/@clerk/clerk-expo.md) — 133.6K weekly downloads
- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads

## Recent versions

- 1.1.2 (latest) — 2024-05-07
- 1.1.1 — 2024-04-04
- 1.1.0 — 2024-03-20
- 1.0.4 — 2024-02-23
- 1.0.3 — 2024-02-15
- 1.0.2 — 2024-01-18
- 1.0.1 — 2023-12-20
- 1.0.0 — 2023-12-12
- 0.8.2 — 2023-09-12
- 0.8.1 — 2023-08-07
- 0.7.20 — 2023-07-19
- 0.7.19 — 2023-04-20
- 0.7.18 — 2023-04-14
- 0.7.17 — 2023-03-07
- 0.7.16 — 2022-12-23
- … 37 more at https://npm.io/package/@endo/static-module-record/versions

## README

# StaticModuleRecord

This package provides a shim for the `StaticModuleRecord` constructor, suitable
for use with the SES shim `importHook`.
The static module record accepts a JavaScript module and converts it into
a form that SES can use to securely emulate JavaScript modules (ESMs, the `mjs`
file format) with compartments.

```js
import 'ses';
import { StaticModuleRecord } from '@endo/static-module-record`;

const c1 = new Compartment({}, {}, {
  name: "first compartment",
  resolveHook: (moduleSpecifier, moduleReferrer) => {
    return resolve(moduleSpecifier, moduleReferrer);
  },
  importHook: async moduleSpecifier => {
    const moduleLocation = locate(moduleSpecifier);
    const moduleText = await retrieve(moduleLocation);
    return new StaticModuleRecord(moduleText, moduleLocation);
  },
});
```

## Source maps

The `StaticModuleRecord` is a shim for what we hope to eventually call a native
`ModuleSource` constructor.
However, in the absence of a native `ModuleSource`, this produces a
serializable object that emulates the behavior of `ModuleSource` in conjunction
with the `Compartment` constructor from `ses`.
A detail that leaks from the implementation is that the constructor rewrites
the source, from an ESM `[[Module]]` grammar construction to a `[[Program]]`
construction suitable for confining with the compartment's confined evaluator.

This transform attempts to be unobtrusive, but currently causes some alignment
changes due to (hopefully temporary) limitations to the underlying code
generator.
In the interim, generating a source map can help.

The `StaticModuleRecord` constructor accepts non-standards-track
`sourceMapHook` and `sourceMapUrl` options.

Previously, the sole option was a `string` argument for the `sourceUrl`, such
that this would be appended to the generated source.
This change allows for the old or new usage:

```js
new StaticModuleRecord(source, sourceUrl);
// or
new StaticModuleRecord(source, { sourceUrl, sourceMapUrl, sourceMapHook });
```

The `sourceMapUrl` is necessary for generating a source map.
The URL will appear only in the generated source map, so a fully qualified
source map URL is safe and allows for continuity if the map is generated and
debugged on the same host.
This is important because Endo captures precompiled Static Module Records in
bundles, excluding source maps, such that a relative path is not useful.

The `sourceMapHook` will receive a string source map and a details bag
including:

- `source`
- `sourceUrl`
- `sourceMapUrl`

Such that the receiver can store the source map somewhere as a side-effect.

Note: the `sourceMapHook` is synchronous and returns `void`.
Exceptions thrown by the hook will propagate up through the constructor.  If
the hook returns a promise, it will be dropped and rejections will go uncaught.
If the hook must do async work, these should be queued up as a job that the
caller can later await.

## Bug Disclosure

Please help us practice coordinated security bug disclosure, by using the
instructions in
[SECURITY.md](https://github.com/endojs/endo/blob/master/packages/ses/SECURITY.md)
to report security-sensitive bugs privately.

For non-security bugs, please use the [regular Issues
page](https://github.com/endojs/endo/issues).

---
_Source: https://npm.io/package/@endo/static-module-record · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
