> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/mercuryworkshop/scramjet/llms.txt
> Use this file to discover all available pages before exploring further.

# Config types

> Configuration type definitions for Scramjet

Scramjet uses a comprehensive configuration system to control behavior, feature flags, and URL encoding.

## ScramjetInitConfig

The configuration interface for initializing Scramjet.

```typescript theme={null}
interface ScramjetInitConfig {
  prefix: string;
  globals: {
    wrapfn: string;
    wrappropertybase: string;
    wrappropertyfn: string;
    cleanrestfn: string;
    importfn: string;
    rewritefn: string;
    metafn: string;
    setrealmfn: string;
    pushsourcemapfn: string;
    trysetfn: string;
    templocid: string;
    tempunusedid: string;
  };
  files: {
    wasm: string;
    all: string;
    sync: string;
  };
  flags: Partial<ScramjetFlags>;
  siteFlags?: Record<string, Partial<ScramjetFlags>>;
  codec: {
    encode: (url: string) => string;
    decode: (url: string) => string;
  };
}
```

### Properties

<ParamField path="prefix" type="string" required>
  The URL prefix for proxied content. Default: `/scramjet/`

  <Expandable title="Example">
    ```typescript theme={null}
    prefix: "/scramjet/"
    ```
  </Expandable>
</ParamField>

<ParamField path="globals" type="object" required>
  Global variable names used by Scramjet's runtime.

  <Expandable title="Properties">
    <ParamField path="wrapfn" type="string">
      Default: `$scramjet$wrap`
    </ParamField>

    <ParamField path="wrappropertybase" type="string">
      Default: `$scramjet__`
    </ParamField>

    <ParamField path="wrappropertyfn" type="string">
      Default: `$scramjet$prop`
    </ParamField>

    <ParamField path="cleanrestfn" type="string">
      Default: `$scramjet$clean`
    </ParamField>

    <ParamField path="importfn" type="string">
      Default: `$scramjet$import`
    </ParamField>

    <ParamField path="rewritefn" type="string">
      Default: `$scramjet$rewrite`
    </ParamField>

    <ParamField path="metafn" type="string">
      Default: `$scramjet$meta`
    </ParamField>

    <ParamField path="setrealmfn" type="string">
      Default: `$scramjet$setrealm`
    </ParamField>

    <ParamField path="pushsourcemapfn" type="string">
      Default: `$scramjet$pushsourcemap`
    </ParamField>

    <ParamField path="trysetfn" type="string">
      Default: `$scramjet$tryset`
    </ParamField>

    <ParamField path="templocid" type="string">
      Default: `$scramjet$temploc`
    </ParamField>

    <ParamField path="tempunusedid" type="string">
      Default: `$scramjet$tempunused`
    </ParamField>
  </Expandable>
</ParamField>

<ParamField path="files" type="object" required>
  Paths to Scramjet bundle files.

  <Expandable title="Properties">
    <ParamField path="wasm" type="string">
      Path to WASM file. Default: `/scramjet.wasm.wasm`
    </ParamField>

    <ParamField path="all" type="string">
      Path to full bundle. Default: `/scramjet.all.js`
    </ParamField>

    <ParamField path="sync" type="string">
      Path to sync bundle. Default: `/scramjet.sync.js`
    </ParamField>
  </Expandable>
</ParamField>

<ParamField path="flags" type="Partial<ScramjetFlags>" required>
  Feature flags to enable or disable Scramjet features. See [ScramjetFlags](#scramjetflags) below.
</ParamField>

<ParamField path="siteFlags" type="Record<string, Partial<ScramjetFlags>>">
  Per-site feature flag overrides. Keys are hostnames or URLs.

  <Expandable title="Example">
    ```typescript theme={null}
    siteFlags: {
      "example.com": {
        strictRewrites: false
      }
    }
    ```
  </Expandable>
</ParamField>

<ParamField path="codec" type="object" required>
  URL encoding and decoding functions.

  <Expandable title="Properties">
    <ParamField path="encode" type="(url: string) => string">
      Function to encode URLs. Default uses `encodeURIComponent`.
    </ParamField>

    <ParamField path="decode" type="(url: string) => string">
      Function to decode URLs. Default uses `decodeURIComponent`.
    </ParamField>
  </Expandable>
</ParamField>

### Example

```typescript theme={null}
const config: Partial<ScramjetInitConfig> = {
  prefix: "/scramjet/",
  flags: {
    serviceworkers: false,
    syncxhr: false,
    strictRewrites: true,
    captureErrors: true,
    sourcemaps: true
  },
  codec: {
    encode: (url) => btoa(url),
    decode: (url) => atob(url)
  }
};
```

## ScramjetConfig

The internal configuration interface (extends `ScramjetInitConfig` with normalized types).

```typescript theme={null}
interface ScramjetConfig {
  prefix: string;
  globals: { /* ... */ };
  files: { /* ... */ };
  flags: ScramjetFlags;
  siteFlags: Record<string, Partial<ScramjetFlags>>;
  codec: {
    encode: string;
    decode: string;
  };
}
```

<Info>
  `ScramjetConfig` is the same as `ScramjetInitConfig`, except the `codec` functions are serialized as strings and `flags` is complete (not partial).
</Info>

## ScramjetFlags

Feature flags that control Scramjet's behavior.

```typescript theme={null}
type ScramjetFlags = {
  serviceworkers: boolean;
  syncxhr: boolean;
  strictRewrites: boolean;
  rewriterLogs: boolean;
  captureErrors: boolean;
  cleanErrors: boolean;
  scramitize: boolean;
  sourcemaps: boolean;
  destructureRewrites: boolean;
  interceptDownloads: boolean;
  allowInvalidJs: boolean;
  allowFailedIntercepts: boolean;
};
```

### Properties

<ParamField path="serviceworkers" type="boolean">
  Enable service worker support. Default: `false`

  <Warning>
    Enabling this may cause compatibility issues with some sites.
  </Warning>
</ParamField>

<ParamField path="syncxhr" type="boolean">
  Enable synchronous XMLHttpRequest support. Default: `false`
</ParamField>

<ParamField path="strictRewrites" type="boolean">
  Enable strict URL rewriting. Default: `true`

  <Info>
    When enabled, invalid URLs will throw errors instead of being silently ignored.
  </Info>
</ParamField>

<ParamField path="rewriterLogs" type="boolean">
  Enable verbose rewriter logging. Default: `false`
</ParamField>

<ParamField path="captureErrors" type="boolean">
  Capture and handle errors from proxified code. Default: `true`
</ParamField>

<ParamField path="cleanErrors" type="boolean">
  Clean Scramjet internals from error stack traces. Default: `false`
</ParamField>

<ParamField path="scramitize" type="boolean">
  Enable scramitization feature. Default: `false`
</ParamField>

<ParamField path="sourcemaps" type="boolean">
  Enable source map support. Default: `true`
</ParamField>

<ParamField path="destructureRewrites" type="boolean">
  Enable destructuring in rewrites. Default: `false`
</ParamField>

<ParamField path="interceptDownloads" type="boolean">
  Intercept and emit events for downloads. Default: `false`
</ParamField>

<ParamField path="allowInvalidJs" type="boolean">
  Allow invalid JavaScript to pass through. Default: `true`
</ParamField>

<ParamField path="allowFailedIntercepts" type="boolean">
  Allow failed intercepts without throwing errors. Default: `true`
</ParamField>

### Example

```typescript theme={null}
const flags: Partial<ScramjetFlags> = {
  strictRewrites: true,
  captureErrors: true,
  sourcemaps: true,
  interceptDownloads: true,
  cleanErrors: false
};

const scramjet = new ScramjetController({
  prefix: "/scramjet/",
  flags
});
```

## ScramjetVersionInfo

Version information for the current Scramjet build.

```typescript theme={null}
interface ScramjetVersionInfo {
  /** The git commit hash that this build was created from */
  build: string;
  /** The semantic version */
  version: string;
}
```

### Example

```typescript theme={null}
console.log(`Scramjet v${$scramjetVersion.version}`);
console.log(`Build: ${$scramjetVersion.build}`);
```
